@acanthis-dec/storage 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2026 ConstasJ
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # @acanthis-dec/storage
2
+
3
+ [中文文档](./README.zh-CN.md) | [Workspace README](../../README.md)
4
+
5
+ Persistence package for Acanthis. It combines SQLite/libSQL access, Drizzle migrations, filesystem storage, cache records, cover data, normalized metadata, and database-backed cookies.
6
+
7
+ ## Installation
8
+
9
+ Workspace usage:
10
+
11
+ ```powershell
12
+ pnpm install --frozen-lockfile
13
+ pnpm --filter=@acanthis-dec/storage run check-types
14
+ pnpm --filter=@acanthis-dec/storage run build
15
+ ```
16
+
17
+ Import from workspace source or the published ESM package:
18
+
19
+ ```ts
20
+ import { StorageService } from "@acanthis-dec/storage";
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```ts
26
+ import { StorageService } from "@acanthis-dec/storage";
27
+
28
+ const storage = new StorageService({
29
+ dataDir: "data",
30
+ db: {
31
+ path: "data/data.db",
32
+ migrations: { directory: "migrations" },
33
+ },
34
+ });
35
+
36
+ const hash = await storage.setNovelContent("<p>Hello</p>");
37
+ const content = await storage.getNovelContent(hash);
38
+ const cookieStore = storage.getCookieStore();
39
+
40
+ await storage.close();
41
+ ```
42
+
43
+ ## API
44
+
45
+ ### `StorageService`
46
+
47
+ - `getNovelContent(hash)` and `setNovelContent(content)` read and write content files by hash.
48
+ - `getCoverData(type, platform, platformId)` and `setCoverData(...)` manage cover binaries.
49
+ - `addSearchResult(keyword, platform, results)` and `searchNovels(keyword, platform)` cache search results.
50
+ - `getNovelCache(platform, platformId)` and `addNovelCache(novel)` manage normalized novel metadata.
51
+ - `getVolumeMeta(platform, platformId)` reads volume metadata.
52
+ - `getChapterFromTitle(title)` and `getChapterFromId(platform, platformId)` read chapter metadata.
53
+ - `addNovelContentHash(platform, chapterId, contentHash)` links chapter metadata to stored content.
54
+ - `getCookieStore()` returns a database-backed cookie store for browser-fetch integration.
55
+ - `getCache(key, schema)` and `setCache(key, value)` store typed small cache entries.
56
+ - `close(logger?)` closes the database connection.
57
+
58
+ ### Other exports
59
+
60
+ - `DatabaseService` and `DatabaseOptions` for lower-level database access.
61
+ - `FSStorageService` for filesystem-backed content and cover storage.
62
+ - `DatabaseCookieStore` for cookie persistence.
63
+
64
+ Keep `migrations/` aligned with database schema changes because the API server Docker image copies those migration files at runtime.
@@ -0,0 +1,64 @@
1
+ # @acanthis-dec/storage
2
+
3
+ [English README](./README.md) | [工作区 README](../../README.zh-CN.md)
4
+
5
+ Acanthis 的持久化包。它组合 SQLite/libSQL 访问、Drizzle migration、文件系统存储、缓存记录、封面数据、统一元数据和数据库 Cookie 存储。
6
+
7
+ ## 安装
8
+
9
+ 工作区内使用:
10
+
11
+ ```powershell
12
+ pnpm install --frozen-lockfile
13
+ pnpm --filter=@acanthis-dec/storage run check-types
14
+ pnpm --filter=@acanthis-dec/storage run build
15
+ ```
16
+
17
+ 从 workspace 源码或发布后的 ESM 包导入:
18
+
19
+ ```ts
20
+ import { StorageService } from "@acanthis-dec/storage";
21
+ ```
22
+
23
+ ## 用法
24
+
25
+ ```ts
26
+ import { StorageService } from "@acanthis-dec/storage";
27
+
28
+ const storage = new StorageService({
29
+ dataDir: "data",
30
+ db: {
31
+ path: "data/data.db",
32
+ migrations: { directory: "migrations" },
33
+ },
34
+ });
35
+
36
+ const hash = await storage.setNovelContent("<p>Hello</p>");
37
+ const content = await storage.getNovelContent(hash);
38
+ const cookieStore = storage.getCookieStore();
39
+
40
+ await storage.close();
41
+ ```
42
+
43
+ ## API
44
+
45
+ ### `StorageService`
46
+
47
+ - `getNovelContent(hash)` 与 `setNovelContent(content)` 按 hash 读写正文文件。
48
+ - `getCoverData(type, platform, platformId)` 与 `setCoverData(...)` 管理封面二进制数据。
49
+ - `addSearchResult(keyword, platform, results)` 与 `searchNovels(keyword, platform)` 缓存搜索结果。
50
+ - `getNovelCache(platform, platformId)` 与 `addNovelCache(novel)` 管理统一作品元数据。
51
+ - `getVolumeMeta(platform, platformId)` 读取分卷元数据。
52
+ - `getChapterFromTitle(title)` 与 `getChapterFromId(platform, platformId)` 读取章节元数据。
53
+ - `addNovelContentHash(platform, chapterId, contentHash)` 将章节元数据关联到已保存正文。
54
+ - `getCookieStore()` 返回供 browser-fetch 集成的数据库 Cookie store。
55
+ - `getCache(key, schema)` 与 `setCache(key, value)` 存取带类型校验的小型缓存项。
56
+ - `close(logger?)` 关闭数据库连接。
57
+
58
+ ### 其他导出
59
+
60
+ - `DatabaseService` 与 `DatabaseOptions` 用于较底层的数据库访问。
61
+ - `FSStorageService` 用于文件系统正文与封面存储。
62
+ - `DatabaseCookieStore` 用于 Cookie 持久化。
63
+
64
+ 数据库 schema 变更时需保持 `migrations/` 同步,因为 API server Docker 镜像会在运行时复制这些 migration 文件。