@cosmicdrift/kumiko-framework 0.413.0 → 0.414.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 +64 -13
- package/agents/api/framework-event-store.md +14 -0
- package/agents/api/framework-ui-types.md +149 -21
- package/agents/api/renderer-web.md +93 -9
- package/agents/api/testing-helpers.md +3 -2
- package/agents/api/testing-stack.md +3 -0
- package/agents/api/types.md +205 -14
- package/agents/api.md +7 -7
- package/agents/boot-rules.md +63 -9
- 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/currencies-global.md +1 -0
- package/agents/examples/env-composition.md +7 -11
- package/agents/examples/helpdesk.md +15 -8
- 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 +1537 -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 +19 -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/routes.d.ts +2 -0
- package/dist/api/routes.js +9 -1
- 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 +76 -23
- package/dist/db/parent-ref-global-hosts.d.ts +20 -0
- package/dist/db/parent-ref-global-hosts.js +47 -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 -8
- package/dist/db/queries/rls-shape.d.ts +2 -1
- package/dist/db/queries/rls-shape.js +10 -0
- 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 +293 -26
- 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.js +1 -0
- 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 +33 -6
- 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 +129 -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 +149 -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 +31 -0
- package/dist/engine/boot-validator/named-filter-rules.d.ts +32 -2
- package/dist/engine/boot-validator/named-filter-rules.js +32 -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 +31 -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 +39 -0
- package/dist/engine/boot-validator/query-refs.js +24 -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-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 +23 -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.d.ts +1 -0
- package/dist/engine/registry-validate.js +9 -1
- package/dist/engine/registry.js +2 -1
- package/dist/engine/resolve-named-list-filters.js +5 -2
- package/dist/engine/schema-builder.js +6 -10
- package/dist/engine/screen-helpers.d.ts +12 -0
- package/dist/engine/screen-helpers.js +17 -1
- package/dist/engine/soft-delete-cleanup.js +5 -8
- 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/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/feature.js +1 -0
- 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 +19 -4
- 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 +2 -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 +24 -12
- 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.js +31 -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 +17 -9
- package/dist/pipeline/event-dispatcher.d.ts +4 -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/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.js +14 -9
- 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 +4 -0
- package/dist/ui-types/card-column-roles.js +6 -3
- package/dist/ui-types/index.d.ts +2 -2
- package/dist/ui-types/index.js +1 -1
- 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 +9 -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 +6 -0
- package/presets/biome-rules.json +465 -0
- package/src/changes.json +309 -0
- package/dist/engine/minor-units.d.ts +0 -2
- package/dist/engine/minor-units.js +0 -8
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// Zod schema for ComplianceProfileOverride with recursive `.strict()` validation.
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
// OVERRIDABLE_PROFILE_KEYS. Sub-level typos (for example,
|
|
3
|
+
// A top-level key whitelist alone would let sub-level typos (for example,
|
|
5
4
|
// `{ userRights: { weeks: 3 } }` instead of
|
|
6
|
-
// `{ userRights: { gracePeriod: { days: 30 } } }`)
|
|
5
|
+
// `{ userRights: { gracePeriod: { days: 30 } } }`) pass through —
|
|
7
6
|
// deepMerge spliced the nonsense into the effective profile, and a caller
|
|
8
7
|
// reading `userRights.gracePeriod.days` crashed with `undefined`.
|
|
9
8
|
//
|
|
10
9
|
// The schema maps the ComplianceProfile structure to DeepPartial form and
|
|
11
|
-
// uses `.strict()` on every object so unknown keys throw. It is
|
|
12
|
-
// source of truth
|
|
10
|
+
// uses `.strict()` on every object so unknown keys throw. It is the single
|
|
11
|
+
// source of truth for the override whitelist; profiles.test.ts checks it
|
|
12
|
+
// against ComplianceProfile.
|
|
13
13
|
//
|
|
14
14
|
// Identification fields (`key`, `region`, `label`, `extends`) are excluded
|
|
15
15
|
// from the schema because overriding them would destroy profile identity.
|
|
@@ -64,6 +64,15 @@ export const KUMIKO_SUB_PROCESSORS = [
|
|
|
64
64
|
sccRequired: true,
|
|
65
65
|
status: "active",
|
|
66
66
|
},
|
|
67
|
+
{
|
|
68
|
+
name: "Scaleway SAS",
|
|
69
|
+
purpose: "Platform key custody (Key Manager)",
|
|
70
|
+
region: "EU (France)",
|
|
71
|
+
dpa: "https://www.scaleway.com/en/contracts/",
|
|
72
|
+
addedAt: "2026-07-04",
|
|
73
|
+
appliesTo: ["all-tiers"],
|
|
74
|
+
status: "active",
|
|
75
|
+
},
|
|
67
76
|
{
|
|
68
77
|
name: "ALL-INKL.COM – Neue Medien Münnich",
|
|
69
78
|
purpose: "Mailbox Hosting (support and contact mailboxes)",
|
|
@@ -84,7 +93,7 @@ export const KUMIKO_SUB_PROCESSORS = [
|
|
|
84
93
|
},
|
|
85
94
|
{
|
|
86
95
|
name: "Scaleway SAS",
|
|
87
|
-
purpose: "
|
|
96
|
+
purpose: "Transactional Email Delivery (TEM)",
|
|
88
97
|
region: "EU (France)",
|
|
89
98
|
dpa: "https://www.scaleway.com/en/contracts/",
|
|
90
99
|
addedAt: "2026-11-01",
|
package/dist/crypto/index.d.ts
CHANGED
|
@@ -9,5 +9,5 @@ export { type KmsWiring, requireKmsWiring, requireKmsWiringAsync, resolveKmsWiri
|
|
|
9
9
|
export { hashOpaqueToken, hashOpaqueTokenSync, opaqueTokenHashMatches, } from "./opaque-token-hash.ts";
|
|
10
10
|
export { createPgKmsAdapter, rewrapSubjectKeys, } from "./pg-kms-adapter.ts";
|
|
11
11
|
export { PII_CIPHERTEXT_CORRUPT_CODE, PiiCiphertextCorruptError, } from "./pii-ciphertext-corrupt.ts";
|
|
12
|
-
export { configuredPiiSubjectKms, configurePiiSubjectKms, decryptPiiFieldValues, decryptPiiValueForSubject, encryptPiiFieldValues, encryptPiiJsonValueForSubject, encryptPiiValueForSubject, isPiiCiphertext, PII_CIPHERTEXT_PREFIX, PII_ERASED_SENTINEL, } from "./pii-field-encryption.ts";
|
|
12
|
+
export { configuredPiiSubjectKms, configurePiiSubjectKms, decryptPiiFieldValues, decryptPiiValueForSubject, encryptPiiFieldValues, encryptPiiJsonValueForSubject, encryptPiiValueForSubject, isPiiCiphertext, PII_CIPHERTEXT_PREFIX, PII_ERASED_SENTINEL, piiCiphertextMaxLengthFor, } from "./pii-field-encryption.ts";
|
|
13
13
|
export { collectPiiEncryptedFields, collectPiiSubjectFields, isRecordKeyedField, resolveSubjectForField, SubjectResolutionError, } from "./subject-resolver.ts";
|
package/dist/crypto/index.js
CHANGED
|
@@ -9,5 +9,5 @@ export { requireKmsWiring, requireKmsWiringAsync, resolveKmsWiring, resolveKmsWi
|
|
|
9
9
|
export { hashOpaqueToken, hashOpaqueTokenSync, opaqueTokenHashMatches, } from "./opaque-token-hash.js";
|
|
10
10
|
export { createPgKmsAdapter, rewrapSubjectKeys, } from "./pg-kms-adapter.js";
|
|
11
11
|
export { PII_CIPHERTEXT_CORRUPT_CODE, PiiCiphertextCorruptError, } from "./pii-ciphertext-corrupt.js";
|
|
12
|
-
export { configuredPiiSubjectKms, configurePiiSubjectKms, decryptPiiFieldValues, decryptPiiValueForSubject, encryptPiiFieldValues, encryptPiiJsonValueForSubject, encryptPiiValueForSubject, isPiiCiphertext, PII_CIPHERTEXT_PREFIX, PII_ERASED_SENTINEL, } from "./pii-field-encryption.js";
|
|
12
|
+
export { configuredPiiSubjectKms, configurePiiSubjectKms, decryptPiiFieldValues, decryptPiiValueForSubject, encryptPiiFieldValues, encryptPiiJsonValueForSubject, encryptPiiValueForSubject, isPiiCiphertext, PII_CIPHERTEXT_PREFIX, PII_ERASED_SENTINEL, piiCiphertextMaxLengthFor, } from "./pii-field-encryption.js";
|
|
13
13
|
export { collectPiiEncryptedFields, collectPiiSubjectFields, isRecordKeyedField, resolveSubjectForField, SubjectResolutionError, } from "./subject-resolver.js";
|
|
@@ -3,6 +3,8 @@ import type { TenantId } from "../engine/types/identifiers.ts";
|
|
|
3
3
|
import { type KmsAdapter, type KmsContext, type LocalKeyKmsAdapter, PII_ERASED_SENTINEL, type SubjectId } from "./kms-adapter.ts";
|
|
4
4
|
import { isPiiCiphertext, PII_CIPHERTEXT_PREFIX, PII_CIPHERTEXT_PREFIX_JSON } from "./pii-ciphertext-format.ts";
|
|
5
5
|
export { isPiiCiphertext, PII_CIPHERTEXT_PREFIX, PII_CIPHERTEXT_PREFIX_JSON, PII_ERASED_SENTINEL };
|
|
6
|
+
/** Upper bound for the stored length of a PII value whose plaintext is at most `plaintextMax` characters. */
|
|
7
|
+
export declare function piiCiphertextMaxLengthFor(plaintextMax: number): number;
|
|
6
8
|
export declare function piiCiphertextSubject(value: string): SubjectId;
|
|
7
9
|
export declare function encryptPiiValueForSubject(kms: LocalKeyKmsAdapter, subject: SubjectId, value: string, kmsCtx: KmsContext, field: string): Promise<string>;
|
|
8
10
|
export declare function encryptPiiJsonValueForSubject(kms: LocalKeyKmsAdapter, subject: SubjectId, value: unknown, kmsCtx: KmsContext, field: string): Promise<string>;
|
|
@@ -17,14 +17,25 @@
|
|
|
17
17
|
import { createCipheriv, createDecipheriv, randomBytes } from "node:crypto";
|
|
18
18
|
import { assertIrreversibleOperationAllowed } from "../pipeline/irreversible-operation-gate.js";
|
|
19
19
|
import { isLocalKeyKmsAdapter, KeyAlreadyExistsError, KeyErasedError, KeyNotFoundError, PII_ERASED_SENTINEL, subjectIdFromKey, subjectIdToKey, } from "./kms-adapter.js";
|
|
20
|
-
import { classifyKmsOutage } from "./kms-outage.js";
|
|
20
|
+
import { classifyKmsOutage, EncryptionUnavailableError } from "./kms-outage.js";
|
|
21
21
|
import { PiiCiphertextCorruptError } from "./pii-ciphertext-corrupt.js";
|
|
22
22
|
import { isPiiCiphertext, PII_CIPHERTEXT_PREFIX, PII_CIPHERTEXT_PREFIX_JSON, PII_CIPHERTEXT_PREFIX_V1, } from "./pii-ciphertext-format.js";
|
|
23
23
|
import { resolveSubjectForField } from "./subject-resolver.js";
|
|
24
24
|
// Spec value (crypto-shredding.md) — renderers show it verbatim.
|
|
25
25
|
export { isPiiCiphertext, PII_CIPHERTEXT_PREFIX, PII_CIPHERTEXT_PREFIX_JSON, PII_ERASED_SENTINEL };
|
|
26
|
+
const DEK_LENGTH = 32;
|
|
26
27
|
const IV_LENGTH = 12;
|
|
27
28
|
const AUTH_TAG_LENGTH = 16;
|
|
29
|
+
// A zod `max` counts UTF-16 units, each of which is at most 3 UTF-8 bytes (a surrogate pair is 2 units, 4 bytes).
|
|
30
|
+
const MAX_UTF8_BYTES_PER_UTF16_UNIT = 3;
|
|
31
|
+
// "tenant:<uuid>" / "user:<uuid>" are 43 / 41 chars; record keys carry a free-form entity name, so leave headroom.
|
|
32
|
+
const SUBJECT_KEY_MAX_LENGTH = 128;
|
|
33
|
+
/** Upper bound for the stored length of a PII value whose plaintext is at most `plaintextMax` characters. */
|
|
34
|
+
export function piiCiphertextMaxLengthFor(plaintextMax) {
|
|
35
|
+
const blobBytes = IV_LENGTH + AUTH_TAG_LENGTH + plaintextMax * MAX_UTF8_BYTES_PER_UTF16_UNIT;
|
|
36
|
+
const base64Length = Math.ceil(blobBytes / 3) * 4;
|
|
37
|
+
return PII_CIPHERTEXT_PREFIX_JSON.length + SUBJECT_KEY_MAX_LENGTH + 1 + base64Length;
|
|
38
|
+
}
|
|
28
39
|
function buildAad(subject, field, isJson) {
|
|
29
40
|
return Buffer.from(`${subjectIdToKey(subject)}|${field}${isJson ? "|json" : ""}`, "utf8");
|
|
30
41
|
}
|
|
@@ -59,6 +70,10 @@ function parseCiphertext(value) {
|
|
|
59
70
|
};
|
|
60
71
|
}
|
|
61
72
|
function decryptValue(dek, blob, subject, field, hasAad, isJson) {
|
|
73
|
+
// A wrong-sized DEK is a key-store fault, not a damaged ciphertext: scrub/export must not wipe intact values for it.
|
|
74
|
+
if (dek.length !== DEK_LENGTH) {
|
|
75
|
+
throw new EncryptionUnavailableError(new Error(`DEK has ${dek.length} bytes, expected ${DEK_LENGTH}`));
|
|
76
|
+
}
|
|
62
77
|
try {
|
|
63
78
|
const iv = blob.subarray(0, IV_LENGTH);
|
|
64
79
|
const tag = blob.subarray(IV_LENGTH, IV_LENGTH + AUTH_TAG_LENGTH);
|
|
@@ -164,5 +164,9 @@ async function applyEntityEventInScope(event, table, entity, tx) {
|
|
|
164
164
|
await deleteMany(tx, table, { id: event.aggregateId });
|
|
165
165
|
return { kind: "applied", verb, row: null };
|
|
166
166
|
}
|
|
167
|
+
default: {
|
|
168
|
+
const exhaustiveCheck = verb;
|
|
169
|
+
return exhaustiveCheck;
|
|
170
|
+
}
|
|
167
171
|
}
|
|
168
172
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const BUN_SQL_CONNECTION_ERROR_CODES: readonly string[];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Client-side Bun.SQL failures that mean the connection could not be used.
|
|
2
|
+
export const BUN_SQL_CONNECTION_ERROR_CODES = [
|
|
3
|
+
"ERR_POSTGRES_CONNECTION_CLOSED",
|
|
4
|
+
"ERR_POSTGRES_CONNECTION_REFUSED",
|
|
5
|
+
"ERR_POSTGRES_CONNECTION_TIMEOUT",
|
|
6
|
+
"ERR_POSTGRES_CONNECTION_FAILED",
|
|
7
|
+
];
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// (entities, storeTables, projections, multiStreamProjections). One shared
|
|
3
3
|
// source so the test-DB push and migrations cannot drift apart again.
|
|
4
4
|
import { compareByCodepoint } from "../utils/compare.js";
|
|
5
|
-
import { assertBackingTableSuperset, deriveEntityTableMeta, } from "./entity-table-meta.js";
|
|
5
|
+
import { assertBackingTableSuperset, deriveEntityTableMeta, entityReadsSystemRows, } from "./entity-table-meta.js";
|
|
6
6
|
import { enumerateFeatureTableSources } from "./feature-table-sources.js";
|
|
7
7
|
import { asEntityTableMeta } from "./query.js";
|
|
8
8
|
function canonicalColumnsKey(meta) {
|
|
@@ -45,6 +45,9 @@ export function collectTableMetas(features) {
|
|
|
45
45
|
assertBackingTableSuperset(name, fieldMeta, tableMeta);
|
|
46
46
|
meta = tableMeta;
|
|
47
47
|
}
|
|
48
|
+
if (entityReadsSystemRows(feature, name, ent) && meta.systemRowsReadable !== true) {
|
|
49
|
+
meta = { ...meta, systemRowsReadable: true };
|
|
50
|
+
}
|
|
48
51
|
registerPass1Meta(metas, byName, meta, `entity "${name}" (${feature.name})`);
|
|
49
52
|
}
|
|
50
53
|
for (const entry of Object.values(feature.storeTables)) {
|
package/dist/db/config-seed.js
CHANGED
|
@@ -47,7 +47,7 @@ export async function seedConfigValues(seeds, table, entity, registry, db, ciphe
|
|
|
47
47
|
// user-cascade matches the user's actual tenantId, not the SYSTEM
|
|
48
48
|
// sentinel — a SYSTEM-rooted user row would be unreachable.
|
|
49
49
|
if (scope === "user" && (!seed.tenantId || !seed.userId)) {
|
|
50
|
-
throw new Error(`seedConfigValues: user-scope seed "${seed.key}" requires both tenantId and userId —
|
|
50
|
+
throw new Error(`seedConfigValues: user-scope seed "${seed.key}" requires both tenantId and userId — set { value, scope: "user", tenantId, userId }.`);
|
|
51
51
|
}
|
|
52
52
|
const tenantId = seed.tenantId ?? SYSTEM_TENANT_ID;
|
|
53
53
|
const userId = scope === "user" ? (seed.userId ?? null) : null;
|
|
@@ -33,7 +33,7 @@ function relatedDefaultCurrency(spec, input) {
|
|
|
33
33
|
: undefined;
|
|
34
34
|
return related?.defaultCurrency ?? FRAMEWORK_DEFAULT_CURRENCY;
|
|
35
35
|
}
|
|
36
|
-
function buildExpression(spec, input,
|
|
36
|
+
function buildExpression(spec, input, moneyPair = false) {
|
|
37
37
|
if (spec.kind === "coalesce")
|
|
38
38
|
return buildCoalesceExpression(spec.fields, input);
|
|
39
39
|
const runtime = input.runtime?.derivedSql;
|
|
@@ -52,9 +52,13 @@ function buildExpression(spec, input, currency = false) {
|
|
|
52
52
|
db: input.db,
|
|
53
53
|
runtime,
|
|
54
54
|
parentVisibility: input.runtime?.parentVisibility,
|
|
55
|
-
|
|
55
|
+
moneyPair,
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
+
// The driver hands jsonb back parsed; NULL (hidden or unreadable related field) has no pair.
|
|
59
|
+
function moneyPairOf(raw) {
|
|
60
|
+
return Array.isArray(raw) ? [raw[0], raw[1]] : [null, null];
|
|
61
|
+
}
|
|
58
62
|
export function buildDerivedSelect(input) {
|
|
59
63
|
if (input.runtime?.derivedSql === undefined)
|
|
60
64
|
return undefined;
|
|
@@ -69,10 +73,9 @@ export function buildDerivedSelect(input) {
|
|
|
69
73
|
valueType: def.valueType,
|
|
70
74
|
sortable: def.sortable === true,
|
|
71
75
|
expression: buildExpression(def.sql, input),
|
|
72
|
-
|
|
76
|
+
money: def.valueType === "money"
|
|
73
77
|
? {
|
|
74
|
-
|
|
75
|
-
expression: buildExpression(def.sql, input, true),
|
|
78
|
+
pairExpression: buildExpression(def.sql, input, true),
|
|
76
79
|
fallback: relatedDefaultCurrency(def.sql, input),
|
|
77
80
|
}
|
|
78
81
|
: undefined,
|
|
@@ -82,10 +85,10 @@ export function buildDerivedSelect(input) {
|
|
|
82
85
|
return undefined;
|
|
83
86
|
return {
|
|
84
87
|
projections: (params) => plans
|
|
85
|
-
.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
.map((plan) => ({
|
|
89
|
+
alias: plan.alias,
|
|
90
|
+
expression: plan.money === undefined ? plan.expression : plan.money.pairExpression,
|
|
91
|
+
}))
|
|
89
92
|
.map(({ alias, expression }) => `, ${expression?.(params) ?? "NULL"} AS "${alias}"`)
|
|
90
93
|
.join(""),
|
|
91
94
|
sortExpr: (name) => {
|
|
@@ -96,14 +99,13 @@ export function buildDerivedSelect(input) {
|
|
|
96
99
|
takeValues: (rawRows) => rawRows.map((raw) => {
|
|
97
100
|
const values = {};
|
|
98
101
|
for (const plan of plans) {
|
|
99
|
-
if (plan.
|
|
100
|
-
const amount = raw[plan.alias];
|
|
102
|
+
if (plan.money !== undefined) {
|
|
103
|
+
const [amount, currency] = moneyPairOf(raw[plan.alias]);
|
|
101
104
|
// A stored money field without an amount has no key on the row; match that.
|
|
102
105
|
if (amount !== null && amount !== undefined) {
|
|
103
|
-
values[plan.name] = readMoney(plan.name, amount,
|
|
106
|
+
values[plan.name] = readMoney(plan.name, amount, currency, plan.money.fallback);
|
|
104
107
|
}
|
|
105
108
|
delete raw[plan.alias];
|
|
106
|
-
delete raw[plan.currency.alias];
|
|
107
109
|
continue;
|
|
108
110
|
}
|
|
109
111
|
values[plan.name] = coerceDriverValueOfPgType(raw[plan.alias], PG_TYPE_OF_VALUE_TYPE[plan.valueType], plan.alias);
|
|
@@ -26,6 +26,6 @@ export declare function buildRelatedSubquery(input: {
|
|
|
26
26
|
readonly db: TenantDb;
|
|
27
27
|
readonly runtime: DerivedSqlRuntime;
|
|
28
28
|
readonly parentVisibility: ParentVisibilityOption | undefined;
|
|
29
|
-
/** Select the measured money field
|
|
30
|
-
readonly
|
|
29
|
+
/** Select the measured money field as [amount, currency] in one subquery. */
|
|
30
|
+
readonly moneyPair?: boolean;
|
|
31
31
|
}): ((params: unknown[]) => string) | undefined;
|
|
@@ -124,8 +124,10 @@ function relatedSelect(measure, column, related, input) {
|
|
|
124
124
|
if (measure.kind === "countDistinct")
|
|
125
125
|
return () => `COUNT(DISTINCT ${column(measure.field)})::int`;
|
|
126
126
|
if (measure.label !== true) {
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
if (input.moneyPair === true) {
|
|
128
|
+
return () => `jsonb_build_array(${column(measure.field)}, ${column(`${measure.field}Currency`)})`;
|
|
129
|
+
}
|
|
130
|
+
return () => column(measure.field);
|
|
129
131
|
}
|
|
130
132
|
const def = related.fields[measure.field];
|
|
131
133
|
if (def?.type !== "reference" || def.labelField === undefined)
|
package/dist/db/dialect.d.ts
CHANGED
|
@@ -88,6 +88,9 @@ export declare namespace sql {
|
|
|
88
88
|
}
|
|
89
89
|
export type ColumnMap = Record<string, ColumnBuilder<unknown>>;
|
|
90
90
|
type IndexOrPk = IndexBuilderWithCols | PrimaryKeyDescriptor;
|
|
91
|
+
export declare function table<TCols extends ColumnMap>(tableName: `read_${string}`, cols: TCols, optsFn?: (t: {
|
|
92
|
+
[K in keyof TCols]: ColumnHandle;
|
|
93
|
+
}) => Record<string, IndexOrPk> | ReadonlyArray<IndexOrPk>): SchemaTable;
|
|
91
94
|
export declare function table<TCols extends ColumnMap>(tableName: string, cols: TCols, optsFn?: (t: {
|
|
92
95
|
[K in keyof TCols]: ColumnHandle;
|
|
93
96
|
}) => Record<string, IndexOrPk> | ReadonlyArray<IndexOrPk>): WritableSchemaTable;
|
package/dist/db/dialect.js
CHANGED
|
@@ -224,11 +224,9 @@ function makeIndex(name, unique) {
|
|
|
224
224
|
},
|
|
225
225
|
};
|
|
226
226
|
}
|
|
227
|
-
// @wrapper-known semantic-alias
|
|
228
227
|
export function index(name) {
|
|
229
228
|
return makeIndex(name, false);
|
|
230
229
|
}
|
|
231
|
-
// @wrapper-known semantic-alias
|
|
232
230
|
export function uniqueIndex(name) {
|
|
233
231
|
return makeIndex(name, true);
|
|
234
232
|
}
|
|
@@ -304,7 +302,7 @@ export function table(tableName, cols, optsFn) {
|
|
|
304
302
|
const handle = {
|
|
305
303
|
name: final.sqlName,
|
|
306
304
|
pgType: final.pgType,
|
|
307
|
-
getSQLType: () => pgTypeToSqlType(final.pgType),
|
|
305
|
+
getSQLType: () => pgTypeToSqlType(final.pgType),
|
|
308
306
|
};
|
|
309
307
|
handles[field] = handle;
|
|
310
308
|
const meta = {
|
|
@@ -43,7 +43,7 @@ function instantFromDriver(value) {
|
|
|
43
43
|
if (isTemporalInstant(value))
|
|
44
44
|
return value;
|
|
45
45
|
// Number coercion via +date — equivalent to .getTime() without a Date-API
|
|
46
|
-
// method (
|
|
46
|
+
// method (no-date-api plugin). Date → epoch milliseconds, then to Temporal.Instant.
|
|
47
47
|
if (value instanceof Date)
|
|
48
48
|
return Temporal.Instant.fromEpochMilliseconds(+value);
|
|
49
49
|
if (typeof value === "string") {
|
|
@@ -65,7 +65,7 @@ function instantFromDriver(value) {
|
|
|
65
65
|
// (e.g. America/Los_Angeles reads back the 14th for a stored 15th). Routing
|
|
66
66
|
// through Instant→ZonedDateTimeISO("UTC")→PlainDate reads the calendar day
|
|
67
67
|
// back deterministically without ever touching a local Date getter — the
|
|
68
|
-
// same +value idiom instantFromDriver uses (
|
|
68
|
+
// same +value idiom instantFromDriver uses (no-date-api plugin: no
|
|
69
69
|
// `.getTime()`), just anchored to a fixed zone instead of process-local.
|
|
70
70
|
// A real `date` column always arrives as a UTC-midnight Date. Anything else means the column is
|
|
71
71
|
// still timestamptz (declared `date` before its ALTER ran); the UTC anchor then silently shifts
|
|
@@ -11,7 +11,7 @@ export function isSqlExpression(v) {
|
|
|
11
11
|
// A `date` column takes a plain "yyyy-mm-dd" string (or PlainDate.toString())
|
|
12
12
|
// as-is — no Instant detour. Postgres parses a DATE literal without ever
|
|
13
13
|
// consulting the session timezone, so this is TZ-independent by construction
|
|
14
|
-
// (verified empirically — see plainDateFromDriver
|
|
14
|
+
// (verified empirically — see plainDateFromDriver in driver-row-coercion.ts for the read side).
|
|
15
15
|
// Compat cushion: code (this field used to be an Instant) may still
|
|
16
16
|
// hand a Temporal.Instant into a where-filter or write on a `date` column —
|
|
17
17
|
// same UTC anchor as plainDateFromDriver's read side, so a filter built with
|
package/dist/db/eagerload.js
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
// never skipped silently.
|
|
20
20
|
import { requestContext } from "../api/request-context.js";
|
|
21
21
|
import { collectPiiSubjectFields, configuredPiiSubjectKms, decryptPiiFieldValues, } from "../crypto/index.js";
|
|
22
|
-
import { selectMany } from "../db/query.js";
|
|
22
|
+
import { coerceRow, selectMany } from "../db/query.js";
|
|
23
23
|
import { filterReadFields } from "../engine/field-access.js";
|
|
24
24
|
import { shiftParams, tableNameOf } from "../engine/ownership.js";
|
|
25
25
|
import { parseRefTargetEntityName } from "../engine/parse-ref-target.js";
|
|
@@ -31,7 +31,8 @@ import { toPostgresArrayLiteral } from "./queries/postgres-array-literal.js";
|
|
|
31
31
|
import { executeRawQueryRead } from "./queries/raw-sql.js";
|
|
32
32
|
import { resolveReadOwnership } from "./read-ownership.js";
|
|
33
33
|
import { buildEntityTable, physicalColumnName } from "./table-builder.js";
|
|
34
|
-
import {
|
|
34
|
+
import { extractTableInfo } from "./table-info.js";
|
|
35
|
+
import { tenantDbRunnerForTable } from "./tenant-db-runner.js";
|
|
35
36
|
const log = createFallbackLogger("eagerload");
|
|
36
37
|
function isReferenceField(field) {
|
|
37
38
|
return field.type === "reference";
|
|
@@ -67,9 +68,11 @@ async function decryptReferencedRow(row, piiFields, encryptedFields, kms) {
|
|
|
67
68
|
}
|
|
68
69
|
return out;
|
|
69
70
|
}
|
|
70
|
-
// One
|
|
71
|
-
//
|
|
72
|
-
//
|
|
71
|
+
// One lookup per ref field. Unrestricted targets load rows by id later; for
|
|
72
|
+
// restricted ones the access clause is part of this same SELECT so unreadable
|
|
73
|
+
// rows are never loaded. Raw SQL because ownership/parentRef clauses are SQL
|
|
74
|
+
// fragments; the table is unaliased since where-rules qualify columns with the
|
|
75
|
+
// table name.
|
|
73
76
|
async function resolveRefAccessScope(refEntity, refTable, refTableName, ids, db, viewer) {
|
|
74
77
|
const access = resolveReadOwnership({ entity: refEntity, table: refTable }, refTableName, viewer.user, db, viewer.parentVisibility, { includeDeleted: false, narrowTypes: undefined });
|
|
75
78
|
if (access.kind === "empty")
|
|
@@ -87,8 +90,11 @@ async function resolveRefAccessScope(refEntity, refTable, refTableName, ids, db,
|
|
|
87
90
|
}
|
|
88
91
|
const shifted = shiftParams({ sqlText: access.sqlText, params: access.params }, params.length);
|
|
89
92
|
params.push(...shifted.params);
|
|
90
|
-
const rows = await executeRawQueryRead(
|
|
91
|
-
|
|
93
|
+
const rows = await executeRawQueryRead(tenantDbRunnerForTable(db, refTable), `SELECT * FROM "${refTableName}" WHERE "id" = ANY($1::uuid[])${tenantClause} AND ${shifted.sqlText}`, params);
|
|
94
|
+
// The raw SELECT * rows carry driver column names; coerce like selectMany so field-level
|
|
95
|
+
// read rules and PII decryption see the camelCase entity row.
|
|
96
|
+
const info = extractTableInfo(refTable);
|
|
97
|
+
return { kind: "restricted", readableRows: rows.map((row) => coerceRow(row, info)) };
|
|
92
98
|
}
|
|
93
99
|
// Per-row, not Promise.all: a single legacy/backfilled row without a valid
|
|
94
100
|
// envelope (decryptEntityFieldValues throws hard on malformed ciphertext)
|
|
@@ -164,12 +170,9 @@ export async function enrichWithReferences(rows, entity, resolveEntity, db, view
|
|
|
164
170
|
const scope = await resolveRefAccessScope(refEntity, refTable, refTableName, idArray, db, viewer);
|
|
165
171
|
if (scope.kind === "none")
|
|
166
172
|
return emptyLookup;
|
|
167
|
-
const lookedUpRows = await selectMany(db, refTable, {
|
|
168
|
-
id: idArray,
|
|
169
|
-
});
|
|
170
173
|
const rawRefRows = scope.kind === "restricted"
|
|
171
|
-
?
|
|
172
|
-
:
|
|
174
|
+
? scope.readableRows
|
|
175
|
+
: await selectMany(db, refTable, { id: idArray });
|
|
173
176
|
const piiFields = collectPiiSubjectFields(refEntity);
|
|
174
177
|
const encryptedFields = collectEncryptedFieldNames(refEntity);
|
|
175
178
|
const kms = configuredPiiSubjectKms();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Writable } from "@cosmicdrift/kumiko-types/executor-brand";
|
|
2
2
|
import type { EntityDefinition } from "@cosmicdrift/kumiko-types/fields";
|
|
3
3
|
import type { EntityTenancy, TenancyBrand } from "@cosmicdrift/kumiko-types/tenancy-brand";
|
|
4
|
+
import type { FeatureDefinition } from "../engine/types/index.ts";
|
|
4
5
|
import type { BuildEntityTableMetaOptions, EntityTableMeta, UnmanagedTableInput } from "./entity-table-meta-types.ts";
|
|
5
6
|
export type { BuildEntityTableMetaOptions, ColumnMeta, CompositePrimaryKeyMeta, EntityTableMeta, IndexMeta, PgType, UnmanagedTableInput, } from "./entity-table-meta-types.ts";
|
|
6
7
|
export declare function resolveTableName(entityName: string, entity: EntityDefinition, featureName: string | undefined): string;
|
|
@@ -30,3 +31,4 @@ export declare function assertBackingTableSuperset(entityName: string, fieldMeta
|
|
|
30
31
|
export declare function defineUnmanagedTable<const T extends EntityTenancy = "tenant">(input: UnmanagedTableInput & {
|
|
31
32
|
readonly tenancy?: T;
|
|
32
33
|
}): EntityTableMeta & TenancyBrand<T> & Writable;
|
|
34
|
+
export declare function entityReadsSystemRows(feature: Pick<FeatureDefinition, "referenceData">, entityName: string, entity: EntityDefinition): boolean;
|
|
@@ -76,6 +76,7 @@ export function deriveEntityTableMeta(entityName, entity, options) {
|
|
|
76
76
|
source,
|
|
77
77
|
...(piiSubjectFields.length > 0 && { piiSubjectFields }),
|
|
78
78
|
...(entity.tenancy === "global" && { tenancy: "global" }),
|
|
79
|
+
...(entity.systemRowsReadable === true && { systemRowsReadable: true }),
|
|
79
80
|
};
|
|
80
81
|
return source === "unmanaged" ? brandWritable(meta) : meta;
|
|
81
82
|
}
|
|
@@ -248,6 +249,7 @@ export function defineUnmanagedTable(input) {
|
|
|
248
249
|
}),
|
|
249
250
|
source: "unmanaged",
|
|
250
251
|
...(input.tenancy === "global" && { tenancy: "global" }),
|
|
252
|
+
...(input.systemRowsReadable === true && { systemRowsReadable: true }),
|
|
251
253
|
// @cast-boundary phantom-brand — TenancyBrand<T> is a phantom marker with no runtime representation.
|
|
252
254
|
});
|
|
253
255
|
}
|
|
@@ -259,3 +261,8 @@ function assertUnmanagedTableName(tableName, via) {
|
|
|
259
261
|
`See #1208/#1220.`);
|
|
260
262
|
}
|
|
261
263
|
}
|
|
264
|
+
// Reference data rows live on the system tenant by definition, so tenant reads need them.
|
|
265
|
+
export function entityReadsSystemRows(feature, entityName, entity) {
|
|
266
|
+
return (entity.systemRowsReadable === true ||
|
|
267
|
+
(feature.referenceData ?? []).some((def) => def.entityName === entityName));
|
|
268
|
+
}
|
|
@@ -10,11 +10,12 @@ import { isStreamArchived } from "../event-store/index.js";
|
|
|
10
10
|
import { assertUnreachable } from "../utils/index.js";
|
|
11
11
|
import { rehydrateCompoundTypes } from "./compound-types.js";
|
|
12
12
|
import { collectEncryptedFieldNames, decryptEntityFieldValues, encryptEntityFieldValues, logUndecryptableField, resolveEntityFieldEncryption, } from "./entity-field-encryption.js";
|
|
13
|
+
import { withGlobalParentHosts } from "./parent-ref-global-hosts.js";
|
|
13
14
|
import { constraintOf, isUniqueViolation } from "./pg-error.js";
|
|
14
15
|
import { resolveReadOwnership } from "./read-ownership.js";
|
|
15
16
|
import { toSnakeCase } from "./table-builder.js";
|
|
16
17
|
import { columnHandleName, schemaTableName } from "./table-introspection.js";
|
|
17
|
-
import {
|
|
18
|
+
import { tenantDbRunnerForTable } from "./tenant-db-runner.js";
|
|
18
19
|
// Screen filter: maps an operator to a WhereObject condition.
|
|
19
20
|
// The boot validator checks field existence, filterability, and operator/type compatibility.
|
|
20
21
|
// `op` is normalized to {eq,ne,lt,gt,lte,gte,in}; "in" with an
|
|
@@ -305,7 +306,7 @@ export function buildExecutorContext(table, entity, options) {
|
|
|
305
306
|
// re-create onto an archived stream collides on the unique index →
|
|
306
307
|
// version_conflict, which already blocks the write.
|
|
307
308
|
async function assertStreamWritable(db, id, tenantId) {
|
|
308
|
-
if (await isStreamArchived(
|
|
309
|
+
if (await isStreamArchived(tenantDbRunnerForTable(db, table), tenantId, String(id))) {
|
|
309
310
|
throw new ArchivedStreamError(tenantId, String(id));
|
|
310
311
|
}
|
|
311
312
|
}
|
|
@@ -349,7 +350,7 @@ export function buildExecutorContext(table, entity, options) {
|
|
|
349
350
|
params.push(aggregateId, streamTenantId);
|
|
350
351
|
const sqlText = `SELECT 1 AS "__owned", ${streamVersionSubquerySql(params.length - 1, params.length)} ` +
|
|
351
352
|
`FROM "${tableName}" WHERE ${whereParts.join(" AND ")} LIMIT 1`;
|
|
352
|
-
const rows = await executeRawQueryRead(
|
|
353
|
+
const rows = await executeRawQueryRead(tenantDbRunnerForTable(db, table), sqlText, params);
|
|
353
354
|
const first = rows[0];
|
|
354
355
|
if (!first)
|
|
355
356
|
return { owned: false, streamVersion: 0 };
|
|
@@ -361,14 +362,18 @@ export function buildExecutorContext(table, entity, options) {
|
|
|
361
362
|
// soft-deleted row; includeDeleted below only concerns the parent host. Writers use it
|
|
362
363
|
// to treat an unreadable row as nonexistent.
|
|
363
364
|
async function isRowReadable(id, user, db, parentVisibility) {
|
|
364
|
-
const
|
|
365
|
+
const gate = { includeDeleted: false, narrowTypes: undefined };
|
|
366
|
+
const tableName = String(schemaTableName(table));
|
|
367
|
+
const ownership = resolveReadOwnership({ entity, table }, tableName, user, db, await withGlobalParentHosts({ entity, table }, user, db, parentVisibility, gate, {
|
|
368
|
+
kind: "row",
|
|
369
|
+
rowId: id,
|
|
370
|
+
}), gate);
|
|
365
371
|
if (ownership.kind === "pass")
|
|
366
372
|
return true;
|
|
367
373
|
if (ownership.kind === "empty")
|
|
368
374
|
return false;
|
|
369
|
-
const tableName = String(schemaTableName(table));
|
|
370
375
|
const { whereParts, params } = buildRawIdWhere(db, { id }, ownership);
|
|
371
|
-
const rows = await executeRawQueryRead(
|
|
376
|
+
const rows = await executeRawQueryRead(tenantDbRunnerForTable(db, table), `SELECT 1 AS "__readable" FROM "${tableName}" WHERE ${whereParts.join(" AND ")} LIMIT 1`, params);
|
|
372
377
|
return rows.length > 0;
|
|
373
378
|
}
|
|
374
379
|
// Row and MAX(version) in ONE statement: two reads can pair a post-write
|
|
@@ -382,7 +387,7 @@ export function buildExecutorContext(table, entity, options) {
|
|
|
382
387
|
params.push(aggregateId, streamTenantId);
|
|
383
388
|
const sqlText = `SELECT *, ${streamVersionSubquerySql(params.length - 1, params.length)} ` +
|
|
384
389
|
`FROM "${tableName}" WHERE ${whereParts.join(" AND ")} LIMIT 1`;
|
|
385
|
-
const rows = await executeRawQueryRead(
|
|
390
|
+
const rows = await executeRawQueryRead(tenantDbRunnerForTable(db, table), sqlText, params);
|
|
386
391
|
const first = rows[0];
|
|
387
392
|
if (!first)
|
|
388
393
|
return { row: null, streamVersion: 0 };
|
|
@@ -428,7 +433,7 @@ export function buildExecutorContext(table, entity, options) {
|
|
|
428
433
|
const sqlText = `SELECT ${selectCols.join(", ")}, ` +
|
|
429
434
|
`${streamVersionSubquerySql(streamAggregateIdx, streamTenantIdx)} ` +
|
|
430
435
|
`FROM "${tableName}" WHERE ${whereParts.join(" AND ")} LIMIT 1`;
|
|
431
|
-
const rows = await executeRawQueryRead(
|
|
436
|
+
const rows = await executeRawQueryRead(tenantDbRunnerForTable(db, table), sqlText, params);
|
|
432
437
|
const row = rows[0];
|
|
433
438
|
if (!row)
|
|
434
439
|
return { row: null, streamVersion: 0 };
|
|
@@ -2,7 +2,7 @@ import { isPerCurrencyMeasure } from "./aggregate-sql.js";
|
|
|
2
2
|
import { bindShiftedClause } from "./event-store-executor-read-filter.js";
|
|
3
3
|
import { executeRawQueryRead } from "./queries/raw-sql.js";
|
|
4
4
|
import { schemaTableName } from "./table-introspection.js";
|
|
5
|
-
import {
|
|
5
|
+
import { tenantDbRunnerForTable } from "./tenant-db-runner.js";
|
|
6
6
|
// Above the ~180 ISO 4217 codes, so the cap only bounds malformed data.
|
|
7
7
|
const MAX_AGGREGATE_CURRENCIES = 200;
|
|
8
8
|
export function currencyColumnOf(field) {
|
|
@@ -24,7 +24,7 @@ export async function loadMeasureCurrencies(ctx, measures, where, db) {
|
|
|
24
24
|
if (m.clause.kind === "sql")
|
|
25
25
|
conditions.push(`(${bindShiftedClause(params, m.clause)})`);
|
|
26
26
|
const currencySql = where.colSql(currencyColumnOf(m.field));
|
|
27
|
-
const rows = await executeRawQueryRead(
|
|
27
|
+
const rows = await executeRawQueryRead(tenantDbRunnerForTable(db, ctx.table), `SELECT DISTINCT ${currencySql} AS cur FROM "${tableName}" WHERE ${conditions.join(" AND ")} AND ${currencySql} IS NOT NULL ORDER BY 1 LIMIT ${MAX_AGGREGATE_CURRENCIES}`, params);
|
|
28
28
|
byField.set(m.field, rows.map((row) => String(row.cur)));
|
|
29
29
|
}
|
|
30
30
|
return byField;
|
|
@@ -6,7 +6,7 @@ import { appendShiftedClause, bindShiftedClause, } from "./event-store-executor-
|
|
|
6
6
|
import { buildListWhere, createFieldReadClause, } from "./event-store-executor-read-where.js";
|
|
7
7
|
import { executeRawQueryRead } from "./queries/raw-sql.js";
|
|
8
8
|
import { schemaTableName } from "./table-introspection.js";
|
|
9
|
-
import {
|
|
9
|
+
import { tenantDbRunnerForTable } from "./tenant-db-runner.js";
|
|
10
10
|
// One group more than the cap is fetched to tell "exactly 200" from "more".
|
|
11
11
|
const MAX_AGGREGATE_GROUPS = 200;
|
|
12
12
|
function rejectAggregate(path, field, hint) {
|
|
@@ -121,7 +121,7 @@ export async function aggregateList(ctx, payload, user, db, runtimeOptions) {
|
|
|
121
121
|
const whereText = where.whereSql.length > 0 ? ` WHERE ${where.whereSql.join(" AND ")}` : "";
|
|
122
122
|
const groupText = grouped ? groupedKeyOrderLimitSql(MAX_AGGREGATE_GROUPS + 1) : "";
|
|
123
123
|
const tableName = String(schemaTableName(ctx.table));
|
|
124
|
-
const rows = await executeRawQueryRead(
|
|
124
|
+
const rows = await executeRawQueryRead(tenantDbRunnerForTable(db, ctx.table), `SELECT ${selectList} FROM "${tableName}"${whereText}${groupText}`, where.params);
|
|
125
125
|
const truncated = rows.length > MAX_AGGREGATE_GROUPS;
|
|
126
126
|
const groups = rows.slice(0, MAX_AGGREGATE_GROUPS).map((row) => ({
|
|
127
127
|
key: grouped ? aggregateKeyOf(row["k0"]) : null,
|
|
@@ -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];
|