@intentius/chant-lexicon-sql 0.124.46 → 0.124.48

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.
Files changed (360) hide show
  1. package/dist/change-set.d.ts +1 -1
  2. package/dist/change-set.d.ts.map +1 -1
  3. package/dist/change-set.js +2 -1
  4. package/dist/clickhouse/apply/statements.d.ts +9 -0
  5. package/dist/clickhouse/apply/statements.d.ts.map +1 -1
  6. package/dist/clickhouse/apply/statements.js +24 -0
  7. package/dist/clickhouse/import/live-export.d.ts +7 -3
  8. package/dist/clickhouse/import/live-export.d.ts.map +1 -1
  9. package/dist/clickhouse/import/live-export.js +21 -5
  10. package/dist/clickhouse/live/named-collections.d.ts +27 -0
  11. package/dist/clickhouse/live/named-collections.d.ts.map +1 -0
  12. package/dist/clickhouse/live/named-collections.js +53 -0
  13. package/dist/clickhouse/live/undeclarable.d.ts +15 -3
  14. package/dist/clickhouse/live/undeclarable.d.ts.map +1 -1
  15. package/dist/clickhouse/live/undeclarable.js +18 -4
  16. package/dist/clickhouse/named-collections.d.ts +83 -0
  17. package/dist/clickhouse/named-collections.d.ts.map +1 -0
  18. package/dist/clickhouse/named-collections.js +203 -0
  19. package/dist/clickhouse/parser.d.ts.map +1 -1
  20. package/dist/clickhouse/parser.js +1 -1
  21. package/dist/clickhouse/plan/commands.d.ts +2 -1
  22. package/dist/clickhouse/plan/commands.d.ts.map +1 -1
  23. package/dist/clickhouse/plan/commands.js +17 -2
  24. package/dist/clickhouse/plan/diff.d.ts +15 -0
  25. package/dist/clickhouse/plan/diff.d.ts.map +1 -1
  26. package/dist/clickhouse/plan/diff.js +43 -1
  27. package/dist/clickhouse/plan/disruption.d.ts.map +1 -1
  28. package/dist/clickhouse/plan/disruption.js +5 -0
  29. package/dist/clickhouse/plan/rebuild-handoff.d.ts.map +1 -1
  30. package/dist/clickhouse/plan/rebuild-handoff.js +4 -0
  31. package/dist/clickhouse/plan/report.d.ts.map +1 -1
  32. package/dist/clickhouse/plan/report.js +6 -1
  33. package/dist/clickhouse/plan/rules.d.ts +5 -1
  34. package/dist/clickhouse/plan/rules.d.ts.map +1 -1
  35. package/dist/clickhouse/plan/rules.js +7 -3
  36. package/dist/clickhouse/plan/stream.d.ts +40 -0
  37. package/dist/clickhouse/plan/stream.d.ts.map +1 -0
  38. package/dist/clickhouse/plan/stream.js +107 -0
  39. package/dist/clickhouse/rebuild/observe.d.ts +3 -1
  40. package/dist/clickhouse/rebuild/observe.d.ts.map +1 -1
  41. package/dist/clickhouse/rebuild/observe.js +14 -1
  42. package/dist/clickhouse/review-catalog.d.ts +213 -0
  43. package/dist/clickhouse/review-catalog.d.ts.map +1 -0
  44. package/dist/clickhouse/review-catalog.js +330 -0
  45. package/dist/codegen/classifier-page.d.ts.map +1 -1
  46. package/dist/codegen/classifier-page.js +21 -4
  47. package/dist/codegen/clickhouse-module.d.ts.map +1 -1
  48. package/dist/codegen/clickhouse-module.js +3 -0
  49. package/dist/codegen/coverage-page.d.ts.map +1 -1
  50. package/dist/codegen/coverage-page.js +5 -3
  51. package/dist/codegen/docs.js +1 -1
  52. package/dist/codegen/postgres-classifier-page.js +1 -1
  53. package/dist/codegen/registry.d.ts.map +1 -1
  54. package/dist/codegen/registry.js +5 -0
  55. package/dist/composites/catalog.d.ts.map +1 -1
  56. package/dist/composites/catalog.js +100 -0
  57. package/dist/composites/clickhouse.d.ts +2 -0
  58. package/dist/composites/clickhouse.d.ts.map +1 -1
  59. package/dist/composites/clickhouse.js +2 -0
  60. package/dist/composites/otel-tables.d.ts +100 -0
  61. package/dist/composites/otel-tables.d.ts.map +1 -0
  62. package/dist/composites/otel-tables.js +282 -0
  63. package/dist/composites/stream-ingest.d.ts +63 -0
  64. package/dist/composites/stream-ingest.d.ts.map +1 -0
  65. package/dist/composites/stream-ingest.js +39 -0
  66. package/dist/coverage/clickhouse.json +1 -1
  67. package/dist/coverage/postgres.json +7 -7
  68. package/dist/coverage.d.ts +16 -6
  69. package/dist/coverage.d.ts.map +1 -1
  70. package/dist/coverage.js +10 -5
  71. package/dist/drizzle-command.d.ts +17 -0
  72. package/dist/drizzle-command.d.ts.map +1 -0
  73. package/dist/drizzle-command.js +91 -0
  74. package/dist/drizzle.d.ts +70 -0
  75. package/dist/drizzle.d.ts.map +1 -0
  76. package/dist/drizzle.js +684 -0
  77. package/dist/files/clickhouse.d.ts.map +1 -1
  78. package/dist/files/clickhouse.js +8 -1
  79. package/dist/files/common.d.ts +13 -0
  80. package/dist/files/common.d.ts.map +1 -1
  81. package/dist/files/common.js +5 -0
  82. package/dist/files/postgres.js +12 -2
  83. package/dist/generated/clickhouse.d.ts +2 -0
  84. package/dist/generated/clickhouse.d.ts.map +1 -1
  85. package/dist/generated/clickhouse.js +2 -0
  86. package/dist/import-parser.d.ts +21 -1
  87. package/dist/import-parser.d.ts.map +1 -1
  88. package/dist/import-parser.js +79 -5
  89. package/dist/index.d.ts +1 -1
  90. package/dist/index.d.ts.map +1 -1
  91. package/dist/index.js +1 -1
  92. package/dist/integrity.json +6 -5
  93. package/dist/lint/post-synth/audit-entries.d.ts.map +1 -1
  94. package/dist/lint/post-synth/audit-entries.js +1 -0
  95. package/dist/lint/post-synth/index.d.ts.map +1 -1
  96. package/dist/lint/post-synth/index.js +2 -0
  97. package/dist/lint/post-synth/sqlch128.d.ts +18 -0
  98. package/dist/lint/post-synth/sqlch128.d.ts.map +1 -0
  99. package/dist/lint/post-synth/sqlch128.js +222 -0
  100. package/dist/lint/rules/postgres-templates.js +2 -2
  101. package/dist/lsp/postgres-template.d.ts.map +1 -1
  102. package/dist/lsp/postgres-template.js +11 -0
  103. package/dist/manifest.json +1 -1
  104. package/dist/mcp/postgres.js +1 -1
  105. package/dist/meta.json +25 -0
  106. package/dist/migrate/from-postgres/detect.d.ts +4 -0
  107. package/dist/migrate/from-postgres/detect.d.ts.map +1 -0
  108. package/dist/migrate/from-postgres/detect.js +7 -0
  109. package/dist/migrate/from-postgres/emit.d.ts +26 -0
  110. package/dist/migrate/from-postgres/emit.d.ts.map +1 -0
  111. package/dist/migrate/from-postgres/emit.js +86 -0
  112. package/dist/migrate/from-postgres/index.d.ts +51 -0
  113. package/dist/migrate/from-postgres/index.d.ts.map +1 -0
  114. package/dist/migrate/from-postgres/index.js +115 -0
  115. package/dist/migrate/from-postgres/translate.d.ts +73 -0
  116. package/dist/migrate/from-postgres/translate.d.ts.map +1 -0
  117. package/dist/migrate/from-postgres/translate.js +261 -0
  118. package/dist/migrate/from-postgres/types.d.ts +51 -0
  119. package/dist/migrate/from-postgres/types.d.ts.map +1 -0
  120. package/dist/migrate/from-postgres/types.js +211 -0
  121. package/dist/migration-replay.d.ts +73 -0
  122. package/dist/migration-replay.d.ts.map +1 -0
  123. package/dist/migration-replay.js +294 -0
  124. package/dist/okf/index.md +6 -0
  125. package/dist/okf/rules/SQLCH128.md +11 -0
  126. package/dist/okf/types/PostgresForeignDataWrapper.md +9 -0
  127. package/dist/okf/types/PostgresForeignServer.md +9 -0
  128. package/dist/okf/types/PostgresOperator.md +9 -0
  129. package/dist/okf/types/PostgresPublication.md +9 -0
  130. package/dist/okf/types/PostgresStatistics.md +9 -0
  131. package/dist/op/activities/postgres-migration.d.ts.map +1 -1
  132. package/dist/op/activities/postgres-migration.js +4 -0
  133. package/dist/op/activity-contracts.d.ts +20 -0
  134. package/dist/op/activity-contracts.d.ts.map +1 -1
  135. package/dist/op/activity-contracts.js +2 -0
  136. package/dist/plugin.d.ts.map +1 -1
  137. package/dist/plugin.js +36 -2
  138. package/dist/postgres/apply/apply.js +8 -1
  139. package/dist/postgres/apply/statements.d.ts.map +1 -1
  140. package/dist/postgres/apply/statements.js +87 -2
  141. package/dist/postgres/constraint-names.d.ts +30 -0
  142. package/dist/postgres/constraint-names.d.ts.map +1 -0
  143. package/dist/postgres/constraint-names.js +72 -0
  144. package/dist/postgres/entities.d.ts +110 -1
  145. package/dist/postgres/entities.d.ts.map +1 -1
  146. package/dist/postgres/entities.js +146 -0
  147. package/dist/postgres/entity-types.d.ts +5 -0
  148. package/dist/postgres/entity-types.d.ts.map +1 -1
  149. package/dist/postgres/entity-types.js +5 -0
  150. package/dist/postgres/import/generator.d.ts.map +1 -1
  151. package/dist/postgres/import/generator.js +50 -2
  152. package/dist/postgres/import/live-export.d.ts.map +1 -1
  153. package/dist/postgres/import/live-export.js +2 -0
  154. package/dist/postgres/live/catalog-kinds.d.ts +14 -0
  155. package/dist/postgres/live/catalog-kinds.d.ts.map +1 -1
  156. package/dist/postgres/live/catalog-kinds.js +206 -0
  157. package/dist/postgres/live/catalog.d.ts +2 -0
  158. package/dist/postgres/live/catalog.d.ts.map +1 -1
  159. package/dist/postgres/live/catalog.js +3 -1
  160. package/dist/postgres/live/describe-resources.d.ts.map +1 -1
  161. package/dist/postgres/live/describe-resources.js +10 -2
  162. package/dist/postgres/migrate/backfill.d.ts +2 -0
  163. package/dist/postgres/migrate/backfill.d.ts.map +1 -1
  164. package/dist/postgres/migrate/backfill.js +7 -1
  165. package/dist/postgres/migrate/carry.d.ts +45 -1
  166. package/dist/postgres/migrate/carry.d.ts.map +1 -1
  167. package/dist/postgres/migrate/carry.js +72 -8
  168. package/dist/postgres/migrate/observe.d.ts +28 -4
  169. package/dist/postgres/migrate/observe.d.ts.map +1 -1
  170. package/dist/postgres/migrate/observe.js +41 -12
  171. package/dist/postgres/migrate/op.d.ts +26 -1
  172. package/dist/postgres/migrate/op.d.ts.map +1 -1
  173. package/dist/postgres/migrate/op.js +3 -1
  174. package/dist/postgres/migrate/steps.d.ts +35 -2
  175. package/dist/postgres/migrate/steps.d.ts.map +1 -1
  176. package/dist/postgres/migrate/steps.js +158 -12
  177. package/dist/postgres/parser.d.ts +72 -1
  178. package/dist/postgres/parser.d.ts.map +1 -1
  179. package/dist/postgres/parser.js +194 -2
  180. package/dist/postgres/plan/deep.d.ts.map +1 -1
  181. package/dist/postgres/plan/deep.js +29 -1
  182. package/dist/postgres/plan/diff.d.ts.map +1 -1
  183. package/dist/postgres/plan/diff.js +39 -1
  184. package/dist/postgres/plan/normalize.d.ts +17 -2
  185. package/dist/postgres/plan/normalize.d.ts.map +1 -1
  186. package/dist/postgres/plan/normalize.js +109 -1
  187. package/dist/postgres/plan/rules.d.ts +1 -0
  188. package/dist/postgres/plan/rules.d.ts.map +1 -1
  189. package/dist/postgres/plan/rules.js +3 -2
  190. package/dist/postgres/plan/schema.js +1 -1
  191. package/dist/postgres/secret-options.d.ts +10 -0
  192. package/dist/postgres/secret-options.d.ts.map +1 -0
  193. package/dist/postgres/secret-options.js +9 -0
  194. package/dist/postgres/testing/roundtrip-schema.d.ts +3 -2
  195. package/dist/postgres/testing/roundtrip-schema.d.ts.map +1 -1
  196. package/dist/postgres/testing/roundtrip-schema.js +13 -1
  197. package/dist/postgres.d.ts +1 -1
  198. package/dist/postgres.d.ts.map +1 -1
  199. package/dist/postgres.js +1 -1
  200. package/dist/rules/audit-entries.ts +1 -0
  201. package/dist/rules/postgres-templates.ts +2 -2
  202. package/dist/rules/sqlch128.ts +230 -0
  203. package/dist/serializer.d.ts +5 -0
  204. package/dist/serializer.d.ts.map +1 -1
  205. package/dist/serializer.js +13 -2
  206. package/dist/sql-types-command.d.ts +13 -0
  207. package/dist/sql-types-command.d.ts.map +1 -1
  208. package/dist/sql-types-command.js +31 -16
  209. package/dist/sql-types.d.ts +22 -0
  210. package/dist/sql-types.d.ts.map +1 -1
  211. package/dist/sql-types.js +10 -6
  212. package/dist/sqlserver/lexer.d.ts +37 -0
  213. package/dist/sqlserver/lexer.d.ts.map +1 -0
  214. package/dist/sqlserver/lexer.js +254 -0
  215. package/dist/sqlserver/parse.d.ts +185 -0
  216. package/dist/sqlserver/parse.d.ts.map +1 -0
  217. package/dist/sqlserver/parse.js +767 -0
  218. package/dist/sqlserver/translate.d.ts +34 -0
  219. package/dist/sqlserver/translate.d.ts.map +1 -0
  220. package/dist/sqlserver/translate.js +495 -0
  221. package/dist/sqlserver/types.d.ts +44 -0
  222. package/dist/sqlserver/types.d.ts.map +1 -0
  223. package/dist/sqlserver/types.js +133 -0
  224. package/dist/sqlserver/validate.d.ts +31 -0
  225. package/dist/sqlserver/validate.d.ts.map +1 -0
  226. package/dist/sqlserver/validate.js +67 -0
  227. package/dist/validate.d.ts.map +1 -1
  228. package/dist/validate.js +5 -0
  229. package/package.json +2 -2
  230. package/src/change-set.ts +2 -1
  231. package/src/clickhouse/apply/statements.ts +25 -0
  232. package/src/clickhouse/import/live-export.ts +20 -5
  233. package/src/clickhouse/live/named-collections.e2e.test.ts +88 -0
  234. package/src/clickhouse/live/named-collections.ts +61 -0
  235. package/src/clickhouse/live/undeclarable.e2e.test.ts +5 -3
  236. package/src/clickhouse/live/undeclarable.ts +20 -4
  237. package/src/clickhouse/named-collections.test.ts +187 -0
  238. package/src/clickhouse/named-collections.ts +224 -0
  239. package/src/clickhouse/parser.ts +2 -1
  240. package/src/clickhouse/plan/commands.ts +17 -2
  241. package/src/clickhouse/plan/diff.ts +57 -1
  242. package/src/clickhouse/plan/disruption.ts +5 -0
  243. package/src/clickhouse/plan/rebuild-handoff.ts +3 -0
  244. package/src/clickhouse/plan/report.ts +6 -1
  245. package/src/clickhouse/plan/rules.ts +14 -4
  246. package/src/clickhouse/plan/stream-s3queue.e2e.test.ts +148 -0
  247. package/src/clickhouse/plan/stream.test.ts +237 -0
  248. package/src/clickhouse/plan/stream.ts +111 -0
  249. package/src/clickhouse/rebuild/observe.ts +15 -1
  250. package/src/clickhouse/review-catalog.test.ts +181 -0
  251. package/src/clickhouse/review-catalog.ts +489 -0
  252. package/src/codegen/classifier-page.ts +21 -4
  253. package/src/codegen/clickhouse-module.ts +3 -0
  254. package/src/codegen/coverage-page.ts +5 -3
  255. package/src/codegen/docs.ts +1 -1
  256. package/src/codegen/postgres-classifier-page.ts +1 -1
  257. package/src/codegen/registry.ts +5 -0
  258. package/src/composites/catalog.test.ts +6 -1
  259. package/src/composites/catalog.ts +100 -0
  260. package/src/composites/clickhouse.ts +2 -0
  261. package/src/composites/composites.test.ts +1 -1
  262. package/src/composites/otel-tables.test.ts +118 -0
  263. package/src/composites/otel-tables.ts +339 -0
  264. package/src/composites/stream-ingest.test.ts +114 -0
  265. package/src/composites/stream-ingest.ts +82 -0
  266. package/src/core/undeclarable.test.ts +6 -5
  267. package/src/coverage/clickhouse.json +1 -1
  268. package/src/coverage/postgres.json +7 -7
  269. package/src/coverage.test.ts +27 -2
  270. package/src/coverage.ts +18 -7
  271. package/src/drizzle-command.ts +94 -0
  272. package/src/drizzle-kit.e2e.test.ts +89 -0
  273. package/src/drizzle-types.e2e.test.ts +67 -0
  274. package/src/drizzle.test.ts +358 -0
  275. package/src/drizzle.ts +737 -0
  276. package/src/files/clickhouse.ts +8 -1
  277. package/src/files/common.ts +14 -1
  278. package/src/files/postgres.ts +12 -2
  279. package/src/generated/clickhouse.ts +3 -0
  280. package/src/generated/lexicon-sql.json +25 -0
  281. package/src/import-parser.sqlserver.test.ts +92 -0
  282. package/src/import-parser.ts +79 -5
  283. package/src/index.ts +1 -1
  284. package/src/lint/post-synth/audit-entries.ts +1 -0
  285. package/src/lint/post-synth/index.ts +2 -0
  286. package/src/lint/post-synth/sqlch128.test.ts +107 -0
  287. package/src/lint/post-synth/sqlch128.ts +230 -0
  288. package/src/lint/rules/postgres-templates.ts +2 -2
  289. package/src/lsp/postgres-template.ts +11 -0
  290. package/src/mcp/postgres.ts +1 -1
  291. package/src/migrate/from-postgres/cli.test.ts +165 -0
  292. package/src/migrate/from-postgres/detect.ts +7 -0
  293. package/src/migrate/from-postgres/emit.ts +96 -0
  294. package/src/migrate/from-postgres/example.test.ts +205 -0
  295. package/src/migrate/from-postgres/index.ts +122 -0
  296. package/src/migrate/from-postgres/translate.test.ts +242 -0
  297. package/src/migrate/from-postgres/translate.ts +359 -0
  298. package/src/migrate/from-postgres/types.test.ts +116 -0
  299. package/src/migrate/from-postgres/types.ts +236 -0
  300. package/src/migrate/from-postgres/validate.e2e.test.ts +44 -0
  301. package/src/migrate/from-postgres/workspace.e2e.test.ts +114 -0
  302. package/src/migration-replay.e2e.test.ts +155 -0
  303. package/src/migration-replay.test.ts +173 -0
  304. package/src/migration-replay.ts +289 -0
  305. package/src/op/__snapshots__/watch-pipeline.test.ts.snap +2 -2
  306. package/src/op/activities/postgres-migration.ts +4 -0
  307. package/src/op/activity-contracts.ts +2 -0
  308. package/src/plugin.ts +37 -2
  309. package/src/postgres/apply/apply.ts +9 -1
  310. package/src/postgres/apply/statements.ts +74 -1
  311. package/src/postgres/constraint-names.ts +71 -0
  312. package/src/postgres/database-kinds.test.ts +384 -0
  313. package/src/postgres/entities.ts +266 -1
  314. package/src/postgres/entity-types.ts +5 -0
  315. package/src/postgres/import/generator.ts +42 -2
  316. package/src/postgres/import/live-export.ts +1 -0
  317. package/src/postgres/live/catalog-kinds.ts +223 -0
  318. package/src/postgres/live/catalog.ts +6 -1
  319. package/src/postgres/live/database-kinds.e2e.test.ts +164 -0
  320. package/src/postgres/live/describe-resources.ts +11 -2
  321. package/src/postgres/live/undeclarable.e2e.test.ts +13 -6
  322. package/src/postgres/migrate/backfill.ts +13 -1
  323. package/src/postgres/migrate/carry.ts +103 -8
  324. package/src/postgres/migrate/followups.e2e.test.ts +218 -0
  325. package/src/postgres/migrate/followups.test.ts +199 -0
  326. package/src/postgres/migrate/kinds.e2e.test.ts +5 -5
  327. package/src/postgres/migrate/observe.ts +53 -14
  328. package/src/postgres/migrate/op.ts +28 -1
  329. package/src/postgres/migrate/partition.e2e.test.ts +129 -0
  330. package/src/postgres/migrate/partition.test.ts +206 -0
  331. package/src/postgres/migrate/steps.ts +157 -12
  332. package/src/postgres/parser.ts +234 -2
  333. package/src/postgres/plan/deep.ts +28 -1
  334. package/src/postgres/plan/diff.ts +36 -1
  335. package/src/postgres/plan/normalize.ts +122 -1
  336. package/src/postgres/plan/rules.ts +10 -3
  337. package/src/postgres/plan/schema.ts +1 -1
  338. package/src/postgres/secret-options.ts +10 -0
  339. package/src/postgres/testing/roundtrip-schema.ts +13 -1
  340. package/src/postgres.ts +16 -0
  341. package/src/serializer.ts +13 -2
  342. package/src/skills/chant-sql-postgres-migration.md +3 -3
  343. package/src/skills/chant-sql-postgres.md +6 -1
  344. package/src/skills/chant-sql.md +2 -1
  345. package/src/sql-types-command.ts +38 -16
  346. package/src/sql-types.ts +11 -6
  347. package/src/sqlserver/fixture.test.ts +186 -0
  348. package/src/sqlserver/import-cli.test.ts +61 -0
  349. package/src/sqlserver/lexer.ts +260 -0
  350. package/src/sqlserver/parse.ts +865 -0
  351. package/src/sqlserver/translate.test.ts +396 -0
  352. package/src/sqlserver/translate.ts +558 -0
  353. package/src/sqlserver/types.test.ts +102 -0
  354. package/src/sqlserver/types.ts +154 -0
  355. package/src/sqlserver/validate.e2e.test.ts +32 -0
  356. package/src/sqlserver/validate.test.ts +49 -0
  357. package/src/sqlserver/validate.ts +76 -0
  358. package/src/validate.ts +5 -0
  359. package/src/workspace-kinds.test.ts +11 -0
  360. package/workspace-kinds.json +100 -2
