@mason-data/cli 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/README.md +101 -73
  2. package/dist/src/api/error.js +3 -0
  3. package/dist/src/api/postgres/catalog-worker.js +49 -2
  4. package/dist/src/api/postgres/catalog.js +368 -25
  5. package/dist/src/api/postgres/encode.js +3 -1
  6. package/dist/src/api/postgres/explain.js +3 -2
  7. package/dist/src/api/postgres/listener.js +11 -3
  8. package/dist/src/api/postgres/protocol.js +39 -23
  9. package/dist/src/api/postgres/proxy.js +283 -0
  10. package/dist/src/api/postgres/schema.js +6 -0
  11. package/dist/src/api/postgres/server.js +1617 -245
  12. package/dist/src/api/postgres/translate.js +127 -10
  13. package/dist/src/api/request-log.js +18 -5
  14. package/dist/src/cdc/poll.js +5 -5
  15. package/dist/src/cli/background.js +47 -25
  16. package/dist/src/cli/bridge-stdin.js +101 -0
  17. package/dist/src/cli/cancel.js +75 -0
  18. package/dist/src/cli/command.js +170 -11
  19. package/dist/src/cli/commands.js +804 -209
  20. package/dist/src/cli/control.js +59 -0
  21. package/dist/src/cli/credentials.js +182 -0
  22. package/dist/src/cli/demo.js +20 -11
  23. package/dist/src/cli/deploy.js +574 -0
  24. package/dist/src/cli/dev.js +491 -130
  25. package/dist/src/cli/doctor.js +131 -38
  26. package/dist/src/cli/generated-files.js +143 -0
  27. package/dist/src/cli/guides.js +175 -36
  28. package/dist/src/cli/hosted.js +850 -0
  29. package/dist/src/cli/init.js +162 -65
  30. package/dist/src/cli/login.js +289 -0
  31. package/dist/src/cli/machine.js +13 -12
  32. package/dist/src/cli/main.js +11 -5
  33. package/dist/src/cli/mason.cjs +17 -0
  34. package/dist/src/cli/mcp.js +31 -22
  35. package/dist/src/cli/metrics.js +79 -0
  36. package/dist/src/cli/output-gate.js +176 -0
  37. package/dist/src/cli/page-share.js +96 -0
  38. package/dist/src/cli/pg-tls.js +14 -4
  39. package/dist/src/cli/pg-url.js +4 -0
  40. package/dist/src/cli/pin.js +19 -14
  41. package/dist/src/cli/pool-size.cjs +85 -0
  42. package/dist/src/cli/ports.js +2 -0
  43. package/dist/src/cli/preflight.js +138 -46
  44. package/dist/src/cli/project.js +142 -4
  45. package/dist/src/cli/readiness.js +76 -6
  46. package/dist/src/cli/registry.js +65 -38
  47. package/dist/src/cli/replica-hosted.js +665 -0
  48. package/dist/src/cli/replica.js +76 -0
  49. package/dist/src/cli/replication-checks.js +7 -5
  50. package/dist/src/cli/replication-mode.js +105 -26
  51. package/dist/src/cli/request-filter.js +134 -0
  52. package/dist/src/cli/roles.js +585 -0
  53. package/dist/src/cli/run-server.js +637 -48
  54. package/dist/src/cli/runs.js +1 -1
  55. package/dist/src/cli/security.js +67 -18
  56. package/dist/src/cli/serve.js +204 -46
  57. package/dist/src/cli/share-run.js +329 -0
  58. package/dist/src/cli/share.js +286 -0
  59. package/dist/src/cli/source-edit.js +75 -17
  60. package/dist/src/cli/source-role.js +344 -0
  61. package/dist/src/cli/sources.js +306 -47
  62. package/dist/src/cli/style.js +2 -1
  63. package/dist/src/cli/supervise.js +27 -24
  64. package/dist/src/cli/sync.js +55 -25
  65. package/dist/src/cli/token-hosted.js +337 -0
  66. package/dist/src/cli/tunnel.js +200 -0
  67. package/dist/src/cli/ui-ssh.js +460 -0
  68. package/dist/src/cli/ui.js +124 -17
  69. package/dist/src/cli/usage.js +128 -0
  70. package/dist/src/cli/user-hosted.js +299 -0
  71. package/dist/src/cli/user.js +573 -65
  72. package/dist/src/cli/version.js +9 -7
  73. package/dist/src/demo/seed.js +29 -0
  74. package/dist/src/duck/analyze.js +36 -20
  75. package/dist/src/duck/cancel.js +10 -1
  76. package/dist/src/duck/collation.js +266 -0
  77. package/dist/src/duck/constant-key.js +94 -0
  78. package/dist/src/duck/distinct-key.js +283 -26
  79. package/dist/src/duck/events.js +165 -0
  80. package/dist/src/duck/executor-worker.js +20 -11
  81. package/dist/src/duck/executor.js +47 -33
  82. package/dist/src/duck/explain.js +60 -46
  83. package/dist/src/duck/extensions.js +160 -0
  84. package/dist/src/duck/functions.js +461 -63
  85. package/dist/src/duck/gaps.js +48 -21
  86. package/dist/src/duck/generated-plan.js +1070 -0
  87. package/dist/src/duck/generated.js +906 -0
  88. package/dist/src/duck/grants.js +176 -0
  89. package/dist/src/duck/held-types.js +64 -0
  90. package/dist/src/duck/history.js +127 -0
  91. package/dist/src/duck/jsonb-order.js +9 -12
  92. package/dist/src/duck/kept-route.js +6 -5
  93. package/dist/src/duck/kept.js +15 -13
  94. package/dist/src/duck/late.js +1469 -40
  95. package/dist/src/duck/libc-bound.js +341 -0
  96. package/dist/src/duck/libc-order.js +892 -126
  97. package/dist/src/duck/pg-eval-worker.js +7 -1
  98. package/dist/src/duck/pg-eval.js +6 -4
  99. package/dist/src/duck/pgtree.js +774 -23
  100. package/dist/src/duck/plan.js +369 -47
  101. package/dist/src/duck/publication.js +20 -6
  102. package/dist/src/duck/requests.js +269 -93
  103. package/dist/src/duck/resolved.js +117 -2
  104. package/dist/src/duck/rewrite.js +4584 -580
  105. package/dist/src/duck/row-filter.js +655 -0
  106. package/dist/src/duck/statement.js +19 -0
  107. package/dist/src/duck/store.js +439 -177
  108. package/dist/src/duck/stream.js +19 -10
  109. package/dist/src/duck/sync.js +1411 -368
  110. package/dist/src/duck/token.js +4 -1
  111. package/dist/src/duck/types.js +69 -12
  112. package/dist/src/duck/usage.js +326 -0
  113. package/dist/src/duck/users.js +69 -15
  114. package/dist/src/duck/verified.js +161 -1
  115. package/dist/src/duck/views.js +5 -5
  116. package/dist/src/lib/database-name.js +62 -0
  117. package/dist/src/lib/database-url.js +55 -10
  118. package/dist/src/lib/dotenv.js +17 -4
  119. package/dist/src/lib/instant.js +50 -0
  120. package/dist/src/lib/log-buffer.js +77 -0
  121. package/dist/src/lib/log-read.js +196 -0
  122. package/dist/src/lib/pg-numeric.js +390 -49
  123. package/dist/src/lib/project-version.js +23 -23
  124. package/dist/src/lib/secret-mask.js +142 -0
  125. package/dist/src/lib/table-sync.js +282 -0
  126. package/dist/src/web/app.css +706 -66
  127. package/dist/src/web/app.js +331 -409
  128. package/dist/src/web/charts.js +229 -0
  129. package/dist/src/web/index.html +82 -18
  130. package/dist/src/web/pages/queries.js +192 -0
  131. package/dist/src/web/pages/status.js +611 -0
  132. package/dist/src/web/pages/syncs.js +155 -0
  133. package/dist/src/web/pages/tables.js +439 -0
  134. package/dist/src/web/pages/usage.js +397 -0
  135. package/dist/src/web/pages/users.js +219 -0
  136. package/dist/src/web/shared.js +584 -0
  137. package/dist/src/web/vendor/README.md +25 -0
  138. package/dist/src/web/vendor/geist-1.7.2/Geist-Variable.woff2 +0 -0
  139. package/dist/src/web/vendor/geist-1.7.2/GeistMono-Variable.woff2 +0 -0
  140. package/dist/src/web/vendor/geist-1.7.2/LICENSE.txt +92 -0
  141. package/dist/src/web/vendor/lucide-1.56.0/LICENSE.txt +43 -0
  142. package/dist/src/web/vendor/lucide-1.56.0/chart-column.mjs +29 -0
  143. package/dist/src/web/vendor/lucide-1.56.0/layout-dashboard.mjs +29 -0
  144. package/dist/src/web/vendor/lucide-1.56.0/logs.mjs +34 -0
  145. package/dist/src/web/vendor/lucide-1.56.0/menu.mjs +28 -0
  146. package/dist/src/web/vendor/lucide-1.56.0/square-terminal.mjs +28 -0
  147. package/dist/src/web/vendor/lucide-1.56.0/table.mjs +29 -0
  148. package/dist/src/web/vendor/lucide-1.56.0/users.mjs +29 -0
  149. package/dist/src/web/vendor/lucide-1.56.0/x.mjs +27 -0
  150. package/dist/src/web/vendor/uplot-1.6.32/LICENSE.txt +21 -0
  151. package/dist/src/web/vendor/uplot-1.6.32/uPlot.esm.js +6140 -0
  152. package/dist/src/web/vendor/uplot-1.6.32/uPlot.min.css +1 -0
  153. package/dist/src/web/vendor/zilla-slab-5.3.0/LICENSE.txt +93 -0
  154. package/dist/src/web/vendor/zilla-slab-5.3.0/zilla-slab-latin-700-normal.woff2 +0 -0
  155. package/package.json +12 -4
