@congzhen/changewayguard 6.8.12

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 (329) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +270 -0
  3. package/dashboard-dist/api/104.index.js +1420 -0
  4. package/dashboard-dist/api/104.index.js.map +1 -0
  5. package/dashboard-dist/api/113.index.js +496 -0
  6. package/dashboard-dist/api/113.index.js.map +1 -0
  7. package/dashboard-dist/api/18.index.js +67 -0
  8. package/dashboard-dist/api/18.index.js.map +1 -0
  9. package/dashboard-dist/api/217.index.js +44 -0
  10. package/dashboard-dist/api/217.index.js.map +1 -0
  11. package/dashboard-dist/api/222.index.js +90 -0
  12. package/dashboard-dist/api/222.index.js.map +1 -0
  13. package/dashboard-dist/api/25.index.js +3562 -0
  14. package/dashboard-dist/api/25.index.js.map +1 -0
  15. package/dashboard-dist/api/280.index.js +206 -0
  16. package/dashboard-dist/api/280.index.js.map +1 -0
  17. package/dashboard-dist/api/369.index.js +115 -0
  18. package/dashboard-dist/api/369.index.js.map +1 -0
  19. package/dashboard-dist/api/377.index.js +1176 -0
  20. package/dashboard-dist/api/377.index.js.map +1 -0
  21. package/dashboard-dist/api/411.index.js +4250 -0
  22. package/dashboard-dist/api/411.index.js.map +1 -0
  23. package/dashboard-dist/api/424.index.js +135 -0
  24. package/dashboard-dist/api/424.index.js.map +1 -0
  25. package/dashboard-dist/api/573.index.js +806 -0
  26. package/dashboard-dist/api/573.index.js.map +1 -0
  27. package/dashboard-dist/api/598.index.js +328 -0
  28. package/dashboard-dist/api/598.index.js.map +1 -0
  29. package/dashboard-dist/api/62.index.js +4151 -0
  30. package/dashboard-dist/api/62.index.js.map +1 -0
  31. package/dashboard-dist/api/67.index.js +23383 -0
  32. package/dashboard-dist/api/67.index.js.map +1 -0
  33. package/dashboard-dist/api/678.index.js +2734 -0
  34. package/dashboard-dist/api/678.index.js.map +1 -0
  35. package/dashboard-dist/api/698.index.js +1896 -0
  36. package/dashboard-dist/api/698.index.js.map +1 -0
  37. package/dashboard-dist/api/720.index.js +98 -0
  38. package/dashboard-dist/api/720.index.js.map +1 -0
  39. package/dashboard-dist/api/830.index.js +95 -0
  40. package/dashboard-dist/api/830.index.js.map +1 -0
  41. package/dashboard-dist/api/831.index.js +99 -0
  42. package/dashboard-dist/api/831.index.js.map +1 -0
  43. package/dashboard-dist/api/84.index.js +64 -0
  44. package/dashboard-dist/api/84.index.js.map +1 -0
  45. package/dashboard-dist/api/900.index.js +65 -0
  46. package/dashboard-dist/api/900.index.js.map +1 -0
  47. package/dashboard-dist/api/917.index.js +88 -0
  48. package/dashboard-dist/api/917.index.js.map +1 -0
  49. package/dashboard-dist/api/948.index.js +64 -0
  50. package/dashboard-dist/api/948.index.js.map +1 -0
  51. package/dashboard-dist/api/953.index.js +67 -0
  52. package/dashboard-dist/api/953.index.js.map +1 -0
  53. package/dashboard-dist/api/975.index.js +374 -0
  54. package/dashboard-dist/api/975.index.js.map +1 -0
  55. package/dashboard-dist/api/drizzle/sqlite/0000_short_captain_stacy.sql +70 -0
  56. package/dashboard-dist/api/drizzle/sqlite/0001_closed_magus.sql +10 -0
  57. package/dashboard-dist/api/drizzle/sqlite/0002_agent_capability_observation.sql +38 -0
  58. package/dashboard-dist/api/drizzle/sqlite/0003_auth_magic_link.sql +28 -0
  59. package/dashboard-dist/api/drizzle/sqlite/0004_static_scan_fields.sql +8 -0
  60. package/dashboard-dist/api/drizzle/sqlite/0005_gateway_activity.sql +24 -0
  61. package/dashboard-dist/api/drizzle/sqlite/0006_sour_marauders.sql +41 -0
  62. package/dashboard-dist/api/drizzle/sqlite/meta/0000_snapshot.json +460 -0
  63. package/dashboard-dist/api/drizzle/sqlite/meta/0001_snapshot.json +536 -0
  64. package/dashboard-dist/api/drizzle/sqlite/meta/0006_snapshot.json +1249 -0
  65. package/dashboard-dist/api/drizzle/sqlite/meta/_journal.json +55 -0
  66. package/dashboard-dist/api/index.js +27340 -0
  67. package/dashboard-dist/api/index.js.map +1 -0
  68. package/dashboard-dist/api/package.json +16 -0
  69. package/dashboard-dist/api/sourcemap-register.cjs +1 -0
  70. package/dashboard-dist/web/assets/index-CqWIeBTD.js +158 -0
  71. package/dashboard-dist/web/assets/index-Dw7--9q4.css +1 -0
  72. package/dashboard-dist/web/changeway-logo.png +0 -0
  73. package/dashboard-dist/web/favicon.svg +29 -0
  74. package/dashboard-dist/web/index.html +14 -0
  75. package/dashboard-dist/web/logo.svg +16 -0
  76. package/dist/agent/auth.d.ts +37 -0
  77. package/dist/agent/auth.d.ts.map +1 -0
  78. package/dist/agent/auth.js +151 -0
  79. package/dist/agent/auth.js.map +1 -0
  80. package/dist/agent/behavior-detector.d.ts +150 -0
  81. package/dist/agent/behavior-detector.d.ts.map +1 -0
  82. package/dist/agent/behavior-detector.js +573 -0
  83. package/dist/agent/behavior-detector.js.map +1 -0
  84. package/dist/agent/business-reporter.d.ts +114 -0
  85. package/dist/agent/business-reporter.d.ts.map +1 -0
  86. package/dist/agent/business-reporter.js +359 -0
  87. package/dist/agent/business-reporter.js.map +1 -0
  88. package/dist/agent/config-sync.d.ts +70 -0
  89. package/dist/agent/config-sync.d.ts.map +1 -0
  90. package/dist/agent/config-sync.js +133 -0
  91. package/dist/agent/config-sync.js.map +1 -0
  92. package/dist/agent/config.d.ts +97 -0
  93. package/dist/agent/config.d.ts.map +1 -0
  94. package/dist/agent/config.js +359 -0
  95. package/dist/agent/config.js.map +1 -0
  96. package/dist/agent/content-injection-scanner.d.ts +35 -0
  97. package/dist/agent/content-injection-scanner.d.ts.map +1 -0
  98. package/dist/agent/content-injection-scanner.js +270 -0
  99. package/dist/agent/content-injection-scanner.js.map +1 -0
  100. package/dist/agent/engine-log-writer.d.ts +6 -0
  101. package/dist/agent/engine-log-writer.d.ts.map +1 -0
  102. package/dist/agent/engine-log-writer.js +18 -0
  103. package/dist/agent/engine-log-writer.js.map +1 -0
  104. package/dist/agent/env.d.ts +19 -0
  105. package/dist/agent/env.d.ts.map +1 -0
  106. package/dist/agent/env.js +43 -0
  107. package/dist/agent/env.js.map +1 -0
  108. package/dist/agent/event-reporter.d.ts +87 -0
  109. package/dist/agent/event-reporter.d.ts.map +1 -0
  110. package/dist/agent/event-reporter.js +315 -0
  111. package/dist/agent/event-reporter.js.map +1 -0
  112. package/dist/agent/file-watcher.d.ts +50 -0
  113. package/dist/agent/file-watcher.d.ts.map +1 -0
  114. package/dist/agent/file-watcher.js +135 -0
  115. package/dist/agent/file-watcher.js.map +1 -0
  116. package/dist/agent/fs-utils.d.ts +22 -0
  117. package/dist/agent/fs-utils.d.ts.map +1 -0
  118. package/dist/agent/fs-utils.js +41 -0
  119. package/dist/agent/fs-utils.js.map +1 -0
  120. package/dist/agent/gateway-manager.d.ts +59 -0
  121. package/dist/agent/gateway-manager.d.ts.map +1 -0
  122. package/dist/agent/gateway-manager.js +583 -0
  123. package/dist/agent/gateway-manager.js.map +1 -0
  124. package/dist/agent/hook-types.d.ts +276 -0
  125. package/dist/agent/hook-types.d.ts.map +1 -0
  126. package/dist/agent/hook-types.js +51 -0
  127. package/dist/agent/hook-types.js.map +1 -0
  128. package/dist/agent/index.d.ts +8 -0
  129. package/dist/agent/index.d.ts.map +1 -0
  130. package/dist/agent/index.js +8 -0
  131. package/dist/agent/index.js.map +1 -0
  132. package/dist/agent/prompt-gate.d.ts +13 -0
  133. package/dist/agent/prompt-gate.d.ts.map +1 -0
  134. package/dist/agent/prompt-gate.js +28 -0
  135. package/dist/agent/prompt-gate.js.map +1 -0
  136. package/dist/agent/prompt-input.d.ts +9 -0
  137. package/dist/agent/prompt-input.d.ts.map +1 -0
  138. package/dist/agent/prompt-input.js +158 -0
  139. package/dist/agent/prompt-input.js.map +1 -0
  140. package/dist/agent/prompt-output.d.ts +4 -0
  141. package/dist/agent/prompt-output.d.ts.map +1 -0
  142. package/dist/agent/prompt-output.js +19 -0
  143. package/dist/agent/prompt-output.js.map +1 -0
  144. package/dist/agent/runner.d.ts +23 -0
  145. package/dist/agent/runner.d.ts.map +1 -0
  146. package/dist/agent/runner.js +154 -0
  147. package/dist/agent/runner.js.map +1 -0
  148. package/dist/agent/sanitizer.d.ts +10 -0
  149. package/dist/agent/sanitizer.d.ts.map +1 -0
  150. package/dist/agent/sanitizer.js +175 -0
  151. package/dist/agent/sanitizer.js.map +1 -0
  152. package/dist/agent/scan-activity.d.ts +18 -0
  153. package/dist/agent/scan-activity.d.ts.map +1 -0
  154. package/dist/agent/scan-activity.js +32 -0
  155. package/dist/agent/scan-activity.js.map +1 -0
  156. package/dist/agent/types.d.ts +177 -0
  157. package/dist/agent/types.d.ts.map +1 -0
  158. package/dist/agent/types.js +5 -0
  159. package/dist/agent/types.js.map +1 -0
  160. package/dist/agent/workspace-scanner.d.ts +35 -0
  161. package/dist/agent/workspace-scanner.d.ts.map +1 -0
  162. package/dist/agent/workspace-scanner.js +137 -0
  163. package/dist/agent/workspace-scanner.js.map +1 -0
  164. package/dist/dashboard-launcher.d.ts +52 -0
  165. package/dist/dashboard-launcher.d.ts.map +1 -0
  166. package/dist/dashboard-launcher.js +363 -0
  167. package/dist/dashboard-launcher.js.map +1 -0
  168. package/dist/gateway/activity.d.ts +52 -0
  169. package/dist/gateway/activity.d.ts.map +1 -0
  170. package/dist/gateway/activity.js +111 -0
  171. package/dist/gateway/activity.js.map +1 -0
  172. package/dist/gateway/config.d.ts +50 -0
  173. package/dist/gateway/config.d.ts.map +1 -0
  174. package/dist/gateway/config.js +200 -0
  175. package/dist/gateway/config.js.map +1 -0
  176. package/dist/gateway/gateway/activity.d.ts +52 -0
  177. package/dist/gateway/gateway/activity.d.ts.map +1 -0
  178. package/dist/gateway/gateway/activity.js +111 -0
  179. package/dist/gateway/gateway/activity.js.map +1 -0
  180. package/dist/gateway/gateway/config.d.ts +50 -0
  181. package/dist/gateway/gateway/config.d.ts.map +1 -0
  182. package/dist/gateway/gateway/config.js +200 -0
  183. package/dist/gateway/gateway/config.js.map +1 -0
  184. package/dist/gateway/gateway/handlers/anthropic.d.ts +12 -0
  185. package/dist/gateway/gateway/handlers/anthropic.d.ts.map +1 -0
  186. package/dist/gateway/gateway/handlers/anthropic.js +254 -0
  187. package/dist/gateway/gateway/handlers/anthropic.js.map +1 -0
  188. package/dist/gateway/gateway/handlers/gemini.d.ts +12 -0
  189. package/dist/gateway/gateway/handlers/gemini.d.ts.map +1 -0
  190. package/dist/gateway/gateway/handlers/gemini.js +101 -0
  191. package/dist/gateway/gateway/handlers/gemini.js.map +1 -0
  192. package/dist/gateway/gateway/handlers/models.d.ts +4 -0
  193. package/dist/gateway/gateway/handlers/models.d.ts.map +1 -0
  194. package/dist/gateway/gateway/handlers/models.js +36 -0
  195. package/dist/gateway/gateway/handlers/models.js.map +1 -0
  196. package/dist/gateway/gateway/handlers/openai.d.ts +16 -0
  197. package/dist/gateway/gateway/handlers/openai.d.ts.map +1 -0
  198. package/dist/gateway/gateway/handlers/openai.js +254 -0
  199. package/dist/gateway/gateway/handlers/openai.js.map +1 -0
  200. package/dist/gateway/gateway/index.d.ts +27 -0
  201. package/dist/gateway/gateway/index.d.ts.map +1 -0
  202. package/dist/gateway/gateway/index.js +293 -0
  203. package/dist/gateway/gateway/index.js.map +1 -0
  204. package/dist/gateway/gateway/mapping-store.d.ts +38 -0
  205. package/dist/gateway/gateway/mapping-store.d.ts.map +1 -0
  206. package/dist/gateway/gateway/mapping-store.js +74 -0
  207. package/dist/gateway/gateway/mapping-store.js.map +1 -0
  208. package/dist/gateway/gateway/restorer.d.ts +63 -0
  209. package/dist/gateway/gateway/restorer.d.ts.map +1 -0
  210. package/dist/gateway/gateway/restorer.js +284 -0
  211. package/dist/gateway/gateway/restorer.js.map +1 -0
  212. package/dist/gateway/gateway/sanitizer.d.ts +17 -0
  213. package/dist/gateway/gateway/sanitizer.d.ts.map +1 -0
  214. package/dist/gateway/gateway/sanitizer.js +228 -0
  215. package/dist/gateway/gateway/sanitizer.js.map +1 -0
  216. package/dist/gateway/gateway/types.d.ts +53 -0
  217. package/dist/gateway/gateway/types.d.ts.map +1 -0
  218. package/dist/gateway/gateway/types.js +5 -0
  219. package/dist/gateway/gateway/types.js.map +1 -0
  220. package/dist/gateway/handlers/anthropic.d.ts +12 -0
  221. package/dist/gateway/handlers/anthropic.d.ts.map +1 -0
  222. package/dist/gateway/handlers/anthropic.js +254 -0
  223. package/dist/gateway/handlers/anthropic.js.map +1 -0
  224. package/dist/gateway/handlers/gemini.d.ts +12 -0
  225. package/dist/gateway/handlers/gemini.d.ts.map +1 -0
  226. package/dist/gateway/handlers/gemini.js +101 -0
  227. package/dist/gateway/handlers/gemini.js.map +1 -0
  228. package/dist/gateway/handlers/models.d.ts +4 -0
  229. package/dist/gateway/handlers/models.d.ts.map +1 -0
  230. package/dist/gateway/handlers/models.js +36 -0
  231. package/dist/gateway/handlers/models.js.map +1 -0
  232. package/dist/gateway/handlers/openai.d.ts +16 -0
  233. package/dist/gateway/handlers/openai.d.ts.map +1 -0
  234. package/dist/gateway/handlers/openai.js +254 -0
  235. package/dist/gateway/handlers/openai.js.map +1 -0
  236. package/dist/gateway/index.d.ts +27 -0
  237. package/dist/gateway/index.d.ts.map +1 -0
  238. package/dist/gateway/index.js +293 -0
  239. package/dist/gateway/index.js.map +1 -0
  240. package/dist/gateway/mapping-store.d.ts +38 -0
  241. package/dist/gateway/mapping-store.d.ts.map +1 -0
  242. package/dist/gateway/mapping-store.js +74 -0
  243. package/dist/gateway/mapping-store.js.map +1 -0
  244. package/dist/gateway/restorer.d.ts +63 -0
  245. package/dist/gateway/restorer.d.ts.map +1 -0
  246. package/dist/gateway/restorer.js +284 -0
  247. package/dist/gateway/restorer.js.map +1 -0
  248. package/dist/gateway/sanitizer.d.ts +17 -0
  249. package/dist/gateway/sanitizer.d.ts.map +1 -0
  250. package/dist/gateway/sanitizer.js +228 -0
  251. package/dist/gateway/sanitizer.js.map +1 -0
  252. package/dist/gateway/types.d.ts +53 -0
  253. package/dist/gateway/types.d.ts.map +1 -0
  254. package/dist/gateway/types.js +5 -0
  255. package/dist/gateway/types.js.map +1 -0
  256. package/dist/index.d.ts +19 -0
  257. package/dist/index.d.ts.map +1 -0
  258. package/dist/index.js +2084 -0
  259. package/dist/index.js.map +1 -0
  260. package/dist/memory/index.d.ts +5 -0
  261. package/dist/memory/index.d.ts.map +1 -0
  262. package/dist/memory/index.js +5 -0
  263. package/dist/memory/index.js.map +1 -0
  264. package/dist/memory/store.d.ts +82 -0
  265. package/dist/memory/store.d.ts.map +1 -0
  266. package/dist/memory/store.js +194 -0
  267. package/dist/memory/store.js.map +1 -0
  268. package/dist/platform-client/index.d.ts +63 -0
  269. package/dist/platform-client/index.d.ts.map +1 -0
  270. package/dist/platform-client/index.js +294 -0
  271. package/dist/platform-client/index.js.map +1 -0
  272. package/dist/platform-client/types.d.ts +109 -0
  273. package/dist/platform-client/types.d.ts.map +1 -0
  274. package/dist/platform-client/types.js +3 -0
  275. package/dist/platform-client/types.js.map +1 -0
  276. package/gateway/activity.d.ts +52 -0
  277. package/gateway/activity.d.ts.map +1 -0
  278. package/gateway/activity.js +111 -0
  279. package/gateway/activity.js.map +1 -0
  280. package/gateway/config.d.ts +50 -0
  281. package/gateway/config.d.ts.map +1 -0
  282. package/gateway/config.js +200 -0
  283. package/gateway/config.js.map +1 -0
  284. package/gateway/handlers/anthropic.d.ts +12 -0
  285. package/gateway/handlers/anthropic.d.ts.map +1 -0
  286. package/gateway/handlers/anthropic.js +254 -0
  287. package/gateway/handlers/anthropic.js.map +1 -0
  288. package/gateway/handlers/gemini.d.ts +12 -0
  289. package/gateway/handlers/gemini.d.ts.map +1 -0
  290. package/gateway/handlers/gemini.js +101 -0
  291. package/gateway/handlers/gemini.js.map +1 -0
  292. package/gateway/handlers/models.d.ts +4 -0
  293. package/gateway/handlers/models.d.ts.map +1 -0
  294. package/gateway/handlers/models.js +36 -0
  295. package/gateway/handlers/models.js.map +1 -0
  296. package/gateway/handlers/openai.d.ts +16 -0
  297. package/gateway/handlers/openai.d.ts.map +1 -0
  298. package/gateway/handlers/openai.js +254 -0
  299. package/gateway/handlers/openai.js.map +1 -0
  300. package/gateway/index.d.ts +27 -0
  301. package/gateway/index.d.ts.map +1 -0
  302. package/gateway/index.js +293 -0
  303. package/gateway/index.js.map +1 -0
  304. package/gateway/mapping-store.d.ts +38 -0
  305. package/gateway/mapping-store.d.ts.map +1 -0
  306. package/gateway/mapping-store.js +74 -0
  307. package/gateway/mapping-store.js.map +1 -0
  308. package/gateway/restorer.d.ts +63 -0
  309. package/gateway/restorer.d.ts.map +1 -0
  310. package/gateway/restorer.js +284 -0
  311. package/gateway/restorer.js.map +1 -0
  312. package/gateway/sanitizer.d.ts +17 -0
  313. package/gateway/sanitizer.d.ts.map +1 -0
  314. package/gateway/sanitizer.js +228 -0
  315. package/gateway/sanitizer.js.map +1 -0
  316. package/gateway/types.d.ts +53 -0
  317. package/gateway/types.d.ts.map +1 -0
  318. package/gateway/types.js +5 -0
  319. package/gateway/types.js.map +1 -0
  320. package/openclaw.plugin.json +86 -0
  321. package/package.json +74 -0
  322. package/samples/Untitled +1 -0
  323. package/samples/clean-email.txt +20 -0
  324. package/samples/test-document.md +53 -0
  325. package/samples/test-email-popup.txt +44 -0
  326. package/samples/test-email.txt +32 -0
  327. package/samples/test-webpage.html +51 -0
  328. package/scripts/enterprise-enroll.sh +89 -0
  329. package/scripts/enterprise-unenroll.sh +75 -0
