@latticexyz/store 2.0.13-main-609de113f → 3.0.0-main-560fd6a0c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,66 +1,157 @@
1
- import { r as resolveStore } from './store-cb0f85e1.js';
2
- import '@arktype/util';
3
- import './output-2853398e.js';
4
- import '@latticexyz/config';
5
- import 'viem';
6
- import '@latticexyz/schema-type/internal';
1
+ import { r as resolveNamespacedTables } from './namespacedTables-bf676cf3.js';
7
2
 
8
- declare const _default: resolveStore<{
9
- readonly codegen: {
10
- readonly storeImportPath: "../../";
11
- };
3
+ declare const _default: {
12
4
  readonly namespace: "store";
13
- readonly userTypes: {
14
- readonly ResourceId: {
15
- readonly filePath: "./src/ResourceId.sol";
16
- readonly type: "bytes32";
17
- };
18
- readonly FieldLayout: {
19
- readonly filePath: "./src/FieldLayout.sol";
20
- readonly type: "bytes32";
21
- };
22
- readonly Schema: {
23
- readonly filePath: "./src/Schema.sol";
24
- readonly type: "bytes32";
25
- };
26
- };
27
- readonly tables: {
5
+ readonly sourceDirectory: "src";
6
+ readonly tables: resolveNamespacedTables<{
28
7
  readonly StoreHooks: {
8
+ readonly label: "StoreHooks";
9
+ readonly type: "table";
10
+ readonly namespace: "store";
11
+ readonly name: string;
12
+ readonly tableId: `0x${string}`;
29
13
  readonly schema: {
30
- readonly tableId: "ResourceId";
31
- readonly hooks: "bytes21[]";
14
+ readonly tableId: {
15
+ readonly type: "bytes32";
16
+ readonly internalType: "ResourceId";
17
+ };
18
+ readonly hooks: {
19
+ readonly type: "bytes21[]";
20
+ readonly internalType: "bytes21[]";
21
+ };
32
22
  };
33
23
  readonly key: readonly ["tableId"];
24
+ readonly codegen: {
25
+ readonly outputDirectory: string;
26
+ readonly tableIdArgument: false;
27
+ readonly storeArgument: false;
28
+ readonly dataStruct: boolean;
29
+ };
30
+ readonly deploy: {
31
+ readonly disabled: false;
32
+ };
34
33
  };
35
34
  readonly Tables: {
35
+ readonly label: "Tables";
36
+ readonly type: "table";
37
+ readonly namespace: "store";
38
+ readonly name: string;
39
+ readonly tableId: `0x${string}`;
36
40
  readonly schema: {
37
- readonly tableId: "ResourceId";
38
- readonly fieldLayout: "FieldLayout";
39
- readonly keySchema: "Schema";
40
- readonly valueSchema: "Schema";
41
- readonly abiEncodedKeyNames: "bytes";
42
- readonly abiEncodedFieldNames: "bytes";
41
+ readonly tableId: {
42
+ readonly type: "bytes32";
43
+ readonly internalType: "ResourceId";
44
+ };
45
+ readonly fieldLayout: {
46
+ readonly type: "bytes32";
47
+ readonly internalType: "FieldLayout";
48
+ };
49
+ readonly keySchema: {
50
+ readonly type: "bytes32";
51
+ readonly internalType: "Schema";
52
+ };
53
+ readonly valueSchema: {
54
+ readonly type: "bytes32";
55
+ readonly internalType: "Schema";
56
+ };
57
+ readonly abiEncodedKeyNames: {
58
+ readonly type: "bytes";
59
+ readonly internalType: "bytes";
60
+ };
61
+ readonly abiEncodedFieldNames: {
62
+ readonly type: "bytes";
63
+ readonly internalType: "bytes";
64
+ };
43
65
  };
44
66
  readonly key: readonly ["tableId"];
67
+ readonly codegen: {
68
+ readonly outputDirectory: string;
69
+ readonly tableIdArgument: false;
70
+ readonly storeArgument: false;
71
+ readonly dataStruct: boolean;
72
+ };
73
+ readonly deploy: {
74
+ readonly disabled: false;
75
+ };
45
76
  };
46
77
  readonly ResourceIds: {
78
+ readonly label: "ResourceIds";
79
+ readonly type: "table";
80
+ readonly namespace: "store";
81
+ readonly name: string;
82
+ readonly tableId: `0x${string}`;
47
83
  readonly schema: {
48
- readonly resourceId: "ResourceId";
49
- readonly exists: "bool";
84
+ readonly resourceId: {
85
+ readonly type: "bytes32";
86
+ readonly internalType: "ResourceId";
87
+ };
88
+ readonly exists: {
89
+ readonly type: "bool";
90
+ readonly internalType: "bool";
91
+ };
50
92
  };
51
93
  readonly key: readonly ["resourceId"];
94
+ readonly codegen: {
95
+ readonly outputDirectory: string;
96
+ readonly tableIdArgument: false;
97
+ readonly storeArgument: false;
98
+ readonly dataStruct: boolean;
99
+ };
100
+ readonly deploy: {
101
+ readonly disabled: false;
102
+ };
52
103
  };
53
104
  readonly Hooks: {
105
+ readonly label: "Hooks";
106
+ readonly type: "table";
107
+ readonly namespace: "store";
108
+ readonly name: string;
109
+ readonly tableId: `0x${string}`;
54
110
  readonly schema: {
55
- readonly resourceId: "ResourceId";
56
- readonly hooks: "bytes21[]";
111
+ readonly resourceId: {
112
+ readonly type: "bytes32";
113
+ readonly internalType: "ResourceId";
114
+ };
115
+ readonly hooks: {
116
+ readonly type: "bytes21[]";
117
+ readonly internalType: "bytes21[]";
118
+ };
57
119
  };
58
120
  readonly key: readonly ["resourceId"];
59
121
  readonly codegen: {
122
+ readonly outputDirectory: string;
60
123
  readonly tableIdArgument: true;
124
+ readonly storeArgument: false;
125
+ readonly dataStruct: boolean;
126
+ };
127
+ readonly deploy: {
128
+ readonly disabled: false;
61
129
  };
62
130
  };
131
+ }, "store">;
132
+ readonly userTypes: {
133
+ readonly ResourceId: {
134
+ readonly filePath: "./src/ResourceId.sol";
135
+ readonly type: "bytes32";
136
+ };
137
+ readonly FieldLayout: {
138
+ readonly filePath: "./src/FieldLayout.sol";
139
+ readonly type: "bytes32";
140
+ };
141
+ readonly Schema: {
142
+ readonly filePath: "./src/Schema.sol";
143
+ readonly type: "bytes32";
144
+ };
145
+ };
146
+ readonly enums: {};
147
+ readonly enumValues: {};
148
+ readonly codegen: {
149
+ readonly storeImportPath: "../../";
150
+ readonly userTypesFilename: "common.sol";
151
+ readonly outputDirectory: "codegen";
152
+ readonly namespaceDirectories: false;
153
+ readonly indexFilename: "index.sol";
63
154
  };
64
- }>;
155
+ };
65
156
 
66
157
  export { _default as default };
@@ -1,2 +1,2 @@
1
- import{J as e}from"./chunk-M5RJAVGF.js";var o=e({codegen:{storeImportPath:"../../"},namespace:"store",userTypes:{ResourceId:{filePath:"./src/ResourceId.sol",type:"bytes32"},FieldLayout:{filePath:"./src/FieldLayout.sol",type:"bytes32"},Schema:{filePath:"./src/Schema.sol",type:"bytes32"}},tables:{StoreHooks:{schema:{tableId:"ResourceId",hooks:"bytes21[]"},key:["tableId"]},Tables:{schema:{tableId:"ResourceId",fieldLayout:"FieldLayout",keySchema:"Schema",valueSchema:"Schema",abiEncodedKeyNames:"bytes",abiEncodedFieldNames:"bytes"},key:["tableId"]},ResourceIds:{schema:{resourceId:"ResourceId",exists:"bool"},key:["resourceId"]},Hooks:{schema:{resourceId:"ResourceId",hooks:"bytes21[]"},key:["resourceId"],codegen:{tableIdArgument:!0}}}});export{o as default};
1
+ import{K as e}from"./chunk-YSCNU2IH.js";var o=e({codegen:{storeImportPath:"../../"},namespace:"store",userTypes:{ResourceId:{filePath:"./src/ResourceId.sol",type:"bytes32"},FieldLayout:{filePath:"./src/FieldLayout.sol",type:"bytes32"},Schema:{filePath:"./src/Schema.sol",type:"bytes32"}},tables:{StoreHooks:{schema:{tableId:"ResourceId",hooks:"bytes21[]"},key:["tableId"]},Tables:{schema:{tableId:"ResourceId",fieldLayout:"FieldLayout",keySchema:"Schema",valueSchema:"Schema",abiEncodedKeyNames:"bytes",abiEncodedFieldNames:"bytes"},key:["tableId"]},ResourceIds:{schema:{resourceId:"ResourceId",exists:"bool"},key:["resourceId"]},Hooks:{schema:{resourceId:"ResourceId",hooks:"bytes21[]"},key:["resourceId"],codegen:{tableIdArgument:!0}}}});export{o as default};
2
2
  //# sourceMappingURL=mud.config.js.map
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @internal Only kept for backwards compatibility
3
+ */
4
+ type resolveNamespacedTables<tables, namespace> = {
5
+ readonly [label in keyof tables as namespace extends "" ? label : `${namespace & string}__${label & string}`]: tables[label];
6
+ };
7
+ /**
8
+ * @internal Only kept for backwards compatibility
9
+ */
10
+ declare function resolveNamespacedTables<tables, namespace>(tables: tables, namespace: namespace): resolveNamespacedTables<tables, namespace>;
11
+
12
+ export { resolveNamespacedTables as r };
@@ -34,17 +34,33 @@ type ScopedSchemaInput<scope extends Scope> = {
34
34
  type TableCodegenInput = Partial<TableCodegen>;
35
35
  type TableDeployInput = Partial<TableDeploy>;
36
36
  type TableInput = {
37
+ /**
38
+ * Human-readable table label. Used as config keys, table library names, and filenames.
39
+ * Labels are not length constrained like table names, but special characters should be avoided to be compatible with the filesystem, Solidity compiler, etc.
40
+ */
41
+ readonly label: string;
42
+ /**
43
+ * Defaults to `table` if not set.
44
+ */
45
+ readonly type?: "table" | "offchainTable";
46
+ /**
47
+ * Table namespace used in table's resource ID. Only root systems and systems of the same namespace can write to this table.
48
+ * Defaults to the nearest namespace in the config or root namespace if not set.
49
+ */
50
+ readonly namespace?: string;
51
+ /**
52
+ * Table name used in table's resource ID.
53
+ * Defaults to the first 16 characters of `label` if not set.
54
+ */
55
+ readonly name?: string;
37
56
  readonly schema: SchemaInput;
38
57
  readonly key: readonly string[];
39
58
  readonly tableId?: Hex;
40
- readonly name: string;
41
- readonly namespace?: string;
42
- readonly type?: "table" | "offchainTable";
43
59
  readonly codegen?: TableCodegenInput;
44
60
  readonly deploy?: TableDeployInput;
45
61
  };
46
62
  type TablesInput = {
47
- readonly [label: string]: Omit<TableInput, "namespace" | "name">;
63
+ readonly [label: string]: Omit<TableInput, "label" | "namespace">;
48
64
  };
49
65
  type CodegenInput = Partial<Codegen>;
50
66
  type StoreInput = {
@@ -64,10 +80,10 @@ type StoreInput = {
64
80
  /******** Variations with shorthands ********/
65
81
  type TableShorthandInput = SchemaInput | string;
66
82
  type TablesWithShorthandsInput = {
67
- readonly [label: string]: TableInput | TableShorthandInput;
83
+ readonly [label: string]: TablesInput[string] | TableShorthandInput;
68
84
  };
69
85
  type StoreWithShorthandsInput = show<Omit<StoreInput, "tables"> & {
70
- tables: TablesWithShorthandsInput;
86
+ readonly tables: TablesWithShorthandsInput;
71
87
  }>;
72
88
 
73
89
  type UserTypes = {
@@ -99,6 +115,9 @@ type Table = show<Table$1 & {
99
115
  readonly codegen: TableCodegen;
100
116
  readonly deploy: TableDeploy;
101
117
  }>;
118
+ type Tables = {
119
+ readonly [label: string]: Table;
120
+ };
102
121
  type Codegen = {
103
122
  /** @internal */
104
123
  readonly storeImportPath: string;
@@ -137,4 +156,4 @@ type Store = {
137
156
  readonly codegen: Codegen;
138
157
  };
139
158
 
140
- export { AbiTypeScope as A, CodegenInput as C, EnumsInput as E, Store as S, TableCodegenInput as T, UserTypes as U, Scope as a, ScopeOptions as b, SchemaInput as c, ScopedSchemaInput as d, extendScope as e, TableDeployInput as f, getStaticAbiTypeKeys as g, TableInput as h, TablesInput as i, StoreInput as j, TableShorthandInput as k, TablesWithShorthandsInput as l, StoreWithShorthandsInput as m, EnumValues as n, TableCodegen as o, TableDeploy as p, Table as q, Codegen as r };
159
+ export { AbiTypeScope as A, CodegenInput as C, EnumsInput as E, Store as S, TableCodegenInput as T, UserTypes as U, Scope as a, ScopeOptions as b, SchemaInput as c, ScopedSchemaInput as d, extendScope as e, TableDeployInput as f, getStaticAbiTypeKeys as g, TableInput as h, TablesInput as i, StoreInput as j, TableShorthandInput as k, TablesWithShorthandsInput as l, StoreWithShorthandsInput as m, EnumValues as n, TableCodegen as o, TableDeploy as p, Table as q, Tables as r, Codegen as s };
@@ -1,7 +1,8 @@
1
1
  import { merge, conform, show, requiredKeyOf, ErrorMessage, narrow } from '@arktype/util';
2
- import { a as Scope, A as AbiTypeScope, c as SchemaInput, g as getStaticAbiTypeKeys, h as TableInput, o as TableCodegen, i as TablesInput, U as UserTypes, e as extendScope, E as EnumsInput, j as StoreInput } from './output-2853398e.js';
2
+ import { a as Scope, A as AbiTypeScope, c as SchemaInput, g as getStaticAbiTypeKeys, h as TableInput, o as TableCodegen, i as TablesInput, U as UserTypes, e as extendScope, E as EnumsInput, j as StoreInput, k as TableShorthandInput, d as ScopedSchemaInput, l as TablesWithShorthandsInput, m as StoreWithShorthandsInput } from './output-672c1950.js';
3
3
  import { Hex } from 'viem';
4
4
  import { FixedArrayAbiType, fixedArrayToArray } from '@latticexyz/schema-type/internal';
5
+ import { r as resolveNamespacedTables } from './namespacedTables-bf676cf3.js';
5
6
 
6
7
  type get<input, key> = key extends keyof input ? input[key] : undefined;
7
8
  declare function get<input, key extends PropertyKey>(input: input, key: key): get<input, key>;
@@ -76,11 +77,11 @@ type validateKeys<validKeys extends PropertyKey, keys> = keys extends readonly s
76
77
  type ValidateTableOptions = {
77
78
  inStoreContext: boolean;
78
79
  };
79
- type requiredTableKey<inStoreContext extends boolean> = Exclude<requiredKeyOf<TableInput>, inStoreContext extends true ? "name" | "namespace" : "">;
80
+ type requiredTableKey<inStoreContext extends boolean> = Exclude<requiredKeyOf<TableInput>, inStoreContext extends true ? "label" | "namespace" : "">;
80
81
  type validateTable<input, scope extends Scope = AbiTypeScope, options extends ValidateTableOptions = {
81
82
  inStoreContext: false;
82
83
  }> = {
83
- [key in keyof input | requiredTableKey<options["inStoreContext"]>]: key extends "key" ? validateKeys<getStaticAbiTypeKeys<conform<get<input, "schema">, SchemaInput>, scope>, get<input, key>> : key extends "schema" ? validateSchema<get<input, key>, scope> : key extends "name" | "namespace" ? options["inStoreContext"] extends true ? ErrorMessage<"Overrides of `name` and `namespace` are not allowed for tables in a store config"> : key extends keyof input ? narrow<input[key]> : never : key extends keyof TableInput ? TableInput[key] : ErrorMessage<`Key \`${key & string}\` does not exist in TableInput`>;
84
+ [key in keyof input | requiredTableKey<options["inStoreContext"]>]: key extends "key" ? validateKeys<getStaticAbiTypeKeys<conform<get<input, "schema">, SchemaInput>, scope>, get<input, key>> : key extends "schema" ? validateSchema<get<input, key>, scope> : key extends "label" | "namespace" ? options["inStoreContext"] extends true ? ErrorMessage<"Overrides of `label` and `namespace` are not allowed for tables in a store config"> : key extends keyof input ? narrow<input[key]> : never : key extends keyof TableInput ? TableInput[key] : ErrorMessage<`Key \`${key & string}\` does not exist in TableInput`>;
84
85
  };
85
86
  declare function validateTable<input, scope extends Scope = AbiTypeScope>(input: input, scope?: scope, options?: ValidateTableOptions): asserts input is TableInput & input;
86
87
  type resolveTableCodegen<input extends TableInput> = show<{
@@ -88,12 +89,13 @@ type resolveTableCodegen<input extends TableInput> = show<{
88
89
  }>;
89
90
  declare function resolveTableCodegen<input extends TableInput>(input: input): resolveTableCodegen<input>;
90
91
  type resolveTable<input, scope extends Scope = Scope> = input extends TableInput ? {
91
- readonly tableId: Hex;
92
- readonly name: input["name"];
93
- readonly namespace: undefined extends input["namespace"] ? typeof TABLE_DEFAULTS.namespace : input["namespace"];
92
+ readonly label: input["label"];
94
93
  readonly type: undefined extends input["type"] ? typeof TABLE_DEFAULTS.type : input["type"];
95
- readonly key: Readonly<input["key"]>;
94
+ readonly namespace: undefined extends input["namespace"] ? typeof TABLE_DEFAULTS.namespace : input["namespace"];
95
+ readonly name: string;
96
+ readonly tableId: Hex;
96
97
  readonly schema: resolveSchema<input["schema"], scope>;
98
+ readonly key: Readonly<input["key"]>;
97
99
  readonly codegen: resolveTableCodegen<input>;
98
100
  readonly deploy: mergeIfUndefined<undefined extends input["deploy"] ? {} : input["deploy"], TABLE_DEPLOY_DEFAULTS>;
99
101
  } : never;
@@ -108,10 +110,10 @@ type validateTables<tables, scope extends Scope = AbiTypeScope> = {
108
110
  declare function validateTables<scope extends Scope = AbiTypeScope>(input: unknown, scope: scope): asserts input is TablesInput;
109
111
  type resolveTables<tables, scope extends Scope = AbiTypeScope> = show<{
110
112
  readonly [label in keyof tables]: resolveTable<mergeIfUndefined<tables[label], {
111
- name: label;
113
+ label: label;
112
114
  }>, scope>;
113
115
  }>;
114
- declare function resolveTables<tables extends TablesInput, scope extends Scope = AbiTypeScope>(tables: tables, scope?: scope): resolveTables<tables, scope>;
116
+ declare function resolveTables<tables extends TablesInput, scope extends Scope = AbiTypeScope>(tables: tables, scope: scope): resolveTables<tables, scope>;
115
117
 
116
118
  type extractInternalType<userTypes extends UserTypes> = {
117
119
  [key in keyof userTypes]: userTypes[key]["type"];
@@ -142,28 +144,76 @@ declare function resolveCodegen<codegen>(codegen: codegen): resolveCodegen<codeg
142
144
 
143
145
  type extendedScope<input> = scopeWithEnums<get<input, "enums">, scopeWithUserTypes<get<input, "userTypes">>>;
144
146
  declare function extendedScope<input>(input: input): extendedScope<input>;
145
- type validateStore<store> = {
146
- [key in keyof store]: key extends "tables" ? validateTables<store[key], extendedScope<store>> : key extends "userTypes" ? UserTypes : key extends "enums" ? narrow<store[key]> : key extends keyof StoreInput ? StoreInput[key] : ErrorMessage<`\`${key & string}\` is not a valid Store config option.`>;
147
- };
148
- declare function validateStore(store: unknown): asserts store is StoreInput;
149
- type keyPrefix<store> = store extends {
150
- namespace: infer namespace extends string;
151
- } ? namespace extends "" ? "" : `${namespace}__` : "";
152
- type resolveStore<store> = {
153
- readonly sourceDirectory: "sourceDirectory" extends keyof store ? store["sourceDirectory"] : CONFIG_DEFAULTS["sourceDirectory"];
154
- readonly tables: "tables" extends keyof store ? resolveTables<{
155
- [tableKey in keyof store["tables"] & string as `${keyPrefix<store>}${tableKey}`]: mergeIfUndefined<store["tables"][tableKey], {
156
- namespace: get<store, "namespace">;
157
- name: tableKey;
158
- }>;
159
- }, extendedScope<store>> : {};
160
- readonly userTypes: "userTypes" extends keyof store ? store["userTypes"] : {};
161
- readonly enums: "enums" extends keyof store ? show<resolveEnums<store["enums"]>> : {};
162
- readonly enumValues: "enums" extends keyof store ? show<mapEnums<store["enums"]>> : {};
163
- readonly namespace: "namespace" extends keyof store ? store["namespace"] : CONFIG_DEFAULTS["namespace"];
164
- readonly codegen: "codegen" extends keyof store ? resolveCodegen<store["codegen"]> : resolveCodegen<{}>;
165
- };
166
- declare function resolveStore<const store extends StoreInput>(store: store): resolveStore<store>;
167
- declare function defineStore<const store>(store: validateStore<store>): resolveStore<store>;
147
+ type validateStore<input> = {
148
+ [key in keyof input]: key extends "tables" ? validateTables<input[key], extendedScope<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.`>;
149
+ };
150
+ declare function validateStore(input: unknown): asserts input is StoreInput;
151
+ type resolveStore<input, namespace = "namespace" extends keyof input ? input["namespace"] : CONFIG_DEFAULTS["namespace"]> = {
152
+ readonly namespace: namespace;
153
+ readonly sourceDirectory: "sourceDirectory" extends keyof input ? input["sourceDirectory"] : CONFIG_DEFAULTS["sourceDirectory"];
154
+ readonly tables: "tables" extends keyof input ? resolveNamespacedTables<{
155
+ readonly [label in keyof input["tables"]]: resolveTable<mergeIfUndefined<input["tables"][label], {
156
+ label: label;
157
+ namespace: namespace;
158
+ }>, extendedScope<input>>;
159
+ }, namespace> : {};
160
+ readonly userTypes: "userTypes" extends keyof input ? input["userTypes"] : {};
161
+ readonly enums: "enums" extends keyof input ? show<resolveEnums<input["enums"]>> : {};
162
+ readonly enumValues: "enums" extends keyof input ? show<mapEnums<input["enums"]>> : {};
163
+ readonly codegen: "codegen" extends keyof input ? resolveCodegen<input["codegen"]> : resolveCodegen<{}>;
164
+ };
165
+ declare function resolveStore<const input extends StoreInput>(input: input): resolveStore<input>;
166
+ declare function defineStore<const input>(input: validateStore<input>): show<resolveStore<input>>;
167
+
168
+ declare const NoStaticKeyFieldError = "Invalid schema. Expected an `id` field with a static ABI type or an explicit `key` option.";
169
+ type NoStaticKeyFieldError = ErrorMessage<typeof NoStaticKeyFieldError>;
170
+ declare function isTableShorthandInput(shorthand: unknown): shorthand is TableShorthandInput;
171
+ type validateTableWithShorthand<table, scope extends Scope = AbiTypeScope, options extends ValidateTableOptions = {
172
+ inStoreContext: boolean;
173
+ }> = table extends TableShorthandInput ? validateTableShorthand<table, scope> : validateTable<table, scope, options>;
174
+ type validateTableShorthand<input, scope extends Scope = AbiTypeScope> = input extends SchemaInput ? "id" extends getStaticAbiTypeKeys<input, scope> ? conform<input, ScopedSchemaInput<scope>> : NoStaticKeyFieldError : input extends FixedArrayAbiType ? input : input extends keyof scope["types"] ? input : input extends string ? keyof scope["types"] : ScopedSchemaInput<scope>;
175
+ declare function validateTableShorthand<scope extends Scope = AbiTypeScope>(shorthand: unknown, scope?: scope): asserts shorthand is TableShorthandInput;
176
+ type resolveTableShorthand<shorthand, scope extends Scope = AbiTypeScope> = shorthand extends FixedArrayAbiType ? {
177
+ schema: {
178
+ id: "bytes32";
179
+ value: shorthand;
180
+ };
181
+ key: ["id"];
182
+ } : shorthand extends keyof scope["types"] ? {
183
+ schema: {
184
+ id: "bytes32";
185
+ value: shorthand;
186
+ };
187
+ key: ["id"];
188
+ } : shorthand extends SchemaInput ? "id" extends getStaticAbiTypeKeys<shorthand, scope> ? {
189
+ schema: shorthand;
190
+ key: ["id"];
191
+ } : never : never;
192
+ declare function resolveTableShorthand<shorthand extends TableShorthandInput, scope extends Scope = AbiTypeScope>(shorthand: shorthand, scope?: scope): resolveTableShorthand<shorthand, scope>;
193
+ declare function defineTableShorthand<shorthand, scope extends Scope = AbiTypeScope>(shorthand: validateTableShorthand<shorthand, scope>, scope?: scope): resolveTableShorthand<shorthand, scope>;
194
+ /**
195
+ * If a shorthand is provided, it is resolved to a full config.
196
+ * If a full config is provided, it is passed through.
197
+ */
198
+ type resolveTableWithShorthand<table, scope extends Scope = AbiTypeScope> = table extends TableShorthandInput ? resolveTableShorthand<table, scope> : table;
199
+ type resolveTablesWithShorthands<input, scope extends AbiTypeScope = AbiTypeScope> = {
200
+ [label in keyof input]: resolveTableWithShorthand<input[label], scope>;
201
+ };
202
+ type validateTablesWithShorthands<tables, scope extends Scope = AbiTypeScope> = {
203
+ [label in keyof tables]: validateTableWithShorthand<tables[label], scope, {
204
+ inStoreContext: true;
205
+ }>;
206
+ };
207
+ declare function validateTablesWithShorthands<scope extends Scope = AbiTypeScope>(tables: unknown, scope: scope): asserts tables is TablesWithShorthandsInput;
208
+
209
+ type validateStoreWithShorthands<store> = {
210
+ [key in keyof store]: key extends "tables" ? validateTablesWithShorthands<store[key], extendedScope<store>> : validateStore<store>[key];
211
+ };
212
+ declare function validateStoreWithShorthands(store: unknown): asserts store is StoreWithShorthandsInput;
213
+ type resolveStoreWithShorthands<store> = resolveStore<{
214
+ [key in keyof store]: key extends "tables" ? resolveTablesWithShorthands<store[key], extendedScope<store>> : store[key];
215
+ }>;
216
+ declare function resolveStoreWithShorthands<const store extends StoreWithShorthandsInput>(store: store): resolveStoreWithShorthands<store>;
217
+ declare function defineStoreWithShorthands<const store>(store: validateStoreWithShorthands<store>): resolveStoreWithShorthands<store>;
168
218
 
169
- export { CONFIG_DEFAULTS as A, resolveCodegen as B, CODEGEN_DEFAULTS as C, scopeWithEnums as D, resolveEnums as E, mapEnums as F, extractInternalType as G, isUserTypes as H, scopeWithUserTypes as I, validateUserTypes as J, TABLE_CODEGEN_DEFAULTS as T, ValidKeys as V, getPath as a, resolveSchema as b, isSchemaInput as c, defineSchema as d, isValidPrimaryKey as e, validateKeys as f, get as g, hasOwnKey as h, isObject as i, ValidateTableOptions as j, requiredTableKey as k, validateTable as l, mergeIfUndefined as m, resolveTableCodegen as n, resolveTable as o, parseNumber as p, defineTable as q, resolveStore as r, validateTables as s, resolveTables as t, extendedScope as u, validateSchema as v, validateStore as w, defineStore as x, TABLE_DEPLOY_DEFAULTS as y, TABLE_DEFAULTS as z };
219
+ export { resolveTableCodegen as A, resolveTable as B, defineTable as C, validateTables as D, resolveTables as E, extendedScope as F, validateStore as G, resolveStore as H, defineStore as I, CODEGEN_DEFAULTS as J, TABLE_DEPLOY_DEFAULTS as K, TABLE_DEFAULTS as L, CONFIG_DEFAULTS as M, NoStaticKeyFieldError as N, resolveCodegen as O, scopeWithEnums as P, resolveEnums as Q, mapEnums as R, extractInternalType as S, TABLE_CODEGEN_DEFAULTS as T, isUserTypes as U, ValidKeys as V, scopeWithUserTypes as W, validateUserTypes as X, getPath as a, defineSchema as b, isSchemaInput as c, defineStoreWithShorthands as d, isTableShorthandInput as e, validateTableWithShorthand as f, get as g, hasOwnKey as h, isObject as i, validateTableShorthand as j, resolveTableShorthand as k, defineTableShorthand as l, mergeIfUndefined as m, resolveTableWithShorthand as n, resolveTablesWithShorthands as o, parseNumber as p, validateTablesWithShorthands as q, resolveSchema as r, validateStoreWithShorthands as s, resolveStoreWithShorthands as t, isValidPrimaryKey as u, validateSchema as v, validateKeys as w, ValidateTableOptions as x, requiredTableKey as y, validateTable as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@latticexyz/store",
3
- "version": "2.0.13-main-609de113f",
3
+ "version": "3.0.0-main-560fd6a0c",
4
4
  "description": "Store",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,9 +14,7 @@
14
14
  "./internal": "./dist/internal.js",
15
15
  "./mud.config": "./dist/mud.config.js",
16
16
  "./codegen": "./dist/codegen.js",
17
- "./config": "./dist/config.js",
18
17
  "./config/v2": "./dist/config/v2.js",
19
- "./register": "./dist/register.js",
20
18
  "./out/*": "./out/*"
21
19
  },
22
20
  "typesVersions": {
@@ -33,14 +31,8 @@
33
31
  "codegen": [
34
32
  "./dist/codegen.d.ts"
35
33
  ],
36
- "config": [
37
- "./dist/config.d.ts"
38
- ],
39
34
  "config/v2": [
40
35
  "./dist/config/v2.d.ts"
41
- ],
42
- "register": [
43
- "./dist/register.d.ts"
44
36
  ]
45
37
  }
46
38
  },
@@ -54,11 +46,10 @@
54
46
  "abitype": "1.0.0",
55
47
  "arktype": "1.0.29-alpha",
56
48
  "viem": "2.9.20",
57
- "zod": "^3.22.2",
58
- "@latticexyz/common": "2.0.13-main-609de113f",
59
- "@latticexyz/config": "2.0.13-main-609de113f",
60
- "@latticexyz/protocol-parser": "2.0.13-main-609de113f",
61
- "@latticexyz/schema-type": "2.0.13-main-609de113f"
49
+ "@latticexyz/common": "3.0.0-main-560fd6a0c",
50
+ "@latticexyz/config": "3.0.0-main-560fd6a0c",
51
+ "@latticexyz/protocol-parser": "3.0.0-main-560fd6a0c",
52
+ "@latticexyz/schema-type": "3.0.0-main-560fd6a0c"
62
53
  },
63
54
  "devDependencies": {
64
55
  "@arktype/attest": "0.7.5",
@@ -71,8 +62,8 @@
71
62
  "tsup": "^6.7.0",
72
63
  "tsx": "^3.12.6",
73
64
  "vitest": "0.34.6",
74
- "@latticexyz/abi-ts": "2.0.13-main-609de113f",
75
- "@latticexyz/gas-report": "2.0.13-main-609de113f"
65
+ "@latticexyz/abi-ts": "3.0.0-main-560fd6a0c",
66
+ "@latticexyz/gas-report": "3.0.0-main-560fd6a0c"
76
67
  },
77
68
  "scripts": {
78
69
  "build": "pnpm run build:tightcoder && pnpm run build:mud && pnpm run build:abi && pnpm run build:abi-ts && pnpm run build:js",
@@ -1,2 +0,0 @@
1
- function a(e,t){return typeof e=="object"&&e!=null&&n(e,t)?e[t]:void 0}function _(e,t){return t.length?_(a(e,t[0]),t.slice(1)):e}function n(e,t){return typeof e=="object"&&e!==null&&e.hasOwnProperty(t)}function i(e){return e!=null&&typeof e=="object"}function c(e,t){let s=[...new Set([...Object.keys(e),...Object.keys(t)])];return Object.fromEntries(s.map(o=>[o,e[o]??t[o]]))}var m={storeImportPath:"@latticexyz/store/src/",userTypesFilename:"common.sol",outputDirectory:"codegen",namespaceDirectories:!1,indexFilename:"index.sol"},y={outputDirectory:"tables",tableIdArgument:!1,storeArgument:!1},k={disabled:!1},u={namespace:"",type:"table"},l={sourceDirectory:"src",namespace:""};import{schemaAbiTypes as C}from"@latticexyz/schema-type/internal";var X={types:{}},r={types:Object.fromEntries(C.map(e=>[e,e]))};function d(e,t){return{types:{...e.types,...t}}}import{fixedArrayToArray as F,isFixedArrayAbiType as f}from"@latticexyz/schema-type/internal";function x(e,t=r){if(!i(e))throw new Error(`Expected schema, received ${JSON.stringify(e)}`);for(let s of Object.values(e))if(!f(s)&&!n(t.types,s))throw new Error(`"${String(s)}" is not a valid type in this scope.`)}function T(e,t=r){return Object.fromEntries(Object.entries(e).map(([s,o])=>[s,{type:f(o)?F(o):t.types[o],internalType:o}]))}function re(e,t=r){return x(e,t),T(e,t)}function pe(e,t=r){return typeof e=="object"&&e!=null&&Object.values(e).every(s=>f(s)||n(t.types,s))}import{isStaticAbiType as E}from"@latticexyz/schema-type/internal";import{resourceToHex as j}from"@latticexyz/common";function K(e,t=r){return Object.entries(e).filter(([,s])=>n(t.types,s)&&E(t.types[s])).map(([s])=>s)}function N(e,t,s=r){return Array.isArray(e)&&e.every(o=>n(t,o)&&n(s.types,t[o])&&E(s.types[t[o]]))}function b(e,t=r,s={inStoreContext:!1}){if(typeof e!="object"||e==null)throw new Error(`Expected full table config, got \`${JSON.stringify(e)}\``);if(!n(e,"schema"))throw new Error("Missing schema input");if(x(e.schema,t),!n(e,"key")||!N(e.key,e.schema,t))throw new Error(`Invalid key. Expected \`(${K(e.schema,t).map(o=>`"${String(o)}"`).join(" | ")})[]\`, received \`${n(e,"key")&&Array.isArray(e.key)?`[${e.key.map(o=>`"${o}"`).join(", ")}]`:String(a(e,"key"))}\``);if(s.inStoreContext&&n(e,"name")||n(e,"namespace"))throw new Error("Overrides of `name` and `namespace` are not allowed for tables in a store config.")}function P(e){let t=e.codegen;return{outputDirectory:a(t,"outputDirectory")??y.outputDirectory,tableIdArgument:a(t,"tableIdArgument")??y.tableIdArgument,storeArgument:a(t,"storeArgument")??y.storeArgument,dataStruct:a(t,"dataStruct")??Object.keys(e.schema).length-e.key.length>1}}function S(e,t=r){let s=e.name,o=e.type??u.type,p=e.namespace??u.namespace;return{tableId:e.tableId??j({type:o,namespace:p,name:s}),name:s,namespace:p,type:o,key:e.key,schema:T(e.schema,t),codegen:P(e),deploy:c(e.deploy??{},k)}}function xe(e,t=r){return b(e,t),S(e,t)}function g(e,t){if(i(e)){for(let s of Object.values(e))b(s,t,{inStoreContext:!0});return}throw new Error(`Expected store config, received ${JSON.stringify(e)}`)}function h(e,t=r){if(!i(e))throw new Error(`Expected tables config, received ${JSON.stringify(e)}`);return Object.fromEntries(Object.entries(e).map(([s,o])=>[s,S(c(o,{name:s}),t)]))}import{mapObject as $}from"@latticexyz/common/utils";import{isSchemaAbiType as B}from"@latticexyz/schema-type/internal";function G(e){return $(e,t=>t.type)}function M(e){return i(e)&&Object.values(e).every(t=>B(t.type))}function A(e,t=r){return M(e)?d(t,G(e)):t}function v(e){if(!i(e))throw new Error(`Expected userTypes, received ${JSON.stringify(e)}`);for(let{type:t}of Object.values(e))if(!n(r.types,t))throw new Error(`"${String(t)}" is not a valid ABI type.`)}import{flatMorph as I}from"@arktype/util";function V(e){return typeof e=="object"&&e!=null&&Object.values(e).every(t=>Array.isArray(t)&&t.every(s=>typeof s=="string"))}function D(e,t=r){if(V(e)){let s=Object.fromEntries(Object.keys(e).map(o=>[o,"uint8"]));return d(t,s)}return t}function W(e){return e}function O(e){return I(e,(t,s)=>[t,I(s,(o,p)=>[p,o])])}function w(e){return i(e)?c(e,m):m}import{flatMorph as J}from"@arktype/util";function U(e){return D(a(e,"enums"),A(a(e,"userTypes")))}function Y(e){let t=U(e);n(e,"tables")&&g(e.tables,t),n(e,"userTypes")&&v(e.userTypes)}function q(e){let t=w(e.codegen);return{sourceDirectory:e.sourceDirectory??l.sourceDirectory,tables:h(J(e.tables??{},(s,o)=>{let p=e.namespace;return[p?`${p}__${s}`:s,c(o,{namespace:p,name:s,codegen:c(o.codegen??{},{outputDirectory:t.namespaceDirectories&&p?.length?`${p}/tables`:"tables"})})]}),U(e)),userTypes:e.userTypes??{},enums:e.enums??{},enumValues:O(e.enums??{}),namespace:e.namespace??l.namespace,codegen:t}}function We(e){return Y(e),q(e)}export{a,_ as b,n as c,i as d,c as e,m as f,y as g,k as h,u as i,l as j,X as k,r as l,d as m,x as n,T as o,re as p,pe as q,N as r,b as s,P as t,S as u,xe as v,g as w,h as x,G as y,M as z,A,v as B,D as C,W as D,O as E,w as F,U as G,Y as H,q as I,We as J};
2
- //# sourceMappingURL=chunk-M5RJAVGF.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../ts/config/v2/generics.ts","../ts/config/v2/defaults.ts","../ts/config/v2/scope.ts","../ts/config/v2/schema.ts","../ts/config/v2/table.ts","../ts/config/v2/tables.ts","../ts/config/v2/userTypes.ts","../ts/config/v2/enums.ts","../ts/config/v2/codegen.ts","../ts/config/v2/store.ts"],"sourcesContent":["import { merge } from \"@arktype/util\";\n\nexport type get<input, key> = key extends keyof input ? input[key] : undefined;\n\nexport function get<input, key extends PropertyKey>(input: input, key: key): get<input, key> {\n return (typeof input === \"object\" && input != null && hasOwnKey(input, key) ? input[key] : undefined) as never;\n}\n\nexport type getPath<input, path extends readonly PropertyKey[]> = path extends readonly [\n infer head,\n ...infer tail extends PropertyKey[],\n]\n ? head extends keyof input\n ? getPath<input[head], tail>\n : undefined\n : input;\n\nexport function getPath<input, path extends readonly PropertyKey[]>(input: input, path: path): getPath<input, path> {\n return path.length ? (getPath(get(input, path[0]), path.slice(1)) as never) : (input as never);\n}\n\nexport function hasOwnKey<obj, const key extends PropertyKey>(\n object: obj,\n key: key,\n): object is { [k in key]: k extends keyof obj ? obj[k] : unknown } & obj {\n // eslint-disable-next-line no-prototype-builtins\n return typeof object === \"object\" && object !== null && object.hasOwnProperty(key);\n}\n\nexport function isObject<input>(input: input): input is input & object {\n return input != null && typeof input === \"object\";\n}\n\nexport type mergeIfUndefined<base, merged> = merge<\n base,\n {\n [key in keyof merged]: key extends keyof base\n ? undefined extends base[key]\n ? merged[key]\n : base[key]\n : merged[key];\n }\n>;\n\nexport function mergeIfUndefined<base extends object, merged extends object>(\n base: base,\n merged: merged,\n): mergeIfUndefined<base, merged> {\n const allKeys = [...new Set([...Object.keys(base), ...Object.keys(merged)])];\n return Object.fromEntries(\n allKeys.map((key) => [key, base[key as keyof base] ?? merged[key as keyof merged]]),\n ) as never;\n}\n\nexport type parseNumber<T> = T extends `${infer N extends number}` ? N : never;\n","import { CodegenInput, StoreInput, TableCodegenInput, TableDeployInput, TableInput } from \"./input\";\n\nexport const CODEGEN_DEFAULTS = {\n storeImportPath: \"@latticexyz/store/src/\",\n userTypesFilename: \"common.sol\",\n outputDirectory: \"codegen\",\n // TODO: default to true if using top-level `namespaces` key (once its migrated to store)\n namespaceDirectories: false,\n indexFilename: \"index.sol\",\n} as const satisfies CodegenInput;\n\nexport type CODEGEN_DEFAULTS = typeof CODEGEN_DEFAULTS;\n\nexport const TABLE_CODEGEN_DEFAULTS = {\n outputDirectory: \"tables\" as string,\n tableIdArgument: false,\n storeArgument: false,\n} as const satisfies TableCodegenInput;\n\nexport type TABLE_CODEGEN_DEFAULTS = typeof TABLE_CODEGEN_DEFAULTS;\n\nexport const TABLE_DEPLOY_DEFAULTS = {\n disabled: false,\n} as const satisfies TableDeployInput;\n\nexport type TABLE_DEPLOY_DEFAULTS = typeof TABLE_DEPLOY_DEFAULTS;\n\nexport const TABLE_DEFAULTS = {\n namespace: \"\",\n type: \"table\",\n} as const satisfies Pick<TableInput, \"namespace\" | \"type\">;\n\nexport type TABLE_DEFAULTS = typeof TABLE_DEFAULTS;\n\nexport const CONFIG_DEFAULTS = {\n sourceDirectory: \"src\",\n namespace: \"\",\n} as const satisfies StoreInput;\n\nexport type CONFIG_DEFAULTS = typeof CONFIG_DEFAULTS;\n","import { Dict, show } from \"@arktype/util\";\nimport { SchemaInput } from \"./input\";\nimport { StaticAbiType, schemaAbiTypes } from \"@latticexyz/schema-type/internal\";\nimport { AbiType } from \"./output\";\n\nexport const Scope = { types: {} } as const satisfies ScopeOptions;\nexport type Scope = typeof Scope;\n\nexport type AbiTypeScope = ScopeOptions<{ [t in AbiType]: t }>;\nexport const AbiTypeScope = {\n types: Object.fromEntries(schemaAbiTypes.map((abiType) => [abiType, abiType])),\n} as AbiTypeScope;\n\nexport type ScopeOptions<types extends Dict<string, AbiType> = Dict<string, AbiType>> = {\n types: types;\n};\n\nexport type getStaticAbiTypeKeys<\n schema extends SchemaInput,\n scope extends Scope = AbiTypeScope,\n> = SchemaInput extends schema\n ? string\n : {\n [key in keyof schema]: scope[\"types\"] extends { [_ in schema[key]]: StaticAbiType } ? key : never;\n }[keyof schema];\n\nexport type extendScope<scope extends ScopeOptions, additionalTypes extends Dict<string, AbiType>> = show<\n ScopeOptions<show<scope[\"types\"] & additionalTypes>>\n>;\n\nexport function extendScope<scope extends ScopeOptions, additionalTypes extends Dict<string, AbiType>>(\n scope: scope,\n additionalTypes: additionalTypes,\n): extendScope<scope, additionalTypes> {\n return {\n types: {\n ...scope.types,\n ...additionalTypes,\n },\n };\n}\n","import { conform, show } from \"@arktype/util\";\nimport { AbiTypeScope, Scope } from \"./scope\";\nimport { hasOwnKey, isObject } from \"./generics\";\nimport { SchemaInput } from \"./input\";\nimport { FixedArrayAbiType, fixedArrayToArray, isFixedArrayAbiType } from \"@latticexyz/schema-type/internal\";\n\nexport type validateSchema<schema, scope extends Scope = AbiTypeScope> = schema extends string\n ? SchemaInput\n : {\n [key in keyof schema]: schema[key] extends FixedArrayAbiType\n ? schema[key]\n : conform<schema[key], keyof scope[\"types\"]>;\n };\n\nexport function validateSchema<scope extends Scope = AbiTypeScope>(\n schema: unknown,\n scope: scope = AbiTypeScope as never,\n): asserts schema is SchemaInput {\n if (!isObject(schema)) {\n throw new Error(`Expected schema, received ${JSON.stringify(schema)}`);\n }\n\n for (const internalType of Object.values(schema)) {\n if (isFixedArrayAbiType(internalType)) continue;\n if (hasOwnKey(scope.types, internalType)) continue;\n throw new Error(`\"${String(internalType)}\" is not a valid type in this scope.`);\n }\n}\n\nexport type resolveSchema<schema, scope extends Scope> = show<{\n readonly [key in keyof schema]: {\n /** the Solidity primitive ABI type */\n readonly type: schema[key] extends FixedArrayAbiType\n ? fixedArrayToArray<schema[key]>\n : scope[\"types\"][schema[key] & keyof scope[\"types\"]];\n /** the user defined type or Solidity primitive ABI type */\n readonly internalType: schema[key];\n };\n}>;\n\nexport function resolveSchema<schema extends SchemaInput, scope extends Scope = AbiTypeScope>(\n schema: schema,\n scope: scope = AbiTypeScope as unknown as scope,\n): resolveSchema<schema, scope> {\n return Object.fromEntries(\n Object.entries(schema).map(([key, internalType]) => [\n key,\n {\n type: isFixedArrayAbiType(internalType) ? fixedArrayToArray(internalType) : scope.types[internalType as never],\n internalType,\n },\n ]),\n ) as never;\n}\n\nexport function defineSchema<schema, scope extends AbiTypeScope = AbiTypeScope>(\n schema: validateSchema<schema, scope>,\n scope: scope = AbiTypeScope as scope,\n): resolveSchema<schema, scope> {\n validateSchema(schema, scope);\n return resolveSchema(schema, scope) as never;\n}\n\nexport function isSchemaInput<scope extends Scope = AbiTypeScope>(\n input: unknown,\n scope: scope = AbiTypeScope as never,\n): input is SchemaInput {\n return (\n typeof input === \"object\" &&\n input != null &&\n Object.values(input).every((fieldType) => isFixedArrayAbiType(fieldType) || hasOwnKey(scope.types, fieldType))\n );\n}\n","import { ErrorMessage, conform, show, narrow, requiredKeyOf } from \"@arktype/util\";\nimport { isStaticAbiType } from \"@latticexyz/schema-type/internal\";\nimport { Hex } from \"viem\";\nimport { get, hasOwnKey, mergeIfUndefined } from \"./generics\";\nimport { resolveSchema, validateSchema } from \"./schema\";\nimport { AbiTypeScope, Scope, getStaticAbiTypeKeys } from \"./scope\";\nimport { TableCodegen } from \"./output\";\nimport { TABLE_CODEGEN_DEFAULTS, TABLE_DEFAULTS, TABLE_DEPLOY_DEFAULTS } from \"./defaults\";\nimport { resourceToHex } from \"@latticexyz/common\";\nimport { SchemaInput, TableInput } from \"./input\";\n\nexport type ValidKeys<schema extends SchemaInput, scope extends Scope> = readonly [\n getStaticAbiTypeKeys<schema, scope>,\n ...getStaticAbiTypeKeys<schema, scope>[],\n];\n\nfunction getValidKeys<schema extends SchemaInput, scope extends Scope = AbiTypeScope>(\n schema: schema,\n scope: scope = AbiTypeScope as unknown as scope,\n): ValidKeys<schema, scope> {\n return Object.entries(schema)\n .filter(([, internalType]) => hasOwnKey(scope.types, internalType) && isStaticAbiType(scope.types[internalType]))\n .map(([key]) => key) as never;\n}\n\nexport function isValidPrimaryKey<schema extends SchemaInput, scope extends Scope>(\n key: unknown,\n schema: schema,\n scope: scope = AbiTypeScope as unknown as scope,\n): key is ValidKeys<schema, scope> {\n return (\n Array.isArray(key) &&\n key.every(\n (key) =>\n hasOwnKey(schema, key) && hasOwnKey(scope.types, schema[key]) && isStaticAbiType(scope.types[schema[key]]),\n )\n );\n}\n\nexport type validateKeys<validKeys extends PropertyKey, keys> = keys extends readonly string[]\n ? {\n readonly [i in keyof keys]: keys[i] extends validKeys ? keys[i] : validKeys;\n }\n : readonly string[];\n\nexport type ValidateTableOptions = { inStoreContext: boolean };\n\nexport type requiredTableKey<inStoreContext extends boolean> = Exclude<\n requiredKeyOf<TableInput>,\n inStoreContext extends true ? \"name\" | \"namespace\" : \"\"\n>;\n\nexport type validateTable<\n input,\n scope extends Scope = AbiTypeScope,\n options extends ValidateTableOptions = { inStoreContext: false },\n> = {\n [key in keyof input | requiredTableKey<options[\"inStoreContext\"]>]: key extends \"key\"\n ? validateKeys<getStaticAbiTypeKeys<conform<get<input, \"schema\">, SchemaInput>, scope>, get<input, key>>\n : key extends \"schema\"\n ? validateSchema<get<input, key>, scope>\n : key extends \"name\" | \"namespace\"\n ? options[\"inStoreContext\"] extends true\n ? ErrorMessage<\"Overrides of `name` and `namespace` are not allowed for tables in a store config\">\n : key extends keyof input\n ? narrow<input[key]>\n : never\n : key extends keyof TableInput\n ? TableInput[key]\n : ErrorMessage<`Key \\`${key & string}\\` does not exist in TableInput`>;\n};\n\nexport function validateTable<input, scope extends Scope = AbiTypeScope>(\n input: input,\n scope: scope = AbiTypeScope as unknown as scope,\n options: ValidateTableOptions = { inStoreContext: false },\n): asserts input is TableInput & input {\n if (typeof input !== \"object\" || input == null) {\n throw new Error(`Expected full table config, got \\`${JSON.stringify(input)}\\``);\n }\n\n if (!hasOwnKey(input, \"schema\")) {\n throw new Error(\"Missing schema input\");\n }\n validateSchema(input.schema, scope);\n\n if (!hasOwnKey(input, \"key\") || !isValidPrimaryKey(input[\"key\"], input[\"schema\"], scope)) {\n throw new Error(\n `Invalid key. Expected \\`(${getValidKeys(input[\"schema\"], scope)\n .map((item) => `\"${String(item)}\"`)\n .join(\" | \")})[]\\`, received \\`${\n hasOwnKey(input, \"key\") && Array.isArray(input.key)\n ? `[${input.key.map((item) => `\"${item}\"`).join(\", \")}]`\n : String(get(input, \"key\"))\n }\\``,\n );\n }\n\n if ((options.inStoreContext && hasOwnKey(input, \"name\")) || hasOwnKey(input, \"namespace\")) {\n throw new Error(\"Overrides of `name` and `namespace` are not allowed for tables in a store config.\");\n }\n}\n\nexport type resolveTableCodegen<input extends TableInput> = show<{\n [key in keyof TableCodegen]-?: key extends keyof input[\"codegen\"]\n ? undefined extends input[\"codegen\"][key]\n ? key extends \"dataStruct\"\n ? boolean\n : key extends keyof TABLE_CODEGEN_DEFAULTS\n ? TABLE_CODEGEN_DEFAULTS[key]\n : never\n : input[\"codegen\"][key]\n : // dataStruct isn't narrowed, because its value is conditional on the number of value schema fields\n key extends \"dataStruct\"\n ? boolean\n : key extends keyof TABLE_CODEGEN_DEFAULTS\n ? TABLE_CODEGEN_DEFAULTS[key]\n : never;\n}>;\n\nexport function resolveTableCodegen<input extends TableInput>(input: input): resolveTableCodegen<input> {\n const options = input.codegen;\n return {\n outputDirectory: get(options, \"outputDirectory\") ?? TABLE_CODEGEN_DEFAULTS.outputDirectory,\n tableIdArgument: get(options, \"tableIdArgument\") ?? TABLE_CODEGEN_DEFAULTS.tableIdArgument,\n storeArgument: get(options, \"storeArgument\") ?? TABLE_CODEGEN_DEFAULTS.storeArgument,\n // dataStruct is true if there are at least 2 value fields\n dataStruct: get(options, \"dataStruct\") ?? Object.keys(input.schema).length - input.key.length > 1,\n } satisfies TableCodegen as never;\n}\n\nexport type resolveTable<input, scope extends Scope = Scope> = input extends TableInput\n ? {\n readonly tableId: Hex;\n readonly name: input[\"name\"];\n readonly namespace: undefined extends input[\"namespace\"] ? typeof TABLE_DEFAULTS.namespace : input[\"namespace\"];\n readonly type: undefined extends input[\"type\"] ? typeof TABLE_DEFAULTS.type : input[\"type\"];\n readonly key: Readonly<input[\"key\"]>;\n readonly schema: resolveSchema<input[\"schema\"], scope>;\n readonly codegen: resolveTableCodegen<input>;\n readonly deploy: mergeIfUndefined<\n undefined extends input[\"deploy\"] ? {} : input[\"deploy\"],\n TABLE_DEPLOY_DEFAULTS\n >;\n }\n : never;\n\nexport function resolveTable<input extends TableInput, scope extends Scope = AbiTypeScope>(\n input: input,\n scope: scope = AbiTypeScope as unknown as scope,\n): resolveTable<input, scope> {\n const name = input.name;\n const type = input.type ?? TABLE_DEFAULTS.type;\n const namespace = input.namespace ?? TABLE_DEFAULTS.namespace;\n const tableId = input.tableId ?? resourceToHex({ type, namespace, name });\n\n return {\n tableId,\n name,\n namespace,\n type,\n key: input.key,\n schema: resolveSchema(input.schema, scope),\n codegen: resolveTableCodegen(input),\n deploy: mergeIfUndefined(input.deploy ?? {}, TABLE_DEPLOY_DEFAULTS),\n } as never;\n}\n\nexport function defineTable<input, scope extends Scope = AbiTypeScope>(\n input: validateTable<input, scope>,\n scope: scope = AbiTypeScope as unknown as scope,\n): resolveTable<input, scope> {\n validateTable(input, scope);\n return resolveTable(input, scope) as never;\n}\n","import { ErrorMessage, show } from \"@arktype/util\";\nimport { isObject, mergeIfUndefined } from \"./generics\";\nimport { TablesInput } from \"./input\";\nimport { Scope, AbiTypeScope } from \"./scope\";\nimport { validateTable, resolveTable } from \"./table\";\n\nexport type validateTables<tables, scope extends Scope = AbiTypeScope> = {\n [label in keyof tables]: tables[label] extends object\n ? validateTable<tables[label], scope, { inStoreContext: true }>\n : ErrorMessage<`Expected full table config.`>;\n};\n\nexport function validateTables<scope extends Scope = AbiTypeScope>(\n input: unknown,\n scope: scope,\n): asserts input is TablesInput {\n if (isObject(input)) {\n for (const table of Object.values(input)) {\n validateTable(table, scope, { inStoreContext: true });\n }\n return;\n }\n throw new Error(`Expected store config, received ${JSON.stringify(input)}`);\n}\n\nexport type resolveTables<tables, scope extends Scope = AbiTypeScope> = show<{\n readonly [label in keyof tables]: resolveTable<mergeIfUndefined<tables[label], { name: label }>, scope>;\n}>;\n\nexport function resolveTables<tables extends TablesInput, scope extends Scope = AbiTypeScope>(\n tables: tables,\n scope: scope = AbiTypeScope as unknown as scope,\n): resolveTables<tables, scope> {\n if (!isObject(tables)) {\n throw new Error(`Expected tables config, received ${JSON.stringify(tables)}`);\n }\n\n return Object.fromEntries(\n Object.entries(tables).map(([label, table]) => {\n return [label, resolveTable(mergeIfUndefined(table, { name: label }), scope)];\n }),\n ) as never;\n}\n","import { mapObject } from \"@latticexyz/common/utils\";\nimport { UserTypes } from \"./output\";\nimport { isSchemaAbiType } from \"@latticexyz/schema-type/internal\";\nimport { AbiTypeScope, extendScope } from \"./scope\";\nimport { hasOwnKey, isObject } from \"./generics\";\n\nexport type extractInternalType<userTypes extends UserTypes> = { [key in keyof userTypes]: userTypes[key][\"type\"] };\n\nexport function extractInternalType<userTypes extends UserTypes>(userTypes: userTypes): extractInternalType<userTypes> {\n return mapObject(userTypes, (userType) => userType.type);\n}\n\nexport function isUserTypes(userTypes: unknown): userTypes is UserTypes {\n return isObject(userTypes) && Object.values(userTypes).every((userType) => isSchemaAbiType(userType.type));\n}\n\nexport type scopeWithUserTypes<userTypes, scope extends AbiTypeScope = AbiTypeScope> = UserTypes extends userTypes\n ? scope\n : userTypes extends UserTypes\n ? extendScope<scope, extractInternalType<userTypes>>\n : scope;\n\nexport function scopeWithUserTypes<userTypes, scope extends AbiTypeScope = AbiTypeScope>(\n userTypes: userTypes,\n scope: scope = AbiTypeScope as scope,\n): scopeWithUserTypes<userTypes, scope> {\n return (isUserTypes(userTypes) ? extendScope(scope, extractInternalType(userTypes)) : scope) as never;\n}\n\nexport function validateUserTypes(userTypes: unknown): asserts userTypes is UserTypes {\n if (!isObject(userTypes)) {\n throw new Error(`Expected userTypes, received ${JSON.stringify(userTypes)}`);\n }\n\n for (const { type } of Object.values(userTypes)) {\n if (!hasOwnKey(AbiTypeScope.types, type)) {\n throw new Error(`\"${String(type)}\" is not a valid ABI type.`);\n }\n }\n}\n","import { flatMorph } from \"@arktype/util\";\nimport { EnumsInput } from \"./input\";\nimport { AbiTypeScope, extendScope } from \"./scope\";\nimport { parseNumber } from \"./generics\";\n\nfunction isEnums(enums: unknown): enums is EnumsInput {\n return (\n typeof enums === \"object\" &&\n enums != null &&\n Object.values(enums).every((item) => Array.isArray(item) && item.every((element) => typeof element === \"string\"))\n );\n}\n\nexport type scopeWithEnums<enums, scope extends AbiTypeScope = AbiTypeScope> = EnumsInput extends enums\n ? scope\n : enums extends EnumsInput\n ? extendScope<scope, { [key in keyof enums]: \"uint8\" }>\n : scope;\n\nexport function scopeWithEnums<enums, scope extends AbiTypeScope = AbiTypeScope>(\n enums: enums,\n scope: scope = AbiTypeScope as scope,\n): scopeWithEnums<enums, scope> {\n if (isEnums(enums)) {\n const enumScope = Object.fromEntries(Object.keys(enums).map((key) => [key, \"uint8\" as const]));\n return extendScope(scope, enumScope) as never;\n }\n return scope as never;\n}\n\nexport type resolveEnums<enums> = {\n readonly [key in keyof enums]: Readonly<enums[key]>;\n};\n\nexport function resolveEnums<enums extends EnumsInput>(enums: enums): resolveEnums<enums> {\n return enums;\n}\n\nexport type mapEnums<enums> = {\n readonly [key in keyof enums]: {\n readonly [element in keyof enums[key] as enums[key][element] & string]: parseNumber<element>;\n };\n};\n\nexport function mapEnums<enums extends EnumsInput>(enums: enums): resolveEnums<enums> {\n return flatMorph(enums as EnumsInput, (enumName, enumElements) => [\n enumName,\n flatMorph(enumElements, (enumIndex, enumElement) => [enumElement, enumIndex]),\n ]) as never;\n}\n","import { CODEGEN_DEFAULTS } from \"./defaults\";\nimport { isObject, mergeIfUndefined } from \"./generics\";\n\nexport type resolveCodegen<codegen> = codegen extends {}\n ? mergeIfUndefined<codegen, CODEGEN_DEFAULTS>\n : CODEGEN_DEFAULTS;\n\nexport function resolveCodegen<codegen>(codegen: codegen): resolveCodegen<codegen> {\n return (\n isObject(codegen) ? mergeIfUndefined(codegen, CODEGEN_DEFAULTS) : CODEGEN_DEFAULTS\n ) as resolveCodegen<codegen>;\n}\n","import { ErrorMessage, show, flatMorph, narrow } from \"@arktype/util\";\nimport { get, hasOwnKey, mergeIfUndefined } from \"./generics\";\nimport { UserTypes } from \"./output\";\nimport { CONFIG_DEFAULTS } from \"./defaults\";\nimport { StoreInput } from \"./input\";\nimport { resolveTables, validateTables } from \"./tables\";\nimport { scopeWithUserTypes, validateUserTypes } from \"./userTypes\";\nimport { mapEnums, resolveEnums, scopeWithEnums } from \"./enums\";\nimport { resolveCodegen } from \"./codegen\";\n\nexport type extendedScope<input> = scopeWithEnums<get<input, \"enums\">, scopeWithUserTypes<get<input, \"userTypes\">>>;\n\nexport function extendedScope<input>(input: input): extendedScope<input> {\n return scopeWithEnums(get(input, \"enums\"), scopeWithUserTypes(get(input, \"userTypes\")));\n}\n\nexport type validateStore<store> = {\n [key in keyof store]: key extends \"tables\"\n ? validateTables<store[key], extendedScope<store>>\n : key extends \"userTypes\"\n ? UserTypes\n : key extends \"enums\"\n ? narrow<store[key]>\n : key extends keyof StoreInput\n ? StoreInput[key]\n : ErrorMessage<`\\`${key & string}\\` is not a valid Store config option.`>;\n};\n\nexport function validateStore(store: unknown): asserts store is StoreInput {\n const scope = extendedScope(store);\n if (hasOwnKey(store, \"tables\")) {\n validateTables(store.tables, scope);\n }\n\n if (hasOwnKey(store, \"userTypes\")) {\n validateUserTypes(store.userTypes);\n }\n}\n\ntype keyPrefix<store> = store extends { namespace: infer namespace extends string }\n ? namespace extends \"\"\n ? \"\"\n : `${namespace}__`\n : \"\";\n\nexport type resolveStore<store> = {\n readonly sourceDirectory: \"sourceDirectory\" extends keyof store\n ? store[\"sourceDirectory\"]\n : CONFIG_DEFAULTS[\"sourceDirectory\"];\n readonly tables: \"tables\" extends keyof store\n ? resolveTables<\n {\n [tableKey in keyof store[\"tables\"] & string as `${keyPrefix<store>}${tableKey}`]: mergeIfUndefined<\n store[\"tables\"][tableKey],\n { namespace: get<store, \"namespace\">; name: tableKey }\n >;\n },\n extendedScope<store>\n >\n : {};\n readonly userTypes: \"userTypes\" extends keyof store ? store[\"userTypes\"] : {};\n readonly enums: \"enums\" extends keyof store ? show<resolveEnums<store[\"enums\"]>> : {};\n readonly enumValues: \"enums\" extends keyof store ? show<mapEnums<store[\"enums\"]>> : {};\n readonly namespace: \"namespace\" extends keyof store ? store[\"namespace\"] : CONFIG_DEFAULTS[\"namespace\"];\n readonly codegen: \"codegen\" extends keyof store ? resolveCodegen<store[\"codegen\"]> : resolveCodegen<{}>;\n};\n\nexport function resolveStore<const store extends StoreInput>(store: store): resolveStore<store> {\n // TODO: default `namespaceDirectories` to true if using top-level `namespaces` key (once its migrated to store)\n const codegen = resolveCodegen(store.codegen);\n return {\n sourceDirectory: store.sourceDirectory ?? CONFIG_DEFAULTS[\"sourceDirectory\"],\n tables: resolveTables(\n flatMorph(store.tables ?? {}, (name, table) => {\n const namespace = store.namespace;\n const key = namespace ? `${namespace}__${name}` : name;\n return [\n key,\n mergeIfUndefined(table, {\n namespace: namespace,\n name,\n codegen: mergeIfUndefined(table.codegen ?? {}, {\n outputDirectory: codegen.namespaceDirectories && namespace?.length ? `${namespace}/tables` : \"tables\",\n }),\n }),\n ];\n }),\n extendedScope(store),\n ),\n userTypes: store.userTypes ?? {},\n enums: resolveEnums(store.enums ?? {}),\n enumValues: mapEnums(store.enums ?? {}),\n namespace: store.namespace ?? CONFIG_DEFAULTS[\"namespace\"],\n codegen,\n } as never;\n}\n\nexport function defineStore<const store>(store: validateStore<store>): resolveStore<store> {\n validateStore(store);\n return resolveStore(store) as never;\n}\n"],"mappings":"AAIO,SAASA,EAAoCC,EAAcC,EAA2B,CAC3F,OAAQ,OAAOD,GAAU,UAAYA,GAAS,MAAQE,EAAUF,EAAOC,CAAG,EAAID,EAAMC,CAAG,EAAI,MAC7F,CAWO,SAASE,EAAoDH,EAAcI,EAAkC,CAClH,OAAOA,EAAK,OAAUD,EAAQJ,EAAIC,EAAOI,EAAK,CAAC,CAAC,EAAGA,EAAK,MAAM,CAAC,CAAC,EAAeJ,CACjF,CAEO,SAASE,EACdG,EACAJ,EACwE,CAExE,OAAO,OAAOI,GAAW,UAAYA,IAAW,MAAQA,EAAO,eAAeJ,CAAG,CACnF,CAE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BG,EAAeH,EAAM,OAAQC,CAAK,EAGhCC,EAAUF,EAAO,WAAW,GAC9BI,EAAkBJ,EAAM,SAAS,CAErC,CA8BO,SAASK,EAA6CL,EAAmC,CAE9F,IAAMM,EAAUC,EAAeP,EAAM,OAAO,EAC5C,MAAO,CACL,gBAAiBA,EAAM,iBAAmBQ,EAAgB,gBAC1D,OAAQC,EACNC,EAAUV,EAAM,QAAU,CAAC,EAAG,CAACW,EAAMC,IAAU,CAC7C,IAAMC,EAAYb,EAAM,UAExB,MAAO,CADKa,EAAY,GAAGA,MAAcF,IAASA,EAGhDG,EAAiBF,EAAO,CACtB,UAAWC,EACX,KAAAF,EACA,QAASG,EAAiBF,EAAM,SAAW,CAAC,EAAG,CAC7C,gBAAiBN,EAAQ,sBAAwBO,GAAW,OAAS,GAAGA,WAAqB,QAC/F,CAAC,CACH,CAAC,CACH,CACF,CAAC,EACDnB,EAAcM,CAAK,CACrB,EACA,UAAWA,EAAM,WAAa,CAAC,EAC/B,MAAoBA,EAAM,OAAS,CAAC,EACpC,WAAYe,EAASf,EAAM,OAAS,CAAC,CAAC,EACtC,UAAWA,EAAM,WAAaQ,EAAgB,UAC9C,QAAAF,CACF,CACF,CAEO,SAASU,GAAyBhB,EAAkD,CACzF,OAAAD,EAAcC,CAAK,EACZK,EAAaL,CAAK,CAC3B","names":["get","input","key","hasOwnKey","getPath","path","object","isObject","mergeIfUndefined","base","merged","allKeys","CODEGEN_DEFAULTS","TABLE_CODEGEN_DEFAULTS","TABLE_DEPLOY_DEFAULTS","TABLE_DEFAULTS","CONFIG_DEFAULTS","schemaAbiTypes","Scope","AbiTypeScope","abiType","extendScope","scope","additionalTypes","fixedArrayToArray","isFixedArrayAbiType","validateSchema","schema","scope","AbiTypeScope","isObject","internalType","hasOwnKey","resolveSchema","key","defineSchema","isSchemaInput","input","fieldType","isStaticAbiType","resourceToHex","getValidKeys","schema","scope","AbiTypeScope","internalType","hasOwnKey","isStaticAbiType","key","isValidPrimaryKey","validateTable","input","options","validateSchema","item","get","resolveTableCodegen","TABLE_CODEGEN_DEFAULTS","resolveTable","name","type","TABLE_DEFAULTS","namespace","resolveSchema","mergeIfUndefined","TABLE_DEPLOY_DEFAULTS","defineTable","validateTables","input","scope","isObject","table","validateTable","resolveTables","tables","AbiTypeScope","label","resolveTable","mergeIfUndefined","mapObject","isSchemaAbiType","extractInternalType","userTypes","mapObject","userType","isUserTypes","isObject","isSchemaAbiType","scopeWithUserTypes","scope","AbiTypeScope","extendScope","validateUserTypes","type","hasOwnKey","flatMorph","isEnums","enums","item","element","scopeWithEnums","scope","AbiTypeScope","enumScope","key","extendScope","resolveEnums","mapEnums","flatMorph","enumName","enumElements","enumIndex","enumElement","resolveCodegen","codegen","isObject","mergeIfUndefined","CODEGEN_DEFAULTS","flatMorph","extendedScope","input","scopeWithEnums","get","scopeWithUserTypes","validateStore","store","scope","hasOwnKey","validateTables","validateUserTypes","resolveStore","codegen","resolveCodegen","CONFIG_DEFAULTS","resolveTables","flatMorph","name","table","namespace","mergeIfUndefined","mapEnums","defineStore"]}
@@ -1,2 +0,0 @@
1
- var l={namespace:"",enums:{},userTypes:{}},c={directory:"tables",keySchema:{key:"bytes32"},tableIdArgument:!1,storeArgument:!1,offchainOnly:!1};import{AbiTypes as E,StaticAbiTypes as v}from"@latticexyz/schema-type/deprecated";import{z as n,ZodIssueCode as i}from"zod";import{getDuplicates as y,parseStaticArray as S,STORE_NAME_MAX_LENGTH as z,zObjectName as T,zUserEnum as R,zValueName as U,zNamespace as k,zName as D}from"@latticexyz/config/library";import{isSchemaAbiType as O,schemaAbiTypes as j}from"@latticexyz/schema-type/internal";var L=T,I=U,_=U,B=T,K=T,g=n.string(),q=n.string(),$=n.record(I,q).default(c.keySchema),b=n.record(_,g).refine(e=>Object.keys(e).length>0,"Table schema may not be empty"),M=g.transform(e=>b.parse({value:e})),P=b.or(M);function pe(e,t){let s={};for(let[r,a]of Object.entries(e))if(O(a))s[r]=a;else if(t[a]!==void 0)s[r]=t[a].internalType;else{let p=S(a);if(!p)throw new Error(`Unexpected type: ${a}`);s[r]=`${p.elementType}[]`}return s}var h=n.object({directory:n.string().default(c.directory),name:D.optional(),tableIdArgument:n.boolean().default(c.tableIdArgument),storeArgument:n.boolean().default(c.storeArgument),dataStruct:n.boolean().optional(),keySchema:$,valueSchema:P,offchainOnly:n.boolean().default(c.offchainOnly)}).transform(e=>(Object.keys(e.valueSchema).length===1?e.dataStruct??=!1:e.dataStruct??=!0,e)),w=g.transform(e=>h.parse({valueSchema:{value:e}})),G=h.or(w),V=n.record(L,G).transform(e=>{for(let t of Object.keys(e)){let s=e[t];s.name=t.slice(0,z),e[t]=s}return e}),H=n.object({enums:n.record(B,R).default(l.enums)}),X=n.object({filePath:n.string(),internalType:n.enum(j)}),Z=n.object({userTypes:n.record(K,X).default(l.userTypes)}),x=n.object({namespace:k.default(l.namespace),tables:V}).merge(H).merge(Z),le=x.superRefine(C),ye=x.catchall(n.any()).superRefine(C);function C(e,t){for(let o of Object.values(e.tables)){let m=Object.keys(o.keySchema),N=Object.keys(o.valueSchema),f=y([...m,...N]);f.length>0&&t.addIssue({code:i.custom,message:`Field and key names within one table must be unique: ${f.join(", ")}`})}let s=Object.keys(e.tables),r=[...Object.keys(e.enums),...Object.keys(e.userTypes)],a=r,p=[...s,...a],d=y(p);d.length>0&&t.addIssue({code:i.custom,message:`Table library names, enum names, user type names must be globally unique: ${d.join(", ")}`});let A=Object.values(e.tables).map(({name:o})=>o),u=y(A);u.length>0&&t.addIssue({code:i.custom,message:`Table names must be unique: ${u.join(", ")}`});for(let o of Object.values(e.tables)){for(let m of Object.values(o.keySchema))F(r,m,t);for(let m of Object.values(o.valueSchema))J(a,r,m,t)}}function J(e,t,s,r){if(!E.includes(s)&&!e.includes(s)){let a=S(s);a?Q(t,a.elementType,a.staticLength,r):r.addIssue({code:i.custom,message:`${s} is not a valid abi type, and is not defined in userTypes`})}}function F(e,t,s){!v.includes(t)&&!e.includes(t)&&s.addIssue({code:i.custom,message:`${t} is not a static type`})}function Q(e,t,s,r){F(e,t,r),s===0?r.addIssue({code:i.custom,message:"Static array length must not be 0"}):s>=2**16&&r.addIssue({code:i.custom,message:"Static array length must be less than 2**16"})}export{l as a,c as b,P as c,pe as d,G as e,V as f,H as g,Z as h,le as i,ye as j};
2
- //# sourceMappingURL=chunk-RRYXNY5P.js.map