@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.
@@ -2116,6 +2116,10 @@ var SubdocMessage = class extends OutgoingMessage {
2116
2116
 
2117
2117
  //#endregion
2118
2118
  //#region packages/provider/src/AbracadabraProvider.ts
2119
+ /** Validate that a string is a UUID acceptable by the server's DocId parser. */
2120
+ function isValidDocId(id) {
2121
+ return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(id);
2122
+ }
2119
2123
  /**
2120
2124
  * AbracadabraProvider extends HocuspocusProvider with:
2121
2125
  *
@@ -2142,6 +2146,7 @@ var AbracadabraProvider = class AbracadabraProvider extends HocuspocusProvider {
2142
2146
  super(resolved);
2143
2147
  this.effectiveRole = null;
2144
2148
  this.childProviders = /* @__PURE__ */ new Map();
2149
+ this.pendingLoads = /* @__PURE__ */ new Map();
2145
2150
  this.boundHandleYSubdocsChange = this.handleYSubdocsChange.bind(this);
2146
2151
  this._client = client;
2147
2152
  this.abracadabraConfig = configuration;
@@ -2251,7 +2256,10 @@ var AbracadabraProvider = class AbracadabraProvider extends HocuspocusProvider {
2251
2256
  * We intercept additions to register them with the Abracadabra server.
2252
2257
  */
2253
2258
  handleYSubdocsChange({ added, removed }) {
2254
- for (const subdoc of added) this.registerSubdoc(subdoc);
2259
+ for (const subdoc of added) {
2260
+ if (!isValidDocId(subdoc.guid)) continue;
2261
+ this.registerSubdoc(subdoc);
2262
+ }
2255
2263
  for (const subdoc of removed) this.unloadChild(subdoc.guid);
2256
2264
  }
2257
2265
  /**
@@ -2276,7 +2284,15 @@ var AbracadabraProvider = class AbracadabraProvider extends HocuspocusProvider {
2276
2284
  * the server is document-scoped (one WebSocket ↔ one document).
2277
2285
  */
2278
2286
  async loadChild(childId) {
2287
+ 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.`);
2279
2288
  if (this.childProviders.has(childId)) return this.childProviders.get(childId);
2289
+ if (this.pendingLoads.has(childId)) return this.pendingLoads.get(childId);
2290
+ const load = this._doLoadChild(childId);
2291
+ this.pendingLoads.set(childId, load);
2292
+ load.finally(() => this.pendingLoads.delete(childId));
2293
+ return load;
2294
+ }
2295
+ async _doLoadChild(childId) {
2280
2296
  const childDoc = new yjs.Doc({ guid: childId });
2281
2297
  await new Promise((resolve) => {
2282
2298
  const onRegistered = ({ childId: cid }) => {
@@ -2292,7 +2308,7 @@ var AbracadabraProvider = class AbracadabraProvider extends HocuspocusProvider {
2292
2308
  const childProvider = new AbracadabraProvider({
2293
2309
  name: childId,
2294
2310
  document: childDoc,
2295
- url: this.abracadabraConfig.url,
2311
+ url: this.abracadabraConfig.url ?? this.configuration.websocketProvider?.url,
2296
2312
  token: this.configuration.token,
2297
2313
  subdocLoading: this.subdocLoading,
2298
2314
  disableOfflineStore: this.abracadabraConfig.disableOfflineStore,