@photostructure/sqlite 0.0.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.
Files changed (53) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/LICENSE +21 -0
  3. package/README.md +522 -0
  4. package/SECURITY.md +114 -0
  5. package/binding.gyp +94 -0
  6. package/dist/index.cjs +134 -0
  7. package/dist/index.cjs.map +1 -0
  8. package/dist/index.d.cts +408 -0
  9. package/dist/index.d.mts +408 -0
  10. package/dist/index.d.ts +408 -0
  11. package/dist/index.mjs +103 -0
  12. package/dist/index.mjs.map +1 -0
  13. package/package.json +144 -0
  14. package/prebuilds/darwin-arm64/@photostructure+sqlite.glibc.node +0 -0
  15. package/prebuilds/linux-arm64/@photostructure+sqlite.glibc.node +0 -0
  16. package/prebuilds/linux-arm64/@photostructure+sqlite.musl.node +0 -0
  17. package/prebuilds/linux-x64/@photostructure+sqlite.glibc.node +0 -0
  18. package/prebuilds/linux-x64/@photostructure+sqlite.musl.node +0 -0
  19. package/prebuilds/win32-x64/@photostructure+sqlite.glibc.node +0 -0
  20. package/scripts/post-build.mjs +21 -0
  21. package/scripts/prebuild-linux-glibc.sh +108 -0
  22. package/src/aggregate_function.cpp +417 -0
  23. package/src/aggregate_function.h +116 -0
  24. package/src/binding.cpp +160 -0
  25. package/src/dirname.ts +13 -0
  26. package/src/index.ts +465 -0
  27. package/src/shims/base_object-inl.h +8 -0
  28. package/src/shims/base_object.h +50 -0
  29. package/src/shims/debug_utils-inl.h +23 -0
  30. package/src/shims/env-inl.h +19 -0
  31. package/src/shims/memory_tracker-inl.h +17 -0
  32. package/src/shims/napi_extensions.h +73 -0
  33. package/src/shims/node.h +16 -0
  34. package/src/shims/node_errors.h +66 -0
  35. package/src/shims/node_mem-inl.h +8 -0
  36. package/src/shims/node_mem.h +31 -0
  37. package/src/shims/node_url.h +23 -0
  38. package/src/shims/promise_resolver.h +31 -0
  39. package/src/shims/util-inl.h +18 -0
  40. package/src/shims/util.h +101 -0
  41. package/src/sqlite_impl.cpp +2440 -0
  42. package/src/sqlite_impl.h +314 -0
  43. package/src/stack_path.ts +64 -0
  44. package/src/types/node-gyp-build.d.ts +4 -0
  45. package/src/upstream/node_sqlite.cc +2706 -0
  46. package/src/upstream/node_sqlite.h +234 -0
  47. package/src/upstream/sqlite.gyp +38 -0
  48. package/src/upstream/sqlite.js +19 -0
  49. package/src/upstream/sqlite3.c +262809 -0
  50. package/src/upstream/sqlite3.h +13773 -0
  51. package/src/upstream/sqlite3ext.h +723 -0
  52. package/src/user_function.cpp +225 -0
  53. package/src/user_function.h +40 -0
