@spooky-sync/core 0.0.1-canary.24 → 0.0.1-canary.240
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/AGENTS.md +58 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +476 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +210 -0
- package/coverage/lcov-report/src/boot/auth-flip.saga.ts.html +271 -0
- package/coverage/lcov-report/src/boot/boot.saga.ts.html +469 -0
- package/coverage/lcov-report/src/boot/bucket-switch.saga.ts.html +430 -0
- package/coverage/lcov-report/src/boot/index.html +161 -0
- package/coverage/lcov-report/src/boot/preload.saga.ts.html +178 -0
- package/coverage/lcov-report/src/client/bucket-handle.ts.html +766 -0
- package/coverage/lcov-report/src/client/index.html +161 -0
- package/coverage/lcov-report/src/client/router.ts.html +367 -0
- package/coverage/lcov-report/src/client/runtime.ts.html +940 -0
- package/coverage/lcov-report/src/client/sp00ky-client.ts.html +1531 -0
- package/coverage/lcov-report/src/events/index.html +116 -0
- package/coverage/lcov-report/src/events/index.ts.html +877 -0
- package/coverage/lcov-report/src/index.html +146 -0
- package/coverage/lcov-report/src/index.ts.html +202 -0
- package/coverage/lcov-report/src/kernel/constants.ts.html +247 -0
- package/coverage/lcov-report/src/kernel/effects.ts.html +562 -0
- package/coverage/lcov-report/src/kernel/events.ts.html +250 -0
- package/coverage/lcov-report/src/kernel/index.html +176 -0
- package/coverage/lcov-report/src/kernel/interpreter.ts.html +514 -0
- package/coverage/lcov-report/src/kernel/saga.ts.html +304 -0
- package/coverage/lcov-report/src/modules/app-release/index.html +116 -0
- package/coverage/lcov-report/src/modules/app-release/index.ts.html +712 -0
- package/coverage/lcov-report/src/modules/auth/events/index.html +116 -0
- package/coverage/lcov-report/src/modules/auth/events/index.ts.html +142 -0
- package/coverage/lcov-report/src/modules/auth/index.html +116 -0
- package/coverage/lcov-report/src/modules/auth/index.ts.html +1225 -0
- package/coverage/lcov-report/src/modules/crdt/crdt-field.ts.html +967 -0
- package/coverage/lcov-report/src/modules/crdt/index.html +146 -0
- package/coverage/lcov-report/src/modules/crdt/index.ts.html +1474 -0
- package/coverage/lcov-report/src/modules/crdt/loro-loader.ts.html +160 -0
- package/coverage/lcov-report/src/modules/devtools/flags.ts.html +1132 -0
- package/coverage/lcov-report/src/modules/devtools/index.html +161 -0
- package/coverage/lcov-report/src/modules/devtools/index.ts.html +2413 -0
- package/coverage/lcov-report/src/modules/devtools/storage-info.ts.html +589 -0
- package/coverage/lcov-report/src/modules/devtools/versions.ts.html +415 -0
- package/coverage/lcov-report/src/modules/feature-flag/index.html +116 -0
- package/coverage/lcov-report/src/modules/feature-flag/index.ts.html +1033 -0
- package/coverage/lcov-report/src/modules/index.html +116 -0
- package/coverage/lcov-report/src/modules/ref-tables.ts.html +349 -0
- package/coverage/lcov-report/src/mutation/index.html +191 -0
- package/coverage/lcov-report/src/mutation/jobs.ts.html +208 -0
- package/coverage/lcov-report/src/mutation/mutation-id.ts.html +190 -0
- package/coverage/lcov-report/src/mutation/push.saga.ts.html +730 -0
- package/coverage/lcov-report/src/mutation/rows.ts.html +1216 -0
- package/coverage/lcov-report/src/mutation/tray.saga.ts.html +229 -0
- package/coverage/lcov-report/src/mutation/write.saga.ts.html +583 -0
- package/coverage/lcov-report/src/otel/index.html +116 -0
- package/coverage/lcov-report/src/otel/index.ts.html +466 -0
- package/coverage/lcov-report/src/query/env.ts.html +253 -0
- package/coverage/lcov-report/src/query/fetch.saga.ts.html +412 -0
- package/coverage/lcov-report/src/query/hash.ts.html +139 -0
- package/coverage/lcov-report/src/query/index.html +281 -0
- package/coverage/lcov-report/src/query/lifecycle.saga.ts.html +388 -0
- package/coverage/lcov-report/src/query/materialize.saga.ts.html +310 -0
- package/coverage/lcov-report/src/query/materialize.ts.html +217 -0
- package/coverage/lcov-report/src/query/membership.saga.ts.html +709 -0
- package/coverage/lcov-report/src/query/membership.ts.html +559 -0
- package/coverage/lcov-report/src/query/register.saga.ts.html +655 -0
- package/coverage/lcov-report/src/query/render-set.ts.html +265 -0
- package/coverage/lcov-report/src/query/sql.ts.html +322 -0
- package/coverage/lcov-report/src/query/window-query.ts.html +670 -0
- package/coverage/lcov-report/src/services/blobs/blob-cache.ts.html +1894 -0
- package/coverage/lcov-report/src/services/blobs/blob-manifest.ts.html +766 -0
- package/coverage/lcov-report/src/services/blobs/blob-store.ts.html +1162 -0
- package/coverage/lcov-report/src/services/blobs/index.html +161 -0
- package/coverage/lcov-report/src/services/blobs/index.ts.html +295 -0
- package/coverage/lcov-report/src/services/database/cache-engine.ts.html +664 -0
- package/coverage/lcov-report/src/services/database/connection-supervisor.ts.html +1330 -0
- package/coverage/lcov-report/src/services/database/database.ts.html +658 -0
- package/coverage/lcov-report/src/services/database/engine-factory.ts.html +184 -0
- package/coverage/lcov-report/src/services/database/errors.ts.html +187 -0
- package/coverage/lcov-report/src/services/database/events/index.html +116 -0
- package/coverage/lcov-report/src/services/database/events/index.ts.html +184 -0
- package/coverage/lcov-report/src/services/database/index.html +386 -0
- package/coverage/lcov-report/src/services/database/index.ts.html +121 -0
- package/coverage/lcov-report/src/services/database/local-migrator.ts.html +703 -0
- package/coverage/lcov-report/src/services/database/local.ts.html +1633 -0
- package/coverage/lcov-report/src/services/database/plan-render.ts.html +409 -0
- package/coverage/lcov-report/src/services/database/relation-resolver.ts.html +682 -0
- package/coverage/lcov-report/src/services/database/remote.ts.html +1036 -0
- package/coverage/lcov-report/src/services/database/sqlite-cache-engine.ts.html +4132 -0
- package/coverage/lcov-report/src/services/database/sqlite-lock-verify.ts.html +220 -0
- package/coverage/lcov-report/src/services/database/sqlite-open.ts.html +577 -0
- package/coverage/lcov-report/src/services/database/sqlite-plan-sql.ts.html +499 -0
- package/coverage/lcov-report/src/services/database/sqlite-select.ts.html +478 -0
- package/coverage/lcov-report/src/services/database/sqlite-transport.ts.html +757 -0
- package/coverage/lcov-report/src/services/database/surql-translate.ts.html +1333 -0
- package/coverage/lcov-report/src/services/database/surreal-cache-engine.ts.html +568 -0
- package/coverage/lcov-report/src/services/logger/index.html +116 -0
- package/coverage/lcov-report/src/services/logger/index.ts.html +154 -0
- package/coverage/lcov-report/src/services/persistence/index.html +146 -0
- package/coverage/lcov-report/src/services/persistence/localstorage.ts.html +163 -0
- package/coverage/lcov-report/src/services/persistence/resilient.ts.html +208 -0
- package/coverage/lcov-report/src/services/persistence/surrealdb.ts.html +271 -0
- package/coverage/lcov-report/src/services/stream-processor/index.html +146 -0
- package/coverage/lcov-report/src/services/stream-processor/index.ts.html +3313 -0
- package/coverage/lcov-report/src/services/stream-processor/permissions.ts.html +244 -0
- package/coverage/lcov-report/src/services/stream-processor/wasm-types.ts.html +346 -0
- package/coverage/lcov-report/src/services/tabs/broker-client.ts.html +934 -0
- package/coverage/lcov-report/src/services/tabs/coordinator.ts.html +1984 -0
- package/coverage/lcov-report/src/services/tabs/index.html +191 -0
- package/coverage/lcov-report/src/services/tabs/leader-locks.ts.html +310 -0
- package/coverage/lcov-report/src/services/tabs/protocol.ts.html +871 -0
- package/coverage/lcov-report/src/services/tabs/support.ts.html +193 -0
- package/coverage/lcov-report/src/services/tabs/tabs-broker-worker.ts.html +2005 -0
- package/coverage/lcov-report/src/sp00ky.ts.html +100 -0
- package/coverage/lcov-report/src/state/client-state.ts.html +637 -0
- package/coverage/lcov-report/src/state/index.html +161 -0
- package/coverage/lcov-report/src/state/lifecycle.ts.html +343 -0
- package/coverage/lcov-report/src/state/reducers.ts.html +1471 -0
- package/coverage/lcov-report/src/state/selectors.ts.html +637 -0
- package/coverage/lcov-report/src/sync/connection.saga.ts.html +343 -0
- package/coverage/lcov-report/src/sync/index.html +176 -0
- package/coverage/lcov-report/src/sync/live.saga.ts.html +232 -0
- package/coverage/lcov-report/src/sync/policy.ts.html +1606 -0
- package/coverage/lcov-report/src/sync/poll.saga.ts.html +193 -0
- package/coverage/lcov-report/src/sync/tabs.saga.ts.html +361 -0
- package/coverage/lcov-report/src/types.ts.html +2419 -0
- package/coverage/lcov-report/src/utils/blurhash.ts.html +355 -0
- package/coverage/lcov-report/src/utils/error-classification.ts.html +244 -0
- package/coverage/lcov-report/src/utils/index.html +191 -0
- package/coverage/lcov-report/src/utils/index.ts.html +820 -0
- package/coverage/lcov-report/src/utils/parser.ts.html +313 -0
- package/coverage/lcov-report/src/utils/semver.ts.html +175 -0
- package/coverage/lcov-report/src/utils/surql.ts.html +667 -0
- package/coverage/lcov.info +19079 -0
- package/dist/index.d.ts +2946 -140
- package/dist/index.js +13424 -2356
- package/dist/otel/index.d.ts +2 -2
- package/dist/otel/index.js +6 -6
- package/dist/sqlite-open.js +322 -0
- package/dist/sqlite-worker.d.ts +1 -0
- package/dist/sqlite-worker.js +439 -0
- package/dist/tabs-broker-worker.d.ts +8 -0
- package/dist/tabs-broker-worker.js +472 -0
- package/dist/types.d.ts +769 -11
- package/package.json +11 -7
- package/scripts/check-broker-bundle.mjs +33 -0
- package/skills/{spooky-core → sp00ky-core}/SKILL.md +12 -12
- package/skills/{spooky-core → sp00ky-core}/references/auth.md +1 -1
- package/skills/{spooky-core → sp00ky-core}/references/config.md +2 -2
- package/src/bucket-blurhash.test.ts +148 -0
- package/src/build-globals.d.ts +12 -0
- package/src/events/events.test.ts +2 -1
- package/src/events/index.ts +3 -0
- package/src/index.ts +36 -2
- package/src/modules/app-release/index.test.ts +125 -0
- package/src/modules/app-release/index.ts +201 -0
- package/src/modules/auth/auth.local-first.test.ts +141 -0
- package/src/modules/auth/events/index.ts +2 -1
- package/src/modules/auth/index.ts +138 -25
- package/src/modules/cache/cache.relay.test.ts +95 -0
- package/src/modules/cache/index.ts +163 -43
- package/src/modules/cache/types.ts +2 -2
- package/src/modules/crdt/crdt-field.ts +294 -0
- package/src/modules/crdt/crdt-hydration.test.ts +210 -0
- package/src/modules/crdt/crdt-reconnect.test.ts +195 -0
- package/src/modules/crdt/index.ts +463 -0
- package/src/modules/crdt/loro-loader.ts +25 -0
- package/src/modules/data/data.activity.test.ts +109 -0
- package/src/modules/data/data.authority.test.ts +122 -0
- package/src/modules/data/data.heartbeat-wake.test.ts +115 -0
- package/src/modules/data/data.hydration.test.ts +142 -0
- package/src/modules/data/data.membership.test.ts +623 -0
- package/src/modules/data/data.notify-table.test.ts +41 -0
- package/src/modules/data/data.pending-ids.test.ts +199 -0
- package/src/modules/data/data.rebind.test.ts +170 -0
- package/src/modules/data/data.rematerialize.test.ts +114 -0
- package/src/modules/data/data.run.test.ts +113 -0
- package/src/modules/data/data.settled-writes.test.ts +235 -0
- package/src/modules/data/data.status.test.ts +249 -0
- package/src/modules/data/id-set-plan.test.ts +122 -0
- package/src/modules/data/index.ts +2031 -150
- package/src/modules/data/mutation-id.test.ts +25 -0
- package/src/modules/data/mutation-id.ts +35 -0
- package/src/modules/data/window-query.test.ts +52 -0
- package/src/modules/data/window-query.ts +194 -0
- package/src/modules/devtools/flags.ts +349 -0
- package/src/modules/devtools/index.ts +451 -46
- package/src/modules/devtools/notify-throttle.test.ts +154 -0
- package/src/modules/devtools/state-shape.test.ts +146 -0
- package/src/modules/devtools/storage-info.test.ts +79 -0
- package/src/modules/devtools/storage-info.ts +168 -0
- package/src/modules/devtools/versions.test.ts +74 -0
- package/src/modules/devtools/versions.ts +110 -0
- package/src/modules/feature-flag/index.test.ts +251 -0
- package/src/modules/feature-flag/index.ts +308 -0
- package/src/modules/ref-tables.test.ts +91 -0
- package/src/modules/ref-tables.ts +88 -0
- package/src/modules/sync/engine.ts +170 -86
- package/src/modules/sync/events/index.ts +9 -2
- package/src/modules/sync/queue/queue-down.test.ts +228 -0
- package/src/modules/sync/queue/queue-down.ts +108 -13
- package/src/modules/sync/queue/queue-up.forwarded.test.ts +164 -0
- package/src/modules/sync/queue/queue-up.ts +241 -57
- package/src/modules/sync/scheduler.pause.test.ts +109 -0
- package/src/modules/sync/scheduler.retry.test.ts +237 -0
- package/src/modules/sync/scheduler.ts +215 -13
- package/src/modules/sync/sync.cleanup.test.ts +116 -0
- package/src/modules/sync/sync.health.test.ts +167 -0
- package/src/modules/sync/sync.heartbeat.test.ts +80 -0
- package/src/modules/sync/sync.list-ref-meta.test.ts +193 -0
- package/src/modules/sync/sync.live-removal.test.ts +289 -0
- package/src/modules/sync/sync.reconnect.test.ts +145 -0
- package/src/modules/sync/sync.rematerialize-after-fetch.test.ts +93 -0
- package/src/modules/sync/sync.settled-poll.test.ts +58 -0
- package/src/modules/sync/sync.subquery.test.ts +82 -0
- package/src/modules/sync/sync.tabs.test.ts +249 -0
- package/src/modules/sync/sync.ts +2350 -133
- package/src/modules/sync/utils.test.ts +322 -2
- package/src/modules/sync/utils.ts +286 -16
- package/src/otel/index.ts +13 -10
- package/src/services/blobs/blob-cache.test.ts +359 -0
- package/src/services/blobs/blob-cache.ts +603 -0
- package/src/services/blobs/blob-manifest.ts +227 -0
- package/src/services/blobs/blob-store.test.ts +77 -0
- package/src/services/blobs/blob-store.ts +359 -0
- package/src/services/blobs/blob.fixture.ts +90 -0
- package/src/services/blobs/index.ts +70 -0
- package/src/services/database/cache-engine.ts +193 -0
- package/src/services/database/connection-supervisor.test.ts +289 -0
- package/src/services/database/connection-supervisor.ts +415 -0
- package/src/services/database/database.query-timeout.test.ts +140 -0
- package/src/services/database/database.ts +130 -62
- package/src/services/database/engine-factory.ts +33 -0
- package/src/services/database/errors.ts +34 -0
- package/src/services/database/events/index.ts +2 -1
- package/src/services/database/index.ts +7 -0
- package/src/services/database/local-migrator.ts +30 -27
- package/src/services/database/local.test.ts +64 -0
- package/src/services/database/local.ts +484 -67
- package/src/services/database/plan-render.test.ts +159 -0
- package/src/services/database/plan-render.ts +108 -0
- package/src/services/database/relation-resolver.test.ts +467 -0
- package/src/services/database/relation-resolver.ts +0 -0
- package/src/services/database/remote.ts +222 -15
- package/src/services/database/sqlite-cache-engine.test.ts +616 -0
- package/src/services/database/sqlite-cache-engine.timeout.test.ts +61 -0
- package/src/services/database/sqlite-cache-engine.ts +1358 -0
- package/src/services/database/sqlite-devtools-queries.integration.test.ts +143 -0
- package/src/services/database/sqlite-devtools-queries.test.ts +154 -0
- package/src/services/database/sqlite-lock-verify.test.ts +33 -0
- package/src/services/database/sqlite-lock-verify.ts +45 -0
- package/src/services/database/sqlite-open.test.ts +150 -0
- package/src/services/database/sqlite-open.ts +164 -0
- package/src/services/database/sqlite-plan-sql.test.ts +104 -0
- package/src/services/database/sqlite-plan-sql.ts +138 -0
- package/src/services/database/sqlite-projection.test.ts +99 -0
- package/src/services/database/sqlite-select.integration.test.ts +185 -0
- package/src/services/database/sqlite-select.test.ts +246 -0
- package/src/services/database/sqlite-select.ts +131 -0
- package/src/services/database/sqlite-transport.fixture.ts +30 -0
- package/src/services/database/sqlite-transport.ts +224 -0
- package/src/services/database/sqlite-worker.ts +437 -0
- package/src/services/database/surql-translate.ts +416 -0
- package/src/services/database/surreal-cache-engine.ts +161 -0
- package/src/services/logger/index.ts +3 -2
- package/src/services/persistence/localstorage.ts +2 -2
- package/src/services/persistence/resilient.ts +11 -4
- package/src/services/persistence/surrealdb.ts +10 -10
- package/src/services/stream-processor/index.ts +796 -84
- package/src/services/stream-processor/permissions.test.ts +47 -0
- package/src/services/stream-processor/permissions.ts +53 -0
- package/src/services/stream-processor/stream-processor.batch.test.ts +186 -0
- package/src/services/stream-processor/stream-processor.prime.test.ts +198 -0
- package/src/services/stream-processor/stream-processor.reset.test.ts +226 -0
- package/src/services/stream-processor/stream-processor.test.ts +1 -1
- package/src/services/stream-processor/wasm-types.ts +59 -3
- package/src/services/tabs/broker-client.ts +283 -0
- package/src/services/tabs/broker.test.ts +327 -0
- package/src/services/tabs/coordinator.test.ts +365 -0
- package/src/services/tabs/coordinator.ts +633 -0
- package/src/services/tabs/fake-ports.fixture.ts +112 -0
- package/src/services/tabs/leader-locks.ts +75 -0
- package/src/services/tabs/protocol.ts +258 -0
- package/src/services/tabs/support.ts +36 -0
- package/src/services/tabs/tabs-broker-worker.ts +640 -0
- package/src/sp00ky.auth-order.test.ts +112 -0
- package/src/sp00ky.init-query.test.ts +183 -0
- package/src/sp00ky.local-first.test.ts +60 -0
- package/src/sp00ky.ts +1854 -0
- package/src/types.ts +548 -13
- package/src/utils/blurhash.ts +90 -0
- package/src/utils/error-classification.test.ts +54 -0
- package/src/utils/error-classification.ts +25 -0
- package/src/utils/index.ts +79 -13
- package/src/utils/parser.test.ts +49 -120
- package/src/utils/parser.ts +32 -2
- package/src/utils/semver.test.ts +32 -0
- package/src/utils/semver.ts +30 -0
- package/src/utils/surql.ts +30 -18
- package/src/utils/withRetry.test.ts +1 -1
- package/tsdown.config.ts +86 -1
- package/src/spooky.ts +0 -395
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Logger } from '../../services/logger/index';
|
|
3
|
-
import { SchemaStructure } from '@spooky-sync/query-builder';
|
|
1
|
+
import type { LocalStore, RemoteDatabaseService } from '../../services/database/index';
|
|
2
|
+
import type { Logger } from '../../services/logger/index';
|
|
3
|
+
import type { SchemaStructure } from '@spooky-sync/query-builder';
|
|
4
4
|
import { RecordId } from 'surrealdb';
|
|
5
|
-
import { StreamUpdate, StreamUpdateReceiver } from '../../services/stream-processor/index';
|
|
5
|
+
import type { StreamUpdate, StreamUpdateReceiver } from '../../services/stream-processor/index';
|
|
6
6
|
import { encodeRecordId } from '../../utils/index';
|
|
7
7
|
|
|
8
8
|
// DevTools interfaces (matching extension expectations)
|
|
@@ -13,31 +13,173 @@ export interface DevToolsEvent {
|
|
|
13
13
|
payload: any;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
import { DataModule } from '../data/index';
|
|
17
|
-
import { AuthService } from '../auth/index';
|
|
16
|
+
import type { DataModule } from '../data/index';
|
|
17
|
+
import type { AuthService } from '../auth/index';
|
|
18
18
|
import { AuthEventTypes } from '../auth/events/index';
|
|
19
|
+
import {
|
|
20
|
+
type BackendInfo,
|
|
21
|
+
emptyBackendInfo,
|
|
22
|
+
parseBackendInfo,
|
|
23
|
+
UNAVAILABLE,
|
|
24
|
+
} from './versions';
|
|
25
|
+
import { walkOpfs, type BlobCacheInfo, type SharedTabsInfo, type StorageInfo } from './storage-info';
|
|
26
|
+
import { FlagsAdminService, type LocalOverrideStore } from './flags';
|
|
27
|
+
|
|
28
|
+
// Real bundled frontend versions, injected at build time by tsdown's
|
|
29
|
+
// version-define plugin (see tsdown.config.ts). The `typeof` guard keeps these
|
|
30
|
+
// from throwing a ReferenceError when a downstream app bundles core from source
|
|
31
|
+
// (where the plugin never runs); in that case they fall back to 'unknown' and
|
|
32
|
+
// DevTools simply reports an unknown frontend version instead of crashing.
|
|
33
|
+
const CORE_VERSION =
|
|
34
|
+
typeof __SP00KY_CORE_VERSION__ !== 'undefined' ? __SP00KY_CORE_VERSION__ : 'unknown';
|
|
35
|
+
const WASM_VERSION =
|
|
36
|
+
typeof __SP00KY_WASM_VERSION__ !== 'undefined' ? __SP00KY_WASM_VERSION__ : 'unknown';
|
|
37
|
+
const SURREAL_VERSION =
|
|
38
|
+
typeof __SP00KY_SURREAL_VERSION__ !== 'undefined' ? __SP00KY_SURREAL_VERSION__ : 'unknown';
|
|
19
39
|
|
|
20
40
|
export class DevToolsService implements StreamUpdateReceiver {
|
|
21
41
|
private eventsHistory: DevToolsEvent[] = [];
|
|
22
42
|
private eventIdCounter = 0;
|
|
23
|
-
|
|
43
|
+
// Real bundled frontend version (injected at build time via tsdown `define`).
|
|
44
|
+
private version = CORE_VERSION;
|
|
45
|
+
// Backend stack info (versions + per-entity status), read via the
|
|
46
|
+
// `fn::spooky::info()` SurrealQL function; empty/'unavailable' until resolved.
|
|
47
|
+
private backendInfo: BackendInfo = emptyBackendInfo();
|
|
48
|
+
// Dormant until a devtools consumer (extension panel or MCP) handshakes via
|
|
49
|
+
// `SP00KY_DEVTOOLS_CONNECT`. While false, `notifyDevTools()`/`addEvent()` do no
|
|
50
|
+
// work, so prod pays zero serialization/postMessage cost for an unwatched panel.
|
|
51
|
+
// `window.__00__.getState()` stays live regardless, so the panel's first paint
|
|
52
|
+
// (the on-demand GET_STATE pull) still works before the push channel turns on.
|
|
53
|
+
private enabled = false;
|
|
54
|
+
|
|
55
|
+
// A state push serializes EVERY active query's full record set (see
|
|
56
|
+
// `getActiveQueries`) and postMessage clones it again, so its cost scales with
|
|
57
|
+
// the whole client dataset — and it is triggered per event, including one per
|
|
58
|
+
// local DB query (`DATABASE_LOCAL_QUERY` → `logEvent`). Unthrottled, a single
|
|
59
|
+
// page load's few hundred local queries turn a handful of MB of rows into GBs
|
|
60
|
+
// of short-lived large-object garbage and OOM the renderer (V8
|
|
61
|
+
// "young object promotion failed"). Coalesce instead: push immediately when
|
|
62
|
+
// idle, then at most once per window, always serializing the LATEST state.
|
|
63
|
+
private static readonly NOTIFY_MIN_INTERVAL_MS = 250;
|
|
64
|
+
private notifyTimer: ReturnType<typeof setTimeout> | null = null;
|
|
65
|
+
private lastNotifyAt = 0;
|
|
66
|
+
/** How many ids a pushed state carries per view; the rest is on demand. */
|
|
67
|
+
private static readonly STATE_IDS_CAP = 200;
|
|
68
|
+
/** devtools numeric hash -> the query's `_00_query` id, for on-demand rows. */
|
|
69
|
+
private hashToQuery = new Map<number, unknown>();
|
|
70
|
+
|
|
71
|
+
/** Shared-tabs snapshot for the panel, wired by Sp00kyClient whenever the
|
|
72
|
+
* feature was REQUESTED (so an inactive/degraded tab still reports why). */
|
|
73
|
+
private tabsInfoProvider: (() => SharedTabsInfo | null) | null = null;
|
|
74
|
+
|
|
75
|
+
setTabsInfoProvider(provider: () => SharedTabsInfo | null): void {
|
|
76
|
+
this.tabsInfoProvider = provider;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Blob cache counters for the panel, wired by Sp00kyClient. */
|
|
80
|
+
private blobInfoProvider: (() => BlobCacheInfo) | null = null;
|
|
81
|
+
|
|
82
|
+
setBlobInfoProvider(provider: () => BlobCacheInfo): void {
|
|
83
|
+
this.blobInfoProvider = provider;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Full local table list (incl. internal `_00_*`), enumerated from the local DB
|
|
87
|
+
// via our own reliable `service.query` — the DevTools panel's page-eval query
|
|
88
|
+
// bridge is unreliable under load, so the panel relies on this instead.
|
|
89
|
+
private localTables: string[] = [];
|
|
90
|
+
private localTablesFetching = false;
|
|
91
|
+
private localTablesAt = 0;
|
|
92
|
+
|
|
93
|
+
// Feature flag admin, backing the panel's Access tab. The local-override
|
|
94
|
+
// store is injected later (`setFeatureFlagOverrides`) because the
|
|
95
|
+
// FeatureFlagModule is built after this service.
|
|
96
|
+
private featureOverrides: LocalOverrideStore | null = null;
|
|
97
|
+
private readonly flagsAdmin: FlagsAdminService;
|
|
24
98
|
|
|
25
99
|
constructor(
|
|
26
|
-
private databaseService:
|
|
100
|
+
private databaseService: LocalStore,
|
|
27
101
|
private remoteDatabaseService: RemoteDatabaseService,
|
|
28
102
|
private logger: Logger,
|
|
29
103
|
private schema: SchemaStructure,
|
|
30
104
|
private authService: AuthService<SchemaStructure>,
|
|
31
105
|
private dataManager?: DataModule<SchemaStructure>
|
|
32
106
|
) {
|
|
107
|
+
this.flagsAdmin = new FlagsAdminService({
|
|
108
|
+
remote: this.remoteDatabaseService,
|
|
109
|
+
local: this.databaseService,
|
|
110
|
+
logger: this.logger,
|
|
111
|
+
currentUserId: () => {
|
|
112
|
+
const id = this.authService.currentUser?.id;
|
|
113
|
+
if (!id) return null;
|
|
114
|
+
return id instanceof RecordId ? encodeRecordId(id) : String(id);
|
|
115
|
+
},
|
|
116
|
+
overrides: () => this.featureOverrides,
|
|
117
|
+
});
|
|
118
|
+
|
|
33
119
|
this.exposeToWindow();
|
|
34
120
|
|
|
35
|
-
//
|
|
121
|
+
// Stay dormant until a devtools consumer announces itself. The extension's
|
|
122
|
+
// page-script posts this once it detects `window.__00__`; the panel can also
|
|
123
|
+
// disconnect to return us to dormant. Until then we skip all serialization.
|
|
124
|
+
if (typeof window !== 'undefined') {
|
|
125
|
+
window.addEventListener('message', (e) => {
|
|
126
|
+
if (e.source !== window) return;
|
|
127
|
+
const type = (e.data as { type?: string } | undefined)?.type;
|
|
128
|
+
if (type === 'SP00KY_DEVTOOLS_CONNECT') {
|
|
129
|
+
this.enabled = true;
|
|
130
|
+
this.refreshLocalTables();
|
|
131
|
+
this.notifyDevTools();
|
|
132
|
+
} else if (type === 'SP00KY_DEVTOOLS_DISCONNECT') {
|
|
133
|
+
this.enabled = false;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Subscribe to auth events. The initial fire-and-forget version fetch (below)
|
|
139
|
+
// races the remote connection; on the free plan the remote DB (SurrealDB
|
|
140
|
+
// Cloud) has no guest access, so `fn::spooky::info()` is only callable once
|
|
141
|
+
// signed in. Re-fetch when auth resolves — until the versions actually land —
|
|
142
|
+
// instead of leaving them 'unavailable' forever.
|
|
36
143
|
this.authService.eventSystem.subscribe(AuthEventTypes.AuthStateChanged, () => {
|
|
37
|
-
this.
|
|
144
|
+
if (this.authService.isAuthenticated && this.backendInfo.versions.ssp === UNAVAILABLE) {
|
|
145
|
+
void this.refreshBackendVersions();
|
|
146
|
+
} else {
|
|
147
|
+
this.notifyDevTools();
|
|
148
|
+
}
|
|
38
149
|
});
|
|
39
150
|
|
|
40
|
-
|
|
151
|
+
// Push state when the local store reports its durability (the open happens
|
|
152
|
+
// during connect, typically before a panel attaches, so this mostly matters
|
|
153
|
+
// for a later bucket switch that loses OPFS).
|
|
154
|
+
this.databaseService.subscribeToStorageHealth?.(() => this.notifyDevTools());
|
|
155
|
+
|
|
156
|
+
// Fire-and-forget backend version discovery; re-push state when it lands.
|
|
157
|
+
void this.refreshBackendVersions();
|
|
158
|
+
|
|
159
|
+
this.logger.debug({ Category: 'sp00ky-client::DevToolsService::init' }, 'Service initialized');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Re-read backend stack info via the `fn::spooky::info()` SurrealQL function
|
|
164
|
+
* over the open remote connection (no HTTP/CORS), then notify the panel.
|
|
165
|
+
* Never throws: on failure the info stays empty/'unavailable'.
|
|
166
|
+
*/
|
|
167
|
+
private async refreshBackendVersions(): Promise<void> {
|
|
168
|
+
try {
|
|
169
|
+
// `RETURN fn::spooky::info()` → one statement result: the /info entity array.
|
|
170
|
+
const result = await this.remoteDatabaseService.query<unknown[]>(
|
|
171
|
+
'RETURN fn::spooky::info()'
|
|
172
|
+
);
|
|
173
|
+
const first = Array.isArray(result) ? result[0] : result;
|
|
174
|
+
this.backendInfo = parseBackendInfo(first);
|
|
175
|
+
} catch (err) {
|
|
176
|
+
this.logger.debug(
|
|
177
|
+
{ err, Category: 'sp00ky-client::DevToolsService::versions' },
|
|
178
|
+
'fn::spooky::info() unavailable; backend versions stay unavailable'
|
|
179
|
+
);
|
|
180
|
+
this.backendInfo = emptyBackendInfo();
|
|
181
|
+
}
|
|
182
|
+
this.notifyDevTools();
|
|
41
183
|
}
|
|
42
184
|
|
|
43
185
|
// Get active queries directly from DataManager (single source of truth)
|
|
@@ -48,21 +190,52 @@ export class DevToolsService implements StreamUpdateReceiver {
|
|
|
48
190
|
const queries = this.dataManager.getActiveQueries();
|
|
49
191
|
queries.forEach((q) => {
|
|
50
192
|
const queryHash = this.hashString(encodeRecordId(q.config.id));
|
|
193
|
+
const createdAt =
|
|
194
|
+
q.config.lastActiveAt instanceof Date
|
|
195
|
+
? q.config.lastActiveAt.getTime()
|
|
196
|
+
: new Date(q.config.lastActiveAt || Date.now()).getTime();
|
|
197
|
+
this.hashToQuery.set(queryHash, q.config.id);
|
|
198
|
+
const localArray = q.config.localArray ?? [];
|
|
199
|
+
const remoteArray = q.config.remoteArray ?? [];
|
|
51
200
|
result.set(queryHash, {
|
|
52
201
|
queryHash,
|
|
53
202
|
status: 'active',
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
203
|
+
// Runtime fetch status, distinct from the `status: 'active'`
|
|
204
|
+
// registration flag above. `fetchStatus` is 'idle' | 'fetching'.
|
|
205
|
+
fetchStatus: q.status,
|
|
206
|
+
isFetching: q.status === 'fetching',
|
|
207
|
+
createdAt,
|
|
208
|
+
// Real last-update time; before the first update it equals createdAt.
|
|
209
|
+
// (Previously Date.now(), which reset the column on every state push.)
|
|
210
|
+
lastUpdate: q.lastUpdatedAt ?? createdAt,
|
|
59
211
|
updateCount: q.updateCount,
|
|
212
|
+
ttl: q.config.ttl,
|
|
60
213
|
query: q.config.surql,
|
|
61
214
|
variables: q.config.params || {},
|
|
62
215
|
dataSize: q.records?.length || 0,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
216
|
+
// Counts and (capped) ids only. The rows themselves used to ride along
|
|
217
|
+
// here: every push then deep-cloned every view's records twice
|
|
218
|
+
// (serialize + postMessage), on a 4k-row client dataset up to four
|
|
219
|
+
// times a second, from inside the ingest call stack. The panel pulls
|
|
220
|
+
// rows on demand through `getQueryRows` instead.
|
|
221
|
+
localCount: localArray.length,
|
|
222
|
+
remoteCount: remoteArray.length,
|
|
223
|
+
localIds: localArray.slice(0, DevToolsService.STATE_IDS_CAP).map(([id]) => id),
|
|
224
|
+
remoteIds: remoteArray.slice(0, DevToolsService.STATE_IDS_CAP).map(([id]) => id),
|
|
225
|
+
idsTruncated:
|
|
226
|
+
localArray.length > DevToolsService.STATE_IDS_CAP ||
|
|
227
|
+
remoteArray.length > DevToolsService.STATE_IDS_CAP,
|
|
228
|
+
// Membership state, so "why is this list empty" is answerable from
|
|
229
|
+
// the panel: is the server's set known, has a non-empty one been seen
|
|
230
|
+
// this session, how many empty reads were ignored.
|
|
231
|
+
membershipKnown: q.config.membershipKnown === true,
|
|
232
|
+
authoritative: q.config.membershipKnown === true,
|
|
233
|
+
viewLost: q.viewLost === true,
|
|
234
|
+
serverState: q.serverState ?? null,
|
|
235
|
+
// Detailed per-phase processing-time breakdown (SSP sub-phases, local/
|
|
236
|
+
// remote record fetch, frontend reconcile, registration). Flows to both
|
|
237
|
+
// the DevTools panel and the MCP (which returns activeQueries verbatim).
|
|
238
|
+
timings: this.dataManager.phaseTimings(q),
|
|
66
239
|
});
|
|
67
240
|
});
|
|
68
241
|
return result;
|
|
@@ -70,7 +243,7 @@ export class DevToolsService implements StreamUpdateReceiver {
|
|
|
70
243
|
|
|
71
244
|
public onQueryInitialized(payload: any) {
|
|
72
245
|
this.logger.debug(
|
|
73
|
-
{ payload, Category: '
|
|
246
|
+
{ payload, Category: 'sp00ky-client::DevToolsService::onQueryInitialized' },
|
|
74
247
|
'QueryInitialized'
|
|
75
248
|
);
|
|
76
249
|
const queryHash = this.hashString(payload.queryId.toString());
|
|
@@ -87,7 +260,7 @@ export class DevToolsService implements StreamUpdateReceiver {
|
|
|
87
260
|
this.logger.debug(
|
|
88
261
|
{
|
|
89
262
|
id: payload.queryId?.toString(),
|
|
90
|
-
Category: '
|
|
263
|
+
Category: 'sp00ky-client::DevToolsService::onQueryUpdated',
|
|
91
264
|
},
|
|
92
265
|
'QueryUpdated'
|
|
93
266
|
);
|
|
@@ -95,18 +268,28 @@ export class DevToolsService implements StreamUpdateReceiver {
|
|
|
95
268
|
|
|
96
269
|
this.addEvent('QUERY_UPDATED', {
|
|
97
270
|
queryHash,
|
|
98
|
-
|
|
271
|
+
recordCount: Array.isArray(payload.records) ? payload.records.length : 0,
|
|
99
272
|
});
|
|
100
273
|
this.notifyDevTools();
|
|
101
274
|
}
|
|
102
275
|
|
|
103
276
|
public onStreamUpdate(update: StreamUpdate) {
|
|
277
|
+
// A synthetic re-materialize is not an ingest (DataModule.scheduleRematerialize).
|
|
278
|
+
if (update.synthetic) return;
|
|
104
279
|
this.logger.debug(
|
|
105
|
-
{ update, Category: '
|
|
280
|
+
{ queryHash: update.queryHash, Category: 'sp00ky-client::DevToolsService::onStreamUpdate' },
|
|
106
281
|
'StreamUpdate'
|
|
107
282
|
);
|
|
283
|
+
// Counts and timings, not the `localArray` itself: that is one [id, version]
|
|
284
|
+
// pair per row of the view, serialized on every single update.
|
|
108
285
|
this.addEvent('STREAM_UPDATE', {
|
|
109
|
-
|
|
286
|
+
queryHash: update.queryHash,
|
|
287
|
+
op: update.op,
|
|
288
|
+
localCount: update.localArray?.length ?? 0,
|
|
289
|
+
materializationTimeMs: update.materializationTimeMs,
|
|
290
|
+
storeApplyMs: update.storeApplyMs,
|
|
291
|
+
circuitStepMs: update.circuitStepMs,
|
|
292
|
+
transformMs: update.transformMs,
|
|
110
293
|
});
|
|
111
294
|
this.notifyDevTools();
|
|
112
295
|
}
|
|
@@ -116,8 +299,10 @@ export class DevToolsService implements StreamUpdateReceiver {
|
|
|
116
299
|
payloads.forEach((p) => {
|
|
117
300
|
this.addEvent('MUTATION_REQUEST_EXECUTION', {
|
|
118
301
|
mutation: {
|
|
119
|
-
type: 'create',
|
|
120
|
-
|
|
302
|
+
type: p.type ?? 'create',
|
|
303
|
+
// Field names only; a payload body (a PGN, a document) is not
|
|
304
|
+
// something to clone on every write.
|
|
305
|
+
fields: 'data' in p && p.data && typeof p.data === 'object' ? Object.keys(p.data) : [],
|
|
121
306
|
selector: encodeRecordId(p.record_id),
|
|
122
307
|
},
|
|
123
308
|
});
|
|
@@ -142,6 +327,8 @@ export class DevToolsService implements StreamUpdateReceiver {
|
|
|
142
327
|
}
|
|
143
328
|
|
|
144
329
|
private addEvent(eventType: string, payload: any) {
|
|
330
|
+
// No consumer attached → skip recording (and the recursive serialize it does).
|
|
331
|
+
if (!this.enabled) return;
|
|
145
332
|
this.eventsHistory.push({
|
|
146
333
|
id: this.eventIdCounter++,
|
|
147
334
|
timestamp: Date.now(),
|
|
@@ -151,7 +338,55 @@ export class DevToolsService implements StreamUpdateReceiver {
|
|
|
151
338
|
if (this.eventsHistory.length > 100) this.eventsHistory.shift();
|
|
152
339
|
}
|
|
153
340
|
|
|
154
|
-
|
|
341
|
+
/** Unwrap a SurrealDB `INFO FOR DB` result to its `{ tables, ... }` object. */
|
|
342
|
+
private unwrapInfo(res: any): any {
|
|
343
|
+
if (!Array.isArray(res) || !res[0]) return null;
|
|
344
|
+
const first = res[0];
|
|
345
|
+
if (first && typeof first === 'object' && 'result' in first) return first.result;
|
|
346
|
+
if (Array.isArray(first)) return first[0];
|
|
347
|
+
return first;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Refresh the cached full local-table list from `INFO FOR DB`. Fire-and-forget
|
|
352
|
+
* and throttled — called from getState() so the panel gets every table
|
|
353
|
+
* (including internal `_00_*`) without running its own (flaky) queries.
|
|
354
|
+
*/
|
|
355
|
+
private refreshLocalTables(): void {
|
|
356
|
+
if (this.localTablesFetching) return;
|
|
357
|
+
const now = Date.now();
|
|
358
|
+
if (now - this.localTablesAt < 30_000) return;
|
|
359
|
+
this.localTablesFetching = true;
|
|
360
|
+
void this.databaseService
|
|
361
|
+
.query<any>('INFO FOR DB')
|
|
362
|
+
.then((res) => {
|
|
363
|
+
const info = this.unwrapInfo(res);
|
|
364
|
+
this.localTablesAt = Date.now();
|
|
365
|
+
if (info && info.tables) {
|
|
366
|
+
// The circuit snapshot table holds a BLOB, not JSON rows; the
|
|
367
|
+
// explorer cannot render it and has nothing to show for it.
|
|
368
|
+
const names = Object.keys(info.tables).filter((n) => n !== '_00_circuit_snapshot');
|
|
369
|
+
const changed =
|
|
370
|
+
names.length !== this.localTables.length ||
|
|
371
|
+
names.some((n, i) => n !== this.localTables[i]);
|
|
372
|
+
this.localTables = names;
|
|
373
|
+
if (changed) this.notifyDevTools();
|
|
374
|
+
}
|
|
375
|
+
})
|
|
376
|
+
.catch(() => {
|
|
377
|
+
// Ignore — fall back to the declared app schema below.
|
|
378
|
+
})
|
|
379
|
+
.finally(() => {
|
|
380
|
+
this.localTablesFetching = false;
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
private getState(opts: { refreshTables?: boolean } = {}) {
|
|
385
|
+
// The local-table list (`INFO FOR DB`, a local round trip) is refreshed on
|
|
386
|
+
// an explicit pull only, never by the push path: pushes follow every sync
|
|
387
|
+
// event, and a local query per push competed with the app's own writes for
|
|
388
|
+
// the single local op queue.
|
|
389
|
+
if (opts.refreshTables) this.refreshLocalTables();
|
|
155
390
|
return this.serializeForDevTools({
|
|
156
391
|
eventsHistory: [...this.eventsHistory],
|
|
157
392
|
activeQueries: Object.fromEntries(this.getActiveQueries()),
|
|
@@ -160,24 +395,148 @@ export class DevToolsService implements StreamUpdateReceiver {
|
|
|
160
395
|
userId: this.authService.currentUser?.id,
|
|
161
396
|
},
|
|
162
397
|
version: this.version,
|
|
398
|
+
versions: {
|
|
399
|
+
frontend: {
|
|
400
|
+
core: CORE_VERSION,
|
|
401
|
+
wasm: WASM_VERSION,
|
|
402
|
+
surrealdb: SURREAL_VERSION,
|
|
403
|
+
},
|
|
404
|
+
backend: this.backendInfo.versions,
|
|
405
|
+
entities: this.backendInfo.entities,
|
|
406
|
+
},
|
|
163
407
|
database: {
|
|
164
|
-
|
|
408
|
+
// Prefer the live local-table list (includes internal `_00_*`); fall
|
|
409
|
+
// back to the declared app schema until the first enumeration lands.
|
|
410
|
+
tables: this.localTables.length
|
|
411
|
+
? this.localTables
|
|
412
|
+
: this.schema.tables.map((t) => t.name),
|
|
165
413
|
tableData: {},
|
|
414
|
+
// Which backend answers "Local". The Database explorer labels its source
|
|
415
|
+
// picker with it and explains translation failures against `sqlite`,
|
|
416
|
+
// whose SurrealQL vocabulary is a bounded subset.
|
|
417
|
+
engine: this.databaseService.engineKind ?? 'custom',
|
|
418
|
+
// Durability of the local store. `fallback: true` means persistence was
|
|
419
|
+
// requested but the dataset is actually sitting in RAM.
|
|
420
|
+
storage: this.databaseService.storageHealth ?? { status: 'unknown', fallback: false },
|
|
421
|
+
// Shared-tabs role state (null when the feature is off / fell back).
|
|
422
|
+
tabs: this.tabsInfoProvider?.() ?? null,
|
|
166
423
|
},
|
|
167
424
|
});
|
|
168
425
|
}
|
|
169
426
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
427
|
+
/**
|
|
428
|
+
* Full storage diagnostics for the DevTools Storage tab. Every section is
|
|
429
|
+
* gathered independently and failures land in that section's `error` field,
|
|
430
|
+
* so one broken source (a mid-switch worker, a browser without OPFS) never
|
|
431
|
+
* blanks the whole panel.
|
|
432
|
+
*/
|
|
433
|
+
public async getStorageInfo(opts?: { tableCounts?: boolean }): Promise<StorageInfo> {
|
|
434
|
+
const nav = typeof navigator !== 'undefined' ? navigator : undefined;
|
|
435
|
+
|
|
436
|
+
const info: StorageInfo = {
|
|
437
|
+
at: Date.now(),
|
|
438
|
+
engine: {
|
|
439
|
+
kind: this.databaseService.engineKind ?? 'custom',
|
|
440
|
+
store: this.databaseService.getConfig()?.store ?? 'memory',
|
|
441
|
+
bucketId: this.databaseService.currentBucketId,
|
|
442
|
+
},
|
|
443
|
+
health: this.databaseService.storageHealth ?? { status: 'unknown', fallback: false },
|
|
444
|
+
tabs: this.tabsInfoProvider?.() ?? null,
|
|
445
|
+
browser: {},
|
|
446
|
+
opfs: { supported: false, entries: [], totalBytes: 0, truncated: false },
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
try {
|
|
450
|
+
if (nav?.storage?.estimate) {
|
|
451
|
+
const est = await nav.storage.estimate();
|
|
452
|
+
info.browser.usage = est.usage;
|
|
453
|
+
info.browser.quota = est.quota;
|
|
454
|
+
// Chrome-only per-storage-system breakdown; absent elsewhere.
|
|
455
|
+
const details = (est as any).usageDetails;
|
|
456
|
+
if (details && typeof details === 'object') info.browser.usageDetails = details;
|
|
457
|
+
}
|
|
458
|
+
if (nav?.storage?.persisted) {
|
|
459
|
+
info.browser.persisted = await nav.storage.persisted();
|
|
460
|
+
}
|
|
461
|
+
} catch (e) {
|
|
462
|
+
info.browser.error = e instanceof Error ? e.message : String(e);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
info.opfs = await walkOpfs();
|
|
466
|
+
|
|
467
|
+
try {
|
|
468
|
+
info.blobs = this.blobInfoProvider?.();
|
|
469
|
+
} catch (e) {
|
|
470
|
+
this.logger.warn(
|
|
471
|
+
{ err: e, Category: 'sp00ky-client::DevToolsService::getStorageInfo' },
|
|
472
|
+
'Blob cache diagnostics failed'
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
const stats = (globalThis as any).__sqliteStats;
|
|
477
|
+
if (stats && typeof stats === 'object') {
|
|
478
|
+
info.sqliteStats = { ...stats, byType: { ...(stats.byType ?? {}) } };
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
try {
|
|
482
|
+
info.engineDiagnostics = await this.databaseService.getStorageDiagnostics?.(opts);
|
|
483
|
+
} catch (e) {
|
|
484
|
+
this.logger.warn(
|
|
485
|
+
{ err: e, Category: 'sp00ky-client::DevToolsService::getStorageInfo' },
|
|
486
|
+
'Engine storage diagnostics failed'
|
|
179
487
|
);
|
|
180
488
|
}
|
|
489
|
+
|
|
490
|
+
return this.serializeForDevTools(info);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/** Ask the browser to exempt this origin's storage from eviction. */
|
|
494
|
+
public async requestPersistentStorage(): Promise<{ granted: boolean }> {
|
|
495
|
+
try {
|
|
496
|
+
const granted = (await navigator.storage?.persist?.()) ?? false;
|
|
497
|
+
return { granted };
|
|
498
|
+
} catch {
|
|
499
|
+
return { granted: false };
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Request a state push. Coalesced (see {@link NOTIFY_MIN_INTERVAL_MS}): the
|
|
505
|
+
* first call after an idle period pushes straight away so the panel stays
|
|
506
|
+
* responsive, and any calls during the window collapse into ONE trailing push
|
|
507
|
+
* that serializes the state as of the flush, not as of the request. Callers
|
|
508
|
+
* stay fire-and-forget.
|
|
509
|
+
*/
|
|
510
|
+
private notifyDevTools() {
|
|
511
|
+
// No consumer attached → no getState() serialization, no postMessage broadcast.
|
|
512
|
+
if (!this.enabled) return;
|
|
513
|
+
if (typeof window === 'undefined') return;
|
|
514
|
+
// A trailing push is already queued; it will carry this change too.
|
|
515
|
+
if (this.notifyTimer !== null) return;
|
|
516
|
+
|
|
517
|
+
// Always a macrotask, never inline: this is called from inside the ingest
|
|
518
|
+
// and mutation call stacks (onStreamUpdate / onMutation), i.e. inside the
|
|
519
|
+
// `await db.create(...)` the app is waiting on. A push that serializes the
|
|
520
|
+
// state right there charged every write for the panel's refresh.
|
|
521
|
+
const waited = Date.now() - this.lastNotifyAt;
|
|
522
|
+
const delay = Math.max(0, DevToolsService.NOTIFY_MIN_INTERVAL_MS - waited);
|
|
523
|
+
this.notifyTimer = setTimeout(() => {
|
|
524
|
+
this.notifyTimer = null;
|
|
525
|
+
// Still gated on `enabled`: the panel may have disconnected while queued.
|
|
526
|
+
if (this.enabled) this.flushNotify();
|
|
527
|
+
}, delay);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
private flushNotify() {
|
|
531
|
+
this.lastNotifyAt = Date.now();
|
|
532
|
+
window.postMessage(
|
|
533
|
+
{
|
|
534
|
+
type: 'SP00KY_STATE_CHANGED',
|
|
535
|
+
source: 'sp00ky-devtools-page',
|
|
536
|
+
state: this.getState(),
|
|
537
|
+
},
|
|
538
|
+
'*'
|
|
539
|
+
);
|
|
181
540
|
}
|
|
182
541
|
|
|
183
542
|
private serializeForDevTools(data: any, seen = new WeakSet<object>()): any {
|
|
@@ -218,6 +577,10 @@ export class DevToolsService implements StreamUpdateReceiver {
|
|
|
218
577
|
const result: Record<string, any> = {};
|
|
219
578
|
for (const key in data) {
|
|
220
579
|
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
580
|
+
// Skip absent optional fields: recursing them would emit the STRING
|
|
581
|
+
// 'undefined' (the top-level mapping below), which panels then have
|
|
582
|
+
// to filter back out (see 3d84fe8a).
|
|
583
|
+
if (data[key] === undefined) continue;
|
|
221
584
|
result[key] = this.serializeForDevTools(data[key], seen);
|
|
222
585
|
}
|
|
223
586
|
}
|
|
@@ -227,15 +590,54 @@ export class DevToolsService implements StreamUpdateReceiver {
|
|
|
227
590
|
return data;
|
|
228
591
|
}
|
|
229
592
|
|
|
593
|
+
/**
|
|
594
|
+
* Hand the FeatureFlagModule to the Access tab so it can read and write local
|
|
595
|
+
* overrides. Called from `Sp00kyClient` once both are constructed; until then
|
|
596
|
+
* the override methods are no-ops that report an empty map.
|
|
597
|
+
*/
|
|
598
|
+
public setFeatureFlagOverrides(store: LocalOverrideStore): void {
|
|
599
|
+
this.featureOverrides = store;
|
|
600
|
+
}
|
|
601
|
+
|
|
230
602
|
private exposeToWindow() {
|
|
231
603
|
if (typeof window !== 'undefined') {
|
|
232
|
-
(window as any).
|
|
604
|
+
(window as any).__00__ = {
|
|
233
605
|
version: this.version,
|
|
234
|
-
getState: () => this.getState(),
|
|
606
|
+
getState: () => this.getState({ refreshTables: true }),
|
|
607
|
+
// The rows of ONE view, on demand. The pushed state carries counts and
|
|
608
|
+
// capped ids only (see getActiveQueries); the panel's Data tab and the
|
|
609
|
+
// MCP fetch the rows here when somebody actually looks at them.
|
|
610
|
+
getQueryRows: (queryHash: number) => {
|
|
611
|
+
const id = this.hashToQuery.get(Number(queryHash));
|
|
612
|
+
const q = id !== undefined ? this.dataManager?.getQueryById(id as any) : undefined;
|
|
613
|
+
if (!q) return null;
|
|
614
|
+
return this.serializeForDevTools({
|
|
615
|
+
queryHash: Number(queryHash),
|
|
616
|
+
data: q.records,
|
|
617
|
+
localArray: q.config.localArray,
|
|
618
|
+
remoteArray: q.config.remoteArray,
|
|
619
|
+
});
|
|
620
|
+
},
|
|
621
|
+
// ---- Feature flags (Access tab) --------------------------------
|
|
622
|
+
// Remote reads/writes are admin-gated by SurrealDB, not here: a
|
|
623
|
+
// non-admin gets an empty flag list, and the `fn::feature::*` calls
|
|
624
|
+
// are denied outright. The override methods are purely local and
|
|
625
|
+
// work signed out.
|
|
626
|
+
getFlags: () => this.flagsAdmin.getFlags(),
|
|
627
|
+
setFlagEnabled: (key: string, enabled: boolean) =>
|
|
628
|
+
this.flagsAdmin.setFlagEnabled(key, enabled),
|
|
629
|
+
setFlagUserVariant: (key: string, variant: string, remove: boolean, userId?: string) =>
|
|
630
|
+
this.flagsAdmin.setFlagUserVariant(key, variant, remove, userId),
|
|
631
|
+
setLocalFlagOverride: (key: string, variant: string | null, payload?: unknown) =>
|
|
632
|
+
this.flagsAdmin.setLocalFlagOverride(key, variant, payload),
|
|
633
|
+
clearLocalFlagOverrides: () => this.flagsAdmin.clearLocalFlagOverrides(),
|
|
235
634
|
clearHistory: () => {
|
|
236
635
|
this.eventsHistory = [];
|
|
237
636
|
this.notifyDevTools();
|
|
238
637
|
},
|
|
638
|
+
refreshVersions: () => this.refreshBackendVersions(),
|
|
639
|
+
getStorageInfo: (opts?: { tableCounts?: boolean }) => this.getStorageInfo(opts),
|
|
640
|
+
requestPersistentStorage: () => this.requestPersistentStorage(),
|
|
239
641
|
getTableData: async (tableName: string) => {
|
|
240
642
|
try {
|
|
241
643
|
// Returns the first statement result as T.
|
|
@@ -270,7 +672,7 @@ export class DevToolsService implements StreamUpdateReceiver {
|
|
|
270
672
|
return this.serializeForDevTools(records) || [];
|
|
271
673
|
} catch (e) {
|
|
272
674
|
this.logger.error(
|
|
273
|
-
{ err: e, Category: '
|
|
675
|
+
{ err: e, Category: 'sp00ky-client::DevToolsService::exposeToWindow' },
|
|
274
676
|
'Failed to get table data'
|
|
275
677
|
);
|
|
276
678
|
return [];
|
|
@@ -299,7 +701,7 @@ export class DevToolsService implements StreamUpdateReceiver {
|
|
|
299
701
|
runQuery: async (query: string, target: 'local' | 'remote' = 'local') => {
|
|
300
702
|
try {
|
|
301
703
|
this.logger.debug(
|
|
302
|
-
{ query, target, Category: '
|
|
704
|
+
{ query, target, Category: 'sp00ky-client::DevToolsService::runQuery' },
|
|
303
705
|
'Running query (START)'
|
|
304
706
|
);
|
|
305
707
|
const service = target === 'remote' ? this.remoteDatabaseService : this.databaseService;
|
|
@@ -314,7 +716,7 @@ export class DevToolsService implements StreamUpdateReceiver {
|
|
|
314
716
|
time: queryTime,
|
|
315
717
|
resultType: typeof result,
|
|
316
718
|
isArray: Array.isArray(result),
|
|
317
|
-
Category: '
|
|
719
|
+
Category: 'sp00ky-client::DevToolsService::runQuery',
|
|
318
720
|
},
|
|
319
721
|
'Database returned result'
|
|
320
722
|
);
|
|
@@ -328,7 +730,7 @@ export class DevToolsService implements StreamUpdateReceiver {
|
|
|
328
730
|
{
|
|
329
731
|
serializeTime,
|
|
330
732
|
serializedLength: JSON.stringify(serialized).length,
|
|
331
|
-
Category: '
|
|
733
|
+
Category: 'sp00ky-client::DevToolsService::runQuery',
|
|
332
734
|
},
|
|
333
735
|
'Serialization complete'
|
|
334
736
|
);
|
|
@@ -340,7 +742,7 @@ export class DevToolsService implements StreamUpdateReceiver {
|
|
|
340
742
|
};
|
|
341
743
|
} catch (e: any) {
|
|
342
744
|
this.logger.error(
|
|
343
|
-
{ err: e, query, target, Category: '
|
|
745
|
+
{ err: e, query, target, Category: 'sp00ky-client::DevToolsService::runQuery' },
|
|
344
746
|
'Query execution failed'
|
|
345
747
|
);
|
|
346
748
|
// Ensure we always return a string for error
|
|
@@ -353,12 +755,15 @@ export class DevToolsService implements StreamUpdateReceiver {
|
|
|
353
755
|
|
|
354
756
|
window.postMessage(
|
|
355
757
|
{
|
|
356
|
-
type: '
|
|
357
|
-
source: '
|
|
758
|
+
type: 'SP00KY_DETECTED',
|
|
759
|
+
source: 'sp00ky-devtools-page',
|
|
358
760
|
data: { version: this.version, detected: true },
|
|
359
761
|
},
|
|
360
762
|
'*'
|
|
361
763
|
);
|
|
764
|
+
|
|
765
|
+
// Dispatch custom event so the devtools page-script can detect late initialization
|
|
766
|
+
window.dispatchEvent(new CustomEvent('sp00ky:init'));
|
|
362
767
|
}
|
|
363
768
|
}
|
|
364
769
|
}
|