@dialecte/core 0.4.7 → 0.4.9

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.
@@ -38,12 +38,19 @@ export declare class Document<GenericConfig extends AnyDialecteConfig, GenericEx
38
38
  readonly channelName: string;
39
39
  /** Announce a mutation on the project channel (provided by the owning Project) */
40
40
  private notify;
41
+ /**
42
+ * Recompute this document's canUndo/canRedo on the shared project entry
43
+ * (provided by the owning Project). Called locally after a commit so the
44
+ * flags are up to date synchronously, without depending on a channel echo.
45
+ */
46
+ private refreshHistoryStatus;
41
47
  /** Track concurrent transactions to manage loading flag */
42
48
  private activeTransactions;
43
49
  constructor(store: Store, config: GenericConfig, documentId: string, extensions: GenericExtension | undefined, hooks: DialecteHooks<GenericConfig> | undefined, project: {
44
50
  state: DocumentState;
45
51
  channelName: string;
46
52
  notify: (message: ProjectChannelMessage) => void;
53
+ refreshHistoryStatus: () => Promise<void>;
47
54
  });
48
55
  private withQueryExtensions;
49
56
  private withAllExtensions;
@@ -1 +1 @@
1
- {"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../src/document/document.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAI3C,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAC5F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAC5D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE/D;;;;;;;;;;;GAWG;AACH,qBAAa,QAAQ,CACpB,aAAa,SAAS,iBAAiB,EACvC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CAAC,EAAE,MAAM,CAAA;KAAE,GAC1B,OAAO,CAAC,CAAC,CAAC;IAmDb;;;;;;;;;;;;;;;;;;;OAmBG;IACG,OAAO,CACZ,EAAE,EAAE,CAAC,EAAE,EAAE,WAAW,CAAC,aAAa,CAAC,GAAG,aAAa,CAAC,gBAAgB,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,EACvF,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAC1B,OAAO,CAAC,mBAAmB,CAAC,aAAa,EAAE,gBAAgB,CAAC,CAAC;IAmGhE,iCAAiC;IACjC,KAAK,IAAI,IAAI;IAIb,wDAAwD;IAClD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAG9B"}
@@ -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,gBAA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AAC,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/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { $ as e, A as t, B as n, C as r, D as i, E as a, F as o, G as s, H as c, I as l, J as u, K as d, L as f, M as p, N as m, O as h, P as g, Q as _, R as v, S as y, T as b, U as x, V as S, W as C, X as w, Y as T, Z as E, _ as D, a as O, at as k, b as A, c as j, ct as M, d as N, et as P, f as F, g as I, h as L, i as R, it as z, j as B, k as V, l as H, lt as U, m as W, n as G, nt as K, o as q, ot as J, p as Y, q as X, r as Z, rt as Q, s as $, st as ee, t as te, tt as ne, u as re, ut as ie, v as ae, w as oe, x as se, y as ce } from "./project-DxIu-3AU.js";
1
+ import { $ as e, A as t, B as n, C as r, D as i, E as a, F as o, G as s, H as c, I as l, J as u, K as d, L as f, M as p, N as m, O as h, P as g, Q as _, R as v, S as y, T as b, U as x, V as S, W as C, X as w, Y as T, Z as E, _ as D, a as O, at as k, b as A, c as j, ct as M, d as N, et as P, f as F, g as I, h as L, i as R, it as z, j as B, k as V, l as H, lt as U, m as W, n as G, nt as K, o as q, ot as J, p as Y, q as X, r as Z, rt as Q, s as $, st as ee, t as te, tt as ne, u as re, ut as ie, v as ae, w as oe, x as se, y as ce } from "./project-D-KS3OPN.js";
2
2
  import { m as le, p as ue } from "./utils-C5_11hqg.js";
