@arona/store-sqlite 0.0.0-stage → 0.0.3

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
+ MIT License
2
+
3
+ Copyright (c) 2025-2026 Djobbo Maïga
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,29 @@
1
+ import { MessageSessionStore, SessionStoreError, StrongMessageSessionStore } from "@arona/core";
2
+ import { Effect, Layer, Scope } from "effect";
3
+ import { SqlClient } from "effect/sql";
4
+ /**
5
+ * Opens a node SQLite client.
6
+ *
7
+ * File paths get their parent directories created. `:memory:` stays in
8
+ * process. File databases use WAL so another process can read the file while
9
+ * the bot is running. Close the surrounding Scope to release the client.
10
+ */
11
+ export declare const open: (filename: string, options?: {
12
+ readonly busyTimeoutMs?: number | undefined;
13
+ }) => Effect.Effect<SqlClient.SqlClient, SessionStoreError, Scope.Scope>;
14
+ /** Applies the store schema. Safe to run on every startup. */
15
+ export declare const migrate: (client: SqlClient.SqlClient) => Effect.Effect<void, SessionStoreError>;
16
+ /** The SQLite-backed session store for an open Effect SQL client. */
17
+ export declare const make: (client: SqlClient.SqlClient, clock?: () => number) => StrongMessageSessionStore;
18
+ /** A Layer for an already-open SQLite client. */
19
+ export declare const layerFrom: (client: SqlClient.SqlClient, options?: {
20
+ readonly migrate?: boolean;
21
+ readonly clock?: (() => number) | undefined;
22
+ }) => Layer.Layer<MessageSessionStore, SessionStoreError>;
23
+ /** The canonical resource-owning SQLite layer. */
24
+ export declare const layer: (options: {
25
+ readonly filename: string;
26
+ readonly migrate?: boolean;
27
+ readonly clock?: (() => number) | undefined;
28
+ readonly busyTimeoutMs?: number | undefined;
29
+ }) => Layer.Layer<MessageSessionStore, SessionStoreError>;
package/dist/index.js ADDED
@@ -0,0 +1,64 @@
1
+ import { mkdirSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { MessageSessionStore, migrateSqlSessionStore, nowMillis, sqlSessionStore, storeError } from "@arona/core";
4
+ import { SqliteClient } from "@effect/sql-sqlite-node";
5
+ import { Context, Duration, Effect, Layer } from "effect";
6
+ import { SqlClient } from "effect/sql";
7
+ // src/sqlite.ts
8
+ const isMemory = (filename) => filename === ":memory:" || filename.trim() === "";
9
+ const targetOf = (filename) => filename.trim() === "" ? ":memory:" : filename;
10
+ const ensureDirectory = (filename) => Effect.try({
11
+ try: () => {
12
+ if (!isMemory(filename)) mkdirSync(path.dirname(path.resolve(filename)), { recursive: true });
13
+ },
14
+ catch: (cause) => storeError(`SQLite directory failed: ${filename}`, cause)
15
+ });
16
+ const clientLayer = (filename, busyTimeoutMs) => {
17
+ const target = targetOf(filename);
18
+ const requested = busyTimeoutMs ?? 5e3;
19
+ const timeout = Number.isFinite(requested) && requested > 0 ? Math.trunc(requested) : 5e3;
20
+ return SqliteClient.layer({
21
+ filename: target,
22
+ busyTimeout: Duration.millis(timeout),
23
+ ...isMemory(target) ? { disableWAL: true } : {}
24
+ });
25
+ };
26
+ /**
27
+ * Opens a node SQLite client.
28
+ *
29
+ * File paths get their parent directories created. `:memory:` stays in
30
+ * process. File databases use WAL so another process can read the file while
31
+ * the bot is running. Close the surrounding Scope to release the client.
32
+ */
33
+ const open = (filename, options = {}) => Effect.gen(function* () {
34
+ const target = targetOf(filename);
35
+ yield* ensureDirectory(target);
36
+ const context = yield* Layer.build(clientLayer(target, options.busyTimeoutMs)).pipe(Effect.mapError((cause) => storeError(`SQLite open failed: ${target}`, cause)));
37
+ return Context.get(context, SqlClient.SqlClient);
38
+ });
39
+ /** Applies the store schema. Safe to run on every startup. */
40
+ const migrate = migrateSqlSessionStore;
41
+ /** The SQLite-backed session store for an open Effect SQL client. */
42
+ const make = (client, clock = nowMillis) => sqlSessionStore(client, clock);
43
+ /** A Layer for an already-open SQLite client. */
44
+ const layerFrom = (client, options = {}) => Layer.effect(MessageSessionStore, (options.migrate === true ? migrate(client) : Effect.void).pipe(Effect.as(make(client, options.clock ?? nowMillis))));
45
+ /**
46
+ * Opens, migrates and owns a libSQL database for the lifetime of a scope.
47
+ *
48
+ * The client is closed when the layer scope ends. Pass this layer to a platform
49
+ * client and it picks the store up from the context, so resumable messages need
50
+ * no separate `open`/`migrate`/`make` wiring. Migrations run by default; pass
51
+ * `{ migrate: false }` to skip them.
52
+ */
53
+ const layerOwned = (filename, options = {}) => {
54
+ const target = targetOf(filename);
55
+ const client = clientLayer(target, options.busyTimeoutMs).pipe(Layer.catchCause((cause) => Layer.unwrap(Effect.fail(storeError(`SQLite open failed: ${target}`, cause)))));
56
+ return Layer.unwrap(ensureDirectory(target).pipe(Effect.as(Layer.effect(MessageSessionStore, Effect.gen(function* () {
57
+ const sql = yield* SqlClient.SqlClient;
58
+ if (options.migrate !== false) yield* migrate(sql);
59
+ return make(sql, options.clock ?? nowMillis);
60
+ })).pipe(Layer.provide(client)))));
61
+ };
62
+ /** The canonical resource-owning SQLite layer. */
63
+ const layer = (options) => layerOwned(options.filename, options);
64
+ export { layer, layerFrom, make, migrate, open };
@@ -0,0 +1,2 @@
1
+ /** Absolute path to the SQLite migrations shipped with this package. */
2
+ export declare const migrationsDir: string;
@@ -0,0 +1,5 @@
1
+ import { fileURLToPath } from "node:url";
2
+ // src/migrations.ts
3
+ /** Absolute path to the SQLite migrations shipped with this package. */
4
+ const migrationsDir = fileURLToPath(new URL("../migrations", import.meta.url).href);
5
+ export { migrationsDir };
@@ -0,0 +1,23 @@
1
+ CREATE TABLE IF NOT EXISTS arona_message_sessions (
2
+ id TEXT PRIMARY KEY,
3
+ version INTEGER NOT NULL,
4
+ status TEXT NOT NULL,
5
+ component TEXT NOT NULL,
6
+ build TEXT NOT NULL,
7
+ props TEXT NOT NULL,
8
+ state TEXT,
9
+ message_id TEXT,
10
+ channel_id TEXT,
11
+ guild_id TEXT,
12
+ ephemeral INTEGER NOT NULL,
13
+ created_at INTEGER NOT NULL,
14
+ updated_at INTEGER NOT NULL,
15
+ expires_at INTEGER,
16
+ last_interaction_id TEXT
17
+ );
18
+
19
+ CREATE INDEX IF NOT EXISTS arona_message_sessions_message
20
+ ON arona_message_sessions (message_id);
21
+
22
+ CREATE INDEX IF NOT EXISTS arona_message_sessions_active
23
+ ON arona_message_sessions (status, expires_at);
@@ -0,0 +1,2 @@
1
+ ALTER TABLE arona_message_sessions ADD COLUMN lease_owner TEXT;
2
+ ALTER TABLE arona_message_sessions ADD COLUMN lease_until INTEGER;
package/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
2
  "name": "@arona/store-sqlite",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.0.3",
4
+ "description": "Node SQLite session store for Arona",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/djobbo/arona.git"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "migrations"
13
+ ],
14
+ "type": "module",
15
+ "module": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js"
21
+ },
22
+ "./migrations": {
23
+ "types": "./dist/migrations.d.ts",
24
+ "import": "./dist/migrations.js"
25
+ }
26
+ },
27
+ "dependencies": {
28
+ "@arona/core": "0.0.3",
29
+ "@effect/sql-sqlite-node": "4.2.0"
30
+ },
31
+ "devDependencies": {
32
+ "@types/node": "^26.6.10",
33
+ "effect": "4.2.0",
34
+ "fast-check": "4.11.0",
35
+ "typescript": "^5.8.3",
36
+ "vite-plus": "1.8.0"
37
+ },
38
+ "peerDependencies": {
39
+ "effect": "^4.2.0",
40
+ "typescript": "^5.8.3"
41
+ },
42
+ "engines": {
43
+ "node": "^22.18.0 || ^24.11.0 || >=26.0.0"
44
+ },
45
+ "scripts": {
46
+ "build": "vp pack",
47
+ "dev": "vp pack --watch",
48
+ "test": "vp test",
49
+ "check:types": "effect-tsgo tsrs --noEmit",
50
+ "check:lint": "effect-tsgo vp lint"
51
+ }
6
52
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.