@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,64 @@
|
|
|
1
|
+
import { and, eq, inArray, isNull } from "drizzle-orm";
|
|
2
|
+
import { authorizationOutbox } from "./access-changes.tables.js";
|
|
3
|
+
/** Scoped completion reads and explicit failed-fact retry; never settles facts. */
|
|
4
|
+
export class PostgresAccessChangeCompletionStatus {
|
|
5
|
+
db;
|
|
6
|
+
constructor(db) {
|
|
7
|
+
this.db = db;
|
|
8
|
+
}
|
|
9
|
+
async readUnfinished(input) {
|
|
10
|
+
if (input.ownerPartitionIds.length === 0)
|
|
11
|
+
return [];
|
|
12
|
+
const rows = await this.db
|
|
13
|
+
.select({
|
|
14
|
+
idempotencyKey: authorizationOutbox.idempotencyKey,
|
|
15
|
+
ownerPartitionId: authorizationOutbox.ownerPartitionId,
|
|
16
|
+
status: authorizationOutbox.status,
|
|
17
|
+
})
|
|
18
|
+
.from(authorizationOutbox)
|
|
19
|
+
.where(and(inArray(authorizationOutbox.ownerPartitionId, [...input.ownerPartitionIds]), inArray(authorizationOutbox.status, ["PENDING", "FAILED"])))
|
|
20
|
+
.orderBy(authorizationOutbox.enqueuedAt, authorizationOutbox.id);
|
|
21
|
+
return rows.map((row) => {
|
|
22
|
+
if (row.ownerPartitionId === null || (row.status !== "PENDING" && row.status !== "FAILED")) {
|
|
23
|
+
throw new Error("Completion query returned a fact outside its scope");
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
...row,
|
|
27
|
+
ownerPartitionId: row.ownerPartitionId,
|
|
28
|
+
status: row.status,
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The named resources that still have a PENDING fact, a write or delete
|
|
34
|
+
* not yet projected to the graph, as `type:id`. A FAILED fact has stopped
|
|
35
|
+
* retrying, so it does not count: a caller waiting on it would wait for
|
|
36
|
+
* good. One query.
|
|
37
|
+
*/
|
|
38
|
+
async pendingResources(resources) {
|
|
39
|
+
if (resources.length === 0)
|
|
40
|
+
return new Set();
|
|
41
|
+
const named = new Set(resources.map(resourceKey));
|
|
42
|
+
const rows = await this.db
|
|
43
|
+
.selectDistinct({
|
|
44
|
+
type: authorizationOutbox.resourceType,
|
|
45
|
+
id: authorizationOutbox.resourceId,
|
|
46
|
+
})
|
|
47
|
+
.from(authorizationOutbox)
|
|
48
|
+
.where(and(eq(authorizationOutbox.status, "PENDING"), inArray(authorizationOutbox.resourceId, [...new Set(resources.map((resource) => resource.id))])));
|
|
49
|
+
return new Set(rows.map(resourceKey).filter((key) => named.has(key)));
|
|
50
|
+
}
|
|
51
|
+
async retryFailed(input) {
|
|
52
|
+
input.lease.assertPartition(input.ownerPartitionId);
|
|
53
|
+
if (input.idempotencyKeys.length === 0)
|
|
54
|
+
return;
|
|
55
|
+
await this.db
|
|
56
|
+
.update(authorizationOutbox)
|
|
57
|
+
.set({ status: "PENDING", attempts: 0, lastError: null })
|
|
58
|
+
.where(and(eq(authorizationOutbox.ownerPartitionId, input.ownerPartitionId), inArray(authorizationOutbox.idempotencyKey, [...input.idempotencyKeys]), eq(authorizationOutbox.status, "FAILED"), isNull(authorizationOutbox.lockedBy), isNull(authorizationOutbox.lockedAt), isNull(authorizationOutbox.supersededAt), isNull(authorizationOutbox.supersededByIdempotencyKey)));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function resourceKey(resource) {
|
|
62
|
+
return `${resource.type}:${resource.id}`;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=completion-status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"completion-status.js","sourceRoot":"","sources":["../../../../src/lib/access-changes/postgres/completion-status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAUvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,mFAAmF;AACnF,MAAM,OAAO,oCAAoC;IAGlB,EAAE;IAA/B,YAA6B,EAAiB;kBAAjB,EAAE;IAAkB,CAAC;IAElD,KAAK,CAAC,cAAc,CAAC,KAEpB;QACC,IAAI,KAAK,CAAC,iBAAiB,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,EAAE,CAAC;QACpD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,EAAE;aACvB,MAAM,CAAC;YACN,cAAc,EAAE,mBAAmB,CAAC,cAAc;YAClD,gBAAgB,EAAE,mBAAmB,CAAC,gBAAgB;YACtD,MAAM,EAAE,mBAAmB,CAAC,MAAM;SACnC,CAAC;aACD,IAAI,CAAC,mBAAmB,CAAC;aACzB,KAAK,CACJ,GAAG,CACD,OAAO,CAAC,mBAAmB,CAAC,gBAAgB,EAAE,CAAC,GAAG,KAAK,CAAC,iBAAiB,CAAC,CAAC,EAC3E,OAAO,CAAC,mBAAmB,CAAC,MAAM,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAC3D,CACF;aACA,OAAO,CAAC,mBAAmB,CAAC,UAAU,EAAE,mBAAmB,CAAC,EAAE,CAAC,CAAC;QACnE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;YACtB,IAAI,GAAG,CAAC,gBAAgB,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,KAAK,SAAS,IAAI,GAAG,CAAC,MAAM,KAAK,QAAQ,CAAC,EAAE,CAAC;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AAK,CAAC;YAAE,OAAO;QAC/C,MAAM,IAAI,CAAC,EAAE;aACV,MAAM,CAAC,mBAAmB,CAAC;aAC3B,GAAG,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;aACxD,KAAK,CACJ,GAAG,CACD,EAAE,CAAC,mBAAmB,CAAC,gBAAgB,EAAE,KAAK,CAAC,gBAAgB,CAAC,EAChE,OAAO,CAAC,mBAAmB,CAAC,cAAc,EAAE,CAAC,GAAG,KAAK,CAAC,eAAe,CAAC,CAAC,EACvE,EAAE,CAAC,mBAAmB,CAAC,MAAM,EAAE,QAAQ,CAAC,EACxC,MAAM,CAAC,mBAAmB,CAAC,QAAQ,CAAC,EACpC,MAAM,CAAC,mBAAmB,CAAC,QAAQ,CAAC,EACpC,MAAM,CAAC,mBAAmB,CAAC,YAAY,CAAC,EACxC,MAAM,CAAC,mBAAmB,CAAC,0BAA0B,CAAC,CACvD,CACF,CAAC;IACN,CAAC;CACF;AAED,SAAS,WAAW,CAAC,QAAwD;IAC3E,OAAO,GAAG,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,EAAE,EAAE,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { DrizzleHandle } from "@dads-framework/postgres";
|
|
2
|
+
import type { EnqueueAccessChanges } from "../enqueue.js";
|
|
3
|
+
import { type AccessChange, type OutboxTx } from "../enqueue.js";
|
|
4
|
+
import type { OwnerLockLease } from "@dads-framework/access/runtime";
|
|
5
|
+
/**
|
|
6
|
+
* Postgres adapter for the outbox seam. Ordinary producers only insert. The
|
|
7
|
+
* explicit replacement path is the single exception: a single-source
|
|
8
|
+
* lifecycle writer holding the matching partition lease may terminally
|
|
9
|
+
* supersede older exact opposite facts in the same transaction that records
|
|
10
|
+
* their replacement facts.
|
|
11
|
+
*
|
|
12
|
+
* `onConflictDoNothing` on `idempotency_key` is deliberate and load-bearing: a
|
|
13
|
+
* retried transaction re-enqueuing the same fact must be a no-op rather than a
|
|
14
|
+
* unique-violation that fails the state change it was recording. The key is
|
|
15
|
+
* derived from the cause (see `outboxKeyForRelationship`), so "the same fact"
|
|
16
|
+
* means the same logical change, not merely the same tuple.
|
|
17
|
+
*/
|
|
18
|
+
export declare class PostgresEnqueueAccessChanges implements EnqueueAccessChanges {
|
|
19
|
+
private readonly db;
|
|
20
|
+
constructor(db: DrizzleHandle);
|
|
21
|
+
/**
|
|
22
|
+
* The handle a fact with no row of its own uses. One multi-row insert is
|
|
23
|
+
* already atomic, so this needs no explicit transaction — and the database
|
|
24
|
+
* stays here in the adapter, which is the point.
|
|
25
|
+
*/
|
|
26
|
+
append(entries: readonly AccessChange[]): Promise<void>;
|
|
27
|
+
enqueue(entries: readonly AccessChange[], tx: OutboxTx): Promise<void>;
|
|
28
|
+
enqueueReplacingOpposite(entries: readonly AccessChange[], tx: OutboxTx, lease: OwnerLockLease): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=enqueue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enqueue.d.ts","sourceRoot":"","sources":["../../../../src/lib/access-changes/postgres/enqueue.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAI9D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAGrE;;;;;;;;;;;;GAYG;AACH,qBAAa,4BAA6B,YAAW,oBAAoB;IAC3D,OAAO,CAAC,QAAQ,CAAC,EAAE;IAA/B,YAA6B,EAAE,EAAE,aAAa,EAAI;IAElD;;;;OAIG;IACG,MAAM,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAE5D;IAEK,OAAO,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,EAAE,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAwB3E;IAEK,wBAAwB,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAuCnH;CACF"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { and, eq, inArray, isNull } from "drizzle-orm";
|
|
2
|
+
import { mintEntityId } from "@dads-framework/core/contract";
|
|
3
|
+
import { accessChangeIdSchema } from "../access-change.ids.js";
|
|
4
|
+
import {} from "../enqueue.js";
|
|
5
|
+
import { authorizationOutbox } from "./access-changes.tables.js";
|
|
6
|
+
/**
|
|
7
|
+
* Postgres adapter for the outbox seam. Ordinary producers only insert. The
|
|
8
|
+
* explicit replacement path is the single exception: a single-source
|
|
9
|
+
* lifecycle writer holding the matching partition lease may terminally
|
|
10
|
+
* supersede older exact opposite facts in the same transaction that records
|
|
11
|
+
* their replacement facts.
|
|
12
|
+
*
|
|
13
|
+
* `onConflictDoNothing` on `idempotency_key` is deliberate and load-bearing: a
|
|
14
|
+
* retried transaction re-enqueuing the same fact must be a no-op rather than a
|
|
15
|
+
* unique-violation that fails the state change it was recording. The key is
|
|
16
|
+
* derived from the cause (see `outboxKeyForRelationship`), so "the same fact"
|
|
17
|
+
* means the same logical change, not merely the same tuple.
|
|
18
|
+
*/
|
|
19
|
+
export class PostgresEnqueueAccessChanges {
|
|
20
|
+
db;
|
|
21
|
+
constructor(db) {
|
|
22
|
+
this.db = db;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The handle a fact with no row of its own uses. One multi-row insert is
|
|
26
|
+
* already atomic, so this needs no explicit transaction — and the database
|
|
27
|
+
* stays here in the adapter, which is the point.
|
|
28
|
+
*/
|
|
29
|
+
async append(entries) {
|
|
30
|
+
await this.enqueue(entries, this.db);
|
|
31
|
+
}
|
|
32
|
+
async enqueue(entries, tx) {
|
|
33
|
+
if (entries.length === 0)
|
|
34
|
+
return;
|
|
35
|
+
const enqueuedAt = new Date();
|
|
36
|
+
await tx
|
|
37
|
+
.insert(authorizationOutbox)
|
|
38
|
+
.values(entries.map((entry) => ({
|
|
39
|
+
id: mintEntityId(accessChangeIdSchema),
|
|
40
|
+
idempotencyKey: entry.idempotencyKey,
|
|
41
|
+
operation: entry.operation,
|
|
42
|
+
resourceType: entry.relationship.resource.type,
|
|
43
|
+
resourceId: entry.relationship.resource.id,
|
|
44
|
+
relation: entry.relationship.relation,
|
|
45
|
+
subjectType: entry.relationship.subject.type,
|
|
46
|
+
subjectId: entry.relationship.subject.id,
|
|
47
|
+
subjectRelation: entry.relationship.subject.relation ?? null,
|
|
48
|
+
ownerPartitionId: entry.ownerPartitionId,
|
|
49
|
+
status: "PENDING",
|
|
50
|
+
enqueuedAt,
|
|
51
|
+
})))
|
|
52
|
+
.onConflictDoNothing({
|
|
53
|
+
target: authorizationOutbox.idempotencyKey,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
async enqueueReplacingOpposite(entries, tx, lease) {
|
|
57
|
+
if (entries.length === 0)
|
|
58
|
+
return;
|
|
59
|
+
if (entries.some((entry) => entry.ownerPartitionId === null)) {
|
|
60
|
+
throw new Error("replacement facts require an owner partition");
|
|
61
|
+
}
|
|
62
|
+
for (const entry of entries) {
|
|
63
|
+
lease.assertPartition(requireOwnerPartition(entry));
|
|
64
|
+
}
|
|
65
|
+
const supersededAt = new Date();
|
|
66
|
+
for (const entry of entries) {
|
|
67
|
+
const { resource, relation, subject } = entry.relationship;
|
|
68
|
+
const ownerPartitionId = requireOwnerPartition(entry);
|
|
69
|
+
await tx
|
|
70
|
+
.update(authorizationOutbox)
|
|
71
|
+
.set({
|
|
72
|
+
status: "SUPERSEDED",
|
|
73
|
+
lockedBy: null,
|
|
74
|
+
lockedAt: null,
|
|
75
|
+
lastError: null,
|
|
76
|
+
supersededAt,
|
|
77
|
+
supersededByIdempotencyKey: entry.idempotencyKey,
|
|
78
|
+
})
|
|
79
|
+
.where(and(eq(authorizationOutbox.operation, entry.operation === "WRITE" ? "DELETE" : "WRITE"), eq(authorizationOutbox.resourceType, resource.type), eq(authorizationOutbox.resourceId, resource.id), eq(authorizationOutbox.relation, relation), eq(authorizationOutbox.subjectType, subject.type), eq(authorizationOutbox.subjectId, subject.id), subject.relation === undefined
|
|
80
|
+
? isNull(authorizationOutbox.subjectRelation)
|
|
81
|
+
: eq(authorizationOutbox.subjectRelation, subject.relation), eq(authorizationOutbox.ownerPartitionId, ownerPartitionId), inArray(authorizationOutbox.status, ["PENDING", "FAILED"])));
|
|
82
|
+
}
|
|
83
|
+
await this.enqueue(entries, tx);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function requireOwnerPartition(entry) {
|
|
87
|
+
if (entry.ownerPartitionId === null) {
|
|
88
|
+
throw new Error("replacement facts require an owner partition");
|
|
89
|
+
}
|
|
90
|
+
return entry.ownerPartitionId;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=enqueue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enqueue.js","sourceRoot":"","sources":["../../../../src/lib/access-changes/postgres/enqueue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGvD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE/D,OAAO,EAAoC,MAAM,eAAe,CAAC;AAEjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,4BAA4B;IACV,EAAE;IAA/B,YAA6B,EAAiB;kBAAjB,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AC,mBAAmB,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC,EAC7C,OAAO,CAAC,QAAQ,KAAK,SAAS;gBAC5B,CAAC,CAAC,MAAM,CAAC,mBAAmB,CAAC,eAAe,CAAC;gBAC7C,CAAC,CAAC,EAAE,CAAC,mBAAmB,CAAC,eAAe,EAAE,OAAO,CAAC,QAAQ,CAAC,EAC7D,EAAE,CAAC,mBAAmB,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,EAC1D,OAAO,CAAC,mBAAmB,CAAC,MAAM,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAC3D,CACF,CAAC;QACN,CAAC;QACD,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAClC,CAAC;CACF;AAED,SAAS,qBAAqB,CAAC,KAAmB;IAChD,IAAI,KAAK,CAAC,gBAAgB,KAAK,IAAI,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,KAAK,CAAC,gBAAgB,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"20260828163001_authorization_outbox.migration.d.ts","sourceRoot":"","sources":["../../../../../src/lib/access-changes/postgres/migrations/20260828163001_authorization_outbox.migration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,wBAAgB,EAAE,CAAC,GAAG,EAAE,gBAAgB,GAAG,IAAI,CA0C9C;AAED,wBAAgB,IAAI,CAAC,GAAG,EAAE,gBAAgB,GAAG,IAAI,CAEhD"}
|
package/dist/lib/access-changes/postgres/migrations/20260828163001_authorization_outbox.migration.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export function up(pgm) {
|
|
2
|
+
pgm.createTable("authorization_outbox", {
|
|
3
|
+
id: {
|
|
4
|
+
type: "uuid",
|
|
5
|
+
primaryKey: true,
|
|
6
|
+
notNull: true,
|
|
7
|
+
default: pgm.func("gen_random_uuid()"),
|
|
8
|
+
},
|
|
9
|
+
idempotency_key: { type: "text", notNull: true },
|
|
10
|
+
operation: { type: "text", notNull: true },
|
|
11
|
+
resource_type: { type: "text", notNull: true },
|
|
12
|
+
resource_id: { type: "text", notNull: true },
|
|
13
|
+
relation: { type: "text", notNull: true },
|
|
14
|
+
subject_type: { type: "text", notNull: true },
|
|
15
|
+
subject_id: { type: "text", notNull: true },
|
|
16
|
+
subject_relation: { type: "text" },
|
|
17
|
+
owner_partition_id: { type: "uuid" },
|
|
18
|
+
status: { type: "text", notNull: true },
|
|
19
|
+
attempts: { type: "integer", notNull: true, default: 0 },
|
|
20
|
+
locked_by: { type: "text" },
|
|
21
|
+
locked_at: { type: "timestamptz" },
|
|
22
|
+
last_error: { type: "text" },
|
|
23
|
+
enqueued_at: { type: "timestamptz", notNull: true },
|
|
24
|
+
projected_at: { type: "timestamptz" },
|
|
25
|
+
superseded_at: { type: "timestamptz" },
|
|
26
|
+
superseded_by_idempotency_key: { type: "text" },
|
|
27
|
+
});
|
|
28
|
+
pgm.addConstraint("authorization_outbox", "authorization_outbox_supersession_check", "CHECK ((((status = 'SUPERSEDED'::text) AND (superseded_at IS NOT NULL) AND (superseded_by_idempotency_key IS NOT NULL) AND (last_error IS NULL)) OR ((status <> 'SUPERSEDED'::text) AND (superseded_at IS NULL) AND (superseded_by_idempotency_key IS NULL))))");
|
|
29
|
+
pgm.createIndex("authorization_outbox", ["idempotency_key"], {
|
|
30
|
+
name: "authorization_outbox_idempotency_uidx",
|
|
31
|
+
unique: true,
|
|
32
|
+
});
|
|
33
|
+
pgm.createIndex("authorization_outbox", ["owner_partition_id"], {
|
|
34
|
+
name: "authorization_outbox_partition_idx",
|
|
35
|
+
});
|
|
36
|
+
pgm.createIndex("authorization_outbox", ["status", "enqueued_at"], {
|
|
37
|
+
name: "authorization_outbox_status_enqueued_idx",
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
export function down(pgm) {
|
|
41
|
+
pgm.dropTable("authorization_outbox");
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=20260828163001_authorization_outbox.migration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"20260828163001_authorization_outbox.migration.js","sourceRoot":"","sources":["../../../../../src/lib/access-changes/postgres/migrations/20260828163001_authorization_outbox.migration.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,EAAE,CAAC,GAAqB;IACtC,GAAG,CAAC,WAAW,CAAC,sBAAsB,EAAE;QACtC,EAAE,EAAE;YACF,IAAI,EAAE,MAAM;YACZ,UAAU,EAAE,IAAI;YAChB,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,GAAG,CAAC,IAAI,CAAC,mBAAmB,CAAC;SACvC;QACD,eAAe,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;QAChD,SAAS,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;QAC1C,aAAa,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;QAC9C,WAAW,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;QAC5C,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;QACzC,YAAY,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;QAC7C,UAAU,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;QAC3C,gBAAgB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;QAClC,kBAAkB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;QACpC,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;QACvC,QAAQ,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE;QACxD,SAAS,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;QAC3B,SAAS,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE;QAClC,UAAU,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;QAC5B,WAAW,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,IAAI,EAAE;QACnD,YAAY,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE;QACrC,aAAa,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE;QACtC,6BAA6B,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;KAChD,CAAC,CAAC;IACH,GAAG,CAAC,aAAa,CACf,sBAAsB,EACtB,yCAAyC,EACzC,gQAAgQ,CACjQ,CAAC;IACF,GAAG,CAAC,WAAW,CAAC,sBAAsB,EAAE,CAAC,iBAAiB,CAAC,EAAE;QAC3D,IAAI,EAAE,uCAAuC;QAC7C,MAAM,EAAE,IAAI;KACb,CAAC,CAAC;IACH,GAAG,CAAC,WAAW,CAAC,sBAAsB,EAAE,CAAC,oBAAoB,CAAC,EAAE;QAC9D,IAAI,EAAE,oCAAoC;KAC3C,CAAC,CAAC;IACH,GAAG,CAAC,WAAW,CAAC,sBAAsB,EAAE,CAAC,QAAQ,EAAE,aAAa,CAAC,EAAE;QACjE,IAAI,EAAE,0CAA0C;KACjD,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,GAAqB;IACxC,GAAG,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { OwnerLock } from "@dads-framework/access/runtime";
|
|
2
|
+
type AuthorizationLockClient = {
|
|
3
|
+
query(statement: string, values: readonly unknown[]): Promise<{
|
|
4
|
+
readonly rows: readonly Record<string, unknown>[];
|
|
5
|
+
}>;
|
|
6
|
+
release(destroy?: boolean): void;
|
|
7
|
+
};
|
|
8
|
+
type AuthorizationLockPool = {
|
|
9
|
+
readonly options?: {
|
|
10
|
+
readonly max?: number;
|
|
11
|
+
};
|
|
12
|
+
connect(): Promise<AuthorizationLockClient>;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Connections a flow's first lock must leave to non-lock work. A lock holder
|
|
16
|
+
* keeps its lock connection while its operation checks out another, so lock
|
|
17
|
+
* holders (this lock's, the participant coordinator's, a site's puller and
|
|
18
|
+
* outbox sender) must never own the whole pool between them: each would wait
|
|
19
|
+
* on the others for a connection, for good.
|
|
20
|
+
*
|
|
21
|
+
* Only connections held FOR LOCKS count. Plain queries and callers queued in
|
|
22
|
+
* pg's own FIFO are ignored: they release on their own, so they cannot close
|
|
23
|
+
* that cycle, and counting them would turn ordinary load into refused access
|
|
24
|
+
* writes. A lock taken NESTED, on a call path that already holds a lock
|
|
25
|
+
* connection, is not a new flow (the outer holder is waiting on it), so it
|
|
26
|
+
* leaves only {@link NESTED_LOCK_HOLDER_FREE_CONNECTIONS}.
|
|
27
|
+
*/
|
|
28
|
+
export declare const LOCK_HOLDER_FREE_CONNECTIONS = 2;
|
|
29
|
+
/** What a lock nested inside another lock on the same call path leaves free. */
|
|
30
|
+
export declare const NESTED_LOCK_HOLDER_FREE_CONNECTIONS = 1;
|
|
31
|
+
/** The pool a lock connection is reserved against; only its size is read. */
|
|
32
|
+
export type LockConnectionPool = {
|
|
33
|
+
readonly options?: {
|
|
34
|
+
readonly max?: number;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Runs `operation` marked as holding a lock connection, so a lock taken
|
|
39
|
+
* inside it reserves as nested ({@link reserveLockConnection}). Every lock
|
|
40
|
+
* that keeps a pooled connection while its operation runs calls this around
|
|
41
|
+
* that operation.
|
|
42
|
+
*/
|
|
43
|
+
export declare function runHoldingLockConnection<T>(operation: () => Promise<T>): Promise<T>;
|
|
44
|
+
/**
|
|
45
|
+
* Reserves one of `pool`'s connections for a lock holder, before it checks
|
|
46
|
+
* the connection out, or answers null when lock holders would then hold more
|
|
47
|
+
* than `max - LOCK_HOLDER_FREE_CONNECTIONS` (`max - 1` when nested; never
|
|
48
|
+
* fewer than one). The answer releases the reservation; call it once the
|
|
49
|
+
* lock's connection is back in the pool. A pool that reports no `max` is
|
|
50
|
+
* not limited, only counted.
|
|
51
|
+
*/
|
|
52
|
+
export declare function reserveLockConnection(pool: LockConnectionPool): (() => void) | null;
|
|
53
|
+
type CoordinatorLog = {
|
|
54
|
+
warn(value: object, message?: string): void;
|
|
55
|
+
};
|
|
56
|
+
type CoordinatorOptions = {
|
|
57
|
+
readonly acquisitionTimeoutMs?: number;
|
|
58
|
+
readonly retryDelayMs?: number;
|
|
59
|
+
readonly maxConcurrentLockClients?: number;
|
|
60
|
+
readonly now?: () => number;
|
|
61
|
+
readonly delay?: (milliseconds: number) => Promise<void>;
|
|
62
|
+
readonly log?: CoordinatorLog;
|
|
63
|
+
};
|
|
64
|
+
/** Holds a partition session lock on one dedicated pooled client. */
|
|
65
|
+
export declare class PostgresOwnerLock extends OwnerLock {
|
|
66
|
+
private readonly pool;
|
|
67
|
+
private readonly acquisitionTimeoutMs;
|
|
68
|
+
private readonly retryDelayMs;
|
|
69
|
+
private readonly maxConcurrentLockClients;
|
|
70
|
+
private readonly now;
|
|
71
|
+
private readonly delay;
|
|
72
|
+
private readonly log;
|
|
73
|
+
private activePermits;
|
|
74
|
+
constructor(pool: AuthorizationLockPool, options?: CoordinatorOptions);
|
|
75
|
+
protected runLocked<T>(ownerPartitionId: string, operation: () => Promise<T>): Promise<T>;
|
|
76
|
+
private acquire;
|
|
77
|
+
private tryAcquire;
|
|
78
|
+
private tryLock;
|
|
79
|
+
private release;
|
|
80
|
+
private tryAcquirePermit;
|
|
81
|
+
private connectWithin;
|
|
82
|
+
private waitForRetry;
|
|
83
|
+
}
|
|
84
|
+
export {};
|
|
85
|
+
//# sourceMappingURL=owner-lock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
|
|
|
1
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
2
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
|
+
import { conflict } from "@dads-framework/core/errors";
|
|
4
|
+
import { OwnerLock } from "@dads-framework/access/runtime";
|
|
5
|
+
const AUTHORIZATION_PARTITION_LOCK_NAMESPACE = 719_405;
|
|
6
|
+
const DEFAULT_ACQUISITION_TIMEOUT_MS = 2_000;
|
|
7
|
+
const DEFAULT_RETRY_DELAY_MS = 10;
|
|
8
|
+
/**
|
|
9
|
+
* Connections a flow's first lock must leave to non-lock work. A lock holder
|
|
10
|
+
* keeps its lock connection while its operation checks out another, so lock
|
|
11
|
+
* holders (this lock's, the participant coordinator's, a site's puller and
|
|
12
|
+
* outbox sender) must never own the whole pool between them: each would wait
|
|
13
|
+
* on the others for a connection, for good.
|
|
14
|
+
*
|
|
15
|
+
* Only connections held FOR LOCKS count. Plain queries and callers queued in
|
|
16
|
+
* pg's own FIFO are ignored: they release on their own, so they cannot close
|
|
17
|
+
* that cycle, and counting them would turn ordinary load into refused access
|
|
18
|
+
* writes. A lock taken NESTED, on a call path that already holds a lock
|
|
19
|
+
* connection, is not a new flow (the outer holder is waiting on it), so it
|
|
20
|
+
* leaves only {@link NESTED_LOCK_HOLDER_FREE_CONNECTIONS}.
|
|
21
|
+
*/
|
|
22
|
+
export const LOCK_HOLDER_FREE_CONNECTIONS = 2;
|
|
23
|
+
/** What a lock nested inside another lock on the same call path leaves free. */
|
|
24
|
+
export const NESTED_LOCK_HOLDER_FREE_CONNECTIONS = 1;
|
|
25
|
+
const lockConnectionHeldOnThisPath = new AsyncLocalStorage();
|
|
26
|
+
/** Per pool object: how many of its connections lock holders hold right now. */
|
|
27
|
+
const lockConnectionsHeld = new WeakMap();
|
|
28
|
+
/**
|
|
29
|
+
* Runs `operation` marked as holding a lock connection, so a lock taken
|
|
30
|
+
* inside it reserves as nested ({@link reserveLockConnection}). Every lock
|
|
31
|
+
* that keeps a pooled connection while its operation runs calls this around
|
|
32
|
+
* that operation.
|
|
33
|
+
*/
|
|
34
|
+
export function runHoldingLockConnection(operation) {
|
|
35
|
+
return lockConnectionHeldOnThisPath.run(true, operation);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Reserves one of `pool`'s connections for a lock holder, before it checks
|
|
39
|
+
* the connection out, or answers null when lock holders would then hold more
|
|
40
|
+
* than `max - LOCK_HOLDER_FREE_CONNECTIONS` (`max - 1` when nested; never
|
|
41
|
+
* fewer than one). The answer releases the reservation; call it once the
|
|
42
|
+
* lock's connection is back in the pool. A pool that reports no `max` is
|
|
43
|
+
* not limited, only counted.
|
|
44
|
+
*/
|
|
45
|
+
export function reserveLockConnection(pool) {
|
|
46
|
+
const held = lockConnectionsHeld.get(pool) ?? 0;
|
|
47
|
+
const max = pool.options?.max;
|
|
48
|
+
if (max !== undefined) {
|
|
49
|
+
const leaveFree = lockConnectionHeldOnThisPath.getStore() === true
|
|
50
|
+
? NESTED_LOCK_HOLDER_FREE_CONNECTIONS
|
|
51
|
+
: LOCK_HOLDER_FREE_CONNECTIONS;
|
|
52
|
+
if (held + 1 > Math.max(1, max - leaveFree))
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
lockConnectionsHeld.set(pool, held + 1);
|
|
56
|
+
let released = false;
|
|
57
|
+
return () => {
|
|
58
|
+
if (released)
|
|
59
|
+
return;
|
|
60
|
+
released = true;
|
|
61
|
+
lockConnectionsHeld.set(pool, (lockConnectionsHeld.get(pool) ?? 1) - 1);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const SILENT_LOG = { warn: () => undefined };
|
|
65
|
+
/** Holds a partition session lock on one dedicated pooled client. */
|
|
66
|
+
export class PostgresOwnerLock extends OwnerLock {
|
|
67
|
+
pool;
|
|
68
|
+
acquisitionTimeoutMs;
|
|
69
|
+
retryDelayMs;
|
|
70
|
+
maxConcurrentLockClients;
|
|
71
|
+
now;
|
|
72
|
+
delay;
|
|
73
|
+
log;
|
|
74
|
+
activePermits = 0;
|
|
75
|
+
constructor(pool, options = {}) {
|
|
76
|
+
super();
|
|
77
|
+
this.pool = pool;
|
|
78
|
+
this.acquisitionTimeoutMs = options.acquisitionTimeoutMs ?? DEFAULT_ACQUISITION_TIMEOUT_MS;
|
|
79
|
+
this.retryDelayMs = options.retryDelayMs ?? DEFAULT_RETRY_DELAY_MS;
|
|
80
|
+
const poolMaximum = pool.options?.max ?? 3;
|
|
81
|
+
this.maxConcurrentLockClients = options.maxConcurrentLockClients ?? Math.max(1, poolMaximum - 2);
|
|
82
|
+
this.now = options.now ?? Date.now;
|
|
83
|
+
this.delay = options.delay ?? sleep;
|
|
84
|
+
this.log = options.log ?? SILENT_LOG;
|
|
85
|
+
}
|
|
86
|
+
async runLocked(ownerPartitionId, operation) {
|
|
87
|
+
const acquired = await this.acquire(ownerPartitionId);
|
|
88
|
+
try {
|
|
89
|
+
return await runHoldingLockConnection(operation);
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
await this.release(acquired, ownerPartitionId);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async acquire(ownerPartitionId) {
|
|
96
|
+
const deadline = this.now() + this.acquisitionTimeoutMs;
|
|
97
|
+
while (this.now() <= deadline) {
|
|
98
|
+
const acquired = await this.tryAcquire(ownerPartitionId, deadline);
|
|
99
|
+
if (acquired !== null)
|
|
100
|
+
return acquired;
|
|
101
|
+
await this.waitForRetry(deadline);
|
|
102
|
+
}
|
|
103
|
+
throw acquisitionTimeout();
|
|
104
|
+
}
|
|
105
|
+
async tryAcquire(ownerPartitionId, deadline) {
|
|
106
|
+
const releasePermit = this.tryAcquirePermit();
|
|
107
|
+
if (releasePermit === null)
|
|
108
|
+
return null;
|
|
109
|
+
let client;
|
|
110
|
+
try {
|
|
111
|
+
client = await this.connectWithin(deadline);
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
releasePermit();
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
return this.tryLock(client, releasePermit, ownerPartitionId);
|
|
118
|
+
}
|
|
119
|
+
async tryLock(client, releasePermit, ownerPartitionId) {
|
|
120
|
+
try {
|
|
121
|
+
const result = await client.query("select pg_try_advisory_lock(hashtextextended($1, $2)) as acquired", [
|
|
122
|
+
ownerPartitionId,
|
|
123
|
+
AUTHORIZATION_PARTITION_LOCK_NAMESPACE,
|
|
124
|
+
]);
|
|
125
|
+
if (result.rows[0]?.["acquired"] === true) {
|
|
126
|
+
return { client, releasePermit };
|
|
127
|
+
}
|
|
128
|
+
client.release();
|
|
129
|
+
releasePermit();
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
client.release(true);
|
|
134
|
+
releasePermit();
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async release(acquired, ownerPartitionId) {
|
|
139
|
+
let unlockFailure = null;
|
|
140
|
+
try {
|
|
141
|
+
const result = await acquired.client.query("select pg_advisory_unlock(hashtextextended($1, $2)) as unlocked", [
|
|
142
|
+
ownerPartitionId,
|
|
143
|
+
AUTHORIZATION_PARTITION_LOCK_NAMESPACE,
|
|
144
|
+
]);
|
|
145
|
+
if (result.rows[0]?.["unlocked"] !== true) {
|
|
146
|
+
unlockFailure = new Error("authorization partition lock was not held");
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
unlockFailure = normalizeError(error);
|
|
151
|
+
}
|
|
152
|
+
acquired.client.release(unlockFailure !== null);
|
|
153
|
+
acquired.releasePermit();
|
|
154
|
+
if (unlockFailure !== null) {
|
|
155
|
+
this.log.warn({ ownerPartitionId, error: unlockFailure.message }, "Authorization partition unlock failed; destroyed session");
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
tryAcquirePermit() {
|
|
159
|
+
if (this.activePermits >= this.maxConcurrentLockClients)
|
|
160
|
+
return null;
|
|
161
|
+
const releaseReservation = reserveLockConnection(this.pool);
|
|
162
|
+
if (releaseReservation === null)
|
|
163
|
+
return null;
|
|
164
|
+
this.activePermits += 1;
|
|
165
|
+
let released = false;
|
|
166
|
+
return () => {
|
|
167
|
+
if (released)
|
|
168
|
+
return;
|
|
169
|
+
released = true;
|
|
170
|
+
this.activePermits -= 1;
|
|
171
|
+
releaseReservation();
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
connectWithin(deadline) {
|
|
175
|
+
const remaining = deadline - this.now();
|
|
176
|
+
if (remaining <= 0)
|
|
177
|
+
return Promise.reject(acquisitionTimeout());
|
|
178
|
+
return connectBefore(this.pool.connect(), remaining);
|
|
179
|
+
}
|
|
180
|
+
async waitForRetry(deadline) {
|
|
181
|
+
const remaining = deadline - this.now();
|
|
182
|
+
if (remaining <= 0)
|
|
183
|
+
throw acquisitionTimeout();
|
|
184
|
+
await this.delay(Math.min(this.retryDelayMs, remaining));
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function connectBefore(connection, timeoutMs) {
|
|
188
|
+
return new Promise((resolve, reject) => {
|
|
189
|
+
let settled = false;
|
|
190
|
+
const timeout = setTimeout(() => {
|
|
191
|
+
settled = true;
|
|
192
|
+
reject(acquisitionTimeout());
|
|
193
|
+
}, timeoutMs);
|
|
194
|
+
const accept = (client) => {
|
|
195
|
+
if (settled) {
|
|
196
|
+
client.release();
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
settled = true;
|
|
200
|
+
clearTimeout(timeout);
|
|
201
|
+
resolve(client);
|
|
202
|
+
};
|
|
203
|
+
const refuse = (error) => {
|
|
204
|
+
if (settled)
|
|
205
|
+
return;
|
|
206
|
+
settled = true;
|
|
207
|
+
clearTimeout(timeout);
|
|
208
|
+
reject(normalizeError(error));
|
|
209
|
+
};
|
|
210
|
+
connection.then(accept, refuse);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
function acquisitionTimeout() {
|
|
214
|
+
return conflict("AUTHORIZATION_PARTITION_BUSY", "Authorization partition is temporarily busy");
|
|
215
|
+
}
|
|
216
|
+
function normalizeError(error) {
|
|
217
|
+
return error instanceof Error ? error : new Error("authorization partition operation failed");
|
|
218
|
+
}
|
|
219
|
+
//# sourceMappingURL=owner-lock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"owner-lock.js","sourceRoot":"","sources":["../../../../src/lib/access-changes/postgres/owner-lock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAE3D,MAAM,sCAAsC,GAAG,OAAO,CAAC;AACvD,MAAM,8BAA8B,GAAG,KAAK,CAAC;AAC7C,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAYlC;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAC;AAE9C,gFAAgF;AAChF,MAAM,CAAC,MAAM,mCAAmC,GAAG,CAAC,CAAC;AAOrD,MAAM,4BAA4B,GAAG,IAAI,iBAAiB,EAAQ,CAAC;AAEnE,gFAAgF;AAChF,MAAM,mBAAmB,GAAG,IAAI,OAAO,EAA8B,CAAC;AAEtE;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAAI,SAA2B;IACrE,OAAO,4BAA4B,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;AAC3D,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAwB;IAC5D,MAAM,IAAI,GAAG,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChD,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC;IAC9B,IAAI,GAAG,KA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S,kBAAkB;IACzB,OAAO,QAAQ,CAAC,8BAA8B,EAAE,6CAA6C,CAAC,CAAC;AACjG,CAAC;AAED,SAAS,cAAc,CAAC,KAAc;IACpC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;AAChG,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { DrizzleHandle } from "@dads-framework/postgres";
|
|
2
|
+
/**
|
|
3
|
+
* Gives every fact that has not reached the graph a fresh attempt budget:
|
|
4
|
+
* a FAILED fact goes back to PENDING, and a waiting PENDING fact's spent
|
|
5
|
+
* attempts are forgiven. A fact a worker holds right now is left alone. Its
|
|
6
|
+
* last error stays for the record.
|
|
7
|
+
*
|
|
8
|
+
* For an outbox with no human watching its failures (a remote instance’s
|
|
9
|
+
* graph), where FAILED must mean "not yet", never "never", and an outage of
|
|
10
|
+
* the graph must not spend a fact's attempts: the caller runs it after a
|
|
11
|
+
* drain the graph took cleanly, and after failures it has shown were the
|
|
12
|
+
* graph being unreachable. A waiting fact is never stale against a later
|
|
13
|
+
* change to its tuple, because a producer that replaces opposite facts
|
|
14
|
+
* supersedes PENDING and FAILED ones alike. Answers how many facts it reset.
|
|
15
|
+
*/
|
|
16
|
+
export declare function requeueFailedAccessChanges(db: Pick<DrizzleHandle, "update">): Promise<number>;
|
|
17
|
+
//# sourceMappingURL=requeue-failed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requeue-failed.d.ts","sourceRoot":"","sources":["../../../../src/lib/access-changes/postgres/requeue-failed.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAI9D;;;;;;;;;;;;;GAaG;AACH,wBAAsB,0BAA0B,CAAC,EAAE,EAAE,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAenG"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { and, eq, gt, isNull, or } from "drizzle-orm";
|
|
2
|
+
import { authorizationOutbox } from "./access-changes.tables.js";
|
|
3
|
+
/**
|
|
4
|
+
* Gives every fact that has not reached the graph a fresh attempt budget:
|
|
5
|
+
* a FAILED fact goes back to PENDING, and a waiting PENDING fact's spent
|
|
6
|
+
* attempts are forgiven. A fact a worker holds right now is left alone. Its
|
|
7
|
+
* last error stays for the record.
|
|
8
|
+
*
|
|
9
|
+
* For an outbox with no human watching its failures (a remote instance’s
|
|
10
|
+
* graph), where FAILED must mean "not yet", never "never", and an outage of
|
|
11
|
+
* the graph must not spend a fact's attempts: the caller runs it after a
|
|
12
|
+
* drain the graph took cleanly, and after failures it has shown were the
|
|
13
|
+
* graph being unreachable. A waiting fact is never stale against a later
|
|
14
|
+
* change to its tuple, because a producer that replaces opposite facts
|
|
15
|
+
* supersedes PENDING and FAILED ones alike. Answers how many facts it reset.
|
|
16
|
+
*/
|
|
17
|
+
export async function requeueFailedAccessChanges(db) {
|
|
18
|
+
const reset = await db
|
|
19
|
+
.update(authorizationOutbox)
|
|
20
|
+
.set({ status: "PENDING", attempts: 0 })
|
|
21
|
+
.where(and(isNull(authorizationOutbox.lockedBy), or(eq(authorizationOutbox.status, "FAILED"), and(eq(authorizationOutbox.status, "PENDING"), gt(authorizationOutbox.attempts, 0)))))
|
|
22
|
+
.returning({ id: authorizationOutbox.id });
|
|
23
|
+
return reset.length;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=requeue-failed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requeue-failed.js","sourceRoot":"","sources":["../../../../src/lib/access-changes/postgres/requeue-failed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAItD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAAC,EAAiC;IAChF,MAAM,KAAK,GAAG,MAAM,EAAE;SACnB,MAAM,CAAC,mBAAmB,CAAC;SAC3B,GAAG,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;SACvC,KAAK,CACJ,GAAG,CACD,MAAM,CAAC,mBAAmB,CAAC,QAAQ,CAAC,EACpC,EAAE,CACA,EAAE,CAAC,mBAAmB,CAAC,MAAM,EAAE,QAAQ,CAAC,EACxC,GAAG,CAAC,EAAE,CAAC,mBAAmB,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,mBAAmB,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CACpF,CACF,CACF;SACA,SAAS,CAAC,EAAE,EAAE,EAAE,mBAAmB,CAAC,EAAE,EAAE,CAAC,CAAC;IAC7C,OAAO,KAAK,CAAC,MAAM,CAAC;AACtB,CAAC"}
|