@latticexyz/common 2.2.18-2762cefb93e90632e0b25e11d0238b5998852f8b → 2.2.18-318924725246340b208d3fbee8793314686f1759
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/actions.js +39 -1
- package/dist/actions.js.map +1 -1
- package/dist/chains.d.ts +10 -6
- package/dist/chains.js +79 -1
- package/dist/chains.js.map +1 -1
- package/dist/chunk-324BIDBP.js +70 -0
- package/dist/{chunk-DPUUE7NM.js.map → chunk-324BIDBP.js.map} +1 -1
- package/dist/chunk-5Q2OTK63.js +208 -0
- package/dist/{chunk-6FIKI2CG.js.map → chunk-5Q2OTK63.js.map} +1 -1
- package/dist/chunk-6Y3PYSE7.js +64 -0
- package/dist/{chunk-ZIUX7JCQ.js.map → chunk-6Y3PYSE7.js.map} +1 -1
- package/dist/chunk-73UWXFXB.js +11 -0
- package/dist/{chunk-TCWGPC6G.js.map → chunk-73UWXFXB.js.map} +1 -1
- package/dist/chunk-CHXZROA7.js +16 -0
- package/dist/{chunk-ZV2KGJCD.js.map → chunk-CHXZROA7.js.map} +1 -1
- package/dist/chunk-GRGLAPN2.js +12 -0
- package/dist/{chunk-QQCZY3XJ.js.map → chunk-GRGLAPN2.js.map} +1 -1
- package/dist/codegen.js +706 -49
- package/dist/codegen.js.map +1 -1
- package/dist/errors.js +6 -1
- package/dist/foundry.js +71 -2
- package/dist/foundry.js.map +1 -1
- package/dist/index.js +233 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.js +205 -9
- package/dist/internal.js.map +1 -1
- package/dist/kms.js +168 -1
- package/dist/kms.js.map +1 -1
- package/dist/utils.js +122 -1
- package/dist/utils.js.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-6FIKI2CG.js +0 -2
- package/dist/chunk-DPUUE7NM.js +0 -2
- package/dist/chunk-QQCZY3XJ.js +0 -2
- package/dist/chunk-TCWGPC6G.js +0 -2
- package/dist/chunk-ZIUX7JCQ.js +0 -2
- package/dist/chunk-ZV2KGJCD.js +0 -2
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// src/resourceTypes.ts
|
|
2
|
+
var resourceTypes = ["table", "offchainTable", "namespace", "system"];
|
|
3
|
+
|
|
4
|
+
// src/resourceToHex.ts
|
|
5
|
+
import { stringToHex, concatHex } from "viem";
|
|
6
|
+
var resourceTypeIds = {
|
|
7
|
+
// keep these in sync with storeResourceTypes.sol
|
|
8
|
+
table: "tb",
|
|
9
|
+
offchainTable: "ot",
|
|
10
|
+
// keep these in sync with worldResourceTypes.sol
|
|
11
|
+
namespace: "ns",
|
|
12
|
+
system: "sy"
|
|
13
|
+
};
|
|
14
|
+
function resourceToHex(resource) {
|
|
15
|
+
const typeId = resourceTypeIds[resource.type];
|
|
16
|
+
if (resource.namespace.length > 14) {
|
|
17
|
+
throw new Error(`Namespaces must fit into \`bytes14\`, but "${resource.namespace}" is too long.`);
|
|
18
|
+
}
|
|
19
|
+
return concatHex([
|
|
20
|
+
stringToHex(typeId, { size: 2 }),
|
|
21
|
+
stringToHex(resource.namespace, { size: 14 }),
|
|
22
|
+
stringToHex(resource.name.slice(0, 16), { size: 16 })
|
|
23
|
+
]);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// src/resourceToLabel.ts
|
|
27
|
+
var rootNamespace = "";
|
|
28
|
+
function resourceToLabel({
|
|
29
|
+
namespace,
|
|
30
|
+
name
|
|
31
|
+
}) {
|
|
32
|
+
return namespace === rootNamespace ? name : `${namespace}__${name}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/hexToResource.ts
|
|
36
|
+
import { hexToString, sliceHex } from "viem";
|
|
37
|
+
var resourceTypeIdToType = Object.fromEntries(
|
|
38
|
+
Object.entries(resourceTypeIds).map(([key, value]) => [value, key])
|
|
39
|
+
);
|
|
40
|
+
function getResourceType(resourceTypeId) {
|
|
41
|
+
const type = resourceTypeIdToType[resourceTypeId];
|
|
42
|
+
if (resourceTypes.includes(type)) {
|
|
43
|
+
return type;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function hexToResource(hex) {
|
|
47
|
+
const resourceTypeId = hexToString(sliceHex(hex, 0, 2)).replace(/\0+$/, "");
|
|
48
|
+
const type = getResourceType(resourceTypeId);
|
|
49
|
+
const namespace = hexToString(sliceHex(hex, 2, 16)).replace(/\0+$/, "");
|
|
50
|
+
const name = hexToString(sliceHex(hex, 16, 32)).replace(/\0+$/, "");
|
|
51
|
+
if (!type) {
|
|
52
|
+
throw new Error(`Unknown type (${resourceTypeId}) for resource (${resourceToLabel({ namespace, name })})`);
|
|
53
|
+
}
|
|
54
|
+
return { resourceId: hex, type, namespace, name };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export {
|
|
58
|
+
resourceTypes,
|
|
59
|
+
resourceTypeIds,
|
|
60
|
+
resourceToHex,
|
|
61
|
+
resourceToLabel,
|
|
62
|
+
hexToResource
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=chunk-6Y3PYSE7.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/resourceTypes.ts","../src/resourceToHex.ts","../src/resourceToLabel.ts","../src/hexToResource.ts"],"sourcesContent":["export const resourceTypes = [\"table\", \"offchainTable\", \"namespace\", \"system\"] as const;\n\nexport type ResourceType = (typeof resourceTypes)[number];\n","import { Hex, stringToHex, concatHex } from \"viem\";\nimport { Resource } from \"./common\";\nimport { ResourceType } from \"./resourceTypes\";\n\n/** @internal */\nexport const resourceTypeIds = {\n // keep these in sync with storeResourceTypes.sol\n table: \"tb\",\n offchainTable: \"ot\",\n // keep these in sync with worldResourceTypes.sol\n namespace: \"ns\",\n system: \"sy\",\n} as const satisfies Record<ResourceType, string>;\n\nexport function resourceToHex(resource: Omit<Resource, \"resourceId\">): Hex {\n const typeId = resourceTypeIds[resource.type];\n // Because namespaces are tied to access control, it's not safe to automatically truncate. Instead, we'll throw an error.\n if (resource.namespace.length > 14) {\n throw new Error(`Namespaces must fit into \\`bytes14\\`, but \"${resource.namespace}\" is too long.`);\n }\n return concatHex([\n stringToHex(typeId, { size: 2 }),\n stringToHex(resource.namespace, { size: 14 }),\n stringToHex(resource.name.slice(0, 16), { size: 16 }),\n ]);\n}\n","const rootNamespace = \"\";\n\nexport type ResourceLabel<\n namespace extends string = string,\n name extends string = string,\n> = namespace extends typeof rootNamespace ? name : `${namespace}__${name}`;\n\nexport function resourceToLabel<namespace extends string, name extends string>({\n namespace,\n name,\n}: {\n readonly namespace: namespace;\n readonly name: name;\n}): ResourceLabel<namespace, name> {\n return (namespace === rootNamespace ? name : `${namespace}__${name}`) as ResourceLabel<namespace, name>;\n}\n","import { Hex, hexToString, sliceHex } from \"viem\";\nimport { Resource } from \"./common\";\nimport { ResourceType, resourceTypes } from \"./resourceTypes\";\nimport { resourceTypeIds } from \"./resourceToHex\";\nimport { ReverseMap } from \"./type-utils/common\";\nimport { resourceToLabel } from \"./resourceToLabel\";\n\nconst resourceTypeIdToType = Object.fromEntries(\n Object.entries(resourceTypeIds).map(([key, value]) => [value, key]),\n) as ReverseMap<typeof resourceTypeIds>;\n\nfunction getResourceType(resourceTypeId: string): ResourceType | undefined {\n // TODO: replace Partial with `noUncheckedIndexedAccess`\n const type = (resourceTypeIdToType as Partial<Record<string, ResourceType>>)[resourceTypeId];\n if (resourceTypes.includes(type as ResourceType)) {\n return type;\n }\n}\n\nexport function hexToResource(hex: Hex): Resource {\n const resourceTypeId = hexToString(sliceHex(hex, 0, 2)).replace(/\\0+$/, \"\");\n const type = getResourceType(resourceTypeId);\n const namespace = hexToString(sliceHex(hex, 2, 16)).replace(/\\0+$/, \"\");\n const name = hexToString(sliceHex(hex, 16, 32)).replace(/\\0+$/, \"\");\n\n if (!type) {\n throw new Error(`Unknown type (${resourceTypeId}) for resource (${resourceToLabel({ namespace, name })})`);\n }\n\n return { resourceId: hex, type, namespace, name };\n}\n"],"mappings":"AAAO,
|
|
1
|
+
{"version":3,"sources":["../src/resourceTypes.ts","../src/resourceToHex.ts","../src/resourceToLabel.ts","../src/hexToResource.ts"],"sourcesContent":["export const resourceTypes = [\"table\", \"offchainTable\", \"namespace\", \"system\"] as const;\n\nexport type ResourceType = (typeof resourceTypes)[number];\n","import { Hex, stringToHex, concatHex } from \"viem\";\nimport { Resource } from \"./common\";\nimport { ResourceType } from \"./resourceTypes\";\n\n/** @internal */\nexport const resourceTypeIds = {\n // keep these in sync with storeResourceTypes.sol\n table: \"tb\",\n offchainTable: \"ot\",\n // keep these in sync with worldResourceTypes.sol\n namespace: \"ns\",\n system: \"sy\",\n} as const satisfies Record<ResourceType, string>;\n\nexport function resourceToHex(resource: Omit<Resource, \"resourceId\">): Hex {\n const typeId = resourceTypeIds[resource.type];\n // Because namespaces are tied to access control, it's not safe to automatically truncate. Instead, we'll throw an error.\n if (resource.namespace.length > 14) {\n throw new Error(`Namespaces must fit into \\`bytes14\\`, but \"${resource.namespace}\" is too long.`);\n }\n return concatHex([\n stringToHex(typeId, { size: 2 }),\n stringToHex(resource.namespace, { size: 14 }),\n stringToHex(resource.name.slice(0, 16), { size: 16 }),\n ]);\n}\n","const rootNamespace = \"\";\n\nexport type ResourceLabel<\n namespace extends string = string,\n name extends string = string,\n> = namespace extends typeof rootNamespace ? name : `${namespace}__${name}`;\n\nexport function resourceToLabel<namespace extends string, name extends string>({\n namespace,\n name,\n}: {\n readonly namespace: namespace;\n readonly name: name;\n}): ResourceLabel<namespace, name> {\n return (namespace === rootNamespace ? name : `${namespace}__${name}`) as ResourceLabel<namespace, name>;\n}\n","import { Hex, hexToString, sliceHex } from \"viem\";\nimport { Resource } from \"./common\";\nimport { ResourceType, resourceTypes } from \"./resourceTypes\";\nimport { resourceTypeIds } from \"./resourceToHex\";\nimport { ReverseMap } from \"./type-utils/common\";\nimport { resourceToLabel } from \"./resourceToLabel\";\n\nconst resourceTypeIdToType = Object.fromEntries(\n Object.entries(resourceTypeIds).map(([key, value]) => [value, key]),\n) as ReverseMap<typeof resourceTypeIds>;\n\nfunction getResourceType(resourceTypeId: string): ResourceType | undefined {\n // TODO: replace Partial with `noUncheckedIndexedAccess`\n const type = (resourceTypeIdToType as Partial<Record<string, ResourceType>>)[resourceTypeId];\n if (resourceTypes.includes(type as ResourceType)) {\n return type;\n }\n}\n\nexport function hexToResource(hex: Hex): Resource {\n const resourceTypeId = hexToString(sliceHex(hex, 0, 2)).replace(/\\0+$/, \"\");\n const type = getResourceType(resourceTypeId);\n const namespace = hexToString(sliceHex(hex, 2, 16)).replace(/\\0+$/, \"\");\n const name = hexToString(sliceHex(hex, 16, 32)).replace(/\\0+$/, \"\");\n\n if (!type) {\n throw new Error(`Unknown type (${resourceTypeId}) for resource (${resourceToLabel({ namespace, name })})`);\n }\n\n return { resourceId: hex, type, namespace, name };\n}\n"],"mappings":";AAAO,IAAM,gBAAgB,CAAC,SAAS,iBAAiB,aAAa,QAAQ;;;ACA7E,SAAc,aAAa,iBAAiB;AAKrC,IAAM,kBAAkB;AAAA;AAAA,EAE7B,OAAO;AAAA,EACP,eAAe;AAAA;AAAA,EAEf,WAAW;AAAA,EACX,QAAQ;AACV;AAEO,SAAS,cAAc,UAA6C;AACzE,QAAM,SAAS,gBAAgB,SAAS,IAAI;AAE5C,MAAI,SAAS,UAAU,SAAS,IAAI;AAClC,UAAM,IAAI,MAAM,8CAA8C,SAAS,SAAS,gBAAgB;AAAA,EAClG;AACA,SAAO,UAAU;AAAA,IACf,YAAY,QAAQ,EAAE,MAAM,EAAE,CAAC;AAAA,IAC/B,YAAY,SAAS,WAAW,EAAE,MAAM,GAAG,CAAC;AAAA,IAC5C,YAAY,SAAS,KAAK,MAAM,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC;AAAA,EACtD,CAAC;AACH;;;ACzBA,IAAM,gBAAgB;AAOf,SAAS,gBAA+D;AAAA,EAC7E;AAAA,EACA;AACF,GAGmC;AACjC,SAAQ,cAAc,gBAAgB,OAAO,GAAG,SAAS,KAAK,IAAI;AACpE;;;ACfA,SAAc,aAAa,gBAAgB;AAO3C,IAAM,uBAAuB,OAAO;AAAA,EAClC,OAAO,QAAQ,eAAe,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,OAAO,GAAG,CAAC;AACpE;AAEA,SAAS,gBAAgB,gBAAkD;AAEzE,QAAM,OAAQ,qBAA+D,cAAc;AAC3F,MAAI,cAAc,SAAS,IAAoB,GAAG;AAChD,WAAO;AAAA,EACT;AACF;AAEO,SAAS,cAAc,KAAoB;AAChD,QAAM,iBAAiB,YAAY,SAAS,KAAK,GAAG,CAAC,CAAC,EAAE,QAAQ,QAAQ,EAAE;AAC1E,QAAM,OAAO,gBAAgB,cAAc;AAC3C,QAAM,YAAY,YAAY,SAAS,KAAK,GAAG,EAAE,CAAC,EAAE,QAAQ,QAAQ,EAAE;AACtE,QAAM,OAAO,YAAY,SAAS,KAAK,IAAI,EAAE,CAAC,EAAE,QAAQ,QAAQ,EAAE;AAElE,MAAI,CAAC,MAAM;AACT,UAAM,IAAI,MAAM,iBAAiB,cAAc,mBAAmB,gBAAgB,EAAE,WAAW,KAAK,CAAC,CAAC,GAAG;AAAA,EAC3G;AAEA,SAAO,EAAE,YAAY,KAAK,MAAM,WAAW,KAAK;AAClD;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/debug.ts
|
|
2
|
+
import createDebug from "debug";
|
|
3
|
+
var debug = createDebug("mud:common");
|
|
4
|
+
var error = createDebug("mud:common");
|
|
5
|
+
debug.log = console.debug.bind(console);
|
|
6
|
+
error.log = console.error.bind(console);
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
debug
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=chunk-73UWXFXB.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/debug.ts"],"sourcesContent":["import createDebug from \"debug\";\n\nexport const debug = createDebug(\"mud:common\");\nexport const error = createDebug(\"mud:common\");\n\n// Pipe debug output to stdout instead of stderr\ndebug.log = console.debug.bind(console);\n\n// Pipe error output to stderr\nerror.log = console.error.bind(console);\n"],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"sources":["../src/debug.ts"],"sourcesContent":["import createDebug from \"debug\";\n\nexport const debug = createDebug(\"mud:common\");\nexport const error = createDebug(\"mud:common\");\n\n// Pipe debug output to stdout instead of stderr\ndebug.log = console.debug.bind(console);\n\n// Pipe error output to stderr\nerror.log = console.error.bind(console);\n"],"mappings":";AAAA,OAAO,iBAAiB;AAEjB,IAAM,QAAQ,YAAY,YAAY;AACtC,IAAM,QAAQ,YAAY,YAAY;AAG7C,MAAM,MAAM,QAAQ,MAAM,KAAK,OAAO;AAGtC,MAAM,MAAM,QAAQ,MAAM,KAAK,OAAO;","names":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// src/utils/uniqueBy.ts
|
|
2
|
+
function uniqueBy(values, getKey) {
|
|
3
|
+
const map = /* @__PURE__ */ new Map();
|
|
4
|
+
for (const value of values) {
|
|
5
|
+
const key = getKey(value);
|
|
6
|
+
if (!map.has(key)) {
|
|
7
|
+
map.set(key, value);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
return Array.from(map.values());
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
uniqueBy
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=chunk-CHXZROA7.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/uniqueBy.ts"],"sourcesContent":["export function uniqueBy<value, key>(values: readonly value[], getKey: (value: value) => key): readonly value[] {\n const map = new Map<key, value>();\n for (const value of values) {\n const key = getKey(value);\n if (!map.has(key)) {\n map.set(key, value);\n }\n }\n return Array.from(map.values());\n}\n"],"mappings":"AAAO,
|
|
1
|
+
{"version":3,"sources":["../src/utils/uniqueBy.ts"],"sourcesContent":["export function uniqueBy<value, key>(values: readonly value[], getKey: (value: value) => key): readonly value[] {\n const map = new Map<key, value>();\n for (const value of values) {\n const key = getKey(value);\n if (!map.has(key)) {\n map.set(key, value);\n }\n }\n return Array.from(map.values());\n}\n"],"mappings":";AAAO,SAAS,SAAqB,QAA0B,QAAiD;AAC9G,QAAM,MAAM,oBAAI,IAAgB;AAChC,aAAW,SAAS,QAAQ;AAC1B,UAAM,MAAM,OAAO,KAAK;AACxB,QAAI,CAAC,IAAI,IAAI,GAAG,GAAG;AACjB,UAAI,IAAI,KAAK,KAAK;AAAA,IACpB;AAAA,EACF;AACA,SAAO,MAAM,KAAK,IAAI,OAAO,CAAC;AAChC;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors/MUDError.ts"],"sourcesContent":["export class MUDError extends Error {\n name = \"MUDError\";\n}\n"],"mappings":"AAAO,
|
|
1
|
+
{"version":3,"sources":["../src/errors/MUDError.ts"],"sourcesContent":["export class MUDError extends Error {\n name = \"MUDError\";\n}\n"],"mappings":";AAAO,IAAM,WAAN,cAAuB,MAAM;AAAA,EAA7B;AAAA;AACL,gBAAO;AAAA;AACT;","names":[]}
|