@latticexyz/world 2.0.0 → 2.0.1

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,4 +1,4 @@
1
- export { d as defineWorld, r as resolveWorld, v as validateWorld } from '../world-c96a2291.js';
1
+ export { d as defineWorld, r as resolveWorld, v as validateWorld } from '../world-744aa7b1.js';
2
2
  import { W as World, M as Module, S as Systems } from '../output-993b3634.js';
3
3
  export { C as Codegen, D as Deploy, a as System } from '../output-993b3634.js';
4
4
  import { mutable, conform } from '@arktype/util';
package/dist/index.d.ts CHANGED
@@ -1,11 +1,29 @@
1
- export { d as defineWorld } from './world-c96a2291.js';
1
+ import { validateTablesWithShorthands, extendedScope, Scope, AbiTypeScope, resolveTablesWithShorthands } from '@latticexyz/store/config/v2';
2
+ import { v as validateWorld, a as validateNamespaces, r as resolveWorld, W as WorldWithShorthandsInput } from './world-744aa7b1.js';
2
3
  export { W as World } from './output-993b3634.js';
3
4
  import '@arktype/util';
4
- import '@latticexyz/store/config/v2';
5
5
  import './defaults-87a942d7.js';
6
6
  import '@latticexyz/store';
7
7
 
8
8
  declare const worldDeployedEvent = "event WorldDeployed(address indexed newContract, uint256 salt)";
9
9
  declare const helloWorldEvent = "event HelloWorld(bytes32 indexed worldVersion)";
10
10
 
