@dialecte/core 0.4.7 → 0.4.8

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,10 +1,32 @@
1
1
  import { Ref, RefOrRecord } from '../document';
2
- import { RawRecord, TrackedRecord, TreeRecord, AnyDialecteConfig, AttributeInputOf, ElementsOf, FullAttributeObjectOf, AttributesValueObjectOf, OperationStatus, ParentRelationship, ChildRelationship } from '../types';
2
+ import { RawRecord, TrackedRecord, TreeRecord, AnyDialecteConfig, Attribute, AttributeInputOf, ElementsOf, FullAttributeObjectOf, AttributesValueObjectOf, OperationStatus, ParentRelationship, ChildRelationship } from '../types';
3
3
  /**
4
4
  * Converts a TrackedRecord | TreeRecord to RawRecord
5
5
  * If already a RawRecord, returns as-is.
6
6
  */
7
7
  export declare function toRawRecord<GenericConfig extends AnyDialecteConfig, GenericElement extends ElementsOf<GenericConfig>>(record: RawRecord<GenericConfig, GenericElement> | TrackedRecord<GenericConfig, GenericElement> | TreeRecord<GenericConfig, GenericElement>): RawRecord<GenericConfig, GenericElement>;
8
+ /**
9
+ * Widen any per-element dialecte value to its element-union form — the same value,
10
+ * with its element type parameter widened from a specific `GenericElement` to
11
+ * `ElementsOf<GenericConfig>`.
12
+ *
13
+ * A `RawRecord<Config, GenericElement>` (or `Ref`, `Attribute`, …) is semantically
14
+ * one of the element union, but these types are invariant in their element
15
+ * parameter (the attribute `name`/`tagName` narrows per element), so TypeScript
16
+ * cannot verify the upcast for an unresolved type parameter. `widen` performs it
17
+ * in one place, behind overloads that keep it a *widening* (not an arbitrary cast):
18
+ * the config is inferred from the argument, so callers write `widen(record)` with
19
+ * no type arguments. At runtime it is the identity function.
20
+ *
21
+ * Use it wherever a per-element value must flow into an element-union API — e.g.
22
+ * building an `Operation`, or passing a `Ref<Config, GenericElement>` to a
23
+ * union-typed method.
24
+ */
25
+ export declare function widen<GenericConfig extends AnyDialecteConfig, GenericElement extends ElementsOf<GenericConfig>>(thing: TreeRecord<GenericConfig, GenericElement>): TreeRecord<GenericConfig, ElementsOf<GenericConfig>>;
26
+ export declare function widen<GenericConfig extends AnyDialecteConfig, GenericElement extends ElementsOf<GenericConfig>>(thing: TrackedRecord<GenericConfig, GenericElement>): TrackedRecord<GenericConfig, ElementsOf<GenericConfig>>;
27
+ export declare function widen<GenericConfig extends AnyDialecteConfig, GenericElement extends ElementsOf<GenericConfig>>(thing: RawRecord<GenericConfig, GenericElement>): RawRecord<GenericConfig, ElementsOf<GenericConfig>>;
28
+ export declare function widen<GenericConfig extends AnyDialecteConfig, GenericElement extends ElementsOf<GenericConfig>>(thing: Ref<GenericConfig, GenericElement>): Ref<GenericConfig, ElementsOf<GenericConfig>>;
29
+ export declare function widen<GenericConfig extends AnyDialecteConfig, GenericElement extends ElementsOf<GenericConfig>>(thing: Attribute<GenericConfig, GenericElement>): Attribute<GenericConfig, ElementsOf<GenericConfig>>;
8
30
  /**
9
31
  * Converts a RawRecord | TreeRecord to TrackedRecord
10
32
  * If already a TrackedRecord, returns as-is.
@@ -1 +1 @@
1
- {"version":3,"file":"converter.d.ts","sourceRoot":"","sources":["../../src/helpers/converter.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAClD,OAAO,KAAK,EACX,SAAS,EACT,aAAa,EACb,UAAU,EACV,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,EACV,qBAAqB,EACrB,uBAAuB,EAEvB,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,MAAM,SAAS,CAAA;AAEhB;;;GAGG;AACH,wBAAgB,WAAW,CAC1B,aAAa,SAAS,iBAAiB,EACvC,cAAc,SAAS,UAAU,CAAC,aAAa,CAAC,EAEhD,MAAM,EACH,SAAS,CAAC,aAAa,EAAE,cAAc,CAAC,GACxC,aAAa,CAAC,aAAa,EAAE,cAAc,CAAC,GAC5C,UAAU,CAAC,aAAa,EAAE,cAAc,CAAC,GAC1C,S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CAAC,GAC/D,gBAAgB,CAAC,aAAa,EAAE,cAAc,CAAC,EAAE,CAAA;CACpD,GAAG,qBAAqB,CAAC,aAAa,EAAE,cAAc,CAAC,EAAE,CAezD;AAmED;;;GAGG;AACH,wBAAgB,KAAK,CACpB,aAAa,SAAS,iBAAiB,EACvC,cAAc,SAAS,UAAU,CAAC,aAAa,CAAC,EAC/C,KAAK,EAAE,GAAG,CAAC,aAAa,EAAE,cAAc,CAAC,GAAG,SAAS,GAAG,GAAG,CAAC,aAAa,EAAE,cAAc,CAAC,CAAA;AAC5F,wBAAgB,KAAK,CACpB,aAAa,SAAS,iBAAiB,EACvC,cAAc,SAAS,UAAU,CAAC,aAAa,CAAC,EAEhD,KAAK,EACF,kBAAkB,CAAC,aAAa,EAAE,cAAc,CAAC,GACjD,iBAAiB,CAAC,aAAa,EAAE,cAAc,CAAC,GAChD,SAAS,GACV,GAAG,CAAC,aAAa,EAAE,cAAc,CAAC,CAAA;AACrC,wBAAgB,KAAK,CACpB,aAAa,SAAS,iBAAiB,EACvC,cAAc,SAAS,UAAU,CAAC,aAAa,CAAC,EAEhD,KAAK,EACF,SAAS,CAAC,aAAa,EAAE,cAAc,CAAC,GACxC,aAAa,CAAC,aAAa,EAAE,cAAc,CAAC,GAC5C,UAAU,CAAC,aAAa,EAAE,cAAc,CAAC,GACzC,SAAS,GACV,GAAG,CAAC,aAAa,EAAE,cAAc,CAAC,CAAA;AACrC,wBAAgB,KAAK,CACpB,aAAa,SAAS,iBAAiB,EACvC,cAAc,SAAS,UAAU,CAAC,aAAa,CAAC,EAC/C,KAAK,EAAE,WAAW,CAAC,aAAa,EAAE,cAAc,CAAC,GAAG,SAAS,GAAG,GAAG,CAAC,aAAa,EAAE,cAAc,CAAC,CAAA"}
package/dist/helpers.js CHANGED
@@ -64,35 +64,38 @@ function E(e) {
64
64
  };
65
65
  }
66
66
  function D(e) {
67
+ return e;
68
+ }
69
+ function O(e) {
67
70
  let { record: t, status: n } = e, r = n ?? ("status" in t ? t.status : "unchanged");
68
71
  return {
69
72
  ...E(t),
70
73
  status: r
71
74
  };
72
75
  }
73
- function O(e) {
76
+ function k(e) {
74
77
  let { record: t, status: n, tree: r } = e, i = r ?? ("tree" in t ? t.tree : []);
75
78
  return {
76
- ...D({
79
+ ...O({
77
80
  record: t,
78
81
  status: n
79
82
  }),
80
83
  tree: i
81
84
  };
82
85
  }
83
- function k(e) {
86
+ function A(e) {
84
87
  let { dialecteConfig: t, tagName: n, attributes: r } = e;
85
88
  return (Array.isArray(r) ? r : Object.entries(r).map(([e, r]) => ({
86
89
  name: e,
87
90
  value: r,
88
91
  namespace: t.definition[n]?.attributes.details[e]?.namespace || void 0
89
- }))).map((e) => A({
92
+ }))).map((e) => j({
90
93
  attribute: e,
91
94
  dialecteConfig: t,
92
95
  tagName: n
93
96
  }));
94
97
  }
95
- function A(t) {
98
+ function j(t) {
96
99
  let { attribute: r, dialecteConfig: a, tagName: s } = t, c;
97
100
  typeof r.namespace == "string" ? (c = o(a, r.namespace), c || i("UNKNOWN_NAMESPACE_PREFIX", {
98
101
  detail: `Unknown namespace '${r.namespace}' on attribute '${r.name}' — use a registered namespace key or pass a full { name, namespace: { prefix, uri } }.`,
@@ -115,7 +118,7 @@ function A(t) {
115
118
  namespace: c
116
119
  });
117
120
  }
118
- function j(e) {
121
+ function M(e) {
119
122
  return a(e, { detail: "The record or ref is undefined" }), {
120
123
  id: e.id,
121
124
  tagName: e.tagName
@@ -123,8 +126,8 @@ function j(e) {
123
126
  }
124
127
  //#endregion
125
128
  //#region src/helpers/standardizing.ts
126
- function M(e) {
127
- let { dialecteConfig: n, hooks: r, record: i } = e, { id: a, tagName: o, attributes: s, namespace: c, value: l } = i, u = a ?? crypto.randomUUID(), d = s ? k({
129
+ function N(e) {
130
+ let { dialecteConfig: n, hooks: r, record: i } = e, { id: a, tagName: o, attributes: s, namespace: c, value: l } = i, u = a ?? crypto.randomUUID(), d = s ? A({
128
131
  tagName: o,
129
132
  attributes: s,
130
133
  dialecteConfig: n
@@ -164,7 +167,7 @@ function M(e) {
164
167
  }
165
168
  //#endregion
166
169
  //#region src/helpers/assert-fixed.ts
167
- function N(e) {
170
+ function P(e) {
168
171
  let { dialecteConfig: t, tagName: n, attributes: a } = e;
169
172
  for (let e of a) {
170
173
  let a = r({
@@ -180,7 +183,7 @@ function N(e) {
180
183
  }
181
184
  //#endregion
182
185
  //#region src/helpers/merge-extensions.ts
183
- function P(e, t, n, r) {
186
+ function F(e, t, n, r) {
184
187
  if (!e || !t) return;
185
188
  let i = Object.keys(t).filter((t) => t in e);
186
189
  a(i.length === 0, {
@@ -188,12 +191,12 @@ function P(e, t, n, r) {
188
191
  detail: `Module "${n}" has conflicting ${r} method(s): ${i.map((e) => `"${e}"`).join(", ")}`
189
192
  });
190
193
  }
191
- function F(e) {
194
+ function I(e) {
192
195
  let t = {}, n = {}, r = [...Object.entries(e.base ?? {}), ...Object.entries(e.custom ?? {})];
193
- for (let [e, i] of r) i.query && (P(t[e], i.query, e, "query"), t[e] = {
196
+ for (let [e, i] of r) i.query && (F(t[e], i.query, e, "query"), t[e] = {
194
197
  ...t[e],
195
198
  ...i.query
196
- }), i.transaction && (P(n[e], i.transaction, e, "transaction"), n[e] = {
199
+ }), i.transaction && (F(n[e], i.transaction, e, "transaction"), n[e] = {
197
200
  ...n[e],
198
201
  ...i.transaction
199
202
  });
@@ -204,15 +207,15 @@ function F(e) {
204
207
  }
205
208
  //#endregion
206
209
  //#region src/helpers/strip-attributes.ts
207
- function I(e, t) {
210
+ function L(e, t) {
208
211
  let n = new Set(t), r = {
209
212
  ...e,
210
213
  attributes: e.attributes.filter((e) => !n.has(e.name))
211
214
  };
212
215
  return "tree" in e ? {
213
216
  ...r,
214
- tree: e.tree.map((e) => I(e, t))
217
+ tree: e.tree.map((e) => L(e, t))
215
218
  } : r;
216
219
  }
217
220
  //#endregion
218
- export { l as CUSTOM_RECORD_ID_ATTRIBUTE, s as CUSTOM_RECORD_ID_ATTRIBUTE_NAME, c as DIALECTE_DEV_NAMESPACE, f as DIALECTE_NAMESPACES, d as XMLNS_XSI_NAMESPACE, u as XSI_NAMESPACE, N as assertNoFixedViolation, T as isAttributeOf, S as isChildOf, w as isElementOf, _ as isFullAttributeArray, C as isParentOf, v as isRawRecord, x as isRecordOf, y as isTrackedRecord, b as isTreeRecord, F as mergeExtensions, M as standardizeRecord, I as stripAttributes, k as toFullAttributeArray, E as toRawRecord, j as toRef, D as toTrackedRecord, O as toTreeRecord };
221
+ export { l as CUSTOM_RECORD_ID_ATTRIBUTE, s as CUSTOM_RECORD_ID_ATTRIBUTE_NAME, c as DIALECTE_DEV_NAMESPACE, f as DIALECTE_NAMESPACES, d as XMLNS_XSI_NAMESPACE, u as XSI_NAMESPACE, P as assertNoFixedViolation, T as isAttributeOf, S as isChildOf, w as isElementOf, _ as isFullAttributeArray, C as isParentOf, v as isRawRecord, x as isRecordOf, y as isTrackedRecord, b as isTreeRecord, I as mergeExtensions, N as standardizeRecord, L as stripAttributes, A as toFullAttributeArray, E as toRawRecord, M as toRef, O as toTrackedRecord, k as toTreeRecord, D as widen };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dialecte/core",
3
- "version": "0.4.7",
3
+ "version": "0.4.8",
4
4
  "description": "Dialecte - Core functionality for Dialecte SDK",
5
5
  "license": "MIT",
6
6
  "repository": {