@atscript/ui 0.1.204 → 0.1.205

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 (59) hide show
  1. package/dist/form/create-form-def.cjs +38 -34
  2. package/dist/form/create-form-def.d.cts +23 -22
  3. package/dist/form/create-form-def.d.mts +23 -22
  4. package/dist/form/create-form-def.mjs +38 -34
  5. package/dist/form/decimal-format.cjs +9 -11
  6. package/dist/form/decimal-format.mjs +9 -11
  7. package/dist/form/diff.cjs +32 -14
  8. package/dist/form/diff.d.cts +7 -4
  9. package/dist/form/diff.d.mts +7 -4
  10. package/dist/form/diff.mjs +32 -14
  11. package/dist/form/loaded-empty.cjs +56 -0
  12. package/dist/form/loaded-empty.d.cts +25 -0
  13. package/dist/form/loaded-empty.d.mts +25 -0
  14. package/dist/form/loaded-empty.mjs +56 -0
  15. package/dist/form/omit-derived.cjs +38 -0
  16. package/dist/form/omit-derived.d.cts +17 -0
  17. package/dist/form/omit-derived.d.mts +17 -0
  18. package/dist/form/omit-derived.mjs +38 -0
  19. package/dist/form/optional-mode.cjs +85 -0
  20. package/dist/form/optional-mode.d.cts +58 -0
  21. package/dist/form/optional-mode.d.mts +58 -0
  22. package/dist/form/optional-mode.mjs +82 -0
  23. package/dist/form/path-utils.cjs +4 -5
  24. package/dist/form/path-utils.mjs +4 -5
  25. package/dist/form/types.d.cts +15 -16
  26. package/dist/form/types.d.mts +15 -16
  27. package/dist/form/validate.cjs +2 -2
  28. package/dist/form/validate.mjs +2 -2
  29. package/dist/index.cjs +23 -4
  30. package/dist/index.d.cts +7 -3
  31. package/dist/index.d.mts +7 -3
  32. package/dist/index.mjs +10 -6
  33. package/dist/plugin/annotations.cjs +12 -0
  34. package/dist/plugin/annotations.mjs +13 -1
  35. package/dist/plugin/value-help-validation.cjs +25 -1
  36. package/dist/plugin/value-help-validation.mjs +25 -2
  37. package/dist/shared/annotation-keys.cjs +3 -0
  38. package/dist/shared/annotation-keys.d.cts +3 -1
  39. package/dist/shared/annotation-keys.d.mts +3 -1
  40. package/dist/shared/annotation-keys.mjs +3 -1
  41. package/dist/shared/exact-number.cjs +12 -0
  42. package/dist/shared/exact-number.mjs +12 -0
  43. package/dist/shared/meta-cache.cjs +1 -1
  44. package/dist/shared/meta-cache.mjs +1 -1
  45. package/dist/table/create-table-def.cjs +4 -1
  46. package/dist/table/create-table-def.mjs +4 -2
  47. package/dist/table/types.d.cts +23 -16
  48. package/dist/table/types.d.mts +23 -16
  49. package/dist/table/value-kind.cjs +37 -2
  50. package/dist/table/value-kind.d.cts +22 -2
  51. package/dist/table/value-kind.d.mts +22 -2
  52. package/dist/table/value-kind.mjs +36 -3
  53. package/dist/value-help/distinct-client.cjs +5 -4
  54. package/dist/value-help/distinct-client.d.cts +8 -2
  55. package/dist/value-help/distinct-client.d.mts +8 -2
  56. package/dist/value-help/distinct-client.mjs +5 -4
  57. package/dist/value-help/value-help-client.cjs +45 -9
  58. package/dist/value-help/value-help-client.mjs +45 -9
  59. package/package.json +11 -12
