@cchistory/lite 0.4.5 → 0.6.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/INSTALL.md +1 -1
- package/apps/lite-cli/dist/agent-contract.d.ts +7 -5
- package/apps/lite-cli/dist/agent-contract.d.ts.map +1 -1
- package/apps/lite-cli/dist/agent-contract.js +36 -25
- package/apps/lite-cli/dist/agent-contract.js.map +1 -1
- package/apps/lite-cli/dist/bin.js +2 -2
- package/apps/lite-cli/dist/bin.js.map +1 -1
- package/apps/lite-cli/dist/index.d.ts.map +1 -1
- package/apps/lite-cli/dist/index.js +151 -66
- package/apps/lite-cli/dist/index.js.map +1 -1
- package/apps/lite-cli/dist/index.test.js +59 -89
- package/apps/lite-cli/dist/index.test.js.map +1 -1
- package/apps/lite-cli/dist/query.d.ts +4 -1
- package/apps/lite-cli/dist/query.d.ts.map +1 -1
- package/apps/lite-cli/dist/query.js +45 -29
- package/apps/lite-cli/dist/query.js.map +1 -1
- package/apps/lite-cli/dist/resource-errors.d.ts +3 -0
- package/apps/lite-cli/dist/resource-errors.d.ts.map +1 -0
- package/apps/lite-cli/dist/resource-errors.js +17 -0
- package/apps/lite-cli/dist/resource-errors.js.map +1 -0
- package/apps/lite-cli/dist/shell.d.ts +12 -2
- package/apps/lite-cli/dist/shell.d.ts.map +1 -1
- package/apps/lite-cli/dist/shell.js +129 -57
- package/apps/lite-cli/dist/shell.js.map +1 -1
- package/apps/lite-cli/dist/sql-query.test.d.ts +2 -0
- package/apps/lite-cli/dist/sql-query.test.d.ts.map +1 -0
- package/apps/lite-cli/dist/sql-query.test.js +290 -0
- package/apps/lite-cli/dist/sql-query.test.js.map +1 -0
- package/apps/lite-cli/dist/version.d.ts +1 -1
- package/apps/lite-cli/dist/version.js +1 -1
- package/apps/lite-tui/dist/bin.js +2 -2
- package/apps/lite-tui/dist/bin.js.map +1 -1
- package/apps/lite-tui/dist/index.d.ts.map +1 -1
- package/apps/lite-tui/dist/index.js +6 -2
- package/apps/lite-tui/dist/index.js.map +1 -1
- package/apps/lite-tui/dist/index.test.js +10 -8
- package/apps/lite-tui/dist/index.test.js.map +1 -1
- package/apps/lite-tui/dist/render.d.ts +1 -1
- package/apps/lite-tui/dist/version.d.ts +1 -1
- package/apps/lite-tui/dist/version.js +1 -1
- package/bin/cchistory-lite-tui.mjs +2 -2
- package/bin/cchistory-lite.mjs +2 -2
- package/docs/guide/for-agents.md +66 -46
- package/docs/guide/lite.md +53 -11
- package/docs/guide/queries/latest-sessions.sql +4 -0
- package/docs/guide/queries/latest-turns.sql +1 -0
- package/docs/guide/queries/list-sessions.sql +2 -0
- package/docs/guide/query.md +153 -0
- package/node_modules/@cchistory/canonical/dist/directory-scope.d.ts +7 -0
- package/node_modules/@cchistory/canonical/dist/directory-scope.d.ts.map +1 -1
- package/node_modules/@cchistory/canonical/dist/directory-scope.js +11 -0
- package/node_modules/@cchistory/canonical/dist/directory-scope.js.map +1 -1
- package/node_modules/@cchistory/canonical/dist/index.d.ts +5 -1
- package/node_modules/@cchistory/canonical/dist/index.d.ts.map +1 -1
- package/node_modules/@cchistory/canonical/dist/index.js +5 -1
- package/node_modules/@cchistory/canonical/dist/index.js.map +1 -1
- package/node_modules/@cchistory/canonical/dist/query.d.ts +15 -0
- package/node_modules/@cchistory/canonical/dist/query.d.ts.map +1 -0
- package/node_modules/@cchistory/canonical/dist/query.js +208 -0
- package/node_modules/@cchistory/canonical/dist/query.js.map +1 -0
- package/node_modules/@cchistory/canonical/dist/session-family.d.ts +1 -0
- package/node_modules/@cchistory/canonical/dist/session-family.d.ts.map +1 -1
- package/node_modules/@cchistory/canonical/dist/session-family.js +3 -0
- package/node_modules/@cchistory/canonical/dist/session-family.js.map +1 -1
- package/node_modules/@cchistory/canonical/dist/session-family.test.js +61 -0
- package/node_modules/@cchistory/canonical/dist/session-family.test.js.map +1 -1
- package/node_modules/@cchistory/canonical/dist/session-interpreter.d.ts +30 -0
- package/node_modules/@cchistory/canonical/dist/session-interpreter.d.ts.map +1 -0
- package/node_modules/@cchistory/canonical/dist/session-interpreter.js +713 -0
- package/node_modules/@cchistory/canonical/dist/session-interpreter.js.map +1 -0
- package/node_modules/@cchistory/canonical/dist/session-interpreter.test.d.ts +2 -0
- package/node_modules/@cchistory/canonical/dist/session-interpreter.test.d.ts.map +1 -0
- package/node_modules/@cchistory/canonical/dist/session-interpreter.test.js +56 -0
- package/node_modules/@cchistory/canonical/dist/session-interpreter.test.js.map +1 -0
- package/node_modules/@cchistory/canonical/package.json +1 -1
- package/node_modules/@cchistory/domain/dist/evidence-atoms.d.ts +7 -0
- package/node_modules/@cchistory/domain/dist/evidence-atoms.d.ts.map +1 -0
- package/node_modules/@cchistory/domain/dist/evidence-atoms.js +36 -0
- package/node_modules/@cchistory/domain/dist/evidence-atoms.js.map +1 -0
- package/node_modules/@cchistory/domain/dist/evidence-values.d.ts +26 -0
- package/node_modules/@cchistory/domain/dist/evidence-values.d.ts.map +1 -0
- package/node_modules/@cchistory/domain/dist/evidence-values.js +80 -0
- package/node_modules/@cchistory/domain/dist/evidence-values.js.map +1 -0
- package/node_modules/@cchistory/domain/dist/index.d.ts +6 -0
- package/node_modules/@cchistory/domain/dist/index.d.ts.map +1 -1
- package/node_modules/@cchistory/domain/dist/index.js +5 -0
- package/node_modules/@cchistory/domain/dist/index.js.map +1 -1
- package/node_modules/@cchistory/domain/dist/masks.d.ts +31 -0
- package/node_modules/@cchistory/domain/dist/masks.d.ts.map +1 -0
- package/node_modules/@cchistory/domain/dist/masks.js +342 -0
- package/node_modules/@cchistory/domain/dist/masks.js.map +1 -0
- package/node_modules/@cchistory/domain/dist/parsed-session.d.ts +58 -0
- package/node_modules/@cchistory/domain/dist/parsed-session.d.ts.map +1 -0
- package/node_modules/@cchistory/domain/dist/parsed-session.js +2 -0
- package/node_modules/@cchistory/domain/dist/parsed-session.js.map +1 -0
- package/node_modules/@cchistory/domain/dist/query.d.ts +67 -0
- package/node_modules/@cchistory/domain/dist/query.d.ts.map +1 -0
- package/node_modules/@cchistory/domain/dist/query.js +2 -0
- package/node_modules/@cchistory/domain/dist/query.js.map +1 -0
- package/node_modules/@cchistory/domain/dist/token-evidence.d.ts +14 -0
- package/node_modules/@cchistory/domain/dist/token-evidence.d.ts.map +1 -0
- package/node_modules/@cchistory/domain/dist/token-evidence.js +247 -0
- package/node_modules/@cchistory/domain/dist/token-evidence.js.map +1 -0
- package/node_modules/@cchistory/domain/package.json +1 -1
- package/node_modules/@cchistory/live-runtime/dist/bootstrap.d.ts +1 -1
- package/node_modules/@cchistory/live-runtime/dist/bootstrap.d.ts.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/bootstrap.js +1 -1
- package/node_modules/@cchistory/live-runtime/dist/bootstrap.js.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/index.d.ts +30 -9
- package/node_modules/@cchistory/live-runtime/dist/index.d.ts.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/index.js +314 -143
- package/node_modules/@cchistory/live-runtime/dist/index.js.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/index.test.js +177 -20
- package/node_modules/@cchistory/live-runtime/dist/index.test.js.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/launcher-memory.d.ts +12 -0
- package/node_modules/@cchistory/live-runtime/dist/launcher-memory.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/launcher-memory.js +44 -0
- package/node_modules/@cchistory/live-runtime/dist/launcher-memory.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/launcher-memory.test.d.ts +2 -0
- package/node_modules/@cchistory/live-runtime/dist/launcher-memory.test.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/launcher-memory.test.js +20 -0
- package/node_modules/@cchistory/live-runtime/dist/launcher-memory.test.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/live-read-recovery.test.d.ts +2 -0
- package/node_modules/@cchistory/live-runtime/dist/live-read-recovery.test.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/live-read-recovery.test.js +92 -0
- package/node_modules/@cchistory/live-runtime/dist/live-read-recovery.test.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.d.ts +16 -0
- package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.js +55 -0
- package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.test.d.ts +2 -0
- package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.test.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.test.js +192 -0
- package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.test.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.d.ts +22 -22
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.d.ts.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.js +53 -47
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.js.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.test.js +287 -83
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.test.js.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/selective-query.d.ts +47 -0
- package/node_modules/@cchistory/live-runtime/dist/selective-query.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/selective-query.js +15 -0
- package/node_modules/@cchistory/live-runtime/dist/selective-query.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/selective-query.test.d.ts +2 -0
- package/node_modules/@cchistory/live-runtime/dist/selective-query.test.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/selective-query.test.js +171 -0
- package/node_modules/@cchistory/live-runtime/dist/selective-query.test.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-query.d.ts +37 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-query.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-query.js +301 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-query.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-query.test.d.ts +2 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-query.test.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-query.test.js +67 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-query.test.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-worker.d.ts +2 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-worker.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-worker.js +14 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-worker.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/system-memory.d.ts +13 -10
- package/node_modules/@cchistory/live-runtime/dist/system-memory.d.ts.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/system-memory.js +61 -34
- package/node_modules/@cchistory/live-runtime/dist/system-memory.js.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/system-memory.test.d.ts +2 -0
- package/node_modules/@cchistory/live-runtime/dist/system-memory.test.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/system-memory.test.js +76 -0
- package/node_modules/@cchistory/live-runtime/dist/system-memory.test.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/package.json +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/discovery.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/core/discovery.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/factories.d.ts +2 -4
- package/node_modules/@cchistory/source-adapters/dist/core/factories.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/factories.js +1 -23
- package/node_modules/@cchistory/source-adapters/dist/core/factories.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.d.ts +25 -0
- package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.js +81 -0
- package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.test.d.ts +2 -0
- package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.test.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.test.js +122 -0
- package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.test.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/core/git-project.d.ts +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/git-project.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/git-project.js +2 -11
- package/node_modules/@cchistory/source-adapters/dist/core/git-project.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/jsonl-records.test.js +31 -1
- package/node_modules/@cchistory/source-adapters/dist/core/jsonl-records.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/parser.d.ts +4 -3
- package/node_modules/@cchistory/source-adapters/dist/core/parser.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/parser.js +32 -13
- package/node_modules/@cchistory/source-adapters/dist/core/parser.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/probe.d.ts +8 -6
- package/node_modules/@cchistory/source-adapters/dist/core/probe.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/probe.js +46 -45
- package/node_modules/@cchistory/source-adapters/dist/core/probe.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/projections.d.ts +2 -28
- package/node_modules/@cchistory/source-adapters/dist/core/projections.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/projections.js +2 -695
- package/node_modules/@cchistory/source-adapters/dist/core/projections.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/projections.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/core/projections.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/read-budget.d.ts +18 -0
- package/node_modules/@cchistory/source-adapters/dist/core/read-budget.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/core/read-budget.js +27 -0
- package/node_modules/@cchistory/source-adapters/dist/core/read-budget.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/core/read-budget.test.d.ts +2 -0
- package/node_modules/@cchistory/source-adapters/dist/core/read-budget.test.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/core/read-budget.test.js +76 -0
- package/node_modules/@cchistory/source-adapters/dist/core/read-budget.test.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.d.ts +6 -0
- package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/source-identity.d.ts +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/source-identity.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/source-identity.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/source-identity.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/token-usage.d.ts +1 -13
- package/node_modules/@cchistory/source-adapters/dist/core/token-usage.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/token-usage.js +1 -246
- package/node_modules/@cchistory/source-adapters/dist/core/token-usage.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/tokens.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/tokens.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/type-guards.d.ts +1 -25
- package/node_modules/@cchistory/source-adapters/dist/core/type-guards.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/type-guards.js +1 -79
- package/node_modules/@cchistory/source-adapters/dist/core/type-guards.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/types.d.ts +6 -35
- package/node_modules/@cchistory/source-adapters/dist/core/types.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/vscode-state.d.ts +2 -1
- package/node_modules/@cchistory/source-adapters/dist/core/vscode-state.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/vscode-state.js +14 -10
- package/node_modules/@cchistory/source-adapters/dist/core/vscode-state.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/index.d.ts +6 -0
- package/node_modules/@cchistory/source-adapters/dist/index.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/index.js +4 -0
- package/node_modules/@cchistory/source-adapters/dist/index.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/index.test.d.ts +2 -0
- package/node_modules/@cchistory/source-adapters/dist/index.test.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/index.test.js +2 -0
- package/node_modules/@cchistory/source-adapters/dist/index.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/masks.d.ts +1 -30
- package/node_modules/@cchistory/source-adapters/dist/masks.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/masks.js +1 -341
- package/node_modules/@cchistory/source-adapters/dist/masks.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/accio.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/accio.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/amp.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/amp.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/claude.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/claude.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/codebuddy.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/codebuddy.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/codex/activity-evidence.d.ts +14 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/codex/activity-evidence.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/codex/activity-evidence.js +103 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/codex/activity-evidence.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/codex.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/codex.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/cursor/runtime.d.ts +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/cursor/runtime.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/cursor/runtime.js +5 -3
- package/node_modules/@cchistory/source-adapters/dist/platforms/cursor/runtime.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/cursor-agent.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/cursor-agent.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/cursor.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/cursor.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/factory-droid.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/factory-droid.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/gemini.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/gemini.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/grok.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/grok.js +24 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/grok.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/grok.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/grok.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/kimi.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/kimi.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/lobechat.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/lobechat.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/openclaw.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/openclaw.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/opencode.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/opencode.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/zcode/runtime.d.ts +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/zcode/runtime.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/zcode/runtime.js +11 -9
- package/node_modules/@cchistory/source-adapters/dist/platforms/zcode/runtime.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/zcode.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/zcode.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/probe-reference.test.d.ts +8 -0
- package/node_modules/@cchistory/source-adapters/dist/probe-reference.test.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/probe-reference.test.js +7 -0
- package/node_modules/@cchistory/source-adapters/dist/probe-reference.test.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/test-helpers.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/package.json +1 -1
- package/node_modules/commander/LICENSE +22 -0
- package/node_modules/commander/Readme.md +428 -0
- package/node_modules/commander/index.js +1224 -0
- package/node_modules/commander/package.json +38 -0
- package/node_modules/commander/typings/index.d.ts +310 -0
- package/node_modules/discontinuous-range/.npmignore +28 -0
- package/node_modules/discontinuous-range/.travis.yml +4 -0
- package/node_modules/discontinuous-range/LICENSE +21 -0
- package/node_modules/discontinuous-range/README.md +23 -0
- package/node_modules/discontinuous-range/index.js +144 -0
- package/node_modules/discontinuous-range/package.json +27 -0
- package/node_modules/discontinuous-range/test/main-test.js +96 -0
- package/node_modules/moo/LICENSE +29 -0
- package/node_modules/moo/README.md +385 -0
- package/node_modules/moo/moo.js +645 -0
- package/node_modules/moo/package.json +29 -0
- package/node_modules/nearley/LICENSE.txt +21 -0
- package/node_modules/nearley/README.md +80 -0
- package/node_modules/nearley/bin/nearley-railroad.js +121 -0
- package/node_modules/nearley/bin/nearley-test.js +64 -0
- package/node_modules/nearley/bin/nearley-unparse.js +29 -0
- package/node_modules/nearley/bin/nearleyc.js +38 -0
- package/node_modules/nearley/builtin/cow.ne +2 -0
- package/node_modules/nearley/builtin/number.ne +51 -0
- package/node_modules/nearley/builtin/postprocessors.ne +36 -0
- package/node_modules/nearley/builtin/string.ne +26 -0
- package/node_modules/nearley/builtin/whitespace.ne +5 -0
- package/node_modules/nearley/lib/compile.js +307 -0
- package/node_modules/nearley/lib/generate.js +244 -0
- package/node_modules/nearley/lib/lint.js +28 -0
- package/node_modules/nearley/lib/nearley-language-bootstrapped.js +132 -0
- package/node_modules/nearley/lib/nearley-language-bootstrapped.ne +126 -0
- package/node_modules/nearley/lib/nearley.js +564 -0
- package/node_modules/nearley/lib/stream.js +18 -0
- package/node_modules/nearley/lib/unparse.js +139 -0
- package/node_modules/nearley/package.json +63 -0
- package/node_modules/pgsql-ast-parser/ast-mapper.d.ts +237 -0
- package/node_modules/pgsql-ast-parser/ast-mapper.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/ast-mapper.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/ast-mapper.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/ast-visitor.d.ts +33 -0
- package/node_modules/pgsql-ast-parser/ast-visitor.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/ast-visitor.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/ast-visitor.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/index.d.ts +11 -0
- package/node_modules/pgsql-ast-parser/index.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/index.js +6484 -0
- package/node_modules/pgsql-ast-parser/index.js.map +1 -0
- package/node_modules/pgsql-ast-parser/interfaces.d.ts +1 -0
- package/node_modules/pgsql-ast-parser/interfaces.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/keywords.d.ts +2 -0
- package/node_modules/pgsql-ast-parser/keywords.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/lexer.d.ts +15 -0
- package/node_modules/pgsql-ast-parser/lexer.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/lexer.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/lexer.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/array-lexer.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/array-lexer.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/array.ne.d.ts +29 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/array.ne.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/array.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/array.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/geometric-lexer.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/geometric-lexer.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/geometric.ne.d.ts +29 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/geometric.ne.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/geometric.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/geometric.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-builder.d.ts +10 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-builder.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-iso-lexer.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-iso-lexer.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-iso.ne.d.ts +29 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-iso.ne.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-lexer.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-lexer.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval.ne.d.ts +29 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval.ne.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/package.json +69 -0
- package/node_modules/pgsql-ast-parser/parser.d.ts +33 -0
- package/node_modules/pgsql-ast-parser/parser.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/pg-escape.d.ts +2 -0
- package/node_modules/pgsql-ast-parser/pg-escape.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/readme.md +255 -0
- package/node_modules/pgsql-ast-parser/src/ast-mapper.spec.ts +296 -0
- package/node_modules/pgsql-ast-parser/src/ast-mapper.ts +1378 -0
- package/node_modules/pgsql-ast-parser/src/ast-visitor.spec.ts +57 -0
- package/node_modules/pgsql-ast-parser/src/ast-visitor.ts +101 -0
- package/node_modules/pgsql-ast-parser/src/index.ts +10 -0
- package/node_modules/pgsql-ast-parser/src/interfaces.ts +0 -0
- package/node_modules/pgsql-ast-parser/src/keywords.ts +8 -0
- package/node_modules/pgsql-ast-parser/src/lexer.spec.ts +245 -0
- package/node_modules/pgsql-ast-parser/src/lexer.ts +267 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/array-lexer.ts +27 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/array.ne +18 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/array.spec.ts +55 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/geometric-lexer.ts +26 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/geometric.ne +88 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/geometric.spec.ts +131 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/interval-builder.ts +148 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/interval-iso-lexer.ts +17 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/interval-iso.ne +53 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/interval-lexer.ts +26 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/interval.ne +54 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/interval.spec.ts +106 -0
- package/node_modules/pgsql-ast-parser/src/parser.ts +142 -0
- package/node_modules/pgsql-ast-parser/src/pg-escape.ts +14 -0
- package/node_modules/pgsql-ast-parser/src/syntax/alter-index.ne +29 -0
- package/node_modules/pgsql-ast-parser/src/syntax/alter-index.spec.ts +35 -0
- package/node_modules/pgsql-ast-parser/src/syntax/alter-table.ne +123 -0
- package/node_modules/pgsql-ast-parser/src/syntax/alter-table.spec.ts +476 -0
- package/node_modules/pgsql-ast-parser/src/syntax/alter-type.ne +33 -0
- package/node_modules/pgsql-ast-parser/src/syntax/alter-type.spec.ts +29 -0
- package/node_modules/pgsql-ast-parser/src/syntax/ast.ts +1150 -0
- package/node_modules/pgsql-ast-parser/src/syntax/base.ne +369 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-extension.ne +17 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-extension.spec.ts +37 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-index.ne +62 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-index.spec.ts +245 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-table.ne +174 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-table.spec.ts +761 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-type.ne +40 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-type.spec.ts +32 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-view.ne +68 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-view.spec.ts +187 -0
- package/node_modules/pgsql-ast-parser/src/syntax/deallocate.ne +13 -0
- package/node_modules/pgsql-ast-parser/src/syntax/deallocate.spec.ts +19 -0
- package/node_modules/pgsql-ast-parser/src/syntax/delete.ne +36 -0
- package/node_modules/pgsql-ast-parser/src/syntax/delete.spec.ts +71 -0
- package/node_modules/pgsql-ast-parser/src/syntax/drop.ne +28 -0
- package/node_modules/pgsql-ast-parser/src/syntax/drop.spec.ts +77 -0
- package/node_modules/pgsql-ast-parser/src/syntax/edge-cases.spec.ts +41 -0
- package/node_modules/pgsql-ast-parser/src/syntax/expr.ne +350 -0
- package/node_modules/pgsql-ast-parser/src/syntax/expr.spec.ts +1638 -0
- package/node_modules/pgsql-ast-parser/src/syntax/functions.ne +114 -0
- package/node_modules/pgsql-ast-parser/src/syntax/functions.spec.ts +235 -0
- package/node_modules/pgsql-ast-parser/src/syntax/insert.ne +63 -0
- package/node_modules/pgsql-ast-parser/src/syntax/insert.spec.ts +292 -0
- package/node_modules/pgsql-ast-parser/src/syntax/main.ne +77 -0
- package/node_modules/pgsql-ast-parser/src/syntax/nearley.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/src/syntax/prepare.ne +8 -0
- package/node_modules/pgsql-ast-parser/src/syntax/prepare.spec.ts +44 -0
- package/node_modules/pgsql-ast-parser/src/syntax/refresh-materialized-view.ne +19 -0
- package/node_modules/pgsql-ast-parser/src/syntax/refresh-materialized-view.spec.ts +42 -0
- package/node_modules/pgsql-ast-parser/src/syntax/select.ne +223 -0
- package/node_modules/pgsql-ast-parser/src/syntax/select.spec.ts +1063 -0
- package/node_modules/pgsql-ast-parser/src/syntax/sequence.ne +101 -0
- package/node_modules/pgsql-ast-parser/src/syntax/sequence.spec.ts +103 -0
- package/node_modules/pgsql-ast-parser/src/syntax/simple-statements.ne +168 -0
- package/node_modules/pgsql-ast-parser/src/syntax/simple-statements.spec.ts +327 -0
- package/node_modules/pgsql-ast-parser/src/syntax/spec-utils.ts +333 -0
- package/node_modules/pgsql-ast-parser/src/syntax/union.ne +18 -0
- package/node_modules/pgsql-ast-parser/src/syntax/union.spec.ts +125 -0
- package/node_modules/pgsql-ast-parser/src/syntax/update.ne +56 -0
- package/node_modules/pgsql-ast-parser/src/syntax/update.spec.ts +87 -0
- package/node_modules/pgsql-ast-parser/src/syntax/with.ne +41 -0
- package/node_modules/pgsql-ast-parser/src/syntax/with.spec.ts +155 -0
- package/node_modules/pgsql-ast-parser/src/to-sql.spec.ts +85 -0
- package/node_modules/pgsql-ast-parser/src/to-sql.ts +1555 -0
- package/node_modules/pgsql-ast-parser/src/utils.ts +47 -0
- package/node_modules/pgsql-ast-parser/syntax/alter-index.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/alter-index.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/alter-table.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/alter-table.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/alter-type.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/alter-type.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/ast.d.ts +826 -0
- package/node_modules/pgsql-ast-parser/syntax/ast.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/create-extension.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/create-extension.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/create-index.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/create-index.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/create-table.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/create-table.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/create-type.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/create-type.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/create-view.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/create-view.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/deallocate.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/deallocate.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/delete.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/delete.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/drop.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/drop.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/edge-cases.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/edge-cases.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/expr.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/expr.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/functions.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/functions.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/insert.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/insert.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/main.ne.d.ts +29 -0
- package/node_modules/pgsql-ast-parser/syntax/main.ne.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/prepare.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/prepare.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/refresh-materialized-view.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/refresh-materialized-view.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/select.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/select.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/sequence.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/sequence.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/simple-statements.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/simple-statements.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/spec-utils.d.ts +35 -0
- package/node_modules/pgsql-ast-parser/syntax/spec-utils.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/union.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/union.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/update.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/update.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/with.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/with.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/to-sql.d.ts +7 -0
- package/node_modules/pgsql-ast-parser/to-sql.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/to-sql.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/to-sql.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/utils.d.ts +16 -0
- package/node_modules/pgsql-ast-parser/utils.d.ts.map +1 -0
- package/node_modules/railroad-diagrams/.gitattributes +22 -0
- package/node_modules/railroad-diagrams/.npmignore +163 -0
- package/node_modules/railroad-diagrams/README.md +86 -0
- package/node_modules/railroad-diagrams/css-example.py-js +183 -0
- package/node_modules/railroad-diagrams/example.html +141 -0
- package/node_modules/railroad-diagrams/generator.html +59 -0
- package/node_modules/railroad-diagrams/package.json +23 -0
- package/node_modules/railroad-diagrams/railroad-diagrams.css +23 -0
- package/node_modules/railroad-diagrams/railroad-diagrams.js +524 -0
- package/node_modules/railroad-diagrams/railroad_diagrams.py +427 -0
- package/node_modules/randexp/LICENSE +19 -0
- package/node_modules/randexp/README.md +134 -0
- package/node_modules/randexp/lib/randexp.js +245 -0
- package/node_modules/randexp/package.json +48 -0
- package/node_modules/ret/LICENSE +19 -0
- package/node_modules/ret/README.md +183 -0
- package/node_modules/ret/lib/index.js +282 -0
- package/node_modules/ret/lib/positions.js +17 -0
- package/node_modules/ret/lib/sets.js +82 -0
- package/node_modules/ret/lib/types.js +10 -0
- package/node_modules/ret/lib/util.js +111 -0
- package/node_modules/ret/package.json +35 -0
- package/package.json +22 -6
- package/schemas/cchistory-lite-agent-v1.schema.json +6 -7
- package/schemas/cchistory-lite-error-v1.schema.json +58 -8
- package/schemas/cchistory-lite-query-result-v2.schema.json +66 -11
- package/schemas/cchistory-lite-query-result-v3.schema.json +219 -0
- package/schemas/cchistory-lite-query-v3.schema.json +57 -0
- package/schemas/cchistory-lite-source-inventory-v1.schema.json +72 -0
- package/skills/using-cchistory-lite/SKILL.md +126 -55
- package/node_modules/@cchistory/live-runtime/dist/node-memory.d.ts +0 -8
- package/node_modules/@cchistory/live-runtime/dist/node-memory.d.ts.map +0 -1
- package/node_modules/@cchistory/live-runtime/dist/node-memory.js +0 -110
- package/node_modules/@cchistory/live-runtime/dist/node-memory.js.map +0 -1
|
@@ -0,0 +1,1378 @@
|
|
|
1
|
+
import * as a from './syntax/ast';
|
|
2
|
+
import { nil, NotSupported, trimNullish } from './utils';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export interface IAstPartialMapper {
|
|
7
|
+
statement?: (val: a.Statement) => a.Statement | nil;
|
|
8
|
+
update?: (val: a.UpdateStatement) => a.Statement | nil
|
|
9
|
+
insert?: (val: a.InsertStatement) => a.Statement | nil
|
|
10
|
+
delete?: (val: a.DeleteStatement) => a.Statement | nil
|
|
11
|
+
comment?: (val: a.CommentStatement) => a.Statement | nil
|
|
12
|
+
do?: (val: a.DoStatement) => a.Statement | nil
|
|
13
|
+
createFunction?: (val: a.CreateFunctionStatement) => a.Statement | nil
|
|
14
|
+
dropFunction?: (val: a.DropFunctionStatement) => a.Statement | nil
|
|
15
|
+
raise?: (val: a.RaiseStatement) => a.Statement | nil
|
|
16
|
+
createSchema?: (val: a.CreateSchemaStatement) => a.Statement | nil
|
|
17
|
+
createEnum?(val: a.CreateEnumType): a.Statement | nil
|
|
18
|
+
alterEnum?(val: a.AlterEnumType): a.Statement | nil
|
|
19
|
+
createCompositeType?(val: a.CreateCompositeType): a.Statement | nil
|
|
20
|
+
drop?: (val: a.DropStatement) => a.Statement | nil
|
|
21
|
+
show?: (val: a.ShowStatement) => a.Statement | nil
|
|
22
|
+
createTable?: (val: a.CreateTableStatement) => a.Statement | nil
|
|
23
|
+
truncateTable?: (val: a.TruncateTableStatement) => a.Statement | nil
|
|
24
|
+
createExtension?: (val: a.CreateExtensionStatement) => a.Statement | nil
|
|
25
|
+
set?: (st: a.SetStatement) => a.SetStatement | nil
|
|
26
|
+
dataType?: (dataType: a.DataTypeDef) => a.DataTypeDef
|
|
27
|
+
prepare?: (st: a.PrepareStatement) => a.Statement | nil
|
|
28
|
+
deallocate?: (st: a.DeallocateStatement) => a.Statement | nil
|
|
29
|
+
parameter?: (st: a.ExprParameter) => a.Expr | nil
|
|
30
|
+
tableRef?: (st: a.QNameAliased) => a.QNameAliased | nil
|
|
31
|
+
transaction?: (val: a.CommitStatement | a.RollbackStatement | a.StartTransactionStatement) => a.Statement | nil
|
|
32
|
+
createIndex?: (val: a.CreateIndexStatement) => a.Statement | nil
|
|
33
|
+
alterTable?: (st: a.AlterTableStatement) => a.Statement | nil
|
|
34
|
+
alterIndex?: (st: a.AlterIndexStatement) => a.Statement | nil
|
|
35
|
+
tableAlteration?: (change: a.TableAlteration, table: a.QNameAliased) => a.TableAlteration | nil
|
|
36
|
+
dropColumn?: (change: a.TableAlterationDropColumn, table: a.QNameAliased) => a.TableAlteration | nil
|
|
37
|
+
dropConstraint?: (change: a.TableAlterationDropConstraint, table: a.QNameAliased) => a.TableAlteration | nil
|
|
38
|
+
renameConstraint?: (change: a.TableAlterationRenameConstraint, table: a.QNameAliased) => a.TableAlteration | nil
|
|
39
|
+
setTableOwner?: (change: a.TableAlterationOwner, table: a.QNameAliased) => a.TableAlteration | nil
|
|
40
|
+
renameColumn?: (change: a.TableAlterationRenameColumn, table: a.QNameAliased) => a.TableAlteration | nil
|
|
41
|
+
renameTable?: (change: a.TableAlterationRename, table: a.QNameAliased) => a.TableAlteration | nil
|
|
42
|
+
alterColumn?: (change: a.TableAlterationAlterColumn, inTable: a.QNameAliased) => a.TableAlteration | nil
|
|
43
|
+
setColumnType?: (alter: a.AlterColumnSetType, inTable: a.QName, inColumn: a.Name) => a.AlterColumn | nil
|
|
44
|
+
alterColumnSimple?: (alter: a.AlterColumnSimple, inTable: a.QName, inColumn: a.Name) => a.AlterColumn | nil
|
|
45
|
+
alterColumnAddGenerated?: (alter: a.AlterColumnAddGenerated, inTable: a.QName, inColumn: a.Name) => a.AlterColumn | nil
|
|
46
|
+
setColumnDefault?: (alter: a.AlterColumnSetDefault, inTable: a.QName, inColumn: a.Name) => a.AlterColumn | nil
|
|
47
|
+
addConstraint?: (change: a.TableAlterationAddConstraint, inTable: a.QName) => a.TableAlteration | nil
|
|
48
|
+
addColumn?: (change: a.TableAlterationAddColumn, inTable: a.QName) => a.TableAlteration | nil
|
|
49
|
+
createColumn?: (col: a.CreateColumnDef) => a.CreateColumnDef | nil
|
|
50
|
+
likeTable?: (col: a.CreateColumnsLikeTable) => a.CreateColumnDef | a.CreateColumnsLikeTable | nil
|
|
51
|
+
with?: (val: a.WithStatement) => a.SelectStatement | nil
|
|
52
|
+
withRecursive?: (val: a.WithRecursiveStatement) => a.SelectStatement | nil;
|
|
53
|
+
union?: (val: a.SelectFromUnion) => a.SelectStatement | nil
|
|
54
|
+
select?: (val: a.SelectStatement) => a.SelectStatement | nil
|
|
55
|
+
selection?: (val: a.SelectFromStatement) => a.SelectStatement | nil
|
|
56
|
+
createView?: (val: a.CreateViewStatement) => a.Statement | nil
|
|
57
|
+
createMaterializedView?: (val: a.CreateMaterializedViewStatement) => a.Statement | nil
|
|
58
|
+
refreshMaterializedView?: (val: a.RefreshMaterializedViewStatement) => a.Statement | nil
|
|
59
|
+
from?: (from: a.From) => a.From | nil
|
|
60
|
+
fromCall?: (from: a.FromCall) => a.From | nil
|
|
61
|
+
fromStatement?: (from: a.FromStatement) => a.From | nil
|
|
62
|
+
values?: (from: a.ValuesStatement) => a.SelectStatement | nil;
|
|
63
|
+
fromTable?: (from: a.FromTable) => a.From | nil
|
|
64
|
+
selectionColumn?: (val: a.SelectedColumn) => a.SelectedColumn | nil
|
|
65
|
+
expr?: (val: a.Expr) => a.Expr | nil
|
|
66
|
+
ternary?: (val: a.ExprTernary) => a.Expr | nil
|
|
67
|
+
arraySelect?: (val: a.ExprArrayFromSelect) => a.Expr | nil
|
|
68
|
+
arrayIndex?: (val: a.ExprArrayIndex) => a.Expr | nil
|
|
69
|
+
member?: (val: a.ExprMember) => a.Expr | nil
|
|
70
|
+
extract?: (st: a.ExprExtract) => a.Expr | nil
|
|
71
|
+
case?: (val: a.ExprCase) => a.Expr | nil
|
|
72
|
+
cast?: (val: a.ExprCast) => a.Expr | nil
|
|
73
|
+
call?: (val: a.ExprCall) => a.Expr | nil
|
|
74
|
+
callSubstring?: (val: a.ExprSubstring) => a.Expr | nil
|
|
75
|
+
callOverlay?: (val: a.ExprOverlay) => a.Expr | nil
|
|
76
|
+
array?: (val: a.ExprList) => a.Expr | nil
|
|
77
|
+
constant?: (value: a.ExprLiteral) => a.Expr | nil
|
|
78
|
+
default?: (value: a.ExprDefault) => a.Expr | nil;
|
|
79
|
+
ref?: (val: a.ExprRef) => a.Expr | nil
|
|
80
|
+
unary?: (val: a.ExprUnary) => a.Expr | nil
|
|
81
|
+
binary?: (val: a.ExprBinary) => a.Expr | nil
|
|
82
|
+
join?(join: a.JoinClause): a.JoinClause | nil
|
|
83
|
+
constraint?: (constraint: a.ColumnConstraint) => a.ColumnConstraint | nil
|
|
84
|
+
valueKeyword?(val: a.ExprValueKeyword): a.Expr | nil
|
|
85
|
+
tablespace?(val: a.TablespaceStatement): a.Statement | nil
|
|
86
|
+
setGlobal?(val: a.SetGlobalStatement): a.Statement | nil
|
|
87
|
+
setTimezone?(val: a.SetTimezone): a.Statement | nil
|
|
88
|
+
setNames?(val: a.SetNames): a.Statement | nil
|
|
89
|
+
createSequence?(seq: a.CreateSequenceStatement): a.Statement | nil
|
|
90
|
+
alterSequence?(seq: a.AlterSequenceStatement): a.Statement | nil
|
|
91
|
+
begin?(begin: a.BeginStatement): a.Statement | nil
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export type IAstFullMapper = {
|
|
95
|
+
[key in keyof IAstPartialMapper]-?: IAstPartialMapper[key];
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export type IAstMapper = IAstFullMapper & {
|
|
99
|
+
/** Forces the next call to use the default implementation, not yours */
|
|
100
|
+
super(): IAstMapper;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Builds an AST modifier based on the default implementation, merged with the one you provide.
|
|
106
|
+
*
|
|
107
|
+
* Example of a modifier that renames all reference to columns 'foo' to 'bar'
|
|
108
|
+
* ```ts
|
|
109
|
+
* const mapper = astMapper(b => ({
|
|
110
|
+
* ref: a => assignChanged(a, {
|
|
111
|
+
* name: a.name === 'foo'
|
|
112
|
+
* ? 'bar'
|
|
113
|
+
* : a.name
|
|
114
|
+
* })
|
|
115
|
+
* }));
|
|
116
|
+
*
|
|
117
|
+
* const modified = mapper.statement(myStatementToModify);
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export function astMapper(modifierBuilder: MapperBuilder): IAstMapper {
|
|
121
|
+
const instance = new AstDefaultMapper();
|
|
122
|
+
instance.wrapped = modifierBuilder(instance);
|
|
123
|
+
return instance;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export type MapperBuilder = (defaultImplem: IAstMapper) => IAstPartialMapper;
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
type PartialNil<T> = {
|
|
131
|
+
[P in keyof T]?: T[P] | nil;
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* An helper function that returns a copy of an object with modified properties
|
|
135
|
+
* (similar to Object.assign()), but ONLY if thos properties have changed.
|
|
136
|
+
* Will return the original object if not.
|
|
137
|
+
*/
|
|
138
|
+
export function assignChanged<T>(orig: T, assign: PartialNil<T>): T {
|
|
139
|
+
if (!orig) {
|
|
140
|
+
return orig;
|
|
141
|
+
}
|
|
142
|
+
let changed = false;
|
|
143
|
+
for (const k of Object.keys(assign)) {
|
|
144
|
+
if ((orig as any)[k] !== (assign as any)[k]) {
|
|
145
|
+
changed = true;
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (!changed) {
|
|
150
|
+
return orig;
|
|
151
|
+
}
|
|
152
|
+
return trimNullish({
|
|
153
|
+
...orig,
|
|
154
|
+
...assign,
|
|
155
|
+
}, 0);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* An helper function that returns a map of an array, but:
|
|
160
|
+
* - It will return the original array if it is null-ish
|
|
161
|
+
* - It will remove all null-ish entries
|
|
162
|
+
* - It will return the original array if nothing has changed
|
|
163
|
+
*/
|
|
164
|
+
export function arrayNilMap<T extends Object>(this: void, collection: T[] | nil, mapper: (v: T) => T | nil): T[] | nil {
|
|
165
|
+
if (!collection?.length) {
|
|
166
|
+
return collection;
|
|
167
|
+
}
|
|
168
|
+
let changed = false;
|
|
169
|
+
let ret: T[] = collection;
|
|
170
|
+
for (let i = 0; i < collection.length; i++) {
|
|
171
|
+
const orig = collection[i];
|
|
172
|
+
const val = mapper(orig);
|
|
173
|
+
if (!changed && (!val || val !== orig)) {
|
|
174
|
+
changed = true;
|
|
175
|
+
ret = collection.slice(0, i);
|
|
176
|
+
}
|
|
177
|
+
if (!val) {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
if (changed) {
|
|
181
|
+
ret.push(val);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return ret;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function withAccepts(val: a.Statement | nil): val is a.WithStatementBinding {
|
|
188
|
+
switch (val?.type) {
|
|
189
|
+
case 'select':
|
|
190
|
+
case 'delete':
|
|
191
|
+
case 'insert':
|
|
192
|
+
case 'update':
|
|
193
|
+
case 'union':
|
|
194
|
+
case 'union all':
|
|
195
|
+
case 'with':
|
|
196
|
+
return true;
|
|
197
|
+
default:
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Can be used to modify an AST.
|
|
204
|
+
*
|
|
205
|
+
* You will have to override functions that you're interested in to use this class.
|
|
206
|
+
*
|
|
207
|
+
* Example: Will remove all references in
|
|
208
|
+
*/
|
|
209
|
+
export class AstDefaultMapper implements IAstMapper {
|
|
210
|
+
|
|
211
|
+
wrapped?: IAstPartialMapper;
|
|
212
|
+
skipNext?: boolean;
|
|
213
|
+
|
|
214
|
+
super() {
|
|
215
|
+
return new SkipModifier(this);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
statement(val: a.Statement): a.Statement | nil {
|
|
219
|
+
switch (val.type) {
|
|
220
|
+
case 'alter table':
|
|
221
|
+
return this.alterTable(val);
|
|
222
|
+
case 'alter index':
|
|
223
|
+
return this.alterIndex(val);
|
|
224
|
+
case 'commit':
|
|
225
|
+
case 'start transaction':
|
|
226
|
+
case 'rollback':
|
|
227
|
+
return this.transaction(val);
|
|
228
|
+
case 'create index':
|
|
229
|
+
return this.createIndex(val);
|
|
230
|
+
case 'create table':
|
|
231
|
+
return this.createTable(val);
|
|
232
|
+
case 'truncate table':
|
|
233
|
+
return this.truncateTable(val);
|
|
234
|
+
case 'delete':
|
|
235
|
+
return this.delete(val);
|
|
236
|
+
case 'insert':
|
|
237
|
+
return this.insert(val);
|
|
238
|
+
case 'with':
|
|
239
|
+
return this.with(val);
|
|
240
|
+
case 'with recursive':
|
|
241
|
+
return this.withRecursive(val);
|
|
242
|
+
case 'select':
|
|
243
|
+
return this.selection(val);
|
|
244
|
+
case 'update':
|
|
245
|
+
return this.update(val);
|
|
246
|
+
case 'create extension':
|
|
247
|
+
return this.createExtension(val);
|
|
248
|
+
case 'tablespace':
|
|
249
|
+
return this.tablespace(val);
|
|
250
|
+
case 'set':
|
|
251
|
+
return this.setGlobal(val);
|
|
252
|
+
case 'set timezone':
|
|
253
|
+
return this.setTimezone(val);
|
|
254
|
+
case 'set names':
|
|
255
|
+
return this.setNames(val);
|
|
256
|
+
case 'create sequence':
|
|
257
|
+
return this.createSequence(val);
|
|
258
|
+
case 'alter sequence':
|
|
259
|
+
return this.alterSequence(val);
|
|
260
|
+
case 'begin':
|
|
261
|
+
return this.begin(val);
|
|
262
|
+
case 'drop table':
|
|
263
|
+
case 'drop index':
|
|
264
|
+
case 'drop sequence':
|
|
265
|
+
case 'drop type':
|
|
266
|
+
case 'drop trigger':
|
|
267
|
+
return this.drop(val);
|
|
268
|
+
case 'create enum':
|
|
269
|
+
return this.createEnum(val);
|
|
270
|
+
case 'alter enum':
|
|
271
|
+
return this.alterEnum(val);
|
|
272
|
+
case 'create composite type':
|
|
273
|
+
return this.createCompositeType(val);
|
|
274
|
+
case 'union':
|
|
275
|
+
case 'union all':
|
|
276
|
+
return this.union(val);
|
|
277
|
+
case 'show':
|
|
278
|
+
return this.show(val);
|
|
279
|
+
case 'prepare':
|
|
280
|
+
return this.prepare(val);
|
|
281
|
+
case 'deallocate':
|
|
282
|
+
return this.deallocate(val);
|
|
283
|
+
case 'create view':
|
|
284
|
+
return this.createView(val);
|
|
285
|
+
case 'create materialized view':
|
|
286
|
+
return this.createMaterializedView(val);
|
|
287
|
+
case 'refresh materialized view':
|
|
288
|
+
return this.refreshMaterializedView(val);
|
|
289
|
+
case 'create schema':
|
|
290
|
+
return this.createSchema(val);
|
|
291
|
+
case 'raise':
|
|
292
|
+
return this.raise(val);
|
|
293
|
+
case 'comment':
|
|
294
|
+
return this.comment(val);
|
|
295
|
+
case 'do':
|
|
296
|
+
return this.do(val);
|
|
297
|
+
case 'create function':
|
|
298
|
+
return this.createFunction(val);
|
|
299
|
+
case 'drop function':
|
|
300
|
+
return this.dropFunction(val);
|
|
301
|
+
case 'values':
|
|
302
|
+
return this.values(val);
|
|
303
|
+
default:
|
|
304
|
+
throw NotSupported.never(val);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
comment(val: a.CommentStatement): a.Statement | nil {
|
|
309
|
+
// not really supported :/
|
|
310
|
+
return val;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
createView(val: a.CreateViewStatement): a.Statement | nil {
|
|
314
|
+
const query = this.select(val.query);
|
|
315
|
+
if (!query) {
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
const ref = this.tableRef(val.name);
|
|
319
|
+
if (!ref) {
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
return assignChanged(val, {
|
|
323
|
+
query,
|
|
324
|
+
name: ref,
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
createMaterializedView(val: a.CreateMaterializedViewStatement): a.Statement | nil {
|
|
329
|
+
const query = this.select(val.query);
|
|
330
|
+
if (!query) {
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
333
|
+
const ref = this.tableRef(val.name);
|
|
334
|
+
if (!ref) {
|
|
335
|
+
return null;
|
|
336
|
+
}
|
|
337
|
+
return assignChanged(val, {
|
|
338
|
+
query,
|
|
339
|
+
name: ref,
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
refreshMaterializedView(val: a.RefreshMaterializedViewStatement): a.Statement | nil {
|
|
344
|
+
return val;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
do(val: a.DoStatement): a.Statement | nil {
|
|
349
|
+
return val;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
createFunction(val: a.CreateFunctionStatement): a.Statement | nil {
|
|
353
|
+
// process arguments
|
|
354
|
+
const args = arrayNilMap(val.arguments, a => {
|
|
355
|
+
const type = this.dataType(a.type);
|
|
356
|
+
return assignChanged(a, { type });
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
// process return type
|
|
360
|
+
let returns: typeof val.returns;
|
|
361
|
+
if (val.returns) {
|
|
362
|
+
switch (val.returns.kind) {
|
|
363
|
+
case 'table':
|
|
364
|
+
returns = assignChanged(val.returns, {
|
|
365
|
+
columns: arrayNilMap(val.returns.columns, v => {
|
|
366
|
+
const type = this.dataType(v.type);
|
|
367
|
+
return type && assignChanged(v, { type })
|
|
368
|
+
})
|
|
369
|
+
});
|
|
370
|
+
break;
|
|
371
|
+
case undefined:
|
|
372
|
+
case null:
|
|
373
|
+
case 'array':
|
|
374
|
+
returns = this.dataType(val.returns);
|
|
375
|
+
break;
|
|
376
|
+
default:
|
|
377
|
+
throw NotSupported.never(val.returns);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return assignChanged(val, {
|
|
381
|
+
returns,
|
|
382
|
+
arguments: args,
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
dropFunction(val: a.DropFunctionStatement): a.Statement | nil {
|
|
387
|
+
const args = arrayNilMap(val.arguments, a => {
|
|
388
|
+
const type = this.dataType(a.type);
|
|
389
|
+
return assignChanged(a, { type });
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
return assignChanged(val, {
|
|
393
|
+
arguments: args,
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
show(val: a.ShowStatement): a.Statement | nil {
|
|
398
|
+
return val;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
createEnum(val: a.CreateEnumType): a.Statement | nil {
|
|
402
|
+
return val;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
alterEnum(val: a.AlterEnumType): a.Statement | nil {
|
|
406
|
+
return val;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
createCompositeType(val: a.CreateCompositeType): a.Statement | nil {
|
|
410
|
+
const attributes = arrayNilMap(val.attributes, a => assignChanged(a, {
|
|
411
|
+
dataType: this.dataType(a.dataType),
|
|
412
|
+
}));
|
|
413
|
+
return assignChanged(val, { attributes });
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
drop(val: a.DropStatement): a.Statement | nil {
|
|
418
|
+
return val;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
alterSequence(seq: a.AlterSequenceStatement): a.Statement | nil {
|
|
422
|
+
if (seq.change.type === 'set options') {
|
|
423
|
+
if (seq.change.as) {
|
|
424
|
+
this.dataType(seq.change.as);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return seq;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
begin(begin: a.BeginStatement): a.Statement | nil {
|
|
431
|
+
return begin;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
createSequence(seq: a.CreateSequenceStatement): a.Statement | nil {
|
|
435
|
+
if (seq.options.as) {
|
|
436
|
+
this.dataType(seq.options.as);
|
|
437
|
+
}
|
|
438
|
+
return seq;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
tablespace(val: a.TablespaceStatement): a.Statement | nil {
|
|
442
|
+
return val;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
setGlobal(val: a.SetGlobalStatement): a.Statement | nil {
|
|
446
|
+
return val;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
setTimezone(val: a.SetTimezone): a.Statement | nil {
|
|
450
|
+
return val;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
setNames(val: a.SetNames): a.Statement | nil {
|
|
454
|
+
return val;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
update(val: a.UpdateStatement): a.Statement | nil {
|
|
458
|
+
if (!val) {
|
|
459
|
+
return val;
|
|
460
|
+
}
|
|
461
|
+
const table = this.tableRef(val.table);
|
|
462
|
+
if (!table) {
|
|
463
|
+
return null; // nothing to update
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
const from = val.from && this.from(val.from);
|
|
467
|
+
|
|
468
|
+
const where = val.where && this.expr(val.where);
|
|
469
|
+
|
|
470
|
+
const sets = arrayNilMap(val.sets, x => this.set(x));
|
|
471
|
+
if (!sets?.length) {
|
|
472
|
+
return null; // nothing to update
|
|
473
|
+
}
|
|
474
|
+
const returning = arrayNilMap(val.returning, c => this.selectionColumn(c));
|
|
475
|
+
|
|
476
|
+
return assignChanged(val, {
|
|
477
|
+
table,
|
|
478
|
+
where,
|
|
479
|
+
sets,
|
|
480
|
+
from,
|
|
481
|
+
returning,
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
insert(val: a.InsertStatement): a.Statement | nil {
|
|
487
|
+
const into = this.tableRef(val.into);
|
|
488
|
+
if (!into) {
|
|
489
|
+
return null; // nowhere to insert into
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
const select = val.insert && this.select(val.insert);
|
|
493
|
+
|
|
494
|
+
if (!select) {
|
|
495
|
+
// nothing to insert
|
|
496
|
+
return null;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
const returning = arrayNilMap(val.returning, c => this.selectionColumn(c));
|
|
500
|
+
let on = val.onConflict?.on;
|
|
501
|
+
switch (on?.type) {
|
|
502
|
+
case 'on constraint':
|
|
503
|
+
// nothing to do
|
|
504
|
+
break;
|
|
505
|
+
case 'on expr':
|
|
506
|
+
on = assignChanged(on, {
|
|
507
|
+
exprs: arrayNilMap(on.exprs, e => this.expr(e)),
|
|
508
|
+
});
|
|
509
|
+
break;
|
|
510
|
+
case null:
|
|
511
|
+
case undefined:
|
|
512
|
+
break;
|
|
513
|
+
default:
|
|
514
|
+
throw NotSupported.never(on);
|
|
515
|
+
}
|
|
516
|
+
let ocdo = val.onConflict?.do;
|
|
517
|
+
if (ocdo && ocdo !== 'do nothing') {
|
|
518
|
+
const sets = arrayNilMap(ocdo.sets, x => this.set(x));
|
|
519
|
+
if (!sets?.length) {
|
|
520
|
+
ocdo = 'do nothing';
|
|
521
|
+
} else if (ocdo.sets !== sets) {
|
|
522
|
+
ocdo = { sets };
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
return assignChanged(val, {
|
|
527
|
+
into,
|
|
528
|
+
insert: select,
|
|
529
|
+
returning,
|
|
530
|
+
onConflict: !ocdo ? val.onConflict : assignChanged(val.onConflict, {
|
|
531
|
+
do: ocdo,
|
|
532
|
+
on,
|
|
533
|
+
}),
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
raise(val: a.RaiseStatement): a.Statement | nil {
|
|
539
|
+
return assignChanged(val, {
|
|
540
|
+
formatExprs: val.formatExprs && arrayNilMap(val.formatExprs, x => this.expr(x)),
|
|
541
|
+
using: val.using && arrayNilMap(val.using, u => {
|
|
542
|
+
return assignChanged(u, {
|
|
543
|
+
value: this.expr(u.value),
|
|
544
|
+
})
|
|
545
|
+
}),
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
delete(val: a.DeleteStatement): a.Statement | nil {
|
|
551
|
+
const from = this.tableRef(val.from);
|
|
552
|
+
if (!from) {
|
|
553
|
+
return null; // nothing to delete
|
|
554
|
+
}
|
|
555
|
+
const where = val.where && this.expr(val.where);
|
|
556
|
+
const returning = arrayNilMap(val.returning, c => this.selectionColumn(c));
|
|
557
|
+
|
|
558
|
+
return assignChanged(val, {
|
|
559
|
+
where,
|
|
560
|
+
returning,
|
|
561
|
+
from,
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
createSchema(val: a.CreateSchemaStatement): a.Statement | nil {
|
|
566
|
+
return val;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
createTable(val: a.CreateTableStatement): a.Statement | nil {
|
|
570
|
+
const columns = arrayNilMap(val.columns, col => {
|
|
571
|
+
switch (col.kind) {
|
|
572
|
+
case 'column':
|
|
573
|
+
return this.createColumn(col);
|
|
574
|
+
case 'like table':
|
|
575
|
+
return this.likeTable(col);
|
|
576
|
+
default:
|
|
577
|
+
throw NotSupported.never(col);
|
|
578
|
+
}
|
|
579
|
+
})
|
|
580
|
+
if (!columns?.length) {
|
|
581
|
+
return null; // no column to create
|
|
582
|
+
}
|
|
583
|
+
return assignChanged(val, {
|
|
584
|
+
columns,
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
likeTable(col: a.CreateColumnsLikeTable): a.CreateColumnDef | a.CreateColumnsLikeTable | nil {
|
|
589
|
+
const like = this.tableRef(col.like);
|
|
590
|
+
if (!like) {
|
|
591
|
+
return null;
|
|
592
|
+
}
|
|
593
|
+
return assignChanged(col, { like });
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
truncateTable(val: a.TruncateTableStatement): a.Statement | nil {
|
|
598
|
+
return val;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
constraint(c: a.ColumnConstraint): a.ColumnConstraint | nil {
|
|
603
|
+
switch (c.type) {
|
|
604
|
+
case 'not null':
|
|
605
|
+
case 'null':
|
|
606
|
+
case 'primary key':
|
|
607
|
+
case 'unique':
|
|
608
|
+
case 'add generated':
|
|
609
|
+
if (c.type === 'add generated' && c.expression) {
|
|
610
|
+
const expression = this.expr(c.expression);
|
|
611
|
+
if (!expression) {
|
|
612
|
+
return null;
|
|
613
|
+
}
|
|
614
|
+
return assignChanged(c, {
|
|
615
|
+
expression,
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
return c;
|
|
619
|
+
case 'default': {
|
|
620
|
+
const def = this.expr(c.default);
|
|
621
|
+
if (!def) {
|
|
622
|
+
return null;
|
|
623
|
+
}
|
|
624
|
+
return assignChanged(c, {
|
|
625
|
+
default: def,
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
case 'check': {
|
|
629
|
+
const def = this.expr(c.expr);
|
|
630
|
+
if (!def) {
|
|
631
|
+
return null;
|
|
632
|
+
}
|
|
633
|
+
return assignChanged(c, {
|
|
634
|
+
expr: def,
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
case 'reference': {
|
|
638
|
+
const foreignTable = this.tableRef(c.foreignTable);
|
|
639
|
+
if (!foreignTable) {
|
|
640
|
+
return null;
|
|
641
|
+
}
|
|
642
|
+
return assignChanged(c, {
|
|
643
|
+
foreignTable,
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
default:
|
|
647
|
+
throw NotSupported.never(c);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
set(st: a.SetStatement): a.SetStatement | nil {
|
|
652
|
+
const value = this.expr(st.value);
|
|
653
|
+
if (!value) {
|
|
654
|
+
return null;
|
|
655
|
+
}
|
|
656
|
+
return assignChanged(st, {
|
|
657
|
+
value,
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
// =========================================
|
|
663
|
+
// ================ STUFF ==================
|
|
664
|
+
// =========================================
|
|
665
|
+
|
|
666
|
+
/** Called when a data type definition is encountered */
|
|
667
|
+
dataType(dataType: a.DataTypeDef): a.DataTypeDef {
|
|
668
|
+
return dataType;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
/** Called when an alias of a table is created */
|
|
672
|
+
tableRef(st: a.QNameAliased): a.QNameAliased | nil {
|
|
673
|
+
return st;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
transaction(val: a.CommitStatement | a.RollbackStatement | a.StartTransactionStatement): a.Statement | nil {
|
|
677
|
+
return val;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
createExtension(val: a.CreateExtensionStatement): a.Statement | nil {
|
|
681
|
+
return val;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
createIndex(val: a.CreateIndexStatement): a.Statement | nil {
|
|
685
|
+
const expressions = arrayNilMap(val.expressions, e => {
|
|
686
|
+
const expression = this.expr(e.expression);
|
|
687
|
+
if (expression === e.expression) {
|
|
688
|
+
return e;
|
|
689
|
+
}
|
|
690
|
+
if (!expression) {
|
|
691
|
+
return null; // no more index expression
|
|
692
|
+
}
|
|
693
|
+
return {
|
|
694
|
+
...e,
|
|
695
|
+
expression,
|
|
696
|
+
};
|
|
697
|
+
});
|
|
698
|
+
if (!expressions?.length) {
|
|
699
|
+
return null; // no columns to create index on
|
|
700
|
+
}
|
|
701
|
+
return assignChanged(val, {
|
|
702
|
+
expressions,
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
prepare(st: a.PrepareStatement): a.Statement | nil {
|
|
707
|
+
const statement = this.statement(st.statement);
|
|
708
|
+
if (!statement) {
|
|
709
|
+
return null;
|
|
710
|
+
}
|
|
711
|
+
return assignChanged(st, {
|
|
712
|
+
args: arrayNilMap(st.args, a => this.dataType(a)),
|
|
713
|
+
statement,
|
|
714
|
+
})
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
deallocate(st: a.DeallocateStatement): a.Statement | nil {
|
|
718
|
+
return st;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
// =========================================
|
|
722
|
+
// ============== ALTER INDEX ==============
|
|
723
|
+
// =========================================
|
|
724
|
+
|
|
725
|
+
alterIndex(st: a.AlterIndexStatement): a.Statement | nil {
|
|
726
|
+
// not much as of today...might improve this in the future
|
|
727
|
+
return st;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
// =========================================
|
|
731
|
+
// ============== ALTER TABLE ==============
|
|
732
|
+
// =========================================
|
|
733
|
+
|
|
734
|
+
alterTable(st: a.AlterTableStatement): a.Statement | nil {
|
|
735
|
+
const table = this.tableRef(st.table);
|
|
736
|
+
if (!table) {
|
|
737
|
+
return null; // no table
|
|
738
|
+
}
|
|
739
|
+
let changes: a.TableAlteration[] = [];
|
|
740
|
+
let hasChanged: boolean = false;
|
|
741
|
+
for (let i = 0; i < (st.changes?.length || 0); i++) {
|
|
742
|
+
const currentChange: a.TableAlteration = st.changes[i];
|
|
743
|
+
const change: a.TableAlteration | nil = this.tableAlteration(currentChange, st.table);
|
|
744
|
+
|
|
745
|
+
hasChanged = hasChanged || (change != currentChange);
|
|
746
|
+
|
|
747
|
+
if (!!change) {
|
|
748
|
+
changes.push(change);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
if (!changes.length) {
|
|
753
|
+
return null; // no change left
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
if (!hasChanged) {
|
|
757
|
+
return st;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
return assignChanged(st, {
|
|
761
|
+
table,
|
|
762
|
+
changes,
|
|
763
|
+
});
|
|
764
|
+
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
tableAlteration(change: a.TableAlteration, table: a.QNameAliased): a.TableAlteration | nil {
|
|
768
|
+
switch (change.type) {
|
|
769
|
+
case 'add column':
|
|
770
|
+
return this.addColumn(change, table);
|
|
771
|
+
case 'add constraint':
|
|
772
|
+
return this.addConstraint(change, table);
|
|
773
|
+
case 'alter column':
|
|
774
|
+
return this.alterColumn(change, table);
|
|
775
|
+
case 'rename':
|
|
776
|
+
return this.renameTable(change, table);
|
|
777
|
+
case 'rename column':
|
|
778
|
+
return this.renameColumn(change, table);
|
|
779
|
+
case 'rename constraint':
|
|
780
|
+
return this.renameConstraint(change, table);
|
|
781
|
+
case 'drop column':
|
|
782
|
+
return this.dropColumn(change, table);
|
|
783
|
+
case 'drop constraint':
|
|
784
|
+
return this.dropConstraint(change, table);
|
|
785
|
+
case 'owner':
|
|
786
|
+
return this.setTableOwner(change, table);
|
|
787
|
+
default:
|
|
788
|
+
throw NotSupported.never(change);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
dropColumn(change: a.TableAlterationDropColumn, table: a.QNameAliased): a.TableAlteration | nil {
|
|
793
|
+
return change;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
dropConstraint(change: a.TableAlterationDropConstraint, table: a.QNameAliased): a.TableAlteration | nil {
|
|
797
|
+
return change;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
setTableOwner(change: a.TableAlterationOwner, table: a.QNameAliased): a.TableAlteration | nil {
|
|
801
|
+
return change;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
renameConstraint(change: a.TableAlterationRenameConstraint, table: a.QNameAliased): a.TableAlteration | nil {
|
|
805
|
+
return change;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
renameColumn(change: a.TableAlterationRenameColumn, table: a.QNameAliased): a.TableAlteration | nil {
|
|
809
|
+
return change;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
renameTable(change: a.TableAlterationRename, table: a.QNameAliased): a.TableAlteration | nil {
|
|
814
|
+
return change;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
alterColumn(change: a.TableAlterationAlterColumn, inTable: a.QNameAliased): a.TableAlteration | nil {
|
|
818
|
+
let alter: a.AlterColumn | nil;
|
|
819
|
+
switch (change.alter.type) {
|
|
820
|
+
case 'set default':
|
|
821
|
+
alter = this.setColumnDefault(change.alter, inTable, change.column);
|
|
822
|
+
break;
|
|
823
|
+
case 'set type':
|
|
824
|
+
alter = this.setColumnType(change.alter, inTable, change.column);
|
|
825
|
+
break;
|
|
826
|
+
case 'drop default':
|
|
827
|
+
case 'set not null':
|
|
828
|
+
case 'drop not null':
|
|
829
|
+
alter = this.alterColumnSimple(change.alter, inTable, change.column);
|
|
830
|
+
break;
|
|
831
|
+
case 'add generated':
|
|
832
|
+
alter = this.alterColumnAddGenerated(change.alter, inTable, change.column);
|
|
833
|
+
break;
|
|
834
|
+
default:
|
|
835
|
+
throw NotSupported.never(change.alter);
|
|
836
|
+
}
|
|
837
|
+
if (!alter) {
|
|
838
|
+
return null; // no more alter
|
|
839
|
+
}
|
|
840
|
+
return assignChanged(change, {
|
|
841
|
+
alter,
|
|
842
|
+
});
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
setColumnType(alter: a.AlterColumnSetType, inTable: a.QName, inColumn: a.Name): a.AlterColumn | nil {
|
|
846
|
+
const dataType = this.dataType(alter.dataType);
|
|
847
|
+
return assignChanged(alter, {
|
|
848
|
+
dataType,
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
alterColumnAddGenerated(alter: a.AlterColumnAddGenerated, inTable: a.QName, inColumn: a.Name): a.AlterColumn | nil {
|
|
853
|
+
return alter;
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
|
|
857
|
+
alterColumnSimple(alter: a.AlterColumnSimple, inTable: a.QName, inColumn: a.Name): a.AlterColumn | nil {
|
|
858
|
+
return alter;
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
setColumnDefault(alter: a.AlterColumnSetDefault, inTable: a.QName, inColumn: a.Name): a.AlterColumn | nil {
|
|
862
|
+
const def = this.expr(alter.default);
|
|
863
|
+
if (!def) {
|
|
864
|
+
return null; // no more default to set
|
|
865
|
+
}
|
|
866
|
+
return assignChanged(alter, {
|
|
867
|
+
default: def,
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
addConstraint(change: a.TableAlterationAddConstraint, inTable: a.QName): a.TableAlteration | nil {
|
|
872
|
+
return change;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
addColumn(change: a.TableAlterationAddColumn, inTable: a.QName): a.TableAlteration | nil {
|
|
876
|
+
const column = this.createColumn(change.column);
|
|
877
|
+
if (!column) {
|
|
878
|
+
return null; // no more column to add
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
return assignChanged(change, {
|
|
882
|
+
column,
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
createColumn(col: a.CreateColumnDef): a.CreateColumnDef | nil {
|
|
887
|
+
// to be overriden
|
|
888
|
+
const dataType = this.dataType(col.dataType);
|
|
889
|
+
if (!dataType) {
|
|
890
|
+
return null; // no data type => remove column
|
|
891
|
+
}
|
|
892
|
+
const constraints = arrayNilMap(col.constraints, m => this.constraint(m))
|
|
893
|
+
?? undefined;
|
|
894
|
+
return assignChanged(col, {
|
|
895
|
+
dataType,
|
|
896
|
+
constraints,
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
// =========================================
|
|
901
|
+
// ============== SELECTIONS ==============
|
|
902
|
+
// =========================================
|
|
903
|
+
|
|
904
|
+
select(val: a.SelectStatement): a.SelectStatement | nil {
|
|
905
|
+
switch (val.type) {
|
|
906
|
+
case 'select':
|
|
907
|
+
return this.selection(val);
|
|
908
|
+
case 'union':
|
|
909
|
+
case 'union all':
|
|
910
|
+
return this.union(val);
|
|
911
|
+
case 'with':
|
|
912
|
+
return this.with(val);
|
|
913
|
+
case 'values':
|
|
914
|
+
return this.values(val);
|
|
915
|
+
case 'with recursive':
|
|
916
|
+
return this.withRecursive(val);
|
|
917
|
+
default:
|
|
918
|
+
throw NotSupported.never(val);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
selection(val: a.SelectFromStatement): a.SelectStatement | nil {
|
|
923
|
+
const from = arrayNilMap(val.from, c => this.from(c));
|
|
924
|
+
const columns = arrayNilMap(val.columns, c => this.selectionColumn(c));
|
|
925
|
+
const where = val.where && this.expr(val.where);
|
|
926
|
+
const groupBy = arrayNilMap(val.groupBy, c => this.expr(c));
|
|
927
|
+
const having = val.having && this.expr(val.having);
|
|
928
|
+
const orderBy = this.orderBy(val.orderBy);
|
|
929
|
+
const limit = assignChanged(val.limit, {
|
|
930
|
+
limit: this.expr(val.limit?.limit),
|
|
931
|
+
offset: this.expr(val.limit?.offset),
|
|
932
|
+
});
|
|
933
|
+
|
|
934
|
+
return assignChanged(val, {
|
|
935
|
+
from,
|
|
936
|
+
columns,
|
|
937
|
+
where,
|
|
938
|
+
groupBy,
|
|
939
|
+
having,
|
|
940
|
+
orderBy,
|
|
941
|
+
limit,
|
|
942
|
+
});
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
orderBy(orderBy: a.OrderByStatement[] | null | undefined) {
|
|
946
|
+
return arrayNilMap(orderBy, c => {
|
|
947
|
+
const by = this.expr(c.by);
|
|
948
|
+
if (!by) {
|
|
949
|
+
return null;
|
|
950
|
+
}
|
|
951
|
+
if (by === c.by) {
|
|
952
|
+
return c;
|
|
953
|
+
}
|
|
954
|
+
return {
|
|
955
|
+
...c,
|
|
956
|
+
by,
|
|
957
|
+
};
|
|
958
|
+
});
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
union(val: a.SelectFromUnion): a.SelectStatement | nil {
|
|
962
|
+
const left = this.select(val.left);
|
|
963
|
+
const right = this.select(val.right);
|
|
964
|
+
if (!left || !right) {
|
|
965
|
+
return left ?? right;
|
|
966
|
+
}
|
|
967
|
+
return assignChanged(val, {
|
|
968
|
+
left,
|
|
969
|
+
right
|
|
970
|
+
})
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
with(val: a.WithStatement): a.SelectStatement | nil {
|
|
974
|
+
const bind = arrayNilMap(val.bind, s => {
|
|
975
|
+
const statement = this.statement(s.statement);
|
|
976
|
+
return withAccepts(statement)
|
|
977
|
+
? assignChanged(s, { statement })
|
|
978
|
+
: null;
|
|
979
|
+
});
|
|
980
|
+
|
|
981
|
+
// no bindngs
|
|
982
|
+
if (!bind) {
|
|
983
|
+
return null;
|
|
984
|
+
}
|
|
985
|
+
const _in = this.statement(val.in);
|
|
986
|
+
if (!withAccepts(_in)) {
|
|
987
|
+
return null;
|
|
988
|
+
}
|
|
989
|
+
return assignChanged(val, {
|
|
990
|
+
bind,
|
|
991
|
+
in: _in,
|
|
992
|
+
})
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
withRecursive(val: a.WithRecursiveStatement): a.SelectStatement | nil {
|
|
996
|
+
const statement = this.union(val.bind);
|
|
997
|
+
if (!statement) {
|
|
998
|
+
return null;
|
|
999
|
+
}
|
|
1000
|
+
// 'with recursive' only accepts unions
|
|
1001
|
+
if (statement.type !== 'union' && statement.type !== 'union all') {
|
|
1002
|
+
return null;
|
|
1003
|
+
}
|
|
1004
|
+
const _in = this.statement(val.in);
|
|
1005
|
+
if (!withAccepts(_in)) {
|
|
1006
|
+
return null;
|
|
1007
|
+
}
|
|
1008
|
+
return assignChanged(val, {
|
|
1009
|
+
bind: statement,
|
|
1010
|
+
in: _in,
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
|
|
1015
|
+
from(from: a.From): a.From | nil {
|
|
1016
|
+
switch (from.type) {
|
|
1017
|
+
case 'table':
|
|
1018
|
+
return this.fromTable(from);
|
|
1019
|
+
case 'statement':
|
|
1020
|
+
return this.fromStatement(from);
|
|
1021
|
+
case 'call':
|
|
1022
|
+
return this.fromCall(from);
|
|
1023
|
+
default:
|
|
1024
|
+
throw NotSupported.never(from);
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
fromCall(from: a.FromCall): a.From | nil {
|
|
1029
|
+
const call = this.call(from);
|
|
1030
|
+
if (!call || call.type !== 'call') {
|
|
1031
|
+
return null;
|
|
1032
|
+
}
|
|
1033
|
+
return assignChanged(from, call);
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
|
|
1037
|
+
fromStatement(from: a.FromStatement): a.From | nil {
|
|
1038
|
+
const statement = this.select(from.statement);
|
|
1039
|
+
if (!statement) {
|
|
1040
|
+
return null; // nothing to select from
|
|
1041
|
+
}
|
|
1042
|
+
const join = from.join && this.join(from.join);
|
|
1043
|
+
return assignChanged(from, {
|
|
1044
|
+
statement,
|
|
1045
|
+
join,
|
|
1046
|
+
})
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
values(from: a.ValuesStatement): a.SelectStatement | nil {
|
|
1050
|
+
const values = arrayNilMap(from.values, x => arrayNilMap(x, y => this.expr(y)));
|
|
1051
|
+
if (!values?.length) {
|
|
1052
|
+
return null; // nothing to select from
|
|
1053
|
+
}
|
|
1054
|
+
return assignChanged(from, {
|
|
1055
|
+
values,
|
|
1056
|
+
});
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
join(join: a.JoinClause): a.JoinClause | nil {
|
|
1060
|
+
const on = join.on && this.expr(join.on);
|
|
1061
|
+
if (!on && !join.using) {
|
|
1062
|
+
return join;
|
|
1063
|
+
}
|
|
1064
|
+
return assignChanged(join, {
|
|
1065
|
+
on,
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
fromTable(from: a.FromTable): a.From | nil {
|
|
1070
|
+
const nfrom = this.tableRef(from.name);
|
|
1071
|
+
if (!nfrom) {
|
|
1072
|
+
return null; // nothing to select from
|
|
1073
|
+
}
|
|
1074
|
+
const join = from.join && this.join(from.join);
|
|
1075
|
+
return assignChanged(from, {
|
|
1076
|
+
name: nfrom,
|
|
1077
|
+
join,
|
|
1078
|
+
})
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
|
|
1082
|
+
selectionColumn(val: a.SelectedColumn): a.SelectedColumn | nil {
|
|
1083
|
+
const expr = this.expr(val.expr);
|
|
1084
|
+
if (!expr) {
|
|
1085
|
+
return null; // not selected anymore
|
|
1086
|
+
}
|
|
1087
|
+
return assignChanged(val, {
|
|
1088
|
+
expr,
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
// =========================================
|
|
1093
|
+
// ============== EXPRESSIONS ==============
|
|
1094
|
+
// =========================================
|
|
1095
|
+
|
|
1096
|
+
expr(val: a.Expr | nil): a.Expr | nil {
|
|
1097
|
+
if (!val) {
|
|
1098
|
+
return val;
|
|
1099
|
+
}
|
|
1100
|
+
switch (val.type) {
|
|
1101
|
+
case 'binary':
|
|
1102
|
+
return this.binary(val);
|
|
1103
|
+
case 'unary':
|
|
1104
|
+
return this.unary(val);
|
|
1105
|
+
case 'ref':
|
|
1106
|
+
return this.ref(val);
|
|
1107
|
+
case 'string':
|
|
1108
|
+
case 'numeric':
|
|
1109
|
+
case 'integer':
|
|
1110
|
+
case 'boolean':
|
|
1111
|
+
case 'constant':
|
|
1112
|
+
case 'null':
|
|
1113
|
+
return this.constant(val);
|
|
1114
|
+
case 'list':
|
|
1115
|
+
case 'array':
|
|
1116
|
+
return this.array(val);
|
|
1117
|
+
case 'array select':
|
|
1118
|
+
return this.arraySelect(val);
|
|
1119
|
+
case 'call':
|
|
1120
|
+
return this.call(val);
|
|
1121
|
+
case 'cast':
|
|
1122
|
+
return this.cast(val)
|
|
1123
|
+
case 'case':
|
|
1124
|
+
return this.case(val);
|
|
1125
|
+
case 'member':
|
|
1126
|
+
return this.member(val);
|
|
1127
|
+
case 'arrayIndex':
|
|
1128
|
+
return this.arrayIndex(val);
|
|
1129
|
+
case 'ternary':
|
|
1130
|
+
return this.ternary(val);
|
|
1131
|
+
case 'select':
|
|
1132
|
+
case 'union':
|
|
1133
|
+
case 'union all':
|
|
1134
|
+
case 'with':
|
|
1135
|
+
case 'with recursive':
|
|
1136
|
+
return this.select(val);
|
|
1137
|
+
case 'keyword':
|
|
1138
|
+
return this.valueKeyword(val);
|
|
1139
|
+
case 'parameter':
|
|
1140
|
+
return this.parameter(val);
|
|
1141
|
+
case 'extract':
|
|
1142
|
+
return this.extract(val);
|
|
1143
|
+
case 'overlay':
|
|
1144
|
+
return this.callOverlay(val);
|
|
1145
|
+
case 'substring':
|
|
1146
|
+
return this.callSubstring(val);
|
|
1147
|
+
case 'values':
|
|
1148
|
+
return this.values(val);
|
|
1149
|
+
case 'default':
|
|
1150
|
+
return this.default(val);
|
|
1151
|
+
default:
|
|
1152
|
+
throw NotSupported.never(val);
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
|
|
1157
|
+
arraySelect(val: a.ExprArrayFromSelect) {
|
|
1158
|
+
const select = this.select(val.select);
|
|
1159
|
+
if (!select) {
|
|
1160
|
+
return null;
|
|
1161
|
+
}
|
|
1162
|
+
return assignChanged(val, { select });
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
extract(st: a.ExprExtract): a.Expr | nil {
|
|
1166
|
+
const from = this.expr(st.from);
|
|
1167
|
+
if (!from) {
|
|
1168
|
+
return null;
|
|
1169
|
+
}
|
|
1170
|
+
return assignChanged(st, { from })
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
valueKeyword(val: a.ExprValueKeyword): a.Expr | nil {
|
|
1174
|
+
return val;
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
ternary(val: a.ExprTernary): a.Expr | nil {
|
|
1178
|
+
const value = this.expr(val.value);
|
|
1179
|
+
const lo = this.expr(val.lo);
|
|
1180
|
+
const hi = this.expr(val.hi);
|
|
1181
|
+
if (!value || !lo || !hi) {
|
|
1182
|
+
return null; // missing a branch
|
|
1183
|
+
}
|
|
1184
|
+
return assignChanged(val, {
|
|
1185
|
+
value,
|
|
1186
|
+
lo,
|
|
1187
|
+
hi,
|
|
1188
|
+
});
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
parameter(st: a.ExprParameter): a.Expr | nil {
|
|
1192
|
+
return st;
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
arrayIndex(val: a.ExprArrayIndex): a.Expr | nil {
|
|
1196
|
+
const array = this.expr(val.array);
|
|
1197
|
+
const index = this.expr(val.index);
|
|
1198
|
+
if (!array || !index) {
|
|
1199
|
+
return null;
|
|
1200
|
+
}
|
|
1201
|
+
return assignChanged(val, {
|
|
1202
|
+
array,
|
|
1203
|
+
index,
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
member(val: a.ExprMember): a.Expr | nil {
|
|
1208
|
+
const operand = this.expr(val.operand);
|
|
1209
|
+
if (!operand) {
|
|
1210
|
+
return null;
|
|
1211
|
+
}
|
|
1212
|
+
return assignChanged(val, {
|
|
1213
|
+
operand,
|
|
1214
|
+
});
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
case(val: a.ExprCase): a.Expr | nil {
|
|
1218
|
+
const value = val.value && this.expr(val.value);
|
|
1219
|
+
const whens = arrayNilMap(val.whens, w => {
|
|
1220
|
+
const when = this.expr(w.when);
|
|
1221
|
+
const value = this.expr(w.value);
|
|
1222
|
+
if (!when || !value) {
|
|
1223
|
+
return null;
|
|
1224
|
+
}
|
|
1225
|
+
return assignChanged(w, {
|
|
1226
|
+
value,
|
|
1227
|
+
when,
|
|
1228
|
+
});
|
|
1229
|
+
});
|
|
1230
|
+
if (!whens?.length) {
|
|
1231
|
+
return null; // no case
|
|
1232
|
+
}
|
|
1233
|
+
const els = val.else && this.expr(val.else);
|
|
1234
|
+
|
|
1235
|
+
return assignChanged(val, {
|
|
1236
|
+
value,
|
|
1237
|
+
whens,
|
|
1238
|
+
else: els,
|
|
1239
|
+
});
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
cast(val: a.ExprCast): a.Expr | nil {
|
|
1243
|
+
const operand = this.expr(val.operand);
|
|
1244
|
+
if (!operand) {
|
|
1245
|
+
return null;
|
|
1246
|
+
}
|
|
1247
|
+
return assignChanged(val, {
|
|
1248
|
+
operand,
|
|
1249
|
+
});
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
call(val: a.ExprCall): a.Expr | nil {
|
|
1253
|
+
const args = arrayNilMap(val.args, a => this.expr(a));
|
|
1254
|
+
if (!args) {
|
|
1255
|
+
return null;
|
|
1256
|
+
}
|
|
1257
|
+
const orderBy = this.orderBy(val.orderBy);
|
|
1258
|
+
const filter = this.expr(val.filter);
|
|
1259
|
+
const withinGroupList = val.withinGroup ? [val.withinGroup] : undefined
|
|
1260
|
+
const withinGroup = this.orderBy(withinGroupList)?.[0];
|
|
1261
|
+
return assignChanged(val, {
|
|
1262
|
+
args,
|
|
1263
|
+
orderBy,
|
|
1264
|
+
filter,
|
|
1265
|
+
withinGroup,
|
|
1266
|
+
});
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
callSubstring(val: a.ExprSubstring): a.Expr | nil {
|
|
1270
|
+
return assignChanged(val, {
|
|
1271
|
+
value: this.expr(val.value),
|
|
1272
|
+
from: this.expr(val.from),
|
|
1273
|
+
for: this.expr(val.for),
|
|
1274
|
+
})
|
|
1275
|
+
}
|
|
1276
|
+
callOverlay(val: a.ExprOverlay): a.Expr | nil {
|
|
1277
|
+
return assignChanged(val, {
|
|
1278
|
+
value: this.expr(val.value),
|
|
1279
|
+
placing: this.expr(val.placing),
|
|
1280
|
+
from: this.expr(val.from),
|
|
1281
|
+
for: this.expr(val.for),
|
|
1282
|
+
})
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
array(val: a.ExprList): a.Expr | nil {
|
|
1286
|
+
const expressions = arrayNilMap(val.expressions, a => this.expr(a));
|
|
1287
|
+
if (!expressions) {
|
|
1288
|
+
return null;
|
|
1289
|
+
}
|
|
1290
|
+
return assignChanged(val, {
|
|
1291
|
+
expressions,
|
|
1292
|
+
});
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
constant(value: a.ExprLiteral): a.Expr | nil {
|
|
1296
|
+
return value;
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
default(value: a.ExprDefault): a.Expr | nil {
|
|
1300
|
+
return value;
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
/** Called when a reference is used */
|
|
1304
|
+
ref(val: a.ExprRef): a.Expr | nil {
|
|
1305
|
+
return val;
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
unary(val: a.ExprUnary): a.Expr | nil {
|
|
1309
|
+
const operand = this.expr(val.operand);
|
|
1310
|
+
if (!operand) {
|
|
1311
|
+
return null;
|
|
1312
|
+
}
|
|
1313
|
+
return assignChanged(val, {
|
|
1314
|
+
operand,
|
|
1315
|
+
});
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
binary(val: a.ExprBinary): a.Expr | nil {
|
|
1319
|
+
const left = this.expr(val.left);
|
|
1320
|
+
const right = this.expr(val.right);
|
|
1321
|
+
if (!left || !right) {
|
|
1322
|
+
return null;
|
|
1323
|
+
}
|
|
1324
|
+
return assignChanged(val, {
|
|
1325
|
+
left,
|
|
1326
|
+
right,
|
|
1327
|
+
});
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
// ====== auto implement the replace mechanism
|
|
1332
|
+
const proto = AstDefaultMapper.prototype as any;
|
|
1333
|
+
for (const k of Object.getOwnPropertyNames(proto)) {
|
|
1334
|
+
const orig = proto[k] as Function;
|
|
1335
|
+
if (k === 'constructor' || k === 'super' || typeof orig !== 'function') {
|
|
1336
|
+
continue;
|
|
1337
|
+
}
|
|
1338
|
+
Object.defineProperty(proto, k, {
|
|
1339
|
+
configurable: false,
|
|
1340
|
+
get() {
|
|
1341
|
+
return function (this: AstDefaultMapper, ...args: []) {
|
|
1342
|
+
if (this.skipNext) {
|
|
1343
|
+
this.skipNext = false;
|
|
1344
|
+
return orig.apply(this, args);
|
|
1345
|
+
}
|
|
1346
|
+
const impl = (this.wrapped as any)?.[k];
|
|
1347
|
+
if (!impl) {
|
|
1348
|
+
return orig.apply(this, args);
|
|
1349
|
+
}
|
|
1350
|
+
return impl.apply(this.wrapped, args);
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
});
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
|
|
1357
|
+
// ====== auto implement the skip mechanism
|
|
1358
|
+
class SkipModifier extends AstDefaultMapper {
|
|
1359
|
+
constructor(readonly parent: AstDefaultMapper) {
|
|
1360
|
+
super();
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
for (const k of Object.getOwnPropertyNames(proto)) {
|
|
1365
|
+
const orig = proto[k] as Function;
|
|
1366
|
+
if (k === 'constructor' || k === 'super' || typeof orig !== 'function') {
|
|
1367
|
+
continue;
|
|
1368
|
+
}
|
|
1369
|
+
Object.defineProperty(SkipModifier.prototype, k, {
|
|
1370
|
+
configurable: false,
|
|
1371
|
+
get() {
|
|
1372
|
+
return function (this: SkipModifier, ...args: []) {
|
|
1373
|
+
this.parent.skipNext = true;
|
|
1374
|
+
return orig.apply(this.parent, args);
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
});
|
|
1378
|
+
}
|