@atscript/ui 0.1.146 → 0.1.147

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
@@ -336,7 +336,8 @@ const UI_TAGS = new Set([
336
336
  * - **Non-object types** (primitive, array, union, etc.): produces a single leaf root field
337
337
  * with `path: ''`.
338
338
  *
339
- * A `@db.column.derived` field is marked `derived` straight from its metadata.
339
+ * A `@db.column.derived` field is marked `derived` straight from its metadata;
340
+ * a computed view column, from `opts.metaFields`.
340
341
  */
341
342
  function createFormDef(type, opts) {
342
343
  if (type.type.kind !== "object") {
@@ -366,7 +367,9 @@ function createFormDef(type, opts) {
366
367
  if (originalProp.type.of.type.kind === "array" && !getFieldMeta(originalProp, "ui.form.component")) continue;
367
368
  }
368
369
  if (kind === "array" || kind === "object" || kind === "union" || kind === "tuple") structuredPrefixes.add(path + ".");
369
- fields.push(createFieldDef(path, originalProp));
370
+ const field = createFieldDef(path, originalProp);
371
+ if (opts?.metaFields?.[path]?.computed) field.derived = true;
372
+ fields.push(field);
370
373
  }
371
374
  const orderMap = new Map(fields.map((f) => [f, getFieldMeta(f.prop, "ui.form.order") ?? Infinity]));
372
375
  fields.sort((a, b) => orderMap.get(a) - orderMap.get(b));
@@ -2326,13 +2329,15 @@ function createTableDef(meta, preDeserializedType) {
2326
2329
  columns.sort((a, b) => a.order - b.order);
2327
2330
  const actions = groupActions(meta.actions ?? []);
2328
2331
  const crud = meta.crud ?? {};
2332
+ const preferredId = meta.preferredId ?? meta.primaryKeys;
2329
2333
  return {
2330
2334
  type,
2331
2335
  columns,
2332
2336
  flatMap,
2333
2337
  fetchableFields: new Set(Object.keys(meta.fields).filter((p) => isReadable(meta.fields[p]))),
2334
2338
  primaryKeys: meta.primaryKeys,
2335
- preferredId: meta.preferredId ?? meta.primaryKeys,
2339
+ preferredId,
2340
+ identifierFields: identifierFieldsOf(preferredId, meta.actions ?? []),
2336
2341
  versionColumn: meta.versionColumn,
2337
2342
  crud,
2338
2343
  canRemove: "remove" in crud,
@@ -2343,6 +2348,21 @@ function createTableDef(meta, preDeserializedType) {
2343
2348
  relations: meta.relations
2344
2349
  };
2345
2350
  }
2351
+ /**
2352
+ * `preferredId` ∪ every delegated action's `idMap` paths, in that order —
2353
+ * the same array when no action carries an `idMap`.
2354
+ */
2355
+ function identifierFieldsOf(preferredId, actions) {
2356
+ let out;
2357
+ for (const a of actions) {
2358
+ if (!a.idMap) continue;
2359
+ for (const path of Object.values(a.idMap)) {
2360
+ if (preferredId.includes(path) || out?.includes(path)) continue;
2361
+ (out ??= [...preferredId]).push(path);
2362
+ }
2363
+ }
2364
+ return out ?? preferredId;
2365
+ }
2346
2366
  /** A field the caller may read: listed in `meta.fields` and not write-only. */
2347
2367
  function isReadable(field) {
2348
2368
  return field !== void 0 && field.writeOnly !== true;
@@ -2429,11 +2449,26 @@ function getColumn(def, path) {
2429
2449
  *
2430
2450
  * Table/rows-level navigate actions carry no `$1` placeholder and return
2431
2451
  * `action.value` verbatim.
2452
+ *
2453
+ * A delegated action (`action.idMap`, since 0.1.147) reads `id` as one of THIS
2454
+ * table's rows (or identifiers) and encodes the owner's identification it maps
2455
+ * to, in `Object.keys(idMap)` order — the same as `Client`. A row the map
2456
+ * cannot address (a missing path) has no link.
2432
2457
  */
2433
2458
  function navigateHrefFor(action, id, preferredId) {
2434
2459
  if (action.processor !== "navigate") return void 0;
2435
2460
  if (action.level !== "row") return action.value;
2436
- if (id === void 0 || preferredId.length === 0) return void 0;
2461
+ if (id === void 0) return void 0;
2462
+ if (action.idMap) {
2463
+ let mapped;
2464
+ try {
2465
+ mapped = (0, _atscript_db_client.actionIdentifier)(action, id, []);
2466
+ } catch {
2467
+ return;
2468
+ }
2469
+ return action.value.replace(/\$1/g, (0, _atscript_db_client.encodeNavigateId)(mapped, Object.keys(action.idMap)));
2470
+ }
2471
+ if (preferredId.length === 0) return void 0;
2437
2472
  return action.value.replace(/\$1/g, (0, _atscript_db_client.encodeNavigateId)(id, preferredId));
2438
2473
  }
2439
2474
  //#endregion
package/dist/index.d.cts CHANGED
@@ -241,6 +241,16 @@ interface CreateFormDefOptions {
241
241
  * Root-table concept; not propagated into nested recursive calls.
242
242
  */
243
243
  versionColumn?: string;
244
+ /**
245
+ * `meta.fields` of the `/meta` the type came from. A field it marks
246
+ * `computed` (a computed view column, whose `@db.compute` annotation the
247
+ * server does not send) is marked `derived` like a `@db.column.derived`
248
+ * one: read-only, never validated, never sent. Root-table concept; not
249
+ * propagated into nested recursive calls. Since 0.1.147.
250
+ */
251
+ metaFields?: Record<string, {
252
+ computed?: boolean;
253
+ }>;
244
254
  }
245
255
  /**
246
256
  * Converts an ATScript annotated type into a FormDef.
@@ -249,7 +259,8 @@ interface CreateFormDefOptions {
249
259
  * - **Non-object types** (primitive, array, union, etc.): produces a single leaf root field
250
260
  * with `path: ''`.
251
261
  *
252
- * A `@db.column.derived` field is marked `derived` straight from its metadata.
262
+ * A `@db.column.derived` field is marked `derived` straight from its metadata;
263
+ * a computed view column, from `opts.metaFields`.
253
264
  */
254
265
  declare function createFormDef(type: TAtscriptAnnotatedType, opts?: CreateFormDefOptions): FormDef;
255
266
  /**
@@ -1029,6 +1040,14 @@ interface RelationInfo {
1029
1040
  name: string;
1030
1041
  direction: "to" | "from" | "via";
1031
1042
  isArray: boolean;
1043
+ /**
1044
+ * `true` when the relation is `@db.rel.filterable`: the server accepts
1045
+ * filters by related rows on it (`ticket: { $some: {…} }` /
1046
+ * `{ $none: {…} }`, URL `ticket=$some(status=open)`). Absent otherwise.
1047
+ * Tables display such predicates (residual filters) but offer no UI to
1048
+ * author them. Needs `@atscript/moost-db` 0.1.147+. Since 0.1.147.
1049
+ */
1050
+ filterable?: boolean;
1032
1051
  }
1033
1052
  /** Per-field capability flags. */
1034
1053
  interface FieldMeta {
@@ -1055,6 +1074,14 @@ interface FieldMeta {
1055
1074
  * Since 0.1.144.
1056
1075
  */
1057
1076
  derived?: boolean;
1077
+ /**
1078
+ * A computed view column (`@db.compute`, `@atscript/db` 0.1.147+): the
1079
+ * database evaluates it from other fields of the view. It is a column like
1080
+ * any other — sorting and filtering follow `sortable` / `filterable` —
1081
+ * but never writable: `createFormDef` marks it `derived` when given these
1082
+ * fields (`CreateFormDefOptions.metaFields`). Since 0.1.147.
1083
+ */
1084
+ computed?: boolean;
1058
1085
  }
1059
1086
  /** Meta response from moost-db `/meta` endpoint. */
1060
1087
  interface MetaResponse {
@@ -1120,6 +1147,17 @@ interface TableDef {
1120
1147
  primaryKeys: string[];
1121
1148
  /** Preferred row identifier — see `MetaResponse.preferredId`. */
1122
1149
  preferredId: string[];
1150
+ /**
1151
+ * The row fields an action identifier is built from: `preferredId` plus
1152
+ * every path a delegated action's `idMap` reads (an action another
1153
+ * controller owns, e.g. a view listing its source table's actions). The
1154
+ * table keeps these values on every identifier it hands to an action, so
1155
+ * the client can map them to the owner's identification. Equals
1156
+ * `preferredId` when no action carries an `idMap`. Always set by
1157
+ * `createTableDef`; a hand-built `TableDef` may omit it (consumers fall back
1158
+ * to `preferredId`). Since 0.1.147.
1159
+ */
1160
+ identifierFields?: string[];
1123
1161
  /** Server-managed OCC column name — see `MetaResponse.versionColumn`. */
1124
1162
  versionColumn?: string;
1125
1163
  /** Per-op CRUD permissions advertised in `/meta`. Key absent → denied. */
@@ -1310,6 +1348,11 @@ declare function getColumn(def: TableDef, path: string): ColumnDef | undefined;
1310
1348
  *
1311
1349
  * Table/rows-level navigate actions carry no `$1` placeholder and return
1312
1350
  * `action.value` verbatim.
1351
+ *
1352
+ * A delegated action (`action.idMap`, since 0.1.147) reads `id` as one of THIS
1353
+ * table's rows (or identifiers) and encodes the owner's identification it maps
1354
+ * to, in `Object.keys(idMap)` order — the same as `Client`. A row the map
1355
+ * cannot address (a missing path) has no link.
1313
1356
  */
1314
1357
  declare function navigateHrefFor(action: TDbActionInfo$1, id: Record<string, unknown> | undefined, preferredId: readonly string[]): string | undefined;
1315
1358
  //#endregion
package/dist/index.d.mts CHANGED
@@ -241,6 +241,16 @@ interface CreateFormDefOptions {
241
241
  * Root-table concept; not propagated into nested recursive calls.
242
242
  */
243
243
  versionColumn?: string;
244
+ /**
245
+ * `meta.fields` of the `/meta` the type came from. A field it marks
246
+ * `computed` (a computed view column, whose `@db.compute` annotation the
247
+ * server does not send) is marked `derived` like a `@db.column.derived`
248
+ * one: read-only, never validated, never sent. Root-table concept; not
249
+ * propagated into nested recursive calls. Since 0.1.147.
250
+ */
251
+ metaFields?: Record<string, {
252
+ computed?: boolean;
253
+ }>;
244
254
  }
245
255
  /**
246
256
  * Converts an ATScript annotated type into a FormDef.
@@ -249,7 +259,8 @@ interface CreateFormDefOptions {
249
259
  * - **Non-object types** (primitive, array, union, etc.): produces a single leaf root field
250
260
  * with `path: ''`.
251
261
  *
252
- * A `@db.column.derived` field is marked `derived` straight from its metadata.
262
+ * A `@db.column.derived` field is marked `derived` straight from its metadata;
263
+ * a computed view column, from `opts.metaFields`.
253
264
  */
254
265
  declare function createFormDef(type: TAtscriptAnnotatedType, opts?: CreateFormDefOptions): FormDef;
255
266
  /**
@@ -1029,6 +1040,14 @@ interface RelationInfo {
1029
1040
  name: string;
1030
1041
  direction: "to" | "from" | "via";
1031
1042
  isArray: boolean;
1043
+ /**
1044
+ * `true` when the relation is `@db.rel.filterable`: the server accepts
1045
+ * filters by related rows on it (`ticket: { $some: {…} }` /
1046
+ * `{ $none: {…} }`, URL `ticket=$some(status=open)`). Absent otherwise.
1047
+ * Tables display such predicates (residual filters) but offer no UI to
1048
+ * author them. Needs `@atscript/moost-db` 0.1.147+. Since 0.1.147.
1049
+ */
1050
+ filterable?: boolean;
1032
1051
  }
1033
1052
  /** Per-field capability flags. */
1034
1053
  interface FieldMeta {
@@ -1055,6 +1074,14 @@ interface FieldMeta {
1055
1074
  * Since 0.1.144.
1056
1075
  */
1057
1076
  derived?: boolean;
1077
+ /**
1078
+ * A computed view column (`@db.compute`, `@atscript/db` 0.1.147+): the
1079
+ * database evaluates it from other fields of the view. It is a column like
1080
+ * any other — sorting and filtering follow `sortable` / `filterable` —
1081
+ * but never writable: `createFormDef` marks it `derived` when given these
1082
+ * fields (`CreateFormDefOptions.metaFields`). Since 0.1.147.
1083
+ */
1084
+ computed?: boolean;
1058
1085
  }
1059
1086
  /** Meta response from moost-db `/meta` endpoint. */
1060
1087
  interface MetaResponse {
@@ -1120,6 +1147,17 @@ interface TableDef {
1120
1147
  primaryKeys: string[];
1121
1148
  /** Preferred row identifier — see `MetaResponse.preferredId`. */
1122
1149
  preferredId: string[];
1150
+ /**
1151
+ * The row fields an action identifier is built from: `preferredId` plus
1152
+ * every path a delegated action's `idMap` reads (an action another
1153
+ * controller owns, e.g. a view listing its source table's actions). The
1154
+ * table keeps these values on every identifier it hands to an action, so
1155
+ * the client can map them to the owner's identification. Equals
1156
+ * `preferredId` when no action carries an `idMap`. Always set by
1157
+ * `createTableDef`; a hand-built `TableDef` may omit it (consumers fall back
1158
+ * to `preferredId`). Since 0.1.147.
1159
+ */
1160
+ identifierFields?: string[];
1123
1161
  /** Server-managed OCC column name — see `MetaResponse.versionColumn`. */
1124
1162
  versionColumn?: string;
1125
1163
  /** Per-op CRUD permissions advertised in `/meta`. Key absent → denied. */
@@ -1310,6 +1348,11 @@ declare function getColumn(def: TableDef, path: string): ColumnDef | undefined;
1310
1348
  *
1311
1349
  * Table/rows-level navigate actions carry no `$1` placeholder and return
1312
1350
  * `action.value` verbatim.
1351
+ *
1352
+ * A delegated action (`action.idMap`, since 0.1.147) reads `id` as one of THIS
1353
+ * table's rows (or identifiers) and encodes the owner's identification it maps
1354
+ * to, in `Object.keys(idMap)` order — the same as `Client`. A row the map
1355
+ * cannot address (a missing path) has no link.
1313
1356
  */
1314
1357
  declare function navigateHrefFor(action: TDbActionInfo$1, id: Record<string, unknown> | undefined, preferredId: readonly string[]): string | undefined;
1315
1358
  //#endregion
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Validator, createDataFromAnnotatedType, deserializeAnnotatedType, detectDiscriminator, flattenAnnotatedType } from "@atscript/typescript/utils";
2
- import { Client, encodeNavigateId } from "@atscript/db-client";
2
+ import { Client, actionIdentifier, encodeNavigateId } from "@atscript/db-client";
3
3
  import { createDbValidatorPlugin } from "@atscript/db/validator";
4
4
  //#region src/shared/annotation-keys.ts
5
5
  const UI_TYPE = "ui.type";
@@ -335,7 +335,8 @@ const UI_TAGS = new Set([
335
335
  * - **Non-object types** (primitive, array, union, etc.): produces a single leaf root field
336
336
  * with `path: ''`.
337
337
  *
338
- * A `@db.column.derived` field is marked `derived` straight from its metadata.
338
+ * A `@db.column.derived` field is marked `derived` straight from its metadata;
339
+ * a computed view column, from `opts.metaFields`.
339
340
  */
340
341
  function createFormDef(type, opts) {
341
342
  if (type.type.kind !== "object") {
@@ -365,7 +366,9 @@ function createFormDef(type, opts) {
365
366
  if (originalProp.type.of.type.kind === "array" && !getFieldMeta(originalProp, "ui.form.component")) continue;
366
367
  }
367
368
  if (kind === "array" || kind === "object" || kind === "union" || kind === "tuple") structuredPrefixes.add(path + ".");
368
- fields.push(createFieldDef(path, originalProp));
369
+ const field = createFieldDef(path, originalProp);
370
+ if (opts?.metaFields?.[path]?.computed) field.derived = true;
371
+ fields.push(field);
369
372
  }
370
373
  const orderMap = new Map(fields.map((f) => [f, getFieldMeta(f.prop, "ui.form.order") ?? Infinity]));
371
374
  fields.sort((a, b) => orderMap.get(a) - orderMap.get(b));
@@ -2325,13 +2328,15 @@ function createTableDef(meta, preDeserializedType) {
2325
2328
  columns.sort((a, b) => a.order - b.order);
2326
2329
  const actions = groupActions(meta.actions ?? []);
2327
2330
  const crud = meta.crud ?? {};
2331
+ const preferredId = meta.preferredId ?? meta.primaryKeys;
2328
2332
  return {
2329
2333
  type,
2330
2334
  columns,
2331
2335
  flatMap,
2332
2336
  fetchableFields: new Set(Object.keys(meta.fields).filter((p) => isReadable(meta.fields[p]))),
2333
2337
  primaryKeys: meta.primaryKeys,
2334
- preferredId: meta.preferredId ?? meta.primaryKeys,
2338
+ preferredId,
2339
+ identifierFields: identifierFieldsOf(preferredId, meta.actions ?? []),
2335
2340
  versionColumn: meta.versionColumn,
2336
2341
  crud,
2337
2342
  canRemove: "remove" in crud,
@@ -2342,6 +2347,21 @@ function createTableDef(meta, preDeserializedType) {
2342
2347
  relations: meta.relations
2343
2348
  };
2344
2349
  }
2350
+ /**
2351
+ * `preferredId` ∪ every delegated action's `idMap` paths, in that order —
2352
+ * the same array when no action carries an `idMap`.
2353
+ */
2354
+ function identifierFieldsOf(preferredId, actions) {
2355
+ let out;
2356
+ for (const a of actions) {
2357
+ if (!a.idMap) continue;
2358
+ for (const path of Object.values(a.idMap)) {
2359
+ if (preferredId.includes(path) || out?.includes(path)) continue;
2360
+ (out ??= [...preferredId]).push(path);
2361
+ }
2362
+ }
2363
+ return out ?? preferredId;
2364
+ }
2345
2365
  /** A field the caller may read: listed in `meta.fields` and not write-only. */
2346
2366
  function isReadable(field) {
2347
2367
  return field !== void 0 && field.writeOnly !== true;
@@ -2428,11 +2448,26 @@ function getColumn(def, path) {
2428
2448
  *
2429
2449
  * Table/rows-level navigate actions carry no `$1` placeholder and return
2430
2450
  * `action.value` verbatim.
2451
+ *
2452
+ * A delegated action (`action.idMap`, since 0.1.147) reads `id` as one of THIS
2453
+ * table's rows (or identifiers) and encodes the owner's identification it maps
2454
+ * to, in `Object.keys(idMap)` order — the same as `Client`. A row the map
2455
+ * cannot address (a missing path) has no link.
2431
2456
  */
2432
2457
  function navigateHrefFor(action, id, preferredId) {
2433
2458
  if (action.processor !== "navigate") return void 0;
2434
2459
  if (action.level !== "row") return action.value;
2435
- if (id === void 0 || preferredId.length === 0) return void 0;
2460
+ if (id === void 0) return void 0;
2461
+ if (action.idMap) {
2462
+ let mapped;
2463
+ try {
2464
+ mapped = actionIdentifier(action, id, []);
2465
+ } catch {
2466
+ return;
2467
+ }
2468
+ return action.value.replace(/\$1/g, encodeNavigateId(mapped, Object.keys(action.idMap)));
2469
+ }
2470
+ if (preferredId.length === 0) return void 0;
2436
2471
  return action.value.replace(/\$1/g, encodeNavigateId(id, preferredId));
2437
2472
  }
2438
2473
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/ui",
3
- "version": "0.1.146",
3
+ "version": "0.1.147",
4
4
  "description": "Framework-agnostic runtime for form and table definitions from atscript annotated types",
5
5
  "keywords": [
6
6
  "annotations",
@@ -47,19 +47,20 @@
47
47
  "access": "public"
48
48
  },
49
49
  "dependencies": {
50
- "@atscript/db-client": "^0.1.146"
50
+ "@atscript/db-client": "^0.1.147"
51
51
  },
52
52
  "devDependencies": {
53
- "@atscript/core": "^0.1.98",
54
- "@atscript/db": "^0.1.146",
55
- "@atscript/typescript": "^0.1.98",
56
- "unplugin-atscript": "^0.1.98",
53
+ "@atscript/core": "^0.1.99",
54
+ "@atscript/db": "^0.1.147",
55
+ "@atscript/typescript": "^0.1.99",
56
+ "@uniqu/core": "^0.1.12",
57
+ "unplugin-atscript": "^0.1.99",
57
58
  "vitest": "npm:@voidzero-dev/vite-plus-test@0.1.14"
58
59
  },
59
60
  "peerDependencies": {
60
- "@atscript/core": "^0.1.98",
61
- "@atscript/db": "^0.1.146",
62
- "@atscript/typescript": "^0.1.98"
61
+ "@atscript/core": "^0.1.99",
62
+ "@atscript/db": "^0.1.147",
63
+ "@atscript/typescript": "^0.1.99"
63
64
  },
64
65
  "scripts": {
65
66
  "build": "vp pack",