@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,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a Postgres transaction sends behind its BEGIN, and the small
|
|
3
|
+
* statement builders that send and the transaction share. The ahead statements
|
|
4
|
+
* must be exactly the ones the transaction sends in its turn, so they are built
|
|
5
|
+
* here by the same rules (`plainStatement`, `scopedStatement`,
|
|
6
|
+
* `rowLockStatement`) that `postgres.ts` calls when it sends them; this file
|
|
7
|
+
* holds no other state than the per-handle lock bookkeeping below.
|
|
8
|
+
*/
|
|
9
|
+
import { type Filter, type QueryRequest, type SqlFragment } from './adapter.js';
|
|
10
|
+
import { type AheadReport } from './postgresTransactionHandle.js';
|
|
11
|
+
import { KeyRows } from './scoped/keyRows.js';
|
|
12
|
+
import type { PostgresScopeCatalog } from './scoped/postgresScopeCatalog.js';
|
|
13
|
+
import type { PgQuery } from './postgresPool.js';
|
|
14
|
+
import type { WriteAhead } from './writeAhead.js';
|
|
15
|
+
import type { RowScope } from '../shared/rowScope.js';
|
|
16
|
+
import type { DatabaseSchema, TableMeta } from '../shared/schema.js';
|
|
17
|
+
import type { PostgresTransactionJournal } from './storeHost.js';
|
|
18
|
+
import type { PostgresTransactionVerifier } from './postgres.js';
|
|
19
|
+
export declare const PLAIN_SCOPE: RowScope;
|
|
20
|
+
export declare const heldLocks: WeakMap<PgQuery, Map<string, () => void>>;
|
|
21
|
+
export declare const heldRows: WeakMap<PgQuery, Set<string>>;
|
|
22
|
+
export declare const lockKey: (text: string, values: readonly unknown[]) => string;
|
|
23
|
+
export declare function rowLockStatement(table: TableMeta, key: Readonly<Record<string, string | number>>): [string, unknown[]];
|
|
24
|
+
export declare function plainTable(table: string): {
|
|
25
|
+
schema: string;
|
|
26
|
+
name: string;
|
|
27
|
+
};
|
|
28
|
+
export declare const catalogId: (table: string) => string;
|
|
29
|
+
export declare function plainStatement(request: QueryRequest): SqlFragment | undefined;
|
|
30
|
+
/** A row lock as a scoped transaction keeps it: its table and the filter that names the row. */
|
|
31
|
+
export declare const rowLockKey: (table: TableMeta, filter: Filter) => string;
|
|
32
|
+
export declare function scopedStatement(schema: DatabaseSchema, within: RowScope, request: QueryRequest): SqlFragment | undefined;
|
|
33
|
+
export declare function reportWriteAhead(report: AheadReport | undefined, committed: boolean): void;
|
|
34
|
+
/** The statements openPlain sends behind the BEGIN; each exactly what the transaction sends in its turn (lockRecordNow, queryOn). */
|
|
35
|
+
export declare function sendPlainAhead(owner: object, write: PgQuery, schema: DatabaseSchema, keyRows: KeyRows, journal: PostgresTransactionJournal<unknown> | undefined, hint: WriteAhead): Promise<unknown>[];
|
|
36
|
+
/**
|
|
37
|
+
* The statements a scoped transaction opens with, sent behind its BEGIN
|
|
38
|
+
* (openWrite's `sent`), from what it was told (writeAhead.ts) and the scope
|
|
39
|
+
* catalog read last time: the verifier's own (its fence), the journal's
|
|
40
|
+
* receipt lookup, and for each target its row lock, its row read in full
|
|
41
|
+
* through the scope (kept to answer its reads by key, keyRows.ts), and,
|
|
42
|
+
* where the write is captured for history, the capture's own lock and read
|
|
43
|
+
* (historyWrites). Each is exactly the statement the transaction sends in
|
|
44
|
+
* its turn, built by the same rules; one it never sends is left, counted,
|
|
45
|
+
* and changes nothing. None where the client does not pipeline.
|
|
46
|
+
*/
|
|
47
|
+
export declare function sendWriteAhead(owner: object, write: PgQuery, scope: RowScope, peeked: PostgresScopeCatalog | undefined, keyRows: KeyRows, journal: PostgresTransactionJournal<unknown> | undefined, verify: PostgresTransactionVerifier | undefined, hint: WriteAhead | undefined, locked: Set<string>): Promise<unknown>[];
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a Postgres transaction sends behind its BEGIN, and the small
|
|
3
|
+
* statement builders that send and the transaction share. The ahead statements
|
|
4
|
+
* must be exactly the ones the transaction sends in its turn, so they are built
|
|
5
|
+
* here by the same rules (`plainStatement`, `scopedStatement`,
|
|
6
|
+
* `rowLockStatement`) that `postgres.ts` calls when it sends them; this file
|
|
7
|
+
* holds no other state than the per-handle lock bookkeeping below.
|
|
8
|
+
*/
|
|
9
|
+
import { POSTGRES_STYLE, buildWhere, clampLimit, clampOffset } from './adapter.js';
|
|
10
|
+
import { holdAhead, sendAhead, sendsAhead } from './postgresTransactionHandle.js';
|
|
11
|
+
import { createScopedReads } from './scoped/scopedReads.js';
|
|
12
|
+
import { KeyRows } from './scoped/keyRows.js';
|
|
13
|
+
import { isRuntimeRelation, qualified } from './postgresValues.js';
|
|
14
|
+
import { capturesWrites } from './writeCapture.js';
|
|
15
|
+
/* The row scope an unscoped transaction's kept rows are filed under (keyRows.ts): none, the same object every time. */
|
|
16
|
+
export const PLAIN_SCOPE = Object.freeze({});
|
|
17
|
+
/* The record locks a transaction took behind its BEGIN (openPlain), by statement, each with what marks it taken.
|
|
18
|
+
Only those: a lock taken later could be let go by a ROLLBACK TO SAVEPOINT, one taken at the opening cannot. */
|
|
19
|
+
export const heldLocks = new WeakMap();
|
|
20
|
+
/* Of those, the ones that found their row: it is the transaction's, unmoving, until it ends (openPlain's `widen`). */
|
|
21
|
+
export const heldRows = new WeakMap();
|
|
22
|
+
export const lockKey = (text, values) => JSON.stringify([text, values]);
|
|
23
|
+
/* lockRecordNow's statement for a row named by its whole primary key, and its values. */
|
|
24
|
+
export function rowLockStatement(table, key) {
|
|
25
|
+
const pk = table.columns.filter((column) => column.primaryKey).map((column) => column.name);
|
|
26
|
+
const where = buildWhere({ groups: [pk.map((column) => ({ column, op: '=', value: key[column] }))] }, POSTGRES_STYLE);
|
|
27
|
+
return [`SELECT ${pk.map(POSTGRES_STYLE.quote).join(', ')} FROM ${qualified(table)}${where.text} FOR UPDATE`, where.params];
|
|
28
|
+
}
|
|
29
|
+
/* A table's schema and name from the name a request gives it, as assertPostgresTable reads it. */
|
|
30
|
+
export function plainTable(table) {
|
|
31
|
+
const dot = table.indexOf('.');
|
|
32
|
+
return dot === -1 ? { schema: 'public', name: table } : { schema: table.slice(0, dot), name: table.slice(dot + 1) };
|
|
33
|
+
}
|
|
34
|
+
/* A table's catalog id from the name a request gives it: a bare name is in the public schema, as assertPostgresTable reads it. */
|
|
35
|
+
export const catalogId = (table) => (table.includes('.') ? table : `public.${table}`);
|
|
36
|
+
/* The statement queryOn sends for an unordered read, without sending it: the table as its id names it
|
|
37
|
+
(assertPostgresTable), the read bounded as every read is. */
|
|
38
|
+
export function plainStatement(request) {
|
|
39
|
+
if (request.orderBy?.length)
|
|
40
|
+
return undefined;
|
|
41
|
+
const at = plainTable(request.table);
|
|
42
|
+
const where = buildWhere(request.filter, POSTGRES_STYLE);
|
|
43
|
+
const cols = request.columns?.length ? request.columns.map((column) => POSTGRES_STYLE.quote(column)).join(', ') : '*';
|
|
44
|
+
const n = where.params.length;
|
|
45
|
+
return {
|
|
46
|
+
text: `SELECT ${cols} FROM ${qualified(at)}${where.text} LIMIT $${n + 1} OFFSET $${n + 2}`,
|
|
47
|
+
params: [...where.params, clampLimit(request.limit), clampOffset(request.offset)],
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/* A statement a scoped read would send, without sending it: createScopedReads
|
|
51
|
+
compiles before it executes, so the executor is reached synchronously and
|
|
52
|
+
says what it was handed. */
|
|
53
|
+
/** A row lock as a scoped transaction keeps it: its table and the filter that names the row. */
|
|
54
|
+
export const rowLockKey = (table, filter) => `${table.id}\u0000${JSON.stringify(filter)}`;
|
|
55
|
+
export function scopedStatement(schema, within, request) {
|
|
56
|
+
let said;
|
|
57
|
+
void createScopedReads(schema, within, POSTGRES_STYLE, async (sql) => {
|
|
58
|
+
said = sql;
|
|
59
|
+
return { columns: [], rows: [], ms: 0, sql };
|
|
60
|
+
})
|
|
61
|
+
.query(request)
|
|
62
|
+
.catch(() => { });
|
|
63
|
+
return said;
|
|
64
|
+
}
|
|
65
|
+
/* Statements sent ahead that a committed transaction never asked: a hint
|
|
66
|
+
that no longer says what the transaction does. Warned once per statement
|
|
67
|
+
outside production; a refused transaction stops early, and leaves some by
|
|
68
|
+
design. With MISTRI_AHEAD_REPORT set, every transaction's account is a line
|
|
69
|
+
on stderr (e2e/write-storm.spec.ts reads it). */
|
|
70
|
+
const warnedAhead = new Set();
|
|
71
|
+
export function reportWriteAhead(report, committed) {
|
|
72
|
+
if (!report || (!report.sent && !report.missed))
|
|
73
|
+
return;
|
|
74
|
+
const said = (key) => {
|
|
75
|
+
try {
|
|
76
|
+
return String(JSON.parse(key)[0]).slice(0, 160);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return key.slice(0, 160);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
if (process.env.MISTRI_AHEAD_REPORT)
|
|
83
|
+
process.stderr.write(`mistri-ahead ${JSON.stringify({ at: Date.now(), committed, sent: report.sent, taken: report.taken, answered: report.answered, missed: report.missed, left: report.left.map(said), redone: report.redone, asked: report.asked })}\n`);
|
|
84
|
+
if (!committed || process.env.NODE_ENV === 'production')
|
|
85
|
+
return;
|
|
86
|
+
for (const statement of report.left.map(said)) {
|
|
87
|
+
if (warnedAhead.has(statement))
|
|
88
|
+
continue;
|
|
89
|
+
warnedAhead.add(statement);
|
|
90
|
+
process.emitWarning(`A statement sent ahead was never asked by the transaction it was sent for: ${statement}`, 'MistriWriteAhead');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** The statements openPlain sends behind the BEGIN; each exactly what the transaction sends in its turn (lockRecordNow, queryOn). */
|
|
94
|
+
export function sendPlainAhead(owner, write, schema, keyRows, journal, hint) {
|
|
95
|
+
if (!sendsAhead(write))
|
|
96
|
+
return [];
|
|
97
|
+
const opening = [];
|
|
98
|
+
try {
|
|
99
|
+
if (hint.receipt !== undefined && journal?.ahead)
|
|
100
|
+
opening.push(...journal.ahead(hint.receipt));
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
/* Asked in its turn. */
|
|
104
|
+
}
|
|
105
|
+
const answers = sendAhead(write, opening);
|
|
106
|
+
for (const target of hint.targets) {
|
|
107
|
+
const table = schema.tables.find((candidate) => candidate.id === catalogId(target.table));
|
|
108
|
+
if (!table || table.isView || isRuntimeRelation(table.id))
|
|
109
|
+
continue;
|
|
110
|
+
const pk = table.columns.filter((column) => column.primaryKey).map((column) => column.name);
|
|
111
|
+
const key = target.key;
|
|
112
|
+
if (!pk.length ||
|
|
113
|
+
Object.keys(key).length !== pk.length ||
|
|
114
|
+
!pk.every((column) => Object.hasOwn(key, column) && (typeof key[column] === 'string' || typeof key[column] === 'number')))
|
|
115
|
+
continue;
|
|
116
|
+
const filter = { groups: [pk.map((column) => ({ column, op: '=', value: key[column] }))] };
|
|
117
|
+
if (!hint.readOnly && (hint.locks || (hint.writes && capturesWrites(owner, table.id)))) {
|
|
118
|
+
/* lockRecordNow's statement, where the transaction will send it (the save's own lock, the history capture's). Held rather than answered once: the row stays locked until the transaction ends,
|
|
119
|
+
so each later lock of it in this transaction (the command's, the history capture's) is answered by it, even
|
|
120
|
+
after a write to another record has moved the statement generation. */
|
|
121
|
+
const [text, values] = rowLockStatement(table, key);
|
|
122
|
+
const lock = holdAhead(write, { text, values });
|
|
123
|
+
if (lock) {
|
|
124
|
+
answers.push(lock.answer);
|
|
125
|
+
const locks = heldLocks.get(write) ?? new Map();
|
|
126
|
+
heldLocks.set(write, locks);
|
|
127
|
+
const rows = heldRows.get(write) ?? new Set();
|
|
128
|
+
heldRows.set(write, rows);
|
|
129
|
+
void lock.answer.then((result) => {
|
|
130
|
+
if (result.rows.length <= 1)
|
|
131
|
+
locks.set(lockKey(text, values), lock.take);
|
|
132
|
+
// Only a row that is there is held: one that is not could be inserted by another transaction meanwhile.
|
|
133
|
+
if (result.rows.length === 1)
|
|
134
|
+
rows.add(lockKey(text, values));
|
|
135
|
+
}, () => { });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const read = plainStatement({ table: table.id, filter, limit: 2, offset: 0 });
|
|
139
|
+
const row = read && holdAhead(write, { text: read.text, values: read.params });
|
|
140
|
+
if (row) {
|
|
141
|
+
answers.push(row.answer);
|
|
142
|
+
keyRows.keep(PLAIN_SCOPE, table, filter, row.answer.then((result) => result.rows), row.take);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return answers;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* The statements a scoped transaction opens with, sent behind its BEGIN
|
|
149
|
+
* (openWrite's `sent`), from what it was told (writeAhead.ts) and the scope
|
|
150
|
+
* catalog read last time: the verifier's own (its fence), the journal's
|
|
151
|
+
* receipt lookup, and for each target its row lock, its row read in full
|
|
152
|
+
* through the scope (kept to answer its reads by key, keyRows.ts), and,
|
|
153
|
+
* where the write is captured for history, the capture's own lock and read
|
|
154
|
+
* (historyWrites). Each is exactly the statement the transaction sends in
|
|
155
|
+
* its turn, built by the same rules; one it never sends is left, counted,
|
|
156
|
+
* and changes nothing. None where the client does not pipeline.
|
|
157
|
+
*/
|
|
158
|
+
export function sendWriteAhead(owner, write, scope, peeked, keyRows, journal, verify, hint, locked) {
|
|
159
|
+
if (!sendsAhead(write) || (!hint && !verify?.ahead))
|
|
160
|
+
return [];
|
|
161
|
+
const opening = [];
|
|
162
|
+
try {
|
|
163
|
+
opening.push(...(verify?.ahead?.() ?? []));
|
|
164
|
+
if (hint?.receipt !== undefined && journal?.ahead)
|
|
165
|
+
opening.push(...journal.ahead(hint.receipt));
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
/* Asked in its turn. */
|
|
169
|
+
}
|
|
170
|
+
const answers = sendAhead(write, opening);
|
|
171
|
+
for (const target of (peeked && hint?.targets) || []) {
|
|
172
|
+
const table = peeked.schema.tables.find((candidate) => candidate.id === catalogId(target.table));
|
|
173
|
+
if (!table || !peeked.lockable.has(table.id))
|
|
174
|
+
continue;
|
|
175
|
+
const pk = table.columns.filter((column) => column.primaryKey).map((column) => column.name);
|
|
176
|
+
const key = target.key;
|
|
177
|
+
if (!pk.length ||
|
|
178
|
+
Object.keys(key).length !== pk.length ||
|
|
179
|
+
!pk.every((column) => Object.hasOwn(key, column) && (typeof key[column] === 'string' || typeof key[column] === 'number')))
|
|
180
|
+
continue;
|
|
181
|
+
// The scoped transaction's own key filter and lock (scopedTransaction.ts keyFilter, `lock` above).
|
|
182
|
+
const filter = { groups: [pk.map((column) => ({ column, op: '=', value: key[column] }))] };
|
|
183
|
+
const where = buildWhere(filter, POSTGRES_STYLE);
|
|
184
|
+
if (!hint.readOnly) {
|
|
185
|
+
answers.push(...sendAhead(write, [{ text: `SELECT 1 FROM ${qualified(table)}${where.text} FOR UPDATE`, values: where.params }]));
|
|
186
|
+
locked.add(rowLockKey(table, filter));
|
|
187
|
+
}
|
|
188
|
+
// With its reference columns' stored text, as the scoped transaction reads its rows (storedText.ts).
|
|
189
|
+
const read = scopedStatement(peeked.schema, scope, { table: table.id, filter, limit: 2, offset: 0, storedText: true });
|
|
190
|
+
const row = read && holdAhead(write, { text: read.text, values: read.params });
|
|
191
|
+
if (row) {
|
|
192
|
+
answers.push(row.answer);
|
|
193
|
+
keyRows.keep(scope, table, filter, row.answer.then((result) => result.rows), row.take);
|
|
194
|
+
}
|
|
195
|
+
if (hint.writes && !hint.readOnly && capturesWrites(owner, table.id)) {
|
|
196
|
+
// historyWrites' read: lockRecordNow, then queryOn of the whole row by the key as given.
|
|
197
|
+
const given = buildWhere({ groups: [Object.entries(key).map(([column, value]) => ({ column, op: '=', value }))] }, POSTGRES_STYLE);
|
|
198
|
+
const n = given.params.length;
|
|
199
|
+
answers.push(...sendAhead(write, [
|
|
200
|
+
{
|
|
201
|
+
text: `SELECT ${pk.map(POSTGRES_STYLE.quote).join(', ')} FROM ${qualified(table)}${where.text} FOR UPDATE`,
|
|
202
|
+
values: where.params,
|
|
203
|
+
},
|
|
204
|
+
{ text: `SELECT * FROM ${qualified(table)}${given.text} LIMIT $${n + 1} OFFSET $${n + 2}`, values: [...given.params, 2, 0] },
|
|
205
|
+
]));
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return answers;
|
|
209
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/** How long a person's reads stay on the primary after they write: well past a healthy replica's lag. */
|
|
2
|
+
export declare const FRESH_READ_MS = 10000;
|
|
3
|
+
/** How long a replica that failed is passed over before it is tried again. */
|
|
4
|
+
export declare const REPLICA_BACKOFF_MS = 30000;
|
|
5
|
+
/** The most replicas one connection may name. Past this, a pooler or a load balancer is the tool. */
|
|
6
|
+
export declare const MAX_REPLICAS = 8;
|
|
7
|
+
/**
|
|
8
|
+
* Who the current work is for, as far as read-your-write cares. Set by the
|
|
9
|
+
* HTTP layer for the whole request, so a write anywhere in it and a read
|
|
10
|
+
* anywhere after it agree.
|
|
11
|
+
*/
|
|
12
|
+
export interface ReadContext {
|
|
13
|
+
/** The request arrived with a fresh write marker, or wrote since: its reads stay on the primary. */
|
|
14
|
+
fresh: boolean;
|
|
15
|
+
/** A caller with no cookie jar (a bearer token): its writes are remembered here, in this process, under this key. */
|
|
16
|
+
readonly key?: string;
|
|
17
|
+
/** Called on the request's first write: the HTTP layer sets the marker the browser carries back. */
|
|
18
|
+
readonly onWrite?: () => void;
|
|
19
|
+
}
|
|
20
|
+
/** Run `work` for `context`: its writes keep its later reads on the primary. */
|
|
21
|
+
export declare function readsAs<T>(context: ReadContext, work: () => T): T;
|
|
22
|
+
/** Run `work` with its reads allowed on a replica, unless something around it pinned the primary. */
|
|
23
|
+
export declare function lagTolerantReads<T>(work: () => T): T;
|
|
24
|
+
/** Run `work` with every read on the primary, whatever runs inside it. */
|
|
25
|
+
export declare function primaryReads<T>(work: () => T): T;
|
|
26
|
+
/** A write began for the current caller: its reads go to the primary for FRESH_READ_MS. Background work is nobody's. */
|
|
27
|
+
export declare function noteWrite(now?: number): void;
|
|
28
|
+
/** Whether a read starting now may go to a replica. */
|
|
29
|
+
export declare function replicaReadWanted(now?: number): boolean;
|
|
30
|
+
/** A replica read that must go to the primary instead, for a reason the replica's own error does not say. */
|
|
31
|
+
export declare class ReplicaUnavailable extends Error {
|
|
32
|
+
readonly failure: 'down' | 'retry';
|
|
33
|
+
constructor(failure: 'down' | 'retry', message: string, options?: {
|
|
34
|
+
cause?: unknown;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Why a replica's read failed, as far as routing cares:
|
|
39
|
+
* `down` — it could not be reached or lost its connection: pass it over and use the primary;
|
|
40
|
+
* `retry` — this read cannot be answered there now (its pool is full, it lags behind a
|
|
41
|
+
* migration, recovery cancelled it): use the primary, keep the replica;
|
|
42
|
+
* undefined — the primary would refuse it too, so the error is the answer.
|
|
43
|
+
*/
|
|
44
|
+
export declare function replicaFailure(error: unknown): 'down' | 'retry' | undefined;
|
|
45
|
+
/** One connection's replicas, taken in turn, each passed over for a while after it fails. */
|
|
46
|
+
export declare class ReplicaSet<Pool> {
|
|
47
|
+
readonly pools: readonly Pool[];
|
|
48
|
+
private readonly now;
|
|
49
|
+
private next;
|
|
50
|
+
private readonly downUntil;
|
|
51
|
+
/** Reads answered by each replica, and reads that fell back to the primary from it. */
|
|
52
|
+
readonly served: number[];
|
|
53
|
+
readonly fellBack: number[];
|
|
54
|
+
constructor(pools: readonly Pool[], now?: () => number);
|
|
55
|
+
/** The next replica that is not being passed over, or undefined when every one is. */
|
|
56
|
+
pick(): {
|
|
57
|
+
index: number;
|
|
58
|
+
pool: Pool;
|
|
59
|
+
} | undefined;
|
|
60
|
+
/** Pass replica `index` over for REPLICA_BACKOFF_MS. */
|
|
61
|
+
down(index: number): void;
|
|
62
|
+
/** Whether replica `index` is in use now (not being passed over). */
|
|
63
|
+
healthy(index: number): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Run one read: on a replica when the work wants one and one is in turn,
|
|
66
|
+
* else on the primary. A replica that cannot answer hands the read to the
|
|
67
|
+
* primary (replicaFailure); any other failure is the read's own.
|
|
68
|
+
*/
|
|
69
|
+
read<T>(onReplica: (pool: Pool) => Promise<T>, onPrimary: () => Promise<T>): Promise<T>;
|
|
70
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read replicas: which database a read goes to.
|
|
3
|
+
*
|
|
4
|
+
* A connection may name replicas (`"replicas": [url, …]` in its config). A
|
|
5
|
+
* read goes to one only when three things hold, and to the primary otherwise:
|
|
6
|
+
*
|
|
7
|
+
* - The work it runs in said it tolerates lag (`lagTolerantReads`): a list,
|
|
8
|
+
* a dashboard's breakdowns, a count, an export, the Workbench grid. The
|
|
9
|
+
* HTTP layer says so per route (packages/engine/src/server/http/readRouting.ts). Nothing
|
|
10
|
+
* else does, so a read nobody classified — a record page, a command, the
|
|
11
|
+
* catalog, a store — stays on the primary by default.
|
|
12
|
+
* - No enclosing work pinned the primary (`primaryReads`): a write's own
|
|
13
|
+
* reads, a record page composed from list reads, the catalog. A pin is not
|
|
14
|
+
* undone by a lag-tolerant route nested inside it.
|
|
15
|
+
* - Whoever is asking has not written in the last FRESH_READ_MS. A write
|
|
16
|
+
* sends that browser's reads to the primary for that long, so the list it
|
|
17
|
+
* returns to after a save shows the save. The marker travels with the
|
|
18
|
+
* browser, not the process (a short-lived cookie, readRouting.ts), so it
|
|
19
|
+
* holds across pods and two anonymous visitors never share one. A client
|
|
20
|
+
* without cookies — a bearer-token API or MCP caller — is keyed by its
|
|
21
|
+
* token in this process instead: per pod, which is a replica's lag and
|
|
22
|
+
* nothing worse.
|
|
23
|
+
*
|
|
24
|
+
* Replicas take turns. One that fails to connect, or loses its connection,
|
|
25
|
+
* is passed over for REPLICA_BACKOFF_MS and the read runs again on the
|
|
26
|
+
* primary; a read the primary would refuse as well (a bad filter, a
|
|
27
|
+
* cancel) is not run twice. Replica sessions are read-only the way the
|
|
28
|
+
* primary's readers are (postgresPool.ts), so a write that
|
|
29
|
+
* reached one by mistake would be refused by the server.
|
|
30
|
+
*/
|
|
31
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
32
|
+
import { currentSpan } from './telemetry/trace.js';
|
|
33
|
+
import { isPoolBusy } from './poolMetrics.js';
|
|
34
|
+
import { StatementStopped } from './statementControl.js';
|
|
35
|
+
import { inBackgroundWork } from './writeLanes.js';
|
|
36
|
+
/** How long a person's reads stay on the primary after they write: well past a healthy replica's lag. */
|
|
37
|
+
export const FRESH_READ_MS = 10_000;
|
|
38
|
+
/** How long a replica that failed is passed over before it is tried again. */
|
|
39
|
+
export const REPLICA_BACKOFF_MS = 30_000;
|
|
40
|
+
/** The most replicas one connection may name. Past this, a pooler or a load balancer is the tool. */
|
|
41
|
+
export const MAX_REPLICAS = 8;
|
|
42
|
+
const preference = new AsyncLocalStorage();
|
|
43
|
+
const reader = new AsyncLocalStorage();
|
|
44
|
+
/** Run `work` for `context`: its writes keep its later reads on the primary. */
|
|
45
|
+
export function readsAs(context, work) {
|
|
46
|
+
return reader.run(context, work);
|
|
47
|
+
}
|
|
48
|
+
/** Run `work` with its reads allowed on a replica, unless something around it pinned the primary. */
|
|
49
|
+
export function lagTolerantReads(work) {
|
|
50
|
+
return preference.getStore() === 'primary' ? work() : preference.run('replica', work);
|
|
51
|
+
}
|
|
52
|
+
/** Run `work` with every read on the primary, whatever runs inside it. */
|
|
53
|
+
export function primaryReads(work) {
|
|
54
|
+
return preference.getStore() === 'primary' ? work() : preference.run('primary', work);
|
|
55
|
+
}
|
|
56
|
+
/* Whether any connection in this process has replicas. Until one does, a
|
|
57
|
+
write sets no marker: a deployment without replicas sends no cookie. */
|
|
58
|
+
let replicasConfigured = false;
|
|
59
|
+
/* Last write per keyed caller, in this process. Pruned as it grows, so many
|
|
60
|
+
tokens cannot grow it without bound. */
|
|
61
|
+
const wrote = new Map();
|
|
62
|
+
const PRUNE_AT = 4_096;
|
|
63
|
+
/** A write began for the current caller: its reads go to the primary for FRESH_READ_MS. Background work is nobody's. */
|
|
64
|
+
export function noteWrite(now = Date.now()) {
|
|
65
|
+
if (!replicasConfigured || inBackgroundWork())
|
|
66
|
+
return;
|
|
67
|
+
const context = reader.getStore();
|
|
68
|
+
if (!context)
|
|
69
|
+
return;
|
|
70
|
+
if (!context.fresh) {
|
|
71
|
+
context.fresh = true;
|
|
72
|
+
context.onWrite?.();
|
|
73
|
+
}
|
|
74
|
+
if (context.key === undefined)
|
|
75
|
+
return;
|
|
76
|
+
wrote.delete(context.key);
|
|
77
|
+
wrote.set(context.key, now);
|
|
78
|
+
if (wrote.size > PRUNE_AT) {
|
|
79
|
+
for (const [key, at] of wrote) {
|
|
80
|
+
if (now - at < FRESH_READ_MS)
|
|
81
|
+
break;
|
|
82
|
+
wrote.delete(key);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** Whether a read starting now may go to a replica. */
|
|
87
|
+
export function replicaReadWanted(now = Date.now()) {
|
|
88
|
+
if (preference.getStore() !== 'replica')
|
|
89
|
+
return false;
|
|
90
|
+
const context = reader.getStore();
|
|
91
|
+
if (context?.fresh)
|
|
92
|
+
return false;
|
|
93
|
+
const at = context?.key === undefined ? undefined : wrote.get(context.key);
|
|
94
|
+
return at === undefined || now - at >= FRESH_READ_MS;
|
|
95
|
+
}
|
|
96
|
+
/** A replica read that must go to the primary instead, for a reason the replica's own error does not say. */
|
|
97
|
+
export class ReplicaUnavailable extends Error {
|
|
98
|
+
failure;
|
|
99
|
+
constructor(failure, message, options) {
|
|
100
|
+
super(message, options);
|
|
101
|
+
this.failure = failure;
|
|
102
|
+
this.name = 'ReplicaUnavailable';
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Why a replica's read failed, as far as routing cares:
|
|
107
|
+
* `down` — it could not be reached or lost its connection: pass it over and use the primary;
|
|
108
|
+
* `retry` — this read cannot be answered there now (its pool is full, it lags behind a
|
|
109
|
+
* migration, recovery cancelled it): use the primary, keep the replica;
|
|
110
|
+
* undefined — the primary would refuse it too, so the error is the answer.
|
|
111
|
+
*/
|
|
112
|
+
export function replicaFailure(error) {
|
|
113
|
+
if (error instanceof ReplicaUnavailable)
|
|
114
|
+
return error.failure;
|
|
115
|
+
if (error instanceof StatementStopped)
|
|
116
|
+
return undefined;
|
|
117
|
+
if (isPoolBusy(error))
|
|
118
|
+
return 'retry';
|
|
119
|
+
const e = (error ?? {});
|
|
120
|
+
const code = typeof e.code === 'string' ? e.code : '';
|
|
121
|
+
const message = typeof e.message === 'string' ? e.message : '';
|
|
122
|
+
if (NETWORK.has(code) || e.fatal === true)
|
|
123
|
+
return 'down';
|
|
124
|
+
/* PostgreSQL: connection exceptions (08), the server going away (57P01–03),
|
|
125
|
+
no room (53300), credentials (28) and a database missing (3D000) are the
|
|
126
|
+
replica's state, not the read's. */
|
|
127
|
+
if (/^(08|28)[0-9A-Z]{3}$/.test(code) || ['57P01', '57P02', '57P03', '53300', '3D000'].includes(code))
|
|
128
|
+
return 'down';
|
|
129
|
+
/* A standby cancels a read that conflicts with replay; a relation or column
|
|
130
|
+
missing on the replica is a migration that has not reached it yet. */
|
|
131
|
+
if (code === '40001' && /recovery/i.test(message))
|
|
132
|
+
return 'retry';
|
|
133
|
+
if (code === '42P01' || code === '42703')
|
|
134
|
+
return 'retry';
|
|
135
|
+
if (/Connection terminated|timeout exceeded when trying to connect|connect ECONNREFUSED/i.test(message))
|
|
136
|
+
return 'down';
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
const NETWORK = new Set(['ECONNREFUSED', 'ECONNRESET', 'ETIMEDOUT', 'ENOTFOUND', 'EHOSTUNREACH', 'ENETUNREACH', 'EPIPE', 'EAI_AGAIN']);
|
|
140
|
+
/** One connection's replicas, taken in turn, each passed over for a while after it fails. */
|
|
141
|
+
export class ReplicaSet {
|
|
142
|
+
pools;
|
|
143
|
+
now;
|
|
144
|
+
next = 0;
|
|
145
|
+
downUntil;
|
|
146
|
+
/** Reads answered by each replica, and reads that fell back to the primary from it. */
|
|
147
|
+
served;
|
|
148
|
+
fellBack;
|
|
149
|
+
constructor(pools, now = () => Date.now()) {
|
|
150
|
+
this.pools = pools;
|
|
151
|
+
this.now = now;
|
|
152
|
+
if (pools.length > 0)
|
|
153
|
+
replicasConfigured = true;
|
|
154
|
+
this.downUntil = pools.map(() => 0);
|
|
155
|
+
this.served = pools.map(() => 0);
|
|
156
|
+
this.fellBack = pools.map(() => 0);
|
|
157
|
+
}
|
|
158
|
+
/** The next replica that is not being passed over, or undefined when every one is. */
|
|
159
|
+
pick() {
|
|
160
|
+
const at = this.now();
|
|
161
|
+
for (let tried = 0; tried < this.pools.length; tried++) {
|
|
162
|
+
const index = (this.next + tried) % this.pools.length;
|
|
163
|
+
if (this.downUntil[index] <= at) {
|
|
164
|
+
this.next = (index + 1) % this.pools.length;
|
|
165
|
+
return { index, pool: this.pools[index] };
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
/** Pass replica `index` over for REPLICA_BACKOFF_MS. */
|
|
171
|
+
down(index) {
|
|
172
|
+
this.downUntil[index] = this.now() + REPLICA_BACKOFF_MS;
|
|
173
|
+
}
|
|
174
|
+
/** Whether replica `index` is in use now (not being passed over). */
|
|
175
|
+
healthy(index) {
|
|
176
|
+
return this.downUntil[index] <= this.now();
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Run one read: on a replica when the work wants one and one is in turn,
|
|
180
|
+
* else on the primary. A replica that cannot answer hands the read to the
|
|
181
|
+
* primary (replicaFailure); any other failure is the read's own.
|
|
182
|
+
*/
|
|
183
|
+
async read(onReplica, onPrimary) {
|
|
184
|
+
const chosen = replicaReadWanted() ? this.pick() : undefined;
|
|
185
|
+
const span = currentSpan();
|
|
186
|
+
if (!chosen) {
|
|
187
|
+
span?.setAttribute('mistri.read.pool', 'primary');
|
|
188
|
+
return onPrimary();
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
const out = await onReplica(chosen.pool);
|
|
192
|
+
this.served[chosen.index] += 1;
|
|
193
|
+
span?.setAttribute('mistri.read.pool', 'replica');
|
|
194
|
+
return out;
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
const failure = replicaFailure(error);
|
|
198
|
+
if (!failure)
|
|
199
|
+
throw error;
|
|
200
|
+
if (failure === 'down')
|
|
201
|
+
this.down(chosen.index);
|
|
202
|
+
this.fellBack[chosen.index] += 1;
|
|
203
|
+
span?.event('replica fallback', { 'mistri.replica': chosen.index + 1, 'mistri.replica.failure': failure });
|
|
204
|
+
span?.setAttribute('mistri.read.pool', 'primary');
|
|
205
|
+
return onPrimary();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { DatabaseSchema } from '../shared/schema.js';
|
|
2
|
+
import { Refusal } from './adapter.js';
|
|
3
|
+
import type { PgQuery } from './postgresPool.js';
|
|
4
|
+
type Dialect = DatabaseSchema['dialect'];
|
|
5
|
+
export declare const RESERVED_SCHEMAS: readonly string[];
|
|
6
|
+
/** Whether a relation, as the engine names it, is tablewalk's own. */
|
|
7
|
+
export declare function isReservedRelation(schema: string | undefined, name: string): boolean;
|
|
8
|
+
/** The refusal for a statement found to touch `name`, by whichever half found it. */
|
|
9
|
+
export declare function reservedRefusal(name: string): Refusal;
|
|
10
|
+
/**
|
|
11
|
+
* Why this statement must not run under the guard, or null when nothing in
|
|
12
|
+
* its text reaches a reserved relation.
|
|
13
|
+
*/
|
|
14
|
+
export declare function reservedInText(sql: string, dialect: Dialect): string | null;
|
|
15
|
+
/** @throws Refusal when the statement's text reaches a reserved relation. */
|
|
16
|
+
export declare function refuseReservedText(sql: string, dialect: Dialect): void;
|
|
17
|
+
/**
|
|
18
|
+
* The Postgres check before a statement is given a connection: its text,
|
|
19
|
+
* and for a read, whether the planner can list what it reads — the engine
|
|
20
|
+
* half below needs a plan, so a statement the planner cannot explain is
|
|
21
|
+
* refused rather than run unchecked.
|
|
22
|
+
*/
|
|
23
|
+
export declare function refusePostgresReserved(sql: string, write?: boolean): void;
|
|
24
|
+
/**
|
|
25
|
+
* The Postgres engine half: the planner's own list of what a statement
|
|
26
|
+
* scans, read inside the transaction it will run in, so views, search_path
|
|
27
|
+
* and CTEs resolve as they will there.
|
|
28
|
+
*/
|
|
29
|
+
export declare function refuseReservedPlan(db: PgQuery, sql: string, params: unknown[]): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* The first reserved relation a Postgres `EXPLAIN (VERBOSE, FORMAT JSON)`
|
|
32
|
+
* plan reads. The plan is the planner's list of what the statement will
|
|
33
|
+
* actually scan — views expanded, search_path resolved, CTEs and subqueries
|
|
34
|
+
* included. What a function reads by a computed name is not in it; the
|
|
35
|
+
* lexical half refuses those functions by name.
|
|
36
|
+
*/
|
|
37
|
+
export declare function reservedInPlan(plan: unknown): string | null;
|
|
38
|
+
export {};
|