@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,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The authorization port, guarded against lists that grow without bound.
|
|
3
|
+
*
|
|
4
|
+
* A list built from "every visible id, then `WHERE id IN (...)`" is fast with
|
|
5
|
+
* ten ids and fails at sixty-five thousand, and nothing in between says so.
|
|
6
|
+
* This decorator enforces a fail-closed `lookupResources` policy and watches
|
|
7
|
+
* every answer:
|
|
8
|
+
*
|
|
9
|
+
* - **Fail-closed `lookupResources`.** `lookupResources` throws unless the
|
|
10
|
+
* compiled model explicitly lists the resource type in
|
|
11
|
+
* `allowLookupResourcesOn` (and does not bind it in `scopeBindings`) or the
|
|
12
|
+
* queried relation is declared `sparse-direct` in the record's scope
|
|
13
|
+
* bindings. Record lists use `requiresScoped`.
|
|
14
|
+
* - **Warning mark.** A lookup past `warnLookupIds` succeeds and notes a
|
|
15
|
+
* warning on the request, which the request row records as a fault.
|
|
16
|
+
* - **Hard cap.** A lookup past `maxLookupIds` fails with an error naming the
|
|
17
|
+
* resource type: a failing list is an incident with a message, a hanging
|
|
18
|
+
* one is not. The cap sits well below Postgres's 65,535-parameter limit.
|
|
19
|
+
* - **Round-trip budget.** A request whose authorization round trips pass
|
|
20
|
+
* `warnRoundTrips` notes a warning the same way: an N+1 loop of checks, not
|
|
21
|
+
* only a large list.
|
|
22
|
+
*
|
|
23
|
+
* Its own decorator rather than part of `TalliedAuthorization`: the tally
|
|
24
|
+
* promises it never changes an outcome, and this one refuses reads. It sits
|
|
25
|
+
* outside the tally (so it reads the round trips the tally just counted) and
|
|
26
|
+
* inside answer-once (so a repeated question is judged once).
|
|
27
|
+
*/
|
|
28
|
+
import { isLookupResourcesAllowed, isSparseDirectGrant } from "@dads-framework/access/scopes";
|
|
29
|
+
import { currentRequestWork, countAuthorizationLookupSize, noteAuthorizationWarning, } from "@dads-framework/core/runtime/request-work";
|
|
30
|
+
import { Authorization, checkOutcome, } from "@dads-framework/access/runtime";
|
|
31
|
+
export const DEFAULT_AUTHORIZATION_GUARD_MARKS = {
|
|
32
|
+
warnLookupIds: 1_000,
|
|
33
|
+
maxLookupIds: 10_000,
|
|
34
|
+
warnRoundTrips: 50,
|
|
35
|
+
};
|
|
36
|
+
/** Postgres refuses a statement with more bind parameters than this. */
|
|
37
|
+
const POSTGRES_PARAMETER_LIMIT = 65_535;
|
|
38
|
+
/** Apply the compiled model's fail-closed `lookupResources` policy. */
|
|
39
|
+
export function authorizationKinds(model) {
|
|
40
|
+
return {
|
|
41
|
+
mayLookup: (resourceType, permission) => isLookupResourcesAllowed(model, resourceType) || isSparseDirectGrant(model, resourceType, permission),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** A `lookupResources` on a resource type not allowed for unbounded lookup. */
|
|
45
|
+
export class RecordLookupRefusedError extends Error {
|
|
46
|
+
constructor(query) {
|
|
47
|
+
super(`lookupResources on ${query.resourceType}#${query.permission} refused: ${query.resourceType} is not in allowLookupResourcesOn ` +
|
|
48
|
+
`and ${query.permission} is not a sparse-direct scope binding; a record list must use requiresScoped and declare scope bindings ` +
|
|
49
|
+
`(docs/architecture/authorization.md, "To move a record list onto a scope plan")`);
|
|
50
|
+
this.name = "RecordLookupRefusedError";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** A `lookupResources` that returned more ids than the hard cap allows. */
|
|
54
|
+
export class LookupOverHardCapError extends Error {
|
|
55
|
+
constructor(query, idCount, maxLookupIds) {
|
|
56
|
+
super(`lookupResources on ${query.resourceType}#${query.permission} for a ${query.subject.type} returned ${idCount} ids, ` +
|
|
57
|
+
`over the ${maxLookupIds} cap (AUTHZ_LOOKUP_MAX_IDS); this list must be filtered by scope, not by every visible id`);
|
|
58
|
+
this.name = "LookupOverHardCapError";
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export class GuardedAuthorization extends Authorization {
|
|
62
|
+
#inner;
|
|
63
|
+
#marks;
|
|
64
|
+
#policy;
|
|
65
|
+
constructor(inner, marks, policy) {
|
|
66
|
+
super();
|
|
67
|
+
requireSaneMarks(marks);
|
|
68
|
+
this.#inner = inner;
|
|
69
|
+
this.#marks = marks;
|
|
70
|
+
this.#policy = policy;
|
|
71
|
+
}
|
|
72
|
+
async check(query) {
|
|
73
|
+
const allowed = await this.#inner.check(query);
|
|
74
|
+
this.#watchRoundTrips();
|
|
75
|
+
return allowed;
|
|
76
|
+
}
|
|
77
|
+
async checkMany(queries) {
|
|
78
|
+
if (queries.length === 0)
|
|
79
|
+
return [];
|
|
80
|
+
const checkMany = this.#inner.checkMany?.bind(this.#inner);
|
|
81
|
+
if (checkMany === undefined) {
|
|
82
|
+
const decisions = [];
|
|
83
|
+
for (const query of queries)
|
|
84
|
+
decisions.push(await this.check(query));
|
|
85
|
+
return decisions;
|
|
86
|
+
}
|
|
87
|
+
const decisions = await checkMany(queries);
|
|
88
|
+
this.#watchRoundTrips();
|
|
89
|
+
return decisions;
|
|
90
|
+
}
|
|
91
|
+
async checkEach(queries) {
|
|
92
|
+
if (queries.length === 0)
|
|
93
|
+
return [];
|
|
94
|
+
const checkEach = this.#inner.checkEach?.bind(this.#inner);
|
|
95
|
+
if (checkEach === undefined) {
|
|
96
|
+
return Promise.all(queries.map((query) => checkOutcome(() => this.check(query))));
|
|
97
|
+
}
|
|
98
|
+
const outcomes = await checkEach(queries);
|
|
99
|
+
this.#watchRoundTrips();
|
|
100
|
+
return outcomes;
|
|
101
|
+
}
|
|
102
|
+
async lookupResources(query) {
|
|
103
|
+
this.#refuseRecordLookup(query);
|
|
104
|
+
const ids = await this.#inner.lookupResources(query);
|
|
105
|
+
countAuthorizationLookupSize(ids.length);
|
|
106
|
+
if (ids.length > this.#marks.maxLookupIds) {
|
|
107
|
+
throw new LookupOverHardCapError(query, ids.length, this.#marks.maxLookupIds);
|
|
108
|
+
}
|
|
109
|
+
if (ids.length > this.#marks.warnLookupIds) {
|
|
110
|
+
noteAuthorizationWarning({
|
|
111
|
+
type: "AuthorizationLookupOverWarningMark",
|
|
112
|
+
fingerprint: `authz.lookup-size:${query.resourceType}#${query.permission}`,
|
|
113
|
+
detail: `lookupResources on ${query.resourceType}#${query.permission} for a ${query.subject.type} returned ${ids.length} ids, over the ${this.#marks.warnLookupIds} mark (AUTHZ_LOOKUP_WARN_IDS)`,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
this.#watchRoundTrips();
|
|
117
|
+
return ids;
|
|
118
|
+
}
|
|
119
|
+
async writeRelationships(writes) {
|
|
120
|
+
return this.#inner.writeRelationships(writes);
|
|
121
|
+
}
|
|
122
|
+
async deleteRelationships(filter) {
|
|
123
|
+
return this.#inner.deleteRelationships(filter);
|
|
124
|
+
}
|
|
125
|
+
async relationshipExists(filter) {
|
|
126
|
+
return this.#inner.relationshipExists(filter);
|
|
127
|
+
}
|
|
128
|
+
async listDirectSubjects(query) {
|
|
129
|
+
return this.#inner.listDirectSubjects(query);
|
|
130
|
+
}
|
|
131
|
+
#refuseRecordLookup(query) {
|
|
132
|
+
if (this.#policy.mayLookup(query.resourceType, query.permission))
|
|
133
|
+
return;
|
|
134
|
+
throw new RecordLookupRefusedError(query);
|
|
135
|
+
}
|
|
136
|
+
/** Read after the inner call, when the tally has counted it. */
|
|
137
|
+
#watchRoundTrips() {
|
|
138
|
+
const roundTrips = currentRequestWork()?.authzCheckCount ?? 0;
|
|
139
|
+
if (roundTrips <= this.#marks.warnRoundTrips)
|
|
140
|
+
return;
|
|
141
|
+
noteAuthorizationWarning({
|
|
142
|
+
type: "AuthorizationRoundTripsOverBudget",
|
|
143
|
+
fingerprint: "authz.round-trips",
|
|
144
|
+
detail: `request made more than ${this.#marks.warnRoundTrips} authorization round trips (AUTHZ_ROUND_TRIPS_WARN)`,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function requireSaneMarks(marks) {
|
|
149
|
+
const { warnLookupIds, maxLookupIds } = marks;
|
|
150
|
+
for (const [name, value] of Object.entries(marks)) {
|
|
151
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
152
|
+
throw new Error(`authorization guard mark ${name} must be a positive integer, got ${value}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (warnLookupIds >= maxLookupIds) {
|
|
156
|
+
throw new Error(`authorization guard warnLookupIds (${warnLookupIds}) must be below maxLookupIds (${maxLookupIds})`);
|
|
157
|
+
}
|
|
158
|
+
if (maxLookupIds >= POSTGRES_PARAMETER_LIMIT) {
|
|
159
|
+
throw new Error(`authorization guard maxLookupIds (${maxLookupIds}) must stay below Postgres's ${POSTGRES_PARAMETER_LIMIT}-parameter limit`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=guarded-authorization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guarded-authorization.js","sourceRoot":"","sources":["../../../src/lib/access/guarded-authorization.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAC9F,OAAO,EACL,kBAAkB,EAClB,4BAA4B,EAC5B,wBAAwB,GACzB,MAAM,2CAA2C,CAAC;AAEnD,OAAO,EACL,aAAa,EACb,YAAY,GASb,MAAM,gCAAgC,CAAC;AAYxC,MAAM,CAAC,MAAM,iCAAiC,GAA4B;IACxE,aAAa,EAAE,KAAK;IACpB,YAAY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4B,IAAI,oCAAoC,KAAK,EAAE,CAAC,CAAC;QAC/F,CAAC;IACH,CAAC;IACD,IAAI,aAAa,IAAI,YAAY,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CACb,sCAAsC,aAAa,iCAAiC,YAAY,GAAG,CACpG,CAAC;IACJ,CAAC;IACD,IAAI,YAAY,IAAI,wBAAwB,EAAE,CAAC;QAC7C,MAAM,IAAI,KAAK,CACb,qCAAqC,YAAY,gCAAgC,wBAAwB,kBAAkB,CAC5H,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Authorization } from "@dads-framework/access/runtime";
|
|
2
|
+
import type { ResourceLookup } from "@dads-framework/access/runtime";
|
|
3
|
+
/**
|
|
4
|
+
* The list-query authorization dance, fail-closed: lookupResources yields
|
|
5
|
+
* the subject's visible set, and an EMPTY set returns an empty page WITHOUT
|
|
6
|
+
* calling `list` — this guard is the reason the helper exists (an empty
|
|
7
|
+
* IN () clause is a classic widening footgun; empty means "sees nothing",
|
|
8
|
+
* never "sees all" — docs/architecture/authorization.md). Filters inside
|
|
9
|
+
* `list` narrow within the visible set, never widen.
|
|
10
|
+
*
|
|
11
|
+
* SUPERSEDED AT THE HTTP EDGE by the kit's `requireVisibility` access
|
|
12
|
+
* declaration, which owns the same fail-closed dance and hands handlers the
|
|
13
|
+
* visible set. This helper remains the pattern for NON-HTTP callers (jobs,
|
|
14
|
+
* subscribers, future edges) that need a visibility-scoped list.
|
|
15
|
+
*/
|
|
16
|
+
export declare function listOnlyVisible<T>(authorization: Authorization, lookup: ResourceLookup, list: (visibleIds: readonly string[]) => Promise<{
|
|
17
|
+
rows: readonly T[];
|
|
18
|
+
total: number;
|
|
19
|
+
}>): Promise<{
|
|
20
|
+
rows: readonly T[];
|
|
21
|
+
total: number;
|
|
22
|
+
}>;
|
|
23
|
+
//# sourceMappingURL=list-only-visible.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-only-visible.d.ts","sourceRoot":"","sources":["../../../src/lib/access/list-only-visible.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAErE;;;;;;;;;;;;GAYG;AACH,wBAAsB,eAAe,CAAC,CAAC,EACrC,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,cAAc,EACtB,IAAI,EAAE,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,KAAK,OAAO,CAAC;IAAE,IAAI,EAAE,SAAS,CAAC,EAAE,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,GACtF,OAAO,CAAC;IAAE,IAAI,EAAE,SAAS,CAAC,EAAE,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAMhD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The list-query authorization dance, fail-closed: lookupResources yields
|
|
3
|
+
* the subject's visible set, and an EMPTY set returns an empty page WITHOUT
|
|
4
|
+
* calling `list` — this guard is the reason the helper exists (an empty
|
|
5
|
+
* IN () clause is a classic widening footgun; empty means "sees nothing",
|
|
6
|
+
* never "sees all" — docs/architecture/authorization.md). Filters inside
|
|
7
|
+
* `list` narrow within the visible set, never widen.
|
|
8
|
+
*
|
|
9
|
+
* SUPERSEDED AT THE HTTP EDGE by the kit's `requireVisibility` access
|
|
10
|
+
* declaration, which owns the same fail-closed dance and hands handlers the
|
|
11
|
+
* visible set. This helper remains the pattern for NON-HTTP callers (jobs,
|
|
12
|
+
* subscribers, future edges) that need a visibility-scoped list.
|
|
13
|
+
*/
|
|
14
|
+
export async function listOnlyVisible(authorization, lookup, list) {
|
|
15
|
+
const visibleIds = await authorization.lookupResources(lookup);
|
|
16
|
+
if (visibleIds.length === 0) {
|
|
17
|
+
return { rows: [], total: 0 };
|
|
18
|
+
}
|
|
19
|
+
return list(visibleIds);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=list-only-visible.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-only-visible.js","sourceRoot":"","sources":["../../../src/lib/access/list-only-visible.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,aAA4B,EAC5B,MAAsB,EACtB,IAAuF;IAEvF,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;IAC/D,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IAChC,CAAC;IACD,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spice-db-empty-schema.d.ts","sourceRoot":"","sources":["../../../../src/lib/access/logic/spice-db-empty-schema.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAI1D"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** SpiceDB's refusal to read a schema that was never written. */
|
|
2
|
+
export function isEmptySchemaError(error) {
|
|
3
|
+
return /no schema has been defined|schema has not been defined|no schema has been written|object definitions have not been written|schema is empty/i.test(errorMessage(error));
|
|
4
|
+
}
|
|
5
|
+
function errorMessage(error) {
|
|
6
|
+
if (error instanceof Error) {
|
|
7
|
+
return error.message;
|
|
8
|
+
}
|
|
9
|
+
if (typeof error === "object" && error !== null && "message" in error) {
|
|
10
|
+
const message = error.message;
|
|
11
|
+
if (typeof message === "string") {
|
|
12
|
+
return message;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return String(error);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=spice-db-empty-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spice-db-empty-schema.js","sourceRoot":"","sources":["../../../../src/lib/access/logic/spice-db-empty-schema.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,OAAO,6IAA6I,CAAC,IAAI,CACvJ,YAAY,CAAC,KAAK,CAAC,CACpB,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC,OAAO,CAAC;IACvB,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,SAAS,IAAI,KAAK,EAAE,CAAC;QACtE,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC9B,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAChC,OAAO,OAAO,CAAC;QACjB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type SpiceDbSecurityMode = "secure" | "insecure-localhost" | "insecure-plaintext";
|
|
2
|
+
/** Chooses the Authzed transport mode without dropping request credentials. */
|
|
3
|
+
export declare function resolveSpiceDbSecurityMode(endpoint: string, insecure: boolean): SpiceDbSecurityMode;
|
|
4
|
+
//# sourceMappingURL=spice-db-security.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spice-db-security.d.ts","sourceRoot":"","sources":["../../../../src/lib/access/logic/spice-db-security.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,oBAAoB,GAAG,oBAAoB,CAAC;AAEzF,+EAA+E;AAC/E,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,mBAAmB,CAKnG"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Chooses the Authzed transport mode without dropping request credentials. */
|
|
2
|
+
export function resolveSpiceDbSecurityMode(endpoint, insecure) {
|
|
3
|
+
if (!insecure) {
|
|
4
|
+
return "secure";
|
|
5
|
+
}
|
|
6
|
+
return endpoint.startsWith("localhost:") ? "insecure-localhost" : "insecure-plaintext";
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=spice-db-security.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spice-db-security.js","sourceRoot":"","sources":["../../../../src/lib/access/logic/spice-db-security.ts"],"names":[],"mappings":"AAEA,+EAA+E;AAC/E,MAAM,UAAU,0BAA0B,CAAC,QAAgB,EAAE,QAAiB;IAC5E,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,OAAO,QAAQ,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,oBAAoB,CAAC;AACzF,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When a relationship write that SpiceDB did not accept is worth sending again.
|
|
3
|
+
*
|
|
4
|
+
* Concurrent writes to one datastore can lose a race inside SpiceDB: the
|
|
5
|
+
* in-memory datastore answers `DEADLINE_EXCEEDED: serialization max retries
|
|
6
|
+
* exceeded`, and the SQL datastores answer `ABORTED` on a serialization
|
|
7
|
+
* conflict. Neither is a refusal — the same write succeeds a moment later.
|
|
8
|
+
* Every write this adapter sends is idempotent (relationship writes TOUCH,
|
|
9
|
+
* deletes of absent tuples are no-ops), so sending it again is safe.
|
|
10
|
+
*
|
|
11
|
+
* Without this, a lost race was terminal for the caller. A resource created during concurrent writes could return success
|
|
12
|
+
* with its ownership fact still pending.
|
|
13
|
+
*
|
|
14
|
+
* A refusal (`FAILED_PRECONDITION`, `INVALID_ARGUMENT`, …) is never retried:
|
|
15
|
+
* it will be refused again, and the caller must hear it once.
|
|
16
|
+
*/
|
|
17
|
+
/** Total sends of one write, the first included. */
|
|
18
|
+
export declare const SPICE_DB_WRITE_ATTEMPTS = 4;
|
|
19
|
+
export declare function isRetryableSpiceDbWriteError(error: unknown): boolean;
|
|
20
|
+
/** Back off 10, 20, 40 ms: long enough for the competing write to commit. */
|
|
21
|
+
export declare function spiceDbWriteRetryDelayMs(failedAttempt: number): number;
|
|
22
|
+
//# sourceMappingURL=spice-db-write-retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spice-db-write-retry.d.ts","sourceRoot":"","sources":["../../../../src/lib/access/logic/spice-db-write-retry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AASH,oDAAoD;AACpD,eAAO,MAAM,uBAAuB,IAAI,CAAC;AAEzC,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAKpE;AAED,6EAA6E;AAC7E,wBAAgB,wBAAwB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAEtE"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When a relationship write that SpiceDB did not accept is worth sending again.
|
|
3
|
+
*
|
|
4
|
+
* Concurrent writes to one datastore can lose a race inside SpiceDB: the
|
|
5
|
+
* in-memory datastore answers `DEADLINE_EXCEEDED: serialization max retries
|
|
6
|
+
* exceeded`, and the SQL datastores answer `ABORTED` on a serialization
|
|
7
|
+
* conflict. Neither is a refusal — the same write succeeds a moment later.
|
|
8
|
+
* Every write this adapter sends is idempotent (relationship writes TOUCH,
|
|
9
|
+
* deletes of absent tuples are no-ops), so sending it again is safe.
|
|
10
|
+
*
|
|
11
|
+
* Without this, a lost race was terminal for the caller. A resource created during concurrent writes could return success
|
|
12
|
+
* with its ownership fact still pending.
|
|
13
|
+
*
|
|
14
|
+
* A refusal (`FAILED_PRECONDITION`, `INVALID_ARGUMENT`, …) is never retried:
|
|
15
|
+
* it will be refused again, and the caller must hear it once.
|
|
16
|
+
*/
|
|
17
|
+
/** gRPC status codes for a write that lost a race rather than one SpiceDB refused. */
|
|
18
|
+
const RETRYABLE_WRITE_STATUS_CODES = new Set([
|
|
19
|
+
4, // DEADLINE_EXCEEDED — memdb serialization retries exhausted
|
|
20
|
+
10, // ABORTED — SQL datastore serialization conflict
|
|
21
|
+
14, // UNAVAILABLE — connection dropped before an answer
|
|
22
|
+
]);
|
|
23
|
+
/** Total sends of one write, the first included. */
|
|
24
|
+
export const SPICE_DB_WRITE_ATTEMPTS = 4;
|
|
25
|
+
export function isRetryableSpiceDbWriteError(error) {
|
|
26
|
+
if (typeof error !== "object" || error === null || !("code" in error)) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
return typeof error.code === "number" && RETRYABLE_WRITE_STATUS_CODES.has(error.code);
|
|
30
|
+
}
|
|
31
|
+
/** Back off 10, 20, 40 ms: long enough for the competing write to commit. */
|
|
32
|
+
export function spiceDbWriteRetryDelayMs(failedAttempt) {
|
|
33
|
+
return 10 * 2 ** (failedAttempt - 1);
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=spice-db-write-retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spice-db-write-retry.js","sourceRoot":"","sources":["../../../../src/lib/access/logic/spice-db-write-retry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,sFAAsF;AACtF,MAAM,4BAA4B,GAAwB,IAAI,GAAG,CAAC;IAChE,CAAC,EAAE,4DAA4D;IAC/D,EAAE,EAAE,iDAAiD;IACrD,EAAE,EAAE,oDAAoD;CACzD,CAAC,CAAC;AAEH,oDAAoD;AACpD,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC;AAEzC,MAAM,UAAU,4BAA4B,CAAC,KAAc;IACzD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC,EAAE,CAAC;QACtE,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,4BAA4B,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACxF,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,wBAAwB,CAAC,aAAqB;IAC5D,OAAO,EAAE,GAAG,CAAC,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Domain-owned ownership reconciliation seam (docs/architecture/authorization.md).
|
|
3
|
+
* Each domain contributes an audit via compose*(); the composition root
|
|
4
|
+
* registers them; domains never import each other.
|
|
5
|
+
*/
|
|
6
|
+
export type MissingOwnershipTuple = {
|
|
7
|
+
readonly resourceType: string;
|
|
8
|
+
readonly resourceId: string;
|
|
9
|
+
readonly kind: "missingTuple";
|
|
10
|
+
readonly expectedRelation: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Report-only check: durable rows that should carry a parent authz fact.
|
|
14
|
+
* Implementations live in the owning domain next to its readers.
|
|
15
|
+
*/
|
|
16
|
+
export declare abstract class MissingOwnershipTuples {
|
|
17
|
+
abstract run(): Promise<readonly MissingOwnershipTuple[]>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=missing-ownership-tuples.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"missing-ownership-tuples.d.ts","sourceRoot":"","sources":["../../../src/lib/access/missing-ownership-tuples.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,qBAAqB,GAAG;IAClC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;CACnC,CAAC;AAEF;;;GAGG;AACH,8BAAsB,sBAAsB;IAC1C,QAAQ,CAAC,GAAG,IAAI,OAAO,CAAC,SAAS,qBAAqB,EAAE,CAAC,CAAC;CAC3D"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Domain-owned ownership reconciliation seam (docs/architecture/authorization.md).
|
|
3
|
+
* Each domain contributes an audit via compose*(); the composition root
|
|
4
|
+
* registers them; domains never import each other.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Report-only check: durable rows that should carry a parent authz fact.
|
|
8
|
+
* Implementations live in the owning domain next to its readers.
|
|
9
|
+
*/
|
|
10
|
+
export class MissingOwnershipTuples {
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=missing-ownership-tuples.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"missing-ownership-tuples.js","sourceRoot":"","sources":["../../../src/lib/access/missing-ownership-tuples.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH;;;GAGG;AACH,MAAM,OAAgB,sBAAsB;CAE3C"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { SpiceDbConsistencyToken } from "@dads-framework/access/runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The ZedToken of the newest relationship write this process made, so that
|
|
4
|
+
* enforcement reads can ask SpiceDB for `at_least_as_fresh` than it and be
|
|
5
|
+
* served from SpiceDB's cache instead of walking the datastore every time.
|
|
6
|
+
*
|
|
7
|
+
* ZedTokens are opaque, so two tokens cannot be compared. What this process
|
|
8
|
+
* can know is the order its own writes finished in: a write that started
|
|
9
|
+
* after every earlier write had finished committed after all of them, so its
|
|
10
|
+
* token covers every write before it. A write that overlapped another one
|
|
11
|
+
* gives no such order — the revision is fixed somewhere inside the call — so
|
|
12
|
+
* it leaves no trusted token at all, and enforcement falls back to a fully
|
|
13
|
+
* consistent read until the next write that overlapped nothing. A failed
|
|
14
|
+
* write may still have committed, so it clears the token the same way. An
|
|
15
|
+
* older token therefore never replaces a newer one: it is either provably
|
|
16
|
+
* newest or forgotten.
|
|
17
|
+
*
|
|
18
|
+
* `SpiceDbAuthorization` runs its writes one at a time, so overlap should
|
|
19
|
+
* never happen there; the check stays as the safety net if it ever does.
|
|
20
|
+
*
|
|
21
|
+
* Process-local on purpose (see `docs/architecture/authorization.md#consistency`):
|
|
22
|
+
* the API refuses to boot as more than one instance while this is the only
|
|
23
|
+
* record of the newest write.
|
|
24
|
+
* TODO(second API instance): persist the newest token in Postgres, written
|
|
25
|
+
* where the tuples are written and read once per request, before
|
|
26
|
+
* `API_MAX_INSTANCES` may exceed 1.
|
|
27
|
+
*/
|
|
28
|
+
export declare class NewestWrittenToken {
|
|
29
|
+
#private;
|
|
30
|
+
/** The token every enforcement read may be at least as fresh as; none means read fully consistent. */
|
|
31
|
+
current(): SpiceDbConsistencyToken | undefined;
|
|
32
|
+
/** Runs one relationship write and keeps its token only when it is provably the newest. */
|
|
33
|
+
track<T>(write: () => Promise<T>, tokenOf: (response: T) => SpiceDbConsistencyToken): Promise<T>;
|
|
34
|
+
/** Forgets the token, for a change the token does not describe (a schema write). */
|
|
35
|
+
forget(): void;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=newest-written-token.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"newest-written-token.d.ts","sourceRoot":"","sources":["../../../src/lib/access/newest-written-token.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,kBAAkB;;IAI7B,sGAAsG;IACtG,OAAO,IAAI,uBAAuB,GAAG,SAAS,CAE7C;IAED,2FAA2F;IACrF,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,uBAAuB,GAAG,OAAO,CAAC,CAAC,CAAC,CAarG;IAED,oFAAoF;IACpF,MAAM,IAAI,IAAI,CAGb;CACF"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ZedToken of the newest relationship write this process made, so that
|
|
3
|
+
* enforcement reads can ask SpiceDB for `at_least_as_fresh` than it and be
|
|
4
|
+
* served from SpiceDB's cache instead of walking the datastore every time.
|
|
5
|
+
*
|
|
6
|
+
* ZedTokens are opaque, so two tokens cannot be compared. What this process
|
|
7
|
+
* can know is the order its own writes finished in: a write that started
|
|
8
|
+
* after every earlier write had finished committed after all of them, so its
|
|
9
|
+
* token covers every write before it. A write that overlapped another one
|
|
10
|
+
* gives no such order — the revision is fixed somewhere inside the call — so
|
|
11
|
+
* it leaves no trusted token at all, and enforcement falls back to a fully
|
|
12
|
+
* consistent read until the next write that overlapped nothing. A failed
|
|
13
|
+
* write may still have committed, so it clears the token the same way. An
|
|
14
|
+
* older token therefore never replaces a newer one: it is either provably
|
|
15
|
+
* newest or forgotten.
|
|
16
|
+
*
|
|
17
|
+
* `SpiceDbAuthorization` runs its writes one at a time, so overlap should
|
|
18
|
+
* never happen there; the check stays as the safety net if it ever does.
|
|
19
|
+
*
|
|
20
|
+
* Process-local on purpose (see `docs/architecture/authorization.md#consistency`):
|
|
21
|
+
* the API refuses to boot as more than one instance while this is the only
|
|
22
|
+
* record of the newest write.
|
|
23
|
+
* TODO(second API instance): persist the newest token in Postgres, written
|
|
24
|
+
* where the tuples are written and read once per request, before
|
|
25
|
+
* `API_MAX_INSTANCES` may exceed 1.
|
|
26
|
+
*/
|
|
27
|
+
export class NewestWrittenToken {
|
|
28
|
+
#finishedWrites = 0;
|
|
29
|
+
#token;
|
|
30
|
+
/** The token every enforcement read may be at least as fresh as; none means read fully consistent. */
|
|
31
|
+
current() {
|
|
32
|
+
return this.#token;
|
|
33
|
+
}
|
|
34
|
+
/** Runs one relationship write and keeps its token only when it is provably the newest. */
|
|
35
|
+
async track(write, tokenOf) {
|
|
36
|
+
const finishedBeforeStart = this.#finishedWrites;
|
|
37
|
+
let written;
|
|
38
|
+
try {
|
|
39
|
+
const response = await write();
|
|
40
|
+
const token = tokenOf(response);
|
|
41
|
+
written = token.length > 0 ? token : undefined;
|
|
42
|
+
return response;
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
const overlappedAnotherWrite = this.#finishedWrites !== finishedBeforeStart;
|
|
46
|
+
this.#finishedWrites += 1;
|
|
47
|
+
this.#token = overlappedAnotherWrite ? undefined : written;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/** Forgets the token, for a change the token does not describe (a schema write). */
|
|
51
|
+
forget() {
|
|
52
|
+
this.#finishedWrites += 1;
|
|
53
|
+
this.#token = undefined;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=newest-written-token.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"newest-written-token.js","sourceRoot":"","sources":["../../../src/lib/access/newest-written-token.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,kBAAkB;IAC7B,eAAe,GAAG,CAAC,CAAC;IACpB,MAAM,CAAsC;IAE5C,sGAAsG;IACtG,OAAO;QACL,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,2FAA2F;IAC3F,KAAK,CAAC,KAAK,CAAI,KAAuB,EAAE,OAAiD;QACvF,MAAM,mBAAmB,GAAG,IAAI,CAAC,eAAe,CAAC;QACjD,IAAI,OAA4C,CAAC;QACjD,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,KAAK,EAAE,CAAC;YAC/B,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;YAChC,OAAO,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;YAC/C,OAAO,QAAQ,CAAC;QAClB,CAAC;gBAAS,CAAC;YACT,MAAM,sBAAsB,GAAG,IAAI,CAAC,eAAe,KAAK,mBAAmB,CAAC;YAC5E,IAAI,CAAC,eAAe,IAAI,CAAC,CAAC;YAC1B,IAAI,CAAC,MAAM,GAAG,sBAAsB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;QAC7D,CAAC;IACH,CAAC;IAED,oFAAoF;IACpF,MAAM;QACJ,IAAI,CAAC,eAAe,IAAI,CAAC,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs writes one after another, in the order they were asked for.
|
|
3
|
+
*
|
|
4
|
+
* Each write starts only once the one before it has settled, whether it
|
|
5
|
+
* succeeded or failed, and a failure reaches only its own caller. This is
|
|
6
|
+
* what lets every successful relationship write leave a token the adapter
|
|
7
|
+
* can trust as the newest: with no two writes in flight together, the order
|
|
8
|
+
* they finish in is the order they committed in.
|
|
9
|
+
*/
|
|
10
|
+
export declare class OneWriteAtATime {
|
|
11
|
+
#private;
|
|
12
|
+
run<T>(write: () => Promise<T>): Promise<T>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=one-write-at-a-time.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"one-write-at-a-time.d.ts","sourceRoot":"","sources":["../../../src/lib/access/one-write-at-a-time.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,qBAAa,eAAe;;IAG1B,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAO1C;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs writes one after another, in the order they were asked for.
|
|
3
|
+
*
|
|
4
|
+
* Each write starts only once the one before it has settled, whether it
|
|
5
|
+
* succeeded or failed, and a failure reaches only its own caller. This is
|
|
6
|
+
* what lets every successful relationship write leave a token the adapter
|
|
7
|
+
* can trust as the newest: with no two writes in flight together, the order
|
|
8
|
+
* they finish in is the order they committed in.
|
|
9
|
+
*/
|
|
10
|
+
export class OneWriteAtATime {
|
|
11
|
+
#last = Promise.resolve();
|
|
12
|
+
run(write) {
|
|
13
|
+
const result = this.#last.then(write, write);
|
|
14
|
+
this.#last = result.then(() => undefined, () => undefined);
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=one-write-at-a-time.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"one-write-at-a-time.js","sourceRoot":"","sources":["../../../src/lib/access/one-write-at-a-time.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,OAAO,eAAe;IAC1B,KAAK,GAAqB,OAAO,CAAC,OAAO,EAAE,CAAC;IAE5C,GAAG,CAAI,KAAuB;QAC5B,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC7C,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CACtB,GAAG,EAAE,CAAC,SAAS,EACf,GAAG,EAAE,CAAC,SAAS,CAChB,CAAC;QACF,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|