@atscript/ui 0.1.196 → 0.1.197

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.
@@ -1,5 +1,6 @@
1
1
  const require_annotation_keys = require("../shared/annotation-keys.cjs");
2
2
  const require_field_resolver = require("../shared/field-resolver.cjs");
3
+ const require_extract_ref = require("../value-help/extract-ref.cjs");
3
4
  let _atscript_typescript_utils = require("@atscript/typescript/utils");
4
5
  //#region src/form/path-utils.ts
5
6
  /**
@@ -132,9 +133,21 @@ function primitiveInitFallback(prop) {
132
133
  }
133
134
  }
134
135
  function createFormData(type, resolver) {
135
- let value = (0, _atscript_typescript_utils.createDataFromAnnotatedType)(type, { mode: resolver ?? defaultValueResolver });
136
+ const resolve = resolver ?? defaultValueResolver;
137
+ const pickers = /* @__PURE__ */ new Map();
138
+ const unset = [];
139
+ let value = (0, _atscript_typescript_utils.createDataFromAnnotatedType)(type, { mode: (prop, path) => {
140
+ const resolved = resolve(prop, path);
141
+ if (resolved !== void 0) return resolved;
142
+ if (pickers.get(path) === prop) unset.push(path);
143
+ else if (prop.type.kind === "object") {
144
+ for (const [key, child] of prop.type.props) if (child.type.kind === "" && require_extract_ref.extractValueHelp(child)) pickers.set(joinPath(path, key), child);
145
+ }
146
+ } });
136
147
  if (value === void 0) value = primitiveInitFallback(type);
137
- return { value };
148
+ const data = { value };
149
+ for (const path of unset) deleteByPath(data, path);
150
+ return data;
138
151
  }
139
152
  const variantValidatorCache = /* @__PURE__ */ new WeakMap();
140
153
  function getVariantValidator(variant) {
@@ -1,5 +1,6 @@
1
1
  import { META_DEFAULT, UI_FORM_FN_VALUE } from "../shared/annotation-keys.mjs";
2
2
  import { resolveFieldProp } from "../shared/field-resolver.mjs";
3
+ import { extractValueHelp } from "../value-help/extract-ref.mjs";
3
4
  import { createDataFromAnnotatedType, detectDiscriminator } from "@atscript/typescript/utils";
4
5
  //#region src/form/path-utils.ts
5
6
  /**
@@ -132,9 +133,21 @@ function primitiveInitFallback(prop) {
132
133
  }
133
134
  }
134
135
  function createFormData(type, resolver) {
135
- let value = createDataFromAnnotatedType(type, { mode: resolver ?? defaultValueResolver });
136
+ const resolve = resolver ?? defaultValueResolver;
137
+ const pickers = /* @__PURE__ */ new Map();
138
+ const unset = [];
139
+ let value = createDataFromAnnotatedType(type, { mode: (prop, path) => {
140
+ const resolved = resolve(prop, path);
141
+ if (resolved !== void 0) return resolved;
142
+ if (pickers.get(path) === prop) unset.push(path);
143
+ else if (prop.type.kind === "object") {
144
+ for (const [key, child] of prop.type.props) if (child.type.kind === "" && extractValueHelp(child)) pickers.set(joinPath(path, key), child);
145
+ }
146
+ } });
136
147
  if (value === void 0) value = primitiveInitFallback(type);
137
- return { value };
148
+ const data = { value };
149
+ for (const path of unset) deleteByPath(data, path);
150
+ return data;
138
151
  }
139
152
  const variantValidatorCache = /* @__PURE__ */ new WeakMap();
