diff --git a/.changeset/cold-spiders-poke.md b/.changeset/cold-spiders-poke.md new file mode 100644 index 0000000..28cf2c7 --- /dev/null +++ b/.changeset/cold-spiders-poke.md @@ -0,0 +1,5 @@ +--- +"@powersync/sql-js": patch +--- + +Update PowerSync SQLite core extension to version 0.5.1 diff --git a/.github/workflows/build-package.yaml b/.github/workflows/build-package.yaml index 5a40f91..ba8ab58 100644 --- a/.github/workflows/build-package.yaml +++ b/.github/workflows/build-package.yaml @@ -9,23 +9,17 @@ jobs: name: Build Packages runs-on: ubuntu-latest steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v7 with: persist-credentials: false - - uses: pnpm/action-setup@v4 - name: Install pnpm - + - name: Enable Corepack + run: corepack enable - name: Setup NodeJS - uses: actions/setup-node@v6 + uses: actions/setup-node@v7 with: node-version-file: ".nvmrc" cache: pnpm - - - name: Update npm - run: | - npm install -g npm@latest - npm --version - name: Install dependencies run: pnpm install @@ -36,7 +30,7 @@ jobs: sudo apt-get install -y libdigest-sha3-perl - name: Setup Emscripten - uses: mymindstorm/setup-emsdk@v14 + uses: emscripten-core/setup-emsdk@v16 with: version: "latest" actions-cache-folder: "emsdk-cache" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 88fa5b1..2dd67cd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,21 +20,15 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout Repo - uses: actions/checkout@v5 - - uses: pnpm/action-setup@v4 - name: Install pnpm - with: - run_install: false + uses: actions/checkout@v7 + - name: Enable Corepack + run: corepack enable - name: Setup NodeJS uses: actions/setup-node@v6 with: node-version-file: ".nvmrc" cache: pnpm - - name: Update npm - run: | - npm install -g npm@latest - npm --version - name: Install dependencies run: pnpm install @@ -45,9 +39,9 @@ jobs: sudo apt-get install -y libdigest-sha3-perl - name: Setup Emscripten - uses: mymindstorm/setup-emsdk@v14 + uses: emscripten-core/setup-emsdk@v16 with: - version: 4.0.10 + version: "latest" actions-cache-folder: "emsdk-cache" - name: Build diff --git a/.nvmrc b/.nvmrc index f3a1a23..4c1a08d 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -v24.10.0 +v26.5.0 diff --git a/build.sh b/build.sh index 7041c11..c380daf 100755 --- a/build.sh +++ b/build.sh @@ -1,7 +1,7 @@ #!/bin/sh set -e -POWERSYNC_CORE_VERSION="0.4.12" +POWERSYNC_CORE_VERSION="0.5.1" SQLITE_PATH="sql.js" if [ -d "$SQLITE_PATH" ]; then diff --git a/package.json b/package.json index 1ec4175..be210b2 100644 --- a/package.json +++ b/package.json @@ -31,5 +31,5 @@ "devDependencies": { "@changesets/cli": "^2.29.5" }, - "packageManager": "pnpm@10.19.0+sha512.c9fc7236e92adf5c8af42fd5bf1612df99c2ceb62f27047032f4720b33f8eacdde311865e91c411f2774f618d82f320808ecb51718bfa82c060c4ba7c76a32b8" + "packageManager": "pnpm@11.17.0+sha512.cca3cea332ad254bb84145f966d19f4879615210346fc92c79a047f23a0d7b3cca3c3792f0076ba1f1831d277efbcf0a9119b31a9a60eca7fb3d6231f331ef72" } diff --git a/patches/powersync-update-002.patch b/patches/powersync-update-002.patch deleted file mode 100644 index e321dc3..0000000 --- a/patches/powersync-update-002.patch +++ /dev/null @@ -1,16 +0,0 @@ -diff --git a/src/api.js b/src/api.js -index c7f102b..2d2d106 100644 ---- a/src/api.js -+++ b/src/api.js -@@ -613,6 +613,11 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { - if (val === null) { - return this.bindNull(pos); - } -+ -+ // Add ArrayBuffer support -+ if (val instanceof ArrayBuffer) { -+ return this.bindBlob(new Uint8Array(val), pos); -+ } - if (val.length != null) { - return this.bindBlob(val, pos); - } diff --git a/patches/powersync-update.patch b/patches/powersync-update.patch deleted file mode 100644 index 535c9ff..0000000 --- a/patches/powersync-update.patch +++ /dev/null @@ -1,34 +0,0 @@ -diff --git a/src/update.c b/src/update.c -new file mode 100644 -index 0000000..c7e8a23 ---- /dev/null -+++ b/src/update.c -@@ -0,0 +1,28 @@ -+#include "sqlite3ext.h" -+SQLITE_EXTENSION_INIT1 -+ -+#include -+#include -+#include -+ -+EM_JS(void, call_js_update_hook, (int db_p, int type, const char* db_name, const char* table_name), { -+ if (typeof onSqliteUpdate === "function") { -+ onSqliteUpdate(db_p, type, UTF8ToString(db_name), UTF8ToString(table_name)); -+ } else { -+ console.error("onSqliteUpdate is not defined"); -+ } -+}); -+ -+static void sqlite_update_callback(void* pArg, int type, const char* db, const char* table, sqlite3_int64 rowid) { -+ call_js_update_hook((int)(intptr_t)pArg, type, db, table); -+} -+ -+static int register_update_hook_on_open(sqlite3* db, const char** pzErrMsg, const sqlite3_api_routines* pApi) { -+ SQLITE_EXTENSION_INIT2(pApi); -+ sqlite3_update_hook(db, sqlite_update_callback, db); -+ return SQLITE_OK; -+} -+ -+void register_update_hook_extension(void) { -+ sqlite3_auto_extension((void(*)(void))register_update_hook_on_open); -+} diff --git a/patches/powersync.patch b/patches/powersync.patch index 3a9da4d..93eb508 100644 --- a/patches/powersync.patch +++ b/patches/powersync.patch @@ -1,5 +1,5 @@ diff --git a/Makefile b/Makefile -index 4530653..8c40a26 100644 +index 4530653..9435392 100644 --- a/Makefile +++ b/Makefile @@ -6,14 +6,15 @@ @@ -31,15 +31,6 @@ index 4530653..8c40a26 100644 # When compiling to WASM, enabling memory-growth is not expected to make much of an impact, so we enable it for all builds # Since tihs is a library and not a standalone executable, we don't want to catch unhandled Node process exceptions -@@ -59,7 +61,7 @@ EMFLAGS_DEBUG = \ - -s ASSERTIONS=2 \ - -O1 - --BITCODE_FILES = out/sqlite3.o out/extension-functions.o -+BITCODE_FILES = out/sqlite3.o out/extension-functions.o out/update.o - - OUTPUT_WRAPPER_FILES = src/shell-pre.js src/shell-post.js - @@ -76,13 +78,13 @@ all: optimized debug worker debug: dist/sql-asm-debug.js dist/sql-wasm-debug.js @@ -79,17 +70,7 @@ index 4530653..8c40a26 100644 mv $@ out/tmp-raw.js cat src/shell-pre.js out/tmp-raw.js src/shell-post.js > $@ rm out/tmp-raw.js -@@ -153,6 +155,9 @@ out/extension-functions.o: sqlite-src/$(SQLITE_AMALGAMATION) - # Generate llvm bitcode - $(EMCC) $(SQLITE_COMPILATION_FLAGS) -c sqlite-src/$(SQLITE_AMALGAMATION)/extension-functions.c -o $@ - -+out/update.o: sqlite-src/$(SQLITE_AMALGAMATION) -+ $(EMCC) $(SQLITE_COMPILATION_FLAGS) -c sqlite-src/$(SQLITE_AMALGAMATION)/update.c -o $@ -+ - # TODO: This target appears to be unused. If we re-instatate it, we'll need to add more files inside of the JS folder - # module.tar.gz: test package.json AUTHORS README.md dist/sql-asm.js - # tar --create --gzip $^ > $@ -@@ -172,8 +177,8 @@ sqlite-src: sqlite-src/$(SQLITE_AMALGAMATION) sqlite-src/$(SQLITE_AMALGAMATION)/ +@@ -172,8 +174,8 @@ sqlite-src: sqlite-src/$(SQLITE_AMALGAMATION) sqlite-src/$(SQLITE_AMALGAMATION)/ sqlite-src/$(SQLITE_AMALGAMATION): cache/$(SQLITE_AMALGAMATION).zip sqlite-src/$(SQLITE_AMALGAMATION)/$(EXTENSION_FUNCTIONS) mkdir -p sqlite-src/$(SQLITE_AMALGAMATION) @@ -100,39 +81,20 @@ index 4530653..8c40a26 100644 # We don't delete the sqlite_amalgamation folder. That's a job for clean # Also, the extension functions get copied here, and if we get the order of these steps wrong, # this step could remove the extension functions, and that's not what we want -@@ -182,11 +187,15 @@ sqlite-src/$(SQLITE_AMALGAMATION): cache/$(SQLITE_AMALGAMATION).zip sqlite-src/$ - - sqlite-src/$(SQLITE_AMALGAMATION)/$(EXTENSION_FUNCTIONS): cache/$(EXTENSION_FUNCTIONS) - mkdir -p sqlite-src/$(SQLITE_AMALGAMATION) -+ cp 'src/update.c' sqlite-src/$(SQLITE_AMALGAMATION)/update.c - echo '$(EXTENSION_FUNCTIONS_SHA1) ./cache/$(EXTENSION_FUNCTIONS)' > cache/check.txt - sha1sum -c cache/check.txt - cp 'cache/$(EXTENSION_FUNCTIONS)' $@ - - -+sqlite-src/$(SQLITE_AMALGAMATION)/update.c: sqlite-src -+ cp 'src/update.c' $@ -+ - .PHONY: clean - clean: - rm -f out/* dist/* cache/* - diff --git a/src/api.js b/src/api.js -index c7f102b..4c20316 100644 +index c7f102b..a40b32a 100644 --- a/src/api.js +++ b/src/api.js -@@ -72,6 +72,10 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { +@@ -72,6 +72,8 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { var SQLITE_UPDATE = 23; var SQLITE_DELETE = 9; // var - cwrap function + Module['ccall']('powersync_init_static', 'int', []); -+ Module['ccall']('register_update_hook_extension', 'void', []); -+ + var sqlite3_open = cwrap("sqlite3_open", "number", ["string", "number"]); var sqlite3_close_v2 = cwrap("sqlite3_close_v2", "number", ["number"]); var sqlite3_exec = cwrap( -@@ -122,6 +126,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { +@@ -122,6 +124,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { "number", ["number", "string"] ); @@ -140,7 +102,19 @@ index c7f102b..4c20316 100644 var sqlite3_step = cwrap("sqlite3_step", "number", ["number"]); var sqlite3_errmsg = cwrap("sqlite3_errmsg", "string", ["number"]); var sqlite3_column_count = cwrap( -@@ -1155,6 +1160,13 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { +@@ -613,6 +616,11 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { + if (val === null) { + return this.bindNull(pos); + } ++ ++ // Add ArrayBuffer support ++ if (val instanceof ArrayBuffer) { ++ return this.bindBlob(new Uint8Array(val), pos); ++ } + if (val.length != null) { + return this.bindBlob(val, pos); + } +@@ -1155,6 +1163,13 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { return sqlite3_changes(this.db); }; @@ -155,10 +129,10 @@ index c7f102b..4c20316 100644 var size = sqlite3_value_bytes(ptr); var blob_ptr = sqlite3_value_blob(ptr); diff --git a/src/exported_functions.json b/src/exported_functions.json -index 3be2595..709bc5c 100644 +index 3be2595..99b78c4 100644 --- a/src/exported_functions.json +++ b/src/exported_functions.json -@@ -1,47 +1,50 @@ +@@ -1,47 +1,48 @@ [ -"_malloc", -"_free", @@ -250,9 +224,7 @@ index 3be2595..709bc5c 100644 + "_sqlite3_aggregate_context", + "_RegisterExtensionFunctions", + "_sqlite3_last_insert_rowid", -+ "_sqlite3_update_hook", -+ "_powersync_init_static", -+ "_register_update_hook_extension" ++ "_powersync_init_static" ] diff --git a/src/exported_runtime_methods.json b/src/exported_runtime_methods.json index f099056..b1712fc 100644