@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.
- package/dist/chunk-4TACS4IT.js +2 -0
- package/dist/{chunk-Y2IOLXYI.js.map → chunk-4TACS4IT.js.map} +1 -1
- package/dist/chunk-5YJ4WITG.js +2 -0
- package/dist/{chunk-YO3UX5MT.js.map → chunk-5YJ4WITG.js.map} +1 -1
- package/dist/codegen.js +210 -1005
- package/dist/codegen.js.map +1 -1
- package/dist/index.js +1 -22
- package/dist/internal.js +1 -302
- package/dist/internal.js.map +1 -1
- package/dist/mud.config.js +1 -60
- package/dist/mud.config.js.map +1 -1
- package/package.json +11 -47
- package/dist/chunk-Y2IOLXYI.js +0 -27
- package/dist/chunk-YO3UX5MT.js +0 -460
- package/dist/codegen.cjs +0 -1270
- package/dist/codegen.cjs.map +0 -1
- package/dist/codegen.d.cts +0 -173
- package/dist/index.cjs +0 -449
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -15
- package/dist/internal.cjs +0 -756
- package/dist/internal.cjs.map +0 -1
- package/dist/internal.d.cts +0 -88
- package/dist/mud.config.cjs +0 -468
- package/dist/mud.config.cjs.map +0 -1
- package/dist/mud.config.d.cts +0 -295
- package/dist/output-DjNNBwhs.d.cts +0 -215
- package/dist/store-7QsNcifl.d.cts +0 -326
package/dist/internal.cjs
DELETED
@@ -1,756 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __create = Object.create;
|
3
|
-
var __defProp = Object.defineProperty;
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
-
var __export = (target, all) => {
|
9
|
-
for (var name in all)
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
-
};
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
-
for (let key of __getOwnPropNames(from))
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
-
}
|
18
|
-
return to;
|
19
|
-
};
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
-
mod
|
27
|
-
));
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
-
|
30
|
-
// ts/exports/internal.ts
|
31
|
-
var internal_exports = {};
|
32
|
-
__export(internal_exports, {
|
33
|
-
AbiTypeScope: () => AbiTypeScope,
|
34
|
-
CODEGEN_DEFAULTS: () => CODEGEN_DEFAULTS,
|
35
|
-
CONFIG_DEFAULTS: () => CONFIG_DEFAULTS,
|
36
|
-
NoStaticKeyFieldError: () => NoStaticKeyFieldError,
|
37
|
-
Scope: () => Scope,
|
38
|
-
TABLE_CODEGEN_DEFAULTS: () => TABLE_CODEGEN_DEFAULTS,
|
39
|
-
TABLE_DEFAULTS: () => TABLE_DEFAULTS,
|
40
|
-
TABLE_DEPLOY_DEFAULTS: () => TABLE_DEPLOY_DEFAULTS,
|
41
|
-
defineNamespaces: () => defineNamespaces,
|
42
|
-
defineSchema: () => defineSchema,
|
43
|
-
defineStore: () => defineStore,
|
44
|
-
defineTable: () => defineTable,
|
45
|
-
defineTableShorthand: () => defineTableShorthand,
|
46
|
-
defineTables: () => defineTables,
|
47
|
-
emptyRecord: () => emptyRecord,
|
48
|
-
expandTableShorthand: () => expandTableShorthand,
|
49
|
-
extendScope: () => extendScope,
|
50
|
-
extendedScope: () => extendedScope,
|
51
|
-
extractInternalType: () => extractInternalType,
|
52
|
-
flattenNamespacedTables: () => flattenNamespacedTables,
|
53
|
-
flattenStoreLogs: () => flattenStoreLogs,
|
54
|
-
get: () => get,
|
55
|
-
getPath: () => getPath,
|
56
|
-
getRecord: () => getRecord,
|
57
|
-
getStaticDataLocation: () => getStaticDataLocation,
|
58
|
-
getStoreLogs: () => getStoreLogs,
|
59
|
-
hasOwnKey: () => hasOwnKey,
|
60
|
-
isObject: () => isObject,
|
61
|
-
isSchemaInput: () => isSchemaInput,
|
62
|
-
isTableShorthandInput: () => isTableShorthandInput,
|
63
|
-
isUserTypes: () => isUserTypes,
|
64
|
-
isValidPrimaryKey: () => isValidPrimaryKey,
|
65
|
-
logToRecord: () => logToRecord,
|
66
|
-
mapEnums: () => mapEnums,
|
67
|
-
mergeIfUndefined: () => mergeIfUndefined,
|
68
|
-
resolveCodegen: () => resolveCodegen,
|
69
|
-
resolveEnums: () => resolveEnums,
|
70
|
-
resolveNamespace: () => resolveNamespace,
|
71
|
-
resolveNamespaces: () => resolveNamespaces,
|
72
|
-
resolveSchema: () => resolveSchema,
|
73
|
-
resolveStore: () => resolveStore,
|
74
|
-
resolveTable: () => resolveTable,
|
75
|
-
resolveTableCodegen: () => resolveTableCodegen,
|
76
|
-
resolveTables: () => resolveTables,
|
77
|
-
scopeWithEnums: () => scopeWithEnums,
|
78
|
-
scopeWithUserTypes: () => scopeWithUserTypes,
|
79
|
-
validateNamespace: () => validateNamespace,
|
80
|
-
validateNamespaces: () => validateNamespaces,
|
81
|
-
validateSchema: () => validateSchema,
|
82
|
-
validateStore: () => validateStore,
|
83
|
-
validateTable: () => validateTable,
|
84
|
-
validateTableShorthand: () => validateTableShorthand,
|
85
|
-
validateTables: () => validateTables,
|
86
|
-
validateUserTypes: () => validateUserTypes
|
87
|
-
});
|
88
|
-
module.exports = __toCommonJS(internal_exports);
|
89
|
-
|
90
|
-
// ts/common.ts
|
91
|
-
var emptyRecord = {
|
92
|
-
staticData: "0x",
|
93
|
-
encodedLengths: "0x",
|
94
|
-
dynamicData: "0x"
|
95
|
-
};
|
96
|
-
|
97
|
-
// ts/getStoreLogs.ts
|
98
|
-
var import_viem = require("viem");
|
99
|
-
|
100
|
-
// ts/storeEventsAbi.ts
|
101
|
-
var import_abitype = require("abitype");
|
102
|
-
|
103
|
-
// ts/storeEvents.ts
|
104
|
-
var storeSetRecordEvent = "event Store_SetRecord(bytes32 indexed tableId, bytes32[] keyTuple, bytes staticData, bytes32 encodedLengths, bytes dynamicData)";
|
105
|
-
var storeSpliceStaticDataEvent = "event Store_SpliceStaticData(bytes32 indexed tableId, bytes32[] keyTuple, uint48 start, bytes data)";
|
106
|
-
var storeSpliceDynamicDataEvent = "event Store_SpliceDynamicData(bytes32 indexed tableId, bytes32[] keyTuple, uint8 dynamicFieldIndex, uint48 start, uint40 deleteCount, bytes32 encodedLengths, bytes data)";
|
107
|
-
var storeDeleteRecordEvent = "event Store_DeleteRecord(bytes32 indexed tableId, bytes32[] keyTuple)";
|
108
|
-
var storeEvents = [
|
109
|
-
storeSetRecordEvent,
|
110
|
-
storeSpliceStaticDataEvent,
|
111
|
-
storeSpliceDynamicDataEvent,
|
112
|
-
storeDeleteRecordEvent
|
113
|
-
];
|
114
|
-
|
115
|
-
// ts/storeEventsAbi.ts
|
116
|
-
var storeEventsAbi = (0, import_abitype.parseAbi)(storeEvents);
|
117
|
-
|
118
|
-
// ts/debug.ts
|
119
|
-
var import_debug = __toESM(require("debug"), 1);
|
120
|
-
var debug = (0, import_debug.default)("mud:store");
|
121
|
-
debug.log = console.debug.bind(console);
|
122
|
-
var error = (0, import_debug.default)("mud:store");
|
123
|
-
error.log = console.error.bind(console);
|
124
|
-
|
125
|
-
// ts/getStoreLogs.ts
|
126
|
-
var import_common = require("@latticexyz/common");
|
127
|
-
async function getStoreLogs(client, { address, tableId, fromBlock, toBlock } = {}) {
|
128
|
-
const topics = [storeEventsAbi.map(import_viem.toEventSelector), tableId ?? null];
|
129
|
-
const tableIds = tableId ? Array.isArray(tableId) ? tableId : [tableId] : [];
|
130
|
-
const addresses = address ? Array.isArray(address) ? address : [address] : [];
|
131
|
-
debug(
|
132
|
-
`getting store logs for ${tableIds.length ? tableIds.map(import_common.hexToResource).map(import_common.resourceToLabel).join(", ") : "all tables"} at ${addresses.length ? addresses.join(", ") : "any address"}`
|
133
|
-
);
|
134
|
-
const logs = await client.request({
|
135
|
-
method: "eth_getLogs",
|
136
|
-
params: [
|
137
|
-
{
|
138
|
-
address,
|
139
|
-
topics,
|
140
|
-
fromBlock: typeof fromBlock === "bigint" ? (0, import_viem.numberToHex)(fromBlock) : fromBlock,
|
141
|
-
toBlock: typeof toBlock === "bigint" ? (0, import_viem.numberToHex)(toBlock) : toBlock
|
142
|
-
}
|
143
|
-
]
|
144
|
-
});
|
145
|
-
const formattedLogs = logs.map((log) => (0, import_viem.formatLog)(log));
|
146
|
-
return (0, import_viem.parseEventLogs)({
|
147
|
-
abi: storeEventsAbi,
|
148
|
-
args: { tableId },
|
149
|
-
logs: formattedLogs,
|
150
|
-
strict: true
|
151
|
-
});
|
152
|
-
}
|
153
|
-
|
154
|
-
// ts/flattenStoreLogs.ts
|
155
|
-
var import_viem2 = require("viem");
|
156
|
-
var import_common3 = require("@latticexyz/common");
|
157
|
-
function getKey(log) {
|
158
|
-
return [log.address, log.args.tableId, log.args.keyTuple.join(",")].join(":");
|
159
|
-
}
|
160
|
-
function flattenStoreLogs(logs) {
|
161
|
-
const sortedLogs = logs.slice().sort(import_common3.logSort);
|
162
|
-
const records = /* @__PURE__ */ new Map();
|
163
|
-
for (const log of sortedLogs) {
|
164
|
-
const key = getKey(log);
|
165
|
-
if (log.eventName === "Store_SetRecord") {
|
166
|
-
records.delete(key);
|
167
|
-
records.set(key, log);
|
168
|
-
} else if (log.eventName === "Store_SpliceStaticData") {
|
169
|
-
const previousRecord = records.get(key);
|
170
|
-
const { staticData, encodedLengths, dynamicData } = previousRecord?.args ?? emptyRecord;
|
171
|
-
const nextRecord = {
|
172
|
-
...log,
|
173
|
-
eventName: "Store_SetRecord",
|
174
|
-
args: {
|
175
|
-
tableId: log.args.tableId,
|
176
|
-
keyTuple: log.args.keyTuple,
|
177
|
-
staticData: (0, import_common3.spliceHex)(staticData, log.args.start, (0, import_viem2.size)(log.args.data), log.args.data),
|
178
|
-
encodedLengths,
|
179
|
-
dynamicData
|
180
|
-
}
|
181
|
-
};
|
182
|
-
records.delete(key);
|
183
|
-
records.set(key, nextRecord);
|
184
|
-
} else if (log.eventName === "Store_SpliceDynamicData") {
|
185
|
-
const previousRecord = records.get(key);
|
186
|
-
const { staticData, dynamicData } = previousRecord?.args ?? emptyRecord;
|
187
|
-
const nextRecord = {
|
188
|
-
...log,
|
189
|
-
eventName: "Store_SetRecord",
|
190
|
-
args: {
|
191
|
-
tableId: log.args.tableId,
|
192
|
-
keyTuple: log.args.keyTuple,
|
193
|
-
staticData,
|
194
|
-
encodedLengths: log.args.encodedLengths,
|
195
|
-
dynamicData: (0, import_common3.spliceHex)(dynamicData, log.args.start, log.args.deleteCount, log.args.data)
|
196
|
-
}
|
197
|
-
};
|
198
|
-
records.delete(key);
|
199
|
-
records.set(key, nextRecord);
|
200
|
-
} else if (log.eventName === "Store_DeleteRecord") {
|
201
|
-
records.delete(key);
|
202
|
-
}
|
203
|
-
}
|
204
|
-
return Array.from(records.values());
|
205
|
-
}
|
206
|
-
|
207
|
-
// ts/logToRecord.ts
|
208
|
-
var import_internal = require("@latticexyz/protocol-parser/internal");
|
209
|
-
function logToRecord({
|
210
|
-
table,
|
211
|
-
log
|
212
|
-
}) {
|
213
|
-
const keySchema = (0, import_internal.getSchemaTypes)((0, import_internal.getKeySchema)(table));
|
214
|
-
const valueSchema = (0, import_internal.getSchemaTypes)((0, import_internal.getValueSchema)(table));
|
215
|
-
const key = (0, import_internal.decodeKey)(keySchema, log.args.keyTuple);
|
216
|
-
const value = (0, import_internal.decodeValueArgs)(valueSchema, log.args);
|
217
|
-
return { ...key, ...value };
|
218
|
-
}
|
219
|
-
|
220
|
-
// ts/getRecord.ts
|
221
|
-
var import_internal2 = require("@latticexyz/protocol-parser/internal");
|
222
|
-
var import_actions = require("viem/actions");
|
223
|
-
var import_utils = require("viem/utils");
|
224
|
-
async function getRecord(client, { address, table, key, blockTag }) {
|
225
|
-
const [staticData, encodedLengths, dynamicData] = await (0, import_utils.getAction)(
|
226
|
-
client,
|
227
|
-
import_actions.readContract,
|
228
|
-
"readContract"
|
229
|
-
)({
|
230
|
-
address,
|
231
|
-
abi,
|
232
|
-
functionName: "getRecord",
|
233
|
-
args: [table.tableId, (0, import_internal2.getKeyTuple)(table, key)],
|
234
|
-
blockTag
|
235
|
-
});
|
236
|
-
return {
|
237
|
-
...key,
|
238
|
-
...(0, import_internal2.decodeValueArgs)((0, import_internal2.getSchemaTypes)((0, import_internal2.getValueSchema)(table)), { staticData, encodedLengths, dynamicData })
|
239
|
-
};
|
240
|
-
}
|
241
|
-
var abi = [
|
242
|
-
{
|
243
|
-
type: "function",
|
244
|
-
name: "getRecord",
|
245
|
-
inputs: [
|
246
|
-
{
|
247
|
-
name: "tableId",
|
248
|
-
type: "bytes32",
|
249
|
-
internalType: "ResourceId"
|
250
|
-
},
|
251
|
-
{
|
252
|
-
name: "keyTuple",
|
253
|
-
type: "bytes32[]",
|
254
|
-
internalType: "bytes32[]"
|
255
|
-
}
|
256
|
-
],
|
257
|
-
outputs: [
|
258
|
-
{
|
259
|
-
name: "staticData",
|
260
|
-
type: "bytes",
|
261
|
-
internalType: "bytes"
|
262
|
-
},
|
263
|
-
{
|
264
|
-
name: "encodedLengths",
|
265
|
-
type: "bytes32",
|
266
|
-
internalType: "EncodedLengths"
|
267
|
-
},
|
268
|
-
{
|
269
|
-
name: "dynamicData",
|
270
|
-
type: "bytes",
|
271
|
-
internalType: "bytes"
|
272
|
-
}
|
273
|
-
],
|
274
|
-
stateMutability: "view"
|
275
|
-
}
|
276
|
-
];
|
277
|
-
|
278
|
-
// ts/getStaticDataLocation.ts
|
279
|
-
var import_viem3 = require("viem");
|
280
|
-
var SLOT = (0, import_viem3.hexToBigInt)((0, import_viem3.keccak256)((0, import_viem3.toBytes)("mud.store")));
|
281
|
-
function getStaticDataLocation(tableId, keyTuple) {
|
282
|
-
return (0, import_viem3.numberToHex)(SLOT ^ (0, import_viem3.hexToBigInt)((0, import_viem3.keccak256)((0, import_viem3.concatHex)([tableId, ...keyTuple]))), { size: 32 });
|
283
|
-
}
|
284
|
-
|
285
|
-
// ts/config/v2/defaults.ts
|
286
|
-
var CODEGEN_DEFAULTS = {
|
287
|
-
storeImportPath: "@latticexyz/store/src",
|
288
|
-
userTypesFilename: "common.sol",
|
289
|
-
outputDirectory: "codegen",
|
290
|
-
indexFilename: "index.sol"
|
291
|
-
};
|
292
|
-
var TABLE_CODEGEN_DEFAULTS = {
|
293
|
-
outputDirectory: "tables",
|
294
|
-
tableIdArgument: false,
|
295
|
-
storeArgument: false
|
296
|
-
};
|
297
|
-
var TABLE_DEPLOY_DEFAULTS = {
|
298
|
-
disabled: false
|
299
|
-
};
|
300
|
-
var TABLE_DEFAULTS = {
|
301
|
-
namespaceLabel: "",
|
302
|
-
type: "table"
|
303
|
-
};
|
304
|
-
var CONFIG_DEFAULTS = {
|
305
|
-
sourceDirectory: "src",
|
306
|
-
namespace: ""
|
307
|
-
};
|
308
|
-
|
309
|
-
// ts/config/v2/generics.ts
|
310
|
-
function get(input, key) {
|
311
|
-
return typeof input === "object" && input != null && hasOwnKey(input, key) ? input[key] : void 0;
|
312
|
-
}
|
313
|
-
function getPath(input, path) {
|
314
|
-
return path.length ? getPath(get(input, path[0]), path.slice(1)) : input;
|
315
|
-
}
|
316
|
-
function hasOwnKey(object, key) {
|
317
|
-
return typeof object === "object" && object !== null && object.hasOwnProperty(key);
|
318
|
-
}
|
319
|
-
function isObject(input) {
|
320
|
-
return input != null && typeof input === "object";
|
321
|
-
}
|
322
|
-
function mergeIfUndefined(base, defaults) {
|
323
|
-
const keys = [.../* @__PURE__ */ new Set([...Object.keys(base), ...Object.keys(defaults)])];
|
324
|
-
return Object.fromEntries(
|
325
|
-
keys.map((key) => [
|
326
|
-
key,
|
327
|
-
typeof base[key] === "undefined" ? defaults[key] : base[key]
|
328
|
-
])
|
329
|
-
);
|
330
|
-
}
|
331
|
-
|
332
|
-
// ts/config/v2/codegen.ts
|
333
|
-
function resolveCodegen(codegen) {
|
334
|
-
return isObject(codegen) ? mergeIfUndefined(codegen, CODEGEN_DEFAULTS) : CODEGEN_DEFAULTS;
|
335
|
-
}
|
336
|
-
|
337
|
-
// ts/config/v2/enums.ts
|
338
|
-
var import_util = require("@ark/util");
|
339
|
-
|
340
|
-
// ts/config/v2/scope.ts
|
341
|
-
var import_internal3 = require("@latticexyz/schema-type/internal");
|
342
|
-
var Scope = { types: {} };
|
343
|
-
var AbiTypeScope = {
|
344
|
-
types: Object.fromEntries(import_internal3.schemaAbiTypes.map((abiType) => [abiType, abiType]))
|
345
|
-
};
|
346
|
-
function extendScope(scope, additionalTypes) {
|
347
|
-
return {
|
348
|
-
types: {
|
349
|
-
...scope.types,
|
350
|
-
...additionalTypes
|
351
|
-
}
|
352
|
-
};
|
353
|
-
}
|
354
|
-
|
355
|
-
// ts/config/v2/enums.ts
|
356
|
-
function isEnums(enums) {
|
357
|
-
return typeof enums === "object" && enums != null && Object.values(enums).every((item) => Array.isArray(item) && item.every((element) => typeof element === "string"));
|
358
|
-
}
|
359
|
-
function scopeWithEnums(enums, scope = AbiTypeScope) {
|
360
|
-
if (isEnums(enums)) {
|
361
|
-
const enumScope = Object.fromEntries(Object.keys(enums).map((key) => [key, "uint8"]));
|
362
|
-
return extendScope(scope, enumScope);
|
363
|
-
}
|
364
|
-
return scope;
|
365
|
-
}
|
366
|
-
function resolveEnums(enums) {
|
367
|
-
return enums;
|
368
|
-
}
|
369
|
-
function mapEnums(enums) {
|
370
|
-
return (0, import_util.flatMorph)(enums, (enumName, enumElements) => [
|
371
|
-
enumName,
|
372
|
-
(0, import_util.flatMorph)(enumElements, (enumIndex, enumElement) => [enumElement, enumIndex])
|
373
|
-
]);
|
374
|
-
}
|
375
|
-
|
376
|
-
// ts/config/v2/flattenNamespacedTables.ts
|
377
|
-
function flattenNamespacedTables(config) {
|
378
|
-
return Object.fromEntries(
|
379
|
-
Object.entries(config.namespaces).flatMap(
|
380
|
-
([namespaceLabel, namespace]) => Object.entries(namespace.tables).map(([tableLabel, table]) => [
|
381
|
-
namespaceLabel === "" ? tableLabel : `${namespaceLabel}__${tableLabel}`,
|
382
|
-
table
|
383
|
-
])
|
384
|
-
)
|
385
|
-
);
|
386
|
-
}
|
387
|
-
|
388
|
-
// ts/config/v2/namespace.ts
|
389
|
-
var import_util2 = require("@ark/util");
|
390
|
-
|
391
|
-
// ts/config/v2/table.ts
|
392
|
-
var import_internal5 = require("@latticexyz/schema-type/internal");
|
393
|
-
|
394
|
-
// ts/config/v2/schema.ts
|
395
|
-
var import_internal4 = require("@latticexyz/schema-type/internal");
|
396
|
-
function validateSchema(schema, scope = AbiTypeScope) {
|
397
|
-
if (!isObject(schema)) {
|
398
|
-
throw new Error(`Expected schema, received ${JSON.stringify(schema)}`);
|
399
|
-
}
|
400
|
-
for (const internalType of Object.values(schema)) {
|
401
|
-
if ((0, import_internal4.isFixedArrayAbiType)(internalType)) continue;
|
402
|
-
if (hasOwnKey(scope.types, internalType)) continue;
|
403
|
-
throw new Error(`"${String(internalType)}" is not a valid type in this scope.`);
|
404
|
-
}
|
405
|
-
}
|
406
|
-
function resolveSchema(schema, scope = AbiTypeScope) {
|
407
|
-
return Object.fromEntries(
|
408
|
-
Object.entries(schema).map(([key, internalType]) => [
|
409
|
-
key,
|
410
|
-
{
|
411
|
-
type: (0, import_internal4.isFixedArrayAbiType)(internalType) ? (0, import_internal4.fixedArrayToArray)(internalType) : scope.types[internalType],
|
412
|
-
internalType
|
413
|
-
}
|
414
|
-
])
|
415
|
-
);
|
416
|
-
}
|
417
|
-
function defineSchema(schema, scope = AbiTypeScope) {
|
418
|
-
validateSchema(schema, scope);
|
419
|
-
return resolveSchema(schema, scope);
|
420
|
-
}
|
421
|
-
function isSchemaInput(input, scope = AbiTypeScope) {
|
422
|
-
return typeof input === "object" && input != null && Object.values(input).every((fieldType) => (0, import_internal4.isFixedArrayAbiType)(fieldType) || hasOwnKey(scope.types, fieldType));
|
423
|
-
}
|
424
|
-
|
425
|
-
// ts/config/v2/table.ts
|
426
|
-
var import_common4 = require("@latticexyz/common");
|
427
|
-
function getValidKeys(schema, scope = AbiTypeScope) {
|
428
|
-
return Object.entries(schema).filter(([, internalType]) => hasOwnKey(scope.types, internalType) && (0, import_internal5.isStaticAbiType)(scope.types[internalType])).map(([key]) => key);
|
429
|
-
}
|
430
|
-
function isValidPrimaryKey(key, schema, scope = AbiTypeScope) {
|
431
|
-
return Array.isArray(key) && key.every(
|
432
|
-
(key2) => hasOwnKey(schema, key2) && hasOwnKey(scope.types, schema[key2]) && (0, import_internal5.isStaticAbiType)(scope.types[schema[key2]])
|
433
|
-
);
|
434
|
-
}
|
435
|
-
function validateTable(input, scope = AbiTypeScope, options = { inStoreContext: false }) {
|
436
|
-
if (typeof input !== "object" || input == null) {
|
437
|
-
throw new Error(`Expected full table config, got \`${JSON.stringify(input)}\``);
|
438
|
-
}
|
439
|
-
if (!hasOwnKey(input, "schema")) {
|
440
|
-
throw new Error("Missing schema input");
|
441
|
-
}
|
442
|
-
validateSchema(input.schema, scope);
|
443
|
-
if (!hasOwnKey(input, "key") || !isValidPrimaryKey(input["key"], input["schema"], scope)) {
|
444
|
-
throw new Error(
|
445
|
-
`Invalid key. Expected \`(${getValidKeys(input["schema"], scope).map((item) => `"${String(item)}"`).join(" | ")})[]\`, received \`${hasOwnKey(input, "key") && Array.isArray(input.key) ? `[${input.key.map((item) => `"${item}"`).join(", ")}]` : String(get(input, "key"))}\``
|
446
|
-
);
|
447
|
-
}
|
448
|
-
if (hasOwnKey(input, "namespace") && typeof input.namespace === "string" && input.namespace.length > 14) {
|
449
|
-
throw new Error(`Table \`namespace\` must fit into a \`bytes14\`, but "${input.namespace}" is too long.`);
|
450
|
-
}
|
451
|
-
if (hasOwnKey(input, "namespaceLabel") && typeof input.namespaceLabel === "string" && (!hasOwnKey(input, "namespace") || typeof input.namespace !== "string") && input.namespaceLabel.length > 14) {
|
452
|
-
throw new Error(
|
453
|
-
`Table \`namespace\` defaults to \`namespaceLabel\`, but must fit into a \`bytes14\` and "${input.namespaceLabel}" is too long. Provide explicit \`namespace\` override.`
|
454
|
-
);
|
455
|
-
}
|
456
|
-
if (hasOwnKey(input, "name") && typeof input.name === "string" && input.name.length > 16) {
|
457
|
-
throw new Error(`Table \`name\` must fit into a \`bytes16\`, but "${input.name}" is too long.`);
|
458
|
-
}
|
459
|
-
if (options.inStoreContext && (hasOwnKey(input, "label") || hasOwnKey(input, "namespaceLabel") || hasOwnKey(input, "namespace"))) {
|
460
|
-
throw new Error(
|
461
|
-
"Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for tables in this context."
|
462
|
-
);
|
463
|
-
}
|
464
|
-
}
|
465
|
-
function resolveTableCodegen(input) {
|
466
|
-
const options = input.codegen;
|
467
|
-
return {
|
468
|
-
outputDirectory: get(options, "outputDirectory") ?? TABLE_CODEGEN_DEFAULTS.outputDirectory,
|
469
|
-
tableIdArgument: get(options, "tableIdArgument") ?? TABLE_CODEGEN_DEFAULTS.tableIdArgument,
|
470
|
-
storeArgument: get(options, "storeArgument") ?? TABLE_CODEGEN_DEFAULTS.storeArgument,
|
471
|
-
// dataStruct is true if there are at least 2 value fields
|
472
|
-
dataStruct: get(options, "dataStruct") ?? Object.keys(input.schema).length - input.key.length > 1
|
473
|
-
};
|
474
|
-
}
|
475
|
-
function resolveTable(input, scope = AbiTypeScope) {
|
476
|
-
const namespaceLabel = input.namespaceLabel ?? TABLE_DEFAULTS.namespaceLabel;
|
477
|
-
const namespace = input.namespace ?? namespaceLabel;
|
478
|
-
const label = input.label;
|
479
|
-
const name = input.name ?? label.slice(0, 16);
|
480
|
-
const type = input.type ?? TABLE_DEFAULTS.type;
|
481
|
-
const tableId = (0, import_common4.resourceToHex)({ type, namespace, name });
|
482
|
-
return {
|
483
|
-
label,
|
484
|
-
type,
|
485
|
-
namespace,
|
486
|
-
namespaceLabel,
|
487
|
-
name,
|
488
|
-
tableId,
|
489
|
-
schema: resolveSchema(input.schema, scope),
|
490
|
-
key: input.key,
|
491
|
-
codegen: resolveTableCodegen(input),
|
492
|
-
deploy: mergeIfUndefined(input.deploy ?? {}, TABLE_DEPLOY_DEFAULTS)
|
493
|
-
};
|
494
|
-
}
|
495
|
-
function defineTable(input, scope = AbiTypeScope) {
|
496
|
-
validateTable(input, scope);
|
497
|
-
return resolveTable(input, scope);
|
498
|
-
}
|
499
|
-
|
500
|
-
// ts/config/v2/tableShorthand.ts
|
501
|
-
var import_internal6 = require("@latticexyz/schema-type/internal");
|
502
|
-
var NoStaticKeyFieldError = "Invalid schema. Expected an `id` field with a static ABI type or an explicit `key` option.";
|
503
|
-
function isTableShorthandInput(shorthand) {
|
504
|
-
return typeof shorthand === "string" || isObject(shorthand) && Object.values(shorthand).every((value) => typeof value === "string");
|
505
|
-
}
|
506
|
-
function validateTableShorthand(shorthand, scope = AbiTypeScope) {
|
507
|
-
if (typeof shorthand === "string") {
|
508
|
-
if ((0, import_internal6.isFixedArrayAbiType)(shorthand) || hasOwnKey(scope.types, shorthand)) {
|
509
|
-
return;
|
510
|
-
}
|
511
|
-
throw new Error(`Invalid ABI type. \`${shorthand}\` not found in scope.`);
|
512
|
-
}
|
513
|
-
if (typeof shorthand === "object" && shorthand !== null) {
|
514
|
-
if (isSchemaInput(shorthand, scope)) {
|
515
|
-
if (hasOwnKey(shorthand, "id") && (0, import_internal6.isStaticAbiType)(scope.types[shorthand.id])) {
|
516
|
-
return;
|
517
|
-
}
|
518
|
-
throw new Error(`Invalid schema. Expected an \`id\` field with a static ABI type or an explicit \`key\` option.`);
|
519
|
-
}
|
520
|
-
throw new Error(`Invalid schema. Are you using invalid types or missing types in your scope?`);
|
521
|
-
}
|
522
|
-
throw new Error(`Invalid table shorthand.`);
|
523
|
-
}
|
524
|
-
function expandTableShorthand(shorthand, scope) {
|
525
|
-
if (typeof shorthand === "string") {
|
526
|
-
return {
|
527
|
-
schema: {
|
528
|
-
id: "bytes32",
|
529
|
-
value: shorthand
|
530
|
-
},
|
531
|
-
key: ["id"]
|
532
|
-
};
|
533
|
-
}
|
534
|
-
if (isSchemaInput(shorthand, scope)) {
|
535
|
-
return {
|
536
|
-
schema: shorthand,
|
537
|
-
key: ["id"]
|
538
|
-
};
|
539
|
-
}
|
540
|
-
return shorthand;
|
541
|
-
}
|
542
|
-
function defineTableShorthand(input, scope = AbiTypeScope) {
|
543
|
-
validateTableShorthand(input, scope);
|
544
|
-
return expandTableShorthand(input, scope);
|
545
|
-
}
|
546
|
-
|
547
|
-
// ts/config/v2/tables.ts
|
548
|
-
function validateTables(input, scope) {
|
549
|
-
if (isObject(input)) {
|
550
|
-
for (const table of Object.values(input)) {
|
551
|
-
if (isTableShorthandInput(table)) {
|
552
|
-
validateTableShorthand(table, scope);
|
553
|
-
} else {
|
554
|
-
validateTable(table, scope, { inStoreContext: true });
|
555
|
-
}
|
556
|
-
}
|
557
|
-
return;
|
558
|
-
}
|
559
|
-
throw new Error(`Expected tables config, received ${JSON.stringify(input)}`);
|
560
|
-
}
|
561
|
-
function resolveTables(tables, scope) {
|
562
|
-
return Object.fromEntries(
|
563
|
-
Object.entries(tables).map(([label, table]) => {
|
564
|
-
return [label, resolveTable(mergeIfUndefined(expandTableShorthand(table, scope), { label }), scope)];
|
565
|
-
})
|
566
|
-
);
|
567
|
-
}
|
568
|
-
function defineTables(input, scope = AbiTypeScope) {
|
569
|
-
validateTables(input, scope);
|
570
|
-
return resolveTables(input, scope);
|
571
|
-
}
|
572
|
-
|
573
|
-
// ts/config/v2/namespace.ts
|
574
|
-
function validateNamespace(input, scope) {
|
575
|
-
if (hasOwnKey(input, "namespace") && typeof input.namespace === "string" && input.namespace.length > 14) {
|
576
|
-
throw new Error(`\`namespace\` must fit into a \`bytes14\`, but "${input.namespace}" is too long.`);
|
577
|
-
}
|
578
|
-
if (hasOwnKey(input, "tables")) {
|
579
|
-
validateTables(input.tables, scope);
|
580
|
-
}
|
581
|
-
}
|
582
|
-
function resolveNamespace(input, scope = AbiTypeScope) {
|
583
|
-
const namespaceLabel = input.label;
|
584
|
-
const namespace = input.namespace ?? namespaceLabel.slice(0, 14);
|
585
|
-
return {
|
586
|
-
label: namespaceLabel,
|
587
|
-
namespace,
|
588
|
-
tables: resolveTables(
|
589
|
-
(0, import_util2.flatMorph)(input.tables ?? {}, (label, table) => {
|
590
|
-
return [label, mergeIfUndefined(expandTableShorthand(table, scope), { namespace, namespaceLabel })];
|
591
|
-
}),
|
592
|
-
scope
|
593
|
-
)
|
594
|
-
};
|
595
|
-
}
|
596
|
-
|
597
|
-
// ts/config/v2/namespaces.ts
|
598
|
-
var import_util3 = require("@ark/util");
|
599
|
-
var import_utils2 = require("@latticexyz/common/utils");
|
600
|
-
function validateNamespaces(namespaces, scope) {
|
601
|
-
if (!isObject(namespaces)) {
|
602
|
-
throw new Error(`Expected namespaces, received ${JSON.stringify(namespaces)}`);
|
603
|
-
}
|
604
|
-
for (const namespace of Object.values(namespaces)) {
|
605
|
-
validateNamespace(namespace, scope);
|
606
|
-
}
|
607
|
-
}
|
608
|
-
function resolveNamespaces(input, scope) {
|
609
|
-
if (!isObject(input)) {
|
610
|
-
throw new Error(`Expected namespaces config, received ${JSON.stringify(input)}`);
|
611
|
-
}
|
612
|
-
const namespaces = (0, import_util3.flatMorph)(input, (label, namespace) => [
|
613
|
-
label,
|
614
|
-
resolveNamespace(mergeIfUndefined(namespace, { label }), scope)
|
615
|
-
]);
|
616
|
-
const duplicates = Array.from((0, import_utils2.groupBy)(Object.values(namespaces), (namespace) => namespace.namespace).entries()).filter(([, entries]) => entries.length > 1).map(([namespace]) => namespace);
|
617
|
-
if (duplicates.length > 0) {
|
618
|
-
throw new Error(`Found namespaces defined more than once in config: ${duplicates.join(", ")}`);
|
619
|
-
}
|
620
|
-
return namespaces;
|
621
|
-
}
|
622
|
-
function defineNamespaces(input, scope = AbiTypeScope) {
|
623
|
-
validateNamespaces(input, scope);
|
624
|
-
return resolveNamespaces(input, scope);
|
625
|
-
}
|
626
|
-
|
627
|
-
// ts/config/v2/userTypes.ts
|
628
|
-
var import_utils3 = require("@latticexyz/common/utils");
|
629
|
-
var import_internal7 = require("@latticexyz/schema-type/internal");
|
630
|
-
function extractInternalType(userTypes) {
|
631
|
-
return (0, import_utils3.mapObject)(userTypes, (userType) => userType.type);
|
632
|
-
}
|
633
|
-
function isUserTypes(userTypes) {
|
634
|
-
return isObject(userTypes) && Object.values(userTypes).every((userType) => (0, import_internal7.isSchemaAbiType)(userType.type));
|
635
|
-
}
|
636
|
-
function scopeWithUserTypes(userTypes, scope = AbiTypeScope) {
|
637
|
-
return isUserTypes(userTypes) ? extendScope(scope, extractInternalType(userTypes)) : scope;
|
638
|
-
}
|
639
|
-
function validateUserTypes(userTypes) {
|
640
|
-
if (!isObject(userTypes)) {
|
641
|
-
throw new Error(`Expected userTypes, received ${JSON.stringify(userTypes)}`);
|
642
|
-
}
|
643
|
-
for (const { type } of Object.values(userTypes)) {
|
644
|
-
if (!hasOwnKey(AbiTypeScope.types, type)) {
|
645
|
-
throw new Error(`"${String(type)}" is not a valid ABI type.`);
|
646
|
-
}
|
647
|
-
}
|
648
|
-
}
|
649
|
-
|
650
|
-
// ts/config/v2/store.ts
|
651
|
-
function extendedScope(input) {
|
652
|
-
return scopeWithEnums(get(input, "enums"), scopeWithUserTypes(get(input, "userTypes")));
|
653
|
-
}
|
654
|
-
function validateStore(input) {
|
655
|
-
const scope = extendedScope(input);
|
656
|
-
if (hasOwnKey(input, "namespaces")) {
|
657
|
-
if (hasOwnKey(input, "namespace") || hasOwnKey(input, "tables")) {
|
658
|
-
throw new Error("Cannot use `namespaces` with `namespace` or `tables` keys.");
|
659
|
-
}
|
660
|
-
validateNamespaces(input.namespaces, scope);
|
661
|
-
}
|
662
|
-
if (hasOwnKey(input, "namespace") && typeof input.namespace === "string" && input.namespace.length > 14) {
|
663
|
-
throw new Error(`\`namespace\` must fit into a \`bytes14\`, but "${input.namespace}" is too long.`);
|
664
|
-
}
|
665
|
-
if (hasOwnKey(input, "tables")) {
|
666
|
-
validateTables(input.tables, scope);
|
667
|
-
}
|
668
|
-
if (hasOwnKey(input, "userTypes")) {
|
669
|
-
validateUserTypes(input.userTypes);
|
670
|
-
}
|
671
|
-
}
|
672
|
-
function resolveStore(input) {
|
673
|
-
const scope = extendedScope(input);
|
674
|
-
const baseNamespace = input.namespace ?? CONFIG_DEFAULTS["namespace"];
|
675
|
-
const namespaces = input.namespaces ? {
|
676
|
-
multipleNamespaces: true,
|
677
|
-
namespace: null,
|
678
|
-
namespaces: resolveNamespaces(input.namespaces, scope)
|
679
|
-
} : {
|
680
|
-
multipleNamespaces: false,
|
681
|
-
namespace: baseNamespace,
|
682
|
-
namespaces: resolveNamespaces({ [baseNamespace]: input }, scope)
|
683
|
-
};
|
684
|
-
const tables = flattenNamespacedTables(namespaces);
|
685
|
-
return {
|
686
|
-
...namespaces,
|
687
|
-
tables,
|
688
|
-
sourceDirectory: input.sourceDirectory ?? CONFIG_DEFAULTS["sourceDirectory"],
|
689
|
-
userTypes: input.userTypes ?? {},
|
690
|
-
enums: resolveEnums(input.enums ?? {}),
|
691
|
-
enumValues: mapEnums(input.enums ?? {}),
|
692
|
-
codegen: resolveCodegen(input.codegen)
|
693
|
-
};
|
694
|
-
}
|
695
|
-
function defineStore(input) {
|
696
|
-
validateStore(input);
|
697
|
-
return resolveStore(input);
|
698
|
-
}
|
699
|
-
// Annotate the CommonJS export names for ESM import in node:
|
700
|
-
0 && (module.exports = {
|
701
|
-
AbiTypeScope,
|
702
|
-
CODEGEN_DEFAULTS,
|
703
|
-
CONFIG_DEFAULTS,
|
704
|
-
NoStaticKeyFieldError,
|
705
|
-
Scope,
|
706
|
-
TABLE_CODEGEN_DEFAULTS,
|
707
|
-
TABLE_DEFAULTS,
|
708
|
-
TABLE_DEPLOY_DEFAULTS,
|
709
|
-
defineNamespaces,
|
710
|
-
defineSchema,
|
711
|
-
defineStore,
|
712
|
-
defineTable,
|
713
|
-
defineTableShorthand,
|
714
|
-
defineTables,
|
715
|
-
emptyRecord,
|
716
|
-
expandTableShorthand,
|
717
|
-
extendScope,
|
718
|
-
extendedScope,
|
719
|
-
extractInternalType,
|
720
|
-
flattenNamespacedTables,
|
721
|
-
flattenStoreLogs,
|
722
|
-
get,
|
723
|
-
getPath,
|
724
|
-
getRecord,
|
725
|
-
getStaticDataLocation,
|
726
|
-
getStoreLogs,
|
727
|
-
hasOwnKey,
|
728
|
-
isObject,
|
729
|
-
isSchemaInput,
|
730
|
-
isTableShorthandInput,
|
731
|
-
isUserTypes,
|
732
|
-
isValidPrimaryKey,
|
733
|
-
logToRecord,
|
734
|
-
mapEnums,
|
735
|
-
mergeIfUndefined,
|
736
|
-
resolveCodegen,
|
737
|
-
resolveEnums,
|
738
|
-
resolveNamespace,
|
739
|
-
resolveNamespaces,
|
740
|
-
resolveSchema,
|
741
|
-
resolveStore,
|
742
|
-
resolveTable,
|
743
|
-
resolveTableCodegen,
|
744
|
-
resolveTables,
|
745
|
-
scopeWithEnums,
|
746
|
-
scopeWithUserTypes,
|
747
|
-
validateNamespace,
|
748
|
-
validateNamespaces,
|
749
|
-
validateSchema,
|
750
|
-
validateStore,
|
751
|
-
validateTable,
|
752
|
-
validateTableShorthand,
|
753
|
-
validateTables,
|
754
|
-
validateUserTypes
|
755
|
-
});
|
756
|
-
//# sourceMappingURL=internal.cjs.map
|