Skip to content

Commit

Permalink
Made typescript type-checking in the cli into a config option
Browse files Browse the repository at this point in the history
  • Loading branch information
ritave committed Oct 6, 2024
1 parent 7f1740e commit 1ab5a3d
Show file tree
Hide file tree
Showing 56 changed files with 158 additions and 41 deletions.
3 changes: 3 additions & 0 deletions packages/examples/packages/bip32/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const config: SnapConfig = {
server: {
port: 8001,
},
typescript: {
enabled: true,
},
stats: {
buffer: false,
builtIns: {
Expand Down
7 changes: 4 additions & 3 deletions packages/examples/packages/bip32/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ import { getPrivateNode, getPublicKey } from './utils';
export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
switch (request.method) {
case 'getPublicKey':
return await getPublicKey(
request.params as unknown as GetBip32PublicKeyParams,
);
return await getPublicKey(request.params as GetBip32PublicKeyParams);

case 'signMessage': {
const { message, curve, ...params } = request.params as SignMessageParams;

if (!message || typeof message !== 'string') {
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new InvalidParamsError(`Invalid signature data: "${message}".`);
}

Expand Down Expand Up @@ -75,6 +74,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
});

if (!approved) {
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new UserRejectedRequestError();
}

Expand All @@ -100,6 +100,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
}

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
3 changes: 3 additions & 0 deletions packages/examples/packages/bip44/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const config: SnapConfig = {
server: {
port: 8002,
},
typescript: {
enabled: true,
},
stats: {
buffer: false,
builtIns: {
Expand Down
2 changes: 2 additions & 0 deletions packages/examples/packages/bip44/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
});

if (!approved) {
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new UserRejectedRequestError();
}

Expand All @@ -67,6 +68,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
}

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
1 change: 1 addition & 0 deletions packages/examples/packages/browserify-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
return 'Hello from Browserify!';

default: {
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/examples/packages/browserify/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
return 'Hello from the MetaMask Snaps CLI using Browserify!';

default: {
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
}
Expand Down
3 changes: 3 additions & 0 deletions packages/examples/packages/client-status/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const config: SnapConfig = {
server: {
port: 8027,
},
typescript: {
enabled: true,
},
stats: {
buffer: false,
},
Expand Down
1 change: 1 addition & 0 deletions packages/examples/packages/client-status/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
}

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
3 changes: 3 additions & 0 deletions packages/examples/packages/cronjobs/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const config: SnapConfig = {
server: {
port: 8004,
},
typescript: {
enabled: true,
},
stats: {
buffer: false,
},
Expand Down
1 change: 1 addition & 0 deletions packages/examples/packages/cronjobs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const onCronjob: OnCronjobHandler = async ({ request }) => {
},
});
default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
3 changes: 3 additions & 0 deletions packages/examples/packages/dialogs/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const config: SnapConfig = {
server: {
port: 8005,
},
typescript: {
enabled: true,
},
stats: {
buffer: false,
},
Expand Down
1 change: 1 addition & 0 deletions packages/examples/packages/dialogs/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
});

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
Expand Down
3 changes: 3 additions & 0 deletions packages/examples/packages/errors/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const config: SnapConfig = {
server: {
port: 8006,
},
typescript: {
enabled: true,
},
};

export default config;
3 changes: 3 additions & 0 deletions packages/examples/packages/ethereum-provider/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const config: SnapConfig = {
server: {
port: 8007,
},
typescript: {
enabled: true,
},
stats: {
buffer: false,
},
Expand Down
1 change: 1 addition & 0 deletions packages/examples/packages/ethereum-provider/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
}

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
3 changes: 3 additions & 0 deletions packages/examples/packages/ethers-js/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const config: SnapConfig = {
server: {
port: 8008,
},
typescript: {
enabled: true,
},
stats: {
buffer: false,
builtIns: {
Expand Down
3 changes: 3 additions & 0 deletions packages/examples/packages/file-upload/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const config: SnapConfig = {
server: {
port: 8030,
},
typescript: {
enabled: true,
},
stats: {
buffer: false,
},
Expand Down
1 change: 1 addition & 0 deletions packages/examples/packages/file-upload/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
}

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({
method: request.method,
});
Expand Down
3 changes: 3 additions & 0 deletions packages/examples/packages/get-entropy/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const config: SnapConfig = {
server: {
port: 8009,
},
typescript: {
enabled: true,
},
stats: {
buffer: false,
builtIns: {
Expand Down
2 changes: 2 additions & 0 deletions packages/examples/packages/get-entropy/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
});

if (!approved) {
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new UserRejectedRequestError();
}

Expand All @@ -57,6 +58,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
}

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
3 changes: 3 additions & 0 deletions packages/examples/packages/get-file/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const config: SnapConfig = {
server: {
port: 8024,
},
typescript: {
enabled: true,
},
stats: {
buffer: false,
},
Expand Down
1 change: 1 addition & 0 deletions packages/examples/packages/get-file/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
}

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
3 changes: 3 additions & 0 deletions packages/examples/packages/home-page/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const config: SnapConfig = {
server: {
port: 8025,
},
typescript: {
enabled: true,
},
stats: {
buffer: false,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/home-page/src/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('onHomePage', () => {

await screen.clickElement('footer_button');

const newUi = await response.getInterface();
const newUi = response.getInterface();

expect(newUi).toRender(
<Box>
Expand Down
3 changes: 3 additions & 0 deletions packages/examples/packages/images/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const config: SnapConfig = {
server: {
port: 8026,
},
typescript: {
enabled: true,
},
stats: {
buffer: false,
},
Expand Down
1 change: 1 addition & 0 deletions packages/examples/packages/images/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
}

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
3 changes: 3 additions & 0 deletions packages/examples/packages/interactive-ui/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const config: SnapConfig = {
server: {
port: 8028,
},
typescript: {
enabled: true,
},
stats: {
buffer: false,
},
Expand Down
1 change: 1 addition & 0 deletions packages/examples/packages/interactive-ui/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
}

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({
method: request.method,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const config: SnapConfig = {
server: {
port: 8012,
},
typescript: {
enabled: true,
},
stats: {
buffer: false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const config: SnapConfig = {
server: {
port: 8011,
},
typescript: {
enabled: true,
},
stats: {
buffer: false,
builtIns: {
Expand Down
3 changes: 3 additions & 0 deletions packages/examples/packages/json-rpc/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const config: SnapConfig = {
server: {
port: 8013,
},
typescript: {
enabled: true,
},
stats: {
buffer: false,
},
Expand Down
1 change: 1 addition & 0 deletions packages/examples/packages/json-rpc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
}

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
3 changes: 3 additions & 0 deletions packages/examples/packages/jsx/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const config: SnapConfig = {
server: {
port: 8029,
},
typescript: {
enabled: true,
},
stats: {
buffer: false,
},
Expand Down
3 changes: 3 additions & 0 deletions packages/examples/packages/lifecycle-hooks/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const config: SnapConfig = {
server: {
port: 8022,
},
typescript: {
enabled: true,
},
stats: {
buffer: false,
},
Expand Down
3 changes: 3 additions & 0 deletions packages/examples/packages/localization/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const config: SnapConfig = {
server: {
port: 8020,
},
typescript: {
enabled: true,
},
stats: {
buffer: false,
},
Expand Down
1 change: 1 addition & 0 deletions packages/examples/packages/localization/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
return await getMessage('hello');

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
3 changes: 3 additions & 0 deletions packages/examples/packages/manage-state/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const config: SnapConfig = {
server: {
port: 8014,
},
typescript: {
enabled: true,
},
stats: {
buffer: false,
},
Expand Down
1 change: 1 addition & 0 deletions packages/examples/packages/manage-state/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
}

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
3 changes: 3 additions & 0 deletions packages/examples/packages/name-lookup/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const config: SnapConfig = {
server: {
port: 8023,
},
typescript: {
enabled: true,
},
stats: {
buffer: false,
},
Expand Down
Loading

0 comments on commit 1ab5a3d

Please sign in to comment.