@atscript/ui 0.1.133 → 0.1.134

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
@@ -375,13 +408,15 @@ function createFieldDef(path, prop) {
375
408
  const allStatic = !hasComputedAnnotations(prop);
376
409
  const uiType = getFieldMeta(prop, "ui.form.type") ?? getFieldMeta(prop, "ui.type");
377
410
  const pushDown = getFieldMeta(prop, UI_FORM_PUSH_DOWN) !== void 0;
411
+ const valueHelpInfo = extractValueHelp(prop);
378
412
  const base = {
379
413
  path,
380
414
  prop,
381
415
  phantom: false,
382
416
  name,
383
417
  allStatic,
384
- pushDown
418
+ pushDown,
419
+ valueHelpInfo
385
420
  };
386
421
  const customType = uiType;
387
422
  if (kind === "array") {
@@ -441,7 +476,7 @@ function createFieldDef(path, prop) {
441
476
  })
442
477
  };
443
478
  }
444
- if (extractValueHelp(prop)) return {
479
+ if (valueHelpInfo) return {
445
480
  ...base,
446
481
  type: uiType ?? "ref"
447
482
  };
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
@@ -374,13 +407,15 @@ function createFieldDef(path, prop) {
374
407
  const allStatic = !hasComputedAnnotations(prop);
375
408
  const uiType = getFieldMeta(prop, "ui.form.type") ?? getFieldMeta(prop, "ui.type");
376
409
  const pushDown = getFieldMeta(prop, UI_FORM_PUSH_DOWN) !== void 0;
410
+ const valueHelpInfo = extractValueHelp(prop);
377
411
  const base = {
378
412
  path,
379
413
  prop,
380
414
  phantom: false,
381
415
  name,
382
416
  allStatic,
383
- pushDown
417
+ pushDown,
418
+ valueHelpInfo
384
419
  };
385
420
  const customType = uiType;
386
421
  if (kind === "array") {
@@ -440,7 +475,7 @@ function createFieldDef(path, prop) {
440
475
  })
441
476
  };
442
477
  }
443
- if (extractValueHelp(prop)) return {
478
+ if (valueHelpInfo) return {
444
479
  ...base,
445
480
  type: uiType ?? "ref"
446
481
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/ui",
3
- "version": "0.1.133",
3
+ "version": "0.1.134",
4
4
  "description": "Framework-agnostic runtime for form and table definitions from atscript annotated types",
5
5
  "keywords": [
6
6
  "annotations",