@cchistory/lite 0.4.4 โ 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 +35 -28
- 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 +155 -81
- package/apps/lite-cli/dist/index.js.map +1 -1
- package/apps/lite-cli/dist/index.test.js +87 -63
- 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 -42
- package/docs/guide/lite.md +64 -24
- 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 -58
- 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 +32 -23
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.d.ts.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.js +65 -45
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.js.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.test.js +363 -59
- 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 -53
- 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,57 @@
|
|
|
1
|
+
import 'mocha';
|
|
2
|
+
import 'chai';
|
|
3
|
+
import { astVisitor } from './ast-visitor';
|
|
4
|
+
import { expect } from 'chai';
|
|
5
|
+
|
|
6
|
+
describe('Ast visitor', () => {
|
|
7
|
+
|
|
8
|
+
// just a quickcheck. (those were throwing)
|
|
9
|
+
it('visits ref when implemented', () => {
|
|
10
|
+
let visited = null;
|
|
11
|
+
const mapper = astVisitor(() => ({
|
|
12
|
+
ref: r => visited = r.name,
|
|
13
|
+
}))
|
|
14
|
+
mapper.expr({
|
|
15
|
+
type: 'unary',
|
|
16
|
+
op: 'NOT',
|
|
17
|
+
operand: {
|
|
18
|
+
type: 'ref',
|
|
19
|
+
name: 'myRef'
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
expect(visited).to.equal('myRef');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('does not visit ref when not implemented', () => {
|
|
26
|
+
let visited = null;
|
|
27
|
+
astVisitor(() => ({
|
|
28
|
+
})).expr({
|
|
29
|
+
type: 'unary',
|
|
30
|
+
op: 'NOT',
|
|
31
|
+
operand: {
|
|
32
|
+
type: 'ref',
|
|
33
|
+
name: 'myRef'
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
expect(visited).to.equal(null);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
it('allow super call', () => {
|
|
41
|
+
let visited = null;
|
|
42
|
+
astVisitor(v => ({
|
|
43
|
+
ref: r => {
|
|
44
|
+
visited = r.name;
|
|
45
|
+
return v.super().ref(r);
|
|
46
|
+
},
|
|
47
|
+
})).expr({
|
|
48
|
+
type: 'unary',
|
|
49
|
+
op: 'NOT',
|
|
50
|
+
operand: {
|
|
51
|
+
type: 'ref',
|
|
52
|
+
name: 'myRef'
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
expect(visited).to.equal('myRef');
|
|
56
|
+
});
|
|
57
|
+
})
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import * as a from './syntax/ast';
|
|
2
|
+
import { AstDefaultMapper, IAstPartialMapper, astMapper, IAstMapper } from './ast-mapper';
|
|
3
|
+
import { ReplaceReturnType } from './utils';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export type IAstPartialVisitor = { [key in keyof IAstPartialMapper]: ReplaceReturnType<IAstPartialMapper[key], any> }
|
|
8
|
+
export type IAstFullVisitor = {
|
|
9
|
+
[key in keyof IAstPartialVisitor]-?: IAstPartialVisitor[key];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type IAstVisitor = IAstFullVisitor & {
|
|
13
|
+
super(): IAstVisitor;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Visitor {
|
|
18
|
+
mapper?: IAstMapper;
|
|
19
|
+
visitor?: IAstPartialVisitor;
|
|
20
|
+
|
|
21
|
+
super() {
|
|
22
|
+
return new SkipVisitor(this);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// =============== auto implement the mapper
|
|
27
|
+
const mapperProto = AstDefaultMapper.prototype as any;
|
|
28
|
+
for (const k of Object.getOwnPropertyNames(mapperProto)) {
|
|
29
|
+
const orig = mapperProto[k] as Function;
|
|
30
|
+
if (k === 'constructor' || k === 'super' || typeof orig !== 'function') {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
Object.defineProperty(Visitor.prototype, k, {
|
|
34
|
+
configurable: false,
|
|
35
|
+
get() {
|
|
36
|
+
return function (this: Visitor, ...args: any[]) {
|
|
37
|
+
const impl = (this.visitor as any)[k] as Function;
|
|
38
|
+
if (!impl) {
|
|
39
|
+
// just ignore & forward call to mapper
|
|
40
|
+
return orig.apply(this, args);
|
|
41
|
+
}
|
|
42
|
+
// return first argument
|
|
43
|
+
// ...which means "I dont wana change anything"
|
|
44
|
+
// in the ast-modifier language.
|
|
45
|
+
impl.apply(this.visitor, args);
|
|
46
|
+
return args[0];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
// ====== auto implement the skip mechanism
|
|
54
|
+
class SkipVisitor {
|
|
55
|
+
constructor(readonly parent: Visitor) {
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
for (const k of Object.getOwnPropertyNames(mapperProto)) {
|
|
60
|
+
const orig = mapperProto[k] as Function;
|
|
61
|
+
if (k === 'constructor' || k === 'super' || typeof orig !== 'function') {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
Object.defineProperty(SkipVisitor.prototype, k, {
|
|
65
|
+
configurable: false,
|
|
66
|
+
get() {
|
|
67
|
+
return function (this: SkipVisitor, ...args: []) {
|
|
68
|
+
return orig.apply(this.parent, args);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Builds an AST visitor based on the default implementation, merged with the one you provide.
|
|
76
|
+
*
|
|
77
|
+
* Example of visitor which counts references to a column 'foo':
|
|
78
|
+
*
|
|
79
|
+
* ```ts
|
|
80
|
+
* let cnt = 0;
|
|
81
|
+
* const visitor = astVisitor(v => ({
|
|
82
|
+
* ref: r => {
|
|
83
|
+
* if (r.name === 'foo') {
|
|
84
|
+
* cnt++;
|
|
85
|
+
* }
|
|
86
|
+
* v.super().ref(r);
|
|
87
|
+
* }
|
|
88
|
+
* }));
|
|
89
|
+
*
|
|
90
|
+
* visitor.statement(myStatementToCount);
|
|
91
|
+
* console.log(`${cnt} references to foo !`);
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export function astVisitor<T extends IAstPartialVisitor = IAstPartialVisitor>(visitorBuilder: (defaultImplem: IAstVisitor) => T): IAstVisitor {
|
|
95
|
+
return astMapper(m => {
|
|
96
|
+
const ret = new Visitor();
|
|
97
|
+
ret.mapper = m;
|
|
98
|
+
ret.visitor = visitorBuilder(ret as any);
|
|
99
|
+
return ret as any;
|
|
100
|
+
})
|
|
101
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { parse, parseFirst, parseArrayLiteral, parseGeometricLiteral, parseIntervalLiteral, parseWithComments } from './parser';
|
|
2
|
+
export { astVisitor } from './ast-visitor'
|
|
3
|
+
export { arrayNilMap, assignChanged, astMapper } from './ast-mapper';
|
|
4
|
+
export { toSql } from './to-sql';
|
|
5
|
+
export * from './syntax/ast';
|
|
6
|
+
export type { IAstToSql } from './to-sql';
|
|
7
|
+
export type { IAstPartialMapper, IAstMapper } from './ast-mapper';
|
|
8
|
+
export type { nil } from './utils';
|
|
9
|
+
export type { IAstPartialVisitor, IAstVisitor } from './ast-visitor'
|
|
10
|
+
export { intervalToString, normalizeInterval } from './literal-syntaxes/interval-builder';
|
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// https://www.postgresql.org/docs/current/sql-keywords-appendix.html
|
|
2
|
+
// $('table.table').children('tbody').children().toArray().filter(x => { const txt = $($(x).children()[1]).text(); return txt.includes('reserved') && !txt.includes('non-reserved')}).map(x => $($(x).children()[0]).text())
|
|
3
|
+
export const sqlKeywords = [
|
|
4
|
+
"ALL", "ANALYSE", "ANALYZE", "AND", "ANY", "ARRAY", "AS", "ASC", "ASYMMETRIC", "AUTHORIZATION", "BINARY", "BOTH", "CASE", "CAST", "CHECK", "COLLATE", "COLLATION", "CONCURRENTLY", "CONSTRAINT", "CREATE", "CROSS", "CURRENT_CATALOG", "CURRENT_DATE", "CURRENT_ROLE", "CURRENT_SCHEMA", "CURRENT_TIME", "CURRENT_TIMESTAMP", "CURRENT_USER", "DEFAULT", "DEFERRABLE", "DESC", "DISTINCT", "DO", "ELSE", "END", "EXCEPT", "FALSE", "FETCH", "FOR", "FOREIGN", "FREEZE", "FROM", "FULL", "GRANT", "GROUP", "HAVING", "ILIKE", "IN", "INITIALLY", "INNER", "INTERSECT", "INTO", "IS", "ISNULL", "JOIN", "LATERAL", "LEADING", "LEFT", "LIKE", "LIMIT", "LOCALTIME", "LOCALTIMESTAMP", "NATURAL", "NOT", "NOTNULL", "NULL", "OFFSET", "ON", "ONLY", "OR", "ORDER", "OUTER", "OVERLAPS", "PLACING", "PRIMARY", "REFERENCES", "RETURNING", "RIGHT", "SELECT", "SESSION_USER", "SIMILAR", "SOME", "SYMMETRIC", "TABLE", "TABLESAMPLE", "THEN", "TO", "TRAILING", "TRUE", "UNION", "UNIQUE", "USER", "USING", "VARIADIC", "VERBOSE", "WHEN", "WHERE", "WINDOW", "WITH"
|
|
5
|
+
|
|
6
|
+
// added manually
|
|
7
|
+
, "PRECISION"
|
|
8
|
+
];
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import 'mocha';
|
|
2
|
+
import 'chai';
|
|
3
|
+
import { lexer } from './lexer';
|
|
4
|
+
import { expect, assert } from 'chai';
|
|
5
|
+
import { Optional } from './utils';
|
|
6
|
+
import { Token } from 'moo';
|
|
7
|
+
|
|
8
|
+
describe('Lexer', () => {
|
|
9
|
+
|
|
10
|
+
const hasContent = new Set([
|
|
11
|
+
'word',
|
|
12
|
+
'quoted_word',
|
|
13
|
+
'int',
|
|
14
|
+
'float',
|
|
15
|
+
'codeblock',
|
|
16
|
+
]);
|
|
17
|
+
function next(expected: any) {
|
|
18
|
+
const result = lexer.next() as Optional<Token>;
|
|
19
|
+
delete result.toString;
|
|
20
|
+
delete result.col;
|
|
21
|
+
delete result.line;
|
|
22
|
+
delete result.lineBreaks;
|
|
23
|
+
delete result.offset;
|
|
24
|
+
delete result.text;
|
|
25
|
+
if (!hasContent.has(result.type!)) {
|
|
26
|
+
delete result.value;
|
|
27
|
+
}
|
|
28
|
+
expect(result).to.deep.equal(expected);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
it('comments and minus are not confused', () => {
|
|
32
|
+
lexer.reset(`1 - 2`);
|
|
33
|
+
next({ type: 'int', value: '1' });
|
|
34
|
+
next({ type: 'op_minus' });
|
|
35
|
+
next({ type: 'int', value: '2' });
|
|
36
|
+
|
|
37
|
+
lexer.reset(`1 -- 2`);
|
|
38
|
+
next({ type: 'int', value: '1' });
|
|
39
|
+
expect(lexer.next()).to.equal(undefined)
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('member and minus ops are not confused', () => {
|
|
43
|
+
lexer.reset(`- -> ->>`);
|
|
44
|
+
next({ type: 'op_minus'});
|
|
45
|
+
next({ type: 'op_member'});
|
|
46
|
+
next({ type: 'op_membertext'});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('comments and division are not confused', () => {
|
|
50
|
+
lexer.reset(`1 / 2`);
|
|
51
|
+
next({ type: 'int', value: '1' });
|
|
52
|
+
next({ type: 'op_div' });
|
|
53
|
+
next({ type: 'int', value: '2' });
|
|
54
|
+
|
|
55
|
+
lexer.reset(`1 /* 2 */`);
|
|
56
|
+
next({ type: 'int', value: '1' });
|
|
57
|
+
expect(lexer.next()).to.equal(undefined)
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('like/ilike ops', () => {
|
|
61
|
+
lexer.reset(`!~~*`);
|
|
62
|
+
next({ type: 'op_not_ilike' });
|
|
63
|
+
|
|
64
|
+
lexer.reset(`!~~ *`);
|
|
65
|
+
next({ type: 'op_not_like' });
|
|
66
|
+
next({ type: 'star' });
|
|
67
|
+
|
|
68
|
+
lexer.reset(`~~*`);
|
|
69
|
+
next({ type: 'op_ilike' });
|
|
70
|
+
|
|
71
|
+
lexer.reset(`~~ *`);
|
|
72
|
+
next({ type: 'op_like' });
|
|
73
|
+
next({ type: 'star' });
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('tokenizes end comment', () => {
|
|
77
|
+
lexer.reset(`SELECT -- test`);
|
|
78
|
+
next({ type: 'kw_select' });
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('tokenizes middle comment', () => {
|
|
82
|
+
lexer.reset(`SELECT -- test\n*`);
|
|
83
|
+
next({ type: 'kw_select' });
|
|
84
|
+
next({ type: 'star' });
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
it('tokenizes middle comment after op', () => {
|
|
89
|
+
lexer.reset(`2+-- yo\n2`);
|
|
90
|
+
next({ type: 'int', value: '2' });
|
|
91
|
+
next({ type: 'op_plus' });
|
|
92
|
+
next({ type: 'int', value: '2' });
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('tokenizes star comment', () => {
|
|
96
|
+
lexer.reset(`SELECT /* test */ *`);
|
|
97
|
+
next({ type: 'kw_select' });
|
|
98
|
+
next({ type: 'star' });
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('allows punctuation in keyords', () => {
|
|
102
|
+
// see https://github.com/oguimbal/pgsql-ast-parser/issues/100
|
|
103
|
+
lexer.reset(`SELECT /* :,| */ *`);
|
|
104
|
+
next({ type: 'kw_select' });
|
|
105
|
+
next({ type: 'star' });
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('tokenizes select', () => {
|
|
109
|
+
lexer.reset(`SELECT * FROM test`);
|
|
110
|
+
next({ type: 'kw_select' });
|
|
111
|
+
next({ type: 'star' });
|
|
112
|
+
next({ type: 'kw_from' });
|
|
113
|
+
next({ type: 'word', value: 'test' });
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('tokenizes select without spaces', () => {
|
|
117
|
+
lexer.reset(`SELECT(id)from"test"`);
|
|
118
|
+
next({ type: 'kw_select' });
|
|
119
|
+
next({ type: 'lparen' });
|
|
120
|
+
next({ type: 'word', value: 'id' });
|
|
121
|
+
next({ type: 'rparen' });
|
|
122
|
+
next({ type: 'kw_from' });
|
|
123
|
+
next({ type: 'quoted_word', value: 'test' });
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('tokenizes "" as the letter " in names', () => {
|
|
127
|
+
lexer.reset(`"a""b"`);
|
|
128
|
+
next({ type: 'quoted_word', value: 'a""b' });
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
it('keeps case in quoted names', () => {
|
|
133
|
+
lexer.reset(`"Name"`);
|
|
134
|
+
next({ type: 'quoted_word', value: 'Name' });
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('lowers non quoted names', () => {
|
|
138
|
+
lexer.reset(`Name`);
|
|
139
|
+
next({ type: 'word', value: 'name' });
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
it('supports edge cases names', () => {
|
|
143
|
+
lexer.reset(`_Name "_Name" a_b name_`);
|
|
144
|
+
next({ type: 'word', value: '_name' });
|
|
145
|
+
next({ type: 'quoted_word', value: '_Name' });
|
|
146
|
+
next({ type: 'word', value: 'a_b' });
|
|
147
|
+
next({ type: 'word', value: 'name_' });
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
it('tokenizes additive binaries', () => {
|
|
151
|
+
lexer.reset('2+2');
|
|
152
|
+
next({ type: 'int', value: '2' });
|
|
153
|
+
next({ type: 'op_plus' });
|
|
154
|
+
next({ type: 'int', value: '2' });
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('tokenizes comma', () => {
|
|
158
|
+
lexer.reset('2,2');
|
|
159
|
+
next({ type: 'int', value: '2' });
|
|
160
|
+
next({ type: 'comma' });
|
|
161
|
+
next({ type: 'int', value: '2' });
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
it('tokenizes floats', () => {
|
|
166
|
+
lexer.reset('1.,.1,-.1,-0.1,0.1,10.,-10.');
|
|
167
|
+
next({ type: 'float', value: '1.' });
|
|
168
|
+
next({ type: 'comma' });
|
|
169
|
+
next({ type: 'float', value: '.1' });
|
|
170
|
+
next({ type: 'comma' });
|
|
171
|
+
next({ type: 'float', value: '-.1' });
|
|
172
|
+
next({ type: 'comma' });
|
|
173
|
+
next({ type: 'float', value: '-0.1' });
|
|
174
|
+
next({ type: 'comma' });
|
|
175
|
+
next({ type: 'float', value: '0.1' });
|
|
176
|
+
next({ type: 'comma' });
|
|
177
|
+
next({ type: 'float', value: '10.' });
|
|
178
|
+
next({ type: 'comma' });
|
|
179
|
+
next({ type: 'float', value: '-10.' });
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
it('tokenizes ->', () => {
|
|
183
|
+
lexer.reset('a->b');
|
|
184
|
+
next({ type: 'word', value: 'a' });
|
|
185
|
+
next({ type: 'op_member' });
|
|
186
|
+
next({ type: 'word', value: 'b' });
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it('tokenizes ->>', () => {
|
|
190
|
+
lexer.reset('a->>b');
|
|
191
|
+
next({ type: 'word', value: 'a' });
|
|
192
|
+
next({ type: 'op_membertext' });
|
|
193
|
+
next({ type: 'word', value: 'b' });
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('tokenises empty string', () => {
|
|
197
|
+
lexer.reset(`''`)
|
|
198
|
+
next({ type: 'string' });
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
it(`tokenizes SELECT pg_catalog.set_config('search_path', '', false);`, () => {
|
|
202
|
+
lexer.reset(`SELECT pg_catalog.set_config('search_path', '', false);`);
|
|
203
|
+
next({ type: 'kw_select' });
|
|
204
|
+
next({ type: 'word', value: 'pg_catalog' });
|
|
205
|
+
next({ type: 'dot' });
|
|
206
|
+
next({ type: 'word', value: 'set_config' });
|
|
207
|
+
next({ type: 'lparen' });
|
|
208
|
+
next({ type: 'string' });
|
|
209
|
+
next({ type: 'comma' });
|
|
210
|
+
next({ type: 'string' });
|
|
211
|
+
next({ type: 'comma' });
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
it('tokenizes code block', () => {
|
|
215
|
+
lexer.reset(`before $$ code $ block $$ after`);
|
|
216
|
+
next({ type: 'word', value: 'before' });
|
|
217
|
+
next({ type: 'codeblock', value: ' code $ block ' });
|
|
218
|
+
next({ type: 'word', value: 'after' });
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
it('tokenizes multiline code block', () => {
|
|
222
|
+
const multi = `code
|
|
223
|
+
block`;
|
|
224
|
+
lexer.reset(`$$${multi}$$`);
|
|
225
|
+
next({ type: 'codeblock', value: multi });
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
it('can parse multiple full comments', () => {
|
|
229
|
+
lexer.reset('select /* comment a */ * from /* comment b */ tbl');
|
|
230
|
+
next({ type: 'kw_select' });
|
|
231
|
+
next({ type: 'star' });
|
|
232
|
+
next({ type: 'kw_from' });
|
|
233
|
+
next({ type: 'word', value: 'tbl' });
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it ('can parse an empty full comment', () => {
|
|
237
|
+
lexer.reset('/**/ select');
|
|
238
|
+
next({ type: 'kw_select' });
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
it ('can parse nested full comments', () => {
|
|
242
|
+
lexer.reset('/* /* */ /* /* */ */ */ select');
|
|
243
|
+
next({ type: 'kw_select' });
|
|
244
|
+
})
|
|
245
|
+
});
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { compile, keywords, Token } from 'moo';
|
|
2
|
+
|
|
3
|
+
import { sqlKeywords } from './keywords';
|
|
4
|
+
import { NodeLocation, PGComment } from './syntax/ast';
|
|
5
|
+
|
|
6
|
+
// build keywords
|
|
7
|
+
const keywordsMap: any = {};
|
|
8
|
+
for (const k of sqlKeywords) {
|
|
9
|
+
keywordsMap['kw_' + k.toLowerCase()] = k;
|
|
10
|
+
}
|
|
11
|
+
const caseInsensitiveKeywords = (map: any) => {
|
|
12
|
+
const transform = keywords(map)
|
|
13
|
+
return (text: string) => transform(text.toUpperCase())
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
// build lexer
|
|
18
|
+
export const lexer = compile({
|
|
19
|
+
word: {
|
|
20
|
+
match: /[eE](?!')[A-Za-z0-9_]*|[a-df-zA-DF-Z_][A-Za-z0-9_]*/,
|
|
21
|
+
type: caseInsensitiveKeywords(keywordsMap),
|
|
22
|
+
value: x => x.toLowerCase(),
|
|
23
|
+
},
|
|
24
|
+
wordQuoted: {
|
|
25
|
+
match: /"(?:[^"\*]|"")+"/,
|
|
26
|
+
type: () => 'quoted_word',
|
|
27
|
+
value: x => x.substring(1, x.length - 1),
|
|
28
|
+
},
|
|
29
|
+
string: {
|
|
30
|
+
match: /'(?:[^']|\'\')*'/,
|
|
31
|
+
value: x => {
|
|
32
|
+
return x.substring(1, x.length - 1)
|
|
33
|
+
.replace(/''/g, '\'');
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
eString: {
|
|
37
|
+
match: /\b(?:e|E)'(?:[^'\\]|[\r\n\s]|(?:\\\s)|(?:\\\n)|(?:\\.)|(?:\'\'))+'/,
|
|
38
|
+
value: x => {
|
|
39
|
+
return x.substring(2, x.length - 1)
|
|
40
|
+
.replace(/''/g, '\'')
|
|
41
|
+
.replace(/\\([\s\n])/g, (_, x) => x)
|
|
42
|
+
.replace(/\\./g, m => JSON.parse('"' + m + '"'));
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
qparam: {
|
|
46
|
+
match: /\$\d+/,
|
|
47
|
+
},
|
|
48
|
+
commentLine: /\-\-.*?$[\s\r\n]*/,
|
|
49
|
+
commentFullOpen: /\/\*/,
|
|
50
|
+
commentFullClose: /\*\/[\s\r\n]*/,
|
|
51
|
+
star: '*',
|
|
52
|
+
comma: ',',
|
|
53
|
+
space: { match: /[\s\t\n\v\f\r]+/, lineBreaks: true, },
|
|
54
|
+
int: /\-?\d+(?![\.\d])/,
|
|
55
|
+
float: /\-?(?:(?:\d*\.\d+)|(?:\d+\.\d*))/,
|
|
56
|
+
// word: /[a-zA-Z][A-Za-z0-9_\-]*/,
|
|
57
|
+
lparen: '(',
|
|
58
|
+
rparen: ')',
|
|
59
|
+
lbracket: '[',
|
|
60
|
+
rbracket: ']',
|
|
61
|
+
semicolon: ';',
|
|
62
|
+
dot: /\.(?!\d)/,
|
|
63
|
+
op_cast: '::',
|
|
64
|
+
op_colon: ':',
|
|
65
|
+
op_plus: '+',
|
|
66
|
+
op_eq: '=',
|
|
67
|
+
op_neq: {
|
|
68
|
+
match: /(?:!=)|(?:\<\>)/,
|
|
69
|
+
value: () => '!=',
|
|
70
|
+
},
|
|
71
|
+
op_membertext: '->>',
|
|
72
|
+
op_member: '->',
|
|
73
|
+
op_minus: '-',
|
|
74
|
+
op_div: /\//,
|
|
75
|
+
op_not_ilike: /\!~~\*/, // !~~* =ILIKE
|
|
76
|
+
op_not_like: /\!~~/, // !~~ =LIKE
|
|
77
|
+
op_ilike: /~~\*/, // ~~* =ILIKE
|
|
78
|
+
op_like: /~~/, // ~~ =LIKE
|
|
79
|
+
op_mod: '%',
|
|
80
|
+
op_exp: '^',
|
|
81
|
+
op_additive: {
|
|
82
|
+
// group other additive operators
|
|
83
|
+
match: ['||', '-', '#-', '&&'],
|
|
84
|
+
},
|
|
85
|
+
op_compare: {
|
|
86
|
+
// group other comparison operators
|
|
87
|
+
// ... to add: "IN" and "NOT IN" that are matched by keywords
|
|
88
|
+
match: ['>', '>=', '<', '<=', '@>', '<@', '?', '?|', '?&', '#>>', '>>', '<<', '~', '~*', '!~', '!~*', '@@'],
|
|
89
|
+
},
|
|
90
|
+
ops_others: {
|
|
91
|
+
// referenced as (any other operator) in https://www.postgresql.org/docs/12/sql-syntax-lexical.html#SQL-PRECEDENCE
|
|
92
|
+
// see also https://www.postgresql.org/docs/9.0/functions-math.html
|
|
93
|
+
match: ['|', '&', '^', '#'],
|
|
94
|
+
},
|
|
95
|
+
codeblock: {
|
|
96
|
+
match: /\$\$(?:.|[\s\t\n\v\f\r])*?\$\$/s,
|
|
97
|
+
lineBreaks: true,
|
|
98
|
+
value: (x: string) => x.substring(2, x.length - 2),
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
lexer.next = (next => () => {
|
|
103
|
+
let tok: Token | undefined;
|
|
104
|
+
let commentFull: {
|
|
105
|
+
nested: number;
|
|
106
|
+
offset: number;
|
|
107
|
+
text: string;
|
|
108
|
+
} | null = null;
|
|
109
|
+
|
|
110
|
+
while (tok = next.call(lexer)) {
|
|
111
|
+
// js regex can't be recursive, so we'll keep track of nested opens (/*) and closes (*/).
|
|
112
|
+
if (tok.type === 'commentFullOpen') {
|
|
113
|
+
if (commentFull === null) { // initial open - start collecting content
|
|
114
|
+
commentFull = {
|
|
115
|
+
nested: 0,
|
|
116
|
+
offset: tok.offset,
|
|
117
|
+
text: tok.text
|
|
118
|
+
}
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
commentFull.nested++;
|
|
122
|
+
}
|
|
123
|
+
if (commentFull != null) {
|
|
124
|
+
// collect comment content
|
|
125
|
+
commentFull.text += tok.text;
|
|
126
|
+
|
|
127
|
+
if (tok.type === 'commentFullClose') {
|
|
128
|
+
if (commentFull.nested === 0) { // finish comment, if not nested
|
|
129
|
+
comments?.push(makeComment(commentFull))
|
|
130
|
+
commentFull = null;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
commentFull.nested--;
|
|
134
|
+
}
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (tok.type === 'space') {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (tok.type === 'commentLine') {
|
|
141
|
+
comments?.push(makeComment(tok))
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (trackingLoc && tok) {
|
|
148
|
+
const start = tok.offset;
|
|
149
|
+
const loc: NodeLocation = {
|
|
150
|
+
start,
|
|
151
|
+
end: start + tok.text.length,
|
|
152
|
+
};
|
|
153
|
+
(tok as any)._location = loc;
|
|
154
|
+
}
|
|
155
|
+
return tok;
|
|
156
|
+
})(lexer.next);
|
|
157
|
+
|
|
158
|
+
export const lexerAny: any = lexer;
|
|
159
|
+
|
|
160
|
+
let comments: PGComment[] | null = null;
|
|
161
|
+
|
|
162
|
+
const makeComment = ({ offset, text }: { offset: number; text: string }): PGComment => ({
|
|
163
|
+
_location: { start: offset, end: offset + text.length },
|
|
164
|
+
comment: text,
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
export function trackingComments<T>(act: () => T): { ast: T; comments: PGComment[] } {
|
|
168
|
+
if (comments) {
|
|
169
|
+
throw new Error('WAT ? Recursive comments tracking ๐ค๐คจ ?');
|
|
170
|
+
}
|
|
171
|
+
try {
|
|
172
|
+
comments = [];
|
|
173
|
+
const ast = act();
|
|
174
|
+
return { comments, ast };
|
|
175
|
+
} finally {
|
|
176
|
+
comments = null;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
let trackingLoc = false;
|
|
181
|
+
export function tracking<T>(act: () => T): T {
|
|
182
|
+
if (trackingLoc) {
|
|
183
|
+
return act();
|
|
184
|
+
}
|
|
185
|
+
try {
|
|
186
|
+
trackingLoc = true;
|
|
187
|
+
return act();
|
|
188
|
+
} finally {
|
|
189
|
+
trackingLoc = false;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function track(xs: any, ret: any) {
|
|
194
|
+
if (!trackingLoc || !ret || typeof ret !== 'object') {
|
|
195
|
+
return ret;
|
|
196
|
+
}
|
|
197
|
+
const start = seek(xs, true);
|
|
198
|
+
const end = seek(xs, false);
|
|
199
|
+
if (!start || !end) {
|
|
200
|
+
return ret;
|
|
201
|
+
}
|
|
202
|
+
if (start === end) {
|
|
203
|
+
ret._location = start;
|
|
204
|
+
} else {
|
|
205
|
+
const loc: NodeLocation = {
|
|
206
|
+
start: start.start,
|
|
207
|
+
end: end.end,
|
|
208
|
+
};
|
|
209
|
+
ret._location = loc;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return ret;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const literal = Symbol('_literal');
|
|
216
|
+
const doubleQuotedSym = Symbol('_doublequoted');
|
|
217
|
+
export function box(xs: any, value: any, doubleQuoted?: boolean) {
|
|
218
|
+
if (!trackingLoc && !doubleQuoted) {
|
|
219
|
+
return value;
|
|
220
|
+
}
|
|
221
|
+
return track(xs, { [literal]: value, [doubleQuotedSym]: doubleQuoted });
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
function unwrapNoBox(e: any[]): any {
|
|
226
|
+
if (Array.isArray(e) && e.length === 1) {
|
|
227
|
+
e = unwrapNoBox(e[0]);
|
|
228
|
+
}
|
|
229
|
+
if (Array.isArray(e) && !e.length) {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
return e;
|
|
233
|
+
}
|
|
234
|
+
export function doubleQuoted(value: any) {
|
|
235
|
+
const uw = unwrapNoBox(value);
|
|
236
|
+
if (typeof value === 'object' && uw?.[doubleQuotedSym]) {
|
|
237
|
+
return {doubleQuoted: true};
|
|
238
|
+
}
|
|
239
|
+
return undefined;
|
|
240
|
+
}
|
|
241
|
+
export function unbox(value: any): any {
|
|
242
|
+
if (typeof value === 'object') {
|
|
243
|
+
return value?.[literal] ?? value;
|
|
244
|
+
}
|
|
245
|
+
return value;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
function seek(xs: any, start: boolean): NodeLocation | null {
|
|
250
|
+
if (!xs) {
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
if (Array.isArray(xs)) {
|
|
254
|
+
const diff = start ? 1 : -1;
|
|
255
|
+
for (let i = start ? 0 : xs.length - 1; i >= 0 && i < xs.length; i += diff) {
|
|
256
|
+
const v = seek(xs[i], start);
|
|
257
|
+
if (v) {
|
|
258
|
+
return v;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
if (typeof xs !== 'object') {
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
return xs._location;
|
|
267
|
+
}
|