@dads-framework/access 0.0.0-stage → 0.1.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.
Files changed (208) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +78 -2
  3. package/dist/access.tsbuildinfo +1 -0
  4. package/dist/core/access-model.d.ts +30 -0
  5. package/dist/core/access-model.d.ts.map +1 -0
  6. package/dist/core/access-model.js +27 -0
  7. package/dist/core/access-model.js.map +1 -0
  8. package/dist/core/catalog-only.d.ts +42 -0
  9. package/dist/core/catalog-only.d.ts.map +1 -0
  10. package/dist/core/catalog-only.js +29 -0
  11. package/dist/core/catalog-only.js.map +1 -0
  12. package/dist/core/combinators.d.ts +25 -0
  13. package/dist/core/combinators.d.ts.map +1 -0
  14. package/dist/core/combinators.js +61 -0
  15. package/dist/core/combinators.js.map +1 -0
  16. package/dist/core/compare-access-ir.d.ts +9 -0
  17. package/dist/core/compare-access-ir.d.ts.map +1 -0
  18. package/dist/core/compare-access-ir.js +170 -0
  19. package/dist/core/compare-access-ir.js.map +1 -0
  20. package/dist/core/conformance.d.ts +21 -0
  21. package/dist/core/conformance.d.ts.map +1 -0
  22. package/dist/core/conformance.js +87 -0
  23. package/dist/core/conformance.js.map +1 -0
  24. package/dist/core/emit-ir.d.ts +8 -0
  25. package/dist/core/emit-ir.d.ts.map +1 -0
  26. package/dist/core/emit-ir.js +103 -0
  27. package/dist/core/emit-ir.js.map +1 -0
  28. package/dist/core/emit-zed.d.ts +9 -0
  29. package/dist/core/emit-zed.d.ts.map +1 -0
  30. package/dist/core/emit-zed.js +76 -0
  31. package/dist/core/emit-zed.js.map +1 -0
  32. package/dist/core/entity-handle.d.ts +39 -0
  33. package/dist/core/entity-handle.d.ts.map +1 -0
  34. package/dist/core/entity-handle.js +15 -0
  35. package/dist/core/entity-handle.js.map +1 -0
  36. package/dist/core/entity-kinds.d.ts +24 -0
  37. package/dist/core/entity-kinds.d.ts.map +1 -0
  38. package/dist/core/entity-kinds.js +30 -0
  39. package/dist/core/entity-kinds.js.map +1 -0
  40. package/dist/core/generated-header.d.ts +4 -0
  41. package/dist/core/generated-header.d.ts.map +1 -0
  42. package/dist/core/generated-header.js +6 -0
  43. package/dist/core/generated-header.js.map +1 -0
  44. package/dist/core/grantable.d.ts +62 -0
  45. package/dist/core/grantable.d.ts.map +1 -0
  46. package/dist/core/grantable.js +31 -0
  47. package/dist/core/grantable.js.map +1 -0
  48. package/dist/core/holders.d.ts +26 -0
  49. package/dist/core/holders.d.ts.map +1 -0
  50. package/dist/core/holders.js +38 -0
  51. package/dist/core/holders.js.map +1 -0
  52. package/dist/core/ir.d.ts +51 -0
  53. package/dist/core/ir.d.ts.map +1 -0
  54. package/dist/core/ir.js +2 -0
  55. package/dist/core/ir.js.map +1 -0
  56. package/dist/core/lifecycle.d.ts +10 -0
  57. package/dist/core/lifecycle.d.ts.map +1 -0
  58. package/dist/core/lifecycle.js +4 -0
  59. package/dist/core/lifecycle.js.map +1 -0
  60. package/dist/core/model.d.ts +43 -0
  61. package/dist/core/model.d.ts.map +1 -0
  62. package/dist/core/model.js +100 -0
  63. package/dist/core/model.js.map +1 -0
  64. package/dist/core/parse-zed.d.ts +8 -0
  65. package/dist/core/parse-zed.d.ts.map +1 -0
  66. package/dist/core/parse-zed.js +197 -0
  67. package/dist/core/parse-zed.js.map +1 -0
  68. package/dist/core/refs.d.ts +43 -0
  69. package/dist/core/refs.d.ts.map +1 -0
  70. package/dist/core/refs.js +28 -0
  71. package/dist/core/refs.js.map +1 -0
  72. package/dist/core/scope-binding-check.d.ts +11 -0
  73. package/dist/core/scope-binding-check.d.ts.map +1 -0
  74. package/dist/core/scope-binding-check.js +51 -0
  75. package/dist/core/scope-binding-check.js.map +1 -0
  76. package/dist/core/scope-bindings.d.ts +47 -0
  77. package/dist/core/scope-bindings.d.ts.map +1 -0
  78. package/dist/core/scope-bindings.js +8 -0
  79. package/dist/core/scope-bindings.js.map +1 -0
  80. package/dist/core/scope-plan-read.d.ts +9 -0
  81. package/dist/core/scope-plan-read.d.ts.map +1 -0
  82. package/dist/core/scope-plan-read.js +44 -0
  83. package/dist/core/scope-plan-read.js.map +1 -0
  84. package/dist/core/scope-plan-simplify.d.ts +5 -0
  85. package/dist/core/scope-plan-simplify.d.ts.map +1 -0
  86. package/dist/core/scope-plan-simplify.js +71 -0
  87. package/dist/core/scope-plan-simplify.js.map +1 -0
  88. package/dist/core/scope-plan.d.ts +77 -0
  89. package/dist/core/scope-plan.d.ts.map +1 -0
  90. package/dist/core/scope-plan.js +190 -0
  91. package/dist/core/scope-plan.js.map +1 -0
  92. package/dist/core/visible-record-exceptions.d.ts +21 -0
  93. package/dist/core/visible-record-exceptions.d.ts.map +1 -0
  94. package/dist/core/visible-record-exceptions.js +27 -0
  95. package/dist/core/visible-record-exceptions.js.map +1 -0
  96. package/dist/core/world.d.ts +44 -0
  97. package/dist/core/world.d.ts.map +1 -0
  98. package/dist/core/world.js +60 -0
  99. package/dist/core/world.js.map +1 -0
  100. package/dist/core/write-artifacts.d.ts +15 -0
  101. package/dist/core/write-artifacts.d.ts.map +1 -0
  102. package/dist/core/write-artifacts.js +53 -0
  103. package/dist/core/write-artifacts.js.map +1 -0
  104. package/dist/core/zod-enums.d.ts +3 -0
  105. package/dist/core/zod-enums.d.ts.map +1 -0
  106. package/dist/core/zod-enums.js +9 -0
  107. package/dist/core/zod-enums.js.map +1 -0
  108. package/dist/index.d.ts +40 -0
  109. package/dist/index.d.ts.map +1 -0
  110. package/dist/index.js +24 -0
  111. package/dist/index.js.map +1 -0
  112. package/dist/runtime/access-changes.d.ts +92 -0
  113. package/dist/runtime/access-changes.d.ts.map +1 -0
  114. package/dist/runtime/access-changes.js +57 -0
  115. package/dist/runtime/access-changes.js.map +1 -0
  116. package/dist/runtime/answer-once-authorization.d.ts +40 -0
  117. package/dist/runtime/answer-once-authorization.d.ts.map +1 -0
  118. package/dist/runtime/answer-once-authorization.js +172 -0
  119. package/dist/runtime/answer-once-authorization.js.map +1 -0
  120. package/dist/runtime/apply-access-changes-after-commit.d.ts +39 -0
  121. package/dist/runtime/apply-access-changes-after-commit.d.ts.map +1 -0
  122. package/dist/runtime/apply-access-changes-after-commit.js +37 -0
  123. package/dist/runtime/apply-access-changes-after-commit.js.map +1 -0
  124. package/dist/runtime/authorization-consistency-cookie.d.ts +9 -0
  125. package/dist/runtime/authorization-consistency-cookie.d.ts.map +1 -0
  126. package/dist/runtime/authorization-consistency-cookie.js +46 -0
  127. package/dist/runtime/authorization-consistency-cookie.js.map +1 -0
  128. package/dist/runtime/authorization-consistency.d.ts +6 -0
  129. package/dist/runtime/authorization-consistency.d.ts.map +1 -0
  130. package/dist/runtime/authorization-consistency.js +23 -0
  131. package/dist/runtime/authorization-consistency.js.map +1 -0
  132. package/dist/runtime/authorization.d.ts +137 -0
  133. package/dist/runtime/authorization.d.ts.map +1 -0
  134. package/dist/runtime/authorization.js +35 -0
  135. package/dist/runtime/authorization.js.map +1 -0
  136. package/dist/runtime/fake-authorization.d.ts +39 -0
  137. package/dist/runtime/fake-authorization.d.ts.map +1 -0
  138. package/dist/runtime/fake-authorization.js +147 -0
  139. package/dist/runtime/fake-authorization.js.map +1 -0
  140. package/dist/runtime/index.d.ts +13 -0
  141. package/dist/runtime/index.d.ts.map +1 -0
  142. package/dist/runtime/index.js +12 -0
  143. package/dist/runtime/index.js.map +1 -0
  144. package/dist/runtime/owner-lock.d.ts +36 -0
  145. package/dist/runtime/owner-lock.d.ts.map +1 -0
  146. package/dist/runtime/owner-lock.js +102 -0
  147. package/dist/runtime/owner-lock.js.map +1 -0
  148. package/dist/runtime/present-token.d.ts +2 -0
  149. package/dist/runtime/present-token.d.ts.map +1 -0
  150. package/dist/runtime/present-token.js +4 -0
  151. package/dist/runtime/present-token.js.map +1 -0
  152. package/dist/runtime/question-identity.d.ts +5 -0
  153. package/dist/runtime/question-identity.d.ts.map +1 -0
  154. package/dist/runtime/question-identity.js +16 -0
  155. package/dist/runtime/question-identity.js.map +1 -0
  156. package/dist/runtime/recording-authorization.d.ts +39 -0
  157. package/dist/runtime/recording-authorization.d.ts.map +1 -0
  158. package/dist/runtime/recording-authorization.js +56 -0
  159. package/dist/runtime/recording-authorization.js.map +1 -0
  160. package/dist/runtime/relationship-page.d.ts +12 -0
  161. package/dist/runtime/relationship-page.d.ts.map +1 -0
  162. package/dist/runtime/relationship-page.js +2 -0
  163. package/dist/runtime/relationship-page.js.map +1 -0
  164. package/dist/runtime/request-subject.d.ts +49 -0
  165. package/dist/runtime/request-subject.d.ts.map +1 -0
  166. package/dist/runtime/request-subject.js +8 -0
  167. package/dist/runtime/request-subject.js.map +1 -0
  168. package/dist/runtime/resolve-read-consistency.d.ts +15 -0
  169. package/dist/runtime/resolve-read-consistency.d.ts.map +1 -0
  170. package/dist/runtime/resolve-read-consistency.js +13 -0
  171. package/dist/runtime/resolve-read-consistency.js.map +1 -0
  172. package/dist/runtime/route-access.d.ts +66 -0
  173. package/dist/runtime/route-access.d.ts.map +1 -0
  174. package/dist/runtime/route-access.js +35 -0
  175. package/dist/runtime/route-access.js.map +1 -0
  176. package/dist/runtime/scope-answer.d.ts +47 -0
  177. package/dist/runtime/scope-answer.d.ts.map +1 -0
  178. package/dist/runtime/scope-answer.js +84 -0
  179. package/dist/runtime/scope-answer.js.map +1 -0
  180. package/dist/runtime/testing.d.ts +4 -0
  181. package/dist/runtime/testing.d.ts.map +1 -0
  182. package/dist/runtime/testing.js +4 -0
  183. package/dist/runtime/testing.js.map +1 -0
  184. package/dist/schema/apply-desired-schema.d.ts +20 -0
  185. package/dist/schema/apply-desired-schema.d.ts.map +1 -0
  186. package/dist/schema/apply-desired-schema.js +115 -0
  187. package/dist/schema/apply-desired-schema.js.map +1 -0
  188. package/dist/schema/authorization-schema-store.d.ts +13 -0
  189. package/dist/schema/authorization-schema-store.d.ts.map +1 -0
  190. package/dist/schema/authorization-schema-store.js +3 -0
  191. package/dist/schema/authorization-schema-store.js.map +1 -0
  192. package/dist/schema/index.d.ts +6 -0
  193. package/dist/schema/index.d.ts.map +1 -0
  194. package/dist/schema/index.js +6 -0
  195. package/dist/schema/index.js.map +1 -0
  196. package/dist/schema/logic/parse-write-schema-blocker.d.ts +16 -0
  197. package/dist/schema/logic/parse-write-schema-blocker.d.ts.map +1 -0
  198. package/dist/schema/logic/parse-write-schema-blocker.js +42 -0
  199. package/dist/schema/logic/parse-write-schema-blocker.js.map +1 -0
  200. package/dist/schema/logic/parse-zed-schema-surface.d.ts +11 -0
  201. package/dist/schema/logic/parse-zed-schema-surface.d.ts.map +1 -0
  202. package/dist/schema/logic/parse-zed-schema-surface.js +54 -0
  203. package/dist/schema/logic/parse-zed-schema-surface.js.map +1 -0
  204. package/dist/schema/logic/plan-schema-contraction.d.ts +9 -0
  205. package/dist/schema/logic/plan-schema-contraction.d.ts.map +1 -0
  206. package/dist/schema/logic/plan-schema-contraction.js +21 -0
  207. package/dist/schema/logic/plan-schema-contraction.js.map +1 -0
  208. package/package.json +50 -4
