pixiboardjs 0.1.0-alpha.2 → 0.1.0-alpha.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.0-alpha.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Fix lost variant index entries during concurrent BrowserPersistenceAdapter writes by serializing writes for the same asset.
8
+
9
+ Merge NativeIndexedDB variant updates within a transaction so concurrent writes preserve all variant index entries.
10
+
11
+ ## 0.1.0-alpha.3
12
+
13
+ ### Patch Changes
14
+
15
+ - Fix the official site generic host import dispatch so imported assets are routed through the configured host preview flow.
16
+
17
+ Keep local model content-addressed variants in isolated copies so preview variant updates do not mutate shared asset data.
18
+
3
19
  ## 0.1.0-alpha.2
4
20
 
5
21
  ### Minor Changes
package/dist/browser.js CHANGED
@@ -4621,6 +4621,7 @@ var BrowserPersistenceAdapter = class {
4621
4621
  #onCleanupError;
4622
4622
  #abortController = new AbortController();
4623
4623
  #leasesByAsset = /* @__PURE__ */ new Map();
4624
+ #assetWrites = /* @__PURE__ */ new Map();
4624
4625
  #cleanupErrors = [];
4625
4626
  #destroyed = false;
4626
4627
  #destroyPromise;
@@ -4821,6 +4822,9 @@ var BrowserPersistenceAdapter = class {
4821
4822
  return this.commitImport(await this.prepareUrl(url, options), options);
4822
4823
  }
4823
4824
  async putAsset(record2, blob, options = {}) {
4825
+ return this.#serializeAsset(record2.id, () => this.#putAsset(record2, blob, options));
4826
+ }
4827
+ async #putAsset(record2, blob, options) {
4824
4828
  return this.#run(options.signal, async (signal) => {
4825
4829
  const variant = options.variant === void 0 ? "original" : options.variant;
4826
4830
  assertAssetVariant(variant);
@@ -4873,9 +4877,11 @@ var BrowserPersistenceAdapter = class {
4873
4877
  }
4874
4878
  async putDerivative(assetId, variant, blob, options = {}) {
4875
4879
  assertAssetVariant(variant);
4876
- const entry = await this.#run(options.signal, (signal) => this.#indexedDb.getAssetEntry(assetId, signal));
4877
- if (entry === void 0) throw new BrowserAssetNotFoundError(assetId);
4878
- return this.putAsset(entry.record, blob, { ...options, variant });
4880
+ return this.#serializeAsset(assetId, () => this.#run(options.signal, async (signal) => {
4881
+ const entry = await this.#indexedDb.getAssetEntry(assetId, signal);
4882
+ if (entry === void 0) throw new BrowserAssetNotFoundError(assetId);
4883
+ return this.#putAsset(entry.record, blob, { ...options, variant, signal });
4884
+ }));
4879
4885
  }
4880
4886
  async getAsset(id, options = {}) {
4881
4887
  return this.#run(options.signal, async (signal) => {
@@ -4904,6 +4910,9 @@ var BrowserPersistenceAdapter = class {
4904
4910
  });
4905
4911
  }
4906
4912
  async deleteAsset(id, options = {}) {
4913
+ return this.#serializeAsset(id, () => this.#deleteAsset(id, options));
4914
+ }
4915
+ async #deleteAsset(id, options) {
4907
4916
  return this.#run(options.signal, async (signal) => {
4908
4917
  const entry = await this.#indexedDb.getAssetEntry(id, signal);
4909
4918
  this.#throwIfAborted(signal);
@@ -5120,6 +5129,16 @@ var BrowserPersistenceAdapter = class {
5120
5129
  };
5121
5130
  return { sourceType, asset, blob, fileName };
5122
5131
  }
5132
+ #serializeAsset(id, operation) {
5133
+ const previous = this.#assetWrites.get(id) ?? Promise.resolve();
5134
+ const result = previous.then(operation);
5135
+ const settled = result.then(() => void 0, () => void 0);
5136
+ this.#assetWrites.set(id, settled);
5137
+ void settled.then(() => {
5138
+ if (this.#assetWrites.get(id) === settled) this.#assetWrites.delete(id);
5139
+ });
5140
+ return result;
5141
+ }
5123
5142
  async #run(externalSignal, operation) {
5124
5143
  if (this.#destroyed) throw new BrowserPersistenceDestroyedError();
5125
5144
  const controller = new AbortController();
@@ -5460,19 +5479,40 @@ var NativeIndexedDbPort = class {
5460
5479
  async putAssetEntry(entry, binaryWrite, signal) {
5461
5480
  for (const variant of Object.keys(entry.binaries)) assertAssetVariant(variant);
5462
5481
  if (binaryWrite !== void 0) assertAssetVariant(binaryWrite.variant);
5463
- await this.#write([ASSET_STORE, BLOB_STORE], signal, (transaction) => {
5464
- transaction.objectStore(ASSET_STORE).put(entry, entry.id);
5482
+ const database = await this.#open(signal);
5483
+ if (signal.aborted) throw abortError2(signal);
5484
+ const transaction = database.transaction([ASSET_STORE, BLOB_STORE], "readwrite");
5485
+ const done = transactionDone(transaction, signal);
5486
+ try {
5487
+ const assets = transaction.objectStore(ASSET_STORE);
5488
+ const current = await requestResult(assets.get(entry.id));
5489
+ const committed = binaryWrite !== void 0 && current !== void 0 ? {
5490
+ ...entry,
5491
+ record: binaryWrite.variant === "original" ? entry.record : current.record,
5492
+ createdAt: current.createdAt,
5493
+ updatedAt: Math.max(current.updatedAt, entry.updatedAt),
5494
+ binaries: { ...current.binaries, [binaryWrite.variant]: entry.binaries[binaryWrite.variant] }
5495
+ } : current !== void 0 ? {
5496
+ ...entry,
5497
+ binaries: { ...entry.binaries, ...current.binaries }
5498
+ } : entry;
5499
+ assets.put(committed, entry.id);
5465
5500
  if (binaryWrite !== void 0) {
5466
5501
  const blobs = transaction.objectStore(BLOB_STORE);
5467
- const binary = entry.binaries[binaryWrite.variant];
5502
+ const binary = committed.binaries[binaryWrite.variant];
5468
5503
  const key = blobKey(entry.id, binaryWrite.variant);
5469
- if (binary?.storage.kind === "opfs") {
5470
- blobs.delete(key);
5471
- } else {
5472
- blobs.put(binaryWrite.blob, key);
5473
- }
5504
+ if (binary?.storage.kind === "opfs") blobs.delete(key);
5505
+ else blobs.put(binaryWrite.blob, key);
5474
5506
  }
5475
- });
5507
+ await done;
5508
+ } catch (error) {
5509
+ try {
5510
+ transaction.abort();
5511
+ } catch {
5512
+ }
5513
+ await done.catch(() => void 0);
5514
+ throw error;
5515
+ }
5476
5516
  }
5477
5517
  async commitAssetAndDocument(document2, entry, binaryWrite, signal, options = {}) {
5478
5518
  for (const variant of Object.keys(entry.binaries)) assertAssetVariant(variant);