@dads-framework/spicedb-access 0.0.0-stage → 0.4.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 (381) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +80 -2
  3. package/bin/dads-import-spicedb.mjs +139 -0
  4. package/dist/authz-journal/index.d.ts +3 -0
  5. package/dist/authz-journal/index.d.ts.map +1 -0
  6. package/dist/authz-journal/index.js +3 -0
  7. package/dist/authz-journal/index.js.map +1 -0
  8. package/dist/authz-journal/migration-journal.access.d.ts +11 -0
  9. package/dist/authz-journal/migration-journal.access.d.ts.map +1 -0
  10. package/dist/authz-journal/migration-journal.access.js +16 -0
  11. package/dist/authz-journal/migration-journal.access.js.map +1 -0
  12. package/dist/authz-journal/migration-version.access.d.ts +7 -0
  13. package/dist/authz-journal/migration-version.access.d.ts.map +1 -0
  14. package/dist/authz-journal/migration-version.access.js +11 -0
  15. package/dist/authz-journal/migration-version.access.js.map +1 -0
  16. package/dist/index.d.ts +44 -0
  17. package/dist/index.d.ts.map +1 -0
  18. package/dist/index.js +43 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/lib/access/check-all.d.ts +8 -0
  21. package/dist/lib/access/check-all.d.ts.map +1 -0
  22. package/dist/lib/access/check-all.js +11 -0
  23. package/dist/lib/access/check-all.js.map +1 -0
  24. package/dist/lib/access/guarded-authorization.d.ts +71 -0
  25. package/dist/lib/access/guarded-authorization.d.ts.map +1 -0
  26. package/dist/lib/access/guarded-authorization.js +162 -0
  27. package/dist/lib/access/guarded-authorization.js.map +1 -0
  28. package/dist/lib/access/list-only-visible.d.ts +23 -0
  29. package/dist/lib/access/list-only-visible.d.ts.map +1 -0
  30. package/dist/lib/access/list-only-visible.js +21 -0
  31. package/dist/lib/access/list-only-visible.js.map +1 -0
  32. package/dist/lib/access/logic/spice-db-empty-schema.d.ts +3 -0
  33. package/dist/lib/access/logic/spice-db-empty-schema.d.ts.map +1 -0
  34. package/dist/lib/access/logic/spice-db-empty-schema.js +17 -0
  35. package/dist/lib/access/logic/spice-db-empty-schema.js.map +1 -0
  36. package/dist/lib/access/logic/spice-db-security.d.ts +4 -0
  37. package/dist/lib/access/logic/spice-db-security.d.ts.map +1 -0
  38. package/dist/lib/access/logic/spice-db-security.js +8 -0
  39. package/dist/lib/access/logic/spice-db-security.js.map +1 -0
  40. package/dist/lib/access/logic/spice-db-write-retry.d.ts +22 -0
  41. package/dist/lib/access/logic/spice-db-write-retry.d.ts.map +1 -0
  42. package/dist/lib/access/logic/spice-db-write-retry.js +35 -0
  43. package/dist/lib/access/logic/spice-db-write-retry.js.map +1 -0
  44. package/dist/lib/access/missing-ownership-tuples.d.ts +19 -0
  45. package/dist/lib/access/missing-ownership-tuples.d.ts.map +1 -0
  46. package/dist/lib/access/missing-ownership-tuples.js +12 -0
  47. package/dist/lib/access/missing-ownership-tuples.js.map +1 -0
  48. package/dist/lib/access/newest-written-token.d.ts +37 -0
  49. package/dist/lib/access/newest-written-token.d.ts.map +1 -0
  50. package/dist/lib/access/newest-written-token.js +56 -0
  51. package/dist/lib/access/newest-written-token.js.map +1 -0
  52. package/dist/lib/access/one-write-at-a-time.d.ts +14 -0
  53. package/dist/lib/access/one-write-at-a-time.d.ts.map +1 -0
  54. package/dist/lib/access/one-write-at-a-time.js +18 -0
  55. package/dist/lib/access/one-write-at-a-time.js.map +1 -0
  56. package/dist/lib/access/spice-db-authorization.d.ts +102 -0
  57. package/dist/lib/access/spice-db-authorization.d.ts.map +1 -0
  58. package/dist/lib/access/spice-db-authorization.js +275 -0
  59. package/dist/lib/access/spice-db-authorization.js.map +1 -0
  60. package/dist/lib/access/spice-db-clients.d.ts +19 -0
  61. package/dist/lib/access/spice-db-clients.d.ts.map +1 -0
  62. package/dist/lib/access/spice-db-clients.js +27 -0
  63. package/dist/lib/access/spice-db-clients.js.map +1 -0
  64. package/dist/lib/access/spice-db-consistency.d.ts +24 -0
  65. package/dist/lib/access/spice-db-consistency.d.ts.map +1 -0
  66. package/dist/lib/access/spice-db-consistency.js +44 -0
  67. package/dist/lib/access/spice-db-consistency.js.map +1 -0
  68. package/dist/lib/access/spice-db-permission-checks.d.ts +21 -0
  69. package/dist/lib/access/spice-db-permission-checks.d.ts.map +1 -0
  70. package/dist/lib/access/spice-db-permission-checks.js +102 -0
  71. package/dist/lib/access/spice-db-permission-checks.js.map +1 -0
  72. package/dist/lib/access/spice-db-relationship-read.d.ts +5 -0
  73. package/dist/lib/access/spice-db-relationship-read.d.ts.map +1 -0
  74. package/dist/lib/access/spice-db-relationship-read.js +21 -0
  75. package/dist/lib/access/spice-db-relationship-read.js.map +1 -0
  76. package/dist/lib/access/spice-db-write-deadline.d.ts +23 -0
  77. package/dist/lib/access/spice-db-write-deadline.d.ts.map +1 -0
  78. package/dist/lib/access/spice-db-write-deadline.js +41 -0
  79. package/dist/lib/access/spice-db-write-deadline.js.map +1 -0
  80. package/dist/lib/access/tallied-authorization.d.ts +31 -0
  81. package/dist/lib/access/tallied-authorization.d.ts.map +1 -0
  82. package/dist/lib/access/tallied-authorization.js +62 -0
  83. package/dist/lib/access/tallied-authorization.js.map +1 -0
  84. package/dist/lib/access/testing/acting-company-fixture.d.ts +46 -0
  85. package/dist/lib/access/testing/acting-company-fixture.d.ts.map +1 -0
  86. package/dist/lib/access/testing/acting-company-fixture.js +74 -0
  87. package/dist/lib/access/testing/acting-company-fixture.js.map +1 -0
  88. package/dist/lib/access-changes/access-change.ids.d.ts +5 -0
  89. package/dist/lib/access-changes/access-change.ids.d.ts.map +1 -0
  90. package/dist/lib/access-changes/access-change.ids.js +4 -0
  91. package/dist/lib/access-changes/access-change.ids.js.map +1 -0
  92. package/dist/lib/access-changes/apply-after-commit.d.ts +25 -0
  93. package/dist/lib/access-changes/apply-after-commit.d.ts.map +1 -0
  94. package/dist/lib/access-changes/apply-after-commit.js +91 -0
  95. package/dist/lib/access-changes/apply-after-commit.js.map +1 -0
  96. package/dist/lib/access-changes/apply.d.ts +60 -0
  97. package/dist/lib/access-changes/apply.d.ts.map +1 -0
  98. package/dist/lib/access-changes/apply.js +133 -0
  99. package/dist/lib/access-changes/apply.js.map +1 -0
  100. package/dist/lib/access-changes/claim.d.ts +79 -0
  101. package/dist/lib/access-changes/claim.d.ts.map +1 -0
  102. package/dist/lib/access-changes/claim.js +3 -0
  103. package/dist/lib/access-changes/claim.js.map +1 -0
  104. package/dist/lib/access-changes/complete.d.ts +38 -0
  105. package/dist/lib/access-changes/complete.d.ts.map +1 -0
  106. package/dist/lib/access-changes/complete.js +129 -0
  107. package/dist/lib/access-changes/complete.js.map +1 -0
  108. package/dist/lib/access-changes/completion-status.d.ts +21 -0
  109. package/dist/lib/access-changes/completion-status.d.ts.map +1 -0
  110. package/dist/lib/access-changes/completion-status.js +7 -0
  111. package/dist/lib/access-changes/completion-status.js.map +1 -0
  112. package/dist/lib/access-changes/enqueue.d.ts +14 -0
  113. package/dist/lib/access-changes/enqueue.d.ts.map +1 -0
  114. package/dist/lib/access-changes/enqueue.js +5 -0
  115. package/dist/lib/access-changes/enqueue.js.map +1 -0
  116. package/dist/lib/access-changes/logic/claim-rules.d.ts +49 -0
  117. package/dist/lib/access-changes/logic/claim-rules.d.ts.map +1 -0
  118. package/dist/lib/access-changes/logic/claim-rules.js +48 -0
  119. package/dist/lib/access-changes/logic/claim-rules.js.map +1 -0
  120. package/dist/lib/access-changes/postgres/access-changes.tables.d.ts +342 -0
  121. package/dist/lib/access-changes/postgres/access-changes.tables.d.ts.map +1 -0
  122. package/dist/lib/access-changes/postgres/access-changes.tables.js +36 -0
  123. package/dist/lib/access-changes/postgres/access-changes.tables.js.map +1 -0
  124. package/dist/lib/access-changes/postgres/claim.d.ts +43 -0
  125. package/dist/lib/access-changes/postgres/claim.d.ts.map +1 -0
  126. package/dist/lib/access-changes/postgres/claim.js +132 -0
  127. package/dist/lib/access-changes/postgres/claim.js.map +1 -0
  128. package/dist/lib/access-changes/postgres/completion-status.d.ts +27 -0
  129. package/dist/lib/access-changes/postgres/completion-status.d.ts.map +1 -0
  130. package/dist/lib/access-changes/postgres/completion-status.js +64 -0
  131. package/dist/lib/access-changes/postgres/completion-status.js.map +1 -0
  132. package/dist/lib/access-changes/postgres/enqueue.d.ts +30 -0
  133. package/dist/lib/access-changes/postgres/enqueue.d.ts.map +1 -0
  134. package/dist/lib/access-changes/postgres/enqueue.js +92 -0
  135. package/dist/lib/access-changes/postgres/enqueue.js.map +1 -0
  136. package/dist/lib/access-changes/postgres/migrations/20260828163001_authorization_outbox.migration.d.ts +4 -0
  137. package/dist/lib/access-changes/postgres/migrations/20260828163001_authorization_outbox.migration.d.ts.map +1 -0
  138. package/dist/lib/access-changes/postgres/migrations/20260828163001_authorization_outbox.migration.js +43 -0
  139. package/dist/lib/access-changes/postgres/migrations/20260828163001_authorization_outbox.migration.js.map +1 -0
  140. package/dist/lib/access-changes/postgres/owner-lock.d.ts +85 -0
  141. package/dist/lib/access-changes/postgres/owner-lock.d.ts.map +1 -0
  142. package/dist/lib/access-changes/postgres/owner-lock.js +219 -0
  143. package/dist/lib/access-changes/postgres/owner-lock.js.map +1 -0
  144. package/dist/lib/access-changes/postgres/requeue-failed.d.ts +17 -0
  145. package/dist/lib/access-changes/postgres/requeue-failed.d.ts.map +1 -0
  146. package/dist/lib/access-changes/postgres/requeue-failed.js +25 -0
  147. package/dist/lib/access-changes/postgres/requeue-failed.js.map +1 -0
  148. package/dist/lib/access-changes/revoke.d.ts +104 -0
  149. package/dist/lib/access-changes/revoke.d.ts.map +1 -0
  150. package/dist/lib/access-changes/revoke.js +48 -0
  151. package/dist/lib/access-changes/revoke.js.map +1 -0
  152. package/dist/lib/access-changes/synced-row-relationships.d.ts +56 -0
  153. package/dist/lib/access-changes/synced-row-relationships.d.ts.map +1 -0
  154. package/dist/lib/access-changes/synced-row-relationships.js +111 -0
  155. package/dist/lib/access-changes/synced-row-relationships.js.map +1 -0
  156. package/dist/lib/catalog-sizes/audit-catalog-sizes.job.d.ts +41 -0
  157. package/dist/lib/catalog-sizes/audit-catalog-sizes.job.d.ts.map +1 -0
  158. package/dist/lib/catalog-sizes/audit-catalog-sizes.job.js +77 -0
  159. package/dist/lib/catalog-sizes/audit-catalog-sizes.job.js.map +1 -0
  160. package/dist/lib/catalog-sizes/catalog-size-reader.d.ts +15 -0
  161. package/dist/lib/catalog-sizes/catalog-size-reader.d.ts.map +1 -0
  162. package/dist/lib/catalog-sizes/catalog-size-reader.js +41 -0
  163. package/dist/lib/catalog-sizes/catalog-size-reader.js.map +1 -0
  164. package/dist/lib/catalog-sizes/catalog-tables.d.ts +38 -0
  165. package/dist/lib/catalog-sizes/catalog-tables.d.ts.map +1 -0
  166. package/dist/lib/catalog-sizes/catalog-tables.js +52 -0
  167. package/dist/lib/catalog-sizes/catalog-tables.js.map +1 -0
  168. package/dist/lib/schema-migrate/clone-spice-db-datastore.d.ts +9 -0
  169. package/dist/lib/schema-migrate/clone-spice-db-datastore.d.ts.map +1 -0
  170. package/dist/lib/schema-migrate/clone-spice-db-datastore.js +47 -0
  171. package/dist/lib/schema-migrate/clone-spice-db-datastore.js.map +1 -0
  172. package/dist/lib/schema-migrate/parse-authorization-schema-migration-environment.d.ts +31 -0
  173. package/dist/lib/schema-migrate/parse-authorization-schema-migration-environment.d.ts.map +1 -0
  174. package/dist/lib/schema-migrate/parse-authorization-schema-migration-environment.js +26 -0
  175. package/dist/lib/schema-migrate/parse-authorization-schema-migration-environment.js.map +1 -0
  176. package/dist/lib/scoped-lists/keep-permitted.d.ts +24 -0
  177. package/dist/lib/scoped-lists/keep-permitted.d.ts.map +1 -0
  178. package/dist/lib/scoped-lists/keep-permitted.js +29 -0
  179. package/dist/lib/scoped-lists/keep-permitted.js.map +1 -0
  180. package/dist/lib/scoped-lists/scope-predicate.d.ts +18 -0
  181. package/dist/lib/scoped-lists/scope-predicate.d.ts.map +1 -0
  182. package/dist/lib/scoped-lists/scope-predicate.js +96 -0
  183. package/dist/lib/scoped-lists/scope-predicate.js.map +1 -0
  184. package/dist/lib/scoped-lists/scope-sql-bindings.d.ts +64 -0
  185. package/dist/lib/scoped-lists/scope-sql-bindings.d.ts.map +1 -0
  186. package/dist/lib/scoped-lists/scope-sql-bindings.js +45 -0
  187. package/dist/lib/scoped-lists/scope-sql-bindings.js.map +1 -0
  188. package/dist/lib/scoped-lists/testing/scoped-list-fixture.d.ts +369 -0
  189. package/dist/lib/scoped-lists/testing/scoped-list-fixture.d.ts.map +1 -0
  190. package/dist/lib/scoped-lists/testing/scoped-list-fixture.js +145 -0
  191. package/dist/lib/scoped-lists/testing/scoped-list-fixture.js.map +1 -0
  192. package/dist/migration/definition-changes.d.mts +28 -0
  193. package/dist/migration/definition-changes.d.mts.map +1 -0
  194. package/dist/migration/definition-changes.mjs +282 -0
  195. package/dist/migration/definition-changes.mjs.map +1 -0
  196. package/dist/migration/index.d.ts +15 -0
  197. package/dist/migration/index.d.ts.map +1 -0
  198. package/dist/migration/index.js +14 -0
  199. package/dist/migration/index.js.map +1 -0
  200. package/dist/migration/lib/access-migrations/assert-access-migrations-up-to-date.d.ts +26 -0
  201. package/dist/migration/lib/access-migrations/assert-access-migrations-up-to-date.d.ts.map +1 -0
  202. package/dist/migration/lib/access-migrations/assert-access-migrations-up-to-date.js +57 -0
  203. package/dist/migration/lib/access-migrations/assert-access-migrations-up-to-date.js.map +1 -0
  204. package/dist/migration/lib/access-migrations/define-access-migration.d.ts +51 -0
  205. package/dist/migration/lib/access-migrations/define-access-migration.d.ts.map +1 -0
  206. package/dist/migration/lib/access-migrations/define-access-migration.js +63 -0
  207. package/dist/migration/lib/access-migrations/define-access-migration.js.map +1 -0
  208. package/dist/migration/lib/access-migrations/diff-access-models-format.d.ts +12 -0
  209. package/dist/migration/lib/access-migrations/diff-access-models-format.d.ts.map +1 -0
  210. package/dist/migration/lib/access-migrations/diff-access-models-format.js +81 -0
  211. package/dist/migration/lib/access-migrations/diff-access-models-format.js.map +1 -0
  212. package/dist/migration/lib/access-migrations/diff-access-models.d.ts +79 -0
  213. package/dist/migration/lib/access-migrations/diff-access-models.d.ts.map +1 -0
  214. package/dist/migration/lib/access-migrations/diff-access-models.js +197 -0
  215. package/dist/migration/lib/access-migrations/diff-access-models.js.map +1 -0
  216. package/dist/migration/lib/access-migrations/index.d.ts +8 -0
  217. package/dist/migration/lib/access-migrations/index.d.ts.map +1 -0
  218. package/dist/migration/lib/access-migrations/index.js +8 -0
  219. package/dist/migration/lib/access-migrations/index.js.map +1 -0
  220. package/dist/migration/lib/access-migrations/run-postgres-access-migrations.d.ts +17 -0
  221. package/dist/migration/lib/access-migrations/run-postgres-access-migrations.d.ts.map +1 -0
  222. package/dist/migration/lib/access-migrations/run-postgres-access-migrations.js +105 -0
  223. package/dist/migration/lib/access-migrations/run-postgres-access-migrations.js.map +1 -0
  224. package/dist/migration/lib/access-migrations/run-spicedb-access-migrations.d.ts +21 -0
  225. package/dist/migration/lib/access-migrations/run-spicedb-access-migrations.d.ts.map +1 -0
  226. package/dist/migration/lib/access-migrations/run-spicedb-access-migrations.js +64 -0
  227. package/dist/migration/lib/access-migrations/run-spicedb-access-migrations.js.map +1 -0
  228. package/dist/migration/lib/access-migrations/run-sqlite-access-migrations.d.ts +18 -0
  229. package/dist/migration/lib/access-migrations/run-sqlite-access-migrations.d.ts.map +1 -0
  230. package/dist/migration/lib/access-migrations/run-sqlite-access-migrations.js +102 -0
  231. package/dist/migration/lib/access-migrations/run-sqlite-access-migrations.js.map +1 -0
  232. package/dist/migration/lib/access-migrations/sql-migration-types.d.ts +52 -0
  233. package/dist/migration/lib/access-migrations/sql-migration-types.d.ts.map +1 -0
  234. package/dist/migration/lib/access-migrations/sql-migration-types.js +57 -0
  235. package/dist/migration/lib/access-migrations/sql-migration-types.js.map +1 -0
  236. package/dist/migration/lib/journal/authorization-change-files.d.ts +7 -0
  237. package/dist/migration/lib/journal/authorization-change-files.d.ts.map +1 -0
  238. package/dist/migration/lib/journal/authorization-change-files.js +94 -0
  239. package/dist/migration/lib/journal/authorization-change-files.js.map +1 -0
  240. package/dist/migration/lib/journal/journal-entry.d.ts +47 -0
  241. package/dist/migration/lib/journal/journal-entry.d.ts.map +1 -0
  242. package/dist/migration/lib/journal/journal-entry.js +2 -0
  243. package/dist/migration/lib/journal/journal-entry.js.map +1 -0
  244. package/dist/migration/lib/journal/load-authorization-changes.d.ts +9 -0
  245. package/dist/migration/lib/journal/load-authorization-changes.d.ts.map +1 -0
  246. package/dist/migration/lib/journal/load-authorization-changes.js +32 -0
  247. package/dist/migration/lib/journal/load-authorization-changes.js.map +1 -0
  248. package/dist/migration/lib/journal/load-journal.d.ts +21 -0
  249. package/dist/migration/lib/journal/load-journal.d.ts.map +1 -0
  250. package/dist/migration/lib/journal/load-journal.js +73 -0
  251. package/dist/migration/lib/journal/load-journal.js.map +1 -0
  252. package/dist/migration/lib/journal/read-authorization-migration-status.d.ts +10 -0
  253. package/dist/migration/lib/journal/read-authorization-migration-status.d.ts.map +1 -0
  254. package/dist/migration/lib/journal/read-authorization-migration-status.js +64 -0
  255. package/dist/migration/lib/journal/read-authorization-migration-status.js.map +1 -0
  256. package/dist/migration/lib/logic/authorization-change-history.d.ts +22 -0
  257. package/dist/migration/lib/logic/authorization-change-history.d.ts.map +1 -0
  258. package/dist/migration/lib/logic/authorization-change-history.js +103 -0
  259. package/dist/migration/lib/logic/authorization-change-history.js.map +1 -0
  260. package/dist/migration/lib/logic/classify-schema-diff.d.ts +26 -0
  261. package/dist/migration/lib/logic/classify-schema-diff.d.ts.map +1 -0
  262. package/dist/migration/lib/logic/classify-schema-diff.js +104 -0
  263. package/dist/migration/lib/logic/classify-schema-diff.js.map +1 -0
  264. package/dist/migration/lib/postgres-to-spicedb/authzed-target-adapter.d.ts +62 -0
  265. package/dist/migration/lib/postgres-to-spicedb/authzed-target-adapter.d.ts.map +1 -0
  266. package/dist/migration/lib/postgres-to-spicedb/authzed-target-adapter.js +63 -0
  267. package/dist/migration/lib/postgres-to-spicedb/authzed-target-adapter.js.map +1 -0
  268. package/dist/migration/lib/postgres-to-spicedb/column-relation-outbox-triggers.d.ts +45 -0
  269. package/dist/migration/lib/postgres-to-spicedb/column-relation-outbox-triggers.d.ts.map +1 -0
  270. package/dist/migration/lib/postgres-to-spicedb/column-relation-outbox-triggers.js +140 -0
  271. package/dist/migration/lib/postgres-to-spicedb/column-relation-outbox-triggers.js.map +1 -0
  272. package/dist/migration/lib/postgres-to-spicedb/index.d.ts +4 -0
  273. package/dist/migration/lib/postgres-to-spicedb/index.d.ts.map +1 -0
  274. package/dist/migration/lib/postgres-to-spicedb/index.js +4 -0
  275. package/dist/migration/lib/postgres-to-spicedb/index.js.map +1 -0
  276. package/dist/migration/lib/postgres-to-spicedb/migrate-postgres-to-spicedb.d.ts +47 -0
  277. package/dist/migration/lib/postgres-to-spicedb/migrate-postgres-to-spicedb.d.ts.map +1 -0
  278. package/dist/migration/lib/postgres-to-spicedb/migrate-postgres-to-spicedb.js +199 -0
  279. package/dist/migration/lib/postgres-to-spicedb/migrate-postgres-to-spicedb.js.map +1 -0
  280. package/dist/migration/lib/run-authorization-changes.d.ts +5 -0
  281. package/dist/migration/lib/run-authorization-changes.d.ts.map +1 -0
  282. package/dist/migration/lib/run-authorization-changes.js +159 -0
  283. package/dist/migration/lib/run-authorization-changes.js.map +1 -0
  284. package/dist/migration/lib/run-authorization-migrations.d.ts +47 -0
  285. package/dist/migration/lib/run-authorization-migrations.d.ts.map +1 -0
  286. package/dist/migration/lib/run-authorization-migrations.js +202 -0
  287. package/dist/migration/lib/run-authorization-migrations.js.map +1 -0
  288. package/dist/migration/lib/scaffold/build-migration-bridge-schema.d.ts +7 -0
  289. package/dist/migration/lib/scaffold/build-migration-bridge-schema.d.ts.map +1 -0
  290. package/dist/migration/lib/scaffold/build-migration-bridge-schema.js +83 -0
  291. package/dist/migration/lib/scaffold/build-migration-bridge-schema.js.map +1 -0
  292. package/dist/migration/lib/scaffold/renumber-migration.d.ts +69 -0
  293. package/dist/migration/lib/scaffold/renumber-migration.d.ts.map +1 -0
  294. package/dist/migration/lib/scaffold/renumber-migration.js +170 -0
  295. package/dist/migration/lib/scaffold/renumber-migration.js.map +1 -0
  296. package/dist/migration/lib/scaffold/scaffold-authorization-change.d.ts +19 -0
  297. package/dist/migration/lib/scaffold/scaffold-authorization-change.d.ts.map +1 -0
  298. package/dist/migration/lib/scaffold/scaffold-authorization-change.js +47 -0
  299. package/dist/migration/lib/scaffold/scaffold-authorization-change.js.map +1 -0
  300. package/dist/migration/lib/scaffold/scaffold-migration.d.ts +32 -0
  301. package/dist/migration/lib/scaffold/scaffold-migration.d.ts.map +1 -0
  302. package/dist/migration/lib/scaffold/scaffold-migration.js +89 -0
  303. package/dist/migration/lib/scaffold/scaffold-migration.js.map +1 -0
  304. package/dist/migration/lib/spicedb-to-postgres/access-model-from-ir.d.ts +8 -0
  305. package/dist/migration/lib/spicedb-to-postgres/access-model-from-ir.d.ts.map +1 -0
  306. package/dist/migration/lib/spicedb-to-postgres/access-model-from-ir.js +10 -0
  307. package/dist/migration/lib/spicedb-to-postgres/access-model-from-ir.js.map +1 -0
  308. package/dist/migration/lib/spicedb-to-postgres/authzed-client-adapter.d.ts +94 -0
  309. package/dist/migration/lib/spicedb-to-postgres/authzed-client-adapter.d.ts.map +1 -0
  310. package/dist/migration/lib/spicedb-to-postgres/authzed-client-adapter.js +100 -0
  311. package/dist/migration/lib/spicedb-to-postgres/authzed-client-adapter.js.map +1 -0
  312. package/dist/migration/lib/spicedb-to-postgres/cli-args.d.ts +30 -0
  313. package/dist/migration/lib/spicedb-to-postgres/cli-args.d.ts.map +1 -0
  314. package/dist/migration/lib/spicedb-to-postgres/cli-args.js +208 -0
  315. package/dist/migration/lib/spicedb-to-postgres/cli-args.js.map +1 -0
  316. package/dist/migration/lib/spicedb-to-postgres/cli-format.d.ts +16 -0
  317. package/dist/migration/lib/spicedb-to-postgres/cli-format.d.ts.map +1 -0
  318. package/dist/migration/lib/spicedb-to-postgres/cli-format.js +77 -0
  319. package/dist/migration/lib/spicedb-to-postgres/cli-format.js.map +1 -0
  320. package/dist/migration/lib/spicedb-to-postgres/cli.d.ts +47 -0
  321. package/dist/migration/lib/spicedb-to-postgres/cli.d.ts.map +1 -0
  322. package/dist/migration/lib/spicedb-to-postgres/cli.js +165 -0
  323. package/dist/migration/lib/spicedb-to-postgres/cli.js.map +1 -0
  324. package/dist/migration/lib/spicedb-to-postgres/index.d.ts +8 -0
  325. package/dist/migration/lib/spicedb-to-postgres/index.d.ts.map +1 -0
  326. package/dist/migration/lib/spicedb-to-postgres/index.js +8 -0
  327. package/dist/migration/lib/spicedb-to-postgres/index.js.map +1 -0
  328. package/dist/migration/lib/spicedb-to-postgres/migrate-spicedb-to-postgres.d.ts +36 -0
  329. package/dist/migration/lib/spicedb-to-postgres/migrate-spicedb-to-postgres.d.ts.map +1 -0
  330. package/dist/migration/lib/spicedb-to-postgres/migrate-spicedb-to-postgres.js +129 -0
  331. package/dist/migration/lib/spicedb-to-postgres/migrate-spicedb-to-postgres.js.map +1 -0
  332. package/dist/migration/lib/spicedb-to-postgres/postgres-relationship-ddl.d.ts +13 -0
  333. package/dist/migration/lib/spicedb-to-postgres/postgres-relationship-ddl.d.ts.map +1 -0
  334. package/dist/migration/lib/spicedb-to-postgres/postgres-relationship-ddl.js +60 -0
  335. package/dist/migration/lib/spicedb-to-postgres/postgres-relationship-ddl.js.map +1 -0
  336. package/dist/migration/lib/spicedb-to-postgres/verify-parity.d.ts +51 -0
  337. package/dist/migration/lib/spicedb-to-postgres/verify-parity.d.ts.map +1 -0
  338. package/dist/migration/lib/spicedb-to-postgres/verify-parity.js +174 -0
  339. package/dist/migration/lib/spicedb-to-postgres/verify-parity.js.map +1 -0
  340. package/dist/migration/testing/fake-schema-store.d.ts +31 -0
  341. package/dist/migration/testing/fake-schema-store.d.ts.map +1 -0
  342. package/dist/migration/testing/fake-schema-store.js +79 -0
  343. package/dist/migration/testing/fake-schema-store.js.map +1 -0
  344. package/dist/spicedb-access.tsbuildinfo +1 -0
  345. package/dist/testing/create-shared-test-spice-db.d.ts +4 -0
  346. package/dist/testing/create-shared-test-spice-db.d.ts.map +1 -0
  347. package/dist/testing/create-shared-test-spice-db.js +9 -0
  348. package/dist/testing/create-shared-test-spice-db.js.map +1 -0
  349. package/dist/testing/fake-apply-after-commit.d.ts +29 -0
  350. package/dist/testing/fake-apply-after-commit.d.ts.map +1 -0
  351. package/dist/testing/fake-apply-after-commit.js +50 -0
  352. package/dist/testing/fake-apply-after-commit.js.map +1 -0
  353. package/dist/testing/fake-claim.d.ts +50 -0
  354. package/dist/testing/fake-claim.d.ts.map +1 -0
  355. package/dist/testing/fake-claim.js +187 -0
  356. package/dist/testing/fake-claim.js.map +1 -0
  357. package/dist/testing/fake-enqueue.d.ts +37 -0
  358. package/dist/testing/fake-enqueue.d.ts.map +1 -0
  359. package/dist/testing/fake-enqueue.js +84 -0
  360. package/dist/testing/fake-enqueue.js.map +1 -0
  361. package/dist/testing/in-memory-owner-lock.d.ts +7 -0
  362. package/dist/testing/in-memory-owner-lock.d.ts.map +1 -0
  363. package/dist/testing/in-memory-owner-lock.js +25 -0
  364. package/dist/testing/in-memory-owner-lock.js.map +1 -0
  365. package/dist/testing/index.d.ts +11 -0
  366. package/dist/testing/index.d.ts.map +1 -0
  367. package/dist/testing/index.js +11 -0
  368. package/dist/testing/index.js.map +1 -0
  369. package/dist/testing/prove-scope-matches-lookup.d.ts +22 -0
  370. package/dist/testing/prove-scope-matches-lookup.d.ts.map +1 -0
  371. package/dist/testing/prove-scope-matches-lookup.js +67 -0
  372. package/dist/testing/prove-scope-matches-lookup.js.map +1 -0
  373. package/dist/testing/start-test-spice-db.d.ts +31 -0
  374. package/dist/testing/start-test-spice-db.d.ts.map +1 -0
  375. package/dist/testing/start-test-spice-db.js +73 -0
  376. package/dist/testing/start-test-spice-db.js.map +1 -0
  377. package/dist/testing/tuned-spice-db-benchmark.d.ts +22 -0
  378. package/dist/testing/tuned-spice-db-benchmark.d.ts.map +1 -0
  379. package/dist/testing/tuned-spice-db-benchmark.js +148 -0
  380. package/dist/testing/tuned-spice-db-benchmark.js.map +1 -0
  381. package/package.json +73 -4