@@ -21,10 +21,12 @@ export const VERIFIED = new Map([
21
21
  ["aggregate:2115", "the aggregate max(bigint)"],
22
22
  ["aggregate:2116", "the aggregate max(integer)"],
23
23
  ["aggregate:2117", "the aggregate max(smallint)"],
24
+ ["aggregate:2118", "the aggregate max(oid)"],
24
25
  ["aggregate:2119", "the aggregate max(real)"],
25
26
  ["aggregate:2120", "the aggregate max(double precision)"],
26
27
  ["aggregate:2122", "the aggregate max(date)"],
27
28
  ["aggregate:2123", "the aggregate max(time without time zone)"],
29
+ ["aggregate:2124", "the aggregate max(time with time zone)"],
28
30
  ["aggregate:2126", "the aggregate max(timestamp without time zone)"],
29
31
  ["aggregate:2127", "the aggregate max(timestamp with time zone)"],
30
32
  ["aggregate:2128", "the aggregate max(interval)"],
@@ -33,10 +35,12 @@ export const VERIFIED = new Map([
33
35
  ["aggregate:2131", "the aggregate min(bigint)"],
34
36
  ["aggregate:2132", "the aggregate min(integer)"],
35
37
  ["aggregate:2133", "the aggregate min(smallint)"],
38
+ ["aggregate:2134", "the aggregate min(oid)"],
36
39
  ["aggregate:2135", "the aggregate min(real)"],
37
40
  ["aggregate:2136", "the aggregate min(double precision)"],
38
41
  ["aggregate:2138", "the aggregate min(date)"],
39
42
  ["aggregate:2139", "the aggregate min(time without time zone)"],
43
+ ["aggregate:2140", "the aggregate min(time with time zone)"],
40
44
  ["aggregate:2142", "the aggregate min(timestamp without time zone)"],
41
45
  ["aggregate:2143", "the aggregate min(timestamp with time zone)"],
42
46
  ["aggregate:2144", "the aggregate min(interval)"],
@@ -95,7 +99,9 @@ export const VERIFIED = new Map([
95
99
  ["aggregate:3538", "the aggregate string_agg(text,text)"],
96
100
  ["aggregate:3972", "the aggregate percentile_disc(double precision,anyelement)"],
97
101
  ["aggregate:3974", "the aggregate percentile_cont(double precision,double precision)"],
102
+ ["aggregate:3978", "the aggregate percentile_disc(double precision[],anyelement)"],
98
103
  ["aggregate:3984", "the aggregate mode(anyelement)"],
104
+ ["aggregate:ext:latest(anyelement)", "the aggregate latest(anyelement) (an extension's)"],
99
105
  ["cast:1007>1022", "a cast from integer[] to double precision[]"],
100
106
  ["cast:1007>1043", "a cast from integer[] to character varying"],
101
107
  ["cast:1007>1231", "a cast from integer[] to numeric[]"],
@@ -104,6 +110,9 @@ export const VERIFIED = new Map([
104
110
  ["cast:1009>25", "a cast from text[] to text"],
105
111
  ["cast:1015>1009", "a cast from character varying[] to text[]"],
106
112
  ["cast:1016>25", "a cast from bigint[] to text"],
113
+ ["cast:1017>25", "a cast from point[] to text"],
114
+ ["cast:1028>25", "a cast from oid[] to text"],
115
+ ["cast:1040>25", "a cast from macaddr[] to text"],
107
116
  ["cast:1042>1700", "a cast from character to numeric"],
108
117
  ["cast:1042>23", "a cast from character to integer"],
109
118
  ["cast:1042>701", "a cast from character to double precision"],
@@ -129,11 +138,19 @@ export const VERIFIED = new Map([
129
138
  ["cast:114>25", "a cast from json to text"],
130
139
  ["cast:114>3802", "a cast from json to jsonb"],
131
140
  ["cast:1182>25", "a cast from date[] to text"],
141
+ ["cast:1183>25", "a cast from time without time zone[] to text"],
132
142
  ["cast:1184>1043", "a cast from timestamp with time zone to character varying"],
133
143
  ["cast:1184>25", "a cast from timestamp with time zone to text"],
134
144
  ["cast:1185>25", "a cast from timestamp with time zone[] to text"],
135
145
  ["cast:1186>1043", "a cast from interval to character varying"],
136
146
  ["cast:1186>25", "a cast from interval to text"],
147
+ ["cast:1231>1022", "a cast from numeric[] to double precision[]"],
148
+ ["cast:1266>25", "a cast from time with time zone to text"],
149
+ ["cast:1270>25", "a cast from time with time zone[] to text"],
150
+ ["cast:1560>1562", "a cast from bit to bit varying"],
151
+ ["cast:1560>25", "a cast from bit to text"],
152
+ ["cast:1561>25", "a cast from bit[] to text"],
153
+ ["cast:1562>25", "a cast from bit varying to text"],
137
154
  ["cast:1700>1043", "a cast from numeric to character varying"],
138
155
  ["cast:1700>1700", "a cast from numeric to numeric"],
139
156
  ["cast:1700>25", "a cast from numeric to text"],
@@ -142,9 +159,12 @@ export const VERIFIED = new Map([
142
159
  ["cast:20>25", "a cast from bigint to text"],
143
160
  ["cast:21>1043", "a cast from smallint to character varying"],
144
161
  ["cast:21>25", "a cast from smallint to text"],
162
+ ["cast:2205>25", "a cast from regclass to text"],
163
+ ["cast:2206>25", "a cast from regtype to text"],
145
164
  ["cast:2249>25", "a cast from record to text"],
146
165
  ["cast:23>1043", "a cast from integer to character varying"],
147
166
  ["cast:23>25", "a cast from integer to text"],
167
+ ["cast:23>26", "a cast from integer to oid"],
148
168
  ["cast:25>1042", "a cast from text to character"],
149
169
  ["cast:25>1043", "a cast from text to character varying"],
150
170
  ["cast:25>1082", "a cast from text to date"],
@@ -162,18 +182,52 @@ export const VERIFIED = new Map([
162
182
  ["cast:25>700", "a cast from text to real"],
163
183
  ["cast:25>701", "a cast from text to double precision"],
164
184
  ["cast:25>ext:mood", "a cast from text to mood (an extension's)"],
185
+ ["cast:26>25", "a cast from oid to text"],
186
+ ["cast:27>25", "a cast from tid to text"],
187
+ ["cast:28>25", "a cast from xid to text"],
165
188
  ["cast:2950>1043", "a cast from uuid to character varying"],
166
189
  ["cast:2950>25", "a cast from uuid to text"],
190
+ ["cast:29>25", "a cast from cid to text"],
191
+ ["cast:3220>25", "a cast from pg_lsn to text"],
192
+ ["cast:3614>25", "a cast from tsvector to text"],
193
+ ["cast:3615>25", "a cast from tsquery to text"],
194
+ ["cast:3643>25", "a cast from tsvector[] to text"],
167
195
  ["cast:3802>1043", "a cast from jsonb to character varying"],
168
196
  ["cast:3802>114", "a cast from jsonb to json"],
169
197
  ["cast:3802>25", "a cast from jsonb to text"],
198
+ ["cast:3904>25", "a cast from int4range to text"],
199
+ ["cast:3905>25", "a cast from int4range[] to text"],
200
+ ["cast:3906>25", "a cast from numrange to text"],
201
+ ["cast:3908>25", "a cast from tsrange to text"],
202
+ ["cast:3910>25", "a cast from tstzrange to text"],
203
+ ["cast:3912>25", "a cast from daterange to text"],
204
+ ["cast:3926>25", "a cast from int8range to text"],
205
+ ["cast:4072>25", "a cast from jsonpath to text"],
206
+ ["cast:4451>25", "a cast from int4multirange to text"],
207
+ ["cast:4534>25", "a cast from tstzmultirange to text"],
208
+ ["cast:5069>25", "a cast from xid8 to text"],
209
+ ["cast:600>25", "a cast from point to text"],
210
+ ["cast:601>25", "a cast from lseg to text"],
211
+ ["cast:602>25", "a cast from path to text"],
212
+ ["cast:603>25", "a cast from box to text"],
213
+ ["cast:604>25", "a cast from polygon to text"],
214
+ ["cast:628>25", "a cast from line to text"],
215
+ ["cast:650>869", "a cast from cidr to inet"],
216
+ ["cast:651>25", "a cast from cidr[] to text"],
170
217
  ["cast:700>1043", "a cast from real to character varying"],
171
218
  ["cast:700>25", "a cast from real to text"],
172
219
  ["cast:701>1043", "a cast from double precision to character varying"],
173
220
  ["cast:701>25", "a cast from double precision to text"],
221
+ ["cast:718>25", "a cast from circle to text"],
222
+ ["cast:774>25", "a cast from macaddr8 to text"],
223
+ ["cast:790>25", "a cast from money to text"],
224
+ ["cast:791>25", "a cast from money[] to text"],
225
+ ["cast:829>25", "a cast from macaddr to text"],
174
226
  ["cast:ext:citext>1043", "a cast from citext (an extension's) to character varying"],
175
227
  ["cast:ext:citext>25", "a cast from citext (an extension's) to text"],
176
228
  ["cast:ext:mood>25", "a cast from mood (an extension's) to text"],
229
+ ["cast:made>25", "a cast from a type the source made to text"],
230
+ ["cast:rowtype>25", "a cast from a table's row type to text"],
177
231
  ["field:AGGREF.aggdirectargs", "an ordered-set aggregate's direct argument"],
178
232
  ["field:AGGREF.aggdistinct", "an aggregate of DISTINCT values"],
179
233
  ["field:AGGREF.aggfilter", "an aggregate's FILTER (WHERE …)"],
@@ -198,6 +252,7 @@ export const VERIFIED = new Map([
198
252
  ["field:GROUPINGSET.kind=0", "an empty grouping set ()"],
199
253
  ["field:GROUPINGSET.kind=1", "a grouping set's column"],
200
254
  ["field:GROUPINGSET.kind=2", "ROLLUP"],
255
+ ["field:GROUPINGSET.kind=3", "CUBE"],
201
256
  ["field:GROUPINGSET.kind=4", "GROUPING SETS"],
202
257
  ["field:JOINEXPR.jointype=0", "INNER JOIN"],
203
258
  ["field:JOINEXPR.jointype=1", "LEFT JOIN"],
@@ -228,6 +283,10 @@ export const VERIFIED = new Map([
228
283
  ["field:RANGETBLENTRY.rtekind=5", "VALUES"],
229
284
  ["field:RANGETBLENTRY.rtekind=6", "a WITH query"],
230
285
  ["field:RANGETBLENTRY.rtekind=9", "GROUP BY"],
286
+ ["field:ROWCOMPAREEXPR.cmptype=1", "ROWCOMPAREEXPR.cmptype = 1"],
287
+ ["field:ROWCOMPAREEXPR.cmptype=2", "ROWCOMPAREEXPR.cmptype = 2"],
288
+ ["field:ROWCOMPAREEXPR.cmptype=4", "ROWCOMPAREEXPR.cmptype = 4"],
289
+ ["field:ROWCOMPAREEXPR.cmptype=5", "ROWCOMPAREEXPR.cmptype = 5"],
231
290
  ["field:SCALARARRAYOPEXPR.useOr=false", "op ALL (array)"],
232
291
  ["field:SCALARARRAYOPEXPR.useOr=true", "op ANY (array) / IN (list)"],
233
292
  ["field:SETOPERATIONSTMT.all=false", "UNION / INTERSECT / EXCEPT without ALL"],
@@ -240,6 +299,7 @@ export const VERIFIED = new Map([
240
299
  ["field:SQLVALUEFUNCTION.op=0", "CURRENT_DATE"],
241
300
  ["field:SQLVALUEFUNCTION.op=3", "CURRENT_TIMESTAMP"],
242
301
  ["field:SUBLINK.subLinkType=0", "EXISTS (subquery)"],
302
+ ["field:SUBLINK.subLinkType=1", "op ALL (subquery)"],
243
303
  ["field:SUBLINK.subLinkType=2", "IN / op ANY (subquery)"],
244
304
  ["field:SUBLINK.subLinkType=4", "a scalar subquery"],
245
305
  ["field:SUBLINK.subLinkType=6", "ARRAY(subquery)"],
@@ -274,6 +334,7 @@ export const VERIFIED = new Map([
274
334
  ["function:1218", "the function date_trunc(text,interval)"],
275
335
  ["function:1283", "the function quote_literal(text)"],
276
336
  ["function:1284", "the function date_trunc(text,timestamp with time zone,text)"],
337
+ ["function:1288", "the function int8(oid)"],
277
338
  ["function:1295", "the function justify_days(interval)"],
278
339
  ["function:1299", "the function now()"],
279
340
  ["function:1307", "the function \"overlaps\"(timestamp with time zone,interval,timestamp with time zone,timestamp with time zone)"],
@@ -295,6 +356,7 @@ export const VERIFIED = new Map([
295
356
  ["function:1384", "the function date_part(text,date)"],
296
357
  ["function:1385", "the function date_part(text,time without time zone)"],
297
358
  ["function:1386", "the function age(timestamp with time zone)"],
359
+ ["function:1388", "the function timetz(timestamp with time zone)"],
298
360
  ["function:1389", "the function isfinite(timestamp with time zone)"],
299
361
  ["function:1390", "the function isfinite(interval)"],
300
362
  ["function:1394", "the function abs(real)"],
@@ -305,9 +367,11 @@ export const VERIFIED = new Map([
305
367
  ["function:1400", "the function name(character varying)"],
306
368
  ["function:1481", "the function log10(numeric)"],
307
369
  ["function:1598", "the function random()"],
370
+ ["function:1619", "the function pg_typeof(\"any\")"],
308
371
  ["function:1620", "the function ascii(text)"],
309
372
  ["function:1621", "the function chr(integer)"],
310
373
  ["function:1622", "the function repeat(text,integer)"],
374
+ ["function:1685", "the function \"bit\"(bit,integer,boolean)"],
311
375
  ["function:1703", "the function \"numeric\"(numeric,integer)"],
312
376
  ["function:1705", "the function abs(numeric)"],
313
377
  ["function:1706", "the function sign(numeric)"],
@@ -322,6 +386,7 @@ export const VERIFIED = new Map([
322
386
  ["function:1732", "the function exp(numeric)"],
323
387
  ["function:1734", "the function ln(numeric)"],
324
388
  ["function:1736", "the function log(numeric,numeric)"],
389
+ ["function:1738", "the function pow(numeric,numeric)"],
325
390
  ["function:1740", "the function \"numeric\"(integer)"],
326
391
  ["function:1741", "the function log(numeric)"],
327
392
  ["function:1742", "the function \"numeric\"(real)"],
@@ -343,6 +408,7 @@ export const VERIFIED = new Map([
343
408
  ["function:1946", "the function encode(bytea,text)"],
344
409
  ["function:1961", "the function \"timestamp\"(timestamp without time zone,integer)"],
345
410
  ["function:1967", "the function timestamptz(timestamp with time zone,integer)"],
411
+ ["function:1969", "the function timetz(time with time zone,integer)"],
346
412
  ["function:1973", "the function div(numeric,numeric)"],
347
413
  ["function:1987", "the function similar_to_escape(text)"],
348
414
  ["function:2010", "the function length(bytea)"],
@@ -353,12 +419,16 @@ export const VERIFIED = new Map([
353
419
  ["function:2027", "the function \"timestamp\"(timestamp with time zone)"],
354
420
  ["function:2028", "the function timestamptz(timestamp without time zone)"],
355
421
  ["function:2029", "the function date(timestamp without time zone)"],
422
+ ["function:2037", "the function timezone(text,time with time zone)"],
423
+ ["function:2046", "the function \"time\"(time with time zone)"],
424
+ ["function:2047", "the function timetz(time without time zone)"],
356
425
  ["function:2048", "the function isfinite(timestamp without time zone)"],
357
426
  ["function:2049", "the function to_char(timestamp without time zone,text)"],
358
427
  ["function:2058", "the function age(timestamp without time zone,timestamp without time zone)"],
359
428
  ["function:2059", "the function age(timestamp without time zone)"],
360
429
  ["function:2069", "the function timezone(text,timestamp without time zone)"],
361
430
  ["function:2073", "the function \"substring\"(text,text)"],
431
+ ["function:2077", "the function current_setting(text)"],
362
432
  ["function:2087", "the function replace(text,text,text)"],
363
433
  ["function:2088", "the function split_part(text,text,integer)"],
364
434
  ["function:2089", "the function to_hex(integer)"],
@@ -410,10 +480,12 @@ export const VERIFIED = new Map([
410
480
  ["function:3207", "the function jsonb_array_length(jsonb)"],
411
481
  ["function:3208", "the function jsonb_each(jsonb)"],
412
482
  ["function:3210", "the function jsonb_typeof(jsonb)"],
483
+ ["function:3217", "the function jsonb_extract_path(jsonb,text[])"],
413
484
  ["function:3219", "the function jsonb_array_elements(jsonb)"],
414
485
  ["function:3271", "the function jsonb_build_array(\"any\")"],
415
486
  ["function:3273", "the function jsonb_build_object(\"any\")"],
416
487
  ["function:3277", "the function array_position(anycompatiblearray,anycompatible)"],
488
+ ["function:3294", "the function current_setting(text,boolean)"],
417
489
  ["function:3396", "the function regexp_match(text,text)"],
418
490
  ["function:3464", "the function make_interval(integer,integer,integer,integer,integer,integer,double precision)"],
419
491
  ["function:3465", "the function jsonb_array_elements_text(jsonb)"],
@@ -449,6 +521,7 @@ export const VERIFIED = new Map([
449
521
  ["function:4007", "the function jsonb_path_query_array(jsonb,jsonpath,jsonb,boolean)"],
450
522
  ["function:4008", "the function jsonb_path_query_first(jsonb,jsonpath,jsonb,boolean)"],
451
523
  ["function:401", "the function text(character)"],
524
+ ["function:406", "the function text(name)"],
452
525
  ["function:407", "the function name(text)"],
453
526
  ["function:409", "the function name(character)"],
454
527
  ["function:480", "the function int4(bigint)"],
@@ -463,6 +536,7 @@ export const VERIFIED = new Map([
463
536
  ["function:6177", "the function date_bin(interval,timestamp without time zone,timestamp without time zone)"],
464
537
  ["function:6199", "the function \"extract\"(text,date)"],
465
538
  ["function:6200", "the function \"extract\"(text,time without time zone)"],
539
+ ["function:6201", "the function \"extract\"(text,time with time zone)"],
466
540
  ["function:6202", "the function \"extract\"(text,timestamp without time zone)"],
467
541
  ["function:6203", "the function \"extract\"(text,timestamp with time zone)"],
468
542
  ["function:6204", "the function \"extract\"(text,interval)"],
@@ -499,8 +573,8 @@ export const VERIFIED = new Map([
499
573
  ["function:939", "the function generate_series(timestamp with time zone,timestamp with time zone,interval)"],
500
574
  ["function:940", "the function mod(smallint,smallint)"],
501
575
  ["function:941", "the function mod(integer,integer)"],
576
+ ["function:946", "the function text(\"char\")"],
502
577
  ["function:947", "the function mod(bigint,bigint)"],
503
- ["function:ext:current_setting(text)", "the function current_setting(text) (an extension's)"],
504
578
  ["node:AGGREF", "an aggregate"],
505
579
  ["node:ALIAS", "an alias"],
506
580
  ["node:ARRAYCOERCEEXPR", "a cast of an array's elements"],
@@ -532,6 +606,7 @@ export const VERIFIED = new Map([
532
606
  ["node:RANGETBLFUNCTION", "a function in FROM"],
533
607
  ["node:RANGETBLREF", "an item of FROM"],
534
608
  ["node:RELABELTYPE", "a binary-compatible cast"],
609
+ ["node:ROWCOMPAREEXPR", "a row comparison"],
535
610
  ["node:ROWEXPR", "ROW(…)"],
536
611
  ["node:RTEPERMISSIONINFO", "a table read"],
537
612
  ["node:SCALARARRAYOPEXPR", "IN (list) / op ANY|ALL (array)"],
@@ -544,6 +619,7 @@ export const VERIFIED = new Map([
544
619
  ["node:VAR", "a column"],
545
620
  ["node:WINDOWCLAUSE", "a window (OVER)"],
546
621
  ["node:WINDOWFUNC", "a window function"],
622
+ ["operator:1038", "the operator ^(numeric,numeric)"],
547
623
  ["operator:1054", "the operator =(character,character)"],
548
624
  ["operator:1055", "the operator ~(character,text)"],
549
625
  ["operator:1056", "the operator !~(character,text)"],
@@ -596,10 +672,13 @@ export const VERIFIED = new Map([
596
672
  ["operator:1204", "the operator <=(inet,inet)"],
597
673
  ["operator:1205", "the operator >(inet,inet)"],
598
674
  ["operator:1206", "the operator >=(inet,inet)"],
675
+ ["operator:1207", "the operator ~~(name,text)"],
599
676
  ["operator:1209", "the operator ~~(text,text)"],
600
677
  ["operator:1210", "the operator !~~(text,text)"],
601
678
  ["operator:1211", "the operator ~~(character,text)"],
602
679
  ["operator:1212", "the operator !~~(character,text)"],
680
+ ["operator:1220", "the operator =(macaddr,macaddr)"],
681
+ ["operator:1221", "the operator <>(macaddr,macaddr)"],
603
682
  ["operator:1228", "the operator ~*(text,text)"],
604
683
  ["operator:1229", "the operator !~*(text,text)"],
605
684
  ["operator:1234", "the operator ~*(character,text)"],
@@ -624,6 +703,12 @@ export const VERIFIED = new Map([
624
703
  ["operator:1360", "the operator +(date,time without time zone)"],
625
704
  ["operator:1399", "the operator -(time without time zone,time without time zone)"],
626
705
  ["operator:15", "the operator =(integer,bigint)"],
706
+ ["operator:1550", "the operator =(time with time zone,time with time zone)"],
707
+ ["operator:1551", "the operator <>(time with time zone,time with time zone)"],
708
+ ["operator:1552", "the operator <(time with time zone,time with time zone)"],
709
+ ["operator:1553", "the operator <=(time with time zone,time with time zone)"],
710
+ ["operator:1554", "the operator >(time with time zone,time with time zone)"],
711
+ ["operator:1555", "the operator >=(time with time zone,time with time zone)"],
627
712
  ["operator:1583", "the operator *(interval,double precision)"],
628
713
  ["operator:1584", "the operator *(double precision,interval)"],
629
714
  ["operator:1585", "the operator /(interval,double precision)"],
@@ -643,8 +728,14 @@ export const VERIFIED = new Map([
643
728
  ["operator:1760", "the operator *(numeric,numeric)"],
644
729
  ["operator:1761", "the operator /(numeric,numeric)"],
645
730
  ["operator:1762", "the operator %(numeric,numeric)"],
731
+ ["operator:1784", "the operator =(bit,bit)"],
732
+ ["operator:1785", "the operator <>(bit,bit)"],
646
733
  ["operator:1800", "the operator +(time without time zone,interval)"],
647
734
  ["operator:1801", "the operator -(time without time zone,interval)"],
735
+ ["operator:1802", "the operator +(time with time zone,interval)"],
736
+ ["operator:1803", "the operator -(time with time zone,interval)"],
737
+ ["operator:1804", "the operator =(bit varying,bit varying)"],
738
+ ["operator:1805", "the operator <>(bit varying,bit varying)"],
648
739
  ["operator:1862", "the operator =(smallint,bigint)"],
649
740
  ["operator:1863", "the operator <>(smallint,bigint)"],
650
741
  ["operator:1864", "the operator <(smallint,bigint)"],
@@ -721,11 +812,14 @@ export const VERIFIED = new Map([
721
812
  ["operator:2543", "the operator >=(timestamp with time zone,timestamp without time zone)"],
722
813
  ["operator:2544", "the operator >(timestamp with time zone,timestamp without time zone)"],
723
814
  ["operator:2545", "the operator <>(timestamp with time zone,timestamp without time zone)"],
815
+ ["operator:2552", "the operator +(interval,time with time zone)"],
724
816
  ["operator:2750", "the operator &&(anyarray,anyarray)"],
725
817
  ["operator:2751", "the operator @>(anyarray,anyarray)"],
726
818
  ["operator:2752", "the operator <@(anyarray,anyarray)"],
727
819
  ["operator:2779", "the operator ||(text,anynonarray)"],
728
820
  ["operator:2780", "the operator ||(anynonarray,text)"],
821
+ ["operator:2860", "the operator =(anymultirange,anymultirange)"],
822
+ ["operator:2861", "the operator <>(anymultirange,anymultirange)"],
729
823
  ["operator:2972", "the operator =(uuid,uuid)"],
730
824
  ["operator:2973", "the operator <>(uuid,uuid)"],
731
825
  ["operator:2974", "the operator <(uuid,uuid)"],
@@ -736,6 +830,8 @@ export const VERIFIED = new Map([
736
830
  ["operator:3211", "the operator ->(jsonb,text)"],
737
831
  ["operator:3212", "the operator ->(jsonb,integer)"],
738
832
  ["operator:3213", "the operator #>(jsonb,text[])"],
833
+ ["operator:3222", "the operator =(pg_lsn,pg_lsn)"],
834
+ ["operator:3223", "the operator <>(pg_lsn,pg_lsn)"],
739
835
  ["operator:3240", "the operator =(jsonb,jsonb)"],
740
836
  ["operator:3241", "the operator <>(jsonb,jsonb)"],
741
837
  ["operator:3242", "the operator <(jsonb,jsonb)"],
@@ -747,6 +843,9 @@ export const VERIFIED = new Map([
747
843
  ["operator:3248", "the operator ?|(jsonb,text[])"],
748
844
  ["operator:3249", "the operator ?&(jsonb,text[])"],
749
845
  ["operator:3250", "the operator <@(jsonb,jsonb)"],
846
+ ["operator:3315", "the operator <>(xid,xid)"],
847
+ ["operator:3362", "the operator =(macaddr8,macaddr8)"],
848
+ ["operator:3363", "the operator <>(macaddr8,macaddr8)"],
750
849
  ["operator:3477", "the operator ->>(jsonb,text)"],
751
850
  ["operator:3481", "the operator ->>(jsonb,integer)"],
752
851
  ["operator:349", "the operator ||(anycompatiblearray,anycompatible)"],
@@ -754,12 +853,19 @@ export const VERIFIED = new Map([
754
853
  ["operator:3517", "the operator <>(anyenum,anyenum)"],
755
854
  ["operator:3518", "the operator <(anyenum,anyenum)"],
756
855
  ["operator:3519", "the operator >(anyenum,anyenum)"],
856
+ ["operator:352", "the operator =(xid,xid)"],
757
857
  ["operator:3520", "the operator <=(anyenum,anyenum)"],
758
858
  ["operator:3521", "the operator >=(anyenum,anyenum)"],
759
859
  ["operator:36", "the operator <>(integer,bigint)"],
860
+ ["operator:3629", "the operator =(tsvector,tsvector)"],
861
+ ["operator:3630", "the operator <>(tsvector,tsvector)"],
760
862
  ["operator:37", "the operator <(integer,bigint)"],
761
863
  ["operator:374", "the operator ||(anycompatible,anycompatiblearray)"],
762
864
  ["operator:375", "the operator ||(anycompatiblearray,anycompatiblearray)"],
865
+ ["operator:385", "the operator =(cid,cid)"],
866
+ ["operator:387", "the operator =(tid,tid)"],
867
+ ["operator:3882", "the operator =(anyrange,anyrange)"],
868
+ ["operator:3883", "the operator <>(anyrange,anyrange)"],
763
869
  ["operator:3962", "the operator ->(json,text)"],
764
870
  ["operator:3963", "the operator ->>(json,text)"],
765
871
  ["operator:3964", "the operator ->(json,integer)"],
@@ -768,6 +874,7 @@ export const VERIFIED = new Map([
768
874
  ["operator:3967", "the operator #>>(json,text[])"],
769
875
  ["operator:4012", "the operator @?(jsonb,jsonpath)"],
770
876
  ["operator:4013", "the operator @@(jsonb,jsonpath)"],
877
+ ["operator:402", "the operator <>(tid,tid)"],
771
878
  ["operator:410", "the operator =(bigint,bigint)"],
772
879
  ["operator:411", "the operator <>(bigint,bigint)"],
773
880
  ["operator:412", "the operator <(bigint,bigint)"],
@@ -782,6 +889,8 @@ export const VERIFIED = new Map([
782
889
  ["operator:430", "the operator >=(bigint,integer)"],
783
890
  ["operator:439", "the operator %(bigint,bigint)"],
784
891
  ["operator:484", "the operator -(NONE,bigint)"],
892
+ ["operator:5068", "the operator =(xid8,xid8)"],
893
+ ["operator:5072", "the operator <>(xid8,xid8)"],
785
894
  ["operator:514", "the operator *(integer,integer)"],
786
895
  ["operator:518", "the operator <>(integer,integer)"],
787
896
  ["operator:519", "the operator <>(smallint,smallint)"],
@@ -833,14 +942,19 @@ export const VERIFIED = new Map([
833
942
  ["operator:592", "the operator -(double precision,double precision)"],
834
943
  ["operator:593", "the operator /(double precision,double precision)"],
835
944
  ["operator:594", "the operator *(double precision,double precision)"],
945
+ ["operator:607", "the operator =(oid,oid)"],
946
+ ["operator:608", "the operator <>(oid,oid)"],
947
+ ["operator:610", "the operator >(oid,oid)"],
836
948
  ["operator:620", "the operator =(real,real)"],
837
949
  ["operator:621", "the operator <>(real,real)"],
838
950
  ["operator:622", "the operator <(real,real)"],
839
951
  ["operator:623", "the operator >(real,real)"],
840
952
  ["operator:624", "the operator <=(real,real)"],
841
953
  ["operator:625", "the operator >=(real,real)"],
954
+ ["operator:630", "the operator <>(\"char\",\"char\")"],
842
955
  ["operator:641", "the operator ~(text,text)"],
843
956
  ["operator:642", "the operator !~(text,text)"],
957
+ ["operator:643", "the operator <>(name,name)"],
844
958
  ["operator:654", "the operator ||(text,text)"],
845
959
  ["operator:664", "the operator <(text,text)"],
846
960
  ["operator:665", "the operator <=(text,text)"],
@@ -877,6 +991,8 @@ export const VERIFIED = new Map([
877
991
  ["operator:825", "the operator /(smallint,bigint)"],
878
992
  ["operator:85", "the operator <>(boolean,boolean)"],
879
993
  ["operator:91", "the operator =(boolean,boolean)"],
994
+ ["operator:92", "the operator =(\"char\",\"char\")"],
995
+ ["operator:93", "the operator =(name,name)"],
880
996
  ["operator:94", "the operator =(smallint,smallint)"],
881
997
  ["operator:95", "the operator <(smallint,smallint)"],
882
998
  ["operator:96", "the operator =(integer,integer)"],
@@ -898,8 +1014,11 @@ export const VERIFIED = new Map([
898
1014
  ["type:1014", "a value of type character[]"],
899
1015
  ["type:1015", "a value of type character varying[]"],
900
1016
  ["type:1016", "a value of type bigint[]"],
1017
+ ["type:1017", "a value of type point[]"],
901
1018
  ["type:1021", "a value of type real[]"],
902
1019
  ["type:1022", "a value of type double precision[]"],
1020
+ ["type:1028", "a value of type oid[]"],
1021
+ ["type:1040", "a value of type macaddr[]"],
903
1022
  ["type:1041", "a value of type inet[]"],
904
1023
  ["type:1042", "a value of type character"],
905
1024
  ["type:1043", "a value of type character varying"],
@@ -915,30 +1034,71 @@ export const VERIFIED = new Map([
915
1034
  ["type:1186", "a value of type interval"],
916
1035
  ["type:1187", "a value of type interval[]"],
917
1036
  ["type:1231", "a value of type numeric[]"],
1037
+ ["type:1266", "a value of type time with time zone"],
1038
+ ["type:1270", "a value of type time with time zone[]"],
1039
+ ["type:142", "a value of type xml"],
1040
+ ["type:1560", "a value of type bit"],
1041
+ ["type:1561", "a value of type bit[]"],
1042
+ ["type:1562", "a value of type bit varying"],
918
1043
  ["type:16", "a value of type boolean"],
919
1044
  ["type:17", "a value of type bytea"],
920
1045
  ["type:1700", "a value of type numeric"],
1046
+ ["type:18", "a value of type \"char\""],
921
1047
  ["type:19", "a value of type name"],
922
1048
  ["type:199", "a value of type json[]"],
923
1049
  ["type:20", "a value of type bigint"],
924
1050
  ["type:21", "a value of type smallint"],
1051
+ ["type:2205", "a value of type regclass"],
1052
+ ["type:2206", "a value of type regtype"],
925
1053
  ["type:2249", "a value of type record"],
926
1054
  ["type:23", "a value of type integer"],
927
1055
  ["type:25", "a value of type text"],
1056
+ ["type:26", "a value of type oid"],
1057
+ ["type:27", "a value of type tid"],
1058
+ ["type:28", "a value of type xid"],
1059
+ ["type:29", "a value of type cid"],
928
1060
  ["type:2950", "a value of type uuid"],
929
1061
  ["type:2951", "a value of type uuid[]"],
1062
+ ["type:3220", "a value of type pg_lsn"],
1063
+ ["type:3614", "a value of type tsvector"],
1064
+ ["type:3615", "a value of type tsquery"],
1065
+ ["type:3643", "a value of type tsvector[]"],
930
1066
  ["type:3802", "a value of type jsonb"],
931
1067
  ["type:3807", "a value of type jsonb[]"],
1068
+ ["type:3904", "a value of type int4range"],
1069
+ ["type:3905", "a value of type int4range[]"],
1070
+ ["type:3906", "a value of type numrange"],
1071
+ ["type:3908", "a value of type tsrange"],
1072
+ ["type:3910", "a value of type tstzrange"],
1073
+ ["type:3912", "a value of type daterange"],
1074
+ ["type:3926", "a value of type int8range"],
932
1075
  ["type:4072", "a value of type jsonpath"],
1076
+ ["type:4451", "a value of type int4multirange"],
1077
+ ["type:4534", "a value of type tstzmultirange"],
1078
+ ["type:5069", "a value of type xid8"],
1079
+ ["type:600", "a value of type point"],
1080
+ ["type:601", "a value of type lseg"],
1081
+ ["type:602", "a value of type path"],
1082
+ ["type:603", "a value of type box"],
1083
+ ["type:604", "a value of type polygon"],
1084
+ ["type:628", "a value of type line"],
1085
+ ["type:650", "a value of type cidr"],
1086
+ ["type:651", "a value of type cidr[]"],
933
1087
  ["type:700", "a value of type real"],
934
1088
  ["type:701", "a value of type double precision"],
935
1089
  ["type:705", "a value of type unknown"],
1090
+ ["type:718", "a value of type circle"],
1091
+ ["type:774", "a value of type macaddr8"],
1092
+ ["type:790", "a value of type money"],
1093
+ ["type:791", "a value of type money[]"],
1094
+ ["type:829", "a value of type macaddr"],
936
1095
  ["type:869", "a value of type inet"],
937
1096
  ["type:ext:_citext", "a value of type _citext (an extension's)"],
938
1097
  ["type:ext:_mood", "a value of type _mood (an extension's)"],
939
1098
  ["type:ext:citext", "a value of type citext (an extension's)"],
940
1099
  ["type:ext:level", "a value of type level (an extension's)"],
941
1100
  ["type:ext:mood", "a value of type mood (an extension's)"],
1101
+ ["type:made", "a value of type a type the source made"],
942
1102
  ["type:rowtype", "a value of type a table's row type"],
943
1103
  ["window:2050", "the window function max(anyarray)"],
944
1104
  ["window:2051", "the window function min(anyarray)"],
@@ -15,10 +15,10 @@
15
15
  * view's name.
16
16
  */
17
17
  import { deparseSync } from "pgsql-deparser";
18
- import { StatementError } from "../api/postgres/server.js";
18
+ import { gapRefusal } from "./statement.js";
19
19
  import { parseSql } from "../api/postgres/parser.js";
20
20
  import { catalogRows } from "./analyze.js";
21
- import { gapMark } from "./gaps.js";
21
+ import { sessionSetSql } from "../api/postgres/catalog.js";
22
22
  import { treeDifference } from "./rewrite.js";
23
23
  /** views read through views read through views…: past this depth the statement is refused (a definition is never
24
24
  * recursive, so only a deep stack of views reaches it) */
@@ -28,7 +28,7 @@ const quote = (name) => `"${name.replace(/"/g, '""')}"`;
28
28
  const literal = (s) => `'${s.replace(/'/g, "''")}'`;
29
29
  const sval = (n) => isObject(n) && isObject(n.String) && typeof n.String.sval === "string" ? n.String.sval : null;
30
30
  export function viewRefused(message, hint) {
31
- return new StatementError({ code: "0A000", message, hint, detail: `${gapMark("view-forms")} (docs/SQL-SUPPORT.md)` });
31
+ return gapRefusal("view-forms", message, hint);
32
32
  }
33
33
  /** the views Postgres's analysis read: every range-table entry of a relation whose kind is a view, by OID */
34
34
  export function viewsRead(tree) {
@@ -73,7 +73,7 @@ function nodes(root) {
73
73
  * The statement with every view it reads replaced by its definition, printed; null when it reads no view. Throws a
74
74
  * StatementError (gap view-forms) where the replacement could read otherwise than Postgres does.
75
75
  */
76
- export async function expandViews(catalog, stmt, analysis, searchPathSql) {
76
+ export async function expandViews(catalog, stmt, analysis, under) {
77
77
  const read = viewsRead(analysis.tree);
78
78
  if (read.size === 0)
79
79
  return null;
@@ -83,7 +83,7 @@ export async function expandViews(catalog, stmt, analysis, searchPathSql) {
83
83
  const ctes = new Set(all.filter((n) => n.kind === "CommonTableExpr").map((n) => n.body.ctename));
84
84
  // each name the statement writes, resolved as Postgres resolves it under the session's search_path
85
85
  const spelled = ranges.map((r) => [r.body.catalogname, r.body.schemaname, r.body.relname].filter((x) => typeof x === "string").map(quote).join("."));
86
- const resolved = spelled.length === 0 ? [] : await catalogRows(catalog, `SET LOCAL search_path = ${searchPathSql}, pg_catalog; SELECT v.i::text, c.oid::text, n.nspname, c.reltype::text FROM (VALUES ${spelled.map((s, i) => `(${i}, ${literal(s)})`).join(", ")}) AS v(i, name) ` +
86
+ const resolved = spelled.length === 0 ? [] : await catalogRows(catalog, `${sessionSetSql(under, true)}; SELECT v.i::text, c.oid::text, n.nspname, c.reltype::text FROM (VALUES ${spelled.map((s, i) => `(${i}, ${literal(s)})`).join(", ")}) AS v(i, name) ` +
87
87
  `JOIN pg_class c ON c.oid = to_regclass(v.name) JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind = 'v'`);
88
88
  const asView = new Map(resolved.map(([i, oid, schema, rowType]) => [Number(i), { oid: Number(oid), schema: schema, rowType: Number(rowType) }]));
89
89
  // the names that are views must be the views Postgres read: a WITH query of a view's name is one or the other
@@ -0,0 +1,62 @@
1
+ /**
2
+ * THE DATABASE NAME A TOOL CONNECTS WITH, the one place it is decided: what the listener accepts, what `current_database()`
3
+ * and `pg_database` answer, and what every URL Mason prints ends in. It is `mason` (it shows in every connection string),
4
+ * unless the source says otherwise: `database:` in the sources file, committed, so a tool that says `database=production`
5
+ * keeps saying it. On a server whose sources file has no such line, `MASON_PG_DATABASE` says it instead.
6
+ *
7
+ * It is NOT the project's name, which stays what names the replication slot and publication (src/cli/replication-mode.ts
8
+ * `deploymentOf`): a fixed name in that place would give two projects on one source one slot, each reading away the
9
+ * other's changes. Nothing else may derive this name: a run records it in its URL (`postgresApiUrl`), and a command reads
10
+ * that URL (`postgresLink`) or, with Mason stopped, asks here (`projectDatabase`, src/cli/project.ts).
11
+ *
12
+ * When a project has more than one source, a second source with no `database:` would clash on `mason`: it is refused,
13
+ * with the exact line to add.
14
+ */
15
+ /** The name a tool connects with when nothing says another. */
16
+ export const DEFAULT_DATABASE = "mason";
17
+ /** The setting a server names it with, when its sources file does not. */
18
+ export const DATABASE_SETTING = "MASON_PG_DATABASE";
19
+ /** Postgres's longest name (NAMEDATALEN - 1): `pg_database.datname` would cut a longer one, and a tool's would not match. */
20
+ const MAX_NAME_BYTES = 63;
21
+ /**
22
+ * WHY `name` CANNOT BE A DATABASE NAME, or null. As wide as Postgres's, because the point is a tool keeping the name it
23
+ * has: capitals, dashes, dots and spaces are all real databases' (`postgres` and `template1` too: `databaseNameSql` makes
24
+ * room for them). What is refused is what could not be served: nothing, past Postgres's length, a control character,
25
+ * what no URL can carry (`.` and `..` are path steps, whatever their escaping) and a variable, since the name is written
26
+ * out (it is the same on every machine that runs the project).
27
+ */
28
+ export function databaseNameProblem(name) {
29
+ if (name === "")
30
+ return "it is empty: a tool must have a name to connect with";
31
+ const bytes = Buffer.byteLength(name);
32
+ if (bytes > MAX_NAME_BYTES)
33
+ return `${JSON.stringify(name)} is ${bytes} bytes, and a Postgres database name is at most ${MAX_NAME_BYTES}`;
34
+ if (/\p{Cc}/u.test(name))
35
+ return `${JSON.stringify(name)} holds a control character, which no tool's connection form can carry`;
36
+ if (name === "." || name === "..")
37
+ return `${JSON.stringify(name)} cannot be the last part of a connection URL, which reads it as a step in a path`;
38
+ if (name.includes("${"))
39
+ return `${JSON.stringify(name)} is a variable, and the name is written out: it is the same on every machine that runs this project`;
40
+ return null;
41
+ }
42
+ /**
43
+ * THE RULE: the sources file's `database:`, else on a server `MASON_PG_DATABASE`, else `mason`. `mason serve` refuses
44
+ * the two when they disagree, on its settings' one report (src/cli/serve.ts), so a run never has to choose.
45
+ */
46
+ export function connectDatabase(written, config, env) {
47
+ return written.database ?? (config.served === true ? env[DATABASE_SETTING] || null : null) ?? DEFAULT_DATABASE;
48
+ }
49
+ /** The setting where it means nothing (`mason start`, a project's sources file being what names it): refused, never ignored. */
50
+ export const databaseSettingRefusal = (env, shown) => {
51
+ const set = env[DATABASE_SETTING];
52
+ if (!set)
53
+ return null;
54
+ return { message: `${DATABASE_SETTING} is mason serve's setting, and mason start ignores no setting silently`,
55
+ fix: `write database: ${set} in ${shown} (it is committed, so every machine answers as it), and unset ${DATABASE_SETTING}` };
56
+ };
57
+ /**
58
+ * THE HINT OF A `3D000`: the right name, how a tool says it, and where the name is set. A client reads it before any
59
+ * password, so it never names the sources file by its path: that file is named for the source's own database.
60
+ */
61
+ export const wrongDatabaseHint = (database) => `this Mason answers as the database "${database}": connect with database=${database}, the last part of a postgres:// URL. ` +
62
+ `It is set by database: in the project's sources file (sources/<name>.yml), or ${DATABASE_SETTING} on a server`;