@atscript/ui 0.1.197 → 0.1.198

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.
@@ -150,6 +150,7 @@ function collectFields(objectType, flatMap, edit, opts) {
150
150
  }
151
151
  if (kind === "array" || kind === "object" || kind === "union" || kind === "tuple") structuredPrefixes.add(path + ".");
152
152
  const field = createFieldDef(path, originalProp, edit);
153
+ if (require_extract_ref.isValueHelpPicker(originalProp)) field.picker = true;
153
154
  fields.push({
154
155
  field: opts?.metaFields?.[path]?.computed ? {
155
156
  ...field,
@@ -505,3 +506,4 @@ function typeLabel(kind) {
505
506
  exports.buildUnionVariants = buildUnionVariants;
506
507
  exports.createFormDef = createFormDef;
507
508
  exports.findVersionColumn = findVersionColumn;
509
+ exports.resolveOriginalProp = resolveOriginalProp;
@@ -3,7 +3,7 @@ import { isServedType } from "../i18n/model-texts.mjs";
3
3
  import { getFieldMeta, hasComputedAnnotations } from "../shared/field-resolver.mjs";
4
4
  import { AS_UI_MESSAGES } from "../messages.mjs";
5
5
  import { isEmptyMember, isPureLiteralUnion } from "../value-help/extract-literals.mjs";
6
- import { extractValueHelp } from "../value-help/extract-ref.mjs";
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
9
  import { isNavRelation, isServerStampedOnUpdate } from "@atscript/db/validator";
@@ -150,6 +150,7 @@ function collectFields(objectType, flatMap, edit, opts) {
150
150
  }
151
151
  if (kind === "array" || kind === "object" || kind === "union" || kind === "tuple") structuredPrefixes.add(path + ".");
152
152
  const field = createFieldDef(path, originalProp, edit);
153
+ if (isValueHelpPicker(originalProp)) field.picker = true;
153
154
  fields.push({
154
155
  field: opts?.metaFields?.[path]?.computed ? {
155
156
  ...field,
@@ -502,4 +503,4 @@ function typeLabel(kind) {
502
503
  } : { label: capitalize(kind) };
503
504
  }
504
505
  //#endregion
505
- export { buildUnionVariants, createFormDef, findVersionColumn };
506
+ export { buildUnionVariants, createFormDef, findVersionColumn, resolveOriginalProp };
@@ -141,7 +141,7 @@ function createFormData(type, resolver) {
141
141
  if (resolved !== void 0) return resolved;
142
142
  if (pickers.get(path) === prop) unset.push(path);
143
143
  else if (prop.type.kind === "object") {
144
- for (const [key, child] of prop.type.props) if (child.type.kind === "" && require_extract_ref.extractValueHelp(child)) pickers.set(joinPath(path, key), child);
144
+ for (const [key, child] of prop.type.props) if (require_extract_ref.isValueHelpPicker(child)) pickers.set(joinPath(path, key), child);
145
145
  }
146
146
  } });
147
147
  if (value === void 0) value = primitiveInitFallback(type);
@@ -1,6 +1,6 @@
1
1
  import { META_DEFAULT, UI_FORM_FN_VALUE } from "../shared/annotation-keys.mjs";
2
2
  import { resolveFieldProp } from "../shared/field-resolver.mjs";
3
- import { extractValueHelp } from "../value-help/extract-ref.mjs";
3
+ import { isValueHelpPicker } from "../value-help/extract-ref.mjs";
4
4
  import { createDataFromAnnotatedType, detectDiscriminator } from "@atscript/typescript/utils";
5
5
  //#region src/form/path-utils.ts
6
6
  /**
@@ -141,7 +141,7 @@ function createFormData(type, resolver) {
141
141
  if (resolved !== void 0) return resolved;
142
142
  if (pickers.get(path) === prop) unset.push(path);
143
143
  else if (prop.type.kind === "object") {
144
- for (const [key, child] of prop.type.props) if (child.type.kind === "" && extractValueHelp(child)) pickers.set(joinPath(path, key), child);
144
+ for (const [key, child] of prop.type.props) if (isValueHelpPicker(child)) pickers.set(joinPath(path, key), child);
145
145
  }
146
146
  } });
147
147
  if (value === void 0) value = primitiveInitFallback(type);
@@ -57,6 +57,14 @@ interface FormFieldDef {
57
57
  * the component layer.
58
58
  */
59
59
  valueHelpInfo?: ValueHelpInfo;
60
+ /**
61
+ * A property of an object (at any depth: a nested object, an object row of
62
+ * an array) that the form renders as a value-help picker. A new form leaves
63
+ * it unset, and a required one left unpicked fails with code `REQUIRED`
64
+ * (pass it to `createFieldValidator` as `picker`). An array item, a tuple
65
+ * position and a union-typed field are none. Since 0.1.198.
66
+ */
67
+ picker?: true;
60
68
  /**
61
69
  * Server-owned field: a `@db.column.derived` one (read from the type
62
70
  * metadata), a computed view column (`CreateFormDefOptions.metaFields`) or,
@@ -57,6 +57,14 @@ interface FormFieldDef {
57
57
  * the component layer.
58
58
  */
59
59
  valueHelpInfo?: ValueHelpInfo;
60
+ /**
61
+ * A property of an object (at any depth: a nested object, an object row of
62
+ * an array) that the form renders as a value-help picker. A new form leaves
63
+ * it unset, and a required one left unpicked fails with code `REQUIRED`
64
+ * (pass it to `createFieldValidator` as `picker`). An array item, a tuple
65
+ * position and a union-typed field are none. Since 0.1.198.
66
+ */
67
+ picker?: true;
60
68
  /**
61
69
  * Server-owned field: a `@db.column.derived` one (read from the type
62
70
  * metadata), a computed view column (`CreateFormDefOptions.metaFields`) or,
@@ -1,7 +1,9 @@
1
1
  const require_annotation_keys = require("../shared/annotation-keys.cjs");
2
2
  const require_types = require("./types.cjs");
3
3
  const require_ui_texts = require("../i18n/ui-texts.cjs");
4
+ const require_extract_ref = require("../value-help/extract-ref.cjs");
4
5
  const require_skipped_nav = require("./skipped-nav.cjs");
6
+ const require_create_form_def = require("./create-form-def.cjs");
5
7
  const require_error_utils = require("./error-utils.cjs");
6
8
  let _atscript_typescript_utils = require("@atscript/typescript/utils");
7
9
  let _atscript_db_validator = require("@atscript/db/validator");
@@ -57,6 +59,39 @@ const serverManagedPlugin = (ctx, def, value) => {
57
59
  if (value !== void 0) return void 0;
58
60
  return dbPlugin(Object.create(ctx, { context: { value: INSERT_CONTEXT } }), withoutFk(def), value);
59
61
  };
62
+ /**
63
+ * A required value-help picker left unpicked — absent, `null` (its ×), or `""`
64
+ * for a string foreign key (never a key; a `@ui.valueHelp` binding on a plain
65
+ * string column takes `""`, as the server does) — fails with code `REQUIRED`
66
+ * and its `@expect.message`, else the code's text ("Must not be empty"), as
67
+ * `@meta.required` reports a missing value (a number field may not carry
68
+ * `@meta.required`). A `@meta.required` field keeps the validator's own rule
69
+ * (its message).
70
+ *
71
+ * Only for `pickers`: the props of the fields the form renders as a picker
72
+ * ({@link collectPickerProps}, or the per-field validator's own `picker`
73
+ * prop) — not an array item, a tuple position or a union branch, which keep
74
+ * the validation they had.
75
+ *
76
+ * Listed last, as the validator checks `@meta.required` after its plugins: an
77
+ * absent FK the database fills passes first ({@link serverManagedPlugin}), and
78
+ * a field's own `@ui.form.validate` words its error.
79
+ */
80
+ function missingPickPlugin(pickers) {
81
+ return (ctx, def, value) => {
82
+ if (value !== void 0 && value !== null && value !== "") return void 0;
83
+ if (!pickers.has(def) || def.optional || def.metadata.has("meta.required")) return void 0;
84
+ if (value === "") {
85
+ if (!(def.type.designType === "string") || !require_extract_ref.isForeignKey(def)) return void 0;
86
+ }
87
+ const custom = def.metadata.get(require_annotation_keys.EXPECT_MESSAGE);
88
+ ctx.error(custom || _atscript_typescript_utils.VALIDATOR_MESSAGES.REQUIRED, void 0, void 0, {
89
+ code: "REQUIRED",
90
+ custom: !!custom
91
+ });
92
+ return false;
93
+ };
94
+ }
60
95
  /** A view of `def` without its `@db.rel.FK` marker — `def` itself when it has none. */
61
96
  function withoutFk(def) {
62
97
  if (!def.metadata.has("db.rel.FK")) return def;
@@ -72,27 +107,68 @@ function withoutFk(def) {
72
107
  * it is not derived (an interface's stamp below a union of several types, too)
73
108
  * stays validated. A recursive type's def graph is cyclic: each field def is
74
109
  * visited once.
110
+ *
111
+ * Each field's prop is read from `def.type`, the type the validator walks,
112
+ * along the field's path — not from the field def: a def a Vue form holds
113
+ * reactive hands out proxies of the props of a compiled type, which the
114
+ * validator visits raw (fixed in 0.1.198).
75
115
  */
76
116
  function collectDerivedProps(def) {
77
117
  const derived = /* @__PURE__ */ new Set();
78
118
  const kept = /* @__PURE__ */ new Set();
79
119
  const seen = /* @__PURE__ */ new Set();
80
- const walk = (fields) => {
120
+ const walkFields = (fields, type) => {
81
121
  for (const field of fields) {
82
- if (seen.has(field)) continue;
83
- seen.add(field);
84
- if (field.derived) {
85
- derived.add(field.prop);
86
- continue;
87
- }
88
- kept.add(field.prop);
89
- walk(require_types.childFields(field));
122
+ const prop = field.path === "" ? type : type.type.kind === "object" ? require_create_form_def.resolveOriginalProp(type, field.path) : void 0;
123
+ if (prop) walkField(field, prop);
90
124
  }
91
125
  };
92
- walk(def.fields);
126
+ const walkField = (field, prop) => {
127
+ if (seen.has(field)) return;
128
+ seen.add(field);
129
+ if (field.derived) {
130
+ derived.add(prop);
131
+ return;
132
+ }
133
+ kept.add(prop);
134
+ if (require_types.isObjectField(field)) return walkFields(field.objectDef.fields, prop);
135
+ if (require_types.isArrayField(field)) return walkField(field.itemField, prop.type.of);
136
+ const items = prop.type.items ?? [prop];
137
+ if (require_types.isTupleField(field)) field.itemFields.forEach((f, i) => walkField(f, items[i] ?? prop));
138
+ else if (require_types.isUnionField(field)) field.unionVariants.forEach((v, i) => {
139
+ const item = items[i] ?? prop;
140
+ if (v.def) walkFields(v.def.fields, item);
141
+ if (v.itemField) walkField(v.itemField, item);
142
+ });
143
+ };
144
+ walkFields(def.fields, def.type);
93
145
  for (const prop of kept) derived.delete(prop);
94
146
  return derived;
95
147
  }
148
+ /**
149
+ * The props of the fields the form renders as a value-help picker
150
+ * ({@link FormFieldDef.picker}): every object property of `type` at any depth
151
+ * (a nested object, an object row of an array, a union's object variant) that
152
+ * {@link isValueHelpPicker} accepts — not an array item, a tuple position or a
153
+ * union branch. Read from the type the validator walks, so the props are the
154
+ * nodes it visits: a def a Vue form holds reactive hands out proxies of them.
155
+ * A recursive type is visited once per node.
156
+ */
157
+ function collectPickerProps(type) {
158
+ const pickers = /* @__PURE__ */ new Set();
159
+ const seen = /* @__PURE__ */ new Set();
160
+ const walk = (node) => {
161
+ if (seen.has(node)) return;
162
+ seen.add(node);
163
+ const t = node.type;
164
+ if (t.kind === "object") for (const prop of t.props.values()) if (require_extract_ref.isValueHelpPicker(prop)) pickers.add(prop);
165
+ else walk(prop);
166
+ else if (t.kind === "array") walk(t.of);
167
+ else if (t.kind !== "") for (const item of t.items) walk(item);
168
+ };
169
+ walk(type);
170
+ return pickers;
171
+ }
96
172
  let defaultValidatorPlugins = [];
97
173
  /** Replace the default validator plugins applied to every form/field validator. */
98
174
  function setDefaultValidatorPlugins(plugins) {
@@ -120,6 +196,7 @@ function getDefaultValidatorPlugins() {
120
196
  function getFormValidator(def, opts) {
121
197
  const derived = collectDerivedProps(def);
122
198
  const derivedPlugin = (_ctx, prop) => derived.has(prop) ? true : void 0;
199
+ const pickers = collectPickerProps(def.type);
123
200
  const options = {
124
201
  unknownProps: "ignore",
125
202
  ...opts,
@@ -127,7 +204,8 @@ function getFormValidator(def, opts) {
127
204
  ...derived.size > 0 ? [derivedPlugin] : [],
128
205
  serverManagedPlugin,
129
206
  ...defaultValidatorPlugins,
130
- ...opts?.plugins ?? []
207
+ ...opts?.plugins ?? [],
208
+ ...pickers.size > 0 ? [missingPickPlugin(pickers)] : []
131
209
  ]
132
210
  };
133
211
  const validator = new _atscript_typescript_utils.Validator(def.type, options);
@@ -186,7 +264,11 @@ function createFieldValidator(prop, opts) {
186
264
  skipDescendantsPlugin,
187
265
  serverManagedPlugin,
188
266
  ...defaultValidatorPlugins
189
- ] : [serverManagedPlugin, ...defaultValidatorPlugins] };
267
+ ] : [
268
+ serverManagedPlugin,
269
+ ...defaultValidatorPlugins,
270
+ ...opts?.picker ? [missingPickPlugin(new Set([prop]))] : []
271
+ ] };
190
272
  cached = new _atscript_typescript_utils.Validator(prop, options);
191
273
  }
192
274
  const judged = skipNormalize ? value : (0, _atscript_typescript_utils.normalizeForType)(prop, value, options);
@@ -63,6 +63,12 @@ interface TFieldValidatorOptions {
63
63
  * own annotations are then not looked up as ids again. Codes are still translated.
64
64
  */
65
65
  served?: () => boolean;
66
+ /**
67
+ * The prop is a field the form renders as a value-help picker
68
+ * ({@link FormFieldDef.picker}): left unpicked, a required one fails with
69
+ * code `REQUIRED`, as the form validator reports it. Since 0.1.198.
70
+ */
71
+ picker?: boolean;
66
72
  }
67
73
  /**
68
74
  * Whether a type kind is a container that carries its own children:
@@ -63,6 +63,12 @@ interface TFieldValidatorOptions {
63
63
  * own annotations are then not looked up as ids again. Codes are still translated.
64
64
  */
65
65
  served?: () => boolean;
66
+ /**
67
+ * The prop is a field the form renders as a value-help picker
68
+ * ({@link FormFieldDef.picker}): left unpicked, a required one fails with
69
+ * code `REQUIRED`, as the form validator reports it. Since 0.1.198.
70
+ */
71
+ picker?: boolean;
66
72
  }
67
73
  /**
68
74
  * Whether a type kind is a container that carries its own children:
@@ -1,9 +1,11 @@
1
- import { DB_REL_FK } from "../shared/annotation-keys.mjs";
2
- import { childFields } from "./types.mjs";
1
+ import { DB_REL_FK, EXPECT_MESSAGE } from "../shared/annotation-keys.mjs";
2
+ import { isArrayField, isObjectField, isTupleField, isUnionField } from "./types.mjs";
3
3
  import { getUiTexts } from "../i18n/ui-texts.mjs";
4
+ import { isForeignKey, isValueHelpPicker } from "../value-help/extract-ref.mjs";
4
5
  import { isSkippedNavField } from "./skipped-nav.mjs";
6
+ import { resolveOriginalProp } from "./create-form-def.mjs";
5
7
  import { validatorErrorsToMap } from "./error-utils.mjs";
6
- import { Validator, localizeErrors, normalizeForType } from "@atscript/typescript/utils";
8
+ import { VALIDATOR_MESSAGES, Validator, localizeErrors, normalizeForType } from "@atscript/typescript/utils";
7
9
  import { createDbValidatorPlugin } from "@atscript/db/validator";
8
10
  //#region src/form/validate.ts
9
11
  /**
@@ -57,6 +59,39 @@ const serverManagedPlugin = (ctx, def, value) => {
57
59
  if (value !== void 0) return void 0;
58
60
  return dbPlugin(Object.create(ctx, { context: { value: INSERT_CONTEXT } }), withoutFk(def), value);
59
61
  };
62
+ /**
63
+ * A required value-help picker left unpicked — absent, `null` (its ×), or `""`
64
+ * for a string foreign key (never a key; a `@ui.valueHelp` binding on a plain
65
+ * string column takes `""`, as the server does) — fails with code `REQUIRED`
66
+ * and its `@expect.message`, else the code's text ("Must not be empty"), as
67
+ * `@meta.required` reports a missing value (a number field may not carry
68
+ * `@meta.required`). A `@meta.required` field keeps the validator's own rule
69
+ * (its message).
70
+ *
71
+ * Only for `pickers`: the props of the fields the form renders as a picker
72
+ * ({@link collectPickerProps}, or the per-field validator's own `picker`
73
+ * prop) — not an array item, a tuple position or a union branch, which keep
74
+ * the validation they had.
75
+ *
76
+ * Listed last, as the validator checks `@meta.required` after its plugins: an
77
+ * absent FK the database fills passes first ({@link serverManagedPlugin}), and
78
+ * a field's own `@ui.form.validate` words its error.
79
+ */
80
+ function missingPickPlugin(pickers) {
81
+ return (ctx, def, value) => {
82
+ if (value !== void 0 && value !== null && value !== "") return void 0;
83
+ if (!pickers.has(def) || def.optional || def.metadata.has("meta.required")) return void 0;
84
+ if (value === "") {
85
+ if (!(def.type.designType === "string") || !isForeignKey(def)) return void 0;
86
+ }
87
+ const custom = def.metadata.get(EXPECT_MESSAGE);
88
+ ctx.error(custom || VALIDATOR_MESSAGES.REQUIRED, void 0, void 0, {
89
+ code: "REQUIRED",
90
+ custom: !!custom
91
+ });
92
+ return false;
93
+ };
94
+ }
60
95
  /** A view of `def` without its `@db.rel.FK` marker — `def` itself when it has none. */
61
96
  function withoutFk(def) {
62
97
  if (!def.metadata.has("db.rel.FK")) return def;
@@ -72,27 +107,68 @@ function withoutFk(def) {
72
107
  * it is not derived (an interface's stamp below a union of several types, too)
73
108
  * stays validated. A recursive type's def graph is cyclic: each field def is
74
109
  * visited once.
110
+ *
111
+ * Each field's prop is read from `def.type`, the type the validator walks,
112
+ * along the field's path — not from the field def: a def a Vue form holds
113
+ * reactive hands out proxies of the props of a compiled type, which the
114
+ * validator visits raw (fixed in 0.1.198).
75
115
  */
76
116
  function collectDerivedProps(def) {
77
117
  const derived = /* @__PURE__ */ new Set();
78
118
  const kept = /* @__PURE__ */ new Set();
79
119
  const seen = /* @__PURE__ */ new Set();
80
- const walk = (fields) => {
120
+ const walkFields = (fields, type) => {
81
121
  for (const field of fields) {
82
- if (seen.has(field)) continue;
83
- seen.add(field);
84
- if (field.derived) {
85
- derived.add(field.prop);
86
- continue;
87
- }
88
- kept.add(field.prop);
89
- walk(childFields(field));
122
+ const prop = field.path === "" ? type : type.type.kind === "object" ? resolveOriginalProp(type, field.path) : void 0;
123
+ if (prop) walkField(field, prop);
90
124
  }
91
125
  };
92
- walk(def.fields);
126
+ const walkField = (field, prop) => {
127
+ if (seen.has(field)) return;
128
+ seen.add(field);
129
+ if (field.derived) {
130
+ derived.add(prop);
131
+ return;
132
+ }
133
+ kept.add(prop);
134
+ if (isObjectField(field)) return walkFields(field.objectDef.fields, prop);
135
+ if (isArrayField(field)) return walkField(field.itemField, prop.type.of);
136
+ const items = prop.type.items ?? [prop];
137
+ if (isTupleField(field)) field.itemFields.forEach((f, i) => walkField(f, items[i] ?? prop));
138
+ else if (isUnionField(field)) field.unionVariants.forEach((v, i) => {
139
+ const item = items[i] ?? prop;
140
+ if (v.def) walkFields(v.def.fields, item);
141
+ if (v.itemField) walkField(v.itemField, item);
142
+ });
143
+ };
144
+ walkFields(def.fields, def.type);
93
145
  for (const prop of kept) derived.delete(prop);
94
146
  return derived;
95
147
  }
148
+ /**
149
+ * The props of the fields the form renders as a value-help picker
150
+ * ({@link FormFieldDef.picker}): every object property of `type` at any depth
151
+ * (a nested object, an object row of an array, a union's object variant) that
152
+ * {@link isValueHelpPicker} accepts — not an array item, a tuple position or a
153
+ * union branch. Read from the type the validator walks, so the props are the
154
+ * nodes it visits: a def a Vue form holds reactive hands out proxies of them.
155
+ * A recursive type is visited once per node.
156
+ */
157
+ function collectPickerProps(type) {
158
+ const pickers = /* @__PURE__ */ new Set();
159
+ const seen = /* @__PURE__ */ new Set();
160
+ const walk = (node) => {
161
+ if (seen.has(node)) return;
162
+ seen.add(node);
163
+ const t = node.type;
164
+ if (t.kind === "object") for (const prop of t.props.values()) if (isValueHelpPicker(prop)) pickers.add(prop);
165
+ else walk(prop);
166
+ else if (t.kind === "array") walk(t.of);
167
+ else if (t.kind !== "") for (const item of t.items) walk(item);
168
+ };
169
+ walk(type);
170
+ return pickers;
171
+ }
96
172
  let defaultValidatorPlugins = [];
97
173
  /** Replace the default validator plugins applied to every form/field validator. */
98
174
  function setDefaultValidatorPlugins(plugins) {
@@ -120,6 +196,7 @@ function getDefaultValidatorPlugins() {
120
196
  function getFormValidator(def, opts) {
121
197
  const derived = collectDerivedProps(def);
122
198
  const derivedPlugin = (_ctx, prop) => derived.has(prop) ? true : void 0;
199
+ const pickers = collectPickerProps(def.type);
123
200
  const options = {
124
201
  unknownProps: "ignore",
125
202
  ...opts,
@@ -127,7 +204,8 @@ function getFormValidator(def, opts) {
127
204
  ...derived.size > 0 ? [derivedPlugin] : [],
128
205
  serverManagedPlugin,
129
206
  ...defaultValidatorPlugins,
130
- ...opts?.plugins ?? []
207
+ ...opts?.plugins ?? [],
208
+ ...pickers.size > 0 ? [missingPickPlugin(pickers)] : []
131
209
  ]
132
210
  };
133
211
  const validator = new Validator(def.type, options);
@@ -186,7 +264,11 @@ function createFieldValidator(prop, opts) {
186
264
  skipDescendantsPlugin,
187
265
  serverManagedPlugin,
188
266
  ...defaultValidatorPlugins
189
- ] : [serverManagedPlugin, ...defaultValidatorPlugins] };
267
+ ] : [
268
+ serverManagedPlugin,
269
+ ...defaultValidatorPlugins,
270
+ ...opts?.picker ? [missingPickPlugin(new Set([prop]))] : []
271
+ ] };
190
272
  cached = new Validator(prop, options);
191
273
  }
192
274
  const judged = skipNormalize ? value : normalizeForType(prop, value, options);
@@ -77,6 +77,7 @@ const META_REQUIRED = "meta.required";
77
77
  const META_DEFAULT = "meta.default";
78
78
  const META_SENSITIVE = "meta.sensitive";
79
79
  const EXPECT_MAX_LENGTH = "expect.maxLength";
80
+ const EXPECT_MESSAGE = "expect.message";
80
81
  const EXPECT_ARRAY_KEY = "expect.array.key";
81
82
  const EXPECT_ARRAY_UNIQUE_ITEMS = "expect.array.uniqueItems";
82
83
  const UI_FORM_FN_PREFIX = "ui.form.fn.";
@@ -119,6 +120,7 @@ exports.DB_VIEW_FOR = DB_VIEW_FOR;
119
120
  exports.EXPECT_ARRAY_KEY = EXPECT_ARRAY_KEY;
120
121
  exports.EXPECT_ARRAY_UNIQUE_ITEMS = EXPECT_ARRAY_UNIQUE_ITEMS;
121
122
  exports.EXPECT_MAX_LENGTH = EXPECT_MAX_LENGTH;
123
+ exports.EXPECT_MESSAGE = EXPECT_MESSAGE;
122
124
  exports.META_DEFAULT = META_DEFAULT;
123
125
  exports.META_DESCRIPTION = META_DESCRIPTION;
124
126
  exports.META_ID = META_ID;
@@ -77,6 +77,7 @@ const META_REQUIRED = "meta.required";
77
77
  const META_DEFAULT = "meta.default";
78
78
  const META_SENSITIVE = "meta.sensitive";
79
79
  const EXPECT_MAX_LENGTH = "expect.maxLength";
80
+ const EXPECT_MESSAGE = "expect.message";
80
81
  const EXPECT_ARRAY_KEY = "expect.array.key";
81
82
  const EXPECT_ARRAY_UNIQUE_ITEMS = "expect.array.uniqueItems";
82
83
  const UI_FORM_FN_PREFIX = "ui.form.fn.";
@@ -101,4 +102,4 @@ const UI_TABLE_FN_CLASSES = "ui.table.fn.classes";
101
102
  const UI_TABLE_FN_STYLES = "ui.table.fn.styles";
102
103
  const UI_FORM_VALIDATE = "ui.form.validate";
103
104
  //#endregion
104
- 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, 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_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 };
105
+ 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_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 };
@@ -113,5 +113,41 @@ function extractValueHelp(prop) {
113
113
  node = (target.type.kind === "object" ? target.type : void 0)?.props.get(ref.field);
114
114
  }
115
115
  }
116
+ /** Field types that still pick from the value help: the picker, a dropdown or radio group of the dictionary. */
117
+ const PICKER_TYPES = new Set([
118
+ "ref",
119
+ "select",
120
+ "radio"
121
+ ]);
122
+ /**
123
+ * Whether the form renders `prop` as a value-help picker: a scalar with a value
124
+ * help ({@link extractValueHelp}) whose `@ui.form.type` / `@ui.type`, if any,
125
+ * still picks from it (`tags` edits an array only, so a scalar ignores it) —
126
+ * or that names its own component (`@ui.form.component`, which wins over the
127
+ * type: a custom picker). Any other type, a custom type name included, makes a
128
+ * plain field (an FK typed `text`). A union-typed field renders as a union or a
129
+ * select instead.
130
+ */
131
+ function isValueHelpPicker(prop) {
132
+ if (prop.type.kind !== "" || extractValueHelp(prop) === void 0) return false;
133
+ if (prop.metadata.has("ui.form.component")) return true;
134
+ const declared = prop.metadata.get("ui.form.type") ?? prop.metadata.get("ui.type");
135
+ return declared === void 0 || declared === "tags" || PICKER_TYPES.has(declared);
136
+ }
137
+ /**
138
+ * Whether `prop` holds a foreign key: it carries `@db.rel.FK`, or references a
139
+ * field that does (a reference chain, as {@link extractValueHelp} walks it).
140
+ */
141
+ function isForeignKey(prop) {
142
+ let node = prop;
143
+ for (let depth = 0; node && depth < MAX_REF_CHAIN_DEPTH; depth++) {
144
+ if (node.metadata.has("db.rel.FK")) return true;
145
+ const target = node.ref?.type();
146
+ node = target?.type.kind === "object" ? target.type.props.get(node.ref.field) : void 0;
147
+ }
148
+ return false;
149
+ }
116
150
  //#endregion
117
151
  exports.extractValueHelp = extractValueHelp;
152
+ exports.isForeignKey = isForeignKey;
153
+ exports.isValueHelpPicker = isValueHelpPicker;
@@ -113,5 +113,39 @@ function extractValueHelp(prop) {
113
113
  node = (target.type.kind === "object" ? target.type : void 0)?.props.get(ref.field);
114
114
  }
115
115
  }
116
+ /** Field types that still pick from the value help: the picker, a dropdown or radio group of the dictionary. */
117
+ const PICKER_TYPES = new Set([
118
+ "ref",
119
+ "select",
120
+ "radio"
121
+ ]);
122
+ /**
123
+ * Whether the form renders `prop` as a value-help picker: a scalar with a value
124
+ * help ({@link extractValueHelp}) whose `@ui.form.type` / `@ui.type`, if any,
125
+ * still picks from it (`tags` edits an array only, so a scalar ignores it) —
126
+ * or that names its own component (`@ui.form.component`, which wins over the
127
+ * type: a custom picker). Any other type, a custom type name included, makes a
128
+ * plain field (an FK typed `text`). A union-typed field renders as a union or a
129
+ * select instead.
130
+ */
131
+ function isValueHelpPicker(prop) {
132
+ if (prop.type.kind !== "" || extractValueHelp(prop) === void 0) return false;
133
+ if (prop.metadata.has("ui.form.component")) return true;
134
+ const declared = prop.metadata.get("ui.form.type") ?? prop.metadata.get("ui.type");
135
+ return declared === void 0 || declared === "tags" || PICKER_TYPES.has(declared);
136
+ }
137
+ /**
138
+ * Whether `prop` holds a foreign key: it carries `@db.rel.FK`, or references a
139
+ * field that does (a reference chain, as {@link extractValueHelp} walks it).
140
+ */
141
+ function isForeignKey(prop) {
142
+ let node = prop;
143
+ for (let depth = 0; node && depth < MAX_REF_CHAIN_DEPTH; depth++) {
144
+ if (node.metadata.has("db.rel.FK")) return true;
145
+ const target = node.ref?.type();
146
+ node = target?.type.kind === "object" ? target.type.props.get(node.ref.field) : void 0;
147
+ }
148
+ return false;
149
+ }
116
150
  //#endregion
117
- export { extractValueHelp };
151
+ export { extractValueHelp, isForeignKey, isValueHelpPicker };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/ui",
3
- "version": "0.1.197",
3
+ "version": "0.1.198",
4
4
  "description": "Framework-agnostic runtime for form and table definitions from atscript annotated types",
5
5
  "keywords": [
6
6
  "annotations",