@opencrvs/toolkit 2.0.0-rc.da37d4e → 2.0.0-rc.db5d96b
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/create-countryconfig/index.js +73 -0
- package/create-countryconfig/package.json +11 -0
- package/dist/application-config/index.js +19 -24
- package/dist/cli.js +297 -133
- package/dist/commons/api/router.d.ts +37 -34
- package/dist/commons/application-config/index.d.ts +16 -4
- package/dist/commons/events/ActionInput.d.ts +36 -0
- package/dist/commons/events/Draft.d.ts +1 -0
- package/dist/commons/events/EventIndex.d.ts +1 -0
- package/dist/commons/events/EventMetadata.d.ts +1 -0
- package/dist/commons/events/locations.d.ts +21 -0
- package/dist/commons/events/mocks.test.utils.d.ts +19 -0
- package/dist/commons/events/scopes.d.ts +24 -1
- package/dist/commons/events/state/index.d.ts +2 -1
- package/dist/events/index.js +71 -20
- 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 +60 -35
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts +1 -1
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
- package/dist/migrations/v2.0/checkout-upstream-files.js +1 -2
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +9 -1
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -1
- package/dist/migrations/v2.0/delete-infrastructure-directory.js +66 -20
- package/dist/migrations/v2.0/index.d.ts +5 -3
- package/dist/migrations/v2.0/index.d.ts.map +1 -1
- package/dist/migrations/v2.0/index.js +297 -133
- 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 +90 -1
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +11 -1
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -1
- package/dist/migrations/v2.0/merge-infrastructure-directory.js +17 -16
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -1
- package/dist/migrations/v2.0/migrate-workqueue-configs.js +140 -59
- package/dist/notification/index.js +16 -20
- package/opencrvs-toolkit-2.0.0-rc.db5d96b.tgz +0 -0
- package/package.json +1 -1
- package/opencrvs-toolkit-2.0.0-rc.da37d4e.tgz +0 -0
package/dist/cli.js
CHANGED
|
@@ -178,6 +178,8 @@ 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";
|
|
181
183
|
var CUSTOM_ACTION_TYPE_PROPERTY_NAME = "customActionType";
|
|
182
184
|
var AUDIT_HISTORY_LABEL_PROPERTY_NAME = "auditHistoryLabel";
|
|
183
185
|
var DEDUPLICATION_PROPERTY_NAME = "deduplication";
|
|
@@ -187,9 +189,12 @@ var FORM_PROPERTY_NAME = "form";
|
|
|
187
189
|
var ACTION_TYPE_ENUM_NAME = "ActionType";
|
|
188
190
|
var VALIDATE_MEMBER_NAME = "VALIDATE";
|
|
189
191
|
var CUSTOM_MEMBER_NAME = "CUSTOM";
|
|
192
|
+
var REGISTER_MEMBER_NAME2 = "REGISTER";
|
|
190
193
|
var VALIDATE_STRING_LITERAL = "VALIDATE";
|
|
191
194
|
var CUSTOM_STRING_LITERAL = "CUSTOM";
|
|
195
|
+
var REGISTER_STRING_LITERAL2 = "REGISTER";
|
|
192
196
|
var VALIDATE_DECLARATION_VALUE = "VALIDATE_DECLARATION";
|
|
197
|
+
var VALIDATED_FLAG_VALUE = "validated";
|
|
193
198
|
function isValidateType(typeInitializer) {
|
|
194
199
|
if (typeInitializer.getKind() === import_ts_morph2.SyntaxKind.PropertyAccessExpression) {
|
|
195
200
|
const propAccess = typeInitializer.asKindOrThrow(
|
|
@@ -313,6 +318,50 @@ function transformValidateActionToCustom(obj, eventType) {
|
|
|
313
318
|
}
|
|
314
319
|
return true;
|
|
315
320
|
}
|
|
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
|
+
}
|
|
316
365
|
function processFile2(filePath, project) {
|
|
317
366
|
const sourceFile = project.getSourceFile(filePath);
|
|
318
367
|
if (!sourceFile) return 0;
|
|
@@ -378,6 +427,18 @@ function processFile2(filePath, project) {
|
|
|
378
427
|
` [${import_path2.default.relative(process.cwd(), filePath)}] Added top-level 'flags' array to defineConfig`
|
|
379
428
|
);
|
|
380
429
|
}
|
|
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
|
+
}
|
|
381
442
|
if (fileNeedsImports) {
|
|
382
443
|
ensureImports(sourceFile);
|
|
383
444
|
}
|
|
@@ -424,7 +485,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
424
485
|
}
|
|
425
486
|
console.log(
|
|
426
487
|
`
|
|
427
|
-
Done.
|
|
488
|
+
Done. Applied ${totalTransformed} change(s): VALIDATE \u2192 CUSTOM (${VALIDATE_DECLARATION_VALUE}) and '${VALIDATED_FLAG_VALUE}' remove-flag on matching REGISTER actions.`
|
|
428
489
|
);
|
|
429
490
|
}
|
|
430
491
|
|
|
@@ -667,14 +728,14 @@ var QUERY_PROPERTY_NAME = "query";
|
|
|
667
728
|
var TYPE_PROPERTY_NAME5 = "type";
|
|
668
729
|
var CLAUSES_PROPERTY_NAME = "clauses";
|
|
669
730
|
var STATUS_PROPERTY_NAME = "status";
|
|
670
|
-
var
|
|
731
|
+
var FLAGS_PROPERTY_NAME2 = "flags";
|
|
671
732
|
var TERMS_PROPERTY_NAME = "terms";
|
|
672
733
|
var TERM_PROPERTY_NAME = "term";
|
|
673
734
|
var ANY_OF_PROPERTY_NAME = "anyOf";
|
|
674
735
|
var VALIDATED_STATUS_VALUE = "VALIDATED";
|
|
675
|
-
var
|
|
736
|
+
var VALIDATED_FLAG_VALUE2 = "validated";
|
|
676
737
|
function addValidatedFlag(clause) {
|
|
677
|
-
const flagsProperty = clause.getProperty(
|
|
738
|
+
const flagsProperty = clause.getProperty(FLAGS_PROPERTY_NAME2);
|
|
678
739
|
if (flagsProperty && import_ts_morph5.Node.isPropertyAssignment(flagsProperty)) {
|
|
679
740
|
const flagsInit = flagsProperty.getInitializer();
|
|
680
741
|
if (flagsInit && import_ts_morph5.Node.isObjectLiteralExpression(flagsInit)) {
|
|
@@ -682,19 +743,19 @@ function addValidatedFlag(clause) {
|
|
|
682
743
|
if (anyOfProperty && import_ts_morph5.Node.isPropertyAssignment(anyOfProperty)) {
|
|
683
744
|
const anyOfInit = anyOfProperty.getInitializer();
|
|
684
745
|
if (anyOfInit && import_ts_morph5.Node.isArrayLiteralExpression(anyOfInit)) {
|
|
685
|
-
anyOfInit.addElement(`'${
|
|
746
|
+
anyOfInit.addElement(`'${VALIDATED_FLAG_VALUE2}'`);
|
|
686
747
|
}
|
|
687
748
|
} else {
|
|
688
749
|
flagsInit.addPropertyAssignment({
|
|
689
750
|
name: ANY_OF_PROPERTY_NAME,
|
|
690
|
-
initializer: `['${
|
|
751
|
+
initializer: `['${VALIDATED_FLAG_VALUE2}']`
|
|
691
752
|
});
|
|
692
753
|
}
|
|
693
754
|
}
|
|
694
755
|
} else {
|
|
695
756
|
clause.addPropertyAssignment({
|
|
696
|
-
name:
|
|
697
|
-
initializer: `{ ${ANY_OF_PROPERTY_NAME}: ['${
|
|
757
|
+
name: FLAGS_PROPERTY_NAME2,
|
|
758
|
+
initializer: `{ ${ANY_OF_PROPERTY_NAME}: ['${VALIDATED_FLAG_VALUE2}'] }`
|
|
698
759
|
});
|
|
699
760
|
}
|
|
700
761
|
}
|
|
@@ -860,23 +921,26 @@ var DEFINE_CONFIG_NAME4 = "defineConfig";
|
|
|
860
921
|
var DEFINE_WORKQUEUES_NAME2 = "defineWorkqueues";
|
|
861
922
|
var ACTIONS_PROPERTY_NAME4 = "actions";
|
|
862
923
|
var ACTION_PROPERTY_NAME = "action";
|
|
863
|
-
var
|
|
924
|
+
var FLAGS_PROPERTY_NAME3 = "flags";
|
|
864
925
|
var QUERY_PROPERTY_NAME2 = "query";
|
|
865
926
|
var TYPE_PROPERTY_NAME6 = "type";
|
|
927
|
+
var ID_PROPERTY_NAME2 = "id";
|
|
866
928
|
var CLAUSES_PROPERTY_NAME2 = "clauses";
|
|
867
929
|
var ANY_OF_PROPERTY_NAME2 = "anyOf";
|
|
868
930
|
var FLAG_ID = "pending-first-certificate-issuance";
|
|
869
931
|
var REGISTER_TYPE = "REGISTER";
|
|
870
932
|
var PRINT_CERTIFICATE_TYPE = "PRINT_CERTIFICATE";
|
|
871
|
-
|
|
933
|
+
function flagDefinitionInitializer(eventType) {
|
|
934
|
+
return `{
|
|
872
935
|
id: '${FLAG_ID}',
|
|
873
936
|
label: {
|
|
874
|
-
id: 'event.
|
|
937
|
+
id: 'event.${eventType}.flag.${FLAG_ID}',
|
|
875
938
|
defaultMessage: 'Pending first certificate issuance',
|
|
876
939
|
description: 'Flag label for first certificate issuance'
|
|
877
940
|
},
|
|
878
941
|
requiresAction: true
|
|
879
942
|
}`;
|
|
943
|
+
}
|
|
880
944
|
function isActionOfType(obj, typeName) {
|
|
881
945
|
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME6);
|
|
882
946
|
if (!typeProperty || !import_ts_morph6.Node.isPropertyAssignment(typeProperty)) return false;
|
|
@@ -890,18 +954,20 @@ function isActionOfType(obj, typeName) {
|
|
|
890
954
|
}
|
|
891
955
|
return false;
|
|
892
956
|
}
|
|
893
|
-
function
|
|
894
|
-
const
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
957
|
+
function getEventType(configArg) {
|
|
958
|
+
for (const propName of [TYPE_PROPERTY_NAME6, ID_PROPERTY_NAME2]) {
|
|
959
|
+
const prop = configArg.getProperty(propName);
|
|
960
|
+
if (!prop || !import_ts_morph6.Node.isPropertyAssignment(prop)) continue;
|
|
961
|
+
const initializer = prop.getInitializer();
|
|
962
|
+
if (!initializer) continue;
|
|
963
|
+
if (import_ts_morph6.Node.isStringLiteral(initializer)) {
|
|
964
|
+
return initializer.getLiteralValue().toLowerCase();
|
|
965
|
+
}
|
|
966
|
+
if (import_ts_morph6.Node.isPropertyAccessExpression(initializer)) {
|
|
967
|
+
return initializer.getName().toLowerCase();
|
|
968
|
+
}
|
|
903
969
|
}
|
|
904
|
-
return
|
|
970
|
+
return null;
|
|
905
971
|
}
|
|
906
972
|
function hasElementWithId(array3, id) {
|
|
907
973
|
for (const el of array3.getElements()) {
|
|
@@ -915,27 +981,28 @@ function hasElementWithId(array3, id) {
|
|
|
915
981
|
}
|
|
916
982
|
return false;
|
|
917
983
|
}
|
|
918
|
-
function ensureTopLevelFlagDefinition(configArg) {
|
|
919
|
-
const
|
|
984
|
+
function ensureTopLevelFlagDefinition(configArg, eventType) {
|
|
985
|
+
const initializer = flagDefinitionInitializer(eventType);
|
|
986
|
+
const flagsProp = configArg.getProperty(FLAGS_PROPERTY_NAME3);
|
|
920
987
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
921
988
|
const flagsInit = flagsProp.getInitializer();
|
|
922
989
|
if (flagsInit && import_ts_morph6.Node.isArrayLiteralExpression(flagsInit)) {
|
|
923
990
|
if (hasElementWithId(flagsInit, FLAG_ID)) return false;
|
|
924
|
-
flagsInit.addElement(
|
|
991
|
+
flagsInit.addElement(initializer);
|
|
925
992
|
return true;
|
|
926
993
|
}
|
|
927
994
|
return false;
|
|
928
995
|
}
|
|
929
996
|
configArg.addPropertyAssignment({
|
|
930
|
-
name:
|
|
997
|
+
name: FLAGS_PROPERTY_NAME3,
|
|
931
998
|
initializer: `[
|
|
932
|
-
${
|
|
999
|
+
${initializer}
|
|
933
1000
|
]`
|
|
934
1001
|
});
|
|
935
1002
|
return true;
|
|
936
1003
|
}
|
|
937
1004
|
function ensureActionOperationFlag(action, operation) {
|
|
938
|
-
const flagsProp = action.getProperty(
|
|
1005
|
+
const flagsProp = action.getProperty(FLAGS_PROPERTY_NAME3);
|
|
939
1006
|
const entry = `{ id: '${FLAG_ID}', operation: '${operation}' }`;
|
|
940
1007
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
941
1008
|
const flagsInit = flagsProp.getInitializer();
|
|
@@ -947,16 +1014,18 @@ function ensureActionOperationFlag(action, operation) {
|
|
|
947
1014
|
return false;
|
|
948
1015
|
}
|
|
949
1016
|
action.addPropertyAssignment({
|
|
950
|
-
name:
|
|
1017
|
+
name: FLAGS_PROPERTY_NAME3,
|
|
951
1018
|
initializer: `[${entry}]`
|
|
952
1019
|
});
|
|
953
1020
|
return true;
|
|
954
1021
|
}
|
|
955
|
-
function
|
|
1022
|
+
function processConfig(configArg, eventType, relPath) {
|
|
956
1023
|
let changes = 0;
|
|
957
|
-
if (ensureTopLevelFlagDefinition(configArg)) {
|
|
1024
|
+
if (ensureTopLevelFlagDefinition(configArg, eventType)) {
|
|
958
1025
|
changes++;
|
|
959
|
-
console.log(
|
|
1026
|
+
console.log(
|
|
1027
|
+
` [${relPath}] (${eventType}) Added '${FLAG_ID}' to top-level flags`
|
|
1028
|
+
);
|
|
960
1029
|
}
|
|
961
1030
|
const actionsProp = configArg.getProperty(ACTIONS_PROPERTY_NAME4);
|
|
962
1031
|
if (!actionsProp || !import_ts_morph6.Node.isPropertyAssignment(actionsProp)) return changes;
|
|
@@ -970,7 +1039,7 @@ function processBirthConfig(configArg, relPath) {
|
|
|
970
1039
|
if (ensureActionOperationFlag(element, "add")) {
|
|
971
1040
|
changes++;
|
|
972
1041
|
console.log(
|
|
973
|
-
` [${relPath}] Added '${FLAG_ID}' add-flag to REGISTER action`
|
|
1042
|
+
` [${relPath}] (${eventType}) Added '${FLAG_ID}' add-flag to REGISTER action`
|
|
974
1043
|
);
|
|
975
1044
|
}
|
|
976
1045
|
}
|
|
@@ -978,7 +1047,7 @@ function processBirthConfig(configArg, relPath) {
|
|
|
978
1047
|
if (ensureActionOperationFlag(element, "remove")) {
|
|
979
1048
|
changes++;
|
|
980
1049
|
console.log(
|
|
981
|
-
` [${relPath}] Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`
|
|
1050
|
+
` [${relPath}] (${eventType}) Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`
|
|
982
1051
|
);
|
|
983
1052
|
}
|
|
984
1053
|
}
|
|
@@ -1007,7 +1076,7 @@ function hasPrintCertificateAction(workqueue) {
|
|
|
1007
1076
|
return false;
|
|
1008
1077
|
}
|
|
1009
1078
|
function addFlagToQueryClause(clause) {
|
|
1010
|
-
const flagsProp = clause.getProperty(
|
|
1079
|
+
const flagsProp = clause.getProperty(FLAGS_PROPERTY_NAME3);
|
|
1011
1080
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
1012
1081
|
const flagsInit = flagsProp.getInitializer();
|
|
1013
1082
|
if (flagsInit && import_ts_morph6.Node.isObjectLiteralExpression(flagsInit)) {
|
|
@@ -1032,7 +1101,7 @@ function addFlagToQueryClause(clause) {
|
|
|
1032
1101
|
}
|
|
1033
1102
|
} else {
|
|
1034
1103
|
clause.addPropertyAssignment({
|
|
1035
|
-
name:
|
|
1104
|
+
name: FLAGS_PROPERTY_NAME3,
|
|
1036
1105
|
initializer: `{ ${ANY_OF_PROPERTY_NAME2}: ['${FLAG_ID}'] }`
|
|
1037
1106
|
});
|
|
1038
1107
|
return true;
|
|
@@ -1076,8 +1145,9 @@ function processFile6(filePath, project) {
|
|
|
1076
1145
|
if (args2.length === 0) continue;
|
|
1077
1146
|
const configArg = args2[0];
|
|
1078
1147
|
if (!import_ts_morph6.Node.isObjectLiteralExpression(configArg)) continue;
|
|
1079
|
-
|
|
1080
|
-
|
|
1148
|
+
const eventType = getEventType(configArg);
|
|
1149
|
+
if (!eventType) continue;
|
|
1150
|
+
totalChanges += processConfig(configArg, eventType, relPath);
|
|
1081
1151
|
}
|
|
1082
1152
|
if (calleeName === DEFINE_WORKQUEUES_NAME2) {
|
|
1083
1153
|
const args2 = call.getArguments();
|
|
@@ -1106,7 +1176,7 @@ function processFile6(filePath, project) {
|
|
|
1106
1176
|
async function main6() {
|
|
1107
1177
|
const srcDir = import_path6.default.join(process.cwd(), "src");
|
|
1108
1178
|
console.log(
|
|
1109
|
-
`Scanning for
|
|
1179
|
+
`Scanning for defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}
|
|
1110
1180
|
`
|
|
1111
1181
|
);
|
|
1112
1182
|
const project = new import_ts_morph6.Project({
|
|
@@ -1131,7 +1201,7 @@ async function main6() {
|
|
|
1131
1201
|
}
|
|
1132
1202
|
if (modifiedFiles.length === 0) {
|
|
1133
1203
|
console.log(
|
|
1134
|
-
"No
|
|
1204
|
+
"No event configs or PRINT_CERTIFICATE workqueues found. Nothing to do."
|
|
1135
1205
|
);
|
|
1136
1206
|
return;
|
|
1137
1207
|
}
|
|
@@ -3604,6 +3674,10 @@ var ACTION_PROPERTY_NAME2 = "action";
|
|
|
3604
3674
|
var CONDITIONALS_PROPERTY_NAME = "conditionals";
|
|
3605
3675
|
var TYPE_PROPERTY_NAME7 = "type";
|
|
3606
3676
|
var SLUG_PROPERTY_NAME = "slug";
|
|
3677
|
+
var READ_ACTION_TYPE = "READ";
|
|
3678
|
+
var ACTION_TYPE_IMPORT_NAME = "ActionType";
|
|
3679
|
+
var TOOLKIT_EVENTS_MODULE2 = "@opencrvs/toolkit/events";
|
|
3680
|
+
var READ_ACTION_FALLBACK_INITIALIZER = `{ type: ${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE} }`;
|
|
3607
3681
|
var SUPPORTED_WORKQUEUE_ACTION_TYPES = /* @__PURE__ */ new Set([
|
|
3608
3682
|
"READ",
|
|
3609
3683
|
"DELETE",
|
|
@@ -3651,91 +3725,137 @@ function isUnsupportedActionType(action) {
|
|
|
3651
3725
|
}
|
|
3652
3726
|
return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
|
|
3653
3727
|
}
|
|
3654
|
-
function
|
|
3655
|
-
const
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3728
|
+
function ensureValidAction(workqueue, relPath) {
|
|
3729
|
+
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
3730
|
+
const actionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
|
|
3731
|
+
if (actionProperty && import_ts_morph17.Node.isPropertyAssignment(actionProperty)) {
|
|
3732
|
+
const initializer = actionProperty.getInitializer();
|
|
3733
|
+
if (initializer && import_ts_morph17.Node.isObjectLiteralExpression(initializer)) {
|
|
3734
|
+
if (!isUnsupportedActionType(initializer)) {
|
|
3735
|
+
return { changed: false, usedReadFallback: false };
|
|
3736
|
+
}
|
|
3737
|
+
actionProperty.set({
|
|
3738
|
+
name: ACTION_PROPERTY_NAME2,
|
|
3739
|
+
initializer: READ_ACTION_FALLBACK_INITIALIZER
|
|
3740
|
+
});
|
|
3741
|
+
console.log(
|
|
3742
|
+
` [${relPath}] Replaced unsupported 'action' type with '${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE}' on workqueue '${workqueueLabel}'`
|
|
3743
|
+
);
|
|
3744
|
+
return { changed: true, usedReadFallback: true };
|
|
3745
|
+
}
|
|
3662
3746
|
}
|
|
3747
|
+
workqueue.addPropertyAssignment({
|
|
3748
|
+
name: ACTION_PROPERTY_NAME2,
|
|
3749
|
+
initializer: READ_ACTION_FALLBACK_INITIALIZER
|
|
3750
|
+
});
|
|
3751
|
+
console.log(
|
|
3752
|
+
` [${relPath}] Added default 'action: ${READ_ACTION_FALLBACK_INITIALIZER}' to workqueue '${workqueueLabel}'`
|
|
3753
|
+
);
|
|
3754
|
+
return { changed: true, usedReadFallback: true };
|
|
3755
|
+
}
|
|
3756
|
+
function migrateWorkqueueActions(workqueue, relPath) {
|
|
3663
3757
|
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
3664
|
-
const
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3758
|
+
const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME5);
|
|
3759
|
+
let actionsArrayMigrated = false;
|
|
3760
|
+
if (actionsProperty && import_ts_morph17.Node.isPropertyAssignment(actionsProperty)) {
|
|
3761
|
+
const actionsInitializer = actionsProperty.getInitializer();
|
|
3762
|
+
if (actionsInitializer && import_ts_morph17.Node.isArrayLiteralExpression(actionsInitializer)) {
|
|
3763
|
+
const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
|
|
3764
|
+
if (existingActionProperty) {
|
|
3765
|
+
if (import_ts_morph17.Node.isPropertyAssignment(existingActionProperty)) {
|
|
3766
|
+
const existingActionInitializer = existingActionProperty.getInitializer();
|
|
3767
|
+
if (existingActionInitializer && import_ts_morph17.Node.isObjectLiteralExpression(existingActionInitializer)) {
|
|
3768
|
+
const conditionalsProperty = existingActionInitializer.getProperty(
|
|
3769
|
+
CONDITIONALS_PROPERTY_NAME
|
|
3770
|
+
);
|
|
3771
|
+
if (conditionalsProperty) {
|
|
3772
|
+
conditionalsProperty.remove();
|
|
3773
|
+
console.log(
|
|
3774
|
+
` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`
|
|
3775
|
+
);
|
|
3776
|
+
}
|
|
3777
|
+
}
|
|
3778
|
+
}
|
|
3779
|
+
actionsProperty.remove();
|
|
3780
|
+
console.log(
|
|
3781
|
+
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
|
|
3671
3782
|
);
|
|
3672
|
-
|
|
3673
|
-
|
|
3783
|
+
actionsArrayMigrated = true;
|
|
3784
|
+
} else {
|
|
3785
|
+
const actionCandidates = actionsInitializer.getElements().filter(
|
|
3786
|
+
(element) => import_ts_morph17.Node.isObjectLiteralExpression(element)
|
|
3787
|
+
);
|
|
3788
|
+
if (actionCandidates.length === 0) {
|
|
3789
|
+
actionsProperty.remove();
|
|
3674
3790
|
console.log(
|
|
3675
|
-
` [${relPath}] Removed
|
|
3791
|
+
` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`
|
|
3676
3792
|
);
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3793
|
+
actionsArrayMigrated = true;
|
|
3794
|
+
} else {
|
|
3795
|
+
if (actionCandidates.length > 1) {
|
|
3796
|
+
const droppedCount = actionCandidates.length - 1;
|
|
3797
|
+
console.warn(
|
|
3798
|
+
` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
|
|
3799
|
+
);
|
|
3800
|
+
}
|
|
3801
|
+
const conditionalsProperty = actionCandidates[0].getProperty(
|
|
3802
|
+
CONDITIONALS_PROPERTY_NAME
|
|
3682
3803
|
);
|
|
3804
|
+
if (conditionalsProperty) {
|
|
3805
|
+
conditionalsProperty.remove();
|
|
3806
|
+
console.log(
|
|
3807
|
+
` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`
|
|
3808
|
+
);
|
|
3809
|
+
}
|
|
3810
|
+
if (isUnsupportedActionType(actionCandidates[0])) {
|
|
3811
|
+
actionsProperty.remove();
|
|
3812
|
+
console.log(
|
|
3813
|
+
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`
|
|
3814
|
+
);
|
|
3815
|
+
actionsArrayMigrated = true;
|
|
3816
|
+
} else {
|
|
3817
|
+
const firstActionText = actionCandidates[0].getText();
|
|
3818
|
+
workqueue.addPropertyAssignment({
|
|
3819
|
+
name: ACTION_PROPERTY_NAME2,
|
|
3820
|
+
initializer: firstActionText
|
|
3821
|
+
});
|
|
3822
|
+
actionsProperty.remove();
|
|
3823
|
+
console.log(
|
|
3824
|
+
` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
|
|
3825
|
+
);
|
|
3826
|
+
actionsArrayMigrated = true;
|
|
3827
|
+
}
|
|
3683
3828
|
}
|
|
3684
3829
|
}
|
|
3685
3830
|
}
|
|
3686
|
-
actionsProperty.remove();
|
|
3687
|
-
console.log(
|
|
3688
|
-
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
|
|
3689
|
-
);
|
|
3690
|
-
return 1;
|
|
3691
3831
|
}
|
|
3692
|
-
const
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
}
|
|
3702
|
-
if (actionCandidates.length > 1) {
|
|
3703
|
-
const droppedCount = actionCandidates.length - 1;
|
|
3704
|
-
console.warn(
|
|
3705
|
-
` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
|
|
3706
|
-
);
|
|
3707
|
-
}
|
|
3708
|
-
const conditionalsProperty = actionCandidates[0].getProperty(
|
|
3709
|
-
CONDITIONALS_PROPERTY_NAME
|
|
3832
|
+
const fallback = ensureValidAction(workqueue, relPath);
|
|
3833
|
+
return {
|
|
3834
|
+
changed: actionsArrayMigrated || fallback.changed,
|
|
3835
|
+
usedReadFallback: fallback.usedReadFallback
|
|
3836
|
+
};
|
|
3837
|
+
}
|
|
3838
|
+
function ensureActionTypeImport(sourceFile) {
|
|
3839
|
+
const existingImport = sourceFile.getImportDeclaration(
|
|
3840
|
+
(decl) => decl.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE2
|
|
3710
3841
|
);
|
|
3711
|
-
if (
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
if (isUnsupportedActionType(actionCandidates[0])) {
|
|
3718
|
-
actionsProperty.remove();
|
|
3719
|
-
console.log(
|
|
3720
|
-
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`
|
|
3721
|
-
);
|
|
3722
|
-
return 1;
|
|
3842
|
+
if (existingImport) {
|
|
3843
|
+
const alreadyImported = existingImport.getNamedImports().some((ni) => ni.getName() === ACTION_TYPE_IMPORT_NAME);
|
|
3844
|
+
if (!alreadyImported) {
|
|
3845
|
+
existingImport.addNamedImport(ACTION_TYPE_IMPORT_NAME);
|
|
3846
|
+
}
|
|
3847
|
+
return;
|
|
3723
3848
|
}
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
initializer: firstActionText
|
|
3849
|
+
sourceFile.addImportDeclaration({
|
|
3850
|
+
moduleSpecifier: TOOLKIT_EVENTS_MODULE2,
|
|
3851
|
+
namedImports: [ACTION_TYPE_IMPORT_NAME]
|
|
3728
3852
|
});
|
|
3729
|
-
actionsProperty.remove();
|
|
3730
|
-
console.log(
|
|
3731
|
-
` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
|
|
3732
|
-
);
|
|
3733
|
-
return 1;
|
|
3734
3853
|
}
|
|
3735
3854
|
function processFile13(filePath, project) {
|
|
3736
3855
|
const sourceFile = project.getSourceFile(filePath);
|
|
3737
3856
|
if (!sourceFile) return 0;
|
|
3738
3857
|
let migratedWorkqueues = 0;
|
|
3858
|
+
let needsActionTypeImport = false;
|
|
3739
3859
|
const relPath = import_path18.default.relative(process.cwd(), filePath);
|
|
3740
3860
|
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
3741
3861
|
import_ts_morph17.SyntaxKind.CallExpression
|
|
@@ -3751,9 +3871,14 @@ function processFile13(filePath, project) {
|
|
|
3751
3871
|
if (!import_ts_morph17.Node.isArrayLiteralExpression(workqueuesArg)) continue;
|
|
3752
3872
|
for (const element of workqueuesArg.getElements()) {
|
|
3753
3873
|
if (!import_ts_morph17.Node.isObjectLiteralExpression(element)) continue;
|
|
3754
|
-
|
|
3874
|
+
const result = migrateWorkqueueActions(element, relPath);
|
|
3875
|
+
if (result.changed) migratedWorkqueues++;
|
|
3876
|
+
if (result.usedReadFallback) needsActionTypeImport = true;
|
|
3755
3877
|
}
|
|
3756
3878
|
}
|
|
3879
|
+
if (needsActionTypeImport) {
|
|
3880
|
+
ensureActionTypeImport(sourceFile);
|
|
3881
|
+
}
|
|
3757
3882
|
return migratedWorkqueues;
|
|
3758
3883
|
}
|
|
3759
3884
|
async function main18() {
|
|
@@ -4088,7 +4213,7 @@ Saved ${handlerRelPath}.`);
|
|
|
4088
4213
|
// src/migrations/v2.0/checkout-upstream-files.ts
|
|
4089
4214
|
var import_child_process = require("child_process");
|
|
4090
4215
|
var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
|
|
4091
|
-
var UPSTREAM_BRANCH = "
|
|
4216
|
+
var UPSTREAM_BRANCH = "release-v2.0.0";
|
|
4092
4217
|
var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
|
|
4093
4218
|
var FILES_TO_CHECKOUT = [
|
|
4094
4219
|
"src/analytics/analytics.ts",
|
|
@@ -4638,9 +4763,13 @@ function gitShowBytes(ref, path23) {
|
|
|
4638
4763
|
return null;
|
|
4639
4764
|
}
|
|
4640
4765
|
}
|
|
4641
|
-
async function main25(
|
|
4766
|
+
async function main25({
|
|
4767
|
+
subdirs = []
|
|
4768
|
+
} = {}) {
|
|
4769
|
+
const pathspecs = subdirs.length > 0 ? subdirs.map((s) => `${INFRASTRUCTURE_DIR}/${s}/`) : [`${INFRASTRUCTURE_DIR}/`];
|
|
4770
|
+
const scopeLabel = pathspecs.map((p) => `'${p}'`).join(", ");
|
|
4642
4771
|
console.log(
|
|
4643
|
-
`Merging
|
|
4772
|
+
`Merging ${scopeLabel} from ${UPSTREAM_URL}@${UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...
|
|
4644
4773
|
`
|
|
4645
4774
|
);
|
|
4646
4775
|
assertIsGitRepo();
|
|
@@ -4655,20 +4784,12 @@ async function main25() {
|
|
|
4655
4784
|
const ref = `${TEMP_REMOTE2}/${UPSTREAM_BRANCH}`;
|
|
4656
4785
|
const baseRef = `${TEMP_REMOTE2}/${BASE_BRANCH}`;
|
|
4657
4786
|
const upstreamFiles = runGit(
|
|
4658
|
-
[
|
|
4659
|
-
"ls-tree",
|
|
4660
|
-
"-r",
|
|
4661
|
-
"--name-only",
|
|
4662
|
-
"-z",
|
|
4663
|
-
ref,
|
|
4664
|
-
"--",
|
|
4665
|
-
`${INFRASTRUCTURE_DIR}/`
|
|
4666
|
-
],
|
|
4787
|
+
["ls-tree", "-r", "--name-only", "-z", ref, "--", ...pathspecs],
|
|
4667
4788
|
{ silent: true }
|
|
4668
4789
|
).split("\0").filter(Boolean);
|
|
4669
4790
|
if (upstreamFiles.length === 0) {
|
|
4670
4791
|
console.log(
|
|
4671
|
-
` No files found under
|
|
4792
|
+
` No files found under ${scopeLabel} on ${ref}. Nothing to merge.`
|
|
4672
4793
|
);
|
|
4673
4794
|
return;
|
|
4674
4795
|
}
|
|
@@ -4743,7 +4864,9 @@ async function main25() {
|
|
|
4743
4864
|
var import_fs6 = require("fs");
|
|
4744
4865
|
var import_path25 = require("path");
|
|
4745
4866
|
var INFRASTRUCTURE_DIR2 = "infrastructure";
|
|
4746
|
-
async function main26(
|
|
4867
|
+
async function main26({
|
|
4868
|
+
keep = []
|
|
4869
|
+
} = {}) {
|
|
4747
4870
|
const fullPath = (0, import_path25.join)(process.cwd(), INFRASTRUCTURE_DIR2);
|
|
4748
4871
|
if (!(0, import_fs6.existsSync)(fullPath)) {
|
|
4749
4872
|
console.log(
|
|
@@ -4751,24 +4874,64 @@ async function main26() {
|
|
|
4751
4874
|
);
|
|
4752
4875
|
return;
|
|
4753
4876
|
}
|
|
4754
|
-
console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
|
|
4755
|
-
`);
|
|
4756
4877
|
assertIsGitRepo();
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
console.log(
|
|
4878
|
+
if (keep.length === 0) {
|
|
4879
|
+
console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
|
|
4880
|
+
`);
|
|
4881
|
+
runGit(["rm", "-rf", "--ignore-unmatch", "--", `${INFRASTRUCTURE_DIR2}/`], {
|
|
4882
|
+
silent: true
|
|
4883
|
+
});
|
|
4884
|
+
console.log(
|
|
4885
|
+
` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR2}/'.`
|
|
4886
|
+
);
|
|
4887
|
+
if ((0, import_fs6.existsSync)(fullPath)) {
|
|
4888
|
+
(0, import_fs6.rmSync)(fullPath, { recursive: true, force: true });
|
|
4889
|
+
console.log(
|
|
4890
|
+
` Removed remaining untracked files under '${INFRASTRUCTURE_DIR2}/'.`
|
|
4891
|
+
);
|
|
4892
|
+
}
|
|
4893
|
+
console.log(
|
|
4894
|
+
`
|
|
4895
|
+
Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
|
|
4896
|
+
);
|
|
4897
|
+
return;
|
|
4898
|
+
}
|
|
4899
|
+
const keepSet = new Set(keep);
|
|
4900
|
+
console.log(
|
|
4901
|
+
`Deleting contents of '${INFRASTRUCTURE_DIR2}/' except: ${[...keepSet].map((name) => `'${name}'`).join(", ")}
|
|
4902
|
+
`
|
|
4903
|
+
);
|
|
4904
|
+
const topLevelEntries = (0, import_fs6.readdirSync)(fullPath, { withFileTypes: true });
|
|
4905
|
+
let deleted = 0;
|
|
4906
|
+
for (const entry of topLevelEntries) {
|
|
4907
|
+
if (keepSet.has(entry.name)) {
|
|
4908
|
+
console.log(` Keeping '${INFRASTRUCTURE_DIR2}/${entry.name}'.`);
|
|
4909
|
+
continue;
|
|
4910
|
+
}
|
|
4911
|
+
const relPath = `${INFRASTRUCTURE_DIR2}/${entry.name}${entry.isDirectory() ? "/" : ""}`;
|
|
4912
|
+
runGit(["rm", "-rf", "--ignore-unmatch", "--", relPath], { silent: true });
|
|
4913
|
+
const fullEntryPath = (0, import_path25.join)(fullPath, entry.name);
|
|
4914
|
+
if ((0, import_fs6.existsSync)(fullEntryPath)) {
|
|
4915
|
+
(0, import_fs6.rmSync)(fullEntryPath, { recursive: true, force: true });
|
|
4916
|
+
}
|
|
4917
|
+
console.log(` Deleted '${relPath}'.`);
|
|
4918
|
+
deleted++;
|
|
4919
|
+
}
|
|
4920
|
+
const presentNames = new Set(topLevelEntries.map((e) => e.name));
|
|
4921
|
+
const missingKeeps = [...keepSet].filter((name) => !presentNames.has(name));
|
|
4922
|
+
if (missingKeeps.length > 0) {
|
|
4923
|
+
console.warn(
|
|
4924
|
+
` [warn] Requested to keep ${missingKeeps.map((n) => `'${n}'`).join(", ")} but they don't exist under '${INFRASTRUCTURE_DIR2}/'.`
|
|
4925
|
+
);
|
|
4764
4926
|
}
|
|
4765
4927
|
console.log(
|
|
4766
4928
|
`
|
|
4767
|
-
Done. Review the staged
|
|
4929
|
+
Done. Deleted ${deleted} top-level entr${deleted === 1 ? "y" : "ies"}. Review the staged deletions with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
|
|
4768
4930
|
);
|
|
4769
4931
|
}
|
|
4770
4932
|
|
|
4771
4933
|
// src/migrations/v2.0/index.ts
|
|
4934
|
+
var NON_SWARM_INFRA_SUBDIRS = ["postgres", "metabase"];
|
|
4772
4935
|
async function runUpgrade(dockerSwarm) {
|
|
4773
4936
|
await main18();
|
|
4774
4937
|
await main();
|
|
@@ -4797,7 +4960,8 @@ async function runUpgrade(dockerSwarm) {
|
|
|
4797
4960
|
if (dockerSwarm) {
|
|
4798
4961
|
await main25();
|
|
4799
4962
|
} else {
|
|
4800
|
-
await main26();
|
|
4963
|
+
await main26({ keep: NON_SWARM_INFRA_SUBDIRS });
|
|
4964
|
+
await main25({ subdirs: NON_SWARM_INFRA_SUBDIRS });
|
|
4801
4965
|
}
|
|
4802
4966
|
}
|
|
4803
4967
|
|