@automattic/vip 4.1.6 → 4.1.8

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 (311) hide show
  1. package/assets/dev-env.lando.template.yml.ejs +1 -1
  2. package/dist/bin/vip-app-deploy-token-generate.js +110 -78
  3. package/dist/bin/vip-app-deploy-token.js +24 -16
  4. package/dist/bin/vip-app-deploy-validate.js +45 -41
  5. package/dist/bin/vip-app-deploy.js +222 -215
  6. package/dist/bin/vip-app-list.js +59 -43
  7. package/dist/bin/vip-app.js +97 -66
  8. package/dist/bin/vip-backup-db.js +36 -29
  9. package/dist/bin/vip-backup.js +16 -9
  10. package/dist/bin/vip-cache-purge-url.js +93 -55
  11. package/dist/bin/vip-cache.js +23 -14
  12. package/dist/bin/vip-config-envvar-delete.js +74 -73
  13. package/dist/bin/vip-config-envvar-get-all.js +68 -68
  14. package/dist/bin/vip-config-envvar-get.js +46 -46
  15. package/dist/bin/vip-config-envvar-list.js +54 -57
  16. package/dist/bin/vip-config-envvar-set.js +102 -96
  17. package/dist/bin/vip-config-envvar.js +38 -24
  18. package/dist/bin/vip-config-software-get.js +88 -75
  19. package/dist/bin/vip-config-software-update.js +116 -120
  20. package/dist/bin/vip-config-software.js +31 -21
  21. package/dist/bin/vip-config.js +25 -17
  22. package/dist/bin/vip-db-phpmyadmin.js +40 -39
  23. package/dist/bin/vip-db.js +13 -12
  24. package/dist/bin/vip-defensive-mode-configure.js +197 -197
  25. package/dist/bin/vip-defensive-mode-disable.js +43 -35
  26. package/dist/bin/vip-defensive-mode-enable.js +47 -38
  27. package/dist/bin/vip-defensive-mode.js +28 -17
  28. package/dist/bin/vip-dev-env-create.js +147 -104
  29. package/dist/bin/vip-dev-env-destroy.js +48 -39
  30. package/dist/bin/vip-dev-env-envvar-delete.js +60 -49
  31. package/dist/bin/vip-dev-env-envvar-get-all.js +52 -45
  32. package/dist/bin/vip-dev-env-envvar-get.js +48 -37
  33. package/dist/bin/vip-dev-env-envvar-list.js +48 -41
  34. package/dist/bin/vip-dev-env-envvar-set.js +83 -70
  35. package/dist/bin/vip-dev-env-envvar.js +38 -23
  36. package/dist/bin/vip-dev-env-exec.js +81 -74
  37. package/dist/bin/vip-dev-env-import-media.js +34 -26
  38. package/dist/bin/vip-dev-env-import-sql.js +65 -51
  39. package/dist/bin/vip-dev-env-import.js +23 -14
  40. package/dist/bin/vip-dev-env-info.js +59 -50
  41. package/dist/bin/vip-dev-env-list.js +34 -31
  42. package/dist/bin/vip-dev-env-logs.js +59 -49
  43. package/dist/bin/vip-dev-env-purge.js +71 -63
  44. package/dist/bin/vip-dev-env-shell.js +82 -71
  45. package/dist/bin/vip-dev-env-start.js +77 -65
  46. package/dist/bin/vip-dev-env-stop.js +80 -74
  47. package/dist/bin/vip-dev-env-sync-sql.js +80 -72
  48. package/dist/bin/vip-dev-env-sync.js +18 -11
  49. package/dist/bin/vip-dev-env-update.js +93 -84
  50. package/dist/bin/vip-dev-env.js +25 -8
  51. package/dist/bin/vip-edge-workers-build.js +82 -54
  52. package/dist/bin/vip-edge-workers-delete.js +84 -52
  53. package/dist/bin/vip-edge-workers-deploy.js +186 -126
  54. package/dist/bin/vip-edge-workers-disable.js +75 -44
  55. package/dist/bin/vip-edge-workers-enable.js +86 -54
  56. package/dist/bin/vip-edge-workers-get.js +108 -88
  57. package/dist/bin/vip-edge-workers-init.js +83 -53
  58. package/dist/bin/vip-edge-workers-list.js +89 -54
  59. package/dist/bin/vip-edge-workers-new.js +98 -69
  60. package/dist/bin/vip-edge-workers-validate.js +123 -82
  61. package/dist/bin/vip-edge-workers.js +19 -6
  62. package/dist/bin/vip-export-sql.js +75 -69
  63. package/dist/bin/vip-export.js +12 -7
  64. package/dist/bin/vip-import-media-abort.js +99 -73
  65. package/dist/bin/vip-import-media-status.js +83 -51
  66. package/dist/bin/vip-import-media.js +165 -166
  67. package/dist/bin/vip-import-sql-status.js +75 -45
  68. package/dist/bin/vip-import-sql.js +536 -596
  69. package/dist/bin/vip-import-validate-files.js +122 -141
  70. package/dist/bin/vip-import-validate-sql.js +52 -16
  71. package/dist/bin/vip-import.js +16 -7
  72. package/dist/bin/vip-logout.js +17 -13
  73. package/dist/bin/vip-logs.js +209 -183
  74. package/dist/bin/vip-search-replace.js +85 -53
  75. package/dist/bin/vip-slowlogs.js +168 -147
  76. package/dist/bin/vip-sync.js +163 -133
  77. package/dist/bin/vip-whoami.js +71 -35
  78. package/dist/bin/vip-wp.js +506 -549
  79. package/dist/bin/vip.js +161 -116
  80. package/dist/commands/backup-db.js +183 -149
  81. package/dist/commands/dev-env-import-sql.js +162 -117
  82. package/dist/commands/dev-env-sync-sql.js +372 -330
  83. package/dist/commands/export-sql.js +441 -425
  84. package/dist/commands/phpmyadmin.js +232 -212
  85. package/dist/commands/wp-ssh.js +218 -187
  86. package/dist/lib/analytics/clients/tracks.js +84 -91
  87. package/dist/lib/analytics/index.js +27 -27
  88. package/dist/lib/api/app.js +37 -36
  89. package/dist/lib/api/cache-purge.js +17 -20
  90. package/dist/lib/api/constants.js +5 -6
  91. package/dist/lib/api/edge-workers.js +84 -135
  92. package/dist/lib/api/error-debug.js +10 -13
  93. package/dist/lib/api/feature-flags.js +16 -17
  94. package/dist/lib/api/http.js +47 -48
  95. package/dist/lib/api/user.js +17 -18
  96. package/dist/lib/api.js +107 -116
  97. package/dist/lib/app-logs/app-logs.js +24 -25
  98. package/dist/lib/app-slowlogs/app-slowlogs.js +23 -24
  99. package/dist/lib/app-slowlogs/types.js +2 -1
  100. package/dist/lib/app.js +6 -8
  101. package/dist/lib/backup-storage-availability/backup-storage-availability.js +119 -119
  102. package/dist/lib/backup-storage-availability/docker-machine-not-found-error.js +5 -6
  103. package/dist/lib/cli/apiConfig.js +71 -41
  104. package/dist/lib/cli/command.js +1120 -873
  105. package/dist/lib/cli/config.js +29 -29
  106. package/dist/lib/cli/envAlias.js +35 -50
  107. package/dist/lib/cli/exit.js +19 -19
  108. package/dist/lib/cli/format.js +172 -172
  109. package/dist/lib/cli/progress.js +193 -236
  110. package/dist/lib/cli/prompt.js +14 -15
  111. package/dist/lib/cli/runtime-mode.js +5 -6
  112. package/dist/lib/client-file-uploader.js +489 -641
  113. package/dist/lib/config/software.js +206 -212
  114. package/dist/lib/constants/dev-environment.js +40 -37
  115. package/dist/lib/constants/file-size.js +6 -7
  116. package/dist/lib/constants/vipgo.js +24 -12
  117. package/dist/lib/custom-deploy/custom-deploy.js +138 -120
  118. package/dist/lib/database.js +88 -85
  119. package/dist/lib/defensive-mode/api.js +41 -46
  120. package/dist/lib/defensive-mode/cli-helpers.js +40 -40
  121. package/dist/lib/dev-environment/dev-environment-cli.js +776 -735
  122. package/dist/lib/dev-environment/dev-environment-configuration-file.js +224 -191
  123. package/dist/lib/dev-environment/dev-environment-core.js +697 -732
  124. package/dist/lib/dev-environment/dev-environment-database.js +57 -41
  125. package/dist/lib/dev-environment/dev-environment-lando.js +734 -666
  126. package/dist/lib/dev-environment/docker-utils.js +96 -90
  127. package/dist/lib/dev-environment/env-vars.js +61 -59
  128. package/dist/lib/dev-environment/lando-loader.js +6 -7
  129. package/dist/lib/dev-environment/types.js +2 -1
  130. package/dist/lib/edge-workers/confirmation.js +42 -36
  131. package/dist/lib/edge-workers/deployment.js +150 -159
  132. package/dist/lib/edge-workers/index.js +68 -85
  133. package/dist/lib/edge-workers/location.js +26 -26
  134. package/dist/lib/edge-workers/output.js +14 -15
  135. package/dist/lib/edge-workers/project.js +123 -132
  136. package/dist/lib/edge-workers/toolchains/assemblyscript/constants.js +6 -8
  137. package/dist/lib/edge-workers/toolchains/assemblyscript/index.js +100 -101
  138. package/dist/lib/edge-workers/toolchains/assemblyscript/templates.js +31 -33
  139. package/dist/lib/edge-workers/toolchains/index.js +15 -15
  140. package/dist/lib/edge-workers/types.js +10 -38
  141. package/dist/lib/edge-workers/validation.js +161 -150
  142. package/dist/lib/env.js +16 -17
  143. package/dist/lib/envvar/api-delete.js +16 -18
  144. package/dist/lib/envvar/api-get-all.js +15 -19
  145. package/dist/lib/envvar/api-get.js +8 -9
  146. package/dist/lib/envvar/api-list.js +16 -21
  147. package/dist/lib/envvar/api-set.js +20 -19
  148. package/dist/lib/envvar/api.js +34 -29
  149. package/dist/lib/envvar/input.js +29 -34
  150. package/dist/lib/envvar/logging.js +9 -11
  151. package/dist/lib/envvar/read-file.js +6 -7
  152. package/dist/lib/http/download-file.js +76 -44
  153. package/dist/lib/http/proxy-agent.js +37 -40
  154. package/dist/lib/http/proxy-dispatcher.js +69 -71
  155. package/dist/lib/keychain/insecure.js +40 -36
  156. package/dist/lib/keychain/keychain.js +2 -1
  157. package/dist/lib/keychain/secure.js +16 -15
  158. package/dist/lib/keychain.js +22 -22
  159. package/dist/lib/live-backup-copy.js +117 -115
  160. package/dist/lib/logout.js +17 -19
  161. package/dist/lib/media-import/config.js +15 -14
  162. package/dist/lib/media-import/media-file-import.js +9 -13
  163. package/dist/lib/media-import/progress.js +53 -65
  164. package/dist/lib/media-import/status.js +241 -256
  165. package/dist/lib/media-import/utils.js +15 -15
  166. package/dist/lib/node-version-check.js +16 -16
  167. package/dist/lib/promise.js +16 -17
  168. package/dist/lib/read-file.js +48 -16
  169. package/dist/lib/rechallenge/client.js +37 -43
  170. package/dist/lib/rechallenge/errors.js +38 -37
  171. package/dist/lib/rechallenge/flow.js +148 -123
  172. package/dist/lib/rechallenge/index.js +23 -24
  173. package/dist/lib/rechallenge/link.js +153 -151
  174. package/dist/lib/rechallenge/open-browser.js +14 -17
  175. package/dist/lib/rechallenge/token-cache.js +83 -86
  176. package/dist/lib/rechallenge/types.js +5 -14
  177. package/dist/lib/retry.js +93 -129
  178. package/dist/lib/search-and-replace.js +164 -148
  179. package/dist/lib/site-import/db-file-import.js +12 -16
  180. package/dist/lib/site-import/status.js +291 -291
  181. package/dist/lib/token.js +86 -87
  182. package/dist/lib/tracker.js +51 -62
  183. package/dist/lib/types/graphql/rate-limit-exceeded-error.js +2 -1
  184. package/dist/lib/types.js +2 -1
  185. package/dist/lib/user-error.js +6 -8
  186. package/dist/lib/utils.js +81 -87
  187. package/dist/lib/validations/custom-deploy.js +218 -186
  188. package/dist/lib/validations/is-multi-site-sql-dump.js +6 -6
  189. package/dist/lib/validations/is-multi-site.js +83 -50
  190. package/dist/lib/validations/is-multisite-domain-mapped.js +92 -62
  191. package/dist/lib/validations/line-by-line.js +78 -46
  192. package/dist/lib/validations/site-type.js +59 -63
  193. package/dist/lib/validations/sql-insert-parser.js +415 -0
  194. package/dist/lib/validations/sql.js +551 -431
  195. package/dist/lib/validations/utils.js +27 -29
  196. package/dist/lib/vip-import-validate-files.js +481 -490
  197. package/dist/lib/wp/helpers.js +41 -45
  198. package/dist/lib/wp/readline.js +21 -57
  199. package/dist/lib/xdg-data.js +11 -12
  200. package/helpers/mark-cli-executable.js +9 -0
  201. package/node_modules/@apollo/client/CHANGELOG.md +10 -0
  202. package/node_modules/@apollo/client/__cjs/cache/inmemory/helpers.cjs +5 -0
  203. package/node_modules/@apollo/client/__cjs/cache/inmemory/helpers.cjs.map +1 -1
  204. package/node_modules/@apollo/client/__cjs/cache/inmemory/inMemoryCache.cjs +2 -1
  205. package/node_modules/@apollo/client/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
  206. package/node_modules/@apollo/client/__cjs/cache/inmemory/key-extractor.cjs +14 -2
  207. package/node_modules/@apollo/client/__cjs/cache/inmemory/key-extractor.cjs.map +1 -1
  208. package/node_modules/@apollo/client/__cjs/cache/inmemory/policies.cjs +16 -0
  209. package/node_modules/@apollo/client/__cjs/cache/inmemory/policies.cjs.map +1 -1
  210. package/node_modules/@apollo/client/__cjs/cache/inmemory/policies.d.cts +2 -0
  211. package/node_modules/@apollo/client/__cjs/cache/inmemory/writeToStore.cjs +3 -2
  212. package/node_modules/@apollo/client/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
  213. package/node_modules/@apollo/client/__cjs/core/QueryInfo.cjs +9 -1
  214. package/node_modules/@apollo/client/__cjs/core/QueryInfo.cjs.map +1 -1
  215. package/node_modules/@apollo/client/__cjs/core/QueryInfo.d.cts +1 -1
  216. package/node_modules/@apollo/client/__cjs/core/QueryManager.cjs +10 -3
  217. package/node_modules/@apollo/client/__cjs/core/QueryManager.cjs.map +1 -1
  218. package/node_modules/@apollo/client/__cjs/react/hooks/useFragment.cjs.map +1 -1
  219. package/node_modules/@apollo/client/__cjs/react/hooks/useFragment.d.cts +42 -43
  220. package/node_modules/@apollo/client/__cjs/version.cjs +1 -1
  221. package/node_modules/@apollo/client/cache/inmemory/helpers.js +5 -0
  222. package/node_modules/@apollo/client/cache/inmemory/helpers.js.map +1 -1
  223. package/node_modules/@apollo/client/cache/inmemory/inMemoryCache.js +2 -1
  224. package/node_modules/@apollo/client/cache/inmemory/inMemoryCache.js.map +1 -1
  225. package/node_modules/@apollo/client/cache/inmemory/key-extractor.js +14 -2
  226. package/node_modules/@apollo/client/cache/inmemory/key-extractor.js.map +1 -1
  227. package/node_modules/@apollo/client/cache/inmemory/policies.d.ts +2 -0
  228. package/node_modules/@apollo/client/cache/inmemory/policies.js +17 -1
  229. package/node_modules/@apollo/client/cache/inmemory/policies.js.map +1 -1
  230. package/node_modules/@apollo/client/cache/inmemory/writeToStore.js +3 -2
  231. package/node_modules/@apollo/client/cache/inmemory/writeToStore.js.map +1 -1
  232. package/node_modules/@apollo/client/core/QueryInfo.d.ts +1 -1
  233. package/node_modules/@apollo/client/core/QueryInfo.js +10 -2
  234. package/node_modules/@apollo/client/core/QueryInfo.js.map +1 -1
  235. package/node_modules/@apollo/client/core/QueryManager.js +10 -3
  236. package/node_modules/@apollo/client/core/QueryManager.js.map +1 -1
  237. package/node_modules/@apollo/client/package.json +1 -1
  238. package/node_modules/@apollo/client/react/hooks/useFragment.d.ts +42 -43
  239. package/node_modules/@apollo/client/react/hooks/useFragment.js.map +1 -1
  240. package/node_modules/@apollo/client/react/hooks-compiled/useFragment.d.ts +42 -43
  241. package/node_modules/@apollo/client/react/hooks-compiled/useFragment.js.map +1 -1
  242. package/node_modules/@apollo/client/version.js +1 -1
  243. package/node_modules/@automattic/vip-search-replace/README.md +6 -1
  244. package/node_modules/@automattic/vip-search-replace/lib/index.js +46 -14
  245. package/node_modules/@automattic/vip-search-replace/package.json +1 -1
  246. package/node_modules/@types/node/README.md +1 -1
  247. package/node_modules/@types/node/package.json +2 -2
  248. package/node_modules/@types/node/zlib.d.ts +752 -0
  249. package/node_modules/check-disk-space/README.md +92 -32
  250. package/node_modules/check-disk-space/dist/check-disk-space.d.mts +58 -0
  251. package/node_modules/check-disk-space/dist/check-disk-space.mjs +170 -190
  252. package/node_modules/check-disk-space/package.json +43 -71
  253. package/node_modules/cpu-features/build/Makefile +2 -2
  254. package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/filesystem.o.d +1 -1
  255. package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_aarch64_linux_or_android.o.d +1 -1
  256. package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_aarch64_macos_or_iphone.o.d +1 -1
  257. package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_aarch64_windows.o.d +1 -1
  258. package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_arm_linux_or_android.o.d +1 -1
  259. package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_mips_linux_or_android.o.d +1 -1
  260. package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_ppc_linux.o.d +1 -1
  261. package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_x86_freebsd.o.d +1 -1
  262. package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_x86_linux_or_android.o.d +1 -1
  263. package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_x86_macos.o.d +1 -1
  264. package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_x86_windows.o.d +1 -1
  265. package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/stack_line_reader.o.d +1 -1
  266. package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/string_view.o.d +1 -1
  267. package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpufeatures/src/binding.o.d +157 -145
  268. package/node_modules/cpu-features/build/Release/cpufeatures.node +0 -0
  269. package/node_modules/cpu-features/build/Release/obj.target/cpufeatures/src/binding.o +0 -0
  270. package/node_modules/cpu-features/build/Release/obj.target/cpufeatures.node +0 -0
  271. package/node_modules/cpu-features/build/config.gypi +100 -31
  272. package/node_modules/cpu-features/build/cpufeatures.target.mk +14 -14
  273. package/node_modules/cpu-features/build/deps/cpu_features/cpu_features.target.mk +14 -14
  274. package/node_modules/ssh2/lib/protocol/crypto/build/Makefile +2 -2
  275. package/node_modules/ssh2/lib/protocol/crypto/build/Release/.deps/Release/obj.target/sshcrypto/src/binding.o.d.raw +136 -0
  276. package/node_modules/ssh2/lib/protocol/crypto/build/sshcrypto.target.mk +14 -14
  277. package/node_modules/undici/docs/docs/api/Interceptors.md +15 -2
  278. package/node_modules/undici/lib/dispatcher/client-h2.js +78 -3
  279. package/node_modules/undici/lib/dispatcher/pool-base.js +20 -3
  280. package/node_modules/undici/package.json +3 -3
  281. package/node_modules/undici/types/api.d.ts +1 -1
  282. package/node_modules/undici/types/utility.d.ts +4 -4
  283. package/package.json +44 -13
  284. package/dist/lib/analytics/clients/client.js +0 -1
  285. package/dist/lib/analytics/clients/pendo.js +0 -78
  286. package/helpers/check-version.js +0 -16
  287. package/node_modules/check-disk-space/dist/check-disk-space.cjs +0 -210
  288. package/node_modules/check-disk-space/dist/check-disk-space.d.ts +0 -53
  289. package/node_modules/fetch-retry/.eslintignore +0 -1
  290. package/node_modules/fetch-retry/.eslintrc.yml +0 -20
  291. package/node_modules/fetch-retry/.github/workflows/node.js.yml +0 -32
  292. package/node_modules/fetch-retry/.husky/pre-commit +0 -6
  293. package/node_modules/fetch-retry/.nycrc.json +0 -24
  294. package/node_modules/fetch-retry/.travis.yml +0 -3
  295. package/node_modules/fetch-retry/LICENSE +0 -21
  296. package/node_modules/fetch-retry/README.md +0 -128
  297. package/node_modules/fetch-retry/dist/fetch-retry.umd.js +0 -151
  298. package/node_modules/fetch-retry/index.d.ts +0 -29
  299. package/node_modules/fetch-retry/index.js +0 -143
  300. package/node_modules/fetch-retry/package.json +0 -41
  301. package/node_modules/fetch-retry/rollup.config.js +0 -12
  302. package/node_modules/fetch-retry/test/.eslintrc.yml +0 -7
  303. package/node_modules/fetch-retry/test/integration/index.js +0 -212
  304. package/node_modules/fetch-retry/test/integration/mock-api/index.js +0 -42
  305. package/node_modules/fetch-retry/test/unit/index.js +0 -1169
  306. package/node_modules/ssh2/lib/protocol/crypto/build/Release/.deps/Release/obj.target/sshcrypto/src/binding.o.d +0 -265
  307. package/node_modules/ssh2/lib/protocol/crypto/build/Release/.deps/Release/obj.target/sshcrypto.node.d +0 -1
  308. package/node_modules/ssh2/lib/protocol/crypto/build/Release/.deps/Release/sshcrypto.node.d +0 -1
  309. package/node_modules/ssh2/lib/protocol/crypto/build/Release/obj.target/sshcrypto/src/binding.o +0 -0
  310. package/node_modules/ssh2/lib/protocol/crypto/build/Release/obj.target/sshcrypto.node +0 -0
  311. package/node_modules/ssh2/lib/protocol/crypto/build/Release/sshcrypto.node +0 -0
