@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 @@
|
|
|
1
|
+
{"version":3,"file":"catalog-tables.js","sourceRoot":"","sources":["../../../src/lib/catalog-sizes/catalog-tables.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,YAAY,EAAc,MAAM,aAAa,CAAC;AAqBvD,MAAM,UAAU,YAAY,CAAC,MAAwB,EAAE,KAAY;IACjE,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IAC7E,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,SAAS,EAAE,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;AACvE,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,MAAwB,EAAE,MAAc;IAC1E,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IAC7E,CAAC;IACD,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,GAAG,MAAM,CAAC,QAAQ,mCAAmC,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,WAAoC;IAClE,OAAO,WAAW,IAAI,WAAW,CAAC;AACpC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAClC,gBAAmC,EACnC,YAAgD;IAEhD,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;IACtE,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAC3C,OAAO;QACL,GAAG,gBAAgB;aAChB,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;aAC7C,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;YAClB,IAAI,EAAE,QAAQ;YACd,OAAO,EACL,gJAAgJ;SACnJ,CAAC,CAAC;QACL,GAAG,YAAY;aACZ,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;aAChD,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YACf,IAAI,EAAE,KAAK,CAAC,QAAQ;YACpB,OAAO,EAAE,iEAAiE;SAC3E,CAAC,CAAC;KACN,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ApplyAuthorizationSchemaLog } from "@dads-framework/access/schema";
|
|
2
|
+
export declare function cloneSpiceDbDatastore(input: {
|
|
3
|
+
adminUrl: string;
|
|
4
|
+
sourceDatabase: string;
|
|
5
|
+
log?: ApplyAuthorizationSchemaLog;
|
|
6
|
+
}): Promise<"cloned" | "skipped">;
|
|
7
|
+
export declare function spiceDbDatastoreAdminUrl(datastoreUrl: string): string;
|
|
8
|
+
export declare function spiceDbDatastoreDatabaseName(datastoreUrl: string): string;
|
|
9
|
+
//# sourceMappingURL=clone-spice-db-datastore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clone-spice-db-datastore.d.ts","sourceRoot":"","sources":["../../../src/lib/schema-migrate/clone-spice-db-datastore.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAKjF,wBAAsB,qBAAqB,CAAC,KAAK,EAAE;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,GAAG,CAAC,EAAE,2BAA2B,CAAC;CACnC,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAwChC;AAED,wBAAgB,wBAAwB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAIrE;AAED,wBAAgB,4BAA4B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAOzE"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createPostgresConnection } from "@dads-framework/postgres";
|
|
2
|
+
const PREVIOUS_DATABASE = "spicedb_previous";
|
|
3
|
+
const IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
4
|
+
export async function cloneSpiceDbDatastore(input) {
|
|
5
|
+
if (!IDENTIFIER.test(input.sourceDatabase)) {
|
|
6
|
+
throw new Error("SpiceDB datastore database name is not a SQL identifier");
|
|
7
|
+
}
|
|
8
|
+
const connection = createPostgresConnection({ connectionString: input.adminUrl, schema: {}, maxConnections: 1 }, {
|
|
9
|
+
error: (context, message) => input.log?.info(context, message ?? "Postgres snapshot connection error"),
|
|
10
|
+
});
|
|
11
|
+
try {
|
|
12
|
+
await connection.pool.query("SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = $1 AND pid <> pg_backend_pid()", [PREVIOUS_DATABASE]);
|
|
13
|
+
await connection.pool.query(`DROP DATABASE IF EXISTS ${PREVIOUS_DATABASE}`);
|
|
14
|
+
await connection.pool.query(`CREATE DATABASE ${PREVIOUS_DATABASE} TEMPLATE ${input.sourceDatabase}`);
|
|
15
|
+
input.log?.info({
|
|
16
|
+
event: "authorization.schema.snapshot.cloned",
|
|
17
|
+
code: "AUTHORIZATION_SCHEMA_SNAPSHOT_CLONED",
|
|
18
|
+
database: PREVIOUS_DATABASE,
|
|
19
|
+
}, "cloned the SpiceDB datastore before contracting leftover tuples");
|
|
20
|
+
return "cloned";
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
input.log?.info({
|
|
24
|
+
event: "authorization.schema.snapshot.skipped",
|
|
25
|
+
code: "AUTHORIZATION_SCHEMA_SNAPSHOT_SKIPPED",
|
|
26
|
+
cause: error instanceof Error ? error.name : "UnknownError",
|
|
27
|
+
}, "could not clone the SpiceDB datastore; continuing without a rolling snapshot");
|
|
28
|
+
return "skipped";
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
await connection.close().catch(() => undefined);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function spiceDbDatastoreAdminUrl(datastoreUrl) {
|
|
35
|
+
const url = new URL(datastoreUrl);
|
|
36
|
+
url.pathname = "/postgres";
|
|
37
|
+
return url.toString();
|
|
38
|
+
}
|
|
39
|
+
export function spiceDbDatastoreDatabaseName(datastoreUrl) {
|
|
40
|
+
const url = new URL(datastoreUrl);
|
|
41
|
+
const name = url.pathname.replace(/^\//, "");
|
|
42
|
+
if (name === "" || !IDENTIFIER.test(name)) {
|
|
43
|
+
throw new Error("SpiceDB datastore URL is missing a database name");
|
|
44
|
+
}
|
|
45
|
+
return name;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=clone-spice-db-datastore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clone-spice-db-datastore.js","sourceRoot":"","sources":["../../../src/lib/schema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AE,uCAAuC;YAC9C,IAAI,EAAE,uCAAuC;YAC7C,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc;SAC5D,EACD,8EAA8E,CAC/E,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC;YAAS,CAAC;QACT,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAClD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,YAAoB;IAC3D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC;IAClC,GAAG,CAAC,QAAQ,GAAG,WAAW,CAAC;IAC3B,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;AACxB,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,YAAoB;IAC/D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC;IAClC,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC7C,IAAI,IAAI,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
declare const authorizationSchemaMigrationEnvironmentSchema: z.ZodPipe<z.ZodObject<{
|
|
3
|
+
SPICEDB_ENDPOINT: z.ZodDefault<z.ZodString>;
|
|
4
|
+
SPICEDB_PRESHARED_KEY: z.ZodDefault<z.ZodString>;
|
|
5
|
+
SPICEDB_INSECURE: z.ZodPipe<z.ZodDefault<z.ZodEnum<{
|
|
6
|
+
false: "false";
|
|
7
|
+
true: "true";
|
|
8
|
+
}>>, z.ZodTransform<boolean, "false" | "true">>;
|
|
9
|
+
AUTHZ_JOURNAL_FOLDER: z.ZodDefault<z.ZodString>;
|
|
10
|
+
SPICEDB_DATASTORE_CONN_URI: z.ZodOptional<z.ZodString>;
|
|
11
|
+
SPICEDB_DATASTORE_ADMIN_URL: z.ZodOptional<z.ZodString>;
|
|
12
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
13
|
+
endpoint: string;
|
|
14
|
+
presharedKey: string;
|
|
15
|
+
insecure: boolean;
|
|
16
|
+
journalFolder: string;
|
|
17
|
+
datastorePostgresUrl: string | undefined;
|
|
18
|
+
datastoreAdminUrl: string | undefined;
|
|
19
|
+
}, {
|
|
20
|
+
SPICEDB_ENDPOINT: string;
|
|
21
|
+
SPICEDB_PRESHARED_KEY: string;
|
|
22
|
+
SPICEDB_INSECURE: boolean;
|
|
23
|
+
AUTHZ_JOURNAL_FOLDER: string;
|
|
24
|
+
SPICEDB_DATASTORE_CONN_URI?: string | undefined;
|
|
25
|
+
SPICEDB_DATASTORE_ADMIN_URL?: string | undefined;
|
|
26
|
+
}>>;
|
|
27
|
+
export type AuthorizationSchemaMigrationEnvironment = z.infer<typeof authorizationSchemaMigrationEnvironmentSchema>;
|
|
28
|
+
/** Parses SpiceDB schema-migrate settings for the database-migration process. */
|
|
29
|
+
export declare function parseAuthorizationSchemaMigrationEnvironment(input: unknown): AuthorizationSchemaMigrationEnvironment;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=parse-authorization-schema-migration-environment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-authorization-schema-migration-environment.d.ts","sourceRoot":"","sources":["../../../src/lib/schema-migrate/parse-authorization-schema-migration-environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,QAAA,MAAM,6CAA6C;;;;;;;;;;;;;;;;;;;;;;;;GAmB9C,CAAC;AAEN,MAAM,MAAM,uCAAuC,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,6CAA6C,CAAC,CAAC;AAEpH,iFAAiF;AACjF,wBAAgB,4CAA4C,CAAC,KAAK,EAAE,OAAO,GAAG,uCAAuC,CAEpH"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const authorizationSchemaMigrationEnvironmentSchema = z
|
|
3
|
+
.object({
|
|
4
|
+
SPICEDB_ENDPOINT: z.string().min(1).default("localhost:50051"),
|
|
5
|
+
SPICEDB_PRESHARED_KEY: z.string().min(1).default("spicedb-local-dev-key"),
|
|
6
|
+
SPICEDB_INSECURE: z
|
|
7
|
+
.enum(["true", "false"])
|
|
8
|
+
.default("true")
|
|
9
|
+
.transform((value) => value === "true"),
|
|
10
|
+
AUTHZ_JOURNAL_FOLDER: z.string().min(1).default("/app/authz-journal"),
|
|
11
|
+
SPICEDB_DATASTORE_CONN_URI: z.string().min(1).optional(),
|
|
12
|
+
SPICEDB_DATASTORE_ADMIN_URL: z.string().min(1).optional(),
|
|
13
|
+
})
|
|
14
|
+
.transform((environment) => ({
|
|
15
|
+
endpoint: environment.SPICEDB_ENDPOINT,
|
|
16
|
+
presharedKey: environment.SPICEDB_PRESHARED_KEY,
|
|
17
|
+
insecure: environment.SPICEDB_INSECURE,
|
|
18
|
+
journalFolder: environment.AUTHZ_JOURNAL_FOLDER,
|
|
19
|
+
datastorePostgresUrl: environment.SPICEDB_DATASTORE_CONN_URI,
|
|
20
|
+
datastoreAdminUrl: environment.SPICEDB_DATASTORE_ADMIN_URL,
|
|
21
|
+
}));
|
|
22
|
+
/** Parses SpiceDB schema-migrate settings for the database-migration process. */
|
|
23
|
+
export function parseAuthorizationSchemaMigrationEnvironment(input) {
|
|
24
|
+
return authorizationSchemaMigrationEnvironmentSchema.parse(input);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=parse-authorization-schema-migration-environment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-authorization-schema-migration-environment.js","sourceRoot":"","sources":["../../../src/lib/schema-migrate/parse-authorization-schema-migration-environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,6CAA6C,GAAG,CAAC;KACpD,MAAM,CAAC;IACN,gBAAgB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC;IAC9D,qBAAqB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,uBAAuB,CAAC;IACzE,gBAAgB,EAAE,CAAC;SAChB,IAAI,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;SACvB,OAAO,CAAC,MAAM,CAAC;SACf,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,MAAM,CAAC;IACzC,oBAAoB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,oBAAoB,CAAC;IACrE,0BAA0B,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IACxD,2BAA2B,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;CAC1D,CAAC;KACD,SAAS,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAC3B,QAAQ,EAAE,WAAW,CAAC,gBAAgB;IACtC,YAAY,EAAE,WAAW,CAAC,qBAAqB;IAC/C,QAAQ,EAAE,WAAW,CAAC,gBAAgB;IACtC,aAAa,EAAE,WAAW,CAAC,oBAAoB;IAC/C,oBAAoB,EAAE,WAAW,CAAC,0BAA0B;IAC5D,iBAAiB,EAAE,WAAW,CAAC,2BAA2B;CAC3D,CAAC,CAAC,CAAC;AAIN,iFAAiF;AACjF,MAAM,UAAU,4CAA4C,CAAC,KAAc;IACzE,OAAO,6CAA6C,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page re-check behind every scoped list. The scope predicate decides
|
|
3
|
+
* which rows SQL reads and counts; this decides which of the page's rows the
|
|
4
|
+
* caller sees. So a wrong plan or a wrong SQL binding can mis-count a list or
|
|
5
|
+
* leave a page short, but it can never show a row the caller may not view.
|
|
6
|
+
*/
|
|
7
|
+
import type { PermissionToken } from "@dads-framework/access";
|
|
8
|
+
import type { PermissionQuery, SubjectRef } from "@dads-framework/access/runtime";
|
|
9
|
+
/**
|
|
10
|
+
* The checks a page re-check needs. `Authorization` satisfies it; when the
|
|
11
|
+
* adapter offers the optional bulk `checkMany`, the page is asked in batches.
|
|
12
|
+
*/
|
|
13
|
+
export type PageCheck = {
|
|
14
|
+
check(query: PermissionQuery): Promise<boolean>;
|
|
15
|
+
checkMany?(queries: readonly PermissionQuery[]): Promise<readonly boolean[]>;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Keep the rows the subject holds `permission` on, in their SQL order. A row
|
|
19
|
+
* whose decision is missing is dropped, never kept.
|
|
20
|
+
*/
|
|
21
|
+
export declare function keepPermitted<Row extends {
|
|
22
|
+
readonly id: string;
|
|
23
|
+
}>(authorization: PageCheck, subject: SubjectRef, permission: PermissionToken, rows: readonly Row[]): Promise<readonly Row[]>;
|
|
24
|
+
//# sourceMappingURL=keep-permitted.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keep-permitted.d.ts","sourceRoot":"","sources":["../../../src/lib/scoped-lists/keep-permitted.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAGlF;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAChD,SAAS,CAAC,CAAC,OAAO,EAAE,SAAS,eAAe,EAAE,GAAG,OAAO,CAAC,SAAS,OAAO,EAAE,CAAC,CAAC;CAC9E,CAAC;AAOF;;;GAGG;AACH,wBAAsB,aAAa,CAAC,GAAG,SAAS;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,EACrE,aAAa,EAAE,SAAS,EACxB,OAAO,EAAE,UAAU,EACnB,UAAU,EAAE,eAAe,EAC3B,IAAI,EAAE,SAAS,GAAG,EAAE,GACnB,OAAO,CAAC,SAAS,GAAG,EAAE,CAAC,CAkBzB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { checkAll } from "../access/check-all.js";
|
|
2
|
+
/** Bulk batches stay within one SpiceDB request each. */
|
|
3
|
+
const BULK_CHECK_SIZE = 128;
|
|
4
|
+
/** Without bulk checks, a page asks this many single checks at once. */
|
|
5
|
+
const SINGLE_CHECK_CONCURRENCY = 16;
|
|
6
|
+
/**
|
|
7
|
+
* Keep the rows the subject holds `permission` on, in their SQL order. A row
|
|
8
|
+
* whose decision is missing is dropped, never kept.
|
|
9
|
+
*/
|
|
10
|
+
export async function keepPermitted(authorization, subject, permission, rows) {
|
|
11
|
+
const kept = [];
|
|
12
|
+
const batchSize = authorization.checkMany === undefined ? SINGLE_CHECK_CONCURRENCY : BULK_CHECK_SIZE;
|
|
13
|
+
for (let start = 0; start < rows.length; start += batchSize) {
|
|
14
|
+
const batch = rows.slice(start, start + batchSize);
|
|
15
|
+
const queries = batch.map((row) => ({
|
|
16
|
+
subject,
|
|
17
|
+
permission: permission.permissionName,
|
|
18
|
+
resource: { type: permission.entityWireName, id: row.id },
|
|
19
|
+
}));
|
|
20
|
+
const allowed = await checkAll(authorization, queries);
|
|
21
|
+
batch.forEach((row, index) => {
|
|
22
|
+
if (allowed[index] === true) {
|
|
23
|
+
kept.push(row);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return kept;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=keep-permitted.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keep-permitted.js","sourceRoot":"","sources":["../../../src/lib/scoped-lists/keep-permitted.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAWlD,yDAAyD;AACzD,MAAM,eAAe,GAAG,GAAG,CAAC;AAC5B,wEAAwE;AACxE,MAAM,wBAAwB,GAAG,EAAE,CAAC;AAEpC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,aAAwB,EACxB,OAAmB,EACnB,UAA2B,EAC3B,IAAoB;IAEpB,MAAM,IAAI,GAAU,EAAE,CAAC;IACvB,MAAM,SAAS,GAAG,aAAa,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,eAAe,CAAC;IACrG,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,SAAS,EAAE,CAAC;QAC5D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC,CAAC;QACnD,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAmB,EAAE,CAAC,CAAC;YACnD,OAAO;YACP,UAAU,EAAE,UAAU,CAAC,cAAc;YACrC,QAAQ,EAAE,EAAE,IAAI,EAAE,UAAU,CAAC,cAAc,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE;SAC1D,CAAC,CAAC,CAAC;QACJ,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QACvD,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;YAC3B,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC;gBAC5B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACjB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Renders a scope plan, with its SpiceDB answers, as one SQL condition over
|
|
3
|
+
* the record's own columns. The same condition serves the page query and its
|
|
4
|
+
* `COUNT(*)`, so the total and the page can never disagree about scope.
|
|
5
|
+
*
|
|
6
|
+
* Every id set is one `uuid[]` parameter (`= ANY($n::uuid[])`), never an `IN`
|
|
7
|
+
* list, so a large answer cannot reach Postgres's 65,535-parameter cap.
|
|
8
|
+
*/
|
|
9
|
+
import { type SQL } from "drizzle-orm";
|
|
10
|
+
import { type ScopeAnswer } from "@dads-framework/access/runtime";
|
|
11
|
+
import type { ScopeSqlBindings } from "./scope-sql-bindings.js";
|
|
12
|
+
/**
|
|
13
|
+
* The WHERE condition that keeps exactly the records the plan admits.
|
|
14
|
+
* `bindings` are the listed record's own; a `via` renders the walked-to
|
|
15
|
+
* record with matching bindings from `related`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function scopePredicate(answer: ScopeAnswer, bindings: ScopeSqlBindings, related?: readonly ScopeSqlBindings[]): SQL;
|
|
18
|
+
//# sourceMappingURL=scope-predicate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope-predicate.d.ts","sourceRoot":"","sources":["../../../src/lib/scoped-lists/scope-predicate.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAO,KAAK,GAAG,EAAE,MAAM,aAAa,CAAC;AAI5C,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,gCAAgC,CAAC;AACpF,OAAO,KAAK,EAAW,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEzE;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,WAAW,EACnB,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,GAAE,SAAS,gBAAgB,EAAO,GACxC,GAAG,CAKL"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Renders a scope plan, with its SpiceDB answers, as one SQL condition over
|
|
3
|
+
* the record's own columns. The same condition serves the page query and its
|
|
4
|
+
* `COUNT(*)`, so the total and the page can never disagree about scope.
|
|
5
|
+
*
|
|
6
|
+
* Every id set is one `uuid[]` parameter (`= ANY($n::uuid[])`), never an `IN`
|
|
7
|
+
* list, so a large answer cannot reach Postgres's 65,535-parameter cap.
|
|
8
|
+
*/
|
|
9
|
+
import { sql } from "drizzle-orm";
|
|
10
|
+
import { scopeQuestionKey } from "@dads-framework/access/runtime";
|
|
11
|
+
/**
|
|
12
|
+
* The WHERE condition that keeps exactly the records the plan admits.
|
|
13
|
+
* `bindings` are the listed record's own; a `via` renders the walked-to
|
|
14
|
+
* record with matching bindings from `related`.
|
|
15
|
+
*/
|
|
16
|
+
export function scopePredicate(answer, bindings, related = []) {
|
|
17
|
+
if (bindings.wireName !== answer.resourceType) {
|
|
18
|
+
throw new Error(`scope answer is for ${answer.resourceType} but the SQL bindings are for ${bindings.wireName}`);
|
|
19
|
+
}
|
|
20
|
+
return renderPlan(answer.plan, { answer, related }, bindings);
|
|
21
|
+
}
|
|
22
|
+
function renderPlan(plan, rendering, bindings) {
|
|
23
|
+
switch (plan.kind) {
|
|
24
|
+
case "lookup":
|
|
25
|
+
return renderLookup(roleSql(bindings, plan.role), idsParameter(rendering.answer, plan.targetType, plan.targetPermission), bindings, plan.role);
|
|
26
|
+
case "tag":
|
|
27
|
+
return renderTag(roleSql(bindings, plan.role), bindings, plan.role);
|
|
28
|
+
case "direct":
|
|
29
|
+
return sql `${bindings.id} = ANY(${idsParameter(rendering.answer, bindings.wireName, plan.role)})`;
|
|
30
|
+
case "via":
|
|
31
|
+
return renderVia(plan.role, plan.targetType, plan.plan, rendering, bindings);
|
|
32
|
+
case "any":
|
|
33
|
+
return joined(plan.plans, " OR ", sql `FALSE`, rendering, bindings);
|
|
34
|
+
case "all":
|
|
35
|
+
return joined(plan.plans, " AND ", sql `TRUE`, rendering, bindings);
|
|
36
|
+
case "not":
|
|
37
|
+
// A NULL inside (a NULL column compared with ANY) is "no match", as an
|
|
38
|
+
// absent tuple is in SpiceDB, so it must negate to TRUE, not to NULL.
|
|
39
|
+
return sql `NOT COALESCE((${renderPlan(plan.plan, rendering, bindings)}), FALSE)`;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function renderLookup(role, ids, bindings, roleName) {
|
|
43
|
+
switch (role.kind) {
|
|
44
|
+
case "scope-column":
|
|
45
|
+
return sql `${role.column} = ANY(${ids})`;
|
|
46
|
+
case "scope-join":
|
|
47
|
+
case "derived":
|
|
48
|
+
return sql `(${role.matches(ids)})`;
|
|
49
|
+
case "tag":
|
|
50
|
+
throw new Error(`${bindings.wireName} role ${roleName} is a tag, but the plan looks up scopes through it`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function renderTag(role, bindings, roleName) {
|
|
54
|
+
if (role.kind !== "tag") {
|
|
55
|
+
throw new Error(`${bindings.wireName} role ${roleName} is bound as ${role.kind}, but the plan uses it as a tag`);
|
|
56
|
+
}
|
|
57
|
+
return sql `(${role.condition})`;
|
|
58
|
+
}
|
|
59
|
+
/** The walked-to record matches the inner plan, joined on the role's column. */
|
|
60
|
+
function renderVia(roleName, targetType, inner, rendering, bindings) {
|
|
61
|
+
const role = roleSql(bindings, roleName);
|
|
62
|
+
if (role.kind !== "scope-column") {
|
|
63
|
+
throw new Error(`${bindings.wireName} role ${roleName} walks into ${targetType}, so it must be bound as scope-column, not ${role.kind}`);
|
|
64
|
+
}
|
|
65
|
+
const target = rendering.related.find((entry) => entry.wireName === targetType);
|
|
66
|
+
if (target === undefined) {
|
|
67
|
+
throw new Error(`${bindings.wireName} role ${roleName} walks into ${targetType}, which has no scope SQL bindings`);
|
|
68
|
+
}
|
|
69
|
+
if (target.table === bindings.table) {
|
|
70
|
+
throw new Error(`${bindings.wireName} role ${roleName} walks into its own table; a self-walk needs a table alias this builder does not make`);
|
|
71
|
+
}
|
|
72
|
+
return sql `EXISTS (SELECT 1 FROM ${target.table} WHERE ${target.id} = ${role.column} AND ${renderPlan(inner, rendering, target)})`;
|
|
73
|
+
}
|
|
74
|
+
function joined(plans, separator, whenEmpty, rendering, bindings) {
|
|
75
|
+
if (plans.length === 0) {
|
|
76
|
+
return whenEmpty;
|
|
77
|
+
}
|
|
78
|
+
const parts = plans.map((plan) => renderPlan(plan, rendering, bindings));
|
|
79
|
+
return sql `(${sql.join(parts, sql.raw(separator))})`;
|
|
80
|
+
}
|
|
81
|
+
function roleSql(bindings, roleName) {
|
|
82
|
+
const role = bindings.roles[roleName];
|
|
83
|
+
if (role === undefined) {
|
|
84
|
+
throw new Error(`${bindings.wireName} role ${roleName} has no scope SQL binding`);
|
|
85
|
+
}
|
|
86
|
+
return role;
|
|
87
|
+
}
|
|
88
|
+
/** One question's answer as a single `uuid[]` parameter. */
|
|
89
|
+
function idsParameter(answer, resourceType, permission) {
|
|
90
|
+
const ids = answer.idsByQuestion.get(scopeQuestionKey({ resourceType, permission }));
|
|
91
|
+
if (ids === undefined) {
|
|
92
|
+
throw new Error(`scope answer has no ids for ${resourceType}#${permission}; build it with answerScope for the same plan`);
|
|
93
|
+
}
|
|
94
|
+
return sql `${sql.param([...ids])}::uuid[]`;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=scope-predicate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope-predicate.js","sourceRoot":"","sources":["../../../src/lib/scoped-lists/scope-predicate.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;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CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;IACzE,OAAO,GAAG,CAAA,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC;AACvD,CAAC;AAED,SAAS,OAAO,CAAC,QAA0B,EAAE,QAAgB;IAC3D,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACtC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,GAAG,QAAQ,CAAC,QAAQ,SAAS,QAAQ,2BAA2B,CAAC,CAAC;IACpF,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,4DAA4D;AAC5D,SAAS,YAAY,CAAC,MAAmB,EAAE,YAAoB,EAAE,UAAkB;IACjF,MAAM,GAAG,GAAG,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,gBAAgB,CAAC,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;IACrF,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CACb,+BAA+B,YAAY,IAAI,UAAU,+CAA+C,CACzG,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,CAAA,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,UAAU,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The SQL side of a record's scope bindings. The access kit declares each
|
|
3
|
+
* role's kind (`scopeBindings`); the owning domain hands the matching SQL
|
|
4
|
+
* here, once per record, beside its tables. A role's SQL must match its
|
|
5
|
+
* declared kind: TypeScript refuses a mismatch when the declaration's type is
|
|
6
|
+
* in view, and registration refuses it at boot otherwise.
|
|
7
|
+
*/
|
|
8
|
+
import type { AnyColumn, SQL, Table } from "drizzle-orm";
|
|
9
|
+
import type { RoleBinding, ScopeBindings, ScopeRoleBindings } from "@dads-framework/access/scopes";
|
|
10
|
+
/** `scope-column`: the record's own column holding the scope id. */
|
|
11
|
+
export type ScopeColumnSql = {
|
|
12
|
+
readonly kind: "scope-column";
|
|
13
|
+
readonly column: AnyColumn;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* `scope-join`: an EXISTS over the record's child rows. `ids` renders as one
|
|
17
|
+
* `uuid[]` parameter; compare with `= ANY(${ids})`.
|
|
18
|
+
*/
|
|
19
|
+
export type ScopeJoinSql = {
|
|
20
|
+
readonly kind: "scope-join";
|
|
21
|
+
readonly matches: (ids: SQL) => SQL;
|
|
22
|
+
};
|
|
23
|
+
/** `tag`: the constant condition the wildcard tuple stands for. */
|
|
24
|
+
export type TagSql = {
|
|
25
|
+
readonly kind: "tag";
|
|
26
|
+
readonly condition: SQL;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* `derived`: the domain's condition for a role with no column of its own,
|
|
30
|
+
* including that its target id is one of `ids`.
|
|
31
|
+
*/
|
|
32
|
+
export type DerivedSql = {
|
|
33
|
+
readonly kind: "derived";
|
|
34
|
+
readonly matches: (ids: SQL) => SQL;
|
|
35
|
+
};
|
|
36
|
+
export type RoleSql = ScopeColumnSql | ScopeJoinSql | TagSql | DerivedSql;
|
|
37
|
+
type RoleSqlFor<Binding extends RoleBinding> = Extract<RoleSql, {
|
|
38
|
+
readonly kind: Binding["kind"];
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* The SQL each declared role needs, by the kind it was declared with. A
|
|
42
|
+
* `sparse-direct` role takes none: the plan matches it on the id column.
|
|
43
|
+
*/
|
|
44
|
+
export type ScopeSqlRoles<Roles extends ScopeRoleBindings> = {
|
|
45
|
+
readonly [Role in keyof Roles as Roles[Role]["kind"] extends "sparse-direct" ? never : Role]: RoleSqlFor<Roles[Role]>;
|
|
46
|
+
};
|
|
47
|
+
/** One record's registered SQL bindings, read by `scopePredicate`. */
|
|
48
|
+
export type ScopeSqlBindings = {
|
|
49
|
+
readonly wireName: string;
|
|
50
|
+
readonly table: Table;
|
|
51
|
+
readonly id: AnyColumn;
|
|
52
|
+
readonly roles: Readonly<Record<string, RoleSql>>;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Declare how a bound record's roles render as SQL. Throws, naming every role,
|
|
56
|
+
* when the SQL does not match the declared kinds.
|
|
57
|
+
*/
|
|
58
|
+
export declare function scopeSqlBindings<const Roles extends ScopeRoleBindings>(bindings: ScopeBindings<Roles>, storage: {
|
|
59
|
+
readonly table: Table;
|
|
60
|
+
readonly id: AnyColumn;
|
|
61
|
+
readonly roles: ScopeSqlRoles<Roles> & Readonly<Record<string, RoleSql>>;
|
|
62
|
+
}): ScopeSqlBindings;
|
|
63
|
+
export {};
|
|
64
|
+
//# sourceMappingURL=scope-sql-bindings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope-sql-bindings.d.ts","sourceRoot":"","sources":["../../../src/lib/scoped-lists/scope-sql-bindings.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzD,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAEnG,oEAAoE;AACpE,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;CAC5B,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,GAAG,CAAC;CACrC,CAAC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P,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,SAAS,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAC1E,GACA,gBAAgB,CAgBlB"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declare how a bound record's roles render as SQL. Throws, naming every role,
|
|
3
|
+
* when the SQL does not match the declared kinds.
|
|
4
|
+
*/
|
|
5
|
+
export function scopeSqlBindings(bindings, storage) {
|
|
6
|
+
const wireName = bindings.entity.wireName;
|
|
7
|
+
const failures = mismatchedRoles(bindings.roles, storage.roles);
|
|
8
|
+
if (failures.length > 0) {
|
|
9
|
+
throw new Error(`scope SQL bindings for ${wireName} do not match its scope bindings:\n${failures
|
|
10
|
+
.map((failure) => ` ${failure}`)
|
|
11
|
+
.join("\n")}`);
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
wireName,
|
|
15
|
+
table: storage.table,
|
|
16
|
+
id: storage.id,
|
|
17
|
+
roles: storage.roles,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function mismatchedRoles(declared, rendered) {
|
|
21
|
+
const failures = [];
|
|
22
|
+
for (const [roleName, binding] of Object.entries(declared)) {
|
|
23
|
+
const roleSql = rendered[roleName];
|
|
24
|
+
if (binding.kind === "sparse-direct") {
|
|
25
|
+
if (roleSql !== undefined) {
|
|
26
|
+
failures.push(`role ${roleName} is sparse-direct and takes no SQL; the plan matches it on the id column`);
|
|
27
|
+
}
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (roleSql === undefined) {
|
|
31
|
+
failures.push(`role ${roleName} is bound as ${binding.kind} but has no SQL`);
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (roleSql.kind !== binding.kind) {
|
|
35
|
+
failures.push(`role ${roleName} is bound as ${binding.kind} but its SQL is for ${roleSql.kind}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
for (const roleName of Object.keys(rendered)) {
|
|
39
|
+
if (declared[roleName] === undefined) {
|
|
40
|
+
failures.push(`SQL names role ${roleName}, which the scope bindings do not bind`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return failures;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=scope-sql-bindings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope-sql-bindings.js","sourceRoot":"","sources":["../../../src/lib/scoped-lists/scope-sql-bindings.ts"],"names":[],"mappings":"AA6DA;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAC9B,QAA8B,EAC9B,OAIC;IAED,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC;IAC1C,MAAM,QAAQ,GAAG,eAAe,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IAChE,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACb,0BAA0B,QAAQ,sCAAsC,QAAQ;aAC7E,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,OAAO,EAAE,CAAC;aAChC,IAAI,CAAC,IAAI,CAAC,EAAE,CAChB,CAAC;IACJ,CAAC;IACD,OAAO;QACL,QAAQ;QACR,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,EAAE,EAAE,OAAO,CAAC,EAAE;QACd,KAAK,EAAE,OAAO,CAAC,KAAK;KACrB,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,QAA2B,EAAE,QAA2C;IAC/F,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,KAAK,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAc,QAAQ,CAAC,EAA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