@mistriwork/engine 0.0.0 → 1.0.0-rc.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +16 -1
- package/dist/adapters/adapter.d.ts +726 -0
- package/dist/adapters/adapter.js +444 -0
- package/dist/adapters/cache/cacheStore.d.ts +75 -0
- package/dist/adapters/cache/cacheStore.js +160 -0
- package/dist/adapters/cache/resp.d.ts +52 -0
- package/dist/adapters/cache/resp.js +237 -0
- package/dist/adapters/commands/canonicalJson.d.ts +19 -0
- package/dist/adapters/commands/canonicalJson.js +154 -0
- package/dist/adapters/connect.d.ts +29 -0
- package/dist/adapters/connect.js +40 -0
- package/dist/adapters/connectionBudget.d.ts +101 -0
- package/dist/adapters/connectionBudget.js +128 -0
- package/dist/adapters/dbLatency.d.ts +35 -0
- package/dist/adapters/dbLatency.js +79 -0
- package/dist/adapters/epochCache.d.ts +50 -0
- package/dist/adapters/epochCache.js +85 -0
- package/dist/adapters/http/egress.d.ts +48 -0
- package/dist/adapters/http/egress.js +175 -0
- package/dist/adapters/http/httpAdapter.d.ts +71 -0
- package/dist/adapters/http/httpAdapter.js +512 -0
- package/dist/adapters/http/httpDescription.d.ts +32 -0
- package/dist/adapters/http/httpDescription.js +246 -0
- package/dist/adapters/http/openapi.d.ts +98 -0
- package/dist/adapters/http/openapi.js +487 -0
- package/dist/adapters/layoutRefusal.d.ts +24 -0
- package/dist/adapters/layoutRefusal.js +35 -0
- package/dist/adapters/net/networkPolicy.d.ts +44 -0
- package/dist/adapters/net/networkPolicy.js +123 -0
- package/dist/adapters/net/untrustedDatabase.d.ts +18 -0
- package/dist/adapters/net/untrustedDatabase.js +120 -0
- package/dist/adapters/poolAdmission.d.ts +43 -0
- package/dist/adapters/poolAdmission.js +184 -0
- package/dist/adapters/poolMetrics.d.ts +121 -0
- package/dist/adapters/poolMetrics.js +185 -0
- package/dist/adapters/postgres.d.ts +441 -0
- package/dist/adapters/postgres.js +1841 -0
- package/dist/adapters/postgresCatalog.d.ts +107 -0
- package/dist/adapters/postgresCatalog.js +421 -0
- package/dist/adapters/postgresCatalogDigest.d.ts +30 -0
- package/dist/adapters/postgresCatalogDigest.js +93 -0
- package/dist/adapters/postgresCatalogRows.d.ts +64 -0
- package/dist/adapters/postgresCatalogRows.js +37 -0
- package/dist/adapters/postgresDates.d.ts +1 -0
- package/dist/adapters/postgresDates.js +39 -0
- package/dist/adapters/postgresMaintenance.d.ts +33 -0
- package/dist/adapters/postgresMaintenance.js +179 -0
- package/dist/adapters/postgresPool.d.ts +255 -0
- package/dist/adapters/postgresPool.js +838 -0
- package/dist/adapters/postgresPooler.d.ts +28 -0
- package/dist/adapters/postgresPooler.js +267 -0
- package/dist/adapters/postgresReadCatalog.d.ts +31 -0
- package/dist/adapters/postgresReadCatalog.js +226 -0
- package/dist/adapters/postgresReadSnapshot.d.ts +46 -0
- package/dist/adapters/postgresReadSnapshot.js +133 -0
- package/dist/adapters/postgresSchemaEpoch.d.ts +24 -0
- package/dist/adapters/postgresSchemaEpoch.js +149 -0
- package/dist/adapters/postgresTransactionHandle.d.ts +173 -0
- package/dist/adapters/postgresTransactionHandle.js +524 -0
- package/dist/adapters/postgresValues.d.ts +30 -0
- package/dist/adapters/postgresValues.js +75 -0
- package/dist/adapters/postgresWriteAhead.d.ts +47 -0
- package/dist/adapters/postgresWriteAhead.js +209 -0
- package/dist/adapters/replicas.d.ts +70 -0
- package/dist/adapters/replicas.js +208 -0
- package/dist/adapters/reservedSql.d.ts +38 -0
- package/dist/adapters/reservedSql.js +264 -0
- package/dist/adapters/rolePrivileges.d.ts +17 -0
- package/dist/adapters/rolePrivileges.js +22 -0
- package/dist/adapters/scoped/keyRows.d.ts +65 -0
- package/dist/adapters/scoped/keyRows.js +179 -0
- package/dist/adapters/scoped/keyTypes.d.ts +34 -0
- package/dist/adapters/scoped/keyTypes.js +66 -0
- package/dist/adapters/scoped/postgresScopeCatalog.d.ts +34 -0
- package/dist/adapters/scoped/postgresScopeCatalog.js +457 -0
- package/dist/adapters/scoped/postgresTriggers.d.ts +137 -0
- package/dist/adapters/scoped/postgresTriggers.js +1545 -0
- package/dist/adapters/scoped/scopeTriggers.d.ts +122 -0
- package/dist/adapters/scoped/scopeTriggers.js +131 -0
- package/dist/adapters/scoped/scopedCommandOperations.d.ts +5 -0
- package/dist/adapters/scoped/scopedCommandOperations.js +48 -0
- package/dist/adapters/scoped/scopedReads.d.ts +22 -0
- package/dist/adapters/scoped/scopedReads.js +192 -0
- package/dist/adapters/scoped/scopedTransaction.d.ts +159 -0
- package/dist/adapters/scoped/scopedTransaction.js +547 -0
- package/dist/adapters/scoped/sqliteScopeCatalog.d.ts +32 -0
- package/dist/adapters/scoped/sqliteScopeCatalog.js +420 -0
- package/dist/adapters/scoped/sqliteTriggerSession.d.ts +64 -0
- package/dist/adapters/scoped/sqliteTriggerSession.js +245 -0
- package/dist/adapters/scoped/sqliteTriggers.d.ts +20 -0
- package/dist/adapters/scoped/sqliteTriggers.js +822 -0
- package/dist/adapters/scoped/storedText.d.ts +45 -0
- package/dist/adapters/scoped/storedText.js +61 -0
- package/dist/adapters/scoped/triggerEffects.d.ts +98 -0
- package/dist/adapters/scoped/triggerEffects.js +189 -0
- package/dist/adapters/scoped/triggerProof.d.ts +124 -0
- package/dist/adapters/scoped/triggerProof.js +366 -0
- package/dist/adapters/scoped/updateGuard.d.ts +3 -0
- package/dist/adapters/scoped/updateGuard.js +40 -0
- package/dist/adapters/serverSettings.d.ts +45 -0
- package/dist/adapters/serverSettings.js +46 -0
- package/dist/adapters/snapshotRead.d.ts +8 -0
- package/dist/adapters/snapshotRead.js +37 -0
- package/dist/adapters/sqlite.d.ts +273 -0
- package/dist/adapters/sqlite.js +1557 -0
- package/dist/adapters/sqliteCostlyReads.d.ts +33 -0
- package/dist/adapters/sqliteCostlyReads.js +49 -0
- package/dist/adapters/sqliteDecimals.d.ts +22 -0
- package/dist/adapters/sqliteDecimals.js +51 -0
- package/dist/adapters/sqliteHandles.d.ts +43 -0
- package/dist/adapters/sqliteHandles.js +143 -0
- package/dist/adapters/sqliteStatementProcess.d.ts +29 -0
- package/dist/adapters/sqliteStatementProcess.js +131 -0
- package/dist/adapters/statementControl.d.ts +34 -0
- package/dist/adapters/statementControl.js +90 -0
- package/dist/adapters/storeHost.d.ts +133 -0
- package/dist/adapters/storeHost.js +13 -0
- package/dist/adapters/telemetry/drivers.d.ts +21 -0
- package/dist/adapters/telemetry/drivers.js +321 -0
- package/dist/adapters/telemetry/metrics.d.ts +63 -0
- package/dist/adapters/telemetry/metrics.js +122 -0
- package/dist/adapters/telemetry/otlp.d.ts +12 -0
- package/dist/adapters/telemetry/otlp.js +320 -0
- package/dist/adapters/telemetry/otlpEncode.d.ts +48 -0
- package/dist/adapters/telemetry/otlpEncode.js +366 -0
- package/dist/adapters/telemetry/otlpEnv.d.ts +1 -0
- package/dist/adapters/telemetry/otlpEnv.js +12 -0
- package/dist/adapters/telemetry/serverTiming.d.ts +83 -0
- package/dist/adapters/telemetry/serverTiming.js +503 -0
- package/dist/adapters/telemetry/start.d.ts +10 -0
- package/dist/adapters/telemetry/start.js +25 -0
- package/dist/adapters/telemetry/statement.d.ts +16 -0
- package/dist/adapters/telemetry/statement.js +134 -0
- package/dist/adapters/telemetry/trace.d.ts +127 -0
- package/dist/adapters/telemetry/trace.js +295 -0
- package/dist/adapters/writeAhead.d.ts +27 -0
- package/dist/adapters/writeAhead.js +46 -0
- package/dist/adapters/writeAttribution.d.ts +18 -0
- package/dist/adapters/writeAttribution.js +23 -0
- package/dist/adapters/writeCapture.d.ts +80 -0
- package/dist/adapters/writeCapture.js +20 -0
- package/dist/adapters/writeLanes.d.ts +94 -0
- package/dist/adapters/writeLanes.js +232 -0
- package/dist/engine.d.ts +15 -0
- package/dist/engine.js +13 -0
- package/dist/server/auth/credentials.d.ts +61 -0
- package/dist/server/auth/credentials.js +260 -0
- package/dist/server/cacheService.d.ts +50 -0
- package/dist/server/cacheService.js +110 -0
- package/dist/server/cli/args.d.ts +182 -0
- package/dist/server/cli/args.js +348 -0
- package/dist/server/cli/bin.d.ts +5 -0
- package/dist/server/cli/bin.js +66 -0
- package/dist/server/cli/browser.d.ts +15 -0
- package/dist/server/cli/browser.js +37 -0
- package/dist/server/cli/config.d.ts +50 -0
- package/dist/server/cli/config.js +206 -0
- package/dist/server/cli/startup.d.ts +36 -0
- package/dist/server/cli/startup.js +128 -0
- package/dist/server/cli/startupOptions.d.ts +63 -0
- package/dist/server/cli/startupOptions.js +143 -0
- package/dist/server/cli/subcommand.d.ts +28 -0
- package/dist/server/cli/subcommand.js +32 -0
- package/dist/server/cli/usage.d.ts +13 -0
- package/dist/server/cli/usage.js +31 -0
- package/dist/server/clientHttp.d.ts +184 -0
- package/dist/server/clientHttp.js +700 -0
- package/dist/server/clientSurface.d.ts +128 -0
- package/dist/server/clientSurface.js +182 -0
- package/dist/server/columnGrants.d.ts +106 -0
- package/dist/server/columnGrants.js +741 -0
- package/dist/server/compileCache.d.ts +1 -0
- package/dist/server/compileCache.js +30 -0
- package/dist/server/config/locations.d.ts +1 -0
- package/dist/server/config/locations.js +15 -0
- package/dist/server/config/profile.d.ts +123 -0
- package/dist/server/config/profile.js +236 -0
- package/dist/server/configPaths.d.ts +7 -0
- package/dist/server/configPaths.js +34 -0
- package/dist/server/configSections.d.ts +64 -0
- package/dist/server/configSections.js +72 -0
- package/dist/server/connectionRedaction.d.ts +30 -0
- package/dist/server/connectionRedaction.js +77 -0
- package/dist/server/connections.d.ts +358 -0
- package/dist/server/connections.js +988 -0
- package/dist/server/constraints.d.ts +82 -0
- package/dist/server/constraints.js +169 -0
- package/dist/server/demo.d.ts +9 -0
- package/dist/server/demo.js +554 -0
- package/dist/server/devclient.d.ts +108 -0
- package/dist/server/devclient.js +361 -0
- package/dist/server/evidence.d.ts +55 -0
- package/dist/server/evidence.js +323 -0
- package/dist/server/hiddenColumns.d.ts +32 -0
- package/dist/server/hiddenColumns.js +244 -0
- package/dist/server/http/baselineHeaders.d.ts +24 -0
- package/dist/server/http/baselineHeaders.js +12 -0
- package/dist/server/http/captured.d.ts +35 -0
- package/dist/server/http/captured.js +73 -0
- package/dist/server/http/clock.d.ts +1 -0
- package/dist/server/http/clock.js +14 -0
- package/dist/server/http/connectionSource.d.ts +4 -0
- package/dist/server/http/connectionSource.js +48 -0
- package/dist/server/http/context.d.ts +189 -0
- package/dist/server/http/context.js +11 -0
- package/dist/server/http/crawlerText.d.ts +15 -0
- package/dist/server/http/crawlerText.js +32 -0
- package/dist/server/http/dataRoutes.d.ts +88 -0
- package/dist/server/http/dataRoutes.js +137 -0
- package/dist/server/http/door.d.ts +57 -0
- package/dist/server/http/door.js +39 -0
- package/dist/server/http/exportRoute.d.ts +15 -0
- package/dist/server/http/exportRoute.js +320 -0
- package/dist/server/http/firstPaint.d.ts +108 -0
- package/dist/server/http/firstPaint.js +262 -0
- package/dist/server/http/httpOperationRoutes.d.ts +11 -0
- package/dist/server/http/httpOperationRoutes.js +50 -0
- package/dist/server/http/pageReads.d.ts +20 -0
- package/dist/server/http/pageReads.js +205 -0
- package/dist/server/http/pageRoutes.d.ts +39 -0
- package/dist/server/http/pageRoutes.js +291 -0
- package/dist/server/http/probes.d.ts +22 -0
- package/dist/server/http/probes.js +27 -0
- package/dist/server/http/rateLimit.d.ts +131 -0
- package/dist/server/http/rateLimit.js +351 -0
- package/dist/server/http/readRoutes.d.ts +9 -0
- package/dist/server/http/readRoutes.js +131 -0
- package/dist/server/http/readRouting.d.ts +20 -0
- package/dist/server/http/readRouting.js +80 -0
- package/dist/server/http/recordCompose.d.ts +67 -0
- package/dist/server/http/recordCompose.js +167 -0
- package/dist/server/http/recordWrites.d.ts +89 -0
- package/dist/server/http/recordWrites.js +298 -0
- package/dist/server/http/refusalReport.d.ts +38 -0
- package/dist/server/http/refusalReport.js +75 -0
- package/dist/server/http/reply.d.ts +130 -0
- package/dist/server/http/reply.js +394 -0
- package/dist/server/http/requestOrigin.d.ts +11 -0
- package/dist/server/http/requestOrigin.js +8 -0
- package/dist/server/http/router.d.ts +45 -0
- package/dist/server/http/router.js +22 -0
- package/dist/server/http/serverCore.d.ts +68 -0
- package/dist/server/http/serverCore.js +177 -0
- package/dist/server/http/traceRequest.d.ts +30 -0
- package/dist/server/http/traceRequest.js +224 -0
- package/dist/server/http/trust.d.ts +261 -0
- package/dist/server/http/trust.js +472 -0
- package/dist/server/http/writeRefusal.d.ts +33 -0
- package/dist/server/http/writeRefusal.js +24 -0
- package/dist/server/httpConnection.d.ts +49 -0
- package/dist/server/httpConnection.js +170 -0
- package/dist/server/impact.d.ts +55 -0
- package/dist/server/impact.js +47 -0
- package/dist/server/journal.d.ts +134 -0
- package/dist/server/journal.js +398 -0
- package/dist/server/keysetReadHttp.d.ts +52 -0
- package/dist/server/keysetReadHttp.js +85 -0
- package/dist/server/layouts.d.ts +49 -0
- package/dist/server/layouts.js +192 -0
- package/dist/server/migrate/cli.d.ts +102 -0
- package/dist/server/migrate/cli.js +702 -0
- package/dist/server/migrate/database.d.ts +37 -0
- package/dist/server/migrate/database.js +247 -0
- package/dist/server/migrate/desired.d.ts +76 -0
- package/dist/server/migrate/desired.js +292 -0
- package/dist/server/migrate/files.d.ts +34 -0
- package/dist/server/migrate/files.js +141 -0
- package/dist/server/migrate/flyway.d.ts +7 -0
- package/dist/server/migrate/flyway.js +69 -0
- package/dist/server/migrate/history.d.ts +70 -0
- package/dist/server/migrate/history.js +211 -0
- package/dist/server/migrate/runner.d.ts +100 -0
- package/dist/server/migrate/runner.js +413 -0
- package/dist/server/migrate/snapshot.d.ts +30 -0
- package/dist/server/migrate/snapshot.js +239 -0
- package/dist/server/migrate/target.d.ts +33 -0
- package/dist/server/migrate/target.js +82 -0
- package/dist/server/openapiDraft.d.ts +25 -0
- package/dist/server/openapiDraft.js +171 -0
- package/dist/server/operations/diagnostics.d.ts +101 -0
- package/dist/server/operations/diagnostics.js +284 -0
- package/dist/server/operations/requestMetrics.d.ts +33 -0
- package/dist/server/operations/requestMetrics.js +94 -0
- package/dist/server/packageVersion.d.ts +1 -0
- package/dist/server/packageVersion.js +11 -0
- package/dist/server/poolConfig.d.ts +34 -0
- package/dist/server/poolConfig.js +114 -0
- package/dist/server/product.d.ts +20 -0
- package/dist/server/product.js +12 -0
- package/dist/server/recordHistoryOperations.d.ts +39 -0
- package/dist/server/recordHistoryOperations.js +43 -0
- package/dist/server/recordWriteOperations.d.ts +111 -0
- package/dist/server/recordWriteOperations.js +329 -0
- package/dist/server/resourceReadHttp.d.ts +81 -0
- package/dist/server/resourceReadHttp.js +606 -0
- package/dist/server/resourceReadOperations.d.ts +147 -0
- package/dist/server/resourceReadOperations.js +452 -0
- package/dist/server/scaffoldMachine.d.ts +54 -0
- package/dist/server/scaffoldMachine.js +184 -0
- package/dist/server/seed/cli.d.ts +20 -0
- package/dist/server/seed/cli.js +164 -0
- package/dist/server/seed/lexicon.d.ts +26 -0
- package/dist/server/seed/lexicon.js +585 -0
- package/dist/server/seed/seed.d.ts +70 -0
- package/dist/server/seed/seed.js +779 -0
- package/dist/server/seed/words.d.ts +21 -0
- package/dist/server/seed/words.js +164 -0
- package/dist/server/serverRequests.d.ts +6 -0
- package/dist/server/serverRequests.js +33 -0
- package/dist/server/serverTimeouts.d.ts +33 -0
- package/dist/server/serverTimeouts.js +32 -0
- package/dist/server/shapeonly.d.ts +32 -0
- package/dist/server/shapeonly.js +115 -0
- package/dist/server/startupWarnings.d.ts +32 -0
- package/dist/server/startupWarnings.js +92 -0
- package/dist/shared/addressParams.d.ts +28 -0
- package/dist/shared/addressParams.js +47 -0
- package/dist/shared/aggregate.d.ts +49 -0
- package/dist/shared/aggregate.js +107 -0
- package/dist/shared/appCards.d.ts +123 -0
- package/dist/shared/appCards.js +385 -0
- package/dist/shared/appComponents.d.ts +177 -0
- package/dist/shared/appComponents.js +422 -0
- package/dist/shared/appDocuments.d.ts +43 -0
- package/dist/shared/appDocuments.js +131 -0
- package/dist/shared/appEmbeds.d.ts +21 -0
- package/dist/shared/appEmbeds.js +24 -0
- package/dist/shared/appIcons.d.ts +28 -0
- package/dist/shared/appIcons.js +223 -0
- package/dist/shared/appLinks.d.ts +17 -0
- package/dist/shared/appLinks.js +124 -0
- package/dist/shared/appListColumns.d.ts +3 -0
- package/dist/shared/appListColumns.js +66 -0
- package/dist/shared/appLocale.d.ts +36 -0
- package/dist/shared/appLocale.js +86 -0
- package/dist/shared/appMessages.d.ts +44 -0
- package/dist/shared/appMessages.js +78 -0
- package/dist/shared/appNoun.d.ts +21 -0
- package/dist/shared/appNoun.js +32 -0
- package/dist/shared/autoBucket.d.ts +98 -0
- package/dist/shared/autoBucket.js +305 -0
- package/dist/shared/autoValues.d.ts +25 -0
- package/dist/shared/autoValues.js +25 -0
- package/dist/shared/breakdown.d.ts +228 -0
- package/dist/shared/breakdown.js +570 -0
- package/dist/shared/breakdowntext.d.ts +41 -0
- package/dist/shared/breakdowntext.js +400 -0
- package/dist/shared/builtInThemes.d.ts +2 -0
- package/dist/shared/builtInThemes.js +771 -0
- package/dist/shared/chartSeparation.d.ts +11 -0
- package/dist/shared/chartSeparation.js +58 -0
- package/dist/shared/clauses.d.ts +22 -0
- package/dist/shared/clauses.js +97 -0
- package/dist/shared/columnCaption.d.ts +16 -0
- package/dist/shared/columnCaption.js +90 -0
- package/dist/shared/commandFieldPath.d.ts +2 -0
- package/dist/shared/commandFieldPath.js +7 -0
- package/dist/shared/commandWire.d.ts +26 -0
- package/dist/shared/commandWire.js +41 -0
- package/dist/shared/computed.d.ts +161 -0
- package/dist/shared/computed.js +378 -0
- package/dist/shared/computedParse.d.ts +13 -0
- package/dist/shared/computedParse.js +278 -0
- package/dist/shared/computedValue.d.ts +47 -0
- package/dist/shared/computedValue.js +191 -0
- package/dist/shared/connection.d.ts +30 -0
- package/dist/shared/connection.js +1 -0
- package/dist/shared/csv.d.ts +20 -0
- package/dist/shared/csv.js +63 -0
- package/dist/shared/dashLayout.d.ts +30 -0
- package/dist/shared/dashLayout.js +132 -0
- package/dist/shared/dashboardAsks.d.ts +93 -0
- package/dist/shared/dashboardAsks.js +129 -0
- package/dist/shared/dashboardTrend.d.ts +20 -0
- package/dist/shared/dashboardTrend.js +50 -0
- package/dist/shared/decimals.d.ts +37 -0
- package/dist/shared/decimals.js +148 -0
- package/dist/shared/declaredReferences.d.ts +50 -0
- package/dist/shared/declaredReferences.js +202 -0
- package/dist/shared/definedFields.d.ts +63 -0
- package/dist/shared/definedFields.js +103 -0
- package/dist/shared/definedValues.d.ts +63 -0
- package/dist/shared/definedValues.js +184 -0
- package/dist/shared/displayDefaults.d.ts +135 -0
- package/dist/shared/displayDefaults.js +543 -0
- package/dist/shared/dueDate.d.ts +6 -0
- package/dist/shared/dueDate.js +6 -0
- package/dist/shared/duration.d.ts +4 -0
- package/dist/shared/duration.js +23 -0
- package/dist/shared/fileBounds.d.ts +9 -0
- package/dist/shared/fileBounds.js +9 -0
- package/dist/shared/filter.d.ts +238 -0
- package/dist/shared/filter.js +332 -0
- package/dist/shared/firstPaint.d.ts +24 -0
- package/dist/shared/firstPaint.js +33 -0
- package/dist/shared/form.d.ts +21 -0
- package/dist/shared/form.js +25 -0
- package/dist/shared/formValues.d.ts +104 -0
- package/dist/shared/formValues.js +352 -0
- package/dist/shared/funnel.d.ts +45 -0
- package/dist/shared/funnel.js +108 -0
- package/dist/shared/httpOperations.d.ts +48 -0
- package/dist/shared/httpOperations.js +9 -0
- package/dist/shared/iconGlyphs.d.ts +4 -0
- package/dist/shared/iconGlyphs.js +151 -0
- package/dist/shared/iconWeights.d.ts +3 -0
- package/dist/shared/iconWeights.js +162 -0
- package/dist/shared/imageWidths.d.ts +32 -0
- package/dist/shared/imageWidths.js +38 -0
- package/dist/shared/keysetPage.d.ts +64 -0
- package/dist/shared/keysetPage.js +161 -0
- package/dist/shared/like.d.ts +20 -0
- package/dist/shared/like.js +29 -0
- package/dist/shared/listEmpty.d.ts +12 -0
- package/dist/shared/listEmpty.js +36 -0
- package/dist/shared/listFilters.d.ts +28 -0
- package/dist/shared/listFilters.js +84 -0
- package/dist/shared/listPresentations.d.ts +199 -0
- package/dist/shared/listPresentations.js +7 -0
- package/dist/shared/listQuestion.d.ts +52 -0
- package/dist/shared/listQuestion.js +137 -0
- package/dist/shared/lookPalettes.d.ts +62 -0
- package/dist/shared/lookPalettes.js +306 -0
- package/dist/shared/maskQuoted.d.ts +24 -0
- package/dist/shared/maskQuoted.js +48 -0
- package/dist/shared/mentionLabel.d.ts +19 -0
- package/dist/shared/mentionLabel.js +38 -0
- package/dist/shared/mentionLookup.d.ts +17 -0
- package/dist/shared/mentionLookup.js +64 -0
- package/dist/shared/menuCounts.d.ts +16 -0
- package/dist/shared/menuCounts.js +74 -0
- package/dist/shared/model.d.ts +79 -0
- package/dist/shared/model.js +153 -0
- package/dist/shared/money.d.ts +53 -0
- package/dist/shared/money.js +98 -0
- package/dist/shared/moneyEntry.d.ts +7 -0
- package/dist/shared/moneyEntry.js +27 -0
- package/dist/shared/mount.d.ts +118 -0
- package/dist/shared/mount.js +248 -0
- package/dist/shared/niceTicks.d.ts +26 -0
- package/dist/shared/niceTicks.js +50 -0
- package/dist/shared/order.d.ts +59 -0
- package/dist/shared/order.js +133 -0
- package/dist/shared/page.d.ts +135 -0
- package/dist/shared/page.js +1187 -0
- package/dist/shared/pageAnatomy.d.ts +99 -0
- package/dist/shared/pageAnatomy.js +370 -0
- package/dist/shared/pageConfig.d.ts +25 -0
- package/dist/shared/pageConfig.js +1308 -0
- package/dist/shared/pageEmptyActions.d.ts +12 -0
- package/dist/shared/pageEmptyActions.js +20 -0
- package/dist/shared/pageLayouts.d.ts +72 -0
- package/dist/shared/pageLayouts.js +205 -0
- package/dist/shared/pageModel.d.ts +785 -0
- package/dist/shared/pageModel.js +121 -0
- package/dist/shared/pagePaths.d.ts +180 -0
- package/dist/shared/pagePaths.js +869 -0
- package/dist/shared/pagePlans.d.ts +52 -0
- package/dist/shared/pagePlans.js +108 -0
- package/dist/shared/pageRoutes.d.ts +9 -0
- package/dist/shared/pageRoutes.js +9 -0
- package/dist/shared/query.d.ts +166 -0
- package/dist/shared/query.js +1302 -0
- package/dist/shared/queryDates.d.ts +12 -0
- package/dist/shared/queryDates.js +101 -0
- package/dist/shared/queryOperands.d.ts +99 -0
- package/dist/shared/queryOperands.js +131 -0
- package/dist/shared/reads.d.ts +103 -0
- package/dist/shared/reads.js +154 -0
- package/dist/shared/recordLabel.d.ts +51 -0
- package/dist/shared/recordLabel.js +123 -0
- package/dist/shared/recordReadKeys.d.ts +30 -0
- package/dist/shared/recordReadKeys.js +51 -0
- package/dist/shared/recordReads.d.ts +268 -0
- package/dist/shared/recordReads.js +368 -0
- package/dist/shared/recordview.d.ts +198 -0
- package/dist/shared/recordview.js +356 -0
- package/dist/shared/referenceModel.d.ts +58 -0
- package/dist/shared/referenceModel.js +194 -0
- package/dist/shared/refusal.d.ts +80 -0
- package/dist/shared/refusal.js +184 -0
- package/dist/shared/relatedCreate.d.ts +30 -0
- package/dist/shared/relatedCreate.js +162 -0
- package/dist/shared/resourceHttp.d.ts +464 -0
- package/dist/shared/resourceHttp.js +1 -0
- package/dist/shared/richText.d.ts +85 -0
- package/dist/shared/richText.js +305 -0
- package/dist/shared/rollups.d.ts +143 -0
- package/dist/shared/rollups.js +64 -0
- package/dist/shared/rowScope.d.ts +72 -0
- package/dist/shared/rowScope.js +376 -0
- package/dist/shared/runtimeTables.d.ts +44 -0
- package/dist/shared/runtimeTables.js +79 -0
- package/dist/shared/schema.d.ts +529 -0
- package/dist/shared/schema.js +627 -0
- package/dist/shared/schematext.d.ts +38 -0
- package/dist/shared/schematext.js +101 -0
- package/dist/shared/scopeCatalog.d.ts +29 -0
- package/dist/shared/scopeCatalog.js +472 -0
- package/dist/shared/servedApp.d.ts +686 -0
- package/dist/shared/servedApp.js +45 -0
- package/dist/shared/sessionLease.d.ts +34 -0
- package/dist/shared/sessionLease.js +3 -0
- package/dist/shared/shape.d.ts +55 -0
- package/dist/shared/shape.js +168 -0
- package/dist/shared/slug.d.ts +1 -0
- package/dist/shared/slug.js +12 -0
- package/dist/shared/sortText.d.ts +14 -0
- package/dist/shared/sortText.js +26 -0
- package/dist/shared/sqlRelation.d.ts +4 -0
- package/dist/shared/sqlRelation.js +8 -0
- package/dist/shared/sqlsaved.d.ts +44 -0
- package/dist/shared/sqlsaved.js +63 -0
- package/dist/shared/stitchedPaths.d.ts +27 -0
- package/dist/shared/stitchedPaths.js +38 -0
- package/dist/shared/structuredFilter.d.ts +22 -0
- package/dist/shared/structuredFilter.js +1 -0
- package/dist/shared/subtitlePath.d.ts +20 -0
- package/dist/shared/subtitlePath.js +24 -0
- package/dist/shared/suggest.d.ts +18 -0
- package/dist/shared/suggest.js +59 -0
- package/dist/shared/tableSizing.d.ts +4 -0
- package/dist/shared/tableSizing.js +9 -0
- package/dist/shared/tagLists.d.ts +57 -0
- package/dist/shared/tagLists.js +34 -0
- package/dist/shared/textRules.d.ts +54 -0
- package/dist/shared/textRules.js +133 -0
- package/dist/shared/theme.d.ts +94 -0
- package/dist/shared/theme.js +800 -0
- package/dist/shared/themeColor.d.ts +34 -0
- package/dist/shared/themeColor.js +109 -0
- package/dist/shared/themeFaces.d.ts +30 -0
- package/dist/shared/themeFaces.js +42 -0
- package/dist/shared/themeInk.d.ts +20 -0
- package/dist/shared/themeInk.js +52 -0
- package/dist/shared/themeLooks.d.ts +9 -0
- package/dist/shared/themeLooks.js +572 -0
- package/dist/shared/themeParts.d.ts +26 -0
- package/dist/shared/themeParts.js +71 -0
- package/dist/shared/themePartsCheck.d.ts +21 -0
- package/dist/shared/themePartsCheck.js +91 -0
- package/dist/shared/themePresets.d.ts +85 -0
- package/dist/shared/themePresets.js +139 -0
- package/dist/shared/themeRecipeWords.d.ts +156 -0
- package/dist/shared/themeRecipeWords.js +156 -0
- package/dist/shared/themeRecipes.d.ts +213 -0
- package/dist/shared/themeRecipes.js +234 -0
- package/dist/shared/themeResolve.d.ts +55 -0
- package/dist/shared/themeResolve.js +52 -0
- package/dist/shared/themeTokens.d.ts +107 -0
- package/dist/shared/themeTokens.js +116 -0
- package/dist/shared/themeType.d.ts +38 -0
- package/dist/shared/themeType.js +205 -0
- package/dist/shared/unitWord.d.ts +4 -0
- package/dist/shared/unitWord.js +37 -0
- package/dist/shared/view.d.ts +195 -0
- package/dist/shared/view.js +987 -0
- package/dist/shared/viewLabels.d.ts +47 -0
- package/dist/shared/viewLabels.js +459 -0
- package/dist/shared/viewPaths.d.ts +248 -0
- package/dist/shared/viewPaths.js +294 -0
- package/dist/shared/viewtext.d.ts +57 -0
- package/dist/shared/viewtext.js +282 -0
- package/dist/shared/vocabulary.d.ts +71 -0
- package/dist/shared/vocabulary.js +249 -0
- package/dist/shared/weekStart.d.ts +7 -0
- package/dist/shared/weekStart.js +36 -0
- package/mark.svg +1 -0
- package/package.json +266 -3
- package/schema/model.d.ts +298 -0
- package/schema/theme.d.ts +587 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { DatabaseSchema } from '../../shared/schema.js';
|
|
2
|
+
import type { RowScope } from '../../shared/rowScope.js';
|
|
3
|
+
import type { PgQuery } from '../postgresPool.js';
|
|
4
|
+
import { type ScopeCatalog } from './scopedTransaction.js';
|
|
5
|
+
import type { TriggerKeyFacts } from './triggerEffects.js';
|
|
6
|
+
export interface PostgresScopeCatalog extends ScopeCatalog {
|
|
7
|
+
/** Ordinary tables the writer role may UPDATE, and so lock rows in. A
|
|
8
|
+
* superset of `writable`: a lockable table with a trigger is still refused
|
|
9
|
+
* as a target, but its rows can be held for a parent-visibility check. */
|
|
10
|
+
lockable: ReadonlySet<string>;
|
|
11
|
+
/** The relations this read pinned, quoted, in order: what a later transaction under the same epoch pins before it reads the epoch. */
|
|
12
|
+
pinned: readonly string[];
|
|
13
|
+
/** Each table in `triggered`, what its triggers' proof was read from (postgresTriggers.ts triggerVersion): read
|
|
14
|
+
* again before COMMIT by a transaction that relied on it (attestPostgresTriggers). */
|
|
15
|
+
triggerVersions?: ReadonlyMap<string, string>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Before COMMIT, in a transaction that let a write fire a trigger the catalog proved validation-only: the proof's
|
|
19
|
+
* sources read again. A table's triggers cannot change under its pin, but the function a trigger runs, and the
|
|
20
|
+
* functions, operators and casts its conditions resolve to, can (CREATE OR REPLACE FUNCTION takes no lock on the table). Under
|
|
21
|
+
* READ COMMITTED this read sees every change committed before it, so every version a write that has already run
|
|
22
|
+
* could have used: a changed one refuses the transaction.
|
|
23
|
+
*/
|
|
24
|
+
export declare function attestPostgresTriggers(client: PgQuery, catalog: PostgresScopeCatalog, tables: ReadonlySet<string>): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* For `mistri check`: what a write's own catalog reads about `ids` to judge a trigger's effects
|
|
27
|
+
* (readPostgresScopeCatalog), read on `client` outside a write: the keys, the tables in a partition or inheritance
|
|
28
|
+
* hierarchy, and the tables a scoped write cannot target for row security, a rule, or the role's privileges.
|
|
29
|
+
*/
|
|
30
|
+
export declare function effectCatalogFacts(client: PgQuery, given: readonly string[]): Promise<TriggerKeyFacts>;
|
|
31
|
+
/** Call only on the leased writer inside its transaction, before any read of
|
|
32
|
+
* user data. The describe callback is the adapter's own introspection so the
|
|
33
|
+
* evidence has the same shape as the catalog the permissions were bound to. */
|
|
34
|
+
export declare function readPostgresScopeCatalog(client: PgQuery, scope: RowScope, describe: (client: PgQuery) => Promise<DatabaseSchema>): Promise<PostgresScopeCatalog>;
|
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The scope catalog on PostgreSQL.
|
|
3
|
+
*
|
|
4
|
+
* SQLite reads its physical metadata inside `BEGIN IMMEDIATE`, where nothing
|
|
5
|
+
* else can write, so what it attests is what the transaction will see until
|
|
6
|
+
* COMMIT. PostgreSQL has no such fence: DDL from another session commits
|
|
7
|
+
* under a READ COMMITTED transaction unless something holds a lock on the
|
|
8
|
+
* relation it touches. So the tables this scope may write are pinned first,
|
|
9
|
+
* with `LOCK TABLE … IN ROW EXCLUSIVE MODE` — the lock an UPDATE takes
|
|
10
|
+
* anyway, compatible with every ordinary reader and writer and in conflict
|
|
11
|
+
* with everything that would change what a write means: ALTER TABLE, CREATE
|
|
12
|
+
* TRIGGER, ADD FOREIGN KEY (on either side), CREATE INDEX, ENABLE ROW LEVEL
|
|
13
|
+
* SECURITY. The catalog is read *after* the pin, so drift that committed
|
|
14
|
+
* before it is what the attestation compares, and drift after it waits for
|
|
15
|
+
* this transaction to end.
|
|
16
|
+
*
|
|
17
|
+
* Only tables in the scope that the writer role may update are pinned. That
|
|
18
|
+
* is not a loophole: a table outside the scope is unreadable here (`WHERE
|
|
19
|
+
* 1 = 0`), and one the role cannot update cannot be written by it, locked
|
|
20
|
+
* for update, or have its rows held for a parent check — so it is never in
|
|
21
|
+
* `writable` and the guarantee it lacks is one it could not use.
|
|
22
|
+
*
|
|
23
|
+
* What is described is exactly what `introspect()` describes, on the leased
|
|
24
|
+
* writer inside the transaction, so the deployed catalog and this evidence
|
|
25
|
+
* differ only when the database does.
|
|
26
|
+
*/
|
|
27
|
+
import { POSTGRES_STYLE, Refusal } from '../adapter.js';
|
|
28
|
+
import { captureScopeCatalog } from '../../shared/scopeCatalog.js';
|
|
29
|
+
import { writtenType } from '../postgresCatalog.js';
|
|
30
|
+
import { referenceKey, triggerNames } from './scopedTransaction.js';
|
|
31
|
+
import { baseType, CATALOG_OPERATORS, defaultBtreeClass, postgresTreeTriggerNames, postgresTriggerAnalyzer, postgresTriggersByTable, postgresTriggerStatement, postgresTriggerVersions, readPostgresTableCode, } from './postgresTriggers.js';
|
|
32
|
+
import { keyTypeRefusal, postgresKeyType } from './keyTypes.js';
|
|
33
|
+
const { EQ, GT, LT, NE, PLUS } = CATALOG_OPERATORS;
|
|
34
|
+
const refuse = () => {
|
|
35
|
+
throw new Refusal('PostgreSQL scoped transactions require a complete catalog and an ordinary table the writer may update.');
|
|
36
|
+
};
|
|
37
|
+
/** The adapter's own id convention: `schema.name`, or `name` in public. */
|
|
38
|
+
function located(id) {
|
|
39
|
+
const dot = id.indexOf('.');
|
|
40
|
+
return dot === -1 ? { schema: 'public', name: id } : { schema: id.slice(0, dot), name: id.slice(dot + 1) };
|
|
41
|
+
}
|
|
42
|
+
const key = (at) => `${at.schema}.${at.name}`;
|
|
43
|
+
/** A column's type as a refusal names it: as declared, and a domain with the type it is over. */
|
|
44
|
+
const saidType = (type, typmod, base, basemod) => `pg_catalog.format_type(${type}, ${typmod}) OPERATOR(pg_catalog.||) CASE WHEN ${type} ${NE} ${base}
|
|
45
|
+
THEN ' (a domain over ' OPERATOR(pg_catalog.||) pg_catalog.format_type(${base}, ${basemod}) OPERATOR(pg_catalog.||) ')' ELSE '' END`;
|
|
46
|
+
/** Everything that decides whether a write to a relation means what the
|
|
47
|
+
* scope assumes: its kind, row security, and the presence of triggers,
|
|
48
|
+
* rules and policies — and whether this role may update it at all. */
|
|
49
|
+
async function facts(client, targets) {
|
|
50
|
+
const result = new Map();
|
|
51
|
+
if (!targets.length)
|
|
52
|
+
return result;
|
|
53
|
+
const rows = await client.query(
|
|
54
|
+
/* Every function and operator named in pg_catalog (postgresTriggers.ts CAT): with `cardinality` found through the
|
|
55
|
+
search_path, `public.cardinality(text[])` answered 0 for every table, which read as no triggers at all. */
|
|
56
|
+
`SELECT n.nspname::pg_catalog.text AS schema, c.relname::pg_catalog.text AS name, c.relkind::pg_catalog.text AS kind,
|
|
57
|
+
c.relrowsecurity AS rls, pg_catalog.cardinality(fired.names) ${GT} 0 AS triggers, fired.names AS trigger_names,
|
|
58
|
+
EXISTS (SELECT 1 FROM pg_catalog.pg_rewrite r WHERE r.ev_class ${EQ} c.oid) AS rules,
|
|
59
|
+
EXISTS (SELECT 1 FROM pg_catalog.pg_policy p WHERE p.polrelid ${EQ} c.oid) AS policies,
|
|
60
|
+
pg_catalog.has_table_privilege(c.oid, 'UPDATE') AS updatable,
|
|
61
|
+
c.relkind ${EQ} 'p' OR EXISTS (SELECT 1 FROM pg_catalog.pg_inherits i WHERE i.inhrelid ${EQ} c.oid OR i.inhparent ${EQ} c.oid)
|
|
62
|
+
AS hierarchy,
|
|
63
|
+
unkeyed.name AS unkeyed_column, unkeyed.said AS unkeyed_type
|
|
64
|
+
FROM ${WANTED}
|
|
65
|
+
-- A key column whose type is not on the list (keyTypes.ts), its domains unwrapped: no scoped write targets the table.
|
|
66
|
+
LEFT JOIN LATERAL (SELECT a.attname::pg_catalog.text AS name, ${saidType('a.atttypid', 'a.atttypmod', 'b.type', 'b.typmod')} AS said
|
|
67
|
+
FROM pg_catalog.pg_index i JOIN pg_catalog.pg_attribute a ON a.attrelid ${EQ} c.oid AND a.attnum OPERATOR(pg_catalog.=) ANY (i.indkey)
|
|
68
|
+
CROSS JOIN LATERAL ${baseType('a.atttypid', 'a.atttypmod')} AS b
|
|
69
|
+
WHERE i.indrelid ${EQ} c.oid AND i.indisprimary AND NOT ${postgresKeyType('b.type')}
|
|
70
|
+
ORDER BY a.attnum LIMIT 1) AS unkeyed ON true
|
|
71
|
+
-- Its partitions' and inheritance children's too: a write through it reaches their rows and fires theirs.
|
|
72
|
+
CROSS JOIN LATERAL (SELECT ${postgresTreeTriggerNames('c.oid')} AS names) AS fired`, [targets.map((target) => target.schema), targets.map((target) => target.name)]);
|
|
73
|
+
for (const row of rows.rows) {
|
|
74
|
+
if (typeof row.schema !== 'string' ||
|
|
75
|
+
typeof row.name !== 'string' ||
|
|
76
|
+
typeof row.kind !== 'string' ||
|
|
77
|
+
[row.rls, row.triggers, row.rules, row.policies, row.updatable, row.hierarchy].some((value) => typeof value !== 'boolean') ||
|
|
78
|
+
!Array.isArray(row.trigger_names) ||
|
|
79
|
+
row.trigger_names.some((name) => typeof name !== 'string') ||
|
|
80
|
+
(row.unkeyed_column !== null && typeof row.unkeyed_column !== 'string') ||
|
|
81
|
+
(row.unkeyed_type !== null && typeof row.unkeyed_type !== 'string') ||
|
|
82
|
+
result.has(key(row)))
|
|
83
|
+
return refuse();
|
|
84
|
+
result.set(key(row), row);
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
const lockable = (fact) => fact !== undefined && ['r', 'p'].includes(fact.kind) && fact.updatable;
|
|
89
|
+
const clean = (fact) => !fact.rls && !fact.triggers && !fact.rules && !fact.policies;
|
|
90
|
+
/** Clean but for its triggers: each write is then judged by the triggers it fires (scopedTransaction.ts target). */
|
|
91
|
+
const cleanButTriggers = (fact) => fact.triggers && !fact.rls && !fact.rules && !fact.policies;
|
|
92
|
+
/** The rows of the triggers of `tables`, read on the writer. */
|
|
93
|
+
async function triggerRows(client, tables) {
|
|
94
|
+
const result = await client.query(postgresTriggerStatement(true), [
|
|
95
|
+
tables.map((table) => table.schema),
|
|
96
|
+
tables.map((table) => table.name),
|
|
97
|
+
]);
|
|
98
|
+
return result.rows;
|
|
99
|
+
}
|
|
100
|
+
/** The triggers of `tables` (adapter ids), read and proven on the writer: what fires each, whether it only validates, and what that was proven from. */
|
|
101
|
+
async function readTriggers(client, tables) {
|
|
102
|
+
const byKey = await postgresTriggersByTable(await triggerRows(client, tables), postgresTriggerAnalyzer(client));
|
|
103
|
+
const read = new Map();
|
|
104
|
+
for (const table of tables) {
|
|
105
|
+
const found = byKey.get(key(table));
|
|
106
|
+
// The facts said it has triggers, and the table is pinned against CREATE and DROP TRIGGER: none is a catalog this code misread.
|
|
107
|
+
if (!found)
|
|
108
|
+
return refuse();
|
|
109
|
+
read.set(table.id, found);
|
|
110
|
+
}
|
|
111
|
+
return read;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Before COMMIT, in a transaction that let a write fire a trigger the catalog proved validation-only: the proof's
|
|
115
|
+
* sources read again. A table's triggers cannot change under its pin, but the function a trigger runs, and the
|
|
116
|
+
* functions, operators and casts its conditions resolve to, can (CREATE OR REPLACE FUNCTION takes no lock on the table). Under
|
|
117
|
+
* READ COMMITTED this read sees every change committed before it, so every version a write that has already run
|
|
118
|
+
* could have used: a changed one refuses the transaction.
|
|
119
|
+
*/
|
|
120
|
+
export async function attestPostgresTriggers(client, catalog, tables) {
|
|
121
|
+
if (!tables.size)
|
|
122
|
+
return;
|
|
123
|
+
try {
|
|
124
|
+
const wanted = [...tables].map((id) => {
|
|
125
|
+
const table = catalog.schema.tables.find((candidate) => candidate.id === id);
|
|
126
|
+
const version = catalog.triggerVersions?.get(id);
|
|
127
|
+
if (!table || version === undefined)
|
|
128
|
+
return refuse();
|
|
129
|
+
return { id, schema: table.schema, name: table.name, version };
|
|
130
|
+
});
|
|
131
|
+
// The versions alone: what the proof was made from, not the proof made again.
|
|
132
|
+
const read = postgresTriggerVersions(await triggerRows(client, wanted));
|
|
133
|
+
for (const table of wanted)
|
|
134
|
+
if (read.get(key(table)) !== table.version)
|
|
135
|
+
return refuse();
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
if (error instanceof Refusal)
|
|
139
|
+
throw error;
|
|
140
|
+
return refuse();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/** The relations of `$1` (schemas) and `$2` (names), as `c` and `n`: the proof's own catalog read, its operators named in pg_catalog (postgresTriggers.ts). */
|
|
144
|
+
const WANTED = `pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid ${EQ} c.relnamespace
|
|
145
|
+
JOIN ROWS FROM (pg_catalog.unnest($1::pg_catalog.text[]), pg_catalog.unnest($2::pg_catalog.text[])) AS wanted(schema, name)
|
|
146
|
+
ON n.nspname ${EQ} wanted.schema AND c.relname ${EQ} wanted.name`;
|
|
147
|
+
/**
|
|
148
|
+
* How a trigger's key equality compares on PostgreSQL, for `ids` (triggerEffects.ts): each column's base type and
|
|
149
|
+
* type modifier with its domains unwrapped, its collation and whether that collation is deterministic; and the
|
|
150
|
+
* column sets each table is unique on as such an equality compares. A unique index counts only where it is valid,
|
|
151
|
+
* immediate (a deferrable one holds duplicates until COMMIT), B-tree, over plain columns of the whole table, and
|
|
152
|
+
* each column is indexed under its own collation and its type's default operator class: an index under "C" on a
|
|
153
|
+
* column whose collation folds case, or under a pattern operator class, is unique by an equality the trigger does not
|
|
154
|
+
* make. `TableMeta.unique` (an App's address, a tenant's bound) is read by looser rules and is left as it is.
|
|
155
|
+
*/
|
|
156
|
+
async function effectKeyFacts(client, ids) {
|
|
157
|
+
// Each once: a table named twice would count each index column twice.
|
|
158
|
+
const at = [...new Set(ids)].map(located);
|
|
159
|
+
const params = [at.map((table) => table.schema), at.map((table) => table.name)];
|
|
160
|
+
const tables = `SELECT c.oid, n.nspname::pg_catalog.text OPERATOR(pg_catalog.||) '.' OPERATOR(pg_catalog.||) c.relname::pg_catalog.text AS id
|
|
161
|
+
FROM ${WANTED}`;
|
|
162
|
+
const columns = await client.query(`WITH t AS (${tables})
|
|
163
|
+
SELECT t.id, a.attname::pg_catalog.text AS name, b.type::pg_catalog.int4 AS type, b.typmod::pg_catalog.int4 AS typmod,
|
|
164
|
+
pg_catalog.format_type(b.type, b.typmod) AS said, a.attcollation::pg_catalog.int4 AS collation,
|
|
165
|
+
coalesce(ln.nspname::pg_catalog.text, '') AS collschema, coalesce(l.collname::pg_catalog.text, '') AS collname,
|
|
166
|
+
coalesce((pg_catalog.to_jsonb(l) OPERATOR(pg_catalog.->>) 'collisdeterministic')::pg_catalog.bool, true) AS exact,
|
|
167
|
+
${postgresKeyType('b.type')} AS keyable, ${saidType('a.atttypid', 'a.atttypmod', 'b.type', 'b.typmod')} AS declared
|
|
168
|
+
FROM t JOIN pg_catalog.pg_attribute a ON a.attrelid ${EQ} t.oid AND a.attnum ${GT} 0 AND NOT a.attisdropped
|
|
169
|
+
CROSS JOIN LATERAL ${baseType('a.atttypid', 'a.atttypmod')} AS b
|
|
170
|
+
LEFT JOIN pg_catalog.pg_collation l ON l.oid ${EQ} a.attcollation
|
|
171
|
+
LEFT JOIN pg_catalog.pg_namespace ln ON ln.oid ${EQ} l.collnamespace`, params);
|
|
172
|
+
const keys = await client.query(`WITH t AS (${tables})
|
|
173
|
+
SELECT t.id, pg_catalog.array_agg(a.attname::pg_catalog.text ORDER BY k.ord) AS columns,
|
|
174
|
+
pg_catalog.bool_and(k.coll ${EQ} a.attcollation AND k.opclass ${EQ} ${defaultBtreeClass('b.type')}) AS own
|
|
175
|
+
FROM t
|
|
176
|
+
JOIN pg_catalog.pg_index i ON i.indrelid ${EQ} t.oid
|
|
177
|
+
JOIN pg_catalog.pg_class ic ON ic.oid ${EQ} i.indexrelid
|
|
178
|
+
CROSS JOIN LATERAL ROWS FROM (pg_catalog.unnest(i.indkey::pg_catalog.int2[]), pg_catalog.unnest(i.indcollation::pg_catalog.oid[]), pg_catalog.unnest(i.indclass::pg_catalog.oid[]))
|
|
179
|
+
WITH ORDINALITY AS k(attnum, coll, opclass, ord)
|
|
180
|
+
JOIN pg_catalog.pg_attribute a ON a.attrelid ${EQ} t.oid AND a.attnum ${EQ} k.attnum
|
|
181
|
+
CROSS JOIN LATERAL ${baseType('a.atttypid', 'a.atttypmod')} AS b
|
|
182
|
+
WHERE i.indisunique AND i.indisvalid AND i.indimmediate AND i.indpred IS NULL AND i.indexprs IS NULL
|
|
183
|
+
AND i.indnatts ${EQ} i.indnkeyatts AND ic.relam ${EQ} 403::pg_catalog.oid
|
|
184
|
+
GROUP BY t.id, i.indexrelid
|
|
185
|
+
HAVING pg_catalog.count(*) ${EQ} pg_catalog.max(i.indnkeyatts)`, params);
|
|
186
|
+
const compared = new Map();
|
|
187
|
+
for (const row of columns.rows) {
|
|
188
|
+
if (typeof row.id !== 'string' ||
|
|
189
|
+
typeof row.name !== 'string' ||
|
|
190
|
+
typeof row.said !== 'string' ||
|
|
191
|
+
typeof row.exact !== 'boolean' ||
|
|
192
|
+
typeof row.keyable !== 'boolean' ||
|
|
193
|
+
typeof row.declared !== 'string')
|
|
194
|
+
return refuse();
|
|
195
|
+
compared.set(`${row.id}\u0000${row.name}`, {
|
|
196
|
+
type: `${String(row.type)}:${String(row.typmod)}`,
|
|
197
|
+
collation: String(row.collation),
|
|
198
|
+
exact: row.exact,
|
|
199
|
+
keyable: row.keyable,
|
|
200
|
+
declared: row.declared,
|
|
201
|
+
// Named with its schema: two collations of one name in two schemas are two collations (an ICU "sv" and a libc one).
|
|
202
|
+
said: `${row.said}${row.collname ? ` COLLATE ${POSTGRES_STYLE.quote(String(row.collschema))}.${POSTGRES_STYLE.quote(String(row.collname))}` : ''}`,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
const unique = new Map();
|
|
206
|
+
for (const row of keys.rows) {
|
|
207
|
+
if (typeof row.id !== 'string' || !Array.isArray(row.columns) || row.columns.some((name) => typeof name !== 'string'))
|
|
208
|
+
return refuse();
|
|
209
|
+
if (row.own === true)
|
|
210
|
+
unique.set(row.id, [...(unique.get(row.id) ?? []), row.columns]);
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
keys: (table) => unique.get(table.id) ?? [],
|
|
214
|
+
comparison: (table, column) => compared.get(`${table.id}\u0000${column}`),
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
/** A type as `ri_triggers.c` casts to it: its schema and name, each quoted where it needs it. */
|
|
218
|
+
const castType = (oid) => `(SELECT pg_catalog.quote_ident(tn.nspname::pg_catalog.text) OPERATOR(pg_catalog.||) '.'
|
|
219
|
+
OPERATOR(pg_catalog.||) pg_catalog.quote_ident(t.typname::pg_catalog.text)
|
|
220
|
+
FROM pg_catalog.pg_type t JOIN pg_catalog.pg_namespace tn ON tn.oid ${EQ} t.typnamespace WHERE t.oid ${EQ} ${oid})`;
|
|
221
|
+
/* Whether a type is a pseudo-type: a polymorphic operator's input (an enum's `anyenum`), which a side is not cast to.
|
|
222
|
+
The operator resolves it from the side's own type. */
|
|
223
|
+
const pseudo = (oid) => `EXISTS (SELECT FROM pg_catalog.pg_type pt WHERE pt.oid ${EQ} ${oid} AND pt.typtype ${EQ} 'p')`;
|
|
224
|
+
const CONCAT = 'OPERATOR(pg_catalog.||)';
|
|
225
|
+
/**
|
|
226
|
+
* A column's type as a cast names it whatever the search_path: its schema and name from pg_type, each quoted where it
|
|
227
|
+
* needs it (castType), then its modifier as the digits the type's own input reads back — `pg_catalog."numeric"(10,2)`,
|
|
228
|
+
* `pg_catalog.bpchar(3)`. `format_type` said `text` and `character(3)`: a name found through the search_path when the
|
|
229
|
+
* statement runs, which a type made after the catalog was read (a domain `public.text` over `name`, with pg_catalog
|
|
230
|
+
* after public) answered, and a check that read 64 characters as 63 found another key than the foreign key. The
|
|
231
|
+
* modifier is what `format_type` adds to the type's bare name, a parenthesised list for every type a reference may be
|
|
232
|
+
* that has one (varchar, char, numeric: keyTypes.ts). NULL where it is not: a type a check cannot name.
|
|
233
|
+
*/
|
|
234
|
+
const sqlType = (oid, typmod) => `(SELECT CASE WHEN m.said IS NOT NULL THEN
|
|
235
|
+
pg_catalog.quote_ident(tn.nspname::pg_catalog.text) ${CONCAT} '.' ${CONCAT} pg_catalog.quote_ident(t.typname::pg_catalog.text) ${CONCAT} m.said END
|
|
236
|
+
FROM pg_catalog.pg_type t JOIN pg_catalog.pg_namespace tn ON tn.oid ${EQ} t.typnamespace
|
|
237
|
+
CROSS JOIN LATERAL (SELECT CASE
|
|
238
|
+
WHEN ${typmod} ${LT} 0 THEN ''
|
|
239
|
+
WHEN pg_catalog.left(pg_catalog.format_type(t.oid, ${typmod}), pg_catalog.length(pg_catalog.format_type(t.oid, NULL)))
|
|
240
|
+
${EQ} pg_catalog.format_type(t.oid, NULL)
|
|
241
|
+
THEN pg_catalog.substr(pg_catalog.format_type(t.oid, ${typmod}), pg_catalog.length(pg_catalog.format_type(t.oid, NULL)) ${PLUS} 1)
|
|
242
|
+
END AS said) AS m
|
|
243
|
+
WHERE t.oid ${EQ} ${oid})`;
|
|
244
|
+
/**
|
|
245
|
+
* How each foreign key of `schema` compares a reference with its parent's key (ScopeCatalog.references), as the
|
|
246
|
+
* database's own check states it (ri_triggers.c RI_FKey_check, ruleutils.c generate_operator_clause): the parent
|
|
247
|
+
* column, cast to the operator's left type where its own is another, then `OPERATOR(schema.name)` of the constraint's
|
|
248
|
+
* own equality (`conpfeqop`), then the value read as the referencing column's type, typmod and all and named by its
|
|
249
|
+
* schema (sqlType), and cast to the operator's right type where that is another. Neither side is cast to a
|
|
250
|
+
* pseudo-type (`pseudo`): an enum's `anyenum` is resolved from the side's own type. A parent check written so finds the
|
|
251
|
+
* row the foreign key finds: by `=` and the value as given, a char(3) 'ab ' found the text key 'ab ', where the foreign
|
|
252
|
+
* key, comparing as text, finds 'ab'. A key whose columns or operators the catalog does not give whole, either side of
|
|
253
|
+
* which is of a type a key may not be (keyTypes.ts), or whose type a cast cannot name, is refused to a scoped write
|
|
254
|
+
* through it.
|
|
255
|
+
*/
|
|
256
|
+
async function foreignKeyComparisons(client, schema) {
|
|
257
|
+
const at = schema.tables.map((table) => ({ schema: table.schema, name: table.name }));
|
|
258
|
+
const result = await client.query(`SELECT n.nspname::pg_catalog.text AS schema, c.relname::pg_catalog.text AS "table", con.conname::pg_catalog.text AS name,
|
|
259
|
+
k.ord::pg_catalog.int4 AS ord, fa.attname::pg_catalog.text AS child, pa.attname::pg_catalog.text AS parent,
|
|
260
|
+
${sqlType('fa.atttypid', 'fa.atttypmod')} AS type, ${writtenType('fa.atttypid', 'fa.atttypmod')} AS written,
|
|
261
|
+
${postgresKeyType('fb.type')} AS child_keyable, ${saidType('fa.atttypid', 'fa.atttypmod', 'fb.type', 'fb.typmod')} AS child_said,
|
|
262
|
+
${postgresKeyType('pb.type')} AS parent_keyable, ${saidType('pa.atttypid', 'pa.atttypmod', 'pb.type', 'pb.typmod')} AS parent_said,
|
|
263
|
+
pg_catalog.quote_ident(opn.nspname::pg_catalog.text) OPERATOR(pg_catalog.||) '.' OPERATOR(pg_catalog.||) o.oprname::pg_catalog.text AS operator,
|
|
264
|
+
CASE WHEN pa.atttypid ${EQ} o.oprleft OR ${pseudo('o.oprleft')} THEN NULL ELSE ${castType('o.oprleft')} END AS "left",
|
|
265
|
+
CASE WHEN fa.atttypid ${EQ} o.oprright OR ${pseudo('o.oprright')} THEN NULL ELSE ${castType('o.oprright')} END AS "right"
|
|
266
|
+
FROM ${WANTED}
|
|
267
|
+
-- Never a clone that points at a partition, as the schema reads them (postgresCatalog.ts).
|
|
268
|
+
JOIN pg_catalog.pg_constraint con ON con.conrelid ${EQ} c.oid AND con.contype ${EQ} 'f'
|
|
269
|
+
AND NOT EXISTS (SELECT FROM pg_catalog.pg_constraint pc WHERE pc.oid ${EQ} con.conparentid AND pc.confrelid ${NE} con.confrelid)
|
|
270
|
+
CROSS JOIN LATERAL ROWS FROM (pg_catalog.unnest(con.conkey), pg_catalog.unnest(con.confkey), pg_catalog.unnest(con.conpfeqop))
|
|
271
|
+
WITH ORDINALITY AS k(child, parent, operator, ord)
|
|
272
|
+
LEFT JOIN pg_catalog.pg_attribute fa ON fa.attrelid ${EQ} con.conrelid AND fa.attnum ${EQ} k.child
|
|
273
|
+
LEFT JOIN pg_catalog.pg_attribute pa ON pa.attrelid ${EQ} con.confrelid AND pa.attnum ${EQ} k.parent
|
|
274
|
+
LEFT JOIN LATERAL ${baseType('fa.atttypid', 'fa.atttypmod')} AS fb ON true
|
|
275
|
+
LEFT JOIN LATERAL ${baseType('pa.atttypid', 'pa.atttypmod')} AS pb ON true
|
|
276
|
+
LEFT JOIN pg_catalog.pg_operator o ON o.oid ${EQ} k.operator
|
|
277
|
+
LEFT JOIN pg_catalog.pg_namespace opn ON opn.oid ${EQ} o.oprnamespace
|
|
278
|
+
ORDER BY 1, 2, 3, 4`, [at.map((table) => table.schema), at.map((table) => table.name)]);
|
|
279
|
+
const read = new Map();
|
|
280
|
+
for (const row of result.rows) {
|
|
281
|
+
const id = `${String(row.schema)}.${String(row.table)}\u0000${String(row.name)}`;
|
|
282
|
+
read.set(id, [...(read.get(id) ?? []), row]);
|
|
283
|
+
}
|
|
284
|
+
const comparisons = new Map();
|
|
285
|
+
for (const fk of schema.foreignKeys) {
|
|
286
|
+
const rows = read.get(`${fk.from.table}\u0000${fk.name}`) ?? [];
|
|
287
|
+
const whole = rows.length === fk.from.columns.length &&
|
|
288
|
+
rows.every((row, index) => row.ord === index + 1 &&
|
|
289
|
+
row.child === fk.from.columns[index] &&
|
|
290
|
+
row.parent === fk.to.columns[index] &&
|
|
291
|
+
(row.type === null || typeof row.type === 'string') &&
|
|
292
|
+
typeof row.written === 'string' &&
|
|
293
|
+
typeof row.child_keyable === 'boolean' &&
|
|
294
|
+
typeof row.parent_keyable === 'boolean' &&
|
|
295
|
+
typeof row.child_said === 'string' &&
|
|
296
|
+
typeof row.parent_said === 'string' &&
|
|
297
|
+
typeof row.operator === 'string' &&
|
|
298
|
+
(row.left === null || typeof row.left === 'string') &&
|
|
299
|
+
(row.right === null || typeof row.right === 'string'));
|
|
300
|
+
const unnamed = rows.findIndex((row) => row.type === null);
|
|
301
|
+
// Each side a row's identity (keyTypes.ts): the key pointed at, then the reference.
|
|
302
|
+
const parent = rows.findIndex((row) => row.parent_keyable !== true);
|
|
303
|
+
const child = rows.findIndex((row) => row.child_keyable !== true);
|
|
304
|
+
comparisons.set(referenceKey(fk), !whole
|
|
305
|
+
? {
|
|
306
|
+
refused: `"${fk.from.table}".${fk.from.columns.join('+')} has a foreign key ("${fk.name}") whose comparison the catalog does not give whole, so a parent it points at cannot be checked as it compares.`,
|
|
307
|
+
}
|
|
308
|
+
: parent !== -1
|
|
309
|
+
? { refused: `${keyTypeRefusal('postgres', fk.to.table, fk.to.columns[parent], rows[parent].parent_said)}.` }
|
|
310
|
+
: child !== -1
|
|
311
|
+
? { refused: `${keyTypeRefusal('postgres', fk.from.table, fk.from.columns[child], rows[child].child_said)}.` }
|
|
312
|
+
: unnamed !== -1
|
|
313
|
+
? {
|
|
314
|
+
refused: `"${fk.from.table}".${fk.from.columns[unnamed]} is of a type whose modifier a check cannot write, which a scoped write does not support for a reference.`,
|
|
315
|
+
}
|
|
316
|
+
: {
|
|
317
|
+
columns: rows.map((row) => ({
|
|
318
|
+
// Coerced as the write coerces it (postgresCatalog.ts writtenType): a domain read as the type it is over.
|
|
319
|
+
type: row.written,
|
|
320
|
+
equality: {
|
|
321
|
+
operator: row.operator,
|
|
322
|
+
type: row.type,
|
|
323
|
+
...(typeof row.left === 'string' ? { left: row.left } : {}),
|
|
324
|
+
...(typeof row.right === 'string' ? { right: row.right } : {}),
|
|
325
|
+
},
|
|
326
|
+
})),
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
return comparisons;
|
|
330
|
+
}
|
|
331
|
+
/** What blocks a scoped write to a table beyond its triggers, as a refusal names it; undefined where nothing does. */
|
|
332
|
+
const blockerOf = (fact) => !['r', 'p'].includes(fact.kind)
|
|
333
|
+
? 'a kind a scoped write cannot target'
|
|
334
|
+
: !fact.updatable
|
|
335
|
+
? 'no UPDATE privilege for the role that writes'
|
|
336
|
+
: fact.rls || fact.rules || fact.policies
|
|
337
|
+
? [fact.rules ? 'a rule' : '', fact.policies || fact.rls ? 'row-level security' : ''].filter(Boolean).join(' and ')
|
|
338
|
+
: undefined;
|
|
339
|
+
/**
|
|
340
|
+
* For `mistri check`: what a write's own catalog reads about `ids` to judge a trigger's effects
|
|
341
|
+
* (readPostgresScopeCatalog), read on `client` outside a write: the keys, the tables in a partition or inheritance
|
|
342
|
+
* hierarchy, and the tables a scoped write cannot target for row security, a rule, or the role's privileges.
|
|
343
|
+
*/
|
|
344
|
+
export async function effectCatalogFacts(client, given) {
|
|
345
|
+
const ids = [...new Set(given)];
|
|
346
|
+
const read = await facts(client, ids.map(located));
|
|
347
|
+
const blocked = new Map();
|
|
348
|
+
const hierarchy = new Set();
|
|
349
|
+
for (const id of ids) {
|
|
350
|
+
const fact = read.get(key(located(id)));
|
|
351
|
+
if (fact?.hierarchy)
|
|
352
|
+
hierarchy.add(id);
|
|
353
|
+
const blocker = fact && blockerOf(fact);
|
|
354
|
+
if (blocker)
|
|
355
|
+
blocked.set(id, blocker);
|
|
356
|
+
}
|
|
357
|
+
return { ...(await effectKeyFacts(client, ids)), hierarchy, blocked };
|
|
358
|
+
}
|
|
359
|
+
/** What makes a table unclean, as a refusal names it. */
|
|
360
|
+
const unclean = (fact) => [fact.triggers ? triggerNames(fact.trigger_names) : '', fact.rules ? 'a rule' : '', fact.policies || fact.rls ? 'row-level security' : '']
|
|
361
|
+
.filter(Boolean)
|
|
362
|
+
.join(' and ');
|
|
363
|
+
/** Call only on the leased writer inside its transaction, before any read of
|
|
364
|
+
* user data. The describe callback is the adapter's own introspection so the
|
|
365
|
+
* evidence has the same shape as the catalog the permissions were bound to. */
|
|
366
|
+
export async function readPostgresScopeCatalog(client, scope, describe) {
|
|
367
|
+
try {
|
|
368
|
+
const wanted = Object.keys(scope).map(located);
|
|
369
|
+
const before = await facts(client, wanted);
|
|
370
|
+
const pinned = wanted.filter((target) => lockable(before.get(key(target))));
|
|
371
|
+
const relations = pinned.map((target) => `${POSTGRES_STYLE.quote(target.schema)}.${POSTGRES_STYLE.quote(target.name)}`);
|
|
372
|
+
if (pinned.length)
|
|
373
|
+
await client.query(`LOCK TABLE ${relations.join(', ')} IN ROW EXCLUSIVE MODE`);
|
|
374
|
+
const described = await describe(client);
|
|
375
|
+
const schema = captureScopeCatalog({ ...described, label: 'PostgreSQL scoped transaction', readAt: new Date().toISOString() });
|
|
376
|
+
const after = facts(client, schema.tables.map((table) => ({ schema: table.schema, name: table.name })));
|
|
377
|
+
const held = new Set(pinned.map(key));
|
|
378
|
+
const writable = new Set();
|
|
379
|
+
const blockedBy = new Map();
|
|
380
|
+
const unkeyed = new Map();
|
|
381
|
+
const hierarchy = new Set();
|
|
382
|
+
const locks = new Set();
|
|
383
|
+
const withTriggers = [];
|
|
384
|
+
for (const table of schema.tables) {
|
|
385
|
+
const fact = (await after).get(key(table));
|
|
386
|
+
// A relation the catalog listed a moment ago and cannot describe now
|
|
387
|
+
// was dropped under this transaction; nothing here may rely on it.
|
|
388
|
+
if (!fact || table.id !== key(table))
|
|
389
|
+
return refuse();
|
|
390
|
+
if (fact.unkeyed_column !== null)
|
|
391
|
+
unkeyed.set(table.id, keyTypeRefusal('postgres', table.id, fact.unkeyed_column, fact.unkeyed_type ?? 'unknown'));
|
|
392
|
+
// Never a target, but still lockable: a reference to a partitioned table holds its parent row through it.
|
|
393
|
+
if (fact.hierarchy)
|
|
394
|
+
hierarchy.add(table.id);
|
|
395
|
+
if (!lockable(fact))
|
|
396
|
+
continue;
|
|
397
|
+
locks.add(table.id);
|
|
398
|
+
if (fact.hierarchy)
|
|
399
|
+
continue;
|
|
400
|
+
// Writable means pinned: a table that became clean after the pin
|
|
401
|
+
// decision could be dirtied again before COMMIT, so it stays read-only.
|
|
402
|
+
const ordinary = held.has(table.id) && !table.isView && table.columns.some((column) => column.primaryKey);
|
|
403
|
+
if (ordinary && clean(fact))
|
|
404
|
+
writable.add(table.id);
|
|
405
|
+
else if (ordinary && cleanButTriggers(fact))
|
|
406
|
+
withTriggers.push({ id: table.id, schema: table.schema, name: table.name });
|
|
407
|
+
else if (!clean(fact))
|
|
408
|
+
blockedBy.set(table.id, unclean(fact));
|
|
409
|
+
}
|
|
410
|
+
/* Read only where a table has triggers: a database without them asks nothing more than it did. */
|
|
411
|
+
const read = withTriggers.length ? await readTriggers(client, withTriggers) : undefined;
|
|
412
|
+
const readTriggered = new Map([...(read ?? [])].map(([id, entry]) => [id, entry.triggers]));
|
|
413
|
+
const triggerVersions = new Map([...(read ?? [])].map(([id, entry]) => [id, entry.version]));
|
|
414
|
+
/* What else a write to a writable table runs — a default, a CHECK, a domain — judged as a trigger that is not
|
|
415
|
+
validation-only where it calls a function of the database's: a table with such code is written only by the
|
|
416
|
+
writes that run none of it. Read before the effects are judged, so a trigger's write to such a table is
|
|
417
|
+
refused as the person's own would be. */
|
|
418
|
+
const written = schema.tables.filter((table) => writable.has(table.id) || readTriggered.has(table.id));
|
|
419
|
+
const code = await readPostgresTableCode(client, written);
|
|
420
|
+
for (const table of written) {
|
|
421
|
+
const own = code.get(key(table));
|
|
422
|
+
if (!own)
|
|
423
|
+
continue;
|
|
424
|
+
writable.delete(table.id);
|
|
425
|
+
readTriggered.set(table.id, [...(readTriggered.get(table.id) ?? []), ...own]);
|
|
426
|
+
}
|
|
427
|
+
// Keyed effects are judged against the catalog they run in (triggerEffects.ts); a database without them asks nothing more.
|
|
428
|
+
const triggered = [...readTriggered.values()].some((triggers) => triggers.some((trigger) => trigger.effects))
|
|
429
|
+
? (await import('./triggerEffects.js')).resolveTriggerEffects({
|
|
430
|
+
schema,
|
|
431
|
+
writable,
|
|
432
|
+
triggered: readTriggered,
|
|
433
|
+
foldCase: false,
|
|
434
|
+
hierarchy,
|
|
435
|
+
...(await effectKeyFacts(client, [...writable, ...readTriggered.keys()])),
|
|
436
|
+
})
|
|
437
|
+
: readTriggered;
|
|
438
|
+
return {
|
|
439
|
+
schema,
|
|
440
|
+
writable,
|
|
441
|
+
references: await foreignKeyComparisons(client, schema),
|
|
442
|
+
...(blockedBy.size ? { blockedBy } : {}),
|
|
443
|
+
...(unkeyed.size ? { unkeyed } : {}),
|
|
444
|
+
...(hierarchy.size ? { hierarchy } : {}),
|
|
445
|
+
...(triggered.size ? { triggered, triggerVersions } : {}),
|
|
446
|
+
lockable: locks,
|
|
447
|
+
pinned: relations,
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
catch (error) {
|
|
451
|
+
if (error instanceof Refusal)
|
|
452
|
+
throw error;
|
|
453
|
+
// A lock the role may not take, a vanished relation or unknown metadata
|
|
454
|
+
// cannot weaken the boundary; the failure aborts the transaction anyway.
|
|
455
|
+
return refuse();
|
|
456
|
+
}
|
|
457
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { PgQuery } from '../postgresPool.js';
|
|
2
|
+
import { type ScopeTrigger } from './scopeTriggers.js';
|
|
3
|
+
export declare const CATALOG_OPERATORS: {
|
|
4
|
+
readonly EQ: "OPERATOR(pg_catalog.=)";
|
|
5
|
+
readonly NE: "OPERATOR(pg_catalog.<>)";
|
|
6
|
+
readonly LT: "OPERATOR(pg_catalog.<)";
|
|
7
|
+
readonly GT: "OPERATOR(pg_catalog.>)";
|
|
8
|
+
readonly PLUS: "OPERATOR(pg_catalog.+)";
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* A type with its domains unwrapped, and the type modifier of the last one that has one (a domain over varchar(3)
|
|
12
|
+
* compares as varchar(3)), as a subquery of `(type, typmod)` over the type and modifier expressions given.
|
|
13
|
+
*/
|
|
14
|
+
export declare const baseType: (type: string, typmod: string) => string;
|
|
15
|
+
/**
|
|
16
|
+
* The default B-tree operator class of a (base) type, as a scalar subquery: its own, or the one class a binary cast
|
|
17
|
+
* from it (varchar to text), an enum or an array reaches; NULL where there is none or more than one. What an index
|
|
18
|
+
* of the type is built with unless it says otherwise, and so what its equality means.
|
|
19
|
+
*/
|
|
20
|
+
export declare const defaultBtreeClass: (type: string) => string;
|
|
21
|
+
/** One row of {@link postgresTriggerStatement}. */
|
|
22
|
+
export interface PostgresTriggerRow {
|
|
23
|
+
schema: string;
|
|
24
|
+
table: string;
|
|
25
|
+
/** The trigger's own relation, quoted for SQL: where its conditions are parsed. */
|
|
26
|
+
relation: string;
|
|
27
|
+
name: string;
|
|
28
|
+
type: number;
|
|
29
|
+
columns: string[];
|
|
30
|
+
listed: number;
|
|
31
|
+
generated: boolean;
|
|
32
|
+
constraint: boolean;
|
|
33
|
+
transition: boolean;
|
|
34
|
+
qual: string;
|
|
35
|
+
language: string;
|
|
36
|
+
kind: string;
|
|
37
|
+
definer: boolean;
|
|
38
|
+
configured: boolean;
|
|
39
|
+
arguments: number;
|
|
40
|
+
source: string;
|
|
41
|
+
version: string;
|
|
42
|
+
around: string;
|
|
43
|
+
}
|
|
44
|
+
/** The names of the triggers a write to `root` (an oid expression) may fire, sorted: what the scope catalog's facts count. */
|
|
45
|
+
export declare const postgresTreeTriggerNames: (root: string) => string;
|
|
46
|
+
/**
|
|
47
|
+
* Every user trigger a write to a table may fire, with what the proof reads: the table's own and each of its
|
|
48
|
+
* partitions' and children's, keyed by the table written. `wanted` reads those of the tables named by `$1`
|
|
49
|
+
* (schemas) and `$2` (names); otherwise every ordinary or partitioned table outside the system's schemas, with no
|
|
50
|
+
* parameters (for `mistri check`).
|
|
51
|
+
*/
|
|
52
|
+
export declare function postgresTriggerStatement(wanted: boolean): string;
|
|
53
|
+
/** What a stored tree (`pg_node_tree` as text) holds, read as PostgreSQL's own reader reads it (nodes/read.c). */
|
|
54
|
+
interface PostgresTree {
|
|
55
|
+
nodes: ReadonlyMap<string, number>;
|
|
56
|
+
functions: ReadonlySet<number>;
|
|
57
|
+
operators: ReadonlySet<number>;
|
|
58
|
+
/** Each OPEXPR's operator, in the order the tree holds them: a key's equalities, one each, in the order parsed. */
|
|
59
|
+
opexprs: readonly number[];
|
|
60
|
+
/** The domains it coerces to (CoerceToDomain), whose constraints run when it does. */
|
|
61
|
+
domains: ReadonlySet<number>;
|
|
62
|
+
/** The types of its constants: what a literal in its place is read as. */
|
|
63
|
+
constants: ReadonlySet<number>;
|
|
64
|
+
}
|
|
65
|
+
/** A stored tree, read structurally: every node, and the functions and operators it names. Undefined when it is not one this reader knows. */
|
|
66
|
+
export declare function readPostgresTree(text: string): PostgresTree | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* Whether a trigger function's body is in the grammar, and if it is, its
|
|
69
|
+
* conditions, each as the SQL PostgreSQL is to parse in its place (a literal
|
|
70
|
+
* as NULL, TG_OP as a NULL text, NEW and OLD as the view's `"new"` and
|
|
71
|
+
* `"old"`). `returns` is what its RETURN may give back.
|
|
72
|
+
*/
|
|
73
|
+
export declare function plpgsqlConditions(source: string, returns: ReadonlySet<string>): readonly string[] | undefined;
|
|
74
|
+
/** What PostgreSQL said of one trigger's conditions (postgresTriggerAnalyzer). */
|
|
75
|
+
export interface PostgresConditions {
|
|
76
|
+
/** The stored tree of a view selecting them, every one in its place. */
|
|
77
|
+
tree: string;
|
|
78
|
+
/** Whether every one is a boolean, as PL/pgSQL's IF takes it without a cast. */
|
|
79
|
+
boolean: boolean;
|
|
80
|
+
/** The type of each value selected after them, when there are any (a keyed write's). */
|
|
81
|
+
types?: readonly number[];
|
|
82
|
+
}
|
|
83
|
+
/** A value a keyed write assigns, by its type, to `column` of `relation` (SQL, schema-qualified). */
|
|
84
|
+
export interface PostgresAssignment {
|
|
85
|
+
from: number;
|
|
86
|
+
relation: string;
|
|
87
|
+
column: string;
|
|
88
|
+
}
|
|
89
|
+
/** PostgreSQL, asked about triggers on the session that will fire them. */
|
|
90
|
+
export interface PostgresTriggerAnalyzer {
|
|
91
|
+
/** `conditions`, then `values`, parsed over `relation` as NEW and OLD; undefined when PostgreSQL would not parse them. */
|
|
92
|
+
conditions(relation: string, conditions: readonly string[], values?: readonly string[]): Promise<PostgresConditions | undefined>;
|
|
93
|
+
/**
|
|
94
|
+
* Of these functions and operators, each one not proven pure (`f<oid>` or `o<oid>`); of these types, each a literal
|
|
95
|
+
* of which is read through a domain's input, which runs the domain's checks (`t<oid>`); of these assignments, each
|
|
96
|
+
* one that would run a cast's function not proven pure, or reaches no column (`c<index>`); of these key
|
|
97
|
+
* equalities, each whose operator is not its column's own equality, or whose column is not there (`k<index>`).
|
|
98
|
+
*/
|
|
99
|
+
impure(functions: readonly number[], operators: readonly number[], types: readonly number[], assignments?: readonly PostgresAssignment[], keys?: readonly PostgresKeyOperator[]): Promise<ReadonlySet<string>>;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* One equality of a trigger's key as PostgreSQL resolved it: its operator, and the key column it compares. It
|
|
103
|
+
* must be the equality (strategy 3) of the default B-tree operator class of the column's type, unwrapped of its
|
|
104
|
+
* domains: the equality a unique index of the column is unique by, and the one the proof reads the row with.
|
|
105
|
+
*/
|
|
106
|
+
interface PostgresKeyOperator {
|
|
107
|
+
readonly operator: number;
|
|
108
|
+
readonly relation: string;
|
|
109
|
+
readonly column: string;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The analyzer on `client`, which must be inside a transaction that may write
|
|
113
|
+
* (a read-only one cannot make even a temporary view). Each parse is made and
|
|
114
|
+
* undone inside a savepoint, so the transaction is left as it was, and a
|
|
115
|
+
* condition PostgreSQL rejects only fails its own proof.
|
|
116
|
+
*/
|
|
117
|
+
export declare function postgresTriggerAnalyzer(client: PgQuery): PostgresTriggerAnalyzer;
|
|
118
|
+
/**
|
|
119
|
+
* Each table's triggers, keyed `schema.name`, from the statement's rows, and
|
|
120
|
+
* what each table's proof was read from. Throws on a row of an unknown shape.
|
|
121
|
+
*/
|
|
122
|
+
export declare function postgresTriggersByTable(rows: readonly unknown[], analyzer: PostgresTriggerAnalyzer | undefined): Promise<Map<string, {
|
|
123
|
+
triggers: ScopeTrigger[];
|
|
124
|
+
version: string;
|
|
125
|
+
}>>;
|
|
126
|
+
/** What each table's proof was read from, keyed `schema.name`, without proving anything again: what an attestation compares. */
|
|
127
|
+
export declare function postgresTriggerVersions(rows: readonly unknown[]): Map<string, string>;
|
|
128
|
+
/**
|
|
129
|
+
* The code each wanted table's writes may run that calls a function the
|
|
130
|
+
* database made, as the triggers a write is judged by (never validation-only),
|
|
131
|
+
* keyed `schema.name`. `client` answers on the writer.
|
|
132
|
+
*/
|
|
133
|
+
export declare function readPostgresTableCode(client: PgQuery, tables: ReadonlyArray<{
|
|
134
|
+
schema: string;
|
|
135
|
+
name: string;
|
|
136
|
+
}>): Promise<Map<string, ScopeTrigger[]>>;
|
|
137
|
+
export {};
|