@@ -1,30 +1,70 @@
1
1
  "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.validate = exports.staticSqlValidations = exports.getTableNames = void 0;
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.validate = exports.staticSqlValidations = exports.getTableNames = exports.validateImportFileExtension = void 0;
5
40
  exports.validateFilename = validateFilename;
6
- exports.validateImportFileExtension = void 0;
7
- var _singleLineLog = require("@wwa/single-line-log");
8
- var _chalk = _interopRequireDefault(require("chalk"));
9
- var _nodeEvents = require("node:events");
10
- var _nodePath = _interopRequireDefault(require("node:path"));
11
- var exit = _interopRequireWildcard(require("../../lib/cli/exit"));
12
- var _clientFileUploader = require("../../lib/client-file-uploader");
13
- var _tracker = require("../../lib/tracker");
14
- var _lineByLine = require("../../lib/validations/line-by-line");
15
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
16
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
41
+ const single_line_log_1 = require("@wwa/single-line-log");
42
+ const chalk_1 = __importDefault(require("chalk"));
43
+ const node_events_1 = require("node:events");
44
+ const node_path_1 = __importDefault(require("node:path"));
45
+ const exit = __importStar(require("../../lib/cli/exit"));
46
+ const client_file_uploader_1 = require("../../lib/client-file-uploader");
47
+ const tracker_1 = require("../../lib/tracker");
48
+ const line_by_line_1 = require("../../lib/validations/line-by-line");
49
+ const sql_insert_parser_1 = require("../../lib/validations/sql-insert-parser");
17
50
  let problemsFound = 0;