@@ -0,0 +1,2734 @@
1
+ export const id = 678;
2
+ export const ids = [678];
3
+ export const modules = {
4
+
5
+ /***/ 5678:
6
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
7
+
8
+ // ESM COMPAT FLAG
9
+ __webpack_require__.r(__webpack_exports__);
10
+
11
+ // EXPORTS
12
+ __webpack_require__.d(__webpack_exports__, {
13
+ "default": () => (/* binding */ src)
14
+ });
15
+
16
+ // EXTERNAL MODULE: external "os"
17
+ var external_os_ = __webpack_require__(857);
18
+ // EXTERNAL MODULE: external "fs"
19
+ var external_fs_ = __webpack_require__(9896);
20
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/src/query.js
21
+ const originCache = new Map()
22
+ , originStackCache = new Map()
23
+ , originError = Symbol('OriginError')
24
+
25
+ const CLOSE = {}
26
+ class Query extends Promise {
27
+ constructor(strings, args, handler, canceller, options = {}) {
28
+ let resolve
29
+ , reject
30
+
31
+ super((a, b) => {
32
+ resolve = a
33
+ reject = b
34
+ })
35
+
36
+ this.tagged = Array.isArray(strings.raw)
37
+ this.strings = strings
38
+ this.args = args
39
+ this.handler = handler
40
+ this.canceller = canceller
41
+ this.options = options
42
+
43
+ this.state = null
44
+ this.statement = null
45
+
46
+ this.resolve = x => (this.active = false, resolve(x))
47
+ this.reject = x => (this.active = false, reject(x))
48
+
49
+ this.active = false
50
+ this.cancelled = null
51
+ this.executed = false
52
+ this.signature = ''
53
+
54
+ this[originError] = this.handler.debug
55
+ ? new Error()
56
+ : this.tagged && cachedError(this.strings)
57
+ }
58
+
59
+ get origin() {
60
+ return (this.handler.debug
61
+ ? this[originError].stack
62
+ : this.tagged && originStackCache.has(this.strings)
63
+ ? originStackCache.get(this.strings)
64
+ : originStackCache.set(this.strings, this[originError].stack).get(this.strings)
65
+ ) || ''
66
+ }
67
+
68
+ static get [Symbol.species]() {
69
+ return Promise
70
+ }
71
+
72
+ cancel() {
73
+ return this.canceller && (this.canceller(this), this.canceller = null)
74
+ }
75
+
76
+ simple() {
77
+ this.options.simple = true
78
+ this.options.prepare = false
79
+ return this
80
+ }
81
+
82
+ async readable() {
83
+ this.simple()
84
+ this.streaming = true
85
+ return this
86
+ }
87
+
88
+ async writable() {
89
+ this.simple()
90
+ this.streaming = true
91
+ return this
92
+ }
93
+
94
+ cursor(rows = 1, fn) {
95
+ this.options.simple = false
96
+ if (typeof rows === 'function') {
97
+ fn = rows
98
+ rows = 1
99
+ }
100
+
101
+ this.cursorRows = rows
102
+
103
+ if (typeof fn === 'function')
104
+ return (this.cursorFn = fn, this)
105
+
106
+ let prev
107
+ return {
108
+ [Symbol.asyncIterator]: () => ({
109
+ next: () => {
110
+ if (this.executed && !this.active)
111
+ return { done: true }
112
+
113
+ prev && prev()
114
+ const promise = new Promise((resolve, reject) => {
115
+ this.cursorFn = value => {
116
+ resolve({ value, done: false })
117
+ return new Promise(r => prev = r)
118
+ }
119
+ this.resolve = () => (this.active = false, resolve({ done: true }))
120
+ this.reject = x => (this.active = false, reject(x))
121
+ })
122
+ this.execute()
123
+ return promise
124
+ },
125
+ return() {
126
+ prev && prev(CLOSE)
127
+ return { done: true }
128
+ }
129
+ })
130
+ }
131
+ }
132
+
133
+ describe() {
134
+ this.options.simple = false
135
+ this.onlyDescribe = this.options.prepare = true
136
+ return this
137
+ }
138
+
139
+ stream() {
140
+ throw new Error('.stream has been renamed to .forEach')
141
+ }
142
+
143
+ forEach(fn) {
144
+ this.forEachFn = fn
145
+ this.handle()
146
+ return this
147
+ }
148
+
149
+ raw() {
150
+ this.isRaw = true
151
+ return this
152
+ }
153
+
154
+ values() {
155
+ this.isRaw = 'values'
156
+ return this
157
+ }
158
+
159
+ async handle() {
160
+ !this.executed && (this.executed = true) && await 1 && this.handler(this)
161
+ }
162
+
163
+ execute() {
164
+ this.handle()
165
+ return this
166
+ }
167
+
168
+ then() {
169
+ this.handle()
170
+ return super.then.apply(this, arguments)
171
+ }
172
+
173
+ catch() {
174
+ this.handle()
175
+ return super.catch.apply(this, arguments)
176
+ }
177
+
178
+ finally() {
179
+ this.handle()
180
+ return super.finally.apply(this, arguments)
181
+ }
182
+ }
183
+
184
+ function cachedError(xs) {
185
+ if (originCache.has(xs))
186
+ return originCache.get(xs)
187
+
188
+ const x = Error.stackTraceLimit
189
+ Error.stackTraceLimit = 4
190
+ originCache.set(xs, new Error())
191
+ Error.stackTraceLimit = x
192
+ return originCache.get(xs)
193
+ }
194
+
195
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/src/errors.js
196
+ class PostgresError extends Error {
197
+ constructor(x) {
198
+ super(x.message)
199
+ this.name = this.constructor.name
200
+ Object.assign(this, x)
201
+ }
202
+ }
203
+
204
+ const Errors = {
205
+ connection,
206
+ postgres,
207
+ generic,
208
+ notSupported
209
+ }
210
+
211
+ function connection(x, options, socket) {
212
+ const { host, port } = socket || options
213
+ const error = Object.assign(
214
+ new Error(('write ' + x + ' ' + (options.path || (host + ':' + port)))),
215
+ {
216
+ code: x,
217
+ errno: x,
218
+ address: options.path || host
219
+ }, options.path ? {} : { port: port }
220
+ )
221
+ Error.captureStackTrace(error, connection)
222
+ return error
223
+ }
224
+
225
+ function postgres(x) {
226
+ const error = new PostgresError(x)
227
+ Error.captureStackTrace(error, postgres)
228
+ return error
229
+ }
230
+
231
+ function generic(code, message) {
232
+ const error = Object.assign(new Error(code + ': ' + message), { code })
233
+ Error.captureStackTrace(error, generic)
234
+ return error
235
+ }
236
+
237
+ /* c8 ignore next 10 */
238
+ function notSupported(x) {
239
+ const error = Object.assign(
240
+ new Error(x + ' (B) is not supported'),
241
+ {
242
+ code: 'MESSAGE_NOT_SUPPORTED',
243
+ name: x
244
+ }
245
+ )
246
+ Error.captureStackTrace(error, notSupported)
247
+ return error
248
+ }
249
+
250
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/src/types.js
251
+
252
+
253
+
254
+ const types = {
255
+ string: {
256
+ to: 25,
257
+ from: null, // defaults to string
258
+ serialize: x => '' + x
259
+ },
260
+ number: {
261
+ to: 0,
262
+ from: [21, 23, 26, 700, 701],
263
+ serialize: x => '' + x,
264
+ parse: x => +x
265
+ },
266
+ json: {
267
+ to: 114,
268
+ from: [114, 3802],
269
+ serialize: x => JSON.stringify(x),
270
+ parse: x => JSON.parse(x)
271
+ },
272
+ boolean: {
273
+ to: 16,
274
+ from: 16,
275
+ serialize: x => x === true ? 't' : 'f',
276
+ parse: x => x === 't'
277
+ },
278
+ date: {
279
+ to: 1184,
280
+ from: [1082, 1114, 1184],
281
+ serialize: x => (x instanceof Date ? x : new Date(x)).toISOString(),
282
+ parse: x => new Date(x)
283
+ },
284
+ bytea: {
285
+ to: 17,
286
+ from: 17,
287
+ serialize: x => '\\x' + Buffer.from(x).toString('hex'),
288
+ parse: x => Buffer.from(x.slice(2), 'hex')
289
+ }
290
+ }
291
+
292
+ class NotTagged { then() { notTagged() } catch() { notTagged() } finally() { notTagged() }}
293
+
294
+ class Identifier extends NotTagged {
295
+ constructor(value) {
296
+ super()
297
+ this.value = escapeIdentifier(value)
298
+ }
299
+ }
300
+
301
+ class Parameter extends NotTagged {
302
+ constructor(value, type, array) {
303
+ super()
304
+ this.value = value
305
+ this.type = type
306
+ this.array = array
307
+ }
308
+ }
309
+
310
+ class Builder extends NotTagged {
311
+ constructor(first, rest) {
312
+ super()
313
+ this.first = first
314
+ this.rest = rest
315
+ }
316
+
317
+ build(before, parameters, types, options) {
318
+ const keyword = builders.map(([x, fn]) => ({ fn, i: before.search(x) })).sort((a, b) => a.i - b.i).pop()
319
+ return keyword.i === -1
320
+ ? escapeIdentifiers(this.first, options)
321
+ : keyword.fn(this.first, this.rest, parameters, types, options)
322
+ }
323
+ }
324
+
325
+ function handleValue(x, parameters, types, options) {
326
+ let value = x instanceof Parameter ? x.value : x
327
+ if (value === undefined) {
328
+ x instanceof Parameter
329
+ ? x.value = options.transform.undefined
330
+ : value = x = options.transform.undefined
331
+
332
+ if (value === undefined)
333
+ throw Errors.generic('UNDEFINED_VALUE', 'Undefined values are not allowed')
334
+ }
335
+
336
+ return '$' + (types.push(
337
+ x instanceof Parameter
338
+ ? (parameters.push(x.value), x.array
339
+ ? x.array[x.type || inferType(x.value)] || x.type || firstIsString(x.value)
340
+ : x.type
341
+ )
342
+ : (parameters.push(x), inferType(x))
343
+ ))
344
+ }
345
+
346
+ const defaultHandlers = typeHandlers(types)
347
+
348
+ function stringify(q, string, value, parameters, types, options) { // eslint-disable-line
349
+ for (let i = 1; i < q.strings.length; i++) {
350
+ string += (stringifyValue(string, value, parameters, types, options)) + q.strings[i]
351
+ value = q.args[i]
352
+ }
353
+
354
+ return string
355
+ }
356
+
357
+ function stringifyValue(string, value, parameters, types, o) {
358
+ return (
359
+ value instanceof Builder ? value.build(string, parameters, types, o) :
360
+ value instanceof Query ? fragment(value, parameters, types, o) :
361
+ value instanceof Identifier ? value.value :
362
+ value && value[0] instanceof Query ? value.reduce((acc, x) => acc + ' ' + fragment(x, parameters, types, o), '') :
363
+ handleValue(value, parameters, types, o)
364
+ )
365
+ }
366
+
367
+ function fragment(q, parameters, types, options) {
368
+ q.fragment = true
369
+ return stringify(q, q.strings[0], q.args[0], parameters, types, options)
370
+ }
371
+
372
+ function valuesBuilder(first, parameters, types, columns, options) {
373
+ return first.map(row =>
374
+ '(' + columns.map(column =>
375
+ stringifyValue('values', row[column], parameters, types, options)
376
+ ).join(',') + ')'
377
+ ).join(',')
378
+ }
379
+
380
+ function values(first, rest, parameters, types, options) {
381
+ const multi = Array.isArray(first[0])
382
+ const columns = rest.length ? rest.flat() : Object.keys(multi ? first[0] : first)
383
+ return valuesBuilder(multi ? first : [first], parameters, types, columns, options)
384
+ }
385
+
386
+ function types_select(first, rest, parameters, types, options) {
387
+ typeof first === 'string' && (first = [first].concat(rest))
388
+ if (Array.isArray(first))
389
+ return escapeIdentifiers(first, options)
390
+
391
+ let value
392
+ const columns = rest.length ? rest.flat() : Object.keys(first)
393
+ return columns.map(x => {
394
+ value = first[x]
395
+ return (
396
+ value instanceof Query ? fragment(value, parameters, types, options) :
397
+ value instanceof Identifier ? value.value :
398
+ handleValue(value, parameters, types, options)
399
+ ) + ' as ' + escapeIdentifier(options.transform.column.to ? options.transform.column.to(x) : x)
400
+ }).join(',')
401
+ }
402
+
403
+ const builders = Object.entries({
404
+ values,
405
+ in: (...xs) => {
406
+ const x = values(...xs)
407
+ return x === '()' ? '(null)' : x
408
+ },
409
+ select: types_select,
410
+ as: types_select,
411
+ returning: types_select,
412
+ '\\(': types_select,
413
+
414
+ update(first, rest, parameters, types, options) {
415
+ return (rest.length ? rest.flat() : Object.keys(first)).map(x =>
416
+ escapeIdentifier(options.transform.column.to ? options.transform.column.to(x) : x) +
417
+ '=' + stringifyValue('values', first[x], parameters, types, options)
418
+ )
419
+ },
420
+
421
+ insert(first, rest, parameters, types, options) {
422
+ const columns = rest.length ? rest.flat() : Object.keys(Array.isArray(first) ? first[0] : first)
423
+ return '(' + escapeIdentifiers(columns, options) + ')values' +
424
+ valuesBuilder(Array.isArray(first) ? first : [first], parameters, types, columns, options)
425
+ }
426
+ }).map(([x, fn]) => ([new RegExp('((?:^|[\\s(])' + x + '(?:$|[\\s(]))(?![\\s\\S]*\\1)', 'i'), fn]))
427
+
428
+ function notTagged() {
429
+ throw Errors.generic('NOT_TAGGED_CALL', 'Query not called as a tagged template literal')
430
+ }
431
+
432
+ const serializers = defaultHandlers.serializers
433
+ const parsers = defaultHandlers.parsers
434
+
435
+ const END = {}
436
+
437
+ function firstIsString(x) {
438
+ if (Array.isArray(x))
439
+ return firstIsString(x[0])
440
+ return typeof x === 'string' ? 1009 : 0
441
+ }
442
+
443
+ const mergeUserTypes = function(types) {
444
+ const user = typeHandlers(types || {})
445
+ return {
446
+ serializers: Object.assign({}, serializers, user.serializers),
447
+ parsers: Object.assign({}, parsers, user.parsers)
448
+ }
449
+ }
450
+
451
+ function typeHandlers(types) {
452
+ return Object.keys(types).reduce((acc, k) => {
453
+ types[k].from && [].concat(types[k].from).forEach(x => acc.parsers[x] = types[k].parse)
454
+ if (types[k].serialize) {
455
+ acc.serializers[types[k].to] = types[k].serialize
456
+ types[k].from && [].concat(types[k].from).forEach(x => acc.serializers[x] = types[k].serialize)
457
+ }
458
+ return acc
459
+ }, { parsers: {}, serializers: {} })
460
+ }
461
+
462
+ function escapeIdentifiers(xs, { transform: { column } }) {
463
+ return xs.map(x => escapeIdentifier(column.to ? column.to(x) : x)).join(',')
464
+ }
465
+
466
+ const escapeIdentifier = function escape(str) {
467
+ return '"' + str.replace(/"/g, '""').replace(/\./g, '"."') + '"'
468
+ }
469
+
470
+ const inferType = function inferType(x) {
471
+ return (
472
+ x instanceof Parameter ? x.type :
473
+ x instanceof Date ? 1184 :
474
+ x instanceof Uint8Array ? 17 :
475
+ (x === true || x === false) ? 16 :
476
+ typeof x === 'bigint' ? 20 :
477
+ Array.isArray(x) ? inferType(x[0]) :
478
+ 0
479
+ )
480
+ }
481
+
482
+ const escapeBackslash = /\\/g
483
+ const escapeQuote = /"/g
484
+
485
+ function arrayEscape(x) {
486
+ return x
487
+ .replace(escapeBackslash, '\\\\')
488
+ .replace(escapeQuote, '\\"')
489
+ }
490
+
491
+ const arraySerializer = function arraySerializer(xs, serializer, options, typarray) {
492
+ if (Array.isArray(xs) === false)
493
+ return xs
494
+
495
+ if (!xs.length)
496
+ return '{}'
497
+
498
+ const first = xs[0]
499
+ // Only _box (1020) has the ';' delimiter for arrays, all other types use the ',' delimiter
500
+ const delimiter = typarray === 1020 ? ';' : ','
501
+
502
+ if (Array.isArray(first) && !first.type)
503
+ return '{' + xs.map(x => arraySerializer(x, serializer, options, typarray)).join(delimiter) + '}'
504
+
505
+ return '{' + xs.map(x => {
506
+ if (x === undefined) {
507
+ x = options.transform.undefined
508
+ if (x === undefined)
509
+ throw Errors.generic('UNDEFINED_VALUE', 'Undefined values are not allowed')
510
+ }
511
+
512
+ return x === null
513
+ ? 'null'
514
+ : '"' + arrayEscape(serializer ? serializer(x.type ? x.value : x) : '' + x) + '"'
515
+ }).join(delimiter) + '}'
516
+ }
517
+
518
+ const arrayParserState = {
519
+ i: 0,
520
+ char: null,
521
+ str: '',
522
+ quoted: false,
523
+ last: 0
524
+ }
525
+
526
+ const arrayParser = function arrayParser(x, parser, typarray) {
527
+ arrayParserState.i = arrayParserState.last = 0
528
+ return arrayParserLoop(arrayParserState, x, parser, typarray)
529
+ }
530
+
531
+ function arrayParserLoop(s, x, parser, typarray) {
532
+ const xs = []
533
+ // Only _box (1020) has the ';' delimiter for arrays, all other types use the ',' delimiter
534
+ const delimiter = typarray === 1020 ? ';' : ','
535
+ for (; s.i < x.length; s.i++) {
536
+ s.char = x[s.i]
537
+ if (s.quoted) {
538
+ if (s.char === '\\') {
539
+ s.str += x[++s.i]
540
+ } else if (s.char === '"') {
541
+ xs.push(parser ? parser(s.str) : s.str)
542
+ s.str = ''
543
+ s.quoted = x[s.i + 1] === '"'
544
+ s.last = s.i + 2
545
+ } else {
546
+ s.str += s.char
547
+ }
548
+ } else if (s.char === '"') {
549
+ s.quoted = true
550
+ } else if (s.char === '{') {
551
+ s.last = ++s.i
552
+ xs.push(arrayParserLoop(s, x, parser, typarray))
553
+ } else if (s.char === '}') {
554
+ s.quoted = false
555
+ s.last < s.i && xs.push(parser ? parser(x.slice(s.last, s.i)) : x.slice(s.last, s.i))
556
+ s.last = s.i + 1
557
+ break
558
+ } else if (s.char === delimiter && s.p !== '}' && s.p !== '"') {
559
+ xs.push(parser ? parser(x.slice(s.last, s.i)) : x.slice(s.last, s.i))
560
+ s.last = s.i + 1
561
+ }
562
+ s.p = s.char
563
+ }
564
+ s.last < s.i && xs.push(parser ? parser(x.slice(s.last, s.i + 1)) : x.slice(s.last, s.i + 1))
565
+ return xs
566
+ }
567
+
568
+ const toCamel = x => {
569
+ let str = x[0]
570
+ for (let i = 1; i < x.length; i++)
571
+ str += x[i] === '_' ? x[++i].toUpperCase() : x[i]
572
+ return str
573
+ }
574
+
575
+ const toPascal = x => {
576
+ let str = x[0].toUpperCase()
577
+ for (let i = 1; i < x.length; i++)
578
+ str += x[i] === '_' ? x[++i].toUpperCase() : x[i]
579
+ return str
580
+ }
581
+
582
+ const toKebab = x => x.replace(/_/g, '-')
583
+
584
+ const fromCamel = x => x.replace(/([A-Z])/g, '_$1').toLowerCase()
585
+ const fromPascal = x => (x.slice(0, 1) + x.slice(1).replace(/([A-Z])/g, '_$1')).toLowerCase()
586
+ const fromKebab = x => x.replace(/-/g, '_')
587
+
588
+ function createJsonTransform(fn) {
589
+ return function jsonTransform(x, column) {
590
+ return typeof x === 'object' && x !== null && (column.type === 114 || column.type === 3802)
591
+ ? Array.isArray(x)
592
+ ? x.map(x => jsonTransform(x, column))
593
+ : Object.entries(x).reduce((acc, [k, v]) => Object.assign(acc, { [fn(k)]: jsonTransform(v, column) }), {})
594
+ : x
595
+ }
596
+ }
597
+
598
+ toCamel.column = { from: toCamel }
599
+ toCamel.value = { from: createJsonTransform(toCamel) }
600
+ fromCamel.column = { to: fromCamel }
601
+
602
+ const camel = { ...toCamel }
603
+ camel.column.to = fromCamel
604
+
605
+ toPascal.column = { from: toPascal }
606
+ toPascal.value = { from: createJsonTransform(toPascal) }
607
+ fromPascal.column = { to: fromPascal }
608
+
609
+ const pascal = { ...toPascal }
610
+ pascal.column.to = fromPascal
611
+
612
+ toKebab.column = { from: toKebab }
613
+ toKebab.value = { from: createJsonTransform(toKebab) }
614
+ fromKebab.column = { to: fromKebab }
615
+
616
+ const kebab = { ...toKebab }
617
+ kebab.column.to = fromKebab
618
+
619
+ // EXTERNAL MODULE: external "net"
620
+ var external_net_ = __webpack_require__(9278);
621
+ // EXTERNAL MODULE: external "tls"
622
+ var external_tls_ = __webpack_require__(4756);
623
+ // EXTERNAL MODULE: external "crypto"
624
+ var external_crypto_ = __webpack_require__(6982);
625
+ // EXTERNAL MODULE: external "stream"
626
+ var external_stream_ = __webpack_require__(2203);
627
+ // EXTERNAL MODULE: external "perf_hooks"
628
+ var external_perf_hooks_ = __webpack_require__(2987);
629
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/src/result.js
630
+ class Result extends Array {
631
+ constructor() {
632
+ super()
633
+ Object.defineProperties(this, {
634
+ count: { value: null, writable: true },
635
+ state: { value: null, writable: true },
636
+ command: { value: null, writable: true },
637
+ columns: { value: null, writable: true },
638
+ statement: { value: null, writable: true }
639
+ })
640
+ }
641
+
642
+ static get [Symbol.species]() {
643
+ return Array
644
+ }
645
+ }
646
+
647
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/src/queue.js
648
+ /* harmony default export */ const src_queue = (Queue);
649
+
650
+ function Queue(initial = []) {
651
+ let xs = initial.slice()
652
+ let index = 0
653
+
654
+ return {
655
+ get length() {
656
+ return xs.length - index
657
+ },
658
+ remove: (x) => {
659
+ const index = xs.indexOf(x)
660
+ return index === -1
661
+ ? null
662
+ : (xs.splice(index, 1), x)
663
+ },
664
+ push: (x) => (xs.push(x), x),
665
+ shift: () => {
666
+ const out = xs[index++]
667
+
668
+ if (index === xs.length) {
669
+ index = 0
670
+ xs = []
671
+ } else {
672
+ xs[index - 1] = undefined
673
+ }
674
+
675
+ return out
676
+ }
677
+ }
678
+ }
679
+
680
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/src/bytes.js
681
+ const size = 256
682
+ let buffer = Buffer.allocUnsafe(size)
683
+
684
+ const messages = 'BCcDdEFfHPpQSX'.split('').reduce((acc, x) => {
685
+ const v = x.charCodeAt(0)
686
+ acc[x] = () => {
687
+ buffer[0] = v
688
+ b.i = 5
689
+ return b
690
+ }
691
+ return acc
692
+ }, {})
693
+
694
+ const b = Object.assign(bytes_reset, messages, {
695
+ N: String.fromCharCode(0),
696
+ i: 0,
697
+ inc(x) {
698
+ b.i += x
699
+ return b
700
+ },
701
+ str(x) {
702
+ const length = Buffer.byteLength(x)
703
+ fit(length)
704
+ b.i += buffer.write(x, b.i, length, 'utf8')
705
+ return b
706
+ },
707
+ i16(x) {
708
+ fit(2)
709
+ buffer.writeUInt16BE(x, b.i)
710
+ b.i += 2
711
+ return b
712
+ },
713
+ i32(x, i) {
714
+ if (i || i === 0) {
715
+ buffer.writeUInt32BE(x, i)
716
+ return b
717
+ }
718
+ fit(4)
719
+ buffer.writeUInt32BE(x, b.i)
720
+ b.i += 4
721
+ return b
722
+ },
723
+ z(x) {
724
+ fit(x)
725
+ buffer.fill(0, b.i, b.i + x)
726
+ b.i += x
727
+ return b
728
+ },
729
+ raw(x) {
730
+ buffer = Buffer.concat([buffer.subarray(0, b.i), x])
731
+ b.i = buffer.length
732
+ return b
733
+ },
734
+ end(at = 1) {
735
+ buffer.writeUInt32BE(b.i - at, at)
736
+ const out = buffer.subarray(0, b.i)
737
+ b.i = 0
738
+ buffer = Buffer.allocUnsafe(size)
739
+ return out
740
+ }
741
+ })
742
+
743
+ /* harmony default export */ const bytes = (b);
744
+
745
+ function fit(x) {
746
+ if (buffer.length - b.i < x) {
747
+ const prev = buffer
748
+ , length = prev.length
749
+
750
+ buffer = Buffer.allocUnsafe(length + (length >> 1) + x)
751
+ prev.copy(buffer)
752
+ }
753
+ }
754
+
755
+ function bytes_reset() {
756
+ b.i = 0
757
+ return b
758
+ }
759
+
760
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/src/connection.js
761
+
762
+
763
+
764
+
765
+
766
+
767
+
768
+
769
+
770
+
771
+
772
+
773
+
774
+ /* harmony default export */ const src_connection = (Connection);
775
+
776
+ let uid = 1
777
+
778
+ const Sync = bytes().S().end()
779
+ , Flush = bytes().H().end()
780
+ , SSLRequest = bytes().i32(8).i32(80877103).end(8)
781
+ , ExecuteUnnamed = Buffer.concat([bytes().E().str(bytes.N).i32(0).end(), Sync])
782
+ , DescribeUnnamed = bytes().D().str('S').str(bytes.N).end()
783
+ , noop = () => { /* noop */ }
784
+
785
+ const retryRoutines = new Set([
786
+ 'FetchPreparedStatement',
787
+ 'RevalidateCachedQuery',
788
+ 'transformAssignedExpr'
789
+ ])
790
+
791
+ const errorFields = {
792
+ 83 : 'severity_local', // S
793
+ 86 : 'severity', // V
794
+ 67 : 'code', // C
795
+ 77 : 'message', // M
796
+ 68 : 'detail', // D
797
+ 72 : 'hint', // H
798
+ 80 : 'position', // P
799
+ 112 : 'internal_position', // p
800
+ 113 : 'internal_query', // q
801
+ 87 : 'where', // W
802
+ 115 : 'schema_name', // s
803
+ 116 : 'table_name', // t
804
+ 99 : 'column_name', // c
805
+ 100 : 'data type_name', // d
806
+ 110 : 'constraint_name', // n
807
+ 70 : 'file', // F
808
+ 76 : 'line', // L
809
+ 82 : 'routine' // R
810
+ }
811
+
812
+ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose = noop } = {}) {
813
+ const {
814
+ sslnegotiation,
815
+ ssl,
816
+ max,
817
+ user,
818
+ host,
819
+ port,
820
+ database,
821
+ parsers,
822
+ transform,
823
+ onnotice,
824
+ onnotify,
825
+ onparameter,
826
+ max_pipeline,
827
+ keep_alive,
828
+ backoff,
829
+ target_session_attrs
830
+ } = options
831
+
832
+ const sent = src_queue()
833
+ , id = uid++
834
+ , backend = { pid: null, secret: null }
835
+ , idleTimer = timer(end, options.idle_timeout)
836
+ , lifeTimer = timer(end, options.max_lifetime)
837
+ , connectTimer = timer(connectTimedOut, options.connect_timeout)
838
+
839
+ let socket = null
840
+ , cancelMessage
841
+ , errorResponse = null
842
+ , result = new Result()
843
+ , incoming = Buffer.alloc(0)
844
+ , needsTypes = options.fetch_types
845
+ , backendParameters = {}
846
+ , statements = {}
847
+ , statementId = Math.random().toString(36).slice(2)
848
+ , statementCount = 1
849
+ , closedTime = 0
850
+ , remaining = 0
851
+ , hostIndex = 0
852
+ , retries = 0
853
+ , length = 0
854
+ , delay = 0
855
+ , rows = 0
856
+ , serverSignature = null
857
+ , nextWriteTimer = null
858
+ , terminated = false
859
+ , incomings = null
860
+ , results = null
861
+ , initial = null
862
+ , ending = null
863
+ , stream = null
864
+ , chunk = null
865
+ , ended = null
866
+ , nonce = null
867
+ , query = null
868
+ , final = null
869
+
870
+ const connection = {
871
+ queue: queues.closed,
872
+ idleTimer,
873
+ connect(query) {
874
+ initial = query
875
+ reconnect()
876
+ },
877
+ terminate,
878
+ execute,
879
+ cancel,
880
+ end,
881
+ count: 0,
882
+ id
883
+ }
884
+
885
+ queues.closed && queues.closed.push(connection)
886
+
887
+ return connection
888
+
889
+ async function createSocket() {
890
+ let x
891
+ try {
892
+ x = options.socket
893
+ ? (await Promise.resolve(options.socket(options)))
894
+ : new external_net_.Socket()
895
+ } catch (e) {
896
+ error(e)
897
+ return
898
+ }
899
+ x.on('error', error)
900
+ x.on('close', closed)
901
+ x.on('drain', drain)
902
+ return x
903
+ }
904
+
905
+ async function cancel({ pid, secret }, resolve, reject) {
906
+ try {
907
+ cancelMessage = bytes().i32(16).i32(80877102).i32(pid).i32(secret).end(16)
908
+ await connect()
909
+ socket.once('error', reject)
910
+ socket.once('close', resolve)
911
+ } catch (error) {
912
+ reject(error)
913
+ }
914
+ }
915
+
916
+ function execute(q) {
917
+ if (terminated)
918
+ return queryError(q, Errors.connection('CONNECTION_DESTROYED', options))
919
+
920
+ if (stream)
921
+ return queryError(q, Errors.generic('COPY_IN_PROGRESS', 'You cannot execute queries during copy'))
922
+
923
+ if (q.cancelled)
924
+ return
925
+
926
+ try {
927
+ q.state = backend
928
+ query
929
+ ? sent.push(q)
930
+ : (query = q, query.active = true)
931
+
932
+ build(q)
933
+ return write(toBuffer(q))
934
+ && !q.describeFirst
935
+ && !q.cursorFn
936
+ && sent.length < max_pipeline
937
+ && (!q.options.onexecute || q.options.onexecute(connection))
938
+ } catch (error) {
939
+ sent.length === 0 && write(Sync)
940
+ errored(error)
941
+ return true
942
+ }
943
+ }
944
+
945
+ function toBuffer(q) {
946
+ if (q.parameters.length >= 65534)
947
+ throw Errors.generic('MAX_PARAMETERS_EXCEEDED', 'Max number of parameters (65534) exceeded')
948
+
949
+ return q.options.simple
950
+ ? bytes().Q().str(q.statement.string + bytes.N).end()
951
+ : q.describeFirst
952
+ ? Buffer.concat([describe(q), Flush])
953
+ : q.prepare
954
+ ? q.prepared
955
+ ? prepared(q)
956
+ : Buffer.concat([describe(q), prepared(q)])
957
+ : unnamed(q)
958
+ }
959
+
960
+ function describe(q) {
961
+ return Buffer.concat([
962
+ Parse(q.statement.string, q.parameters, q.statement.types, q.statement.name),
963
+ Describe('S', q.statement.name)
964
+ ])
965
+ }
966
+
967
+ function prepared(q) {
968
+ return Buffer.concat([
969
+ Bind(q.parameters, q.statement.types, q.statement.name, q.cursorName),
970
+ q.cursorFn
971
+ ? Execute('', q.cursorRows)
972
+ : ExecuteUnnamed
973
+ ])
974
+ }
975
+
976
+ function unnamed(q) {
977
+ return Buffer.concat([
978
+ Parse(q.statement.string, q.parameters, q.statement.types),
979
+ DescribeUnnamed,
980
+ prepared(q)
981
+ ])
982
+ }
983
+
984
+ function build(q) {
985
+ const parameters = []
986
+ , types = []
987
+
988
+ const string = stringify(q, q.strings[0], q.args[0], parameters, types, options)
989
+
990
+ !q.tagged && q.args.forEach(x => handleValue(x, parameters, types, options))
991
+
992
+ q.prepare = options.prepare && ('prepare' in q.options ? q.options.prepare : true)
993
+ q.string = string
994
+ q.signature = q.prepare && types + string
995
+ q.onlyDescribe && (delete statements[q.signature])
996
+ q.parameters = q.parameters || parameters
997
+ q.prepared = q.prepare && q.signature in statements
998
+ q.describeFirst = q.onlyDescribe || (parameters.length && !q.prepared)
999
+ q.statement = q.prepared
1000
+ ? statements[q.signature]
1001
+ : { string, types, name: q.prepare ? statementId + statementCount++ : '' }
1002
+
1003
+ typeof options.debug === 'function' && options.debug(id, string, parameters, types)
1004
+ }
1005
+
1006
+ function write(x, fn) {
1007
+ chunk = chunk ? Buffer.concat([chunk, x]) : Buffer.from(x)
1008
+ if (fn || chunk.length >= 1024)
1009
+ return nextWrite(fn)
1010
+ nextWriteTimer === null && (nextWriteTimer = setImmediate(nextWrite))
1011
+ return true
1012
+ }
1013
+
1014
+ function nextWrite(fn) {
1015
+ const x = socket.write(chunk, fn)
1016
+ nextWriteTimer !== null && clearImmediate(nextWriteTimer)
1017
+ chunk = nextWriteTimer = null
1018
+ return x
1019
+ }
1020
+
1021
+ function connectTimedOut() {
1022
+ errored(Errors.connection('CONNECT_TIMEOUT', options, socket))
1023
+ socket.destroy()
1024
+ }
1025
+
1026
+ async function secure() {
1027
+ if (sslnegotiation !== 'direct') {
1028
+ write(SSLRequest)
1029
+ const canSSL = await new Promise(r => socket.once('data', x => r(x[0] === 83))) // S
1030
+
1031
+ if (!canSSL && ssl === 'prefer')
1032
+ return connected()
1033
+ }
1034
+
1035
+ const options = {
1036
+ socket,
1037
+ servername: external_net_.isIP(socket.host) ? undefined : socket.host
1038
+ }
1039
+
1040
+ if (sslnegotiation === 'direct')
1041
+ options.ALPNProtocols = ['postgresql']
1042
+
1043
+ if (ssl === 'require' || ssl === 'allow' || ssl === 'prefer')
1044
+ options.rejectUnauthorized = false
1045
+ else if (typeof ssl === 'object')
1046
+ Object.assign(options, ssl)
1047
+
1048
+ socket.removeAllListeners()
1049
+ socket = external_tls_.connect(options)
1050
+ socket.on('secureConnect', connected)
1051
+ socket.on('error', error)
1052
+ socket.on('close', closed)
1053
+ socket.on('drain', drain)
1054
+ }
1055
+
1056
+ /* c8 ignore next 3 */
1057
+ function drain() {
1058
+ !query && onopen(connection)
1059
+ }
1060
+
1061
+ function data(x) {
1062
+ if (incomings) {
1063
+ incomings.push(x)
1064
+ remaining -= x.length
1065
+ if (remaining > 0)
1066
+ return
1067
+ }
1068
+
1069
+ incoming = incomings
1070
+ ? Buffer.concat(incomings, length - remaining)
1071
+ : incoming.length === 0
1072
+ ? x
1073
+ : Buffer.concat([incoming, x], incoming.length + x.length)
1074
+
1075
+ while (incoming.length > 4) {
1076
+ length = incoming.readUInt32BE(1)
1077
+ if (length >= incoming.length) {
1078
+ remaining = length - incoming.length
1079
+ incomings = [incoming]
1080
+ break
1081
+ }
1082
+
1083
+ try {
1084
+ handle(incoming.subarray(0, length + 1))
1085
+ } catch (e) {
1086
+ query && (query.cursorFn || query.describeFirst) && write(Sync)
1087
+ errored(e)
1088
+ }
1089
+ incoming = incoming.subarray(length + 1)
1090
+ remaining = 0
1091
+ incomings = null
1092
+ }
1093
+ }
1094
+
1095
+ async function connect() {
1096
+ terminated = false
1097
+ backendParameters = {}
1098
+ socket || (socket = await createSocket())
1099
+
1100
+ if (!socket)
1101
+ return
1102
+
1103
+ connectTimer.start()
1104
+
1105
+ if (options.socket)
1106
+ return ssl ? secure() : connected()
1107
+
1108
+ socket.on('connect', ssl ? secure : connected)
1109
+
1110
+ if (options.path)
1111
+ return socket.connect(options.path)
1112
+
1113
+ socket.ssl = ssl
1114
+ socket.connect(port[hostIndex], host[hostIndex])
1115
+ socket.host = host[hostIndex]
1116
+ socket.port = port[hostIndex]
1117
+
1118
+ hostIndex = (hostIndex + 1) % port.length
1119
+ }
1120
+
1121
+ function reconnect() {
1122
+ setTimeout(connect, closedTime ? Math.max(0, closedTime + delay - external_perf_hooks_.performance.now()) : 0)
1123
+ }
1124
+
1125
+ function connected() {
1126
+ try {
1127
+ statements = {}
1128
+ needsTypes = options.fetch_types
1129
+ statementId = Math.random().toString(36).slice(2)
1130
+ statementCount = 1
1131
+ lifeTimer.start()
1132
+ socket.on('data', data)
1133
+ keep_alive && socket.setKeepAlive && socket.setKeepAlive(true, 1000 * keep_alive)
1134
+ const s = StartupMessage()
1135
+ write(s)
1136
+ } catch (err) {
1137
+ error(err)
1138
+ }
1139
+ }
1140
+
1141
+ function error(err) {
1142
+ if (connection.queue === queues.connecting && options.host[retries + 1])
1143
+ return
1144
+
1145
+ errored(err)
1146
+ while (sent.length)
1147
+ queryError(sent.shift(), err)
1148
+ }
1149
+
1150
+ function errored(err) {
1151
+ stream && (stream.destroy(err), stream = null)
1152
+ query && queryError(query, err)
1153
+ initial && (queryError(initial, err), initial = null)
1154
+ }
1155
+
1156
+ function queryError(query, err) {
1157
+ if (query.reserve)
1158
+ return query.reject(err)
1159
+
1160
+ if (!err || typeof err !== 'object')
1161
+ err = new Error(err)
1162
+
1163
+ 'query' in err || 'parameters' in err || Object.defineProperties(err, {
1164
+ stack: { value: err.stack + query.origin.replace(/.*\n/, '\n'), enumerable: options.debug },
1165
+ query: { value: query.string, enumerable: options.debug },
1166
+ parameters: { value: query.parameters, enumerable: options.debug },
1167
+ args: { value: query.args, enumerable: options.debug },
1168
+ types: { value: query.statement && query.statement.types, enumerable: options.debug }
1169
+ })
1170
+ query.reject(err)
1171
+ }
1172
+
1173
+ function end() {
1174
+ return ending || (
1175
+ !connection.reserved && onend(connection),
1176
+ !connection.reserved && !initial && !query && sent.length === 0
1177
+ ? (terminate(), new Promise(r => socket && socket.readyState !== 'closed' ? socket.once('close', r) : r()))
1178
+ : ending = new Promise(r => ended = r)
1179
+ )
1180
+ }
1181
+
1182
+ function terminate() {
1183
+ terminated = true
1184
+ if (stream || query || initial || sent.length)
1185
+ error(Errors.connection('CONNECTION_DESTROYED', options))
1186
+
1187
+ clearImmediate(nextWriteTimer)
1188
+ if (socket) {
1189
+ socket.removeListener('data', data)
1190
+ socket.removeListener('connect', connected)
1191
+ socket.readyState === 'open' && socket.end(bytes().X().end())
1192
+ }
1193
+ ended && (ended(), ending = ended = null)
1194
+ }
1195
+
1196
+ async function closed(hadError) {
1197
+ incoming = Buffer.alloc(0)
1198
+ remaining = 0
1199
+ incomings = null
1200
+ clearImmediate(nextWriteTimer)
1201
+ socket.removeListener('data', data)
1202
+ socket.removeListener('connect', connected)
1203
+ idleTimer.cancel()
1204
+ lifeTimer.cancel()
1205
+ connectTimer.cancel()
1206
+
1207
+ socket.removeAllListeners()
1208
+ socket = null
1209
+
1210
+ if (initial)
1211
+ return reconnect()
1212
+
1213
+ !hadError && (query || sent.length) && error(Errors.connection('CONNECTION_CLOSED', options, socket))
1214
+ closedTime = external_perf_hooks_.performance.now()
1215
+ hadError && options.shared.retries++
1216
+ delay = (typeof backoff === 'function' ? backoff(options.shared.retries) : backoff) * 1000
1217
+ onclose(connection, Errors.connection('CONNECTION_CLOSED', options, socket))
1218
+ }
1219
+
1220
+ /* Handlers */
1221
+ function handle(xs, x = xs[0]) {
1222
+ (
1223
+ x === 68 ? DataRow : // D
1224
+ x === 100 ? CopyData : // d
1225
+ x === 65 ? NotificationResponse : // A
1226
+ x === 83 ? ParameterStatus : // S
1227
+ x === 90 ? ReadyForQuery : // Z
1228
+ x === 67 ? CommandComplete : // C
1229
+ x === 50 ? BindComplete : // 2
1230
+ x === 49 ? ParseComplete : // 1
1231
+ x === 116 ? ParameterDescription : // t
1232
+ x === 84 ? RowDescription : // T
1233
+ x === 82 ? Authentication : // R
1234
+ x === 110 ? NoData : // n
1235
+ x === 75 ? BackendKeyData : // K
1236
+ x === 69 ? ErrorResponse : // E
1237
+ x === 115 ? PortalSuspended : // s
1238
+ x === 51 ? CloseComplete : // 3
1239
+ x === 71 ? CopyInResponse : // G
1240
+ x === 78 ? NoticeResponse : // N
1241
+ x === 72 ? CopyOutResponse : // H
1242
+ x === 99 ? CopyDone : // c
1243
+ x === 73 ? EmptyQueryResponse : // I
1244
+ x === 86 ? FunctionCallResponse : // V
1245
+ x === 118 ? NegotiateProtocolVersion : // v
1246
+ x === 87 ? CopyBothResponse : // W
1247
+ /* c8 ignore next */
1248
+ UnknownMessage
1249
+ )(xs)
1250
+ }
1251
+
1252
+ function DataRow(x) {
1253
+ let index = 7
1254
+ let length
1255
+ let column
1256
+ let value
1257
+
1258
+ const row = query.isRaw ? new Array(query.statement.columns.length) : {}
1259
+ for (let i = 0; i < query.statement.columns.length; i++) {
1260
+ column = query.statement.columns[i]
1261
+ length = x.readInt32BE(index)
1262
+ index += 4
1263
+
1264
+ value = length === -1
1265
+ ? null
1266
+ : query.isRaw === true
1267
+ ? x.subarray(index, index += length)
1268
+ : column.parser === undefined
1269
+ ? x.toString('utf8', index, index += length)
1270
+ : column.parser.array === true
1271
+ ? column.parser(x.toString('utf8', index + 1, index += length))
1272
+ : column.parser(x.toString('utf8', index, index += length))
1273
+
1274
+ query.isRaw
1275
+ ? (row[i] = query.isRaw === true
1276
+ ? value
1277
+ : transform.value.from ? transform.value.from(value, column) : value)
1278
+ : (row[column.name] = transform.value.from ? transform.value.from(value, column) : value)
1279
+ }
1280
+
1281
+ query.forEachFn
1282
+ ? query.forEachFn(transform.row.from ? transform.row.from(row) : row, result)
1283
+ : (result[rows++] = transform.row.from ? transform.row.from(row) : row)
1284
+ }
1285
+
1286
+ function ParameterStatus(x) {
1287
+ const [k, v] = x.toString('utf8', 5, x.length - 1).split(bytes.N)
1288
+ backendParameters[k] = v
1289
+ if (options.parameters[k] !== v) {
1290
+ options.parameters[k] = v
1291
+ onparameter && onparameter(k, v)
1292
+ }
1293
+ }
1294
+
1295
+ function ReadyForQuery(x) {
1296
+ if (query) {
1297
+ if (errorResponse) {
1298
+ query.retried
1299
+ ? errored(query.retried)
1300
+ : query.prepared && retryRoutines.has(errorResponse.routine)
1301
+ ? retry(query, errorResponse)
1302
+ : errored(errorResponse)
1303
+ } else {
1304
+ query.resolve(results || result)
1305
+ }
1306
+ } else if (errorResponse) {
1307
+ errored(errorResponse)
1308
+ }
1309
+
1310
+ query = results = errorResponse = null
1311
+ result = new Result()
1312
+ connectTimer.cancel()
1313
+
1314
+ if (initial) {
1315
+ if (target_session_attrs) {
1316
+ if (!backendParameters.in_hot_standby || !backendParameters.default_transaction_read_only)
1317
+ return fetchState()
1318
+ else if (tryNext(target_session_attrs, backendParameters))
1319
+ return terminate()
1320
+ }
1321
+
1322
+ if (needsTypes) {
1323
+ initial.reserve && (initial = null)
1324
+ return fetchArrayTypes()
1325
+ }
1326
+
1327
+ initial && !initial.reserve && execute(initial)
1328
+ options.shared.retries = retries = 0
1329
+ initial = null
1330
+ return
1331
+ }
1332
+
1333
+ while (sent.length && (query = sent.shift()) && (query.active = true, query.cancelled))
1334
+ Connection(options).cancel(query.state, query.cancelled.resolve, query.cancelled.reject)
1335
+
1336
+ if (query)
1337
+ return // Consider opening if able and sent.length < 50
1338
+
1339
+ connection.reserved
1340
+ ? !connection.reserved.release && x[5] === 73 // I
1341
+ ? ending
1342
+ ? terminate()
1343
+ : (connection.reserved = null, onopen(connection))
1344
+ : connection.reserved()
1345
+ : ending
1346
+ ? terminate()
1347
+ : onopen(connection)
1348
+ }
1349
+
1350
+ function CommandComplete(x) {
1351
+ rows = 0
1352
+
1353
+ for (let i = x.length - 1; i > 0; i--) {
1354
+ if (x[i] === 32 && x[i + 1] < 58 && result.count === null)
1355
+ result.count = +x.toString('utf8', i + 1, x.length - 1)
1356
+ if (x[i - 1] >= 65) {
1357
+ result.command = x.toString('utf8', 5, i)
1358
+ result.state = backend
1359
+ break
1360
+ }
1361
+ }
1362
+
1363
+ final && (final(), final = null)
1364
+
1365
+ if (result.command === 'BEGIN' && max !== 1 && !connection.reserved)
1366
+ return errored(Errors.generic('UNSAFE_TRANSACTION', 'Only use sql.begin, sql.reserved or max: 1'))
1367
+
1368
+ if (query.options.simple)
1369
+ return BindComplete()
1370
+
1371
+ if (query.cursorFn) {
1372
+ result.count && query.cursorFn(result)
1373
+ write(Sync)
1374
+ }
1375
+ }
1376
+
1377
+ function ParseComplete() {
1378
+ query.parsing = false
1379
+ }
1380
+
1381
+ function BindComplete() {
1382
+ !result.statement && (result.statement = query.statement)
1383
+ result.columns = query.statement.columns
1384
+ }
1385
+
1386
+ function ParameterDescription(x) {
1387
+ const length = x.readUInt16BE(5)
1388
+
1389
+ for (let i = 0; i < length; ++i)
1390
+ !query.statement.types[i] && (query.statement.types[i] = x.readUInt32BE(7 + i * 4))
1391
+
1392
+ query.prepare && (statements[query.signature] = query.statement)
1393
+ query.describeFirst && !query.onlyDescribe && (write(prepared(query)), query.describeFirst = false)
1394
+ }
1395
+
1396
+ function RowDescription(x) {
1397
+ if (result.command) {
1398
+ results = results || [result]
1399
+ results.push(result = new Result())
1400
+ result.count = null
1401
+ query.statement.columns = null
1402
+ }
1403
+
1404
+ const length = x.readUInt16BE(5)
1405
+ let index = 7
1406
+ let start
1407
+
1408
+ query.statement.columns = Array(length)
1409
+
1410
+ for (let i = 0; i < length; ++i) {
1411
+ start = index
1412
+ while (x[index++] !== 0);
1413
+ const table = x.readUInt32BE(index)
1414
+ const number = x.readUInt16BE(index + 4)
1415
+ const type = x.readUInt32BE(index + 6)
1416
+ query.statement.columns[i] = {
1417
+ name: transform.column.from
1418
+ ? transform.column.from(x.toString('utf8', start, index - 1))
1419
+ : x.toString('utf8', start, index - 1),
1420
+ parser: parsers[type],
1421
+ table,
1422
+ number,
1423
+ type
1424
+ }
1425
+ index += 18
1426
+ }
1427
+
1428
+ result.statement = query.statement
1429
+ if (query.onlyDescribe)
1430
+ return (query.resolve(query.statement), write(Sync))
1431
+ }
1432
+
1433
+ async function Authentication(x, type = x.readUInt32BE(5)) {
1434
+ (
1435
+ type === 3 ? AuthenticationCleartextPassword :
1436
+ type === 5 ? AuthenticationMD5Password :
1437
+ type === 10 ? SASL :
1438
+ type === 11 ? SASLContinue :
1439
+ type === 12 ? SASLFinal :
1440
+ type !== 0 ? UnknownAuth :
1441
+ noop
1442
+ )(x, type)
1443
+ }
1444
+
1445
+ /* c8 ignore next 5 */
1446
+ async function AuthenticationCleartextPassword() {
1447
+ const payload = await Pass()
1448
+ write(
1449
+ bytes().p().str(payload).z(1).end()
1450
+ )
1451
+ }
1452
+
1453
+ async function AuthenticationMD5Password(x) {
1454
+ const payload = 'md5' + (
1455
+ await md5(
1456
+ Buffer.concat([
1457
+ Buffer.from(await md5((await Pass()) + user)),
1458
+ x.subarray(9)
1459
+ ])
1460
+ )
1461
+ )
1462
+ write(
1463
+ bytes().p().str(payload).z(1).end()
1464
+ )
1465
+ }
1466
+
1467
+ async function SASL() {
1468
+ nonce = (await external_crypto_.randomBytes(18)).toString('base64')
1469
+ bytes().p().str('SCRAM-SHA-256' + bytes.N)
1470
+ const i = bytes.i
1471
+ write(bytes.inc(4).str('n,,n=*,r=' + nonce).i32(bytes.i - i - 4, i).end())
1472
+ }
1473
+
1474
+ async function SASLContinue(x) {
1475
+ const res = x.toString('utf8', 9).split(',').reduce((acc, x) => (acc[x[0]] = x.slice(2), acc), {})
1476
+
1477
+ const saltedPassword = await external_crypto_.pbkdf2Sync(
1478
+ await Pass(),
1479
+ Buffer.from(res.s, 'base64'),
1480
+ parseInt(res.i), 32,
1481
+ 'sha256'
1482
+ )
1483
+
1484
+ const clientKey = await hmac(saltedPassword, 'Client Key')
1485
+
1486
+ const auth = 'n=*,r=' + nonce + ','
1487
+ + 'r=' + res.r + ',s=' + res.s + ',i=' + res.i
1488
+ + ',c=biws,r=' + res.r
1489
+
1490
+ serverSignature = (await hmac(await hmac(saltedPassword, 'Server Key'), auth)).toString('base64')
1491
+
1492
+ const payload = 'c=biws,r=' + res.r + ',p=' + xor(
1493
+ clientKey, Buffer.from(await hmac(await sha256(clientKey), auth))
1494
+ ).toString('base64')
1495
+
1496
+ write(
1497
+ bytes().p().str(payload).end()
1498
+ )
1499
+ }
1500
+
1501
+ function SASLFinal(x) {
1502
+ if (x.toString('utf8', 9).split(bytes.N, 1)[0].slice(2) === serverSignature)
1503
+ return
1504
+ /* c8 ignore next 5 */
1505
+ errored(Errors.generic('SASL_SIGNATURE_MISMATCH', 'The server did not return the correct signature'))
1506
+ socket.destroy()
1507
+ }
1508
+
1509
+ function Pass() {
1510
+ return Promise.resolve(typeof options.pass === 'function'
1511
+ ? options.pass()
1512
+ : options.pass
1513
+ )
1514
+ }
1515
+
1516
+ function NoData() {
1517
+ result.statement = query.statement
1518
+ result.statement.columns = []
1519
+ if (query.onlyDescribe)
1520
+ return (query.resolve(query.statement), write(Sync))
1521
+ }
1522
+
1523
+ function BackendKeyData(x) {
1524
+ backend.pid = x.readUInt32BE(5)
1525
+ backend.secret = x.readUInt32BE(9)
1526
+ }
1527
+
1528
+ async function fetchArrayTypes() {
1529
+ needsTypes = false
1530
+ const types = await new Query([`
1531
+ select b.oid, b.typarray
1532
+ from pg_catalog.pg_type a
1533
+ left join pg_catalog.pg_type b on b.oid = a.typelem
1534
+ where a.typcategory = 'A'
1535
+ group by b.oid, b.typarray
1536
+ order by b.oid
1537
+ `], [], execute)
1538
+ types.forEach(({ oid, typarray }) => addArrayType(oid, typarray))
1539
+ }
1540
+
1541
+ function addArrayType(oid, typarray) {
1542
+ if (!!options.parsers[typarray] && !!options.serializers[typarray]) return
1543
+ const parser = options.parsers[oid]
1544
+ options.shared.typeArrayMap[oid] = typarray
1545
+ options.parsers[typarray] = (xs) => arrayParser(xs, parser, typarray)
1546
+ options.parsers[typarray].array = true
1547
+ options.serializers[typarray] = (xs) => arraySerializer(xs, options.serializers[oid], options, typarray)
1548
+ }
1549
+
1550
+ function tryNext(x, xs) {
1551
+ return (
1552
+ (x === 'read-write' && xs.default_transaction_read_only === 'on') ||
1553
+ (x === 'read-only' && xs.default_transaction_read_only === 'off') ||
1554
+ (x === 'primary' && xs.in_hot_standby === 'on') ||
1555
+ (x === 'standby' && xs.in_hot_standby === 'off') ||
1556
+ (x === 'prefer-standby' && xs.in_hot_standby === 'off' && options.host[retries])
1557
+ )
1558
+ }
1559
+
1560
+ function fetchState() {
1561
+ const query = new Query([`
1562
+ show transaction_read_only;
1563
+ select pg_catalog.pg_is_in_recovery()
1564
+ `], [], execute, null, { simple: true })
1565
+ query.resolve = ([[a], [b]]) => {
1566
+ backendParameters.default_transaction_read_only = a.transaction_read_only
1567
+ backendParameters.in_hot_standby = b.pg_is_in_recovery ? 'on' : 'off'
1568
+ }
1569
+ query.execute()
1570
+ }
1571
+
1572
+ function ErrorResponse(x) {
1573
+ if (query) {
1574
+ (query.cursorFn || query.describeFirst) && write(Sync)
1575
+ errorResponse = Errors.postgres(parseError(x))
1576
+ } else {
1577
+ errored(Errors.postgres(parseError(x)))
1578
+ }
1579
+ }
1580
+
1581
+ function retry(q, error) {
1582
+ delete statements[q.signature]
1583
+ q.retried = error
1584
+ execute(q)
1585
+ }
1586
+
1587
+ function NotificationResponse(x) {
1588
+ if (!onnotify)
1589
+ return
1590
+
1591
+ let index = 9
1592
+ while (x[index++] !== 0);
1593
+ onnotify(
1594
+ x.toString('utf8', 9, index - 1),
1595
+ x.toString('utf8', index, x.length - 1)
1596
+ )
1597
+ }
1598
+
1599
+ async function PortalSuspended() {
1600
+ try {
1601
+ const x = await Promise.resolve(query.cursorFn(result))
1602
+ rows = 0
1603
+ x === CLOSE
1604
+ ? write(Close(query.portal))
1605
+ : (result = new Result(), write(Execute('', query.cursorRows)))
1606
+ } catch (err) {
1607
+ write(Sync)
1608
+ query.reject(err)
1609
+ }
1610
+ }
1611
+
1612
+ function CloseComplete() {
1613
+ result.count && query.cursorFn(result)
1614
+ query.resolve(result)
1615
+ }
1616
+
1617
+ function CopyInResponse() {
1618
+ stream = new external_stream_.Writable({
1619
+ autoDestroy: true,
1620
+ write(chunk, encoding, callback) {
1621
+ socket.write(bytes().d().raw(chunk).end(), callback)
1622
+ },
1623
+ destroy(error, callback) {
1624
+ callback(error)
1625
+ socket.write(bytes().f().str(error + bytes.N).end())
1626
+ stream = null
1627
+ },
1628
+ final(callback) {
1629
+ socket.write(bytes().c().end())
1630
+ final = callback
1631
+ stream = null
1632
+ }
1633
+ })
1634
+ query.resolve(stream)
1635
+ }
1636
+
1637
+ function CopyOutResponse() {
1638
+ stream = new external_stream_.Readable({
1639
+ read() { socket.resume() }
1640
+ })
1641
+ query.resolve(stream)
1642
+ }
1643
+
1644
+ /* c8 ignore next 3 */
1645
+ function CopyBothResponse() {
1646
+ stream = new external_stream_.Duplex({
1647
+ autoDestroy: true,
1648
+ read() { socket.resume() },
1649
+ /* c8 ignore next 11 */
1650
+ write(chunk, encoding, callback) {
1651
+ socket.write(bytes().d().raw(chunk).end(), callback)
1652
+ },
1653
+ destroy(error, callback) {
1654
+ callback(error)
1655
+ socket.write(bytes().f().str(error + bytes.N).end())
1656
+ stream = null
1657
+ },
1658
+ final(callback) {
1659
+ socket.write(bytes().c().end())
1660
+ final = callback
1661
+ }
1662
+ })
1663
+ query.resolve(stream)
1664
+ }
1665
+
1666
+ function CopyData(x) {
1667
+ stream && (stream.push(x.subarray(5)) || socket.pause())
1668
+ }
1669
+
1670
+ function CopyDone() {
1671
+ stream && stream.push(null)
1672
+ stream = null
1673
+ }
1674
+
1675
+ function NoticeResponse(x) {
1676
+ onnotice
1677
+ ? onnotice(parseError(x))
1678
+ : console.log(parseError(x)) // eslint-disable-line
1679
+
1680
+ }
1681
+
1682
+ /* c8 ignore next 3 */
1683
+ function EmptyQueryResponse() {
1684
+ /* noop */
1685
+ }
1686
+
1687
+ /* c8 ignore next 3 */
1688
+ function FunctionCallResponse() {
1689
+ errored(Errors.notSupported('FunctionCallResponse'))
1690
+ }
1691
+
1692
+ /* c8 ignore next 3 */
1693
+ function NegotiateProtocolVersion() {
1694
+ errored(Errors.notSupported('NegotiateProtocolVersion'))
1695
+ }
1696
+
1697
+ /* c8 ignore next 3 */
1698
+ function UnknownMessage(x) {
1699
+ console.error('Postgres.js : Unknown Message:', x[0]) // eslint-disable-line
1700
+ }
1701
+
1702
+ /* c8 ignore next 3 */
1703
+ function UnknownAuth(x, type) {
1704
+ console.error('Postgres.js : Unknown Auth:', type) // eslint-disable-line
1705
+ }
1706
+
1707
+ /* Messages */
1708
+ function Bind(parameters, types, statement = '', portal = '') {
1709
+ let prev
1710
+ , type
1711
+
1712
+ bytes().B().str(portal + bytes.N).str(statement + bytes.N).i16(0).i16(parameters.length)
1713
+
1714
+ parameters.forEach((x, i) => {
1715
+ if (x === null)
1716
+ return bytes.i32(0xFFFFFFFF)
1717
+
1718
+ type = types[i]
1719
+ parameters[i] = x = type in options.serializers
1720
+ ? options.serializers[type](x)
1721
+ : '' + x
1722
+
1723
+ prev = bytes.i
1724
+ bytes.inc(4).str(x).i32(bytes.i - prev - 4, prev)
1725
+ })
1726
+
1727
+ bytes.i16(0)
1728
+
1729
+ return bytes.end()
1730
+ }
1731
+
1732
+ function Parse(str, parameters, types, name = '') {
1733
+ bytes().P().str(name + bytes.N).str(str + bytes.N).i16(parameters.length)
1734
+ parameters.forEach((x, i) => bytes.i32(types[i] || 0))
1735
+ return bytes.end()
1736
+ }
1737
+
1738
+ function Describe(x, name = '') {
1739
+ return bytes().D().str(x).str(name + bytes.N).end()
1740
+ }
1741
+
1742
+ function Execute(portal = '', rows = 0) {
1743
+ return Buffer.concat([
1744
+ bytes().E().str(portal + bytes.N).i32(rows).end(),
1745
+ Flush
1746
+ ])
1747
+ }
1748
+
1749
+ function Close(portal = '') {
1750
+ return Buffer.concat([
1751
+ bytes().C().str('P').str(portal + bytes.N).end(),
1752
+ bytes().S().end()
1753
+ ])
1754
+ }
1755
+
1756
+ function StartupMessage() {
1757
+ return cancelMessage || bytes().inc(4).i16(3).z(2).str(
1758
+ Object.entries(Object.assign({
1759
+ user,
1760
+ database,
1761
+ client_encoding: 'UTF8'
1762
+ },
1763
+ options.connection
1764
+ )).filter(([, v]) => v).map(([k, v]) => k + bytes.N + v).join(bytes.N)
1765
+ ).z(2).end(0)
1766
+ }
1767
+
1768
+ }
1769
+
1770
+ function parseError(x) {
1771
+ const error = {}
1772
+ let start = 5
1773
+ for (let i = 5; i < x.length - 1; i++) {
1774
+ if (x[i] === 0) {
1775
+ error[errorFields[x[start]]] = x.toString('utf8', start + 1, i)
1776
+ start = i + 1
1777
+ }
1778
+ }
1779
+ return error
1780
+ }
1781
+
1782
+ function md5(x) {
1783
+ return external_crypto_.createHash('md5').update(x).digest('hex')
1784
+ }
1785
+
1786
+ function hmac(key, x) {
1787
+ return external_crypto_.createHmac('sha256', key).update(x).digest()
1788
+ }
1789
+
1790
+ function sha256(x) {
1791
+ return external_crypto_.createHash('sha256').update(x).digest()
1792
+ }
1793
+
1794
+ function xor(a, b) {
1795
+ const length = Math.max(a.length, b.length)
1796
+ const buffer = Buffer.allocUnsafe(length)
1797
+ for (let i = 0; i < length; i++)
1798
+ buffer[i] = a[i] ^ b[i]
1799
+ return buffer
1800
+ }
1801
+
1802
+ function timer(fn, seconds) {
1803
+ seconds = typeof seconds === 'function' ? seconds() : seconds
1804
+ if (!seconds)
1805
+ return { cancel: noop, start: noop }
1806
+
1807
+ let timer
1808
+ return {
1809
+ cancel() {
1810
+ timer && (clearTimeout(timer), timer = null)
1811
+ },
1812
+ start() {
1813
+ timer && clearTimeout(timer)
1814
+ timer = setTimeout(done, seconds * 1000, arguments)
1815
+ }
1816
+ }
1817
+
1818
+ function done(args) {
1819
+ fn.apply(null, args)
1820
+ timer = null
1821
+ }
1822
+ }
1823
+
1824
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/src/subscribe.js
1825
+ const subscribe_noop = () => { /* noop */ }
1826
+
1827
+ function Subscribe(postgres, options) {
1828
+ const subscribers = new Map()
1829
+ , slot = 'postgresjs_' + Math.random().toString(36).slice(2)
1830
+ , state = {}
1831
+
1832
+ let connection
1833
+ , stream
1834
+ , ended = false
1835
+
1836
+ const sql = subscribe.sql = postgres({
1837
+ ...options,
1838
+ transform: { column: {}, value: {}, row: {} },
1839
+ max: 1,
1840
+ fetch_types: false,
1841
+ idle_timeout: null,
1842
+ max_lifetime: null,
1843
+ connection: {
1844
+ ...options.connection,
1845
+ replication: 'database'
1846
+ },
1847
+ onclose: async function() {
1848
+ if (ended)
1849
+ return
1850
+ stream = null
1851
+ state.pid = state.secret = undefined
1852
+ connected(await init(sql, slot, options.publications))
1853
+ subscribers.forEach(event => event.forEach(({ onsubscribe }) => onsubscribe()))
1854
+ },
1855
+ no_subscribe: true
1856
+ })
1857
+
1858
+ const end = sql.end
1859
+ , close = sql.close
1860
+
1861
+ sql.end = async() => {
1862
+ ended = true
1863
+ stream && (await new Promise(r => (stream.once('close', r), stream.end())))
1864
+ return end()
1865
+ }
1866
+
1867
+ sql.close = async() => {
1868
+ stream && (await new Promise(r => (stream.once('close', r), stream.end())))
1869
+ return close()
1870
+ }
1871
+
1872
+ return subscribe
1873
+
1874
+ async function subscribe(event, fn, onsubscribe = subscribe_noop, onerror = subscribe_noop) {
1875
+ event = parseEvent(event)
1876
+
1877
+ if (!connection)
1878
+ connection = init(sql, slot, options.publications)
1879
+
1880
+ const subscriber = { fn, onsubscribe }
1881
+ const fns = subscribers.has(event)
1882
+ ? subscribers.get(event).add(subscriber)
1883
+ : subscribers.set(event, new Set([subscriber])).get(event)
1884
+
1885
+ const unsubscribe = () => {
1886
+ fns.delete(subscriber)
1887
+ fns.size === 0 && subscribers.delete(event)
1888
+ }
1889
+
1890
+ return connection.then(x => {
1891
+ connected(x)
1892
+ onsubscribe()
1893
+ stream && stream.on('error', onerror)
1894
+ return { unsubscribe, state, sql }
1895
+ })
1896
+ }
1897
+
1898
+ function connected(x) {
1899
+ stream = x.stream
1900
+ state.pid = x.state.pid
1901
+ state.secret = x.state.secret
1902
+ }
1903
+
1904
+ async function init(sql, slot, publications) {
1905
+ if (!publications)
1906
+ throw new Error('Missing publication names')
1907
+
1908
+ const xs = await sql.unsafe(
1909
+ `CREATE_REPLICATION_SLOT ${ slot } TEMPORARY LOGICAL pgoutput NOEXPORT_SNAPSHOT`
1910
+ )
1911
+
1912
+ const [x] = xs
1913
+
1914
+ const stream = await sql.unsafe(
1915
+ `START_REPLICATION SLOT ${ slot } LOGICAL ${
1916
+ x.consistent_point
1917
+ } (proto_version '1', publication_names '${ publications }')`
1918
+ ).writable()
1919
+
1920
+ const state = {
1921
+ lsn: Buffer.concat(x.consistent_point.split('/').map(x => Buffer.from(('00000000' + x).slice(-8), 'hex')))
1922
+ }
1923
+
1924
+ stream.on('data', data)
1925
+ stream.on('error', error)
1926
+ stream.on('close', sql.close)
1927
+
1928
+ return { stream, state: xs.state }
1929
+
1930
+ function error(e) {
1931
+ console.error('Unexpected error during logical streaming - reconnecting', e) // eslint-disable-line
1932
+ }
1933
+
1934
+ function data(x) {
1935
+ if (x[0] === 0x77) {
1936
+ parse(x.subarray(25), state, sql.options.parsers, handle, options.transform)
1937
+ } else if (x[0] === 0x6b && x[17]) {
1938
+ state.lsn = x.subarray(1, 9)
1939
+ pong()
1940
+ }
1941
+ }
1942
+
1943
+ function handle(a, b) {
1944
+ const path = b.relation.schema + '.' + b.relation.table
1945
+ call('*', a, b)
1946
+ call('*:' + path, a, b)
1947
+ b.relation.keys.length && call('*:' + path + '=' + b.relation.keys.map(x => a[x.name]), a, b)
1948
+ call(b.command, a, b)
1949
+ call(b.command + ':' + path, a, b)
1950
+ b.relation.keys.length && call(b.command + ':' + path + '=' + b.relation.keys.map(x => a[x.name]), a, b)
1951
+ }
1952
+
1953
+ function pong() {
1954
+ const x = Buffer.alloc(34)
1955
+ x[0] = 'r'.charCodeAt(0)
1956
+ x.fill(state.lsn, 1)
1957
+ x.writeBigInt64BE(BigInt(Date.now() - Date.UTC(2000, 0, 1)) * BigInt(1000), 25)
1958
+ stream.write(x)
1959
+ }
1960
+ }
1961
+
1962
+ function call(x, a, b) {
1963
+ subscribers.has(x) && subscribers.get(x).forEach(({ fn }) => fn(a, b, x))
1964
+ }
1965
+ }
1966
+
1967
+ function Time(x) {
1968
+ return new Date(Date.UTC(2000, 0, 1) + Number(x / BigInt(1000)))
1969
+ }
1970
+
1971
+ function parse(x, state, parsers, handle, transform) {
1972
+ const char = (acc, [k, v]) => (acc[k.charCodeAt(0)] = v, acc)
1973
+
1974
+ Object.entries({
1975
+ R: x => { // Relation
1976
+ let i = 1
1977
+ const r = state[x.readUInt32BE(i)] = {
1978
+ schema: x.toString('utf8', i += 4, i = x.indexOf(0, i)) || 'pg_catalog',
1979
+ table: x.toString('utf8', i + 1, i = x.indexOf(0, i + 1)),
1980
+ columns: Array(x.readUInt16BE(i += 2)),
1981
+ keys: []
1982
+ }
1983
+ i += 2
1984
+
1985
+ let columnIndex = 0
1986
+ , column
1987
+
1988
+ while (i < x.length) {
1989
+ column = r.columns[columnIndex++] = {
1990
+ key: x[i++],
1991
+ name: transform.column.from
1992
+ ? transform.column.from(x.toString('utf8', i, i = x.indexOf(0, i)))
1993
+ : x.toString('utf8', i, i = x.indexOf(0, i)),
1994
+ type: x.readUInt32BE(i += 1),
1995
+ parser: parsers[x.readUInt32BE(i)],
1996
+ atttypmod: x.readUInt32BE(i += 4)
1997
+ }
1998
+
1999
+ column.key && r.keys.push(column)
2000
+ i += 4
2001
+ }
2002
+ },
2003
+ Y: () => { /* noop */ }, // Type
2004
+ O: () => { /* noop */ }, // Origin
2005
+ B: x => { // Begin
2006
+ state.date = Time(x.readBigInt64BE(9))
2007
+ state.lsn = x.subarray(1, 9)
2008
+ },
2009
+ I: x => { // Insert
2010
+ let i = 1
2011
+ const relation = state[x.readUInt32BE(i)]
2012
+ const { row } = tuples(x, relation.columns, i += 7, transform)
2013
+
2014
+ handle(row, {
2015
+ command: 'insert',
2016
+ relation
2017
+ })
2018
+ },
2019
+ D: x => { // Delete
2020
+ let i = 1
2021
+ const relation = state[x.readUInt32BE(i)]
2022
+ i += 4
2023
+ const key = x[i] === 75
2024
+ handle(key || x[i] === 79
2025
+ ? tuples(x, relation.columns, i += 3, transform).row
2026
+ : null
2027
+ , {
2028
+ command: 'delete',
2029
+ relation,
2030
+ key
2031
+ })
2032
+ },
2033
+ U: x => { // Update
2034
+ let i = 1
2035
+ const relation = state[x.readUInt32BE(i)]
2036
+ i += 4
2037
+ const key = x[i] === 75
2038
+ const xs = key || x[i] === 79
2039
+ ? tuples(x, relation.columns, i += 3, transform)
2040
+ : null
2041
+
2042
+ xs && (i = xs.i)
2043
+
2044
+ const { row } = tuples(x, relation.columns, i + 3, transform)
2045
+
2046
+ handle(row, {
2047
+ command: 'update',
2048
+ relation,
2049
+ key,
2050
+ old: xs && xs.row
2051
+ })
2052
+ },
2053
+ T: () => { /* noop */ }, // Truncate,
2054
+ C: () => { /* noop */ } // Commit
2055
+ }).reduce(char, {})[x[0]](x)
2056
+ }
2057
+
2058
+ function tuples(x, columns, xi, transform) {
2059
+ let type
2060
+ , column
2061
+ , value
2062
+
2063
+ const row = transform.raw ? new Array(columns.length) : {}
2064
+ for (let i = 0; i < columns.length; i++) {
2065
+ type = x[xi++]
2066
+ column = columns[i]
2067
+ value = type === 110 // n
2068
+ ? null
2069
+ : type === 117 // u
2070
+ ? undefined
2071
+ : column.parser === undefined
2072
+ ? x.toString('utf8', xi + 4, xi += 4 + x.readUInt32BE(xi))
2073
+ : column.parser.array === true
2074
+ ? column.parser(x.toString('utf8', xi + 5, xi += 4 + x.readUInt32BE(xi)))
2075
+ : column.parser(x.toString('utf8', xi + 4, xi += 4 + x.readUInt32BE(xi)))
2076
+
2077
+ transform.raw
2078
+ ? (row[i] = transform.raw === true
2079
+ ? value
2080
+ : transform.value.from ? transform.value.from(value, column) : value)
2081
+ : (row[column.name] = transform.value.from
2082
+ ? transform.value.from(value, column)
2083
+ : value
2084
+ )
2085
+ }
2086
+
2087
+ return { i: xi, row: transform.row.from ? transform.row.from(row) : row }
2088
+ }
2089
+
2090
+ function parseEvent(x) {
2091
+ const xs = x.match(/^(\*|insert|update|delete)?:?([^.]+?\.?[^=]+)?=?(.+)?/i) || []
2092
+
2093
+ if (!xs)
2094
+ throw new Error('Malformed subscribe pattern: ' + x)
2095
+
2096
+ const [, command, path, key] = xs
2097
+
2098
+ return (command || '*')
2099
+ + (path ? ':' + (path.indexOf('.') === -1 ? 'public.' + path : path) : '')
2100
+ + (key ? '=' + key : '')
2101
+ }
2102
+
2103
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/src/large.js
2104
+
2105
+
2106
+ function largeObject(sql, oid, mode = 0x00020000 | 0x00040000) {
2107
+ return new Promise(async(resolve, reject) => {
2108
+ await sql.begin(async sql => {
2109
+ let finish
2110
+ !oid && ([{ oid }] = await sql`select lo_creat(-1) as oid`)
2111
+ const [{ fd }] = await sql`select lo_open(${ oid }, ${ mode }) as fd`
2112
+
2113
+ const lo = {
2114
+ writable,
2115
+ readable,
2116
+ close : () => sql`select lo_close(${ fd })`.then(finish),
2117
+ tell : () => sql`select lo_tell64(${ fd })`,
2118
+ read : (x) => sql`select loread(${ fd }, ${ x }) as data`,
2119
+ write : (x) => sql`select lowrite(${ fd }, ${ x })`,
2120
+ truncate : (x) => sql`select lo_truncate64(${ fd }, ${ x })`,
2121
+ seek : (x, whence = 0) => sql`select lo_lseek64(${ fd }, ${ x }, ${ whence })`,
2122
+ size : () => sql`
2123
+ select
2124
+ lo_lseek64(${ fd }, location, 0) as position,
2125
+ seek.size
2126
+ from (
2127
+ select
2128
+ lo_lseek64($1, 0, 2) as size,
2129
+ tell.location
2130
+ from (select lo_tell64($1) as location) tell
2131
+ ) seek
2132
+ `
2133
+ }
2134
+
2135
+ resolve(lo)
2136
+
2137
+ return new Promise(async r => finish = r)
2138
+
2139
+ async function readable({
2140
+ highWaterMark = 2048 * 8,
2141
+ start = 0,
2142
+ end = Infinity
2143
+ } = {}) {
2144
+ let max = end - start
2145
+ start && await lo.seek(start)
2146
+ return new external_stream_.Readable({
2147
+ highWaterMark,
2148
+ async read(size) {
2149
+ const l = size > max ? size - max : size
2150
+ max -= size
2151
+ const [{ data }] = await lo.read(l)
2152
+ this.push(data)
2153
+ if (data.length < size)
2154
+ this.push(null)
2155
+ }
2156
+ })
2157
+ }
2158
+
2159
+ async function writable({
2160
+ highWaterMark = 2048 * 8,
2161
+ start = 0
2162
+ } = {}) {
2163
+ start && await lo.seek(start)
2164
+ return new external_stream_.Writable({
2165
+ highWaterMark,
2166
+ write(chunk, encoding, callback) {
2167
+ lo.write(chunk).then(() => callback(), callback)
2168
+ }
2169
+ })
2170
+ }
2171
+ }).catch(reject)
2172
+ })
2173
+ }
2174
+
2175
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/src/index.js
2176
+
2177
+
2178
+
2179
+
2180
+
2181
+
2182
+
2183
+
2184
+
2185
+
2186
+
2187
+
2188
+ Object.assign(Postgres, {
2189
+ PostgresError: PostgresError,
2190
+ toPascal: toPascal,
2191
+ pascal: pascal,
2192
+ toCamel: toCamel,
2193
+ camel: camel,
2194
+ toKebab: toKebab,
2195
+ kebab: kebab,
2196
+ fromPascal: fromPascal,
2197
+ fromCamel: fromCamel,
2198
+ fromKebab: fromKebab,
2199
+ BigInt: {
2200
+ to: 20,
2201
+ from: [20],
2202
+ parse: x => BigInt(x), // eslint-disable-line
2203
+ serialize: x => x.toString()
2204
+ }
2205
+ })
2206
+
2207
+ /* harmony default export */ const src = (Postgres);
2208
+
2209
+ function Postgres(a, b) {
2210
+ const options = parseOptions(a, b)
2211
+ , subscribe = options.no_subscribe || Subscribe(Postgres, { ...options })
2212
+
2213
+ let ending = false
2214
+
2215
+ const queries = src_queue()
2216
+ , connecting = src_queue()
2217
+ , reserved = src_queue()
2218
+ , closed = src_queue()
2219
+ , ended = src_queue()
2220
+ , open = src_queue()
2221
+ , busy = src_queue()
2222
+ , full = src_queue()
2223
+ , queues = { connecting, reserved, closed, ended, open, busy, full }
2224
+
2225
+ const connections = [...Array(options.max)].map(() => src_connection(options, queues, { onopen, onend, onclose }))
2226
+
2227
+ const sql = Sql(handler)
2228
+
2229
+ Object.assign(sql, {
2230
+ get parameters() { return options.parameters },
2231
+ largeObject: largeObject.bind(null, sql),
2232
+ subscribe,
2233
+ CLOSE: CLOSE,
2234
+ END: CLOSE,
2235
+ PostgresError: PostgresError,
2236
+ options,
2237
+ reserve,
2238
+ listen,
2239
+ begin,
2240
+ close,
2241
+ end
2242
+ })
2243
+
2244
+ return sql
2245
+
2246
+ function Sql(handler) {
2247
+ handler.debug = options.debug
2248
+
2249
+ Object.entries(options.types).reduce((acc, [name, type]) => {
2250
+ acc[name] = (x) => new Parameter(x, type.to)
2251
+ return acc
2252
+ }, typed)
2253
+
2254
+ Object.assign(sql, {
2255
+ types: typed,
2256
+ typed,
2257
+ unsafe,
2258
+ notify,
2259
+ array,
2260
+ json,
2261
+ file
2262
+ })
2263
+
2264
+ return sql
2265
+
2266
+ function typed(value, type) {
2267
+ return new Parameter(value, type)
2268
+ }
2269
+
2270
+ function sql(strings, ...args) {
2271
+ const query = strings && Array.isArray(strings.raw)
2272
+ ? new Query(strings, args, handler, cancel)
2273
+ : typeof strings === 'string' && !args.length
2274
+ ? new Identifier(options.transform.column.to ? options.transform.column.to(strings) : strings)
2275
+ : new Builder(strings, args)
2276
+ return query
2277
+ }
2278
+
2279
+ function unsafe(string, args = [], options = {}) {
2280
+ arguments.length === 2 && !Array.isArray(args) && (options = args, args = [])
2281
+ const query = new Query([string], args, handler, cancel, {
2282
+ prepare: false,
2283
+ ...options,
2284
+ simple: 'simple' in options ? options.simple : args.length === 0
2285
+ })
2286
+ return query
2287
+ }
2288
+
2289
+ function file(path, args = [], options = {}) {
2290
+ arguments.length === 2 && !Array.isArray(args) && (options = args, args = [])
2291
+ const query = new Query([], args, (query) => {
2292
+ external_fs_["read"+"File"](path, 'utf8', (err, string) => {
2293
+ if (err)
2294
+ return query.reject(err)
2295
+
2296
+ query.strings = [string]
2297
+ handler(query)
2298
+ })
2299
+ }, cancel, {
2300
+ ...options,
2301
+ simple: 'simple' in options ? options.simple : args.length === 0
2302
+ })
2303
+ return query
2304
+ }
2305
+ }
2306
+
2307
+ async function listen(name, fn, onlisten) {
2308
+ const listener = { fn, onlisten }
2309
+
2310
+ const sql = listen.sql || (listen.sql = Postgres({
2311
+ ...options,
2312
+ max: 1,
2313
+ idle_timeout: null,
2314
+ max_lifetime: null,
2315
+ fetch_types: false,
2316
+ onclose() {
2317
+ Object.entries(listen.channels).forEach(([name, { listeners }]) => {
2318
+ delete listen.channels[name]
2319
+ Promise.all(listeners.map(l => listen(name, l.fn, l.onlisten).catch(() => { /* noop */ })))
2320
+ })
2321
+ },
2322
+ onnotify(c, x) {
2323
+ c in listen.channels && listen.channels[c].listeners.forEach(l => l.fn(x))
2324
+ }
2325
+ }))
2326
+
2327
+ const channels = listen.channels || (listen.channels = {})
2328
+ , exists = name in channels
2329
+
2330
+ if (exists) {
2331
+ channels[name].listeners.push(listener)
2332
+ const result = await channels[name].result
2333
+ listener.onlisten && listener.onlisten()
2334
+ return { state: result.state, unlisten }
2335
+ }
2336
+
2337
+ channels[name] = { result: sql`listen ${
2338
+ sql.unsafe('"' + name.replace(/"/g, '""') + '"')
2339
+ }`, listeners: [listener] }
2340
+ const result = await channels[name].result
2341
+ listener.onlisten && listener.onlisten()
2342
+ return { state: result.state, unlisten }
2343
+
2344
+ async function unlisten() {
2345
+ if (name in channels === false)
2346
+ return
2347
+
2348
+ channels[name].listeners = channels[name].listeners.filter(x => x !== listener)
2349
+ if (channels[name].listeners.length)
2350
+ return
2351
+
2352
+ delete channels[name]
2353
+ return sql`unlisten ${
2354
+ sql.unsafe('"' + name.replace(/"/g, '""') + '"')
2355
+ }`
2356
+ }
2357
+ }
2358
+
2359
+ async function notify(channel, payload) {
2360
+ return await sql`select pg_notify(${ channel }, ${ '' + payload })`
2361
+ }
2362
+
2363
+ async function reserve() {
2364
+ const queue = src_queue()
2365
+ const c = open.length
2366
+ ? open.shift()
2367
+ : await new Promise((resolve, reject) => {
2368
+ const query = { reserve: resolve, reject }
2369
+ queries.push(query)
2370
+ closed.length && connect(closed.shift(), query)
2371
+ })
2372
+
2373
+ move(c, reserved)
2374
+ c.reserved = () => queue.length
2375
+ ? c.execute(queue.shift())
2376
+ : move(c, reserved)
2377
+ c.reserved.release = true
2378
+
2379
+ const sql = Sql(handler)
2380
+ sql.release = () => {
2381
+ c.reserved = null
2382
+ onopen(c)
2383
+ }
2384
+
2385
+ return sql
2386
+
2387
+ function handler(q) {
2388
+ c.queue === full
2389
+ ? queue.push(q)
2390
+ : c.execute(q) || move(c, full)
2391
+ }
2392
+ }
2393
+
2394
+ async function begin(options, fn) {
2395
+ !fn && (fn = options, options = '')
2396
+ const queries = src_queue()
2397
+ let savepoints = 0
2398
+ , connection
2399
+ , prepare = null
2400
+
2401
+ try {
2402
+ await sql.unsafe('begin ' + options.replace(/[^a-z ]/ig, ''), [], { onexecute }).execute()
2403
+ return await Promise.race([
2404
+ scope(connection, fn),
2405
+ new Promise((_, reject) => connection.onclose = reject)
2406
+ ])
2407
+ } catch (error) {
2408
+ throw error
2409
+ }
2410
+
2411
+ async function scope(c, fn, name) {
2412
+ const sql = Sql(handler)
2413
+ sql.savepoint = savepoint
2414
+ sql.prepare = x => prepare = x.replace(/[^a-z0-9$-_. ]/gi)
2415
+ let uncaughtError
2416
+ , result
2417
+
2418
+ name && await sql`savepoint ${ sql(name) }`
2419
+ try {
2420
+ result = await new Promise((resolve, reject) => {
2421
+ const x = fn(sql)
2422
+ Promise.resolve(Array.isArray(x) ? Promise.all(x) : x).then(resolve, reject)
2423
+ })
2424
+
2425
+ if (uncaughtError)
2426
+ throw uncaughtError
2427
+ } catch (e) {
2428
+ await (name
2429
+ ? sql`rollback to ${ sql(name) }`
2430
+ : sql`rollback`
2431
+ )
2432
+ throw e instanceof PostgresError && e.code === '25P02' && uncaughtError || e
2433
+ }
2434
+
2435
+ if (!name) {
2436
+ prepare
2437
+ ? await sql`prepare transaction '${ sql.unsafe(prepare) }'`
2438
+ : await sql`commit`
2439
+ }
2440
+
2441
+ return result
2442
+
2443
+ function savepoint(name, fn) {
2444
+ if (name && Array.isArray(name.raw))
2445
+ return savepoint(sql => sql.apply(sql, arguments))
2446
+
2447
+ arguments.length === 1 && (fn = name, name = null)
2448
+ return scope(c, fn, 's' + savepoints++ + (name ? '_' + name : ''))
2449
+ }
2450
+
2451
+ function handler(q) {
2452
+ q.catch(e => uncaughtError || (uncaughtError = e))
2453
+ c.queue === full
2454
+ ? queries.push(q)
2455
+ : c.execute(q) || move(c, full)
2456
+ }
2457
+ }
2458
+
2459
+ function onexecute(c) {
2460
+ connection = c
2461
+ move(c, reserved)
2462
+ c.reserved = () => queries.length
2463
+ ? c.execute(queries.shift())
2464
+ : move(c, reserved)
2465
+ }
2466
+ }
2467
+
2468
+ function move(c, queue) {
2469
+ c.queue.remove(c)
2470
+ queue.push(c)
2471
+ c.queue = queue
2472
+ queue === open
2473
+ ? c.idleTimer.start()
2474
+ : c.idleTimer.cancel()
2475
+ return c
2476
+ }
2477
+
2478
+ function json(x) {
2479
+ return new Parameter(x, 3802)
2480
+ }
2481
+
2482
+ function array(x, type) {
2483
+ if (!Array.isArray(x))
2484
+ return array(Array.from(arguments))
2485
+
2486
+ return new Parameter(x, type || (x.length ? inferType(x) || 25 : 0), options.shared.typeArrayMap)
2487
+ }
2488
+
2489
+ function handler(query) {
2490
+ if (ending)
2491
+ return query.reject(Errors.connection('CONNECTION_ENDED', options, options))
2492
+
2493
+ if (open.length)
2494
+ return go(open.shift(), query)
2495
+
2496
+ if (closed.length)
2497
+ return connect(closed.shift(), query)
2498
+
2499
+ busy.length
2500
+ ? go(busy.shift(), query)
2501
+ : queries.push(query)
2502
+ }
2503
+
2504
+ function go(c, query) {
2505
+ return c.execute(query)
2506
+ ? move(c, busy)
2507
+ : move(c, full)
2508
+ }
2509
+
2510
+ function cancel(query) {
2511
+ return new Promise((resolve, reject) => {
2512
+ query.state
2513
+ ? query.active
2514
+ ? src_connection(options).cancel(query.state, resolve, reject)
2515
+ : query.cancelled = { resolve, reject }
2516
+ : (
2517
+ queries.remove(query),
2518
+ query.cancelled = true,
2519
+ query.reject(Errors.generic('57014', 'canceling statement due to user request')),
2520
+ resolve()
2521
+ )
2522
+ })
2523
+ }
2524
+
2525
+ async function end({ timeout = null } = {}) {
2526
+ if (ending)
2527
+ return ending
2528
+
2529
+ await 1
2530
+ let timer
2531
+ return ending = Promise.race([
2532
+ new Promise(r => timeout !== null && (timer = setTimeout(destroy, timeout * 1000, r))),
2533
+ Promise.all(connections.map(c => c.end()).concat(
2534
+ listen.sql ? listen.sql.end({ timeout: 0 }) : [],
2535
+ subscribe.sql ? subscribe.sql.end({ timeout: 0 }) : []
2536
+ ))
2537
+ ]).then(() => clearTimeout(timer))
2538
+ }
2539
+
2540
+ async function close() {
2541
+ await Promise.all(connections.map(c => c.end()))
2542
+ }
2543
+
2544
+ async function destroy(resolve) {
2545
+ await Promise.all(connections.map(c => c.terminate()))
2546
+ while (queries.length)
2547
+ queries.shift().reject(Errors.connection('CONNECTION_DESTROYED', options))
2548
+ resolve()
2549
+ }
2550
+
2551
+ function connect(c, query) {
2552
+ move(c, connecting)
2553
+ c.connect(query)
2554
+ return c
2555
+ }
2556
+
2557
+ function onend(c) {
2558
+ move(c, ended)
2559
+ }
2560
+
2561
+ function onopen(c) {
2562
+ if (queries.length === 0)
2563
+ return move(c, open)
2564
+
2565
+ let max = Math.ceil(queries.length / (connecting.length + 1))
2566
+ , ready = true
2567
+
2568
+ while (ready && queries.length && max-- > 0) {
2569
+ const query = queries.shift()
2570
+ if (query.reserve)
2571
+ return query.reserve(c)
2572
+
2573
+ ready = c.execute(query)
2574
+ }
2575
+
2576
+ ready
2577
+ ? move(c, busy)
2578
+ : move(c, full)
2579
+ }
2580
+
2581
+ function onclose(c, e) {
2582
+ move(c, closed)
2583
+ c.reserved = null
2584
+ c.onclose && (c.onclose(e), c.onclose = null)
2585
+ options.onclose && options.onclose(c.id)
2586
+ queries.length && connect(c, queries.shift())
2587
+ }
2588
+ }
2589
+
2590
+ function parseOptions(a, b) {
2591
+ if (a && a.shared)
2592
+ return a
2593
+
2594
+ const env = process["env"] // eslint-disable-line
2595
+ , o = (!a || typeof a === 'string' ? b : a) || {}
2596
+ , { url, multihost } = parseUrl(a)
2597
+ , query = [...url.searchParams].reduce((a, [b, c]) => (a[b] = c, a), {})
2598
+ , host = o.hostname || o.host || multihost || url.hostname || env.PGHOST || 'localhost'
2599
+ , port = o.port || url.port || env.PGPORT || 5432
2600
+ , user = o.user || o.username || url.username || env.PGUSERNAME || env.PGUSER || osUsername()
2601
+
2602
+ o.no_prepare && (o.prepare = false)
2603
+ query.sslmode && (query.ssl = query.sslmode, delete query.sslmode)
2604
+ 'timeout' in o && (console.log('The timeout option is deprecated, use idle_timeout instead'), o.idle_timeout = o.timeout) // eslint-disable-line
2605
+ query.sslrootcert === 'system' && (query.ssl = 'verify-full')
2606
+
2607
+ const ints = ['idle_timeout', 'connect_timeout', 'max_lifetime', 'max_pipeline', 'backoff', 'keep_alive']
2608
+ const defaults = {
2609
+ max : globalThis.Cloudflare ? 3 : 10,
2610
+ ssl : false,
2611
+ sslnegotiation : null,
2612
+ idle_timeout : null,
2613
+ connect_timeout : 30,
2614
+ max_lifetime : max_lifetime,
2615
+ max_pipeline : 100,
2616
+ backoff : backoff,
2617
+ keep_alive : 60,
2618
+ prepare : true,
2619
+ debug : false,
2620
+ fetch_types : true,
2621
+ publications : 'alltables',
2622
+ target_session_attrs: null
2623
+ }
2624
+
2625
+ return {
2626
+ host : Array.isArray(host) ? host : host.split(',').map(x => x.split(':')[0]),
2627
+ port : Array.isArray(port) ? port : host.split(',').map(x => parseInt(x.split(':')[1] || port)),
2628
+ path : o.path || host.indexOf('/') > -1 && host + '/.s.PGSQL.' + port,
2629
+ database : o.database || o.db || (url.pathname || '').slice(1) || env.PGDATABASE || user,
2630
+ user : user,
2631
+ pass : o.pass || o.password || url.password || env.PGPASSWORD || '',
2632
+ ...Object.entries(defaults).reduce(
2633
+ (acc, [k, d]) => {
2634
+ const value = k in o ? o[k] : k in query
2635
+ ? (query[k] === 'disable' || query[k] === 'false' ? false : query[k])
2636
+ : env['PG' + k.toUpperCase()] || d
2637
+ acc[k] = typeof value === 'string' && ints.includes(k)
2638
+ ? +value
2639
+ : value
2640
+ return acc
2641
+ },
2642
+ {}
2643
+ ),
2644
+ connection : {
2645
+ application_name: env.PGAPPNAME || 'postgres.js',
2646
+ ...o.connection,
2647
+ ...Object.entries(query).reduce((acc, [k, v]) => (k in defaults || (acc[k] = v), acc), {})
2648
+ },
2649
+ types : o.types || {},
2650
+ target_session_attrs: tsa(o, url, env),
2651
+ onnotice : o.onnotice,
2652
+ onnotify : o.onnotify,
2653
+ onclose : o.onclose,
2654
+ onparameter : o.onparameter,
2655
+ socket : o.socket,
2656
+ transform : parseTransform(o.transform || { undefined: undefined }),
2657
+ parameters : {},
2658
+ shared : { retries: 0, typeArrayMap: {} },
2659
+ ...mergeUserTypes(o.types)
2660
+ }
2661
+ }
2662
+
2663
+ function tsa(o, url, env) {
2664
+ const x = o.target_session_attrs || url.searchParams.get('target_session_attrs') || env.PGTARGETSESSIONATTRS
2665
+ if (!x || ['read-write', 'read-only', 'primary', 'standby', 'prefer-standby'].includes(x))
2666
+ return x
2667
+
2668
+ throw new Error('target_session_attrs ' + x + ' is not supported')
2669
+ }
2670
+
2671
+ function backoff(retries) {
2672
+ return (0.5 + Math.random() / 2) * Math.min(3 ** retries / 100, 20)
2673
+ }
2674
+
2675
+ function max_lifetime() {
2676
+ return 60 * (30 + Math.random() * 30)
2677
+ }
2678
+
2679
+ function parseTransform(x) {
2680
+ return {
2681
+ undefined: x.undefined,
2682
+ column: {
2683
+ from: typeof x.column === 'function' ? x.column : x.column && x.column.from,
2684
+ to: x.column && x.column.to
2685
+ },
2686
+ value: {
2687
+ from: typeof x.value === 'function' ? x.value : x.value && x.value.from,
2688
+ to: x.value && x.value.to
2689
+ },
2690
+ row: {
2691
+ from: typeof x.row === 'function' ? x.row : x.row && x.row.from,
2692
+ to: x.row && x.row.to
2693
+ }
2694
+ }
2695
+ }
2696
+
2697
+ function parseUrl(url) {
2698
+ if (!url || typeof url !== 'string')
2699
+ return { url: { searchParams: new Map() } }
2700
+
2701
+ let host = url
2702
+ host = host.slice(host.indexOf('://') + 3).split(/[?/]/)[0]
2703
+ host = decodeURIComponent(host.slice(host.indexOf('@') + 1))
2704
+
2705
+ const urlObj = new URL(url.replace(host, host.split(',')[0]))
2706
+
2707
+ return {
2708
+ url: {
2709
+ username: decodeURIComponent(urlObj.username),
2710
+ password: decodeURIComponent(urlObj.password),
2711
+ host: urlObj.host,
2712
+ hostname: urlObj.hostname,
2713
+ port: urlObj.port,
2714
+ pathname: urlObj.pathname,
2715
+ searchParams: urlObj.searchParams
2716
+ },
2717
+ multihost: host.indexOf(',') > -1 && host
2718
+ }
2719
+ }
2720
+
2721
+ function osUsername() {
2722
+ try {
2723
+ return external_os_.userInfo().username // eslint-disable-line
2724
+ } catch (_) {
2725
+ return process["env"].USERNAME || process["env"].USER || process["env"].LOGNAME // eslint-disable-line
2726
+ }
2727
+ }
2728
+
2729
+
2730
+ /***/ })
2731
+
2732
+ };
2733
+
2734
+ //# sourceMappingURL=678.index.js.map