@effect-native/libcrsql 0.16.3-1 → 0.16.301

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 (54) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +41 -152
  3. package/dist/cjs/browser-unsupported.js +14 -0
  4. package/dist/cjs/browser-unsupported.js.map +1 -0
  5. package/dist/cjs/index.js +77 -0
  6. package/dist/cjs/index.js.map +1 -0
  7. package/dist/cjs/paths.js +45 -0
  8. package/dist/cjs/paths.js.map +1 -0
  9. package/dist/cjs/platform.js +61 -0
  10. package/dist/cjs/platform.js.map +1 -0
  11. package/dist/cjs/version.js +12 -0
  12. package/dist/cjs/version.js.map +1 -0
  13. package/dist/dts/browser-unsupported.d.ts +7 -0
  14. package/dist/dts/browser-unsupported.d.ts.map +1 -0
  15. package/dist/dts/index.d.ts +44 -0
  16. package/dist/dts/index.d.ts.map +1 -0
  17. package/dist/dts/paths.d.ts +38 -0
  18. package/dist/dts/paths.d.ts.map +1 -0
  19. package/dist/dts/platform.d.ts +30 -0
  20. package/dist/dts/platform.d.ts.map +1 -0
  21. package/dist/dts/version.d.ts +6 -0
  22. package/dist/dts/version.d.ts.map +1 -0
  23. package/dist/esm/browser-unsupported.js +10 -0
  24. package/dist/esm/browser-unsupported.js.map +1 -0
  25. package/dist/esm/index.js +68 -0
  26. package/dist/esm/index.js.map +1 -0
  27. package/dist/esm/package.json +8 -0
  28. package/dist/esm/paths.js +38 -0
  29. package/dist/esm/paths.js.map +1 -0
  30. package/dist/esm/platform.js +52 -0
  31. package/dist/esm/platform.js.map +1 -0
  32. package/dist/esm/version.js +6 -0
  33. package/dist/esm/version.js.map +1 -0
  34. package/dist/lib/darwin-aarch64/libcrsqlite.dylib +0 -0
  35. package/{lib/crsqlite-darwin-x86_64.dylib → dist/lib/darwin-x86_64/libcrsqlite.dylib} +0 -0
  36. package/dist/lib/linux-aarch64/libcrsqlite.so +0 -0
  37. package/dist/lib/linux-x86_64/libcrsqlite.so +0 -0
  38. package/dist/lib/win-i686/crsqlite.dll +0 -0
  39. package/dist/lib/win-x86_64/crsqlite.dll +0 -0
  40. package/effect/package.json +6 -0
  41. package/package.json +55 -59
  42. package/paths/package.json +6 -0
  43. package/src/browser-unsupported.ts +9 -0
  44. package/src/effect.ts +117 -0
  45. package/src/index.ts +87 -0
  46. package/src/paths.ts +47 -0
  47. package/src/platform.ts +75 -0
  48. package/src/version.ts +5 -0
  49. package/bin/libcrsql-extension-path.js +0 -10
  50. package/index.d.ts +0 -16
  51. package/index.js +0 -67
  52. package/lib/crsqlite-darwin-aarch64.dylib +0 -0
  53. package/react-native.d.ts +0 -13
  54. package/react-native.js +0 -32
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Root entrypoint: absolute path getters with zero external dependencies.
3
+ *
4
+ * @since 0.16.300
5
+ */
6
+ import * as fs from "node:fs";
7
+ import { fileURLToPath } from "node:url";
8
+ import { buildRelativeLibraryPath, detectPlatform, isSupportedPlatform, SUPPORTED_PLATFORMS as _SUPPORTED_PLATFORMS } from "./platform.js";
9
+ import { CRSQLITE_VERSION as _CRSQLITE_VERSION } from "./version.js";
10
+ /**
11
+ * Synchronous absolute path resolution for the cr-sqlite extension binary.
12
+ *
13
+ * - Returns an absolute path string that you can pass to `db.loadExtension()`.
14
+ * - Throws native Error with `code` set to `ERR_PLATFORM_UNSUPPORTED` or
15
+ * `ERR_EXTENSION_NOT_FOUND`.
16
+ *
17
+ * @since 0.16.300
18
+ * @example
19
+ * import { getCrSqliteExtensionPathSync } from "@effect-native/libcrsql"
20
+ *
21
+ * const path = getCrSqliteExtensionPathSync()
22
+ * console.log(path)
23
+ */
24
+ export const getCrSqliteExtensionPathSync = platform => {
25
+ const target = platform ?? detectPlatform();
26
+ if (!isSupportedPlatform(target)) {
27
+ const err = new Error(`Platform "${target}" is not supported. Detected: ${process.platform}-${process.arch}. Supported: ${SUPPORTED_PLATFORMS.join(", ")}`);
28
+ err.code = "ERR_PLATFORM_UNSUPPORTED";
29
+ throw err;
30
+ }
31
+ const abs = fileURLToPath(new URL(`../${buildRelativeLibraryPath(target)}`, import.meta.url));
32
+ // Best-effort existence check without external deps.
33
+ // Note: this synchronous check runs once per import/use and ensures the
34
+ // contract of this package (absolute path to an existing native binary).
35
+ // If needed, we can memoize this at runtime, but import memoization already
36
+ // avoids repeated work in typical usage.
37
+ try {
38
+ fs.accessSync(abs);
39
+ } catch {
40
+ const err = new Error(`Extension binary not found: ${abs}`);
41
+ err.code = "ERR_EXTENSION_NOT_FOUND";
42
+ throw err;
43
+ }
44
+ return abs;
45
+ };
46
+ /**
47
+ * Absolute path to the cr-sqlite binary for the current platform, computed at import time.
48
+ *
49
+ * - Useful for the simplest use cases: just import and load.
50
+ * - Throws on unsupported platform or if the binary is not present.
51
+ *
52
+ * @since 0.16.300
53
+ * @example
54
+ * import { pathToCrSqliteExtension } from "@effect-native/libcrsql"
55
+ * console.log(pathToCrSqliteExtension)
56
+ */
57
+ export const pathToCrSqliteExtension = /*#__PURE__*/getCrSqliteExtensionPathSync();
58
+ /**
59
+ * List of supported platforms.
60
+ * @since 0.16.300
61
+ */
62
+ export const SUPPORTED_PLATFORMS = _SUPPORTED_PLATFORMS;
63
+ /**
64
+ * Bundled upstream cr-sqlite version.
65
+ * @since 0.16.300
66
+ */
67
+ export const CRSQLITE_VERSION = _CRSQLITE_VERSION;
68
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["fs","fileURLToPath","buildRelativeLibraryPath","detectPlatform","isSupportedPlatform","SUPPORTED_PLATFORMS","_SUPPORTED_PLATFORMS","CRSQLITE_VERSION","_CRSQLITE_VERSION","getCrSqliteExtensionPathSync","platform","target","err","Error","process","arch","join","code","abs","URL","import","meta","url","accessSync","pathToCrSqliteExtension"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;AAKA,OAAO,KAAKA,EAAE,MAAM,SAAS;AAC7B,SAASC,aAAa,QAAQ,UAAU;AACxC,SACEC,wBAAwB,EACxBC,cAAc,EACdC,mBAAmB,EACnBC,mBAAmB,IAAIC,oBAAoB,QACtC,eAAe;AACtB,SAASC,gBAAgB,IAAIC,iBAAiB,QAAQ,cAAc;AAIpE;;;;;;;;;;;;;;AAcA,OAAO,MAAMC,4BAA4B,GAAIC,QAAmB,IAAY;EAC1E,MAAMC,MAAM,GAAGD,QAAQ,IAAIP,cAAc,EAAE;EAC3C,IAAI,CAACC,mBAAmB,CAACO,MAAM,CAAC,EAAE;IAChC,MAAMC,GAAG,GAA0B,IAAIC,KAAK,CAC1C,aAAaF,MAAM,iCAAiCG,OAAO,CAACJ,QAAQ,IAAII,OAAO,CAACC,IAAI,gBAClFV,mBAAmB,CAACW,IAAI,CAAC,IAAI,CAC/B,EAAE,CACH;IACDJ,GAAG,CAACK,IAAI,GAAG,0BAA0B;IACrC,MAAML,GAAG;EACX;EACA,MAAMM,GAAG,GAAGjB,aAAa,CAAC,IAAIkB,GAAG,CAAC,MAAMjB,wBAAwB,CAACS,MAAM,CAAC,EAAE,EAAES,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC,CAAC;EAC7F;EACA;EACA;EACA;EACA;EACA,IAAI;IACFtB,EAAE,CAACuB,UAAU,CAACL,GAAG,CAAC;EACpB,CAAC,CAAC,MAAM;IACN,MAAMN,GAAG,GAA0B,IAAIC,KAAK,CAAC,+BAA+BK,GAAG,EAAE,CAAC;IAClFN,GAAG,CAACK,IAAI,GAAG,yBAAyB;IACpC,MAAML,GAAG;EACX;EACA,OAAOM,GAAG;AACZ,CAAC;AAED;;;;;;;;;;;AAWA,OAAO,MAAMM,uBAAuB,gBAAWf,4BAA4B,EAAE;AAQ7E;;;;AAIA,OAAO,MAAMJ,mBAAmB,GAAGC,oBAAoB;AACvD;;;;AAIA,OAAO,MAAMC,gBAAgB,GAAGC,iBAAiB","ignoreList":[]}
@@ -0,0 +1,8 @@
1
+ {
2
+ "type": "module",
3
+ "sideEffects": [
4
+ "./index.js",
5
+ "./paths.js",
6
+ "./effect.js"
7
+ ]
8
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Absolute paths per-platform. These are computed from this module location
3
+ * using Node built-ins only (no external dependencies, no I/O).
4
+ *
5
+ * @since 0.16.300
6
+ */
7
+ import { fileURLToPath } from "node:url";
8
+ /**
9
+ * Absolute path to darwin-aarch64 cr-sqlite dylib.
10
+ * @since 0.16.300
11
+ */
12
+ export const darwin_aarch64 = /*#__PURE__*/fileURLToPath(/*#__PURE__*/new URL("../lib/darwin-aarch64/libcrsqlite.dylib", import.meta.url));
13
+ /**
14
+ * Absolute path to darwin-x86_64 cr-sqlite dylib.
15
+ * @since 0.16.300
16
+ */
17
+ export const darwin_x86_64 = /*#__PURE__*/fileURLToPath(/*#__PURE__*/new URL("../lib/darwin-x86_64/libcrsqlite.dylib", import.meta.url));
18
+ /**
19
+ * Absolute path to linux-aarch64 cr-sqlite so.
20
+ * @since 0.16.300
21
+ */
22
+ export const linux_aarch64 = /*#__PURE__*/fileURLToPath(/*#__PURE__*/new URL("../lib/linux-aarch64/libcrsqlite.so", import.meta.url));
23
+ /**
24
+ * Absolute path to linux-x86_64 cr-sqlite so.
25
+ * @since 0.16.300
26
+ */
27
+ export const linux_x86_64 = /*#__PURE__*/fileURLToPath(/*#__PURE__*/new URL("../lib/linux-x86_64/libcrsqlite.so", import.meta.url));
28
+ /**
29
+ * Absolute path to win-x86_64 cr-sqlite dll.
30
+ * @since 0.16.300
31
+ */
32
+ export const win_x86_64 = /*#__PURE__*/fileURLToPath(/*#__PURE__*/new URL("../lib/win-x86_64/crsqlite.dll", import.meta.url));
33
+ /**
34
+ * Absolute path to win-i686 cr-sqlite dll.
35
+ * @since 0.16.300
36
+ */
37
+ export const win_i686 = /*#__PURE__*/fileURLToPath(/*#__PURE__*/new URL("../lib/win-i686/crsqlite.dll", import.meta.url));
38
+ //# sourceMappingURL=paths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.js","names":["fileURLToPath","darwin_aarch64","URL","import","meta","url","darwin_x86_64","linux_aarch64","linux_x86_64","win_x86_64","win_i686"],"sources":["../../src/paths.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;AAMA,SAASA,aAAa,QAAQ,UAAU;AAExC;;;;AAIA,OAAO,MAAMC,cAAc,gBAAGD,aAAa,cAAC,IAAIE,GAAG,CAAC,yCAAyC,EAAEC,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC,CAAC;AAChH;;;;AAIA,OAAO,MAAMC,aAAa,gBAAGN,aAAa,cAAC,IAAIE,GAAG,CAAC,wCAAwC,EAAEC,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC,CAAC;AAC9G;;;;AAIA,OAAO,MAAME,aAAa,gBAAGP,aAAa,cAAC,IAAIE,GAAG,CAAC,qCAAqC,EAAEC,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC,CAAC;AAC3G;;;;AAIA,OAAO,MAAMG,YAAY,gBAAGR,aAAa,cAAC,IAAIE,GAAG,CAAC,oCAAoC,EAAEC,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC,CAAC;AACzG;;;;AAIA,OAAO,MAAMI,UAAU,gBAAGT,aAAa,cAAC,IAAIE,GAAG,CAAC,gCAAgC,EAAEC,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC,CAAC;AACnG;;;;AAIA,OAAO,MAAMK,QAAQ,gBAAGV,aAAa,cAAC,IAAIE,GAAG,CAAC,8BAA8B,EAAEC,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Platform detection and mapping utilities for @effect-native/libcrsql.
3
+ * @since 0.16.300
4
+ */
5
+ // Platform detection and mapping
6
+ /**
7
+ * List of supported platforms.
8
+ * @since 0.16.300
9
+ */
10
+ export const SUPPORTED_PLATFORMS = ["darwin-aarch64", "darwin-x86_64", "linux-aarch64", "linux-x86_64", "win-x86_64", "win-i686"];
11
+ /**
12
+ * True if the given string is a supported platform.
13
+ * @since 0.16.300
14
+ */
15
+ export const isSupportedPlatform = p => SUPPORTED_PLATFORMS.includes(p);
16
+ /**
17
+ * Detect current platform string.
18
+ * @since 0.16.300
19
+ */
20
+ export const detectPlatform = () => {
21
+ const platform = process.platform;
22
+ const arch = process.arch;
23
+ // Map Node.js platform/arch to our strings
24
+ if (platform === "darwin" && arch === "arm64") return "darwin-aarch64";
25
+ if (platform === "darwin" && arch === "x64") return "darwin-x86_64";
26
+ if (platform === "linux" && arch === "arm64") return "linux-aarch64";
27
+ if (platform === "linux" && arch === "x64") return "linux-x86_64";
28
+ if (platform === "win32" && arch === "x64") return "win-x86_64";
29
+ if (platform === "win32" && arch === "ia32") return "win-i686";
30
+ return `${platform}-${arch}`;
31
+ };
32
+ /**
33
+ * Build relative path to the cr-sqlite binary within the package.
34
+ * @since 0.16.300
35
+ */
36
+ export const buildRelativeLibraryPath = platform => {
37
+ switch (platform) {
38
+ case "darwin-aarch64":
39
+ case "darwin-x86_64":
40
+ return `lib/${platform}/libcrsqlite.dylib`;
41
+ case "linux-aarch64":
42
+ case "linux-x86_64":
43
+ return `lib/${platform}/libcrsqlite.so`;
44
+ case "win-x86_64":
45
+ case "win-i686":
46
+ return `lib/${platform}/crsqlite.dll`;
47
+ }
48
+ // Exhaustiveness note: if a new Platform variant is added, TypeScript will error
49
+ // unless it is handled above. This fallback exists only for type safety.
50
+ return platform;
51
+ };
52
+ //# sourceMappingURL=platform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.js","names":["SUPPORTED_PLATFORMS","isSupportedPlatform","p","includes","detectPlatform","platform","process","arch","buildRelativeLibraryPath"],"sources":["../../src/platform.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;AAIA;AAcA;;;;AAIA,OAAO,MAAMA,mBAAmB,GAA4B,CAC1D,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,cAAc,EACd,YAAY,EACZ,UAAU,CACF;AAEV;;;;AAIA,OAAO,MAAMC,mBAAmB,GAAIC,CAAS,IAC1CF,mBAA6C,CAACG,QAAQ,CAACD,CAAC,CAAC;AAE5D;;;;AAIA,OAAO,MAAME,cAAc,GAAGA,CAAA,KAAa;EACzC,MAAMC,QAAQ,GAAGC,OAAO,CAACD,QAAQ;EACjC,MAAME,IAAI,GAAGD,OAAO,CAACC,IAAI;EACzB;EACA,IAAIF,QAAQ,KAAK,QAAQ,IAAIE,IAAI,KAAK,OAAO,EAAE,OAAO,gBAAgB;EACtE,IAAIF,QAAQ,KAAK,QAAQ,IAAIE,IAAI,KAAK,KAAK,EAAE,OAAO,eAAe;EACnE,IAAIF,QAAQ,KAAK,OAAO,IAAIE,IAAI,KAAK,OAAO,EAAE,OAAO,eAAe;EACpE,IAAIF,QAAQ,KAAK,OAAO,IAAIE,IAAI,KAAK,KAAK,EAAE,OAAO,cAAc;EACjE,IAAIF,QAAQ,KAAK,OAAO,IAAIE,IAAI,KAAK,KAAK,EAAE,OAAO,YAAY;EAC/D,IAAIF,QAAQ,KAAK,OAAO,IAAIE,IAAI,KAAK,MAAM,EAAE,OAAO,UAAU;EAC9D,OAAO,GAAGF,QAAQ,IAAIE,IAAI,EAAE;AAC9B,CAAC;AAED;;;;AAIA,OAAO,MAAMC,wBAAwB,GAAIH,QAAkB,IAAY;EACrE,QAAQA,QAAQ;IACd,KAAK,gBAAgB;IACrB,KAAK,eAAe;MAClB,OAAO,OAAOA,QAAQ,oBAAoB;IAC5C,KAAK,eAAe;IACpB,KAAK,cAAc;MACjB,OAAO,OAAOA,QAAQ,iBAAiB;IACzC,KAAK,YAAY;IACjB,KAAK,UAAU;MACb,OAAO,OAAOA,QAAQ,eAAe;EACzC;EACA;EACA;EACA,OAAOA,QAAwB;AACjC,CAAC","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Underlying cr-sqlite release version bundled with this package.
3
+ * @since 0.16.300
4
+ */
5
+ export const CRSQLITE_VERSION = "0.16.3";
6
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","names":["CRSQLITE_VERSION"],"sources":["../../src/version.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;AAIA,OAAO,MAAMA,gBAAgB,GAAG,QAAQ","ignoreList":[]}
Binary file
Binary file
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": [],
3
+ "main": "../dist/cjs/effect.js",
4
+ "module": "../dist/esm/effect.js",
5
+ "types": "../dist/dts/effect.d.ts"
6
+ }
package/package.json CHANGED
@@ -1,70 +1,66 @@
1
1
  {
2
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",
3
+ "version": "0.16.301",
4
+ "description": "Absolute paths to cr-sqlite extension binaries for Node.js with optional Effect API",
47
5
  "license": "MIT",
48
6
  "repository": {
49
7
  "type": "git",
50
- "url": "https://github.com/effect-native/cr-sqlite.git"
8
+ "url": "https://github.com/effect-native/effect-native.git",
9
+ "directory": "packages-native/libcrsql"
51
10
  },
52
- "engines": {
53
- "node": ">=16.0.0"
11
+ "sideEffects": [
12
+ "./dist/cjs/index.js",
13
+ "./dist/cjs/paths.js",
14
+ "./dist/cjs/effect.js",
15
+ "./dist/esm/index.js",
16
+ "./dist/esm/paths.js",
17
+ "./dist/esm/effect.js"
18
+ ],
19
+ "homepage": "https://github.com/effect-native/effect-native",
20
+ "peerDependencies": {
21
+ "effect": "*",
22
+ "@effect/platform": "*"
54
23
  },
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"
24
+ "peerDependenciesMeta": {
25
+ "effect": {
26
+ "optional": true
27
+ },
28
+ "@effect/platform": {
29
+ "optional": true
30
+ }
66
31
  },
67
32
  "publishConfig": {
68
- "access": "public"
33
+ "provenance": true
34
+ },
35
+ "main": "./dist/cjs/index.js",
36
+ "module": "./dist/esm/index.js",
37
+ "types": "./dist/dts/index.d.ts",
38
+ "exports": {
39
+ "./package.json": "./package.json",
40
+ ".": {
41
+ "types": "./dist/dts/index.d.ts",
42
+ "import": "./dist/esm/index.js",
43
+ "default": "./dist/cjs/index.js"
44
+ },
45
+ "./paths": {
46
+ "types": "./dist/dts/paths.d.ts",
47
+ "import": "./dist/esm/paths.js",
48
+ "default": "./dist/cjs/paths.js"
49
+ },
50
+ "./effect": {
51
+ "types": "./dist/dts/effect.d.ts",
52
+ "import": "./dist/esm/effect.js",
53
+ "default": "./dist/cjs/effect.js"
54
+ }
55
+ },
56
+ "typesVersions": {
57
+ "*": {
58
+ "paths": [
59
+ "./dist/dts/paths.d.ts"
60
+ ],
61
+ "effect": [
62
+ "./dist/dts/effect.d.ts"
63
+ ]
64
+ }
69
65
  }
70
66
  }
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": [],
3
+ "main": "../dist/cjs/paths.js",
4
+ "module": "../dist/esm/paths.js",
5
+ "types": "../dist/dts/paths.d.ts"
6
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Browser guard for @effect-native/libcrsql.
3
+ * This package is Node.js-only and provides paths to native binaries.
4
+ * @since 0.16.300
5
+ */
6
+ // Importing in browser environments is not supported.
7
+
8
+ const msg = "@effect-native/libcrsql is Node.js-only (native binaries). Browser is not supported."
9
+ throw new Error(msg)
package/src/effect.ts ADDED
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Effect entrypoint: idiomatic Effect API with TaggedError failures.
3
+ *
4
+ * @since 0.16.300
5
+ */
6
+ import { Brand, Data, Effect } from "effect"
7
+ import * as fs from "node:fs"
8
+ import { fileURLToPath } from "node:url"
9
+ import {
10
+ buildRelativeLibraryPath,
11
+ detectPlatform,
12
+ isSupportedPlatform,
13
+ SUPPORTED_PLATFORMS as _SUPPORTED_PLATFORMS
14
+ } from "./platform.js"
15
+ import type { Platform as _Platform } from "./platform.js"
16
+
17
+ /**
18
+ * Error indicating that a platform-arch combination is not supported.
19
+ * @since 0.16.300
20
+ */
21
+ export class PlatformNotSupportedError extends Data.TaggedError("PlatformNotSupportedError")<{
22
+ readonly platform: string
23
+ readonly supportedPlatforms: ReadonlyArray<string>
24
+ readonly detectedArch: string
25
+ readonly detectedPlatform: string
26
+ }> {
27
+ /**
28
+ * @since 0.16.300
29
+ */
30
+ get message() {
31
+ return `Platform "${this.platform}" is not supported. Detected: ${this.detectedPlatform}-${this.detectedArch}. Supported: ${
32
+ this.supportedPlatforms.join(", ")
33
+ }`
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Error indicating that the resolved binary path does not exist.
39
+ * @since 0.16.300
40
+ */
41
+ export class ExtensionNotFoundError extends Data.TaggedError("ExtensionNotFoundError")<{
42
+ readonly path: string
43
+ readonly platform: string
44
+ }> {}
45
+
46
+ /**
47
+ * Branded absolute path to the cr-sqlite binary.
48
+ * @since 0.16.300
49
+ */
50
+ export type ExtensionPath = string & Brand.Brand<"ExtensionPath">
51
+ /**
52
+ * Brand constructor for `ExtensionPath`.
53
+ * @since 0.16.300
54
+ */
55
+ export const ExtensionPath = Brand.nominal<ExtensionPath>()
56
+
57
+ // Uses a best-effort Node fs sync check without depending on @effect/platform.
58
+ /**
59
+ * Effect-based absolute path resolution with idiomatic TaggedError failures.
60
+ *
61
+ * - Succeeds with a branded `ExtensionPath` string.
62
+ * - Fails with `PlatformNotSupportedError` or `ExtensionNotFoundError`.
63
+ *
64
+ * @since 0.16.300
65
+ * @example
66
+ * import { getCrSqliteExtensionPath } from "@effect-native/libcrsql/effect"
67
+ * import { Effect } from "effect"
68
+ *
69
+ * const program = getCrSqliteExtensionPath()
70
+ * Effect.runPromise(program)
71
+ */
72
+ export const getCrSqliteExtensionPath = (
73
+ platform?: Platform
74
+ ): Effect.Effect<ExtensionPath, PlatformNotSupportedError | ExtensionNotFoundError> =>
75
+ Effect.gen(function*() {
76
+ const target = platform ?? detectPlatform()
77
+ if (!isSupportedPlatform(target)) {
78
+ return yield* Effect.fail(
79
+ new PlatformNotSupportedError({
80
+ platform: target,
81
+ supportedPlatforms: SUPPORTED_PLATFORMS,
82
+ detectedArch: process.arch,
83
+ detectedPlatform: process.platform
84
+ })
85
+ )
86
+ }
87
+ const abs = fileURLToPath(new URL(`../${buildRelativeLibraryPath(target)}`, import.meta.url))
88
+
89
+ const exists = yield* Effect.sync(() => {
90
+ try {
91
+ // Synchronous check is acceptable here since this path is computed
92
+ // infrequently and typically only once per process.
93
+ fs.accessSync(abs)
94
+ return true
95
+ } catch {
96
+ return false
97
+ }
98
+ })
99
+
100
+ if (!exists) {
101
+ return yield* Effect.fail(new ExtensionNotFoundError({ path: abs, platform: target }))
102
+ }
103
+
104
+ return ExtensionPath(abs)
105
+ })
106
+
107
+ /**
108
+ * Supported platform-arch identifiers.
109
+ * @since 0.16.300
110
+ */
111
+ export type Platform = _Platform
112
+
113
+ /**
114
+ * List of supported platforms.
115
+ * @since 0.16.300
116
+ */
117
+ export const SUPPORTED_PLATFORMS = _SUPPORTED_PLATFORMS
package/src/index.ts ADDED
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Root entrypoint: absolute path getters with zero external dependencies.
3
+ *
4
+ * @since 0.16.300
5
+ */
6
+ import * as fs from "node:fs"
7
+ import { fileURLToPath } from "node:url"
8
+ import {
9
+ buildRelativeLibraryPath,
10
+ detectPlatform,
11
+ isSupportedPlatform,
12
+ SUPPORTED_PLATFORMS as _SUPPORTED_PLATFORMS
13
+ } from "./platform.js"
14
+ import { CRSQLITE_VERSION as _CRSQLITE_VERSION } from "./version.js"
15
+
16
+ import type { Platform as _Platform } from "./platform.js"
17
+
18
+ /**
19
+ * Synchronous absolute path resolution for the cr-sqlite extension binary.
20
+ *
21
+ * - Returns an absolute path string that you can pass to `db.loadExtension()`.
22
+ * - Throws native Error with `code` set to `ERR_PLATFORM_UNSUPPORTED` or
23
+ * `ERR_EXTENSION_NOT_FOUND`.
24
+ *
25
+ * @since 0.16.300
26
+ * @example
27
+ * import { getCrSqliteExtensionPathSync } from "@effect-native/libcrsql"
28
+ *
29
+ * const path = getCrSqliteExtensionPathSync()
30
+ * console.log(path)
31
+ */
32
+ export const getCrSqliteExtensionPathSync = (platform?: Platform): string => {
33
+ const target = platform ?? detectPlatform()
34
+ if (!isSupportedPlatform(target)) {
35
+ const err: NodeJS.ErrnoException = new Error(
36
+ `Platform "${target}" is not supported. Detected: ${process.platform}-${process.arch}. Supported: ${
37
+ SUPPORTED_PLATFORMS.join(", ")
38
+ }`
39
+ )
40
+ err.code = "ERR_PLATFORM_UNSUPPORTED"
41
+ throw err
42
+ }
43
+ const abs = fileURLToPath(new URL(`../${buildRelativeLibraryPath(target)}`, import.meta.url))
44
+ // Best-effort existence check without external deps.
45
+ // Note: this synchronous check runs once per import/use and ensures the
46
+ // contract of this package (absolute path to an existing native binary).
47
+ // If needed, we can memoize this at runtime, but import memoization already
48
+ // avoids repeated work in typical usage.
49
+ try {
50
+ fs.accessSync(abs)
51
+ } catch {
52
+ const err: NodeJS.ErrnoException = new Error(`Extension binary not found: ${abs}`)
53
+ err.code = "ERR_EXTENSION_NOT_FOUND"
54
+ throw err
55
+ }
56
+ return abs
57
+ }
58
+
59
+ /**
60
+ * Absolute path to the cr-sqlite binary for the current platform, computed at import time.
61
+ *
62
+ * - Useful for the simplest use cases: just import and load.
63
+ * - Throws on unsupported platform or if the binary is not present.
64
+ *
65
+ * @since 0.16.300
66
+ * @example
67
+ * import { pathToCrSqliteExtension } from "@effect-native/libcrsql"
68
+ * console.log(pathToCrSqliteExtension)
69
+ */
70
+ export const pathToCrSqliteExtension: string = getCrSqliteExtensionPathSync()
71
+
72
+ /**
73
+ * Supported platform-arch identifiers.
74
+ * @since 0.16.300
75
+ */
76
+ export type Platform = _Platform
77
+
78
+ /**
79
+ * List of supported platforms.
80
+ * @since 0.16.300
81
+ */
82
+ export const SUPPORTED_PLATFORMS = _SUPPORTED_PLATFORMS
83
+ /**
84
+ * Bundled upstream cr-sqlite version.
85
+ * @since 0.16.300
86
+ */
87
+ export const CRSQLITE_VERSION = _CRSQLITE_VERSION
package/src/paths.ts ADDED
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Absolute paths per-platform. These are computed from this module location
3
+ * using Node built-ins only (no external dependencies, no I/O).
4
+ *
5
+ * @since 0.16.300
6
+ */
7
+ import { fileURLToPath } from "node:url"
8
+
9
+ /**
10
+ * Absolute path to darwin-aarch64 cr-sqlite dylib.
11
+ * @since 0.16.300
12
+ */
13
+ export const darwin_aarch64 = fileURLToPath(new URL("../lib/darwin-aarch64/libcrsqlite.dylib", import.meta.url))
14
+ /**
15
+ * Absolute path to darwin-x86_64 cr-sqlite dylib.
16
+ * @since 0.16.300
17
+ */
18
+ export const darwin_x86_64 = fileURLToPath(new URL("../lib/darwin-x86_64/libcrsqlite.dylib", import.meta.url))
19
+ /**
20
+ * Absolute path to linux-aarch64 cr-sqlite so.
21
+ * @since 0.16.300
22
+ */
23
+ export const linux_aarch64 = fileURLToPath(new URL("../lib/linux-aarch64/libcrsqlite.so", import.meta.url))
24
+ /**
25
+ * Absolute path to linux-x86_64 cr-sqlite so.
26
+ * @since 0.16.300
27
+ */
28
+ export const linux_x86_64 = fileURLToPath(new URL("../lib/linux-x86_64/libcrsqlite.so", import.meta.url))
29
+ /**
30
+ * Absolute path to win-x86_64 cr-sqlite dll.
31
+ * @since 0.16.300
32
+ */
33
+ export const win_x86_64 = fileURLToPath(new URL("../lib/win-x86_64/crsqlite.dll", import.meta.url))
34
+ /**
35
+ * Absolute path to win-i686 cr-sqlite dll.
36
+ * @since 0.16.300
37
+ */
38
+ export const win_i686 = fileURLToPath(new URL("../lib/win-i686/crsqlite.dll", import.meta.url))
39
+
40
+ /**
41
+ * Map of platform name to absolute path.
42
+ * @since 0.16.300
43
+ */
44
+ export type Paths = {
45
+ readonly [K in "darwin_aarch64" | "darwin_x86_64" | "linux_aarch64" | "linux_x86_64" | "win_x86_64" | "win_i686"]:
46
+ string
47
+ }