@opencrvs/toolkit 2.2.0-rc.ac299dc → 2.2.0-rc.e6591c5

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 (249) hide show
  1. package/build.sh +17 -14
  2. package/dist/application-config/index.js +21 -11
  3. package/dist/authentication/index.d.ts +2 -1
  4. package/dist/authentication/index.js +20 -13
  5. package/dist/cli.js +2631 -377
  6. package/dist/commons/api/router.d.ts +263 -250
  7. package/dist/commons/application-config/index.d.ts +3 -3
  8. package/dist/commons/conditionals/conditionals.d.ts +4 -4
  9. package/dist/commons/conditionals/index.d.ts +1 -0
  10. package/dist/commons/conditionals/validate.d.ts +6 -1
  11. package/dist/commons/events/ActionConfig.d.ts +16 -23
  12. package/dist/commons/events/ActionDocument.d.ts +1 -0
  13. package/dist/commons/events/ActionInput.d.ts +4 -4
  14. package/dist/commons/events/ActionStatus.d.ts +2 -2
  15. package/dist/commons/events/ActionType.d.ts +2 -0
  16. package/dist/commons/events/AdvancedSearchConfig.d.ts +3 -6
  17. package/dist/commons/events/CompositeFieldValue.d.ts +5 -1
  18. package/dist/commons/events/CountryConfigQueryInput.d.ts +0 -18
  19. package/dist/commons/events/Draft.d.ts +34 -1
  20. package/dist/commons/events/EventConfig.d.ts +448 -1
  21. package/dist/commons/events/EventDocument.d.ts +2 -0
  22. package/dist/commons/events/EventIndex.d.ts +3 -6
  23. package/dist/commons/events/EventInput.d.ts +1 -0
  24. package/dist/commons/events/EventMetadata.d.ts +1 -1
  25. package/dist/commons/events/FieldConfig.d.ts +1 -1
  26. package/dist/commons/events/FieldTypeMapping.d.ts +17 -17
  27. package/dist/commons/events/Flag.d.ts +1 -7
  28. package/dist/commons/events/PlainDate.d.ts +6 -0
  29. package/dist/commons/events/WorkqueueConfig.d.ts +12 -27
  30. package/dist/commons/events/defineConfig.d.ts +7 -2
  31. package/dist/commons/events/event.d.ts +4 -1
  32. package/dist/commons/events/eventConfigValidation.d.ts +9 -0
  33. package/dist/commons/events/field.d.ts +5 -5
  34. package/dist/commons/events/index.d.ts +3 -0
  35. package/dist/commons/events/locations.d.ts +1 -1
  36. package/dist/commons/events/scopes.d.ts +2 -1
  37. package/dist/commons/events/state/flags.d.ts +1 -1
  38. package/dist/commons/events/state/index.d.ts +1 -0
  39. package/dist/commons/events/test.utils.d.ts +62 -7
  40. package/dist/commons/events/toNotificationForm.d.ts +17 -0
  41. package/dist/commons/events/utils.d.ts +59 -7
  42. package/dist/commons/users/Role.d.ts +23 -0
  43. package/dist/commons/users/User.d.ts +263 -0
  44. package/dist/commons/users/authentication.d.ts +67 -0
  45. package/dist/commons/users/index.d.ts +5 -0
  46. package/dist/commons/users/roleValidations.d.ts +15 -0
  47. package/dist/commons/users/scopes.d.ts +1402 -0
  48. package/dist/commons/users/userReferences.d.ts +176 -0
  49. package/dist/conditionals/index.js +5 -6
  50. package/dist/configurator/index.d.ts +24 -0
  51. package/dist/configurator/index.d.ts.map +1 -0
  52. package/dist/configurator/index.js +161 -0
  53. package/dist/configurator/layout.d.ts +29 -0
  54. package/dist/configurator/layout.d.ts.map +1 -0
  55. package/dist/configurator/layout.js +78 -0
  56. package/dist/configurator/paths.d.ts +13 -0
  57. package/dist/configurator/paths.d.ts.map +1 -0
  58. package/dist/configurator/paths.js +48 -0
  59. package/dist/configurator/server/environments.d.ts +20 -0
  60. package/dist/configurator/server/environments.d.ts.map +1 -0
  61. package/dist/configurator/server/environments.js +143 -0
  62. package/dist/configurator/server/files.d.ts +11 -0
  63. package/dist/configurator/server/files.d.ts.map +1 -0
  64. package/dist/configurator/server/files.js +67 -0
  65. package/dist/configurator/server/github.d.ts +56 -0
  66. package/dist/configurator/server/github.d.ts.map +1 -0
  67. package/dist/configurator/server/github.js +239 -0
  68. package/dist/configurator/server/plugin.d.ts +39 -0
  69. package/dist/configurator/server/plugin.d.ts.map +1 -0
  70. package/dist/configurator/server/plugin.js +298 -0
  71. package/dist/configurator/server/seal.d.ts +2 -0
  72. package/dist/configurator/server/seal.d.ts.map +1 -0
  73. package/dist/configurator/server/seal.js +36 -0
  74. package/dist/configurator/server/sshKeys.d.ts +5 -0
  75. package/dist/configurator/server/sshKeys.d.ts.map +1 -0
  76. package/dist/configurator/server/sshKeys.js +28 -0
  77. package/dist/configurator/server/start.d.ts +12 -0
  78. package/dist/configurator/server/start.d.ts.map +1 -0
  79. package/dist/configurator/server/start.js +91 -0
  80. package/dist/configurator/testing.d.ts +11 -0
  81. package/dist/configurator/testing.d.ts.map +1 -0
  82. package/dist/configurator/testing.js +74 -0
  83. package/dist/configurator/ui/bindings/bindings.d.ts +35 -0
  84. package/dist/configurator/ui/bindings/bindings.d.ts.map +1 -0
  85. package/dist/configurator/ui/bindings/bindings.js +5 -0
  86. package/dist/configurator/ui/bindings/parsers.d.ts +7 -0
  87. package/dist/configurator/ui/bindings/parsers.d.ts.map +1 -0
  88. package/dist/configurator/ui/bindings/parsers.js +85 -0
  89. package/dist/configurator/ui/form/users.d.ts +11 -0
  90. package/dist/configurator/ui/form/users.d.ts.map +1 -0
  91. package/dist/configurator/ui/form/users.js +33 -0
  92. package/dist/configurator/ui/plan/dependencyHosts.d.ts +2 -0
  93. package/dist/configurator/ui/plan/dependencyHosts.d.ts.map +1 -0
  94. package/dist/configurator/ui/plan/dependencyHosts.js +36 -0
  95. package/dist/configurator/ui/plan/templateValues.d.ts +11 -0
  96. package/dist/configurator/ui/plan/templateValues.d.ts.map +1 -0
  97. package/dist/configurator/ui/plan/templateValues.js +70 -0
  98. package/dist/configurator/workflows.d.ts +54 -0
  99. package/dist/configurator/workflows.d.ts.map +1 -0
  100. package/dist/configurator/workflows.js +161 -0
  101. package/dist/configurator-assets/forms/bindings.yml +265 -0
  102. package/dist/configurator-assets/templates/README.md +18 -0
  103. package/dist/configurator-assets/templates/charts-values/dependencies/values.override.yaml +4 -0
  104. package/dist/configurator-assets/templates/charts-values/dependencies/values.yaml +96 -0
  105. package/dist/configurator-assets/templates/charts-values/opencrvs-services/values.override.yaml +4 -0
  106. package/dist/configurator-assets/templates/charts-values/opencrvs-services/values.yaml +83 -0
  107. package/dist/configurator-assets/templates/charts-values/opentelemetry/values.yaml +102 -0
  108. package/dist/configurator-assets/templates/charts-values/traefik/values.override.yaml +4 -0
  109. package/dist/configurator-assets/templates/charts-values/traefik/values.yaml +130 -0
  110. package/dist/configurator-assets/templates/inventory/inventory.template.yml +98 -0
  111. package/dist/configurator-assets/ui/apple-touch-icon.png +0 -0
  112. package/dist/configurator-assets/ui/assets/index-CaqYFJUk.css +6 -0
  113. package/dist/configurator-assets/ui/assets/index-DU1Y6E0b.js +169 -0
  114. package/dist/configurator-assets/ui/assets/opencrvs-logo-sIjz08HT.svg +1 -0
  115. package/dist/configurator-assets/ui/assets/poppins-400-BwTUGeWf.woff2 +0 -0
  116. package/dist/configurator-assets/ui/assets/poppins-500-CWICHMj6.woff2 +0 -0
  117. package/dist/configurator-assets/ui/assets/poppins-600-DJVo7c07.woff2 +0 -0
  118. package/dist/configurator-assets/ui/assets/poppins-700-g9MkRaG0.woff2 +0 -0
  119. package/dist/configurator-assets/ui/favicon-32x32.png +0 -0
  120. package/dist/configurator-assets/ui/index.html +25 -0
  121. package/dist/environment/custom-types.d.ts +1 -0
  122. package/dist/environment/custom-types.d.ts.map +1 -1
  123. package/dist/environment/derived-variables.d.ts +18 -4
  124. package/dist/environment/derived-variables.d.ts.map +1 -1
  125. package/dist/environment/derived-variables.js +20 -4
  126. package/dist/environment/questions.d.ts +42 -9
  127. package/dist/environment/questions.d.ts.map +1 -1
  128. package/dist/environment/questions.js +71 -48
  129. package/dist/environment/registry.d.ts +15 -0
  130. package/dist/environment/registry.d.ts.map +1 -0
  131. package/dist/environment/registry.js +112 -0
  132. package/dist/environment/setup-environment.d.ts.map +1 -1
  133. package/dist/environment/setup-environment.js +145 -25
  134. package/dist/environment/templates.d.ts.map +1 -1
  135. package/dist/events/index.js +826 -210
  136. package/dist/migrations/add-notify-config.d.ts +40 -0
  137. package/dist/migrations/add-notify-config.d.ts.map +1 -0
  138. package/dist/migrations/add-notify-config.js +249 -0
  139. package/dist/migrations/index.d.ts +9 -0
  140. package/dist/migrations/index.d.ts.map +1 -0
  141. package/dist/migrations/index.js +1306 -0
  142. package/dist/migrations/move-declaration-to-declare-action.d.ts +38 -0
  143. package/dist/migrations/move-declaration-to-declare-action.d.ts.map +1 -0
  144. package/dist/migrations/move-declaration-to-declare-action.js +260 -0
  145. package/dist/migrations/{add-translations.d.ts → persistent/add-translations.d.ts} +1 -1
  146. package/dist/migrations/persistent/add-translations.d.ts.map +1 -0
  147. package/dist/migrations/{add-translations.js → persistent/add-translations.js} +2 -2
  148. package/dist/migrations/persistent/check-upgrade-path.d.ts +36 -0
  149. package/dist/migrations/persistent/check-upgrade-path.d.ts.map +1 -0
  150. package/dist/migrations/persistent/check-upgrade-path.js +105 -0
  151. package/dist/migrations/persistent/update-toolkit-dependency.d.ts +7 -0
  152. package/dist/migrations/persistent/update-toolkit-dependency.d.ts.map +1 -0
  153. package/dist/migrations/persistent/update-toolkit-dependency.js +77 -0
  154. package/dist/migrations/{v2.2/read-declaration-through-helper.d.ts → read-declaration-through-helper.d.ts} +1 -1
  155. package/dist/migrations/read-declaration-through-helper.d.ts.map +1 -0
  156. package/dist/migrations/{v2.2/read-declaration-through-helper.js → read-declaration-through-helper.js} +4 -62
  157. package/dist/migrations/replace-incomplete-flag.d.ts +26 -0
  158. package/dist/migrations/replace-incomplete-flag.d.ts.map +1 -0
  159. package/dist/migrations/replace-incomplete-flag.js +126 -0
  160. package/dist/migrations/resolve-versioned-event-config.d.ts +56 -0
  161. package/dist/migrations/resolve-versioned-event-config.d.ts.map +1 -0
  162. package/dist/migrations/resolve-versioned-event-config.js +353 -0
  163. package/dist/migrations/utils.d.ts +61 -0
  164. package/dist/migrations/utils.d.ts.map +1 -0
  165. package/dist/migrations/utils.js +218 -0
  166. package/dist/notification/index.js +722 -82
  167. package/dist/roles/index.d.ts +2 -0
  168. package/dist/roles/index.d.ts.map +1 -0
  169. package/dist/roles/index.js +730 -0
  170. package/dist/scopes/index.d.ts +54 -94
  171. package/dist/scopes/index.js +15 -12
  172. package/dist/templates/charts-values/dependencies/values.yaml +5 -2
  173. package/dist/templates/charts-values/opencrvs-services/values.yaml +5 -7
  174. package/dist/templates/charts-values/traefik/values.yaml +2 -0
  175. package/dist/verify/endpoints.d.ts +11 -0
  176. package/dist/verify/endpoints.d.ts.map +1 -1
  177. package/dist/verify/endpoints.js +21 -27
  178. package/opencrvs-toolkit-2.2.0-rc.e6591c5.tgz +0 -0
  179. package/package.json +17 -4
  180. package/tsconfig.build.json +11 -1
  181. package/tsconfig.build.tsbuildinfo +1 -1
  182. package/tsconfig.json +15 -6
  183. package/dist/migrations/add-translations.d.ts.map +0 -1
  184. package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts +0 -3
  185. package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts.map +0 -1
  186. package/dist/migrations/v2.1/add-explicit-correction-flags.js +0 -234
  187. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +0 -3
  188. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +0 -1
  189. package/dist/migrations/v2.1/add-recovery-link-notifications.js +0 -511
  190. package/dist/migrations/v2.1/enable-telemetry.d.ts +0 -3
  191. package/dist/migrations/v2.1/enable-telemetry.d.ts.map +0 -1
  192. package/dist/migrations/v2.1/enable-telemetry.js +0 -455
  193. package/dist/migrations/v2.1/index.d.ts +0 -6
  194. package/dist/migrations/v2.1/index.d.ts.map +0 -1
  195. package/dist/migrations/v2.1/index.js +0 -50
  196. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts +0 -17
  197. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts.map +0 -1
  198. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.js +0 -348
  199. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts +0 -2
  200. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts.map +0 -1
  201. package/dist/migrations/v2.1/remove-metabase-package-installs.js +0 -161
  202. package/dist/migrations/v2.1/remove-sentry.d.ts +0 -3
  203. package/dist/migrations/v2.1/remove-sentry.d.ts.map +0 -1
  204. package/dist/migrations/v2.1/remove-sentry.js +0 -354
  205. package/dist/migrations/v2.1/rename-trigger-paths.d.ts +0 -3
  206. package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +0 -1
  207. package/dist/migrations/v2.1/rename-trigger-paths.js +0 -216
  208. package/dist/migrations/v2.1/template-files.d.ts +0 -8
  209. package/dist/migrations/v2.1/template-files.d.ts.map +0 -1
  210. package/dist/migrations/v2.1/template-files.js +0 -49
  211. package/dist/migrations/v2.1/upgrade-tilt.d.ts +0 -11
  212. package/dist/migrations/v2.1/upgrade-tilt.d.ts.map +0 -1
  213. package/dist/migrations/v2.1/upgrade-tilt.js +0 -139
  214. package/dist/migrations/v2.2/index.d.ts +0 -6
  215. package/dist/migrations/v2.2/index.d.ts.map +0 -1
  216. package/dist/migrations/v2.2/index.js +0 -456
  217. package/dist/migrations/v2.2/read-declaration-through-helper.d.ts.map +0 -1
  218. package/dist/templates/countryconfig-template/.tiltignore +0 -1
  219. package/dist/templates/countryconfig-template/Dockerfile.assets +0 -7
  220. package/dist/templates/countryconfig-template/Tiltfile +0 -112
  221. package/dist/templates/countryconfig-template/assets/README.md +0 -1
  222. package/dist/templates/countryconfig-template/assets/clear-all-data-dev.sh +0 -61
  223. package/dist/templates/countryconfig-template/assets/deployment/deploy.sh +0 -455
  224. package/dist/templates/countryconfig-template/assets/deployment/reindex.sh +0 -168
  225. package/dist/templates/countryconfig-template/assets/deployment/validate-required-variables-in-compose-files.ts +0 -67
  226. package/dist/templates/countryconfig-template/assets/elasticsearch/reindex.sh +0 -168
  227. package/dist/templates/countryconfig-template/assets/metabase/README.md +0 -34
  228. package/dist/templates/countryconfig-template/assets/metabase/environment-configuration.sql +0 -36
  229. package/dist/templates/countryconfig-template/assets/metabase/initialize-database.sh +0 -46
  230. package/dist/templates/countryconfig-template/assets/metabase/metabase.init.db.sql +0 -27737
  231. package/dist/templates/countryconfig-template/assets/metabase/open-shell.sh +0 -21
  232. package/dist/templates/countryconfig-template/assets/metabase/package.json +0 -13
  233. package/dist/templates/countryconfig-template/assets/metabase/run-dev.sh +0 -108
  234. package/dist/templates/countryconfig-template/assets/metabase/run.sh +0 -120
  235. package/dist/templates/countryconfig-template/assets/metabase/update-database.sh +0 -40
  236. package/dist/templates/countryconfig-template/assets/postgres/setup-analytics.sh +0 -135
  237. package/dist/templates/countryconfig-template/assets/postgres/setup-reference-data.sh +0 -108
  238. package/dist/templates/countryconfig-template/tilt/clear-all-data.ps1 +0 -50
  239. package/dist/templates/countryconfig-template/tilt/clear-all-data.sh +0 -35
  240. package/dist/templates/countryconfig-template/tilt/common.tilt +0 -145
  241. package/dist/templates/countryconfig-template/tilt/examples/dependencies/values.yaml +0 -15
  242. package/dist/templates/countryconfig-template/tilt/examples/opencrvs-services/values.yaml +0 -56
  243. package/dist/templates/countryconfig-template/tilt/examples/traefik/values-minikube.yaml +0 -21
  244. package/dist/templates/countryconfig-template/tilt/examples/traefik/values.yaml +0 -38
  245. package/dist/templates/countryconfig-template/tilt/helm/dependencies/values.yaml +0 -17
  246. package/dist/templates/countryconfig-template/tilt/helm/opencrvs-services/values.yaml +0 -16
  247. package/dist/templates/countryconfig-template/tilt/lib.tilt +0 -95
  248. package/dist/templates/countryconfig-template/tilt/opencrvs.tilt +0 -136
  249. package/opencrvs-toolkit-2.2.0-rc.ac299dc.tgz +0 -0
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Helpers shared by the codemods, kept apart so a codemod can be removed
3
+ * without breaking the others.
4
+ */
5
+ import { CallExpression, Node, ObjectLiteralExpression, SourceFile } from 'ts-morph';
6
+ export declare function location(node: Node): string;
7
+ /**
8
+ * Returns true if the call is to the `defineConfig` published by the toolkit,
9
+ * as opposed to a function of the same name declared in the country config.
10
+ */
11
+ export declare function isToolkitDefineConfigCall(call: CallExpression): boolean;
12
+ /** Finds a property given by name, whether written `key: value` or shorthand. */
13
+ export declare function findProperty(literal: ObjectLiteralExpression, name: string): import("ts-morph").PropertyAssignment | import("ts-morph").ShorthandPropertyAssignment | undefined;
14
+ /**
15
+ * Returns true if the node may be the action of the given type. An action not
16
+ * written inline (a variable, a call, a spread) may be, unless its type shows
17
+ * it is some other action.
18
+ */
19
+ export declare function mayBeAction(node: Node, actionType: string): boolean;
20
+ export declare function isAction(literal: ObjectLiteralExpression, actionType: string): boolean;
21
+ /** The whitespace the line the node starts on is indented by. */
22
+ export declare function indentationOf(node: Node): string;
23
+ /** The text from the position to the end of its line, without the line break. */
24
+ export declare function restOfLine(text: string, position: number): string;
25
+ export declare function isOnlyComments(text: string): boolean;
26
+ /**
27
+ * Where a property sits in its object literal. A property on lines of its own
28
+ * owns the comments on the lines above it and the comment after it on its last
29
+ * line, and they move with it.
30
+ */
31
+ export interface PropertyLayout {
32
+ ownsLines: boolean;
33
+ /** The first comment above the property, or the property itself. */
34
+ start: number;
35
+ /** After the comma following the property, or the property when it has none. */
36
+ end: number;
37
+ hasComma: boolean;
38
+ /** The comment after the property on its last line, with the space before it. */
39
+ trailingComment: string;
40
+ }
41
+ export declare function layoutOf(property: Node): PropertyLayout;
42
+ export interface TextEdit {
43
+ start: number;
44
+ end: number;
45
+ text: string;
46
+ }
47
+ export declare function insertAt(position: number, text: string): TextEdit;
48
+ /**
49
+ * Applies the edits to the file together, as editing a node through ts-morph
50
+ * invalidates nodes still waiting to be edited.
51
+ */
52
+ export declare function applyTextEdits(sourceFile: SourceFile, edits: TextEdit[]): void;
53
+ /**
54
+ * Returns the name a toolkit export is called by in the file: its local alias
55
+ * when the file already imports it from the toolkit, its own name when the
56
+ * name is free, or undefined when the file binds that name to something else.
57
+ */
58
+ export declare function findToolkitImportName(sourceFile: SourceFile, name: string): string | undefined;
59
+ /** Adds the toolkit export to the file's toolkit import, unless already imported. */
60
+ export declare function addToolkitImport(sourceFile: SourceFile, name: string): void;
61
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/migrations/utils.ts"],"names":[],"mappings":"AAWA;;;GAGG;AAEH,OAAO,EACL,cAAc,EACd,IAAI,EACJ,uBAAuB,EACvB,UAAU,EAGX,MAAM,UAAU,CAAA;AAMjB,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,UAMlC;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,cAAc,WAW7D;AAED,iFAAiF;AACjF,wBAAgB,YAAY,CAAC,OAAO,EAAE,uBAAuB,EAAE,IAAI,EAAE,MAAM,sGAO1E;AA0BD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,WAkBzD;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,uBAAuB,EAAE,UAAU,EAAE,MAAM,WAO5E;AAED,iEAAiE;AACjE,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,UAKvC;AAED,iFAAiF;AACjF,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,UAIxD;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,WAE1C;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,OAAO,CAAA;IAClB,oEAAoE;IACpE,KAAK,EAAE,MAAM,CAAA;IACb,gFAAgF;IAChF,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,OAAO,CAAA;IACjB,iFAAiF;IACjF,eAAe,EAAE,MAAM,CAAA;CACxB;AAED,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,IAAI,GAAG,cAAc,CA+BvD;AAED,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;CACb;AAED,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,CAEjE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,QAYvE;AAcD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,sBAczE;AAED,qFAAqF;AACrF,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,QA4CpE"}
@@ -0,0 +1,218 @@
1
+ "use strict";
2
+ /*
3
+ * This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
+ *
7
+ * OpenCRVS is also distributed under the terms of the Civil Registration
8
+ * & Healthcare Disclaimer located at http://opencrvs.org/license.
9
+ *
10
+ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
11
+ */
12
+ var __importDefault = (this && this.__importDefault) || function (mod) {
13
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.location = location;
17
+ exports.isToolkitDefineConfigCall = isToolkitDefineConfigCall;
18
+ exports.findProperty = findProperty;
19
+ exports.mayBeAction = mayBeAction;
20
+ exports.isAction = isAction;
21
+ exports.indentationOf = indentationOf;
22
+ exports.restOfLine = restOfLine;
23
+ exports.isOnlyComments = isOnlyComments;
24
+ exports.layoutOf = layoutOf;
25
+ exports.insertAt = insertAt;
26
+ exports.applyTextEdits = applyTextEdits;
27
+ exports.findToolkitImportName = findToolkitImportName;
28
+ exports.addToolkitImport = addToolkitImport;
29
+ /**
30
+ * Helpers shared by the codemods, kept apart so a codemod can be removed
31
+ * without breaking the others.
32
+ */
33
+ const ts_morph_1 = require("ts-morph");
34
+ const path_1 = __importDefault(require("path"));
35
+ const DEFINE_CONFIG_NAME = 'defineConfig';
36
+ const TOOLKIT_EVENTS_MODULE = '@opencrvs/toolkit/events';
37
+ function location(node) {
38
+ const relPath = path_1.default.relative(process.cwd(), node.getSourceFile().getFilePath());
39
+ return `${relPath}:${node.getStartLineNumber()}`;
40
+ }
41
+ /**
42
+ * Returns true if the call is to the `defineConfig` published by the toolkit,
43
+ * as opposed to a function of the same name declared in the country config.
44
+ */
45
+ function isToolkitDefineConfigCall(call) {
46
+ var _a;
47
+ const symbol = call.getExpression().getSymbol();
48
+ const resolved = (_a = symbol === null || symbol === void 0 ? void 0 : symbol.getAliasedSymbol()) !== null && _a !== void 0 ? _a : symbol;
49
+ if ((resolved === null || resolved === void 0 ? void 0 : resolved.getName()) !== DEFINE_CONFIG_NAME) {
50
+ return false;
51
+ }
52
+ return resolved
53
+ .getDeclarations()
54
+ .some((declaration) => declaration.getSourceFile().isDeclarationFile());
55
+ }
56
+ /** Finds a property given by name, whether written `key: value` or shorthand. */
57
+ function findProperty(literal, name) {
58
+ const property = literal.getProperty(name);
59
+ return ts_morph_1.Node.isPropertyAssignment(property) ||
60
+ ts_morph_1.Node.isShorthandPropertyAssignment(property)
61
+ ? property
62
+ : undefined;
63
+ }
64
+ /**
65
+ * Returns false only if the action type's `type` is known to be some other
66
+ * action: a string literal, or a union of them, other than the given one.
67
+ */
68
+ function mayHaveActionType(actionType, node, expectedActionType) {
69
+ const typeProperty = actionType.getProperty('type');
70
+ if (!typeProperty) {
71
+ return true;
72
+ }
73
+ const type = typeProperty.getTypeAtLocation(node);
74
+ const values = type.isUnion() ? type.getUnionTypes() : [type];
75
+ return !values.every((value) => value.isStringLiteral() && value.getLiteralValue() !== expectedActionType);
76
+ }
77
+ /**
78
+ * Returns true if the node may be the action of the given type. An action not
79
+ * written inline (a variable, a call, a spread) may be, unless its type shows
80
+ * it is some other action.
81
+ */
82
+ function mayBeAction(node, actionType) {
83
+ if (ts_morph_1.Node.isObjectLiteralExpression(node)) {
84
+ return isAction(node, actionType);
85
+ }
86
+ if (ts_morph_1.Node.isSpreadElement(node)) {
87
+ const arrayType = node.getExpression().getType();
88
+ const elementTypes = arrayType.isTuple()
89
+ ? arrayType.getTupleElements()
90
+ : [arrayType.getArrayElementType()];
91
+ return elementTypes.some((elementType) => !elementType || mayHaveActionType(elementType, node, actionType));
92
+ }
93
+ return mayHaveActionType(node.getType(), node, actionType);
94
+ }
95
+ function isAction(literal, actionType) {
96
+ const type = findProperty(literal, 'type');
97
+ return (ts_morph_1.Node.isPropertyAssignment(type) &&
98
+ type.getInitializerOrThrow().getType().getLiteralValue() === actionType);
99
+ }
100
+ /** The whitespace the line the node starts on is indented by. */
101
+ function indentationOf(node) {
102
+ var _a;
103
+ var _b;
104
+ const text = node.getSourceFile().getFullText();
105
+ const lineStart = text.lastIndexOf('\n', node.getStart() - 1) + 1;
106
+ return (_b = (_a = /^[ \t]*/.exec(text.slice(lineStart))) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : '';
107
+ }
108
+ /** The text from the position to the end of its line, without the line break. */
109
+ function restOfLine(text, position) {
110
+ const lineEnd = text.indexOf('\n', position);
111
+ return text.slice(position, lineEnd === -1 ? text.length : lineEnd);
112
+ }
113
+ function isOnlyComments(text) {
114
+ return /^\s*(?:\/\/.*|\/\*.*?\*\/\s*)*$/.test(text);
115
+ }
116
+ function layoutOf(property) {
117
+ var _a;
118
+ var _b;
119
+ const text = property.getSourceFile().getFullText();
120
+ const next = property.getNextSibling();
121
+ const hasComma = (next === null || next === void 0 ? void 0 : next.getKind()) === ts_morph_1.SyntaxKind.CommaToken;
122
+ const end = next && hasComma ? next.getEnd() : property.getEnd();
123
+ const trailing = restOfLine(text, end);
124
+ // A comment on the line the previous property ends on is that property's
125
+ const lineBreak = text
126
+ .slice(property.getFullStart(), property.getStart())
127
+ .indexOf('\n');
128
+ if (lineBreak === -1 || !isOnlyComments(trailing)) {
129
+ return {
130
+ ownsLines: false,
131
+ start: property.getStart(true),
132
+ end,
133
+ hasComma,
134
+ trailingComment: ''
135
+ };
136
+ }
137
+ const firstLine = property.getFullStart() + lineBreak + 1;
138
+ return {
139
+ ownsLines: true,
140
+ start: firstLine + ((_b = (_a = /^\s*/.exec(text.slice(firstLine))) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0),
141
+ end,
142
+ hasComma,
143
+ trailingComment: trailing.trimEnd()
144
+ };
145
+ }
146
+ function insertAt(position, text) {
147
+ return { start: position, end: position, text };
148
+ }
149
+ /**
150
+ * Applies the edits to the file together, as editing a node through ts-morph
151
+ * invalidates nodes still waiting to be edited.
152
+ */
153
+ function applyTextEdits(sourceFile, edits) {
154
+ // Applied from the end of the file, so each edit leaves the positions of
155
+ // the ones still to apply untouched
156
+ const text = [...edits]
157
+ .sort((a, b) => b.start - a.start)
158
+ .reduce((result, edit) => result.slice(0, edit.start) + edit.text + result.slice(edit.end), sourceFile.getFullText());
159
+ sourceFile.replaceWithText(text);
160
+ }
161
+ /** Finds the value import of the toolkit's events module, if the file has one. */
162
+ function findToolkitImport(sourceFile) {
163
+ // A type-only import cannot carry a function, and a namespace import cannot
164
+ // be given named imports, so neither is extended
165
+ return sourceFile.getImportDeclaration((declaration) => declaration.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE &&
166
+ !declaration.isTypeOnly() &&
167
+ !declaration.getNamespaceImport());
168
+ }
169
+ /**
170
+ * Returns the name a toolkit export is called by in the file: its local alias
171
+ * when the file already imports it from the toolkit, its own name when the
172
+ * name is free, or undefined when the file binds that name to something else.
173
+ */
174
+ function findToolkitImportName(sourceFile, name) {
175
+ var _a, _b;
176
+ var _c;
177
+ const imported = (_a = findToolkitImport(sourceFile)) === null || _a === void 0 ? void 0 : _a.getNamedImports().find((namedImport) => namedImport.getName() === name);
178
+ if (imported) {
179
+ return (_c = (_b = imported.getAliasNode()) === null || _b === void 0 ? void 0 : _b.getText()) !== null && _c !== void 0 ? _c : name;
180
+ }
181
+ if (sourceFile.getLocal(name)) {
182
+ return undefined;
183
+ }
184
+ return name;
185
+ }
186
+ /** Adds the toolkit export to the file's toolkit import, unless already imported. */
187
+ function addToolkitImport(sourceFile, name) {
188
+ const toolkitImport = findToolkitImport(sourceFile);
189
+ if (!toolkitImport) {
190
+ const imports = sourceFile.getImportDeclarations();
191
+ const lastImport = imports[imports.length - 1];
192
+ // Inserted as text so the import keeps the country config's style
193
+ // (single quotes, no semicolon) rather than ts-morph's defaults
194
+ sourceFile.insertStatements(lastImport ? lastImport.getChildIndex() + 1 : 0, `import { ${name} } from '${TOOLKIT_EVENTS_MODULE}'`);
195
+ return;
196
+ }
197
+ const alreadyImported = toolkitImport
198
+ .getNamedImports()
199
+ .some((namedImport) => namedImport.getName() === name);
200
+ if (alreadyImported) {
201
+ return;
202
+ }
203
+ const namedImports = toolkitImport.getNamedImports();
204
+ // ts-morph's addNamedImport collapses a multi-line import onto one line, so
205
+ // the import is rewritten keeping one name per line when it had them
206
+ if (toolkitImport.getDefaultImport() || namedImports.length === 0) {
207
+ toolkitImport.addNamedImport(name);
208
+ return;
209
+ }
210
+ const names = [
211
+ ...namedImports.map((namedImport) => namedImport.getText()),
212
+ name
213
+ ];
214
+ const specifiers = toolkitImport.getText().includes('\n')
215
+ ? `{\n ${names.join(',\n ')}\n}`
216
+ : `{ ${names.join(', ')} }`;
217
+ toolkitImport.replaceWithText(`import ${specifiers} from '${TOOLKIT_EVENTS_MODULE}'`);
218
+ }