@abraca/dabra 0.1.6 → 0.1.7

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.
@@ -2086,6 +2086,10 @@ var SubdocMessage = class extends OutgoingMessage {
2086
2086
 
2087
2087
  //#endregion
2088
2088
  //#region packages/provider/src/AbracadabraProvider.ts
2089
+ /** Validate that a string is a UUID acceptable by the server's DocId parser. */
2090
+ function isValidDocId(id) {
2091
+ return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(id);
2092
+ }
2089
2093
  /**
2090
2094
  * AbracadabraProvider extends HocuspocusProvider with:
2091
2095
  *
@@ -2112,6 +2116,7 @@ var AbracadabraProvider = class AbracadabraProvider extends HocuspocusProvider {
2112
2116
  super(resolved);
2113
2117
  this.effectiveRole = null;
2114
2118
  this.childProviders = /* @__PURE__ */ new Map();
2119
+ this.pendingLoads = /* @__PURE__ */ new Map();
2115
2120
  this.boundHandleYSubdocsChange = this.handleYSubdocsChange.bind(this);
2116
2121
  this._client = client;
2117
2122
  this.abracadabraConfig = configuration;
@@ -2221,7 +2226,10 @@ var AbracadabraProvider = class AbracadabraProvider extends HocuspocusProvider {
2221
2226
  * We intercept additions to register them with the Abracadabra server.
2222
2227
  */
2223
2228
  handleYSubdocsChange({ added, removed }) {
2224
- for (const subdoc of added) this.registerSubdoc(subdoc);
2229
+ for (const subdoc of added) {
2230
+ if (!isValidDocId(subdoc.guid)) continue;
2231
+ this.registerSubdoc(subdoc);
2232
+ }
2225
2233
  for (const subdoc of removed) this.unloadChild(subdoc.guid);
2226
2234
  }
2227
2235
  /**
@@ -2246,7 +2254,15 @@ var AbracadabraProvider = class AbracadabraProvider extends HocuspocusProvider {
2246
2254
  * the server is document-scoped (one WebSocket ↔ one document).
2247
2255
  */
2248
2256
  async loadChild(childId) {
2257
+ if (!isValidDocId(childId)) throw new Error(`loadChild: "${childId}" is not a valid document ID (must be a UUID). If this node was created with an older version of the app, delete it and recreate it.`);
2249
2258
  if (this.childProviders.has(childId)) return this.childProviders.get(childId);
2259
+ if (this.pendingLoads.has(childId)) return this.pendingLoads.get(childId);
2260
+ const load = this._doLoadChild(childId);
2261
+ this.pendingLoads.set(childId, load);
2262
+ load.finally(() => this.pendingLoads.delete(childId));
2263
+ return load;
2264
+ }
2265
+ async _doLoadChild(childId) {
2250
2266
  const childDoc = new Y.Doc({ guid: childId });
2251
2267
  await new Promise((resolve) => {
2252
2268
  const onRegistered = ({ childId: cid }) => {
@@ -2262,7 +2278,7 @@ var AbracadabraProvider = class AbracadabraProvider extends HocuspocusProvider {
2262
2278
  const childProvider = new AbracadabraProvider({
2263
2279
  name: childId,
2264
2280
  document: childDoc,
2265
- url: this.abracadabraConfig.url,
2281
+ url: this.abracadabraConfig.url ?? this.configuration.websocketProvider?.url,
2266
2282
  token: this.configuration.token,
2267
2283
  subdocLoading: this.subdocLoading,
2268
2284
  disableOfflineStore: this.abracadabraConfig.disableOfflineStore,