@fabrika/auth-core 0.9.0-dev.12 → 0.9.0-dev.13
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/package.json +1 -1
- package/src/contract-canonical.ts +109 -0
- package/src/contract.ts +92 -0
- package/src/types.ts +18 -0
- package/types/src/contract-canonical.d.ts +6 -1
- package/types/src/contract.d.ts +102 -0
- package/types/src/types.d.ts +14 -0
package/package.json
CHANGED
|
@@ -4,12 +4,19 @@
|
|
|
4
4
|
import type {
|
|
5
5
|
BodyAdmission,
|
|
6
6
|
Caller,
|
|
7
|
+
ColumnTestArtifact,
|
|
8
|
+
ConditionArtifact,
|
|
9
|
+
ConditionLiteralArtifact,
|
|
10
|
+
ConfersArtifact,
|
|
7
11
|
ContractArtifact,
|
|
8
12
|
CspSource,
|
|
9
13
|
EndpointRow,
|
|
14
|
+
MemberRevealsArtifact,
|
|
10
15
|
MountArtifact,
|
|
11
16
|
OutputShape,
|
|
17
|
+
RevealsArtifact,
|
|
12
18
|
RoleArtifact,
|
|
19
|
+
RowsTestArtifact,
|
|
13
20
|
SchemaShape,
|
|
14
21
|
TableActionArtifact,
|
|
15
22
|
TablePolicyArtifact,
|
|
@@ -27,6 +34,7 @@ export function canonicalizeArtifact(artifact: ContractArtifact): ContractArtifa
|
|
|
27
34
|
dimensions: artifact.dimensions,
|
|
28
35
|
actions: artifact.actions,
|
|
29
36
|
roles: mapValues(artifact.roles, canonicalRole),
|
|
37
|
+
...(artifact.relations === undefined ? {} : { relations: artifact.relations }),
|
|
30
38
|
mounts: mapValues(artifact.mounts, canonicalMount),
|
|
31
39
|
files: mapValues(artifact.files, (collection) => ({
|
|
32
40
|
...collection,
|
|
@@ -101,6 +109,7 @@ function canonicalRole(role: RoleArtifact): RoleArtifact {
|
|
|
101
109
|
grants: sorted(role.grants),
|
|
102
110
|
member: role.member === null ? null : { scope: role.member.scope, assignableBy: sorted(role.member.assignableBy) },
|
|
103
111
|
...(role.external === true ? { external: true } : {}),
|
|
112
|
+
...(role.via === undefined ? {} : { via: mapValues(role.via, sorted) }),
|
|
104
113
|
}
|
|
105
114
|
}
|
|
106
115
|
|
|
@@ -151,9 +160,109 @@ function canonicalTable(table: TablePolicyArtifact): TablePolicyArtifact {
|
|
|
151
160
|
scope: table.scope.mode === 'child' ? { ...table.scope, inherit: sorted(table.scope.inherit) } : table.scope,
|
|
152
161
|
insert: sorted(table.insert),
|
|
153
162
|
update: sorted(table.update),
|
|
163
|
+
...(table.when === undefined ? {} : { when: mapValues(table.when, canonicalCondition) }),
|
|
164
|
+
...(table.confers === undefined ? {} : { confers: mapValues(table.confers, canonicalConfers) }),
|
|
165
|
+
...(table.reveals === undefined ? {} : { reveals: mapValues(table.reveals, canonicalReveals) }),
|
|
166
|
+
...(table.memberReveals === undefined ? {} : { memberReveals: mapValues(table.memberReveals, canonicalMemberReveals) }),
|
|
154
167
|
}
|
|
155
168
|
}
|
|
156
169
|
|
|
170
|
+
function canonicalConfers(confers: ConfersArtifact): ConfersArtifact {
|
|
171
|
+
return confers.when === undefined ? confers : { ...confers, when: canonicalCondition(confers.when) }
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function canonicalReveals(reveals: RevealsArtifact): RevealsArtifact {
|
|
175
|
+
return {
|
|
176
|
+
...reveals,
|
|
177
|
+
actions: sorted(reveals.actions),
|
|
178
|
+
...(reveals.when === undefined ? {} : { when: canonicalCondition(reveals.when) }),
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function canonicalMemberReveals(reveals: MemberRevealsArtifact): MemberRevealsArtifact {
|
|
183
|
+
return {
|
|
184
|
+
...reveals,
|
|
185
|
+
actions: sorted(reveals.actions),
|
|
186
|
+
...(reveals.when === undefined ? {} : { when: canonicalCondition(reveals.when) }),
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* A condition with its connectives' operands and its `in` / `notIn` lists sorted by their canonical JSON: AND and OR
|
|
192
|
+
* commute and a list is a set, so neither order changes which rows it admits.
|
|
193
|
+
*/
|
|
194
|
+
export function canonicalCondition(condition: ConditionArtifact): ConditionArtifact {
|
|
195
|
+
if ('allOf' in condition && isConditionList(condition.allOf)) {
|
|
196
|
+
return { allOf: sortedConditions(condition.allOf) }
|
|
197
|
+
}
|
|
198
|
+
if ('anyOf' in condition && isConditionList(condition.anyOf)) {
|
|
199
|
+
return { anyOf: sortedConditions(condition.anyOf) }
|
|
200
|
+
}
|
|
201
|
+
if ('not' in condition && isCondition(condition.not)) {
|
|
202
|
+
return { not: canonicalCondition(condition.not) }
|
|
203
|
+
}
|
|
204
|
+
const rows = canonicalRows(condition)
|
|
205
|
+
if (rows !== undefined) return rows
|
|
206
|
+
const tests: Record<string, ColumnTestArtifact | RowsTestArtifact> = {}
|
|
207
|
+
for (const [path, test] of Object.entries(condition)) {
|
|
208
|
+
const after = isCondition(test) ? canonicalRows(test) : undefined
|
|
209
|
+
if (after !== undefined) {
|
|
210
|
+
tests[path] = after
|
|
211
|
+
continue
|
|
212
|
+
}
|
|
213
|
+
// A parsed artifact holds nothing else here; dropping an unknown test would widen what the condition admits.
|
|
214
|
+
if (!isColumnTest(test)) throw new Error(`the condition test of ${path} is not a column test`)
|
|
215
|
+
tests[path] = canonicalTest(test)
|
|
216
|
+
}
|
|
217
|
+
return tests
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** `some` or `none` with its condition canonical, or `undefined` for any other form: one beside another key is no rows test. */
|
|
221
|
+
function canonicalRows(condition: object): RowsTestArtifact | undefined {
|
|
222
|
+
if (Object.keys(condition).length !== 1) return undefined
|
|
223
|
+
if ('some' in condition && isConditionRecord(condition.some)) {
|
|
224
|
+
return { some: mapValues(condition.some, canonicalCondition) }
|
|
225
|
+
}
|
|
226
|
+
if ('none' in condition && isConditionRecord(condition.none)) {
|
|
227
|
+
return { none: mapValues(condition.none, canonicalCondition) }
|
|
228
|
+
}
|
|
229
|
+
return undefined
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function canonicalTest(test: ColumnTestArtifact): ColumnTestArtifact {
|
|
233
|
+
return {
|
|
234
|
+
...test,
|
|
235
|
+
...(test.in === undefined ? {} : { in: sortedLiterals(test.in) }),
|
|
236
|
+
...(test.notIn === undefined ? {} : { notIn: sortedLiterals(test.notIn) }),
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function sortedConditions(conditions: readonly ConditionArtifact[]): ConditionArtifact[] {
|
|
241
|
+
return conditions.map(canonicalCondition).sort((a, b) => compare(canonicalJson(a), canonicalJson(b)))
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function sortedLiterals(values: readonly ConditionLiteralArtifact[]): ConditionLiteralArtifact[] {
|
|
245
|
+
return [...values].sort((a, b) => compare(JSON.stringify(a), JSON.stringify(b)))
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function isCondition(value: unknown): value is ConditionArtifact {
|
|
249
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function isConditionRecord(value: unknown): value is Readonly<Record<string, ConditionArtifact>> {
|
|
253
|
+
return isCondition(value) && Object.values(value).every(isCondition)
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function isConditionList(value: unknown): value is readonly ConditionArtifact[] {
|
|
257
|
+
return Array.isArray(value) && value.every(isCondition)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const COLUMN_TEST_OPERATORS: ReadonlySet<string> = new Set(['eq', 'notEq', 'in', 'notIn', 'isNull', 'lt', 'lte', 'gt', 'gte'])
|
|
261
|
+
|
|
262
|
+
function isColumnTest(value: unknown): value is ColumnTestArtifact {
|
|
263
|
+
return isCondition(value) && Object.keys(value).every((operator) => COLUMN_TEST_OPERATORS.has(operator))
|
|
264
|
+
}
|
|
265
|
+
|
|
157
266
|
function canonicalizeEndpoint(row: EndpointRow): EndpointRow {
|
|
158
267
|
const shared = {
|
|
159
268
|
admission: row.admission === null ? null : canonicalAdmission(row.admission),
|
package/src/contract.ts
CHANGED
|
@@ -24,6 +24,11 @@ export interface ContractArtifact extends EndpointTable {
|
|
|
24
24
|
/** Action → description. Exact actions only; the artifact holds no wildcard. */
|
|
25
25
|
readonly actions: Readonly<Record<string, string>>
|
|
26
26
|
readonly roles: Readonly<Record<string, RoleArtifact>>
|
|
27
|
+
/**
|
|
28
|
+
* The relations a table's rows confer (`relations: { owner: { dimension: 'project' } }`): a role's `via` holds its
|
|
29
|
+
* actions where a row names the caller. Absent unless declared, so the digest stays.
|
|
30
|
+
*/
|
|
31
|
+
readonly relations?: Readonly<Record<string, RelationArtifact>>
|
|
27
32
|
readonly mounts: Readonly<Record<string, MountArtifact>>
|
|
28
33
|
readonly files: Readonly<Record<string, FileCollectionArtifact>>
|
|
29
34
|
/**
|
|
@@ -484,6 +489,16 @@ export interface RoleArtifact {
|
|
|
484
489
|
readonly member: { readonly scope: string; readonly assignableBy: readonly string[] } | null
|
|
485
490
|
/** An external principal may hold this membership role (ADR-0051). Absent unless declared, so digests stay. */
|
|
486
491
|
readonly external?: true
|
|
492
|
+
/**
|
|
493
|
+
* Relation → actions the holder of a global grant of this role holds at each node a relation row names them at.
|
|
494
|
+
* Absent unless declared, so digests stay.
|
|
495
|
+
*/
|
|
496
|
+
readonly via?: Readonly<Record<string, readonly string[]>>
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/** A relation of the vocabulary: the dimension whose nodes its rows name. */
|
|
500
|
+
export interface RelationArtifact {
|
|
501
|
+
readonly dimension: string
|
|
487
502
|
}
|
|
488
503
|
|
|
489
504
|
// ── Mounts and companions ───────────────────────────────────────────────────────────────────────
|
|
@@ -866,6 +881,83 @@ export interface TablePolicyArtifact {
|
|
|
866
881
|
* Absent for a table, so the digest stays.
|
|
867
882
|
*/
|
|
868
883
|
readonly view?: true
|
|
884
|
+
/** Relation → how a row of this table confers it. Absent unless declared, so the digest stays. */
|
|
885
|
+
readonly confers?: Readonly<Record<string, ConfersArtifact>>
|
|
886
|
+
/** Action → the condition a row must meet for it, narrowing what any grant of it reaches. Absent unless declared. */
|
|
887
|
+
readonly when?: Readonly<Record<string, ConditionArtifact>>
|
|
888
|
+
/**
|
|
889
|
+
* Relation of the table's own dimension → the ancestor its rows reveal. Absent unless declared, so the digest stays.
|
|
890
|
+
* A reader that ignores it reaches less, never more.
|
|
891
|
+
*/
|
|
892
|
+
readonly reveals?: Readonly<Record<string, RevealsArtifact>>
|
|
893
|
+
/**
|
|
894
|
+
* Dimension outside the chain → the column a `Within`'s read reaches a row through. Absent unless declared, so the
|
|
895
|
+
* digest stays. A reader that ignores it reaches less, never more.
|
|
896
|
+
*/
|
|
897
|
+
readonly readThrough?: Readonly<Record<string, string>>
|
|
898
|
+
/**
|
|
899
|
+
* The table's own dimension → the ancestor its rows reveal to a grant at their node, for a `Within`'s reads. Absent
|
|
900
|
+
* unless declared, so the digest stays. A reader that ignores it reaches less, never more.
|
|
901
|
+
*/
|
|
902
|
+
readonly memberReveals?: Readonly<Record<string, MemberRevealsArtifact>>
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
/** A row reveals its node in `to` for `actions` to a grant of them at the row's own node, while `when` admits the row. */
|
|
906
|
+
export interface MemberRevealsArtifact {
|
|
907
|
+
readonly to: string
|
|
908
|
+
readonly actions: readonly string[]
|
|
909
|
+
readonly when?: ConditionArtifact
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
/** A row the relation reaches reveals its node in `to` for `actions`, while `when` admits the row. */
|
|
913
|
+
export interface RevealsArtifact {
|
|
914
|
+
readonly to: string
|
|
915
|
+
readonly actions: readonly string[]
|
|
916
|
+
readonly when?: ConditionArtifact
|
|
917
|
+
/** On a reveal matched through `readThrough`: an insert delegates, and `self` lets it name a node its writer holds. */
|
|
918
|
+
readonly assign?: { readonly self: boolean }
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
/** A row names `principal` at the node in `node`, until `expires`, while `when` admits it; `assign` bounds its writer. */
|
|
922
|
+
export interface ConfersArtifact {
|
|
923
|
+
/** The column that holds the principal, or `<column>.<principal column>` through one foreign key of the table. */
|
|
924
|
+
readonly principal: string
|
|
925
|
+
readonly node: string
|
|
926
|
+
readonly expires: string | null
|
|
927
|
+
readonly when?: ConditionArtifact
|
|
928
|
+
readonly assign: { readonly maxDays: number | null; readonly self: boolean } | null
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
/**
|
|
932
|
+
* A structured row condition: connectives, `{ '<column or fk_column.column>': test }` with every test holding, or
|
|
933
|
+
* `some` / `none` of the rows of one table whose foreign key names the row, also at the end of a path
|
|
934
|
+
* (`{ '<fk_column>': { some: … } }`). Each form is absent from a condition that does not use it, so its digest stays.
|
|
935
|
+
*/
|
|
936
|
+
export type ConditionArtifact =
|
|
937
|
+
| { readonly allOf: readonly ConditionArtifact[] }
|
|
938
|
+
| { readonly anyOf: readonly ConditionArtifact[] }
|
|
939
|
+
| { readonly not: ConditionArtifact }
|
|
940
|
+
| RowsTestArtifact
|
|
941
|
+
| { readonly [path: string]: ColumnTestArtifact | RowsTestArtifact }
|
|
942
|
+
|
|
943
|
+
/** `some` or `none` of the rows of one table whose foreign key names the row. */
|
|
944
|
+
export type RowsTestArtifact =
|
|
945
|
+
| { readonly some: Readonly<Record<string, ConditionArtifact>> }
|
|
946
|
+
| { readonly none: Readonly<Record<string, ConditionArtifact>> }
|
|
947
|
+
|
|
948
|
+
export type ConditionLiteralArtifact = string | number | boolean
|
|
949
|
+
|
|
950
|
+
/** One operator of a column test; `{ now: true }` compares a timestamp with the statement's clock. */
|
|
951
|
+
export interface ColumnTestArtifact {
|
|
952
|
+
readonly eq?: ConditionLiteralArtifact
|
|
953
|
+
readonly notEq?: ConditionLiteralArtifact
|
|
954
|
+
readonly in?: readonly ConditionLiteralArtifact[]
|
|
955
|
+
readonly notIn?: readonly ConditionLiteralArtifact[]
|
|
956
|
+
readonly isNull?: boolean
|
|
957
|
+
readonly lt?: ConditionLiteralArtifact | { readonly now: true }
|
|
958
|
+
readonly lte?: ConditionLiteralArtifact | { readonly now: true }
|
|
959
|
+
readonly gt?: ConditionLiteralArtifact | { readonly now: true }
|
|
960
|
+
readonly gte?: ConditionLiteralArtifact | { readonly now: true }
|
|
869
961
|
}
|
|
870
962
|
|
|
871
963
|
/** A column's own read action, its own write action, or both; an absent one is left out. */
|
package/src/types.ts
CHANGED
|
@@ -45,6 +45,18 @@ export interface Scope {
|
|
|
45
45
|
value: string
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* The pseudo-scope of a relation entry: `{ type: '~rel', value: <relation> }` means the action is held where a row of
|
|
50
|
+
* the application names the principal in that relation. No dimension may start with `~`, so no reader that compares
|
|
51
|
+
* scopes by `(type, value)` mistakes one for a dimension value, and none resolves it but the framework.
|
|
52
|
+
*/
|
|
53
|
+
export const RELATION_SCOPE_TYPE = '~rel'
|
|
54
|
+
|
|
55
|
+
/** A scope type no dimension, grant or key may name: IAM derives a `~` entry itself and never stores one. */
|
|
56
|
+
export function isReservedScopeType(type: string): boolean {
|
|
57
|
+
return type.startsWith('~')
|
|
58
|
+
}
|
|
59
|
+
|
|
48
60
|
export interface PermissionEntry {
|
|
49
61
|
action: string
|
|
50
62
|
/** null = global / all scopes */
|
|
@@ -80,6 +92,12 @@ export interface RoleDef {
|
|
|
80
92
|
member?: { scope: string; assignableBy?: string[] }
|
|
81
93
|
/** An external principal may hold this membership role (ADR-0051). Only a membership role may declare it. */
|
|
82
94
|
external?: true
|
|
95
|
+
/**
|
|
96
|
+
* Relation → exact actions. A GLOBAL grant of this role also carries `{ action, scope: { type: '~rel', value:
|
|
97
|
+
* relation } }`: the application holds the action where one of its rows names the principal in that relation.
|
|
98
|
+
* Only an application-wide internal role declares it.
|
|
99
|
+
*/
|
|
100
|
+
via?: Record<string, string[]>
|
|
83
101
|
}
|
|
84
102
|
|
|
85
103
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BodyAdmission, ContractArtifact, OutputShape, SchemaShape, TableActionArtifact } from './contract';
|
|
1
|
+
import type { BodyAdmission, ConditionArtifact, ContractArtifact, OutputShape, SchemaShape, TableActionArtifact } from './contract';
|
|
2
2
|
/**
|
|
3
3
|
* The artifact with every array whose order carries no meaning sorted: endpoints by id, and every list of names.
|
|
4
4
|
* Tuple items and union options keep their order, because it changes what a schema admits. Object keys are left
|
|
@@ -11,6 +11,11 @@ export declare function canonicalArtifactJson(artifact: ContractArtifact): strin
|
|
|
11
11
|
export declare function canonicalJson(value: unknown): string;
|
|
12
12
|
/** Each action of one table operation, `[]` for none: how a reader of the artifact reads `actions.read` and the others. */
|
|
13
13
|
export declare function tableActions(actions: TableActionArtifact | null): readonly string[];
|
|
14
|
+
/**
|
|
15
|
+
* A condition with its connectives' operands and its `in` / `notIn` lists sorted by their canonical JSON: AND and OR
|
|
16
|
+
* commute and a list is a set, so neither order changes which rows it admits.
|
|
17
|
+
*/
|
|
18
|
+
export declare function canonicalCondition(condition: ConditionArtifact): ConditionArtifact;
|
|
14
19
|
/** A body admission with its content types sorted. */
|
|
15
20
|
export declare function canonicalAdmission(admission: BodyAdmission): BodyAdmission;
|
|
16
21
|
/** An output shape: an attachment keeps its column order, which is the file's; each column's shape is canonical. */
|
package/types/src/contract.d.ts
CHANGED
|
@@ -19,6 +19,11 @@ export interface ContractArtifact extends EndpointTable {
|
|
|
19
19
|
/** Action → description. Exact actions only; the artifact holds no wildcard. */
|
|
20
20
|
readonly actions: Readonly<Record<string, string>>;
|
|
21
21
|
readonly roles: Readonly<Record<string, RoleArtifact>>;
|
|
22
|
+
/**
|
|
23
|
+
* The relations a table's rows confer (`relations: { owner: { dimension: 'project' } }`): a role's `via` holds its
|
|
24
|
+
* actions where a row names the caller. Absent unless declared, so the digest stays.
|
|
25
|
+
*/
|
|
26
|
+
readonly relations?: Readonly<Record<string, RelationArtifact>>;
|
|
22
27
|
readonly mounts: Readonly<Record<string, MountArtifact>>;
|
|
23
28
|
readonly files: Readonly<Record<string, FileCollectionArtifact>>;
|
|
24
29
|
/**
|
|
@@ -436,6 +441,15 @@ export interface RoleArtifact {
|
|
|
436
441
|
} | null;
|
|
437
442
|
/** An external principal may hold this membership role (ADR-0051). Absent unless declared, so digests stay. */
|
|
438
443
|
readonly external?: true;
|
|
444
|
+
/**
|
|
445
|
+
* Relation → actions the holder of a global grant of this role holds at each node a relation row names them at.
|
|
446
|
+
* Absent unless declared, so digests stay.
|
|
447
|
+
*/
|
|
448
|
+
readonly via?: Readonly<Record<string, readonly string[]>>;
|
|
449
|
+
}
|
|
450
|
+
/** A relation of the vocabulary: the dimension whose nodes its rows name. */
|
|
451
|
+
export interface RelationArtifact {
|
|
452
|
+
readonly dimension: string;
|
|
439
453
|
}
|
|
440
454
|
export type MountArtifact = RpcMountArtifact | LinkMountArtifact | SpaMountArtifact | HealthMountArtifact | FormMountArtifact | WebhookMountArtifact;
|
|
441
455
|
export interface RpcMountArtifact {
|
|
@@ -777,6 +791,94 @@ export interface TablePolicyArtifact {
|
|
|
777
791
|
* Absent for a table, so the digest stays.
|
|
778
792
|
*/
|
|
779
793
|
readonly view?: true;
|
|
794
|
+
/** Relation → how a row of this table confers it. Absent unless declared, so the digest stays. */
|
|
795
|
+
readonly confers?: Readonly<Record<string, ConfersArtifact>>;
|
|
796
|
+
/** Action → the condition a row must meet for it, narrowing what any grant of it reaches. Absent unless declared. */
|
|
797
|
+
readonly when?: Readonly<Record<string, ConditionArtifact>>;
|
|
798
|
+
/**
|
|
799
|
+
* Relation of the table's own dimension → the ancestor its rows reveal. Absent unless declared, so the digest stays.
|
|
800
|
+
* A reader that ignores it reaches less, never more.
|
|
801
|
+
*/
|
|
802
|
+
readonly reveals?: Readonly<Record<string, RevealsArtifact>>;
|
|
803
|
+
/**
|
|
804
|
+
* Dimension outside the chain → the column a `Within`'s read reaches a row through. Absent unless declared, so the
|
|
805
|
+
* digest stays. A reader that ignores it reaches less, never more.
|
|
806
|
+
*/
|
|
807
|
+
readonly readThrough?: Readonly<Record<string, string>>;
|
|
808
|
+
/**
|
|
809
|
+
* The table's own dimension → the ancestor its rows reveal to a grant at their node, for a `Within`'s reads. Absent
|
|
810
|
+
* unless declared, so the digest stays. A reader that ignores it reaches less, never more.
|
|
811
|
+
*/
|
|
812
|
+
readonly memberReveals?: Readonly<Record<string, MemberRevealsArtifact>>;
|
|
813
|
+
}
|
|
814
|
+
/** A row reveals its node in `to` for `actions` to a grant of them at the row's own node, while `when` admits the row. */
|
|
815
|
+
export interface MemberRevealsArtifact {
|
|
816
|
+
readonly to: string;
|
|
817
|
+
readonly actions: readonly string[];
|
|
818
|
+
readonly when?: ConditionArtifact;
|
|
819
|
+
}
|
|
820
|
+
/** A row the relation reaches reveals its node in `to` for `actions`, while `when` admits the row. */
|
|
821
|
+
export interface RevealsArtifact {
|
|
822
|
+
readonly to: string;
|
|
823
|
+
readonly actions: readonly string[];
|
|
824
|
+
readonly when?: ConditionArtifact;
|
|
825
|
+
/** On a reveal matched through `readThrough`: an insert delegates, and `self` lets it name a node its writer holds. */
|
|
826
|
+
readonly assign?: {
|
|
827
|
+
readonly self: boolean;
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
/** A row names `principal` at the node in `node`, until `expires`, while `when` admits it; `assign` bounds its writer. */
|
|
831
|
+
export interface ConfersArtifact {
|
|
832
|
+
/** The column that holds the principal, or `<column>.<principal column>` through one foreign key of the table. */
|
|
833
|
+
readonly principal: string;
|
|
834
|
+
readonly node: string;
|
|
835
|
+
readonly expires: string | null;
|
|
836
|
+
readonly when?: ConditionArtifact;
|
|
837
|
+
readonly assign: {
|
|
838
|
+
readonly maxDays: number | null;
|
|
839
|
+
readonly self: boolean;
|
|
840
|
+
} | null;
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* A structured row condition: connectives, `{ '<column or fk_column.column>': test }` with every test holding, or
|
|
844
|
+
* `some` / `none` of the rows of one table whose foreign key names the row, also at the end of a path
|
|
845
|
+
* (`{ '<fk_column>': { some: … } }`). Each form is absent from a condition that does not use it, so its digest stays.
|
|
846
|
+
*/
|
|
847
|
+
export type ConditionArtifact = {
|
|
848
|
+
readonly allOf: readonly ConditionArtifact[];
|
|
849
|
+
} | {
|
|
850
|
+
readonly anyOf: readonly ConditionArtifact[];
|
|
851
|
+
} | {
|
|
852
|
+
readonly not: ConditionArtifact;
|
|
853
|
+
} | RowsTestArtifact | {
|
|
854
|
+
readonly [path: string]: ColumnTestArtifact | RowsTestArtifact;
|
|
855
|
+
};
|
|
856
|
+
/** `some` or `none` of the rows of one table whose foreign key names the row. */
|
|
857
|
+
export type RowsTestArtifact = {
|
|
858
|
+
readonly some: Readonly<Record<string, ConditionArtifact>>;
|
|
859
|
+
} | {
|
|
860
|
+
readonly none: Readonly<Record<string, ConditionArtifact>>;
|
|
861
|
+
};
|
|
862
|
+
export type ConditionLiteralArtifact = string | number | boolean;
|
|
863
|
+
/** One operator of a column test; `{ now: true }` compares a timestamp with the statement's clock. */
|
|
864
|
+
export interface ColumnTestArtifact {
|
|
865
|
+
readonly eq?: ConditionLiteralArtifact;
|
|
866
|
+
readonly notEq?: ConditionLiteralArtifact;
|
|
867
|
+
readonly in?: readonly ConditionLiteralArtifact[];
|
|
868
|
+
readonly notIn?: readonly ConditionLiteralArtifact[];
|
|
869
|
+
readonly isNull?: boolean;
|
|
870
|
+
readonly lt?: ConditionLiteralArtifact | {
|
|
871
|
+
readonly now: true;
|
|
872
|
+
};
|
|
873
|
+
readonly lte?: ConditionLiteralArtifact | {
|
|
874
|
+
readonly now: true;
|
|
875
|
+
};
|
|
876
|
+
readonly gt?: ConditionLiteralArtifact | {
|
|
877
|
+
readonly now: true;
|
|
878
|
+
};
|
|
879
|
+
readonly gte?: ConditionLiteralArtifact | {
|
|
880
|
+
readonly now: true;
|
|
881
|
+
};
|
|
780
882
|
}
|
|
781
883
|
/** A column's own read action, its own write action, or both; an absent one is left out. */
|
|
782
884
|
export interface ColumnPolicyArtifact {
|
package/types/src/types.d.ts
CHANGED
|
@@ -34,6 +34,14 @@ export interface Scope {
|
|
|
34
34
|
type: string;
|
|
35
35
|
value: string;
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* The pseudo-scope of a relation entry: `{ type: '~rel', value: <relation> }` means the action is held where a row of
|
|
39
|
+
* the application names the principal in that relation. No dimension may start with `~`, so no reader that compares
|
|
40
|
+
* scopes by `(type, value)` mistakes one for a dimension value, and none resolves it but the framework.
|
|
41
|
+
*/
|
|
42
|
+
export declare const RELATION_SCOPE_TYPE = "~rel";
|
|
43
|
+
/** A scope type no dimension, grant or key may name: IAM derives a `~` entry itself and never stores one. */
|
|
44
|
+
export declare function isReservedScopeType(type: string): boolean;
|
|
37
45
|
export interface PermissionEntry {
|
|
38
46
|
action: string;
|
|
39
47
|
/** null = global / all scopes */
|
|
@@ -70,6 +78,12 @@ export interface RoleDef {
|
|
|
70
78
|
};
|
|
71
79
|
/** An external principal may hold this membership role (ADR-0051). Only a membership role may declare it. */
|
|
72
80
|
external?: true;
|
|
81
|
+
/**
|
|
82
|
+
* Relation → exact actions. A GLOBAL grant of this role also carries `{ action, scope: { type: '~rel', value:
|
|
83
|
+
* relation } }`: the application holds the action where one of its rows names the principal in that relation.
|
|
84
|
+
* Only an application-wide internal role declares it.
|
|
85
|
+
*/
|
|
86
|
+
via?: Record<string, string[]>;
|
|
73
87
|
}
|
|
74
88
|
/**
|
|
75
89
|
* One scope dimension an app exposes. IAM evaluates every value as a flat scope; `in` only tells IAM
|