@atscript/ui 0.1.204 → 0.1.206

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.
Files changed (61) hide show
  1. package/dist/form/create-form-def.cjs +72 -83
  2. package/dist/form/create-form-def.d.cts +32 -22
  3. package/dist/form/create-form-def.d.mts +32 -22
  4. package/dist/form/create-form-def.mjs +73 -84
  5. package/dist/form/db-column.cjs +37 -0
  6. package/dist/form/db-column.mjs +35 -0
  7. package/dist/form/decimal-format.cjs +9 -11
  8. package/dist/form/decimal-format.mjs +9 -11
  9. package/dist/form/diff.cjs +32 -14
  10. package/dist/form/diff.d.cts +7 -4
  11. package/dist/form/diff.d.mts +7 -4
  12. package/dist/form/diff.mjs +32 -14
  13. package/dist/form/loaded-empty.cjs +56 -0
  14. package/dist/form/loaded-empty.d.cts +25 -0
  15. package/dist/form/loaded-empty.d.mts +25 -0
  16. package/dist/form/loaded-empty.mjs +56 -0
  17. package/dist/form/omit-derived.cjs +38 -0
  18. package/dist/form/omit-derived.d.cts +17 -0
  19. package/dist/form/omit-derived.d.mts +17 -0
  20. package/dist/form/omit-derived.mjs +38 -0
  21. package/dist/form/optional-mode.cjs +85 -0
  22. package/dist/form/optional-mode.d.cts +58 -0
  23. package/dist/form/optional-mode.d.mts +58 -0
  24. package/dist/form/optional-mode.mjs +82 -0
  25. package/dist/form/path-utils.cjs +14 -10
  26. package/dist/form/path-utils.mjs +14 -10
  27. package/dist/form/types.d.cts +16 -16
  28. package/dist/form/types.d.mts +16 -16
  29. package/dist/form/validate.cjs +2 -2
  30. package/dist/form/validate.mjs +2 -2
  31. package/dist/index.cjs +23 -4
  32. package/dist/index.d.cts +7 -3
  33. package/dist/index.d.mts +7 -3
  34. package/dist/index.mjs +10 -6
  35. package/dist/plugin/annotations.cjs +12 -0
  36. package/dist/plugin/annotations.mjs +13 -1
  37. package/dist/plugin/value-help-validation.cjs +25 -1
  38. package/dist/plugin/value-help-validation.mjs +25 -2
  39. package/dist/shared/annotation-keys.cjs +3 -0
  40. package/dist/shared/annotation-keys.d.cts +3 -1
  41. package/dist/shared/annotation-keys.d.mts +3 -1
  42. package/dist/shared/annotation-keys.mjs +3 -1
  43. package/dist/shared/exact-number.cjs +12 -0
  44. package/dist/shared/exact-number.mjs +12 -0
  45. package/dist/shared/meta-cache.cjs +1 -1
  46. package/dist/shared/meta-cache.mjs +1 -1
  47. package/dist/table/create-table-def.cjs +4 -1
  48. package/dist/table/create-table-def.mjs +4 -2
  49. package/dist/table/types.d.cts +23 -16
  50. package/dist/table/types.d.mts +23 -16
  51. package/dist/table/value-kind.cjs +37 -2
  52. package/dist/table/value-kind.d.cts +22 -2
  53. package/dist/table/value-kind.d.mts +22 -2
  54. package/dist/table/value-kind.mjs +36 -3
  55. package/dist/value-help/distinct-client.cjs +5 -4
  56. package/dist/value-help/distinct-client.d.cts +8 -2
  57. package/dist/value-help/distinct-client.d.mts +8 -2
  58. package/dist/value-help/distinct-client.mjs +5 -4
  59. package/dist/value-help/value-help-client.cjs +45 -9
  60. package/dist/value-help/value-help-client.mjs +45 -9
  61. package/package.json +11 -12
@@ -2,8 +2,28 @@ import { TFormEntryOptions } from "../value-help/types.mjs";
2
2
  import { ColumnValueKind } from "./types.mjs";
3
3
 
4
4
  //#region src/table/value-kind.d.ts
