@atscript/ui 0.1.204 → 0.1.206

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.
Files changed (61) hide show
  1. package/dist/form/create-form-def.cjs +72 -83
  2. package/dist/form/create-form-def.d.cts +32 -22
  3. package/dist/form/create-form-def.d.mts +32 -22
  4. package/dist/form/create-form-def.mjs +73 -84
  5. package/dist/form/db-column.cjs +37 -0
  6. package/dist/form/db-column.mjs +35 -0
  7. package/dist/form/decimal-format.cjs +9 -11
  8. package/dist/form/decimal-format.mjs +9 -11
  9. package/dist/form/diff.cjs +32 -14
  10. package/dist/form/diff.d.cts +7 -4
  11. package/dist/form/diff.d.mts +7 -4
  12. package/dist/form/diff.mjs +32 -14
  13. package/dist/form/loaded-empty.cjs +56 -0
  14. package/dist/form/loaded-empty.d.cts +25 -0
  15. package/dist/form/loaded-empty.d.mts +25 -0
  16. package/dist/form/loaded-empty.mjs +56 -0
  17. package/dist/form/omit-derived.cjs +38 -0
  18. package/dist/form/omit-derived.d.cts +17 -0
  19. package/dist/form/omit-derived.d.mts +17 -0
  20. package/dist/form/omit-derived.mjs +38 -0
  21. package/dist/form/optional-mode.cjs +85 -0
  22. package/dist/form/optional-mode.d.cts +58 -0
  23. package/dist/form/optional-mode.d.mts +58 -0
  24. package/dist/form/optional-mode.mjs +82 -0
  25. package/dist/form/path-utils.cjs +14 -10
  26. package/dist/form/path-utils.mjs +14 -10
  27. package/dist/form/types.d.cts +16 -16
  28. package/dist/form/types.d.mts +16 -16
  29. package/dist/form/validate.cjs +2 -2
  30. package/dist/form/validate.mjs +2 -2
  31. package/dist/index.cjs +23 -4
  32. package/dist/index.d.cts +7 -3
  33. package/dist/index.d.mts +7 -3
  34. package/dist/index.mjs +10 -6
  35. package/dist/plugin/annotations.cjs +12 -0
  36. package/dist/plugin/annotations.mjs +13 -1
  37. package/dist/plugin/value-help-validation.cjs +25 -1
  38. package/dist/plugin/value-help-validation.mjs +25 -2
  39. package/dist/shared/annotation-keys.cjs +3 -0
  40. package/dist/shared/annotation-keys.d.cts +3 -1
  41. package/dist/shared/annotation-keys.d.mts +3 -1
  42. package/dist/shared/annotation-keys.mjs +3 -1
  43. package/dist/shared/exact-number.cjs +12 -0
  44. package/dist/shared/exact-number.mjs +12 -0
  45. package/dist/shared/meta-cache.cjs +1 -1
  46. package/dist/shared/meta-cache.mjs +1 -1
  47. package/dist/table/create-table-def.cjs +4 -1
  48. package/dist/table/create-table-def.mjs +4 -2
  49. package/dist/table/types.d.cts +23 -16
  50. package/dist/table/types.d.mts +23 -16
  51. package/dist/table/value-kind.cjs +37 -2
  52. package/dist/table/value-kind.d.cts +22 -2
  53. package/dist/table/value-kind.d.mts +22 -2
  54. package/dist/table/value-kind.mjs +36 -3
  55. package/dist/value-help/distinct-client.cjs +5 -4
  56. package/dist/value-help/distinct-client.d.cts +8 -2
  57. package/dist/value-help/distinct-client.d.mts +8 -2
  58. package/dist/value-help/distinct-client.mjs +5 -4
  59. package/dist/value-help/value-help-client.cjs +45 -9
  60. package/dist/value-help/value-help-client.mjs +45 -9
  61. package/package.json +11 -12
@@ -4,6 +4,7 @@ const require_field_resolver = require("../shared/field-resolver.cjs");
4
4
  const require_messages = require("../messages.cjs");
5
5
  const require_extract_literals = require("../value-help/extract-literals.cjs");
6
6
  const require_extract_ref = require("../value-help/extract-ref.cjs");
7
+ const require_db_column = require("./db-column.cjs");
7
8
  const require_skipped_nav = require("./skipped-nav.cjs");
