@cosmicdrift/kumiko-framework 0.413.1 → 0.415.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/AGENTS.md +5 -2
- package/agents/api/framework-db.md +14 -3
- package/agents/api/framework-engine.md +69 -13
- package/agents/api/framework-errors.md +1 -1
- package/agents/api/framework-event-store.md +14 -0
- package/agents/api/framework-ui-types.md +158 -21
- package/agents/api/renderer-web.md +112 -11
- package/agents/api/testing-helpers.md +3 -2
- package/agents/api/testing-stack.md +3 -0
- package/agents/api/types.md +248 -24
- package/agents/api.md +7 -7
- package/agents/boot-rules.md +66 -10
- package/agents/examples/api-docs.md +2 -6
- package/agents/examples/auth-mfa.md +57 -10
- package/agents/examples/chat-channels.md +2 -0
- package/agents/examples/crypto-shredding-hr.md +63 -1
- package/agents/examples/currencies-global.md +1 -0
- package/agents/examples/env-composition.md +7 -11
- package/agents/examples/managed-pages.md +90 -1
- package/agents/examples/pwa-shell.md +210 -0
- package/agents/examples/rate-limiting.md +3 -3
- package/agents/examples/record-detail-layout.md +1643 -67
- package/agents/examples/workflow-engine.md +16 -12
- package/agents/examples.md +1 -0
- package/agents/features-index.md +4 -2
- package/agents/features.md +22 -7
- package/agents/widgets.md +26 -1
- package/dist/api/api-constants.d.ts +1 -0
- package/dist/api/api-constants.js +4 -0
- package/dist/api/auth-middleware.js +4 -3
- package/dist/api/auth-routes-shared.js +2 -1
- package/dist/api/entity-read-access.d.ts +1 -0
- package/dist/api/entity-read-access.js +18 -0
- package/dist/api/export/export-route.d.ts +6 -1
- package/dist/api/export/export-route.js +27 -1
- package/dist/api/export/export-rows.js +19 -3
- package/dist/api/request-context-internals.d.ts +2 -0
- package/dist/api/request-context-scopes.js +9 -2
- package/dist/api/request-context.js +1 -1
- package/dist/api/routes.d.ts +2 -0
- package/dist/api/routes.js +9 -1
- package/dist/api/server-event-dispatcher.js +3 -0
- package/dist/api/server-extra-routes.js +2 -1
- package/dist/api/server-feature-http-routes.d.ts +9 -0
- package/dist/api/server-feature-http-routes.js +109 -0
- package/dist/api/server-middleware.js +2 -19
- package/dist/api/server-pat-rate-limit-guard.d.ts +3 -0
- package/dist/api/server-pat-rate-limit-guard.js +19 -0
- package/dist/api/server-rate-limit-wiring.d.ts +10 -0
- package/dist/api/server-rate-limit-wiring.js +37 -0
- package/dist/api/server-routes.d.ts +4 -12
- package/dist/api/server-routes.js +12 -171
- package/dist/api/server-schema-route.d.ts +3 -0
- package/dist/api/server-schema-route.js +58 -0
- package/dist/api/server-wiring.js +2 -37
- package/dist/api/server.js +3 -1
- package/dist/compliance/override-schema.js +5 -5
- package/dist/compliance/sub-processors.js +10 -1
- package/dist/crypto/index.d.ts +1 -1
- package/dist/crypto/index.js +1 -1
- package/dist/crypto/pii-field-encryption.d.ts +2 -0
- package/dist/crypto/pii-field-encryption.js +16 -1
- package/dist/db/apply-entity-event.js +4 -0
- package/dist/db/bun-sql-connection-codes.d.ts +1 -0
- package/dist/db/bun-sql-connection-codes.js +7 -0
- package/dist/db/collect-table-metas.js +4 -1
- package/dist/db/config-seed.js +1 -1
- package/dist/db/derived-field-sql.js +15 -13
- package/dist/db/derived-related-sql.d.ts +2 -2
- package/dist/db/derived-related-sql.js +4 -2
- package/dist/db/dialect.d.ts +3 -0
- package/dist/db/dialect.js +1 -3
- package/dist/db/driver-row-coercion.js +2 -2
- package/dist/db/driver-value-preparation.js +1 -1
- package/dist/db/eagerload.js +15 -12
- package/dist/db/entity-table-meta.d.ts +2 -0
- package/dist/db/entity-table-meta.js +7 -0
- package/dist/db/event-store-executor-context.js +13 -8
- package/dist/db/event-store-executor-read-aggregate-currencies.js +2 -2
- package/dist/db/event-store-executor-read-aggregate.js +2 -2
- package/dist/db/event-store-executor-read-filter.d.ts +4 -0
- package/dist/db/event-store-executor-read-filter.js +28 -11
- package/dist/db/event-store-executor-read-search.d.ts +1 -0
- package/dist/db/event-store-executor-read-search.js +6 -6
- package/dist/db/event-store-executor-read-sort.js +3 -3
- package/dist/db/event-store-executor-read-where.js +14 -5
- package/dist/db/event-store-executor-read.js +7 -7
- package/dist/db/event-store-executor-write.js +50 -95
- package/dist/db/executor-managed-tables.js +4 -1
- package/dist/db/index.d.ts +4 -2
- package/dist/db/index.js +4 -2
- package/dist/db/known-table-names.d.ts +1 -0
- package/dist/db/known-table-names.js +7 -5
- package/dist/db/list-aggregate-labels.d.ts +1 -0
- package/dist/db/list-aggregate-labels.js +9 -1
- package/dist/db/migrate-generator.js +23 -4
- package/dist/db/migrate-rls-diff.d.ts +1 -0
- package/dist/db/migrate-rls-diff.js +15 -1
- package/dist/db/migrate-runner.js +2 -2
- package/dist/db/money.d.ts +1 -1
- package/dist/db/money.js +1 -4
- package/dist/db/parent-ref-clause.d.ts +6 -2
- package/dist/db/parent-ref-clause.js +105 -24
- package/dist/db/parent-ref-global-hosts.d.ts +23 -0
- package/dist/db/parent-ref-global-hosts.js +85 -0
- package/dist/db/production-schema-command-hint.d.ts +1 -0
- package/dist/db/production-schema-command-hint.js +3 -0
- package/dist/db/queries/backfill-pii.js +55 -29
- package/dist/db/queries/ddl.js +13 -2
- package/dist/db/queries/event-store-open-streams.d.ts +15 -0
- package/dist/db/queries/event-store-open-streams.js +33 -0
- package/dist/db/queries/event-store-payload-scrub.d.ts +5 -0
- package/dist/db/queries/event-store-payload-scrub.js +11 -0
- package/dist/db/queries/event-store.js +0 -1
- package/dist/db/queries/raw-sql.js +0 -1
- package/dist/db/queries/rebuild-rls-guard.d.ts +2 -1
- package/dist/db/queries/rebuild-rls-guard.js +24 -11
- package/dist/db/queries/rls-boot-catalog.d.ts +1 -0
- package/dist/db/queries/rls-boot-catalog.js +13 -9
- package/dist/db/queries/rls-shape.d.ts +3 -1
- package/dist/db/queries/rls-shape.js +31 -6
- package/dist/db/queries/session-advisory-lock.js +2 -1
- package/dist/db/queries/test-stack.js +7 -7
- package/dist/db/query.js +16 -11
- package/dist/db/rebuild-marker.js +11 -2
- package/dist/db/render-rls-ddl.d.ts +2 -0
- package/dist/db/render-rls-ddl.js +16 -11
- package/dist/db/replay-migration-sql.js +1 -1
- package/dist/db/row-level-security-boot-check.js +18 -5
- package/dist/db/row-level-security-connection.js +25 -12
- package/dist/db/row-level-security-scope.d.ts +2 -1
- package/dist/db/row-level-security-scope.js +9 -5
- package/dist/db/sql-identifier.d.ts +1 -0
- package/dist/db/sql-identifier.js +3 -0
- package/dist/db/system-tenant-read-db.d.ts +5 -0
- package/dist/db/system-tenant-read-db.js +28 -0
- package/dist/db/table-builder.d.ts +3 -1
- package/dist/db/table-builder.js +18 -8
- package/dist/db/table-info.d.ts +1 -2
- package/dist/db/table-introspection.d.ts +3 -0
- package/dist/db/table-introspection.js +6 -0
- package/dist/db/table-push.d.ts +1 -0
- package/dist/db/table-push.js +7 -1
- package/dist/db/tenant-db-runner.d.ts +3 -0
- package/dist/db/tenant-db-runner.js +19 -1
- package/dist/db/transaction-serialization.d.ts +1 -0
- package/dist/db/transaction-serialization.js +20 -3
- package/dist/db/where-clause.js +11 -2
- package/dist/db/write-ownership-failures.d.ts +25 -0
- package/dist/db/write-ownership-failures.js +82 -0
- package/dist/engine/boot-validator/boot-check.js +7 -1
- package/dist/engine/boot-validator/boot-phases-app.js +5 -5
- package/dist/engine/boot-validator/boot-phases.js +3 -2
- package/dist/engine/boot-validator/boot-rules.d.ts +305 -28
- package/dist/engine/boot-validator/boot-rules.js +4 -0
- package/dist/engine/boot-validator/bundled-lists-table.js +2 -2
- package/dist/engine/boot-validator/card-meta-overflow-rules.d.ts +2 -2
- package/dist/engine/boot-validator/card-meta-overflow-rules.js +2 -2
- package/dist/engine/boot-validator/card-meta-overflow.js +8 -5
- package/dist/engine/boot-validator/config-deps.d.ts +0 -1
- package/dist/engine/boot-validator/config-deps.js +0 -28
- package/dist/engine/boot-validator/config-key-rules.d.ts +0 -15
- package/dist/engine/boot-validator/config-key-rules.js +0 -15
- package/dist/engine/boot-validator/dashboard-screen-target.d.ts +22 -0
- package/dist/engine/boot-validator/dashboard-screen-target.js +20 -0
- package/dist/engine/boot-validator/dashboard-stat-navigate.d.ts +1 -0
- package/dist/engine/boot-validator/dashboard-stat-navigate.js +25 -17
- package/dist/engine/boot-validator/definition-webhook-events-rules.d.ts +5 -0
- package/dist/engine/boot-validator/definition-webhook-events-rules.js +5 -0
- package/dist/engine/boot-validator/derived-sql-fields.js +1 -2
- package/dist/engine/boot-validator/entity-declaration-rules.d.ts +5 -0
- package/dist/engine/boot-validator/entity-declaration-rules.js +5 -0
- package/dist/engine/boot-validator/entity-list-screens.d.ts +1 -0
- package/dist/engine/boot-validator/entity-list-screens.js +35 -13
- package/dist/engine/boot-validator/entity-structure-rules.d.ts +5 -0
- package/dist/engine/boot-validator/entity-structure-rules.js +5 -0
- package/dist/engine/boot-validator/list-column-layout.js +10 -6
- package/dist/engine/boot-validator/list-row-guidance-rules.d.ts +67 -0
- package/dist/engine/boot-validator/list-row-guidance-rules.js +67 -0
- package/dist/engine/boot-validator/list-row-guidance.d.ts +20 -0
- package/dist/engine/boot-validator/list-row-guidance.js +143 -0
- package/dist/engine/boot-validator/list-sort-summary-rules.d.ts +42 -0
- package/dist/engine/boot-validator/list-sort-summary-rules.js +42 -0
- package/dist/engine/boot-validator/list-sort-summary.d.ts +5 -0
- package/dist/engine/boot-validator/list-sort-summary.js +160 -0
- package/dist/engine/boot-validator/list-table-options.js +15 -1
- package/dist/engine/boot-validator/list-table-rules.d.ts +10 -5
- package/dist/engine/boot-validator/list-table-rules.js +10 -5
- package/dist/engine/boot-validator/list-toolbar-options.d.ts +10 -0
- package/dist/engine/boot-validator/list-toolbar-options.js +30 -0
- package/dist/engine/boot-validator/named-filter-rules.d.ts +42 -2
- package/dist/engine/boot-validator/named-filter-rules.js +42 -2
- package/dist/engine/boot-validator/ownership.js +10 -1
- package/dist/engine/boot-validator/parent-ref.js +87 -50
- package/dist/engine/boot-validator/projection-list-screens.d.ts +1 -0
- package/dist/engine/boot-validator/projection-list-screens.js +32 -1
- package/dist/engine/boot-validator/query-output-columns.js +62 -9
- package/dist/engine/boot-validator/query-output-guidance.d.ts +7 -0
- package/dist/engine/boot-validator/query-output-guidance.js +40 -0
- package/dist/engine/boot-validator/query-refs.js +34 -1
- package/dist/engine/boot-validator/row-decoration.d.ts +11 -0
- package/dist/engine/boot-validator/row-decoration.js +16 -0
- package/dist/engine/boot-validator/screens-actions.js +1 -1
- package/dist/engine/boot-validator/screens-dashboard-links.d.ts +10 -0
- package/dist/engine/boot-validator/screens-dashboard-links.js +36 -0
- package/dist/engine/boot-validator/screens-dashboard-narrow.d.ts +4 -0
- package/dist/engine/boot-validator/screens-dashboard-narrow.js +211 -0
- package/dist/engine/boot-validator/screens-dashboard-rules.d.ts +84 -4
- package/dist/engine/boot-validator/screens-dashboard-rules.js +84 -4
- package/dist/engine/boot-validator/screens-dashboard.js +29 -7
- package/dist/engine/boot-validator/screens-kind-entity-list.js +32 -27
- package/dist/engine/boot-validator/screens-kind-projection-detail-guidance.d.ts +3 -0
- package/dist/engine/boot-validator/screens-kind-projection-detail-guidance.js +46 -0
- package/dist/engine/boot-validator/screens-kind-projection-detail-rules.d.ts +20 -0
- package/dist/engine/boot-validator/screens-kind-projection-detail-rules.js +20 -0
- package/dist/engine/boot-validator/screens-kind-projection-detail.js +2 -0
- package/dist/engine/boot-validator/screens-kind-projection-list.js +4 -0
- package/dist/engine/boot-validator/screens-kind-rules.d.ts +25 -0
- package/dist/engine/boot-validator/screens-kind-rules.js +25 -0
- package/dist/engine/boot-validator/screens-lists.d.ts +8 -2
- package/dist/engine/boot-validator/screens-lists.js +19 -3
- package/dist/engine/boot-validator/screens.js +1 -1
- package/dist/engine/boot-validator/sort-nulls.d.ts +2 -0
- package/dist/engine/boot-validator/sort-nulls.js +15 -0
- package/dist/engine/boot-validator/zod-shape.d.ts +2 -1
- package/dist/engine/boot-validator/zod-shape.js +19 -1
- package/dist/engine/build-app-schema.js +4 -0
- package/dist/engine/config-helpers.d.ts +1 -2
- package/dist/engine/config-helpers.js +6 -7
- package/dist/engine/define-feature.js +1 -0
- package/dist/engine/define-handler.d.ts +1 -0
- package/dist/engine/define-handler.js +4 -2
- package/dist/engine/definition-violations.js +2 -2
- package/dist/engine/entity-handlers.js +3 -8
- package/dist/engine/entity-list-runtime-options.js +9 -8
- package/dist/engine/factories.d.ts +2 -0
- package/dist/engine/feature-config-events-jobs.js +1 -0
- package/dist/engine/feature-entity-handlers.js +5 -2
- package/dist/engine/field-access.d.ts +1 -1
- package/dist/engine/field-access.js +7 -10
- package/dist/engine/find-entity.js +3 -3
- package/dist/engine/form-derivations.js +3 -3
- package/dist/engine/index.d.ts +3 -3
- package/dist/engine/index.js +2 -2
- package/dist/engine/named-filter-roles.d.ts +3 -0
- package/dist/engine/named-filter-roles.js +15 -0
- package/dist/engine/pipeline.js +0 -1
- package/dist/engine/project-app-schema-for-roles.js +17 -2
- package/dist/engine/qualified-name.js +0 -1
- package/dist/engine/registry-facade.js +1 -2
- package/dist/engine/registry-state.d.ts +1 -1
- package/dist/engine/registry-state.js +5 -2
- package/dist/engine/registry-validate.js +2 -1
- package/dist/engine/resolve-named-list-filters.js +5 -2
- package/dist/engine/schema-builder.js +9 -11
- package/dist/engine/screen-helpers.d.ts +12 -0
- package/dist/engine/screen-helpers.js +17 -1
- package/dist/engine/soft-delete-cleanup.js +3 -5
- package/dist/engine/state-machine.js +0 -1
- package/dist/engine/steps/_database-clock.d.ts +2 -0
- package/dist/engine/steps/_database-clock.js +6 -0
- package/dist/engine/steps/compute.js +1 -1
- package/dist/engine/steps/retry.js +5 -1
- package/dist/engine/steps/return.js +0 -1
- package/dist/engine/steps/wait-for-event.js +2 -1
- package/dist/engine/steps/wait.js +2 -1
- package/dist/engine/system-user.d.ts +2 -2
- package/dist/engine/system-user.js +2 -2
- package/dist/engine/types/handlers.d.ts +1 -1
- package/dist/engine/types/handlers.js +1 -1
- package/dist/engine/types/screen.d.ts +1 -1
- package/dist/engine/types/screen.js +1 -1
- package/dist/engine/webhook-contracts.d.ts +2 -3
- package/dist/engine/webhook-contracts.js +2 -25
- package/dist/engine/webhook-events.js +48 -29
- package/dist/engine/webhook-payload-strictness.d.ts +7 -0
- package/dist/engine/webhook-payload-strictness.js +53 -0
- package/dist/env/_zod-introspect.d.ts +1 -0
- package/dist/env/dry-run.d.ts +1 -1
- package/dist/env/dry-run.js +1 -1
- package/dist/env/field-meta.d.ts +4 -0
- package/dist/env/field-meta.js +67 -0
- package/dist/env/field-rules.d.ts +9 -0
- package/dist/env/field-rules.js +46 -0
- package/dist/env/index.d.ts +3 -3
- package/dist/env/index.js +16 -71
- package/dist/env/internals.d.ts +3 -0
- package/dist/env/internals.js +1 -2
- package/dist/env/required-env.d.ts +3 -1
- package/dist/env/required-env.js +5 -2
- package/dist/errors/reasons.d.ts +1 -0
- package/dist/errors/reasons.js +4 -0
- package/dist/errors/serialize.js +2 -2
- package/dist/errors/write-error-info.js +0 -2
- package/dist/es-ops/operations-schema.js +18 -7
- package/dist/event-store/admin-api.js +3 -3
- package/dist/event-store/event-store.js +0 -3
- package/dist/event-store/index.d.ts +1 -0
- package/dist/event-store/index.js +1 -0
- package/dist/event-store/transfer.js +1 -1
- package/dist/files/assert-file-refs-belong-to-tenant.d.ts +2 -1
- package/dist/files/assert-file-refs-belong-to-tenant.js +15 -13
- package/dist/files/bind-pending-file-refs.d.ts +3 -1
- package/dist/files/bind-pending-file-refs.js +54 -27
- package/dist/files/copy-pending-file-refs-to-tenant.js +7 -3
- package/dist/files/create-file-ref.d.ts +4 -1
- package/dist/files/create-file-ref.js +14 -3
- package/dist/files/default-file-guard.js +4 -1
- package/dist/files/file-claim.d.ts +6 -0
- package/dist/files/file-claim.js +17 -0
- package/dist/files/file-field-slots.d.ts +2 -0
- package/dist/files/file-field-slots.js +28 -0
- package/dist/files/file-ref-entity.d.ts +3 -0
- package/dist/files/file-ref-entity.js +2 -0
- package/dist/files/file-ref-table.d.ts +3 -0
- package/dist/files/file-routes.d.ts +4 -1
- package/dist/files/file-routes.js +80 -16
- package/dist/files/in-memory-provider.d.ts +1 -1
- package/dist/files/in-memory-provider.js +2 -1
- package/dist/files/index.d.ts +1 -1
- package/dist/files/index.js +1 -1
- package/dist/files/invalid-file-ref-error.d.ts +2 -0
- package/dist/files/invalid-file-ref-error.js +15 -0
- package/dist/files/local-provider.js +9 -2
- package/dist/files/provider-resolver.js +1 -1
- package/dist/files/rebind-file-ref.d.ts +3 -2
- package/dist/files/rebind-file-ref.js +24 -18
- package/dist/files/resolve-file-handles.d.ts +13 -0
- package/dist/files/resolve-file-handles.js +57 -0
- package/dist/files/storage-tracking.d.ts +1 -1
- package/dist/files/storage-tracking.js +5 -2
- package/dist/files/sweep-stale-pending-file-refs.js +10 -4
- package/dist/files/types.d.ts +4 -0
- package/dist/files/types.js +10 -0
- package/dist/files/upload-field-resolution.d.ts +1 -0
- package/dist/files/upload-field-resolution.js +16 -2
- package/dist/files/upload-ledger.js +1 -1
- package/dist/i18n/required-surface-guidance-keys.d.ts +3 -0
- package/dist/i18n/required-surface-guidance-keys.js +9 -0
- package/dist/i18n/required-surface-keys.js +21 -5
- package/dist/internal/boot-rule-table-expectations.d.ts +2 -0
- package/dist/internal/boot-rule-table-expectations.js +29 -0
- package/dist/internal/row-level-security.d.ts +1 -0
- package/dist/internal/row-level-security.js +1 -0
- package/dist/internal/testing.d.ts +1 -0
- package/dist/internal/testing.js +1 -0
- package/dist/jobs/index.d.ts +1 -0
- package/dist/jobs/index.js +1 -0
- package/dist/jobs/job-load-events.d.ts +10 -0
- package/dist/jobs/job-load-events.js +12 -0
- package/dist/jobs/job-runner-context.js +6 -158
- package/dist/jobs/job-runner-dispatch.d.ts +7 -0
- package/dist/jobs/job-runner-dispatch.js +57 -0
- package/dist/jobs/job-runner-event-triggers.js +18 -9
- package/dist/jobs/job-runner-execution.js +5 -2
- package/dist/jobs/job-runner-facets.d.ts +48 -0
- package/dist/jobs/job-runner-facets.js +156 -0
- package/dist/jobs/job-runner-gates.js +19 -11
- package/dist/jobs/job-runner-helpers.d.ts +5 -1
- package/dist/jobs/job-runner-helpers.js +18 -3
- package/dist/jobs/job-runner-scope.d.ts +1 -0
- package/dist/jobs/job-runner-scope.js +2 -0
- package/dist/jobs/job-runner-tenant-cap-lock.d.ts +2 -0
- package/dist/jobs/job-runner-tenant-cap-lock.js +30 -0
- package/dist/jobs/job-runner-types.d.ts +1 -0
- package/dist/jobs/job-runner.js +39 -70
- package/dist/jobs/obliterate-job-queues.d.ts +6 -0
- package/dist/jobs/obliterate-job-queues.js +23 -0
- package/dist/lifecycle/lifecycle.js +1 -1
- package/dist/migrations/event-header-scrub.d.ts +11 -0
- package/dist/migrations/event-header-scrub.js +33 -0
- package/dist/migrations/event-payload-scrub.d.ts +1 -1
- package/dist/migrations/event-payload-scrub.js +36 -4
- package/dist/migrations/index.d.ts +1 -0
- package/dist/migrations/index.js +2 -0
- package/dist/migrations/kumiko-drift.d.ts +5 -2
- package/dist/migrations/kumiko-drift.js +51 -14
- package/dist/migrations/pending-rebuilds.js +4 -5
- package/dist/observability/sensitive-filter.js +0 -12
- package/dist/pipeline/aggregate-type-removal.js +17 -4
- package/dist/pipeline/context-services.d.ts +2 -0
- package/dist/pipeline/context-services.js +5 -2
- package/dist/pipeline/dispatch-batch.js +4 -3
- package/dist/pipeline/dispatch-context-helpers.d.ts +11 -0
- package/dist/pipeline/dispatch-context-helpers.js +58 -0
- package/dist/pipeline/dispatch-nested-write.d.ts +7 -0
- package/dist/pipeline/dispatch-nested-write.js +119 -0
- package/dist/pipeline/dispatch-query.js +10 -3
- package/dist/pipeline/dispatch-scope.js +4 -3
- package/dist/pipeline/dispatch-shared.d.ts +2 -6
- package/dist/pipeline/dispatch-shared.js +6 -38
- package/dist/pipeline/dispatch-write.d.ts +0 -1
- package/dist/pipeline/dispatch-write.js +3 -302
- package/dist/pipeline/dispatcher-utils.js +6 -0
- package/dist/pipeline/effective-system-scope.d.ts +3 -0
- package/dist/pipeline/effective-system-scope.js +22 -0
- package/dist/pipeline/event-dispatcher-delivery.d.ts +1 -0
- package/dist/pipeline/event-dispatcher-delivery.js +20 -9
- package/dist/pipeline/event-dispatcher.d.ts +6 -1
- package/dist/pipeline/event-dispatcher.js +6 -7
- package/dist/pipeline/handler-context-auth.d.ts +3 -2
- package/dist/pipeline/handler-context-auth.js +3 -4
- package/dist/pipeline/handler-context-db.js +11 -4
- package/dist/pipeline/handler-context-dispatch.js +2 -2
- package/dist/pipeline/handler-context-events.d.ts +8 -3
- package/dist/pipeline/handler-context-events.js +20 -65
- package/dist/pipeline/handler-context-member-resolution.js +16 -8
- package/dist/pipeline/handler-context-notify.d.ts +1 -0
- package/dist/pipeline/handler-context-notify.js +2 -0
- package/dist/pipeline/handler-context-phase-denials.js +3 -2
- package/dist/pipeline/handler-context-projection.d.ts +3 -0
- package/dist/pipeline/handler-context-projection.js +39 -0
- package/dist/pipeline/handler-context-scope.d.ts +1 -1
- package/dist/pipeline/handler-context-scope.js +14 -2
- package/dist/pipeline/index.d.ts +1 -1
- package/dist/pipeline/index.js +1 -1
- package/dist/pipeline/irreversible-operation-gate.js +36 -10
- package/dist/pipeline/lifecycle-pipeline.d.ts +1 -0
- package/dist/pipeline/lifecycle-pipeline.js +7 -4
- package/dist/pipeline/member-reader.js +4 -2
- package/dist/pipeline/msp-rebuild.js +1 -1
- package/dist/pipeline/nested-write-parent-guard.d.ts +5 -0
- package/dist/pipeline/nested-write-parent-guard.js +81 -0
- package/dist/pipeline/projection-rebuild.d.ts +2 -0
- package/dist/pipeline/projection-rebuild.js +16 -7
- package/dist/pipeline/projection-state.js +4 -6
- package/dist/pipeline/system-hooks.js +36 -6
- package/dist/pipeline/write-result-masking.js +31 -3
- package/dist/pipeline/write-transition-guard.d.ts +7 -0
- package/dist/pipeline/write-transition-guard.js +95 -0
- package/dist/schema-cli/shared.d.ts +2 -0
- package/dist/schema-cli/shared.js +4 -2
- package/dist/schema-cli/validate-command.js +43 -28
- package/dist/search/meilisearch-adapter-internals.d.ts +2 -0
- package/dist/search/meilisearch-adapter-internals.js +5 -0
- package/dist/search/meilisearch-adapter.d.ts +1 -0
- package/dist/search/meilisearch-adapter.js +17 -11
- package/dist/search/reindex-entity.d.ts +2 -0
- package/dist/search/reindex-entity.js +32 -4
- package/dist/search/reindex-tenants-search.js +20 -4
- package/dist/time/tz-context.js +1 -1
- package/dist/ui-types/card-column-roles.d.ts +6 -0
- package/dist/ui-types/card-column-roles.js +21 -3
- package/dist/ui-types/index.d.ts +3 -3
- package/dist/ui-types/index.js +2 -2
- package/dist/utils/ids.js +0 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/return-path-limit.d.ts +1 -0
- package/dist/utils/return-path-limit.js +1 -0
- package/package.json +5 -3
- package/presets/biome-app.json +39 -21
- package/presets/biome-plugins/admin-api.grit +10 -0
- package/presets/biome-plugins/error-reasons.grit +53 -0
- package/presets/biome-plugins/es-literal-writes-tests.grit +18 -0
- package/presets/biome-plugins/es-literal-writes.grit +22 -0
- package/presets/biome-plugins/i18n-locale-terminology-de.grit +15 -0
- package/presets/biome-plugins/i18n-locale-terminology-romance.grit +10 -0
- package/presets/biome-plugins/no-create-test-dispatcher.grit +5 -0
- package/presets/biome-plugins/no-css-properties-type.grit +7 -0
- package/presets/biome-plugins/no-date-api.grit +11 -0
- package/presets/biome-plugins/no-direct-fetch.grit +16 -0
- package/presets/biome-plugins/no-direct-fs.grit +16 -0
- package/presets/biome-plugins/no-external-font-cdn-css.grit +9 -0
- package/presets/biome-plugins/no-external-font-cdn.grit +12 -0
- package/presets/biome-plugins/no-raw-hooks.grit +10 -0
- package/presets/biome-plugins/no-same-folder-barrel-import.grit +11 -0
- package/presets/biome-plugins/no-screen-container-classes.grit +7 -0
- package/presets/biome-plugins/no-skipped-or-retried-tests.grit +34 -0
- package/presets/biome-plugins/no-temporal-polyfill-require.grit +10 -0
- package/presets/biome-plugins/raw-html-in-web.grit +40 -0
- package/presets/biome-plugins/raw-ui-in-app.grit +142 -0
- package/presets/biome-plugins/restricted-event-store-symbols.grit +18 -0
- package/presets/biome-plugins/test-title.grit +20 -0
- package/presets/biome-plugins/unsafe-json-parse.grit +12 -0
- package/presets/biome-rules.json +467 -0
- package/src/changes.json +366 -0
- package/dist/engine/minor-units.d.ts +0 -2
- package/dist/engine/minor-units.js +0 -8
|
@@ -24,6 +24,10 @@ export declare function deriveParentNarrowTypes(entity: EntityDefinition, payloa
|
|
|
24
24
|
readonly filter?: ListFilter;
|
|
25
25
|
readonly filters?: readonly ListFilter[];
|
|
26
26
|
}): ReadonlySet<string> | undefined;
|
|
27
|
+
export declare function deriveParentNarrowHostIds(entity: EntityDefinition, payload: {
|
|
28
|
+
readonly filter?: ListFilter;
|
|
29
|
+
readonly filters?: readonly ListFilter[];
|
|
30
|
+
}): ReadonlySet<string> | undefined;
|
|
27
31
|
export declare function collectListFilters(payload: {
|
|
28
32
|
readonly filter?: ListFilter | undefined;
|
|
29
33
|
readonly filters?: readonly ListFilter[] | undefined;
|
|
@@ -2,8 +2,11 @@ import { isPlainObject } from "@cosmicdrift/kumiko-types/type-guards";
|
|
|
2
2
|
import { computeBlindIndex, configuredBlindIndexKey } from "../crypto/index.js";
|
|
3
3
|
import { shiftParams } from "../engine/ownership.js";
|
|
4
4
|
import { ValidationError } from "../errors/index.js";
|
|
5
|
+
import { pgTypeToSqlType } from "./dialect.js";
|
|
5
6
|
import { isListFilterAllowed } from "./entity-field-encryption.js";
|
|
6
7
|
import { buildFilterWhere } from "./event-store-executor-context.js";
|
|
8
|
+
import { extractTableInfo } from "./table-info.js";
|
|
9
|
+
import { asEntityTableMeta } from "./table-introspection.js";
|
|
7
10
|
// Rebases a clause's local $1..$n onto `params` and returns the shifted text.
|
|
8
11
|
export function bindShiftedClause(params, clause) {
|
|
9
12
|
const shifted = shiftParams({ sqlText: clause.sqlText, params: clause.params }, params.length);
|
|
@@ -22,6 +25,17 @@ export function bindPlaceholders(params, values) {
|
|
|
22
25
|
})
|
|
23
26
|
.join(", ");
|
|
24
27
|
}
|
|
28
|
+
// One array parameter instead of one placeholder per value: Postgres rejects more than 65535 binds,
|
|
29
|
+
// and a long id list would also bloat the SQL text that lands in the plan cache.
|
|
30
|
+
function inListSql(table, colSql, params, field, values) {
|
|
31
|
+
const columnName = extractTableInfo(table).columnOf(field);
|
|
32
|
+
const pgType = asEntityTableMeta(table)?.columns.find((c) => c.name === columnName)?.pgType;
|
|
33
|
+
const arrayable = pgType !== undefined && pgType !== "jsonb" && pgType !== "serial" && pgType !== "bigserial";
|
|
34
|
+
if (!arrayable)
|
|
35
|
+
return `${colSql(field)} IN (${bindPlaceholders(params, values)})`;
|
|
36
|
+
params.push(values);
|
|
37
|
+
return `${colSql(field)} = ANY($${params.length}::${pgTypeToSqlType(pgType)}[])`;
|
|
38
|
+
}
|
|
25
39
|
// multiSelect stores its options as a jsonb array — a filter value is one
|
|
26
40
|
// option, not the whole array, so eq/ne/in must check array containment
|
|
27
41
|
// (`@>`) instead of scalar `=`/`<>`/`IN` against the jsonb column.
|
|
@@ -83,11 +97,7 @@ function applyScreenFilter(table, colSql, whereSql, params, f) {
|
|
|
83
97
|
whereSql.push(`${colSql(field)} IS NULL`);
|
|
84
98
|
}
|
|
85
99
|
else if (Array.isArray(value)) {
|
|
86
|
-
|
|
87
|
-
params.push(v);
|
|
88
|
-
return `$${params.length}`;
|
|
89
|
-
});
|
|
90
|
-
whereSql.push(`${colSql(field)} IN (${placeholders.join(", ")})`);
|
|
100
|
+
whereSql.push(inListSql(table, colSql, params, field, value));
|
|
91
101
|
}
|
|
92
102
|
else if (isPlainObject(value)) {
|
|
93
103
|
if (value["ne"] === null && Object.keys(value).length === 1) {
|
|
@@ -130,17 +140,24 @@ function applyScreenFilter(table, colSql, whereSql, params, f) {
|
|
|
130
140
|
// the SQL even needs to consider. Skipped for multiSelect fields, where `eq`
|
|
131
141
|
// means containment (see applyMultiSelectFilter) rather than equality.
|
|
132
142
|
export function deriveParentNarrowTypes(entity, payload) {
|
|
133
|
-
|
|
134
|
-
|
|
143
|
+
return pinnedParentFieldValues(entity, payload, entity.parentRef?.entityTypeField);
|
|
144
|
+
}
|
|
145
|
+
// Same subset argument for the host id field: a list pinned to some hosts only needs those
|
|
146
|
+
// hosts resolved.
|
|
147
|
+
export function deriveParentNarrowHostIds(entity, payload) {
|
|
148
|
+
return pinnedParentFieldValues(entity, payload, entity.parentRef?.entityIdField);
|
|
149
|
+
}
|
|
150
|
+
function pinnedParentFieldValues(entity, payload, parentField) {
|
|
151
|
+
if (parentField === undefined)
|
|
135
152
|
return undefined;
|
|
136
|
-
if (entity.fields[
|
|
153
|
+
if (entity.fields[parentField]?.type === "multiSelect")
|
|
137
154
|
return undefined;
|
|
138
|
-
const
|
|
155
|
+
const fieldFilters = [
|
|
139
156
|
...(payload.filter ? [payload.filter] : []),
|
|
140
157
|
...(payload.filters ?? []),
|
|
141
|
-
].filter((f) => f.field ===
|
|
158
|
+
].filter((f) => f.field === parentField);
|
|
142
159
|
let narrowed;
|
|
143
|
-
for (const f of
|
|
160
|
+
for (const f of fieldFilters) {
|
|
144
161
|
let values;
|
|
145
162
|
if (f.op === "eq" && typeof f.value === "string") {
|
|
146
163
|
values = [f.value];
|
|
@@ -10,6 +10,7 @@ import type { TenantDb } from "./tenant-db.ts";
|
|
|
10
10
|
type ReferenceSearchOption = NonNullable<Parameters<EventStoreExecutor["list"]>[3]>["referenceSearch"];
|
|
11
11
|
export declare function referenceTargetOwnership(targetEntity: EntityDefinition, targetTable: Table, targetTableName: string, user: SessionUser, db: TenantDb, parentVisibility: ParentVisibilityOption | undefined): OwnershipClause;
|
|
12
12
|
export declare function isSoftDeletedTargetHidden(targetEntity: EntityDefinition, targetTable: Table): boolean;
|
|
13
|
+
export declare function referenceTargetTable(name: string, entity: EntityDefinition): Table;
|
|
13
14
|
export type ListSearchRequest = {
|
|
14
15
|
readonly searchTerm: string;
|
|
15
16
|
readonly searchAdapter: SearchAdapter | undefined;
|
|
@@ -9,7 +9,7 @@ import { executeRawQueryRead } from "./queries/raw-sql.js";
|
|
|
9
9
|
import { resolveReadOwnership } from "./read-ownership.js";
|
|
10
10
|
import { buildEntityTable, physicalColumnName } from "./table-builder.js";
|
|
11
11
|
import { schemaTableName } from "./table-introspection.js";
|
|
12
|
-
import {
|
|
12
|
+
import { tenantDbRunnerForTable } from "./tenant-db-runner.js";
|
|
13
13
|
// Above this many target-row matches, drop the reference clause
|
|
14
14
|
// entirely instead of truncating: an arbitrary 200-row slice of "which
|
|
15
15
|
// targets match" would silently hide rows a full-cardinality match would
|
|
@@ -56,8 +56,8 @@ export function isSoftDeletedTargetHidden(targetEntity, targetTable) {
|
|
|
56
56
|
}
|
|
57
57
|
// Tenant-scoped ILIKE lookup against one reference target — never raw/
|
|
58
58
|
// unscoped SQL, a match in a foreign tenant must never surface a row here.
|
|
59
|
-
// Mirrors the main table's
|
|
60
|
-
//
|
|
59
|
+
// Mirrors the main table's tenant filter in appendTenantAndSoftDeleteScope
|
|
60
|
+
// (event-store-executor-read-where.ts) — keep in lock-step.
|
|
61
61
|
async function resolveReferenceMatchesViaIlike(descriptor, searchTerm, targetEntity, targetTable, targetTableName, user, db, parentVisibility) {
|
|
62
62
|
// The label must not leak through match counts: a viewer who cannot read the
|
|
63
63
|
// target row or its label field would otherwise probe names by searching.
|
|
@@ -88,7 +88,7 @@ async function resolveReferenceMatchesViaIlike(descriptor, searchTerm, targetEnt
|
|
|
88
88
|
// used as label) — Postgres has no ILIKE for those types otherwise.
|
|
89
89
|
const sql = `SELECT "id" FROM "${targetTableName}" WHERE ("${labelCol}")::text ILIKE $1${tenantClause}${ownershipClause}${deletedClause} ` +
|
|
90
90
|
`LIMIT ${MAX_REFERENCE_SEARCH_IDS + 1}`;
|
|
91
|
-
const rows = await executeRawQueryRead(
|
|
91
|
+
const rows = await executeRawQueryRead(tenantDbRunnerForTable(db, targetTable), sql, subParams);
|
|
92
92
|
if (rows.length === 0 || rows.length > MAX_REFERENCE_SEARCH_IDS) {
|
|
93
93
|
// skip: no match, or over the cap — drop the clause rather than
|
|
94
94
|
// truncate to an arbitrary slice of matching targets
|
|
@@ -134,7 +134,7 @@ async function resolveReferenceMatchesViaSearchIndex(descriptor, searchTerm, tar
|
|
|
134
134
|
}
|
|
135
135
|
const sql = `SELECT "id" FROM "${targetTableName}" WHERE "id" IN (${idPlaceholders.join(", ")})` +
|
|
136
136
|
`${tenantClause}${ownershipClause}`;
|
|
137
|
-
const rows = await executeRawQueryRead(
|
|
137
|
+
const rows = await executeRawQueryRead(tenantDbRunnerForTable(db, targetTable), sql, params);
|
|
138
138
|
if (rows.length === 0)
|
|
139
139
|
return undefined;
|
|
140
140
|
return { ownColumn: descriptor.ownColumn, ids: rows.map((r) => r.id) };
|
|
@@ -168,7 +168,7 @@ async function resolveReferenceMatches(descriptor, searchTerm, resolveEntity, db
|
|
|
168
168
|
// Building the table is pure but not free, and runs on every search request;
|
|
169
169
|
// keyed by the definition object so a re-registered entity never sees a stale table.
|
|
170
170
|
const referenceTargetTables = new WeakMap();
|
|
171
|
-
function referenceTargetTable(name, entity) {
|
|
171
|
+
export function referenceTargetTable(name, entity) {
|
|
172
172
|
const cached = referenceTargetTables.get(entity);
|
|
173
173
|
if (cached?.name === name)
|
|
174
174
|
return cached.table;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { buildOwnershipClause, normalizeAccessEntry, shiftParams, } from "../engine/ownership.js";
|
|
2
2
|
import { SYSTEM_TENANT_ID } from "../engine/types/identifiers.js";
|
|
3
3
|
import { isListSortAllowed, isSensitiveLabelField } from "./entity-field-encryption.js";
|
|
4
|
-
import { isSoftDeletedTargetHidden, referenceTargetOwnership, } from "./event-store-executor-read-search.js";
|
|
5
|
-
import {
|
|
4
|
+
import { isSoftDeletedTargetHidden, referenceTargetOwnership, referenceTargetTable, } from "./event-store-executor-read-search.js";
|
|
5
|
+
import { physicalColumnName } from "./table-builder.js";
|
|
6
6
|
import { schemaTableName } from "./table-introspection.js";
|
|
7
7
|
// Projected alongside the row when a reference sort is active, so the keyset
|
|
8
8
|
// cursor carries the label that was ordered by instead of the FK's UUID.
|
|
@@ -47,7 +47,7 @@ export function buildReferenceSortExpr(outerColumnSql, descriptor, resolveEntity
|
|
|
47
47
|
return undefined;
|
|
48
48
|
}
|
|
49
49
|
const targetTable = resolveTable?.(descriptor.targetEntityName) ??
|
|
50
|
-
|
|
50
|
+
referenceTargetTable(descriptor.targetEntityName, targetEntity);
|
|
51
51
|
// The order of labels the viewer may not read would leak them bit by bit, same as the search path.
|
|
52
52
|
const labelAccess = buildOwnershipClause(user, normalizeAccessEntry(targetEntity.fields[descriptor.labelField]?.access?.read), targetTable, 1, TARGET_ALIAS);
|
|
53
53
|
if (labelAccess.kind !== "pass")
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { buildOwnershipClause, normalizeAccessEntry, } from "../engine/ownership.js";
|
|
2
2
|
import { SYSTEM_TENANT_ID } from "../engine/types/identifiers.js";
|
|
3
3
|
import { ValidationError } from "../errors/index.js";
|
|
4
|
-
import { appendShiftedClause, applyListFilter, collectListFilters, deriveParentNarrowTypes, } from "./event-store-executor-read-filter.js";
|
|
4
|
+
import { appendShiftedClause, applyListFilter, collectListFilters, deriveParentNarrowHostIds, deriveParentNarrowTypes, } from "./event-store-executor-read-filter.js";
|
|
5
5
|
import { applyListSearch } from "./event-store-executor-read-search.js";
|
|
6
|
+
import { withGlobalParentHosts } from "./parent-ref-global-hosts.js";
|
|
6
7
|
import { resolveReadOwnership } from "./read-ownership.js";
|
|
7
8
|
import { physicalColumnName } from "./table-builder.js";
|
|
8
9
|
import { schemaTableName } from "./table-introspection.js";
|
|
@@ -39,13 +40,21 @@ export async function buildListWhere(ctx, payload, user, db, runtimeOptions) {
|
|
|
39
40
|
],
|
|
40
41
|
});
|
|
41
42
|
}
|
|
43
|
+
// Soft-deleted rows leave the search index, so a search over the trash would always come back
|
|
44
|
+
// empty; refusing is honest, an empty list would read as "nothing in the trash matches".
|
|
45
|
+
if (onlyDeleted && payload.search) {
|
|
46
|
+
throw new ValidationError({
|
|
47
|
+
fields: [
|
|
48
|
+
{ path: "search", code: "search_in_trash", i18nKey: "errors.validation.onlyDeleted" },
|
|
49
|
+
],
|
|
50
|
+
});
|
|
51
|
+
}
|
|
42
52
|
// The parent-visibility gate lifts its deleted-host predicate for a trash list the same way.
|
|
43
53
|
const includeDeleted = onlyDeleted || runtimeOptions?.includeDeleted === true;
|
|
54
|
+
const gate = { includeDeleted, narrowTypes: deriveParentNarrowTypes(entity, payload) };
|
|
55
|
+
const parentVisibility = await withGlobalParentHosts(ctx, user, db, runtimeOptions?.parentVisibility, gate, { kind: "list", pinnedHostIds: deriveParentNarrowHostIds(entity, payload) });
|
|
44
56
|
// Decide before touching search or the DB: an `empty` ownership skips both paths.
|
|
45
|
-
const ownership = resolveReadOwnership(ctx, tableName, user, db,
|
|
46
|
-
includeDeleted,
|
|
47
|
-
narrowTypes: deriveParentNarrowTypes(entity, payload),
|
|
48
|
-
});
|
|
57
|
+
const ownership = resolveReadOwnership(ctx, tableName, user, db, parentVisibility, gate);
|
|
49
58
|
if (ownership.kind === "empty")
|
|
50
59
|
return { kind: "empty" };
|
|
51
60
|
const where = {
|
|
@@ -7,9 +7,10 @@ import { appendCursorBoundary, countListRows, encodeNextCursor, resolveListPagin
|
|
|
7
7
|
import { appendStreamVersionProjection, coerceAndRehydrateRow, takeStreamVersions, withStreamVersion, } from "./event-store-executor-read-rows.js";
|
|
8
8
|
import { renderListOrderBy, resolveListSort, takeLastSortLabel, } from "./event-store-executor-read-sort.js";
|
|
9
9
|
import { buildListWhere } from "./event-store-executor-read-where.js";
|
|
10
|
+
import { withGlobalParentHosts } from "./parent-ref-global-hosts.js";
|
|
10
11
|
import { resolveReadOwnership } from "./read-ownership.js";
|
|
11
12
|
import { schemaTableName } from "./table-introspection.js";
|
|
12
|
-
import {
|
|
13
|
+
import { tenantDbRunnerForTable } from "./tenant-db-runner.js";
|
|
13
14
|
// The read verbs (list/aggregate/detail) of the event-store-executor. Split out
|
|
14
15
|
// of event-store-executor.ts — behavior-preserving relocation, not a redesign:
|
|
15
16
|
// unchanged from the original, now behind an explicit ExecutorContext instead
|
|
@@ -24,7 +25,7 @@ export function createReadVerbs(ctx) {
|
|
|
24
25
|
// list + detail are unchanged from crud-executor — projections are the
|
|
25
26
|
// read-model and serve these queries directly.
|
|
26
27
|
async list(payload, user, db, runtimeOptions) {
|
|
27
|
-
const runner =
|
|
28
|
+
const runner = tenantDbRunnerForTable(db, table);
|
|
28
29
|
const { limit, offset } = resolveListPagination(payload);
|
|
29
30
|
const totalCount = payload.totalCount === true;
|
|
30
31
|
const tableName = String(schemaTableName(table));
|
|
@@ -112,10 +113,9 @@ export function createReadVerbs(ctx) {
|
|
|
112
113
|
// db/parent-ref-clause.ts). `empty` → the user can never see this row
|
|
113
114
|
// regardless of its id. Return null (same shape as "not found", so a
|
|
114
115
|
// probing attacker can't distinguish "no access" from "doesn't exist").
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
});
|
|
116
|
+
const gate = { includeDeleted: false, narrowTypes: undefined };
|
|
117
|
+
const parentVisibility = await withGlobalParentHosts(ctx, user, db, options?.parentVisibility, gate, { kind: "row", rowId: payload.id });
|
|
118
|
+
const ownership = resolveReadOwnership(ctx, tableName, user, db, parentVisibility, gate);
|
|
119
119
|
if (ownership.kind === "empty")
|
|
120
120
|
return null;
|
|
121
121
|
const idWhere = idFilter(payload.id);
|
|
@@ -142,7 +142,7 @@ export function createReadVerbs(ctx) {
|
|
|
142
142
|
streamVersion = probe.streamVersion;
|
|
143
143
|
}
|
|
144
144
|
else {
|
|
145
|
-
streamVersion = await getStreamVersion(
|
|
145
|
+
streamVersion = await getStreamVersion(tenantDbRunnerForTable(db, table), String(payload.id), streamTenantFor(user));
|
|
146
146
|
}
|
|
147
147
|
if (!(streamVersion > 0 && cached["version"] !== streamVersion)) {
|
|
148
148
|
// Cached rows are stored re-encrypted (see the `set` below) so an
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ErasedSubjectHandlings, } from "../crypto/pii-field-encryption.js";
|
|
2
|
-
import { checkWriteFieldOwnership } from "../engine/field-access.js";
|
|
3
2
|
import { instructionFieldNames } from "../engine/instruction-fields.js";
|
|
4
|
-
import {
|
|
3
|
+
import { userCanWriteFieldRow } from "../engine/ownership.js";
|
|
5
4
|
import { buildInsertSchema, buildUpdateSchema } from "../engine/schema-builder.js";
|
|
6
5
|
import { isRecordLocked, isUnchangedValue } from "../engine/screen-helpers.js";
|
|
7
6
|
import { IdempotentReplayError, PreconditionFailedError, RecordLockedError, } from "../errors/classes.js";
|
|
@@ -9,6 +8,7 @@ import { AccessDeniedError, VersionConflictError as FrameworkVersionConflict, In
|
|
|
9
8
|
import { isSubjectErasedConflict } from "../errors/subject-erased.js";
|
|
10
9
|
import { IdempotentAppendConflictError as EventStoreIdempotentAppendConflict } from "../event-store/errors.js";
|
|
11
10
|
import { append, VersionConflictError as EventStoreVersionConflict, getStreamVersion, } from "../event-store/index.js";
|
|
11
|
+
import { resolveFileHandles } from "../files/resolve-file-handles.js";
|
|
12
12
|
import { assertInstructionFieldWriteAllowed, assertIrreversibleOperationAllowed, isIrreversibleEntityVerb, } from "../pipeline/irreversible-operation-gate.js";
|
|
13
13
|
import { generateId } from "../utils/index.js";
|
|
14
14
|
import { applyEntityEvent } from "./apply-entity-event.js";
|
|
@@ -19,7 +19,8 @@ import { fieldStateFailure, optimisticLockFailure, ownershipDeniedFailure, proje
|
|
|
19
19
|
import { isFrameworkSystemUser, isLockGuardBypassed } from "./lock-guard.js";
|
|
20
20
|
import { runInSavepointIfSupported } from "./query.js";
|
|
21
21
|
import { assertPersonalDataWrite, tableNameOf, withExecutorManagedWrites } from "./tenant-db.js";
|
|
22
|
-
import {
|
|
22
|
+
import { tenantDbWriteRunnerForTable } from "./tenant-db-runner.js";
|
|
23
|
+
import { createOwnershipFailure, updateOwnershipFailure } from "./write-ownership-failures.js";
|
|
23
24
|
// The five write verbs (create/update/delete/forget/restore) of the event-
|
|
24
25
|
// store-executor, split out of event-store-executor.ts. They read an explicit
|
|
25
26
|
// ExecutorContext instead of capturing the factory's local scope directly.
|
|
@@ -161,82 +162,6 @@ export function createWriteVerbs(ctx) {
|
|
|
161
162
|
assertPersonalDataWrite(db, tableNameOf(table), Object.keys(data), entity);
|
|
162
163
|
assertInstructionFieldWriteAllowed(entityName, action, Object.keys(data), entityInstructionFieldNames);
|
|
163
164
|
}
|
|
164
|
-
function createOwnershipFailure(user, streamTenantId, payloadWithoutId, data) {
|
|
165
|
-
// H.2 — entity-level write-ownership on create. No oldRow exists, so
|
|
166
|
-
// only the new row is checked. No Straddle concern for creates.
|
|
167
|
-
if (!userCanCreateFieldRow(ownershipSubject(user, streamTenantId), entity.access?.write, data)) {
|
|
168
|
-
return ownershipDeniedFailure({
|
|
169
|
-
scope: "entity",
|
|
170
|
-
entityName,
|
|
171
|
-
action: "create",
|
|
172
|
-
userId: user.id,
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
// Field-level write-ownership on create — mirror of entity-level but
|
|
176
|
-
// per declared field. Role-level was already checked by the
|
|
177
|
-
// dispatcher; here we enforce ownership-rules against the new row.
|
|
178
|
-
//
|
|
179
|
-
// Which fields get checked is scoped to the pre-hook payload
|
|
180
|
-
// — a hook-derived field the user never submitted must not be
|
|
181
|
-
// field-ownership-checked against the user. The rule for a checked
|
|
182
|
-
// field is still evaluated against the full post-hook row (`data`) —
|
|
183
|
-
// an ownership rule can reference a column only a hook populates.
|
|
184
|
-
const fieldDeniedCreate = checkWriteFieldOwnership(entity, applyDefaults(payloadWithoutId), ownershipSubject(user, streamTenantId), undefined, data);
|
|
185
|
-
if (fieldDeniedCreate) {
|
|
186
|
-
return ownershipDeniedFailure({
|
|
187
|
-
scope: "field",
|
|
188
|
-
entityName,
|
|
189
|
-
action: "create",
|
|
190
|
-
field: fieldDeniedCreate,
|
|
191
|
-
userId: user.id,
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
return undefined;
|
|
195
|
-
}
|
|
196
|
-
function updateOwnershipFailure(user, streamTenantId, id, submittedChanges, previous, changes, mergedNew) {
|
|
197
|
-
// H.2 — entity-level write-ownership on update. Load old row (already
|
|
198
|
-
// done above), build post-change row via shallow merge. Straddle-safe
|
|
199
|
-
// multi-role check: at least one role must accept BOTH old and new —
|
|
200
|
-
// prevents the attack where role A passes old, role B passes new and
|
|
201
|
-
// aggregation would wrongly allow a row-grab.
|
|
202
|
-
if (!userCanWriteFieldRow(ownershipSubject(user, streamTenantId), entity.access?.write, previous, mergedNew)) {
|
|
203
|
-
return ownershipDeniedFailure({
|
|
204
|
-
scope: "entity",
|
|
205
|
-
entityName,
|
|
206
|
-
action: "update",
|
|
207
|
-
userId: user.id,
|
|
208
|
-
entityId: id,
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
// Field-level write-ownership on update — this is the path the
|
|
212
|
-
// dispatcher could not evaluate (no oldRow). Now that we have
|
|
213
|
-
// `previous`, we can run the ownership rules per field against both
|
|
214
|
-
// sides and reject individual fields the user isn't entitled to
|
|
215
|
-
// touch on this specific row.
|
|
216
|
-
//
|
|
217
|
-
// Which fields get checked is scoped to `payload.changes` (the user's
|
|
218
|
-
// actual submission), NOT `changes` (post-preSave-hook data)
|
|
219
|
-
// — a hook-derived field the user never submitted (e.g. a system hook
|
|
220
|
-
// setting `assignedTo`) has no business being field-ownership-checked
|
|
221
|
-
// against the *user*, and doing so rejects writes the user is fully
|
|
222
|
-
// entitled to make. The dispatcher's role-gate (checkWriteFieldAccess)
|
|
223
|
-
// already runs on this same pre-hook payload for consistency. The rule
|
|
224
|
-
// for a checked field is still evaluated against the full post-hook
|
|
225
|
-
// row (`changes` merged onto `previous`) — an ownership rule can
|
|
226
|
-
// reference a column only a hook populates.
|
|
227
|
-
const fieldDeniedUpdate = checkWriteFieldOwnership(entity, submittedChanges, ownershipSubject(user, streamTenantId), previous, changes);
|
|
228
|
-
if (fieldDeniedUpdate) {
|
|
229
|
-
return ownershipDeniedFailure({
|
|
230
|
-
scope: "field",
|
|
231
|
-
entityName,
|
|
232
|
-
action: "update",
|
|
233
|
-
field: fieldDeniedUpdate,
|
|
234
|
-
userId: user.id,
|
|
235
|
-
entityId: id,
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
return undefined;
|
|
239
|
-
}
|
|
240
165
|
function updateSelectOptionFailure(user, mergedNew, previous, options) {
|
|
241
166
|
// Statutory retention/erasure writes may change a condition field (e.g. null a PII
|
|
242
167
|
// reference) and must not be blocked by the select rule — same exemption as the lock.
|
|
@@ -431,19 +356,31 @@ export function createWriteVerbs(ctx) {
|
|
|
431
356
|
const streamTenantMismatch = streamTenantCreateFailure(db, payload, streamTenantId);
|
|
432
357
|
if (streamTenantMismatch)
|
|
433
358
|
return streamTenantMismatch;
|
|
434
|
-
const runner =
|
|
359
|
+
const runner = tenantDbWriteRunnerForTable(db, "ctx.db executor create", table);
|
|
435
360
|
// Respect an explicit id in the payload (seed pattern, SCIM import). Without
|
|
436
361
|
// one the framework mints a fresh UUIDv7 via generateId. Strip it out of the
|
|
437
362
|
// event payload so defaults + downstream consumers don't see a redundant id field.
|
|
438
363
|
const explicitId = typeof payload["id"] === "string" ? payload["id"] : undefined; // @cast-boundary engine-payload
|
|
439
364
|
const aggregateId = explicitId ?? generateId();
|
|
440
|
-
const { id: _id, ...
|
|
365
|
+
const { id: _id, ...payloadWithHandles } = payload;
|
|
366
|
+
const handles = await resolveFileHandles(entity, entityName, payloadWithHandles, db, user);
|
|
367
|
+
if ("failure" in handles)
|
|
368
|
+
return handles.failure;
|
|
369
|
+
const payloadWithoutId = handles.values;
|
|
441
370
|
const preSaveResult = await runPreSave(options?.preSave, applyDefaults(payloadWithoutId), {}, true, entityName, "create", createOutputSchema);
|
|
442
371
|
if ("failure" in preSaveResult)
|
|
443
372
|
return preSaveResult.failure;
|
|
444
373
|
const data = preSaveResult.data;
|
|
445
374
|
assertFieldWritesAllowed(db, "create", data);
|
|
446
|
-
const ownershipDenied = createOwnershipFailure(
|
|
375
|
+
const ownershipDenied = createOwnershipFailure({
|
|
376
|
+
entity,
|
|
377
|
+
entityName,
|
|
378
|
+
user,
|
|
379
|
+
streamTenantId,
|
|
380
|
+
payloadWithoutId,
|
|
381
|
+
data,
|
|
382
|
+
applyDefaults,
|
|
383
|
+
});
|
|
447
384
|
if (ownershipDenied)
|
|
448
385
|
return ownershipDenied;
|
|
449
386
|
const invalidFieldState = fieldStateFailure(entity.fields, data);
|
|
@@ -485,31 +422,46 @@ export function createWriteVerbs(ctx) {
|
|
|
485
422
|
// Persisted event carries ciphertext by design — the caller-facing
|
|
486
423
|
// echo must be plaintext like every other response field.
|
|
487
424
|
event: echoEvent,
|
|
425
|
+
claimedFileRefIds: handles.claimedFileRefIds,
|
|
488
426
|
},
|
|
489
427
|
};
|
|
490
428
|
},
|
|
491
429
|
async update(payload, user, db, updateOptions) {
|
|
492
|
-
const runner =
|
|
430
|
+
const runner = tenantDbWriteRunnerForTable(db, "ctx.db executor update", table);
|
|
493
431
|
assertTenantAllowedOnGlobalEntity("update", "payload.changes.tenantId", payload.changes["tenantId"]);
|
|
432
|
+
const unreadable = await unreadableRowFailure(payload.id, user, db, updateOptions?.parentVisibility);
|
|
433
|
+
if (unreadable)
|
|
434
|
+
return unreadable;
|
|
494
435
|
const previous = await loadById(payload.id, db, {
|
|
495
436
|
includeDeleted: updateOptions?.includeDeleted === true,
|
|
496
437
|
});
|
|
497
438
|
if (!previous)
|
|
498
439
|
return writeFailure(new NotFoundError(entityName, payload.id));
|
|
499
|
-
const unreadable = await unreadableRowFailure(payload.id, user, db, updateOptions?.parentVisibility);
|
|
500
|
-
if (unreadable)
|
|
501
|
-
return unreadable;
|
|
502
440
|
const streamTenantId = updateOptions?.streamTenantId;
|
|
503
441
|
const streamTenantMismatch = streamTenantOverrideFailure(db, previous, streamTenantId);
|
|
504
442
|
if (streamTenantMismatch)
|
|
505
443
|
return streamTenantMismatch;
|
|
506
|
-
const
|
|
444
|
+
const handles = await resolveFileHandles(entity, entityName, payload.changes, db, user);
|
|
445
|
+
if ("failure" in handles)
|
|
446
|
+
return handles.failure;
|
|
447
|
+
const submittedChanges = { ...handles.values };
|
|
448
|
+
const preSaveResult = await runPreSave(updateOptions?.preSave, submittedChanges, previous, false, entityName, "update", updateOutputSchema);
|
|
507
449
|
if ("failure" in preSaveResult)
|
|
508
450
|
return preSaveResult.failure;
|
|
509
451
|
const changes = preSaveResult.data;
|
|
510
452
|
assertFieldWritesAllowed(db, "update", changes);
|
|
511
453
|
const mergedNew = { ...previous, ...changes };
|
|
512
|
-
const guardFailure = updateOwnershipFailure(
|
|
454
|
+
const guardFailure = updateOwnershipFailure({
|
|
455
|
+
entity,
|
|
456
|
+
entityName,
|
|
457
|
+
user,
|
|
458
|
+
streamTenantId,
|
|
459
|
+
id: payload.id,
|
|
460
|
+
submittedChanges,
|
|
461
|
+
previous,
|
|
462
|
+
changes,
|
|
463
|
+
mergedNew,
|
|
464
|
+
}) ??
|
|
513
465
|
recordLockedFailure(previous, payload.id, user, updateOptions) ??
|
|
514
466
|
updateSelectOptionFailure(user, mergedNew, previous, updateOptions);
|
|
515
467
|
if (guardFailure)
|
|
@@ -550,6 +502,7 @@ export function createWriteVerbs(ctx) {
|
|
|
550
502
|
isNew: false,
|
|
551
503
|
entityName,
|
|
552
504
|
event: echoEvent,
|
|
505
|
+
claimedFileRefIds: handles.claimedFileRefIds,
|
|
553
506
|
},
|
|
554
507
|
};
|
|
555
508
|
}
|
|
@@ -569,13 +522,13 @@ export function createWriteVerbs(ctx) {
|
|
|
569
522
|
if (isIrreversibleEntityVerb("delete", entity)) {
|
|
570
523
|
assertIrreversibleOperationAllowed(`${entityName}.delete (entity has no softDelete)`);
|
|
571
524
|
}
|
|
572
|
-
const runner =
|
|
573
|
-
const existing = await loadById(payload.id, db);
|
|
574
|
-
if (!existing)
|
|
575
|
-
return writeFailure(new NotFoundError(entityName, payload.id));
|
|
525
|
+
const runner = tenantDbWriteRunnerForTable(db, "ctx.db executor delete", table);
|
|
576
526
|
const unreadable = await unreadableRowFailure(payload.id, user, db, options?.parentVisibility);
|
|
577
527
|
if (unreadable)
|
|
578
528
|
return unreadable;
|
|
529
|
+
const existing = await loadById(payload.id, db);
|
|
530
|
+
if (!existing)
|
|
531
|
+
return writeFailure(new NotFoundError(entityName, payload.id));
|
|
579
532
|
const streamTenantId = options?.streamTenantId;
|
|
580
533
|
const streamTenantMismatch = streamTenantOverrideFailure(db, existing, streamTenantId);
|
|
581
534
|
if (streamTenantMismatch)
|
|
@@ -598,7 +551,9 @@ export function createWriteVerbs(ctx) {
|
|
|
598
551
|
return lockedDelete;
|
|
599
552
|
await assertStreamWritable(db, payload.id, streamTenantFor(user, streamTenantId));
|
|
600
553
|
// Stream-version authoritative (see update() for rationale).
|
|
601
|
-
const currentVersion = await
|
|
554
|
+
const currentVersion = await currentStreamVersion(db, runner, payload.id, streamTenantFor(user, streamTenantId), options?.expect);
|
|
555
|
+
if (typeof currentVersion !== "number")
|
|
556
|
+
return currentVersion;
|
|
602
557
|
// Deletes carry the full pre-delete row as `previous`. That's what
|
|
603
558
|
// projections and downstream consumers need to reverse any aggregates —
|
|
604
559
|
// a `{}`-payload delete would make cross-aggregate projections impossible
|
|
@@ -656,7 +611,7 @@ export function createWriteVerbs(ctx) {
|
|
|
656
611
|
// without the isDeleted filter so trashed (soft-deleted) rows are erased too.
|
|
657
612
|
async forget(payload, user, db, options) {
|
|
658
613
|
assertIrreversibleOperationAllowed(`${entityName}.forget`);
|
|
659
|
-
const runner =
|
|
614
|
+
const runner = tenantDbWriteRunnerForTable(db, "ctx.db executor forget", table);
|
|
660
615
|
const raw = await db.fetchOne(table, { id: payload.id });
|
|
661
616
|
if (!raw)
|
|
662
617
|
return writeFailure(new NotFoundError(entityName, payload.id));
|
|
@@ -732,7 +687,7 @@ export function createWriteVerbs(ctx) {
|
|
|
732
687
|
i18nKey: "errors.softDeleteNotEnabled",
|
|
733
688
|
}));
|
|
734
689
|
}
|
|
735
|
-
const runner =
|
|
690
|
+
const runner = tenantDbWriteRunnerForTable(db, "ctx.db executor restore", table);
|
|
736
691
|
const streamTenantId = options?.streamTenantId;
|
|
737
692
|
// Before loadSoftDeletedRow: its not_deleted answer would confirm that an unreadable
|
|
738
693
|
// live row exists.
|
|
@@ -9,8 +9,11 @@ export function markExecutorManagedTable(table, entitySource) {
|
|
|
9
9
|
const meta = asEntityTableMeta(table);
|
|
10
10
|
if (meta !== undefined)
|
|
11
11
|
executorManagedTables.add(meta);
|
|
12
|
-
if (entitySource !== undefined)
|
|
12
|
+
if (entitySource !== undefined) {
|
|
13
13
|
entitySourceByTable.set(table, entitySource);
|
|
14
|
+
if (meta !== undefined)
|
|
15
|
+
entitySourceByTable.set(meta, entitySource);
|
|
16
|
+
}
|
|
14
17
|
}
|
|
15
18
|
export function executorManagedEntitySourceOf(table) {
|
|
16
19
|
if (typeof table !== "object" || table === null)
|
package/dist/db/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { isTimestamptzType } from "./aggregate-sql.ts";
|
|
|
2
2
|
export { applyEntityEvent } from "./apply-entity-event.ts";
|
|
3
3
|
export { assertExistsIn } from "./assert-exists-in.ts";
|
|
4
4
|
export { nullBlindIndexesForSubject, recordEventsOwnedExclusivelyByTenant, recordRowExistsInTenant, recordRowOwningTenantId, subjectRowExistsInTenant, } from "./blind-index-cleanup.ts";
|
|
5
|
+
export { BUN_SQL_CONNECTION_ERROR_CODES } from "./bun-sql-connection-codes.ts";
|
|
5
6
|
export { collectTableMetas } from "./collect-table-metas.ts";
|
|
6
7
|
export { seedConfigValues } from "./config-seed.ts";
|
|
7
8
|
export type { DbConnection, DbRow, DbRunner, DbTx, } from "./connection.ts";
|
|
@@ -24,7 +25,7 @@ export { runMigrationsFromDir } from "./migrate-runner.ts";
|
|
|
24
25
|
export { type MoneyRead, rehydrateMoney } from "./money.ts";
|
|
25
26
|
export { extractPgError, isUndefinedTable, isUniqueViolation, } from "./pg-error.ts";
|
|
26
27
|
export { acquireNamespacedAdvisoryLock } from "./queries/advisory-lock.ts";
|
|
27
|
-
export { readDatabaseNow } from "./queries/database-now.ts";
|
|
28
|
+
export { queryDatabaseNow, readDatabaseNow } from "./queries/database-now.ts";
|
|
28
29
|
export { listEventTenantIds } from "./queries/event-tenants.ts";
|
|
29
30
|
export { toPostgresArrayLiteral } from "./queries/postgres-array-literal.ts";
|
|
30
31
|
export { executeRawQuery } from "./queries/raw-sql.ts";
|
|
@@ -37,11 +38,12 @@ export { ROW_LEVEL_SECURITY_MODES, type RowLevelSecurityMode } from "./render-rl
|
|
|
37
38
|
export { assertRowLevelSecurityBootState, assertRowLevelSecurityTableState, } from "./row-level-security-boot-check.ts";
|
|
38
39
|
export { rowLevelSecurityModeOf } from "./row-level-security-connection.ts";
|
|
39
40
|
export type { RowLevelSecurityScope } from "./row-level-security-scope.ts";
|
|
40
|
-
export { assertNoActiveRowLevelSecurityScope } from "./row-level-security-scope.ts";
|
|
41
|
+
export { assertNoActiveRowLevelSecurityScope, outsideRowLevelSecurityScope, } from "./row-level-security-scope.ts";
|
|
41
42
|
export { tableExists } from "./schema-inspection.ts";
|
|
42
43
|
export { scopeTenantDbToTenant } from "./scope-tenant-db-to-tenant.ts";
|
|
43
44
|
export { buildBaseColumns, buildEntityTable, declareGlobalTenancy, type EntityTable, type ExecutorManagedRunner, physicalColumnName, type WritableSchemaTable, type WritableTable, } from "./table-builder.ts";
|
|
44
45
|
export { extractTableInfo, type TableInfo } from "./table-info.ts";
|
|
46
|
+
export { isSchemaTable } from "./table-introspection.ts";
|
|
45
47
|
export type { ExecutorManagedTenantDb, TenantDb, UncheckedSystemDb, } from "./tenant-db.ts";
|
|
46
48
|
export { castTenantRows, createSystemDbView, createTenantDataDestroyDb, createTenantDb, } from "./tenant-db.ts";
|
|
47
49
|
export { runInOwnTransaction } from "./tenant-db-scoped-rebind.ts";
|
package/dist/db/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export { isTimestamptzType } from "./aggregate-sql.js";
|
|
|
2
2
|
export { applyEntityEvent } from "./apply-entity-event.js";
|
|
3
3
|
export { assertExistsIn } from "./assert-exists-in.js";
|
|
4
4
|
export { nullBlindIndexesForSubject, recordEventsOwnedExclusivelyByTenant, recordRowExistsInTenant, recordRowOwningTenantId, subjectRowExistsInTenant, } from "./blind-index-cleanup.js";
|
|
5
|
+
export { BUN_SQL_CONNECTION_ERROR_CODES } from "./bun-sql-connection-codes.js";
|
|
5
6
|
export { collectTableMetas } from "./collect-table-metas.js";
|
|
6
7
|
export { seedConfigValues } from "./config-seed.js";
|
|
7
8
|
export { createDbConnection, DEFAULT_OUTSIDE_TRANSACTION_POOL_MAX, dbConnectionOptionsFromEnv, outsideTransactionPoolOptionsFromEnv, serverTimeoutOptionsFromEnv, } from "./connection.js";
|
|
@@ -20,7 +21,7 @@ export { runMigrationsFromDir } from "./migrate-runner.js";
|
|
|
20
21
|
export { rehydrateMoney } from "./money.js";
|
|
21
22
|
export { extractPgError, isUndefinedTable, isUniqueViolation, } from "./pg-error.js";
|
|
22
23
|
export { acquireNamespacedAdvisoryLock } from "./queries/advisory-lock.js";
|
|
23
|
-
export { readDatabaseNow } from "./queries/database-now.js";
|
|
24
|
+
export { queryDatabaseNow, readDatabaseNow } from "./queries/database-now.js";
|
|
24
25
|
export { listEventTenantIds } from "./queries/event-tenants.js";
|
|
25
26
|
export { toPostgresArrayLiteral } from "./queries/postgres-array-literal.js";
|
|
26
27
|
export { executeRawQuery } from "./queries/raw-sql.js";
|
|
@@ -31,10 +32,11 @@ export { renderTablesDdl } from "./render-ddl.js";
|
|
|
31
32
|
export { ROW_LEVEL_SECURITY_MODES } from "./render-rls-ddl.js";
|
|
32
33
|
export { assertRowLevelSecurityBootState, assertRowLevelSecurityTableState, } from "./row-level-security-boot-check.js";
|
|
33
34
|
export { rowLevelSecurityModeOf } from "./row-level-security-connection.js";
|
|
34
|
-
export { assertNoActiveRowLevelSecurityScope } from "./row-level-security-scope.js";
|
|
35
|
+
export { assertNoActiveRowLevelSecurityScope, outsideRowLevelSecurityScope, } from "./row-level-security-scope.js";
|
|
35
36
|
export { tableExists } from "./schema-inspection.js";
|
|
36
37
|
export { scopeTenantDbToTenant } from "./scope-tenant-db-to-tenant.js";
|
|
37
38
|
export { buildBaseColumns, buildEntityTable, declareGlobalTenancy, physicalColumnName, } from "./table-builder.js";
|
|
38
39
|
export { extractTableInfo } from "./table-info.js";
|
|
40
|
+
export { isSchemaTable } from "./table-introspection.js";
|
|
39
41
|
export { castTenantRows, createSystemDbView, createTenantDataDestroyDb, createTenantDb, } from "./tenant-db.js";
|
|
40
42
|
export { runInOwnTransaction } from "./tenant-db-scoped-rebind.js";
|
|
@@ -2,5 +2,6 @@ import type { FeatureDefinition } from "../engine/types/index.ts";
|
|
|
2
2
|
export declare function isLiveFrameworkTable(tableName: string): boolean;
|
|
3
3
|
export type KnownTables = {
|
|
4
4
|
readonly has: (tableName: string) => boolean;
|
|
5
|
+
readonly readsSystemRows: (tableName: string) => boolean;
|
|
5
6
|
};
|
|
6
7
|
export declare function knownTablesOf(features: readonly FeatureDefinition[]): KnownTables;
|
|
@@ -11,11 +11,13 @@ export function isLiveFrameworkTable(tableName) {
|
|
|
11
11
|
// Same source as `kumiko schema generate`: a tenant table that is not listed here has no owner left.
|
|
12
12
|
export function knownTablesOf(features) {
|
|
13
13
|
// Lazy: a healthy boot finds no unprotected table and never asks, so it skips collecting metas.
|
|
14
|
-
let
|
|
14
|
+
let metas;
|
|
15
|
+
const metaOf = (tableName) => {
|
|
16
|
+
metas ??= new Map(collectTableMetas(features).map((meta) => [meta.tableName, meta]));
|
|
17
|
+
return metas.get(tableName);
|
|
18
|
+
};
|
|
15
19
|
return {
|
|
16
|
-
has: (tableName) =>
|
|
17
|
-
|
|
18
|
-
return names.has(tableName) || isLiveFrameworkTable(tableName);
|
|
19
|
-
},
|
|
20
|
+
has: (tableName) => metaOf(tableName) !== undefined || isLiveFrameworkTable(tableName),
|
|
21
|
+
readsSystemRows: (tableName) => metaOf(tableName)?.systemRowsReadable === true,
|
|
20
22
|
};
|
|
21
23
|
}
|
|
@@ -9,6 +9,7 @@ type LabelDeps = {
|
|
|
9
9
|
readonly viewer: EagerLoadViewer;
|
|
10
10
|
};
|
|
11
11
|
export declare function labelListAggregateGroups(result: ListAggregateResult, groupByField: string | undefined, deps: LabelDeps, db: TenantDb): Promise<ListAggregateResult>;
|
|
12
|
+
export declare function isAnsweredListAggregate(value: unknown): value is ListAggregateResult;
|
|
12
13
|
type AggregateRequest = Parameters<EventStoreExecutor["aggregate"]>[0];
|
|
13
14
|
export declare function answerListAggregate(executor: Pick<EventStoreExecutor, "aggregate">, request: AggregateRequest, user: Parameters<EventStoreExecutor["aggregate"]>[1], db: TenantDb, runtimeOptions: Parameters<EventStoreExecutor["aggregate"]>[3], labelDeps: LabelDeps): Promise<ListAggregateResult>;
|
|
14
15
|
export {};
|
|
@@ -20,7 +20,15 @@ export async function labelListAggregateGroups(result, groupByField, deps, db) {
|
|
|
20
20
|
});
|
|
21
21
|
return { ...result, groups };
|
|
22
22
|
}
|
|
23
|
+
// Brand by identity: only results built by answerListAggregate skip the row-shaped read pipeline,
|
|
24
|
+
// a handler that merely returns `{ groups: [...] }` does not.
|
|
25
|
+
const answeredAggregates = new WeakSet();
|
|
26
|
+
export function isAnsweredListAggregate(value) {
|
|
27
|
+
return typeof value === "object" && value !== null && answeredAggregates.has(value);
|
|
28
|
+
}
|
|
23
29
|
export async function answerListAggregate(executor, request, user, db, runtimeOptions, labelDeps) {
|
|
24
30
|
const result = await executor.aggregate(request, user, db, runtimeOptions);
|
|
25
|
-
|
|
31
|
+
const labelled = await labelListAggregateGroups(result, request.aggregate.groupBy, labelDeps, db);
|
|
32
|
+
answeredAggregates.add(labelled);
|
|
33
|
+
return labelled;
|
|
26
34
|
}
|