@mdbase-dev/sdk 0.0.0-stage → 0.1.0-beta.153
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/LICENSE +21 -0
- package/README.md +844 -2
- package/dist/account-key.d.ts +176 -0
- package/dist/account-key.js +409 -0
- package/dist/account-key.js.map +1 -0
- package/dist/account.d.ts +11 -0
- package/dist/account.js +9 -0
- package/dist/account.js.map +1 -0
- package/dist/app-grant/client.d.ts +209 -0
- package/dist/app-grant/client.js +930 -0
- package/dist/app-grant/client.js.map +1 -0
- package/dist/app-grant/grant-store.d.ts +77 -0
- package/dist/app-grant/grant-store.js +201 -0
- package/dist/app-grant/grant-store.js.map +1 -0
- package/dist/app-grant/index.d.ts +11 -0
- package/dist/app-grant/index.js +10 -0
- package/dist/app-grant/index.js.map +1 -0
- package/dist/app-grant/native-completion.d.ts +22 -0
- package/dist/app-grant/native-completion.js +63 -0
- package/dist/app-grant/native-completion.js.map +1 -0
- package/dist/app-grant/people.d.ts +10 -0
- package/dist/app-grant/people.js +84 -0
- package/dist/app-grant/people.js.map +1 -0
- package/dist/app-grant/setup-attempt.d.ts +12 -0
- package/dist/app-grant/setup-attempt.js +62 -0
- package/dist/app-grant/setup-attempt.js.map +1 -0
- package/dist/app-grant/setup-producer.d.ts +31 -0
- package/dist/app-grant/setup-producer.js +65 -0
- package/dist/app-grant/setup-producer.js.map +1 -0
- package/dist/app-grant/setup.d.ts +11 -0
- package/dist/app-grant/setup.js +222 -0
- package/dist/app-grant/setup.js.map +1 -0
- package/dist/app-host/app-environment.d.ts +27 -0
- package/dist/app-host/app-environment.js +48 -0
- package/dist/app-host/app-environment.js.map +1 -0
- package/dist/app-host/app-origin.d.ts +7 -0
- package/dist/app-host/app-origin.js +48 -0
- package/dist/app-host/app-origin.js.map +1 -0
- package/dist/app-host/bases-pages.d.ts +29 -0
- package/dist/app-host/bases-pages.js +42 -0
- package/dist/app-host/bases-pages.js.map +1 -0
- package/dist/app-host/bases-wire.d.ts +159 -0
- package/dist/app-host/bases-wire.js +376 -0
- package/dist/app-host/bases-wire.js.map +1 -0
- package/dist/app-host/browser-direct-access.d.ts +18 -0
- package/dist/app-host/browser-direct-access.js +17 -0
- package/dist/app-host/browser-direct-access.js.map +1 -0
- package/dist/app-host/cloud-copy-bootstrap.d.ts +127 -0
- package/dist/app-host/cloud-copy-bootstrap.js +606 -0
- package/dist/app-host/cloud-copy-bootstrap.js.map +1 -0
- package/dist/app-host/cloud-copy-host.d.ts +248 -0
- package/dist/app-host/cloud-copy-host.js +1028 -0
- package/dist/app-host/cloud-copy-host.js.map +1 -0
- package/dist/app-host/cloud-copy-persistence-idb.d.ts +33 -0
- package/dist/app-host/cloud-copy-persistence-idb.js +255 -0
- package/dist/app-host/cloud-copy-persistence-idb.js.map +1 -0
- package/dist/app-host/cloud-copy-persistence.d.ts +57 -0
- package/dist/app-host/cloud-copy-persistence.js +341 -0
- package/dist/app-host/cloud-copy-persistence.js.map +1 -0
- package/dist/app-host/collection-control.d.ts +111 -0
- package/dist/app-host/collection-control.js +604 -0
- package/dist/app-host/collection-control.js.map +1 -0
- package/dist/app-host/collection-delete.d.ts +7 -0
- package/dist/app-host/collection-delete.js +54 -0
- package/dist/app-host/collection-delete.js.map +1 -0
- package/dist/app-host/collection-display-name.d.ts +2 -0
- package/dist/app-host/collection-display-name.js +22 -0
- package/dist/app-host/collection-display-name.js.map +1 -0
- package/dist/app-host/collection-join-ledger.d.ts +52 -0
- package/dist/app-host/collection-join-ledger.js +208 -0
- package/dist/app-host/collection-join-ledger.js.map +1 -0
- package/dist/app-host/collection-people.d.ts +32 -0
- package/dist/app-host/collection-people.js +119 -0
- package/dist/app-host/collection-people.js.map +1 -0
- package/dist/app-host/collection-readiness.d.ts +119 -0
- package/dist/app-host/collection-readiness.js +649 -0
- package/dist/app-host/collection-readiness.js.map +1 -0
- package/dist/app-host/collection-setup-journal.d.ts +59 -0
- package/dist/app-host/collection-setup-journal.js +813 -0
- package/dist/app-host/collection-setup-journal.js.map +1 -0
- package/dist/app-host/collection-setup-types.d.ts +155 -0
- package/dist/app-host/collection-setup-types.js +10 -0
- package/dist/app-host/collection-setup-types.js.map +1 -0
- package/dist/app-host/cp-authority.d.ts +65 -0
- package/dist/app-host/cp-authority.js +243 -0
- package/dist/app-host/cp-authority.js.map +1 -0
- package/dist/app-host/cp-people.d.ts +23 -0
- package/dist/app-host/cp-people.js +145 -0
- package/dist/app-host/cp-people.js.map +1 -0
- package/dist/app-host/cp-problem.d.ts +34 -0
- package/dist/app-host/cp-problem.js +114 -0
- package/dist/app-host/cp-problem.js.map +1 -0
- package/dist/app-host/device-key-custody.d.ts +51 -0
- package/dist/app-host/device-key-custody.js +128 -0
- package/dist/app-host/device-key-custody.js.map +1 -0
- package/dist/app-host/device-key-idb.d.ts +31 -0
- package/dist/app-host/device-key-idb.js +176 -0
- package/dist/app-host/device-key-idb.js.map +1 -0
- package/dist/app-host/device-key-provider.d.ts +33 -0
- package/dist/app-host/device-key-provider.js +181 -0
- package/dist/app-host/device-key-provider.js.map +1 -0
- package/dist/app-host/device-registration.d.ts +51 -0
- package/dist/app-host/device-registration.js +180 -0
- package/dist/app-host/device-registration.js.map +1 -0
- package/dist/app-host/foreground-wake.d.ts +43 -0
- package/dist/app-host/foreground-wake.js +113 -0
- package/dist/app-host/foreground-wake.js.map +1 -0
- package/dist/app-host/handover.d.ts +27 -0
- package/dist/app-host/handover.js +82 -0
- package/dist/app-host/handover.js.map +1 -0
- package/dist/app-host/http-log.d.ts +96 -0
- package/dist/app-host/http-log.js +608 -0
- package/dist/app-host/http-log.js.map +1 -0
- package/dist/app-host/index.d.ts +63 -0
- package/dist/app-host/index.js +33 -0
- package/dist/app-host/index.js.map +1 -0
- package/dist/app-host/initial-sync.d.ts +22 -0
- package/dist/app-host/initial-sync.js +41 -0
- package/dist/app-host/initial-sync.js.map +1 -0
- package/dist/app-host/installation-sign-in.d.ts +319 -0
- package/dist/app-host/installation-sign-in.js +1231 -0
- package/dist/app-host/installation-sign-in.js.map +1 -0
- package/dist/app-host/installation-store.d.ts +56 -0
- package/dist/app-host/installation-store.js +285 -0
- package/dist/app-host/installation-store.js.map +1 -0
- package/dist/app-host/ledger-rows.d.ts +3 -0
- package/dist/app-host/ledger-rows.js +23 -0
- package/dist/app-host/ledger-rows.js.map +1 -0
- package/dist/app-host/local-facade.d.ts +24 -0
- package/dist/app-host/local-facade.js +361 -0
- package/dist/app-host/local-facade.js.map +1 -0
- package/dist/app-host/log-pump.d.ts +124 -0
- package/dist/app-host/log-pump.js +326 -0
- package/dist/app-host/log-pump.js.map +1 -0
- package/dist/app-host/log-push.d.ts +90 -0
- package/dist/app-host/log-push.js +376 -0
- package/dist/app-host/log-push.js.map +1 -0
- package/dist/app-host/log-token-cache.d.ts +28 -0
- package/dist/app-host/log-token-cache.js +104 -0
- package/dist/app-host/log-token-cache.js.map +1 -0
- package/dist/app-host/native-sign-in.d.ts +27 -0
- package/dist/app-host/native-sign-in.js +12 -0
- package/dist/app-host/native-sign-in.js.map +1 -0
- package/dist/app-host/noise-custody.d.ts +62 -0
- package/dist/app-host/noise-custody.js +238 -0
- package/dist/app-host/noise-custody.js.map +1 -0
- package/dist/app-host/noise-idb.d.ts +33 -0
- package/dist/app-host/noise-idb.js +199 -0
- package/dist/app-host/noise-idb.js.map +1 -0
- package/dist/app-host/open-wait.d.ts +3 -0
- package/dist/app-host/open-wait.js +17 -0
- package/dist/app-host/open-wait.js.map +1 -0
- package/dist/app-host/opening-progress.d.ts +3 -0
- package/dist/app-host/opening-progress.js +5 -0
- package/dist/app-host/opening-progress.js.map +1 -0
- package/dist/app-host/owner.d.ts +103 -0
- package/dist/app-host/owner.js +262 -0
- package/dist/app-host/owner.js.map +1 -0
- package/dist/app-host/private-bootstrap.d.ts +78 -0
- package/dist/app-host/private-bootstrap.js +230 -0
- package/dist/app-host/private-bootstrap.js.map +1 -0
- package/dist/app-host/private-persistence-idb.d.ts +32 -0
- package/dist/app-host/private-persistence-idb.js +188 -0
- package/dist/app-host/private-persistence-idb.js.map +1 -0
- package/dist/app-host/private-persistence.d.ts +55 -0
- package/dist/app-host/private-persistence.js +257 -0
- package/dist/app-host/private-persistence.js.map +1 -0
- package/dist/app-host/scoped-sign-in-session.d.ts +49 -0
- package/dist/app-host/scoped-sign-in-session.js +243 -0
- package/dist/app-host/scoped-sign-in-session.js.map +1 -0
- package/dist/app-host/setup-engine.d.ts +14 -0
- package/dist/app-host/setup-engine.js +73 -0
- package/dist/app-host/setup-engine.js.map +1 -0
- package/dist/app-host/sign-out-erase.d.ts +37 -0
- package/dist/app-host/sign-out-erase.js +139 -0
- package/dist/app-host/sign-out-erase.js.map +1 -0
- package/dist/app-host/status.d.ts +62 -0
- package/dist/app-host/status.js +43 -0
- package/dist/app-host/status.js.map +1 -0
- package/dist/app-host/storage-probe.d.ts +46 -0
- package/dist/app-host/storage-probe.js +63 -0
- package/dist/app-host/storage-probe.js.map +1 -0
- package/dist/app-host/timer-port.d.ts +29 -0
- package/dist/app-host/timer-port.js +483 -0
- package/dist/app-host/timer-port.js.map +1 -0
- package/dist/app-host/wasm-runtime.d.ts +302 -0
- package/dist/app-host/wasm-runtime.js +1050 -0
- package/dist/app-host/wasm-runtime.js.map +1 -0
- package/dist/app-host/web-collection.d.ts +78 -0
- package/dist/app-host/web-collection.js +671 -0
- package/dist/app-host/web-collection.js.map +1 -0
- package/dist/app-host/web-sign-in-problem.d.ts +17 -0
- package/dist/app-host/web-sign-in-problem.js +59 -0
- package/dist/app-host/web-sign-in-problem.js.map +1 -0
- package/dist/app-host/web-sign-in-session.d.ts +367 -0
- package/dist/app-host/web-sign-in-session.js +1258 -0
- package/dist/app-host/web-sign-in-session.js.map +1 -0
- package/dist/app-storage/app-binary-index.d.ts +33 -0
- package/dist/app-storage/app-binary-index.js +274 -0
- package/dist/app-storage/app-binary-index.js.map +1 -0
- package/dist/app-storage/app-sqlite-index.d.ts +40 -0
- package/dist/app-storage/app-sqlite-index.js +102 -0
- package/dist/app-storage/app-sqlite-index.js.map +1 -0
- package/dist/app-storage/collection-sql.d.ts +39 -0
- package/dist/app-storage/collection-sql.js +93 -0
- package/dist/app-storage/collection-sql.js.map +1 -0
- package/dist/app-storage/index.d.ts +10 -0
- package/dist/app-storage/index.js +7 -0
- package/dist/app-storage/index.js.map +1 -0
- package/dist/app-storage/sqlite-index.d.ts +95 -0
- package/dist/app-storage/sqlite-index.js +280 -0
- package/dist/app-storage/sqlite-index.js.map +1 -0
- package/dist/application/asset-loader.d.ts +22 -0
- package/dist/application/asset-loader.js +130 -0
- package/dist/application/asset-loader.js.map +1 -0
- package/dist/application/asset-pins.json +24 -0
- package/dist/application/browser-capabilities.d.ts +48 -0
- package/dist/application/browser-capabilities.js +87 -0
- package/dist/application/browser-capabilities.js.map +1 -0
- package/dist/application/browser-selection.d.ts +58 -0
- package/dist/application/browser-selection.js +160 -0
- package/dist/application/browser-selection.js.map +1 -0
- package/dist/application/capabilities.d.ts +20 -0
- package/dist/application/capabilities.js +22 -0
- package/dist/application/capabilities.js.map +1 -0
- package/dist/application/collection-selection.d.ts +147 -0
- package/dist/application/collection-selection.js +351 -0
- package/dist/application/collection-selection.js.map +1 -0
- package/dist/application/configuration.d.ts +52 -0
- package/dist/application/configuration.js +568 -0
- package/dist/application/configuration.js.map +1 -0
- package/dist/application/declaration.d.ts +51 -0
- package/dist/application/declaration.js +100 -0
- package/dist/application/declaration.js.map +1 -0
- package/dist/application/entry.d.ts +343 -0
- package/dist/application/entry.js +945 -0
- package/dist/application/entry.js.map +1 -0
- package/dist/application/file-access.d.ts +55 -0
- package/dist/application/file-access.js +93 -0
- package/dist/application/file-access.js.map +1 -0
- package/dist/application/file-readiness.d.ts +16 -0
- package/dist/application/file-readiness.js +53 -0
- package/dist/application/file-readiness.js.map +1 -0
- package/dist/application/forgotten.d.ts +15 -0
- package/dist/application/forgotten.js +70 -0
- package/dist/application/forgotten.js.map +1 -0
- package/dist/application/front-door.d.ts +68 -0
- package/dist/application/front-door.js +66 -0
- package/dist/application/front-door.js.map +1 -0
- package/dist/application/local-build.d.ts +5 -0
- package/dist/application/local-build.js +22 -0
- package/dist/application/local-build.js.map +1 -0
- package/dist/application/manifest.d.ts +16 -0
- package/dist/application/manifest.js +31 -0
- package/dist/application/manifest.js.map +1 -0
- package/dist/application/native-assets.d.ts +25 -0
- package/dist/application/native-assets.js +29 -0
- package/dist/application/native-assets.js.map +1 -0
- package/dist/application/native-authorization-rpc.d.ts +23 -0
- package/dist/application/native-authorization-rpc.js +54 -0
- package/dist/application/native-authorization-rpc.js.map +1 -0
- package/dist/application/notification-readiness.d.ts +33 -0
- package/dist/application/notification-readiness.js +222 -0
- package/dist/application/notification-readiness.js.map +1 -0
- package/dist/application/packaged-assets.d.ts +5 -0
- package/dist/application/packaged-assets.js +55 -0
- package/dist/application/packaged-assets.js.map +1 -0
- package/dist/application/packaged-trust.d.ts +5 -0
- package/dist/application/packaged-trust.js +10 -0
- package/dist/application/packaged-trust.js.map +1 -0
- package/dist/application/people-readiness.d.ts +23 -0
- package/dist/application/people-readiness.js +213 -0
- package/dist/application/people-readiness.js.map +1 -0
- package/dist/application/phase.d.ts +108 -0
- package/dist/application/phase.js +113 -0
- package/dist/application/phase.js.map +1 -0
- package/dist/application/portal-reservation.d.ts +38 -0
- package/dist/application/portal-reservation.js +183 -0
- package/dist/application/portal-reservation.js.map +1 -0
- package/dist/application/private-collections.d.ts +114 -0
- package/dist/application/private-collections.js +415 -0
- package/dist/application/private-collections.js.map +1 -0
- package/dist/application/readiness.d.ts +59 -0
- package/dist/application/readiness.js +223 -0
- package/dist/application/readiness.js.map +1 -0
- package/dist/application/registration-refusal.d.ts +16 -0
- package/dist/application/registration-refusal.js +41 -0
- package/dist/application/registration-refusal.js.map +1 -0
- package/dist/application/registration.d.ts +26 -0
- package/dist/application/registration.js +372 -0
- package/dist/application/registration.js.map +1 -0
- package/dist/application/return-url.d.ts +1 -0
- package/dist/application/return-url.js +40 -0
- package/dist/application/return-url.js.map +1 -0
- package/dist/application/runtime.d.ts +107 -0
- package/dist/application/runtime.js +379 -0
- package/dist/application/runtime.js.map +1 -0
- package/dist/application/scope.d.ts +34 -0
- package/dist/application/scope.js +164 -0
- package/dist/application/scope.js.map +1 -0
- package/dist/application/session-hint.d.ts +21 -0
- package/dist/application/session-hint.js +87 -0
- package/dist/application/session-hint.js.map +1 -0
- package/dist/application/setup.d.ts +105 -0
- package/dist/application/setup.js +137 -0
- package/dist/application/setup.js.map +1 -0
- package/dist/application/sign-out.d.ts +17 -0
- package/dist/application/sign-out.js +28 -0
- package/dist/application/sign-out.js.map +1 -0
- package/dist/application/storage-scope.d.ts +8 -0
- package/dist/application/storage-scope.js +15 -0
- package/dist/application/storage-scope.js.map +1 -0
- package/dist/application/tabs.d.ts +98 -0
- package/dist/application/tabs.js +407 -0
- package/dist/application/tabs.js.map +1 -0
- package/dist/application/timer-criteria.d.ts +5 -0
- package/dist/application/timer-criteria.js +15 -0
- package/dist/application/timer-criteria.js.map +1 -0
- package/dist/application/ui-connections.d.ts +35 -0
- package/dist/application/ui-connections.js +129 -0
- package/dist/application/ui-connections.js.map +1 -0
- package/dist/application/worker-client.d.ts +59 -0
- package/dist/application/worker-client.js +381 -0
- package/dist/application/worker-client.js.map +1 -0
- package/dist/application/worker-host.d.ts +84 -0
- package/dist/application/worker-host.js +547 -0
- package/dist/application/worker-host.js.map +1 -0
- package/dist/application/worker-protocol.d.ts +40 -0
- package/dist/application/worker-protocol.js +83 -0
- package/dist/application/worker-protocol.js.map +1 -0
- package/dist/application/worker-session.d.ts +45 -0
- package/dist/application/worker-session.js +37 -0
- package/dist/application/worker-session.js.map +1 -0
- package/dist/application/worker.d.ts +1 -0
- package/dist/application/worker.js +34835 -0
- package/dist/application/worker.js.map +1 -0
- package/dist/attachment-wire.d.ts +15 -0
- package/dist/attachment-wire.js +47 -0
- package/dist/attachment-wire.js.map +1 -0
- package/dist/browser/mdbase-sdk.js +49398 -0
- package/dist/browser/mdbase-sdk.min.js +130 -0
- package/dist/browser.d.ts +4 -0
- package/dist/browser.js +5 -0
- package/dist/browser.js.map +1 -0
- package/dist/cbor.d.ts +52 -0
- package/dist/cbor.js +480 -0
- package/dist/cbor.js.map +1 -0
- package/dist/client.d.ts +658 -0
- package/dist/client.js +1966 -0
- package/dist/client.js.map +1 -0
- package/dist/codec.d.ts +82 -0
- package/dist/codec.js +388 -0
- package/dist/codec.js.map +1 -0
- package/dist/collection-availability.d.ts +34 -0
- package/dist/collection-availability.js +63 -0
- package/dist/collection-availability.js.map +1 -0
- package/dist/contract-query.d.ts +31 -0
- package/dist/contract-query.js +13 -0
- package/dist/contract-query.js.map +1 -0
- package/dist/contract-records.d.ts +51 -0
- package/dist/contract-records.js +14 -0
- package/dist/contract-records.js.map +1 -0
- package/dist/describe-error.d.ts +61 -0
- package/dist/describe-error.js +452 -0
- package/dist/describe-error.js.map +1 -0
- package/dist/errors.d.ts +65 -0
- package/dist/errors.js +94 -0
- package/dist/errors.js.map +1 -0
- package/dist/files.d.ts +147 -0
- package/dist/files.js +537 -0
- package/dist/files.js.map +1 -0
- package/dist/holds.d.ts +74 -0
- package/dist/holds.js +118 -0
- package/dist/holds.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/keys.d.ts +40 -0
- package/dist/keys.js +181 -0
- package/dist/keys.js.map +1 -0
- package/dist/live.d.ts +38 -0
- package/dist/live.js +82 -0
- package/dist/live.js.map +1 -0
- package/dist/local-build.d.ts +13 -0
- package/dist/local-build.js +47 -0
- package/dist/local-build.js.map +1 -0
- package/dist/native/provenance.json +23 -0
- package/dist/native/runtime.wasm +0 -0
- package/dist/native/sqlite3.d.ts +5 -0
- package/dist/native/sqlite3.js +17392 -0
- package/dist/native/sqlite3.js.map +1 -0
- package/dist/native/sqlite3.wasm +0 -0
- package/dist/node.d.ts +63 -0
- package/dist/node.js +255 -0
- package/dist/node.js.map +1 -0
- package/dist/notifications.d.ts +95 -0
- package/dist/notifications.js +226 -0
- package/dist/notifications.js.map +1 -0
- package/dist/offline-shell-build.d.ts +25 -0
- package/dist/offline-shell-build.js +78 -0
- package/dist/offline-shell-build.js.map +1 -0
- package/dist/offline-shell-worker.d.ts +46 -0
- package/dist/offline-shell-worker.js +115 -0
- package/dist/offline-shell-worker.js.map +1 -0
- package/dist/people.d.ts +82 -0
- package/dist/people.js +199 -0
- package/dist/people.js.map +1 -0
- package/dist/presence.d.ts +21 -0
- package/dist/presence.js +109 -0
- package/dist/presence.js.map +1 -0
- package/dist/private-account.d.ts +197 -0
- package/dist/private-account.js +510 -0
- package/dist/private-account.js.map +1 -0
- package/dist/private.d.ts +55 -0
- package/dist/private.js +69 -0
- package/dist/private.js.map +1 -0
- package/dist/read-helpers.d.ts +32 -0
- package/dist/read-helpers.js +181 -0
- package/dist/read-helpers.js.map +1 -0
- package/dist/records/session.d.ts +60 -0
- package/dist/records/session.js +534 -0
- package/dist/records/session.js.map +1 -0
- package/dist/records/types.d.ts +76 -0
- package/dist/records/types.js +2 -0
- package/dist/records/types.js.map +1 -0
- package/dist/records/witness.d.ts +19 -0
- package/dist/records/witness.js +64 -0
- package/dist/records/witness.js.map +1 -0
- package/dist/records.d.ts +23 -0
- package/dist/records.js +234 -0
- package/dist/records.js.map +1 -0
- package/dist/runtime/wasm.d.ts +69 -0
- package/dist/runtime/wasm.js +274 -0
- package/dist/runtime/wasm.js.map +1 -0
- package/dist/runtime-wire.d.ts +71 -0
- package/dist/runtime-wire.js +71 -0
- package/dist/runtime-wire.js.map +1 -0
- package/dist/saved-views.d.ts +29 -0
- package/dist/saved-views.js +171 -0
- package/dist/saved-views.js.map +1 -0
- package/dist/semver.d.ts +22 -0
- package/dist/semver.js +63 -0
- package/dist/semver.js.map +1 -0
- package/dist/session.d.ts +65 -0
- package/dist/session.js +332 -0
- package/dist/session.js.map +1 -0
- package/dist/status.d.ts +46 -0
- package/dist/status.js +59 -0
- package/dist/status.js.map +1 -0
- package/dist/strength.d.ts +12 -0
- package/dist/strength.js +194 -0
- package/dist/strength.js.map +1 -0
- package/dist/testing/application.d.ts +59 -0
- package/dist/testing/application.js +230 -0
- package/dist/testing/application.js.map +1 -0
- package/dist/testing/index.d.ts +10 -0
- package/dist/testing/index.js +6 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/memory-contracts.d.ts +40 -0
- package/dist/testing/memory-contracts.js +127 -0
- package/dist/testing/memory-contracts.js.map +1 -0
- package/dist/testing/memory-replica.d.ts +191 -0
- package/dist/testing/memory-replica.js +1465 -0
- package/dist/testing/memory-replica.js.map +1 -0
- package/dist/testing/noise-server.d.ts +11 -0
- package/dist/testing/noise-server.js +65 -0
- package/dist/testing/noise-server.js.map +1 -0
- package/dist/testing/test-app.d.ts +93 -0
- package/dist/testing/test-app.js +140 -0
- package/dist/testing/test-app.js.map +1 -0
- package/dist/thin-client.d.ts +67 -0
- package/dist/thin-client.js +42 -0
- package/dist/thin-client.js.map +1 -0
- package/dist/timers.d.ts +158 -0
- package/dist/timers.js +258 -0
- package/dist/timers.js.map +1 -0
- package/dist/transport/bases-rpc.d.ts +15 -0
- package/dist/transport/bases-rpc.js +61 -0
- package/dist/transport/bases-rpc.js.map +1 -0
- package/dist/transport/control-route.d.ts +34 -0
- package/dist/transport/control-route.js +84 -0
- package/dist/transport/control-route.js.map +1 -0
- package/dist/transport/inprocess.d.ts +13 -0
- package/dist/transport/inprocess.js +37 -0
- package/dist/transport/inprocess.js.map +1 -0
- package/dist/transport/local-link.d.ts +53 -0
- package/dist/transport/local-link.js +66 -0
- package/dist/transport/local-link.js.map +1 -0
- package/dist/transport/next-relay.d.ts +64 -0
- package/dist/transport/next-relay.js +222 -0
- package/dist/transport/next-relay.js.map +1 -0
- package/dist/transport/noise-session.d.ts +88 -0
- package/dist/transport/noise-session.js +264 -0
- package/dist/transport/noise-session.js.map +1 -0
- package/dist/transport/noise.d.ts +102 -0
- package/dist/transport/noise.js +307 -0
- package/dist/transport/noise.js.map +1 -0
- package/dist/transport/original-session.d.ts +6 -0
- package/dist/transport/original-session.js +6 -0
- package/dist/transport/original-session.js.map +1 -0
- package/dist/transport/port.d.ts +67 -0
- package/dist/transport/port.js +184 -0
- package/dist/transport/port.js.map +1 -0
- package/dist/transport/read-fence-policy.d.ts +3 -0
- package/dist/transport/read-fence-policy.js +11 -0
- package/dist/transport/read-fence-policy.js.map +1 -0
- package/dist/transport/relay-close.d.ts +31 -0
- package/dist/transport/relay-close.js +23 -0
- package/dist/transport/relay-close.js.map +1 -0
- package/dist/transport/relay-pipe.d.ts +15 -0
- package/dist/transport/relay-pipe.js +190 -0
- package/dist/transport/relay-pipe.js.map +1 -0
- package/dist/transport/relay.d.ts +36 -0
- package/dist/transport/relay.js +45 -0
- package/dist/transport/relay.js.map +1 -0
- package/dist/type-packs.d.ts +124 -0
- package/dist/type-packs.js +188 -0
- package/dist/type-packs.js.map +1 -0
- package/dist/validation.d.ts +30 -0
- package/dist/validation.js +125 -0
- package/dist/validation.js.map +1 -0
- package/dist/values.d.ts +37 -0
- package/dist/values.js +133 -0
- package/dist/values.js.map +1 -0
- package/dist/view-sources.d.ts +31 -0
- package/dist/view-sources.js +78 -0
- package/dist/view-sources.js.map +1 -0
- package/dist/wire.d.ts +857 -0
- package/dist/wire.js +915 -0
- package/dist/wire.js.map +1 -0
- package/dist/witness.d.ts +7 -0
- package/dist/witness.js +82 -0
- package/dist/witness.js.map +1 -0
- package/dist/write-ledger.d.ts +41 -0
- package/dist/write-ledger.js +184 -0
- package/dist/write-ledger.js.map +1 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/application-authorization.d.ts +32 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/application-authorization.js +207 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/application-contract.d.ts +23 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/application-contract.js +76 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/application-declaration.d.ts +120 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/application-declaration.js +1 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/authorization-errors.d.ts +34 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/authorization-errors.js +52 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/capabilities.d.ts +73 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/capabilities.js +92 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/change-events.generated.d.ts +48 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/change-events.generated.js +18 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/collection-setup.d.ts +93 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/collection-setup.js +7 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/compatibility.d.ts +37 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/compatibility.js +65 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/connect-problems.generated.d.ts +1533 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/connect-problems.generated.js +598 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/files.d.ts +288 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/files.js +426 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/index.d.ts +723 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/index.js +104 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/manifest-validators.generated.d.ts +13 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/manifest-validators.generated.js +7940 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/manifest.d.ts +72 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/manifest.js +643 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/mutation-fingerprint.d.ts +6 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/mutation-fingerprint.js +116 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/next-authorization.d.ts +30 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/next-authorization.js +90 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/operations.d.ts +15 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/operations.js +196 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/people.d.ts +33 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/people.js +26 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/records.d.ts +108 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/records.js +3 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/type-packs.d.ts +154 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/type-packs.js +30 -0
- package/node_modules/@mdbase-dev/connect-protocol/package.json +49 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/application-capability-catalog.v1.json +40 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/application-capability-catalog.v2.json +68 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/catalog.json +17 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/change-events.v1.json +48 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/connect-problem.v1.schema.json +5665 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/connect-problems.v1.catalog.json +373 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/connect-protocol.v1.schema.json +901 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/data-contract.schema.json +163 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/encrypted-relay.v1.schema.json +63 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/encrypted-relay.v2.schema.json +63 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/encrypted-relay.v3.schema.json +64 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/files.v1.schema.json +551 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/interop/v0.1/action-cancellation.schema.json +6 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/interop/v0.1/action-invocation.schema.json +6 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/interop/v0.1/action-outcome.schema.json +6 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/interop/v0.1/action-provider-declaration.schema.json +6 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/interop/v0.1/action-request.schema.json +6 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/interop/v0.1/conformance-claim.schema.json +6 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/interop/v0.1/event-source-declaration.schema.json +6 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/interop/v0.1/event.schema.json +6 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/interop/v0.1/profile.schema.json +456 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/mdbase-app.legacy-v1.schema.json +430 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/mdbase-app.schema.json +437 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/mdbase-query.v0.3.schema.json +176 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/next-trust.v1.schema.json +54 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/notification-webhook.v1.schema.json +56 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/operation-catalog.v1.json +43 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/operation-mutation-classification.v1.json +554 -0
- package/node_modules/@mdbase-dev/connect-protocol/schemas/sync.v1.schema.json +483 -0
- package/node_modules/@noble/hashes/LICENSE +21 -0
- package/node_modules/@noble/hashes/README.md +478 -0
- package/node_modules/@noble/hashes/_blake.d.ts +20 -0
- package/node_modules/@noble/hashes/_blake.js +59 -0
- package/node_modules/@noble/hashes/_md.d.ts +95 -0
- package/node_modules/@noble/hashes/_md.js +209 -0
- package/node_modules/@noble/hashes/_u64.d.ts +36 -0
- package/node_modules/@noble/hashes/_u64.js +77 -0
- package/node_modules/@noble/hashes/argon2.d.ts +148 -0
- package/node_modules/@noble/hashes/argon2.js +577 -0
- package/node_modules/@noble/hashes/blake1.d.ts +162 -0
- package/node_modules/@noble/hashes/blake1.js +630 -0
- package/node_modules/@noble/hashes/blake2.d.ts +203 -0
- package/node_modules/@noble/hashes/blake2.js +573 -0
- package/node_modules/@noble/hashes/blake3.d.ts +68 -0
- package/node_modules/@noble/hashes/blake3.js +310 -0
- package/node_modules/@noble/hashes/eskdf.d.ts +91 -0
- package/node_modules/@noble/hashes/eskdf.js +225 -0
- package/node_modules/@noble/hashes/hkdf.d.ts +70 -0
- package/node_modules/@noble/hashes/hkdf.js +152 -0
- package/node_modules/@noble/hashes/hmac.d.ts +50 -0
- package/node_modules/@noble/hashes/hmac.js +93 -0
- package/node_modules/@noble/hashes/index.d.ts +1 -0
- package/node_modules/@noble/hashes/index.js +34 -0
- package/node_modules/@noble/hashes/legacy.d.ts +107 -0
- package/node_modules/@noble/hashes/legacy.js +348 -0
- package/node_modules/@noble/hashes/package.json +91 -0
- package/node_modules/@noble/hashes/pbkdf2.d.ts +66 -0
- package/node_modules/@noble/hashes/pbkdf2.js +176 -0
- package/node_modules/@noble/hashes/scrypt.d.ts +98 -0
- package/node_modules/@noble/hashes/scrypt.js +304 -0
- package/node_modules/@noble/hashes/sha2.d.ts +176 -0
- package/node_modules/@noble/hashes/sha2.js +446 -0
- package/node_modules/@noble/hashes/sha3-addons.d.ts +533 -0
- package/node_modules/@noble/hashes/sha3-addons.js +973 -0
- package/node_modules/@noble/hashes/sha3.d.ts +208 -0
- package/node_modules/@noble/hashes/sha3.js +475 -0
- package/node_modules/@noble/hashes/src/_blake.ts +67 -0
- package/node_modules/@noble/hashes/src/_md.ts +227 -0
- package/node_modules/@noble/hashes/src/_u64.ts +111 -0
- package/node_modules/@noble/hashes/src/argon2.ts +693 -0
- package/node_modules/@noble/hashes/src/blake1.ts +677 -0
- package/node_modules/@noble/hashes/src/blake2.ts +648 -0
- package/node_modules/@noble/hashes/src/blake3.ts +344 -0
- package/node_modules/@noble/hashes/src/eskdf.ts +265 -0
- package/node_modules/@noble/hashes/src/hkdf.ts +161 -0
- package/node_modules/@noble/hashes/src/hmac.ts +130 -0
- package/node_modules/@noble/hashes/src/index.ts +33 -0
- package/node_modules/@noble/hashes/src/legacy.ts +361 -0
- package/node_modules/@noble/hashes/src/pbkdf2.ts +219 -0
- package/node_modules/@noble/hashes/src/scrypt.ts +375 -0
- package/node_modules/@noble/hashes/src/sha2.ts +486 -0
- package/node_modules/@noble/hashes/src/sha3-addons.ts +1157 -0
- package/node_modules/@noble/hashes/src/sha3.ts +525 -0
- package/node_modules/@noble/hashes/src/utils.ts +978 -0
- package/node_modules/@noble/hashes/src/webcrypto.ts +283 -0
- package/node_modules/@noble/hashes/utils.d.ts +560 -0
- package/node_modules/@noble/hashes/utils.js +687 -0
- package/node_modules/@noble/hashes/webcrypto.d.ts +121 -0
- package/node_modules/@noble/hashes/webcrypto.js +228 -0
- package/node_modules/yaml/LICENSE +13 -0
- package/node_modules/yaml/README.md +172 -0
- package/node_modules/yaml/bin.mjs +11 -0
- package/node_modules/yaml/browser/dist/compose/compose-collection.js +88 -0
- package/node_modules/yaml/browser/dist/compose/compose-doc.js +43 -0
- package/node_modules/yaml/browser/dist/compose/compose-node.js +109 -0
- package/node_modules/yaml/browser/dist/compose/compose-scalar.js +86 -0
- package/node_modules/yaml/browser/dist/compose/composer.js +219 -0
- package/node_modules/yaml/browser/dist/compose/resolve-block-map.js +115 -0
- package/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js +198 -0
- package/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +49 -0
- package/node_modules/yaml/browser/dist/compose/resolve-end.js +37 -0
- package/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +207 -0
- package/node_modules/yaml/browser/dist/compose/resolve-flow-scalar.js +226 -0
- package/node_modules/yaml/browser/dist/compose/resolve-props.js +146 -0
- package/node_modules/yaml/browser/dist/compose/util-contains-newline.js +34 -0
- package/node_modules/yaml/browser/dist/compose/util-empty-scalar-position.js +26 -0
- package/node_modules/yaml/browser/dist/compose/util-flow-indent-check.js +15 -0
- package/node_modules/yaml/browser/dist/compose/util-map-includes.js +13 -0
- package/node_modules/yaml/browser/dist/doc/Document.js +335 -0
- package/node_modules/yaml/browser/dist/doc/anchors.js +71 -0
- package/node_modules/yaml/browser/dist/doc/applyReviver.js +55 -0
- package/node_modules/yaml/browser/dist/doc/createNode.js +88 -0
- package/node_modules/yaml/browser/dist/doc/directives.js +176 -0
- package/node_modules/yaml/browser/dist/errors.js +57 -0
- package/node_modules/yaml/browser/dist/index.js +17 -0
- package/node_modules/yaml/browser/dist/log.js +11 -0
- package/node_modules/yaml/browser/dist/nodes/Alias.js +118 -0
- package/node_modules/yaml/browser/dist/nodes/Collection.js +147 -0
- package/node_modules/yaml/browser/dist/nodes/Node.js +38 -0
- package/node_modules/yaml/browser/dist/nodes/Pair.js +36 -0
- package/node_modules/yaml/browser/dist/nodes/Scalar.js +24 -0
- package/node_modules/yaml/browser/dist/nodes/YAMLMap.js +144 -0
- package/node_modules/yaml/browser/dist/nodes/YAMLSeq.js +113 -0
- package/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +63 -0
- package/node_modules/yaml/browser/dist/nodes/identity.js +36 -0
- package/node_modules/yaml/browser/dist/nodes/toJS.js +37 -0
- package/node_modules/yaml/browser/dist/parse/cst-scalar.js +214 -0
- package/node_modules/yaml/browser/dist/parse/cst-stringify.js +61 -0
- package/node_modules/yaml/browser/dist/parse/cst-visit.js +97 -0
- package/node_modules/yaml/browser/dist/parse/cst.js +98 -0
- package/node_modules/yaml/browser/dist/parse/lexer.js +721 -0
- package/node_modules/yaml/browser/dist/parse/line-counter.js +39 -0
- package/node_modules/yaml/browser/dist/parse/parser.js +975 -0
- package/node_modules/yaml/browser/dist/public-api.js +102 -0
- package/node_modules/yaml/browser/dist/schema/Schema.js +37 -0
- package/node_modules/yaml/browser/dist/schema/common/map.js +17 -0
- package/node_modules/yaml/browser/dist/schema/common/null.js +15 -0
- package/node_modules/yaml/browser/dist/schema/common/seq.js +17 -0
- package/node_modules/yaml/browser/dist/schema/common/string.js +14 -0
- package/node_modules/yaml/browser/dist/schema/core/bool.js +19 -0
- package/node_modules/yaml/browser/dist/schema/core/float.js +43 -0
- package/node_modules/yaml/browser/dist/schema/core/int.js +38 -0
- package/node_modules/yaml/browser/dist/schema/core/schema.js +23 -0
- package/node_modules/yaml/browser/dist/schema/json/schema.js +62 -0
- package/node_modules/yaml/browser/dist/schema/tags.js +96 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/binary.js +58 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/bool.js +26 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js +46 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/int.js +71 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/merge.js +67 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js +74 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js +78 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/schema.js +39 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/set.js +93 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js +101 -0
- package/node_modules/yaml/browser/dist/stringify/foldFlowLines.js +146 -0
- package/node_modules/yaml/browser/dist/stringify/stringify.js +129 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyCollection.js +153 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyComment.js +20 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyDocument.js +85 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyNumber.js +25 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyPair.js +150 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyString.js +336 -0
- package/node_modules/yaml/browser/dist/util.js +11 -0
- package/node_modules/yaml/browser/dist/visit.js +233 -0
- package/node_modules/yaml/browser/index.js +5 -0
- package/node_modules/yaml/browser/package.json +3 -0
- package/node_modules/yaml/dist/cli.d.ts +8 -0
- package/node_modules/yaml/dist/cli.mjs +201 -0
- package/node_modules/yaml/dist/compose/compose-collection.d.ts +11 -0
- package/node_modules/yaml/dist/compose/compose-collection.js +90 -0
- package/node_modules/yaml/dist/compose/compose-doc.d.ts +7 -0
- package/node_modules/yaml/dist/compose/compose-doc.js +45 -0
- package/node_modules/yaml/dist/compose/compose-node.d.ts +29 -0
- package/node_modules/yaml/dist/compose/compose-node.js +112 -0
- package/node_modules/yaml/dist/compose/compose-scalar.d.ts +5 -0
- package/node_modules/yaml/dist/compose/compose-scalar.js +88 -0
- package/node_modules/yaml/dist/compose/composer.d.ts +63 -0
- package/node_modules/yaml/dist/compose/composer.js +224 -0
- package/node_modules/yaml/dist/compose/resolve-block-map.d.ts +6 -0
- package/node_modules/yaml/dist/compose/resolve-block-map.js +117 -0
- package/node_modules/yaml/dist/compose/resolve-block-scalar.d.ts +11 -0
- package/node_modules/yaml/dist/compose/resolve-block-scalar.js +200 -0
- package/node_modules/yaml/dist/compose/resolve-block-seq.d.ts +6 -0
- package/node_modules/yaml/dist/compose/resolve-block-seq.js +51 -0
- package/node_modules/yaml/dist/compose/resolve-end.d.ts +6 -0
- package/node_modules/yaml/dist/compose/resolve-end.js +39 -0
- package/node_modules/yaml/dist/compose/resolve-flow-collection.d.ts +7 -0
- package/node_modules/yaml/dist/compose/resolve-flow-collection.js +209 -0
- package/node_modules/yaml/dist/compose/resolve-flow-scalar.d.ts +10 -0
- package/node_modules/yaml/dist/compose/resolve-flow-scalar.js +228 -0
- package/node_modules/yaml/dist/compose/resolve-props.d.ts +23 -0
- package/node_modules/yaml/dist/compose/resolve-props.js +148 -0
- package/node_modules/yaml/dist/compose/util-contains-newline.d.ts +2 -0
- package/node_modules/yaml/dist/compose/util-contains-newline.js +36 -0
- package/node_modules/yaml/dist/compose/util-empty-scalar-position.d.ts +2 -0
- package/node_modules/yaml/dist/compose/util-empty-scalar-position.js +28 -0
- package/node_modules/yaml/dist/compose/util-flow-indent-check.d.ts +3 -0
- package/node_modules/yaml/dist/compose/util-flow-indent-check.js +17 -0
- package/node_modules/yaml/dist/compose/util-map-includes.d.ts +4 -0
- package/node_modules/yaml/dist/compose/util-map-includes.js +15 -0
- package/node_modules/yaml/dist/doc/Document.d.ts +141 -0
- package/node_modules/yaml/dist/doc/Document.js +337 -0
- package/node_modules/yaml/dist/doc/anchors.d.ts +24 -0
- package/node_modules/yaml/dist/doc/anchors.js +76 -0
- package/node_modules/yaml/dist/doc/applyReviver.d.ts +9 -0
- package/node_modules/yaml/dist/doc/applyReviver.js +57 -0
- package/node_modules/yaml/dist/doc/createNode.d.ts +17 -0
- package/node_modules/yaml/dist/doc/createNode.js +90 -0
- package/node_modules/yaml/dist/doc/directives.d.ts +49 -0
- package/node_modules/yaml/dist/doc/directives.js +178 -0
- package/node_modules/yaml/dist/errors.d.ts +21 -0
- package/node_modules/yaml/dist/errors.js +62 -0
- package/node_modules/yaml/dist/index.d.ts +25 -0
- package/node_modules/yaml/dist/index.js +50 -0
- package/node_modules/yaml/dist/log.d.ts +3 -0
- package/node_modules/yaml/dist/log.js +19 -0
- package/node_modules/yaml/dist/nodes/Alias.d.ts +29 -0
- package/node_modules/yaml/dist/nodes/Alias.js +120 -0
- package/node_modules/yaml/dist/nodes/Collection.d.ts +73 -0
- package/node_modules/yaml/dist/nodes/Collection.js +151 -0
- package/node_modules/yaml/dist/nodes/Node.d.ts +53 -0
- package/node_modules/yaml/dist/nodes/Node.js +40 -0
- package/node_modules/yaml/dist/nodes/Pair.d.ts +22 -0
- package/node_modules/yaml/dist/nodes/Pair.js +39 -0
- package/node_modules/yaml/dist/nodes/Scalar.d.ts +47 -0
- package/node_modules/yaml/dist/nodes/Scalar.js +27 -0
- package/node_modules/yaml/dist/nodes/YAMLMap.d.ts +53 -0
- package/node_modules/yaml/dist/nodes/YAMLMap.js +147 -0
- package/node_modules/yaml/dist/nodes/YAMLSeq.d.ts +60 -0
- package/node_modules/yaml/dist/nodes/YAMLSeq.js +115 -0
- package/node_modules/yaml/dist/nodes/addPairToJSMap.d.ts +4 -0
- package/node_modules/yaml/dist/nodes/addPairToJSMap.js +65 -0
- package/node_modules/yaml/dist/nodes/identity.d.ts +23 -0
- package/node_modules/yaml/dist/nodes/identity.js +53 -0
- package/node_modules/yaml/dist/nodes/toJS.d.ts +29 -0
- package/node_modules/yaml/dist/nodes/toJS.js +39 -0
- package/node_modules/yaml/dist/options.d.ts +350 -0
- package/node_modules/yaml/dist/parse/cst-scalar.d.ts +64 -0
- package/node_modules/yaml/dist/parse/cst-scalar.js +218 -0
- package/node_modules/yaml/dist/parse/cst-stringify.d.ts +8 -0
- package/node_modules/yaml/dist/parse/cst-stringify.js +63 -0
- package/node_modules/yaml/dist/parse/cst-visit.d.ts +39 -0
- package/node_modules/yaml/dist/parse/cst-visit.js +99 -0
- package/node_modules/yaml/dist/parse/cst.d.ts +109 -0
- package/node_modules/yaml/dist/parse/cst.js +112 -0
- package/node_modules/yaml/dist/parse/lexer.d.ts +87 -0
- package/node_modules/yaml/dist/parse/lexer.js +723 -0
- package/node_modules/yaml/dist/parse/line-counter.d.ts +22 -0
- package/node_modules/yaml/dist/parse/line-counter.js +41 -0
- package/node_modules/yaml/dist/parse/parser.d.ts +84 -0
- package/node_modules/yaml/dist/parse/parser.js +980 -0
- package/node_modules/yaml/dist/public-api.d.ts +44 -0
- package/node_modules/yaml/dist/public-api.js +107 -0
- package/node_modules/yaml/dist/schema/Schema.d.ts +17 -0
- package/node_modules/yaml/dist/schema/Schema.js +39 -0
- package/node_modules/yaml/dist/schema/common/map.d.ts +2 -0
- package/node_modules/yaml/dist/schema/common/map.js +19 -0
- package/node_modules/yaml/dist/schema/common/null.d.ts +4 -0
- package/node_modules/yaml/dist/schema/common/null.js +17 -0
- package/node_modules/yaml/dist/schema/common/seq.d.ts +2 -0
- package/node_modules/yaml/dist/schema/common/seq.js +19 -0
- package/node_modules/yaml/dist/schema/common/string.d.ts +2 -0
- package/node_modules/yaml/dist/schema/common/string.js +16 -0
- package/node_modules/yaml/dist/schema/core/bool.d.ts +4 -0
- package/node_modules/yaml/dist/schema/core/bool.js +21 -0
- package/node_modules/yaml/dist/schema/core/float.d.ts +4 -0
- package/node_modules/yaml/dist/schema/core/float.js +47 -0
- package/node_modules/yaml/dist/schema/core/int.d.ts +4 -0
- package/node_modules/yaml/dist/schema/core/int.js +42 -0
- package/node_modules/yaml/dist/schema/core/schema.d.ts +1 -0
- package/node_modules/yaml/dist/schema/core/schema.js +25 -0
- package/node_modules/yaml/dist/schema/json/schema.d.ts +2 -0
- package/node_modules/yaml/dist/schema/json/schema.js +64 -0
- package/node_modules/yaml/dist/schema/json-schema.d.ts +69 -0
- package/node_modules/yaml/dist/schema/tags.d.ts +48 -0
- package/node_modules/yaml/dist/schema/tags.js +99 -0
- package/node_modules/yaml/dist/schema/types.d.ts +92 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/binary.d.ts +2 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/binary.js +70 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/bool.d.ts +7 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/bool.js +29 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/float.d.ts +4 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/float.js +50 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/int.d.ts +5 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/int.js +76 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/merge.d.ts +9 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/merge.js +71 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/omap.d.ts +22 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/omap.js +77 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/pairs.d.ts +10 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/pairs.js +82 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/schema.d.ts +1 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/schema.js +41 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/set.d.ts +28 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/set.js +96 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.d.ts +6 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.js +105 -0
- package/node_modules/yaml/dist/stringify/foldFlowLines.d.ts +34 -0
- package/node_modules/yaml/dist/stringify/foldFlowLines.js +151 -0
- package/node_modules/yaml/dist/stringify/stringify.d.ts +21 -0
- package/node_modules/yaml/dist/stringify/stringify.js +132 -0
- package/node_modules/yaml/dist/stringify/stringifyCollection.d.ts +17 -0
- package/node_modules/yaml/dist/stringify/stringifyCollection.js +155 -0
- package/node_modules/yaml/dist/stringify/stringifyComment.d.ts +10 -0
- package/node_modules/yaml/dist/stringify/stringifyComment.js +24 -0
- package/node_modules/yaml/dist/stringify/stringifyDocument.d.ts +4 -0
- package/node_modules/yaml/dist/stringify/stringifyDocument.js +87 -0
- package/node_modules/yaml/dist/stringify/stringifyNumber.d.ts +2 -0
- package/node_modules/yaml/dist/stringify/stringifyNumber.js +27 -0
- package/node_modules/yaml/dist/stringify/stringifyPair.d.ts +3 -0
- package/node_modules/yaml/dist/stringify/stringifyPair.js +152 -0
- package/node_modules/yaml/dist/stringify/stringifyString.d.ts +9 -0
- package/node_modules/yaml/dist/stringify/stringifyString.js +338 -0
- package/node_modules/yaml/dist/test-events.d.ts +4 -0
- package/node_modules/yaml/dist/test-events.js +134 -0
- package/node_modules/yaml/dist/util.d.ts +16 -0
- package/node_modules/yaml/dist/util.js +28 -0
- package/node_modules/yaml/dist/visit.d.ts +102 -0
- package/node_modules/yaml/dist/visit.js +236 -0
- package/node_modules/yaml/package.json +97 -0
- package/node_modules/yaml/util.js +2 -0
- package/package.json +108 -4
- package/vendor/mdbase-connect-sdk-e6e66bcd172f.json +13 -0
- package/vendor/mdbase-dev-connect-protocol-0.1.0-beta.145-e6e66bcd172f.tgz +0 -0
|
@@ -0,0 +1,1465 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `MemoryReplica`: an in-memory stand-in for a replica that speaks the real client
|
|
3
|
+
* protocol (frames, hello, pushes, receipts). For SDK tests, app tests and demo modes.
|
|
4
|
+
*
|
|
5
|
+
* It is **not** the replica: no planner, merge or lifecycle. Its semantics are
|
|
6
|
+
* deliberately simple:
|
|
7
|
+
* - patches apply blindly, and bodies are replaced or edited;
|
|
8
|
+
* - `where` is evaluated by an optional callback;
|
|
9
|
+
* - mutations stay `pending` until confirmed, either after `confirmDelayMs` or by
|
|
10
|
+
* calling {@link MemoryReplica.confirmAll}.
|
|
11
|
+
*
|
|
12
|
+
* The real runtime replaces it behind the same `Connector`.
|
|
13
|
+
*/
|
|
14
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
15
|
+
import { decode, encode, Float64 } from "../cbor.js";
|
|
16
|
+
import { hash as hashCodec, hashFromBytes, list, uuid as uuidCodec } from "../codec.js";
|
|
17
|
+
import { ERROR_CODES, isMdbaseError, mdbaseError, MdbaseError } from "../errors.js";
|
|
18
|
+
import { portPair } from "../transport/port.js";
|
|
19
|
+
import { revisionOf, toPlain, toValue, uuidv7 } from "../values.js";
|
|
20
|
+
import * as w from "../wire.js";
|
|
21
|
+
import { accountKeyStatus } from "../private.js";
|
|
22
|
+
import { contractRecordWire, contractWritePlan } from "../contract-records.js";
|
|
23
|
+
import { contractQueryResult } from "../contract-query.js";
|
|
24
|
+
import { contractDigest, contractFields, implementationDigest, implementationFor, mapWrite, } from "./memory-contracts.js";
|
|
25
|
+
function problem(code, message, reason) {
|
|
26
|
+
const p = { code, recovery: ERROR_CODES[code], message };
|
|
27
|
+
if (reason)
|
|
28
|
+
p.reason = reason;
|
|
29
|
+
return p;
|
|
30
|
+
}
|
|
31
|
+
function renderDocument(r) {
|
|
32
|
+
const lines = [...r.frontmatter].map(([k, v]) => `${k}: ${JSON.stringify(toPlain(v))}`);
|
|
33
|
+
return lines.length ? `---\n${lines.join("\n")}\n---\n${r.body}` : r.body;
|
|
34
|
+
}
|
|
35
|
+
/** Synthetic frontmatter subset shared by document creates and replacements.
|
|
36
|
+
* Not Core's YAML/type/contract parser. */
|
|
37
|
+
function parseDocument(doc) {
|
|
38
|
+
const mm = /^---\n([\s\S]*?)\n---\n?([\s\S]*)$/.exec(doc);
|
|
39
|
+
const frontmatter = new Map();
|
|
40
|
+
for (const line of (mm?.[1] ?? "").split("\n")) {
|
|
41
|
+
const i = line.indexOf(":");
|
|
42
|
+
if (i > 0) {
|
|
43
|
+
const raw = line.slice(i + 1).trim();
|
|
44
|
+
let v = raw;
|
|
45
|
+
try {
|
|
46
|
+
v = JSON.parse(raw);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// keep as text
|
|
50
|
+
}
|
|
51
|
+
frontmatter.set(line.slice(0, i).trim(), v);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return { frontmatter, body: mm ? mm[2] : doc };
|
|
55
|
+
}
|
|
56
|
+
function revision(r) {
|
|
57
|
+
return hashFromBytes(sha256(new TextEncoder().encode(renderDocument(r))));
|
|
58
|
+
}
|
|
59
|
+
function mediaOf(path) {
|
|
60
|
+
const ext = path.slice(path.lastIndexOf(".") + 1).toLowerCase();
|
|
61
|
+
if (["png", "jpg", "jpeg", "gif", "webp", "svg", "avif"].includes(ext))
|
|
62
|
+
return "image";
|
|
63
|
+
if (["mp3", "wav", "ogg", "m4a", "flac"].includes(ext))
|
|
64
|
+
return "audio";
|
|
65
|
+
if (["mp4", "webm", "mov", "mkv"].includes(ext))
|
|
66
|
+
return "video";
|
|
67
|
+
if (ext === "pdf")
|
|
68
|
+
return "pdf";
|
|
69
|
+
return "other";
|
|
70
|
+
}
|
|
71
|
+
/** A few of Core's `paths::media_type` entries, enough for SDK tests. */
|
|
72
|
+
const MEDIA_TYPES = { png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", pdf: "application/pdf", txt: "text/plain" };
|
|
73
|
+
function mediaTypeOf(path) {
|
|
74
|
+
const name = path.slice(path.lastIndexOf("/") + 1);
|
|
75
|
+
const dot = name.lastIndexOf(".");
|
|
76
|
+
return dot < 0 ? undefined : MEDIA_TYPES[name.slice(dot + 1).toLowerCase()];
|
|
77
|
+
}
|
|
78
|
+
function applyScalarEdits(base, edits) {
|
|
79
|
+
const chars = Array.from(base);
|
|
80
|
+
// Apply from the end so earlier offsets stay valid.
|
|
81
|
+
for (const [start, end, insert] of [...edits].sort((a, b) => b[0] - a[0])) {
|
|
82
|
+
chars.splice(start, end - start, ...Array.from(insert));
|
|
83
|
+
}
|
|
84
|
+
return chars.join("");
|
|
85
|
+
}
|
|
86
|
+
export class MemoryReplica {
|
|
87
|
+
opts;
|
|
88
|
+
collection;
|
|
89
|
+
records = new Map();
|
|
90
|
+
files = new Map();
|
|
91
|
+
uploads = new Map();
|
|
92
|
+
receipts = new Map();
|
|
93
|
+
pendingQueue = [];
|
|
94
|
+
pendingRecords = new Map();
|
|
95
|
+
conns = new Set();
|
|
96
|
+
seq = 0;
|
|
97
|
+
viewVersion = 0;
|
|
98
|
+
changeLog = [];
|
|
99
|
+
nextSub = 1;
|
|
100
|
+
nextStream = 1;
|
|
101
|
+
online = true;
|
|
102
|
+
awaiters = new Map();
|
|
103
|
+
/** AK1 §6 stand-in: the secret `account_key_setup` enrolled, and this device's unlock state. */
|
|
104
|
+
accountKeySecret = null;
|
|
105
|
+
accountKey = { state: "idle" };
|
|
106
|
+
stalled = false;
|
|
107
|
+
loseNext = false;
|
|
108
|
+
failWrite = null;
|
|
109
|
+
holdList = new Map();
|
|
110
|
+
conflictList = [];
|
|
111
|
+
baseViews = new Map();
|
|
112
|
+
/** Test hook: answer `describe_typing` with this instead (for mismatch tests). */
|
|
113
|
+
typingAnswer;
|
|
114
|
+
constructor(opts = {}) {
|
|
115
|
+
this.opts = opts;
|
|
116
|
+
this.collection = opts.collection ?? uuidv7();
|
|
117
|
+
}
|
|
118
|
+
// ---------------------------------------------------------------- test controls
|
|
119
|
+
/** A connector for `MdbaseClient.connect`. Each `open` is a new session. */
|
|
120
|
+
connector() {
|
|
121
|
+
return {
|
|
122
|
+
description: "memory",
|
|
123
|
+
open: async (hello) => {
|
|
124
|
+
const [client, server] = portPair();
|
|
125
|
+
const conn = {
|
|
126
|
+
port: server,
|
|
127
|
+
subs: new Map(),
|
|
128
|
+
status: false,
|
|
129
|
+
holds: false,
|
|
130
|
+
conflicts: false,
|
|
131
|
+
changesWatch: false,
|
|
132
|
+
presence: new Set(),
|
|
133
|
+
joined: new Map(),
|
|
134
|
+
pseudonym: globalThis.crypto.getRandomValues(new Uint8Array(16)),
|
|
135
|
+
mutations: new Set(),
|
|
136
|
+
streams: new Map(),
|
|
137
|
+
};
|
|
138
|
+
const helloResponse = this.hello(hello);
|
|
139
|
+
if (this.opts.refuse) {
|
|
140
|
+
queueMicrotask(() => server.close());
|
|
141
|
+
return { port: client, helloResponse };
|
|
142
|
+
}
|
|
143
|
+
this.conns.add(conn);
|
|
144
|
+
Object.assign(client, {
|
|
145
|
+
readAppBases: async (bytes) => this.basesRead(bytes),
|
|
146
|
+
readAppBasesDiscovery: async (op, bytes) => this.basesDiscovery(op, bytes),
|
|
147
|
+
});
|
|
148
|
+
server.onframe = (f) => void this.onFrame(conn, f);
|
|
149
|
+
server.onclose = () => this.drop(conn);
|
|
150
|
+
return { port: client, helloResponse };
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
/** Drop every session (simulates a broken link; clients reconnect). */
|
|
155
|
+
dropConnections() {
|
|
156
|
+
for (const c of [...this.conns])
|
|
157
|
+
c.port.close();
|
|
158
|
+
}
|
|
159
|
+
/** Simulate the log service being unreachable: submits stay pending. */
|
|
160
|
+
setOnline(online) {
|
|
161
|
+
this.online = online;
|
|
162
|
+
this.pushStatus();
|
|
163
|
+
if (online && this.opts.confirmDelayMs !== null)
|
|
164
|
+
this.scheduleConfirm();
|
|
165
|
+
}
|
|
166
|
+
/** Seed a confirmed record directly. */
|
|
167
|
+
seed(r) {
|
|
168
|
+
const rec = {
|
|
169
|
+
id: r.id ?? uuidv7(),
|
|
170
|
+
path: r.path,
|
|
171
|
+
types: r.types ?? [],
|
|
172
|
+
frontmatter: new Map(Object.entries(r.frontmatter ?? {})),
|
|
173
|
+
body: r.body ?? "",
|
|
174
|
+
confirmedSeq: ++this.seq,
|
|
175
|
+
pending: false,
|
|
176
|
+
};
|
|
177
|
+
this.records.set(rec.id, rec);
|
|
178
|
+
this.touch(rec.id, rec.path, "put");
|
|
179
|
+
return rec;
|
|
180
|
+
}
|
|
181
|
+
/** Confirm every pending mutation now. */
|
|
182
|
+
confirmAll() {
|
|
183
|
+
while (this.pendingQueue.length)
|
|
184
|
+
this.confirmNext();
|
|
185
|
+
}
|
|
186
|
+
// ------------------------------------------------------------ faults (R6)
|
|
187
|
+
/** Another device edits a record; the change arrives confirmed. A `null`
|
|
188
|
+
* frontmatter value removes the field. */
|
|
189
|
+
editElsewhere(ref, change) {
|
|
190
|
+
const r = this.rec(ref);
|
|
191
|
+
if (change.body !== undefined)
|
|
192
|
+
r.body = change.body;
|
|
193
|
+
for (const [k, v] of Object.entries(change.frontmatter ?? {})) {
|
|
194
|
+
if (v === null)
|
|
195
|
+
r.frontmatter.delete(k);
|
|
196
|
+
else
|
|
197
|
+
r.frontmatter.set(k, v);
|
|
198
|
+
}
|
|
199
|
+
r.confirmedSeq = ++this.seq;
|
|
200
|
+
this.touch(r.id, r.path, "put");
|
|
201
|
+
this.pushStatus();
|
|
202
|
+
}
|
|
203
|
+
/** Another device renames (moves) a record. */
|
|
204
|
+
renameElsewhere(ref, to) {
|
|
205
|
+
const r = this.rec(ref), from = r.path;
|
|
206
|
+
r.path = to;
|
|
207
|
+
r.confirmedSeq = ++this.seq;
|
|
208
|
+
this.touch(r.id, from, "remove");
|
|
209
|
+
this.touch(r.id, to, "put");
|
|
210
|
+
this.pushStatus();
|
|
211
|
+
}
|
|
212
|
+
/** Another device deletes a record. */
|
|
213
|
+
deleteElsewhere(ref) {
|
|
214
|
+
const r = this.rec(ref);
|
|
215
|
+
this.records.delete(r.id);
|
|
216
|
+
++this.seq;
|
|
217
|
+
this.touch(r.id, r.path, "remove", "record", r.types);
|
|
218
|
+
this.pushStatus();
|
|
219
|
+
}
|
|
220
|
+
/** The next request runs but its response is lost and the session drops,
|
|
221
|
+
* as when a link breaks after a write was captured. Clients reconnect, and
|
|
222
|
+
* a resubmitted write (same mutation ID) gets its original receipt. */
|
|
223
|
+
loseNextResponse() {
|
|
224
|
+
this.loseNext = true;
|
|
225
|
+
}
|
|
226
|
+
/** The next submit fails with `p` and captures nothing. */
|
|
227
|
+
failNextWrite(p = problem("unavailable", "the replica could not take the write", "storage_busy")) {
|
|
228
|
+
this.failWrite = p;
|
|
229
|
+
}
|
|
230
|
+
/** Stuck pending: while stalled, writes are not confirmed on their own even
|
|
231
|
+
* though the replica is online (`confirmAll` still confirms). */
|
|
232
|
+
stallConfirmations(stalled = true) {
|
|
233
|
+
this.stalled = stalled;
|
|
234
|
+
if (!stalled)
|
|
235
|
+
this.scheduleConfirm();
|
|
236
|
+
}
|
|
237
|
+
/** Put a hold on a record (as the replica does on a conflicting or suspect
|
|
238
|
+
* write). Resolve it with `client.resolveHold`. */
|
|
239
|
+
hold(ref, o = {}) {
|
|
240
|
+
const r = this.rec(ref), id = uuidv7(), reason = o.reason ?? "conflict";
|
|
241
|
+
r.hold = { id, reason };
|
|
242
|
+
this.holdList.set(id, {
|
|
243
|
+
record: r.id,
|
|
244
|
+
hold: { id, path: r.path, reason, since: Date.now(), mine: o.mine ?? r.body, ...(o.theirs !== undefined ? { theirs: o.theirs } : {}), saves: 0 },
|
|
245
|
+
});
|
|
246
|
+
this.touch(r.id, r.path, "put");
|
|
247
|
+
this.pushHolds();
|
|
248
|
+
this.pushStatus();
|
|
249
|
+
return id;
|
|
250
|
+
}
|
|
251
|
+
/** Record a merged field conflict on a record (the kept value is applied). */
|
|
252
|
+
conflict(ref, o) {
|
|
253
|
+
const r = this.rec(ref);
|
|
254
|
+
r.frontmatter.set(o.field, toValue(o.kept));
|
|
255
|
+
r.confirmedSeq = ++this.seq;
|
|
256
|
+
r.unresolved = (r.unresolved ?? 0) + 1;
|
|
257
|
+
const entry = {
|
|
258
|
+
mutation: uuidv7(),
|
|
259
|
+
seq: this.seq,
|
|
260
|
+
conflict: { kind: "field", id: r.id, field: o.field, kept: { form: "value", value: toValue(o.kept) }, lost: { form: "value", value: toValue(o.lost) } },
|
|
261
|
+
};
|
|
262
|
+
this.conflictList.push(entry);
|
|
263
|
+
this.touch(r.id, r.path, "put");
|
|
264
|
+
this.pushConflicts();
|
|
265
|
+
this.pushStatus();
|
|
266
|
+
return entry;
|
|
267
|
+
}
|
|
268
|
+
/** Declare a type, so `describe` lists it with this definition and schema. */
|
|
269
|
+
seedType(name, definition = {}) {
|
|
270
|
+
const fm = { kind: "mdbase.type", name, ...definition };
|
|
271
|
+
const path = `_types/${name}.md`;
|
|
272
|
+
this.seedResource(path, `---\n${Object.entries(fm).map(([k, v]) => `${k}: ${JSON.stringify(v)}`).join("\n")}\n---\n`);
|
|
273
|
+
return path;
|
|
274
|
+
}
|
|
275
|
+
/** Add a saved view for app Bases reads (another view in the same file when
|
|
276
|
+
* the path exists). Returns its identity for `executeAppBases`. */
|
|
277
|
+
seedBaseView(view) {
|
|
278
|
+
if (!view.types.length)
|
|
279
|
+
throw new Error("MemoryReplica: a Bases view needs a type");
|
|
280
|
+
let r = [...this.records.values()].find((x) => x.path === view.path);
|
|
281
|
+
if (!r)
|
|
282
|
+
r = this.seed({ path: view.path });
|
|
283
|
+
const views = [...(this.baseViews.get(r.id) ?? []), view];
|
|
284
|
+
this.baseViews.set(r.id, views);
|
|
285
|
+
r.body = views.map((v) => `- name: ${JSON.stringify(v.name ?? null)}\n types: ${JSON.stringify(v.types)}\n columns: ${JSON.stringify(v.columns)}`).join("\n") + "\n";
|
|
286
|
+
r.confirmedSeq = ++this.seq;
|
|
287
|
+
this.touch(r.id, r.path, "put");
|
|
288
|
+
return { record: r.id, sourceRevision: revisionOf(r.body), ordinal: views.length - 1 };
|
|
289
|
+
}
|
|
290
|
+
rec(ref) {
|
|
291
|
+
const r = this.records.get(ref) ?? [...this.records.values()].find((x) => x.path === ref);
|
|
292
|
+
if (!r)
|
|
293
|
+
throw new Error(`MemoryReplica: no record ${ref}`);
|
|
294
|
+
return r;
|
|
295
|
+
}
|
|
296
|
+
pushHolds() {
|
|
297
|
+
const payload = list(w.hold).enc([...this.holdList.values()].map((h) => h.hold));
|
|
298
|
+
for (const c of this.conns)
|
|
299
|
+
if (c.holds)
|
|
300
|
+
this.push(c, "holds", payload);
|
|
301
|
+
}
|
|
302
|
+
pushConflicts() {
|
|
303
|
+
const payload = list(w.conflictEntry).enc(this.conflictList);
|
|
304
|
+
for (const c of this.conns)
|
|
305
|
+
if (c.conflicts)
|
|
306
|
+
this.push(c, "conflicts", payload);
|
|
307
|
+
}
|
|
308
|
+
// ------------------------------------------------------------ app Bases (subset)
|
|
309
|
+
basesClock() {
|
|
310
|
+
const now = new Date();
|
|
311
|
+
return w.opClock.enc({ instant: now.getTime(), tz: "UTC", localDate: now.toISOString().slice(0, 10) });
|
|
312
|
+
}
|
|
313
|
+
basesRevision() {
|
|
314
|
+
return hashCodec.enc(hashFromBytes(sha256(new TextEncoder().encode(`memory-${this.viewVersion}`))));
|
|
315
|
+
}
|
|
316
|
+
basesDescriptor(r, ordinal) {
|
|
317
|
+
const v = this.baseViews.get(r.id)[ordinal];
|
|
318
|
+
const digest = (s) => hashCodec.enc(hashFromBytes(sha256(new TextEncoder().encode(s))));
|
|
319
|
+
return new Map([
|
|
320
|
+
[0, uuidCodec.enc(r.id)], [1, r.path], [2, hashCodec.enc(revisionOf(r.body))], [3, ordinal],
|
|
321
|
+
[4, v.name ?? null], [5, "table"],
|
|
322
|
+
[6, v.types.map((t) => new Map([[0, t], [1, "1"], [2, digest(`contract:${t}`)], [3, digest(`implementation:${t}`)]]))],
|
|
323
|
+
]);
|
|
324
|
+
}
|
|
325
|
+
basesRefusal(p) {
|
|
326
|
+
return encode(new Map([[0, 1], [7, w.problem.enc(p)]]));
|
|
327
|
+
}
|
|
328
|
+
basesView(record, revisionWire, ordinal) {
|
|
329
|
+
const id = uuidCodec.dec(record), r = this.records.get(id), views = this.baseViews.get(id);
|
|
330
|
+
if (!r || !views || typeof ordinal !== "number" || !views[ordinal])
|
|
331
|
+
return problem("not_found", "no such view", "view_not_found");
|
|
332
|
+
if (hashCodec.dec(revisionWire) !== revisionOf(r.body))
|
|
333
|
+
return problem("conflict", "the view changed", "view_source_changed");
|
|
334
|
+
return { r, ordinal };
|
|
335
|
+
}
|
|
336
|
+
basesRead(bytes) {
|
|
337
|
+
const m = decode(bytes);
|
|
338
|
+
const found = this.basesView(m.get(0), m.get(1), m.get(2));
|
|
339
|
+
if (!("r" in found))
|
|
340
|
+
return this.basesRefusal(found);
|
|
341
|
+
const view = this.baseViews.get(found.r.id)[found.ordinal];
|
|
342
|
+
const cell = (v) => v === null || v === undefined ? [0] : typeof v === "boolean" ? [1, v] : typeof v === "number" ? [2, new Float64(v)]
|
|
343
|
+
: typeof v === "string" ? [3, v] : Array.isArray(v) ? [6, v.map(cell)] : [3, JSON.stringify(v)];
|
|
344
|
+
const value = (r, column) => column === "file.path" ? r.path : column === "file.name" ? r.path.slice(r.path.lastIndexOf("/") + 1)
|
|
345
|
+
: toPlain(r.frontmatter.get(column.replace(/^(note|fm)\./, "")) ?? null);
|
|
346
|
+
const all = this.evalQuery(new Map([["types", view.types]]))
|
|
347
|
+
.map((r) => [uuidCodec.enc(r.id), r.path, hashCodec.enc(revision(r)), view.columns.map((c) => cell(value(r, c)))]);
|
|
348
|
+
const win = m.get(6);
|
|
349
|
+
const offset = win?.get(0) ?? 0, rows = win ? all.slice(offset, offset + win.get(1)) : all;
|
|
350
|
+
const out = new Map([
|
|
351
|
+
[0, 1], [1, this.basesDescriptor(found.r, found.ordinal)], [2, new Map([[0, view.columns], [1, []]])],
|
|
352
|
+
[3, rows], [4, []], [5, this.basesClock()], [6, this.basesRevision()],
|
|
353
|
+
]);
|
|
354
|
+
if (win)
|
|
355
|
+
out.set(8, new Map([[0, offset], [1, win.get(1)], [2, all.length], [3, []]]));
|
|
356
|
+
return encode(out);
|
|
357
|
+
}
|
|
358
|
+
basesDiscovery(op, bytes) {
|
|
359
|
+
const m = decode(bytes);
|
|
360
|
+
if (op === "read-view-source") {
|
|
361
|
+
const found = this.basesView(m.get(1), m.get(2), m.get(3));
|
|
362
|
+
if (!("r" in found))
|
|
363
|
+
return this.basesRefusal(found);
|
|
364
|
+
return encode(new Map([
|
|
365
|
+
[0, 1], [1, this.basesDescriptor(found.r, found.ordinal)], [2, found.r.body], [3, this.basesClock()], [4, this.basesRevision()],
|
|
366
|
+
]));
|
|
367
|
+
}
|
|
368
|
+
const limit = m.get(2), handle = m.get(3);
|
|
369
|
+
const start = handle instanceof Uint8Array ? new DataView(handle.buffer, handle.byteOffset).getUint32(0) : 0;
|
|
370
|
+
const all = [...this.baseViews.keys()].filter((id) => this.records.has(id)).sort()
|
|
371
|
+
.flatMap((id) => this.baseViews.get(id).map((_, i) => this.basesDescriptor(this.records.get(id), i)));
|
|
372
|
+
const next = start + limit < all.length ? new Uint8Array(32) : null;
|
|
373
|
+
if (next)
|
|
374
|
+
new DataView(next.buffer).setUint32(0, start + limit);
|
|
375
|
+
return encode(new Map([
|
|
376
|
+
[0, 1], [1, all.slice(start, start + limit)], [2, this.basesClock()], [3, this.basesRevision()], [4, next],
|
|
377
|
+
]));
|
|
378
|
+
}
|
|
379
|
+
/** Reject a pending mutation (as a failed check at head would). */
|
|
380
|
+
reject(mutation, p = problem("conflict", "rejected at head", "revision")) {
|
|
381
|
+
const r = this.receipts.get(mutation);
|
|
382
|
+
if (!r || r.state !== "pending")
|
|
383
|
+
return;
|
|
384
|
+
this.pendingQueue = this.pendingQueue.filter((m) => m !== mutation);
|
|
385
|
+
// Roll the local view back: the rejected mutation's effects disappear (§6).
|
|
386
|
+
for (const [id, before] of this.priors.get(mutation) ?? []) {
|
|
387
|
+
const cur = this.records.get(id);
|
|
388
|
+
if (before)
|
|
389
|
+
this.records.set(id, before);
|
|
390
|
+
else
|
|
391
|
+
this.records.delete(id);
|
|
392
|
+
if (cur && (!before || cur.path !== before.path))
|
|
393
|
+
this.touch(id, cur.path, "remove");
|
|
394
|
+
if (before)
|
|
395
|
+
this.touch(id, before.path, "put");
|
|
396
|
+
}
|
|
397
|
+
this.priors.delete(mutation);
|
|
398
|
+
this.settle({ mutation, state: "rejected", problem: p });
|
|
399
|
+
}
|
|
400
|
+
get allRecords() {
|
|
401
|
+
return [...this.records.values()];
|
|
402
|
+
}
|
|
403
|
+
get sessionCount() {
|
|
404
|
+
return this.conns.size;
|
|
405
|
+
}
|
|
406
|
+
// ---------------------------------------------------------------- protocol
|
|
407
|
+
hello(frame) {
|
|
408
|
+
const f = w.clientFrame.dec(frame);
|
|
409
|
+
if (f.kind !== "request" || f.method !== "hello")
|
|
410
|
+
throw new Error("expected hello");
|
|
411
|
+
if (this.opts.refuse)
|
|
412
|
+
return w.clientFrame.enc({ kind: "response", id: f.id, problem: this.opts.refuse });
|
|
413
|
+
const p = w.helloParams.dec(f.params);
|
|
414
|
+
const minor = Math.max(-1, ...p.versions.filter((v) => v.major === 1 && v.minor <= 3).map((v) => v.minor));
|
|
415
|
+
if (minor < 0) {
|
|
416
|
+
return w.clientFrame.enc({
|
|
417
|
+
kind: "response",
|
|
418
|
+
id: f.id,
|
|
419
|
+
problem: problem("upgrade_required", "no common API version"),
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
const grant = {
|
|
423
|
+
capabilities: this.opts.capabilities ?? [
|
|
424
|
+
"collection.read",
|
|
425
|
+
"records.create",
|
|
426
|
+
"records.edit",
|
|
427
|
+
"records.delete",
|
|
428
|
+
"definitions.manage",
|
|
429
|
+
],
|
|
430
|
+
role: this.opts.role ?? "owner",
|
|
431
|
+
};
|
|
432
|
+
if (this.opts.grant)
|
|
433
|
+
grant.grant = this.opts.grant;
|
|
434
|
+
if (this.opts.fileFolders)
|
|
435
|
+
grant.fileFolders = [...this.opts.fileFolders];
|
|
436
|
+
const result = {
|
|
437
|
+
version: { major: 1, minor },
|
|
438
|
+
runtimeVersion: this.opts.runtimeVersion ?? "memory-0",
|
|
439
|
+
sem: { major: 1, minor: 0 },
|
|
440
|
+
collection: this.collection,
|
|
441
|
+
grant,
|
|
442
|
+
status: this.status(),
|
|
443
|
+
features: (p.features ?? []).filter((x) => x === "presence" || x === "fence"),
|
|
444
|
+
};
|
|
445
|
+
return w.clientFrame.enc({ kind: "response", id: f.id, result: w.helloResult.enc(result) });
|
|
446
|
+
}
|
|
447
|
+
status() {
|
|
448
|
+
return {
|
|
449
|
+
mode: "synced",
|
|
450
|
+
confirmedThrough: this.seq,
|
|
451
|
+
headKnown: this.seq,
|
|
452
|
+
pending: this.pendingQueue.length,
|
|
453
|
+
...(this.pendingQueue.length ? { oldestPending: Date.now() } : {}),
|
|
454
|
+
holds: this.holdList.size,
|
|
455
|
+
unresolved: [...this.records.values()].reduce((n, r) => n + (r.unresolved ?? 0), 0),
|
|
456
|
+
connection: this.online ? "online" : "offline",
|
|
457
|
+
incidents: [],
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
send(c, f) {
|
|
461
|
+
try {
|
|
462
|
+
c.port.send(w.clientFrame.enc(f));
|
|
463
|
+
}
|
|
464
|
+
catch {
|
|
465
|
+
// closed
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
push(c, type, payload) {
|
|
469
|
+
this.send(c, { kind: "push", type, payload });
|
|
470
|
+
}
|
|
471
|
+
drop(c) {
|
|
472
|
+
this.conns.delete(c);
|
|
473
|
+
for (const id of c.joined.keys())
|
|
474
|
+
this.pushPresence(id);
|
|
475
|
+
}
|
|
476
|
+
async onFrame(c, raw) {
|
|
477
|
+
const f = w.clientFrame.dec(raw);
|
|
478
|
+
if (f.kind !== "request")
|
|
479
|
+
return;
|
|
480
|
+
if (this.loseNext) {
|
|
481
|
+
this.loseNext = false;
|
|
482
|
+
await this.dispatch(c, f.method, f.params).catch(() => { });
|
|
483
|
+
c.port.close();
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
try {
|
|
487
|
+
const result = await this.dispatch(c, f.method, f.params);
|
|
488
|
+
this.send(c, { kind: "response", id: f.id, result: result ?? null });
|
|
489
|
+
}
|
|
490
|
+
catch (e) {
|
|
491
|
+
const p = isMdbaseError(e)
|
|
492
|
+
? e.toProblem()
|
|
493
|
+
: problem("invalid_request", e instanceof Error ? e.message : String(e));
|
|
494
|
+
this.send(c, { kind: "response", id: f.id, problem: p });
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
contractMethod(method, m, contracts) {
|
|
498
|
+
if (method === "query_contract_v1") {
|
|
499
|
+
const sel = { id: m.get(1), version: m.get(2) };
|
|
500
|
+
const impls = contracts.filter((c) => c.id === sel.id && c.version === sel.version);
|
|
501
|
+
if (!impls.length)
|
|
502
|
+
throw mdbaseError("not_found", "no such contract", "data_contract_not_found");
|
|
503
|
+
const where = m.get(5);
|
|
504
|
+
if (where && !this.opts.where)
|
|
505
|
+
throw mdbaseError("invalid_request", "MemoryReplica: pass a `where` evaluator to use where");
|
|
506
|
+
const rows = [...this.records.values()]
|
|
507
|
+
.sort((a, b) => (a.path < b.path ? -1 : 1))
|
|
508
|
+
.map((r) => ({
|
|
509
|
+
r,
|
|
510
|
+
implementations: impls
|
|
511
|
+
.filter((c) => r.types.includes(c.type))
|
|
512
|
+
.map((c) => ({ typeName: c.type, fields: contractFields(c, r), issues: [] }))
|
|
513
|
+
.filter((x) => !where || this.opts.where(where, { ...r, frontmatter: x.fields })),
|
|
514
|
+
}))
|
|
515
|
+
.filter((x) => x.implementations.length);
|
|
516
|
+
const start = Number(m.get(4) ?? 0);
|
|
517
|
+
const limit = m.get(3) ?? 128;
|
|
518
|
+
const slice = rows.slice(start, start + limit);
|
|
519
|
+
const page = { records: slice.map((x) => this.view(x.r)), complete: true, asOf: this.viewVersion };
|
|
520
|
+
if (start + limit < rows.length)
|
|
521
|
+
page.cursor = String(start + limit);
|
|
522
|
+
return contractQueryResult.enc({
|
|
523
|
+
version: 1, page, contractDigest: contractDigest(impls[0]),
|
|
524
|
+
records: slice.map((x) => ({ id: x.r.id, implementations: x.implementations })),
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
if (method === "get_contract_v1") {
|
|
528
|
+
const r = this.find(m.get(1));
|
|
529
|
+
const c = implementationFor(contracts, { id: m.get(2), version: m.get(3), type: m.get(4) }, r);
|
|
530
|
+
return contractRecordWire.enc({
|
|
531
|
+
version: 1, id: r.id, path: r.path, revision: revision(r), type: c.type, fields: contractFields(c, r),
|
|
532
|
+
contractDigest: contractDigest(c), implementationDigest: implementationDigest(c),
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
const target = m.get(4);
|
|
536
|
+
const r = target === undefined ? undefined : this.find(target);
|
|
537
|
+
const sel = { id: m.get(1), version: m.get(2), type: m.get(3) };
|
|
538
|
+
// Promotion: an untyped record takes the implementing type through `type`.
|
|
539
|
+
const promoting = m.get(7) === true && r !== undefined && r.types.length === 0;
|
|
540
|
+
if (m.get(7) === true && r?.types.length && !contracts.some((c) => c.id === sel.id && c.version === sel.version && r.types.includes(c.type))) {
|
|
541
|
+
throw mdbaseError("invalid_request", "only a record without types can be promoted", "data_contract_promote_typed");
|
|
542
|
+
}
|
|
543
|
+
const c = implementationFor(contracts, sel, promoting ? undefined : r);
|
|
544
|
+
const mapped = mapWrite(c, r, (m.get(5) ?? new Map()), (m.get(6) ?? []));
|
|
545
|
+
if (promoting) {
|
|
546
|
+
mapped.patch.set("type", c.type);
|
|
547
|
+
mapped.base.push({ key: "type" });
|
|
548
|
+
}
|
|
549
|
+
return contractWritePlan.enc({
|
|
550
|
+
version: 1, type: c.type, ...mapped, contractDigest: contractDigest(c), implementationDigest: implementationDigest(c),
|
|
551
|
+
...(r ? { id: r.id, path: r.path, revision: revision(r) } : {}),
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
find(ref) {
|
|
555
|
+
const r = typeof ref === "string"
|
|
556
|
+
? [...this.records.values()].find((x) => x.path === ref)
|
|
557
|
+
: this.records.get(uuidCodec.dec(ref));
|
|
558
|
+
if (!r)
|
|
559
|
+
throw mdbaseError("not_found", "no such record");
|
|
560
|
+
return r;
|
|
561
|
+
}
|
|
562
|
+
view(r, inc) {
|
|
563
|
+
const v = {
|
|
564
|
+
id: r.id,
|
|
565
|
+
path: r.path,
|
|
566
|
+
revision: revision(r),
|
|
567
|
+
frontmatter: new Map(r.frontmatter),
|
|
568
|
+
types: r.types,
|
|
569
|
+
state: {
|
|
570
|
+
state: r.pending ? "pending" : "confirmed",
|
|
571
|
+
confirmedSeq: r.confirmedSeq,
|
|
572
|
+
...(r.hold ? { hold: { ...r.hold } } : {}),
|
|
573
|
+
...(r.unresolved ? { unresolved: r.unresolved } : {}),
|
|
574
|
+
},
|
|
575
|
+
};
|
|
576
|
+
if (inc?.body)
|
|
577
|
+
v.body = r.body;
|
|
578
|
+
if (inc?.document)
|
|
579
|
+
v.document = renderDocument(r);
|
|
580
|
+
if (inc?.effective)
|
|
581
|
+
v.effective = new Map(r.frontmatter);
|
|
582
|
+
return v;
|
|
583
|
+
}
|
|
584
|
+
evalQuery(q) {
|
|
585
|
+
const types = q.get("types");
|
|
586
|
+
const where = q.get("where");
|
|
587
|
+
let rows = [...this.records.values()].filter((r) => !types?.length || types.some((t) => r.types.includes(t)));
|
|
588
|
+
if (where) {
|
|
589
|
+
if (!this.opts.where)
|
|
590
|
+
throw mdbaseError("invalid_request", "MemoryReplica: pass a `where` evaluator to use where");
|
|
591
|
+
rows = rows.filter((r) => this.opts.where(where, r));
|
|
592
|
+
}
|
|
593
|
+
const order = q.get("order_by");
|
|
594
|
+
const keys = [];
|
|
595
|
+
for (const o of Array.isArray(order) ? order : order ? [order] : []) {
|
|
596
|
+
if (typeof o === "string")
|
|
597
|
+
keys.push({ field: o.replace(/^-/, ""), desc: o.startsWith("-") });
|
|
598
|
+
else if (o instanceof Map) {
|
|
599
|
+
const m = o;
|
|
600
|
+
keys.push({ field: String(m.get("field")), desc: m.get("direction") === "desc" });
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
const get = (r, field) => field === "file.path" || field === "path" ? r.path : toPlain(r.frontmatter.get(field.replace(/^fm\./, "")) ?? null);
|
|
604
|
+
rows.sort((a, b) => {
|
|
605
|
+
for (const k of keys) {
|
|
606
|
+
const x = get(a, k.field);
|
|
607
|
+
const y = get(b, k.field);
|
|
608
|
+
if (x === y)
|
|
609
|
+
continue;
|
|
610
|
+
const c = x === null ? -1 : y === null ? 1 : x < y ? -1 : 1;
|
|
611
|
+
return k.desc ? -c : c;
|
|
612
|
+
}
|
|
613
|
+
return a.path < b.path ? -1 : a.path > b.path ? 1 : 0;
|
|
614
|
+
});
|
|
615
|
+
return rows;
|
|
616
|
+
}
|
|
617
|
+
page(q) {
|
|
618
|
+
const all = this.evalQuery(q);
|
|
619
|
+
const start = Number(q.get("cursor") ?? 0);
|
|
620
|
+
const limit = q.get("limit");
|
|
621
|
+
const rows = limit === undefined ? all.slice(start) : all.slice(start, start + limit);
|
|
622
|
+
const next = start + rows.length;
|
|
623
|
+
return next < all.length && limit !== undefined ? { rows, cursor: String(next) } : { rows };
|
|
624
|
+
}
|
|
625
|
+
async dispatch(c, method, p) {
|
|
626
|
+
const m = (p ?? new Map());
|
|
627
|
+
switch (method) {
|
|
628
|
+
case "cancel":
|
|
629
|
+
return null;
|
|
630
|
+
case "describe": {
|
|
631
|
+
const types = new Set();
|
|
632
|
+
for (const r of this.records.values())
|
|
633
|
+
r.types.forEach((t) => types.add(t));
|
|
634
|
+
for (const p of this.resources.keys()) {
|
|
635
|
+
const m = /^_types\/(.+)\.md$/.exec(p);
|
|
636
|
+
if (m)
|
|
637
|
+
types.add(m[1]);
|
|
638
|
+
}
|
|
639
|
+
return w.describeResult.enc({
|
|
640
|
+
specVersion: "0.3.0-rc.5",
|
|
641
|
+
types: [...types].sort().map((name) => this.typeSummary(name, m.get(0) === true)),
|
|
642
|
+
settings: new Map(),
|
|
643
|
+
inclusion: { include: ["image", "audio", "video", "pdf", "other"] },
|
|
644
|
+
issues: [],
|
|
645
|
+
contracts: [],
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
case "new_type_file": {
|
|
649
|
+
// Synthetic subset of Core's derivation: frontmatter name, default folder.
|
|
650
|
+
const { frontmatter } = parseDocument(m.get(0));
|
|
651
|
+
const name = frontmatter.get("name");
|
|
652
|
+
if (frontmatter.get("kind") !== "mdbase.type" || typeof name !== "string" || name === "" || name.includes("/")) {
|
|
653
|
+
throw mdbaseError("invalid_record", "the type needs a usable name", "invalid_type_definition");
|
|
654
|
+
}
|
|
655
|
+
const existing = [...this.resources.keys()].find((p) => p.toLowerCase() === `_types/${name.toLowerCase()}.md`);
|
|
656
|
+
if (existing !== undefined) {
|
|
657
|
+
throw mdbaseError("conflict", "the type exists", { reason: "type_conflict", details: existing });
|
|
658
|
+
}
|
|
659
|
+
return w.newTypeFile.enc({ name, path: `_types/${name}.md` });
|
|
660
|
+
}
|
|
661
|
+
case "get_resource": {
|
|
662
|
+
const path = m.get(0);
|
|
663
|
+
const r = this.resources.get(path);
|
|
664
|
+
if (r === undefined)
|
|
665
|
+
throw mdbaseError("not_found", "no such resource");
|
|
666
|
+
return w.resourceView.enc(this.resourceView(path, r, true));
|
|
667
|
+
}
|
|
668
|
+
case "list_resources": {
|
|
669
|
+
const folder = m.get(0);
|
|
670
|
+
const text = m.get(1) === true;
|
|
671
|
+
const resources = [...this.resources.entries()]
|
|
672
|
+
.filter(([p]) => !folder || p.startsWith(folder.endsWith("/") ? folder : `${folder}/`))
|
|
673
|
+
.sort((a, b) => (a[0] < b[0] ? -1 : 1))
|
|
674
|
+
.map(([p, r]) => this.resourceView(p, r, text));
|
|
675
|
+
return w.listResourcesResult.enc({ resources, complete: true });
|
|
676
|
+
}
|
|
677
|
+
case "backlinks": {
|
|
678
|
+
const target = this.find(m.get(0));
|
|
679
|
+
const inc = m.get(1) ? w.include.dec(m.get(1)) : undefined;
|
|
680
|
+
const backlinks = [...this.records.values()]
|
|
681
|
+
.filter((r) => r.id !== target.id)
|
|
682
|
+
.map((r) => ({ r, links: this.linksOf(r).filter((l) => l.resolution.target === target.id) }))
|
|
683
|
+
.filter((x) => x.links.length)
|
|
684
|
+
.sort((a, b) => (a.r.path < b.r.path ? -1 : 1))
|
|
685
|
+
.map((x) => ({ record: this.view(x.r, inc), links: x.links }));
|
|
686
|
+
return w.backlinksResult.enc({ backlinks, complete: true, asOf: this.viewVersion });
|
|
687
|
+
}
|
|
688
|
+
case "list_pending": {
|
|
689
|
+
const pending = this.pendingQueue
|
|
690
|
+
// Owner-scoped like the replica: one grant per MemoryReplica, so every
|
|
691
|
+
// session (a reload included) sees them.
|
|
692
|
+
.map((mu) => ({ receipt: this.receipts.get(mu), captured: 0, ops: this.pendingOps.get(mu) ?? [] }))
|
|
693
|
+
.filter((x) => x.ops.length);
|
|
694
|
+
return w.listPendingResult.enc({ pending });
|
|
695
|
+
}
|
|
696
|
+
case "get_status":
|
|
697
|
+
return w.syncStatus.enc(this.status());
|
|
698
|
+
case "subscribe_status":
|
|
699
|
+
c.status = true;
|
|
700
|
+
return null;
|
|
701
|
+
case "get": {
|
|
702
|
+
const inc = m.get(1) ? w.include.dec(m.get(1)) : undefined;
|
|
703
|
+
return w.recordView.enc(this.view(this.find(m.get(0)), inc));
|
|
704
|
+
}
|
|
705
|
+
case "query": {
|
|
706
|
+
const q = (m.get(0) ?? new Map());
|
|
707
|
+
const inc = m.get(1) ? w.include.dec(m.get(1)) : undefined;
|
|
708
|
+
const { rows, cursor } = this.page(q);
|
|
709
|
+
const r = { records: rows.map((x) => this.view(x, inc)), complete: true, asOf: this.viewVersion };
|
|
710
|
+
if (cursor)
|
|
711
|
+
r.cursor = cursor;
|
|
712
|
+
return w.queryResult.enc(r);
|
|
713
|
+
}
|
|
714
|
+
case "subscribe": {
|
|
715
|
+
const sub = {
|
|
716
|
+
id: this.nextSub++,
|
|
717
|
+
query: (m.get(0) ?? new Map()),
|
|
718
|
+
include: m.get(1) ? w.include.dec(m.get(1)) : undefined,
|
|
719
|
+
last: new Map(),
|
|
720
|
+
order: [],
|
|
721
|
+
};
|
|
722
|
+
c.subs.set(sub.id, sub);
|
|
723
|
+
queueMicrotask(() => this.refreshSub(c, sub, true));
|
|
724
|
+
return new Map([[0, sub.id]]);
|
|
725
|
+
}
|
|
726
|
+
case "unsubscribe":
|
|
727
|
+
c.subs.delete(m.get(0));
|
|
728
|
+
return null;
|
|
729
|
+
case "changes": {
|
|
730
|
+
const after = Number(m.get(0) ?? 0);
|
|
731
|
+
const limit = m.get(1) ?? 1000;
|
|
732
|
+
const changes = this.changeLog.filter((x) => x.version > after).slice(0, limit);
|
|
733
|
+
if (m.get(2) === true)
|
|
734
|
+
c.changesWatch = true;
|
|
735
|
+
const cursor = String(changes.length ? changes[changes.length - 1].version : Math.max(after, this.viewVersion));
|
|
736
|
+
return w.changesResult.enc({ changes, cursor, reset: after > this.viewVersion });
|
|
737
|
+
}
|
|
738
|
+
case "submit":
|
|
739
|
+
return w.submitResult.enc(await this.submit(c, w.submitParams.dec(p)));
|
|
740
|
+
case "receipt": {
|
|
741
|
+
const r = this.receipts.get(uuidCodec.dec(m.get(0)));
|
|
742
|
+
if (!r)
|
|
743
|
+
throw mdbaseError("not_found", "no such mutation");
|
|
744
|
+
return w.receipt.enc(r);
|
|
745
|
+
}
|
|
746
|
+
case "await": {
|
|
747
|
+
const id = uuidCodec.dec(m.get(0));
|
|
748
|
+
const r = this.receipts.get(id);
|
|
749
|
+
if (!r)
|
|
750
|
+
throw mdbaseError("not_found", "no such mutation");
|
|
751
|
+
if (r.state === "pending") {
|
|
752
|
+
const timeout = m.get(1);
|
|
753
|
+
await new Promise((res) => {
|
|
754
|
+
const list = this.awaiters.get(id) ?? [];
|
|
755
|
+
list.push(res);
|
|
756
|
+
this.awaiters.set(id, list);
|
|
757
|
+
if (timeout !== undefined)
|
|
758
|
+
setTimeout(res, timeout);
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
return w.receipt.enc(this.receipts.get(id));
|
|
762
|
+
}
|
|
763
|
+
case "describe_typing": {
|
|
764
|
+
const types = (m.get(0) ?? []);
|
|
765
|
+
const paths = (m.get(1) ?? []);
|
|
766
|
+
if (types.length > w.DESCRIBE_TYPING_MAX_TYPES || paths.length > w.DESCRIBE_TYPING_MAX_PATHS) {
|
|
767
|
+
throw mdbaseError("too_large", "describe_typing: too many types or paths");
|
|
768
|
+
}
|
|
769
|
+
if (this.typingAnswer)
|
|
770
|
+
return w.describeTypingResult.enc(this.typingAnswer(types, paths));
|
|
771
|
+
// Top-level fields only; nested paths are `none` at the op layer, before Core is asked.
|
|
772
|
+
const fields = paths.map((path) => ({
|
|
773
|
+
path,
|
|
774
|
+
hint: path.includes(".") || types.length === 0 || !this.opts.typing ? "none" : this.opts.typing(types, path),
|
|
775
|
+
}));
|
|
776
|
+
return w.describeTypingResult.enc({ catalogGeneration: this.viewVersion, fields });
|
|
777
|
+
}
|
|
778
|
+
case "account_key_setup": {
|
|
779
|
+
const secret = m.get(0);
|
|
780
|
+
if (!(secret instanceof Uint8Array) || secret.length !== 32)
|
|
781
|
+
throw mdbaseError("invalid_request", "the account secret is 32 bytes");
|
|
782
|
+
this.accountKeySecret = secret.slice();
|
|
783
|
+
const mutation = uuidv7();
|
|
784
|
+
c.mutations.add(mutation);
|
|
785
|
+
const r = { mutation, state: "pending" };
|
|
786
|
+
this.receipts.set(mutation, r);
|
|
787
|
+
this.pendingQueue.push(mutation);
|
|
788
|
+
this.pendingRecords.set(mutation, []);
|
|
789
|
+
this.pushStatus();
|
|
790
|
+
return w.receipt.enc(r);
|
|
791
|
+
}
|
|
792
|
+
case "account_key_unlock": {
|
|
793
|
+
const secret = m.get(0);
|
|
794
|
+
if (!(secret instanceof Uint8Array) || secret.length !== 32)
|
|
795
|
+
throw mdbaseError("invalid_request", "the account secret is 32 bytes");
|
|
796
|
+
const refused = (reason) => ({
|
|
797
|
+
state: "refused",
|
|
798
|
+
problem: { code: "forbidden", recovery: "reauthorize", message: `account key refused: ${reason}`, details: new Map([["reason", reason]]) },
|
|
799
|
+
});
|
|
800
|
+
const enrolled = this.accountKeySecret;
|
|
801
|
+
this.accountKey = !enrolled ? refused("device_missing")
|
|
802
|
+
: enrolled.length === secret.length && enrolled.every((b, i) => b === secret[i]) ? { state: "keyed" }
|
|
803
|
+
: refused("enrolment_mismatch");
|
|
804
|
+
return null;
|
|
805
|
+
}
|
|
806
|
+
case "account_key_status":
|
|
807
|
+
return accountKeyStatus.enc(this.accountKey);
|
|
808
|
+
case "list_holds":
|
|
809
|
+
return list(w.hold).enc([...this.holdList.values()].map((h) => h.hold));
|
|
810
|
+
case "resolve_hold": {
|
|
811
|
+
const id = uuidCodec.dec(m.get(0)), how = w.holdResolution.dec(m.get(1)), use = m.get(2);
|
|
812
|
+
const held = this.holdList.get(id);
|
|
813
|
+
if (!held)
|
|
814
|
+
throw mdbaseError("not_found", "no such hold");
|
|
815
|
+
const r = this.records.get(held.record);
|
|
816
|
+
this.holdList.delete(id);
|
|
817
|
+
if (r)
|
|
818
|
+
delete r.hold;
|
|
819
|
+
const theirs = typeof held.hold.theirs === "string" ? held.hold.theirs : undefined;
|
|
820
|
+
const ops = !r ? []
|
|
821
|
+
: how === "delete" ? [{ kind: "delete", id: r.id }]
|
|
822
|
+
: how === "take_theirs" && theirs !== undefined ? [{ kind: "update", id: r.id, body: theirs }]
|
|
823
|
+
: how === "use" && use !== undefined ? [{ kind: "update", id: r.id, body: use }]
|
|
824
|
+
: how === "keep_both" ? [{ kind: "create", id: uuidv7(), path: r.path.replace(/(\.[^./]+)?$/, " (copy)$1"), body: theirs ?? r.body }]
|
|
825
|
+
: [{ kind: "update", id: r.id }];
|
|
826
|
+
const [receipt] = await this.submit(c, { ops, mutationId: uuidv7() });
|
|
827
|
+
this.pushHolds();
|
|
828
|
+
this.pushStatus();
|
|
829
|
+
return w.receipt.enc(receipt);
|
|
830
|
+
}
|
|
831
|
+
case "subscribe_holds":
|
|
832
|
+
c.holds = true;
|
|
833
|
+
return null;
|
|
834
|
+
case "list_conflicts": {
|
|
835
|
+
const record = m.get(0) === undefined ? undefined : uuidCodec.dec(m.get(0));
|
|
836
|
+
return list(w.conflictEntry).enc(this.conflictList.filter((e) => !record || e.conflict.id === record));
|
|
837
|
+
}
|
|
838
|
+
case "subscribe_conflicts":
|
|
839
|
+
c.conflicts = true;
|
|
840
|
+
return null;
|
|
841
|
+
case "presence_join":
|
|
842
|
+
case "presence_update": {
|
|
843
|
+
const id = uuidCodec.dec(m.get(0));
|
|
844
|
+
c.joined.set(id, m.get(1) ?? null);
|
|
845
|
+
this.pushPresence(id);
|
|
846
|
+
return null;
|
|
847
|
+
}
|
|
848
|
+
case "presence_leave": {
|
|
849
|
+
const id = uuidCodec.dec(m.get(0));
|
|
850
|
+
c.joined.delete(id);
|
|
851
|
+
this.pushPresence(id);
|
|
852
|
+
return null;
|
|
853
|
+
}
|
|
854
|
+
case "subscribe_presence": {
|
|
855
|
+
const id = uuidCodec.dec(m.get(0));
|
|
856
|
+
c.presence.add(id);
|
|
857
|
+
queueMicrotask(() => this.pushPresence(id, c));
|
|
858
|
+
return null;
|
|
859
|
+
}
|
|
860
|
+
case "list_files": {
|
|
861
|
+
const folder = m.get(0);
|
|
862
|
+
const files = [...this.files.values()]
|
|
863
|
+
.filter((f) => !folder || f.path.startsWith(folder.endsWith("/") ? folder : `${folder}/`))
|
|
864
|
+
.sort((a, b) => (a.path < b.path ? -1 : 1))
|
|
865
|
+
.map((f) => this.fileView(f));
|
|
866
|
+
return w.listFilesResult.enc({ files, complete: true });
|
|
867
|
+
}
|
|
868
|
+
case "get_file":
|
|
869
|
+
return w.fileView.enc(this.fileView(this.findFile(m.get(0))));
|
|
870
|
+
case "open_upload": {
|
|
871
|
+
const op = w.openUploadParams.dec(p);
|
|
872
|
+
const u = this.uploads.get(op.transfer) ?? { params: op, fileId: op.fileId ?? uuidv7(), chunks: new Map() };
|
|
873
|
+
this.uploads.set(op.transfer, u);
|
|
874
|
+
return w.openUploadResult.enc({
|
|
875
|
+
transfer: op.transfer,
|
|
876
|
+
chunkSize: 1024 * 1024,
|
|
877
|
+
received: [...u.chunks.keys()],
|
|
878
|
+
expiresAt: Date.now() + 86_400_000,
|
|
879
|
+
fileId: u.fileId,
|
|
880
|
+
});
|
|
881
|
+
}
|
|
882
|
+
case "upload_chunk": {
|
|
883
|
+
const ch = w.uploadChunkParams.dec(p);
|
|
884
|
+
const u = this.uploads.get(ch.transfer);
|
|
885
|
+
if (!u)
|
|
886
|
+
throw mdbaseError("not_found", "no such transfer", "transfer_expired");
|
|
887
|
+
u.chunks.set(ch.index, ch.bytes.slice());
|
|
888
|
+
return new Map([[0, u.chunks.size]]);
|
|
889
|
+
}
|
|
890
|
+
case "commit_upload":
|
|
891
|
+
return w.receipt.enc(this.commitUpload(c, uuidCodec.dec(m.get(0))));
|
|
892
|
+
case "abort_upload":
|
|
893
|
+
this.uploads.delete(uuidCodec.dec(m.get(0)));
|
|
894
|
+
return null;
|
|
895
|
+
case "read_file": {
|
|
896
|
+
const f = this.findFile(m.get(0));
|
|
897
|
+
const range = m.get(1);
|
|
898
|
+
const data = range ? f.bytes.subarray(range[0], range[0] + range[1]) : f.bytes;
|
|
899
|
+
const id = this.nextStream++;
|
|
900
|
+
c.streams.set(id, { data, offset: 0, acked: 0 });
|
|
901
|
+
queueMicrotask(() => this.pumpStream(c, id));
|
|
902
|
+
return new Map([
|
|
903
|
+
[0, id],
|
|
904
|
+
[1, w.fileView.enc(this.fileView(f))],
|
|
905
|
+
]);
|
|
906
|
+
}
|
|
907
|
+
case "ack_chunks": {
|
|
908
|
+
const st = c.streams.get(m.get(0));
|
|
909
|
+
if (st) {
|
|
910
|
+
st.acked = m.get(1);
|
|
911
|
+
this.pumpStream(c, m.get(0));
|
|
912
|
+
}
|
|
913
|
+
return null;
|
|
914
|
+
}
|
|
915
|
+
case "cancel_stream":
|
|
916
|
+
c.streams.delete(m.get(0));
|
|
917
|
+
return null;
|
|
918
|
+
case "fence_report":
|
|
919
|
+
return null;
|
|
920
|
+
case "get_contract_v1":
|
|
921
|
+
case "map_contract_write_v1":
|
|
922
|
+
case "query_contract_v1":
|
|
923
|
+
if (this.opts.contracts)
|
|
924
|
+
return this.contractMethod(method, m, this.opts.contracts);
|
|
925
|
+
throw mdbaseError("invalid_request", `MemoryReplica does not implement ${method}`, "unknown_method");
|
|
926
|
+
default:
|
|
927
|
+
throw mdbaseError("invalid_request", `MemoryReplica does not implement ${method}`, "unknown_method");
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
pumpStream(c, id) {
|
|
931
|
+
const st = c.streams.get(id);
|
|
932
|
+
if (!st)
|
|
933
|
+
return;
|
|
934
|
+
const CHUNK = 256 * 1024;
|
|
935
|
+
while (st.offset - st.acked < 8 * 1024 * 1024) {
|
|
936
|
+
const end = Math.min(st.data.length, st.offset + CHUNK);
|
|
937
|
+
const last = end >= st.data.length;
|
|
938
|
+
this.push(c, "file_chunk", w.fileChunk.enc({ stream: id, offset: st.offset, bytes: st.data.slice(st.offset, end), last }));
|
|
939
|
+
st.offset = end;
|
|
940
|
+
if (last) {
|
|
941
|
+
c.streams.delete(id);
|
|
942
|
+
return;
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
findFile(ref) {
|
|
947
|
+
const f = typeof ref === "string" ? [...this.files.values()].find((x) => x.path === ref) : this.files.get(uuidCodec.dec(ref));
|
|
948
|
+
if (!f)
|
|
949
|
+
throw mdbaseError("not_found", "no such file");
|
|
950
|
+
return f;
|
|
951
|
+
}
|
|
952
|
+
fileView(f) {
|
|
953
|
+
return {
|
|
954
|
+
id: f.id,
|
|
955
|
+
path: f.path,
|
|
956
|
+
size: f.bytes.length,
|
|
957
|
+
digest: hashFromBytes(sha256(f.bytes)),
|
|
958
|
+
media: mediaOf(f.path),
|
|
959
|
+
...(mediaTypeOf(f.path) ? { mediaType: mediaTypeOf(f.path) } : {}),
|
|
960
|
+
state: f.pending ? "pending_upload" : "materialized",
|
|
961
|
+
confirmedSeq: f.confirmedSeq,
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
commitUpload(c, transfer) {
|
|
965
|
+
const u = this.uploads.get(transfer);
|
|
966
|
+
if (!u)
|
|
967
|
+
throw mdbaseError("not_found", "no such transfer", "transfer_expired");
|
|
968
|
+
const total = [...u.chunks.entries()].sort((a, b) => a[0] - b[0]);
|
|
969
|
+
const bytes = new Uint8Array(u.params.size);
|
|
970
|
+
let off = 0;
|
|
971
|
+
for (const [, ch] of total) {
|
|
972
|
+
bytes.set(ch, off);
|
|
973
|
+
off += ch.length;
|
|
974
|
+
}
|
|
975
|
+
if (off !== u.params.size)
|
|
976
|
+
throw mdbaseError("invalid_request", "size mismatch", "size_mismatch");
|
|
977
|
+
if (u.params.digest && hashFromBytes(sha256(bytes)) !== u.params.digest) {
|
|
978
|
+
throw mdbaseError("invalid_request", "digest mismatch", "digest_mismatch");
|
|
979
|
+
}
|
|
980
|
+
this.uploads.delete(transfer);
|
|
981
|
+
const mutation = u.params.mutationId ?? uuidv7();
|
|
982
|
+
const existing = this.receipts.get(mutation);
|
|
983
|
+
if (existing)
|
|
984
|
+
return existing;
|
|
985
|
+
const id = u.fileId;
|
|
986
|
+
const prev = this.files.get(id);
|
|
987
|
+
if (u.params.ifRevision && prev && hashFromBytes(sha256(prev.bytes)) !== u.params.ifRevision) {
|
|
988
|
+
throw mdbaseError("conflict", "file changed", "revision");
|
|
989
|
+
}
|
|
990
|
+
this.files.set(id, { id, path: u.params.path, bytes, confirmedSeq: prev?.confirmedSeq ?? 0, pending: true });
|
|
991
|
+
this.touch(id, u.params.path, "put", "file");
|
|
992
|
+
c.mutations.add(mutation);
|
|
993
|
+
const r = { mutation, state: "pending" };
|
|
994
|
+
this.receipts.set(mutation, r);
|
|
995
|
+
this.pendingQueue.push(mutation);
|
|
996
|
+
this.pendingRecords.set(mutation, []);
|
|
997
|
+
this.fileMutations.set(mutation, [id]);
|
|
998
|
+
this.pushStatus();
|
|
999
|
+
this.scheduleConfirm();
|
|
1000
|
+
return r;
|
|
1001
|
+
}
|
|
1002
|
+
fileMutations = new Map();
|
|
1003
|
+
resources = new Map();
|
|
1004
|
+
pendingOps = new Map();
|
|
1005
|
+
/** Seed a resource (a type file, mdbase.yaml). */
|
|
1006
|
+
seedResource(path, text) {
|
|
1007
|
+
this.resources.set(path, { text, pending: false });
|
|
1008
|
+
}
|
|
1009
|
+
/** Synthetic type summary: the parsed subset of the type file, never Core's catalog. */
|
|
1010
|
+
typeSummary(name, definitions) {
|
|
1011
|
+
const path = `_types/${name}.md`;
|
|
1012
|
+
const summary = { name, path, implements: [] };
|
|
1013
|
+
const source = this.resources.get(path);
|
|
1014
|
+
if (source === undefined)
|
|
1015
|
+
return definitions ? { ...summary, definition: new Map(), schema: null } : summary;
|
|
1016
|
+
const { frontmatter } = parseDocument(source.text);
|
|
1017
|
+
const version = frontmatter.get("version");
|
|
1018
|
+
if (typeof version === "number" && Number.isInteger(version))
|
|
1019
|
+
summary.version = version;
|
|
1020
|
+
summary.revision = this.resourceView(path, source, false).revision;
|
|
1021
|
+
if (definitions) {
|
|
1022
|
+
// parseDocument leaves JSON objects plain; normalise them to data maps.
|
|
1023
|
+
const definition = toValue(frontmatter);
|
|
1024
|
+
const schema = definition.get("schema");
|
|
1025
|
+
summary.definition = definition;
|
|
1026
|
+
summary.schema = schema instanceof Map ? (schema.get("value") ?? null) : null;
|
|
1027
|
+
}
|
|
1028
|
+
return summary;
|
|
1029
|
+
}
|
|
1030
|
+
resourceView(path, r, text) {
|
|
1031
|
+
const bytes = new TextEncoder().encode(r.text);
|
|
1032
|
+
const v = {
|
|
1033
|
+
path,
|
|
1034
|
+
revision: hashFromBytes(sha256(bytes)),
|
|
1035
|
+
size: bytes.length,
|
|
1036
|
+
state: r.pending ? "pending" : "confirmed",
|
|
1037
|
+
};
|
|
1038
|
+
if (text)
|
|
1039
|
+
v.text = r.text;
|
|
1040
|
+
return v;
|
|
1041
|
+
}
|
|
1042
|
+
/** `[[target]]` / `![[target]]` links in the body, resolved by path or basename. */
|
|
1043
|
+
linksOf(r) {
|
|
1044
|
+
const out = [];
|
|
1045
|
+
for (const m of r.body.matchAll(/(!?)\[\[([^\]|#]+)(?:[^\]]*)\]\]/g)) {
|
|
1046
|
+
const name = m[2].trim();
|
|
1047
|
+
const target = [...this.records.values()].find((x) => x.path === name || x.path === `${name}.md` || x.path.replace(/\.md$/, "").split("/").pop() === name);
|
|
1048
|
+
out.push({
|
|
1049
|
+
raw: m[0],
|
|
1050
|
+
embed: m[1] === "!",
|
|
1051
|
+
resolution: target ? { kind: "record", target: target.id, path: target.path } : { kind: "not_found" },
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1054
|
+
return out;
|
|
1055
|
+
}
|
|
1056
|
+
/** Dry-run preflight: links a delete breaks, links a rename rewrites. */
|
|
1057
|
+
preflight(ops) {
|
|
1058
|
+
const pf = { rewrites: [], broken: [] };
|
|
1059
|
+
for (const op of ops) {
|
|
1060
|
+
if (op.kind !== "delete" && op.kind !== "rename")
|
|
1061
|
+
continue;
|
|
1062
|
+
for (const r of [...this.records.values()].sort((a, b) => (a.path < b.path ? -1 : 1))) {
|
|
1063
|
+
for (const l of this.linksOf(r)) {
|
|
1064
|
+
if (l.resolution.target !== op.id)
|
|
1065
|
+
continue;
|
|
1066
|
+
if (op.kind === "rename" && op.updateRefs) {
|
|
1067
|
+
pf.rewrites.push({ record: r.id, path: r.path, from: l.raw, to: l.raw.replace(/\[\[[^\]|#]+/, (x) => x.slice(0, x.indexOf("[[") + 2) + op.to.replace(/\.md$/, "")) });
|
|
1068
|
+
}
|
|
1069
|
+
else {
|
|
1070
|
+
pf.broken.push({ record: r.id, path: r.path, raw: l.raw, target: op.id });
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
return pf;
|
|
1076
|
+
}
|
|
1077
|
+
/** Record state before each pending mutation, to roll back on reject. */
|
|
1078
|
+
priors = new Map();
|
|
1079
|
+
async submit(c, p) {
|
|
1080
|
+
if (this.failWrite && !p.dryRun) {
|
|
1081
|
+
const failure = this.failWrite;
|
|
1082
|
+
this.failWrite = null;
|
|
1083
|
+
throw new MdbaseError(failure);
|
|
1084
|
+
}
|
|
1085
|
+
const groups = p.allowPartial ? p.ops.map((op) => [op]) : [p.ops];
|
|
1086
|
+
const ids = p.allowPartial ? (p.mutationIds ?? []) : [p.mutationId ?? uuidv7()];
|
|
1087
|
+
const out = [];
|
|
1088
|
+
for (let i = 0; i < groups.length; i++) {
|
|
1089
|
+
const mutation = ids[i] ?? uuidv7();
|
|
1090
|
+
const known = this.receipts.get(mutation);
|
|
1091
|
+
if (known) {
|
|
1092
|
+
out.push(known);
|
|
1093
|
+
continue;
|
|
1094
|
+
}
|
|
1095
|
+
let r;
|
|
1096
|
+
try {
|
|
1097
|
+
if (p.dryRun) {
|
|
1098
|
+
// Validate without changing anything: apply to a scratch copy.
|
|
1099
|
+
const saved = {
|
|
1100
|
+
records: new Map([...this.records].map(([k, v]) => [k, { ...v, frontmatter: new Map(v.frontmatter) }])),
|
|
1101
|
+
resources: new Map([...this.resources].map(([k, v]) => [k, { ...v }])),
|
|
1102
|
+
files: new Map(this.files),
|
|
1103
|
+
changeLog: this.changeLog.length,
|
|
1104
|
+
viewVersion: this.viewVersion,
|
|
1105
|
+
};
|
|
1106
|
+
const pf = this.preflight(groups[i]);
|
|
1107
|
+
const mute = this.conns;
|
|
1108
|
+
this.conns = new Set();
|
|
1109
|
+
try {
|
|
1110
|
+
const touched = this.applyOps(groups[i], mutation);
|
|
1111
|
+
r = { mutation, state: "pending", records: touched.map((id) => this.view(this.records.get(id), p.include)), preflight: pf };
|
|
1112
|
+
}
|
|
1113
|
+
finally {
|
|
1114
|
+
this.records = saved.records;
|
|
1115
|
+
this.resources = saved.resources;
|
|
1116
|
+
this.files = saved.files;
|
|
1117
|
+
this.changeLog.length = saved.changeLog;
|
|
1118
|
+
this.viewVersion = saved.viewVersion;
|
|
1119
|
+
this.priors.delete(mutation);
|
|
1120
|
+
this.conns = mute;
|
|
1121
|
+
}
|
|
1122
|
+
out.push(r);
|
|
1123
|
+
continue;
|
|
1124
|
+
}
|
|
1125
|
+
const touched = this.applyOps(groups[i], mutation);
|
|
1126
|
+
r = { mutation, state: "pending", records: touched.map((id) => this.view(this.records.get(id), p.include)) };
|
|
1127
|
+
this.pendingOps.set(mutation, groups[i]);
|
|
1128
|
+
c.mutations.add(mutation);
|
|
1129
|
+
this.receipts.set(mutation, r);
|
|
1130
|
+
this.pendingQueue.push(mutation);
|
|
1131
|
+
this.pendingRecords.set(mutation, touched);
|
|
1132
|
+
this.pushStatus();
|
|
1133
|
+
this.scheduleConfirm();
|
|
1134
|
+
}
|
|
1135
|
+
catch (e) {
|
|
1136
|
+
const prob = e instanceof MdbaseError ? e.toProblem() : problem("invalid_request", String(e));
|
|
1137
|
+
r = { mutation, state: "rejected", problem: prob };
|
|
1138
|
+
this.receipts.set(mutation, r);
|
|
1139
|
+
}
|
|
1140
|
+
if (p.wait === "confirmed" && r.state === "pending") {
|
|
1141
|
+
await new Promise((res) => {
|
|
1142
|
+
const list = this.awaiters.get(mutation) ?? [];
|
|
1143
|
+
list.push(res);
|
|
1144
|
+
this.awaiters.set(mutation, list);
|
|
1145
|
+
});
|
|
1146
|
+
r = this.receipts.get(mutation);
|
|
1147
|
+
}
|
|
1148
|
+
out.push(r);
|
|
1149
|
+
}
|
|
1150
|
+
return out;
|
|
1151
|
+
}
|
|
1152
|
+
/** Apply ops to the local view; returns the record IDs touched (still present). */
|
|
1153
|
+
applyOps(ops, mutation) {
|
|
1154
|
+
const touched = [];
|
|
1155
|
+
// Validate everything first: a mutation is atomic.
|
|
1156
|
+
const staged = new Map();
|
|
1157
|
+
const cur = (id) => (staged.has(id) ? staged.get(id) : this.records.get(id));
|
|
1158
|
+
for (const op of ops) {
|
|
1159
|
+
switch (op.kind) {
|
|
1160
|
+
case "create": {
|
|
1161
|
+
if (cur(op.id))
|
|
1162
|
+
throw mdbaseError("invalid_request", "record ID exists");
|
|
1163
|
+
const path = op.path ?? `${op.type ?? "record"}-${op.id.slice(0, 8)}.md`;
|
|
1164
|
+
if ([...this.records.values()].some((r) => r.path.toLowerCase() === path.toLowerCase() && staged.get(r.id) !== null)) {
|
|
1165
|
+
throw mdbaseError("conflict", `path ${path} is taken`, "path_taken");
|
|
1166
|
+
}
|
|
1167
|
+
staged.set(op.id, {
|
|
1168
|
+
id: op.id,
|
|
1169
|
+
path,
|
|
1170
|
+
types: op.type ? [op.type] : [],
|
|
1171
|
+
...(op.document === undefined
|
|
1172
|
+
? { frontmatter: new Map(op.frontmatter ?? []), body: op.body ?? "" }
|
|
1173
|
+
: parseDocument(op.document)),
|
|
1174
|
+
confirmedSeq: 0,
|
|
1175
|
+
pending: true,
|
|
1176
|
+
});
|
|
1177
|
+
touched.push(op.id);
|
|
1178
|
+
break;
|
|
1179
|
+
}
|
|
1180
|
+
case "update": {
|
|
1181
|
+
const r0 = cur(op.id);
|
|
1182
|
+
if (!r0)
|
|
1183
|
+
throw mdbaseError("not_found", "no such record");
|
|
1184
|
+
if (op.ifRevision && op.ifRevision !== revision(r0)) {
|
|
1185
|
+
throw new MdbaseError({
|
|
1186
|
+
...problem("conflict", "the record changed since if_revision", "revision"),
|
|
1187
|
+
details: new Map([["current", revision(r0)]]),
|
|
1188
|
+
});
|
|
1189
|
+
}
|
|
1190
|
+
const r = { ...r0, frontmatter: new Map(r0.frontmatter), pending: true };
|
|
1191
|
+
for (const [k, v] of op.patch ?? [])
|
|
1192
|
+
r.frontmatter.set(k, v);
|
|
1193
|
+
// Explicit membership, as Core reads the `type` key.
|
|
1194
|
+
const declared = r.frontmatter.get("type");
|
|
1195
|
+
if (typeof declared === "string" && !r.types.includes(declared))
|
|
1196
|
+
r.types = [declared];
|
|
1197
|
+
for (const k of op.unset ?? [])
|
|
1198
|
+
r.frontmatter.delete(k);
|
|
1199
|
+
for (const [k, items] of op.add ?? []) {
|
|
1200
|
+
const old = r.frontmatter.get(k);
|
|
1201
|
+
const arr = Array.isArray(old) ? [...old] : [];
|
|
1202
|
+
for (const it of items)
|
|
1203
|
+
if (!arr.some((x) => JSON.stringify(toPlain(x)) === JSON.stringify(toPlain(it))))
|
|
1204
|
+
arr.push(it);
|
|
1205
|
+
r.frontmatter.set(k, arr);
|
|
1206
|
+
}
|
|
1207
|
+
for (const [k, items] of op.remove ?? []) {
|
|
1208
|
+
const old = r.frontmatter.get(k);
|
|
1209
|
+
if (Array.isArray(old)) {
|
|
1210
|
+
const drop = new Set(items.map((x) => JSON.stringify(toPlain(x))));
|
|
1211
|
+
r.frontmatter.set(k, old.filter((x) => !drop.has(JSON.stringify(toPlain(x)))));
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
if (op.bodyEdits) {
|
|
1215
|
+
const base = hashFromBytes(sha256(new TextEncoder().encode(r.body)));
|
|
1216
|
+
if (op.bodyBase && op.bodyBase !== base)
|
|
1217
|
+
throw mdbaseError("conflict", "body changed", "body");
|
|
1218
|
+
r.body = applyScalarEdits(r.body, op.bodyEdits);
|
|
1219
|
+
}
|
|
1220
|
+
else if (op.body !== undefined)
|
|
1221
|
+
r.body = op.body;
|
|
1222
|
+
staged.set(op.id, r);
|
|
1223
|
+
touched.push(op.id);
|
|
1224
|
+
break;
|
|
1225
|
+
}
|
|
1226
|
+
case "document": {
|
|
1227
|
+
const r0 = cur(op.id);
|
|
1228
|
+
if (!op.new) {
|
|
1229
|
+
staged.set(op.id, null);
|
|
1230
|
+
break;
|
|
1231
|
+
}
|
|
1232
|
+
staged.set(op.id, {
|
|
1233
|
+
id: op.id,
|
|
1234
|
+
path: op.new.path || r0?.path || `${op.id}.md`,
|
|
1235
|
+
types: r0?.types ?? [],
|
|
1236
|
+
...parseDocument(op.new.doc),
|
|
1237
|
+
confirmedSeq: r0?.confirmedSeq ?? 0,
|
|
1238
|
+
pending: true,
|
|
1239
|
+
});
|
|
1240
|
+
touched.push(op.id);
|
|
1241
|
+
break;
|
|
1242
|
+
}
|
|
1243
|
+
case "delete": {
|
|
1244
|
+
const r0 = cur(op.id);
|
|
1245
|
+
if (!r0)
|
|
1246
|
+
throw mdbaseError("not_found", "no such record");
|
|
1247
|
+
if (op.ifRevision && op.ifRevision !== revision(r0))
|
|
1248
|
+
throw mdbaseError("conflict", "changed", "revision");
|
|
1249
|
+
staged.set(op.id, null);
|
|
1250
|
+
break;
|
|
1251
|
+
}
|
|
1252
|
+
case "rename": {
|
|
1253
|
+
const r0 = cur(op.id);
|
|
1254
|
+
if (!r0)
|
|
1255
|
+
throw mdbaseError("not_found", "no such record");
|
|
1256
|
+
if ([...this.records.values()].some((r) => r.path === op.to && r.id !== op.id)) {
|
|
1257
|
+
throw mdbaseError("conflict", `path ${op.to} is taken`, "path_taken");
|
|
1258
|
+
}
|
|
1259
|
+
staged.set(op.id, { ...r0, path: op.to, pending: true });
|
|
1260
|
+
touched.push(op.id);
|
|
1261
|
+
break;
|
|
1262
|
+
}
|
|
1263
|
+
case "file_move": {
|
|
1264
|
+
const f = this.files.get(op.id);
|
|
1265
|
+
if (!f)
|
|
1266
|
+
throw mdbaseError("not_found", "no such file");
|
|
1267
|
+
this.touch(f.id, f.path, "remove", "file");
|
|
1268
|
+
f.path = op.to;
|
|
1269
|
+
f.pending = true;
|
|
1270
|
+
this.touch(f.id, f.path, "put", "file");
|
|
1271
|
+
break;
|
|
1272
|
+
}
|
|
1273
|
+
case "file_delete": {
|
|
1274
|
+
const f = this.files.get(op.id);
|
|
1275
|
+
if (!f)
|
|
1276
|
+
throw mdbaseError("not_found", "no such file");
|
|
1277
|
+
this.files.delete(op.id);
|
|
1278
|
+
this.touch(f.id, f.path, "remove", "file");
|
|
1279
|
+
break;
|
|
1280
|
+
}
|
|
1281
|
+
case "resource_put": {
|
|
1282
|
+
const cur = this.resources.get(op.path);
|
|
1283
|
+
if (op.mustNotExist && cur) {
|
|
1284
|
+
throw new MdbaseError({
|
|
1285
|
+
...problem("conflict", `a resource exists at ${op.path}`, "path_taken"),
|
|
1286
|
+
details: this.resourceView(op.path, cur, false).revision,
|
|
1287
|
+
});
|
|
1288
|
+
}
|
|
1289
|
+
if (op.baseRevision && (!cur || this.resourceView(op.path, cur, false).revision !== op.baseRevision)) {
|
|
1290
|
+
throw mdbaseError("conflict", "the resource changed", "revision");
|
|
1291
|
+
}
|
|
1292
|
+
this.resources.set(op.path, { text: op.doc, pending: true });
|
|
1293
|
+
break;
|
|
1294
|
+
}
|
|
1295
|
+
case "resource_delete": {
|
|
1296
|
+
const cur = this.resources.get(op.path);
|
|
1297
|
+
if (!cur)
|
|
1298
|
+
throw mdbaseError("not_found", "no such resource");
|
|
1299
|
+
if (op.baseRevision && this.resourceView(op.path, cur, false).revision !== op.baseRevision) {
|
|
1300
|
+
throw mdbaseError("conflict", "the resource changed", "revision");
|
|
1301
|
+
}
|
|
1302
|
+
this.resources.delete(op.path);
|
|
1303
|
+
break;
|
|
1304
|
+
}
|
|
1305
|
+
case "conflict_dismiss": {
|
|
1306
|
+
const before = this.conflictList.length;
|
|
1307
|
+
this.conflictList = this.conflictList.filter((e) => !(e.mutation === op.mutation && e.conflict.id === op.record));
|
|
1308
|
+
const r0 = this.records.get(op.record);
|
|
1309
|
+
if (r0 && before !== this.conflictList.length) {
|
|
1310
|
+
r0.unresolved = Math.max(0, (r0.unresolved ?? 0) - 1);
|
|
1311
|
+
this.pushConflicts();
|
|
1312
|
+
}
|
|
1313
|
+
break;
|
|
1314
|
+
}
|
|
1315
|
+
default:
|
|
1316
|
+
throw mdbaseError("invalid_request", `MemoryReplica does not implement ${op.kind}`);
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
const prior = new Map();
|
|
1320
|
+
for (const id of staged.keys()) {
|
|
1321
|
+
const b = this.records.get(id);
|
|
1322
|
+
prior.set(id, b ? { ...b, frontmatter: new Map(b.frontmatter) } : null);
|
|
1323
|
+
}
|
|
1324
|
+
this.priors.set(mutation, prior);
|
|
1325
|
+
for (const [id, r] of staged) {
|
|
1326
|
+
const before = this.records.get(id);
|
|
1327
|
+
if (r === null) {
|
|
1328
|
+
this.records.delete(id);
|
|
1329
|
+
if (before)
|
|
1330
|
+
this.touch(id, before.path, "remove");
|
|
1331
|
+
}
|
|
1332
|
+
else {
|
|
1333
|
+
this.records.set(id, r);
|
|
1334
|
+
if (before && before.path !== r.path)
|
|
1335
|
+
this.touch(id, before.path, "remove");
|
|
1336
|
+
this.touch(id, r.path, "put");
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
return touched.filter((id) => this.records.has(id));
|
|
1340
|
+
}
|
|
1341
|
+
confirmTimer = null;
|
|
1342
|
+
scheduleConfirm() {
|
|
1343
|
+
const d = this.opts.confirmDelayMs;
|
|
1344
|
+
if (d === null || !this.online || this.stalled || this.confirmTimer)
|
|
1345
|
+
return;
|
|
1346
|
+
this.confirmTimer = setTimeout(() => {
|
|
1347
|
+
this.confirmTimer = null;
|
|
1348
|
+
if (this.online && !this.stalled)
|
|
1349
|
+
this.confirmAll();
|
|
1350
|
+
}, d ?? 0);
|
|
1351
|
+
}
|
|
1352
|
+
confirmNext() {
|
|
1353
|
+
const mutation = this.pendingQueue.shift();
|
|
1354
|
+
if (!mutation)
|
|
1355
|
+
return;
|
|
1356
|
+
const seq = ++this.seq;
|
|
1357
|
+
const ids = this.pendingRecords.get(mutation) ?? [];
|
|
1358
|
+
for (const id of ids) {
|
|
1359
|
+
const r = this.records.get(id);
|
|
1360
|
+
if (r) {
|
|
1361
|
+
r.pending = false;
|
|
1362
|
+
r.confirmedSeq = seq;
|
|
1363
|
+
this.touch(id, r.path, "put");
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
for (const id of this.fileMutations.get(mutation) ?? []) {
|
|
1367
|
+
const f = this.files.get(id);
|
|
1368
|
+
if (f) {
|
|
1369
|
+
f.pending = false;
|
|
1370
|
+
f.confirmedSeq = seq;
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
this.pendingRecords.delete(mutation);
|
|
1374
|
+
this.fileMutations.delete(mutation);
|
|
1375
|
+
this.priors.delete(mutation);
|
|
1376
|
+
for (const op of this.pendingOps.get(mutation) ?? []) {
|
|
1377
|
+
if (op.kind === "resource_put") {
|
|
1378
|
+
const r = this.resources.get(op.path);
|
|
1379
|
+
if (r)
|
|
1380
|
+
r.pending = false;
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
this.pendingOps.delete(mutation);
|
|
1384
|
+
const records = ids.filter((id) => this.records.has(id)).map((id) => this.view(this.records.get(id)));
|
|
1385
|
+
this.settle({ mutation, state: "confirmed", seq, status: "applied", records });
|
|
1386
|
+
}
|
|
1387
|
+
settle(r) {
|
|
1388
|
+
this.receipts.set(r.mutation, r);
|
|
1389
|
+
for (const c of this.conns)
|
|
1390
|
+
if (c.mutations.has(r.mutation))
|
|
1391
|
+
this.push(c, "receipt", w.receipt.enc(r));
|
|
1392
|
+
for (const res of this.awaiters.get(r.mutation) ?? [])
|
|
1393
|
+
res();
|
|
1394
|
+
this.awaiters.delete(r.mutation);
|
|
1395
|
+
this.pushStatus();
|
|
1396
|
+
}
|
|
1397
|
+
pushStatus() {
|
|
1398
|
+
const s = w.syncStatus.enc(this.status());
|
|
1399
|
+
for (const c of this.conns)
|
|
1400
|
+
if (c.status)
|
|
1401
|
+
this.push(c, "status", s);
|
|
1402
|
+
}
|
|
1403
|
+
pushPresence(record, only) {
|
|
1404
|
+
const peers = [];
|
|
1405
|
+
for (const c of this.conns) {
|
|
1406
|
+
const st = c.joined.get(record);
|
|
1407
|
+
if (st !== undefined)
|
|
1408
|
+
peers.push({ session: c.pseudonym, state: st, lastSeen: Date.now() });
|
|
1409
|
+
}
|
|
1410
|
+
const payload = w.presencePush.enc({ record, peers });
|
|
1411
|
+
for (const c of only ? [only] : this.conns)
|
|
1412
|
+
if (c.presence.has(record))
|
|
1413
|
+
this.push(c, "presence", payload);
|
|
1414
|
+
}
|
|
1415
|
+
/** Record a change and refresh live queries. */
|
|
1416
|
+
touch(id, path, kind, entity = "record", types) {
|
|
1417
|
+
this.viewVersion++;
|
|
1418
|
+
const t = entity === "record" ? (types ?? this.records.get(id)?.types) : undefined;
|
|
1419
|
+
const ch = { id, path, kind, version: this.viewVersion, entity, ...(t?.length ? { types: [...t] } : {}) };
|
|
1420
|
+
this.changeLog.push(ch);
|
|
1421
|
+
queueMicrotask(() => {
|
|
1422
|
+
for (const c of this.conns) {
|
|
1423
|
+
for (const sub of c.subs.values())
|
|
1424
|
+
this.refreshSub(c, sub, false);
|
|
1425
|
+
if (c.changesWatch) {
|
|
1426
|
+
this.push(c, "changes", w.changesResult.enc({ changes: [ch], cursor: String(ch.version), reset: false }));
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
});
|
|
1430
|
+
}
|
|
1431
|
+
refreshSub(c, sub, first) {
|
|
1432
|
+
if (!c.subs.has(sub.id))
|
|
1433
|
+
return;
|
|
1434
|
+
const { rows } = this.page(new Map([...sub.query].filter(([k]) => k !== "cursor")));
|
|
1435
|
+
const views = rows.map((r) => this.view(r, sub.include));
|
|
1436
|
+
const next = new Map(views.map((v) => [v.id, `${v.revision}|${v.state.state}|${v.path}`]));
|
|
1437
|
+
const order = views.map((v) => v.id);
|
|
1438
|
+
if (first) {
|
|
1439
|
+
sub.last = next;
|
|
1440
|
+
sub.order = order;
|
|
1441
|
+
this.push(c, "query_update", w.queryUpdate.enc({ sub: sub.id, kind: "snapshot", added: views, order, complete: true, asOf: this.viewVersion }));
|
|
1442
|
+
return;
|
|
1443
|
+
}
|
|
1444
|
+
const added = views.filter((v) => !sub.last.has(v.id));
|
|
1445
|
+
const changed = views.filter((v) => sub.last.has(v.id) && sub.last.get(v.id) !== next.get(v.id));
|
|
1446
|
+
const removed = [...sub.last.keys()].filter((id) => !next.has(id));
|
|
1447
|
+
const orderChanged = order.join() !== sub.order.join();
|
|
1448
|
+
if (!added.length && !changed.length && !removed.length && !orderChanged)
|
|
1449
|
+
return;
|
|
1450
|
+
sub.last = next;
|
|
1451
|
+
sub.order = order;
|
|
1452
|
+
const u = { sub: sub.id, kind: "diff", complete: true, asOf: this.viewVersion };
|
|
1453
|
+
if (added.length)
|
|
1454
|
+
u.added = added;
|
|
1455
|
+
if (changed.length)
|
|
1456
|
+
u.changed = changed;
|
|
1457
|
+
if (removed.length)
|
|
1458
|
+
u.removed = removed;
|
|
1459
|
+
if (orderChanged)
|
|
1460
|
+
u.order = order;
|
|
1461
|
+
this.push(c, "query_update", w.queryUpdate.enc(u));
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
export { list };
|
|
1465
|
+
//# sourceMappingURL=memory-replica.js.map
|