11
- export { helloWorldEvent, worldDeployedEvent };
11
+ type validateWorldWithShorthands<world> = {
12
+ [key in keyof world]: key extends "tables" ? validateTablesWithShorthands<world[key], extendedScope<world>> : key extends "namespaces" ? validateNamespacesWithShorthands<world[key], extendedScope<world>> : validateWorld<world>[key];
13
+ };
14
+ type validateNamespacesWithShorthands<namespaces, scope extends Scope = AbiTypeScope> = {
15
+ [namespace in keyof namespaces]: {
16
+ [key in keyof namespaces[namespace]]: key extends "tables" ? validateTablesWithShorthands<namespaces[namespace][key], scope> : validateNamespaces<namespaces[namespace], scope>[key];
17
+ };
18
+ };
19
+ type resolveWorldWithShorthands<world> = resolveWorld<{
20
+ [key in keyof world]: key extends "tables" ? resolveTablesWithShorthands<world[key], extendedScope<world>> : key extends "namespaces" ? {
21
+ [namespaceKey in keyof world[key]]: {
22
+ [namespaceProp in keyof world[key][namespaceKey]]: namespaceProp extends "tables" ? resolveTablesWithShorthands<world[key][namespaceKey][namespaceProp], extendedScope<world>> : world[key][namespaceKey][namespaceProp];
23
+ };
24
+ } : world[key];
25
+ }>;
26
+ declare function resolveWorldWithShorthands<world extends WorldWithShorthandsInput>(world: world): resolveWorldWithShorthands<world>;
27
+ declare function defineWorldWithShorthands<world>(world: validateWorldWithShorthands<world>): resolveWorldWithShorthands<world>;
28
+
29
+ export { defineWorldWithShorthands as defineWorld, helloWorldEvent, worldDeployedEvent };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{c as e}from"./chunk-3GSLUFHC.js";import"./chunk-RF4HOV37.js";var o="event WorldDeployed(address indexed newContract, uint256 salt)",t="event HelloWorld(bytes32 indexed worldVersion)";export{e as defineWorld,t as helloWorldEvent,o as worldDeployedEvent};
1
+ import{a as d,b as l}from"./chunk-3GSLUFHC.js";import"./chunk-RF4HOV37.js";var S="event WorldDeployed(address indexed newContract, uint256 salt)",v="event HelloWorld(bytes32 indexed worldVersion)";import{extendedScope as m,get as p,hasOwnKey as h,isObject as k,isTableShorthandInput as i,resolveTableShorthand as c,validateTablesWithShorthands as W}from"@latticexyz/store/config/v2";import{mapObject as r}from"@latticexyz/common/utils";function f(e){let s=m(e);if(h(e,"tables")&&W(e.tables,s),h(e,"namespaces")&&k(e.namespaces))for(let t of Object.keys(e.namespaces))W(p(p(e.namespaces,t),"tables")??{},s)}function x(e){let s=m(e),t=r(e.tables??{},o=>i(o)?c(o,s):o),y=r(e.namespaces??{},o=>({...o,tables:r(o.tables??{},a=>i(a)?c(a,s):a)})),n={...e,tables:t,namespaces:y};return d(n),l(n)}function w(e){return f(e),x(e)}export{w as defineWorld,v as helloWorldEvent,S as worldDeployedEvent};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../ts/worldEvents.ts"],"sourcesContent":["// from WorldFactory\nexport const worldDeployedEvent = \"event WorldDeployed(address indexed newContract, uint256 salt)\";\n\n// from World\nexport const helloWorldEvent = \"event HelloWorld(bytes32 indexed worldVersion)\";\n"],"mappings":"oEACO,IAAMA,EAAqB,iEAGrBC,EAAkB","names":["worldDeployedEvent","helloWorldEvent"]}
1
+ {"version":3,"sources":["../ts/worldEvents.ts","../ts/config/v2/worldWithShorthands.ts"],"sourcesContent":["// from WorldFactory\nexport const worldDeployedEvent = \"event WorldDeployed(address indexed newContract, uint256 salt)\";\n\n// from World\nexport const helloWorldEvent = \"event HelloWorld(bytes32 indexed worldVersion)\";\n","import {\n AbiTypeScope,\n extendedScope,\n get,\n hasOwnKey,\n isObject,\n isTableShorthandInput,\n resolveTableShorthand,\n resolveTablesWithShorthands,\n validateTablesWithShorthands,\n Scope,\n} from \"@latticexyz/store/config/v2\";\nimport { mapObject } from \"@latticexyz/common/utils\";\nimport { resolveWorld, validateWorld } from \"./world\";\nimport { WorldWithShorthandsInput } from \"./input\";\nimport { validateNamespaces } from \"./namespaces\";\n\nexport type resolveWorldWithShorthands<world> = resolveWorld<{\n [key in keyof world]: key extends \"tables\"\n ? resolveTablesWithShorthands<world[key], extendedScope<world>>\n : key extends \"namespaces\"\n ? {\n [namespaceKey in keyof world[key]]: {\n [namespaceProp in keyof world[key][namespaceKey]]: namespaceProp extends \"tables\"\n ? resolveTablesWithShorthands<world[key][namespaceKey][namespaceProp], extendedScope<world>>\n : world[key][namespaceKey][namespaceProp];\n };\n }\n : world[key];\n}>;\n\nexport type validateWorldWithShorthands<world> = {\n [key in keyof world]: key extends \"tables\"\n ? validateTablesWithShorthands<world[key], extendedScope<world>>\n : key extends \"namespaces\"\n ? validateNamespacesWithShorthands<world[key], extendedScope<world>>\n : validateWorld<world>[key];\n};\n\nfunction validateWorldWithShorthands(world: unknown): asserts world is WorldWithShorthandsInput {\n const scope = extendedScope(world);\n if (hasOwnKey(world, \"tables\")) {\n validateTablesWithShorthands(world.tables, scope);\n }\n\n if (hasOwnKey(world, \"namespaces\") && isObject(world.namespaces)) {\n for (const namespaceKey of Object.keys(world.namespaces)) {\n validateTablesWithShorthands(get(get(world.namespaces, namespaceKey), \"tables\") ?? {}, scope);\n }\n }\n}\n\nexport type validateNamespacesWithShorthands<namespaces, scope extends Scope = AbiTypeScope> = {\n [namespace in keyof namespaces]: {\n [key in keyof namespaces[namespace]]: key extends \"tables\"\n ? validateTablesWithShorthands<namespaces[namespace][key], scope>\n : validateNamespaces<namespaces[namespace], scope>[key];\n };\n};\n\nexport function resolveWorldWithShorthands<world extends WorldWithShorthandsInput>(\n world: world,\n): resolveWorldWithShorthands<world> {\n const scope = extendedScope(world);\n const tables = mapObject(world.tables ?? {}, (table) => {\n return isTableShorthandInput(table) ? resolveTableShorthand(table, scope) : table;\n });\n const namespaces = mapObject(world.namespaces ?? {}, (namespace) => ({\n ...namespace,\n tables: mapObject(namespace.tables ?? {}, (table) => {\n return isTableShorthandInput(table) ? resolveTableShorthand(table, scope) : table;\n }),\n }));\n\n const fullConfig = { ...world, tables, namespaces };\n validateWorld(fullConfig);\n\n return resolveWorld(fullConfig) as unknown as resolveWorldWithShorthands<world>;\n}\n\nexport function defineWorldWithShorthands<world>(\n world: validateWorldWithShorthands<world>,\n): resolveWorldWithShorthands<world> {\n validateWorldWithShorthands(world);\n return resolveWorldWithShorthands(world) as unknown as resolveWorldWithShorthands<world>;\n}\n"],"mappings":"2EACO,IAAMA,EAAqB,iEAGrBC,EAAkB,iDCJ/B,OAEE,iBAAAC,EACA,OAAAC,EACA,aAAAC,EACA,YAAAC,EACA,yBAAAC,EACA,yBAAAC,EAEA,gCAAAC,MAEK,8BACP,OAAS,aAAAC,MAAiB,2BA2B1B,SAASC,EAA4BC,EAA2D,CAC9F,IAAMC,EAAQC,EAAcF,CAAK,EAKjC,GAJIG,EAAUH,EAAO,QAAQ,GAC3BI,EAA6BJ,EAAM,OAAQC,CAAK,EAG9CE,EAAUH,EAAO,YAAY,GAAKK,EAASL,EAAM,UAAU,EAC7D,QAAWM,KAAgB,OAAO,KAAKN,EAAM,UAAU,EACrDI,EAA6BG,EAAIA,EAAIP,EAAM,WAAYM,CAAY,EAAG,QAAQ,GAAK,CAAC,EAAGL,CAAK,CAGlG,CAUO,SAASO,EACdR,EACmC,CACnC,IAAMC,EAAQC,EAAcF,CAAK,EAC3BS,EAASC,EAAUV,EAAM,QAAU,CAAC,EAAIW,GACrCC,EAAsBD,CAAK,EAAIE,EAAsBF,EAAOV,CAAK,EAAIU,CAC7E,EACKG,EAAaJ,EAAUV,EAAM,YAAc,CAAC,EAAIe,IAAe,CACnE,GAAGA,EACH,OAAQL,EAAUK,EAAU,QAAU,CAAC,EAAIJ,GAClCC,EAAsBD,CAAK,EAAIE,EAAsBF,EAAOV,CAAK,EAAIU,CAC7E,CACH,EAAE,EAEIK,EAAa,CAAE,GAAGhB,EAAO,OAAAS,EAAQ,WAAAK,CAAW,EAClD,OAAAG,EAAcD,CAAU,EAEjBE,EAAaF,CAAU,CAChC,CAEO,SAASG,EACdnB,EACmC,CACnC,OAAAD,EAA4BC,CAAK,EAC1BQ,EAA2BR,CAAK,CACzC","names":["worldDeployedEvent","helloWorldEvent","extendedScope","get","hasOwnKey","isObject","isTableShorthandInput","resolveTableShorthand","validateTablesWithShorthands","mapObject","validateWorldWithShorthands","world","scope","extendedScope","hasOwnKey","validateTablesWithShorthands","isObject","namespaceKey","get","resolveWorldWithShorthands","tables","mapObject","table","isTableShorthandInput","resolveTableShorthand","namespaces","namespace","fullConfig","validateWorld","resolveWorld","defineWorldWithShorthands"]}
@@ -24,7 +24,7 @@ declare const _default: {
24
24
  readonly namespaceId: "ResourceId";
25
25
  readonly owner: "address";
26
26
  };
