@spooky-sync/core 0.0.1-canary.9 → 0.0.1-canary.91

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 (65) hide show
  1. package/AGENTS.md +56 -0
  2. package/dist/index.d.ts +907 -339
  3. package/dist/index.js +2837 -402
  4. package/dist/otel/index.d.ts +21 -0
  5. package/dist/otel/index.js +86 -0
  6. package/dist/types.d.ts +543 -0
  7. package/package.json +39 -9
  8. package/skills/sp00ky-core/SKILL.md +258 -0
  9. package/skills/sp00ky-core/references/auth.md +98 -0
  10. package/skills/sp00ky-core/references/config.md +76 -0
  11. package/src/build-globals.d.ts +12 -0
  12. package/src/events/events.test.ts +2 -1
  13. package/src/events/index.ts +3 -0
  14. package/src/index.ts +9 -2
  15. package/src/modules/auth/events/index.ts +2 -1
  16. package/src/modules/auth/index.ts +59 -20
  17. package/src/modules/cache/index.ts +41 -29
  18. package/src/modules/cache/types.ts +2 -2
  19. package/src/modules/crdt/crdt-field.ts +281 -0
  20. package/src/modules/crdt/crdt-hydration.test.ts +206 -0
  21. package/src/modules/crdt/index.ts +352 -0
  22. package/src/modules/data/data.status.test.ts +108 -0
  23. package/src/modules/data/index.ts +732 -109
  24. package/src/modules/data/window-query.test.ts +52 -0
  25. package/src/modules/data/window-query.ts +130 -0
  26. package/src/modules/devtools/index.ts +115 -21
  27. package/src/modules/devtools/versions.test.ts +74 -0
  28. package/src/modules/devtools/versions.ts +81 -0
  29. package/src/modules/feature-flag/index.ts +166 -0
  30. package/src/modules/ref-tables.test.ts +66 -0
  31. package/src/modules/ref-tables.ts +69 -0
  32. package/src/modules/sync/engine.ts +101 -37
  33. package/src/modules/sync/events/index.ts +9 -2
  34. package/src/modules/sync/queue/queue-down.ts +5 -4
  35. package/src/modules/sync/queue/queue-up.ts +14 -13
  36. package/src/modules/sync/scheduler.ts +40 -3
  37. package/src/modules/sync/sync.ts +893 -59
  38. package/src/modules/sync/utils.test.ts +269 -2
  39. package/src/modules/sync/utils.ts +182 -17
  40. package/src/otel/index.ts +127 -0
  41. package/src/services/database/database.ts +11 -11
  42. package/src/services/database/events/index.ts +2 -1
  43. package/src/services/database/local-migrator.ts +21 -21
  44. package/src/services/database/local.test.ts +33 -0
  45. package/src/services/database/local.ts +192 -32
  46. package/src/services/database/remote.ts +13 -13
  47. package/src/services/logger/index.ts +6 -101
  48. package/src/services/persistence/localstorage.ts +2 -2
  49. package/src/services/persistence/resilient.ts +41 -0
  50. package/src/services/persistence/surrealdb.ts +9 -9
  51. package/src/services/stream-processor/index.ts +248 -37
  52. package/src/services/stream-processor/permissions.test.ts +47 -0
  53. package/src/services/stream-processor/permissions.ts +53 -0
  54. package/src/services/stream-processor/stream-processor.batch.test.ts +136 -0
  55. package/src/services/stream-processor/stream-processor.test.ts +1 -1
  56. package/src/services/stream-processor/wasm-types.ts +18 -2
  57. package/src/sp00ky.auth-order.test.ts +65 -0
  58. package/src/sp00ky.ts +648 -0
  59. package/src/types.ts +192 -15
  60. package/src/utils/index.ts +35 -13
  61. package/src/utils/parser.ts +3 -2
  62. package/src/utils/surql.ts +24 -15
  63. package/src/utils/withRetry.test.ts +1 -1
  64. package/tsdown.config.ts +55 -1
  65. package/src/spooky.ts +0 -392
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spooky-sync/core",
3
- "version": "0.0.1-canary.9",
3
+ "version": "0.0.1-canary.91",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -8,6 +8,10 @@
8
8
  ".": {
9
9
  "types": "./dist/index.d.ts",
10
10
  "import": "./dist/index.js"
11
+ },
12
+ "./otel": {
13
+ "types": "./dist/otel/index.d.ts",
14
+ "import": "./dist/otel/index.js"
11
15
  }
