@opencrvs/toolkit 1.9.12-rc.ad09474 → 1.9.12-rc.af3c5dc
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 +8 -0
- package/dist/application-config/index.js +2045 -41
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +2422 -0
- package/dist/commons/api/router.d.ts +106 -75
- package/dist/commons/application-config/index.d.ts +13 -16
- package/dist/commons/conditionals/conditionals.d.ts +3 -3
- package/dist/commons/events/ActionDocument.d.ts +198 -198
- package/dist/commons/events/ActionInput.d.ts +113 -113
- package/dist/commons/events/ActionType.d.ts +3 -3
- package/dist/commons/events/AdvancedSearchConfig.d.ts +16 -10
- package/dist/commons/events/CompositeFieldValue.d.ts +4 -4
- package/dist/commons/events/CountryConfigQueryInput.d.ts +443 -172
- package/dist/commons/events/Draft.d.ts +15 -15
- package/dist/commons/events/DynamicFieldValue.d.ts +37 -19
- package/dist/commons/events/EventConfig.d.ts +1 -1
- package/dist/commons/events/EventDocument.d.ts +81 -81
- package/dist/commons/events/EventIndex.d.ts +35 -27
- package/dist/commons/events/EventInput.d.ts +1 -1
- package/dist/commons/events/EventMetadata.d.ts +24 -24
- package/dist/commons/events/FieldConfig.d.ts +155 -44
- package/dist/commons/events/FieldType.d.ts +2 -1
- package/dist/commons/events/FieldTypeMapping.d.ts +98 -72
- package/dist/commons/events/FieldValue.d.ts +54 -26
- package/dist/commons/events/PlainDate.d.ts +1 -1
- package/dist/commons/events/WorkqueueColumnConfig.d.ts +16 -16
- package/dist/commons/events/WorkqueueConfig.d.ts +438 -194
- package/dist/commons/events/defineConfig.d.ts +0 -4
- package/dist/commons/events/locations.d.ts +4 -4
- package/dist/commons/events/state/index.d.ts +2 -2
- package/dist/commons/events/state/utils.d.ts +3 -3
- package/dist/commons/events/utils.d.ts +5 -177
- package/dist/conditionals/index.js +13 -5
- package/dist/events/index.js +142 -33
- 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/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 +753 -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/index.d.ts +7 -0
- package/dist/migrations/v2.0/index.d.ts.map +1 -0
- package/dist/migrations/v2.0/index.js +2361 -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 +281 -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/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-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-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/notification/index.js +73 -23
- package/dist/scopes/index.d.ts +31 -10
- package/dist/scopes/index.js +17 -5
- package/opencrvs-toolkit-1.9.12-rc.af3c5dc.tgz +0 -0
- package/package.json +11 -7
- package/tsconfig.tsbuildinfo +1 -1
- package/opencrvs-toolkit-1.9.12-rc.ad09474.tgz +0 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,2422 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// src/migrations/v2.0/remove-review-from-register-action.ts
|
|
27
|
+
var import_ts_morph = require("ts-morph");
|
|
28
|
+
var import_path = __toESM(require("path"));
|
|
29
|
+
var DEFINE_CONFIG_NAME = "defineConfig";
|
|
30
|
+
var ACTIONS_PROPERTY_NAME = "actions";
|
|
31
|
+
var TYPE_PROPERTY_NAME = "type";
|
|
32
|
+
var REVIEW_PROPERTY_NAME = "review";
|
|
33
|
+
var REGISTER_ENUM_NAME = "ActionType";
|
|
34
|
+
var REGISTER_MEMBER_NAME = "REGISTER";
|
|
35
|
+
var REGISTER_STRING_LITERAL = "REGISTER";
|
|
36
|
+
function isRegisterType(typeInitializer) {
|
|
37
|
+
if (typeInitializer.getKind() === import_ts_morph.SyntaxKind.PropertyAccessExpression) {
|
|
38
|
+
const propAccess = typeInitializer.asKindOrThrow(
|
|
39
|
+
import_ts_morph.SyntaxKind.PropertyAccessExpression
|
|
40
|
+
);
|
|
41
|
+
const obj = propAccess.getExpression();
|
|
42
|
+
const member = propAccess.getName();
|
|
43
|
+
return import_ts_morph.Node.isIdentifier(obj) && obj.getText() === REGISTER_ENUM_NAME && member === REGISTER_MEMBER_NAME;
|
|
44
|
+
}
|
|
45
|
+
if (typeInitializer.getKind() === import_ts_morph.SyntaxKind.StringLiteral) {
|
|
46
|
+
return typeInitializer.asKindOrThrow(import_ts_morph.SyntaxKind.StringLiteral).getLiteralValue() === REGISTER_STRING_LITERAL;
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
function removeReviewFromRegisterActions(obj) {
|
|
51
|
+
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME);
|
|
52
|
+
if (!typeProperty || !import_ts_morph.Node.isPropertyAssignment(typeProperty)) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
const typeInitializer = typeProperty.getInitializer();
|
|
56
|
+
if (!typeInitializer || !isRegisterType(typeInitializer)) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
const reviewProperty = obj.getProperty(REVIEW_PROPERTY_NAME);
|
|
60
|
+
if (!reviewProperty) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
reviewProperty.remove();
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
function processFile(filePath, project) {
|
|
67
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
68
|
+
if (!sourceFile) return 0;
|
|
69
|
+
let removedCount = 0;
|
|
70
|
+
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
71
|
+
import_ts_morph.SyntaxKind.CallExpression
|
|
72
|
+
);
|
|
73
|
+
for (const call of callExpressions) {
|
|
74
|
+
const expression = call.getExpression();
|
|
75
|
+
if (!import_ts_morph.Node.isIdentifier(expression) || expression.getText() !== DEFINE_CONFIG_NAME) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const args2 = call.getArguments();
|
|
79
|
+
if (args2.length === 0) continue;
|
|
80
|
+
const configArg = args2[0];
|
|
81
|
+
if (!import_ts_morph.Node.isObjectLiteralExpression(configArg)) continue;
|
|
82
|
+
const actionsProperty = configArg.getProperty(ACTIONS_PROPERTY_NAME);
|
|
83
|
+
if (!actionsProperty || !import_ts_morph.Node.isPropertyAssignment(actionsProperty))
|
|
84
|
+
continue;
|
|
85
|
+
const actionsInitializer = actionsProperty.getInitializer();
|
|
86
|
+
if (!actionsInitializer || !import_ts_morph.Node.isArrayLiteralExpression(actionsInitializer))
|
|
87
|
+
continue;
|
|
88
|
+
for (const element of actionsInitializer.getElements()) {
|
|
89
|
+
if (!import_ts_morph.Node.isObjectLiteralExpression(element)) continue;
|
|
90
|
+
const wasRemoved = removeReviewFromRegisterActions(element);
|
|
91
|
+
if (wasRemoved) {
|
|
92
|
+
removedCount++;
|
|
93
|
+
console.log(
|
|
94
|
+
` [${import_path.default.relative(getCwd(), filePath)}] Removed 'review' from REGISTER action`
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return removedCount;
|
|
100
|
+
}
|
|
101
|
+
async function main() {
|
|
102
|
+
const srcDir = import_path.default.join(getCwd(), "src");
|
|
103
|
+
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
104
|
+
`);
|
|
105
|
+
const project = new import_ts_morph.Project({
|
|
106
|
+
tsConfigFilePath: import_path.default.resolve(srcDir, "../tsconfig.json"),
|
|
107
|
+
// Do not emit — we only manipulate source files
|
|
108
|
+
skipAddingFilesFromTsConfig: false
|
|
109
|
+
// addFilesFromTsConfig: true
|
|
110
|
+
});
|
|
111
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
112
|
+
const fp = sf.getFilePath();
|
|
113
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
114
|
+
});
|
|
115
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
116
|
+
`);
|
|
117
|
+
let totalRemoved = 0;
|
|
118
|
+
const modifiedFiles = [];
|
|
119
|
+
for (const sourceFile of sourceFiles) {
|
|
120
|
+
const filePath = sourceFile.getFilePath();
|
|
121
|
+
const removed = processFile(filePath, project);
|
|
122
|
+
if (removed > 0) {
|
|
123
|
+
totalRemoved += removed;
|
|
124
|
+
modifiedFiles.push(filePath);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (modifiedFiles.length === 0) {
|
|
128
|
+
console.log(
|
|
129
|
+
"No 'review' properties found on REGISTER actions. Nothing to do."
|
|
130
|
+
);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
console.log(`
|
|
134
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
135
|
+
for (const filePath of modifiedFiles) {
|
|
136
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
137
|
+
await sourceFile.save();
|
|
138
|
+
console.log(` Saved: ${import_path.default.relative(getCwd(), filePath)}`);
|
|
139
|
+
}
|
|
140
|
+
console.log(
|
|
141
|
+
`
|
|
142
|
+
Done. Removed ${totalRemoved} 'review' property assignment(s) from REGISTER action(s).`
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// src/migrations/v2.0/make-built-in-validate-actions-custom.ts
|
|
147
|
+
var import_ts_morph2 = require("ts-morph");
|
|
148
|
+
var import_path2 = __toESM(require("path"));
|
|
149
|
+
var TOOLKIT_EVENTS_MODULE = "@opencrvs/toolkit/events";
|
|
150
|
+
var REQUIRED_SYMBOLS = [
|
|
151
|
+
"ConditionalType",
|
|
152
|
+
"and",
|
|
153
|
+
"status",
|
|
154
|
+
"not",
|
|
155
|
+
"flag",
|
|
156
|
+
"InherentFlags"
|
|
157
|
+
];
|
|
158
|
+
function ensureImports(sourceFile) {
|
|
159
|
+
const existingImport = sourceFile.getImportDeclaration(
|
|
160
|
+
(decl) => decl.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE
|
|
161
|
+
);
|
|
162
|
+
if (existingImport) {
|
|
163
|
+
const existingNames = new Set(
|
|
164
|
+
existingImport.getNamedImports().map((ni) => ni.getName())
|
|
165
|
+
);
|
|
166
|
+
for (const name of REQUIRED_SYMBOLS) {
|
|
167
|
+
if (!existingNames.has(name)) {
|
|
168
|
+
existingImport.addNamedImport(name);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
} else {
|
|
172
|
+
sourceFile.addImportDeclaration({
|
|
173
|
+
moduleSpecifier: TOOLKIT_EVENTS_MODULE,
|
|
174
|
+
namedImports: REQUIRED_SYMBOLS
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
var DEFINE_CONFIG_NAME2 = "defineConfig";
|
|
179
|
+
var ACTIONS_PROPERTY_NAME2 = "actions";
|
|
180
|
+
var TYPE_PROPERTY_NAME2 = "type";
|
|
181
|
+
var CUSTOM_ACTION_TYPE_PROPERTY_NAME = "customActionType";
|
|
182
|
+
var AUDIT_HISTORY_LABEL_PROPERTY_NAME = "auditHistoryLabel";
|
|
183
|
+
var DEDUPLICATION_PROPERTY_NAME = "deduplication";
|
|
184
|
+
var REVIEW_PROPERTY_NAME2 = "review";
|
|
185
|
+
var FIELDS_PROPERTY_NAME = "fields";
|
|
186
|
+
var FORM_PROPERTY_NAME = "form";
|
|
187
|
+
var ACTION_TYPE_ENUM_NAME = "ActionType";
|
|
188
|
+
var VALIDATE_MEMBER_NAME = "VALIDATE";
|
|
189
|
+
var CUSTOM_MEMBER_NAME = "CUSTOM";
|
|
190
|
+
var VALIDATE_STRING_LITERAL = "VALIDATE";
|
|
191
|
+
var CUSTOM_STRING_LITERAL = "CUSTOM";
|
|
192
|
+
var VALIDATE_DECLARATION_VALUE = "VALIDATE_DECLARATION";
|
|
193
|
+
function isValidateType(typeInitializer) {
|
|
194
|
+
if (typeInitializer.getKind() === import_ts_morph2.SyntaxKind.PropertyAccessExpression) {
|
|
195
|
+
const propAccess = typeInitializer.asKindOrThrow(
|
|
196
|
+
import_ts_morph2.SyntaxKind.PropertyAccessExpression
|
|
197
|
+
);
|
|
198
|
+
const obj = propAccess.getExpression();
|
|
199
|
+
const member = propAccess.getName();
|
|
200
|
+
return import_ts_morph2.Node.isIdentifier(obj) && obj.getText() === ACTION_TYPE_ENUM_NAME && member === VALIDATE_MEMBER_NAME;
|
|
201
|
+
}
|
|
202
|
+
if (typeInitializer.getKind() === import_ts_morph2.SyntaxKind.StringLiteral) {
|
|
203
|
+
return typeInitializer.asKindOrThrow(import_ts_morph2.SyntaxKind.StringLiteral).getLiteralValue() === VALIDATE_STRING_LITERAL;
|
|
204
|
+
}
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
function resolveEventType(configArg) {
|
|
208
|
+
const typeProperty = configArg.getProperty(TYPE_PROPERTY_NAME2);
|
|
209
|
+
if (!typeProperty || !import_ts_morph2.Node.isPropertyAssignment(typeProperty)) return null;
|
|
210
|
+
const initializer = typeProperty.getInitializer();
|
|
211
|
+
if (!initializer) return null;
|
|
212
|
+
if (import_ts_morph2.Node.isStringLiteral(initializer)) {
|
|
213
|
+
return initializer.getLiteralValue().toLowerCase();
|
|
214
|
+
}
|
|
215
|
+
if (initializer.getKind() === import_ts_morph2.SyntaxKind.PropertyAccessExpression && import_ts_morph2.Node.isPropertyAccessExpression(initializer)) {
|
|
216
|
+
return initializer.getName().toLowerCase();
|
|
217
|
+
}
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
function transformValidateActionToCustom(obj, eventType) {
|
|
221
|
+
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME2);
|
|
222
|
+
if (!typeProperty || !import_ts_morph2.Node.isPropertyAssignment(typeProperty)) {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
const typeInitializer = typeProperty.getInitializer();
|
|
226
|
+
if (!typeInitializer || !isValidateType(typeInitializer)) {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
if (typeInitializer.getKind() === import_ts_morph2.SyntaxKind.PropertyAccessExpression) {
|
|
230
|
+
typeInitializer.replaceWithText(
|
|
231
|
+
`${ACTION_TYPE_ENUM_NAME}.${CUSTOM_MEMBER_NAME}`
|
|
232
|
+
);
|
|
233
|
+
} else {
|
|
234
|
+
typeInitializer.replaceWithText(`'${CUSTOM_STRING_LITERAL}'`);
|
|
235
|
+
}
|
|
236
|
+
if (!obj.getProperty(CUSTOM_ACTION_TYPE_PROPERTY_NAME)) {
|
|
237
|
+
obj.addPropertyAssignment({
|
|
238
|
+
name: CUSTOM_ACTION_TYPE_PROPERTY_NAME,
|
|
239
|
+
initializer: `'${VALIDATE_DECLARATION_VALUE}'`
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
if (!obj.getProperty(AUDIT_HISTORY_LABEL_PROPERTY_NAME)) {
|
|
243
|
+
const messageId = `event.${eventType}.custom.action.validate-declaration.audit-history-label`;
|
|
244
|
+
obj.addPropertyAssignment({
|
|
245
|
+
name: AUDIT_HISTORY_LABEL_PROPERTY_NAME,
|
|
246
|
+
initializer: `{
|
|
247
|
+
defaultMessage: 'Validated',
|
|
248
|
+
description: 'The label to show in audit history for the validate action',
|
|
249
|
+
id: '${messageId}'
|
|
250
|
+
}`
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
if (!obj.getProperty("supportingCopy")) {
|
|
254
|
+
const supportingCopyId = `event.${eventType}.custom.action.validate-declaration.supportingCopy`;
|
|
255
|
+
obj.addPropertyAssignment({
|
|
256
|
+
name: "supportingCopy",
|
|
257
|
+
initializer: `{
|
|
258
|
+
defaultMessage:
|
|
259
|
+
'Approving this declaration confirms it as legally accepted and eligible for registration.',
|
|
260
|
+
description:
|
|
261
|
+
'This is the supporting copy for the Validate declaration -action',
|
|
262
|
+
id: '${supportingCopyId}'
|
|
263
|
+
}`
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
if (!obj.getProperty("conditionals")) {
|
|
267
|
+
obj.addPropertyAssignment({
|
|
268
|
+
name: "conditionals",
|
|
269
|
+
initializer: `[
|
|
270
|
+
{
|
|
271
|
+
type: ConditionalType.SHOW,
|
|
272
|
+
conditional: and(status('DECLARED'), not(flag('validated')))
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
type: ConditionalType.ENABLE,
|
|
276
|
+
conditional: not(flag(InherentFlags.POTENTIAL_DUPLICATE))
|
|
277
|
+
}
|
|
278
|
+
]`
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
if (!obj.getProperty("flags")) {
|
|
282
|
+
obj.addPropertyAssignment({
|
|
283
|
+
name: "flags",
|
|
284
|
+
initializer: `[{ id: 'validated', operation: 'add' }]`
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
const deduplicationProperty = obj.getProperty(DEDUPLICATION_PROPERTY_NAME);
|
|
288
|
+
if (deduplicationProperty) {
|
|
289
|
+
deduplicationProperty.remove();
|
|
290
|
+
}
|
|
291
|
+
const reviewProperty = obj.getProperty(REVIEW_PROPERTY_NAME2);
|
|
292
|
+
if (reviewProperty && import_ts_morph2.Node.isPropertyAssignment(reviewProperty)) {
|
|
293
|
+
const reviewInitializer = reviewProperty.getInitializer();
|
|
294
|
+
if (reviewInitializer) {
|
|
295
|
+
if (import_ts_morph2.Node.isObjectLiteralExpression(reviewInitializer)) {
|
|
296
|
+
const fieldsProperty = reviewInitializer.getProperty(FIELDS_PROPERTY_NAME);
|
|
297
|
+
if (fieldsProperty && import_ts_morph2.Node.isPropertyAssignment(fieldsProperty)) {
|
|
298
|
+
const fieldsInitializer = fieldsProperty.getInitializer();
|
|
299
|
+
if (fieldsInitializer) {
|
|
300
|
+
reviewProperty.set({
|
|
301
|
+
name: FORM_PROPERTY_NAME,
|
|
302
|
+
initializer: fieldsInitializer.getText()
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
} else {
|
|
307
|
+
reviewProperty.set({
|
|
308
|
+
name: FORM_PROPERTY_NAME,
|
|
309
|
+
initializer: `${reviewInitializer.getText()}.fields`
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return true;
|
|
315
|
+
}
|
|
316
|
+
function processFile2(filePath, project) {
|
|
317
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
318
|
+
if (!sourceFile) return 0;
|
|
319
|
+
let transformedCount = 0;
|
|
320
|
+
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
321
|
+
import_ts_morph2.SyntaxKind.CallExpression
|
|
322
|
+
);
|
|
323
|
+
for (const call of callExpressions) {
|
|
324
|
+
const expression = call.getExpression();
|
|
325
|
+
if (!import_ts_morph2.Node.isIdentifier(expression) || expression.getText() !== DEFINE_CONFIG_NAME2) {
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
const args2 = call.getArguments();
|
|
329
|
+
if (args2.length === 0) continue;
|
|
330
|
+
const configArg = args2[0];
|
|
331
|
+
if (!import_ts_morph2.Node.isObjectLiteralExpression(configArg)) continue;
|
|
332
|
+
const actionsProperty = configArg.getProperty(ACTIONS_PROPERTY_NAME2);
|
|
333
|
+
if (!actionsProperty || !import_ts_morph2.Node.isPropertyAssignment(actionsProperty))
|
|
334
|
+
continue;
|
|
335
|
+
const actionsInitializer = actionsProperty.getInitializer();
|
|
336
|
+
if (!actionsInitializer || !import_ts_morph2.Node.isArrayLiteralExpression(actionsInitializer))
|
|
337
|
+
continue;
|
|
338
|
+
const eventType = resolveEventType(configArg);
|
|
339
|
+
if (!eventType) {
|
|
340
|
+
console.warn(
|
|
341
|
+
` [${import_path2.default.relative(getCwd(), configArg.getSourceFile().getFilePath())}] Could not resolve root 'type' from defineConfig \u2014 skipping auditHistoryLabel id generation`
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
let fileNeedsImports = false;
|
|
345
|
+
let configHadValidateAction = false;
|
|
346
|
+
for (const element of actionsInitializer.getElements()) {
|
|
347
|
+
if (!import_ts_morph2.Node.isObjectLiteralExpression(element)) continue;
|
|
348
|
+
const wasTransformed = transformValidateActionToCustom(
|
|
349
|
+
element,
|
|
350
|
+
eventType ?? "unknown"
|
|
351
|
+
);
|
|
352
|
+
if (wasTransformed) {
|
|
353
|
+
transformedCount++;
|
|
354
|
+
fileNeedsImports = true;
|
|
355
|
+
configHadValidateAction = true;
|
|
356
|
+
console.log(
|
|
357
|
+
` [${import_path2.default.relative(getCwd(), filePath)}] Transformed VALIDATE action to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'`
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
if (configHadValidateAction && !configArg.getProperty("flags")) {
|
|
362
|
+
const resolvedEventType = eventType ?? "unknown";
|
|
363
|
+
configArg.addPropertyAssignment({
|
|
364
|
+
name: "flags",
|
|
365
|
+
initializer: `[
|
|
366
|
+
{
|
|
367
|
+
id: 'validated',
|
|
368
|
+
label: {
|
|
369
|
+
id: 'event.${resolvedEventType}.flag.validated',
|
|
370
|
+
defaultMessage: 'Validated',
|
|
371
|
+
description: 'Flag label for validated'
|
|
372
|
+
},
|
|
373
|
+
requiresAction: true
|
|
374
|
+
}
|
|
375
|
+
]`
|
|
376
|
+
});
|
|
377
|
+
console.log(
|
|
378
|
+
` [${import_path2.default.relative(getCwd(), filePath)}] Added top-level 'flags' array to defineConfig`
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
if (fileNeedsImports) {
|
|
382
|
+
ensureImports(sourceFile);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
return transformedCount;
|
|
386
|
+
}
|
|
387
|
+
async function main2() {
|
|
388
|
+
const srcDir = import_path2.default.join(getCwd(), "src");
|
|
389
|
+
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
390
|
+
`);
|
|
391
|
+
const project = new import_ts_morph2.Project({
|
|
392
|
+
tsConfigFilePath: import_path2.default.resolve(srcDir, "../tsconfig.json"),
|
|
393
|
+
// Do not emit — we only manipulate source files
|
|
394
|
+
skipAddingFilesFromTsConfig: false
|
|
395
|
+
});
|
|
396
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
397
|
+
const fp = sf.getFilePath();
|
|
398
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
399
|
+
});
|
|
400
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
401
|
+
`);
|
|
402
|
+
let totalTransformed = 0;
|
|
403
|
+
const modifiedFiles = [];
|
|
404
|
+
for (const sourceFile of sourceFiles) {
|
|
405
|
+
const filePath = sourceFile.getFilePath();
|
|
406
|
+
const transformed = processFile2(filePath, project);
|
|
407
|
+
if (transformed > 0) {
|
|
408
|
+
totalTransformed += transformed;
|
|
409
|
+
modifiedFiles.push(filePath);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
if (modifiedFiles.length === 0) {
|
|
413
|
+
console.log(
|
|
414
|
+
"No VALIDATE actions found inside defineConfig calls. Nothing to do."
|
|
415
|
+
);
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
console.log(`
|
|
419
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
420
|
+
for (const filePath of modifiedFiles) {
|
|
421
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
422
|
+
await sourceFile.save();
|
|
423
|
+
console.log(` Saved: ${import_path2.default.relative(getCwd(), filePath)}`);
|
|
424
|
+
}
|
|
425
|
+
console.log(
|
|
426
|
+
`
|
|
427
|
+
Done. Transformed ${totalTransformed} VALIDATE action(s) to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'.`
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// src/migrations/v2.0/remove-delete-actions.ts
|
|
432
|
+
var import_ts_morph3 = require("ts-morph");
|
|
433
|
+
var import_path3 = __toESM(require("path"));
|
|
434
|
+
var DEFINE_CONFIG_NAME3 = "defineConfig";
|
|
435
|
+
var ACTIONS_PROPERTY_NAME3 = "actions";
|
|
436
|
+
var TYPE_PROPERTY_NAME3 = "type";
|
|
437
|
+
var ACTION_TYPE_ENUM_NAME2 = "ActionType";
|
|
438
|
+
var DELETE_MEMBER_NAME = "DELETE";
|
|
439
|
+
var DELETE_STRING_LITERAL = "DELETE";
|
|
440
|
+
function isDeleteType(typeInitializer) {
|
|
441
|
+
if (typeInitializer.getKind() === import_ts_morph3.SyntaxKind.PropertyAccessExpression) {
|
|
442
|
+
const propAccess = typeInitializer.asKindOrThrow(
|
|
443
|
+
import_ts_morph3.SyntaxKind.PropertyAccessExpression
|
|
444
|
+
);
|
|
445
|
+
const obj = propAccess.getExpression();
|
|
446
|
+
const member = propAccess.getName();
|
|
447
|
+
return import_ts_morph3.Node.isIdentifier(obj) && obj.getText() === ACTION_TYPE_ENUM_NAME2 && member === DELETE_MEMBER_NAME;
|
|
448
|
+
}
|
|
449
|
+
if (typeInitializer.getKind() === import_ts_morph3.SyntaxKind.StringLiteral) {
|
|
450
|
+
return typeInitializer.asKindOrThrow(import_ts_morph3.SyntaxKind.StringLiteral).getLiteralValue() === DELETE_STRING_LITERAL;
|
|
451
|
+
}
|
|
452
|
+
return false;
|
|
453
|
+
}
|
|
454
|
+
function isDeleteAction(obj) {
|
|
455
|
+
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME3);
|
|
456
|
+
if (!typeProperty || !import_ts_morph3.Node.isPropertyAssignment(typeProperty)) {
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
const typeInitializer = typeProperty.getInitializer();
|
|
460
|
+
return !!typeInitializer && isDeleteType(typeInitializer);
|
|
461
|
+
}
|
|
462
|
+
function processFile3(filePath, project) {
|
|
463
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
464
|
+
if (!sourceFile) return 0;
|
|
465
|
+
let removedCount = 0;
|
|
466
|
+
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
467
|
+
import_ts_morph3.SyntaxKind.CallExpression
|
|
468
|
+
);
|
|
469
|
+
for (const call of callExpressions) {
|
|
470
|
+
const expression = call.getExpression();
|
|
471
|
+
if (!import_ts_morph3.Node.isIdentifier(expression) || expression.getText() !== DEFINE_CONFIG_NAME3) {
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
474
|
+
const args2 = call.getArguments();
|
|
475
|
+
if (args2.length === 0) continue;
|
|
476
|
+
const configArg = args2[0];
|
|
477
|
+
if (!import_ts_morph3.Node.isObjectLiteralExpression(configArg)) continue;
|
|
478
|
+
const actionsProperty = configArg.getProperty(ACTIONS_PROPERTY_NAME3);
|
|
479
|
+
if (!actionsProperty || !import_ts_morph3.Node.isPropertyAssignment(actionsProperty))
|
|
480
|
+
continue;
|
|
481
|
+
const actionsInitializer = actionsProperty.getInitializer();
|
|
482
|
+
if (!actionsInitializer || !import_ts_morph3.Node.isArrayLiteralExpression(actionsInitializer))
|
|
483
|
+
continue;
|
|
484
|
+
const indicesToRemove = [];
|
|
485
|
+
actionsInitializer.getElements().forEach((element, index) => {
|
|
486
|
+
if (import_ts_morph3.Node.isObjectLiteralExpression(element) && isDeleteAction(element)) {
|
|
487
|
+
indicesToRemove.push(index);
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
for (const index of indicesToRemove.reverse()) {
|
|
491
|
+
actionsInitializer.removeElement(index);
|
|
492
|
+
removedCount++;
|
|
493
|
+
console.log(
|
|
494
|
+
` [${import_path3.default.relative(getCwd(), filePath)}] Removed DELETE action at index ${index}`
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
return removedCount;
|
|
499
|
+
}
|
|
500
|
+
async function main3() {
|
|
501
|
+
const srcDir = import_path3.default.join(getCwd(), "src");
|
|
502
|
+
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
503
|
+
`);
|
|
504
|
+
const project = new import_ts_morph3.Project({
|
|
505
|
+
tsConfigFilePath: import_path3.default.resolve(srcDir, "../tsconfig.json"),
|
|
506
|
+
// Do not emit — we only manipulate source files
|
|
507
|
+
skipAddingFilesFromTsConfig: false
|
|
508
|
+
});
|
|
509
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
510
|
+
const fp = sf.getFilePath();
|
|
511
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
512
|
+
});
|
|
513
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
514
|
+
`);
|
|
515
|
+
let totalRemoved = 0;
|
|
516
|
+
const modifiedFiles = [];
|
|
517
|
+
for (const sourceFile of sourceFiles) {
|
|
518
|
+
const filePath = sourceFile.getFilePath();
|
|
519
|
+
const removed = processFile3(filePath, project);
|
|
520
|
+
if (removed > 0) {
|
|
521
|
+
totalRemoved += removed;
|
|
522
|
+
modifiedFiles.push(filePath);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
if (modifiedFiles.length === 0) {
|
|
526
|
+
console.log(
|
|
527
|
+
"No DELETE actions found inside defineConfig calls. Nothing to do."
|
|
528
|
+
);
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
console.log(`
|
|
532
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
533
|
+
for (const filePath of modifiedFiles) {
|
|
534
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
535
|
+
await sourceFile.save();
|
|
536
|
+
console.log(` Saved: ${import_path3.default.relative(getCwd(), filePath)}`);
|
|
537
|
+
}
|
|
538
|
+
console.log(
|
|
539
|
+
`
|
|
540
|
+
Done. Removed ${totalRemoved} DELETE action(s) from defineConfig call(s).`
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
// src/migrations/v2.0/convert-paragraph-to-heading.ts
|
|
545
|
+
var import_ts_morph4 = require("ts-morph");
|
|
546
|
+
var import_path4 = __toESM(require("path"));
|
|
547
|
+
var FIELD_TYPE_ENUM_NAME = "FieldType";
|
|
548
|
+
var PARAGRAPH_MEMBER_NAME = "PARAGRAPH";
|
|
549
|
+
var HEADING_MEMBER_NAME = "HEADING";
|
|
550
|
+
var TYPE_PROPERTY_NAME4 = "type";
|
|
551
|
+
var CONFIGURATION_PROPERTY_NAME = "configuration";
|
|
552
|
+
var STYLES_PROPERTY_NAME = "styles";
|
|
553
|
+
var FONT_VARIANT_PROPERTY_NAME = "fontVariant";
|
|
554
|
+
var HEADING_FONT_VARIANTS = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4"]);
|
|
555
|
+
function isParagraphType(typeInitializer) {
|
|
556
|
+
if (!import_ts_morph4.Node.isPropertyAccessExpression(typeInitializer)) return false;
|
|
557
|
+
const obj = typeInitializer.getExpression();
|
|
558
|
+
const member = typeInitializer.getName();
|
|
559
|
+
return import_ts_morph4.Node.isIdentifier(obj) && obj.getText() === FIELD_TYPE_ENUM_NAME && member === PARAGRAPH_MEMBER_NAME;
|
|
560
|
+
}
|
|
561
|
+
function getFontVariantProperty(obj) {
|
|
562
|
+
const configProperty = obj.getProperty(CONFIGURATION_PROPERTY_NAME);
|
|
563
|
+
if (!configProperty || !import_ts_morph4.Node.isPropertyAssignment(configProperty)) return null;
|
|
564
|
+
const configInitializer = configProperty.getInitializer();
|
|
565
|
+
if (!configInitializer || !import_ts_morph4.Node.isObjectLiteralExpression(configInitializer))
|
|
566
|
+
return null;
|
|
567
|
+
const stylesProperty = configInitializer.getProperty(STYLES_PROPERTY_NAME);
|
|
568
|
+
if (!stylesProperty || !import_ts_morph4.Node.isPropertyAssignment(stylesProperty)) return null;
|
|
569
|
+
const stylesInitializer = stylesProperty.getInitializer();
|
|
570
|
+
if (!stylesInitializer || !import_ts_morph4.Node.isObjectLiteralExpression(stylesInitializer))
|
|
571
|
+
return null;
|
|
572
|
+
const fontVariantProperty = stylesInitializer.getProperty(
|
|
573
|
+
FONT_VARIANT_PROPERTY_NAME
|
|
574
|
+
);
|
|
575
|
+
if (!fontVariantProperty || !import_ts_morph4.Node.isPropertyAssignment(fontVariantProperty))
|
|
576
|
+
return null;
|
|
577
|
+
return fontVariantProperty;
|
|
578
|
+
}
|
|
579
|
+
function transformParagraphField(obj) {
|
|
580
|
+
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME4);
|
|
581
|
+
if (!typeProperty || !import_ts_morph4.Node.isPropertyAssignment(typeProperty)) return null;
|
|
582
|
+
const typeInitializer = typeProperty.getInitializer();
|
|
583
|
+
if (!typeInitializer || !isParagraphType(typeInitializer)) return null;
|
|
584
|
+
const fontVariantProperty = getFontVariantProperty(obj);
|
|
585
|
+
if (fontVariantProperty) {
|
|
586
|
+
const fontVariantInitializer = fontVariantProperty.getInitializer();
|
|
587
|
+
if (fontVariantInitializer && import_ts_morph4.Node.isStringLiteral(fontVariantInitializer) && HEADING_FONT_VARIANTS.has(fontVariantInitializer.getLiteralValue())) {
|
|
588
|
+
typeInitializer.replaceWithText(
|
|
589
|
+
`${FIELD_TYPE_ENUM_NAME}.${HEADING_MEMBER_NAME}`
|
|
590
|
+
);
|
|
591
|
+
return "converted-to-heading";
|
|
592
|
+
}
|
|
593
|
+
fontVariantProperty.remove();
|
|
594
|
+
return "removed-font-variant";
|
|
595
|
+
}
|
|
596
|
+
return null;
|
|
597
|
+
}
|
|
598
|
+
function processFile4(filePath, project) {
|
|
599
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
600
|
+
if (!sourceFile) return 0;
|
|
601
|
+
let changedCount = 0;
|
|
602
|
+
const objectLiterals = sourceFile.getDescendantsOfKind(
|
|
603
|
+
import_ts_morph4.SyntaxKind.ObjectLiteralExpression
|
|
604
|
+
);
|
|
605
|
+
for (const obj of objectLiterals) {
|
|
606
|
+
const result = transformParagraphField(obj);
|
|
607
|
+
if (result === "converted-to-heading") {
|
|
608
|
+
changedCount++;
|
|
609
|
+
console.log(
|
|
610
|
+
` [${import_path4.default.relative(getCwd(), filePath)}] Converted PARAGRAPH with heading fontVariant to HEADING`
|
|
611
|
+
);
|
|
612
|
+
} else if (result === "removed-font-variant") {
|
|
613
|
+
changedCount++;
|
|
614
|
+
console.log(
|
|
615
|
+
` [${import_path4.default.relative(getCwd(), filePath)}] Removed non-heading fontVariant from PARAGRAPH`
|
|
616
|
+
);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
return changedCount;
|
|
620
|
+
}
|
|
621
|
+
async function main4() {
|
|
622
|
+
const srcDir = import_path4.default.join(getCwd(), "src");
|
|
623
|
+
console.log(`Scanning for FieldType.PARAGRAPH fields in: ${srcDir}
|
|
624
|
+
`);
|
|
625
|
+
const project = new import_ts_morph4.Project({
|
|
626
|
+
tsConfigFilePath: import_path4.default.resolve(srcDir, "../tsconfig.json"),
|
|
627
|
+
skipAddingFilesFromTsConfig: false
|
|
628
|
+
});
|
|
629
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
630
|
+
const fp = sf.getFilePath();
|
|
631
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
632
|
+
});
|
|
633
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
634
|
+
`);
|
|
635
|
+
let totalChanged = 0;
|
|
636
|
+
const modifiedFiles = [];
|
|
637
|
+
for (const sourceFile of sourceFiles) {
|
|
638
|
+
const filePath = sourceFile.getFilePath();
|
|
639
|
+
const changed = processFile4(filePath, project);
|
|
640
|
+
if (changed > 0) {
|
|
641
|
+
totalChanged += changed;
|
|
642
|
+
modifiedFiles.push(filePath);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
if (modifiedFiles.length === 0) {
|
|
646
|
+
console.log(
|
|
647
|
+
"No FieldType.PARAGRAPH fields with fontVariant found. Nothing to do."
|
|
648
|
+
);
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
console.log(`
|
|
652
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
653
|
+
for (const filePath of modifiedFiles) {
|
|
654
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
655
|
+
await sourceFile.save();
|
|
656
|
+
console.log(` Saved: ${import_path4.default.relative(getCwd(), filePath)}`);
|
|
657
|
+
}
|
|
658
|
+
console.log(`
|
|
659
|
+
Done. Processed ${totalChanged} FieldType.PARAGRAPH field(s).`);
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
// src/migrations/v2.0/migrate-validated-workqueue-status-to-flag.ts
|
|
663
|
+
var import_ts_morph5 = require("ts-morph");
|
|
664
|
+
var import_path5 = __toESM(require("path"));
|
|
665
|
+
var DEFINE_WORKQUEUES_NAME = "defineWorkqueues";
|
|
666
|
+
var QUERY_PROPERTY_NAME = "query";
|
|
667
|
+
var TYPE_PROPERTY_NAME5 = "type";
|
|
668
|
+
var CLAUSES_PROPERTY_NAME = "clauses";
|
|
669
|
+
var STATUS_PROPERTY_NAME = "status";
|
|
670
|
+
var FLAGS_PROPERTY_NAME = "flags";
|
|
671
|
+
var TERMS_PROPERTY_NAME = "terms";
|
|
672
|
+
var TERM_PROPERTY_NAME = "term";
|
|
673
|
+
var ANY_OF_PROPERTY_NAME = "anyOf";
|
|
674
|
+
var VALIDATED_STATUS_VALUE = "VALIDATED";
|
|
675
|
+
var VALIDATED_FLAG_VALUE = "validated";
|
|
676
|
+
function addValidatedFlag(clause) {
|
|
677
|
+
const flagsProperty = clause.getProperty(FLAGS_PROPERTY_NAME);
|
|
678
|
+
if (flagsProperty && import_ts_morph5.Node.isPropertyAssignment(flagsProperty)) {
|
|
679
|
+
const flagsInit = flagsProperty.getInitializer();
|
|
680
|
+
if (flagsInit && import_ts_morph5.Node.isObjectLiteralExpression(flagsInit)) {
|
|
681
|
+
const anyOfProperty = flagsInit.getProperty(ANY_OF_PROPERTY_NAME);
|
|
682
|
+
if (anyOfProperty && import_ts_morph5.Node.isPropertyAssignment(anyOfProperty)) {
|
|
683
|
+
const anyOfInit = anyOfProperty.getInitializer();
|
|
684
|
+
if (anyOfInit && import_ts_morph5.Node.isArrayLiteralExpression(anyOfInit)) {
|
|
685
|
+
anyOfInit.addElement(`'${VALIDATED_FLAG_VALUE}'`);
|
|
686
|
+
}
|
|
687
|
+
} else {
|
|
688
|
+
flagsInit.addPropertyAssignment({
|
|
689
|
+
name: ANY_OF_PROPERTY_NAME,
|
|
690
|
+
initializer: `['${VALIDATED_FLAG_VALUE}']`
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
} else {
|
|
695
|
+
clause.addPropertyAssignment({
|
|
696
|
+
name: FLAGS_PROPERTY_NAME,
|
|
697
|
+
initializer: `{ ${ANY_OF_PROPERTY_NAME}: ['${VALIDATED_FLAG_VALUE}'] }`
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
function migrateClause(clause) {
|
|
702
|
+
const statusProperty = clause.getProperty(STATUS_PROPERTY_NAME);
|
|
703
|
+
if (!statusProperty || !import_ts_morph5.Node.isPropertyAssignment(statusProperty)) {
|
|
704
|
+
return false;
|
|
705
|
+
}
|
|
706
|
+
const statusInit = statusProperty.getInitializer();
|
|
707
|
+
if (!statusInit || !import_ts_morph5.Node.isObjectLiteralExpression(statusInit)) {
|
|
708
|
+
return false;
|
|
709
|
+
}
|
|
710
|
+
const statusTypeProperty = statusInit.getProperty(TYPE_PROPERTY_NAME5);
|
|
711
|
+
if (!statusTypeProperty || !import_ts_morph5.Node.isPropertyAssignment(statusTypeProperty)) {
|
|
712
|
+
return false;
|
|
713
|
+
}
|
|
714
|
+
const statusTypeInit = statusTypeProperty.getInitializer();
|
|
715
|
+
if (!statusTypeInit || !import_ts_morph5.Node.isStringLiteral(statusTypeInit)) {
|
|
716
|
+
return false;
|
|
717
|
+
}
|
|
718
|
+
const statusType = statusTypeInit.getLiteralValue();
|
|
719
|
+
if (statusType === "anyOf") {
|
|
720
|
+
const termsProperty = statusInit.getProperty(TERMS_PROPERTY_NAME);
|
|
721
|
+
if (!termsProperty || !import_ts_morph5.Node.isPropertyAssignment(termsProperty)) {
|
|
722
|
+
return false;
|
|
723
|
+
}
|
|
724
|
+
const termsInit = termsProperty.getInitializer();
|
|
725
|
+
if (!termsInit || !import_ts_morph5.Node.isArrayLiteralExpression(termsInit)) {
|
|
726
|
+
return false;
|
|
727
|
+
}
|
|
728
|
+
const elements = termsInit.getElements();
|
|
729
|
+
const validatedIndex = elements.findIndex(
|
|
730
|
+
(el) => import_ts_morph5.Node.isStringLiteral(el) && el.getLiteralValue() === VALIDATED_STATUS_VALUE
|
|
731
|
+
);
|
|
732
|
+
if (validatedIndex === -1) return false;
|
|
733
|
+
termsInit.removeElement(validatedIndex);
|
|
734
|
+
if (termsInit.getElements().length === 0) {
|
|
735
|
+
statusProperty.remove();
|
|
736
|
+
}
|
|
737
|
+
addValidatedFlag(clause);
|
|
738
|
+
return true;
|
|
739
|
+
}
|
|
740
|
+
if (statusType === "exact") {
|
|
741
|
+
const termProperty = statusInit.getProperty(TERM_PROPERTY_NAME);
|
|
742
|
+
if (!termProperty || !import_ts_morph5.Node.isPropertyAssignment(termProperty)) {
|
|
743
|
+
return false;
|
|
744
|
+
}
|
|
745
|
+
const termInit = termProperty.getInitializer();
|
|
746
|
+
if (!termInit || !import_ts_morph5.Node.isStringLiteral(termInit)) {
|
|
747
|
+
return false;
|
|
748
|
+
}
|
|
749
|
+
if (termInit.getLiteralValue() !== VALIDATED_STATUS_VALUE) return false;
|
|
750
|
+
statusProperty.remove();
|
|
751
|
+
addValidatedFlag(clause);
|
|
752
|
+
return true;
|
|
753
|
+
}
|
|
754
|
+
return false;
|
|
755
|
+
}
|
|
756
|
+
function walkQuery(queryObj) {
|
|
757
|
+
const typeProperty = queryObj.getProperty(TYPE_PROPERTY_NAME5);
|
|
758
|
+
if (typeProperty && import_ts_morph5.Node.isPropertyAssignment(typeProperty)) {
|
|
759
|
+
const typeInit = typeProperty.getInitializer();
|
|
760
|
+
if (typeInit && import_ts_morph5.Node.isStringLiteral(typeInit) && (typeInit.getLiteralValue() === "or" || typeInit.getLiteralValue() === "and")) {
|
|
761
|
+
const clausesProperty = queryObj.getProperty(CLAUSES_PROPERTY_NAME);
|
|
762
|
+
if (!clausesProperty || !import_ts_morph5.Node.isPropertyAssignment(clausesProperty)) {
|
|
763
|
+
return 0;
|
|
764
|
+
}
|
|
765
|
+
const clausesInit = clausesProperty.getInitializer();
|
|
766
|
+
if (!clausesInit || !import_ts_morph5.Node.isArrayLiteralExpression(clausesInit)) {
|
|
767
|
+
return 0;
|
|
768
|
+
}
|
|
769
|
+
let changed = 0;
|
|
770
|
+
for (const clause of clausesInit.getElements()) {
|
|
771
|
+
if (import_ts_morph5.Node.isObjectLiteralExpression(clause)) {
|
|
772
|
+
changed += walkQuery(clause);
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
return changed;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
return migrateClause(queryObj) ? 1 : 0;
|
|
779
|
+
}
|
|
780
|
+
function processFile5(filePath, project) {
|
|
781
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
782
|
+
if (!sourceFile) return 0;
|
|
783
|
+
let migratedCount = 0;
|
|
784
|
+
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
785
|
+
import_ts_morph5.SyntaxKind.CallExpression
|
|
786
|
+
);
|
|
787
|
+
for (const call of callExpressions) {
|
|
788
|
+
const expression = call.getExpression();
|
|
789
|
+
if (!import_ts_morph5.Node.isIdentifier(expression) || expression.getText() !== DEFINE_WORKQUEUES_NAME) {
|
|
790
|
+
continue;
|
|
791
|
+
}
|
|
792
|
+
const args2 = call.getArguments();
|
|
793
|
+
if (args2.length === 0) continue;
|
|
794
|
+
const workqueuesArg = args2[0];
|
|
795
|
+
if (!import_ts_morph5.Node.isArrayLiteralExpression(workqueuesArg)) continue;
|
|
796
|
+
for (const workqueueElement of workqueuesArg.getElements()) {
|
|
797
|
+
if (!import_ts_morph5.Node.isObjectLiteralExpression(workqueueElement)) continue;
|
|
798
|
+
const queryProperty = workqueueElement.getProperty(QUERY_PROPERTY_NAME);
|
|
799
|
+
if (!queryProperty || !import_ts_morph5.Node.isPropertyAssignment(queryProperty)) continue;
|
|
800
|
+
const queryInit = queryProperty.getInitializer();
|
|
801
|
+
if (!queryInit || !import_ts_morph5.Node.isObjectLiteralExpression(queryInit)) continue;
|
|
802
|
+
const changed = walkQuery(queryInit);
|
|
803
|
+
if (changed > 0) {
|
|
804
|
+
migratedCount += changed;
|
|
805
|
+
console.log(
|
|
806
|
+
` [${import_path5.default.relative(getCwd(), filePath)}] Migrated ${changed} clause(s): VALIDATED status \u2192 flags.anyOf`
|
|
807
|
+
);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
return migratedCount;
|
|
812
|
+
}
|
|
813
|
+
async function main5() {
|
|
814
|
+
const srcDir = import_path5.default.join(getCwd(), "src");
|
|
815
|
+
console.log(`Scanning for defineWorkqueues calls in: ${srcDir}
|
|
816
|
+
`);
|
|
817
|
+
const project = new import_ts_morph5.Project({
|
|
818
|
+
tsConfigFilePath: import_path5.default.resolve(srcDir, "../tsconfig.json"),
|
|
819
|
+
skipAddingFilesFromTsConfig: false
|
|
820
|
+
});
|
|
821
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
822
|
+
const fp = sf.getFilePath();
|
|
823
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
824
|
+
});
|
|
825
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
826
|
+
`);
|
|
827
|
+
let totalMigrated = 0;
|
|
828
|
+
const modifiedFiles = [];
|
|
829
|
+
for (const sourceFile of sourceFiles) {
|
|
830
|
+
const filePath = sourceFile.getFilePath();
|
|
831
|
+
const migrated = processFile5(filePath, project);
|
|
832
|
+
if (migrated > 0) {
|
|
833
|
+
totalMigrated += migrated;
|
|
834
|
+
modifiedFiles.push(filePath);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
if (modifiedFiles.length === 0) {
|
|
838
|
+
console.log(
|
|
839
|
+
"No VALIDATED status references found in defineWorkqueues calls. Nothing to do."
|
|
840
|
+
);
|
|
841
|
+
return;
|
|
842
|
+
}
|
|
843
|
+
console.log(`
|
|
844
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
845
|
+
for (const filePath of modifiedFiles) {
|
|
846
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
847
|
+
await sourceFile.save();
|
|
848
|
+
console.log(` Saved: ${import_path5.default.relative(getCwd(), filePath)}`);
|
|
849
|
+
}
|
|
850
|
+
console.log(
|
|
851
|
+
`
|
|
852
|
+
Done. Migrated ${totalMigrated} clause(s) from VALIDATED status to flags.anyOf['validated'].`
|
|
853
|
+
);
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
// src/migrations/v2.0/add-birth-certificate-issuance-flag.ts
|
|
857
|
+
var import_ts_morph6 = require("ts-morph");
|
|
858
|
+
var import_path6 = __toESM(require("path"));
|
|
859
|
+
var DEFINE_CONFIG_NAME4 = "defineConfig";
|
|
860
|
+
var DEFINE_WORKQUEUES_NAME2 = "defineWorkqueues";
|
|
861
|
+
var ACTIONS_PROPERTY_NAME4 = "actions";
|
|
862
|
+
var ACTION_PROPERTY_NAME = "action";
|
|
863
|
+
var FLAGS_PROPERTY_NAME2 = "flags";
|
|
864
|
+
var QUERY_PROPERTY_NAME2 = "query";
|
|
865
|
+
var TYPE_PROPERTY_NAME6 = "type";
|
|
866
|
+
var CLAUSES_PROPERTY_NAME2 = "clauses";
|
|
867
|
+
var ANY_OF_PROPERTY_NAME2 = "anyOf";
|
|
868
|
+
var FLAG_ID = "pending-first-certificate-issuance";
|
|
869
|
+
var REGISTER_TYPE = "REGISTER";
|
|
870
|
+
var PRINT_CERTIFICATE_TYPE = "PRINT_CERTIFICATE";
|
|
871
|
+
var FLAG_DEFINITION_INITIALIZER = `{
|
|
872
|
+
id: '${FLAG_ID}',
|
|
873
|
+
label: {
|
|
874
|
+
id: 'event.birth.flag.${FLAG_ID}',
|
|
875
|
+
defaultMessage: 'Pending first certificate issuance',
|
|
876
|
+
description: 'Flag label for first certificate issuance'
|
|
877
|
+
},
|
|
878
|
+
requiresAction: true
|
|
879
|
+
}`;
|
|
880
|
+
function isActionOfType(obj, typeName) {
|
|
881
|
+
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME6);
|
|
882
|
+
if (!typeProperty || !import_ts_morph6.Node.isPropertyAssignment(typeProperty)) return false;
|
|
883
|
+
const typeInit = typeProperty.getInitializer();
|
|
884
|
+
if (!typeInit) return false;
|
|
885
|
+
if (import_ts_morph6.Node.isPropertyAccessExpression(typeInit)) {
|
|
886
|
+
return typeInit.getName() === typeName;
|
|
887
|
+
}
|
|
888
|
+
if (import_ts_morph6.Node.isStringLiteral(typeInit)) {
|
|
889
|
+
return typeInit.getLiteralValue() === typeName;
|
|
890
|
+
}
|
|
891
|
+
return false;
|
|
892
|
+
}
|
|
893
|
+
function isBirthConfig(configArg) {
|
|
894
|
+
const typeProperty = configArg.getProperty(TYPE_PROPERTY_NAME6);
|
|
895
|
+
if (!typeProperty || !import_ts_morph6.Node.isPropertyAssignment(typeProperty)) return false;
|
|
896
|
+
const initializer = typeProperty.getInitializer();
|
|
897
|
+
if (!initializer) return false;
|
|
898
|
+
if (import_ts_morph6.Node.isStringLiteral(initializer)) {
|
|
899
|
+
return initializer.getLiteralValue().toLowerCase() === "birth";
|
|
900
|
+
}
|
|
901
|
+
if (import_ts_morph6.Node.isPropertyAccessExpression(initializer)) {
|
|
902
|
+
return initializer.getName().toLowerCase() === "birth";
|
|
903
|
+
}
|
|
904
|
+
return false;
|
|
905
|
+
}
|
|
906
|
+
function hasElementWithId(array, id) {
|
|
907
|
+
for (const el of array.getElements()) {
|
|
908
|
+
if (!import_ts_morph6.Node.isObjectLiteralExpression(el)) continue;
|
|
909
|
+
const idProp = el.getProperty("id");
|
|
910
|
+
if (!idProp || !import_ts_morph6.Node.isPropertyAssignment(idProp)) continue;
|
|
911
|
+
const idInit = idProp.getInitializer();
|
|
912
|
+
if (idInit && import_ts_morph6.Node.isStringLiteral(idInit) && idInit.getLiteralValue() === id) {
|
|
913
|
+
return true;
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
return false;
|
|
917
|
+
}
|
|
918
|
+
function ensureTopLevelFlagDefinition(configArg) {
|
|
919
|
+
const flagsProp = configArg.getProperty(FLAGS_PROPERTY_NAME2);
|
|
920
|
+
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
921
|
+
const flagsInit = flagsProp.getInitializer();
|
|
922
|
+
if (flagsInit && import_ts_morph6.Node.isArrayLiteralExpression(flagsInit)) {
|
|
923
|
+
if (hasElementWithId(flagsInit, FLAG_ID)) return false;
|
|
924
|
+
flagsInit.addElement(FLAG_DEFINITION_INITIALIZER);
|
|
925
|
+
return true;
|
|
926
|
+
}
|
|
927
|
+
return false;
|
|
928
|
+
}
|
|
929
|
+
configArg.addPropertyAssignment({
|
|
930
|
+
name: FLAGS_PROPERTY_NAME2,
|
|
931
|
+
initializer: `[
|
|
932
|
+
${FLAG_DEFINITION_INITIALIZER}
|
|
933
|
+
]`
|
|
934
|
+
});
|
|
935
|
+
return true;
|
|
936
|
+
}
|
|
937
|
+
function ensureActionOperationFlag(action, operation) {
|
|
938
|
+
const flagsProp = action.getProperty(FLAGS_PROPERTY_NAME2);
|
|
939
|
+
const entry = `{ id: '${FLAG_ID}', operation: '${operation}' }`;
|
|
940
|
+
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
941
|
+
const flagsInit = flagsProp.getInitializer();
|
|
942
|
+
if (flagsInit && import_ts_morph6.Node.isArrayLiteralExpression(flagsInit)) {
|
|
943
|
+
if (hasElementWithId(flagsInit, FLAG_ID)) return false;
|
|
944
|
+
flagsInit.addElement(entry);
|
|
945
|
+
return true;
|
|
946
|
+
}
|
|
947
|
+
return false;
|
|
948
|
+
}
|
|
949
|
+
action.addPropertyAssignment({
|
|
950
|
+
name: FLAGS_PROPERTY_NAME2,
|
|
951
|
+
initializer: `[${entry}]`
|
|
952
|
+
});
|
|
953
|
+
return true;
|
|
954
|
+
}
|
|
955
|
+
function processBirthConfig(configArg, relPath) {
|
|
956
|
+
let changes = 0;
|
|
957
|
+
if (ensureTopLevelFlagDefinition(configArg)) {
|
|
958
|
+
changes++;
|
|
959
|
+
console.log(` [${relPath}] Added '${FLAG_ID}' to top-level flags`);
|
|
960
|
+
}
|
|
961
|
+
const actionsProp = configArg.getProperty(ACTIONS_PROPERTY_NAME4);
|
|
962
|
+
if (!actionsProp || !import_ts_morph6.Node.isPropertyAssignment(actionsProp)) return changes;
|
|
963
|
+
const actionsInit = actionsProp.getInitializer();
|
|
964
|
+
if (!actionsInit || !import_ts_morph6.Node.isArrayLiteralExpression(actionsInit)) {
|
|
965
|
+
return changes;
|
|
966
|
+
}
|
|
967
|
+
for (const element of actionsInit.getElements()) {
|
|
968
|
+
if (!import_ts_morph6.Node.isObjectLiteralExpression(element)) continue;
|
|
969
|
+
if (isActionOfType(element, REGISTER_TYPE)) {
|
|
970
|
+
if (ensureActionOperationFlag(element, "add")) {
|
|
971
|
+
changes++;
|
|
972
|
+
console.log(
|
|
973
|
+
` [${relPath}] Added '${FLAG_ID}' add-flag to REGISTER action`
|
|
974
|
+
);
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
if (isActionOfType(element, PRINT_CERTIFICATE_TYPE)) {
|
|
978
|
+
if (ensureActionOperationFlag(element, "remove")) {
|
|
979
|
+
changes++;
|
|
980
|
+
console.log(
|
|
981
|
+
` [${relPath}] Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`
|
|
982
|
+
);
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
return changes;
|
|
987
|
+
}
|
|
988
|
+
function hasPrintCertificateAction(workqueue) {
|
|
989
|
+
const actionsProp = workqueue.getProperty(ACTIONS_PROPERTY_NAME4);
|
|
990
|
+
if (actionsProp && import_ts_morph6.Node.isPropertyAssignment(actionsProp)) {
|
|
991
|
+
const actionsInit = actionsProp.getInitializer();
|
|
992
|
+
if (actionsInit && import_ts_morph6.Node.isArrayLiteralExpression(actionsInit)) {
|
|
993
|
+
for (const el of actionsInit.getElements()) {
|
|
994
|
+
if (import_ts_morph6.Node.isObjectLiteralExpression(el) && isActionOfType(el, PRINT_CERTIFICATE_TYPE)) {
|
|
995
|
+
return true;
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
const actionProp = workqueue.getProperty(ACTION_PROPERTY_NAME);
|
|
1001
|
+
if (actionProp && import_ts_morph6.Node.isPropertyAssignment(actionProp)) {
|
|
1002
|
+
const actionInit = actionProp.getInitializer();
|
|
1003
|
+
if (actionInit && import_ts_morph6.Node.isObjectLiteralExpression(actionInit) && isActionOfType(actionInit, PRINT_CERTIFICATE_TYPE)) {
|
|
1004
|
+
return true;
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
return false;
|
|
1008
|
+
}
|
|
1009
|
+
function addFlagToQueryClause(clause) {
|
|
1010
|
+
const flagsProp = clause.getProperty(FLAGS_PROPERTY_NAME2);
|
|
1011
|
+
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
1012
|
+
const flagsInit = flagsProp.getInitializer();
|
|
1013
|
+
if (flagsInit && import_ts_morph6.Node.isObjectLiteralExpression(flagsInit)) {
|
|
1014
|
+
const anyOfProp = flagsInit.getProperty(ANY_OF_PROPERTY_NAME2);
|
|
1015
|
+
if (anyOfProp && import_ts_morph6.Node.isPropertyAssignment(anyOfProp)) {
|
|
1016
|
+
const anyOfInit = anyOfProp.getInitializer();
|
|
1017
|
+
if (anyOfInit && import_ts_morph6.Node.isArrayLiteralExpression(anyOfInit)) {
|
|
1018
|
+
const alreadyPresent = anyOfInit.getElements().some(
|
|
1019
|
+
(el) => import_ts_morph6.Node.isStringLiteral(el) && el.getLiteralValue() === FLAG_ID
|
|
1020
|
+
);
|
|
1021
|
+
if (alreadyPresent) return false;
|
|
1022
|
+
anyOfInit.addElement(`'${FLAG_ID}'`);
|
|
1023
|
+
return true;
|
|
1024
|
+
}
|
|
1025
|
+
} else {
|
|
1026
|
+
flagsInit.addPropertyAssignment({
|
|
1027
|
+
name: ANY_OF_PROPERTY_NAME2,
|
|
1028
|
+
initializer: `['${FLAG_ID}']`
|
|
1029
|
+
});
|
|
1030
|
+
return true;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
} else {
|
|
1034
|
+
clause.addPropertyAssignment({
|
|
1035
|
+
name: FLAGS_PROPERTY_NAME2,
|
|
1036
|
+
initializer: `{ ${ANY_OF_PROPERTY_NAME2}: ['${FLAG_ID}'] }`
|
|
1037
|
+
});
|
|
1038
|
+
return true;
|
|
1039
|
+
}
|
|
1040
|
+
return false;
|
|
1041
|
+
}
|
|
1042
|
+
function walkQueryForFlagAddition(queryObj) {
|
|
1043
|
+
const typeProp = queryObj.getProperty(TYPE_PROPERTY_NAME6);
|
|
1044
|
+
if (typeProp && import_ts_morph6.Node.isPropertyAssignment(typeProp)) {
|
|
1045
|
+
const typeInit = typeProp.getInitializer();
|
|
1046
|
+
if (typeInit && import_ts_morph6.Node.isStringLiteral(typeInit) && (typeInit.getLiteralValue() === "or" || typeInit.getLiteralValue() === "and")) {
|
|
1047
|
+
const clausesProp = queryObj.getProperty(CLAUSES_PROPERTY_NAME2);
|
|
1048
|
+
if (!clausesProp || !import_ts_morph6.Node.isPropertyAssignment(clausesProp)) return 0;
|
|
1049
|
+
const clausesInit = clausesProp.getInitializer();
|
|
1050
|
+
if (!clausesInit || !import_ts_morph6.Node.isArrayLiteralExpression(clausesInit)) return 0;
|
|
1051
|
+
let changed = 0;
|
|
1052
|
+
for (const clause of clausesInit.getElements()) {
|
|
1053
|
+
if (import_ts_morph6.Node.isObjectLiteralExpression(clause)) {
|
|
1054
|
+
changed += walkQueryForFlagAddition(clause);
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
return changed;
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
return addFlagToQueryClause(queryObj) ? 1 : 0;
|
|
1061
|
+
}
|
|
1062
|
+
function processFile6(filePath, project) {
|
|
1063
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
1064
|
+
if (!sourceFile) return 0;
|
|
1065
|
+
let totalChanges = 0;
|
|
1066
|
+
const relPath = import_path6.default.relative(getCwd(), filePath);
|
|
1067
|
+
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
1068
|
+
import_ts_morph6.SyntaxKind.CallExpression
|
|
1069
|
+
);
|
|
1070
|
+
for (const call of callExpressions) {
|
|
1071
|
+
const expression = call.getExpression();
|
|
1072
|
+
if (!import_ts_morph6.Node.isIdentifier(expression)) continue;
|
|
1073
|
+
const calleeName = expression.getText();
|
|
1074
|
+
if (calleeName === DEFINE_CONFIG_NAME4) {
|
|
1075
|
+
const args2 = call.getArguments();
|
|
1076
|
+
if (args2.length === 0) continue;
|
|
1077
|
+
const configArg = args2[0];
|
|
1078
|
+
if (!import_ts_morph6.Node.isObjectLiteralExpression(configArg)) continue;
|
|
1079
|
+
if (!isBirthConfig(configArg)) continue;
|
|
1080
|
+
totalChanges += processBirthConfig(configArg, relPath);
|
|
1081
|
+
}
|
|
1082
|
+
if (calleeName === DEFINE_WORKQUEUES_NAME2) {
|
|
1083
|
+
const args2 = call.getArguments();
|
|
1084
|
+
if (args2.length === 0) continue;
|
|
1085
|
+
const workqueuesArg = args2[0];
|
|
1086
|
+
if (!import_ts_morph6.Node.isArrayLiteralExpression(workqueuesArg)) continue;
|
|
1087
|
+
for (const workqueueEl of workqueuesArg.getElements()) {
|
|
1088
|
+
if (!import_ts_morph6.Node.isObjectLiteralExpression(workqueueEl)) continue;
|
|
1089
|
+
if (!hasPrintCertificateAction(workqueueEl)) continue;
|
|
1090
|
+
const queryProp = workqueueEl.getProperty(QUERY_PROPERTY_NAME2);
|
|
1091
|
+
if (!queryProp || !import_ts_morph6.Node.isPropertyAssignment(queryProp)) continue;
|
|
1092
|
+
const queryInit = queryProp.getInitializer();
|
|
1093
|
+
if (!queryInit || !import_ts_morph6.Node.isObjectLiteralExpression(queryInit)) continue;
|
|
1094
|
+
const changed = walkQueryForFlagAddition(queryInit);
|
|
1095
|
+
if (changed > 0) {
|
|
1096
|
+
totalChanges += changed;
|
|
1097
|
+
console.log(
|
|
1098
|
+
` [${relPath}] Added '${FLAG_ID}' to flags.anyOf in ${changed} PRINT_CERTIFICATE workqueue clause(s)`
|
|
1099
|
+
);
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
return totalChanges;
|
|
1105
|
+
}
|
|
1106
|
+
async function main6() {
|
|
1107
|
+
const srcDir = import_path6.default.join(getCwd(), "src");
|
|
1108
|
+
console.log(
|
|
1109
|
+
`Scanning for birth defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}
|
|
1110
|
+
`
|
|
1111
|
+
);
|
|
1112
|
+
const project = new import_ts_morph6.Project({
|
|
1113
|
+
tsConfigFilePath: import_path6.default.resolve(srcDir, "../tsconfig.json"),
|
|
1114
|
+
skipAddingFilesFromTsConfig: false
|
|
1115
|
+
});
|
|
1116
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
1117
|
+
const fp = sf.getFilePath();
|
|
1118
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
1119
|
+
});
|
|
1120
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
1121
|
+
`);
|
|
1122
|
+
let totalChanges = 0;
|
|
1123
|
+
const modifiedFiles = [];
|
|
1124
|
+
for (const sourceFile of sourceFiles) {
|
|
1125
|
+
const filePath = sourceFile.getFilePath();
|
|
1126
|
+
const changes = processFile6(filePath, project);
|
|
1127
|
+
if (changes > 0) {
|
|
1128
|
+
totalChanges += changes;
|
|
1129
|
+
modifiedFiles.push(filePath);
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
if (modifiedFiles.length === 0) {
|
|
1133
|
+
console.log(
|
|
1134
|
+
"No birth configs or PRINT_CERTIFICATE workqueues found. Nothing to do."
|
|
1135
|
+
);
|
|
1136
|
+
return;
|
|
1137
|
+
}
|
|
1138
|
+
console.log(`
|
|
1139
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
1140
|
+
for (const filePath of modifiedFiles) {
|
|
1141
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1142
|
+
await sourceFile.save();
|
|
1143
|
+
console.log(` Saved: ${import_path6.default.relative(getCwd(), filePath)}`);
|
|
1144
|
+
}
|
|
1145
|
+
console.log(
|
|
1146
|
+
`
|
|
1147
|
+
Done. Applied ${totalChanges} change(s) across ${modifiedFiles.length} file(s).`
|
|
1148
|
+
);
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
// src/migrations/v2.0/remove-pending-certification-flag.ts
|
|
1152
|
+
var import_ts_morph7 = require("ts-morph");
|
|
1153
|
+
var import_path7 = __toESM(require("path"));
|
|
1154
|
+
var INHERENT_FLAGS_ENUM_NAME = "InherentFlags";
|
|
1155
|
+
var PENDING_CERTIFICATION_MEMBER = "PENDING_CERTIFICATION";
|
|
1156
|
+
function isPendingCertificationFlag(node) {
|
|
1157
|
+
if (!import_ts_morph7.Node.isPropertyAccessExpression(node)) return false;
|
|
1158
|
+
const obj = node.getExpression();
|
|
1159
|
+
const member = node.getName();
|
|
1160
|
+
return import_ts_morph7.Node.isIdentifier(obj) && obj.getText() === INHERENT_FLAGS_ENUM_NAME && member === PENDING_CERTIFICATION_MEMBER;
|
|
1161
|
+
}
|
|
1162
|
+
function processFile7(filePath, project) {
|
|
1163
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
1164
|
+
if (!sourceFile) return 0;
|
|
1165
|
+
let removedCount = 0;
|
|
1166
|
+
const arrayLiterals = sourceFile.getDescendantsOfKind(
|
|
1167
|
+
import_ts_morph7.SyntaxKind.ArrayLiteralExpression
|
|
1168
|
+
);
|
|
1169
|
+
for (const array of arrayLiterals) {
|
|
1170
|
+
const indicesToRemove = [];
|
|
1171
|
+
array.getElements().forEach((element, index) => {
|
|
1172
|
+
if (isPendingCertificationFlag(element)) {
|
|
1173
|
+
indicesToRemove.push(index);
|
|
1174
|
+
}
|
|
1175
|
+
});
|
|
1176
|
+
for (const index of indicesToRemove.reverse()) {
|
|
1177
|
+
array.removeElement(index);
|
|
1178
|
+
removedCount++;
|
|
1179
|
+
console.log(
|
|
1180
|
+
` [${import_path7.default.relative(getCwd(), filePath)}] Removed InherentFlags.PENDING_CERTIFICATION from array`
|
|
1181
|
+
);
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
return removedCount;
|
|
1185
|
+
}
|
|
1186
|
+
async function main7() {
|
|
1187
|
+
const srcDir = import_path7.default.join(getCwd(), "src");
|
|
1188
|
+
console.log(
|
|
1189
|
+
`Scanning for InherentFlags.PENDING_CERTIFICATION array elements in: ${srcDir}
|
|
1190
|
+
`
|
|
1191
|
+
);
|
|
1192
|
+
const project = new import_ts_morph7.Project({
|
|
1193
|
+
tsConfigFilePath: import_path7.default.resolve(srcDir, "../tsconfig.json"),
|
|
1194
|
+
skipAddingFilesFromTsConfig: false
|
|
1195
|
+
});
|
|
1196
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
1197
|
+
const fp = sf.getFilePath();
|
|
1198
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
1199
|
+
});
|
|
1200
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
1201
|
+
`);
|
|
1202
|
+
let totalRemoved = 0;
|
|
1203
|
+
const modifiedFiles = [];
|
|
1204
|
+
for (const sourceFile of sourceFiles) {
|
|
1205
|
+
const filePath = sourceFile.getFilePath();
|
|
1206
|
+
const removed = processFile7(filePath, project);
|
|
1207
|
+
if (removed > 0) {
|
|
1208
|
+
totalRemoved += removed;
|
|
1209
|
+
modifiedFiles.push(filePath);
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
if (modifiedFiles.length === 0) {
|
|
1213
|
+
console.log(
|
|
1214
|
+
"No InherentFlags.PENDING_CERTIFICATION elements found in any array. Nothing to do."
|
|
1215
|
+
);
|
|
1216
|
+
return;
|
|
1217
|
+
}
|
|
1218
|
+
console.log(`
|
|
1219
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
1220
|
+
for (const filePath of modifiedFiles) {
|
|
1221
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1222
|
+
await sourceFile.save();
|
|
1223
|
+
console.log(` Saved: ${import_path7.default.relative(getCwd(), filePath)}`);
|
|
1224
|
+
}
|
|
1225
|
+
console.log(
|
|
1226
|
+
`
|
|
1227
|
+
Done. Removed ${totalRemoved} InherentFlags.PENDING_CERTIFICATION element(s) from array(s).`
|
|
1228
|
+
);
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
// src/migrations/v2.0/rename-location-parent-id.ts
|
|
1232
|
+
var import_ts_morph8 = require("ts-morph");
|
|
1233
|
+
var import_path8 = __toESM(require("path"));
|
|
1234
|
+
var OLD_PROPERTY_NAME = "parentId";
|
|
1235
|
+
var NEW_PROPERTY_NAME = "administrativeAreaId";
|
|
1236
|
+
var LOCATION_TYPE_NAME = "Location";
|
|
1237
|
+
var LOCATION_STRUCTURAL_PROPS = [
|
|
1238
|
+
"id",
|
|
1239
|
+
"name",
|
|
1240
|
+
"externalId",
|
|
1241
|
+
"locationType"
|
|
1242
|
+
];
|
|
1243
|
+
var LOCATION_AREA_ID_PROPS = ["administrativeAreaId", "parentId"];
|
|
1244
|
+
function isSingleLocationType(t) {
|
|
1245
|
+
if (t.getAliasSymbol()?.getName() === LOCATION_TYPE_NAME) return true;
|
|
1246
|
+
if (t.getSymbol()?.getName() === LOCATION_TYPE_NAME) return true;
|
|
1247
|
+
if (t.isObject()) {
|
|
1248
|
+
const propNames = new Set(t.getProperties().map((p) => p.getName()));
|
|
1249
|
+
const hasCorePropNames = LOCATION_STRUCTURAL_PROPS.every(
|
|
1250
|
+
(p) => propNames.has(p)
|
|
1251
|
+
);
|
|
1252
|
+
const hasAreaIdProp = LOCATION_AREA_ID_PROPS.some((p) => propNames.has(p));
|
|
1253
|
+
if (hasCorePropNames && hasAreaIdProp) return true;
|
|
1254
|
+
}
|
|
1255
|
+
return false;
|
|
1256
|
+
}
|
|
1257
|
+
function isLocationType(node) {
|
|
1258
|
+
let type;
|
|
1259
|
+
try {
|
|
1260
|
+
type = node.getType();
|
|
1261
|
+
} catch {
|
|
1262
|
+
return false;
|
|
1263
|
+
}
|
|
1264
|
+
if (isSingleLocationType(type)) return true;
|
|
1265
|
+
for (const constituent of type.getUnionTypes()) {
|
|
1266
|
+
if (isSingleLocationType(constituent)) return true;
|
|
1267
|
+
}
|
|
1268
|
+
return false;
|
|
1269
|
+
}
|
|
1270
|
+
function processFile8(filePath, project) {
|
|
1271
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
1272
|
+
if (!sourceFile) return 0;
|
|
1273
|
+
let renamedCount = 0;
|
|
1274
|
+
const candidates = sourceFile.getDescendantsOfKind(import_ts_morph8.SyntaxKind.PropertyAccessExpression).filter((propAccess) => propAccess.getName() === OLD_PROPERTY_NAME);
|
|
1275
|
+
for (const propAccess of candidates) {
|
|
1276
|
+
const obj = propAccess.getExpression();
|
|
1277
|
+
if (!isLocationType(obj)) continue;
|
|
1278
|
+
propAccess.getNameNode().replaceWithText(NEW_PROPERTY_NAME);
|
|
1279
|
+
renamedCount++;
|
|
1280
|
+
console.log(
|
|
1281
|
+
` [${import_path8.default.relative(getCwd(), filePath)}] Renamed Location.${OLD_PROPERTY_NAME} \u2192 Location.${NEW_PROPERTY_NAME}`
|
|
1282
|
+
);
|
|
1283
|
+
}
|
|
1284
|
+
return renamedCount;
|
|
1285
|
+
}
|
|
1286
|
+
async function main8() {
|
|
1287
|
+
const srcDir = import_path8.default.join(getCwd(), "src");
|
|
1288
|
+
console.log(
|
|
1289
|
+
`Scanning for Location.${OLD_PROPERTY_NAME} references in: ${srcDir}
|
|
1290
|
+
`
|
|
1291
|
+
);
|
|
1292
|
+
const project = new import_ts_morph8.Project({
|
|
1293
|
+
tsConfigFilePath: import_path8.default.resolve(srcDir, "../tsconfig.json"),
|
|
1294
|
+
skipAddingFilesFromTsConfig: false
|
|
1295
|
+
});
|
|
1296
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
1297
|
+
const fp = sf.getFilePath();
|
|
1298
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
1299
|
+
});
|
|
1300
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
1301
|
+
`);
|
|
1302
|
+
let totalRenamed = 0;
|
|
1303
|
+
const modifiedFiles = [];
|
|
1304
|
+
for (const sourceFile of sourceFiles) {
|
|
1305
|
+
const filePath = sourceFile.getFilePath();
|
|
1306
|
+
const renamed = processFile8(filePath, project);
|
|
1307
|
+
if (renamed > 0) {
|
|
1308
|
+
totalRenamed += renamed;
|
|
1309
|
+
modifiedFiles.push(filePath);
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
if (modifiedFiles.length === 0) {
|
|
1313
|
+
console.log(
|
|
1314
|
+
`No Location.${OLD_PROPERTY_NAME} references found. Nothing to do.`
|
|
1315
|
+
);
|
|
1316
|
+
return;
|
|
1317
|
+
}
|
|
1318
|
+
console.log(`
|
|
1319
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
1320
|
+
for (const filePath of modifiedFiles) {
|
|
1321
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1322
|
+
await sourceFile.save();
|
|
1323
|
+
console.log(` Saved: ${import_path8.default.relative(getCwd(), filePath)}`);
|
|
1324
|
+
}
|
|
1325
|
+
console.log(
|
|
1326
|
+
`
|
|
1327
|
+
Done. Renamed ${totalRenamed} Location.${OLD_PROPERTY_NAME} reference(s) to Location.${NEW_PROPERTY_NAME}.`
|
|
1328
|
+
);
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
// src/migrations/v2.0/rename-api-paths.ts
|
|
1332
|
+
var import_ts_morph9 = require("ts-morph");
|
|
1333
|
+
var import_path9 = __toESM(require("path"));
|
|
1334
|
+
var PATH_RENAMES = {
|
|
1335
|
+
"/events": "/config/events",
|
|
1336
|
+
"/application-config": "/config/application",
|
|
1337
|
+
"/workqueue": "/config/workqueues",
|
|
1338
|
+
"/locations": "/config/locations",
|
|
1339
|
+
"/users": "/config/users",
|
|
1340
|
+
"/roles": "/config/roles"
|
|
1341
|
+
};
|
|
1342
|
+
var METHOD_PROPERTY_NAME = "method";
|
|
1343
|
+
var PATH_PROPERTY_NAME = "path";
|
|
1344
|
+
var HTTP_VERBS = /* @__PURE__ */ new Set([
|
|
1345
|
+
"GET",
|
|
1346
|
+
"POST",
|
|
1347
|
+
"PUT",
|
|
1348
|
+
"PATCH",
|
|
1349
|
+
"DELETE",
|
|
1350
|
+
"OPTIONS",
|
|
1351
|
+
"HEAD",
|
|
1352
|
+
"*"
|
|
1353
|
+
]);
|
|
1354
|
+
function isRouteConfig(obj) {
|
|
1355
|
+
const methodProp = obj.getProperty(METHOD_PROPERTY_NAME);
|
|
1356
|
+
if (!methodProp || !import_ts_morph9.Node.isPropertyAssignment(methodProp)) return false;
|
|
1357
|
+
const methodInit = methodProp.getInitializer();
|
|
1358
|
+
if (!methodInit) return false;
|
|
1359
|
+
if (import_ts_morph9.Node.isStringLiteral(methodInit)) {
|
|
1360
|
+
if (!HTTP_VERBS.has(methodInit.getLiteralValue().toUpperCase()))
|
|
1361
|
+
return false;
|
|
1362
|
+
} else if (import_ts_morph9.Node.isArrayLiteralExpression(methodInit)) {
|
|
1363
|
+
const allVerbs = methodInit.getElements().every(
|
|
1364
|
+
(el) => import_ts_morph9.Node.isStringLiteral(el) && HTTP_VERBS.has(el.getLiteralValue().toUpperCase())
|
|
1365
|
+
);
|
|
1366
|
+
if (!allVerbs) return false;
|
|
1367
|
+
} else {
|
|
1368
|
+
return false;
|
|
1369
|
+
}
|
|
1370
|
+
const pathProp = obj.getProperty(PATH_PROPERTY_NAME);
|
|
1371
|
+
if (!pathProp || !import_ts_morph9.Node.isPropertyAssignment(pathProp)) return false;
|
|
1372
|
+
const pathInit = pathProp.getInitializer();
|
|
1373
|
+
return !!pathInit && import_ts_morph9.Node.isStringLiteral(pathInit);
|
|
1374
|
+
}
|
|
1375
|
+
function renameRoutePath(obj) {
|
|
1376
|
+
const pathProp = obj.getProperty(PATH_PROPERTY_NAME);
|
|
1377
|
+
if (!pathProp || !import_ts_morph9.Node.isPropertyAssignment(pathProp)) return null;
|
|
1378
|
+
const pathInit = pathProp.getInitializer();
|
|
1379
|
+
if (!pathInit || !import_ts_morph9.Node.isStringLiteral(pathInit)) return null;
|
|
1380
|
+
const oldPath = pathInit.getLiteralValue();
|
|
1381
|
+
const newPath = PATH_RENAMES[oldPath];
|
|
1382
|
+
if (!newPath) return null;
|
|
1383
|
+
pathInit.replaceWithText(`'${newPath}'`);
|
|
1384
|
+
return newPath;
|
|
1385
|
+
}
|
|
1386
|
+
function processFile9(filePath, project) {
|
|
1387
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
1388
|
+
if (!sourceFile) return 0;
|
|
1389
|
+
let renamedCount = 0;
|
|
1390
|
+
const relPath = import_path9.default.relative(getCwd(), filePath);
|
|
1391
|
+
const candidates = sourceFile.getDescendantsOfKind(
|
|
1392
|
+
import_ts_morph9.SyntaxKind.ObjectLiteralExpression
|
|
1393
|
+
);
|
|
1394
|
+
for (const obj of candidates) {
|
|
1395
|
+
if (!isRouteConfig(obj)) continue;
|
|
1396
|
+
const newPath = renameRoutePath(obj);
|
|
1397
|
+
if (newPath) {
|
|
1398
|
+
renamedCount++;
|
|
1399
|
+
console.log(` [${relPath}] Renamed route path \u2192 '${newPath}'`);
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
return renamedCount;
|
|
1403
|
+
}
|
|
1404
|
+
async function main9() {
|
|
1405
|
+
const srcDir = import_path9.default.join(getCwd(), "src");
|
|
1406
|
+
console.log(`Scanning for Hapi route configs in: ${srcDir}
|
|
1407
|
+
`);
|
|
1408
|
+
console.log("Active path renames:");
|
|
1409
|
+
for (const [from, to] of Object.entries(PATH_RENAMES)) {
|
|
1410
|
+
console.log(` '${from}' \u2192 '${to}'`);
|
|
1411
|
+
}
|
|
1412
|
+
console.log();
|
|
1413
|
+
const project = new import_ts_morph9.Project({
|
|
1414
|
+
tsConfigFilePath: import_path9.default.resolve(srcDir, "../tsconfig.json"),
|
|
1415
|
+
skipAddingFilesFromTsConfig: false
|
|
1416
|
+
});
|
|
1417
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
1418
|
+
const fp = sf.getFilePath();
|
|
1419
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
1420
|
+
});
|
|
1421
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
1422
|
+
`);
|
|
1423
|
+
let totalRenamed = 0;
|
|
1424
|
+
const modifiedFiles = [];
|
|
1425
|
+
for (const sourceFile of sourceFiles) {
|
|
1426
|
+
const filePath = sourceFile.getFilePath();
|
|
1427
|
+
const renamed = processFile9(filePath, project);
|
|
1428
|
+
if (renamed > 0) {
|
|
1429
|
+
totalRenamed += renamed;
|
|
1430
|
+
modifiedFiles.push(filePath);
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
if (modifiedFiles.length === 0) {
|
|
1434
|
+
console.log("No matching route paths found. Nothing to do.");
|
|
1435
|
+
return;
|
|
1436
|
+
}
|
|
1437
|
+
console.log(`
|
|
1438
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
1439
|
+
for (const filePath of modifiedFiles) {
|
|
1440
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1441
|
+
await sourceFile.save();
|
|
1442
|
+
console.log(` Saved: ${import_path9.default.relative(getCwd(), filePath)}`);
|
|
1443
|
+
}
|
|
1444
|
+
console.log(`
|
|
1445
|
+
Done. Renamed ${totalRenamed} route path(s).`);
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
// src/migrations/v2.0/convert-config-files-to-ts.ts
|
|
1449
|
+
var fs = __toESM(require("fs"));
|
|
1450
|
+
var import_ts_morph10 = require("ts-morph");
|
|
1451
|
+
var import_path10 = __toESM(require("path"));
|
|
1452
|
+
var CLIENT_VALID_KEYS = /* @__PURE__ */ new Set([
|
|
1453
|
+
"COUNTRY",
|
|
1454
|
+
"LANGUAGES",
|
|
1455
|
+
"SENTRY",
|
|
1456
|
+
"REGISTER_BACKGROUND",
|
|
1457
|
+
"DASHBOARDS",
|
|
1458
|
+
"FEATURES"
|
|
1459
|
+
]);
|
|
1460
|
+
var LOGIN_VALID_KEYS = /* @__PURE__ */ new Set([
|
|
1461
|
+
"COUNTRY",
|
|
1462
|
+
"LANGUAGES",
|
|
1463
|
+
"USER_NOTIFICATION_DELIVERY_METHOD",
|
|
1464
|
+
"INFORMANT_NOTIFICATION_DELIVERY_METHOD",
|
|
1465
|
+
"PHONE_NUMBER_PATTERN",
|
|
1466
|
+
"LOGIN_BACKGROUND",
|
|
1467
|
+
"SENTRY"
|
|
1468
|
+
]);
|
|
1469
|
+
var APPLICATION_CONFIG_VALID_KEYS = /* @__PURE__ */ new Set([
|
|
1470
|
+
"APPLICATION_NAME",
|
|
1471
|
+
"COUNTRY_LOGO",
|
|
1472
|
+
"SYSTEM_IANA_TIMEZONE",
|
|
1473
|
+
"CURRENCY",
|
|
1474
|
+
"ADMIN_STRUCTURE",
|
|
1475
|
+
"PHONE_NUMBER_PATTERN",
|
|
1476
|
+
"USER_NOTIFICATION_DELIVERY_METHOD",
|
|
1477
|
+
"INFORMANT_NOTIFICATION_DELIVERY_METHOD",
|
|
1478
|
+
"SEARCH_DEFAULT_CRITERIA"
|
|
1479
|
+
]);
|
|
1480
|
+
var CONFIG_GROUPS = [
|
|
1481
|
+
{
|
|
1482
|
+
baseName: "client-config",
|
|
1483
|
+
prodName: "client-config.prod",
|
|
1484
|
+
defineFn: "defineClientConfig",
|
|
1485
|
+
importFrom: "@opencrvs/toolkit/application-config",
|
|
1486
|
+
validKeys: CLIENT_VALID_KEYS,
|
|
1487
|
+
requiredPlaceholders: {
|
|
1488
|
+
// BackgroundConfig requires backgroundColor or backgroundImage
|
|
1489
|
+
REGISTER_BACKGROUND: "{ backgroundColor: '#F4F4F7' }"
|
|
1490
|
+
},
|
|
1491
|
+
exportNames: {
|
|
1492
|
+
"client-config": "clientConfig",
|
|
1493
|
+
"client-config.prod": "clientConfigProd"
|
|
1494
|
+
},
|
|
1495
|
+
routePath: "/client-config.js"
|
|
1496
|
+
},
|
|
1497
|
+
{
|
|
1498
|
+
baseName: "login-config",
|
|
1499
|
+
prodName: "login-config.prod",
|
|
1500
|
+
defineFn: "defineLoginConfig",
|
|
1501
|
+
importFrom: "@opencrvs/toolkit/application-config",
|
|
1502
|
+
validKeys: LOGIN_VALID_KEYS,
|
|
1503
|
+
requiredPlaceholders: {},
|
|
1504
|
+
// These keys are always sourced from applicationConfig rather than
|
|
1505
|
+
// copied from the old JS file or filled with a placeholder value.
|
|
1506
|
+
// LOGIN_BACKGROUND lives in applicationConfig and is not part of the
|
|
1507
|
+
// ApplicationConfig schema, so Phase 3 will inline its value and remove
|
|
1508
|
+
// it from applicationConfig automatically.
|
|
1509
|
+
applicationConfigKeys: [
|
|
1510
|
+
"LOGIN_BACKGROUND",
|
|
1511
|
+
"USER_NOTIFICATION_DELIVERY_METHOD",
|
|
1512
|
+
"INFORMANT_NOTIFICATION_DELIVERY_METHOD",
|
|
1513
|
+
"PHONE_NUMBER_PATTERN"
|
|
1514
|
+
],
|
|
1515
|
+
applicationConfigImportPath: "./api/application/application-config",
|
|
1516
|
+
exportNames: {
|
|
1517
|
+
"login-config": "loginConfig",
|
|
1518
|
+
"login-config.prod": "loginConfigProd"
|
|
1519
|
+
},
|
|
1520
|
+
routePath: "/login-config.js"
|
|
1521
|
+
}
|
|
1522
|
+
];
|
|
1523
|
+
var HTTP_VERBS2 = /* @__PURE__ */ new Set([
|
|
1524
|
+
"GET",
|
|
1525
|
+
"POST",
|
|
1526
|
+
"PUT",
|
|
1527
|
+
"PATCH",
|
|
1528
|
+
"DELETE",
|
|
1529
|
+
"OPTIONS",
|
|
1530
|
+
"HEAD",
|
|
1531
|
+
"*"
|
|
1532
|
+
]);
|
|
1533
|
+
function extractWindowConfig(jsFilePath) {
|
|
1534
|
+
const jsProject = new import_ts_morph10.Project({
|
|
1535
|
+
compilerOptions: { allowJs: true, checkJs: false }
|
|
1536
|
+
// addFilesFromTsConfig: false
|
|
1537
|
+
});
|
|
1538
|
+
let sourceFile;
|
|
1539
|
+
try {
|
|
1540
|
+
sourceFile = jsProject.addSourceFileAtPath(jsFilePath);
|
|
1541
|
+
} catch {
|
|
1542
|
+
console.warn(` Could not parse ${jsFilePath}`);
|
|
1543
|
+
return null;
|
|
1544
|
+
}
|
|
1545
|
+
for (const binary of sourceFile.getDescendantsOfKind(
|
|
1546
|
+
import_ts_morph10.SyntaxKind.BinaryExpression
|
|
1547
|
+
)) {
|
|
1548
|
+
if (binary.getOperatorToken().getKind() !== import_ts_morph10.SyntaxKind.EqualsToken) continue;
|
|
1549
|
+
const left = binary.getLeft();
|
|
1550
|
+
if (!import_ts_morph10.Node.isPropertyAccessExpression(left)) continue;
|
|
1551
|
+
if (left.getExpression().getText() !== "window") continue;
|
|
1552
|
+
if (left.getName() !== "config") continue;
|
|
1553
|
+
const right = binary.getRight();
|
|
1554
|
+
if (import_ts_morph10.Node.isObjectLiteralExpression(right)) return right;
|
|
1555
|
+
}
|
|
1556
|
+
return null;
|
|
1557
|
+
}
|
|
1558
|
+
function convertLanguages(init) {
|
|
1559
|
+
if (import_ts_morph10.Node.isStringLiteral(init)) {
|
|
1560
|
+
const langs = init.getLiteralValue().split(",").map((l) => `'${l.trim()}'`).join(", ");
|
|
1561
|
+
return `[${langs}]`;
|
|
1562
|
+
}
|
|
1563
|
+
return init.getText();
|
|
1564
|
+
}
|
|
1565
|
+
function extractStaticUrlString(init) {
|
|
1566
|
+
if (import_ts_morph10.Node.isStringLiteral(init)) {
|
|
1567
|
+
return init.getLiteralValue();
|
|
1568
|
+
}
|
|
1569
|
+
if (init.getKind() === import_ts_morph10.SyntaxKind.NoSubstitutionTemplateLiteral) {
|
|
1570
|
+
const raw = init.getText();
|
|
1571
|
+
return raw.slice(1, -1);
|
|
1572
|
+
}
|
|
1573
|
+
return null;
|
|
1574
|
+
}
|
|
1575
|
+
function transformDashboardUrl(init, isProd) {
|
|
1576
|
+
if (!isProd) return init.getText();
|
|
1577
|
+
const urlString = extractStaticUrlString(init);
|
|
1578
|
+
if (!urlString) return init.getText();
|
|
1579
|
+
try {
|
|
1580
|
+
const parsed = new URL(urlString);
|
|
1581
|
+
const rest = parsed.pathname + parsed.search + parsed.hash;
|
|
1582
|
+
return `\`\${scheme}//metabase.\${hostname}${rest}\``;
|
|
1583
|
+
} catch {
|
|
1584
|
+
return init.getText();
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
function transformDashboardsValue(init, isProd) {
|
|
1588
|
+
if (!isProd || !import_ts_morph10.Node.isArrayLiteralExpression(init)) {
|
|
1589
|
+
return init.getText();
|
|
1590
|
+
}
|
|
1591
|
+
const elementParts = [];
|
|
1592
|
+
for (const el of init.getElements()) {
|
|
1593
|
+
if (!import_ts_morph10.Node.isObjectLiteralExpression(el)) {
|
|
1594
|
+
elementParts.push(el.getText());
|
|
1595
|
+
continue;
|
|
1596
|
+
}
|
|
1597
|
+
const propParts = [];
|
|
1598
|
+
for (const prop of el.getProperties()) {
|
|
1599
|
+
if (!import_ts_morph10.Node.isPropertyAssignment(prop)) {
|
|
1600
|
+
propParts.push(prop.getText());
|
|
1601
|
+
continue;
|
|
1602
|
+
}
|
|
1603
|
+
const propName = prop.getName();
|
|
1604
|
+
const propInit = prop.getInitializer();
|
|
1605
|
+
if (!propInit) {
|
|
1606
|
+
propParts.push(prop.getText());
|
|
1607
|
+
continue;
|
|
1608
|
+
}
|
|
1609
|
+
if (propName === "url") {
|
|
1610
|
+
propParts.push(`url: ${transformDashboardUrl(propInit, isProd)}`);
|
|
1611
|
+
} else {
|
|
1612
|
+
propParts.push(`${propName}: ${propInit.getText()}`);
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
elementParts.push(
|
|
1616
|
+
` {
|
|
1617
|
+
${propParts.map((p) => ` ${p}`).join(",\n")}
|
|
1618
|
+
}`
|
|
1619
|
+
);
|
|
1620
|
+
}
|
|
1621
|
+
return `[
|
|
1622
|
+
${elementParts.join(",\n")}
|
|
1623
|
+
]`;
|
|
1624
|
+
}
|
|
1625
|
+
function generateTsContent(configObj, exportName, group, isProd) {
|
|
1626
|
+
const headerLines = [];
|
|
1627
|
+
if (isProd) {
|
|
1628
|
+
headerLines.push(`import { env } from './environment'`);
|
|
1629
|
+
}
|
|
1630
|
+
headerLines.push(`import { ${group.defineFn} } from '${group.importFrom}'`);
|
|
1631
|
+
if (group.applicationConfigImportPath) {
|
|
1632
|
+
headerLines.push(
|
|
1633
|
+
`import { applicationConfig } from '${group.applicationConfigImportPath}'`
|
|
1634
|
+
);
|
|
1635
|
+
}
|
|
1636
|
+
headerLines.push("");
|
|
1637
|
+
if (isProd) {
|
|
1638
|
+
headerLines.push(`const scheme = 'https'`);
|
|
1639
|
+
headerLines.push(`const hostname = env.DOMAIN`);
|
|
1640
|
+
headerLines.push(`const sentry = env.SENTRY_DSN`);
|
|
1641
|
+
} else {
|
|
1642
|
+
headerLines.push(`const scheme = 'http'`);
|
|
1643
|
+
headerLines.push(`const hostname = 'localhost'`);
|
|
1644
|
+
}
|
|
1645
|
+
const propertyLines = [];
|
|
1646
|
+
const seenKeys = /* @__PURE__ */ new Set();
|
|
1647
|
+
const appConfigKeySet = new Set(group.applicationConfigKeys ?? []);
|
|
1648
|
+
for (const prop of configObj.getProperties()) {
|
|
1649
|
+
if (!import_ts_morph10.Node.isPropertyAssignment(prop)) continue;
|
|
1650
|
+
const name = prop.getName();
|
|
1651
|
+
if (!group.validKeys.has(name)) continue;
|
|
1652
|
+
if (appConfigKeySet.has(name)) continue;
|
|
1653
|
+
seenKeys.add(name);
|
|
1654
|
+
const init = prop.getInitializer();
|
|
1655
|
+
if (!init) continue;
|
|
1656
|
+
if (name === "LANGUAGES") {
|
|
1657
|
+
propertyLines.push(` LANGUAGES: ${convertLanguages(init)}`);
|
|
1658
|
+
} else if (name === "SENTRY" && isProd) {
|
|
1659
|
+
propertyLines.push(` SENTRY: sentry`);
|
|
1660
|
+
} else if (name === "DASHBOARDS") {
|
|
1661
|
+
propertyLines.push(
|
|
1662
|
+
` DASHBOARDS: ${transformDashboardsValue(init, isProd)}`
|
|
1663
|
+
);
|
|
1664
|
+
} else {
|
|
1665
|
+
propertyLines.push(` ${name}: ${init.getText()}`);
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
for (const [key, placeholder] of Object.entries(group.requiredPlaceholders)) {
|
|
1669
|
+
if (!seenKeys.has(key)) {
|
|
1670
|
+
propertyLines.push(
|
|
1671
|
+
` // TODO: configure ${key} \u2014 replace this placeholder`,
|
|
1672
|
+
` ${key}: ${placeholder}`
|
|
1673
|
+
);
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
for (const key of appConfigKeySet) {
|
|
1677
|
+
propertyLines.push(` ${key}: applicationConfig.${key}`);
|
|
1678
|
+
}
|
|
1679
|
+
const body = propertyLines.join(",\n");
|
|
1680
|
+
return [
|
|
1681
|
+
...headerLines,
|
|
1682
|
+
"",
|
|
1683
|
+
`export const ${exportName} = ${group.defineFn}({`,
|
|
1684
|
+
body,
|
|
1685
|
+
"})",
|
|
1686
|
+
""
|
|
1687
|
+
].join("\n");
|
|
1688
|
+
}
|
|
1689
|
+
function convertFile(name, group, srcDir) {
|
|
1690
|
+
const jsFilePath = import_path10.default.join(srcDir, `${name}.js`);
|
|
1691
|
+
const tsFilePath = import_path10.default.join(srcDir, `${name}.ts`);
|
|
1692
|
+
if (!fs.existsSync(jsFilePath)) {
|
|
1693
|
+
console.log(` Skipping ${name}.js \u2014 file not found`);
|
|
1694
|
+
return false;
|
|
1695
|
+
}
|
|
1696
|
+
if (fs.existsSync(tsFilePath)) {
|
|
1697
|
+
console.log(` Skipping ${name}.js \u2014 ${name}.ts already exists`);
|
|
1698
|
+
return false;
|
|
1699
|
+
}
|
|
1700
|
+
const configObj = extractWindowConfig(jsFilePath);
|
|
1701
|
+
if (!configObj) {
|
|
1702
|
+
console.warn(
|
|
1703
|
+
` [${name}.js] Could not locate window.config assignment \u2014 skipping`
|
|
1704
|
+
);
|
|
1705
|
+
return false;
|
|
1706
|
+
}
|
|
1707
|
+
const isProd = name.endsWith(".prod");
|
|
1708
|
+
const exportName = group.exportNames[name];
|
|
1709
|
+
const content = generateTsContent(configObj, exportName, group, isProd);
|
|
1710
|
+
fs.writeFileSync(tsFilePath, content, "utf8");
|
|
1711
|
+
fs.unlinkSync(jsFilePath);
|
|
1712
|
+
console.log(` Converted ${name}.js \u2192 ${name}.ts (export: ${exportName})`);
|
|
1713
|
+
return true;
|
|
1714
|
+
}
|
|
1715
|
+
function isRouteConfig2(obj) {
|
|
1716
|
+
const methodProp = obj.getProperty("method");
|
|
1717
|
+
if (!methodProp || !import_ts_morph10.Node.isPropertyAssignment(methodProp)) return false;
|
|
1718
|
+
const methodInit = methodProp.getInitializer();
|
|
1719
|
+
if (!methodInit) return false;
|
|
1720
|
+
if (import_ts_morph10.Node.isStringLiteral(methodInit)) {
|
|
1721
|
+
if (!HTTP_VERBS2.has(methodInit.getLiteralValue().toUpperCase()))
|
|
1722
|
+
return false;
|
|
1723
|
+
} else if (import_ts_morph10.Node.isArrayLiteralExpression(methodInit)) {
|
|
1724
|
+
const allVerbs = methodInit.getElements().every(
|
|
1725
|
+
(el) => import_ts_morph10.Node.isStringLiteral(el) && HTTP_VERBS2.has(el.getLiteralValue().toUpperCase())
|
|
1726
|
+
);
|
|
1727
|
+
if (!allVerbs) return false;
|
|
1728
|
+
} else {
|
|
1729
|
+
return false;
|
|
1730
|
+
}
|
|
1731
|
+
const pathProp = obj.getProperty("path");
|
|
1732
|
+
if (!pathProp || !import_ts_morph10.Node.isPropertyAssignment(pathProp)) return false;
|
|
1733
|
+
const pathInit = pathProp.getInitializer();
|
|
1734
|
+
return !!pathInit && import_ts_morph10.Node.isStringLiteral(pathInit);
|
|
1735
|
+
}
|
|
1736
|
+
function getRoutePath(obj) {
|
|
1737
|
+
const pathProp = obj.getProperty("path");
|
|
1738
|
+
if (!pathProp || !import_ts_morph10.Node.isPropertyAssignment(pathProp)) return null;
|
|
1739
|
+
const pathInit = pathProp.getInitializer();
|
|
1740
|
+
if (!pathInit || !import_ts_morph10.Node.isStringLiteral(pathInit)) return null;
|
|
1741
|
+
return pathInit.getLiteralValue();
|
|
1742
|
+
}
|
|
1743
|
+
function findHandlerProperty(routeObj) {
|
|
1744
|
+
const directHandler = routeObj.getProperty("handler");
|
|
1745
|
+
if (directHandler && import_ts_morph10.Node.isPropertyAssignment(directHandler)) {
|
|
1746
|
+
return directHandler;
|
|
1747
|
+
}
|
|
1748
|
+
const optionsProp = routeObj.getProperty("options");
|
|
1749
|
+
if (optionsProp && import_ts_morph10.Node.isPropertyAssignment(optionsProp)) {
|
|
1750
|
+
const optionsInit = optionsProp.getInitializer();
|
|
1751
|
+
if (optionsInit && import_ts_morph10.Node.isObjectLiteralExpression(optionsInit)) {
|
|
1752
|
+
const nestedHandler = optionsInit.getProperty("handler");
|
|
1753
|
+
if (nestedHandler && import_ts_morph10.Node.isPropertyAssignment(nestedHandler)) {
|
|
1754
|
+
return nestedHandler;
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
return null;
|
|
1759
|
+
}
|
|
1760
|
+
function ensureConfigImports(sourceFile, group, srcDir) {
|
|
1761
|
+
const routeFileDir = import_path10.default.dirname(sourceFile.getFilePath());
|
|
1762
|
+
for (const name of [group.baseName, group.prodName]) {
|
|
1763
|
+
const exportName = group.exportNames[name];
|
|
1764
|
+
const absoluteConfigPath = import_path10.default.join(srcDir, name);
|
|
1765
|
+
const rel = import_path10.default.relative(routeFileDir, absoluteConfigPath).replace(/\\/g, "/");
|
|
1766
|
+
const moduleSpecifier = rel.startsWith(".") ? rel : `./${rel}`;
|
|
1767
|
+
const alreadyImported = sourceFile.getImportDeclarations().some(
|
|
1768
|
+
(d) => d.getModuleSpecifierValue() === moduleSpecifier || d.getNamedImports().some((ni) => ni.getName() === exportName)
|
|
1769
|
+
);
|
|
1770
|
+
if (!alreadyImported) {
|
|
1771
|
+
sourceFile.addImportDeclaration({
|
|
1772
|
+
moduleSpecifier,
|
|
1773
|
+
namedImports: [exportName]
|
|
1774
|
+
});
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
function updateRouteHandlers(sourceFiles, group, srcDir, relCwd) {
|
|
1779
|
+
const baseExport = group.exportNames[group.baseName];
|
|
1780
|
+
const prodExport = group.exportNames[group.prodName];
|
|
1781
|
+
const newHandlerText = `async (request, h) => {
|
|
1782
|
+
const config =
|
|
1783
|
+
process.env.NODE_ENV === 'production' ? ${prodExport} : ${baseExport}
|
|
1784
|
+
return h
|
|
1785
|
+
.response(\`window.config = \${JSON.stringify(config)}\`)
|
|
1786
|
+
.type('application/javascript')
|
|
1787
|
+
}`;
|
|
1788
|
+
let replacedCount = 0;
|
|
1789
|
+
for (const sourceFile of sourceFiles) {
|
|
1790
|
+
const filePath = sourceFile.getFilePath();
|
|
1791
|
+
const candidates = sourceFile.getDescendantsOfKind(
|
|
1792
|
+
import_ts_morph10.SyntaxKind.ObjectLiteralExpression
|
|
1793
|
+
);
|
|
1794
|
+
for (const obj of candidates) {
|
|
1795
|
+
if (!isRouteConfig2(obj)) continue;
|
|
1796
|
+
if (getRoutePath(obj) !== group.routePath) continue;
|
|
1797
|
+
const handlerProp = findHandlerProperty(obj);
|
|
1798
|
+
if (!handlerProp) {
|
|
1799
|
+
console.warn(
|
|
1800
|
+
` [${relCwd(filePath)}] Found route '${group.routePath}' but could not locate handler property \u2014 skipping`
|
|
1801
|
+
);
|
|
1802
|
+
continue;
|
|
1803
|
+
}
|
|
1804
|
+
handlerProp.setInitializer(newHandlerText);
|
|
1805
|
+
ensureConfigImports(sourceFile, group, srcDir);
|
|
1806
|
+
replacedCount++;
|
|
1807
|
+
console.log(
|
|
1808
|
+
` [${relCwd(filePath)}] Replaced handler for route '${group.routePath}'`
|
|
1809
|
+
);
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
return replacedCount;
|
|
1813
|
+
}
|
|
1814
|
+
function resolveConfigChain(configObj, path12) {
|
|
1815
|
+
let current = configObj;
|
|
1816
|
+
for (const key of path12) {
|
|
1817
|
+
if (!import_ts_morph10.Node.isObjectLiteralExpression(current)) return null;
|
|
1818
|
+
const prop = current.getProperty(key);
|
|
1819
|
+
if (!prop || !import_ts_morph10.Node.isPropertyAssignment(prop)) return null;
|
|
1820
|
+
const initNode = prop.getInitializer();
|
|
1821
|
+
if (!initNode) return null;
|
|
1822
|
+
current = initNode;
|
|
1823
|
+
}
|
|
1824
|
+
return current.getText();
|
|
1825
|
+
}
|
|
1826
|
+
async function main10() {
|
|
1827
|
+
const srcDir = import_path10.default.join(getCwd(), "src");
|
|
1828
|
+
const relCwd = (fp) => import_path10.default.relative(getCwd(), fp);
|
|
1829
|
+
console.log("Phase 1: Converting JS config files to TypeScript...\n");
|
|
1830
|
+
let convertedCount = 0;
|
|
1831
|
+
for (const group of CONFIG_GROUPS) {
|
|
1832
|
+
for (const name of [group.baseName, group.prodName]) {
|
|
1833
|
+
if (convertFile(name, group, srcDir)) {
|
|
1834
|
+
convertedCount++;
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
if (convertedCount === 0) {
|
|
1839
|
+
console.log(" No JS config files needed conversion.\n");
|
|
1840
|
+
} else {
|
|
1841
|
+
console.log(`
|
|
1842
|
+
Converted ${convertedCount} file(s).
|
|
1843
|
+
`);
|
|
1844
|
+
}
|
|
1845
|
+
console.log(
|
|
1846
|
+
"Phase 3: Wrapping applicationConfig with defineApplicationConfig...\n"
|
|
1847
|
+
);
|
|
1848
|
+
const appConfigRelPath = "api/application/application-config.ts";
|
|
1849
|
+
const appConfigAbsPath = import_path10.default.join(srcDir, appConfigRelPath);
|
|
1850
|
+
if (!fs.existsSync(appConfigAbsPath)) {
|
|
1851
|
+
console.log(` Skipping Phase 3 \u2014 ${appConfigRelPath} not found in src/
|
|
1852
|
+
`);
|
|
1853
|
+
} else {
|
|
1854
|
+
const appConfigProject = new import_ts_morph10.Project({
|
|
1855
|
+
tsConfigFilePath: import_path10.default.resolve(srcDir, "../tsconfig.json"),
|
|
1856
|
+
skipAddingFilesFromTsConfig: false
|
|
1857
|
+
});
|
|
1858
|
+
const appConfigFile = appConfigProject.getSourceFile(appConfigAbsPath) ?? appConfigProject.addSourceFileAtPath(appConfigAbsPath);
|
|
1859
|
+
let wrapped = false;
|
|
1860
|
+
for (const varDecl of appConfigFile.getVariableDeclarations()) {
|
|
1861
|
+
if (varDecl.getName() !== "applicationConfig") continue;
|
|
1862
|
+
const init = varDecl.getInitializer();
|
|
1863
|
+
if (!init || !import_ts_morph10.Node.isObjectLiteralExpression(init)) continue;
|
|
1864
|
+
const propsToRemove = init.getProperties().filter((prop) => {
|
|
1865
|
+
if (!import_ts_morph10.Node.isPropertyAssignment(prop)) return false;
|
|
1866
|
+
const name = prop.getNameNode().getText().replace(/^['"]|['"]$/g, "");
|
|
1867
|
+
return !APPLICATION_CONFIG_VALID_KEYS.has(name);
|
|
1868
|
+
});
|
|
1869
|
+
if (propsToRemove.length > 0) {
|
|
1870
|
+
const filesToSaveAfterInlining = /* @__PURE__ */ new Set();
|
|
1871
|
+
for (const removedProp of propsToRemove) {
|
|
1872
|
+
const key = removedProp.getName();
|
|
1873
|
+
for (const sf of appConfigProject.getSourceFiles()) {
|
|
1874
|
+
if (sf.getFilePath() === appConfigAbsPath) continue;
|
|
1875
|
+
if (!sf.getFilePath().includes("/src/")) continue;
|
|
1876
|
+
if (sf.getFilePath().includes("/node_modules/")) continue;
|
|
1877
|
+
let madeReplacement = true;
|
|
1878
|
+
while (madeReplacement) {
|
|
1879
|
+
madeReplacement = false;
|
|
1880
|
+
for (const identNode of sf.getDescendantsOfKind(
|
|
1881
|
+
import_ts_morph10.SyntaxKind.Identifier
|
|
1882
|
+
)) {
|
|
1883
|
+
if (identNode.getText() !== "applicationConfig") continue;
|
|
1884
|
+
let node = identNode;
|
|
1885
|
+
const accessPath = [];
|
|
1886
|
+
while (true) {
|
|
1887
|
+
const parent = node.getParent();
|
|
1888
|
+
if (!import_ts_morph10.Node.isPropertyAccessExpression(parent)) break;
|
|
1889
|
+
if (parent.getExpression() !== node) break;
|
|
1890
|
+
accessPath.push(parent.getName());
|
|
1891
|
+
node = parent;
|
|
1892
|
+
}
|
|
1893
|
+
if (accessPath.length === 0 || accessPath[0] !== key) continue;
|
|
1894
|
+
const resolvedValue = resolveConfigChain(init, accessPath);
|
|
1895
|
+
if (resolvedValue === null) {
|
|
1896
|
+
console.log(
|
|
1897
|
+
` Cannot resolve applicationConfig.${accessPath.join(".")} \u2014 skipping inline replacement`
|
|
1898
|
+
);
|
|
1899
|
+
continue;
|
|
1900
|
+
}
|
|
1901
|
+
node.replaceWithText(resolvedValue);
|
|
1902
|
+
console.log(
|
|
1903
|
+
` Inlined applicationConfig.${accessPath.join(".")} \u2192 ${resolvedValue} in ${import_path10.default.relative(getCwd(), sf.getFilePath())}`
|
|
1904
|
+
);
|
|
1905
|
+
filesToSaveAfterInlining.add(sf);
|
|
1906
|
+
madeReplacement = true;
|
|
1907
|
+
break;
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
for (const sf of Array.from(filesToSaveAfterInlining)) {
|
|
1913
|
+
await sf.save();
|
|
1914
|
+
console.log(
|
|
1915
|
+
` Saved (inlined): ${import_path10.default.relative(getCwd(), sf.getFilePath())}`
|
|
1916
|
+
);
|
|
1917
|
+
}
|
|
1918
|
+
for (const prop of [...propsToRemove].reverse()) {
|
|
1919
|
+
const propName = prop.getName();
|
|
1920
|
+
console.log(
|
|
1921
|
+
` Removing unknown key '${propName}' from applicationConfig (not in ApplicationConfig schema)`
|
|
1922
|
+
);
|
|
1923
|
+
prop.remove();
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
varDecl.setInitializer(`defineApplicationConfig(${init.getText()})`);
|
|
1927
|
+
const TOOLKIT_MODULE = "@opencrvs/toolkit/application-config";
|
|
1928
|
+
const existing = appConfigFile.getImportDeclaration(
|
|
1929
|
+
(d) => d.getModuleSpecifierValue() === TOOLKIT_MODULE
|
|
1930
|
+
);
|
|
1931
|
+
if (existing) {
|
|
1932
|
+
const names = new Set(
|
|
1933
|
+
existing.getNamedImports().map((ni) => ni.getName())
|
|
1934
|
+
);
|
|
1935
|
+
if (!names.has("defineApplicationConfig")) {
|
|
1936
|
+
existing.addNamedImport("defineApplicationConfig");
|
|
1937
|
+
}
|
|
1938
|
+
} else {
|
|
1939
|
+
appConfigFile.addImportDeclaration({
|
|
1940
|
+
moduleSpecifier: TOOLKIT_MODULE,
|
|
1941
|
+
namedImports: ["defineApplicationConfig"]
|
|
1942
|
+
});
|
|
1943
|
+
}
|
|
1944
|
+
wrapped = true;
|
|
1945
|
+
console.log(
|
|
1946
|
+
` Wrapped applicationConfig with defineApplicationConfig in ${appConfigRelPath}`
|
|
1947
|
+
);
|
|
1948
|
+
break;
|
|
1949
|
+
}
|
|
1950
|
+
if (!wrapped) {
|
|
1951
|
+
console.log(
|
|
1952
|
+
` Skipping Phase 3 \u2014 applicationConfig plain object not found (already wrapped?)
|
|
1953
|
+
`
|
|
1954
|
+
);
|
|
1955
|
+
} else {
|
|
1956
|
+
await appConfigFile.save();
|
|
1957
|
+
console.log(` Saved: ${appConfigRelPath}
|
|
1958
|
+
`);
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
console.log("Phase 2: Updating Hapi route handlers...\n");
|
|
1962
|
+
const project = new import_ts_morph10.Project({
|
|
1963
|
+
tsConfigFilePath: import_path10.default.resolve(srcDir, "../tsconfig.json"),
|
|
1964
|
+
skipAddingFilesFromTsConfig: false
|
|
1965
|
+
});
|
|
1966
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
1967
|
+
const fp = sf.getFilePath();
|
|
1968
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
1969
|
+
});
|
|
1970
|
+
console.log(` Analysing ${sourceFiles.length} source file(s).
|
|
1971
|
+
`);
|
|
1972
|
+
let totalReplaced = 0;
|
|
1973
|
+
for (const group of CONFIG_GROUPS) {
|
|
1974
|
+
totalReplaced += updateRouteHandlers(sourceFiles, group, srcDir, relCwd);
|
|
1975
|
+
}
|
|
1976
|
+
if (totalReplaced === 0) {
|
|
1977
|
+
console.log(" No route handlers matched \u2014 nothing to update in Phase 2.\n");
|
|
1978
|
+
}
|
|
1979
|
+
const modified = sourceFiles.filter((sf) => sf.wasForgotten() === false);
|
|
1980
|
+
const toSave = modified.filter(
|
|
1981
|
+
(sf) => sf.getDescendantsOfKind(import_ts_morph10.SyntaxKind.ObjectLiteralExpression).length > 0
|
|
1982
|
+
);
|
|
1983
|
+
let savedCount = 0;
|
|
1984
|
+
for (const sf of project.getSourceFiles()) {
|
|
1985
|
+
if (sf.isSaved()) continue;
|
|
1986
|
+
await sf.save();
|
|
1987
|
+
console.log(` Saved: ${relCwd(sf.getFilePath())}`);
|
|
1988
|
+
savedCount++;
|
|
1989
|
+
}
|
|
1990
|
+
if (savedCount === 0 && totalReplaced === 0) {
|
|
1991
|
+
console.log("Nothing was changed.");
|
|
1992
|
+
return;
|
|
1993
|
+
}
|
|
1994
|
+
console.log(
|
|
1995
|
+
`
|
|
1996
|
+
Done. Converted ${convertedCount} config file(s), replaced ${totalReplaced} route handler(s).`
|
|
1997
|
+
);
|
|
1998
|
+
}
|
|
1999
|
+
|
|
2000
|
+
// src/migrations/v2.0/migrate-scopes.ts
|
|
2001
|
+
var import_ts_morph11 = require("ts-morph");
|
|
2002
|
+
var import_path11 = __toESM(require("path"));
|
|
2003
|
+
var import_commons = require("@opencrvs/commons");
|
|
2004
|
+
var ROLES_FILE_RELATIVE_PATH = "src/data-seeding/roles/roles.ts";
|
|
2005
|
+
var SCOPES_PROPERTY_NAME = "scopes";
|
|
2006
|
+
var TOOLKIT_SCOPES_MODULE = "@opencrvs/toolkit/scopes";
|
|
2007
|
+
var DEFINE_SCOPES_IMPORT_NAME = "defineScopes";
|
|
2008
|
+
var DEFINE_ROLES_IMPORT_NAME = "defineRoles";
|
|
2009
|
+
function resolveScopeKeyFromElementAccess(element) {
|
|
2010
|
+
if (import_ts_morph11.Node.isPropertyAccessExpression(element) && element.getExpression().getText() === "SCOPES") {
|
|
2011
|
+
return element.getName();
|
|
2012
|
+
}
|
|
2013
|
+
if (import_ts_morph11.Node.isElementAccessExpression(element) && element.getExpression().getText() === "SCOPES") {
|
|
2014
|
+
const argumentExpression = element.getArgumentExpression();
|
|
2015
|
+
if (argumentExpression && (import_ts_morph11.Node.isStringLiteral(argumentExpression) || import_ts_morph11.Node.isNoSubstitutionTemplateLiteral(argumentExpression))) {
|
|
2016
|
+
return argumentExpression.getLiteralValue();
|
|
2017
|
+
}
|
|
2018
|
+
}
|
|
2019
|
+
return null;
|
|
2020
|
+
}
|
|
2021
|
+
function resolveLegacyScopeFromElement(element) {
|
|
2022
|
+
if (import_ts_morph11.Node.isStringLiteral(element) || import_ts_morph11.Node.isNoSubstitutionTemplateLiteral(element)) {
|
|
2023
|
+
return element.getLiteralValue();
|
|
2024
|
+
}
|
|
2025
|
+
const scopeKey = resolveScopeKeyFromElementAccess(element);
|
|
2026
|
+
if (scopeKey) {
|
|
2027
|
+
const scopeValue = import_commons.SCOPES[scopeKey];
|
|
2028
|
+
return typeof scopeValue === "string" ? scopeValue : null;
|
|
2029
|
+
}
|
|
2030
|
+
const expressionType = element.getType();
|
|
2031
|
+
if (expressionType.isStringLiteral()) {
|
|
2032
|
+
const literalValue = expressionType.getLiteralValue();
|
|
2033
|
+
return typeof literalValue === "string" ? literalValue : null;
|
|
2034
|
+
}
|
|
2035
|
+
return null;
|
|
2036
|
+
}
|
|
2037
|
+
function migrateScopesArrays(rolesFilePath, project) {
|
|
2038
|
+
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
2039
|
+
if (!sourceFile) return { migratedCount: 0, removedCount: 0 };
|
|
2040
|
+
let migratedCount = 0;
|
|
2041
|
+
let removedCount = 0;
|
|
2042
|
+
const scopesProperties = sourceFile.getDescendantsOfKind(import_ts_morph11.SyntaxKind.PropertyAssignment).filter((prop) => prop.getName() === SCOPES_PROPERTY_NAME);
|
|
2043
|
+
for (const scopesProp of scopesProperties) {
|
|
2044
|
+
const initializer = scopesProp.getInitializer();
|
|
2045
|
+
if (!initializer || !import_ts_morph11.Node.isArrayLiteralExpression(initializer)) continue;
|
|
2046
|
+
const elements = initializer.getElements();
|
|
2047
|
+
for (let index = elements.length - 1; index >= 0; index--) {
|
|
2048
|
+
const element = elements[index];
|
|
2049
|
+
if (!import_ts_morph11.Node.isExpression(element)) continue;
|
|
2050
|
+
const scopeKey = resolveScopeKeyFromElementAccess(element);
|
|
2051
|
+
if (scopeKey && !(scopeKey in import_commons.SCOPES)) {
|
|
2052
|
+
console.warn(
|
|
2053
|
+
` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Removing unknown scope reference: SCOPES.${scopeKey}`
|
|
2054
|
+
);
|
|
2055
|
+
initializer.removeElement(index);
|
|
2056
|
+
removedCount++;
|
|
2057
|
+
continue;
|
|
2058
|
+
}
|
|
2059
|
+
const legacyScope = resolveLegacyScopeFromElement(element);
|
|
2060
|
+
if (!legacyScope) {
|
|
2061
|
+
console.warn(
|
|
2062
|
+
` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Skipping non-literal scope expression: ${element.getText()}`
|
|
2063
|
+
);
|
|
2064
|
+
continue;
|
|
2065
|
+
}
|
|
2066
|
+
try {
|
|
2067
|
+
const migratedScope = (0, import_commons.legacyScopeToV2Scope)(legacyScope);
|
|
2068
|
+
const scope = (0, import_commons.decodeScope)(migratedScope);
|
|
2069
|
+
if (!scope) {
|
|
2070
|
+
console.warn(
|
|
2071
|
+
` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Could not decode migrated scope '${migratedScope}'.`
|
|
2072
|
+
);
|
|
2073
|
+
continue;
|
|
2074
|
+
}
|
|
2075
|
+
element.replaceWithText(JSON.stringify(scope));
|
|
2076
|
+
migratedCount++;
|
|
2077
|
+
} catch (error) {
|
|
2078
|
+
console.warn(
|
|
2079
|
+
` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`
|
|
2080
|
+
);
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2084
|
+
if (removedCount > 0) {
|
|
2085
|
+
console.log(
|
|
2086
|
+
` Removed ${removedCount} unknown SCOPES reference(s) from '${import_path11.default.relative(getCwd(), rolesFilePath)}'.`
|
|
2087
|
+
);
|
|
2088
|
+
}
|
|
2089
|
+
return { migratedCount, removedCount };
|
|
2090
|
+
}
|
|
2091
|
+
function ensureScopesHelpersImport(rolesFilePath, project) {
|
|
2092
|
+
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
2093
|
+
if (!sourceFile) return false;
|
|
2094
|
+
const existingImport = sourceFile.getImportDeclaration(
|
|
2095
|
+
(decl) => decl.getModuleSpecifierValue() === TOOLKIT_SCOPES_MODULE
|
|
2096
|
+
);
|
|
2097
|
+
let changed = false;
|
|
2098
|
+
if (existingImport) {
|
|
2099
|
+
const hasDefineScopesImport = existingImport.getNamedImports().some((ni) => ni.getName() === DEFINE_SCOPES_IMPORT_NAME);
|
|
2100
|
+
const hasDefineRolesImport = existingImport.getNamedImports().some((ni) => ni.getName() === DEFINE_ROLES_IMPORT_NAME);
|
|
2101
|
+
if (!hasDefineScopesImport) {
|
|
2102
|
+
existingImport.addNamedImport(DEFINE_SCOPES_IMPORT_NAME);
|
|
2103
|
+
changed = true;
|
|
2104
|
+
}
|
|
2105
|
+
if (!hasDefineRolesImport) {
|
|
2106
|
+
existingImport.addNamedImport(DEFINE_ROLES_IMPORT_NAME);
|
|
2107
|
+
changed = true;
|
|
2108
|
+
}
|
|
2109
|
+
const encodeScopeImport = existingImport.getNamedImports().find((ni) => ni.getName() === "encodeScope");
|
|
2110
|
+
if (encodeScopeImport) {
|
|
2111
|
+
encodeScopeImport.remove();
|
|
2112
|
+
changed = true;
|
|
2113
|
+
}
|
|
2114
|
+
return changed;
|
|
2115
|
+
}
|
|
2116
|
+
sourceFile.addImportDeclaration({
|
|
2117
|
+
moduleSpecifier: TOOLKIT_SCOPES_MODULE,
|
|
2118
|
+
namedImports: [DEFINE_SCOPES_IMPORT_NAME, DEFINE_ROLES_IMPORT_NAME]
|
|
2119
|
+
});
|
|
2120
|
+
return true;
|
|
2121
|
+
}
|
|
2122
|
+
function wrapScopesArraysWithDefineScopes(rolesFilePath, project) {
|
|
2123
|
+
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
2124
|
+
if (!sourceFile) return 0;
|
|
2125
|
+
let wrappedCount = 0;
|
|
2126
|
+
const scopesProperties = sourceFile.getDescendantsOfKind(import_ts_morph11.SyntaxKind.PropertyAssignment).filter((prop) => prop.getName() === SCOPES_PROPERTY_NAME);
|
|
2127
|
+
for (const scopesProp of scopesProperties) {
|
|
2128
|
+
const initializer = scopesProp.getInitializer();
|
|
2129
|
+
if (!initializer) continue;
|
|
2130
|
+
if (import_ts_morph11.Node.isCallExpression(initializer) && initializer.getExpression().getText() === DEFINE_SCOPES_IMPORT_NAME) {
|
|
2131
|
+
continue;
|
|
2132
|
+
}
|
|
2133
|
+
if (!import_ts_morph11.Node.isArrayLiteralExpression(initializer)) continue;
|
|
2134
|
+
scopesProp.setInitializer(
|
|
2135
|
+
`${DEFINE_SCOPES_IMPORT_NAME}(${initializer.getText()})`
|
|
2136
|
+
);
|
|
2137
|
+
wrappedCount++;
|
|
2138
|
+
}
|
|
2139
|
+
return wrappedCount;
|
|
2140
|
+
}
|
|
2141
|
+
function wrapRolesWithDefineRoles(rolesFilePath, project) {
|
|
2142
|
+
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
2143
|
+
if (!sourceFile) return false;
|
|
2144
|
+
const rolesDeclaration = sourceFile.getVariableDeclaration("roles");
|
|
2145
|
+
if (!rolesDeclaration) return false;
|
|
2146
|
+
const initializer = rolesDeclaration.getInitializer();
|
|
2147
|
+
if (!initializer) return false;
|
|
2148
|
+
if (import_ts_morph11.Node.isCallExpression(initializer) && initializer.getExpression().getText() === DEFINE_ROLES_IMPORT_NAME) {
|
|
2149
|
+
return false;
|
|
2150
|
+
}
|
|
2151
|
+
if (!import_ts_morph11.Node.isArrayLiteralExpression(initializer)) return false;
|
|
2152
|
+
const typeNode = rolesDeclaration.getTypeNode();
|
|
2153
|
+
if (typeNode?.getText().includes("Role")) {
|
|
2154
|
+
rolesDeclaration.removeType();
|
|
2155
|
+
}
|
|
2156
|
+
rolesDeclaration.setInitializer(
|
|
2157
|
+
`${DEFINE_ROLES_IMPORT_NAME}(${initializer.getText()})`
|
|
2158
|
+
);
|
|
2159
|
+
return true;
|
|
2160
|
+
}
|
|
2161
|
+
function pruneNamedImportIfUnused(sourceFile, moduleSpecifier, importName) {
|
|
2162
|
+
const importDeclaration = sourceFile.getImportDeclaration(
|
|
2163
|
+
(decl) => decl.getModuleSpecifierValue() === moduleSpecifier
|
|
2164
|
+
);
|
|
2165
|
+
if (!importDeclaration) return false;
|
|
2166
|
+
const namedImport = importDeclaration.getNamedImports().find((ni) => ni.getName() === importName);
|
|
2167
|
+
if (!namedImport) return false;
|
|
2168
|
+
const references = sourceFile.getDescendantsOfKind(import_ts_morph11.SyntaxKind.Identifier).filter(
|
|
2169
|
+
(identifier) => identifier.getText() === importName && !import_ts_morph11.Node.isImportSpecifier(identifier.getParent())
|
|
2170
|
+
);
|
|
2171
|
+
if (references.length > 0) {
|
|
2172
|
+
return false;
|
|
2173
|
+
}
|
|
2174
|
+
namedImport.remove();
|
|
2175
|
+
if (importDeclaration.getNamedImports().length === 0 && !importDeclaration.getDefaultImport() && !importDeclaration.getNamespaceImport()) {
|
|
2176
|
+
importDeclaration.remove();
|
|
2177
|
+
}
|
|
2178
|
+
return true;
|
|
2179
|
+
}
|
|
2180
|
+
function removeRoleTypeDefinitionAndUnusedImports(rolesFilePath, project) {
|
|
2181
|
+
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
2182
|
+
if (!sourceFile) return false;
|
|
2183
|
+
let removed = false;
|
|
2184
|
+
const roleTypeAlias = sourceFile.getTypeAlias("Role");
|
|
2185
|
+
if (roleTypeAlias) {
|
|
2186
|
+
roleTypeAlias.remove();
|
|
2187
|
+
removed = true;
|
|
2188
|
+
}
|
|
2189
|
+
const roleInterface = sourceFile.getInterface("Role");
|
|
2190
|
+
if (roleInterface) {
|
|
2191
|
+
roleInterface.remove();
|
|
2192
|
+
removed = true;
|
|
2193
|
+
}
|
|
2194
|
+
const removedScopeImport = pruneNamedImportIfUnused(
|
|
2195
|
+
sourceFile,
|
|
2196
|
+
TOOLKIT_SCOPES_MODULE,
|
|
2197
|
+
"Scope"
|
|
2198
|
+
);
|
|
2199
|
+
const removedMessageDescriptorImport = pruneNamedImportIfUnused(
|
|
2200
|
+
sourceFile,
|
|
2201
|
+
"react-intl",
|
|
2202
|
+
"MessageDescriptor"
|
|
2203
|
+
);
|
|
2204
|
+
removed = removed || removedScopeImport || removedMessageDescriptorImport;
|
|
2205
|
+
return removed;
|
|
2206
|
+
}
|
|
2207
|
+
async function main11() {
|
|
2208
|
+
const cwd2 = getCwd();
|
|
2209
|
+
const srcDir = import_path11.default.join(cwd2, "src");
|
|
2210
|
+
const rolesFilePath = import_path11.default.join(cwd2, ROLES_FILE_RELATIVE_PATH);
|
|
2211
|
+
console.log(`Scanning roles scopes in: ${rolesFilePath}`);
|
|
2212
|
+
const project = new import_ts_morph11.Project({
|
|
2213
|
+
tsConfigFilePath: import_path11.default.resolve(srcDir, "../tsconfig.json"),
|
|
2214
|
+
skipAddingFilesFromTsConfig: false
|
|
2215
|
+
});
|
|
2216
|
+
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
2217
|
+
if (!sourceFile) {
|
|
2218
|
+
console.log(
|
|
2219
|
+
`No roles file found at '${ROLES_FILE_RELATIVE_PATH}'. Nothing to do.`
|
|
2220
|
+
);
|
|
2221
|
+
return;
|
|
2222
|
+
}
|
|
2223
|
+
const importChanged = ensureScopesHelpersImport(rolesFilePath, project);
|
|
2224
|
+
const { migratedCount, removedCount } = migrateScopesArrays(
|
|
2225
|
+
rolesFilePath,
|
|
2226
|
+
project
|
|
2227
|
+
);
|
|
2228
|
+
const wrappedScopesCount = wrapScopesArraysWithDefineScopes(
|
|
2229
|
+
rolesFilePath,
|
|
2230
|
+
project
|
|
2231
|
+
);
|
|
2232
|
+
const wrappedRoles = wrapRolesWithDefineRoles(rolesFilePath, project);
|
|
2233
|
+
const removedRoleType = removeRoleTypeDefinitionAndUnusedImports(
|
|
2234
|
+
rolesFilePath,
|
|
2235
|
+
project
|
|
2236
|
+
);
|
|
2237
|
+
if (migratedCount === 0 && removedCount === 0 && wrappedScopesCount === 0 && !wrappedRoles && !removedRoleType && !importChanged) {
|
|
2238
|
+
console.log("No migratable literal scopes found. Nothing to do.");
|
|
2239
|
+
return;
|
|
2240
|
+
}
|
|
2241
|
+
await sourceFile.save();
|
|
2242
|
+
console.log(
|
|
2243
|
+
`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." : "."}`
|
|
2244
|
+
);
|
|
2245
|
+
}
|
|
2246
|
+
|
|
2247
|
+
// src/migrations/v2.0/remove-deprecated-imports.ts
|
|
2248
|
+
var import_ts_morph12 = require("ts-morph");
|
|
2249
|
+
var import_path12 = __toESM(require("path"));
|
|
2250
|
+
var DEPRECATED_IMPORT = "SCOPES";
|
|
2251
|
+
var TARGET_MODULES = /* @__PURE__ */ new Set([
|
|
2252
|
+
"@opencrvs/toolkit/scopes",
|
|
2253
|
+
"@opencrvs/toolkit"
|
|
2254
|
+
]);
|
|
2255
|
+
function processFile10(filePath, project) {
|
|
2256
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
2257
|
+
if (!sourceFile) return 0;
|
|
2258
|
+
let removedCount = 0;
|
|
2259
|
+
const importDecls = sourceFile.getImportDeclarations().filter((decl) => TARGET_MODULES.has(decl.getModuleSpecifierValue()));
|
|
2260
|
+
for (const decl of importDecls) {
|
|
2261
|
+
const matchingNamedImports = decl.getNamedImports().filter((ni) => ni.getName() === DEPRECATED_IMPORT);
|
|
2262
|
+
if (matchingNamedImports.length === 0) continue;
|
|
2263
|
+
for (const namedImport of matchingNamedImports) {
|
|
2264
|
+
namedImport.remove();
|
|
2265
|
+
removedCount++;
|
|
2266
|
+
}
|
|
2267
|
+
const hasAnyNamedImportsLeft = decl.getNamedImports().length > 0;
|
|
2268
|
+
const hasDefaultImport = !!decl.getDefaultImport();
|
|
2269
|
+
const hasNamespaceImport = !!decl.getNamespaceImport();
|
|
2270
|
+
if (!hasAnyNamedImportsLeft && !hasDefaultImport && !hasNamespaceImport) {
|
|
2271
|
+
decl.remove();
|
|
2272
|
+
}
|
|
2273
|
+
console.log(
|
|
2274
|
+
` [${import_path12.default.relative(getCwd(), filePath)}] Removed ${matchingNamedImports.length} deprecated '${DEPRECATED_IMPORT}' import(s) from '${decl.getModuleSpecifierValue()}'`
|
|
2275
|
+
);
|
|
2276
|
+
}
|
|
2277
|
+
return removedCount;
|
|
2278
|
+
}
|
|
2279
|
+
async function main12() {
|
|
2280
|
+
const srcDir = import_path12.default.join(getCwd(), "src");
|
|
2281
|
+
console.log(`Scanning for deprecated imports in: ${srcDir}
|
|
2282
|
+
`);
|
|
2283
|
+
const project = new import_ts_morph12.Project({
|
|
2284
|
+
tsConfigFilePath: import_path12.default.resolve(srcDir, "../tsconfig.json"),
|
|
2285
|
+
skipAddingFilesFromTsConfig: false
|
|
2286
|
+
});
|
|
2287
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
2288
|
+
const fp = sf.getFilePath();
|
|
2289
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
2290
|
+
});
|
|
2291
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
2292
|
+
`);
|
|
2293
|
+
let totalRemoved = 0;
|
|
2294
|
+
const modifiedFiles = [];
|
|
2295
|
+
for (const sourceFile of sourceFiles) {
|
|
2296
|
+
const filePath = sourceFile.getFilePath();
|
|
2297
|
+
const removed = processFile10(filePath, project);
|
|
2298
|
+
if (removed > 0) {
|
|
2299
|
+
totalRemoved += removed;
|
|
2300
|
+
modifiedFiles.push(filePath);
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
2303
|
+
if (modifiedFiles.length === 0) {
|
|
2304
|
+
console.log("No deprecated imports found. Nothing to do.");
|
|
2305
|
+
return;
|
|
2306
|
+
}
|
|
2307
|
+
console.log(`
|
|
2308
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
2309
|
+
for (const filePath of modifiedFiles) {
|
|
2310
|
+
await project.getSourceFileOrThrow(filePath).save();
|
|
2311
|
+
console.log(` Saved: ${import_path12.default.relative(getCwd(), filePath)}`);
|
|
2312
|
+
}
|
|
2313
|
+
console.log(`
|
|
2314
|
+
Done. Removed ${totalRemoved} deprecated import(s).`);
|
|
2315
|
+
}
|
|
2316
|
+
|
|
2317
|
+
// src/migrations/v2.0/index.ts
|
|
2318
|
+
var cwd;
|
|
2319
|
+
function getCwd() {
|
|
2320
|
+
if (!cwd) {
|
|
2321
|
+
throw new Error("Country config working directory not set.");
|
|
2322
|
+
}
|
|
2323
|
+
return cwd;
|
|
2324
|
+
}
|
|
2325
|
+
async function runUpgrade(ccwd) {
|
|
2326
|
+
if (ccwd) {
|
|
2327
|
+
console.log("Country config working directory:", ccwd);
|
|
2328
|
+
cwd = ccwd;
|
|
2329
|
+
}
|
|
2330
|
+
if (!ccwd) {
|
|
2331
|
+
console.log(
|
|
2332
|
+
"Will use current working directory as country config working directory."
|
|
2333
|
+
);
|
|
2334
|
+
cwd = process.cwd();
|
|
2335
|
+
}
|
|
2336
|
+
await main();
|
|
2337
|
+
await main2();
|
|
2338
|
+
await main3();
|
|
2339
|
+
await main4();
|
|
2340
|
+
await main5();
|
|
2341
|
+
await main6();
|
|
2342
|
+
await main7();
|
|
2343
|
+
await main8();
|
|
2344
|
+
await main9();
|
|
2345
|
+
await main10();
|
|
2346
|
+
await main11();
|
|
2347
|
+
await main12();
|
|
2348
|
+
}
|
|
2349
|
+
|
|
2350
|
+
// src/cli.ts
|
|
2351
|
+
var args = process.argv.slice(2);
|
|
2352
|
+
var USAGE = `
|
|
2353
|
+
Usage: opencrvs <command>
|
|
2354
|
+
|
|
2355
|
+
Commands:
|
|
2356
|
+
environment init Initialise a new environment
|
|
2357
|
+
upgrade Upgrade an existing environment
|
|
2358
|
+
check-translations Check translation files for completeness
|
|
2359
|
+
|
|
2360
|
+
Run 'opencrvs <command> --help' for more information on a command.
|
|
2361
|
+
`.trim();
|
|
2362
|
+
function main13() {
|
|
2363
|
+
const command = args[0];
|
|
2364
|
+
if (!command || command === "--help" || command === "-h") {
|
|
2365
|
+
console.log(USAGE);
|
|
2366
|
+
process.exit(0);
|
|
2367
|
+
}
|
|
2368
|
+
switch (command) {
|
|
2369
|
+
case "environment":
|
|
2370
|
+
return handleEnvironment();
|
|
2371
|
+
case "upgrade":
|
|
2372
|
+
return handleUpgrade();
|
|
2373
|
+
case "check-translations":
|
|
2374
|
+
return handleCheckTranslations();
|
|
2375
|
+
default:
|
|
2376
|
+
console.error(`Unknown command: ${command}
|
|
2377
|
+
`);
|
|
2378
|
+
console.log(USAGE);
|
|
2379
|
+
process.exit(1);
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
function handleEnvironment() {
|
|
2383
|
+
const subcommand = args[1];
|
|
2384
|
+
if (!subcommand || subcommand === "--help" || subcommand === "-h") {
|
|
2385
|
+
console.log(
|
|
2386
|
+
`
|
|
2387
|
+
Usage: opencrvs environment <subcommand>
|
|
2388
|
+
|
|
2389
|
+
Subcommands:
|
|
2390
|
+
init Initialise a new environment
|
|
2391
|
+
`.trim()
|
|
2392
|
+
);
|
|
2393
|
+
process.exit(0);
|
|
2394
|
+
}
|
|
2395
|
+
switch (subcommand) {
|
|
2396
|
+
case "init":
|
|
2397
|
+
console.log("Initialising environment...");
|
|
2398
|
+
console.warn("This command is not implemented yet!");
|
|
2399
|
+
process.exit(1);
|
|
2400
|
+
break;
|
|
2401
|
+
default:
|
|
2402
|
+
console.error(`Unknown subcommand: environment ${subcommand}`);
|
|
2403
|
+
process.exit(1);
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
async function handleUpgrade() {
|
|
2407
|
+
console.log("Initiating upgrade...");
|
|
2408
|
+
try {
|
|
2409
|
+
const pathToCountryconfig = args[1];
|
|
2410
|
+
await runUpgrade(pathToCountryconfig);
|
|
2411
|
+
console.log("Upgrade completed successfully!");
|
|
2412
|
+
} catch (error) {
|
|
2413
|
+
console.error("Upgrade failed:", error);
|
|
2414
|
+
process.exit(1);
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
function handleCheckTranslations() {
|
|
2418
|
+
console.log("Checking translations...");
|
|
2419
|
+
console.warn("This command is not implemented yet!");
|
|
2420
|
+
process.exit(1);
|
|
2421
|
+
}
|
|
2422
|
+
main13();
|