@spooky-sync/core 1.0.0-beta.1 → 1.0.0-beta.11

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.
Files changed (55) hide show
  1. package/AGENTS.md +4 -3
  2. package/dist/index.d.ts +170 -9
  3. package/dist/index.js +5398 -2968
  4. package/dist/rows-worker.d.ts +1 -0
  5. package/dist/rows-worker.js +2731 -0
  6. package/dist/sqlite-open.js +1 -1
  7. package/dist/sqlite-worker.js +1 -1
  8. package/dist/types.d.ts +131 -13
  9. package/package.json +9 -4
  10. package/scripts/check-worker-entries.mjs +15 -2
  11. package/skills/sp00ky-core/SKILL.md +2 -0
  12. package/src/client/bucket-handle.ts +21 -1
  13. package/src/client/eager-paint.test.ts +82 -0
  14. package/src/client/services.ts +4 -1
  15. package/src/client/sp00ky-client.test.ts +143 -1
  16. package/src/client/sp00ky-client.ts +158 -19
  17. package/src/index.ts +9 -0
  18. package/src/kernel/effects.ts +12 -2
  19. package/src/kernel/interpreter.test.ts +17 -0
  20. package/src/kernel/interpreter.ts +5 -2
  21. package/src/modules/channel/hub.test.ts +223 -0
  22. package/src/modules/channel/hub.ts +355 -0
  23. package/src/modules/channel/index.ts +358 -14
  24. package/src/modules/channel/room.test.ts +340 -0
  25. package/src/modules/channel/room.ts +367 -0
  26. package/src/modules/channel/rooms.fixture.ts +383 -0
  27. package/src/modules/channel/share.test.ts +535 -0
  28. package/src/modules/channel/webrtc.ts +2 -2
  29. package/src/modules/devtools/storage-info.ts +4 -3
  30. package/src/query/materialize.saga.test.ts +16 -0
  31. package/src/query/materialize.saga.ts +7 -26
  32. package/src/query/materialize.ts +79 -3
  33. package/src/query/register.saga.test.ts +61 -0
  34. package/src/query/register.saga.ts +39 -2
  35. package/src/services/database/cache-engine.ts +17 -3
  36. package/src/services/database/engine-factory.ts +7 -0
  37. package/src/services/database/index.ts +1 -0
  38. package/src/services/database/rows-cache-engine.test.ts +1584 -0
  39. package/src/services/database/rows-cache-engine.ts +1203 -0
  40. package/src/services/database/rows-exec.integration.test.ts +589 -0
  41. package/src/services/database/rows-exec.ts +1027 -0
  42. package/src/services/database/rows-prewarm.ts +251 -0
  43. package/src/services/database/rows-store.test.ts +635 -0
  44. package/src/services/database/rows-store.ts +1208 -0
  45. package/src/services/database/rows-transport.fixture.ts +151 -0
  46. package/src/services/database/rows-worker.ts +607 -0
  47. package/src/services/database/rows-yield.test.ts +141 -0
  48. package/src/services/database/rows-yield.ts +92 -0
  49. package/src/services/database/sqlite-cache-engine.test.ts +22 -1
  50. package/src/services/database/sqlite-cache-engine.ts +55 -34
  51. package/src/services/database/sqlite-transport.ts +7 -5
  52. package/src/services/tabs/support.ts +6 -4
  53. package/src/types.ts +41 -6
  54. package/tsdown.config.ts +42 -1
  55. package/vitest.config.ts +4 -0
