@substrat-run/adapter-cloudflare 0.221.0 → 0.223.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/dist/broker-telemetry.d.ts +2 -5
- package/dist/broker-telemetry.d.ts.map +1 -1
- package/dist/broker-telemetry.js +2 -5
- package/dist/broker-telemetry.js.map +1 -1
- package/dist/control-plane-do.d.ts +251 -67
- package/dist/control-plane-do.d.ts.map +1 -1
- package/dist/control-plane-do.js +666 -247
- package/dist/control-plane-do.js.map +1 -1
- package/dist/delivery-broker-do.d.ts +3 -2
- package/dist/delivery-broker-do.d.ts.map +1 -1
- package/dist/delivery-broker-do.js +10 -4
- package/dist/delivery-broker-do.js.map +1 -1
- package/dist/delivery-handoff.d.ts +17 -1
- package/dist/delivery-handoff.d.ts.map +1 -1
- package/dist/delivery-handoff.js +19 -5
- package/dist/delivery-handoff.js.map +1 -1
- package/dist/directory-cutover.d.ts +243 -0
- package/dist/directory-cutover.d.ts.map +1 -0
- package/dist/directory-cutover.js +604 -0
- package/dist/directory-cutover.js.map +1 -0
- package/dist/directory-mirror-apply.d.ts +19 -1
- package/dist/directory-mirror-apply.d.ts.map +1 -1
- package/dist/directory-mirror-apply.js +19 -3
- package/dist/directory-mirror-apply.js.map +1 -1
- package/dist/directory-mirror-backfill.d.ts +2 -0
- package/dist/directory-mirror-backfill.d.ts.map +1 -1
- package/dist/directory-mirror-backfill.js +6 -4
- package/dist/directory-mirror-backfill.js.map +1 -1
- package/dist/directory-mirror.d.ts +24 -0
- package/dist/directory-mirror.d.ts.map +1 -1
- package/dist/directory-mirror.js +16 -2
- package/dist/directory-mirror.js.map +1 -1
- package/dist/directory-objects.d.ts +40 -0
- package/dist/directory-objects.d.ts.map +1 -1
- package/dist/directory-objects.js +134 -2
- package/dist/directory-objects.js.map +1 -1
- package/dist/directory-placement.d.ts.map +1 -1
- package/dist/directory-placement.js +7 -1
- package/dist/directory-placement.js.map +1 -1
- package/dist/directory-split-inventory.d.ts +5 -3
- package/dist/directory-split-inventory.d.ts.map +1 -1
- package/dist/directory-split-inventory.js +12 -6
- package/dist/directory-split-inventory.js.map +1 -1
- package/dist/directory-tenant-orgs.d.ts +19 -0
- package/dist/directory-tenant-orgs.d.ts.map +1 -0
- package/dist/directory-tenant-orgs.js +33 -0
- package/dist/directory-tenant-orgs.js.map +1 -0
- package/dist/directory-tenant-roles.d.ts +35 -0
- package/dist/directory-tenant-roles.d.ts.map +1 -0
- package/dist/directory-tenant-roles.js +78 -0
- package/dist/directory-tenant-roles.js.map +1 -0
- package/dist/directory-tenant-tuples.d.ts +165 -0
- package/dist/directory-tenant-tuples.d.ts.map +1 -0
- package/dist/directory-tenant-tuples.js +197 -0
- package/dist/directory-tenant-tuples.js.map +1 -0
- package/dist/executor-route.d.ts +13 -0
- package/dist/executor-route.d.ts.map +1 -0
- package/dist/executor-route.js +12 -0
- package/dist/executor-route.js.map +1 -0
- package/dist/host.d.ts +76 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +386 -67
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/platform-sweeper-do.d.ts +1 -1
- package/dist/platform-sweeper-do.js +1 -1
- package/dist/scope-do.d.ts +11 -2
- package/dist/scope-do.d.ts.map +1 -1
- package/dist/scope-do.js +206 -58
- package/dist/scope-do.js.map +1 -1
- package/dist/scope-sweeper-do.d.ts +22 -0
- package/dist/scope-sweeper-do.d.ts.map +1 -1
- package/dist/scope-sweeper-do.js +74 -54
- package/dist/scope-sweeper-do.js.map +1 -1
- package/dist/scope-wake.d.ts +12 -1
- package/dist/scope-wake.d.ts.map +1 -1
- package/dist/scope-wake.js +14 -1
- package/dist/scope-wake.js.map +1 -1
- package/dist/tenant-due-work-do.d.ts +99 -0
- package/dist/tenant-due-work-do.d.ts.map +1 -0
- package/dist/tenant-due-work-do.js +149 -0
- package/dist/tenant-due-work-do.js.map +1 -0
- package/package.json +10 -10
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A tenant's organizations (`orgs`, K-22), as SQL over any store that holds the table: the one
|
|
3
|
+
* directory (`ControlPlaneDO`) and, for a tenant whose directory reads are cut over (K-68 step 3e,
|
|
4
|
+
* `directory-cutover.ts`), the tenant's own `TenantDirectoryDO`. Both run these functions, so an org is
|
|
5
|
+
* created, its slug held unique in the tenant and its existence answered the same way wherever it lands.
|
|
6
|
+
*
|
|
7
|
+
* An org is never removed from a live tenant: only the tenant's reap deletes its rows, and a cut-over
|
|
8
|
+
* tenant's reap is refused until it is flipped off. So "the org exists" read once stays true.
|
|
9
|
+
*/
|
|
10
|
+
import { substratError } from '@substrat-run/contracts';
|
|
11
|
+
export const ORGS = 'orgs';
|
|
12
|
+
export function readOrgRow(sql, tenantId, orgId) {
|
|
13
|
+
return sql.exec('SELECT * FROM orgs WHERE tenant_id = ? AND org_id = ?', tenantId, orgId).toArray()[0];
|
|
14
|
+
}
|
|
15
|
+
export function listOrgRows(sql, tenantId) {
|
|
16
|
+
return sql.exec('SELECT * FROM orgs WHERE tenant_id = ? ORDER BY slug', tenantId).toArray();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Create an org, in the caller's transaction. False when it already exists (idempotent); throws
|
|
20
|
+
* `conflict` when another org of the tenant holds the slug (slugs are unique per tenant).
|
|
21
|
+
*/
|
|
22
|
+
export function createOrgIn(store, orgId, tenantId, slug, name, createdAt) {
|
|
23
|
+
if (readOrgRow(store.sql, tenantId, orgId))
|
|
24
|
+
return false;
|
|
25
|
+
const slugOwner = store.sql.exec('SELECT org_id FROM orgs WHERE tenant_id = ? AND slug = ?', tenantId, slug).toArray()[0];
|
|
26
|
+
if (slugOwner) {
|
|
27
|
+
throw substratError('conflict', `org slug '${slug}' already taken by ${slugOwner.org_id} (slugs are unique per tenant)`);
|
|
28
|
+
}
|
|
29
|
+
store.sql.exec('INSERT INTO orgs (org_id, tenant_id, slug, name, created_at) VALUES (?, ?, ?, ?, ?)', orgId, tenantId, slug, name, createdAt);
|
|
30
|
+
store.touched?.(ORGS, [orgId]);
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=directory-tenant-orgs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directory-tenant-orgs.js","sourceRoot":"","sources":["../src/directory-tenant-orgs.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC;AAU3B,MAAM,UAAU,UAAU,CAAC,GAAe,EAAE,QAAgB,EAAE,KAAa;IACzE,OAAO,GAAG,CAAC,IAAI,CAAC,uDAAuD,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAkC,CAAC;AAC1I,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,GAAe,EAAE,QAAgB;IAC3D,OAAO,GAAG,CAAC,IAAI,CAAC,sDAAsD,EAAE,QAAQ,CAAC,CAAC,OAAO,EAAyB,CAAC;AACrH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CACzB,KAAiF,EACjF,KAAa,EACb,QAAgB,EAChB,IAAY,EACZ,IAAY,EACZ,SAAiB;IAEjB,IAAI,UAAU,CAAC,KAAK,CAAC,GAAG,EAAE,QAAQ,EAAE,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACzD,MAAM,SAAS,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,0DAA0D,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAE3G,CAAC;IACd,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,aAAa,CAAC,UAAU,EAAE,aAAa,IAAI,sBAAsB,SAAS,CAAC,MAAM,gCAAgC,CAAC,CAAC;IAC3H,CAAC;IACD,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,qFAAqF,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;IAC9I,KAAK,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAC/B,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ListPage, RoleDefinition } from '@substrat-run/contracts';
|
|
2
|
+
/** A role row as the directory stores it; the coordinator parses it through the `tenantRole` contract. */
|
|
3
|
+
export interface RoleRow {
|
|
4
|
+
tenant_id: string;
|
|
5
|
+
role_key: string;
|
|
6
|
+
permissions: string;
|
|
7
|
+
source: string;
|
|
8
|
+
/** Absent on an older control plane's projection wire. */
|
|
9
|
+
holder?: 'person' | 'system' | null;
|
|
10
|
+
}
|
|
11
|
+
export type RoleFilterRows = {
|
|
12
|
+
tenantId?: string;
|
|
13
|
+
source?: string;
|
|
14
|
+
} & ListPage;
|
|
15
|
+
/** What a definition is judged against (#2447), as the coordinator read it. */
|
|
16
|
+
export interface RoleReservation {
|
|
17
|
+
reserved: readonly string[];
|
|
18
|
+
declared: readonly string[];
|
|
19
|
+
}
|
|
20
|
+
/** Raw rows of a filter, paged on the composite key `${tenantId}|${roleKey}`. */
|
|
21
|
+
export declare function listRoleRows(sql: SqlStorage, filter: RoleFilterRows): RoleRow[];
|
|
22
|
+
export declare function readRole(sql: SqlStorage, tenantId: string, key: string): RoleDefinition | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* INSERT OR REPLACE, judged first in the caller's transaction (#2447, `reservedRoleDefinitionRefusal`):
|
|
25
|
+
* against `reservation` and the tenant's roles as stored now. Whether the key is seated decides a
|
|
26
|
+
* system-held definition of a key with no system-held definition stored; its tenant-level seats are
|
|
27
|
+
* read here, and `seatedInScopes` carries what the coordinator read off the tenant's scopes. A refusal
|
|
28
|
+
* is answered as data and writes nothing. Answers the role it replaced.
|
|
29
|
+
*/
|
|
30
|
+
export declare function defineRoleRow(sql: SqlStorage, tenantId: string, role: RoleDefinition, reservation: RoleReservation, seatedInScopes: boolean, nowIso: string): {
|
|
31
|
+
before: RoleDefinition | null;
|
|
32
|
+
} | {
|
|
33
|
+
refused: string;
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=directory-tenant-roles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directory-tenant-roles.d.ts","sourceRoot":"","sources":["../src/directory-tenant-roles.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAExE,0GAA0G;AAC1G,MAAM,WAAW,OAAO;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,0DAA0D;IAC1D,MAAM,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,IAAI,CAAC;CACrC;AAED,MAAM,MAAM,cAAc,GAAG;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,QAAQ,CAAC;AAE/E,+EAA+E;AAC/E,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;CAC7B;AAED,iFAAiF;AACjF,wBAAgB,YAAY,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,GAAG,OAAO,EAAE,CA+B/E;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAWnG;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,UAAU,EACf,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,cAAc,EACpB,WAAW,EAAE,eAAe,EAC5B,cAAc,EAAE,OAAO,EACvB,MAAM,EAAE,MAAM,GACb;IAAE,MAAM,EAAE,cAAc,GAAG,IAAI,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CA4BzD"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A tenant's role definitions (`_substrat_roles`, checker rule 1), as SQL over any store that holds
|
|
3
|
+
* the table: the one directory (`ControlPlaneDO`) and, for a tenant whose directory reads are cut
|
|
4
|
+
* over (K-68 step 3e, `directory-cutover.ts`), the tenant's own `TenantDirectoryDO`. Both run these
|
|
5
|
+
* functions, so a definition is judged and a read is answered the same way wherever it lands: the
|
|
6
|
+
* cut-over moves where the rows are read and first written, never what the code does with them.
|
|
7
|
+
*/
|
|
8
|
+
import { assertRowLimit, reservedRoleDefinitionRefusal, TENANT_SEATED_ROLES_SQL } from '@substrat-run/kernel';
|
|
9
|
+
/** Raw rows of a filter, paged on the composite key `${tenantId}|${roleKey}`. */
|
|
10
|
+
export function listRoleRows(sql, filter) {
|
|
11
|
+
const where = [];
|
|
12
|
+
const params = [];
|
|
13
|
+
if (filter.tenantId) {
|
|
14
|
+
where.push('tenant_id = ?');
|
|
15
|
+
params.push(filter.tenantId);
|
|
16
|
+
}
|
|
17
|
+
if (filter.source) {
|
|
18
|
+
where.push('source = ?');
|
|
19
|
+
params.push(filter.source);
|
|
20
|
+
}
|
|
21
|
+
const order = (filter.order ?? 'asc') === 'desc' ? 'DESC' : 'ASC';
|
|
22
|
+
if (filter.cursor) {
|
|
23
|
+
// Composite sort key `${tenantId}|${roleKey}` (pagination.ts) — the
|
|
24
|
+
// tenant id is a ULID and never contains '|', so split on the FIRST.
|
|
25
|
+
const split = filter.cursor.indexOf('|');
|
|
26
|
+
const afterTenant = split === -1 ? filter.cursor : filter.cursor.slice(0, split);
|
|
27
|
+
const afterKey = split === -1 ? '' : filter.cursor.slice(split + 1);
|
|
28
|
+
const cmp = order === 'DESC' ? '<' : '>';
|
|
29
|
+
where.push(`(tenant_id ${cmp} ? OR (tenant_id = ? AND role_key ${cmp} ?))`);
|
|
30
|
+
params.push(afterTenant, afterTenant, afterKey);
|
|
31
|
+
}
|
|
32
|
+
let text = 'SELECT tenant_id, role_key, permissions, source, holder FROM _substrat_roles' +
|
|
33
|
+
(where.length ? ` WHERE ${where.join(' AND ')}` : '') +
|
|
34
|
+
` ORDER BY tenant_id ${order}, role_key ${order}`;
|
|
35
|
+
if (filter.limit !== undefined) {
|
|
36
|
+
text += ' LIMIT ?';
|
|
37
|
+
params.push(assertRowLimit('limit', filter.limit));
|
|
38
|
+
}
|
|
39
|
+
return sql.exec(text, ...params).toArray();
|
|
40
|
+
}
|
|
41
|
+
export function readRole(sql, tenantId, key) {
|
|
42
|
+
const row = sql
|
|
43
|
+
.exec('SELECT role_key, permissions, source, holder FROM _substrat_roles WHERE tenant_id = ? AND role_key = ?', tenantId, key)
|
|
44
|
+
.toArray()[0];
|
|
45
|
+
if (!row)
|
|
46
|
+
return undefined;
|
|
47
|
+
return {
|
|
48
|
+
key: row.role_key,
|
|
49
|
+
permissions: JSON.parse(row.permissions),
|
|
50
|
+
source: row.source,
|
|
51
|
+
holder: row.holder ?? undefined,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* INSERT OR REPLACE, judged first in the caller's transaction (#2447, `reservedRoleDefinitionRefusal`):
|
|
56
|
+
* against `reservation` and the tenant's roles as stored now. Whether the key is seated decides a
|
|
57
|
+
* system-held definition of a key with no system-held definition stored; its tenant-level seats are
|
|
58
|
+
* read here, and `seatedInScopes` carries what the coordinator read off the tenant's scopes. A refusal
|
|
59
|
+
* is answered as data and writes nothing. Answers the role it replaced.
|
|
60
|
+
*/
|
|
61
|
+
export function defineRoleRow(sql, tenantId, role, reservation, seatedInScopes, nowIso) {
|
|
62
|
+
const tenantRoles = listRoleRows(sql, { tenantId }).map((r) => ({
|
|
63
|
+
key: r.role_key,
|
|
64
|
+
permissions: JSON.parse(r.permissions),
|
|
65
|
+
holder: r.holder ?? undefined,
|
|
66
|
+
}));
|
|
67
|
+
const stored = tenantRoles.find((r) => r.key === role.key);
|
|
68
|
+
const seated = stored?.holder !== 'system' && role.holder === 'system' &&
|
|
69
|
+
(seatedInScopes || sql.exec(TENANT_SEATED_ROLES_SQL, tenantId, nowIso).toArray().some((r) => r.role_key === role.key));
|
|
70
|
+
const refused = reservedRoleDefinitionRefusal(role, { reserved: new Set(reservation.reserved), declared: new Set(reservation.declared) }, tenantRoles, seated);
|
|
71
|
+
if (refused)
|
|
72
|
+
return { refused };
|
|
73
|
+
const before = readRole(sql, tenantId, role.key) ?? null;
|
|
74
|
+
sql.exec(`INSERT OR REPLACE INTO _substrat_roles (tenant_id, role_key, permissions, source, holder)
|
|
75
|
+
VALUES (?, ?, ?, ?, ?)`, tenantId, role.key, JSON.stringify(role.permissions), String(role.source), role.holder ?? 'person');
|
|
76
|
+
return { before };
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=directory-tenant-roles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directory-tenant-roles.js","sourceRoot":"","sources":["../src/directory-tenant-roles.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,cAAc,EAAE,6BAA6B,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAqB9G,iFAAiF;AACjF,MAAM,UAAU,YAAY,CAAC,GAAe,EAAE,MAAsB;IAClE,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,MAAM,GAAwB,EAAE,CAAC;IACvC,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QACpB,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAC5B,MAAM,CAAC,IAAI,CAAC,MAAM,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AAG,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3D,MAAM,MAAM,GACV,MAAM,EAAE,MAAM,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,KAAK,QAAQ;QACvD,CAAC,cAAc,IAAK,GAAG,CAAC,IAAI,CAAC,uBAAuB,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,OAAO,EAA6B,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACrJ,MAAM,OAAO,GAAG,6BAA6B,CAC3C,IAAI,EACJ,EAAE,QAAQ,EAAE,IAAI,GAAG,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,IAAI,GAAG,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,EACpF,WAAW,EACX,MAAM,CACP,CAAC;IACF,IAAI,OAAO;QAAE,OAAO,EAAE,OAAO,EAAE,CAAC;IAChC,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC;IACzD,GAAG,CAAC,IAAI,CACN;4BACwB,EACxB,QAAQ,EACR,IAAI,CAAC,GAAG,EACR,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,EAChC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EACnB,IAAI,CAAC,MAAM,IAAI,QAAQ,CACxB,CAAC;IACF,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A tenant's tuples (`_substrat_tenant_tuples`: memberships, tenant-level role seats and grants) and
|
|
3
|
+
* the removal fences beside them (`_substrat_membership_fences`, #1184), as SQL over any store that
|
|
4
|
+
* holds the tables: the one directory (`ControlPlaneDO`) and, for a tenant whose directory reads are
|
|
5
|
+
* cut over (K-68 step 3e, `directory-cutover.ts`), the tenant's own `TenantDirectoryDO`. Both run these
|
|
6
|
+
* functions, so a membership change is bounded, a grant written and a revocation fenced the same way
|
|
7
|
+
* wherever it lands: the cut-over moves where the rows are read and first written, never what the
|
|
8
|
+
* code decides with them.
|
|
9
|
+
*
|
|
10
|
+
* Each unit is synchronous and runs inside the caller's transaction, so its reads and its writes are
|
|
11
|
+
* one unit wherever it runs. What differs between the two stores is `TupleStore`: where an admin row
|
|
12
|
+
* goes (the directory writes it; the object carries it to the directory with the write), whether the
|
|
13
|
+
* tenant holds an org (the directory's table until orgs are cut over), and which keys a unit wrote
|
|
14
|
+
* (the object records them owed).
|
|
15
|
+
*/
|
|
16
|
+
import { type MembershipChange, type MembershipChangeResult, type PermissionTupleRow, type SwitchKind, type SwitchSql, type TenantDirectoryReader } from '@substrat-run/kernel';
|
|
17
|
+
import { type OrgRow } from './directory-tenant-orgs.js';
|
|
18
|
+
export declare const TENANT_TUPLES = "_substrat_tenant_tuples";
|
|
19
|
+
export declare const MEMBERSHIP_FENCES = "_substrat_membership_fences";
|
|
20
|
+
/** One org membership as `listMembers` reads it (#2047: with its expiry). */
|
|
21
|
+
export interface MemberTupleRow {
|
|
22
|
+
subject: string;
|
|
23
|
+
revoked_at: string | null;
|
|
24
|
+
expires_at: string | null;
|
|
25
|
+
}
|
|
26
|
+
/** An admin row as a unit hands it on: the directory's `recordAdmin` input, opaque here. */
|
|
27
|
+
export interface TupleAdminEntry {
|
|
28
|
+
id: string;
|
|
29
|
+
[field: string]: unknown;
|
|
30
|
+
}
|
|
31
|
+
export interface TupleStore {
|
|
32
|
+
sql: SqlStorage;
|
|
33
|
+
/** The unit's clock, ISO 8601. */
|
|
34
|
+
now(): string;
|
|
35
|
+
/** An admin row the unit writes with its rows. */
|
|
36
|
+
admin(entry: TupleAdminEntry): void;
|
|
37
|
+
/** Whether the tenant holds the org (orgs are never removed from a live tenant, only by its reap). */
|
|
38
|
+
orgKnown(tenantId: string, orgId: string): boolean;
|
|
39
|
+
/** A key the unit wrote (the object records it owed to the directory). */
|
|
40
|
+
touched?(table: string, key: readonly string[]): void;
|
|
41
|
+
}
|
|
42
|
+
export declare function tenantTupleRows(sql: SqlStorage, tenantId: string, subject: string, relationPrefix: string): PermissionTupleRow[];
|
|
43
|
+
/** Every tenant-level tuple of the tenant, tombstones included (scope-local projection mirrors them). */
|
|
44
|
+
export declare function dumpTenantTupleRows(sql: SqlStorage, tenantId: string): PermissionTupleRow[];
|
|
45
|
+
/** Members of an org. Live only unless `includeRevoked` — revoked rows are evidence. */
|
|
46
|
+
export declare function listMemberRows(sql: SqlStorage, tenantId: string, object: string, includeRevoked: boolean): MemberTupleRow[];
|
|
47
|
+
/** The tenant-level reads a bound asks inside a unit (#1184), over `sql`. */
|
|
48
|
+
export declare function tenantDirectoryReaderOver(sql: SqlStorage, now: () => string): TenantDirectoryReader;
|
|
49
|
+
/** A tenant tuple, upserted (a re-grant un-tombstones it). */
|
|
50
|
+
export declare function writeTenantTupleIn(store: TupleStore, tenantId: string, subject: string, relation: string, object: string, expiresAt: string | null): void;
|
|
51
|
+
/** Tombstone a tenant tuple by its exact (subject, relation, object). Whether a live row changed. */
|
|
52
|
+
export declare function revokeTenantTupleIn(store: TupleStore, tenantId: string, subject: string, relation: string, object: string, at: string): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* A tenant-level removal (#1184): the tombstone, the principal's removal fence (raised whether or
|
|
55
|
+
* not anything was held, so a removal of someone whose add is on its way still wins), and the admin
|
|
56
|
+
* row, written only when something changed. The time is minted here, in the unit.
|
|
57
|
+
*/
|
|
58
|
+
export declare function revokeAndFenceIn(store: TupleStore, tenantId: string, principal: string, relation: string, object: string, row: TupleAdminEntry): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* `assignRole` at the tenant node (#2526): the role's reservation judged against the role as stored
|
|
61
|
+
* (`reserved`: a role mixing system-reserved keys with others is refused, #2430), then the tuple and
|
|
62
|
+
* its admin row. A refusal writes nothing. A role not defined here is not judged.
|
|
63
|
+
*/
|
|
64
|
+
export declare function assignTenantRoleIn(store: TupleStore, tenantId: string, principal: string, roleKey: string, reserved: readonly string[], audit: TupleAdminEntry): {
|
|
65
|
+
refused?: string;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* A membership change as one unit (#1184, `HostAdmin.applyMembership`): an add's removal fence, the
|
|
69
|
+
* role (and its reservation, #2430), the bound (`boundedBy` covering every permission the role
|
|
70
|
+
* carries, against the tuples and the role as they stand now), the org when the change names one
|
|
71
|
+
* (#2047: bounded by `boundedBy`'s own live membership of it), then the writes and their admin rows.
|
|
72
|
+
*/
|
|
73
|
+
export declare function applyMembershipIn(store: TupleStore, change: MembershipChange, row: TupleAdminEntry, orgRow: TupleAdminEntry | undefined, reserved: readonly string[]): MembershipChangeResult;
|
|
74
|
+
/**
|
|
75
|
+
* One unit of a cut-over family (tuples and fences, then orgs), as the directory hands it to a cut-over
|
|
76
|
+
* tenant's object (`tupleFirst`). Whatever the directory alone holds is decided there first and handed
|
|
77
|
+
* in: whether an org exists while orgs are still the directory's (`orgKnown`; an org is never removed
|
|
78
|
+
* from a live tenant, so the answer cannot go stale; null once orgs are the object's, which then reads
|
|
79
|
+
* its own), the system switches a `system:` grant is refused under (asked in the same exclusive step as
|
|
80
|
+
* the write).
|
|
81
|
+
*/
|
|
82
|
+
export type TupleOp = {
|
|
83
|
+
kind: 'write';
|
|
84
|
+
subject: string;
|
|
85
|
+
relation: string;
|
|
86
|
+
object: string;
|
|
87
|
+
expiresAt: string | null;
|
|
88
|
+
audit: TupleAdminEntry | null;
|
|
89
|
+
} | {
|
|
90
|
+
kind: 'assignRole';
|
|
91
|
+
principal: string;
|
|
92
|
+
roleKey: string;
|
|
93
|
+
reserved: string[];
|
|
94
|
+
audit: TupleAdminEntry;
|
|
95
|
+
} | {
|
|
96
|
+
kind: 'membership';
|
|
97
|
+
change: MembershipChange;
|
|
98
|
+
row: TupleAdminEntry;
|
|
99
|
+
orgRow: TupleAdminEntry | null;
|
|
100
|
+
reserved: string[];
|
|
101
|
+
orgKnown: boolean | null;
|
|
102
|
+
} | {
|
|
103
|
+
kind: 'revokeAndFence';
|
|
104
|
+
principal: string;
|
|
105
|
+
relation: string;
|
|
106
|
+
object: string;
|
|
107
|
+
row: TupleAdminEntry;
|
|
108
|
+
} | {
|
|
109
|
+
kind: 'orgTuple';
|
|
110
|
+
orgId: string;
|
|
111
|
+
subject: string;
|
|
112
|
+
relation: string;
|
|
113
|
+
object: string;
|
|
114
|
+
expiresAt: string | null;
|
|
115
|
+
audit: TupleAdminEntry;
|
|
116
|
+
} | {
|
|
117
|
+
kind: 'createOrg';
|
|
118
|
+
orgId: string;
|
|
119
|
+
slug: string;
|
|
120
|
+
name: string;
|
|
121
|
+
createdAt: string;
|
|
122
|
+
audit: TupleAdminEntry | null;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* What each op answers: `write` nothing, `assignRole` its refusal, `membership` its result,
|
|
126
|
+
* `revokeAndFence` whether it changed, `orgTuple` nothing or an unknown org, `createOrg` whether it
|
|
127
|
+
* created or the slug's conflict (refusals cross the hop as data, so their code survives it).
|
|
128
|
+
*/
|
|
129
|
+
export type TupleOpResult = Record<string, never> | {
|
|
130
|
+
refused?: string;
|
|
131
|
+
} | MembershipChangeResult | {
|
|
132
|
+
changed: boolean;
|
|
133
|
+
} | {
|
|
134
|
+
unknownOrg?: true;
|
|
135
|
+
} | {
|
|
136
|
+
created: boolean;
|
|
137
|
+
} | {
|
|
138
|
+
conflict: string;
|
|
139
|
+
};
|
|
140
|
+
/** Run one op in the caller's transaction. */
|
|
141
|
+
export declare function runTupleOp(store: TupleStore, tenantId: string, op: TupleOp): TupleOpResult;
|
|
142
|
+
/** The family's reads, as the directory asks a cut-over tenant's object (`tupleRead`). */
|
|
143
|
+
export type TupleRead = {
|
|
144
|
+
kind: 'tuples';
|
|
145
|
+
subject: string;
|
|
146
|
+
relationPrefix: string;
|
|
147
|
+
} | {
|
|
148
|
+
kind: 'dump';
|
|
149
|
+
} | {
|
|
150
|
+
kind: 'members';
|
|
151
|
+
object: string;
|
|
152
|
+
includeRevoked: boolean;
|
|
153
|
+
} | {
|
|
154
|
+
kind: 'held';
|
|
155
|
+
switchKind: SwitchKind;
|
|
156
|
+
keys: string[];
|
|
157
|
+
now: string;
|
|
158
|
+
} | {
|
|
159
|
+
kind: 'org';
|
|
160
|
+
orgId: string;
|
|
161
|
+
} | {
|
|
162
|
+
kind: 'orgs';
|
|
163
|
+
};
|
|
164
|
+
export declare function runTupleRead(sql: SqlStorage, kernelSql: SwitchSql, tenantId: string, q: TupleRead): PermissionTupleRow[] | MemberTupleRow[] | string[] | OrgRow | OrgRow[] | null;
|
|
165
|
+
//# sourceMappingURL=directory-tenant-tuples.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directory-tenant-tuples.d.ts","sourceRoot":"","sources":["../src/directory-tenant-tuples.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAQL,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,EACvB,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,qBAAqB,EAC3B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAwC,KAAK,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAE/F,eAAO,MAAM,aAAa,4BAA4B,CAAC;AACvD,eAAO,MAAM,iBAAiB,gCAAgC,CAAC;AAE/D,6EAA6E;AAC7E,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,4FAA4F;AAC5F,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;I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,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,GAAG,aAAa,CA+B1F;AAED,0FAA0F;AAC1F,MAAM,MAAM,SAAS,GACjB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,GAC3D;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,OAAO,CAAA;CAAE,GAC5D;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GACrE;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAErB,wBAAgB,YAAY,CAC1B,GAAG,EAAE,UAAU,EACf,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,MAAM,EAChB,CAAC,EAAE,SAAS,GACX,kBAAkB,EAAE,GAAG,cAAc,EAAE,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAe/E"}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A tenant's tuples (`_substrat_tenant_tuples`: memberships, tenant-level role seats and grants) and
|
|
3
|
+
* the removal fences beside them (`_substrat_membership_fences`, #1184), as SQL over any store that
|
|
4
|
+
* holds the tables: the one directory (`ControlPlaneDO`) and, for a tenant whose directory reads are
|
|
5
|
+
* cut over (K-68 step 3e, `directory-cutover.ts`), the tenant's own `TenantDirectoryDO`. Both run these
|
|
6
|
+
* functions, so a membership change is bounded, a grant written and a revocation fenced the same way
|
|
7
|
+
* wherever it lands: the cut-over moves where the rows are read and first written, never what the
|
|
8
|
+
* code decides with them.
|
|
9
|
+
*
|
|
10
|
+
* Each unit is synchronous and runs inside the caller's transaction, so its reads and its writes are
|
|
11
|
+
* one unit wherever it runs. What differs between the two stores is `TupleStore`: where an admin row
|
|
12
|
+
* goes (the directory writes it; the object carries it to the directory with the write), whether the
|
|
13
|
+
* tenant holds an org (the directory's table until orgs are cut over), and which keys a unit wrote
|
|
14
|
+
* (the object records them owed).
|
|
15
|
+
*/
|
|
16
|
+
import { MEMBERSHIP_FENCE_SINCE_SQL, memberAddedAudit, orgChangeBound, RAISE_MEMBERSHIP_FENCE_SQL, reservedRoleRefusal, tenantCoverage, tenantHeldOf, } from '@substrat-run/kernel';
|
|
17
|
+
import { readRole } from './directory-tenant-roles.js';
|
|
18
|
+
import { createOrgIn, listOrgRows, readOrgRow } from './directory-tenant-orgs.js';
|
|
19
|
+
export const TENANT_TUPLES = '_substrat_tenant_tuples';
|
|
20
|
+
export const MEMBERSHIP_FENCES = '_substrat_membership_fences';
|
|
21
|
+
// -- reads ------------------------------------------------------------------
|
|
22
|
+
export function tenantTupleRows(sql, tenantId, subject, relationPrefix) {
|
|
23
|
+
return sql
|
|
24
|
+
.exec(`SELECT subject, relation, object, expires_at, revoked_at FROM _substrat_tenant_tuples
|
|
25
|
+
WHERE tenant_id = ? AND subject = ? AND relation LIKE ?`, tenantId, subject, `${relationPrefix}%`)
|
|
26
|
+
.toArray();
|
|
27
|
+
}
|
|
28
|
+
/** Every tenant-level tuple of the tenant, tombstones included (scope-local projection mirrors them). */
|
|
29
|
+
export function dumpTenantTupleRows(sql, tenantId) {
|
|
30
|
+
return sql
|
|
31
|
+
.exec(`SELECT subject, relation, object, expires_at, revoked_at FROM _substrat_tenant_tuples WHERE tenant_id = ?`, tenantId)
|
|
32
|
+
.toArray();
|
|
33
|
+
}
|
|
34
|
+
/** Members of an org. Live only unless `includeRevoked` — revoked rows are evidence. */
|
|
35
|
+
export function listMemberRows(sql, tenantId, object, includeRevoked) {
|
|
36
|
+
return sql
|
|
37
|
+
.exec(`SELECT subject, revoked_at, expires_at FROM _substrat_tenant_tuples
|
|
38
|
+
WHERE tenant_id = ? AND relation = 'member' AND object = ?
|
|
39
|
+
${includeRevoked ? '' : 'AND revoked_at IS NULL'}
|
|
40
|
+
ORDER BY subject`, tenantId, object)
|
|
41
|
+
.toArray();
|
|
42
|
+
}
|
|
43
|
+
/** The tenant-level reads a bound asks inside a unit (#1184), over `sql`. */
|
|
44
|
+
export function tenantDirectoryReaderOver(sql, now) {
|
|
45
|
+
return {
|
|
46
|
+
now,
|
|
47
|
+
tenantTuples: (tenantId, subject, prefix) => tenantTupleRows(sql, tenantId, subject, prefix),
|
|
48
|
+
getRole: (tenantId, key) => readRole(sql, tenantId, key),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
// -- writes -----------------------------------------------------------------
|
|
52
|
+
/** A tenant tuple, upserted (a re-grant un-tombstones it). */
|
|
53
|
+
export function writeTenantTupleIn(store, tenantId, subject, relation, object, expiresAt) {
|
|
54
|
+
store.sql.exec(`INSERT OR REPLACE INTO _substrat_tenant_tuples
|
|
55
|
+
(tenant_id, subject, relation, object, expires_at)
|
|
56
|
+
VALUES (?, ?, ?, ?, ?)`, tenantId, subject, relation, object, expiresAt);
|
|
57
|
+
store.touched?.(TENANT_TUPLES, [tenantId, subject, relation, object]);
|
|
58
|
+
}
|
|
59
|
+
/** Tombstone a tenant tuple by its exact (subject, relation, object). Whether a live row changed. */
|
|
60
|
+
export function revokeTenantTupleIn(store, tenantId, subject, relation, object, at) {
|
|
61
|
+
const changed = store.sql.exec(`UPDATE _substrat_tenant_tuples SET revoked_at = ?
|
|
62
|
+
WHERE tenant_id = ? AND subject = ? AND relation = ? AND object = ?
|
|
63
|
+
AND revoked_at IS NULL`, at, tenantId, subject, relation, object).rowsWritten > 0;
|
|
64
|
+
if (changed)
|
|
65
|
+
store.touched?.(TENANT_TUPLES, [tenantId, subject, relation, object]);
|
|
66
|
+
return changed;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A tenant-level removal (#1184): the tombstone, the principal's removal fence (raised whether or
|
|
70
|
+
* not anything was held, so a removal of someone whose add is on its way still wins), and the admin
|
|
71
|
+
* row, written only when something changed. The time is minted here, in the unit.
|
|
72
|
+
*/
|
|
73
|
+
export function revokeAndFenceIn(store, tenantId, principal, relation, object, row) {
|
|
74
|
+
const at = store.now();
|
|
75
|
+
const changed = revokeTenantTupleIn(store, tenantId, `principal:${principal}`, relation, object, at);
|
|
76
|
+
store.sql.exec(RAISE_MEMBERSHIP_FENCE_SQL, tenantId, principal, at);
|
|
77
|
+
store.touched?.(MEMBERSHIP_FENCES, [tenantId, principal]);
|
|
78
|
+
if (changed)
|
|
79
|
+
store.admin({ ...row, at });
|
|
80
|
+
return changed;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* `assignRole` at the tenant node (#2526): the role's reservation judged against the role as stored
|
|
84
|
+
* (`reserved`: a role mixing system-reserved keys with others is refused, #2430), then the tuple and
|
|
85
|
+
* its admin row. A refusal writes nothing. A role not defined here is not judged.
|
|
86
|
+
*/
|
|
87
|
+
export function assignTenantRoleIn(store, tenantId, principal, roleKey, reserved, audit) {
|
|
88
|
+
const role = reserved.length > 0 ? readRole(store.sql, tenantId, roleKey) : undefined;
|
|
89
|
+
const refused = role ? reservedRoleRefusal(role, new Set(reserved), 'platform') : null;
|
|
90
|
+
if (refused)
|
|
91
|
+
return { refused };
|
|
92
|
+
writeTenantTupleIn(store, tenantId, `principal:${principal}`, `role:${roleKey}`, `tenant:${tenantId}`, null);
|
|
93
|
+
store.admin(audit);
|
|
94
|
+
return {};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* A membership change as one unit (#1184, `HostAdmin.applyMembership`): an add's removal fence, the
|
|
98
|
+
* role (and its reservation, #2430), the bound (`boundedBy` covering every permission the role
|
|
99
|
+
* carries, against the tuples and the role as they stand now), the org when the change names one
|
|
100
|
+
* (#2047: bounded by `boundedBy`'s own live membership of it), then the writes and their admin rows.
|
|
101
|
+
*/
|
|
102
|
+
export function applyMembershipIn(store, change, row, orgRow, reserved) {
|
|
103
|
+
const { tenantId, principal, roleKey, boundedBy, orgId } = change;
|
|
104
|
+
const reader = tenantDirectoryReaderOver(store.sql, () => store.now());
|
|
105
|
+
if (change.op === 'add') {
|
|
106
|
+
const fence = store.sql.exec(MEMBERSHIP_FENCE_SINCE_SQL, tenantId, principal, change.unlessRemovedSince).toArray()[0];
|
|
107
|
+
if (fence)
|
|
108
|
+
return { applied: false, removedAt: fence.removed_at };
|
|
109
|
+
}
|
|
110
|
+
const role = readRole(store.sql, tenantId, roleKey);
|
|
111
|
+
if (!role)
|
|
112
|
+
return { applied: false, unknownRole: roleKey };
|
|
113
|
+
const refused = change.op === 'add' ? reservedRoleRefusal(role, new Set(reserved), 'person') : null;
|
|
114
|
+
if (refused)
|
|
115
|
+
return { applied: false, reserved: refused };
|
|
116
|
+
const bound = tenantCoverage(reader, tenantId, boundedBy, role.permissions);
|
|
117
|
+
if (!bound.covered)
|
|
118
|
+
return { applied: false, missing: bound.missing };
|
|
119
|
+
const org = orgId ? { orgId, row: orgRow, ...orgChangeBound(reader, tenantId, { ...change, orgId }) } : undefined;
|
|
120
|
+
if (org) {
|
|
121
|
+
if (!org.row)
|
|
122
|
+
throw new Error('applyMembership: an org change needs its audit row');
|
|
123
|
+
if (!store.orgKnown(tenantId, org.orgId))
|
|
124
|
+
return { applied: false, unknownOrg: org.orgId };
|
|
125
|
+
if (!org.bounded)
|
|
126
|
+
return { applied: false, notMember: org.orgId };
|
|
127
|
+
}
|
|
128
|
+
if (change.op === 'remove') {
|
|
129
|
+
const roleTaken = revokeAndFenceIn(store, tenantId, principal, `role:${roleKey}`, `tenant:${tenantId}`, row);
|
|
130
|
+
const orgLeft = !!org && revokeAndFenceIn(store, tenantId, principal, 'member', `org:${org.orgId}`, { ...org.row, before: { principal, orgId: org.orgId } });
|
|
131
|
+
return { applied: true, changed: roleTaken || orgLeft };
|
|
132
|
+
}
|
|
133
|
+
const at = store.now();
|
|
134
|
+
writeTenantTupleIn(store, tenantId, `principal:${principal}`, `role:${roleKey}`, `tenant:${tenantId}`, null);
|
|
135
|
+
store.admin({ ...row, at });
|
|
136
|
+
if (org?.bounded) {
|
|
137
|
+
writeTenantTupleIn(store, tenantId, `principal:${principal}`, 'member', `org:${org.orgId}`, org.expiresAt);
|
|
138
|
+
store.admin({ ...org.row, after: memberAddedAudit(principal, org.orgId, org.expiresAt), at });
|
|
139
|
+
}
|
|
140
|
+
return { applied: true };
|
|
141
|
+
}
|
|
142
|
+
/** Run one op in the caller's transaction. */
|
|
143
|
+
export function runTupleOp(store, tenantId, op) {
|
|
144
|
+
switch (op.kind) {
|
|
145
|
+
case 'write':
|
|
146
|
+
writeTenantTupleIn(store, tenantId, op.subject, op.relation, op.object, op.expiresAt);
|
|
147
|
+
if (op.audit)
|
|
148
|
+
store.admin(op.audit);
|
|
149
|
+
return {};
|
|
150
|
+
case 'assignRole':
|
|
151
|
+
return assignTenantRoleIn(store, tenantId, op.principal, op.roleKey, op.reserved, op.audit);
|
|
152
|
+
case 'membership':
|
|
153
|
+
if (op.change.tenantId !== tenantId)
|
|
154
|
+
throw new Error(`a membership change of ${op.change.tenantId} is not ${tenantId}'s`);
|
|
155
|
+
return applyMembershipIn(store, op.change, op.row, op.orgRow ?? undefined, op.reserved);
|
|
156
|
+
case 'revokeAndFence':
|
|
157
|
+
return { changed: revokeAndFenceIn(store, tenantId, op.principal, op.relation, op.object, op.row) };
|
|
158
|
+
case 'orgTuple':
|
|
159
|
+
if (!store.orgKnown(tenantId, op.orgId))
|
|
160
|
+
return { unknownOrg: true };
|
|
161
|
+
writeTenantTupleIn(store, tenantId, op.subject, op.relation, op.object, op.expiresAt);
|
|
162
|
+
store.admin(op.audit);
|
|
163
|
+
return {};
|
|
164
|
+
case 'createOrg': {
|
|
165
|
+
let created;
|
|
166
|
+
try {
|
|
167
|
+
created = createOrgIn(store, op.orgId, tenantId, op.slug, op.name, op.createdAt);
|
|
168
|
+
}
|
|
169
|
+
catch (err) {
|
|
170
|
+
// Thrown before any write: answered as data, so the directory rethrows it with its code.
|
|
171
|
+
if (err.code === 'conflict')
|
|
172
|
+
return { conflict: err.message };
|
|
173
|
+
throw err;
|
|
174
|
+
}
|
|
175
|
+
if (created && op.audit)
|
|
176
|
+
store.admin(op.audit);
|
|
177
|
+
return { created };
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
export function runTupleRead(sql, kernelSql, tenantId, q) {
|
|
182
|
+
switch (q.kind) {
|
|
183
|
+
case 'tuples':
|
|
184
|
+
return tenantTupleRows(sql, tenantId, q.subject, q.relationPrefix);
|
|
185
|
+
case 'dump':
|
|
186
|
+
return dumpTenantTupleRows(sql, tenantId);
|
|
187
|
+
case 'members':
|
|
188
|
+
return listMemberRows(sql, tenantId, q.object, q.includeRevoked);
|
|
189
|
+
case 'held':
|
|
190
|
+
return tenantHeldOf(kernelSql, q.switchKind, tenantId, q.keys, q.now);
|
|
191
|
+
case 'org':
|
|
192
|
+
return readOrgRow(sql, tenantId, q.orgId) ?? null;
|
|
193
|
+
case 'orgs':
|
|
194
|
+
return listOrgRows(sql, tenantId);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=directory-tenant-tuples.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directory-tenant-tuples.js","sourceRoot":"","sources":["../src/directory-tenant-tuples.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EACL,0BAA0B,EAC1B,gBAAgB,EAChB,cAAc,EACd,0BAA0B,EAC1B,mBAAmB,EACnB,cAAc,EACd,YAAY,GAOb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAe,MAAM,4BAA4B,CA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CAAC;IACH,CAAC;AACH,CAAC;AAWD,MAAM,UAAU,YAAY,CAC1B,GAAe,EACf,SAAoB,EACpB,QAAgB,EAChB,CAAY;IAEZ,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;QACf,KAAK,QAAQ;YACX,OAAO,eAAe,CAAC,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,cAAc,CAAC,CAAC;QACrE,KAAK,MAAM;YACT,OAAO,mBAAmB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QAC5C,KAAK,SAAS;YACZ,OAAO,cAAc,CAAC,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,cAAc,CAAC,CAAC;QACnE,KAAK,MAAM;YACT,OAAO,YAAY,CAAC,SAAS,EAAE,CAAC,CAAC,UAAU,EAAE,QAAQ,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;QACxE,KAAK,KAAK;YACR,OAAO,UAAU,CAAC,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;QACpD,KAAK,MAAM;YACT,OAAO,WAAW,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IACtC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #3676: what `routeExecutorEventToPlatform` answers when the delivery it was asked to route is no
|
|
3
|
+
* longer due in the scope's journal — another pass acting on the same due read routed it first, or
|
|
4
|
+
* it was dead-lettered, or it is waiting out a backoff. Nothing was written. Not an attempt, and not
|
|
5
|
+
* a full room either (`null`): the caller's pass carries on with the next delivery.
|
|
6
|
+
*
|
|
7
|
+
* A literal rather than an object so it crosses the RPC as itself. A platform request id is a ulid,
|
|
8
|
+
* so it can never read as one. A coordinator older than this answer counts it as routed, which
|
|
9
|
+
* over-counts its report and writes nothing twice.
|
|
10
|
+
*/
|
|
11
|
+
export declare const EXECUTOR_ROUTE_NOT_DUE = "not-due";
|
|
12
|
+
export type ExecutorRouteNotDue = typeof EXECUTOR_ROUTE_NOT_DUE;
|
|
13
|
+
//# sourceMappingURL=executor-route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor-route.d.ts","sourceRoot":"","sources":["../src/executor-route.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,YAAY,CAAC;AAChD,MAAM,MAAM,mBAAmB,GAAG,OAAO,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #3676: what `routeExecutorEventToPlatform` answers when the delivery it was asked to route is no
|
|
3
|
+
* longer due in the scope's journal — another pass acting on the same due read routed it first, or
|
|
4
|
+
* it was dead-lettered, or it is waiting out a backoff. Nothing was written. Not an attempt, and not
|
|
5
|
+
* a full room either (`null`): the caller's pass carries on with the next delivery.
|
|
6
|
+
*
|
|
7
|
+
* A literal rather than an object so it crosses the RPC as itself. A platform request id is a ulid,
|
|
8
|
+
* so it can never read as one. A coordinator older than this answer counts it as routed, which
|
|
9
|
+
* over-counts its report and writes nothing twice.
|
|
10
|
+
*/
|
|
11
|
+
export const EXECUTOR_ROUTE_NOT_DUE = 'not-due';
|
|
12
|
+
//# sourceMappingURL=executor-route.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor-route.js","sourceRoot":"","sources":["../src/executor-route.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,SAAS,CAAC"}
|