@@ -116,6 +116,12 @@ export const AGGREGATE_OPTIONS = [
116
116
  ];
117
117
  /** `CREATE COLLATION`'s options (sql-createcollation). */
118
118
  export const COLLATION_OPTIONS = ["locale", "lc_collate", "lc_ctype", "provider", "deterministic", "rules", "version"];
119
+ /** `CREATE OPERATOR`'s options (sql-createoperator); `procedure` is the old spelling of `function`. */
120
+ export const OPERATOR_OPTIONS = ["function", "procedure", "leftarg", "rightarg", "commutator", "negator", "restrict", "join", "hashes", "merges"];
121
+ /** `CREATE STATISTICS`'s kinds (sql-createstatistics). */
122
+ export const STATISTICS_KINDS = ["ndistinct", "dependencies", "mcv"];
123
+ /** `CREATE PUBLICATION ... WITH (...)`'s options (sql-createpublication); `publish_generated_columns` is 18's. */
124
+ export const PUBLICATION_OPTIONS = ["publish", "publish_via_partition_root", "publish_generated_columns"];
119
125
  /** What may follow `IS` inside a `b_expr`. */
120
126
  const B_EXPR_IS = [["DISTINCT", "FROM"], ["NOT", "DISTINCT", "FROM"], ["DOCUMENT"], ["NOT", "DOCUMENT"]];