12
16
  },
13
17
  "scripts": {
@@ -18,24 +22,50 @@
18
22
  },
19
23
  "repository": {
20
24
  "type": "git",
21
- "url": "https://github.com/mono424/spooky.git",
25
+ "url": "https://github.com/mono424/sp00ky.git",
22
26
  "directory": "packages/core"
23
27
  },
28
+ "keywords": [
29
+ "surrealdb",
30
+ "local-first",
31
+ "sync",
32
+ "tanstack-intent"
33
+ ],
24
34
  "publishConfig": {
25
35
  "access": "public"
26
36
  },
27
- "dependencies": {
37
+ "peerDependencies": {
28
38
  "@opentelemetry/api": "^1.9.0",
29
39
  "@opentelemetry/exporter-logs-otlp-proto": "^0.211.0",
30
- "@opentelemetry/resources": "^2.5.0",
40
+ "@opentelemetry/resources": "^2.6.0",
31
41
  "@opentelemetry/sdk-logs": "^0.211.0",
32
- "@opentelemetry/semantic-conventions": "^1.39.0",
33
- "@spooky-sync/query-builder": "workspace:*",
34
- "@spooky-sync/ssp-wasm": "workspace:*",
35
- "@surrealdb/wasm": "^3.0.0",
42
+ "@opentelemetry/semantic-conventions": "^1.39.0"
43
+ },
44
+ "peerDependenciesMeta": {
45
+ "@opentelemetry/api": {
46
+ "optional": true
47
+ },
48
+ "@opentelemetry/exporter-logs-otlp-proto": {
49
+ "optional": true
50
+ },
51
+ "@opentelemetry/resources": {
52
+ "optional": true
53
+ },
54
+ "@opentelemetry/sdk-logs": {
55
+ "optional": true
56
+ },
57
+ "@opentelemetry/semantic-conventions": {
58
+ "optional": true
59
+ }
60
+ },
61
+ "dependencies": {
62
+ "@spooky-sync/query-builder": "0.0.1-canary.91",
63
+ "@spooky-sync/ssp-wasm": "0.0.1-canary.91",
64
+ "@surrealdb/wasm": "^3.0.3",
36
65
  "fast-json-patch": "^3.1.1",
66
+ "loro-crdt": "^1.5.6",
37
67
  "pino": "^10.1.0",
38
- "surrealdb": "2.0.0"
68
+ "surrealdb": "2.0.3"
39
69
  },
40
70
  "devDependencies": {
41
71
  "@types/node": "^22.5.2",
@@ -0,0 +1,258 @@
1
+ ---
2
+ name: sp00ky-core
3
+ description: >-
4
+ Core client for the Sp00ky reactive local-first SurrealDB framework. Use when
5
+ initializing Sp00kyClient, registering queries and subscriptions, performing
6
+ mutations (create/update/delete), handling auth (signUp/signIn/signOut),
7
+ working with file buckets, or using backend runs (HTTP outbox pattern).
8
+ metadata:
9
+ author: sp00ky-sync
10
+ version: "0.0.1"
11
+ ---
12
+
13
+ # Sp00ky Core
14
+
15
+ `@spooky-sync/core` provides `Sp00kyClient`, the main entry point for the Sp00ky framework. It handles local-first data sync with SurrealDB, reactive queries, optimistic mutations, authentication, file storage, and backend runs.
16
+
17
+ ## Initialization
18
+
19
+ ```typescript
20
+ import { Sp00kyClient } from '@spooky-sync/core';
21
+ import { schema } from './generated/schema'; // Generated by `spooky generate`
22
+ import schemaSurql from './generated/schema.surql?raw';
23
+
24
+ const client = new Sp00kyClient({
25
+ database: {
26
+ endpoint: 'ws://localhost:8000',
27
+ namespace: 'my_ns',
28
+ database: 'my_db',
29
+ store: 'indexeddb', // or 'memory'
30
+ },
31
+ schema,
32
+ schemaSurql,
33
+ logLevel: 'info',
34
+ });
35
+
36
+ // IMPORTANT: You must call init() before using the client
37
+ await client.init();
38
+
39
+ // When done (e.g., app teardown):
40
+ await client.close();
41
+ ```
42
+
43
+ ### Sp00kyConfig Options
44
+
45
+ See [references/config.md](references/config.md) for all configuration options.
46
+
47
+ Key fields:
48
+ - `database.endpoint` — SurrealDB WebSocket URL
49
+ - `database.namespace` / `database.database` — SurrealDB namespace and database
50
+ - `database.store` — `'indexeddb'` (persistent) or `'memory'` (transient)
51
+ - `schema` — The `SchemaStructure` object (use `as const satisfies SchemaStructure`)
52
+ - `schemaSurql` — The compiled SURQL schema string for local DB provisioning
53
+ - `logLevel` — `'debug' | 'info' | 'warn' | 'error'`
54
+ - `persistenceClient` — `'surrealdb'` (default), `'localstorage'`, or a custom `PersistenceClient`
55
+ - `streamDebounceTime` — Debounce ms for stream updates (default: 100)
56
+
57
+ ## Querying
58
+
59
+ Queries are registered with the client and return a hash. You subscribe to the hash to receive reactive updates.
60
+
61
+ ```typescript
62
+ // Register a query — returns a QueryBuilder
63
+ const finalQuery = client.query('post', {})
64
+ .where({ author: 'user:alice' })
65
+ .orderBy('createdAt', 'desc')
66
+ .limit(20)
67
+ .build();
68
+
69
+ // Run it to get the hash
70
+ const { hash } = await finalQuery.run();
71
+
72
+ // Subscribe to reactive updates
73
+ const unsubscribe = await client.subscribe(hash, (records) => {
74
+ console.log('Posts:', records);
75
+ }, { immediate: true });
76
+
77
+ // Later: unsubscribe
78
+ unsubscribe();
79
+ ```
80
+
81
+ ### Query TTL
82
+
83
+ Queries have a time-to-live. Supported values: `'1m'`, `'5m'`, `'10m'` (default), `'15m'`, `'20m'`, `'25m'`, `'30m'`, `'1h'`–`'12h'`, `'1d'`.
84
+
85
+ ## Mutations
86
+
87
+ Mutations are optimistic and automatically synced to the remote SurrealDB instance.
88
+
89
+ ```typescript
90
+ // Create — pass a full "table:id" string and the record data
91
+ await client.create('post:abc123', {
92
+ title: 'Hello World',
93
+ body: 'My first post',
94
+ author: 'user:alice',
95
+ });
96
+
97
+ // Update — pass table name, record ID, and partial data
98
+ await client.update('post', 'post:abc123', { title: 'Updated Title' });
99
+
100
+ // Update with debounce (useful for text fields)
101
+ await client.update('post', 'post:abc123', { body: 'typing...' }, {
102
+ debounced: { key: 'recordId_x_fields', delay: 300 },
103
+ });
104
+
105
+ // Delete
106
+ await client.delete('post', 'post:abc123');
107
+ ```
108
+
109
+ ### Debounced Updates
110
+
111
+ Use `debounced` option for frequent updates (e.g., live typing):
112
+ - `key: 'recordId'` — Debounce by record ID only (latest write wins, no merge)
113
+ - `key: 'recordId_x_fields'` — Debounce by record ID + changed fields (recommended)
114
+
115
+ ## Authentication
116
+
117
+ See [references/auth.md](references/auth.md) for the full auth API.
118
+
119
+ ```typescript
120
+ // Sign up
121
+ await client.auth.signUp('user_access', {
122
+ email: 'alice@example.com',
123
+ password: 'secret',
124
+ name: 'Alice',
125
+ });
126
+
127
+ // Sign in
128
+ await client.auth.signIn('user_access', {
129
+ email: 'alice@example.com',
130
+ password: 'secret',
131
+ });
132
+
133
+ // Subscribe to auth state changes
134
+ const unsub = client.auth.subscribe((userId) => {
135
+ console.log('Auth state:', userId); // string ID or null
136
+ });
137
+
138
+ // Sign out
139
+ await client.auth.signOut();
140
+ ```
141
+
142
+ Auth state properties: `client.auth.token`, `client.auth.currentUser`, `client.auth.isAuthenticated`, `client.auth.isLoading`.
143
+
144
+ ## Buckets (File Storage)
145
+
146
+ ```typescript
147
+ const avatars = client.bucket('avatars');
148
+
149
+ await avatars.put('alice/profile.png', fileBytes);
150
+ const content = await avatars.get('alice/profile.png');
151
+ const exists = await avatars.exists('alice/profile.png');
152
+ await avatars.delete('alice/profile.png');
153
+ await avatars.copy('alice/profile.png', 'alice/backup.png');
154
+ await avatars.rename('old.png', 'new.png');
155
+ const files = await avatars.list('alice/');
156
+ ```
157
+
158
+ Buckets must be defined in the schema under the `buckets` array.
159
+
160
+ ## Backend Runs (HTTP Outbox)
161
+
162
+ Backend runs let you trigger server-side HTTP operations via an **outbox pattern**. When you call `db.run()`, it creates a job record in a local outbox table. That record syncs to remote SurrealDB, where the Sp00ky Sync Platform (SSP) picks it up and calls your backend HTTP API. The result status is written back to the job record and syncs to the client reactively.
163
+
164
+ ### `db.run()` Signature
165
+
166
+ ```typescript
167
+ db.run<B extends BackendNames<S>, R extends BackendRoutes<S, B>>(
168
+ backend: B, // Backend name from sp00ky.yml (e.g., 'api')
169
+ route: R, // Route path from OpenAPI spec (e.g., '/spookify')
170
+ payload: RoutePayload<S, B, R>, // Typed args for the route
171
+ options?: RunOptions
172
+ ): Promise<void>
173
+ ```
174
+
175
+ All parameters are type-safe — `backend`, `route`, and `payload` are inferred from the generated schema.
176
+
177
+ ### RunOptions
178
+
179
+ | Option | Type | Default | Description |
180
+ |--------|------|---------|-------------|
181
+ | `assignedTo` | `string` | `undefined` | Record ID to link the job to an entity (e.g., `'thread:abc'`) |
182
+ | `max_retries` | `number` | `3` | Maximum retry attempts on failure |
183
+ | `retry_strategy` | `'linear' \| 'exponential'` | `'linear'` | Backoff strategy between retries |
184
+
185
+ ### Entity Linking via `assignedTo`
186
+
187
+ The `assignedTo` option is how you link a job to an entity. Passing a record ID:
188
+
189
+ - Sets the `assigned_to` field on the job record (typed as `record<thread>` etc. in the outbox schema)
190
+ - Enables **permission scoping** — e.g., `WHERE assigned_to.author.id = $auth.id` restricts job visibility to the entity's owner
191
+ - Allows **querying jobs via relationships** — use `.related('jobs')` on the parent entity to reactively track job status
192
+
193
+ ### Full Example
194
+
195
+ **1. Configure the backend in `sp00ky.yml`:**
196
+
197
+ ```yaml
198
+ backends:
199
+ api:
200
+ type: http
201
+ spec: ../api/openapi.yml
202
+ baseUrl: http://host.docker.internal:3660
203
+ auth:
204
+ type: token
205
+ token: MY_SECRET
206
+ method:
207
+ type: outbox
208
+ table: job
209
+ schema: ./src/outbox/api.surql
210
+ ```
211
+
212
+ **2. Define the outbox table in SurrealQL** (`src/outbox/api.surql`):
213
+
214
+ ```sql
215
+ DEFINE TABLE job SCHEMAFULL
216
+ PERMISSIONS
217
+ FOR select, create, update, delete
218
+ WHERE $access = "account" AND assigned_to.author.id = $auth.id;
219
+
220
+ DEFINE FIELD assigned_to ON TABLE job TYPE record<thread>;
221
+ DEFINE FIELD path ON TABLE job TYPE string;
222
+ DEFINE FIELD payload ON TABLE job TYPE any;
223
+ DEFINE FIELD retries ON TABLE job TYPE int DEFAULT ALWAYS 0;
224
+ DEFINE FIELD max_retries ON TABLE job TYPE int DEFAULT ALWAYS 3;
225
+ DEFINE FIELD retry_strategy ON TABLE job TYPE string DEFAULT ALWAYS "linear"
226
+ ASSERT $value IN ["linear", "exponential"];
227
+ DEFINE FIELD status ON TABLE job TYPE string DEFAULT ALWAYS "pending"
228
+ ASSERT $value IN ["pending", "processing", "success", "failed"];
229
+ DEFINE FIELD errors ON TABLE job TYPE array<object> DEFAULT ALWAYS [];
230
+ DEFINE FIELD created_at ON TABLE job TYPE datetime VALUE time::now();
231
+ ```
232
+
233
+ **3. Run `spooky generate`** — this produces the typed `backends` block in `schema.gen.ts`.
234
+
235
+ **4. Call `db.run()` with entity linking:**
236
+
237
+ ```typescript
238
+ // Trigger the /spookify backend route, linked to a thread
239
+ await client.run('api', '/spookify', { id: threadId }, {
240
+ assignedTo: threadId, // Links job to the thread entity
241
+ });
242
+ ```
243
+
244
+ ### How It Works Under the Hood
245
+
246
+ When you call `db.run('api', '/spookify', payload, options)`:
247
+
248
+ 1. Validates the route exists in the schema and all required args are present
249
+ 2. Creates a record in the outbox table (`job`) with fields: `path`, `payload` (JSON-stringified), `max_retries`, `retry_strategy`, and optionally `assigned_to`
250
+ 3. The record is created via the standard `client.create()` path — optimistic, synced to remote
251
+ 4. SSP detects the new job, calls your backend HTTP API, and updates the job's `status` field (`pending` → `processing` → `success`/`failed`)
252
+
253
+ ## Common Pitfalls
254
+
255
+ 1. **Must call `init()` before using the client** — All operations will fail if you skip initialization.
256
+ 2. **Schema is generated** — Use `spooky generate` to produce the schema TypeScript file and SURQL file from your `.surql` definitions.
257
+ 3. **RecordId format** — SurrealDB uses `table:id` format. When creating records, pass the full ID (e.g., `'post:abc123'`). The framework auto-converts string IDs to `RecordId` objects internally.
258
+ 4. **Queries are hash-based** — The same query always produces the same hash, enabling deduplication and caching.
@@ -0,0 +1,98 @@
1
+ # Authentication Reference
2
+
3
+ ## AuthService API
4
+
5
+ The `AuthService` is available on `Sp00kyClient` as `client.auth`.
6
+
7
+ ### Properties
8
+
9
+ | Property | Type | Description |
10
+ |----------|------|-------------|
11
+ | `token` | `string \| null` | Current auth token |
12
+ | `currentUser` | `any \| null` | Current authenticated user record |
13
+ | `isAuthenticated` | `boolean` | Whether a user is authenticated |
14
+ | `isLoading` | `boolean` | Whether auth state is being validated |
15
+
16
+ ### Methods
17
+
18
+ #### `signUp(accessName, params)`
19
+
20
+ Create a new account using the named access definition from the schema.
21
+
22
+ ```typescript
23
+ await client.auth.signUp('user_access', {
24
+ email: 'alice@example.com',
25
+ password: 'secret123',
26
+ name: 'Alice',
27
+ });
28
+ ```
29
+
30
+ The access definition in the schema determines what parameters are required:
31
+
32
+ ```typescript
33
+ access: {
34
+ user_access: {
35
+ signup: {
36
+ params: {
37
+ email: { type: 'string', optional: false },
38
+ password: { type: 'string', optional: false },
39
+ name: { type: 'string', optional: true },
40
+ },
41
+ },
42
+ signIn: {
43
+ params: {
44
+ email: { type: 'string', optional: false },
45
+ password: { type: 'string', optional: false },
46
+ },
47
+ },
48
+ },
49
+ }
50
+ ```
51
+
52
+ Parameters are fully type-safe — TypeScript will infer the correct types from the schema.
53
+
54
+ #### `signIn(accessName, params)`
55
+
56
+ Authenticate with existing credentials.
57
+
58
+ ```typescript
59
+ await client.auth.signIn('user_access', {
60
+ email: 'alice@example.com',
61
+ password: 'secret123',
62
+ });
63
+ ```
64
+
65
+ #### `signOut()`
66
+
67
+ Sign out, clear the session token, and notify subscribers.
68
+
69
+ ```typescript
70
+ await client.auth.signOut();
71
+ ```
72
+
73
+ #### `subscribe(callback)`
74
+
75
+ Subscribe to auth state changes. The callback fires immediately with the current state, then on every change.
76
+
77
+ ```typescript
78
+ const unsub = client.auth.subscribe((userId: string | null) => {
79
+ if (userId) {
80
+ console.log('Logged in as', userId);
81
+ } else {
82
+ console.log('Not authenticated');
83
+ }
84
+ });
85
+
86
+ // Cleanup
87
+ unsub();
88
+ ```
89
+
90
+ #### `check(accessToken?)`
91
+
92
+ Manually re-validate the current session. Called automatically during `init()`.
93
+
94
+ ```typescript
95
+ await client.auth.check();
96
+ // Or with a specific token:
97
+ await client.auth.check('eyJhbGciOiJIUzI1NiJ9...');
98
+ ```
@@ -0,0 +1,76 @@
1
+ # Sp00kyConfig Reference
2
+
3
+ ```typescript
4
+ interface Sp00kyConfig<S extends SchemaStructure> {
5
+ database: {
6
+ /** SurrealDB WebSocket endpoint URL */
7
+ endpoint?: string;
8
+ /** SurrealDB namespace */
9
+ namespace: string;
10
+ /** SurrealDB database name */
11
+ database: string;
12
+ /** Local store type: 'memory' (transient) or 'indexeddb' (persistent) */
13
+ store?: 'memory' | 'indexeddb';
14
+ /** Authentication token */
15
+ token?: string;
16
+ };
17
+ /** Unique client identifier. Auto-generated if not provided. */
18
+ clientId?: string;
19
+ /** The schema object (must use `as const satisfies SchemaStructure`) */
20
+ schema: S;
21
+ /** Compiled SURQL schema string for local DB provisioning */
22
+ schemaSurql: string;
23
+ /** Logging level */
24
+ logLevel: 'debug' | 'info' | 'warn' | 'error' | 'fatal' | 'silent' | 'trace';
25
+ /**
26
+ * Persistence client for local storage.
27
+ * - 'surrealdb': Uses the local SurrealDB instance (default)
28
+ * - 'localstorage': Uses browser localStorage
29
+ * - Custom: Provide an object implementing PersistenceClient
30
+ */
31
+ persistenceClient?: PersistenceClient | 'surrealdb' | 'localstorage';
32
+ /** A pino browser transmit object for forwarding logs (e.g. via @spooky-sync/core/otel) */
33
+ otelTransmit?: PinoTransmit;
34
+ /** Debounce time in ms for stream updates (default: 100) */
35
+ streamDebounceTime?: number;
36
+ }
37
+ ```
38
+
39
+ ## PersistenceClient Interface
40
+
41
+ ```typescript
42
+ interface PersistenceClient {
43
+ set<T>(key: string, value: T): Promise<void>;
44
+ get<T>(key: string): Promise<T | null>;
45
+ remove(key: string): Promise<void>;
46
+ }
47
+ ```
48
+
49
+ ## QueryTimeToLive Values
50
+
51
+ Supported TTL values for `client.query()`:
52
+
53
+ `'1m'`, `'5m'`, `'10m'`, `'15m'`, `'20m'`, `'25m'`, `'30m'`, `'1h'`, `'2h'`, `'3h'`, `'4h'`, `'5h'`, `'6h'`, `'7h'`, `'8h'`, `'9h'`, `'10h'`, `'11h'`, `'12h'`, `'1d'`
54
+
55
+ ## RunOptions
56
+
57
+ ```typescript
58
+ interface RunOptions {
59
+ assignedTo?: string;
60
+ max_retries?: number;
61
+ retry_strategy?: 'linear' | 'exponential';
62
+ }
63
+ ```
64
+
65
+ ## UpdateOptions
66
+
67
+ ```typescript
68
+ interface UpdateOptions {
69
+ debounced?: boolean | {
70
+ /** 'recordId': latest write wins. 'recordId_x_fields': merge by field (recommended). */
71
+ key?: 'recordId' | 'recordId_x_fields';
72
+ /** Debounce delay in ms */
73
+ delay?: number;
74
+ };
75
+ }
76
+ ```
@@ -0,0 +1,12 @@
1
+ // Build-time string constants injected by tsdown's `define` (see
2
+ // tsdown.config.ts). They carry the real bundled frontend package versions so
3
+ // the DevTools can surface frontend/backend version drift.
4
+ //
5
+ // Typed as `string | undefined` on purpose: the substitution only happens when
6
+ // `@spooky-sync/core` is built with our tsdown plugin. A downstream app that
7
+ // bundles core from source never runs that plugin, so these identifiers must be
8
+ // guarded with `typeof` (see modules/devtools/index.ts) to avoid a runtime
9
+ // ReferenceError that would break DB initialization.
10
+ declare const __SP00KY_CORE_VERSION__: string | undefined;
11
+ declare const __SP00KY_WASM_VERSION__: string | undefined;
12
+ declare const __SP00KY_SURREAL_VERSION__: string | undefined;
@@ -1,5 +1,6 @@
1
1
  import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
- import { EventSystem, EventDefinition } from './index';
2
+ import type { EventDefinition } from './index';
3
+ import { EventSystem } from './index';
3
4
 
4
5
  // Define test event types
5
6
  type TestEvents = {
@@ -172,6 +172,9 @@ export class EventSystem<E extends EventTypeMap> {
172
172
  * @param payload The data associated with the event.
173
173
  */
174
174
  emit<T extends EventType<E>, P extends EventPayload<E, T>>(type: T, payload: P): void {
175
+ // `{ type, payload }` structurally matches `Event<E, T>` (= the indexed
176
+ // access `E[T]`), but TS can't verify assignability to an indexed-access
177
+ // type over the generic `E`/`T`, so the constructed event is asserted.
175
178
  const event = {
176
179
  type,
177
180
  payload,
package/src/index.ts CHANGED
@@ -1,4 +1,11 @@
1
1
  export * from './types';
2
- export * from './spooky';
2
+ export * from './sp00ky';
3
3
  export * from './modules/auth/index';
4
- export { fileToUint8Array } from './utils/index';
4
+ export { CrdtField, CrdtManager, cursorColorFromName, CURSOR_COLORS } from './modules/crdt/index';
5
+ export {
6
+ FeatureFlagModule,
7
+ FeatureFlagHandle,
8
+ type FeatureFlagOptions,
9
+ type FeatureFlagSnapshot,
10
+ } from './modules/feature-flag/index';
11
+ export { fileToUint8Array, textToHtml } from './utils/index';
@@ -1,4 +1,5 @@
1
- import { createEventSystem, EventDefinition, EventSystem } from '../../../events/index';
1
+ import type { EventDefinition, EventSystem } from '../../../events/index';
2
+ import { createEventSystem } from '../../../events/index';
2
3
 
3
4
  export const AuthEventTypes = {
4
5
  AuthStateChanged: 'AUTH_STATE_CHANGED',