@atscript/ui 0.1.203 → 0.1.205
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/form/create-form-def.cjs +52 -21
- package/dist/form/create-form-def.d.cts +23 -18
- package/dist/form/create-form-def.d.mts +23 -18
- package/dist/form/create-form-def.mjs +52 -21
- package/dist/form/decimal-format.cjs +9 -11
- package/dist/form/decimal-format.mjs +9 -11
- package/dist/form/diff.cjs +32 -14
- package/dist/form/diff.d.cts +7 -4
- package/dist/form/diff.d.mts +7 -4
- package/dist/form/diff.mjs +32 -14
- package/dist/form/loaded-empty.cjs +56 -0
- package/dist/form/loaded-empty.d.cts +25 -0
- package/dist/form/loaded-empty.d.mts +25 -0
- package/dist/form/loaded-empty.mjs +56 -0
- package/dist/form/omit-derived.cjs +38 -0
- package/dist/form/omit-derived.d.cts +17 -0
- package/dist/form/omit-derived.d.mts +17 -0
- package/dist/form/omit-derived.mjs +38 -0
- package/dist/form/optional-mode.cjs +85 -0
- package/dist/form/optional-mode.d.cts +58 -0
- package/dist/form/optional-mode.d.mts +58 -0
- package/dist/form/optional-mode.mjs +82 -0
- package/dist/form/path-utils.cjs +4 -5
- package/dist/form/path-utils.mjs +4 -5
- package/dist/form/types.d.cts +15 -14
- package/dist/form/types.d.mts +15 -14
- package/dist/form/validate.cjs +2 -2
- package/dist/form/validate.mjs +2 -2
- package/dist/index.cjs +23 -4
- package/dist/index.d.cts +7 -3
- package/dist/index.d.mts +7 -3
- package/dist/index.mjs +10 -6
- package/dist/plugin/annotations.cjs +12 -0
- package/dist/plugin/annotations.mjs +13 -1
- package/dist/plugin/value-help-validation.cjs +25 -1
- package/dist/plugin/value-help-validation.mjs +25 -2
- package/dist/shared/annotation-keys.cjs +3 -0
- package/dist/shared/annotation-keys.d.cts +3 -1
- package/dist/shared/annotation-keys.d.mts +3 -1
- package/dist/shared/annotation-keys.mjs +3 -1
- package/dist/shared/exact-number.cjs +12 -0
- package/dist/shared/exact-number.mjs +12 -0
- package/dist/shared/meta-cache.cjs +1 -1
- package/dist/shared/meta-cache.mjs +1 -1
- package/dist/table/create-table-def.cjs +4 -1
- package/dist/table/create-table-def.mjs +4 -2
- package/dist/table/types.d.cts +23 -16
- package/dist/table/types.d.mts +23 -16
- package/dist/table/value-kind.cjs +37 -2
- package/dist/table/value-kind.d.cts +22 -2
- package/dist/table/value-kind.d.mts +22 -2
- package/dist/table/value-kind.mjs +36 -3
- package/dist/value-help/distinct-client.cjs +5 -4
- package/dist/value-help/distinct-client.d.cts +8 -2
- package/dist/value-help/distinct-client.d.mts +8 -2
- package/dist/value-help/distinct-client.mjs +5 -4
- package/dist/value-help/value-help-client.cjs +45 -9
- package/dist/value-help/value-help-client.mjs +45 -9
- package/package.json +11 -12
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ColumnValueKind } from "../table/types.mjs";
|
|
1
2
|
import { ClientLike, FilterExpr } from "@atscript/db-client";
|
|
2
3
|
|
|
3
4
|
//#region src/value-help/distinct-client.d.ts
|
|
@@ -13,8 +14,13 @@ interface DistinctValuesOptions {
|
|
|
13
14
|
skip?: number;
|
|
14
15
|
/** Send `$sort` on the grouped field — only when the server lists it as sortable. */
|
|
15
16
|
sortable?: boolean;
|
|
16
|
-
/**
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* The field's storage kind. A numeric one ({@link NUMERIC_VALUE_KINDS}) is
|
|
19
|
+
* searched by exact value — text that is no value of it finds nothing; a
|
|
20
|
+
* `decimal` / `long` value is sent as text (since 0.1.205; before, a
|
|
21
|
+
* `numeric` flag and a JS number).
|
|
22
|
+
*/
|
|
23
|
+
valueKind?: ColumnValueKind;
|
|
18
24
|
/** Extra scope AND'd into the query (e.g. the table's `forceFilters`). */
|
|
19
25
|
filter?: FilterExpr;
|
|
20
26
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getByPath } from "../form/path-utils.mjs";
|
|
2
2
|
import { escapeRegex } from "../shared/str.mjs";
|
|
3
|
+
import { NUMERIC_VALUE_KINDS, coerceNumericText } from "../table/value-kind.mjs";
|
|
3
4
|
//#region src/value-help/distinct-client.ts
|
|
4
5
|
/**
|
|
5
6
|
* `true` for a 4xx answer — the server declined this picker (gate, ARBAC, unknown field).
|
|
@@ -23,13 +24,13 @@ async function fetchDistinctValues(client, field, opts = {}) {
|
|
|
23
24
|
const text = opts.text?.trim();
|
|
24
25
|
const conditions = [];
|
|
25
26
|
if (opts.filter) conditions.push(opts.filter);
|
|
26
|
-
if (text) if (opts.
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
27
|
+
if (text) if (opts.valueKind && NUMERIC_VALUE_KINDS.has(opts.valueKind)) {
|
|
28
|
+
const value = coerceNumericText(text, opts.valueKind);
|
|
29
|
+
if (value === void 0) return {
|
|
29
30
|
items: [],
|
|
30
31
|
hasMore: false
|
|
31
32
|
};
|
|
32
|
-
conditions.push({ [field]:
|
|
33
|
+
conditions.push({ [field]: value });
|
|
33
34
|
} else conditions.push({ [field]: { $regex: `/^${escapeRegex(text)}/i` } });
|
|
34
35
|
const filter = conditions.length > 1 ? { $and: conditions } : conditions[0];
|
|
35
36
|
const rows = await client.aggregate({
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
const require_str = require("../shared/str.cjs");
|
|
2
|
+
const require_create_table_def = require("../table/create-table-def.cjs");
|
|
3
|
+
const require_value_kind = require("../table/value-kind.cjs");
|
|
2
4
|
//#region src/value-help/value-help-client.ts
|
|
3
5
|
let cacheTtl = 5e3;
|
|
4
6
|
let searches = /* @__PURE__ */ new WeakMap();
|
|
@@ -100,7 +102,8 @@ var ValueHelpClient = class {
|
|
|
100
102
|
if (text) if (resolved.searchable) controls.$search = text;
|
|
101
103
|
else {
|
|
102
104
|
const keyField = valueField ?? resolved.primaryKeys[0] ?? resolved.labelField;
|
|
103
|
-
const search = buildOrFilter(text, computeSelectFields(resolved, mode, valueField), keyField);
|
|
105
|
+
const search = buildOrFilter(text, computeSelectFields(resolved, mode, valueField), keyField, resolved.targetType);
|
|
106
|
+
if (!search) return { items: [] };
|
|
104
107
|
filter = scope ? { $and: [scope, search] } : search;
|
|
105
108
|
}
|
|
106
109
|
const items = await sharedQuery(this._client, {
|
|
@@ -135,18 +138,51 @@ function computeSelectFields(resolved, mode, valueField) {
|
|
|
135
138
|
if (mode === "filter") fields.push(...resolved.attrFields);
|
|
136
139
|
return [...new Set(fields)];
|
|
137
140
|
}
|
|
141
|
+
/** Storage kinds the server matches text against (`$regex`): strings and whole numbers. */
|
|
142
|
+
const TEXT_MATCHED = new Set([
|
|
143
|
+
"string",
|
|
144
|
+
"date",
|
|
145
|
+
"isoDate",
|
|
146
|
+
"integer"
|
|
147
|
+
]);
|
|
138
148
|
/**
|
|
139
|
-
* Build a Uniquery `$or` filter for value-help search across multiple fields
|
|
140
|
-
*
|
|
149
|
+
* Build a Uniquery `$or` filter for value-help search across multiple fields:
|
|
150
|
+
* a case-insensitive prefix `$regex` on each field the server matches text
|
|
151
|
+
* against, and an exact match on the key — typed by the key's storage kind, and
|
|
152
|
+
* only when `text` is a value of it (the server refuses `"Acme"` against a
|
|
153
|
+
* numeric key, and the whole `$or` with it). `undefined` when no condition is
|
|
154
|
+
* left. A field `targetType` does not describe keeps the old typing: regex, and
|
|
155
|
+
* a number key when the text is one.
|
|
141
156
|
*/
|
|
142
|
-
function buildOrFilter(text, fields,
|
|
157
|
+
function buildOrFilter(text, fields, keyField, targetType) {
|
|
158
|
+
const props = (targetType?.type)?.props;
|
|
143
159
|
const escaped = require_str.escapeRegex(text);
|
|
144
160
|
const conditions = [];
|
|
145
|
-
for (const field of fields)
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
161
|
+
for (const field of fields) {
|
|
162
|
+
if (field === keyField) continue;
|
|
163
|
+
const prop = props?.get(field);
|
|
164
|
+
if (!prop || TEXT_MATCHED.has(require_create_table_def.inferValueKind(prop))) conditions.push({ [field]: { $regex: `/^${escaped}/i` } });
|
|
165
|
+
}
|
|
166
|
+
const key = keyComparand(text, props?.get(keyField));
|
|
167
|
+
if (key !== void 0) conditions.push({ [keyField]: key });
|
|
168
|
+
return conditions.length > 0 ? { $or: conditions } : void 0;
|
|
169
|
+
}
|
|
170
|
+
/** `text` as a value of the key field, or `undefined` when it is none. */
|
|
171
|
+
function keyComparand(text, prop) {
|
|
172
|
+
if (!prop) {
|
|
173
|
+
const n = Number(text);
|
|
174
|
+
return Number.isNaN(n) ? text : n;
|
|
175
|
+
}
|
|
176
|
+
const kind = require_create_table_def.inferValueKind(prop);
|
|
177
|
+
switch (kind) {
|
|
178
|
+
case "number":
|
|
179
|
+
case "integer":
|
|
180
|
+
case "decimal":
|
|
181
|
+
case "long":
|
|
182
|
+
case "timestamp": return require_value_kind.coerceNumericText(text, kind);
|
|
183
|
+
case "boolean": return;
|
|
184
|
+
default: return text;
|
|
185
|
+
}
|
|
150
186
|
}
|
|
151
187
|
//#endregion
|
|
152
188
|
exports.ValueHelpClient = ValueHelpClient;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { escapeRegex } from "../shared/str.mjs";
|
|
2
|
+
import { inferValueKind } from "../table/create-table-def.mjs";
|
|
3
|
+
import { coerceNumericText } from "../table/value-kind.mjs";
|
|
2
4
|
//#region src/value-help/value-help-client.ts
|
|
3
5
|
let cacheTtl = 5e3;
|
|
4
6
|
let searches = /* @__PURE__ */ new WeakMap();
|
|
@@ -100,7 +102,8 @@ var ValueHelpClient = class {
|
|
|
100
102
|
if (text) if (resolved.searchable) controls.$search = text;
|
|
101
103
|
else {
|
|
102
104
|
const keyField = valueField ?? resolved.primaryKeys[0] ?? resolved.labelField;
|
|
103
|
-
const search = buildOrFilter(text, computeSelectFields(resolved, mode, valueField), keyField);
|
|
105
|
+
const search = buildOrFilter(text, computeSelectFields(resolved, mode, valueField), keyField, resolved.targetType);
|
|
106
|
+
if (!search) return { items: [] };
|
|
104
107
|
filter = scope ? { $and: [scope, search] } : search;
|
|
105
108
|
}
|
|
106
109
|
const items = await sharedQuery(this._client, {
|
|
@@ -135,18 +138,51 @@ function computeSelectFields(resolved, mode, valueField) {
|
|
|
135
138
|
if (mode === "filter") fields.push(...resolved.attrFields);
|
|
136
139
|
return [...new Set(fields)];
|
|
137
140
|
}
|
|
141
|
+
/** Storage kinds the server matches text against (`$regex`): strings and whole numbers. */
|
|
142
|
+
const TEXT_MATCHED = new Set([
|
|
143
|
+
"string",
|
|
144
|
+
"date",
|
|
145
|
+
"isoDate",
|
|
146
|
+
"integer"
|
|
147
|
+
]);
|
|
138
148
|
/**
|
|
139
|
-
* Build a Uniquery `$or` filter for value-help search across multiple fields
|
|
140
|
-
*
|
|
149
|
+
* Build a Uniquery `$or` filter for value-help search across multiple fields:
|
|
150
|
+
* a case-insensitive prefix `$regex` on each field the server matches text
|
|
151
|
+
* against, and an exact match on the key — typed by the key's storage kind, and
|
|
152
|
+
* only when `text` is a value of it (the server refuses `"Acme"` against a
|
|
153
|
+
* numeric key, and the whole `$or` with it). `undefined` when no condition is
|
|
154
|
+
* left. A field `targetType` does not describe keeps the old typing: regex, and
|
|
155
|
+
* a number key when the text is one.
|
|
141
156
|
*/
|
|
142
|
-
function buildOrFilter(text, fields,
|
|
157
|
+
function buildOrFilter(text, fields, keyField, targetType) {
|
|
158
|
+
const props = (targetType?.type)?.props;
|
|
143
159
|
const escaped = escapeRegex(text);
|
|
144
160
|
const conditions = [];
|
|
145
|
-
for (const field of fields)
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
161
|
+
for (const field of fields) {
|
|
162
|
+
if (field === keyField) continue;
|
|
163
|
+
const prop = props?.get(field);
|
|
164
|
+
if (!prop || TEXT_MATCHED.has(inferValueKind(prop))) conditions.push({ [field]: { $regex: `/^${escaped}/i` } });
|
|
165
|
+
}
|
|
166
|
+
const key = keyComparand(text, props?.get(keyField));
|
|
167
|
+
if (key !== void 0) conditions.push({ [keyField]: key });
|
|
168
|
+
return conditions.length > 0 ? { $or: conditions } : void 0;
|
|
169
|
+
}
|
|
170
|
+
/** `text` as a value of the key field, or `undefined` when it is none. */
|
|
171
|
+
function keyComparand(text, prop) {
|
|
172
|
+
if (!prop) {
|
|
173
|
+
const n = Number(text);
|
|
174
|
+
return Number.isNaN(n) ? text : n;
|
|
175
|
+
}
|
|
176
|
+
const kind = inferValueKind(prop);
|
|
177
|
+
switch (kind) {
|
|
178
|
+
case "number":
|
|
179
|
+
case "integer":
|
|
180
|
+
case "decimal":
|
|
181
|
+
case "long":
|
|
182
|
+
case "timestamp": return coerceNumericText(text, kind);
|
|
183
|
+
case "boolean": return;
|
|
184
|
+
default: return text;
|
|
185
|
+
}
|
|
150
186
|
}
|
|
151
187
|
//#endregion
|
|
152
188
|
export { ValueHelpClient, invalidateValueHelpCache, setValueHelpCacheTtl, valueHelpSelect };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/ui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.205",
|
|
4
4
|
"description": "Framework-agnostic runtime for form and table definitions from atscript annotated types",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"annotations",
|
|
@@ -51,21 +51,20 @@
|
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|
|
53
53
|
},
|
|
54
|
-
"dependencies": {
|
|
55
|
-
"@atscript/db-client": "^0.1.206"
|
|
56
|
-
},
|
|
57
54
|
"devDependencies": {
|
|
58
|
-
"@atscript/core": "^0.2.
|
|
59
|
-
"@atscript/db": "^0.1.
|
|
60
|
-
"@atscript/
|
|
61
|
-
"@
|
|
62
|
-
"
|
|
55
|
+
"@atscript/core": "^0.2.31",
|
|
56
|
+
"@atscript/db": "^0.1.209",
|
|
57
|
+
"@atscript/db-client": "^0.1.209",
|
|
58
|
+
"@atscript/typescript": "^0.2.31",
|
|
59
|
+
"@uniqu/core": "^0.3.0",
|
|
60
|
+
"unplugin-atscript": "^0.2.31",
|
|
63
61
|
"vitest": "npm:@voidzero-dev/vite-plus-test@0.1.14"
|
|
64
62
|
},
|
|
65
63
|
"peerDependencies": {
|
|
66
|
-
"@atscript/core": "^0.2.
|
|
67
|
-
"@atscript/db": "^0.1.
|
|
68
|
-
"@atscript/
|
|
64
|
+
"@atscript/core": "^0.2.31",
|
|
65
|
+
"@atscript/db": "^0.1.209",
|
|
66
|
+
"@atscript/db-client": "^0.1.209",
|
|
67
|
+
"@atscript/typescript": "^0.2.31"
|
|
69
68
|
},
|
|
70
69
|
"scripts": {
|
|
71
70
|
"build": "vp pack",
|