@atproto/oauth-client-browser 0.3.41 → 0.4.0-next.0

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.
Files changed (40) hide show
  1. package/dist/browser-oauth-client.d.ts +4 -1
  2. package/dist/browser-oauth-client.d.ts.map +1 -1
  3. package/dist/browser-oauth-client.js +24 -38
  4. package/dist/browser-oauth-client.js.map +1 -1
  5. package/dist/browser-oauth-database.d.ts +2 -2
  6. package/dist/browser-oauth-database.d.ts.map +1 -1
  7. package/dist/browser-oauth-database.js +19 -35
  8. package/dist/browser-oauth-database.js.map +1 -1
  9. package/dist/browser-runtime-implementation.d.ts +1 -1
  10. package/dist/browser-runtime-implementation.d.ts.map +1 -1
  11. package/dist/browser-runtime-implementation.js +4 -13
  12. package/dist/browser-runtime-implementation.js.map +1 -1
  13. package/dist/errors.js +2 -11
  14. package/dist/errors.js.map +1 -1
  15. package/dist/index.d.ts +2 -2
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +7 -25
  18. package/dist/index.js.map +1 -1
  19. package/dist/indexed-db/db-index.js +8 -17
  20. package/dist/indexed-db/db-index.js.map +1 -1
  21. package/dist/indexed-db/db-object-store.js +13 -22
  22. package/dist/indexed-db/db-object-store.js.map +1 -1
  23. package/dist/indexed-db/db-transaction.d.ts +1 -1
  24. package/dist/indexed-db/db-transaction.d.ts.map +1 -1
  25. package/dist/indexed-db/db-transaction.js +13 -29
  26. package/dist/indexed-db/db-transaction.js.map +1 -1
  27. package/dist/indexed-db/db.d.ts +1 -1
  28. package/dist/indexed-db/db.d.ts.map +1 -1
  29. package/dist/indexed-db/db.js +13 -34
  30. package/dist/indexed-db/db.js.map +1 -1
  31. package/dist/indexed-db/index.js +4 -20
  32. package/dist/indexed-db/index.js.map +1 -1
  33. package/dist/indexed-db/schema.js +1 -2
  34. package/dist/indexed-db/util.js +2 -6
  35. package/dist/indexed-db/util.js.map +1 -1
  36. package/dist/indexed-db-store.js +5 -19
  37. package/dist/indexed-db-store.js.map +1 -1
  38. package/dist/util.js +3 -6
  39. package/dist/util.js.map +1 -1
  40. package/package.json +14 -13
package/dist/errors.js CHANGED
@@ -1,20 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LoginContinuedInParentWindowError = void 0;
4
1
  /**
5
2
  * Special error class destined to be thrown when the login process was
6
3
  * performed in a popup and should be continued in the parent/initiating window.
7
4
  */
