Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ node_modules

docs/.vitepress/dist
docs/.vitepress/cache

CLAUDE.md
27 changes: 27 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
description = "PGLite mobile build env";

inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";

outputs = { self, nixpkgs }:
let
forAllSystems = f:
nixpkgs.lib.genAttrs [ "aarch64-darwin" "x86_64-darwin" "x86_64-linux" ] (system:
f (import nixpkgs { inherit system; config = { allowUnfree = true; android_sdk.accept_license = true; }; })
);
in {
devShells = forAllSystems (pkgs:
let
android = pkgs.androidenv.composeAndroidPackages {
platformVersions = [ "34" ];
buildToolsVersions = [ "35.0.0" ];
ndkVersions = [ "27.1.12297006" ];
cmakeVersions = [ "3.22.1" ];
includeEmulator = false;
# Ensure NDK is included in the SDK closure
includeNDK = true;
};
commonPkgs = with pkgs; [
gnumake perl pkg-config coreutils gnused gawk python3
];
in {
android = pkgs.mkShell {
packages = commonPkgs ++ [ android.androidsdk ];
shellHook = ''
export ANDROID_SDK_ROOT=${android.androidsdk}/libexec/android-sdk
# Prefer standard ndk-bundle path if present (older layouts)
if [ -d "$ANDROID_SDK_ROOT/ndk-bundle" ]; then
export ANDROID_NDK_ROOT="$ANDROID_SDK_ROOT/ndk-bundle"
export ANDROID_NDK="$ANDROID_NDK_ROOT"
else
# Try pinned version directory from composeAndroidPackages
if [ -d "$ANDROID_SDK_ROOT/ndk/27.1.12297006" ]; then
export ANDROID_NDK="$ANDROID_SDK_ROOT/ndk/27.1.12297006"
else
# Fallback: pick first ndk version
first_ndk=$(ls -1 "$ANDROID_SDK_ROOT/ndk" 2>/dev/null | head -n1 || true)
if [ -n "$first_ndk" ]; then export ANDROID_NDK="$ANDROID_SDK_ROOT/ndk/$first_ndk"; fi
fi
fi
if [ -d "$ANDROID_NDK/toolchains/llvm/prebuilt" ]; then
export PATH="$ANDROID_NDK/toolchains/llvm/prebuilt/*/bin:$PATH"
elif [ -d "$ANDROID_NDK/toolchains/llvm/bin" ]; then
export PATH="$ANDROID_NDK/toolchains/llvm/bin:$PATH"
fi
export MAKE=gmake
echo "Android devShell ready: ANDROID_NDK=$ANDROID_NDK"
'';
};

ios = pkgs.mkShell {
packages = commonPkgs;
shellHook = ''
export MAKE=gmake
echo "iOS devShell ready (requires Xcode/CLT for xcrun/SDKs)"
'';
};
}
);
};
}

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
"prettier": "3.3.3",
"tsup": "^8.3.0",
"tsx": "^4.19.1",
"typescript": "^5.6.3"
"typescript": "~5.6.3"
},
"dependencies": {
"@types/node": "^20.16.11"
}
}
139 changes: 139 additions & 0 deletions packages/pglite-base/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{
"name": "@electric-sql/pglite-base",
"version": "0.3.7",
"private": false,
"publishConfig": {
"access": "public"
},
"description": "PGlite base package containing non-web-specific PostgreSQL WASM functionality for use in Node.js, Bun, and other non-browser environments.",
"keywords": [
"postgres",
"sql",
"database",
"wasm",
"client",
"pglite",
"base"
],
"author": "Electric DB Limited",
"homepage": "https://pglite.dev",
"license": "Apache-2.0",
"main": "dist/index.cjs",
"module": "dist/index.js",
"exports": {
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
},
"./template": {
"import": {
"types": "./dist/templating.d.ts",
"default": "./dist/templating.js"
},
"require": {
"types": "./dist/templating.d.cts",
"default": "./dist/templating.cjs"
}
},
"./vector": {
"import": {
"types": "./dist/vector/index.d.ts",
"default": "./dist/vector/index.js"
},
"require": {
"types": "./dist/vector/index.d.cts",
"default": "./dist/vector/index.cjs"
}
},
"./pg_ivm": {
"import": {
"types": "./dist/pg_ivm/index.d.ts",
"default": "./dist/pg_ivm/index.js"
},
"require": {
"types": "./dist/pg_ivm/index.d.cts",
"default": "./dist/pg_ivm/index.cjs"
}
},
"./nodefs": {
"import": {
"types": "./dist/fs/nodefs.d.ts",
"default": "./dist/fs/nodefs.js"
},
"require": {
"types": "./dist/fs/nodefs.d.cts",
"default": "./dist/fs/nodefs.cjs"
}
},
"./basefs": {
"import": {
"types": "./dist/fs/base.d.ts",
"default": "./dist/fs/base.js"
},
"require": {
"types": "./dist/fs/base.d.cts",
"default": "./dist/fs/base.cjs"
}
},
"./contrib/*": {
"types": "./dist/contrib/*.d.ts",
"import": "./dist/contrib/*.js",
"require": "./dist/contrib/*.cjs"
},
"./src/postgresMod": {
"import": {
"types": "./dist/postgresMod.d.ts",
"default": "./dist/postgresMod.js"
},
"require": {
"types": "./dist/postgresMod.d.cts",
"default": "./dist/postgresMod.cjs"
}
}
},
"type": "module",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "https://github.com/electric-sql/pglite",
"directory": "packages/pglite-base"
},
"scripts": {
"check:exports": "attw . --pack --profile node16",
"test": "pnpm test:basic && pnpm test:node",
"test:basic": "pnpm test:clean && vitest tests/*.test.js tests/*.test.ts tests/**/*.test.js tests/**/*.test.ts",
"test:node": "pnpm test:clean && pnpm vitest tests/targets/runtimes/node-*.test.js",
"test:clean": "rm -rf ./pgdata-test",
"build": "tsup",
"build:js": "tsup",
"lint": "eslint ./src --report-unused-disable-directives --max-warnings 0",
"format": "prettier --write ./src",
"typecheck": "tsc --noEmit",
"stylecheck": "pnpm lint && prettier --check ./src",
"prepublishOnly": "pnpm check:exports"
},
"dependencies": {
"tinytar": "^0.1.0"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.18.1",
"@electric-sql/pg-protocol": "workspace:*",
"@types/emscripten": "^1.39.13",
"@types/node": "^20.16.11",
"@types/node-fetch": "^2.6.11",
"async-mutex": "^0.4.1",
"buffer": "^6.0.3",
"bun": "^1.1.30",
"tsup": "^8.5.0",
"vitest": "^2.1.2"
}
}
File renamed without changes.
16 changes: 16 additions & 0 deletions packages/pglite-base/src/contrib/amcheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type {
Extension,
ExtensionSetupResult,
PGliteInterface,
} from '../interface'

