@unikvs/indexeddb 0.0.1 → 0.0.5

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026-present, tai-kun
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ import type { IStorage } from "@unikvs/core";
2
+ /**
3
+ * ブラウザーの IndexedDB を永続化先として使用するストレージクラスです。
4
+ */
5
+ export default class Indexeddb implements IStorage {
6
+ /**
7
+ * IndexedDB のデータベースインスタンスを保持します。
8
+ *
9
+ * ストレージがオープンされるまで null です。
10
+ */
11
+ private db;
12
+ /**
13
+ * 使用するデータベース名です。
14
+ */
15
+ private readonly dbName;
16
+ /**
17
+ * 使用するオブジェクトストア名です。
18
+ */
19
+ private readonly storeName;
20
+ readonly name: string;
21
+ /**
22
+ * Indexeddb インスタンスを初期化します。
23
+ *
24
+ * @param dbName データベース名です。
25
+ * @param storeName データを保存するオブジェクトストア名です。
26
+ */
27
+ constructor(dbName?: string, storeName?: string);
28
+ get isOpen(): boolean;
29
+ open(): Promise<void>;
30
+ close(): Promise<void>;
31
+ write(args: Pick<IStorage.WriteArgs<any>, "key" | "data">): Promise<void>;
32
+ read(args: Pick<IStorage.ReadArgs, "key">): Promise<any>;
33
+ exists(args: Pick<IStorage.ExistsArgs, "key">): Promise<boolean>;
34
+ delete(args: Pick<IStorage.DeleteArgs, "key">): Promise<void>;
35
+ clear(): Promise<void>;
36
+ getWritable(args: Pick<IStorage.GetWritableArgs, "key">): WritableStream<Uint8Array>;
37
+ getReadable(args: Pick<IStorage.GetReadableArgs, "key">): ReadableStream<Uint8Array>;
38
+ }
39
+ //# sourceMappingURL=indexeddb.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"indexeddb.d.ts","sourceRoot":"","sources":["../../src/indexeddb.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,SAAU,YAAW,QAAQ;IAChD;;;;OAIG;IACH,OAAO,CAAC,EAAE,CAAsB;IAEhC;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IAEnC,SAAgB,IAAI,EAAE,MAAM,CAAC;IAE7B;;;;;OAKG;gBACgB,MAAM,GAAE,MAAoB,EAAE,SAAS,GAAE,MAAoB;IAOhF,IAAW,MAAM,IAAI,OAAO,CAE3B;IAEY,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAerB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAKtB,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAKzE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;IAaxD,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAQhE,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAK7D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,eAAe,EAAE,KAAK,CAAC,GAAG,cAAc,CAAC,UAAU,CAAC;IAwBpF,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,eAAe,EAAE,KAAK,CAAC,GAAG,cAAc,CAAC,UAAU,CAAC;CAY5F"}
@@ -0,0 +1,94 @@
1
+ import { openDB } from "idb";
2
+ /**
3
+ * ブラウザーの IndexedDB を永続化先として使用するストレージクラスです。
4
+ */
5
+ export default class Indexeddb {
6
+ /**
7
+ * Indexeddb インスタンスを初期化します。
8
+ *
9
+ * @param dbName データベース名です。
10
+ * @param storeName データを保存するオブジェクトストア名です。
11
+ */
12
+ constructor(dbName = "unikvs_db", storeName = "kvs_store") {
13
+ this.name = "Indexeddb";
14
+ this.db = null;
15
+ this.dbName = dbName;
16
+ this.storeName = storeName;
17
+ }
18
+ get isOpen() {
19
+ return this.db !== null;
20
+ }
21
+ async open() {
22
+ if (this.db) {
23
+ return;
24
+ }
25
+ this.db = await openDB(this.dbName, 1, {
26
+ upgrade: (db) => {
27
+ // オブジェクトストアが存在しない場合は作成します
28
+ if (!db.objectStoreNames.contains(this.storeName)) {
29
+ db.createObjectStore(this.storeName);
30
+ }
31
+ },
32
+ });
33
+ }
34
+ async close() {
35
+ this.db.close();
36
+ this.db = null;
37
+ }
38
+ async write(args) {
39
+ const { key, data } = args;
40
+ await this.db.put(this.storeName, data, key);
41
+ }
42
+ async read(args) {
43
+ const { key } = args;
44
+ // Opfs の挙動に合わせて、存在しない場合は DOMException (NotFoundError) を投げます
45
+ if (!(await this.exists({ key }))) {
46
+ throw new DOMException(`A requested file or directory could not be found at the time an operation was processed.`, "NotFoundError");
47
+ }
48
+ return await this.db.get(this.storeName, key);
49
+ }
50
+ async exists(args) {
51
+ const { key } = args;
52
+ // count() はキーが存在すれば 1 を、存在しなければ 0 を返します
53
+ const count = await this.db.count(this.storeName, key);
54
+ return count > 0;
55
+ }
56
+ async delete(args) {
57
+ const { key } = args;
58
+ await this.db.delete(this.storeName, key);
59
+ }
60
+ async clear() {
61
+ await this.db.clear(this.storeName);
62
+ }
63
+ getWritable(args) {
64
+ const { key } = args;
65
+ const chunks = [];
66
+ // IndexedDB にはネイティブなファイルストリームがないため、書き込まれたチャンクをメモリに保持し、クローズ時にまとめて put します。
67
+ return new WritableStream({
68
+ write: (chunk) => {
69
+ chunks.push(chunk);
70
+ },
71
+ close: async () => {
72
+ const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
73
+ const result = new Uint8Array(totalLength);
74
+ let offset = 0;
75
+ for (const chunk of chunks) {
76
+ result.set(chunk, offset);
77
+ offset += chunk.length;
78
+ }
79
+ await this.db.put(this.storeName, result, key);
80
+ },
81
+ });
82
+ }
83
+ getReadable(args) {
84
+ const { key } = args;
85
+ return new ReadableStream({
86
+ pull: async (controller) => {
87
+ // データ全体をメモリにロードしてから ReadableStream に流し込みます。
88
+ const data = await this.read({ key });
89
+ controller.enqueue(data);
90
+ controller.close();
91
+ },
92
+ });
93
+ }
94
+ }
package/package.json CHANGED
@@ -1,10 +1,48 @@
1
1
  {
2
2
  "name": "@unikvs/indexeddb",
3
- "version": "0.0.1",
4
- "description": "OIDC trusted publishing setup package for @unikvs/indexeddb",
5
- "keywords": [
6
- "oidc",
7
- "trusted-publishing",
8
- "setup"
9
- ]
10
- }
3
+ "version": "0.0.5",
4
+ "description": "",
5
+ "homepage": "https://github.com/tai-kun/unikvs",
6
+ "license": "MIT",
7
+ "author": "tai-kun",
8
+ "repository": {
9
+ "url": "https://github.com/tai-kun/unikvs"
10
+ },
11
+ "files": [
12
+ "dist",
13
+ "src",
14
+ "package.json",
15
+ "LICENSE"
16
+ ],
17
+ "type": "module",
18
+ "sideEffects": false,
19
+ "main": "./dist/src/index.js",
20
+ "types": "./dist/src/index.d.ts",
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/src/index.d.ts",
24
+ "default": "./dist/src/index.js"
25
+ }
26
+ },
27
+ "dependencies": {
28
+ "@unikvs/core": "0.0.5",
29
+ "idb": "^8.0.3"
30
+ },
31
+ "devDependencies": {
32
+ "@tsconfig/node24": "^24.0.4",
33
+ "@tsconfig/strictest": "^2.0.8",
34
+ "@types/node": "^24.12.2",
35
+ "@vitest/browser": "^4.1.5",
36
+ "@vitest/browser-playwright": "^4.1.5",
37
+ "npm-check-updates": "^20.0.2",
38
+ "playwright": "^1.59.1",
39
+ "vite": "^8.0.10",
40
+ "vitest": "^4.1.5"
41
+ },
42
+ "peerDependencies": {
43
+ "@logtape/logtape": "^2.0.0"
44
+ },
45
+ "scripts": {
46
+ "build": "tsc --project ./.config/tsconfig.build.json"
47
+ }
48
+ }
@@ -0,0 +1,135 @@
1
+ import type { IStorage } from "@unikvs/core";
2
+ import { openDB, type IDBPDatabase } from "idb";
3
+
4
+ /**
5
+ * ブラウザーの IndexedDB を永続化先として使用するストレージクラスです。
6
+ */
7
+ export default class Indexeddb implements IStorage {
8
+ /**
9
+ * IndexedDB のデータベースインスタンスを保持します。
10
+ *
11
+ * ストレージがオープンされるまで null です。
12
+ */
13
+ private db: IDBPDatabase | null;
14
+
15
+ /**
16
+ * 使用するデータベース名です。
17
+ */
18
+ private readonly dbName: string;
19
+
20
+ /**
21
+ * 使用するオブジェクトストア名です。
22
+ */
23
+ private readonly storeName: string;
24
+
25
+ public readonly name: string;
26
+
27
+ /**
28
+ * Indexeddb インスタンスを初期化します。
29
+ *
30
+ * @param dbName データベース名です。
31
+ * @param storeName データを保存するオブジェクトストア名です。
32
+ */
33
+ public constructor(dbName: string = "unikvs_db", storeName: string = "kvs_store") {
34
+ this.name = "Indexeddb";
35
+ this.db = null;
36
+ this.dbName = dbName;
37
+ this.storeName = storeName;
38
+ }
39
+
40
+ public get isOpen(): boolean {
41
+ return this.db !== null;
42
+ }
43
+
44
+ public async open(): Promise<void> {
45
+ if (this.db) {
46
+ return;
47
+ }
48
+
49
+ this.db = await openDB(this.dbName, 1, {
50
+ upgrade: (db) => {
51
+ // オブジェクトストアが存在しない場合は作成します
52
+ if (!db.objectStoreNames.contains(this.storeName)) {
53
+ db.createObjectStore(this.storeName);
54
+ }
55
+ },
56
+ });
57
+ }
58
+
59
+ public async close(): Promise<void> {
60
+ this.db!.close();
61
+ this.db = null;
62
+ }
63
+
64
+ public async write(args: Pick<IStorage.WriteArgs<any>, "key" | "data">): Promise<void> {
65
+ const { key, data } = args;
66
+ await this.db!.put(this.storeName, data, key);
67
+ }
68
+
69
+ public async read(args: Pick<IStorage.ReadArgs, "key">): Promise<any> {
70
+ const { key } = args;
71
+ // Opfs の挙動に合わせて、存在しない場合は DOMException (NotFoundError) を投げます
72
+ if (!(await this.exists({ key }))) {
73
+ throw new DOMException(
74
+ `A requested file or directory could not be found at the time an operation was processed.`,
75
+ "NotFoundError",
76
+ );
77
+ }
78
+
79
+ return await this.db!.get(this.storeName, key);
80
+ }
81
+
82
+ public async exists(args: Pick<IStorage.ExistsArgs, "key">): Promise<boolean> {
83
+ const { key } = args;
84
+
85
+ // count() はキーが存在すれば 1 を、存在しなければ 0 を返します
86
+ const count = await this.db!.count(this.storeName, key);
87
+ return count > 0;
88
+ }
89
+
90
+ public async delete(args: Pick<IStorage.DeleteArgs, "key">): Promise<void> {
91
+ const { key } = args;
92
+ await this.db!.delete(this.storeName, key);
93
+ }
94
+
95
+ public async clear(): Promise<void> {
96
+ await this.db!.clear(this.storeName);
97
+ }
98
+
99
+ public getWritable(args: Pick<IStorage.GetWritableArgs, "key">): WritableStream<Uint8Array> {
100
+ const { key } = args;
101
+ const chunks: Uint8Array[] = [];
102
+
103
+ // IndexedDB にはネイティブなファイルストリームがないため、書き込まれたチャンクをメモリに保持し、クローズ時にまとめて put します。
104
+ return new WritableStream({
105
+ write: (chunk) => {
106
+ chunks.push(chunk);
107
+ },
108
+ close: async () => {
109
+ const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
110
+ const result = new Uint8Array(totalLength);
111
+ let offset = 0;
112
+
113
+ for (const chunk of chunks) {
114
+ result.set(chunk, offset);
115
+ offset += chunk.length;
116
+ }
117
+
118
+ await this.db!.put(this.storeName, result, key);
119
+ },
120
+ });
121
+ }
122
+
123
+ public getReadable(args: Pick<IStorage.GetReadableArgs, "key">): ReadableStream<Uint8Array> {
124
+ const { key } = args;
125
+
126
+ return new ReadableStream({
127
+ pull: async (controller) => {
128
+ // データ全体をメモリにロードしてから ReadableStream に流し込みます。
129
+ const data = await this.read({ key });
130
+ controller.enqueue(data);
131
+ controller.close();
132
+ },
133
+ });
134
+ }
135
+ }
package/README.md DELETED
@@ -1,45 +0,0 @@
1
- # @unikvs/indexeddb
2
-
3
- ## ⚠️ IMPORTANT NOTICE ⚠️
4
-
5
- **This package is created solely for the purpose of setting up OIDC (OpenID Connect) trusted publishing with npm.**
6
-
7
- This is **NOT** a functional package and contains **NO** code or functionality beyond the OIDC setup configuration.
8
-
9
- ## Purpose
10
-
11
- This package exists to:
12
- 1. Configure OIDC trusted publishing for the package name `@unikvs/indexeddb`
13
- 2. Enable secure, token-less publishing from CI/CD workflows
14
- 3. Establish provenance for packages published under this name
15
-
16
- ## What is OIDC Trusted Publishing?
17
-
18
- OIDC trusted publishing allows package maintainers to publish packages directly from their CI/CD workflows without needing to manage npm access tokens. Instead, it uses OpenID Connect to establish trust between the CI/CD provider (like GitHub Actions) and npm.
19
-
20
- ## Setup Instructions
21
-
22
- To properly configure OIDC trusted publishing for this package:
23
-
24
- 1. Go to [npmjs.com](https://www.npmjs.com/) and navigate to your package settings
25
- 2. Configure the trusted publisher (e.g., GitHub Actions)
26
- 3. Specify the repository and workflow that should be allowed to publish
27
- 4. Use the configured workflow to publish your actual package
28
-
29
- ## DO NOT USE THIS PACKAGE
30
-
31
- This package is a placeholder for OIDC configuration only. It:
32
- - Contains no executable code
33
- - Provides no functionality
34
- - Should not be installed as a dependency
35
- - Exists only for administrative purposes
36
-
37
- ## More Information
38
-
39
- For more details about npm's trusted publishing feature, see:
40
- - [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
41
- - [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
42
-
43
- ---
44
-
45
- **Maintained for OIDC setup purposes only**