@opencrvs/toolkit 2.0.0-rc.754b1d1 → 2.0.0-rc.764c76e
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/dist/application-config/index.js +11 -39
- package/dist/cli.js +317 -1656
- package/dist/commons/api/router.d.ts +54 -55
- package/dist/commons/application-config/index.d.ts +4 -16
- package/dist/commons/conditionals/conditionals.d.ts +3 -3
- package/dist/commons/events/FieldConfig.d.ts +0 -5
- package/dist/commons/events/locations.d.ts +1 -17
- package/dist/conditionals/index.js +7 -35
- package/dist/events/index.js +7 -73
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -1
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +39 -63
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts +0 -19
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
- package/dist/migrations/v2.0/checkout-upstream-files.js +13 -17
- package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -1
- package/dist/migrations/v2.0/convert-config-files-to-ts.js +5 -4
- package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -1
- package/dist/migrations/v2.0/convert-paragraph-to-heading.js +5 -4
- package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -1
- package/dist/migrations/v2.0/create-events-index.js +2 -1
- package/dist/migrations/v2.0/index.d.ts +4 -8
- package/dist/migrations/v2.0/index.d.ts.map +1 -1
- package/dist/migrations/v2.0/index.js +314 -1624
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -1
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +7 -95
- package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -1
- package/dist/migrations/v2.0/migrate-scopes.js +7 -6
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -1
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +4 -3
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -1
- package/dist/migrations/v2.0/migrate-workqueue-configs.js +4 -3
- package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-delete-actions.js +4 -3
- package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-demo-scope.js +3 -2
- package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-deprecated-imports.js +4 -3
- package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-hearth-migrations.js +2 -1
- package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-pending-certification-flag.js +4 -3
- package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-review-from-register-action.js +4 -3
- package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -1
- package/dist/migrations/v2.0/rename-api-paths.js +4 -3
- package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -1
- package/dist/migrations/v2.0/rename-location-parent-id.js +4 -3
- package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -1
- package/dist/migrations/v2.0/simplify-analytics-precalculations.js +2 -1
- package/dist/notification/index.js +7 -35
- package/dist/scopes/index.d.ts +10 -82
- package/dist/scopes/index.js +8 -41
- package/opencrvs-toolkit-2.0.0-rc.764c76e.tgz +0 -0
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +0 -3
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +0 -1
- package/dist/migrations/v2.0/add-resend-invite-notification.js +0 -373
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +0 -3
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +0 -1
- package/dist/migrations/v2.0/delete-infrastructure-directory.js +0 -77
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +0 -3
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +0 -1
- package/dist/migrations/v2.0/merge-infrastructure-directory.js +0 -221
- package/dist/migrations/v2.0/migrate-application-config-url.d.ts +0 -3
- package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +0 -1
- package/dist/migrations/v2.0/migrate-application-config-url.js +0 -342
- package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +0 -3
- package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-fhir-url-helpers.js +0 -163
- package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +0 -3
- package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-old-statistics-service.js +0 -356
- package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +0 -3
- package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-unused-environment-variables.js +0 -186
- package/dist/migrations/v2.0/update-package-json.d.ts +0 -3
- package/dist/migrations/v2.0/update-package-json.d.ts.map +0 -1
- package/dist/migrations/v2.0/update-package-json.js +0 -105
- package/opencrvs-toolkit-2.0.0-rc.754b1d1.tgz +0 -0
package/dist/cli.js
CHANGED
|
@@ -91,7 +91,7 @@ function processFile(filePath, project) {
|
|
|
91
91
|
if (wasRemoved) {
|
|
92
92
|
removedCount++;
|
|
93
93
|
console.log(
|
|
94
|
-
` [${import_path.default.relative(
|
|
94
|
+
` [${import_path.default.relative(getCwd(), filePath)}] Removed 'review' from REGISTER action`
|
|
95
95
|
);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
@@ -99,7 +99,7 @@ function processFile(filePath, project) {
|
|
|
99
99
|
return removedCount;
|
|
100
100
|
}
|
|
101
101
|
async function main() {
|
|
102
|
-
const srcDir = import_path.default.join(
|
|
102
|
+
const srcDir = import_path.default.join(getCwd(), "src");
|
|
103
103
|
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
104
104
|
`);
|
|
105
105
|
const project = new import_ts_morph.Project({
|
|
@@ -135,7 +135,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
135
135
|
for (const filePath of modifiedFiles) {
|
|
136
136
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
137
137
|
await sourceFile.save();
|
|
138
|
-
console.log(` Saved: ${import_path.default.relative(
|
|
138
|
+
console.log(` Saved: ${import_path.default.relative(getCwd(), filePath)}`);
|
|
139
139
|
}
|
|
140
140
|
console.log(
|
|
141
141
|
`
|
|
@@ -178,8 +178,6 @@ function ensureImports(sourceFile) {
|
|
|
178
178
|
var DEFINE_CONFIG_NAME2 = "defineConfig";
|
|
179
179
|
var ACTIONS_PROPERTY_NAME2 = "actions";
|
|
180
180
|
var TYPE_PROPERTY_NAME2 = "type";
|
|
181
|
-
var ID_PROPERTY_NAME = "id";
|
|
182
|
-
var FLAGS_PROPERTY_NAME = "flags";
|
|
183
181
|
var CUSTOM_ACTION_TYPE_PROPERTY_NAME = "customActionType";
|
|
184
182
|
var AUDIT_HISTORY_LABEL_PROPERTY_NAME = "auditHistoryLabel";
|
|
185
183
|
var DEDUPLICATION_PROPERTY_NAME = "deduplication";
|
|
@@ -189,12 +187,9 @@ var FORM_PROPERTY_NAME = "form";
|
|
|
189
187
|
var ACTION_TYPE_ENUM_NAME = "ActionType";
|
|
190
188
|
var VALIDATE_MEMBER_NAME = "VALIDATE";
|
|
191
189
|
var CUSTOM_MEMBER_NAME = "CUSTOM";
|
|
192
|
-
var REGISTER_MEMBER_NAME2 = "REGISTER";
|
|
193
190
|
var VALIDATE_STRING_LITERAL = "VALIDATE";
|
|
194
191
|
var CUSTOM_STRING_LITERAL = "CUSTOM";
|
|
195
|
-
var REGISTER_STRING_LITERAL2 = "REGISTER";
|
|
196
192
|
var VALIDATE_DECLARATION_VALUE = "VALIDATE_DECLARATION";
|
|
197
|
-
var VALIDATED_FLAG_VALUE = "validated";
|
|
198
193
|
function isValidateType(typeInitializer) {
|
|
199
194
|
if (typeInitializer.getKind() === import_ts_morph2.SyntaxKind.PropertyAccessExpression) {
|
|
200
195
|
const propAccess = typeInitializer.asKindOrThrow(
|
|
@@ -318,50 +313,6 @@ function transformValidateActionToCustom(obj, eventType) {
|
|
|
318
313
|
}
|
|
319
314
|
return true;
|
|
320
315
|
}
|
|
321
|
-
function isRegisterAction(action) {
|
|
322
|
-
const typeProperty = action.getProperty(TYPE_PROPERTY_NAME2);
|
|
323
|
-
if (!typeProperty || !import_ts_morph2.Node.isPropertyAssignment(typeProperty)) return false;
|
|
324
|
-
const typeInit = typeProperty.getInitializer();
|
|
325
|
-
if (!typeInit) return false;
|
|
326
|
-
if (import_ts_morph2.Node.isPropertyAccessExpression(typeInit)) {
|
|
327
|
-
const enumExpr = typeInit.getExpression();
|
|
328
|
-
return import_ts_morph2.Node.isIdentifier(enumExpr) && enumExpr.getText() === ACTION_TYPE_ENUM_NAME && typeInit.getName() === REGISTER_MEMBER_NAME2;
|
|
329
|
-
}
|
|
330
|
-
if (import_ts_morph2.Node.isStringLiteral(typeInit)) {
|
|
331
|
-
return typeInit.getLiteralValue() === REGISTER_STRING_LITERAL2;
|
|
332
|
-
}
|
|
333
|
-
return false;
|
|
334
|
-
}
|
|
335
|
-
function arrayHasElementWithId(array3, id) {
|
|
336
|
-
for (const el of array3.getElements()) {
|
|
337
|
-
if (!import_ts_morph2.Node.isObjectLiteralExpression(el)) continue;
|
|
338
|
-
const idProp = el.getProperty(ID_PROPERTY_NAME);
|
|
339
|
-
if (!idProp || !import_ts_morph2.Node.isPropertyAssignment(idProp)) continue;
|
|
340
|
-
const idInit = idProp.getInitializer();
|
|
341
|
-
if (idInit && import_ts_morph2.Node.isStringLiteral(idInit) && idInit.getLiteralValue() === id) {
|
|
342
|
-
return true;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
return false;
|
|
346
|
-
}
|
|
347
|
-
function ensureRegisterRemovesValidatedFlag(action) {
|
|
348
|
-
const entry = `{ id: '${VALIDATED_FLAG_VALUE}', operation: 'remove' }`;
|
|
349
|
-
const flagsProp = action.getProperty(FLAGS_PROPERTY_NAME);
|
|
350
|
-
if (flagsProp && import_ts_morph2.Node.isPropertyAssignment(flagsProp)) {
|
|
351
|
-
const flagsInit = flagsProp.getInitializer();
|
|
352
|
-
if (flagsInit && import_ts_morph2.Node.isArrayLiteralExpression(flagsInit)) {
|
|
353
|
-
if (arrayHasElementWithId(flagsInit, VALIDATED_FLAG_VALUE)) return false;
|
|
354
|
-
flagsInit.addElement(entry);
|
|
355
|
-
return true;
|
|
356
|
-
}
|
|
357
|
-
return false;
|
|
358
|
-
}
|
|
359
|
-
action.addPropertyAssignment({
|
|
360
|
-
name: FLAGS_PROPERTY_NAME,
|
|
361
|
-
initializer: `[${entry}]`
|
|
362
|
-
});
|
|
363
|
-
return true;
|
|
364
|
-
}
|
|
365
316
|
function processFile2(filePath, project) {
|
|
366
317
|
const sourceFile = project.getSourceFile(filePath);
|
|
367
318
|
if (!sourceFile) return 0;
|
|
@@ -387,7 +338,7 @@ function processFile2(filePath, project) {
|
|
|
387
338
|
const eventType = resolveEventType(configArg);
|
|
388
339
|
if (!eventType) {
|
|
389
340
|
console.warn(
|
|
390
|
-
` [${import_path2.default.relative(
|
|
341
|
+
` [${import_path2.default.relative(getCwd(), configArg.getSourceFile().getFilePath())}] Could not resolve root 'type' from defineConfig \u2014 skipping auditHistoryLabel id generation`
|
|
391
342
|
);
|
|
392
343
|
}
|
|
393
344
|
let fileNeedsImports = false;
|
|
@@ -403,7 +354,7 @@ function processFile2(filePath, project) {
|
|
|
403
354
|
fileNeedsImports = true;
|
|
404
355
|
configHadValidateAction = true;
|
|
405
356
|
console.log(
|
|
406
|
-
` [${import_path2.default.relative(
|
|
357
|
+
` [${import_path2.default.relative(getCwd(), filePath)}] Transformed VALIDATE action to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'`
|
|
407
358
|
);
|
|
408
359
|
}
|
|
409
360
|
}
|
|
@@ -424,21 +375,9 @@ function processFile2(filePath, project) {
|
|
|
424
375
|
]`
|
|
425
376
|
});
|
|
426
377
|
console.log(
|
|
427
|
-
` [${import_path2.default.relative(
|
|
378
|
+
` [${import_path2.default.relative(getCwd(), filePath)}] Added top-level 'flags' array to defineConfig`
|
|
428
379
|
);
|
|
429
380
|
}
|
|
430
|
-
if (configHadValidateAction) {
|
|
431
|
-
for (const element of actionsInitializer.getElements()) {
|
|
432
|
-
if (!import_ts_morph2.Node.isObjectLiteralExpression(element)) continue;
|
|
433
|
-
if (!isRegisterAction(element)) continue;
|
|
434
|
-
if (ensureRegisterRemovesValidatedFlag(element)) {
|
|
435
|
-
transformedCount++;
|
|
436
|
-
console.log(
|
|
437
|
-
` [${import_path2.default.relative(process.cwd(), filePath)}] Added '${VALIDATED_FLAG_VALUE}' remove-flag to REGISTER action`
|
|
438
|
-
);
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
381
|
if (fileNeedsImports) {
|
|
443
382
|
ensureImports(sourceFile);
|
|
444
383
|
}
|
|
@@ -446,7 +385,7 @@ function processFile2(filePath, project) {
|
|
|
446
385
|
return transformedCount;
|
|
447
386
|
}
|
|
448
387
|
async function main2() {
|
|
449
|
-
const srcDir = import_path2.default.join(
|
|
388
|
+
const srcDir = import_path2.default.join(getCwd(), "src");
|
|
450
389
|
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
451
390
|
`);
|
|
452
391
|
const project = new import_ts_morph2.Project({
|
|
@@ -481,11 +420,11 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
481
420
|
for (const filePath of modifiedFiles) {
|
|
482
421
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
483
422
|
await sourceFile.save();
|
|
484
|
-
console.log(` Saved: ${import_path2.default.relative(
|
|
423
|
+
console.log(` Saved: ${import_path2.default.relative(getCwd(), filePath)}`);
|
|
485
424
|
}
|
|
486
425
|
console.log(
|
|
487
426
|
`
|
|
488
|
-
Done.
|
|
427
|
+
Done. Transformed ${totalTransformed} VALIDATE action(s) to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'.`
|
|
489
428
|
);
|
|
490
429
|
}
|
|
491
430
|
|
|
@@ -552,14 +491,14 @@ function processFile3(filePath, project) {
|
|
|
552
491
|
actionsInitializer.removeElement(index);
|
|
553
492
|
removedCount++;
|
|
554
493
|
console.log(
|
|
555
|
-
` [${import_path3.default.relative(
|
|
494
|
+
` [${import_path3.default.relative(getCwd(), filePath)}] Removed DELETE action at index ${index}`
|
|
556
495
|
);
|
|
557
496
|
}
|
|
558
497
|
}
|
|
559
498
|
return removedCount;
|
|
560
499
|
}
|
|
561
500
|
async function main3() {
|
|
562
|
-
const srcDir = import_path3.default.join(
|
|
501
|
+
const srcDir = import_path3.default.join(getCwd(), "src");
|
|
563
502
|
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
564
503
|
`);
|
|
565
504
|
const project = new import_ts_morph3.Project({
|
|
@@ -594,7 +533,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
594
533
|
for (const filePath of modifiedFiles) {
|
|
595
534
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
596
535
|
await sourceFile.save();
|
|
597
|
-
console.log(` Saved: ${import_path3.default.relative(
|
|
536
|
+
console.log(` Saved: ${import_path3.default.relative(getCwd(), filePath)}`);
|
|
598
537
|
}
|
|
599
538
|
console.log(
|
|
600
539
|
`
|
|
@@ -668,19 +607,19 @@ function processFile4(filePath, project) {
|
|
|
668
607
|
if (result === "converted-to-heading") {
|
|
669
608
|
changedCount++;
|
|
670
609
|
console.log(
|
|
671
|
-
` [${import_path4.default.relative(
|
|
610
|
+
` [${import_path4.default.relative(getCwd(), filePath)}] Converted PARAGRAPH with heading fontVariant to HEADING`
|
|
672
611
|
);
|
|
673
612
|
} else if (result === "removed-font-variant") {
|
|
674
613
|
changedCount++;
|
|
675
614
|
console.log(
|
|
676
|
-
` [${import_path4.default.relative(
|
|
615
|
+
` [${import_path4.default.relative(getCwd(), filePath)}] Removed non-heading fontVariant from PARAGRAPH`
|
|
677
616
|
);
|
|
678
617
|
}
|
|
679
618
|
}
|
|
680
619
|
return changedCount;
|
|
681
620
|
}
|
|
682
621
|
async function main4() {
|
|
683
|
-
const srcDir = import_path4.default.join(
|
|
622
|
+
const srcDir = import_path4.default.join(getCwd(), "src");
|
|
684
623
|
console.log(`Scanning for FieldType.PARAGRAPH fields in: ${srcDir}
|
|
685
624
|
`);
|
|
686
625
|
const project = new import_ts_morph4.Project({
|
|
@@ -714,7 +653,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
714
653
|
for (const filePath of modifiedFiles) {
|
|
715
654
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
716
655
|
await sourceFile.save();
|
|
717
|
-
console.log(` Saved: ${import_path4.default.relative(
|
|
656
|
+
console.log(` Saved: ${import_path4.default.relative(getCwd(), filePath)}`);
|
|
718
657
|
}
|
|
719
658
|
console.log(`
|
|
720
659
|
Done. Processed ${totalChanged} FieldType.PARAGRAPH field(s).`);
|
|
@@ -728,14 +667,14 @@ var QUERY_PROPERTY_NAME = "query";
|
|
|
728
667
|
var TYPE_PROPERTY_NAME5 = "type";
|
|
729
668
|
var CLAUSES_PROPERTY_NAME = "clauses";
|
|
730
669
|
var STATUS_PROPERTY_NAME = "status";
|
|
731
|
-
var
|
|
670
|
+
var FLAGS_PROPERTY_NAME = "flags";
|
|
732
671
|
var TERMS_PROPERTY_NAME = "terms";
|
|
733
672
|
var TERM_PROPERTY_NAME = "term";
|
|
734
673
|
var ANY_OF_PROPERTY_NAME = "anyOf";
|
|
735
674
|
var VALIDATED_STATUS_VALUE = "VALIDATED";
|
|
736
|
-
var
|
|
675
|
+
var VALIDATED_FLAG_VALUE = "validated";
|
|
737
676
|
function addValidatedFlag(clause) {
|
|
738
|
-
const flagsProperty = clause.getProperty(
|
|
677
|
+
const flagsProperty = clause.getProperty(FLAGS_PROPERTY_NAME);
|
|
739
678
|
if (flagsProperty && import_ts_morph5.Node.isPropertyAssignment(flagsProperty)) {
|
|
740
679
|
const flagsInit = flagsProperty.getInitializer();
|
|
741
680
|
if (flagsInit && import_ts_morph5.Node.isObjectLiteralExpression(flagsInit)) {
|
|
@@ -743,19 +682,19 @@ function addValidatedFlag(clause) {
|
|
|
743
682
|
if (anyOfProperty && import_ts_morph5.Node.isPropertyAssignment(anyOfProperty)) {
|
|
744
683
|
const anyOfInit = anyOfProperty.getInitializer();
|
|
745
684
|
if (anyOfInit && import_ts_morph5.Node.isArrayLiteralExpression(anyOfInit)) {
|
|
746
|
-
anyOfInit.addElement(`'${
|
|
685
|
+
anyOfInit.addElement(`'${VALIDATED_FLAG_VALUE}'`);
|
|
747
686
|
}
|
|
748
687
|
} else {
|
|
749
688
|
flagsInit.addPropertyAssignment({
|
|
750
689
|
name: ANY_OF_PROPERTY_NAME,
|
|
751
|
-
initializer: `['${
|
|
690
|
+
initializer: `['${VALIDATED_FLAG_VALUE}']`
|
|
752
691
|
});
|
|
753
692
|
}
|
|
754
693
|
}
|
|
755
694
|
} else {
|
|
756
695
|
clause.addPropertyAssignment({
|
|
757
|
-
name:
|
|
758
|
-
initializer: `{ ${ANY_OF_PROPERTY_NAME}: ['${
|
|
696
|
+
name: FLAGS_PROPERTY_NAME,
|
|
697
|
+
initializer: `{ ${ANY_OF_PROPERTY_NAME}: ['${VALIDATED_FLAG_VALUE}'] }`
|
|
759
698
|
});
|
|
760
699
|
}
|
|
761
700
|
}
|
|
@@ -864,7 +803,7 @@ function processFile5(filePath, project) {
|
|
|
864
803
|
if (changed > 0) {
|
|
865
804
|
migratedCount += changed;
|
|
866
805
|
console.log(
|
|
867
|
-
` [${import_path5.default.relative(
|
|
806
|
+
` [${import_path5.default.relative(getCwd(), filePath)}] Migrated ${changed} clause(s): VALIDATED status \u2192 flags.anyOf`
|
|
868
807
|
);
|
|
869
808
|
}
|
|
870
809
|
}
|
|
@@ -872,7 +811,7 @@ function processFile5(filePath, project) {
|
|
|
872
811
|
return migratedCount;
|
|
873
812
|
}
|
|
874
813
|
async function main5() {
|
|
875
|
-
const srcDir = import_path5.default.join(
|
|
814
|
+
const srcDir = import_path5.default.join(getCwd(), "src");
|
|
876
815
|
console.log(`Scanning for defineWorkqueues calls in: ${srcDir}
|
|
877
816
|
`);
|
|
878
817
|
const project = new import_ts_morph5.Project({
|
|
@@ -906,7 +845,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
906
845
|
for (const filePath of modifiedFiles) {
|
|
907
846
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
908
847
|
await sourceFile.save();
|
|
909
|
-
console.log(` Saved: ${import_path5.default.relative(
|
|
848
|
+
console.log(` Saved: ${import_path5.default.relative(getCwd(), filePath)}`);
|
|
910
849
|
}
|
|
911
850
|
console.log(
|
|
912
851
|
`
|
|
@@ -921,26 +860,23 @@ var DEFINE_CONFIG_NAME4 = "defineConfig";
|
|
|
921
860
|
var DEFINE_WORKQUEUES_NAME2 = "defineWorkqueues";
|
|
922
861
|
var ACTIONS_PROPERTY_NAME4 = "actions";
|
|
923
862
|
var ACTION_PROPERTY_NAME = "action";
|
|
924
|
-
var
|
|
863
|
+
var FLAGS_PROPERTY_NAME2 = "flags";
|
|
925
864
|
var QUERY_PROPERTY_NAME2 = "query";
|
|
926
865
|
var TYPE_PROPERTY_NAME6 = "type";
|
|
927
|
-
var ID_PROPERTY_NAME2 = "id";
|
|
928
866
|
var CLAUSES_PROPERTY_NAME2 = "clauses";
|
|
929
867
|
var ANY_OF_PROPERTY_NAME2 = "anyOf";
|
|
930
868
|
var FLAG_ID = "pending-first-certificate-issuance";
|
|
931
869
|
var REGISTER_TYPE = "REGISTER";
|
|
932
870
|
var PRINT_CERTIFICATE_TYPE = "PRINT_CERTIFICATE";
|
|
933
|
-
|
|
934
|
-
return `{
|
|
871
|
+
var FLAG_DEFINITION_INITIALIZER = `{
|
|
935
872
|
id: '${FLAG_ID}',
|
|
936
873
|
label: {
|
|
937
|
-
id: 'event
|
|
874
|
+
id: 'event.birth.flag.${FLAG_ID}',
|
|
938
875
|
defaultMessage: 'Pending first certificate issuance',
|
|
939
876
|
description: 'Flag label for first certificate issuance'
|
|
940
877
|
},
|
|
941
878
|
requiresAction: true
|
|
942
879
|
}`;
|
|
943
|
-
}
|
|
944
880
|
function isActionOfType(obj, typeName) {
|
|
945
881
|
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME6);
|
|
946
882
|
if (!typeProperty || !import_ts_morph6.Node.isPropertyAssignment(typeProperty)) return false;
|
|
@@ -954,20 +890,18 @@ function isActionOfType(obj, typeName) {
|
|
|
954
890
|
}
|
|
955
891
|
return false;
|
|
956
892
|
}
|
|
957
|
-
function
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
return initializer.getLiteralValue().toLowerCase();
|
|
965
|
-
}
|
|
966
|
-
if (import_ts_morph6.Node.isPropertyAccessExpression(initializer)) {
|
|
967
|
-
return initializer.getName().toLowerCase();
|
|
968
|
-
}
|
|
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";
|
|
969
900
|
}
|
|
970
|
-
|
|
901
|
+
if (import_ts_morph6.Node.isPropertyAccessExpression(initializer)) {
|
|
902
|
+
return initializer.getName().toLowerCase() === "birth";
|
|
903
|
+
}
|
|
904
|
+
return false;
|
|
971
905
|
}
|
|
972
906
|
function hasElementWithId(array3, id) {
|
|
973
907
|
for (const el of array3.getElements()) {
|
|
@@ -981,28 +915,27 @@ function hasElementWithId(array3, id) {
|
|
|
981
915
|
}
|
|
982
916
|
return false;
|
|
983
917
|
}
|
|
984
|
-
function ensureTopLevelFlagDefinition(configArg
|
|
985
|
-
const
|
|
986
|
-
const flagsProp = configArg.getProperty(FLAGS_PROPERTY_NAME3);
|
|
918
|
+
function ensureTopLevelFlagDefinition(configArg) {
|
|
919
|
+
const flagsProp = configArg.getProperty(FLAGS_PROPERTY_NAME2);
|
|
987
920
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
988
921
|
const flagsInit = flagsProp.getInitializer();
|
|
989
922
|
if (flagsInit && import_ts_morph6.Node.isArrayLiteralExpression(flagsInit)) {
|
|
990
923
|
if (hasElementWithId(flagsInit, FLAG_ID)) return false;
|
|
991
|
-
flagsInit.addElement(
|
|
924
|
+
flagsInit.addElement(FLAG_DEFINITION_INITIALIZER);
|
|
992
925
|
return true;
|
|
993
926
|
}
|
|
994
927
|
return false;
|
|
995
928
|
}
|
|
996
929
|
configArg.addPropertyAssignment({
|
|
997
|
-
name:
|
|
930
|
+
name: FLAGS_PROPERTY_NAME2,
|
|
998
931
|
initializer: `[
|
|
999
|
-
${
|
|
932
|
+
${FLAG_DEFINITION_INITIALIZER}
|
|
1000
933
|
]`
|
|
1001
934
|
});
|
|
1002
935
|
return true;
|
|
1003
936
|
}
|
|
1004
937
|
function ensureActionOperationFlag(action, operation) {
|
|
1005
|
-
const flagsProp = action.getProperty(
|
|
938
|
+
const flagsProp = action.getProperty(FLAGS_PROPERTY_NAME2);
|
|
1006
939
|
const entry = `{ id: '${FLAG_ID}', operation: '${operation}' }`;
|
|
1007
940
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
1008
941
|
const flagsInit = flagsProp.getInitializer();
|
|
@@ -1014,18 +947,16 @@ function ensureActionOperationFlag(action, operation) {
|
|
|
1014
947
|
return false;
|
|
1015
948
|
}
|
|
1016
949
|
action.addPropertyAssignment({
|
|
1017
|
-
name:
|
|
950
|
+
name: FLAGS_PROPERTY_NAME2,
|
|
1018
951
|
initializer: `[${entry}]`
|
|
1019
952
|
});
|
|
1020
953
|
return true;
|
|
1021
954
|
}
|
|
1022
|
-
function
|
|
955
|
+
function processBirthConfig(configArg, relPath) {
|
|
1023
956
|
let changes = 0;
|
|
1024
|
-
if (ensureTopLevelFlagDefinition(configArg
|
|
957
|
+
if (ensureTopLevelFlagDefinition(configArg)) {
|
|
1025
958
|
changes++;
|
|
1026
|
-
console.log(
|
|
1027
|
-
` [${relPath}] (${eventType}) Added '${FLAG_ID}' to top-level flags`
|
|
1028
|
-
);
|
|
959
|
+
console.log(` [${relPath}] Added '${FLAG_ID}' to top-level flags`);
|
|
1029
960
|
}
|
|
1030
961
|
const actionsProp = configArg.getProperty(ACTIONS_PROPERTY_NAME4);
|
|
1031
962
|
if (!actionsProp || !import_ts_morph6.Node.isPropertyAssignment(actionsProp)) return changes;
|
|
@@ -1039,7 +970,7 @@ function processConfig(configArg, eventType, relPath) {
|
|
|
1039
970
|
if (ensureActionOperationFlag(element, "add")) {
|
|
1040
971
|
changes++;
|
|
1041
972
|
console.log(
|
|
1042
|
-
` [${relPath}]
|
|
973
|
+
` [${relPath}] Added '${FLAG_ID}' add-flag to REGISTER action`
|
|
1043
974
|
);
|
|
1044
975
|
}
|
|
1045
976
|
}
|
|
@@ -1047,7 +978,7 @@ function processConfig(configArg, eventType, relPath) {
|
|
|
1047
978
|
if (ensureActionOperationFlag(element, "remove")) {
|
|
1048
979
|
changes++;
|
|
1049
980
|
console.log(
|
|
1050
|
-
` [${relPath}]
|
|
981
|
+
` [${relPath}] Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`
|
|
1051
982
|
);
|
|
1052
983
|
}
|
|
1053
984
|
}
|
|
@@ -1076,7 +1007,7 @@ function hasPrintCertificateAction(workqueue) {
|
|
|
1076
1007
|
return false;
|
|
1077
1008
|
}
|
|
1078
1009
|
function addFlagToQueryClause(clause) {
|
|
1079
|
-
const flagsProp = clause.getProperty(
|
|
1010
|
+
const flagsProp = clause.getProperty(FLAGS_PROPERTY_NAME2);
|
|
1080
1011
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
1081
1012
|
const flagsInit = flagsProp.getInitializer();
|
|
1082
1013
|
if (flagsInit && import_ts_morph6.Node.isObjectLiteralExpression(flagsInit)) {
|
|
@@ -1101,7 +1032,7 @@ function addFlagToQueryClause(clause) {
|
|
|
1101
1032
|
}
|
|
1102
1033
|
} else {
|
|
1103
1034
|
clause.addPropertyAssignment({
|
|
1104
|
-
name:
|
|
1035
|
+
name: FLAGS_PROPERTY_NAME2,
|
|
1105
1036
|
initializer: `{ ${ANY_OF_PROPERTY_NAME2}: ['${FLAG_ID}'] }`
|
|
1106
1037
|
});
|
|
1107
1038
|
return true;
|
|
@@ -1132,7 +1063,7 @@ function processFile6(filePath, project) {
|
|
|
1132
1063
|
const sourceFile = project.getSourceFile(filePath);
|
|
1133
1064
|
if (!sourceFile) return 0;
|
|
1134
1065
|
let totalChanges = 0;
|
|
1135
|
-
const relPath = import_path6.default.relative(
|
|
1066
|
+
const relPath = import_path6.default.relative(getCwd(), filePath);
|
|
1136
1067
|
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
1137
1068
|
import_ts_morph6.SyntaxKind.CallExpression
|
|
1138
1069
|
);
|
|
@@ -1145,9 +1076,8 @@ function processFile6(filePath, project) {
|
|
|
1145
1076
|
if (args2.length === 0) continue;
|
|
1146
1077
|
const configArg = args2[0];
|
|
1147
1078
|
if (!import_ts_morph6.Node.isObjectLiteralExpression(configArg)) continue;
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
totalChanges += processConfig(configArg, eventType, relPath);
|
|
1079
|
+
if (!isBirthConfig(configArg)) continue;
|
|
1080
|
+
totalChanges += processBirthConfig(configArg, relPath);
|
|
1151
1081
|
}
|
|
1152
1082
|
if (calleeName === DEFINE_WORKQUEUES_NAME2) {
|
|
1153
1083
|
const args2 = call.getArguments();
|
|
@@ -1174,9 +1104,9 @@ function processFile6(filePath, project) {
|
|
|
1174
1104
|
return totalChanges;
|
|
1175
1105
|
}
|
|
1176
1106
|
async function main6() {
|
|
1177
|
-
const srcDir = import_path6.default.join(
|
|
1107
|
+
const srcDir = import_path6.default.join(getCwd(), "src");
|
|
1178
1108
|
console.log(
|
|
1179
|
-
`Scanning for defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}
|
|
1109
|
+
`Scanning for birth defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}
|
|
1180
1110
|
`
|
|
1181
1111
|
);
|
|
1182
1112
|
const project = new import_ts_morph6.Project({
|
|
@@ -1201,7 +1131,7 @@ async function main6() {
|
|
|
1201
1131
|
}
|
|
1202
1132
|
if (modifiedFiles.length === 0) {
|
|
1203
1133
|
console.log(
|
|
1204
|
-
"No
|
|
1134
|
+
"No birth configs or PRINT_CERTIFICATE workqueues found. Nothing to do."
|
|
1205
1135
|
);
|
|
1206
1136
|
return;
|
|
1207
1137
|
}
|
|
@@ -1210,7 +1140,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1210
1140
|
for (const filePath of modifiedFiles) {
|
|
1211
1141
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1212
1142
|
await sourceFile.save();
|
|
1213
|
-
console.log(` Saved: ${import_path6.default.relative(
|
|
1143
|
+
console.log(` Saved: ${import_path6.default.relative(getCwd(), filePath)}`);
|
|
1214
1144
|
}
|
|
1215
1145
|
console.log(
|
|
1216
1146
|
`
|
|
@@ -1247,14 +1177,14 @@ function processFile7(filePath, project) {
|
|
|
1247
1177
|
array3.removeElement(index);
|
|
1248
1178
|
removedCount++;
|
|
1249
1179
|
console.log(
|
|
1250
|
-
` [${import_path7.default.relative(
|
|
1180
|
+
` [${import_path7.default.relative(getCwd(), filePath)}] Removed InherentFlags.PENDING_CERTIFICATION from array`
|
|
1251
1181
|
);
|
|
1252
1182
|
}
|
|
1253
1183
|
}
|
|
1254
1184
|
return removedCount;
|
|
1255
1185
|
}
|
|
1256
1186
|
async function main7() {
|
|
1257
|
-
const srcDir = import_path7.default.join(
|
|
1187
|
+
const srcDir = import_path7.default.join(getCwd(), "src");
|
|
1258
1188
|
console.log(
|
|
1259
1189
|
`Scanning for InherentFlags.PENDING_CERTIFICATION array elements in: ${srcDir}
|
|
1260
1190
|
`
|
|
@@ -1290,7 +1220,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1290
1220
|
for (const filePath of modifiedFiles) {
|
|
1291
1221
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1292
1222
|
await sourceFile.save();
|
|
1293
|
-
console.log(` Saved: ${import_path7.default.relative(
|
|
1223
|
+
console.log(` Saved: ${import_path7.default.relative(getCwd(), filePath)}`);
|
|
1294
1224
|
}
|
|
1295
1225
|
console.log(
|
|
1296
1226
|
`
|
|
@@ -1348,13 +1278,13 @@ function processFile8(filePath, project) {
|
|
|
1348
1278
|
propAccess.getNameNode().replaceWithText(NEW_PROPERTY_NAME);
|
|
1349
1279
|
renamedCount++;
|
|
1350
1280
|
console.log(
|
|
1351
|
-
` [${import_path8.default.relative(
|
|
1281
|
+
` [${import_path8.default.relative(getCwd(), filePath)}] Renamed Location.${OLD_PROPERTY_NAME} \u2192 Location.${NEW_PROPERTY_NAME}`
|
|
1352
1282
|
);
|
|
1353
1283
|
}
|
|
1354
1284
|
return renamedCount;
|
|
1355
1285
|
}
|
|
1356
1286
|
async function main8() {
|
|
1357
|
-
const srcDir = import_path8.default.join(
|
|
1287
|
+
const srcDir = import_path8.default.join(getCwd(), "src");
|
|
1358
1288
|
console.log(
|
|
1359
1289
|
`Scanning for Location.${OLD_PROPERTY_NAME} references in: ${srcDir}
|
|
1360
1290
|
`
|
|
@@ -1390,7 +1320,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1390
1320
|
for (const filePath of modifiedFiles) {
|
|
1391
1321
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1392
1322
|
await sourceFile.save();
|
|
1393
|
-
console.log(` Saved: ${import_path8.default.relative(
|
|
1323
|
+
console.log(` Saved: ${import_path8.default.relative(getCwd(), filePath)}`);
|
|
1394
1324
|
}
|
|
1395
1325
|
console.log(
|
|
1396
1326
|
`
|
|
@@ -1457,7 +1387,7 @@ function processFile9(filePath, project) {
|
|
|
1457
1387
|
const sourceFile = project.getSourceFile(filePath);
|
|
1458
1388
|
if (!sourceFile) return 0;
|
|
1459
1389
|
let renamedCount = 0;
|
|
1460
|
-
const relPath = import_path9.default.relative(
|
|
1390
|
+
const relPath = import_path9.default.relative(getCwd(), filePath);
|
|
1461
1391
|
const candidates = sourceFile.getDescendantsOfKind(
|
|
1462
1392
|
import_ts_morph9.SyntaxKind.ObjectLiteralExpression
|
|
1463
1393
|
);
|
|
@@ -1472,7 +1402,7 @@ function processFile9(filePath, project) {
|
|
|
1472
1402
|
return renamedCount;
|
|
1473
1403
|
}
|
|
1474
1404
|
async function main9() {
|
|
1475
|
-
const srcDir = import_path9.default.join(
|
|
1405
|
+
const srcDir = import_path9.default.join(getCwd(), "src");
|
|
1476
1406
|
console.log(`Scanning for Hapi route configs in: ${srcDir}
|
|
1477
1407
|
`);
|
|
1478
1408
|
console.log("Active path renames:");
|
|
@@ -1509,7 +1439,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1509
1439
|
for (const filePath of modifiedFiles) {
|
|
1510
1440
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1511
1441
|
await sourceFile.save();
|
|
1512
|
-
console.log(` Saved: ${import_path9.default.relative(
|
|
1442
|
+
console.log(` Saved: ${import_path9.default.relative(getCwd(), filePath)}`);
|
|
1513
1443
|
}
|
|
1514
1444
|
console.log(`
|
|
1515
1445
|
Done. Renamed ${totalRenamed} route path(s).`);
|
|
@@ -1883,9 +1813,9 @@ function updateRouteHandlers(sourceFiles, group, srcDir, relCwd) {
|
|
|
1883
1813
|
}
|
|
1884
1814
|
return replacedCount;
|
|
1885
1815
|
}
|
|
1886
|
-
function resolveConfigChain(configObj,
|
|
1816
|
+
function resolveConfigChain(configObj, path17) {
|
|
1887
1817
|
let current = configObj;
|
|
1888
|
-
for (const key of
|
|
1818
|
+
for (const key of path17) {
|
|
1889
1819
|
if (!import_ts_morph10.Node.isObjectLiteralExpression(current)) return null;
|
|
1890
1820
|
const prop = current.getProperty(key);
|
|
1891
1821
|
if (!prop || !import_ts_morph10.Node.isPropertyAssignment(prop)) return null;
|
|
@@ -1930,8 +1860,8 @@ function ensureJoinImport(sf) {
|
|
|
1930
1860
|
});
|
|
1931
1861
|
}
|
|
1932
1862
|
async function main10() {
|
|
1933
|
-
const srcDir = import_path10.default.join(
|
|
1934
|
-
const relCwd = (fp) => import_path10.default.relative(
|
|
1863
|
+
const srcDir = import_path10.default.join(getCwd(), "src");
|
|
1864
|
+
const relCwd = (fp) => import_path10.default.relative(getCwd(), fp);
|
|
1935
1865
|
console.log("Phase 1: Converting JS config files to TypeScript...\n");
|
|
1936
1866
|
let convertedCount = 0;
|
|
1937
1867
|
for (const group of CONFIG_GROUPS) {
|
|
@@ -2019,7 +1949,7 @@ async function main10() {
|
|
|
2019
1949
|
ensureJoinImport(sf);
|
|
2020
1950
|
}
|
|
2021
1951
|
console.log(
|
|
2022
|
-
` Inlined applicationConfig.${accessPath.join(".")} \u2192 ${adjustedValue} in ${import_path10.default.relative(
|
|
1952
|
+
` Inlined applicationConfig.${accessPath.join(".")} \u2192 ${adjustedValue} in ${import_path10.default.relative(getCwd(), sf.getFilePath())}`
|
|
2023
1953
|
);
|
|
2024
1954
|
filesToSaveAfterInlining.add(sf);
|
|
2025
1955
|
madeReplacement = true;
|
|
@@ -2031,7 +1961,7 @@ async function main10() {
|
|
|
2031
1961
|
for (const sf of Array.from(filesToSaveAfterInlining)) {
|
|
2032
1962
|
await sf.save();
|
|
2033
1963
|
console.log(
|
|
2034
|
-
` Saved (inlined): ${import_path10.default.relative(
|
|
1964
|
+
` Saved (inlined): ${import_path10.default.relative(getCwd(), sf.getFilePath())}`
|
|
2035
1965
|
);
|
|
2036
1966
|
}
|
|
2037
1967
|
for (const prop of [...propsToRemove].reverse()) {
|
|
@@ -2180,10 +2110,6 @@ var scopeByEvent = z3.preprocess(
|
|
|
2180
2110
|
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
2181
2111
|
z3.array(z3.string()).optional()
|
|
2182
2112
|
).describe("Event type, e.g. birth, death");
|
|
2183
|
-
var userRole = z3.preprocess(
|
|
2184
|
-
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
2185
|
-
z3.array(z3.string()).optional()
|
|
2186
|
-
).describe("User role, e.g. admin, field agent");
|
|
2187
2113
|
var scopeOptionsPlaceEvent = z3.object({
|
|
2188
2114
|
event: scopeByEvent,
|
|
2189
2115
|
placeOfEvent: JurisdictionFilter.optional()
|
|
@@ -2207,9 +2133,6 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
|
|
|
2207
2133
|
var AccessLevelOptions = z3.object({
|
|
2208
2134
|
accessLevel: JurisdictionFilter.optional()
|
|
2209
2135
|
});
|
|
2210
|
-
var AllUserScopeOptions = AccessLevelOptions.extend({
|
|
2211
|
-
role: userRole.optional()
|
|
2212
|
-
});
|
|
2213
2136
|
var WorkqueueOrDashboardOptions = z3.object({
|
|
2214
2137
|
ids: z3.preprocess(
|
|
2215
2138
|
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
@@ -2219,7 +2142,6 @@ var WorkqueueOrDashboardOptions = z3.object({
|
|
|
2219
2142
|
var AllScopeOptions = z3.object({
|
|
2220
2143
|
...AllRecordScopeOptions.shape,
|
|
2221
2144
|
...AccessLevelOptions.shape,
|
|
2222
|
-
...AllUserScopeOptions.shape,
|
|
2223
2145
|
...WorkqueueOrDashboardOptions.shape
|
|
2224
2146
|
});
|
|
2225
2147
|
var ScopeOptionKey = AllScopeOptions.keyof();
|
|
@@ -2292,28 +2214,6 @@ var RecordScopeV2 = z3.discriminatedUnion("type", [
|
|
|
2292
2214
|
]).describe(
|
|
2293
2215
|
"Scopes used to check user's permission to perform actions on a record."
|
|
2294
2216
|
);
|
|
2295
|
-
var SystemScopeType = z3.enum([
|
|
2296
|
-
"organisation.read-locations",
|
|
2297
|
-
"user.read",
|
|
2298
|
-
"user.create",
|
|
2299
|
-
"user.edit"
|
|
2300
|
-
]);
|
|
2301
|
-
var UserScopeType = SystemScopeType.extract([
|
|
2302
|
-
"user.read",
|
|
2303
|
-
"user.create",
|
|
2304
|
-
"user.edit"
|
|
2305
|
-
]);
|
|
2306
|
-
var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
|
|
2307
|
-
var UserScopeV2 = z3.discriminatedUnion("type", [
|
|
2308
|
-
z3.object({
|
|
2309
|
-
type: ScopesWithRoleOption,
|
|
2310
|
-
options: AllUserScopeOptions.optional()
|
|
2311
|
-
}),
|
|
2312
|
-
z3.object({
|
|
2313
|
-
type: UserScopeType.extract(["user.read"]),
|
|
2314
|
-
options: AccessLevelOptions.optional()
|
|
2315
|
-
})
|
|
2316
|
-
]);
|
|
2317
2217
|
var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
|
|
2318
2218
|
z3.object({
|
|
2319
2219
|
type: ScopesWithPlaceEventOptions,
|
|
@@ -2334,14 +2234,16 @@ var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
|
|
|
2334
2234
|
}).optional()
|
|
2335
2235
|
})
|
|
2336
2236
|
]).describe("Resolved scope with location/user IDs instead of filters.");
|
|
2237
|
+
var SystemScopeType = z3.enum([
|
|
2238
|
+
"organisation.read-locations",
|
|
2239
|
+
"user.read",
|
|
2240
|
+
"user.create",
|
|
2241
|
+
"user.edit"
|
|
2242
|
+
]);
|
|
2337
2243
|
var Scope2 = z3.discriminatedUnion("type", [
|
|
2338
2244
|
z3.object({ type: PlainScopeType }),
|
|
2339
2245
|
...RecordScopeV2.options,
|
|
2340
|
-
|
|
2341
|
-
z3.object({
|
|
2342
|
-
type: z3.literal("organisation.read-locations"),
|
|
2343
|
-
options: AccessLevelOptions.optional()
|
|
2344
|
-
}),
|
|
2246
|
+
z3.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
|
|
2345
2247
|
z3.object({
|
|
2346
2248
|
type: z3.literal("workqueue"),
|
|
2347
2249
|
options: WorkqueueOrDashboardOptions
|
|
@@ -2676,7 +2578,7 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2676
2578
|
const scopeKey = resolveScopeKeyFromElementAccess(element);
|
|
2677
2579
|
if (scopeKey && !(scopeKey in SCOPES)) {
|
|
2678
2580
|
console.warn(
|
|
2679
|
-
` [${import_path11.default.relative(
|
|
2581
|
+
` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Removing unknown scope reference: SCOPES.${scopeKey}`
|
|
2680
2582
|
);
|
|
2681
2583
|
initializer.removeElement(index);
|
|
2682
2584
|
removedCount++;
|
|
@@ -2685,7 +2587,7 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2685
2587
|
const legacyScope = resolveLegacyScopeFromElement(element);
|
|
2686
2588
|
if (!legacyScope) {
|
|
2687
2589
|
console.warn(
|
|
2688
|
-
` [${import_path11.default.relative(
|
|
2590
|
+
` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Skipping non-literal scope expression: ${element.getText()}`
|
|
2689
2591
|
);
|
|
2690
2592
|
continue;
|
|
2691
2593
|
}
|
|
@@ -2694,7 +2596,7 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2694
2596
|
const scope = decodeScope(migratedScope);
|
|
2695
2597
|
if (!scope) {
|
|
2696
2598
|
console.warn(
|
|
2697
|
-
` [${import_path11.default.relative(
|
|
2599
|
+
` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Could not decode migrated scope '${migratedScope}'.`
|
|
2698
2600
|
);
|
|
2699
2601
|
continue;
|
|
2700
2602
|
}
|
|
@@ -2702,14 +2604,14 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2702
2604
|
migratedCount++;
|
|
2703
2605
|
} catch (error) {
|
|
2704
2606
|
console.warn(
|
|
2705
|
-
` [${import_path11.default.relative(
|
|
2607
|
+
` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`
|
|
2706
2608
|
);
|
|
2707
2609
|
}
|
|
2708
2610
|
}
|
|
2709
2611
|
}
|
|
2710
2612
|
if (removedCount > 0) {
|
|
2711
2613
|
console.log(
|
|
2712
|
-
` Removed ${removedCount} unknown SCOPES reference(s) from '${import_path11.default.relative(
|
|
2614
|
+
` Removed ${removedCount} unknown SCOPES reference(s) from '${import_path11.default.relative(getCwd(), rolesFilePath)}'.`
|
|
2713
2615
|
);
|
|
2714
2616
|
}
|
|
2715
2617
|
return { migratedCount, removedCount };
|
|
@@ -2831,9 +2733,9 @@ function removeRoleTypeDefinitionAndUnusedImports(rolesFilePath, project) {
|
|
|
2831
2733
|
return removed;
|
|
2832
2734
|
}
|
|
2833
2735
|
async function main11() {
|
|
2834
|
-
const
|
|
2835
|
-
const srcDir = import_path11.default.join(
|
|
2836
|
-
const rolesFilePath = import_path11.default.join(
|
|
2736
|
+
const cwd2 = getCwd();
|
|
2737
|
+
const srcDir = import_path11.default.join(cwd2, "src");
|
|
2738
|
+
const rolesFilePath = import_path11.default.join(cwd2, ROLES_FILE_RELATIVE_PATH);
|
|
2837
2739
|
console.log(`Scanning roles scopes in: ${rolesFilePath}`);
|
|
2838
2740
|
const project = new import_ts_morph11.Project({
|
|
2839
2741
|
tsConfigFilePath: import_path11.default.resolve(srcDir, "../tsconfig.json"),
|
|
@@ -2897,13 +2799,13 @@ function processFile10(filePath, project) {
|
|
|
2897
2799
|
decl.remove();
|
|
2898
2800
|
}
|
|
2899
2801
|
console.log(
|
|
2900
|
-
` [${import_path12.default.relative(
|
|
2802
|
+
` [${import_path12.default.relative(getCwd(), filePath)}] Removed ${matchingNamedImports.length} deprecated '${DEPRECATED_IMPORT}' import(s) from '${decl.getModuleSpecifierValue()}'`
|
|
2901
2803
|
);
|
|
2902
2804
|
}
|
|
2903
2805
|
return removedCount;
|
|
2904
2806
|
}
|
|
2905
2807
|
async function main12() {
|
|
2906
|
-
const srcDir = import_path12.default.join(
|
|
2808
|
+
const srcDir = import_path12.default.join(getCwd(), "src");
|
|
2907
2809
|
console.log(`Scanning for deprecated imports in: ${srcDir}
|
|
2908
2810
|
`);
|
|
2909
2811
|
const project = new import_ts_morph12.Project({
|
|
@@ -2934,924 +2836,201 @@ async function main12() {
|
|
|
2934
2836
|
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
2935
2837
|
for (const filePath of modifiedFiles) {
|
|
2936
2838
|
await project.getSourceFileOrThrow(filePath).save();
|
|
2937
|
-
console.log(` Saved: ${import_path12.default.relative(
|
|
2839
|
+
console.log(` Saved: ${import_path12.default.relative(getCwd(), filePath)}`);
|
|
2938
2840
|
}
|
|
2939
2841
|
console.log(`
|
|
2940
2842
|
Done. Removed ${totalRemoved} deprecated import(s).`);
|
|
2941
2843
|
}
|
|
2942
2844
|
|
|
2943
|
-
// src/migrations/v2.0/
|
|
2944
|
-
var import_path13 = __toESM(require("path"));
|
|
2845
|
+
// src/migrations/v2.0/migrate-workqueue-configs.ts
|
|
2945
2846
|
var import_ts_morph13 = require("ts-morph");
|
|
2946
|
-
var
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2847
|
+
var import_path13 = __toESM(require("path"));
|
|
2848
|
+
var DEFINE_WORKQUEUES_NAME3 = "defineWorkqueues";
|
|
2849
|
+
var ACTIONS_PROPERTY_NAME5 = "actions";
|
|
2850
|
+
var ACTION_PROPERTY_NAME2 = "action";
|
|
2851
|
+
var CONDITIONALS_PROPERTY_NAME = "conditionals";
|
|
2852
|
+
var TYPE_PROPERTY_NAME7 = "type";
|
|
2853
|
+
var SLUG_PROPERTY_NAME = "slug";
|
|
2854
|
+
var SUPPORTED_WORKQUEUE_ACTION_TYPES = /* @__PURE__ */ new Set([
|
|
2855
|
+
"READ",
|
|
2856
|
+
"DELETE",
|
|
2857
|
+
"DECLARE",
|
|
2858
|
+
"REGISTER",
|
|
2859
|
+
"EDIT",
|
|
2860
|
+
"REJECT",
|
|
2861
|
+
"MARK_AS_DUPLICATE",
|
|
2862
|
+
"ARCHIVE",
|
|
2863
|
+
"PRINT_CERTIFICATE",
|
|
2864
|
+
"REQUEST_CORRECTION"
|
|
2950
2865
|
]);
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
if (!sourceFile) return [];
|
|
2956
|
-
const removed = [];
|
|
2957
|
-
const cleanEnvCall = sourceFile.getDescendantsOfKind(import_ts_morph13.SyntaxKind.CallExpression).find((call) => {
|
|
2958
|
-
const expr = call.getExpression();
|
|
2959
|
-
return import_ts_morph13.Node.isIdentifier(expr) && expr.getText() === "cleanEnv";
|
|
2960
|
-
});
|
|
2961
|
-
if (!cleanEnvCall) return removed;
|
|
2962
|
-
const schemaArg = cleanEnvCall.getArguments()[1]?.asKind(import_ts_morph13.SyntaxKind.ObjectLiteralExpression);
|
|
2963
|
-
if (!schemaArg) return removed;
|
|
2964
|
-
for (const name of UNUSED_ENV_VARS) {
|
|
2965
|
-
const prop = schemaArg.getProperty(name);
|
|
2966
|
-
if (!prop) continue;
|
|
2967
|
-
if (prop.isKind(import_ts_morph13.SyntaxKind.PropertyAssignment) || prop.isKind(import_ts_morph13.SyntaxKind.ShorthandPropertyAssignment)) {
|
|
2968
|
-
prop.remove();
|
|
2969
|
-
removed.push(name);
|
|
2970
|
-
}
|
|
2866
|
+
function getWorkqueueLabel(workqueue) {
|
|
2867
|
+
const slugProperty = workqueue.getProperty(SLUG_PROPERTY_NAME);
|
|
2868
|
+
if (!slugProperty || !import_ts_morph13.Node.isPropertyAssignment(slugProperty)) {
|
|
2869
|
+
return "(unknown slug)";
|
|
2971
2870
|
}
|
|
2972
|
-
|
|
2871
|
+
const slugInitializer = slugProperty.getInitializer();
|
|
2872
|
+
if (!slugInitializer || !import_ts_morph13.Node.isStringLiteral(slugInitializer)) {
|
|
2873
|
+
return "(unknown slug)";
|
|
2874
|
+
}
|
|
2875
|
+
return slugInitializer.getLiteralValue();
|
|
2973
2876
|
}
|
|
2974
|
-
function
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2877
|
+
function getActionTypeName(action) {
|
|
2878
|
+
const typeProperty = action.getProperty(TYPE_PROPERTY_NAME7);
|
|
2879
|
+
if (!typeProperty || !import_ts_morph13.Node.isPropertyAssignment(typeProperty)) {
|
|
2880
|
+
return null;
|
|
2881
|
+
}
|
|
2882
|
+
const typeInitializer = typeProperty.getInitializer();
|
|
2883
|
+
if (!typeInitializer) {
|
|
2884
|
+
return null;
|
|
2885
|
+
}
|
|
2886
|
+
if (import_ts_morph13.Node.isStringLiteral(typeInitializer)) {
|
|
2887
|
+
return typeInitializer.getLiteralValue();
|
|
2888
|
+
}
|
|
2889
|
+
if (import_ts_morph13.Node.isPropertyAccessExpression(typeInitializer)) {
|
|
2890
|
+
return typeInitializer.getName();
|
|
2891
|
+
}
|
|
2892
|
+
return null;
|
|
2978
2893
|
}
|
|
2979
|
-
function
|
|
2980
|
-
const
|
|
2981
|
-
if (!
|
|
2982
|
-
|
|
2983
|
-
for (const stmt of [...sourceFile.getVariableStatements()]) {
|
|
2984
|
-
const declarations = [...stmt.getDeclarations()];
|
|
2985
|
-
const declarationsToRemove = declarations.filter((decl) => {
|
|
2986
|
-
const name = decl.getName();
|
|
2987
|
-
const accessedEnvVar = extractEnvAccess(decl.getInitializer()?.getText());
|
|
2988
|
-
return UNUSED_ENV_VARS.has(name) || accessedEnvVar !== null && UNUSED_ENV_VARS.has(accessedEnvVar);
|
|
2989
|
-
});
|
|
2990
|
-
if (declarationsToRemove.length === 0) continue;
|
|
2991
|
-
const namesToRemove = declarationsToRemove.map((decl) => decl.getName());
|
|
2992
|
-
removed.push(...namesToRemove);
|
|
2993
|
-
if (declarationsToRemove.length === declarations.length) {
|
|
2994
|
-
stmt.remove();
|
|
2995
|
-
} else {
|
|
2996
|
-
for (const decl of declarationsToRemove) {
|
|
2997
|
-
decl.remove();
|
|
2998
|
-
}
|
|
2999
|
-
}
|
|
2894
|
+
function isUnsupportedActionType(action) {
|
|
2895
|
+
const typeName = getActionTypeName(action);
|
|
2896
|
+
if (!typeName) {
|
|
2897
|
+
return false;
|
|
3000
2898
|
}
|
|
3001
|
-
return
|
|
2899
|
+
return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
|
|
3002
2900
|
}
|
|
3003
|
-
|
|
3004
|
-
const
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
}
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
const
|
|
3013
|
-
const
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
2901
|
+
function migrateWorkqueueActions(workqueue, relPath) {
|
|
2902
|
+
const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME5);
|
|
2903
|
+
if (!actionsProperty || !import_ts_morph13.Node.isPropertyAssignment(actionsProperty)) {
|
|
2904
|
+
return 0;
|
|
2905
|
+
}
|
|
2906
|
+
const actionsInitializer = actionsProperty.getInitializer();
|
|
2907
|
+
if (!actionsInitializer || !import_ts_morph13.Node.isArrayLiteralExpression(actionsInitializer)) {
|
|
2908
|
+
return 0;
|
|
2909
|
+
}
|
|
2910
|
+
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
2911
|
+
const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
|
|
2912
|
+
if (existingActionProperty) {
|
|
2913
|
+
if (import_ts_morph13.Node.isPropertyAssignment(existingActionProperty)) {
|
|
2914
|
+
const existingActionInitializer = existingActionProperty.getInitializer();
|
|
2915
|
+
if (existingActionInitializer && import_ts_morph13.Node.isObjectLiteralExpression(existingActionInitializer)) {
|
|
2916
|
+
const conditionalsProperty2 = existingActionInitializer.getProperty(
|
|
2917
|
+
CONDITIONALS_PROPERTY_NAME
|
|
2918
|
+
);
|
|
2919
|
+
if (conditionalsProperty2) {
|
|
2920
|
+
conditionalsProperty2.remove();
|
|
2921
|
+
console.log(
|
|
2922
|
+
` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`
|
|
2923
|
+
);
|
|
2924
|
+
}
|
|
2925
|
+
if (isUnsupportedActionType(existingActionInitializer)) {
|
|
2926
|
+
existingActionProperty.remove();
|
|
2927
|
+
console.log(
|
|
2928
|
+
` [${relPath}] Removed unsupported 'action' type on workqueue '${workqueueLabel}'`
|
|
2929
|
+
);
|
|
2930
|
+
}
|
|
2931
|
+
}
|
|
2932
|
+
}
|
|
2933
|
+
actionsProperty.remove();
|
|
3017
2934
|
console.log(
|
|
3018
|
-
` [${
|
|
2935
|
+
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
|
|
3019
2936
|
);
|
|
3020
|
-
|
|
2937
|
+
return 1;
|
|
2938
|
+
}
|
|
2939
|
+
const actionCandidates = actionsInitializer.getElements().filter(
|
|
2940
|
+
(element) => import_ts_morph13.Node.isObjectLiteralExpression(element)
|
|
2941
|
+
);
|
|
2942
|
+
if (actionCandidates.length === 0) {
|
|
2943
|
+
actionsProperty.remove();
|
|
3021
2944
|
console.log(
|
|
3022
|
-
` [${
|
|
2945
|
+
` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`
|
|
3023
2946
|
);
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
2947
|
+
return 1;
|
|
2948
|
+
}
|
|
2949
|
+
if (actionCandidates.length > 1) {
|
|
2950
|
+
const droppedCount = actionCandidates.length - 1;
|
|
2951
|
+
console.warn(
|
|
2952
|
+
` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
|
|
3027
2953
|
);
|
|
3028
2954
|
}
|
|
3029
|
-
const
|
|
3030
|
-
|
|
3031
|
-
|
|
2955
|
+
const conditionalsProperty = actionCandidates[0].getProperty(
|
|
2956
|
+
CONDITIONALS_PROPERTY_NAME
|
|
2957
|
+
);
|
|
2958
|
+
if (conditionalsProperty) {
|
|
2959
|
+
conditionalsProperty.remove();
|
|
3032
2960
|
console.log(
|
|
3033
|
-
` [${
|
|
2961
|
+
` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`
|
|
3034
2962
|
);
|
|
3035
|
-
}
|
|
2963
|
+
}
|
|
2964
|
+
if (isUnsupportedActionType(actionCandidates[0])) {
|
|
2965
|
+
actionsProperty.remove();
|
|
3036
2966
|
console.log(
|
|
3037
|
-
` [${
|
|
2967
|
+
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`
|
|
3038
2968
|
);
|
|
3039
|
-
|
|
3040
|
-
console.log(` [${CONSTANTS_FILE_RELATIVE}] File not found \u2014 skipping.`);
|
|
3041
|
-
}
|
|
3042
|
-
if (envRemoved.length === 0 && constsRemoved.length === 0) {
|
|
3043
|
-
console.log("\nNothing to do.");
|
|
3044
|
-
return;
|
|
2969
|
+
return 1;
|
|
3045
2970
|
}
|
|
2971
|
+
const firstActionText = actionCandidates[0].getText();
|
|
2972
|
+
workqueue.addPropertyAssignment({
|
|
2973
|
+
name: ACTION_PROPERTY_NAME2,
|
|
2974
|
+
initializer: firstActionText
|
|
2975
|
+
});
|
|
2976
|
+
actionsProperty.remove();
|
|
3046
2977
|
console.log(
|
|
3047
|
-
`
|
|
3048
|
-
Done. NOTE: usages of these constants elsewhere in 'src/' may now produce TypeScript errors and need manual review.`
|
|
2978
|
+
` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
|
|
3049
2979
|
);
|
|
2980
|
+
return 1;
|
|
3050
2981
|
}
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
if (!sourceFile) {
|
|
3064
|
-
return {
|
|
3065
|
-
removedHelpers: [],
|
|
3066
|
-
removedImportCount: 0,
|
|
3067
|
-
remainingFhirReferences: 0
|
|
3068
|
-
};
|
|
3069
|
-
}
|
|
3070
|
-
const removedHelpers = [];
|
|
3071
|
-
let removedImportCount = 0;
|
|
3072
|
-
for (const fn of sourceFile.getFunctions()) {
|
|
3073
|
-
const name = fn.getName();
|
|
3074
|
-
if (!name || !HELPER_NAMES.has(name)) continue;
|
|
3075
|
-
removedHelpers.push(name);
|
|
3076
|
-
fn.remove();
|
|
3077
|
-
}
|
|
3078
|
-
for (const stmt of [...sourceFile.getVariableStatements()]) {
|
|
3079
|
-
const declarations = [...stmt.getDeclarations()];
|
|
3080
|
-
const toRemove = declarations.filter((decl) => HELPER_NAMES.has(decl.getName()));
|
|
3081
|
-
if (toRemove.length === 0) continue;
|
|
3082
|
-
removedHelpers.push(...toRemove.map((decl) => decl.getName()));
|
|
3083
|
-
if (toRemove.length === declarations.length) {
|
|
3084
|
-
stmt.remove();
|
|
3085
|
-
} else {
|
|
3086
|
-
for (const decl of toRemove) decl.remove();
|
|
3087
|
-
}
|
|
3088
|
-
}
|
|
3089
|
-
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3090
|
-
const matches = decl.getNamedImports().filter((ni) => ni.getName() === FHIR_IMPORT);
|
|
3091
|
-
if (matches.length === 0) continue;
|
|
3092
|
-
for (const named of matches) {
|
|
3093
|
-
named.remove();
|
|
3094
|
-
removedImportCount++;
|
|
2982
|
+
function processFile11(filePath, project) {
|
|
2983
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
2984
|
+
if (!sourceFile) return 0;
|
|
2985
|
+
let migratedWorkqueues = 0;
|
|
2986
|
+
const relPath = import_path13.default.relative(getCwd(), filePath);
|
|
2987
|
+
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
2988
|
+
import_ts_morph13.SyntaxKind.CallExpression
|
|
2989
|
+
);
|
|
2990
|
+
for (const call of callExpressions) {
|
|
2991
|
+
const expression = call.getExpression();
|
|
2992
|
+
if (!import_ts_morph13.Node.isIdentifier(expression) || expression.getText() !== DEFINE_WORKQUEUES_NAME3) {
|
|
2993
|
+
continue;
|
|
3095
2994
|
}
|
|
3096
|
-
const
|
|
3097
|
-
|
|
3098
|
-
const
|
|
3099
|
-
if (!
|
|
3100
|
-
|
|
2995
|
+
const args2 = call.getArguments();
|
|
2996
|
+
if (args2.length === 0) continue;
|
|
2997
|
+
const workqueuesArg = args2[0];
|
|
2998
|
+
if (!import_ts_morph13.Node.isArrayLiteralExpression(workqueuesArg)) continue;
|
|
2999
|
+
for (const element of workqueuesArg.getElements()) {
|
|
3000
|
+
if (!import_ts_morph13.Node.isObjectLiteralExpression(element)) continue;
|
|
3001
|
+
migratedWorkqueues += migrateWorkqueueActions(element, relPath);
|
|
3101
3002
|
}
|
|
3102
3003
|
}
|
|
3103
|
-
|
|
3104
|
-
return { removedHelpers, removedImportCount, remainingFhirReferences };
|
|
3004
|
+
return migratedWorkqueues;
|
|
3105
3005
|
}
|
|
3106
|
-
async function
|
|
3107
|
-
const
|
|
3108
|
-
|
|
3006
|
+
async function main13() {
|
|
3007
|
+
const srcDir = import_path13.default.join(getCwd(), "src");
|
|
3008
|
+
console.log(`Scanning for defineWorkqueues calls in: ${srcDir}
|
|
3009
|
+
`);
|
|
3010
|
+
const project = new import_ts_morph13.Project({
|
|
3011
|
+
tsConfigFilePath: import_path13.default.resolve(srcDir, "../tsconfig.json"),
|
|
3109
3012
|
skipAddingFilesFromTsConfig: false
|
|
3110
3013
|
});
|
|
3111
3014
|
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3112
3015
|
const fp = sf.getFilePath();
|
|
3113
3016
|
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3114
3017
|
});
|
|
3115
|
-
console.log(`
|
|
3018
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
3116
3019
|
`);
|
|
3117
|
-
let
|
|
3118
|
-
let totalRemovedHelpers = 0;
|
|
3020
|
+
let totalMigrated = 0;
|
|
3119
3021
|
const modifiedFiles = [];
|
|
3120
|
-
const warnings = [];
|
|
3121
3022
|
for (const sourceFile of sourceFiles) {
|
|
3122
3023
|
const filePath = sourceFile.getFilePath();
|
|
3123
|
-
const
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
if (changed) {
|
|
3024
|
+
const migrated = processFile11(filePath, project);
|
|
3025
|
+
if (migrated > 0) {
|
|
3026
|
+
totalMigrated += migrated;
|
|
3127
3027
|
modifiedFiles.push(filePath);
|
|
3128
|
-
totalRemovedImports += result.removedImportCount;
|
|
3129
|
-
totalRemovedHelpers += result.removedHelpers.length;
|
|
3130
|
-
if (result.removedHelpers.length > 0) {
|
|
3131
|
-
console.log(
|
|
3132
|
-
` [${rel}] Removed helper(s): ${result.removedHelpers.join(", ")}`
|
|
3133
|
-
);
|
|
3134
|
-
}
|
|
3135
|
-
if (result.removedImportCount > 0) {
|
|
3136
|
-
console.log(
|
|
3137
|
-
` [${rel}] Removed ${result.removedImportCount} '${FHIR_IMPORT}' import(s)`
|
|
3138
|
-
);
|
|
3139
|
-
}
|
|
3140
|
-
}
|
|
3141
|
-
if (result.remainingFhirReferences > 0) {
|
|
3142
|
-
warnings.push(
|
|
3143
|
-
`${rel}: ${result.remainingFhirReferences} remaining '${FHIR_IMPORT}' reference(s)`
|
|
3144
|
-
);
|
|
3145
3028
|
}
|
|
3146
3029
|
}
|
|
3147
|
-
if (modifiedFiles.length === 0
|
|
3148
|
-
console.log(
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
if (modifiedFiles.length > 0) {
|
|
3152
|
-
console.log(`
|
|
3153
|
-
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
3154
|
-
for (const filePath of modifiedFiles) {
|
|
3155
|
-
await project.getSourceFileOrThrow(filePath).save();
|
|
3156
|
-
console.log(` Saved: ${import_path14.default.relative(process.cwd(), filePath)}`);
|
|
3157
|
-
}
|
|
3158
|
-
}
|
|
3159
|
-
if (warnings.length > 0) {
|
|
3160
|
-
console.warn(
|
|
3161
|
-
`
|
|
3162
|
-
WARNING: Some '${FHIR_IMPORT}' usages remain and need manual cleanup:
|
|
3163
|
-
` + warnings.map((line) => ` - ${line}`).join("\n")
|
|
3164
|
-
);
|
|
3165
|
-
}
|
|
3166
|
-
console.log(
|
|
3167
|
-
`
|
|
3168
|
-
Done. Removed ${totalRemovedHelpers} helper declaration(s) and ${totalRemovedImports} '${FHIR_IMPORT}' import(s).`
|
|
3169
|
-
);
|
|
3170
|
-
}
|
|
3171
|
-
|
|
3172
|
-
// src/migrations/v2.0/migrate-application-config-url.ts
|
|
3173
|
-
var import_path15 = __toESM(require("path"));
|
|
3174
|
-
var import_ts_morph15 = require("ts-morph");
|
|
3175
|
-
var TARGET_IDENTIFIER = "APPLICATION_CONFIG_URL";
|
|
3176
|
-
var REPLACEMENT_IDENTIFIER = "applicationConfig";
|
|
3177
|
-
var REPLACEMENT_MODULE = "@countryconfig/api/application/application-config";
|
|
3178
|
-
var FUNCTION_LIKE_KINDS = [
|
|
3179
|
-
import_ts_morph15.SyntaxKind.FunctionDeclaration,
|
|
3180
|
-
import_ts_morph15.SyntaxKind.FunctionExpression,
|
|
3181
|
-
import_ts_morph15.SyntaxKind.ArrowFunction,
|
|
3182
|
-
import_ts_morph15.SyntaxKind.MethodDeclaration
|
|
3183
|
-
];
|
|
3184
|
-
function describeFunction(node) {
|
|
3185
|
-
if (import_ts_morph15.Node.isFunctionDeclaration(node) || import_ts_morph15.Node.isMethodDeclaration(node)) {
|
|
3186
|
-
return node.getName() ?? "<anonymous>";
|
|
3187
|
-
}
|
|
3188
|
-
const parent = node.getParent();
|
|
3189
|
-
if (parent && import_ts_morph15.Node.isVariableDeclaration(parent)) {
|
|
3190
|
-
return parent.getName();
|
|
3191
|
-
}
|
|
3192
|
-
if (parent && import_ts_morph15.Node.isPropertyAssignment(parent)) {
|
|
3193
|
-
return parent.getName();
|
|
3194
|
-
}
|
|
3195
|
-
if (import_ts_morph15.Node.isFunctionExpression(node) && node.getNameNode() !== void 0) {
|
|
3196
|
-
return node.getNameNode()?.getText() ?? "<anonymous>";
|
|
3197
|
-
}
|
|
3198
|
-
return "<anonymous>";
|
|
3199
|
-
}
|
|
3200
|
-
function hasBlockBody(node) {
|
|
3201
|
-
if (import_ts_morph15.Node.isFunctionDeclaration(node) || import_ts_morph15.Node.isFunctionExpression(node) || import_ts_morph15.Node.isMethodDeclaration(node)) {
|
|
3202
|
-
return node.getBody() !== void 0;
|
|
3203
|
-
}
|
|
3204
|
-
if (import_ts_morph15.Node.isArrowFunction(node)) {
|
|
3205
|
-
return node.getBody().getKind() === import_ts_morph15.SyntaxKind.Block;
|
|
3206
|
-
}
|
|
3207
|
-
return false;
|
|
3208
|
-
}
|
|
3209
|
-
function isConfigFetcher(node) {
|
|
3210
|
-
let referencesTarget = false;
|
|
3211
|
-
let callsFetch = false;
|
|
3212
|
-
for (const id of node.getDescendantsOfKind(import_ts_morph15.SyntaxKind.Identifier)) {
|
|
3213
|
-
const text = id.getText();
|
|
3214
|
-
if (!referencesTarget && text === TARGET_IDENTIFIER) referencesTarget = true;
|
|
3215
|
-
if (!callsFetch && text === "fetch") {
|
|
3216
|
-
const parent = id.getParent();
|
|
3217
|
-
if (import_ts_morph15.Node.isCallExpression(parent) && parent.getExpression() === id) {
|
|
3218
|
-
callsFetch = true;
|
|
3219
|
-
}
|
|
3220
|
-
}
|
|
3221
|
-
if (referencesTarget && callsFetch) return true;
|
|
3222
|
-
}
|
|
3223
|
-
return false;
|
|
3224
|
-
}
|
|
3225
|
-
function processFile11(sourceFile) {
|
|
3226
|
-
const importsWithTarget = sourceFile.getImportDeclarations().filter(
|
|
3227
|
-
(decl) => decl.getNamedImports().some((ni) => ni.getName() === TARGET_IDENTIFIER)
|
|
3228
|
-
);
|
|
3229
|
-
if (importsWithTarget.length === 0) {
|
|
3230
|
-
return { changed: false, rewrittenFunctions: [], renamedReferences: 0 };
|
|
3231
|
-
}
|
|
3232
|
-
const collidingLocals = sourceFile.getDescendantsOfKind(import_ts_morph15.SyntaxKind.Identifier).filter((id) => id.getText() === REPLACEMENT_IDENTIFIER).filter((id) => {
|
|
3233
|
-
const parent = id.getParent();
|
|
3234
|
-
const kind = parent.getKind();
|
|
3235
|
-
return kind === import_ts_morph15.SyntaxKind.VariableDeclaration || kind === import_ts_morph15.SyntaxKind.FunctionDeclaration || kind === import_ts_morph15.SyntaxKind.ClassDeclaration || kind === import_ts_morph15.SyntaxKind.Parameter;
|
|
3236
|
-
});
|
|
3237
|
-
if (collidingLocals.length > 0) {
|
|
3238
|
-
return {
|
|
3239
|
-
changed: false,
|
|
3240
|
-
rewrittenFunctions: [],
|
|
3241
|
-
renamedReferences: 0,
|
|
3242
|
-
skippedReason: `local declaration named '${REPLACEMENT_IDENTIFIER}' would collide`
|
|
3243
|
-
};
|
|
3244
|
-
}
|
|
3245
|
-
const candidateFunctions = FUNCTION_LIKE_KINDS.flatMap(
|
|
3246
|
-
(kind) => sourceFile.getDescendantsOfKind(kind)
|
|
3247
|
-
);
|
|
3248
|
-
candidateFunctions.sort((a, b) => a.getStart() - b.getStart());
|
|
3249
|
-
const rewrittenFunctions = [];
|
|
3250
|
-
const rewrittenSet = /* @__PURE__ */ new Set();
|
|
3251
|
-
for (const fn of candidateFunctions) {
|
|
3252
|
-
if (!hasBlockBody(fn)) continue;
|
|
3253
|
-
if (!isConfigFetcher(fn)) continue;
|
|
3254
|
-
let inRewrittenAncestor = false;
|
|
3255
|
-
let cursor = fn.getParent();
|
|
3256
|
-
while (cursor) {
|
|
3257
|
-
if (rewrittenSet.has(cursor)) {
|
|
3258
|
-
inRewrittenAncestor = true;
|
|
3259
|
-
break;
|
|
3260
|
-
}
|
|
3261
|
-
cursor = cursor.getParent();
|
|
3262
|
-
}
|
|
3263
|
-
if (inRewrittenAncestor) continue;
|
|
3264
|
-
const start = fn.getStart();
|
|
3265
|
-
const line = sourceFile.getLineAndColumnAtPos(start).line;
|
|
3266
|
-
const name = describeFunction(fn);
|
|
3267
|
-
if (import_ts_morph15.Node.isFunctionDeclaration(fn) || import_ts_morph15.Node.isFunctionExpression(fn) || import_ts_morph15.Node.isMethodDeclaration(fn) || import_ts_morph15.Node.isArrowFunction(fn)) {
|
|
3268
|
-
fn.setBodyText(`return ${REPLACEMENT_IDENTIFIER}`);
|
|
3269
|
-
}
|
|
3270
|
-
rewrittenFunctions.push({ name, line });
|
|
3271
|
-
rewrittenSet.add(fn);
|
|
3272
|
-
}
|
|
3273
|
-
for (const decl of importsWithTarget) {
|
|
3274
|
-
const targetNamed = decl.getNamedImports().find((ni) => ni.getName() === TARGET_IDENTIFIER);
|
|
3275
|
-
targetNamed?.remove();
|
|
3276
|
-
const isNowEmpty = decl.getNamedImports().length === 0 && !decl.getDefaultImport() && !decl.getNamespaceImport();
|
|
3277
|
-
if (isNowEmpty) decl.remove();
|
|
3278
|
-
}
|
|
3279
|
-
const existing = sourceFile.getImportDeclaration(
|
|
3280
|
-
(decl) => decl.getModuleSpecifierValue() === REPLACEMENT_MODULE
|
|
3281
|
-
);
|
|
3282
|
-
if (existing) {
|
|
3283
|
-
const alreadyImported = existing.getNamedImports().some((ni) => ni.getName() === REPLACEMENT_IDENTIFIER);
|
|
3284
|
-
if (!alreadyImported) existing.addNamedImport(REPLACEMENT_IDENTIFIER);
|
|
3285
|
-
} else {
|
|
3286
|
-
sourceFile.addImportDeclaration({
|
|
3287
|
-
moduleSpecifier: REPLACEMENT_MODULE,
|
|
3288
|
-
namedImports: [REPLACEMENT_IDENTIFIER]
|
|
3289
|
-
});
|
|
3290
|
-
}
|
|
3291
|
-
const renameTargets = sourceFile.getDescendantsOfKind(import_ts_morph15.SyntaxKind.Identifier).filter((id) => id.getText() === TARGET_IDENTIFIER).filter((id) => !id.getFirstAncestorByKind(import_ts_morph15.SyntaxKind.ImportDeclaration)).filter((id) => {
|
|
3292
|
-
const parent = id.getParent();
|
|
3293
|
-
const parentKind = parent.getKind();
|
|
3294
|
-
if (parentKind === import_ts_morph15.SyntaxKind.PropertyAccessExpression) {
|
|
3295
|
-
const pae = parent.asKind(import_ts_morph15.SyntaxKind.PropertyAccessExpression);
|
|
3296
|
-
if (pae.getNameNode() === id) return false;
|
|
3297
|
-
}
|
|
3298
|
-
if (parentKind === import_ts_morph15.SyntaxKind.PropertyAssignment) {
|
|
3299
|
-
const pa = parent.asKind(import_ts_morph15.SyntaxKind.PropertyAssignment);
|
|
3300
|
-
if (pa.getNameNode() === id) return false;
|
|
3301
|
-
}
|
|
3302
|
-
if (parentKind === import_ts_morph15.SyntaxKind.ShorthandPropertyAssignment) {
|
|
3303
|
-
return false;
|
|
3304
|
-
}
|
|
3305
|
-
return true;
|
|
3306
|
-
}).sort((a, b) => b.getPos() - a.getPos());
|
|
3307
|
-
for (const id of renameTargets) {
|
|
3308
|
-
id.replaceWithText(REPLACEMENT_IDENTIFIER);
|
|
3309
|
-
}
|
|
3310
|
-
return {
|
|
3311
|
-
changed: true,
|
|
3312
|
-
rewrittenFunctions,
|
|
3313
|
-
renamedReferences: renameTargets.length
|
|
3314
|
-
};
|
|
3315
|
-
}
|
|
3316
|
-
async function main15() {
|
|
3317
|
-
const project = new import_ts_morph15.Project({
|
|
3318
|
-
tsConfigFilePath: import_path15.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3319
|
-
skipAddingFilesFromTsConfig: false
|
|
3320
|
-
});
|
|
3321
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3322
|
-
const fp = sf.getFilePath();
|
|
3323
|
-
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3324
|
-
});
|
|
3325
|
-
console.log(
|
|
3326
|
-
`Migrating '${TARGET_IDENTIFIER}' \u2192 '${REPLACEMENT_IDENTIFIER}' across ${sourceFiles.length} source file(s)...
|
|
3327
|
-
`
|
|
3328
|
-
);
|
|
3329
|
-
let changedFiles = 0;
|
|
3330
|
-
let totalRewrittenFunctions = 0;
|
|
3331
|
-
let totalRenamedReferences = 0;
|
|
3332
|
-
const skipped = [];
|
|
3333
|
-
for (const sourceFile of sourceFiles) {
|
|
3334
|
-
const filePath = sourceFile.getFilePath();
|
|
3335
|
-
const rel = import_path15.default.relative(process.cwd(), filePath);
|
|
3336
|
-
const result = processFile11(sourceFile);
|
|
3337
|
-
if (result.skippedReason) {
|
|
3338
|
-
skipped.push(`${rel} (${result.skippedReason})`);
|
|
3339
|
-
continue;
|
|
3340
|
-
}
|
|
3341
|
-
if (!result.changed) continue;
|
|
3342
|
-
await sourceFile.save();
|
|
3343
|
-
changedFiles++;
|
|
3344
|
-
totalRewrittenFunctions += result.rewrittenFunctions.length;
|
|
3345
|
-
totalRenamedReferences += result.renamedReferences;
|
|
3346
|
-
for (const fn of result.rewrittenFunctions) {
|
|
3347
|
-
console.log(
|
|
3348
|
-
` [${rel}:${fn.line}] Rewrote '${fn.name}' body \u2192 'return ${REPLACEMENT_IDENTIFIER}' (config fetch eliminated)`
|
|
3349
|
-
);
|
|
3350
|
-
}
|
|
3351
|
-
if (result.renamedReferences > 0) {
|
|
3352
|
-
console.log(
|
|
3353
|
-
` [${rel}] Renamed ${result.renamedReferences} stray reference(s) ${TARGET_IDENTIFIER} \u2192 ${REPLACEMENT_IDENTIFIER}`
|
|
3354
|
-
);
|
|
3355
|
-
}
|
|
3356
|
-
}
|
|
3357
|
-
if (skipped.length > 0) {
|
|
3358
|
-
console.warn(
|
|
3359
|
-
`
|
|
3360
|
-
${skipped.length} file(s) skipped:
|
|
3361
|
-
` + skipped.map((s) => ` - ${s}`).join("\n")
|
|
3362
|
-
);
|
|
3363
|
-
}
|
|
3364
|
-
if (changedFiles === 0) {
|
|
3365
|
-
console.log(`
|
|
3366
|
-
No files reference '${TARGET_IDENTIFIER}'. Nothing to do.`);
|
|
3367
|
-
return;
|
|
3368
|
-
}
|
|
3369
|
-
console.log(
|
|
3370
|
-
`
|
|
3371
|
-
Done. Updated ${changedFiles} file(s): ${totalRewrittenFunctions} fetch function(s) rewritten, ${totalRenamedReferences} bare reference(s) renamed.`
|
|
3372
|
-
);
|
|
3373
|
-
if (totalRewrittenFunctions > 0) {
|
|
3374
|
-
console.log(
|
|
3375
|
-
`NOTE: rewriting fetch functions discards any custom logic that lived inside them. Review the diff and re-apply any country-specific adjustments on top of '${REPLACEMENT_IDENTIFIER}'.`
|
|
3376
|
-
);
|
|
3377
|
-
}
|
|
3378
|
-
}
|
|
3379
|
-
|
|
3380
|
-
// src/migrations/v2.0/remove-old-statistics-service.ts
|
|
3381
|
-
var import_path16 = __toESM(require("path"));
|
|
3382
|
-
var import_ts_morph16 = require("ts-morph");
|
|
3383
|
-
var ROUTE_PATH = "/statistics";
|
|
3384
|
-
var HANDLER_NAME = "statisticsHandler";
|
|
3385
|
-
function isStatisticsRouteObject(obj) {
|
|
3386
|
-
const pathProp = obj.getProperty("path");
|
|
3387
|
-
if (!pathProp || !import_ts_morph16.Node.isPropertyAssignment(pathProp)) return false;
|
|
3388
|
-
const init = pathProp.getInitializer();
|
|
3389
|
-
if (!init) return false;
|
|
3390
|
-
if (import_ts_morph16.Node.isStringLiteral(init) || import_ts_morph16.Node.isNoSubstitutionTemplateLiteral(init)) {
|
|
3391
|
-
return init.getLiteralValue() === ROUTE_PATH;
|
|
3392
|
-
}
|
|
3393
|
-
return false;
|
|
3394
|
-
}
|
|
3395
|
-
function removeStatisticsRoutes(sourceFile) {
|
|
3396
|
-
let removed = 0;
|
|
3397
|
-
const callExpressions = [
|
|
3398
|
-
...sourceFile.getDescendantsOfKind(import_ts_morph16.SyntaxKind.CallExpression)
|
|
3399
|
-
];
|
|
3400
|
-
for (const call of callExpressions) {
|
|
3401
|
-
if (call.wasForgotten()) continue;
|
|
3402
|
-
const expr = call.getExpression();
|
|
3403
|
-
if (!import_ts_morph16.Node.isPropertyAccessExpression(expr)) continue;
|
|
3404
|
-
if (expr.getName() !== "route") continue;
|
|
3405
|
-
const args2 = call.getArguments();
|
|
3406
|
-
if (args2.length === 0) continue;
|
|
3407
|
-
const firstArg = args2[0];
|
|
3408
|
-
if (import_ts_morph16.Node.isObjectLiteralExpression(firstArg)) {
|
|
3409
|
-
if (!isStatisticsRouteObject(firstArg)) continue;
|
|
3410
|
-
const stmt = call.getFirstAncestorByKind(import_ts_morph16.SyntaxKind.ExpressionStatement);
|
|
3411
|
-
if (stmt) {
|
|
3412
|
-
stmt.remove();
|
|
3413
|
-
removed++;
|
|
3414
|
-
} else {
|
|
3415
|
-
call.replaceWithText("");
|
|
3416
|
-
removed++;
|
|
3417
|
-
}
|
|
3418
|
-
continue;
|
|
3419
|
-
}
|
|
3420
|
-
if (import_ts_morph16.Node.isArrayLiteralExpression(firstArg)) {
|
|
3421
|
-
const matchingIndexes = firstArg.getElements().map((el, idx) => ({ el, idx })).filter(
|
|
3422
|
-
({ el }) => import_ts_morph16.Node.isObjectLiteralExpression(el) && isStatisticsRouteObject(el)
|
|
3423
|
-
).map(({ idx }) => idx);
|
|
3424
|
-
matchingIndexes.sort((a, b) => b - a).forEach((idx) => {
|
|
3425
|
-
firstArg.removeElement(idx);
|
|
3426
|
-
removed++;
|
|
3427
|
-
});
|
|
3428
|
-
}
|
|
3429
|
-
}
|
|
3430
|
-
return removed;
|
|
3431
|
-
}
|
|
3432
|
-
function removeStatisticsHandlerImports(sourceFile) {
|
|
3433
|
-
let changed = false;
|
|
3434
|
-
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3435
|
-
const targetNamed = decl.getNamedImports().find((ni) => ni.getName() === HANDLER_NAME);
|
|
3436
|
-
if (!targetNamed) continue;
|
|
3437
|
-
targetNamed.remove();
|
|
3438
|
-
changed = true;
|
|
3439
|
-
const isNowEmpty = decl.getNamedImports().length === 0 && !decl.getDefaultImport() && !decl.getNamespaceImport();
|
|
3440
|
-
if (isNowEmpty) decl.remove();
|
|
3441
|
-
}
|
|
3442
|
-
return changed;
|
|
3443
|
-
}
|
|
3444
|
-
function processFile12(sourceFile) {
|
|
3445
|
-
const routesRemoved = removeStatisticsRoutes(sourceFile);
|
|
3446
|
-
const importsCleaned = removeStatisticsHandlerImports(sourceFile);
|
|
3447
|
-
return { routesRemoved, importsCleaned };
|
|
3448
|
-
}
|
|
3449
|
-
function collectLocalImportsInSubtree(sourceFile, subtreeRoot) {
|
|
3450
|
-
const result = [];
|
|
3451
|
-
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3452
|
-
const moduleSf = decl.getModuleSpecifierSourceFile();
|
|
3453
|
-
if (!moduleSf) continue;
|
|
3454
|
-
const fp = moduleSf.getFilePath();
|
|
3455
|
-
if (!fp.startsWith(subtreeRoot)) continue;
|
|
3456
|
-
result.push(fp);
|
|
3457
|
-
}
|
|
3458
|
-
return result;
|
|
3459
|
-
}
|
|
3460
|
-
function deleteOrphanedDescendants(project, startingFile, subtreeRoot) {
|
|
3461
|
-
const initialCandidates = collectLocalImportsInSubtree(
|
|
3462
|
-
startingFile,
|
|
3463
|
-
subtreeRoot
|
|
3464
|
-
);
|
|
3465
|
-
const startingPath = startingFile.getFilePath();
|
|
3466
|
-
const deleted = /* @__PURE__ */ new Set([startingPath]);
|
|
3467
|
-
const seen = /* @__PURE__ */ new Set();
|
|
3468
|
-
const worklist = [...initialCandidates];
|
|
3469
|
-
const orphans = [];
|
|
3470
|
-
while (worklist.length > 0) {
|
|
3471
|
-
const candidate = worklist.shift();
|
|
3472
|
-
if (seen.has(candidate)) continue;
|
|
3473
|
-
seen.add(candidate);
|
|
3474
|
-
if (deleted.has(candidate)) continue;
|
|
3475
|
-
if (!candidate.startsWith(subtreeRoot)) continue;
|
|
3476
|
-
const candidateSf = project.getSourceFile(candidate);
|
|
3477
|
-
if (!candidateSf) continue;
|
|
3478
|
-
const stillImported = project.getSourceFiles().some((sf) => {
|
|
3479
|
-
const sfPath = sf.getFilePath();
|
|
3480
|
-
if (deleted.has(sfPath)) return false;
|
|
3481
|
-
if (sfPath === candidate) return false;
|
|
3482
|
-
return sf.getImportDeclarations().some(
|
|
3483
|
-
(decl) => decl.getModuleSpecifierSourceFile()?.getFilePath() === candidate
|
|
3484
|
-
);
|
|
3485
|
-
});
|
|
3486
|
-
if (stillImported) continue;
|
|
3487
|
-
const next = collectLocalImportsInSubtree(candidateSf, subtreeRoot);
|
|
3488
|
-
worklist.push(...next);
|
|
3489
|
-
candidateSf.delete();
|
|
3490
|
-
deleted.add(candidate);
|
|
3491
|
-
orphans.push(candidate);
|
|
3492
|
-
}
|
|
3493
|
-
return orphans;
|
|
3494
|
-
}
|
|
3495
|
-
function processHandlerFile(project) {
|
|
3496
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3497
|
-
const fp = sf.getFilePath();
|
|
3498
|
-
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3499
|
-
});
|
|
3500
|
-
for (const sf of sourceFiles) {
|
|
3501
|
-
const fn = sf.getFunction(HANDLER_NAME);
|
|
3502
|
-
if (!fn) continue;
|
|
3503
|
-
const filePath = sf.getFilePath();
|
|
3504
|
-
const exportsByName = [...sf.getExportedDeclarations().keys()];
|
|
3505
|
-
const otherExports = exportsByName.filter((name) => name !== HANDLER_NAME);
|
|
3506
|
-
if (otherExports.length === 0) {
|
|
3507
|
-
const subtreeRoot = import_path16.default.dirname(filePath) + import_path16.default.sep;
|
|
3508
|
-
const orphansDeleted = deleteOrphanedDescendants(
|
|
3509
|
-
project,
|
|
3510
|
-
sf,
|
|
3511
|
-
subtreeRoot
|
|
3512
|
-
);
|
|
3513
|
-
sf.delete();
|
|
3514
|
-
return { filePath, action: "deleted", orphansDeleted };
|
|
3515
|
-
}
|
|
3516
|
-
fn.remove();
|
|
3517
|
-
return {
|
|
3518
|
-
filePath,
|
|
3519
|
-
action: "function-removed",
|
|
3520
|
-
remainingExports: otherExports,
|
|
3521
|
-
orphansDeleted: []
|
|
3522
|
-
};
|
|
3523
|
-
}
|
|
3524
|
-
return { filePath: "", action: "not-found", orphansDeleted: [] };
|
|
3525
|
-
}
|
|
3526
|
-
async function main16() {
|
|
3527
|
-
const project = new import_ts_morph16.Project({
|
|
3528
|
-
tsConfigFilePath: import_path16.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3529
|
-
skipAddingFilesFromTsConfig: false
|
|
3530
|
-
});
|
|
3531
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3532
|
-
const fp = sf.getFilePath();
|
|
3533
|
-
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3534
|
-
});
|
|
3535
|
-
console.log(
|
|
3536
|
-
`Removing legacy 'GET ${ROUTE_PATH}' route and '${HANDLER_NAME}' across ${sourceFiles.length} source file(s)...
|
|
3537
|
-
`
|
|
3538
|
-
);
|
|
3539
|
-
let totalRoutesRemoved = 0;
|
|
3540
|
-
let totalFilesWithImportsCleaned = 0;
|
|
3541
|
-
let totalFilesWithRoutesRemoved = 0;
|
|
3542
|
-
for (const sourceFile of sourceFiles) {
|
|
3543
|
-
const filePath = sourceFile.getFilePath();
|
|
3544
|
-
const rel = import_path16.default.relative(process.cwd(), filePath);
|
|
3545
|
-
const result = processFile12(sourceFile);
|
|
3546
|
-
if (result.routesRemoved > 0) {
|
|
3547
|
-
console.log(
|
|
3548
|
-
` [${rel}] Removed ${result.routesRemoved} '${ROUTE_PATH}' route(s)`
|
|
3549
|
-
);
|
|
3550
|
-
totalRoutesRemoved += result.routesRemoved;
|
|
3551
|
-
totalFilesWithRoutesRemoved++;
|
|
3552
|
-
}
|
|
3553
|
-
if (result.importsCleaned) {
|
|
3554
|
-
console.log(` [${rel}] Cleaned up '${HANDLER_NAME}' import`);
|
|
3555
|
-
totalFilesWithImportsCleaned++;
|
|
3556
|
-
}
|
|
3557
|
-
if (result.routesRemoved > 0 || result.importsCleaned) {
|
|
3558
|
-
await sourceFile.save();
|
|
3559
|
-
}
|
|
3560
|
-
}
|
|
3561
|
-
const handlerResult = processHandlerFile(project);
|
|
3562
|
-
switch (handlerResult.action) {
|
|
3563
|
-
case "deleted": {
|
|
3564
|
-
const rel = import_path16.default.relative(process.cwd(), handlerResult.filePath);
|
|
3565
|
-
console.log(
|
|
3566
|
-
` [${rel}] Deleted handler file ('${HANDLER_NAME}' was the sole export).`
|
|
3567
|
-
);
|
|
3568
|
-
for (const orphanPath of handlerResult.orphansDeleted) {
|
|
3569
|
-
const orphanRel = import_path16.default.relative(process.cwd(), orphanPath);
|
|
3570
|
-
console.log(
|
|
3571
|
-
` [${orphanRel}] Deleted (no remaining importers in the project after handler removal).`
|
|
3572
|
-
);
|
|
3573
|
-
}
|
|
3574
|
-
await project.save();
|
|
3575
|
-
break;
|
|
3576
|
-
}
|
|
3577
|
-
case "function-removed": {
|
|
3578
|
-
const rel = import_path16.default.relative(process.cwd(), handlerResult.filePath);
|
|
3579
|
-
console.warn(
|
|
3580
|
-
` [${rel}] Removed '${HANDLER_NAME}' function but kept the file (other exports remain: ${handlerResult.remainingExports?.join(", ")}). Review whether the file is still needed.`
|
|
3581
|
-
);
|
|
3582
|
-
const sf = project.getSourceFile(handlerResult.filePath);
|
|
3583
|
-
if (sf) await sf.save();
|
|
3584
|
-
break;
|
|
3585
|
-
}
|
|
3586
|
-
case "not-found":
|
|
3587
|
-
break;
|
|
3588
|
-
}
|
|
3589
|
-
if (totalRoutesRemoved === 0 && totalFilesWithImportsCleaned === 0 && handlerResult.action === "not-found") {
|
|
3590
|
-
console.log(`
|
|
3591
|
-
No legacy '${ROUTE_PATH}' route or handler found. Nothing to do.`);
|
|
3592
|
-
return;
|
|
3593
|
-
}
|
|
3594
|
-
const orphansSummary = handlerResult.orphansDeleted.length > 0 ? ` and ${handlerResult.orphansDeleted.length} orphaned helper file(s)` : "";
|
|
3595
|
-
console.log(
|
|
3596
|
-
`
|
|
3597
|
-
Done. Removed ${totalRoutesRemoved} route(s) across ${totalFilesWithRoutesRemoved} file(s); cleaned ${HANDLER_NAME} import in ${totalFilesWithImportsCleaned} file(s)${orphansSummary}.`
|
|
3598
|
-
);
|
|
3599
|
-
}
|
|
3600
|
-
|
|
3601
|
-
// src/migrations/v2.0/update-package-json.ts
|
|
3602
|
-
var import_fs = require("fs");
|
|
3603
|
-
var import_path17 = __toESM(require("path"));
|
|
3604
|
-
var PACKAGE_JSON_RELATIVE = "package.json";
|
|
3605
|
-
var TARGET_VERSION = "2.0.0";
|
|
3606
|
-
var TARGET_ZOD_RANGE = "^4.2.1";
|
|
3607
|
-
async function main17() {
|
|
3608
|
-
const packageJsonPath = import_path17.default.join(process.cwd(), PACKAGE_JSON_RELATIVE);
|
|
3609
|
-
if (!(0, import_fs.existsSync)(packageJsonPath)) {
|
|
3610
|
-
console.log(`'${PACKAGE_JSON_RELATIVE}' not found in ${process.cwd()} \u2014 skipping.`);
|
|
3611
|
-
return;
|
|
3612
|
-
}
|
|
3613
|
-
const raw = (0, import_fs.readFileSync)(packageJsonPath, "utf8");
|
|
3614
|
-
let parsed;
|
|
3615
|
-
try {
|
|
3616
|
-
parsed = JSON.parse(raw);
|
|
3617
|
-
} catch (error) {
|
|
3618
|
-
console.warn(
|
|
3619
|
-
` [${PACKAGE_JSON_RELATIVE}] Failed to parse JSON \u2014 skipping update. ${error.message}`
|
|
3620
|
-
);
|
|
3621
|
-
return;
|
|
3622
|
-
}
|
|
3623
|
-
console.log(`Updating '${PACKAGE_JSON_RELATIVE}'...`);
|
|
3624
|
-
const previousVersion = parsed.version;
|
|
3625
|
-
const versionChanged = previousVersion !== TARGET_VERSION;
|
|
3626
|
-
parsed.version = TARGET_VERSION;
|
|
3627
|
-
if (versionChanged) {
|
|
3628
|
-
console.log(
|
|
3629
|
-
` Set version: ${previousVersion ?? "<unset>"} \u2192 ${TARGET_VERSION}`
|
|
3630
|
-
);
|
|
3631
|
-
} else {
|
|
3632
|
-
console.log(` Version already ${TARGET_VERSION} \u2014 no change.`);
|
|
3633
|
-
}
|
|
3634
|
-
let zodBucket = "dependencies";
|
|
3635
|
-
if (parsed.devDependencies && "zod" in parsed.devDependencies) {
|
|
3636
|
-
zodBucket = "devDependencies";
|
|
3637
|
-
}
|
|
3638
|
-
if (!parsed[zodBucket]) {
|
|
3639
|
-
parsed[zodBucket] = {};
|
|
3640
|
-
}
|
|
3641
|
-
const bucket = parsed[zodBucket];
|
|
3642
|
-
const previousZod = bucket.zod;
|
|
3643
|
-
const zodChanged = previousZod !== TARGET_ZOD_RANGE;
|
|
3644
|
-
bucket.zod = TARGET_ZOD_RANGE;
|
|
3645
|
-
if (zodChanged) {
|
|
3646
|
-
console.log(
|
|
3647
|
-
` Set ${zodBucket}.zod: ${previousZod ?? "<absent>"} \u2192 ${TARGET_ZOD_RANGE}`
|
|
3648
|
-
);
|
|
3649
|
-
} else {
|
|
3650
|
-
console.log(` ${zodBucket}.zod already ${TARGET_ZOD_RANGE} \u2014 no change.`);
|
|
3651
|
-
}
|
|
3652
|
-
const trailingNewline = raw.endsWith("\n") ? "\n" : "";
|
|
3653
|
-
const next = JSON.stringify(parsed, null, 2) + trailingNewline;
|
|
3654
|
-
if (next === raw) {
|
|
3655
|
-
console.log("\n No changes to write.");
|
|
3656
|
-
return;
|
|
3657
|
-
}
|
|
3658
|
-
(0, import_fs.writeFileSync)(packageJsonPath, next, "utf8");
|
|
3659
|
-
console.log(`
|
|
3660
|
-
Saved '${PACKAGE_JSON_RELATIVE}'.`);
|
|
3661
|
-
console.log(
|
|
3662
|
-
` NOTE: run \`yarn install\` (or your package manager equivalent) to install the updated dependency versions.`
|
|
3663
|
-
);
|
|
3664
|
-
}
|
|
3665
|
-
|
|
3666
|
-
// src/migrations/v2.0/migrate-workqueue-configs.ts
|
|
3667
|
-
var import_ts_morph17 = require("ts-morph");
|
|
3668
|
-
var import_path18 = __toESM(require("path"));
|
|
3669
|
-
var DEFINE_WORKQUEUES_NAME3 = "defineWorkqueues";
|
|
3670
|
-
var ACTIONS_PROPERTY_NAME5 = "actions";
|
|
3671
|
-
var ACTION_PROPERTY_NAME2 = "action";
|
|
3672
|
-
var CONDITIONALS_PROPERTY_NAME = "conditionals";
|
|
3673
|
-
var TYPE_PROPERTY_NAME7 = "type";
|
|
3674
|
-
var SLUG_PROPERTY_NAME = "slug";
|
|
3675
|
-
var SUPPORTED_WORKQUEUE_ACTION_TYPES = /* @__PURE__ */ new Set([
|
|
3676
|
-
"READ",
|
|
3677
|
-
"DELETE",
|
|
3678
|
-
"DECLARE",
|
|
3679
|
-
"REGISTER",
|
|
3680
|
-
"EDIT",
|
|
3681
|
-
"REJECT",
|
|
3682
|
-
"MARK_AS_DUPLICATE",
|
|
3683
|
-
"ARCHIVE",
|
|
3684
|
-
"PRINT_CERTIFICATE",
|
|
3685
|
-
"REQUEST_CORRECTION"
|
|
3686
|
-
]);
|
|
3687
|
-
function getWorkqueueLabel(workqueue) {
|
|
3688
|
-
const slugProperty = workqueue.getProperty(SLUG_PROPERTY_NAME);
|
|
3689
|
-
if (!slugProperty || !import_ts_morph17.Node.isPropertyAssignment(slugProperty)) {
|
|
3690
|
-
return "(unknown slug)";
|
|
3691
|
-
}
|
|
3692
|
-
const slugInitializer = slugProperty.getInitializer();
|
|
3693
|
-
if (!slugInitializer || !import_ts_morph17.Node.isStringLiteral(slugInitializer)) {
|
|
3694
|
-
return "(unknown slug)";
|
|
3695
|
-
}
|
|
3696
|
-
return slugInitializer.getLiteralValue();
|
|
3697
|
-
}
|
|
3698
|
-
function getActionTypeName(action) {
|
|
3699
|
-
const typeProperty = action.getProperty(TYPE_PROPERTY_NAME7);
|
|
3700
|
-
if (!typeProperty || !import_ts_morph17.Node.isPropertyAssignment(typeProperty)) {
|
|
3701
|
-
return null;
|
|
3702
|
-
}
|
|
3703
|
-
const typeInitializer = typeProperty.getInitializer();
|
|
3704
|
-
if (!typeInitializer) {
|
|
3705
|
-
return null;
|
|
3706
|
-
}
|
|
3707
|
-
if (import_ts_morph17.Node.isStringLiteral(typeInitializer)) {
|
|
3708
|
-
return typeInitializer.getLiteralValue();
|
|
3709
|
-
}
|
|
3710
|
-
if (import_ts_morph17.Node.isPropertyAccessExpression(typeInitializer)) {
|
|
3711
|
-
return typeInitializer.getName();
|
|
3712
|
-
}
|
|
3713
|
-
return null;
|
|
3714
|
-
}
|
|
3715
|
-
function isUnsupportedActionType(action) {
|
|
3716
|
-
const typeName = getActionTypeName(action);
|
|
3717
|
-
if (!typeName) {
|
|
3718
|
-
return false;
|
|
3719
|
-
}
|
|
3720
|
-
return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
|
|
3721
|
-
}
|
|
3722
|
-
function migrateWorkqueueActions(workqueue, relPath) {
|
|
3723
|
-
const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME5);
|
|
3724
|
-
if (!actionsProperty || !import_ts_morph17.Node.isPropertyAssignment(actionsProperty)) {
|
|
3725
|
-
return 0;
|
|
3726
|
-
}
|
|
3727
|
-
const actionsInitializer = actionsProperty.getInitializer();
|
|
3728
|
-
if (!actionsInitializer || !import_ts_morph17.Node.isArrayLiteralExpression(actionsInitializer)) {
|
|
3729
|
-
return 0;
|
|
3730
|
-
}
|
|
3731
|
-
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
3732
|
-
const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
|
|
3733
|
-
if (existingActionProperty) {
|
|
3734
|
-
if (import_ts_morph17.Node.isPropertyAssignment(existingActionProperty)) {
|
|
3735
|
-
const existingActionInitializer = existingActionProperty.getInitializer();
|
|
3736
|
-
if (existingActionInitializer && import_ts_morph17.Node.isObjectLiteralExpression(existingActionInitializer)) {
|
|
3737
|
-
const conditionalsProperty2 = existingActionInitializer.getProperty(
|
|
3738
|
-
CONDITIONALS_PROPERTY_NAME
|
|
3739
|
-
);
|
|
3740
|
-
if (conditionalsProperty2) {
|
|
3741
|
-
conditionalsProperty2.remove();
|
|
3742
|
-
console.log(
|
|
3743
|
-
` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`
|
|
3744
|
-
);
|
|
3745
|
-
}
|
|
3746
|
-
if (isUnsupportedActionType(existingActionInitializer)) {
|
|
3747
|
-
existingActionProperty.remove();
|
|
3748
|
-
console.log(
|
|
3749
|
-
` [${relPath}] Removed unsupported 'action' type on workqueue '${workqueueLabel}'`
|
|
3750
|
-
);
|
|
3751
|
-
}
|
|
3752
|
-
}
|
|
3753
|
-
}
|
|
3754
|
-
actionsProperty.remove();
|
|
3755
|
-
console.log(
|
|
3756
|
-
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
|
|
3757
|
-
);
|
|
3758
|
-
return 1;
|
|
3759
|
-
}
|
|
3760
|
-
const actionCandidates = actionsInitializer.getElements().filter(
|
|
3761
|
-
(element) => import_ts_morph17.Node.isObjectLiteralExpression(element)
|
|
3762
|
-
);
|
|
3763
|
-
if (actionCandidates.length === 0) {
|
|
3764
|
-
actionsProperty.remove();
|
|
3765
|
-
console.log(
|
|
3766
|
-
` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`
|
|
3767
|
-
);
|
|
3768
|
-
return 1;
|
|
3769
|
-
}
|
|
3770
|
-
if (actionCandidates.length > 1) {
|
|
3771
|
-
const droppedCount = actionCandidates.length - 1;
|
|
3772
|
-
console.warn(
|
|
3773
|
-
` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
|
|
3774
|
-
);
|
|
3775
|
-
}
|
|
3776
|
-
const conditionalsProperty = actionCandidates[0].getProperty(
|
|
3777
|
-
CONDITIONALS_PROPERTY_NAME
|
|
3778
|
-
);
|
|
3779
|
-
if (conditionalsProperty) {
|
|
3780
|
-
conditionalsProperty.remove();
|
|
3781
|
-
console.log(
|
|
3782
|
-
` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`
|
|
3783
|
-
);
|
|
3784
|
-
}
|
|
3785
|
-
if (isUnsupportedActionType(actionCandidates[0])) {
|
|
3786
|
-
actionsProperty.remove();
|
|
3787
|
-
console.log(
|
|
3788
|
-
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`
|
|
3789
|
-
);
|
|
3790
|
-
return 1;
|
|
3791
|
-
}
|
|
3792
|
-
const firstActionText = actionCandidates[0].getText();
|
|
3793
|
-
workqueue.addPropertyAssignment({
|
|
3794
|
-
name: ACTION_PROPERTY_NAME2,
|
|
3795
|
-
initializer: firstActionText
|
|
3796
|
-
});
|
|
3797
|
-
actionsProperty.remove();
|
|
3798
|
-
console.log(
|
|
3799
|
-
` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
|
|
3800
|
-
);
|
|
3801
|
-
return 1;
|
|
3802
|
-
}
|
|
3803
|
-
function processFile13(filePath, project) {
|
|
3804
|
-
const sourceFile = project.getSourceFile(filePath);
|
|
3805
|
-
if (!sourceFile) return 0;
|
|
3806
|
-
let migratedWorkqueues = 0;
|
|
3807
|
-
const relPath = import_path18.default.relative(process.cwd(), filePath);
|
|
3808
|
-
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
3809
|
-
import_ts_morph17.SyntaxKind.CallExpression
|
|
3810
|
-
);
|
|
3811
|
-
for (const call of callExpressions) {
|
|
3812
|
-
const expression = call.getExpression();
|
|
3813
|
-
if (!import_ts_morph17.Node.isIdentifier(expression) || expression.getText() !== DEFINE_WORKQUEUES_NAME3) {
|
|
3814
|
-
continue;
|
|
3815
|
-
}
|
|
3816
|
-
const args2 = call.getArguments();
|
|
3817
|
-
if (args2.length === 0) continue;
|
|
3818
|
-
const workqueuesArg = args2[0];
|
|
3819
|
-
if (!import_ts_morph17.Node.isArrayLiteralExpression(workqueuesArg)) continue;
|
|
3820
|
-
for (const element of workqueuesArg.getElements()) {
|
|
3821
|
-
if (!import_ts_morph17.Node.isObjectLiteralExpression(element)) continue;
|
|
3822
|
-
migratedWorkqueues += migrateWorkqueueActions(element, relPath);
|
|
3823
|
-
}
|
|
3824
|
-
}
|
|
3825
|
-
return migratedWorkqueues;
|
|
3826
|
-
}
|
|
3827
|
-
async function main18() {
|
|
3828
|
-
const srcDir = import_path18.default.join(process.cwd(), "src");
|
|
3829
|
-
console.log(`Scanning for defineWorkqueues calls in: ${srcDir}
|
|
3830
|
-
`);
|
|
3831
|
-
const project = new import_ts_morph17.Project({
|
|
3832
|
-
tsConfigFilePath: import_path18.default.resolve(srcDir, "../tsconfig.json"),
|
|
3833
|
-
skipAddingFilesFromTsConfig: false
|
|
3834
|
-
});
|
|
3835
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3836
|
-
const fp = sf.getFilePath();
|
|
3837
|
-
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3838
|
-
});
|
|
3839
|
-
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
3840
|
-
`);
|
|
3841
|
-
let totalMigrated = 0;
|
|
3842
|
-
const modifiedFiles = [];
|
|
3843
|
-
for (const sourceFile of sourceFiles) {
|
|
3844
|
-
const filePath = sourceFile.getFilePath();
|
|
3845
|
-
const migrated = processFile13(filePath, project);
|
|
3846
|
-
if (migrated > 0) {
|
|
3847
|
-
totalMigrated += migrated;
|
|
3848
|
-
modifiedFiles.push(filePath);
|
|
3849
|
-
}
|
|
3850
|
-
}
|
|
3851
|
-
if (modifiedFiles.length === 0) {
|
|
3852
|
-
console.log(
|
|
3853
|
-
"No deprecated workqueue 'actions' arrays found inside defineWorkqueues calls. Nothing to do."
|
|
3854
|
-
);
|
|
3030
|
+
if (modifiedFiles.length === 0) {
|
|
3031
|
+
console.log(
|
|
3032
|
+
"No deprecated workqueue 'actions' arrays found inside defineWorkqueues calls. Nothing to do."
|
|
3033
|
+
);
|
|
3855
3034
|
return;
|
|
3856
3035
|
}
|
|
3857
3036
|
console.log(`
|
|
@@ -3859,7 +3038,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
3859
3038
|
for (const filePath of modifiedFiles) {
|
|
3860
3039
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
3861
3040
|
await sourceFile.save();
|
|
3862
|
-
console.log(` Saved: ${
|
|
3041
|
+
console.log(` Saved: ${import_path13.default.relative(getCwd(), filePath)}`);
|
|
3863
3042
|
}
|
|
3864
3043
|
console.log(
|
|
3865
3044
|
`
|
|
@@ -3868,13 +3047,13 @@ Done. Migrated ${totalMigrated} deprecated workqueue 'actions' definition(s) to
|
|
|
3868
3047
|
}
|
|
3869
3048
|
|
|
3870
3049
|
// src/migrations/v2.0/remove-demo-scope.ts
|
|
3871
|
-
var
|
|
3872
|
-
var
|
|
3050
|
+
var import_path14 = __toESM(require("path"));
|
|
3051
|
+
var import_ts_morph14 = require("ts-morph");
|
|
3873
3052
|
var ROLES_HANDLER_RELATIVE_PATH = "src/data-seeding/roles/handler.ts";
|
|
3874
|
-
async function
|
|
3875
|
-
const rolesHandlerPath =
|
|
3876
|
-
const project = new
|
|
3877
|
-
tsConfigFilePath:
|
|
3053
|
+
async function main14() {
|
|
3054
|
+
const rolesHandlerPath = import_path14.default.join(getCwd(), ROLES_HANDLER_RELATIVE_PATH);
|
|
3055
|
+
const project = new import_ts_morph14.Project({
|
|
3056
|
+
tsConfigFilePath: import_path14.default.resolve(getCwd(), "tsconfig.json"),
|
|
3878
3057
|
skipAddingFilesFromTsConfig: false
|
|
3879
3058
|
});
|
|
3880
3059
|
const sourceFile = project.getSourceFile(rolesHandlerPath);
|
|
@@ -3923,7 +3102,7 @@ async function main19() {
|
|
|
3923
3102
|
|
|
3924
3103
|
// src/migrations/v2.0/remove-hearth-migrations.ts
|
|
3925
3104
|
var fs2 = __toESM(require("fs"));
|
|
3926
|
-
var
|
|
3105
|
+
var import_path15 = __toESM(require("path"));
|
|
3927
3106
|
var PATHS_TO_REMOVE = [
|
|
3928
3107
|
{
|
|
3929
3108
|
relativePath: "src/migrations/hearth",
|
|
@@ -3935,9 +3114,9 @@ var PATHS_TO_REMOVE = [
|
|
|
3935
3114
|
},
|
|
3936
3115
|
{ relativePath: "src/utils/hearth-helpers.ts", label: "Hearth helpers file" }
|
|
3937
3116
|
];
|
|
3938
|
-
async function
|
|
3117
|
+
async function main15() {
|
|
3939
3118
|
for (const { relativePath, label } of PATHS_TO_REMOVE) {
|
|
3940
|
-
const absolutePath =
|
|
3119
|
+
const absolutePath = import_path15.default.join(getCwd(), relativePath);
|
|
3941
3120
|
if (fs2.existsSync(absolutePath)) {
|
|
3942
3121
|
fs2.rmSync(absolutePath, { recursive: true, force: true });
|
|
3943
3122
|
console.log(`Removed ${label} '${relativePath}'.`);
|
|
@@ -3948,9 +3127,9 @@ async function main20() {
|
|
|
3948
3127
|
}
|
|
3949
3128
|
|
|
3950
3129
|
// src/migrations/v2.0/create-events-index.ts
|
|
3951
|
-
var
|
|
3952
|
-
var
|
|
3953
|
-
var
|
|
3130
|
+
var import_ts_morph15 = require("ts-morph");
|
|
3131
|
+
var import_fs = __toESM(require("fs"));
|
|
3132
|
+
var import_path16 = __toESM(require("path"));
|
|
3954
3133
|
var DEFINE_CONFIG_NAME5 = "defineConfig";
|
|
3955
3134
|
var HANDLER_FUNCTION_NAMES = /* @__PURE__ */ new Set([
|
|
3956
3135
|
"getCustomEventsHandler",
|
|
@@ -3972,7 +3151,7 @@ var LICENSE_HEADER = `/*
|
|
|
3972
3151
|
`;
|
|
3973
3152
|
function findEventConfigExports(project, srcDir) {
|
|
3974
3153
|
const found = [];
|
|
3975
|
-
const eventsIndexAbs =
|
|
3154
|
+
const eventsIndexAbs = import_path16.default.join(srcDir, "events", "index.ts");
|
|
3976
3155
|
for (const sourceFile of project.getSourceFiles()) {
|
|
3977
3156
|
const filePath = sourceFile.getFilePath();
|
|
3978
3157
|
if (!filePath.startsWith(srcDir) || filePath.includes("/node_modules/")) {
|
|
@@ -3984,10 +3163,10 @@ function findEventConfigExports(project, srcDir) {
|
|
|
3984
3163
|
for (const decl of statement.getDeclarations()) {
|
|
3985
3164
|
const initializer = decl.getInitializer();
|
|
3986
3165
|
if (!initializer) continue;
|
|
3987
|
-
const unwrapped =
|
|
3988
|
-
if (!
|
|
3166
|
+
const unwrapped = import_ts_morph15.Node.isAsExpression(initializer) ? initializer.getExpression() : initializer;
|
|
3167
|
+
if (!import_ts_morph15.Node.isCallExpression(unwrapped)) continue;
|
|
3989
3168
|
const callee = unwrapped.getExpression();
|
|
3990
|
-
if (!
|
|
3169
|
+
if (!import_ts_morph15.Node.isIdentifier(callee)) continue;
|
|
3991
3170
|
if (callee.getText() !== DEFINE_CONFIG_NAME5) continue;
|
|
3992
3171
|
found.push({ name: decl.getName(), filePath });
|
|
3993
3172
|
}
|
|
@@ -3996,8 +3175,8 @@ function findEventConfigExports(project, srcDir) {
|
|
|
3996
3175
|
return found;
|
|
3997
3176
|
}
|
|
3998
3177
|
function buildIndexImportSpecifier(eventConfigFilePath, srcDir) {
|
|
3999
|
-
const eventsIndexDir =
|
|
4000
|
-
let rel =
|
|
3178
|
+
const eventsIndexDir = import_path16.default.join(srcDir, "events");
|
|
3179
|
+
let rel = import_path16.default.relative(eventsIndexDir, eventConfigFilePath).split(import_path16.default.sep).join("/");
|
|
4001
3180
|
if (rel.endsWith(".ts")) rel = rel.slice(0, -".ts".length);
|
|
4002
3181
|
if (rel.endsWith("/index")) rel = rel.slice(0, -"/index".length);
|
|
4003
3182
|
if (!rel.startsWith(".")) rel = "./" + rel;
|
|
@@ -4074,17 +3253,17 @@ function modifyHandler(sourceFile, exportNames) {
|
|
|
4074
3253
|
);
|
|
4075
3254
|
}
|
|
4076
3255
|
for (const call of sourceFile.getDescendantsOfKind(
|
|
4077
|
-
|
|
3256
|
+
import_ts_morph15.SyntaxKind.CallExpression
|
|
4078
3257
|
)) {
|
|
4079
3258
|
const callee = call.getExpression();
|
|
4080
|
-
if (!
|
|
3259
|
+
if (!import_ts_morph15.Node.isPropertyAccessExpression(callee)) continue;
|
|
4081
3260
|
if (callee.getName() !== RESPONSE_METHOD_NAME) continue;
|
|
4082
3261
|
const args2 = call.getArguments();
|
|
4083
3262
|
if (args2.length !== 1) continue;
|
|
4084
3263
|
const [arg] = args2;
|
|
4085
|
-
if (!
|
|
3264
|
+
if (!import_ts_morph15.Node.isArrayLiteralExpression(arg)) continue;
|
|
4086
3265
|
if (arg.getElements().length === 0) continue;
|
|
4087
|
-
if (!arg.getElements().every((el) =>
|
|
3266
|
+
if (!arg.getElements().every((el) => import_ts_morph15.Node.isIdentifier(el))) continue;
|
|
4088
3267
|
arg.replaceWithText(EVENT_CONFIGS_IDENTIFIER);
|
|
4089
3268
|
changes.push(
|
|
4090
3269
|
`rewrote h.response([...]) \u2192 h.response(${EVENT_CONFIGS_IDENTIFIER})`
|
|
@@ -4092,13 +3271,13 @@ function modifyHandler(sourceFile, exportNames) {
|
|
|
4092
3271
|
}
|
|
4093
3272
|
return changes;
|
|
4094
3273
|
}
|
|
4095
|
-
async function
|
|
4096
|
-
const
|
|
4097
|
-
const srcDir =
|
|
3274
|
+
async function main16() {
|
|
3275
|
+
const cwd2 = getCwd();
|
|
3276
|
+
const srcDir = import_path16.default.join(cwd2, "src");
|
|
4098
3277
|
console.log(`Scanning for defineConfig event exports in: ${srcDir}
|
|
4099
3278
|
`);
|
|
4100
|
-
const project = new
|
|
4101
|
-
tsConfigFilePath:
|
|
3279
|
+
const project = new import_ts_morph15.Project({
|
|
3280
|
+
tsConfigFilePath: import_path16.default.resolve(srcDir, "../tsconfig.json"),
|
|
4102
3281
|
skipAddingFilesFromTsConfig: false
|
|
4103
3282
|
});
|
|
4104
3283
|
const eventConfigExports = findEventConfigExports(project, srcDir);
|
|
@@ -4110,15 +3289,15 @@ async function main21() {
|
|
|
4110
3289
|
}
|
|
4111
3290
|
console.log(`Found ${eventConfigExports.length} event config export(s):`);
|
|
4112
3291
|
for (const e of eventConfigExports) {
|
|
4113
|
-
console.log(` ${e.name} \u2190 ${
|
|
3292
|
+
console.log(` ${e.name} \u2190 ${import_path16.default.relative(cwd2, e.filePath)}`);
|
|
4114
3293
|
}
|
|
4115
|
-
const eventsIndexAbs =
|
|
4116
|
-
const eventsIndexRel =
|
|
4117
|
-
if (
|
|
3294
|
+
const eventsIndexAbs = import_path16.default.join(srcDir, "events", "index.ts");
|
|
3295
|
+
const eventsIndexRel = import_path16.default.relative(cwd2, eventsIndexAbs);
|
|
3296
|
+
if (import_fs.default.existsSync(eventsIndexAbs)) {
|
|
4118
3297
|
console.log(`
|
|
4119
3298
|
[${eventsIndexRel}] already exists \u2014 leaving untouched.`);
|
|
4120
3299
|
} else {
|
|
4121
|
-
|
|
3300
|
+
import_fs.default.mkdirSync(import_path16.default.dirname(eventsIndexAbs), { recursive: true });
|
|
4122
3301
|
const source = buildEventsIndexSource(eventConfigExports, srcDir);
|
|
4123
3302
|
const eventsIndexFile = project.createSourceFile(eventsIndexAbs, source, {
|
|
4124
3303
|
overwrite: false
|
|
@@ -4139,7 +3318,7 @@ No event-config handler file found (looked for exported function(s): ${Array.fro
|
|
|
4139
3318
|
);
|
|
4140
3319
|
return;
|
|
4141
3320
|
}
|
|
4142
|
-
const handlerRelPath =
|
|
3321
|
+
const handlerRelPath = import_path16.default.relative(cwd2, handler.getFilePath());
|
|
4143
3322
|
const exportNameSet = new Set(eventConfigExports.map((e) => e.name));
|
|
4144
3323
|
const changes = modifyHandler(handler, exportNameSet);
|
|
4145
3324
|
if (changes.length === 0) {
|
|
@@ -4159,13 +3338,12 @@ var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
|
|
|
4159
3338
|
var UPSTREAM_BRANCH = "develop";
|
|
4160
3339
|
var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
|
|
4161
3340
|
var FILES_TO_CHECKOUT = [
|
|
4162
|
-
"
|
|
4163
|
-
"
|
|
4164
|
-
"Dockerfile.assets"
|
|
3341
|
+
"infrastructure/postgres/setup-analytics.sh",
|
|
3342
|
+
"src/analytics/analytics.ts"
|
|
4165
3343
|
];
|
|
4166
3344
|
function runGit(args2, { silent = false } = {}) {
|
|
4167
3345
|
return (0, import_child_process.execFileSync)("git", args2, {
|
|
4168
|
-
cwd:
|
|
3346
|
+
cwd: getCwd(),
|
|
4169
3347
|
encoding: "utf8",
|
|
4170
3348
|
stdio: silent ? ["ignore", "pipe", "pipe"] : ["ignore", "pipe", "inherit"]
|
|
4171
3349
|
});
|
|
@@ -4181,11 +3359,11 @@ function tryGit(args2) {
|
|
|
4181
3359
|
function assertIsGitRepo() {
|
|
4182
3360
|
if (!tryGit(["rev-parse", "--is-inside-work-tree"])) {
|
|
4183
3361
|
throw new Error(
|
|
4184
|
-
|
|
3362
|
+
`checkout-upstream-files: ${getCwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`
|
|
4185
3363
|
);
|
|
4186
3364
|
}
|
|
4187
3365
|
}
|
|
4188
|
-
async function
|
|
3366
|
+
async function main17() {
|
|
4189
3367
|
console.log(
|
|
4190
3368
|
`Checking out ${FILES_TO_CHECKOUT.length} file(s) from ${UPSTREAM_URL}@${UPSTREAM_BRANCH}...
|
|
4191
3369
|
`
|
|
@@ -4233,356 +3411,10 @@ async function main22() {
|
|
|
4233
3411
|
}
|
|
4234
3412
|
}
|
|
4235
3413
|
|
|
4236
|
-
// src/migrations/v2.0/add-resend-invite-notification.ts
|
|
4237
|
-
var import_fs3 = require("fs");
|
|
4238
|
-
var import_path22 = __toESM(require("path"));
|
|
4239
|
-
var import_ts_morph20 = require("ts-morph");
|
|
4240
|
-
var TS_MORPH_PROJECT_OPTIONS = {
|
|
4241
|
-
skipAddingFilesFromTsConfig: true,
|
|
4242
|
-
manipulationSettings: {
|
|
4243
|
-
indentationText: import_ts_morph20.IndentationText.TwoSpaces
|
|
4244
|
-
}
|
|
4245
|
-
};
|
|
4246
|
-
var EMAIL_TEMPLATES_INDEX = "src/api/notification/email-templates/index.ts";
|
|
4247
|
-
var NOTIFICATION_HANDLER = "src/api/notification/handler.ts";
|
|
4248
|
-
var USER_NOTIFICATION_ROUTES = "src/config/routes/userNotificationRoutes.ts";
|
|
4249
|
-
var SMS_SERVICE = "src/api/notification/sms-service.ts";
|
|
4250
|
-
var NOTIFICATION_CSV = "src/translations/notification.csv";
|
|
4251
|
-
var RESEND_INVITE_HTML = "src/api/notification/email-templates/other/resend-invite.html";
|
|
4252
|
-
var RESEND_INVITE_HTML_CONTENT = `<!doctype html>
|
|
4253
|
-
<html>
|
|
4254
|
-
<head>
|
|
4255
|
-
<link
|
|
4256
|
-
href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap"
|
|
4257
|
-
rel="stylesheet"
|
|
4258
|
-
/>
|
|
4259
|
-
<style type="text/css">
|
|
4260
|
-
body {
|
|
4261
|
-
font-family: 'Noto Sans', sans-serif;
|
|
4262
|
-
color: #222;
|
|
4263
|
-
padding: 16px 24px;
|
|
4264
|
-
}
|
|
4265
|
-
|
|
4266
|
-
h1 {
|
|
4267
|
-
font-size: 21px;
|
|
4268
|
-
margin-top: 32px;
|
|
4269
|
-
margin-bottom: 36px;
|
|
4270
|
-
font-weight: 700;
|
|
4271
|
-
}
|
|
4272
|
-
|
|
4273
|
-
p {
|
|
4274
|
-
font-weight: 400;
|
|
4275
|
-
font-size: 16px;
|
|
4276
|
-
line-height: 1.8;
|
|
4277
|
-
margin-bottom: 24px;
|
|
4278
|
-
}
|
|
4279
|
-
|
|
4280
|
-
i {
|
|
4281
|
-
color: #666;
|
|
4282
|
-
font-weight: 400;
|
|
4283
|
-
font-size: 16px;
|
|
4284
|
-
}
|
|
4285
|
-
</style>
|
|
4286
|
-
</head>
|
|
4287
|
-
|
|
4288
|
-
<body>
|
|
4289
|
-
<img
|
|
4290
|
-
src="{{countryLogo}}"
|
|
4291
|
-
alt="country_logo"
|
|
4292
|
-
style="max-height: 88px; max-width: 100%"
|
|
4293
|
-
/>
|
|
4294
|
-
<h1>Your {{applicationName}} account invitation</h1>
|
|
4295
|
-
<p>Hello {{firstname}},</p>
|
|
4296
|
-
<p>Your account invitation has been resent. Please use the following credentials to access your account:</p>
|
|
4297
|
-
<p>
|
|
4298
|
-
Username: <strong>{{username}}</strong><br />
|
|
4299
|
-
Password: <strong>{{temporaryPassword}}</strong>
|
|
4300
|
-
</p>
|
|
4301
|
-
<p>
|
|
4302
|
-
Please click the link below to complete your account setup and start using
|
|
4303
|
-
{{applicationName}}.
|
|
4304
|
-
</p>
|
|
4305
|
-
|
|
4306
|
-
<div style="margin-top: 32px; margin-bottom: 32px">
|
|
4307
|
-
<a href="{{loginURL}}">Complete setup</a>
|
|
4308
|
-
</div>
|
|
4309
|
-
<br />
|
|
4310
|
-
<p>
|
|
4311
|
-
Best regards, <br />
|
|
4312
|
-
{{applicationName}} Team
|
|
4313
|
-
</p>
|
|
4314
|
-
</body>
|
|
4315
|
-
</html>
|
|
4316
|
-
`;
|
|
4317
|
-
var CSV_ROW = "resendInviteNotification,The SMS message that is sent when a user invitation is resent,Your OpenCRVS account invitation was resent. Please login with your username: {{username}} and temporary password: {{temporaryPassword}},Votre invitation de compte OpenCRVS a \xE9t\xE9 renvoy\xE9e. Veuillez vous connecter avec votre nom d'utilisateur : {{username}} et votre mot de passe temporaire : {{temporaryPassword}}.\n";
|
|
4318
|
-
function getObjectLiteralFromConst(declaration) {
|
|
4319
|
-
if (!declaration) {
|
|
4320
|
-
return;
|
|
4321
|
-
}
|
|
4322
|
-
const initializer = declaration.getInitializer();
|
|
4323
|
-
if (!initializer) {
|
|
4324
|
-
return;
|
|
4325
|
-
}
|
|
4326
|
-
if (import_ts_morph20.Node.isObjectLiteralExpression(initializer)) {
|
|
4327
|
-
return initializer;
|
|
4328
|
-
}
|
|
4329
|
-
if (import_ts_morph20.Node.isAsExpression(initializer)) {
|
|
4330
|
-
const expression = initializer.getExpression();
|
|
4331
|
-
if (import_ts_morph20.Node.isObjectLiteralExpression(expression)) {
|
|
4332
|
-
return expression;
|
|
4333
|
-
}
|
|
4334
|
-
}
|
|
4335
|
-
if (import_ts_morph20.Node.isSatisfiesExpression(initializer)) {
|
|
4336
|
-
const expression = initializer.getExpression();
|
|
4337
|
-
if (import_ts_morph20.Node.isObjectLiteralExpression(expression)) {
|
|
4338
|
-
return expression;
|
|
4339
|
-
}
|
|
4340
|
-
}
|
|
4341
|
-
}
|
|
4342
|
-
function patchEmailTemplatesIndex() {
|
|
4343
|
-
const full = import_path22.default.join(process.cwd(), EMAIL_TEMPLATES_INDEX);
|
|
4344
|
-
if (!(0, import_fs3.existsSync)(full)) {
|
|
4345
|
-
console.log(` '${EMAIL_TEMPLATES_INDEX}' missing \u2014 skipping.`);
|
|
4346
|
-
return false;
|
|
4347
|
-
}
|
|
4348
|
-
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4349
|
-
const sourceFile = project.addSourceFileAtPath(full);
|
|
4350
|
-
let changed = false;
|
|
4351
|
-
const triggerVariableObject = getObjectLiteralFromConst(
|
|
4352
|
-
sourceFile.getVariableDeclaration("TriggerVariable")
|
|
4353
|
-
);
|
|
4354
|
-
if (triggerVariableObject) {
|
|
4355
|
-
const hasResendInviteVariable = triggerVariableObject.getProperties().some((prop) => prop.getText().includes("[TriggerEvent.RESEND_INVITE]"));
|
|
4356
|
-
if (!hasResendInviteVariable) {
|
|
4357
|
-
const properties = triggerVariableObject.getProperties();
|
|
4358
|
-
const lastProperty = properties[properties.length - 1];
|
|
4359
|
-
if (lastProperty) {
|
|
4360
|
-
sourceFile.insertText(
|
|
4361
|
-
lastProperty.getEnd(),
|
|
4362
|
-
`,
|
|
4363
|
-
[TriggerEvent.RESEND_INVITE]: z.object({
|
|
4364
|
-
firstname: z.string(),
|
|
4365
|
-
username: z.string(),
|
|
4366
|
-
temporaryPassword: z.string(),
|
|
4367
|
-
completeSetupUrl: z.string(),
|
|
4368
|
-
loginURL: z.string()
|
|
4369
|
-
})`
|
|
4370
|
-
);
|
|
4371
|
-
changed = true;
|
|
4372
|
-
}
|
|
4373
|
-
}
|
|
4374
|
-
}
|
|
4375
|
-
const templatesObject = getObjectLiteralFromConst(
|
|
4376
|
-
sourceFile.getVariableDeclaration("templates")
|
|
4377
|
-
);
|
|
4378
|
-
if (templatesObject) {
|
|
4379
|
-
const hasResendInviteTemplate = templatesObject.getProperties().some(
|
|
4380
|
-
(prop) => prop.getText().includes("readOtherTemplate<TriggerVariable['resend-invite']>")
|
|
4381
|
-
);
|
|
4382
|
-
if (!hasResendInviteTemplate) {
|
|
4383
|
-
const userCreatedProp = templatesObject.getProperties().find((prop) => prop.getText().includes("[TriggerEvent.USER_CREATED]"));
|
|
4384
|
-
const anchor = userCreatedProp ?? templatesObject.getProperties()[templatesObject.getProperties().length - 1];
|
|
4385
|
-
if (anchor) {
|
|
4386
|
-
sourceFile.insertText(
|
|
4387
|
-
anchor.getEnd(),
|
|
4388
|
-
`,
|
|
4389
|
-
[TriggerEvent.RESEND_INVITE]: {
|
|
4390
|
-
type: 'resend-invite',
|
|
4391
|
-
subject: 'Your OpenCRVS account invitation',
|
|
4392
|
-
template:
|
|
4393
|
-
readOtherTemplate<TriggerVariable['resend-invite']>('resend-invite')
|
|
4394
|
-
}`
|
|
4395
|
-
);
|
|
4396
|
-
changed = true;
|
|
4397
|
-
}
|
|
4398
|
-
}
|
|
4399
|
-
}
|
|
4400
|
-
if (changed) {
|
|
4401
|
-
sourceFile.saveSync();
|
|
4402
|
-
}
|
|
4403
|
-
return changed;
|
|
4404
|
-
}
|
|
4405
|
-
function patchNotificationHandler() {
|
|
4406
|
-
const full = import_path22.default.join(process.cwd(), NOTIFICATION_HANDLER);
|
|
4407
|
-
if (!(0, import_fs3.existsSync)(full)) {
|
|
4408
|
-
return false;
|
|
4409
|
-
}
|
|
4410
|
-
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4411
|
-
const sourceFile = project.addSourceFileAtPath(full);
|
|
4412
|
-
const convertFn = sourceFile.getFunction("convertPayloadToVariable");
|
|
4413
|
-
if (!convertFn) {
|
|
4414
|
-
return false;
|
|
4415
|
-
}
|
|
4416
|
-
const switchStmt = convertFn.getFirstDescendantByKind(
|
|
4417
|
-
import_ts_morph20.SyntaxKind.SwitchStatement
|
|
4418
|
-
);
|
|
4419
|
-
if (!switchStmt) {
|
|
4420
|
-
return false;
|
|
4421
|
-
}
|
|
4422
|
-
const clauses = switchStmt.getCaseBlock().getClauses();
|
|
4423
|
-
const hasResendInvite = clauses.some(
|
|
4424
|
-
(clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.RESEND_INVITE"
|
|
4425
|
-
);
|
|
4426
|
-
if (hasResendInvite) {
|
|
4427
|
-
return false;
|
|
4428
|
-
}
|
|
4429
|
-
const userCreatedClauseIndex = clauses.findIndex(
|
|
4430
|
-
(clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.USER_CREATED"
|
|
4431
|
-
);
|
|
4432
|
-
if (userCreatedClauseIndex < 0) {
|
|
4433
|
-
return false;
|
|
4434
|
-
}
|
|
4435
|
-
const userCreatedClause = clauses[userCreatedClauseIndex];
|
|
4436
|
-
sourceFile.insertText(
|
|
4437
|
-
userCreatedClause.getEnd(),
|
|
4438
|
-
`
|
|
4439
|
-
|
|
4440
|
-
case TriggerEvent.RESEND_INVITE:
|
|
4441
|
-
return {
|
|
4442
|
-
firstname,
|
|
4443
|
-
username: payload.username,
|
|
4444
|
-
temporaryPassword: payload.temporaryPassword,
|
|
4445
|
-
completeSetupUrl: LOGIN_URL,
|
|
4446
|
-
loginURL: LOGIN_URL
|
|
4447
|
-
}`
|
|
4448
|
-
);
|
|
4449
|
-
sourceFile.saveSync();
|
|
4450
|
-
return true;
|
|
4451
|
-
}
|
|
4452
|
-
function getReturnedArrayLiteral(functionFilePath, fnName) {
|
|
4453
|
-
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4454
|
-
const sourceFile = project.addSourceFileAtPath(functionFilePath);
|
|
4455
|
-
const fn = sourceFile.getFunction(fnName);
|
|
4456
|
-
const returnStmt = fn?.getFirstDescendantByKind(import_ts_morph20.SyntaxKind.ReturnStatement);
|
|
4457
|
-
const expr = returnStmt?.getExpression();
|
|
4458
|
-
if (!expr || !import_ts_morph20.Node.isArrayLiteralExpression(expr)) {
|
|
4459
|
-
return { sourceFile, arrayLiteral: void 0 };
|
|
4460
|
-
}
|
|
4461
|
-
return { sourceFile, arrayLiteral: expr };
|
|
4462
|
-
}
|
|
4463
|
-
function patchUserNotificationRoutes() {
|
|
4464
|
-
const full = import_path22.default.join(process.cwd(), USER_NOTIFICATION_ROUTES);
|
|
4465
|
-
if (!(0, import_fs3.existsSync)(full)) {
|
|
4466
|
-
return false;
|
|
4467
|
-
}
|
|
4468
|
-
const { sourceFile, arrayLiteral } = getReturnedArrayLiteral(
|
|
4469
|
-
full,
|
|
4470
|
-
"getUserNotificationRoutes"
|
|
4471
|
-
);
|
|
4472
|
-
if (!arrayLiteral) {
|
|
4473
|
-
return false;
|
|
4474
|
-
}
|
|
4475
|
-
const elements = arrayLiteral.getElements();
|
|
4476
|
-
const routeExists = elements.some(
|
|
4477
|
-
(element) => element.getText().includes(`path: '/triggers/user/resend-invite'`)
|
|
4478
|
-
);
|
|
4479
|
-
if (routeExists) {
|
|
4480
|
-
return false;
|
|
4481
|
-
}
|
|
4482
|
-
const anchor = elements.find(
|
|
4483
|
-
(element) => element.getText().includes(`path: '/triggers/user/user-created'`)
|
|
4484
|
-
) ?? elements[elements.length - 1];
|
|
4485
|
-
if (!anchor) {
|
|
4486
|
-
return false;
|
|
4487
|
-
}
|
|
4488
|
-
sourceFile.insertText(
|
|
4489
|
-
anchor.getEnd(),
|
|
4490
|
-
`,
|
|
4491
|
-
{
|
|
4492
|
-
method: 'POST',
|
|
4493
|
-
path: '/triggers/user/resend-invite',
|
|
4494
|
-
handler: makeNotificationHandler('resend-invite'),
|
|
4495
|
-
options: {
|
|
4496
|
-
auth: false,
|
|
4497
|
-
tags: ['api'],
|
|
4498
|
-
description: 'Handles notification for resent user invite'
|
|
4499
|
-
}
|
|
4500
|
-
}`
|
|
4501
|
-
);
|
|
4502
|
-
sourceFile.saveSync();
|
|
4503
|
-
return true;
|
|
4504
|
-
}
|
|
4505
|
-
function patchSmsService() {
|
|
4506
|
-
const full = import_path22.default.join(process.cwd(), SMS_SERVICE);
|
|
4507
|
-
if (!(0, import_fs3.existsSync)(full)) {
|
|
4508
|
-
return false;
|
|
4509
|
-
}
|
|
4510
|
-
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4511
|
-
const sourceFile = project.addSourceFileAtPath(full);
|
|
4512
|
-
let changed = false;
|
|
4513
|
-
const otherTemplatesObject = getObjectLiteralFromConst(
|
|
4514
|
-
sourceFile.getVariableDeclaration("otherTemplates")
|
|
4515
|
-
);
|
|
4516
|
-
if (otherTemplatesObject) {
|
|
4517
|
-
const hasResendTemplate = otherTemplatesObject.getProperties().some((prop) => prop.getText().includes("resendInviteNotification"));
|
|
4518
|
-
if (!hasResendTemplate) {
|
|
4519
|
-
const userCredentialsIndex = otherTemplatesObject.getProperties().findIndex((prop) => prop.getText().includes("userCredentialsNotification"));
|
|
4520
|
-
otherTemplatesObject.insertPropertyAssignment(
|
|
4521
|
-
userCredentialsIndex >= 0 ? userCredentialsIndex + 1 : otherTemplatesObject.getProperties().length,
|
|
4522
|
-
{
|
|
4523
|
-
name: "resendInviteNotification",
|
|
4524
|
-
initializer: `'resendInviteNotification'`
|
|
4525
|
-
}
|
|
4526
|
-
);
|
|
4527
|
-
changed = true;
|
|
4528
|
-
}
|
|
4529
|
-
}
|
|
4530
|
-
const triggerToSmsTemplateObject = getObjectLiteralFromConst(
|
|
4531
|
-
sourceFile.getVariableDeclaration("TriggerToSMSTemplate")
|
|
4532
|
-
);
|
|
4533
|
-
if (triggerToSmsTemplateObject) {
|
|
4534
|
-
const hasResendInviteMap = triggerToSmsTemplateObject.getProperties().some((prop) => prop.getText().includes(`['resend-invite']`));
|
|
4535
|
-
if (!hasResendInviteMap) {
|
|
4536
|
-
const userCreatedIndex = triggerToSmsTemplateObject.getProperties().findIndex((prop) => prop.getText().includes(`['user-created']`));
|
|
4537
|
-
triggerToSmsTemplateObject.insertPropertyAssignment(
|
|
4538
|
-
userCreatedIndex >= 0 ? userCreatedIndex + 1 : triggerToSmsTemplateObject.getProperties().length,
|
|
4539
|
-
{
|
|
4540
|
-
name: `['resend-invite']`,
|
|
4541
|
-
initializer: `'resendInviteNotification'`
|
|
4542
|
-
}
|
|
4543
|
-
);
|
|
4544
|
-
changed = true;
|
|
4545
|
-
}
|
|
4546
|
-
}
|
|
4547
|
-
if (changed) {
|
|
4548
|
-
sourceFile.saveSync();
|
|
4549
|
-
}
|
|
4550
|
-
return changed;
|
|
4551
|
-
}
|
|
4552
|
-
async function main23() {
|
|
4553
|
-
console.log("Adding RESEND_INVITE notification wiring\u2026");
|
|
4554
|
-
const touched = [];
|
|
4555
|
-
if (patchEmailTemplatesIndex()) touched.push(EMAIL_TEMPLATES_INDEX);
|
|
4556
|
-
if (patchNotificationHandler()) touched.push(NOTIFICATION_HANDLER);
|
|
4557
|
-
if (patchUserNotificationRoutes()) touched.push(USER_NOTIFICATION_ROUTES);
|
|
4558
|
-
if (patchSmsService()) touched.push(SMS_SERVICE);
|
|
4559
|
-
const csvPath = import_path22.default.join(process.cwd(), NOTIFICATION_CSV);
|
|
4560
|
-
if ((0, import_fs3.existsSync)(csvPath)) {
|
|
4561
|
-
let t = (0, import_fs3.readFileSync)(csvPath, "utf8");
|
|
4562
|
-
if (!/^resendInviteNotification,/m.test(t)) {
|
|
4563
|
-
if (!t.endsWith("\n")) t += "\n";
|
|
4564
|
-
(0, import_fs3.writeFileSync)(csvPath, t + CSV_ROW);
|
|
4565
|
-
touched.push(NOTIFICATION_CSV);
|
|
4566
|
-
}
|
|
4567
|
-
}
|
|
4568
|
-
const htmlPath = import_path22.default.join(process.cwd(), RESEND_INVITE_HTML);
|
|
4569
|
-
(0, import_fs3.mkdirSync)(import_path22.default.dirname(htmlPath), { recursive: true });
|
|
4570
|
-
if (!(0, import_fs3.existsSync)(htmlPath)) {
|
|
4571
|
-
(0, import_fs3.writeFileSync)(htmlPath, RESEND_INVITE_HTML_CONTENT);
|
|
4572
|
-
touched.push(RESEND_INVITE_HTML);
|
|
4573
|
-
}
|
|
4574
|
-
if (touched.length === 0) {
|
|
4575
|
-
console.log(" Nothing to update (already present or anchors not found).");
|
|
4576
|
-
return;
|
|
4577
|
-
}
|
|
4578
|
-
console.log(` Updated:
|
|
4579
|
-
${touched.map((f) => ` - ${f}`).join("\n")}`);
|
|
4580
|
-
}
|
|
4581
|
-
|
|
4582
3414
|
// src/migrations/v2.0/simplify-analytics-precalculations.ts
|
|
4583
|
-
var
|
|
4584
|
-
var
|
|
4585
|
-
var
|
|
3415
|
+
var import_ts_morph16 = require("ts-morph");
|
|
3416
|
+
var import_fs2 = __toESM(require("fs"));
|
|
3417
|
+
var import_path17 = __toESM(require("path"));
|
|
4586
3418
|
var ANALYTICS_FILE_REL = "src/analytics/analytics.ts";
|
|
4587
3419
|
var FUNCTION_NAME = "precalculateAdditionalAnalytics";
|
|
4588
3420
|
var IMPORT_NAMES_TO_REMOVE = /* @__PURE__ */ new Set(["Event", "precalculateBirthEvent"]);
|
|
@@ -4618,10 +3450,10 @@ function findPrecalculateFunction(sourceFile) {
|
|
|
4618
3450
|
return void 0;
|
|
4619
3451
|
}
|
|
4620
3452
|
function getFunctionBodyBlock(fn) {
|
|
4621
|
-
if (
|
|
3453
|
+
if (import_ts_morph16.Node.isFunctionDeclaration(fn)) return fn.getBody();
|
|
4622
3454
|
const initializer = fn.getInitializer();
|
|
4623
3455
|
if (!initializer) return void 0;
|
|
4624
|
-
if (!
|
|
3456
|
+
if (!import_ts_morph16.Node.isArrowFunction(initializer) && !import_ts_morph16.Node.isFunctionExpression(initializer)) {
|
|
4625
3457
|
return void 0;
|
|
4626
3458
|
}
|
|
4627
3459
|
return initializer.getBody();
|
|
@@ -4631,9 +3463,9 @@ function simplifyPrecalculateFunction(sourceFile) {
|
|
|
4631
3463
|
const fn = findPrecalculateFunction(sourceFile);
|
|
4632
3464
|
if (!fn) return log;
|
|
4633
3465
|
const body = getFunctionBodyBlock(fn);
|
|
4634
|
-
if (!body || !
|
|
3466
|
+
if (!body || !import_ts_morph16.Node.isBlock(body)) return log;
|
|
4635
3467
|
for (const statement of [...body.getStatements()]) {
|
|
4636
|
-
const references = statement.getDescendantsOfKind(
|
|
3468
|
+
const references = statement.getDescendantsOfKind(import_ts_morph16.SyntaxKind.Identifier).some((id) => IMPORT_NAMES_TO_REMOVE.has(id.getText()));
|
|
4637
3469
|
if (references) {
|
|
4638
3470
|
statement.remove();
|
|
4639
3471
|
log.push(`removed statement in ${FUNCTION_NAME} referencing removed imports`);
|
|
@@ -4641,7 +3473,7 @@ function simplifyPrecalculateFunction(sourceFile) {
|
|
|
4641
3473
|
}
|
|
4642
3474
|
const remaining = body.getStatements();
|
|
4643
3475
|
const last = remaining[remaining.length - 1];
|
|
4644
|
-
const alreadyCorrect = last &&
|
|
3476
|
+
const alreadyCorrect = last && import_ts_morph16.Node.isReturnStatement(last) && last.getExpression()?.getText() === RETURN_EXPRESSION_TEXT;
|
|
4645
3477
|
if (!alreadyCorrect) {
|
|
4646
3478
|
body.addStatements(`return ${RETURN_EXPRESSION_TEXT}`);
|
|
4647
3479
|
log.push(
|
|
@@ -4650,17 +3482,17 @@ function simplifyPrecalculateFunction(sourceFile) {
|
|
|
4650
3482
|
}
|
|
4651
3483
|
return log;
|
|
4652
3484
|
}
|
|
4653
|
-
async function
|
|
4654
|
-
const
|
|
4655
|
-
const absPath =
|
|
4656
|
-
if (!
|
|
3485
|
+
async function main18() {
|
|
3486
|
+
const cwd2 = getCwd();
|
|
3487
|
+
const absPath = import_path17.default.join(cwd2, ANALYTICS_FILE_REL);
|
|
3488
|
+
if (!import_fs2.default.existsSync(absPath)) {
|
|
4657
3489
|
console.log(
|
|
4658
3490
|
`[${ANALYTICS_FILE_REL}] does not exist \u2014 nothing to clean up.`
|
|
4659
3491
|
);
|
|
4660
3492
|
return;
|
|
4661
3493
|
}
|
|
4662
|
-
const project = new
|
|
4663
|
-
tsConfigFilePath:
|
|
3494
|
+
const project = new import_ts_morph16.Project({
|
|
3495
|
+
tsConfigFilePath: import_path17.default.resolve(cwd2, "tsconfig.json"),
|
|
4664
3496
|
skipAddingFilesFromTsConfig: false
|
|
4665
3497
|
});
|
|
4666
3498
|
const sourceFile = project.getSourceFile(absPath);
|
|
@@ -4687,158 +3519,26 @@ async function main24() {
|
|
|
4687
3519
|
Saved ${ANALYTICS_FILE_REL}.`);
|
|
4688
3520
|
}
|
|
4689
3521
|
|
|
4690
|
-
// src/migrations/v2.0/
|
|
4691
|
-
var
|
|
4692
|
-
|
|
4693
|
-
|
|
4694
|
-
|
|
4695
|
-
var TEMP_REMOTE2 = "opencrvs-upgrade-v19-v20-codemod-merge-infra";
|
|
4696
|
-
var INFRASTRUCTURE_DIR = "infrastructure";
|
|
4697
|
-
var BASE_BRANCH = "release-v1.9";
|
|
4698
|
-
function gitShowBytes(ref, path23) {
|
|
4699
|
-
try {
|
|
4700
|
-
const buf = (0, import_child_process2.execFileSync)("git", ["show", `${ref}:${path23}`], {
|
|
4701
|
-
cwd: process.cwd(),
|
|
4702
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
4703
|
-
});
|
|
4704
|
-
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
4705
|
-
} catch {
|
|
4706
|
-
return null;
|
|
3522
|
+
// src/migrations/v2.0/index.ts
|
|
3523
|
+
var cwd;
|
|
3524
|
+
function getCwd() {
|
|
3525
|
+
if (!cwd) {
|
|
3526
|
+
throw new Error("Country config working directory not set.");
|
|
4707
3527
|
}
|
|
3528
|
+
return cwd;
|
|
4708
3529
|
}
|
|
4709
|
-
async function
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
);
|
|
4714
|
-
assertIsGitRepo();
|
|
4715
|
-
tryGit(["remote", "remove", TEMP_REMOTE2]);
|
|
4716
|
-
try {
|
|
4717
|
-
console.log(` Adding temporary remote '${TEMP_REMOTE2}' \u2192 ${UPSTREAM_URL}`);
|
|
4718
|
-
runGit(["remote", "add", TEMP_REMOTE2, UPSTREAM_URL], { silent: true });
|
|
4719
|
-
console.log(
|
|
4720
|
-
` Fetching ${TEMP_REMOTE2}/{${UPSTREAM_BRANCH},${BASE_BRANCH}} (depth 1)...`
|
|
4721
|
-
);
|
|
4722
|
-
runGit(["fetch", "--depth=1", TEMP_REMOTE2, UPSTREAM_BRANCH, BASE_BRANCH]);
|
|
4723
|
-
const ref = `${TEMP_REMOTE2}/${UPSTREAM_BRANCH}`;
|
|
4724
|
-
const baseRef = `${TEMP_REMOTE2}/${BASE_BRANCH}`;
|
|
4725
|
-
const upstreamFiles = runGit(
|
|
4726
|
-
[
|
|
4727
|
-
"ls-tree",
|
|
4728
|
-
"-r",
|
|
4729
|
-
"--name-only",
|
|
4730
|
-
"-z",
|
|
4731
|
-
ref,
|
|
4732
|
-
"--",
|
|
4733
|
-
`${INFRASTRUCTURE_DIR}/`
|
|
4734
|
-
],
|
|
4735
|
-
{ silent: true }
|
|
4736
|
-
).split("\0").filter(Boolean);
|
|
4737
|
-
if (upstreamFiles.length === 0) {
|
|
4738
|
-
console.log(
|
|
4739
|
-
` No files found under '${INFRASTRUCTURE_DIR}/' on ${ref}. Nothing to merge.`
|
|
4740
|
-
);
|
|
4741
|
-
return;
|
|
4742
|
-
}
|
|
4743
|
-
const tmpDir = (0, import_fs5.mkdtempSync)((0, import_path24.join)((0, import_os.tmpdir)(), "opencrvs-merge-infra-"));
|
|
4744
|
-
const baseTmp = (0, import_path24.join)(tmpDir, "base");
|
|
4745
|
-
const theirsTmp = (0, import_path24.join)(tmpDir, "theirs");
|
|
4746
|
-
let added = 0;
|
|
4747
|
-
let merged = 0;
|
|
4748
|
-
const conflictedFiles = [];
|
|
4749
|
-
for (const file of upstreamFiles) {
|
|
4750
|
-
const fullPath = (0, import_path24.join)(process.cwd(), file);
|
|
4751
|
-
if (!(0, import_fs5.existsSync)(fullPath)) {
|
|
4752
|
-
if (tryGit(["checkout", ref, "--", file])) {
|
|
4753
|
-
console.log(` + ${file} (new from upstream)`);
|
|
4754
|
-
added++;
|
|
4755
|
-
} else {
|
|
4756
|
-
console.warn(` [warn] failed to add new file ${file}`);
|
|
4757
|
-
}
|
|
4758
|
-
continue;
|
|
4759
|
-
}
|
|
4760
|
-
const theirContents = gitShowBytes(ref, file);
|
|
4761
|
-
if (theirContents === null) {
|
|
4762
|
-
console.warn(` [warn] could not read ${file} from ${ref} \u2014 skipping.`);
|
|
4763
|
-
continue;
|
|
4764
|
-
}
|
|
4765
|
-
(0, import_fs5.writeFileSync)(theirsTmp, theirContents);
|
|
4766
|
-
const baseContents = gitShowBytes(baseRef, file);
|
|
4767
|
-
(0, import_fs5.writeFileSync)(baseTmp, baseContents ?? new Uint8Array(0));
|
|
4768
|
-
try {
|
|
4769
|
-
(0, import_child_process2.execFileSync)("git", ["merge-file", fullPath, baseTmp, theirsTmp], {
|
|
4770
|
-
cwd: process.cwd(),
|
|
4771
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
4772
|
-
});
|
|
4773
|
-
runGit(["add", "--", file], { silent: true });
|
|
4774
|
-
merged++;
|
|
4775
|
-
} catch (err) {
|
|
4776
|
-
const status = err.status;
|
|
4777
|
-
if (typeof status === "number" && status > 0) {
|
|
4778
|
-
conflictedFiles.push(file);
|
|
4779
|
-
console.warn(
|
|
4780
|
-
` ! ${file} (${status} conflict${status > 1 ? "s" : ""})`
|
|
4781
|
-
);
|
|
4782
|
-
} else {
|
|
4783
|
-
conflictedFiles.push(file);
|
|
4784
|
-
console.warn(
|
|
4785
|
-
` [warn] merge failed for ${file} (likely binary or unreadable) \u2014 left untouched.`
|
|
4786
|
-
);
|
|
4787
|
-
}
|
|
4788
|
-
}
|
|
4789
|
-
}
|
|
4790
|
-
console.log(
|
|
4791
|
-
`
|
|
4792
|
-
Done. ${added} added, ${merged} merged cleanly, ${conflictedFiles.length} with conflicts.`
|
|
4793
|
-
);
|
|
4794
|
-
if (conflictedFiles.length > 0) {
|
|
4795
|
-
console.warn(
|
|
4796
|
-
`
|
|
4797
|
-
NOTE: ${conflictedFiles.length} file(s) under '${INFRASTRUCTURE_DIR}/' have merge conflicts that you must resolve manually.
|
|
4798
|
-
Look for the standard conflict markers (<<<<<<<, =======, >>>>>>>) in:
|
|
4799
|
-
` + conflictedFiles.map((f) => ` - ${f}`).join("\n") + `
|
|
4800
|
-
After resolving, stage the fixes with: git add ${INFRASTRUCTURE_DIR}/`
|
|
4801
|
-
);
|
|
4802
|
-
}
|
|
4803
|
-
} finally {
|
|
4804
|
-
if (tryGit(["remote", "remove", TEMP_REMOTE2])) {
|
|
4805
|
-
console.log(` Removed temporary remote '${TEMP_REMOTE2}'.`);
|
|
4806
|
-
}
|
|
3530
|
+
async function runUpgrade(ccwd) {
|
|
3531
|
+
if (ccwd) {
|
|
3532
|
+
console.log("Country config working directory:", ccwd);
|
|
3533
|
+
cwd = ccwd;
|
|
4807
3534
|
}
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
// src/migrations/v2.0/delete-infrastructure-directory.ts
|
|
4811
|
-
var import_fs6 = require("fs");
|
|
4812
|
-
var import_path25 = require("path");
|
|
4813
|
-
var INFRASTRUCTURE_DIR2 = "infrastructure";
|
|
4814
|
-
async function main26() {
|
|
4815
|
-
const fullPath = (0, import_path25.join)(process.cwd(), INFRASTRUCTURE_DIR2);
|
|
4816
|
-
if (!(0, import_fs6.existsSync)(fullPath)) {
|
|
3535
|
+
if (!ccwd) {
|
|
4817
3536
|
console.log(
|
|
4818
|
-
|
|
3537
|
+
"Will use current working directory as country config working directory."
|
|
4819
3538
|
);
|
|
4820
|
-
|
|
4821
|
-
}
|
|
4822
|
-
console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
|
|
4823
|
-
`);
|
|
4824
|
-
assertIsGitRepo();
|
|
4825
|
-
runGit(["rm", "-rf", "--ignore-unmatch", "--", `${INFRASTRUCTURE_DIR2}/`], {
|
|
4826
|
-
silent: true
|
|
4827
|
-
});
|
|
4828
|
-
console.log(` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR2}/'.`);
|
|
4829
|
-
if ((0, import_fs6.existsSync)(fullPath)) {
|
|
4830
|
-
(0, import_fs6.rmSync)(fullPath, { recursive: true, force: true });
|
|
4831
|
-
console.log(` Removed remaining untracked files under '${INFRASTRUCTURE_DIR2}/'.`);
|
|
3539
|
+
cwd = process.cwd();
|
|
4832
3540
|
}
|
|
4833
|
-
|
|
4834
|
-
`
|
|
4835
|
-
Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
|
|
4836
|
-
);
|
|
4837
|
-
}
|
|
4838
|
-
|
|
4839
|
-
// src/migrations/v2.0/index.ts
|
|
4840
|
-
async function runUpgrade(dockerSwarm) {
|
|
4841
|
-
await main18();
|
|
3541
|
+
await main13();
|
|
4842
3542
|
await main();
|
|
4843
3543
|
await main2();
|
|
4844
3544
|
await main3();
|
|
@@ -4851,22 +3551,11 @@ async function runUpgrade(dockerSwarm) {
|
|
|
4851
3551
|
await main10();
|
|
4852
3552
|
await main11();
|
|
4853
3553
|
await main12();
|
|
4854
|
-
await main13();
|
|
4855
3554
|
await main14();
|
|
4856
3555
|
await main15();
|
|
4857
3556
|
await main16();
|
|
4858
|
-
await main19();
|
|
4859
|
-
await main20();
|
|
4860
|
-
await main21();
|
|
4861
|
-
await main22();
|
|
4862
|
-
await main23();
|
|
4863
|
-
await main24();
|
|
4864
3557
|
await main17();
|
|
4865
|
-
|
|
4866
|
-
await main25();
|
|
4867
|
-
} else {
|
|
4868
|
-
await main26();
|
|
4869
|
-
}
|
|
3558
|
+
await main18();
|
|
4870
3559
|
}
|
|
4871
3560
|
|
|
4872
3561
|
// src/cli.ts
|
|
@@ -4881,20 +3570,7 @@ Commands:
|
|
|
4881
3570
|
|
|
4882
3571
|
Run 'opencrvs <command> --help' for more information on a command.
|
|
4883
3572
|
`.trim();
|
|
4884
|
-
|
|
4885
|
-
Usage: opencrvs upgrade [options]
|
|
4886
|
-
|
|
4887
|
-
Upgrade the country config in the current working directory to the next
|
|
4888
|
-
major version of OpenCRVS.
|
|
4889
|
-
|
|
4890
|
-
Options:
|
|
4891
|
-
--docker-swarm Keep and merge the 'infrastructure/' directory with
|
|
4892
|
-
upstream changes. Use this if your country deploys
|
|
4893
|
-
OpenCRVS via Docker Swarm. When omitted, the
|
|
4894
|
-
'infrastructure/' directory is deleted (default).
|
|
4895
|
-
-h, --help Show this message.
|
|
4896
|
-
`.trim();
|
|
4897
|
-
function main27() {
|
|
3573
|
+
function main19() {
|
|
4898
3574
|
const command = args[0];
|
|
4899
3575
|
if (!command || command === "--help" || command === "-h") {
|
|
4900
3576
|
console.log(USAGE);
|
|
@@ -4939,25 +3615,10 @@ Subcommands:
|
|
|
4939
3615
|
}
|
|
4940
3616
|
}
|
|
4941
3617
|
async function handleUpgrade() {
|
|
4942
|
-
const upgradeArgs = args.slice(1);
|
|
4943
|
-
if (upgradeArgs.includes("--help") || upgradeArgs.includes("-h")) {
|
|
4944
|
-
console.log(UPGRADE_USAGE);
|
|
4945
|
-
process.exit(0);
|
|
4946
|
-
}
|
|
4947
|
-
const KNOWN_FLAGS = /* @__PURE__ */ new Set(["--docker-swarm"]);
|
|
4948
|
-
const unknownFlags = upgradeArgs.filter(
|
|
4949
|
-
(arg) => arg.startsWith("-") && !KNOWN_FLAGS.has(arg)
|
|
4950
|
-
);
|
|
4951
|
-
if (unknownFlags.length > 0) {
|
|
4952
|
-
console.error(`Unknown option(s): ${unknownFlags.join(", ")}
|
|
4953
|
-
`);
|
|
4954
|
-
console.log(UPGRADE_USAGE);
|
|
4955
|
-
process.exit(1);
|
|
4956
|
-
}
|
|
4957
|
-
const dockerSwarm = upgradeArgs.includes("--docker-swarm");
|
|
4958
3618
|
console.log("Initiating upgrade...");
|
|
4959
3619
|
try {
|
|
4960
|
-
|
|
3620
|
+
const pathToCountryconfig = args[1];
|
|
3621
|
+
await runUpgrade(pathToCountryconfig);
|
|
4961
3622
|
console.log("Upgrade completed successfully!");
|
|
4962
3623
|
} catch (error) {
|
|
4963
3624
|
console.error("Upgrade failed:", error);
|
|
@@ -4969,4 +3630,4 @@ function handleCheckTranslations() {
|
|
|
4969
3630
|
console.warn("This command is not implemented yet!");
|
|
4970
3631
|
process.exit(1);
|
|
4971
3632
|
}
|
|
4972
|
-
|
|
3633
|
+
main19();
|