@opencrvs/toolkit 2.0.0-rc.f7427a1 → 2.0.0-rc.f79b1c0
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 +53 -31
- package/dist/cli.js +334 -140
- package/dist/commons/api/router.d.ts +61 -52
- package/dist/commons/application-config/index.d.ts +16 -4
- package/dist/commons/conditionals/conditionals.d.ts +6 -6
- package/dist/commons/events/ActionInput.d.ts +36 -0
- package/dist/commons/events/Draft.d.ts +1 -0
- package/dist/commons/events/FieldConfig.d.ts +10 -0
- package/dist/commons/events/locations.d.ts +38 -1
- package/dist/commons/events/mocks.test.utils.d.ts +19 -0
- package/dist/commons/events/scopes.d.ts +24 -1
- package/dist/conditionals/index.js +37 -7
- package/dist/events/index.js +143 -27
- 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 +334 -140
- 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 +50 -27
- package/dist/scopes/index.d.ts +87 -10
- package/dist/scopes/index.js +43 -8
- package/opencrvs-toolkit-2.0.0-rc.f79b1c0.tgz +0 -0
- package/package.json +1 -1
- package/opencrvs-toolkit-2.0.0-rc.f7427a1.tgz +0 -0
|
@@ -190,6 +190,8 @@ function ensureImports(sourceFile) {
|
|
|
190
190
|
var DEFINE_CONFIG_NAME2 = "defineConfig";
|
|
191
191
|
var ACTIONS_PROPERTY_NAME2 = "actions";
|
|
192
192
|
var TYPE_PROPERTY_NAME2 = "type";
|
|
193
|
+
var ID_PROPERTY_NAME = "id";
|
|
194
|
+
var FLAGS_PROPERTY_NAME = "flags";
|
|
193
195
|
var CUSTOM_ACTION_TYPE_PROPERTY_NAME = "customActionType";
|
|
194
196
|
var AUDIT_HISTORY_LABEL_PROPERTY_NAME = "auditHistoryLabel";
|
|
195
197
|
var DEDUPLICATION_PROPERTY_NAME = "deduplication";
|
|
@@ -199,9 +201,12 @@ var FORM_PROPERTY_NAME = "form";
|
|
|
199
201
|
var ACTION_TYPE_ENUM_NAME = "ActionType";
|
|
200
202
|
var VALIDATE_MEMBER_NAME = "VALIDATE";
|
|
201
203
|
var CUSTOM_MEMBER_NAME = "CUSTOM";
|
|
204
|
+
var REGISTER_MEMBER_NAME2 = "REGISTER";
|
|
202
205
|
var VALIDATE_STRING_LITERAL = "VALIDATE";
|
|
203
206
|
var CUSTOM_STRING_LITERAL = "CUSTOM";
|
|
207
|
+
var REGISTER_STRING_LITERAL2 = "REGISTER";
|
|
204
208
|
var VALIDATE_DECLARATION_VALUE = "VALIDATE_DECLARATION";
|
|
209
|
+
var VALIDATED_FLAG_VALUE = "validated";
|
|
205
210
|
function isValidateType(typeInitializer) {
|
|
206
211
|
if (typeInitializer.getKind() === import_ts_morph2.SyntaxKind.PropertyAccessExpression) {
|
|
207
212
|
const propAccess = typeInitializer.asKindOrThrow(
|
|
@@ -325,6 +330,50 @@ function transformValidateActionToCustom(obj, eventType) {
|
|
|
325
330
|
}
|
|
326
331
|
return true;
|
|
327
332
|
}
|
|
333
|
+
function isRegisterAction(action) {
|
|
334
|
+
const typeProperty = action.getProperty(TYPE_PROPERTY_NAME2);
|
|
335
|
+
if (!typeProperty || !import_ts_morph2.Node.isPropertyAssignment(typeProperty)) return false;
|
|
336
|
+
const typeInit = typeProperty.getInitializer();
|
|
337
|
+
if (!typeInit) return false;
|
|
338
|
+
if (import_ts_morph2.Node.isPropertyAccessExpression(typeInit)) {
|
|
339
|
+
const enumExpr = typeInit.getExpression();
|
|
340
|
+
return import_ts_morph2.Node.isIdentifier(enumExpr) && enumExpr.getText() === ACTION_TYPE_ENUM_NAME && typeInit.getName() === REGISTER_MEMBER_NAME2;
|
|
341
|
+
}
|
|
342
|
+
if (import_ts_morph2.Node.isStringLiteral(typeInit)) {
|
|
343
|
+
return typeInit.getLiteralValue() === REGISTER_STRING_LITERAL2;
|
|
344
|
+
}
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
function arrayHasElementWithId(array3, id) {
|
|
348
|
+
for (const el of array3.getElements()) {
|
|
349
|
+
if (!import_ts_morph2.Node.isObjectLiteralExpression(el)) continue;
|
|
350
|
+
const idProp = el.getProperty(ID_PROPERTY_NAME);
|
|
351
|
+
if (!idProp || !import_ts_morph2.Node.isPropertyAssignment(idProp)) continue;
|
|
352
|
+
const idInit = idProp.getInitializer();
|
|
353
|
+
if (idInit && import_ts_morph2.Node.isStringLiteral(idInit) && idInit.getLiteralValue() === id) {
|
|
354
|
+
return true;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return false;
|
|
358
|
+
}
|
|
359
|
+
function ensureRegisterRemovesValidatedFlag(action) {
|
|
360
|
+
const entry = `{ id: '${VALIDATED_FLAG_VALUE}', operation: 'remove' }`;
|
|
361
|
+
const flagsProp = action.getProperty(FLAGS_PROPERTY_NAME);
|
|
362
|
+
if (flagsProp && import_ts_morph2.Node.isPropertyAssignment(flagsProp)) {
|
|
363
|
+
const flagsInit = flagsProp.getInitializer();
|
|
364
|
+
if (flagsInit && import_ts_morph2.Node.isArrayLiteralExpression(flagsInit)) {
|
|
365
|
+
if (arrayHasElementWithId(flagsInit, VALIDATED_FLAG_VALUE)) return false;
|
|
366
|
+
flagsInit.addElement(entry);
|
|
367
|
+
return true;
|
|
368
|
+
}
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
action.addPropertyAssignment({
|
|
372
|
+
name: FLAGS_PROPERTY_NAME,
|
|
373
|
+
initializer: `[${entry}]`
|
|
374
|
+
});
|
|
375
|
+
return true;
|
|
376
|
+
}
|
|
328
377
|
function processFile2(filePath, project) {
|
|
329
378
|
const sourceFile = project.getSourceFile(filePath);
|
|
330
379
|
if (!sourceFile) return 0;
|
|
@@ -390,6 +439,18 @@ function processFile2(filePath, project) {
|
|
|
390
439
|
` [${import_path2.default.relative(process.cwd(), filePath)}] Added top-level 'flags' array to defineConfig`
|
|
391
440
|
);
|
|
392
441
|
}
|
|
442
|
+
if (configHadValidateAction) {
|
|
443
|
+
for (const element of actionsInitializer.getElements()) {
|
|
444
|
+
if (!import_ts_morph2.Node.isObjectLiteralExpression(element)) continue;
|
|
445
|
+
if (!isRegisterAction(element)) continue;
|
|
446
|
+
if (ensureRegisterRemovesValidatedFlag(element)) {
|
|
447
|
+
transformedCount++;
|
|
448
|
+
console.log(
|
|
449
|
+
` [${import_path2.default.relative(process.cwd(), filePath)}] Added '${VALIDATED_FLAG_VALUE}' remove-flag to REGISTER action`
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
393
454
|
if (fileNeedsImports) {
|
|
394
455
|
ensureImports(sourceFile);
|
|
395
456
|
}
|
|
@@ -436,7 +497,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
436
497
|
}
|
|
437
498
|
console.log(
|
|
438
499
|
`
|
|
439
|
-
Done.
|
|
500
|
+
Done. Applied ${totalTransformed} change(s): VALIDATE \u2192 CUSTOM (${VALIDATE_DECLARATION_VALUE}) and '${VALIDATED_FLAG_VALUE}' remove-flag on matching REGISTER actions.`
|
|
440
501
|
);
|
|
441
502
|
}
|
|
442
503
|
|
|
@@ -679,14 +740,14 @@ var QUERY_PROPERTY_NAME = "query";
|
|
|
679
740
|
var TYPE_PROPERTY_NAME5 = "type";
|
|
680
741
|
var CLAUSES_PROPERTY_NAME = "clauses";
|
|
681
742
|
var STATUS_PROPERTY_NAME = "status";
|
|
682
|
-
var
|
|
743
|
+
var FLAGS_PROPERTY_NAME2 = "flags";
|
|
683
744
|
var TERMS_PROPERTY_NAME = "terms";
|
|
684
745
|
var TERM_PROPERTY_NAME = "term";
|
|
685
746
|
var ANY_OF_PROPERTY_NAME = "anyOf";
|
|
686
747
|
var VALIDATED_STATUS_VALUE = "VALIDATED";
|
|
687
|
-
var
|
|
748
|
+
var VALIDATED_FLAG_VALUE2 = "validated";
|
|
688
749
|
function addValidatedFlag(clause) {
|
|
689
|
-
const flagsProperty = clause.getProperty(
|
|
750
|
+
const flagsProperty = clause.getProperty(FLAGS_PROPERTY_NAME2);
|
|
690
751
|
if (flagsProperty && import_ts_morph5.Node.isPropertyAssignment(flagsProperty)) {
|
|
691
752
|
const flagsInit = flagsProperty.getInitializer();
|
|
692
753
|
if (flagsInit && import_ts_morph5.Node.isObjectLiteralExpression(flagsInit)) {
|
|
@@ -694,19 +755,19 @@ function addValidatedFlag(clause) {
|
|
|
694
755
|
if (anyOfProperty && import_ts_morph5.Node.isPropertyAssignment(anyOfProperty)) {
|
|
695
756
|
const anyOfInit = anyOfProperty.getInitializer();
|
|
696
757
|
if (anyOfInit && import_ts_morph5.Node.isArrayLiteralExpression(anyOfInit)) {
|
|
697
|
-
anyOfInit.addElement(`'${
|
|
758
|
+
anyOfInit.addElement(`'${VALIDATED_FLAG_VALUE2}'`);
|
|
698
759
|
}
|
|
699
760
|
} else {
|
|
700
761
|
flagsInit.addPropertyAssignment({
|
|
701
762
|
name: ANY_OF_PROPERTY_NAME,
|
|
702
|
-
initializer: `['${
|
|
763
|
+
initializer: `['${VALIDATED_FLAG_VALUE2}']`
|
|
703
764
|
});
|
|
704
765
|
}
|
|
705
766
|
}
|
|
706
767
|
} else {
|
|
707
768
|
clause.addPropertyAssignment({
|
|
708
|
-
name:
|
|
709
|
-
initializer: `{ ${ANY_OF_PROPERTY_NAME}: ['${
|
|
769
|
+
name: FLAGS_PROPERTY_NAME2,
|
|
770
|
+
initializer: `{ ${ANY_OF_PROPERTY_NAME}: ['${VALIDATED_FLAG_VALUE2}'] }`
|
|
710
771
|
});
|
|
711
772
|
}
|
|
712
773
|
}
|
|
@@ -872,23 +933,26 @@ var DEFINE_CONFIG_NAME4 = "defineConfig";
|
|
|
872
933
|
var DEFINE_WORKQUEUES_NAME2 = "defineWorkqueues";
|
|
873
934
|
var ACTIONS_PROPERTY_NAME4 = "actions";
|
|
874
935
|
var ACTION_PROPERTY_NAME = "action";
|
|
875
|
-
var
|
|
936
|
+
var FLAGS_PROPERTY_NAME3 = "flags";
|
|
876
937
|
var QUERY_PROPERTY_NAME2 = "query";
|
|
877
938
|
var TYPE_PROPERTY_NAME6 = "type";
|
|
939
|
+
var ID_PROPERTY_NAME2 = "id";
|
|
878
940
|
var CLAUSES_PROPERTY_NAME2 = "clauses";
|
|
879
941
|
var ANY_OF_PROPERTY_NAME2 = "anyOf";
|
|
880
942
|
var FLAG_ID = "pending-first-certificate-issuance";
|
|
881
943
|
var REGISTER_TYPE = "REGISTER";
|
|
882
944
|
var PRINT_CERTIFICATE_TYPE = "PRINT_CERTIFICATE";
|
|
883
|
-
|
|
945
|
+
function flagDefinitionInitializer(eventType) {
|
|
946
|
+
return `{
|
|
884
947
|
id: '${FLAG_ID}',
|
|
885
948
|
label: {
|
|
886
|
-
id: 'event.
|
|
949
|
+
id: 'event.${eventType}.flag.${FLAG_ID}',
|
|
887
950
|
defaultMessage: 'Pending first certificate issuance',
|
|
888
951
|
description: 'Flag label for first certificate issuance'
|
|
889
952
|
},
|
|
890
953
|
requiresAction: true
|
|
891
954
|
}`;
|
|
955
|
+
}
|
|
892
956
|
function isActionOfType(obj, typeName) {
|
|
893
957
|
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME6);
|
|
894
958
|
if (!typeProperty || !import_ts_morph6.Node.isPropertyAssignment(typeProperty)) return false;
|
|
@@ -902,18 +966,20 @@ function isActionOfType(obj, typeName) {
|
|
|
902
966
|
}
|
|
903
967
|
return false;
|
|
904
968
|
}
|
|
905
|
-
function
|
|
906
|
-
const
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
969
|
+
function getEventType(configArg) {
|
|
970
|
+
for (const propName of [TYPE_PROPERTY_NAME6, ID_PROPERTY_NAME2]) {
|
|
971
|
+
const prop = configArg.getProperty(propName);
|
|
972
|
+
if (!prop || !import_ts_morph6.Node.isPropertyAssignment(prop)) continue;
|
|
973
|
+
const initializer = prop.getInitializer();
|
|
974
|
+
if (!initializer) continue;
|
|
975
|
+
if (import_ts_morph6.Node.isStringLiteral(initializer)) {
|
|
976
|
+
return initializer.getLiteralValue().toLowerCase();
|
|
977
|
+
}
|
|
978
|
+
if (import_ts_morph6.Node.isPropertyAccessExpression(initializer)) {
|
|
979
|
+
return initializer.getName().toLowerCase();
|
|
980
|
+
}
|
|
915
981
|
}
|
|
916
|
-
return
|
|
982
|
+
return null;
|
|
917
983
|
}
|
|
918
984
|
function hasElementWithId(array3, id) {
|
|
919
985
|
for (const el of array3.getElements()) {
|
|
@@ -927,27 +993,28 @@ function hasElementWithId(array3, id) {
|
|
|
927
993
|
}
|
|
928
994
|
return false;
|
|
929
995
|
}
|
|
930
|
-
function ensureTopLevelFlagDefinition(configArg) {
|
|
931
|
-
const
|
|
996
|
+
function ensureTopLevelFlagDefinition(configArg, eventType) {
|
|
997
|
+
const initializer = flagDefinitionInitializer(eventType);
|
|
998
|
+
const flagsProp = configArg.getProperty(FLAGS_PROPERTY_NAME3);
|
|
932
999
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
933
1000
|
const flagsInit = flagsProp.getInitializer();
|
|
934
1001
|
if (flagsInit && import_ts_morph6.Node.isArrayLiteralExpression(flagsInit)) {
|
|
935
1002
|
if (hasElementWithId(flagsInit, FLAG_ID)) return false;
|
|
936
|
-
flagsInit.addElement(
|
|
1003
|
+
flagsInit.addElement(initializer);
|
|
937
1004
|
return true;
|
|
938
1005
|
}
|
|
939
1006
|
return false;
|
|
940
1007
|
}
|
|
941
1008
|
configArg.addPropertyAssignment({
|
|
942
|
-
name:
|
|
1009
|
+
name: FLAGS_PROPERTY_NAME3,
|
|
943
1010
|
initializer: `[
|
|
944
|
-
${
|
|
1011
|
+
${initializer}
|
|
945
1012
|
]`
|
|
946
1013
|
});
|
|
947
1014
|
return true;
|
|
948
1015
|
}
|
|
949
1016
|
function ensureActionOperationFlag(action, operation) {
|
|
950
|
-
const flagsProp = action.getProperty(
|
|
1017
|
+
const flagsProp = action.getProperty(FLAGS_PROPERTY_NAME3);
|
|
951
1018
|
const entry = `{ id: '${FLAG_ID}', operation: '${operation}' }`;
|
|
952
1019
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
953
1020
|
const flagsInit = flagsProp.getInitializer();
|
|
@@ -959,16 +1026,18 @@ function ensureActionOperationFlag(action, operation) {
|
|
|
959
1026
|
return false;
|
|
960
1027
|
}
|
|
961
1028
|
action.addPropertyAssignment({
|
|
962
|
-
name:
|
|
1029
|
+
name: FLAGS_PROPERTY_NAME3,
|
|
963
1030
|
initializer: `[${entry}]`
|
|
964
1031
|
});
|
|
965
1032
|
return true;
|
|
966
1033
|
}
|
|
967
|
-
function
|
|
1034
|
+
function processConfig(configArg, eventType, relPath) {
|
|
968
1035
|
let changes = 0;
|
|
969
|
-
if (ensureTopLevelFlagDefinition(configArg)) {
|
|
1036
|
+
if (ensureTopLevelFlagDefinition(configArg, eventType)) {
|
|
970
1037
|
changes++;
|
|
971
|
-
console.log(
|
|
1038
|
+
console.log(
|
|
1039
|
+
` [${relPath}] (${eventType}) Added '${FLAG_ID}' to top-level flags`
|
|
1040
|
+
);
|
|
972
1041
|
}
|
|
973
1042
|
const actionsProp = configArg.getProperty(ACTIONS_PROPERTY_NAME4);
|
|
974
1043
|
if (!actionsProp || !import_ts_morph6.Node.isPropertyAssignment(actionsProp)) return changes;
|
|
@@ -982,7 +1051,7 @@ function processBirthConfig(configArg, relPath) {
|
|
|
982
1051
|
if (ensureActionOperationFlag(element, "add")) {
|
|
983
1052
|
changes++;
|
|
984
1053
|
console.log(
|
|
985
|
-
` [${relPath}] Added '${FLAG_ID}' add-flag to REGISTER action`
|
|
1054
|
+
` [${relPath}] (${eventType}) Added '${FLAG_ID}' add-flag to REGISTER action`
|
|
986
1055
|
);
|
|
987
1056
|
}
|
|
988
1057
|
}
|
|
@@ -990,7 +1059,7 @@ function processBirthConfig(configArg, relPath) {
|
|
|
990
1059
|
if (ensureActionOperationFlag(element, "remove")) {
|
|
991
1060
|
changes++;
|
|
992
1061
|
console.log(
|
|
993
|
-
` [${relPath}] Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`
|
|
1062
|
+
` [${relPath}] (${eventType}) Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`
|
|
994
1063
|
);
|
|
995
1064
|
}
|
|
996
1065
|
}
|
|
@@ -1019,7 +1088,7 @@ function hasPrintCertificateAction(workqueue) {
|
|
|
1019
1088
|
return false;
|
|
1020
1089
|
}
|
|
1021
1090
|
function addFlagToQueryClause(clause) {
|
|
1022
|
-
const flagsProp = clause.getProperty(
|
|
1091
|
+
const flagsProp = clause.getProperty(FLAGS_PROPERTY_NAME3);
|
|
1023
1092
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
1024
1093
|
const flagsInit = flagsProp.getInitializer();
|
|
1025
1094
|
if (flagsInit && import_ts_morph6.Node.isObjectLiteralExpression(flagsInit)) {
|
|
@@ -1044,7 +1113,7 @@ function addFlagToQueryClause(clause) {
|
|
|
1044
1113
|
}
|
|
1045
1114
|
} else {
|
|
1046
1115
|
clause.addPropertyAssignment({
|
|
1047
|
-
name:
|
|
1116
|
+
name: FLAGS_PROPERTY_NAME3,
|
|
1048
1117
|
initializer: `{ ${ANY_OF_PROPERTY_NAME2}: ['${FLAG_ID}'] }`
|
|
1049
1118
|
});
|
|
1050
1119
|
return true;
|
|
@@ -1088,8 +1157,9 @@ function processFile6(filePath, project) {
|
|
|
1088
1157
|
if (args.length === 0) continue;
|
|
1089
1158
|
const configArg = args[0];
|
|
1090
1159
|
if (!import_ts_morph6.Node.isObjectLiteralExpression(configArg)) continue;
|
|
1091
|
-
|
|
1092
|
-
|
|
1160
|
+
const eventType = getEventType(configArg);
|
|
1161
|
+
if (!eventType) continue;
|
|
1162
|
+
totalChanges += processConfig(configArg, eventType, relPath);
|
|
1093
1163
|
}
|
|
1094
1164
|
if (calleeName === DEFINE_WORKQUEUES_NAME2) {
|
|
1095
1165
|
const args = call.getArguments();
|
|
@@ -1118,7 +1188,7 @@ function processFile6(filePath, project) {
|
|
|
1118
1188
|
async function main6() {
|
|
1119
1189
|
const srcDir = import_path6.default.join(process.cwd(), "src");
|
|
1120
1190
|
console.log(
|
|
1121
|
-
`Scanning for
|
|
1191
|
+
`Scanning for defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}
|
|
1122
1192
|
`
|
|
1123
1193
|
);
|
|
1124
1194
|
const project = new import_ts_morph6.Project({
|
|
@@ -1143,7 +1213,7 @@ async function main6() {
|
|
|
1143
1213
|
}
|
|
1144
1214
|
if (modifiedFiles.length === 0) {
|
|
1145
1215
|
console.log(
|
|
1146
|
-
"No
|
|
1216
|
+
"No event configs or PRINT_CERTIFICATE workqueues found. Nothing to do."
|
|
1147
1217
|
);
|
|
1148
1218
|
return;
|
|
1149
1219
|
}
|
|
@@ -2122,6 +2192,10 @@ var scopeByEvent = z3.preprocess(
|
|
|
2122
2192
|
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
2123
2193
|
z3.array(z3.string()).optional()
|
|
2124
2194
|
).describe("Event type, e.g. birth, death");
|
|
2195
|
+
var userRole = z3.preprocess(
|
|
2196
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
2197
|
+
z3.array(z3.string()).optional()
|
|
2198
|
+
).describe("User role, e.g. admin, field agent");
|
|
2125
2199
|
var scopeOptionsPlaceEvent = z3.object({
|
|
2126
2200
|
event: scopeByEvent,
|
|
2127
2201
|
placeOfEvent: JurisdictionFilter.optional()
|
|
@@ -2145,6 +2219,9 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
|
|
|
2145
2219
|
var AccessLevelOptions = z3.object({
|
|
2146
2220
|
accessLevel: JurisdictionFilter.optional()
|
|
2147
2221
|
});
|
|
2222
|
+
var AllUserScopeOptions = AccessLevelOptions.extend({
|
|
2223
|
+
role: userRole.optional()
|
|
2224
|
+
});
|
|
2148
2225
|
var WorkqueueOrDashboardOptions = z3.object({
|
|
2149
2226
|
ids: z3.preprocess(
|
|
2150
2227
|
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
@@ -2154,6 +2231,7 @@ var WorkqueueOrDashboardOptions = z3.object({
|
|
|
2154
2231
|
var AllScopeOptions = z3.object({
|
|
2155
2232
|
...AllRecordScopeOptions.shape,
|
|
2156
2233
|
...AccessLevelOptions.shape,
|
|
2234
|
+
...AllUserScopeOptions.shape,
|
|
2157
2235
|
...WorkqueueOrDashboardOptions.shape
|
|
2158
2236
|
});
|
|
2159
2237
|
var ScopeOptionKey = AllScopeOptions.keyof();
|
|
@@ -2226,6 +2304,30 @@ var RecordScopeV2 = z3.discriminatedUnion("type", [
|
|
|
2226
2304
|
]).describe(
|
|
2227
2305
|
"Scopes used to check user's permission to perform actions on a record."
|
|
2228
2306
|
);
|
|
2307
|
+
var SystemScopeType = z3.enum([
|
|
2308
|
+
"organisation.read-locations",
|
|
2309
|
+
"user.read",
|
|
2310
|
+
"user.create",
|
|
2311
|
+
"user.edit",
|
|
2312
|
+
"user.search"
|
|
2313
|
+
]);
|
|
2314
|
+
var UserScopeType = SystemScopeType.extract([
|
|
2315
|
+
"user.read",
|
|
2316
|
+
"user.create",
|
|
2317
|
+
"user.edit",
|
|
2318
|
+
"user.search"
|
|
2319
|
+
]);
|
|
2320
|
+
var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
|
|
2321
|
+
var UserScopeV2 = z3.discriminatedUnion("type", [
|
|
2322
|
+
z3.object({
|
|
2323
|
+
type: ScopesWithRoleOption,
|
|
2324
|
+
options: AllUserScopeOptions.optional()
|
|
2325
|
+
}),
|
|
2326
|
+
z3.object({
|
|
2327
|
+
type: UserScopeType.extract(["user.read", "user.search"]),
|
|
2328
|
+
options: AccessLevelOptions.optional()
|
|
2329
|
+
})
|
|
2330
|
+
]);
|
|
2229
2331
|
var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
|
|
2230
2332
|
z3.object({
|
|
2231
2333
|
type: ScopesWithPlaceEventOptions,
|
|
@@ -2246,16 +2348,14 @@ var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
|
|
|
2246
2348
|
}).optional()
|
|
2247
2349
|
})
|
|
2248
2350
|
]).describe("Resolved scope with location/user IDs instead of filters.");
|
|
2249
|
-
var SystemScopeType = z3.enum([
|
|
2250
|
-
"organisation.read-locations",
|
|
2251
|
-
"user.read",
|
|
2252
|
-
"user.create",
|
|
2253
|
-
"user.edit"
|
|
2254
|
-
]);
|
|
2255
2351
|
var Scope2 = z3.discriminatedUnion("type", [
|
|
2256
2352
|
z3.object({ type: PlainScopeType }),
|
|
2257
2353
|
...RecordScopeV2.options,
|
|
2258
|
-
|
|
2354
|
+
...UserScopeV2.options,
|
|
2355
|
+
z3.object({
|
|
2356
|
+
type: z3.literal("organisation.read-locations"),
|
|
2357
|
+
options: AccessLevelOptions.optional()
|
|
2358
|
+
}),
|
|
2259
2359
|
z3.object({
|
|
2260
2360
|
type: z3.literal("workqueue"),
|
|
2261
2361
|
options: WorkqueueOrDashboardOptions
|
|
@@ -3586,6 +3686,10 @@ var ACTION_PROPERTY_NAME2 = "action";
|
|
|
3586
3686
|
var CONDITIONALS_PROPERTY_NAME = "conditionals";
|
|
3587
3687
|
var TYPE_PROPERTY_NAME7 = "type";
|
|
3588
3688
|
var SLUG_PROPERTY_NAME = "slug";
|
|
3689
|
+
var READ_ACTION_TYPE = "READ";
|
|
3690
|
+
var ACTION_TYPE_IMPORT_NAME = "ActionType";
|
|
3691
|
+
var TOOLKIT_EVENTS_MODULE2 = "@opencrvs/toolkit/events";
|
|
3692
|
+
var READ_ACTION_FALLBACK_INITIALIZER = `{ type: ${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE} }`;
|
|
3589
3693
|
var SUPPORTED_WORKQUEUE_ACTION_TYPES = /* @__PURE__ */ new Set([
|
|
3590
3694
|
"READ",
|
|
3591
3695
|
"DELETE",
|
|
@@ -3633,91 +3737,137 @@ function isUnsupportedActionType(action) {
|
|
|
3633
3737
|
}
|
|
3634
3738
|
return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
|
|
3635
3739
|
}
|
|
3636
|
-
function
|
|
3637
|
-
const
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3740
|
+
function ensureValidAction(workqueue, relPath) {
|
|
3741
|
+
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
3742
|
+
const actionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
|
|
3743
|
+
if (actionProperty && import_ts_morph17.Node.isPropertyAssignment(actionProperty)) {
|
|
3744
|
+
const initializer = actionProperty.getInitializer();
|
|
3745
|
+
if (initializer && import_ts_morph17.Node.isObjectLiteralExpression(initializer)) {
|
|
3746
|
+
if (!isUnsupportedActionType(initializer)) {
|
|
3747
|
+
return { changed: false, usedReadFallback: false };
|
|
3748
|
+
}
|
|
3749
|
+
actionProperty.set({
|
|
3750
|
+
name: ACTION_PROPERTY_NAME2,
|
|
3751
|
+
initializer: READ_ACTION_FALLBACK_INITIALIZER
|
|
3752
|
+
});
|
|
3753
|
+
console.log(
|
|
3754
|
+
` [${relPath}] Replaced unsupported 'action' type with '${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE}' on workqueue '${workqueueLabel}'`
|
|
3755
|
+
);
|
|
3756
|
+
return { changed: true, usedReadFallback: true };
|
|
3757
|
+
}
|
|
3644
3758
|
}
|
|
3759
|
+
workqueue.addPropertyAssignment({
|
|
3760
|
+
name: ACTION_PROPERTY_NAME2,
|
|
3761
|
+
initializer: READ_ACTION_FALLBACK_INITIALIZER
|
|
3762
|
+
});
|
|
3763
|
+
console.log(
|
|
3764
|
+
` [${relPath}] Added default 'action: ${READ_ACTION_FALLBACK_INITIALIZER}' to workqueue '${workqueueLabel}'`
|
|
3765
|
+
);
|
|
3766
|
+
return { changed: true, usedReadFallback: true };
|
|
3767
|
+
}
|
|
3768
|
+
function migrateWorkqueueActions(workqueue, relPath) {
|
|
3645
3769
|
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
3646
|
-
const
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3770
|
+
const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME5);
|
|
3771
|
+
let actionsArrayMigrated = false;
|
|
3772
|
+
if (actionsProperty && import_ts_morph17.Node.isPropertyAssignment(actionsProperty)) {
|
|
3773
|
+
const actionsInitializer = actionsProperty.getInitializer();
|
|
3774
|
+
if (actionsInitializer && import_ts_morph17.Node.isArrayLiteralExpression(actionsInitializer)) {
|
|
3775
|
+
const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
|
|
3776
|
+
if (existingActionProperty) {
|
|
3777
|
+
if (import_ts_morph17.Node.isPropertyAssignment(existingActionProperty)) {
|
|
3778
|
+
const existingActionInitializer = existingActionProperty.getInitializer();
|
|
3779
|
+
if (existingActionInitializer && import_ts_morph17.Node.isObjectLiteralExpression(existingActionInitializer)) {
|
|
3780
|
+
const conditionalsProperty = existingActionInitializer.getProperty(
|
|
3781
|
+
CONDITIONALS_PROPERTY_NAME
|
|
3782
|
+
);
|
|
3783
|
+
if (conditionalsProperty) {
|
|
3784
|
+
conditionalsProperty.remove();
|
|
3785
|
+
console.log(
|
|
3786
|
+
` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`
|
|
3787
|
+
);
|
|
3788
|
+
}
|
|
3789
|
+
}
|
|
3790
|
+
}
|
|
3791
|
+
actionsProperty.remove();
|
|
3792
|
+
console.log(
|
|
3793
|
+
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
|
|
3794
|
+
);
|
|
3795
|
+
actionsArrayMigrated = true;
|
|
3796
|
+
} else {
|
|
3797
|
+
const actionCandidates = actionsInitializer.getElements().filter(
|
|
3798
|
+
(element) => import_ts_morph17.Node.isObjectLiteralExpression(element)
|
|
3653
3799
|
);
|
|
3654
|
-
if (
|
|
3655
|
-
|
|
3800
|
+
if (actionCandidates.length === 0) {
|
|
3801
|
+
actionsProperty.remove();
|
|
3656
3802
|
console.log(
|
|
3657
|
-
` [${relPath}] Removed
|
|
3803
|
+
` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`
|
|
3658
3804
|
);
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3805
|
+
actionsArrayMigrated = true;
|
|
3806
|
+
} else {
|
|
3807
|
+
if (actionCandidates.length > 1) {
|
|
3808
|
+
const droppedCount = actionCandidates.length - 1;
|
|
3809
|
+
console.warn(
|
|
3810
|
+
` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
|
|
3811
|
+
);
|
|
3812
|
+
}
|
|
3813
|
+
const conditionalsProperty = actionCandidates[0].getProperty(
|
|
3814
|
+
CONDITIONALS_PROPERTY_NAME
|
|
3664
3815
|
);
|
|
3816
|
+
if (conditionalsProperty) {
|
|
3817
|
+
conditionalsProperty.remove();
|
|
3818
|
+
console.log(
|
|
3819
|
+
` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`
|
|
3820
|
+
);
|
|
3821
|
+
}
|
|
3822
|
+
if (isUnsupportedActionType(actionCandidates[0])) {
|
|
3823
|
+
actionsProperty.remove();
|
|
3824
|
+
console.log(
|
|
3825
|
+
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`
|
|
3826
|
+
);
|
|
3827
|
+
actionsArrayMigrated = true;
|
|
3828
|
+
} else {
|
|
3829
|
+
const firstActionText = actionCandidates[0].getText();
|
|
3830
|
+
workqueue.addPropertyAssignment({
|
|
3831
|
+
name: ACTION_PROPERTY_NAME2,
|
|
3832
|
+
initializer: firstActionText
|
|
3833
|
+
});
|
|
3834
|
+
actionsProperty.remove();
|
|
3835
|
+
console.log(
|
|
3836
|
+
` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
|
|
3837
|
+
);
|
|
3838
|
+
actionsArrayMigrated = true;
|
|
3839
|
+
}
|
|
3665
3840
|
}
|
|
3666
3841
|
}
|
|
3667
3842
|
}
|
|
3668
|
-
actionsProperty.remove();
|
|
3669
|
-
console.log(
|
|
3670
|
-
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
|
|
3671
|
-
);
|
|
3672
|
-
return 1;
|
|
3673
3843
|
}
|
|
3674
|
-
const
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
}
|
|
3684
|
-
if (actionCandidates.length > 1) {
|
|
3685
|
-
const droppedCount = actionCandidates.length - 1;
|
|
3686
|
-
console.warn(
|
|
3687
|
-
` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
|
|
3688
|
-
);
|
|
3689
|
-
}
|
|
3690
|
-
const conditionalsProperty = actionCandidates[0].getProperty(
|
|
3691
|
-
CONDITIONALS_PROPERTY_NAME
|
|
3844
|
+
const fallback = ensureValidAction(workqueue, relPath);
|
|
3845
|
+
return {
|
|
3846
|
+
changed: actionsArrayMigrated || fallback.changed,
|
|
3847
|
+
usedReadFallback: fallback.usedReadFallback
|
|
3848
|
+
};
|
|
3849
|
+
}
|
|
3850
|
+
function ensureActionTypeImport(sourceFile) {
|
|
3851
|
+
const existingImport = sourceFile.getImportDeclaration(
|
|
3852
|
+
(decl) => decl.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE2
|
|
3692
3853
|
);
|
|
3693
|
-
if (
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
if (isUnsupportedActionType(actionCandidates[0])) {
|
|
3700
|
-
actionsProperty.remove();
|
|
3701
|
-
console.log(
|
|
3702
|
-
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`
|
|
3703
|
-
);
|
|
3704
|
-
return 1;
|
|
3854
|
+
if (existingImport) {
|
|
3855
|
+
const alreadyImported = existingImport.getNamedImports().some((ni) => ni.getName() === ACTION_TYPE_IMPORT_NAME);
|
|
3856
|
+
if (!alreadyImported) {
|
|
3857
|
+
existingImport.addNamedImport(ACTION_TYPE_IMPORT_NAME);
|
|
3858
|
+
}
|
|
3859
|
+
return;
|
|
3705
3860
|
}
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
initializer: firstActionText
|
|
3861
|
+
sourceFile.addImportDeclaration({
|
|
3862
|
+
moduleSpecifier: TOOLKIT_EVENTS_MODULE2,
|
|
3863
|
+
namedImports: [ACTION_TYPE_IMPORT_NAME]
|
|
3710
3864
|
});
|
|
3711
|
-
actionsProperty.remove();
|
|
3712
|
-
console.log(
|
|
3713
|
-
` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
|
|
3714
|
-
);
|
|
3715
|
-
return 1;
|
|
3716
3865
|
}
|
|
3717
3866
|
function processFile13(filePath, project) {
|
|
3718
3867
|
const sourceFile = project.getSourceFile(filePath);
|
|
3719
3868
|
if (!sourceFile) return 0;
|
|
3720
3869
|
let migratedWorkqueues = 0;
|
|
3870
|
+
let needsActionTypeImport = false;
|
|
3721
3871
|
const relPath = import_path18.default.relative(process.cwd(), filePath);
|
|
3722
3872
|
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
3723
3873
|
import_ts_morph17.SyntaxKind.CallExpression
|
|
@@ -3733,9 +3883,14 @@ function processFile13(filePath, project) {
|
|
|
3733
3883
|
if (!import_ts_morph17.Node.isArrayLiteralExpression(workqueuesArg)) continue;
|
|
3734
3884
|
for (const element of workqueuesArg.getElements()) {
|
|
3735
3885
|
if (!import_ts_morph17.Node.isObjectLiteralExpression(element)) continue;
|
|
3736
|
-
|
|
3886
|
+
const result = migrateWorkqueueActions(element, relPath);
|
|
3887
|
+
if (result.changed) migratedWorkqueues++;
|
|
3888
|
+
if (result.usedReadFallback) needsActionTypeImport = true;
|
|
3737
3889
|
}
|
|
3738
3890
|
}
|
|
3891
|
+
if (needsActionTypeImport) {
|
|
3892
|
+
ensureActionTypeImport(sourceFile);
|
|
3893
|
+
}
|
|
3739
3894
|
return migratedWorkqueues;
|
|
3740
3895
|
}
|
|
3741
3896
|
async function main18() {
|
|
@@ -4070,7 +4225,7 @@ Saved ${handlerRelPath}.`);
|
|
|
4070
4225
|
// src/migrations/v2.0/checkout-upstream-files.ts
|
|
4071
4226
|
var import_child_process = require("child_process");
|
|
4072
4227
|
var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
|
|
4073
|
-
var UPSTREAM_BRANCH = "
|
|
4228
|
+
var UPSTREAM_BRANCH = "release-v2.0.0";
|
|
4074
4229
|
var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
|
|
4075
4230
|
var FILES_TO_CHECKOUT = [
|
|
4076
4231
|
"src/analytics/analytics.ts",
|
|
@@ -4620,9 +4775,13 @@ function gitShowBytes(ref, path23) {
|
|
|
4620
4775
|
return null;
|
|
4621
4776
|
}
|
|
4622
4777
|
}
|
|
4623
|
-
async function main25(
|
|
4778
|
+
async function main25({
|
|
4779
|
+
subdirs = []
|
|
4780
|
+
} = {}) {
|
|
4781
|
+
const pathspecs = subdirs.length > 0 ? subdirs.map((s) => `${INFRASTRUCTURE_DIR}/${s}/`) : [`${INFRASTRUCTURE_DIR}/`];
|
|
4782
|
+
const scopeLabel = pathspecs.map((p) => `'${p}'`).join(", ");
|
|
4624
4783
|
console.log(
|
|
4625
|
-
`Merging
|
|
4784
|
+
`Merging ${scopeLabel} from ${UPSTREAM_URL}@${UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...
|
|
4626
4785
|
`
|
|
4627
4786
|
);
|
|
4628
4787
|
assertIsGitRepo();
|
|
@@ -4637,20 +4796,12 @@ async function main25() {
|
|
|
4637
4796
|
const ref = `${TEMP_REMOTE2}/${UPSTREAM_BRANCH}`;
|
|
4638
4797
|
const baseRef = `${TEMP_REMOTE2}/${BASE_BRANCH}`;
|
|
4639
4798
|
const upstreamFiles = runGit(
|
|
4640
|
-
[
|
|
4641
|
-
"ls-tree",
|
|
4642
|
-
"-r",
|
|
4643
|
-
"--name-only",
|
|
4644
|
-
"-z",
|
|
4645
|
-
ref,
|
|
4646
|
-
"--",
|
|
4647
|
-
`${INFRASTRUCTURE_DIR}/`
|
|
4648
|
-
],
|
|
4799
|
+
["ls-tree", "-r", "--name-only", "-z", ref, "--", ...pathspecs],
|
|
4649
4800
|
{ silent: true }
|
|
4650
4801
|
).split("\0").filter(Boolean);
|
|
4651
4802
|
if (upstreamFiles.length === 0) {
|
|
4652
4803
|
console.log(
|
|
4653
|
-
` No files found under
|
|
4804
|
+
` No files found under ${scopeLabel} on ${ref}. Nothing to merge.`
|
|
4654
4805
|
);
|
|
4655
4806
|
return;
|
|
4656
4807
|
}
|
|
@@ -4725,7 +4876,9 @@ async function main25() {
|
|
|
4725
4876
|
var import_fs6 = require("fs");
|
|
4726
4877
|
var import_path25 = require("path");
|
|
4727
4878
|
var INFRASTRUCTURE_DIR2 = "infrastructure";
|
|
4728
|
-
async function main26(
|
|
4879
|
+
async function main26({
|
|
4880
|
+
keep = []
|
|
4881
|
+
} = {}) {
|
|
4729
4882
|
const fullPath = (0, import_path25.join)(process.cwd(), INFRASTRUCTURE_DIR2);
|
|
4730
4883
|
if (!(0, import_fs6.existsSync)(fullPath)) {
|
|
4731
4884
|
console.log(
|
|
@@ -4733,24 +4886,64 @@ async function main26() {
|
|
|
4733
4886
|
);
|
|
4734
4887
|
return;
|
|
4735
4888
|
}
|
|
4736
|
-
console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
|
|
4737
|
-
`);
|
|
4738
4889
|
assertIsGitRepo();
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
console.log(
|
|
4890
|
+
if (keep.length === 0) {
|
|
4891
|
+
console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
|
|
4892
|
+
`);
|
|
4893
|
+
runGit(["rm", "-rf", "--ignore-unmatch", "--", `${INFRASTRUCTURE_DIR2}/`], {
|
|
4894
|
+
silent: true
|
|
4895
|
+
});
|
|
4896
|
+
console.log(
|
|
4897
|
+
` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR2}/'.`
|
|
4898
|
+
);
|
|
4899
|
+
if ((0, import_fs6.existsSync)(fullPath)) {
|
|
4900
|
+
(0, import_fs6.rmSync)(fullPath, { recursive: true, force: true });
|
|
4901
|
+
console.log(
|
|
4902
|
+
` Removed remaining untracked files under '${INFRASTRUCTURE_DIR2}/'.`
|
|
4903
|
+
);
|
|
4904
|
+
}
|
|
4905
|
+
console.log(
|
|
4906
|
+
`
|
|
4907
|
+
Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
|
|
4908
|
+
);
|
|
4909
|
+
return;
|
|
4910
|
+
}
|
|
4911
|
+
const keepSet = new Set(keep);
|
|
4912
|
+
console.log(
|
|
4913
|
+
`Deleting contents of '${INFRASTRUCTURE_DIR2}/' except: ${[...keepSet].map((name) => `'${name}'`).join(", ")}
|
|
4914
|
+
`
|
|
4915
|
+
);
|
|
4916
|
+
const topLevelEntries = (0, import_fs6.readdirSync)(fullPath, { withFileTypes: true });
|
|
4917
|
+
let deleted = 0;
|
|
4918
|
+
for (const entry of topLevelEntries) {
|
|
4919
|
+
if (keepSet.has(entry.name)) {
|
|
4920
|
+
console.log(` Keeping '${INFRASTRUCTURE_DIR2}/${entry.name}'.`);
|
|
4921
|
+
continue;
|
|
4922
|
+
}
|
|
4923
|
+
const relPath = `${INFRASTRUCTURE_DIR2}/${entry.name}${entry.isDirectory() ? "/" : ""}`;
|
|
4924
|
+
runGit(["rm", "-rf", "--ignore-unmatch", "--", relPath], { silent: true });
|
|
4925
|
+
const fullEntryPath = (0, import_path25.join)(fullPath, entry.name);
|
|
4926
|
+
if ((0, import_fs6.existsSync)(fullEntryPath)) {
|
|
4927
|
+
(0, import_fs6.rmSync)(fullEntryPath, { recursive: true, force: true });
|
|
4928
|
+
}
|
|
4929
|
+
console.log(` Deleted '${relPath}'.`);
|
|
4930
|
+
deleted++;
|
|
4931
|
+
}
|
|
4932
|
+
const presentNames = new Set(topLevelEntries.map((e) => e.name));
|
|
4933
|
+
const missingKeeps = [...keepSet].filter((name) => !presentNames.has(name));
|
|
4934
|
+
if (missingKeeps.length > 0) {
|
|
4935
|
+
console.warn(
|
|
4936
|
+
` [warn] Requested to keep ${missingKeeps.map((n) => `'${n}'`).join(", ")} but they don't exist under '${INFRASTRUCTURE_DIR2}/'.`
|
|
4937
|
+
);
|
|
4746
4938
|
}
|
|
4747
4939
|
console.log(
|
|
4748
4940
|
`
|
|
4749
|
-
Done. Review the staged
|
|
4941
|
+
Done. Deleted ${deleted} top-level entr${deleted === 1 ? "y" : "ies"}. Review the staged deletions with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
|
|
4750
4942
|
);
|
|
4751
4943
|
}
|
|
4752
4944
|
|
|
4753
4945
|
// src/migrations/v2.0/index.ts
|
|
4946
|
+
var NON_SWARM_INFRA_SUBDIRS = ["postgres", "metabase"];
|
|
4754
4947
|
async function runUpgrade(dockerSwarm) {
|
|
4755
4948
|
await main18();
|
|
4756
4949
|
await main();
|
|
@@ -4779,6 +4972,7 @@ async function runUpgrade(dockerSwarm) {
|
|
|
4779
4972
|
if (dockerSwarm) {
|
|
4780
4973
|
await main25();
|
|
4781
4974
|
} else {
|
|
4782
|
-
await main26();
|
|
4975
|
+
await main26({ keep: NON_SWARM_INFRA_SUBDIRS });
|
|
4976
|
+
await main25({ subdirs: NON_SWARM_INFRA_SUBDIRS });
|
|
4783
4977
|
}
|
|
4784
4978
|
}
|