@atscript/ui 0.1.202 → 0.1.204
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/form/create-form-def.cjs +80 -10
- package/dist/form/create-form-def.d.cts +24 -8
- package/dist/form/create-form-def.d.mts +24 -8
- package/dist/form/create-form-def.mjs +80 -11
- package/dist/form/diff.cjs +1 -1
- package/dist/form/diff.mjs +1 -1
- package/dist/form/types.d.cts +18 -6
- package/dist/form/types.d.mts +18 -6
- package/dist/form/validate.cjs +8 -6
- package/dist/form/validate.mjs +9 -7
- package/dist/plugin/value-help-validation.cjs +10 -2
- package/dist/plugin/value-help-validation.mjs +10 -2
- package/dist/shared/annotation-keys.cjs +4 -0
- package/dist/shared/annotation-keys.mjs +3 -1
- package/dist/table/create-table-def.cjs +7 -18
- package/dist/table/create-table-def.mjs +8 -19
- package/dist/table/types.d.cts +9 -12
- package/dist/table/types.d.mts +9 -12
- package/package.json +10 -10
|
@@ -6,6 +6,7 @@ const require_extract_literals = require("../value-help/extract-literals.cjs");
|
|
|
6
6
|
const require_extract_ref = require("../value-help/extract-ref.cjs");
|
|
7
7
|
const require_skipped_nav = require("./skipped-nav.cjs");
|
|
8
8
|
let _atscript_typescript_utils = require("@atscript/typescript/utils");
|
|
9
|
+
let _atscript_db_meta = require("@atscript/db/meta");
|
|
9
10
|
let _atscript_db_validator = require("@atscript/db/validator");
|
|
10
11
|
//#region src/form/create-form-def.ts
|
|
11
12
|
/** Known atscript primitive extension tags that map directly to field types. */
|
|
@@ -48,9 +49,15 @@ function unnamed(field) {
|
|
|
48
49
|
* - **Non-object types** (primitive, array, union, etc.): produces a single leaf root field
|
|
49
50
|
* with `path: ''`.
|
|
50
51
|
*
|
|
51
|
-
* A `@db.column.derived
|
|
52
|
-
* a computed
|
|
53
|
-
*
|
|
52
|
+
* A server-computed field — `@db.column.derived`, a computed view column
|
|
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
61
|
*
|
|
55
62
|
* A navigation field (`@db.rel.from` / `.to` / `.via` / `.store`) is left out unless it
|
|
56
63
|
* carries a `@ui.form.*` annotation of its own (see {@link isSkippedNavField}).
|
|
@@ -152,18 +159,71 @@ function collectFields(objectType, flatMap, edit, opts) {
|
|
|
152
159
|
const field = createFieldDef(path, originalProp, edit);
|
|
153
160
|
if (require_extract_ref.isValueHelpPicker(originalProp)) field.picker = true;
|
|
154
161
|
fields.push({
|
|
155
|
-
field
|
|
156
|
-
...field,
|
|
157
|
-
derived: true
|
|
158
|
-
} : field,
|
|
162
|
+
field,
|
|
159
163
|
order: require_field_resolver.getFieldMeta(originalProp, "ui.form.order") ?? Infinity,
|
|
160
164
|
pushDown: require_field_resolver.getFieldMeta(originalProp, require_annotation_keys.UI_FORM_PUSH_DOWN) !== void 0
|
|
161
165
|
});
|
|
162
166
|
}
|
|
167
|
+
if (opts) markServerOwned(fields, objectType, opts.metaFields);
|
|
163
168
|
keepWritableFills(fields);
|
|
164
169
|
return fields;
|
|
165
170
|
}
|
|
166
171
|
/**
|
|
172
|
+
* 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.
|
|
183
|
+
*/
|
|
184
|
+
function markServerOwned(fields, type, metaFields) {
|
|
185
|
+
const own = (0, _atscript_db_meta.writableViewReadOnlyFields)(type);
|
|
186
|
+
if (own.size === 0 && !metaFields) return;
|
|
187
|
+
const filled = /* @__PURE__ */ new Set();
|
|
188
|
+
for (const { field } of fields) {
|
|
189
|
+
const parent = parentPrefix(field.path);
|
|
190
|
+
for (const f of field.valueHelpInfo?.fill ?? []) filled.add(parent + f.local);
|
|
191
|
+
}
|
|
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 = {
|
|
204
|
+
...c.field,
|
|
205
|
+
derived: true
|
|
206
|
+
};
|
|
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
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* A server-owned field the form writes all the same: a pick fills it, a
|
|
216
|
+
* `@ui.form.fn.value` computes it, or a `@ui.form.fn.readonly` can make it
|
|
217
|
+
* editable.
|
|
218
|
+
*/
|
|
219
|
+
function writtenByForm(field, filled) {
|
|
220
|
+
return filled.has(field.path) || require_field_resolver.getFieldMeta(field.prop, "ui.form.fn.value") !== void 0 || require_field_resolver.getFieldMeta(field.prop, "ui.form.fn.readonly") !== void 0;
|
|
221
|
+
}
|
|
222
|
+
/** The path of the object holding `path`, with its trailing dot — `""` at the top. */
|
|
223
|
+
function parentPrefix(path) {
|
|
224
|
+
return path.slice(0, path.lastIndexOf(".") + 1);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
167
227
|
* Scopes a binding's sibling names to the def (since 0.1.190). Host references
|
|
168
228
|
* (`hostFilter`) and fills (`@ui.valueHelp.fill`) name fields of the interface
|
|
169
229
|
* declaring the bound field; a field the def lists by a dotted path — a field of
|
|
@@ -179,8 +239,7 @@ function keepWritableFills(fields) {
|
|
|
179
239
|
for (const { field } of fields) {
|
|
180
240
|
const info = field.valueHelpInfo;
|
|
181
241
|
if (!info?.fill && !info?.hostFilter) continue;
|
|
182
|
-
const
|
|
183
|
-
const parent = dot < 0 ? "" : field.path.slice(0, dot + 1);
|
|
242
|
+
const parent = parentPrefix(field.path);
|
|
184
243
|
const hostFilter = parent && info.hostFilter ? info.hostFilter.map((h) => ({
|
|
185
244
|
...h,
|
|
186
245
|
local: parent + h.local
|
|
@@ -239,7 +298,7 @@ function buildFieldDef(path, prop, edit) {
|
|
|
239
298
|
const uiType = declaredType === "tags" && kind !== "array" ? void 0 : declaredType;
|
|
240
299
|
const pushDown = require_field_resolver.getFieldMeta(prop, require_annotation_keys.UI_FORM_PUSH_DOWN) !== void 0;
|
|
241
300
|
const valueHelpInfo = require_extract_ref.extractValueHelp(prop);
|
|
242
|
-
const derived =
|
|
301
|
+
const derived = isServerComputed(prop) || edit && path !== "" && isUpdateStamped(prop);
|
|
243
302
|
const base = {
|
|
244
303
|
path,
|
|
245
304
|
prop,
|
|
@@ -467,6 +526,16 @@ function createVariant(def, edit) {
|
|
|
467
526
|
};
|
|
468
527
|
}
|
|
469
528
|
/**
|
|
529
|
+
* A field whose value the server computes and a write never sets:
|
|
530
|
+
* `@db.column.derived` (a table column derived from a JSON field), `@db.compute`
|
|
531
|
+
* (a computed view column) or `@db.compute.host` (a view field the serving host
|
|
532
|
+
* fills after each read). Each is valid on a top-level field only.
|
|
533
|
+
*/
|
|
534
|
+
function isServerComputed(prop) {
|
|
535
|
+
const meta = prop.metadata;
|
|
536
|
+
return meta.has("db.column.derived") || meta.has("db.compute") || meta.has("db.compute.host");
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
470
539
|
* An update-stamped field (see `CreateFormDefOptions.mode`). Read off the prop,
|
|
471
540
|
* or — as `@atscript/db` does — off the one value member of `T | null`, unless
|
|
472
541
|
* the prop references another field.
|
|
@@ -506,4 +575,5 @@ function typeLabel(kind) {
|
|
|
506
575
|
exports.buildUnionVariants = buildUnionVariants;
|
|
507
576
|
exports.createFormDef = createFormDef;
|
|
508
577
|
exports.findVersionColumn = findVersionColumn;
|
|
578
|
+
exports.isServerComputed = isServerComputed;
|
|
509
579
|
exports.resolveOriginalProp = resolveOriginalProp;
|
|
@@ -13,11 +13,21 @@ interface CreateFormDefOptions {
|
|
|
13
13
|
*/
|
|
14
14
|
versionColumn?: string;
|
|
15
15
|
/**
|
|
16
|
-
* `meta.fields` of the `/meta` the type came from
|
|
17
|
-
* `
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
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).
|
|
21
31
|
*/
|
|
22
32
|
metaFields?: Record<string, {
|
|
23
33
|
computed?: boolean;
|
|
@@ -45,9 +55,15 @@ interface CreateFormDefOptions {
|
|
|
45
55
|
* - **Non-object types** (primitive, array, union, etc.): produces a single leaf root field
|
|
46
56
|
* with `path: ''`.
|
|
47
57
|
*
|
|
48
|
-
* A `@db.column.derived
|
|
49
|
-
* a computed
|
|
50
|
-
*
|
|
58
|
+
* A server-computed field — `@db.column.derived`, a computed view column
|
|
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.
|
|
51
67
|
*
|
|
52
68
|
* A navigation field (`@db.rel.from` / `.to` / `.via` / `.store`) is left out unless it
|
|
53
69
|
* carries a `@ui.form.*` annotation of its own (see {@link isSkippedNavField}).
|
|
@@ -13,11 +13,21 @@ interface CreateFormDefOptions {
|
|
|
13
13
|
*/
|
|
14
14
|
versionColumn?: string;
|
|
15
15
|
/**
|
|
16
|
-
* `meta.fields` of the `/meta` the type came from
|
|
17
|
-
* `
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
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).
|
|
21
31
|
*/
|
|
22
32
|
metaFields?: Record<string, {
|
|
23
33
|
computed?: boolean;
|
|
@@ -45,9 +55,15 @@ interface CreateFormDefOptions {
|
|
|
45
55
|
* - **Non-object types** (primitive, array, union, etc.): produces a single leaf root field
|
|
46
56
|
* with `path: ''`.
|
|
47
57
|
*
|
|
48
|
-
* A `@db.column.derived
|
|
49
|
-
* a computed
|
|
50
|
-
*
|
|
58
|
+
* A server-computed field — `@db.column.derived`, a computed view column
|
|
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.
|
|
51
67
|
*
|
|
52
68
|
* A navigation field (`@db.rel.from` / `.to` / `.via` / `.store`) is left out unless it
|
|
53
69
|
* carries a `@ui.form.*` annotation of its own (see {@link isSkippedNavField}).
|
|
@@ -6,6 +6,7 @@ import { isEmptyMember, isPureLiteralUnion } from "../value-help/extract-literal
|
|
|
6
6
|
import { extractValueHelp, isValueHelpPicker } from "../value-help/extract-ref.mjs";
|
|
7
7
|
import { isSkippedNavField } from "./skipped-nav.mjs";
|
|
8
8
|
import { flattenAnnotatedType } from "@atscript/typescript/utils";
|
|
9
|
+
import { writableViewReadOnlyFields } from "@atscript/db/meta";
|
|
9
10
|
import { isNavRelation, isServerStampedOnUpdate } from "@atscript/db/validator";
|
|
10
11
|
//#region src/form/create-form-def.ts
|
|
11
12
|
/** Known atscript primitive extension tags that map directly to field types. */
|
|
@@ -48,9 +49,15 @@ function unnamed(field) {
|
|
|
48
49
|
* - **Non-object types** (primitive, array, union, etc.): produces a single leaf root field
|
|
49
50
|
* with `path: ''`.
|
|
50
51
|
*
|
|
51
|
-
* A `@db.column.derived
|
|
52
|
-
* a computed
|
|
53
|
-
*
|
|
52
|
+
* A server-computed field — `@db.column.derived`, a computed view column
|
|
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
61
|
*
|
|
55
62
|
* A navigation field (`@db.rel.from` / `.to` / `.via` / `.store`) is left out unless it
|
|
56
63
|
* carries a `@ui.form.*` annotation of its own (see {@link isSkippedNavField}).
|
|
@@ -152,18 +159,71 @@ function collectFields(objectType, flatMap, edit, opts) {
|
|
|
152
159
|
const field = createFieldDef(path, originalProp, edit);
|
|
153
160
|
if (isValueHelpPicker(originalProp)) field.picker = true;
|
|
154
161
|
fields.push({
|
|
155
|
-
field
|
|
156
|
-
...field,
|
|
157
|
-
derived: true
|
|
158
|
-
} : field,
|
|
162
|
+
field,
|
|
159
163
|
order: getFieldMeta(originalProp, "ui.form.order") ?? Infinity,
|
|
160
164
|
pushDown: getFieldMeta(originalProp, UI_FORM_PUSH_DOWN) !== void 0
|
|
161
165
|
});
|
|
162
166
|
}
|
|
167
|
+
if (opts) markServerOwned(fields, objectType, opts.metaFields);
|
|
163
168
|
keepWritableFills(fields);
|
|
164
169
|
return fields;
|
|
165
170
|
}
|
|
166
171
|
/**
|
|
172
|
+
* 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.
|
|
183
|
+
*/
|
|
184
|
+
function markServerOwned(fields, type, metaFields) {
|
|
185
|
+
const own = writableViewReadOnlyFields(type);
|
|
186
|
+
if (own.size === 0 && !metaFields) return;
|
|
187
|
+
const filled = /* @__PURE__ */ new Set();
|
|
188
|
+
for (const { field } of fields) {
|
|
189
|
+
const parent = parentPrefix(field.path);
|
|
190
|
+
for (const f of field.valueHelpInfo?.fill ?? []) filled.add(parent + f.local);
|
|
191
|
+
}
|
|
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 = {
|
|
204
|
+
...c.field,
|
|
205
|
+
derived: true
|
|
206
|
+
};
|
|
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
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* A server-owned field the form writes all the same: a pick fills it, a
|
|
216
|
+
* `@ui.form.fn.value` computes it, or a `@ui.form.fn.readonly` can make it
|
|
217
|
+
* editable.
|
|
218
|
+
*/
|
|
219
|
+
function writtenByForm(field, filled) {
|
|
220
|
+
return filled.has(field.path) || getFieldMeta(field.prop, "ui.form.fn.value") !== void 0 || getFieldMeta(field.prop, "ui.form.fn.readonly") !== void 0;
|
|
221
|
+
}
|
|
222
|
+
/** The path of the object holding `path`, with its trailing dot — `""` at the top. */
|
|
223
|
+
function parentPrefix(path) {
|
|
224
|
+
return path.slice(0, path.lastIndexOf(".") + 1);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
167
227
|
* Scopes a binding's sibling names to the def (since 0.1.190). Host references
|
|
168
228
|
* (`hostFilter`) and fills (`@ui.valueHelp.fill`) name fields of the interface
|
|
169
229
|
* declaring the bound field; a field the def lists by a dotted path — a field of
|
|
@@ -179,8 +239,7 @@ function keepWritableFills(fields) {
|
|
|
179
239
|
for (const { field } of fields) {
|
|
180
240
|
const info = field.valueHelpInfo;
|
|
181
241
|
if (!info?.fill && !info?.hostFilter) continue;
|
|
182
|
-
const
|
|
183
|
-
const parent = dot < 0 ? "" : field.path.slice(0, dot + 1);
|
|
242
|
+
const parent = parentPrefix(field.path);
|
|
184
243
|
const hostFilter = parent && info.hostFilter ? info.hostFilter.map((h) => ({
|
|
185
244
|
...h,
|
|
186
245
|
local: parent + h.local
|
|
@@ -239,7 +298,7 @@ function buildFieldDef(path, prop, edit) {
|
|
|
239
298
|
const uiType = declaredType === "tags" && kind !== "array" ? void 0 : declaredType;
|
|
240
299
|
const pushDown = getFieldMeta(prop, UI_FORM_PUSH_DOWN) !== void 0;
|
|
241
300
|
const valueHelpInfo = extractValueHelp(prop);
|
|
242
|
-
const derived =
|
|
301
|
+
const derived = isServerComputed(prop) || edit && path !== "" && isUpdateStamped(prop);
|
|
243
302
|
const base = {
|
|
244
303
|
path,
|
|
245
304
|
prop,
|
|
@@ -467,6 +526,16 @@ function createVariant(def, edit) {
|
|
|
467
526
|
};
|
|
468
527
|
}
|
|
469
528
|
/**
|
|
529
|
+
* A field whose value the server computes and a write never sets:
|
|
530
|
+
* `@db.column.derived` (a table column derived from a JSON field), `@db.compute`
|
|
531
|
+
* (a computed view column) or `@db.compute.host` (a view field the serving host
|
|
532
|
+
* fills after each read). Each is valid on a top-level field only.
|
|
533
|
+
*/
|
|
534
|
+
function isServerComputed(prop) {
|
|
535
|
+
const meta = prop.metadata;
|
|
536
|
+
return meta.has("db.column.derived") || meta.has("db.compute") || meta.has("db.compute.host");
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
470
539
|
* An update-stamped field (see `CreateFormDefOptions.mode`). Read off the prop,
|
|
471
540
|
* or — as `@atscript/db` does — off the one value member of `T | null`, unless
|
|
472
541
|
* the prop references another field.
|
|
@@ -503,4 +572,4 @@ function typeLabel(kind) {
|
|
|
503
572
|
} : { label: capitalize(kind) };
|
|
504
573
|
}
|
|
505
574
|
//#endregion
|
|
506
|
-
export { buildUnionVariants, createFormDef, findVersionColumn, resolveOriginalProp };
|
|
575
|
+
export { buildUnionVariants, createFormDef, findVersionColumn, isServerComputed, resolveOriginalProp };
|
package/dist/form/diff.cjs
CHANGED
|
@@ -76,7 +76,7 @@ function isNavKey(def, key) {
|
|
|
76
76
|
*/
|
|
77
77
|
function diffFields(fields, prefix, baseline, current, changes, patch, mergePaths, versionColumn) {
|
|
78
78
|
for (const field of fields) {
|
|
79
|
-
if (field.phantom || field.derived || versionColumn !== void 0 && !prefix && field.path === versionColumn) continue;
|
|
79
|
+
if (field.phantom || field.derived && !field.servedReadonly || versionColumn !== void 0 && !prefix && field.path === versionColumn) continue;
|
|
80
80
|
const fullPath = prefix ? `${prefix}.${field.path}` : field.path;
|
|
81
81
|
if (require_types.isArrayField(field)) {
|
|
82
82
|
diffArrayField(field, fullPath, baseline, current, changes, patch, mergePaths);
|
package/dist/form/diff.mjs
CHANGED
|
@@ -76,7 +76,7 @@ function isNavKey(def, key) {
|
|
|
76
76
|
*/
|
|
77
77
|
function diffFields(fields, prefix, baseline, current, changes, patch, mergePaths, versionColumn) {
|
|
78
78
|
for (const field of fields) {
|
|
79
|
-
if (field.phantom || field.derived || versionColumn !== void 0 && !prefix && field.path === versionColumn) continue;
|
|
79
|
+
if (field.phantom || field.derived && !field.servedReadonly || versionColumn !== void 0 && !prefix && field.path === versionColumn) continue;
|
|
80
80
|
const fullPath = prefix ? `${prefix}.${field.path}` : field.path;
|
|
81
81
|
if (isArrayField(field)) {
|
|
82
82
|
diffArrayField(field, fullPath, baseline, current, changes, patch, mergePaths);
|
package/dist/form/types.d.cts
CHANGED
|
@@ -66,14 +66,26 @@ interface FormFieldDef {
|
|
|
66
66
|
*/
|
|
67
67
|
picker?: true;
|
|
68
68
|
/**
|
|
69
|
-
* Server-owned field: a
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* `
|
|
74
|
-
*
|
|
69
|
+
* Server-owned field: a server-computed one read from the type metadata
|
|
70
|
+
* (`@db.column.derived`, `@db.compute`, `@db.compute.host`), a served field
|
|
71
|
+
* `CreateFormDefOptions.metaFields` marks (a computed column, a
|
|
72
|
+
* `@meta.readonly` field the form never writes), a field a compiled
|
|
73
|
+
* `@db.view.writable` view declares itself (a join column; since 0.1.204)
|
|
74
|
+
* or, in an edit form, an update-stamped one (see
|
|
75
|
+
* `CreateFormDefOptions.mode`). Rendered read-only, never required, exempt
|
|
76
|
+
* from form validation and never sent by `buildFormDiff` (the server drops
|
|
77
|
+
* or overwrites a written value anyway) — unless `servedReadonly`. Since
|
|
78
|
+
* 0.1.144.
|
|
75
79
|
*/
|
|
76
80
|
derived?: true;
|
|
81
|
+
/**
|
|
82
|
+
* Set with `derived` on a field `CreateFormDefOptions.metaFields` marks only
|
|
83
|
+
* for its served `@meta.readonly`: `buildFormDiff` still sends a changed
|
|
84
|
+
* value. The client can't tell a writable view's own field (the server drops
|
|
85
|
+
* it from a write) from a table's read-only one that app code may set.
|
|
86
|
+
* Since 0.1.203.
|
|
87
|
+
*/
|
|
88
|
+
servedReadonly?: true;
|
|
77
89
|
/**
|
|
78
90
|
* The enclosing prop whose `@ui.literalLabel` labels also apply to this
|
|
79
91
|
* field's values: the array prop of an item field (`flags: boolean[]`) or the
|
package/dist/form/types.d.mts
CHANGED
|
@@ -66,14 +66,26 @@ interface FormFieldDef {
|
|
|
66
66
|
*/
|
|
67
67
|
picker?: true;
|
|
68
68
|
/**
|
|
69
|
-
* Server-owned field: a
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* `
|
|
74
|
-
*
|
|
69
|
+
* Server-owned field: a server-computed one read from the type metadata
|
|
70
|
+
* (`@db.column.derived`, `@db.compute`, `@db.compute.host`), a served field
|
|
71
|
+
* `CreateFormDefOptions.metaFields` marks (a computed column, a
|
|
72
|
+
* `@meta.readonly` field the form never writes), a field a compiled
|
|
73
|
+
* `@db.view.writable` view declares itself (a join column; since 0.1.204)
|
|
74
|
+
* or, in an edit form, an update-stamped one (see
|
|
75
|
+
* `CreateFormDefOptions.mode`). Rendered read-only, never required, exempt
|
|
76
|
+
* from form validation and never sent by `buildFormDiff` (the server drops
|
|
77
|
+
* or overwrites a written value anyway) — unless `servedReadonly`. Since
|
|
78
|
+
* 0.1.144.
|
|
75
79
|
*/
|
|
76
80
|
derived?: true;
|
|
81
|
+
/**
|
|
82
|
+
* Set with `derived` on a field `CreateFormDefOptions.metaFields` marks only
|
|
83
|
+
* for its served `@meta.readonly`: `buildFormDiff` still sends a changed
|
|
84
|
+
* value. The client can't tell a writable view's own field (the server drops
|
|
85
|
+
* it from a write) from a table's read-only one that app code may set.
|
|
86
|
+
* Since 0.1.203.
|
|
87
|
+
*/
|
|
88
|
+
servedReadonly?: true;
|
|
77
89
|
/**
|
|
78
90
|
* The enclosing prop whose `@ui.literalLabel` labels also apply to this
|
|
79
91
|
* field's values: the array prop of an item field (`flags: boolean[]`) or the
|
package/dist/form/validate.cjs
CHANGED
|
@@ -38,8 +38,9 @@ const INSERT_CONTEXT = { mode: "insert" };
|
|
|
38
38
|
/**
|
|
39
39
|
* Always-on plugin for fields the server fills in, so a create form is not
|
|
40
40
|
* blocked on them:
|
|
41
|
-
* - `@db.column.derived
|
|
42
|
-
*
|
|
41
|
+
* - a server-computed field (`@db.column.derived`, `@db.compute`,
|
|
42
|
+
* `@db.compute.host` — {@link isServerComputed}): read-only, never
|
|
43
|
+
* validated (not even a loaded value, which the user could not fix).
|
|
43
44
|
* - a navigation field the form leaves out (`isSkippedNavField`): loaded
|
|
44
45
|
* related rows the form neither renders nor sends.
|
|
45
46
|
* - an absent `@db.default*` / `@db.column.version` / `@db.onUpdate.inc` value
|
|
@@ -55,7 +56,7 @@ const INSERT_CONTEXT = { mode: "insert" };
|
|
|
55
56
|
* insert context instead.
|
|
56
57
|
*/
|
|
57
58
|
const serverManagedPlugin = (ctx, def, value) => {
|
|
58
|
-
if (
|
|
59
|
+
if (require_create_form_def.isServerComputed(def) || require_skipped_nav.isSkippedNavField(def)) return true;
|
|
59
60
|
if (value !== void 0) return void 0;
|
|
60
61
|
return dbPlugin(Object.create(ctx, { context: { value: INSERT_CONTEXT } }), withoutFk(def), value);
|
|
61
62
|
};
|
|
@@ -102,9 +103,10 @@ function withoutFk(def) {
|
|
|
102
103
|
}
|
|
103
104
|
/**
|
|
104
105
|
* The props of the fields `createFormDef` marked `derived`, at any depth — a
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
106
|
+
* served field the server owns (`metaFields`: a computed column, a
|
|
107
|
+
* `@meta.readonly` one the form never writes) or an edit form's
|
|
108
|
+
* update-stamped field (see `CreateFormDefOptions.mode`) carries no annotation
|
|
109
|
+
* the plugin above could read. The validator matches by prop, so a prop that is also used where
|
|
108
110
|
* it is not derived (an interface's stamp below a union of several types, too)
|
|
109
111
|
* stays validated. A recursive type's def graph is cyclic: each field def is
|
|
110
112
|
* visited once.
|
package/dist/form/validate.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { isArrayField, isObjectField, isTupleField, isUnionField } from "./types
|
|
|
3
3
|
import { getUiTexts } from "../i18n/ui-texts.mjs";
|
|
4
4
|
import { isForeignKey, isValueHelpPicker } from "../value-help/extract-ref.mjs";
|
|
5
5
|
import { isSkippedNavField } from "./skipped-nav.mjs";
|
|
6
|
-
import { resolveOriginalProp } from "./create-form-def.mjs";
|
|
6
|
+
import { isServerComputed, resolveOriginalProp } from "./create-form-def.mjs";
|
|
7
7
|
import { validatorErrorsToMap } from "./error-utils.mjs";
|
|
8
8
|
import { VALIDATOR_MESSAGES, Validator, localizeErrors, normalizeForType } from "@atscript/typescript/utils";
|
|
9
9
|
import { createDbValidatorPlugin } from "@atscript/db/validator";
|
|
@@ -38,8 +38,9 @@ const INSERT_CONTEXT = { mode: "insert" };
|
|
|
38
38
|
/**
|
|
39
39
|
* Always-on plugin for fields the server fills in, so a create form is not
|
|
40
40
|
* blocked on them:
|
|
41
|
-
* - `@db.column.derived
|
|
42
|
-
*
|
|
41
|
+
* - a server-computed field (`@db.column.derived`, `@db.compute`,
|
|
42
|
+
* `@db.compute.host` — {@link isServerComputed}): read-only, never
|
|
43
|
+
* validated (not even a loaded value, which the user could not fix).
|
|
43
44
|
* - a navigation field the form leaves out (`isSkippedNavField`): loaded
|
|
44
45
|
* related rows the form neither renders nor sends.
|
|
45
46
|
* - an absent `@db.default*` / `@db.column.version` / `@db.onUpdate.inc` value
|
|
@@ -55,7 +56,7 @@ const INSERT_CONTEXT = { mode: "insert" };
|
|
|
55
56
|
* insert context instead.
|
|
56
57
|
*/
|
|
57
58
|
const serverManagedPlugin = (ctx, def, value) => {
|
|
58
|
-
if (def
|
|
59
|
+
if (isServerComputed(def) || isSkippedNavField(def)) return true;
|
|
59
60
|
if (value !== void 0) return void 0;
|
|
60
61
|
return dbPlugin(Object.create(ctx, { context: { value: INSERT_CONTEXT } }), withoutFk(def), value);
|
|
61
62
|
};
|
|
@@ -102,9 +103,10 @@ function withoutFk(def) {
|
|
|
102
103
|
}
|
|
103
104
|
/**
|
|
104
105
|
* The props of the fields `createFormDef` marked `derived`, at any depth — a
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
106
|
+
* served field the server owns (`metaFields`: a computed column, a
|
|
107
|
+
* `@meta.readonly` one the form never writes) or an edit form's
|
|
108
|
+
* update-stamped field (see `CreateFormDefOptions.mode`) carries no annotation
|
|
109
|
+
* the plugin above could read. The validator matches by prop, so a prop that is also used where
|
|
108
110
|
* it is not derived (an interface's stamp below a union of several types, too)
|
|
109
111
|
* stays validated. A recursive type's def graph is cyclic: each field def is
|
|
110
112
|
* visited once.
|
|
@@ -315,6 +315,12 @@ function bindingOf(field, doc) {
|
|
|
315
315
|
}
|
|
316
316
|
}
|
|
317
317
|
const SCALAR = "a scalar (not an object, an array, a navigation or @db.json)";
|
|
318
|
+
/** The annotations of a field whose value the server computes — a fill never writes one. */
|
|
319
|
+
const SERVER_COMPUTED = [
|
|
320
|
+
"db.column.derived",
|
|
321
|
+
"db.compute",
|
|
322
|
+
"db.compute.host"
|
|
323
|
+
];
|
|
318
324
|
/** Whether a field holds no scalar: an object, an array, `@db.json` or a navigation. */
|
|
319
325
|
function isNotScalar(prop, doc) {
|
|
320
326
|
if (prop.countAnnotations("db.json") > 0 || (0, _atscript_db_shared.isNavProp)(prop)) return true;
|
|
@@ -575,8 +581,10 @@ function validateFill(token, args, doc) {
|
|
|
575
581
|
});
|
|
576
582
|
else {
|
|
577
583
|
localOk = true;
|
|
578
|
-
|
|
579
|
-
|
|
584
|
+
const names = (0, _atscript_db_shared.effectiveAnnotationNames)(prop, doc);
|
|
585
|
+
const computed = SERVER_COMPUTED.find((key) => names.has(key));
|
|
586
|
+
if (computed) errors.push({
|
|
587
|
+
message: `'${local}' is @${computed} — a pick never writes it`,
|
|
580
588
|
severity: WARNING,
|
|
581
589
|
range: localArg.range
|
|
582
590
|
});
|
|
@@ -315,6 +315,12 @@ function bindingOf(field, doc) {
|
|
|
315
315
|
}
|
|
316
316
|
}
|
|
317
317
|
const SCALAR = "a scalar (not an object, an array, a navigation or @db.json)";
|
|
318
|
+
/** The annotations of a field whose value the server computes — a fill never writes one. */
|
|
319
|
+
const SERVER_COMPUTED = [
|
|
320
|
+
"db.column.derived",
|
|
321
|
+
"db.compute",
|
|
322
|
+
"db.compute.host"
|
|
323
|
+
];
|
|
318
324
|
/** Whether a field holds no scalar: an object, an array, `@db.json` or a navigation. */
|
|
319
325
|
function isNotScalar(prop, doc) {
|
|
320
326
|
if (prop.countAnnotations("db.json") > 0 || isNavProp(prop)) return true;
|
|
@@ -575,8 +581,10 @@ function validateFill(token, args, doc) {
|
|
|
575
581
|
});
|
|
576
582
|
else {
|
|
577
583
|
localOk = true;
|
|
578
|
-
|
|
579
|
-
|
|
584
|
+
const names = effectiveAnnotationNames(prop, doc);
|
|
585
|
+
const computed = SERVER_COMPUTED.find((key) => names.has(key));
|
|
586
|
+
if (computed) errors.push({
|
|
587
|
+
message: `'${local}' is @${computed} — a pick never writes it`,
|
|
580
588
|
severity: WARNING,
|
|
581
589
|
range: localArg.range
|
|
582
590
|
});
|
|
@@ -70,6 +70,8 @@ const DB_COLUMN_PRECISION = "db.column.precision";
|
|
|
70
70
|
const DB_COLUMN_VERSION = "db.column.version";
|
|
71
71
|
const DB_COLUMN_VERSION_TOKEN = "db.column.version.token";
|
|
72
72
|
const DB_COLUMN_DERIVED = "db.column.derived";
|
|
73
|
+
const DB_COMPUTE = "db.compute";
|
|
74
|
+
const DB_COMPUTE_HOST = "db.compute.host";
|
|
73
75
|
const WF_ACTION_WITH_DATA = "wf.action.withData";
|
|
74
76
|
const META_LABEL = "meta.label";
|
|
75
77
|
const META_ID = "meta.id";
|
|
@@ -110,6 +112,8 @@ exports.DB_COLUMN_DERIVED = DB_COLUMN_DERIVED;
|
|
|
110
112
|
exports.DB_COLUMN_PRECISION = DB_COLUMN_PRECISION;
|
|
111
113
|
exports.DB_COLUMN_VERSION = DB_COLUMN_VERSION;
|
|
112
114
|
exports.DB_COLUMN_VERSION_TOKEN = DB_COLUMN_VERSION_TOKEN;
|
|
115
|
+
exports.DB_COMPUTE = DB_COMPUTE;
|
|
116
|
+
exports.DB_COMPUTE_HOST = DB_COMPUTE_HOST;
|
|
113
117
|
exports.DB_ENCRYPTED = DB_ENCRYPTED;
|
|
114
118
|
exports.DB_HTTP_PATH = DB_HTTP_PATH;
|
|
115
119
|
exports.DB_JSON = DB_JSON;
|
|
@@ -70,6 +70,8 @@ const DB_COLUMN_PRECISION = "db.column.precision";
|
|
|
70
70
|
const DB_COLUMN_VERSION = "db.column.version";
|
|
71
71
|
const DB_COLUMN_VERSION_TOKEN = "db.column.version.token";
|
|
72
72
|
const DB_COLUMN_DERIVED = "db.column.derived";
|
|
73
|
+
const DB_COMPUTE = "db.compute";
|
|
74
|
+
const DB_COMPUTE_HOST = "db.compute.host";
|
|
73
75
|
const WF_ACTION_WITH_DATA = "wf.action.withData";
|
|
74
76
|
const META_LABEL = "meta.label";
|
|
75
77
|
const META_ID = "meta.id";
|
|
@@ -104,4 +106,4 @@ const UI_TABLE_FN_CLASSES = "ui.table.fn.classes";
|
|
|
104
106
|
const UI_TABLE_FN_STYLES = "ui.table.fn.styles";
|
|
105
107
|
const UI_FORM_VALIDATE = "ui.form.validate";
|
|
106
108
|
//#endregion
|
|
107
|
-
export { DB_AMOUNT_CURRENCY, DB_AMOUNT_CURRENCY_REF, DB_COLUMN_DERIVED, DB_COLUMN_PRECISION, DB_COLUMN_VERSION, DB_COLUMN_VERSION_TOKEN, DB_ENCRYPTED, DB_HTTP_PATH, DB_JSON, DB_REL_FK, DB_TABLE, DB_UNIT, DB_UNIT_REF, DB_VIEW, DB_VIEW_FOR, EXPECT_ARRAY_KEY, EXPECT_ARRAY_UNIQUE_ITEMS, EXPECT_MAX_LENGTH, EXPECT_MESSAGE, META_DEFAULT, META_DESCRIPTION, META_ID, META_LABEL, META_READONLY, META_REQUIRED, META_SENSITIVE, UI_DICT_ATTR, UI_DICT_DESCR, UI_DICT_FILTERABLE, UI_DICT_LABEL, UI_DICT_SEARCHABLE, UI_DICT_SORTABLE, UI_FORM_ACTION, UI_FORM_ATTR, UI_FORM_AUTOCOMPLETE, UI_FORM_CLASSES, UI_FORM_COMPONENT, UI_FORM_DISABLED, UI_FORM_FN_ATTR, UI_FORM_FN_CLASSES, UI_FORM_FN_DESCRIPTION, UI_FORM_FN_DISABLED, UI_FORM_FN_HIDDEN, UI_FORM_FN_HINT, UI_FORM_FN_LABEL, UI_FORM_FN_OPTIONS, UI_FORM_FN_PLACEHOLDER, UI_FORM_FN_PREFIX, UI_FORM_FN_READONLY, UI_FORM_FN_STYLES, UI_FORM_FN_SUBMIT_DISABLED, UI_FORM_FN_SUBMIT_TEXT, UI_FORM_FN_TITLE, UI_FORM_FN_VALUE, UI_FORM_GRID_COL_SPAN, UI_FORM_GRID_ROW_SPAN, UI_FORM_HIDDEN, UI_FORM_HINT, UI_FORM_LABEL_SINGULAR, UI_FORM_NS, UI_FORM_OPTIONS, UI_FORM_ORDER, UI_FORM_PLACEHOLDER, UI_FORM_PREFIX, UI_FORM_PREFIX_ICON, UI_FORM_PREFIX_REF, UI_FORM_PUSH_DOWN, UI_FORM_STYLES, UI_FORM_SUBMIT_TEXT, UI_FORM_SUFFIX, UI_FORM_SUFFIX_ICON, UI_FORM_SUFFIX_REF, UI_FORM_TYPE, UI_FORM_VALIDATE, UI_LITERAL_LABEL, UI_NAV_GROUP, UI_NAV_HIDDEN, UI_NAV_ORDER, UI_TABLE_ATTR, UI_TABLE_CLASSES, UI_TABLE_COMPONENT, UI_TABLE_EXCLUDE, UI_TABLE_FILL, UI_TABLE_FN_ATTR, UI_TABLE_FN_CLASSES, UI_TABLE_FN_PREFIX, UI_TABLE_FN_STYLES, UI_TABLE_ORDER, UI_TABLE_SELECT_WITH, UI_TABLE_STYLES, UI_TABLE_TYPE, UI_TABLE_WIDTH, UI_TYPE, UI_VALUE_HELP, UI_VALUE_HELP_COLUMN, UI_VALUE_HELP_DISTINCT, UI_VALUE_HELP_FILL, UI_VALUE_LABEL, WF_ACTION_WITH_DATA };
|
|
109
|
+
export { DB_AMOUNT_CURRENCY, DB_AMOUNT_CURRENCY_REF, DB_COLUMN_DERIVED, DB_COLUMN_PRECISION, DB_COLUMN_VERSION, DB_COLUMN_VERSION_TOKEN, DB_COMPUTE, DB_COMPUTE_HOST, DB_ENCRYPTED, DB_HTTP_PATH, DB_JSON, DB_REL_FK, DB_TABLE, DB_UNIT, DB_UNIT_REF, DB_VIEW, DB_VIEW_FOR, EXPECT_ARRAY_KEY, EXPECT_ARRAY_UNIQUE_ITEMS, EXPECT_MAX_LENGTH, EXPECT_MESSAGE, META_DEFAULT, META_DESCRIPTION, META_ID, META_LABEL, META_READONLY, META_REQUIRED, META_SENSITIVE, UI_DICT_ATTR, UI_DICT_DESCR, UI_DICT_FILTERABLE, UI_DICT_LABEL, UI_DICT_SEARCHABLE, UI_DICT_SORTABLE, UI_FORM_ACTION, UI_FORM_ATTR, UI_FORM_AUTOCOMPLETE, UI_FORM_CLASSES, UI_FORM_COMPONENT, UI_FORM_DISABLED, UI_FORM_FN_ATTR, UI_FORM_FN_CLASSES, UI_FORM_FN_DESCRIPTION, UI_FORM_FN_DISABLED, UI_FORM_FN_HIDDEN, UI_FORM_FN_HINT, UI_FORM_FN_LABEL, UI_FORM_FN_OPTIONS, UI_FORM_FN_PLACEHOLDER, UI_FORM_FN_PREFIX, UI_FORM_FN_READONLY, UI_FORM_FN_STYLES, UI_FORM_FN_SUBMIT_DISABLED, UI_FORM_FN_SUBMIT_TEXT, UI_FORM_FN_TITLE, UI_FORM_FN_VALUE, UI_FORM_GRID_COL_SPAN, UI_FORM_GRID_ROW_SPAN, UI_FORM_HIDDEN, UI_FORM_HINT, UI_FORM_LABEL_SINGULAR, UI_FORM_NS, UI_FORM_OPTIONS, UI_FORM_ORDER, UI_FORM_PLACEHOLDER, UI_FORM_PREFIX, UI_FORM_PREFIX_ICON, UI_FORM_PREFIX_REF, UI_FORM_PUSH_DOWN, UI_FORM_STYLES, UI_FORM_SUBMIT_TEXT, UI_FORM_SUFFIX, UI_FORM_SUFFIX_ICON, UI_FORM_SUFFIX_REF, UI_FORM_TYPE, UI_FORM_VALIDATE, UI_LITERAL_LABEL, UI_NAV_GROUP, UI_NAV_HIDDEN, UI_NAV_ORDER, UI_TABLE_ATTR, UI_TABLE_CLASSES, UI_TABLE_COMPONENT, UI_TABLE_EXCLUDE, UI_TABLE_FILL, UI_TABLE_FN_ATTR, UI_TABLE_FN_CLASSES, UI_TABLE_FN_PREFIX, UI_TABLE_FN_STYLES, UI_TABLE_ORDER, UI_TABLE_SELECT_WITH, UI_TABLE_STYLES, UI_TABLE_TYPE, UI_TABLE_WIDTH, UI_TYPE, UI_VALUE_HELP, UI_VALUE_HELP_COLUMN, UI_VALUE_HELP_DISTINCT, UI_VALUE_HELP_FILL, UI_VALUE_LABEL, WF_ACTION_WITH_DATA };
|
|
@@ -45,16 +45,6 @@ function createTableDef(meta, preDeserializedType, t) {
|
|
|
45
45
|
distinct
|
|
46
46
|
}));
|
|
47
47
|
}
|
|
48
|
-
if (meta.decorations) {
|
|
49
|
-
const decoType = (0, _atscript_typescript_utils.deserializeAnnotatedType)(meta.decorations);
|
|
50
|
-
if (decoType.type.kind === "object") for (const [path, prop] of decoType.type.props) {
|
|
51
|
-
const fieldMeta = meta.fields[path];
|
|
52
|
-
if (!fieldMeta?.decoration || flatMap.has(path)) continue;
|
|
53
|
-
if (require_field_resolver.getFieldMeta(prop, "ui.table.exclude") !== void 0) continue;
|
|
54
|
-
flatMap.set(path, prop);
|
|
55
|
-
columns.push(buildColumn(path, prop, fieldMeta, { options: require_extract_literals.extractFieldLiteralOptions(prop, t) }));
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
48
|
columns.sort((a, b) => a.order - b.order);
|
|
59
49
|
const actions = groupActions(meta.actions ?? []);
|
|
60
50
|
const crud = meta.crud ?? {};
|
|
@@ -78,9 +68,9 @@ function createTableDef(meta, preDeserializedType, t) {
|
|
|
78
68
|
};
|
|
79
69
|
}
|
|
80
70
|
/**
|
|
81
|
-
* One column
|
|
82
|
-
* is
|
|
83
|
-
*
|
|
71
|
+
* One column, its capabilities from `/meta`: a view's host-computed field
|
|
72
|
+
* (`@db.compute.host`) is served `sortable: false, filterable: false`, so it
|
|
73
|
+
* shows as a plain read-only column.
|
|
84
74
|
*/
|
|
85
75
|
function buildColumn(path, prop, fieldMeta, resolved) {
|
|
86
76
|
const { options, valueHelpInfo, distinct } = resolved;
|
|
@@ -88,8 +78,7 @@ function buildColumn(path, prop, fieldMeta, resolved) {
|
|
|
88
78
|
const tableType = require_field_resolver.getFieldMeta(prop, require_annotation_keys.UI_TABLE_TYPE);
|
|
89
79
|
const sharedType = require_field_resolver.getFieldMeta(prop, require_annotation_keys.UI_TYPE);
|
|
90
80
|
const tableComponent = require_field_resolver.getFieldMeta(prop, require_annotation_keys.UI_TABLE_COMPONENT);
|
|
91
|
-
const
|
|
92
|
-
const filterOps = decoration ? void 0 : fieldMeta.filterOps;
|
|
81
|
+
const filterOps = fieldMeta.filterOps;
|
|
93
82
|
let selectWith = require_field_resolver.getFieldMeta(prop, require_annotation_keys.UI_TABLE_SELECT_WITH);
|
|
94
83
|
const label = require_value_label.valueLabelOf(prop);
|
|
95
84
|
let valueLabel;
|
|
@@ -109,10 +98,10 @@ function buildColumn(path, prop, fieldMeta, resolved) {
|
|
|
109
98
|
valueKind: inferValueKind(prop),
|
|
110
99
|
component: tableComponent,
|
|
111
100
|
selectWith,
|
|
112
|
-
sortable:
|
|
113
|
-
filterable:
|
|
101
|
+
sortable: fieldMeta.sortable ?? false,
|
|
102
|
+
filterable: fieldMeta.filterable ?? false,
|
|
114
103
|
...filterOps && { filterOps: [...filterOps] },
|
|
115
|
-
nullable:
|
|
104
|
+
nullable: prop.optional === true || hasEmptyMember(prop),
|
|
116
105
|
width: require_field_resolver.getFieldMeta(prop, require_annotation_keys.UI_TABLE_WIDTH),
|
|
117
106
|
...require_field_resolver.getFieldMeta(prop, "ui.table.fill") !== void 0 && { fill: true },
|
|
118
107
|
maxLen: maxLengthMeta?.length,
|
|
@@ -6,7 +6,7 @@ import { extractValueHelp } from "../value-help/extract-ref.mjs";
|
|
|
6
6
|
import { humanizePath } from "../shared/str.mjs";
|
|
7
7
|
import { extractMeasurement } from "../form/measurement.mjs";
|
|
8
8
|
import { valueLabelOf } from "../shared/value-label.mjs";
|
|
9
|
-
import {
|
|
9
|
+
import { flattenAnnotatedType } from "@atscript/typescript/utils";
|
|
10
10
|
//#region src/table/create-table-def.ts
|
|
11
11
|
/**
|
|
12
12
|
* Builds a TableDef from a moost-db MetaResponse.
|
|
@@ -45,16 +45,6 @@ function createTableDef(meta, preDeserializedType, t) {
|
|
|
45
45
|
distinct
|
|
46
46
|
}));
|
|
47
47
|
}
|
|
48
|
-
if (meta.decorations) {
|
|
49
|
-
const decoType = deserializeAnnotatedType(meta.decorations);
|
|
50
|
-
if (decoType.type.kind === "object") for (const [path, prop] of decoType.type.props) {
|
|
51
|
-
const fieldMeta = meta.fields[path];
|
|
52
|
-
if (!fieldMeta?.decoration || flatMap.has(path)) continue;
|
|
53
|
-
if (getFieldMeta(prop, "ui.table.exclude") !== void 0) continue;
|
|
54
|
-
flatMap.set(path, prop);
|
|
55
|
-
columns.push(buildColumn(path, prop, fieldMeta, { options: extractFieldLiteralOptions(prop, t) }));
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
48
|
columns.sort((a, b) => a.order - b.order);
|
|
59
49
|
const actions = groupActions(meta.actions ?? []);
|
|
60
50
|
const crud = meta.crud ?? {};
|
|
@@ -78,9 +68,9 @@ function createTableDef(meta, preDeserializedType, t) {
|
|
|
78
68
|
};
|
|
79
69
|
}
|
|
80
70
|
/**
|
|
81
|
-
* One column
|
|
82
|
-
* is
|
|
83
|
-
*
|
|
71
|
+
* One column, its capabilities from `/meta`: a view's host-computed field
|
|
72
|
+
* (`@db.compute.host`) is served `sortable: false, filterable: false`, so it
|
|
73
|
+
* shows as a plain read-only column.
|
|
84
74
|
*/
|
|
85
75
|
function buildColumn(path, prop, fieldMeta, resolved) {
|
|
86
76
|
const { options, valueHelpInfo, distinct } = resolved;
|
|
@@ -88,8 +78,7 @@ function buildColumn(path, prop, fieldMeta, resolved) {
|
|
|
88
78
|
const tableType = getFieldMeta(prop, UI_TABLE_TYPE);
|
|
89
79
|
const sharedType = getFieldMeta(prop, UI_TYPE);
|
|
90
80
|
const tableComponent = getFieldMeta(prop, UI_TABLE_COMPONENT);
|
|
91
|
-
const
|
|
92
|
-
const filterOps = decoration ? void 0 : fieldMeta.filterOps;
|
|
81
|
+
const filterOps = fieldMeta.filterOps;
|
|
93
82
|
let selectWith = getFieldMeta(prop, UI_TABLE_SELECT_WITH);
|
|
94
83
|
const label = valueLabelOf(prop);
|
|
95
84
|
let valueLabel;
|
|
@@ -109,10 +98,10 @@ function buildColumn(path, prop, fieldMeta, resolved) {
|
|
|
109
98
|
valueKind: inferValueKind(prop),
|
|
110
99
|
component: tableComponent,
|
|
111
100
|
selectWith,
|
|
112
|
-
sortable:
|
|
113
|
-
filterable:
|
|
101
|
+
sortable: fieldMeta.sortable ?? false,
|
|
102
|
+
filterable: fieldMeta.filterable ?? false,
|
|
114
103
|
...filterOps && { filterOps: [...filterOps] },
|
|
115
|
-
nullable:
|
|
104
|
+
nullable: prop.optional === true || hasEmptyMember(prop),
|
|
116
105
|
width: getFieldMeta(prop, UI_TABLE_WIDTH),
|
|
117
106
|
...getFieldMeta(prop, "ui.table.fill") !== void 0 && { fill: true },
|
|
118
107
|
maxLen: maxLengthMeta?.length,
|
package/dist/table/types.d.cts
CHANGED
|
@@ -62,17 +62,19 @@ interface FieldMeta {
|
|
|
62
62
|
* A computed view column (`@db.compute`, `@atscript/db` 0.1.147+): the
|
|
63
63
|
* database evaluates it from other fields of the view. It is a column like
|
|
64
64
|
* any other — sorting and filtering follow `sortable` / `filterable` —
|
|
65
|
-
* but never writable: `createFormDef` marks it `derived`
|
|
66
|
-
*
|
|
65
|
+
* but never writable: `createFormDef` marks it `derived` (from the served
|
|
66
|
+
* `db.compute` marker since 0.1.205, else from these fields —
|
|
67
|
+
* `CreateFormDefOptions.metaFields`). Since 0.1.147.
|
|
67
68
|
*/
|
|
68
69
|
computed?: boolean;
|
|
69
70
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
71
|
+
* A view's host-computed field (`@db.compute.host`, `@atscript/db`
|
|
72
|
+
* 0.1.205+): no column — the server's `computeHost` fills it after each
|
|
73
|
+
* read. Selectable only: served `sortable: false, filterable: false`, so it
|
|
74
|
+
* is a read-only column with no sort or filter, and a form treats it as
|
|
75
|
+
* `derived`. Since 0.1.203 (replaces `decoration`).
|
|
74
76
|
*/
|
|
75
|
-
|
|
77
|
+
hostComputed?: boolean;
|
|
76
78
|
/**
|
|
77
79
|
* `$groupBy` on this field passes the server's gate (`@atscript/moost-db`
|
|
78
80
|
* 0.1.148+). Together with `filterable` and `@ui.valueHelp.distinct` it
|
|
@@ -107,11 +109,6 @@ interface MetaResponse {
|
|
|
107
109
|
relations: RelationInfo[];
|
|
108
110
|
fields: Record<string, FieldMeta>;
|
|
109
111
|
type: TSerializedAnnotatedType;
|
|
110
|
-
/**
|
|
111
|
-
* The controller's declared display-only fields (`@DbDecorations`) as a
|
|
112
|
-
* serialized plain interface. Absent on older servers. Since 0.1.148.
|
|
113
|
-
*/
|
|
114
|
-
decorations?: TSerializedAnnotatedType;
|
|
115
112
|
}
|
|
116
113
|
/**
|
|
117
114
|
* Server-declared actions grouped by `level`. Built by `createTableDef` from
|
package/dist/table/types.d.mts
CHANGED
|
@@ -62,17 +62,19 @@ interface FieldMeta {
|
|
|
62
62
|
* A computed view column (`@db.compute`, `@atscript/db` 0.1.147+): the
|
|
63
63
|
* database evaluates it from other fields of the view. It is a column like
|
|
64
64
|
* any other — sorting and filtering follow `sortable` / `filterable` —
|
|
65
|
-
* but never writable: `createFormDef` marks it `derived`
|
|
66
|
-
*
|
|
65
|
+
* but never writable: `createFormDef` marks it `derived` (from the served
|
|
66
|
+
* `db.compute` marker since 0.1.205, else from these fields —
|
|
67
|
+
* `CreateFormDefOptions.metaFields`). Since 0.1.147.
|
|
67
68
|
*/
|
|
68
69
|
computed?: boolean;
|
|
69
70
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
71
|
+
* A view's host-computed field (`@db.compute.host`, `@atscript/db`
|
|
72
|
+
* 0.1.205+): no column — the server's `computeHost` fills it after each
|
|
73
|
+
* read. Selectable only: served `sortable: false, filterable: false`, so it
|
|
74
|
+
* is a read-only column with no sort or filter, and a form treats it as
|
|
75
|
+
* `derived`. Since 0.1.203 (replaces `decoration`).
|
|
74
76
|
*/
|
|
75
|
-
|
|
77
|
+
hostComputed?: boolean;
|
|
76
78
|
/**
|
|
77
79
|
* `$groupBy` on this field passes the server's gate (`@atscript/moost-db`
|
|
78
80
|
* 0.1.148+). Together with `filterable` and `@ui.valueHelp.distinct` it
|
|
@@ -107,11 +109,6 @@ interface MetaResponse {
|
|
|
107
109
|
relations: RelationInfo[];
|
|
108
110
|
fields: Record<string, FieldMeta>;
|
|
109
111
|
type: TSerializedAnnotatedType;
|
|
110
|
-
/**
|
|
111
|
-
* The controller's declared display-only fields (`@DbDecorations`) as a
|
|
112
|
-
* serialized plain interface. Absent on older servers. Since 0.1.148.
|
|
113
|
-
*/
|
|
114
|
-
decorations?: TSerializedAnnotatedType;
|
|
115
112
|
}
|
|
116
113
|
/**
|
|
117
114
|
* Server-declared actions grouped by `level`. Built by `createTableDef` from
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/ui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.204",
|
|
4
4
|
"description": "Framework-agnostic runtime for form and table definitions from atscript annotated types",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"annotations",
|
|
@@ -52,20 +52,20 @@
|
|
|
52
52
|
"access": "public"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@atscript/db-client": "^0.1.
|
|
55
|
+
"@atscript/db-client": "^0.1.208"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@atscript/core": "^0.2.
|
|
59
|
-
"@atscript/db": "^0.1.
|
|
60
|
-
"@atscript/typescript": "^0.2.
|
|
61
|
-
"@uniqu/core": "^0.2.
|
|
62
|
-
"unplugin-atscript": "^0.2.
|
|
58
|
+
"@atscript/core": "^0.2.30",
|
|
59
|
+
"@atscript/db": "^0.1.208",
|
|
60
|
+
"@atscript/typescript": "^0.2.30",
|
|
61
|
+
"@uniqu/core": "^0.2.3",
|
|
62
|
+
"unplugin-atscript": "^0.2.30",
|
|
63
63
|
"vitest": "npm:@voidzero-dev/vite-plus-test@0.1.14"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
|
-
"@atscript/core": "^0.2.
|
|
67
|
-
"@atscript/db": "^0.1.
|
|
68
|
-
"@atscript/typescript": "^0.2.
|
|
66
|
+
"@atscript/core": "^0.2.30",
|
|
67
|
+
"@atscript/db": "^0.1.208",
|
|
68
|
+
"@atscript/typescript": "^0.2.30"
|
|
69
69
|
},
|
|
70
70
|
"scripts": {
|
|
71
71
|
"build": "vp pack",
|