3
3
  export { V as AnyQuery, i as AnyTransaction, N as BLOBS_SCHEMA, F as BLOB_DATA_SCHEMA, Y as CHANGELOG_SCHEMA, W as DOCUMENTS_SCHEMA, re as DexieStore, oe as Document, le as ERROR_CATALOG, H as InMemoryStore, L as META_SCHEMA, p as ParseSession, te as Project, h as Query, I as TABLE_BLOBS, D as TABLE_BLOB_PREFIX, ae as TABLE_CHANGELOG, ce as TABLE_DOCUMENTS, A as TABLE_META, se as TABLE_RECORD_PREFIX, f as TEMP_IDB_ID_ATTRIBUTE_NAME, a as Transaction, C as applyOmit, x as applyOrder, u as applyUnwrap, ie as bindExtensions, y as blobTableName, R as buildDocumentState, g as buildXmlDocument, S as collectSnapshotRecords, o as downloadFile, q as exportBlob, $ as exportDocument, K as findAncestors, P as findByAttributes, e as findDescendants, v as formatXml, E as getAttribute, _ as getAttributeFullObject, T as getAttributes, w as getAttributesFullObject, z as getChild, Q as getChildren, ee as getRecord, J as getRecords, k as getRecordsByTagName, t as getSnapshot, c as getTree, Z as importDocument, M as indexStagedDeletesByParent, G as initEmptyDocument, m as inspectXml, s as isOmitted, b as isTransactionContext, ne as matchesAttributeFilter, U as overlayAllStaged, d as parseOmit, B as parseXmlFile, O as reconcileDocumentState, r as recordTableName, n as recordsToTree, j as resolveStore, X as shouldStopTraversal, ue as throwDialecteError, l as xmlDocumentToString };
@@ -11,16 +11,18 @@ import { AnyDialecteConfig, BlobAttachment, BlobRecord, DialecteHooks } from '..
11
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
- /** Posting side of the project channel. Never listened to. */
15
- private _postChannel?;
16
14
  /**
17
- * Listening side of the project channel. A separate instance from
18
- * _postChannel on purpose: BroadcastChannel withholds a message only from
19
- * the exact instance that posted it, so this instance also receives this
20
- * tab's own posts (echo) one code path folds every mutation source,
21
- * local and cross-tab, into project state.
22
- */
23
- private _listenChannel?;
15
+ * The project channel: posts this realm's mutations and listens for other
16
+ * realms' (other tab / iframe / second Project instance). BroadcastChannel
17
+ * withholds a message from the exact instance that posted it, so this realm
18
+ * never receives its own posts — local state is maintained inline by the
19
+ * mutation methods, and the listener folds in only foreign messages.
20
+ */
21
+ private _channel?;
22
+ /** Set once close()/destroy() begins, to stop new channel-triggered store work. */
23
+ private closing;
24
+ /** In-flight fire-and-forget work triggered by foreign messages, awaited on teardown. */
25
+ private readonly pendingBroadcastWork;
24
26
  private readonly storage;
25
27
  private configs;
26
28
  private defaultConfigKey;
@@ -28,7 +30,7 @@ export declare class Project<GenericConfig extends AnyDialecteConfig, GenericMod
28
30
  private hooks?;
29
31
  get name(): string;
30
32
  private get store();
31
- private get postChannel();
33
+ private get channel();
32
34
  /**
33
35
  * Name of this project's BroadcastChannel — the public event contract.
34
36
  * Open your own instance (see createChannel) to receive every
@@ -59,11 +61,20 @@ export declare class Project<GenericConfig extends AnyDialecteConfig, GenericMod
59
61
  */
60
62
  open(name: string): Promise<this>;
61
63
  /**
62
- * Fold an incoming channel message into project state. Receives this tab's
63
- * own posts too (see _listenChannel), so every mutation source — local
64
- * commit, other-tab commit, undo/redo converges through this one handler.
64
+ * Fold an incoming channel message into project state. This realm never
65
+ * receives its own posts (BroadcastChannel withholds them from the posting
66
+ * instance), so this only ever handles foreign messages another tab, an
67
+ * iframe, or a second Project instance. Local mutations maintain state inline.
65
68
  */
66
69
  private onChannelMessage;
70
+ /**
71
+ * Track channel-triggered fire-and-forget work so `close`/`destroy` can wait for
72
+ * it to settle before tearing down the store. A foreign message delivered as the
73
+ * project is closing would otherwise read or reconcile the store after it was
74
+ * closed/deleted — surfacing as DatabaseClosedError or ConstraintError. The work
75
+ * keeps its own error swallowing; here it is only awaited, never rethrown.
76
+ */
77
+ private trackBroadcastWork;
67
78
  /** Recompute canUndo/canRedo for a document from the store's history. */