package/package.json ADDED
@@ -0,0 +1,144 @@
1
+ {
2
+ "name": "@photostructure/sqlite",
3
+ "version": "0.0.1",
4
+ "description": "Drop-in replacement for node:sqlite",
5
+ "homepage": "https://photostructure.github.io/node-sqlite/",
6
+ "types": "./dist/index.d.ts",
7
+ "main": "./dist/index.cjs",
8
+ "module": "./dist/index.mjs",
9
+ "exports": {
10
+ ".": {
11
+ "require": {
12
+ "types": "./dist/index.d.cts",
13
+ "default": "./dist/index.cjs"
14
+ },
15
+ "import": {
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.mjs"
18
+ }
19
+ },
20
+ "./package.json": "./package.json"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/photostructure/node-sqlite.git"
25
+ },
26
+ "license": "MIT",
27
+ "private": false,
28
+ "scripts": {
29
+ "install": "node-gyp-build",
30
+ "clean": "run-p clean:*",
31
+ "clean:dist": "del-cli dist \"*.tsbuildinfo\"",
32
+ "clean:native": "node-gyp clean",
33
+ "sync:node": "tsx scripts/sync-from-node.ts",
34
+ "sync:sqlite": "tsx scripts/sync-from-sqlite.ts",
35
+ "node-gyp-rebuild": "node-gyp rebuild",
36
+ "build": "run-p build:native build:dist",
37
+ "build:native": "prebuildify --napi --tag-libc --strip",
38
+ "build:linux-glibc": "bash scripts/prebuild-linux-glibc.sh",
39
+ "build:dist": "tsup && node scripts/post-build.mjs",
40
+ "tests": "run-s tests:*",
41
+ "tests:cjs": "jest",
42
+ "tests:esm": "cross-env TEST_ESM=1 node --experimental-vm-modules --no-warnings node_modules/jest/bin/jest.js",
43
+ "// test": "support `npm t name_of_file` (and don't fail due to missing coverage)",
44
+ "test": "npm run tests:cjs -- --no-coverage",
45
+ "test:serial": "npm run tests:cjs -- --runInBand --no-coverage",
46
+ "test:all": "run-s \"tests:cjs -- {@}\" \"tests:esm -- {@}\" --",
47
+ "// test:api-compat": "run by the api compability CI workflow",
48
+ "test:api-compat": "jest --config jest.config.api-compat.cjs",
49
+ "test:node-compat": "cross-env NODE_OPTIONS=\"--experimental-sqlite --no-warnings\" npm run tests:cjs -- --no-coverage test/node-compatibility.test.ts",
50
+ "test:build-extension": "cd test/fixtures/test-extension && node build.js",
51
+ "memory:test": "cross-env TEST_MEMORY=1 node --expose-gc node_modules/jest/bin/jest.js --no-coverage test/memory.test.ts",
52
+ "memory:valgrind": "bash scripts/valgrind-test.sh",
53
+ "memory:asan": "bash scripts/sanitizers-test.sh",
54
+ "check:memory": "node scripts/check-memory.mjs",
55
+ "benchmark": "cd benchmark && npm install && npm run bench",
56
+ "benchmark:memory": "cd benchmark && npm install && npm run bench:memory",
57
+ "benchmark:full": "cd benchmark && npm install && npm run bench && npm run bench:memory",
58
+ "lint": "run-p lint:*",
59
+ "lint:ts": "tsc --noEmit",
60
+ "lint:ts-build": "tsc -p tsconfig.build.json --noEmit",
61
+ "lint:ts-scripts": "tsc --noEmit --module esnext --target es2022 --moduleResolution node --project scripts/tsconfig.json",
62
+ "lint:eslint": "eslint src/ test/",
63
+ "// lint:api-compat": "run by the api compability CI workflow",
64
+ "lint:api-compat": "tsx scripts/check-api-compat.ts",
65
+ "lint:native": "tsx scripts/clang-tidy.ts",
66
+ "fmt": "run-p fmt:*",
67
+ "fmt:ts": "prettier --write \"**/*.{ts,js,mjs,json,md}\"",
68
+ "// fmt:native": "on ubuntu: `sudo apt install clang-format`. NOTE: we don't reformat src/upstream!",
69
+ "fmt:native": "clang-format --style=LLVM -i src/shims/*.h src/*.cpp src/*.h test/fixtures/test-extension/*.c || true",
70
+ "docs": "typedoc",
71
+ "// precommit": "should be manually run by developers before they run `git commit`",
72
+ "precommit": "tsx scripts/precommit.ts",
73
+ "prepare-release": "npm run build:dist",
74
+ "release": "release-it",
75
+ "security": "run-s security:*",
76
+ "security:audit": "npm audit --production",
77
+ "security:audit-fix": "npm audit fix --force",
78
+ "security:osv": "if command -v osv-scanner >/dev/null 2>&1; then osv-scanner scan source --recursive .; else echo 'OSV Scanner not installed. Install with: go install github.com/google/osv-scanner/cmd/osv-scanner@latest'; fi",
79
+ "xsecurity:snyk": "snyk test"
80
+ },
81
+ "gypfile": true,
82
+ "publishConfig": {
83
+ "access": "public"
84
+ },
85
+ "engines": {
86
+ "node": ">=20.0.0"
87
+ },
88
+ "os": [
89
+ "darwin",
90
+ "linux",
91
+ "win32"
92
+ ],
93
+ "cpu": [
94
+ "x64",
95
+ "arm64"
96
+ ],
97
+ "keywords": [
98
+ "sqlite",
99
+ "node:sqlite",
100
+ "drop-in-replacement",
101
+ "database",
102
+ "sql",
103
+ "native",
104
+ "node-addon",
105
+ "DatabaseSync",
106
+ "StatementSync",
107
+ "sync",
108
+ "performance"
109
+ ],
110
+ "dependencies": {
111
+ "node-addon-api": "^8.3.1",
112
+ "node-gyp-build": "^4.8.4"
113
+ },
114
+ "devDependencies": {
115
+ "@eslint/js": "^9.28.0",
116
+ "@types/jest": "^29.5.14",
117
+ "@types/node": "^24.0.1",
118
+ "@typescript-eslint/eslint-plugin": "^8.34.0",
119
+ "@typescript-eslint/parser": "^8.34.0",
120
+ "cross-env": "^7.0.3",
121
+ "del-cli": "^6.0.0",
122
+ "eslint": "^9.28.0",
123
+ "eslint-plugin-regexp": "^2.9.0",
124
+ "globals": "^16.2.0",
125
+ "jest": "^29.7.0",
126
+ "node-gyp": "^11.2.0",
127
+ "npm-run-all": "4.1.5",
128
+ "prebuildify": "^6.0.1",
129
+ "prettier": "^3.5.3",
130
+ "prettier-plugin-organize-imports": "^4.1.0",
131
+ "release-it": "^19.0.3",
132
+ "snyk": "^1.1297.1",
133
+ "ts-jest": "^29.3.4",
134
+ "tsup": "^8.5.0",
135
+ "tsx": "^4.20.1",
136
+ "typedoc": "^0.28.5",
137
+ "typescript": "^5.8.3",
138
+ "typescript-eslint": "^8.34.0"
139
+ },
140
+ "versions": {
141
+ "nodejs": "v24.2.1@b854f4d",
142
+ "sqlite": "3.50.1"
143
+ }
144
+ }
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { copyFile } from "fs/promises";
4
+ import { dirname, join } from "path";
5
+ import { fileURLToPath } from "url";
6
+
7
+ const __dirname = dirname(fileURLToPath(import.meta.url));
8
+ const distDir = join(__dirname, "..", "dist");
9
+
10
+ // Copy .d.ts to .d.cts for CommonJS type safety
11
+ async function createCjsTypes() {
12
+ try {
13
+ await copyFile(join(distDir, "index.d.ts"), join(distDir, "index.d.cts"));
14
+ console.log("Created index.d.cts for CommonJS type safety");
15
+ } catch (error) {
16
+ console.error("Error creating .d.cts file:", error);
17
+ process.exit(1);
18
+ }
19
+ }
20
+
21
+ createCjsTypes();
@@ -0,0 +1,108 @@
1
+ #!/bin/bash
2
+ # Build native module with portable GLIBC compatibility
3
+ # Uses Debian 11 Bullseye (GLIBC 2.31) to balance compatibility and modern toolchain
4
+ #
5
+ # GLIBC versions in official Node.js Docker images:
6
+ # - node:*-buster: GLIBC 2.28 (Debian 10) - Python 3.7, GCC 8.3 (too old)
7
+ # - node:*-bullseye: GLIBC 2.31 (Debian 11) - Python 3.9, GCC 10.2 (good balance)
8
+ # - node:*-bookworm: GLIBC 2.36 (Debian 12) - Python 3.11, GCC 12.2
9
+ # - node:* (default): GLIBC 2.36 (Debian 12 Bookworm)
10
+ # - node:*-alpine: musl libc (not GLIBC)
11
+ #
12
+ # Other common environments:
13
+ # - Ubuntu 20.04 LTS: GLIBC 2.31 (matches our target)
14
+ # - Ubuntu 22.04 LTS: GLIBC 2.35
15
+ # - CentOS 7: GLIBC 2.17 (EOL, not supported)
16
+ # - Amazon Linux 2: GLIBC 2.26 (older, but should work)
17
+ #
18
+ # By targeting GLIBC 2.31, we support Ubuntu 20.04 LTS and newer,
19
+ # while having a modern enough toolchain for Node.js requirements.
20
+
21
+ set -euo pipefail
22
+
23
+ # Allow architecture override (for CI cross-compilation)
24
+ TARGET_ARCH="${TARGET_ARCH:-}"
25
+
26
+ # If no target architecture specified, detect from host
27
+ if [ -z "$TARGET_ARCH" ]; then
28
+ ARCH=$(uname -m)
29
+ if [ "$ARCH" = "x86_64" ]; then
30
+ TARGET_ARCH="x64"
31
+ elif [ "$ARCH" = "aarch64" ]; then
32
+ TARGET_ARCH="arm64"
33
+ else
34
+ echo "Unsupported architecture: $ARCH"
35
+ exit 1
36
+ fi
37
+ fi
38
+
39
+ # Map to Docker platform architecture
40
+ if [ "$TARGET_ARCH" = "x64" ]; then
41
+ DOCKER_ARCH="amd64"
42
+ elif [ "$TARGET_ARCH" = "arm64" ]; then
43
+ DOCKER_ARCH="arm64"
44
+ else
45
+ echo "Unsupported target architecture: $TARGET_ARCH"
46
+ exit 1
47
+ fi
48
+
49
+ # Determine which build command to use
50
+ BUILD_CMD="${BUILD_CMD:-npm run build:native}"
51
+
52
+ # Check if we're already in a compatible environment
53
+ if [ -f /etc/os-release ]; then
54
+ . /etc/os-release
55
+ if [[ "${ID:-}" == "debian" && "${VERSION_ID:-}" == "11" ]]; then
56
+ echo "Already in Debian 11 Bullseye, building directly..."
57
+ $BUILD_CMD
58
+ exit 0
59
+ fi
60
+ fi
61
+
62
+ # Check if Docker is available
63
+ if ! command -v docker &> /dev/null; then
64
+ echo "Docker not found, falling back to local build"
65
+ echo "Warning: Binary may not be portable due to GLIBC version"
66
+ $BUILD_CMD
67
+ exit 0
68
+ fi
69
+
70
+ echo "Building native module in Debian 11 Bullseye container for GLIBC 2.31 compatibility..."
71
+ echo "Target architecture: $TARGET_ARCH (Docker platform: linux/$DOCKER_ARCH)"
72
+
73
+ # Create a container, build inside it, then copy artifacts out
74
+ CONTAINER_NAME="node-sqlite-build-$$"
75
+
76
+ # Start container in background
77
+ docker run -d \
78
+ --name "$CONTAINER_NAME" \
79
+ --platform "linux/$DOCKER_ARCH" \
80
+ node:20-bullseye \
81
+ sleep 3600
82
+
83
+ # Copy project files into container
84
+ docker cp . "$CONTAINER_NAME:/tmp/project"
85
+
86
+ # Run build inside container
87
+ # Debian 11 has Python 3.9 and GCC 10.2 which support our requirements
88
+ docker exec "$CONTAINER_NAME" sh -c "
89
+ cd /tmp/project && \
90
+ apt-get update -qq && \
91
+ apt-get install -y -qq build-essential python3 && \
92
+ # Verify versions
93
+ echo 'Python version:' && python3 --version && \
94
+ echo 'GCC version:' && gcc --version | head -1 && \
95
+ # Build the project
96
+ npm ci --ignore-scripts && \
97
+ $BUILD_CMD
98
+ "
99
+
100
+ # Copy artifacts back with proper ownership
101
+ docker cp "$CONTAINER_NAME:/tmp/project/prebuilds" . 2>/dev/null || true
102
+ docker cp "$CONTAINER_NAME:/tmp/project/build" . 2>/dev/null || true
103
+ docker cp "$CONTAINER_NAME:/tmp/project/config.gypi" . 2>/dev/null || true
104
+
105
+ # Clean up container
106
+ docker rm -f "$CONTAINER_NAME" >/dev/null
107
+
108
+ echo "Portable build complete!"