@ouispec/cli 0.6.0 → 0.9.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/README.md CHANGED
@@ -25,6 +25,10 @@ Required, and explicit: nothing an app depends on has a default, so a misconfigu
25
25
  "apiSpec": "@acme/api-client/openapi.json",
26
26
  "appCatalogs": [{ "module": "src/studio/catalog.ts", "export": "canvasCatalog", "hosts": ["Canvas"] }],
27
27
  "unbound": [],
28
+ "outside": [
29
+ { "component": "SignInPage", "reason": "before sign-in" },
30
+ { "route": "/share/:token", "reason": "a public share link, opened signed out" }
31
+ ],
28
32
  "out": "src/agent/generated"
29
33
  }
30
34
  ```
@@ -42,9 +46,48 @@ Required, and explicit: nothing an app depends on has a default, so a misconfigu
42
46
  | `mappings` | no | Tier 2 mappings of third-party design systems the app does not own (below). |
43
47
  | `appCatalogs` | no | Room catalogs the app declares itself. Needs Vite (below). |
44
48
  | `unbound` | no | Pages whose controls are not all bound yet. It may only shrink. |
49
+ | `outside` | no | Pages the assistant is never on, each by `component` or `route`, with its `reason` (below). |
45
50
 
46
51
  `apiClient` was replaced by `apiSpec`.
47
52
 
53
+ ## Pages outside the assistant
54
+
55
+ Pages before sign-in, and public pages a link opens (a share link, a confirmation link), have no assistant. `outside` names each, by its page component or by a route it is on, with the reason:
56
+
57
+ ```json
58
+ "outside": [
59
+ { "component": "SignInPage", "reason": "before sign-in" },
60
+ { "route": "/share/:token", "reason": "a public share link, opened signed out" }
61
+ ]
62
+ ```
63
+
64
+ An outside page has no surface, its controls are not enforced, it is not among the pages `app_navigate` lists, and the knowledge's overview tells the assistant it is not on those routes. A page on several routes is outside on all of them: named by route, each of its routes is named. A page is in `unbound` (the assistant is on it, but it is not bound yet) or in `outside`, never both.
65
+
66
+ The list cannot hide a page of the app. A page is outside only when nothing around it or in it is the assistant's, and the build fails, naming the reason, when:
67
+
68
+ - a `shell` entry frames one of its routes;
69
+ - an element its routes render around it, a layout route's or a `routeWrappers` component's at any level, holds something someone can use (a control, bound or not, a display, a room) or a person-only component, which is how the assistant's own UI is declared. A wrapper that is not the app's own (`Suspense`) renders only what it is given; a layout route's element must be the app's own;
70
+ - the page renders the app's frame (a `shell` entry, or a layout route that is a frame) itself;
71
+ - the page has a binding, display or room of its own, on no page the assistant is on. One a component shares with pages the assistant is on (a video player on a public watch page and in the app) is that component's, and is offered on those pages.
72
+
73
+ So a page under the app's frame, or one that binds anything only for itself, is never outside.
74
+
75
+ ## A page's query
76
+
77
+ A list page that keeps its filters in its address declares the query it reads, once, with `defineQuery` from `@ouispec/bindings`, and reads it with `readQuery` (and writes it with `writeQuery`):
78
+
79
+ ```ts
80
+ export const LANE_QUERY = defineQuery({
81
+ view: { values: LANE_VIEWS, default: 'lane', description: 'The open lane, or closed repair orders with declined work' },
82
+ advisor: { type: 'string', description: 'A service advisor, by name as the lane shows it' },
83
+ });
84
+ const query = readQuery(LANE_QUERY, searchParams);
85
+ ```
86
+
87
+ The generator finds each `readQuery(<declaration>, …)` in the page, in a component it renders, or in an app hook they call (the hook may take the declaration as an argument), follows the declaration to its `defineQuery({ … })` constant, and reads it as it reads a binding: every value a build-time constant, an imported option list included. The generated `app.navigate` then takes `query`, one alternative per such page with its routes in `x-routes`, `path` names the page's parameters (`/dashboard/service-lane (Service lane; ?view, ?advisor)`), and the page's knowledge lists them, so the assistant opens the page filtered in one call. `app.navigate` also takes `params`, which fills a route's `:parameters` when `path` is written as the route. A build where no page declares a query is generated as before, with `params` added. The contract's integrator guide ("Going to a page, already filtered") has the declaration's schema and what the runtime checks.
88
+
89
+ The build fails for a declaration it cannot read (`readQuery` given something other than a `defineQuery` constant, or a value built by a call), one that does not match `page-query.json`, a default the page would never read back (not one of its values, out of its range, on a `multiple`), and a parameter two declarations on one page give different meanings.
90
+
48
91
  ## Design systems
49
92
 
50
93
  Each package in `designSystem` must resolve from the app and name its control table in its `package.json`:
@@ -87,6 +130,8 @@ The app imports mapped controls from the bound module. Each use is read as a tie
87
130
  - A room recipe naming an entry the room does not have.
88
131
  - On an enforced page, a mapped control imported straight from its package: the error names the bound import.
89
132
  - A mapping that does not match its schema, names a package the app cannot resolve, maps a package also in `designSystem` (or one of its subpaths, or a package one of whose subpaths `designSystem` lists), maps a package another mapping maps, uses a kind no design system registers, or does not fit the package's types (an export it does not have, a prop its component does not take).
133
+ - A page in `outside` that the assistant may be on (above), or one that is also in `unbound`, or an entry naming no page.
134
+ - A page's query the build cannot read, or one that breaks `page-query.json` or declares a parameter twice differently (above).
90
135
  - A stale bound module or control table, or a file in `<out>/bound/` no mapping emits (`--check`; writing removes it).
91
136
 
92
137
  ## Person-only components
@@ -101,7 +146,7 @@ On one of these components, the generator fails the build for:
101
146
  - an `agent` prop, even `{ nonAgent }`;
102
147
  - a spread of props, which could carry a binding the build cannot see.
103
148
 
104
- What such a component renders is never bound, so its callbacks need no `data-non-agent`. `@ouispec/agent-react` declares `ApprovalCard` this way.
149
+ What such a component renders is never bound, so its callbacks need no `data-non-agent`. `@ouispec/agent-react` declares `ApprovalCard` this way. A package listed in `designSystem` declares its own the same way (a sign-in screen, the assistant's panel): a person-only export needs no control table entry, and one that is in both is an error, as the package must say which it is.
105
150
 
106
151
  ## The contract's vocabulary
107
152
 
package/dist/analyze.d.ts CHANGED
@@ -86,8 +86,24 @@ export interface Tier2Found {
86
86
  /** It passes props through a spread, which the build cannot read. */
87
87
  spread: boolean;
88
88
  }
89
+ /**
90
+ * A query the page reads from its address: `readQuery(<declaration>, …)` in
91
+ * the page, a component it renders or an app hook they call, with the
92
+ * declaration (`defineQuery({ … })`) as the build reads it.
93
+ */
94
+ export interface FoundQuery {
95
+ /** The declaration's constant (`LANE_QUERY`), or `readQuery` for one written in the call. */
96
+ name: string;
97
+ /** Where the declaration is written. */
98
+ file: string;
99
+ line: number;
100
+ /** Its value as the build reads it: a `PageQuery` when every value is a build-time constant. */
101
+ declaration: unknown;
102
+ }
89
103
  export interface PageAnalysis {
90
104
  controls: FoundControl[];
105
+ /** The queries the page reads from its address, each declaration once. */
106
+ queries: FoundQuery[];
91
107
  rooms: Set<LoadedCatalog>;
92
108
  dialogs: DialogStep[];
93
109
  /** The page's own PageHeader: its title and every description it can show. */
@@ -109,6 +125,10 @@ export interface PageAnalysis {
109
125
  * is checked against the actions there are.
110
126
  */
111
127
  nonAgent: Finding[];
128
+ /** Where a person-only component (`oui.personOnly`) is rendered, each naming it: the person's own UI, such as the assistant's. */
129
+ personOnly: Finding[];
130
+ /** Every one of the app's components the page renders, itself included. */
131
+ components: Set<ts.Node>;
112
132
  }
113
133
  export declare class PageAnalyzer {
114
134
  private readonly source;
@@ -148,12 +168,25 @@ export declare class PageAnalyzer {
148
168
  private destructuredProps;
149
169
  private walk;
150
170
  /**
151
- * `useRoomRegistration(catalog, …)` in a body, or in an app hook it calls
152
- * (`useVectorBoardSurface()`), followed hook by hook.
171
+ * `useRoomRegistration(catalog, …)` and `readQuery(declaration, …)` in a
172
+ * body, or in an app hook it calls (`useVectorBoardSurface()`,
173
+ * `useLaneQuery()`), followed hook by hook.
153
174
  */
154
175
  private findRegistrations;
155
176
  /** The catalog an expression names: a package's, by import, or the app's own, by module and export. */
156
177
  private catalogFor;
178
+ /**
179
+ * Whether a callee is `@ouispec/bindings`'s export of this name: imported
180
+ * from the package (renamed or through a namespace import), or re-exported
181
+ * by the app's own module and resolved to the package's declaration.
182
+ */
183
+ private isBindingsExport;
184
+ /**
185
+ * A `readQuery(declaration, …)` call: its declaration, followed to the
186
+ * `defineQuery({ … })` constant it names, read as the build reads a
187
+ * binding. Each declaration once, however many components read it.
188
+ */
189
+ private recordQuery;
157
190
  /**
158
191
  * The package a JSX tag or identifier is imported from: a bound module's key
159
192
  * (`bound:<package>`) when it comes from a tier 2 bound module, however the
@@ -1 +1 @@
1
- {"version":3,"file":"analyze.d.ts","sourceRoot":"","sources":["../src/analyze.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,E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IACH,OAAO,CAAC,YAAY;IAsBpB;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAqBtB,OAAO,CAAC,OAAO;IAiNf,OAAO,CAAC,KAAK;IAwDb,OAAO,CAAC,QAAQ;IAehB,OAAO,CAAC,OAAO;IAgCf,OAAO,CAAC,KAAK;IAcb,OAAO,CAAC,OAAO;IA4Bf;;;;;OAKG;IACH,OAAO,CAAC,aAAa;IAYrB,OAAO,CAAC,WAAW;IAcnB;;;;;;OAMG;IACH,OAAO,CAAC,OAAO;IAqDf,4FAA4F;IAC5F,OAAO,CAAC,YAAY;IAapB;;;;OAIG;IACH,OAAO,CAAC,MAAM;IAgCd;;;;;OAKG;IACH,OAAO,CAAC,cAAc;IA6BtB;;;;;;OAMG;IACH,OAAO,CAAC,iBAAiB;CAoB1B;AA0HD,4EAA4E;AAC5E,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,CAAC,IAAI,EAAE,GAAG,MAAM,EAAE,CAWnE"}
package/dist/analyze.js CHANGED
@@ -67,6 +67,7 @@ export class PageAnalyzer {
67
67
  analyze(pageDecl) {
68
68
  const result = {
69
69
  controls: [],
70
+ queries: [],
70
71
  rooms: new Set(),
71
72
  dialogs: [],
72
73
  header: { title: null, subtitles: [] },
@@ -75,6 +76,8 @@ export class PageAnalyzer {
75
76
  errors: [],
76
77
  tier2Uses: [],
77
78
  nonAgent: [],
79
+ personOnly: [],
80
+ components: new Set(),
78
81
  };
79
82
  this.nonAgentReasons = result.nonAgent;
80
83
  this.importsChecked = new Set();
@@ -158,6 +161,7 @@ export class PageAnalyzer {
158
161
  const sf = decl.getSourceFile();
159
162
  if (!this.source.isAppFile(sf))
160
163
  return;
164
+ out.components.add(decl);
161
165
  const key = `${sf.fileName}:${decl.pos}:${ctx.element ? `${ctx.element.getSourceFile().fileName}@${ctx.element.pos}` : ''}:${ctx.reach.map(r => JSON.stringify({ ...r, owner: undefined, setters: undefined })).join('>')}:${ctx.itemized}`;
162
166
  if (seen.has(key) || ctx.depth > 40)
163
167
  return;
@@ -175,8 +179,9 @@ export class PageAnalyzer {
175
179
  visit(body);
176
180
  }
177
181
  /**
178
- * `useRoomRegistration(catalog, …)` in a body, or in an app hook it calls
179
- * (`useVectorBoardSurface()`), followed hook by hook.
182
+ * `useRoomRegistration(catalog, …)` and `readQuery(declaration, …)` in a
183
+ * body, or in an app hook it calls (`useVectorBoardSurface()`,
184
+ * `useLaneQuery()`), followed hook by hook.
180
185
  */
181
186
  findRegistrations(node, out, seen, args = new Map()) {
182
187
  // An argument named by one of the hook's own parameters is what its caller passed.
@@ -192,6 +197,9 @@ export class PageAnalyzer {
192
197
  if (catalog)
193
198
  out.rooms.add(catalog);
194
199
  }
200
+ else if (this.isBindingsExport(callee, 'readQuery')) {
201
+ this.recordQuery(n, n.arguments[0] ? passed(n.arguments[0]) : undefined, out);
202
+ }
195
203
  else if (ts.isIdentifier(callee) && /^use[A-Z]/.test(callee.text)) {
196
204
  const symbol = resolveSymbol(this.source.checker, callee);
197
205
  const decl = symbol?.valueDeclaration ?? symbol?.declarations?.[0];
@@ -234,6 +242,86 @@ export class PageAnalyzer {
234
242
  const file = decl.getSourceFile().fileName;
235
243
  return this.catalogs.find(c => c.appModule?.file === file && c.appModule.export === symbol.name);
236
244
  }
245
+ /**
246
+ * Whether a callee is `@ouispec/bindings`'s export of this name: imported
247
+ * from the package (renamed or through a namespace import), or re-exported
248
+ * by the app's own module and resolved to the package's declaration.
249
+ */
250
+ isBindingsExport(callee, name) {
251
+ const BINDINGS = '@ouispec/bindings';
252
+ const e = unwrap(callee);
253
+ const id = ts.isPropertyAccessExpression(e) ? e.expression : e;
254
+ if (!ts.isIdentifier(id))
255
+ return false;
256
+ const decl = this.source.checker.getSymbolAtLocation(id)?.declarations?.[0];
257
+ if (decl) {
258
+ let n = decl;
259
+ while (n && !ts.isImportDeclaration(n))
260
+ n = n.parent;
261
+ if (n && ts.isImportDeclaration(n) && ts.isStringLiteral(n.moduleSpecifier) && n.moduleSpecifier.text === BINDINGS) {
262
+ if (ts.isNamespaceImport(decl))
263
+ return ts.isPropertyAccessExpression(e) && e.name.text === name;
264
+ return ts.isImportSpecifier(decl) && !ts.isPropertyAccessExpression(e) && (decl.propertyName ?? decl.name).text === name;
265
+ }
266
+ }
267
+ const target = resolveSymbol(this.source.checker, ts.isPropertyAccessExpression(e) ? e.name : id);
268
+ const declared = target?.valueDeclaration ?? target?.declarations?.[0];
269
+ return (!!declared &&
270
+ target.name === name &&
271
+ /[\\/]@ouispec[\\/]bindings[\\/]/.test(declared.getSourceFile().fileName));
272
+ }
273
+ /**
274
+ * A `readQuery(declaration, …)` call: its declaration, followed to the
275
+ * `defineQuery({ … })` constant it names, read as the build reads a
276
+ * binding. Each declaration once, however many components read it.
277
+ */
278
+ recordQuery(call, arg, out) {
279
+ const at = (node) => {
280
+ const sf = node.getSourceFile();
281
+ return { file: this.source.rel(sf), line: sf.getLineAndCharacterOfPosition(node.getStart()).line + 1 };
282
+ };
283
+ let expr = arg ? unwrap(arg) : undefined;
284
+ let name = 'readQuery';
285
+ let where = call;
286
+ if (expr && ts.isIdentifier(expr)) {
287
+ const symbol = resolveSymbol(this.source.checker, expr);
288
+ const decl = symbol?.valueDeclaration ?? symbol?.declarations?.[0];
289
+ if (decl && ts.isVariableDeclaration(decl) && decl.initializer && decl.parent.flags & ts.NodeFlags.Const) {
290
+ name = expr.text;
291
+ where = decl;
292
+ expr = unwrap(decl.initializer);
293
+ }
294
+ else {
295
+ out.errors.push({
296
+ ...at(call),
297
+ message: `readQuery(${expr.text}, …): its declaration must be a constant the build can read, \`const ${expr.text} = defineQuery({ … })\``,
298
+ });
299
+ return;
300
+ }
301
+ }
302
+ if (expr && ts.isCallExpression(expr) && this.isBindingsExport(expr.expression, 'defineQuery'))
303
+ expr = expr.arguments[0];
304
+ if (!expr || !ts.isObjectLiteralExpression(unwrap(expr))) {
305
+ out.errors.push({
306
+ ...at(call),
307
+ message: `readQuery(…): its declaration must be \`defineQuery({ … })\`, written as an object the build can read`,
308
+ });
309
+ return;
310
+ }
311
+ const place = at(where);
312
+ if (out.queries.some(q => q.file === place.file && q.line === place.line && q.name === name))
313
+ return;
314
+ const declaration = evaluate(this.source.checker, expr);
315
+ const unknown = unknownPaths(declaration);
316
+ if (unknown.length) {
317
+ out.errors.push({
318
+ ...place,
319
+ message: `The query ${name} has values the build cannot read without running the app (${unknown.join(', ')}): each must be a literal, a constant or an option list it can follow`,
320
+ });
321
+ return;
322
+ }
323
+ out.queries.push({ name, ...place, declaration });
324
+ }
237
325
  /**
238
326
  * The package a JSX tag or identifier is imported from: a bound module's key
239
327
  * (`bound:<package>`) when it comes from a tier 2 bound module, however the
@@ -432,6 +520,12 @@ export class PageAnalyzer {
432
520
  const local = this.localReach(el, body, tabs, out, decl, ctx);
433
521
  const reach = [...ctx.reach, ...local.reach];
434
522
  const itemized = local.itemized ?? ctx.itemized;
523
+ // A person-only component, a design system's as much as any other package's.
524
+ const personOnly = pkg ? this.personOnly(pkg).get(this.importedName(el.tagName)) : undefined;
525
+ if (pkg && personOnly) {
526
+ this.personOnlyElement(el, tagText, pkg, personOnly, out);
527
+ return;
528
+ }
435
529
  if (pkg && this.designSystem.includes(pkg)) {
436
530
  const name = this.controlName(pkg, el.tagName);
437
531
  if (isPage && name === 'PageHeader' && out.header.title === null) {
@@ -452,11 +546,6 @@ export class PageAnalyzer {
452
546
  // A mapped control imported straight from its package: its import is reported (checkMappedImports).
453
547
  if (pkg && this.mappedByPackage.get(pkg)?.exports.has(this.importedName(el.tagName)))
454
548
  return;
455
- const personOnly = pkg ? this.personOnly(pkg).get(this.importedName(el.tagName)) : undefined;
456
- if (pkg && personOnly) {
457
- this.personOnlyElement(el, tagText, pkg, personOnly, out);
458
- return;
459
- }
460
549
  const room = pkg && this.catalogs.find(c => c.package === pkg && c.hosts.includes(this.importedName(el.tagName)));
461
550
  if (room) {
462
551
  out.rooms.add(room);
@@ -516,6 +605,13 @@ export class PageAnalyzer {
516
605
  personOnlyElement(el, tag, pkg, why, out) {
517
606
  const sf = el.getSourceFile();
518
607
  const at = { file: this.source.rel(sf), line: sf.getLineAndCharacterOfPosition(el.getStart()).line + 1 };
608
+ out.personOnly.push({ ...at, message: `<${tag}> from ${pkg}` });
609
+ if (this.controls.has(`${pkg}#${this.importedName(el.tagName)}`)) {
610
+ out.errors.push({
611
+ ...at,
612
+ message: `<${tag}> is in ${pkg}'s control table and also person-only (oui.personOnly: ${why}): ${pkg} must say one or the other`,
613
+ });
614
+ }
519
615
  if (hasJsxAttribute(el, 'agent')) {
520
616
  out.errors.push({ ...at, message: `<${tag}> from ${pkg} is the person's own and takes no agent binding: ${why}` });
521
617
  }
@@ -1469,4 +1565,14 @@ function repeats(node, scope) {
1469
1565
  }
1470
1566
  return false;
1471
1567
  }
1568
+ /** Where a value read from source holds something only running the app would know: `view.values[2].label`. */
1569
+ function unknownPaths(value, path = '') {
1570
+ if (value === UNKNOWN)
1571
+ return [path || '(the whole declaration)'];
1572
+ if (Array.isArray(value))
1573
+ return value.flatMap((v, i) => unknownPaths(v, `${path}[${i}]`));
1574
+ if (value && typeof value === 'object')
1575
+ return Object.entries(value).flatMap(([k, v]) => unknownPaths(v, path ? `${path}.${k}` : k));
1576
+ return [];
1577
+ }
1472
1578
  //# sourceMappingURL=analyze.js.map