8
9
  let _atscript_typescript_utils = require("@atscript/typescript/utils");
9
10
  let _atscript_db_meta = require("@atscript/db/meta");
@@ -24,7 +25,7 @@ const UI_TAGS = new Set([
24
25
  * an endless expansion: a tree's `children` items are the same def at every
25
26
  * depth, built once. A field def is reused only at the same path relative to
26
27
  * its object def, so a reused field always sits where it was built. Both are
27
- * per mode (`edit`), which shapes the defs.
28
+ * per {@link TWrite}, which shapes the defs.
28
29
  */
29
30
  const defsInProgress = [];
30
31
  const fieldsInProgress = [];
@@ -51,13 +52,14 @@ function unnamed(field) {
51
52
  *
52
53
  * A server-computed field — `@db.column.derived`, a computed view column
53
54
  * (`@db.compute`) or a host-computed one (`@db.compute.host`) — is marked
54
- * `derived` straight from its metadata; a served field the server owns, from
55
- * `opts.metaFields`; an update-stamped field (see `CreateFormDefOptions.mode`),
56
- * when `opts.mode` is `"edit"`. Over a compiled `@db.view.writable` view type,
57
- * a field the view declares itself (a join column, a computed field) is
58
- * `derived` as well — its controller drops it from every write — unless the
59
- * form writes it (a pick's fill target, a `@ui.form.fn.value` or
60
- * `@ui.form.fn.readonly` field). Since 0.1.204.
55
+ * `derived` straight from its metadata; a served field `/meta` marks
56
+ * `readOnly`, from `opts.metaFields`; an update-stamped field (see
57
+ * `CreateFormDefOptions.mode`), when `opts.mode` is `"edit"`. Over a compiled
58
+ * `@db.view.writable` view type, a field the view declares itself (a join
59
+ * column, a computed field) is `derived` as well — its controller drops it
60
+ * from every write. A `readOnly` or own field the form writes stays an
61
+ * ordinary one (a pick's fill target, a `@ui.form.fn.value` or
62
+ * `@ui.form.fn.readonly` field). Since 0.1.204; `readOnly` since 0.1.205.
61
63
  *
62
64
  * A navigation field (`@db.rel.from` / `.to` / `.via` / `.store`) is left out unless it
63
65
  * carries a `@ui.form.*` annotation of its own (see {@link isSkippedNavField}).
@@ -68,17 +70,19 @@ function unnamed(field) {
68
70
  * becomes a nested object field, since inlining it would never end.
69
71
  */
70
72
  function createFormDef(type, opts) {
71
- const def = buildFormDef(type, opts?.mode === "edit", opts ?? {});
73
+ const write = opts?.mode === "edit" ? "edit" : "create";
74
+ const def = buildFormDef(type, write, opts ?? {});
72
75
  if (require_model_texts.isServedType(type)) def.served = true;
76
+ if (write === "edit") def.edit = true;
73
77
  return def;
74
78
  }
75
79
  /**
76
80
  * The def of an object (or a leaf) type. `root`: the caller's options, for the
77
81
  * form's own type only — nested objects get none of the root-table ones.
78
82
  */
79
- function buildFormDef(type, edit, root) {
83
+ function buildFormDef(type, write, root) {
80
84
  if (type.type.kind !== "object") {
81
- const rootField = createFieldDef("", type, edit);
85
+ const rootField = createFieldDef("", type, write);
82
86
  const fields = [rootField];
83
87
  return {
84
88
  type,
@@ -90,14 +94,14 @@ function buildFormDef(type, edit, root) {
90
94
  };
91
95
  }
92
96
  if (!root) {
93
- const reached = defsInProgress.find((e) => e.type === type && e.edit === edit);
97
+ const reached = defsInProgress.find((e) => e.type === type && e.write === write);
94
98
  if (reached) return reached.def;
95
99
  }
96
100
  const objectType = type;
97
101
  const flatMap = (0, _atscript_typescript_utils.flattenAnnotatedType)(objectType, { excludePhantomTypes: false });
98
102
  const opts = root && {
99
103
  ...root,
100
- versionColumn: root.versionColumn ?? (edit ? findVersionColumn(flatMap) : void 0)
104
+ versionColumn: root.versionColumn ?? (write === "edit" ? findVersionColumn(flatMap) : void 0)
101
105
  };
102
106
  const fields = [];
103
107
  const rootField = {
@@ -121,11 +125,11 @@ function buildFormDef(type, edit, root) {
121
125
  let collected;
122
126
  if (!root) defsInProgress.push({
123
127
  type,
124
- edit,
128
+ write,
125
129
  def
126
130
  });
127
131
  try {
128
- collected = collectFields(objectType, flatMap, edit, opts);
132
+ collected = collectFields(objectType, flatMap, write, opts);
129
133
  } finally {
130
134
  if (!root) defsInProgress.pop();
131
135
  }
@@ -138,7 +142,7 @@ function buildFormDef(type, edit, root) {
138
142
  return def;
139
143
  }
140
144
  /** Builds the top-level fields of an object def from its flattened props, unsorted. */
141
- function collectFields(objectType, flatMap, edit, opts) {
145
+ function collectFields(objectType, flatMap, write, opts) {
142
146
  const fields = [];
143
147
  const structuredPrefixes = /* @__PURE__ */ new Set();
144
148
  for (const [path, prop] of flatMap.entries()) {
@@ -156,7 +160,7 @@ function collectFields(objectType, flatMap, edit, opts) {
156
160
  if (originalProp.type.of.type.kind === "array" && !require_field_resolver.getFieldMeta(originalProp, "ui.form.component")) continue;
157
161
  }
158
162
  if (kind === "array" || kind === "object" || kind === "union" || kind === "tuple") structuredPrefixes.add(path + ".");
159
- const field = createFieldDef(path, originalProp, edit);
163
+ const field = createFieldDef(path, originalProp, write);
160
164
  if (require_extract_ref.isValueHelpPicker(originalProp)) field.picker = true;
161
165
  fields.push({
162
166
  field,
@@ -170,16 +174,12 @@ function collectFields(objectType, flatMap, edit, opts) {
170
174
  }
171
175
  /**
172
176
  * Marks `derived` the fields the server owns although their own metadata does
173
- * not say so: a column `metaFields` flags `computed`; unless the form writes
174
- * it, a field a compiled `@db.view.writable` view declares itself
175
- * (`writableViewReadOnlyFields`, with the leaves of one rendered inline); and,
176
- * with `servedReadonly` (still diffed), a top-level served `@meta.readonly`
177
- * field the form never writes (a view's own fields are top-level; see
178
- * `CreateFormDefOptions.metaFields`). The type's knowledge wins over that
179
- * ambiguous served marker. Root def only: only the root form is written
180
- * through the view's controller, and `metaFields` keys are root paths. The
181
- * def gets a copy: a recursive type's field defs may be shared with nested
182
- * defs.
177
+ * not say so — unless the form writes them ({@link writtenByForm}): a field
178
+ * `/meta` marks `readOnly` (`metaFields`; see {@link servedReadOnly}), and a field a compiled
179
+ * `@db.view.writable` view declares itself (`writableViewReadOnlyFields`, with
180
+ * the leaves of one rendered inline). Root def only: only the root form is
181
+ * written through the endpoint, and `metaFields` keys are root paths. The def
182
+ * gets a copy: a recursive type's field defs may be shared with nested defs.
183
183
  */
184
184
  function markServerOwned(fields, type, metaFields) {
185
185
  const own = (0, _atscript_db_meta.writableViewReadOnlyFields)(type);
@@ -190,28 +190,33 @@ function markServerOwned(fields, type, metaFields) {
190
190
  for (const f of field.valueHelpInfo?.fill ?? []) filled.add(parent + f.local);
191
191
  }
192
192
  for (const c of fields) {
193
- const { path, prop, derived } = c.field;
194
- if (derived) continue;
195
- if (metaFields?.[path]?.computed) {
196
- c.field = {
197
- ...c.field,
198
- derived: true
199
- };
200
- continue;
201
- }
202
- if (writtenByForm(c.field, filled)) continue;
203
- if (own.has(path.split(".", 1)[0])) c.field = {
193
+ const { path, derived } = c.field;
194
+ if (derived || writtenByForm(c.field, filled)) continue;
195
+ const head = path.split(".", 1)[0];
196
+ if (own.has(head) || metaFields && (servedReadOnly(metaFields, path) || head !== path && servedReadOnly(metaFields, head))) c.field = {
204
197
  ...c.field,
205
198
  derived: true
206
199
  };
207
- else if (metaFields && !path.includes(".") && require_field_resolver.getFieldMeta(prop, "meta.readonly") !== void 0) c.field = {
208
- ...c.field,
209
- derived: true,
210
- servedReadonly: true
211
- };
212
200
  }
213
201
  }
214
202
  /**
203
+ * Whether `/meta` marks `path` read-only: its own entry, or — an object field
204
+ * (`/meta` lists the leaves only) — every leaf under it. Every leaf, not one: a
205
+ * permission layer may mark a single leaf read-only.
206
+ */
207
+ function servedReadOnly(metaFields, path) {
208
+ const entry = metaFields[path];
209
+ if (entry) return entry.readOnly === true;
210
+ const prefix = `${path}.`;
211
+ let leaves = 0;
212
+ for (const key in metaFields) {
213
+ if (!key.startsWith(prefix)) continue;
214
+ if (!metaFields[key]?.readOnly) return false;
215
+ leaves++;
216
+ }
217
+ return leaves > 0;
218
+ }
219
+ /**
215
220
  * A server-owned field the form writes all the same: a pick fills it, a
216
221
  * `@ui.form.fn.value` computes it, or a `@ui.form.fn.readonly` can make it
217
222
  * editable.
@@ -261,36 +266,37 @@ function keepWritableFills(fields) {
261
266
  }
262
267
  }
263
268
  /**
264
- * Creates a FormFieldDef from any ATScript annotated type. `edit`: the form
265
- * edits a stored row (`CreateFormDefOptions.mode`).
269
+ * Creates a FormFieldDef from any ATScript annotated type. `write`: how the
270
+ * server writes it ({@link TWrite}, from `CreateFormDefOptions.mode`).
266
271
  *
267
272
  * An array, union or tuple reached again at the same path inside its own
268
273
  * build (an array item, a union variant or a tuple item of a recursive alias)
269
274
  * gets the field def under construction. Every other recursion passes an
270
275
  * object def, which `defsInProgress` catches, so the build always ends.
271
276
  */
272
- function createFieldDef(path, prop, edit) {
277
+ function createFieldDef(path, prop, write) {
273
278
  const kind = prop.type.kind;
274
- if (kind === "" || kind === "object") return buildFieldDef(path, prop, edit);
275
- const reached = fieldsInProgress.find((e) => e.prop === prop && e.path === path && e.edit === edit);
279
+ if (kind === "" || kind === "object") return buildFieldDef(path, prop, write);
280
+ const reached = fieldsInProgress.find((e) => e.prop === prop && e.path === path && e.write === write);
276
281
  if (reached) return reached.field;
277
282
  const building = {
278
283
  prop,
279
284
  path,
280
- edit,
285
+ write,
281
286
  field: {},
282
287
  copies: []
283
288
  };
284
289
  fieldsInProgress.push(building);
285
290
  try {
286
- const field = Object.assign(building.field, buildFieldDef(path, prop, edit));
291
+ const field = Object.assign(building.field, buildFieldDef(path, prop, write));
287
292
  for (const copy of building.copies) Object.assign(copy, field, { name: "" });
288
293
  return field;
289
294
  } finally {
290
295
  fieldsInProgress.pop();
291
296
  }
292
297
  }
293
- function buildFieldDef(path, prop, edit) {
298
+ function buildFieldDef(path, typeProp, write) {
299
+ const prop = write === "create" && path !== "" && !typeProp.optional && require_db_column.isDbDefaulted(typeProp) ? Object.create(typeProp, { optional: { value: true } }) : typeProp;
294
300
  const kind = prop.type.kind;
295
301
  const name = path.slice(path.lastIndexOf(".") + 1);
296
302
  const allStatic = !require_field_resolver.hasComputedAnnotations(prop);
@@ -298,7 +304,7 @@ function buildFieldDef(path, prop, edit) {
298
304
  const uiType = declaredType === "tags" && kind !== "array" ? void 0 : declaredType;
299
305
  const pushDown = require_field_resolver.getFieldMeta(prop, require_annotation_keys.UI_FORM_PUSH_DOWN) !== void 0;
300
306
  const valueHelpInfo = require_extract_ref.extractValueHelp(prop);
301
- const derived = isServerComputed(prop) || edit && path !== "" && isUpdateStamped(prop);
307
+ const derived = isServerComputed(prop) || write === "edit" && path !== "" && isUpdateStamped(prop);
302
308
  const base = {
303
309
  path,
304
310
  prop,
@@ -320,21 +326,21 @@ function buildFieldDef(path, prop, edit) {
320
326
  type: "array",
321
327
  customType: isTags ? "tags" : isMultiselect ? "multiselect" : customType,
322
328
  itemType: arrayType.of,
323
- itemField: labelledBy(createFieldDef("", arrayType.of, edit), prop)
329
+ itemField: labelledBy(createFieldDef("", arrayType.of, write), prop)
324
330
  };
325
331
  }
326
332
  if (kind === "object") return {
327
333
  ...base,
328
334
  type: "object",
329
335
  customType,
330
- objectDef: buildFormDef(prop, edit)
336
+ objectDef: buildFormDef(prop, write)
331
337
  };
332
338
  if (kind === "union") {
333
339
  if (require_extract_literals.isPureLiteralUnion(prop)) return {
334
340
  ...base,
335
341
  type: uiType ?? "select"
336
342
  };
337
- const unionVariants = createUnionVariants(prop, edit && soleValueMember(prop) !== void 0);
343
+ const unionVariants = createUnionVariants(prop, require_db_column.soleValueMember(prop) === void 0 ? void 0 : write);
338
344
  if (unionVariants.length > 1) return {
339
345
  ...base,
340
346
  type: "union",
@@ -363,7 +369,7 @@ function buildFieldDef(path, prop, edit) {
363
369
  ...base,
364
370
  type: "tuple",
365
371
  customType,
366
- itemFields: tupleType.items.map((item, i) => unnamed(createFieldDef(String(i), item, false)))
372
+ itemFields: tupleType.items.map((item, i) => unnamed(createFieldDef(String(i), item, void 0)))
367
373
  };
368
374
  }
369
375
  if (valueHelpInfo) return {
@@ -473,7 +479,7 @@ function isChildOfStructured(path, prefixes) {
473
479
  * Iterates top-level items directly — one variant per item.
474
480
  */
475
481
  function buildUnionVariants(typeDef) {
476
- return createUnionVariants(typeDef, false);
482
+ return createUnionVariants(typeDef, void 0);
477
483
  }
478
484
  /**
479
485
  * A scalar field inside `outer` (an array item, a union variant) also takes `outer`'s
@@ -483,11 +489,11 @@ function labelledBy(field, outer) {
483
489
  if (field.prop?.type.kind === "" && outer.metadata.has("ui.literalLabel")) field.labelsFrom = outer;
484
490
  return field;
485
491
  }
486
- function createUnionVariants(typeDef, edit) {
492
+ function createUnionVariants(typeDef, write) {
487
493
  const items = typeDef.type.items ?? [typeDef];
488
494
  const variants = [];
489
495
  for (const item of items) {
490
- const v = createVariant(item, edit);
496
+ const v = createVariant(item, write);
491
497
  if (v.itemField) labelledBy(v.itemField, typeDef);
492
498
  if (items.length > 1) v.label = `${String(variants.length + 1)}. ${v.label}`;
493
499
  variants.push(v);
@@ -495,7 +501,7 @@ function createUnionVariants(typeDef, edit) {
495
501
  return variants;
496
502
  }
497
503
  /** Creates a single union variant from an annotated type item. */
498
- function createVariant(def, edit) {
504
+ function createVariant(def, write) {
499
505
  const kind = def.type.kind;
500
506
  if (kind === "object") {
501
507
  const label = require_field_resolver.getFieldMeta(def, require_annotation_keys.META_LABEL);
@@ -506,8 +512,8 @@ function createVariant(def, edit) {
506
512
  labelText: label
507
513
  },
508
514
  type: def,
509
- def: buildFormDef(def, edit),
510
- itemField: hasComponent ? createFieldDef("", def, edit) : void 0
515
+ def: buildFormDef(def, write),
516
+ itemField: hasComponent ? createFieldDef("", def, write) : void 0
511
517
  };
512
518
  }
513
519
  if (kind === "") {
@@ -515,14 +521,14 @@ function createVariant(def, edit) {
515
521
  return {
516
522
  ...typeLabel(dt === "phantom" ? "item" : dt),
517
523
  type: def,
518
- itemField: createFieldDef("", def, edit),
524
+ itemField: createFieldDef("", def, write),
519
525
  designType: dt
520
526
  };
521
527
  }
522
528
  return {
523
529
  ...typeLabel(kind),
524
530
  type: def,
525
- itemField: createFieldDef("", def, edit)
531
+ itemField: createFieldDef("", def, write)
526
532
  };
527
533
  }
528
534
  /**
@@ -535,26 +541,9 @@ function isServerComputed(prop) {
535
541
  const meta = prop.metadata;
536
542
  return meta.has("db.column.derived") || meta.has("db.compute") || meta.has("db.compute.host");
537
543
  }
538
- /**
539
- * An update-stamped field (see `CreateFormDefOptions.mode`). Read off the prop,
540
- * or — as `@atscript/db` does — off the one value member of `T | null`, unless
541
- * the prop references another field.
542
- */
544
+ /** An update-stamped field (see `CreateFormDefOptions.mode`), read as {@link columnHas} reads it. */
543
545
  function isUpdateStamped(prop) {
544
- if ((0, _atscript_db_validator.isServerStampedOnUpdate)(prop.metadata)) return true;
545
- const member = prop.ref?.field ? void 0 : soleValueMember(prop);
546
- return member !== void 0 && (0, _atscript_db_validator.isServerStampedOnUpdate)(member.metadata);
547
- }
548
- /** The one non-`null` / `undefined` member of a (nested) union, if there is exactly one. */
549
- function soleValueMember(prop) {
550
- if (prop.type.kind !== "union") return void 0;
551
- const members = /* @__PURE__ */ new Set();
552
- const visit = (t) => {
553
- if (t.type.kind === "union") for (const item of t.type.items) visit(item);
554
- else if (!require_extract_literals.isEmptyMember(t)) members.add(t);
555
- };
556
- visit(prop);
557
- return members.size === 1 ? members.values().next().value : void 0;
546
+ return require_db_column.columnHas(prop, _atscript_db_validator.isServerStampedOnUpdate);
558
547
  }
559
548
  function capitalize(s) {
560
549
  return s.charAt(0).toUpperCase() + s.slice(1);
@@ -14,23 +14,19 @@ interface CreateFormDefOptions {
14
14
  versionColumn?: string;
15
15
  /**
16
16
  * `meta.fields` of the `/meta` the type came from — pass it for a form over
17
- * a served type. Marks `derived` (read-only, never validated, never
18
- * required, never sent) a field it flags `computed` (a server before
19
- * `@atscript/db` 0.1.205 leaves `@db.compute` out of the type). A top-level
20
- * `@meta.readonly` field the form never writes — the marker a
21
- * `@db.view.writable` view's own fields (join columns, aliases) are served
22
- * with — becomes `derived` with `servedReadonly`: read-only, never
23
- * validated, never required, but a changed value is still sent (the client
24
- * can't tell a view's own field from a table's read-only one; the view's
25
- * controller drops its own keys from a write). A read-only field the form
26
- * writes stays an ordinary one: one a pick fills (`@ui.valueHelp.fill`), one
27
- * `@ui.form.fn.value` computes, and one `@ui.form.fn.readonly` can make
28
- * editable. Root-table concept; not propagated into nested recursive calls.
29
- * Since 0.1.147; `@meta.readonly` since 0.1.203 (`@atscript/db` 0.1.205
30
- * serves it).
17
+ * a served type. A field it marks `readOnly` (`@atscript/db` ≥ 0.1.209: a
18
+ * field not in the endpoint's write model — derived, computed, a writable
19
+ * view's own field, or one a permission overlay marks) is `derived`:
20
+ * read-only, never validated, never required, never sent. A read-only field
21
+ * the form writes itself stays an ordinary one — one a pick fills
22
+ * (`@ui.valueHelp.fill`), one `@ui.form.fn.value` computes, one
23
+ * `@ui.form.fn.readonly` can make editable: it is sent, and the server drops
24
+ * the key. Root-table concept; not propagated into nested recursive calls.
25
+ * Since 0.1.147; `readOnly` since 0.1.205 (before, the `computed` flag and a
26
+ * served `@meta.readonly`).
31
27
  */
32
28
  metaFields?: Record<string, {
33
- computed?: boolean;
29
+ readOnly?: boolean;
34
30
  }>;
35
31
  /**
36
32
  * What the form is for. `"edit"` — the form edits a stored row and is sent
@@ -45,6 +41,19 @@ interface CreateFormDefOptions {
45
41
  * server only fills it when the value is left out and it has
46
42
  * `@db.default.now`, or is an `@db.onUpdate.inc` counter (`0`). Since
47
43
  * 0.1.154; `@db.onUpdate.inc` since 0.1.159.
44
+ *
45
+ * `"create"` makes a field the database fills when an insert leaves it out
46
+ * — a `@db.default*`, the fields `@atscript/db` makes optional on insert —
47
+ * an optional one: its def's `prop` is a view of the type's prop with
48
+ * `optional: true`, so it is offered, emptied and validated as an optional
49
+ * field, and a create leaves it out when empty. At the same places as the
50
+ * update stamps: any depth, but not a reference to another field, an array
51
+ * element, or below a tuple or a union of several types (the database fills
52
+ * none there). Since 0.1.206.
53
+ *
54
+ * `"edit"` also sets `FormDef.edit`: an emptied optional field then holds
55
+ * its empty value (`""`, `null` or `false`; business mode, see
56
+ * `emptiedValue`), so a whole-record update clears it too. Since 0.1.205.
48
57
  */
49
58
  mode?: "create" | "edit";
50
59
  }
@@ -57,13 +66,14 @@ interface CreateFormDefOptions {
57
66
  *
58
67
  * A server-computed field — `@db.column.derived`, a computed view column
59
68
  * (`@db.compute`) or a host-computed one (`@db.compute.host`) — is marked
60
- * `derived` straight from its metadata; a served field the server owns, from
61
- * `opts.metaFields`; an update-stamped field (see `CreateFormDefOptions.mode`),
62
- * when `opts.mode` is `"edit"`. Over a compiled `@db.view.writable` view type,
63
- * a field the view declares itself (a join column, a computed field) is
64
- * `derived` as well — its controller drops it from every write — unless the
65
- * form writes it (a pick's fill target, a `@ui.form.fn.value` or
66
- * `@ui.form.fn.readonly` field). Since 0.1.204.
69
+ * `derived` straight from its metadata; a served field `/meta` marks
70
+ * `readOnly`, from `opts.metaFields`; an update-stamped field (see
71
+ * `CreateFormDefOptions.mode`), when `opts.mode` is `"edit"`. Over a compiled
72
+ * `@db.view.writable` view type, a field the view declares itself (a join
73
+ * column, a computed field) is `derived` as well — its controller drops it
74
+ * from every write. A `readOnly` or own field the form writes stays an
75
+ * ordinary one (a pick's fill target, a `@ui.form.fn.value` or
76
+ * `@ui.form.fn.readonly` field). Since 0.1.204; `readOnly` since 0.1.205.
67
77
  *
68
78
  * A navigation field (`@db.rel.from` / `.to` / `.via` / `.store`) is left out unless it
69
79
  * carries a `@ui.form.*` annotation of its own (see {@link isSkippedNavField}).
@@ -14,23 +14,19 @@ interface CreateFormDefOptions {
14
14
  versionColumn?: string;
15
15
  /**
16
16
  * `meta.fields` of the `/meta` the type came from — pass it for a form over
17
- * a served type. Marks `derived` (read-only, never validated, never
18
- * required, never sent) a field it flags `computed` (a server before
19
- * `@atscript/db` 0.1.205 leaves `@db.compute` out of the type). A top-level
20
- * `@meta.readonly` field the form never writes — the marker a
21
- * `@db.view.writable` view's own fields (join columns, aliases) are served
22
- * with — becomes `derived` with `servedReadonly`: read-only, never
23
- * validated, never required, but a changed value is still sent (the client
24
- * can't tell a view's own field from a table's read-only one; the view's
25
- * controller drops its own keys from a write). A read-only field the form
26
- * writes stays an ordinary one: one a pick fills (`@ui.valueHelp.fill`), one
27
- * `@ui.form.fn.value` computes, and one `@ui.form.fn.readonly` can make
28
- * editable. Root-table concept; not propagated into nested recursive calls.
29
- * Since 0.1.147; `@meta.readonly` since 0.1.203 (`@atscript/db` 0.1.205
30
- * serves it).
17
+ * a served type. A field it marks `readOnly` (`@atscript/db` ≥ 0.1.209: a
18
+ * field not in the endpoint's write model — derived, computed, a writable
19
+ * view's own field, or one a permission overlay marks) is `derived`:
20
+ * read-only, never validated, never required, never sent. A read-only field
21
+ * the form writes itself stays an ordinary one — one a pick fills
22
+ * (`@ui.valueHelp.fill`), one `@ui.form.fn.value` computes, one
23
+ * `@ui.form.fn.readonly` can make editable: it is sent, and the server drops
24
+ * the key. Root-table concept; not propagated into nested recursive calls.
25
+ * Since 0.1.147; `readOnly` since 0.1.205 (before, the `computed` flag and a
26
+ * served `@meta.readonly`).
31
27
  */
32
28
  metaFields?: Record<string, {
33
- computed?: boolean;
29
+ readOnly?: boolean;
34
30
  }>;
35
31
  /**
36
32
  * What the form is for. `"edit"` — the form edits a stored row and is sent
@@ -45,6 +41,19 @@ interface CreateFormDefOptions {
45
41
  * server only fills it when the value is left out and it has
46
42
  * `@db.default.now`, or is an `@db.onUpdate.inc` counter (`0`). Since
47
43
  * 0.1.154; `@db.onUpdate.inc` since 0.1.159.
44
+ *
45
+ * `"create"` makes a field the database fills when an insert leaves it out
46
+ * — a `@db.default*`, the fields `@atscript/db` makes optional on insert —
47
+ * an optional one: its def's `prop` is a view of the type's prop with
48
+ * `optional: true`, so it is offered, emptied and validated as an optional
49
+ * field, and a create leaves it out when empty. At the same places as the
50
+ * update stamps: any depth, but not a reference to another field, an array
51
+ * element, or below a tuple or a union of several types (the database fills
52
+ * none there). Since 0.1.206.
53
+ *
54
+ * `"edit"` also sets `FormDef.edit`: an emptied optional field then holds
55
+ * its empty value (`""`, `null` or `false`; business mode, see
56
+ * `emptiedValue`), so a whole-record update clears it too. Since 0.1.205.
48
57
  */
49
58
  mode?: "create" | "edit";
50
59
  }
@@ -57,13 +66,14 @@ interface CreateFormDefOptions {
57
66
  *
58
67
  * A server-computed field — `@db.column.derived`, a computed view column
59
68
  * (`@db.compute`) or a host-computed one (`@db.compute.host`) — is marked
60
- * `derived` straight from its metadata; a served field the server owns, from
61
- * `opts.metaFields`; an update-stamped field (see `CreateFormDefOptions.mode`),
62
- * when `opts.mode` is `"edit"`. Over a compiled `@db.view.writable` view type,
63
- * a field the view declares itself (a join column, a computed field) is
64
- * `derived` as well — its controller drops it from every write — unless the
65
- * form writes it (a pick's fill target, a `@ui.form.fn.value` or
66
- * `@ui.form.fn.readonly` field). Since 0.1.204.
69
+ * `derived` straight from its metadata; a served field `/meta` marks
70
+ * `readOnly`, from `opts.metaFields`; an update-stamped field (see
71
+ * `CreateFormDefOptions.mode`), when `opts.mode` is `"edit"`. Over a compiled
72
+ * `@db.view.writable` view type, a field the view declares itself (a join
73
+ * column, a computed field) is `derived` as well — its controller drops it
74
+ * from every write. A `readOnly` or own field the form writes stays an
75
+ * ordinary one (a pick's fill target, a `@ui.form.fn.value` or
76
+ * `@ui.form.fn.readonly` field). Since 0.1.204; `readOnly` since 0.1.205.
67
77
  *
68
78
  * A navigation field (`@db.rel.from` / `.to` / `.via` / `.store`) is left out unless it
69
79
  * carries a `@ui.form.*` annotation of its own (see {@link isSkippedNavField}).