@enbox/browser 0.3.70 → 0.3.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -7
- package/dist/browser.mjs +14 -14
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/blob-url-pool.js +36 -0
- package/dist/esm/blob-url-pool.js.map +1 -0
- package/dist/esm/file-envelope-url-store.js +203 -0
- package/dist/esm/file-envelope-url-store.js.map +1 -0
- package/dist/esm/index.js +12 -12
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/object-url-reference.js +68 -0
- package/dist/esm/object-url-reference.js.map +1 -0
- package/dist/types/blob-url-pool.d.ts +16 -0
- package/dist/types/blob-url-pool.d.ts.map +1 -0
- package/dist/types/file-envelope-url-store.d.ts +30 -0
- package/dist/types/file-envelope-url-store.d.ts.map +1 -0
- package/dist/types/index.d.ts +16 -14
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/object-url-reference.d.ts +20 -0
- package/dist/types/object-url-reference.d.ts.map +1 -0
- package/package.json +7 -7
- package/src/blob-url-pool.ts +55 -0
- package/src/file-envelope-url-store.ts +260 -0
- package/src/index.ts +23 -159
- package/src/object-url-reference.ts +82 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ObjectUrlReference } from './object-url-reference.js';
|
|
2
|
+
class DefaultBlobUrlPool {
|
|
3
|
+
constructor() {
|
|
4
|
+
this._references = new Map();
|
|
5
|
+
this._isDisposed = false;
|
|
6
|
+
}
|
|
7
|
+
acquire(blob) {
|
|
8
|
+
if (this._isDisposed) {
|
|
9
|
+
throw new Error('BlobUrlPool is disposed.');
|
|
10
|
+
}
|
|
11
|
+
let reference = this._references.get(blob);
|
|
12
|
+
if (reference === undefined) {
|
|
13
|
+
reference = new ObjectUrlReference(blob, (released) => {
|
|
14
|
+
this._references.delete(blob);
|
|
15
|
+
released.revoke();
|
|
16
|
+
});
|
|
17
|
+
this._references.set(blob, reference);
|
|
18
|
+
}
|
|
19
|
+
return reference.acquire();
|
|
20
|
+
}
|
|
21
|
+
dispose() {
|
|
22
|
+
if (this._isDisposed) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
this._isDisposed = true;
|
|
26
|
+
for (const reference of this._references.values()) {
|
|
27
|
+
reference.revoke();
|
|
28
|
+
}
|
|
29
|
+
this._references.clear();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** Create a terminally disposable, reference-counted object URL pool. */
|
|
33
|
+
export function createBlobUrlPool() {
|
|
34
|
+
return new DefaultBlobUrlPool();
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=blob-url-pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blob-url-pool.js","sourceRoot":"","sources":["../../src/blob-url-pool.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAgB/D,MAAM,kBAAkB;IAAxB;QACmB,gBAAW,GAAG,IAAI,GAAG,EAA4B,CAAC;QAC3D,gBAAW,GAAG,KAAK,CAAC;IA6B9B,CAAC;IA3BQ,OAAO,CAAC,IAAU;QACvB,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC9C,CAAC;QAED,IAAI,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC3C,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,SAAS,GAAG,IAAI,kBAAkB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAQ,EAAE;gBAC1D,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBAC9B,QAAQ,CAAC,MAAM,EAAE,CAAC;YACpB,CAAC,CAAC,CAAC;YACH,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QACxC,CAAC;QACD,OAAO,SAAS,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;IAEM,OAAO;QACZ,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,OAAO;QACT,CAAC;QAED,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,CAAC;YAClD,SAAS,CAAC,MAAM,EAAE,CAAC;QACrB,CAAC;QACD,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;CACF;AAED,yEAAyE;AACzE,MAAM,UAAU,iBAAiB;IAC/B,OAAO,IAAI,kBAAkB,EAAE,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { ObjectUrlReference } from './object-url-reference.js';
|
|
11
|
+
const DEFAULT_MAX_BYTES = 128 * 1024 * 1024;
|
|
12
|
+
const DEFAULT_MAX_ENTRIES = 50;
|
|
13
|
+
function assertLimit(value, name) {
|
|
14
|
+
if (value !== Infinity && (!Number.isSafeInteger(value) || value < 0)) {
|
|
15
|
+
throw new TypeError(`${name} must be a non-negative safe integer or Infinity.`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function throwAborted(controller) {
|
|
19
|
+
controller.abort();
|
|
20
|
+
throw controller.signal.reason;
|
|
21
|
+
}
|
|
22
|
+
class DefaultFileEnvelopeUrlStore {
|
|
23
|
+
constructor(_options) {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
this._options = _options;
|
|
26
|
+
this._cache = new Map();
|
|
27
|
+
this._entries = new Set();
|
|
28
|
+
this._pending = new Map();
|
|
29
|
+
this._bytes = 0;
|
|
30
|
+
this._generation = 0;
|
|
31
|
+
this._isDisposed = false;
|
|
32
|
+
this._maxBytes = (_a = _options.maxBytes) !== null && _a !== void 0 ? _a : DEFAULT_MAX_BYTES;
|
|
33
|
+
this._maxEntries = (_b = _options.maxEntries) !== null && _b !== void 0 ? _b : DEFAULT_MAX_ENTRIES;
|
|
34
|
+
assertLimit(this._maxBytes, 'maxBytes');
|
|
35
|
+
assertLimit(this._maxEntries, 'maxEntries');
|
|
36
|
+
}
|
|
37
|
+
acquire(request) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
var _a;
|
|
40
|
+
this._assertActive();
|
|
41
|
+
const key = this._options.key(request);
|
|
42
|
+
const cached = this._cache.get(key);
|
|
43
|
+
if (cached !== undefined) {
|
|
44
|
+
return this._acquire(cached);
|
|
45
|
+
}
|
|
46
|
+
const pending = (_a = this._pending.get(key)) !== null && _a !== void 0 ? _a : this._startRead(request, key);
|
|
47
|
+
const entry = yield pending.promise;
|
|
48
|
+
if (this._isDisposed || pending.generation !== this._generation) {
|
|
49
|
+
return throwAborted(pending.controller);
|
|
50
|
+
}
|
|
51
|
+
if (entry === undefined) {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
if (this._cache.get(key) !== entry) {
|
|
55
|
+
return throwAborted(pending.controller);
|
|
56
|
+
}
|
|
57
|
+
return this._acquire(entry);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
acquireCached(request) {
|
|
61
|
+
this._assertActive();
|
|
62
|
+
const entry = this._cache.get(this._options.key(request));
|
|
63
|
+
return entry === undefined ? undefined : this._acquire(entry);
|
|
64
|
+
}
|
|
65
|
+
invalidate(request) {
|
|
66
|
+
this._assertActive();
|
|
67
|
+
const key = this._options.key(request);
|
|
68
|
+
const pending = this._pending.get(key);
|
|
69
|
+
pending === null || pending === void 0 ? void 0 : pending.controller.abort();
|
|
70
|
+
this._pending.delete(key);
|
|
71
|
+
const entry = this._cache.get(key);
|
|
72
|
+
if (entry !== undefined) {
|
|
73
|
+
this._remove(entry);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
clear() {
|
|
77
|
+
this._assertActive();
|
|
78
|
+
this._reset(false);
|
|
79
|
+
}
|
|
80
|
+
dispose() {
|
|
81
|
+
if (this._isDisposed) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
this._isDisposed = true;
|
|
85
|
+
this._reset(true);
|
|
86
|
+
}
|
|
87
|
+
_abortReads() {
|
|
88
|
+
for (const pending of this._pending.values()) {
|
|
89
|
+
pending.controller.abort();
|
|
90
|
+
}
|
|
91
|
+
this._pending.clear();
|
|
92
|
+
}
|
|
93
|
+
_acquire(entry) {
|
|
94
|
+
this._cache.delete(entry.key);
|
|
95
|
+
this._cache.set(entry.key, entry);
|
|
96
|
+
const lease = entry.url.acquire();
|
|
97
|
+
this._evict();
|
|
98
|
+
return Object.freeze({
|
|
99
|
+
filename: entry.filename,
|
|
100
|
+
mimeType: entry.mimeType,
|
|
101
|
+
release: lease.release,
|
|
102
|
+
releaseAfter: lease.releaseAfter,
|
|
103
|
+
url: lease.url,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
_assertActive() {
|
|
107
|
+
if (this._isDisposed) {
|
|
108
|
+
throw new Error('FileEnvelopeUrlStore is disposed.');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
_assertCurrent(key, controller, generation) {
|
|
112
|
+
var _a;
|
|
113
|
+
if (this._isDisposed
|
|
114
|
+
|| controller.signal.aborted
|
|
115
|
+
|| this._generation !== generation
|
|
116
|
+
|| ((_a = this._pending.get(key)) === null || _a === void 0 ? void 0 : _a.controller) !== controller) {
|
|
117
|
+
throwAborted(controller);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
_evict() {
|
|
121
|
+
while (this._cache.size > this._maxEntries || this._bytes > this._maxBytes) {
|
|
122
|
+
const entry = [...this._cache.values()].find((candidate) => candidate.url.references === 0);
|
|
123
|
+
if (entry === undefined) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
this._remove(entry);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
_load(request, key, controller, generation) {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
+
const value = yield this._options.read(request, controller.signal);
|
|
132
|
+
this._assertCurrent(key, controller, generation);
|
|
133
|
+
if (value === undefined) {
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
const blob = this._options.blobForUrl(value);
|
|
137
|
+
this._assertCurrent(key, controller, generation);
|
|
138
|
+
const url = new ObjectUrlReference(blob, () => this._released(entry));
|
|
139
|
+
const entry = {
|
|
140
|
+
bytes: blob.size,
|
|
141
|
+
filename: value.filename,
|
|
142
|
+
key,
|
|
143
|
+
mimeType: value.mimeType,
|
|
144
|
+
url,
|
|
145
|
+
};
|
|
146
|
+
this._cache.set(key, entry);
|
|
147
|
+
this._bytes += entry.bytes;
|
|
148
|
+
this._entries.add(entry);
|
|
149
|
+
return entry;
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
_released(entry) {
|
|
153
|
+
if (this._cache.get(entry.key) !== entry) {
|
|
154
|
+
this._revoke(entry);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
this._evict();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
_remove(entry) {
|
|
161
|
+
if (this._cache.get(entry.key) !== entry) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
this._cache.delete(entry.key);
|
|
165
|
+
this._bytes -= entry.bytes;
|
|
166
|
+
if (entry.url.references === 0) {
|
|
167
|
+
this._revoke(entry);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
_reset(revokeActive) {
|
|
171
|
+
this._generation += 1;
|
|
172
|
+
this._abortReads();
|
|
173
|
+
this._cache.clear();
|
|
174
|
+
this._bytes = 0;
|
|
175
|
+
for (const entry of this._entries) {
|
|
176
|
+
if (revokeActive || entry.url.references === 0) {
|
|
177
|
+
this._revoke(entry);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
_revoke(entry) {
|
|
182
|
+
entry.url.revoke();
|
|
183
|
+
this._entries.delete(entry);
|
|
184
|
+
}
|
|
185
|
+
_startRead(request, key) {
|
|
186
|
+
const controller = new AbortController();
|
|
187
|
+
const generation = this._generation;
|
|
188
|
+
const promise = this._load(request, key, controller, generation).finally(() => {
|
|
189
|
+
var _a;
|
|
190
|
+
if (((_a = this._pending.get(key)) === null || _a === void 0 ? void 0 : _a.controller) === controller) {
|
|
191
|
+
this._pending.delete(key);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
const pending = { controller, generation, promise };
|
|
195
|
+
this._pending.set(key, pending);
|
|
196
|
+
return pending;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/** Create a bounded file-envelope URL store with deduplicated reads. */
|
|
200
|
+
export function createFileEnvelopeUrlStore(options) {
|
|
201
|
+
return new DefaultFileEnvelopeUrlStore(options);
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=file-envelope-url-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-envelope-url-store.js","sourceRoot":"","sources":["../../src/file-envelope-url-store.ts"],"names":[],"mappings":";;;;;;;;;AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,MAAM,iBAAiB,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;AAC5C,MAAM,mBAAmB,GAAG,EAAE,CAAC;AA4C/B,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AQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC,CAAC,CAAC;QACH,MAAM,OAAO,GAAG,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;QACpD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAChC,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAED,wEAAwE;AACxE,MAAM,UAAU,0BAA0B,CACxC,OAA6C;IAE7C,OAAO,IAAI,2BAA2B,CAAC,OAAO,CAAC,CAAC;AAClD,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -8,14 +8,17 @@
|
|
|
8
8
|
* @example Single-import dapp setup
|
|
9
9
|
* ```ts
|
|
10
10
|
* import {
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* BrowserConnectHandler, createConnectionStore,
|
|
12
|
+
* defineApplicationManifest,
|
|
13
13
|
* } from '@enbox/browser';
|
|
14
|
+
* import { MyProtocol } from './my-protocol.js';
|
|
14
15
|
*
|
|
15
|
-
* const
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* const store = createConnectionStore({
|
|
17
|
+
* application : defineApplicationManifest({ protocols: [MyProtocol] }),
|
|
18
|
+
* connectHandler : BrowserConnectHandler({ appName: 'My App' }),
|
|
18
19
|
* });
|
|
20
|
+
* const snapshot = await store.connect();
|
|
21
|
+
* if (snapshot.phase !== 'connected') throw snapshot.error ?? new Error('Connection failed.');
|
|
19
22
|
* ```
|
|
20
23
|
*
|
|
21
24
|
* For non-browser environments (Node.js, CLI, desktop), import from
|
|
@@ -26,11 +29,11 @@
|
|
|
26
29
|
// ─── Re-exports from @enbox/api ─────────────────────────────────
|
|
27
30
|
//
|
|
28
31
|
// The high-level Enbox API: DWN records and protocols.
|
|
29
|
-
export
|
|
32
|
+
export * from '@enbox/api';
|
|
30
33
|
// ─── Re-exports from @enbox/auth ────────────────────────────────
|
|
31
34
|
//
|
|
32
35
|
// Authentication lifecycle, session management, connect handlers.
|
|
33
|
-
export
|
|
36
|
+
export * from '@enbox/auth/browser';
|
|
34
37
|
// ─── Re-exports from @enbox/connect ─────────────────────────────
|
|
35
38
|
//
|
|
36
39
|
// The connect kernel pieces wallet apps need alongside the popup
|
|
@@ -48,6 +51,8 @@ export { fetchWalletWellKnown, probeWalletWellKnown, WALLET_WELL_KNOWN_PATH } fr
|
|
|
48
51
|
export { discoverWalletConnectServerUrl, runConnectModal } from './ui/connect-modal.js';
|
|
49
52
|
export { MAX_PIN_ATTEMPTS, RelayConnectCancelledError, runRelayConnect } from './relay-connect-runner.js';
|
|
50
53
|
export { encodeQr, qrToSvg } from './ui/qr.js';
|
|
54
|
+
export { createBlobUrlPool } from './blob-url-pool.js';
|
|
55
|
+
export { createFileEnvelopeUrlStore } from './file-envelope-url-store.js';
|
|
51
56
|
// ─── Convenience re-exports for dapps ───────────────────────────
|
|
52
57
|
//
|
|
53
58
|
// So that most browser dapps only need `@enbox/browser` (plus
|
|
@@ -55,11 +60,6 @@ export { encodeQr, qrToSvg } from './ui/qr.js';
|
|
|
55
60
|
// symbols dapps most commonly reached into sibling packages for; anything
|
|
56
61
|
// more specialized is still available by importing the underlying package
|
|
57
62
|
// directly.
|
|
58
|
-
// Canonical typed record (from @enbox/api).
|
|
59
|
-
export { Record } from '@enbox/api';
|
|
60
|
-
// Custom storage adapter + DWN registration provider-auth callback shapes
|
|
61
|
-
// (from @enbox/auth).
|
|
62
|
-
export { BrowserStorage } from '@enbox/auth/browser';
|
|
63
63
|
// Public-profile read/cache layer (from @enbox/protocols): fetch other
|
|
64
64
|
// users' published profiles (displayName + avatar/hero) from their DWNs
|
|
65
65
|
// with caching, retries, negative caching, and refcounted subscriptions.
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":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uEAAuE;AACvE,wEAAwE;AACxE,yEAAyE;AACzE,uEAAuE;AACvE,OAAO,EAAE,mBAAmB,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AAkBrF,oEAAoE;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAiB5C,4EAA4E;AAC5E,mCAAmC;AACnC,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const MAX_TIMER_DELAY_MS = 2147483647;
|
|
2
|
+
function assertReleaseDelay(delayMs) {
|
|
3
|
+
if (!Number.isSafeInteger(delayMs) || delayMs < 0 || delayMs > MAX_TIMER_DELAY_MS) {
|
|
4
|
+
throw new TypeError(`delayMs must be an integer between 0 and ${MAX_TIMER_DELAY_MS}.`);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
/** Private reference-counted ownership for one object URL. */
|
|
8
|
+
export class ObjectUrlReference {
|
|
9
|
+
constructor(blob, _onEmpty) {
|
|
10
|
+
this._onEmpty = _onEmpty;
|
|
11
|
+
this._isRevoked = false;
|
|
12
|
+
this._references = 0;
|
|
13
|
+
this._releaseTimers = new Set();
|
|
14
|
+
this.url = globalThis.URL.createObjectURL(blob);
|
|
15
|
+
}
|
|
16
|
+
get references() {
|
|
17
|
+
return this._references;
|
|
18
|
+
}
|
|
19
|
+
acquire() {
|
|
20
|
+
if (this._isRevoked) {
|
|
21
|
+
throw new Error('Object URL has been revoked.');
|
|
22
|
+
}
|
|
23
|
+
this._references += 1;
|
|
24
|
+
let released = false;
|
|
25
|
+
let releaseTimer;
|
|
26
|
+
const release = () => {
|
|
27
|
+
if (released) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
released = true;
|
|
31
|
+
if (releaseTimer !== undefined) {
|
|
32
|
+
clearTimeout(releaseTimer);
|
|
33
|
+
this._releaseTimers.delete(releaseTimer);
|
|
34
|
+
}
|
|
35
|
+
if (this._isRevoked) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
this._references -= 1;
|
|
39
|
+
if (this._references === 0) {
|
|
40
|
+
this._onEmpty(this);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
return Object.freeze({
|
|
44
|
+
url: this.url,
|
|
45
|
+
release,
|
|
46
|
+
releaseAfter: (delayMs) => {
|
|
47
|
+
assertReleaseDelay(delayMs);
|
|
48
|
+
if (released || this._isRevoked || releaseTimer !== undefined) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
releaseTimer = setTimeout(release, delayMs);
|
|
52
|
+
this._releaseTimers.add(releaseTimer);
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
revoke() {
|
|
57
|
+
if (!this._isRevoked) {
|
|
58
|
+
this._isRevoked = true;
|
|
59
|
+
for (const timer of this._releaseTimers) {
|
|
60
|
+
clearTimeout(timer);
|
|
61
|
+
}
|
|
62
|
+
this._releaseTimers.clear();
|
|
63
|
+
this._references = 0;
|
|
64
|
+
globalThis.URL.revokeObjectURL(this.url);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=object-url-reference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object-url-reference.js","sourceRoot":"","sources":["../../src/object-url-reference.ts"],"names":[],"mappings":"AAQA,MAAM,kBAAkB,GAAG,UAAa,CAAC;AAEzC,SAAS,kBAAkB,CAAC,OAAe;IACzC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,OAAO,GAAG,CAAC,IAAI,OAAO,GAAG,kBAAkB,EAAE,CAAC;QAClF,MAAM,IAAI,SAAS,CAAC,4CAA4C,kBAAkB,GAAG,CAAC,CAAC;IACzF,CAAC;AACH,CAAC;AAED,8DAA8D;AAC9D,MAAM,OAAO,kBAAkB;IAM7B,YAAmB,IAAU,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AAI,QAAQ,IAAI,IAAI,CAAC,UAAU,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;oBAC9D,OAAO;gBACT,CAAC;gBACD,YAAY,GAAG,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;gBAC5C,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;YACxC,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAEM,MAAM;QACX,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YACvB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;gBACxC,YAAY,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC;YACD,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;YAC5B,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;YACrB,UAAU,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ObjectUrlLease } from './object-url-reference.js';
|
|
2
|
+
/**
|
|
3
|
+
* A reference-counted lease for a browser object URL.
|
|
4
|
+
*
|
|
5
|
+
* When replacing a URL already rendered by the DOM, `releaseAfter()` provides
|
|
6
|
+
* a grace period without passing the lease through the component tree.
|
|
7
|
+
*/
|
|
8
|
+
export type BlobUrlLease = ObjectUrlLease;
|
|
9
|
+
/** Owns object URLs for Blob identities until their last lease is released. */
|
|
10
|
+
export interface BlobUrlPool {
|
|
11
|
+
acquire(blob: Blob): BlobUrlLease;
|
|
12
|
+
dispose(): void;
|
|
13
|
+
}
|
|
14
|
+
/** Create a terminally disposable, reference-counted object URL pool. */
|
|
15
|
+
export declare function createBlobUrlPool(): BlobUrlPool;
|
|
16
|
+
//# sourceMappingURL=blob-url-pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blob-url-pool.d.ts","sourceRoot":"","sources":["../../src/blob-url-pool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAIhE;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,cAAc,CAAC;AAE1C,+EAA+E;AAC/E,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,YAAY,CAAC;IAClC,OAAO,IAAI,IAAI,CAAC;CACjB;AAmCD,yEAAyE;AACzE,wBAAgB,iBAAiB,IAAI,WAAW,CAE/C"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { FileEnvelopeData } from '@enbox/api';
|
|
2
|
+
import type { BlobUrlLease } from './blob-url-pool.js';
|
|
3
|
+
/** A cached file envelope represented by a leased browser object URL. */
|
|
4
|
+
export type FileEnvelopeUrlLease = BlobUrlLease & Readonly<{
|
|
5
|
+
filename: string;
|
|
6
|
+
mimeType: string;
|
|
7
|
+
}>;
|
|
8
|
+
export type FileEnvelopeUrlStoreOptions<Request> = Readonly<{
|
|
9
|
+
/** Select the stable cache key for a read request. */
|
|
10
|
+
key(request: Request): string;
|
|
11
|
+
/** Read and decode the file. The signal aborts invalidated work. */
|
|
12
|
+
read(request: Request, signal: AbortSignal): Promise<FileEnvelopeData | undefined>;
|
|
13
|
+
/** Choose the Blob exposed by the URL, retaining MIME/render policy in the caller. */
|
|
14
|
+
blobForUrl(value: FileEnvelopeData): Blob;
|
|
15
|
+
/** Maximum cached entries (default 50). Soft while every eviction candidate is leased. */
|
|
16
|
+
maxEntries?: number;
|
|
17
|
+
/** Maximum cached Blob bytes (default 128 MiB). Soft while every eviction candidate is leased. */
|
|
18
|
+
maxBytes?: number;
|
|
19
|
+
}>;
|
|
20
|
+
/** A keyed, bounded object URL cache for decoded file envelopes. */
|
|
21
|
+
export interface FileEnvelopeUrlStore<Request> {
|
|
22
|
+
acquire(request: Request): Promise<FileEnvelopeUrlLease | undefined>;
|
|
23
|
+
acquireCached(request: Request): FileEnvelopeUrlLease | undefined;
|
|
24
|
+
clear(): void;
|
|
25
|
+
dispose(): void;
|
|
26
|
+
invalidate(request: Request): void;
|
|
27
|
+
}
|
|
28
|
+
/** Create a bounded file-envelope URL store with deduplicated reads. */
|
|
29
|
+
export declare function createFileEnvelopeUrlStore<Request>(options: FileEnvelopeUrlStoreOptions<Request>): FileEnvelopeUrlStore<Request>;
|
|
30
|
+
//# sourceMappingURL=file-envelope-url-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-envelope-url-store.d.ts","sourceRoot":"","sources":["../../src/file-envelope-url-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAqBvD,yEAAyE;AACzE,MAAM,MAAM,oBAAoB,GAAG,YAAY,GAAG,QAAQ,CAAC;IACzD,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC,CAAC;AAEH,MAAM,MAAM,2BAA2B,CAAC,OAAO,IAAI,QAAQ,CAAC;IAC1D,sDAAsD;IACtD,GAAG,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC;IAC9B,oEAAoE;IACpE,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAAC;IACnF,sFAAsF;IACtF,UAAU,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAC1C,0FAA0F;IAC1F,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kGAAkG;IAClG,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC,CAAC;AAEH,oEAAoE;AACpE,MAAM,WAAW,oBAAoB,CAAC,OAAO;IAC3C,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAAC;IACrE,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,oBAAoB,GAAG,SAAS,CAAC;IAClE,KAAK,IAAI,IAAI,CAAC;IACd,OAAO,IAAI,IAAI,CAAC;IAChB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;CACpC;AA6MD,wEAAwE;AACxE,wBAAgB,0BAA0B,CAAC,OAAO,EAChD,OAAO,EAAE,2BAA2B,CAAC,OAAO,CAAC,GAC5C,oBAAoB,CAAC,OAAO,CAAC,CAE/B"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -8,14 +8,17 @@
|
|
|
8
8
|
* @example Single-import dapp setup
|
|
9
9
|
* ```ts
|
|
10
10
|
* import {
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* BrowserConnectHandler, createConnectionStore,
|
|
12
|
+
* defineApplicationManifest,
|
|
13
13
|
* } from '@enbox/browser';
|
|
14
|
+
* import { MyProtocol } from './my-protocol.js';
|
|
14
15
|
*
|
|
15
|
-
* const
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* const store = createConnectionStore({
|
|
17
|
+
* application : defineApplicationManifest({ protocols: [MyProtocol] }),
|
|
18
|
+
* connectHandler : BrowserConnectHandler({ appName: 'My App' }),
|
|
18
19
|
* });
|
|
20
|
+
* const snapshot = await store.connect();
|
|
21
|
+
* if (snapshot.phase !== 'connected') throw snapshot.error ?? new Error('Connection failed.');
|
|
19
22
|
* ```
|
|
20
23
|
*
|
|
21
24
|
* For non-browser environments (Node.js, CLI, desktop), import from
|
|
@@ -23,12 +26,10 @@
|
|
|
23
26
|
*
|
|
24
27
|
* @packageDocumentation
|
|
25
28
|
*/
|
|
26
|
-
export
|
|
27
|
-
export
|
|
28
|
-
export { AuthManager, AuthSession, ConnectDeniedError, SESSION_EXPIRED_ERROR_CODE, SESSION_REVOKED_ERROR_CODE, computeConnectionStatus, isConnectDeniedError, isSessionExpiredError, isSessionInvalidError, normalizeProtocolRequests, WalletConnect, } from '@enbox/auth/browser';
|
|
29
|
-
export type { AuthEvent, AuthEventHandler, AuthManagerOptions, AuthState, ComputeConnectionStatusOptions, ConnectionMonitorOptions, ConnectionState, ConnectionStatus, ConnectionStatusGrant, ConnectHandler, ConnectOptions, ConnectResult, DisconnectOptions, GetConnectionStatusOptions, HandlerConnectOptions, ImportFromPortableOptions, VaultConnectOptions, Permission, PortableIdentity, ProtocolDefinitionCarrier, ProtocolPermissionRequest, ProtocolRequest, RefreshOptions, RegistrationOptions, StorageAdapter, SyncOption, WalletConnectOptions, } from '@enbox/auth/browser';
|
|
29
|
+
export * from '@enbox/api';
|
|
30
|
+
export * from '@enbox/auth/browser';
|
|
30
31
|
export { CONNECT_DENIED_TOKEN, ConnectProvider } from '@enbox/connect';
|
|
31
|
-
export type { ConnectApproval,
|
|
32
|
+
export type { ConnectApproval, ConnectRequest } from '@enbox/connect';
|
|
32
33
|
export * from './web-features.js';
|
|
33
34
|
export { BrowserConnectHandler, DEFAULT_WALLETS } from './browser-connect-handler.js';
|
|
34
35
|
export type { BrowserConnectHandlerOptions, WalletOption } from './browser-connect-handler.js';
|
|
@@ -46,13 +47,14 @@ export { MAX_PIN_ATTEMPTS, RelayConnectCancelledError, runRelayConnect } from '.
|
|
|
46
47
|
export type { RelayConnectOptions } from './relay-connect-runner.js';
|
|
47
48
|
export { encodeQr, qrToSvg } from './ui/qr.js';
|
|
48
49
|
export type { QrCode, QrSvgOptions } from './ui/qr.js';
|
|
49
|
-
export {
|
|
50
|
-
export {
|
|
51
|
-
export
|
|
50
|
+
export { createBlobUrlPool } from './blob-url-pool.js';
|
|
51
|
+
export type { BlobUrlLease, BlobUrlPool } from './blob-url-pool.js';
|
|
52
|
+
export { createFileEnvelopeUrlStore } from './file-envelope-url-store.js';
|
|
53
|
+
export type { FileEnvelopeUrlLease, FileEnvelopeUrlStore, FileEnvelopeUrlStoreOptions, } from './file-envelope-url-store.js';
|
|
52
54
|
export { createProfileReader, isRetryableProfileReadStatus } from '@enbox/protocols';
|
|
53
55
|
export type { ProfileEntryStatus, ProfileFieldSnapshot, ProfileFieldStatus, ProfileImages, ProfileReader, ProfileReaderFailure, ProfileReaderImagesMode, ProfileReaderOptions, ProfileReaderRecordsSurface, ProfileReaderSource, ProfileReaderTimers, ProfileSnapshot, ProfileWatchListener, PublicProfile, } from '@enbox/protocols';
|
|
54
56
|
export { DwnInterface } from '@enbox/agent';
|
|
55
|
-
export type { DeadLetterEntry, RemoteSyncState, RemoteSyncStatus, SyncConnectivityState, SyncEngine, SyncEvent, SyncEventListener, SyncHealthSummary, } from '@enbox/agent';
|
|
57
|
+
export type { DeadLetterEntry, RemoteSyncState, RemoteSyncStatus, SyncConnectivityState, SyncEngine, SyncEvent, SyncEventListener, SyncHealthSummary, SyncIdentityStatus, } from '@enbox/agent';
|
|
56
58
|
export { DateSort, DwnInterfaceName, DwnMethodName } from '@enbox/dwn-sdk-js';
|
|
57
59
|
export type { ProtocolActionRule, ProtocolDefinition } from '@enbox/dwn-sdk-js';
|
|
58
60
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAMH,cAAc,YAAY,CAAC;AAM3B,cAAc,qBAAqB,CAAC;AAOpC,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACvE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAMtE,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACt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AAE,MAAM,8BAA8B,CAAC;AAC1E,YAAY,EACV,oBAAoB,EACpB,oBAAoB,EACpB,2BAA2B,GAC5B,MAAM,8BAA8B,CAAC;AActC,OAAO,EAAE,mBAAmB,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AACrF,YAAY,EACV,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,oBAAoB,EACpB,uBAAuB,EACvB,oBAAoB,EACpB,2BAA2B,EAC3B,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,EACf,oBAAoB,EACpB,aAAa,GACd,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAK5C,YAAY,EACV,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,UAAU,EACV,SAAS,EACT,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AAItB,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC9E,YAAY,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type ObjectUrlLease = Readonly<{
|
|
2
|
+
url: string;
|
|
3
|
+
/** Release immediately, cancelling any deferred release. Idempotent. */
|
|
4
|
+
release(): void;
|
|
5
|
+
/** Release after a grace period. The first deferred release wins. */
|
|
6
|
+
releaseAfter(delayMs: number): void;
|
|
7
|
+
}>;
|
|
8
|
+
/** Private reference-counted ownership for one object URL. */
|
|
9
|
+
export declare class ObjectUrlReference {
|
|
10
|
+
private readonly _onEmpty;
|
|
11
|
+
readonly url: string;
|
|
12
|
+
private _isRevoked;
|
|
13
|
+
private _references;
|
|
14
|
+
private readonly _releaseTimers;
|
|
15
|
+
constructor(blob: Blob, _onEmpty: (reference: ObjectUrlReference) => void);
|
|
16
|
+
get references(): number;
|
|
17
|
+
acquire(): ObjectUrlLease;
|
|
18
|
+
revoke(): void;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=object-url-reference.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object-url-reference.d.ts","sourceRoot":"","sources":["../../src/object-url-reference.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,wEAAwE;IACxE,OAAO,IAAI,IAAI,CAAC;IAChB,qEAAqE;IACrE,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACrC,CAAC,CAAC;AAUH,8DAA8D;AAC9D,qBAAa,kBAAkB;IAME,OAAO,CAAC,QAAQ,CAAC,QAAQ;IALxD,SAAgB,GAAG,EAAE,MAAM,CAAC;IAC5B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA4C;gBAExD,IAAI,EAAE,IAAI,EAAmB,QAAQ,EAAE,CAAC,SAAS,EAAE,kBAAkB,KAAK,IAAI;IAIjG,IAAW,UAAU,IAAI,MAAM,CAE9B;IAEM,OAAO,IAAI,cAAc;IAuCzB,MAAM,IAAI,IAAI;CAWtB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enbox/browser",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.71",
|
|
4
4
|
"description": "Enbox tools and features to use in the browser",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/esm/index.js",
|
|
@@ -66,15 +66,15 @@
|
|
|
66
66
|
"access": "public"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@enbox/agent": "0.8.
|
|
70
|
-
"@enbox/api": "0.6.
|
|
71
|
-
"@enbox/auth": "0.6.
|
|
69
|
+
"@enbox/agent": "0.8.40",
|
|
70
|
+
"@enbox/api": "0.6.79",
|
|
71
|
+
"@enbox/auth": "0.6.86",
|
|
72
72
|
"@enbox/common": "0.1.6",
|
|
73
|
-
"@enbox/connect": "0.1.
|
|
73
|
+
"@enbox/connect": "0.1.20",
|
|
74
74
|
"@enbox/crypto": "0.1.9",
|
|
75
75
|
"@enbox/dids": "0.1.10",
|
|
76
|
-
"@enbox/dwn-sdk-js": "0.4.
|
|
77
|
-
"@enbox/protocols": "0.2.
|
|
76
|
+
"@enbox/dwn-sdk-js": "0.4.24",
|
|
77
|
+
"@enbox/protocols": "0.2.106"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
80
|
"@types/qrcode": "^1.5.6",
|