18
51
  let lineNum = 1;
19
52
  const tableNames = [];
53
+ let currentInsertStatementTableName;
54
+ let currentInsertStatementColumns;
55
+ let currentInsertStatementColumnList;
56
+ let currentInsertStatementHasValues = false;
57
+ let currentInsertStatementValuesFinished = false;
58
+ let currentInsertStatementRowBuffer;
59
+ let currentSqlCommentStripState = { inBlockComment: false };
20
60
  function formatError(message) {
21
- return `${_chalk.default.red('SQL Error:')} ${message}`;
61
+ return `${chalk_1.default.red('SQL Error:')} ${message}`;
22
62
  }
23
63
  function formatWarning(message) {
24
- return `${_chalk.default.yellow('Warning:')} ${message}`;
64
+ return `${chalk_1.default.yellow('Warning:')} ${message}`;
25
65
  }
26
66
  function formatRecommendation(message) {
27
- return `${_chalk.default.yellow('Recommendation:')} ${message}`;
67
+ return `${chalk_1.default.yellow('Recommendation:')} ${message}`;
28
68
  }
29
69
  /**
30
70
  * Check if a file has a valid extension
@@ -32,451 +72,531 @@ function formatRecommendation(message) {
32
72
  * @param {string} filename The file extension
33
73
  * @returns {boolean} True if the extension is valid
34
74
  */
