renkei-storage-sqlite 0.3.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 +202 -0
- package/README.md +26 -0
- package/dist/index.d.ts +70 -0
- package/dist/index.js +303 -0
- package/dist/index.js.map +1 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Achraf Reyani
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# renkei-storage-sqlite
|
|
2
|
+
|
|
3
|
+
renkei(連携)の SQLite ストレージ。Node 22.13+ の組み込み `node:sqlite` を使うので**依存ゼロ、ネイティブビルドなし、DB サーバー不要** — ファイル 1 つで動きます(WAL モード、外部キー有効、起動時に自動マイグレーション)。`renkei-server` は `DATABASE_URL=sqlite:./data/renkei.db` で自動的にこれを使います。
|
|
4
|
+
|
|
5
|
+
SQLite storage for renkei (連携). Built on Node 22.13+'s bundled `node:sqlite`: **zero dependencies, no native build, no database server** — one file on disk (WAL mode, foreign keys on, migrations applied on boot). `renkei-server` picks it up with `DATABASE_URL=sqlite:./data/renkei.db`.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { createSqliteStorage } from 'renkei-storage-sqlite';
|
|
9
|
+
|
|
10
|
+
const storage = createSqliteStorage({ filename: './data/renkei.db' }); // or ':memory:'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`better-sqlite3` や Bun の `bun:sqlite` を使う場合は、開いた DB をそのまま渡します。
|
|
14
|
+
With `better-sqlite3` or Bun's `bun:sqlite`, pass the opened database as the driver:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import Database from 'better-sqlite3';
|
|
18
|
+
import { createSqliteDriverStorage } from 'renkei-storage-sqlite';
|
|
19
|
+
|
|
20
|
+
const storage = createSqliteDriverStorage(new Database('./data/renkei.db'));
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Node 22.5–22.12 では `node --experimental-sqlite` が必要です。
|
|
24
|
+
On Node 22.5–22.12 start Node with `--experimental-sqlite`.
|
|
25
|
+
|
|
26
|
+
ドキュメント / Docs: <https://github.com/AchrafReyani/renkei> · Apache-2.0
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Storage } from 'renkei-core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The slice of a synchronous SQLite binding that this adapter needs. Node's
|
|
5
|
+
* built-in `node:sqlite` (`DatabaseSync`), `better-sqlite3` and Bun's
|
|
6
|
+
* `bun:sqlite` all satisfy it structurally, so any of them can be passed to
|
|
7
|
+
* `createSqliteDriverStorage()` without a wrapper.
|
|
8
|
+
*/
|
|
9
|
+
interface SqliteDriver {
|
|
10
|
+
/** Run one or more statements with no parameters (DDL, PRAGMAs, BEGIN/COMMIT). */
|
|
11
|
+
exec(sql: string): unknown;
|
|
12
|
+
prepare(sql: string): SqliteStatement;
|
|
13
|
+
close?(): unknown;
|
|
14
|
+
}
|
|
15
|
+
interface SqliteStatement {
|
|
16
|
+
run(...params: SqliteValue[]): unknown;
|
|
17
|
+
get(...params: SqliteValue[]): unknown;
|
|
18
|
+
all(...params: SqliteValue[]): unknown;
|
|
19
|
+
}
|
|
20
|
+
/** What SQLite can bind directly. Booleans, Dates and JSON are converted by the adapter. */
|
|
21
|
+
type SqliteValue = null | number | bigint | string | Uint8Array;
|
|
22
|
+
type Row = Record<string, unknown>;
|
|
23
|
+
|
|
24
|
+
interface SqliteStorageOptions {
|
|
25
|
+
now?: () => Date;
|
|
26
|
+
/** Run the bundled migrations in `init()`. Default true. */
|
|
27
|
+
autoMigrate?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Wrap any synchronous SQLite binding (see `SqliteDriver`) as renkei Storage.
|
|
31
|
+
* `init()` migrates (unless `autoMigrate: false`), `close()` closes the driver.
|
|
32
|
+
*/
|
|
33
|
+
declare function createSqliteDriverStorage(driver: SqliteDriver, options?: SqliteStorageOptions): Storage;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Schema, one entry per version. Applied in order by `migrateSqlite()`, which
|
|
37
|
+
* tracks the current version in `PRAGMA user_version`. Append, never edit.
|
|
38
|
+
*
|
|
39
|
+
* Column names match `renkei-storage-postgres`; only the types differ:
|
|
40
|
+
* timestamps are epoch milliseconds (INTEGER), booleans are 0/1, JSON is TEXT.
|
|
41
|
+
* Tables are prefixed `renkei_` so the file can be shared with an application.
|
|
42
|
+
*/
|
|
43
|
+
declare const migrations: readonly string[];
|
|
44
|
+
/** The schema version a fully migrated database reports in `PRAGMA user_version`. */
|
|
45
|
+
declare const schemaVersion: number;
|
|
46
|
+
/**
|
|
47
|
+
* Bring the database up to `schemaVersion`. Idempotent: a database that is
|
|
48
|
+
* already current is left untouched, so this is safe to run on every boot.
|
|
49
|
+
* Each pending version runs inside one transaction.
|
|
50
|
+
*/
|
|
51
|
+
declare function migrateSqlite(driver: SqliteDriver): void;
|
|
52
|
+
declare function readUserVersion(driver: SqliteDriver): number;
|
|
53
|
+
|
|
54
|
+
interface SqliteStorageConfig extends SqliteStorageOptions {
|
|
55
|
+
/** File path, or `:memory:` for a throwaway database. Parent directories are created. */
|
|
56
|
+
filename: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Storage backed by Node's built-in `node:sqlite` (Node 22.13+; on 22.5–22.12
|
|
60
|
+
* start Node with `--experimental-sqlite`). No native module to compile, no
|
|
61
|
+
* separate database server: one file on disk, WAL mode, foreign keys on.
|
|
62
|
+
*
|
|
63
|
+
* On Bun or with `better-sqlite3`, open the database yourself and pass it to
|
|
64
|
+
* `createSqliteDriverStorage()` instead — the driver interface is the same.
|
|
65
|
+
*/
|
|
66
|
+
declare function createSqliteStorage(config: SqliteStorageConfig): Storage;
|
|
67
|
+
/** Open a `node:sqlite` database with renkei's pragmas applied. */
|
|
68
|
+
declare function openNodeSqlite(filename: string): SqliteDriver;
|
|
69
|
+
|
|
70
|
+
export { type Row, type SqliteDriver, type SqliteStatement, type SqliteStorageConfig, type SqliteStorageOptions, type SqliteValue, createSqliteDriverStorage, createSqliteStorage, migrateSqlite, migrations, openNodeSqlite, readUserVersion, schemaVersion };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { mkdirSync } from "fs";
|
|
3
|
+
import { dirname } from "path";
|
|
4
|
+
|
|
5
|
+
// src/schema.ts
|
|
6
|
+
var migrations = [
|
|
7
|
+
`
|
|
8
|
+
CREATE TABLE IF NOT EXISTS renkei_identity (
|
|
9
|
+
sub TEXT PRIMARY KEY NOT NULL,
|
|
10
|
+
email TEXT,
|
|
11
|
+
email_verified INTEGER,
|
|
12
|
+
display_name TEXT,
|
|
13
|
+
picture_url TEXT,
|
|
14
|
+
created_at INTEGER NOT NULL,
|
|
15
|
+
updated_at INTEGER NOT NULL
|
|
16
|
+
);
|
|
17
|
+
CREATE TABLE IF NOT EXISTS renkei_line_account (
|
|
18
|
+
identity_sub TEXT NOT NULL REFERENCES renkei_identity(sub) ON DELETE CASCADE,
|
|
19
|
+
channel_id TEXT NOT NULL,
|
|
20
|
+
line_user_id TEXT NOT NULL,
|
|
21
|
+
kind TEXT NOT NULL,
|
|
22
|
+
friend INTEGER,
|
|
23
|
+
friend_checked_at INTEGER,
|
|
24
|
+
raw_profile TEXT,
|
|
25
|
+
created_at INTEGER NOT NULL,
|
|
26
|
+
updated_at INTEGER NOT NULL,
|
|
27
|
+
PRIMARY KEY (channel_id, line_user_id)
|
|
28
|
+
);
|
|
29
|
+
CREATE INDEX IF NOT EXISTS renkei_line_account_identity_idx ON renkei_line_account (identity_sub);
|
|
30
|
+
CREATE TABLE IF NOT EXISTS renkei_payload (
|
|
31
|
+
model TEXT NOT NULL,
|
|
32
|
+
id TEXT NOT NULL,
|
|
33
|
+
payload TEXT NOT NULL,
|
|
34
|
+
uid TEXT,
|
|
35
|
+
user_code TEXT,
|
|
36
|
+
grant_id TEXT,
|
|
37
|
+
expires_at INTEGER,
|
|
38
|
+
consumed_at INTEGER,
|
|
39
|
+
PRIMARY KEY (model, id)
|
|
40
|
+
);
|
|
41
|
+
CREATE INDEX IF NOT EXISTS renkei_payload_uid_idx ON renkei_payload (model, uid);
|
|
42
|
+
CREATE INDEX IF NOT EXISTS renkei_payload_user_code_idx ON renkei_payload (model, user_code);
|
|
43
|
+
CREATE INDEX IF NOT EXISTS renkei_payload_grant_idx ON renkei_payload (model, grant_id);
|
|
44
|
+
CREATE INDEX IF NOT EXISTS renkei_payload_expires_idx ON renkei_payload (expires_at);
|
|
45
|
+
`
|
|
46
|
+
];
|
|
47
|
+
var schemaVersion = migrations.length;
|
|
48
|
+
function migrateSqlite(driver) {
|
|
49
|
+
const current = readUserVersion(driver);
|
|
50
|
+
for (let v = current; v < migrations.length; v++) {
|
|
51
|
+
driver.exec("BEGIN");
|
|
52
|
+
try {
|
|
53
|
+
driver.exec(migrations[v]);
|
|
54
|
+
driver.exec(`PRAGMA user_version = ${v + 1}`);
|
|
55
|
+
driver.exec("COMMIT");
|
|
56
|
+
} catch (err) {
|
|
57
|
+
driver.exec("ROLLBACK");
|
|
58
|
+
throw err;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function readUserVersion(driver) {
|
|
63
|
+
const row = driver.prepare("PRAGMA user_version").get();
|
|
64
|
+
return Number(row?.user_version ?? 0);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// src/storage.ts
|
|
68
|
+
function createSqliteDriverStorage(driver, options = {}) {
|
|
69
|
+
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
70
|
+
const storage = {
|
|
71
|
+
identities: new SqliteIdentityStore(driver, now),
|
|
72
|
+
payloads: new SqlitePayloadStore(driver, now),
|
|
73
|
+
init: async () => {
|
|
74
|
+
if (options.autoMigrate !== false) migrateSqlite(driver);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
if (driver.close) {
|
|
78
|
+
storage.close = async () => {
|
|
79
|
+
driver.close?.();
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return storage;
|
|
83
|
+
}
|
|
84
|
+
var ms = (d) => d.getTime();
|
|
85
|
+
var date = (v) => new Date(Number(v));
|
|
86
|
+
var bool = (v) => v === void 0 ? null : v ? 1 : 0;
|
|
87
|
+
var json = (v) => v === void 0 ? null : JSON.stringify(v);
|
|
88
|
+
var names = (cols) => cols.map(([c]) => c).join(", ");
|
|
89
|
+
var marks = (cols) => cols.map(() => "?").join(", ");
|
|
90
|
+
var values = (cols) => cols.map(([, v]) => v);
|
|
91
|
+
function toIdentity(r) {
|
|
92
|
+
return {
|
|
93
|
+
sub: r.sub,
|
|
94
|
+
createdAt: date(r.created_at),
|
|
95
|
+
updatedAt: date(r.updated_at),
|
|
96
|
+
...r.email != null ? { email: r.email } : {},
|
|
97
|
+
...r.email_verified != null ? { emailVerified: Number(r.email_verified) === 1 } : {},
|
|
98
|
+
...r.display_name != null ? { displayName: r.display_name } : {},
|
|
99
|
+
...r.picture_url != null ? { pictureUrl: r.picture_url } : {}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function toAccount(r) {
|
|
103
|
+
return {
|
|
104
|
+
identitySub: r.identity_sub,
|
|
105
|
+
channelId: r.channel_id,
|
|
106
|
+
lineUserId: r.line_user_id,
|
|
107
|
+
kind: r.kind,
|
|
108
|
+
createdAt: date(r.created_at),
|
|
109
|
+
updatedAt: date(r.updated_at),
|
|
110
|
+
...r.friend != null ? { friend: Number(r.friend) === 1 } : {},
|
|
111
|
+
...r.friend_checked_at != null ? { friendCheckedAt: date(r.friend_checked_at) } : {},
|
|
112
|
+
...r.raw_profile != null ? { rawProfile: JSON.parse(r.raw_profile) } : {}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function identityColumns(patch) {
|
|
116
|
+
const cols = [];
|
|
117
|
+
if (patch.email !== void 0) cols.push(["email", patch.email]);
|
|
118
|
+
if (patch.emailVerified !== void 0) cols.push(["email_verified", bool(patch.emailVerified)]);
|
|
119
|
+
if (patch.displayName !== void 0) cols.push(["display_name", patch.displayName]);
|
|
120
|
+
if (patch.pictureUrl !== void 0) cols.push(["picture_url", patch.pictureUrl]);
|
|
121
|
+
return cols;
|
|
122
|
+
}
|
|
123
|
+
var SqliteIdentityStore = class {
|
|
124
|
+
constructor(db, now) {
|
|
125
|
+
this.db = db;
|
|
126
|
+
this.now = now;
|
|
127
|
+
}
|
|
128
|
+
db;
|
|
129
|
+
now;
|
|
130
|
+
async findIdentity(sub) {
|
|
131
|
+
const row = this.db.prepare("SELECT * FROM renkei_identity WHERE sub = ?").get(sub);
|
|
132
|
+
return row ? toIdentity(row) : void 0;
|
|
133
|
+
}
|
|
134
|
+
async findIdentityByLineAccount(channelId, lineUserId) {
|
|
135
|
+
const row = this.db.prepare(
|
|
136
|
+
`SELECT i.* FROM renkei_line_account a
|
|
137
|
+
JOIN renkei_identity i ON i.sub = a.identity_sub
|
|
138
|
+
WHERE a.channel_id = ? AND a.line_user_id = ?`
|
|
139
|
+
).get(channelId, lineUserId);
|
|
140
|
+
return row ? toIdentity(row) : void 0;
|
|
141
|
+
}
|
|
142
|
+
async createIdentity(init) {
|
|
143
|
+
const t = ms(this.now());
|
|
144
|
+
const cols = [
|
|
145
|
+
["sub", init.sub],
|
|
146
|
+
...identityColumns(init),
|
|
147
|
+
["created_at", t],
|
|
148
|
+
["updated_at", t]
|
|
149
|
+
];
|
|
150
|
+
this.db.prepare(`INSERT INTO renkei_identity (${names(cols)}) VALUES (${marks(cols)})`).run(...values(cols));
|
|
151
|
+
const created = await this.findIdentity(init.sub);
|
|
152
|
+
if (!created) throw new Error("insert returned no row");
|
|
153
|
+
return created;
|
|
154
|
+
}
|
|
155
|
+
async updateIdentity(sub, patch) {
|
|
156
|
+
const cols = [...identityColumns(patch), ["updated_at", ms(this.now())]];
|
|
157
|
+
const set = cols.map(([c]) => `${c} = ?`).join(", ");
|
|
158
|
+
this.db.prepare(`UPDATE renkei_identity SET ${set} WHERE sub = ?`).run(...values(cols), sub);
|
|
159
|
+
const updated = await this.findIdentity(sub);
|
|
160
|
+
if (!updated) throw new Error(`identity ${sub} not found`);
|
|
161
|
+
return updated;
|
|
162
|
+
}
|
|
163
|
+
async upsertLineAccount(record) {
|
|
164
|
+
const t = ms(this.now());
|
|
165
|
+
const update = [
|
|
166
|
+
["identity_sub", record.identitySub],
|
|
167
|
+
["kind", record.kind],
|
|
168
|
+
["updated_at", t]
|
|
169
|
+
];
|
|
170
|
+
if (record.friend !== void 0) update.push(["friend", bool(record.friend)]);
|
|
171
|
+
if (record.friendCheckedAt !== void 0) {
|
|
172
|
+
update.push(["friend_checked_at", ms(record.friendCheckedAt)]);
|
|
173
|
+
}
|
|
174
|
+
if (record.rawProfile !== void 0) update.push(["raw_profile", json(record.rawProfile)]);
|
|
175
|
+
const insert = [
|
|
176
|
+
["channel_id", record.channelId],
|
|
177
|
+
["line_user_id", record.lineUserId],
|
|
178
|
+
["created_at", t],
|
|
179
|
+
...update
|
|
180
|
+
];
|
|
181
|
+
const set = update.map(([c]) => `${c} = excluded.${c}`).join(", ");
|
|
182
|
+
this.db.prepare(
|
|
183
|
+
`INSERT INTO renkei_line_account (${names(insert)}) VALUES (${marks(insert)})
|
|
184
|
+
ON CONFLICT (channel_id, line_user_id) DO UPDATE SET ${set}`
|
|
185
|
+
).run(...values(insert));
|
|
186
|
+
const row = await this.findLineAccount(record.channelId, record.lineUserId);
|
|
187
|
+
if (!row) throw new Error("upsert returned no row");
|
|
188
|
+
return row;
|
|
189
|
+
}
|
|
190
|
+
async listLineAccounts(sub) {
|
|
191
|
+
const rows = this.db.prepare("SELECT * FROM renkei_line_account WHERE identity_sub = ?").all(sub);
|
|
192
|
+
return rows.map(toAccount);
|
|
193
|
+
}
|
|
194
|
+
async findLineAccount(channelId, lineUserId) {
|
|
195
|
+
const row = this.db.prepare("SELECT * FROM renkei_line_account WHERE channel_id = ? AND line_user_id = ?").get(channelId, lineUserId);
|
|
196
|
+
return row ? toAccount(row) : void 0;
|
|
197
|
+
}
|
|
198
|
+
async setFriendship(channelId, lineUserId, friend, at = this.now()) {
|
|
199
|
+
this.db.prepare(
|
|
200
|
+
`UPDATE renkei_line_account SET friend = ?, friend_checked_at = ?, updated_at = ?
|
|
201
|
+
WHERE channel_id = ? AND line_user_id = ?`
|
|
202
|
+
).run(bool(friend), ms(at), ms(this.now()), channelId, lineUserId);
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
var NOT_EXPIRED = "(expires_at IS NULL OR expires_at > ?)";
|
|
206
|
+
var SqlitePayloadStore = class {
|
|
207
|
+
constructor(db, now) {
|
|
208
|
+
this.db = db;
|
|
209
|
+
this.now = now;
|
|
210
|
+
}
|
|
211
|
+
db;
|
|
212
|
+
now;
|
|
213
|
+
toRecord(row) {
|
|
214
|
+
const p = JSON.parse(row.payload);
|
|
215
|
+
if (row.consumed_at != null) p.consumed = Math.floor(Number(row.consumed_at) / 1e3);
|
|
216
|
+
return p;
|
|
217
|
+
}
|
|
218
|
+
findOne(column, model, value) {
|
|
219
|
+
const row = this.db.prepare(`SELECT * FROM renkei_payload WHERE model = ? AND ${column} = ? AND ${NOT_EXPIRED}`).get(model, value, ms(this.now()));
|
|
220
|
+
return row ? this.toRecord(row) : void 0;
|
|
221
|
+
}
|
|
222
|
+
async upsert(model, id, payload, expiresInSeconds) {
|
|
223
|
+
const expiresAt = expiresInSeconds !== void 0 ? ms(this.now()) + expiresInSeconds * 1e3 : null;
|
|
224
|
+
this.db.prepare(
|
|
225
|
+
`INSERT INTO renkei_payload (model, id, payload, uid, user_code, grant_id, expires_at, consumed_at)
|
|
226
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, NULL)
|
|
227
|
+
ON CONFLICT (model, id) DO UPDATE SET
|
|
228
|
+
payload = excluded.payload, uid = excluded.uid, user_code = excluded.user_code,
|
|
229
|
+
grant_id = excluded.grant_id, expires_at = excluded.expires_at, consumed_at = NULL`
|
|
230
|
+
).run(
|
|
231
|
+
model,
|
|
232
|
+
id,
|
|
233
|
+
JSON.stringify(payload),
|
|
234
|
+
typeof payload.uid === "string" ? payload.uid : null,
|
|
235
|
+
typeof payload.userCode === "string" ? payload.userCode : null,
|
|
236
|
+
typeof payload.grantId === "string" ? payload.grantId : null,
|
|
237
|
+
expiresAt
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
async find(model, id) {
|
|
241
|
+
return this.findOne("id", model, id);
|
|
242
|
+
}
|
|
243
|
+
async findByUid(model, uid) {
|
|
244
|
+
return this.findOne("uid", model, uid);
|
|
245
|
+
}
|
|
246
|
+
async findByUserCode(model, userCode) {
|
|
247
|
+
return this.findOne("user_code", model, userCode);
|
|
248
|
+
}
|
|
249
|
+
async consume(model, id) {
|
|
250
|
+
this.db.prepare("UPDATE renkei_payload SET consumed_at = ? WHERE model = ? AND id = ?").run(ms(this.now()), model, id);
|
|
251
|
+
}
|
|
252
|
+
async destroy(model, id) {
|
|
253
|
+
this.db.prepare("DELETE FROM renkei_payload WHERE model = ? AND id = ?").run(model, id);
|
|
254
|
+
}
|
|
255
|
+
async revokeByGrantId(model, grantId) {
|
|
256
|
+
this.db.prepare("DELETE FROM renkei_payload WHERE model = ? AND grant_id = ?").run(model, grantId);
|
|
257
|
+
}
|
|
258
|
+
/** Housekeeping: delete expired rows. Call from a cron or on an interval. */
|
|
259
|
+
async purgeExpired() {
|
|
260
|
+
this.db.prepare("DELETE FROM renkei_payload WHERE expires_at <= ?").run(ms(this.now()));
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
// src/index.ts
|
|
265
|
+
function createSqliteStorage(config) {
|
|
266
|
+
const { filename, ...options } = config;
|
|
267
|
+
return createSqliteDriverStorage(openNodeSqlite(filename), options);
|
|
268
|
+
}
|
|
269
|
+
function openNodeSqlite(filename) {
|
|
270
|
+
const sqlite = loadNodeSqlite();
|
|
271
|
+
if (!sqlite) {
|
|
272
|
+
throw new Error(
|
|
273
|
+
"renkei-storage-sqlite: node:sqlite is not available. Use Node 22.13 or newer (or run `node --experimental-sqlite` on 22.5-22.12), or pass your own driver to createSqliteDriverStorage()."
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
const inMemory = filename === ":memory:" || filename === "";
|
|
277
|
+
if (!inMemory) mkdirSync(dirname(filename), { recursive: true });
|
|
278
|
+
const db = new sqlite.DatabaseSync(filename);
|
|
279
|
+
db.exec("PRAGMA foreign_keys = ON");
|
|
280
|
+
db.exec("PRAGMA busy_timeout = 5000");
|
|
281
|
+
if (!inMemory) {
|
|
282
|
+
db.exec("PRAGMA journal_mode = WAL");
|
|
283
|
+
db.exec("PRAGMA synchronous = NORMAL");
|
|
284
|
+
}
|
|
285
|
+
return db;
|
|
286
|
+
}
|
|
287
|
+
function loadNodeSqlite() {
|
|
288
|
+
try {
|
|
289
|
+
return process.getBuiltinModule("node:sqlite");
|
|
290
|
+
} catch {
|
|
291
|
+
return void 0;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
export {
|
|
295
|
+
createSqliteDriverStorage,
|
|
296
|
+
createSqliteStorage,
|
|
297
|
+
migrateSqlite,
|
|
298
|
+
migrations,
|
|
299
|
+
openNodeSqlite,
|
|
300
|
+
readUserVersion,
|
|
301
|
+
schemaVersion
|
|
302
|
+
};
|
|
303
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/schema.ts","../src/storage.ts"],"sourcesContent":["import { mkdirSync } from 'node:fs';\nimport { dirname } from 'node:path';\nimport type { Storage } from 'renkei-core';\nimport type { SqliteDriver } from './driver.js';\nimport { createSqliteDriverStorage, type SqliteStorageOptions } from './storage.js';\n\nexport type { Row, SqliteDriver, SqliteStatement, SqliteValue } from './driver.js';\nexport { migrateSqlite, migrations, readUserVersion, schemaVersion } from './schema.js';\nexport { createSqliteDriverStorage, type SqliteStorageOptions } from './storage.js';\n\nexport interface SqliteStorageConfig extends SqliteStorageOptions {\n /** File path, or `:memory:` for a throwaway database. Parent directories are created. */\n filename: string;\n}\n\n/**\n * Storage backed by Node's built-in `node:sqlite` (Node 22.13+; on 22.5–22.12\n * start Node with `--experimental-sqlite`). No native module to compile, no\n * separate database server: one file on disk, WAL mode, foreign keys on.\n *\n * On Bun or with `better-sqlite3`, open the database yourself and pass it to\n * `createSqliteDriverStorage()` instead — the driver interface is the same.\n */\nexport function createSqliteStorage(config: SqliteStorageConfig): Storage {\n const { filename, ...options } = config;\n return createSqliteDriverStorage(openNodeSqlite(filename), options);\n}\n\n/** Open a `node:sqlite` database with renkei's pragmas applied. */\nexport function openNodeSqlite(filename: string): SqliteDriver {\n const sqlite = loadNodeSqlite();\n if (!sqlite) {\n throw new Error(\n 'renkei-storage-sqlite: node:sqlite is not available. Use Node 22.13 or newer ' +\n '(or run `node --experimental-sqlite` on 22.5-22.12), or pass your own driver to ' +\n 'createSqliteDriverStorage().',\n );\n }\n const inMemory = filename === ':memory:' || filename === '';\n if (!inMemory) mkdirSync(dirname(filename), { recursive: true });\n const db = new sqlite.DatabaseSync(filename);\n db.exec('PRAGMA foreign_keys = ON');\n db.exec('PRAGMA busy_timeout = 5000');\n if (!inMemory) {\n db.exec('PRAGMA journal_mode = WAL');\n db.exec('PRAGMA synchronous = NORMAL');\n }\n return db;\n}\n\n/** Synchronous, import-free lookup so this module loads on runtimes without node:sqlite. */\nfunction loadNodeSqlite(): typeof import('node:sqlite') | undefined {\n try {\n return process.getBuiltinModule('node:sqlite') as typeof import('node:sqlite') | undefined;\n } catch {\n return undefined;\n }\n}\n","import type { SqliteDriver } from './driver.js';\n\n/**\n * Schema, one entry per version. Applied in order by `migrateSqlite()`, which\n * tracks the current version in `PRAGMA user_version`. Append, never edit.\n *\n * Column names match `renkei-storage-postgres`; only the types differ:\n * timestamps are epoch milliseconds (INTEGER), booleans are 0/1, JSON is TEXT.\n * Tables are prefixed `renkei_` so the file can be shared with an application.\n */\nexport const migrations: readonly string[] = [\n `\nCREATE TABLE IF NOT EXISTS renkei_identity (\n sub TEXT PRIMARY KEY NOT NULL,\n email TEXT,\n email_verified INTEGER,\n display_name TEXT,\n picture_url TEXT,\n created_at INTEGER NOT NULL,\n updated_at INTEGER NOT NULL\n);\nCREATE TABLE IF NOT EXISTS renkei_line_account (\n identity_sub TEXT NOT NULL REFERENCES renkei_identity(sub) ON DELETE CASCADE,\n channel_id TEXT NOT NULL,\n line_user_id TEXT NOT NULL,\n kind TEXT NOT NULL,\n friend INTEGER,\n friend_checked_at INTEGER,\n raw_profile TEXT,\n created_at INTEGER NOT NULL,\n updated_at INTEGER NOT NULL,\n PRIMARY KEY (channel_id, line_user_id)\n);\nCREATE INDEX IF NOT EXISTS renkei_line_account_identity_idx ON renkei_line_account (identity_sub);\nCREATE TABLE IF NOT EXISTS renkei_payload (\n model TEXT NOT NULL,\n id TEXT NOT NULL,\n payload TEXT NOT NULL,\n uid TEXT,\n user_code TEXT,\n grant_id TEXT,\n expires_at INTEGER,\n consumed_at INTEGER,\n PRIMARY KEY (model, id)\n);\nCREATE INDEX IF NOT EXISTS renkei_payload_uid_idx ON renkei_payload (model, uid);\nCREATE INDEX IF NOT EXISTS renkei_payload_user_code_idx ON renkei_payload (model, user_code);\nCREATE INDEX IF NOT EXISTS renkei_payload_grant_idx ON renkei_payload (model, grant_id);\nCREATE INDEX IF NOT EXISTS renkei_payload_expires_idx ON renkei_payload (expires_at);\n`,\n];\n\n/** The schema version a fully migrated database reports in `PRAGMA user_version`. */\nexport const schemaVersion = migrations.length;\n\n/**\n * Bring the database up to `schemaVersion`. Idempotent: a database that is\n * already current is left untouched, so this is safe to run on every boot.\n * Each pending version runs inside one transaction.\n */\nexport function migrateSqlite(driver: SqliteDriver): void {\n const current = readUserVersion(driver);\n for (let v = current; v < migrations.length; v++) {\n driver.exec('BEGIN');\n try {\n driver.exec(migrations[v] as string);\n driver.exec(`PRAGMA user_version = ${v + 1}`);\n driver.exec('COMMIT');\n } catch (err) {\n driver.exec('ROLLBACK');\n throw err;\n }\n }\n}\n\nexport function readUserVersion(driver: SqliteDriver): number {\n const row = driver.prepare('PRAGMA user_version').get() as\n | { user_version?: number | bigint }\n | undefined;\n return Number(row?.user_version ?? 0);\n}\n","import type {\n Identity,\n IdentityPatch,\n IdentityStore,\n LineAccount,\n LineAccountKind,\n LineAccountUpsert,\n PayloadRecord,\n PayloadStore,\n Storage,\n} from 'renkei-core';\nimport type { Row, SqliteDriver, SqliteValue } from './driver.js';\nimport { migrateSqlite } from './schema.js';\n\nexport interface SqliteStorageOptions {\n now?: () => Date;\n /** Run the bundled migrations in `init()`. Default true. */\n autoMigrate?: boolean;\n}\n\n/**\n * Wrap any synchronous SQLite binding (see `SqliteDriver`) as renkei Storage.\n * `init()` migrates (unless `autoMigrate: false`), `close()` closes the driver.\n */\nexport function createSqliteDriverStorage(\n driver: SqliteDriver,\n options: SqliteStorageOptions = {},\n): Storage {\n const now = options.now ?? (() => new Date());\n const storage: Storage = {\n identities: new SqliteIdentityStore(driver, now),\n payloads: new SqlitePayloadStore(driver, now),\n init: async () => {\n if (options.autoMigrate !== false) migrateSqlite(driver);\n },\n };\n if (driver.close) {\n storage.close = async () => {\n driver.close?.();\n };\n }\n return storage;\n}\n\n// ---- value mapping -------------------------------------------------------\n\ntype Col = [name: string, value: SqliteValue];\n\nconst ms = (d: Date): number => d.getTime();\nconst date = (v: unknown): Date => new Date(Number(v));\nconst bool = (v: boolean | undefined): SqliteValue => (v === undefined ? null : v ? 1 : 0);\nconst json = (v: unknown): SqliteValue => (v === undefined ? null : JSON.stringify(v));\nconst names = (cols: Col[]) => cols.map(([c]) => c).join(', ');\nconst marks = (cols: Col[]) => cols.map(() => '?').join(', ');\nconst values = (cols: Col[]) => cols.map(([, v]) => v);\n\nfunction toIdentity(r: Row): Identity {\n return {\n sub: r.sub as string,\n createdAt: date(r.created_at),\n updatedAt: date(r.updated_at),\n ...(r.email != null ? { email: r.email as string } : {}),\n ...(r.email_verified != null ? { emailVerified: Number(r.email_verified) === 1 } : {}),\n ...(r.display_name != null ? { displayName: r.display_name as string } : {}),\n ...(r.picture_url != null ? { pictureUrl: r.picture_url as string } : {}),\n };\n}\n\nfunction toAccount(r: Row): LineAccount {\n return {\n identitySub: r.identity_sub as string,\n channelId: r.channel_id as string,\n lineUserId: r.line_user_id as string,\n kind: r.kind as LineAccountKind,\n createdAt: date(r.created_at),\n updatedAt: date(r.updated_at),\n ...(r.friend != null ? { friend: Number(r.friend) === 1 } : {}),\n ...(r.friend_checked_at != null ? { friendCheckedAt: date(r.friend_checked_at) } : {}),\n ...(r.raw_profile != null\n ? { rawProfile: JSON.parse(r.raw_profile as string) as Record<string, unknown> }\n : {}),\n };\n}\n\n/** Column assignments for the defined keys of a patch — `undefined` means \"leave unchanged\". */\nfunction identityColumns(patch: IdentityPatch): Col[] {\n const cols: Col[] = [];\n if (patch.email !== undefined) cols.push(['email', patch.email]);\n if (patch.emailVerified !== undefined) cols.push(['email_verified', bool(patch.emailVerified)]);\n if (patch.displayName !== undefined) cols.push(['display_name', patch.displayName]);\n if (patch.pictureUrl !== undefined) cols.push(['picture_url', patch.pictureUrl]);\n return cols;\n}\n\n// ---- identities ----------------------------------------------------------\n\nclass SqliteIdentityStore implements IdentityStore {\n constructor(\n private readonly db: SqliteDriver,\n private readonly now: () => Date,\n ) {}\n\n async findIdentity(sub: string) {\n const row = this.db.prepare('SELECT * FROM renkei_identity WHERE sub = ?').get(sub) as\n | Row\n | undefined;\n return row ? toIdentity(row) : undefined;\n }\n\n async findIdentityByLineAccount(channelId: string, lineUserId: string) {\n const row = this.db\n .prepare(\n `SELECT i.* FROM renkei_line_account a\n JOIN renkei_identity i ON i.sub = a.identity_sub\n WHERE a.channel_id = ? AND a.line_user_id = ?`,\n )\n .get(channelId, lineUserId) as Row | undefined;\n return row ? toIdentity(row) : undefined;\n }\n\n async createIdentity(init: IdentityPatch & { sub: string }) {\n const t = ms(this.now());\n const cols: Col[] = [\n ['sub', init.sub],\n ...identityColumns(init),\n ['created_at', t],\n ['updated_at', t],\n ];\n this.db\n .prepare(`INSERT INTO renkei_identity (${names(cols)}) VALUES (${marks(cols)})`)\n .run(...values(cols));\n const created = await this.findIdentity(init.sub);\n if (!created) throw new Error('insert returned no row');\n return created;\n }\n\n async updateIdentity(sub: string, patch: IdentityPatch) {\n const cols: Col[] = [...identityColumns(patch), ['updated_at', ms(this.now())]];\n const set = cols.map(([c]) => `${c} = ?`).join(', ');\n this.db.prepare(`UPDATE renkei_identity SET ${set} WHERE sub = ?`).run(...values(cols), sub);\n const updated = await this.findIdentity(sub);\n if (!updated) throw new Error(`identity ${sub} not found`);\n return updated;\n }\n\n async upsertLineAccount(record: LineAccountUpsert) {\n const t = ms(this.now());\n // Always-written columns; the optional ones join only when defined, so an\n // upsert that omits `friend` keeps the stored friendship.\n const update: Col[] = [\n ['identity_sub', record.identitySub],\n ['kind', record.kind],\n ['updated_at', t],\n ];\n if (record.friend !== undefined) update.push(['friend', bool(record.friend)]);\n if (record.friendCheckedAt !== undefined) {\n update.push(['friend_checked_at', ms(record.friendCheckedAt)]);\n }\n if (record.rawProfile !== undefined) update.push(['raw_profile', json(record.rawProfile)]);\n const insert: Col[] = [\n ['channel_id', record.channelId],\n ['line_user_id', record.lineUserId],\n ['created_at', t],\n ...update,\n ];\n const set = update.map(([c]) => `${c} = excluded.${c}`).join(', ');\n this.db\n .prepare(\n `INSERT INTO renkei_line_account (${names(insert)}) VALUES (${marks(insert)})\n ON CONFLICT (channel_id, line_user_id) DO UPDATE SET ${set}`,\n )\n .run(...values(insert));\n const row = await this.findLineAccount(record.channelId, record.lineUserId);\n if (!row) throw new Error('upsert returned no row');\n return row;\n }\n\n async listLineAccounts(sub: string) {\n const rows = this.db\n .prepare('SELECT * FROM renkei_line_account WHERE identity_sub = ?')\n .all(sub) as Row[];\n return rows.map(toAccount);\n }\n\n async findLineAccount(channelId: string, lineUserId: string) {\n const row = this.db\n .prepare('SELECT * FROM renkei_line_account WHERE channel_id = ? AND line_user_id = ?')\n .get(channelId, lineUserId) as Row | undefined;\n return row ? toAccount(row) : undefined;\n }\n\n async setFriendship(channelId: string, lineUserId: string, friend: boolean, at = this.now()) {\n this.db\n .prepare(\n `UPDATE renkei_line_account SET friend = ?, friend_checked_at = ?, updated_at = ?\n WHERE channel_id = ? AND line_user_id = ?`,\n )\n .run(bool(friend), ms(at), ms(this.now()), channelId, lineUserId);\n }\n}\n\n// ---- payloads ------------------------------------------------------------\n\nconst NOT_EXPIRED = '(expires_at IS NULL OR expires_at > ?)';\n\nclass SqlitePayloadStore implements PayloadStore {\n constructor(\n private readonly db: SqliteDriver,\n private readonly now: () => Date,\n ) {}\n\n private toRecord(row: Row): PayloadRecord {\n const p = JSON.parse(row.payload as string) as PayloadRecord;\n if (row.consumed_at != null) p.consumed = Math.floor(Number(row.consumed_at) / 1000);\n return p;\n }\n\n private findOne(column: 'id' | 'uid' | 'user_code', model: string, value: string) {\n const row = this.db\n .prepare(`SELECT * FROM renkei_payload WHERE model = ? AND ${column} = ? AND ${NOT_EXPIRED}`)\n .get(model, value, ms(this.now())) as Row | undefined;\n return row ? this.toRecord(row) : undefined;\n }\n\n async upsert(model: string, id: string, payload: PayloadRecord, expiresInSeconds?: number) {\n const expiresAt =\n expiresInSeconds !== undefined ? ms(this.now()) + expiresInSeconds * 1000 : null;\n this.db\n .prepare(\n `INSERT INTO renkei_payload (model, id, payload, uid, user_code, grant_id, expires_at, consumed_at)\n VALUES (?, ?, ?, ?, ?, ?, ?, NULL)\n ON CONFLICT (model, id) DO UPDATE SET\n payload = excluded.payload, uid = excluded.uid, user_code = excluded.user_code,\n grant_id = excluded.grant_id, expires_at = excluded.expires_at, consumed_at = NULL`,\n )\n .run(\n model,\n id,\n JSON.stringify(payload),\n typeof payload.uid === 'string' ? payload.uid : null,\n typeof payload.userCode === 'string' ? payload.userCode : null,\n typeof payload.grantId === 'string' ? payload.grantId : null,\n expiresAt,\n );\n }\n\n async find(model: string, id: string) {\n return this.findOne('id', model, id);\n }\n\n async findByUid(model: string, uid: string) {\n return this.findOne('uid', model, uid);\n }\n\n async findByUserCode(model: string, userCode: string) {\n return this.findOne('user_code', model, userCode);\n }\n\n async consume(model: string, id: string) {\n this.db\n .prepare('UPDATE renkei_payload SET consumed_at = ? WHERE model = ? AND id = ?')\n .run(ms(this.now()), model, id);\n }\n\n async destroy(model: string, id: string) {\n this.db.prepare('DELETE FROM renkei_payload WHERE model = ? AND id = ?').run(model, id);\n }\n\n async revokeByGrantId(model: string, grantId: string) {\n this.db\n .prepare('DELETE FROM renkei_payload WHERE model = ? AND grant_id = ?')\n .run(model, grantId);\n }\n\n /** Housekeeping: delete expired rows. Call from a cron or on an interval. */\n async purgeExpired() {\n this.db.prepare('DELETE FROM renkei_payload WHERE expires_at <= ?').run(ms(this.now()));\n }\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,SAAS,eAAe;;;ACSjB,IAAM,aAAgC;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuCF;AAGO,IAAM,gBAAgB,WAAW;AAOjC,SAAS,cAAc,QAA4B;AACxD,QAAM,UAAU,gBAAgB,MAAM;AACtC,WAAS,IAAI,SAAS,IAAI,WAAW,QAAQ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I,CAAC,QAAQ;AACX,UAAM,IAAI;AAAA,MACR;AAAA,IAGF;AAAA,EACF;AACA,QAAM,WAAW,aAAa,cAAc,aAAa;AACzD,MAAI,CAAC,SAAU,WAAU,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAK,CAAC;AAC/D,QAAM,KAAK,IAAI,OAAO,aAAa,QAAQ;AAC3C,KAAG,KAAK,0BAA0B;AAClC,KAAG,KAAK,4BAA4B;AACpC,MAAI,CAAC,UAAU;AACb,OAAG,KAAK,2BAA2B;AACnC,OAAG,KAAK,6BAA6B;AAAA,EACvC;AACA,SAAO;AACT;AAGA,SAAS,iBAA2D;AAClE,MAAI;AACF,WAAO,QAAQ,iBAAiB,aAAa;AAAA,EAC/C,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "renkei-storage-sqlite",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "SQLite storage for renkei. Zero dependencies on Node 22.13+ (built-in node:sqlite); better-sqlite3 and Bun via a 3-method driver interface.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/AchrafReyani/renkei.git",
|
|
9
|
+
"directory": "packages/storage-sqlite"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"development": "./src/index.ts",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=22.13"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"renkei-core": "0.2.3"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsup src/index.ts --format esm --dts --clean --sourcemap",
|
|
34
|
+
"typecheck": "tsc --noEmit",
|
|
35
|
+
"test": "vitest run"
|
|
36
|
+
}
|
|
37
|
+
}
|