@atscript/ui 0.1.133 → 0.1.135

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/index.cjs CHANGED
@@ -268,22 +268,55 @@ function collectLiterals(items, seen) {
268
268
  //#endregion
269
269
  //#region src/value-help/extract-ref.ts
270
270
  /**
271
- * Synchronous probe. Returns `{ url, targetField }` iff:
272
- * 1. the prop carries `@db.rel.FK`,
273
- * 2. the prop has a `.ref`,
271
+ * Hard cap on how many `.ref` hops the chain walk follows. Real chains are one
272
+ * or two hops (view field → table field → dictionary); the cap is a backstop,
273
+ * not a modelling limit — and it is also what terminates a cyclic chain.
274
+ */
275
+ const MAX_REF_CHAIN_DEPTH = 8;
276
+ /**
277
+ * Synchronous probe. Returns `{ url, targetField }` for the first link of the
278
+ * reference chain starting at `prop` that satisfies all three conditions:
279
+ *
280
+ * 1. the link carries `@db.rel.FK`,
281
+ * 2. the link has a `.ref`,
274
282
  * 3. the ref's target metadata carries `@db.http.path`.
283
+ *
284
+ * Since 0.1.134 the probe follows **reference chains**: when a link does not
285
+ * qualify, it hops onto the referenced field (`ref.type()` → that object's
286
+ * `props[ref.field]`) and re-tests. A view field declared as
287
+ * `errorCode: Issue.errorCode`, where `Issue.errorCode: ErrorCode.code` is the
288
+ * link carrying `@db.rel.FK`, therefore keeps its value help instead of losing
289
+ * the dictionary.
290
+ *
291
+ * This mirrors what the server already does on the `/meta` path: since
292
+ * `@atscript/db` 0.1.128 the serialized meta collapses such chains onto the
293
+ * terminal field (`ref` → terminal, `db.rel.FK: true`), so a form def built
294
+ * from `/meta` and one built from the compiled `.as` type land on the same
295
+ * dictionary.
296
+ *
297
+ * The walk is bounded ({@link MAX_REF_CHAIN_DEPTH}), which is also what makes a
298
+ * cyclic chain terminate (it runs out of hops and gives up instead of looping).
299
+ * It stops as soon as a link has no `.ref`, or the referenced
300
+ * field cannot be found — e.g. behind a shallow `{ id, metadata }` ref target
301
+ * from `/meta`, which carries no props (and needs none: the server already
302
+ * resolved the chain).
275
303
  */
276
304
  function extractValueHelp(prop) {
277
- if (!prop.metadata.has("db.rel.FK")) return void 0;
278
- if (!prop.ref) return void 0;
279
- const target = prop.ref.type();
280
- if (!target) return void 0;
281
- const url = target.metadata.get(DB_HTTP_PATH);
282
- if (!url) return void 0;
283
- return {
284
- url,
285
- targetField: prop.ref.field
286
- };
305
+ let node = prop;
306
+ for (let depth = 0; node && depth < MAX_REF_CHAIN_DEPTH; depth++) {
307
+ const ref = node.ref;
308
+ if (!ref) return void 0;
309
+ const target = ref.type();
310
+ if (!target) return void 0;
311
+ if (node.metadata.has("db.rel.FK")) {
312
+ const url = target.metadata.get(DB_HTTP_PATH);
313
+ if (url) return {
314
+ url,
315
+ targetField: ref.field
316
+ };
317
+ }
318
+ node = (target.type.kind === "object" ? target.type : void 0)?.props.get(ref.field);
319
+ }
287
320
  }
288
321
  //#endregion
289
322
  //#region src/form/create-form-def.ts
@@ -329,11 +362,7 @@ function createFormDef(type, opts) {
329
362
  if (isChildOfStructured(path, structuredPrefixes)) continue;
330
363
  const originalProp = resolveOriginalProp(objectType, path) ?? prop;
331
364
  const kind = originalProp.type.kind;
332
- if (kind === "object") {
333
- const hasLabel = getFieldMeta(originalProp, META_LABEL) !== void 0;
334
- const hasComponent = getFieldMeta(originalProp, UI_FORM_COMPONENT) !== void 0;
335
- if (!hasLabel && !hasComponent) continue;
336
- }
365
+ if (kind === "object" && !isStructuredObject(originalProp)) continue;
337
366
  if (kind === "array") {
338
367
  if (originalProp.type.of.type.kind === "array" && !getFieldMeta(originalProp, "ui.form.component")) continue;
339
368
  }
@@ -375,13 +404,15 @@ function createFieldDef(path, prop) {
375
404
  const allStatic = !hasComputedAnnotations(prop);
376
405
  const uiType = getFieldMeta(prop, "ui.form.type") ?? getFieldMeta(prop, "ui.type");
377
406
  const pushDown = getFieldMeta(prop, UI_FORM_PUSH_DOWN) !== void 0;
407
+ const valueHelpInfo = extractValueHelp(prop);
378
408
  const base = {
379
409
  path,
380
410
  prop,
381
411
  phantom: false,
382
412
  name,
383
413
  allStatic,
384
- pushDown
414
+ pushDown,
415
+ valueHelpInfo
385
416
  };
386
417
  const customType = uiType;
387
418
  if (kind === "array") {
@@ -441,7 +472,7 @@ function createFieldDef(path, prop) {
441
472
  })
442
473
  };
443
474
  }
444
- if (extractValueHelp(prop)) return {
475
+ if (valueHelpInfo) return {
445
476
  ...base,
446
477
  type: uiType ?? "ref"
447
478
  };
@@ -473,6 +504,49 @@ function createFieldDef(path, prop) {
473
504
  phantom: kind === "" && dt === "phantom"
474
505
  };
475
506
  }
507
+ /** Non-`ui.form.*` keys that still address the object itself. */
508
+ const OBJECT_IDENTITY_KEYS = new Set([
509
+ META_LABEL,
510
+ META_DESCRIPTION,
511
+ UI_TYPE
512
+ ]);
513
+ const UI_FORM_NS = "ui.form.";
514
+ /** `ui.form.*` keys that place a field rather than give it an identity. */
515
+ const UI_FORM_PLACEMENT_NS = "ui.form.grid.";
516
+ /**
517
+ * Whether an object prop renders as a field of its own rather than being
518
+ * flattened into its parent.
519
+ *
520
+ * Any `@ui.form.*` annotation (plus `@meta.label` / `@meta.description` /
521
+ * `@ui.type`) means the author addressed the object itself, so it needs a
522
+ * field to carry that instruction to a renderer — a collapsible section, or
523
+ * whatever `@ui.form.component` / `@ui.form.type` names. An object with none
524
+ * of them is a pure namespace: it is dropped and its children render inline
525
+ * in the parent grid, which keeps DB-flattened structs (`addr.street` stored
526
+ * as `addr__street`) from growing chrome nobody asked for. `@db.*`,
527
+ * `@expect.*` and the rest of `@meta.*` stay out for exactly that reason —
528
+ * they are what such a struct carries.
529
+ *
530
+ * Placement keys (`@ui.form.order`, `@ui.form.grid.*`) are excluded: they
531
+ * position a field among its siblings, and a namespace has no position of its
532
+ * own — its children carry their own.
533
+ *
534
+ * A prefix rule rather than a list because the list was wrong the moment it
535
+ * was written. Matching on `@meta.label` and `@ui.form.component` alone left
536
+ * every other key to be read off a prop that never became a field: a
537
+ * `@meta.description` went missing, a `@ui.form.type` component silently
538
+ * never mounted, `@ui.form.pushDown` never pushed down, and — the one that
539
+ * mattered — `@ui.form.hidden` on a struct left every child on screen.
540
+ */
541
+ function isStructuredObject(prop) {
542
+ for (const key of prop.metadata.keys()) {
543
+ if (OBJECT_IDENTITY_KEYS.has(key)) return true;
544
+ if (!key.startsWith(UI_FORM_NS)) continue;
545
+ if (key === "ui.form.order" || key.startsWith(UI_FORM_PLACEMENT_NS)) continue;
546
+ return true;
547
+ }
548
+ return false;
549
+ }
476
550
  /** Resolves the original annotated type from the type hierarchy by path. */
477
551
  function resolveOriginalProp(type, path) {
478
552
  const parts = path.split(".");
package/dist/index.d.cts CHANGED
@@ -151,6 +151,15 @@ interface FormFieldDef {
151
151
  * stays in `fields[]` for validation/data; only its render slot moves.
152
152
  */
153
153
  pushDown: boolean;
154
+ /**
155
+ * Value-help target for an FK field — `{ url, targetField }` resolved once by
156
+ * `extractValueHelp` while the def is built (since 0.1.134; mirrors
157
+ * `ColumnDef.valueHelpInfo` on the table side). `undefined` for every field
158
+ * that is not an FK. Renderers read this instead of re-walking the
159
+ * annotations per field, which also keeps the annotation dependency out of
160
+ * the component layer.
161
+ */
162
+ valueHelpInfo?: ValueHelpInfo;
154
163
  }
155
164
  /**
156
165
  * Complete form definition — produced by createFormDef().
@@ -414,10 +423,32 @@ declare function isPureLiteralUnion(prop: TAtscriptAnnotatedType): boolean;
414
423
  //#endregion
415
424
  //#region src/value-help/extract-ref.d.ts
416
425
  /**
417
- * Synchronous probe. Returns `{ url, targetField }` iff:
418
- * 1. the prop carries `@db.rel.FK`,
419
- * 2. the prop has a `.ref`,
426
+ * Synchronous probe. Returns `{ url, targetField }` for the first link of the
427
+ * reference chain starting at `prop` that satisfies all three conditions:
428
+ *
429
+ * 1. the link carries `@db.rel.FK`,
430
+ * 2. the link has a `.ref`,
420
431
  * 3. the ref's target metadata carries `@db.http.path`.
432
+ *
433
+ * Since 0.1.134 the probe follows **reference chains**: when a link does not
434
+ * qualify, it hops onto the referenced field (`ref.type()` → that object's
435
+ * `props[ref.field]`) and re-tests. A view field declared as
436
+ * `errorCode: Issue.errorCode`, where `Issue.errorCode: ErrorCode.code` is the
437
+ * link carrying `@db.rel.FK`, therefore keeps its value help instead of losing
438
+ * the dictionary.
439
+ *
440
+ * This mirrors what the server already does on the `/meta` path: since
441
+ * `@atscript/db` 0.1.128 the serialized meta collapses such chains onto the
442
+ * terminal field (`ref` → terminal, `db.rel.FK: true`), so a form def built
443
+ * from `/meta` and one built from the compiled `.as` type land on the same
444
+ * dictionary.
445
+ *
446
+ * The walk is bounded ({@link MAX_REF_CHAIN_DEPTH}), which is also what makes a
447
+ * cyclic chain terminate (it runs out of hops and gives up instead of looping).
448
+ * It stops as soon as a link has no `.ref`, or the referenced
449
+ * field cannot be found — e.g. behind a shallow `{ id, metadata }` ref target
450
+ * from `/meta`, which carries no props (and needs none: the server already
451
+ * resolved the chain).
421
452
  */
422
453
  declare function extractValueHelp(prop: TAtscriptAnnotatedType): ValueHelpInfo | undefined;
423
454
  //#endregion
@@ -1121,6 +1152,15 @@ interface ColumnDef {
1121
1152
  * (`path: '__actions'`).
1122
1153
  */
1123
1154
  fixed?: boolean;
1155
+ /**
1156
+ * Client-owned (display-only) column: nothing on the server backs it, so it
1157
+ * never enters `$select`, server sorting or filters. It still takes part in
1158
+ * column visibility, reordering and presets like any other column. Produced
1159
+ * from `<AsTableRoot :display-columns>`. A `local` column with
1160
+ * `sortable: true` is sorted in memory over the loaded page, never by the
1161
+ * server. Since 0.1.134.
1162
+ */
1163
+ local?: boolean;
1124
1164
  }
1125
1165
  /** A single sort directive. */
1126
1166
  interface SortControl {
package/dist/index.d.mts CHANGED
@@ -151,6 +151,15 @@ interface FormFieldDef {
151
151
  * stays in `fields[]` for validation/data; only its render slot moves.
152
152
  */
153
153
  pushDown: boolean;
154
+ /**
155
+ * Value-help target for an FK field — `{ url, targetField }` resolved once by
156
+ * `extractValueHelp` while the def is built (since 0.1.134; mirrors
157
+ * `ColumnDef.valueHelpInfo` on the table side). `undefined` for every field
158
+ * that is not an FK. Renderers read this instead of re-walking the
159
+ * annotations per field, which also keeps the annotation dependency out of
160
+ * the component layer.
161
+ */
162
+ valueHelpInfo?: ValueHelpInfo;
154
163
  }
155
164
  /**
156
165
  * Complete form definition — produced by createFormDef().
@@ -414,10 +423,32 @@ declare function isPureLiteralUnion(prop: TAtscriptAnnotatedType): boolean;
414
423
  //#endregion
415
424
  //#region src/value-help/extract-ref.d.ts
416
425
  /**
417
- * Synchronous probe. Returns `{ url, targetField }` iff:
418
- * 1. the prop carries `@db.rel.FK`,
419
- * 2. the prop has a `.ref`,
426
+ * Synchronous probe. Returns `{ url, targetField }` for the first link of the
427
+ * reference chain starting at `prop` that satisfies all three conditions:
428
+ *
429
+ * 1. the link carries `@db.rel.FK`,
430
+ * 2. the link has a `.ref`,
420
431
  * 3. the ref's target metadata carries `@db.http.path`.
432
+ *
433
+ * Since 0.1.134 the probe follows **reference chains**: when a link does not
434
+ * qualify, it hops onto the referenced field (`ref.type()` → that object's
435
+ * `props[ref.field]`) and re-tests. A view field declared as
436
+ * `errorCode: Issue.errorCode`, where `Issue.errorCode: ErrorCode.code` is the
437
+ * link carrying `@db.rel.FK`, therefore keeps its value help instead of losing
438
+ * the dictionary.
439
+ *
440
+ * This mirrors what the server already does on the `/meta` path: since
441
+ * `@atscript/db` 0.1.128 the serialized meta collapses such chains onto the
442
+ * terminal field (`ref` → terminal, `db.rel.FK: true`), so a form def built
443
+ * from `/meta` and one built from the compiled `.as` type land on the same
444
+ * dictionary.
445
+ *
446
+ * The walk is bounded ({@link MAX_REF_CHAIN_DEPTH}), which is also what makes a
447
+ * cyclic chain terminate (it runs out of hops and gives up instead of looping).
448
+ * It stops as soon as a link has no `.ref`, or the referenced
449
+ * field cannot be found — e.g. behind a shallow `{ id, metadata }` ref target
450
+ * from `/meta`, which carries no props (and needs none: the server already
451
+ * resolved the chain).
421
452
  */
422
453
  declare function extractValueHelp(prop: TAtscriptAnnotatedType): ValueHelpInfo | undefined;
423
454
  //#endregion
@@ -1121,6 +1152,15 @@ interface ColumnDef {
1121
1152
  * (`path: '__actions'`).
1122
1153
  */
1123
1154
  fixed?: boolean;
1155
+ /**
1156
+ * Client-owned (display-only) column: nothing on the server backs it, so it
1157
+ * never enters `$select`, server sorting or filters. It still takes part in
1158
+ * column visibility, reordering and presets like any other column. Produced
1159
+ * from `<AsTableRoot :display-columns>`. A `local` column with
1160
+ * `sortable: true` is sorted in memory over the loaded page, never by the
1161
+ * server. Since 0.1.134.
1162
+ */
1163
+ local?: boolean;
1124
1164
  }
1125
1165
  /** A single sort directive. */
1126
1166
  interface SortControl {
package/dist/index.mjs CHANGED
@@ -267,22 +267,55 @@ function collectLiterals(items, seen) {
267
267
  //#endregion
268
268
  //#region src/value-help/extract-ref.ts
269
269
  /**
270
- * Synchronous probe. Returns `{ url, targetField }` iff:
271
- * 1. the prop carries `@db.rel.FK`,
272
- * 2. the prop has a `.ref`,
270
+ * Hard cap on how many `.ref` hops the chain walk follows. Real chains are one
271
+ * or two hops (view field → table field → dictionary); the cap is a backstop,
272
+ * not a modelling limit — and it is also what terminates a cyclic chain.
273
+ */
274
+ const MAX_REF_CHAIN_DEPTH = 8;
275
+ /**
276
+ * Synchronous probe. Returns `{ url, targetField }` for the first link of the
277
+ * reference chain starting at `prop` that satisfies all three conditions:
278
+ *
279
+ * 1. the link carries `@db.rel.FK`,
280
+ * 2. the link has a `.ref`,
273
281
  * 3. the ref's target metadata carries `@db.http.path`.
282
+ *
283
+ * Since 0.1.134 the probe follows **reference chains**: when a link does not
284
+ * qualify, it hops onto the referenced field (`ref.type()` → that object's
285
+ * `props[ref.field]`) and re-tests. A view field declared as
286
+ * `errorCode: Issue.errorCode`, where `Issue.errorCode: ErrorCode.code` is the
287
+ * link carrying `@db.rel.FK`, therefore keeps its value help instead of losing
288
+ * the dictionary.
289
+ *
290
+ * This mirrors what the server already does on the `/meta` path: since
291
+ * `@atscript/db` 0.1.128 the serialized meta collapses such chains onto the
292
+ * terminal field (`ref` → terminal, `db.rel.FK: true`), so a form def built
293
+ * from `/meta` and one built from the compiled `.as` type land on the same
294
+ * dictionary.
295
+ *
296
+ * The walk is bounded ({@link MAX_REF_CHAIN_DEPTH}), which is also what makes a
297
+ * cyclic chain terminate (it runs out of hops and gives up instead of looping).
298
+ * It stops as soon as a link has no `.ref`, or the referenced
299
+ * field cannot be found — e.g. behind a shallow `{ id, metadata }` ref target
300
+ * from `/meta`, which carries no props (and needs none: the server already
301
+ * resolved the chain).
274
302
  */
275
303
  function extractValueHelp(prop) {
276
- if (!prop.metadata.has("db.rel.FK")) return void 0;
277
- if (!prop.ref) return void 0;
278
- const target = prop.ref.type();
279
- if (!target) return void 0;
280
- const url = target.metadata.get(DB_HTTP_PATH);
281
- if (!url) return void 0;
282
- return {
283
- url,
284
- targetField: prop.ref.field
285
- };
304
+ let node = prop;
305
+ for (let depth = 0; node && depth < MAX_REF_CHAIN_DEPTH; depth++) {
306
+ const ref = node.ref;
307
+ if (!ref) return void 0;
308
+ const target = ref.type();
309
+ if (!target) return void 0;
310
+ if (node.metadata.has("db.rel.FK")) {
311
+ const url = target.metadata.get(DB_HTTP_PATH);
312
+ if (url) return {
313
+ url,
314
+ targetField: ref.field
315
+ };
316
+ }
317
+ node = (target.type.kind === "object" ? target.type : void 0)?.props.get(ref.field);
318
+ }
286
319
  }
287
320
  //#endregion
288
321
  //#region src/form/create-form-def.ts
@@ -328,11 +361,7 @@ function createFormDef(type, opts) {
328
361
  if (isChildOfStructured(path, structuredPrefixes)) continue;
329
362
  const originalProp = resolveOriginalProp(objectType, path) ?? prop;
330
363
  const kind = originalProp.type.kind;
331
- if (kind === "object") {
332
- const hasLabel = getFieldMeta(originalProp, META_LABEL) !== void 0;
333
- const hasComponent = getFieldMeta(originalProp, UI_FORM_COMPONENT) !== void 0;
334
- if (!hasLabel && !hasComponent) continue;
335
- }
364
+ if (kind === "object" && !isStructuredObject(originalProp)) continue;
336
365
  if (kind === "array") {
337
366
  if (originalProp.type.of.type.kind === "array" && !getFieldMeta(originalProp, "ui.form.component")) continue;
338
367
  }
@@ -374,13 +403,15 @@ function createFieldDef(path, prop) {
374
403
  const allStatic = !hasComputedAnnotations(prop);
375
404
  const uiType = getFieldMeta(prop, "ui.form.type") ?? getFieldMeta(prop, "ui.type");
376
405
  const pushDown = getFieldMeta(prop, UI_FORM_PUSH_DOWN) !== void 0;
406
+ const valueHelpInfo = extractValueHelp(prop);
377
407
  const base = {
378
408
  path,
379
409
  prop,
380
410
  phantom: false,
381
411
  name,
382
412
  allStatic,
383
- pushDown
413
+ pushDown,
414
+ valueHelpInfo
384
415
  };
385
416
  const customType = uiType;
386
417
  if (kind === "array") {
@@ -440,7 +471,7 @@ function createFieldDef(path, prop) {
440
471
  })
441
472
  };
442
473
  }
443
- if (extractValueHelp(prop)) return {
474
+ if (valueHelpInfo) return {
444
475
  ...base,
445
476
  type: uiType ?? "ref"
446
477
  };
@@ -472,6 +503,49 @@ function createFieldDef(path, prop) {
472
503
  phantom: kind === "" && dt === "phantom"
473
504
  };
474
505
  }
506
+ /** Non-`ui.form.*` keys that still address the object itself. */
507
+ const OBJECT_IDENTITY_KEYS = new Set([
508
+ META_LABEL,
509
+ META_DESCRIPTION,
510
+ UI_TYPE
511
+ ]);
512
+ const UI_FORM_NS = "ui.form.";
513
+ /** `ui.form.*` keys that place a field rather than give it an identity. */
514
+ const UI_FORM_PLACEMENT_NS = "ui.form.grid.";
515
+ /**
516
+ * Whether an object prop renders as a field of its own rather than being
517
+ * flattened into its parent.
518
+ *
519
+ * Any `@ui.form.*` annotation (plus `@meta.label` / `@meta.description` /
520
+ * `@ui.type`) means the author addressed the object itself, so it needs a
521
+ * field to carry that instruction to a renderer — a collapsible section, or
522
+ * whatever `@ui.form.component` / `@ui.form.type` names. An object with none
523
+ * of them is a pure namespace: it is dropped and its children render inline
524
+ * in the parent grid, which keeps DB-flattened structs (`addr.street` stored
525
+ * as `addr__street`) from growing chrome nobody asked for. `@db.*`,
526
+ * `@expect.*` and the rest of `@meta.*` stay out for exactly that reason —
527
+ * they are what such a struct carries.
528
+ *
529
+ * Placement keys (`@ui.form.order`, `@ui.form.grid.*`) are excluded: they
530
+ * position a field among its siblings, and a namespace has no position of its
531
+ * own — its children carry their own.
532
+ *
533
+ * A prefix rule rather than a list because the list was wrong the moment it
534
+ * was written. Matching on `@meta.label` and `@ui.form.component` alone left
535
+ * every other key to be read off a prop that never became a field: a
536
+ * `@meta.description` went missing, a `@ui.form.type` component silently
537
+ * never mounted, `@ui.form.pushDown` never pushed down, and — the one that
538
+ * mattered — `@ui.form.hidden` on a struct left every child on screen.
539
+ */
540
+ function isStructuredObject(prop) {
541
+ for (const key of prop.metadata.keys()) {
542
+ if (OBJECT_IDENTITY_KEYS.has(key)) return true;
543
+ if (!key.startsWith(UI_FORM_NS)) continue;
544
+ if (key === "ui.form.order" || key.startsWith(UI_FORM_PLACEMENT_NS)) continue;
545
+ return true;
546
+ }
547
+ return false;
548
+ }
475
549
  /** Resolves the original annotated type from the type hierarchy by path. */
476
550
  function resolveOriginalProp(type, path) {
477
551
  const parts = path.split(".");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/ui",
3
- "version": "0.1.133",
3
+ "version": "0.1.135",
4
4
  "description": "Framework-agnostic runtime for form and table definitions from atscript annotated types",
5
5
  "keywords": [
6
6
  "annotations",