dl-once 0.0.1 → 0.0.2

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 (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +128 -28
  3. package/dist/_bytes-builder.d.ts +34 -0
  4. package/dist/_bytes-builder.d.ts.map +1 -0
  5. package/dist/_bytes-builder.js +48 -0
  6. package/dist/cache-storage.d.ts +74 -0
  7. package/dist/cache-storage.d.ts.map +1 -0
  8. package/dist/cache-storage.js +1 -0
  9. package/dist/dl-once.d.ts +242 -0
  10. package/dist/dl-once.d.ts.map +1 -0
  11. package/dist/dl-once.js +245 -0
  12. package/dist/hash-verification-hook.d.ts +46 -0
  13. package/dist/hash-verification-hook.d.ts.map +1 -0
  14. package/dist/hash-verification-hook.js +97 -0
  15. package/dist/index.d.ts +16 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +8 -0
  18. package/dist/indexeddb-cache-storage.d.ts +51 -0
  19. package/dist/indexeddb-cache-storage.d.ts.map +1 -0
  20. package/dist/indexeddb-cache-storage.js +573 -0
  21. package/dist/md5-verification-hook.d.ts +15 -0
  22. package/dist/md5-verification-hook.d.ts.map +1 -0
  23. package/dist/md5-verification-hook.js +17 -0
  24. package/dist/memory-cache-storage.d.ts +41 -0
  25. package/dist/memory-cache-storage.d.ts.map +1 -0
  26. package/dist/memory-cache-storage.js +290 -0
  27. package/dist/node-fs-cache-storage.d.ts +63 -0
  28. package/dist/node-fs-cache-storage.d.ts.map +1 -0
  29. package/dist/node-fs-cache-storage.js +565 -0
  30. package/dist/sha256-verification-hook.d.ts +15 -0
  31. package/dist/sha256-verification-hook.d.ts.map +1 -0
  32. package/dist/sha256-verification-hook.js +17 -0
  33. package/package.json +46 -7
  34. package/src/_bytes-builder.ts +66 -0
  35. package/src/cache-storage.ts +86 -0
  36. package/src/dl-once.ts +554 -0
  37. package/src/hash-verification-hook.ts +98 -0
  38. package/src/index.ts +28 -0
  39. package/src/indexeddb-cache-storage.ts +535 -0
  40. package/src/md5-verification-hook.ts +18 -0
  41. package/src/memory-cache-storage.ts +361 -0
  42. package/src/node-fs-cache-storage.ts +511 -0
  43. package/src/sha256-verification-hook.ts +18 -0
@@ -0,0 +1,245 @@
1
+ import { getLogger } from "@logtape/logtape";
2
+ import BytesBuilder from "./_bytes-builder.js";
3
+ /**
4
+ * ロガーのインスタンスです。
5
+ */
6
+ const log = getLogger("dl-once");
7
+ /**
8
+ * ターゲット情報を解析して Request オブジェクトに変換します。
9
+ *
10
+ * @param target 解析対象のターゲットです。
11
+ * @returns 解析された Request オブジェクトを返す Promise です。
12
+ */
13
+ async function parseTarget(target) {
14
+ return typeof target === "function"
15
+ ? await parseTarget(await target())
16
+ : target instanceof Request
17
+ ? target
18
+ : new Request(target);
19
+ }
20
+ /**
21
+ * 指定されたターゲットからデータを一度だけダウンロードし、バイナリーデータとして返します。
22
+ *
23
+ * キャッシュが利用可能な場合はキャッシュから取得を試み、失敗した場合はネットワーク経由で取得します。
24
+ *
25
+ * @param target ダウンロード対象(単体、設定オブジェクト、またはその配列)です。
26
+ * @param options ダウンロードの動作を制御するオプションです。
27
+ * @returns 取得されたバイナリーデータ(Uint8Array)を解決する Promise です。
28
+ */
29
+ export default async function downloadOnce(target, options = {}) {
30
+ // ターゲットを配列に正規化します。
31
+ const targets = Array.isArray(target)
32
+ ? target
33
+ : [target];
34
+ if (targets.length === 0) {
35
+ throw new Error("No targets provided");
36
+ }
37
+ // オプションから各設定を抽出します。
38
+ const { hooks: rawGlobalHooks = [], signal, fetcher: defaultFetcher = fetch, cacheHandle: defaultCacheHandle, forceDownload: defaultForceDownload = false, } = options;
39
+ // Falsy な値を除去したグローバルフックのリストを作成します。
40
+ const globalHooks = rawGlobalHooks.filter(hook => !!hook);
41
+ // コールバック(フック等)で使用するタイムアウト付きのシグナルを設定します(デフォルトは 60 分)。
42
+ const callbackSignal = signal || AbortSignal.timeout(60 * 60e3);
43
+ const errors = [];
44
+ // 複数のターゲットを順番に試行します。
45
+ for (const item of targets) {
46
+ // 各ループの開始時に中断を確認します。
47
+ signal?.throwIfAborted();
48
+ // ターゲットが Config オブジェクトか、プリミティブな Target かを判定して正規化します。
49
+ const { hooks: targetHooks = [], target: actualTarget, fetcher = defaultFetcher, cacheHandle = defaultCacheHandle, forceDownload = defaultForceDownload, } = typeof item === "string"
50
+ || item instanceof URL
51
+ || item instanceof Request
52
+ || typeof item === "function"
53
+ ? { target: item }
54
+ : item;
55
+ let writer = null;
56
+ const hooks = [];
57
+ const closedHooks = new Set();
58
+ try {
59
+ // キャッシュからの読み込みを試行します。
60
+ if (cacheHandle && !forceDownload) {
61
+ try {
62
+ const reader = await cacheHandle.getReader({
63
+ signal: callbackSignal,
64
+ });
65
+ if (reader) {
66
+ const chunks = new BytesBuilder();
67
+ for await (const data of reader) {
68
+ signal?.throwIfAborted();
69
+ chunks.write(data);
70
+ }
71
+ return chunks.bytes();
72
+ }
73
+ }
74
+ catch (ex) {
75
+ // キャッシュ読み込み失敗時はログを出力し、ネットワークフェッチへフォールバックします。
76
+ log.warn `Cache read failed, falling back to network fetch: ${ex}`;
77
+ }
78
+ }
79
+ // ネットワークからのダウンロード準備を開始します。
80
+ const request = await parseTarget(actualTarget);
81
+ // 前処理フックを実行します(個別設定のフックを優先)。
82
+ for (const hook of [...targetHooks.filter((hook) => !!hook), ...globalHooks]) {
83
+ await hook.onBeforeDownload?.({
84
+ signal: callbackSignal,
85
+ request,
86
+ });
87
+ hooks.push(hook);
88
+ }
89
+ // リクエスト初期化設定を作成します。
90
+ const requestInit = signal instanceof AbortSignal
91
+ ? { signal }
92
+ : undefined;
93
+ // HTTP リクエストを実行します。
94
+ const response = await fetcher(request, requestInit);
95
+ if (!response.ok) {
96
+ throw new Error(`HTTP Error: [${response.status}] ${response.statusText}`);
97
+ }
98
+ if (!response.body) {
99
+ throw new Error("Response body is null");
100
+ }
101
+ // キャッシュへの書き込みが可能な場合はライターを初期化します。
102
+ if (cacheHandle) {
103
+ try {
104
+ writer = await cacheHandle.getWriter({
105
+ signal: callbackSignal,
106
+ request,
107
+ response,
108
+ });
109
+ }
110
+ catch (ex) {
111
+ log.warn `Failed to create cache writer: ${ex}`;
112
+ }
113
+ }
114
+ // ストリームからデータを読み取ります。
115
+ const reader = response.body.getReader();
116
+ const chunks = new BytesBuilder();
117
+ try {
118
+ while (true) {
119
+ signal?.throwIfAborted();
120
+ const { done, value: chunkData, } = await reader.read();
121
+ if (chunkData) {
122
+ // データを受信するたびに各フックの onChunkRead を呼び出します。
123
+ for (let i = 0; i < hooks.length; i++) {
124
+ if (closedHooks.has(i)) {
125
+ continue;
126
+ }
127
+ const hook = hooks[i];
128
+ try {
129
+ await hook.onChunkRead?.({
130
+ signal: callbackSignal,
131
+ response,
132
+ chunkData,
133
+ });
134
+ }
135
+ catch (ex) {
136
+ // フック内でのエラー発生時は onError を呼び出し、そのフックをクローズ扱い(以降無視)にします。
137
+ try {
138
+ closedHooks.add(i);
139
+ await hook.onError?.({
140
+ reason: ex,
141
+ signal: callbackSignal,
142
+ });
143
+ }
144
+ catch (ex) {
145
+ log.warn `Failed to call error handler: ${ex}`;
146
+ }
147
+ }
148
+ }
149
+ // 読み込んだデータをビルダーとキャッシュライターに書き込みます。
150
+ chunks.write(chunkData);
151
+ await writer?.write(chunkData);
152
+ }
153
+ if (done) {
154
+ break;
155
+ }
156
+ }
157
+ }
158
+ catch (ex) {
159
+ // リーダーの読み取り中にエラーが発生した場合はストリームをキャンセルします。
160
+ try {
161
+ await reader.cancel(ex);
162
+ }
163
+ catch (ex) {
164
+ log.warn `Failed to cancel reader: ${ex}`;
165
+ }
166
+ throw ex;
167
+ }
168
+ finally {
169
+ // ロックを確実に解放します。
170
+ try {
171
+ reader.releaseLock();
172
+ }
173
+ catch (ex) {
174
+ log.warn `Failed to release reader lock: ${ex}`;
175
+ }
176
+ }
177
+ // 正常終了時のクリーンアップ処理です。
178
+ for (let i = 0; i < hooks.length; i++) {
179
+ if (closedHooks.has(i)) {
180
+ continue;
181
+ }
182
+ const hook = hooks[i];
183
+ try {
184
+ closedHooks.add(i);
185
+ await hook.onClose?.({
186
+ signal: callbackSignal,
187
+ });
188
+ }
189
+ catch (ex) {
190
+ try {
191
+ await hook.onError?.({
192
+ reason: ex,
193
+ signal: callbackSignal,
194
+ });
195
+ }
196
+ catch (ex) {
197
+ log.warn `Failed to call error handler: ${ex}`;
198
+ }
199
+ throw ex;
200
+ }
201
+ }
202
+ // キャッシュライターを閉じます。
203
+ await writer?.close();
204
+ writer = null;
205
+ // すべてのデータを結合したバイナリーを返します。
206
+ return chunks.bytes();
207
+ }
208
+ catch (ex) {
209
+ // 試行が失敗した場合はエラーを蓄積し、次のターゲット(存在すれば)に移行します。
210
+ errors.push(ex);
211
+ // キャッシュ書き込みを中止します。
212
+ try {
213
+ await writer?.abort(ex);
214
+ writer = null;
215
+ }
216
+ catch (ex) {
217
+ log.warn `Failed to abort cache writer: ${ex}`;
218
+ }
219
+ // まだ生存しているフックに対してエラー通知を行います。
220
+ for (let i = 0; i < hooks.length; i++) {
221
+ if (closedHooks.has(i)) {
222
+ continue;
223
+ }
224
+ const hook = hooks[i];
225
+ try {
226
+ closedHooks.add(i);
227
+ await hook.onError?.({
228
+ reason: ex,
229
+ signal: callbackSignal,
230
+ });
231
+ }
232
+ catch (ex) {
233
+ log.warn `Failed to call error handler: ${ex}`;
234
+ }
235
+ }
236
+ }
237
+ }
238
+ // すべてのターゲットで失敗した場合は AggregateError を投げます。
239
+ if (errors.length === 1) {
240
+ throw errors[0];
241
+ }
242
+ else {
243
+ throw new AggregateError(errors);
244
+ }
245
+ }
@@ -0,0 +1,46 @@
1
+ import type { IHasher } from "hash-wasm";
2
+ import type { ChunkReadHandlerArgs, IHook } from "./dl-once.js";
3
+ /**
4
+ * ダウンロードされたデータのハッシュ値を検証するためのフッククラスです。
5
+ *
6
+ * `hash-wasm` ライブラリーを使用して、ストリーム読み込みに合わせて逐次的にハッシュ計算を行い、完了時に期待されるハッシュ値と一致するかを判定します。
7
+ */
8
+ export default class HashVerificationHook implements IHook {
9
+ #private;
10
+ /**
11
+ * HashVerificationHook の新しいインスタンスを作成します。
12
+ *
13
+ * @param createHahser ハッシュ計算を行うオブジェクトを作成する関数です。
14
+ * @param expectedHash 比較対象となる 16 進数形式の期待されるハッシュ値です。
15
+ */
16
+ constructor(createHahser: () => Promise<IHasher>, expectedHash: string);
17
+ /**
18
+ * ダウンロード開始前に呼び出される非同期メソッドです。
19
+ *
20
+ * ハッシュ計算用の WebAssembly インスタンスを作成し、初期化処理を行います。
21
+ *
22
+ * @returns インスタンスの準備が完了した際に解決される Promise です。
23
+ */
24
+ onBeforeDownload(): Promise<void>;
25
+ /**
26
+ * データチャンクが読み込まれるたびに呼び出されるメソッドです。
27
+ *
28
+ * 取得したチャンクデータをハッシュ計算機に送り、中間状態を更新します。
29
+ *
30
+ * @param args チャンクデータを含むハンドラー引数です。
31
+ */
32
+ onChunkRead(args: Pick<ChunkReadHandlerArgs, "chunkData">): void;
33
+ /**
34
+ * ダウンロードストリームが正常に終了した際に呼び出されるメソッドです。
35
+ *
36
+ * 最終的なハッシュ値を算出し、期待される値と異なる場合はエラーを投げます。
37
+ */
38
+ onClose(): void;
39
+ /**
40
+ * ダウンロード中にエラーが発生した際に呼び出されるメソッドです。
41
+ *
42
+ * 保持しているハッシュ計算機のインスタンスを破棄し、リソースを解放します。
43
+ */
44
+ onError(): void;
45
+ }
46
+ //# sourceMappingURL=hash-verification-hook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash-verification-hook.d.ts","sourceRoot":"","sources":["../src/hash-verification-hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAEhE;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,oBAAqB,YAAW,KAAK;;IAgBxD;;;;;OAKG;gBACgB,YAAY,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,YAAY,EAAE,MAAM;IAM7E;;;;;;OAMG;IACU,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAY9C;;;;;;OAMG;IACI,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,oBAAoB,EAAE,WAAW,CAAC,GAAG,IAAI;IAQvE;;;;OAIG;IACI,OAAO,IAAI,IAAI;IAatB;;;;OAIG;IACI,OAAO,IAAI,IAAI;CAIvB"}
@@ -0,0 +1,97 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ 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");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ 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");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _HashVerificationHook_createHahser, _HashVerificationHook_hasher, _HashVerificationHook_expectedHash;
13
+ /**
14
+ * ダウンロードされたデータのハッシュ値を検証するためのフッククラスです。
15
+ *
16
+ * `hash-wasm` ライブラリーを使用して、ストリーム読み込みに合わせて逐次的にハッシュ計算を行い、完了時に期待されるハッシュ値と一致するかを判定します。
17
+ */
18
+ class HashVerificationHook {
19
+ /**
20
+ * HashVerificationHook の新しいインスタンスを作成します。
21
+ *
22
+ * @param createHahser ハッシュ計算を行うオブジェクトを作成する関数です。
23
+ * @param expectedHash 比較対象となる 16 進数形式の期待されるハッシュ値です。
24
+ */
25
+ constructor(createHahser, expectedHash) {
26
+ /**
27
+ * ハッシュ計算を行うオブジェクトを作成する関数です。
28
+ */
29
+ _HashVerificationHook_createHahser.set(this, void 0);
30
+ /**
31
+ * ハッシュ計算を行うための WebAssembly インスタンスを保持するプロパティーです。
32
+ */
33
+ _HashVerificationHook_hasher.set(this, null);
34
+ /**
35
+ * 比較対象となる期待されるハッシュ値(小文字)を保持する読み取り専用プロパティーです。
36
+ */
37
+ _HashVerificationHook_expectedHash.set(this, void 0);
38
+ __classPrivateFieldSet(this, _HashVerificationHook_createHahser, createHahser, "f");
39
+ // 比較時の揺らぎをなくすため、入力されたハッシュ値を小文字に正規化して保存します。
40
+ __classPrivateFieldSet(this, _HashVerificationHook_expectedHash, expectedHash.toLowerCase(), "f");
41
+ }
42
+ /**
43
+ * ダウンロード開始前に呼び出される非同期メソッドです。
44
+ *
45
+ * ハッシュ計算用の WebAssembly インスタンスを作成し、初期化処理を行います。
46
+ *
47
+ * @returns インスタンスの準備が完了した際に解決される Promise です。
48
+ */
49
+ async onBeforeDownload() {
50
+ if (__classPrivateFieldGet(this, _HashVerificationHook_hasher, "f")) {
51
+ throw new Error("Hasher is already initialized");
52
+ }
53
+ // hash-wasm ライブラリーを使用してハッシュ計算用の WASM インスタンスを作成します。
54
+ __classPrivateFieldSet(this, _HashVerificationHook_hasher, await __classPrivateFieldGet(this, _HashVerificationHook_createHahser, "f").call(this), "f");
55
+ // ハッシュ計算の内部状態をリセットし、新しいストリームの受け入れ準備を整えます。
56
+ __classPrivateFieldGet(this, _HashVerificationHook_hasher, "f").init();
57
+ }
58
+ /**
59
+ * データチャンクが読み込まれるたびに呼び出されるメソッドです。
60
+ *
61
+ * 取得したチャンクデータをハッシュ計算機に送り、中間状態を更新します。
62
+ *
63
+ * @param args チャンクデータを含むハンドラー引数です。
64
+ */
65
+ onChunkRead(args) {
66
+ const { chunkData } = args;
67
+ // 初期化済みのハッシュ計算機へバイナリーデータを渡します。
68
+ // update メソッドにより、メモリー効率を保ちながら逐次計算が行われます。
69
+ __classPrivateFieldGet(this, _HashVerificationHook_hasher, "f").update(chunkData);
70
+ }
71
+ /**
72
+ * ダウンロードストリームが正常に終了した際に呼び出されるメソッドです。
73
+ *
74
+ * 最終的なハッシュ値を算出し、期待される値と異なる場合はエラーを投げます。
75
+ */
76
+ onClose() {
77
+ // これまでに蓄積されたデータから最終的なダイジェスト(16 進数文字列)を作成します。
78
+ const finalHash = __classPrivateFieldGet(this, _HashVerificationHook_hasher, "f").digest();
79
+ // 算出したハッシュと、コンストラクターで受け取った期待値を比較します。
80
+ if (finalHash !== __classPrivateFieldGet(this, _HashVerificationHook_expectedHash, "f")) {
81
+ // データの整合性が保たれていないため、詳細な情報を添えてエラーを投げます。
82
+ throw new Error(`Hash mismatch! Expected: ${__classPrivateFieldGet(this, _HashVerificationHook_expectedHash, "f")}, but got: ${finalHash}`);
83
+ }
84
+ __classPrivateFieldSet(this, _HashVerificationHook_hasher, null, "f");
85
+ }
86
+ /**
87
+ * ダウンロード中にエラーが発生した際に呼び出されるメソッドです。
88
+ *
89
+ * 保持しているハッシュ計算機のインスタンスを破棄し、リソースを解放します。
90
+ */
91
+ onError() {
92
+ // 計算途中の状態を破棄するため、プロパティーを null にリセットします。
93
+ __classPrivateFieldSet(this, _HashVerificationHook_hasher, null, "f");
94
+ }
95
+ }
96
+ _HashVerificationHook_createHahser = new WeakMap(), _HashVerificationHook_hasher = new WeakMap(), _HashVerificationHook_expectedHash = new WeakMap();
97
+ export default HashVerificationHook;
@@ -0,0 +1,16 @@
1
+ export type * from "./dl-once.js";
2
+ export { default, default as downloadOnce } from "./dl-once.js";
3
+ export type * from "./hash-verification-hook.js";
4
+ export { default as HashVerificationHook } from "./hash-verification-hook.js";
5
+ export type * from "./md5-verification-hook.js";
6
+ export { default as Md5VerificationHook } from "./md5-verification-hook.js";
7
+ export type * from "./sha256-verification-hook.js";
8
+ export { default as Sha256VerificationHook } from "./sha256-verification-hook.js";
9
+ export type * from "./cache-storage.js";
10
+ export type * from "./indexeddb-cache-storage.js";
11
+ export { default as IndexedDbCacheStorage } from "./indexeddb-cache-storage.js";
12
+ export type * from "./memory-cache-storage.js";
13
+ export { default as MemoryCacheStorage } from "./memory-cache-storage.js";
14
+ export type * from "./node-fs-cache-storage.js";
15
+ export { default as NodeFsCacheStorage } from "./node-fs-cache-storage.js";
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,mBAAmB,cAAc,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,cAAc,CAAC;AAIhE,mBAAmB,6BAA6B,CAAC;AACjD,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAE9E,mBAAmB,4BAA4B,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAE5E,mBAAmB,+BAA+B,CAAC;AACnD,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAIlF,mBAAmB,oBAAoB,CAAC;AAExC,mBAAmB,8BAA8B,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAEhF,mBAAmB,2BAA2B,CAAC;AAC/C,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE1E,mBAAmB,4BAA4B,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,4BAA4B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ // メイン
2
+ export { default, default as downloadOnce } from "./dl-once.js";
3
+ export { default as HashVerificationHook } from "./hash-verification-hook.js";
4
+ export { default as Md5VerificationHook } from "./md5-verification-hook.js";
5
+ export { default as Sha256VerificationHook } from "./sha256-verification-hook.js";
6
+ export { default as IndexedDbCacheStorage } from "./indexeddb-cache-storage.js";
7
+ export { default as MemoryCacheStorage } from "./memory-cache-storage.js";
8
+ export { default as NodeFsCacheStorage } from "./node-fs-cache-storage.js";
@@ -0,0 +1,51 @@
1
+ import type { ClearOptions, CloseOptions, ICacheStorage, OpenOptions } from "./cache-storage.js";
2
+ import type { ICacheHandle } from "./dl-once.js";
3
+ /**
4
+ * IndexedDB をバックエンドとしたキャッシュストレージの実装クラスです。
5
+ */
6
+ export default class IndexedDbCacheStorage implements ICacheStorage, AsyncDisposable {
7
+ #private;
8
+ /**
9
+ * IndexedDbCacheStorage のインスタンスを初期化します。
10
+ *
11
+ * @param dbName データベース名です。指定されない場合はデフォルト名が使用されます。
12
+ */
13
+ constructor(dbName: string | undefined);
14
+ /**
15
+ * ストレージが開いているかどうかを返します。
16
+ */
17
+ get isOpen(): boolean;
18
+ /**
19
+ * データベースを開き、初期化を行います。
20
+ *
21
+ * @param options オープン時のオプション(Signal 等)です。
22
+ */
23
+ open(options?: OpenOptions | undefined): Promise<void>;
24
+ /**
25
+ * データベース接続を閉じます。
26
+ *
27
+ * @param options クローズ時のオプションです。
28
+ */
29
+ close(options?: CloseOptions | undefined): Promise<void>;
30
+ /**
31
+ * `using` 構文等で利用される非同期破棄メソッドです。
32
+ *
33
+ * 接続が開いている場合は閉じます。
34
+ */
35
+ [Symbol.asyncDispose](): Promise<void>;
36
+ /**
37
+ * キャッシュされたデータを削除します。
38
+ *
39
+ * 引数の組み合わせにより、特定のキーの削除または全削除を行います。
40
+ */
41
+ clear(cacheKey?: string | undefined, options?: Omit<ClearOptions, "cacheKey"> | undefined): Promise<void>;
42
+ clear(options?: ClearOptions | undefined): Promise<void>;
43
+ /**
44
+ * 指定したキーに対するキャッシュ操作ハンドルを作成します。
45
+ *
46
+ * @param key キャッシュキーです。
47
+ * @returns キャッシュハンドルインスタンスです。
48
+ */
49
+ createCacheHandle(key: string): ICacheHandle;
50
+ }
51
+ //# sourceMappingURL=indexeddb-cache-storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"indexeddb-cache-storage.d.ts","sourceRoot":"","sources":["../src/indexeddb-cache-storage.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjG,OAAO,KAAK,EAAgC,YAAY,EAAW,MAAM,cAAc,CAAC;AA6UxF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,qBAAsB,YAAW,aAAa,EAAE,eAAe;;IAgBlF;;;;OAIG;gBACgB,MAAM,EAAE,MAAM,GAAG,SAAS;IAiB7C;;OAEG;IACH,IAAW,MAAM,IAAI,OAAO,CAE3B;IAED;;;;OAIG;IACU,IAAI,CAAC,OAAO,GAAE,WAAW,GAAG,SAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAuBvE;;;;OAIG;IACU,KAAK,CAAC,OAAO,GAAE,YAAY,GAAG,SAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAWzE;;;;OAIG;IACU,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;IAOnD;;;;OAIG;IACI,KAAK,CACV,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,EAC7B,OAAO,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,GAAG,SAAS,GACnD,OAAO,CAAC,IAAI,CAAC;IAET,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAwE/D;;;;;OAKG;IACI,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY;CAKpD"}