forgeos 0.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.npmignore +1 -0
- package/AGENTS.md +277 -0
- package/CHANGELOG.md +8 -0
- package/CONTRIBUTING.md +58 -0
- package/README.md +377 -0
- package/bin/forge-bun.mjs +110 -0
- package/bin/forge.mjs +19 -0
- package/package.json +96 -0
- package/packages/eslint-plugin-forge/index.ts +15 -0
- package/packages/eslint-plugin-forge/package.json +10 -0
- package/packages/eslint-plugin-forge/src/check-source.ts +95 -0
- package/packages/eslint-plugin-forge/src/load-artifacts.ts +24 -0
- package/packages/eslint-plugin-forge/src/rule-no-forge-guard-violation.ts +93 -0
- package/src/forge/_generated/actionSubscriptions.json +2 -0
- package/src/forge/_generated/actionSubscriptions.ts +10 -0
- package/src/forge/_generated/agentAdapterManifest.json +2 -0
- package/src/forge/_generated/agentAdapterManifest.ts +73 -0
- package/src/forge/_generated/agentContract.json +2 -0
- package/src/forge/_generated/agentContract.ts +912 -0
- package/src/forge/_generated/agentQuickstart.md +32 -0
- package/src/forge/_generated/aiContext.ts +59 -0
- package/src/forge/_generated/aiModels.json +2 -0
- package/src/forge/_generated/aiModels.ts +35 -0
- package/src/forge/_generated/aiProviders.json +2 -0
- package/src/forge/_generated/aiProviders.ts +23 -0
- package/src/forge/_generated/aiRegistry.json +2 -0
- package/src/forge/_generated/aiRegistry.ts +29 -0
- package/src/forge/_generated/api.json +2 -0
- package/src/forge/_generated/api.ts +8 -0
- package/src/forge/_generated/appGraph.json +2 -0
- package/src/forge/_generated/appGraph.ts +14511 -0
- package/src/forge/_generated/appMap.md +35 -0
- package/src/forge/_generated/artifactManifest.json +2 -0
- package/src/forge/_generated/artifactManifest.ts +7 -0
- package/src/forge/_generated/authClaims.json +2 -0
- package/src/forge/_generated/authClaims.ts +13 -0
- package/src/forge/_generated/authConfig.json +2 -0
- package/src/forge/_generated/authConfig.ts +17 -0
- package/src/forge/_generated/authContext.ts +23 -0
- package/src/forge/_generated/authRegistry.json +2 -0
- package/src/forge/_generated/authRegistry.ts +25 -0
- package/src/forge/_generated/buildInfo.json +2 -0
- package/src/forge/_generated/buildInfo.ts +9 -0
- package/src/forge/_generated/capabilityMap.json +2 -0
- package/src/forge/_generated/capabilityMap.md +15 -0
- package/src/forge/_generated/capabilityMap.ts +17 -0
- package/src/forge/_generated/client.ts +282 -0
- package/src/forge/_generated/clientApi.ts +9 -0
- package/src/forge/_generated/clientManifest.json +2 -0
- package/src/forge/_generated/clientManifest.ts +39 -0
- package/src/forge/_generated/clientTypes.ts +78 -0
- package/src/forge/_generated/configRegistry.json +2 -0
- package/src/forge/_generated/configRegistry.ts +4 -0
- package/src/forge/_generated/dataGraph.json +2 -0
- package/src/forge/_generated/dataGraph.ts +8 -0
- package/src/forge/_generated/db.json +2 -0
- package/src/forge/_generated/db.ts +2 -0
- package/src/forge/_generated/dbSecurityManifest.json +2 -0
- package/src/forge/_generated/dbSecurityManifest.ts +15 -0
- package/src/forge/_generated/dbSessionContext.json +2 -0
- package/src/forge/_generated/dbSessionContext.ts +39 -0
- package/src/forge/_generated/deployManifest.json +2 -0
- package/src/forge/_generated/deployManifest.ts +14 -0
- package/src/forge/_generated/devManifest.json +2 -0
- package/src/forge/_generated/devManifest.ts +47 -0
- package/src/forge/_generated/envSchema.json +2 -0
- package/src/forge/_generated/envSchema.ts +59 -0
- package/src/forge/_generated/frontendGraph.json +2 -0
- package/src/forge/_generated/frontendGraph.ts +27 -0
- package/src/forge/_generated/importGuards.json +2 -0
- package/src/forge/_generated/importGuards.ts +652 -0
- package/src/forge/_generated/index.ts +67 -0
- package/src/forge/_generated/liveProductionManifest.json +2 -0
- package/src/forge/_generated/liveProductionManifest.ts +23 -0
- package/src/forge/_generated/liveProtocol.json +2 -0
- package/src/forge/_generated/liveProtocol.ts +21 -0
- package/src/forge/_generated/liveQueryRegistry.json +2 -0
- package/src/forge/_generated/liveQueryRegistry.ts +9 -0
- package/src/forge/_generated/liveTransportConfig.json +2 -0
- package/src/forge/_generated/liveTransportConfig.ts +19 -0
- package/src/forge/_generated/makeRegistry.json +2 -0
- package/src/forge/_generated/makeRegistry.ts +163 -0
- package/src/forge/_generated/makeTemplates.json +2 -0
- package/src/forge/_generated/makeTemplates.ts +61 -0
- package/src/forge/_generated/mockMap.json +2 -0
- package/src/forge/_generated/mockMap.ts +7 -0
- package/src/forge/_generated/operationPlaybooks.md +145 -0
- package/src/forge/_generated/packageGraph.json +2 -0
- package/src/forge/_generated/packageGraph.ts +168569 -0
- package/src/forge/_generated/packageUpgradeRegistry.json +2 -0
- package/src/forge/_generated/packageUpgradeRegistry.ts +15 -0
- package/src/forge/_generated/permissionMatrix.json +2 -0
- package/src/forge/_generated/permissionMatrix.ts +7 -0
- package/src/forge/_generated/policyRegistry.json +2 -0
- package/src/forge/_generated/policyRegistry.ts +11 -0
- package/src/forge/_generated/queryRegistry.json +2 -0
- package/src/forge/_generated/queryRegistry.ts +9 -0
- package/src/forge/_generated/react.d.ts +22 -0
- package/src/forge/_generated/react.ts +29 -0
- package/src/forge/_generated/reactManifest.json +2 -0
- package/src/forge/_generated/reactManifest.ts +19 -0
- package/src/forge/_generated/releaseManifest.json +2 -0
- package/src/forge/_generated/releaseManifest.ts +25 -0
- package/src/forge/_generated/rlsPolicies.json +2 -0
- package/src/forge/_generated/rlsPolicies.sql +34 -0
- package/src/forge/_generated/rlsPolicies.ts +6 -0
- package/src/forge/_generated/runtimeGraph.json +2 -0
- package/src/forge/_generated/runtimeGraph.ts +8 -0
- package/src/forge/_generated/runtimeMatrix.json +2 -0
- package/src/forge/_generated/runtimeMatrix.ts +229125 -0
- package/src/forge/_generated/runtimeRegistry.ts +2 -0
- package/src/forge/_generated/runtimeRules.md +79 -0
- package/src/forge/_generated/secretRegistry.json +2 -0
- package/src/forge/_generated/secretRegistry.ts +50 -0
- package/src/forge/_generated/secretsContext.ts +11 -0
- package/src/forge/_generated/serverApi.ts +10 -0
- package/src/forge/_generated/sourceMapManifest.json +2 -0
- package/src/forge/_generated/sourceMapManifest.ts +7 -0
- package/src/forge/_generated/sqlPlan.json +2 -0
- package/src/forge/_generated/sqlPlan.ts +88 -0
- package/src/forge/_generated/subscriptionManifest.json +2 -0
- package/src/forge/_generated/subscriptionManifest.ts +7 -0
- package/src/forge/_generated/symbolicationManifest.json +2 -0
- package/src/forge/_generated/symbolicationManifest.ts +17 -0
- package/src/forge/_generated/telemetryRegistry.json +2 -0
- package/src/forge/_generated/telemetryRegistry.ts +9 -0
- package/src/forge/_generated/telemetrySinks.json +2 -0
- package/src/forge/_generated/telemetrySinks.ts +11 -0
- package/src/forge/_generated/tenantScope.json +2 -0
- package/src/forge/_generated/tenantScope.ts +8 -0
- package/src/forge/_generated/testGraph.json +2 -0
- package/src/forge/_generated/testGraph.ts +3054 -0
- package/src/forge/_generated/testPlanRegistry.json +2 -0
- package/src/forge/_generated/testPlanRegistry.ts +33 -0
- package/src/forge/_generated/uiRoutes.json +2 -0
- package/src/forge/_generated/uiRoutes.ts +16 -0
- package/src/forge/_generated/uiScenarios.json +2 -0
- package/src/forge/_generated/uiScenarios.ts +30 -0
- package/src/forge/_generated/uiTestManifest.json +2 -0
- package/src/forge/_generated/uiTestManifest.ts +27 -0
- package/src/forge/_generated/workflowRegistry.json +2 -0
- package/src/forge/_generated/workflowRegistry.ts +9 -0
- package/src/forge/_generated/workflowSubscriptions.json +2 -0
- package/src/forge/_generated/workflowSubscriptions.ts +10 -0
- package/src/forge/agent-adapters/index.ts +1002 -0
- package/src/forge/agent-adapters/types.ts +135 -0
- package/src/forge/cli/agent-contract.ts +50 -0
- package/src/forge/cli/ai.ts +148 -0
- package/src/forge/cli/auth.ts +198 -0
- package/src/forge/cli/build.ts +105 -0
- package/src/forge/cli/bun-exec.ts +4 -0
- package/src/forge/cli/commands.ts +1130 -0
- package/src/forge/cli/db.ts +316 -0
- package/src/forge/cli/deps.ts +277 -0
- package/src/forge/cli/dev.ts +529 -0
- package/src/forge/cli/doctor.ts +209 -0
- package/src/forge/cli/feature.ts +485 -0
- package/src/forge/cli/index.ts +25 -0
- package/src/forge/cli/lint-forge.ts +119 -0
- package/src/forge/cli/live.ts +179 -0
- package/src/forge/cli/main.ts +92 -0
- package/src/forge/cli/make.ts +133 -0
- package/src/forge/cli/new.ts +505 -0
- package/src/forge/cli/outbox.ts +297 -0
- package/src/forge/cli/output.ts +114 -0
- package/src/forge/cli/parse.ts +2211 -0
- package/src/forge/cli/policy.ts +204 -0
- package/src/forge/cli/query.ts +91 -0
- package/src/forge/cli/refactor.ts +221 -0
- package/src/forge/cli/release.ts +285 -0
- package/src/forge/cli/rls.ts +322 -0
- package/src/forge/cli/run.ts +76 -0
- package/src/forge/cli/secrets.ts +274 -0
- package/src/forge/cli/self-host.ts +468 -0
- package/src/forge/cli/serve.ts +93 -0
- package/src/forge/cli/telemetry.ts +219 -0
- package/src/forge/cli/verify.ts +587 -0
- package/src/forge/cli/version.ts +1 -0
- package/src/forge/cli/windows.ts +413 -0
- package/src/forge/cli/worker.ts +87 -0
- package/src/forge/cli/workflow.ts +424 -0
- package/src/forge/compiler/action-subscriptions/build.ts +116 -0
- package/src/forge/compiler/action-subscriptions/constants.ts +2 -0
- package/src/forge/compiler/action-subscriptions/index.ts +6 -0
- package/src/forge/compiler/action-subscriptions/parse.ts +6 -0
- package/src/forge/compiler/agent-contract/build.ts +1651 -0
- package/src/forge/compiler/agent-contract/types.ts +326 -0
- package/src/forge/compiler/ai-registry/build.ts +165 -0
- package/src/forge/compiler/ai-registry/constants.ts +2 -0
- package/src/forge/compiler/ai-registry/parse.ts +56 -0
- package/src/forge/compiler/api-surface/build.ts +107 -0
- package/src/forge/compiler/app-graph/build.ts +121 -0
- package/src/forge/compiler/app-graph/classify.ts +10 -0
- package/src/forge/compiler/app-graph/dup-symbol.ts +29 -0
- package/src/forge/compiler/app-graph/extract.ts +124 -0
- package/src/forge/compiler/app-graph/forge-apis.ts +29 -0
- package/src/forge/compiler/app-graph/index.ts +15 -0
- package/src/forge/compiler/app-graph/module-graph.ts +320 -0
- package/src/forge/compiler/app-graph/parser.ts +119 -0
- package/src/forge/compiler/app-graph/symbols.ts +48 -0
- package/src/forge/compiler/app-graph/tsconfig-hash.ts +62 -0
- package/src/forge/compiler/app-graph/types.ts +43 -0
- package/src/forge/compiler/app-graph/versions.ts +14 -0
- package/src/forge/compiler/cache/index.ts +17 -0
- package/src/forge/compiler/cache/key.ts +46 -0
- package/src/forge/compiler/cache/scheduler.ts +72 -0
- package/src/forge/compiler/cache/store.ts +78 -0
- package/src/forge/compiler/classifier/capabilities.ts +78 -0
- package/src/forge/compiler/classifier/classify.ts +113 -0
- package/src/forge/compiler/classifier/contexts.ts +188 -0
- package/src/forge/compiler/classifier/index.ts +18 -0
- package/src/forge/compiler/classifier/runtime-matrix.ts +45 -0
- package/src/forge/compiler/classifier/secrets.ts +41 -0
- package/src/forge/compiler/classifier/signals.ts +129 -0
- package/src/forge/compiler/client-sdk/build-manifest.ts +151 -0
- package/src/forge/compiler/client-sdk/render-client.ts +432 -0
- package/src/forge/compiler/data-graph/build.ts +131 -0
- package/src/forge/compiler/data-graph/constants.ts +5 -0
- package/src/forge/compiler/data-graph/index.ts +6 -0
- package/src/forge/compiler/data-graph/parse.ts +176 -0
- package/src/forge/compiler/data-graph/rls/build.ts +222 -0
- package/src/forge/compiler/data-graph/rls/types.ts +62 -0
- package/src/forge/compiler/data-graph/sql/ddl.ts +390 -0
- package/src/forge/compiler/data-graph/sql/naming.ts +10 -0
- package/src/forge/compiler/data-graph/sql/serialize.ts +85 -0
- package/src/forge/compiler/data-graph/sql/types.ts +37 -0
- package/src/forge/compiler/dev-manifest/build.ts +170 -0
- package/src/forge/compiler/dev-manifest/constants.ts +5 -0
- package/src/forge/compiler/diagnostics/codes.ts +611 -0
- package/src/forge/compiler/diagnostics/create.ts +245 -0
- package/src/forge/compiler/diagnostics/index.ts +55 -0
- package/src/forge/compiler/emitter/artifact-kind.ts +14 -0
- package/src/forge/compiler/emitter/barrel.ts +44 -0
- package/src/forge/compiler/emitter/constants.ts +7 -0
- package/src/forge/compiler/emitter/emit.ts +237 -0
- package/src/forge/compiler/emitter/index.ts +24 -0
- package/src/forge/compiler/emitter/lock.ts +62 -0
- package/src/forge/compiler/emitter/render.ts +73 -0
- package/src/forge/compiler/emitter/write.ts +35 -0
- package/src/forge/compiler/frontend-graph/build.ts +495 -0
- package/src/forge/compiler/fs/index.ts +23 -0
- package/src/forge/compiler/fs/memory.ts +233 -0
- package/src/forge/compiler/fs/node.ts +139 -0
- package/src/forge/compiler/fs/profile.ts +108 -0
- package/src/forge/compiler/fs/types.ts +52 -0
- package/src/forge/compiler/guards/artifacts.ts +96 -0
- package/src/forge/compiler/guards/check-ai-usage.ts +98 -0
- package/src/forge/compiler/guards/check-import-guards.ts +106 -0
- package/src/forge/compiler/guards/check-process-env.ts +98 -0
- package/src/forge/compiler/guards/check-query-usage.ts +76 -0
- package/src/forge/compiler/guards/index.ts +11 -0
- package/src/forge/compiler/guards/propagate-contexts.ts +57 -0
- package/src/forge/compiler/index.ts +17 -0
- package/src/forge/compiler/integration/add.ts +496 -0
- package/src/forge/compiler/integration/index.ts +17 -0
- package/src/forge/compiler/integration/plan.ts +283 -0
- package/src/forge/compiler/integration/render.ts +189 -0
- package/src/forge/compiler/integration/snapshot.ts +52 -0
- package/src/forge/compiler/integration/templates/ai.ts +131 -0
- package/src/forge/compiler/integration/templates/index.ts +8 -0
- package/src/forge/compiler/integration/templates/posthog.ts +145 -0
- package/src/forge/compiler/integration/templates/render.ts +113 -0
- package/src/forge/compiler/integration/templates/sentry.ts +151 -0
- package/src/forge/compiler/integration/templates/stripe.ts +109 -0
- package/src/forge/compiler/integration/templates/types.ts +14 -0
- package/src/forge/compiler/integration/templates/zod.ts +55 -0
- package/src/forge/compiler/live-production/types.ts +122 -0
- package/src/forge/compiler/live-query-registry/build.ts +150 -0
- package/src/forge/compiler/live-query-registry/constants.ts +2 -0
- package/src/forge/compiler/make-registry/build.ts +179 -0
- package/src/forge/compiler/orchestrator/discover.ts +214 -0
- package/src/forge/compiler/orchestrator/fast-check.ts +117 -0
- package/src/forge/compiler/orchestrator/generate-lock.ts +138 -0
- package/src/forge/compiler/orchestrator/guards.ts +5 -0
- package/src/forge/compiler/orchestrator/index.ts +27 -0
- package/src/forge/compiler/orchestrator/manifest-hashes.ts +21 -0
- package/src/forge/compiler/orchestrator/manifest.ts +92 -0
- package/src/forge/compiler/orchestrator/orphans.ts +51 -0
- package/src/forge/compiler/orchestrator/plan.ts +876 -0
- package/src/forge/compiler/orchestrator/profile.ts +36 -0
- package/src/forge/compiler/orchestrator/run.ts +277 -0
- package/src/forge/compiler/orchestrator/serialize.ts +886 -0
- package/src/forge/compiler/orchestrator/session.ts +96 -0
- package/src/forge/compiler/orchestrator/types.ts +31 -0
- package/src/forge/compiler/orchestrator/verify.ts +38 -0
- package/src/forge/compiler/orchestrator/workspace-index.ts +154 -0
- package/src/forge/compiler/package-graph/capabilities-stub.ts +33 -0
- package/src/forge/compiler/package-graph/checksum.ts +97 -0
- package/src/forge/compiler/package-graph/compiler.ts +392 -0
- package/src/forge/compiler/package-graph/constants.ts +4 -0
- package/src/forge/compiler/package-graph/dts-extractor.ts +142 -0
- package/src/forge/compiler/package-graph/exports-discovery.ts +84 -0
- package/src/forge/compiler/package-graph/extract-dts.ts +32 -0
- package/src/forge/compiler/package-graph/index.ts +33 -0
- package/src/forge/compiler/package-graph/jsdoc.ts +62 -0
- package/src/forge/compiler/package-graph/read-file.ts +21 -0
- package/src/forge/compiler/package-graph/resolve.ts +127 -0
- package/src/forge/compiler/package-manager/adapter.ts +237 -0
- package/src/forge/compiler/package-manager/bun-executable.ts +92 -0
- package/src/forge/compiler/package-manager/commands.ts +47 -0
- package/src/forge/compiler/package-manager/detect.ts +79 -0
- package/src/forge/compiler/package-manager/executor.ts +117 -0
- package/src/forge/compiler/package-manager/index.ts +22 -0
- package/src/forge/compiler/package-manager/parse-spec.ts +16 -0
- package/src/forge/compiler/package-manager/version.ts +27 -0
- package/src/forge/compiler/package-upgrades/apply.ts +195 -0
- package/src/forge/compiler/package-upgrades/comparator.ts +181 -0
- package/src/forge/compiler/package-upgrades/impact.ts +139 -0
- package/src/forge/compiler/package-upgrades/markdown.ts +97 -0
- package/src/forge/compiler/package-upgrades/planner.ts +532 -0
- package/src/forge/compiler/package-upgrades/risk.ts +208 -0
- package/src/forge/compiler/package-upgrades/types.ts +174 -0
- package/src/forge/compiler/policy-registry/build.ts +266 -0
- package/src/forge/compiler/policy-registry/constants.ts +2 -0
- package/src/forge/compiler/policy-registry/parse.ts +81 -0
- package/src/forge/compiler/primitives/compare.ts +26 -0
- package/src/forge/compiler/primitives/hash.ts +40 -0
- package/src/forge/compiler/primitives/header.ts +45 -0
- package/src/forge/compiler/primitives/index.ts +45 -0
- package/src/forge/compiler/primitives/paths.ts +24 -0
- package/src/forge/compiler/primitives/result.ts +164 -0
- package/src/forge/compiler/primitives/serialize.ts +66 -0
- package/src/forge/compiler/primitives/sort.ts +87 -0
- package/src/forge/compiler/query-registry/build.ts +114 -0
- package/src/forge/compiler/query-registry/constants.ts +2 -0
- package/src/forge/compiler/recipes/definitions.ts +289 -0
- package/src/forge/compiler/recipes/helpers.ts +37 -0
- package/src/forge/compiler/recipes/index.ts +21 -0
- package/src/forge/compiler/recipes/registry.ts +102 -0
- package/src/forge/compiler/release/build.ts +100 -0
- package/src/forge/compiler/release/types.ts +119 -0
- package/src/forge/compiler/runtime-graph/build.ts +137 -0
- package/src/forge/compiler/runtime-graph/constants.ts +5 -0
- package/src/forge/compiler/runtime-graph/index.ts +5 -0
- package/src/forge/compiler/sandbox/artifact-sanitize.ts +26 -0
- package/src/forge/compiler/sandbox/backends/child.ts +123 -0
- package/src/forge/compiler/sandbox/backends/docker.ts +173 -0
- package/src/forge/compiler/sandbox/index.ts +51 -0
- package/src/forge/compiler/sandbox/inspect.ts +143 -0
- package/src/forge/compiler/sandbox/inspector-entry.ts +115 -0
- package/src/forge/compiler/sandbox/limits.ts +31 -0
- package/src/forge/compiler/sandbox/scrub-env.ts +60 -0
- package/src/forge/compiler/sandbox/secret-scan.ts +54 -0
- package/src/forge/compiler/sandbox/serialize.ts +106 -0
- package/src/forge/compiler/sandbox/types.ts +7 -0
- package/src/forge/compiler/secret-registry/build.ts +123 -0
- package/src/forge/compiler/telemetry-registry/build.ts +89 -0
- package/src/forge/compiler/telemetry-registry/constants.ts +2 -0
- package/src/forge/compiler/telemetry-registry/parse.ts +13 -0
- package/src/forge/compiler/test-graph/build.ts +277 -0
- package/src/forge/compiler/types/action-subscriptions.ts +19 -0
- package/src/forge/compiler/types/ai-registry.ts +33 -0
- package/src/forge/compiler/types/app-graph.ts +80 -0
- package/src/forge/compiler/types/capability.ts +29 -0
- package/src/forge/compiler/types/classification.ts +9 -0
- package/src/forge/compiler/types/cli.ts +159 -0
- package/src/forge/compiler/types/data-graph.ts +24 -0
- package/src/forge/compiler/types/dev-manifest.ts +41 -0
- package/src/forge/compiler/types/diagnostic.ts +12 -0
- package/src/forge/compiler/types/emit.ts +25 -0
- package/src/forge/compiler/types/frontend-graph.ts +81 -0
- package/src/forge/compiler/types/import-guards.ts +19 -0
- package/src/forge/compiler/types/index.ts +98 -0
- package/src/forge/compiler/types/integration.ts +25 -0
- package/src/forge/compiler/types/json.ts +3 -0
- package/src/forge/compiler/types/live-query-registry.ts +32 -0
- package/src/forge/compiler/types/lock.ts +37 -0
- package/src/forge/compiler/types/package-graph.ts +84 -0
- package/src/forge/compiler/types/policy-registry.ts +69 -0
- package/src/forge/compiler/types/query-registry.ts +18 -0
- package/src/forge/compiler/types/runtime-graph.ts +30 -0
- package/src/forge/compiler/types/runtime-matrix.ts +16 -0
- package/src/forge/compiler/types/runtime.ts +30 -0
- package/src/forge/compiler/types/sandbox.ts +24 -0
- package/src/forge/compiler/types/secret-registry.ts +38 -0
- package/src/forge/compiler/types/telemetry-registry.ts +26 -0
- package/src/forge/compiler/types/test-graph.ts +45 -0
- package/src/forge/compiler/types/workflow-registry.ts +42 -0
- package/src/forge/compiler/workflow-registry/build.ts +180 -0
- package/src/forge/compiler/workflow-registry/constants.ts +2 -0
- package/src/forge/compiler/workflow-registry/index.ts +5 -0
- package/src/forge/compiler/workflow-registry/parse.ts +19 -0
- package/src/forge/dev/server.ts +1379 -0
- package/src/forge/dev/types.ts +49 -0
- package/src/forge/dev/watch.ts +109 -0
- package/src/forge/dev-console/cycle.ts +652 -0
- package/src/forge/dev-console/types.ts +99 -0
- package/src/forge/feature/compiler.ts +656 -0
- package/src/forge/feature/examples.ts +125 -0
- package/src/forge/feature/types.ts +177 -0
- package/src/forge/impact/index.ts +1160 -0
- package/src/forge/impact/types.ts +151 -0
- package/src/forge/intent/index.ts +490 -0
- package/src/forge/intent/types.ts +73 -0
- package/src/forge/make/fields.ts +146 -0
- package/src/forge/make/index.ts +1101 -0
- package/src/forge/make/naming.ts +42 -0
- package/src/forge/make/templates.ts +525 -0
- package/src/forge/make/types.ts +151 -0
- package/src/forge/platform/module.ts +20 -0
- package/src/forge/policy.ts +1 -0
- package/src/forge/react/index.ts +418 -0
- package/src/forge/refactor/index.ts +1936 -0
- package/src/forge/refactor/text-utils.ts +34 -0
- package/src/forge/refactor/types.ts +191 -0
- package/src/forge/refactor/workspace-fs.ts +171 -0
- package/src/forge/repair/index.ts +656 -0
- package/src/forge/repair/rules/index.ts +476 -0
- package/src/forge/repair/types.ts +175 -0
- package/src/forge/review/index.ts +992 -0
- package/src/forge/review/types.ts +196 -0
- package/src/forge/runtime/ai/check.ts +86 -0
- package/src/forge/runtime/ai/context.ts +394 -0
- package/src/forge/runtime/ai/cost-estimator.ts +41 -0
- package/src/forge/runtime/ai/mock.ts +49 -0
- package/src/forge/runtime/ai/providers.ts +78 -0
- package/src/forge/runtime/ai/state.ts +17 -0
- package/src/forge/runtime/ai/types.ts +67 -0
- package/src/forge/runtime/auth/authenticate.ts +58 -0
- package/src/forge/runtime/auth/claims.ts +119 -0
- package/src/forge/runtime/auth/config.ts +148 -0
- package/src/forge/runtime/auth/errors.ts +45 -0
- package/src/forge/runtime/auth/evaluate.ts +126 -0
- package/src/forge/runtime/auth/resolve.ts +74 -0
- package/src/forge/runtime/auth/types.ts +87 -0
- package/src/forge/runtime/auth/verifier.ts +138 -0
- package/src/forge/runtime/context/create-context.ts +204 -0
- package/src/forge/runtime/context/create-query-context.ts +34 -0
- package/src/forge/runtime/db/adapter.ts +31 -0
- package/src/forge/runtime/db/factory.ts +83 -0
- package/src/forge/runtime/db/generated-client.ts +294 -0
- package/src/forge/runtime/db/memory-adapter.ts +706 -0
- package/src/forge/runtime/db/migrate.ts +132 -0
- package/src/forge/runtime/db/outbox.ts +54 -0
- package/src/forge/runtime/db/pglite-adapter.ts +51 -0
- package/src/forge/runtime/db/postgres-adapter.ts +112 -0
- package/src/forge/runtime/db/read-only-client.ts +97 -0
- package/src/forge/runtime/db/session-context.ts +62 -0
- package/src/forge/runtime/executor.ts +446 -0
- package/src/forge/runtime/live/dependency-tracker.ts +57 -0
- package/src/forge/runtime/live/invalidation-log.ts +189 -0
- package/src/forge/runtime/live/live-query-runner.ts +267 -0
- package/src/forge/runtime/live/registry.ts +28 -0
- package/src/forge/runtime/live/sse.ts +75 -0
- package/src/forge/runtime/live/subscription-manager.ts +443 -0
- package/src/forge/runtime/live/types.ts +143 -0
- package/src/forge/runtime/outbox/claim.ts +153 -0
- package/src/forge/runtime/outbox/process.ts +298 -0
- package/src/forge/runtime/outbox/retry.ts +8 -0
- package/src/forge/runtime/outbox/subscriptions.ts +33 -0
- package/src/forge/runtime/outbox/types.ts +69 -0
- package/src/forge/runtime/policy/check.ts +157 -0
- package/src/forge/runtime/policy/load.ts +55 -0
- package/src/forge/runtime/query/registry.ts +19 -0
- package/src/forge/runtime/query/run-query.ts +347 -0
- package/src/forge/runtime/release/runtime.ts +322 -0
- package/src/forge/runtime/release/symbolicate.ts +175 -0
- package/src/forge/runtime/runner/command-transaction.ts +193 -0
- package/src/forge/runtime/runner/run-entry.ts +226 -0
- package/src/forge/runtime/secrets/check.ts +78 -0
- package/src/forge/runtime/secrets/create-context.ts +138 -0
- package/src/forge/runtime/secrets/env-loader.ts +94 -0
- package/src/forge/runtime/secrets/runtime-bundle.ts +47 -0
- package/src/forge/runtime/secrets/types.ts +31 -0
- package/src/forge/runtime/telemetry/buffer.ts +87 -0
- package/src/forge/runtime/telemetry/context.ts +192 -0
- package/src/forge/runtime/telemetry/correlation.ts +13 -0
- package/src/forge/runtime/telemetry/flush.ts +190 -0
- package/src/forge/runtime/telemetry/process.ts +20 -0
- package/src/forge/runtime/telemetry/scrubber.ts +115 -0
- package/src/forge/runtime/telemetry/sinks/local-jsonl.ts +39 -0
- package/src/forge/runtime/telemetry/sinks/posthog.ts +64 -0
- package/src/forge/runtime/telemetry/sinks/sentry.ts +60 -0
- package/src/forge/runtime/telemetry/spans.ts +58 -0
- package/src/forge/runtime/telemetry/types.ts +64 -0
- package/src/forge/runtime/workflows/cancel.ts +26 -0
- package/src/forge/runtime/workflows/create-run.ts +98 -0
- package/src/forge/runtime/workflows/process-run.ts +182 -0
- package/src/forge/runtime/workflows/process-step.ts +190 -0
- package/src/forge/runtime/workflows/process.ts +260 -0
- package/src/forge/runtime/workflows/registry.ts +51 -0
- package/src/forge/runtime/workflows/resolve-step.ts +46 -0
- package/src/forge/runtime/workflows/retry-run.ts +44 -0
- package/src/forge/runtime/workflows/retry.ts +8 -0
- package/src/forge/runtime/workflows/sanitize.ts +19 -0
- package/src/forge/runtime/workflows/start-from-outbox.ts +71 -0
- package/src/forge/runtime/workflows/types.ts +77 -0
- package/src/forge/server.ts +96 -0
- package/src/forge/ui/index.ts +770 -0
- package/src/forge/ui/types.ts +191 -0
- package/templates/b2b-support-web/.env.example +22 -0
- package/templates/b2b-support-web/.vscode/settings.json +14 -0
- package/templates/b2b-support-web/AGENTS.md +108 -0
- package/templates/b2b-support-web/README.md +48 -0
- package/templates/b2b-support-web/forge.config.ts +3 -0
- package/templates/b2b-support-web/package.json +34 -0
- package/templates/b2b-support-web/src/actions/captureTicketCreated.ts +14 -0
- package/templates/b2b-support-web/src/commands/closeTicket.ts +20 -0
- package/templates/b2b-support-web/src/commands/createTicket.ts +47 -0
- package/templates/b2b-support-web/src/commands/manageBilling.ts +9 -0
- package/templates/b2b-support-web/src/forge/schema.ts +35 -0
- package/templates/b2b-support-web/src/policies.ts +9 -0
- package/templates/b2b-support-web/src/queries/getTicket.ts +6 -0
- package/templates/b2b-support-web/src/queries/listTickets.ts +6 -0
- package/templates/b2b-support-web/src/queries/liveTickets.ts +9 -0
- package/templates/b2b-support-web/src/workflows/triageTicketWorkflow.ts +64 -0
- package/templates/b2b-support-web/tsconfig.json +14 -0
- package/templates/b2b-support-web/web/app/globals.css +77 -0
- package/templates/b2b-support-web/web/app/layout.tsx +13 -0
- package/templates/b2b-support-web/web/app/page.tsx +13 -0
- package/templates/b2b-support-web/web/app/providers.tsx +21 -0
- package/templates/b2b-support-web/web/app/tickets/page.tsx +21 -0
- package/templates/b2b-support-web/web/components/CreateTicketForm.tsx +43 -0
- package/templates/b2b-support-web/web/components/PolicyDeniedDemo.tsx +31 -0
- package/templates/b2b-support-web/web/components/TicketList.tsx +52 -0
- package/templates/b2b-support-web/web/components/TraceDetails.tsx +18 -0
- package/templates/b2b-support-web/web/components/TriageStatus.tsx +13 -0
- package/templates/b2b-support-web/web/lib/forge.ts +13 -0
- package/templates/b2b-support-web/web/next-env.d.ts +5 -0
- package/templates/b2b-support-web/web/next.config.ts +8 -0
- package/templates/b2b-support-web/web/package.json +21 -0
- package/templates/b2b-support-web/web/tsconfig.json +30 -0
- package/templates/minimal-web/.vscode/settings.json +14 -0
- package/templates/minimal-web/README.md +21 -0
- package/templates/minimal-web/forge.config.ts +3 -0
- package/templates/minimal-web/package.json +32 -0
- package/templates/minimal-web/src/actions/logNoteCreated.ts +11 -0
- package/templates/minimal-web/src/commands/createNote.ts +26 -0
- package/templates/minimal-web/src/forge/schema.ts +12 -0
- package/templates/minimal-web/src/policies.ts +6 -0
- package/templates/minimal-web/src/queries/listNotes.ts +8 -0
- package/templates/minimal-web/src/queries/liveNotes.ts +8 -0
- package/templates/minimal-web/tsconfig.json +15 -0
- package/templates/minimal-web/web/index.html +12 -0
- package/templates/minimal-web/web/package.json +21 -0
- package/templates/minimal-web/web/src/App.tsx +89 -0
- package/templates/minimal-web/web/src/lib/forge.ts +13 -0
- package/templates/minimal-web/web/src/main.tsx +13 -0
- package/templates/minimal-web/web/src/styles.css +156 -0
- package/templates/minimal-web/web/tsconfig.json +18 -0
|
@@ -0,0 +1,706 @@
|
|
|
1
|
+
import type { DbAdapter, DbQueryResult, DbTransaction } from "./adapter.ts";
|
|
2
|
+
|
|
3
|
+
interface MemoryRow {
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
interface MemoryTable {
|
|
8
|
+
rows: MemoryRow[];
|
|
9
|
+
nextSerial: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function normalizeRows(rows: MemoryRow[]): DbQueryResult {
|
|
13
|
+
return {
|
|
14
|
+
rows: rows.map((row) => ({ ...row })),
|
|
15
|
+
rowCount: rows.length,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function parseNow(): string {
|
|
20
|
+
return new Date().toISOString();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function compareValue(left: unknown, right: unknown): boolean {
|
|
24
|
+
if (left instanceof Date && typeof right === "string") {
|
|
25
|
+
return left.getTime() <= new Date(right).getTime();
|
|
26
|
+
}
|
|
27
|
+
if (typeof left === "string" && typeof right === "string") {
|
|
28
|
+
if (left.includes("T") && right.includes("T")) {
|
|
29
|
+
return new Date(left).getTime() <= new Date(right).getTime();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return left === right;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function parseTableName(sql: string): string | null {
|
|
36
|
+
const patterns = [
|
|
37
|
+
/FROM\s+"([^"]+)"/i,
|
|
38
|
+
/INTO\s+"([^"]+)"/i,
|
|
39
|
+
/INTO\s+([a-z_][a-z0-9_]*)/i,
|
|
40
|
+
/FROM\s+([a-z_][a-z0-9_]*)/i,
|
|
41
|
+
/UPDATE\s+"([^"]+)"/i,
|
|
42
|
+
/UPDATE\s+([a-z_][a-z0-9_]*)/i,
|
|
43
|
+
/TABLE\s+"([^"]+)"/i,
|
|
44
|
+
/TABLE\s+([a-z_][a-z0-9_]*)/i,
|
|
45
|
+
];
|
|
46
|
+
for (const pattern of patterns) {
|
|
47
|
+
const match = sql.match(pattern);
|
|
48
|
+
if (match?.[1]) {
|
|
49
|
+
return match[1];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function splitSqlList(value: string): string[] {
|
|
56
|
+
const parts: string[] = [];
|
|
57
|
+
let current = "";
|
|
58
|
+
let quote: "'" | "\"" | null = null;
|
|
59
|
+
|
|
60
|
+
for (const char of value) {
|
|
61
|
+
if (char === "(" && quote === null) {
|
|
62
|
+
current += char;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (char === ")" && quote === null) {
|
|
66
|
+
current += char;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if ((char === "'" || char === "\"") && quote === null) {
|
|
70
|
+
quote = char;
|
|
71
|
+
} else if (char === quote) {
|
|
72
|
+
quote = null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const openParens = (current.match(/\(/g) ?? []).length;
|
|
76
|
+
const closeParens = (current.match(/\)/g) ?? []).length;
|
|
77
|
+
if (char === "," && quote === null && openParens === closeParens) {
|
|
78
|
+
parts.push(current.trim());
|
|
79
|
+
current = "";
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
current += char;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (current.trim().length > 0) {
|
|
87
|
+
parts.push(current.trim());
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return parts;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function parseSqlLiteral(token: string, params: unknown[]): unknown {
|
|
94
|
+
const paramMatch = token.match(/^\$(\d+)/);
|
|
95
|
+
if (paramMatch?.[1]) {
|
|
96
|
+
return params[Number(paramMatch[1]) - 1];
|
|
97
|
+
}
|
|
98
|
+
if (/^now\(\)$/i.test(token)) {
|
|
99
|
+
return parseNow();
|
|
100
|
+
}
|
|
101
|
+
if (/^null$/i.test(token)) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
if (
|
|
105
|
+
(token.startsWith("'") && token.endsWith("'")) ||
|
|
106
|
+
(token.startsWith("\"") && token.endsWith("\""))
|
|
107
|
+
) {
|
|
108
|
+
return token.slice(1, -1);
|
|
109
|
+
}
|
|
110
|
+
const numeric = Number(token);
|
|
111
|
+
return Number.isFinite(numeric) ? numeric : token;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function deterministicUuid(serial: number): string {
|
|
115
|
+
return `00000000-0000-0000-0000-${String(serial).padStart(12, "0")}`;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function applySystemDefaults(tableName: string, row: MemoryRow): void {
|
|
119
|
+
const now = parseNow();
|
|
120
|
+
|
|
121
|
+
if (tableName === "_forge_outbox") {
|
|
122
|
+
row.created_at ??= now;
|
|
123
|
+
row.processed_at ??= null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (tableName === "_forge_outbox_deliveries") {
|
|
127
|
+
row.status ??= "pending";
|
|
128
|
+
row.attempts ??= 0;
|
|
129
|
+
row.max_attempts ??= 5;
|
|
130
|
+
row.next_attempt_at ??= now;
|
|
131
|
+
row.locked_at ??= null;
|
|
132
|
+
row.locked_by ??= null;
|
|
133
|
+
row.last_error ??= null;
|
|
134
|
+
row.processed_at ??= null;
|
|
135
|
+
row.created_at ??= now;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (tableName === "_forge_workflow_runs") {
|
|
139
|
+
row.status ??= "pending";
|
|
140
|
+
row.current_step ??= null;
|
|
141
|
+
row.last_error ??= null;
|
|
142
|
+
row.created_at ??= now;
|
|
143
|
+
row.updated_at ??= now;
|
|
144
|
+
row.started_at ??= null;
|
|
145
|
+
row.completed_at ??= null;
|
|
146
|
+
row.canceled_at ??= null;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (tableName === "_forge_workflow_steps") {
|
|
150
|
+
row.status ??= "pending";
|
|
151
|
+
row.input ??= null;
|
|
152
|
+
row.output ??= null;
|
|
153
|
+
row.attempts ??= 0;
|
|
154
|
+
row.max_attempts ??= 5;
|
|
155
|
+
row.next_attempt_at ??= now;
|
|
156
|
+
row.locked_at ??= null;
|
|
157
|
+
row.locked_by ??= null;
|
|
158
|
+
row.last_error ??= null;
|
|
159
|
+
row.started_at ??= null;
|
|
160
|
+
row.completed_at ??= null;
|
|
161
|
+
row.created_at ??= now;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (tableName === "_forge_telemetry_events") {
|
|
165
|
+
row.status ??= "pending";
|
|
166
|
+
row.created_at ??= now;
|
|
167
|
+
row.next_attempt_at ??= now;
|
|
168
|
+
row.attempts ??= 0;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (tableName === "_forge_trace_spans") {
|
|
172
|
+
row.started_at ??= now;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (tableName === "_forge_live_invalidations") {
|
|
176
|
+
row.payload ??= {};
|
|
177
|
+
row.created_at ??= now;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (tableName === "_forge_live_subscription_debug") {
|
|
181
|
+
row.created_at ??= now;
|
|
182
|
+
row.updated_at ??= now;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function projectRows(sql: string, rows: MemoryRow[]): MemoryRow[] {
|
|
187
|
+
const selectMatch = sql.match(/^SELECT\s+(.+?)\s+FROM\s/i);
|
|
188
|
+
const selectList = selectMatch?.[1]?.trim();
|
|
189
|
+
if (!selectList || selectList === "*" || /COUNT\(\*\)/i.test(selectList)) {
|
|
190
|
+
return rows;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const columns = splitSqlList(selectList)
|
|
194
|
+
.map((column) => column.replace(/\s+AS\s+\w+$/i, "").trim())
|
|
195
|
+
.map((column) => column.replace(/^[\w.]+\./, "").replace(/"/g, ""));
|
|
196
|
+
|
|
197
|
+
return rows.map((row) => {
|
|
198
|
+
const projected: MemoryRow = {};
|
|
199
|
+
for (const column of columns) {
|
|
200
|
+
projected[column] = row[column];
|
|
201
|
+
}
|
|
202
|
+
return projected;
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export class MemoryAdapter implements DbAdapter {
|
|
207
|
+
readonly kind = "memory" as const;
|
|
208
|
+
private tables = new Map<string, MemoryTable>();
|
|
209
|
+
private sequences = new Map<string, number>();
|
|
210
|
+
|
|
211
|
+
async query(sql: string, params: unknown[] = []): Promise<DbQueryResult> {
|
|
212
|
+
const trimmed = sql.trim().replace(/\s+/g, " ");
|
|
213
|
+
|
|
214
|
+
if (trimmed.startsWith("CREATE TABLE")) {
|
|
215
|
+
const match =
|
|
216
|
+
trimmed.match(/CREATE TABLE IF NOT EXISTS "([^"]+)"/i) ??
|
|
217
|
+
trimmed.match(/CREATE TABLE IF NOT EXISTS ([a-z_][a-z0-9_]*)/i);
|
|
218
|
+
if (match?.[1] && !this.tables.has(match[1])) {
|
|
219
|
+
this.tables.set(match[1], { rows: [], nextSerial: 1 });
|
|
220
|
+
}
|
|
221
|
+
return { rows: [], rowCount: 0 };
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (trimmed.startsWith("CREATE SEQUENCE")) {
|
|
225
|
+
const match =
|
|
226
|
+
trimmed.match(/CREATE SEQUENCE IF NOT EXISTS "([^"]+)"/i) ??
|
|
227
|
+
trimmed.match(/CREATE SEQUENCE IF NOT EXISTS ([a-z_][a-z0-9_]*)/i);
|
|
228
|
+
if (match?.[1] && !this.sequences.has(match[1])) {
|
|
229
|
+
const start = Number(trimmed.match(/START WITH\s+(\d+)/i)?.[1] ?? 1);
|
|
230
|
+
this.sequences.set(match[1], Number.isFinite(start) ? start : 1);
|
|
231
|
+
}
|
|
232
|
+
return { rows: [], rowCount: 0 };
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (trimmed.startsWith("CREATE INDEX")) {
|
|
236
|
+
return { rows: [], rowCount: 0 };
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (trimmed.startsWith("DROP TABLE")) {
|
|
240
|
+
const match = trimmed.match(/DROP TABLE IF EXISTS "([^"]+)"/i);
|
|
241
|
+
if (match?.[1]) {
|
|
242
|
+
this.tables.delete(match[1]);
|
|
243
|
+
}
|
|
244
|
+
return { rows: [], rowCount: 0 };
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (trimmed.startsWith("TRUNCATE")) {
|
|
248
|
+
const match =
|
|
249
|
+
trimmed.match(/TRUNCATE TABLE "([^"]+)"/i) ??
|
|
250
|
+
trimmed.match(/TRUNCATE TABLE ([a-z_][a-z0-9_]*)/i);
|
|
251
|
+
if (match?.[1]) {
|
|
252
|
+
const table = this.tables.get(match[1]);
|
|
253
|
+
if (table) {
|
|
254
|
+
table.rows = [];
|
|
255
|
+
if (/RESTART IDENTITY/i.test(trimmed)) {
|
|
256
|
+
table.nextSerial = 1;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return { rows: [], rowCount: 0 };
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (trimmed.startsWith("INSERT INTO")) {
|
|
264
|
+
return this.handleInsert(trimmed, params);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (trimmed.startsWith("SELECT")) {
|
|
268
|
+
return this.handleSelect(trimmed, params);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (trimmed.startsWith("UPDATE")) {
|
|
272
|
+
return this.handleUpdate(trimmed, params);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (trimmed.startsWith("DELETE")) {
|
|
276
|
+
return this.handleDelete(trimmed, params);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return { rows: [], rowCount: 0 };
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
private handleInsert(sql: string, params: unknown[]): DbQueryResult {
|
|
283
|
+
const tableName = parseTableName(sql);
|
|
284
|
+
if (!tableName) {
|
|
285
|
+
return { rows: [], rowCount: 0 };
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const table = this.ensureTable(tableName);
|
|
289
|
+
const row: MemoryRow = {};
|
|
290
|
+
const columnsMatch = sql.match(/\(([^)]+)\)\s*VALUES/i);
|
|
291
|
+
const columns =
|
|
292
|
+
columnsMatch?.[1]
|
|
293
|
+
?.split(",")
|
|
294
|
+
.map((column) => column.trim().replace(/"/g, "")) ?? [];
|
|
295
|
+
|
|
296
|
+
const valuesMatch = sql.match(/\)\s*VALUES\s*\((.+?)\)(?:\s|$)/i);
|
|
297
|
+
const values = valuesMatch?.[1] ? splitSqlList(valuesMatch[1]) : [];
|
|
298
|
+
|
|
299
|
+
columns.forEach((column, index) => {
|
|
300
|
+
const token = values[index];
|
|
301
|
+
row[column] = token ? parseSqlLiteral(token, params) : params[index];
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
if (/ON CONFLICT/i.test(sql)) {
|
|
305
|
+
const conflictColumn = sql.match(/ON CONFLICT\s*\(\s*"?(\w+)"?\s*\)/i)?.[1];
|
|
306
|
+
if (conflictColumn) {
|
|
307
|
+
const existing = table.rows.find((candidate) => candidate[conflictColumn] === row[conflictColumn]);
|
|
308
|
+
if (existing) {
|
|
309
|
+
if (/DO NOTHING/i.test(sql)) {
|
|
310
|
+
return { rows: [], rowCount: 0 };
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (row.id === undefined && columns.includes("id") === false) {
|
|
317
|
+
row.id =
|
|
318
|
+
tableName.startsWith("_forge_") || tableName.includes("outbox")
|
|
319
|
+
? table.nextSerial++
|
|
320
|
+
: deterministicUuid(table.nextSerial++);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (row.created_at === undefined && columns.includes("created_at")) {
|
|
324
|
+
row.created_at = parseNow();
|
|
325
|
+
}
|
|
326
|
+
if (row.updated_at === undefined && columns.includes("updated_at")) {
|
|
327
|
+
row.updated_at = parseNow();
|
|
328
|
+
}
|
|
329
|
+
if (row.next_attempt_at === undefined && columns.includes("next_attempt_at")) {
|
|
330
|
+
row.next_attempt_at = parseNow();
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
applySystemDefaults(tableName, row);
|
|
334
|
+
|
|
335
|
+
table.rows.push(row);
|
|
336
|
+
|
|
337
|
+
if (/RETURNING/i.test(sql)) {
|
|
338
|
+
if (/RETURNING\s+\*/i.test(sql)) {
|
|
339
|
+
return { rows: [{ ...row }], rowCount: 1 };
|
|
340
|
+
}
|
|
341
|
+
const returningMatch = sql.match(/RETURNING\s+"?(\w+)"?/i);
|
|
342
|
+
const returningCol = returningMatch?.[1] ?? "id";
|
|
343
|
+
return { rows: [{ [returningCol]: row[returningCol] }], rowCount: 1 };
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return { rows: [{ ...row }], rowCount: 1 };
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
private handleSelect(sql: string, params: unknown[]): DbQueryResult {
|
|
350
|
+
const nextvalMatch = sql.match(/nextval\(\s*'([^']+)'\s*\)/i);
|
|
351
|
+
if (nextvalMatch?.[1]) {
|
|
352
|
+
const name = nextvalMatch[1];
|
|
353
|
+
const current = this.sequences.get(name) ?? 1;
|
|
354
|
+
this.sequences.set(name, current + 1);
|
|
355
|
+
return { rows: [{ revision: current, nextval: current }], rowCount: 1 };
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (/MAX\(\s*revision\s*\)/i.test(sql)) {
|
|
359
|
+
const table = this.tables.get("_forge_live_invalidations");
|
|
360
|
+
const max = Math.max(
|
|
361
|
+
0,
|
|
362
|
+
...((table?.rows ?? []).map((row) => Number(row.revision)).filter(Number.isFinite)),
|
|
363
|
+
);
|
|
364
|
+
const alias = sql.match(/AS\s+"?(\w+)"?/i)?.[1] ?? "revision";
|
|
365
|
+
return { rows: [{ [alias]: max, revision: max }], rowCount: 1 };
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (/information_schema\.tables/i.test(sql)) {
|
|
369
|
+
const tables = [...this.tables.keys()].sort().map((name) => ({ table_name: name }));
|
|
370
|
+
return normalizeRows(tables);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
if (/COUNT\(\*\)/i.test(sql)) {
|
|
374
|
+
const tableName = parseTableName(sql);
|
|
375
|
+
if (!tableName) {
|
|
376
|
+
return { rows: [{ count: 0 }], rowCount: 1 };
|
|
377
|
+
}
|
|
378
|
+
const table = this.tables.get(tableName);
|
|
379
|
+
let rows = table?.rows ?? [];
|
|
380
|
+
|
|
381
|
+
if (/GROUP BY\s+"?status"?/i.test(sql)) {
|
|
382
|
+
const grouped = new Map<string, number>();
|
|
383
|
+
for (const row of rows) {
|
|
384
|
+
const status = String(row.status ?? "unknown");
|
|
385
|
+
grouped.set(status, (grouped.get(status) ?? 0) + 1);
|
|
386
|
+
}
|
|
387
|
+
return normalizeRows(
|
|
388
|
+
[...grouped.entries()].map(([status, count]) => ({ status, count })),
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
if (/WHERE/i.test(sql)) {
|
|
393
|
+
rows = this.filterRows(rows, sql, params);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
const alias = sql.match(/COUNT\(\*\)(?:::int)?\s+AS\s+"?(\w+)"?/i)?.[1] ?? "count";
|
|
397
|
+
return { rows: [{ [alias]: rows.length, count: rows.length }], rowCount: 1 };
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
if (/JOIN/i.test(sql)) {
|
|
401
|
+
return this.handleJoinSelect(sql, params);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
const tableName = parseTableName(sql);
|
|
405
|
+
if (!tableName) {
|
|
406
|
+
return { rows: [], rowCount: 0 };
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
const table = this.tables.get(tableName);
|
|
410
|
+
if (!table) {
|
|
411
|
+
return { rows: [], rowCount: 0 };
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
let rows = [...table.rows];
|
|
415
|
+
|
|
416
|
+
if (/WHERE/i.test(sql)) {
|
|
417
|
+
rows = this.filterRows(rows, sql, params);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
if (/ORDER BY/i.test(sql)) {
|
|
421
|
+
const orderMatch = sql.match(/ORDER BY\s+"?(\w+)"?/i);
|
|
422
|
+
const column = orderMatch?.[1];
|
|
423
|
+
if (column) {
|
|
424
|
+
rows.sort((a, b) => {
|
|
425
|
+
const left = a[column];
|
|
426
|
+
const right = b[column];
|
|
427
|
+
if (left === right) return 0;
|
|
428
|
+
return (left as number) < (right as number) ? -1 : 1;
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
if (/ORDER BY\s+revision/i.test(sql)) {
|
|
434
|
+
rows.sort((a, b) => Number(a.revision) - Number(b.revision));
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
if (/LIMIT/i.test(sql)) {
|
|
438
|
+
const limitMatch = sql.match(/LIMIT\s+\$(\d+)/i);
|
|
439
|
+
const limitParam = limitMatch ? Number(params[Number(limitMatch[1]) - 1]) : Number(params[params.length - 1] ?? params[0]);
|
|
440
|
+
if (Number.isFinite(limitParam)) {
|
|
441
|
+
rows = rows.slice(0, limitParam);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
if (/ORDER BY\s+id\s+DESC/i.test(sql)) {
|
|
446
|
+
rows.sort((a, b) => Number(b.id) - Number(a.id));
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
return normalizeRows(projectRows(sql, rows));
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
private handleJoinSelect(sql: string, _params: unknown[]): DbQueryResult {
|
|
453
|
+
const deliveryTable = this.tables.get("_forge_outbox_deliveries");
|
|
454
|
+
const outboxTable = this.tables.get("_forge_outbox");
|
|
455
|
+
if (!deliveryTable || !outboxTable) {
|
|
456
|
+
return { rows: [], rowCount: 0 };
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
let rows: MemoryRow[] = deliveryTable.rows.map((delivery) => {
|
|
460
|
+
const event = outboxTable.rows.find((row) => row.id === delivery.outbox_id);
|
|
461
|
+
return {
|
|
462
|
+
...delivery,
|
|
463
|
+
event_type: event?.event_type,
|
|
464
|
+
event_created_at: event?.created_at,
|
|
465
|
+
};
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
if (/WHERE\s+d\.status\s*=\s*'dead'/i.test(sql)) {
|
|
469
|
+
rows = rows.filter((row) => row.status === "dead");
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
rows.sort((a, b) => Number(a.id) - Number(b.id));
|
|
473
|
+
return normalizeRows(projectRows(sql, rows));
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
private filterRows(rows: MemoryRow[], sql: string, params: unknown[]): MemoryRow[] {
|
|
477
|
+
if (/status\s*=\s*'pending'/i.test(sql) && /next_attempt_at\s*<=\s*now\(\)/i.test(sql)) {
|
|
478
|
+
return rows.filter((row) => row.status === "pending");
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
if (/trace_id\s*=\s*\$\d+/i.test(sql)) {
|
|
482
|
+
return rows.filter((row) => row.trace_id === params[0]);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
if (/status\s+IN\s*\(\s*'pending'\s*,\s*'running'\s*,\s*'failed'\s*\)/i.test(sql)) {
|
|
486
|
+
return rows.filter((row) =>
|
|
487
|
+
["pending", "running", "failed"].includes(String(row.status)),
|
|
488
|
+
);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
if (/status\s+NOT\s+IN\s*\(\s*'completed'\s*,\s*'skipped'\s*\)/i.test(sql)) {
|
|
492
|
+
return rows.filter(
|
|
493
|
+
(row) => !["completed", "skipped"].includes(String(row.status)),
|
|
494
|
+
);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
if (/status\s*=\s*'dead'/i.test(sql) && /COUNT/i.test(sql)) {
|
|
498
|
+
return rows.filter((row) => row.status === "dead");
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
if (/step_index\s*<\s*\$\d+/i.test(sql) && /status\s*!=\s*'completed'/i.test(sql)) {
|
|
502
|
+
const threshold = Number(params[1]);
|
|
503
|
+
const runId = params[0];
|
|
504
|
+
return rows.filter(
|
|
505
|
+
(row) =>
|
|
506
|
+
row.run_id === runId &&
|
|
507
|
+
Number(row.step_index) < threshold &&
|
|
508
|
+
row.status !== "completed",
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
if (/idempotency_key\s*=\s*\$\d+/i.test(sql)) {
|
|
513
|
+
return rows.filter((row) => row.idempotency_key === params[0]);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
if (/status\s*=\s*'dead'/i.test(sql)) {
|
|
517
|
+
return rows.filter((row) => row.status === "dead");
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
const conditions = [
|
|
521
|
+
...sql.matchAll(
|
|
522
|
+
/(?:^|\s|AND\s)(?:\w+\.)?"?(\w+)"?\s*(=|<=|>=|>|<|!=)\s*(\$\d+|now\(\)|'[^']*'|"[^"]*"|\d+)/gi,
|
|
523
|
+
),
|
|
524
|
+
];
|
|
525
|
+
|
|
526
|
+
return rows.filter((row) => {
|
|
527
|
+
for (const condition of conditions) {
|
|
528
|
+
const column = condition[1]!;
|
|
529
|
+
const operator = condition[2]!;
|
|
530
|
+
const value = parseSqlLiteral(condition[3]!, params);
|
|
531
|
+
|
|
532
|
+
if (operator === "<=") {
|
|
533
|
+
if (!compareValue(row[column], value)) {
|
|
534
|
+
return false;
|
|
535
|
+
}
|
|
536
|
+
} else if (operator === ">") {
|
|
537
|
+
if (!(Number(row[column]) > Number(value))) {
|
|
538
|
+
return false;
|
|
539
|
+
}
|
|
540
|
+
} else if (operator === ">=") {
|
|
541
|
+
if (!(Number(row[column]) >= Number(value))) {
|
|
542
|
+
return false;
|
|
543
|
+
}
|
|
544
|
+
} else if (operator === "<") {
|
|
545
|
+
if (!(Number(row[column]) < Number(value))) {
|
|
546
|
+
return false;
|
|
547
|
+
}
|
|
548
|
+
} else if (operator === "!=") {
|
|
549
|
+
if (row[column] === value) {
|
|
550
|
+
return false;
|
|
551
|
+
}
|
|
552
|
+
} else if (row[column] !== value) {
|
|
553
|
+
return false;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
return true;
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
private handleUpdate(sql: string, params: unknown[]): DbQueryResult {
|
|
561
|
+
const tableName = parseTableName(sql);
|
|
562
|
+
if (!tableName) {
|
|
563
|
+
return { rows: [], rowCount: 0 };
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
const table = this.tables.get(tableName);
|
|
567
|
+
if (!table) {
|
|
568
|
+
return { rows: [], rowCount: 0 };
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
const setMatch = sql.match(/SET (.+?) WHERE/i);
|
|
572
|
+
const assignments = setMatch?.[1]?.split(",") ?? [];
|
|
573
|
+
const whereMatch = sql.match(/WHERE\s+"?(\w+)"?\s*=\s*\$\d+/i);
|
|
574
|
+
const whereColumn = whereMatch?.[1] ?? "id";
|
|
575
|
+
const whereValue = params[params.length - 1];
|
|
576
|
+
|
|
577
|
+
let updated = 0;
|
|
578
|
+
for (const row of table.rows) {
|
|
579
|
+
if (row[whereColumn] !== whereValue) {
|
|
580
|
+
continue;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
if (/AND\s+"?status"?\s*=\s*'pending'/i.test(sql) && row.status !== "pending") {
|
|
584
|
+
continue;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
if (/trace_id\s*=\s*\$\d+\s+AND\s+span_id\s*=\s*\$\d+/i.test(sql)) {
|
|
588
|
+
const traceId = params[params.length - 2];
|
|
589
|
+
const spanId = params[params.length - 1];
|
|
590
|
+
if (row.trace_id !== traceId || row.span_id !== spanId) {
|
|
591
|
+
continue;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
if (
|
|
596
|
+
/status\s+NOT\s+IN\s*\(\s*'completed'\s*,\s*'canceled'\s*,\s*'dead'\s*\)/i.test(sql) &&
|
|
597
|
+
["completed", "canceled", "dead"].includes(String(row.status))
|
|
598
|
+
) {
|
|
599
|
+
continue;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
if (/status\s+IN\s*\(\s*'pending'\s*,\s*'running'\s*\)/i.test(sql) && !["pending", "running"].includes(String(row.status))) {
|
|
603
|
+
continue;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
if (/status\s+IN\s*\(\s*'failed'\s*,\s*'dead'\s*\)/i.test(sql) && !["failed", "dead"].includes(String(row.status))) {
|
|
607
|
+
continue;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
for (const assignment of assignments) {
|
|
611
|
+
const [rawColumn, rawExpression] = assignment.split("=");
|
|
612
|
+
const column = rawColumn?.trim().replace(/"/g, "");
|
|
613
|
+
if (!column) {
|
|
614
|
+
continue;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
const expression = rawExpression?.trim() ?? "";
|
|
618
|
+
const paramMatch = expression.match(/\$(\d+)/);
|
|
619
|
+
const normalizedExpression = expression.replace(/"/g, "").replace(/\s+/g, " ");
|
|
620
|
+
|
|
621
|
+
if (normalizedExpression.toLowerCase() === `${column.toLowerCase()} + 1`) {
|
|
622
|
+
row[column] = Number(row[column] ?? 0) + 1;
|
|
623
|
+
} else if (paramMatch?.[1]) {
|
|
624
|
+
row[column] = params[Number(paramMatch[1]) - 1];
|
|
625
|
+
} else {
|
|
626
|
+
row[column] = parseSqlLiteral(expression, params);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
updated += 1;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
return { rows: [], rowCount: updated };
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
private handleDelete(sql: string, params: unknown[]): DbQueryResult {
|
|
637
|
+
const tableName = parseTableName(sql);
|
|
638
|
+
if (!tableName) {
|
|
639
|
+
return { rows: [], rowCount: 0 };
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
const table = this.tables.get(tableName);
|
|
643
|
+
if (!table) {
|
|
644
|
+
return { rows: [], rowCount: 0 };
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
if (!/WHERE/i.test(sql)) {
|
|
648
|
+
const before = table.rows.length;
|
|
649
|
+
table.rows = [];
|
|
650
|
+
return { rows: [], rowCount: before };
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
if (/WHERE\s+"?status"?\s*=\s*'dead'/i.test(sql)) {
|
|
654
|
+
const before = table.rows.length;
|
|
655
|
+
table.rows = table.rows.filter((row) => row.status !== "dead");
|
|
656
|
+
return { rows: [], rowCount: before - table.rows.length };
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
const id = params[0];
|
|
660
|
+
const before = table.rows.length;
|
|
661
|
+
table.rows = table.rows.filter((row) => row.id !== id);
|
|
662
|
+
return { rows: [], rowCount: before - table.rows.length };
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
async begin(): Promise<DbTransaction> {
|
|
666
|
+
const snapshot = new Map<string, MemoryTable>();
|
|
667
|
+
for (const [name, table] of this.tables) {
|
|
668
|
+
snapshot.set(name, {
|
|
669
|
+
rows: table.rows.map((row) => ({ ...row })),
|
|
670
|
+
nextSerial: table.nextSerial,
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
const sequenceSnapshot = new Map(this.sequences);
|
|
674
|
+
|
|
675
|
+
const adapter = this;
|
|
676
|
+
|
|
677
|
+
return {
|
|
678
|
+
query: (querySql, queryParams) => adapter.query(querySql, queryParams),
|
|
679
|
+
async commit() {
|
|
680
|
+
/* committed in place */
|
|
681
|
+
},
|
|
682
|
+
async rollback() {
|
|
683
|
+
adapter.tables = snapshot;
|
|
684
|
+
adapter.sequences = sequenceSnapshot;
|
|
685
|
+
},
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
async close(): Promise<void> {
|
|
690
|
+
this.tables.clear();
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
private ensureTable(name: string): MemoryTable {
|
|
694
|
+
const existing = this.tables.get(name);
|
|
695
|
+
if (existing) {
|
|
696
|
+
return existing;
|
|
697
|
+
}
|
|
698
|
+
const created = { rows: [], nextSerial: 1 };
|
|
699
|
+
this.tables.set(name, created);
|
|
700
|
+
return created;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
export function createMemoryAdapter(): DbAdapter {
|
|
705
|
+
return new MemoryAdapter();
|
|
706
|
+
}
|