@opencrvs/toolkit 2.0.0-rc.f78dc59 → 2.0.0-rc.f85460d
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/cli.js +40 -110
- 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 +35 -60
- package/dist/migrations/v2.0/index.js +40 -110
- 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 +1 -90
- package/opencrvs-toolkit-2.0.0-rc.f85460d.tgz +0 -0
- package/package.json +1 -1
- package/opencrvs-toolkit-2.0.0-rc.f78dc59.tgz +0 -0
package/dist/cli.js
CHANGED
|
@@ -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;
|
|
@@ -427,18 +378,6 @@ function processFile2(filePath, project) {
|
|
|
427
378
|
` [${import_path2.default.relative(process.cwd(), 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
|
}
|
|
@@ -485,7 +424,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
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
|
|
|
@@ -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
|
}
|
|
@@ -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;
|
|
@@ -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();
|
|
@@ -1176,7 +1106,7 @@ function processFile6(filePath, project) {
|
|
|
1176
1106
|
async function main6() {
|
|
1177
1107
|
const srcDir = import_path6.default.join(process.cwd(), "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
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add-birth-certificate-issuance-flag.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/add-birth-certificate-issuance-flag.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"add-birth-certificate-issuance-flag.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/add-birth-certificate-issuance-flag.ts"],"names":[],"mappings":"AA2aA,iBAAe,IAAI,kBAiDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -24,17 +24,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
exports.main = main;
|
|
26
26
|
/**
|
|
27
|
-
* Codemod: Add `pending-first-certificate-issuance` flag to event configs and workqueues.
|
|
27
|
+
* Codemod: Add `pending-first-certificate-issuance` flag to birth event configs and workqueues.
|
|
28
28
|
*
|
|
29
29
|
* Usage:
|
|
30
30
|
* ts-node -r tsconfig-paths/register src/migrations/v2.0/add-birth-certificate-issuance-flag.ts
|
|
31
31
|
*
|
|
32
32
|
* What it does:
|
|
33
|
-
* defineConfig (
|
|
33
|
+
* defineConfig (birth type only):
|
|
34
34
|
* - Ensures the top-level `flags` array contains the `pending-first-certificate-issuance`
|
|
35
|
-
* flag definition
|
|
36
|
-
* `event.birth.flag.pending-first-certificate-issuance`,
|
|
37
|
-
* `event.death.flag.pending-first-certificate-issuance`.
|
|
35
|
+
* flag definition
|
|
38
36
|
* - Ensures every `REGISTER` action has
|
|
39
37
|
* `flags: [{ id: 'pending-first-certificate-issuance', operation: 'add' }]`
|
|
40
38
|
* - Ensures every `PRINT_CERTIFICATE` action has
|
|
@@ -57,27 +55,20 @@ const ACTION_PROPERTY_NAME = 'action';
|
|
|
57
55
|
const FLAGS_PROPERTY_NAME = 'flags';
|
|
58
56
|
const QUERY_PROPERTY_NAME = 'query';
|
|
59
57
|
const TYPE_PROPERTY_NAME = 'type';
|
|
60
|
-
const ID_PROPERTY_NAME = 'id';
|
|
61
58
|
const CLAUSES_PROPERTY_NAME = 'clauses';
|
|
62
59
|
const ANY_OF_PROPERTY_NAME = 'anyOf';
|
|
63
60
|
const FLAG_ID = 'pending-first-certificate-issuance';
|
|
64
61
|
const REGISTER_TYPE = 'REGISTER';
|
|
65
62
|
const PRINT_CERTIFICATE_TYPE = 'PRINT_CERTIFICATE';
|
|
66
|
-
|
|
67
|
-
* Builds the flag-definition object literal for a given event type so the i18n
|
|
68
|
-
* `label.id` is namespaced per event (e.g. `event.death.flag.…`).
|
|
69
|
-
*/
|
|
70
|
-
function flagDefinitionInitializer(eventType) {
|
|
71
|
-
return `{
|
|
63
|
+
const FLAG_DEFINITION_INITIALIZER = `{
|
|
72
64
|
id: '${FLAG_ID}',
|
|
73
65
|
label: {
|
|
74
|
-
id: 'event
|
|
66
|
+
id: 'event.birth.flag.${FLAG_ID}',
|
|
75
67
|
defaultMessage: 'Pending first certificate issuance',
|
|
76
68
|
description: 'Flag label for first certificate issuance'
|
|
77
69
|
},
|
|
78
70
|
requiresAction: true
|
|
79
71
|
}`;
|
|
80
|
-
}
|
|
81
72
|
// ─── Generic helpers ──────────────────────────────────────────────────────────
|
|
82
73
|
/**
|
|
83
74
|
* Returns true if the object's `type` property matches the given type name.
|
|
@@ -99,36 +90,23 @@ function isActionOfType(obj, typeName) {
|
|
|
99
90
|
return false;
|
|
100
91
|
}
|
|
101
92
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* shifted across core/country-config versions, so both are tried.
|
|
105
|
-
*
|
|
106
|
-
* Handles all known shapes:
|
|
107
|
-
* - `type: 'birth'` / `id: 'birth'`
|
|
108
|
-
* - `type: EventType.BIRTH` / `id: Event.Birth`
|
|
109
|
-
*
|
|
110
|
-
* For `PropertyAccessExpression` (enum access), the *member name* is returned
|
|
111
|
-
* lower-cased — this works for the conventional `EventType.BIRTH = 'birth'` and
|
|
112
|
-
* `Event.Birth = 'birth'` mappings used in core and country configs.
|
|
113
|
-
*
|
|
114
|
-
* Returns null when no event type can be determined.
|
|
93
|
+
* Returns true when the `defineConfig` root config object describes a birth event.
|
|
94
|
+
* Handles both `'birth'` string literal and `EventType.BIRTH` enum access.
|
|
115
95
|
*/
|
|
116
|
-
function
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return initializer.getName().toLowerCase();
|
|
129
|
-
}
|
|
96
|
+
function isBirthConfig(configArg) {
|
|
97
|
+
const typeProperty = configArg.getProperty(TYPE_PROPERTY_NAME);
|
|
98
|
+
if (!typeProperty || !ts_morph_1.Node.isPropertyAssignment(typeProperty))
|
|
99
|
+
return false;
|
|
100
|
+
const initializer = typeProperty.getInitializer();
|
|
101
|
+
if (!initializer)
|
|
102
|
+
return false;
|
|
103
|
+
if (ts_morph_1.Node.isStringLiteral(initializer)) {
|
|
104
|
+
return initializer.getLiteralValue().toLowerCase() === 'birth';
|
|
105
|
+
}
|
|
106
|
+
if (ts_morph_1.Node.isPropertyAccessExpression(initializer)) {
|
|
107
|
+
return initializer.getName().toLowerCase() === 'birth';
|
|
130
108
|
}
|
|
131
|
-
return
|
|
109
|
+
return false;
|
|
132
110
|
}
|
|
133
111
|
/**
|
|
134
112
|
* Returns true if an array literal contains an object literal with `id: <id>`.
|
|
@@ -151,19 +129,17 @@ function hasElementWithId(array, id) {
|
|
|
151
129
|
}
|
|
152
130
|
// ─── defineConfig helpers ─────────────────────────────────────────────────────
|
|
153
131
|
/**
|
|
154
|
-
* Ensures the top-level `flags` array in a `defineConfig` contains the
|
|
155
|
-
* `pending-first-certificate-issuance` flag definition.
|
|
156
|
-
* `label.id` is namespaced per event type (e.g. `event.death.flag.…`).
|
|
132
|
+
* Ensures the top-level `flags` array in a birth `defineConfig` contains the
|
|
133
|
+
* `pending-first-certificate-issuance` flag definition.
|
|
157
134
|
*/
|
|
158
|
-
function ensureTopLevelFlagDefinition(configArg
|
|
159
|
-
const initializer = flagDefinitionInitializer(eventType);
|
|
135
|
+
function ensureTopLevelFlagDefinition(configArg) {
|
|
160
136
|
const flagsProp = configArg.getProperty(FLAGS_PROPERTY_NAME);
|
|
161
137
|
if (flagsProp && ts_morph_1.Node.isPropertyAssignment(flagsProp)) {
|
|
162
138
|
const flagsInit = flagsProp.getInitializer();
|
|
163
139
|
if (flagsInit && ts_morph_1.Node.isArrayLiteralExpression(flagsInit)) {
|
|
164
140
|
if (hasElementWithId(flagsInit, FLAG_ID))
|
|
165
141
|
return false;
|
|
166
|
-
flagsInit.addElement(
|
|
142
|
+
flagsInit.addElement(FLAG_DEFINITION_INITIALIZER);
|
|
167
143
|
return true;
|
|
168
144
|
}
|
|
169
145
|
return false;
|
|
@@ -171,7 +147,7 @@ function ensureTopLevelFlagDefinition(configArg, eventType) {
|
|
|
171
147
|
// No `flags` property at all — create it
|
|
172
148
|
configArg.addPropertyAssignment({
|
|
173
149
|
name: FLAGS_PROPERTY_NAME,
|
|
174
|
-
initializer: `[\n ${
|
|
150
|
+
initializer: `[\n ${FLAG_DEFINITION_INITIALIZER}\n]`
|
|
175
151
|
});
|
|
176
152
|
return true;
|
|
177
153
|
}
|
|
@@ -198,15 +174,15 @@ function ensureActionOperationFlag(action, operation) {
|
|
|
198
174
|
return true;
|
|
199
175
|
}
|
|
200
176
|
/**
|
|
201
|
-
* Processes a
|
|
177
|
+
* Processes a birth defineConfig object: ensures top-level flag definition,
|
|
202
178
|
* REGISTER action flags, and PRINT_CERTIFICATE action flags.
|
|
203
179
|
* Returns the number of changes made.
|
|
204
180
|
*/
|
|
205
|
-
function
|
|
181
|
+
function processBirthConfig(configArg, relPath) {
|
|
206
182
|
let changes = 0;
|
|
207
|
-
if (ensureTopLevelFlagDefinition(configArg
|
|
183
|
+
if (ensureTopLevelFlagDefinition(configArg)) {
|
|
208
184
|
changes++;
|
|
209
|
-
console.log(` [${relPath}]
|
|
185
|
+
console.log(` [${relPath}] Added '${FLAG_ID}' to top-level flags`);
|
|
210
186
|
}
|
|
211
187
|
const actionsProp = configArg.getProperty(ACTIONS_PROPERTY_NAME);
|
|
212
188
|
if (!actionsProp || !ts_morph_1.Node.isPropertyAssignment(actionsProp))
|
|
@@ -221,13 +197,13 @@ function processConfig(configArg, eventType, relPath) {
|
|
|
221
197
|
if (isActionOfType(element, REGISTER_TYPE)) {
|
|
222
198
|
if (ensureActionOperationFlag(element, 'add')) {
|
|
223
199
|
changes++;
|
|
224
|
-
console.log(` [${relPath}]
|
|
200
|
+
console.log(` [${relPath}] Added '${FLAG_ID}' add-flag to REGISTER action`);
|
|
225
201
|
}
|
|
226
202
|
}
|
|
227
203
|
if (isActionOfType(element, PRINT_CERTIFICATE_TYPE)) {
|
|
228
204
|
if (ensureActionOperationFlag(element, 'remove')) {
|
|
229
205
|
changes++;
|
|
230
|
-
console.log(` [${relPath}]
|
|
206
|
+
console.log(` [${relPath}] Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`);
|
|
231
207
|
}
|
|
232
208
|
}
|
|
233
209
|
}
|
|
@@ -356,10 +332,9 @@ function processFile(filePath, project) {
|
|
|
356
332
|
const configArg = args[0];
|
|
357
333
|
if (!ts_morph_1.Node.isObjectLiteralExpression(configArg))
|
|
358
334
|
continue;
|
|
359
|
-
|
|
360
|
-
if (!eventType)
|
|
335
|
+
if (!isBirthConfig(configArg))
|
|
361
336
|
continue;
|
|
362
|
-
totalChanges +=
|
|
337
|
+
totalChanges += processBirthConfig(configArg, relPath);
|
|
363
338
|
}
|
|
364
339
|
// ── defineWorkqueues ──────────────────────────────────────────────────────
|
|
365
340
|
if (calleeName === DEFINE_WORKQUEUES_NAME) {
|
|
@@ -394,7 +369,7 @@ function processFile(filePath, project) {
|
|
|
394
369
|
function main() {
|
|
395
370
|
return __awaiter(this, void 0, void 0, function* () {
|
|
396
371
|
const srcDir = path_1.default.join(process.cwd(), 'src');
|
|
397
|
-
console.log(`Scanning for defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}\n`);
|
|
372
|
+
console.log(`Scanning for birth defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}\n`);
|
|
398
373
|
const project = new ts_morph_1.Project({
|
|
399
374
|
tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
|
|
400
375
|
skipAddingFilesFromTsConfig: false
|
|
@@ -415,7 +390,7 @@ function main() {
|
|
|
415
390
|
}
|
|
416
391
|
}
|
|
417
392
|
if (modifiedFiles.length === 0) {
|
|
418
|
-
console.log('No
|
|
393
|
+
console.log('No birth configs or PRINT_CERTIFICATE workqueues found. Nothing to do.');
|
|
419
394
|
return;
|
|
420
395
|
}
|
|
421
396
|
console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
|
|
@@ -190,8 +190,6 @@ 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";
|
|
195
193
|
var CUSTOM_ACTION_TYPE_PROPERTY_NAME = "customActionType";
|
|
196
194
|
var AUDIT_HISTORY_LABEL_PROPERTY_NAME = "auditHistoryLabel";
|
|
197
195
|
var DEDUPLICATION_PROPERTY_NAME = "deduplication";
|
|
@@ -201,12 +199,9 @@ var FORM_PROPERTY_NAME = "form";
|
|
|
201
199
|
var ACTION_TYPE_ENUM_NAME = "ActionType";
|
|
202
200
|
var VALIDATE_MEMBER_NAME = "VALIDATE";
|
|
203
201
|
var CUSTOM_MEMBER_NAME = "CUSTOM";
|
|
204
|
-
var REGISTER_MEMBER_NAME2 = "REGISTER";
|
|
205
202
|
var VALIDATE_STRING_LITERAL = "VALIDATE";
|
|
206
203
|
var CUSTOM_STRING_LITERAL = "CUSTOM";
|
|
207
|
-
var REGISTER_STRING_LITERAL2 = "REGISTER";
|
|
208
204
|
var VALIDATE_DECLARATION_VALUE = "VALIDATE_DECLARATION";
|
|
209
|
-
var VALIDATED_FLAG_VALUE = "validated";
|
|
210
205
|
function isValidateType(typeInitializer) {
|
|
211
206
|
if (typeInitializer.getKind() === import_ts_morph2.SyntaxKind.PropertyAccessExpression) {
|
|
212
207
|
const propAccess = typeInitializer.asKindOrThrow(
|
|
@@ -330,50 +325,6 @@ function transformValidateActionToCustom(obj, eventType) {
|
|
|
330
325
|
}
|
|
331
326
|
return true;
|
|
332
327
|
}
|
|
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
|
-
}
|
|
377
328
|
function processFile2(filePath, project) {
|
|
378
329
|
const sourceFile = project.getSourceFile(filePath);
|
|
379
330
|
if (!sourceFile) return 0;
|
|
@@ -439,18 +390,6 @@ function processFile2(filePath, project) {
|
|
|
439
390
|
` [${import_path2.default.relative(process.cwd(), filePath)}] Added top-level 'flags' array to defineConfig`
|
|
440
391
|
);
|
|
441
392
|
}
|
|
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
|
-
}
|
|
454
393
|
if (fileNeedsImports) {
|
|
455
394
|
ensureImports(sourceFile);
|
|
456
395
|
}
|
|
@@ -497,7 +436,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
497
436
|
}
|
|
498
437
|
console.log(
|
|
499
438
|
`
|
|
500
|
-
Done.
|
|
439
|
+
Done. Transformed ${totalTransformed} VALIDATE action(s) to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'.`
|
|
501
440
|
);
|
|
502
441
|
}
|
|
503
442
|
|
|
@@ -740,14 +679,14 @@ var QUERY_PROPERTY_NAME = "query";
|
|
|
740
679
|
var TYPE_PROPERTY_NAME5 = "type";
|
|
741
680
|
var CLAUSES_PROPERTY_NAME = "clauses";
|
|
742
681
|
var STATUS_PROPERTY_NAME = "status";
|
|
743
|
-
var
|
|
682
|
+
var FLAGS_PROPERTY_NAME = "flags";
|
|
744
683
|
var TERMS_PROPERTY_NAME = "terms";
|
|
745
684
|
var TERM_PROPERTY_NAME = "term";
|
|
746
685
|
var ANY_OF_PROPERTY_NAME = "anyOf";
|
|
747
686
|
var VALIDATED_STATUS_VALUE = "VALIDATED";
|
|
748
|
-
var
|
|
687
|
+
var VALIDATED_FLAG_VALUE = "validated";
|
|
749
688
|
function addValidatedFlag(clause) {
|
|
750
|
-
const flagsProperty = clause.getProperty(
|
|
689
|
+
const flagsProperty = clause.getProperty(FLAGS_PROPERTY_NAME);
|
|
751
690
|
if (flagsProperty && import_ts_morph5.Node.isPropertyAssignment(flagsProperty)) {
|
|
752
691
|
const flagsInit = flagsProperty.getInitializer();
|
|
753
692
|
if (flagsInit && import_ts_morph5.Node.isObjectLiteralExpression(flagsInit)) {
|
|
@@ -755,19 +694,19 @@ function addValidatedFlag(clause) {
|
|
|
755
694
|
if (anyOfProperty && import_ts_morph5.Node.isPropertyAssignment(anyOfProperty)) {
|
|
756
695
|
const anyOfInit = anyOfProperty.getInitializer();
|
|
757
696
|
if (anyOfInit && import_ts_morph5.Node.isArrayLiteralExpression(anyOfInit)) {
|
|
758
|
-
anyOfInit.addElement(`'${
|
|
697
|
+
anyOfInit.addElement(`'${VALIDATED_FLAG_VALUE}'`);
|
|
759
698
|
}
|
|
760
699
|
} else {
|
|
761
700
|
flagsInit.addPropertyAssignment({
|
|
762
701
|
name: ANY_OF_PROPERTY_NAME,
|
|
763
|
-
initializer: `['${
|
|
702
|
+
initializer: `['${VALIDATED_FLAG_VALUE}']`
|
|
764
703
|
});
|
|
765
704
|
}
|
|
766
705
|
}
|
|
767
706
|
} else {
|
|
768
707
|
clause.addPropertyAssignment({
|
|
769
|
-
name:
|
|
770
|
-
initializer: `{ ${ANY_OF_PROPERTY_NAME}: ['${
|
|
708
|
+
name: FLAGS_PROPERTY_NAME,
|
|
709
|
+
initializer: `{ ${ANY_OF_PROPERTY_NAME}: ['${VALIDATED_FLAG_VALUE}'] }`
|
|
771
710
|
});
|
|
772
711
|
}
|
|
773
712
|
}
|
|
@@ -933,26 +872,23 @@ var DEFINE_CONFIG_NAME4 = "defineConfig";
|
|
|
933
872
|
var DEFINE_WORKQUEUES_NAME2 = "defineWorkqueues";
|
|
934
873
|
var ACTIONS_PROPERTY_NAME4 = "actions";
|
|
935
874
|
var ACTION_PROPERTY_NAME = "action";
|
|
936
|
-
var
|
|
875
|
+
var FLAGS_PROPERTY_NAME2 = "flags";
|
|
937
876
|
var QUERY_PROPERTY_NAME2 = "query";
|
|
938
877
|
var TYPE_PROPERTY_NAME6 = "type";
|
|
939
|
-
var ID_PROPERTY_NAME2 = "id";
|
|
940
878
|
var CLAUSES_PROPERTY_NAME2 = "clauses";
|
|
941
879
|
var ANY_OF_PROPERTY_NAME2 = "anyOf";
|
|
942
880
|
var FLAG_ID = "pending-first-certificate-issuance";
|
|
943
881
|
var REGISTER_TYPE = "REGISTER";
|
|
944
882
|
var PRINT_CERTIFICATE_TYPE = "PRINT_CERTIFICATE";
|
|
945
|
-
|
|
946
|
-
return `{
|
|
883
|
+
var FLAG_DEFINITION_INITIALIZER = `{
|
|
947
884
|
id: '${FLAG_ID}',
|
|
948
885
|
label: {
|
|
949
|
-
id: 'event
|
|
886
|
+
id: 'event.birth.flag.${FLAG_ID}',
|
|
950
887
|
defaultMessage: 'Pending first certificate issuance',
|
|
951
888
|
description: 'Flag label for first certificate issuance'
|
|
952
889
|
},
|
|
953
890
|
requiresAction: true
|
|
954
891
|
}`;
|
|
955
|
-
}
|
|
956
892
|
function isActionOfType(obj, typeName) {
|
|
957
893
|
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME6);
|
|
958
894
|
if (!typeProperty || !import_ts_morph6.Node.isPropertyAssignment(typeProperty)) return false;
|
|
@@ -966,20 +902,18 @@ function isActionOfType(obj, typeName) {
|
|
|
966
902
|
}
|
|
967
903
|
return false;
|
|
968
904
|
}
|
|
969
|
-
function
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
return initializer.getLiteralValue().toLowerCase();
|
|
977
|
-
}
|
|
978
|
-
if (import_ts_morph6.Node.isPropertyAccessExpression(initializer)) {
|
|
979
|
-
return initializer.getName().toLowerCase();
|
|
980
|
-
}
|
|
905
|
+
function isBirthConfig(configArg) {
|
|
906
|
+
const typeProperty = configArg.getProperty(TYPE_PROPERTY_NAME6);
|
|
907
|
+
if (!typeProperty || !import_ts_morph6.Node.isPropertyAssignment(typeProperty)) return false;
|
|
908
|
+
const initializer = typeProperty.getInitializer();
|
|
909
|
+
if (!initializer) return false;
|
|
910
|
+
if (import_ts_morph6.Node.isStringLiteral(initializer)) {
|
|
911
|
+
return initializer.getLiteralValue().toLowerCase() === "birth";
|
|
981
912
|
}
|
|
982
|
-
|
|
913
|
+
if (import_ts_morph6.Node.isPropertyAccessExpression(initializer)) {
|
|
914
|
+
return initializer.getName().toLowerCase() === "birth";
|
|
915
|
+
}
|
|
916
|
+
return false;
|
|
983
917
|
}
|
|
984
918
|
function hasElementWithId(array3, id) {
|
|
985
919
|
for (const el of array3.getElements()) {
|
|
@@ -993,28 +927,27 @@ function hasElementWithId(array3, id) {
|
|
|
993
927
|
}
|
|
994
928
|
return false;
|
|
995
929
|
}
|
|
996
|
-
function ensureTopLevelFlagDefinition(configArg
|
|
997
|
-
const
|
|
998
|
-
const flagsProp = configArg.getProperty(FLAGS_PROPERTY_NAME3);
|
|
930
|
+
function ensureTopLevelFlagDefinition(configArg) {
|
|
931
|
+
const flagsProp = configArg.getProperty(FLAGS_PROPERTY_NAME2);
|
|
999
932
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
1000
933
|
const flagsInit = flagsProp.getInitializer();
|
|
1001
934
|
if (flagsInit && import_ts_morph6.Node.isArrayLiteralExpression(flagsInit)) {
|
|
1002
935
|
if (hasElementWithId(flagsInit, FLAG_ID)) return false;
|
|
1003
|
-
flagsInit.addElement(
|
|
936
|
+
flagsInit.addElement(FLAG_DEFINITION_INITIALIZER);
|
|
1004
937
|
return true;
|
|
1005
938
|
}
|
|
1006
939
|
return false;
|
|
1007
940
|
}
|
|
1008
941
|
configArg.addPropertyAssignment({
|
|
1009
|
-
name:
|
|
942
|
+
name: FLAGS_PROPERTY_NAME2,
|
|
1010
943
|
initializer: `[
|
|
1011
|
-
${
|
|
944
|
+
${FLAG_DEFINITION_INITIALIZER}
|
|
1012
945
|
]`
|
|
1013
946
|
});
|
|
1014
947
|
return true;
|
|
1015
948
|
}
|
|
1016
949
|
function ensureActionOperationFlag(action, operation) {
|
|
1017
|
-
const flagsProp = action.getProperty(
|
|
950
|
+
const flagsProp = action.getProperty(FLAGS_PROPERTY_NAME2);
|
|
1018
951
|
const entry = `{ id: '${FLAG_ID}', operation: '${operation}' }`;
|
|
1019
952
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
1020
953
|
const flagsInit = flagsProp.getInitializer();
|
|
@@ -1026,18 +959,16 @@ function ensureActionOperationFlag(action, operation) {
|
|
|
1026
959
|
return false;
|
|
1027
960
|
}
|
|
1028
961
|
action.addPropertyAssignment({
|
|
1029
|
-
name:
|
|
962
|
+
name: FLAGS_PROPERTY_NAME2,
|
|
1030
963
|
initializer: `[${entry}]`
|
|
1031
964
|
});
|
|
1032
965
|
return true;
|
|
1033
966
|
}
|
|
1034
|
-
function
|
|
967
|
+
function processBirthConfig(configArg, relPath) {
|
|
1035
968
|
let changes = 0;
|
|
1036
|
-
if (ensureTopLevelFlagDefinition(configArg
|
|
969
|
+
if (ensureTopLevelFlagDefinition(configArg)) {
|
|
1037
970
|
changes++;
|
|
1038
|
-
console.log(
|
|
1039
|
-
` [${relPath}] (${eventType}) Added '${FLAG_ID}' to top-level flags`
|
|
1040
|
-
);
|
|
971
|
+
console.log(` [${relPath}] Added '${FLAG_ID}' to top-level flags`);
|
|
1041
972
|
}
|
|
1042
973
|
const actionsProp = configArg.getProperty(ACTIONS_PROPERTY_NAME4);
|
|
1043
974
|
if (!actionsProp || !import_ts_morph6.Node.isPropertyAssignment(actionsProp)) return changes;
|
|
@@ -1051,7 +982,7 @@ function processConfig(configArg, eventType, relPath) {
|
|
|
1051
982
|
if (ensureActionOperationFlag(element, "add")) {
|
|
1052
983
|
changes++;
|
|
1053
984
|
console.log(
|
|
1054
|
-
` [${relPath}]
|
|
985
|
+
` [${relPath}] Added '${FLAG_ID}' add-flag to REGISTER action`
|
|
1055
986
|
);
|
|
1056
987
|
}
|
|
1057
988
|
}
|
|
@@ -1059,7 +990,7 @@ function processConfig(configArg, eventType, relPath) {
|
|
|
1059
990
|
if (ensureActionOperationFlag(element, "remove")) {
|
|
1060
991
|
changes++;
|
|
1061
992
|
console.log(
|
|
1062
|
-
` [${relPath}]
|
|
993
|
+
` [${relPath}] Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`
|
|
1063
994
|
);
|
|
1064
995
|
}
|
|
1065
996
|
}
|
|
@@ -1088,7 +1019,7 @@ function hasPrintCertificateAction(workqueue) {
|
|
|
1088
1019
|
return false;
|
|
1089
1020
|
}
|
|
1090
1021
|
function addFlagToQueryClause(clause) {
|
|
1091
|
-
const flagsProp = clause.getProperty(
|
|
1022
|
+
const flagsProp = clause.getProperty(FLAGS_PROPERTY_NAME2);
|
|
1092
1023
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
1093
1024
|
const flagsInit = flagsProp.getInitializer();
|
|
1094
1025
|
if (flagsInit && import_ts_morph6.Node.isObjectLiteralExpression(flagsInit)) {
|
|
@@ -1113,7 +1044,7 @@ function addFlagToQueryClause(clause) {
|
|
|
1113
1044
|
}
|
|
1114
1045
|
} else {
|
|
1115
1046
|
clause.addPropertyAssignment({
|
|
1116
|
-
name:
|
|
1047
|
+
name: FLAGS_PROPERTY_NAME2,
|
|
1117
1048
|
initializer: `{ ${ANY_OF_PROPERTY_NAME2}: ['${FLAG_ID}'] }`
|
|
1118
1049
|
});
|
|
1119
1050
|
return true;
|
|
@@ -1157,9 +1088,8 @@ function processFile6(filePath, project) {
|
|
|
1157
1088
|
if (args.length === 0) continue;
|
|
1158
1089
|
const configArg = args[0];
|
|
1159
1090
|
if (!import_ts_morph6.Node.isObjectLiteralExpression(configArg)) continue;
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
totalChanges += processConfig(configArg, eventType, relPath);
|
|
1091
|
+
if (!isBirthConfig(configArg)) continue;
|
|
1092
|
+
totalChanges += processBirthConfig(configArg, relPath);
|
|
1163
1093
|
}
|
|
1164
1094
|
if (calleeName === DEFINE_WORKQUEUES_NAME2) {
|
|
1165
1095
|
const args = call.getArguments();
|
|
@@ -1188,7 +1118,7 @@ function processFile6(filePath, project) {
|
|
|
1188
1118
|
async function main6() {
|
|
1189
1119
|
const srcDir = import_path6.default.join(process.cwd(), "src");
|
|
1190
1120
|
console.log(
|
|
1191
|
-
`Scanning for defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}
|
|
1121
|
+
`Scanning for birth defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}
|
|
1192
1122
|
`
|
|
1193
1123
|
);
|
|
1194
1124
|
const project = new import_ts_morph6.Project({
|
|
@@ -1213,7 +1143,7 @@ async function main6() {
|
|
|
1213
1143
|
}
|
|
1214
1144
|
if (modifiedFiles.length === 0) {
|
|
1215
1145
|
console.log(
|
|
1216
|
-
"No
|
|
1146
|
+
"No birth configs or PRINT_CERTIFICATE workqueues found. Nothing to do."
|
|
1217
1147
|
);
|
|
1218
1148
|
return;
|
|
1219
1149
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make-built-in-validate-actions-custom.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/make-built-in-validate-actions-custom.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"make-built-in-validate-actions-custom.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/make-built-in-validate-actions-custom.ts"],"names":[],"mappings":"AA2WA,iBAAe,IAAI,kBAiDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -41,10 +41,6 @@ exports.main = main;
|
|
|
41
41
|
* - Removes the `deduplication` property from those objects
|
|
42
42
|
* - Replaces `review: { fields: <value> }` with `form: <value>`, or
|
|
43
43
|
* `review: <expr>` with `form: <expr>.fields` when the value is not an inline object
|
|
44
|
-
* - Adds the top-level `validated` flag definition and `{ id: 'validated',
|
|
45
|
-
* operation: 'add' }` to the (now custom) validate action
|
|
46
|
-
* - Adds `{ id: 'validated', operation: 'remove' }` to every `REGISTER` action
|
|
47
|
-
* in the same config, closing the flag's lifecycle when registration happens
|
|
48
44
|
* - Saves the modified files in-place
|
|
49
45
|
*/
|
|
50
46
|
const ts_morph_1 = require("ts-morph");
|
|
@@ -78,8 +74,6 @@ function ensureImports(sourceFile) {
|
|
|
78
74
|
const DEFINE_CONFIG_NAME = 'defineConfig';
|
|
79
75
|
const ACTIONS_PROPERTY_NAME = 'actions';
|
|
80
76
|
const TYPE_PROPERTY_NAME = 'type';
|
|
81
|
-
const ID_PROPERTY_NAME = 'id';
|
|
82
|
-
const FLAGS_PROPERTY_NAME = 'flags';
|
|
83
77
|
const CUSTOM_ACTION_TYPE_PROPERTY_NAME = 'customActionType';
|
|
84
78
|
const AUDIT_HISTORY_LABEL_PROPERTY_NAME = 'auditHistoryLabel';
|
|
85
79
|
const DEDUPLICATION_PROPERTY_NAME = 'deduplication';
|
|
@@ -89,12 +83,9 @@ const FORM_PROPERTY_NAME = 'form';
|
|
|
89
83
|
const ACTION_TYPE_ENUM_NAME = 'ActionType';
|
|
90
84
|
const VALIDATE_MEMBER_NAME = 'VALIDATE';
|
|
91
85
|
const CUSTOM_MEMBER_NAME = 'CUSTOM';
|
|
92
|
-
const REGISTER_MEMBER_NAME = 'REGISTER';
|
|
93
86
|
const VALIDATE_STRING_LITERAL = 'VALIDATE';
|
|
94
87
|
const CUSTOM_STRING_LITERAL = 'CUSTOM';
|
|
95
|
-
const REGISTER_STRING_LITERAL = 'REGISTER';
|
|
96
88
|
const VALIDATE_DECLARATION_VALUE = 'VALIDATE_DECLARATION';
|
|
97
|
-
const VALIDATED_FLAG_VALUE = 'validated';
|
|
98
89
|
function isValidateType(typeInitializer) {
|
|
99
90
|
// Matches: ActionType.VALIDATE
|
|
100
91
|
if (typeInitializer.getKind() === ts_morph_1.SyntaxKind.PropertyAccessExpression) {
|
|
@@ -239,72 +230,6 @@ function transformValidateActionToCustom(obj, eventType) {
|
|
|
239
230
|
}
|
|
240
231
|
return true;
|
|
241
232
|
}
|
|
242
|
-
function isRegisterAction(action) {
|
|
243
|
-
const typeProperty = action.getProperty(TYPE_PROPERTY_NAME);
|
|
244
|
-
if (!typeProperty || !ts_morph_1.Node.isPropertyAssignment(typeProperty))
|
|
245
|
-
return false;
|
|
246
|
-
const typeInit = typeProperty.getInitializer();
|
|
247
|
-
if (!typeInit)
|
|
248
|
-
return false;
|
|
249
|
-
// Matches: ActionType.REGISTER
|
|
250
|
-
if (ts_morph_1.Node.isPropertyAccessExpression(typeInit)) {
|
|
251
|
-
const enumExpr = typeInit.getExpression();
|
|
252
|
-
return (ts_morph_1.Node.isIdentifier(enumExpr) &&
|
|
253
|
-
enumExpr.getText() === ACTION_TYPE_ENUM_NAME &&
|
|
254
|
-
typeInit.getName() === REGISTER_MEMBER_NAME);
|
|
255
|
-
}
|
|
256
|
-
// Matches: "REGISTER"
|
|
257
|
-
if (ts_morph_1.Node.isStringLiteral(typeInit)) {
|
|
258
|
-
return typeInit.getLiteralValue() === REGISTER_STRING_LITERAL;
|
|
259
|
-
}
|
|
260
|
-
return false;
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Returns true if an array literal contains an object literal with `id: <id>`.
|
|
264
|
-
*/
|
|
265
|
-
function arrayHasElementWithId(array, id) {
|
|
266
|
-
for (const el of array.getElements()) {
|
|
267
|
-
if (!ts_morph_1.Node.isObjectLiteralExpression(el))
|
|
268
|
-
continue;
|
|
269
|
-
const idProp = el.getProperty(ID_PROPERTY_NAME);
|
|
270
|
-
if (!idProp || !ts_morph_1.Node.isPropertyAssignment(idProp))
|
|
271
|
-
continue;
|
|
272
|
-
const idInit = idProp.getInitializer();
|
|
273
|
-
if (idInit &&
|
|
274
|
-
ts_morph_1.Node.isStringLiteral(idInit) &&
|
|
275
|
-
idInit.getLiteralValue() === id) {
|
|
276
|
-
return true;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
return false;
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Adds `{ id: 'validated', operation: 'remove' }` to a REGISTER action's
|
|
283
|
-
* `flags` array. Skips if any `validated` flag entry is already present —
|
|
284
|
-
* this keeps the codemod idempotent and avoids stomping on an intentional
|
|
285
|
-
* `add` op a maintainer may have authored manually.
|
|
286
|
-
*
|
|
287
|
-
* Returns true if a change was made.
|
|
288
|
-
*/
|
|
289
|
-
function ensureRegisterRemovesValidatedFlag(action) {
|
|
290
|
-
const entry = `{ id: '${VALIDATED_FLAG_VALUE}', operation: 'remove' }`;
|
|
291
|
-
const flagsProp = action.getProperty(FLAGS_PROPERTY_NAME);
|
|
292
|
-
if (flagsProp && ts_morph_1.Node.isPropertyAssignment(flagsProp)) {
|
|
293
|
-
const flagsInit = flagsProp.getInitializer();
|
|
294
|
-
if (flagsInit && ts_morph_1.Node.isArrayLiteralExpression(flagsInit)) {
|
|
295
|
-
if (arrayHasElementWithId(flagsInit, VALIDATED_FLAG_VALUE))
|
|
296
|
-
return false;
|
|
297
|
-
flagsInit.addElement(entry);
|
|
298
|
-
return true;
|
|
299
|
-
}
|
|
300
|
-
return false;
|
|
301
|
-
}
|
|
302
|
-
action.addPropertyAssignment({
|
|
303
|
-
name: FLAGS_PROPERTY_NAME,
|
|
304
|
-
initializer: `[${entry}]`
|
|
305
|
-
});
|
|
306
|
-
return true;
|
|
307
|
-
}
|
|
308
233
|
function processFile(filePath, project) {
|
|
309
234
|
const sourceFile = project.getSourceFile(filePath);
|
|
310
235
|
if (!sourceFile)
|
|
@@ -372,20 +297,6 @@ function processFile(filePath, project) {
|
|
|
372
297
|
});
|
|
373
298
|
console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Added top-level 'flags' array to defineConfig`);
|
|
374
299
|
}
|
|
375
|
-
// Close the `validated` flag's lifecycle: when the validate action adds the
|
|
376
|
-
// flag, the matching REGISTER action(s) must remove it on registration.
|
|
377
|
-
if (configHadValidateAction) {
|
|
378
|
-
for (const element of actionsInitializer.getElements()) {
|
|
379
|
-
if (!ts_morph_1.Node.isObjectLiteralExpression(element))
|
|
380
|
-
continue;
|
|
381
|
-
if (!isRegisterAction(element))
|
|
382
|
-
continue;
|
|
383
|
-
if (ensureRegisterRemovesValidatedFlag(element)) {
|
|
384
|
-
transformedCount++;
|
|
385
|
-
console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Added '${VALIDATED_FLAG_VALUE}' remove-flag to REGISTER action`);
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
300
|
if (fileNeedsImports) {
|
|
390
301
|
ensureImports(sourceFile);
|
|
391
302
|
}
|
|
@@ -427,6 +338,6 @@ function main() {
|
|
|
427
338
|
yield sourceFile.save();
|
|
428
339
|
console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
|
|
429
340
|
}
|
|
430
|
-
console.log(`\nDone.
|
|
341
|
+
console.log(`\nDone. Transformed ${totalTransformed} VALIDATE action(s) to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'.`);
|
|
431
342
|
});
|
|
432
343
|
}
|
|
Binary file
|
package/package.json
CHANGED
|
Binary file
|