@@ -0,0 +1,137 @@
1
+ /**
2
+ * The authorization seam (docs/architecture/authorization.md): every access
3
+ * decision in the system goes through this port. SpiceDB is an adapter
4
+ * behind it; nothing outside the adapter imports the SpiceDB client.
5
+ *
6
+ * Failed checks surface to callers as 404s — don't leak existence
7
+ * (docs/architecture/api-conventions.md#errors).
8
+ */
9
+ /** Maps `user:abc123` to an explicit subject type and identifier. */
10
+ export type SubjectRef = {
11
+ type: string;
12
+ id: string;
13
+ /** subject-set relation, e.g. organization#member as a subject */
14
+ relation?: string;
15
+ };
16
+ /** String identifiers passed to the authorization adapter. */
17
+ export type WireResourceRef = {
18
+ /** namespaced object type, e.g. "organizations/organization" */
19
+ type: string;
20
+ id: string;
21
+ };
22
+ export type { WireResourceRef as ResourceRef };
23
+ export type PermissionQuery = {
24
+ subject: SubjectRef;
25
+ /** permission (verb), never a relation (noun) */
26
+ permission: string;
27
+ resource: WireResourceRef;
28
+ /**
29
+ * Preserved for read-your-writes callers. Enforcement never reads older
30
+ * than the server's own newest write, with or without this token.
31
+ */
32
+ consistencyToken?: SpiceDbConsistencyToken;
33
+ /**
34
+ * `fully-consistent` reads past every cache, so a grant another API
35
+ * instance projected after this process's own newest write is seen. For a
36
+ * refusal that must be final before acting on it; it costs a full read.
37
+ */
38
+ consistency?: "fully-consistent";
39
+ };
40
+ export type ResourceLookup = {
41
+ subject: SubjectRef;
42
+ permission: string;
43
+ resourceType: string;
44
+ /**
45
+ * Preserved for read-your-writes callers. Discovery never reads older than
46
+ * the server's own newest write; an old token cannot retain resources
47
+ * revoked by another request.
48
+ */
49
+ consistencyToken?: SpiceDbConsistencyToken;
50
+ };
51
+ export type RelationshipWrite = {
52
+ resource: WireResourceRef;
53
+ /** relation (noun), e.g. "owner", "admin" */
54
+ relation: string;
55
+ subject: SubjectRef;
56
+ };
57
+ export type RelationshipFilter = {
58
+ resourceType: string;
59
+ resourceId?: string;
60
+ relation?: string;
61
+ /**
62
+ * When set, only delete tuples for this subject (SpiceDB optionalSubjectFilter).
63
+ * Pass `id: ""` to match every subject of `type` (type-wide subject filter).
64
+ */
65
+ subject?: SubjectRef;
66
+ };
67
+ /**
68
+ * List subjects that hold a **direct** relation on a resource (ReadRelationships).
69
+ * Membership / people UIs use this — not permission LookupSubjects — so inherited
70
+ * administrators who inherit access do not appear as direct members.
71
+ */
72
+ export type DirectSubjectLookup = {
73
+ resource: WireResourceRef;
74
+ relation: string;
75
+ /**
76
+ * Override the adapter's ordinary read posture for a correctness-critical
77
+ * direct-subject decision. Omit for the configured default used by display
78
+ * lists; last-holder guards require a current roster.
79
+ */
80
+ consistency?: "fully-consistent";
81
+ consistencyToken?: SpiceDbConsistencyToken;
82
+ };
83
+ /**
84
+ * One question's outcome from `checkEach`: the decision, or the error the
85
+ * vendor reported for that question alone.
86
+ */
87
+ export type PermissionCheckOutcome = {
88
+ readonly kind: "answered";
89
+ readonly allowed: boolean;
90
+ } | {
91
+ readonly kind: "failed";
92
+ readonly error: Error;
93
+ };
94
+ /** Opaque consistency token — pass back for read-your-writes flows. */
95
+ export type SpiceDbConsistencyToken = string;
96
+ /**
97
+ * Abstract class on purpose: it is both the TypeScript interface and the
98
+ * wiring seam. Implemented by SpiceDbAuthorization; constructed by
99
+ * createSpiceDbAuthorization in the composition root; FakeAuthorization for unit tests.
100
+ */
101
+ export declare abstract class Authorization {
102
+ /** Enforcement decision; a completed revocation the server wrote cannot read stale. */
103
+ abstract check(query: PermissionQuery): Promise<boolean>;
104
+ /** Decisions in input order, as fresh as `check`; item errors deny and batch failures propagate. */
105
+ checkMany?(queries: readonly PermissionQuery[]): Promise<readonly boolean[]>;
106
+ /**
107
+ * Outcomes in input order from one bulk call, as fresh as `check`. An item
108
+ * error is that item's `failed` outcome, never a deny; a batch failure
109
+ * propagates. How concurrent single checks share one round trip.
110
+ */
111
+ checkEach?(queries: readonly PermissionQuery[]): Promise<readonly PermissionCheckOutcome[]>;
112
+ /** Authorized collection; never a union from before a revocation the server wrote. */
113
+ abstract lookupResources(query: ResourceLookup): Promise<readonly string[]>;
114
+ abstract writeRelationships(writes: readonly RelationshipWrite[]): Promise<SpiceDbConsistencyToken>;
115
+ abstract deleteRelationships(filter: RelationshipFilter): Promise<SpiceDbConsistencyToken>;
116
+ /**
117
+ * True when at least one subject holds `relation` on the resource —
118
+ * used by ownership reconciliation (row without parent tuple).
119
+ */
120
+ abstract relationshipExists(filter: {
121
+ resourceType: string;
122
+ resourceId: string;
123
+ relation: string;
124
+ }): Promise<boolean>;
125
+ /**
126
+ * Subjects with a direct `relation` tuple on `resource` — for grant lists.
127
+ */
128
+ abstract listDirectSubjects(query: DirectSubjectLookup): Promise<readonly SubjectRef[]>;
129
+ }
130
+ /**
131
+ * One plain check as a `checkEach` outcome: what a decorator answers per item
132
+ * when the port behind it has no bulk `checkEach`.
133
+ */
134
+ export declare function checkOutcome(check: () => Promise<boolean>): Promise<PermissionCheckOutcome>;
135
+ /** Helper for tuple literals: relationshipWrite(resource, relation, subject). */
136
+ export declare function relationshipWrite(resource: WireResourceRef, relation: string, subject: SubjectRef): RelationshipWrite;
137
+ //# sourceMappingURL=authorization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization.d.ts","sourceRoot":"","sources":["../../src/runtime/authorization.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,qEAAqE;AACrE,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,8DAA8D;AAC9D,MAAM,MAAM,eAAe,GAAG;IAC5B,gEAAgE;IAChE,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,YAAY,EAAE,eAAe,IAAI,WAAW,EAAE,CAAC;AAE/C,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,UAAU,CAAC;IACpB,iDAAiD;IACjD,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,eAAe,CAAC;IAC1B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,uBAAuB,CAAC;IAC3C;;;;OAIG;IACH,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,UAAU,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,uBAAuB,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,eAAe,CAAC;IAC1B,6CAA6C;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,UAAU,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACp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AmB,CAC1B,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,uBAAuB,CAAC,CAAC;IACpC;;;OAGG;IACH,QAAQ,CAAC,kBAAkB,CAAC,MAAM,EAAE;QAClC,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,MAAM,CAAC;KAClB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACrB;;OAEG;IACH,QAAQ,CAAC,kBAAkB,CACzB,KAAK,EAAE,mBAAmB,GACzB,OAAO,CAAC,SAAS,UAAU,EAAE,CAAC,CAAC;CACnC;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAChC,KAAK,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,GAC5B,OAAO,CAAC,sBAAsB,CAAC,CASjC;AAED,iFAAiF;AACjF,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,eAAe,EACzB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,UAAU,GAClB,iBAAiB,CAEnB"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The authorization seam (docs/architecture/authorization.md): every access
3
+ * decision in the system goes through this port. SpiceDB is an adapter
4
+ * behind it; nothing outside the adapter imports the SpiceDB client.
5
+ *
6
+ * Failed checks surface to callers as 404s — don't leak existence
7
+ * (docs/architecture/api-conventions.md#errors).
8
+ */
9
+ /**
10
+ * Abstract class on purpose: it is both the TypeScript interface and the
11
+ * wiring seam. Implemented by SpiceDbAuthorization; constructed by
12
+ * createSpiceDbAuthorization in the composition root; FakeAuthorization for unit tests.
13
+ */
14
+ export class Authorization {
15
+ }
16
+ /**
17
+ * One plain check as a `checkEach` outcome: what a decorator answers per item
18
+ * when the port behind it has no bulk `checkEach`.
19
+ */
20
+ export async function checkOutcome(check) {
21
+ try {
22
+ return { kind: "answered", allowed: await check() };
23
+ }
24
+ catch (error) {
25
+ return {
26
+ kind: "failed",
27
+ error: error instanceof Error ? error : new Error(String(error)),
28
+ };
29
+ }
30
+ }
31
+ /** Helper for tuple literals: relationshipWrite(resource, relation, subject). */
32
+ export function relationshipWrite(resource, relation, subject) {
33
+ return { resource, relation, subject };
34
+ }
35
+ //# sourceMappingURL=authorization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization.js","sourceRoot":"","sources":["../../src/runtime/authorization.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA+FH;;;;GAIG;AACH,MAAM,OAAgB,aAAa;CAoClC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,KAA6B;IAE7B,IAAI,CAAC;QACH,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,KAAK,EAAE,EAAE,CAAC;IACtD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;SACjE,CAAC;IACJ,CAAC;AACH,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,iBAAiB,CAC/B,QAAyB,EACzB,QAAgB,EAChB,OAAmB;IAEnB,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;AACzC,CAAC"}
@@ -0,0 +1,39 @@
1
+ import type { Authorization, DirectSubjectLookup, PermissionQuery, RelationshipFilter, RelationshipWrite, ResourceLookup, SubjectRef, SpiceDbConsistencyToken } from "./authorization.js";
2
+ /**
3
+ * Hand-written in-memory fake (docs/architecture/authorization.md#testing):
4
+ * a tuple map plus an explicit permission→relations table per resource type.
5
+ * Unit tests seed tuples and assert decisions in milliseconds — no SpiceDB.
6
+ *
7
+ * The permission table mirrors the .zed fragments deliberately simply
8
+ * (no arrows) — arrow semantics are integration-tested against real SpiceDB.
9
+ *
10
+ * THE TRICK EVERY NEW TEST NEEDS: because arrows don't traverse here, a
11
+ * positive check/lookup on an owner-arrow resource uses the OWNING
12
+ * ORGANIZATION as the subject — `{ type: "organizations/organization",
13
+ * id: ORG_ID }` — not the end user. In production the subject is always
14
+ * the user and SpiceDB walks user → org → resource; the fake only sees the
15
+ * last hop. A user-subject lookup returning [] here is usually THIS, not a
16
+ * missing tuple.
17
+ */
18
+ export declare class FakeAuthorization implements Authorization {
19
+ /** e.g. { "organizations/organization": { view: ["admin","member"], manage: ["admin"] } } */
20
+ private readonly permissions;
21
+ private readonly tuples;
22
+ private writeCounter;
23
+ constructor(
24
+ /** e.g. { "organizations/organization": { view: ["admin","member"], manage: ["admin"] } } */
25
+ permissions?: Record<string, Record<string, readonly string[]>>);
26
+ seed(...writes: readonly RelationshipWrite[]): void;
27
+ check(query: PermissionQuery): Promise<boolean>;
28
+ lookupResources(query: ResourceLookup): Promise<readonly string[]>;
29
+ writeRelationships(writes: readonly RelationshipWrite[]): Promise<SpiceDbConsistencyToken>;
30
+ deleteRelationships(filter: RelationshipFilter): Promise<SpiceDbConsistencyToken>;
31
+ relationshipExists(filter: {
32
+ resourceType: string;
33
+ resourceId: string;
34
+ relation: string;
35
+ }): Promise<boolean>;
36
+ listDirectSubjects(query: DirectSubjectLookup): Promise<readonly SubjectRef[]>;
37
+ private relationsFor;
38
+ }
39
+ //# sourceMappingURL=fake-authorization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fake-authorization.d.ts","sourceRoot":"","sources":["../../src/runtime/fake-authorization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,EACd,UAAU,EACV,uBAAuB,EACxB,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,iBAAkB,YAAW,aAAa;IAKnD,6FAA6F;IAC7F,OAAO,CAAC,QAAQ,CAAC,WAAW;IAL9B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAC5C,OAAO,CAAC,YAAY,CAAK;IAEzB;IACE,6FAA6F;IAC5E,WAAW,GAAE,MAAM,CAClC,MAAM,EACN,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAC7B,EACJ;IAEJ,IAAI,CAAC,GAAG,MAAM,EAAE,SAAS,iBAAiB,EAAE,GAAG,IAAI,CAIlD;IAED,KAAK,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAY9C;IAED,eAAe,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAgBjE;IAED,kBAAkB,CAChB,MAAM,EAAE,SAAS,iBAAiB,EAAE,GACnC,OAAO,CAAC,uBAAuB,CAAC,CAIlC;IAED,mBAAmB,CACjB,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,uBAAuB,CAAC,CAOlC;IAED,kBAAkB,CAAC,MAAM,EAAE;QACzB,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,MAAM,CAAC;KAClB,GAAG,OAAO,CAAC,OAAO,CAAC,CAKnB;IAED,kBAAkB,CAChB,KAAK,EAAE,mBAAmB,GACzB,OAAO,CAAC,SAAS,UAAU,EAAE,CAAC,CAmBhC;IAED,OAAO,CAAC,YAAY;CAMrB"}
@@ -0,0 +1,147 @@
1
+ /**
2
+ * Hand-written in-memory fake (docs/architecture/authorization.md#testing):
3
+ * a tuple map plus an explicit permission→relations table per resource type.
4
+ * Unit tests seed tuples and assert decisions in milliseconds — no SpiceDB.
5
+ *
6
+ * The permission table mirrors the .zed fragments deliberately simply
7
+ * (no arrows) — arrow semantics are integration-tested against real SpiceDB.
8
+ *
9
+ * THE TRICK EVERY NEW TEST NEEDS: because arrows don't traverse here, a
10
+ * positive check/lookup on an owner-arrow resource uses the OWNING
11
+ * ORGANIZATION as the subject — `{ type: "organizations/organization",
12
+ * id: ORG_ID }` — not the end user. In production the subject is always
13
+ * the user and SpiceDB walks user → org → resource; the fake only sees the
14
+ * last hop. A user-subject lookup returning [] here is usually THIS, not a
15
+ * missing tuple.
16
+ */
17
+ export class FakeAuthorization {
18
+ permissions;
19
+ tuples = new Set();
20
+ writeCounter = 0;
21
+ constructor(
22
+ /** e.g. { "organizations/organization": { view: ["admin","member"], manage: ["admin"] } } */
23
+ permissions = {}) {
24
+ this.permissions = permissions;
25
+ }
26
+ seed(...writes) {
27
+ for (const write of writes) {
28
+ this.tuples.add(key(write));
29
+ }
30
+ }
31
+ check(query) {
32
+ const relations = this.relationsFor(query.resource.type, query.permission);
33
+ const allowed = relations.some((relation) => this.tuples.has(key({
34
+ resource: query.resource,
35
+ relation,
36
+ subject: query.subject,
37
+ })));
38
+ return Promise.resolve(allowed);
39
+ }
40
+ lookupResources(query) {
41
+ const relations = this.relationsFor(query.resourceType, query.permission);
42
+ const prefix = `${query.resourceType}:`;
43
+ const suffixes = relations.map((relation) => `#${relation}@${query.subject.type}:${query.subject.id}${query.subject.relation ? `#${query.subject.relation}` : ""}`);
44
+ const ids = [...this.tuples]
45
+ .filter((tuple) => tuple.startsWith(prefix) &&
46
+ suffixes.some((suffix) => tuple.endsWith(suffix)))
47
+ .map((tuple) => tuple.slice(prefix.length).split("#")[0])
48
+ .filter((id) => id !== undefined);
49
+ return Promise.resolve([...new Set(ids)]);
50
+ }
51
+ writeRelationships(writes) {
52
+ this.seed(...writes);
53
+ this.writeCounter += 1;
54
+ return Promise.resolve(`fake-token-${this.writeCounter}`);
55
+ }
56
+ deleteRelationships(filter) {
57
+ for (const tuple of [...this.tuples]) {
58
+ if (!tupleMatchesFilter(tuple, filter))
59
+ continue;
60
+ this.tuples.delete(tuple);
61
+ }
62
+ this.writeCounter += 1;
63
+ return Promise.resolve(`fake-token-${this.writeCounter}`);
64
+ }
65
+ relationshipExists(filter) {
66
+ const prefix = `${filter.resourceType}:${filter.resourceId}#${filter.relation}@`;
67
+ return Promise.resolve([...this.tuples].some((tuple) => tuple.startsWith(prefix)));
68
+ }
69
+ listDirectSubjects(query) {
70
+ const prefix = `${query.resource.type}:${query.resource.id}#${query.relation}@`;
71
+ const subjects = [];
72
+ for (const tuple of this.tuples) {
73
+ if (!tuple.startsWith(prefix))
74
+ continue;
75
+ const subjectPart = tuple.slice(prefix.length);
76
+ const hash = subjectPart.indexOf("#");
77
+ const objectPart = hash === -1 ? subjectPart : subjectPart.slice(0, hash);
78
+ const subjectRelation = hash === -1 ? undefined : subjectPart.slice(hash + 1);
79
+ const colon = objectPart.indexOf(":");
80
+ if (colon === -1)
81
+ continue;
82
+ subjects.push({
83
+ type: objectPart.slice(0, colon),
84
+ id: objectPart.slice(colon + 1),
85
+ ...(subjectRelation ? { relation: subjectRelation } : {}),
86
+ });
87
+ }
88
+ return Promise.resolve(subjects);
89
+ }
90
+ relationsFor(resourceType, permission) {
91
+ return this.permissions[resourceType]?.[permission] ?? [permission];
92
+ }
93
+ }
94
+ function key(write) {
95
+ const subjectRelation = write.subject.relation
96
+ ? `#${write.subject.relation}`
97
+ : "";
98
+ return `${write.resource.type}:${write.resource.id}#${write.relation}@${write.subject.type}:${write.subject.id}${subjectRelation}`;
99
+ }
100
+ function subjectMatches(subjectPart, filter) {
101
+ const hash = subjectPart.indexOf("#");
102
+ const objectPart = hash === -1 ? subjectPart : subjectPart.slice(0, hash);
103
+ const subjectRelation = hash === -1 ? undefined : subjectPart.slice(hash + 1);
104
+ const colon = objectPart.indexOf(":");
105
+ if (colon === -1)
106
+ return false;
107
+ if (objectPart.slice(0, colon) !== filter.type)
108
+ return false;
109
+ if (objectPart.slice(colon + 1) !== filter.id)
110
+ return false;
111
+ if (filter.relation !== undefined && subjectRelation !== filter.relation) {
112
+ return false;
113
+ }
114
+ return true;
115
+ }
116
+ function tupleMatchesFilter(tuple, filter) {
117
+ const parts = splitTuple(tuple);
118
+ if (parts === undefined || parts.resourceType !== filter.resourceType)
119
+ return false;
120
+ if (filter.resourceId && parts.resourceId !== filter.resourceId)
121
+ return false;
122
+ if (filter.relation && parts.relation !== filter.relation)
123
+ return false;
124
+ return (filter.subject === undefined ||
125
+ subjectMatches(parts.subject, filter.subject));
126
+ }
127
+ function splitTuple(tuple) {
128
+ // Preserve the second # delimiter, which belongs to the subject relation.
129
+ const hash = tuple.indexOf("#");
130
+ if (hash === -1)
131
+ return undefined;
132
+ const resource = tuple.slice(0, hash);
133
+ const rest = tuple.slice(hash + 1);
134
+ if (!resource || !rest)
135
+ return undefined;
136
+ const at = rest.indexOf("@");
137
+ if (at === -1)
138
+ return undefined;
139
+ const [resourceType, resourceId] = resource.split(":", 2);
140
+ return {
141
+ resourceType,
142
+ resourceId,
143
+ relation: rest.slice(0, at),
144
+ subject: rest.slice(at + 1),
145
+ };
146
+ }
147
+ //# sourceMappingURL=fake-authorization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fake-authorization.js","sourceRoot":"","sources":["../../src/runtime/fake-authorization.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,iBAAiB;IAMT,WAAW;IALb,MAAM,GAAG,IAAI,GAAG,EAAU,CAAC;IACpC,YAAY,GAAG,CAAC,CAAC;IAEzB;IACE,6FAA6F;IAC5E,WAAW,GAGxB,EAAE;2BAHW,WAAW;IAI3B,CAAC;IAEJ,IAAI,CAAC,GAAG,MAAoC;QAC1C,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,KAAK,CAAC,KAAsB;QAC1B,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;QAC3E,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CA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;QACV,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;QAC3B,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC;KAC5B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,13 @@
1
+ export { Authorization, checkOutcome, relationshipWrite, type DirectSubjectLookup, type PermissionCheckOutcome, type PermissionQuery, type RelationshipFilter, type RelationshipWrite, type ResourceLookup, type ResourceRef, type SpiceDbConsistencyToken, type SubjectRef, type WireResourceRef, } from "./authorization.js";
2
+ export { authorizationConsistencyTokenOnThisRequest, recordWrittenAuthorizationConsistency, runWithAuthorizationConsistency, writtenAuthorizationConsistencyOnThisRequest, } from "./authorization-consistency.js";
3
+ export { AUTHORIZATION_CONSISTENCY_COOKIE, authorizationConsistencyClearCookie, authorizationConsistencySetCookie, authorizationConsistencyTokenFromCookieHeader, } from "./authorization-consistency-cookie.js";
4
+ export { RequestSubject, type AuthMethod, type RequestHeaders, type ResolvedSubject, } from "./request-subject.js";
5
+ export { evaluateRouteAccess, type ResourceIdSource, type RequirePermissionMetadata, type RouteAccessInput, type RouteAccessVerdict, } from "./route-access.js";
6
+ export { answerScope, planScopedList, scopeQuestionKey, scopeQuestions, type ScopeAnswer, type ScopeLookups, type ScopeQuestion, } from "./scope-answer.js";
7
+ export { accessChangesToWrite, EnqueueAccessChanges, OUTBOX_OPERATION_VALUES, outboxKeyForRelationship, type AccessChange, type OutboxOperation, } from "./access-changes.js";
8
+ export { ApplyAccessChangesAfterCommit } from "./apply-access-changes-after-commit.js";
9
+ export { OwnerLock, OwnerLockLease } from "./owner-lock.js";
10
+ export type { RelationshipPage, RelationshipPageRequest, } from "./relationship-page.js";
11
+ export { AnswerOnceAuthorization } from "./answer-once-authorization.js";
12
+ export { resolveReadConsistency, type ReadConsistencyDecision, } from "./resolve-read-consistency.js";
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.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B,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EACL,sBAAsB,EACtB,KAAK,uBAAuB,GAC7B,MAAM,+BAA+B,CAAC"}
@@ -0,0 +1,12 @@
1
+ export { Authorization, checkOutcome, relationshipWrite, } from "./authorization.js";
2
+ export { authorizationConsistencyTokenOnThisRequest, recordWrittenAuthorizationConsistency, runWithAuthorizationConsistency, writtenAuthorizationConsistencyOnThisRequest, } from "./authorization-consistency.js";
3
+ export { AUTHORIZATION_CONSISTENCY_COOKIE, authorizationConsistencyClearCookie, authorizationConsistencySetCookie, authorizationConsistencyTokenFromCookieHeader, } from "./authorization-consistency-cookie.js";
4
+ export { RequestSubject, } from "./request-subject.js";
5
+ export { evaluateRouteAccess, } from "./route-access.js";
6
+ export { answerScope, planScopedList, scopeQuestionKey, scopeQuestions, } from "./scope-answer.js";
7
+ export { accessChangesToWrite, EnqueueAccessChanges, OUTBOX_OPERATION_VALUES, outboxKeyForRelationship, } from "./access-changes.js";
8
+ export { ApplyAccessChangesAfterCommit } from "./apply-access-changes-after-commit.js";
9
+ export { OwnerLock, OwnerLockLease } from "./owner-lock.js";
10
+ export { AnswerOnceAuthorization } from "./answer-once-authorization.js";
11
+ export { resolveReadConsistency, } from "./resolve-read-consistency.js";
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,YAAY,EACZ,iBAAiB,GAWlB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,0CAA0C,EAC1C,qCAAqC,EACrC,+BAA+B,EAC/B,4CAA4C,GAC7C,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,gCAAgC,EAChC,mCAAmC,EACnC,iCAAiC,EACjC,6CAA6C,GAC9C,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACL,cAAc,GAIf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,mBAAmB,GAKpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,cAAc,GAIf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,uBAAuB,EACvB,wBAAwB,GAGzB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AACvF,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAK5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EACL,sBAAsB,GAEvB,MAAM,+BAA+B,CAAC"}
@@ -0,0 +1,36 @@
1
+ declare const AUTHORIZATION_PARTITION_LEASE_TOKEN: unique symbol;
2
+ type DeferredProjection = () => Promise<void>;
3
+ /**
4
+ * Opaque proof that the caller currently owns one authorization partition.
5
+ * Lifecycle coordinators may pass it across domain seams to extend the same
6
+ * critical section without recursively acquiring the Postgres session lock.
7
+ */
8
+ export declare class OwnerLockLease {
9
+ readonly ownerPartitionId: string;
10
+ private readonly deferred;
11
+ private active;
12
+ constructor(ownerPartitionId: string, deferred: DeferredProjection[], token: typeof AUTHORIZATION_PARTITION_LEASE_TOKEN);
13
+ assertPartition(ownerPartitionId: string): void;
14
+ /** Run only after the coordinator has released the session lock. */
15
+ afterRelease(operation: DeferredProjection): void;
16
+ close(): void;
17
+ private assertActive;
18
+ }
19
+ /** Cross-process ordering boundary for one authorization owner partition. */
20
+ export declare abstract class OwnerLock {
21
+ run<T>(ownerPartitionId: string, operation: (lease: OwnerLockLease) => Promise<T>): Promise<T>;
22
+ protected abstract runLocked<T>(ownerPartitionId: string, operation: () => Promise<T>): Promise<T>;
23
+ }
24
+ /**
25
+ * Run `operation` as though a SEPARATE process were running it — outside the
26
+ * partitions this call path holds.
27
+ *
28
+ * Exported only through `testing/`, and only for the interleavings that are
29
+ * genuinely two workers in production: a projector that claimed a row before
30
+ * a producer superseded it runs in its own process, so writing that test as a
31
+ * nested call is an artifact of the test, not a design the wall should allow.
32
+ * Production code that wants the lock released has `lease.afterRelease`.
33
+ */
34
+ export declare function runOutsideHeldPartitions<T>(operation: () => Promise<T>): Promise<T>;
35
+ export {};
36
+ //# sourceMappingURL=owner-lock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"owner-lock.d.ts","sourceRoot":"","sources":["../../src/runtime/owner-lock.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,mCAAmC,eAExC,CAAC;AAEF,KAAK,kBAAkB,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;AAoB9C;;;;GAIG;AACH,qBAAa,cAAc;IAIvB,QAAQ,CAAC,gBAAgB,EAAE,MAAM;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAJ3B,OAAO,CAAC,MAAM,CAAQ;IAEtB,YACW,gBAAgB,EAAE,MAAM,EAChB,QAAQ,EAAE,kBAAkB,EAAE,EAC/C,KAAK,EAAE,OAAO,mCAAmC,EAKlD;IAED,eAAe,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAK9C;IAED,oEAAoE;IACpE,YAAY,CAAC,SAAS,EAAE,kBAAkB,GAAG,IAAI,CAGhD;IAED,KAAK,IAAI,IAAI,CAEZ;IAED,OAAO,CAAC,YAAY;CAKrB;AAED,6EAA6E;AAC7E,8BAAsB,SAAS;IACvB,GAAG,CAAC,CAAC,EACT,gBAAgB,EAAE,MAAM,EACxB,SAAS,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,OAAO,CAAC,CAAC,CAAC,GAC/C,OAAO,CAAC,CAAC,CAAC,CAwBZ;IAED,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,EAC5B,gBAAgB,EAAE,MAAM,EACxB,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAC1B,OAAO,CAAC,CAAC,CAAC,CAAC;CACf;AAED;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,EACxC,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAC1B,OAAO,CAAC,CAAC,CAAC,CAEZ"}
@@ -0,0 +1,102 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ const AUTHORIZATION_PARTITION_LEASE_TOKEN = Symbol("authorization-partition-lease");
3
+ /**
4
+ * The partitions the current call path already holds.
5
+ *
6
+ * Nested owner locks are forbidden.
7
+ * Re-entering a partition is not contention that resolves — the lock lives on
8
+ * a POOLED SESSION, and a Postgres advisory lock is re-entrant only within one
9
+ * session, so a caller that re-enters is waiting for itself. It burns the
10
+ * whole acquisition timeout and reports `AUTHORIZATION_PARTITION_BUSY`, which
11
+ * reads exactly like a busy neighbour and sent one investigation looking for a
12
+ * leaked lease from a previous process. Work that needs the lock released
13
+ * first belongs in `lease.afterRelease`.
14
+ *
15
+ * Scoped to the call path rather than the process on purpose: two concurrent
16
+ * requests holding the same partition are real contention and must still
17
+ * queue.
18
+ */
19
+ const partitionsHeldOnThisPath = new AsyncLocalStorage();
20
+ /**
21
+ * Opaque proof that the caller currently owns one authorization partition.
22
+ * Lifecycle coordinators may pass it across domain seams to extend the same
23
+ * critical section without recursively acquiring the Postgres session lock.
24
+ */
25
+ export class OwnerLockLease {
26
+ ownerPartitionId;
27
+ deferred;
28
+ active = true;
29
+ constructor(ownerPartitionId, deferred, token) {
30
+ this.ownerPartitionId = ownerPartitionId;
31
+ this.deferred = deferred;
32
+ if (token !== AUTHORIZATION_PARTITION_LEASE_TOKEN) {
33
+ throw new Error("authorization partition leases are coordinator-owned");
34
+ }
35
+ }
36
+ assertPartition(ownerPartitionId) {
37
+ this.assertActive();
38
+ if (ownerPartitionId !== this.ownerPartitionId) {
39
+ throw new Error("authorization partition lease does not match scope");
40
+ }
41
+ }
42
+ /** Run only after the coordinator has released the session lock. */
43
+ afterRelease(operation) {
44
+ this.assertActive();
45
+ this.deferred.push(operation);
46
+ }
47
+ close() {
48
+ this.active = false;
49
+ }
50
+ assertActive() {
51
+ if (!this.active) {
52
+ throw new Error("authorization partition lease is no longer active");
53
+ }
54
+ }
55
+ }
56
+ /** Cross-process ordering boundary for one authorization owner partition. */
57
+ export class OwnerLock {
58
+ async run(ownerPartitionId, operation) {
59
+ refuseReentry(ownerPartitionId);
60
+ const deferred = [];
61
+ const lease = new OwnerLockLease(ownerPartitionId, deferred, AUTHORIZATION_PARTITION_LEASE_TOKEN);
62
+ // The deferred projections run OUTSIDE this scope, which is the whole
63
+ // point of `afterRelease`: by then the lock is gone and the partition is
64
+ // free for the projector to take on its own session.
65
+ const result = await partitionsHeldOnThisPath.run(alsoHolding(ownerPartitionId), () => this.runLocked(ownerPartitionId, async () => {
66
+ try {
67
+ return await operation(lease);
68
+ }
69
+ finally {
70
+ lease.close();
71
+ }
72
+ }));
73
+ for (const projection of deferred)
74
+ await projection();
75
+ return result;
76
+ }
77
+ }
78
+ /**
79
+ * Run `operation` as though a SEPARATE process were running it — outside the
80
+ * partitions this call path holds.
81
+ *
82
+ * Exported only through `testing/`, and only for the interleavings that are
83
+ * genuinely two workers in production: a projector that claimed a row before
84
+ * a producer superseded it runs in its own process, so writing that test as a
85
+ * nested call is an artifact of the test, not a design the wall should allow.
86
+ * Production code that wants the lock released has `lease.afterRelease`.
87
+ */
88
+ export function runOutsideHeldPartitions(operation) {
89
+ return partitionsHeldOnThisPath.exit(operation);
90
+ }
91
+ function refuseReentry(ownerPartitionId) {
92
+ const held = partitionsHeldOnThisPath.getStore();
93
+ if (held?.has(ownerPartitionId) !== true)
94
+ return;
95
+ throw new Error(`authorization partition ${ownerPartitionId} is already held on this call path; ` +
96
+ "defer the nested work with lease.afterRelease");
97
+ }
98
+ function alsoHolding(ownerPartitionId) {
99
+ const held = partitionsHeldOnThisPath.getStore();
100
+ return new Set([...(held ?? []), ownerPartitionId]);
101
+ }
102
+ //# sourceMappingURL=owner-lock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ow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Token(token: string | undefined): string | undefined;
2
+ //# sourceMappingURL=present-token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"present-token.d.ts","sourceRoot":"","sources":["../../src/runtime/present-token.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAE1E"}
@@ -0,0 +1,4 @@
1
+ export function presentToken(token) {
2
+ return token !== undefined && token.length > 0 ? token : undefined;
3
+ }
4
+ //# sourceMappingURL=present-token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"present-token.js","sourceRoot":"","sources":["../../src/runtime/present-token.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,YAAY,CAAC,KAAyB;IACpD,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACrE,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { PermissionQuery, ResourceLookup } from "./authorization.js";
2
+ /** The question independent of how fresh its answer must be. */
3
+ export declare function permissionQuestionIdentity(query: PermissionQuery): readonly [readonly string[], string, string, string];
4
+ export declare function lookupQuestionIdentity(query: ResourceLookup): readonly [readonly string[], string, string];
5
+ //# sourceMappingURL=question-identity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"question-identity.d.ts","sourceRoot":"","sources":["../../src/runtime/question-identity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EAEf,MAAM,oBAAoB,CAAC;AAM5B,gEAAgE;AAChE,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,eAAe,GACrB,SAAS,CAAC,SAAS,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAOtD;AAED,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,cAAc,GACpB,SAAS,CAAC,SAAS,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,CAE9C"}
@@ -0,0 +1,16 @@
1
+ function subjectIdentity(subject) {
2
+ return [subject.type, subject.id, subject.relation ?? ""];
3
+ }
4
+ /** The question independent of how fresh its answer must be. */
5
+ export function permissionQuestionIdentity(query) {
6
+ return [
7
+ subjectIdentity(query.subject),
8
+ query.permission,
9
+ query.resource.type,
10
+ query.resource.id,
11
+ ];
12
+ }
13
+ export function lookupQuestionIdentity(query) {
14
+ return [subjectIdentity(query.subject), query.permission, query.resourceType];
15
+ }
16
+ //# sourceMappingURL=question-identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"question-identity.js","sourceRoot":"","sources":["../../src/runtime/question-identity.ts"],"names":[],"mappings":"AAMA,SAAS,eAAe,CAAC,OAAmB;IAC1C,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;AAC5D,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,0BAA0B,CACxC,KAAsB;IAEtB,OAAO;QACL,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC;QAC9B,KAAK,CAAC,UAAU;QAChB,KAAK,CAAC,QAAQ,CAAC,IAAI;QACnB,KAAK,CAAC,QAAQ,CAAC,EAAE;KAClB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,KAAqB;IAErB,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;AAChF,CAAC"}