const setup = async (_pg: PGliteInterface, _emscriptenOpts: any) => {
return {
bundlePath: new URL('../../release/amcheck.tar.gz', import.meta.url),
} satisfies ExtensionSetupResult
}

export const amcheck = {
name: 'amcheck',
setup,
} satisfies Extension
16 changes: 16 additions & 0 deletions packages/pglite-base/src/contrib/auto_explain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type {
Extension,
ExtensionSetupResult,
PGliteInterface,
} from '../interface'

const setup = async (_pg: PGliteInterface, _emscriptenOpts: any) => {
return {
bundlePath: new URL('../../release/auto_explain.tar.gz', import.meta.url),
} satisfies ExtensionSetupResult
}

export const auto_explain = {
name: 'auto_explain',
setup,
} satisfies Extension
16 changes: 16 additions & 0 deletions packages/pglite-base/src/contrib/bloom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type {
Extension,
ExtensionSetupResult,
PGliteInterface,
} from '../interface'

const setup = async (_pg: PGliteInterface, _emscriptenOpts: any) => {
return {
bundlePath: new URL('../../release/bloom.tar.gz', import.meta.url),
} satisfies ExtensionSetupResult
}

export const bloom = {
name: 'bloom',
setup,
} satisfies Extension
16 changes: 16 additions & 0 deletions packages/pglite-base/src/contrib/btree_gin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type {
Extension,
ExtensionSetupResult,
PGliteInterface,
} from '../interface'

const setup = async (_pg: PGliteInterface, _emscriptenOpts: any) => {
return {
bundlePath: new URL('../../release/btree_gin.tar.gz', import.meta.url),
} satisfies ExtensionSetupResult
}

export const btree_gin = {
name: 'btree_gin',
setup,
} satisfies Extension
16 changes: 16 additions & 0 deletions packages/pglite-base/src/contrib/btree_gist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type {
Extension,
ExtensionSetupResult,
PGliteInterface,
} from '../interface'

const setup = async (_pg: PGliteInterface, _emscriptenOpts: any) => {
return {
bundlePath: new URL('../../release/btree_gist.tar.gz', import.meta.url),
} satisfies ExtensionSetupResult
}

export const btree_gist = {
name: 'btree_gist',
setup,
} satisfies Extension
16 changes: 16 additions & 0 deletions packages/pglite-base/src/contrib/citext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type {
Extension,
ExtensionSetupResult,
PGliteInterface,
} from '../interface'

const setup = async (_pg: PGliteInterface, _emscriptenOpts: any) => {
return {
bundlePath: new URL('../../release/citext.tar.gz', import.meta.url),
} satisfies ExtensionSetupResult
}

export const citext = {
name: 'citext',
setup,
} satisfies Extension
16 changes: 16 additions & 0 deletions packages/pglite-base/src/contrib/cube.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type {
Extension,
ExtensionSetupResult,
PGliteInterface,
} from '../interface'

const setup = async (_pg: PGliteInterface, _emscriptenOpts: any) => {
return {
bundlePath: new URL('../../release/cube.tar.gz', import.meta.url),
} satisfies ExtensionSetupResult
}

export const cube = {
name: 'cube',
setup,
} satisfies Extension
16 changes: 16 additions & 0 deletions packages/pglite-base/src/contrib/earthdistance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type {
Extension,
ExtensionSetupResult,
PGliteInterface,
} from '../interface'

const setup = async (_pg: PGliteInterface, _emscriptenOpts: any) => {
return {
bundlePath: new URL('../../release/earthdistance.tar.gz', import.meta.url),
} satisfies ExtensionSetupResult
}

export const earthdistance = {
name: 'earthdistance',
setup,
} satisfies Extension
Loading