27
- key: ["namespaceId"];
27
+ key: readonly ["namespaceId"];
28
28
  name: "NamespaceOwner";
29
29
  }>;
30
30
  readonly deploy: {
@@ -58,7 +58,7 @@ declare const _default: {
58
58
  readonly caller: "address";
59
59
  readonly access: "bool";
60
60
  };
61
- key: ["resourceId", "caller"];
61
+ key: readonly ["resourceId", "caller"];
62
62
  name: "ResourceAccess";
63
63
  }>;
64
64
  readonly deploy: {
@@ -92,7 +92,7 @@ declare const _default: {
92
92
  readonly argumentsHash: "bytes32";
93
93
  readonly isInstalled: "bool";
94
94
  };
95
- key: ["moduleAddress", "argumentsHash"];
95
+ key: readonly ["moduleAddress", "argumentsHash"];
96
96
  name: "InstalledModules";
97
97
  }>;
98
98
  readonly deploy: {
@@ -126,7 +126,7 @@ declare const _default: {
126
126
  readonly delegatee: "address";
127
127
  readonly delegationControlId: "ResourceId";
128
128
  };
129
- key: ["delegator", "delegatee"];
129
+ key: readonly ["delegator", "delegatee"];
130
130
  name: "UserDelegationControl";
131
131
  }>;
