Skip to content

feat(web): support static extension initializers - #1151

Merged
simolus3 merged 3 commits into
powersync-ja:mainfrom
akpor-kofi:feat/additional-wasm-initializers
Oct 19, 2026
Merged

simolus3 merged 3 commits into
powersync-ja:mainfrom
akpor-kofi:feat/additional-wasm-initializers

Conversation

@akpor-kofi

@akpor-kofi akpor-kofi commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Custom wa-sqlite builds can statically link extensions but need a way to call their exported initialization functions before opening connections. This adds additionalInitializationFunctions, an optional array of exported function names, to the web database open options.

The names are forwarded to local connections and database workers, including read-only workers. One ordered loop calls powersync_init_static first, then each additional no-argument export, and checks every return code before open_v2. A nonzero return code from the core or an extension aborts initialization; absent exports also reject opening. The default makes no additional calls. The TSDoc describes the initialization contract. Website documentation is tracked separately in powersync-ja/powersync-docs#688.

This follows @simolus3's suggested approach in powersync-ja/wa-sqlite#96. The consumer backport in https://github.com/nukoder-ng/nukodes/pull/155 on PowerSync Web 1.39.1 was validated with a decimal build exporting decimal_init_static, using unmodified wa-sqlite startup code.

Validation

  • tsc -b packages/web passes, including common/shared-internals references. pnpm --filter @powersync/web build also passes, including the worker bundles.
  • Eleven existing Chromium browser connection-opening and encryption tests pass after the core return-code check.
  • Ten temporary isolated checks pass against the actual TypeScript connection class: omitted/empty options, core-first extension ordering, failed core initialization with/without extras, failed extension initialization, missing exports, thrown core exceptions, read-only flags and encryption setup ordering. Failures prevent SQLite opening. The temporary test and runner config are deleted and not committed.
  • Earlier feature validation also exercised an additional exported initializer on local, dedicated-worker and shared-worker connections, plus a missing export.
  • Consumer backport: Chromium dedicated/shared IndexedDB and OPFS, and WebKit dedicated/shared IndexedDB pass exact decimal scalar/window/collation queries, 10,000-row sums and persisted reopen. Omitting the initializer leaves decimal unavailable with the new WASM build.
  • Prettier and git diff --check pass. pnpm lint cannot run in this checkout because the eslint executable is not installed; the repository also has no root ESLint configuration.

Changelog / operational notes

  • Adds a minor changeset for @powersync/web. Core initialization failures now reject database opening, using the same return-code check as additional extensions.
  • No dependency/lockfile, build tooling, configuration, database migration/schema, environment, permission, background job, webhook or provider integration changes.
  • Custom builders must export their initialization functions and bundle workers against the matching generated JavaScript/WASM pair. Standard builds keep their current behavior.

@changeset-bot

changeset-bot Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8029d57

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@powersync/web Minor
@powersync/diagnostics-app Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment thread packages/web/README.md Outdated
Comment thread packages/web/src/db/adapters/wa-sqlite/RawSqliteConnection.ts
@akpor-kofi
akpor-kofi marked this pull request as ready for review October 16, 2026 15:42
@simolus3
simolus3 merged commit bf54805 into powersync-ja:main Oct 19, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants