@cchistory/lite 0.4.5 → 0.5.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 +4 -5
- package/apps/lite-cli/dist/agent-contract.d.ts.map +1 -1
- package/apps/lite-cli/dist/agent-contract.js +32 -25
- package/apps/lite-cli/dist/agent-contract.js.map +1 -1
- package/apps/lite-cli/dist/bin.js +3 -3
- 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 +147 -66
- package/apps/lite-cli/dist/index.js.map +1 -1
- package/apps/lite-cli/dist/index.test.js +76 -60
- 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 +3 -3
- 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 +2 -2
- package/apps/lite-tui/dist/index.js.map +1 -1
- package/apps/lite-tui/dist/index.test.js +5 -3
- 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 +3 -3
- package/bin/cchistory-lite.mjs +3 -3
- package/docs/guide/for-agents.md +65 -46
- package/docs/guide/lite.md +49 -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 +0 -1
- package/node_modules/@cchistory/live-runtime/dist/bootstrap.d.ts.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/bootstrap.js +0 -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 +263 -142
- 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/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 +21 -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 -41
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.js.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.test.js +266 -57
- 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 +166 -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 +80 -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/parser.d.ts +2 -1
- package/node_modules/@cchistory/source-adapters/dist/core/parser.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/parser.js +4 -4
- 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 +54 -36
- 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 +75 -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 +125 -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,333 @@
|
|
|
1
|
+
import { Parser, Grammar } from 'nearley';
|
|
2
|
+
import { expect, assert } from 'chai';
|
|
3
|
+
import grammar from '../syntax/main.ne';
|
|
4
|
+
import { trimNullish } from '../utils';
|
|
5
|
+
import { Expr, SelectStatement, CreateTableStatement, CreateIndexStatement, Statement, InsertStatement, UpdateStatement, AlterTableStatement, DeleteStatement, CreateExtensionStatement, CreateSequenceStatement, AlterSequenceStatement, SelectedColumn, Interval, BinaryOperator, ExprBinary, Name, ExprInteger, FromTable, QName, AlterIndexStatement, ExprNumeric } from './ast';
|
|
6
|
+
import { astMapper, IAstMapper } from '../ast-mapper';
|
|
7
|
+
import { toSql, IAstToSql } from '../to-sql';
|
|
8
|
+
import { parseIntervalLiteral } from '../parser';
|
|
9
|
+
import { normalizeInterval } from '../literal-syntaxes/interval-builder';
|
|
10
|
+
import { tracking } from '../lexer';
|
|
11
|
+
|
|
12
|
+
export function checkSelect(value: string | string[], expected: SelectStatement) {
|
|
13
|
+
checkTree(value, expected, (p, m) => m.statement(p));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function checkCreateSequence(value: string | string[], expected: CreateSequenceStatement) {
|
|
17
|
+
checkTree(value, expected, (p, m) => m.statement(p));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function checkCreateTable(value: string | string[], expected: CreateTableStatement) {
|
|
21
|
+
checkTree(value, expected, (p, m) => m.statement(p));
|
|
22
|
+
}
|
|
23
|
+
export function checkCreateTableLoc(value: string | string[], expected: CreateTableStatement) {
|
|
24
|
+
checkTree(value, expected, (p, m) => m.statement(p), undefined, true);
|
|
25
|
+
}
|
|
26
|
+
export function checkCreateIndex(value: string | string[], expected: CreateIndexStatement) {
|
|
27
|
+
checkTree(value, expected, (p, m) => m.statement(p));
|
|
28
|
+
}
|
|
29
|
+
export function checkCreateIndexLoc(value: string | string[], expected: CreateIndexStatement) {
|
|
30
|
+
checkTree(value, expected, (p, m) => m.statement(p), undefined, true);
|
|
31
|
+
}
|
|
32
|
+
export function checkAlterSequence(value: string | string[], expected: AlterSequenceStatement) {
|
|
33
|
+
checkTree(value, expected, (p, m) => m.statement(p));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function checkCreateExtension(value: string | string[], expected: CreateExtensionStatement) {
|
|
37
|
+
checkTree(value, expected, (p, m) => m.statement(p));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function checkInsert(value: string | string[], expected: InsertStatement) {
|
|
41
|
+
checkTree(value, expected, (p, m) => m.statement(p));
|
|
42
|
+
}
|
|
43
|
+
export function checkInsertLoc(value: string | string[], expected: InsertStatement) {
|
|
44
|
+
checkTree(value, expected, (p, m) => m.statement(p), undefined, true);
|
|
45
|
+
}
|
|
46
|
+
export function checkDelete(value: string | string[], expected: DeleteStatement) {
|
|
47
|
+
checkTree(value, expected, (p, m) => m.statement(p));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function checkAlterTable(value: string | string[], expected: AlterTableStatement) {
|
|
51
|
+
checkTree(value, expected, (p, m) => m.statement(p));
|
|
52
|
+
}
|
|
53
|
+
export function checkAlterIndex(value: string | string[], expected: AlterIndexStatement) {
|
|
54
|
+
checkTree(value, expected, (p, m) => m.statement(p));
|
|
55
|
+
}
|
|
56
|
+
export function checkAlterTableLoc(value: string | string[], expected: AlterTableStatement) {
|
|
57
|
+
checkTree(value, expected, (p, m) => m.statement(p), undefined, true);
|
|
58
|
+
}
|
|
59
|
+
export function checkUpdate(value: string | string[], expected: UpdateStatement) {
|
|
60
|
+
checkTree(value, expected, (p, m) => m.statement(p));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function checkStatement(value: string | string[], expected: Statement) {
|
|
64
|
+
checkTree(value, expected, (p, m) => m.statement(p));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function hideLocs(val: any): any {
|
|
68
|
+
if (!val) {
|
|
69
|
+
return val;
|
|
70
|
+
}
|
|
71
|
+
if (typeof val !== 'object') {
|
|
72
|
+
return val;
|
|
73
|
+
}
|
|
74
|
+
if (Array.isArray(val)) {
|
|
75
|
+
return val.map(hideLocs);
|
|
76
|
+
}
|
|
77
|
+
const ret = {} as any;
|
|
78
|
+
for (const [k, v] of Object.entries(val)) {
|
|
79
|
+
ret[k] = hideLocs(v);
|
|
80
|
+
}
|
|
81
|
+
delete ret._location;
|
|
82
|
+
return ret;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
function deepEqual<T>(a: T, b: T, strict?: boolean, depth = 10, numberDelta = 0.0001) {
|
|
88
|
+
if (depth < 0) {
|
|
89
|
+
throw new Error('Comparing too deep entities');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (a === b) {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
if (!strict) {
|
|
96
|
+
// should not use '==' because it could call .toString() on objects when compared to strings.
|
|
97
|
+
// ... which is not ok. Especially when working with translatable objects, which .toString() returns a transaltion (a string, thus)
|
|
98
|
+
if (!a && !b) {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (Array.isArray(a)) {
|
|
104
|
+
if (!Array.isArray(b) || a.length !== b.length)
|
|
105
|
+
return false;
|
|
106
|
+
for (let i = 0; i < a.length; i++) {
|
|
107
|
+
if (!deepEqual(a[i], b[i], strict, depth - 1, numberDelta))
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// handle dates
|
|
114
|
+
if (a instanceof Date || b instanceof Date) {
|
|
115
|
+
return a === b;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const fa = Number.isFinite(<any>a);
|
|
119
|
+
const fb = Number.isFinite(<any>b);
|
|
120
|
+
if (fa || fb) {
|
|
121
|
+
return fa && fb && Math.abs(<any>a - <any>b) <= numberDelta;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// handle plain objects
|
|
125
|
+
if (typeof a !== 'object' || typeof a !== typeof b)
|
|
126
|
+
return false;
|
|
127
|
+
if (!a || !b) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
const ak = Object.keys(a);
|
|
133
|
+
const bk = Object.keys(b);
|
|
134
|
+
if (strict && ak.length !== bk.length)
|
|
135
|
+
return false;
|
|
136
|
+
const set: Iterable<string> = strict
|
|
137
|
+
? Object.keys(a)
|
|
138
|
+
: new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
139
|
+
for (const k of set) {
|
|
140
|
+
if (!deepEqual((a as any)[k], (b as any)[k], strict, depth - 1, numberDelta))
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
declare var __non_webpack_require__: any;
|
|
148
|
+
|
|
149
|
+
function inspect(elt: any) {
|
|
150
|
+
return __non_webpack_require__('util').inspect(elt);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function checkTree<T>(value: string | string[], expected: T, mapper: (parsed: T, m: IAstMapper | IAstToSql) => any, start?: string, checkLocations?: boolean) {
|
|
154
|
+
if (typeof value === 'string') {
|
|
155
|
+
value = [value];
|
|
156
|
+
}
|
|
157
|
+
for (const sql of value) {
|
|
158
|
+
it('parses ' + sql, () => {
|
|
159
|
+
const gram = Grammar.fromCompiled(grammar);
|
|
160
|
+
if (start) {
|
|
161
|
+
gram.start = start
|
|
162
|
+
}
|
|
163
|
+
function doParse(psql: string) {
|
|
164
|
+
const parser = new Parser(gram);
|
|
165
|
+
parser.feed(psql);
|
|
166
|
+
const ret = parser.finish();
|
|
167
|
+
if (!ret.length) {
|
|
168
|
+
assert.fail('Unexpected end of input');
|
|
169
|
+
}
|
|
170
|
+
if (ret.length !== 1) {
|
|
171
|
+
const noLocs = ret.map(hideLocs);
|
|
172
|
+
if (noLocs.slice(1).every(p => deepEqual(p, noLocs[0]))) {
|
|
173
|
+
assert.fail(`${noLocs.length} ambiguous syntaxes, but they yielded the same ASTs : ` + inspect(noLocs[0]));
|
|
174
|
+
} else {
|
|
175
|
+
assert.fail(`${noLocs.length} ambiguous syntaxes, AND THEY HAVE YIELDED DIFFERENT ASTs : \n` + noLocs
|
|
176
|
+
.map(inspect)
|
|
177
|
+
.join('\n\n ====================== \n\n'));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return trimNullish(ret[0]);
|
|
181
|
+
}
|
|
182
|
+
const parsedWithLocations = tracking(() => doParse(sql));
|
|
183
|
+
const parsedWithoutTracking = doParse(sql);
|
|
184
|
+
const parsed =
|
|
185
|
+
checkLocations
|
|
186
|
+
? parsedWithLocations
|
|
187
|
+
: parsedWithoutTracking;
|
|
188
|
+
|
|
189
|
+
// check that it is what we expected
|
|
190
|
+
expect(parsed)
|
|
191
|
+
.to.deep.equal(expected, 'Parser has not returned the expected AST');
|
|
192
|
+
|
|
193
|
+
// check that top-level statements always have at least some kind of basic position
|
|
194
|
+
assert.exists(parsedWithLocations._location, 'Top level statements must have a location');
|
|
195
|
+
|
|
196
|
+
// check that it generates the same with/without location tracking
|
|
197
|
+
expect(hideLocs(parsedWithLocations)).to.deep.equal(hideLocs(parsedWithoutTracking), 'Parser did not return the same thing with and without location tracking enabled');
|
|
198
|
+
|
|
199
|
+
// check that it is stable through ast modifier
|
|
200
|
+
const modified = mapper(parsed, astMapper(() => ({})));
|
|
201
|
+
expect(modified).to.equal(parsed, 'It is not stable when passing through a neutral AST mapper -> Should return THE SAME REFERENCE to avoid copying stuff when nothing changed.');
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
// check that it procuces sql
|
|
205
|
+
let newSql: string;
|
|
206
|
+
try {
|
|
207
|
+
newSql = mapper(parsed, toSql);
|
|
208
|
+
assert.isString(newSql);
|
|
209
|
+
} catch (e) {
|
|
210
|
+
(e as any).message = `⛔ ⛔ ⛔ ⛔ ⛔ ⛔ ⛔ ⛔ ⛔
|
|
211
|
+
Failed to generate SQL from the parsed AST
|
|
212
|
+
=> There should be something wrong in to-sql.ts
|
|
213
|
+
⛔ ⛔ ⛔ ⛔ ⛔ ⛔ ⛔ ⛔ ⛔
|
|
214
|
+
${(e as any).message}`;
|
|
215
|
+
throw e;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// reparse the generated sql...
|
|
219
|
+
let reparsed: any;
|
|
220
|
+
try {
|
|
221
|
+
assert.isString(newSql);
|
|
222
|
+
reparsed = checkLocations
|
|
223
|
+
? tracking(() => doParse(newSql))
|
|
224
|
+
: doParse(newSql);
|
|
225
|
+
} catch (e) {
|
|
226
|
+
(e as any).message = `⛔ ⛔ ⛔ ⛔ ⛔ ⛔ ⛔ ⛔ ⛔
|
|
227
|
+
The parsed AST converted-back to SQL generated invalid SQL.
|
|
228
|
+
=> There should be something wrong in to-sql.ts
|
|
229
|
+
⛔ ⛔ ⛔ ⛔ ⛔ ⛔ ⛔ ⛔ ⛔
|
|
230
|
+
${(e as any).message}`;
|
|
231
|
+
throw e;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// ...and check it still produces the same ast.
|
|
235
|
+
expect(hideLocs(reparsed)).to.deep.equal(hideLocs(expected), `⛔ ⛔ ⛔ ⛔ ⛔ ⛔ ⛔ ⛔ ⛔
|
|
236
|
+
SQL -> AST -> SQL transformation is not stable !
|
|
237
|
+
=> This means that the parser is OK, but you might have forgotten to implement something in to-sql.ts
|
|
238
|
+
⛔ ⛔ ⛔ ⛔ ⛔ ⛔ ⛔ ⛔ ⛔ `);
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export function checkInvalid(sql: string, start?: string) {
|
|
244
|
+
it('does not parses ' + sql, () => {
|
|
245
|
+
const gram = Grammar.fromCompiled(grammar);
|
|
246
|
+
if (start) {
|
|
247
|
+
gram.start = start
|
|
248
|
+
}
|
|
249
|
+
assert.throws(() => {
|
|
250
|
+
const parser = new Parser(gram);
|
|
251
|
+
parser.feed(sql);
|
|
252
|
+
expect(parser.results).not.to.deep.equal([]);
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
export function checkValid(sql: string, start?: string) {
|
|
259
|
+
it('parses ' + sql, () => {
|
|
260
|
+
const gram = Grammar.fromCompiled(grammar);
|
|
261
|
+
if (start) {
|
|
262
|
+
gram.start = start
|
|
263
|
+
}
|
|
264
|
+
const parser = new Parser(gram);
|
|
265
|
+
parser.feed(sql);
|
|
266
|
+
expect(parser.results).not.to.deep.equal([]);
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
export function checkInvalidExpr(sql: string) {
|
|
272
|
+
return checkInvalid(sql, 'expr');
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export function checkTreeExpr(value: string | string[], expected: Expr) {
|
|
276
|
+
checkTree(value, expected, (p, m) => m.expr(p), 'expr');
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export function checkTreeExprLoc(value: string | string[], expected: Expr) {
|
|
280
|
+
checkTree(value, expected, (p, m) => m.expr(p), 'expr', true);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
export function columns(...vals: (Expr | string)[]): SelectedColumn[] {
|
|
285
|
+
return vals.map<SelectedColumn>(expr => typeof expr === 'string'
|
|
286
|
+
? { expr: { type: 'ref', name: expr } }
|
|
287
|
+
: { expr });
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
export function checkInterval(input: string | string[], expected: Interval) {
|
|
292
|
+
|
|
293
|
+
for (const v of Array.isArray(input) ? input : [input]) {
|
|
294
|
+
it('parses interval "' + v + '"', () => {
|
|
295
|
+
expect(normalizeInterval(parseIntervalLiteral(v)))
|
|
296
|
+
.to.deep.equal(expected);
|
|
297
|
+
})
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
export const star: Expr = { type: 'ref', name: '*' };
|
|
303
|
+
export const starCol: SelectedColumn = { expr: star };
|
|
304
|
+
export function col(name: string, alias?: string): SelectedColumn {
|
|
305
|
+
return {
|
|
306
|
+
expr: ref(name),
|
|
307
|
+
... alias ? { name: alias } : undefined,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
export function ref(name: string): Expr {
|
|
311
|
+
return { type: 'ref', name };
|
|
312
|
+
}
|
|
313
|
+
export function binary(left: Expr, op: BinaryOperator, right: Expr): ExprBinary {
|
|
314
|
+
return { type: 'binary', left, op, right };
|
|
315
|
+
}
|
|
316
|
+
export function name(name: string): Name {
|
|
317
|
+
return { name };
|
|
318
|
+
}
|
|
319
|
+
export function qname(name: string, schema?: string): QName {
|
|
320
|
+
return { name, schema };
|
|
321
|
+
}
|
|
322
|
+
export function int(value: number): ExprInteger {
|
|
323
|
+
return { type: 'integer', value };
|
|
324
|
+
}
|
|
325
|
+
export function tbl(nm: string): FromTable {
|
|
326
|
+
return {
|
|
327
|
+
type: 'table',
|
|
328
|
+
name: name(nm),
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
export function numeric(value: number): ExprNumeric {
|
|
332
|
+
return { type: 'numeric', value };
|
|
333
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
@lexer lexerAny
|
|
2
|
+
@include "base.ne"
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
union_left -> select_statement
|
|
6
|
+
| select_values
|
|
7
|
+
| selection_paren
|
|
8
|
+
|
|
9
|
+
union_right -> selection
|
|
10
|
+
| selection_paren
|
|
11
|
+
|
|
12
|
+
union_statement -> union_left (%kw_union %kw_all:?) union_right {% x => {
|
|
13
|
+
return track(x, {
|
|
14
|
+
type: toStr(x[1], ' '),
|
|
15
|
+
left: unwrap(x[0]),
|
|
16
|
+
right: unwrap(x[2]),
|
|
17
|
+
});
|
|
18
|
+
} %}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import 'mocha';
|
|
2
|
+
import 'chai';
|
|
3
|
+
import { checkSelect, columns, int, tbl } from './spec-utils';
|
|
4
|
+
import { SelectedColumn } from './ast';
|
|
5
|
+
|
|
6
|
+
describe('Union statement', () => {
|
|
7
|
+
|
|
8
|
+
checkSelect(`select * from (values (1,'one')) as fst union (select * from (values (2,'two')) as snd)`, {
|
|
9
|
+
type: 'union',
|
|
10
|
+
left: {
|
|
11
|
+
type: 'select',
|
|
12
|
+
from: [{
|
|
13
|
+
type: 'statement',
|
|
14
|
+
statement: {
|
|
15
|
+
type: 'values',
|
|
16
|
+
values: [
|
|
17
|
+
[{ type: 'integer', value: 1 }, { type: 'string', value: 'one' }],
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
alias: 'fst',
|
|
21
|
+
}],
|
|
22
|
+
columns: columns({ type: 'ref', name: '*' })
|
|
23
|
+
},
|
|
24
|
+
right: {
|
|
25
|
+
|
|
26
|
+
type: 'select',
|
|
27
|
+
from: [{
|
|
28
|
+
type: 'statement',
|
|
29
|
+
statement: {
|
|
30
|
+
type: 'values',
|
|
31
|
+
values: [
|
|
32
|
+
[{ type: 'integer', value: 2 }, { type: 'string', value: 'two' }],
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
alias: 'snd',
|
|
36
|
+
}],
|
|
37
|
+
columns: columns({ type: 'ref', name: '*' })
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
checkSelect([
|
|
42
|
+
`select * from ta union select * from tb union select * from tc`
|
|
43
|
+
, `select * from ta union select * from tb union (select * from tc)`
|
|
44
|
+
, `select * from ta union (select * from tb union select * from tc)`
|
|
45
|
+
, `select * from ta union (select * from tb union (select * from tc))`], {
|
|
46
|
+
type: 'union',
|
|
47
|
+
left: {
|
|
48
|
+
type: 'select',
|
|
49
|
+
columns: columns({ type: 'ref', name: '*' }),
|
|
50
|
+
from: [tbl('ta')],
|
|
51
|
+
},
|
|
52
|
+
right: {
|
|
53
|
+
type: 'union',
|
|
54
|
+
left: {
|
|
55
|
+
type: 'select',
|
|
56
|
+
columns: columns({ type: 'ref', name: '*' }),
|
|
57
|
+
from: [tbl('tb')],
|
|
58
|
+
},
|
|
59
|
+
right: {
|
|
60
|
+
type: 'select',
|
|
61
|
+
columns: columns({ type: 'ref', name: '*' }),
|
|
62
|
+
from: [tbl('tc')],
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
checkSelect(`(SELECT 'a' UNION SELECT NULL) UNION SELECT 'b'`, {
|
|
68
|
+
type: 'union',
|
|
69
|
+
left: {
|
|
70
|
+
type: 'union',
|
|
71
|
+
left: {
|
|
72
|
+
type: 'select',
|
|
73
|
+
columns: columns({ type: 'string', value: 'a' }),
|
|
74
|
+
},
|
|
75
|
+
right: {
|
|
76
|
+
type: 'select',
|
|
77
|
+
columns: columns({ type: 'null' }),
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
right: {
|
|
81
|
+
type: 'select',
|
|
82
|
+
columns: columns({ type: 'string', value: 'b' }),
|
|
83
|
+
},
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
checkSelect(`SELECT 'a' UNION ALL SELECT 'b'`, {
|
|
87
|
+
type: 'union all',
|
|
88
|
+
left: {
|
|
89
|
+
type: 'select',
|
|
90
|
+
columns: columns({ type: 'string', value: 'a' }),
|
|
91
|
+
},
|
|
92
|
+
right: {
|
|
93
|
+
type: 'select',
|
|
94
|
+
columns: columns({ type: 'string', value: 'b' }),
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const star: SelectedColumn = { expr: { type: 'ref', name: '*' } };
|
|
99
|
+
|
|
100
|
+
checkSelect(`select * from tbl where x in (
|
|
101
|
+
select 1
|
|
102
|
+
union
|
|
103
|
+
select 2
|
|
104
|
+
)`, {
|
|
105
|
+
type: 'select',
|
|
106
|
+
columns: [star],
|
|
107
|
+
from: [tbl('tbl')],
|
|
108
|
+
where: {
|
|
109
|
+
type: 'binary',
|
|
110
|
+
op: 'IN',
|
|
111
|
+
left: { type: 'ref', name: 'x' },
|
|
112
|
+
right: {
|
|
113
|
+
type: 'union',
|
|
114
|
+
left: { type: 'select', columns: [{ expr: { type: 'integer', value: 1 } }] },
|
|
115
|
+
right: { type: 'select', columns: [{ expr: { type: 'integer', value: 2 } }] },
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
checkSelect(`values (1) union values (2)`, {
|
|
121
|
+
type: 'union',
|
|
122
|
+
left: {type: 'values', values: [[int(1)]]},
|
|
123
|
+
right: {type: 'values', values: [[int(2)]]},
|
|
124
|
+
});
|
|
125
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
@lexer lexerAny
|
|
2
|
+
@include "base.ne"
|
|
3
|
+
@include "expr.ne"
|
|
4
|
+
@include "select.ne"
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
update_statement -> kw_update table_ref_aliased
|
|
8
|
+
kw_set update_set_list
|
|
9
|
+
(%kw_from select_from_subject {% last %}):?
|
|
10
|
+
select_where:?
|
|
11
|
+
(%kw_returning select_expr_list_aliased {% last %}):?
|
|
12
|
+
{% x => {
|
|
13
|
+
const from = unwrap(x[4]);
|
|
14
|
+
const where = unwrap(x[5]);
|
|
15
|
+
const returning = x[6];
|
|
16
|
+
return track(x, {
|
|
17
|
+
type: 'update',
|
|
18
|
+
table: unwrap(x[1]),
|
|
19
|
+
sets: x[3],
|
|
20
|
+
...where ? {where} : {},
|
|
21
|
+
...from ? {from} : {},
|
|
22
|
+
...returning ? {returning} : {},
|
|
23
|
+
});
|
|
24
|
+
} %}
|
|
25
|
+
|
|
26
|
+
update_set_list -> update_set (comma update_set {% last %}):* {% ([head, tail]) => {
|
|
27
|
+
const ret = [];
|
|
28
|
+
for (const _t of [head, ...(tail || [])]) {
|
|
29
|
+
const t = unwrap(_t);
|
|
30
|
+
if (Array.isArray(t)) {
|
|
31
|
+
ret.push(...t);
|
|
32
|
+
} else {
|
|
33
|
+
ret.push(t);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return ret;
|
|
37
|
+
} %}
|
|
38
|
+
|
|
39
|
+
update_set -> update_set_one | update_set_multiple
|
|
40
|
+
|
|
41
|
+
update_set_one -> ident %op_eq expr {% x => box(x, {
|
|
42
|
+
column: asName(x[0]),
|
|
43
|
+
value: unwrap(x[2]),
|
|
44
|
+
}) %}
|
|
45
|
+
|
|
46
|
+
update_set_multiple -> collist_paren %op_eq (lparen expr_list_raw rparen {% get(1) %}) {% x => {
|
|
47
|
+
const cols = x[0];
|
|
48
|
+
const exprs = x[2];
|
|
49
|
+
if (cols.length !== exprs.length) {
|
|
50
|
+
throw new Error('number of columns does not match number of values');
|
|
51
|
+
}
|
|
52
|
+
return box(x, cols.map((x: any, i: number) => ({
|
|
53
|
+
column: asName(x),
|
|
54
|
+
value: unwrap(exprs[i]),
|
|
55
|
+
})))
|
|
56
|
+
} %}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import 'mocha';
|
|
2
|
+
import 'chai';
|
|
3
|
+
import { checkUpdate, col } from './spec-utils';
|
|
4
|
+
|
|
5
|
+
describe('Update', () => {
|
|
6
|
+
|
|
7
|
+
checkUpdate([`update test set a=1`, `UPDATE"test"SET"a"=1`], {
|
|
8
|
+
type: 'update',
|
|
9
|
+
table: { name: 'test' },
|
|
10
|
+
sets: [{
|
|
11
|
+
column: { name: 'a' },
|
|
12
|
+
value: { type: 'integer', value: 1 }
|
|
13
|
+
}]
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
checkUpdate([`update test set (a,b)=(1,2), c=3`], {
|
|
17
|
+
type: 'update',
|
|
18
|
+
table: { name: 'test' },
|
|
19
|
+
sets: [{
|
|
20
|
+
column: { name: 'a' },
|
|
21
|
+
value: { type: 'integer', value: 1 }
|
|
22
|
+
}, {
|
|
23
|
+
column: { name: 'b' },
|
|
24
|
+
value: { type: 'integer', value: 2 }
|
|
25
|
+
}, {
|
|
26
|
+
column: { name: 'c' },
|
|
27
|
+
value: { type: 'integer', value: 3 }
|
|
28
|
+
}]
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
checkUpdate([`update test set a=1, b=a where a>1`], {
|
|
32
|
+
type: 'update',
|
|
33
|
+
table: { name: 'test' },
|
|
34
|
+
sets: [{
|
|
35
|
+
column: { name: 'a' },
|
|
36
|
+
value: { type: 'integer', value: 1 }
|
|
37
|
+
}, {
|
|
38
|
+
column: { name: 'b' },
|
|
39
|
+
value: { type: 'ref', name: 'a' },
|
|
40
|
+
}],
|
|
41
|
+
where: {
|
|
42
|
+
type: 'binary',
|
|
43
|
+
op: '>',
|
|
44
|
+
left: { type: 'ref', name: 'a' },
|
|
45
|
+
right: { type: 'integer', value: 1 },
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
checkUpdate([`update test set value=default`], {
|
|
50
|
+
type: 'update',
|
|
51
|
+
table: { name: 'test' },
|
|
52
|
+
sets: [{
|
|
53
|
+
column: { name: 'value' },
|
|
54
|
+
value: { type: 'default' },
|
|
55
|
+
}],
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
checkUpdate([`update mytable
|
|
59
|
+
set col = subsel.subcol
|
|
60
|
+
from (select id, subcol from subtable) as subsel
|
|
61
|
+
where subsel.id=mytable.id`], {
|
|
62
|
+
type: 'update',
|
|
63
|
+
table: { name: 'mytable' },
|
|
64
|
+
sets: [{
|
|
65
|
+
column: { name: 'col' },
|
|
66
|
+
value: { type: 'ref', name: 'subcol', table: { name: 'subsel' } },
|
|
67
|
+
}],
|
|
68
|
+
from: {
|
|
69
|
+
type: 'statement',
|
|
70
|
+
alias: 'subsel',
|
|
71
|
+
statement: {
|
|
72
|
+
type: 'select',
|
|
73
|
+
columns: [col('id'), col('subcol')],
|
|
74
|
+
from: [{
|
|
75
|
+
type: 'table',
|
|
76
|
+
name: { name: 'subtable' },
|
|
77
|
+
}]
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
where: {
|
|
81
|
+
type: 'binary',
|
|
82
|
+
op: '=',
|
|
83
|
+
left: { type: 'ref', name: 'id', table: { name: 'subsel' } },
|
|
84
|
+
right: { type: 'ref', name: 'id', table: { name: 'mytable' } },
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
@lexer lexerAny
|
|
2
|
+
|
|
3
|
+
# https://www.postgresql.org/docs/current/queries-with.html
|
|
4
|
+
|
|
5
|
+
with_statement -> %kw_with with_statement_bindings with_statement_statement {% x => track(x, {
|
|
6
|
+
type: 'with',
|
|
7
|
+
bind: x[1],
|
|
8
|
+
in: unwrap(x[2]),
|
|
9
|
+
}) %}
|
|
10
|
+
|
|
11
|
+
with_recursive_statement -> (%kw_with kw_recursive)
|
|
12
|
+
ident
|
|
13
|
+
collist_paren
|
|
14
|
+
%kw_as
|
|
15
|
+
lparen
|
|
16
|
+
union_statement
|
|
17
|
+
rparen
|
|
18
|
+
with_statement_statement {% x => track(x, {
|
|
19
|
+
type: 'with recursive',
|
|
20
|
+
alias: asName(x[1]),
|
|
21
|
+
columnNames: x[2].map(asName),
|
|
22
|
+
bind: x[5],
|
|
23
|
+
in: unwrap(x[7]),
|
|
24
|
+
}) %}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
with_statement_bindings -> with_statement_binding (comma with_statement_binding {% last %}):* {% ([head, tail]) => {
|
|
28
|
+
return [head, ...(tail || [])];
|
|
29
|
+
} %}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
with_statement_binding -> word %kw_as lparen with_statement_statement rparen {% x => track(x, {
|
|
33
|
+
alias: asName(x[0]),
|
|
34
|
+
statement: unwrap(x[3]),
|
|
35
|
+
}) %}
|
|
36
|
+
|
|
37
|
+
with_statement_statement
|
|
38
|
+
-> selection
|
|
39
|
+
| insert_statement
|
|
40
|
+
| update_statement
|
|
41
|
+
| delete_statement
|