dexie-cloud-addon 4.1.0-beta.41 → 4.1.0-beta.43

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.
@@ -0,0 +1,2 @@
1
+ import Dexie from "dexie";
2
+ export declare function dbOnClosed(db: Dexie, handler: () => void): () => void;
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * ==========================================================================
10
10
  *
11
- * Version 4.1.0-beta.41, Wed Jan 29 2025
11
+ * Version 4.1.0-beta.43, Fri Feb 07 2025
12
12
  *
13
13
  * https://dexie.org
14
14
  *
@@ -1800,19 +1800,25 @@ function triggerSync(db, purpose) {
1800
1800
  }
1801
1801
  }
1802
1802
 
1803
+ const hasArrayBufferB64 = "fromBase64" in Uint8Array; // https://github.com/tc39/proposal-arraybuffer-base64;
1803
1804
  const b64decode = typeof Buffer !== "undefined"
1804
- ? (base64) => Buffer.from(base64, "base64")
1805
- : (base64) => {
1806
- const binary_string = atob(base64);
1807
- const len = binary_string.length;
1808
- const bytes = new Uint8Array(len);
1809
- for (var i = 0; i < len; i++) {
1810
- bytes[i] = binary_string.charCodeAt(i);
1811
- }
1812
- return bytes;
1813
- };
1805
+ ? (base64) => Buffer.from(base64, "base64") // Node
1806
+ : hasArrayBufferB64
1807
+ ? // @ts-ignore: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromBase64
1808
+ (base64) => Uint8Array.fromBase64(base64) // Modern javascript standard
1809
+ : (base64) => {
1810
+ // Legacy DOM workaround
1811
+ const binary_string = atob(base64);
1812
+ const len = binary_string.length;
1813
+ const bytes = new Uint8Array(len);
1814
+ for (var i = 0; i < len; i++) {
1815
+ bytes[i] = binary_string.charCodeAt(i);
1816
+ }
1817
+ return bytes;
1818
+ };
1814
1819
  const b64encode = typeof Buffer !== "undefined"
1815
1820
  ? (b) => {
1821
+ // Node
1816
1822
  if (ArrayBuffer.isView(b)) {
1817
1823
  return Buffer.from(b.buffer, b.byteOffset, b.byteLength).toString("base64");
1818
1824
  }
@@ -1820,16 +1826,20 @@ const b64encode = typeof Buffer !== "undefined"
1820
1826
  return Buffer.from(b).toString("base64");
1821
1827
  }
1822
1828
  }
1823
- : (b) => {
1824
- const u8a = ArrayBuffer.isView(b) ? b : new Uint8Array(b);
1825
- const CHUNK_SIZE = 0x1000;
1826
- const strs = [];
1827
- for (let i = 0, l = u8a.length; i < l; i += CHUNK_SIZE) {
1828
- const chunk = u8a.subarray(i, i + CHUNK_SIZE);
1829
- strs.push(String.fromCharCode.apply(null, chunk));
1830
- }
1831
- return btoa(strs.join(""));
1832
- };
1829
+ : hasArrayBufferB64
1830
+ ? // @ts-ignore https://github.com/tc39/proposal-arraybuffer-base64
1831
+ (b) => b.toBase64() // Modern Javascript standard
1832
+ : (b) => {
1833
+ // Legacy DOM workaround
1834
+ const u8a = ArrayBuffer.isView(b) ? b : new Uint8Array(b);
1835
+ const CHUNK_SIZE = 0x1000;
1836
+ const strs = [];
1837
+ for (let i = 0, l = u8a.length; i < l; i += CHUNK_SIZE) {
1838
+ const chunk = u8a.subarray(i, i + CHUNK_SIZE);
1839
+ strs.push(String.fromCharCode.apply(null, chunk));
1840
+ }
1841
+ return btoa(strs.join(""));
1842
+ };
1833
1843
 
1834
1844
  function computeRealmSetHash(_a) {
1835
1845
  return __awaiter(this, arguments, void 0, function* ({ realms, inviteRealms, }) {
@@ -4235,6 +4245,26 @@ var undefinedDef = {
4235
4245
  },
4236
4246
  };
4237
4247
 
4248
+ var FileDef = {
4249
+ File: {
4250
+ test: (file, toStringTag) => toStringTag === "File",
4251
+ replace: (file) => ({
4252
+ $t: "File",
4253
+ v: b64encode(string2ArrayBuffer(readBlobSync(file))),
4254
+ type: file.type,
4255
+ name: file.name,
4256
+ lastModified: new Date(file.lastModified).toISOString(),
4257
+ }),
4258
+ revive: ({ type, v, name, lastModified }) => {
4259
+ const ab = b64decode(v);
4260
+ return new File([ab], name, {
4261
+ type,
4262
+ lastModified: new Date(lastModified).getTime(),
4263
+ });
4264
+ },
4265
+ },
4266
+ };
4267
+
4238
4268
  // Since server revisions are stored in bigints, we need to handle clients without
4239
4269
  // bigint support to not fail when serverRevision is passed over to client.
4240
4270
  // We need to not fail when reviving it and we need to somehow store the information.
@@ -4270,7 +4300,7 @@ const bigIntDef = hasBigIntSupport
4270
4300
  revive: ({ v }) => new FakeBigInt(v),
4271
4301
  },
4272
4302
  };
4273
- const defs = Object.assign(Object.assign(Object.assign({}, undefinedDef), bigIntDef), { PropModification: {
4303
+ const defs = Object.assign(Object.assign(Object.assign(Object.assign({}, undefinedDef), bigIntDef), FileDef), { PropModification: {
4274
4304
  test: (val) => val instanceof PropModification,
4275
4305
  replace: (propModification) => {
4276
4306
  return Object.assign({ $t: 'PropModification' }, propModification['@@propmod']);
@@ -8158,7 +8188,7 @@ function dexieCloud(dexie) {
8158
8188
  const syncComplete = new Subject();
8159
8189
  dexie.cloud = {
8160
8190
  // @ts-ignore
8161
- version: "4.1.0-beta.41",
8191
+ version: "4.1.0-beta.43",
8162
8192
  options: Object.assign({}, DEFAULT_OPTIONS),
8163
8193
  schema: null,
8164
8194
  get currentUserId() {
@@ -8476,7 +8506,7 @@ function dexieCloud(dexie) {
8476
8506
  }
8477
8507
  }
8478
8508
  // @ts-ignore
8479
- dexieCloud.version = "4.1.0-beta.41";
8509
+ dexieCloud.version = "4.1.0-beta.43";
8480
8510
  Dexie.Cloud = dexieCloud;
8481
8511
 
8482
8512
  // In case the SW lives for a while, let it reuse already opened connections: