@atproto/oauth-client-browser 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. package/LICENSE.txt +7 -0
  2. package/dist/browser-oauth-client.d.ts +58 -0
  3. package/dist/browser-oauth-client.d.ts.map +1 -0
  4. package/dist/browser-oauth-client.js +353 -0
  5. package/dist/browser-oauth-client.js.map +1 -0
  6. package/dist/browser-oauth-database.d.ts +61 -0
  7. package/dist/browser-oauth-database.d.ts.map +1 -0
  8. package/dist/browser-oauth-database.js +175 -0
  9. package/dist/browser-oauth-database.js.map +1 -0
  10. package/dist/browser-runtime-implementation.d.ts +10 -0
  11. package/dist/browser-runtime-implementation.d.ts.map +1 -0
  12. package/dist/browser-runtime-implementation.js +56 -0
  13. package/dist/browser-runtime-implementation.js.map +1 -0
  14. package/dist/disposable-polyfill/index.d.ts +1 -0
  15. package/dist/disposable-polyfill/index.d.ts.map +1 -0
  16. package/dist/disposable-polyfill/index.js +11 -0
  17. package/dist/disposable-polyfill/index.js.map +1 -0
  18. package/dist/errors.d.ts +9 -0
  19. package/dist/errors.d.ts.map +1 -0
  20. package/dist/errors.js +20 -0
  21. package/dist/errors.js.map +1 -0
  22. package/dist/index.d.ts +11 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +31 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/indexed-db/db-index.d.ts +12 -0
  27. package/dist/indexed-db/db-index.d.ts.map +1 -0
  28. package/dist/indexed-db/db-index.js +49 -0
  29. package/dist/indexed-db/db-index.js.map +1 -0
  30. package/dist/indexed-db/db-object-store.d.ts +17 -0
  31. package/dist/indexed-db/db-object-store.d.ts.map +1 -0
  32. package/dist/indexed-db/db-object-store.js +47 -0
  33. package/dist/indexed-db/db-object-store.js.map +1 -0
  34. package/dist/indexed-db/db-transaction.d.ts +13 -0
  35. package/dist/indexed-db/db-transaction.d.ts.map +1 -0
  36. package/dist/indexed-db/db-transaction.js +60 -0
  37. package/dist/indexed-db/db-transaction.js.map +1 -0
  38. package/dist/indexed-db/db.d.ts +17 -0
  39. package/dist/indexed-db/db.d.ts.map +1 -0
  40. package/dist/indexed-db/db.js +114 -0
  41. package/dist/indexed-db/db.js.map +1 -0
  42. package/dist/indexed-db/index.d.ts +6 -0
  43. package/dist/indexed-db/index.d.ts.map +1 -0
  44. package/dist/indexed-db/index.js +22 -0
  45. package/dist/indexed-db/index.js.map +1 -0
  46. package/dist/indexed-db/schema.d.ts +3 -0
  47. package/dist/indexed-db/schema.d.ts.map +1 -0
  48. package/dist/indexed-db/schema.js +3 -0
  49. package/dist/indexed-db/schema.js.map +1 -0
  50. package/dist/indexed-db/util.d.ts +2 -0
  51. package/dist/indexed-db/util.d.ts.map +1 -0
  52. package/dist/indexed-db/util.js +24 -0
  53. package/dist/indexed-db/util.js.map +1 -0
  54. package/dist/indexed-db-store.d.ts +18 -0
  55. package/dist/indexed-db-store.d.ts.map +1 -0
  56. package/dist/indexed-db-store.js +68 -0
  57. package/dist/indexed-db-store.js.map +1 -0
  58. package/dist/util.d.ts +18 -0
  59. package/dist/util.d.ts.map +1 -0
  60. package/dist/util.js +19 -0
  61. package/dist/util.js.map +1 -0
  62. package/package.json +72 -0
