Skip to content

Commit

Permalink
maybe getting closer
Browse files Browse the repository at this point in the history
  • Loading branch information
holic committed Jul 9, 2024
1 parent a68c6f9 commit 14dd5e8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
6 changes: 5 additions & 1 deletion packages/store/ts/config/v2/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export type resolveNamespace<input, scope extends Scope = AbiTypeScope> = input
{
[label in keyof input["tables"]]: mergeIfUndefined<
input["tables"][label],
{ label: label; namespace: input["namespace"] }
{
label: label;
// TODO: figure out how to dedupe with above `namespace` value?
namespace: undefined extends input["namespace"] ? truncate<input["label"], 14> : input["namespace"];
}
>;
},
scope
Expand Down
6 changes: 6 additions & 0 deletions packages/store/ts/config/v2/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ describe("defineStore", () => {
userTypes: {},
enums: {},
enumValues: {},
label: "",
namespace: "",
codegen: CODEGEN_DEFAULTS,
} as const;
Expand Down Expand Up @@ -102,6 +103,7 @@ describe("defineStore", () => {
},
enums: {},
enumValues: {},
label: "",
namespace: "",
codegen: CODEGEN_DEFAULTS,
} as const;
Expand Down Expand Up @@ -150,6 +152,7 @@ describe("defineStore", () => {
userTypes: {},
enums: {},
enumValues: {},
label: "",
namespace: "",
codegen: CODEGEN_DEFAULTS,
} as const;
Expand Down Expand Up @@ -226,6 +229,7 @@ describe("defineStore", () => {
userTypes: {},
enums: {},
enumValues: {},
label: "",
namespace: "",
codegen: CODEGEN_DEFAULTS,
} as const;
Expand Down Expand Up @@ -309,6 +313,7 @@ describe("defineStore", () => {
},
enums: {},
enumValues: {},
label: "",
namespace: "",
codegen: CODEGEN_DEFAULTS,
} as const;
Expand Down Expand Up @@ -428,6 +433,7 @@ describe("defineStore", () => {
second: 1,
},
},
label: "",
namespace: "",
codegen: CODEGEN_DEFAULTS,
} as const;
Expand Down
22 changes: 11 additions & 11 deletions packages/store/ts/config/v2/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ export function extendedScope<input>(input: input): extendedScope<input> {
return scopeWithEnums(get(input, "enums"), scopeWithUserTypes(get(input, "userTypes")));
}

export type validateStore<input> = input extends NamespaceInput
? validateNamespace<Pick<input, keyof NamespaceInput>, extendedScope<input>> & {
[key in keyof input]: key extends "userTypes"
? UserTypes
: key extends "enums"
? narrow<input[key]>
: key extends keyof StoreInput
? StoreInput[key]
: ErrorMessage<`\`${key & string}\` is not a valid Store config option.`>;
}
: never;
export type validateStore<input> = (input extends NamespaceInput
? validateNamespace<Pick<input, keyof NamespaceInput>, extendedScope<input>>
: {}) & {
[key in keyof input]: key extends "userTypes"
? UserTypes
: key extends "enums"
? narrow<input[key]>
: key extends keyof StoreInput
? StoreInput[key]
: ErrorMessage<`\`${key & string}\` is not a valid Store config option.`>;
};

export function validateStore(input: unknown): asserts input is StoreInput {
const scope = extendedScope(input);
Expand Down
4 changes: 4 additions & 0 deletions packages/store/ts/config/v2/storeWithShorthands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe("defineStoreWithShorthands", () => {
userTypes: {},
enums: {},
enumValues: {},
label: "",
namespace: "",
codegen: CODEGEN_DEFAULTS,
} as const;
Expand Down Expand Up @@ -74,6 +75,7 @@ describe("defineStoreWithShorthands", () => {
userTypes: { CustomType: { type: "address", filePath: "path/to/file" } },
enums: {},
enumValues: {},
label: "",
namespace: "",
codegen: CODEGEN_DEFAULTS,
} as const;
Expand Down Expand Up @@ -117,6 +119,7 @@ describe("defineStoreWithShorthands", () => {
userTypes: {},
enums: {},
enumValues: {},
label: "",
namespace: "",
codegen: CODEGEN_DEFAULTS,
} as const;
Expand Down Expand Up @@ -160,6 +163,7 @@ describe("defineStoreWithShorthands", () => {
userTypes: {},
enums: {},
enumValues: {},
label: "",
namespace: "",
codegen: CODEGEN_DEFAULTS,
} as const;
Expand Down

0 comments on commit 14dd5e8

Please sign in to comment.