5
- /** Storage kinds that hold plain numbers (a `timestamp` is epoch ms, but filters treat it as a date). */
5
+ /**
6
+ * Storage kinds that hold numbers (a `timestamp` is epoch ms, but filters treat
7
+ * it as a date). A `decimal` or `long` value is exact numeric text, not a JS
8
+ * number.
9
+ */
6
10
  declare const NUMERIC_VALUE_KINDS: ReadonlySet<ColumnValueKind>;
11
+ /** Whether `raw` is plain decimal-number text (`12`, `-0.5`, `1e3`) — not `Infinity`, `0x1`, or `1_000`. Since 0.1.205. */
12
+ declare function isNumericText(raw: string): boolean;
13
+ /**
14
+ * The typed value of numeric text — what a filter or a search sends for a
15
+ * field of storage kind `valueKind` — or `undefined` when the text is no such
16
+ * value:
17
+ *
18
+ * - an `integer` takes whole numbers only;
19
+ * - a `decimal` keeps the text as a **string** (a JS number would round it);
20
+ * - a `long` takes integer text within the 64-bit range, as canonical text
21
+ * (`" +007 "` → `"7"`);
22
+ * - any other kind gets a finite number.
23
+ *
24
+ * Since 0.1.205 (`@atscript/ui-table`'s filter coercion before).
25
+ */
26
+ declare function coerceNumericText(raw: string, valueKind?: ColumnValueKind): string | number | undefined;
7
27
  /**
8
28
  * The typed value of an option — a column's or a form field's — the literal
9
29
  * itself (`true`, `3`, `'a'`), falling back to the string `key` for a hand-built
@@ -13,4 +33,4 @@ declare const NUMERIC_VALUE_KINDS: ReadonlySet<ColumnValueKind>;
13
33
  */
14
34
  declare function optionValue(option: TFormEntryOptions): string | number | boolean;
15
35
  //#endregion
16
- export { NUMERIC_VALUE_KINDS, optionValue };
36
+ export { NUMERIC_VALUE_KINDS, coerceNumericText, isNumericText, optionValue };
@@ -1,10 +1,43 @@
1
+ import { canonicalLong } from "@atscript/db/meta";
1
2
  //#region src/table/value-kind.ts
2
- /** Storage kinds that hold plain numbers (a `timestamp` is epoch ms, but filters treat it as a date). */
3
+ /**
4
+ * Storage kinds that hold numbers (a `timestamp` is epoch ms, but filters treat
5
+ * it as a date). A `decimal` or `long` value is exact numeric text, not a JS
6
+ * number.
7
+ */
3
8
  const NUMERIC_VALUE_KINDS = new Set([
4
9
  "number",
5
10
  "integer",
6
- "decimal"
11
+ "decimal",
12
+ "long"
7
13
  ]);
