@atscript/ui 0.1.121 → 0.1.123
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 +76 -12
- package/dist/index.d.cts +34 -1
- package/dist/index.d.mts +34 -1
- package/dist/index.mjs +73 -13
- package/dist/plugin.cjs +28 -0
- package/dist/plugin.mjs +28 -0
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -42,7 +42,12 @@ const UI_DICT_ATTR = "ui.dict.attr";
|
|
|
42
42
|
const UI_DICT_FILTERABLE = "ui.dict.filterable";
|
|
43
43
|
const UI_DICT_SORTABLE = "ui.dict.sortable";
|
|
44
44
|
const UI_DICT_SEARCHABLE = "ui.dict.searchable";
|
|
45
|
+
const UI_NAV_GROUP = "ui.nav.group";
|
|
46
|
+
const UI_NAV_ORDER = "ui.nav.order";
|
|
47
|
+
const UI_NAV_HIDDEN = "ui.nav.hidden";
|
|
45
48
|
const DB_REL_FK = "db.rel.FK";
|
|
49
|
+
const DB_TABLE = "db.table";
|
|
50
|
+
const DB_VIEW = "db.view";
|
|
46
51
|
const DB_HTTP_PATH = "db.http.path";
|
|
47
52
|
const DB_AMOUNT_CURRENCY = "db.amount.currency";
|
|
48
53
|
const DB_AMOUNT_CURRENCY_REF = "db.amount.currency.ref";
|
|
@@ -2164,6 +2169,18 @@ function groupInteger(integer, locale) {
|
|
|
2164
2169
|
return out.join(sep);
|
|
2165
2170
|
}
|
|
2166
2171
|
//#endregion
|
|
2172
|
+
//#region src/shared/str.ts
|
|
2173
|
+
/** Converts a dot-path to a human-readable label (e.g. 'firstName' → 'First Name'). */
|
|
2174
|
+
function humanizePath(path) {
|
|
2175
|
+
return path.slice(path.lastIndexOf(".") + 1).replace(/([a-z])([A-Z])/g, "$1 $2").replace(/^./, (s) => s.toUpperCase());
|
|
2176
|
+
}
|
|
2177
|
+
/** Safely convert an unknown value to a string without triggering no-base-to-string lint errors. */
|
|
2178
|
+
function str(value) {
|
|
2179
|
+
if (typeof value === "string") return value;
|
|
2180
|
+
if (typeof value === "number" || typeof value === "bigint" || typeof value === "boolean") return `${value}`;
|
|
2181
|
+
return JSON.stringify(value) ?? "";
|
|
2182
|
+
}
|
|
2183
|
+
//#endregion
|
|
2167
2184
|
//#region src/table/create-table-def.ts
|
|
2168
2185
|
/**
|
|
2169
2186
|
* Builds a TableDef from a moost-db MetaResponse.
|
|
@@ -2276,18 +2293,6 @@ function inferDisplayType(prop, literalOpts) {
|
|
|
2276
2293
|
}
|
|
2277
2294
|
return "text";
|
|
2278
2295
|
}
|
|
2279
|
-
/** Converts a dot-path to a human-readable label (e.g. 'firstName' → 'First Name'). */
|
|
2280
|
-
function humanizePath(path) {
|
|
2281
|
-
return path.slice(path.lastIndexOf(".") + 1).replace(/([a-z])([A-Z])/g, "$1 $2").replace(/^./, (s) => s.toUpperCase());
|
|
2282
|
-
}
|
|
2283
|
-
//#endregion
|
|
2284
|
-
//#region src/shared/str.ts
|
|
2285
|
-
/** Safely convert an unknown value to a string without triggering no-base-to-string lint errors. */
|
|
2286
|
-
function str(value) {
|
|
2287
|
-
if (typeof value === "string") return value;
|
|
2288
|
-
if (typeof value === "number" || typeof value === "bigint" || typeof value === "boolean") return `${value}`;
|
|
2289
|
-
return JSON.stringify(value) ?? "";
|
|
2290
|
-
}
|
|
2291
2296
|
//#endregion
|
|
2292
2297
|
//#region src/table/column-resolver.ts
|
|
2293
2298
|
/** Get sortable columns. */
|
|
@@ -2331,6 +2336,61 @@ function navigateHrefFor(action, id, preferredId) {
|
|
|
2331
2336
|
return action.value.replace(/\$1/g, (0, _atscript_db_client.encodeNavigateId)(id, preferredId));
|
|
2332
2337
|
}
|
|
2333
2338
|
//#endregion
|
|
2339
|
+
//#region src/nav/model-routes.ts
|
|
2340
|
+
/**
|
|
2341
|
+
* Derives navigable routes from DB-backed models' metadata.
|
|
2342
|
+
*
|
|
2343
|
+
* A model is included only when it is a DB entity (`@db.table`, `@db.view`,
|
|
2344
|
+
* or `@db.view.for`) AND a path can be derived: `@db.http.path` first, then
|
|
2345
|
+
* the string value of `@db.table` / `@db.view`, then the type's own id
|
|
2346
|
+
* as-is. Models where none of these yield a non-empty path are omitted.
|
|
2347
|
+
*
|
|
2348
|
+
* Routes are sorted by `order` ascending (undefined last, ties keep input
|
|
2349
|
+
* order). Hidden models are returned with `hidden: true` — filtering and
|
|
2350
|
+
* grouping are left to the consumer.
|
|
2351
|
+
*/
|
|
2352
|
+
function buildModelRoutes(models) {
|
|
2353
|
+
const routes = [];
|
|
2354
|
+
for (const model of models) {
|
|
2355
|
+
const table = getFieldMeta(model, DB_TABLE);
|
|
2356
|
+
const view = getFieldMeta(model, DB_VIEW);
|
|
2357
|
+
const isView = view !== void 0 || hasFieldMeta(model, "db.view.for");
|
|
2358
|
+
if (table === void 0 && !isView) continue;
|
|
2359
|
+
const path = resolvePath(model, table, view);
|
|
2360
|
+
if (path === void 0) continue;
|
|
2361
|
+
const route = {
|
|
2362
|
+
model,
|
|
2363
|
+
path,
|
|
2364
|
+
label: getFieldMeta(model, "meta.label") ?? humanizePath(path.slice(path.lastIndexOf("/") + 1)),
|
|
2365
|
+
kind: isView ? "view" : "table"
|
|
2366
|
+
};
|
|
2367
|
+
const group = getFieldMeta(model, UI_NAV_GROUP);
|
|
2368
|
+
if (typeof group === "string") route.group = group;
|
|
2369
|
+
const order = getFieldMeta(model, UI_NAV_ORDER);
|
|
2370
|
+
if (typeof order === "number") route.order = order;
|
|
2371
|
+
if (getFieldMeta(model, "ui.nav.hidden") === true) route.hidden = true;
|
|
2372
|
+
routes.push(route);
|
|
2373
|
+
}
|
|
2374
|
+
routes.sort((a, b) => {
|
|
2375
|
+
const ao = a.order ?? Number.POSITIVE_INFINITY;
|
|
2376
|
+
const bo = b.order ?? Number.POSITIVE_INFINITY;
|
|
2377
|
+
return ao === bo ? 0 : ao - bo;
|
|
2378
|
+
});
|
|
2379
|
+
return routes;
|
|
2380
|
+
}
|
|
2381
|
+
/** `db.http.path` > string `db.table`/`db.view` name > type id — mirrors moost-db's controller prefix resolution, so the path matches the HTTP mount of a token-bound controller. */
|
|
2382
|
+
function resolvePath(model, table, view) {
|
|
2383
|
+
const http = getFieldMeta(model, DB_HTTP_PATH);
|
|
2384
|
+
let raw;
|
|
2385
|
+
if (typeof http === "string") raw = http;
|
|
2386
|
+
else if (typeof table === "string") raw = table;
|
|
2387
|
+
else if (typeof view === "string") raw = view;
|
|
2388
|
+
else if (typeof model.id === "string") raw = model.id;
|
|
2389
|
+
if (!raw) return void 0;
|
|
2390
|
+
const path = raw.replace(/^\/+|\/+$/g, "");
|
|
2391
|
+
return path.length > 0 ? path : void 0;
|
|
2392
|
+
}
|
|
2393
|
+
//#endregion
|
|
2334
2394
|
exports.DB_AMOUNT_CURRENCY = DB_AMOUNT_CURRENCY;
|
|
2335
2395
|
exports.DB_AMOUNT_CURRENCY_REF = DB_AMOUNT_CURRENCY_REF;
|
|
2336
2396
|
exports.DB_COLUMN_PRECISION = DB_COLUMN_PRECISION;
|
|
@@ -2395,6 +2455,9 @@ exports.UI_FORM_SUFFIX_ICON = UI_FORM_SUFFIX_ICON;
|
|
|
2395
2455
|
exports.UI_FORM_SUFFIX_REF = UI_FORM_SUFFIX_REF;
|
|
2396
2456
|
exports.UI_FORM_TYPE = UI_FORM_TYPE;
|
|
2397
2457
|
exports.UI_FORM_VALIDATE = UI_FORM_VALIDATE;
|
|
2458
|
+
exports.UI_NAV_GROUP = UI_NAV_GROUP;
|
|
2459
|
+
exports.UI_NAV_HIDDEN = UI_NAV_HIDDEN;
|
|
2460
|
+
exports.UI_NAV_ORDER = UI_NAV_ORDER;
|
|
2398
2461
|
exports.UI_TABLE_ATTR = UI_TABLE_ATTR;
|
|
2399
2462
|
exports.UI_TABLE_CLASSES = UI_TABLE_CLASSES;
|
|
2400
2463
|
exports.UI_TABLE_COMPONENT = UI_TABLE_COMPONENT;
|
|
@@ -2417,6 +2480,7 @@ exports.buildDescendantErrorCounts = buildDescendantErrorCounts;
|
|
|
2417
2480
|
exports.buildFormDiff = buildFormDiff;
|
|
2418
2481
|
exports.buildFormRebase = buildFormRebase;
|
|
2419
2482
|
exports.buildGridClasses = buildGridClasses;
|
|
2483
|
+
exports.buildModelRoutes = buildModelRoutes;
|
|
2420
2484
|
exports.buildUnionVariants = buildUnionVariants;
|
|
2421
2485
|
exports.collectDirtyPaths = collectDirtyPaths;
|
|
2422
2486
|
exports.createFieldValidator = createFieldValidator;
|
package/dist/index.d.cts
CHANGED
|
@@ -41,6 +41,9 @@ declare const UI_DICT_ATTR: "ui.dict.attr";
|
|
|
41
41
|
declare const UI_DICT_FILTERABLE: "ui.dict.filterable";
|
|
42
42
|
declare const UI_DICT_SORTABLE: "ui.dict.sortable";
|
|
43
43
|
declare const UI_DICT_SEARCHABLE: "ui.dict.searchable";
|
|
44
|
+
declare const UI_NAV_GROUP: "ui.nav.group";
|
|
45
|
+
declare const UI_NAV_ORDER: "ui.nav.order";
|
|
46
|
+
declare const UI_NAV_HIDDEN: "ui.nav.hidden";
|
|
44
47
|
declare const DB_REL_FK: "db.rel.FK";
|
|
45
48
|
declare const DB_HTTP_PATH: "db.http.path";
|
|
46
49
|
declare const DB_AMOUNT_CURRENCY: "db.amount.currency";
|
|
@@ -1227,4 +1230,34 @@ declare function getColumn(def: TableDef, path: string): ColumnDef | undefined;
|
|
|
1227
1230
|
*/
|
|
1228
1231
|
declare function navigateHrefFor(action: TDbActionInfo$1, id: Record<string, unknown> | undefined, preferredId: readonly string[]): string | undefined;
|
|
1229
1232
|
//#endregion
|
|
1230
|
-
|
|
1233
|
+
//#region src/nav/model-routes.d.ts
|
|
1234
|
+
/** A navigable route derived from a DB-backed model's metadata. */
|
|
1235
|
+
interface TModelRoute {
|
|
1236
|
+
model: TAtscriptAnnotatedType;
|
|
1237
|
+
/** Route path without leading/trailing slashes — mountable anywhere. */
|
|
1238
|
+
path: string;
|
|
1239
|
+
/** Display label — from @meta.label or humanized last path segment. */
|
|
1240
|
+
label: string;
|
|
1241
|
+
kind: "table" | "view";
|
|
1242
|
+
/** Nav section from @ui.nav.group — grouping is the consumer's job. */
|
|
1243
|
+
group?: string;
|
|
1244
|
+
/** Position from @ui.nav.order — lower first, undefined last. */
|
|
1245
|
+
order?: number;
|
|
1246
|
+
/** From @ui.nav.hidden — hidden routes are still returned; consumers filter. */
|
|
1247
|
+
hidden?: boolean;
|
|
1248
|
+
}
|
|
1249
|
+
/**
|
|
1250
|
+
* Derives navigable routes from DB-backed models' metadata.
|
|
1251
|
+
*
|
|
1252
|
+
* A model is included only when it is a DB entity (`@db.table`, `@db.view`,
|
|
1253
|
+
* or `@db.view.for`) AND a path can be derived: `@db.http.path` first, then
|
|
1254
|
+
* the string value of `@db.table` / `@db.view`, then the type's own id
|
|
1255
|
+
* as-is. Models where none of these yield a non-empty path are omitted.
|
|
1256
|
+
*
|
|
1257
|
+
* Routes are sorted by `order` ascending (undefined last, ties keep input
|
|
1258
|
+
* order). Hidden models are returned with `hidden: true` — filtering and
|
|
1259
|
+
* grouping are left to the consumer.
|
|
1260
|
+
*/
|
|
1261
|
+
declare function buildModelRoutes(models: readonly TAtscriptAnnotatedType[]): TModelRoute[];
|
|
1262
|
+
//#endregion
|
|
1263
|
+
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 };
|
package/dist/index.d.mts
CHANGED
|
@@ -41,6 +41,9 @@ declare const UI_DICT_ATTR: "ui.dict.attr";
|
|
|
41
41
|
declare const UI_DICT_FILTERABLE: "ui.dict.filterable";
|
|
42
42
|
declare const UI_DICT_SORTABLE: "ui.dict.sortable";
|
|
43
43
|
declare const UI_DICT_SEARCHABLE: "ui.dict.searchable";
|
|
44
|
+
declare const UI_NAV_GROUP: "ui.nav.group";
|
|
45
|
+
declare const UI_NAV_ORDER: "ui.nav.order";
|
|
46
|
+
declare const UI_NAV_HIDDEN: "ui.nav.hidden";
|
|
44
47
|
declare const DB_REL_FK: "db.rel.FK";
|
|
45
48
|
declare const DB_HTTP_PATH: "db.http.path";
|
|
46
49
|
declare const DB_AMOUNT_CURRENCY: "db.amount.currency";
|
|
@@ -1227,4 +1230,34 @@ declare function getColumn(def: TableDef, path: string): ColumnDef | undefined;
|
|
|
1227
1230
|
*/
|
|
1228
1231
|
declare function navigateHrefFor(action: TDbActionInfo$1, id: Record<string, unknown> | undefined, preferredId: readonly string[]): string | undefined;
|
|
1229
1232
|
//#endregion
|
|
1230
|
-
|
|
1233
|
+
//#region src/nav/model-routes.d.ts
|
|
1234
|
+
/** A navigable route derived from a DB-backed model's metadata. */
|
|
1235
|
+
interface TModelRoute {
|
|
1236
|
+
model: TAtscriptAnnotatedType;
|
|
1237
|
+
/** Route path without leading/trailing slashes — mountable anywhere. */
|
|
1238
|
+
path: string;
|
|
1239
|
+
/** Display label — from @meta.label or humanized last path segment. */
|
|
1240
|
+
label: string;
|
|
1241
|
+
kind: "table" | "view";
|
|
1242
|
+
/** Nav section from @ui.nav.group — grouping is the consumer's job. */
|
|
1243
|
+
group?: string;
|
|
1244
|
+
/** Position from @ui.nav.order — lower first, undefined last. */
|
|
1245
|
+
order?: number;
|
|
1246
|
+
/** From @ui.nav.hidden — hidden routes are still returned; consumers filter. */
|
|
1247
|
+
hidden?: boolean;
|
|
1248
|
+
}
|
|
1249
|
+
/**
|
|
1250
|
+
* Derives navigable routes from DB-backed models' metadata.
|
|
1251
|
+
*
|
|
1252
|
+
* A model is included only when it is a DB entity (`@db.table`, `@db.view`,
|
|
1253
|
+
* or `@db.view.for`) AND a path can be derived: `@db.http.path` first, then
|
|
1254
|
+
* the string value of `@db.table` / `@db.view`, then the type's own id
|
|
1255
|
+
* as-is. Models where none of these yield a non-empty path are omitted.
|
|
1256
|
+
*
|
|
1257
|
+
* Routes are sorted by `order` ascending (undefined last, ties keep input
|
|
1258
|
+
* order). Hidden models are returned with `hidden: true` — filtering and
|
|
1259
|
+
* grouping are left to the consumer.
|
|
1260
|
+
*/
|
|
1261
|
+
declare function buildModelRoutes(models: readonly TAtscriptAnnotatedType[]): TModelRoute[];
|
|
1262
|
+
//#endregion
|
|
1263
|
+
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 };
|
package/dist/index.mjs
CHANGED
|
@@ -41,7 +41,12 @@ const UI_DICT_ATTR = "ui.dict.attr";
|
|
|
41
41
|
const UI_DICT_FILTERABLE = "ui.dict.filterable";
|
|
42
42
|
const UI_DICT_SORTABLE = "ui.dict.sortable";
|
|
43
43
|
const UI_DICT_SEARCHABLE = "ui.dict.searchable";
|
|
44
|
+
const UI_NAV_GROUP = "ui.nav.group";
|
|
45
|
+
const UI_NAV_ORDER = "ui.nav.order";
|
|
46
|
+
const UI_NAV_HIDDEN = "ui.nav.hidden";
|
|
44
47
|
const DB_REL_FK = "db.rel.FK";
|
|
48
|
+
const DB_TABLE = "db.table";
|
|
49
|
+
const DB_VIEW = "db.view";
|
|
45
50
|
const DB_HTTP_PATH = "db.http.path";
|
|
46
51
|
const DB_AMOUNT_CURRENCY = "db.amount.currency";
|
|
47
52
|
const DB_AMOUNT_CURRENCY_REF = "db.amount.currency.ref";
|
|
@@ -2163,6 +2168,18 @@ function groupInteger(integer, locale) {
|
|
|
2163
2168
|
return out.join(sep);
|
|
2164
2169
|
}
|
|
2165
2170
|
//#endregion
|
|
2171
|
+
//#region src/shared/str.ts
|
|
2172
|
+
/** Converts a dot-path to a human-readable label (e.g. 'firstName' → 'First Name'). */
|
|
2173
|
+
function humanizePath(path) {
|
|
2174
|
+
return path.slice(path.lastIndexOf(".") + 1).replace(/([a-z])([A-Z])/g, "$1 $2").replace(/^./, (s) => s.toUpperCase());
|
|
2175
|
+
}
|
|
2176
|
+
/** Safely convert an unknown value to a string without triggering no-base-to-string lint errors. */
|
|
2177
|
+
function str(value) {
|
|
2178
|
+
if (typeof value === "string") return value;
|
|
2179
|
+
if (typeof value === "number" || typeof value === "bigint" || typeof value === "boolean") return `${value}`;
|
|
2180
|
+
return JSON.stringify(value) ?? "";
|
|
2181
|
+
}
|
|
2182
|
+
//#endregion
|
|
2166
2183
|
//#region src/table/create-table-def.ts
|
|
2167
2184
|
/**
|
|
2168
2185
|
* Builds a TableDef from a moost-db MetaResponse.
|
|
@@ -2275,18 +2292,6 @@ function inferDisplayType(prop, literalOpts) {
|
|
|
2275
2292
|
}
|
|
2276
2293
|
return "text";
|
|
2277
2294
|
}
|
|
2278
|
-
/** Converts a dot-path to a human-readable label (e.g. 'firstName' → 'First Name'). */
|
|
2279
|
-
function humanizePath(path) {
|
|
2280
|
-
return path.slice(path.lastIndexOf(".") + 1).replace(/([a-z])([A-Z])/g, "$1 $2").replace(/^./, (s) => s.toUpperCase());
|
|
2281
|
-
}
|
|
2282
|
-
//#endregion
|
|
2283
|
-
//#region src/shared/str.ts
|
|
2284
|
-
/** Safely convert an unknown value to a string without triggering no-base-to-string lint errors. */
|
|
2285
|
-
function str(value) {
|
|
2286
|
-
if (typeof value === "string") return value;
|
|
2287
|
-
if (typeof value === "number" || typeof value === "bigint" || typeof value === "boolean") return `${value}`;
|
|
2288
|
-
return JSON.stringify(value) ?? "";
|
|
2289
|
-
}
|
|
2290
2295
|
//#endregion
|
|
2291
2296
|
//#region src/table/column-resolver.ts
|
|
2292
2297
|
/** Get sortable columns. */
|
|
@@ -2330,4 +2335,59 @@ function navigateHrefFor(action, id, preferredId) {
|
|
|
2330
2335
|
return action.value.replace(/\$1/g, encodeNavigateId(id, preferredId));
|
|
2331
2336
|
}
|
|
2332
2337
|
//#endregion
|
|
2333
|
-
|
|
2338
|
+
//#region src/nav/model-routes.ts
|
|
2339
|
+
/**
|
|
2340
|
+
* Derives navigable routes from DB-backed models' metadata.
|
|
2341
|
+
*
|
|
2342
|
+
* A model is included only when it is a DB entity (`@db.table`, `@db.view`,
|
|
2343
|
+
* or `@db.view.for`) AND a path can be derived: `@db.http.path` first, then
|
|
2344
|
+
* the string value of `@db.table` / `@db.view`, then the type's own id
|
|
2345
|
+
* as-is. Models where none of these yield a non-empty path are omitted.
|
|
2346
|
+
*
|
|
2347
|
+
* Routes are sorted by `order` ascending (undefined last, ties keep input
|
|
2348
|
+
* order). Hidden models are returned with `hidden: true` — filtering and
|
|
2349
|
+
* grouping are left to the consumer.
|
|
2350
|
+
*/
|
|
2351
|
+
function buildModelRoutes(models) {
|
|
2352
|
+
const routes = [];
|
|
2353
|
+
for (const model of models) {
|
|
2354
|
+
const table = getFieldMeta(model, DB_TABLE);
|
|
2355
|
+
const view = getFieldMeta(model, DB_VIEW);
|
|
2356
|
+
const isView = view !== void 0 || hasFieldMeta(model, "db.view.for");
|
|
2357
|
+
if (table === void 0 && !isView) continue;
|
|
2358
|
+
const path = resolvePath(model, table, view);
|
|
2359
|
+
if (path === void 0) continue;
|
|
2360
|
+
const route = {
|
|
2361
|
+
model,
|
|
2362
|
+
path,
|
|
2363
|
+
label: getFieldMeta(model, "meta.label") ?? humanizePath(path.slice(path.lastIndexOf("/") + 1)),
|
|
2364
|
+
kind: isView ? "view" : "table"
|
|
2365
|
+
};
|
|
2366
|
+
const group = getFieldMeta(model, UI_NAV_GROUP);
|
|
2367
|
+
if (typeof group === "string") route.group = group;
|
|
2368
|
+
const order = getFieldMeta(model, UI_NAV_ORDER);
|
|
2369
|
+
if (typeof order === "number") route.order = order;
|
|
2370
|
+
if (getFieldMeta(model, "ui.nav.hidden") === true) route.hidden = true;
|
|
2371
|
+
routes.push(route);
|
|
2372
|
+
}
|
|
2373
|
+
routes.sort((a, b) => {
|
|
2374
|
+
const ao = a.order ?? Number.POSITIVE_INFINITY;
|
|
2375
|
+
const bo = b.order ?? Number.POSITIVE_INFINITY;
|
|
2376
|
+
return ao === bo ? 0 : ao - bo;
|
|
2377
|
+
});
|
|
2378
|
+
return routes;
|
|
2379
|
+
}
|
|
2380
|
+
/** `db.http.path` > string `db.table`/`db.view` name > type id — mirrors moost-db's controller prefix resolution, so the path matches the HTTP mount of a token-bound controller. */
|
|
2381
|
+
function resolvePath(model, table, view) {
|
|
2382
|
+
const http = getFieldMeta(model, DB_HTTP_PATH);
|
|
2383
|
+
let raw;
|
|
2384
|
+
if (typeof http === "string") raw = http;
|
|
2385
|
+
else if (typeof table === "string") raw = table;
|
|
2386
|
+
else if (typeof view === "string") raw = view;
|
|
2387
|
+
else if (typeof model.id === "string") raw = model.id;
|
|
2388
|
+
if (!raw) return void 0;
|
|
2389
|
+
const path = raw.replace(/^\/+|\/+$/g, "");
|
|
2390
|
+
return path.length > 0 ? path : void 0;
|
|
2391
|
+
}
|
|
2392
|
+
//#endregion
|
|
2393
|
+
export { 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, EXPECT_MAX_LENGTH, META_DEFAULT, META_DESCRIPTION, META_ID, META_LABEL, META_READONLY, META_REQUIRED, META_SENSITIVE, StaticFieldResolver, 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, 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/plugin.cjs
CHANGED
|
@@ -49,6 +49,7 @@ const ROW_SPAN_VALUES = [
|
|
|
49
49
|
* - `ui.form.<key>` — form-only static
|
|
50
50
|
* - `ui.table.<key>` — table-only static
|
|
51
51
|
* - `ui.dict.<key>` — value-help annotations
|
|
52
|
+
* - `ui.nav.<key>` — model-level navigation annotations
|
|
52
53
|
* - `ui.array.<key>` — array control annotations
|
|
53
54
|
*
|
|
54
55
|
* The dynamic `ui.form.fn.*` / `ui.table.fn.*` and `ui.form.validate` specs
|
|
@@ -469,6 +470,33 @@ const uiAnnotations = { ui: {
|
|
|
469
470
|
passedWhenReferred: false
|
|
470
471
|
})
|
|
471
472
|
},
|
|
473
|
+
nav: {
|
|
474
|
+
group: new _atscript_core.AnnotationSpec({
|
|
475
|
+
description: "Navigation section this model belongs to when the app generates navigation from model metadata (`buildModelRoutes`). Models sharing a group value are meant to render under one nav section — grouping itself is left to the consumer.\n\n**Example:**\n```atscript\n@db.table 'orders'\n@ui.nav.group 'Sales'\nexport interface Order {\n```\n",
|
|
476
|
+
nodeType: ["interface", "type"],
|
|
477
|
+
passedWhenReferred: false,
|
|
478
|
+
argument: {
|
|
479
|
+
name: "group",
|
|
480
|
+
type: "string",
|
|
481
|
+
description: "Nav section name shared by related models."
|
|
482
|
+
}
|
|
483
|
+
}),
|
|
484
|
+
order: new _atscript_core.AnnotationSpec({
|
|
485
|
+
description: "Position of this model in generated navigation — lower values appear first; models without an order sort last (in input order).\n\n**Example:**\n```atscript\n@db.table 'orders'\n@ui.nav.order 1\nexport interface Order {\n```\n",
|
|
486
|
+
nodeType: ["interface", "type"],
|
|
487
|
+
passedWhenReferred: false,
|
|
488
|
+
argument: {
|
|
489
|
+
name: "order",
|
|
490
|
+
type: "number",
|
|
491
|
+
description: "Numeric order (lower = earlier)"
|
|
492
|
+
}
|
|
493
|
+
}),
|
|
494
|
+
hidden: new _atscript_core.AnnotationSpec({
|
|
495
|
+
description: "Opts this model out of generated navigation (e.g. API-only models). `buildModelRoutes` still returns the route flagged `hidden: true` — filtering is the consumer's decision.\n\n**Example:**\n```atscript\n@db.table 'audit_log'\n@ui.nav.hidden\nexport interface AuditLog {\n```\n",
|
|
496
|
+
nodeType: ["interface", "type"],
|
|
497
|
+
passedWhenReferred: false
|
|
498
|
+
})
|
|
499
|
+
},
|
|
472
500
|
array: {
|
|
473
501
|
add: { label: new _atscript_core.AnnotationSpec({
|
|
474
502
|
description: "Label for the add-item button (default: \"Add item\")",
|
package/dist/plugin.mjs
CHANGED
|
@@ -49,6 +49,7 @@ const ROW_SPAN_VALUES = [
|
|
|
49
49
|
* - `ui.form.<key>` — form-only static
|
|
50
50
|
* - `ui.table.<key>` — table-only static
|
|
51
51
|
* - `ui.dict.<key>` — value-help annotations
|
|
52
|
+
* - `ui.nav.<key>` — model-level navigation annotations
|
|
52
53
|
* - `ui.array.<key>` — array control annotations
|
|
53
54
|
*
|
|
54
55
|
* The dynamic `ui.form.fn.*` / `ui.table.fn.*` and `ui.form.validate` specs
|
|
@@ -469,6 +470,33 @@ const uiAnnotations = { ui: {
|
|
|
469
470
|
passedWhenReferred: false
|
|
470
471
|
})
|
|
471
472
|
},
|
|
473
|
+
nav: {
|
|
474
|
+
group: new AnnotationSpec({
|
|
475
|
+
description: "Navigation section this model belongs to when the app generates navigation from model metadata (`buildModelRoutes`). Models sharing a group value are meant to render under one nav section — grouping itself is left to the consumer.\n\n**Example:**\n```atscript\n@db.table 'orders'\n@ui.nav.group 'Sales'\nexport interface Order {\n```\n",
|
|
476
|
+
nodeType: ["interface", "type"],
|
|
477
|
+
passedWhenReferred: false,
|
|
478
|
+
argument: {
|
|
479
|
+
name: "group",
|
|
480
|
+
type: "string",
|
|
481
|
+
description: "Nav section name shared by related models."
|
|
482
|
+
}
|
|
483
|
+
}),
|
|
484
|
+
order: new AnnotationSpec({
|
|
485
|
+
description: "Position of this model in generated navigation — lower values appear first; models without an order sort last (in input order).\n\n**Example:**\n```atscript\n@db.table 'orders'\n@ui.nav.order 1\nexport interface Order {\n```\n",
|
|
486
|
+
nodeType: ["interface", "type"],
|
|
487
|
+
passedWhenReferred: false,
|
|
488
|
+
argument: {
|
|
489
|
+
name: "order",
|
|
490
|
+
type: "number",
|
|
491
|
+
description: "Numeric order (lower = earlier)"
|
|
492
|
+
}
|
|
493
|
+
}),
|
|
494
|
+
hidden: new AnnotationSpec({
|
|
495
|
+
description: "Opts this model out of generated navigation (e.g. API-only models). `buildModelRoutes` still returns the route flagged `hidden: true` — filtering is the consumer's decision.\n\n**Example:**\n```atscript\n@db.table 'audit_log'\n@ui.nav.hidden\nexport interface AuditLog {\n```\n",
|
|
496
|
+
nodeType: ["interface", "type"],
|
|
497
|
+
passedWhenReferred: false
|
|
498
|
+
})
|
|
499
|
+
},
|
|
472
500
|
array: {
|
|
473
501
|
add: { label: new AnnotationSpec({
|
|
474
502
|
description: "Label for the add-item button (default: \"Add item\")",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/ui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.123",
|
|
4
4
|
"description": "Framework-agnostic runtime for form and table definitions from atscript annotated types",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"annotations",
|
|
@@ -47,18 +47,18 @@
|
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@atscript/db-client": "^0.1.
|
|
50
|
+
"@atscript/db-client": "^0.1.117"
|
|
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.84",
|
|
54
|
+
"@atscript/db": "^0.1.117",
|
|
55
|
+
"@atscript/typescript": "^0.1.84",
|
|
56
|
+
"unplugin-atscript": "^0.1.84",
|
|
57
57
|
"vitest": "npm:@voidzero-dev/vite-plus-test@0.1.14"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"@atscript/core": "^0.1.
|
|
61
|
-
"@atscript/typescript": "^0.1.
|
|
60
|
+
"@atscript/core": "^0.1.84",
|
|
61
|
+
"@atscript/typescript": "^0.1.84"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"build": "vp pack",
|