@@ -0,0 +1,60 @@
1
+ import { type Result } from "@dads-framework/core/errors";
2
+ import type { Authorization } from "@dads-framework/access/runtime";
3
+ import type { ClaimAccessChanges } from "./claim.js";
4
+ import type { OwnerLock } from "@dads-framework/access/runtime";
5
+ export type ApplyAccessChangesReport = {
6
+ readonly claimed: number;
7
+ readonly projected: number;
8
+ readonly failed: number;
9
+ };
10
+ export type ApplyAccessChangesInput = {
11
+ readonly batchSize?: number;
12
+ readonly workerId: string;
13
+ };
14
+ /**
15
+ * Carries claimed facts from Postgres into SpiceDB — the outbox's only reader,
16
+ * and the reason a producer never has to call the graph itself.
17
+ *
18
+ * **Idempotency is the contract here, not a hope.** Delivery is at-least-once
19
+ * by design: a crashed worker's lease expires and its rows come back, so the
20
+ * same batch can be applied twice. That is safe because both operations are
21
+ * naturally idempotent — SpiceDB's relationship write uses TOUCH semantics, so
22
+ * writing an existing tuple changes nothing, and deleting an absent tuple is a
23
+ * no-op. The projector therefore never needs to ask what it already did.
24
+ *
25
+ * Each row settles on its own. One fact that cannot be projected must not
26
+ * strand the rest of the batch, because the rest are somebody's access.
27
+ */
28
+ export declare class ApplyAccessChanges {
29
+ private readonly store;
30
+ private readonly authorization;
31
+ private readonly now;
32
+ private readonly coordinator;
33
+ private readonly leaseMs;
34
+ private readonly maxAttempts;
35
+ constructor(store: ClaimAccessChanges, authorization: Authorization, now: () => Date, coordinator: OwnerLock, leaseMs?: number, maxAttempts?: number);
36
+ execute(input: ApplyAccessChangesInput): Promise<Result<ApplyAccessChangesReport>>;
37
+ /**
38
+ * Project exactly the named facts — the immediate dispatch a create runs
39
+ * once its transaction has committed.
40
+ *
41
+ * It is the same claim/apply/settle path as `execute`, narrowed by key, so
42
+ * the producer still never touches claim or settle itself. A key already
43
+ * projected, or held by a live worker, is not claimed and therefore not
44
+ * re-applied.
45
+ */
46
+ applyKeys(input: {
47
+ readonly idempotencyKeys: readonly string[];
48
+ readonly workerId: string;
49
+ }): Promise<Result<ApplyAccessChangesReport>>;
50
+ /**
51
+ * Of the named facts, the ones another worker is projecting right now:
52
+ * still PENDING under a live lease. It claims nothing, so a caller waiting
53
+ * on its own facts never takes them from the worker that holds them.
54
+ */
55
+ keysHeldByLiveClaims(idempotencyKeys: readonly string[]): Promise<readonly string[]>;
56
+ private settle;
57
+ /** True when the fact reached the graph; false when it was recorded failed. */
58
+ private apply;
59
+ }
60
+ //# sourceMappingURL=apply.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../../../src/lib/access-changes/apply.ts"],"names":[],"mappings":"AAAA,OAAO,EAAM,KAAK,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,KAAK,EAAE,aAAa,EAAqB,MAAM,gCAAgC,CAAC;AACvF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AASrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAEhE,MAAM,MAAM,wBAAwB,GAAG;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,qBAAa,kBAAkB;IAE3B,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAN9B,YACmB,KAAK,EAAE,kBAAkB,EACzB,aAAa,EAAE,aAAa,EAC5B,GAAG,EAAE,MAAM,IAAI,EACf,WAAW,EAAE,SAAS,EACtB,OAAO,GAAE,MAAyB,EAClC,WAAW,GAAE,MAA6B,EACzD;IAEE,OAAO,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,MAAM,CAAC,wBAAwB,CAAC,CAAC,CASvF;IAED;;;;;;;;OAQG;IACG,SAAS,CAAC,KAAK,EAAE;QACrB,QAAQ,CAAC,eAAe,EAAE,SAAS,MAAM,EAAE,CAAC;QAC5C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;KAC3B,GAAG,OAAO,CAAC,MAAM,CAAC,wBAAwB,CAAC,CAAC,CAS5C;IAED;;;;OAIG;IACG,oBAAoB,CAAC,eAAe,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAKzF;YAEa,MAAM;IA0BpB,+EAA+E;YACjE,KAAK;CA2BpB"}
@@ -0,0 +1,133 @@
1
+ import { ok } from "@dads-framework/core/errors";
2
+ import {} from "./claim.js";
3
+ import { DEFAULT_LEASE_MS, DEFAULT_MAX_ATTEMPTS, leaseCutoff, outcomeAfterFailure, summarizeError, } from "./logic/claim-rules.js";
4
+ /**
5
+ * Carries claimed facts from Postgres into SpiceDB — the outbox's only reader,
6
+ * and the reason a producer never has to call the graph itself.
7
+ *
8
+ * **Idempotency is the contract here, not a hope.** Delivery is at-least-once
9
+ * by design: a crashed worker's lease expires and its rows come back, so the
10
+ * same batch can be applied twice. That is safe because both operations are
11
+ * naturally idempotent — SpiceDB's relationship write uses TOUCH semantics, so
12
+ * writing an existing tuple changes nothing, and deleting an absent tuple is a
13
+ * no-op. The projector therefore never needs to ask what it already did.
14
+ *
15
+ * Each row settles on its own. One fact that cannot be projected must not
16
+ * strand the rest of the batch, because the rest are somebody's access.
17
+ */
18
+ export class ApplyAccessChanges {
19
+ store;
20
+ authorization;
21
+ now;
22
+ coordinator;
23
+ leaseMs;
24
+ maxAttempts;
25
+ constructor(store, authorization, now, coordinator, leaseMs = DEFAULT_LEASE_MS, maxAttempts = DEFAULT_MAX_ATTEMPTS) {
26
+ this.store = store;
27
+ this.authorization = authorization;
28
+ this.now = now;
29
+ this.coordinator = coordinator;
30
+ this.leaseMs = leaseMs;
31
+ this.maxAttempts = maxAttempts;
32
+ }
33
+ async execute(input) {
34
+ const at = this.now();
35
+ const claimed = await this.store.claim({
36
+ batchSize: input.batchSize ?? 50,
37
+ workerId: input.workerId,
38
+ now: at,
39
+ leaseCutoff: leaseCutoff(at, this.leaseMs),
40
+ });
41
+ return this.settle(claimed, input.workerId);
42
+ }
43
+ /**
44
+ * Project exactly the named facts — the immediate dispatch a create runs
45
+ * once its transaction has committed.
46
+ *
47
+ * It is the same claim/apply/settle path as `execute`, narrowed by key, so
48
+ * the producer still never touches claim or settle itself. A key already
49
+ * projected, or held by a live worker, is not claimed and therefore not
50
+ * re-applied.
51
+ */
52
+ async applyKeys(input) {
53
+ const at = this.now();
54
+ const claimed = await this.store.claimByKeys({
55
+ idempotencyKeys: input.idempotencyKeys,
56
+ workerId: input.workerId,
57
+ now: at,
58
+ leaseCutoff: leaseCutoff(at, this.leaseMs),
59
+ });
60
+ return this.settle(claimed, input.workerId);
61
+ }
62
+ /**
63
+ * Of the named facts, the ones another worker is projecting right now:
64
+ * still PENDING under a live lease. It claims nothing, so a caller waiting
65
+ * on its own facts never takes them from the worker that holds them.
66
+ */
67
+ async keysHeldByLiveClaims(idempotencyKeys) {
68
+ return this.store.heldByLiveClaim({
69
+ idempotencyKeys,
70
+ leaseCutoff: leaseCutoff(this.now(), this.leaseMs),
71
+ });
72
+ }
73
+ async settle(claimed, workerId) {
74
+ let projected = 0;
75
+ let failed = 0;
76
+ for (const row of claimed) {
77
+ const settleRow = async () => {
78
+ const owned = await this.store.isClaimOwned(row.id, workerId);
79
+ if (!owned)
80
+ return "SUPERSEDED";
81
+ const applied = await this.apply(row, workerId);
82
+ if (applied === "APPLIED") {
83
+ const settled = await this.store.markProjected([row.id], this.now(), workerId);
84
+ return settled ? "PROJECTED" : "OWNERSHIP_LOST";
85
+ }
86
+ return applied;
87
+ };
88
+ const outcome = row.ownerPartitionId === null ? await settleRow() : await this.coordinator.run(row.ownerPartitionId, settleRow);
89
+ if (outcome === "PROJECTED")
90
+ projected += 1;
91
+ if (outcome === "FAILED")
92
+ failed += 1;
93
+ }
94
+ return ok({ claimed: claimed.length, projected, failed });
95
+ }
96
+ /** True when the fact reached the graph; false when it was recorded failed. */
97
+ async apply(row, workerId) {
98
+ try {
99
+ if (row.operation === "WRITE") {
100
+ await this.authorization.writeRelationships([toRelationship(row)]);
101
+ }
102
+ else {
103
+ await this.authorization.deleteRelationships({
104
+ resourceType: row.resourceType,
105
+ resourceId: row.resourceId,
106
+ relation: row.relation,
107
+ subject: {
108
+ type: row.subjectType,
109
+ id: row.subjectId,
110
+ ...(row.subjectRelation === null ? {} : { relation: row.subjectRelation }),
111
+ },
112
+ });
113
+ }
114
+ return "APPLIED";
115
+ }
116
+ catch (error) {
117
+ const settled = await this.store.markFailed(row.id, outcomeAfterFailure(row.attempts, this.maxAttempts), summarizeError(error), workerId);
118
+ return settled ? "FAILED" : "OWNERSHIP_LOST";
119
+ }
120
+ }
121
+ }
122
+ function toRelationship(row) {
123
+ return {
124
+ resource: { type: row.resourceType, id: row.resourceId },
125
+ relation: row.relation,
126
+ subject: {
127
+ type: row.subjectType,
128
+ id: row.subjectId,
129
+ ...(row.subjectRelation === null ? {} : { relation: row.subjectRelation }),
130
+ },
131
+ };
132
+ }
133
+ //# sourceMappingURL=apply.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply.js","sourceRoot":"","sources":["../../../src/lib/access-changes/apply.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAe,MAAM,6BAA6B,CAAC;AAI9D,OAAO,EAAyB,MAAM,YAAY,CAAC;AACnD,O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,cAAc,CAAC,KAAK,CAAC,EACrB,QAAQ,CACT,CAAC;YACF,OAAO,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC;QAC/C,CAAC;IACH,CAAC;CACF;AAED,SAAS,cAAc,CAAC,GAAqB;IAC3C,OAAO;QACL,QAAQ,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC,YAAY,EAAE,EAAE,EAAE,GAAG,CAAC,UAAU,EAAE;QACxD,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,OAAO,EAAE;YACP,IAAI,EAAE,GAAG,CAAC,WAAW;YACrB,EAAE,EAAE,GAAG,CAAC,SAAS;YACjB,GAAG,CAAC,GAAG,CAAC,eAAe,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,CAAC,eAAe,EAAE,CAAC;SAC3E;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,79 @@
1
+ import type { AccessChangeId } from "./access-change.ids.js";
2
+ import type { authorizationOutbox } from "./postgres/access-changes.tables.js";
3
+ /**
4
+ * The projector's side of the outbox: claim work, report what happened.
5
+ *
6
+ * Separate from `EnqueueAccessChanges` on purpose. Producers only ever append,
7
+ * inside someone else's transaction; the projector only ever claims and
8
+ * settles, in its own. Keeping them apart means a domain writer cannot reach a
9
+ * method that marks facts projected, and the projector cannot enqueue.
10
+ */
11
+ /** One claimed fact, flattened out of storage and ready to apply. */
12
+ export type ClaimedOutboxRow = Readonly<Pick<typeof authorizationOutbox.$inferSelect, "id" | "idempotencyKey" | "operation" | "resourceType" | "resourceId" | "relation" | "subjectType" | "subjectId" | "subjectRelation" | "ownerPartitionId" | "attempts">>;
13
+ export type OutboxClaim = {
14
+ readonly batchSize: number;
15
+ readonly workerId: string;
16
+ readonly now: Date;
17
+ /** Rows locked at or before this instant are stealable (a dead worker's). */
18
+ readonly leaseCutoff: Date;
19
+ };
20
+ /**
21
+ * A claim narrowed to facts the caller already knows the keys of — the
22
+ * immediate dispatch that runs right after a create commits.
23
+ *
24
+ * Scoped rather than a general drain on purpose: a request must project the
25
+ * facts IT caused and nothing else. A full-queue drain inside a request would
26
+ * make one user's create latency depend on the size of everybody's backlog,
27
+ * and would let a poison row anywhere in the queue take the request down with
28
+ * it. Same lease rules, same exclusion, narrower window.
29
+ */
30
+ export type OutboxKeyClaim = {
31
+ readonly idempotencyKeys: readonly string[];
32
+ readonly workerId: string;
33
+ readonly now: Date;
34
+ readonly leaseCutoff: Date;
35
+ };
36
+ /**
37
+ * Named facts to look up without claiming them: which are still PENDING under
38
+ * a live lease (locked after `leaseCutoff`), so another worker is projecting
39
+ * them right now.
40
+ */
41
+ export type OutboxHeldKeysQuery = {
42
+ readonly idempotencyKeys: readonly string[];
43
+ readonly leaseCutoff: Date;
44
+ };
45
+ export type OutboxCounts = {
46
+ readonly pending: number;
47
+ readonly failed: number;
48
+ };
49
+ export declare abstract class ClaimAccessChanges {
50
+ /**
51
+ * Take up to `batchSize` rows, stamping them with this worker. Must be
52
+ * atomic per row — two workers running at once may never receive the same
53
+ * fact — which is why the adapter claims with `FOR UPDATE SKIP LOCKED` and
54
+ * this seam offers no read-then-write alternative.
55
+ */
56
+ abstract claim(claim: OutboxClaim): Promise<readonly ClaimedOutboxRow[]>;
57
+ /**
58
+ * The same atomic take, restricted to named facts. A key whose row is
59
+ * already PROJECTED, or is held by a live worker, is simply not returned —
60
+ * so a dispatch that races the background projector does nothing rather
61
+ * than projecting twice.
62
+ */
63
+ abstract claimByKeys(claim: OutboxKeyClaim): Promise<readonly ClaimedOutboxRow[]>;
64
+ /**
65
+ * Of the named facts, the keys still PENDING and held under a live lease by
66
+ * any worker. A read only: it claims nothing, takes no row lock and never
67
+ * waits, so a caller can watch another worker's claim without stealing it.
68
+ */
69
+ abstract heldByLiveClaim(query: OutboxHeldKeysQuery): Promise<readonly string[]>;
70
+ abstract isClaimOwned(id: AccessChangeId, workerId: string): Promise<boolean>;
71
+ abstract markProjected(ids: readonly AccessChangeId[], at: Date, workerId: string): Promise<boolean>;
72
+ abstract markFailed(id: AccessChangeId, outcome: {
73
+ readonly status: "PENDING" | "FAILED";
74
+ readonly attempts: number;
75
+ }, lastError: string, workerId: string): Promise<boolean>;
76
+ /** What the reconcile operation reports: is the projector telling the truth? */
77
+ abstract counts(): Promise<OutboxCounts>;
78
+ }
79
+ //# sourceMappingURL=claim.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claim.d.ts","sourceRoot":"","sources":["../../../src/lib/access-changes/claim.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAE/E;;;;;;;GAOG;AAEH,qEAAqE;AACrE,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CACrC,IAAI,CACF,OAAO,mBAAmB,CAAC,YAAY,EACrC,IAAI,GACJ,gBAAgB,GAChB,WAAW,GACX,cAAc,GACd,YAAY,GACZ,UAAU,GACV,aAAa,GACb,WAAW,GACX,iBAAiB,GACjB,kBAAkB,GAClB,UAAU,CACb,CACF,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC;IACnB,6EAA6E;IAC7E,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC;CAC5B,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,eAAe,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC;IACnB,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC;CAC5B,CAA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,YAAY,CAAC,CAAC;CAC1C"}
@@ -0,0 +1,3 @@
1
+ export class ClaimAccessChanges {
2
+ }
3
+ //# sourceMappingURL=claim.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claim.js","sourceRoot":"","sources":["../../../src/lib/access-changes/claim.ts"],"names":[],"mappings":"AAsEA,MAAM,OAAgB,kBAAkB;CAkCvC"}
@@ -0,0 +1,38 @@
1
+ import { type Result } from "@dads-framework/core/errors";
2
+ import type { ApplyAccessChanges } from "./apply.js";
3
+ import type { AccessChangeCompletionStatusReader, RetryFailedAccessChanges } from "./completion-status.js";
4
+ import type { OwnerLock } from "@dads-framework/access/runtime";
5
+ export type CompleteAccessChangesInput = {
6
+ readonly ownerPartitionIds: readonly string[];
7
+ /** Starts another attempt budget only for the previously exhausted facts. */
8
+ readonly retryFailed?: boolean;
9
+ /**
10
+ * Finish only these facts inside the named partitions. A request that must
11
+ * not answer before its own facts land names them, so another caller's
12
+ * backlog in the same partition is neither applied inside the request nor
13
+ * able to fail it. Omitted, every unfinished fact in the partitions counts;
14
+ * an empty list has nothing to finish.
15
+ */
16
+ readonly idempotencyKeys?: readonly string[];
17
+ };
18
+ /**
19
+ * Returns success only after the named partitions — or, when the caller names
20
+ * facts, those facts within them — have nothing unfinished. Callers must
21
+ * release every lifecycle lease before invoking completion.
22
+ */
23
+ export declare abstract class CompleteAccessChanges {
24
+ abstract complete(input: CompleteAccessChangesInput): Promise<Result<void>>;
25
+ }
26
+ type CompletionDependencies = {
27
+ readonly statusReader: AccessChangeCompletionStatusReader;
28
+ readonly retry: RetryFailedAccessChanges;
29
+ readonly projector: Pick<ApplyAccessChanges, "applyKeys">;
30
+ readonly ownerLock: OwnerLock;
31
+ readonly createWorkerId?: () => string;
32
+ readonly now?: () => number;
33
+ readonly delay?: (milliseconds: number) => Promise<void>;
34
+ };
35
+ /** Creates strict completion without changing best-effort inline dispatch. */
36
+ export declare function createCompleteAccessChanges(dependencies: CompletionDependencies): CompleteAccessChanges;
37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AC;CAC1D,CAAC;AA+FF,8EAA8E;AAC9E,wBAAgB,2BAA2B,CAAC,YAAY,EAAE,sBAAsB,GAAG,qBAAqB,CAEvG"}
@@ -0,0 +1,129 @@
1
+ import { setTimeout as sleep } from "node:timers/promises";
2
+ import { randomUUID } from "node:crypto";
3
+ import { conflict, err, ok } from "@dads-framework/core/errors";
4
+ /**
5
+ * Returns success only after the named partitions — or, when the caller names
6
+ * facts, those facts within them — have nothing unfinished. Callers must
7
+ * release every lifecycle lease before invoking completion.
8
+ */
9
+ export class CompleteAccessChanges {
10
+ }
11
+ /**
12
+ * How long completion waits for facts another live worker has claimed. Two
13
+ * requests for one customer overlap routinely — Entra provisions in parallel —
14
+ * and the other worker settles its claim in milliseconds, so refusing at once
15
+ * turned ordinary overlap into a 409. Bounded well inside the request timeout.
16
+ */
17
+ const OTHER_WORKER_WAIT_MS = 5_000;
18
+ const OTHER_WORKER_POLL_MS = 25;
19
+ class CompleteAccessChangesLive extends CompleteAccessChanges {
20
+ dependencies;
21
+ constructor(dependencies) {
22
+ super();
23
+ this.dependencies = dependencies;
24
+ }
25
+ async complete(input) {
26
+ const ownerPartitionIds = [...new Set(input.ownerPartitionIds)].sort();
27
+ if (hasNothingToFinish(ownerPartitionIds, input.idempotencyKeys)) {
28
+ return ok(undefined);
29
+ }
30
+ const named = namedFacts(input.idempotencyKeys);
31
+ try {
32
+ const unfinished = await this.readUnfinished(ownerPartitionIds, named);
33
+ if (input.retryFailed === true) {
34
+ await this.retryFailed(ownerPartitionIds, unfinished);
35
+ }
36
+ return await this.finish(ownerPartitionIds, named, unfinished);
37
+ }
38
+ catch {
39
+ return incomplete();
40
+ }
41
+ }
42
+ /**
43
+ * Project what this worker can claim, then wait out facts another live
44
+ * worker holds. A refused projection or an exhausted fact ends it at once:
45
+ * nobody else is about to settle those.
46
+ */
47
+ async finish(ownerPartitionIds, named, firstUnfinished) {
48
+ const now = this.dependencies.now ?? Date.now;
49
+ const delay = this.dependencies.delay ?? sleep;
50
+ const deadline = now() + OTHER_WORKER_WAIT_MS;
51
+ let unfinished = firstUnfinished;
52
+ for (;;) {
53
+ const report = await this.project(unfinished);
54
+ if (report === null)
55
+ return incomplete();
56
+ const remaining = await this.readUnfinished(ownerPartitionIds, named);
57
+ if (remaining.length === 0)
58
+ return ok(undefined);
59
+ if (!heldByAnotherWorker(unfinished, report))
60
+ return incomplete();
61
+ if (remaining.some((fact) => fact.status === "FAILED")) {
62
+ return incomplete();
63
+ }
64
+ if (now() >= deadline)
65
+ return incomplete();
66
+ await delay(OTHER_WORKER_POLL_MS);
67
+ unfinished = remaining;
68
+ }
69
+ }
70
+ /** Null only when the projector refused facts it was handed. */
71
+ async project(unfinished) {
72
+ if (unfinished.length === 0)
73
+ return { claimed: 0, projected: 0, failed: 0 };
74
+ const projected = await this.dependencies.projector.applyKeys({
75
+ idempotencyKeys: unfinished.map((fact) => fact.idempotencyKey),
76
+ workerId: this.dependencies.createWorkerId?.() ?? randomUUID(),
77
+ });
78
+ return projected.ok ? projected.value : null;
79
+ }
80
+ /** The partitions' unfinished facts, narrowed to the named ones when given. */
81
+ async readUnfinished(ownerPartitionIds, named) {
82
+ const unfinished = await this.dependencies.statusReader.readUnfinished({
83
+ ownerPartitionIds,
84
+ });
85
+ if (named === null)
86
+ return unfinished;
87
+ return unfinished.filter((fact) => named.has(fact.idempotencyKey));
88
+ }
89
+ async retryFailed(ownerPartitionIds, unfinished) {
90
+ for (const ownerPartitionId of ownerPartitionIds) {
91
+ const idempotencyKeys = unfinished
92
+ .filter((fact) => fact.ownerPartitionId === ownerPartitionId && fact.status === "FAILED")
93
+ .map((fact) => fact.idempotencyKey);
94
+ if (idempotencyKeys.length === 0)
95
+ continue;
96
+ await this.dependencies.ownerLock.run(ownerPartitionId, (lease) => this.dependencies.retry.retryFailed({
97
+ ownerPartitionId,
98
+ idempotencyKeys,
99
+ lease,
100
+ }));
101
+ }
102
+ }
103
+ }
104
+ /** Creates strict completion without changing best-effort inline dispatch. */
105
+ export function createCompleteAccessChanges(dependencies) {
106
+ return new CompleteAccessChangesLive(dependencies);
107
+ }
108
+ /** No partitions, or the caller named an empty list of facts. */
109
+ function hasNothingToFinish(ownerPartitionIds, idempotencyKeys) {
110
+ return ownerPartitionIds.length === 0 || idempotencyKeys?.length === 0;
111
+ }
112
+ /** The caller's named facts, or null when every unfinished fact counts. */
113
+ function namedFacts(idempotencyKeys) {
114
+ return idempotencyKeys === undefined ? null : new Set(idempotencyKeys);
115
+ }
116
+ /**
117
+ * Some PENDING fact went unclaimed and nothing failed: another live worker
118
+ * holds it. A FAILED fact is never claimable, so it does not count.
119
+ */
120
+ function heldByAnotherWorker(unfinished, report) {
121
+ const pending = unfinished.filter((fact) => fact.status === "PENDING");
122
+ return report.failed === 0 && report.claimed < pending.length;
123
+ }
124
+ function incomplete() {
125
+ return err(conflict("AUTHORIZATION_ACCESS_CHANGES_INCOMPLETE", "Access changes are not yet enforced; retry provisioning", {
126
+ retryable: true,
127
+ }));
128
+ }
129
+ //# sourceMappingURL=complete.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"complete.js","sourceRoot":"","sources":["../../../src/lib/access-changes/complete.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE,EAAe,MAAM,6BAA6B,CAAC;AAuB7E;;;;GAIG;AACH,MAAM,OAAgB,qBAAqB;CAE1C;AAED;;;;;GAKG;AACH,MAAM,oBAAoB,GAAG,KAAK,CAAC;AACnC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAYhC,MAAM,yBAA0B,SAAQ,qBAAqB;IAC9B,YAAY;IAAzC,YAA6B,YAAoC;QAC/D,KAAK,EAAE,CAAC;4BADmB,YAAY;IAEzC,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,KAAiC;QAC9C,M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OAAO,eAAe,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,eAAe,CAAC,CAAC;AACzE,CAAC;AAED;;;GAGG;AACH,SAAS,mBAAmB,CAAC,UAA6C,EAAE,MAAgC;IAC1G,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC;IACvE,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;AAChE,CAAC;AAED,SAAS,UAAU;IACjB,OAAO,GAAG,CACR,QAAQ,CAAC,yCAAyC,EAAE,yDAAyD,EAAE;QAC7G,SAAS,EAAE,IAAI;KAChB,CAAC,CACH,CAAC;AACJ,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { OwnerLockLease } from "@dads-framework/access/runtime";
2
+ export type UnfinishedAccessChange = {
3
+ readonly idempotencyKey: string;
4
+ readonly ownerPartitionId: string;
5
+ readonly status: "PENDING" | "FAILED";
6
+ };
7
+ /** Reads unfinished facts only within the caller's explicit owner partitions. */
8
+ export declare abstract class AccessChangeCompletionStatusReader {
9
+ abstract readUnfinished(input: {
10
+ readonly ownerPartitionIds: readonly string[];
11
+ }): Promise<readonly UnfinishedAccessChange[]>;
12
+ }
13
+ /** Explicitly reopens named exhausted facts under their owner's live lease. */
14
+ export declare abstract class RetryFailedAccessChanges {
15
+ abstract retryFailed(input: {
16
+ readonly ownerPartitionId: string;
17
+ readonly idempotencyKeys: readonly string[];
18
+ readonly lease: OwnerLockLease;
19
+ }): Promise<void>;
20
+ }
21
+ //# sourceMappingURL=completion-status.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"completion-status.d.ts","sourceRoot":"","sources":["../../../src/lib/access-changes/completion-status.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAErE,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;CACvC,CAAC;AAEF,iFAAiF;AACjF,8BAAsB,kCAAkC;IACtD,QAAQ,CAAC,cAAc,CAAC,KAAK,EAAE;QAC7B,QAAQ,CAAC,iBAAiB,EAAE,SAAS,MAAM,EAAE,CAAC;KAC/C,GAAG,OAAO,CAAC,SAAS,sBAAsB,EAAE,CAAC,CAAC;CAChD;AAED,+EAA+E;AAC/E,8BAAsB,wBAAwB;IAC5C,QAAQ,CAAC,WAAW,CAAC,KAAK,EAAE;QAC1B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;QAClC,QAAQ,CAAC,eAAe,EAAE,SAAS,MAAM,EAAE,CAAC;QAC5C,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;KAChC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnB"}
@@ -0,0 +1,7 @@
1
+ /** Reads unfinished facts only within the caller's explicit owner partitions. */
2
+ export class AccessChangeCompletionStatusReader {
3
+ }
4
+ /** Explicitly reopens named exhausted facts under their owner's live lease. */
5
+ export class RetryFailedAccessChanges {
6
+ }
7
+ //# sourceMappingURL=completion-status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"completion-status.js","sourceRoot":"","sources":["../../../src/lib/access-changes/completion-status.ts"],"names":[],"mappings":"AAQA,iFAAiF;AACjF,MAAM,OAAgB,kCAAkC;CAIvD;AAED,+EAA+E;AAC/E,MAAM,OAAgB,wBAAwB;CAM7C"}
@@ -0,0 +1,14 @@
1
+ import { EnqueueAccessChanges as AccessChangesEnqueuer } from "@dads-framework/access/runtime";
2
+ import type { DrizzleHandle } from "@dads-framework/postgres";
3
+ export { accessChangesToWrite, OUTBOX_OPERATION_VALUES, outboxKeyForRelationship, type AccessChange, type OutboxOperation, } from "@dads-framework/access/runtime";
4
+ export declare const OUTBOX_STATUS_VALUES: readonly ["PENDING", "PROJECTED", "FAILED", "SUPERSEDED"];
5
+ export type OutboxStatus = (typeof OUTBOX_STATUS_VALUES)[number];
6
+ /**
7
+ * The caller's open transaction handle. The outbox uses insert and update.
8
+ * Same-database authorization additionally requires execute on a real
9
+ * transaction. Other writers and test doubles can still use the narrow port.
10
+ */
11
+ export type OutboxTx = Pick<DrizzleHandle, "insert" | "update"> & Partial<Pick<DrizzleHandle, "execute">>;
12
+ export type EnqueueAccessChanges = AccessChangesEnqueuer<OutboxTx>;
13
+ export declare const EnqueueAccessChanges: abstract new () => AccessChangesEnqueuer<OutboxTx>;
14
+ //# sourceMappingURL=enqueue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enqueue.d.ts","sourceRoot":"","sources":["../../../src/lib/access-changes/enqueue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,IAAI,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAC/F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,EACL,oBAAoB,EACpB,uBAAuB,EACvB,wBAAwB,EACxB,KAAK,YAAY,EACjB,KAAK,eAAe,GACrB,MAAM,gCAAgC,CAAC;AAExC,eAAO,MAAM,oBAAoB,YAAI,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,CAAU,CAAC;AAE9F,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjE;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,EAAE,QAAQ,GAAG,QAAQ,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC,CAAC;AAE1G,MAAM,MAAM,oBAAoB,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAC;AACnE,eAAO,MAAM,oBAAoB,oDAAkC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { EnqueueAccessChanges as AccessChangesEnqueuer } from "@dads-framework/access/runtime";
2
+ export { accessChangesToWrite, OUTBOX_OPERATION_VALUES, outboxKeyForRelationship, } from "@dads-framework/access/runtime";
3
+ export const OUTBOX_STATUS_VALUES = ["PENDING", "PROJECTED", "FAILED", "SUPERSEDED"];
4
+ export const EnqueueAccessChanges = AccessChangesEnqueuer;
5
+ //# sourceMappingURL=enqueue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enqueue.js","sourceRoot":"","sources":["../../../src/lib/access-changes/enqueue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,IAAI,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAG/F,OAAO,EACL,oBAAoB,EACpB,uBAAuB,EACvB,wBAAwB,GAGzB,MAAM,gCAAgC,CAAC;AAExC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,CAAU,CAAC;AAY9F,MAAM,CAAC,MAAM,oBAAoB,GAAG,qBAA+B,CAAC"}
@@ -0,0 +1,49 @@
1
+ import type { OutboxStatus } from "../enqueue.js";
2
+ /**
3
+ * The projector's decisions, with no database and no clock of their own.
4
+ *
5
+ * Claiming itself must happen in SQL — only the database can hand one row to
6
+ * exactly one worker — so what lives here is the two judgements that surround
7
+ * it: which rows a claim is ALLOWED to take, expressed as the cutoff its WHERE
8
+ * compares against, and what becomes of a row whose projection just failed.
9
+ * Both are the kind of arithmetic that is wrong in production and untestable
10
+ * there.
11
+ */
12
+ /** How long a worker may hold a claimed row before another may steal it. */
13
+ export declare const DEFAULT_LEASE_MS = 60000;
14
+ /**
15
+ * Give up after this many failures and leave the row for a human. The count is
16
+ * deliberately small: a fact that has failed five times is not going to
17
+ * succeed on the sixth, and a row retried forever is a queue that never drains
18
+ * and an alert nobody sees.
19
+ */
20
+ export declare const DEFAULT_MAX_ATTEMPTS = 5;
21
+ /**
22
+ * A row locked at or before this instant has an expired lease and may be
23
+ * re-claimed. This is what stops a crashed worker parking a fact forever: the
24
+ * worker is gone, its lock is stale, and the next run takes the row back.
25
+ */
26
+ export declare function leaseCutoff(now: Date, leaseMs?: number): Date;
27
+ /**
28
+ * A failure settles a row as retryable or spent — never as PROJECTED, which is
29
+ * why the type is narrower than `OutboxStatus`.
30
+ */
31
+ export type FailureOutcome = {
32
+ readonly status: Extract<OutboxStatus, "PENDING" | "FAILED">;
33
+ readonly attempts: number;
34
+ };
35
+ /**
36
+ * What a failed projection does to its row. Below the limit it goes back to
37
+ * PENDING with its lock released, so the next run picks it up; at the limit it
38
+ * becomes FAILED and stays visible, because a fact that cannot be projected is
39
+ * a human's problem and a silent drop would be a permission that quietly never
40
+ * arrived.
41
+ */
42
+ export declare function outcomeAfterFailure(attemptsBefore: number, maxAttempts?: number): FailureOutcome;
43
+ /**
44
+ * Trim an adapter's error to something a `last_error` column and a human can
45
+ * both hold. Never widened into structured diagnostics: this column exists to
46
+ * say what went wrong at a glance, and the projector's logs hold the rest.
47
+ */
48
+ export declare function summarizeError(error: unknown, maxLength?: number): string;
49
+ //# sourceMappingURL=claim-rules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claim-rules.d.ts","sourceRoot":"","sources":["../../../../src/lib/access-changes/logic/claim-rules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD;;;;;;;;;GASG;AAEH,4EAA4E;AAC5E,eAAO,MAAM,gBAAgB,QAAS,CAAC;AAEvC;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,IAAI,CAAC;AAEtC;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,GAAE,MAAyB,GAAG,IAAI,CAE/E;AAED;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,EAAE,SAAS,GAAG,QAAQ,CAAC,CAAC;IAC7D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,cAAc,EAAE,MAAM,EACtB,WAAW,GAAE,MAA6B,GACzC,cAAc,CAGhB;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,SAAM,GAAG,MAAM,CAGtE"}