140
153
  function getVariantValidator(variant) {
@@ -1,4 +1,4 @@
1
- require("../shared/annotation-keys.cjs");
1
+ const require_annotation_keys = require("../shared/annotation-keys.cjs");
2
2
  const require_types = require("./types.cjs");
3
3
  const require_ui_texts = require("../i18n/ui-texts.cjs");
4
4
  const require_skipped_nav = require("./skipped-nav.cjs");
@@ -43,8 +43,10 @@ const INSERT_CONTEXT = { mode: "insert" };
43
43
  * - an absent `@db.default*` / `@db.column.version` / `@db.onUpdate.inc` value
44
44
  * — delegated to `@atscript/db`'s own insert-mode rule, so the key list has
45
45
  * one owner.
46
- * `db.rel.FK` is kept out: a form fills the FK itself (no nested nav
47
- * object), so an empty required FK must still fail.
46
+ * That rule passes every absent `@db.rel.FK` too (a nested related row can
47
+ * fill it), but a form fills the FK itself: the rule gets the field without
48
+ * its FK marker, so an empty FK still fails unless the database fills it (a
49
+ * `@db.default*` of its own).
48
50
  *
49
51
  * The db plugin reads its mode from the validation context, which here
50
52
  * carries the form's `{ data, context }` — it gets a view of `ctx` with the
@@ -52,9 +54,16 @@ const INSERT_CONTEXT = { mode: "insert" };
52
54
  */
53
55
  const serverManagedPlugin = (ctx, def, value) => {
54
56
  if (def.metadata.has("db.column.derived") || require_skipped_nav.isSkippedNavField(def)) return true;
55
- if (value !== void 0 || def.metadata.has("db.rel.FK")) return void 0;
56
- return dbPlugin(Object.create(ctx, { context: { value: INSERT_CONTEXT } }), def, value);
57
+ if (value !== void 0) return void 0;
58
+ return dbPlugin(Object.create(ctx, { context: { value: INSERT_CONTEXT } }), withoutFk(def), value);
57
59
  };
60
+ /** A view of `def` without its `@db.rel.FK` marker — `def` itself when it has none. */
61
+ function withoutFk(def) {
62
+ if (!def.metadata.has("db.rel.FK")) return def;
63
+ const metadata = new Map(def.metadata);
64
+ metadata.delete(require_annotation_keys.DB_REL_FK);
65
+ return Object.create(def, { metadata: { value: metadata } });
66
+ }
58
67
  /**
59
68
  * The props of the fields `createFormDef` marked `derived`, at any depth — a
60
69
  * computed view column (`metaFields`) or an edit form's update-stamped field
@@ -1,4 +1,4 @@
1
- import "../shared/annotation-keys.mjs";
1
+ import { DB_REL_FK } from "../shared/annotation-keys.mjs";
2
2
  import { childFields } from "./types.mjs";
3
3
  import { getUiTexts } from "../i18n/ui-texts.mjs";
4
4
  import { isSkippedNavField } from "./skipped-nav.mjs";
@@ -43,8 +43,10 @@ const INSERT_CONTEXT = { mode: "insert" };
43
43
  * - an absent `@db.default*` / `@db.column.version` / `@db.onUpdate.inc` value
44
44
  * — delegated to `@atscript/db`'s own insert-mode rule, so the key list has
45
45
  * one owner.
46
- * `db.rel.FK` is kept out: a form fills the FK itself (no nested nav
47
- * object), so an empty required FK must still fail.
46
+ * That rule passes every absent `@db.rel.FK` too (a nested related row can
47
+ * fill it), but a form fills the FK itself: the rule gets the field without
48
+ * its FK marker, so an empty FK still fails unless the database fills it (a
49
+ * `@db.default*` of its own).
48
50
  *
49
51
  * The db plugin reads its mode from the validation context, which here
50
52
  * carries the form's `{ data, context }` — it gets a view of `ctx` with the
@@ -52,9 +54,16 @@ const INSERT_CONTEXT = { mode: "insert" };
52
54
  */
53
55
  const serverManagedPlugin = (ctx, def, value) => {
54
56
  if (def.metadata.has("db.column.derived") || isSkippedNavField(def)) return true;
55
- if (value !== void 0 || def.metadata.has("db.rel.FK")) return void 0;
56
- return dbPlugin(Object.create(ctx, { context: { value: INSERT_CONTEXT } }), def, value);
57
+ if (value !== void 0) return void 0;
58
+ return dbPlugin(Object.create(ctx, { context: { value: INSERT_CONTEXT } }), withoutFk(def), value);
57
59
  };
60
+ /** A view of `def` without its `@db.rel.FK` marker — `def` itself when it has none. */
61
+ function withoutFk(def) {
62
+ if (!def.metadata.has("db.rel.FK")) return def;
63
+ const metadata = new Map(def.metadata);
64
+ metadata.delete(DB_REL_FK);
65
+ return Object.create(def, { metadata: { value: metadata } });
66
+ }
58
67
  /**
59
68
  * The props of the fields `createFormDef` marked `derived`, at any depth — a
60
69
  * computed view column (`metaFields`) or an edit form's update-stamped field
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/ui",
3
- "version": "0.1.196",
3
+ "version": "0.1.197",
4
4
  "description": "Framework-agnostic runtime for form and table definitions from atscript annotated types",
5
5
  "keywords": [
6
6
  "annotations",
@@ -52,20 +52,20 @@
52
52
  "access": "public"
53
53
  },
54
54
  "dependencies": {
55
- "@atscript/db-client": "^0.1.201"
55
+ "@atscript/db-client": "^0.1.202"
56
56
  },
57
57
  "devDependencies": {
58
- "@atscript/core": "^0.2.26",
59
- "@atscript/db": "^0.1.201",
60
- "@atscript/typescript": "^0.2.26",
58
+ "@atscript/core": "^0.2.27",
59
+ "@atscript/db": "^0.1.202",
60
+ "@atscript/typescript": "^0.2.27",
61
61
  "@uniqu/core": "^0.2.2",
62
- "unplugin-atscript": "^0.2.26",
62
+ "unplugin-atscript": "^0.2.27",
63
63
  "vitest": "npm:@voidzero-dev/vite-plus-test@0.1.14"
64
64
  },
65
65
  "peerDependencies": {
66
- "@atscript/core": "^0.2.26",
67
- "@atscript/db": "^0.1.201",
68
- "@atscript/typescript": "^0.2.26"
66
+ "@atscript/core": "^0.2.27",
67
+ "@atscript/db": "^0.1.202",
68
+ "@atscript/typescript": "^0.2.27"
69
69
  },
70
70
  "scripts": {
71
71
  "build": "vp pack",