@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,39 @@
1
+ import type { Authorization, DirectSubjectLookup, PermissionQuery, RelationshipFilter, RelationshipWrite, ResourceLookup, SpiceDbConsistencyToken, SubjectRef } from "./authorization.js";
2
+ type CheckAnswer = {
3
+ query: PermissionQuery;
4
+ answer: boolean;
5
+ };
6
+ type LookupAnswer = {
7
+ query: ResourceLookup;
8
+ answer: readonly string[];
9
+ };
10
+ type RecordingAuthorizationOptions = {
11
+ checks?: readonly CheckAnswer[];
12
+ lookups?: readonly LookupAnswer[];
13
+ };
14
+ /** An explicit-answer fake for decision tests; it records questions but never evaluates tuples or arrows. */
15
+ export declare class RecordingAuthorization implements Authorization {
16
+ private readonly answers;
17
+ readonly questions: ({
18
+ kind: "check";
19
+ query: PermissionQuery;
20
+ } | {
21
+ kind: "lookup";
22
+ query: ResourceLookup;
23
+ })[];
24
+ constructor(answers?: RecordingAuthorizationOptions);
25
+ check(query: PermissionQuery): Promise<boolean>;
26
+ lookupResources(query: ResourceLookup): Promise<readonly string[]>;
27
+ writeRelationships(writes: readonly RelationshipWrite[]): Promise<SpiceDbConsistencyToken>;
28
+ deleteRelationships(filter: RelationshipFilter): Promise<SpiceDbConsistencyToken>;
29
+ relationshipExists(filter: {
30
+ resourceType: string;
31
+ resourceId: string;
32
+ relation: string;
33
+ }): Promise<boolean>;
34
+ listDirectSubjects(query: DirectSubjectLookup): Promise<readonly SubjectRef[]>;
35
+ private find;
36
+ private rejectDuplicateAnswers;
37
+ }
38
+ export {};
39
+ //# sourceMappingURL=recording-authorization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recording-authorization.d.ts","sourceRoot":"","sources":["../../src/runtime/recording-authorization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,EACd,uBAAuB,EACvB,UAAU,EACX,MAAM,oBAAoB,CAAC;AAM5B,KAAK,WAAW,GAAG;IAAE,KAAK,EAAE,eAAe,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC;AAC/D,KAAK,YAAY,GAAG;IAAE,KAAK,EAAE,cAAc,CAAC;IAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC;AACzE,KAAK,6BAA6B,GAAG;IACnC,MAAM,CAAC,EAAE,SAAS,WAAW,EAAE,CAAC;IAChC,OAAO,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;CACnC,CAAC;AAEF,6GAA6G;AAC7G,qBAAa,sBAAuB,YAAW,aAAa;IAK9C,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJpC,QAAQ,CAAC,SAAS,EAAE,CAChB;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,eAAe,CAAA;KAAE,GACzC;QAAE,IAAI,EAAE,QAAQ,CAAC;QAAC,KAAK,EAAE,cAAc,CAAA;KAAE,CAC5C,EAAE,CAAM;IACT,YAA6B,OAAO,GAAE,6BAAkC,EAOvE;IACD,KAAK,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAO9C;IACD,eAAe,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAOjE;IACD,kBAAkB,CAChB,MAAM,EAAE,SAAS,iBAAiB,EAAE,GACnC,OAAO,CAAC,uBAAuB,CAAC,CAOlC;IACD,mBAAmB,CACjB,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,uBAAuB,CAAC,CAOlC;IACD,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,CAOnB;IACD,kBAAkB,CAChB,KAAK,EAAE,mBAAmB,GACzB,OAAO,CAAC,SAAS,UAAU,EAAE,CAAC,CAOhC;IACD,OAAO,CAAC,IAAI;IAYZ,OAAO,CAAC,sBAAsB;CAS/B"}
@@ -0,0 +1,56 @@
1
+ import { lookupQuestionIdentity, permissionQuestionIdentity, } from "./question-identity.js";
2
+ /** An explicit-answer fake for decision tests; it records questions but never evaluates tuples or arrows. */
3
+ export class RecordingAuthorization {
4
+ answers;
5
+ questions = [];
6
+ constructor(answers = {}) {
7
+ this.answers = answers;
8
+ this.rejectDuplicateAnswers(answers.checks ?? [], permissionKey, "check");
9
+ this.rejectDuplicateAnswers(answers.lookups ?? [], lookupAnswerKey, "lookup");
10
+ }
11
+ check(query) {
12
+ this.questions.push({ kind: "check", query });
13
+ return Promise.resolve().then(() => this.find(this.answers.checks ?? [], permissionKey, query, "check")
14
+ .answer);
15
+ }
16
+ lookupResources(query) {
17
+ this.questions.push({ kind: "lookup", query });
18
+ return Promise.resolve().then(() => this.find(this.answers.lookups ?? [], lookupAnswerKey, query, "lookup")
19
+ .answer);
20
+ }
21
+ writeRelationships(writes) {
22
+ void writes;
23
+ return Promise.reject(new Error("RecordingAuthorization does not support tuple mutation; use FakeAuthorization"));
24
+ }
25
+ deleteRelationships(filter) {
26
+ void filter;
27
+ return Promise.reject(new Error("RecordingAuthorization does not support tuple mutation; use FakeAuthorization"));
28
+ }
29
+ relationshipExists(filter) {
30
+ void filter;
31
+ return Promise.reject(new Error("RecordingAuthorization does not support tuple inspection; use FakeAuthorization"));
32
+ }
33
+ listDirectSubjects(query) {
34
+ void query;
35
+ return Promise.reject(new Error("RecordingAuthorization does not support tuple inspection; use FakeAuthorization"));
36
+ }
37
+ find(answers, keyOf, query, kind) {
38
+ const key = keyOf(query);
39
+ const found = answers.find((candidate) => keyOf(candidate.query) === key);
40
+ if (!found)
41
+ throw new Error(`RecordingAuthorization unanswered ${kind}: ${key}`);
42
+ return found;
43
+ }
44
+ rejectDuplicateAnswers(answers, keyOf, kind) {
45
+ const keys = answers.map((answer) => keyOf(answer.query));
46
+ if (new Set(keys).size !== keys.length)
47
+ throw new Error(`RecordingAuthorization duplicate ${kind} answer`);
48
+ }
49
+ }
50
+ function permissionKey(query) {
51
+ return JSON.stringify(permissionQuestionIdentity(query));
52
+ }
53
+ function lookupAnswerKey(query) {
54
+ return JSON.stringify(lookupQuestionIdentity(query));
55
+ }
56
+ //# sourceMappingURL=recording-authorization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recording-authorization.js","sourceRoot":"","sources":["../../src/runtime/recording-authorization.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,wBAAwB,CAAC;AAShC,6GAA6G;AAC7G,MAAM,OAAO,sBAAsB;IAKJ,OAAO;IAJ3B,SAAS,GAGZ,EAAE,CAAC;IACT,YAA6B,OAAO,GAAkC,EAAE;uBAA3C,OAAO;QAClC,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;QAC1E,IAAI,CAAC,sBAAsB,CACzB,OAAO,C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AO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CACP,iFAAiF,CAClF,CACF,CAAC;IACJ,CAAC;IACO,IAAI,CACV,OAAqB,EACrB,KAAoC,EACpC,KAAiB,EACjB,IAAY;QAEZ,MAAM,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;QACzB,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC;QAC1E,IAAI,CAAC,KAAK;YACR,MAAM,IAAI,KAAK,CAAC,qCAAqC,IAAI,KAAK,GAAG,EAAE,CAAC,CAAC;QACvE,OAAO,KAAK,CAAC;IACf,CAAC;IACO,sBAAsB,CAC5B,OAAqB,EACrB,KAAoC,EACpC,IAAY;QAEZ,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAC1D,IAAI,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM;YACpC,MAAM,IAAI,KAAK,CAAC,oCAAoC,IAAI,SAAS,CAAC,CAAC;IACvE,CAAC;CACF;AAED,SAAS,aAAa,CAAC,KAAsB;IAC3C,OAAO,IAAI,CAAC,SAAS,CAAC,0BAA0B,CAAC,KAAK,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED,SAAS,eAAe,CAAC,KAAqB;IAC5C,OAAO,IAAI,CAAC,SAAS,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC,CAAC;AACvD,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { RelationshipWrite } from "./authorization.js";
2
+ /** Bounded maintenance read, separate from application permission lookups. */
3
+ export type RelationshipPageRequest = {
4
+ readonly resourceType: string;
5
+ readonly cursor?: string;
6
+ };
7
+ /** Opaque cursors resume the same filtered read; null means the scan is complete. */
8
+ export type RelationshipPage = {
9
+ readonly relationships: readonly RelationshipWrite[];
10
+ readonly nextCursor: string | null;
11
+ };
12
+ //# sourceMappingURL=relationship-page.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relationship-page.d.ts","sourceRoot":"","sources":["../../src/runtime/relationship-page.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE5D,8EAA8E;AAC9E,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,qFAAqF;AACrF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,aAAa,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACrD,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CACpC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=relationship-page.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relationship-page.js","sourceRoot":"","sources":["../../src/runtime/relationship-page.ts"],"names":[],"mappings":""}
@@ -0,0 +1,49 @@
1
+ import type { SubjectRef } from "./authorization.js";
2
+ /**
3
+ * Resolves the authenticated subject from an incoming request. The concrete
4
+ * implementation lives with the identity wiring (Better Auth session lookup);
5
+ * the guard depends only on this port so the authz lib stays vendor-free
6
+ * (docs/architecture/engineering-principles.md §3).
7
+ */
8
+ export type RequestHeaders = {
9
+ headers: Record<string, string | string[] | undefined>;
10
+ /** The request's path and query, when the caller has one. */
11
+ readonly url?: string;
12
+ };
13
+ /**
14
+ * Which credential authenticated the caller:
15
+ * session cookie / opaque bearer refresh layer, a human access JWT, or a
16
+ * device JWT. Recorded for diagnostics only — it never widens or narrows a
17
+ * decision.
18
+ */
19
+ export type AuthMethod = "session-cookie" | "access-jwt" | "device-jwt";
20
+ /** The authenticated subject plus the credential that produced it. */
21
+ export type ResolvedSubject = {
22
+ readonly subject: SubjectRef;
23
+ readonly method: AuthMethod;
24
+ /**
25
+ * When the caller last proved who they are on the session that
26
+ * authenticated them, by a sign-in the server itself forced and checked
27
+ * (the auth server stamps it as it makes the session), for the few writes
28
+ * that ask for a recent sign-in. Present only when the resolver read a
29
+ * session that carries the stamp; an ordinary sign-in, a JWT, or a
30
+ * resolver that cannot say leaves it out, and such a write refuses.
31
+ */
32
+ readonly sessionReauthenticatedAt?: Date;
33
+ };
34
+ /**
35
+ * Abstract class on purpose: it is both the TypeScript interface and the
36
+ * wiring seam. Implemented by the importing app (for example a session lookup
37
+ * in its identity layer); bound by the composition root.
38
+ */
39
+ export declare abstract class RequestSubject {
40
+ /** Returns the authenticated subject, or null when unauthenticated. */
41
+ abstract resolve(request: RequestHeaders): Promise<SubjectRef | null>;
42
+ /**
43
+ * The same resolution, plus which credential answered. Optional so every
44
+ * existing resolver and test fake stays valid: callers that want the
45
+ * method fall back to `resolve` and record none.
46
+ */
47
+ resolveWithMethod?(request: RequestHeaders): Promise<ResolvedSubject | null>;
48
+ }
49
+ //# sourceMappingURL=request-subject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-subject.d.ts","sourceRoot":"","sources":["../../src/runtime/request-subject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;IACvD,6DAA6D;IAC7D,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,gBAAgB,GAAG,YAAY,GAAG,YAAY,CAAC;AAExE,sEAAsE;AACtE,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B;;;;;;;OAOG;IACH,QAAQ,CAAC,wBAAwB,CAAC,EAAE,IAAI,CAAC;CAC1C,CAAC;AAEF;;;;GAIG;AACH,8BAAsB,cAAc;IAClC,uEAAuE;IACvE,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IAEtE;;;;OAIG;IACH,iBAAiB,CAAC,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;CAC9E"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Abstract class on purpose: it is both the TypeScript interface and the
3
+ * wiring seam. Implemented by the importing app (for example a session lookup
4
+ * in its identity layer); bound by the composition root.
5
+ */
6
+ export class RequestSubject {
7
+ }
8
+ //# sourceMappingURL=request-subject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-subject.js","sourceRoot":"","sources":["../../src/runtime/request-subject.ts"],"names":[],"mappings":"AAqCA;;;;GAIG;AACH,MAAM,OAAgB,cAAc;CAUnC"}
@@ -0,0 +1,15 @@
1
+ export type ReadConsistencyDecision = {
2
+ readonly kind: "fully-consistent";
3
+ } | {
4
+ readonly kind: "at-least-as-fresh";
5
+ readonly token: string;
6
+ } | {
7
+ readonly kind: "minimize-latency";
8
+ };
9
+ export declare function resolveReadConsistency(input: {
10
+ readonly adapterConsistency: "minimize-latency" | "fully-consistent";
11
+ readonly queryConsistency?: "fully-consistent";
12
+ readonly queryToken?: string;
13
+ readonly requestToken?: string;
14
+ }): ReadConsistencyDecision;
15
+ //# sourceMappingURL=resolve-read-consistency.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-read-consistency.d.ts","sourceRoot":"","sources":["../../src/runtime/resolve-read-consistency.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,uBAAuB,GAC/B;IAAE,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAA;CAAE,GACrC;IAAE,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC9D;IAAE,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAE1C,wBAAgB,sBAAsB,CAAC,KAAK,EAAE;IAC5C,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB,GAAG,kBAAkB,CAAC;IACrE,QAAQ,CAAC,gBAAgB,CAAC,EAAE,kBAAkB,CAAC;IAC/C,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAChC,GAAG,uBAAuB,CAa1B"}
@@ -0,0 +1,13 @@
1
+ import { presentToken } from "./present-token.js";
2
+ export function resolveReadConsistency(input) {
3
+ if (input.adapterConsistency === "fully-consistent" ||
4
+ input.queryConsistency === "fully-consistent") {
5
+ return { kind: "fully-consistent" };
6
+ }
7
+ const token = presentToken(input.queryToken) ?? presentToken(input.requestToken);
8
+ if (token !== undefined) {
9
+ return { kind: "at-least-as-fresh", token };
10
+ }
11
+ return { kind: "minimize-latency" };
12
+ }
13
+ //# sourceMappingURL=resolve-read-consistency.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-read-consistency.js","sourceRoot":"","sources":["../../src/runtime/resolve-read-consistency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAOlD,MAAM,UAAU,sBAAsB,CAAC,KAKtC;IACC,IACE,KAAK,CAAC,kBAAkB,KAAK,kBAAkB;QAC/C,KAAK,CAAC,gBAAgB,KAAK,kBAAkB,EAC7C,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,kBAAkB,EAAE,CAAC;IACtC,CAAC;IACD,MAAM,KAAK,GACT,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,YAAY,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACrE,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,EAAE,IAAI,EAAE,mBAAmB,EAAE,KAAK,EAAE,CAAC;IAC9C,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,kBAAkB,EAAE,CAAC;AACtC,CAAC"}
@@ -0,0 +1,66 @@
1
+ import type { SubjectRef } from "./authorization.js";
2
+ /**
3
+ * Where the resource id for a route-level check comes from. The source names
4
+ * the RESOURCE side of the question only — the subject is always the
5
+ * session/JWT-resolved caller; nothing client-supplied ever names the
6
+ * subject. Resolution happens at the edge (the kit); this table only ever
7
+ * sees the resolved id.
8
+ */
9
+ export type ResourceIdSource = {
10
+ kind: "param";
11
+ name: string;
12
+ } | {
13
+ kind: "body";
14
+ name: string;
15
+ } | {
16
+ kind: "query";
17
+ name: string;
18
+ } | {
19
+ kind: "header";
20
+ name: string;
21
+ } | {
22
+ kind: "fixed";
23
+ id: string;
24
+ } | {
25
+ kind: "none";
26
+ };
27
+ /** A route's declared permission requirement. */
28
+ export type RequirePermissionMetadata = {
29
+ resourceType: string;
30
+ permission: string;
31
+ source: ResourceIdSource;
32
+ };
33
+ /**
34
+ * The guard's pure decision (docs/testing/README.md — guards are tested as
35
+ * pure decisions plus one e2e for the wiring). Given the route's metadata,
36
+ * the resolved subject, and the check outcome, produce the verdict.
37
+ */
38
+ export type RouteAccessInput = {
39
+ isPublic: boolean;
40
+ sessionOnly: boolean;
41
+ permission: RequirePermissionMetadata | undefined;
42
+ subject: SubjectRef | null;
43
+ resourceId: string | undefined;
44
+ /** result of Authorization.check, when a permission check applies */
45
+ checkResult?: boolean;
46
+ };
47
+ export type RouteAccessVerdict = {
48
+ outcome: "allow";
49
+ } | {
50
+ outcome: "unauthenticated";
51
+ } | {
52
+ outcome: "not-found";
53
+ } | {
54
+ outcome: "check";
55
+ resource: {
56
+ type: string;
57
+ id: string;
58
+ };
59
+ permission: string;
60
+ };
61
+ /**
62
+ * Two-phase evaluation: call once without checkResult to learn whether a
63
+ * check() is needed (outcome "check"), then again with the result.
64
+ */
65
+ export declare function evaluateRouteAccess(input: RouteAccessInput): RouteAccessVerdict;
66
+ //# sourceMappingURL=route-access.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route-access.d.ts","sourceRoot":"","sources":["../../src/runtime/route-access.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GACxB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAC7B;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAErB,iDAAiD;AACjD,MAAM,MAAM,yBAAyB,GAAG;IACtC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,gBAAgB,CAAC;CAC1B,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,yBAAyB,GAAG,SAAS,CAAC;IAClD,OAAO,EAAE,UAAU,GAAG,IAAI,CAAC;IAC3B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,qEAAqE;IACrE,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAC1B;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,GACpB;IAAE,OAAO,EAAE,iBAAiB,CAAA;CAAE,GAC9B;IAAE,OAAO,EAAE,WAAW,CAAA;CAAE,GACxB;IACE,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IACvC,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEN;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,gBAAgB,GACtB,kBAAkB,CA6BpB"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Two-phase evaluation: call once without checkResult to learn whether a
3
+ * check() is needed (outcome "check"), then again with the result.
4
+ */
5
+ export function evaluateRouteAccess(input) {
6
+ if (input.isPublic) {
7
+ return { outcome: "allow" };
8
+ }
9
+ if (!input.permission && !input.sessionOnly) {
10
+ // Routes outside the domain walls carry no metadata (health, root).
11
+ return { outcome: "allow" };
12
+ }
13
+ if (!input.subject) {
14
+ return { outcome: "unauthenticated" };
15
+ }
16
+ if (!input.permission) {
17
+ return { outcome: "allow" }; // @RequireSession — mutation/query owns authorization
18
+ }
19
+ if (!input.resourceId) {
20
+ // Misconfigured route (param missing) — fail closed.
21
+ return { outcome: "not-found" };
22
+ }
23
+ if (input.checkResult === undefined) {
24
+ return {
25
+ outcome: "check",
26
+ resource: {
27
+ type: input.permission.resourceType,
28
+ id: input.resourceId,
29
+ },
30
+ permission: input.permission.permission,
31
+ };
32
+ }
33
+ return input.checkResult ? { outcome: "allow" } : { outcome: "not-found" };
34
+ }
35
+ //# sourceMappingURL=route-access.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route-access.js","sourceRoot":"","sources":["../../src/runtime/route-access.ts"],"names":[],"mappings":"AAiDA;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CACjC,KAAuB;IAEvB,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;QACnB,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;IAC9B,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,UAAU,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;QAC5C,oEAAoE;QACpE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;IAC9B,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAAC;IACxC,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;QACtB,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,sDAAsD;IACrF,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;QACtB,qDAAqD;QACrD,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;IAClC,CAAC;IACD,IAAI,KAAK,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;QACpC,OAAO;YACL,OAAO,EAAE,OAAO;YAChB,QAAQ,EAAE;gBACR,IAAI,EAAE,KAAK,CAAC,UAAU,CAAC,YAAY;gBACnC,EAAE,EAAE,KAAK,CAAC,UAAU;aACrB;YACD,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,UAAU;SACxC,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;AAC7E,CAAC"}
@@ -0,0 +1,47 @@
1
+ import type { AccessModel, ScopePlan } from "../index.js";
2
+ import type { ResourceLookup, SubjectRef } from "./authorization.js";
3
+ /** One question SpiceDB answers for a plan: which ids of `resourceType` the caller may `permission`. */
4
+ export type ScopeQuestion = {
5
+ readonly resourceType: string;
6
+ readonly permission: string;
7
+ };
8
+ /**
9
+ * Everything a list handler needs to render its scope as SQL: the compiled
10
+ * plan, who asked, and each question's answer keyed by `scopeQuestionKey`.
11
+ */
12
+ export type ScopeAnswer = {
13
+ readonly resourceType: string;
14
+ readonly permission: string;
15
+ readonly plan: ScopePlan;
16
+ readonly subject: SubjectRef;
17
+ readonly idsByQuestion: ReadonlyMap<string, readonly string[]>;
18
+ };
19
+ /** The port `answerScope` asks through; `Authorization` satisfies it. */
20
+ export type ScopeLookups = {
21
+ lookupResources(query: ResourceLookup): Promise<readonly string[]>;
22
+ };
23
+ export declare function scopeQuestionKey(question: ScopeQuestion): string;
24
+ /**
25
+ * Compile the scope plan for a list of `resourceType` by `permission`. Throws,
26
+ * naming every rule path that cannot be compiled, so a list on a model whose
27
+ * bindings cannot carry its rules refuses to register.
28
+ */
29
+ export declare function planScopedList(model: AccessModel, resourceType: string, permission: string): ScopePlan;
30
+ /**
31
+ * Every distinct question a plan needs answered, in first-seen order: each
32
+ * scope lookup, plus each sparse direct grant asked on the record it sits on
33
+ * (inside a `via`, that is the walked-to record).
34
+ */
35
+ export declare function scopeQuestions(plan: ScopePlan, resourceType: string): readonly ScopeQuestion[];
36
+ /**
37
+ * Ask every question the plan needs, in parallel, once each. An empty answer
38
+ * is kept, not short-circuited: an `any` with one empty arm can still match.
39
+ */
40
+ export declare function answerScope(input: {
41
+ readonly resourceType: string;
42
+ readonly permission: string;
43
+ readonly plan: ScopePlan;
44
+ readonly subject: SubjectRef;
45
+ readonly lookups: ScopeLookups;
46
+ }): Promise<ScopeAnswer>;
47
+ //# sourceMappingURL=scope-answer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope-answer.d.ts","sourceRoot":"","sources":["../../src/runtime/scope-answer.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE1D,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,oBAAoB,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B"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * The SpiceDB half of a scoped record list: compile the permission's scope
3
+ * plan once, then per request ask each distinct scope question once and keep
4
+ * the answers by question. The SQL half (`scopePredicate`) renders the plan
5
+ * against those answers; nothing here touches a table.
6
+ */
7
+ import { compileScopePlan } from "../index.js";
8
+ export function scopeQuestionKey(question) {
9
+ return `${question.resourceType}#${question.permission}`;
10
+ }
11
+ /**
12
+ * Compile the scope plan for a list of `resourceType` by `permission`. Throws,
13
+ * naming every rule path that cannot be compiled, so a list on a model whose
14
+ * bindings cannot carry its rules refuses to register.
15
+ */
16
+ export function planScopedList(model, resourceType, permission) {
17
+ return compileScopePlan(model, resourceType, permission);
18
+ }
19
+ /**
20
+ * Every distinct question a plan needs answered, in first-seen order: each
21
+ * scope lookup, plus each sparse direct grant asked on the record it sits on
22
+ * (inside a `via`, that is the walked-to record).
23
+ */
24
+ export function scopeQuestions(plan, resourceType) {
25
+ const byKey = new Map();
26
+ collectQuestions(plan, resourceType, byKey);
27
+ return [...byKey.values()];
28
+ }
29
+ function collectQuestions(plan, resourceType, byKey) {
30
+ switch (plan.kind) {
31
+ case "lookup":
32
+ remember(byKey, {
33
+ resourceType: plan.targetType,
34
+ permission: plan.targetPermission,
35
+ });
36
+ return;
37
+ case "direct":
38
+ remember(byKey, { resourceType, permission: plan.role });
39
+ return;
40
+ case "via":
41
+ collectQuestions(plan.plan, plan.targetType, byKey);
42
+ return;
43
+ case "not":
44
+ collectQuestions(plan.plan, resourceType, byKey);
45
+ return;
46
+ case "any":
47
+ case "all":
48
+ for (const child of plan.plans) {
49
+ collectQuestions(child, resourceType, byKey);
50
+ }
51
+ return;
52
+ case "tag":
53
+ return;
54
+ }
55
+ }
56
+ function remember(byKey, question) {
57
+ const key = scopeQuestionKey(question);
58
+ if (!byKey.has(key)) {
59
+ byKey.set(key, question);
60
+ }
61
+ }
62
+ /**
63
+ * Ask every question the plan needs, in parallel, once each. An empty answer
64
+ * is kept, not short-circuited: an `any` with one empty arm can still match.
65
+ */
66
+ export async function answerScope(input) {
67
+ const questions = scopeQuestions(input.plan, input.resourceType);
68
+ const answers = await Promise.all(questions.map(async (question) => {
69
+ const ids = await input.lookups.lookupResources({
70
+ subject: input.subject,
71
+ permission: question.permission,
72
+ resourceType: question.resourceType,
73
+ });
74
+ return [scopeQuestionKey(question), ids];
75
+ }));
76
+ return {
77
+ resourceType: input.resourceType,
78
+ permission: input.permission,
79
+ plan: input.plan,
80
+ subject: input.subject,
81
+ idsByQuestion: new Map(answers),
82
+ };
83
+ }
84
+ //# sourceMappingURL=scope-answer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope-answer.js","sourceRoot":"","sources":["../../src/runtime/scope-answer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AA4B/C,MAAM,UAAU,gBAAgB,CAAC,QAAuB;IACtD,OAAO,GAAG,QAAQ,CAAC,YAAY,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC;AAC3D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAC5B,KAAkB,EAClB,YAAoB,EACpB,UAAkB;IAElB,OAAO,gBAAgB,CAAC,KAAK,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;AAC3D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAC5B,IAAe,EACf,YAAoB;IAEpB,MAAM,KAAK,GAAG,IAAI,GAAG,EAAyB,CAAC;IAC/C,gBAAgB,CAAC,IAAI,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;IAC5C,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;AAC7B,CAAC;AAED,SAAS,gBAAgB,CACvB,IAAe,EACf,YAAoB,EACpB,KAAiC;IAEjC,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,QAAQ;YACX,QAAQ,CAAC,KAAK,EAAE;gBACd,Y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AC,OAAO,CAAC,eAAe,CAAC;YAC9C,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,UAAU,EAAE,QAAQ,CAAC,UAAU;YAC/B,YAAY,EAAE,QAAQ,CAAC,YAAY;SACpC,CAAC,CAAC;QACH,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,CAAC;IAC3C,CAAC,CACF,CACF,CAAC;IACF,OAAO;QACL,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,aAAa,EAAE,IAAI,GAAG,CAAC,OAAO,CAAC;KAChC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { FakeAuthorization } from "./fake-authorization.js";
2
+ export { RecordingAuthorization } from "./recording-authorization.js";
3
+ export { runOutsideHeldPartitions } from "./owner-lock.js";
4
+ //# sourceMappingURL=testing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../src/runtime/testing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { FakeAuthorization } from "./fake-authorization.js";
2
+ export { RecordingAuthorization } from "./recording-authorization.js";
3
+ export { runOutsideHeldPartitions } from "./owner-lock.js";
4
+ //# sourceMappingURL=testing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.js","sourceRoot":"","sources":["../../src/runtime/testing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { type AuthorizationSchemaStore, type SchemaRewriteStep } from "./authorization-schema-store.js";
2
+ import type { ZedRelation } from "./logic/parse-zed-schema-surface.js";
3
+ export type ApplyAuthorizationSchemaLog = {
4
+ info(context: object, message: string): void;
5
+ };
6
+ export type ApplyAuthorizationSchemaReport = {
7
+ removedTypes: readonly string[];
8
+ removedRelations: readonly ZedRelation[];
9
+ wroteSchema: boolean;
10
+ snapshot: "cloned" | "skipped" | "not-needed";
11
+ };
12
+ /** Deletes leftover tuples for removed definitions/relations, then WriteSchema. */
13
+ export declare function applyDesiredAuthorizationSchema(input: {
14
+ store: AuthorizationSchemaStore;
15
+ desiredSchema: string;
16
+ rewriteSteps?: readonly SchemaRewriteStep[];
17
+ snapshotDatastore?: () => Promise<"cloned" | "skipped">;
18
+ log?: ApplyAuthorizationSchemaLog;
19
+ }): Promise<ApplyAuthorizationSchemaReport>;
20
+ //# sourceMappingURL=apply-desired-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply-desired-schema.d.ts","sourceRoot":"","sources":["../../src/schema/apply-desired-schema.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,wBAAwB,EAE7B,KAAK,iBAAiB,EACvB,MAAM,iCAAiC,CAAC;AAGzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AASvE,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9C,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,gBAAgB,EAAE,SAAS,WAAW,EAAE,CAAC;IACzC,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,QAAQ,GAAG,SAAS,GAAG,YAAY,CAAC;CAC/C,CAAC;AAEF,mFAAmF;AACnF,wBAAsB,+BAA+B,CAAC,KAAK,EAAE;IAC3D,KAAK,EAAE,wBAAwB,CAAC;IAChC,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,SAAS,iBAAiB,EAAE,CAAC;IAC5C,iBAAiB,CAAC,EAAE,MAAM,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC;IACxD,GAAG,CAAC,EAAE,2BAA2B,CAAC;CACnC,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAwB1C"}