@atscript/ui 0.1.203 → 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.
|
@@ -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. */
|
|
@@ -52,7 +53,11 @@ function unnamed(field) {
|
|
|
52
53
|
* (`@db.compute`) or a host-computed one (`@db.compute.host`) — is marked
|
|
53
54
|
* `derived` straight from its metadata; a served field the server owns, from
|
|
54
55
|
* `opts.metaFields`; an update-stamped field (see `CreateFormDefOptions.mode`),
|
|
55
|
-
* when `opts.mode` is `"edit"`.
|
|
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.
|
|
56
61
|
*
|
|
57
62
|
* A navigation field (`@db.rel.from` / `.to` / `.via` / `.store`) is left out unless it
|
|
58
63
|
* carries a `@ui.form.*` annotation of its own (see {@link isSkippedNavField}).
|
|
@@ -159,20 +164,26 @@ function collectFields(objectType, flatMap, edit, opts) {
|
|
|
159
164
|
pushDown: require_field_resolver.getFieldMeta(originalProp, require_annotation_keys.UI_FORM_PUSH_DOWN) !== void 0
|
|
160
165
|
});
|
|
161
166
|
}
|
|
162
|
-
if (opts
|
|
167
|
+
if (opts) markServerOwned(fields, objectType, opts.metaFields);
|
|
163
168
|
keepWritableFills(fields);
|
|
164
169
|
return fields;
|
|
165
170
|
}
|
|
166
171
|
/**
|
|
167
|
-
* Marks `derived` the fields
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
* type's
|
|
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.
|
|
174
183
|
*/
|
|
175
|
-
function
|
|
184
|
+
function markServerOwned(fields, type, metaFields) {
|
|
185
|
+
const own = (0, _atscript_db_meta.writableViewReadOnlyFields)(type);
|
|
186
|
+
if (own.size === 0 && !metaFields) return;
|
|
176
187
|
const filled = /* @__PURE__ */ new Set();
|
|
177
188
|
for (const { field } of fields) {
|
|
178
189
|
const parent = parentPrefix(field.path);
|
|
@@ -181,17 +192,33 @@ function markServedDerived(fields, metaFields) {
|
|
|
181
192
|
for (const c of fields) {
|
|
182
193
|
const { path, prop, derived } = c.field;
|
|
183
194
|
if (derived) continue;
|
|
184
|
-
if (metaFields[path]?.computed)
|
|
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 = {
|
|
185
204
|
...c.field,
|
|
186
205
|
derived: true
|
|
187
206
|
};
|
|
188
|
-
else if (!path.includes(".") && require_field_resolver.getFieldMeta(prop, "meta.readonly") !== void 0
|
|
207
|
+
else if (metaFields && !path.includes(".") && require_field_resolver.getFieldMeta(prop, "meta.readonly") !== void 0) c.field = {
|
|
189
208
|
...c.field,
|
|
190
209
|
derived: true,
|
|
191
210
|
servedReadonly: true
|
|
192
211
|
};
|
|
193
212
|
}
|
|
194
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
|
+
}
|
|
195
222
|
/** The path of the object holding `path`, with its trailing dot — `""` at the top. */
|
|
196
223
|
function parentPrefix(path) {
|
|
197
224
|
return path.slice(0, path.lastIndexOf(".") + 1);
|
|
@@ -59,7 +59,11 @@ interface CreateFormDefOptions {
|
|
|
59
59
|
* (`@db.compute`) or a host-computed one (`@db.compute.host`) — is marked
|
|
60
60
|
* `derived` straight from its metadata; a served field the server owns, from
|
|
61
61
|
* `opts.metaFields`; an update-stamped field (see `CreateFormDefOptions.mode`),
|
|
62
|
-
* when `opts.mode` is `"edit"`.
|
|
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.
|
|
63
67
|
*
|
|
64
68
|
* A navigation field (`@db.rel.from` / `.to` / `.via` / `.store`) is left out unless it
|
|
65
69
|
* carries a `@ui.form.*` annotation of its own (see {@link isSkippedNavField}).
|
|
@@ -59,7 +59,11 @@ interface CreateFormDefOptions {
|
|
|
59
59
|
* (`@db.compute`) or a host-computed one (`@db.compute.host`) — is marked
|
|
60
60
|
* `derived` straight from its metadata; a served field the server owns, from
|
|
61
61
|
* `opts.metaFields`; an update-stamped field (see `CreateFormDefOptions.mode`),
|
|
62
|
-
* when `opts.mode` is `"edit"`.
|
|
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.
|
|
63
67
|
*
|
|
64
68
|
* A navigation field (`@db.rel.from` / `.to` / `.via` / `.store`) is left out unless it
|
|
65
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. */
|
|
@@ -52,7 +53,11 @@ function unnamed(field) {
|
|
|
52
53
|
* (`@db.compute`) or a host-computed one (`@db.compute.host`) — is marked
|
|
53
54
|
* `derived` straight from its metadata; a served field the server owns, from
|
|
54
55
|
* `opts.metaFields`; an update-stamped field (see `CreateFormDefOptions.mode`),
|
|
55
|
-
* when `opts.mode` is `"edit"`.
|
|
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.
|
|
56
61
|
*
|
|
57
62
|
* A navigation field (`@db.rel.from` / `.to` / `.via` / `.store`) is left out unless it
|
|
58
63
|
* carries a `@ui.form.*` annotation of its own (see {@link isSkippedNavField}).
|
|
@@ -159,20 +164,26 @@ function collectFields(objectType, flatMap, edit, opts) {
|
|
|
159
164
|
pushDown: getFieldMeta(originalProp, UI_FORM_PUSH_DOWN) !== void 0
|
|
160
165
|
});
|
|
161
166
|
}
|
|
162
|
-
if (opts
|
|
167
|
+
if (opts) markServerOwned(fields, objectType, opts.metaFields);
|
|
163
168
|
keepWritableFills(fields);
|
|
164
169
|
return fields;
|
|
165
170
|
}
|
|
166
171
|
/**
|
|
167
|
-
* Marks `derived` the fields
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
* type's
|
|
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.
|
|
174
183
|
*/
|
|
175
|
-
function
|
|
184
|
+
function markServerOwned(fields, type, metaFields) {
|
|
185
|
+
const own = writableViewReadOnlyFields(type);
|
|
186
|
+
if (own.size === 0 && !metaFields) return;
|
|
176
187
|
const filled = /* @__PURE__ */ new Set();
|
|
177
188
|
for (const { field } of fields) {
|
|
178
189
|
const parent = parentPrefix(field.path);
|
|
@@ -181,17 +192,33 @@ function markServedDerived(fields, metaFields) {
|
|
|
181
192
|
for (const c of fields) {
|
|
182
193
|
const { path, prop, derived } = c.field;
|
|
183
194
|
if (derived) continue;
|
|
184
|
-
if (metaFields[path]?.computed)
|
|
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 = {
|
|
185
204
|
...c.field,
|
|
186
205
|
derived: true
|
|
187
206
|
};
|
|
188
|
-
else if (!path.includes(".") && getFieldMeta(prop, "meta.readonly") !== void 0
|
|
207
|
+
else if (metaFields && !path.includes(".") && getFieldMeta(prop, "meta.readonly") !== void 0) c.field = {
|
|
189
208
|
...c.field,
|
|
190
209
|
derived: true,
|
|
191
210
|
servedReadonly: true
|
|
192
211
|
};
|
|
193
212
|
}
|
|
194
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
|
+
}
|
|
195
222
|
/** The path of the object holding `path`, with its trailing dot — `""` at the top. */
|
|
196
223
|
function parentPrefix(path) {
|
|
197
224
|
return path.slice(0, path.lastIndexOf(".") + 1);
|
package/dist/form/types.d.cts
CHANGED
|
@@ -69,11 +69,13 @@ interface FormFieldDef {
|
|
|
69
69
|
* Server-owned field: a server-computed one read from the type metadata
|
|
70
70
|
* (`@db.column.derived`, `@db.compute`, `@db.compute.host`), a served field
|
|
71
71
|
* `CreateFormDefOptions.metaFields` marks (a computed column, a
|
|
72
|
-
* `@meta.readonly` field the form never writes)
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* `
|
|
76
|
-
*
|
|
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.
|
|
77
79
|
*/
|
|
78
80
|
derived?: true;
|
|
79
81
|
/**
|
package/dist/form/types.d.mts
CHANGED
|
@@ -69,11 +69,13 @@ interface FormFieldDef {
|
|
|
69
69
|
* Server-owned field: a server-computed one read from the type metadata
|
|
70
70
|
* (`@db.column.derived`, `@db.compute`, `@db.compute.host`), a served field
|
|
71
71
|
* `CreateFormDefOptions.metaFields` marks (a computed column, a
|
|
72
|
-
* `@meta.readonly` field the form never writes)
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* `
|
|
76
|
-
*
|
|
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.
|
|
77
79
|
*/
|
|
78
80
|
derived?: true;
|
|
79
81
|
/**
|
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",
|