@effect-native/libcrsql 0.16.3-1

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/README.md ADDED
@@ -0,0 +1,176 @@
1
+ # @effect-native/libcrsql
2
+
3
+ [![npm version](https://badge.fury.io/js/%40effect-native%2Flibcrsql.svg)](https://badge.fury.io/js/%40effect-native%2Flibcrsql)
4
+
5
+ Pure-Nix CR-SQLite extension for conflict-free replicated databases. Just Works™ everywhere - Mac, Linux, Pi, Docker, Vercel, etc.
6
+
7
+ ## What is CR-SQLite?
8
+
9
+ CR-SQLite is a run-time loadable extension for SQLite that enables Conflict-free Replicated Data Types (CRDTs). It allows you to create tables that can be replicated across multiple devices/servers and automatically merge changes without conflicts.
10
+
11
+ This package provides pre-built CR-SQLite extensions via Nix, eliminating the need to build from source.
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install @effect-native/libcrsql
17
+ ```
18
+
19
+ ## Quick Start
20
+
21
+ ```javascript
22
+ import { pathToCRSQLiteExtension } from '@effect-native/libcrsql';
23
+ import Database from 'better-sqlite3';
24
+
25
+ const db = new Database(':memory:');
26
+ db.loadExtension(pathToCRSQLiteExtension);
27
+
28
+ // Convert table to conflict-free replicated relation
29
+ db.exec(`
30
+ CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT);
31
+ SELECT crsql_as_crr('users');
32
+ `);
33
+
34
+ // Insert data - changes are automatically tracked
35
+ db.exec(`INSERT INTO users (name) VALUES ('Alice')`);
36
+
37
+ // Get changes for synchronization
38
+ const changes = db.prepare(`SELECT * FROM crsql_changes`).all();
39
+ console.log('Changes to sync:', changes);
40
+ ```
41
+
42
+ ## API
43
+
44
+ ### `pathToCRSQLiteExtension`
45
+
46
+ Path to the CR-SQLite extension file. Use this with your SQLite library's `loadExtension()` method.
47
+
48
+ ```javascript
49
+ import { pathToCRSQLiteExtension } from '@effect-native/libcrsql';
50
+ console.log(pathToCRSQLiteExtension); // /path/to/crsqlite-darwin-aarch64.dylib
51
+ ```
52
+
53
+ ### `getExtensionPath()`
54
+
55
+ Function that returns the path to the CR-SQLite extension.
56
+
57
+ ```javascript
58
+ import { getExtensionPath } from '@effect-native/libcrsql';
59
+ const extensionPath = getExtensionPath();
60
+ ```
61
+
62
+ ## CLI Usage
63
+
64
+ ```bash
65
+ npx libcrsql-extension-path
66
+ # /path/to/crsqlite-darwin-aarch64.dylib
67
+ ```
68
+
69
+ ## Supported Platforms
70
+
71
+ - ✅ **macOS** (Intel & Apple Silicon)
72
+ - ✅ **Linux** (x86_64 & ARM64)
73
+ - ✅ **Docker** containers
74
+ - ✅ **Vercel**, Netlify, Railway
75
+ - ✅ **Raspberry Pi** 4+
76
+ - ✅ **AWS Lambda** (with custom runtime)
77
+
78
+ ## Database Libraries
79
+
80
+ Works with any SQLite library that supports loading extensions:
81
+
82
+ ### better-sqlite3
83
+ ```javascript
84
+ import Database from 'better-sqlite3';
85
+ import { pathToCRSQLiteExtension } from '@effect-native/libcrsql';
86
+
87
+ const db = new Database('my-app.db');
88
+ db.loadExtension(pathToCRSQLiteExtension);
89
+ ```
90
+
91
+ ### sqlite3
92
+ ```javascript
93
+ import sqlite3 from 'sqlite3';
94
+ import { pathToCRSQLiteExtension } from '@effect-native/libcrsql';
95
+
96
+ const db = new sqlite3.Database('my-app.db');
97
+ db.loadExtension(pathToCRSQLiteExtension);
98
+ ```
99
+
100
+ ### Bun SQLite
101
+ ```javascript
102
+ import { Database } from 'bun:sqlite';
103
+ import { pathToCRSQLiteExtension } from '@effect-native/libcrsql';
104
+
105
+ const db = new Database('my-app.db');
106
+ db.loadExtension(pathToCRSQLiteExtension);
107
+ ```
108
+
109
+ ## React Native
110
+
111
+ This package is for **Node.js/Bun server environments only**. For React Native, use:
112
+
113
+ - [@op-engineering/op-sqlite](https://www.npmjs.com/package/@op-engineering/op-sqlite)
114
+ - [expo-sqlite](https://docs.expo.dev/versions/latest/sdk/sqlite/)
115
+
116
+ ## CR-SQLite Functions
117
+
118
+ Once loaded, CR-SQLite provides these functions:
119
+
120
+ - `crsql_as_crr(table_name)` - Convert table to conflict-free replicated relation
121
+ - `crsql_version()` - Get CR-SQLite version
122
+ - `crsql_changes` - Virtual table containing changes for sync
123
+ - `crsql_begin_alter(table_name)` - Begin schema changes
124
+ - `crsql_commit_alter(table_name)` - Commit schema changes
125
+
126
+ See [CR-SQLite Documentation](https://vlcn.io/docs/cr-sqlite/intro) for complete API reference.
127
+
128
+ ## Development
129
+
130
+ ### Prerequisites
131
+ - [Nix](https://nixos.org/download.html) package manager
132
+ - Node.js 16+
133
+
134
+ ### Building
135
+
136
+ ```bash
137
+ # Build CR-SQLite extensions for all platforms
138
+ npm run bundle-lib
139
+
140
+ # Build production package
141
+ npm run build-production
142
+
143
+ # Run tests
144
+ npm test
145
+ npm run test:docker
146
+ ```
147
+
148
+ ## Troubleshooting
149
+
150
+ ### "Extension not found" Error
151
+
152
+ ```bash
153
+ # Check what platforms are available
154
+ npm list @effect-native/libcrsql
155
+ ls node_modules/@effect-native/libcrsql/lib/
156
+
157
+ # Get extension path for debugging
158
+ npx libcrsql-extension-path
159
+ ```
160
+
161
+ ## Contributing
162
+
163
+ 1. Fork the repository
164
+ 2. Create your feature branch: `git checkout -b my-feature`
165
+ 3. Make your changes and run tests: `npm test`
166
+ 4. Submit a pull request
167
+
168
+ ## License
169
+
170
+ MIT
171
+
172
+ ## Related
173
+
174
+ - [CR-SQLite](https://github.com/vlcn-io/cr-sqlite) - The upstream CR-SQLite project
175
+ - [@effect-native/libsqlite](https://github.com/effect-native/libsqlite) - Nix-built SQLite library
176
+ - [vlcn.io](https://vlcn.io) - CR-SQLite documentation and tools
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { pathToCRSQLiteExtension } from '../index.js';
4
+
5
+ try {
6
+ console.log(pathToCRSQLiteExtension);
7
+ } catch (error) {
8
+ console.error(error.message);
9
+ process.exit(1);
10
+ }
package/index.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Get the absolute path to the bundled CR-SQLite extension
3
+ * @returns Absolute path to crsqlite.dylib/.so
4
+ */
5
+ export declare function getExtensionPath(): string;
6
+
7
+ /**
8
+ * Path to CR-SQLite extension - for use with db.loadExtension()
9
+ */
10
+ export declare const pathToCRSQLiteExtension: string;
11
+
12
+ /**
13
+ * Default export - same as pathToCRSQLiteExtension
14
+ */
15
+ declare const _default: string;
16
+ export default _default;
package/index.js ADDED
@@ -0,0 +1,67 @@
1
+ import { fileURLToPath } from 'node:url';
2
+ import { dirname, resolve } from 'node:path';
3
+ import { existsSync } from 'node:fs';
4
+
5
+ const __dirname = dirname(fileURLToPath(import.meta.url));
6
+
7
+ /**
8
+ * Get the absolute path to the bundled CR-SQLite extension
9
+ * Automatically detects platform and architecture
10
+ * @returns {string} Absolute path to crsqlite.dylib/.so
11
+ */
12
+ export function getExtensionPath() {
13
+ // Browser check - prevent misuse in browsers
14
+ if (typeof window !== 'undefined') {
15
+ throw new Error(
16
+ '@effect-native/libcrsql is for Node.js server environments only. ' +
17
+ 'For browsers, use sql.js or a server-side database API.'
18
+ );
19
+ }
20
+
21
+ // Detect current platform and architecture
22
+ const platform = process.platform === 'darwin' ? 'darwin' : 'linux';
23
+ const arch = process.arch === 'arm64' ? 'aarch64' : 'x86_64';
24
+ const ext = platform === 'darwin' ? 'dylib' : 'so';
25
+
26
+ const libDir = resolve(__dirname, 'lib');
27
+
28
+ // Try platform-specific extension first (highest priority)
29
+ const specificExt = resolve(libDir, `crsqlite-${platform}-${arch}.${ext}`);
30
+ if (existsSync(specificExt)) {
31
+ return specificExt;
32
+ }
33
+
34
+ // Fallback to any available extension for the current platform
35
+ const fallbackCandidates = [
36
+ resolve(libDir, `crsqlite.${ext}`), // Generic for platform
37
+ resolve(libDir, 'crsqlite.dylib'), // macOS generic
38
+ resolve(libDir, 'crsqlite.so'), // Linux generic
39
+ ];
40
+
41
+ for (const candidate of fallbackCandidates) {
42
+ if (existsSync(candidate)) {
43
+ return candidate;
44
+ }
45
+ }
46
+
47
+ // Helpful error message with available platforms
48
+ const availablePlatforms = [];
49
+ const expectedExt = `crsqlite-${platform}-${arch}.${ext}`;
50
+ throw new Error(
51
+ `CR-SQLite extension not found for ${platform}/${arch}. ` +
52
+ `Expected: ${expectedExt}. ` +
53
+ `Available platforms: ${availablePlatforms.join(', ')}. ` +
54
+ `This package supports: Intel/AMD Linux (Docker, most servers), ARM64 Linux (Raspberry Pi 4+, AWS Graviton), Intel Mac, Apple Silicon Mac (M1/M2/M3)`
55
+ );
56
+ }
57
+
58
+ /**
59
+ * Path to CR-SQLite extension - for use with db.loadExtension()
60
+ * Automatically detects your platform and returns the right extension
61
+ */
62
+ export const pathToCRSQLiteExtension = getExtensionPath();
63
+
64
+ /**
65
+ * Default export - same as pathToCRSQLiteExtension
66
+ */
67
+ export default pathToCRSQLiteExtension;
Binary file
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@effect-native/libcrsql",
3
+ "version": "0.16.3-1",
4
+ "description": "Pure-Nix CR-SQLite extension (.dylib/.so) for conflict-free replicated databases",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "react-native": "./react-native.js",
11
+ "default": "./index.js"
12
+ },
13
+ "./react-native": {
14
+ "import": "./react-native.js",
15
+ "types": "./react-native.d.ts"
16
+ },
17
+ "./package.json": "./package.json"
18
+ },
19
+ "scripts": {},
20
+ "bin": {
21
+ "@effect-native/libcrsql": "./bin/libcrsql-extension-path.js",
22
+ "libcrsql-extension-path": "./bin/libcrsql-extension-path.js"
23
+ },
24
+ "files": [
25
+ "index.js",
26
+ "index.d.ts",
27
+ "react-native.js",
28
+ "react-native.d.ts",
29
+ "lib/",
30
+ "bin/",
31
+ "README.md"
32
+ ],
33
+ "keywords": [
34
+ "sqlite",
35
+ "sqlite3",
36
+ "cr-sqlite",
37
+ "crsqlite",
38
+ "crdt",
39
+ "conflict-free",
40
+ "replicated",
41
+ "extension",
42
+ "nix",
43
+ "dylib",
44
+ "shared-library"
45
+ ],
46
+ "author": "Tom Aylott",
47
+ "license": "MIT",
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "https://github.com/effect-native/cr-sqlite.git"
51
+ },
52
+ "engines": {
53
+ "node": ">=16.0.0"
54
+ },
55
+ "peerDependencies": {},
56
+ "dependencies": {},
57
+ "devDependencies": {
58
+ "@effect-native/libsqlite": "^3.50.2-1",
59
+ "@effect/platform": "^0.66.3",
60
+ "@effect/platform-bun": "^0.46.0",
61
+ "@types/bun": "latest",
62
+ "@types/node": "^22.0.0",
63
+ "effect": "^3.10.0",
64
+ "tsx": "^4.19.2",
65
+ "typescript": "^5.7.2"
66
+ },
67
+ "publishConfig": {
68
+ "access": "public"
69
+ }
70
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * React Native placeholder for getExtensionPath
3
+ * @throws Always throws with helpful message for React Native users
4
+ */
5
+ export declare function getExtensionPath(): never;
6
+
7
+ /**
8
+ * React Native placeholder for pathToCRSQLiteExtension
9
+ * @throws Always throws with helpful message for React Native users
10
+ */
11
+ export declare const pathToCRSQLiteExtension: never;
12
+
13
+ export default pathToCRSQLiteExtension;
@@ -0,0 +1,32 @@
1
+ // React Native specific entry point
2
+ // CR-SQLite extensions don't work in React Native
3
+
4
+ /**
5
+ * React Native placeholder for getExtensionPath
6
+ * @throws Always throws with helpful message for React Native users
7
+ */
8
+ export function getExtensionPath() {
9
+ throw new Error(
10
+ '\u{1f6ab} @effect-native/libcrsql is for Node.js / Bun server environments only.\n\n' +
11
+ '\u{1f4f1} For React Native, use one of these instead:\n' +
12
+ ' \u2022 @op-engineering/op-sqlite: https://www.npmjs.com/package/@op-engineering/op-sqlite\n' +
13
+ ' \u2022 expo-sqlite: https://docs.expo.dev/versions/latest/sdk/sqlite/\n' +
14
+ '\u{1f4a1} This package provides native CR-SQLite extensions for Node.js / Bun servers, not mobile apps.'
15
+ );
16
+ }
17
+
18
+ /**
19
+ * React Native placeholder for pathToCRSQLiteExtension
20
+ * @throws Always throws with helpful message
21
+ */
22
+ export const pathToCRSQLiteExtension = (() => {
23
+ throw new Error(
24
+ '\u{1f6ab} @effect-native/libcrsql is for Node.js / Bun server environments only.\n\n' +
25
+ '\u{1f4f1} For React Native, use one of these instead:\n' +
26
+ ' \u2022 @op-engineering/op-sqlite: https://www.npmjs.com/package/@op-engineering/op-sqlite\n' +
27
+ ' \u2022 expo-sqlite: https://docs.expo.dev/versions/latest/sdk/sqlite/\n' +
28
+ '\u{1f4a1} This package provides native CR-SQLite extensions for Node.js / Bun servers, not mobile apps.'
29
+ );
30
+ })();
31
+
32
+ export default pathToCRSQLiteExtension;