@@ -51,13 +51,14 @@ function unnamed(field) {
51
51
  *
52
52
  * A server-computed field — `@db.column.derived`, a computed view column
53
53
  * (`@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.
54
+ * `derived` straight from its metadata; a served field `/meta` marks
55
+ * `readOnly`, from `opts.metaFields`; an update-stamped field (see
56
+ * `CreateFormDefOptions.mode`), when `opts.mode` is `"edit"`. Over a compiled
57
+ * `@db.view.writable` view type, a field the view declares itself (a join
58
+ * column, a computed field) is `derived` as well — its controller drops it
59
+ * from every write. A `readOnly` or own field the form writes stays an
60
+ * ordinary one (a pick's fill target, a `@ui.form.fn.value` or
61
+ * `@ui.form.fn.readonly` field). Since 0.1.204; `readOnly` since 0.1.205.
61
62
  *
62
63
  * A navigation field (`@db.rel.from` / `.to` / `.via` / `.store`) is left out unless it
63
64
  * carries a `@ui.form.*` annotation of its own (see {@link isSkippedNavField}).
@@ -68,8 +69,10 @@ function unnamed(field) {
68
69
  * becomes a nested object field, since inlining it would never end.
69
70
  */
70
71
  function createFormDef(type, opts) {
71
- const def = buildFormDef(type, opts?.mode === "edit", opts ?? {});
72
+ const edit = opts?.mode === "edit";
73
+ const def = buildFormDef(type, edit, opts ?? {});
72
74
  if (require_model_texts.isServedType(type)) def.served = true;
75
+ if (edit) def.edit = true;
73
76
  return def;
74
77
  }
75
78
  /**
@@ -170,16 +173,12 @@ function collectFields(objectType, flatMap, edit, opts) {
170
173
  }
171
174
  /**
172
175
  * 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.
176
+ * not say so — unless the form writes them ({@link writtenByForm}): a field
177
+ * `/meta` marks `readOnly` (`metaFields`; see {@link servedReadOnly}), and a field a compiled
178
+ * `@db.view.writable` view declares itself (`writableViewReadOnlyFields`, with
179
+ * the leaves of one rendered inline). Root def only: only the root form is
180
+ * written through the endpoint, and `metaFields` keys are root paths. The def
181
+ * gets a copy: a recursive type's field defs may be shared with nested defs.
183
182
  */
184
183
  function markServerOwned(fields, type, metaFields) {
185
184
  const own = (0, _atscript_db_meta.writableViewReadOnlyFields)(type);
@@ -190,28 +189,33 @@ function markServerOwned(fields, type, metaFields) {
190
189
  for (const f of field.valueHelpInfo?.fill ?? []) filled.add(parent + f.local);
191
190
  }
192
191
  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 = {
192
+ const { path, derived } = c.field;
193
+ if (derived || writtenByForm(c.field, filled)) continue;
194
+ const head = path.split(".", 1)[0];
195
+ if (own.has(head) || metaFields && (servedReadOnly(metaFields, path) || head !== path && servedReadOnly(metaFields, head))) c.field = {
204
196
  ...c.field,
205
197
  derived: true
206
198
  };
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
199
  }
213
200
  }
214
201
  /**
202
+ * Whether `/meta` marks `path` read-only: its own entry, or — an object field
203
+ * (`/meta` lists the leaves only) — every leaf under it. Every leaf, not one: a
204
+ * permission layer may mark a single leaf read-only.
205
+ */
206
+ function servedReadOnly(metaFields, path) {
207
+ const entry = metaFields[path];
208
+ if (entry) return entry.readOnly === true;
209
+ const prefix = `${path}.`;
210
+ let leaves = 0;
211
+ for (const key in metaFields) {
212
+ if (!key.startsWith(prefix)) continue;
213
+ if (!metaFields[key]?.readOnly) return false;
214
+ leaves++;
215
+ }
216
+ return leaves > 0;
217
+ }
218
+ /**
215
219
  * A server-owned field the form writes all the same: a pick fills it, a
216
220
  * `@ui.form.fn.value` computes it, or a `@ui.form.fn.readonly` can make it
217
221
  * editable.
@@ -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,10 @@ 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
+ * `"edit"` also sets `FormDef.edit`: an emptied optional field then holds
46
+ * its empty value (`""`, `null` or `false`; business mode, see
47
+ * `emptiedValue`), so a whole-record update clears it too. Since 0.1.205.
48
48
  */
49
49
  mode?: "create" | "edit";
50
50
  }
@@ -57,13 +57,14 @@ interface CreateFormDefOptions {
57
57
  *
58
58
  * A server-computed field — `@db.column.derived`, a computed view column
59
59
  * (`@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.
60
+ * `derived` straight from its metadata; a served field `/meta` marks
61
+ * `readOnly`, from `opts.metaFields`; an update-stamped field (see
62
+ * `CreateFormDefOptions.mode`), when `opts.mode` is `"edit"`. Over a compiled
63
+ * `@db.view.writable` view type, a field the view declares itself (a join
64
+ * column, a computed field) is `derived` as well — its controller drops it
65
+ * from every write. A `readOnly` or own field the form writes stays an
66
+ * ordinary one (a pick's fill target, a `@ui.form.fn.value` or
67
+ * `@ui.form.fn.readonly` field). Since 0.1.204; `readOnly` since 0.1.205.
67
68
  *
68
69
  * A navigation field (`@db.rel.from` / `.to` / `.via` / `.store`) is left out unless it
69
70
  * 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,10 @@ 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
+ * `"edit"` also sets `FormDef.edit`: an emptied optional field then holds
46
+ * its empty value (`""`, `null` or `false`; business mode, see
47
+ * `emptiedValue`), so a whole-record update clears it too. Since 0.1.205.
48
48
  */
49
49
  mode?: "create" | "edit";
50
50
  }
@@ -57,13 +57,14 @@ interface CreateFormDefOptions {
57
57
  *
58
58
  * A server-computed field — `@db.column.derived`, a computed view column
59
59
  * (`@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.
60
+ * `derived` straight from its metadata; a served field `/meta` marks
61
+ * `readOnly`, from `opts.metaFields`; an update-stamped field (see
62
+ * `CreateFormDefOptions.mode`), when `opts.mode` is `"edit"`. Over a compiled
63
+ * `@db.view.writable` view type, a field the view declares itself (a join
64
+ * column, a computed field) is `derived` as well — its controller drops it
65
+ * from every write. A `readOnly` or own field the form writes stays an
66
+ * ordinary one (a pick's fill target, a `@ui.form.fn.value` or
67
+ * `@ui.form.fn.readonly` field). Since 0.1.204; `readOnly` since 0.1.205.
67
68
  *
68
69
  * A navigation field (`@db.rel.from` / `.to` / `.via` / `.store`) is left out unless it
69
70
  * carries a `@ui.form.*` annotation of its own (see {@link isSkippedNavField}).
@@ -51,13 +51,14 @@ function unnamed(field) {
51
51
  *
52
52
  * A server-computed field — `@db.column.derived`, a computed view column
53
53
  * (`@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.
54
+ * `derived` straight from its metadata; a served field `/meta` marks
55
+ * `readOnly`, from `opts.metaFields`; an update-stamped field (see
56
+ * `CreateFormDefOptions.mode`), when `opts.mode` is `"edit"`. Over a compiled
57
+ * `@db.view.writable` view type, a field the view declares itself (a join
58
+ * column, a computed field) is `derived` as well — its controller drops it
59
+ * from every write. A `readOnly` or own field the form writes stays an
60
+ * ordinary one (a pick's fill target, a `@ui.form.fn.value` or
61
+ * `@ui.form.fn.readonly` field). Since 0.1.204; `readOnly` since 0.1.205.
61
62
  *
62
63
  * A navigation field (`@db.rel.from` / `.to` / `.via` / `.store`) is left out unless it
63
64
  * carries a `@ui.form.*` annotation of its own (see {@link isSkippedNavField}).
@@ -68,8 +69,10 @@ function unnamed(field) {
68
69
  * becomes a nested object field, since inlining it would never end.
69
70
  */
70
71
  function createFormDef(type, opts) {
71
- const def = buildFormDef(type, opts?.mode === "edit", opts ?? {});
72
+ const edit = opts?.mode === "edit";
73
+ const def = buildFormDef(type, edit, opts ?? {});
72
74
  if (isServedType(type)) def.served = true;
75
+ if (edit) def.edit = true;
73
76
  return def;
74
77
  }
75
78
  /**
@@ -170,16 +173,12 @@ function collectFields(objectType, flatMap, edit, opts) {
170
173
  }
171
174
  /**
172
175
  * 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.
176
+ * not say so — unless the form writes them ({@link writtenByForm}): a field
177
+ * `/meta` marks `readOnly` (`metaFields`; see {@link servedReadOnly}), and a field a compiled
178
+ * `@db.view.writable` view declares itself (`writableViewReadOnlyFields`, with
179
+ * the leaves of one rendered inline). Root def only: only the root form is
180
+ * written through the endpoint, and `metaFields` keys are root paths. The def
181
+ * gets a copy: a recursive type's field defs may be shared with nested defs.
183
182
  */
184
183
  function markServerOwned(fields, type, metaFields) {
185
184
  const own = writableViewReadOnlyFields(type);
@@ -190,28 +189,33 @@ function markServerOwned(fields, type, metaFields) {
190
189
  for (const f of field.valueHelpInfo?.fill ?? []) filled.add(parent + f.local);
191
190
  }
192
191
  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 = {
192
+ const { path, derived } = c.field;
193
+ if (derived || writtenByForm(c.field, filled)) continue;
194
+ const head = path.split(".", 1)[0];
195
+ if (own.has(head) || metaFields && (servedReadOnly(metaFields, path) || head !== path && servedReadOnly(metaFields, head))) c.field = {
204
196
  ...c.field,
205
197
  derived: true
206
198
  };
207
- else if (metaFields && !path.includes(".") && getFieldMeta(prop, "meta.readonly") !== void 0) c.field = {
208
- ...c.field,
209
- derived: true,
210
- servedReadonly: true
211
- };
212
199
  }
213
200
  }
214
201
  /**
202
+ * Whether `/meta` marks `path` read-only: its own entry, or — an object field
203
+ * (`/meta` lists the leaves only) — every leaf under it. Every leaf, not one: a
204
+ * permission layer may mark a single leaf read-only.
205
+ */
206
+ function servedReadOnly(metaFields, path) {
207
+ const entry = metaFields[path];
208
+ if (entry) return entry.readOnly === true;
209
+ const prefix = `${path}.`;
210
+ let leaves = 0;
211
+ for (const key in metaFields) {
212
+ if (!key.startsWith(prefix)) continue;
213
+ if (!metaFields[key]?.readOnly) return false;
214
+ leaves++;
215
+ }
216
+ return leaves > 0;
217
+ }
218
+ /**
215
219
  * A server-owned field the form writes all the same: a pick fills it, a
216
220
  * `@ui.form.fn.value` computes it, or a `@ui.form.fn.readonly` can make it
217
221
  * editable.
@@ -267,24 +267,22 @@ function formatDecimalForDisplay(opts) {
267
267
  } else canonical = value;
268
268
  if (!/^[+-]?\d*(\.\d*)?$/.test(canonical) || canonical === "." || canonical === "-") return canonical;
269
269
  if (scale !== void 0 && scale >= 0) canonical = enforceScale(canonical, scale);
270
- const parts = splitDecimalString(canonical);
271
- const asNumber = Number(canonical);
272
- const intlSafe = Number.isFinite(asNumber);
273
270
  if (currency) {
274
- try {
275
- const fmt = getNumberFormat(locale, {
271
+ const parts = splitDecimalString(canonical);
272
+ const digits = scale ?? Math.min(Math.max(getCurrencyDecimals(currency, locale) ?? 0, parts.decimal.length), 100);
273
+ if (Number.isFinite(Number(canonical))) try {
274
+ return getNumberFormat(locale, {
276
275
  style: "currency",
277
276
  currency,
278
277
  currencyDisplay: "narrowSymbol",
279
- minimumFractionDigits: scale,
280
- maximumFractionDigits: scale,
278
+ minimumFractionDigits: digits,
279
+ maximumFractionDigits: digits,
281
280
  useGrouping
282
- });
283
- if (intlSafe) return fmt.format(asNumber);
281
+ }).format(canonical);
284
282
  } catch {}
285
- return `${currency} ${formatPlain(parts, scale, locale, useGrouping)}`;
283
+ return `${currency} ${formatPlain(parts, digits, locale, useGrouping)}`;
286
284
  }
287
- const base = formatPlain(parts, scale, locale, useGrouping);
285
+ const base = formatPlain(splitDecimalString(canonical), scale, locale, useGrouping);
288
286
  return unit ? `${base} ${unit}` : base;
289
287
  }
290
288
  function formatPlain(parts, scale, locale, useGrouping) {
@@ -267,24 +267,22 @@ function formatDecimalForDisplay(opts) {
267
267
  } else canonical = value;
268
268
  if (!/^[+-]?\d*(\.\d*)?$/.test(canonical) || canonical === "." || canonical === "-") return canonical;
269
269
  if (scale !== void 0 && scale >= 0) canonical = enforceScale(canonical, scale);
270
- const parts = splitDecimalString(canonical);
271
- const asNumber = Number(canonical);
272
- const intlSafe = Number.isFinite(asNumber);
273
270
  if (currency) {
274
- try {
275
- const fmt = getNumberFormat(locale, {
271
+ const parts = splitDecimalString(canonical);
272
+ const digits = scale ?? Math.min(Math.max(getCurrencyDecimals(currency, locale) ?? 0, parts.decimal.length), 100);
273
+ if (Number.isFinite(Number(canonical))) try {
274
+ return getNumberFormat(locale, {
276
275
  style: "currency",
277
276
  currency,
278
277
  currencyDisplay: "narrowSymbol",
279
- minimumFractionDigits: scale,
280
- maximumFractionDigits: scale,
278
+ minimumFractionDigits: digits,
279
+ maximumFractionDigits: digits,
281
280
  useGrouping
282
- });
283
- if (intlSafe) return fmt.format(asNumber);
281
+ }).format(canonical);
284
282
  } catch {}
285
- return `${currency} ${formatPlain(parts, scale, locale, useGrouping)}`;
283
+ return `${currency} ${formatPlain(parts, digits, locale, useGrouping)}`;
286
284
  }
287
- const base = formatPlain(parts, scale, locale, useGrouping);
285
+ const base = formatPlain(splitDecimalString(canonical), scale, locale, useGrouping);
288
286
  return unit ? `${base} ${unit}` : base;
289
287
  }
290
288
  function formatPlain(parts, scale, locale, useGrouping) {
@@ -15,7 +15,11 @@ let _atscript_db_validator = require("@atscript/db/validator");
15
15
  * (`{ value: domainData }`) so this reuses {@link getByPath}.
16
16
  *
17
17
  * Revert-aware: a value edited back to its baseline produces no change and no
18
- * patch entry.
18
+ * patch entry. A value stored unset (`null` / absent) that the form now holds
19
+ * as `""` is no change either, at any depth — a field typed into and emptied
20
+ * again, an optional text emptied on an edit form (since 0.1.205). The reverse
21
+ * is a change: a stored `""` that is now unset is sent as `null`. Emptying a
22
+ * stored value is a change to `""` / `null` / `false`.
19
23
  *
20
24
  * Snapshot contract: the result is NOT a deep copy. `$insert` items, `$replace`
21
25
  * arrays, scalar leaf values, and `changes[].before/after` all hold live
@@ -76,7 +80,7 @@ function isNavKey(def, key) {
76
80
  */
77
81
  function diffFields(fields, prefix, baseline, current, changes, patch, mergePaths, versionColumn) {
78
82
  for (const field of fields) {
79
- if (field.phantom || field.derived && !field.servedReadonly || versionColumn !== void 0 && !prefix && field.path === versionColumn) continue;
83
+ if (field.phantom || field.derived || versionColumn !== void 0 && !prefix && field.path === versionColumn) continue;
80
84
  const fullPath = prefix ? `${prefix}.${field.path}` : field.path;
81
85
  if (require_types.isArrayField(field)) {
82
86
  diffArrayField(field, fullPath, baseline, current, changes, patch, mergePaths);
@@ -111,7 +115,7 @@ function diffLeafRoot(def, baseline, current, changes, patch) {
111
115
  const field = def.rootField;
112
116
  const before = require_path_utils.getByPath(baseline, "");
113
117
  const after = require_path_utils.getByPath(current, "");
114
- if (deepEqual(before, after)) return;
118
+ if (sameStored(before, after)) return;
115
119
  const mergePaths = leafRootMergePaths(def.type);
116
120
  if (require_types.isArrayField(field)) {
117
121
  const arrayPatch = diffArray(field, before, after, mergePaths.has(LEAF_ROOT_KEY));
@@ -137,7 +141,7 @@ function diffLeafRoot(def, baseline, current, changes, patch) {
137
141
  function diffScalarField(field, fullPath, baseline, current, changes, patch, mergePaths) {
138
142
  const before = require_path_utils.getByPath(baseline, fullPath);
139
143
  const after = require_path_utils.getByPath(current, fullPath);
140
- if (deepEqual(before, after)) return;
144
+ if (sameStored(before, after)) return;
141
145
  changes.push({
142
146
  path: fullPath,
143
147
  kind: "set",
@@ -225,7 +229,7 @@ function diffObjectField(field, fullPath, baseline, current, changes, patch, mer
225
229
  function diffArrayField(field, fullPath, baseline, current, changes, patch, mergePaths) {
226
230
  const before = require_path_utils.getByPath(baseline, fullPath);
227
231
  const after = require_path_utils.getByPath(current, fullPath);
228
- if (deepEqual(before, after)) return;
232
+ if (sameStored(before, after)) return;
229
233
  const value = require_field_resolver.getFieldMeta(field.prop, "db.json") !== void 0 || require_field_resolver.getFieldMeta(field.prop, "db.encrypted") !== void 0 ? after ?? null : diffArray(field, before, after, mergePaths.has(fullPath));
230
234
  if (value === void 0) return;
231
235
  changes.push({
@@ -318,7 +322,7 @@ function diffKeyedArray(before, after, keyProps, merge) {
318
322
  continue;
319
323
  }
320
324
  if (afterKeys[kept++] !== k) return { $replace: after };
321
- if (deepEqual(prev, el)) continue;
325
+ if (sameStored(prev, el)) continue;
322
326
  const partial = buildKeyedUpdate(prev, el, keyProps);
323
327
  if (!partial) continue;
324
328
  if (incomplete(el)) return { $replace: after };
@@ -347,7 +351,7 @@ function buildKeyedUpdate(prev, next, keyProps) {
347
351
  if (keyProps.includes(k)) continue;
348
352
  const a = prev[k];
349
353
  const b = next[k];
350
- if (!deepEqual(a, b)) {
354
+ if (!sameStored(a, b)) {
351
355
  partial[k] = b === void 0 ? null : b;
352
356
  changed = true;
353
357
  }
@@ -487,13 +491,27 @@ function stableKey(v) {
487
491
  * unchanged. The patch cannot tell them apart either: it sends a cleared value
488
492
  * as `null`.
489
493
  *
490
- * The single comparator shared across the form engine: diff, conflict
491
- * detection ({@link buildFormRebase}), and apply all route through this — never
492
- * reimplement equality elsewhere.
494
+ * The single comparator shared across the form engine — the diff and conflict
495
+ * detection ({@link buildFormRebase}) — never reimplement equality elsewhere.
493
496
  */
494
497
  function deepEqual(a, b) {
498
+ return equal(a, b, false);
499
+ }
500
+ /**
501
+ * Whether the form's `after` leaves the stored `before` unchanged: {@link deepEqual},
502
+ * and a value stored unset (`null` / `undefined` / absent) that now holds `""` is
503
+ * unchanged too, at any depth — a field the user typed into and emptied again, an
504
+ * optional text emptied on an edit form (business mode), a field switched on and
505
+ * left empty. Asymmetric: a stored `""` that is now unset is a change. Since 0.1.205.
506
+ */
507
+ function sameStored(before, after) {
508
+ return equal(before, after, true);
509
+ }
510
+ /** {@link deepEqual}; with `emptyText`, also `b === ""` over an unset `a` ({@link sameStored}). */
511
+ function equal(a, b, emptyText) {
495
512
  if (a === b) return true;
496
- if (a === null || a === void 0 || b === null || b === void 0) return (a === null || a === void 0) && (b === null || b === void 0);
513
+ const aUnset = a === null || a === void 0;
514
+ if (aUnset || b === null || b === void 0) return aUnset && (b === null || b === void 0 || emptyText && b === "");
497
515
  if (typeof a === "number" && typeof b === "number") return Number.isNaN(a) && Number.isNaN(b);
498
516
  if (typeof a !== "object" || typeof b !== "object") return false;
499
517
  const aIsArr = Array.isArray(a);
@@ -501,13 +519,13 @@ function deepEqual(a, b) {
501
519
  if (aIsArr !== bIsArr) return false;
502
520
  if (aIsArr && bIsArr) {
503
521
  if (a.length !== b.length) return false;
504
- for (let i = 0; i < a.length; i++) if (!deepEqual(a[i], b[i])) return false;
522
+ for (let i = 0; i < a.length; i++) if (!equal(a[i], b[i], emptyText)) return false;
505
523
  return true;
506
524
  }
507
525
  const ao = a;
508
526
  const bo = b;
509
- for (const k of Object.keys(ao)) if (!deepEqual(ao[k], Object.hasOwn(bo, k) ? bo[k] : void 0)) return false;
510
- for (const k of Object.keys(bo)) if (!Object.hasOwn(ao, k) && bo[k] !== void 0 && bo[k] !== null) return false;
527
+ for (const k of Object.keys(ao)) if (!equal(ao[k], Object.hasOwn(bo, k) ? bo[k] : void 0, emptyText)) return false;
528
+ for (const k of Object.keys(bo)) if (!Object.hasOwn(ao, k) && !equal(void 0, bo[k], emptyText)) return false;
511
529
  return true;
512
530
  }
513
531
  //#endregion
@@ -60,7 +60,11 @@ interface FormDiffResult {
60
60
  * (`{ value: domainData }`) so this reuses {@link getByPath}.
61
61
  *
62
62
  * Revert-aware: a value edited back to its baseline produces no change and no
63
- * patch entry.
63
+ * patch entry. A value stored unset (`null` / absent) that the form now holds
64
+ * as `""` is no change either, at any depth — a field typed into and emptied
65
+ * again, an optional text emptied on an edit form (since 0.1.205). The reverse
66
+ * is a change: a stored `""` that is now unset is sent as `null`. Emptying a
67
+ * stored value is a change to `""` / `null` / `false`.
64
68
  *
65
69
  * Snapshot contract: the result is NOT a deep copy. `$insert` items, `$replace`
66
70
  * arrays, scalar leaf values, and `changes[].before/after` all hold live
@@ -80,9 +84,8 @@ declare function buildFormDiff(def: FormDef, baseline: Record<string, unknown>,
80
84
  * unchanged. The patch cannot tell them apart either: it sends a cleared value
81
85
  * as `null`.
82
86
  *
83
- * The single comparator shared across the form engine: diff, conflict
84
- * detection ({@link buildFormRebase}), and apply all route through this — never
85
- * reimplement equality elsewhere.
87
+ * The single comparator shared across the form engine — the diff and conflict
88
+ * detection ({@link buildFormRebase}) — never reimplement equality elsewhere.
86
89
  */
87
90
  declare function deepEqual(a: unknown, b: unknown): boolean;
88
91
  //#endregion
@@ -60,7 +60,11 @@ interface FormDiffResult {
60
60
  * (`{ value: domainData }`) so this reuses {@link getByPath}.
61
61
  *
62
62
  * Revert-aware: a value edited back to its baseline produces no change and no
63
- * patch entry.
63
+ * patch entry. A value stored unset (`null` / absent) that the form now holds
64
+ * as `""` is no change either, at any depth — a field typed into and emptied
65
+ * again, an optional text emptied on an edit form (since 0.1.205). The reverse
66
+ * is a change: a stored `""` that is now unset is sent as `null`. Emptying a
67
+ * stored value is a change to `""` / `null` / `false`.
64
68
  *
65
69
  * Snapshot contract: the result is NOT a deep copy. `$insert` items, `$replace`
66
70
  * arrays, scalar leaf values, and `changes[].before/after` all hold live
@@ -80,9 +84,8 @@ declare function buildFormDiff(def: FormDef, baseline: Record<string, unknown>,
80
84
  * unchanged. The patch cannot tell them apart either: it sends a cleared value
81
85
  * as `null`.
82
86
  *
83
- * The single comparator shared across the form engine: diff, conflict
84
- * detection ({@link buildFormRebase}), and apply all route through this — never
85
- * reimplement equality elsewhere.
87
+ * The single comparator shared across the form engine — the diff and conflict
88
+ * detection ({@link buildFormRebase}) — never reimplement equality elsewhere.
86
89
  */
87
90
  declare function deepEqual(a: unknown, b: unknown): boolean;
88
91
  //#endregion