@opencrvs/toolkit 2.2.0-rc.045257f → 2.2.0-rc.25c3c81

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 (156) hide show
  1. package/build.sh +15 -2
  2. package/dist/application-config/index.js +16 -5
  3. package/dist/authentication/index.d.ts +1 -1
  4. package/dist/authentication/index.js +4 -8
  5. package/dist/cli.js +2197 -544
  6. package/dist/commons/api/router.d.ts +17 -4
  7. package/dist/commons/application-config/index.d.ts +1 -1
  8. package/dist/commons/conditionals/conditionals.d.ts +4 -4
  9. package/dist/commons/conditionals/validate.d.ts +1 -1
  10. package/dist/commons/events/ActionStatus.d.ts +2 -2
  11. package/dist/commons/events/ActionType.d.ts +2 -0
  12. package/dist/commons/events/AdvancedSearchConfig.d.ts +3 -0
  13. package/dist/commons/events/Draft.d.ts +34 -1
  14. package/dist/commons/events/EventConfig.d.ts +446 -0
  15. package/dist/commons/events/EventDocument.d.ts +2 -0
  16. package/dist/commons/events/EventIndex.d.ts +1 -0
  17. package/dist/commons/events/EventInput.d.ts +1 -0
  18. package/dist/commons/events/EventMetadata.d.ts +1 -0
  19. package/dist/commons/events/FieldTypeMapping.d.ts +19 -19
  20. package/dist/commons/events/PlainDate.d.ts +5 -0
  21. package/dist/commons/events/defineConfig.d.ts +7 -2
  22. package/dist/commons/events/event.d.ts +4 -1
  23. package/dist/commons/events/field.d.ts +5 -0
  24. package/dist/commons/events/locations.d.ts +1 -1
  25. package/dist/commons/events/scopes.d.ts +2 -1
  26. package/dist/commons/events/state/index.d.ts +1 -0
  27. package/dist/commons/events/test.utils.d.ts +59 -6
  28. package/dist/commons/events/utils.d.ts +28 -2
  29. package/dist/commons/users/Role.d.ts +23 -0
  30. package/dist/commons/users/User.d.ts +263 -0
  31. package/dist/commons/users/authentication.d.ts +67 -0
  32. package/dist/commons/users/index.d.ts +5 -0
  33. package/dist/commons/users/roleValidations.d.ts +15 -0
  34. package/dist/commons/users/scopes.d.ts +1402 -0
  35. package/dist/commons/users/userReferences.d.ts +176 -0
  36. package/dist/conditionals/index.js +3 -3
  37. package/dist/configurator/index.d.ts +24 -0
  38. package/dist/configurator/index.d.ts.map +1 -0
  39. package/dist/configurator/index.js +161 -0
  40. package/dist/configurator/layout.d.ts +28 -0
  41. package/dist/configurator/layout.d.ts.map +1 -0
  42. package/dist/configurator/layout.js +78 -0
  43. package/dist/configurator/paths.d.ts +13 -0
  44. package/dist/configurator/paths.d.ts.map +1 -0
  45. package/dist/configurator/paths.js +48 -0
  46. package/dist/configurator/server/environments.d.ts +20 -0
  47. package/dist/configurator/server/environments.d.ts.map +1 -0
  48. package/dist/configurator/server/environments.js +143 -0
  49. package/dist/configurator/server/files.d.ts +11 -0
  50. package/dist/configurator/server/files.d.ts.map +1 -0
  51. package/dist/configurator/server/files.js +67 -0
  52. package/dist/configurator/server/github.d.ts +56 -0
  53. package/dist/configurator/server/github.d.ts.map +1 -0
  54. package/dist/configurator/server/github.js +239 -0
  55. package/dist/configurator/server/plugin.d.ts +39 -0
  56. package/dist/configurator/server/plugin.d.ts.map +1 -0
  57. package/dist/configurator/server/plugin.js +298 -0
  58. package/dist/configurator/server/seal.d.ts +2 -0
  59. package/dist/configurator/server/seal.d.ts.map +1 -0
  60. package/dist/configurator/server/seal.js +36 -0
  61. package/dist/configurator/server/sshKeys.d.ts +5 -0
  62. package/dist/configurator/server/sshKeys.d.ts.map +1 -0
  63. package/dist/configurator/server/sshKeys.js +28 -0
  64. package/dist/configurator/server/start.d.ts +12 -0
  65. package/dist/configurator/server/start.d.ts.map +1 -0
  66. package/dist/configurator/server/start.js +91 -0
  67. package/dist/configurator/testing.d.ts +11 -0
  68. package/dist/configurator/testing.d.ts.map +1 -0
  69. package/dist/configurator/testing.js +74 -0
  70. package/dist/configurator/ui/bindings/bindings.d.ts +35 -0
  71. package/dist/configurator/ui/bindings/bindings.d.ts.map +1 -0
  72. package/dist/configurator/ui/bindings/bindings.js +5 -0
  73. package/dist/configurator/ui/bindings/parsers.d.ts +7 -0
  74. package/dist/configurator/ui/bindings/parsers.d.ts.map +1 -0
  75. package/dist/configurator/ui/bindings/parsers.js +85 -0
  76. package/dist/configurator/ui/form/users.d.ts +11 -0
  77. package/dist/configurator/ui/form/users.d.ts.map +1 -0
  78. package/dist/configurator/ui/form/users.js +33 -0
  79. package/dist/configurator/ui/plan/dependencyHosts.d.ts +2 -0
  80. package/dist/configurator/ui/plan/dependencyHosts.d.ts.map +1 -0
  81. package/dist/configurator/ui/plan/dependencyHosts.js +36 -0
  82. package/dist/configurator/ui/plan/templateValues.d.ts +11 -0
  83. package/dist/configurator/ui/plan/templateValues.d.ts.map +1 -0
  84. package/dist/configurator/ui/plan/templateValues.js +70 -0
  85. package/dist/configurator/workflows.d.ts +53 -0
  86. package/dist/configurator/workflows.d.ts.map +1 -0
  87. package/dist/configurator/workflows.js +161 -0
  88. package/dist/configurator-assets/forms/bindings.yml +263 -0
  89. package/dist/configurator-assets/templates/README.md +18 -0
  90. package/dist/configurator-assets/templates/charts-values/dependencies/values.override.yaml +4 -0
  91. package/dist/configurator-assets/templates/charts-values/dependencies/values.yaml +99 -0
  92. package/dist/configurator-assets/templates/charts-values/opencrvs-services/values.override.yaml +4 -0
  93. package/dist/configurator-assets/templates/charts-values/opencrvs-services/values.yaml +83 -0
  94. package/dist/configurator-assets/templates/charts-values/opentelemetry/values.yaml +102 -0
  95. package/dist/configurator-assets/templates/charts-values/traefik/values.override.yaml +4 -0
  96. package/dist/configurator-assets/templates/charts-values/traefik/values.yaml +130 -0
  97. package/dist/configurator-assets/templates/inventory/inventory.template.yml +98 -0
  98. package/dist/configurator-assets/ui/apple-touch-icon.png +0 -0
  99. package/dist/configurator-assets/ui/assets/index-Bf3eC7uO.js +169 -0
  100. package/dist/configurator-assets/ui/assets/index-CaqYFJUk.css +6 -0
  101. package/dist/configurator-assets/ui/assets/opencrvs-logo-sIjz08HT.svg +1 -0
  102. package/dist/configurator-assets/ui/assets/poppins-400-BwTUGeWf.woff2 +0 -0
  103. package/dist/configurator-assets/ui/assets/poppins-500-CWICHMj6.woff2 +0 -0
  104. package/dist/configurator-assets/ui/assets/poppins-600-DJVo7c07.woff2 +0 -0
  105. package/dist/configurator-assets/ui/assets/poppins-700-g9MkRaG0.woff2 +0 -0
  106. package/dist/configurator-assets/ui/favicon-32x32.png +0 -0
  107. package/dist/configurator-assets/ui/index.html +25 -0
  108. package/dist/environment/custom-types.d.ts +1 -0
  109. package/dist/environment/custom-types.d.ts.map +1 -1
  110. package/dist/environment/derived-variables.d.ts +8 -0
  111. package/dist/environment/derived-variables.d.ts.map +1 -1
  112. package/dist/environment/derived-variables.js +9 -0
  113. package/dist/environment/questions.d.ts +42 -9
  114. package/dist/environment/questions.d.ts.map +1 -1
  115. package/dist/environment/questions.js +70 -47
  116. package/dist/environment/registry.d.ts +15 -0
  117. package/dist/environment/registry.d.ts.map +1 -0
  118. package/dist/environment/registry.js +112 -0
  119. package/dist/environment/setup-environment.d.ts.map +1 -1
  120. package/dist/environment/setup-environment.js +104 -23
  121. package/dist/events/index.js +635 -149
  122. package/dist/migrations/add-notify-config.d.ts +40 -0
  123. package/dist/migrations/add-notify-config.d.ts.map +1 -0
  124. package/dist/migrations/add-notify-config.js +249 -0
  125. package/dist/migrations/index.d.ts.map +1 -1
  126. package/dist/migrations/index.js +602 -143
  127. package/dist/migrations/move-declaration-to-declare-action.d.ts.map +1 -1
  128. package/dist/migrations/move-declaration-to-declare-action.js +27 -144
  129. package/dist/migrations/read-declaration-through-helper.d.ts.map +1 -1
  130. package/dist/migrations/read-declaration-through-helper.js +3 -61
  131. package/dist/migrations/resolve-versioned-event-config.d.ts +56 -0
  132. package/dist/migrations/resolve-versioned-event-config.d.ts.map +1 -0
  133. package/dist/migrations/resolve-versioned-event-config.js +353 -0
  134. package/dist/migrations/utils.d.ts +61 -0
  135. package/dist/migrations/utils.d.ts.map +1 -0
  136. package/dist/migrations/utils.js +218 -0
  137. package/dist/notification/index.js +616 -66
  138. package/dist/roles/index.d.ts +2 -0
  139. package/dist/roles/index.d.ts.map +1 -0
  140. package/dist/roles/index.js +730 -0
  141. package/dist/scopes/index.d.ts +0 -10
  142. package/dist/scopes/index.js +3 -7
  143. package/dist/templates/charts-values/dependencies/values.yaml +4 -1
  144. package/dist/templates/charts-values/opencrvs-services/values.yaml +2 -2
  145. package/dist/verify/endpoints.d.ts +11 -0
  146. package/dist/verify/endpoints.d.ts.map +1 -1
  147. package/dist/verify/endpoints.js +21 -27
  148. package/opencrvs-toolkit-2.2.0-rc.25c3c81.tgz +0 -0
  149. package/package.json +16 -3
  150. package/tsconfig.build.json +11 -1
  151. package/tsconfig.build.tsbuildinfo +1 -1
  152. package/tsconfig.json +15 -6
  153. package/dist/environment/dockerhub.d.ts +0 -15
  154. package/dist/environment/dockerhub.d.ts.map +0 -1
  155. package/dist/environment/dockerhub.js +0 -104
  156. package/opencrvs-toolkit-2.2.0-rc.045257f.tgz +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"move-declaration-to-declare-action.d.ts","sourceRoot":"","sources":["../../src/migrations/move-declaration-to-declare-action.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAOL,UAAU,EAGX,MAAM,UAAU,CAAA;AAmWjB;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAqD7E;AAED,iBAAe,IAAI,kBA6ClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
1
+ {"version":3,"file":"move-declaration-to-declare-action.d.ts","sourceRoot":"","sources":["../../src/migrations/move-declaration-to-declare-action.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAOL,UAAU,EAEX,MAAM,UAAU,CAAA;AA2MjB;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAyC7E;AAED,iBAAe,IAAI,kBA6ClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -53,149 +53,39 @@ exports.main = main;
53
53
  */
54
54
  const ts_morph_1 = require("ts-morph");
55
55
  const path_1 = __importDefault(require("path"));
56
+ const utils_1 = require("./utils");
56
57
  const DEFINE_CONFIG_NAME = 'defineConfig';
57
58
  const DECLARATION_PROPERTY_NAME = 'declaration';
58
59
  const ACTIONS_PROPERTY_NAME = 'actions';
59
60
  const DECLARE_ACTION_TYPE = 'DECLARE';
60
- function location(node) {
61
- const relPath = path_1.default.relative(process.cwd(), node.getSourceFile().getFilePath());
62
- return `${relPath}:${node.getStartLineNumber()}`;
63
- }
64
- /**
65
- * Returns true if the call is to the `defineConfig` published by the toolkit,
66
- * as opposed to a function of the same name declared in the country config.
67
- */
68
- function isToolkitDefineConfigCall(call) {
69
- var _a;
70
- const symbol = call.getExpression().getSymbol();
71
- const resolved = (_a = symbol === null || symbol === void 0 ? void 0 : symbol.getAliasedSymbol()) !== null && _a !== void 0 ? _a : symbol;
72
- if ((resolved === null || resolved === void 0 ? void 0 : resolved.getName()) !== DEFINE_CONFIG_NAME) {
73
- return false;
74
- }
75
- return resolved
76
- .getDeclarations()
77
- .some((declaration) => declaration.getSourceFile().isDeclarationFile());
78
- }
79
- /** Finds a property given by name, whether written `key: value` or shorthand. */
80
- function findProperty(literal, name) {
81
- const property = literal.getProperty(name);
82
- return ts_morph_1.Node.isPropertyAssignment(property) ||
83
- ts_morph_1.Node.isShorthandPropertyAssignment(property)
84
- ? property
85
- : undefined;
86
- }
87
- /**
88
- * Returns false only if the action type's `type` is known to be some other
89
- * action: a string literal, or a union of them, other than DECLARE.
90
- */
91
- function mayHaveDeclareType(actionType, node) {
92
- const typeProperty = actionType.getProperty('type');
93
- if (!typeProperty) {
94
- return true;
95
- }
96
- const type = typeProperty.getTypeAtLocation(node);
97
- const values = type.isUnion() ? type.getUnionTypes() : [type];
98
- return !values.every((value) => value.isStringLiteral() && value.getLiteralValue() !== DECLARE_ACTION_TYPE);
99
- }
100
- /**
101
- * Returns true if the node may be the DECLARE action. An action not written
102
- * inline (a variable, a call, a spread) may be, unless its type shows it is
103
- * some other action.
104
- */
105
- function mayBeDeclareAction(node) {
106
- if (ts_morph_1.Node.isObjectLiteralExpression(node)) {
107
- return isDeclareAction(node);
108
- }
109
- if (ts_morph_1.Node.isSpreadElement(node)) {
110
- const arrayType = node.getExpression().getType();
111
- const elementTypes = arrayType.isTuple()
112
- ? arrayType.getTupleElements()
113
- : [arrayType.getArrayElementType()];
114
- return elementTypes.some((elementType) => !elementType || mayHaveDeclareType(elementType, node));
115
- }
116
- return mayHaveDeclareType(node.getType(), node);
117
- }
118
- function isDeclareAction(literal) {
119
- const type = findProperty(literal, 'type');
120
- return (ts_morph_1.Node.isPropertyAssignment(type) &&
121
- type.getInitializerOrThrow().getType().getLiteralValue() ===
122
- DECLARE_ACTION_TYPE);
123
- }
124
61
  /**
125
62
  * Finds the DECLARE action in `actions`, or logs why the config cannot be
126
63
  * rewritten and returns undefined.
127
64
  */
128
65
  function findDeclareAction(config) {
129
- const actions = findProperty(config, ACTIONS_PROPERTY_NAME);
66
+ const actions = (0, utils_1.findProperty)(config, ACTIONS_PROPERTY_NAME);
130
67
  const actionsValue = ts_morph_1.Node.isPropertyAssignment(actions)
131
68
  ? actions.getInitializer()
132
69
  : undefined;
133
70
  if (!ts_morph_1.Node.isArrayLiteralExpression(actionsValue)) {
134
- console.warn(` [${location(config)}] Skipped: \`${ACTIONS_PROPERTY_NAME}\` is not an array literal. Move \`${DECLARATION_PROPERTY_NAME}\` onto the ${DECLARE_ACTION_TYPE} action by hand.`);
71
+ console.warn(` [${(0, utils_1.location)(config)}] Skipped: \`${ACTIONS_PROPERTY_NAME}\` is not an array literal. Move \`${DECLARATION_PROPERTY_NAME}\` onto the ${DECLARE_ACTION_TYPE} action by hand.`);
135
72
  return undefined;
136
73
  }
137
- const candidates = actionsValue.getElements().filter(mayBeDeclareAction);
74
+ const candidates = actionsValue
75
+ .getElements()
76
+ .filter((element) => (0, utils_1.mayBeAction)(element, DECLARE_ACTION_TYPE));
138
77
  if (candidates.length !== 1 ||
139
78
  !ts_morph_1.Node.isObjectLiteralExpression(candidates[0])) {
140
- console.warn(` [${location(config)}] Skipped: could not find exactly one ${DECLARE_ACTION_TYPE} action written as an object literal in \`${ACTIONS_PROPERTY_NAME}\`. Move \`${DECLARATION_PROPERTY_NAME}\` onto it by hand.`);
79
+ console.warn(` [${(0, utils_1.location)(config)}] Skipped: could not find exactly one ${DECLARE_ACTION_TYPE} action written as an object literal in \`${ACTIONS_PROPERTY_NAME}\`. Move \`${DECLARATION_PROPERTY_NAME}\` onto it by hand.`);
141
80
  return undefined;
142
81
  }
143
82
  const declareAction = candidates[0];
144
- if (findProperty(declareAction, DECLARATION_PROPERTY_NAME)) {
145
- console.warn(` [${location(config)}] Skipped: \`${DECLARATION_PROPERTY_NAME}\` is set both at the top level and on the ${DECLARE_ACTION_TYPE} action. Keep only the one on the action.`);
83
+ if ((0, utils_1.findProperty)(declareAction, DECLARATION_PROPERTY_NAME)) {
84
+ console.warn(` [${(0, utils_1.location)(config)}] Skipped: \`${DECLARATION_PROPERTY_NAME}\` is set both at the top level and on the ${DECLARE_ACTION_TYPE} action. Keep only the one on the action.`);
146
85
  return undefined;
147
86
  }
148
87
  return declareAction;
149
88
  }
150
- /** The whitespace the line the node starts on is indented by. */
151
- function indentationOf(node) {
152
- var _a;
153
- var _b;
154
- const text = node.getSourceFile().getFullText();
155
- const lineStart = text.lastIndexOf('\n', node.getStart() - 1) + 1;
156
- return (_b = (_a = /^[ \t]*/.exec(text.slice(lineStart))) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : '';
157
- }
158
- /** The text from the position to the end of its line, without the line break. */
159
- function restOfLine(text, position) {
160
- const lineEnd = text.indexOf('\n', position);
161
- return text.slice(position, lineEnd === -1 ? text.length : lineEnd);
162
- }
163
- function isOnlyComments(text) {
164
- return /^\s*(?:\/\/.*|\/\*.*?\*\/\s*)*$/.test(text);
165
- }
166
- function layoutOf(property) {
167
- var _a;
168
- var _b;
169
- const text = property.getSourceFile().getFullText();
170
- const next = property.getNextSibling();
171
- const hasComma = (next === null || next === void 0 ? void 0 : next.getKind()) === ts_morph_1.SyntaxKind.CommaToken;
172
- const end = next && hasComma ? next.getEnd() : property.getEnd();
173
- const trailing = restOfLine(text, end);
174
- // A comment on the line the previous property ends on is that property's
175
- const lineBreak = text
176
- .slice(property.getFullStart(), property.getStart())
177
- .indexOf('\n');
178
- if (lineBreak === -1 || !isOnlyComments(trailing)) {
179
- return {
180
- ownsLines: false,
181
- start: property.getStart(true),
182
- end,
183
- hasComma,
184
- trailingComment: ''
185
- };
186
- }
187
- const firstLine = property.getFullStart() + lineBreak + 1;
188
- return {
189
- ownsLines: true,
190
- start: firstLine + ((_b = (_a = /^\s*/.exec(text.slice(firstLine))) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0),
191
- end,
192
- hasComma,
193
- trailingComment: trailing.trimEnd()
194
- };
195
- }
196
- function insertAt(position, text) {
197
- return { start: position, end: position, text };
198
- }
199
89
  /**
200
90
  * Returns the edits inserting the property into the DECLARE action after its
201
91
  * `label`, or after its `type` when it has no `label`, in the action's own
@@ -207,13 +97,13 @@ function insertIntoDeclareAction(declareAction, property) {
207
97
  // `type` is always there: it is how the DECLARE action was found
208
98
  const anchor = (_a = declareAction.getProperty('label')) !== null && _a !== void 0 ? _a : declareAction.getPropertyOrThrow('type');
209
99
  const text = property.getSourceFile().getFullText();
210
- const anchorLayout = layoutOf(anchor);
211
- const layout = layoutOf(property);
212
- const indent = indentationOf(anchor);
100
+ const anchorLayout = (0, utils_1.layoutOf)(anchor);
101
+ const layout = (0, utils_1.layoutOf)(property);
102
+ const indent = (0, utils_1.indentationOf)(anchor);
213
103
  // Copied as text so the value keeps its formatting and its comments, with
214
104
  // continuation lines re-indented from the property's indentation to the
215
105
  // anchor's
216
- const oldIndent = indentationOf(property);
106
+ const oldIndent = (0, utils_1.indentationOf)(property);
217
107
  const reindent = (lines) => lines
218
108
  .split('\n')
219
109
  .map((line, index) => index > 0 && line.startsWith(oldIndent)
@@ -222,25 +112,25 @@ function insertIntoDeclareAction(declareAction, property) {
222
112
  .join('\n');
223
113
  if (anchorLayout.ownsLines) {
224
114
  const moved = reindent(text.slice(layout.start, property.getEnd()));
225
- const position = anchorLayout.end + restOfLine(text, anchorLayout.end).length;
115
+ const position = anchorLayout.end + (0, utils_1.restOfLine)(text, anchorLayout.end).length;
226
116
  const insertion = `\n${indent}${moved}${anchorLayout.hasComma ? ',' : ''}${layout.trailingComment}`;
227
117
  if (anchorLayout.hasComma) {
228
- return [insertAt(position, insertion)];
118
+ return [(0, utils_1.insertAt)(position, insertion)];
229
119
  }
230
120
  // The anchor was the last property: it needs a comma now
231
121
  return position === anchor.getEnd()
232
- ? [insertAt(position, `,${insertion}`)]
233
- : [insertAt(anchor.getEnd(), ','), insertAt(position, insertion)];
122
+ ? [(0, utils_1.insertAt)(position, `,${insertion}`)]
123
+ : [(0, utils_1.insertAt)(anchor.getEnd(), ','), (0, utils_1.insertAt)(position, insertion)];
234
124
  }
235
125
  const droppedComments = text.slice(layout.start, property.getStart(true)).trim() !== '' ||
236
126
  layout.trailingComment !== '';
237
127
  if (droppedComments) {
238
- console.warn(` [${location(property)}] The comments next to \`${DECLARATION_PROPERTY_NAME}\` were not moved with it. Move them onto the ${DECLARE_ACTION_TYPE} action by hand.`);
128
+ console.warn(` [${(0, utils_1.location)(property)}] The comments next to \`${DECLARATION_PROPERTY_NAME}\` were not moved with it. Move them onto the ${DECLARE_ACTION_TYPE} action by hand.`);
239
129
  }
240
130
  const isMultiLine = declareAction.getText().includes('\n');
241
131
  const separator = isMultiLine ? `,\n${indent}` : ', ';
242
132
  return [
243
- insertAt(anchor.getEnd(), `${separator}${reindent(property.getText(true))}`)
133
+ (0, utils_1.insertAt)(anchor.getEnd(), `${separator}${reindent(property.getText(true))}`)
244
134
  ];
245
135
  }
246
136
  /**
@@ -250,16 +140,16 @@ function insertIntoDeclareAction(declareAction, property) {
250
140
  function removeFromConfig(property) {
251
141
  var _a;
252
142
  const text = property.getSourceFile().getFullText();
253
- const layout = layoutOf(property);
143
+ const layout = (0, utils_1.layoutOf)(property);
254
144
  // The comma before the property, past any comments, which ts-morph lists
255
145
  // as siblings
256
146
  const previousComma = (_a = property
257
147
  .getPreviousSiblings()
258
- .find((sibling) => !isOnlyComments(sibling.getText()))) === null || _a === void 0 ? void 0 : _a.asKind(ts_morph_1.SyntaxKind.CommaToken);
148
+ .find((sibling) => !(0, utils_1.isOnlyComments)(sibling.getText()))) === null || _a === void 0 ? void 0 : _a.asKind(ts_morph_1.SyntaxKind.CommaToken);
259
149
  if (layout.ownsLines) {
260
150
  const lines = {
261
151
  start: text.lastIndexOf('\n', layout.start - 1),
262
- end: layout.end + restOfLine(text, layout.end).length,
152
+ end: layout.end + (0, utils_1.restOfLine)(text, layout.end).length,
263
153
  text: ''
264
154
  };
265
155
  // The last property: drop the comma before it too
@@ -297,7 +187,7 @@ function findConfigLiteral(call) {
297
187
  return config;
298
188
  }
299
189
  if (config.getType().getProperty(DECLARATION_PROPERTY_NAME)) {
300
- console.warn(` [${location(config)}] Skipped: \`${DEFINE_CONFIG_NAME}\` is not given an object literal. If its config has a top-level \`${DECLARATION_PROPERTY_NAME}\`, move it onto the ${DECLARE_ACTION_TYPE} action by hand.`);
190
+ console.warn(` [${(0, utils_1.location)(config)}] Skipped: \`${DEFINE_CONFIG_NAME}\` is not given an object literal. If its config has a top-level \`${DECLARATION_PROPERTY_NAME}\`, move it onto the ${DECLARE_ACTION_TYPE} action by hand.`);
301
191
  }
302
192
  return undefined;
303
193
  }
@@ -310,15 +200,13 @@ function findConfigLiteral(call) {
310
200
  function moveDeclarationToDeclareAction(sourceFile) {
311
201
  const configs = sourceFile
312
202
  .getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression)
313
- .filter(isToolkitDefineConfigCall)
203
+ .filter(utils_1.isToolkitDefineConfigCall)
314
204
  .map(findConfigLiteral)
315
205
  .filter(ts_morph_1.Node.isObjectLiteralExpression);
316
- // Collected as text edits and applied together, as editing a node through
317
- // ts-morph invalidates nodes still waiting to be edited
318
206
  const edits = [];
319
207
  let changes = 0;
320
208
  for (const config of configs) {
321
- const declaration = findProperty(config, DECLARATION_PROPERTY_NAME);
209
+ const declaration = (0, utils_1.findProperty)(config, DECLARATION_PROPERTY_NAME);
322
210
  if (!declaration) {
323
211
  continue;
324
212
  }
@@ -326,19 +214,14 @@ function moveDeclarationToDeclareAction(sourceFile) {
326
214
  if (!declareAction) {
327
215
  continue;
328
216
  }
329
- console.log(` [${location(declaration)}] Moved \`${declaration.getText()}\` onto the ${DECLARE_ACTION_TYPE} action`);
217
+ console.log(` [${(0, utils_1.location)(declaration)}] Moved \`${declaration.getText()}\` onto the ${DECLARE_ACTION_TYPE} action`);
330
218
  edits.push(...insertIntoDeclareAction(declareAction, declaration), ...removeFromConfig(declaration));
331
219
  changes++;
332
220
  }
333
221
  if (changes === 0) {
334
222
  return 0;
335
223
  }
336
- // Applied from the end of the file, so each edit leaves the positions of
337
- // the ones still to apply untouched
338
- const text = edits
339
- .sort((a, b) => b.start - a.start)
340
- .reduce((result, edit) => result.slice(0, edit.start) + edit.text + result.slice(edit.end), sourceFile.getFullText());
341
- sourceFile.replaceWithText(text);
224
+ (0, utils_1.applyTextEdits)(sourceFile, edits);
342
225
  return changes;
343
226
  }
344
227
  function main() {
@@ -1 +1 @@
1
- {"version":3,"file":"read-declaration-through-helper.d.ts","sourceRoot":"","sources":["../../src/migrations/read-declaration-through-helper.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAIL,UAAU,EAGX,MAAM,UAAU,CAAA;AA8LjB;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAqDtE;AAED,iBAAe,IAAI,kBA6ClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
1
+ {"version":3,"file":"read-declaration-through-helper.d.ts","sourceRoot":"","sources":["../../src/migrations/read-declaration-through-helper.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAIL,UAAU,EAGX,MAAM,UAAU,CAAA;AA8GjB;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAwDtE;AAED,iBAAe,IAAI,kBA6ClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -54,10 +54,10 @@ exports.main = main;
54
54
  */
55
55
  const ts_morph_1 = require("ts-morph");
56
56
  const path_1 = __importDefault(require("path"));
57
+ const utils_1 = require("./utils");
57
58
  const EVENT_CONFIG_TYPE_NAME = 'EventConfig';
58
59
  const DECLARATION_PROPERTY_NAME = 'declaration';
59
60
  const GET_DECLARATION_NAME = 'getDeclaration';
60
- const TOOLKIT_EVENTS_MODULE = '@opencrvs/toolkit/events';
61
61
  /**
62
62
  * Returns true if the type is the `EventConfig` type published by the toolkit,
63
63
  * as opposed to a type of the same name declared in the country config itself.
@@ -122,64 +122,6 @@ function warnSpreadDeclarations(sourceFile) {
122
122
  }
123
123
  }
124
124
  }
125
- /** Finds the value import of the toolkit's events module, if the file has one. */
126
- function findToolkitImport(sourceFile) {
127
- // A type-only import cannot carry a function, and a namespace import cannot
128
- // be given named imports, so neither is extended
129
- return sourceFile.getImportDeclaration((declaration) => declaration.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE &&
130
- !declaration.isTypeOnly() &&
131
- !declaration.getNamespaceImport());
132
- }
133
- /**
134
- * Returns the name `getDeclaration` is called by in the file: its local alias
135
- * when the file already imports it from the toolkit, `getDeclaration` when the
136
- * name is free, or undefined when the file binds `getDeclaration` to
137
- * something else.
138
- */
139
- function findGetDeclarationName(sourceFile) {
140
- var _a, _b;
141
- var _c;
142
- const imported = (_a = findToolkitImport(sourceFile)) === null || _a === void 0 ? void 0 : _a.getNamedImports().find((namedImport) => namedImport.getName() === GET_DECLARATION_NAME);
143
- if (imported) {
144
- return (_c = (_b = imported.getAliasNode()) === null || _b === void 0 ? void 0 : _b.getText()) !== null && _c !== void 0 ? _c : GET_DECLARATION_NAME;
145
- }
146
- if (sourceFile.getLocal(GET_DECLARATION_NAME)) {
147
- return undefined;
148
- }
149
- return GET_DECLARATION_NAME;
150
- }
151
- function addGetDeclarationImport(sourceFile) {
152
- const toolkitImport = findToolkitImport(sourceFile);
153
- if (!toolkitImport) {
154
- const imports = sourceFile.getImportDeclarations();
155
- const lastImport = imports[imports.length - 1];
156
- // Inserted as text so the import keeps the country config's style
157
- // (single quotes, no semicolon) rather than ts-morph's defaults
158
- sourceFile.insertStatements(lastImport ? lastImport.getChildIndex() + 1 : 0, `import { ${GET_DECLARATION_NAME} } from '${TOOLKIT_EVENTS_MODULE}'`);
159
- return;
160
- }
161
- const alreadyImported = toolkitImport
162
- .getNamedImports()
163
- .some((namedImport) => namedImport.getName() === GET_DECLARATION_NAME);
164
- if (alreadyImported) {
165
- return;
166
- }
167
- const namedImports = toolkitImport.getNamedImports();
168
- // ts-morph's addNamedImport collapses a multi-line import onto one line, so
169
- // the import is rewritten keeping one name per line when it had them
170
- if (toolkitImport.getDefaultImport() || namedImports.length === 0) {
171
- toolkitImport.addNamedImport(GET_DECLARATION_NAME);
172
- return;
173
- }
174
- const names = [
175
- ...namedImports.map((namedImport) => namedImport.getText()),
176
- GET_DECLARATION_NAME
177
- ];
178
- const specifiers = toolkitImport.getText().includes('\n')
179
- ? `{\n ${names.join(',\n ')}\n}`
180
- : `{ ${names.join(', ')} }`;
181
- toolkitImport.replaceWithText(`import ${specifiers} from '${TOOLKIT_EVENTS_MODULE}'`);
182
- }
183
125
  /**
184
126
  * Rewrites every `x.declaration` read on an `EventConfig` in the file to
185
127
  * `getDeclaration(x)`.
@@ -209,7 +151,7 @@ function rewriteDeclarationReads(sourceFile) {
209
151
  if (reads.length === 0) {
210
152
  return 0;
211
153
  }
212
- const getDeclarationName = findGetDeclarationName(sourceFile);
154
+ const getDeclarationName = (0, utils_1.findToolkitImportName)(sourceFile, GET_DECLARATION_NAME);
213
155
  if (!getDeclarationName) {
214
156
  console.warn(` [${location(reads[reads.length - 1])}] Skipped ${reads.length} read(s): the file already declares its own \`${GET_DECLARATION_NAME}\`. Rewrite them to use the toolkit's \`${GET_DECLARATION_NAME}()\` by hand.`);
215
157
  return 0;
@@ -218,7 +160,7 @@ function rewriteDeclarationReads(sourceFile) {
218
160
  console.log(` [${location(read)}] ${read.getText()} -> ${getDeclarationName}(${read.getExpression().getText()})`);
219
161
  read.replaceWithText(`${getDeclarationName}(${read.getExpression().getText()})`);
220
162
  }
221
- addGetDeclarationImport(sourceFile);
163
+ (0, utils_1.addToolkitImport)(sourceFile, GET_DECLARATION_NAME);
222
164
  return reads.length;
223
165
  }
224
166
  function main() {
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Codemod: Read a `VersionedEventConfig` through `resolveEventConfig()` wherever
3
+ * the country config uses it as a flat `EventConfig`.
4
+ *
5
+ * Usage:
6
+ * ts-node -r tsconfig-paths/register src/migrations/resolve-versioned-event-config.ts
7
+ *
8
+ * Why:
9
+ * As of v2.2 an event configuration can have several versions, each with an
10
+ * `effectiveFrom` date. `defineConfig` still accepts a flat configuration and
11
+ * wraps it in a single version, but it now returns a `VersionedEventConfig`:
12
+ * `{ id, label, advancedSearch, versions }`. Fields such as `actions` or
13
+ * `analytics` live on each version, so code that reads them straight off the
14
+ * result of `defineConfig`, or passes it to a function expecting an
15
+ * `EventConfig`, stops compiling.
16
+ *
17
+ * What it does:
18
+ * - Scans all TypeScript files under `src/`
19
+ * - Reads `@opencrvs/toolkit/events` from the toolkit running it, not the one the
20
+ * country config has installed, which predates `VersionedEventConfig`
21
+ * - Rewrites `x.field` to `resolveEventConfig(x).field` wherever `x` is the
22
+ * toolkit's `VersionedEventConfig` and `field` is not one of its own fields
23
+ * (`id`, `label`, `advancedSearch` and `versions` are left alone)
24
+ * - Rewrites `x` to `resolveEventConfig(x)` wherever a `VersionedEventConfig` is
25
+ * passed, assigned or returned where an `EventConfig` is expected, and `xs` to
26
+ * `xs.map(resolveEventConfig)` for arrays of them
27
+ * - Adds `resolveEventConfig` to the file's `@opencrvs/toolkit/events` import
28
+ * - Logs, without changing: optional chains (`x?.actions`), writes
29
+ * (`x.actions = ...`, `delete x.actions`...), destructuring `{ actions }` out
30
+ * of a `VersionedEventConfig`, and a possibly undefined `VersionedEventConfig`
31
+ * passed where an `EventConfig` is expected
32
+ * - Leaves a file alone, and logs it, when it already declares its own
33
+ * `resolveEventConfig`
34
+ * - Saves the modified files in-place
35
+ *
36
+ * Runs before `read-declaration-through-helper`, which then rewrites
37
+ * `resolveEventConfig(x).declaration` to `getDeclaration(resolveEventConfig(x))`.
38
+ */
39
+ import { CompilerOptions, SourceFile } from 'ts-morph';
40
+ /**
41
+ * Resolves `@opencrvs/toolkit/events` to `toolkitEventsPath`, keeping the country
42
+ * config's other `paths`. The country config still has the toolkit it upgrades from
43
+ * installed, whose types have no `VersionedEventConfig`, so the codemod reads the
44
+ * types of the toolkit running it instead.
45
+ */
46
+ export declare function withToolkitEventsAt(compilerOptions: CompilerOptions, toolkitEventsPath: string): CompilerOptions;
47
+ /**
48
+ * Rewrites every use of a `VersionedEventConfig` as a flat `EventConfig` in the
49
+ * file to go through `resolveEventConfig()`.
50
+ *
51
+ * @returns the number of uses rewritten.
52
+ */
53
+ export declare function rewriteVersionedEventConfigUses(sourceFile: SourceFile): number;
54
+ declare function main(): Promise<void>;
55
+ export { main };
56
+ //# sourceMappingURL=resolve-versioned-event-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-versioned-event-config.d.ts","sourceRoot":"","sources":["../../src/migrations/resolve-versioned-event-config.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,EACL,eAAe,EAMf,UAAU,EAGX,MAAM,UAAU,CAAA;AAsRjB;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,eAAe,EAAE,eAAe,EAChC,iBAAiB,EAAE,MAAM,GACxB,eAAe,CAQjB;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAC7C,UAAU,EAAE,UAAU,GACrB,MAAM,CAiDR;AAED,iBAAe,IAAI,kBAuDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}