@atscript/ui 0.1.201 → 0.1.203
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 +53 -10
- package/dist/form/create-form-def.d.cts +20 -8
- package/dist/form/create-form-def.d.mts +20 -8
- package/dist/form/create-form-def.mjs +53 -11
- package/dist/form/diff.cjs +1 -1
- package/dist/form/diff.mjs +1 -1
- package/dist/form/types.d.cts +16 -6
- package/dist/form/types.d.mts +16 -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 +9 -9
|
@@ -48,9 +48,11 @@ function unnamed(field) {
|
|
|
48
48
|
* - **Non-object types** (primitive, array, union, etc.): produces a single leaf root field
|
|
49
49
|
* with `path: ''`.
|
|
50
50
|
*
|
|
51
|
-
* A `@db.column.derived
|
|
52
|
-
* a computed
|
|
53
|
-
*
|
|
51
|
+
* A server-computed field — `@db.column.derived`, a computed view column
|
|
52
|
+
* (`@db.compute`) or a host-computed one (`@db.compute.host`) — is marked
|
|
53
|
+
* `derived` straight from its metadata; a served field the server owns, from
|
|
54
|
+
* `opts.metaFields`; an update-stamped field (see `CreateFormDefOptions.mode`),
|
|
55
|
+
* when `opts.mode` is `"edit"`.
|
|
54
56
|
*
|
|
55
57
|
* A navigation field (`@db.rel.from` / `.to` / `.via` / `.store`) is left out unless it
|
|
56
58
|
* carries a `@ui.form.*` annotation of its own (see {@link isSkippedNavField}).
|
|
@@ -152,18 +154,49 @@ function collectFields(objectType, flatMap, edit, opts) {
|
|
|
152
154
|
const field = createFieldDef(path, originalProp, edit);
|
|
153
155
|
if (require_extract_ref.isValueHelpPicker(originalProp)) field.picker = true;
|
|
154
156
|
fields.push({
|
|
155
|
-
field
|
|
156
|
-
...field,
|
|
157
|
-
derived: true
|
|
158
|
-
} : field,
|
|
157
|
+
field,
|
|
159
158
|
order: require_field_resolver.getFieldMeta(originalProp, "ui.form.order") ?? Infinity,
|
|
160
159
|
pushDown: require_field_resolver.getFieldMeta(originalProp, require_annotation_keys.UI_FORM_PUSH_DOWN) !== void 0
|
|
161
160
|
});
|
|
162
161
|
}
|
|
162
|
+
if (opts?.metaFields) markServedDerived(fields, opts.metaFields);
|
|
163
163
|
keepWritableFills(fields);
|
|
164
164
|
return fields;
|
|
165
165
|
}
|
|
166
166
|
/**
|
|
167
|
+
* Marks `derived` the fields of a def over a served type that the server owns
|
|
168
|
+
* although their own metadata does not say so (see
|
|
169
|
+
* `CreateFormDefOptions.metaFields`): a column `meta.fields` flags `computed`,
|
|
170
|
+
* and — `servedReadonly`, still diffed — a top-level `@meta.readonly` field
|
|
171
|
+
* the form never writes (a writable view's own fields are top-level; a
|
|
172
|
+
* namespace leaf rendered inline is not one). The def gets a copy: a recursive
|
|
173
|
+
* type's field defs may be shared with nested defs.
|
|
174
|
+
*/
|
|
175
|
+
function markServedDerived(fields, metaFields) {
|
|
176
|
+
const filled = /* @__PURE__ */ new Set();
|
|
177
|
+
for (const { field } of fields) {
|
|
178
|
+
const parent = parentPrefix(field.path);
|
|
179
|
+
for (const f of field.valueHelpInfo?.fill ?? []) filled.add(parent + f.local);
|
|
180
|
+
}
|
|
181
|
+
for (const c of fields) {
|
|
182
|
+
const { path, prop, derived } = c.field;
|
|
183
|
+
if (derived) continue;
|
|
184
|
+
if (metaFields[path]?.computed) c.field = {
|
|
185
|
+
...c.field,
|
|
186
|
+
derived: true
|
|
187
|
+
};
|
|
188
|
+
else if (!path.includes(".") && require_field_resolver.getFieldMeta(prop, "meta.readonly") !== void 0 && !filled.has(path) && require_field_resolver.getFieldMeta(prop, "ui.form.fn.value") === void 0 && require_field_resolver.getFieldMeta(prop, "ui.form.fn.readonly") === void 0) c.field = {
|
|
189
|
+
...c.field,
|
|
190
|
+
derived: true,
|
|
191
|
+
servedReadonly: true
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/** The path of the object holding `path`, with its trailing dot — `""` at the top. */
|
|
196
|
+
function parentPrefix(path) {
|
|
197
|
+
return path.slice(0, path.lastIndexOf(".") + 1);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
167
200
|
* Scopes a binding's sibling names to the def (since 0.1.190). Host references
|
|
168
201
|
* (`hostFilter`) and fills (`@ui.valueHelp.fill`) name fields of the interface
|
|
169
202
|
* declaring the bound field; a field the def lists by a dotted path — a field of
|
|
@@ -179,8 +212,7 @@ function keepWritableFills(fields) {
|
|
|
179
212
|
for (const { field } of fields) {
|
|
180
213
|
const info = field.valueHelpInfo;
|
|
181
214
|
if (!info?.fill && !info?.hostFilter) continue;
|
|
182
|
-
const
|
|
183
|
-
const parent = dot < 0 ? "" : field.path.slice(0, dot + 1);
|
|
215
|
+
const parent = parentPrefix(field.path);
|
|
184
216
|
const hostFilter = parent && info.hostFilter ? info.hostFilter.map((h) => ({
|
|
185
217
|
...h,
|
|
186
218
|
local: parent + h.local
|
|
@@ -239,7 +271,7 @@ function buildFieldDef(path, prop, edit) {
|
|
|
239
271
|
const uiType = declaredType === "tags" && kind !== "array" ? void 0 : declaredType;
|
|
240
272
|
const pushDown = require_field_resolver.getFieldMeta(prop, require_annotation_keys.UI_FORM_PUSH_DOWN) !== void 0;
|
|
241
273
|
const valueHelpInfo = require_extract_ref.extractValueHelp(prop);
|
|
242
|
-
const derived =
|
|
274
|
+
const derived = isServerComputed(prop) || edit && path !== "" && isUpdateStamped(prop);
|
|
243
275
|
const base = {
|
|
244
276
|
path,
|
|
245
277
|
prop,
|
|
@@ -467,6 +499,16 @@ function createVariant(def, edit) {
|
|
|
467
499
|
};
|
|
468
500
|
}
|
|
469
501
|
/**
|
|
502
|
+
* A field whose value the server computes and a write never sets:
|
|
503
|
+
* `@db.column.derived` (a table column derived from a JSON field), `@db.compute`
|
|
504
|
+
* (a computed view column) or `@db.compute.host` (a view field the serving host
|
|
505
|
+
* fills after each read). Each is valid on a top-level field only.
|
|
506
|
+
*/
|
|
507
|
+
function isServerComputed(prop) {
|
|
508
|
+
const meta = prop.metadata;
|
|
509
|
+
return meta.has("db.column.derived") || meta.has("db.compute") || meta.has("db.compute.host");
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
470
512
|
* An update-stamped field (see `CreateFormDefOptions.mode`). Read off the prop,
|
|
471
513
|
* or — as `@atscript/db` does — off the one value member of `T | null`, unless
|
|
472
514
|
* the prop references another field.
|
|
@@ -506,4 +548,5 @@ function typeLabel(kind) {
|
|
|
506
548
|
exports.buildUnionVariants = buildUnionVariants;
|
|
507
549
|
exports.createFormDef = createFormDef;
|
|
508
550
|
exports.findVersionColumn = findVersionColumn;
|
|
551
|
+
exports.isServerComputed = isServerComputed;
|
|
509
552
|
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,11 @@ 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"`.
|
|
51
63
|
*
|
|
52
64
|
* A navigation field (`@db.rel.from` / `.to` / `.via` / `.store`) is left out unless it
|
|
53
65
|
* 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,11 @@ 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"`.
|
|
51
63
|
*
|
|
52
64
|
* A navigation field (`@db.rel.from` / `.to` / `.via` / `.store`) is left out unless it
|
|
53
65
|
* carries a `@ui.form.*` annotation of its own (see {@link isSkippedNavField}).
|
|
@@ -48,9 +48,11 @@ function unnamed(field) {
|
|
|
48
48
|
* - **Non-object types** (primitive, array, union, etc.): produces a single leaf root field
|
|
49
49
|
* with `path: ''`.
|
|
50
50
|
*
|
|
51
|
-
* A `@db.column.derived
|
|
52
|
-
* a computed
|
|
53
|
-
*
|
|
51
|
+
* A server-computed field — `@db.column.derived`, a computed view column
|
|
52
|
+
* (`@db.compute`) or a host-computed one (`@db.compute.host`) — is marked
|
|
53
|
+
* `derived` straight from its metadata; a served field the server owns, from
|
|
54
|
+
* `opts.metaFields`; an update-stamped field (see `CreateFormDefOptions.mode`),
|
|
55
|
+
* when `opts.mode` is `"edit"`.
|
|
54
56
|
*
|
|
55
57
|
* A navigation field (`@db.rel.from` / `.to` / `.via` / `.store`) is left out unless it
|
|
56
58
|
* carries a `@ui.form.*` annotation of its own (see {@link isSkippedNavField}).
|
|
@@ -152,18 +154,49 @@ function collectFields(objectType, flatMap, edit, opts) {
|
|
|
152
154
|
const field = createFieldDef(path, originalProp, edit);
|
|
153
155
|
if (isValueHelpPicker(originalProp)) field.picker = true;
|
|
154
156
|
fields.push({
|
|
155
|
-
field
|
|
156
|
-
...field,
|
|
157
|
-
derived: true
|
|
158
|
-
} : field,
|
|
157
|
+
field,
|
|
159
158
|
order: getFieldMeta(originalProp, "ui.form.order") ?? Infinity,
|
|
160
159
|
pushDown: getFieldMeta(originalProp, UI_FORM_PUSH_DOWN) !== void 0
|
|
161
160
|
});
|
|
162
161
|
}
|
|
162
|
+
if (opts?.metaFields) markServedDerived(fields, opts.metaFields);
|
|
163
163
|
keepWritableFills(fields);
|
|
164
164
|
return fields;
|
|
165
165
|
}
|
|
166
166
|
/**
|
|
167
|
+
* Marks `derived` the fields of a def over a served type that the server owns
|
|
168
|
+
* although their own metadata does not say so (see
|
|
169
|
+
* `CreateFormDefOptions.metaFields`): a column `meta.fields` flags `computed`,
|
|
170
|
+
* and — `servedReadonly`, still diffed — a top-level `@meta.readonly` field
|
|
171
|
+
* the form never writes (a writable view's own fields are top-level; a
|
|
172
|
+
* namespace leaf rendered inline is not one). The def gets a copy: a recursive
|
|
173
|
+
* type's field defs may be shared with nested defs.
|
|
174
|
+
*/
|
|
175
|
+
function markServedDerived(fields, metaFields) {
|
|
176
|
+
const filled = /* @__PURE__ */ new Set();
|
|
177
|
+
for (const { field } of fields) {
|
|
178
|
+
const parent = parentPrefix(field.path);
|
|
179
|
+
for (const f of field.valueHelpInfo?.fill ?? []) filled.add(parent + f.local);
|
|
180
|
+
}
|
|
181
|
+
for (const c of fields) {
|
|
182
|
+
const { path, prop, derived } = c.field;
|
|
183
|
+
if (derived) continue;
|
|
184
|
+
if (metaFields[path]?.computed) c.field = {
|
|
185
|
+
...c.field,
|
|
186
|
+
derived: true
|
|
187
|
+
};
|
|
188
|
+
else if (!path.includes(".") && getFieldMeta(prop, "meta.readonly") !== void 0 && !filled.has(path) && getFieldMeta(prop, "ui.form.fn.value") === void 0 && getFieldMeta(prop, "ui.form.fn.readonly") === void 0) c.field = {
|
|
189
|
+
...c.field,
|
|
190
|
+
derived: true,
|
|
191
|
+
servedReadonly: true
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/** The path of the object holding `path`, with its trailing dot — `""` at the top. */
|
|
196
|
+
function parentPrefix(path) {
|
|
197
|
+
return path.slice(0, path.lastIndexOf(".") + 1);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
167
200
|
* Scopes a binding's sibling names to the def (since 0.1.190). Host references
|
|
168
201
|
* (`hostFilter`) and fills (`@ui.valueHelp.fill`) name fields of the interface
|
|
169
202
|
* declaring the bound field; a field the def lists by a dotted path — a field of
|
|
@@ -179,8 +212,7 @@ function keepWritableFills(fields) {
|
|
|
179
212
|
for (const { field } of fields) {
|
|
180
213
|
const info = field.valueHelpInfo;
|
|
181
214
|
if (!info?.fill && !info?.hostFilter) continue;
|
|
182
|
-
const
|
|
183
|
-
const parent = dot < 0 ? "" : field.path.slice(0, dot + 1);
|
|
215
|
+
const parent = parentPrefix(field.path);
|
|
184
216
|
const hostFilter = parent && info.hostFilter ? info.hostFilter.map((h) => ({
|
|
185
217
|
...h,
|
|
186
218
|
local: parent + h.local
|
|
@@ -239,7 +271,7 @@ function buildFieldDef(path, prop, edit) {
|
|
|
239
271
|
const uiType = declaredType === "tags" && kind !== "array" ? void 0 : declaredType;
|
|
240
272
|
const pushDown = getFieldMeta(prop, UI_FORM_PUSH_DOWN) !== void 0;
|
|
241
273
|
const valueHelpInfo = extractValueHelp(prop);
|
|
242
|
-
const derived =
|
|
274
|
+
const derived = isServerComputed(prop) || edit && path !== "" && isUpdateStamped(prop);
|
|
243
275
|
const base = {
|
|
244
276
|
path,
|
|
245
277
|
prop,
|
|
@@ -467,6 +499,16 @@ function createVariant(def, edit) {
|
|
|
467
499
|
};
|
|
468
500
|
}
|
|
469
501
|
/**
|
|
502
|
+
* A field whose value the server computes and a write never sets:
|
|
503
|
+
* `@db.column.derived` (a table column derived from a JSON field), `@db.compute`
|
|
504
|
+
* (a computed view column) or `@db.compute.host` (a view field the serving host
|
|
505
|
+
* fills after each read). Each is valid on a top-level field only.
|
|
506
|
+
*/
|
|
507
|
+
function isServerComputed(prop) {
|
|
508
|
+
const meta = prop.metadata;
|
|
509
|
+
return meta.has("db.column.derived") || meta.has("db.compute") || meta.has("db.compute.host");
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
470
512
|
* An update-stamped field (see `CreateFormDefOptions.mode`). Read off the prop,
|
|
471
513
|
* or — as `@atscript/db` does — off the one value member of `T | null`, unless
|
|
472
514
|
* the prop references another field.
|
|
@@ -503,4 +545,4 @@ function typeLabel(kind) {
|
|
|
503
545
|
} : { label: capitalize(kind) };
|
|
504
546
|
}
|
|
505
547
|
//#endregion
|
|
506
|
-
export { buildUnionVariants, createFormDef, findVersionColumn, resolveOriginalProp };
|
|
548
|
+
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,24 @@ 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) or, in an edit
|
|
73
|
+
* form, an update-stamped one (see `CreateFormDefOptions.mode`). Rendered
|
|
74
|
+
* read-only, never required, exempt from form validation and never sent by
|
|
75
|
+
* `buildFormDiff` (the server drops or overwrites a written value anyway) —
|
|
76
|
+
* unless `servedReadonly`. Since 0.1.144.
|
|
75
77
|
*/
|
|
76
78
|
derived?: true;
|
|
79
|
+
/**
|
|
80
|
+
* Set with `derived` on a field `CreateFormDefOptions.metaFields` marks only
|
|
81
|
+
* for its served `@meta.readonly`: `buildFormDiff` still sends a changed
|
|
82
|
+
* value. The client can't tell a writable view's own field (the server drops
|
|
83
|
+
* it from a write) from a table's read-only one that app code may set.
|
|
84
|
+
* Since 0.1.203.
|
|
85
|
+
*/
|
|
86
|
+
servedReadonly?: true;
|
|
77
87
|
/**
|
|
78
88
|
* The enclosing prop whose `@ui.literalLabel` labels also apply to this
|
|
79
89
|
* field's values: the array prop of an item field (`flags: boolean[]`) or the
|
package/dist/form/types.d.mts
CHANGED
|
@@ -66,14 +66,24 @@ 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) or, in an edit
|
|
73
|
+
* form, an update-stamped one (see `CreateFormDefOptions.mode`). Rendered
|
|
74
|
+
* read-only, never required, exempt from form validation and never sent by
|
|
75
|
+
* `buildFormDiff` (the server drops or overwrites a written value anyway) —
|
|
76
|
+
* unless `servedReadonly`. Since 0.1.144.
|
|
75
77
|
*/
|
|
76
78
|
derived?: true;
|
|
79
|
+
/**
|
|
80
|
+
* Set with `derived` on a field `CreateFormDefOptions.metaFields` marks only
|
|
81
|
+
* for its served `@meta.readonly`: `buildFormDiff` still sends a changed
|
|
82
|
+
* value. The client can't tell a writable view's own field (the server drops
|
|
83
|
+
* it from a write) from a table's read-only one that app code may set.
|
|
84
|
+
* Since 0.1.203.
|
|
85
|
+
*/
|
|
86
|
+
servedReadonly?: true;
|
|
77
87
|
/**
|
|
78
88
|
* The enclosing prop whose `@ui.literalLabel` labels also apply to this
|
|
79
89
|
* 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.203",
|
|
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.206"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@atscript/core": "^0.2.
|
|
59
|
-
"@atscript/db": "^0.1.
|
|
60
|
-
"@atscript/typescript": "^0.2.
|
|
58
|
+
"@atscript/core": "^0.2.29",
|
|
59
|
+
"@atscript/db": "^0.1.206",
|
|
60
|
+
"@atscript/typescript": "^0.2.29",
|
|
61
61
|
"@uniqu/core": "^0.2.2",
|
|
62
|
-
"unplugin-atscript": "^0.2.
|
|
62
|
+
"unplugin-atscript": "^0.2.29",
|
|
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.29",
|
|
67
|
+
"@atscript/db": "^0.1.206",
|
|
68
|
+
"@atscript/typescript": "^0.2.29"
|
|
69
69
|
},
|
|
70
70
|
"scripts": {
|
|
71
71
|
"build": "vp pack",
|