@laboverwire/stitch 0.4.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.
- package/CHANGELOG.md +90 -0
- package/LICENSE +201 -0
- package/README.md +39 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/internal-list-apply.d.ts +5 -0
- package/dist/internal-list-apply.d.ts.map +1 -0
- package/dist/internal-list-apply.js +30 -0
- package/dist/internal-list-apply.js.map +1 -0
- package/dist/internal-utils.d.ts +3 -0
- package/dist/internal-utils.d.ts.map +1 -0
- package/dist/internal-utils.js +15 -0
- package/dist/internal-utils.js.map +1 -0
- package/dist/internal-wasm-error.d.ts +9 -0
- package/dist/internal-wasm-error.d.ts.map +1 -0
- package/dist/internal-wasm-error.js +48 -0
- package/dist/internal-wasm-error.js.map +1 -0
- package/dist/memory-store.d.ts +3 -0
- package/dist/memory-store.d.ts.map +1 -0
- package/dist/memory-store.js +572 -0
- package/dist/memory-store.js.map +1 -0
- package/dist/offline-queue.d.ts +6 -0
- package/dist/offline-queue.d.ts.map +1 -0
- package/dist/offline-queue.js +361 -0
- package/dist/offline-queue.js.map +1 -0
- package/dist/persistence-layer.d.ts +7 -0
- package/dist/persistence-layer.d.ts.map +1 -0
- package/dist/persistence-layer.js +409 -0
- package/dist/persistence-layer.js.map +1 -0
- package/dist/react/context.d.ts +10 -0
- package/dist/react/context.d.ts.map +1 -0
- package/dist/react/context.js +9 -0
- package/dist/react/context.js.map +1 -0
- package/dist/react/hooks/useChildCounts.d.ts +3 -0
- package/dist/react/hooks/useChildCounts.d.ts.map +1 -0
- package/dist/react/hooks/useChildCounts.js +85 -0
- package/dist/react/hooks/useChildCounts.js.map +1 -0
- package/dist/react/hooks/useConnectionStatus.d.ts +3 -0
- package/dist/react/hooks/useConnectionStatus.d.ts.map +1 -0
- package/dist/react/hooks/useConnectionStatus.js +9 -0
- package/dist/react/hooks/useConnectionStatus.js.map +1 -0
- package/dist/react/hooks/useEntitySnapshot.d.ts +4 -0
- package/dist/react/hooks/useEntitySnapshot.d.ts.map +1 -0
- package/dist/react/hooks/useEntitySnapshot.js +33 -0
- package/dist/react/hooks/useEntitySnapshot.js.map +1 -0
- package/dist/react/hooks/useRootEntityList.d.ts +9 -0
- package/dist/react/hooks/useRootEntityList.d.ts.map +1 -0
- package/dist/react/hooks/useRootEntityList.js +69 -0
- package/dist/react/hooks/useRootEntityList.js.map +1 -0
- package/dist/react/hooks/useScopedEntities.d.ts +9 -0
- package/dist/react/hooks/useScopedEntities.d.ts.map +1 -0
- package/dist/react/hooks/useScopedEntities.js +82 -0
- package/dist/react/hooks/useScopedEntities.js.map +1 -0
- package/dist/react/hooks/useSyncScope.d.ts +8 -0
- package/dist/react/hooks/useSyncScope.d.ts.map +1 -0
- package/dist/react/hooks/useSyncScope.js +49 -0
- package/dist/react/hooks/useSyncScope.js.map +1 -0
- package/dist/react/hooks/useTopLevelEntities.d.ts +7 -0
- package/dist/react/hooks/useTopLevelEntities.d.ts.map +1 -0
- package/dist/react/hooks/useTopLevelEntities.js +52 -0
- package/dist/react/hooks/useTopLevelEntities.js.map +1 -0
- package/dist/react/index.d.ts +11 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +10 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/provider.d.ts +32 -0
- package/dist/react/provider.d.ts.map +1 -0
- package/dist/react/provider.js +94 -0
- package/dist/react/provider.js.map +1 -0
- package/dist/remote-sync-layer.d.ts +8 -0
- package/dist/remote-sync-layer.d.ts.map +1 -0
- package/dist/remote-sync-layer.js +439 -0
- package/dist/remote-sync-layer.js.map +1 -0
- package/dist/store.d.ts +3 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +779 -0
- package/dist/store.js.map +1 -0
- package/dist/sync-engine.d.ts +3 -0
- package/dist/sync-engine.d.ts.map +1 -0
- package/dist/sync-engine.js +643 -0
- package/dist/sync-engine.js.map +1 -0
- package/dist/types.d.ts +263 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/dist/vue/StitchAuth.d.ts +58 -0
- package/dist/vue/StitchAuth.d.ts.map +1 -0
- package/dist/vue/StitchAuth.js +39 -0
- package/dist/vue/StitchAuth.js.map +1 -0
- package/dist/vue/StoreRoot.d.ts +41 -0
- package/dist/vue/StoreRoot.d.ts.map +1 -0
- package/dist/vue/StoreRoot.js +94 -0
- package/dist/vue/StoreRoot.js.map +1 -0
- package/dist/vue/composables/useChildCounts.d.ts +4 -0
- package/dist/vue/composables/useChildCounts.d.ts.map +1 -0
- package/dist/vue/composables/useChildCounts.js +85 -0
- package/dist/vue/composables/useChildCounts.js.map +1 -0
- package/dist/vue/composables/useConnectionStatus.d.ts +4 -0
- package/dist/vue/composables/useConnectionStatus.d.ts.map +1 -0
- package/dist/vue/composables/useConnectionStatus.js +12 -0
- package/dist/vue/composables/useConnectionStatus.js.map +1 -0
- package/dist/vue/composables/useEntitySnapshot.d.ts +5 -0
- package/dist/vue/composables/useEntitySnapshot.d.ts.map +1 -0
- package/dist/vue/composables/useEntitySnapshot.js +41 -0
- package/dist/vue/composables/useEntitySnapshot.js.map +1 -0
- package/dist/vue/composables/useRootEntityList.d.ts +10 -0
- package/dist/vue/composables/useRootEntityList.d.ts.map +1 -0
- package/dist/vue/composables/useRootEntityList.js +76 -0
- package/dist/vue/composables/useRootEntityList.js.map +1 -0
- package/dist/vue/composables/useScopedEntities.d.ts +10 -0
- package/dist/vue/composables/useScopedEntities.d.ts.map +1 -0
- package/dist/vue/composables/useScopedEntities.js +91 -0
- package/dist/vue/composables/useScopedEntities.js.map +1 -0
- package/dist/vue/composables/useStore.d.ts +3 -0
- package/dist/vue/composables/useStore.d.ts.map +1 -0
- package/dist/vue/composables/useStore.js +9 -0
- package/dist/vue/composables/useStore.js.map +1 -0
- package/dist/vue/composables/useSyncScope.d.ts +9 -0
- package/dist/vue/composables/useSyncScope.d.ts.map +1 -0
- package/dist/vue/composables/useSyncScope.js +50 -0
- package/dist/vue/composables/useSyncScope.js.map +1 -0
- package/dist/vue/composables/useTopLevelEntities.d.ts +8 -0
- package/dist/vue/composables/useTopLevelEntities.d.ts.map +1 -0
- package/dist/vue/composables/useTopLevelEntities.js +58 -0
- package/dist/vue/composables/useTopLevelEntities.js.map +1 -0
- package/dist/vue/index.d.ts +13 -0
- package/dist/vue/index.d.ts.map +1 -0
- package/dist/vue/index.js +12 -0
- package/dist/vue/index.js.map +1 -0
- package/dist/vue/injection-key.d.ts +10 -0
- package/dist/vue/injection-key.d.ts.map +1 -0
- package/dist/vue/injection-key.js +2 -0
- package/dist/vue/injection-key.js.map +1 -0
- package/package.json +111 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
## 0.4.1
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- **Republish of `0.4.0`.** The `0.4.0` tag was pushed but the publish workflow failed before reaching the npm registry — `npm publish --provenance` requires `id-token: write` on the workflow's `permissions` block, which was missing. Fixed in the release workflow; `0.4.1` is the first version actually published to npm. No source changes from `0.4.0`.
|
|
10
|
+
|
|
11
|
+
## 0.4.0
|
|
12
|
+
|
|
13
|
+
### Changed (breaking)
|
|
14
|
+
|
|
15
|
+
- **Minimum supported Node bumped to `>=20`** (from `>=18`). Node 18 reached end-of-life and CI no longer exercises it. Consumers on Node 18 should upgrade to Node 20 LTS or 22.
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- **Open-source release.** Apache-2.0 license; `package.json` now carries `license`, `author`, `repository`, `bugs`, `homepage`, `keywords`, `engines`, `sideEffects`, and a `files` allowlist. `private: true` removed.
|
|
20
|
+
- **Build pipeline.** New `tsconfig.build.json` + `npm run build` emit ESM `dist/` via `tsc` with `rewriteRelativeImportExtensions` (rewrites `.ts` → `.js`). `exports` map points at `dist/index.js`, `dist/react/index.js`, `dist/vue/index.js` with matching `.d.ts` declarations. `prepublishOnly` runs `clean` + `check` + `build` so the npm tarball cannot ship without a green gate.
|
|
21
|
+
- **`mqdb-wasm` bumped to `0.3.2`** (from `0.3.1`).
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- **Polynomial-time backtracking in WASM corruption detection.** `MemoryStore.isWasmCorrupted` and `PersistenceLayer.isDbCorrupted` previously matched error messages with a regex containing `transaction.*null`, which has polynomial complexity on inputs with many `transaction` prefixes (CodeQL `js/polynomial-redos`). Both helpers now delegate to a shared `isCorruptionError(err, extraPatterns)` exported from `internal-wasm-error.ts`, which uses substring `indexOf` checks — same semantics, linear time, and the corruption-pattern list lives in one place.
|
|
26
|
+
|
|
27
|
+
## 0.3.0
|
|
28
|
+
|
|
29
|
+
### Removed
|
|
30
|
+
|
|
31
|
+
- **Pre-0.2 monolithic store.** `PersistenceStore` interface, `createPersistenceStore` factory, and `PersistenceStoreImpl` (entire `src/persistence-store.ts` file) deleted. `createStore` + `Store` is the sole store surface.
|
|
32
|
+
- **React legacy bindings.** `StitchProvider`, `SyncStoreProvider` (alias), `StitchContext`, `StitchContextValue`, `SyncStoreContext`, `SyncStoreContextValue`, `useStitch`, `useSyncStore`, `usePersistenceToMemorySync` all removed. Use `<StoreProvider>` + `<AuthProvider>` with `useStore`.
|
|
33
|
+
- **Vue legacy root.** `StitchRoot` component removed. Use `<StoreRoot>` + `<StitchAuth>`.
|
|
34
|
+
- **Standalone persistence bridge.** `PersistenceBridge`, `PersistenceBridgeConfig`, and `createPersistenceBridge` removed — only meaningful with the removed `PersistenceStore` contract and had no internal consumer in 0.2. `StoreImpl` handles memory↔persistence relay internally.
|
|
35
|
+
- **`isStore()` helper** in `src/internal-utils.ts` removed — existed only to disambiguate the now-deleted `PersistenceStore | Store` union in the two `useConnectionStatus` entry points.
|
|
36
|
+
|
|
37
|
+
No migration shim. 0.2 consumers upgrading to 0.3 will see import errors at the removed names and must port to the unified API documented in `README.md`.
|
|
38
|
+
|
|
39
|
+
### Added
|
|
40
|
+
|
|
41
|
+
- **Anonymous broker support.** `SyncEngine.connect` / `.reconnect` now set `authenticationMethod = 'JWT'` only when `getTicket()` returns a non-empty string. Previously an empty ticket still produced a JWT auth attempt, which `mqdb --anonymous` rejects with `"Bad authentication method"`. A shared `applyTicketAuth(connectOpts, ticket)` helper replaces the duplicated inline block across both call sites.
|
|
42
|
+
- **Vanilla example remote wiring.** `examples/vanilla/src/main.ts` now reads `VITE_STITCH_SERVER_URL` (and optional `VITE_STITCH_AUTH_TICKET`), adds a `remote` block to `StoreOptions` when present, and renders the live connection status in the header. Parity with React/Vue examples.
|
|
43
|
+
- **`examples/**/.env.local`** is now gitignored alongside `node_modules` / `dist`.
|
|
44
|
+
- **Release tooling.** New `RELEASING.md` documents the cut-release recipe. `npm run release:check` runs `npm run check` plus a `scripts/verify-changelog.mjs` gate that fails when `## Unreleased` is empty. Package stays `private: true` — releases are git tags only.
|
|
45
|
+
|
|
46
|
+
### Fixed
|
|
47
|
+
|
|
48
|
+
- **Cross-tab hydration.** A second tab opened against a broker with pre-existing root entities would show an empty list until a page reload. `StoreImpl.onConnected` now calls `persistence.notifyAllEntitySubscribers()` after `syncRootEntityList` resolves, which triggers `useRootEntityList` / the vanilla example's `subscribeToEntity` callback to re-fetch once `initialSyncDone` is true. `onConnected` also catches and swallows sync errors so the notify runs on the success path only.
|
|
49
|
+
- **`subscribeToEntity` double-fire for persistence-backed stores.** The previous refactor wired both `memory.onMutation` and `persistence.subscribe` unconditionally, so every local create/update/delete notified consumers twice (React `useSyncExternalStore` re-rendered twice per mutation). `memory.onMutation` is now filtered to `'load'` and `'clear'` origin tags — the two tags that bypass the persistence path and therefore don't fire on the persistence side. Normal local mutations and remote mutations fire exactly once; `replaceScope` loads still reach subscribers.
|
|
50
|
+
- **Vue `OfflineQueuePanel` stuck on the "offline" hint.** The template read `ctx.store.hasRemote` (a class getter, not a reactive source), so Vue captured the pre-initialize `false` value and never re-rendered. Switched to the module-level `hasRemoteConfigured` exported from `stitch.ts` (what `ConnectionBanner` already uses).
|
|
51
|
+
- **`applyEvent` update no-op preserved.** Briefly changed to upsert while chasing the hydration bug; this resurrected deleted rows when a stale `update` arrived after a `delete`. Reverted with a regression test (`tests/unit/internal-list-apply.test.ts`).
|
|
52
|
+
|
|
53
|
+
## 0.2.0
|
|
54
|
+
|
|
55
|
+
### Added
|
|
56
|
+
|
|
57
|
+
- **Test harness.** Vitest 4 browser mode via Playwright/Chromium — real IndexedDB and WASM, no shims. 19 integration + unit specs. Run with `npm test`.
|
|
58
|
+
- **`MqdbError`.** Every call into `mqdb-wasm` that previously threw raw string or wasm-bindgen errors now throws a proper `Error` subclass with a method-qualified message (`mqdb.list:task: …`), the original exception on `.cause`, and a `.stack` frame. Exported from the public API.
|
|
59
|
+
- **Generic `Schema` type on `createStore`.** `createStore<{ project: Project; task: Task }>(…)` gives typed `read` / `getSnapshot` / `create` / `update` / `delete` / `list` / `subscribeToEntity` / `subscribeToScope`. Untyped callers keep `Record<string, unknown>`. New type exports: `EntitySchema`, `DefaultSchema`, `EntityKey`.
|
|
60
|
+
- **Split providers.**
|
|
61
|
+
- React: `<StoreProvider>` (lifecycle) + `<AuthProvider>` (auth concerns).
|
|
62
|
+
- Vue: `<StoreRoot>` (lifecycle) + `<StitchAuth>` (auth concerns).
|
|
63
|
+
- **Vue composables at hook parity.** `useRootEntityList`, `useScopedEntities`, `useChildCounts`, `useTopLevelEntities` — previously React-only.
|
|
64
|
+
- **`examples/vanilla/`.** Minimal TS + HTML reference (~100 lines) that exercises the core API without a framework.
|
|
65
|
+
- **Vite consumer docs.** Root README section on `server.fs.allow` for consumers aliasing from source.
|
|
66
|
+
|
|
67
|
+
### Changed (breaking)
|
|
68
|
+
|
|
69
|
+
- **`Store.openScope` → `Store.replaceScope`.** Same behavior, clearer name — the in-memory WASM DB is rebuilt on each call. The `useSyncScope` hook still exposes `openScope` as the function name (it now calls `store.replaceScope` internally). Rename direct call sites.
|
|
70
|
+
- **`StoreConfig.dbName` removed.** `options.persistence.dbName` is the sole source of truth. Memory-only stores don't need a name. Legacy `createPersistenceStore(config, dbName)` now takes `dbName` as a second argument.
|
|
71
|
+
- **Subscribe primitives consolidated.** `Store.subscribe` and `Store.onMutation` removed. `Store.subscribeToEntity(entity, (data, op) => …)` is now the only entity-level primitive and carries the full payload. `Store.subscribeToScope(scopeId, entity, () => void)` is unchanged. Migrate: `store.subscribe('x', cb)` → `store.subscribeToEntity('x', cb)`.
|
|
72
|
+
- **Provider split.** React: auth props (`userId`, `authenticated`, `onSessionInvalid`, `onReconnectValidate`) moved from `<StoreProvider>` to the new `<AuthProvider>`. Same split for Vue: move those props from `<StitchRoot>` to the new `<StitchAuth>`. Old components remain behind `@deprecated` until 0.3.
|
|
73
|
+
|
|
74
|
+
### Fixed
|
|
75
|
+
|
|
76
|
+
- **`addIndex` on persistent backend crash.** `persistence-layer.setupSchemas` now uses the async `addSchemaAsync` / `addForeignKeyAsync` / `addIndexAsync` variants. In `mqdb-wasm@0.3.1` the sync variants throw `"sync operations require memory backend"` on persistent DBs, which broke every entity config with `indexes`.
|
|
77
|
+
- **`loadScope` silent under subscribers.** `memory.loadScope` now calls `notifySubscribers` for every loaded entity after the DB swap. Previously consumers that subscribed before `replaceScope` resolved would see stale empty snapshots until an unrelated state change forced a re-read.
|
|
78
|
+
- **Concurrent `initialize()` race.** `Store.initialize` caches an in-flight `_initPromise`; simultaneous callers (React StrictMode, nested providers) now share one init instead of creating a second persistence layer that orphans already-migrated subscribers.
|
|
79
|
+
- **Root entity subscription coverage.** `memory.allEntities` now includes the root entity, with `listRecords` / `create` / `handleChangeEvent` branching on root vs. child. Previously `subscribeToEntity('project', …)` silently dropped mutations on the root.
|
|
80
|
+
- **IndexedDB connection leaks between tests/stores.** `persistence-layer.close()` now calls `Database.free()` before nulling `db`, so subsequent `deleteDatabase` calls no longer block.
|
|
81
|
+
|
|
82
|
+
### Deprecated (slated for removal in 0.3)
|
|
83
|
+
|
|
84
|
+
- `StitchProvider` (React), `SyncStoreProvider`, `StitchContext`, `StitchContextValue`, `useStitch`, `SyncStoreContext`, `SyncStoreContextValue`, `useSyncStore`, `usePersistenceToMemorySync` — all superseded by `<StoreProvider>` + `<AuthProvider>`.
|
|
85
|
+
- `StitchRoot` (Vue) — superseded by `<StoreRoot>` + `<StitchAuth>`.
|
|
86
|
+
- `createPersistenceStore`, `PersistenceStore` — superseded by `createStore` + `Store`.
|
|
87
|
+
|
|
88
|
+
## 0.1.0
|
|
89
|
+
|
|
90
|
+
Initial internal release.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may accept and charge a
|
|
167
|
+
fee for acceptance of support, warranty, indemnity, or other liability
|
|
168
|
+
obligations and/or rights consistent with this License. However, in
|
|
169
|
+
accepting such obligations, You may act only on Your own behalf
|
|
170
|
+
and on Your sole responsibility, not on behalf of any other
|
|
171
|
+
Contributor, and only if You agree to indemnify, defend, and hold
|
|
172
|
+
each Contributor harmless for any liability incurred by, or claims
|
|
173
|
+
asserted against, such Contributor by reason of your accepting any
|
|
174
|
+
such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 LabOverWire
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
200
|
+
implied. See the License for the specific language governing
|
|
201
|
+
permissions and limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @laboverwire/stitch
|
|
2
|
+
|
|
3
|
+
Reactive state synchronization library. Bridges an in-memory store, IndexedDB persistence, and MQTT-based remote sync into a single `Store` interface. Optional React and Vue 3 bindings.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @laboverwire/stitch
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { createStore } from '@laboverwire/stitch';
|
|
11
|
+
|
|
12
|
+
const store = createStore<Schema>(config, {
|
|
13
|
+
persistence: { dbName: 'my-app' },
|
|
14
|
+
remote: { serverUrl: 'wss://mqtt.example.com', getTicket: () => fetchAuthTicket() },
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
await store.initialize();
|
|
18
|
+
await store.replaceScope('project-abc');
|
|
19
|
+
|
|
20
|
+
const tasks = store.getSnapshot('task', 'project-abc');
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Documentation
|
|
24
|
+
|
|
25
|
+
- [Configuration](./docs/configuration.md) — `StoreConfig`, `StoreOptions`, scope model, typed schemas
|
|
26
|
+
- [Store API](./docs/api.md) — full method reference and error handling
|
|
27
|
+
- [React bindings](./docs/react.md) — providers, hooks, runnable example
|
|
28
|
+
- [Vue 3 bindings](./docs/vue.md) — providers, composables, runnable example
|
|
29
|
+
- [Concepts](./docs/concepts.md) — origin tags, offline queue, reconciliation, connection resilience
|
|
30
|
+
- [Vite consumer guide](./docs/vite-consumer.md) — using the package via source alias from a monorepo
|
|
31
|
+
- [Architecture](./ARCHITECTURE.md) — internal layer composition, data flow, invariants
|
|
32
|
+
- [Changelog](./CHANGELOG.md)
|
|
33
|
+
- [Releasing](./RELEASING.md)
|
|
34
|
+
|
|
35
|
+
`examples/` contains runnable vanilla-TS, React, and Vue apps that double as reference implementations.
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
Apache-2.0 — see [LICENSE](./LICENSE).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type { StoreConfig, EntityDefinition, SchemaField, ForeignKeyDefinition, MutationEvent, ScopeBundle, ScopeState, ConnectionStatus, SortField, SortDirection, ListFilter, SyncMutation, MemoryStore, SyncEngine, Store, StoreOptions, PersistenceConfig, RemoteConfig, PersistenceLayer, OfflineQueue, RemoteSyncLayer, LocalAccessor, MutationSender, PendingMutation, ConsolidatedMutation, EntitySchema, DefaultSchema, EntityKey, OriginTag, } from './types.ts';
|
|
2
|
+
export { OwnershipError } from './types.ts';
|
|
3
|
+
export { MqdbError } from './internal-wasm-error.ts';
|
|
4
|
+
export { createMemoryStore } from './memory-store.ts';
|
|
5
|
+
export { createSyncEngine } from './sync-engine.ts';
|
|
6
|
+
export { createStore } from './store.ts';
|
|
7
|
+
export { createPersistenceLayer } from './persistence-layer.ts';
|
|
8
|
+
export { createRemoteSyncLayer } from './remote-sync-layer.ts';
|
|
9
|
+
export { createPersistentOfflineQueue, createInMemoryOfflineQueue } from './offline-queue.ts';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,oBAAoB,EACpB,aAAa,EACb,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,UAAU,EACV,YAAY,EACZ,WAAW,EACX,UAAU,EACV,KAAK,EACL,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,aAAa,EACb,cAAc,EACd,eAAe,EACf,oBAAoB,EACpB,YAAY,EACZ,aAAa,EACb,SAAS,EACT,SAAS,GACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,4BAA4B,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { OwnershipError } from "./types.js";
|
|
2
|
+
export { MqdbError } from "./internal-wasm-error.js";
|
|
3
|
+
export { createMemoryStore } from "./memory-store.js";
|
|
4
|
+
export { createSyncEngine } from "./sync-engine.js";
|
|
5
|
+
export { createStore } from "./store.js";
|
|
6
|
+
export { createPersistenceLayer } from "./persistence-layer.js";
|
|
7
|
+
export { createRemoteSyncLayer } from "./remote-sync-layer.js";
|
|
8
|
+
export { createPersistentOfflineQueue, createInMemoryOfflineQueue } from "./offline-queue.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgCA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,4BAA4B,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal-list-apply.d.ts","sourceRoot":"","sources":["../src/internal-list-apply.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhE,wBAAgB,UAAU,CACxB,IAAI,EAAE,QAAQ,EAAE,EAChB,MAAM,EAAE,OAAO,EACf,EAAE,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GACjC,QAAQ,EAAE,CAwBZ"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export function applyEvent(prev, entity, op) {
|
|
2
|
+
if (!entity || typeof entity !== 'object' || !('id' in entity))
|
|
3
|
+
return prev;
|
|
4
|
+
const item = entity;
|
|
5
|
+
const idx = prev.findIndex((d) => d.id === item.id);
|
|
6
|
+
switch (op) {
|
|
7
|
+
case 'insert': {
|
|
8
|
+
if (idx < 0)
|
|
9
|
+
return [...prev, item];
|
|
10
|
+
const next = prev.slice();
|
|
11
|
+
next[idx] = item;
|
|
12
|
+
return next;
|
|
13
|
+
}
|
|
14
|
+
case 'update': {
|
|
15
|
+
if (idx < 0)
|
|
16
|
+
return prev;
|
|
17
|
+
const next = prev.slice();
|
|
18
|
+
next[idx] = item;
|
|
19
|
+
return next;
|
|
20
|
+
}
|
|
21
|
+
case 'delete': {
|
|
22
|
+
if (idx < 0)
|
|
23
|
+
return prev;
|
|
24
|
+
return [...prev.slice(0, idx), ...prev.slice(idx + 1)];
|
|
25
|
+
}
|
|
26
|
+
default:
|
|
27
|
+
return prev;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=internal-list-apply.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal-list-apply.js","sourceRoot":"","sources":["../src/internal-list-apply.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,UAAU,CACxB,IAAgB,EAChB,MAAe,EACf,EAAkC;IAElC,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,IAAI,MAAM,CAAC;QAAE,OAAO,IAAI,CAAC;IAC5E,MAAM,IAAI,GAAG,MAAkB,CAAC;IAChC,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC,CAAC;IACpD,QAAQ,EAAE,EAAE,CAAC;QACX,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,IAAI,GAAG,GAAG,CAAC;gBAAE,OAAO,CAAC,GAAG,IAAI,EAAE,IAAI,CAAC,CAAC;YACpC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;YAC1B,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;YACjB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,IAAI,GAAG,GAAG,CAAC;gBAAE,OAAO,IAAI,CAAC;YACzB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;YAC1B,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;YACjB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,IAAI,GAAG,GAAG,CAAC;gBAAE,OAAO,IAAI,CAAC;YACzB,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;QACzD,CAAC;QACD;YACE,OAAO,IAAI,CAAC;IAChB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal-utils.d.ts","sourceRoot":"","sources":["../src/internal-utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAQhF;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAG1D"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function stripNulls(obj) {
|
|
2
|
+
const result = {};
|
|
3
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
4
|
+
if (value != null) {
|
|
5
|
+
result[key] = value;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
return result;
|
|
9
|
+
}
|
|
10
|
+
export function isTransientSyncError(err) {
|
|
11
|
+
if (!(err instanceof Error))
|
|
12
|
+
return false;
|
|
13
|
+
return /timeout|disconnected|foreign key violation/i.test(err.message);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=internal-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal-utils.js","sourceRoot":"","sources":["../src/internal-utils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,UAAU,CAAC,GAA4B;IACrD,MAAM,MAAM,GAA4B,EAAE,CAAC;IAC3C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/C,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACtB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,GAAY;IAC/C,IAAI,CAAC,CAAC,GAAG,YAAY,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC1C,OAAO,6CAA6C,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACzE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class MqdbError extends Error {
|
|
2
|
+
readonly method: string;
|
|
3
|
+
constructor(method: string, cause: unknown);
|
|
4
|
+
}
|
|
5
|
+
export declare function wrapWasmError(method: string, cause: unknown): MqdbError;
|
|
6
|
+
export declare function wrapSync<T>(method: string, fn: () => T): T;
|
|
7
|
+
export declare function wrapAsync<T>(method: string, fn: () => Promise<T>): Promise<T>;
|
|
8
|
+
export declare function isCorruptionError(err: unknown, extraPatterns?: readonly string[]): boolean;
|
|
9
|
+
//# sourceMappingURL=internal-wasm-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal-wasm-error.d.ts","sourceRoot":"","sources":["../src/internal-wasm-error.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAU,SAAQ,KAAK;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO;CAM3C;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,SAAS,CAGvE;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAM1D;AAED,wBAAsB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAMnF;AAID,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,EAAE,aAAa,GAAE,SAAS,MAAM,EAAO,GAAG,OAAO,CAY9F"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export class MqdbError extends Error {
|
|
2
|
+
method;
|
|
3
|
+
constructor(method, cause) {
|
|
4
|
+
const rawMessage = cause instanceof Error ? cause.message : String(cause);
|
|
5
|
+
super(`mqdb.${method}: ${rawMessage}`, { cause });
|
|
6
|
+
this.name = 'MqdbError';
|
|
7
|
+
this.method = method;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export function wrapWasmError(method, cause) {
|
|
11
|
+
if (cause instanceof MqdbError)
|
|
12
|
+
return cause;
|
|
13
|
+
return new MqdbError(method, cause);
|
|
14
|
+
}
|
|
15
|
+
export function wrapSync(method, fn) {
|
|
16
|
+
try {
|
|
17
|
+
return fn();
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
throw wrapWasmError(method, err);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export async function wrapAsync(method, fn) {
|
|
24
|
+
try {
|
|
25
|
+
return await fn();
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
throw wrapWasmError(method, err);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const BASE_CORRUPTION_PATTERNS = ['arg0 is null', 'transaction error', 'unreachable'];
|
|
32
|
+
export function isCorruptionError(err, extraPatterns = []) {
|
|
33
|
+
const inner = err instanceof MqdbError ? err.cause : err;
|
|
34
|
+
if (inner instanceof Error && inner.name === 'RuntimeError')
|
|
35
|
+
return true;
|
|
36
|
+
const msg = (inner instanceof Error ? inner.message : String(inner)).toLowerCase();
|
|
37
|
+
for (const pattern of BASE_CORRUPTION_PATTERNS) {
|
|
38
|
+
if (msg.includes(pattern))
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
for (const pattern of extraPatterns) {
|
|
42
|
+
if (msg.includes(pattern))
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
const txIdx = msg.indexOf('transaction');
|
|
46
|
+
return txIdx !== -1 && msg.indexOf('null', txIdx) !== -1;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=internal-wasm-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal-wasm-error.js","sourceRoot":"","sources":["../src/internal-wasm-error.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,SAAU,SAAQ,KAAK;IACzB,MAAM,CAAS;IAExB,YAAY,MAAc,EAAE,KAAc;QACxC,MAAM,UAAU,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC1E,KAAK,CAAC,QAAQ,MAAM,KAAK,UAAU,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAClD,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,KAAc;IAC1D,IAAI,KAAK,YAAY,SAAS;QAAE,OAAO,KAAK,CAAC;IAC7C,OAAO,IAAI,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,QAAQ,CAAI,MAAc,EAAE,EAAW;IACrD,IAAI,CAAC;QACH,OAAO,EAAE,EAAE,CAAC;IACd,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACnC,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAAI,MAAc,EAAE,EAAoB;IACrE,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,EAAE,CAAC;IACpB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACnC,CAAC;AACH,CAAC;AAED,MAAM,wBAAwB,GAAG,CAAC,cAAc,EAAE,mBAAmB,EAAE,aAAa,CAAU,CAAC;AAE/F,MAAM,UAAU,iBAAiB,CAAC,GAAY,EAAE,gBAAmC,EAAE;IACnF,MAAM,KAAK,GAAG,GAAG,YAAY,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC;IACzD,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc;QAAE,OAAO,IAAI,CAAC;IACzE,MAAM,GAAG,GAAG,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IACnF,KAAK,MAAM,OAAO,IAAI,wBAAwB,EAAE,CAAC;QAC/C,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC;YAAE,OAAO,IAAI,CAAC;IACzC,CAAC;IACD,KAAK,MAAM,OAAO,IAAI,aAAa,EAAE,CAAC;QACpC,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC;YAAE,OAAO,IAAI,CAAC;IACzC,CAAC;IACD,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACzC,OAAO,KAAK,KAAK,CAAC,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-store.d.ts","sourceRoot":"","sources":["../src/memory-store.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAiB,WAAW,EAAa,MAAM,YAAY,CAAC;AAumBrF,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,CAElE"}
|