@intentius/chant-lexicon-sql 0.0.0-stage → 0.112.1
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/README.md +39 -2
- package/dist/clickhouse/apply/apply.d.ts +82 -0
- package/dist/clickhouse/apply/apply.d.ts.map +1 -0
- package/dist/clickhouse/apply/mutations.d.ts +46 -0
- package/dist/clickhouse/apply/mutations.d.ts.map +1 -0
- package/dist/clickhouse/apply/statements.d.ts +99 -0
- package/dist/clickhouse/apply/statements.d.ts.map +1 -0
- package/dist/clickhouse/catalog-types.d.ts +76 -0
- package/dist/clickhouse/catalog-types.d.ts.map +1 -0
- package/dist/clickhouse/container.d.ts +63 -0
- package/dist/clickhouse/container.d.ts.map +1 -0
- package/dist/clickhouse/engine-syntax.d.ts +43 -0
- package/dist/clickhouse/engine-syntax.d.ts.map +1 -0
- package/dist/clickhouse/entities.d.ts +183 -0
- package/dist/clickhouse/entities.d.ts.map +1 -0
- package/dist/clickhouse/http.d.ts +40 -0
- package/dist/clickhouse/http.d.ts.map +1 -0
- package/dist/clickhouse/import/generator.d.ts +16 -0
- package/dist/clickhouse/import/generator.d.ts.map +1 -0
- package/dist/clickhouse/import/ir.d.ts +52 -0
- package/dist/clickhouse/import/ir.d.ts.map +1 -0
- package/dist/clickhouse/import/live-export.d.ts +28 -0
- package/dist/clickhouse/import/live-export.d.ts.map +1 -0
- package/dist/clickhouse/import/parser.d.ts +10 -0
- package/dist/clickhouse/import/parser.d.ts.map +1 -0
- package/dist/clickhouse/live/bind.d.ts +56 -0
- package/dist/clickhouse/live/bind.d.ts.map +1 -0
- package/dist/clickhouse/live/catalog.d.ts +39 -0
- package/dist/clickhouse/live/catalog.d.ts.map +1 -0
- package/dist/clickhouse/live/describe-resources.d.ts +34 -0
- package/dist/clickhouse/live/describe-resources.d.ts.map +1 -0
- package/dist/clickhouse/overlays/codecs.d.ts +28 -0
- package/dist/clickhouse/overlays/codecs.d.ts.map +1 -0
- package/dist/clickhouse/overlays/engines.d.ts +20 -0
- package/dist/clickhouse/overlays/engines.d.ts.map +1 -0
- package/dist/clickhouse/overlays/kinds.d.ts +38 -0
- package/dist/clickhouse/overlays/kinds.d.ts.map +1 -0
- package/dist/clickhouse/overlays/projections.d.ts +27 -0
- package/dist/clickhouse/overlays/projections.d.ts.map +1 -0
- package/dist/clickhouse/overlays/skip-indexes.d.ts +10 -0
- package/dist/clickhouse/overlays/skip-indexes.d.ts.map +1 -0
- package/dist/clickhouse/overlays/ttl.d.ts +35 -0
- package/dist/clickhouse/overlays/ttl.d.ts.map +1 -0
- package/dist/clickhouse/overlays/types.d.ts +21 -0
- package/dist/clickhouse/overlays/types.d.ts.map +1 -0
- package/dist/clickhouse/ownership.d.ts +71 -0
- package/dist/clickhouse/ownership.d.ts.map +1 -0
- package/dist/clickhouse/parser.d.ts +130 -0
- package/dist/clickhouse/parser.d.ts.map +1 -0
- package/dist/clickhouse/plan/commands.d.ts +26 -0
- package/dist/clickhouse/plan/commands.d.ts.map +1 -0
- package/dist/clickhouse/plan/deep.d.ts +32 -0
- package/dist/clickhouse/plan/deep.d.ts.map +1 -0
- package/dist/clickhouse/plan/diff.d.ts +37 -0
- package/dist/clickhouse/plan/diff.d.ts.map +1 -0
- package/dist/clickhouse/plan/disruption.d.ts +17 -0
- package/dist/clickhouse/plan/disruption.d.ts.map +1 -0
- package/dist/clickhouse/plan/normalize.d.ts +97 -0
- package/dist/clickhouse/plan/normalize.d.ts.map +1 -0
- package/dist/clickhouse/plan/rebuild-handoff.d.ts +38 -0
- package/dist/clickhouse/plan/rebuild-handoff.d.ts.map +1 -0
- package/dist/clickhouse/plan/report.d.ts +6 -0
- package/dist/clickhouse/plan/report.d.ts.map +1 -0
- package/dist/clickhouse/plan/rules.d.ts +60 -0
- package/dist/clickhouse/plan/rules.d.ts.map +1 -0
- package/dist/clickhouse/plan/schema.d.ts +23 -0
- package/dist/clickhouse/plan/schema.d.ts.map +1 -0
- package/dist/clickhouse/plan/server-format.d.ts +12 -0
- package/dist/clickhouse/plan/server-format.d.ts.map +1 -0
- package/dist/clickhouse/rebuild/backfill.d.ts +70 -0
- package/dist/clickhouse/rebuild/backfill.d.ts.map +1 -0
- package/dist/clickhouse/rebuild/observe.d.ts +157 -0
- package/dist/clickhouse/rebuild/observe.d.ts.map +1 -0
- package/dist/clickhouse/rebuild/op.d.ts +108 -0
- package/dist/clickhouse/rebuild/op.d.ts.map +1 -0
- package/dist/clickhouse/rebuild/partitions.d.ts +24 -0
- package/dist/clickhouse/rebuild/partitions.d.ts.map +1 -0
- package/dist/clickhouse/rebuild/receipts.d.ts +76 -0
- package/dist/clickhouse/rebuild/receipts.d.ts.map +1 -0
- package/dist/clickhouse/rebuild/replicas.d.ts +78 -0
- package/dist/clickhouse/rebuild/replicas.d.ts.map +1 -0
- package/dist/clickhouse/rebuild/steps.d.ts +151 -0
- package/dist/clickhouse/rebuild/steps.d.ts.map +1 -0
- package/dist/clickhouse/rebuild/verify.d.ts +51 -0
- package/dist/clickhouse/rebuild/verify.d.ts.map +1 -0
- package/dist/clickhouse/testing/fake-server.d.ts +27 -0
- package/dist/clickhouse/testing/fake-server.d.ts.map +1 -0
- package/dist/clickhouse/testing/roundtrip-schema.d.ts +3 -0
- package/dist/clickhouse/testing/roundtrip-schema.d.ts.map +1 -0
- package/dist/clickhouse/testing/writable-server.d.ts +35 -0
- package/dist/clickhouse/testing/writable-server.d.ts.map +1 -0
- package/dist/clickhouse/tokens.d.ts +15 -0
- package/dist/clickhouse/tokens.d.ts.map +1 -0
- package/dist/clickhouse.d.ts +24 -0
- package/dist/clickhouse.d.ts.map +1 -0
- package/dist/codegen/classifier-page.d.ts +6 -0
- package/dist/codegen/classifier-page.d.ts.map +1 -0
- package/dist/codegen/clickhouse-module.d.ts +23 -0
- package/dist/codegen/clickhouse-module.d.ts.map +1 -0
- package/dist/codegen/docs-cli.d.ts +3 -0
- package/dist/codegen/docs-cli.d.ts.map +1 -0
- package/dist/codegen/docs.d.ts +8 -0
- package/dist/codegen/docs.d.ts.map +1 -0
- package/dist/codegen/generate-cli.d.ts +3 -0
- package/dist/codegen/generate-cli.d.ts.map +1 -0
- package/dist/codegen/generate.d.ts +40 -0
- package/dist/codegen/generate.d.ts.map +1 -0
- package/dist/codegen/package.d.ts +7 -0
- package/dist/codegen/package.d.ts.map +1 -0
- package/dist/codegen/postgres-classifier-page.d.ts +7 -0
- package/dist/codegen/postgres-classifier-page.d.ts.map +1 -0
- package/dist/codegen/postgres-module.d.ts +30 -0
- package/dist/codegen/postgres-module.d.ts.map +1 -0
- package/dist/codegen/registry.d.ts +12 -0
- package/dist/codegen/registry.d.ts.map +1 -0
- package/dist/composites/audit-log-table.d.ts +31 -0
- package/dist/composites/audit-log-table.d.ts.map +1 -0
- package/dist/composites/catalog.d.ts +3 -0
- package/dist/composites/catalog.d.ts.map +1 -0
- package/dist/composites/cdc-mirror.d.ts +32 -0
- package/dist/composites/cdc-mirror.d.ts.map +1 -0
- package/dist/composites/clickhouse.d.ts +7 -0
- package/dist/composites/clickhouse.d.ts.map +1 -0
- package/dist/composites/events-table.d.ts +32 -0
- package/dist/composites/events-table.d.ts.map +1 -0
- package/dist/composites/index.d.ts +9 -0
- package/dist/composites/index.d.ts.map +1 -0
- package/dist/composites/join-table.d.ts +41 -0
- package/dist/composites/join-table.d.ts.map +1 -0
- package/dist/composites/postgres.d.ts +7 -0
- package/dist/composites/postgres.d.ts.map +1 -0
- package/dist/composites/refreshed-view.d.ts +32 -0
- package/dist/composites/refreshed-view.d.ts.map +1 -0
- package/dist/composites/replacing-table.d.ts +34 -0
- package/dist/composites/replacing-table.d.ts.map +1 -0
- package/dist/composites/rollup-view.d.ts +39 -0
- package/dist/composites/rollup-view.d.ts.map +1 -0
- package/dist/composites/sharded-table.d.ts +35 -0
- package/dist/composites/sharded-table.d.ts.map +1 -0
- package/dist/composites/soft-delete-table.d.ts +40 -0
- package/dist/composites/soft-delete-table.d.ts.map +1 -0
- package/dist/composites/tenant-table.d.ts +34 -0
- package/dist/composites/tenant-table.d.ts.map +1 -0
- package/dist/config.d.ts +213 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/core/apply.d.ts +89 -0
- package/dist/core/apply.d.ts.map +1 -0
- package/dist/core/classifier.d.ts +88 -0
- package/dist/core/classifier.d.ts.map +1 -0
- package/dist/core/container.d.ts +45 -0
- package/dist/core/container.d.ts.map +1 -0
- package/dist/core/cursor.d.ts +67 -0
- package/dist/core/cursor.d.ts.map +1 -0
- package/dist/core/diff.d.ts +49 -0
- package/dist/core/diff.d.ts.map +1 -0
- package/dist/core/entity.d.ts +41 -0
- package/dist/core/entity.d.ts.map +1 -0
- package/dist/core/find-templates.d.ts +69 -0
- package/dist/core/find-templates.d.ts.map +1 -0
- package/dist/core/handoff.d.ts +36 -0
- package/dist/core/handoff.d.ts.map +1 -0
- package/dist/core/index.d.ts +61 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/interpolation.d.ts +88 -0
- package/dist/core/interpolation.d.ts.map +1 -0
- package/dist/core/normalize.d.ts +18 -0
- package/dist/core/normalize.d.ts.map +1 -0
- package/dist/core/ownership.d.ts +60 -0
- package/dist/core/ownership.d.ts.map +1 -0
- package/dist/core/receipts.d.ts +28 -0
- package/dist/core/receipts.d.ts.map +1 -0
- package/dist/core/references.d.ts +37 -0
- package/dist/core/references.d.ts.map +1 -0
- package/dist/core/template.d.ts +41 -0
- package/dist/core/template.d.ts.map +1 -0
- package/dist/core/testing/http-stub.d.ts +17 -0
- package/dist/core/testing/http-stub.d.ts.map +1 -0
- package/dist/core/tokens.d.ts +102 -0
- package/dist/core/tokens.d.ts.map +1 -0
- package/dist/coverage.d.ts +25 -0
- package/dist/coverage.d.ts.map +1 -0
- package/dist/detect.d.ts +15 -0
- package/dist/detect.d.ts.map +1 -0
- package/dist/dialects.d.ts +20 -0
- package/dist/dialects.d.ts.map +1 -0
- package/dist/generated/clickhouse-types.d.ts +4380 -0
- package/dist/generated/clickhouse-types.d.ts.map +1 -0
- package/dist/generated/clickhouse.d.ts +11 -0
- package/dist/generated/clickhouse.d.ts.map +1 -0
- package/dist/generated/postgres-types.d.ts +1579 -0
- package/dist/generated/postgres-types.d.ts.map +1 -0
- package/dist/generated/postgres.d.ts +9 -0
- package/dist/generated/postgres.d.ts.map +1 -0
- package/dist/import-generator.d.ts +8 -0
- package/dist/import-generator.d.ts.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/init-templates.d.ts +20 -0
- package/dist/init-templates.d.ts.map +1 -0
- package/dist/integrity.json +61 -0
- package/dist/lint/audit-catalog.d.ts +10 -0
- package/dist/lint/audit-catalog.d.ts.map +1 -0
- package/dist/lint/audit-lineage.d.ts +25 -0
- package/dist/lint/audit-lineage.d.ts.map +1 -0
- package/dist/lint/post-synth/audit-entries.d.ts +8 -0
- package/dist/lint/post-synth/audit-entries.d.ts.map +1 -0
- package/dist/lint/post-synth/clickhouse-helpers.d.ts +85 -0
- package/dist/lint/post-synth/clickhouse-helpers.d.ts.map +1 -0
- package/dist/lint/post-synth/index.d.ts +3 -0
- package/dist/lint/post-synth/index.d.ts.map +1 -0
- package/dist/lint/post-synth/postgres-audit-entries.d.ts +9 -0
- package/dist/lint/post-synth/postgres-audit-entries.d.ts.map +1 -0
- package/dist/lint/post-synth/postgres-helpers.d.ts +89 -0
- package/dist/lint/post-synth/postgres-helpers.d.ts.map +1 -0
- package/dist/lint/post-synth/sql-helpers.d.ts +27 -0
- package/dist/lint/post-synth/sql-helpers.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlch101.d.ts +12 -0
- package/dist/lint/post-synth/sqlch101.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlch102.d.ts +9 -0
- package/dist/lint/post-synth/sqlch102.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlch103.d.ts +10 -0
- package/dist/lint/post-synth/sqlch103.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlch104.d.ts +9 -0
- package/dist/lint/post-synth/sqlch104.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlch105.d.ts +10 -0
- package/dist/lint/post-synth/sqlch105.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlch106.d.ts +11 -0
- package/dist/lint/post-synth/sqlch106.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlch107.d.ts +10 -0
- package/dist/lint/post-synth/sqlch107.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlch108.d.ts +11 -0
- package/dist/lint/post-synth/sqlch108.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlch109.d.ts +10 -0
- package/dist/lint/post-synth/sqlch109.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlch110.d.ts +12 -0
- package/dist/lint/post-synth/sqlch110.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlch111.d.ts +11 -0
- package/dist/lint/post-synth/sqlch111.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlch112.d.ts +12 -0
- package/dist/lint/post-synth/sqlch112.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlch113.d.ts +9 -0
- package/dist/lint/post-synth/sqlch113.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlch114.d.ts +8 -0
- package/dist/lint/post-synth/sqlch114.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlch115.d.ts +13 -0
- package/dist/lint/post-synth/sqlch115.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlch116.d.ts +10 -0
- package/dist/lint/post-synth/sqlch116.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlch117.d.ts +9 -0
- package/dist/lint/post-synth/sqlch117.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlch118.d.ts +10 -0
- package/dist/lint/post-synth/sqlch118.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlch119.d.ts +11 -0
- package/dist/lint/post-synth/sqlch119.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlch120.d.ts +10 -0
- package/dist/lint/post-synth/sqlch120.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlpg101.d.ts +12 -0
- package/dist/lint/post-synth/sqlpg101.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlpg102.d.ts +11 -0
- package/dist/lint/post-synth/sqlpg102.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlpg103.d.ts +11 -0
- package/dist/lint/post-synth/sqlpg103.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlpg104.d.ts +10 -0
- package/dist/lint/post-synth/sqlpg104.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlpg105.d.ts +10 -0
- package/dist/lint/post-synth/sqlpg105.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlpg106.d.ts +9 -0
- package/dist/lint/post-synth/sqlpg106.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlpg107.d.ts +10 -0
- package/dist/lint/post-synth/sqlpg107.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlpg108.d.ts +11 -0
- package/dist/lint/post-synth/sqlpg108.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlpg109.d.ts +11 -0
- package/dist/lint/post-synth/sqlpg109.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlpg110.d.ts +12 -0
- package/dist/lint/post-synth/sqlpg110.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlpg111.d.ts +10 -0
- package/dist/lint/post-synth/sqlpg111.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlpg112.d.ts +10 -0
- package/dist/lint/post-synth/sqlpg112.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlpg113.d.ts +11 -0
- package/dist/lint/post-synth/sqlpg113.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlpg114.d.ts +13 -0
- package/dist/lint/post-synth/sqlpg114.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlpg115.d.ts +13 -0
- package/dist/lint/post-synth/sqlpg115.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlpg116.d.ts +11 -0
- package/dist/lint/post-synth/sqlpg116.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlpg117.d.ts +12 -0
- package/dist/lint/post-synth/sqlpg117.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlpg118.d.ts +12 -0
- package/dist/lint/post-synth/sqlpg118.d.ts.map +1 -0
- package/dist/lint/rules/index.d.ts +12 -0
- package/dist/lint/rules/index.d.ts.map +1 -0
- package/dist/lint/rules/postgres-templates.d.ts +18 -0
- package/dist/lint/rules/postgres-templates.d.ts.map +1 -0
- package/dist/lint/rules/sqlch001.d.ts +12 -0
- package/dist/lint/rules/sqlch001.d.ts.map +1 -0
- package/dist/lint/rules/sqlch002.d.ts +11 -0
- package/dist/lint/rules/sqlch002.d.ts.map +1 -0
- package/dist/lint/rules/sqlch003.d.ts +12 -0
- package/dist/lint/rules/sqlch003.d.ts.map +1 -0
- package/dist/lint/rules/sqlpg001.d.ts +16 -0
- package/dist/lint/rules/sqlpg001.d.ts.map +1 -0
- package/dist/lint/rules/sqlpg002.d.ts +12 -0
- package/dist/lint/rules/sqlpg002.d.ts.map +1 -0
- package/dist/lint/rules/sqlpg003.d.ts +16 -0
- package/dist/lint/rules/sqlpg003.d.ts.map +1 -0
- package/dist/lint/rules/sqlpg004.d.ts +21 -0
- package/dist/lint/rules/sqlpg004.d.ts.map +1 -0
- package/dist/lint/rules/templates.d.ts +23 -0
- package/dist/lint/rules/templates.d.ts.map +1 -0
- package/dist/live-dialect.d.ts +25 -0
- package/dist/live-dialect.d.ts.map +1 -0
- package/dist/lsp/catalog.d.ts +22 -0
- package/dist/lsp/catalog.d.ts.map +1 -0
- package/dist/lsp/completions.d.ts +13 -0
- package/dist/lsp/completions.d.ts.map +1 -0
- package/dist/lsp/hover.d.ts +12 -0
- package/dist/lsp/hover.d.ts.map +1 -0
- package/dist/lsp/postgres-catalog.d.ts +85 -0
- package/dist/lsp/postgres-catalog.d.ts.map +1 -0
- package/dist/lsp/postgres-template.d.ts +35 -0
- package/dist/lsp/postgres-template.d.ts.map +1 -0
- package/dist/lsp/postgres.d.ts +20 -0
- package/dist/lsp/postgres.d.ts.map +1 -0
- package/dist/lsp/refs.d.ts +8 -0
- package/dist/lsp/refs.d.ts.map +1 -0
- package/dist/lsp/registry.d.ts +4 -0
- package/dist/lsp/registry.d.ts.map +1 -0
- package/dist/lsp/template.d.ts +34 -0
- package/dist/lsp/template.d.ts.map +1 -0
- package/dist/manifest.json +8 -0
- package/dist/mcp/index.d.ts +13 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/postgres.d.ts +32 -0
- package/dist/mcp/postgres.d.ts.map +1 -0
- package/dist/meta.json +67 -0
- package/dist/okf/index.md +67 -0
- package/dist/okf/rules/SQLCH001.md +11 -0
- package/dist/okf/rules/SQLCH002.md +11 -0
- package/dist/okf/rules/SQLCH003.md +11 -0
- package/dist/okf/rules/SQLCH101.md +15 -0
- package/dist/okf/rules/SQLCH102.md +11 -0
- package/dist/okf/rules/SQLCH103.md +11 -0
- package/dist/okf/rules/SQLCH104.md +11 -0
- package/dist/okf/rules/SQLCH105.md +11 -0
- package/dist/okf/rules/SQLCH106.md +11 -0
- package/dist/okf/rules/SQLCH107.md +11 -0
- package/dist/okf/rules/SQLCH108.md +15 -0
- package/dist/okf/rules/SQLCH109.md +11 -0
- package/dist/okf/rules/SQLCH110.md +11 -0
- package/dist/okf/rules/SQLCH111.md +11 -0
- package/dist/okf/rules/SQLCH112.md +11 -0
- package/dist/okf/rules/SQLCH113.md +11 -0
- package/dist/okf/rules/SQLCH114.md +11 -0
- package/dist/okf/rules/SQLCH115.md +11 -0
- package/dist/okf/rules/SQLCH116.md +11 -0
- package/dist/okf/rules/SQLCH117.md +15 -0
- package/dist/okf/rules/SQLCH118.md +15 -0
- package/dist/okf/rules/SQLCH119.md +15 -0
- package/dist/okf/rules/SQLCH120.md +15 -0
- package/dist/okf/rules/SQLPG001.md +11 -0
- package/dist/okf/rules/SQLPG002.md +11 -0
- package/dist/okf/rules/SQLPG003.md +11 -0
- package/dist/okf/rules/SQLPG004.md +11 -0
- package/dist/okf/rules/SQLPG101.md +11 -0
- package/dist/okf/rules/SQLPG102.md +11 -0
- package/dist/okf/rules/SQLPG103.md +11 -0
- package/dist/okf/rules/SQLPG104.md +11 -0
- package/dist/okf/rules/SQLPG105.md +11 -0
- package/dist/okf/rules/SQLPG106.md +11 -0
- package/dist/okf/rules/SQLPG107.md +11 -0
- package/dist/okf/rules/SQLPG108.md +11 -0
- package/dist/okf/rules/SQLPG109.md +11 -0
- package/dist/okf/rules/SQLPG110.md +11 -0
- package/dist/okf/rules/SQLPG111.md +11 -0
- package/dist/okf/rules/SQLPG112.md +11 -0
- package/dist/okf/rules/SQLPG113.md +24 -0
- package/dist/okf/rules/SQLPG114.md +11 -0
- package/dist/okf/rules/SQLPG115.md +11 -0
- package/dist/okf/rules/SQLPG116.md +15 -0
- package/dist/okf/rules/SQLPG117.md +11 -0
- package/dist/okf/rules/SQLPG118.md +11 -0
- package/dist/okf/types/Database.md +15 -0
- package/dist/okf/types/MaterializedView.md +14 -0
- package/dist/okf/types/PostgresDomain.md +13 -0
- package/dist/okf/types/PostgresEnum.md +13 -0
- package/dist/okf/types/PostgresExtension.md +13 -0
- package/dist/okf/types/PostgresIndex.md +9 -0
- package/dist/okf/types/PostgresMaterializedView.md +13 -0
- package/dist/okf/types/PostgresSchema.md +13 -0
- package/dist/okf/types/PostgresSequence.md +13 -0
- package/dist/okf/types/PostgresTable.md +13 -0
- package/dist/okf/types/PostgresView.md +13 -0
- package/dist/okf/types/Table.md +15 -0
- package/dist/okf/types/View.md +13 -0
- package/dist/op/activities/clickhouse-apply.d.ts +56 -0
- package/dist/op/activities/clickhouse-apply.d.ts.map +1 -0
- package/dist/op/activities/clickhouse-emulator.d.ts +26 -0
- package/dist/op/activities/clickhouse-emulator.d.ts.map +1 -0
- package/dist/op/activities/clickhouse-rebuild.d.ts +43 -0
- package/dist/op/activities/clickhouse-rebuild.d.ts.map +1 -0
- package/dist/op/activities/index.d.ts +19 -0
- package/dist/op/activities/index.d.ts.map +1 -0
- package/dist/op/activities/postgres-apply.d.ts +69 -0
- package/dist/op/activities/postgres-apply.d.ts.map +1 -0
- package/dist/op/activities/postgres-emulator.d.ts +33 -0
- package/dist/op/activities/postgres-emulator.d.ts.map +1 -0
- package/dist/op/activities/postgres-migration.d.ts +48 -0
- package/dist/op/activities/postgres-migration.d.ts.map +1 -0
- package/dist/op/activity-contracts.d.ts +464 -0
- package/dist/op/activity-contracts.d.ts.map +1 -0
- package/dist/package-cli.d.ts +3 -0
- package/dist/package-cli.d.ts.map +1 -0
- package/dist/plugin.d.ts +12 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/postgres/apply/apply.d.ts +163 -0
- package/dist/postgres/apply/apply.d.ts.map +1 -0
- package/dist/postgres/apply/statements.d.ts +138 -0
- package/dist/postgres/apply/statements.d.ts.map +1 -0
- package/dist/postgres/catalog-types.d.ts +50 -0
- package/dist/postgres/catalog-types.d.ts.map +1 -0
- package/dist/postgres/container.d.ts +23 -0
- package/dist/postgres/container.d.ts.map +1 -0
- package/dist/postgres/entities.d.ts +322 -0
- package/dist/postgres/entities.d.ts.map +1 -0
- package/dist/postgres/entity-types.d.ts +17 -0
- package/dist/postgres/entity-types.d.ts.map +1 -0
- package/dist/postgres/import/generator.d.ts +28 -0
- package/dist/postgres/import/generator.d.ts.map +1 -0
- package/dist/postgres/import/ir.d.ts +24 -0
- package/dist/postgres/import/ir.d.ts.map +1 -0
- package/dist/postgres/import/live-export.d.ts +26 -0
- package/dist/postgres/import/live-export.d.ts.map +1 -0
- package/dist/postgres/keywords.d.ts +22 -0
- package/dist/postgres/keywords.d.ts.map +1 -0
- package/dist/postgres/live/bind.d.ts +76 -0
- package/dist/postgres/live/bind.d.ts.map +1 -0
- package/dist/postgres/live/catalog.d.ts +98 -0
- package/dist/postgres/live/catalog.d.ts.map +1 -0
- package/dist/postgres/live/client.d.ts +32 -0
- package/dist/postgres/live/client.d.ts.map +1 -0
- package/dist/postgres/live/describe-resources.d.ts +41 -0
- package/dist/postgres/live/describe-resources.d.ts.map +1 -0
- package/dist/postgres/migrate/backfill.d.ts +103 -0
- package/dist/postgres/migrate/backfill.d.ts.map +1 -0
- package/dist/postgres/migrate/batches.d.ts +90 -0
- package/dist/postgres/migrate/batches.d.ts.map +1 -0
- package/dist/postgres/migrate/carry.d.ts +196 -0
- package/dist/postgres/migrate/carry.d.ts.map +1 -0
- package/dist/postgres/migrate/handoff.d.ts +46 -0
- package/dist/postgres/migrate/handoff.d.ts.map +1 -0
- package/dist/postgres/migrate/names.d.ts +55 -0
- package/dist/postgres/migrate/names.d.ts.map +1 -0
- package/dist/postgres/migrate/observe.d.ts +139 -0
- package/dist/postgres/migrate/observe.d.ts.map +1 -0
- package/dist/postgres/migrate/op.d.ts +128 -0
- package/dist/postgres/migrate/op.d.ts.map +1 -0
- package/dist/postgres/migrate/receipts.d.ts +63 -0
- package/dist/postgres/migrate/receipts.d.ts.map +1 -0
- package/dist/postgres/migrate/replication.d.ts +80 -0
- package/dist/postgres/migrate/replication.d.ts.map +1 -0
- package/dist/postgres/migrate/steps.d.ts +225 -0
- package/dist/postgres/migrate/steps.d.ts.map +1 -0
- package/dist/postgres/overlays/columns.d.ts +6 -0
- package/dist/postgres/overlays/columns.d.ts.map +1 -0
- package/dist/postgres/overlays/constraints.d.ts +8 -0
- package/dist/postgres/overlays/constraints.d.ts.map +1 -0
- package/dist/postgres/overlays/indexes.d.ts +8 -0
- package/dist/postgres/overlays/indexes.d.ts.map +1 -0
- package/dist/postgres/overlays/kinds.d.ts +48 -0
- package/dist/postgres/overlays/kinds.d.ts.map +1 -0
- package/dist/postgres/overlays/partitioning.d.ts +5 -0
- package/dist/postgres/overlays/partitioning.d.ts.map +1 -0
- package/dist/postgres/overlays/relations.d.ts +6 -0
- package/dist/postgres/overlays/relations.d.ts.map +1 -0
- package/dist/postgres/overlays/storage.d.ts +28 -0
- package/dist/postgres/overlays/storage.d.ts.map +1 -0
- package/dist/postgres/overlays/type-ddl.d.ts +7 -0
- package/dist/postgres/overlays/type-ddl.d.ts.map +1 -0
- package/dist/postgres/overlays/types.d.ts +24 -0
- package/dist/postgres/overlays/types.d.ts.map +1 -0
- package/dist/postgres/parser.d.ts +216 -0
- package/dist/postgres/parser.d.ts.map +1 -0
- package/dist/postgres/plan/commands.d.ts +61 -0
- package/dist/postgres/plan/commands.d.ts.map +1 -0
- package/dist/postgres/plan/deep.d.ts +33 -0
- package/dist/postgres/plan/deep.d.ts.map +1 -0
- package/dist/postgres/plan/diff.d.ts +45 -0
- package/dist/postgres/plan/diff.d.ts.map +1 -0
- package/dist/postgres/plan/disruption.d.ts +14 -0
- package/dist/postgres/plan/disruption.d.ts.map +1 -0
- package/dist/postgres/plan/normalize.d.ts +108 -0
- package/dist/postgres/plan/normalize.d.ts.map +1 -0
- package/dist/postgres/plan/report.d.ts +6 -0
- package/dist/postgres/plan/report.d.ts.map +1 -0
- package/dist/postgres/plan/rules.d.ts +84 -0
- package/dist/postgres/plan/rules.d.ts.map +1 -0
- package/dist/postgres/plan/schema.d.ts +50 -0
- package/dist/postgres/plan/schema.d.ts.map +1 -0
- package/dist/postgres/plan/server-normalize.d.ts +26 -0
- package/dist/postgres/plan/server-normalize.d.ts.map +1 -0
- package/dist/postgres/providers/aurora.d.ts +12 -0
- package/dist/postgres/providers/aurora.d.ts.map +1 -0
- package/dist/postgres/providers/azure.d.ts +14 -0
- package/dist/postgres/providers/azure.d.ts.map +1 -0
- package/dist/postgres/providers/cloud-sql.d.ts +11 -0
- package/dist/postgres/providers/cloud-sql.d.ts.map +1 -0
- package/dist/postgres/providers/index.d.ts +35 -0
- package/dist/postgres/providers/index.d.ts.map +1 -0
- package/dist/postgres/providers/neon.d.ts +13 -0
- package/dist/postgres/providers/neon.d.ts.map +1 -0
- package/dist/postgres/providers/rds.d.ts +10 -0
- package/dist/postgres/providers/rds.d.ts.map +1 -0
- package/dist/postgres/providers/supabase.d.ts +12 -0
- package/dist/postgres/providers/supabase.d.ts.map +1 -0
- package/dist/postgres/providers/types.d.ts +59 -0
- package/dist/postgres/providers/types.d.ts.map +1 -0
- package/dist/postgres/testing/fake-client.d.ts +38 -0
- package/dist/postgres/testing/fake-client.d.ts.map +1 -0
- package/dist/postgres/testing/migration.d.ts +25 -0
- package/dist/postgres/testing/migration.d.ts.map +1 -0
- package/dist/postgres/testing/roundtrip-schema.d.ts +11 -0
- package/dist/postgres/testing/roundtrip-schema.d.ts.map +1 -0
- package/dist/postgres/testing/server.d.ts +17 -0
- package/dist/postgres/testing/server.d.ts.map +1 -0
- package/dist/postgres/testing/writable-server.d.ts +45 -0
- package/dist/postgres/testing/writable-server.d.ts.map +1 -0
- package/dist/postgres/tokens.d.ts +26 -0
- package/dist/postgres/tokens.d.ts.map +1 -0
- package/dist/postgres.d.ts +13 -0
- package/dist/postgres.d.ts.map +1 -0
- package/dist/rules/audit-entries.ts +29 -0
- package/dist/rules/clickhouse-helpers.ts +206 -0
- package/dist/rules/postgres-audit-entries.ts +29 -0
- package/dist/rules/postgres-helpers.ts +126 -0
- package/dist/rules/postgres-templates.ts +36 -0
- package/dist/rules/sql-helpers.ts +53 -0
- package/dist/rules/sqlch001.ts +53 -0
- package/dist/rules/sqlch002.ts +115 -0
- package/dist/rules/sqlch003.ts +68 -0
- package/dist/rules/sqlch101.ts +35 -0
- package/dist/rules/sqlch102.ts +23 -0
- package/dist/rules/sqlch103.ts +45 -0
- package/dist/rules/sqlch104.ts +42 -0
- package/dist/rules/sqlch105.ts +35 -0
- package/dist/rules/sqlch106.ts +27 -0
- package/dist/rules/sqlch107.ts +35 -0
- package/dist/rules/sqlch108.ts +27 -0
- package/dist/rules/sqlch109.ts +21 -0
- package/dist/rules/sqlch110.ts +29 -0
- package/dist/rules/sqlch111.ts +40 -0
- package/dist/rules/sqlch112.ts +30 -0
- package/dist/rules/sqlch113.ts +20 -0
- package/dist/rules/sqlch114.ts +26 -0
- package/dist/rules/sqlch115.ts +31 -0
- package/dist/rules/sqlch116.ts +22 -0
- package/dist/rules/sqlch117.ts +25 -0
- package/dist/rules/sqlch118.ts +26 -0
- package/dist/rules/sqlch119.ts +31 -0
- package/dist/rules/sqlch120.ts +21 -0
- package/dist/rules/sqlpg001.ts +88 -0
- package/dist/rules/sqlpg002.ts +68 -0
- package/dist/rules/sqlpg003.ts +59 -0
- package/dist/rules/sqlpg004.ts +73 -0
- package/dist/rules/sqlpg101.ts +24 -0
- package/dist/rules/sqlpg102.ts +30 -0
- package/dist/rules/sqlpg103.ts +23 -0
- package/dist/rules/sqlpg104.ts +23 -0
- package/dist/rules/sqlpg105.ts +22 -0
- package/dist/rules/sqlpg106.ts +22 -0
- package/dist/rules/sqlpg107.ts +22 -0
- package/dist/rules/sqlpg108.ts +27 -0
- package/dist/rules/sqlpg109.ts +37 -0
- package/dist/rules/sqlpg110.ts +33 -0
- package/dist/rules/sqlpg111.ts +23 -0
- package/dist/rules/sqlpg112.ts +25 -0
- package/dist/rules/sqlpg113.ts +28 -0
- package/dist/rules/sqlpg114.ts +37 -0
- package/dist/rules/sqlpg115.ts +38 -0
- package/dist/rules/sqlpg116.ts +25 -0
- package/dist/rules/sqlpg117.ts +24 -0
- package/dist/rules/sqlpg118.ts +22 -0
- package/dist/rules/templates.ts +35 -0
- package/dist/serializer.d.ts +37 -0
- package/dist/serializer.d.ts.map +1 -0
- package/dist/skill-defs.d.ts +3 -0
- package/dist/skill-defs.d.ts.map +1 -0
- package/dist/spec/catalog.d.ts +125 -0
- package/dist/spec/catalog.d.ts.map +1 -0
- package/dist/spec/fetch.d.ts +43 -0
- package/dist/spec/fetch.d.ts.map +1 -0
- package/dist/spec/pin.d.ts +39 -0
- package/dist/spec/pin.d.ts.map +1 -0
- package/dist/spec/postgres-catalog.d.ts +108 -0
- package/dist/spec/postgres-catalog.d.ts.map +1 -0
- package/dist/spec/postgres-fetch.d.ts +46 -0
- package/dist/spec/postgres-fetch.d.ts.map +1 -0
- package/dist/spec/postgres-pin.d.ts +67 -0
- package/dist/spec/postgres-pin.d.ts.map +1 -0
- package/dist/types/index.d.ts +4386 -0
- package/dist/validate-cli.d.ts +3 -0
- package/dist/validate-cli.d.ts.map +1 -0
- package/dist/validate.d.ts +15 -0
- package/dist/validate.d.ts.map +1 -0
- package/package.json +74 -4
- package/src/clickhouse/apply/apply.ts +288 -0
- package/src/clickhouse/apply/mutations.ts +90 -0
- package/src/clickhouse/apply/statements.ts +393 -0
- package/src/clickhouse/catalog-types.ts +84 -0
- package/src/clickhouse/container.ts +176 -0
- package/src/clickhouse/engine-syntax.test.ts +53 -0
- package/src/clickhouse/engine-syntax.ts +173 -0
- package/src/clickhouse/entities.test.ts +188 -0
- package/src/clickhouse/entities.ts +425 -0
- package/src/clickhouse/http.ts +76 -0
- package/src/clickhouse/import/generator.ts +153 -0
- package/src/clickhouse/import/import.test.ts +157 -0
- package/src/clickhouse/import/ir.ts +171 -0
- package/src/clickhouse/import/live-export.ts +53 -0
- package/src/clickhouse/import/parser.ts +27 -0
- package/src/clickhouse/import/roundtrip.test.ts +90 -0
- package/src/clickhouse/live/bind.ts +126 -0
- package/src/clickhouse/live/catalog.ts +96 -0
- package/src/clickhouse/live/describe-resources.ts +98 -0
- package/src/clickhouse/live/live.test.ts +143 -0
- package/src/clickhouse/live/roundtrip.e2e.test.ts +93 -0
- package/src/clickhouse/overlays/codecs.ts +68 -0
- package/src/clickhouse/overlays/engines.ts +108 -0
- package/src/clickhouse/overlays/kinds.ts +38 -0
- package/src/clickhouse/overlays/projections.ts +36 -0
- package/src/clickhouse/overlays/skip-indexes.ts +44 -0
- package/src/clickhouse/overlays/ttl.ts +55 -0
- package/src/clickhouse/overlays/types.ts +58 -0
- package/src/clickhouse/ownership.test.ts +20 -0
- package/src/clickhouse/ownership.ts +103 -0
- package/src/clickhouse/parser.test.ts +166 -0
- package/src/clickhouse/parser.ts +459 -0
- package/src/clickhouse/plan/commands.ts +101 -0
- package/src/clickhouse/plan/deep.ts +124 -0
- package/src/clickhouse/plan/diff.ts +203 -0
- package/src/clickhouse/plan/disruption.ts +61 -0
- package/src/clickhouse/plan/normalize.ts +352 -0
- package/src/clickhouse/plan/plan-wiring.test.ts +77 -0
- package/src/clickhouse/plan/plan.e2e.test.ts +77 -0
- package/src/clickhouse/plan/plan.test.ts +201 -0
- package/src/clickhouse/plan/rebuild-handoff.ts +59 -0
- package/src/clickhouse/plan/report.ts +19 -0
- package/src/clickhouse/plan/rules.ts +241 -0
- package/src/clickhouse/plan/schema.ts +56 -0
- package/src/clickhouse/plan/server-format.ts +39 -0
- package/src/clickhouse/rebuild/backfill.ts +186 -0
- package/src/clickhouse/rebuild/observe.ts +380 -0
- package/src/clickhouse/rebuild/op.ts +206 -0
- package/src/clickhouse/rebuild/partitions.ts +62 -0
- package/src/clickhouse/rebuild/rebuild-replicated.e2e.test.ts +513 -0
- package/src/clickhouse/rebuild/rebuild.e2e.test.ts +351 -0
- package/src/clickhouse/rebuild/rebuild.test.ts +190 -0
- package/src/clickhouse/rebuild/receipts.ts +143 -0
- package/src/clickhouse/rebuild/replicas.test.ts +70 -0
- package/src/clickhouse/rebuild/replicas.ts +148 -0
- package/src/clickhouse/rebuild/steps.ts +382 -0
- package/src/clickhouse/rebuild/verify.ts +124 -0
- package/src/clickhouse/testdata/NOTICE +5 -0
- package/src/clickhouse/testdata/clickhouse-tests-corpus.json +302 -0
- package/src/clickhouse/testing/fake-server.ts +65 -0
- package/src/clickhouse/testing/roundtrip-schema.ts +25 -0
- package/src/clickhouse/testing/writable-server.ts +141 -0
- package/src/clickhouse/tokens.ts +28 -0
- package/src/clickhouse.ts +63 -0
- package/src/codegen/classifier-page.test.ts +16 -0
- package/src/codegen/classifier-page.ts +76 -0
- package/src/codegen/clickhouse-module.test.ts +63 -0
- package/src/codegen/clickhouse-module.ts +269 -0
- package/src/codegen/docs-cli.ts +4 -0
- package/src/codegen/docs.ts +225 -0
- package/src/codegen/generate-cli.ts +13 -0
- package/src/codegen/generate.ts +126 -0
- package/src/codegen/package.ts +36 -0
- package/src/codegen/postgres-classifier-page.ts +81 -0
- package/src/codegen/postgres-module.test.ts +77 -0
- package/src/codegen/postgres-module.ts +434 -0
- package/src/codegen/registry.ts +36 -0
- package/src/composites/audit-log-table.ts +54 -0
- package/src/composites/catalog.test.ts +61 -0
- package/src/composites/catalog.ts +529 -0
- package/src/composites/cdc-mirror.ts +54 -0
- package/src/composites/clickhouse.ts +7 -0
- package/src/composites/composites.test.ts +758 -0
- package/src/composites/events-table.ts +49 -0
- package/src/composites/index.ts +9 -0
- package/src/composites/join-table.ts +57 -0
- package/src/composites/postgres.ts +7 -0
- package/src/composites/refreshed-view.ts +46 -0
- package/src/composites/replacing-table.ts +49 -0
- package/src/composites/rollup-view.ts +55 -0
- package/src/composites/sharded-table.ts +49 -0
- package/src/composites/soft-delete-table.ts +61 -0
- package/src/composites/tenant-table.ts +50 -0
- package/src/config.ts +157 -0
- package/src/core/apply.ts +153 -0
- package/src/core/classifier.ts +186 -0
- package/src/core/container.ts +93 -0
- package/src/core/core.test.ts +254 -0
- package/src/core/cursor.ts +189 -0
- package/src/core/diff.ts +72 -0
- package/src/core/entity.ts +85 -0
- package/src/core/find-templates.ts +158 -0
- package/src/core/handoff.ts +44 -0
- package/src/core/index.ts +61 -0
- package/src/core/interpolation.ts +225 -0
- package/src/core/normalize.ts +39 -0
- package/src/core/ownership.test.ts +36 -0
- package/src/core/ownership.ts +133 -0
- package/src/core/receipts.ts +29 -0
- package/src/core/references.ts +74 -0
- package/src/core/template.ts +83 -0
- package/src/core/testing/http-stub.ts +33 -0
- package/src/core/tokens.ts +252 -0
- package/src/coverage.ts +64 -0
- package/src/detect.ts +32 -0
- package/src/dialects.ts +21 -0
- package/src/generated/clickhouse-types.ts +4386 -0
- package/src/generated/clickhouse.ts +2476 -0
- package/src/generated/index.d.ts +4386 -0
- package/src/generated/lexicon-sql.json +67 -0
- package/src/generated/postgres-types.ts +1190 -0
- package/src/generated/postgres.ts +1039 -0
- package/src/import-generator.ts +18 -0
- package/src/index.ts +21 -0
- package/src/init-templates.test.ts +108 -0
- package/src/init-templates.ts +327 -0
- package/src/lint/audit-catalog.ts +73 -0
- package/src/lint/audit-lineage.ts +47 -0
- package/src/lint/post-synth/audit-entries.ts +29 -0
- package/src/lint/post-synth/clickhouse-checks.test.ts +278 -0
- package/src/lint/post-synth/clickhouse-helpers.ts +206 -0
- package/src/lint/post-synth/index.ts +81 -0
- package/src/lint/post-synth/post-synth.test.ts +33 -0
- package/src/lint/post-synth/postgres-audit-entries.ts +29 -0
- package/src/lint/post-synth/postgres-checks.test.ts +257 -0
- package/src/lint/post-synth/postgres-helpers.ts +126 -0
- package/src/lint/post-synth/sql-helpers.ts +53 -0
- package/src/lint/post-synth/sqlch101.ts +35 -0
- package/src/lint/post-synth/sqlch102.ts +23 -0
- package/src/lint/post-synth/sqlch103.ts +45 -0
- package/src/lint/post-synth/sqlch104.ts +42 -0
- package/src/lint/post-synth/sqlch105.ts +35 -0
- package/src/lint/post-synth/sqlch106.ts +27 -0
- package/src/lint/post-synth/sqlch107.ts +35 -0
- package/src/lint/post-synth/sqlch108.ts +27 -0
- package/src/lint/post-synth/sqlch109.ts +21 -0
- package/src/lint/post-synth/sqlch110.ts +29 -0
- package/src/lint/post-synth/sqlch111.ts +40 -0
- package/src/lint/post-synth/sqlch112.ts +30 -0
- package/src/lint/post-synth/sqlch113.ts +20 -0
- package/src/lint/post-synth/sqlch114.ts +26 -0
- package/src/lint/post-synth/sqlch115.ts +31 -0
- package/src/lint/post-synth/sqlch116.ts +22 -0
- package/src/lint/post-synth/sqlch117.ts +25 -0
- package/src/lint/post-synth/sqlch118.ts +26 -0
- package/src/lint/post-synth/sqlch119.ts +31 -0
- package/src/lint/post-synth/sqlch120.ts +21 -0
- package/src/lint/post-synth/sqlpg101.ts +24 -0
- package/src/lint/post-synth/sqlpg102.ts +30 -0
- package/src/lint/post-synth/sqlpg103.ts +23 -0
- package/src/lint/post-synth/sqlpg104.ts +23 -0
- package/src/lint/post-synth/sqlpg105.ts +22 -0
- package/src/lint/post-synth/sqlpg106.ts +22 -0
- package/src/lint/post-synth/sqlpg107.ts +22 -0
- package/src/lint/post-synth/sqlpg108.ts +27 -0
- package/src/lint/post-synth/sqlpg109.ts +37 -0
- package/src/lint/post-synth/sqlpg110.ts +33 -0
- package/src/lint/post-synth/sqlpg111.ts +23 -0
- package/src/lint/post-synth/sqlpg112.ts +25 -0
- package/src/lint/post-synth/sqlpg113.ts +28 -0
- package/src/lint/post-synth/sqlpg114.ts +37 -0
- package/src/lint/post-synth/sqlpg115.ts +38 -0
- package/src/lint/post-synth/sqlpg116.ts +25 -0
- package/src/lint/post-synth/sqlpg117.ts +24 -0
- package/src/lint/post-synth/sqlpg118.ts +22 -0
- package/src/lint/rules/index.ts +13 -0
- package/src/lint/rules/postgres-templates.ts +36 -0
- package/src/lint/rules/rules.test.ts +228 -0
- package/src/lint/rules/sqlch001.ts +53 -0
- package/src/lint/rules/sqlch002.ts +115 -0
- package/src/lint/rules/sqlch003.ts +68 -0
- package/src/lint/rules/sqlpg001.ts +88 -0
- package/src/lint/rules/sqlpg002.ts +68 -0
- package/src/lint/rules/sqlpg003.ts +59 -0
- package/src/lint/rules/sqlpg004.ts +73 -0
- package/src/lint/rules/templates.ts +35 -0
- package/src/live-dialect.ts +37 -0
- package/src/lsp/catalog.ts +60 -0
- package/src/lsp/completions.test.ts +111 -0
- package/src/lsp/completions.ts +128 -0
- package/src/lsp/diagnostics.test.ts +26 -0
- package/src/lsp/hover.test.ts +90 -0
- package/src/lsp/hover.ts +113 -0
- package/src/lsp/postgres-catalog.ts +234 -0
- package/src/lsp/postgres-template.ts +161 -0
- package/src/lsp/postgres.test.ts +150 -0
- package/src/lsp/postgres.ts +270 -0
- package/src/lsp/refs.ts +53 -0
- package/src/lsp/registry.ts +19 -0
- package/src/lsp/template.ts +166 -0
- package/src/mcp/index.ts +304 -0
- package/src/mcp/mcp.test.ts +184 -0
- package/src/mcp/postgres.ts +125 -0
- package/src/op/activities/clickhouse-apply.e2e.test.ts +150 -0
- package/src/op/activities/clickhouse-apply.test.ts +265 -0
- package/src/op/activities/clickhouse-apply.ts +113 -0
- package/src/op/activities/clickhouse-emulator.test.ts +23 -0
- package/src/op/activities/clickhouse-emulator.ts +37 -0
- package/src/op/activities/clickhouse-rebuild.ts +136 -0
- package/src/op/activities/index.ts +50 -0
- package/src/op/activities/postgres-apply.e2e.test.ts +184 -0
- package/src/op/activities/postgres-apply.test.ts +304 -0
- package/src/op/activities/postgres-apply.ts +170 -0
- package/src/op/activities/postgres-emulator.test.ts +26 -0
- package/src/op/activities/postgres-emulator.ts +44 -0
- package/src/op/activities/postgres-migration.ts +182 -0
- package/src/op/activity-contracts.ts +210 -0
- package/src/package-cli.ts +17 -0
- package/src/plugin.test.ts +74 -0
- package/src/plugin.ts +242 -0
- package/src/postgres/apply/apply.ts +582 -0
- package/src/postgres/apply/statements.test.ts +155 -0
- package/src/postgres/apply/statements.ts +603 -0
- package/src/postgres/catalog-types.ts +59 -0
- package/src/postgres/container.ts +72 -0
- package/src/postgres/entities.test.ts +170 -0
- package/src/postgres/entities.ts +1016 -0
- package/src/postgres/entity-types.ts +18 -0
- package/src/postgres/import/generator.ts +176 -0
- package/src/postgres/import/import.test.ts +71 -0
- package/src/postgres/import/ir.ts +67 -0
- package/src/postgres/import/live-export.ts +53 -0
- package/src/postgres/import/live-warnings.test.ts +45 -0
- package/src/postgres/keywords.ts +40 -0
- package/src/postgres/live/bind.ts +146 -0
- package/src/postgres/live/catalog.ts +581 -0
- package/src/postgres/live/client.ts +84 -0
- package/src/postgres/live/describe-resources.ts +111 -0
- package/src/postgres/live/live.test.ts +198 -0
- package/src/postgres/live/roundtrip.e2e.test.ts +111 -0
- package/src/postgres/migrate/backfill.ts +233 -0
- package/src/postgres/migrate/batches.e2e.test.ts +163 -0
- package/src/postgres/migrate/batches.test.ts +36 -0
- package/src/postgres/migrate/batches.ts +159 -0
- package/src/postgres/migrate/carry.e2e.test.ts +335 -0
- package/src/postgres/migrate/carry.test.ts +103 -0
- package/src/postgres/migrate/carry.ts +653 -0
- package/src/postgres/migrate/handoff.ts +73 -0
- package/src/postgres/migrate/kinds.e2e.test.ts +204 -0
- package/src/postgres/migrate/migrate.e2e.test.ts +362 -0
- package/src/postgres/migrate/migrate.test.ts +322 -0
- package/src/postgres/migrate/names.ts +93 -0
- package/src/postgres/migrate/observe.ts +521 -0
- package/src/postgres/migrate/op.ts +242 -0
- package/src/postgres/migrate/receipts.ts +135 -0
- package/src/postgres/migrate/replication.ts +151 -0
- package/src/postgres/migrate/steps.ts +657 -0
- package/src/postgres/overlays/columns.ts +34 -0
- package/src/postgres/overlays/constraints.ts +56 -0
- package/src/postgres/overlays/indexes.ts +27 -0
- package/src/postgres/overlays/kinds.ts +53 -0
- package/src/postgres/overlays/partitioning.ts +26 -0
- package/src/postgres/overlays/relations.ts +29 -0
- package/src/postgres/overlays/storage.ts +75 -0
- package/src/postgres/overlays/type-ddl.ts +38 -0
- package/src/postgres/overlays/types.ts +56 -0
- package/src/postgres/parser.test.ts +214 -0
- package/src/postgres/parser.ts +1062 -0
- package/src/postgres/plan/commands.ts +124 -0
- package/src/postgres/plan/deep.ts +177 -0
- package/src/postgres/plan/diff.ts +323 -0
- package/src/postgres/plan/disruption.ts +52 -0
- package/src/postgres/plan/normalize.test.ts +148 -0
- package/src/postgres/plan/normalize.ts +542 -0
- package/src/postgres/plan/plan.e2e.test.ts +117 -0
- package/src/postgres/plan/plan.test.ts +244 -0
- package/src/postgres/plan/report.ts +24 -0
- package/src/postgres/plan/rules.ts +276 -0
- package/src/postgres/plan/schema.ts +114 -0
- package/src/postgres/plan/server-normalize.ts +123 -0
- package/src/postgres/providers/aurora.ts +45 -0
- package/src/postgres/providers/azure.ts +54 -0
- package/src/postgres/providers/cloud-sql.ts +42 -0
- package/src/postgres/providers/index.ts +90 -0
- package/src/postgres/providers/neon.ts +45 -0
- package/src/postgres/providers/providers.test.ts +136 -0
- package/src/postgres/providers/rds.ts +48 -0
- package/src/postgres/providers/supabase.ts +46 -0
- package/src/postgres/providers/types.ts +70 -0
- package/src/postgres/testdata/NOTICE +31 -0
- package/src/postgres/testdata/postgres-regress-corpus.json +460 -0
- package/src/postgres/testing/fake-client.ts +42 -0
- package/src/postgres/testing/migration.ts +52 -0
- package/src/postgres/testing/roundtrip-schema.ts +46 -0
- package/src/postgres/testing/server.ts +58 -0
- package/src/postgres/testing/writable-server.ts +188 -0
- package/src/postgres/tokens.ts +46 -0
- package/src/postgres.ts +75 -0
- package/src/serializer.test.ts +128 -0
- package/src/serializer.ts +148 -0
- package/src/skill-defs.test.ts +81 -0
- package/src/skill-defs.ts +102 -0
- package/src/skills/chant-sql-plan.md +123 -0
- package/src/skills/chant-sql-postgres-migration.md +126 -0
- package/src/skills/chant-sql-postgres-plan.md +194 -0
- package/src/skills/chant-sql-postgres.md +165 -0
- package/src/skills/chant-sql-rebuild.md +68 -0
- package/src/skills/chant-sql.md +123 -0
- package/src/spec/catalog.e2e.test.ts +29 -0
- package/src/spec/catalog.test.ts +56 -0
- package/src/spec/catalog.ts +311 -0
- package/src/spec/clickhouse-catalog.snapshot.json +5246 -0
- package/src/spec/fetch.test.ts +77 -0
- package/src/spec/fetch.ts +112 -0
- package/src/spec/pin.ts +47 -0
- package/src/spec/postgres-catalog-14.snapshot.json +3494 -0
- package/src/spec/postgres-catalog-15.snapshot.json +3529 -0
- package/src/spec/postgres-catalog-16.snapshot.json +3597 -0
- package/src/spec/postgres-catalog-17.snapshot.json +3656 -0
- package/src/spec/postgres-catalog-18.snapshot.json +3747 -0
- package/src/spec/postgres-catalog.test.ts +43 -0
- package/src/spec/postgres-catalog.ts +301 -0
- package/src/spec/postgres-fetch.test.ts +75 -0
- package/src/spec/postgres-fetch.ts +112 -0
- package/src/spec/postgres-pin.test.ts +64 -0
- package/src/spec/postgres-pin.ts +101 -0
- package/src/typecheck.test.ts +104 -0
- package/src/validate-cli.ts +6 -0
- package/src/validate.ts +149 -0
package/src/mcp/index.ts
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP contributions for the sql lexicon (chant #3210). Tools answer from the
|
|
3
|
+
* committed ClickHouse catalog and the tag parser, so an agent can look up an
|
|
4
|
+
* engine, a type or a setting, and check a statement, without a server.
|
|
5
|
+
*
|
|
6
|
+
* Tools register as `sql:<verb>` and resources as `chant://sql/<path>`.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { McpResourceContribution, McpToolContribution } from "@intentius/chant/mcp/types";
|
|
10
|
+
import { createCatalogResource, createDiffTool } from "@intentius/chant/lexicon-plugin-helpers";
|
|
11
|
+
import { sqlSerializer } from "../serializer";
|
|
12
|
+
import { catalogIndex } from "../lsp/catalog";
|
|
13
|
+
import { database, table, view } from "../clickhouse/entities";
|
|
14
|
+
import { SqlSyntaxError } from "../clickhouse/tokens";
|
|
15
|
+
import { existsSync, readFileSync } from "fs";
|
|
16
|
+
import { diffSchemas } from "../clickhouse/plan/diff";
|
|
17
|
+
import { renderDiff } from "../clickhouse/plan/report";
|
|
18
|
+
import { rebuildOpSuggestions } from "../clickhouse/plan/rebuild-handoff";
|
|
19
|
+
import { CLASSIFIER_RULES } from "../clickhouse/plan/rules";
|
|
20
|
+
import { schemaFromBuildFile, schemaFromBuildOutput } from "../clickhouse/plan/schema";
|
|
21
|
+
import { asMajor, POSTGRES_KINDS, POSTGRES_TAGS, postgresLookup, postgresMcpResources, postgresParse, postgresSearch } from "./postgres";
|
|
22
|
+
import { diffPgSchemas } from "../postgres/plan/diff";
|
|
23
|
+
import { renderPgDiff } from "../postgres/plan/report";
|
|
24
|
+
import { PG_CLASSIFIER_RULES } from "../postgres/plan/rules";
|
|
25
|
+
import { pgSchemaFromBuildFile, pgSchemaFromBuildOutput } from "../postgres/plan/schema";
|
|
26
|
+
import { migrationOpSuggestions } from "../postgres/migrate/handoff";
|
|
27
|
+
import { CLICKHOUSE_IMAGE_DIGEST, CLICKHOUSE_VERSION, clickhouseImage } from "../spec/pin";
|
|
28
|
+
|
|
29
|
+
const KINDS = ["engine", "database-engine", "type", "codec", "index-type", "setting", "function", "format"] as const;
|
|
30
|
+
type Kind = (typeof KINDS)[number];
|
|
31
|
+
|
|
32
|
+
const kindProp = {
|
|
33
|
+
type: "string",
|
|
34
|
+
enum: [...new Set([...KINDS, ...POSTGRES_KINDS])],
|
|
35
|
+
description: `Which part of the catalog. ClickHouse: ${KINDS.join(", ")}. Postgres: ${POSTGRES_KINDS.join(", ")}`,
|
|
36
|
+
};
|
|
37
|
+
const dialectProp = { type: "string", enum: ["clickhouse", "postgres"], description: "The dialect to answer for (default clickhouse)" };
|
|
38
|
+
const majorProp = { type: "number", description: "Postgres only: answer for this major (14 to 18; for classify-change, the server's major); omitted, every major, with since/until on names not in all" };
|
|
39
|
+
|
|
40
|
+
function asDialect(value: unknown): "clickhouse" | "postgres" {
|
|
41
|
+
if (value === undefined || value === "clickhouse") return "clickhouse";
|
|
42
|
+
if (value === "postgres") return "postgres";
|
|
43
|
+
throw new Error("dialect must be clickhouse or postgres");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type Row = { name: string; summary?: string };
|
|
47
|
+
|
|
48
|
+
function rows(kind: Kind): Row[] {
|
|
49
|
+
const index = catalogIndex();
|
|
50
|
+
if (!index) throw new Error("the ClickHouse catalog snapshot could not be read");
|
|
51
|
+
const { catalog } = index;
|
|
52
|
+
switch (kind) {
|
|
53
|
+
case "engine":
|
|
54
|
+
return catalog.tableEngines;
|
|
55
|
+
case "database-engine":
|
|
56
|
+
return catalog.databaseEngines;
|
|
57
|
+
case "type":
|
|
58
|
+
return catalog.typeFamilies;
|
|
59
|
+
case "codec":
|
|
60
|
+
return catalog.codecs;
|
|
61
|
+
case "index-type":
|
|
62
|
+
return catalog.skipIndexTypes;
|
|
63
|
+
case "setting":
|
|
64
|
+
return [
|
|
65
|
+
...catalog.mergeTreeSettings.map((s) => ({ ...s, scope: "merge-tree" })),
|
|
66
|
+
...catalog.querySettings.map((s) => ({ ...s, scope: "query" })),
|
|
67
|
+
];
|
|
68
|
+
case "function":
|
|
69
|
+
return catalog.functions;
|
|
70
|
+
case "format":
|
|
71
|
+
return catalog.formats;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function asKind(value: unknown): Kind {
|
|
76
|
+
if (!KINDS.includes(value as Kind)) throw new Error(`kind must be one of: ${KINDS.join(", ")}`);
|
|
77
|
+
return value as Kind;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const lookupTool: McpToolContribution = {
|
|
81
|
+
name: "lookup",
|
|
82
|
+
description:
|
|
83
|
+
"Look up a catalog entry by name. ClickHouse (default): engine, type family, codec, skip index type, setting, function or format, from the pinned server (" +
|
|
84
|
+
CLICKHOUSE_VERSION +
|
|
85
|
+
"). Postgres (dialect postgres): type or alias, index or table access method, storage parameter, setting, function, key word or extension, from the pinned servers of majors 14 to 18, with since/until. Returns every catalog row with that name, or the closest names when there is none.",
|
|
86
|
+
inputSchema: { type: "object", properties: { dialect: dialectProp, kind: kindProp, name: { type: "string" }, major: majorProp }, required: ["kind", "name"] },
|
|
87
|
+
async handler(params) {
|
|
88
|
+
if (asDialect(params.dialect) === "postgres") return postgresLookup(params);
|
|
89
|
+
const kind = asKind(params.kind);
|
|
90
|
+
const name = String(params.name ?? "");
|
|
91
|
+
const all = rows(kind);
|
|
92
|
+
const exact = all.filter((r) => r.name === name);
|
|
93
|
+
const found = exact.length ? exact : all.filter((r) => r.name.toLowerCase() === name.toLowerCase());
|
|
94
|
+
if (found.length) return { kind, version: CLICKHOUSE_VERSION, matches: found };
|
|
95
|
+
const near = all.filter((r) => r.name.toLowerCase().includes(name.toLowerCase())).slice(0, 10).map((r) => r.name);
|
|
96
|
+
return { kind, version: CLICKHOUSE_VERSION, matches: [], closest: near };
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const searchTool: McpToolContribution = {
|
|
101
|
+
name: "search",
|
|
102
|
+
description: "Search one part of a dialect's catalog by a name substring. Returns names with the first line of their description.",
|
|
103
|
+
inputSchema: {
|
|
104
|
+
type: "object",
|
|
105
|
+
properties: { dialect: dialectProp, kind: kindProp, query: { type: "string" }, major: majorProp, limit: { type: "number", description: "At most this many results (default 25)" } },
|
|
106
|
+
required: ["kind", "query"],
|
|
107
|
+
},
|
|
108
|
+
async handler(params) {
|
|
109
|
+
if (asDialect(params.dialect) === "postgres") return postgresSearch(params);
|
|
110
|
+
const kind = asKind(params.kind);
|
|
111
|
+
const query = String(params.query ?? "").toLowerCase();
|
|
112
|
+
const limit = Math.max(1, Math.min(200, Number(params.limit ?? 25)));
|
|
113
|
+
const hits = rows(kind).filter((r) => r.name.toLowerCase().includes(query));
|
|
114
|
+
return {
|
|
115
|
+
kind,
|
|
116
|
+
total: hits.length,
|
|
117
|
+
results: hits.slice(0, limit).map((r) => ({ name: r.name, ...(typeof r.summary === "string" ? { summary: r.summary } : {}) })),
|
|
118
|
+
};
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const parseTool: McpToolContribution = {
|
|
123
|
+
name: "parse-ddl",
|
|
124
|
+
description:
|
|
125
|
+
"Parse one CREATE statement the way its tag does (dialect clickhouse, the default: table, view, database; dialect postgres: schema, table, index, view, sequence, type, domain, extension), and return the entity it builds (columns, engine, keys, settings, and for a view its lineage). A statement that does not parse comes back as the error with its line and column, the same one SQLCH001 (ClickHouse) or SQLPG001 (Postgres) reports. The statement is plain DDL: there are no interpolations.",
|
|
126
|
+
inputSchema: {
|
|
127
|
+
type: "object",
|
|
128
|
+
properties: {
|
|
129
|
+
dialect: dialectProp,
|
|
130
|
+
tag: { type: "string", enum: [...new Set(["table", "view", "database", ...POSTGRES_TAGS])], description: "The tag the statement belongs in (ClickHouse: table, view, database; Postgres: " + POSTGRES_TAGS.join(", ") + ")" },
|
|
131
|
+
ddl: { type: "string", description: "The CREATE statement" },
|
|
132
|
+
},
|
|
133
|
+
required: ["tag", "ddl"],
|
|
134
|
+
},
|
|
135
|
+
async handler(params) {
|
|
136
|
+
const ddl = String(params.ddl ?? "");
|
|
137
|
+
const tag = String(params.tag);
|
|
138
|
+
if (asDialect(params.dialect) === "postgres") return postgresParse(tag, ddl, position);
|
|
139
|
+
const build = tag === "table" ? table : tag === "view" ? view : tag === "database" ? database : undefined;
|
|
140
|
+
if (!build) throw new Error("tag must be table, view or database");
|
|
141
|
+
const strings = Object.assign([ddl], { raw: [ddl] }) as unknown as TemplateStringsArray;
|
|
142
|
+
try {
|
|
143
|
+
const entity = build(strings);
|
|
144
|
+
return { ok: true, entityType: entity.entityType, name: entity.sqlName, props: JSON.parse(JSON.stringify(entity.props)) };
|
|
145
|
+
} catch (err) {
|
|
146
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
147
|
+
const offset = (err as { offset?: number }).offset;
|
|
148
|
+
const where = typeof offset === "number" ? position(ddl, offset) : undefined;
|
|
149
|
+
const syntax = err instanceof SqlSyntaxError || (err as Error).name === "SqlTemplateError";
|
|
150
|
+
return { ok: false, rule: syntax ? "SQLCH001" : undefined, message, ...(where ?? {}) };
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const classifyTool: McpToolContribution = {
|
|
156
|
+
name: "classify-change",
|
|
157
|
+
description:
|
|
158
|
+
"Classify the schema change between two revisions of a sql lexicon build, offline. Each side is a `chant build` output (a path to the file, or its JSON text); the dialect is the one the output names, or `dialect`. ClickHouse: every change with its class (create, drop, metadata, rewrite, rebuild), the SQLCH2xx rule and the ClickHouse restriction behind it with its documentation link, the rebuilds a plan must refuse in place with the ClickHouseRebuildOp declaration to run each one as, rename hints, and a rendered report. Postgres: every change with its class by the lock it takes (create, metadata, validate, concurrently, rewrite, expand, drop), the SQLPG2xx rule and its restriction with its Postgres documentation link, the `refused` changes that can only be made as expand and contract with the PostgresMigrationOp declaration to run each column rename or type change across kinds as (`migrationOps`), rename hints and a rendered report; `major` is the server's major (default the newest pinned).",
|
|
159
|
+
inputSchema: {
|
|
160
|
+
type: "object",
|
|
161
|
+
properties: {
|
|
162
|
+
before: { type: "string", description: "The earlier build output: a file path or the JSON text" },
|
|
163
|
+
after: { type: "string", description: "The later build output: a file path or the JSON text" },
|
|
164
|
+
dialect: dialectProp,
|
|
165
|
+
major: majorProp,
|
|
166
|
+
},
|
|
167
|
+
required: ["before", "after"],
|
|
168
|
+
},
|
|
169
|
+
async handler(params) {
|
|
170
|
+
if (buildDialect(params) === "postgres") return classifyPostgres(params);
|
|
171
|
+
const side = (v: unknown) => {
|
|
172
|
+
const text = String(v ?? "");
|
|
173
|
+
return !text.trimStart().startsWith("{") && existsSync(text) ? schemaFromBuildFile(text) : schemaFromBuildOutput(text);
|
|
174
|
+
};
|
|
175
|
+
const after = side(params.after);
|
|
176
|
+
const plain = diffSchemas(side(params.before), after);
|
|
177
|
+
const rebuildOps = rebuildOpSuggestions(plain, new Map(after.map((o) => [o.key, o.canonical])), "<env>");
|
|
178
|
+
const diff = rebuildOps.length > 0 ? { ...plain, rebuildOps } : plain;
|
|
179
|
+
const classes: Record<string, number> = {};
|
|
180
|
+
for (const c of diff.changes) classes[c.class] = (classes[c.class] ?? 0) + 1;
|
|
181
|
+
return {
|
|
182
|
+
summary: classes,
|
|
183
|
+
changes: diff.changes.map((c) => ({ ...c, restriction: CLASSIFIER_RULES[c.rule].restriction, cite: CLASSIFIER_RULES[c.rule].cite })),
|
|
184
|
+
rebuilds: diff.rebuilds,
|
|
185
|
+
rebuildOps,
|
|
186
|
+
hints: diff.hints,
|
|
187
|
+
report: renderDiff(diff),
|
|
188
|
+
};
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
/** The dialect a classify call is for: `dialect`, else the one either build output names, else ClickHouse. */
|
|
193
|
+
function buildDialect(params: Record<string, unknown>): "clickhouse" | "postgres" {
|
|
194
|
+
if (params.dialect !== undefined) return asDialect(params.dialect);
|
|
195
|
+
for (const v of [params.after, params.before]) {
|
|
196
|
+
const text = String(v ?? "");
|
|
197
|
+
try {
|
|
198
|
+
const json = text.trimStart().startsWith("{") ? text : existsSync(text) ? readFileSync(text, "utf-8") : "";
|
|
199
|
+
const d = (JSON.parse(json) as { dialect?: string }).dialect;
|
|
200
|
+
if (d === "postgres") return "postgres";
|
|
201
|
+
if (d === "clickhouse") return "clickhouse";
|
|
202
|
+
} catch {
|
|
203
|
+
// Not JSON we can read: the schema reader reports it.
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return "clickhouse";
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function classifyPostgres(params: Record<string, unknown>): unknown {
|
|
210
|
+
const side = (v: unknown) => {
|
|
211
|
+
const text = String(v ?? "");
|
|
212
|
+
return !text.trimStart().startsWith("{") && existsSync(text) ? pgSchemaFromBuildFile(text) : pgSchemaFromBuildOutput(text);
|
|
213
|
+
};
|
|
214
|
+
const after = side(params.after);
|
|
215
|
+
const plain = diffPgSchemas(side(params.before), after, { major: asMajor(params.major) });
|
|
216
|
+
const migrationOps = migrationOpSuggestions(plain.refused, new Map(after.map((o) => [o.key, o.canonical])), "<env>");
|
|
217
|
+
const diff = migrationOps.length > 0 ? { ...plain, migrationOps } : plain;
|
|
218
|
+
const classes: Record<string, number> = {};
|
|
219
|
+
for (const c of diff.changes) classes[c.class] = (classes[c.class] ?? 0) + 1;
|
|
220
|
+
return {
|
|
221
|
+
dialect: "postgres",
|
|
222
|
+
summary: classes,
|
|
223
|
+
changes: diff.changes.map((c) => ({ ...c, restriction: PG_CLASSIFIER_RULES[c.rule].restriction, cite: PG_CLASSIFIER_RULES[c.rule].cite })),
|
|
224
|
+
refused: diff.refused.map((c) => ({
|
|
225
|
+
object: c.object,
|
|
226
|
+
field: c.field,
|
|
227
|
+
rule: c.rule,
|
|
228
|
+
advice: "No in-place change keeps old readers working: run it as expand and contract (add the new, write both, backfill, move readers, drop the old), as a migration Op.",
|
|
229
|
+
})),
|
|
230
|
+
migrationOps,
|
|
231
|
+
hints: diff.hints,
|
|
232
|
+
report: renderPgDiff(diff),
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function position(text: string, offset: number): { line: number; column: number } {
|
|
237
|
+
const before = text.slice(0, offset).split("\n");
|
|
238
|
+
return { line: before.length, column: before[before.length - 1]!.length + 1 };
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** The tools the sql lexicon contributes. */
|
|
242
|
+
export function sqlMcpTools(): McpToolContribution[] {
|
|
243
|
+
return [
|
|
244
|
+
lookupTool,
|
|
245
|
+
searchTool,
|
|
246
|
+
parseTool,
|
|
247
|
+
classifyTool,
|
|
248
|
+
createDiffTool(sqlSerializer, "Compare current sql build output against the previous build", "sql"),
|
|
249
|
+
];
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const json = (value: unknown) => JSON.stringify(value, null, 2);
|
|
253
|
+
|
|
254
|
+
function catalogResource(uri: string, name: string, description: string, read: () => unknown): McpResourceContribution {
|
|
255
|
+
return {
|
|
256
|
+
uri,
|
|
257
|
+
name,
|
|
258
|
+
description,
|
|
259
|
+
mimeType: "application/json",
|
|
260
|
+
async handler() {
|
|
261
|
+
return json(read());
|
|
262
|
+
},
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const need = () => {
|
|
267
|
+
const index = catalogIndex();
|
|
268
|
+
if (!index) throw new Error("the ClickHouse catalog snapshot could not be read");
|
|
269
|
+
return index.catalog;
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
/** The resources the sql lexicon contributes. */
|
|
273
|
+
export function sqlMcpResources(): McpResourceContribution[] {
|
|
274
|
+
return [
|
|
275
|
+
// `generated/` sits beside plugin.ts, which is where the helper looks.
|
|
276
|
+
createCatalogResource(
|
|
277
|
+
new URL("../plugin.ts", import.meta.url).href,
|
|
278
|
+
"SQL Entity Catalog",
|
|
279
|
+
"The entity kinds the sql lexicon declares (database, table, view, materialized view)",
|
|
280
|
+
"lexicon-sql.json",
|
|
281
|
+
"sql",
|
|
282
|
+
),
|
|
283
|
+
...postgresMcpResources(),
|
|
284
|
+
catalogResource("clickhouse-pin", "ClickHouse Pin", "The pinned ClickHouse server the catalog was read from", () => ({
|
|
285
|
+
version: CLICKHOUSE_VERSION,
|
|
286
|
+
image: clickhouseImage(),
|
|
287
|
+
digest: CLICKHOUSE_IMAGE_DIGEST,
|
|
288
|
+
})),
|
|
289
|
+
catalogResource("clickhouse-engines", "ClickHouse Engines", "Table and database engines with their usage line, summary and capabilities", () => ({
|
|
290
|
+
tableEngines: need().tableEngines,
|
|
291
|
+
databaseEngines: need().databaseEngines,
|
|
292
|
+
})),
|
|
293
|
+
catalogResource("clickhouse-types", "ClickHouse Types", "Column type families, with aliases and case sensitivity", () => need().typeFamilies),
|
|
294
|
+
catalogResource("clickhouse-codecs", "ClickHouse Codecs", "Column codecs and skip index types", () => ({
|
|
295
|
+
codecs: need().codecs,
|
|
296
|
+
skipIndexTypes: need().skipIndexTypes,
|
|
297
|
+
})),
|
|
298
|
+
catalogResource("clickhouse-settings", "ClickHouse Settings", "MergeTree and query settings with type, default and tier", () => ({
|
|
299
|
+
mergeTreeSettings: need().mergeTreeSettings,
|
|
300
|
+
querySettings: need().querySettings,
|
|
301
|
+
})),
|
|
302
|
+
catalogResource("clickhouse-functions", "ClickHouse Functions", "Function names, with which are aggregate and which are aliases", () => need().functions),
|
|
303
|
+
];
|
|
304
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { sqlPlugin } from "../plugin";
|
|
3
|
+
import { sqlMcpResources, sqlMcpTools } from "./index";
|
|
4
|
+
|
|
5
|
+
const tool = (name: string) => sqlMcpTools().find((t) => t.name === name)!;
|
|
6
|
+
|
|
7
|
+
describe("sql MCP tools", () => {
|
|
8
|
+
test("the plugin registers them", () => {
|
|
9
|
+
expect(sqlPlugin.mcpTools?.().map((t) => t.name).sort()).toEqual(["lookup", "parse-ddl", "search", "classify-change", "sql:diff"].sort());
|
|
10
|
+
expect(sqlPlugin.mcpResources?.().length).toBeGreaterThan(0);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test("lookup finds an engine and a setting", async () => {
|
|
14
|
+
const e = (await tool("lookup").handler({ kind: "engine", name: "ReplacingMergeTree" })) as { matches: Array<{ syntax: string }> };
|
|
15
|
+
expect(e.matches[0]!.syntax).toContain("ReplacingMergeTree");
|
|
16
|
+
const s = (await tool("lookup").handler({ kind: "setting", name: "index_granularity" })) as { matches: Array<{ scope: string }> };
|
|
17
|
+
expect(s.matches.map((m) => m.scope)).toContain("merge-tree");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("lookup of an unknown name offers close ones", async () => {
|
|
21
|
+
const r = (await tool("lookup").handler({ kind: "engine", name: "Replacing" })) as { matches: unknown[]; closest: string[] };
|
|
22
|
+
expect(r.matches).toEqual([]);
|
|
23
|
+
expect(r.closest).toContain("ReplacingMergeTree");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("lookup refuses an unknown kind", async () => {
|
|
27
|
+
await expect(tool("lookup").handler({ kind: "nope", name: "x" })).rejects.toThrow(/kind must be one of/);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("search narrows by substring and limits", async () => {
|
|
31
|
+
const r = (await tool("search").handler({ kind: "codec", query: "zstd", limit: 1 })) as { total: number; results: unknown[] };
|
|
32
|
+
expect(r.total).toBeGreaterThan(0);
|
|
33
|
+
expect(r.results).toHaveLength(1);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("parse-ddl returns the entity", async () => {
|
|
37
|
+
const r = (await tool("parse-ddl").handler({
|
|
38
|
+
tag: "table",
|
|
39
|
+
ddl: "CREATE TABLE events (user_id UUID, ts DateTime) ENGINE = MergeTree ORDER BY (user_id, ts)",
|
|
40
|
+
})) as { ok: boolean; name: string; props: { columns: unknown[]; engine: { name: string } } };
|
|
41
|
+
expect(r.ok).toBe(true);
|
|
42
|
+
expect(r.name).toBe("events");
|
|
43
|
+
expect(r.props.columns).toHaveLength(2);
|
|
44
|
+
expect(r.props.engine.name).toBe("MergeTree");
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("parse-ddl reports a syntax error at its line and column", async () => {
|
|
48
|
+
const r = (await tool("parse-ddl").handler({ tag: "table", ddl: "CREATE TABLE t (\n a Strin g\n) ENGINE = Log" })) as {
|
|
49
|
+
ok: boolean;
|
|
50
|
+
rule: string;
|
|
51
|
+
line: number;
|
|
52
|
+
column: number;
|
|
53
|
+
};
|
|
54
|
+
expect(r).toMatchObject({ ok: false, rule: "SQLCH001", line: 2, column: 11 });
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe("sql classify-change", () => {
|
|
59
|
+
const build = (ddl: string) => JSON.stringify({ dialect: "clickhouse", objects: [{ export: "events", ddl }] });
|
|
60
|
+
const base = "CREATE TABLE events (id UInt64, kind String) ENGINE = MergeTree ORDER BY id";
|
|
61
|
+
|
|
62
|
+
test("classifies a changed engine as a rebuild with its restriction", async () => {
|
|
63
|
+
const r = (await tool("classify-change").handler({
|
|
64
|
+
before: build(base),
|
|
65
|
+
after: build(base.replace("MergeTree", "ReplacingMergeTree")),
|
|
66
|
+
})) as { summary: Record<string, number>; rebuilds: unknown[]; changes: Array<{ class: string; cite: string }> };
|
|
67
|
+
expect(r.summary.rebuild).toBeGreaterThan(0);
|
|
68
|
+
expect(r.rebuilds.length).toBeGreaterThan(0);
|
|
69
|
+
expect(r.changes[0]!.cite).toMatch(/^https:/);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("identical builds have no changes", async () => {
|
|
73
|
+
const r = (await tool("classify-change").handler({ before: build(base), after: build(base) })) as { changes: unknown[] };
|
|
74
|
+
expect(r.changes).toEqual([]);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe("sql classify-change for Postgres", () => {
|
|
79
|
+
const build = (...ddl: string[]) =>
|
|
80
|
+
JSON.stringify({ dialect: "postgres", objects: ddl.map((d, i) => ({ export: `t${i}`, type: "Postgres::Table", ddl: d })) });
|
|
81
|
+
const orders = "CREATE TABLE app.orders (id bigint PRIMARY KEY, amount numeric(12,2) NOT NULL, note varchar(20))";
|
|
82
|
+
type R = {
|
|
83
|
+
dialect: string;
|
|
84
|
+
summary: Record<string, number>;
|
|
85
|
+
changes: Array<{ field: string; rule: string; class: string; cite: string; restriction: string }>;
|
|
86
|
+
refused: Array<{ rule: string; advice: string }>;
|
|
87
|
+
report: string;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
test("dispatches on the dialect the build names, with class, rule and citation", async () => {
|
|
91
|
+
const r = (await tool("classify-change").handler({
|
|
92
|
+
before: build(orders),
|
|
93
|
+
after: build(orders.replace("note varchar(20)", "note varchar(20), tag text")),
|
|
94
|
+
})) as R;
|
|
95
|
+
expect(r.dialect).toBe("postgres");
|
|
96
|
+
expect(r.changes).toHaveLength(1);
|
|
97
|
+
expect(r.changes[0]).toMatchObject({ field: "columns.tag", rule: "SQLPG201", class: "metadata" });
|
|
98
|
+
expect(r.changes[0]!.cite).toMatch(/^https:\/\/www\.postgresql\.org\/docs\/18\//);
|
|
99
|
+
expect(r.changes[0]!.restriction).toMatch(/ADD COLUMN/);
|
|
100
|
+
expect(r.refused).toEqual([]);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test("a change only expand and contract can make is refused", async () => {
|
|
104
|
+
const r = (await tool("classify-change").handler({
|
|
105
|
+
before: build(orders),
|
|
106
|
+
after: build(orders.replace("amount numeric(12,2)", "amount text")),
|
|
107
|
+
})) as R;
|
|
108
|
+
expect(r.summary.expand).toBeGreaterThan(0);
|
|
109
|
+
expect(r.refused.length).toBeGreaterThan(0);
|
|
110
|
+
expect(r.refused[0]!.advice).toMatch(/expand and contract/);
|
|
111
|
+
expect(r.report).toMatch(/Refused/);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test("the dialect argument and the major are honoured", async () => {
|
|
115
|
+
const stored = "CREATE TABLE t (a int, b int GENERATED ALWAYS AS (a * 2) STORED)";
|
|
116
|
+
const r = (changed: string, major?: number) =>
|
|
117
|
+
tool("classify-change").handler({ dialect: "postgres", major, before: build(stored), after: build(changed) }) as Promise<R>;
|
|
118
|
+
const changed = stored.replace("a * 2", "a * 3");
|
|
119
|
+
expect((await r(changed, 17)).changes[0]!.class).toBe("rewrite");
|
|
120
|
+
expect((await r(changed, 16)).changes[0]!.class).toBe("expand");
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test("identical builds have no changes", async () => {
|
|
124
|
+
const r = (await tool("classify-change").handler({ before: build(orders), after: build(orders) })) as R;
|
|
125
|
+
expect(r.changes).toEqual([]);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe("sql MCP resources", () => {
|
|
130
|
+
test("serve JSON from the catalog", async () => {
|
|
131
|
+
const byUri = (uri: string) => sqlMcpResources().find((r) => r.uri === uri)!;
|
|
132
|
+
expect(JSON.parse(await byUri("clickhouse-pin").handler()).version).toMatch(/^\d+\.\d+/);
|
|
133
|
+
expect(JSON.parse(await byUri("clickhouse-engines").handler()).tableEngines.length).toBeGreaterThan(50);
|
|
134
|
+
expect(JSON.parse(await byUri("clickhouse-types").handler()).length).toBeGreaterThan(50);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe("sql MCP tools for Postgres", () => {
|
|
139
|
+
test("lookup finds a type, an access method and a storage parameter", async () => {
|
|
140
|
+
const t = (await tool("lookup").handler({ dialect: "postgres", kind: "type", name: "int4" })) as { matches: Array<{ aliasOf: string }> };
|
|
141
|
+
expect(t.matches[0]!.aliasOf).toBe("integer");
|
|
142
|
+
const m = (await tool("lookup").handler({ dialect: "postgres", kind: "index-method", name: "gin" })) as { matches: Array<{ properties: string[] }> };
|
|
143
|
+
expect(m.matches[0]!.properties.length).toBeGreaterThan(0);
|
|
144
|
+
const s = (await tool("lookup").handler({ dialect: "postgres", kind: "storage-parameter", name: "fillfactor" })) as { matches: Array<{ targets: string[] }> };
|
|
145
|
+
expect(s.matches[0]!.targets).toContain("table");
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test("a function carries since, and major narrows", async () => {
|
|
149
|
+
const all = (await tool("lookup").handler({ dialect: "postgres", kind: "function", name: "array_sort" })) as { matches: Array<{ since?: number }> };
|
|
150
|
+
expect(all.matches[0]!.since).toBe(18);
|
|
151
|
+
const at15 = (await tool("lookup").handler({ dialect: "postgres", kind: "function", name: "array_sort", major: 15 })) as { matches: unknown[]; closest: string[] };
|
|
152
|
+
expect(at15.matches).toEqual([]);
|
|
153
|
+
await expect(tool("lookup").handler({ dialect: "postgres", kind: "function", name: "x", major: 13 })).rejects.toThrow(/major must be one of/);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test("lookup refuses a ClickHouse kind for Postgres", async () => {
|
|
157
|
+
await expect(tool("lookup").handler({ dialect: "postgres", kind: "engine", name: "x" })).rejects.toThrow(/kind must be one of/);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test("search", async () => {
|
|
161
|
+
const r = (await tool("search").handler({ dialect: "postgres", kind: "keyword", query: "defer", limit: 5 })) as { total: number };
|
|
162
|
+
expect(r.total).toBeGreaterThan(0);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test("parse-ddl returns the entity", async () => {
|
|
166
|
+
const r = (await tool("parse-ddl").handler({ dialect: "postgres", tag: "table", ddl: "CREATE TABLE app.t (id bigint PRIMARY KEY, n text NOT NULL)" })) as { ok: boolean; entityType: string; name: string; props: { columns: unknown[] } };
|
|
167
|
+
expect(r).toMatchObject({ ok: true, entityType: "Postgres::Table", name: "app.t" });
|
|
168
|
+
expect(r.props.columns).toHaveLength(2);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test("parse-ddl reports SQLPG001 at line and column", async () => {
|
|
172
|
+
const r = (await tool("parse-ddl").handler({ dialect: "postgres", tag: "table", ddl: "CREATE TABLE t (\n a ARRAY[4]\n)" })) as { ok: boolean; rule: string; line: number };
|
|
173
|
+
expect(r).toMatchObject({ ok: false, rule: "SQLPG001", line: 2 });
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("the postgres resources are registered under the sql namespace", async () => {
|
|
177
|
+
const uris = sqlMcpResources().map((r) => r.uri);
|
|
178
|
+
expect(uris).toEqual(expect.arrayContaining(["postgres-pin", "postgres-types", "postgres-access-methods", "postgres-storage-parameters", "postgres-functions", "postgres-keywords", "postgres-settings", "clickhouse-engines"]));
|
|
179
|
+
const pin = JSON.parse(await sqlMcpResources().find((r) => r.uri === "postgres-pin")!.handler()) as { pins: unknown[] };
|
|
180
|
+
expect(pin.pins).toHaveLength(5);
|
|
181
|
+
const fns = JSON.parse(await sqlMcpResources().find((r) => r.uri === "postgres-functions")!.handler()) as Array<{ name: string; since?: number }>;
|
|
182
|
+
expect(fns.find((f) => f.name === "array_sort")?.since).toBe(18);
|
|
183
|
+
});
|
|
184
|
+
});
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Postgres side of the sql MCP tools and resources (chant #3283). Rows
|
|
3
|
+
* come from the committed catalogs of the pinned servers, one per major; a
|
|
4
|
+
* name present in only some majors carries `since` and `until`, as the
|
|
5
|
+
* generated types' `@since` / `@until` do.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { McpResourceContribution } from "@intentius/chant/mcp/types";
|
|
9
|
+
import { POSTGRES_LATEST_MAJOR, POSTGRES_MAJORS, POSTGRES_PINS, postgresImage } from "../spec/postgres-pin";
|
|
10
|
+
import { section, type Section } from "../lsp/postgres-catalog";
|
|
11
|
+
import * as pg from "../postgres/entities";
|
|
12
|
+
import { SqlSyntaxError } from "../postgres/tokens";
|
|
13
|
+
|
|
14
|
+
export const POSTGRES_KINDS = ["type", "index-method", "table-method", "storage-parameter", "setting", "function", "keyword", "extension"] as const;
|
|
15
|
+
export type PostgresKind = (typeof POSTGRES_KINDS)[number];
|
|
16
|
+
|
|
17
|
+
type Row = { name: string; summary?: string; since?: number; until?: number };
|
|
18
|
+
|
|
19
|
+
const SECTION: Record<PostgresKind, Section> = {
|
|
20
|
+
type: "types",
|
|
21
|
+
"index-method": "accessMethods",
|
|
22
|
+
"table-method": "accessMethods",
|
|
23
|
+
"storage-parameter": "storageParameters",
|
|
24
|
+
setting: "settings",
|
|
25
|
+
function: "functions",
|
|
26
|
+
keyword: "keywords",
|
|
27
|
+
extension: "extensions",
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export function asPostgresKind(value: unknown): PostgresKind {
|
|
31
|
+
if (!POSTGRES_KINDS.includes(value as PostgresKind)) throw new Error(`kind must be one of: ${POSTGRES_KINDS.join(", ")}`);
|
|
32
|
+
return value as PostgresKind;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The major a tool call is about: `major` when given, else every major (undefined). */
|
|
36
|
+
export function asMajor(value: unknown): number | undefined {
|
|
37
|
+
if (value === undefined || value === null || value === "") return undefined;
|
|
38
|
+
const n = Number(value);
|
|
39
|
+
if (!POSTGRES_MAJORS.includes(n)) throw new Error(`major must be one of: ${POSTGRES_MAJORS.join(", ")}`);
|
|
40
|
+
return n;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The rows of a kind, each with its range; only those at `major` when one is given. */
|
|
44
|
+
export function postgresRows(kind: PostgresKind, major?: number): Row[] {
|
|
45
|
+
const s = section<Record<string, unknown> & { type?: string; description?: string }>(SECTION[kind]);
|
|
46
|
+
if (!s) throw new Error("the Postgres catalog snapshots could not be read");
|
|
47
|
+
const wantType = kind === "index-method" ? "index" : kind === "table-method" ? "table" : undefined;
|
|
48
|
+
const out: Row[] = [];
|
|
49
|
+
for (const e of s.values()) {
|
|
50
|
+
if (major !== undefined && !e.majors.includes(major)) continue;
|
|
51
|
+
if (wantType && e.row.type !== wantType) continue;
|
|
52
|
+
const summary = typeof e.row.description === "string" ? e.row.description : e.detail;
|
|
53
|
+
out.push({ ...(e.row as object), name: e.name, ...(summary ? { summary } : {}), ...e.range } as Row);
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function postgresLookup(params: Record<string, unknown>): unknown {
|
|
59
|
+
const kind = asPostgresKind(params.kind);
|
|
60
|
+
const major = asMajor(params.major);
|
|
61
|
+
const name = String(params.name ?? "");
|
|
62
|
+
const all = postgresRows(kind, major);
|
|
63
|
+
const exact = all.filter((r) => r.name === name);
|
|
64
|
+
const found = exact.length ? exact : all.filter((r) => r.name.toLowerCase() === name.toLowerCase());
|
|
65
|
+
const base = { dialect: "postgres", kind, majors: major !== undefined ? [major] : POSTGRES_MAJORS };
|
|
66
|
+
if (found.length) return { ...base, matches: found };
|
|
67
|
+
const near = all.filter((r) => r.name.toLowerCase().includes(name.toLowerCase())).slice(0, 10).map((r) => r.name);
|
|
68
|
+
return { ...base, matches: [], closest: near };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function postgresSearch(params: Record<string, unknown>): unknown {
|
|
72
|
+
const kind = asPostgresKind(params.kind);
|
|
73
|
+
const query = String(params.query ?? "").toLowerCase();
|
|
74
|
+
const limit = Math.max(1, Math.min(200, Number(params.limit ?? 25)));
|
|
75
|
+
const hits = postgresRows(kind, asMajor(params.major)).filter((r) => r.name.toLowerCase().includes(query));
|
|
76
|
+
return {
|
|
77
|
+
dialect: "postgres",
|
|
78
|
+
kind,
|
|
79
|
+
total: hits.length,
|
|
80
|
+
results: hits.slice(0, limit).map((r) => ({ name: r.name, ...(r.summary ? { summary: r.summary } : {}), ...(r.since ? { since: r.since } : {}), ...(r.until ? { until: r.until } : {}) })),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const TAGS = { schema: pg.schema, table: pg.table, index: pg.index, view: pg.view, sequence: pg.sequence, type: pg.type, domain: pg.domain, extension: pg.extension } as const;
|
|
85
|
+
export const POSTGRES_TAGS = Object.keys(TAGS);
|
|
86
|
+
|
|
87
|
+
/** Parse one statement with the Postgres tag; an error comes back as SQLPG001 with its line and column. */
|
|
88
|
+
export function postgresParse(tag: string, ddl: string, position: (text: string, offset: number) => { line: number; column: number }): unknown {
|
|
89
|
+
const build = (TAGS as Record<string, (s: TemplateStringsArray) => pg.PostgresObject>)[tag];
|
|
90
|
+
if (!build) throw new Error(`tag must be one of: ${POSTGRES_TAGS.join(", ")}`);
|
|
91
|
+
const strings = Object.assign([ddl], { raw: [ddl] }) as unknown as TemplateStringsArray;
|
|
92
|
+
try {
|
|
93
|
+
const entity = build(strings);
|
|
94
|
+
return { ok: true, dialect: "postgres", entityType: entity.entityType, name: entity.sqlName, props: JSON.parse(JSON.stringify((entity as unknown as { props: unknown }).props)) };
|
|
95
|
+
} catch (err) {
|
|
96
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
97
|
+
const offset = (err as { offset?: number }).offset;
|
|
98
|
+
const where = typeof offset === "number" ? position(ddl, offset) : undefined;
|
|
99
|
+
const syntax = err instanceof SqlSyntaxError || (err as Error).name === "SqlTemplateError";
|
|
100
|
+
return { ok: false, dialect: "postgres", rule: syntax ? "SQLPG001" : undefined, message, ...(where ?? {}) };
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const json = (value: unknown) => JSON.stringify(value, null, 2);
|
|
105
|
+
|
|
106
|
+
function resource(uri: string, name: string, description: string, read: () => unknown): McpResourceContribution {
|
|
107
|
+
return { uri, name, description, mimeType: "application/json", async handler() { return json(read()); } };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The Postgres resources: every supported major's names in one list, each with `since` / `until` when not in all. */
|
|
111
|
+
export function postgresMcpResources(): McpResourceContribution[] {
|
|
112
|
+
const all = (...kinds: PostgresKind[]) => Object.fromEntries(kinds.map((k) => [k, postgresRows(k)]));
|
|
113
|
+
return [
|
|
114
|
+
resource("postgres-pin", "Postgres Pins", "The pinned server for each supported major the catalogs were read from", () => ({
|
|
115
|
+
latest: POSTGRES_LATEST_MAJOR,
|
|
116
|
+
pins: POSTGRES_PINS.map((p) => ({ ...p, image: postgresImage(p.major) })),
|
|
117
|
+
})),
|
|
118
|
+
resource("postgres-types", "Postgres Types", "Column types and their aliases, with since/until majors", () => postgresRows("type")),
|
|
119
|
+
resource("postgres-access-methods", "Postgres Access Methods", "Index access methods (btree, gin...) and table access methods", () => all("index-method", "table-method")),
|
|
120
|
+
resource("postgres-storage-parameters", "Postgres Storage Parameters", "WITH (...) parameters, the relation kinds that accept each, and their types", () => postgresRows("storage-parameter")),
|
|
121
|
+
resource("postgres-functions", "Postgres Functions", "Built-in function names with since/until majors", () => postgresRows("function")),
|
|
122
|
+
resource("postgres-keywords", "Postgres Keywords", "Key words and their categories", () => postgresRows("keyword")),
|
|
123
|
+
resource("postgres-settings", "Postgres Settings", "Server settings with type, default and range", () => postgresRows("setting")),
|
|
124
|
+
];
|
|
125
|
+
}
|