132
132
  readonly deploy: {
@@ -155,7 +155,7 @@ declare const _default: {
155
155
  readonly namespaceId: "ResourceId";
156
156
  readonly delegationControlId: "ResourceId";
157
157
  };
158
- key: ["namespaceId"];
158
+ key: readonly ["namespaceId"];
159
159
  name: "NamespaceDelegationControl";
160
160
  }>;
161
161
  readonly deploy: {
@@ -184,7 +184,7 @@ declare const _default: {
184
184
  readonly namespaceId: "ResourceId";
185
185
  readonly balance: "uint256";
186
186
  };
187
- key: ["namespaceId"];
187
+ key: readonly ["namespaceId"];
188
188
  name: "Balances";
189
189
  }>;
190
190
  readonly deploy: {
@@ -221,7 +221,7 @@ declare const _default: {
221
221
  readonly system: "address";
222
222
  readonly publicAccess: "bool";
223
223
  };
224
- key: ["systemId"];
224
+ key: readonly ["systemId"];
225
225
  name: "Systems";
226
226
  }>;
227
227
  readonly deploy: {
@@ -250,7 +250,7 @@ declare const _default: {
250
250
  readonly system: "address";
251
251
  readonly systemId: "ResourceId";
252
252
  };
253
- key: ["system"];
253
+ key: readonly ["system"];
254
254
  name: "SystemRegistry";
255
255
  }>;
256
256
  readonly deploy: {
@@ -279,7 +279,7 @@ declare const _default: {
279
279
  readonly systemId: "ResourceId";
280
280
  readonly value: "bytes21[]";
281
281
  };
282
- key: ["systemId"];
282
+ key: readonly ["systemId"];
283
283
  name: "SystemHooks";
284
284
  }>;
285
285
  readonly deploy: {
@@ -316,7 +316,7 @@ declare const _default: {
316
316
  readonly systemId: "ResourceId";
317
317
  readonly systemFunctionSelector: "bytes4";
318
318
  };
319
- key: ["worldFunctionSelector"];
319
+ key: readonly ["worldFunctionSelector"];
320
320
  name: "FunctionSelectors";
321
321
  }>;