68
79
  private refreshHistoryStatus;
69
80
  /**
@@ -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;AAIrC,OAAO,KAAK,EACX,wBAAwB,EACxB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,EAEhB,aAAa,EACb,YAAY,EACZ,cAAc,EACd,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAC5F,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAI3F;;;;;GAKG;AACH,qBAAa,OAAO,CACnB,aAAa,SAAS,iBAAiB,EACvC,cAAc,SAAS,gBAAgB,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAC9D,YAAY,SAAS,KAAK,GA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
@@ -3481,7 +3481,7 @@ function Wt(e) {
3481
3481
  //#region src/document/document.ts
3482
3482
  var G = class {
3483
3483
  constructor(e, t, n, r, i, a) {
3484
- this.activeTransactions = 0, this.store = e, this.config = t, this.documentId = n, this.hooks = i, this.extensionsRegistry = r, this.state = a.state, this.channelName = a.channelName, this.notify = a.notify;
3484
+ this.activeTransactions = 0, this.store = e, this.config = t, this.documentId = n, this.hooks = i, this.extensionsRegistry = r, this.state = a.state, this.channelName = a.channelName, this.notify = a.notify, this.refreshHistoryStatus = a.refreshHistoryStatus;
3485
3485
  }
3486
3486
  withQueryExtensions(e) {
3487
3487
  let t = te(this.extensionsRegistry?.query, e);
@@ -3513,7 +3513,7 @@ var G = class {
3513
3513
  let n = this.withAllExtensions(this.createTransaction());
3514
3514
  try {
3515
3515
  let r = await e(n);
3516
- return await n.commit(), this.notify({
3516
+ return await n.commit(), await this.refreshHistoryStatus(), this.notify({
3517
3517
  type: "commit",
3518
3518
  documentId: this.documentId,
3519
3519
  timestamp: this.state.lastUpdate ?? Date.now()
@@ -3556,7 +3556,7 @@ var G = class {
3556
3556
  if (!o) {
3557
3557
  o = !0, this.activeTransactions++, this.state.loading = !0;
3558
3558
  try {
3559
- await n.commit(), this.notify({
3559
+ await n.commit(), await this.refreshHistoryStatus(), this.notify({
3560
3560
  type: "commit",
3561
3561
  documentId: this.documentId,
3562
3562
  timestamp: this.state.lastUpdate ?? Date.now()
@@ -8060,11 +8060,11 @@ var Tn = class {
8060
8060
  detail: "Call project.open(name) before accessing project properties."
8061
8061
  }), this._store;
8062
8062
  }
8063
- get postChannel() {
8064
- return o(this._postChannel !== void 0, {
8063
+ get channel() {
8064
+ return o(this._channel !== void 0, {
8065
8065
  key: "PROJECT_NOT_OPENED",
8066
8066
  detail: "Call project.open(name) before accessing project properties."
8067
- }), this._postChannel;
8067
+ }), this._channel;
8068
8068
  }
8069
8069
  get channelName() {
8070
8070
  return `dialecte::project::${this.name}`;
@@ -8073,10 +8073,10 @@ var Tn = class {
8073
8073
  return new BroadcastChannel(this.channelName);
8074
8074
  }
8075
8075
  notify(e) {
8076
- this.postChannel.postMessage(e);
8076
+ this.channel.postMessage(e);
8077
8077
  }
8078
8078
  constructor(e) {
8079
- this.state = {
8079
+ this.closing = !1, this.pendingBroadcastWork = /* @__PURE__ */ new Set(), this.state = {
8080
8080
  documents: /* @__PURE__ */ new Map(),
8081
8081
  activeTransactions: 0
8082
8082
  };
@@ -8087,7 +8087,7 @@ var Tn = class {
8087
8087
  }) : void 0;
8088
8088
  }
