Skip to content

Commit

Permalink
strict type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
pyramation committed Apr 19, 2024
1 parent 94957d5 commit c9fac2d
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 51 deletions.
32 changes: 24 additions & 8 deletions __fixtures__/output/contract.camel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,21 @@ export interface PoolConfig {
poolType: PoolType;
}
export type PoolType = {
xyk: any;
xyk: {
[key: string]: unknown;
};
} | {
stable2Pool: any;
stable2Pool: {
[key: string]: unknown;
};
} | {
stable3Pool: any;
stable3Pool: {
[key: string]: unknown;
};
} | {
weighted: any;
weighted: {
[key: string]: unknown;
};
} | {
custom: string;
};
Expand All @@ -53,9 +61,13 @@ export interface SingleSwapRequest {
swapType: SwapType;
}
export type SwapType = {
giveIn: any;
giveIn: {
[key: string]: unknown;
};
} | {
giveOut: any;
giveOut: {
[key: string]: unknown;
};
} | {
custom: string;
};
Expand Down Expand Up @@ -106,7 +118,11 @@ export type ExecuteMsg = {
owner: string;
};
} | {
dropOwnershipProposal: any;
dropOwnershipProposal: {
[key: string]: unknown;
};
} | {
claimOwnership: any;
claimOwnership: {
[key: string]: unknown;
};
};
32 changes: 24 additions & 8 deletions __fixtures__/output/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,21 @@ export interface PoolConfig {
pool_type: PoolType;
}
export type PoolType = {
xyk: any;
xyk: {
[key: string]: unknown;
};
} | {
stable2_pool: any;
stable2_pool: {
[key: string]: unknown;
};
} | {
stable3_pool: any;
stable3_pool: {
[key: string]: unknown;
};
} | {
weighted: any;
weighted: {
[key: string]: unknown;
};
} | {
custom: string;
};
Expand All @@ -53,9 +61,13 @@ export interface SingleSwapRequest {
swap_type: SwapType;
}
export type SwapType = {
give_in: any;
give_in: {
[key: string]: unknown;
};
} | {
give_out: any;
give_out: {
[key: string]: unknown;
};
} | {
custom: string;
};
Expand Down Expand Up @@ -106,7 +118,11 @@ export type ExecuteMsg = {
owner: string;
};
} | {
drop_ownership_proposal: any;
drop_ownership_proposal: {
[key: string]: unknown;
};
} | {
claim_ownership: any;
claim_ownership: {
[key: string]: unknown;
};
};
4 changes: 3 additions & 1 deletion __fixtures__/output/memo.camel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export interface Memo {
key: string;
description: string;
gitRepo: string;
memo: any;
memo: {
[key: string]: unknown;
};
}[];
}
4 changes: 3 additions & 1 deletion __fixtures__/output/memo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export interface Memo {
key: string;
description: string;
git_repo: string;
memo: any;
memo: {
[key: string]: unknown;
};
}[];
}
64 changes: 48 additions & 16 deletions __tests__/__snapshots__/contract.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,21 @@ export interface PoolConfig {
pool_type: PoolType;
}
export type PoolType = {
xyk: any;
xyk: {
[key: string]: unknown;
};
} | {
stable2_pool: any;
stable2_pool: {
[key: string]: unknown;
};
} | {
stable3_pool: any;
stable3_pool: {
[key: string]: unknown;
};
} | {
weighted: any;
weighted: {
[key: string]: unknown;
};
} | {
custom: string;
};
Expand All @@ -56,9 +64,13 @@ export interface SingleSwapRequest {
swap_type: SwapType;
}
export type SwapType = {
give_in: any;
give_in: {
[key: string]: unknown;
};
} | {
give_out: any;
give_out: {
[key: string]: unknown;
};
} | {
custom: string;
};
Expand Down Expand Up @@ -109,9 +121,13 @@ export type ExecuteMsg = {
owner: string;
};
} | {
drop_ownership_proposal: any;
drop_ownership_proposal: {
[key: string]: unknown;
};
} | {
claim_ownership: any;
claim_ownership: {
[key: string]: unknown;
};
};"
`;

Expand Down Expand Up @@ -151,13 +167,21 @@ export interface PoolConfig {
poolType: PoolType;
}
export type PoolType = {
xyk: any;
xyk: {
[key: string]: unknown;
};
} | {
stable2Pool: any;
stable2Pool: {
[key: string]: unknown;
};
} | {
stable3Pool: any;
stable3Pool: {
[key: string]: unknown;
};
} | {
weighted: any;
weighted: {
[key: string]: unknown;
};
} | {
custom: string;
};
Expand All @@ -171,9 +195,13 @@ export interface SingleSwapRequest {
swapType: SwapType;
}
export type SwapType = {
giveIn: any;
giveIn: {
[key: string]: unknown;
};
} | {
giveOut: any;
giveOut: {
[key: string]: unknown;
};
} | {
custom: string;
};
Expand Down Expand Up @@ -224,8 +252,12 @@ export type ExecuteMsg = {
owner: string;
};
} | {
dropOwnershipProposal: any;
dropOwnershipProposal: {
[key: string]: unknown;
};
} | {
claimOwnership: any;
claimOwnership: {
[key: string]: unknown;
};
};"
`;
8 changes: 6 additions & 2 deletions __tests__/__snapshots__/memo.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ exports[`memo 1`] = `
key: string;
description: string;
git_repo: string;
memo: any;
memo: {
[key: string]: unknown;
};
}[];
}"
`;
Expand All @@ -19,7 +21,9 @@ exports[`memo camelCase 1`] = `
key: string;
description: string;
gitRepo: string;
memo: any;
memo: {
[key: string]: unknown;
};
}[];
}"
`;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"dependencies": {
"@babel/core": "^7.24.4",
"@babel/generator": "^7.24.4",
"@babel/types": "^7.24.0"
"@babel/types": "^7.24.0",
"deepmerge": "^4.3.1"
}
}
13 changes: 10 additions & 3 deletions src/context.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { JSONSchema } from "./types";
import deepmerge from 'deepmerge';

export interface SchemaTSOptions {
useSingleQuotes: boolean;
useCamelCase: boolean;
strictTypeSafety: boolean; // true uses { [k: string]: unknown; }, false uses any
}

export interface SchemaTSContextI {
Expand All @@ -20,17 +22,18 @@ export class SchemaTSContext implements SchemaTSContextI {
parents: JSONSchema[];

constructor(
options: SchemaTSOptions,
options: Partial<SchemaTSOptions>,
root: JSONSchema,
schema: JSONSchema,
parents: JSONSchema[] = []
) {
this.options = options;
this.options = deepmerge(defaultOptions, options ?? {});
this.schema = schema;
this.root = root;
this.parents = parents;
}

// (currently not used)
// Clone the context with the option to add a new parent
clone(newParent: JSONSchema): SchemaTSContext {
// Create a new array for parents to avoid mutation of the original array
Expand All @@ -39,4 +42,8 @@ export class SchemaTSContext implements SchemaTSContextI {
}
}

export const defaultOptions: SchemaTSOptions = { useSingleQuotes: true, useCamelCase: false };
export const defaultOptions: SchemaTSOptions = {
useSingleQuotes: true,
useCamelCase: false,
strictTypeSafety: true
};
Loading

0 comments on commit c9fac2d

Please sign in to comment.