@vireocodedev/sqlite 0.2.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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +100 -0
  3. package/package.json +58 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 vireocodedev
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.
package/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # @vireocodedev/sqlite
2
+
3
+ Framework-free SQLite, OPFS, offline queue, and hydration primitives for browser applications.
4
+
5
+ The package owns reusable storage mechanics. An application still owns its schema, migrations, database filename, Worker entry module, API transport, connectivity policy, and product-specific recovery UX.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @vireocodedev/sqlite @sqlite.org/sqlite-wasm
11
+ ```
12
+
13
+ The package is published publicly on npm; installation requires no registry
14
+ authentication. TypeScript declarations are verified from the packed artifact
15
+ with TypeScript 6, `moduleResolution: "Bundler"`, and `skipLibCheck: false`.
16
+ Relative source maps with embedded source content are published intentionally
17
+ for debugging.
18
+
19
+ ## Entry points
20
+
21
+ | Entry point | Responsibility |
22
+ | ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------- |
23
+ | `@vireocodedev/sqlite` | Worker runtime, entity bundles and clients, lifecycle, hydration, persistent offline queue, replay, and SQL-console contracts |
24
+ | `@vireocodedev/sqlite/offline` | Transport-neutral offline mutation, paged hydration, request-header, queue-policy, and network-status helpers |
25
+
26
+ Both entry points are React-free and worker-safe. They do not own UI, signals, query caches, application entities, or HTTP clients.
27
+
28
+ ## Runtime architecture
29
+
30
+ ```text
31
+ application client
32
+ -> createManagedSqliteRuntime
33
+ -> createSqliteTransport
34
+ -> typed entity / queue / hydration clients
35
+ -> module Worker
36
+ -> createSqliteWorkerRuntime(createSqliteWorkerRuntimeConfig(...))
37
+ -> OPFS SQLite database + ordered migrations
38
+ ```
39
+
40
+ `createManagedSqliteRuntime` single-flights initialization, correlates requests, owns fallback stores, and provides deterministic `reset()` and `dispose()` behavior. A Worker crash rejects current work and tears down that Worker; the next request creates and initializes a fresh instance.
41
+
42
+ The application must create a module Worker and install the worker runtime itself. Database filenames and migration arrays are explicit inputs so independent applications and tests never share hidden global state.
43
+
44
+ ## Entity bundles
45
+
46
+ `createSqliteEntityBundle` derives four typed worker operations from one entity specification: replace the snapshot, upsert one row, list rows, and delete by identifier. Exactly one field must declare `id: true`.
47
+
48
+ Entity, table, field-column, request-key, and generated-column configuration is validated before SQL is generated. `createSqliteWorkerRuntimeConfig` rejects duplicate operation names instead of silently replacing one handler with another.
49
+
50
+ Table names, column names, ordering expressions, migrations, and extra worker handlers remain trusted application-authored SQL structure. Runtime data values are bound separately.
51
+
52
+ ## Offline queue
53
+
54
+ The root entry point exposes one complete persistent queue contract:
55
+
56
+ - ordered command capture;
57
+ - pending and permanently-failed states;
58
+ - retry counts and last errors;
59
+ - deterministic batch replay;
60
+ - successful-command cleanup;
61
+ - explicit status projection;
62
+ - equivalent instance-scoped in-memory fallback behavior.
63
+
64
+ Persisted command bodies and headers are parsed strictly. Corrupt JSON raises a descriptive error carrying the command identifier rather than replaying altered fallback data. Batch sizes and retry limits must be positive integers.
65
+
66
+ The package does not decide when the browser is offline, which requests are safe for a product to queue, how authentication is refreshed, or how permanent failures are shown to a user.
67
+
68
+ ## Hydration
69
+
70
+ Hydration is split into small contracts:
71
+
72
+ - contributor registration;
73
+ - request batching and targeted retries;
74
+ - local revision metadata;
75
+ - readiness/status projection;
76
+ - exclusive database/entity execution;
77
+ - paged snapshot collection through the `/offline` entry point.
78
+
79
+ The hydration controller compares local and remote revisions, applies per-entity timeouts, records failures, and schedules bounded retries. The host supplies contributors, revision transport, locks, event projection, and clock/scheduler dependencies.
80
+
81
+ ## Lifecycle and ownership
82
+
83
+ Database ownership, OPFS file discovery/removal, offline-data cleanup ordering, and operation coordination are instance-scoped factories. Construct one set per application runtime and dispose it when that runtime ends.
84
+
85
+ Destructive lifecycle operations are deliberately explicit. The host chooses storage namespaces, confirmation policy, and when clearing local data is safe.
86
+
87
+ ## Failure semantics
88
+
89
+ - Invalid entity or worker configuration throws synchronously.
90
+ - Duplicate worker operation names throw synchronously.
91
+ - Worker failure rejects pending requests and permits recovery on a new Worker.
92
+ - Reset rejects pending work, terminates the active Worker, and clears initialization state.
93
+ - Dispose is idempotent and permanently rejects later work.
94
+ - Migration failure rolls the transaction back.
95
+ - A database schema newer than the available migration list is rejected.
96
+ - Corrupt persisted queue JSON is rejected, never defaulted.
97
+
98
+ ## Verification and live documentation
99
+
100
+ Package tests exercise runtime lifecycle, queue persistence/replay, hydration scheduling, lifecycle cleanup, concurrency, and framework boundaries. The unified Vireo Storybook contains executable examples under the top-level **SQLite** section; every displayed source file is the same TypeScript module Storybook executes.
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@vireocodedev/sqlite",
3
+ "version": "0.2.0",
4
+ "description": "Reusable SQLite worker/client runtime primitives for the vireocodedev starter product.",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/vireocodedev/starter.git",
11
+ "directory": "packages/sqlite"
12
+ },
13
+ "keywords": [
14
+ "sqlite",
15
+ "opfs",
16
+ "worker",
17
+ "runtime",
18
+ "starter"
19
+ ],
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "import": "./dist/index.js"
24
+ },
25
+ "./offline": {
26
+ "types": "./dist/offline/index.d.ts",
27
+ "import": "./dist/offline/index.js"
28
+ }
29
+ },
30
+ "main": "./dist/index.js",
31
+ "module": "./dist/index.js",
32
+ "types": "./dist/index.d.ts",
33
+ "files": [
34
+ "dist"
35
+ ],
36
+ "scripts": {
37
+ "build": "vite build",
38
+ "dev": "vite build --watch --mode watch",
39
+ "typecheck": "tsc --noEmit -p tsconfig.json",
40
+ "test": "vitest run"
41
+ },
42
+ "peerDependencies": {
43
+ "@sqlite.org/sqlite-wasm": ">=3.53.0-build1"
44
+ },
45
+ "devDependencies": {
46
+ "@sqlite.org/sqlite-wasm": "^3.53.0-build1",
47
+ "jsdom": "^30.0.1",
48
+ "typescript": "npm:@typescript/typescript6@^6.0.2",
49
+ "vite": "^8.2.2",
50
+ "vite-plugin-dts": "^5.0.3",
51
+ "vitest": "^4.1.11"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public",
55
+ "provenance": true,
56
+ "registry": "https://registry.npmjs.org"
57
+ }
58
+ }