8
- class LoginContinuedInParentWindowError extends Error {
5
+ export class LoginContinuedInParentWindowError extends Error {
9
6
  constructor() {
10
7
  super('Login complete, please close the popup window.');
11
- Object.defineProperty(this, "code", {
12
- enumerable: true,
13
- configurable: true,
14
- writable: true,
15
- value: 'LOGIN_CONTINUED_IN_PARENT_WINDOW'
16
- });
8
+ this.code = 'LOGIN_CONTINUED_IN_PARENT_WINDOW';
17
9
  }
18
10
  }
19
- exports.LoginContinuedInParentWindowError = LoginContinuedInParentWindowError;
20
11
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,MAAa,iCAAkC,SAAQ,KAAK;IAE1D;QACE,KAAK,CAAC,gDAAgD,CAAC,CAAA;QAFzD;;;;mBAAO,kCAAkC;WAAA;IAGzC,CAAC;CACF;AALD,8EAKC","sourcesContent":["/**\n * Special error class destined to be thrown when the login process was\n * performed in a popup and should be continued in the parent/initiating window.\n */\nexport class LoginContinuedInParentWindowError extends Error {\n code = 'LOGIN_CONTINUED_IN_PARENT_WINDOW'\n constructor() {\n super('Login complete, please close the popup window.')\n }\n}\n"]}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,OAAO,iCAAkC,SAAQ,KAAK;IAE1D;QACE,KAAK,CAAC,gDAAgD,CAAC,CAAA;QAFzD,SAAI,GAAG,kCAAkC,CAAA;IAGzC,CAAC;CACF","sourcesContent":["/**\n * Special error class destined to be thrown when the login process was\n * performed in a popup and should be continued in the parent/initiating window.\n */\nexport class LoginContinuedInParentWindowError extends Error {\n code = 'LOGIN_CONTINUED_IN_PARENT_WINDOW'\n constructor() {\n super('Login complete, please close the popup window.')\n }\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import 'core-js/modules/esnext.symbol.async-dispose';
2
- import 'core-js/modules/esnext.symbol.dispose';
1
+ import 'core-js/es/symbol/async-dispose.js';
2
+ import 'core-js/es/symbol/dispose.js';
3
3
  export * from '@atproto/jwk-webcrypto';
4
4
  export * from '@atproto/oauth-client';
5
5
  export * from './browser-oauth-client.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,6CAA6C,CAAA;AACpD,OAAO,uCAAuC,CAAA;AAE9C,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AAErC,cAAc,2BAA2B,CAAA;AACzC,cAAc,aAAa,CAAA;AAC3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,oCAAoC,CAAA;AAC3C,OAAO,8BAA8B,CAAA;AAErC,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AAErC,cAAc,2BAA2B,CAAA;AACzC,cAAc,aAAa,CAAA;AAC3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAA"}
package/dist/index.js CHANGED
@@ -1,26 +1,8 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.buildLoopbackClientId = void 0;
18
- require("core-js/modules/esnext.symbol.async-dispose");
19
- require("core-js/modules/esnext.symbol.dispose");
20
- __exportStar(require("@atproto/jwk-webcrypto"), exports);
21
- __exportStar(require("@atproto/oauth-client"), exports);
22
- __exportStar(require("./browser-oauth-client.js"), exports);
23
- __exportStar(require("./errors.js"), exports);
24
- var util_js_1 = require("./util.js");
25
- Object.defineProperty(exports, "buildLoopbackClientId", { enumerable: true, get: function () { return util_js_1.buildLoopbackClientId; } });
1
+ import 'core-js/es/symbol/async-dispose.js';
2
+ import 'core-js/es/symbol/dispose.js';
3
+ export * from '@atproto/jwk-webcrypto';
4
+ export * from '@atproto/oauth-client';
5
+ export * from './browser-oauth-client.js';
6
+ export * from './errors.js';
7
+ export { buildLoopbackClientId } from './util.js';
26
8
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,uDAAoD;AACpD,iDAA8C;AAE9C,yDAAsC;AACtC,wDAAqC;AAErC,4DAAyC;AACzC,8CAA2B;AAC3B,qCAAiD;AAAxC,gHAAA,qBAAqB,OAAA","sourcesContent":["import 'core-js/modules/esnext.symbol.async-dispose'\nimport 'core-js/modules/esnext.symbol.dispose'\n\nexport * from '@atproto/jwk-webcrypto'\nexport * from '@atproto/oauth-client'\n\nexport * from './browser-oauth-client.js'\nexport * from './errors.js'\nexport { buildLoopbackClientId } from './util.js'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,oCAAoC,CAAA;AAC3C,OAAO,8BAA8B,CAAA;AAErC,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AAErC,cAAc,2BAA2B,CAAA;AACzC,cAAc,aAAa,CAAA;AAC3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAA","sourcesContent":["import 'core-js/es/symbol/async-dispose.js'\nimport 'core-js/es/symbol/dispose.js'\n\nexport * from '@atproto/jwk-webcrypto'\nexport * from '@atproto/oauth-client'\n\nexport * from './browser-oauth-client.js'\nexport * from './errors.js'\nexport { buildLoopbackClientId } from './util.js'\n"]}
@@ -1,30 +1,22 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DBIndex = void 0;
4
- const util_js_1 = require("./util.js");
5
- class DBIndex {
1
+ import { promisify } from './util.js';
2
+ export class DBIndex {
6
3
  constructor(idbIndex) {
7
- Object.defineProperty(this, "idbIndex", {
8
- enumerable: true,
9
- configurable: true,
10
- writable: true,
11
- value: idbIndex
12
- });
4
+ this.idbIndex = idbIndex;
13
5
  }
14
6
  count(query) {
15
- return (0, util_js_1.promisify)(this.idbIndex.count(query));
7
+ return promisify(this.idbIndex.count(query));
16
8
  }
17
9
  get(query) {
18
- return (0, util_js_1.promisify)(this.idbIndex.get(query));
10
+ return promisify(this.idbIndex.get(query));
19
11
  }
20
12
  getKey(query) {
21
- return (0, util_js_1.promisify)(this.idbIndex.getKey(query));
13
+ return promisify(this.idbIndex.getKey(query));
22
14
  }
23
15
  getAll(query, count) {
24
- return (0, util_js_1.promisify)(this.idbIndex.getAll(query, count));
16
+ return promisify(this.idbIndex.getAll(query, count));
25
17
  }
26
18
  getAllKeys(query, count) {
27
- return (0, util_js_1.promisify)(this.idbIndex.getAllKeys(query, count));
19
+ return promisify(this.idbIndex.getAllKeys(query, count));
28
20
  }
29
21
  deleteAll(query) {
30
22
  return new Promise((resolve, reject) => {
@@ -45,5 +37,4 @@ class DBIndex {
45
37
  });
46
38
  }
47
39
  }
48
- exports.DBIndex = DBIndex;
49
40
  //# sourceMappingURL=db-index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"db-index.js","sourceRoot":"","sources":["../../src/indexed-db/db-index.ts"],"names":[],"mappings":";;;AACA,uCAAqC;AAErC,MAAa,OAAO;IAClB,YAAoB,QAAkB;QAA1B;;;;mBAAQ,QAAQ;WAAU;IAAG,CAAC;IAE1C,KAAK,CAAC,KAAiC;QACrC,OAAO,IAAA,mBAAS,EAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA;IAC9C,CAAC;IAED,GAAG,CAAC,KAAgC;QAClC,OAAO,IAAA,mBAAS,EAAS,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAA;IACpD,CAAC;IAED,MAAM,CAAC,KAAgC;QACrC,OAAO,IAAA,mBAAS,EAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;IAC/C,CAAC;IAED,MAAM,CAAC,KAAwC,EAAE,KAAc;QAC7D,OAAO,IAAA,mBAAS,EAAW,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAA;IAChE,CAAC;IAED,UAAU,CAAC,KAAwC,EAAE,KAAc;QACjE,OAAO,IAAA,mBAAS,EAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAA;IAC1D,CAAC;IAED,SAAS,CAAC,KAAwC;QAChD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;YAC9C,MAAM,CAAC,SAAS,GAAG,UAAU,KAAK;gBAChC,MAAM,MAAM,GAAI,KAAa,CAAC,MAAM,CAAC,MAA4B,CAAA;gBACjE,IAAI,MAAM,EAAE,CAAC;oBACX,MAAM,CAAC,MAAM,EAAE,CAAA;oBACf,MAAM,CAAC,QAAQ,EAAE,CAAA;gBACnB,CAAC;qBAAM,CAAC;oBACN,OAAO,EAAE,CAAA;gBACX,CAAC;YACH,CAAC,CAAA;YACD,MAAM,CAAC,OAAO,GAAG,UAAU,KAAK;gBAC9B,MAAM,CAAE,KAAK,CAAC,MAAc,EAAE,KAAK,IAAI,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC,CAAA;YACvE,CAAC,CAAA;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AAxCD,0BAwCC","sourcesContent":["import { ObjectStoreSchema } from './schema.js'\nimport { promisify } from './util.js'\n\nexport class DBIndex<Schema extends ObjectStoreSchema> {\n constructor(private idbIndex: IDBIndex) {}\n\n count(query?: IDBValidKey | IDBKeyRange) {\n return promisify(this.idbIndex.count(query))\n }\n\n get(query: IDBValidKey | IDBKeyRange) {\n return promisify<Schema>(this.idbIndex.get(query))\n }\n\n getKey(query: IDBValidKey | IDBKeyRange) {\n return promisify(this.idbIndex.getKey(query))\n }\n\n getAll(query?: IDBValidKey | IDBKeyRange | null, count?: number) {\n return promisify<Schema[]>(this.idbIndex.getAll(query, count))\n }\n\n getAllKeys(query?: IDBValidKey | IDBKeyRange | null, count?: number) {\n return promisify(this.idbIndex.getAllKeys(query, count))\n }\n\n deleteAll(query?: IDBValidKey | IDBKeyRange | null): Promise<void> {\n return new Promise((resolve, reject) => {\n const result = this.idbIndex.openCursor(query)\n result.onsuccess = function (event) {\n const cursor = (event as any).target.result as IDBCursorWithValue\n if (cursor) {\n cursor.delete()\n cursor.continue()\n } else {\n resolve()\n }\n }\n result.onerror = function (event) {\n reject((event.target as any)?.error || new Error('Unexpected error'))\n }\n })\n }\n}\n"]}
1
+ {"version":3,"file":"db-index.js","sourceRoot":"","sources":["../../src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CAAC;oBACN,OAAO,EAAE,CAAA;gBACX,CAAC;YACH,CAAC,CAAA;YACD,MAAM,CAAC,OAAO,GAAG,UAAU,KAAK;gBAC9B,MAAM,CAAE,KAAK,CAAC,MAAc,EAAE,KAAK,IAAI,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC,CAAA;YACvE,CAAC,CAAA;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;CACF","sourcesContent":["import { ObjectStoreSchema } from './schema.js'\nimport { promisify } from './util.js'\n\nexport class DBIndex<Schema extends ObjectStoreSchema> {\n constructor(private idbIndex: IDBIndex) {}\n\n count(query?: IDBValidKey | IDBKeyRange) {\n return promisify(this.idbIndex.count(query))\n }\n\n get(query: IDBValidKey | IDBKeyRange) {\n return promisify<Schema>(this.idbIndex.get(query))\n }\n\n getKey(query: IDBValidKey | IDBKeyRange) {\n return promisify(this.idbIndex.getKey(query))\n }\n\n getAll(query?: IDBValidKey | IDBKeyRange | null, count?: number) {\n return promisify<Schema[]>(this.idbIndex.getAll(query, count))\n }\n\n getAllKeys(query?: IDBValidKey | IDBKeyRange | null, count?: number) {\n return promisify(this.idbIndex.getAllKeys(query, count))\n }\n\n deleteAll(query?: IDBValidKey | IDBKeyRange | null): Promise<void> {\n return new Promise((resolve, reject) => {\n const result = this.idbIndex.openCursor(query)\n result.onsuccess = function (event) {\n const cursor = (event as any).target.result as IDBCursorWithValue\n if (cursor) {\n cursor.delete()\n cursor.continue()\n } else {\n resolve()\n }\n }\n result.onerror = function (event) {\n reject((event.target as any)?.error || new Error('Unexpected error'))\n }\n })\n }\n}\n"]}
@@ -1,47 +1,38 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DBObjectStore = void 0;
4
- const db_index_js_1 = require("./db-index.js");
5
- const util_js_1 = require("./util.js");
6
- class DBObjectStore {
1
+ import { DBIndex } from './db-index.js';
2
+ import { promisify } from './util.js';
3
+ export class DBObjectStore {
7
4
  constructor(idbObjStore) {
8
- Object.defineProperty(this, "idbObjStore", {
9
- enumerable: true,
10
- configurable: true,
11
- writable: true,
12
- value: idbObjStore
13
- });
5
+ this.idbObjStore = idbObjStore;
14
6
  }
15
7
  get name() {
16
8
  return this.idbObjStore.name;
17
9
  }
18
10
  index(name) {
19
- return new db_index_js_1.DBIndex(this.idbObjStore.index(name));
11
+ return new DBIndex(this.idbObjStore.index(name));
20
12
  }
21
13
  get(key) {
22
- return (0, util_js_1.promisify)(this.idbObjStore.get(key));
14
+ return promisify(this.idbObjStore.get(key));
23
15
  }
24
16
  getKey(query) {
25
- return (0, util_js_1.promisify)(this.idbObjStore.getKey(query));
17
+ return promisify(this.idbObjStore.getKey(query));
26
18
  }
27
19
  getAll(query, count) {
28
- return (0, util_js_1.promisify)(this.idbObjStore.getAll(query, count));
20
+ return promisify(this.idbObjStore.getAll(query, count));
29
21
  }
30
22
  getAllKeys(query, count) {
31
- return (0, util_js_1.promisify)(this.idbObjStore.getAllKeys(query, count));
23
+ return promisify(this.idbObjStore.getAllKeys(query, count));
32
24
  }
33
25
  add(value, key) {
34
- return (0, util_js_1.promisify)(this.idbObjStore.add(value, key));
26
+ return promisify(this.idbObjStore.add(value, key));
35
27
  }
36
28
  put(value, key) {
37
- return (0, util_js_1.promisify)(this.idbObjStore.put(value, key));
29
+ return promisify(this.idbObjStore.put(value, key));
38
30
  }
39
31
  delete(key) {
40
- return (0, util_js_1.promisify)(this.idbObjStore.delete(key));
32
+ return promisify(this.idbObjStore.delete(key));
41
33
  }
42
34
  clear() {
43
- return (0, util_js_1.promisify)(this.idbObjStore.clear());
35
+ return promisify(this.idbObjStore.clear());
44
36
  }
45
37
  }
46
- exports.DBObjectStore = DBObjectStore;
47
38
  //# sourceMappingURL=db-object-store.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"db-object-store.js","sourceRoot":"","sources":["../../src/indexed-db/db-object-store.ts"],"names":[],"mappings":";;;AAAA,+CAAuC;AAEvC,uCAAqC;AAErC,MAAa,aAAa;IACxB,YAAoB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AAC,CAAA;IAChD,CAAC;IAED,KAAK;QACH,OAAO,IAAA,mBAAS,EAAC,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC,CAAA;IAC5C,CAAC;CACF;AA1CD,sCA0CC","sourcesContent":["import { DBIndex } from './db-index.js'\nimport { ObjectStoreSchema } from './schema.js'\nimport { promisify } from './util.js'\n\nexport class DBObjectStore<Schema extends ObjectStoreSchema> {\n constructor(private idbObjStore: IDBObjectStore) {}\n\n get name() {\n return this.idbObjStore.name\n }\n\n index(name: string) {\n return new DBIndex<Schema>(this.idbObjStore.index(name))\n }\n\n get(key: IDBValidKey | IDBKeyRange) {\n return promisify<Schema>(this.idbObjStore.get(key))\n }\n\n getKey(query: IDBValidKey | IDBKeyRange) {\n return promisify<IDBValidKey | undefined>(this.idbObjStore.getKey(query))\n }\n\n getAll(query?: IDBValidKey | IDBKeyRange | null, count?: number) {\n return promisify<Schema[]>(this.idbObjStore.getAll(query, count))\n }\n\n getAllKeys(query?: IDBValidKey | IDBKeyRange | null, count?: number) {\n return promisify<IDBValidKey[]>(this.idbObjStore.getAllKeys(query, count))\n }\n\n add(value: Schema, key?: IDBValidKey) {\n return promisify(this.idbObjStore.add(value, key))\n }\n\n put(value: Schema, key?: IDBValidKey) {\n return promisify(this.idbObjStore.put(value, key))\n }\n\n delete(key: IDBValidKey | IDBKeyRange) {\n return promisify(this.idbObjStore.delete(key))\n }\n\n clear() {\n return promisify(this.idbObjStore.clear())\n }\n}\n"]}
1
+ {"version":3,"file":"db-object-store.js","sourceRoot":"","sources":["../../src/indexed-db/db-object-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAEvC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC,MAAM,OAAO,aAAa;IACxB,YAAoB,WAA2B;QAA3B,gBAAW,GAAX,WAAW,CAAgB;IAAG,CAAC;IAEnD,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,WAA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'\nimport { ObjectStoreSchema } from './schema.js'\nimport { promisify } from './util.js'\n\nexport class DBObjectStore<Schema extends ObjectStoreSchema> {\n constructor(private idbObjStore: IDBObjectStore) {}\n\n get name() {\n return this.idbObjStore.name\n }\n\n index(name: string) {\n return new DBIndex<Schema>(this.idbObjStore.index(name))\n }\n\n get(key: IDBValidKey | IDBKeyRange) {\n return promisify<Schema>(this.idbObjStore.get(key))\n }\n\n getKey(query: IDBValidKey | IDBKeyRange) {\n return promisify<IDBValidKey | undefined>(this.idbObjStore.getKey(query))\n }\n\n getAll(query?: IDBValidKey | IDBKeyRange | null, count?: number) {\n return promisify<Schema[]>(this.idbObjStore.getAll(query, count))\n }\n\n getAllKeys(query?: IDBValidKey | IDBKeyRange | null, count?: number) {\n return promisify<IDBValidKey[]>(this.idbObjStore.getAllKeys(query, count))\n }\n\n add(value: Schema, key?: IDBValidKey) {\n return promisify(this.idbObjStore.add(value, key))\n }\n\n put(value: Schema, key?: IDBValidKey) {\n return promisify(this.idbObjStore.put(value, key))\n }\n\n delete(key: IDBValidKey | IDBKeyRange) {\n return promisify(this.idbObjStore.delete(key))\n }\n\n clear() {\n return promisify(this.idbObjStore.clear())\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import 'core-js/modules/esnext.symbol.dispose';
1
+ import 'core-js/es/symbol/dispose.js';
2
2
  import { DBObjectStore } from './db-object-store.js';
3
3
  import { DatabaseSchema } from './schema.js';
4
4
  export declare class DBTransaction<Schema extends DatabaseSchema> implements Disposable {
@@ -1 +1 @@
1
- {"version":3,"file":"db-transaction.d.ts","sourceRoot":"","sources":["../../src/indexed-db/db-transaction.ts"],"names":[],"mappings":"AAAA,OAAO,uCAAuC,CAAA;AAE9C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE5C,qBAAa,aAAa,CAAC,MAAM,SAAS,cAAc,CACtD,YAAW,UAAU;;gBAIT,EAAE,EAAE,cAAc;IAkB9B,SAAS,KAAK,EAAE,IAAI,cAAc,CAGjC;IAEK,KAAK;IAML,MAAM;IAMZ,WAAW,CAAC,CAAC,SAAS,MAAM,MAAM,GAAG,MAAM,EAAE,IAAI,EAAE,CAAC;IAKpD,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI;CAGzB"}
1
+ {"version":3,"file":"db-transaction.d.ts","sourceRoot":"","sources":["../../src/indexed-db/db-transaction.ts"],"names":[],"mappings":"AAAA,OAAO,8BAA8B,CAAA;AAErC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE5C,qBAAa,aAAa,CAAC,MAAM,SAAS,cAAc,CACtD,YAAW,UAAU;;gBAIT,EAAE,EAAE,cAAc;IAkB9B,SAAS,KAAK,EAAE,IAAI,cAAc,CAGjC;IAEK,KAAK;IAML,MAAM;IAMZ,WAAW,CAAC,CAAC,SAAS,MAAM,MAAM,GAAG,MAAM,EAAE,IAAI,EAAE,CAAC;IAKpD,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI;CAGzB"}
@@ -1,24 +1,9 @@
1
- "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
- var _DBTransaction_tx;
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.DBTransaction = void 0;
16
- require("core-js/modules/esnext.symbol.dispose");
17
- const db_object_store_js_1 = require("./db-object-store.js");
18
- class DBTransaction {
1
+ import 'core-js/es/symbol/dispose.js';
2
+ import { DBObjectStore } from './db-object-store.js';
3
+ export class DBTransaction {
4
+ #tx;
19
5
  constructor(tx) {
20
- _DBTransaction_tx.set(this, void 0);
21
- __classPrivateFieldSet(this, _DBTransaction_tx, tx, "f");
6
+ this.#tx = tx;
22
7
  const onAbort = () => {
23
8
  cleanup();
24
9
  };
@@ -26,7 +11,7 @@ class DBTransaction {
26
11
  cleanup();
27
12
  };
28
13
  const cleanup = () => {
29
- __classPrivateFieldSet(this, _DBTransaction_tx, null, "f");
14
+ this.#tx = null;
30
15
  tx.removeEventListener('abort', onAbort);
31
16
  tx.removeEventListener('complete', onComplete);
32
17
  };
@@ -34,28 +19,27 @@ class DBTransaction {
34
19
  tx.addEventListener('complete', onComplete);
35
20
  }
36
21
  get tx() {
37
- if (!__classPrivateFieldGet(this, _DBTransaction_tx, "f"))
22
+ if (!this.#tx)
38
23
  throw new Error('Transaction already ended');
39
- return __classPrivateFieldGet(this, _DBTransaction_tx, "f");
24
+ return this.#tx;
40
25
  }
41
26
  async abort() {
42
27
  const { tx } = this;
43
- __classPrivateFieldSet(this, _DBTransaction_tx, null, "f");
28
+ this.#tx = null;
44
29
  tx.abort();
45
30
  }
46
31
  async commit() {
47
32
  const { tx } = this;
48
- __classPrivateFieldSet(this, _DBTransaction_tx, null, "f");
33
+ this.#tx = null;
49
34
  tx.commit?.();
50
35
  }
51
36
  objectStore(name) {
52
37
  const store = this.tx.objectStore(name);
53
- return new db_object_store_js_1.DBObjectStore(store);
38
+ return new DBObjectStore(store);
54
39
  }
55
- [(_DBTransaction_tx = new WeakMap(), Symbol.dispose)]() {
56
- if (__classPrivateFieldGet(this, _DBTransaction_tx, "f"))
40
+ [Symbol.dispose]() {
41
+ if (this.#tx)
57
42
  this.commit();
58
43
  }
59
44
  }
60
- exports.DBTransaction = DBTransaction;
61
45
  //# sourceMappingURL=db-transaction.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"db-transaction.js","sourceRoot":"","sources":["../../src/indexed-db/db-transaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iDAA8C;AAE9C,6DAAoD;AAGpD,MAAa,aAAa;IAKxB,YAAY,EAAkB;QAF9B,oCAA0B;QAGxB,uBAAA,IAAI,qBAAO,EAAE,MAAA,CAAA;QAEb,MAAM,OAAO,GAAG,GAAG,EAAE;YACnB,OAAO,EAAE,CAAA;QACX,CAAC,CAAA;QACD,MAAM,UAAU,GAAG,GAAG,EAAE;YACtB,OAAO,EAAE,CAAA;QACX,CAAC,CAAA;QACD,MAAM,OAAO,GAAG,GAAG,EAAE;YACnB,uBAAA,IAAI,qBAAO,IAAI,MAAA,CAAA;YACf,EAAE,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;YACxC,EAAE,CAAC,mBAAmB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAA;QAChD,CAAC,CAAA;QACD,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACrC,EAAE,CAAC,gBAAgB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAA;IAC7C,CAAC;IAED,IAAc,EAAE;QACd,IAAI,CAAC,uBAAA,IAAI,yBAAI;YAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAA;QAC3D,OAAO,uBAAA,IAAI,yBAAI,CAAA;IACjB,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,CAAA;QACnB,uBAAA,IAAI,qBAAO,IAAI,MAAA,CAAA;QACf,EAAE,CAAC,KAAK,EAAE,CAAA;IACZ,CAAC;IAED,KAAK,CAAC,MAAM;QACV,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,CAAA;QACnB,uBAAA,IAAI,qBAAO,IAAI,MAAA,CAAA;QACf,EAAE,CAAC,MAAM,EAAE,EAAE,CAAA;IACf,CAAC;IAED,WAAW,CAAkC,IAAO;QAClD,MAAM,KAAK,GAAG,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;QACvC,OAAO,IAAI,kCAAa,CAAY,KAAK,CAAC,CAAA;IAC5C,CAAC;IAED,qCAAC,MAAM,CAAC,OAAO,EAAC;QACd,IAAI,uBAAA,IAAI,yBAAI;YAAE,IAAI,CAAC,MAAM,EAAE,CAAA;IAC7B,CAAC;CACF;AAhDD,sCAgDC","sourcesContent":["import 'core-js/modules/esnext.symbol.dispose'\n\nimport { DBObjectStore } from './db-object-store.js'\nimport { DatabaseSchema } from './schema.js'\n\nexport class DBTransaction<Schema extends DatabaseSchema>\n implements Disposable\n{\n #tx: IDBTransaction | null\n\n constructor(tx: IDBTransaction) {\n this.#tx = tx\n\n const onAbort = () => {\n cleanup()\n }\n const onComplete = () => {\n cleanup()\n }\n const cleanup = () => {\n this.#tx = null\n tx.removeEventListener('abort', onAbort)\n tx.removeEventListener('complete', onComplete)\n }\n tx.addEventListener('abort', onAbort)\n tx.addEventListener('complete', onComplete)\n }\n\n protected get tx(): IDBTransaction {\n if (!this.#tx) throw new Error('Transaction already ended')\n return this.#tx\n }\n\n async abort() {\n const { tx } = this\n this.#tx = null\n tx.abort()\n }\n\n async commit() {\n const { tx } = this\n this.#tx = null\n tx.commit?.()\n }\n\n objectStore<T extends keyof Schema & string>(name: T) {\n const store = this.tx.objectStore(name)\n return new DBObjectStore<Schema[T]>(store)\n }\n\n [Symbol.dispose](): void {\n if (this.#tx) this.commit()\n }\n}\n"]}
1
+ {"version":3,"file":"db-transaction.js","sourceRoot":"","sources":["../../src/indexed-db/db-transaction.ts"],"names":[],"mappings":"AAAA,OAAO,8BAA8B,CAAA;AAErC,OAAO,EA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ACvC,OAAO,IAAI,aAAa,CAAY,KAAK,CAAC,CAAA;IAC5C,CAAC;IAED,CAAC,MAAM,CAAC,OAAO,CAAC;QACd,IAAI,IAAI,CAAC,GAAG;YAAE,IAAI,CAAC,MAAM,EAAE,CAAA;IAC7B,CAAC;CACF","sourcesContent":["import 'core-js/es/symbol/dispose.js'\n\nimport { DBObjectStore } from './db-object-store.js'\nimport { DatabaseSchema } from './schema.js'\n\nexport class DBTransaction<Schema extends DatabaseSchema>\n implements Disposable\n{\n #tx: IDBTransaction | null\n\n constructor(tx: IDBTransaction) {\n this.#tx = tx\n\n const onAbort = () => {\n cleanup()\n }\n const onComplete = () => {\n cleanup()\n }\n const cleanup = () => {\n this.#tx = null\n tx.removeEventListener('abort', onAbort)\n tx.removeEventListener('complete', onComplete)\n }\n tx.addEventListener('abort', onAbort)\n tx.addEventListener('complete', onComplete)\n }\n\n protected get tx(): IDBTransaction {\n if (!this.#tx) throw new Error('Transaction already ended')\n return this.#tx\n }\n\n async abort() {\n const { tx } = this\n this.#tx = null\n tx.abort()\n }\n\n async commit() {\n const { tx } = this\n this.#tx = null\n tx.commit?.()\n }\n\n objectStore<T extends keyof Schema & string>(name: T) {\n const store = this.tx.objectStore(name)\n return new DBObjectStore<Schema[T]>(store)\n }\n\n [Symbol.dispose](): void {\n if (this.#tx) this.commit()\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import 'core-js/modules/esnext.symbol.dispose';
1
+ import 'core-js/es/symbol/dispose.js';
2
2
  import { DBTransaction } from './db-transaction.js';
3
3
  import { DatabaseSchema } from './schema.js';
4
4
  export declare class DB<Schema extends DatabaseSchema> implements Disposable {
@@ -1 +1 @@
1
- {"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/indexed-db/db.ts"],"names":[],"mappings":"AAAA,OAAO,uCAAuC,CAAA;AAE9C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA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c,EAC9D,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,aAAa,CAAC,CAAC,EAAE,EAAE,WAAW,KAAK,IAAI,CAAC,EACpD,SAAS,CAAC,EAAE,qBAAqB;gBAgCjC,EAAE,EAAE,WAAW,EACI,SAAS,CAAC,EAAE,qBAAqB,YAAA;IAetD,SAAS,KAAK,EAAE,IAAI,WAAW,CAG9B;IAED,IAAI,IAAI,WAEP;IAED,IAAI,gBAAgB,kBAEnB;IAED,IAAI,OAAO,WAEV;IAEK,WAAW,CAAC,CAAC,SAAS,SAAS,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,EAAE,EAAE,CAAC,EAC/D,UAAU,EAAE,CAAC,EACb,IAAI,EAAE,kBAAkB,EACxB,GAAG,EAAE,CAAC,EAAE,EAAE,aAAa,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,GACtE,OAAO,CAAC,CAAC,CAAC;IA4Bb,KAAK;IAML,CAAC,MAAM,CAAC,OAAO,CAAC;CAGjB"}
@@ -1,21 +1,6 @@
1
- "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
- var _DB_db;
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.DB = void 0;
16
- require("core-js/modules/esnext.symbol.dispose");
17
- const db_transaction_js_1 = require("./db-transaction.js");
18
- class DB {
1
+ import 'core-js/es/symbol/dispose.js';
2
+ import { DBTransaction } from './db-transaction.js';
3
+ export class DB {
19
4
  static async open(dbName, migrations, txOptions) {
20
5
  const db = await new Promise((resolve, reject) => {
21
6
  const request = indexedDB.open(dbName, migrations.length);
@@ -40,17 +25,12 @@ class DB {
40
25
  });
41
26
  return new DB(db, txOptions);
42
27
  }
28
+ #db;
43
29
  constructor(db, txOptions) {
44
- Object.defineProperty(this, "txOptions", {
45
- enumerable: true,
46
- configurable: true,
47
- writable: true,
48
- value: txOptions
49
- });
50
- _DB_db.set(this, void 0);
51
- __classPrivateFieldSet(this, _DB_db, db, "f");
30
+ this.txOptions = txOptions;
31
+ this.#db = db;
52
32
  const cleanup = () => {
53
- __classPrivateFieldSet(this, _DB_db, null, "f");
33
+ this.#db = null;
54
34
  db.removeEventListener('versionchange', cleanup);
55
35
  db.removeEventListener('close', cleanup);
56
36
  db.close(); // Can we call close on a "closed" database?
@@ -59,9 +39,9 @@ class DB {
59
39
  db.addEventListener('close', cleanup);
60
40
  }
61
41
  get db() {
62
- if (!__classPrivateFieldGet(this, _DB_db, "f"))
42
+ if (!this.#db)
63
43
  throw new Error('Database closed');
64
- return __classPrivateFieldGet(this, _DB_db, "f");
44
+ return this.#db;
65
45
  }
66
46
  get name() {
67
47
  return this.db.name;
@@ -87,7 +67,7 @@ class DB {
87
67
  tx.onerror = () => reject(tx.error);
88
68
  tx.onabort = () => reject(tx.error || new Error('Transaction aborted'));
89
69
  try {
90
- const value = await run(new db_transaction_js_1.DBTransaction(tx));
70
+ const value = await run(new DBTransaction(tx));
91
71
  result = { done: true, value };
92
72
  tx.commit();
93
73
  }
@@ -103,13 +83,12 @@ class DB {
103
83
  }
104
84
  close() {
105
85
  const { db } = this;
106
- __classPrivateFieldSet(this, _DB_db, null, "f");
86
+ this.#db = null;
107
87
  db.close();
108
88
  }
109
- [(_DB_db = new WeakMap(), Symbol.dispose)]() {
110
- if (__classPrivateFieldGet(this, _DB_db, "f"))
89
+ [Symbol.dispose]() {
90
+ if (this.#db)
111
91
  return this.close();
112
92
  }
113
93
  }
114
- exports.DB = DB;
115
94
  //# sourceMappingURL=db.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"db.js","sourceRoot":"","sources":["../../src/indexed-db/db.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iDAA8C;AAE9C,2DAAmD;AAGnD,MAAa,EAAE;IACb,MAAM,CAAC,KAAK,CAAC,IAAI,CACf,MAAc,EACd,UAAoD,EACpD,SAAiC;QAEjC,MAAM,EAAE,GAAG,MAAM,IAAI,OAAO,CAAc,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC5D,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,CAAA;YAEzD,OAAO,CAAC,OAAO,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;YAC7C,OAAO,CAAC,SAAS,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;YACjD,OAAO,CAAC,eAAe,GAAG,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE,EAAE;gBACvD,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAA;gBACzB,IAAI,CAAC;oBACH,KACE,IAAI,OAAO,GAAG,UAAU,EACxB,OAAO,GAAG,CAAC,UAAU,IAAI,UAAU,CAAC,MAAM,CAAC,EAC3C,EAAE,OAAO,EACT,CAAC;wBACD,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,CAAC,CAAA;wBACrC,IAAI,SAAS;4BAAE,SAAS,CAAC,EAAE,CAAC,CAAA;;4BACvB,MAAM,IAAI,KAAK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AAE,GAAG,IAAI,CAAA;QACnB,uBAAA,IAAI,UAAO,IAAI,MAAA,CAAA;QACf,EAAE,CAAC,KAAK,EAAE,CAAA;IACZ,CAAC;IAED,0BAAC,MAAM,CAAC,OAAO,EAAC;QACd,IAAI,uBAAA,IAAI,cAAI;YAAE,OAAO,IAAI,CAAC,KAAK,EAAE,CAAA;IACnC,CAAC;CACF;AA9GD,gBA8GC","sourcesContent":["import 'core-js/modules/esnext.symbol.dispose'\n\nimport { DBTransaction } from './db-transaction.js'\nimport { DatabaseSchema } from './schema.js'\n\nexport class DB<Schema extends DatabaseSchema> implements Disposable {\n static async open<Schema extends DatabaseSchema = DatabaseSchema>(\n dbName: string,\n migrations: ReadonlyArray<(db: IDBDatabase) => void>,\n txOptions?: IDBTransactionOptions,\n ) {\n const db = await new Promise<IDBDatabase>((resolve, reject) => {\n const request = indexedDB.open(dbName, migrations.length)\n\n request.onerror = () => reject(request.error)\n request.onsuccess = () => resolve(request.result)\n request.onupgradeneeded = ({ oldVersion, newVersion }) => {\n const db = request.result\n try {\n for (\n let version = oldVersion;\n version < (newVersion ?? migrations.length);\n ++version\n ) {\n const migration = migrations[version]\n if (migration) migration(db)\n else throw new Error(`Missing migration for version ${version}`)\n }\n } catch (err) {\n db.close()\n reject(err)\n }\n }\n })\n\n return new DB<Schema>(db, txOptions)\n }\n\n #db: null | IDBDatabase\n\n constructor(\n db: IDBDatabase,\n protected readonly txOptions?: IDBTransactionOptions,\n ) {\n this.#db = db\n\n const cleanup = () => {\n this.#db = null\n db.removeEventListener('versionchange', cleanup)\n db.removeEventListener('close', cleanup)\n db.close() // Can we call close on a \"closed\" database?\n }\n\n db.addEventListener('versionchange', cleanup)\n db.addEventListener('close', cleanup)\n }\n\n protected get db(): IDBDatabase {\n if (!this.#db) throw new Error('Database closed')\n return this.#db\n }\n\n get name() {\n return this.db.name\n }\n\n get objectStoreNames() {\n return this.db.objectStoreNames\n }\n\n get version() {\n return this.db.version\n }\n\n async transaction<T extends readonly (keyof Schema & string)[], R>(\n storeNames: T,\n mode: IDBTransactionMode,\n run: (tx: DBTransaction<Pick<Schema, T[number]>>) => R | PromiseLike<R>,\n ): Promise<R> {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise<R>(async (resolve, reject) => {\n try {\n const tx = this.db.transaction(storeNames, mode, this.txOptions)\n let result: { done: false } | { done: true; value: R } = { done: false }\n\n tx.oncomplete = () => {\n if (result.done) resolve(result.value)\n else reject(new Error('Transaction completed without result'))\n }\n tx.onerror = () => reject(tx.error)\n tx.onabort = () => reject(tx.error || new Error('Transaction aborted'))\n\n try {\n const value = await run(new DBTransaction(tx))\n result = { done: true, value }\n tx.commit()\n } catch (err) {\n tx.abort()\n throw err\n }\n } catch (err) {\n reject(err)\n }\n })\n }\n\n close() {\n const { db } = this\n this.#db = null\n db.close()\n }\n\n [Symbol.dispose]() {\n if (this.#db) return this.close()\n }\n}\n"]}
1
+ {"version":3,"file":"db.js","sourceRoot":"","sources":["../../src/indexed-db/db.ts"],"names":[],"mappings":"AAAA,OAAO,8BAA8B,CAAA;AAErC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAGnD,MAAM,OAAO,EAAE;IACb,MAAM,CAAC,KAAK,CAAC,IAAI,CACf,MAAc,EACd,UAAoD,EACpD,SAAiC;QAEjC,MAAM,EAAE,GAAG,MAAM,IAAI,OAAO,CAAc,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC5D,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,CAAA;YAEzD,OAAO,CAAC,OAAO,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;YAC7C,OAAO,CAAC,SAAS,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;YACjD,OAAO,CAAC,eAAe,GAAG,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE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,IAAI,EAAE,KAAK,EAAE,CAAA;oBAC9B,EAAE,CAAC,MAAM,EAAE,CAAA;gBACb,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,EAAE,CAAC,KAAK,EAAE,CAAA;oBACV,MAAM,GAAG,CAAA;gBACX,CAAC;YACH,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,MAAM,CAAC,GAAG,CAAC,CAAA;YACb,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,KAAK;QACH,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,CAAA;QACnB,IAAI,CAAC,GAAG,GAAG,IAAI,CAAA;QACf,EAAE,CAAC,KAAK,EAAE,CAAA;IACZ,CAAC;IAED,CAAC,MAAM,CAAC,OAAO,CAAC;QACd,IAAI,IAAI,CAAC,GAAG;YAAE,OAAO,IAAI,CAAC,KAAK,EAAE,CAAA;IACnC,CAAC;CACF","sourcesContent":["import 'core-js/es/symbol/dispose.js'\n\nimport { DBTransaction } from './db-transaction.js'\nimport { DatabaseSchema } from './schema.js'\n\nexport class DB<Schema extends DatabaseSchema> implements Disposable {\n static async open<Schema extends DatabaseSchema = DatabaseSchema>(\n dbName: string,\n migrations: ReadonlyArray<(db: IDBDatabase) => void>,\n txOptions?: IDBTransactionOptions,\n ) {\n const db = await new Promise<IDBDatabase>((resolve, reject) => {\n const request = indexedDB.open(dbName, migrations.length)\n\n request.onerror = () => reject(request.error)\n request.onsuccess = () => resolve(request.result)\n request.onupgradeneeded = ({ oldVersion, newVersion }) => {\n const db = request.result\n try {\n for (\n let version = oldVersion;\n version < (newVersion ?? migrations.length);\n ++version\n ) {\n const migration = migrations[version]\n if (migration) migration(db)\n else throw new Error(`Missing migration for version ${version}`)\n }\n } catch (err) {\n db.close()\n reject(err)\n }\n }\n })\n\n return new DB<Schema>(db, txOptions)\n }\n\n #db: null | IDBDatabase\n\n constructor(\n db: IDBDatabase,\n protected readonly txOptions?: IDBTransactionOptions,\n ) {\n this.#db = db\n\n const cleanup = () => {\n this.#db = null\n db.removeEventListener('versionchange', cleanup)\n db.removeEventListener('close', cleanup)\n db.close() // Can we call close on a \"closed\" database?\n }\n\n db.addEventListener('versionchange', cleanup)\n db.addEventListener('close', cleanup)\n }\n\n protected get db(): IDBDatabase {\n if (!this.#db) throw new Error('Database closed')\n return this.#db\n }\n\n get name() {\n return this.db.name\n }\n\n get objectStoreNames() {\n return this.db.objectStoreNames\n }\n\n get version() {\n return this.db.version\n }\n\n async transaction<T extends readonly (keyof Schema & string)[], R>(\n storeNames: T,\n mode: IDBTransactionMode,\n run: (tx: DBTransaction<Pick<Schema, T[number]>>) => R | PromiseLike<R>,\n ): Promise<R> {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise<R>(async (resolve, reject) => {\n try {\n const tx = this.db.transaction(storeNames, mode, this.txOptions)\n let result: { done: false } | { done: true; value: R } = { done: false }\n\n tx.oncomplete = () => {\n if (result.done) resolve(result.value)\n else reject(new Error('Transaction completed without result'))\n }\n tx.onerror = () => reject(tx.error)\n tx.onabort = () => reject(tx.error || new Error('Transaction aborted'))\n\n try {\n const value = await run(new DBTransaction(tx))\n result = { done: true, value }\n tx.commit()\n } catch (err) {\n tx.abort()\n throw err\n }\n } catch (err) {\n reject(err)\n }\n })\n }\n\n close() {\n const { db } = this\n this.#db = null\n db.close()\n }\n\n [Symbol.dispose]() {\n if (this.#db) return this.close()\n }\n}\n"]}
@@ -1,21 +1,5 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./db.js"), exports);
18
- __exportStar(require("./db-index.js"), exports);
19
- __exportStar(require("./db-object-store.js"), exports);
20
- __exportStar(require("./db-transaction.js"), exports);
1
+ export * from './db.js';
2
+ export * from './db-index.js';
3
+ export * from './db-object-store.js';
4
+ export * from './db-transaction.js';
21
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/indexed-db/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,gDAA6B;AAC7B,uDAAoC;AACpC,sDAAmC","sourcesContent":["export * from './db.js'\nexport * from './db-index.js'\nexport * from './db-object-store.js'\nexport * from './db-transaction.js'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/indexed-db/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,eAAe,CAAA;AAC7B,cAAc,sBAAsB,CAAA;AACpC,cAAc,qBAAqB,CAAA","sourcesContent":["export * from './db.js'\nexport * from './db-index.js'\nexport * from './db-object-store.js'\nexport * from './db-transaction.js'\n"]}
@@ -1,3 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
3
2
  //# sourceMappingURL=schema.js.map
@@ -1,8 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleRequest = handleRequest;
4
- exports.promisify = promisify;
5
- function handleRequest(request, onSuccess, onError) {
1
+ export function handleRequest(request, onSuccess, onError) {
6
2
  const cleanup = () => {
7
3
  request.removeEventListener('success', success);
8
4
  request.removeEventListener('error', error);
@@ -18,7 +14,7 @@ function handleRequest(request, onSuccess, onError) {
18
14
  request.addEventListener('success', success);
19
15
  request.addEventListener('error', error);
20
16
  }
21
- function promisify(request) {
17
+ export function promisify(request) {
22
18
  return new Promise((resolve, reject) => {
23
19
  handleRequest(request, resolve, reject);
24
20
  });
@@ -1 +1 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/indexed-db/util.ts"],"names":[],"mappings":";;AAAA,sCAmBC;AAED,8BAIC;AAzBD,SAAgB,aAAa,CAC3B,OAAsB,EACtB,SAA8B,EAC9B,OAA+B;IAE/B,MAAM,OAAO,GAAG,GAAG,EAAE;QACnB,OAAO,CAAC,mBAAmB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;QAC/C,OAAO,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAC7C,CAAC,CAAA;IACD,MAAM,OAAO,GAAG,GAAG,EAAE;QACnB,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QACzB,OAAO,EAAE,CAAA;IACX,CAAC,CAAA;IACD,MAAM,KAAK,GAAG,GAAG,EAAE;QACjB,OAAO,CAAC,OAAO,CAAC,KAAK,IAAI,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC,CAAA;QACpD,OAAO,EAAE,CAAA;IACX,CAAC,CAAA;IACD,OAAO,CAAC,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;IAC5C,OAAO,CAAC,gBAAgB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;AAC1C,CAAC;AAED,SAAgB,SAAS,CAAI,OAAsB;IACjD,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACxC,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;IACzC,CAAC,CAAC,CAAA;AACJ,CAAC","sourcesContent":["export function handleRequest<T>(\n request: IDBRequest<T>,\n onSuccess: (result: T) => void,\n onError: (error: Error) => void,\n) {\n const cleanup = () => {\n request.removeEventListener('success', success)\n request.removeEventListener('error', error)\n }\n const success = () => {\n onSuccess(request.result)\n cleanup()\n }\n const error = () => {\n onError(request.error || new Error('Unknown error'))\n cleanup()\n }\n request.addEventListener('success', success)\n request.addEventListener('error', error)\n}\n\nexport function promisify<T>(request: IDBRequest<T>) {\n return new Promise<T>((resolve, reject) => {\n handleRequest(request, resolve, reject)\n })\n}\n"]}
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/indexed-db/util.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,aAAa,CAC3B,OAAsB,EACtB,SAA8B,EAC9B,OAA+B;IAE/B,MAAM,OAAO,GAAG,GAAG,EAAE;QACnB,OAAO,CAAC,mBAAmB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;QAC/C,OAAO,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAC7C,CAAC,CAAA;IACD,MAAM,OAAO,GAAG,GAAG,EAAE;QACnB,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QACzB,OAAO,EAAE,CAAA;IACX,CAAC,CAAA;IACD,MAAM,KAAK,GAAG,GAAG,EAAE;QACjB,OAAO,CAAC,OAAO,CAAC,KAAK,IAAI,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC,CAAA;QACpD,OAAO,EAAE,CAAA;IACX,CAAC,CAAA;IACD,OAAO,CAAC,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;IAC5C,OAAO,CAAC,gBAAgB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;AAC1C,CAAC;AAED,MAAM,UAAU,SAAS,CAAI,OAAsB;IACjD,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACxC,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;IACzC,CAAC,CAAC,CAAA;AACJ,CAAC","sourcesContent":["export function handleRequest<T>(\n request: IDBRequest<T>,\n onSuccess: (result: T) => void,\n onError: (error: Error) => void,\n) {\n const cleanup = () => {\n request.removeEventListener('success', success)\n request.removeEventListener('error', error)\n }\n const success = () => {\n onSuccess(request.result)\n cleanup()\n }\n const error = () => {\n onError(request.error || new Error('Unknown error'))\n cleanup()\n }\n request.addEventListener('success', success)\n request.addEventListener('error', error)\n}\n\nexport function promisify<T>(request: IDBRequest<T>) {\n return new Promise<T>((resolve, reject) => {\n handleRequest(request, resolve, reject)\n })\n}\n"]}
@@ -1,25 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IndexedDBStore = void 0;
4
- const index_js_1 = require("./indexed-db/index.js");
1
+ import { DB } from './indexed-db/index.js';
5
2
  const storeName = 'store';
6
- class IndexedDBStore {
3
+ export class IndexedDBStore {
7
4
  constructor(dbName, maxAge = 600e3) {
8
- Object.defineProperty(this, "dbName", {
9
- enumerable: true,
10
- configurable: true,
11
- writable: true,
12
- value: dbName
13
- });
14
- Object.defineProperty(this, "maxAge", {
15
- enumerable: true,
16
- configurable: true,
17
- writable: true,
18
- value: maxAge
19
- });
5
+ this.dbName = dbName;
6
+ this.maxAge = maxAge;
20
7
  }
21
8
  async run(mode, fn) {
22
- const db = await index_js_1.DB.open(this.dbName, [
9
+ const db = await DB.open(this.dbName, [
23
10
  (db) => {
24
11
  const store = db.createObjectStore(storeName);
25
12
  store.createIndex('createdAt', 'createdAt', { unique: false });
@@ -64,5 +51,4 @@ class IndexedDBStore {
64
51
  });
65
52
  }
66
53
  }
67
- exports.IndexedDBStore = IndexedDBStore;
68
54
  //# sourceMappingURL=indexed-db-store.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"indexed-db-store.js","sourceRoot":"","sources":["../src/indexed-db-store.ts"],"names":[],"mappings":";;;AACA,oDAAyD;AAEzD,MAAM,SAAS,GAAG,OAAO,CAAA;AAMzB,MAAa,cAAc;IAKzB,YACU,MAAc,EACZ,SAAS,KAAK;QADxB;;;;mBAAQ,MAAM;WAAQ;QACtB;;;;mBAAU,MAAM;WAAQ;IACvB,CAAC;IAEM,KAAK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E,KAAQ;QACxB,MAAM,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE;YACpC,KAAK,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,CAAA;QAClD,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAM;QACd,MAAM,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE;YACpC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QACnB,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,cAAc;QAClB,MAAM,UAAU,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,CAAA;QACrD,MAAM,KAAK,GAAG,WAAW,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;QAEhD,MAAM,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;YAC1C,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;YACtC,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;YAC1C,KAAK,MAAM,GAAG,IAAI,IAAI;gBAAE,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAC3C,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AArED,wCAqEC","sourcesContent":["import { Key, SimpleStore, Value } from '@atproto-labs/simple-store'\nimport { DB, DBObjectStore } from './indexed-db/index.js'\n\nconst storeName = 'store'\ntype Item<V> = {\n value: V\n createdAt: Date\n}\n\nexport class IndexedDBStore<\n K extends Extract<IDBValidKey, Key>,\n V extends Value,\n> implements SimpleStore<K, V>\n{\n constructor(\n private dbName: string,\n protected maxAge = 600e3,\n ) {}\n\n protected async run<R>(\n mode: 'readonly' | 'readwrite',\n fn: (s: DBObjectStore<Item<V>>) => R | Promise<R>,\n ): Promise<R> {\n const db = await DB.open<{ store: Item<V> }>(\n this.dbName,\n [\n (db) => {\n const store = db.createObjectStore(storeName)\n store.createIndex('createdAt', 'createdAt', { unique: false })\n },\n ],\n { durability: 'strict' },\n )\n try {\n return await db.transaction([storeName], mode, (tx) =>\n fn(tx.objectStore(storeName)),\n )\n } finally {\n await db[Symbol.dispose]()\n }\n }\n\n async get(key: K): Promise<V | undefined> {\n const item = await this.run('readonly', (store) => store.get(key))\n\n if (!item) return undefined\n\n const age = Date.now() - item.createdAt.getTime()\n if (age > this.maxAge) {\n await this.del(key)\n return undefined\n }\n\n return item?.value\n }\n\n async set(key: K, value: V): Promise<void> {\n await this.run('readwrite', (store) => {\n store.put({ value, createdAt: new Date() }, key)\n })\n }\n\n async del(key: K): Promise<void> {\n await this.run('readwrite', (store) => {\n store.delete(key)\n })\n }\n\n async deleteOutdated() {\n const upperBound = new Date(Date.now() - this.maxAge)\n const query = IDBKeyRange.upperBound(upperBound)\n\n await this.run('readwrite', async (store) => {\n const index = store.index('createdAt')\n const keys = await index.getAllKeys(query)\n for (const key of keys) store.delete(key)\n })\n }\n}\n"]}
1
+ {"version":3,"file":"indexed-db-store.js","sourceRoot":"","sources":["../src/indexed-db-store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAiB,MAAM,uBAAuB,CAAA;AAEzD,MAAM,SAAS,GAAG,OAAO,CAAA;AAMzB,MAAM,OAAO,cAAc;IAKzB,YACU,MAAc,EACZ,SAAS,KAAK;QADhB,WAAM,GAAN,MAAM,CAAQ;QACZ,WAAM,GAAN,MAAM,CAAQ;IACvB,CAAC;IAEM,KAAK,CAAC,GAAG,CACjB,IAA8B,EAC9B,EAAiD;QAEjD,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,IAAI,CACtB,IAAI,CAAC,MAAM,EACX;YACE,CAAC,EAAE,EAAE,EAAE;gBACL,M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AAE,EAAE,EAAE,GAAG,CAAC,CAAA;QAClD,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAM;QACd,MAAM,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE;YACpC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QACnB,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,cAAc;QAClB,MAAM,UAAU,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,CAAA;QACrD,MAAM,KAAK,GAAG,WAAW,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;QAEhD,MAAM,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;YAC1C,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;YACtC,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;YAC1C,KAAK,MAAM,GAAG,IAAI,IAAI;gBAAE,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAC3C,CAAC,CAAC,CAAA;IACJ,CAAC;CACF","sourcesContent":["import { Key, SimpleStore, Value } from '@atproto-labs/simple-store'\nimport { DB, DBObjectStore } from './indexed-db/index.js'\n\nconst storeName = 'store'\ntype Item<V> = {\n value: V\n createdAt: Date\n}\n\nexport class IndexedDBStore<\n K extends Extract<IDBValidKey, Key>,\n V extends Value,\n> implements SimpleStore<K, V>\n{\n constructor(\n private dbName: string,\n protected maxAge = 600e3,\n ) {}\n\n protected async run<R>(\n mode: 'readonly' | 'readwrite',\n fn: (s: DBObjectStore<Item<V>>) => R | Promise<R>,\n ): Promise<R> {\n const db = await DB.open<{ store: Item<V> }>(\n this.dbName,\n [\n (db) => {\n const store = db.createObjectStore(storeName)\n store.createIndex('createdAt', 'createdAt', { unique: false })\n },\n ],\n { durability: 'strict' },\n )\n try {\n return await db.transaction([storeName], mode, (tx) =>\n fn(tx.objectStore(storeName)),\n )\n } finally {\n await db[Symbol.dispose]()\n }\n }\n\n async get(key: K): Promise<V | undefined> {\n const item = await this.run('readonly', (store) => store.get(key))\n\n if (!item) return undefined\n\n const age = Date.now() - item.createdAt.getTime()\n if (age > this.maxAge) {\n await this.del(key)\n return undefined\n }\n\n return item?.value\n }\n\n async set(key: K, value: V): Promise<void> {\n await this.run('readwrite', (store) => {\n store.put({ value, createdAt: new Date() }, key)\n })\n }\n\n async del(key: K): Promise<void> {\n await this.run('readwrite', (store) => {\n store.delete(key)\n })\n }\n\n async deleteOutdated() {\n const upperBound = new Date(Date.now() - this.maxAge)\n const query = IDBKeyRange.upperBound(upperBound)\n\n await this.run('readwrite', async (store) => {\n const index = store.index('createdAt')\n const keys = await index.getAllKeys(query)\n for (const key of keys) store.delete(key)\n })\n }\n}\n"]}