@memberjunction/cli 6.3.0-edge.0 → 6.3.0-edge.2

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 (251) hide show
  1. package/README.md +1047 -359
  2. package/dist/baseline/connection.d.ts.map +1 -1
  3. package/dist/baseline/connection.js +12 -1
  4. package/dist/baseline/connection.js.map +1 -1
  5. package/dist/commands/agent/usage.d.ts +7 -0
  6. package/dist/commands/agent/usage.d.ts.map +1 -0
  7. package/dist/commands/agent/usage.js +10 -0
  8. package/dist/commands/agent/usage.js.map +1 -0
  9. package/dist/commands/app/check-updates.d.ts +2 -2
  10. package/dist/commands/app/check-updates.d.ts.map +1 -1
  11. package/dist/commands/app/check-updates.js +8 -7
  12. package/dist/commands/app/check-updates.js.map +1 -1
  13. package/dist/commands/app/install.d.ts +2 -2
  14. package/dist/commands/app/install.d.ts.map +1 -1
  15. package/dist/commands/app/install.js +29 -18
  16. package/dist/commands/app/install.js.map +1 -1
  17. package/dist/commands/app/remove.d.ts.map +1 -1
  18. package/dist/commands/app/remove.js +3 -1
  19. package/dist/commands/app/remove.js.map +1 -1
  20. package/dist/commands/app/upgrade.d.ts +1 -0
  21. package/dist/commands/app/upgrade.d.ts.map +1 -1
  22. package/dist/commands/app/upgrade.js +6 -0
  23. package/dist/commands/app/upgrade.js.map +1 -1
  24. package/dist/commands/codegen/index.d.ts +1 -0
  25. package/dist/commands/codegen/index.d.ts.map +1 -1
  26. package/dist/commands/codegen/manifest.d.ts +40 -0
  27. package/dist/commands/codegen/manifest.d.ts.map +1 -1
  28. package/dist/commands/codegen/manifest.js +124 -3
  29. package/dist/commands/codegen/manifest.js.map +1 -1
  30. package/dist/commands/diag/usage.d.ts +7 -0
  31. package/dist/commands/diag/usage.d.ts.map +1 -0
  32. package/dist/commands/diag/usage.js +10 -0
  33. package/dist/commands/diag/usage.js.map +1 -0
  34. package/dist/commands/doctor/index.d.ts +6 -0
  35. package/dist/commands/doctor/index.d.ts.map +1 -1
  36. package/dist/commands/doctor/index.js +42 -0
  37. package/dist/commands/doctor/index.js.map +1 -1
  38. package/dist/commands/explorer/postbuild.d.ts +14 -0
  39. package/dist/commands/explorer/postbuild.d.ts.map +1 -0
  40. package/dist/commands/explorer/postbuild.js +49 -0
  41. package/dist/commands/explorer/postbuild.js.map +1 -0
  42. package/dist/commands/explorer/usage.d.ts +7 -0
  43. package/dist/commands/explorer/usage.d.ts.map +1 -0
  44. package/dist/commands/explorer/usage.js +10 -0
  45. package/dist/commands/explorer/usage.js.map +1 -0
  46. package/dist/commands/harness/account/add.d.ts +22 -0
  47. package/dist/commands/harness/account/add.d.ts.map +1 -0
  48. package/dist/commands/harness/account/add.js +100 -0
  49. package/dist/commands/harness/account/add.js.map +1 -0
  50. package/dist/commands/harness/account/clear-cooldown.d.ts +13 -0
  51. package/dist/commands/harness/account/clear-cooldown.d.ts.map +1 -0
  52. package/dist/commands/harness/account/clear-cooldown.js +32 -0
  53. package/dist/commands/harness/account/clear-cooldown.js.map +1 -0
  54. package/dist/commands/harness/account/disable.d.ts +13 -0
  55. package/dist/commands/harness/account/disable.d.ts.map +1 -0
  56. package/dist/commands/harness/account/disable.js +34 -0
  57. package/dist/commands/harness/account/disable.js.map +1 -0
  58. package/dist/commands/harness/account/enable.d.ts +13 -0
  59. package/dist/commands/harness/account/enable.d.ts.map +1 -0
  60. package/dist/commands/harness/account/enable.js +34 -0
  61. package/dist/commands/harness/account/enable.js.map +1 -0
  62. package/dist/commands/harness/account/index.d.ts +7 -0
  63. package/dist/commands/harness/account/index.d.ts.map +1 -0
  64. package/dist/commands/harness/account/index.js +23 -0
  65. package/dist/commands/harness/account/index.js.map +1 -0
  66. package/dist/commands/harness/account/list.d.ts +15 -0
  67. package/dist/commands/harness/account/list.d.ts.map +1 -0
  68. package/dist/commands/harness/account/list.js +58 -0
  69. package/dist/commands/harness/account/list.js.map +1 -0
  70. package/dist/commands/harness/account/login.d.ts +16 -0
  71. package/dist/commands/harness/account/login.d.ts.map +1 -0
  72. package/dist/commands/harness/account/login.js +50 -0
  73. package/dist/commands/harness/account/login.js.map +1 -0
  74. package/dist/commands/harness/account/remove.d.ts +14 -0
  75. package/dist/commands/harness/account/remove.d.ts.map +1 -0
  76. package/dist/commands/harness/account/remove.js +43 -0
  77. package/dist/commands/harness/account/remove.js.map +1 -0
  78. package/dist/commands/harness/account/set-strategy.d.ts +13 -0
  79. package/dist/commands/harness/account/set-strategy.d.ts.map +1 -0
  80. package/dist/commands/harness/account/set-strategy.js +38 -0
  81. package/dist/commands/harness/account/set-strategy.js.map +1 -0
  82. package/dist/commands/harness/index.d.ts +7 -0
  83. package/dist/commands/harness/index.d.ts.map +1 -0
  84. package/dist/commands/harness/index.js +22 -0
  85. package/dist/commands/harness/index.js.map +1 -0
  86. package/dist/commands/harness/usage.d.ts +7 -0
  87. package/dist/commands/harness/usage.d.ts.map +1 -0
  88. package/dist/commands/harness/usage.js +10 -0
  89. package/dist/commands/harness/usage.js.map +1 -0
  90. package/dist/commands/migrate/convert.d.ts +25 -1
  91. package/dist/commands/migrate/convert.d.ts.map +1 -1
  92. package/dist/commands/migrate/convert.js +160 -46
  93. package/dist/commands/migrate/convert.js.map +1 -1
  94. package/dist/commands/migrate/index.d.ts +8 -0
  95. package/dist/commands/migrate/index.d.ts.map +1 -1
  96. package/dist/commands/migrate/index.js +41 -2
  97. package/dist/commands/migrate/index.js.map +1 -1
  98. package/dist/commands/migrate/rebake.d.ts +13 -0
  99. package/dist/commands/migrate/rebake.d.ts.map +1 -1
  100. package/dist/commands/migrate/rebake.js +48 -14
  101. package/dist/commands/migrate/rebake.js.map +1 -1
  102. package/dist/commands/queue/export-topology.d.ts +2 -0
  103. package/dist/commands/queue/export-topology.d.ts.map +1 -1
  104. package/dist/commands/queue/export-topology.js +3 -1
  105. package/dist/commands/queue/export-topology.js.map +1 -1
  106. package/dist/commands/queue/import-bindings.d.ts +2 -0
  107. package/dist/commands/queue/import-bindings.d.ts.map +1 -1
  108. package/dist/commands/queue/import-bindings.js +3 -1
  109. package/dist/commands/queue/import-bindings.js.map +1 -1
  110. package/dist/commands/queue/index.d.ts.map +1 -1
  111. package/dist/commands/queue/index.js +1 -0
  112. package/dist/commands/queue/index.js.map +1 -1
  113. package/dist/commands/queue/sweep.d.ts +11 -0
  114. package/dist/commands/queue/sweep.d.ts.map +1 -0
  115. package/dist/commands/queue/sweep.js +36 -0
  116. package/dist/commands/queue/sweep.js.map +1 -0
  117. package/dist/commands/queue/validate-bindings.d.ts +2 -0
  118. package/dist/commands/queue/validate-bindings.d.ts.map +1 -1
  119. package/dist/commands/queue/validate-bindings.js +3 -1
  120. package/dist/commands/queue/validate-bindings.js.map +1 -1
  121. package/dist/commands/queue/work.d.ts +4 -0
  122. package/dist/commands/queue/work.d.ts.map +1 -1
  123. package/dist/commands/queue/work.js +9 -9
  124. package/dist/commands/queue/work.js.map +1 -1
  125. package/dist/commands/rubric/usage.d.ts +7 -0
  126. package/dist/commands/rubric/usage.d.ts.map +1 -0
  127. package/dist/commands/rubric/usage.js +10 -0
  128. package/dist/commands/rubric/usage.js.map +1 -0
  129. package/dist/commands/test/regression/index.d.ts.map +1 -1
  130. package/dist/commands/test/regression/index.js +2 -0
  131. package/dist/commands/test/regression/index.js.map +1 -1
  132. package/dist/commands/test/regression/new.d.ts +21 -0
  133. package/dist/commands/test/regression/new.d.ts.map +1 -0
  134. package/dist/commands/test/regression/new.js +82 -0
  135. package/dist/commands/test/regression/new.js.map +1 -0
  136. package/dist/commands/test/regression/up.d.ts +1 -0
  137. package/dist/commands/test/regression/up.d.ts.map +1 -1
  138. package/dist/commands/test/regression/up.js +17 -0
  139. package/dist/commands/test/regression/up.js.map +1 -1
  140. package/dist/commands/test/scripts.d.ts +6 -4
  141. package/dist/commands/test/scripts.d.ts.map +1 -1
  142. package/dist/commands/test/scripts.js +14 -0
  143. package/dist/commands/test/scripts.js.map +1 -1
  144. package/dist/commands/test/suite.d.ts +1 -0
  145. package/dist/commands/test/suite.d.ts.map +1 -1
  146. package/dist/commands/test/suite.js +6 -0
  147. package/dist/commands/test/suite.js.map +1 -1
  148. package/dist/commands/usage.js +2 -1
  149. package/dist/commands/usage.js.map +1 -1
  150. package/dist/commands/user/usage.d.ts +7 -0
  151. package/dist/commands/user/usage.d.ts.map +1 -0
  152. package/dist/commands/user/usage.js +10 -0
  153. package/dist/commands/user/usage.js.map +1 -0
  154. package/dist/config.d.ts +119 -0
  155. package/dist/config.d.ts.map +1 -1
  156. package/dist/config.js +43 -1
  157. package/dist/config.js.map +1 -1
  158. package/dist/init-templates/citizen-builder/.env.example +5 -0
  159. package/dist/init-templates/citizen-builder/docker-compose.yml +9 -0
  160. package/dist/init-templates/citizen-builder/scripts/docker-entrypoint.sh +18 -1
  161. package/dist/lib/db-preflight.d.ts.map +1 -1
  162. package/dist/lib/db-preflight.js +22 -0
  163. package/dist/lib/db-preflight.js.map +1 -1
  164. package/dist/lib/derived-usage.d.ts +8 -0
  165. package/dist/lib/derived-usage.d.ts.map +1 -1
  166. package/dist/lib/derived-usage.js +30 -20
  167. package/dist/lib/derived-usage.js.map +1 -1
  168. package/dist/lib/dev-workspace/prebundle.d.ts +3 -1
  169. package/dist/lib/dev-workspace/prebundle.d.ts.map +1 -1
  170. package/dist/lib/dev-workspace/prebundle.js +4 -3
  171. package/dist/lib/dev-workspace/prebundle.js.map +1 -1
  172. package/dist/lib/domain-profiles.d.ts.map +1 -1
  173. package/dist/lib/domain-profiles.js +24 -0
  174. package/dist/lib/domain-profiles.js.map +1 -1
  175. package/dist/lib/domain-usage-command.js +2 -1
  176. package/dist/lib/domain-usage-command.js.map +1 -1
  177. package/dist/lib/explorer-postbuild/public-page-html.d.ts +48 -0
  178. package/dist/lib/explorer-postbuild/public-page-html.d.ts.map +1 -0
  179. package/dist/lib/explorer-postbuild/public-page-html.js +284 -0
  180. package/dist/lib/explorer-postbuild/public-page-html.js.map +1 -0
  181. package/dist/lib/explorer-postbuild/service-worker-check.d.ts +13 -0
  182. package/dist/lib/explorer-postbuild/service-worker-check.d.ts.map +1 -0
  183. package/dist/lib/explorer-postbuild/service-worker-check.js +41 -0
  184. package/dist/lib/explorer-postbuild/service-worker-check.js.map +1 -0
  185. package/dist/lib/harness-account.d.ts +34 -0
  186. package/dist/lib/harness-account.d.ts.map +1 -0
  187. package/dist/lib/harness-account.js +105 -0
  188. package/dist/lib/harness-account.js.map +1 -0
  189. package/dist/lib/pg-preflight/checks.d.ts +28 -0
  190. package/dist/lib/pg-preflight/checks.d.ts.map +1 -0
  191. package/dist/lib/pg-preflight/checks.js +94 -0
  192. package/dist/lib/pg-preflight/checks.js.map +1 -0
  193. package/dist/lib/pg-preflight/extension-check.d.ts +28 -0
  194. package/dist/lib/pg-preflight/extension-check.d.ts.map +1 -0
  195. package/dist/lib/pg-preflight/extension-check.js +86 -0
  196. package/dist/lib/pg-preflight/extension-check.js.map +1 -0
  197. package/dist/lib/pg-preflight/extension-scan.d.ts +24 -0
  198. package/dist/lib/pg-preflight/extension-scan.d.ts.map +1 -0
  199. package/dist/lib/pg-preflight/extension-scan.js +58 -0
  200. package/dist/lib/pg-preflight/extension-scan.js.map +1 -0
  201. package/dist/lib/pg-preflight/pending-migrations.d.ts +28 -0
  202. package/dist/lib/pg-preflight/pending-migrations.d.ts.map +1 -0
  203. package/dist/lib/pg-preflight/pending-migrations.js +48 -0
  204. package/dist/lib/pg-preflight/pending-migrations.js.map +1 -0
  205. package/dist/lib/pg-preflight/preflight.d.ts +18 -0
  206. package/dist/lib/pg-preflight/preflight.d.ts.map +1 -0
  207. package/dist/lib/pg-preflight/preflight.js +43 -0
  208. package/dist/lib/pg-preflight/preflight.js.map +1 -0
  209. package/dist/lib/pg-preflight/remediation.d.ts +27 -0
  210. package/dist/lib/pg-preflight/remediation.d.ts.map +1 -0
  211. package/dist/lib/pg-preflight/remediation.js +82 -0
  212. package/dist/lib/pg-preflight/remediation.js.map +1 -0
  213. package/dist/lib/pg-preflight/render.d.ts +15 -0
  214. package/dist/lib/pg-preflight/render.d.ts.map +1 -0
  215. package/dist/lib/pg-preflight/render.js +48 -0
  216. package/dist/lib/pg-preflight/render.js.map +1 -0
  217. package/dist/lib/pg-preflight/run-for-config.d.ts +23 -0
  218. package/dist/lib/pg-preflight/run-for-config.d.ts.map +1 -0
  219. package/dist/lib/pg-preflight/run-for-config.js +45 -0
  220. package/dist/lib/pg-preflight/run-for-config.js.map +1 -0
  221. package/dist/lib/pg-preflight/types.d.ts +67 -0
  222. package/dist/lib/pg-preflight/types.d.ts.map +1 -0
  223. package/dist/lib/pg-preflight/types.js +8 -0
  224. package/dist/lib/pg-preflight/types.js.map +1 -0
  225. package/dist/lib/regression/test-scaffold.d.ts +52 -0
  226. package/dist/lib/regression/test-scaffold.d.ts.map +1 -0
  227. package/dist/lib/regression/test-scaffold.js +237 -0
  228. package/dist/lib/regression/test-scaffold.js.map +1 -0
  229. package/dist/lib/work-queue/queue-format.d.ts +4 -0
  230. package/dist/lib/work-queue/queue-format.d.ts.map +1 -1
  231. package/dist/lib/work-queue/queue-format.js +15 -0
  232. package/dist/lib/work-queue/queue-format.js.map +1 -1
  233. package/dist/lib/work-queue/queue-worker.d.ts +16 -1
  234. package/dist/lib/work-queue/queue-worker.d.ts.map +1 -1
  235. package/dist/lib/work-queue/queue-worker.js +18 -0
  236. package/dist/lib/work-queue/queue-worker.js.map +1 -1
  237. package/dist/light-commands.d.ts.map +1 -1
  238. package/dist/light-commands.js +34 -0
  239. package/dist/light-commands.js.map +1 -1
  240. package/dist/tsconfig.tsbuildinfo +1 -0
  241. package/dist/utils/app-source-lookups.d.ts +19 -0
  242. package/dist/utils/app-source-lookups.d.ts.map +1 -0
  243. package/dist/utils/app-source-lookups.js +19 -0
  244. package/dist/utils/app-source-lookups.js.map +1 -0
  245. package/dist/utils/open-app-context.d.ts +1 -0
  246. package/dist/utils/open-app-context.d.ts.map +1 -1
  247. package/dist/utils/open-app-context.js +13 -17
  248. package/dist/utils/open-app-context.js.map +1 -1
  249. package/oclif.manifest.json +974 -31
  250. package/package.json +31 -28
  251. package/regression-compose/docker-compose.bacpac-standalone.yml +4 -0
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The individual managed-PostgreSQL preflight checks. Each one runs a read-only catalog
3
+ * query through a {@link PgPreflightQueryRunner} and returns a {@link PgPreflightCheck}.
4
+ *
5
+ * @module lib/pg-preflight/checks
6
+ */
7
+ import type { PgPreflightCheck, PgPreflightCheckId, PgPreflightQueryRunner, PgPreflightStatus, PgRemediationStep, PgSessionContext } from './types.js';
8
+ /** PostgreSQL 14, the lowest version MJ supports. */
9
+ export declare const MIN_PG_SERVER_VERSION_NUM = 140000;
10
+ /** Builds a check result. */
11
+ export declare function MakeCheck(Id: PgPreflightCheckId, Status: PgPreflightStatus, Message: string, Remediation?: PgRemediationStep[], Notes?: string[]): PgPreflightCheck;
12
+ /** Reads the facts every check shares, in one round trip. */
13
+ export declare function ReadSessionContext(runner: PgPreflightQueryRunner): Promise<PgSessionContext>;
14
+ /** The server must be PostgreSQL 14 or later. */
15
+ export declare function CheckServerVersion(session: PgSessionContext, minimum?: number): PgPreflightCheck;
16
+ /** Every group role the migrations grant to must exist. */
17
+ export declare function CheckGroupRoles(runner: PgPreflightQueryRunner, session: PgSessionContext, roles: readonly string[]): Promise<PgPreflightCheck>;
18
+ /** The migrate login needs CREATE on the database: Skyway runs `CREATE SCHEMA IF NOT EXISTS`, which checks it even when the schema exists. */
19
+ export declare function CheckDatabaseCreate(session: PgSessionContext): PgPreflightCheck;
20
+ /** The target schema must be owned by the migrate login, or not exist yet. */
21
+ export declare function CheckTargetSchema(runner: PgPreflightQueryRunner, session: PgSessionContext, schema: string): Promise<PgPreflightCheck>;
22
+ /** TLS for the current backend. Never fails: a warning (info on a loopback host). */
23
+ export declare function CheckTls(runner: PgPreflightQueryRunner, host: string | undefined): Promise<PgPreflightCheck>;
24
+ /** True for localhost and the loopback addresses. */
25
+ export declare function IsLoopbackHost(host: string | undefined): boolean;
26
+ /** Reports `max_connections` and current use. Informational only. */
27
+ export declare function CheckConnections(runner: PgPreflightQueryRunner): Promise<PgPreflightCheck>;
28
+ //# sourceMappingURL=checks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checks.d.ts","sourceRoot":"","sources":["../../../src/lib/pg-preflight/checks.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEpJ,qDAAqD;AACrD,eAAO,MAAM,yBAAyB,SAAS,CAAC;AAEhD,6BAA6B;AAC7B,wBAAgB,SAAS,CACvB,EAAE,EAAE,kBAAkB,EACtB,MAAM,EAAE,iBAAiB,EACzB,OAAO,EAAE,MAAM,EACf,WAAW,GAAE,iBAAiB,EAAO,EACrC,KAAK,GAAE,MAAM,EAAO,GACnB,gBAAgB,CAElB;AAED,6DAA6D;AAC7D,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAWlG;AAED,iDAAiD;AACjD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,gBAAgB,EAAE,OAAO,SAA4B,GAAG,gBAAgB,CAQnH;AAED,2DAA2D;AAC3D,wBAAsB,eAAe,CAAC,MAAM,EAAE,sBAAsB,EAAE,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAWpJ;AAED,8IAA8I;AAC9I,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,GAAG,gBAAgB,CAU/E;AAED,8EAA8E;AAC9E,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,sBAAsB,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAkB5I;AAED,qFAAqF;AACrF,wBAAsB,QAAQ,CAAC,MAAM,EAAE,sBAAsB,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAWlH;AAED,qDAAqD;AACrD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAGhE;AAED,qEAAqE;AACrE,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAShG"}
@@ -0,0 +1,94 @@
1
+ /**
2
+ * The individual managed-PostgreSQL preflight checks. Each one runs a read-only catalog
3
+ * query through a {@link PgPreflightQueryRunner} and returns a {@link PgPreflightCheck}.
4
+ *
5
+ * @module lib/pg-preflight/checks
6
+ */
7
+ import { DatabaseCreateRemediation, RoleRemediation, SchemaOwnerRemediation } from './remediation.js';
8
+ /** PostgreSQL 14, the lowest version MJ supports. */
9
+ export const MIN_PG_SERVER_VERSION_NUM = 140000;
10
+ /** Builds a check result. */
11
+ export function MakeCheck(Id, Status, Message, Remediation = [], Notes = []) {
12
+ return { Id, Status, Message, Remediation, Notes };
13
+ }
14
+ /** Reads the facts every check shares, in one round trip. */
15
+ export async function ReadSessionContext(runner) {
16
+ const rows = await runner.Query(`SELECT current_user AS "Login",
17
+ current_database() AS "Database",
18
+ current_setting('server_version') AS "ServerVersion",
19
+ current_setting('server_version_num')::int AS "ServerVersionNum",
20
+ has_database_privilege(current_database(), 'CREATE') AS "CanCreateInDatabase",
21
+ COALESCE((SELECT rolsuper FROM pg_catalog.pg_roles WHERE rolname = current_user), false) AS "IsSuperuser"`);
22
+ if (rows.length === 0)
23
+ throw new Error('The session context query returned no rows.');
24
+ return rows[0];
25
+ }
26
+ /** The server must be PostgreSQL 14 or later. */
27
+ export function CheckServerVersion(session, minimum = MIN_PG_SERVER_VERSION_NUM) {
28
+ const minimumMajor = Math.floor(minimum / 10000);
29
+ if (session.ServerVersionNum >= minimum) {
30
+ return MakeCheck('server-version', 'pass', `PostgreSQL ${session.ServerVersion} (${minimumMajor} or later required)`);
31
+ }
32
+ return MakeCheck('server-version', 'fail', `PostgreSQL ${session.ServerVersion} is older than ${minimumMajor}, the lowest version MJ supports`, [], [
33
+ `Upgrade the server to PostgreSQL ${minimumMajor} or later.`,
34
+ ]);
35
+ }
36
+ /** Every group role the migrations grant to must exist. */
37
+ export async function CheckGroupRoles(runner, session, roles) {
38
+ if (roles.length === 0) {
39
+ return MakeCheck('group-roles', 'pass', 'The pending migrations grant to no MJ group role');
40
+ }
41
+ const rows = await runner.Query('SELECT rolname FROM pg_catalog.pg_roles WHERE rolname = ANY($1::text[])', [[...roles]]);
42
+ const present = new Set(rows.map((r) => r.rolname));
43
+ const missing = roles.filter((role) => !present.has(role));
44
+ if (missing.length === 0) {
45
+ return MakeCheck('group-roles', 'pass', `Group roles exist: ${roles.join(', ')}`);
46
+ }
47
+ return MakeCheck('group-roles', 'fail', `Missing group role(s) the migrations grant to: ${missing.join(', ')}`, RoleRemediation(session, missing));
48
+ }
49
+ /** The migrate login needs CREATE on the database: Skyway runs `CREATE SCHEMA IF NOT EXISTS`, which checks it even when the schema exists. */
50
+ export function CheckDatabaseCreate(session) {
51
+ if (session.CanCreateInDatabase) {
52
+ return MakeCheck('database-create', 'pass', `${session.Login} has CREATE on database ${session.Database}`);
53
+ }
54
+ return MakeCheck('database-create', 'fail', `${session.Login} lacks CREATE on database ${session.Database} (needed to create schemas and trusted extensions)`, DatabaseCreateRemediation(session));
55
+ }
56
+ /** The target schema must be owned by the migrate login, or not exist yet. */
57
+ export async function CheckTargetSchema(runner, session, schema) {
58
+ const rows = await runner.Query(`SELECT pg_catalog.pg_get_userbyid(nspowner) AS "Owner", pg_catalog.pg_has_role(current_user, nspowner, 'USAGE') AS "Owned"
59
+ FROM pg_catalog.pg_namespace WHERE nspname = $1`, [schema]);
60
+ if (rows.length === 0) {
61
+ return MakeCheck('target-schema', 'info', `Schema ${schema} does not exist yet; the migration creates it, owned by ${session.Login}`);
62
+ }
63
+ if (rows[0].Owned) {
64
+ return MakeCheck('target-schema', 'pass', `Schema ${schema} is owned by ${rows[0].Owner}, which ${session.Login} is or belongs to`);
65
+ }
66
+ return MakeCheck('target-schema', 'fail', `Schema ${schema} is owned by ${rows[0].Owner}, not ${session.Login}, so the migrations cannot alter its objects`, SchemaOwnerRemediation(session, schema));
67
+ }
68
+ /** TLS for the current backend. Never fails: a warning (info on a loopback host). */
69
+ export async function CheckTls(runner, host) {
70
+ const rows = await runner.Query('SELECT ssl, version FROM pg_catalog.pg_stat_ssl WHERE pid = pg_catalog.pg_backend_pid()');
71
+ if (rows[0]?.ssl) {
72
+ return MakeCheck('tls', 'pass', `The connection uses TLS (${rows[0].version ?? 'unknown version'})`);
73
+ }
74
+ if (IsLoopbackHost(host)) {
75
+ return MakeCheck('tls', 'info', 'The connection does not use TLS (expected for a local server)');
76
+ }
77
+ return MakeCheck('tls', 'warn', 'The connection does not use TLS; a managed host should require it');
78
+ }
79
+ /** True for localhost and the loopback addresses. */
80
+ export function IsLoopbackHost(host) {
81
+ const h = (host ?? '').trim().toLowerCase();
82
+ return h === 'localhost' || h === '::1' || h === '[::1]' || h.startsWith('127.');
83
+ }
84
+ /** Reports `max_connections` and current use. Informational only. */
85
+ export async function CheckConnections(runner) {
86
+ const rows = await runner.Query(`SELECT current_setting('max_connections')::int AS "Max",
87
+ current_setting('superuser_reserved_connections')::int AS "Reserved",
88
+ (SELECT count(*) FROM pg_catalog.pg_stat_activity)::int AS "InUse"`);
89
+ const row = rows[0];
90
+ if (!row)
91
+ return MakeCheck('connections', 'info', 'Could not read max_connections');
92
+ return MakeCheck('connections', 'info', `max_connections=${row.Max} (${row.Reserved} reserved for superusers), ${row.InUse} in use`);
93
+ }
94
+ //# sourceMappingURL=checks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checks.js","sourceRoot":"","sources":["../../../src/lib/pg-preflight/checks.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,yBAAyB,EA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EAAE,+DAA+D,CAAC,CAAC;IACnG,CAAC;IACD,OAAO,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,mEAAmE,CAAC,CAAC;AACvG,CAAC;AAED,qDAAqD;AACrD,MAAM,UAAU,cAAc,CAAC,IAAwB;IACrD,MAAM,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC5C,OAAO,CAAC,KAAK,WAAW,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,OAAO,IAAI,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AACnF,CAAC;AAED,qEAAqE;AACrE,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,MAA8B;IACnE,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,KAAK,CAC7B;;+EAE2E,CAC5E,CAAC;IACF,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,IAAI,CAAC,GAAG;QAAE,OAAO,SAAS,CAAC,aAAa,EAAE,MAAM,EAAE,gCAAgC,CAAC,CAAC;IACpF,OAAO,SAAS,CAAC,aAAa,EAAE,MAAM,EAAE,mBAAmB,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,QAAQ,8BAA8B,GAAG,CAAC,KAAK,SAAS,CAAC,CAAC;AACvI,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The extension check: every extension a pending migration `CREATE`s must already be
3
+ * installed, or be creatable by the migrate login on this server.
4
+ *
5
+ * Managed hosts add one more gate. Azure Database for PostgreSQL Flexible Server and
6
+ * Azure HorizonDB refuse `CREATE EXTENSION` for anything missing from the
7
+ * `azure.extensions` server parameter, whatever the login's privileges, so the check
8
+ * reads that parameter whenever the server defines it.
9
+ *
10
+ * @module lib/pg-preflight/extension-check
11
+ */
12
+ import type { PgPreflightCheck, PgPreflightQueryRunner, PgSessionContext } from './types.js';
13
+ /** One required extension as the catalog describes it. */
14
+ export interface ExtensionCatalogRow {
15
+ Name: string;
16
+ InstalledVersion: string | null;
17
+ Trusted: boolean;
18
+ }
19
+ /** Why an extension blocks the migration. */
20
+ type ExtensionProblem = 'unavailable' | 'not-allowlisted' | 'needs-admin';
21
+ /** Splits the `azure.extensions` value; null when the server does not define the parameter. */
22
+ export declare function ParseAllowlist(value: string | null): string[] | null;
23
+ /** Classifies one required extension; null means it is fine. */
24
+ export declare function ClassifyExtension(name: string, row: ExtensionCatalogRow | undefined, allowlist: string[] | null, session: PgSessionContext): ExtensionProblem | null;
25
+ /** Runs the extension check. */
26
+ export declare function CheckExtensions(runner: PgPreflightQueryRunner, session: PgSessionContext, required: readonly string[]): Promise<PgPreflightCheck>;
27
+ export {};
28
+ //# sourceMappingURL=extension-check.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension-check.d.ts","sourceRoot":"","sources":["../../../src/lib/pg-preflight/extension-check.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,KAAK,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE1F,0DAA0D;AAC1D,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,6CAA6C;AAC7C,KAAK,gBAAgB,GAAG,aAAa,GAAG,iBAAiB,GAAG,aAAa,CAAC;AAe1E,+FAA+F;AAC/F,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,EAAE,GAAG,IAAI,CAMpE;AAED,gEAAgE;AAChE,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,mBAAmB,GAAG,SAAS,EACpC,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,EAC1B,OAAO,EAAE,gBAAgB,GACxB,gBAAgB,GAAG,IAAI,CAMzB;AAED,gCAAgC;AAChC,wBAAsB,eAAe,CAAC,MAAM,EAAE,sBAAsB,EAAE,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAcvJ"}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * The extension check: every extension a pending migration `CREATE`s must already be
3
+ * installed, or be creatable by the migrate login on this server.
4
+ *
5
+ * Managed hosts add one more gate. Azure Database for PostgreSQL Flexible Server and
6
+ * Azure HorizonDB refuse `CREATE EXTENSION` for anything missing from the
7
+ * `azure.extensions` server parameter, whatever the login's privileges, so the check
8
+ * reads that parameter whenever the server defines it.
9
+ *
10
+ * @module lib/pg-preflight/extension-check
11
+ */
12
+ import { MakeCheck } from './checks.js';
13
+ import { ExtensionRemediation } from './remediation.js';
14
+ /** Reads the catalog rows for the required extensions, and the Azure allowlist when defined. */
15
+ async function readExtensionState(runner, required) {
16
+ const rows = await runner.Query(`SELECT e.name AS "Name", e.installed_version AS "InstalledVersion", COALESCE(v.trusted, false) AS "Trusted"
17
+ FROM pg_catalog.pg_available_extensions e
18
+ LEFT JOIN pg_catalog.pg_available_extension_versions v ON v.name = e.name AND v.version = e.default_version
19
+ WHERE e.name = ANY($1::text[])`, [[...required]]);
20
+ const allow = await runner.Query(`SELECT current_setting('azure.extensions', true) AS "Allowlist"`);
21
+ return { Rows: rows, Allowlist: ParseAllowlist(allow[0]?.Allowlist ?? null) };
22
+ }
23
+ /** Splits the `azure.extensions` value; null when the server does not define the parameter. */
24
+ export function ParseAllowlist(value) {
25
+ if (value === null)
26
+ return null;
27
+ return value
28
+ .split(',')
29
+ .map((name) => name.trim().toLowerCase())
30
+ .filter((name) => name.length > 0);
31
+ }
32
+ /** Classifies one required extension; null means it is fine. */
33
+ export function ClassifyExtension(name, row, allowlist, session) {
34
+ if (row?.InstalledVersion)
35
+ return null;
36
+ if (!row)
37
+ return 'unavailable';
38
+ if (allowlist !== null && !allowlist.includes(name.toLowerCase()))
39
+ return 'not-allowlisted';
40
+ const canCreate = session.IsSuperuser || (row.Trusted && session.CanCreateInDatabase);
41
+ return canCreate ? null : 'needs-admin';
42
+ }
43
+ /** Runs the extension check. */
44
+ export async function CheckExtensions(runner, session, required) {
45
+ if (required.length === 0) {
46
+ return MakeCheck('extensions', 'pass', 'No pending migration creates an extension');
47
+ }
48
+ const state = await readExtensionState(runner, required);
49
+ const problems = new Map();
50
+ for (const name of required) {
51
+ const problem = ClassifyExtension(name, state.Rows.find((r) => r.Name === name), state.Allowlist, session);
52
+ if (problem)
53
+ problems.set(name, problem);
54
+ }
55
+ if (problems.size === 0) {
56
+ return MakeCheck('extensions', 'pass', `Extensions installed or creatable by ${session.Login}: ${required.join(', ')}`);
57
+ }
58
+ return buildFailure(session, problems, state.Allowlist);
59
+ }
60
+ /** The failed check, with SQL for what SQL can fix and notes for what it cannot. */
61
+ function buildFailure(session, problems, allowlist) {
62
+ const byProblem = (p) => [...problems].filter(([, v]) => v === p).map(([k]) => k);
63
+ const unavailable = byProblem('unavailable');
64
+ const notAllowlisted = byProblem('not-allowlisted');
65
+ const needsAdmin = byProblem('needs-admin');
66
+ const parts = [
67
+ unavailable.length ? `are not available on this server: ${unavailable.join(', ')}` : '',
68
+ notAllowlisted.length ? `are not in the azure.extensions allowlist: ${notAllowlisted.join(', ')}` : '',
69
+ needsAdmin.length ? `${session.Login} cannot create without an administrator: ${needsAdmin.join(', ')}` : '',
70
+ ].filter((p) => p.length > 0);
71
+ return MakeCheck('extensions', 'fail', `Pending migrations need extension(s) that ${parts.join('; ')}`, ExtensionRemediation(session, [...notAllowlisted, ...needsAdmin]), extensionNotes(unavailable, notAllowlisted, allowlist ?? []));
72
+ }
73
+ /** Non-SQL fixes: install packages, or extend the Azure allowlist. */
74
+ function extensionNotes(unavailable, notAllowlisted, allowlist) {
75
+ const notes = [];
76
+ if (unavailable.length > 0) {
77
+ notes.push(`Install the server package that provides ${unavailable.join(', ')}, or use a host that offers it.`);
78
+ }
79
+ if (notAllowlisted.length > 0) {
80
+ const merged = [...new Set([...allowlist, ...notAllowlisted.map((n) => n.toLowerCase())])].join(',');
81
+ notes.push(`Add ${notAllowlisted.join(', ')} to the azure.extensions server parameter before running the SQL below, for example: ` +
82
+ `az postgres flexible-server parameter set --resource-group <rg> --server-name <server> --name azure.extensions --value "${merged}"`);
83
+ }
84
+ return notes;
85
+ }
86
+ //# sourceMappingURL=extension-check.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension-check.js","sourceRoot":"","sources":["../../../src/lib/pg-preflight/extension-check.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAarD,gGAAgG;AAChG,KAAK,UAAU,kBAAkB,CAAC,MAA8B,EAAE,QAA2B;IAC3F,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,KAAK,CAC7B;;;qCAGiC,EACjC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAChB,CAAC;IACF,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,KAAK,CAA+B,iEAAiE,CAAC,CAAC;IAClI,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,SAAS,IAAI,IAAI,CAAC,EAAE,CAAC;AAChF,CAAC;AAED,+FAA+F;AAC/F,MAAM,UAAU,cAAc,CAAC,KAAoB;IACjD,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAChC,OAAO,KAAK;SACT,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;SACxC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG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AAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC9B,OAAO,SAAS,CACd,YAAY,EACZ,MAAM,EACN,6CAA6C,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAC/D,oBAAoB,CAAC,OAAO,EAAE,CAAC,GAAG,cAAc,EAAE,GAAG,UAAU,CAAC,CAAC,EACjE,cAAc,CAAC,WAAW,EAAE,cAAc,EAAE,SAAS,IAAI,EAAE,CAAC,CAC7D,CAAC;AACJ,CAAC;AAED,sEAAsE;AACtE,SAAS,cAAc,CAAC,WAAqB,EAAE,cAAwB,EAAE,SAAmB;IAC1F,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3B,KAAK,CAAC,IAAI,CAAC,4CAA4C,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;IAClH,CAAC;IACD,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC9B,MAAM,MAAM,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,SAAS,EAAE,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACrG,KAAK,CAAC,IAAI,CACR,OAAO,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,uFAAuF;YACrH,2HAA2H,MAAM,GAAG,CACvI,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Finds the PostgreSQL extensions a set of migration scripts will `CREATE`.
3
+ *
4
+ * @module lib/pg-preflight/extension-scan
5
+ */
6
+ /**
7
+ * Returns the extension names the scripts create, de-duplicated, in first-seen order.
8
+ * Quoted names keep their case; bare names fold to lower case, as PostgreSQL does.
9
+ *
10
+ * @param scripts - Migration SQL texts (placeholder substitution is not needed).
11
+ */
12
+ export declare function ExtractCreatedExtensions(scripts: Iterable<string>): string[];
13
+ /**
14
+ * Returns which of the candidate group roles the scripts reference (in a GRANT, an
15
+ * `ALTER DEFAULT PRIVILEGES … TO`, a policy, …), in candidate order. Only those must exist
16
+ * before the migrations run: requiring the installer's full list would fail databases that
17
+ * a set of migrations never grants to (no shipped migration references `cdp_BI` or
18
+ * `cdp_CodeGen`, for example).
19
+ *
20
+ * @param scripts - Migration SQL texts.
21
+ * @param candidates - The role names to look for (the installer's `POSTGRES_MJ_GROUP_ROLES`).
22
+ */
23
+ export declare function ExtractReferencedRoles(scripts: Iterable<string>, candidates: readonly string[]): string[];
24
+ //# sourceMappingURL=extension-scan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension-scan.d.ts","sourceRoot":"","sources":["../../../src/lib/pg-preflight/extension-scan.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAYH;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,CAQ5E;AAaD;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAGzG"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Finds the PostgreSQL extensions a set of migration scripts will `CREATE`.
3
+ *
4
+ * @module lib/pg-preflight/extension-scan
5
+ */
6
+ /**
7
+ * `CREATE EXTENSION [IF NOT EXISTS] name`, where the name is a quoted identifier or a bare one.
8
+ * Group 1 is a quoted name (with `""` escapes), group 2 a bare name.
9
+ */
10
+ const CREATE_EXTENSION_PATTERN = /\bCREATE\s+EXTENSION\s+(?:IF\s+NOT\s+EXISTS\s+)?(?:"((?:[^"]|"")+)"|([A-Za-z_][A-Za-z0-9_$-]*))/gi;
11
+ /** Line comments and block comments, removed before scanning so commented-out statements don't count. */
12
+ const LINE_COMMENT_PATTERN = /--[^\n]*/g;
13
+ const BLOCK_COMMENT_PATTERN = /\/\*[\s\S]*?\*\//g;
14
+ /**
15
+ * Returns the extension names the scripts create, de-duplicated, in first-seen order.
16
+ * Quoted names keep their case; bare names fold to lower case, as PostgreSQL does.
17
+ *
18
+ * @param scripts - Migration SQL texts (placeholder substitution is not needed).
19
+ */
20
+ export function ExtractCreatedExtensions(scripts) {
21
+ const found = new Set();
22
+ for (const script of scripts) {
23
+ for (const name of extensionsInScript(script)) {
24
+ found.add(name);
25
+ }
26
+ }
27
+ return [...found];
28
+ }
29
+ /** The extension names one script creates, in order of appearance. */
30
+ function extensionsInScript(script) {
31
+ const code = script.replace(BLOCK_COMMENT_PATTERN, ' ').replace(LINE_COMMENT_PATTERN, ' ');
32
+ const names = [];
33
+ for (const match of code.matchAll(CREATE_EXTENSION_PATTERN)) {
34
+ const quoted = match[1];
35
+ names.push(quoted !== undefined ? quoted.replace(/""/g, '"') : match[2].toLowerCase());
36
+ }
37
+ return names;
38
+ }
39
+ /**
40
+ * Returns which of the candidate group roles the scripts reference (in a GRANT, an
41
+ * `ALTER DEFAULT PRIVILEGES … TO`, a policy, …), in candidate order. Only those must exist
42
+ * before the migrations run: requiring the installer's full list would fail databases that
43
+ * a set of migrations never grants to (no shipped migration references `cdp_BI` or
44
+ * `cdp_CodeGen`, for example).
45
+ *
46
+ * @param scripts - Migration SQL texts.
47
+ * @param candidates - The role names to look for (the installer's `POSTGRES_MJ_GROUP_ROLES`).
48
+ */
49
+ export function ExtractReferencedRoles(scripts, candidates) {
50
+ const code = [...scripts].map((s) => s.replace(BLOCK_COMMENT_PATTERN, ' ').replace(LINE_COMMENT_PATTERN, ' ')).join('\n');
51
+ return candidates.filter((role) => roleReferencePattern(role).test(code));
52
+ }
53
+ /** Matches a role name quoted (`"cdp_UI"`) or bare, as a whole identifier. */
54
+ function roleReferencePattern(role) {
55
+ const escaped = role.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
56
+ return new RegExp(`"${escaped}"|(?<![A-Za-z0-9_$"])${escaped}(?![A-Za-z0-9_$"])`, 'i');
57
+ }
58
+ //# sourceMappingURL=extension-scan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension-scan.js","sourceRoot":"","sources":["../../../src/lib/pg-preflight/extension-scan.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,MAAM,wBAAwB,GAAG,mGAAmG,CAAC;AAErI,yGAAyG;AACzG,MAAM,oBAAoB,GAAG,WAAW,CAAC;AACzC,MAAM,qBAAqB,GAAG,mBAAmB,CAAC;AAElD;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAAC,OAAyB;IAChE,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,KAAK,MAAM,IAAI,IAAI,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC;YAC9C,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IACD,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC;AACpB,CAAC;AAED,sEAAsE;AACtE,SAAS,kBAAkB,CAAC,MAAc;IACxC,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC;IAC3F,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,wBAAwB,CAAC,EAAE,CAAC;QAC5D,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACxB,KAAK,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;IACzF,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAyB,EAAE,UAA6B;IAC7F,MAAM,IAAI,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1H,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AAC5E,CAAC;AAED,8EAA8E;AAC9E,SAAS,oBAAoB,CAAC,IAAY;IACxC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;IAC5D,OAAO,IAAI,MAAM,CAAC,IAAI,OAAO,wBAAwB,OAAO,oBAAoB,EAAE,GAAG,CAAC,CAAC;AACzF,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Reads the SQL of the migrations `mj migrate` would apply, so the preflight checks
3
+ * exactly the extensions those migrations create (and not, say, every extension any
4
+ * historical migration ever created).
5
+ *
6
+ * @module lib/pg-preflight/pending-migrations
7
+ */
8
+ import { type SkywayConfig } from '@memberjunction/skyway-core';
9
+ /**
10
+ * The SQL of every migration Skyway would run against this database. Out-of-order files
11
+ * are included, because `mj migrate` may enable `outOfOrder` for the run.
12
+ *
13
+ * SIDE EFFECTS: connects with `skywayConfig.Provider` to read the history table, then
14
+ * disconnects. Pass a probe config, not the one the migration will use.
15
+ */
16
+ export declare function ReadPendingMigrationSql(skywayConfig: SkywayConfig): Promise<string[]>;
17
+ /** The extensions the pending migrations create. */
18
+ export declare function ReadPendingExtensions(skywayConfig: SkywayConfig): Promise<string[]>;
19
+ /** What the pending migrations need from the database before they run. */
20
+ export interface PendingMigrationRequirements {
21
+ /** Extensions the pending migrations `CREATE`. */
22
+ Extensions: string[];
23
+ /** The installer's group roles that the pending migrations reference. */
24
+ Roles: string[];
25
+ }
26
+ /** Reads the pending migrations once and returns both the extensions and the group roles they need. */
27
+ export declare function ReadPendingRequirements(skywayConfig: SkywayConfig): Promise<PendingMigrationRequirements>;
28
+ //# sourceMappingURL=pending-migrations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pending-migrations.d.ts","sourceRoot":"","sources":["../../../src/lib/pg-preflight/pending-migrations.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAA+C,KAAK,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAQ7G;;;;;;GAMG;AACH,wBAAsB,uBAAuB,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAe3F;AAED,oDAAoD;AACpD,wBAAsB,qBAAqB,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAEzF;AAED,0EAA0E;AAC1E,MAAM,WAAW,4BAA4B;IAC3C,kDAAkD;IAClD,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,yEAAyE;IACzE,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,uGAAuG;AACvG,wBAAsB,uBAAuB,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAG/G"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Reads the SQL of the migrations `mj migrate` would apply, so the preflight checks
3
+ * exactly the extensions those migrations create (and not, say, every extension any
4
+ * historical migration ever created).
5
+ *
6
+ * @module lib/pg-preflight/pending-migrations
7
+ */
8
+ import { ResolveMigrations, ScanAndResolveMigrations } from '@memberjunction/skyway-core';
9
+ import { POSTGRES_MJ_GROUP_ROLES } from '@memberjunction/installer';
10
+ import { ExtractCreatedExtensions, ExtractReferencedRoles } from './extension-scan.js';
11
+ /** Skyway's defaults for the values `mj migrate` leaves unset (`ResolveConfig` in skyway-core). */
12
+ const DEFAULT_HISTORY_TABLE = 'flyway_schema_history';
13
+ const DEFAULT_BASELINE_VERSION = '1';
14
+ /**
15
+ * The SQL of every migration Skyway would run against this database. Out-of-order files
16
+ * are included, because `mj migrate` may enable `outOfOrder` for the run.
17
+ *
18
+ * SIDE EFFECTS: connects with `skywayConfig.Provider` to read the history table, then
19
+ * disconnects. Pass a probe config, not the one the migration will use.
20
+ */
21
+ export async function ReadPendingMigrationSql(skywayConfig) {
22
+ const provider = skywayConfig.Provider;
23
+ if (!provider)
24
+ throw new Error('The Skyway config has no database provider.');
25
+ const migrations = skywayConfig.Migrations;
26
+ const schema = migrations.DefaultSchema ?? 'public';
27
+ const historyTable = migrations.HistoryTable ?? DEFAULT_HISTORY_TABLE;
28
+ await provider.Connect();
29
+ try {
30
+ const discovered = await ScanAndResolveMigrations(migrations.Locations);
31
+ const applied = (await provider.History.Exists(schema, historyTable)) ? await provider.History.GetAllRecords(schema, historyTable) : [];
32
+ const resolution = ResolveMigrations(discovered, applied, migrations.BaselineVersion ?? DEFAULT_BASELINE_VERSION, migrations.BaselineOnMigrate ?? false, true);
33
+ return resolution.PendingMigrations.map((m) => m.SQL);
34
+ }
35
+ finally {
36
+ await provider.Disconnect();
37
+ }
38
+ }
39
+ /** The extensions the pending migrations create. */
40
+ export async function ReadPendingExtensions(skywayConfig) {
41
+ return ExtractCreatedExtensions(await ReadPendingMigrationSql(skywayConfig));
42
+ }
43
+ /** Reads the pending migrations once and returns both the extensions and the group roles they need. */
44
+ export async function ReadPendingRequirements(skywayConfig) {
45
+ const scripts = await ReadPendingMigrationSql(skywayConfig);
46
+ return { Extensions: ExtractCreatedExtensions(scripts), Roles: ExtractReferencedRoles(scripts, POSTGRES_MJ_GROUP_ROLES) };
47
+ }
48
+ //# sourceMappingURL=pending-migrations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pending-migrations.js","sourceRoot":"","sources":["../../../src/lib/pg-preflight/pending-migrations.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,iBAAiB,EAAE,wBAAwB,EAAqB,MAAM,6BAA6B,CAAC;AAC7G,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAEpF,mGAAmG;AACnG,MAAM,qBAAqB,GAAG,uBAAuB,CAAC;AACtD,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAErC;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,YAA0B;IACtE,MAAM,QAAQ,GAAG,YAAY,CAAC,QAAQ,CAAC;IACvC,IAAI,CAAC,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IAC9E,MAAM,UAAU,GAAG,YAAY,CAAC,UAAU,CAAC;IAC3C,MAAM,MAAM,GAAG,UAAU,CAAC,aAAa,IAAI,QAAQ,CAAC;IACpD,MAAM,YAAY,GAAG,UAAU,CAAC,YAAY,IAAI,qBAAqB,CAAC;IACtE,MAAM,QAAQ,CAAC,OAAO,EAAE,CAAC;IACzB,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,MAAM,wBAAwB,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;QACxE,MAAM,OAAO,GAAG,CAAC,MAAM,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACxI,MAAM,UAAU,GAAG,iBAAiB,CAAC,UAAU,EAAE,OAAO,EAAE,UAAU,CAAC,eAAe,IAAI,wBAAwB,EAAE,UAAU,CAAC,iBAAiB,IAAI,KAAK,EAAE,IAAI,CAAC,CAAC;QAC/J,OAAO,UAAU,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACxD,CAAC;YAAS,CAAC;QACT,MAAM,QAAQ,CAAC,UAAU,EAAE,CAAC;IAC9B,CAAC;AACH,CAAC;AAED,oDAAoD;AACpD,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,YAA0B;IACpE,OAAO,wBAAwB,CAAC,MAAM,uBAAuB,CAAC,YAAY,CAAC,CAAC,CAAC;AAC/E,CAAC;AAUD,uGAAuG;AACvG,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,YAA0B;IACtE,MAAM,OAAO,GAAG,MAAM,uBAAuB,CAAC,YAAY,CAAC,CAAC;IAC5D,OAAO,EAAE,UAAU,EAAE,wBAAwB,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,sBAAsB,CAAC,OAAO,EAAE,uBAAuB,CAAC,EAAE,CAAC;AAC5H,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Managed-PostgreSQL preflight: checks that a database is ready for `mj migrate` before
3
+ * the first migration runs, and says exactly what an administrator must run when it is
4
+ * not. Without it, a pre-provisioned managed database fails partway through the baseline
5
+ * with a GRANT or `CREATE EXTENSION` error.
6
+ *
7
+ * @module lib/pg-preflight/preflight
8
+ */
9
+ import type { PgPreflightOptions, PgPreflightQueryRunner, PgPreflightReport } from './types.js';
10
+ /**
11
+ * Runs every check against an open session. A check whose query throws reports `warn`
12
+ * rather than aborting the rest, except the session query every check needs, which throws.
13
+ *
14
+ * @param runner - Connected as the login `mj migrate` uses.
15
+ * @param options - Target schema, the extensions pending migrations create, and so on.
16
+ */
17
+ export declare function RunPgManagedPreflight(runner: PgPreflightQueryRunner, options: PgPreflightOptions): Promise<PgPreflightReport>;
18
+ //# sourceMappingURL=preflight.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preflight.d.ts","sourceRoot":"","sources":["../../../src/lib/pg-preflight/preflight.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAcH,OAAO,KAAK,EAAwC,kBAAkB,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEnI;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,sBAAsB,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAanI"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Managed-PostgreSQL preflight: checks that a database is ready for `mj migrate` before
3
+ * the first migration runs, and says exactly what an administrator must run when it is
4
+ * not. Without it, a pre-provisioned managed database fails partway through the baseline
5
+ * with a GRANT or `CREATE EXTENSION` error.
6
+ *
7
+ * @module lib/pg-preflight/preflight
8
+ */
9
+ import { POSTGRES_MJ_GROUP_ROLES } from '@memberjunction/installer';
10
+ import { CheckConnections, CheckDatabaseCreate, CheckGroupRoles, CheckServerVersion, CheckTargetSchema, CheckTls, MakeCheck, ReadSessionContext, } from './checks.js';
11
+ import { CheckExtensions } from './extension-check.js';
12
+ /**
13
+ * Runs every check against an open session. A check whose query throws reports `warn`
14
+ * rather than aborting the rest, except the session query every check needs, which throws.
15
+ *
16
+ * @param runner - Connected as the login `mj migrate` uses.
17
+ * @param options - Target schema, the extensions pending migrations create, and so on.
18
+ */
19
+ export async function RunPgManagedPreflight(runner, options) {
20
+ const session = await ReadSessionContext(runner);
21
+ const roles = options.RequiredRoles ?? POSTGRES_MJ_GROUP_ROLES;
22
+ const checks = [
23
+ CheckServerVersion(session, options.MinimumServerVersionNum),
24
+ await guarded('group-roles', () => CheckGroupRoles(runner, session, roles)),
25
+ CheckDatabaseCreate(session),
26
+ await guarded('target-schema', () => CheckTargetSchema(runner, session, options.TargetSchema)),
27
+ await guarded('extensions', () => CheckExtensions(runner, session, options.RequiredExtensions)),
28
+ await guarded('tls', () => CheckTls(runner, options.Host)),
29
+ await guarded('connections', () => CheckConnections(runner)),
30
+ ];
31
+ return { Session: session, TargetSchema: options.TargetSchema, Checks: checks, Passed: !checks.some((c) => c.Status === 'fail') };
32
+ }
33
+ /** Runs one check, turning a query error into a warning that names the check. */
34
+ async function guarded(id, run) {
35
+ try {
36
+ return await run();
37
+ }
38
+ catch (err) {
39
+ const message = err instanceof Error ? err.message : String(err);
40
+ return MakeCheck(id, 'warn', `Could not run the ${id} check: ${message}`);
41
+ }
42
+ }
43
+ //# sourceMappingURL=preflight.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preflight.js","sourceRoot":"","sources":["../../../src/lib/pg-preflight/preflight.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,QAAQ,EACR,SAAS,EACT,kBAAkB,GACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,MAA8B,EAAE,OAA2B;IACrG,MAAM,OAAO,GAAG,MAAM,kBAAkB,CAAC,MAAM,CAAC,CAAC;IACjD,MAAM,KAAK,GAAG,OAAO,CAAC,aAAa,IAAI,uBAAuB,CAAC;IAC/D,MAAM,MAAM,GAAuB;QACjC,kBAAkB,CAAC,OAAO,EAAE,OAAO,CAAC,uBAAuB,CAAC;QAC5D,MAAM,OAAO,CAAC,aAAa,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QAC3E,mBAAmB,CAAC,OAAO,CAAC;QAC5B,MAAM,OAAO,CAAC,eAAe,EAAE,GAAG,EAAE,CAAC,iBAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;QAC9F,MAAM,OAAO,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;QAC/F,MAAM,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;QAC1D,MAAM,OAAO,CAAC,aAAa,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;KAC7D,CAAC;IACF,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,EAAE,CAAC;AACpI,CAAC;AAED,iFAAiF;AACjF,KAAK,UAAU,OAAO,CAAC,EAAsB,EAAE,GAAoC;IACjF,IAAI,CAAC;QACH,OAAO,MAAM,GAAG,EAAE,CAAC;IACrB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACjE,OAAO,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,qBAAqB,EAAE,WAAW,OAAO,EAAE,CAAC,CAAC;IAC5E,CAAC;AACH,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The SQL an administrator runs to fix a failed preflight check.
3
+ *
4
+ * Every statement is taken from the installer's own step builder
5
+ * (`BuildPostgresSetupSteps` in `@memberjunction/installer`) when the installer has
6
+ * one for it, so `mj migrate` and `mj install` can never tell an administrator two
7
+ * different things. A statement is built here only when the installer has no step for
8
+ * it (an Open App schema, an extension outside `POSTGRES_MJ_EXTENSIONS`), and then
9
+ * with the installer's own quoting helper.
10
+ *
11
+ * @module lib/pg-preflight/remediation
12
+ */
13
+ import type { PgPreflightReport, PgRemediationStep, PgSessionContext } from './types.js';
14
+ /** `CREATE ROLE ... NOLOGIN` for each missing group role. */
15
+ export declare function RoleRemediation(session: PgSessionContext, missingRoles: readonly string[]): PgRemediationStep[];
16
+ /** `CREATE EXTENSION IF NOT EXISTS` for each extension. */
17
+ export declare function ExtensionRemediation(session: PgSessionContext, extensions: readonly string[]): PgRemediationStep[];
18
+ /** `GRANT CONNECT, CREATE, TEMPORARY ON DATABASE` to the migrate login. */
19
+ export declare function DatabaseCreateRemediation(session: PgSessionContext): PgRemediationStep[];
20
+ /** `ALTER SCHEMA ... OWNER TO` the migrate login. */
21
+ export declare function SchemaOwnerRemediation(session: PgSessionContext, schema: string): PgRemediationStep[];
22
+ /**
23
+ * Renders every failed check's remediation as one script an administrator can paste
24
+ * into psql or any SQL client. Returns an empty string when nothing needs fixing.
25
+ */
26
+ export declare function RenderRemediationScript(report: PgPreflightReport): string;
27
+ //# sourceMappingURL=remediation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remediation.d.ts","sourceRoot":"","sources":["../../../src/lib/pg-preflight/remediation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAatF,6DAA6D;AAC7D,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,SAAS,MAAM,EAAE,GAAG,iBAAiB,EAAE,CAQ/G;AAED,2DAA2D;AAC3D,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,iBAAiB,EAAE,CAMlH;AAED,2EAA2E;AAC3E,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,gBAAgB,GAAG,iBAAiB,EAAE,CAUxF;AAED,qDAAqD;AACrD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,GAAG,iBAAiB,EAAE,CAGrG;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAUzE"}