@opencrvs/toolkit 1.9.12-rc.fdea6df → 1.9.12-rc.ff04697

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 (107) hide show
  1. package/build.sh +8 -0
  2. package/dist/application-config/index.js +2045 -41
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +3799 -0
  6. package/dist/commons/api/router.d.ts +197 -159
  7. package/dist/commons/application-config/index.d.ts +13 -16
  8. package/dist/commons/conditionals/conditionals.d.ts +3 -3
  9. package/dist/commons/events/ActionDocument.d.ts +198 -198
  10. package/dist/commons/events/ActionInput.d.ts +113 -113
  11. package/dist/commons/events/ActionType.d.ts +3 -3
  12. package/dist/commons/events/AdvancedSearchConfig.d.ts +16 -10
  13. package/dist/commons/events/CompositeFieldValue.d.ts +4 -4
  14. package/dist/commons/events/CountryConfigQueryInput.d.ts +443 -172
  15. package/dist/commons/events/Draft.d.ts +15 -15
  16. package/dist/commons/events/DynamicFieldValue.d.ts +37 -19
  17. package/dist/commons/events/EventConfig.d.ts +4 -2
  18. package/dist/commons/events/EventDocument.d.ts +81 -81
  19. package/dist/commons/events/EventIndex.d.ts +35 -27
  20. package/dist/commons/events/EventInput.d.ts +1 -1
  21. package/dist/commons/events/EventMetadata.d.ts +24 -24
  22. package/dist/commons/events/FieldConfig.d.ts +157 -46
  23. package/dist/commons/events/FieldType.d.ts +2 -1
  24. package/dist/commons/events/FieldTypeMapping.d.ts +98 -72
  25. package/dist/commons/events/FieldValue.d.ts +54 -26
  26. package/dist/commons/events/PlainDate.d.ts +1 -1
  27. package/dist/commons/events/WorkqueueColumnConfig.d.ts +16 -16
  28. package/dist/commons/events/WorkqueueConfig.d.ts +438 -194
  29. package/dist/commons/events/defineConfig.d.ts +0 -4
  30. package/dist/commons/events/locations.d.ts +4 -4
  31. package/dist/commons/events/scopes.d.ts +1 -1
  32. package/dist/commons/events/state/index.d.ts +2 -2
  33. package/dist/commons/events/state/utils.d.ts +3 -3
  34. package/dist/commons/events/utils.d.ts +5 -177
  35. package/dist/conditionals/index.js +13 -5
  36. package/dist/events/index.js +149 -36
  37. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts +3 -0
  38. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -0
  39. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +404 -0
  40. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +22 -0
  41. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -0
  42. package/dist/migrations/v2.0/checkout-upstream-files.js +147 -0
  43. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts +2 -0
  44. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -0
  45. package/dist/migrations/v2.0/convert-config-files-to-ts.js +828 -0
  46. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +3 -0
  47. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -0
  48. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +158 -0
  49. package/dist/migrations/v2.0/create-events-index.d.ts +3 -0
  50. package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -0
  51. package/dist/migrations/v2.0/create-events-index.js +325 -0
  52. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +3 -0
  53. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -0
  54. package/dist/migrations/v2.0/delete-infrastructure-directory.js +77 -0
  55. package/dist/migrations/v2.0/index.d.ts +11 -0
  56. package/dist/migrations/v2.0/index.d.ts.map +1 -0
  57. package/dist/migrations/v2.0/index.js +3709 -0
  58. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +3 -0
  59. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -0
  60. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +343 -0
  61. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +3 -0
  62. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -0
  63. package/dist/migrations/v2.0/merge-infrastructure-directory.js +221 -0
  64. package/dist/migrations/v2.0/migrate-scopes.d.ts +3 -0
  65. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -0
  66. package/dist/migrations/v2.0/migrate-scopes.js +281 -0
  67. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +3 -0
  68. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -0
  69. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +267 -0
  70. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +3 -0
  71. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -0
  72. package/dist/migrations/v2.0/migrate-workqueue-configs.js +236 -0
  73. package/dist/migrations/v2.0/remove-delete-actions.d.ts +3 -0
  74. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -0
  75. package/dist/migrations/v2.0/remove-delete-actions.js +156 -0
  76. package/dist/migrations/v2.0/remove-demo-scope.d.ts +3 -0
  77. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -0
  78. package/dist/migrations/v2.0/remove-demo-scope.js +74 -0
  79. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +3 -0
  80. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -0
  81. package/dist/migrations/v2.0/remove-deprecated-imports.js +96 -0
  82. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +3 -0
  83. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -0
  84. package/dist/migrations/v2.0/remove-hearth-migrations.js +77 -0
  85. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +3 -0
  86. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -0
  87. package/dist/migrations/v2.0/remove-pending-certification-flag.js +109 -0
  88. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +3 -0
  89. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -0
  90. package/dist/migrations/v2.0/remove-review-from-register-action.js +163 -0
  91. package/dist/migrations/v2.0/rename-api-paths.d.ts +3 -0
  92. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -0
  93. package/dist/migrations/v2.0/rename-api-paths.js +187 -0
  94. package/dist/migrations/v2.0/rename-location-parent-id.d.ts +3 -0
  95. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -0
  96. package/dist/migrations/v2.0/rename-location-parent-id.js +180 -0
  97. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +3 -0
  98. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -0
  99. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +195 -0
  100. package/dist/notification/index.js +78 -25
  101. package/dist/scopes/index.d.ts +31 -10
  102. package/dist/scopes/index.js +17 -5
  103. package/opencrvs-toolkit-1.9.12-rc.ff04697.tgz +0 -0
  104. package/package.json +11 -7
  105. package/tsconfig.json +3 -0
  106. package/tsconfig.tsbuildinfo +1 -1
  107. package/opencrvs-toolkit-1.9.12-rc.fdea6df.tgz +0 -0