@@ -0,0 +1,175 @@
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 _BrowserOAuthDatabase_dbPromise, _BrowserOAuthDatabase_cleanupInterval;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.BrowserOAuthDatabase = void 0;
16
+ const jwk_webcrypto_1 = require("@atproto/jwk-webcrypto");
17
+ const index_js_1 = require("./indexed-db/index.js");
18
+ function encodeKey(key) {
19
+ if (!(key instanceof jwk_webcrypto_1.WebcryptoKey) || !key.kid) {
20
+ throw new Error('Invalid key object');
21
+ }
22
+ return {
23
+ keyId: key.kid,
24
+ keyPair: key.cryptoKeyPair,
25
+ };
26
+ }
27
+ async function decodeKey(encoded) {
28
+ return jwk_webcrypto_1.WebcryptoKey.fromKeypair(encoded.keyPair, encoded.keyId);
29
+ }
30
+ const STORES = [
31
+ 'state',
32
+ 'session',
33
+ 'didCache',
34
+ 'dpopNonceCache',
35
+ 'handleCache',
36
+ 'authorizationServerMetadataCache',
37
+ 'protectedResourceMetadataCache',
38
+ ];
39
+ class BrowserOAuthDatabase {
40
+ constructor(options) {
41
+ _BrowserOAuthDatabase_dbPromise.set(this, void 0);
42
+ _BrowserOAuthDatabase_cleanupInterval.set(this, void 0);
43
+ __classPrivateFieldSet(this, _BrowserOAuthDatabase_dbPromise, index_js_1.DB.open(options?.name ?? '@atproto-oauth-client', [
44
+ (db) => {
45
+ for (const name of STORES) {
46
+ const store = db.createObjectStore(name, { autoIncrement: true });
47
+ store.createIndex('expiresAt', 'expiresAt', { unique: false });
48
+ }
49
+ },
50
+ ], { durability: options?.durability ?? 'strict' }), "f");
51
+ __classPrivateFieldSet(this, _BrowserOAuthDatabase_cleanupInterval, setInterval(() => {
52
+ void this.cleanup();
53
+ }, options?.cleanupInterval ?? 30e3), "f");
54
+ }
55
+ async run(storeName, mode, fn) {
56
+ const db = await __classPrivateFieldGet(this, _BrowserOAuthDatabase_dbPromise, "f");
57
+ return await db.transaction([storeName], mode, (tx) => fn(tx.objectStore(storeName)));
58
+ }
59
+ createStore(name, { encode, decode, expiresAt, }) {
60
+ return {
61
+ get: async (key) => {
62
+ // Find item in store
63
+ const item = await this.run(name, 'readonly', (store) => store.get(key));
64
+ // Not found
65
+ if (item === undefined)
66
+ return undefined;
67
+ // Too old (delete)
68
+ if (item.expiresAt != null && new Date(item.expiresAt) < new Date()) {
69
+ await this.run(name, 'readwrite', (store) => store.delete(key));
70
+ return undefined;
71
+ }
72
+ // Item found and valid. Decode
73
+ return decode(item.value);
74
+ },
75
+ getKeys: async () => {
76
+ const keys = await this.run(name, 'readonly', (store) => store.getAllKeys());
77
+ return keys.filter((key) => typeof key === 'string');
78
+ },
79
+ set: async (key, value) => {
80
+ // Create encoded item record
81
+ const item = {
82
+ value: await encode(value),
83
+ expiresAt: expiresAt(value)?.toISOString(),
84
+ };
85
+ // Store item record
86
+ await this.run(name, 'readwrite', (store) => store.put(item, key));
87
+ },
88
+ del: async (key) => {
89
+ // Delete
90
+ await this.run(name, 'readwrite', (store) => store.delete(key));
91
+ },
92
+ };
93
+ }
94
+ getSessionStore() {
95
+ return this.createStore('session', {
96
+ expiresAt: ({ tokenSet }) => tokenSet.refresh_token || tokenSet.expires_at == null
97
+ ? null
98
+ : new Date(tokenSet.expires_at),
99
+ encode: ({ dpopKey, ...session }) => ({
100
+ ...session,
101
+ dpopKey: encodeKey(dpopKey),
102
+ }),
103
+ decode: async ({ dpopKey, ...encoded }) => ({
104
+ ...encoded,
105
+ dpopKey: await decodeKey(dpopKey),
106
+ }),
107
+ });
108
+ }
109
+ getStateStore() {
110
+ return this.createStore('state', {
111
+ expiresAt: (_value) => new Date(Date.now() + 10 * 60e3),
112
+ encode: ({ dpopKey, ...session }) => ({
113
+ ...session,
114
+ dpopKey: encodeKey(dpopKey),
115
+ }),
116
+ decode: async ({ dpopKey, ...encoded }) => ({
117
+ ...encoded,
118
+ dpopKey: await decodeKey(dpopKey),
119
+ }),
120
+ });
121
+ }
122
+ getDpopNonceCache() {
123
+ return this.createStore('dpopNonceCache', {
124
+ expiresAt: (_value) => new Date(Date.now() + 600e3),
125
+ encode: (value) => value,
126
+ decode: (encoded) => encoded,
127
+ });
128
+ }
129
+ getDidCache() {
130
+ return this.createStore('didCache', {
131
+ expiresAt: (_value) => new Date(Date.now() + 60e3),
132
+ encode: (value) => value,
133
+ decode: (encoded) => encoded,
134
+ });
135
+ }
136
+ getHandleCache() {
137
+ return this.createStore('handleCache', {
138
+ expiresAt: (_value) => new Date(Date.now() + 60e3),
139
+ encode: (value) => value,
140
+ decode: (encoded) => encoded,
141
+ });
142
+ }
143
+ getAuthorizationServerMetadataCache() {
144
+ return this.createStore('authorizationServerMetadataCache', {
145
+ expiresAt: (_value) => new Date(Date.now() + 60e3),
146
+ encode: (value) => value,
147
+ decode: (encoded) => encoded,
148
+ });
149
+ }
150
+ getProtectedResourceMetadataCache() {
151
+ return this.createStore('protectedResourceMetadataCache', {
152
+ expiresAt: (_value) => new Date(Date.now() + 60e3),
153
+ encode: (value) => value,
154
+ decode: (encoded) => encoded,
155
+ });
156
+ }
157
+ async cleanup() {
158
+ const db = await __classPrivateFieldGet(this, _BrowserOAuthDatabase_dbPromise, "f");
159
+ for (const name of STORES) {
160
+ await db.transaction([name], 'readwrite', (tx) => tx
161
+ .objectStore(name)
162
+ .index('expiresAt')
163
+ .deleteAll(IDBKeyRange.upperBound(Date.now())));
164
+ }
165
+ }
166
+ async [(_BrowserOAuthDatabase_dbPromise = new WeakMap(), _BrowserOAuthDatabase_cleanupInterval = new WeakMap(), Symbol.asyncDispose)]() {
167
+ clearInterval(__classPrivateFieldGet(this, _BrowserOAuthDatabase_cleanupInterval, "f"));
168
+ const dbPromise = __classPrivateFieldGet(this, _BrowserOAuthDatabase_dbPromise, "f");
169
+ __classPrivateFieldSet(this, _BrowserOAuthDatabase_dbPromise, Promise.reject(new Error('Database has been disposed')), "f");
170
+ const db = await dbPromise;
171
+ await (db[Symbol.asyncDispose] || db[Symbol.dispose]).call(db);
172
+ }
173
+ }
174
+ exports.BrowserOAuthDatabase = BrowserOAuthDatabase;
175
+ //# sourceMappingURL=browser-oauth-database.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-oauth-database.js","sourceRoot":"","sources":["../src/browser-oauth-database.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAIA,0DAAqD;AAOrD,oDAAyD;AAazD,SAAS,SAAS,CAAC,GAAQ;IACzB,IAAI,CAAC,CAAC,GAAG,YAAY,4BAAY,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;QAC/C,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAA;IACvC,CAAC;IACD,OAAO;QACL,KAAK,EAAE,GAAG,CAAC,GAAG;QACd,OAAO,EAAE,GAAG,CAAC,aAAa;KAC3B,CAAA;AACH,CAAC;AAED,KAAK,UAAU,SAAS,CAAC,OAAmB;IAC1C,OAAO,4BAAY,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;AACjE,CAAC;AA4BD,MAAM,MAAM,GAA6B;IACvC,OAAO;IACP,SAAS;IAET,UAAU;IACV,gBAAgB;IAChB,aAAa;IACb,kCAAkC;IAClC,gCAAgC;CACjC,CAAA;AAQD,MAAa,oBAAoB;IAI/B,YAAY,OAAqC;QAHjD,kDAA+B;QAC/B,wDAAiD;QAG/C,uBAAA,IAAI,mCAAc,aAAE,CAAC,IAAI,CACvB,OAAO,EAAE,IAAI,IAAI,uBAAuB,EACxC;YACE,CAAC,EAAE,EAAE,EAAE;gBACL,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;oBAC1B,MAAM,KAAK,GAAG,EAAE,CAAC,iBAAiB,CAAC,IAAI,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAA;oBACjE,KAAK,CAAC,WAAW,CAAC,WAAW,EAAE,WAAW,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAA;gBAChE,CAA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OAAO,EAAE,EAAE,CAAC,OAAO;SAC7B,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,EAAE,GAAG,MAAM,uBAAA,IAAI,uCAAW,CAAA;QAEhC,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;YAC1B,MAAM,EAAE,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,EAAE,EAAE,CAC/C,EAAE;iBACC,WAAW,CAAC,IAAI,CAAC;iBACjB,KAAK,CAAC,WAAW,CAAC;iBAClB,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CACjD,CAAA;QACH,CAAC;IACH,CAAC;IAED,KAAK,CAAC,0GAAC,MAAM,CAAC,YAAY,EAAC;QACzB,aAAa,CAAC,uBAAA,IAAI,6CAAiB,CAAC,CAAA;QACpC,MAAM,SAAS,GAAG,uBAAA,IAAI,uCAAW,CAAA;QACjC,uBAAA,IAAI,mCAAc,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC,MAAA,CAAA;QAEzE,MAAM,EAAE,GAAG,MAAM,SAAS,CAAA;QAC1B,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAChE,CAAC;CACF;AAzLD,oDAyLC"}
@@ -0,0 +1,10 @@
1
+ import { DigestAlgorithm, Key, RuntimeImplementation } from '@atproto/oauth-client';
2
+ export declare class BrowserRuntimeImplementation implements RuntimeImplementation {
3
+ private crypto;
4
+ requestLock: (<T>(name: string, fn: () => T | PromiseLike<T>) => Promise<T>) | undefined;
5
+ constructor(crypto?: Crypto);
6
+ createKey(algs: string[]): Promise<Key>;
7
+ getRandomValues(byteLength: number): Uint8Array;
8
+ digest(bytes: Uint8Array, algorithm: DigestAlgorithm): Promise<Uint8Array>;
9
+ }
10
+ //# sourceMappingURL=browser-runtime-implementation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-runtime-implementation.d.ts","sourceRoot":"","sources":["../src/browser-runtime-implementation.ts"],"names":[],"mappings":"AACA,OAAO,EACL,eAAe,EACf,GAAG,EACH,qBAAqB,EACtB,MAAM,uBAAuB,CAAA;AAE9B,qBAAa,4BAA6B,YAAW,qBAAqB;IAO5D,OAAO,CAAC,MAAM;IAL1B,WAAW,aACG,MAAM,MAAM,MAAM,CAAC,GAAG,YAAY,CAAC,CAAC,KAAG,QAAQ,CAAC,CAAC,cAElD;gBAEO,MAAM,SAAoB;IAiBxC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;IAI7C,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU;IAMzC,MAAM,CACV,KAAK,EAAE,UAAU,EACjB,SAAS,EAAE,eAAe,GACzB,OAAO,CAAC,UAAU,CAAC;CAOvB"}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BrowserRuntimeImplementation = void 0;
4
+ const jwk_webcrypto_1 = require("@atproto/jwk-webcrypto");
5
+ class BrowserRuntimeImplementation {
6
+ constructor(crypto = globalThis.crypto) {
7
+ Object.defineProperty(this, "crypto", {
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true,
11
+ value: crypto
12
+ });
13
+ // https://developer.mozilla.org/en-US/docs/Web/API/LockManager/request
14
+ Object.defineProperty(this, "requestLock", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: navigator.locks?.request
19
+ ? (name, fn) => navigator.locks.request(name, { mode: 'exclusive' }, async () => fn())
20
+ : undefined
21
+ });
22
+ if (!crypto?.subtle) {
23
+ throw new Error('Crypto with CryptoSubtle is required. If running in a browser, make sure the current page is loaded over HTTPS.');
24
+ }
25
+ if (!this.requestLock) {
26
+ // There is no real need to polyfill this on older browsers. The
27
+ // oauth-client library will try and recover from concurrency issues when
28
+ // refreshing tokens.
29
+ console.warn('Locks API not available. You should consider using a more recent browser.');
30
+ }
31
+ }
32
+ async createKey(algs) {
33
+ return jwk_webcrypto_1.WebcryptoKey.generate(algs);
34
+ }
35
+ getRandomValues(byteLength) {
36
+ const bytes = new Uint8Array(byteLength);
37
+ this.crypto.getRandomValues(bytes);
38
+ return bytes;
39
+ }
40
+ async digest(bytes, algorithm) {
41
+ const buffer = await this.crypto.subtle.digest(digestAlgorithmToSubtle(algorithm), bytes);
42
+ return new Uint8Array(buffer);
43
+ }
44
+ }
45
+ exports.BrowserRuntimeImplementation = BrowserRuntimeImplementation;
46
+ function digestAlgorithmToSubtle({ name, }) {
47
+ switch (name) {
48
+ case 'sha256':
49
+ case 'sha384':
50
+ case 'sha512':
51
+ return `SHA-${name.slice(-3)}`;
52
+ default:
53
+ throw new TypeError(`Unknown hash algorithm ${name}`);
54
+ }
55
+ }
56
+ //# sourceMappingURL=browser-runtime-implementation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-runtime-implementation.js","sourceRoot":"","sources":["../src/browser-runtime-implementation.ts"],"names":[],"mappings":";;;AAAA,0DAAqD;AAOrD,MAAa,4BAA4B;IAOvC,YAAoB,SAAS,UAAU,CAAC,MAAM;QAAlC;;;;mBAAQ,MAAM;WAAoB;QAN9C,uEAAuE;QACvE;;;;mBAAc,SAAS,CAAC,KAAK,EAAE,OAAO;gBACpC,CAAC,CAAC,CAAI,IAAY,EAAE,EAA4B,EAAc,EAAE,CAC5D,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,KAAK,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC1E,CAAC,CAAC,SAAS;WAAA;QAGX,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CACb,iHAAiH,CAClH,CAAA;QACH,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,gEAAgE;YAChE,yEAAyE;YACzE,qBAAqB;YACrB,OAAO,CAAC,IAAI,CACV,2EAA2E,CAC5E,CAAA;QACH,CAAC;IACH,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,IAAc;QAC5B,OAAO,4BAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IACpC,CAAC;IAED,eAAe,CAAC,UAAkB;QAChC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,UAAU,CAAC,CAAA;QACxC,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAA;QAClC,OAAO,KAAK,CAAA;IACd,CAAC;IAED,KAAK,CAAC,MAAM,CACV,KAAiB,EACjB,SAA0B;QAE1B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAC5C,uBAAuB,CAAC,SAAS,CAAC,EAClC,KAAK,CACN,CAAA;QACD,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAA;IAC/B,CAAC;CACF;AA5CD,oEA4CC;AAED,SAAS,uBAAuB,CAAC,EAC/B,IAAI,GACY;IAChB,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,QAAQ,CAAC;QACd,KAAK,QAAQ,CAAC;QACd,KAAK,QAAQ;YACX,OAAO,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;QAChC;YACE,MAAM,IAAI,SAAS,CAAC,0BAA0B,IAAI,EAAE,CAAC,CAAA;IACzD,CAAC;AACH,CAAC"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/disposable-polyfill/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ // Code compiled with tsc supports "using" and "await using" syntax. This
3
+ // features is supported by downleveling the code to ES2017. The downleveling
4
+ // relies on `Symbol.dispose` and `Symbol.asyncDispose` symbols. These symbols
5
+ // might not be available in all environments. This package provides a polyfill
6
+ // for these symbols.
7
+ // @ts-expect-error
8
+ Symbol.dispose ?? (Symbol.dispose = Symbol('@@dispose'));
9
+ // @ts-expect-error
10
+ Symbol.asyncDispose ?? (Symbol.asyncDispose = Symbol('@@asyncDispose'));
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/disposable-polyfill/index.ts"],"names":[],"mappings":";AAAA,yEAAyE;AACzE,6EAA6E;AAC7E,8EAA8E;AAC9E,+EAA+E;AAC/E,qBAAqB;AAErB,mBAAmB;AACnB,MAAM,CAAC,OAAO,KAAd,MAAM,CAAC,OAAO,GAAK,MAAM,CAAC,WAAW,CAAC,EAAA;AACtC,mBAAmB;AACnB,MAAM,CAAC,YAAY,KAAnB,MAAM,CAAC,YAAY,GAAK,MAAM,CAAC,gBAAgB,CAAC,EAAA"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Special error class destined to be thrown when the login process was
3
+ * performed in a popup and should be continued in the parent/initiating window.
4
+ */
5
+ export declare class LoginContinuedInParentWindowError extends Error {
6
+ code: string;
7
+ constructor();
8
+ }
9
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,iCAAkC,SAAQ,KAAK;IAC1D,IAAI,SAAqC;;CAI1C"}
package/dist/errors.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LoginContinuedInParentWindowError = void 0;
4
+ /**
5
+ * Special error class destined to be thrown when the login process was
6
+ * performed in a popup and should be continued in the parent/initiating window.
7
+ */
8
+ class LoginContinuedInParentWindowError extends Error {
9
+ constructor() {
10
+ 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
+ });
17
+ }
18
+ }
19
+ exports.LoginContinuedInParentWindowError = LoginContinuedInParentWindowError;
20
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +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"}
@@ -0,0 +1,11 @@
1
+ import './disposable-polyfill/index.js';
2
+ export * from '@atproto-labs/did-resolver';
3
+ export { AppViewHandleResolver, AtprotoHandleResolver, } from '@atproto-labs/handle-resolver';
4
+ export * from '@atproto/did';
5
+ export * from '@atproto/jwk-webcrypto';
6
+ export * from '@atproto/oauth-client';
7
+ export * from '@atproto/oauth-types';
8
+ export * from './browser-oauth-client.js';
9
+ export * from './errors.js';
10
+ export { buildLoopbackClientId } from './util.js';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAA;AAEvC,cAAc,4BAA4B,CAAA;AAC1C,OAAO,EACL,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,+BAA+B,CAAA;AAEtC,cAAc,cAAc,CAAA;AAC5B,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,sBAAsB,CAAA;AAEpC,cAAc,2BAA2B,CAAA;AACzC,cAAc,aAAa,CAAA;AAC3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,31 @@
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 = exports.AtprotoHandleResolver = exports.AppViewHandleResolver = void 0;
18
+ require("./disposable-polyfill/index.js");
19
+ __exportStar(require("@atproto-labs/did-resolver"), exports);
20
+ var handle_resolver_1 = require("@atproto-labs/handle-resolver");
21
+ Object.defineProperty(exports, "AppViewHandleResolver", { enumerable: true, get: function () { return handle_resolver_1.AppViewHandleResolver; } });
22
+ Object.defineProperty(exports, "AtprotoHandleResolver", { enumerable: true, get: function () { return handle_resolver_1.AtprotoHandleResolver; } });
23
+ __exportStar(require("@atproto/did"), exports);
24
+ __exportStar(require("@atproto/jwk-webcrypto"), exports);
25
+ __exportStar(require("@atproto/oauth-client"), exports);
26
+ __exportStar(require("@atproto/oauth-types"), exports);
27
+ __exportStar(require("./browser-oauth-client.js"), exports);
28
+ __exportStar(require("./errors.js"), exports);
29
+ var util_js_1 = require("./util.js");
30
+ Object.defineProperty(exports, "buildLoopbackClientId", { enumerable: true, get: function () { return util_js_1.buildLoopbackClientId; } });
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,0CAAuC;AAEvC,6DAA0C;AAC1C,iEAGsC;AAFpC,wHAAA,qBAAqB,OAAA;AACrB,wHAAA,qBAAqB,OAAA;AAGvB,+CAA4B;AAC5B,yDAAsC;AACtC,wDAAqC;AACrC,uDAAoC;AAEpC,4DAAyC;AACzC,8CAA2B;AAC3B,qCAAiD;AAAxC,gHAAA,qBAAqB,OAAA"}
@@ -0,0 +1,12 @@
1
+ import { ObjectStoreSchema } from './schema.js';
2
+ export declare class DBIndex<Schema extends ObjectStoreSchema> {
3
+ private idbIndex;
4
+ constructor(idbIndex: IDBIndex);
5
+ count(query?: IDBValidKey | IDBKeyRange): Promise<number>;
6
+ get(query: IDBValidKey | IDBKeyRange): Promise<Schema>;
7
+ getKey(query: IDBValidKey | IDBKeyRange): Promise<IDBValidKey | undefined>;
8
+ getAll(query?: IDBValidKey | IDBKeyRange | null, count?: number): Promise<Schema[]>;
9
+ getAllKeys(query?: IDBValidKey | IDBKeyRange | null, count?: number): Promise<IDBValidKey[]>;
10
+ deleteAll(query?: IDBValidKey | IDBKeyRange | null): Promise<void>;
11
+ }
12
+ //# sourceMappingURL=db-index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db-index.d.ts","sourceRoot":"","sources":["../../src/indexed-db/db-index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAG/C,qBAAa,OAAO,CAAC,MAAM,SAAS,iBAAiB;IACvC,OAAO,CAAC,QAAQ;gBAAR,QAAQ,EAAE,QAAQ;IAEtC,KAAK,CAAC,KAAK,CAAC,EAAE,WAAW,GAAG,WAAW;IAIvC,GAAG,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW;IAIpC,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW;IAIvC,MAAM,CAAC,KAAK,CAAC,EAAE,WAAW,GAAG,WAAW,GAAG,IAAI,EAAE,KAAK,CAAC,EAAE,MAAM;IAI/D,UAAU,CAAC,KAAK,CAAC,EAAE,WAAW,GAAG,WAAW,GAAG,IAAI,EAAE,KAAK,CAAC,EAAE,MAAM;IAInE,SAAS,CAAC,KAAK,CAAC,EAAE,WAAW,GAAG,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;CAiBnE"}
@@ -0,0 +1,49 @@
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 {
6
+ constructor(idbIndex) {
7
+ Object.defineProperty(this, "idbIndex", {
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true,
11
+ value: idbIndex
12
+ });
13
+ }
14
+ count(query) {
15
+ return (0, util_js_1.promisify)(this.idbIndex.count(query));
16
+ }
17
+ get(query) {
18
+ return (0, util_js_1.promisify)(this.idbIndex.get(query));
19
+ }
20
+ getKey(query) {
21
+ return (0, util_js_1.promisify)(this.idbIndex.getKey(query));
22
+ }
23
+ getAll(query, count) {
24
+ return (0, util_js_1.promisify)(this.idbIndex.getAll(query, count));
25
+ }
26
+ getAllKeys(query, count) {
27
+ return (0, util_js_1.promisify)(this.idbIndex.getAllKeys(query, count));
28
+ }
29
+ deleteAll(query) {
30
+ return new Promise((resolve, reject) => {
31
+ const result = this.idbIndex.openCursor(query);
32
+ result.onsuccess = function (event) {
33
+ const cursor = event.target.result;
34
+ if (cursor) {
35
+ cursor.delete();
36
+ cursor.continue();
37
+ }
38
+ else {
39
+ resolve();
40
+ }
41
+ };
42
+ result.onerror = function (event) {
43
+ reject(event.target?.error || new Error('Unexpected error'));
44
+ };
45
+ });
46
+ }
47
+ }
48
+ exports.DBIndex = DBIndex;
49
+ //# sourceMappingURL=db-index.js.map
@@ -0,0 +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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O,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"}
@@ -0,0 +1,17 @@
1
+ import { DBIndex } from './db-index.js';
2
+ import { ObjectStoreSchema } from './schema.js';
3
+ export declare class DBObjectStore<Schema extends ObjectStoreSchema> {
4
+ private idbObjStore;
5
+ constructor(idbObjStore: IDBObjectStore);
6
+ get name(): string;
7
+ index(name: string): DBIndex<Schema>;
8
+ get(key: IDBValidKey | IDBKeyRange): Promise<Schema>;
9
+ getKey(query: IDBValidKey | IDBKeyRange): Promise<IDBValidKey | undefined>;
10
+ getAll(query?: IDBValidKey | IDBKeyRange | null, count?: number): Promise<Schema[]>;
11
+ getAllKeys(query?: IDBValidKey | IDBKeyRange | null, count?: number): Promise<IDBValidKey[]>;
12
+ add(value: Schema, key?: IDBValidKey): Promise<IDBValidKey>;
13
+ put(value: Schema, key?: IDBValidKey): Promise<IDBValidKey>;
14
+ delete(key: IDBValidKey | IDBKeyRange): Promise<undefined>;
15
+ clear(): Promise<undefined>;
16
+ }
17
+ //# sourceMappingURL=db-object-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db-object-store.d.ts","sourceRoot":"","sources":["../../src/indexed-db/db-object-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAG/C,qBAAa,aAAa,CAAC,MAAM,SAAS,iBAAiB;IAC7C,OAAO,CAAC,WAAW;gBAAX,WAAW,EAAE,cAAc;IAE/C,IAAI,IAAI,WAEP;IAED,KAAK,CAAC,IAAI,EAAE,MAAM;IAIlB,GAAG,CAAC,GAAG,EAAE,WAAW,GAAG,WAAW;IAIlC,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW;IAIvC,MAAM,CAAC,KAAK,CAAC,EAAE,WAAW,GAAG,WAAW,GAAG,IAAI,EAAE,KAAK,CAAC,EAAE,MAAM;IAI/D,UAAU,CAAC,KAAK,CAAC,EAAE,WAAW,GAAG,WAAW,GAAG,IAAI,EAAE,KAAK,CAAC,EAAE,MAAM;IAInE,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,WAAW;IAIpC,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,WAAW;IAIpC,MAAM,CAAC,GAAG,EAAE,WAAW,GAAG,WAAW;IAIrC,KAAK;CAGN"}
@@ -0,0 +1,47 @@
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 {
7
+ constructor(idbObjStore) {
8
+ Object.defineProperty(this, "idbObjStore", {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value: idbObjStore
13
+ });
14
+ }
15
+ get name() {
16
+ return this.idbObjStore.name;
17
+ }
18
+ index(name) {
19
+ return new db_index_js_1.DBIndex(this.idbObjStore.index(name));
20
+ }
21
+ get(key) {
22
+ return (0, util_js_1.promisify)(this.idbObjStore.get(key));
23
+ }
24
+ getKey(query) {
25
+ return (0, util_js_1.promisify)(this.idbObjStore.getKey(query));
26
+ }
27
+ getAll(query, count) {
28
+ return (0, util_js_1.promisify)(this.idbObjStore.getAll(query, count));
29
+ }
30
+ getAllKeys(query, count) {
31
+ return (0, util_js_1.promisify)(this.idbObjStore.getAllKeys(query, count));
32
+ }
33
+ add(value, key) {
34
+ return (0, util_js_1.promisify)(this.idbObjStore.add(value, key));
35
+ }
36
+ put(value, key) {
37
+ return (0, util_js_1.promisify)(this.idbObjStore.put(value, key));
38
+ }
39
+ delete(key) {
40
+ return (0, util_js_1.promisify)(this.idbObjStore.delete(key));
41
+ }
42
+ clear() {
43
+ return (0, util_js_1.promisify)(this.idbObjStore.clear());
44
+ }
45
+ }
46
+ exports.DBObjectStore = DBObjectStore;
47
+ //# sourceMappingURL=db-object-store.js.map
@@ -0,0 +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,WAA2B;QAAnC;;;;mBAAQ,WAAW;WAAgB;IAAG,CAAC;IAEnD,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;IAC9B,CAAC;IAED,KAAK,CAAC,IAAY;QAChB,OAAO,IAAI,qBAAO,CAAS,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;IAC1D,CAAC;IAED,GAAG,CAAC,GAA8B;QAChC,OAAO,IAAA,mBAAS,EAAS,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;IACrD,CAAC;IAED,MAAM,CAAC,KAAgC;QACrC,OAAO,IAAA,mBAAS,EAA0B,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;IAC3E,CAAC;IAED,MAAM,CAAC,KAAwC,EAAE,KAAc;QAC7D,OAAO,IAAA,mBAAS,EAAW,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAA;IACnE,CAAC;IAED,UAAU,CAAC,KAAwC,EAAE,KAAc;QACjE,OAAO,IAAA,mBAAS,EAAgB,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAA;IAC5E,CAAC;IAED,GAAG,CAAC,KAAa,EAAE,GAAiB;QAClC,OAAO,IAAA,mBAAS,EAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAA;IACpD,CAAC;IAED,GAAG,CAAC,KAAa,EAAE,GAAiB;QAClC,OAAO,IAAA,mBAAS,EAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAA;IACpD,CAAC;IAED,MAAM,CAAC,GAA8B;QACnC,OAAO,IAAA,mBAAS,EAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;IAChD,CAAC;IAED,KAAK;QACH,OAAO,IAAA,mBAAS,EAAC,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC,CAAA;IAC5C,CAAC;CACF;AA1CD,sCA0CC"}
@@ -0,0 +1,13 @@
1
+ /// <reference types="node" />
2
+ import { DBObjectStore } from './db-object-store.js';
3
+ import { DatabaseSchema } from './schema.js';
4
+ export declare class DBTransaction<Schema extends DatabaseSchema> implements Disposable {
5
+ #private;
6
+ constructor(tx: IDBTransaction);
7
+ protected get tx(): IDBTransaction;
8
+ abort(): Promise<void>;
9
+ commit(): Promise<void>;
10
+ objectStore<T extends keyof Schema & string>(name: T): DBObjectStore<Schema[T]>;
11
+ [Symbol.dispose](): void;
12
+ }
13
+ //# sourceMappingURL=db-transaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db-transaction.d.ts","sourceRoot":"","sources":["../../src/indexed-db/db-transaction.ts"],"names":[],"mappings":";AAAA,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"}
@@ -0,0 +1,60 @@
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
+ const db_object_store_js_1 = require("./db-object-store.js");
17
+ class DBTransaction {
18
+ constructor(tx) {
19
+ _DBTransaction_tx.set(this, void 0);
20
+ __classPrivateFieldSet(this, _DBTransaction_tx, tx, "f");
21
+ const onAbort = () => {
22
+ cleanup();
23
+ };
24
+ const onComplete = () => {
25
+ cleanup();
26
+ };
27
+ const cleanup = () => {
28
+ __classPrivateFieldSet(this, _DBTransaction_tx, null, "f");
29
+ tx.removeEventListener('abort', onAbort);
30
+ tx.removeEventListener('complete', onComplete);
31
+ };
32
+ tx.addEventListener('abort', onAbort);
33
+ tx.addEventListener('complete', onComplete);
34
+ }
35
+ get tx() {
36
+ if (!__classPrivateFieldGet(this, _DBTransaction_tx, "f"))
37
+ throw new Error('Transaction already ended');
38
+ return __classPrivateFieldGet(this, _DBTransaction_tx, "f");
39
+ }
40
+ async abort() {
41
+ const { tx } = this;
42
+ __classPrivateFieldSet(this, _DBTransaction_tx, null, "f");
43
+ tx.abort();
44
+ }
45
+ async commit() {
46
+ const { tx } = this;
47
+ __classPrivateFieldSet(this, _DBTransaction_tx, null, "f");
48
+ tx.commit?.();
49
+ }
50
+ objectStore(name) {
51
+ const store = this.tx.objectStore(name);
52
+ return new db_object_store_js_1.DBObjectStore(store);
53
+ }
54
+ [(_DBTransaction_tx = new WeakMap(), Symbol.dispose)]() {
55
+ if (__classPrivateFieldGet(this, _DBTransaction_tx, "f"))
56
+ this.commit();
57
+ }
58
+ }
59
+ exports.DBTransaction = DBTransaction;
60
+ //# sourceMappingURL=db-transaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db-transaction.js","sourceRoot":"","sources":["../../src/indexed-db/db-transaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,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"}
@@ -0,0 +1,17 @@
1
+ /// <reference types="node" />
2
+ import { DatabaseSchema } from './schema.js';
3
+ import { DBTransaction } from './db-transaction.js';
4
+ export declare class DB<Schema extends DatabaseSchema> implements Disposable {
5
+ #private;
6
+ protected readonly txOptions?: IDBTransactionOptions | undefined;
7
+ static open<Schema extends DatabaseSchema = DatabaseSchema>(dbName: string, migrations: ReadonlyArray<(db: IDBDatabase) => void>, txOptions?: IDBTransactionOptions): Promise<DB<Schema>>;
8
+ constructor(db: IDBDatabase, txOptions?: IDBTransactionOptions | undefined);
9
+ protected get db(): IDBDatabase;
10
+ get name(): string;
11
+ get objectStoreNames(): DOMStringList;
12
+ get version(): number;
13
+ transaction<T extends readonly (keyof Schema & string)[], R>(storeNames: T, mode: IDBTransactionMode, run: (tx: DBTransaction<Pick<Schema, T[number]>>) => R | PromiseLike<R>): Promise<R>;
14
+ close(): void;
15
+ [Symbol.dispose](): void;
16
+ }
17
+ //# sourceMappingURL=db.d.ts.map