@valancex/common 0.14.0 → 0.15.0

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/app.js CHANGED
@@ -44,6 +44,11 @@ export const checkDefinition = (author) => {
44
44
  throw new AppDefinitionError(`src/main.ts: the state field "${name}" is the framework's (which page is shown, and the pages visited); choose another`);
45
45
  }
46
46
  }
47
+ for (const [tag, id] of Object.entries(author?.resolve ?? {})) {
48
+ if (typeof id !== "string" || !/^(@[^/\s]+\/)?[^/\s]+\/[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(id) || id.split("/").at(-1) !== tag) {
49
+ throw new AppDefinitionError(`src/main.ts: \`resolve\` maps a tag to the qualified id of the component it means, \`${tag}: "package/${tag}"\`; got ${JSON.stringify(id)} for "${tag}"`);
50
+ }
51
+ }
47
52
  const fields = Object.keys(stateOf(author)?.schema.fields ?? {});
48
53
  for (const name of persistedFields(author)) {
49
54
  if (!fields.includes(name)) {
package/dist/index.d.ts CHANGED
@@ -141,6 +141,12 @@ export type UnitCommandSpec<S, P extends Schema.Struct.Fields = Schema.Struct.Fi
141
141
  /** Events of the component the command announces to its caller, each with the payload it carries, worked out from the state the command leaves: `{ change: (next) => next.at }`. */
142
142
  readonly raises?: Readonly<Record<string, (next: S, args: Schema.Struct.Type<P>) => unknown>>;
143
143
  };
144
+ /** A command of a unit as `unit` takes it: any parameters (they are typed where the command is written, with `unitCommand`). */
145
+ type UnitCommandInput<S> = ((state: S) => Changes<S>) | {
146
+ readonly params?: Schema.Struct.Fields;
147
+ readonly run: (state: S, args: any) => Changes<S>;
148
+ readonly raises?: Readonly<Record<string, (next: S, args: any) => unknown>>;
149
+ };
144
150
  /** A command with parameters, typed: the parameters' types reach `run` and `raises`. */
145
151
  export declare const unitCommand: <S, P extends Schema.Struct.Fields>(spec: {
146
152
  readonly params: P;
@@ -165,7 +171,7 @@ export declare const unitCommand: <S, P extends Schema.Struct.Fields>(spec: {
165
171
  export declare const unit: <F extends Fields>(definition: {
166
172
  readonly state: F;
167
173
  readonly commands: {
168
- readonly [name: string]: UnitCommandSpec<StateOf<F>, any>;
174
+ readonly [name: string]: UnitCommandInput<StateOf<F>>;
169
175
  };
170
176
  readonly controllable?: ReadonlyArray<Extract<keyof F, string>>;
171
177
  }) => Valance.Unit<StateOf<F>>;
@@ -202,6 +208,12 @@ export interface AppDefinition<S extends StateInput = {}> {
202
208
  readonly components?: ReadonlyArray<Component>;
203
209
  /** Built-in components (`heading`, `runs`, …) you replace with your own template of the same name. */
204
210
  readonly override?: ReadonlyArray<Component>;
211
+ /**
212
+ * Which component a tag means when two share a name (Tier 2: nothing to write until there is a collision). A library's component has the qualified id `package/name` (`acme-ui/disclosure`); two
213
+ * libraries that both have a `disclosure`, or a library component named like a built-in, are a compile error that names both ids, and `resolve: { disclosure: "acme-ui/disclosure" }` says which one the
214
+ * tag is. The others are left out of the program, and a library template that writes the tag gets the one chosen. A built-in is replaced by the chosen library component, as `override` would.
215
+ */
216
+ readonly resolve?: Readonly<Record<string, string>>;
205
217
  /**
206
218
  * Application state beyond the page: `{ theme: field(Schema.Literal("light", "dark"), "light") }`. Its fields become names a layout can read. A hand-built `{ schema, initial }` is also accepted, for
207
219
  * hydration and shared schemas.
@@ -220,7 +220,7 @@ export const declared = {
220
220
  "type": {
221
221
  "kind": "string"
222
222
  },
223
- "required": true
223
+ "required": false
224
224
  },
225
225
  "id": {
226
226
  "type": {
@@ -237,7 +237,7 @@ export const declared = {
237
237
  "type": {
238
238
  "kind": "string"
239
239
  },
240
- "required": true
240
+ "required": false
241
241
  }
242
242
  },
243
243
  "events": {}
@@ -254,7 +254,7 @@ export const declared = {
254
254
  "type": {
255
255
  "kind": "string"
256
256
  },
257
- "required": true
257
+ "required": false
258
258
  }
259
259
  },
260
260
  "events": {}
@@ -265,7 +265,7 @@ export const declared = {
265
265
  "type": {
266
266
  "kind": "string"
267
267
  },
268
- "required": true
268
+ "required": false
269
269
  }
270
270
  },
271
271
  "events": {}
@@ -320,7 +320,7 @@ export const declared = {
320
320
  "type": {
321
321
  "kind": "string"
322
322
  },
323
- "required": true
323
+ "required": false
324
324
  },
325
325
  "src": {
326
326
  "type": {
@@ -338,7 +338,7 @@ export const declared = {
338
338
  "type": {
339
339
  "kind": "string"
340
340
  },
341
- "required": true
341
+ "required": false
342
342
  }
343
343
  },
344
344
  "events": {}
@@ -366,13 +366,13 @@ export const declared = {
366
366
  "type": {
367
367
  "kind": "string"
368
368
  },
369
- "required": true
369
+ "required": false
370
370
  },
371
371
  "current": {
372
372
  "type": {
373
373
  "kind": "string"
374
374
  },
375
- "required": true
375
+ "required": false
376
376
  }
377
377
  },
378
378
  "events": {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valancex/common",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "The author's side of a VALANCE application (defineApp, component, field) and the runtime the vlx build runs: the browser and server entries. What src/main.ts imports; @valancex/cli builds what it describes.",
5
5
  "keywords": [
6
6
  "valance",
@@ -67,8 +67,8 @@
67
67
  "@valancex/mesh-runtime": "^0.15.0 || ^0.16.0 || ^0.17.0",
68
68
  "@valancex/nexus": "^0.14.0 || ^0.15.0 || ^0.16.0",
69
69
  "@valancex/port-web": "^0.12.0 || ^0.13.0 || ^0.14.0",
70
- "@valancex/router": "^0.14.0",
71
- "@valancex/valance": "^0.14.0"
70
+ "@valancex/router": "^0.15.0",
71
+ "@valancex/valance": "^0.15.0"
72
72
  },
73
73
  "peerDependencies": {
74
74
  "effect": "^3.10.0"