@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,104 @@
1
+ import type { Authorization, RelationshipFilter, RelationshipWrite } from "@dads-framework/access/runtime";
2
+ import type { EnqueueAccessChanges } from "./enqueue.js";
3
+ /**
4
+ * Write-through revocation: remove access NOW, and record the removal so it
5
+ * cannot be lost.
6
+ *
7
+ * ## Grants and revocations are deliberately asymmetric — do not simplify this
8
+ *
9
+ * It is tempting to notice that this file and the create path both produce
10
+ * outbox rows, and to "unify" them into one enqueue-and-let-the-projector-do-it
11
+ * shape. That would be a security regression, and the asymmetry is the whole
12
+ * reason this helper exists (commitment 2).
13
+ *
14
+ * A **grant** may wait for the projector. Until the tuple lands nobody can
15
+ * reach the resource, so a late grant is a closed door — a slow UI.
16
+ *
17
+ * A **revocation** may not wait. Until the tuple is gone somebody still has
18
+ * access they are no longer entitled to, so a queue between the decision and
19
+ * the removal is a window of lingering access — a security incident. The
20
+ * synchronous `deleteRelationships` is therefore not an optimization that a
21
+ * later refactor may drop; it is the property.
22
+ *
23
+ * ## The synchronous delete is best-effort, and the operation still succeeds
24
+ *
25
+ * The outbox row is committed FIRST, either by `revokeAccess` for a rowless
26
+ * revocation or by the lifecycle writer's own transaction. Only then does the
27
+ * synchronous removal run. If the graph is unreachable and removal throws,
28
+ * the synchronous helper swallows the error and returns normally, because by
29
+ * then the durable record exists and the projector will retry until the tuple
30
+ * is gone. Failing the caller would report failure for a guaranteed removal.
31
+ *
32
+ * The order matters in the other direction too: if the enqueue itself fails
33
+ * this function throws and nothing has been removed, so the caller's operation
34
+ * fails with the world unchanged rather than half-revoked.
35
+ *
36
+ * ## Why neither public helper accepts a transaction handle
37
+ *
38
+ * A lifecycle writer enqueues inside its own transaction so the row, event and
39
+ * DELETE fact commit together, then passes only the committed relationship and
40
+ * cause to `deleteRelationshipsNow`. A rowless revocation
41
+ * has no transaction to join, so `revokeAccess` owns the append before using
42
+ * the same synchronous helper. Mutations receive neither a database handle nor
43
+ * an outbox seam for lifecycle-backed revocation.
44
+ */
45
+ export type RevokeThroughInput = {
46
+ readonly authorization: Authorization;
47
+ readonly outbox: EnqueueAccessChanges;
48
+ /**
49
+ * The tuples being removed, each fully specified. An outbox row names one
50
+ * resource, relation and subject, so "every tuple on this resource" cannot
51
+ * be expressed as a row — name the ones you know here and use `sweep` for
52
+ * the rest.
53
+ */
54
+ readonly relationships: readonly RelationshipWrite[];
55
+ /**
56
+ * The id of the state change that caused this revocation — the deleted row,
57
+ * the ended session, the membership that moved. Makes the idempotency key
58
+ * stable across retries of the same logical change (see
59
+ * `outboxKeyForRelationship`).
60
+ */
61
+ readonly cause: string;
62
+ /** The authority partition these facts belong to. */
63
+ readonly ownerPartitionId?: string | null;
64
+ /**
65
+ * What the synchronous removal actually deletes. Defaults to exactly the
66
+ * relationships above. Deleting an entire resource may instead need a broad filter
67
+ * that removes every tuple on it, including
68
+ * grants this code never enumerated — those cannot become outbox rows, so
69
+ * the synchronous sweep is the only thing that removes them.
70
+ */
71
+ readonly sweep?: readonly RelationshipFilter[];
72
+ /**
73
+ * Told when the synchronous removal fails. Optional so a unit test need not
74
+ * supply one, but production callers should: this is the ONE path where
75
+ * access outlives the decision to remove it, and swallowing it silently
76
+ * would make the security-relevant case the invisible one. The revocation is
77
+ * still guaranteed by the committed row — the log is how anyone finds out
78
+ * the graph is behind.
79
+ */
80
+ readonly log?: RevocationLog;
81
+ };
82
+ /**
83
+ * The narrow logging surface a revocation needs, declared here rather than
84
+ * imported so this battery does not acquire an observability dependency for
85
+ * one call.
86
+ */
87
+ export type RevocationLog = {
88
+ warn(obj: object, msg?: string): void;
89
+ };
90
+ export type CommittedSynchronousRevocationInput = {
91
+ readonly authorization: Authorization;
92
+ readonly relationships: readonly RelationshipWrite[];
93
+ readonly committedFactCause: string;
94
+ readonly sweep?: readonly RelationshipFilter[];
95
+ readonly log?: RevocationLog;
96
+ };
97
+ /**
98
+ * Best-effort graph removal for a caller that MUST already have co-committed
99
+ * exact DELETE facts using `committedFactCause`. This function never records
100
+ * durability.
101
+ */
102
+ export declare function deleteRelationshipsNow(input: CommittedSynchronousRevocationInput): Promise<void>;
103
+ export declare function revokeAccess(input: RevokeThroughInput): Promise<void>;
104
+ //# sourceMappingURL=revoke.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"revoke.d.ts","sourceRoot":"","sources":["../../../src/lib/access-changes/revoke.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAC3G,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAGzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAC;IACtC;;;;;OAKG;IACH,QAAQ,CAAC,aAAa,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACrD;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,qDAAqD;IACrD,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C;;;;;;OAMG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,kBAAkB,EAAE,CAAC;IAC/C;;;;;;;OAOG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,aAAa,CAAC;CAC9B,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG;IAAE,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAEtE,MAAM,MAAM,mCAAmC,GAAG;IAChD,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,QAAQ,CAAC,aAAa,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACrD,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,kBAAkB,EAAE,CAAC;IAC/C,QAAQ,CAAC,GAAG,CAAC,EAAE,aAAa,CAAC;CAC9B,CAAC;AAEF;;;;GAIG;AACH,wBAAsB,sBAAsB,CAAC,KAAK,EAAE,mCAAmC,GAAG,OAAO,CAAC,IAAI,CAAC,CAkBtG;AAED,wBAAsB,YAAY,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAiB3E"}
@@ -0,0 +1,48 @@
1
+ import { outboxKeyForRelationship } from "./enqueue.js";
2
+ /**
3
+ * Best-effort graph removal for a caller that MUST already have co-committed
4
+ * exact DELETE facts using `committedFactCause`. This function never records
5
+ * durability.
6
+ */
7
+ export async function deleteRelationshipsNow(input) {
8
+ const filters = input.sweep ?? input.relationships.map(toFilter);
9
+ for (const filter of filters) {
10
+ try {
11
+ await input.authorization.deleteRelationships(filter);
12
+ }
13
+ catch (error) {
14
+ input.log?.warn({
15
+ error: String(error),
16
+ resourceType: filter.resourceType,
17
+ resourceId: filter.resourceId,
18
+ relation: filter.relation,
19
+ cause: input.committedFactCause,
20
+ }, "synchronous revocation failed; access persists until the outbox row is projected");
21
+ }
22
+ }
23
+ }
24
+ export async function revokeAccess(input) {
25
+ const entries = input.relationships.map((relationship) => ({
26
+ idempotencyKey: outboxKeyForRelationship("DELETE", relationship, input.cause),
27
+ operation: "DELETE",
28
+ relationship,
29
+ ownerPartitionId: input.ownerPartitionId ?? null,
30
+ }));
31
+ await input.outbox.append(entries);
32
+ await deleteRelationshipsNow({
33
+ authorization: input.authorization,
34
+ relationships: input.relationships,
35
+ committedFactCause: input.cause,
36
+ ...(input.sweep === undefined ? {} : { sweep: input.sweep }),
37
+ ...(input.log === undefined ? {} : { log: input.log }),
38
+ });
39
+ }
40
+ function toFilter(relationship) {
41
+ return {
42
+ resourceType: relationship.resource.type,
43
+ resourceId: relationship.resource.id,
44
+ relation: relationship.relation,
45
+ subject: relationship.subject,
46
+ };
47
+ }
48
+ //# sourceMappingURL=revoke.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"revoke.js","sourceRoot":"","sources":["../../../src/lib/access-changes/revoke.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAqB,MAAM,cAAc,CAAC;AAiG3E;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,KAA0C;IACrF,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACjE,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,CAAC;YACH,MAAM,KAAK,CAAC,aAAa,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;QACxD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,KAAK,CAAC,GAAG,EAAE,IAAI,CACb;gBACE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC;gBACpB,YAAY,EAAE,MAAM,CAAC,YAAY;gBACjC,UAAU,EAAE,MAAM,CAAC,UAAU;gBAC7B,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,KAAK,EAAE,KAAK,CAAC,kBAAkB;aAChC,EACD,kFAAkF,CACnF,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,KAAyB;IAC1D,MAAM,OAAO,GAAmB,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QACzE,cAAc,EAAE,wBAAwB,CAAC,QAAQ,EAAE,YAAY,EAAE,KAAK,CAAC,KAAK,CAAC;QAC7E,SAAS,EAAE,QAAQ;QACnB,YAAY;QACZ,gBAAgB,EAAE,KAAK,CAAC,gBAAgB,IAAI,IAAI;KACjD,CAAC,CAAC,CAAC;IAEJ,MAAM,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAEnC,MAAM,sBAAsB,CAAC;QAC3B,aAAa,EAAE,KAAK,CAAC,aAAa;QAClC,aAAa,EAAE,KAAK,CAAC,aAAa;QAClC,kBAAkB,EAAE,KAAK,CAAC,KAAK;QAC/B,GAAG,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;QAC5D,GAAG,CAAC,KAAK,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC;KACvD,CAAC,CAAC;AACL,CAAC;AAED,SAAS,QAAQ,CAAC,YAA+B;IAC/C,OAAO;QACL,YAAY,EAAE,YAAY,CAAC,QAAQ,CAAC,IAAI;QACxC,UAAU,EAAE,YAAY,CAAC,QAAQ,CAAC,EAAE;QACpC,QAAQ,EAAE,YAAY,CAAC,QAAQ;QAC/B,OAAO,EAAE,YAAY,CAAC,OAAO;KAC9B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,56 @@
1
+ import type { SyncedRowWriter } from "@dads-framework/postgres";
2
+ import type { RelationshipWrite } from "@dads-framework/access/runtime";
3
+ import { type AccessChange } from "./enqueue.js";
4
+ import type { OwnerLock, OwnerLockLease } from "@dads-framework/access/runtime";
5
+ /** The relationships a stored row carries, and the authority slice they belong to. */
6
+ export type SyncedRowRelationships = {
7
+ readonly relationships: readonly RelationshipWrite[];
8
+ readonly ownerPartitionId: string | null;
9
+ };
10
+ /**
11
+ * Reads one stored row of the copy and answers its relationships, built by
12
+ * the owning domain's own fact builders: empty when the row is absent or
13
+ * carries none. A row whose removal takes other rows' access with it (a
14
+ * deleted workspace and its records) answers one group per authority
15
+ * slice.
16
+ */
17
+ export type ReadSyncedRowRelationships<Table extends string, Tx> = (tx: Tx, table: Table, id: string) => Promise<SyncedRowRelationships | readonly SyncedRowRelationships[]>;
18
+ /** The outbox a copy records into: plain facts, and facts that replace a waiting opposite. */
19
+ export type SyncedRowOutbox<Tx> = {
20
+ enqueue(entries: readonly AccessChange[], tx: Tx): Promise<void>;
21
+ enqueueReplacingOpposite(entries: readonly AccessChange[], tx: Tx, lease: OwnerLockLease): Promise<void>;
22
+ };
23
+ /**
24
+ * Wraps a copy's row writer so each row it writes or deletes records the
25
+ * row's relationships in the authorization outbox, in the same transaction:
26
+ * the relationships the row carried before and no longer does are deleted,
27
+ * and every one it carries now is written (SpiceDB TOUCHes it, so a tuple
28
+ * already there stays). A row the writer left alone (the same row applied
29
+ * twice) records nothing.
30
+ *
31
+ * Each fact replaces the waiting opposite fact for its exact tuple, under
32
+ * that tuple's authority-slice lock, as the cloud's own writers do: a grant
33
+ * that has not reached the graph yet can never land after the removal that
34
+ * followed it. Each change mints its own cause, because a row moves
35
+ * add → remove → add and a derived key would let a later removal collide
36
+ * with an earlier one and never reach the graph.
37
+ */
38
+ export declare function syncedRowWriterWithRelationships<Table extends string, Tx>(writer: SyncedRowWriter<Table, Tx>, outbox: SyncedRowOutbox<Tx>, partitions: Pick<OwnerLock, "run">, relationshipsOf: ReadSyncedRowRelationships<Table, Tx>, mintCause?: () => string): SyncedRowWriter<Table, Tx>;
39
+ /**
40
+ * States the relationships the given stored rows of a copy carry now, for
41
+ * rows the copy held before it recorded relationships with each write (a
42
+ * site upgraded past that build): each one is written, replacing any
43
+ * waiting opposite fact for its tuple, as the wrapper's writes do. A row no
44
+ * longer stored states nothing. Running it again writes the same tuples
45
+ * again, which the graph keeps as they are. Answers how many facts it
46
+ * recorded.
47
+ */
48
+ export declare function stateSyncedRowRelationships<Table extends string, Tx>(input: {
49
+ readonly tx: Tx;
50
+ readonly table: Table;
51
+ readonly ids: readonly string[];
52
+ readonly outbox: SyncedRowOutbox<Tx>;
53
+ readonly partitions: Pick<OwnerLock, "run">;
54
+ readonly relationshipsOf: ReadSyncedRowRelationships<Table, Tx>;
55
+ }, mintCause?: () => string): Promise<number>;
56
+ //# sourceMappingURL=synced-row-relationships.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"synced-row-relationships.d.ts","sourceRoot":"","sources":["../../../src/lib/access-changes/synced-row-relationships.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAGhE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,KAAK,YAAY,EAA4B,MAAM,cAAc,CAAC;AAC3E,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAEhF,sFAAsF;AACtF,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,CAAC,aAAa,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACrD,QAAQ,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1C,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,0BAA0B,CAAC,KAAK,SAAS,MAAM,EAAE,EAAE,IAAI,CACjE,EAAE,EAAE,EAAE,EACN,KAAK,EAAE,KAAK,EACZ,EAAE,EAAE,MAAM,KACP,OAAO,CAAC,sBAAsB,GAAG,SAAS,sBAAsB,EAAE,CAAC,CAAC;AAEzE,8FAA8F;AAC9F,MAAM,MAAM,eAAe,CAAC,EAAE,IAAI;IAChC,OAAO,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjE,wBAAwB,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1G,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gCAAgC,CAAC,KAAK,SAAS,MAAM,EAAE,EAAE,EACvE,MAAM,EAAE,eAAe,CAAC,KAAK,EAAE,EAAE,CAAC,EAClC,MAAM,EAAE,eAAe,CAAC,EAAE,CAAC,EAC3B,UAAU,EAAE,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,EAClC,eAAe,EAAE,0BAA0B,CAAC,KAAK,EAAE,EAAE,CAAC,EACtD,SAAS,GAAE,MAAM,MAAmB,GACnC,eAAe,CAAC,KAAK,EAAE,EAAE,CAAC,CAwB5B;AAED;;;;;;;;GAQG;AACH,wBAAsB,2BAA2B,CAAC,KAAK,SAAS,MAAM,EAAE,EAAE,EACxE,KAAK,EAAE;IACL,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC;IAChB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC,EAAE,CAAC,CAAC;IACrC,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC5C,QAAQ,CAAC,eAAe,EAAE,0BAA0B,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;CACjE,EACD,SAAS,GAAE,MAAM,MAAmB,GACnC,OAAO,CAAC,MAAM,CAAC,CASjB"}
@@ -0,0 +1,111 @@
1
+ import { mintUuidV7 } from "@dads-framework/core/contract";
2
+ import { outboxKeyForRelationship } from "./enqueue.js";
3
+ /**
4
+ * Wraps a copy's row writer so each row it writes or deletes records the
5
+ * row's relationships in the authorization outbox, in the same transaction:
6
+ * the relationships the row carried before and no longer does are deleted,
7
+ * and every one it carries now is written (SpiceDB TOUCHes it, so a tuple
8
+ * already there stays). A row the writer left alone (the same row applied
9
+ * twice) records nothing.
10
+ *
11
+ * Each fact replaces the waiting opposite fact for its exact tuple, under
12
+ * that tuple's authority-slice lock, as the cloud's own writers do: a grant
13
+ * that has not reached the graph yet can never land after the removal that
14
+ * followed it. Each change mints its own cause, because a row moves
15
+ * add → remove → add and a derived key would let a later removal collide
16
+ * with an earlier one and never reach the graph.
17
+ */
18
+ export function syncedRowWriterWithRelationships(writer, outbox, partitions, relationshipsOf, mintCause = mintUuidV7) {
19
+ const moveKeyHoldersAside = writer.moveKeyHoldersAside?.bind(writer);
20
+ const record = (tx, facts) => recordFacts(outbox, partitions, tx, facts);
21
+ return {
22
+ async upsert(tx, change) {
23
+ const before = await read(relationshipsOf, tx, change.table, change.id);
24
+ const written = await writer.upsert(tx, change);
25
+ if (written !== true)
26
+ return written;
27
+ const after = await read(relationshipsOf, tx, change.table, change.id);
28
+ await record(tx, changedFacts(before, after, mintCause()));
29
+ return true;
30
+ },
31
+ async delete(tx, table, id) {
32
+ const before = await read(relationshipsOf, tx, table, id);
33
+ const deleted = await writer.delete(tx, table, id);
34
+ if (deleted)
35
+ await record(tx, factsFor("DELETE", before, mintCause()));
36
+ return deleted;
37
+ },
38
+ ...(moveKeyHoldersAside === undefined ? {} : { moveKeyHoldersAside }),
39
+ };
40
+ }
41
+ /**
42
+ * States the relationships the given stored rows of a copy carry now, for
43
+ * rows the copy held before it recorded relationships with each write (a
44
+ * site upgraded past that build): each one is written, replacing any
45
+ * waiting opposite fact for its tuple, as the wrapper's writes do. A row no
46
+ * longer stored states nothing. Running it again writes the same tuples
47
+ * again, which the graph keeps as they are. Answers how many facts it
48
+ * recorded.
49
+ */
50
+ export async function stateSyncedRowRelationships(input, mintCause = mintUuidV7) {
51
+ let recorded = 0;
52
+ for (const id of input.ids) {
53
+ const held = await read(input.relationshipsOf, input.tx, input.table, id);
54
+ const facts = factsFor("WRITE", held, mintCause());
55
+ await recordFacts(input.outbox, input.partitions, input.tx, facts);
56
+ recorded += facts.length;
57
+ }
58
+ return recorded;
59
+ }
60
+ /** Records facts slice by slice, each replacing the waiting opposite fact under its slice's lock. */
61
+ async function recordFacts(outbox, partitions, tx, facts) {
62
+ for (const [partition, group] of byPartition(facts)) {
63
+ if (partition === null)
64
+ await outbox.enqueue(group, tx);
65
+ else
66
+ await partitions.run(partition, (lease) => outbox.enqueueReplacingOpposite(group, tx, lease));
67
+ }
68
+ }
69
+ async function read(relationshipsOf, tx, table, id) {
70
+ const answer = await relationshipsOf(tx, table, id);
71
+ const groups = isGroupList(answer) ? answer : [answer];
72
+ const placed = new Map();
73
+ for (const group of groups) {
74
+ for (const relationship of group.relationships) {
75
+ const entry = { relationship, ownerPartitionId: group.ownerPartitionId };
76
+ placed.set(placedKey(entry), entry);
77
+ }
78
+ }
79
+ return [...placed.values()];
80
+ }
81
+ function isGroupList(answer) {
82
+ return Array.isArray(answer);
83
+ }
84
+ function changedFacts(before, after, cause) {
85
+ const kept = new Set(after.map(placedKey));
86
+ const gone = before.filter((entry) => !kept.has(placedKey(entry)));
87
+ return [...factsFor("DELETE", gone, cause), ...factsFor("WRITE", after, cause)];
88
+ }
89
+ function factsFor(operation, entries, cause) {
90
+ return entries.map(({ relationship, ownerPartitionId }) => ({
91
+ idempotencyKey: outboxKeyForRelationship(operation, relationship, cause),
92
+ operation,
93
+ relationship,
94
+ ownerPartitionId,
95
+ }));
96
+ }
97
+ /** Facts grouped by authority slice, in the order each slice first appears. */
98
+ function byPartition(facts) {
99
+ const groups = new Map();
100
+ for (const fact of facts) {
101
+ const group = groups.get(fact.ownerPartitionId) ?? [];
102
+ group.push(fact);
103
+ groups.set(fact.ownerPartitionId, group);
104
+ }
105
+ return groups;
106
+ }
107
+ /** One tuple in one authority slice: the key of a write with no cause. */
108
+ function placedKey(entry) {
109
+ return `${entry.ownerPartitionId ?? ""}|${outboxKeyForRelationship("WRITE", entry.relationship, "")}`;
110
+ }
111
+ //# sourceMappingURL=synced-row-relationships.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"synced-row-relationships.js","sourceRoot":"","sources":["../../../src/lib/access-changes/synced-row-relationships.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAA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AC,CAAC,CAAC;IACnE,OAAO,CAAC,GAAG,QAAQ,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,GAAG,QAAQ,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;AAClF,CAAC;AAED,SAAS,QAAQ,CAAC,SAA6B,EAAE,OAA0B,EAAE,KAAa;IACxF,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,EAAE,gBAAgB,EAAE,EAAE,EAAE,CAAC,CAAC;QAC1D,cAAc,EAAE,wBAAwB,CAAC,SAAS,EAAE,YAAY,EAAE,KAAK,CAAC;QACxE,SAAS;QACT,YAAY;QACZ,gBAAgB;KACjB,CAAC,CAAC,CAAC;AACN,CAAC;AAED,+EAA+E;AAC/E,SAAS,WAAW,CAAC,KAA8B;IACjD,MAAM,MAAM,GAAG,IAAI,GAAG,EAAiC,CAAC;IACxD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC;QACtD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjB,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,0EAA0E;AAC1E,SAAS,SAAS,CAAC,KAAa;IAC9B,OAAO,GAAG,KAAK,CAAC,gBAAgB,IAAI,EAAE,IAAI,wBAAwB,CAAC,OAAO,EAAE,KAAK,CAAC,YAAY,EAAE,EAAE,CAAC,EAAE,CAAC;AACxG,CAAC"}
@@ -0,0 +1,41 @@
1
+ import { type JobDefinition, type JobLog } from "@dads-framework/job-queue/core";
2
+ import type { CatalogSizeReader } from "./catalog-size-reader.js";
3
+ import { type CatalogTableDeclaration } from "./catalog-tables.js";
4
+ export declare const AUDIT_CATALOG_SIZES_JOB = "authorization.audit-catalog-sizes";
5
+ /** One catalog table estimated past the mark. */
6
+ export type OversizedCatalog = {
7
+ readonly wireName: string;
8
+ readonly tableName: string;
9
+ readonly estimatedRows: number;
10
+ readonly warnRows: number;
11
+ };
12
+ /** A catalog estimated past the mark, as the fault this job reports. */
13
+ export declare class CatalogOverSizeMarkError extends Error {
14
+ constructor(catalog: OversizedCatalog);
15
+ }
16
+ export type CreateAuditCatalogSizesJobDeps = {
17
+ readonly catalogTables: readonly CatalogTableDeclaration[];
18
+ readonly reader: CatalogSizeReader;
19
+ /** A catalog table estimated past this many rows is reported. */
20
+ readonly warnRows: number;
21
+ /** Where an oversized catalog is reported; the composition root binds diagnostics. */
22
+ readonly reportFault: (error: CatalogOverSizeMarkError) => void;
23
+ readonly log: JobLog;
24
+ };
25
+ /**
26
+ * Once a day, checks every `catalog` declaration against the data.
27
+ *
28
+ * A catalog list may ask SpiceDB for every visible id because a catalog is
29
+ * supposed to stay small. Nobody has to trust that: this reads Postgres's row
30
+ * estimate for each catalog's table and reports, by name, every one past the
31
+ * mark. A catalog that is really a record shows up here months before its
32
+ * list would trip the lookup guards on a single caller.
33
+ *
34
+ * Reads only `pg_class` (no scan, no lock beyond the catalog's own), and
35
+ * reports rather than throws: an oversized catalog is a finding, not a failed
36
+ * job to retry.
37
+ */
38
+ export declare function createAuditCatalogSizesJob(deps: CreateAuditCatalogSizesJobDeps): JobDefinition;
39
+ /** Every declared catalog table whose estimate is past the mark. */
40
+ export declare function auditCatalogSizes(deps: Pick<CreateAuditCatalogSizesJobDeps, "catalogTables" | "reader" | "warnRows" | "log">): Promise<readonly OversizedCatalog[]>;
41
+ //# sourceMappingURL=audit-catalog-sizes.job.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-catalog-sizes.job.d.ts","sourceRoot":"","sources":["../../../src/lib/catalog-sizes/audit-catalog-sizes.job.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2B,KAAK,aAAa,EAAE,K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ue/core";
3
+ import { hasCatalogTable } from "./catalog-tables.js";
4
+ export const AUDIT_CATALOG_SIZES_JOB = "authorization.audit-catalog-sizes";
5
+ /** A catalog estimated past the mark, as the fault this job reports. */
6
+ export class CatalogOverSizeMarkError extends Error {
7
+ constructor(catalog) {
8
+ super(`${catalog.wireName} is declared a catalog but ${catalog.tableName} holds about ${catalog.estimatedRows} rows, ` +
9
+ `past the ${catalog.warnRows} mark (AUTHZ_CATALOG_SIZE_WARN); if it grows with business activity it is a record, ` +
10
+ `and its lists must move onto requiresScoped`);
11
+ this.name = "CatalogOverSizeMarkError";
12
+ }
13
+ }
14
+ /**
15
+ * Once a day, checks every `catalog` declaration against the data.
16
+ *
17
+ * A catalog list may ask SpiceDB for every visible id because a catalog is
18
+ * supposed to stay small. Nobody has to trust that: this reads Postgres's row
19
+ * estimate for each catalog's table and reports, by name, every one past the
20
+ * mark. A catalog that is really a record shows up here months before its
21
+ * list would trip the lookup guards on a single caller.
22
+ *
23
+ * Reads only `pg_class` (no scan, no lock beyond the catalog's own), and
24
+ * reports rather than throws: an oversized catalog is a finding, not a failed
25
+ * job to retry.
26
+ */
27
+ export function createAuditCatalogSizesJob(deps) {
28
+ if (!Number.isInteger(deps.warnRows) || deps.warnRows <= 0) {
29
+ throw new Error(`catalog size warnRows must be a positive integer, got ${deps.warnRows}`);
30
+ }
31
+ return defineJob({
32
+ name: AUDIT_CATALOG_SIZES_JOB,
33
+ payload: z.strictObject({}),
34
+ retry: { attempts: 3, backoffMs: 5_000 },
35
+ schedules: [
36
+ cronSchedule({
37
+ id: "authorization.audit-catalog-sizes.daily",
38
+ pattern: "0 30 4 * * *",
39
+ timeZone: "UTC",
40
+ payload: {},
41
+ }),
42
+ ],
43
+ run: async () => {
44
+ const oversized = await auditCatalogSizes(deps);
45
+ for (const catalog of oversized) {
46
+ deps.reportFault(new CatalogOverSizeMarkError(catalog));
47
+ deps.log.error({ event: "authorization.catalog-over-size-mark", ...catalog }, "a catalog table is past its size mark");
48
+ }
49
+ },
50
+ });
51
+ }
52
+ /** Every declared catalog table whose estimate is past the mark. */
53
+ export async function auditCatalogSizes(deps) {
54
+ const tables = deps.catalogTables.filter(hasCatalogTable);
55
+ const estimates = await deps.reader.estimatedRows(tables.map((table) => table.tableName));
56
+ const unsized = tables.filter((table) => !estimates.has(table.tableName)).map((table) => table.tableName);
57
+ deps.log.info({
58
+ event: "authorization.catalog-sizes-audited",
59
+ audited: tables.length - unsized.length,
60
+ unsized,
61
+ warnRows: deps.warnRows,
62
+ }, "catalog table sizes audited");
63
+ return tables.flatMap((table) => {
64
+ const estimatedRows = estimates.get(table.tableName);
65
+ return estimatedRows !== undefined && estimatedRows > deps.warnRows
66
+ ? [
67
+ {
68
+ wireName: table.wireName,
69
+ tableName: table.tableName,
70
+ estimatedRows,
71
+ warnRows: deps.warnRows,
72
+ },
73
+ ]
74
+ : [];
75
+ });
76
+ }
77
+ //# sourceMappingURL=audit-catalog-sizes.job.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-catalog-sizes.job.js","sourceRoot":"","sources":["../../../src/lib/catalog-sizes/audit-catalog-sizes.job.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,SAAS,EAAmC,MAAM,gCAAgC,CAAC;AAG1G,OAAO,EAAmD,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEvG,MAAM,CAAC,MAAM,uBAAuB,GAAG,mCAAmC,CAAC;AAU3E,wEAAwE;AACxE,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACjD,YAAY,OAAyB;QACnC,KAAK,CACH,GAAG,OAAO,CAAC,QAAQ,8BAA8B,OAAO,CAAC,SAAS,gBAAgB,OAAO,CAAC,aAAa,SAAS;YAC9G,YAAY,OAAO,CAAC,QAAQ,sFAAsF;YAClH,6CAA6C,CAChD,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACzC,CAAC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,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;IAC1F,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAC1G,IAAI,CAAC,GAAG,CAAC,IAAI,CACX;QACE,KAAK,EAAE,qCAAqC;QAC5C,OAAO,EAAE,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM;QACvC,OAAO;QACP,QAAQ,EAAE,IAAI,CAAC,QAAQ;KACxB,EACD,6BAA6B,CAC9B,CAAC;IACF,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QAC9B,MAAM,aAAa,GAAG,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACrD,OAAO,aAAa,KAAK,SAAS,IAAI,aAAa,GAAG,IAAI,CAAC,QAAQ;YACjE,CAAC,CAAC;gBACE;oBACE,QAAQ,EAAE,KAAK,CAAC,QAAQ;oBACxB,SAAS,EAAE,KAAK,CAAC,SAAS;oBAC1B,aAAa;oBACb,QAAQ,EAAE,IAAI,CAAC,QAAQ;iBACxB;aACF;YACH,CAAC,CAAC,EAAE,CAAC;IACT,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { DrizzleHandle } from "@dads-framework/postgres";
2
+ export declare abstract class CatalogSizeReader {
3
+ /**
4
+ * Estimated rows by table name, in the current schema. A table Postgres has
5
+ * never analyzed (estimate `-1`) or does not have is left out: unknown is
6
+ * not small, and the audit says which tables it could not size.
7
+ */
8
+ abstract estimatedRows(tableNames: readonly string[]): Promise<ReadonlyMap<string, number>>;
9
+ }
10
+ export declare class PostgresCatalogSizeReader extends CatalogSizeReader {
11
+ private readonly db;
12
+ constructor(db: DrizzleHandle);
13
+ estimatedRows(tableNames: readonly string[]): Promise<ReadonlyMap<string, number>>;
14
+ }
15
+ //# sourceMappingURL=catalog-size-reader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog-size-reader.d.ts","sourceRoot":"","sources":["../../../src/lib/catalog-sizes/catalog-size-reader.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE9D,8BAAsB,iBAAiB;IACrC;;;;OAIG;IACH,QAAQ,CAAC,aAAa,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC7F;AAOD,qBAAa,yBAA0B,SAAQ,iBAAiB;IAClD,OAAO,CAAC,QAAQ,CAAC,EAAE;IAA/B,YAA6B,EAAE,EAAE,aAAa,EAE7C;IAEc,aAAa,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAiBhG;CACF"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * How many rows Postgres estimates each table holds. `pg_class.reltuples` is
3
+ * the planner's estimate, kept current by autovacuum's ANALYZE: reading it is
4
+ * one catalog lookup, never a scan, so the audit costs the same however large
5
+ * the tables have grown.
6
+ */
7
+ import { sql } from "drizzle-orm";
8
+ import { z } from "zod";
9
+ export class CatalogSizeReader {
10
+ }
11
+ const estimateRow = z.object({
12
+ table_name: z.string(),
13
+ estimated_rows: z.coerce.number(),
14
+ });
15
+ export class PostgresCatalogSizeReader extends CatalogSizeReader {
16
+ db;
17
+ constructor(db) {
18
+ super();
19
+ this.db = db;
20
+ }
21
+ async estimatedRows(tableNames) {
22
+ if (tableNames.length === 0)
23
+ return new Map();
24
+ const result = await this.db.execute(sql `
25
+ SELECT c.relname AS table_name, c.reltuples::bigint AS estimated_rows
26
+ FROM pg_class c
27
+ JOIN pg_namespace n ON n.oid = c.relnamespace
28
+ WHERE n.nspname = current_schema()
29
+ AND c.relkind IN ('r', 'p')
30
+ AND c.relname = ANY(${sql.param([...tableNames])}::text[])
31
+ `);
32
+ const estimates = new Map();
33
+ for (const row of z.array(estimateRow).parse(result.rows)) {
34
+ if (row.estimated_rows >= 0) {
35
+ estimates.set(row.table_name, row.estimated_rows);
36
+ }
37
+ }
38
+ return estimates;
39
+ }
40
+ }
41
+ //# sourceMappingURL=catalog-size-reader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog-size-reader.js","sourceRoot":"","sources":["../../../src/lib/catalog-sizes/catalog-size-reader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,MAAM,OAAgB,iBAAiB;CAOtC;AAED,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3B,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,cAAc,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE;CAClC,CAAC,CAAC;AAEH,MAAM,OAAO,yBAA0B,SAAQ,iBAAiB;IACjC,EAAE;IAA/B,YAA6B,EAAiB;QAC5C,KAAK,EAAE,CAAC;kBADmB,EAAE;IAE/B,CAAC;IAEQ,KAAK,CAAC,aAAa,CAAC,UAA6B;QACxD,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,GAAG,EAAE,CAAC;QAC9C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAA;;;;;;+BAMb,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC;KACpD,CAAC,CAAC;QACH,MAAM,SAAS,GAAG,IAAI,GAAG,EAAkB,CAAC;QAC5C,KAAK,MAAM,GAAG,IAAI,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1D,IAAI,GAAG,CAAC,cAAc,IAAI,CAAC,EAAE,CAAC;gBAC5B,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Which table holds each `catalog` entity's rows, so the nightly audit can
3
+ * check that a catalog is still as small as its declaration claims.
4
+ *
5
+ * A `catalog` list may still ask SpiceDB for every visible id, because a
6
+ * catalog is bounded by equipment or configuration rather than by daily
7
+ * business. That is a claim about data, and the audit tests it against the
8
+ * data: every catalog names its table here, or says why it has none (a
9
+ * virtual entity keyed by a workspace id, a global singleton).
10
+ */
11
+ import { type Table } from "drizzle-orm";
12
+ /** Any authorization entity or resource carrying a wire name. */
13
+ export type CatalogEntityRef = {
14
+ readonly wireName: string;
15
+ };
16
+ /** A catalog entity and the table its rows live in. */
17
+ export type CatalogTable = {
18
+ readonly wireName: string;
19
+ readonly tableName: string;
20
+ };
21
+ /** A catalog entity with no table of its own, and why. */
22
+ export type CatalogWithoutTable = {
23
+ readonly wireName: string;
24
+ readonly reason: string;
25
+ };
26
+ export type CatalogTableDeclaration = CatalogTable | CatalogWithoutTable;
27
+ export declare function catalogTable(entity: CatalogEntityRef, table: Table): CatalogTable;
28
+ export declare function catalogWithoutTable(entity: CatalogEntityRef, reason: string): CatalogWithoutTable;
29
+ export declare function hasCatalogTable(declaration: CatalogTableDeclaration): declaration is CatalogTable;
30
+ /**
31
+ * Every declared catalog that names no declaration, and every declaration for
32
+ * an entity that is not a declared catalog, as `{ path, message }` failures.
33
+ */
34
+ export declare function catalogTableFailures(catalogWireNames: readonly string[], declarations: readonly CatalogTableDeclaration[]): readonly {
35
+ readonly path: string;
36
+ readonly message: string;
37
+ }[];
38
+ //# sourceMappingURL=catalog-tables.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog-tables.d.ts","sourceRoot":"","sources":["../../../src/lib/catalog-sizes/catalog-tables.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAgB,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAEvD,iEAAiE;AACjE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,uDAAuD;AACvD,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,0DAA0D;AAC1D,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,YAAY,GAAG,mBAAmB,CAAC;AAEzE,wBAAgB,YAAY,CAAC,MAAM,EAAE,gBAAgB,EAAE,KAAK,EAAE,KAAK,GAAG,YAAY,CAKjF;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,GAAG,mBAAmB,CAQjG;AAED,wBAAgB,eAAe,CAAC,WAAW,EAAE,uBAAuB,GAAG,WAAW,IAAI,YAAY,CAEjG;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,gBAAgB,EAAE,SAAS,MAAM,EAAE,EACnC,YAAY,EAAE,SAAS,uBAAuB,EAAE,GAC/C,SAAS;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EAAE,CAkBhE"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Which table holds each `catalog` entity's rows, so the nightly audit can
3
+ * check that a catalog is still as small as its declaration claims.
4
+ *
5
+ * A `catalog` list may still ask SpiceDB for every visible id, because a
6
+ * catalog is bounded by equipment or configuration rather than by daily
7
+ * business. That is a claim about data, and the audit tests it against the
8
+ * data: every catalog names its table here, or says why it has none (a
9
+ * virtual entity keyed by a workspace id, a global singleton).
10
+ */
11
+ import { getTableName } from "drizzle-orm";
12
+ export function catalogTable(entity, table) {
13
+ if (entity.wireName.trim().length === 0) {
14
+ throw new Error("catalog table declaration requires a non-empty wireName");
15
+ }
16
+ return { wireName: entity.wireName, tableName: getTableName(table) };
17
+ }
18
+ export function catalogWithoutTable(entity, reason) {
19
+ if (entity.wireName.trim().length === 0) {
20
+ throw new Error("catalog table declaration requires a non-empty wireName");
21
+ }
22
+ if (reason.trim().length === 0) {
23
+ throw new Error(`${entity.wireName} has no table but gives no reason`);
24
+ }
25
+ return { wireName: entity.wireName, reason };
26
+ }
27
+ export function hasCatalogTable(declaration) {
28
+ return "tableName" in declaration;
29
+ }
30
+ /**
31
+ * Every declared catalog that names no declaration, and every declaration for
32
+ * an entity that is not a declared catalog, as `{ path, message }` failures.
33
+ */
34
+ export function catalogTableFailures(catalogWireNames, declarations) {
35
+ const declared = new Set(declarations.map((entry) => entry.wireName));
36
+ const catalogs = new Set(catalogWireNames);
37
+ return [
38
+ ...catalogWireNames
39
+ .filter((wireName) => !declared.has(wireName))
40
+ .map((wireName) => ({
41
+ path: wireName,
42
+ message: "is a catalog with no table declared for the nightly size audit; add catalogTable(<entity>, <table>) or catalogWithoutTable(<entity>, <reason>)",
43
+ })),
44
+ ...declarations
45
+ .filter((entry) => !catalogs.has(entry.wireName))
46
+ .map((entry) => ({
47
+ path: entry.wireName,
48
+ message: "has a catalog table declaration but is not a registered catalog",
49
+ })),
50
+ ];
51
+ }
52
+ //# sourceMappingURL=catalog-tables.js.map