@@ -0,0 +1,281 @@
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.main = main;
26
+ const ts_morph_1 = require("ts-morph");
27
+ const path_1 = __importDefault(require("path"));
28
+ const scopes_1 = require("../commons/scopes");
29
+ const scopes_deprecated_do_not_use_1 = require("../commons/scopes.deprecated.do-not-use");
30
+ const ROLES_FILE_RELATIVE_PATH = 'src/data-seeding/roles/roles.ts';
31
+ const SCOPES_PROPERTY_NAME = 'scopes';
32
+ const TOOLKIT_SCOPES_MODULE = '@opencrvs/toolkit/scopes';
33
+ const DEFINE_SCOPES_IMPORT_NAME = 'defineScopes';
34
+ const DEFINE_ROLES_IMPORT_NAME = 'defineRoles';
35
+ function resolveScopeKeyFromElementAccess(element) {
36
+ if (ts_morph_1.Node.isPropertyAccessExpression(element) &&
37
+ element.getExpression().getText() === 'SCOPES') {
38
+ return element.getName();
39
+ }
40
+ if (ts_morph_1.Node.isElementAccessExpression(element) &&
41
+ element.getExpression().getText() === 'SCOPES') {
42
+ const argumentExpression = element.getArgumentExpression();
43
+ if (argumentExpression &&
44
+ (ts_morph_1.Node.isStringLiteral(argumentExpression) ||
45
+ ts_morph_1.Node.isNoSubstitutionTemplateLiteral(argumentExpression))) {
46
+ return argumentExpression.getLiteralValue();
47
+ }
48
+ }
49
+ return null;
50
+ }
51
+ function resolveLegacyScopeFromElement(element) {
52
+ if (ts_morph_1.Node.isStringLiteral(element) ||
53
+ ts_morph_1.Node.isNoSubstitutionTemplateLiteral(element)) {
54
+ return element.getLiteralValue();
55
+ }
56
+ const scopeKey = resolveScopeKeyFromElementAccess(element);
57
+ if (scopeKey) {
58
+ const scopeValue = scopes_deprecated_do_not_use_1.SCOPES[scopeKey];
59
+ return typeof scopeValue === 'string' ? scopeValue : null;
60
+ }
61
+ const expressionType = element.getType();
62
+ if (expressionType.isStringLiteral()) {
63
+ const literalValue = expressionType.getLiteralValue();
64
+ return typeof literalValue === 'string' ? literalValue : null;
65
+ }
66
+ return null;
67
+ }
68
+ function migrateScopesArrays(rolesFilePath, project) {
69
+ const sourceFile = project.getSourceFile(rolesFilePath);
70
+ if (!sourceFile)
71
+ return { migratedCount: 0, removedCount: 0 };
72
+ let migratedCount = 0;
73
+ let removedCount = 0;
74
+ const scopesProperties = sourceFile
75
+ .getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertyAssignment)
76
+ .filter((prop) => prop.getName() === SCOPES_PROPERTY_NAME);
77
+ for (const scopesProp of scopesProperties) {
78
+ const initializer = scopesProp.getInitializer();
79
+ if (!initializer || !ts_morph_1.Node.isArrayLiteralExpression(initializer))
80
+ continue;
81
+ const elements = initializer.getElements();
82
+ for (let index = elements.length - 1; index >= 0; index--) {
83
+ const element = elements[index];
84
+ if (!ts_morph_1.Node.isExpression(element))
85
+ continue;
86
+ const scopeKey = resolveScopeKeyFromElementAccess(element);
87
+ if (scopeKey && !(scopeKey in scopes_deprecated_do_not_use_1.SCOPES)) {
88
+ // eslint-disable-next-line no-console
89
+ console.warn(` [${path_1.default.relative(process.cwd(), rolesFilePath)}] Removing unknown scope reference: SCOPES.${scopeKey}`);
90
+ initializer.removeElement(index);
91
+ removedCount++;
92
+ continue;
93
+ }
94
+ const legacyScope = resolveLegacyScopeFromElement(element);
95
+ if (!legacyScope) {
96
+ // eslint-disable-next-line no-console
97
+ console.warn(` [${path_1.default.relative(process.cwd(), rolesFilePath)}] Skipping non-literal scope expression: ${element.getText()}`);
98
+ continue;
99
+ }
100
+ try {
101
+ const migratedScope = (0, scopes_deprecated_do_not_use_1.legacyScopeToV2Scope)(legacyScope);
102
+ const scope = (0, scopes_1.decodeScope)(migratedScope);
103
+ if (!scope) {
104
+ // eslint-disable-next-line no-console
105
+ console.warn(` [${path_1.default.relative(process.cwd(), rolesFilePath)}] Could not decode migrated scope '${migratedScope}'.`);
106
+ continue;
107
+ }
108
+ element.replaceWithText(JSON.stringify(scope));
109
+ migratedCount++;
110
+ }
111
+ catch (error) {
112
+ // eslint-disable-next-line no-console
113
+ console.warn(` [${path_1.default.relative(process.cwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`);
114
+ }
115
+ }
116
+ }
117
+ if (removedCount > 0) {
118
+ // eslint-disable-next-line no-console
119
+ console.log(` Removed ${removedCount} unknown SCOPES reference(s) from '${path_1.default.relative(process.cwd(), rolesFilePath)}'.`);
120
+ }
121
+ return { migratedCount, removedCount };
122
+ }
123
+ function ensureScopesHelpersImport(rolesFilePath, project) {
124
+ const sourceFile = project.getSourceFile(rolesFilePath);
125
+ if (!sourceFile)
126
+ return false;
127
+ const existingImport = sourceFile.getImportDeclaration((decl) => decl.getModuleSpecifierValue() === TOOLKIT_SCOPES_MODULE);
128
+ let changed = false;
129
+ if (existingImport) {
130
+ const hasDefineScopesImport = existingImport
131
+ .getNamedImports()
132
+ .some((ni) => ni.getName() === DEFINE_SCOPES_IMPORT_NAME);
133
+ const hasDefineRolesImport = existingImport
134
+ .getNamedImports()
135
+ .some((ni) => ni.getName() === DEFINE_ROLES_IMPORT_NAME);
136
+ if (!hasDefineScopesImport) {
137
+ existingImport.addNamedImport(DEFINE_SCOPES_IMPORT_NAME);
138
+ changed = true;
139
+ }
140
+ if (!hasDefineRolesImport) {
141
+ existingImport.addNamedImport(DEFINE_ROLES_IMPORT_NAME);
142
+ changed = true;
143
+ }
144
+ const encodeScopeImport = existingImport
145
+ .getNamedImports()
146
+ .find((ni) => ni.getName() === 'encodeScope');
147
+ if (encodeScopeImport) {
148
+ encodeScopeImport.remove();
149
+ changed = true;
150
+ }
151
+ return changed;
152
+ }
153
+ sourceFile.addImportDeclaration({
154
+ moduleSpecifier: TOOLKIT_SCOPES_MODULE,
155
+ namedImports: [DEFINE_SCOPES_IMPORT_NAME, DEFINE_ROLES_IMPORT_NAME]
156
+ });
157
+ return true;
158
+ }
159
+ function wrapScopesArraysWithDefineScopes(rolesFilePath, project) {
160
+ const sourceFile = project.getSourceFile(rolesFilePath);
161
+ if (!sourceFile)
162
+ return 0;
163
+ let wrappedCount = 0;
164
+ const scopesProperties = sourceFile
165
+ .getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertyAssignment)
166
+ .filter((prop) => prop.getName() === SCOPES_PROPERTY_NAME);
167
+ for (const scopesProp of scopesProperties) {
168
+ const initializer = scopesProp.getInitializer();
169
+ if (!initializer)
170
+ continue;
171
+ if (ts_morph_1.Node.isCallExpression(initializer) &&
172
+ initializer.getExpression().getText() === DEFINE_SCOPES_IMPORT_NAME) {
173
+ continue;
174
+ }
175
+ if (!ts_morph_1.Node.isArrayLiteralExpression(initializer))
176
+ continue;
177
+ scopesProp.setInitializer(`${DEFINE_SCOPES_IMPORT_NAME}(${initializer.getText()})`);
178
+ wrappedCount++;
179
+ }
180
+ return wrappedCount;
181
+ }
182
+ function wrapRolesWithDefineRoles(rolesFilePath, project) {
183
+ const sourceFile = project.getSourceFile(rolesFilePath);
184
+ if (!sourceFile)
185
+ return false;
186
+ const rolesDeclaration = sourceFile.getVariableDeclaration('roles');
187
+ if (!rolesDeclaration)
188
+ return false;
189
+ const initializer = rolesDeclaration.getInitializer();
190
+ if (!initializer)
191
+ return false;
192
+ if (ts_morph_1.Node.isCallExpression(initializer) &&
193
+ initializer.getExpression().getText() === DEFINE_ROLES_IMPORT_NAME) {
194
+ return false;
195
+ }
196
+ if (!ts_morph_1.Node.isArrayLiteralExpression(initializer))
197
+ return false;
198
+ const typeNode = rolesDeclaration.getTypeNode();
199
+ if (typeNode === null || typeNode === void 0 ? void 0 : typeNode.getText().includes('Role')) {
200
+ rolesDeclaration.removeType();
201
+ }
202
+ rolesDeclaration.setInitializer(`${DEFINE_ROLES_IMPORT_NAME}(${initializer.getText()})`);
203
+ return true;
204
+ }
205
+ function pruneNamedImportIfUnused(sourceFile, moduleSpecifier, importName) {
206
+ const importDeclaration = sourceFile.getImportDeclaration((decl) => decl.getModuleSpecifierValue() === moduleSpecifier);
207
+ if (!importDeclaration)
208
+ return false;
209
+ const namedImport = importDeclaration
210
+ .getNamedImports()
211
+ .find((ni) => ni.getName() === importName);
212
+ if (!namedImport)
213
+ return false;
214
+ const references = sourceFile
215
+ .getDescendantsOfKind(ts_morph_1.SyntaxKind.Identifier)
216
+ .filter((identifier) => identifier.getText() === importName &&
217
+ !ts_morph_1.Node.isImportSpecifier(identifier.getParent()));
218
+ if (references.length > 0) {
219
+ return false;
220
+ }
221
+ namedImport.remove();
222
+ if (importDeclaration.getNamedImports().length === 0 &&
223
+ !importDeclaration.getDefaultImport() &&
224
+ !importDeclaration.getNamespaceImport()) {
225
+ importDeclaration.remove();
226
+ }
227
+ return true;
228
+ }
229
+ function removeRoleTypeDefinitionAndUnusedImports(rolesFilePath, project) {
230
+ const sourceFile = project.getSourceFile(rolesFilePath);
231
+ if (!sourceFile)
232
+ return false;
233
+ let removed = false;
234
+ const roleTypeAlias = sourceFile.getTypeAlias('Role');
235
+ if (roleTypeAlias) {
236
+ roleTypeAlias.remove();
237
+ removed = true;
238
+ }
239
+ const roleInterface = sourceFile.getInterface('Role');
240
+ if (roleInterface) {
241
+ roleInterface.remove();
242
+ removed = true;
243
+ }
244
+ const removedScopeImport = pruneNamedImportIfUnused(sourceFile, TOOLKIT_SCOPES_MODULE, 'Scope');
245
+ const removedMessageDescriptorImport = pruneNamedImportIfUnused(sourceFile, 'react-intl', 'MessageDescriptor');
246
+ removed = removed || removedScopeImport || removedMessageDescriptorImport;
247
+ return removed;
248
+ }
249
+ function main() {
250
+ return __awaiter(this, void 0, void 0, function* () {
251
+ const cwd = process.cwd();
252
+ const srcDir = path_1.default.join(cwd, 'src');
253
+ const rolesFilePath = path_1.default.join(cwd, ROLES_FILE_RELATIVE_PATH);
254
+ console.log(`Scanning roles scopes in: ${rolesFilePath}`);
255
+ const project = new ts_morph_1.Project({
256
+ tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
257
+ skipAddingFilesFromTsConfig: false
258
+ });
259
+ const sourceFile = project.getSourceFile(rolesFilePath);
260
+ if (!sourceFile) {
261
+ console.log(`No roles file found at '${ROLES_FILE_RELATIVE_PATH}'. Nothing to do.`);
262
+ return;
263
+ }
264
+ const importChanged = ensureScopesHelpersImport(rolesFilePath, project);
265
+ const { migratedCount, removedCount } = migrateScopesArrays(rolesFilePath, project);
266
+ const wrappedScopesCount = wrapScopesArraysWithDefineScopes(rolesFilePath, project);
267
+ const wrappedRoles = wrapRolesWithDefineRoles(rolesFilePath, project);
268
+ const removedRoleType = removeRoleTypeDefinitionAndUnusedImports(rolesFilePath, project);
269
+ if (migratedCount === 0 &&
270
+ removedCount === 0 &&
271
+ wrappedScopesCount === 0 &&
272
+ !wrappedRoles &&
273
+ !removedRoleType &&
274
+ !importChanged) {
275
+ console.log('No migratable literal scopes found. Nothing to do.');
276
+ return;
277
+ }
278
+ yield sourceFile.save();
279
+ console.log(`Done. Migrated ${migratedCount} legacy scope(s), removed ${removedCount} unknown SCOPES reference(s), wrapped ${wrappedScopesCount} scope array(s) with defineScopes()${wrappedRoles ? ', wrapped roles with defineRoles()' : ''}${removedRoleType ? ', and removed Role type definition' : ''}${importChanged ? '. Updated toolkit/scopes imports.' : '.'}`);
280
+ });
281
+ }
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=migrate-validated-workqueue-status-to-flag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate-validated-workqueue-status-to-flag.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/migrate-validated-workqueue-status-to-flag.ts"],"names":[],"mappings":"AAyQA,iBAAe,IAAI,kBA+ClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,267 @@
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.main = main;
26
+ /**
27
+ * Codemod: Migrate `VALIDATED` status references to flags inside `defineWorkqueues` calls.
28
+ *
29
+ * Usage:
30
+ * ts-node -r tsconfig-paths/register src/migrations/v2.0/migrate-validated-workqueue-status-to-flag.ts
31
+ *
32
+ * What it does:
33
+ * - Scans all TypeScript files under `src/`
34
+ * - Finds every `defineWorkqueues([...])` call expression
35
+ * - For each workqueue config's `query`, recursively walks `or`/`and` containers
36
+ * and processes every leaf clause object
37
+ * - In each clause:
38
+ * - `status: { type: 'anyOf', terms: [..., 'VALIDATED', ...] }`
39
+ * → removes `'VALIDATED'` from `terms`; removes `status` entirely if `terms`
40
+ * becomes empty; adds `'validated'` to `flags.anyOf`
41
+ * - `status: { type: 'exact', term: 'VALIDATED' }`
42
+ * → removes `status` entirely; adds `'validated'` to `flags.anyOf`
43
+ * - When adding to `flags.anyOf`, merges with an existing `flags` object if present
44
+ * - Saves the modified files in-place
45
+ */
46
+ const ts_morph_1 = require("ts-morph");
47
+ const path_1 = __importDefault(require("path"));
48
+ const DEFINE_WORKQUEUES_NAME = 'defineWorkqueues';
49
+ const QUERY_PROPERTY_NAME = 'query';
50
+ const TYPE_PROPERTY_NAME = 'type';
51
+ const CLAUSES_PROPERTY_NAME = 'clauses';
52
+ const STATUS_PROPERTY_NAME = 'status';
53
+ const FLAGS_PROPERTY_NAME = 'flags';
54
+ const TERMS_PROPERTY_NAME = 'terms';
55
+ const TERM_PROPERTY_NAME = 'term';
56
+ const ANY_OF_PROPERTY_NAME = 'anyOf';
57
+ const VALIDATED_STATUS_VALUE = 'VALIDATED';
58
+ const VALIDATED_FLAG_VALUE = 'validated';
59
+ // ─── Helpers ─────────────────────────────────────────────────────────────────
60
+ /**
61
+ * Adds `'validated'` to `flags.anyOf` on a clause object, merging with
62
+ * whatever `flags` shape already exists.
63
+ */
64
+ function addValidatedFlag(clause) {
65
+ const flagsProperty = clause.getProperty(FLAGS_PROPERTY_NAME);
66
+ if (flagsProperty && ts_morph_1.Node.isPropertyAssignment(flagsProperty)) {
67
+ const flagsInit = flagsProperty.getInitializer();
68
+ if (flagsInit && ts_morph_1.Node.isObjectLiteralExpression(flagsInit)) {
69
+ const anyOfProperty = flagsInit.getProperty(ANY_OF_PROPERTY_NAME);
70
+ if (anyOfProperty && ts_morph_1.Node.isPropertyAssignment(anyOfProperty)) {
71
+ // Append to existing anyOf array
72
+ const anyOfInit = anyOfProperty.getInitializer();
73
+ if (anyOfInit && ts_morph_1.Node.isArrayLiteralExpression(anyOfInit)) {
74
+ anyOfInit.addElement(`'${VALIDATED_FLAG_VALUE}'`);
75
+ }
76
+ }
77
+ else {
78
+ // flags exists but has no anyOf — add it
79
+ flagsInit.addPropertyAssignment({
80
+ name: ANY_OF_PROPERTY_NAME,
81
+ initializer: `['${VALIDATED_FLAG_VALUE}']`
82
+ });
83
+ }
84
+ }
85
+ }
86
+ else {
87
+ // No flags property at all — add one
88
+ clause.addPropertyAssignment({
89
+ name: FLAGS_PROPERTY_NAME,
90
+ initializer: `{ ${ANY_OF_PROPERTY_NAME}: ['${VALIDATED_FLAG_VALUE}'] }`
91
+ });
92
+ }
93
+ }
94
+ /**
95
+ * Processes a single leaf clause object.
96
+ * Returns true if any change was made.
97
+ */
98
+ function migrateClause(clause) {
99
+ const statusProperty = clause.getProperty(STATUS_PROPERTY_NAME);
100
+ if (!statusProperty || !ts_morph_1.Node.isPropertyAssignment(statusProperty)) {
101
+ return false;
102
+ }
103
+ const statusInit = statusProperty.getInitializer();
104
+ if (!statusInit || !ts_morph_1.Node.isObjectLiteralExpression(statusInit)) {
105
+ return false;
106
+ }
107
+ const statusTypeProperty = statusInit.getProperty(TYPE_PROPERTY_NAME);
108
+ if (!statusTypeProperty || !ts_morph_1.Node.isPropertyAssignment(statusTypeProperty)) {
109
+ return false;
110
+ }
111
+ const statusTypeInit = statusTypeProperty.getInitializer();
112
+ if (!statusTypeInit || !ts_morph_1.Node.isStringLiteral(statusTypeInit)) {
113
+ return false;
114
+ }
115
+ const statusType = statusTypeInit.getLiteralValue();
116
+ // ── anyOf case ──────────────────────────────────────────────────────────────
117
+ if (statusType === 'anyOf') {
118
+ const termsProperty = statusInit.getProperty(TERMS_PROPERTY_NAME);
119
+ if (!termsProperty || !ts_morph_1.Node.isPropertyAssignment(termsProperty)) {
120
+ return false;
121
+ }
122
+ const termsInit = termsProperty.getInitializer();
123
+ if (!termsInit || !ts_morph_1.Node.isArrayLiteralExpression(termsInit)) {
124
+ return false;
125
+ }
126
+ const elements = termsInit.getElements();
127
+ const validatedIndex = elements.findIndex((el) => ts_morph_1.Node.isStringLiteral(el) &&
128
+ el.getLiteralValue() === VALIDATED_STATUS_VALUE);
129
+ if (validatedIndex === -1)
130
+ return false;
131
+ // Remove 'VALIDATED' from terms
132
+ termsInit.removeElement(validatedIndex);
133
+ // If terms is now empty, drop the whole status property
134
+ if (termsInit.getElements().length === 0) {
135
+ statusProperty.remove();
136
+ }
137
+ addValidatedFlag(clause);
138
+ return true;
139
+ }
140
+ // ── exact case ──────────────────────────────────────────────────────────────
141
+ if (statusType === 'exact') {
142
+ const termProperty = statusInit.getProperty(TERM_PROPERTY_NAME);
143
+ if (!termProperty || !ts_morph_1.Node.isPropertyAssignment(termProperty)) {
144
+ return false;
145
+ }
146
+ const termInit = termProperty.getInitializer();
147
+ if (!termInit || !ts_morph_1.Node.isStringLiteral(termInit)) {
148
+ return false;
149
+ }
150
+ if (termInit.getLiteralValue() !== VALIDATED_STATUS_VALUE)
151
+ return false;
152
+ // Remove the entire status property
153
+ statusProperty.remove();
154
+ addValidatedFlag(clause);
155
+ return true;
156
+ }
157
+ return false;
158
+ }
159
+ /**
160
+ * Recursively walks a query node.
161
+ * - If it is an `or`/`and` container, recurses into `clauses`
162
+ * - Otherwise treats it as a leaf clause and calls `migrateClause`
163
+ * Returns the number of clauses changed.
164
+ */
165
+ function walkQuery(queryObj) {
166
+ const typeProperty = queryObj.getProperty(TYPE_PROPERTY_NAME);
167
+ if (typeProperty && ts_morph_1.Node.isPropertyAssignment(typeProperty)) {
168
+ const typeInit = typeProperty.getInitializer();
169
+ if (typeInit &&
170
+ ts_morph_1.Node.isStringLiteral(typeInit) &&
171
+ (typeInit.getLiteralValue() === 'or' ||
172
+ typeInit.getLiteralValue() === 'and')) {
173
+ const clausesProperty = queryObj.getProperty(CLAUSES_PROPERTY_NAME);
174
+ if (!clausesProperty || !ts_morph_1.Node.isPropertyAssignment(clausesProperty)) {
175
+ return 0;
176
+ }
177
+ const clausesInit = clausesProperty.getInitializer();
178
+ if (!clausesInit || !ts_morph_1.Node.isArrayLiteralExpression(clausesInit)) {
179
+ return 0;
180
+ }
181
+ let changed = 0;
182
+ for (const clause of clausesInit.getElements()) {
183
+ if (ts_morph_1.Node.isObjectLiteralExpression(clause)) {
184
+ changed += walkQuery(clause);
185
+ }
186
+ }
187
+ return changed;
188
+ }
189
+ }
190
+ // Leaf clause
191
+ return migrateClause(queryObj) ? 1 : 0;
192
+ }
193
+ // ─── File processor ──────────────────────────────────────────────────────────
194
+ function processFile(filePath, project) {
195
+ const sourceFile = project.getSourceFile(filePath);
196
+ if (!sourceFile)
197
+ return 0;
198
+ let migratedCount = 0;
199
+ const callExpressions = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
200
+ for (const call of callExpressions) {
201
+ const expression = call.getExpression();
202
+ if (!ts_morph_1.Node.isIdentifier(expression) ||
203
+ expression.getText() !== DEFINE_WORKQUEUES_NAME) {
204
+ continue;
205
+ }
206
+ const args = call.getArguments();
207
+ if (args.length === 0)
208
+ continue;
209
+ // The argument must be an array literal of workqueue config objects
210
+ const workqueuesArg = args[0];
211
+ if (!ts_morph_1.Node.isArrayLiteralExpression(workqueuesArg))
212
+ continue;
213
+ for (const workqueueElement of workqueuesArg.getElements()) {
214
+ if (!ts_morph_1.Node.isObjectLiteralExpression(workqueueElement))
215
+ continue;
216
+ const queryProperty = workqueueElement.getProperty(QUERY_PROPERTY_NAME);
217
+ if (!queryProperty || !ts_morph_1.Node.isPropertyAssignment(queryProperty))
218
+ continue;
219
+ const queryInit = queryProperty.getInitializer();
220
+ if (!queryInit || !ts_morph_1.Node.isObjectLiteralExpression(queryInit))
221
+ continue;
222
+ const changed = walkQuery(queryInit);
223
+ if (changed > 0) {
224
+ migratedCount += changed;
225
+ console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Migrated ${changed} clause(s): VALIDATED status → flags.anyOf`);
226
+ }
227
+ }
228
+ }
229
+ return migratedCount;
230
+ }
231
+ // ─── Entry point ─────────────────────────────────────────────────────────────
232
+ function main() {
233
+ return __awaiter(this, void 0, void 0, function* () {
234
+ const srcDir = path_1.default.join(process.cwd(), 'src');
235
+ console.log(`Scanning for defineWorkqueues calls in: ${srcDir}\n`);
236
+ const project = new ts_morph_1.Project({
237
+ tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
238
+ skipAddingFilesFromTsConfig: false
239
+ });
240
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
241
+ const fp = sf.getFilePath();
242
+ return fp.includes('/src/') && !fp.includes('/node_modules/');
243
+ });
244
+ console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
245
+ let totalMigrated = 0;
246
+ const modifiedFiles = [];
247
+ for (const sourceFile of sourceFiles) {
248
+ const filePath = sourceFile.getFilePath();
249
+ const migrated = processFile(filePath, project);
250
+ if (migrated > 0) {
251
+ totalMigrated += migrated;
252
+ modifiedFiles.push(filePath);
253
+ }
254
+ }
255
+ if (modifiedFiles.length === 0) {
256
+ console.log('No VALIDATED status references found in defineWorkqueues calls. Nothing to do.');
257
+ return;
258
+ }
259
+ console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
260
+ for (const filePath of modifiedFiles) {
261
+ const sourceFile = project.getSourceFileOrThrow(filePath);
262
+ yield sourceFile.save();
263
+ console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
264
+ }
265
+ console.log(`\nDone. Migrated ${totalMigrated} clause(s) from VALIDATED status to flags.anyOf['validated'].`);
266
+ });
267
+ }
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=migrate-workqueue-configs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate-workqueue-configs.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/migrate-workqueue-configs.ts"],"names":[],"mappings":"AA+OA,iBAAe,IAAI,kBAqDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}