322
322
  readonly deploy: {
@@ -345,7 +345,7 @@ declare const _default: {
345
345
  readonly functionSelector: "bytes4";
346
346
  readonly functionSignature: "string";
347
347
  };
348
- key: ["functionSelector"];
348
+ key: readonly ["functionSelector"];
349
349
  type: "offchainTable";
350
350
  name: "FunctionSignatures";
351
351
  }>;
@@ -370,7 +370,7 @@ declare const _default: {
370
370
  schema: {
371
371
  readonly value: "address";
372
372
  };
373
- key: [];
373
+ key: readonly [];
374
374
  name: "InitModuleAddress";
375
375
  }>;
376
376
  readonly deploy: {
@@ -1,5 +1,5 @@
1
1
  import { evaluate, narrow, ErrorMessage, conform } from '@arktype/util';
2
- import { StoreInput, mergeIfUndefined, resolveTable, get, extendedScope, validateTables, UserTypes, resolveStore, Store } from '@latticexyz/store/config/v2';
2
+ import { StoreInput, StoreWithShorthandsInput, mergeIfUndefined, resolveTable, get, extendedScope, Scope, AbiTypeScope, validateTables, UserTypes, resolveStore, Store } from '@latticexyz/store/config/v2';
3
3
  import { M as Module } from './output-993b3634.js';
4
4
  import { S as SYSTEM_DEFAULTS } from './defaults-87a942d7.js';
5
5
 
@@ -15,7 +15,7 @@ type SystemInput = {
15
15
  */
16
16
  registerFunctionSelectors?: boolean;
17
17
  /** If openAccess is true, any address can call the system */
18
- openAccess?: true;
18
+ openAccess?: boolean;
19
19
  /** An array of addresses or system names that can access the system */
20
20
  accessList?: string[];
21
21
  };
@@ -64,6 +64,8 @@ type NamespacesInput = {
64
64
  [key: string]: NamespaceInput;
65
65
  };
66
66
  type NamespaceInput = Pick<StoreInput, "tables">;
67
+ /******** Variations with shorthands ********/
68
+ type WorldWithShorthandsInput = Omit<WorldInput, "tables"> & Pick<StoreWithShorthandsInput, "tables">;
67
69
 
68
70
  declare const CODEGEN_DEFAULTS: {
69
71
  readonly worldInterfaceName: "IWorld";
@@ -100,6 +102,12 @@ type resolveSystems<systems extends SystemsInput> = {
100
102
  declare function resolveSystems<systems extends SystemsInput>(systems: systems): resolveSystems<systems>;
101
103
 
102
104
  type namespacedTableKeys<world> = "namespaces" extends keyof world ? "tables" extends keyof world["namespaces"][keyof world["namespaces"]] ? `${keyof world["namespaces"] & string}__${keyof world["namespaces"][keyof world["namespaces"]]["tables"] & string}` : never : never;
105
+ type validateNamespaces<namespaces, scope extends Scope = AbiTypeScope> = {
106
+ [namespace in keyof namespaces]: {
107
+ [key in keyof namespaces[namespace]]: key extends "tables" ? validateTables<namespaces[namespace][key], scope> : namespaces[namespace][key];
108
+ };
109
+ };
110
+ declare function validateNamespaces<scope extends Scope = AbiTypeScope>(namespaces: unknown, scope: scope): asserts namespaces is NamespacesInput;
103
111
  type resolveNamespacedTables<world> = "namespaces" extends keyof world ? {
104
112
  readonly [key in namespacedTableKeys<world>]: key extends `${infer namespace}__${infer table}` ? resolveTable<mergeIfUndefined<get<get<get<get<world, "namespaces">, namespace>, "tables">, table>, {
105
113
  name: table;
@@ -125,4 +133,4 @@ type resolveWorld<world> = evaluate<resolveStore<world> & mergeIfUndefined<{
125
133
  declare function resolveWorld<const world extends WorldInput>(world: world): resolveWorld<world>;
126
134
  declare function defineWorld<const world>(world: validateWorld<world>): resolveWorld<world>;
127
135
 
128
- export { defineWorld as d, resolveWorld as r, validateWorld as v };
136
+ export { WorldWithShorthandsInput as W, validateNamespaces as a, defineWorld as d, resolveWorld as r, validateWorld as v };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@latticexyz/world",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "World framework",
5
5
  "repository": {
6
6
  "type": "git",
@@ -38,15 +38,15 @@
38
38
  }
39
39
  },
40
40
  "dependencies": {
41
- "@arktype/util": "0.0.25",
41
+ "@arktype/util": "0.0.27",
42
42
  "abitype": "1.0.0",
43
43
  "arktype": "1.0.29-alpha",
44
44
  "viem": "2.7.12",
45
45
  "zod": "^3.21.4",
46
- "@latticexyz/common": "2.0.0",
47
- "@latticexyz/config": "2.0.0",
48
- "@latticexyz/schema-type": "2.0.0",
49
- "@latticexyz/store": "2.0.0"
46
+ "@latticexyz/common": "2.0.1",
47
+ "@latticexyz/config": "2.0.1",
48
+ "@latticexyz/schema-type": "2.0.1",
49
+ "@latticexyz/store": "2.0.1"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@types/ejs": "^3.1.1",
@@ -61,8 +61,8 @@
61
61
  "tsup": "^6.7.0",
62
62
  "tsx": "^3.12.6",
63
63
  "vitest": "0.34.6",
64
- "@latticexyz/abi-ts": "2.0.0",
65
- "@latticexyz/gas-report": "2.0.0"
64
+ "@latticexyz/abi-ts": "2.0.1",
65
+ "@latticexyz/gas-report": "2.0.1"
66
66
  },
67
67
  "scripts": {
68
68
  "build": "pnpm run build:mud && pnpm run build:abi && pnpm run build:abi-ts && pnpm run build:js",
@@ -14,7 +14,7 @@ export type SystemInput = {
14
14
  */
15
15
  registerFunctionSelectors?: boolean;
16
16
  /** If openAccess is true, any address can call the system */
17
- openAccess?: true;
17
+ openAccess?: boolean;
18
18
  /** An array of addresses or system names that can access the system */
19
19
  accessList?: string[];
20
20
  };
@@ -727,4 +727,29 @@ describe("defineWorld", () => {
727
727
  }),
728
728
  ).type.errors("Namespaces config will be enabled soon.");
729
729
  });
730
+
731
+ it("should allow setting openAccess of a system to false", () => {
732
+ const config = defineWorld({
733
+ systems: {
734
+ Example: {
735
+ openAccess: false,
736
+ },
737
+ },
738
+ });
739
+
740
+ attest<false>(config.systems.Example.openAccess).equals(false);
741
+ });
742
+
743
+ it("should allow a const config as input", () => {
744
+ const config = {
745
+ tables: {
746
+ Example: {
747
+ schema: { id: "address", name: "string", age: "uint256" },
748
+ key: ["age"],
749
+ },
750
+ },
751
+ } as const;
752
+
753
+ defineWorld(config);
754
+ });
730
755
  });
@@ -321,4 +321,17 @@ describe("defineWorldWithShorthands", () => {
321
321
  "Invalid schema. Expected an `id` field with a static ABI type or an explicit `key` option.",
322
322
  );
323
323
  });
324
+
325
+ it("should allow a const config as input", () => {
326
+ const config = {
327
+ tables: {
328
+ Example: {
329
+ schema: { id: "address", name: "string", age: "uint256" },
330
+ key: ["age"],
331
+ },
332
+ },
333
+ } as const;
334
+
335
+ defineWorldWithShorthands(config);
336
+ });
324
337
  });
@@ -6,5 +6,5 @@
6
6
 
7
7
  export { helloWorldEvent, worldDeployedEvent } from "../worldEvents";
8
8
 
9
- export { defineWorld } from "../config/v2/world";
9
+ export { defineWorldWithShorthands as defineWorld } from "../config/v2/worldWithShorthands";
10
10
  export type { World } from "../config/v2/output";