8089
8089
  async open(e) {
8090
- this._name = e, this._postChannel = new BroadcastChannel(this.channelName), this._listenChannel = new BroadcastChannel(this.channelName), this._listenChannel.addEventListener("message", (e) => {
8090
+ this._name = e, this.closing = !1, this._channel = new BroadcastChannel(this.channelName), this._channel.addEventListener("message", (e) => {
8091
8091
  this.onChannelMessage(e.data);
8092
8092
  });
8093
8093
  let t = yn(e, this.storage, this.configs[this.defaultConfigKey]);
@@ -8097,30 +8097,37 @@ var Tn = class {
8097
8097
  return await Promise.all(n.map((e) => this.refreshHistoryStatus(e.id))), this;
8098
8098
  }
8099
8099
  onChannelMessage(e) {
8100
- switch (e?.type) {
8100
+ if (!this.closing) switch (e?.type) {
8101
8101
  case "init-empty-document":
8102
8102
  case "document-removed":
8103
8103
  case "document-imported":
8104
- this.reconcileFromBroadcast(e.documentId).catch(() => {});
8104
+ this.trackBroadcastWork(this.reconcileFromBroadcast(e.documentId));
8105
8105
  break;
8106
8106
  case "commit": {
8107
8107
  let t = this.state.documents.get(e.documentId);
8108
- t && (t.lastUpdate = e.timestamp ?? Date.now()), this.refreshHistoryStatus(e.documentId).catch(() => {});
8108
+ t && (t.lastUpdate = e.timestamp ?? Date.now()), this.trackBroadcastWork(this.refreshHistoryStatus(e.documentId));
8109
8109
  break;
8110
8110
  }
8111
8111
  }
8112
8112
  }
8113
+ trackBroadcastWork(e) {
8114
+ let t = e.catch(() => {}).finally(() => {
8115
+ this.pendingBroadcastWork.delete(t);
8116
+ });
8117
+ this.pendingBroadcastWork.add(t);
8118
+ }
8113
8119
  async refreshHistoryStatus(e) {
8120
+ if (this.closing) return;
8114
8121
  let t = this.state.documents.get(e);
8115
8122
  if (!t) return;
8116
8123
  let { canUndo: n, canRedo: r } = await this.store.getHistoryStatus(e);
8117
8124
  t.canUndo = n, t.canRedo = r;
8118
8125
  }
8119
8126
  close() {
8120
- this.postChannel.close(), this._listenChannel?.close(), this.store.close();
8127
+ this.closing = !0, this._channel?.close(), this.store.close();
8121
8128
  }
8122
8129
  async destroy() {
8123
- this.postChannel.close(), this._listenChannel?.close(), await this.store.destroy(), this.state.documents.clear();
8130
+ this.closing = !0, this._channel?.close(), await Promise.allSettled(this.pendingBroadcastWork), await this.store.destroy(), this.state.documents.clear();
8124
8131
  }
8125
8132
  async initEmptyDocument(e) {
8126
8133
  let t = await wn({
@@ -8188,7 +8195,8 @@ var Tn = class {
8188
8195
  return new G(this.store, n, e, this.mergedExtensions, this.hooks, {
8189
8196
  state: t,
8190
8197
  channelName: this.channelName,
8191
- notify: (e) => this.notify(e)
8198
+ notify: (e) => this.notify(e),
8199
+ refreshHistoryStatus: () => this.refreshHistoryStatus(e)
8192
8200
  });
8193
8201
  }
8194
8202
  async getDocumentStatus(e) {
@@ -8310,7 +8318,7 @@ var Tn = class {
8310
8318
  Sn(this.state.documents, e);
8311
8319
  }
8312
8320
  async reconcileFromBroadcast(e) {
8313
- await this.store.reconcile(e), await this.refreshState();
8321
+ this.closing || (await this.store.reconcile(e), await this.refreshState());
8314
8322
  }
8315
8323
  };
8316
8324
  //#endregion
package/dist/test.js CHANGED
@@ -1,4 +1,4 @@
1
- import { dt as e, t, u as n, z as r } from "./project-DxIu-3AU.js";
1
+ import { dt as e, t, u as n, z as r } from "./project-D-KS3OPN.js";
2
2
  import { DIALECTE_NAMESPACES as i, standardizeRecord as a, toTrackedRecord as o, toTreeRecord as s } from "./helpers.js";
3
3
  import { expect as c, it as l } from "vitest";
4
4
  //#region src/test/assert-xml/xpath-parser.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dialecte/core",
3
- "version": "0.4.7",
3
+ "version": "0.4.9",
4
4
  "description": "Dialecte - Core functionality for Dialecte SDK",
5
5
  "license": "MIT",
6
6
  "repository": {