package/tsdown.config.ts CHANGED
@@ -61,15 +61,41 @@ const versionDefinePlugin = {
61
61
  const workerUrlPlugin = {
62
62
  name: 'sp00ky-worker-url',
63
63
  transform(code: string) {
64
- if (!code.includes('sqlite-worker.ts') && !code.includes('tabs-broker-worker.ts')) return null;
64
+ if (
65
+ !code.includes('sqlite-worker.ts') &&
66
+ !code.includes('rows-worker.ts') &&
67
+ !code.includes('tabs-broker-worker.ts')
68
+ ) {
69
+ return null;
70
+ }
65
71
  return code
66
72
  .split('sqlite-worker.ts')
67
73
  .join('sqlite-worker.js')
74
+ .split('rows-worker.ts')
75
+ .join('rows-worker.js')
68
76
  .split('tabs-broker-worker.ts')
69
77
  .join('tabs-broker-worker.js');
70
78
  },
71
79
  };
72
80
 
81
+ // V8 compiles a function the first time it is called, on the thread calling
82
+ // it. `//# allFunctionsCalledOnLoad` as a file's FIRST line (Chrome 136+) has
83
+ // the whole file compiled while it loads, off that thread, and kept in the
84
+ // code cache. Only for the row store's worker: a small file of which every
85
+ // function runs within its first requests, and which a page is waiting for.
86
+ // Measured: 0.6 to 1.5 ms off the worker's first `open`. An app's bundler
87
+ // that minifies the worker drops the comment; the docs say how to keep it.
88
+ const COMPILE_HINT = '//# allFunctionsCalledOnLoad\n';
89
+ const compileHintPlugin = {
90
+ name: 'sp00ky-compile-hint',
91
+ generateBundle(_options: unknown, bundle: Record<string, { type: string; code?: string }>) {
92
+ for (const [name, file] of Object.entries(bundle)) {
93
+ if (name !== 'rows-worker.js') continue;
94
+ if (file.type === 'chunk' && typeof file.code === 'string' && !file.code.startsWith(COMPILE_HINT)) file.code = COMPILE_HINT + file.code;
95
+ }
96
+ },
97
+ };
98
+
73
99
  export default defineConfig([
74
100
  {
75
101
  // `sqlite-worker` is emitted at `dist/sqlite-worker.js` (top level, NOT under
@@ -120,4 +146,19 @@ export default defineConfig([
120
146
  },
121
147
  plugins: [versionDefinePlugin],
122
148
  },
149
+ // The row store's worker (`localEngine: 'rows'`), at `dist/rows-worker.js`
150
+ // like the SQLite one. A build of its own so the file holds everything the
151
+ // worker runs and nothing else: the compile hint on its first line then
152
+ // covers the store and its queries, and no page ever loads hinted code.
153
+ {
154
+ entry: { 'rows-worker': 'src/services/database/rows-worker.ts' },
155
+ format: ['esm'],
156
+ dts: true,
157
+ clean: false,
158
+ hash: false,
159
+ outputOptions: {
160
+ chunkFileNames: (chunk: { name: string }) => (chunk.name === 'rows-worker.d' ? '[name].js' : 'rows-worker-[name].js'),
161
+ },
162
+ plugins: [versionDefinePlugin, compileHintPlugin],
163
+ },
123
164
  ]);
package/vitest.config.ts CHANGED
@@ -3,6 +3,9 @@ import { defineConfig } from 'vitest/config';
3
3
  // Thresholds start at the numbers the suite hits today and are ratcheted per
4
4
  // directory as the saga core lands (see the plan's commit 10). Exclusions:
5
5
  // *.fixture.ts / src/testing/** test-only harness code
6
+ // rows-worker.ts runs inside a Worker (OPFS sync access handles +
7
+ // Web Locks); its ops are `handleRowsOp`, which
8
+ // the engine tests run in-process
6
9
  // sqlite-worker.ts runs inside a Worker (sqlite-wasm + OPFS +
7
10
  // postMessage globals); covered by the sqlite
8
11
  // integration tests and the build check
@@ -25,6 +28,7 @@ export default defineConfig({
25
28
  'src/**/*.fixture.ts',
26
29
  'src/testing/**',
27
30
  'src/services/database/sqlite-worker.ts',
31
+ 'src/services/database/rows-worker.ts',
28
32
  'src/client/services.ts',
29
33
  ],
30
34
  thresholds: {