14
+ const NUMERIC_TEXT = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/;
15
+ /** Whether `raw` is plain decimal-number text (`12`, `-0.5`, `1e3`) — not `Infinity`, `0x1`, or `1_000`. Since 0.1.205. */
16
+ function isNumericText(raw) {
17
+ return NUMERIC_TEXT.test(raw.trim());
18
+ }
19
+ /**
20
+ * The typed value of numeric text — what a filter or a search sends for a
21
+ * field of storage kind `valueKind` — or `undefined` when the text is no such
22
+ * value:
23
+ *
24
+ * - an `integer` takes whole numbers only;
25
+ * - a `decimal` keeps the text as a **string** (a JS number would round it);
26
+ * - a `long` takes integer text within the 64-bit range, as canonical text
27
+ * (`" +007 "` → `"7"`);
28
+ * - any other kind gets a finite number.
29
+ *
30
+ * Since 0.1.205 (`@atscript/ui-table`'s filter coercion before).
31
+ */
32
+ function coerceNumericText(raw, valueKind) {
33
+ if (!isNumericText(raw)) return void 0;
34
+ const text = raw.trim();
35
+ if (valueKind === "decimal") return text;
36
+ if (valueKind === "long") return canonicalLong(text);
37
+ const n = Number(text);
38
+ if (!Number.isFinite(n)) return void 0;
39
+ return valueKind === "integer" && !Number.isInteger(n) ? void 0 : n;
40
+ }
8
41
  /**
9
42
  * The typed value of an option — a column's or a form field's — the literal
10
43
  * itself (`true`, `3`, `'a'`), falling back to the string `key` for a hand-built
@@ -16,4 +49,4 @@ function optionValue(option) {
16
49
  return typeof option === "string" ? option : option.value ?? option.key;
17
50
  }
18
51
  //#endregion
19
- export { NUMERIC_VALUE_KINDS, optionValue };
52
+ export { NUMERIC_VALUE_KINDS, coerceNumericText, isNumericText, optionValue };
@@ -1,5 +1,6 @@
1
1
  const require_path_utils = require("../form/path-utils.cjs");
2
2
  const require_str = require("../shared/str.cjs");
3
+ const require_value_kind = require("../table/value-kind.cjs");
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.numeric) {
27
- const n = Number(text);
28
- if (!Number.isFinite(n)) return {
27
+ if (text) if (opts.valueKind && require_value_kind.NUMERIC_VALUE_KINDS.has(opts.valueKind)) {
28
+ const value = require_value_kind.coerceNumericText(text, opts.valueKind);
29
+ if (value === void 0) return {
29
30
  items: [],
30
31
  hasMore: false
31
32
  };
32
- conditions.push({ [field]: n });
33
+ conditions.push({ [field]: value });
33
34
  } else conditions.push({ [field]: { $regex: `/^${require_str.escapeRegex(text)}/i` } });
34
35
  const filter = conditions.length > 1 ? { $and: conditions } : conditions[0];
35
36
  const rows = await client.aggregate({
@@ -1,3 +1,4 @@
1
+ import { ColumnValueKind } from "../table/types.cjs";
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
- /** The field stores numbers: search is an exact match and non-numeric text finds nothing. */
17
- numeric?: boolean;
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,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
- /** The field stores numbers: search is an exact match and non-numeric text finds nothing. */
17
- numeric?: boolean;
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.numeric) {
27
- const n = Number(text);
28
- if (!Number.isFinite(n)) return {
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]: n });
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
- * Uses regex startsWith (case-insensitive) on text fields + exact match on PK.
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, pkField) {
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) if (field !== pkField) conditions.push({ [field]: { $regex: `/^${escaped}/i` } });
146
- const asNum = Number(text);
147
- if (!Number.isNaN(asNum)) conditions.push({ [pkField]: asNum });
148
- else conditions.push({ [pkField]: text });
149
- return { $or: conditions };
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
- * Uses regex startsWith (case-insensitive) on text fields + exact match on PK.
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, pkField) {
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) if (field !== pkField) conditions.push({ [field]: { $regex: `/^${escaped}/i` } });
146
- const asNum = Number(text);
147
- if (!Number.isNaN(asNum)) conditions.push({ [pkField]: asNum });
148
- else conditions.push({ [pkField]: text });
149
- return { $or: conditions };
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.204",
3
+ "version": "0.1.206",
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.208"
56
- },
57
54
  "devDependencies": {
58
- "@atscript/core": "^0.2.30",
59
- "@atscript/db": "^0.1.208",
60
- "@atscript/typescript": "^0.2.30",
61
- "@uniqu/core": "^0.2.3",
62
- "unplugin-atscript": "^0.2.30",
55
+ "@atscript/core": "^0.2.32",
56
+ "@atscript/db": "^0.1.210",
57
+ "@atscript/db-client": "^0.1.210",
58
+ "@atscript/typescript": "^0.2.32",
59
+ "@uniqu/core": "^0.3.0",
60
+ "unplugin-atscript": "^0.2.32",
63
61
  "vitest": "npm:@voidzero-dev/vite-plus-test@0.1.14"
64
62
  },
65
63
  "peerDependencies": {
66
- "@atscript/core": "^0.2.30",
67
- "@atscript/db": "^0.1.208",
68
- "@atscript/typescript": "^0.2.30"
64
+ "@atscript/core": "^0.2.32",
65
+ "@atscript/db": "^0.1.210",
66
+ "@atscript/db-client": "^0.1.210",
67
+ "@atscript/typescript": "^0.2.32"
69
68
  },
70
69
  "scripts": {
71
70
  "build": "vp pack",