@atscript/ui 0.1.143 → 0.1.144
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/index.cjs +34 -9
- package/dist/index.d.cts +28 -8
- package/dist/index.d.mts +28 -8
- package/dist/index.mjs +34 -9
- package/package.json +9 -8
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
let _atscript_typescript_utils = require("@atscript/typescript/utils");
|
|
3
3
|
let _atscript_db_client = require("@atscript/db-client");
|
|
4
|
+
let _atscript_db_validator = require("@atscript/db/validator");
|
|
4
5
|
//#region src/shared/annotation-keys.ts
|
|
5
6
|
const UI_TYPE = "ui.type";
|
|
6
7
|
const UI_FORM_PLACEHOLDER = "ui.form.placeholder";
|
|
@@ -335,9 +336,7 @@ const UI_TAGS = new Set([
|
|
|
335
336
|
* - **Non-object types** (primitive, array, union, etc.): produces a single leaf root field
|
|
336
337
|
* with `path: ''`.
|
|
337
338
|
*
|
|
338
|
-
*
|
|
339
|
-
* exclude from `fields[]` (it stays in `flatMap` so the wire payload is
|
|
340
|
-
* unchanged). Root-table concept; not propagated into nested recursive calls.
|
|
339
|
+
* A `@db.column.derived` field is marked `derived` straight from its metadata.
|
|
341
340
|
*/
|
|
342
341
|
function createFormDef(type, opts) {
|
|
343
342
|
if (type.type.kind !== "object") {
|
|
@@ -412,7 +411,8 @@ function createFieldDef(path, prop) {
|
|
|
412
411
|
name,
|
|
413
412
|
allStatic,
|
|
414
413
|
pushDown,
|
|
415
|
-
valueHelpInfo
|
|
414
|
+
valueHelpInfo,
|
|
415
|
+
...getFieldMeta(prop, "db.column.derived") !== void 0 && { derived: true }
|
|
416
416
|
};
|
|
417
417
|
const customType = uiType;
|
|
418
418
|
if (kind === "array") {
|
|
@@ -1055,6 +1055,27 @@ function deepClone(value, unwrap) {
|
|
|
1055
1055
|
}
|
|
1056
1056
|
//#endregion
|
|
1057
1057
|
//#region src/form/validate.ts
|
|
1058
|
+
const dbPlugin = (0, _atscript_db_validator.createDbValidatorPlugin)();
|
|
1059
|
+
const INSERT_CONTEXT = { mode: "insert" };
|
|
1060
|
+
/**
|
|
1061
|
+
* Always-on plugin for fields the server fills in, so a create form is not
|
|
1062
|
+
* blocked on them:
|
|
1063
|
+
* - `@db.column.derived` — read-only and server-computed: never validated
|
|
1064
|
+
* (not even a loaded value, which the user could not fix).
|
|
1065
|
+
* - an absent `@db.default*` / `@db.column.version` value — delegated to
|
|
1066
|
+
* `@atscript/db`'s own insert-mode rule, so the key list has one owner.
|
|
1067
|
+
* `db.rel.FK` is kept out: a form fills the FK itself (no nested nav
|
|
1068
|
+
* object), so an empty required FK must still fail.
|
|
1069
|
+
*
|
|
1070
|
+
* The db plugin reads its mode from the validation context, which here
|
|
1071
|
+
* carries the form's `{ data, context }` — it gets a view of `ctx` with the
|
|
1072
|
+
* insert context instead.
|
|
1073
|
+
*/
|
|
1074
|
+
const serverManagedPlugin = (ctx, def, value) => {
|
|
1075
|
+
if (def.metadata.has("db.column.derived")) return true;
|
|
1076
|
+
if (value !== void 0 || def.metadata.has("db.rel.FK")) return void 0;
|
|
1077
|
+
return dbPlugin(Object.create(ctx, { context: { value: INSERT_CONTEXT } }), def, value);
|
|
1078
|
+
};
|
|
1058
1079
|
let defaultValidatorPlugins = [];
|
|
1059
1080
|
/** Replace the default validator plugins applied to every form/field validator. */
|
|
1060
1081
|
function setDefaultValidatorPlugins(plugins) {
|
|
@@ -1068,14 +1089,19 @@ function getDefaultValidatorPlugins() {
|
|
|
1068
1089
|
* Returns a reusable validator function for a whole FormDef.
|
|
1069
1090
|
*
|
|
1070
1091
|
* Validator is created once and reused on every call.
|
|
1071
|
-
* ATScript's @expect.* validation runs automatically
|
|
1092
|
+
* ATScript's @expect.* validation runs automatically; server-managed db
|
|
1093
|
+
* fields (`@db.column.derived`, absent `@db.default*` / version) pass.
|
|
1072
1094
|
* For custom `ui.fn.*` validators, install ui-fns and pass its plugin via `opts.plugins`.
|
|
1073
1095
|
*/
|
|
1074
1096
|
function getFormValidator(def, opts) {
|
|
1075
1097
|
const validator = new _atscript_typescript_utils.Validator(def.type, {
|
|
1076
1098
|
unknownProps: "ignore",
|
|
1077
1099
|
...opts,
|
|
1078
|
-
plugins: [
|
|
1100
|
+
plugins: [
|
|
1101
|
+
serverManagedPlugin,
|
|
1102
|
+
...defaultValidatorPlugins,
|
|
1103
|
+
...opts?.plugins ?? []
|
|
1104
|
+
]
|
|
1079
1105
|
});
|
|
1080
1106
|
return (callOpts) => {
|
|
1081
1107
|
if (validator.validate(callOpts.data, true, {
|
|
@@ -1096,7 +1122,7 @@ function getFormValidator(def, opts) {
|
|
|
1096
1122
|
function createFieldValidator(prop, opts) {
|
|
1097
1123
|
let cached;
|
|
1098
1124
|
return (value, externalCtx) => {
|
|
1099
|
-
cached ??= new _atscript_typescript_utils.Validator(prop, { plugins: defaultValidatorPlugins });
|
|
1125
|
+
cached ??= new _atscript_typescript_utils.Validator(prop, { plugins: [serverManagedPlugin, ...defaultValidatorPlugins] });
|
|
1100
1126
|
if (!cached.validate(value, true, externalCtx)) {
|
|
1101
1127
|
if (opts?.rootOnly) {
|
|
1102
1128
|
const rootError = cached.errors?.find((e) => e.path === "");
|
|
@@ -1165,8 +1191,7 @@ function diffFields(fields, prefix, baseline, current, changes, patch, versionCo
|
|
|
1165
1191
|
diffLeafRoot(field, baseline, current, changes, patch);
|
|
1166
1192
|
continue;
|
|
1167
1193
|
}
|
|
1168
|
-
if (field.phantom) continue;
|
|
1169
|
-
if (versionColumn !== void 0 && !prefix && field.path === versionColumn) continue;
|
|
1194
|
+
if (field.phantom || field.derived || versionColumn !== void 0 && !prefix && field.path === versionColumn) continue;
|
|
1170
1195
|
const fullPath = prefix ? `${prefix}.${field.path}` : field.path;
|
|
1171
1196
|
if (isArrayField(field)) {
|
|
1172
1197
|
diffArrayField(field, fullPath, baseline, current, changes, patch);
|
package/dist/index.d.cts
CHANGED
|
@@ -160,6 +160,12 @@ interface FormFieldDef {
|
|
|
160
160
|
* the component layer.
|
|
161
161
|
*/
|
|
162
162
|
valueHelpInfo?: ValueHelpInfo;
|
|
163
|
+
/**
|
|
164
|
+
* Server-computed `@db.column.derived` field, read from the type metadata.
|
|
165
|
+
* Rendered read-only, exempt from form validation and never sent by
|
|
166
|
+
* `buildFormDiff` (the server drops a written value anyway). Since 0.1.144.
|
|
167
|
+
*/
|
|
168
|
+
derived?: true;
|
|
163
169
|
}
|
|
164
170
|
/**
|
|
165
171
|
* Complete form definition — produced by createFormDef().
|
|
@@ -226,6 +232,16 @@ declare function isUnionField(field: FormFieldDef): field is FormUnionFieldDef;
|
|
|
226
232
|
declare function isTupleField(field: FormFieldDef): field is FormTupleFieldDef;
|
|
227
233
|
//#endregion
|
|
228
234
|
//#region src/form/create-form-def.d.ts
|
|
235
|
+
/** Options for {@link createFormDef}. */
|
|
236
|
+
interface CreateFormDefOptions {
|
|
237
|
+
/**
|
|
238
|
+
* `meta.versionColumn` — the server-managed OCC version field (its LOGICAL
|
|
239
|
+
* name; a `@db.column` rename changes only the storage column). Excluded
|
|
240
|
+
* from `fields[]`; it stays in `flatMap` so the wire payload is unchanged.
|
|
241
|
+
* Root-table concept; not propagated into nested recursive calls.
|
|
242
|
+
*/
|
|
243
|
+
versionColumn?: string;
|
|
244
|
+
}
|
|
229
245
|
/**
|
|
230
246
|
* Converts an ATScript annotated type into a FormDef.
|
|
231
247
|
*
|
|
@@ -233,13 +249,9 @@ declare function isTupleField(field: FormFieldDef): field is FormTupleFieldDef;
|
|
|
233
249
|
* - **Non-object types** (primitive, array, union, etc.): produces a single leaf root field
|
|
234
250
|
* with `path: ''`.
|
|
235
251
|
*
|
|
236
|
-
*
|
|
237
|
-
* exclude from `fields[]` (it stays in `flatMap` so the wire payload is
|
|
238
|
-
* unchanged). Root-table concept; not propagated into nested recursive calls.
|
|
252
|
+
* A `@db.column.derived` field is marked `derived` straight from its metadata.
|
|
239
253
|
*/
|
|
240
|
-
declare function createFormDef(type: TAtscriptAnnotatedType, opts?:
|
|
241
|
-
versionColumn?: string;
|
|
242
|
-
}): FormDef;
|
|
254
|
+
declare function createFormDef(type: TAtscriptAnnotatedType, opts?: CreateFormDefOptions): FormDef;
|
|
243
255
|
/**
|
|
244
256
|
* Builds union variant definitions from a union annotated type.
|
|
245
257
|
* Iterates top-level items directly — one variant per item.
|
|
@@ -548,7 +560,8 @@ declare function getDefaultValidatorPlugins(): TValidatorPlugin[];
|
|
|
548
560
|
* Returns a reusable validator function for a whole FormDef.
|
|
549
561
|
*
|
|
550
562
|
* Validator is created once and reused on every call.
|
|
551
|
-
* ATScript's @expect.* validation runs automatically
|
|
563
|
+
* ATScript's @expect.* validation runs automatically; server-managed db
|
|
564
|
+
* fields (`@db.column.derived`, absent `@db.default*` / version) pass.
|
|
552
565
|
* For custom `ui.fn.*` validators, install ui-fns and pass its plugin via `opts.plugins`.
|
|
553
566
|
*/
|
|
554
567
|
declare function getFormValidator(def: FormDef, opts?: Partial<TValidatorOptions>): (callOpts: TFormValidatorCallOptions) => Record<string, string>;
|
|
@@ -1035,6 +1048,13 @@ interface FieldMeta {
|
|
|
1035
1048
|
* fetchable. Since 0.1.141.
|
|
1036
1049
|
*/
|
|
1037
1050
|
writeOnly?: boolean;
|
|
1051
|
+
/**
|
|
1052
|
+
* Server-computed (`@db.column.derived`, `@atscript/db` 0.1.141+): filterable
|
|
1053
|
+
* and sortable like any column, but a value written to it is dropped. Forms
|
|
1054
|
+
* read the annotation from the type itself (`FormFieldDef.derived`).
|
|
1055
|
+
* Since 0.1.144.
|
|
1056
|
+
*/
|
|
1057
|
+
derived?: boolean;
|
|
1038
1058
|
}
|
|
1039
1059
|
/** Meta response from moost-db `/meta` endpoint. */
|
|
1040
1060
|
interface MetaResponse {
|
|
@@ -1323,4 +1343,4 @@ interface TModelRoute {
|
|
|
1323
1343
|
*/
|
|
1324
1344
|
declare function buildModelRoutes(models: readonly TAtscriptAnnotatedType[]): TModelRoute[];
|
|
1325
1345
|
//#endregion
|
|
1326
|
-
export { type ClientFactory, type CloneUnwrap, type ColumnDef, type CurrencyDisplay, DB_AMOUNT_CURRENCY, DB_AMOUNT_CURRENCY_REF, DB_COLUMN_PRECISION, DB_HTTP_PATH, DB_REL_FK, DB_UNIT, DB_UNIT_REF, DEFAULT_COL_SPAN, DEFAULT_ROW_SPAN, type DecimalParts, EXPECT_MAX_LENGTH, type FieldMeta, type FieldResolver, type FormActionInfo, type FormArrayFieldDef, type FormDef, type FormDiffOptions, type FormDiffResult, type FormFieldChange, type FormFieldDef, type FormObjectFieldDef, type FormRebaseOptions, type FormRebaseResult, type FormTupleFieldDef, type FormUnionFieldDef, type FormUnionVariant, type FormatDecimalOptions, type GridSpanArgs, type GridSpec, META_DEFAULT, META_DESCRIPTION, META_ID, META_LABEL, META_READONLY, META_REQUIRED, META_SENSITIVE, type MeasurementInfo, type MetaCacheEntry, type MetaResponse, type PaginationControl, type RelationInfo, type ResolvedValueHelp, type SearchIndexInfo, type SortControl, StaticFieldResolver, type TCrudOp, type TCrudPermissions, type TDbActionInfo, type TDbActionIntent, type TDbActionLevel, type TDbActionProcessor, type TFieldValidatorOptions, type TFormAction, type TFormEntryOptions, type TFormValidatorCallOptions, type TFormValueResolver, type TModelRoute, type TResolveOptions, type TableActionsModel, type TableDef, type TableQueryState, 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_OPTIONS, UI_FORM_ORDER, UI_FORM_PLACEHOLDER, UI_FORM_PREFIX, UI_FORM_PREFIX_ICON, UI_FORM_PREFIX_REF, 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_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, ValueHelpClient, type ValueHelpInfo, type ValueHelpResult, type ValueHelpSearchOptions, WF_ACTION_WITH_DATA, applyFormChanges, asArray, buildDescendantErrorCounts, buildFormDiff, buildFormRebase, buildGridClasses, buildModelRoutes, buildUnionVariants, collectDirtyPaths, createFieldValidator, createFormData, createFormDef, createFormValueResolver, createTableDef, deepClone, deepEqual, defaultResolver, deleteByPath, detectUnionVariant, enforceScale, extractLiteralOptions, extractMeasurement, extractValueHelp, formatDecimalForDisplay, getByPath, getColumn, getCurrencyDecimals, getCurrencyDisplayParts, getDecimalSeparator, getDeclaredFormActions, getDefaultClientFactory, getDefaultValidatorPlugins, getFieldMeta, getFilterableColumns, getFormValidator, getMetaEntry, getResolver, getSortableColumns, getThousandsSeparator, groupInteger, hasComputedAnnotations, hasFieldMeta, isArrayField, isFieldHidden, isObjectField, isPathDirty, isPureLiteralUnion, isTupleField, isUnionField, iteratePathAncestors, joinDecimalString, joinPath, mergeErrorMaps, navigateHrefFor, omitPaths, optKey, optLabel, parseColSpan, parseDecimalInput, parseRowSpan, parseStaticAttrs, parseStaticOptions, resetDefaultClientFactory, resetMetaCache, resetValueHelpCache, resolveAttrs, resolveFieldProp, resolveFormProp, resolveGridSpec, resolveOptions, resolveSingularLabel, resolveStatic, resolveValueHelp, setByPath, setDefaultClientFactory, setDefaultValidatorPlugins, setResolver, splitDecimalString, str, unionVariantChanged, valueHelpDictPaths };
|
|
1346
|
+
export { type ClientFactory, type CloneUnwrap, type ColumnDef, type CreateFormDefOptions, type CurrencyDisplay, DB_AMOUNT_CURRENCY, DB_AMOUNT_CURRENCY_REF, DB_COLUMN_PRECISION, DB_HTTP_PATH, DB_REL_FK, DB_UNIT, DB_UNIT_REF, DEFAULT_COL_SPAN, DEFAULT_ROW_SPAN, type DecimalParts, EXPECT_MAX_LENGTH, type FieldMeta, type FieldResolver, type FormActionInfo, type FormArrayFieldDef, type FormDef, type FormDiffOptions, type FormDiffResult, type FormFieldChange, type FormFieldDef, type FormObjectFieldDef, type FormRebaseOptions, type FormRebaseResult, type FormTupleFieldDef, type FormUnionFieldDef, type FormUnionVariant, type FormatDecimalOptions, type GridSpanArgs, type GridSpec, META_DEFAULT, META_DESCRIPTION, META_ID, META_LABEL, META_READONLY, META_REQUIRED, META_SENSITIVE, type MeasurementInfo, type MetaCacheEntry, type MetaResponse, type PaginationControl, type RelationInfo, type ResolvedValueHelp, type SearchIndexInfo, type SortControl, StaticFieldResolver, type TCrudOp, type TCrudPermissions, type TDbActionInfo, type TDbActionIntent, type TDbActionLevel, type TDbActionProcessor, type TFieldValidatorOptions, type TFormAction, type TFormEntryOptions, type TFormValidatorCallOptions, type TFormValueResolver, type TModelRoute, type TResolveOptions, type TableActionsModel, type TableDef, type TableQueryState, 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_OPTIONS, UI_FORM_ORDER, UI_FORM_PLACEHOLDER, UI_FORM_PREFIX, UI_FORM_PREFIX_ICON, UI_FORM_PREFIX_REF, 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_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, ValueHelpClient, type ValueHelpInfo, type ValueHelpResult, type ValueHelpSearchOptions, WF_ACTION_WITH_DATA, applyFormChanges, asArray, buildDescendantErrorCounts, buildFormDiff, buildFormRebase, buildGridClasses, buildModelRoutes, buildUnionVariants, collectDirtyPaths, createFieldValidator, createFormData, createFormDef, createFormValueResolver, createTableDef, deepClone, deepEqual, defaultResolver, deleteByPath, detectUnionVariant, enforceScale, extractLiteralOptions, extractMeasurement, extractValueHelp, formatDecimalForDisplay, getByPath, getColumn, getCurrencyDecimals, getCurrencyDisplayParts, getDecimalSeparator, getDeclaredFormActions, getDefaultClientFactory, getDefaultValidatorPlugins, getFieldMeta, getFilterableColumns, getFormValidator, getMetaEntry, getResolver, getSortableColumns, getThousandsSeparator, groupInteger, hasComputedAnnotations, hasFieldMeta, isArrayField, isFieldHidden, isObjectField, isPathDirty, isPureLiteralUnion, isTupleField, isUnionField, iteratePathAncestors, joinDecimalString, joinPath, mergeErrorMaps, navigateHrefFor, omitPaths, optKey, optLabel, parseColSpan, parseDecimalInput, parseRowSpan, parseStaticAttrs, parseStaticOptions, resetDefaultClientFactory, resetMetaCache, resetValueHelpCache, resolveAttrs, resolveFieldProp, resolveFormProp, resolveGridSpec, resolveOptions, resolveSingularLabel, resolveStatic, resolveValueHelp, setByPath, setDefaultClientFactory, setDefaultValidatorPlugins, setResolver, splitDecimalString, str, unionVariantChanged, valueHelpDictPaths };
|
package/dist/index.d.mts
CHANGED
|
@@ -160,6 +160,12 @@ interface FormFieldDef {
|
|
|
160
160
|
* the component layer.
|
|
161
161
|
*/
|
|
162
162
|
valueHelpInfo?: ValueHelpInfo;
|
|
163
|
+
/**
|
|
164
|
+
* Server-computed `@db.column.derived` field, read from the type metadata.
|
|
165
|
+
* Rendered read-only, exempt from form validation and never sent by
|
|
166
|
+
* `buildFormDiff` (the server drops a written value anyway). Since 0.1.144.
|
|
167
|
+
*/
|
|
168
|
+
derived?: true;
|
|
163
169
|
}
|
|
164
170
|
/**
|
|
165
171
|
* Complete form definition — produced by createFormDef().
|
|
@@ -226,6 +232,16 @@ declare function isUnionField(field: FormFieldDef): field is FormUnionFieldDef;
|
|
|
226
232
|
declare function isTupleField(field: FormFieldDef): field is FormTupleFieldDef;
|
|
227
233
|
//#endregion
|
|
228
234
|
//#region src/form/create-form-def.d.ts
|
|
235
|
+
/** Options for {@link createFormDef}. */
|
|
236
|
+
interface CreateFormDefOptions {
|
|
237
|
+
/**
|
|
238
|
+
* `meta.versionColumn` — the server-managed OCC version field (its LOGICAL
|
|
239
|
+
* name; a `@db.column` rename changes only the storage column). Excluded
|
|
240
|
+
* from `fields[]`; it stays in `flatMap` so the wire payload is unchanged.
|
|
241
|
+
* Root-table concept; not propagated into nested recursive calls.
|
|
242
|
+
*/
|
|
243
|
+
versionColumn?: string;
|
|
244
|
+
}
|
|
229
245
|
/**
|
|
230
246
|
* Converts an ATScript annotated type into a FormDef.
|
|
231
247
|
*
|
|
@@ -233,13 +249,9 @@ declare function isTupleField(field: FormFieldDef): field is FormTupleFieldDef;
|
|
|
233
249
|
* - **Non-object types** (primitive, array, union, etc.): produces a single leaf root field
|
|
234
250
|
* with `path: ''`.
|
|
235
251
|
*
|
|
236
|
-
*
|
|
237
|
-
* exclude from `fields[]` (it stays in `flatMap` so the wire payload is
|
|
238
|
-
* unchanged). Root-table concept; not propagated into nested recursive calls.
|
|
252
|
+
* A `@db.column.derived` field is marked `derived` straight from its metadata.
|
|
239
253
|
*/
|
|
240
|
-
declare function createFormDef(type: TAtscriptAnnotatedType, opts?:
|
|
241
|
-
versionColumn?: string;
|
|
242
|
-
}): FormDef;
|
|
254
|
+
declare function createFormDef(type: TAtscriptAnnotatedType, opts?: CreateFormDefOptions): FormDef;
|
|
243
255
|
/**
|
|
244
256
|
* Builds union variant definitions from a union annotated type.
|
|
245
257
|
* Iterates top-level items directly — one variant per item.
|
|
@@ -548,7 +560,8 @@ declare function getDefaultValidatorPlugins(): TValidatorPlugin[];
|
|
|
548
560
|
* Returns a reusable validator function for a whole FormDef.
|
|
549
561
|
*
|
|
550
562
|
* Validator is created once and reused on every call.
|
|
551
|
-
* ATScript's @expect.* validation runs automatically
|
|
563
|
+
* ATScript's @expect.* validation runs automatically; server-managed db
|
|
564
|
+
* fields (`@db.column.derived`, absent `@db.default*` / version) pass.
|
|
552
565
|
* For custom `ui.fn.*` validators, install ui-fns and pass its plugin via `opts.plugins`.
|
|
553
566
|
*/
|
|
554
567
|
declare function getFormValidator(def: FormDef, opts?: Partial<TValidatorOptions>): (callOpts: TFormValidatorCallOptions) => Record<string, string>;
|
|
@@ -1035,6 +1048,13 @@ interface FieldMeta {
|
|
|
1035
1048
|
* fetchable. Since 0.1.141.
|
|
1036
1049
|
*/
|
|
1037
1050
|
writeOnly?: boolean;
|
|
1051
|
+
/**
|
|
1052
|
+
* Server-computed (`@db.column.derived`, `@atscript/db` 0.1.141+): filterable
|
|
1053
|
+
* and sortable like any column, but a value written to it is dropped. Forms
|
|
1054
|
+
* read the annotation from the type itself (`FormFieldDef.derived`).
|
|
1055
|
+
* Since 0.1.144.
|
|
1056
|
+
*/
|
|
1057
|
+
derived?: boolean;
|
|
1038
1058
|
}
|
|
1039
1059
|
/** Meta response from moost-db `/meta` endpoint. */
|
|
1040
1060
|
interface MetaResponse {
|
|
@@ -1323,4 +1343,4 @@ interface TModelRoute {
|
|
|
1323
1343
|
*/
|
|
1324
1344
|
declare function buildModelRoutes(models: readonly TAtscriptAnnotatedType[]): TModelRoute[];
|
|
1325
1345
|
//#endregion
|
|
1326
|
-
export { type ClientFactory, type CloneUnwrap, type ColumnDef, type CurrencyDisplay, DB_AMOUNT_CURRENCY, DB_AMOUNT_CURRENCY_REF, DB_COLUMN_PRECISION, DB_HTTP_PATH, DB_REL_FK, DB_UNIT, DB_UNIT_REF, DEFAULT_COL_SPAN, DEFAULT_ROW_SPAN, type DecimalParts, EXPECT_MAX_LENGTH, type FieldMeta, type FieldResolver, type FormActionInfo, type FormArrayFieldDef, type FormDef, type FormDiffOptions, type FormDiffResult, type FormFieldChange, type FormFieldDef, type FormObjectFieldDef, type FormRebaseOptions, type FormRebaseResult, type FormTupleFieldDef, type FormUnionFieldDef, type FormUnionVariant, type FormatDecimalOptions, type GridSpanArgs, type GridSpec, META_DEFAULT, META_DESCRIPTION, META_ID, META_LABEL, META_READONLY, META_REQUIRED, META_SENSITIVE, type MeasurementInfo, type MetaCacheEntry, type MetaResponse, type PaginationControl, type RelationInfo, type ResolvedValueHelp, type SearchIndexInfo, type SortControl, StaticFieldResolver, type TCrudOp, type TCrudPermissions, type TDbActionInfo, type TDbActionIntent, type TDbActionLevel, type TDbActionProcessor, type TFieldValidatorOptions, type TFormAction, type TFormEntryOptions, type TFormValidatorCallOptions, type TFormValueResolver, type TModelRoute, type TResolveOptions, type TableActionsModel, type TableDef, type TableQueryState, 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_OPTIONS, UI_FORM_ORDER, UI_FORM_PLACEHOLDER, UI_FORM_PREFIX, UI_FORM_PREFIX_ICON, UI_FORM_PREFIX_REF, 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_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, ValueHelpClient, type ValueHelpInfo, type ValueHelpResult, type ValueHelpSearchOptions, WF_ACTION_WITH_DATA, applyFormChanges, asArray, buildDescendantErrorCounts, buildFormDiff, buildFormRebase, buildGridClasses, buildModelRoutes, buildUnionVariants, collectDirtyPaths, createFieldValidator, createFormData, createFormDef, createFormValueResolver, createTableDef, deepClone, deepEqual, defaultResolver, deleteByPath, detectUnionVariant, enforceScale, extractLiteralOptions, extractMeasurement, extractValueHelp, formatDecimalForDisplay, getByPath, getColumn, getCurrencyDecimals, getCurrencyDisplayParts, getDecimalSeparator, getDeclaredFormActions, getDefaultClientFactory, getDefaultValidatorPlugins, getFieldMeta, getFilterableColumns, getFormValidator, getMetaEntry, getResolver, getSortableColumns, getThousandsSeparator, groupInteger, hasComputedAnnotations, hasFieldMeta, isArrayField, isFieldHidden, isObjectField, isPathDirty, isPureLiteralUnion, isTupleField, isUnionField, iteratePathAncestors, joinDecimalString, joinPath, mergeErrorMaps, navigateHrefFor, omitPaths, optKey, optLabel, parseColSpan, parseDecimalInput, parseRowSpan, parseStaticAttrs, parseStaticOptions, resetDefaultClientFactory, resetMetaCache, resetValueHelpCache, resolveAttrs, resolveFieldProp, resolveFormProp, resolveGridSpec, resolveOptions, resolveSingularLabel, resolveStatic, resolveValueHelp, setByPath, setDefaultClientFactory, setDefaultValidatorPlugins, setResolver, splitDecimalString, str, unionVariantChanged, valueHelpDictPaths };
|
|
1346
|
+
export { type ClientFactory, type CloneUnwrap, type ColumnDef, type CreateFormDefOptions, type CurrencyDisplay, DB_AMOUNT_CURRENCY, DB_AMOUNT_CURRENCY_REF, DB_COLUMN_PRECISION, DB_HTTP_PATH, DB_REL_FK, DB_UNIT, DB_UNIT_REF, DEFAULT_COL_SPAN, DEFAULT_ROW_SPAN, type DecimalParts, EXPECT_MAX_LENGTH, type FieldMeta, type FieldResolver, type FormActionInfo, type FormArrayFieldDef, type FormDef, type FormDiffOptions, type FormDiffResult, type FormFieldChange, type FormFieldDef, type FormObjectFieldDef, type FormRebaseOptions, type FormRebaseResult, type FormTupleFieldDef, type FormUnionFieldDef, type FormUnionVariant, type FormatDecimalOptions, type GridSpanArgs, type GridSpec, META_DEFAULT, META_DESCRIPTION, META_ID, META_LABEL, META_READONLY, META_REQUIRED, META_SENSITIVE, type MeasurementInfo, type MetaCacheEntry, type MetaResponse, type PaginationControl, type RelationInfo, type ResolvedValueHelp, type SearchIndexInfo, type SortControl, StaticFieldResolver, type TCrudOp, type TCrudPermissions, type TDbActionInfo, type TDbActionIntent, type TDbActionLevel, type TDbActionProcessor, type TFieldValidatorOptions, type TFormAction, type TFormEntryOptions, type TFormValidatorCallOptions, type TFormValueResolver, type TModelRoute, type TResolveOptions, type TableActionsModel, type TableDef, type TableQueryState, 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_OPTIONS, UI_FORM_ORDER, UI_FORM_PLACEHOLDER, UI_FORM_PREFIX, UI_FORM_PREFIX_ICON, UI_FORM_PREFIX_REF, 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_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, ValueHelpClient, type ValueHelpInfo, type ValueHelpResult, type ValueHelpSearchOptions, WF_ACTION_WITH_DATA, applyFormChanges, asArray, buildDescendantErrorCounts, buildFormDiff, buildFormRebase, buildGridClasses, buildModelRoutes, buildUnionVariants, collectDirtyPaths, createFieldValidator, createFormData, createFormDef, createFormValueResolver, createTableDef, deepClone, deepEqual, defaultResolver, deleteByPath, detectUnionVariant, enforceScale, extractLiteralOptions, extractMeasurement, extractValueHelp, formatDecimalForDisplay, getByPath, getColumn, getCurrencyDecimals, getCurrencyDisplayParts, getDecimalSeparator, getDeclaredFormActions, getDefaultClientFactory, getDefaultValidatorPlugins, getFieldMeta, getFilterableColumns, getFormValidator, getMetaEntry, getResolver, getSortableColumns, getThousandsSeparator, groupInteger, hasComputedAnnotations, hasFieldMeta, isArrayField, isFieldHidden, isObjectField, isPathDirty, isPureLiteralUnion, isTupleField, isUnionField, iteratePathAncestors, joinDecimalString, joinPath, mergeErrorMaps, navigateHrefFor, omitPaths, optKey, optLabel, parseColSpan, parseDecimalInput, parseRowSpan, parseStaticAttrs, parseStaticOptions, resetDefaultClientFactory, resetMetaCache, resetValueHelpCache, resolveAttrs, resolveFieldProp, resolveFormProp, resolveGridSpec, resolveOptions, resolveSingularLabel, resolveStatic, resolveValueHelp, setByPath, setDefaultClientFactory, setDefaultValidatorPlugins, setResolver, splitDecimalString, str, unionVariantChanged, valueHelpDictPaths };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Validator, createDataFromAnnotatedType, deserializeAnnotatedType, detectDiscriminator, flattenAnnotatedType } from "@atscript/typescript/utils";
|
|
2
2
|
import { Client, encodeNavigateId } from "@atscript/db-client";
|
|
3
|
+
import { createDbValidatorPlugin } from "@atscript/db/validator";
|
|
3
4
|
//#region src/shared/annotation-keys.ts
|
|
4
5
|
const UI_TYPE = "ui.type";
|
|
5
6
|
const UI_FORM_PLACEHOLDER = "ui.form.placeholder";
|
|
@@ -334,9 +335,7 @@ const UI_TAGS = new Set([
|
|
|
334
335
|
* - **Non-object types** (primitive, array, union, etc.): produces a single leaf root field
|
|
335
336
|
* with `path: ''`.
|
|
336
337
|
*
|
|
337
|
-
*
|
|
338
|
-
* exclude from `fields[]` (it stays in `flatMap` so the wire payload is
|
|
339
|
-
* unchanged). Root-table concept; not propagated into nested recursive calls.
|
|
338
|
+
* A `@db.column.derived` field is marked `derived` straight from its metadata.
|
|
340
339
|
*/
|
|
341
340
|
function createFormDef(type, opts) {
|
|
342
341
|
if (type.type.kind !== "object") {
|
|
@@ -411,7 +410,8 @@ function createFieldDef(path, prop) {
|
|
|
411
410
|
name,
|
|
412
411
|
allStatic,
|
|
413
412
|
pushDown,
|
|
414
|
-
valueHelpInfo
|
|
413
|
+
valueHelpInfo,
|
|
414
|
+
...getFieldMeta(prop, "db.column.derived") !== void 0 && { derived: true }
|
|
415
415
|
};
|
|
416
416
|
const customType = uiType;
|
|
417
417
|
if (kind === "array") {
|
|
@@ -1054,6 +1054,27 @@ function deepClone(value, unwrap) {
|
|
|
1054
1054
|
}
|
|
1055
1055
|
//#endregion
|
|
1056
1056
|
//#region src/form/validate.ts
|
|
1057
|
+
const dbPlugin = createDbValidatorPlugin();
|
|
1058
|
+
const INSERT_CONTEXT = { mode: "insert" };
|
|
1059
|
+
/**
|
|
1060
|
+
* Always-on plugin for fields the server fills in, so a create form is not
|
|
1061
|
+
* blocked on them:
|
|
1062
|
+
* - `@db.column.derived` — read-only and server-computed: never validated
|
|
1063
|
+
* (not even a loaded value, which the user could not fix).
|
|
1064
|
+
* - an absent `@db.default*` / `@db.column.version` value — delegated to
|
|
1065
|
+
* `@atscript/db`'s own insert-mode rule, so the key list has one owner.
|
|
1066
|
+
* `db.rel.FK` is kept out: a form fills the FK itself (no nested nav
|
|
1067
|
+
* object), so an empty required FK must still fail.
|
|
1068
|
+
*
|
|
1069
|
+
* The db plugin reads its mode from the validation context, which here
|
|
1070
|
+
* carries the form's `{ data, context }` — it gets a view of `ctx` with the
|
|
1071
|
+
* insert context instead.
|
|
1072
|
+
*/
|
|
1073
|
+
const serverManagedPlugin = (ctx, def, value) => {
|
|
1074
|
+
if (def.metadata.has("db.column.derived")) return true;
|
|
1075
|
+
if (value !== void 0 || def.metadata.has("db.rel.FK")) return void 0;
|
|
1076
|
+
return dbPlugin(Object.create(ctx, { context: { value: INSERT_CONTEXT } }), def, value);
|
|
1077
|
+
};
|
|
1057
1078
|
let defaultValidatorPlugins = [];
|
|
1058
1079
|
/** Replace the default validator plugins applied to every form/field validator. */
|
|
1059
1080
|
function setDefaultValidatorPlugins(plugins) {
|
|
@@ -1067,14 +1088,19 @@ function getDefaultValidatorPlugins() {
|
|
|
1067
1088
|
* Returns a reusable validator function for a whole FormDef.
|
|
1068
1089
|
*
|
|
1069
1090
|
* Validator is created once and reused on every call.
|
|
1070
|
-
* ATScript's @expect.* validation runs automatically
|
|
1091
|
+
* ATScript's @expect.* validation runs automatically; server-managed db
|
|
1092
|
+
* fields (`@db.column.derived`, absent `@db.default*` / version) pass.
|
|
1071
1093
|
* For custom `ui.fn.*` validators, install ui-fns and pass its plugin via `opts.plugins`.
|
|
1072
1094
|
*/
|
|
1073
1095
|
function getFormValidator(def, opts) {
|
|
1074
1096
|
const validator = new Validator(def.type, {
|
|
1075
1097
|
unknownProps: "ignore",
|
|
1076
1098
|
...opts,
|
|
1077
|
-
plugins: [
|
|
1099
|
+
plugins: [
|
|
1100
|
+
serverManagedPlugin,
|
|
1101
|
+
...defaultValidatorPlugins,
|
|
1102
|
+
...opts?.plugins ?? []
|
|
1103
|
+
]
|
|
1078
1104
|
});
|
|
1079
1105
|
return (callOpts) => {
|
|
1080
1106
|
if (validator.validate(callOpts.data, true, {
|
|
@@ -1095,7 +1121,7 @@ function getFormValidator(def, opts) {
|
|
|
1095
1121
|
function createFieldValidator(prop, opts) {
|
|
1096
1122
|
let cached;
|
|
1097
1123
|
return (value, externalCtx) => {
|
|
1098
|
-
cached ??= new Validator(prop, { plugins: defaultValidatorPlugins });
|
|
1124
|
+
cached ??= new Validator(prop, { plugins: [serverManagedPlugin, ...defaultValidatorPlugins] });
|
|
1099
1125
|
if (!cached.validate(value, true, externalCtx)) {
|
|
1100
1126
|
if (opts?.rootOnly) {
|
|
1101
1127
|
const rootError = cached.errors?.find((e) => e.path === "");
|
|
@@ -1164,8 +1190,7 @@ function diffFields(fields, prefix, baseline, current, changes, patch, versionCo
|
|
|
1164
1190
|
diffLeafRoot(field, baseline, current, changes, patch);
|
|
1165
1191
|
continue;
|
|
1166
1192
|
}
|
|
1167
|
-
if (field.phantom) continue;
|
|
1168
|
-
if (versionColumn !== void 0 && !prefix && field.path === versionColumn) continue;
|
|
1193
|
+
if (field.phantom || field.derived || versionColumn !== void 0 && !prefix && field.path === versionColumn) continue;
|
|
1169
1194
|
const fullPath = prefix ? `${prefix}.${field.path}` : field.path;
|
|
1170
1195
|
if (isArrayField(field)) {
|
|
1171
1196
|
diffArrayField(field, fullPath, baseline, current, changes, patch);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/ui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.144",
|
|
4
4
|
"description": "Framework-agnostic runtime for form and table definitions from atscript annotated types",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"annotations",
|
|
@@ -47,18 +47,19 @@
|
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@atscript/db-client": "^0.1.
|
|
50
|
+
"@atscript/db-client": "^0.1.142"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@atscript/core": "^0.1.
|
|
54
|
-
"@atscript/db": "^0.1.
|
|
55
|
-
"@atscript/typescript": "^0.1.
|
|
56
|
-
"unplugin-atscript": "^0.1.
|
|
53
|
+
"@atscript/core": "^0.1.95",
|
|
54
|
+
"@atscript/db": "^0.1.142",
|
|
55
|
+
"@atscript/typescript": "^0.1.95",
|
|
56
|
+
"unplugin-atscript": "^0.1.95",
|
|
57
57
|
"vitest": "npm:@voidzero-dev/vite-plus-test@0.1.14"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"@atscript/core": "^0.1.
|
|
61
|
-
"@atscript/
|
|
60
|
+
"@atscript/core": "^0.1.95",
|
|
61
|
+
"@atscript/db": "^0.1.142",
|
|
62
|
+
"@atscript/typescript": "^0.1.95"
|
|
62
63
|
},
|
|
63
64
|
"scripts": {
|
|
64
65
|
"build": "vp pack",
|