@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.
- package/LICENSE.md +21 -0
- package/README.md +80 -2
- package/bin/dads-import-spicedb.mjs +139 -0
- package/dist/authz-journal/index.d.ts +3 -0
- package/dist/authz-journal/index.d.ts.map +1 -0
- package/dist/authz-journal/index.js +3 -0
- package/dist/authz-journal/index.js.map +1 -0
- package/dist/authz-journal/migration-journal.access.d.ts +11 -0
- package/dist/authz-journal/migration-journal.access.d.ts.map +1 -0
- package/dist/authz-journal/migration-journal.access.js +16 -0
- package/dist/authz-journal/migration-journal.access.js.map +1 -0
- package/dist/authz-journal/migration-version.access.d.ts +7 -0
- package/dist/authz-journal/migration-version.access.d.ts.map +1 -0
- package/dist/authz-journal/migration-version.access.js +11 -0
- package/dist/authz-journal/migration-version.access.js.map +1 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/access/check-all.d.ts +8 -0
- package/dist/lib/access/check-all.d.ts.map +1 -0
- package/dist/lib/access/check-all.js +11 -0
- package/dist/lib/access/check-all.js.map +1 -0
- package/dist/lib/access/guarded-authorization.d.ts +71 -0
- package/dist/lib/access/guarded-authorization.d.ts.map +1 -0
- package/dist/lib/access/guarded-authorization.js +162 -0
- package/dist/lib/access/guarded-authorization.js.map +1 -0
- package/dist/lib/access/list-only-visible.d.ts +23 -0
- package/dist/lib/access/list-only-visible.d.ts.map +1 -0
- package/dist/lib/access/list-only-visible.js +21 -0
- package/dist/lib/access/list-only-visible.js.map +1 -0
- package/dist/lib/access/logic/spice-db-empty-schema.d.ts +3 -0
- package/dist/lib/access/logic/spice-db-empty-schema.d.ts.map +1 -0
- package/dist/lib/access/logic/spice-db-empty-schema.js +17 -0
- package/dist/lib/access/logic/spice-db-empty-schema.js.map +1 -0
- package/dist/lib/access/logic/spice-db-security.d.ts +4 -0
- package/dist/lib/access/logic/spice-db-security.d.ts.map +1 -0
- package/dist/lib/access/logic/spice-db-security.js +8 -0
- package/dist/lib/access/logic/spice-db-security.js.map +1 -0
- package/dist/lib/access/logic/spice-db-write-retry.d.ts +22 -0
- package/dist/lib/access/logic/spice-db-write-retry.d.ts.map +1 -0
- package/dist/lib/access/logic/spice-db-write-retry.js +35 -0
- package/dist/lib/access/logic/spice-db-write-retry.js.map +1 -0
- package/dist/lib/access/missing-ownership-tuples.d.ts +19 -0
- package/dist/lib/access/missing-ownership-tuples.d.ts.map +1 -0
- package/dist/lib/access/missing-ownership-tuples.js +12 -0
- package/dist/lib/access/missing-ownership-tuples.js.map +1 -0
- package/dist/lib/access/newest-written-token.d.ts +37 -0
- package/dist/lib/access/newest-written-token.d.ts.map +1 -0
- package/dist/lib/access/newest-written-token.js +56 -0
- package/dist/lib/access/newest-written-token.js.map +1 -0
- package/dist/lib/access/one-write-at-a-time.d.ts +14 -0
- package/dist/lib/access/one-write-at-a-time.d.ts.map +1 -0
- package/dist/lib/access/one-write-at-a-time.js +18 -0
- package/dist/lib/access/one-write-at-a-time.js.map +1 -0
- package/dist/lib/access/spice-db-authorization.d.ts +102 -0
- package/dist/lib/access/spice-db-authorization.d.ts.map +1 -0
- package/dist/lib/access/spice-db-authorization.js +275 -0
- package/dist/lib/access/spice-db-authorization.js.map +1 -0
- package/dist/lib/access/spice-db-clients.d.ts +19 -0
- package/dist/lib/access/spice-db-clients.d.ts.map +1 -0
- package/dist/lib/access/spice-db-clients.js +27 -0
- package/dist/lib/access/spice-db-clients.js.map +1 -0
- package/dist/lib/access/spice-db-consistency.d.ts +24 -0
- package/dist/lib/access/spice-db-consistency.d.ts.map +1 -0
- package/dist/lib/access/spice-db-consistency.js +44 -0
- package/dist/lib/access/spice-db-consistency.js.map +1 -0
- package/dist/lib/access/spice-db-permission-checks.d.ts +21 -0
- package/dist/lib/access/spice-db-permission-checks.d.ts.map +1 -0
- package/dist/lib/access/spice-db-permission-checks.js +102 -0
- package/dist/lib/access/spice-db-permission-checks.js.map +1 -0
- package/dist/lib/access/spice-db-relationship-read.d.ts +5 -0
- package/dist/lib/access/spice-db-relationship-read.d.ts.map +1 -0
- package/dist/lib/access/spice-db-relationship-read.js +21 -0
- package/dist/lib/access/spice-db-relationship-read.js.map +1 -0
- package/dist/lib/access/spice-db-write-deadline.d.ts +23 -0
- package/dist/lib/access/spice-db-write-deadline.d.ts.map +1 -0
- package/dist/lib/access/spice-db-write-deadline.js +41 -0
- package/dist/lib/access/spice-db-write-deadline.js.map +1 -0
- package/dist/lib/access/tallied-authorization.d.ts +31 -0
- package/dist/lib/access/tallied-authorization.d.ts.map +1 -0
- package/dist/lib/access/tallied-authorization.js +62 -0
- package/dist/lib/access/tallied-authorization.js.map +1 -0
- package/dist/lib/access/testing/acting-company-fixture.d.ts +46 -0
- package/dist/lib/access/testing/acting-company-fixture.d.ts.map +1 -0
- package/dist/lib/access/testing/acting-company-fixture.js +74 -0
- package/dist/lib/access/testing/acting-company-fixture.js.map +1 -0
- package/dist/lib/access-changes/access-change.ids.d.ts +5 -0
- package/dist/lib/access-changes/access-change.ids.d.ts.map +1 -0
- package/dist/lib/access-changes/access-change.ids.js +4 -0
- package/dist/lib/access-changes/access-change.ids.js.map +1 -0
- package/dist/lib/access-changes/apply-after-commit.d.ts +25 -0
- package/dist/lib/access-changes/apply-after-commit.d.ts.map +1 -0
- package/dist/lib/access-changes/apply-after-commit.js +91 -0
- package/dist/lib/access-changes/apply-after-commit.js.map +1 -0
- package/dist/lib/access-changes/apply.d.ts +60 -0
- package/dist/lib/access-changes/apply.d.ts.map +1 -0
- package/dist/lib/access-changes/apply.js +133 -0
- package/dist/lib/access-changes/apply.js.map +1 -0
- package/dist/lib/access-changes/claim.d.ts +79 -0
- package/dist/lib/access-changes/claim.d.ts.map +1 -0
- package/dist/lib/access-changes/claim.js +3 -0
- package/dist/lib/access-changes/claim.js.map +1 -0
- package/dist/lib/access-changes/complete.d.ts +38 -0
- package/dist/lib/access-changes/complete.d.ts.map +1 -0
- package/dist/lib/access-changes/complete.js +129 -0
- package/dist/lib/access-changes/complete.js.map +1 -0
- package/dist/lib/access-changes/completion-status.d.ts +21 -0
- package/dist/lib/access-changes/completion-status.d.ts.map +1 -0
- package/dist/lib/access-changes/completion-status.js +7 -0
- package/dist/lib/access-changes/completion-status.js.map +1 -0
- package/dist/lib/access-changes/enqueue.d.ts +14 -0
- package/dist/lib/access-changes/enqueue.d.ts.map +1 -0
- package/dist/lib/access-changes/enqueue.js +5 -0
- package/dist/lib/access-changes/enqueue.js.map +1 -0
- package/dist/lib/access-changes/logic/claim-rules.d.ts +49 -0
- package/dist/lib/access-changes/logic/claim-rules.d.ts.map +1 -0
- package/dist/lib/access-changes/logic/claim-rules.js +48 -0
- package/dist/lib/access-changes/logic/claim-rules.js.map +1 -0
- package/dist/lib/access-changes/postgres/access-changes.tables.d.ts +342 -0
- package/dist/lib/access-changes/postgres/access-changes.tables.d.ts.map +1 -0
- package/dist/lib/access-changes/postgres/access-changes.tables.js +36 -0
- package/dist/lib/access-changes/postgres/access-changes.tables.js.map +1 -0
- package/dist/lib/access-changes/postgres/claim.d.ts +43 -0
- package/dist/lib/access-changes/postgres/claim.d.ts.map +1 -0
- package/dist/lib/access-changes/postgres/claim.js +132 -0
- package/dist/lib/access-changes/postgres/claim.js.map +1 -0
- package/dist/lib/access-changes/postgres/completion-status.d.ts +27 -0
- package/dist/lib/access-changes/postgres/completion-status.d.ts.map +1 -0
- package/dist/lib/access-changes/postgres/completion-status.js +64 -0
- package/dist/lib/access-changes/postgres/completion-status.js.map +1 -0
- package/dist/lib/access-changes/postgres/enqueue.d.ts +30 -0
- package/dist/lib/access-changes/postgres/enqueue.d.ts.map +1 -0
- package/dist/lib/access-changes/postgres/enqueue.js +92 -0
- package/dist/lib/access-changes/postgres/enqueue.js.map +1 -0
- package/dist/lib/access-changes/postgres/migrations/20260828163001_authorization_outbox.migration.d.ts +4 -0
- package/dist/lib/access-changes/postgres/migrations/20260828163001_authorization_outbox.migration.d.ts.map +1 -0
- package/dist/lib/access-changes/postgres/migrations/20260828163001_authorization_outbox.migration.js +43 -0
- package/dist/lib/access-changes/postgres/migrations/20260828163001_authorization_outbox.migration.js.map +1 -0
- package/dist/lib/access-changes/postgres/owner-lock.d.ts +85 -0
- package/dist/lib/access-changes/postgres/owner-lock.d.ts.map +1 -0
- package/dist/lib/access-changes/postgres/owner-lock.js +219 -0
- package/dist/lib/access-changes/postgres/owner-lock.js.map +1 -0
- package/dist/lib/access-changes/postgres/requeue-failed.d.ts +17 -0
- package/dist/lib/access-changes/postgres/requeue-failed.d.ts.map +1 -0
- package/dist/lib/access-changes/postgres/requeue-failed.js +25 -0
- package/dist/lib/access-changes/postgres/requeue-failed.js.map +1 -0
- package/dist/lib/access-changes/revoke.d.ts +104 -0
- package/dist/lib/access-changes/revoke.d.ts.map +1 -0
- package/dist/lib/access-changes/revoke.js +48 -0
- package/dist/lib/access-changes/revoke.js.map +1 -0
- package/dist/lib/access-changes/synced-row-relationships.d.ts +56 -0
- package/dist/lib/access-changes/synced-row-relationships.d.ts.map +1 -0
- package/dist/lib/access-changes/synced-row-relationships.js +111 -0
- package/dist/lib/access-changes/synced-row-relationships.js.map +1 -0
- package/dist/lib/catalog-sizes/audit-catalog-sizes.job.d.ts +41 -0
- package/dist/lib/catalog-sizes/audit-catalog-sizes.job.d.ts.map +1 -0
- package/dist/lib/catalog-sizes/audit-catalog-sizes.job.js +77 -0
- package/dist/lib/catalog-sizes/audit-catalog-sizes.job.js.map +1 -0
- package/dist/lib/catalog-sizes/catalog-size-reader.d.ts +15 -0
- package/dist/lib/catalog-sizes/catalog-size-reader.d.ts.map +1 -0
- package/dist/lib/catalog-sizes/catalog-size-reader.js +41 -0
- package/dist/lib/catalog-sizes/catalog-size-reader.js.map +1 -0
- package/dist/lib/catalog-sizes/catalog-tables.d.ts +38 -0
- package/dist/lib/catalog-sizes/catalog-tables.d.ts.map +1 -0
- package/dist/lib/catalog-sizes/catalog-tables.js +52 -0
- package/dist/lib/catalog-sizes/catalog-tables.js.map +1 -0
- package/dist/lib/schema-migrate/clone-spice-db-datastore.d.ts +9 -0
- package/dist/lib/schema-migrate/clone-spice-db-datastore.d.ts.map +1 -0
- package/dist/lib/schema-migrate/clone-spice-db-datastore.js +47 -0
- package/dist/lib/schema-migrate/clone-spice-db-datastore.js.map +1 -0
- package/dist/lib/schema-migrate/parse-authorization-schema-migration-environment.d.ts +31 -0
- package/dist/lib/schema-migrate/parse-authorization-schema-migration-environment.d.ts.map +1 -0
- package/dist/lib/schema-migrate/parse-authorization-schema-migration-environment.js +26 -0
- package/dist/lib/schema-migrate/parse-authorization-schema-migration-environment.js.map +1 -0
- package/dist/lib/scoped-lists/keep-permitted.d.ts +24 -0
- package/dist/lib/scoped-lists/keep-permitted.d.ts.map +1 -0
- package/dist/lib/scoped-lists/keep-permitted.js +29 -0
- package/dist/lib/scoped-lists/keep-permitted.js.map +1 -0
- package/dist/lib/scoped-lists/scope-predicate.d.ts +18 -0
- package/dist/lib/scoped-lists/scope-predicate.d.ts.map +1 -0
- package/dist/lib/scoped-lists/scope-predicate.js +96 -0
- package/dist/lib/scoped-lists/scope-predicate.js.map +1 -0
- package/dist/lib/scoped-lists/scope-sql-bindings.d.ts +64 -0
- package/dist/lib/scoped-lists/scope-sql-bindings.d.ts.map +1 -0
- package/dist/lib/scoped-lists/scope-sql-bindings.js +45 -0
- package/dist/lib/scoped-lists/scope-sql-bindings.js.map +1 -0
- package/dist/lib/scoped-lists/testing/scoped-list-fixture.d.ts +369 -0
- package/dist/lib/scoped-lists/testing/scoped-list-fixture.d.ts.map +1 -0
- package/dist/lib/scoped-lists/testing/scoped-list-fixture.js +145 -0
- package/dist/lib/scoped-lists/testing/scoped-list-fixture.js.map +1 -0
- package/dist/migration/definition-changes.d.mts +28 -0
- package/dist/migration/definition-changes.d.mts.map +1 -0
- package/dist/migration/definition-changes.mjs +282 -0
- package/dist/migration/definition-changes.mjs.map +1 -0
- package/dist/migration/index.d.ts +15 -0
- package/dist/migration/index.d.ts.map +1 -0
- package/dist/migration/index.js +14 -0
- package/dist/migration/index.js.map +1 -0
- package/dist/migration/lib/access-migrations/assert-access-migrations-up-to-date.d.ts +26 -0
- package/dist/migration/lib/access-migrations/assert-access-migrations-up-to-date.d.ts.map +1 -0
- package/dist/migration/lib/access-migrations/assert-access-migrations-up-to-date.js +57 -0
- package/dist/migration/lib/access-migrations/assert-access-migrations-up-to-date.js.map +1 -0
- package/dist/migration/lib/access-migrations/define-access-migration.d.ts +51 -0
- package/dist/migration/lib/access-migrations/define-access-migration.d.ts.map +1 -0
- package/dist/migration/lib/access-migrations/define-access-migration.js +63 -0
- package/dist/migration/lib/access-migrations/define-access-migration.js.map +1 -0
- package/dist/migration/lib/access-migrations/diff-access-models-format.d.ts +12 -0
- package/dist/migration/lib/access-migrations/diff-access-models-format.d.ts.map +1 -0
- package/dist/migration/lib/access-migrations/diff-access-models-format.js +81 -0
- package/dist/migration/lib/access-migrations/diff-access-models-format.js.map +1 -0
- package/dist/migration/lib/access-migrations/diff-access-models.d.ts +79 -0
- package/dist/migration/lib/access-migrations/diff-access-models.d.ts.map +1 -0
- package/dist/migration/lib/access-migrations/diff-access-models.js +197 -0
- package/dist/migration/lib/access-migrations/diff-access-models.js.map +1 -0
- package/dist/migration/lib/access-migrations/index.d.ts +8 -0
- package/dist/migration/lib/access-migrations/index.d.ts.map +1 -0
- package/dist/migration/lib/access-migrations/index.js +8 -0
- package/dist/migration/lib/access-migrations/index.js.map +1 -0
- package/dist/migration/lib/access-migrations/run-postgres-access-migrations.d.ts +17 -0
- package/dist/migration/lib/access-migrations/run-postgres-access-migrations.d.ts.map +1 -0
- package/dist/migration/lib/access-migrations/run-postgres-access-migrations.js +105 -0
- package/dist/migration/lib/access-migrations/run-postgres-access-migrations.js.map +1 -0
- package/dist/migration/lib/access-migrations/run-spicedb-access-migrations.d.ts +21 -0
- package/dist/migration/lib/access-migrations/run-spicedb-access-migrations.d.ts.map +1 -0
- package/dist/migration/lib/access-migrations/run-spicedb-access-migrations.js +64 -0
- package/dist/migration/lib/access-migrations/run-spicedb-access-migrations.js.map +1 -0
- package/dist/migration/lib/access-migrations/run-sqlite-access-migrations.d.ts +18 -0
- package/dist/migration/lib/access-migrations/run-sqlite-access-migrations.d.ts.map +1 -0
- package/dist/migration/lib/access-migrations/run-sqlite-access-migrations.js +102 -0
- package/dist/migration/lib/access-migrations/run-sqlite-access-migrations.js.map +1 -0
- package/dist/migration/lib/access-migrations/sql-migration-types.d.ts +52 -0
- package/dist/migration/lib/access-migrations/sql-migration-types.d.ts.map +1 -0
- package/dist/migration/lib/access-migrations/sql-migration-types.js +57 -0
- package/dist/migration/lib/access-migrations/sql-migration-types.js.map +1 -0
- package/dist/migration/lib/journal/authorization-change-files.d.ts +7 -0
- package/dist/migration/lib/journal/authorization-change-files.d.ts.map +1 -0
- package/dist/migration/lib/journal/authorization-change-files.js +94 -0
- package/dist/migration/lib/journal/authorization-change-files.js.map +1 -0
- package/dist/migration/lib/journal/journal-entry.d.ts +47 -0
- package/dist/migration/lib/journal/journal-entry.d.ts.map +1 -0
- package/dist/migration/lib/journal/journal-entry.js +2 -0
- package/dist/migration/lib/journal/journal-entry.js.map +1 -0
- package/dist/migration/lib/journal/load-authorization-changes.d.ts +9 -0
- package/dist/migration/lib/journal/load-authorization-changes.d.ts.map +1 -0
- package/dist/migration/lib/journal/load-authorization-changes.js +32 -0
- package/dist/migration/lib/journal/load-authorization-changes.js.map +1 -0
- package/dist/migration/lib/journal/load-journal.d.ts +21 -0
- package/dist/migration/lib/journal/load-journal.d.ts.map +1 -0
- package/dist/migration/lib/journal/load-journal.js +73 -0
- package/dist/migration/lib/journal/load-journal.js.map +1 -0
- package/dist/migration/lib/journal/read-authorization-migration-status.d.ts +10 -0
- package/dist/migration/lib/journal/read-authorization-migration-status.d.ts.map +1 -0
- package/dist/migration/lib/journal/read-authorization-migration-status.js +64 -0
- package/dist/migration/lib/journal/read-authorization-migration-status.js.map +1 -0
- package/dist/migration/lib/logic/authorization-change-history.d.ts +22 -0
- package/dist/migration/lib/logic/authorization-change-history.d.ts.map +1 -0
- package/dist/migration/lib/logic/authorization-change-history.js +103 -0
- package/dist/migration/lib/logic/authorization-change-history.js.map +1 -0
- package/dist/migration/lib/logic/classify-schema-diff.d.ts +26 -0
- package/dist/migration/lib/logic/classify-schema-diff.d.ts.map +1 -0
- package/dist/migration/lib/logic/classify-schema-diff.js +104 -0
- package/dist/migration/lib/logic/classify-schema-diff.js.map +1 -0
- package/dist/migration/lib/postgres-to-spicedb/authzed-target-adapter.d.ts +62 -0
- package/dist/migration/lib/postgres-to-spicedb/authzed-target-adapter.d.ts.map +1 -0
- package/dist/migration/lib/postgres-to-spicedb/authzed-target-adapter.js +63 -0
- package/dist/migration/lib/postgres-to-spicedb/authzed-target-adapter.js.map +1 -0
- package/dist/migration/lib/postgres-to-spicedb/column-relation-outbox-triggers.d.ts +45 -0
- package/dist/migration/lib/postgres-to-spicedb/column-relation-outbox-triggers.d.ts.map +1 -0
- package/dist/migration/lib/postgres-to-spicedb/column-relation-outbox-triggers.js +140 -0
- package/dist/migration/lib/postgres-to-spicedb/column-relation-outbox-triggers.js.map +1 -0
- package/dist/migration/lib/postgres-to-spicedb/index.d.ts +4 -0
- package/dist/migration/lib/postgres-to-spicedb/index.d.ts.map +1 -0
- package/dist/migration/lib/postgres-to-spicedb/index.js +4 -0
- package/dist/migration/lib/postgres-to-spicedb/index.js.map +1 -0
- package/dist/migration/lib/postgres-to-spicedb/migrate-postgres-to-spicedb.d.ts +47 -0
- package/dist/migration/lib/postgres-to-spicedb/migrate-postgres-to-spicedb.d.ts.map +1 -0
- package/dist/migration/lib/postgres-to-spicedb/migrate-postgres-to-spicedb.js +199 -0
- package/dist/migration/lib/postgres-to-spicedb/migrate-postgres-to-spicedb.js.map +1 -0
- package/dist/migration/lib/run-authorization-changes.d.ts +5 -0
- package/dist/migration/lib/run-authorization-changes.d.ts.map +1 -0
- package/dist/migration/lib/run-authorization-changes.js +159 -0
- package/dist/migration/lib/run-authorization-changes.js.map +1 -0
- package/dist/migration/lib/run-authorization-migrations.d.ts +47 -0
- package/dist/migration/lib/run-authorization-migrations.d.ts.map +1 -0
- package/dist/migration/lib/run-authorization-migrations.js +202 -0
- package/dist/migration/lib/run-authorization-migrations.js.map +1 -0
- package/dist/migration/lib/scaffold/build-migration-bridge-schema.d.ts +7 -0
- package/dist/migration/lib/scaffold/build-migration-bridge-schema.d.ts.map +1 -0
- package/dist/migration/lib/scaffold/build-migration-bridge-schema.js +83 -0
- package/dist/migration/lib/scaffold/build-migration-bridge-schema.js.map +1 -0
- package/dist/migration/lib/scaffold/renumber-migration.d.ts +69 -0
- package/dist/migration/lib/scaffold/renumber-migration.d.ts.map +1 -0
- package/dist/migration/lib/scaffold/renumber-migration.js +170 -0
- package/dist/migration/lib/scaffold/renumber-migration.js.map +1 -0
- package/dist/migration/lib/scaffold/scaffold-authorization-change.d.ts +19 -0
- package/dist/migration/lib/scaffold/scaffold-authorization-change.d.ts.map +1 -0
- package/dist/migration/lib/scaffold/scaffold-authorization-change.js +47 -0
- package/dist/migration/lib/scaffold/scaffold-authorization-change.js.map +1 -0
- package/dist/migration/lib/scaffold/scaffold-migration.d.ts +32 -0
- package/dist/migration/lib/scaffold/scaffold-migration.d.ts.map +1 -0
- package/dist/migration/lib/scaffold/scaffold-migration.js +89 -0
- package/dist/migration/lib/scaffold/scaffold-migration.js.map +1 -0
- package/dist/migration/lib/spicedb-to-postgres/access-model-from-ir.d.ts +8 -0
- package/dist/migration/lib/spicedb-to-postgres/access-model-from-ir.d.ts.map +1 -0
- package/dist/migration/lib/spicedb-to-postgres/access-model-from-ir.js +10 -0
- package/dist/migration/lib/spicedb-to-postgres/access-model-from-ir.js.map +1 -0
- package/dist/migration/lib/spicedb-to-postgres/authzed-client-adapter.d.ts +94 -0
- package/dist/migration/lib/spicedb-to-postgres/authzed-client-adapter.d.ts.map +1 -0
- package/dist/migration/lib/spicedb-to-postgres/authzed-client-adapter.js +100 -0
- package/dist/migration/lib/spicedb-to-postgres/authzed-client-adapter.js.map +1 -0
- package/dist/migration/lib/spicedb-to-postgres/cli-args.d.ts +30 -0
- package/dist/migration/lib/spicedb-to-postgres/cli-args.d.ts.map +1 -0
- package/dist/migration/lib/spicedb-to-postgres/cli-args.js +208 -0
- package/dist/migration/lib/spicedb-to-postgres/cli-args.js.map +1 -0
- package/dist/migration/lib/spicedb-to-postgres/cli-format.d.ts +16 -0
- package/dist/migration/lib/spicedb-to-postgres/cli-format.d.ts.map +1 -0
- package/dist/migration/lib/spicedb-to-postgres/cli-format.js +77 -0
- package/dist/migration/lib/spicedb-to-postgres/cli-format.js.map +1 -0
- package/dist/migration/lib/spicedb-to-postgres/cli.d.ts +47 -0
- package/dist/migration/lib/spicedb-to-postgres/cli.d.ts.map +1 -0
- package/dist/migration/lib/spicedb-to-postgres/cli.js +165 -0
- package/dist/migration/lib/spicedb-to-postgres/cli.js.map +1 -0
- package/dist/migration/lib/spicedb-to-postgres/index.d.ts +8 -0
- package/dist/migration/lib/spicedb-to-postgres/index.d.ts.map +1 -0
- package/dist/migration/lib/spicedb-to-postgres/index.js +8 -0
- package/dist/migration/lib/spicedb-to-postgres/index.js.map +1 -0
- package/dist/migration/lib/spicedb-to-postgres/migrate-spicedb-to-postgres.d.ts +36 -0
- package/dist/migration/lib/spicedb-to-postgres/migrate-spicedb-to-postgres.d.ts.map +1 -0
- package/dist/migration/lib/spicedb-to-postgres/migrate-spicedb-to-postgres.js +129 -0
- package/dist/migration/lib/spicedb-to-postgres/migrate-spicedb-to-postgres.js.map +1 -0
- package/dist/migration/lib/spicedb-to-postgres/postgres-relationship-ddl.d.ts +13 -0
- package/dist/migration/lib/spicedb-to-postgres/postgres-relationship-ddl.d.ts.map +1 -0
- package/dist/migration/lib/spicedb-to-postgres/postgres-relationship-ddl.js +60 -0
- package/dist/migration/lib/spicedb-to-postgres/postgres-relationship-ddl.js.map +1 -0
- package/dist/migration/lib/spicedb-to-postgres/verify-parity.d.ts +51 -0
- package/dist/migration/lib/spicedb-to-postgres/verify-parity.d.ts.map +1 -0
- package/dist/migration/lib/spicedb-to-postgres/verify-parity.js +174 -0
- package/dist/migration/lib/spicedb-to-postgres/verify-parity.js.map +1 -0
- package/dist/migration/testing/fake-schema-store.d.ts +31 -0
- package/dist/migration/testing/fake-schema-store.d.ts.map +1 -0
- package/dist/migration/testing/fake-schema-store.js +79 -0
- package/dist/migration/testing/fake-schema-store.js.map +1 -0
- package/dist/spicedb-access.tsbuildinfo +1 -0
- package/dist/testing/create-shared-test-spice-db.d.ts +4 -0
- package/dist/testing/create-shared-test-spice-db.d.ts.map +1 -0
- package/dist/testing/create-shared-test-spice-db.js +9 -0
- package/dist/testing/create-shared-test-spice-db.js.map +1 -0
- package/dist/testing/fake-apply-after-commit.d.ts +29 -0
- package/dist/testing/fake-apply-after-commit.d.ts.map +1 -0
- package/dist/testing/fake-apply-after-commit.js +50 -0
- package/dist/testing/fake-apply-after-commit.js.map +1 -0
- package/dist/testing/fake-claim.d.ts +50 -0
- package/dist/testing/fake-claim.d.ts.map +1 -0
- package/dist/testing/fake-claim.js +187 -0
- package/dist/testing/fake-claim.js.map +1 -0
- package/dist/testing/fake-enqueue.d.ts +37 -0
- package/dist/testing/fake-enqueue.d.ts.map +1 -0
- package/dist/testing/fake-enqueue.js +84 -0
- package/dist/testing/fake-enqueue.js.map +1 -0
- package/dist/testing/in-memory-owner-lock.d.ts +7 -0
- package/dist/testing/in-memory-owner-lock.d.ts.map +1 -0
- package/dist/testing/in-memory-owner-lock.js +25 -0
- package/dist/testing/in-memory-owner-lock.js.map +1 -0
- package/dist/testing/index.d.ts +11 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +11 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/prove-scope-matches-lookup.d.ts +22 -0
- package/dist/testing/prove-scope-matches-lookup.d.ts.map +1 -0
- package/dist/testing/prove-scope-matches-lookup.js +67 -0
- package/dist/testing/prove-scope-matches-lookup.js.map +1 -0
- package/dist/testing/start-test-spice-db.d.ts +31 -0
- package/dist/testing/start-test-spice-db.d.ts.map +1 -0
- package/dist/testing/start-test-spice-db.js +73 -0
- package/dist/testing/start-test-spice-db.js.map +1 -0
- package/dist/testing/tuned-spice-db-benchmark.d.ts +22 -0
- package/dist/testing/tuned-spice-db-benchmark.d.ts.map +1 -0
- package/dist/testing/tuned-spice-db-benchmark.js +148 -0
- package/dist/testing/tuned-spice-db-benchmark.js.map +1 -0
- package/package.json +73 -4
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The projector's decisions, with no database and no clock of their own.
|
|
3
|
+
*
|
|
4
|
+
* Claiming itself must happen in SQL — only the database can hand one row to
|
|
5
|
+
* exactly one worker — so what lives here is the two judgements that surround
|
|
6
|
+
* it: which rows a claim is ALLOWED to take, expressed as the cutoff its WHERE
|
|
7
|
+
* compares against, and what becomes of a row whose projection just failed.
|
|
8
|
+
* Both are the kind of arithmetic that is wrong in production and untestable
|
|
9
|
+
* there.
|
|
10
|
+
*/
|
|
11
|
+
/** How long a worker may hold a claimed row before another may steal it. */
|
|
12
|
+
export const DEFAULT_LEASE_MS = 60_000;
|
|
13
|
+
/**
|
|
14
|
+
* Give up after this many failures and leave the row for a human. The count is
|
|
15
|
+
* deliberately small: a fact that has failed five times is not going to
|
|
16
|
+
* succeed on the sixth, and a row retried forever is a queue that never drains
|
|
17
|
+
* and an alert nobody sees.
|
|
18
|
+
*/
|
|
19
|
+
export const DEFAULT_MAX_ATTEMPTS = 5;
|
|
20
|
+
/**
|
|
21
|
+
* A row locked at or before this instant has an expired lease and may be
|
|
22
|
+
* re-claimed. This is what stops a crashed worker parking a fact forever: the
|
|
23
|
+
* worker is gone, its lock is stale, and the next run takes the row back.
|
|
24
|
+
*/
|
|
25
|
+
export function leaseCutoff(now, leaseMs = DEFAULT_LEASE_MS) {
|
|
26
|
+
return new Date(now.getTime() - leaseMs);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* What a failed projection does to its row. Below the limit it goes back to
|
|
30
|
+
* PENDING with its lock released, so the next run picks it up; at the limit it
|
|
31
|
+
* becomes FAILED and stays visible, because a fact that cannot be projected is
|
|
32
|
+
* a human's problem and a silent drop would be a permission that quietly never
|
|
33
|
+
* arrived.
|
|
34
|
+
*/
|
|
35
|
+
export function outcomeAfterFailure(attemptsBefore, maxAttempts = DEFAULT_MAX_ATTEMPTS) {
|
|
36
|
+
const attempts = attemptsBefore + 1;
|
|
37
|
+
return { status: attempts >= maxAttempts ? "FAILED" : "PENDING", attempts };
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Trim an adapter's error to something a `last_error` column and a human can
|
|
41
|
+
* both hold. Never widened into structured diagnostics: this column exists to
|
|
42
|
+
* say what went wrong at a glance, and the projector's logs hold the rest.
|
|
43
|
+
*/
|
|
44
|
+
export function summarizeError(error, maxLength = 500) {
|
|
45
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
46
|
+
return message.length <= maxLength ? message : `${message.slice(0, maxLength - 1)}…`;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=claim-rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claim-rules.js","sourceRoot":"","sources":["../../../../src/lib/access-changes/logic/claim-rules.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AAEH,4EAA4E;AAC5E,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEvC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAEtC;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,GAAS,EAAE,OAAO,GAAW,gBAAgB;IACvE,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC;AAC3C,CAAC;AAWD;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,cAAsB,EACtB,WAAW,GAAW,oBAAoB;IAE1C,MAAM,QAAQ,GAAG,cAAc,GAAG,CAAC,CAAC;IACpC,OAAO,EAAE,MAAM,EAAE,QAAQ,IAAI,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,EAAE,QAAQ,EAAE,CAAC;AAC9E,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc,EAAE,SAAS,GAAG,GAAG;IAC5D,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvE,OAAO,OAAO,CAAC,MAAM,IAAI,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,GAAG,CAAC,CAAC,GAAG,CAAC;AACvF,CAAC"}
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
export type AccessResourceId = string;
|
|
2
|
+
export type AccessSubjectId = string;
|
|
3
|
+
export type AuthorityPartitionId = string;
|
|
4
|
+
export declare const authorizationOutbox: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
5
|
+
name: "authorization_outbox";
|
|
6
|
+
schema: undefined;
|
|
7
|
+
columns: {
|
|
8
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
9
|
+
name: "id";
|
|
10
|
+
tableName: "authorization_outbox";
|
|
11
|
+
dataType: "string";
|
|
12
|
+
columnType: "PgUUID";
|
|
13
|
+
data: string & import("zod").$brand<"AccessChangeId">;
|
|
14
|
+
driverParam: string;
|
|
15
|
+
notNull: true;
|
|
16
|
+
hasDefault: true;
|
|
17
|
+
isPrimaryKey: true;
|
|
18
|
+
isAutoincrement: false;
|
|
19
|
+
hasRuntimeDefault: false;
|
|
20
|
+
enumValues: undefined;
|
|
21
|
+
baseColumn: never;
|
|
22
|
+
identity: undefined;
|
|
23
|
+
generated: undefined;
|
|
24
|
+
}, {}, {
|
|
25
|
+
$type: string & import("zod").$brand<"AccessChangeId">;
|
|
26
|
+
}>;
|
|
27
|
+
idempotencyKey: import("drizzle-orm/pg-core").PgColumn<{
|
|
28
|
+
name: "idempotency_key";
|
|
29
|
+
tableName: "authorization_outbox";
|
|
30
|
+
dataType: "string";
|
|
31
|
+
columnType: "PgText";
|
|
32
|
+
data: string;
|
|
33
|
+
driverParam: string;
|
|
34
|
+
notNull: true;
|
|
35
|
+
hasDefault: false;
|
|
36
|
+
isPrimaryKey: false;
|
|
37
|
+
isAutoincrement: false;
|
|
38
|
+
hasRuntimeDefault: false;
|
|
39
|
+
enumValues: [string, ...string[]];
|
|
40
|
+
baseColumn: never;
|
|
41
|
+
identity: undefined;
|
|
42
|
+
generated: undefined;
|
|
43
|
+
}, {}, {}>;
|
|
44
|
+
operation: import("drizzle-orm/pg-core").PgColumn<{
|
|
45
|
+
name: "operation";
|
|
46
|
+
tableName: "authorization_outbox";
|
|
47
|
+
dataType: "string";
|
|
48
|
+
columnType: "PgText";
|
|
49
|
+
data: "DELETE" | "WRITE";
|
|
50
|
+
driverParam: string;
|
|
51
|
+
notNull: true;
|
|
52
|
+
hasDefault: false;
|
|
53
|
+
isPrimaryKey: false;
|
|
54
|
+
isAutoincrement: false;
|
|
55
|
+
hasRuntimeDefault: false;
|
|
56
|
+
enumValues: ["WRITE", "DELETE"];
|
|
57
|
+
baseColumn: never;
|
|
58
|
+
identity: undefined;
|
|
59
|
+
generated: undefined;
|
|
60
|
+
}, {}, {}>;
|
|
61
|
+
resourceType: import("drizzle-orm/pg-core").PgColumn<{
|
|
62
|
+
name: "resource_type";
|
|
63
|
+
tableName: "authorization_outbox";
|
|
64
|
+
dataType: "string";
|
|
65
|
+
columnType: "PgText";
|
|
66
|
+
data: string;
|
|
67
|
+
driverParam: string;
|
|
68
|
+
notNull: true;
|
|
69
|
+
hasDefault: false;
|
|
70
|
+
isPrimaryKey: false;
|
|
71
|
+
isAutoincrement: false;
|
|
72
|
+
hasRuntimeDefault: false;
|
|
73
|
+
enumValues: [string, ...string[]];
|
|
74
|
+
baseColumn: never;
|
|
75
|
+
identity: undefined;
|
|
76
|
+
generated: undefined;
|
|
77
|
+
}, {}, {}>;
|
|
78
|
+
resourceId: import("drizzle-orm/pg-core").PgColumn<{
|
|
79
|
+
name: "resource_id";
|
|
80
|
+
tableName: "authorization_outbox";
|
|
81
|
+
dataType: "string";
|
|
82
|
+
columnType: "PgText";
|
|
83
|
+
data: string;
|
|
84
|
+
driverParam: string;
|
|
85
|
+
notNull: true;
|
|
86
|
+
hasDefault: false;
|
|
87
|
+
isPrimaryKey: false;
|
|
88
|
+
isAutoincrement: false;
|
|
89
|
+
hasRuntimeDefault: false;
|
|
90
|
+
enumValues: [string, ...string[]];
|
|
91
|
+
baseColumn: never;
|
|
92
|
+
identity: undefined;
|
|
93
|
+
generated: undefined;
|
|
94
|
+
}, {}, {
|
|
95
|
+
$type: string;
|
|
96
|
+
}>;
|
|
97
|
+
relation: import("drizzle-orm/pg-core").PgColumn<{
|
|
98
|
+
name: "relation";
|
|
99
|
+
tableName: "authorization_outbox";
|
|
100
|
+
dataType: "string";
|
|
101
|
+
columnType: "PgText";
|
|
102
|
+
data: string;
|
|
103
|
+
driverParam: string;
|
|
104
|
+
notNull: true;
|
|
105
|
+
hasDefault: false;
|
|
106
|
+
isPrimaryKey: false;
|
|
107
|
+
isAutoincrement: false;
|
|
108
|
+
hasRuntimeDefault: false;
|
|
109
|
+
enumValues: [string, ...string[]];
|
|
110
|
+
baseColumn: never;
|
|
111
|
+
identity: undefined;
|
|
112
|
+
generated: undefined;
|
|
113
|
+
}, {}, {}>;
|
|
114
|
+
subjectType: import("drizzle-orm/pg-core").PgColumn<{
|
|
115
|
+
name: "subject_type";
|
|
116
|
+
tableName: "authorization_outbox";
|
|
117
|
+
dataType: "string";
|
|
118
|
+
columnType: "PgText";
|
|
119
|
+
data: string;
|
|
120
|
+
driverParam: string;
|
|
121
|
+
notNull: true;
|
|
122
|
+
hasDefault: false;
|
|
123
|
+
isPrimaryKey: false;
|
|
124
|
+
isAutoincrement: false;
|
|
125
|
+
hasRuntimeDefault: false;
|
|
126
|
+
enumValues: [string, ...string[]];
|
|
127
|
+
baseColumn: never;
|
|
128
|
+
identity: undefined;
|
|
129
|
+
generated: undefined;
|
|
130
|
+
}, {}, {}>;
|
|
131
|
+
subjectId: import("drizzle-orm/pg-core").PgColumn<{
|
|
132
|
+
name: "subject_id";
|
|
133
|
+
tableName: "authorization_outbox";
|
|
134
|
+
dataType: "string";
|
|
135
|
+
columnType: "PgText";
|
|
136
|
+
data: string;
|
|
137
|
+
driverParam: string;
|
|
138
|
+
notNull: true;
|
|
139
|
+
hasDefault: false;
|
|
140
|
+
isPrimaryKey: false;
|
|
141
|
+
isAutoincrement: false;
|
|
142
|
+
hasRuntimeDefault: false;
|
|
143
|
+
enumValues: [string, ...string[]];
|
|
144
|
+
baseColumn: never;
|
|
145
|
+
identity: undefined;
|
|
146
|
+
generated: undefined;
|
|
147
|
+
}, {}, {
|
|
148
|
+
$type: string;
|
|
149
|
+
}>;
|
|
150
|
+
subjectRelation: import("drizzle-orm/pg-core").PgColumn<{
|
|
151
|
+
name: "subject_relation";
|
|
152
|
+
tableName: "authorization_outbox";
|
|
153
|
+
dataType: "string";
|
|
154
|
+
columnType: "PgText";
|
|
155
|
+
data: string;
|
|
156
|
+
driverParam: string;
|
|
157
|
+
notNull: false;
|
|
158
|
+
hasDefault: false;
|
|
159
|
+
isPrimaryKey: false;
|
|
160
|
+
isAutoincrement: false;
|
|
161
|
+
hasRuntimeDefault: false;
|
|
162
|
+
enumValues: [string, ...string[]];
|
|
163
|
+
baseColumn: never;
|
|
164
|
+
identity: undefined;
|
|
165
|
+
generated: undefined;
|
|
166
|
+
}, {}, {}>;
|
|
167
|
+
ownerPartitionId: import("drizzle-orm/pg-core").PgColumn<{
|
|
168
|
+
name: "owner_partition_id";
|
|
169
|
+
tableName: "authorization_outbox";
|
|
170
|
+
dataType: "string";
|
|
171
|
+
columnType: "PgUUID";
|
|
172
|
+
data: string;
|
|
173
|
+
driverParam: string;
|
|
174
|
+
notNull: false;
|
|
175
|
+
hasDefault: false;
|
|
176
|
+
isPrimaryKey: false;
|
|
177
|
+
isAutoincrement: false;
|
|
178
|
+
hasRuntimeDefault: false;
|
|
179
|
+
enumValues: undefined;
|
|
180
|
+
baseColumn: never;
|
|
181
|
+
identity: undefined;
|
|
182
|
+
generated: undefined;
|
|
183
|
+
}, {}, {
|
|
184
|
+
$type: string;
|
|
185
|
+
}>;
|
|
186
|
+
status: import("drizzle-orm/pg-core").PgColumn<{
|
|
187
|
+
name: "status";
|
|
188
|
+
tableName: "authorization_outbox";
|
|
189
|
+
dataType: "string";
|
|
190
|
+
columnType: "PgText";
|
|
191
|
+
data: "FAILED" | "PENDING" | "PROJECTED" | "SUPERSEDED";
|
|
192
|
+
driverParam: string;
|
|
193
|
+
notNull: true;
|
|
194
|
+
hasDefault: false;
|
|
195
|
+
isPrimaryKey: false;
|
|
196
|
+
isAutoincrement: false;
|
|
197
|
+
hasRuntimeDefault: false;
|
|
198
|
+
enumValues: ["PENDING", "PROJECTED", "FAILED", "SUPERSEDED"];
|
|
199
|
+
baseColumn: never;
|
|
200
|
+
identity: undefined;
|
|
201
|
+
generated: undefined;
|
|
202
|
+
}, {}, {}>;
|
|
203
|
+
attempts: import("drizzle-orm/pg-core").PgColumn<{
|
|
204
|
+
name: "attempts";
|
|
205
|
+
tableName: "authorization_outbox";
|
|
206
|
+
dataType: "number";
|
|
207
|
+
columnType: "PgInteger";
|
|
208
|
+
data: number;
|
|
209
|
+
driverParam: string | number;
|
|
210
|
+
notNull: true;
|
|
211
|
+
hasDefault: true;
|
|
212
|
+
isPrimaryKey: false;
|
|
213
|
+
isAutoincrement: false;
|
|
214
|
+
hasRuntimeDefault: false;
|
|
215
|
+
enumValues: undefined;
|
|
216
|
+
baseColumn: never;
|
|
217
|
+
identity: undefined;
|
|
218
|
+
generated: undefined;
|
|
219
|
+
}, {}, {}>;
|
|
220
|
+
lockedBy: import("drizzle-orm/pg-core").PgColumn<{
|
|
221
|
+
name: "locked_by";
|
|
222
|
+
tableName: "authorization_outbox";
|
|
223
|
+
dataType: "string";
|
|
224
|
+
columnType: "PgText";
|
|
225
|
+
data: string;
|
|
226
|
+
driverParam: string;
|
|
227
|
+
notNull: false;
|
|
228
|
+
hasDefault: false;
|
|
229
|
+
isPrimaryKey: false;
|
|
230
|
+
isAutoincrement: false;
|
|
231
|
+
hasRuntimeDefault: false;
|
|
232
|
+
enumValues: [string, ...string[]];
|
|
233
|
+
baseColumn: never;
|
|
234
|
+
identity: undefined;
|
|
235
|
+
generated: undefined;
|
|
236
|
+
}, {}, {}>;
|
|
237
|
+
lockedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
238
|
+
name: "locked_at";
|
|
239
|
+
tableName: "authorization_outbox";
|
|
240
|
+
dataType: "date";
|
|
241
|
+
columnType: "PgTimestamp";
|
|
242
|
+
data: Date;
|
|
243
|
+
driverParam: string;
|
|
244
|
+
notNull: false;
|
|
245
|
+
hasDefault: false;
|
|
246
|
+
isPrimaryKey: false;
|
|
247
|
+
isAutoincrement: false;
|
|
248
|
+
hasRuntimeDefault: false;
|
|
249
|
+
enumValues: undefined;
|
|
250
|
+
baseColumn: never;
|
|
251
|
+
identity: undefined;
|
|
252
|
+
generated: undefined;
|
|
253
|
+
}, {}, {}>;
|
|
254
|
+
lastError: import("drizzle-orm/pg-core").PgColumn<{
|
|
255
|
+
name: "last_error";
|
|
256
|
+
tableName: "authorization_outbox";
|
|
257
|
+
dataType: "string";
|
|
258
|
+
columnType: "PgText";
|
|
259
|
+
data: string;
|
|
260
|
+
driverParam: string;
|
|
261
|
+
notNull: false;
|
|
262
|
+
hasDefault: false;
|
|
263
|
+
isPrimaryKey: false;
|
|
264
|
+
isAutoincrement: false;
|
|
265
|
+
hasRuntimeDefault: false;
|
|
266
|
+
enumValues: [string, ...string[]];
|
|
267
|
+
baseColumn: never;
|
|
268
|
+
identity: undefined;
|
|
269
|
+
generated: undefined;
|
|
270
|
+
}, {}, {}>;
|
|
271
|
+
enqueuedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
272
|
+
name: "enqueued_at";
|
|
273
|
+
tableName: "authorization_outbox";
|
|
274
|
+
dataType: "date";
|
|
275
|
+
columnType: "PgTimestamp";
|
|
276
|
+
data: Date;
|
|
277
|
+
driverParam: string;
|
|
278
|
+
notNull: true;
|
|
279
|
+
hasDefault: false;
|
|
280
|
+
isPrimaryKey: false;
|
|
281
|
+
isAutoincrement: false;
|
|
282
|
+
hasRuntimeDefault: false;
|
|
283
|
+
enumValues: undefined;
|
|
284
|
+
baseColumn: never;
|
|
285
|
+
identity: undefined;
|
|
286
|
+
generated: undefined;
|
|
287
|
+
}, {}, {}>;
|
|
288
|
+
projectedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
289
|
+
name: "projected_at";
|
|
290
|
+
tableName: "authorization_outbox";
|
|
291
|
+
dataType: "date";
|
|
292
|
+
columnType: "PgTimestamp";
|
|
293
|
+
data: Date;
|
|
294
|
+
driverParam: string;
|
|
295
|
+
notNull: false;
|
|
296
|
+
hasDefault: false;
|
|
297
|
+
isPrimaryKey: false;
|
|
298
|
+
isAutoincrement: false;
|
|
299
|
+
hasRuntimeDefault: false;
|
|
300
|
+
enumValues: undefined;
|
|
301
|
+
baseColumn: never;
|
|
302
|
+
identity: undefined;
|
|
303
|
+
generated: undefined;
|
|
304
|
+
}, {}, {}>;
|
|
305
|
+
supersededAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
306
|
+
name: "superseded_at";
|
|
307
|
+
tableName: "authorization_outbox";
|
|
308
|
+
dataType: "date";
|
|
309
|
+
columnType: "PgTimestamp";
|
|
310
|
+
data: Date;
|
|
311
|
+
driverParam: string;
|
|
312
|
+
notNull: false;
|
|
313
|
+
hasDefault: false;
|
|
314
|
+
isPrimaryKey: false;
|
|
315
|
+
isAutoincrement: false;
|
|
316
|
+
hasRuntimeDefault: false;
|
|
317
|
+
enumValues: undefined;
|
|
318
|
+
baseColumn: never;
|
|
319
|
+
identity: undefined;
|
|
320
|
+
generated: undefined;
|
|
321
|
+
}, {}, {}>;
|
|
322
|
+
supersededByIdempotencyKey: import("drizzle-orm/pg-core").PgColumn<{
|
|
323
|
+
name: "superseded_by_idempotency_key";
|
|
324
|
+
tableName: "authorization_outbox";
|
|
325
|
+
dataType: "string";
|
|
326
|
+
columnType: "PgText";
|
|
327
|
+
data: string;
|
|
328
|
+
driverParam: string;
|
|
329
|
+
notNull: false;
|
|
330
|
+
hasDefault: false;
|
|
331
|
+
isPrimaryKey: false;
|
|
332
|
+
isAutoincrement: false;
|
|
333
|
+
hasRuntimeDefault: false;
|
|
334
|
+
enumValues: [string, ...string[]];
|
|
335
|
+
baseColumn: never;
|
|
336
|
+
identity: undefined;
|
|
337
|
+
generated: undefined;
|
|
338
|
+
}, {}, {}>;
|
|
339
|
+
};
|
|
340
|
+
dialect: 'pg';
|
|
341
|
+
}>;
|
|
342
|
+
//# sourceMappingURL=access-changes.tables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access-changes.tables.d.ts","sourceRoot":"","sources":["../../../../src/lib/access-changes/postgres/access-changes.tables.ts"],"names":[],"mappings":"AAiBA,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC;AACtC,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AACrC,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAE1C,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyC/B,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// GENERATED - DO NOT EDIT. Author a migration, then run npm run db:schema:generate.
|
|
2
|
+
// Schema fingerprint 839b9f107208b809: columns, constraints, indexes, triggers.
|
|
3
|
+
import { check, index, integer, pgTable, text, timestamp, uniqueIndex, uuid, } from "drizzle-orm/pg-core";
|
|
4
|
+
import { sql } from "drizzle-orm";
|
|
5
|
+
import { OUTBOX_OPERATION_VALUES, OUTBOX_STATUS_VALUES } from "../enqueue.js";
|
|
6
|
+
export const authorizationOutbox = pgTable("authorization_outbox", {
|
|
7
|
+
id: uuid("id")
|
|
8
|
+
.primaryKey()
|
|
9
|
+
.defaultRandom()
|
|
10
|
+
.notNull()
|
|
11
|
+
.$type(),
|
|
12
|
+
idempotencyKey: text("idempotency_key").notNull(),
|
|
13
|
+
operation: text("operation", { enum: OUTBOX_OPERATION_VALUES }).notNull(),
|
|
14
|
+
resourceType: text("resource_type").notNull(),
|
|
15
|
+
resourceId: text("resource_id").notNull().$type(),
|
|
16
|
+
relation: text("relation").notNull(),
|
|
17
|
+
subjectType: text("subject_type").notNull(),
|
|
18
|
+
subjectId: text("subject_id").notNull().$type(),
|
|
19
|
+
subjectRelation: text("subject_relation"),
|
|
20
|
+
ownerPartitionId: uuid("owner_partition_id").$type(),
|
|
21
|
+
status: text("status", { enum: OUTBOX_STATUS_VALUES }).notNull(),
|
|
22
|
+
attempts: integer("attempts").default(0).notNull(),
|
|
23
|
+
lockedBy: text("locked_by"),
|
|
24
|
+
lockedAt: timestamp("locked_at", { withTimezone: true }),
|
|
25
|
+
lastError: text("last_error"),
|
|
26
|
+
enqueuedAt: timestamp("enqueued_at", { withTimezone: true }).notNull(),
|
|
27
|
+
projectedAt: timestamp("projected_at", { withTimezone: true }),
|
|
28
|
+
supersededAt: timestamp("superseded_at", { withTimezone: true }),
|
|
29
|
+
supersededByIdempotencyKey: text("superseded_by_idempotency_key"),
|
|
30
|
+
}, (table) => [
|
|
31
|
+
uniqueIndex("authorization_outbox_idempotency_uidx").on(table.idempotencyKey),
|
|
32
|
+
index("authorization_outbox_partition_idx").on(table.ownerPartitionId),
|
|
33
|
+
index("authorization_outbox_status_enqueued_idx").on(table.status, table.enqueuedAt),
|
|
34
|
+
check("authorization_outbox_supersession_check", sql `((${table.status} = 'SUPERSEDED'::text) AND (${table.supersededAt} IS NOT NULL) AND (${table.supersededByIdempotencyKey} IS NOT NULL) AND (${table.lastError} IS NULL)) OR ((${table.status} <> 'SUPERSEDED'::text) AND (${table.supersededAt} IS NULL) AND (${table.supersededByIdempotencyKey} IS NULL))`),
|
|
35
|
+
]);
|
|
36
|
+
//# sourceMappingURL=access-changes.tables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access-changes.tables.js","sourceRoot":"","sources":["../../../../src/lib/access-changes/postgres/access-changes.tables.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,gFAAgF;AAEhF,OAAO,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,OAAO,EACP,IAAI,EACJ,SAAS,EACT,WAAW,EACX,IAAI,GACL,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAM9E,MAAM,CAAC,MAAM,mBAAmB,GAAG,OAAO,CACxC,sBAAsB,EACtB;IACE,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC;SACX,UAAU,EAAE;SACZ,aAAa,EAAE;SACf,OAAO,EAAE;SACT,KAAK,EAAkB;IAC1B,cAAc,EAAE,IAAI,CAAC,iBAAiB,C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AC;CAClE,EACD,CAAC,KAAK,EAAE,EAAE,CAAC;IACT,WAAW,CAAC,uCAAuC,CAAC,CAAC,EAAE,CACrD,KAAK,CAAC,cAAc,CACrB;IACD,KAAK,CAAC,oCAAoC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,gBAAgB,CAAC;IACtE,KAAK,CAAC,0CAA0C,CAAC,CAAC,EAAE,CAClD,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,UAAU,CACjB;IACD,KAAK,CACH,yCAAyC,EACzC,GAAG,CAAA,KAAK,KAAK,CAAC,MAAM,+BAA+B,KAAK,CAAC,YAAY,sBAAsB,KAAK,CAAC,0BAA0B,sBAAsB,KAAK,CAAC,SAAS,mBAAmB,KAAK,CAAC,MAAM,gCAAgC,KAAK,CAAC,YAAY,kBAAkB,KAAK,CAAC,0BAA0B,YAAY,CAChT;CACF,CACF,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { DrizzleHandle } from "@dads-framework/postgres";
|
|
2
|
+
import type { AccessChangeId } from "../access-change.ids.js";
|
|
3
|
+
import type { ClaimAccessChanges } from "../claim.js";
|
|
4
|
+
import { type ClaimedOutboxRow, type OutboxClaim, type OutboxCounts, type OutboxHeldKeysQuery, type OutboxKeyClaim } from "../claim.js";
|
|
5
|
+
/**
|
|
6
|
+
* Postgres adapter for the projector's side of the outbox.
|
|
7
|
+
*
|
|
8
|
+
* The claim is one statement: an UPDATE whose subquery selects with
|
|
9
|
+
* `FOR UPDATE SKIP LOCKED`. Two workers running at once therefore never
|
|
10
|
+
* receive the same row — the second skips what the first has locked instead of
|
|
11
|
+
* waiting for it — and no read-then-write window exists in which both could
|
|
12
|
+
* decide a row was theirs.
|
|
13
|
+
*
|
|
14
|
+
* The claim takes PENDING rows AND rows whose lease has expired. The second
|
|
15
|
+
* half is what stops a crashed worker parking a fact forever: its lock is
|
|
16
|
+
* stale, so the row comes back rather than sitting claimed by a process that
|
|
17
|
+
* no longer exists.
|
|
18
|
+
*/
|
|
19
|
+
export declare class PostgresClaimAccessChanges implements ClaimAccessChanges {
|
|
20
|
+
private readonly db;
|
|
21
|
+
constructor(db: DrizzleHandle);
|
|
22
|
+
claim(claim: OutboxClaim): Promise<readonly ClaimedOutboxRow[]>;
|
|
23
|
+
claimByKeys(claim: OutboxKeyClaim): Promise<readonly ClaimedOutboxRow[]>;
|
|
24
|
+
/**
|
|
25
|
+
* The claim both entry points share, so the exclusion rules cannot drift
|
|
26
|
+
* apart: select eligible rows `FOR UPDATE SKIP LOCKED`, then stamp them in
|
|
27
|
+
* the same statement.
|
|
28
|
+
*/
|
|
29
|
+
private take;
|
|
30
|
+
/**
|
|
31
|
+
* One read on the idempotency-key unique index: no `FOR UPDATE`, so it
|
|
32
|
+
* never waits on, nor takes, another worker's claim.
|
|
33
|
+
*/
|
|
34
|
+
heldByLiveClaim(query: OutboxHeldKeysQuery): Promise<readonly string[]>;
|
|
35
|
+
isClaimOwned(id: AccessChangeId, workerId: string): Promise<boolean>;
|
|
36
|
+
markProjected(ids: readonly AccessChangeId[], at: Date, workerId: string): Promise<boolean>;
|
|
37
|
+
markFailed(id: AccessChangeId, outcome: {
|
|
38
|
+
status: "PENDING" | "FAILED";
|
|
39
|
+
attempts: number;
|
|
40
|
+
}, lastError: string, workerId: string): Promise<boolean>;
|
|
41
|
+
counts(): Promise<OutboxCounts>;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=claim.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claim.d.ts","sourceRoot":"","sources":["../../../../src/lib/access-changes/postgres/claim.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACpB,MAAM,aAAa,CAAC;AAWrB;;;;;;;;;;;;;GAaG;AACH,qBAAa,0BAA2B,YAAW,kBAAkB;IACvD,OAAO,CAAC,QAAQ,CAAC,EAAE;IAA/B,YAA6B,EAAE,EAAE,aAAa,EAAI;IAE5C,KAAK,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,gBAAgB,EAAE,CAAC,CAEpE;IAEK,WAAW,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,SAAS,gBAAgB,EAAE,CAAC,CAQ7E;IAED;;;;OAIG;YACW,IAAI;IAiClB;;;OAGG;IACG,eAAe,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAa5E;IAEK,YAAY,CAAC,EAAE,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAazE;IAEK,aAAa,CAAC,GAAG,EAAE,SAAS,cAAc,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAoBhG;IAEK,UAAU,CACd,EAAE,EAAE,cAAc,EAClB,OAAO,EAAE;QAAE,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,EAC3D,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,OAAO,CAAC,CAqBlB;IAEK,MAAM,IAAI,OAAO,CAAC,YAAY,CAAC,CAWpC;CACF"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { and, count, eq, gt, inArray, isNull, lte, or } from "drizzle-orm";
|
|
2
|
+
import {} from "../claim.js";
|
|
3
|
+
import { authorizationOutbox } from "./access-changes.tables.js";
|
|
4
|
+
/** PENDING, and either unlocked or holding a lock old enough to steal. */
|
|
5
|
+
function claimable(leaseCutoff) {
|
|
6
|
+
return and(eq(authorizationOutbox.status, "PENDING"), or(isNull(authorizationOutbox.lockedAt), lte(authorizationOutbox.lockedAt, leaseCutoff)));
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Postgres adapter for the projector's side of the outbox.
|
|
10
|
+
*
|
|
11
|
+
* The claim is one statement: an UPDATE whose subquery selects with
|
|
12
|
+
* `FOR UPDATE SKIP LOCKED`. Two workers running at once therefore never
|
|
13
|
+
* receive the same row — the second skips what the first has locked instead of
|
|
14
|
+
* waiting for it — and no read-then-write window exists in which both could
|
|
15
|
+
* decide a row was theirs.
|
|
16
|
+
*
|
|
17
|
+
* The claim takes PENDING rows AND rows whose lease has expired. The second
|
|
18
|
+
* half is what stops a crashed worker parking a fact forever: its lock is
|
|
19
|
+
* stale, so the row comes back rather than sitting claimed by a process that
|
|
20
|
+
* no longer exists.
|
|
21
|
+
*/
|
|
22
|
+
export class PostgresClaimAccessChanges {
|
|
23
|
+
db;
|
|
24
|
+
constructor(db) {
|
|
25
|
+
this.db = db;
|
|
26
|
+
}
|
|
27
|
+
async claim(claim) {
|
|
28
|
+
return this.take(claimable(claim.leaseCutoff), claim.batchSize, claim.workerId, claim.now);
|
|
29
|
+
}
|
|
30
|
+
async claimByKeys(claim) {
|
|
31
|
+
if (claim.idempotencyKeys.length === 0)
|
|
32
|
+
return [];
|
|
33
|
+
return this.take(and(claimable(claim.leaseCutoff), inArray(authorizationOutbox.idempotencyKey, [...claim.idempotencyKeys])), claim.idempotencyKeys.length, claim.workerId, claim.now);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The claim both entry points share, so the exclusion rules cannot drift
|
|
37
|
+
* apart: select eligible rows `FOR UPDATE SKIP LOCKED`, then stamp them in
|
|
38
|
+
* the same statement.
|
|
39
|
+
*/
|
|
40
|
+
async take(where, batchSize, workerId, now) {
|
|
41
|
+
const eligible = this.db
|
|
42
|
+
.select({ id: authorizationOutbox.id })
|
|
43
|
+
.from(authorizationOutbox)
|
|
44
|
+
.where(where)
|
|
45
|
+
.orderBy(authorizationOutbox.enqueuedAt)
|
|
46
|
+
.limit(batchSize)
|
|
47
|
+
.for("update", { skipLocked: true });
|
|
48
|
+
return this.db
|
|
49
|
+
.update(authorizationOutbox)
|
|
50
|
+
.set({ lockedBy: workerId, lockedAt: now })
|
|
51
|
+
.where(inArray(authorizationOutbox.id, eligible))
|
|
52
|
+
.returning({
|
|
53
|
+
id: authorizationOutbox.id,
|
|
54
|
+
idempotencyKey: authorizationOutbox.idempotencyKey,
|
|
55
|
+
operation: authorizationOutbox.operation,
|
|
56
|
+
resourceType: authorizationOutbox.resourceType,
|
|
57
|
+
resourceId: authorizationOutbox.resourceId,
|
|
58
|
+
relation: authorizationOutbox.relation,
|
|
59
|
+
subjectType: authorizationOutbox.subjectType,
|
|
60
|
+
subjectId: authorizationOutbox.subjectId,
|
|
61
|
+
subjectRelation: authorizationOutbox.subjectRelation,
|
|
62
|
+
ownerPartitionId: authorizationOutbox.ownerPartitionId,
|
|
63
|
+
attempts: authorizationOutbox.attempts,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* One read on the idempotency-key unique index: no `FOR UPDATE`, so it
|
|
68
|
+
* never waits on, nor takes, another worker's claim.
|
|
69
|
+
*/
|
|
70
|
+
async heldByLiveClaim(query) {
|
|
71
|
+
if (query.idempotencyKeys.length === 0)
|
|
72
|
+
return [];
|
|
73
|
+
const rows = await this.db
|
|
74
|
+
.select({ idempotencyKey: authorizationOutbox.idempotencyKey })
|
|
75
|
+
.from(authorizationOutbox)
|
|
76
|
+
.where(and(inArray(authorizationOutbox.idempotencyKey, [...query.idempotencyKeys]), eq(authorizationOutbox.status, "PENDING"), gt(authorizationOutbox.lockedAt, query.leaseCutoff)));
|
|
77
|
+
return rows.map((row) => row.idempotencyKey);
|
|
78
|
+
}
|
|
79
|
+
async isClaimOwned(id, workerId) {
|
|
80
|
+
const rows = await this.db
|
|
81
|
+
.select({ id: authorizationOutbox.id })
|
|
82
|
+
.from(authorizationOutbox)
|
|
83
|
+
.where(and(eq(authorizationOutbox.id, id), eq(authorizationOutbox.status, "PENDING"), eq(authorizationOutbox.lockedBy, workerId)))
|
|
84
|
+
.limit(1);
|
|
85
|
+
return rows[0] !== undefined;
|
|
86
|
+
}
|
|
87
|
+
async markProjected(ids, at, workerId) {
|
|
88
|
+
if (ids.length === 0)
|
|
89
|
+
return false;
|
|
90
|
+
const settled = await this.db
|
|
91
|
+
.update(authorizationOutbox)
|
|
92
|
+
.set({
|
|
93
|
+
status: "PROJECTED",
|
|
94
|
+
projectedAt: at,
|
|
95
|
+
lockedBy: null,
|
|
96
|
+
lockedAt: null,
|
|
97
|
+
lastError: null,
|
|
98
|
+
})
|
|
99
|
+
.where(and(inArray(authorizationOutbox.id, [...ids]), eq(authorizationOutbox.status, "PENDING"), eq(authorizationOutbox.lockedBy, workerId)))
|
|
100
|
+
.returning({ id: authorizationOutbox.id });
|
|
101
|
+
return settled.length === ids.length;
|
|
102
|
+
}
|
|
103
|
+
async markFailed(id, outcome, lastError, workerId) {
|
|
104
|
+
const settled = await this.db
|
|
105
|
+
.update(authorizationOutbox)
|
|
106
|
+
.set({
|
|
107
|
+
status: outcome.status,
|
|
108
|
+
attempts: outcome.attempts,
|
|
109
|
+
lastError,
|
|
110
|
+
// The lock is released either way: a PENDING row must be claimable by
|
|
111
|
+
// the next run, and a FAILED row must not look like work in progress.
|
|
112
|
+
lockedBy: null,
|
|
113
|
+
lockedAt: null,
|
|
114
|
+
})
|
|
115
|
+
.where(and(eq(authorizationOutbox.id, id), eq(authorizationOutbox.status, "PENDING"), eq(authorizationOutbox.lockedBy, workerId)))
|
|
116
|
+
.returning({ id: authorizationOutbox.id });
|
|
117
|
+
return settled.length === 1;
|
|
118
|
+
}
|
|
119
|
+
async counts() {
|
|
120
|
+
const rows = await this.db
|
|
121
|
+
.select({
|
|
122
|
+
status: authorizationOutbox.status,
|
|
123
|
+
total: count(),
|
|
124
|
+
})
|
|
125
|
+
.from(authorizationOutbox)
|
|
126
|
+
.where(or(eq(authorizationOutbox.status, "PENDING"), eq(authorizationOutbox.status, "FAILED")))
|
|
127
|
+
.groupBy(authorizationOutbox.status);
|
|
128
|
+
const of = (status) => rows.find((row) => row.status === status)?.total ?? 0;
|
|
129
|
+
return { pending: of("PENDING"), failed: of("FAILED") };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=claim.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claim.js","sourceRoot":"","sources":["../../../../src/lib/access-changes/postgres/claim.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAM3E,OAAO,EAMN,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,0EAA0E;AAC1E,SAAS,SAAS,CAAC,WAAiB;IAClC,OAAO,GAAG,CACR,EAAE,CAAC,mBAAmB,CAAC,MAAM,EAAE,SAAS,CAAC,EACzC,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,mBAAmB,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,CACzF,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,0BAA0B;IACR,EAAE;IAA/B,YAA6B,EAAiB;kBAAjB,EAAE;IAAkB,CAAC;IAElD,KAAK,CAAC,KAAK,CAAC,KAAkB;QAC5B,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;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anges, UnfinishedAccessChange } from "../completion-status.js";
|
|
3
|
+
import type { OwnerLockLease } from "@dads-framework/access/runtime";
|
|
4
|
+
/** Scoped completion reads and explicit failed-fact retry; never settles facts. */
|
|
5
|
+
export declare class PostgresAccessChangeCompletionStatus implements AccessChangeCompletionStatusReader, RetryFailedAccessChanges {
|
|
6
|
+
private readonly db;
|
|
7
|
+
constructor(db: DrizzleHandle);
|
|
8
|
+
readUnfinished(input: {
|
|
9
|
+
readonly ownerPartitionIds: readonly string[];
|
|
10
|
+
}): Promise<readonly UnfinishedAccessChange[]>;
|
|
11
|
+
/**
|
|
12
|
+
* The named resources that still have a PENDING fact, a write or delete
|
|
13
|
+
* not yet projected to the graph, as `type:id`. A FAILED fact has stopped
|
|
14
|
+
* retrying, so it does not count: a caller waiting on it would wait for
|
|
15
|
+
* good. One query.
|
|
16
|
+
*/
|
|
17
|
+
pendingResources(resources: readonly {
|
|
18
|
+
readonly type: string;
|
|
19
|
+
readonly id: string;
|
|
20
|
+
}[]): Promise<ReadonlySet<string>>;
|
|
21
|
+
retryFailed(input: {
|
|
22
|
+
readonly ownerPartitionId: string;
|
|
23
|
+
readonly idempotencyKeys: readonly string[];
|
|
24
|
+
readonly lease: OwnerLockLease;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=completion-status.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"completion-status.d.ts","sourceRoot":"","sources":["../../../../src/lib/access-changes/postgres/completion-status.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,KAAK,EACV,kCAAkC,EAClC,wBAAwB,EACxB,sBAAsB,EACvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAGrE,mFAAmF;AACnF,qBAAa,oCACX,YAAW,kCAAkC,EAAE,wBAAwB;IAE3D,OAAO,CAAC,QAAQ,CAAC,EAAE;IAA/B,YAA6B,EAAE,EAAE,aAAa,EAAI;IAE5C,cAAc,CAAC,KAAK,EAAE;QAC1B,QAAQ,CAAC,iBAAiB,EAAE,SAAS,MAAM,EAAE,CAAC;KAC/C,GAAG,OAAO,CAAC,SAAS,sBAAsB,EAAE,CAAC,CA0B7C;IAED;;;;;OAKG;IACG,gBAAgB,CACpB,SAAS,EAAE,SAAS;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;KAAE,EAAE,GACnE,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAgB9B;IAEK,WAAW,CAAC,KAAK,EAAE;QACvB,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,CAiBhB;CACF"}
|