121
127
  class PgParser extends SqlCursor {
@@ -725,6 +731,16 @@ class PgParser extends SqlCursor {
725
731
  return this.cast();
726
732
  if (this.acceptSeq("EVENT", "TRIGGER"))
727
733
  return this.eventTrigger();
734
+ if (this.accept("OPERATOR"))
735
+ return this.operator();
736
+ if (this.accept("STATISTICS"))
737
+ return this.statistics();
738
+ if (this.acceptSeq("FOREIGN", "DATA", "WRAPPER"))
739
+ return this.foreignDataWrapper();
740
+ if (this.accept("SERVER"))
741
+ return this.foreignServer();
742
+ if (this.accept("PUBLICATION"))
743
+ return this.publication();
728
744
  if (kw(this.peek(), "UNIQUE", "INDEX"))
729
745
  return this.index();
730
746
  }
@@ -740,7 +756,7 @@ class PgParser extends SqlCursor {
740
756
  return this.view(true, false, false, false);
741
757
  if (this.accept("VIEW"))
742
758
  return this.view(false, orReplace, persistence === "temporary", recursive);
743
- return this.fail("expected SCHEMA, TABLE, INDEX, VIEW, MATERIALIZED VIEW, SEQUENCE, TYPE, DOMAIN, EXTENSION, FUNCTION, PROCEDURE, AGGREGATE, TRIGGER, EVENT TRIGGER, COLLATION, CAST, POLICY or ROLE");
759
+ return this.fail("expected SCHEMA, TABLE, INDEX, VIEW, MATERIALIZED VIEW, SEQUENCE, TYPE, DOMAIN, EXTENSION, FUNCTION, PROCEDURE, AGGREGATE, TRIGGER, EVENT TRIGGER, COLLATION, CAST, OPERATOR, STATISTICS, FOREIGN DATA WRAPPER, SERVER, PUBLICATION, POLICY or ROLE");
744
760
  }
745
761
  schema() {
746
762
  const node = { statement: "schema", ifNotExists: this.ifNotExists() };
@@ -993,6 +1009,167 @@ class PgParser extends SqlCursor {
993
1009
  this.expectPunct(")");
994
1010
  return node;
995
1011
  }
1012
+ /** An unqualified, database-wide object's name (a wrapper, a server, a publication). */
1013
+ databaseName(what) {
1014
+ const { text, span } = this.nameTok(what);
1015
+ if (this.isPunct("."))
1016
+ this.fail(`expected ${what} without a schema (it belongs to the database)`);
1017
+ return { pieces: [text], span };
1018
+ }
1019
+ /** `( name 'value' [, ...] )`: a foreign data wrapper's or server's options. */
1020
+ genericOptions() {
1021
+ this.expectPunct("(");
1022
+ const out = [];
1023
+ const seen = new Set();
1024
+ for (;;) {
1025
+ const t = this.next();
1026
+ if (t.kind !== "ident" && t.kind !== "qident")
1027
+ this.fail("expected an option name", t);
1028
+ const nameSpan = this.span(this.idx(-1), []);
1029
+ const name = identValue(t);
1030
+ if (seen.has(name))
1031
+ this.fail(`${name} is given twice`, t);
1032
+ seen.add(name);
1033
+ const v = this.next();
1034
+ if (v.kind !== "string" && v.kind !== "ref")
1035
+ this.fail("expected the option's value, a string", v);
1036
+ out.push({ name, nameSpan, value: this.span(this.idx(-1), v.kind === "ref" ? [v.part] : []) });
1037
+ if (this.acceptPunct(","))
1038
+ continue;
1039
+ this.expectPunct(")");
1040
+ return out;
1041
+ }
1042
+ }
1043
+ /** `[schema.]symbol`: an operator's name, its symbol made of operator characters. */
1044
+ operatorName() {
1045
+ const from = this.idx();
1046
+ const refs = [];
1047
+ const pieces = [];
1048
+ const symbol = () => {
1049
+ const t = this.next();
1050
+ if (t.kind !== "op")
1051
+ this.fail("expected the operator's symbol (operator characters, such as ===)", t);
1052
+ pieces.push(t.text);
1053
+ };
1054
+ if (this.peek()?.kind === "op")
1055
+ symbol();
1056
+ else {
1057
+ const t = this.next();
1058
+ this.colId(t, "a schema name");
1059
+ if (t.kind === "ref")
1060
+ refs.push(t.part);
1061
+ pieces.push(t.kind === "ref" ? "" : identValue(t));
1062
+ this.expectPunct(".");
1063
+ symbol();
1064
+ }
1065
+ return { pieces, span: this.span(from, refs) };
1066
+ }
1067
+ operator() {
1068
+ if (kw(this.peek(), "CLASS", "FAMILY") && !this.isPunct(".", 1))
1069
+ this.fail("expected the operator's name (CREATE OPERATOR CLASS and CREATE OPERATOR FAMILY are not declared)");
1070
+ const name = this.operatorName();
1071
+ const options = this.definition("an operator option");
1072
+ this.checkDefinition(options, OPERATOR_OPTIONS, [], "an operator");
1073
+ if (!options.some((o) => o.name === "function" || o.name === "procedure"))
1074
+ this.fail("expected FUNCTION (an operator needs the function it calls)", this.lastSeen());
1075
+ return { statement: "operator", name, options };
1076
+ }
1077
+ statistics() {
1078
+ const ifNotExists = this.ifNotExists();
1079
+ const name = this.qualifiedName("a statistics name");
1080
+ const kinds = [];
1081
+ if (this.isPunct("(")) {
1082
+ for (const k of this.nameList("a statistics kind")) {
1083
+ if (!STATISTICS_KINDS.includes(k.name))
1084
+ this.fail(`expected a statistics kind (${STATISTICS_KINDS.join(", ")})`, this.tokens[k.span.from]);
1085
+ kinds.push(k.name);
1086
+ }
1087
+ }
1088
+ this.expect("ON");
1089
+ const targets = [];
1090
+ do
1091
+ targets.push(this.expr(["FROM"]));
1092
+ while (this.acceptPunct(","));
1093
+ this.expect("FROM");
1094
+ const table = this.qualifiedName("a table name");
1095
+ return { statement: "statistics", ifNotExists, name, kinds, targets, table };
1096
+ }
1097
+ foreignDataWrapper() {
1098
+ const node = { statement: "foreignDataWrapper", name: this.databaseName("a foreign data wrapper name"), options: [] };
1099
+ for (;;) {
1100
+ if (this.accept("HANDLER"))
1101
+ node.handler = this.qualifiedName("a handler function");
1102
+ else if (this.acceptSeq("NO", "HANDLER"))
1103
+ node.handler = null;
1104
+ else if (this.accept("VALIDATOR"))
1105
+ node.validator = this.qualifiedName("a validator function");
1106
+ else if (this.acceptSeq("NO", "VALIDATOR"))
1107
+ node.validator = null;
1108
+ else if (this.accept("OPTIONS"))
1109
+ node.options = this.genericOptions();
1110
+ else
1111
+ return node;
1112
+ }
1113
+ }
1114
+ foreignServer() {
1115
+ const ifNotExists = this.ifNotExists();
1116
+ const name = this.databaseName("a server name");
1117
+ const node = { statement: "foreignServer", ifNotExists, name, options: [] };
1118
+ const string = (what) => {
1119
+ const t = this.next();
1120
+ if (t.kind !== "string" && t.kind !== "ref")
1121
+ this.fail(`expected ${what} as a string`, t);
1122
+ return this.span(this.idx(-1), t.kind === "ref" ? [t.part] : []);
1123
+ };
1124
+ if (this.accept("TYPE"))
1125
+ node.type = string("the server type");
1126
+ if (this.accept("VERSION"))
1127
+ node.version = string("the server version");
1128
+ if (!this.acceptSeq("FOREIGN", "DATA", "WRAPPER"))
1129
+ this.fail("expected FOREIGN DATA WRAPPER (a server names the wrapper it is for)");
1130
+ node.wrapper = this.qualifiedName("a foreign data wrapper name");
1131
+ if (this.accept("OPTIONS"))
1132
+ node.options = this.genericOptions();
1133
+ return node;
1134
+ }
1135
+ publication() {
1136
+ const node = { statement: "publication", name: this.databaseName("a publication name"), allTables: false, items: [], options: [] };
1137
+ if (this.accept("FOR")) {
1138
+ if (this.acceptSeq("ALL", "TABLES"))
1139
+ node.allTables = true;
1140
+ else {
1141
+ let mode;
1142
+ do {
1143
+ if (this.accept("TABLE"))
1144
+ mode = "table";
1145
+ else if (this.acceptSeq("TABLES", "IN", "SCHEMA"))
1146
+ mode = "schema";
1147
+ else if (mode === undefined)
1148
+ this.fail("expected ALL TABLES, TABLE or TABLES IN SCHEMA");
1149
+ if (mode === "schema") {
1150
+ node.items.push({ kind: "schema", schema: this.qualifiedName("a schema name") });
1151
+ continue;
1152
+ }
1153
+ this.accept("ONLY");
1154
+ const table = this.qualifiedName("a table name");
1155
+ if (this.isOp("*"))
1156
+ this.p++;
1157
+ const item = { kind: "table", table };
1158
+ if (this.isPunct("("))
1159
+ item.columns = this.nameList("a column name");
1160
+ if (this.accept("WHERE"))
1161
+ item.where = this.checkedParens();
1162
+ node.items.push(item);
1163
+ } while (this.acceptPunct(","));
1164
+ }
1165
+ }
1166
+ if (kw(this.peek(), "WITH") && this.isPunct("(", 1)) {
1167
+ this.p++;
1168
+ node.options = this.definition("a publication option");
1169
+ this.checkDefinition(node.options, PUBLICATION_OPTIONS, [], "a publication");
1170
+ }
1171
+ return node;
1172
+ }
996
1173
  table(persistence) {
997
1174
  const ifNotExists = this.ifNotExists();
998
1175
  const node = { statement: "table", persistence, ifNotExists, name: this.qualifiedName("a table name"), columns: [], constraints: [], like: [] };
@@ -1747,6 +1924,21 @@ class PgParser extends SqlCursor {
1747
1924
  node.text = this.commentText();
1748
1925
  return node;
1749
1926
  }
1927
+ else if (this.acceptSeq("FOREIGN", "DATA", "WRAPPER")) {
1928
+ objectType = "FOREIGN DATA WRAPPER";
1929
+ target = this.qualifiedName("a foreign data wrapper name");
1930
+ }
1931
+ else if (this.accept("OPERATOR")) {
1932
+ objectType = "OPERATOR";
1933
+ target = this.operatorName();
1934
+ if (!this.isPunct("("))
1935
+ this.fail("expected '(' and the operator's operand types");
1936
+ args = this.parenthesized();
1937
+ }
1938
+ else if (this.accept("SERVER", "PUBLICATION", "STATISTICS")) {
1939
+ objectType = this.lastSeen().text.toUpperCase();
1940
+ target = this.qualifiedName(`a ${objectType.toLowerCase()} name`);
1941
+ }
1750
1942
  else if (this.accept("AGGREGATE", "COLLATION")) {
1751
1943
  objectType = this.lastSeen().text.toUpperCase();
1752
1944
  target = this.qualifiedName(`an ${objectType.toLowerCase()} name`);
@@ -1763,7 +1955,7 @@ class PgParser extends SqlCursor {
1763
1955
  objectType = this.tokens[this.idx(-1)].text.toUpperCase();
1764
1956
  }
1765
1957
  else
1766
- return this.fail("expected TABLE, COLUMN, INDEX, VIEW, MATERIALIZED VIEW, SEQUENCE, TYPE, DOMAIN, SCHEMA, EXTENSION, FUNCTION, PROCEDURE, AGGREGATE, COLLATION, CAST, TRIGGER, EVENT TRIGGER, POLICY, ROLE or CONSTRAINT");
1958
+ return this.fail("expected TABLE, COLUMN, INDEX, VIEW, MATERIALIZED VIEW, SEQUENCE, TYPE, DOMAIN, SCHEMA, EXTENSION, FUNCTION, PROCEDURE, AGGREGATE, COLLATION, CAST, OPERATOR, TRIGGER, EVENT TRIGGER, STATISTICS, FOREIGN DATA WRAPPER, SERVER, PUBLICATION, POLICY, ROLE or CONSTRAINT");
1767
1959
  target = this.qualifiedName("an object name");
1768
1960
  if ((objectType === "FUNCTION" || objectType === "PROCEDURE") && this.isPunct("("))
1769
1961
  args = this.parenthesized();
@@ -1 +1 @@
1
- {"version":3,"file":"deep.d.ts","sourceRoot":"","sources":["../../../src/postgres/plan/deep.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAmB,KAAK,qBAAqB,EAAwD,MAAM,mCAAmC,CAAC;AAEtJ,OAAO,EAAyC,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AACvF,OAAO,EAA2B,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAI7E,OAAO,EAAkD,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAMrG,KAAK,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AA2BrC,+EAA+E;AAC/E,wBAAgB,SAAS,CAAC,CAAC,EAAE,YAAY,GAAG,KAAK,CAGhD;AA2FD,uGAAuG;AACvG,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,iBAAiB,EAAE,CAAC,EAAE,iBAAiB,GAAG,KAAK,CAkEpH;AAED,wBAAsB,oBAAoB,CACxC,OAAO,EAAE;IACP,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC,CAAC;CAC/E,GAAG,IAAI,CAAC,WAAW,EAAE,aAAa,CAAC,GACnC,OAAO,CAAC,qBAAqB,CAAC,CAyEhC"}
1
+ {"version":3,"file":"deep.d.ts","sourceRoot":"","sources":["../../../src/postgres/plan/deep.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAmB,KAAK,qBAAqB,EAAwD,MAAM,mCAAmC,CAAC;AAEtJ,OAAO,EAAyC,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AACvF,OAAO,EAA2B,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAI7E,OAAO,EAAkD,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAMrG,KAAK,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAgCrC,+EAA+E;AAC/E,wBAAgB,SAAS,CAAC,CAAC,EAAE,YAAY,GAAG,KAAK,CAGhD;AAuGD,uGAAuG;AACvG,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,iBAAiB,EAAE,CAAC,EAAE,iBAAiB,GAAG,KAAK,CA4EpH;AAED,wBAAsB,oBAAoB,CACxC,OAAO,EAAE;IACP,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC,CAAC;CAC/E,GAAG,IAAI,CAAC,WAAW,EAAE,aAAa,CAAC,GACnC,OAAO,CAAC,qBAAqB,CAAC,CAyEhC"}
@@ -37,6 +37,11 @@ const TAG = {
37
37
  [POSTGRES_ENTITY_TYPES.collation]: tags.collation,
38
38
  [POSTGRES_ENTITY_TYPES.cast]: tags.cast,
39
39
  [POSTGRES_ENTITY_TYPES.eventTrigger]: tags.eventTrigger,
40
+ [POSTGRES_ENTITY_TYPES.operator]: tags.operator,
41
+ [POSTGRES_ENTITY_TYPES.statistics]: tags.statistics,
42
+ [POSTGRES_ENTITY_TYPES.foreignDataWrapper]: tags.foreignDataWrapper,
43
+ [POSTGRES_ENTITY_TYPES.foreignServer]: tags.foreignServer,
44
+ [POSTGRES_ENTITY_TYPES.publication]: tags.publication,
40
45
  [POSTGRES_ENTITY_TYPES.extension]: tags.extension,
41
46
  [POSTGRES_ENTITY_TYPES.function]: tags.func,
42
47
  [POSTGRES_ENTITY_TYPES.procedure]: tags.procedure,
@@ -129,6 +134,18 @@ const PROP_OF_FIELD = {
129
134
  context: ["context"],
130
135
  event: ["event"],
131
136
  tags: ["tags"],
137
+ targets: ["targets"],
138
+ kinds: ["kinds"],
139
+ handler: ["handler", "handlerName", "noHandler"],
140
+ validator: ["validator", "validatorName", "noValidator"],
141
+ serverType: ["serverType"],
142
+ wrapper: ["wrapper", "wrapperName"],
143
+ allTables: ["allTables"],
144
+ tables: ["tables"],
145
+ schemas: ["schemas"],
146
+ publish: [],
147
+ viaRoot: [],
148
+ generatedColumns: [],
132
149
  };
133
150
  /** Props keys that hold constraints, by constraint kind. */
134
151
  const CONSTRAINT_PROPS = {
@@ -155,6 +172,9 @@ export function inDeclaredVocabulary(declared, live, d, l) {
155
172
  if (d.kind === "aggregate" && d.signature === l.signature)
156
173
  for (const key of ["args", "orderBy"])
157
174
  adopt(key);
175
+ if (d.kind === "operator" && d.signature === l.signature)
176
+ for (const key of ["leftArg", "rightArg"])
177
+ adopt(key);
158
178
  if (d.kind === "cast" && d.name === l.name)
159
179
  for (const key of ["sourceType", "targetType"])
160
180
  adopt(key);
@@ -195,7 +215,15 @@ export function inDeclaredVocabulary(declared, live, d, l) {
195
215
  ].map((c) => c.value);
196
216
  }
197
217
  // An aggregate's or a collation's `options` is the declaration's only when every field read from it is the same (a role's `options` shares the key).
198
- const optionFields = d.kind === "aggregate" ? ["definition"] : d.kind === "collation" ? ["provider", "lcCollate", "lcCtype", "locale", "nondeterministic", "rules"] : undefined;
218
+ const optionFields = d.kind === "aggregate" || d.kind === "operator"
219
+ ? ["definition"]
220
+ : d.kind === "collation"
221
+ ? ["provider", "lcCollate", "lcCtype", "locale", "nondeterministic", "rules"]
222
+ : d.kind === "foreignDataWrapper" || d.kind === "foreignServer"
223
+ ? ["options"]
224
+ : d.kind === "publication"
225
+ ? ["publish", "viaRoot", "generatedColumns"]
226
+ : undefined;
199
227
  if (optionFields) {
200
228
  if (optionFields.every((f) => JSON.stringify(d.fields[f]) === JSON.stringify(l.fields[f])))
201
229
  adopt("options");
@@ -1 +1 @@
1
- {"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../../src/postgres/plan/diff.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAoB,KAAK,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAuB,KAAK,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC3F,OAAO,EAAkE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACvH,OAAO,EAAmE,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AACnH,OAAO,EAAe,KAAK,YAAY,EAAE,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/E,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,oBAAoB,CAAC;AAExE,4HAA4H;AAC5H,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,MAAM,QAAQ,GAAG,gBAAgB,CAAC,kBAAkB,EAAE,aAAa,CAAC,CAAC;AAE3E,MAAM,WAAW,YAAa,SAAQ,SAAS,CAAC,QAAQ,CAAC;IACvD,6EAA6E;IAC7E,OAAO,EAAE,QAAQ,EAAE,CAAC;IACpB,8FAA8F;IAC9F,YAAY,CAAC,EAAE,6BAA6B,EAAE,CAAC;IAC/C,sHAAsH;IACtH,MAAM,CAAC,EAAE,YAAY,EAAE,CAAC;CACzB;AAqHD,gDAAgD;AAChD,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,mBAAmB,GAAG,kBAAkB,CAa5E;AA4OD;;;GAGG;AACH;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,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,CAAC,EAAE,YAAY,EAAE,CAAC;CACzB;AAqHD,gDAAgD;AAChD,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,mBAAmB,GAAG,kBAAkB,CAa5E;AA+QD;;;GAGG;AACH;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,EAAE,KAAK,EAAE,SAAS,cAAc,EAAE,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,YAAY,CAAC,CAAC,CAUpJ;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,SAAS,cAAc,EAAE,EAAE,QAAQ,EAAE,SAAS,cAAc,EAAE,EAAE,OAAO,GAAE,aAAkB,GAAG,YAAY,CAqClJ"}
@@ -201,7 +201,7 @@ function diffUnparsed(key, before, after, out, hints) {
201
201
  }
202
202
  }
203
203
  /** The kinds (#3911) whose definition has no ALTER: a change is a drop and a create, or (an aggregate's) CREATE OR REPLACE. */
204
- const REPLACED_KINDS = new Set(["composite", "range", "aggregate", "collation", "cast", "eventTrigger"]);
204
+ const REPLACED_KINDS = new Set(["composite", "range", "aggregate", "collation", "cast", "eventTrigger", "operator", "statistics"]);
205
205
  /** What each of {@link REPLACED_KINDS} compares besides its name and comment. */
206
206
  const DEFINITION = {
207
207
  composite: ["attributeDefs"],
@@ -210,7 +210,41 @@ const DEFINITION = {
210
210
  collation: ["provider", "lcCollate", "lcCtype", "locale", "nondeterministic", "rules"],
211
211
  cast: ["castMethod", "function", "context"],
212
212
  eventTrigger: ["event", "tags", "function"],
213
+ operator: ["definition"],
214
+ statistics: ["table", "kinds", "targets"],
213
215
  };
216
+ /** The kinds (#3911) the server alters in place, with the fields that cannot be altered (the object is dropped and created) and those that can. */
217
+ const ALTERED_KINDS = {
218
+ foreignDataWrapper: { recreate: [], inPlace: ["handler", "validator", "options"] },
219
+ foreignServer: { recreate: ["serverType", "wrapper"], inPlace: ["version", "options"] },
220
+ publication: { recreate: ["allTables"], inPlace: ["tables", "schemas", "publish", "viaRoot", "generatedColumns"] },
221
+ };
222
+ /**
223
+ * A foreign data wrapper's, foreign server's or publication's change: the
224
+ * comment and each field ALTER reaches in place (SQLPG303); a field it does
225
+ * not reach (a server's type and wrapper, a publication's FOR ALL TABLES) by
226
+ * dropping and creating the object (SQLPG300), refused while something
227
+ * depends on it (SQLPG301).
228
+ */
229
+ function diffAltered(key, before, after, out) {
230
+ if (!same(before.fields.comment, after.fields.comment))
231
+ out.push(change(key, "comment", "SQLPG216", show(before.fields.comment), show(after.fields.comment)));
232
+ const { recreate, inPlace } = ALTERED_KINDS[after.kind];
233
+ const replaced = recreate.filter((k) => !same(before.fields[k], after.fields[k]));
234
+ if (replaced.length > 0) {
235
+ const was = replaced.map((k) => `${k} ${show(before.fields[k]) ?? "-"}`).join("; ");
236
+ const now = replaced.map((k) => `${k} ${show(after.fields[k]) ?? "-"}`).join("; ");
237
+ if (before.dependents && before.dependents.length > 0) {
238
+ out.push(change(key, replaced.join(", "), "SQLPG301", was, now, { note: `${before.dependents.join(", ")} depend${before.dependents.length === 1 ? "s" : ""} on it` }));
239
+ }
240
+ else
241
+ out.push(change(key, replaced.join(", "), "SQLPG300", was, now));
242
+ return;
243
+ }
244
+ for (const k of inPlace)
245
+ if (!same(before.fields[k], after.fields[k]))
246
+ out.push(change(key, k, "SQLPG303", show(before.fields[k]), show(after.fields[k])));
247
+ }
214
248
  /**
215
249
  * A type's, aggregate's, collation's, cast's or event trigger's change: its
216
250
  * comment in place; its definition by CREATE OR REPLACE AGGREGATE where that
@@ -260,6 +294,10 @@ function diffObject(key, before, after, out, hints, major) {
260
294
  diffReplaced(key, before, after, out);
261
295
  return;
262
296
  }
297
+ if (after.kind in ALTERED_KINDS) {
298
+ diffAltered(key, before, after, out);
299
+ return;
300
+ }
263
301
  if (before.schema !== after.schema || before.name !== after.name) {
264
302
  out.push(change(key, "name", after.kind === "index" ? "SQLPG229" : "SQLPG228", qualified(before), qualified(after)));
265
303
  }
@@ -42,7 +42,7 @@
42
42
  * plan or a deep read has one (`./server-normalize.ts`). Offline, between two
43
43
  * builds, only the rules apply.
44
44
  */
45
- import type { AggregateProps, CastProps, RoutineProps } from "../entities.js";
45
+ import type { OperatorProps, AggregateProps, CastProps, RoutineProps } from "../entities.js";
46
46
  /** The integer type a serial spelling stands for, or undefined for any other type. */
47
47
  export declare const serialBase: (type: string | undefined) => string | undefined;
48
48
  /** A qualified name in canonical form: each piece unquoted where it can be, the default schema added to a bare one. */
@@ -85,7 +85,7 @@ export interface CanonicalConstraint {
85
85
  notValid?: boolean;
86
86
  comment?: string;
87
87
  }
88
- export type CanonicalKind = "schema" | "table" | "index" | "view" | "materializedView" | "sequence" | "enum" | "composite" | "range" | "domain" | "extension" | "aggregate" | "collation" | "cast" | "eventTrigger" | "function" | "procedure" | "trigger" | "policy" | "role" | "grant" | "defaultPrivileges";
88
+ export type CanonicalKind = "schema" | "table" | "index" | "view" | "materializedView" | "sequence" | "enum" | "composite" | "range" | "domain" | "extension" | "aggregate" | "collation" | "cast" | "eventTrigger" | "operator" | "statistics" | "foreignDataWrapper" | "foreignServer" | "publication" | "function" | "procedure" | "trigger" | "policy" | "role" | "grant" | "defaultPrivileges";
89
89
  /** The kinds whose declarations are privileges, compared as the access they add up to (`../access/`), not one by one. */
90
90
  export declare const ACCESS_KINDS: ReadonlySet<CanonicalKind>;
91
91
  /** The kinds a profile manages only when it says so (`sql.profiles.<env>.access`). */
@@ -135,6 +135,21 @@ export declare const canonicalCollation: (text: string) => string;
135
135
  export declare function defaultMultirangeName(range: string): string;
136
136
  /** An aggregate's identity among its overloads: `(integer)`, `(*)`, `(text ORDER BY integer)`. */
137
137
  export declare function aggregateSignature(p: Pick<AggregateProps, "args" | "orderBy">, defaultSchema: string): string;
138
+ /** An operator's identity among its overloads: its operand types, `(integer,integer)`, `NONE` for a missing side. */
139
+ export declare function operatorSignature(p: Pick<OperatorProps, "leftArg" | "rightArg">, defaultSchema: string): string;
140
+ /**
141
+ * An operator named where another object names it (a COMMUTATOR or NEGATOR):
142
+ * `OPERATOR(app.===)`, `app.===` or a bare symbol, which the server looks for
143
+ * in the new operator's own schema, as `schema.symbol`.
144
+ */
145
+ export declare function canonicalOperatorRef(text: string, ownSchema: string): string;
146
+ /**
147
+ * The kinds of statistics gathered, sorted. Left out, the server builds all
148
+ * three, except for a lone expression, which gets none of them (only the
149
+ * expression's own statistics); `pg_get_statisticsobjdef` prints the list only
150
+ * when it is not that default.
151
+ */
152
+ export declare function statisticsKinds(kinds: readonly string[] | undefined, targets: readonly string[]): string[] | undefined;
138
153
  /** A cast's name, `(source AS target)`, its types canonical. */
139
154
  export declare const castName: (p: Pick<CastProps, "sourceType" | "targetType">, defaultSchema: string) => string;
140
155
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../../src/postgres/plan/normalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAQH,OAAO,KAAK,EAEV,cAAc,EACd,SAAS,EAmBT,YAAY,EAKb,MAAM,aAAa,CAAC;AAsCrB,sFAAsF;AACtF,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,GAAG,SAAS,KAAG,MAAM,GAAG,SAAiE,CAAC;AAEjI,uHAAuH;AACvH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAQ1E;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,aAAa,SAAW,GAAG,MAAM,GAAG,SAAS,CAgCpG;AA8CD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAyB1E;AAmDD,2HAA2H;AAC3H,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,G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AM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,SAAW,GAAG,iBAAiB,CA6RjI;AAED,kHAAkH;AAClH,wBAAgB,cAAc,CAAC,CAAC,EAAE,mBAAmB,EAAE,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAEtF;AAED,gEAAgE;AAChE,eAAO,MAAM,WAAW,GAAI,2BAA2B,eAAe,KAAG,MAA8B,CAAC"}
@@ -303,6 +303,11 @@ const kindOf = {
303
303
  "Postgres::Collation": "collation",
304
304
  "Postgres::Cast": "cast",
305
305
  "Postgres::EventTrigger": "eventTrigger",
306
+ "Postgres::Operator": "operator",
307
+ "Postgres::Statistics": "statistics",
308
+ "Postgres::ForeignDataWrapper": "foreignDataWrapper",
309
+ "Postgres::ForeignServer": "foreignServer",
310
+ "Postgres::Publication": "publication",
306
311
  "Postgres::Extension": "extension",
307
312
  "Postgres::Function": "function",
308
313
  "Postgres::Procedure": "procedure",
@@ -524,7 +529,7 @@ function triggerFields(p, defaultSchema, fields) {
524
529
  }
525
530
  // ── Types, aggregates, collations, casts, event triggers (#3911) ──────
526
531
  /** The kinds that live in no schema. */
527
- const UNPLACED = new Set(["schema", "extension", "role", "cast", "eventTrigger"]);
532
+ const UNPLACED = new Set(["schema", "extension", "role", "cast", "eventTrigger", "foreignDataWrapper", "foreignServer", "publication"]);
528
533
  /**
529
534
  * A function named where an object calls it (an aggregate's SFUNC, a cast's
530
535
  * or an event trigger's function), as the catalog's `regproc` prints it with
@@ -616,6 +621,77 @@ function collationFields(p, fields) {
616
621
  fields.nondeterministic = p.options.deterministic !== undefined && !isTrue(p.options.deterministic);
617
622
  fields.rules = o.rules;
618
623
  }
624
+ /** An operator's identity among its overloads: its operand types, `(integer,integer)`, `NONE` for a missing side. */
625
+ export function operatorSignature(p, defaultSchema) {
626
+ const side = (t) => (t === undefined ? "NONE" : canonicalArgType(t, defaultSchema));
627
+ return `(${side(p.leftArg)},${side(p.rightArg)})`;
628
+ }
629
+ /**
630
+ * An operator named where another object names it (a COMMUTATOR or NEGATOR):
631
+ * `OPERATOR(app.===)`, `app.===` or a bare symbol, which the server looks for
632
+ * in the new operator's own schema, as `schema.symbol`.
633
+ */
634
+ export function canonicalOperatorRef(text, ownSchema) {
635
+ const inner = text.trim().replace(/^OPERATOR\s*\(\s*(.*?)\s*\)$/is, "$1");
636
+ const m = /^("(?:[^"]|"")+"|[A-Za-z_][A-Za-z0-9_$]*)\s*\.\s*(\S.*)$/s.exec(inner);
637
+ return `${quoteIdent(m ? identValue(m[1]) : ownSchema)}.${(m ? m[2] : inner).trim()}`;
638
+ }
639
+ /** An operator's definition as compared: each function and operator named canonically, a flag only when set. */
640
+ function operatorOptions(p, ownSchema, defaultSchema) {
641
+ const out = {};
642
+ for (const [k, v] of Object.entries(p.options)) {
643
+ if (k === "function" || k === "restrict" || k === "join")
644
+ out[k] = canonicalFunctionName(v, defaultSchema);
645
+ else if (k === "commutator" || k === "negator")
646
+ out[k] = canonicalOperatorRef(v, ownSchema);
647
+ else if (k === "hashes" || k === "merges") {
648
+ if (isTrue(v))
649
+ out[k] = "true";
650
+ }
651
+ else
652
+ out[k] = defValue(v);
653
+ }
654
+ return Object.fromEntries(Object.entries(out).sort(([a], [b]) => (a < b ? -1 : 1)));
655
+ }
656
+ /** An `OPTIONS (...)` list as compared: by name, none as nothing. */
657
+ function sortedOptions(options) {
658
+ const entries = Object.entries(options ?? {}).sort(([a], [b]) => (a < b ? -1 : 1));
659
+ return entries.length > 0 ? Object.fromEntries(entries) : undefined;
660
+ }
661
+ const STATISTICS_ALL = ["dependencies", "mcv", "ndistinct"];
662
+ /**
663
+ * The kinds of statistics gathered, sorted. Left out, the server builds all
664
+ * three, except for a lone expression, which gets none of them (only the
665
+ * expression's own statistics); `pg_get_statisticsobjdef` prints the list only
666
+ * when it is not that default.
667
+ */
668
+ export function statisticsKinds(kinds, targets) {
669
+ if (kinds && kinds.length > 0) {
670
+ const sorted = [...new Set(kinds.map((k) => k.toLowerCase()))].sort();
671
+ return sorted.join() === STATISTICS_ALL.join() ? undefined : sorted;
672
+ }
673
+ const lone = targets.length === 1 && !/^"?[A-Za-z_][A-Za-z0-9_$]*"?$/.test(targets[0].trim());
674
+ return lone ? ["none"] : undefined;
675
+ }
676
+ /** Every action a publication publishes when `publish` is not given. */
677
+ const PUBLISH_ALL = ["delete", "insert", "truncate", "update"];
678
+ /** A publication as compared: its tables with their column lists and row filters, its schemas, and each option at its default left out. */
679
+ function publicationFields(p, defaultSchema, fields) {
680
+ fields.allTables = p.allTables === true;
681
+ const tables = p.tables.map((t) => ({
682
+ table: canonicalName(t.tableName, defaultSchema),
683
+ ...(t.columns && t.columns.length > 0 ? { columns: [...t.columns].sort() } : {}),
684
+ ...(t.where ? { where: canonicalExpr(t.where) } : {}),
685
+ }));
686
+ fields.tables = tables.length > 0 ? tables.sort((a, b) => (a.table < b.table ? -1 : 1)) : undefined;
687
+ fields.schemas = p.schemas.length > 0 ? p.schemas.map((s) => quoteIdent(identValue(s))).sort() : undefined;
688
+ const o = p.options;
689
+ const publish = o.publish === undefined ? PUBLISH_ALL : [...new Set(defValue(o.publish).split(",").map((x) => x.trim().toLowerCase()).filter(Boolean))].sort();
690
+ fields.publish = publish.join() === PUBLISH_ALL.join() ? undefined : publish;
691
+ fields.viaRoot = isTrue(o.publish_via_partition_root);
692
+ const generated = o.publish_generated_columns === undefined ? "none" : defValue(o.publish_generated_columns);
693
+ fields.generatedColumns = generated === "none" ? undefined : generated;
694
+ }
619
695
  /** A cast's name, `(source AS target)`, its types canonical. */
620
696
  export const castName = (p, defaultSchema) => `(${canonicalType(p.sourceType, defaultSchema)} AS ${canonicalType(p.targetType, defaultSchema)})`;
621
697
  /**
@@ -688,6 +764,38 @@ export function canonicalPgObject(entityType, props, defaultSchema = "public") {
688
764
  fields.function = canonicalFunctionName(p.functionName, defaultSchema);
689
765
  break;
690
766
  }
767
+ case "operator": {
768
+ const p = props;
769
+ base.signature = operatorSignature(p, defaultSchema);
770
+ fields.definition = operatorOptions(p, base.schema, defaultSchema);
771
+ break;
772
+ }
773
+ case "statistics": {
774
+ const p = props;
775
+ fields.table = canonicalName(p.tableName, defaultSchema);
776
+ const targets = p.targets.map((t) => canonicalExpr(t)).sort();
777
+ fields.targets = targets;
778
+ fields.kinds = statisticsKinds(p.kinds, p.targets);
779
+ break;
780
+ }
781
+ case "foreignDataWrapper": {
782
+ const p = props;
783
+ fields.handler = p.handlerName && !p.noHandler ? canonicalFunctionName(p.handlerName, defaultSchema) : undefined;
784
+ fields.validator = p.validatorName && !p.noValidator ? canonicalFunctionName(p.validatorName, defaultSchema) : undefined;
785
+ fields.options = sortedOptions(p.options);
786
+ break;
787
+ }
788
+ case "foreignServer": {
789
+ const p = props;
790
+ fields.serverType = p.serverType;
791
+ fields.version = p.version;
792
+ fields.wrapper = quoteIdent(identValue(p.wrapperName));
793
+ fields.options = sortedOptions(p.options);
794
+ break;
795
+ }
796
+ case "publication":
797
+ publicationFields(props, defaultSchema, fields);
798
+ break;
691
799
  case "function":
692
800
  case "procedure": {
693
801
  const p = props;
@@ -96,6 +96,7 @@ export declare const PG_CLASSIFIER_RULES: {
96
96
  readonly SQLPG300: PgClassifierRule;
97
97
  readonly SQLPG301: PgClassifierRule;
98
98
  readonly SQLPG302: PgClassifierRule;
99
+ readonly SQLPG303: PgClassifierRule;
99
100
  readonly SQLPG270: PgClassifierRule;
100
101
  };
101
102
  export type PgClassifierRuleId = keyof typeof PG_CLASSIFIER_RULES;
@@ -1 +1 @@
1
- {"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../../src/postgres/plan/rules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAkB,KAAK,aAAa,EAAE,KAAK,cAAc,IAAI,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAErH,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,UAAU,GAAG,cAAc,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;AAEhH,MAAM,MAAM,gBAAgB,GAAG,iBAAiB,CAAC,aAAa,CAAC,CAAC;AAEhE,eAAO,MAAM,iBAAiB,EAAE,aAAa,CAAC,aAAa,CAY1D,CAAC;AASF,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqUqB,CAAC;AAEtD,MAAM,MAAM,kBAAkB,GAAG,MAAM,OAAO,mBAAmB,CAAC"}
1
+ {"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../../src/postgres/plan/rules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAkB,KAAK,aAAa,EAAE,KAAK,cAAc,IAAI,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAErH,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,UAAU,GAAG,cAAc,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;AAEhH,MAAM,MAAM,gBAAgB,GAAG,iBAAiB,CAAC,aAAa,CAAC,CAAC;AAEhE,eAAO,MAAM,iBAAiB,EAAE,aAAa,CAAC,aAAa,CAY1D,CAAC;AASF,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4UqB,CAAC;AAEtD,MAAM,MAAM,kBAAkB,GAAG,MAAM,OAAO,mBAAmB,CAAC"}
@@ -108,8 +108,9 @@ export const PG_CLASSIFIER_RULES = {
108
108
  SQLPG297: rule("SQLPG297", "metadata", "Revoke a privilege", "REVOKE removes from the object's privileges in the catalog. The role loses it at once: its next statement that needs it fails, so move every reader off it first.", `${DOCS}/sql-revoke.html`),
109
109
  SQLPG298: rule("SQLPG298", "metadata", "Change default privileges", "ALTER DEFAULT PRIVILEGES changes what objects created afterwards are given; objects that exist keep their privileges.", `${DOCS}/sql-alterdefaultprivileges.html`),
110
110
  SQLPG299: rule("SQLPG299", "expand", "Change a clause chant does not read", "chant's parser does not know this clause, so it cannot tell which lock the change takes or whether an in-place statement makes it; the plan refuses it rather than guess. Review it: make it by hand with the ALTER the server documents for the clause, or as expand and contract.", `${DOCS}/sql-altertable.html`),
111
- SQLPG300: rule("SQLPG300", "metadata", "Drop and create a type, aggregate, collation, cast or event trigger", "A composite or range type's definition, a collation's, a cast's and an event trigger's have no ALTER, and an aggregate's argument types, state type and final function cannot be replaced: the object is dropped and created in one transaction. Nothing on the server depends on it (a column, a view, a function or a cast would make the DROP fail); the locks are on its catalog rows only.", `${DOCS}/sql-createtype.html`),
112
- SQLPG301: rule("SQLPG301", "expand", "Change a type, aggregate, collation or cast that other objects depend on", "No ALTER makes the change, and DROP refuses while a column, a view, a function or another object depends on the object. Create the new definition under another name, move what depends on it, then drop the old.", `${DOCS}/sql-droptype.html`),
111
+ SQLPG300: rule("SQLPG300", "metadata", "Drop and create a type, aggregate, collation, cast, event trigger, operator, statistics object, foreign server or publication", "A composite or range type's definition, a collation's, a cast's, an event trigger's, an operator's function and operands and extended statistics' have no ALTER, an aggregate's argument types, state type and final function cannot be replaced, and neither can a foreign server's type or wrapper or a publication's FOR ALL TABLES: the object is dropped and created in one transaction. Nothing on the server depends on it (a column, a view, a function or a cast would make the DROP fail); the locks are on its catalog rows only. Dropped statistics are empty until the next ANALYZE, and a publication that is dropped stops its subscribers until it is created again.", `${DOCS}/sql-createtype.html`),
112
+ SQLPG301: rule("SQLPG301", "expand", "Change a type, aggregate, collation, cast, foreign server or publication that other objects depend on", "No ALTER makes the change, and DROP refuses while a column, a view, a function or another object depends on the object. Create the new definition under another name, move what depends on it, then drop the old.", `${DOCS}/sql-droptype.html`),
113
113
  SQLPG302: rule("SQLPG302", "metadata", "Replace an aggregate's definition", "CREATE OR REPLACE AGGREGATE (14 and later) replaces the aggregate's functions and options in the catalog; no table is locked. Its argument types, its result and its kind (plain, ordered-set, hypothetical-set) have to stay the same, so a change of the state type or the final function is dropped and created instead (SQLPG300).", `${DOCS}/sql-createaggregate.html`),
114
+ SQLPG303: rule("SQLPG303", "metadata", "Alter a foreign data wrapper, foreign server or publication in place", "ALTER FOREIGN DATA WRAPPER (handler, validator, options), ALTER SERVER (version, options) and ALTER PUBLICATION (SET options, ADD and DROP TABLE and TABLES IN SCHEMA) change the object's catalog rows under a brief lock; no table is rewritten. A publication's change reaches its subscribers as the walsender next reads it: a table added is not copied to a subscription until the subscriber runs REFRESH PUBLICATION.", `${DOCS}/sql-alterpublication.html`),
114
115
  SQLPG270: rule("SQLPG270", "drop", "Drop an object", "The object and, for a table, a materialized view or a sequence, its data are gone.", `${DOCS}/sql-droptable.html`),
115
116
  };
@@ -73,7 +73,7 @@ export function pgSchemaFromBuildFile(path, defaultSchema = "public") {
73
73
  export function pgNamespace(kind) {
74
74
  if (kind === "schema" || kind === "extension" || kind === "trigger" || kind === "policy" || kind === "role")
75
75
  return kind;
76
- if (kind === "collation" || kind === "cast" || kind === "eventTrigger")
76
+ if (kind === "collation" || kind === "cast" || kind === "eventTrigger" || kind === "operator" || kind === "statistics" || kind === "foreignDataWrapper" || kind === "foreignServer" || kind === "publication")
77
77
  return kind;
78
78
  if (kind === "grant" || kind === "defaultPrivileges")
79
79
  return "grant";
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Options that hold a credential. A foreign data wrapper's or server's
3
+ * `OPTIONS (...)` can carry any name, and a password in one would be written
4
+ * into a schema file by import and sent to every reader of the plan. The
5
+ * environment supplies credentials, in a user mapping (which is not declared)
6
+ * or its own secret store, as for a role's password (`./entities.ts`).
7
+ */
8
+ /** Whether an option name reads as a credential: `password`, `sslpassword`, `secret_key`, `api_token`. */
9
+ export declare const isSecretOption: (name: string) => boolean;
10
+ //# sourceMappingURL=secret-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secret-options.d.ts","sourceRoot":"","sources":["../../src/postgres/secret-options.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,0GAA0G;AAC1G,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,KAAG,OAA2E,CAAC"}