35
- const validateImportFileExtension = filename => {
36
- const ext = _nodePath.default.extname(filename).toLowerCase();
37
- if (!['.sql', '.gz'].includes(ext)) {
38
- exit.withError('Invalid file extension. Please provide a .sql or .gz file.');
39
- }
75
+ const validateImportFileExtension = (filename) => {
76
+ const ext = node_path_1.default.extname(filename).toLowerCase();
77
+ if (!['.sql', '.gz'].includes(ext)) {
78
+ exit.withError('Invalid file extension. Please provide a .sql or .gz file.');
79
+ }
40
80
  };
41
81
  exports.validateImportFileExtension = validateImportFileExtension;
42
82
  function validateFilename(filename) {
43
- const re = /^[a-z0-9\-_.]+$/i;
44
-
45
- // Exits if filename contains anything outside a-z A-Z - _ .
46
- if (!re.test(filename)) {
47
- exit.withError('Error: The characters used in the name of a file for import are limited to [0-9,a-z,A-Z,-,_,.]');
48
- }
83
+ const re = /^[a-z0-9\-_.]+$/i;
84
+ // Exits if filename contains anything outside a-z A-Z - _ .
85
+ if (!re.test(filename)) {
86
+ exit.withError('Error: The characters used in the name of a file for import are limited to [0-9,a-z,A-Z,-,_,.]');
87
+ }
49
88
  }
50
- const generalCheckFormatter = check => {
51
- const errors = [];
52
- const infos = [];
53
- const validProblems = check.results.filter(result => !result.falsePositive);
54
- if (validProblems.length > 0) {
55
- if (validProblems.some(result => !result.warning)) {
56
- problemsFound += 1;
57
- }
58
- for (const problem of validProblems) {
59
- const text = `${problem.text ?? check.message} on line ${problem.lineNumber ?? ''}.`;
60
- if (problem.warning) {
89
+ const generalCheckFormatter = (check) => {
90
+ const errors = [];
91
+ const infos = [];
92
+ const validProblems = check.results.filter(result => !result.falsePositive);
93
+ if (validProblems.length > 0) {
94
+ if (validProblems.some(result => !result.warning)) {
95
+ problemsFound += 1;
96
+ }
97
+ for (const problem of validProblems) {
98
+ const text = `${problem.text ?? check.message} on line ${problem.lineNumber ?? ''}.`;
99
+ if (problem.warning) {
100
+ errors.push({
101
+ warning: formatWarning(text),
102
+ recommendation: formatRecommendation(problem.recomendation ?? check.recommendation),
103
+ });
104
+ }
105
+ else {
106
+ errors.push({
107
+ error: formatError(text),
108
+ recommendation: formatRecommendation(problem.recomendation ?? check.recommendation),
109
+ });
110
+ }
111
+ }
112
+ }
113
+ else {
114
+ infos.push(`✅ ${check.message} was found 0 times.`);
115
+ }
116
+ return {
117
+ errors,
118
+ infos,
119
+ };
120
+ };
121
+ const lineNumberCheckFormatter = (check) => {
122
+ const errors = [];
123
+ const infos = [];
124
+ if (check.results.length > 0) {
125
+ problemsFound += 1;
126
+ const lineNumbers = check.results.map(result => result.lineNumber);
61
127
  errors.push({
62
- warning: formatWarning(text),
63
- recommendation: formatRecommendation(problem.recomendation ?? check.recommendation)
128
+ error: formatError(`${check.message} on line(s) ${lineNumbers.join(', ')}.`),
129
+ recommendation: formatRecommendation(check.recommendation),
64
130
  });
65
- } else {
131
+ }
132
+ else {
133
+ infos.push(`✅ ${check.message} was found 0 times.`);
134
+ }
135
+ return {
136
+ errors,
137
+ infos,
138
+ };
139
+ };
140
+ const requiredCheckFormatter = (check, type, isImport) => {
141
+ const errors = [];
142
+ const infos = [];
143
+ if (check.results.length > 0) {
144
+ infos.push(`✅ ${check.message} was found ${check.results.length} times.`);
145
+ if (type === 'createTable') {
146
+ if (!isImport) {
147
+ checkTablePrefixes(check.results, errors, infos);
148
+ }
149
+ }
150
+ }
151
+ else {
152
+ problemsFound += 1;
66
153
  errors.push({
67
- error: formatError(text),
68
- recommendation: formatRecommendation(problem.recomendation ?? check.recommendation)
154
+ error: formatError(`${check.message} was not found.`),
155
+ recommendation: formatRecommendation(check.recommendation),
69
156
  });
70
- }
71
- }
72
- } else {
73
- infos.push(`✅ ${check.message} was found 0 times.`);
74
- }
75
- return {
76
- errors,
77
- infos
78
- };
157
+ }
158
+ return {
159
+ errors,
160
+ infos,
161
+ };
79
162
  };
80
- const lineNumberCheckFormatter = check => {
81
- const errors = [];
82
- const infos = [];
83
- if (check.results.length > 0) {
84
- problemsFound += 1;
85
- const lineNumbers = check.results.map(result => result.lineNumber);
86
- errors.push({
87
- error: formatError(`${check.message} on line(s) ${lineNumbers.join(', ')}.`),
88
- recommendation: formatRecommendation(check.recommendation)
163
+ const infoCheckFormatter = (check) => {
164
+ const infos = [];
165
+ check.results.forEach(item => {
166
+ if (item.text) {
167
+ infos.push(item.text);
168
+ }
89
169
  });
90
- } else {
91
- infos.push(`✅ ${check.message} was found 0 times.`);
92
- }
93
- return {
94
- errors,
95
- infos
96
- };
97
- };
98
- const requiredCheckFormatter = (check, type, isImport) => {
99
- const errors = [];
100
- const infos = [];
101
- if (check.results.length > 0) {
102
- infos.push(`✅ ${check.message} was found ${check.results.length} times.`);
103
- if (type === 'createTable') {
104
- if (!isImport) {
105
- checkTablePrefixes(check.results, errors, infos);
106
- }
107
- }
108
- } else {
109
- problemsFound += 1;
110
- errors.push({
111
- error: formatError(`${check.message} was not found.`),
112
- recommendation: formatRecommendation(check.recommendation)
113
- });
114
- }
115
- return {
116
- errors,
117
- infos
118
- };
119
- };
120
- const infoCheckFormatter = check => {
121
- const infos = [];
122
- check.results.forEach(item => {
123
- if (item.text) {
124
- infos.push(item.text);
125
- }
126
- });
127
- return {
128
- errors: [],
129
- infos
130
- };
170
+ return {
171
+ errors: [],
172
+ infos,
173
+ };
131
174
  };
132
175
  function checkTablePrefixes(results, errors, infos) {
133
- const wpTables = [];
134
- const notWPTables = [];
135
- const wpMultisiteTables = [];
136
- results.forEach(result => {
137
- const tableName = result.text ?? '';
138
- if (/^wp_(\d+_)/.exec(tableName)) {
139
- wpMultisiteTables.push(tableName);
140
- } else if (tableName.startsWith('wp_')) {
141
- wpTables.push(tableName);
142
- } else {
143
- notWPTables.push(tableName);
144
- }
145
- });
146
- if (wpTables.length > 0) {
147
- infos.push(` - wp_ prefix tables found: ${wpTables.length} `);
148
- }
149
- if (notWPTables.length > 0) {
150
- problemsFound += 1;
151
- errors.push({
152
- error: formatError(`tables without wp_ prefix found: ${notWPTables.join(',')}`),
153
- recommendation: formatRecommendation('Please make sure all table names are prefixed with `wp_`')
176
+ const wpTables = [];
177
+ const notWPTables = [];
178
+ const wpMultisiteTables = [];
179
+ results.forEach(result => {
180
+ const tableName = result.text ?? '';
181
+ if (/^wp_(\d+_)/.exec(tableName)) {
182
+ wpMultisiteTables.push(tableName);
183
+ }
184
+ else if (tableName.startsWith('wp_')) {
185
+ wpTables.push(tableName);
186
+ }
187
+ else {
188
+ notWPTables.push(tableName);
189
+ }
154
190
  });
155
- }
156
- if (wpMultisiteTables.length > 0) {
157
- infos.push(` - wp_n_ prefix tables found: ${wpMultisiteTables.length} `);
158
- }
191
+ if (wpTables.length > 0) {
192
+ infos.push(` - wp_ prefix tables found: ${wpTables.length} `);
193
+ }
194
+ if (notWPTables.length > 0) {
195
+ problemsFound += 1;
196
+ errors.push({
197
+ error: formatError(`tables without wp_ prefix found: ${notWPTables.join(',')}`),
198
+ recommendation: formatRecommendation('Please make sure all table names are prefixed with `wp_`'),
199
+ });
200
+ }
201
+ if (wpMultisiteTables.length > 0) {
202
+ infos.push(` - wp_n_ prefix tables found: ${wpMultisiteTables.length} `);
203
+ }
159
204
  }
160
205
  const checks = {
161
- binaryLogging: {
162
- matcher: /SET @@SESSION.sql_log_bin/i,
163
- matchHandler: lineNumber => ({
164
- lineNumber
165
- }),
166
- outputFormatter: lineNumberCheckFormatter,
167
- results: [],
168
- message: 'SET @@SESSION.sql_log_bin statement',
169
- excerpt: "'SET @@SESSION.sql_log_bin' statement should not be present (case-insensitive)",
170
- recommendation: 'Remove these lines'
171
- },
172
- trigger: {
173
- // Match `CREATE (DEFINER=`root`@`host`) TRIGGER`
174
- // eslint-disable-next-line security/detect-unsafe-regex
175
- matcher: /^CREATE (\(?DEFINER=`?(\w*)(`@`)?(\w*\.*%?)*`?\)?)?(| )TRIGGER/i,
176
- matchHandler: lineNumber => ({
177
- lineNumber
178
- }),
179
- outputFormatter: lineNumberCheckFormatter,
180
- results: [],
181
- message: 'TRIGGER statement',
182
- excerpt: "'TRIGGER' statement should not be present (case-sensitive)",
183
- recommendation: 'Remove these lines'
184
- },
185
- dropDB: {
186
- matcher: /^DROP DATABASE/i,
187
- matchHandler: lineNumber => ({
188
- lineNumber
189
- }),
190
- outputFormatter: lineNumberCheckFormatter,
191
- results: [],
192
- message: 'DROP DATABASE statement',
193
- excerpt: "'DROP DATABASE' should not be present (case-insensitive)",
194
- recommendation: 'Remove these lines'
195
- },
196
- useStatement: {
197
- matcher: /^USE /i,
198
- matchHandler: lineNumber => ({
199
- lineNumber
200
- }),
201
- outputFormatter: lineNumberCheckFormatter,
202
- results: [],
203
- message: 'USE <DATABASE_NAME> statement',
204
- excerpt: "'USE <DATABASE_NAME>' should not be present (case-insensitive)",
205
- recommendation: 'Remove these lines'
206
- },
207
- alterUser: {
208
- matcher: /^(ALTER USER|SET PASSWORD)/i,
209
- matchHandler: lineNumber => ({
210
- lineNumber
211
- }),
212
- outputFormatter: lineNumberCheckFormatter,
213
- results: [],
214
- message: 'ALTER USER statement',
215
- excerpt: "'ALTER USER' should not be present (case-insensitive)",
216
- recommendation: 'Remove these lines'
217
- },
218
- dropTable: {
219
- matcher: /^DROP TABLE IF EXISTS `?([a-z0-9_]*)/i,
220
- matchHandler: (lineNumber, results) => ({
221
- text: results[1]
222
- }),
223
- outputFormatter: requiredCheckFormatter,
224
- results: [],
225
- message: 'DROP TABLE',
226
- excerpt: "'DROP TABLE IF EXISTS' should be present (case-insensitive)",
227
- recommendation: 'Check import settings to include DROP TABLE statements'
228
- },
229
- createTable: {
230
- matcher: /^CREATE TABLE (?:IF NOT EXISTS )?`?([a-z0-9_]*)/i,
231
- matchHandler: (lineNumber, results) => ({
232
- text: results[1]
233
- }),
234
- outputFormatter: requiredCheckFormatter,
235
- results: [],
236
- message: 'CREATE TABLE',
237
- excerpt: "'CREATE TABLE' should be present (case-insensitive)",
238
- recommendation: 'Check import settings to include CREATE TABLE statements'
239
- },
240
- alterTable: {
241
- matcher: /^ALTER TABLE `?([a-z0-9_]*)/i,
242
- matchHandler: lineNumber => ({
243
- lineNumber
244
- }),
245
- outputFormatter: lineNumberCheckFormatter,
246
- results: [],
247
- message: 'ALTER TABLE statement',
248
- excerpt: "'ALTER TABLE' should not be present (case-insensitive)",
249
- recommendation: 'Remove these lines and define table structure in the CREATE TABLE statement instead'
250
- },
251
- uniqueChecks: {
252
- matcher: /^SET UNIQUE_CHECKS\s*=\s*0/i,
253
- matchHandler: lineNumber => ({
254
- lineNumber
255
- }),
256
- outputFormatter: lineNumberCheckFormatter,
257
- results: [],
258
- message: 'SET UNIQUE_CHECKS = 0',
259
- excerpt: "'SET UNIQUE_CHECKS = 0' should not be present",
260
- recommendation: "Disabling 'UNIQUE_CHECKS' is not allowed. These lines should be removed"
261
- },
262
- siteHomeUrl: {
263
- matcher: `['"](siteurl|home)['"],\\s?['"](.*?)['"]`,
264
- matchHandler: (lineNumber, results) => ({
265
- text: results[1] + ' ' + results[2]
266
- }),
267
- outputFormatter: infoCheckFormatter,
268
- results: [],
269
- message: 'Siteurl/home matches',
270
- excerpt: 'Siteurl/home options',
271
- recommendation: ''
272
- },
273
- siteHomeUrlLando: {
274
- matcher: `['"](siteurl|home)['"],\\s?['"]([^'"]+)['"]`,
275
- matchHandler: (lineNumber, results, expectedDomain) => {
276
- let foundDomain = results[2];
277
- if (!/^https?:\/\//i.test(foundDomain)) {
278
- return {
279
- falsePositive: true
280
- };
281
- }
282
- foundDomain = foundDomain.replace(/^https?:\/\//, '');
283
- if (!foundDomain.trim()) {
284
- return {
285
- falsePositive: true
286
- };
287
- }
288
- if (foundDomain.includes(expectedDomain)) {
289
- return {
290
- falsePositive: true
291
- };
292
- }
293
- return {
294
- warning: true,
295
- lineNumber,
296
- recomendation: `Use '--search-replace="${foundDomain},${expectedDomain}"' switch to replace the domain`
297
- };
206
+ binaryLogging: {
207
+ matcher: /SET @@SESSION.sql_log_bin/i,
208
+ matchHandler: lineNumber => ({ lineNumber }),
209
+ outputFormatter: lineNumberCheckFormatter,
210
+ results: [],
211
+ message: 'SET @@SESSION.sql_log_bin statement',
212
+ excerpt: "'SET @@SESSION.sql_log_bin' statement should not be present (case-insensitive)",
213
+ recommendation: 'Remove these lines',
214
+ },
215
+ trigger: {
216
+ // Match `CREATE (DEFINER=`root`@`host`) TRIGGER`
217
+ // eslint-disable-next-line security/detect-unsafe-regex
218
+ matcher: /^CREATE (\(?DEFINER=`?(\w*)(`@`)?(\w*\.*%?)*`?\)?)?(| )TRIGGER/i,
219
+ matchHandler: lineNumber => ({ lineNumber }),
220
+ outputFormatter: lineNumberCheckFormatter,
221
+ results: [],
222
+ message: 'TRIGGER statement',
223
+ excerpt: "'TRIGGER' statement should not be present (case-sensitive)",
224
+ recommendation: 'Remove these lines',
225
+ },
226
+ dropDB: {
227
+ matcher: /^DROP DATABASE/i,
228
+ matchHandler: lineNumber => ({ lineNumber }),
229
+ outputFormatter: lineNumberCheckFormatter,
230
+ results: [],
231
+ message: 'DROP DATABASE statement',
232
+ excerpt: "'DROP DATABASE' should not be present (case-insensitive)",
233
+ recommendation: 'Remove these lines',
234
+ },
235
+ useStatement: {
236
+ matcher: /^USE /i,
237
+ matchHandler: lineNumber => ({ lineNumber }),
238
+ outputFormatter: lineNumberCheckFormatter,
239
+ results: [],
240
+ message: 'USE <DATABASE_NAME> statement',
241
+ excerpt: "'USE <DATABASE_NAME>' should not be present (case-insensitive)",
242
+ recommendation: 'Remove these lines',
243
+ },
244
+ alterUser: {
245
+ matcher: /^(ALTER USER|SET PASSWORD)/i,
246
+ matchHandler: lineNumber => ({ lineNumber }),
247
+ outputFormatter: lineNumberCheckFormatter,
248
+ results: [],
249
+ message: 'ALTER USER statement',
250
+ excerpt: "'ALTER USER' should not be present (case-insensitive)",
251
+ recommendation: 'Remove these lines',
252
+ },
253
+ dropTable: {
254
+ matcher: /^DROP TABLE IF EXISTS `?([a-z0-9_]*)/i,
255
+ matchHandler: (lineNumber, results) => ({ text: results[1] }),
256
+ outputFormatter: requiredCheckFormatter,
257
+ results: [],
258
+ message: 'DROP TABLE',
259
+ excerpt: "'DROP TABLE IF EXISTS' should be present (case-insensitive)",
260
+ recommendation: 'Check import settings to include DROP TABLE statements',
261
+ },
262
+ createTable: {
263
+ matcher: /^CREATE TABLE (?:IF NOT EXISTS )?`?([a-z0-9_]*)/i,
264
+ matchHandler: (lineNumber, results) => ({ text: results[1] }),
265
+ outputFormatter: requiredCheckFormatter,
266
+ results: [],
267
+ message: 'CREATE TABLE',
268
+ excerpt: "'CREATE TABLE' should be present (case-insensitive)",
269
+ recommendation: 'Check import settings to include CREATE TABLE statements',
270
+ },
271
+ alterTable: {
272
+ matcher: /^ALTER TABLE `?([a-z0-9_]*)/i,
273
+ matchHandler: lineNumber => ({ lineNumber }),
274
+ outputFormatter: lineNumberCheckFormatter,
275
+ results: [],
276
+ message: 'ALTER TABLE statement',
277
+ excerpt: "'ALTER TABLE' should not be present (case-insensitive)",
278
+ recommendation: 'Remove these lines and define table structure in the CREATE TABLE statement instead',
279
+ },
280
+ uniqueChecks: {
281
+ matcher: /^SET UNIQUE_CHECKS\s*=\s*0/i,
282
+ matchHandler: lineNumber => ({ lineNumber }),
283
+ outputFormatter: lineNumberCheckFormatter,
284
+ results: [],
285
+ message: 'SET UNIQUE_CHECKS = 0',
286
+ excerpt: "'SET UNIQUE_CHECKS = 0' should not be present",
287
+ recommendation: "Disabling 'UNIQUE_CHECKS' is not allowed. These lines should be removed",
288
+ },
289
+ siteHomeUrl: {
290
+ matchHandler: (lineNumber, results) => ({ text: results[1] + ' ' + results[2] }),
291
+ outputFormatter: infoCheckFormatter,
292
+ results: [],
293
+ message: 'Siteurl/home matches',
294
+ excerpt: 'Siteurl/home options',
295
+ recommendation: '',
296
+ },
297
+ siteHomeUrlLando: {
298
+ matchHandler: (lineNumber, results, expectedDomain) => {
299
+ let foundDomain = results[2];
300
+ foundDomain = foundDomain.replace(/^https?:\/\//, '');
301
+ if (!foundDomain.trim()) {
302
+ return { falsePositive: true };
303
+ }
304
+ if (foundDomain.includes(expectedDomain)) {
305
+ return { falsePositive: true };
306
+ }
307
+ return {
308
+ warning: true,
309
+ lineNumber,
310
+ recomendation: `Use '--search-replace="${foundDomain},${expectedDomain}"' switch to replace the domain`,
311
+ };
312
+ },
313
+ outputFormatter: generalCheckFormatter,
314
+ results: [],
315
+ message: 'Siteurl/home options not pointing to lando domain',
316
+ excerpt: 'Siteurl/home options not pointing to lando domain',
317
+ recommendation: "Use search-replace to change environment's domain",
318
+ },
319
+ engineInnoDB: {
320
+ matcher: /\sENGINE\s?=(?!(\s?InnoDB))/i,
321
+ matchHandler: lineNumber => ({ lineNumber }),
322
+ outputFormatter: lineNumberCheckFormatter,
323
+ results: [],
324
+ message: 'ENGINE != InnoDB',
325
+ excerpt: "'ENGINE=InnoDB' should be present (case-insensitive) for all tables",
326
+ recommendation: "Ensure your application works with InnoDB and update your SQL dump to include only 'ENGINE=InnoDB' engine definitions in 'CREATE TABLE' statements. " +
327
+ "We suggest you search for all 'ENGINE=X' entries and replace them with 'ENGINE=InnoDB'!",
328
+ },
329
+ autoIncrement: {
330
+ matcher: /\s(NOT NULL AUTO_INCREMENT,)/i,
331
+ matchHandler: (_lineNumber, results) => ({ text: results[1] }),
332
+ outputFormatter: requiredCheckFormatter,
333
+ results: [],
334
+ message: 'AUTO_INCREMENT attribute',
335
+ excerpt: "'AUTO_INCREMENT attribute' should be present (case-insensitive) for all CREATE TABLE statements",
336
+ recommendation: 'Check import settings to include AUTO_INCREMENT attribute in all the CREATE TABLE statements',
298
337
  },
299
- outputFormatter: generalCheckFormatter,
300
- results: [],
301
- message: 'Siteurl/home options not pointing to lando domain',
302
- excerpt: 'Siteurl/home options not pointing to lando domain',
303
- recommendation: "Use search-replace to change environment's domain"
304
- },
305
- engineInnoDB: {
306
- matcher: /\sENGINE\s?=(?!(\s?InnoDB))/i,
307
- matchHandler: lineNumber => ({
308
- lineNumber
309
- }),
310
- outputFormatter: lineNumberCheckFormatter,
311
- results: [],
312
- message: 'ENGINE != InnoDB',
313
- excerpt: "'ENGINE=InnoDB' should be present (case-insensitive) for all tables",
314
- recommendation: "Ensure your application works with InnoDB and update your SQL dump to include only 'ENGINE=InnoDB' engine definitions in 'CREATE TABLE' statements. " + "We suggest you search for all 'ENGINE=X' entries and replace them with 'ENGINE=InnoDB'!"
315
- },
316
- autoIncrement: {
317
- matcher: /\s(NOT NULL AUTO_INCREMENT,)/i,
318
- matchHandler: (_lineNumber, results) => ({
319
- text: results[1]
320
- }),
321
- outputFormatter: requiredCheckFormatter,
322
- results: [],
323
- message: 'AUTO_INCREMENT attribute',
324
- excerpt: "'AUTO_INCREMENT attribute' should be present (case-insensitive) for all CREATE TABLE statements",
325
- recommendation: 'Check import settings to include AUTO_INCREMENT attribute in all the CREATE TABLE statements'
326
- }
327
338
  };
328
339
  const DEV_ENV_SPECIFIC_CHECKS = ['useStatement', 'siteHomeUrlLando'];
329
340
  function findDuplicates(arr, where) {
330
- const filtered = arr.filter(item => {
331
- if (where.has(item)) {
332
- where.delete(item);
333
- return false;
334
- }
335
- return true;
336
- });
337
- return [...new Set(filtered)];
338
- }
339
- const postValidation = async options => {
340
- await (0, _tracker.trackEvent)('import_validate_sql_command_execute', {
341
- is_import: options.isImport
342
- });
343
- if (!options.isImport) {
344
- (0, _singleLineLog.stdout)(`Finished processing ${lineNum} lines.`);
345
- console.log('\n');
346
- }
347
- const errorSummary = {};
348
- const checkEntries = Object.entries(checks).filter(([type]) => !options.skipChecks.includes(type));
349
- const formattedWarnings = [];
350
- let formattedErrors = [];
351
- let formattedInfos = [];
352
- for (const [type, check] of checkEntries) {
353
- const formattedOutput = check.outputFormatter(check, type, options.isImport);
354
- for (const error of formattedOutput.errors) {
355
- if ('warning' in error) {
356
- formattedWarnings.push(error);
357
- } else {
358
- formattedErrors.push(error);
359
- }
360
- }
361
- formattedInfos = formattedInfos.concat(formattedOutput.infos);
362
- errorSummary[type] = check.results.length;
363
- }
364
- errorSummary.problems_found = problemsFound;
365
- const tableNamesSet = new Set(tableNames);
366
- if (tableNames.length > tableNamesSet.size) {
367
- // there was a duplciate table
368
- problemsFound++;
369
- const duplicates = findDuplicates(tableNames, tableNamesSet);
370
- const errorObject = {
371
- error: formatError('Duplicate table names were found: ' + duplicates.join(',')),
372
- recommendation: formatRecommendation('Ensure that there are no duplicate tables in your SQL dump')
373
- };
374
- formattedErrors = formattedErrors.concat(errorObject);
375
- }
376
- if (formattedWarnings.length) {
377
- const warningOutput = [];
378
- formattedWarnings.forEach(warning => {
379
- warningOutput.push(warning.warning);
380
- if (warning.recommendation) {
381
- warningOutput.push(warning.recommendation);
382
- }
383
- warningOutput.push('');
384
- });
385
- console.log(warningOutput.join('\n'));
386
- console.log('');
387
- }
388
- if (problemsFound > 0) {
389
- await (0, _tracker.trackEvent)('import_validate_sql_command_failure', {
390
- is_import: options.isImport,
391
- error: errorSummary
341
+ const filtered = arr.filter(item => {
342
+ if (where.has(item)) {
343
+ where.delete(item);
344
+ return false;
345
+ }
346
+ return true;
392
347
  });
393
- const errorOutput = [];
394
- formattedErrors.forEach(error => {
395
- errorOutput.push(error.error);
396
- if (error.recommendation) {
397
- errorOutput.push(error.recommendation);
398
- }
399
- errorOutput.push('');
400
- });
401
- errorOutput.push(_chalk.default.bold.red(`SQL validation failed due to ${problemsFound} error(s)`));
402
- if (options.isImport) {
403
- throw new Error(errorOutput.join('\n'));
404
- }
405
- exit.withError(errorOutput.join('\n'));
406
- }
407
- if (!options.isImport) {
408
- console.log(formattedInfos.join('\n'));
409
- console.log('');
410
- }
411
- await (0, _tracker.trackEvent)('import_validate_sql_command_success', {
412
- is_import: options.isImport
413
- });
348
+ return [...new Set(filtered)];
349
+ }
350
+ const postValidation = async (options) => {
351
+ await (0, tracker_1.trackEvent)('import_validate_sql_command_execute', { is_import: options.isImport });
352
+ if (!options.isImport) {
353
+ (0, single_line_log_1.stdout)(`Finished processing ${lineNum} lines.`);
354
+ console.log('\n');
355
+ }
356
+ const errorSummary = {};
357
+ const checkEntries = Object.entries(checks).filter(([type]) => !options.skipChecks.includes(type));
358
+ const formattedWarnings = [];
359
+ let formattedErrors = [];
360
+ let formattedInfos = [];
361
+ for (const [type, check] of checkEntries) {
362
+ const formattedOutput = check.outputFormatter(check, type, options.isImport);
363
+ for (const error of formattedOutput.errors) {
364
+ if ('warning' in error) {
365
+ formattedWarnings.push(error);
366
+ }
367
+ else {
368
+ formattedErrors.push(error);
369
+ }
370
+ }
371
+ formattedInfos = formattedInfos.concat(formattedOutput.infos);
372
+ errorSummary[type] = check.results.length;
373
+ }
374
+ errorSummary.problems_found = problemsFound;
375
+ const tableNamesSet = new Set(tableNames);
376
+ if (tableNames.length > tableNamesSet.size) {
377
+ // there was a duplciate table
378
+ problemsFound++;
379
+ const duplicates = findDuplicates(tableNames, tableNamesSet);
380
+ const errorObject = {
381
+ error: formatError('Duplicate table names were found: ' + duplicates.join(',')),
382
+ recommendation: formatRecommendation('Ensure that there are no duplicate tables in your SQL dump'),
383
+ };
384
+ formattedErrors = formattedErrors.concat(errorObject);
385
+ }
386
+ if (formattedWarnings.length) {
387
+ const warningOutput = [];
388
+ formattedWarnings.forEach(warning => {
389
+ warningOutput.push(warning.warning);
390
+ if (warning.recommendation) {
391
+ warningOutput.push(warning.recommendation);
392
+ }
393
+ warningOutput.push('');
394
+ });
395
+ console.log(warningOutput.join('\n'));
396
+ console.log('');
397
+ }
398
+ if (problemsFound > 0) {
399
+ await (0, tracker_1.trackEvent)('import_validate_sql_command_failure', {
400
+ is_import: options.isImport,
401
+ error: errorSummary,
402
+ });
403
+ const errorOutput = [];
404
+ formattedErrors.forEach(error => {
405
+ errorOutput.push(error.error);
406
+ if (error.recommendation) {
407
+ errorOutput.push(error.recommendation);
408
+ }
409
+ errorOutput.push('');
410
+ });
411
+ errorOutput.push(chalk_1.default.bold.red(`SQL validation failed due to ${problemsFound} error(s)`));
412
+ if (options.isImport) {
413
+ throw new Error(errorOutput.join('\n'));
414
+ }
415
+ exit.withError(errorOutput.join('\n'));
416
+ }
417
+ if (!options.isImport) {
418
+ console.log(formattedInfos.join('\n'));
419
+ console.log('');
420
+ }
421
+ await (0, tracker_1.trackEvent)('import_validate_sql_command_success', { is_import: options.isImport });
414
422
  };
415
423
  const getTableNames = () => {
416
- return tableNames;
424
+ return tableNames;
417
425
  };
418
426
  exports.getTableNames = getTableNames;
419
- const checkForTableName = line => {
420
- const matches = /(?<=^CREATE\sTABLE\s)`?(?:(wp_[\d+_]?\w+))`?/.exec(line);
421
- if (matches) {
422
- const tableName = matches[1];
423
- // we should only have one match if we have any since we're looking at the start of the string
424
- tableNames.push(tableName);
425
- }
427
+ const checkForTableName = (line) => {
428
+ const matches = /(?<=^CREATE\sTABLE\s)`?(?:(wp_[\d+_]?\w+))`?/.exec(line);
429
+ if (matches) {
430
+ const tableName = matches[1];
431
+ // we should only have one match if we have any since we're looking at the start of the string
432
+ tableNames.push(tableName);
433
+ }
434
+ };
435
+ const collectInsertColumnList = (line, startIndex) => {
436
+ if (undefined !== currentInsertStatementColumnList) {
437
+ const closingParenthesisIndex = line.indexOf(')');
438
+ if (-1 === closingParenthesisIndex) {
439
+ currentInsertStatementColumnList += `\n${line}`;
440
+ return undefined;
441
+ }
442
+ const columnList = `${currentInsertStatementColumnList}\n${line.slice(0, closingParenthesisIndex)}`;
443
+ currentInsertStatementColumnList = undefined;
444
+ return (0, sql_insert_parser_1.parseInsertColumnListSegment)(columnList);
445
+ }
446
+ const valuesIndex = (0, sql_insert_parser_1.findValuesKeywordIndex)(line);
447
+ const openingParenthesisIndex = line.indexOf('(', startIndex);
448
+ if (-1 === openingParenthesisIndex ||
449
+ (-1 !== valuesIndex && openingParenthesisIndex > valuesIndex)) {
450
+ return undefined;
451
+ }
452
+ const closingParenthesisIndex = line.indexOf(')', openingParenthesisIndex + 1);
453
+ if (-1 !== closingParenthesisIndex) {
454
+ return (0, sql_insert_parser_1.parseInsertColumnListSegment)(line.slice(openingParenthesisIndex + 1, closingParenthesisIndex));
455
+ }
456
+ currentInsertStatementColumnList = line.slice(openingParenthesisIndex + 1);
457
+ return undefined;
458
+ };
459
+ const isSqlCommentOnlyLine = (line) => {
460
+ return '' === line.trim();
461
+ };
462
+ const collectOptionUrlMatchesFromRows = (rows) => {
463
+ return rows
464
+ .map(row => (0, sql_insert_parser_1.getOptionUrlMatchResults)(row, currentInsertStatementColumns))
465
+ .filter((results) => Boolean(results));
466
+ };
467
+ const collectOptionsInsertRows = (line, startIndex) => {
468
+ const lineSegment = line.slice(startIndex);
469
+ const parseInput = currentInsertStatementRowBuffer
470
+ ? `${currentInsertStatementRowBuffer}\n${lineSegment}`
471
+ : lineSegment;
472
+ const { rows, remainder, finished } = (0, sql_insert_parser_1.parseSqlTupleRows)(parseInput, 0);
473
+ currentInsertStatementRowBuffer = remainder;
474
+ currentInsertStatementValuesFinished = Boolean(finished);
475
+ return collectOptionUrlMatchesFromRows(rows);
476
+ };
477
+ const collectOptionsInsertMatches = (uncommentedLine) => {
478
+ if (!(0, sql_insert_parser_1.isWordPressOptionsTable)(currentInsertStatementTableName)) {
479
+ return [];
480
+ }
481
+ if (currentInsertStatementValuesFinished) {
482
+ return [];
483
+ }
484
+ if (isSqlCommentOnlyLine(uncommentedLine)) {
485
+ return [];
486
+ }
487
+ if (!currentInsertStatementHasValues) {
488
+ currentInsertStatementColumns =
489
+ currentInsertStatementColumns ?? collectInsertColumnList(uncommentedLine, 0);
490
+ const valuesKeyword = (0, sql_insert_parser_1.findValuesKeyword)(uncommentedLine);
491
+ if (!valuesKeyword) {
492
+ return [];
493
+ }
494
+ currentInsertStatementHasValues = true;
495
+ return collectOptionsInsertRows(uncommentedLine, valuesKeyword.endIndex);
496
+ }
497
+ return collectOptionsInsertRows(uncommentedLine, 0);
426
498
  };
427
499
  const DEFAULT_VALIDATION_OPTIONS = {
428
- isImport: true,
429
- skipChecks: DEV_ENV_SPECIFIC_CHECKS,
430
- extraCheckParams: {}
500
+ isImport: true,
501
+ skipChecks: DEV_ENV_SPECIFIC_CHECKS,
502
+ extraCheckParams: {},
503
+ };
504
+ const resetFinishedInsertStatement = (uncommentedLine) => {
505
+ if (currentInsertStatementTableName &&
506
+ !currentInsertStatementRowBuffer &&
507
+ !currentSqlCommentStripState.quote &&
508
+ uncommentedLine.length > 0 &&
509
+ uncommentedLine.trimEnd().endsWith(';')) {
510
+ currentInsertStatementTableName = undefined;
511
+ currentInsertStatementColumns = undefined;
512
+ currentInsertStatementColumnList = undefined;
513
+ currentInsertStatementHasValues = false;
514
+ currentInsertStatementValuesFinished = false;
515
+ currentInsertStatementRowBuffer = undefined;
516
+ }
431
517
  };
432
518
  const perLineValidations = (line, options = DEFAULT_VALIDATION_OPTIONS) => {
433
- if (options.isImport && lineNum % 500 === 0) {
434
- (0, _singleLineLog.stdout)(`Reading line ${lineNum} `);
435
- }
436
- checkForTableName(line);
437
- const checkKeys = Object.keys(checks).filter(checkItem => !options.skipChecks.includes(checkItem));
438
- for (const checkKey of checkKeys) {
439
- const check = checks[checkKey];
440
- const results = line.match(check.matcher); // NOSONAR
441
- const extraCheckParams = options.extraCheckParams[checkKey];
442
- if (results) {
443
- check.results.push(check.matchHandler(lineNum, results, extraCheckParams));
444
- }
445
- }
446
- lineNum += 1;
519
+ if (options.isImport && lineNum % 500 === 0) {
520
+ (0, single_line_log_1.stdout)(`Reading line ${lineNum} `);
521
+ }
522
+ checkForTableName(line);
523
+ const wasInQuotedValue = Boolean(currentSqlCommentStripState.quote);
524
+ const rawInsertInfo = wasInQuotedValue ? undefined : (0, sql_insert_parser_1.getInsertStatementInfo)(line);
525
+ const shouldStripComments = currentSqlCommentStripState.inBlockComment ||
526
+ Boolean(currentSqlCommentStripState.quote) ||
527
+ line.includes('/*') ||
528
+ Boolean(currentInsertStatementTableName) ||
529
+ Boolean(rawInsertInfo);
530
+ const uncommentedLine = shouldStripComments
531
+ ? (0, sql_insert_parser_1.stripSqlCommentsOutsideQuotedStrings)(line, currentSqlCommentStripState)
532
+ : line;
533
+ let insertStatementInfo = rawInsertInfo;
534
+ if (!wasInQuotedValue && shouldStripComments) {
535
+ insertStatementInfo = (0, sql_insert_parser_1.getInsertStatementInfo)(uncommentedLine);
536
+ }
537
+ if (insertStatementInfo) {
538
+ currentInsertStatementTableName = insertStatementInfo.tableName;
539
+ currentInsertStatementColumns = (0, sql_insert_parser_1.parseInsertColumnList)(uncommentedLine, insertStatementInfo.tableEndIndex);
540
+ currentInsertStatementColumnList = undefined;
541
+ currentInsertStatementHasValues = false;
542
+ currentInsertStatementValuesFinished = false;
543
+ currentInsertStatementRowBuffer = undefined;
544
+ }
545
+ const optionsInsertMatches = currentInsertStatementTableName
546
+ ? collectOptionsInsertMatches(uncommentedLine)
547
+ : [];
548
+ const checkKeys = Object.keys(checks).filter(checkItem => !options.skipChecks.includes(checkItem));
549
+ for (const checkKey of checkKeys) {
550
+ const check = checks[checkKey];
551
+ const extraCheckParams = options.extraCheckParams[checkKey];
552
+ if ((0, sql_insert_parser_1.checkRequiresOptionsInsertContext)(checkKey)) {
553
+ for (const results of optionsInsertMatches) {
554
+ check.results.push(check.matchHandler(lineNum, results, extraCheckParams));
555
+ }
556
+ continue;
557
+ }
558
+ const results = check.matcher === undefined ? null : line.match(check.matcher); // NOSONAR
559
+ if (results) {
560
+ check.results.push(check.matchHandler(lineNum, results, extraCheckParams));
561
+ }
562
+ }
563
+ resetFinishedInsertStatement(uncommentedLine);
564
+ lineNum += 1;
447
565
  };
448
- const postLineExecutionProcessing = async ({
449
- isImport,
450
- skipChecks
451
- }) => {
452
- await postValidation({
453
- isImport: isImport ?? false,
454
- skipChecks: skipChecks ?? DEV_ENV_SPECIFIC_CHECKS,
455
- extraCheckParams: {}
456
- });
566
+ const postLineExecutionProcessing = async ({ isImport, skipChecks, }) => {
567
+ await postValidation({
568
+ isImport: isImport ?? false,
569
+ skipChecks: skipChecks ?? DEV_ENV_SPECIFIC_CHECKS,
570
+ extraCheckParams: {},
571
+ });
457
572
  };
458
- const staticSqlValidations = exports.staticSqlValidations = {
459
- execute: perLineValidations,
460
- postLineExecutionProcessing
573
+ exports.staticSqlValidations = {
574
+ execute: perLineValidations,
575
+ postLineExecutionProcessing,
461
576
  };
462
-
463
577
  // For standalone SQL validations
464
578
  const validate = async (filename, options = DEFAULT_VALIDATION_OPTIONS) => {
465
- const fileMeta = await (0, _clientFileUploader.getFileMeta)(filename);
466
- if (fileMeta.isCompressed) {
467
- exit.withError('Compressed files cannot be validated. Please extract the archive and re-run the command, providing the path to the extracted SQL file.');
468
- }
469
- const readInterface = await (0, _lineByLine.getReadInterface)(filename);
470
- options.isImport = false;
471
- readInterface.on('line', line => {
472
- perLineValidations(line, options);
473
- });
474
-
475
- // Block until the processing completes
476
- await (0, _nodeEvents.once)(readInterface, 'close');
477
- await postLineExecutionProcessing({
478
- isImport: options.isImport,
479
- skipChecks: options.skipChecks
480
- });
579
+ currentInsertStatementTableName = undefined;
580
+ currentInsertStatementColumns = undefined;
581
+ currentInsertStatementColumnList = undefined;
582
+ currentInsertStatementHasValues = false;
583
+ currentInsertStatementValuesFinished = false;
584
+ currentInsertStatementRowBuffer = undefined;
585
+ currentSqlCommentStripState = { inBlockComment: false };
586
+ const fileMeta = await (0, client_file_uploader_1.getFileMeta)(filename);
587
+ if (fileMeta.isCompressed) {
588
+ exit.withError('Compressed files cannot be validated. Please extract the archive and re-run the command, providing the path to the extracted SQL file.');
589
+ }
590
+ const readInterface = await (0, line_by_line_1.getReadInterface)(filename);
591
+ options.isImport = false;
592
+ readInterface.on('line', line => {
593
+ perLineValidations(line, options);
594
+ });
595
+ // Block until the processing completes
596
+ await (0, node_events_1.once)(readInterface, 'close');
597
+ await postLineExecutionProcessing({
598
+ isImport: options.isImport,
599
+ skipChecks: options.skipChecks,
600
+ });
481
601
  };
482
- exports.validate = validate;
602
+ exports.validate = validate;