@dialecte/core 0.2.4 → 0.2.6

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.js CHANGED
@@ -1,4 +1,4 @@
1
- import { A as s, a as t, C as r, b as o, D as i, c as n, M as A, d as c, P as E, Q as l, T as u, e as T, f as m, g as D, h as d, i as C, j as _, k as b, l as g, m as M, n as R, o as S, p as B, q as O, r as y, s as L, t as N, u as f, v as p, w as F, y as G, z as H, B as h, E as x, F as I, G as P, H as j, I as X, J as w, K as Q, L as U, N as v } from "./index-D1JSZmI2.js";
1
+ import { A as s, a as t, C as r, b as o, D as i, c as n, M as A, d as c, P as E, Q as l, T as u, e as T, f as m, g as D, h as d, i as C, j as _, k as b, l as g, m as M, n as R, o as S, p as B, q as O, r as y, s as L, t as N, u as f, v as p, w as F, y as G, z as H, B as h, E as x, F as I, G as P, H as j, I as X, J as w, K as Q, L as U, N as v } from "./index-Bza8g-6Z.js";
2
2
  import { E as q, t as z } from "./index-DWV6tSGF.js";
3
3
  export {
4
4
  s as AnyQuery,
@@ -0,0 +1,172 @@
1
+ import { i as E } from "./index-DWV6tSGF.js";
2
+ const D = "db-id", v = {
3
+ uri: "http://dialecte.dev/XML/DEV",
4
+ prefix: "dev"
5
+ }, $ = `${v.prefix}:${D}`, b = [
6
+ "id",
7
+ "tagName",
8
+ "namespace",
9
+ "attributes",
10
+ "children",
11
+ "parent",
12
+ "value"
13
+ ], A = [...b, "status"], S = [...A, "tree"];
14
+ function d(e, t) {
15
+ if (typeof e != "object" || e === null)
16
+ return !1;
17
+ const n = Object.keys(e);
18
+ return t.every((a) => a in e) && n.every((a) => t.includes(a)) && n.length === t.length;
19
+ }
20
+ function I(e) {
21
+ return Array.isArray(e);
22
+ }
23
+ function z(e) {
24
+ return d(e, b);
25
+ }
26
+ function F(e) {
27
+ return d(e, A);
28
+ }
29
+ function K(e) {
30
+ return d(e, S);
31
+ }
32
+ function L(e, t) {
33
+ return e.tagName === t;
34
+ }
35
+ function V(e, t) {
36
+ return e.tagName === t;
37
+ }
38
+ function Y(e, t) {
39
+ return e.tagName === t;
40
+ }
41
+ function w(e, t) {
42
+ return t.elements.includes(e);
43
+ }
44
+ function B(e, t) {
45
+ return e.attributes.some((n) => n.name === t);
46
+ }
47
+ function M(e) {
48
+ return {
49
+ id: e.id,
50
+ tagName: e.tagName,
51
+ namespace: e.namespace,
52
+ attributes: e.attributes,
53
+ value: e.value,
54
+ parent: e.parent,
55
+ children: e.children
56
+ };
57
+ }
58
+ function j(e) {
59
+ const { record: t, status: n } = e, a = n ?? ("status" in t ? t.status : "unchanged");
60
+ return {
61
+ ...M(t),
62
+ status: a
63
+ };
64
+ }
65
+ function P(e) {
66
+ const { record: t, status: n, tree: a } = e, r = a ?? ("tree" in t ? t.tree : []);
67
+ return {
68
+ ...j({ record: t, status: n }),
69
+ tree: r
70
+ };
71
+ }
72
+ function k(e) {
73
+ const { dialecteConfig: t, tagName: n, attributes: a } = e;
74
+ return I(a) ? a : Object.entries(a).map(
75
+ ([r, s]) => ({
76
+ name: r,
77
+ value: s,
78
+ namespace: t.definition[n]?.attributes.details[r]?.namespace || void 0
79
+ })
80
+ );
81
+ }
82
+ function X(e) {
83
+ return E(e, {
84
+ detail: "The record or ref is undefined"
85
+ }), {
86
+ id: e.id,
87
+ tagName: e.tagName
88
+ };
89
+ }
90
+ function G(e) {
91
+ const { dialecteConfig: t, hooks: n, record: a } = e, { id: r, tagName: s, attributes: l, namespace: O, value: g } = a, N = r ?? crypto.randomUUID(), c = l ? k({ tagName: s, attributes: l, dialecteConfig: t }) : [], f = {
92
+ id: N,
93
+ tagName: s,
94
+ attributes: c,
95
+ namespace: O ?? {
96
+ prefix: "prefixNeededForNotSupportedNamespace",
97
+ uri: "uriNeededForNotSupportedNamespace"
98
+ },
99
+ value: g ?? "",
100
+ parent: a.parent ?? null,
101
+ children: a.children ?? []
102
+ };
103
+ if (!t.elements.includes(s)) return f;
104
+ const m = t.definition[s].attributes.sequence, o = t.definition[s].attributes.details, T = m.flatMap((i) => {
105
+ const h = o[i].required, _ = o[i]?.namespace || void 0, p = c.find((C) => C.name === i)?.value ?? (h ? o[i]?.default ?? "" : o[i]?.default);
106
+ return p === void 0 ? [] : [
107
+ {
108
+ name: i,
109
+ value: p,
110
+ namespace: _
111
+ }
112
+ ];
113
+ }), y = c.filter(
114
+ (i) => "namespace" in i && i.namespace != null && !m.includes(i.name)
115
+ );
116
+ let u = {
117
+ ...f,
118
+ namespace: t.definition[s].namespace,
119
+ attributes: [...T, ...y]
120
+ };
121
+ return n?.afterStandardizedRecord && (u = n.afterStandardizedRecord({
122
+ record: u
123
+ })), u;
124
+ }
125
+ function R(e, t, n, a) {
126
+ if (!e || !t) return;
127
+ const r = Object.keys(t).filter((s) => s in e);
128
+ E(r.length === 0, {
129
+ key: "EXTENSION_METHOD_COLLISION",
130
+ detail: `Module "${n}" has conflicting ${a} method(s): ${r.map((s) => `"${s}"`).join(", ")}`
131
+ });
132
+ }
133
+ function H(e) {
134
+ const t = {}, n = {}, a = [
135
+ ...Object.entries(e.base ?? {}),
136
+ ...Object.entries(e.custom ?? {})
137
+ ];
138
+ for (const [r, s] of a)
139
+ s.query && (R(
140
+ t[r],
141
+ s.query,
142
+ r,
143
+ "query"
144
+ ), t[r] = { ...t[r], ...s.query }), s.transaction && (R(
145
+ n[r],
146
+ s.transaction,
147
+ r,
148
+ "transaction"
149
+ ), n[r] = { ...n[r], ...s.transaction });
150
+ return { query: t, transaction: n };
151
+ }
152
+ export {
153
+ $ as C,
154
+ v as D,
155
+ D as a,
156
+ V as b,
157
+ w as c,
158
+ I as d,
159
+ Y as e,
160
+ z as f,
161
+ L as g,
162
+ F as h,
163
+ B as i,
164
+ K as j,
165
+ M as k,
166
+ X as l,
167
+ H as m,
168
+ j as n,
169
+ P as o,
170
+ G as s,
171
+ k as t
172
+ };
@@ -1,4 +1,4 @@
1
- import { Document, ExtensionsRegistry } from '../document';
1
+ import { Document, ExtensionModules, MergedExtensions, QueryExtensions, Query } from '../document';
2
2
  import { InitEmptyDocumentOptions, ImportDocumentOptions, ExportDocumentOptions, ProjectParams, ProjectState, DocumentRecord } from './types';
3
3
  import { Store } from '../store';
4
4
  import { AnyDialecteConfig, TransactionHooks } from '../types';
@@ -8,14 +8,14 @@ import { AnyDialecteConfig, TransactionHooks } from '../types';
8
8
  * Owns the Store, file registry, and configuration.
9
9
  * Documents are file-scoped views opened from a Project.
10
10
  */
11
- export declare class Project<GenericConfig extends AnyDialecteConfig, GenericExtension extends ExtensionsRegistry = {}, GenericStore extends Store = Store> {
11
+ export declare class Project<GenericConfig extends AnyDialecteConfig, GenericModules extends ExtensionModules = Record<never, never>, GenericStore extends Store = Store> {
12
12
  private _name?;
13
13
  private _store?;
14
14
  private _channel?;
15
15
  private readonly storage;
16
16
  private configs;
17
17
  private defaultConfigKey;
18
- private extensionsRegistry?;
18
+ private mergedExtensions?;
19
19
  private hooks?;
20
20
  get name(): string;
21
21
  private get store();
@@ -25,7 +25,10 @@ export declare class Project<GenericConfig extends AnyDialecteConfig, GenericExt
25
25
  configs: Record<string, GenericConfig>;
26
26
  defaultConfigKey?: string;
27
27
  storage: ProjectParams<GenericConfig>['storage'];
28
- extensionsRegistry?: GenericExtension;
28
+ extensions?: {
29
+ base?: ExtensionModules;
30
+ custom?: ExtensionModules;
31
+ };
29
32
  hooks?: TransactionHooks<GenericConfig>;
30
33
  });
31
34
  /**
@@ -51,12 +54,12 @@ export declare class Project<GenericConfig extends AnyDialecteConfig, GenericExt
51
54
  */
52
55
  removeDocument(documentId: string): Promise<void>;
53
56
  /**
54
- * Import a File into the project: register, parse XML, persist records.
57
+ * Import one or more Files into the project: register, parse XML, persist records.
55
58
  */
56
- import(file: File, options?: ImportDocumentOptions): Promise<{
59
+ import(files: File[], options?: ImportDocumentOptions): Promise<Array<{
57
60
  documentId: string;
58
61
  recordCount: number;
59
- }>;
62
+ }>>;
60
63
  /**
61
64
  * Export a document as an XMLDocument built from stored records.
62
65
  */
@@ -69,13 +72,23 @@ export declare class Project<GenericConfig extends AnyDialecteConfig, GenericExt
69
72
  /**
70
73
  * Open a file-scoped Document for querying and mutating a specific file.
71
74
  */
72
- openDocument(documentId: string): Document<GenericConfig, GenericExtension>;
75
+ openDocument(documentId: string): Document<GenericConfig, MergedExtensions<GenericModules>>;
73
76
  /**
74
77
  * Get the config for a specific file.
75
78
  */
76
79
  getDocumentConfig(documentId: string): GenericConfig | undefined;
77
80
  undo(documentId: string): Promise<void>;
78
81
  redo(documentId: string): Promise<void>;
82
+ /**
83
+ * Run a query function across all documents, return the first non-undefined result.
84
+ * Iterates documents sequentially; stops at the first match.
85
+ */
86
+ queryFirst<Result>(queryFunction: (query: Query<GenericConfig> & QueryExtensions<MergedExtensions<GenericModules>>) => Promise<Result | undefined>): Promise<Result | undefined>;
87
+ /**
88
+ * Run a query function across all documents, collect and flatten results.
89
+ * Iterates documents sequentially; merges all non-empty arrays.
90
+ */
91
+ queryAll<Result>(queryFunction: (query: Query<GenericConfig> & QueryExtensions<MergedExtensions<GenericModules>>) => Promise<Result[]>): Promise<Result[]>;
79
92
  /** Expose the underlying database instance. Return type is inferred from the store (Dexie for local storage). */
80
93
  getDatabaseInstance(): ReturnType<GenericStore['getDatabaseInstance']>;
81
94
  private refreshState;
@@ -1 +1 @@
1
- {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/project/project.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAGrC,OAAO,KAAK,EACX,wBAAwB,EACxB,qBAAqB,EACrB,qBAAqB,EACrB,aAAa,EACb,YAAY,EACZ,cAAc,EACd,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAA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AAC;IAS9B;;;OAGG;IACG,QAAQ,CAAC,MAAM,EACpB,aAAa,EAAE,CACd,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,GAAG,eAAe,CAAC,gBAAgB,CAAC,cAAc,CAAC,CAAC,KAC3E,OAAO,CAAC,MAAM,EAAE,CAAC,GACpB,OAAO,CAAC,MAAM,EAAE,CAAC;IAYpB,iHAAiH;IACjH,mBAAmB,IAAI,UAAU,CAAC,YAAY,CAAC,qBAAqB,CAAC,CAAC;YAIxD,YAAY;CAI1B"}
package/dist/test.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { expect as m, it as p } from "vitest";
2
- import { x as D, D as w, P as L } from "./index-D1JSZmI2.js";
3
- import { D as T, s as g, n as O, m as M } from "./standardizing-FTZoR5RH.js";
2
+ import { x as D, D as w, P as L } from "./index-Bza8g-6Z.js";
3
+ import { D as T, s as g, o as O, n as M } from "./merge-extensions-dj7By9gG.js";
4
4
  function v(B) {
5
5
  const e = k(B);
6
6
  if (e.length === 0)
@@ -1574,8 +1574,8 @@ async function E(B) {
1574
1574
  defaultConfigKey: "default",
1575
1575
  storage: { type: "local" },
1576
1576
  hooks: a
1577
- }).open(C), s = await A.import(
1578
- new File([e], "source.xml", { type: "text/xml" }),
1577
+ }).open(C), [s] = await A.import(
1578
+ [new File([e], "source.xml", { type: "text/xml" })],
1579
1579
  { useCustomRecordsIds: !0 }
1580
1580
  ), _ = {
1581
1581
  documentId: s.documentId,
@@ -1583,8 +1583,8 @@ async function E(B) {
1583
1583
  };
1584
1584
  let i;
1585
1585
  if (t) {
1586
- const c = await A.import(
1587
- new File([t], "target.xml", { type: "text/xml" }),
1586
+ const [c] = await A.import(
1587
+ [new File([t], "target.xml", { type: "text/xml" })],
1588
1588
  { useCustomRecordsIds: !0 }
1589
1589
  );
1590
1590
  i = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dialecte/core",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "Dialecte - Core functionality for Dialecte SDK",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,144 +0,0 @@
1
- import { i as h } from "./index-DWV6tSGF.js";
2
- const C = "db-id", O = {
3
- uri: "http://dialecte.dev/XML/DEV",
4
- prefix: "dev"
5
- }, j = `${O.prefix}:${C}`, R = [
6
- "id",
7
- "tagName",
8
- "namespace",
9
- "attributes",
10
- "children",
11
- "parent",
12
- "value"
13
- ], E = [...R, "status"], S = [...E, "tree"];
14
- function d(e, t) {
15
- if (typeof e != "object" || e === null)
16
- return !1;
17
- const a = Object.keys(e);
18
- return t.every((n) => n in e) && a.every((n) => t.includes(n)) && a.length === t.length;
19
- }
20
- function y(e) {
21
- return Array.isArray(e);
22
- }
23
- function F(e) {
24
- return d(e, R);
25
- }
26
- function K(e) {
27
- return d(e, E);
28
- }
29
- function V(e) {
30
- return d(e, S);
31
- }
32
- function Y(e, t) {
33
- return e.tagName === t;
34
- }
35
- function w(e, t) {
36
- return e.tagName === t;
37
- }
38
- function B(e, t) {
39
- return e.tagName === t;
40
- }
41
- function L(e, t) {
42
- return t.elements.includes(e);
43
- }
44
- function P(e, t) {
45
- return e.attributes.some((a) => a.name === t);
46
- }
47
- function I(e) {
48
- return {
49
- id: e.id,
50
- tagName: e.tagName,
51
- namespace: e.namespace,
52
- attributes: e.attributes,
53
- value: e.value,
54
- parent: e.parent,
55
- children: e.children
56
- };
57
- }
58
- function x(e) {
59
- const { record: t, status: a } = e, n = a ?? ("status" in t ? t.status : "unchanged");
60
- return {
61
- ...I(t),
62
- status: n
63
- };
64
- }
65
- function $(e) {
66
- const { record: t, status: a, tree: n } = e, i = n ?? ("tree" in t ? t.tree : []);
67
- return {
68
- ...x({ record: t, status: a }),
69
- tree: i
70
- };
71
- }
72
- function M(e) {
73
- const { dialecteConfig: t, tagName: a, attributes: n } = e;
74
- return y(n) ? n : Object.entries(n).map(
75
- ([i, s]) => ({
76
- name: i,
77
- value: s,
78
- namespace: t.definition[a]?.attributes.details[i]?.namespace || void 0
79
- })
80
- );
81
- }
82
- function q(e) {
83
- return h(e, {
84
- detail: "The record or ref is undefined"
85
- }), {
86
- id: e.id,
87
- tagName: e.tagName
88
- };
89
- }
90
- function Q(e) {
91
- const { dialecteConfig: t, hooks: a, record: n } = e, { id: i, tagName: s, attributes: l, namespace: b, value: A } = n, T = i ?? crypto.randomUUID(), o = l ? M({ tagName: s, attributes: l, dialecteConfig: t }) : [], f = {
92
- id: T,
93
- tagName: s,
94
- attributes: o,
95
- namespace: b ?? {
96
- prefix: "prefixNeededForNotSupportedNamespace",
97
- uri: "uriNeededForNotSupportedNamespace"
98
- },
99
- value: A ?? "",
100
- parent: n.parent ?? null,
101
- children: n.children ?? []
102
- };
103
- if (!t.elements.includes(s)) return f;
104
- const m = t.definition[s].attributes.sequence, c = t.definition[s].attributes.details, g = m.flatMap((r) => {
105
- const D = c[r].required, N = c[r]?.namespace || void 0, p = o.find((_) => _.name === r)?.value ?? (D ? c[r]?.default ?? "" : c[r]?.default);
106
- return p === void 0 ? [] : [
107
- {
108
- name: r,
109
- value: p,
110
- namespace: N
111
- }
112
- ];
113
- }), v = o.filter(
114
- (r) => "namespace" in r && r.namespace != null && !m.includes(r.name)
115
- );
116
- let u = {
117
- ...f,
118
- namespace: t.definition[s].namespace,
119
- attributes: [...g, ...v]
120
- };
121
- return a?.afterStandardizedRecord && (u = a.afterStandardizedRecord({
122
- record: u
123
- })), u;
124
- }
125
- export {
126
- j as C,
127
- O as D,
128
- C as a,
129
- w as b,
130
- L as c,
131
- y as d,
132
- B as e,
133
- F as f,
134
- Y as g,
135
- K as h,
136
- P as i,
137
- V as j,
138
- I as k,
139
- q as l,
140
- x as m,
141
- $ as n,
142
- Q as s,
143
- M as t
144
- };