@ultimat3/realtime 31.39.0 → 31.40.0
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/CLAUDE.md +3 -2
- package/package.json +5 -5
- package/src/live-contract.ts +3 -2
- package/src/query-window.ts +9 -3
- package/src/replicator-subject.ts +9 -3
- package/src/server.ts +1 -0
package/CLAUDE.md
CHANGED
|
@@ -111,8 +111,9 @@ A rule marked `†` has its full text in [`docs/history/realtime-rules.md`](../.
|
|
|
111
111
|
re-lookup (`live-definition-input.test.ts`). A cold window is staled only by a table it reads.
|
|
112
112
|
- **A WINDOW is per TENANT** (`windowId(queryHash, tenant)`, `live-tenant.ts`); the read runs as a
|
|
113
113
|
service actor carrying ONLY that org, never the subscriber. †
|
|
114
|
-
- **A change's tenant is its entity's `$tenantColumn`, on every producer
|
|
115
|
-
never a property assumed to be `orgId`; a window
|
|
114
|
+
- **A change's tenant is its entity's `$tenantColumn`, on every producer and in `normalize`** (`change-tenant.ts`, `replicator-tenant.test.ts`),
|
|
115
|
+
never a property assumed to be `orgId`; a window's org is its TENANT alone, `null` untenanted —
|
|
116
|
+
never the input's `orgId` (`query-window-tenant.test.ts`; `orgIdOf` is deprecated, unused); a window lists its tenanted tables (`shape.tenantTables`)
|
|
116
117
|
and `canAffect` refuses a tenant-less insert/update on one for an org-scoped window; a
|
|
117
118
|
tenant-less DELETE (key-only image) passes, and `bridgeChange` keeps a delete only for an id
|
|
118
119
|
the window holds (`live-tenant-column.test.ts`, `tenant-less-delete.test.ts`).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/realtime",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.40.0",
|
|
4
4
|
"description": "Three-tier realtime: channels, live queries, local-first sync — one protocol, one mutator shape",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"test": "bun test"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@ultimat3/core": "31.
|
|
56
|
-
"@ultimat3/entity": "31.
|
|
57
|
-
"@ultimat3/policy": "31.
|
|
58
|
-
"@ultimat3/query": "31.
|
|
55
|
+
"@ultimat3/core": "31.40.0",
|
|
56
|
+
"@ultimat3/entity": "31.40.0",
|
|
57
|
+
"@ultimat3/policy": "31.40.0",
|
|
58
|
+
"@ultimat3/query": "31.40.0",
|
|
59
59
|
"nats": "2.29.3"
|
|
60
60
|
}
|
|
61
61
|
}
|
package/src/live-contract.ts
CHANGED
|
@@ -43,12 +43,13 @@ export interface SnapshotArgs {
|
|
|
43
43
|
|
|
44
44
|
export interface LiveQueryDefinition<R extends LiveRow = LiveRow> {
|
|
45
45
|
readonly name: string;
|
|
46
|
-
/** Dependency set for the pre-filter
|
|
46
|
+
/** Dependency set for the pre-filter: required by this type; `@ultimat3/query` refuses an empty `subscribes:`. */
|
|
47
47
|
readonly entities: readonly string[];
|
|
48
48
|
/** Read set. Lets the pre-filter skip updates that touch no column this query reads. */
|
|
49
49
|
readonly columns?: readonly string[];
|
|
50
50
|
/**
|
|
51
|
-
* Bounded read (`orderBy` + `limit
|
|
51
|
+
* Bounded read (`orderBy` + `limit`; no limit is `X_QUERY_LIVE_UNBOUNDED`, refused where
|
|
52
|
+
* `@ultimat3/query` builds the source — `live-bounds.ts`), unfiltered by policy — and read
|
|
52
53
|
* FOR `tenant`: the org of the subscribers this window serves, `null` for subscribers that carry
|
|
53
54
|
* none. A window is keyed by it (`live-tenant.ts`), so one read is never two orgs' rows.
|
|
54
55
|
*/
|
package/src/query-window.ts
CHANGED
|
@@ -128,9 +128,10 @@ export function queryEntry(
|
|
|
128
128
|
shape: {
|
|
129
129
|
qid,
|
|
130
130
|
entities,
|
|
131
|
-
// The window's own tenant
|
|
132
|
-
// runs
|
|
133
|
-
|
|
131
|
+
// The window's own tenant, and nothing else: a change in another org is dropped before any
|
|
132
|
+
// predicate runs. Never an input property spelled `orgId` — the read runs under `tenant`
|
|
133
|
+
// alone, so filtering by anything else drops changes that read returns (`change-tenant.ts`).
|
|
134
|
+
orgId: tenant,
|
|
134
135
|
// Resolved once per window, so `canAffect` refuses a tenant-less change on these with a
|
|
135
136
|
// lookup in a short list rather than a registry walk per change.
|
|
136
137
|
tenantTables: entities.filter((table) => tenantColumnOfTable(table) !== null),
|
|
@@ -387,6 +388,11 @@ async function readSnapshot(entry: QueryEntry, phase: LiveReadPhase): Promise<Sn
|
|
|
387
388
|
}
|
|
388
389
|
}
|
|
389
390
|
|
|
391
|
+
/**
|
|
392
|
+
* @deprecated Unused by the framework, and removed at the next major. A window's org is its
|
|
393
|
+
* tenant — pass `tenant` to `queryEntry` — never an input property spelled `orgId`: the read runs
|
|
394
|
+
* under the tenant alone, and a change's own tenant is its entity's `$tenantColumn`.
|
|
395
|
+
*/
|
|
390
396
|
export function orgIdOf(input: JsonValue): string | null {
|
|
391
397
|
if (typeof input !== 'object' || input === null || Array.isArray(input)) return null;
|
|
392
398
|
const value = input['orgId'];
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// the subject a change is published under, and the normalize step that drops the unusable and
|
|
3
3
|
// hoists the tenant out of the row. Split from `replicator.ts`, which re-exports both.
|
|
4
4
|
|
|
5
|
+
import { tenantColumnOfTable, tenantIn } from './change-tenant';
|
|
5
6
|
import type { ChangeEvent } from './changefeed';
|
|
6
7
|
|
|
7
8
|
export const CHANGE_SUBJECT_PREFIX = 'x.change';
|
|
@@ -14,7 +15,12 @@ export function changeSubject(change: ChangeEvent): string {
|
|
|
14
15
|
return `${CHANGE_SUBJECT_PREFIX}.${change.table}.${change.orgId ?? '_'}`;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Drops events the pipeline cannot use and hoists the tenant out of the row — from the column the
|
|
20
|
+
* table's ENTITY declares (`change-tenant.ts`), never a property assumed to be `orgId`. It read
|
|
21
|
+
* `row.orgId`, so a key-only DELETE on a `tenant: 'workspaceId'` table whose key holds an `orgId`
|
|
22
|
+
* column was published as that org's change, and the real tenant's windows dropped it.
|
|
23
|
+
*/
|
|
18
24
|
export function normalize(change: ChangeEvent): ChangeEvent | null {
|
|
19
25
|
// The one change that carries no row by design; nothing to hoist a tenant out of.
|
|
20
26
|
if (change.op === 'truncate') return change;
|
|
@@ -23,6 +29,6 @@ export function normalize(change: ChangeEvent): ChangeEvent | null {
|
|
|
23
29
|
if (change.op === 'insert' && change.after === null) return null;
|
|
24
30
|
if (change.op === 'delete' && change.before === null) return null;
|
|
25
31
|
if (change.orgId !== null) return change;
|
|
26
|
-
const orgId = row
|
|
27
|
-
return
|
|
32
|
+
const orgId = tenantIn(tenantColumnOfTable(change.table), row);
|
|
33
|
+
return orgId === null ? change : { ...change, orgId };
|
|
28
34
|
}
|
package/src/server.ts
CHANGED