@latticexyz/store 2.2.18-9fa07c8489f1fbf167d0db01cd9aaa645a29c8e2 → 2.2.18-c2ad22c7feb566e1731ff16e8be291746bdffb3e

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,326 +0,0 @@
1
- import { conform, show, requiredKeyOf, ErrorMessage, narrow } from '@ark/util';
2
- import { r as Scope, A as AbiTypeScope, b as SchemaInput, t as getStaticAbiTypeKeys, e as TableInput, k as TableCodegen, f as TableShorthandInput, c as ScopedSchemaInput, g as TablesInput, U as UserTypes, u as extendScope, E as EnumsInput, N as NamespaceInput, h as NamespacesInput, q as Namespaces, S as StoreInput } from './output-DjNNBwhs.cjs';
3
- import { Hex } from 'viem';
4
- import { FixedArrayAbiType, fixedArrayToArray } from '@latticexyz/schema-type/internal';
5
-
6
- declare const storeEventsAbi: readonly [{
7
- readonly name: "Store_SetRecord";
8
- readonly type: "event";
9
- readonly inputs: readonly [{
10
- readonly type: "bytes32";
11
- readonly name: "tableId";
12
- readonly indexed: true;
13
- }, {
14
- readonly type: "bytes32[]";
15
- readonly name: "keyTuple";
16
- }, {
17
- readonly type: "bytes";
18
- readonly name: "staticData";
19
- }, {
20
- readonly type: "bytes32";
21
- readonly name: "encodedLengths";
22
- }, {
23
- readonly type: "bytes";
24
- readonly name: "dynamicData";
25
- }];
26
- }, {
27
- readonly name: "Store_SpliceStaticData";
28
- readonly type: "event";
29
- readonly inputs: readonly [{
30
- readonly type: "bytes32";
31
- readonly name: "tableId";
32
- readonly indexed: true;
33
- }, {
34
- readonly type: "bytes32[]";
35
- readonly name: "keyTuple";
36
- }, {
37
- readonly type: "uint48";
38
- readonly name: "start";
39
- }, {
40
- readonly type: "bytes";
41
- readonly name: "data";
42
- }];
43
- }, {
44
- readonly name: "Store_SpliceDynamicData";
45
- readonly type: "event";
46
- readonly inputs: readonly [{
47
- readonly type: "bytes32";
48
- readonly name: "tableId";
49
- readonly indexed: true;
50
- }, {
51
- readonly type: "bytes32[]";
52
- readonly name: "keyTuple";
53
- }, {
54
- readonly type: "uint8";
55
- readonly name: "dynamicFieldIndex";
56
- }, {
57
- readonly type: "uint48";
58
- readonly name: "start";
59
- }, {
60
- readonly type: "uint40";
61
- readonly name: "deleteCount";
62
- }, {
63
- readonly type: "bytes32";
64
- readonly name: "encodedLengths";
65
- }, {
66
- readonly type: "bytes";
67
- readonly name: "data";
68
- }];
69
- }, {
70
- readonly name: "Store_DeleteRecord";
71
- readonly type: "event";
72
- readonly inputs: readonly [{
73
- readonly type: "bytes32";
74
- readonly name: "tableId";
75
- readonly indexed: true;
76
- }, {
77
- readonly type: "bytes32[]";
78
- readonly name: "keyTuple";
79
- }];
80
- }];
81
- type storeEventsAbi = typeof storeEventsAbi;
82
- type StoreEventsAbi = typeof storeEventsAbi;
83
- type StoreEventsAbiItem = (typeof storeEventsAbi)[number];
84
- type StoreSetRecordEventAbiItem = StoreEventsAbiItem & {
85
- readonly name: "Store_SetRecord";
86
- };
87
-
88
- type get<input, key> = key extends keyof input ? input[key] : undefined;
89
- declare function get<input, key extends PropertyKey>(input: input, key: key): get<input, key>;
90
- type getPath<input, path extends readonly PropertyKey[]> = path extends readonly [
91
- infer head,
92
- ...infer tail extends PropertyKey[]
93
- ] ? head extends keyof input ? getPath<input[head], tail> : undefined : input;
94
- declare function getPath<input, path extends readonly PropertyKey[]>(input: input, path: path): getPath<input, path>;
95
- declare function hasOwnKey<obj, const key extends PropertyKey>(object: obj, key: key): object is {
96
- [k in key]: k extends keyof obj ? obj[k] : unknown;
97
- } & obj;
98
- declare function isObject<input>(input: input): input is input & object;
99
- type mergeIfUndefined<base, defaults> = {
100
- readonly [key in keyof base | keyof defaults]: key extends keyof base ? undefined extends base[key] ? key extends keyof defaults ? defaults[key] : base[key] : base[key] : key extends keyof defaults ? defaults[key] : never;
101
- };
102
- declare function mergeIfUndefined<base extends object, defaults extends object>(base: base, defaults: defaults): mergeIfUndefined<base, defaults>;
103
- type parseNumber<T> = T extends `${infer N extends number}` ? N : never;
104
-
105
- declare const CODEGEN_DEFAULTS: {
106
- readonly storeImportPath: "@latticexyz/store/src";
107
- readonly userTypesFilename: "common.sol";
108
- readonly outputDirectory: "codegen";
109
- readonly indexFilename: "index.sol";
110
- };
111
- type CODEGEN_DEFAULTS = typeof CODEGEN_DEFAULTS;
112
- declare const TABLE_CODEGEN_DEFAULTS: {
113
- readonly outputDirectory: string;
114
- readonly tableIdArgument: false;
115
- readonly storeArgument: false;
116
- };
117
- type TABLE_CODEGEN_DEFAULTS = typeof TABLE_CODEGEN_DEFAULTS;
118
- declare const TABLE_DEPLOY_DEFAULTS: {
119
- readonly disabled: false;
120
- };
121
- type TABLE_DEPLOY_DEFAULTS = typeof TABLE_DEPLOY_DEFAULTS;
122
- declare const TABLE_DEFAULTS: {
123
- readonly namespaceLabel: "";
124
- readonly type: "table";
125
- };
126
- type TABLE_DEFAULTS = typeof TABLE_DEFAULTS;
127
- declare const CONFIG_DEFAULTS: {
128
- readonly sourceDirectory: "src";
129
- readonly namespace: "";
130
- };
131
- type CONFIG_DEFAULTS = typeof CONFIG_DEFAULTS;
132
-
133
- type validateSchema<schema, scope extends Scope = AbiTypeScope> = schema extends string ? SchemaInput : {
134
- [key in keyof schema]: schema[key] extends FixedArrayAbiType ? schema[key] : conform<schema[key], keyof scope["types"]>;
135
- };
136
- declare function validateSchema<scope extends Scope = AbiTypeScope>(schema: unknown, scope?: scope): asserts schema is SchemaInput;
137
- type resolveSchema<schema, scope extends Scope> = show<{
138
- readonly [key in keyof schema]: {
139
- /** the Solidity primitive ABI type */
140
- readonly type: schema[key] extends FixedArrayAbiType ? fixedArrayToArray<schema[key]> : scope["types"][schema[key] & keyof scope["types"]];
141
- /** the user defined type or Solidity primitive ABI type */
142
- readonly internalType: schema[key];
143
- };
144
- }>;
145
- declare function resolveSchema<schema extends SchemaInput, scope extends Scope = AbiTypeScope>(schema: schema, scope?: scope): resolveSchema<schema, scope>;
146
- declare function defineSchema<schema, scope extends AbiTypeScope = AbiTypeScope>(schema: validateSchema<schema, scope>, scope?: scope): resolveSchema<schema, scope>;
147
- declare function isSchemaInput<scope extends Scope = AbiTypeScope>(input: unknown, scope?: scope): input is SchemaInput;
148
-
149
- type ValidKeys<schema extends SchemaInput, scope extends Scope> = readonly [
150
- getStaticAbiTypeKeys<schema, scope>,
151
- ...getStaticAbiTypeKeys<schema, scope>[]
152
- ];
153
- declare function isValidPrimaryKey<schema extends SchemaInput, scope extends Scope>(key: unknown, schema: schema, scope?: scope): key is ValidKeys<schema, scope>;
154
- type validateKeys<validKeys extends PropertyKey, keys> = keys extends readonly string[] ? {
155
- readonly [i in keyof keys]: keys[i] extends validKeys ? keys[i] : validKeys;
156
- } : readonly string[];
157
- type ValidateTableOptions = {
158
- inStoreContext: boolean;
159
- };
160
- type requiredTableKey<inStoreContext extends boolean> = Exclude<requiredKeyOf<TableInput>, inStoreContext extends true ? "label" | "namespaceLabel" | "namespace" : never>;
161
- type validateTable<input, scope extends Scope = AbiTypeScope, options extends ValidateTableOptions = {
162
- inStoreContext: false;
163
- }> = {
164
- [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" | "namespaceLabel" | "namespace" ? options["inStoreContext"] extends true ? ErrorMessage<"Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for tables in this context"> : key extends keyof input ? narrow<input[key]> : never : key extends keyof TableInput ? TableInput[key] : ErrorMessage<`Key \`${key & string}\` does not exist in TableInput`>;
165
- };
166
- declare function validateTable<input, scope extends Scope = AbiTypeScope>(input: input, scope?: scope, options?: ValidateTableOptions): asserts input is TableInput & input;
167
- type resolveTableCodegen<input extends TableInput> = show<{
168
- [key in keyof TableCodegen]-?: key extends keyof input["codegen"] ? undefined extends input["codegen"][key] ? key extends "dataStruct" ? boolean : key extends keyof TABLE_CODEGEN_DEFAULTS ? TABLE_CODEGEN_DEFAULTS[key] : never : input["codegen"][key] : key extends "dataStruct" ? boolean : key extends keyof TABLE_CODEGEN_DEFAULTS ? TABLE_CODEGEN_DEFAULTS[key] : never;
169
- }>;
170
- declare function resolveTableCodegen<input extends TableInput>(input: input): resolveTableCodegen<input>;
171
- type resolveTable<input, scope extends Scope = Scope> = input extends TableInput ? {
172
- readonly label: input["label"];
173
- readonly namespaceLabel: undefined extends input["namespaceLabel"] ? typeof TABLE_DEFAULTS.namespaceLabel : input["namespaceLabel"];
174
- readonly type: undefined extends input["type"] ? typeof TABLE_DEFAULTS.type : input["type"];
175
- readonly namespace: string;
176
- readonly name: string;
177
- readonly tableId: Hex;
178
- readonly schema: resolveSchema<input["schema"], scope>;
179
- readonly key: Readonly<input["key"]>;
180
- readonly codegen: resolveTableCodegen<input>;
181
- readonly deploy: show<mergeIfUndefined<undefined extends input["deploy"] ? {} : input["deploy"], TABLE_DEPLOY_DEFAULTS>>;
182
- } : never;
183
- declare function resolveTable<input extends TableInput, scope extends Scope = AbiTypeScope>(input: input, scope?: scope): resolveTable<input, scope>;
184
- declare function defineTable<input, scope extends Scope = AbiTypeScope>(input: validateTable<input, scope>, scope?: scope): resolveTable<input, scope>;
185
-
186
- declare const NoStaticKeyFieldError = "Invalid schema. Expected an `id` field with a static ABI type or an explicit `key` option.";
187
- type NoStaticKeyFieldError = ErrorMessage<typeof NoStaticKeyFieldError>;
188
- declare function isTableShorthandInput(shorthand: unknown): shorthand is TableShorthandInput;
189
- type validateTableShorthand<input, scope extends Scope = AbiTypeScope> = input extends SchemaInput ? "id" extends getStaticAbiTypeKeys<input, scope> ? conform<input, ScopedSchemaInput<scope>> : NoStaticKeyFieldError : input extends FixedArrayAbiType | keyof scope["types"] ? input : input extends string ? keyof scope["types"] : ScopedSchemaInput<scope>;
190
- declare function validateTableShorthand<scope extends Scope = AbiTypeScope>(shorthand: unknown, scope?: scope): asserts shorthand is TableShorthandInput;
191
- type expandTableShorthand<shorthand> = shorthand extends string ? {
192
- readonly schema: {
193
- readonly id: "bytes32";
194
- readonly value: shorthand;
195
- };
196
- readonly key: ["id"];
197
- } : shorthand extends SchemaInput ? {
198
- readonly schema: shorthand;
199
- readonly key: ["id"];
200
- } : shorthand;
201
- declare function expandTableShorthand<shorthand, scope extends Scope = AbiTypeScope>(shorthand: shorthand, scope: scope): expandTableShorthand<shorthand>;
202
- declare function defineTableShorthand<input, scope extends Scope = AbiTypeScope>(input: validateTableShorthand<input, scope>, scope?: scope): expandTableShorthand<input>;
203
-
204
- type validateTables<tables, scope extends Scope = AbiTypeScope> = {
205
- [label in keyof tables]: tables[label] extends TableShorthandInput ? validateTableShorthand<tables[label], scope> : tables[label] extends object ? validateTable<tables[label], scope, {
206
- inStoreContext: true;
207
- }> : ErrorMessage<`Expected tables config.`>;
208
- };
209
- declare function validateTables<scope extends Scope = AbiTypeScope>(input: unknown, scope: scope): asserts input is TablesInput;
210
- type resolveTables<tables, scope extends Scope = AbiTypeScope> = {
211
- readonly [label in keyof tables]: resolveTable<mergeIfUndefined<expandTableShorthand<tables[label]>, {
212
- readonly label: label;
213
- }>, scope>;
214
- };
215
- declare function resolveTables<tables extends TablesInput, scope extends Scope = AbiTypeScope>(tables: tables, scope: scope): resolveTables<tables, scope>;
216
- declare function defineTables<input, scope extends Scope = AbiTypeScope>(input: validateTables<input, scope>, scope?: scope): show<resolveTables<input, scope>>;
217
-
218
- type extractInternalType<userTypes extends UserTypes> = {
219
- [key in keyof userTypes]: userTypes[key]["type"];
220
- };
221
- declare function extractInternalType<userTypes extends UserTypes>(userTypes: userTypes): extractInternalType<userTypes>;
222
- declare function isUserTypes(userTypes: unknown): userTypes is UserTypes;
223
- type scopeWithUserTypes<userTypes, scope extends AbiTypeScope = AbiTypeScope> = UserTypes extends userTypes ? scope : userTypes extends UserTypes ? extendScope<scope, extractInternalType<userTypes>> : scope;
224
- declare function scopeWithUserTypes<userTypes, scope extends AbiTypeScope = AbiTypeScope>(userTypes: userTypes, scope?: scope): scopeWithUserTypes<userTypes, scope>;
225
- declare function validateUserTypes(userTypes: unknown): asserts userTypes is UserTypes;
226
-
227
- type scopeWithEnums<enums, scope extends AbiTypeScope = AbiTypeScope> = EnumsInput extends enums ? scope : enums extends EnumsInput ? extendScope<scope, {
228
- [key in keyof enums]: "uint8";
229
- }> : scope;
230
- declare function scopeWithEnums<enums, scope extends AbiTypeScope = AbiTypeScope>(enums: enums, scope?: scope): scopeWithEnums<enums, scope>;
231
- type resolveEnums<enums> = {
232
- readonly [key in keyof enums]: Readonly<enums[key]>;
233
- };
234
- declare function resolveEnums<enums extends EnumsInput>(enums: enums): resolveEnums<enums>;
235
- type mapEnums<enums> = {
236
- readonly [key in keyof enums]: {
237
- readonly [element in keyof enums[key] & `${number}` as enums[key][element] & string]: parseNumber<element>;
238
- };
239
- };
240
- declare function mapEnums<enums extends EnumsInput>(enums: enums): resolveEnums<enums>;
241
-
242
- type resolveCodegen<codegen> = codegen extends {} ? show<mergeIfUndefined<codegen, CODEGEN_DEFAULTS>> : CODEGEN_DEFAULTS;
243
- declare function resolveCodegen<codegen>(codegen: codegen): resolveCodegen<codegen>;
244
-
245
- type validateNamespace<input, scope extends Scope = AbiTypeScope> = {
246
- [key in keyof input]: key extends "tables" ? validateTables<input[key], scope> : key extends keyof NamespaceInput ? NamespaceInput[key] : ErrorMessage<`\`${key & string}\` is not a valid namespace config option.`>;
247
- };
248
- declare function validateNamespace<scope extends Scope = AbiTypeScope>(input: unknown, scope: scope): asserts input is NamespaceInput;
249
- type resolveNamespace<input, scope extends Scope = AbiTypeScope> = input extends NamespaceInput ? {
250
- readonly label: input["label"];
251
- readonly namespace: string;
252
- readonly tables: undefined extends input["tables"] ? {} : show<resolveTables<{
253
- readonly [label in keyof input["tables"]]: mergeIfUndefined<expandTableShorthand<input["tables"][label]>, {
254
- readonly namespace: string;
255
- readonly namespaceLabel: input["label"];
256
- }>;
257
- }, scope>>;
258
- } : never;
259
- declare function resolveNamespace<const input extends NamespaceInput, scope extends Scope = AbiTypeScope>(input: input, scope?: scope): resolveNamespace<input, scope>;
260
-
261
- type validateNamespaces<namespaces, scope extends Scope = AbiTypeScope> = {
262
- [label in keyof namespaces]: validateNamespace<namespaces[label], scope>;
263
- };
264
- declare function validateNamespaces<scope extends Scope = AbiTypeScope>(namespaces: unknown, scope: scope): asserts namespaces is NamespacesInput;
265
- type resolveNamespaces<namespaces, scope extends Scope = AbiTypeScope> = {
266
- readonly [label in keyof namespaces]: resolveNamespace<mergeIfUndefined<namespaces[label], {
267
- label: label;
268
- }>, scope>;
269
- };
270
- declare function resolveNamespaces<input extends NamespacesInput, scope extends Scope = AbiTypeScope>(input: input, scope: scope): resolveNamespaces<input, scope>;
271
- declare function defineNamespaces<input, scope extends Scope = AbiTypeScope>(input: validateNamespaces<input, scope>, scope?: scope): show<resolveNamespaces<input, scope>>;
272
-
273
- type flattenNamespacedTableKeys<config> = config extends {
274
- readonly namespaces: infer namespaces;
275
- } ? {
276
- [namespaceLabel in keyof namespaces]: namespaces[namespaceLabel] extends {
277
- readonly tables: infer tables;
278
- } ? namespaceLabel extends "" ? keyof tables : `${namespaceLabel & string}__${keyof tables & string}` : never;
279
- }[keyof namespaces] : never;
280
- /**
281
- * @internal Only kept for backwards compatibility
282
- */
283
- type flattenNamespacedTables<config> = config extends {
284
- readonly namespaces: Namespaces;
285
- } ? {
286
- readonly [key in flattenNamespacedTableKeys<config>]: key extends `${infer namespaceLabel}__${infer tableLabel}` ? config["namespaces"][namespaceLabel]["tables"][tableLabel] : config["namespaces"][""]["tables"][key];
287
- } : never;
288
- /**
289
- * @internal Only kept for backwards compatibility
290
- */
291
- declare function flattenNamespacedTables<config extends {
292
- readonly namespaces: Namespaces;
293
- }>(config: config): show<flattenNamespacedTables<config>>;
294
-
295
- type extendedScope<input> = scopeWithEnums<get<input, "enums">, scopeWithUserTypes<get<input, "userTypes">>>;
296
- declare function extendedScope<input>(input: input): extendedScope<input>;
297
- type validateStore<input> = {
298
- [key in keyof input]: key extends "namespaces" ? input extends {
299
- namespace?: unknown;
300
- tables?: unknown;
301
- } ? ErrorMessage<"Cannot use `namespaces` with `namespace` or `tables` keys."> : validateNamespaces<input[key], extendedScope<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.`>;
302
- };
303
- declare function validateStore(input: unknown): asserts input is StoreInput;
304
- type resolveNamespaceMode<input> = "namespaces" extends keyof input ? {
305
- readonly multipleNamespaces: true;
306
- readonly namespace: null;
307
- readonly namespaces: show<resolveNamespaces<input["namespaces"], extendedScope<input>>>;
308
- } : {
309
- readonly multipleNamespaces: false;
310
- readonly namespace: string;
311
- readonly namespaces: show<resolveNamespaces<{
312
- readonly [label in "namespace" extends keyof input ? input["namespace"] extends string ? input["namespace"] : CONFIG_DEFAULTS["namespace"] : CONFIG_DEFAULTS["namespace"]]: input;
313
- }, extendedScope<input>>>;
314
- };
315
- type resolveStore<input> = resolveNamespaceMode<input> & {
316
- readonly tables: flattenNamespacedTables<resolveNamespaceMode<input>>;
317
- readonly sourceDirectory: "sourceDirectory" extends keyof input ? input["sourceDirectory"] : CONFIG_DEFAULTS["sourceDirectory"];
318
- readonly userTypes: "userTypes" extends keyof input ? input["userTypes"] : {};
319
- readonly enums: "enums" extends keyof input ? show<resolveEnums<input["enums"]>> : {};
320
- readonly enumValues: "enums" extends keyof input ? show<mapEnums<input["enums"]>> : {};
321
- readonly codegen: "codegen" extends keyof input ? resolveCodegen<input["codegen"]> : resolveCodegen<{}>;
322
- };
323
- declare function resolveStore<const input extends StoreInput>(input: input): resolveStore<input>;
324
- declare function defineStore<const input>(input: validateStore<input>): show<resolveStore<input>>;
325
-
326
- export { scopeWithUserTypes as $, isSchemaInput as A, extendedScope as B, CODEGEN_DEFAULTS as C, validateStore as D, type resolveNamespaceMode as E, resolveStore as F, isValidPrimaryKey as G, type validateKeys as H, type ValidateTableOptions as I, type requiredTableKey as J, validateTable as K, resolveTableCodegen as L, resolveTable as M, defineTable as N, validateTables as O, resolveTables as P, defineTables as Q, NoStaticKeyFieldError as R, type StoreEventsAbi as S, TABLE_CODEGEN_DEFAULTS as T, isTableShorthandInput as U, type ValidKeys as V, validateTableShorthand as W, expandTableShorthand as X, defineTableShorthand as Y, extractInternalType as Z, isUserTypes as _, type StoreEventsAbiItem as a, validateUserTypes as a0, type StoreSetRecordEventAbiItem as b, TABLE_DEPLOY_DEFAULTS as c, defineStore as d, TABLE_DEFAULTS as e, CONFIG_DEFAULTS as f, scopeWithEnums as g, resolveEnums as h, flattenNamespacedTables as i, get as j, getPath as k, hasOwnKey as l, mapEnums as m, isObject as n, mergeIfUndefined as o, type parseNumber as p, resolveNamespace as q, resolveCodegen as r, storeEventsAbi as s, validateNamespaces as t, resolveNamespaces as u, validateNamespace as v, defineNamespaces as w, validateSchema as x, resolveSchema as y, defineSchema as z };