@opencrvs/toolkit 1.9.13-rc.fc5374d → 2.0.0-rc.e0918cb
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.
- package/build.sh +13 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/application-config/index.d.ts +2 -0
- package/dist/application-config/index.d.ts.map +1 -0
- package/dist/application-config/index.js +2128 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +3633 -0
- package/dist/commons/api/router.d.ts +3438 -2300
- package/dist/commons/application-config/index.d.ts +84 -0
- package/dist/commons/conditionals/conditionals.d.ts +27 -3
- package/dist/commons/conditionals/validate.d.ts +13 -3
- package/dist/commons/events/ActionConfig.d.ts +415 -1555
- package/dist/commons/events/ActionDocument.d.ts +888 -1941
- package/dist/commons/events/ActionInput.d.ts +277 -1073
- package/dist/commons/events/ActionType.d.ts +91 -11
- package/dist/commons/events/AdvancedSearchConfig.d.ts +294 -1496
- package/dist/commons/events/AuditLog.d.ts +405 -0
- package/dist/commons/events/CompositeFieldValue.d.ts +30 -190
- package/dist/commons/events/Conditional.d.ts +26 -38
- package/dist/commons/events/Constants.d.ts +1 -1
- package/dist/commons/events/CountryConfigQueryInput.d.ts +1592 -4471
- package/dist/commons/events/DeduplicationConfig.d.ts +15 -171
- package/dist/commons/events/Draft.d.ts +72 -107
- package/dist/commons/events/DynamicFieldValue.d.ts +12 -78
- package/dist/commons/events/EventConfig.d.ts +37 -2420
- package/dist/commons/events/EventConfigInput.d.ts +0 -3
- package/dist/commons/events/EventDocument.d.ts +354 -1366
- package/dist/commons/events/EventIndex.d.ts +212 -1010
- package/dist/commons/events/EventInput.d.ts +3 -8
- package/dist/commons/events/EventMetadata.d.ts +130 -357
- package/dist/commons/events/FieldConfig.d.ts +2892 -12892
- package/dist/commons/events/FieldType.d.ts +26 -4
- package/dist/commons/events/FieldTypeMapping.d.ts +314 -906
- package/dist/commons/events/FieldValue.d.ts +149 -527
- package/dist/commons/events/FileUtils.d.ts +2 -2
- package/dist/commons/events/Flag.d.ts +67 -0
- package/dist/commons/events/FormConfig.d.ts +54 -721
- package/dist/commons/events/PageConfig.d.ts +58 -320
- package/dist/commons/events/PlainDate.d.ts +1 -1
- package/dist/commons/events/SummaryConfig.d.ts +14 -161
- package/dist/commons/events/TemplateConfig.d.ts +2 -3
- package/dist/commons/events/TranslationConfig.d.ts +2 -2
- package/dist/commons/events/WorkqueueColumnConfig.d.ts +74 -37
- package/dist/commons/events/WorkqueueConfig.d.ts +2208 -7553
- package/dist/commons/events/deduplication.d.ts +3 -3
- package/dist/commons/events/defineConfig.d.ts +2 -247
- package/dist/commons/events/eventConfigValidation.d.ts +8 -0
- package/dist/commons/events/index.d.ts +3 -0
- package/dist/commons/events/locations.d.ts +57 -20
- package/dist/commons/events/scopes.d.ts +36 -35
- package/dist/commons/events/state/availableActions.d.ts +7 -2
- package/dist/commons/events/state/flags.d.ts +21 -3
- package/dist/commons/events/state/index.d.ts +30 -27
- package/dist/commons/events/state/utils.d.ts +190 -172
- package/dist/commons/events/test.utils.d.ts +52 -11
- package/dist/commons/events/transactions.d.ts +1 -1
- package/dist/commons/events/utils.d.ts +373 -273
- package/dist/commons/notification/UserNotifications.d.ts +61 -637
- package/dist/conditionals/index.d.ts.map +1 -1
- package/dist/conditionals/index.js +302 -14
- package/dist/events/deduplication.d.ts +3 -3
- package/dist/events/index.js +2860 -2115
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts +3 -0
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -0
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +405 -0
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts +3 -0
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -0
- package/dist/migrations/v2.0/checkout-upstream-files.js +143 -0
- package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts +2 -0
- package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -0
- package/dist/migrations/v2.0/convert-config-files-to-ts.js +829 -0
- package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +3 -0
- package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -0
- package/dist/migrations/v2.0/convert-paragraph-to-heading.js +159 -0
- package/dist/migrations/v2.0/create-events-index.d.ts +3 -0
- package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -0
- package/dist/migrations/v2.0/create-events-index.js +326 -0
- package/dist/migrations/v2.0/index.d.ts +7 -0
- package/dist/migrations/v2.0/index.d.ts.map +1 -0
- package/dist/migrations/v2.0/index.js +3572 -0
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +3 -0
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -0
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +344 -0
- package/dist/migrations/v2.0/migrate-scopes.d.ts +3 -0
- package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -0
- package/dist/migrations/v2.0/migrate-scopes.js +282 -0
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +3 -0
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -0
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +268 -0
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +3 -0
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -0
- package/dist/migrations/v2.0/migrate-workqueue-configs.js +237 -0
- package/dist/migrations/v2.0/remove-delete-actions.d.ts +3 -0
- package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-delete-actions.js +157 -0
- package/dist/migrations/v2.0/remove-demo-scope.d.ts +3 -0
- package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-demo-scope.js +75 -0
- package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +3 -0
- package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-deprecated-imports.js +97 -0
- package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +3 -0
- package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-hearth-migrations.js +78 -0
- package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +3 -0
- package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-pending-certification-flag.js +110 -0
- package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +3 -0
- package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-review-from-register-action.js +164 -0
- package/dist/migrations/v2.0/rename-api-paths.d.ts +3 -0
- package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -0
- package/dist/migrations/v2.0/rename-api-paths.js +188 -0
- package/dist/migrations/v2.0/rename-location-parent-id.d.ts +3 -0
- package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -0
- package/dist/migrations/v2.0/rename-location-parent-id.js +181 -0
- package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +3 -0
- package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -0
- package/dist/migrations/v2.0/simplify-analytics-precalculations.js +196 -0
- package/dist/notification/index.d.ts.map +1 -1
- package/dist/notification/index.js +2076 -1767
- package/dist/scopes/index.d.ts +640 -353
- package/dist/scopes/index.d.ts.map +1 -1
- package/dist/scopes/index.js +340 -300
- package/opencrvs-toolkit-2.0.0-rc.e0918cb.tgz +0 -0
- package/package.json +18 -8
- package/tsconfig.json +12 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/commons/events/CreatedAtLocation.d.ts +0 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-birth-certificate-issuance-flag.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/add-birth-certificate-issuance-flag.ts"],"names":[],"mappings":"AA6aA,iBAAe,IAAI,kBAiDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1,405 @@
|
|
|
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: Add `pending-first-certificate-issuance` flag to birth event configs and workqueues.
|
|
28
|
+
*
|
|
29
|
+
* Usage:
|
|
30
|
+
* ts-node -r tsconfig-paths/register src/migrations/v2.0/add-birth-certificate-issuance-flag.ts
|
|
31
|
+
*
|
|
32
|
+
* What it does:
|
|
33
|
+
* defineConfig (birth type only):
|
|
34
|
+
* - Ensures the top-level `flags` array contains the `pending-first-certificate-issuance`
|
|
35
|
+
* flag definition
|
|
36
|
+
* - Ensures every `REGISTER` action has
|
|
37
|
+
* `flags: [{ id: 'pending-first-certificate-issuance', operation: 'add' }]`
|
|
38
|
+
* - Ensures every `PRINT_CERTIFICATE` action has
|
|
39
|
+
* `flags: [{ id: 'pending-first-certificate-issuance', operation: 'remove' }]`
|
|
40
|
+
*
|
|
41
|
+
* defineWorkqueues:
|
|
42
|
+
* - Finds workqueues whose `actions` array (or `action` object) contains a
|
|
43
|
+
* `PRINT_CERTIFICATE` type entry
|
|
44
|
+
* - Adds `flags: { anyOf: ['pending-first-certificate-issuance'] }` to every leaf
|
|
45
|
+
* clause in that workqueue's `query` (merging with existing `flags` if present)
|
|
46
|
+
*
|
|
47
|
+
* - Saves the modified files in-place
|
|
48
|
+
*/
|
|
49
|
+
const ts_morph_1 = require("ts-morph");
|
|
50
|
+
const path_1 = __importDefault(require("path"));
|
|
51
|
+
const _1 = require(".");
|
|
52
|
+
const DEFINE_CONFIG_NAME = 'defineConfig';
|
|
53
|
+
const DEFINE_WORKQUEUES_NAME = 'defineWorkqueues';
|
|
54
|
+
const ACTIONS_PROPERTY_NAME = 'actions';
|
|
55
|
+
const ACTION_PROPERTY_NAME = 'action';
|
|
56
|
+
const FLAGS_PROPERTY_NAME = 'flags';
|
|
57
|
+
const QUERY_PROPERTY_NAME = 'query';
|
|
58
|
+
const TYPE_PROPERTY_NAME = 'type';
|
|
59
|
+
const CLAUSES_PROPERTY_NAME = 'clauses';
|
|
60
|
+
const ANY_OF_PROPERTY_NAME = 'anyOf';
|
|
61
|
+
const FLAG_ID = 'pending-first-certificate-issuance';
|
|
62
|
+
const REGISTER_TYPE = 'REGISTER';
|
|
63
|
+
const PRINT_CERTIFICATE_TYPE = 'PRINT_CERTIFICATE';
|
|
64
|
+
const FLAG_DEFINITION_INITIALIZER = `{
|
|
65
|
+
id: '${FLAG_ID}',
|
|
66
|
+
label: {
|
|
67
|
+
id: 'event.birth.flag.${FLAG_ID}',
|
|
68
|
+
defaultMessage: 'Pending first certificate issuance',
|
|
69
|
+
description: 'Flag label for first certificate issuance'
|
|
70
|
+
},
|
|
71
|
+
requiresAction: true
|
|
72
|
+
}`;
|
|
73
|
+
// ─── Generic helpers ──────────────────────────────────────────────────────────
|
|
74
|
+
/**
|
|
75
|
+
* Returns true if the object's `type` property matches the given type name.
|
|
76
|
+
* Handles both `ActionType.PRINT_CERTIFICATE` and `'PRINT_CERTIFICATE'` forms.
|
|
77
|
+
*/
|
|
78
|
+
function isActionOfType(obj, typeName) {
|
|
79
|
+
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME);
|
|
80
|
+
if (!typeProperty || !ts_morph_1.Node.isPropertyAssignment(typeProperty))
|
|
81
|
+
return false;
|
|
82
|
+
const typeInit = typeProperty.getInitializer();
|
|
83
|
+
if (!typeInit)
|
|
84
|
+
return false;
|
|
85
|
+
if (ts_morph_1.Node.isPropertyAccessExpression(typeInit)) {
|
|
86
|
+
return typeInit.getName() === typeName;
|
|
87
|
+
}
|
|
88
|
+
if (ts_morph_1.Node.isStringLiteral(typeInit)) {
|
|
89
|
+
return typeInit.getLiteralValue() === typeName;
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Returns true when the `defineConfig` root config object describes a birth event.
|
|
95
|
+
* Handles both `'birth'` string literal and `EventType.BIRTH` enum access.
|
|
96
|
+
*/
|
|
97
|
+
function isBirthConfig(configArg) {
|
|
98
|
+
const typeProperty = configArg.getProperty(TYPE_PROPERTY_NAME);
|
|
99
|
+
if (!typeProperty || !ts_morph_1.Node.isPropertyAssignment(typeProperty))
|
|
100
|
+
return false;
|
|
101
|
+
const initializer = typeProperty.getInitializer();
|
|
102
|
+
if (!initializer)
|
|
103
|
+
return false;
|
|
104
|
+
if (ts_morph_1.Node.isStringLiteral(initializer)) {
|
|
105
|
+
return initializer.getLiteralValue().toLowerCase() === 'birth';
|
|
106
|
+
}
|
|
107
|
+
if (ts_morph_1.Node.isPropertyAccessExpression(initializer)) {
|
|
108
|
+
return initializer.getName().toLowerCase() === 'birth';
|
|
109
|
+
}
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Returns true if an array literal contains an object literal with `id: <id>`.
|
|
114
|
+
*/
|
|
115
|
+
function hasElementWithId(array, id) {
|
|
116
|
+
for (const el of array.getElements()) {
|
|
117
|
+
if (!ts_morph_1.Node.isObjectLiteralExpression(el))
|
|
118
|
+
continue;
|
|
119
|
+
const idProp = el.getProperty('id');
|
|
120
|
+
if (!idProp || !ts_morph_1.Node.isPropertyAssignment(idProp))
|
|
121
|
+
continue;
|
|
122
|
+
const idInit = idProp.getInitializer();
|
|
123
|
+
if (idInit &&
|
|
124
|
+
ts_morph_1.Node.isStringLiteral(idInit) &&
|
|
125
|
+
idInit.getLiteralValue() === id) {
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
// ─── defineConfig helpers ─────────────────────────────────────────────────────
|
|
132
|
+
/**
|
|
133
|
+
* Ensures the top-level `flags` array in a birth `defineConfig` contains the
|
|
134
|
+
* `pending-first-certificate-issuance` flag definition.
|
|
135
|
+
*/
|
|
136
|
+
function ensureTopLevelFlagDefinition(configArg) {
|
|
137
|
+
const flagsProp = configArg.getProperty(FLAGS_PROPERTY_NAME);
|
|
138
|
+
if (flagsProp && ts_morph_1.Node.isPropertyAssignment(flagsProp)) {
|
|
139
|
+
const flagsInit = flagsProp.getInitializer();
|
|
140
|
+
if (flagsInit && ts_morph_1.Node.isArrayLiteralExpression(flagsInit)) {
|
|
141
|
+
if (hasElementWithId(flagsInit, FLAG_ID))
|
|
142
|
+
return false;
|
|
143
|
+
flagsInit.addElement(FLAG_DEFINITION_INITIALIZER);
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
// No `flags` property at all — create it
|
|
149
|
+
configArg.addPropertyAssignment({
|
|
150
|
+
name: FLAGS_PROPERTY_NAME,
|
|
151
|
+
initializer: `[\n ${FLAG_DEFINITION_INITIALIZER}\n]`
|
|
152
|
+
});
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Ensures an action object's `flags` array contains `{ id: FLAG_ID, operation }`.
|
|
157
|
+
*/
|
|
158
|
+
function ensureActionOperationFlag(action, operation) {
|
|
159
|
+
const flagsProp = action.getProperty(FLAGS_PROPERTY_NAME);
|
|
160
|
+
const entry = `{ id: '${FLAG_ID}', operation: '${operation}' }`;
|
|
161
|
+
if (flagsProp && ts_morph_1.Node.isPropertyAssignment(flagsProp)) {
|
|
162
|
+
const flagsInit = flagsProp.getInitializer();
|
|
163
|
+
if (flagsInit && ts_morph_1.Node.isArrayLiteralExpression(flagsInit)) {
|
|
164
|
+
if (hasElementWithId(flagsInit, FLAG_ID))
|
|
165
|
+
return false;
|
|
166
|
+
flagsInit.addElement(entry);
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
action.addPropertyAssignment({
|
|
172
|
+
name: FLAGS_PROPERTY_NAME,
|
|
173
|
+
initializer: `[${entry}]`
|
|
174
|
+
});
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Processes a birth defineConfig object: ensures top-level flag definition,
|
|
179
|
+
* REGISTER action flags, and PRINT_CERTIFICATE action flags.
|
|
180
|
+
* Returns the number of changes made.
|
|
181
|
+
*/
|
|
182
|
+
function processBirthConfig(configArg, relPath) {
|
|
183
|
+
let changes = 0;
|
|
184
|
+
if (ensureTopLevelFlagDefinition(configArg)) {
|
|
185
|
+
changes++;
|
|
186
|
+
console.log(` [${relPath}] Added '${FLAG_ID}' to top-level flags`);
|
|
187
|
+
}
|
|
188
|
+
const actionsProp = configArg.getProperty(ACTIONS_PROPERTY_NAME);
|
|
189
|
+
if (!actionsProp || !ts_morph_1.Node.isPropertyAssignment(actionsProp))
|
|
190
|
+
return changes;
|
|
191
|
+
const actionsInit = actionsProp.getInitializer();
|
|
192
|
+
if (!actionsInit || !ts_morph_1.Node.isArrayLiteralExpression(actionsInit)) {
|
|
193
|
+
return changes;
|
|
194
|
+
}
|
|
195
|
+
for (const element of actionsInit.getElements()) {
|
|
196
|
+
if (!ts_morph_1.Node.isObjectLiteralExpression(element))
|
|
197
|
+
continue;
|
|
198
|
+
if (isActionOfType(element, REGISTER_TYPE)) {
|
|
199
|
+
if (ensureActionOperationFlag(element, 'add')) {
|
|
200
|
+
changes++;
|
|
201
|
+
console.log(` [${relPath}] Added '${FLAG_ID}' add-flag to REGISTER action`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (isActionOfType(element, PRINT_CERTIFICATE_TYPE)) {
|
|
205
|
+
if (ensureActionOperationFlag(element, 'remove')) {
|
|
206
|
+
changes++;
|
|
207
|
+
console.log(` [${relPath}] Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return changes;
|
|
212
|
+
}
|
|
213
|
+
// ─── defineWorkqueues helpers ─────────────────────────────────────────────────
|
|
214
|
+
/**
|
|
215
|
+
* Returns true if a workqueue config object contains a PRINT_CERTIFICATE action
|
|
216
|
+
* in either the (deprecated) `actions` array or the `action` singular object.
|
|
217
|
+
*/
|
|
218
|
+
function hasPrintCertificateAction(workqueue) {
|
|
219
|
+
// Deprecated `actions` array
|
|
220
|
+
const actionsProp = workqueue.getProperty(ACTIONS_PROPERTY_NAME);
|
|
221
|
+
if (actionsProp && ts_morph_1.Node.isPropertyAssignment(actionsProp)) {
|
|
222
|
+
const actionsInit = actionsProp.getInitializer();
|
|
223
|
+
if (actionsInit && ts_morph_1.Node.isArrayLiteralExpression(actionsInit)) {
|
|
224
|
+
for (const el of actionsInit.getElements()) {
|
|
225
|
+
if (ts_morph_1.Node.isObjectLiteralExpression(el) &&
|
|
226
|
+
isActionOfType(el, PRINT_CERTIFICATE_TYPE)) {
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
// Singular `action` object
|
|
233
|
+
const actionProp = workqueue.getProperty(ACTION_PROPERTY_NAME);
|
|
234
|
+
if (actionProp && ts_morph_1.Node.isPropertyAssignment(actionProp)) {
|
|
235
|
+
const actionInit = actionProp.getInitializer();
|
|
236
|
+
if (actionInit &&
|
|
237
|
+
ts_morph_1.Node.isObjectLiteralExpression(actionInit) &&
|
|
238
|
+
isActionOfType(actionInit, PRINT_CERTIFICATE_TYPE)) {
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Adds `FLAG_ID` to `flags.anyOf` on a leaf query clause,
|
|
246
|
+
* merging with any existing `flags` object.
|
|
247
|
+
*/
|
|
248
|
+
function addFlagToQueryClause(clause) {
|
|
249
|
+
const flagsProp = clause.getProperty(FLAGS_PROPERTY_NAME);
|
|
250
|
+
if (flagsProp && ts_morph_1.Node.isPropertyAssignment(flagsProp)) {
|
|
251
|
+
const flagsInit = flagsProp.getInitializer();
|
|
252
|
+
if (flagsInit && ts_morph_1.Node.isObjectLiteralExpression(flagsInit)) {
|
|
253
|
+
const anyOfProp = flagsInit.getProperty(ANY_OF_PROPERTY_NAME);
|
|
254
|
+
if (anyOfProp && ts_morph_1.Node.isPropertyAssignment(anyOfProp)) {
|
|
255
|
+
const anyOfInit = anyOfProp.getInitializer();
|
|
256
|
+
if (anyOfInit && ts_morph_1.Node.isArrayLiteralExpression(anyOfInit)) {
|
|
257
|
+
const alreadyPresent = anyOfInit
|
|
258
|
+
.getElements()
|
|
259
|
+
.some((el) => ts_morph_1.Node.isStringLiteral(el) && el.getLiteralValue() === FLAG_ID);
|
|
260
|
+
if (alreadyPresent)
|
|
261
|
+
return false;
|
|
262
|
+
anyOfInit.addElement(`'${FLAG_ID}'`);
|
|
263
|
+
return true;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
// flags exists but has no anyOf — add it
|
|
268
|
+
flagsInit.addPropertyAssignment({
|
|
269
|
+
name: ANY_OF_PROPERTY_NAME,
|
|
270
|
+
initializer: `['${FLAG_ID}']`
|
|
271
|
+
});
|
|
272
|
+
return true;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
clause.addPropertyAssignment({
|
|
278
|
+
name: FLAGS_PROPERTY_NAME,
|
|
279
|
+
initializer: `{ ${ANY_OF_PROPERTY_NAME}: ['${FLAG_ID}'] }`
|
|
280
|
+
});
|
|
281
|
+
return true;
|
|
282
|
+
}
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Recursively walks an `or`/`and` query container, calling `addFlagToQueryClause`
|
|
287
|
+
* on every leaf clause. Returns the number of clauses modified.
|
|
288
|
+
*/
|
|
289
|
+
function walkQueryForFlagAddition(queryObj) {
|
|
290
|
+
const typeProp = queryObj.getProperty(TYPE_PROPERTY_NAME);
|
|
291
|
+
if (typeProp && ts_morph_1.Node.isPropertyAssignment(typeProp)) {
|
|
292
|
+
const typeInit = typeProp.getInitializer();
|
|
293
|
+
if (typeInit &&
|
|
294
|
+
ts_morph_1.Node.isStringLiteral(typeInit) &&
|
|
295
|
+
(typeInit.getLiteralValue() === 'or' ||
|
|
296
|
+
typeInit.getLiteralValue() === 'and')) {
|
|
297
|
+
const clausesProp = queryObj.getProperty(CLAUSES_PROPERTY_NAME);
|
|
298
|
+
if (!clausesProp || !ts_morph_1.Node.isPropertyAssignment(clausesProp))
|
|
299
|
+
return 0;
|
|
300
|
+
const clausesInit = clausesProp.getInitializer();
|
|
301
|
+
if (!clausesInit || !ts_morph_1.Node.isArrayLiteralExpression(clausesInit))
|
|
302
|
+
return 0;
|
|
303
|
+
let changed = 0;
|
|
304
|
+
for (const clause of clausesInit.getElements()) {
|
|
305
|
+
if (ts_morph_1.Node.isObjectLiteralExpression(clause)) {
|
|
306
|
+
changed += walkQueryForFlagAddition(clause);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return changed;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
// Leaf clause
|
|
313
|
+
return addFlagToQueryClause(queryObj) ? 1 : 0;
|
|
314
|
+
}
|
|
315
|
+
// ─── File processor ──────────────────────────────────────────────────────────
|
|
316
|
+
function processFile(filePath, project) {
|
|
317
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
318
|
+
if (!sourceFile)
|
|
319
|
+
return 0;
|
|
320
|
+
let totalChanges = 0;
|
|
321
|
+
const relPath = path_1.default.relative((0, _1.getCwd)(), filePath);
|
|
322
|
+
const callExpressions = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
323
|
+
for (const call of callExpressions) {
|
|
324
|
+
const expression = call.getExpression();
|
|
325
|
+
if (!ts_morph_1.Node.isIdentifier(expression))
|
|
326
|
+
continue;
|
|
327
|
+
const calleeName = expression.getText();
|
|
328
|
+
// ── defineConfig ──────────────────────────────────────────────────────────
|
|
329
|
+
if (calleeName === DEFINE_CONFIG_NAME) {
|
|
330
|
+
const args = call.getArguments();
|
|
331
|
+
if (args.length === 0)
|
|
332
|
+
continue;
|
|
333
|
+
const configArg = args[0];
|
|
334
|
+
if (!ts_morph_1.Node.isObjectLiteralExpression(configArg))
|
|
335
|
+
continue;
|
|
336
|
+
if (!isBirthConfig(configArg))
|
|
337
|
+
continue;
|
|
338
|
+
totalChanges += processBirthConfig(configArg, relPath);
|
|
339
|
+
}
|
|
340
|
+
// ── defineWorkqueues ──────────────────────────────────────────────────────
|
|
341
|
+
if (calleeName === DEFINE_WORKQUEUES_NAME) {
|
|
342
|
+
const args = call.getArguments();
|
|
343
|
+
if (args.length === 0)
|
|
344
|
+
continue;
|
|
345
|
+
const workqueuesArg = args[0];
|
|
346
|
+
if (!ts_morph_1.Node.isArrayLiteralExpression(workqueuesArg))
|
|
347
|
+
continue;
|
|
348
|
+
for (const workqueueEl of workqueuesArg.getElements()) {
|
|
349
|
+
if (!ts_morph_1.Node.isObjectLiteralExpression(workqueueEl))
|
|
350
|
+
continue;
|
|
351
|
+
if (!hasPrintCertificateAction(workqueueEl))
|
|
352
|
+
continue;
|
|
353
|
+
const queryProp = workqueueEl.getProperty(QUERY_PROPERTY_NAME);
|
|
354
|
+
if (!queryProp || !ts_morph_1.Node.isPropertyAssignment(queryProp))
|
|
355
|
+
continue;
|
|
356
|
+
const queryInit = queryProp.getInitializer();
|
|
357
|
+
if (!queryInit || !ts_morph_1.Node.isObjectLiteralExpression(queryInit))
|
|
358
|
+
continue;
|
|
359
|
+
const changed = walkQueryForFlagAddition(queryInit);
|
|
360
|
+
if (changed > 0) {
|
|
361
|
+
totalChanges += changed;
|
|
362
|
+
console.log(` [${relPath}] Added '${FLAG_ID}' to flags.anyOf in ${changed} PRINT_CERTIFICATE workqueue clause(s)`);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return totalChanges;
|
|
368
|
+
}
|
|
369
|
+
// ─── Entry point ─────────────────────────────────────────────────────────────
|
|
370
|
+
function main() {
|
|
371
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
372
|
+
const srcDir = path_1.default.join((0, _1.getCwd)(), 'src');
|
|
373
|
+
console.log(`Scanning for birth defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}\n`);
|
|
374
|
+
const project = new ts_morph_1.Project({
|
|
375
|
+
tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
|
|
376
|
+
skipAddingFilesFromTsConfig: false
|
|
377
|
+
});
|
|
378
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
379
|
+
const fp = sf.getFilePath();
|
|
380
|
+
return fp.includes('/src/') && !fp.includes('/node_modules/');
|
|
381
|
+
});
|
|
382
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
|
|
383
|
+
let totalChanges = 0;
|
|
384
|
+
const modifiedFiles = [];
|
|
385
|
+
for (const sourceFile of sourceFiles) {
|
|
386
|
+
const filePath = sourceFile.getFilePath();
|
|
387
|
+
const changes = processFile(filePath, project);
|
|
388
|
+
if (changes > 0) {
|
|
389
|
+
totalChanges += changes;
|
|
390
|
+
modifiedFiles.push(filePath);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
if (modifiedFiles.length === 0) {
|
|
394
|
+
console.log('No birth configs or PRINT_CERTIFICATE workqueues found. Nothing to do.');
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
|
|
398
|
+
for (const filePath of modifiedFiles) {
|
|
399
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
400
|
+
yield sourceFile.save();
|
|
401
|
+
console.log(` Saved: ${path_1.default.relative((0, _1.getCwd)(), filePath)}`);
|
|
402
|
+
}
|
|
403
|
+
console.log(`\nDone. Applied ${totalChanges} change(s) across ${modifiedFiles.length} file(s).`);
|
|
404
|
+
});
|
|
405
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkout-upstream-files.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/checkout-upstream-files.ts"],"names":[],"mappings":"AA0GA,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAuDnC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1,143 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.main = main;
|
|
23
|
+
/**
|
|
24
|
+
* Codemod: Replace selected files with their upstream v2.0 versions from
|
|
25
|
+
* opencrvs/opencrvs-countryconfig.
|
|
26
|
+
*
|
|
27
|
+
* Usage:
|
|
28
|
+
* ts-node -r tsconfig-paths/register src/migrations/v2.0/checkout-upstream-files.ts
|
|
29
|
+
*
|
|
30
|
+
* What it does:
|
|
31
|
+
* 1. Registers a temporary git remote that points at the canonical
|
|
32
|
+
* opencrvs-countryconfig repository.
|
|
33
|
+
* 2. Fetches the chosen upstream branch at --depth=1 to keep it fast.
|
|
34
|
+
* 3. Path-scoped checkouts each listed file from that branch. The upstream
|
|
35
|
+
* version is written to the working tree AND staged in the index, so
|
|
36
|
+
* the dev can review the diff afterwards with:
|
|
37
|
+
* git diff --cached -- <file>
|
|
38
|
+
* 4. Removes the temporary remote in all cases (success, failure, or
|
|
39
|
+
* unexpected error) via a `finally` block.
|
|
40
|
+
*
|
|
41
|
+
* Why a git-based approach (as opposed to a raw HTTPS download):
|
|
42
|
+
* - Git handles text, binary, and line endings correctly.
|
|
43
|
+
* - The checked-out files end up staged, giving an obvious review UX.
|
|
44
|
+
* - `git checkout <ref> -- <paths>` is a blob-level copy, so it works
|
|
45
|
+
* whether or not the target repo shares history with
|
|
46
|
+
* opencrvs-countryconfig (e.g. country implementations started from
|
|
47
|
+
* scratch rather than forked).
|
|
48
|
+
*
|
|
49
|
+
* Caveats:
|
|
50
|
+
* - Overwrites any local modifications to the listed files. Run the
|
|
51
|
+
* upgrade on a clean working tree, or accept that the upstream version
|
|
52
|
+
* replaces yours.
|
|
53
|
+
* - Requires git to be installed and network access to github.com.
|
|
54
|
+
* - Requires the country config working directory to be a git repo.
|
|
55
|
+
*/
|
|
56
|
+
const child_process_1 = require("child_process");
|
|
57
|
+
const _1 = require(".");
|
|
58
|
+
const UPSTREAM_URL = 'https://github.com/opencrvs/opencrvs-countryconfig.git';
|
|
59
|
+
// @TODO: This needs to be changed to 'release-v2.0.0' once the branch is created
|
|
60
|
+
const UPSTREAM_BRANCH = 'develop';
|
|
61
|
+
// Remote name used only for the duration of this codemod. Prefixed to avoid
|
|
62
|
+
// clashing with remotes the user may have (origin, upstream, etc.).
|
|
63
|
+
const TEMP_REMOTE = 'opencrvs-upgrade-v19-v20-codemod';
|
|
64
|
+
const FILES_TO_CHECKOUT = [
|
|
65
|
+
'infrastructure/postgres/setup-analytics.sh',
|
|
66
|
+
'src/analytics/analytics.ts'
|
|
67
|
+
];
|
|
68
|
+
// ─── Git helpers ─────────────────────────────────────────────────────────────
|
|
69
|
+
/**
|
|
70
|
+
* Runs a git command in the country config working directory.
|
|
71
|
+
*
|
|
72
|
+
* By default stderr is inherited so the user sees progress output from
|
|
73
|
+
* long-running commands (e.g. `git fetch`). Pass `silent: true` to suppress
|
|
74
|
+
* both stdout and stderr when you only care about the exit code.
|
|
75
|
+
*/
|
|
76
|
+
function runGit(args, { silent = false } = {}) {
|
|
77
|
+
return (0, child_process_1.execFileSync)('git', args, {
|
|
78
|
+
cwd: (0, _1.getCwd)(),
|
|
79
|
+
encoding: 'utf8',
|
|
80
|
+
stdio: silent ? ['ignore', 'pipe', 'pipe'] : ['ignore', 'pipe', 'inherit']
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Runs a git command and returns true on success, false on failure.
|
|
85
|
+
* Stderr/stdout are suppressed — use only when the exit code is the only
|
|
86
|
+
* signal you care about.
|
|
87
|
+
*/
|
|
88
|
+
function tryGit(args) {
|
|
89
|
+
try {
|
|
90
|
+
runGit(args, { silent: true });
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
catch (_a) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function assertIsGitRepo() {
|
|
98
|
+
if (!tryGit(['rev-parse', '--is-inside-work-tree'])) {
|
|
99
|
+
throw new Error(`checkout-upstream-files: ${(0, _1.getCwd)()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// ─── Entry point ─────────────────────────────────────────────────────────────
|
|
103
|
+
function main() {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
console.log(`Checking out ${FILES_TO_CHECKOUT.length} file(s) from ${UPSTREAM_URL}@${UPSTREAM_BRANCH}...\n`);
|
|
106
|
+
assertIsGitRepo();
|
|
107
|
+
// Best-effort cleanup of a stale temp remote from a previous aborted run.
|
|
108
|
+
tryGit(['remote', 'remove', TEMP_REMOTE]);
|
|
109
|
+
try {
|
|
110
|
+
console.log(` Adding temporary remote '${TEMP_REMOTE}' → ${UPSTREAM_URL}`);
|
|
111
|
+
runGit(['remote', 'add', TEMP_REMOTE, UPSTREAM_URL], { silent: true });
|
|
112
|
+
console.log(` Fetching ${TEMP_REMOTE}/${UPSTREAM_BRANCH} (depth 1)...`);
|
|
113
|
+
runGit(['fetch', '--depth=1', TEMP_REMOTE, UPSTREAM_BRANCH]);
|
|
114
|
+
const ref = `${TEMP_REMOTE}/${UPSTREAM_BRANCH}`;
|
|
115
|
+
const missing = [];
|
|
116
|
+
let checkedOut = 0;
|
|
117
|
+
for (const file of FILES_TO_CHECKOUT) {
|
|
118
|
+
// `--` separates paths from refs and avoids ambiguity when a path
|
|
119
|
+
// happens to match a branch/tag name.
|
|
120
|
+
if (tryGit(['checkout', ref, '--', file])) {
|
|
121
|
+
console.log(` Checked out ${file} from ${ref}`);
|
|
122
|
+
checkedOut++;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
console.warn(` [warn] ${file} not found on ${ref} — skipping. Verify the path exists on that branch.`);
|
|
126
|
+
missing.push(file);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
console.log(`\n Checked out ${checkedOut}/${FILES_TO_CHECKOUT.length} file(s) from ${ref}.`);
|
|
130
|
+
if (missing.length > 0) {
|
|
131
|
+
console.warn(` Missing on upstream branch: ${missing.join(', ')}`);
|
|
132
|
+
}
|
|
133
|
+
if (checkedOut > 0) {
|
|
134
|
+
console.log(` Review the staged changes with: git diff --cached -- ${FILES_TO_CHECKOUT.map((f) => `'${f}'`).join(' ')}\n`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
finally {
|
|
138
|
+
if (tryGit(['remote', 'remove', TEMP_REMOTE])) {
|
|
139
|
+
console.log(` Removed temporary remote '${TEMP_REMOTE}'.`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-config-files-to-ts.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/convert-config-files-to-ts.ts"],"names":[],"mappings":"AAyuBA,wBAAsB,IAAI,kBAyPzB"}
|