@opencrvs/toolkit 1.9.14 → 2.0.0-rc.013c085
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build.sh +13 -0
- package/create-countryconfig/index.js +103 -0
- package/create-countryconfig/package.json +21 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/application-config/index.d.ts +2 -0
- package/dist/application-config/index.d.ts.map +1 -0
- package/dist/application-config/index.js +2304 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +5238 -0
- package/dist/commons/api/router.d.ts +5630 -3673
- package/dist/commons/application-config/index.d.ts +97 -0
- package/dist/commons/conditionals/conditionals.d.ts +33 -3
- package/dist/commons/conditionals/validate.d.ts +20 -1
- package/dist/commons/events/ActionConfig.d.ts +415 -1555
- package/dist/commons/events/ActionDocument.d.ts +894 -1941
- package/dist/commons/events/ActionInput.d.ts +326 -1212
- package/dist/commons/events/ActionType.d.ts +91 -11
- package/dist/commons/events/AdvancedSearchConfig.d.ts +294 -1496
- package/dist/commons/events/AuditLog.d.ts +407 -0
- package/dist/commons/events/CompositeFieldValue.d.ts +30 -190
- package/dist/commons/events/Conditional.d.ts +26 -38
- package/dist/commons/events/Constants.d.ts +1 -1
- package/dist/commons/events/CountryConfigQueryInput.d.ts +1592 -4471
- package/dist/commons/events/DeduplicationConfig.d.ts +15 -171
- package/dist/commons/events/Draft.d.ts +72 -111
- package/dist/commons/events/DynamicFieldValue.d.ts +12 -78
- package/dist/commons/events/EventConfig.d.ts +37 -2427
- package/dist/commons/events/EventConfigInput.d.ts +0 -3
- package/dist/commons/events/EventDocument.d.ts +357 -1366
- package/dist/commons/events/EventIndex.d.ts +211 -1012
- package/dist/commons/events/EventInput.d.ts +3 -8
- package/dist/commons/events/EventMetadata.d.ts +129 -363
- package/dist/commons/events/FieldConfig.d.ts +3147 -14211
- package/dist/commons/events/FieldType.d.ts +26 -4
- package/dist/commons/events/FieldTypeMapping.d.ts +314 -906
- package/dist/commons/events/FieldValue.d.ts +154 -526
- package/dist/commons/events/FileUtils.d.ts +2 -2
- package/dist/commons/events/Flag.d.ts +67 -0
- package/dist/commons/events/FormConfig.d.ts +54 -721
- package/dist/commons/events/PageConfig.d.ts +58 -320
- package/dist/commons/events/PlainDate.d.ts +1 -1
- package/dist/commons/events/SummaryConfig.d.ts +14 -161
- package/dist/commons/events/TemplateConfig.d.ts +2 -3
- package/dist/commons/events/TranslationConfig.d.ts +2 -2
- package/dist/commons/events/WorkqueueColumnConfig.d.ts +74 -37
- package/dist/commons/events/WorkqueueConfig.d.ts +2232 -7577
- package/dist/commons/events/deduplication.d.ts +3 -3
- package/dist/commons/events/defineConfig.d.ts +2 -248
- package/dist/commons/events/eventConfigValidation.d.ts +8 -0
- package/dist/commons/events/index.d.ts +5 -0
- package/dist/commons/events/locations.d.ts +93 -19
- package/dist/commons/events/mocks.test.utils.d.ts +19 -0
- package/dist/commons/events/scopes.d.ts +56 -32
- package/dist/commons/events/state/availableActions.d.ts +7 -2
- package/dist/commons/events/state/flags.d.ts +37 -3
- package/dist/commons/events/state/index.d.ts +29 -30
- package/dist/commons/events/state/utils.d.ts +191 -172
- package/dist/commons/events/test.utils.d.ts +52 -11
- package/dist/commons/events/transactions.d.ts +1 -1
- package/dist/commons/events/utils.d.ts +383 -273
- package/dist/commons/notification/UserNotifications.d.ts +76 -637
- package/dist/conditionals/index.d.ts.map +1 -1
- package/dist/conditionals/index.js +338 -14
- package/dist/events/deduplication.d.ts +3 -3
- package/dist/events/index.js +3680 -2227
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts +3 -0
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -0
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +429 -0
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +3 -0
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +1 -0
- package/dist/migrations/v2.0/add-resend-invite-notification.js +373 -0
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts +22 -0
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -0
- package/dist/migrations/v2.0/checkout-upstream-files.js +146 -0
- package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts +2 -0
- package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -0
- package/dist/migrations/v2.0/convert-config-files-to-ts.js +828 -0
- package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +3 -0
- package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -0
- package/dist/migrations/v2.0/convert-paragraph-to-heading.js +158 -0
- package/dist/migrations/v2.0/create-events-index.d.ts +3 -0
- package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -0
- package/dist/migrations/v2.0/create-events-index.js +325 -0
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +11 -0
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -0
- package/dist/migrations/v2.0/delete-infrastructure-directory.js +123 -0
- package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts +3 -0
- package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts.map +1 -0
- package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.js +110 -0
- package/dist/migrations/v2.0/index.d.ts +13 -0
- package/dist/migrations/v2.0/index.d.ts.map +1 -0
- package/dist/migrations/v2.0/index.js +5148 -0
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +3 -0
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -0
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +432 -0
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +13 -0
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -0
- package/dist/migrations/v2.0/merge-infrastructure-directory.js +222 -0
- package/dist/migrations/v2.0/migrate-application-config-url.d.ts +3 -0
- package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +1 -0
- package/dist/migrations/v2.0/migrate-application-config-url.js +342 -0
- package/dist/migrations/v2.0/migrate-scopes.d.ts +3 -0
- package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -0
- package/dist/migrations/v2.0/migrate-scopes.js +305 -0
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +3 -0
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -0
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +267 -0
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +3 -0
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -0
- package/dist/migrations/v2.0/migrate-workqueue-configs.js +317 -0
- package/dist/migrations/v2.0/remove-delete-actions.d.ts +3 -0
- package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-delete-actions.js +156 -0
- package/dist/migrations/v2.0/remove-demo-scope.d.ts +3 -0
- package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-demo-scope.js +74 -0
- package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +3 -0
- package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-deprecated-imports.js +96 -0
- package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +3 -0
- package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-fhir-url-helpers.js +163 -0
- package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +3 -0
- package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-hearth-migrations.js +77 -0
- package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +3 -0
- package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-old-statistics-service.js +356 -0
- package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +3 -0
- package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-pending-certification-flag.js +109 -0
- package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +3 -0
- package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-review-from-register-action.js +163 -0
- package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +3 -0
- package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-unused-environment-variables.js +186 -0
- package/dist/migrations/v2.0/rename-api-paths.d.ts +3 -0
- package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -0
- package/dist/migrations/v2.0/rename-api-paths.js +187 -0
- package/dist/migrations/v2.0/rename-location-parent-id.d.ts +3 -0
- package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -0
- package/dist/migrations/v2.0/rename-location-parent-id.js +180 -0
- package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +3 -0
- package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -0
- package/dist/migrations/v2.0/simplify-analytics-precalculations.js +195 -0
- package/dist/migrations/v2.0/update-package-json.d.ts +3 -0
- package/dist/migrations/v2.0/update-package-json.d.ts.map +1 -0
- package/dist/migrations/v2.0/update-package-json.js +105 -0
- package/dist/notification/index.d.ts.map +1 -1
- package/dist/notification/index.js +2727 -1848
- package/dist/scopes/index.d.ts +716 -352
- package/dist/scopes/index.d.ts.map +1 -1
- package/dist/scopes/index.js +376 -299
- package/opencrvs-toolkit-2.0.0-rc.013c085.tgz +0 -0
- package/package.json +14 -4
- package/tsconfig.json +12 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/commons/events/CreatedAtLocation.d.ts +0 -2
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
4
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
5
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
6
|
+
*
|
|
7
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
8
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
9
|
+
*
|
|
10
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
11
|
+
*/
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.main = main;
|
|
26
|
+
/**
|
|
27
|
+
* Codemod: Remove `InherentFlags.PENDING_CERTIFICATION` from any array literal.
|
|
28
|
+
*
|
|
29
|
+
* Usage:
|
|
30
|
+
* ts-node -r tsconfig-paths/register src/migrations/v2.0/remove-pending-certification-flag.ts
|
|
31
|
+
*
|
|
32
|
+
* What it does:
|
|
33
|
+
* - Scans all TypeScript files under `src/`
|
|
34
|
+
* - Finds every array literal in every file
|
|
35
|
+
* - Removes any element that is the property access expression
|
|
36
|
+
* `InherentFlags.PENDING_CERTIFICATION`
|
|
37
|
+
* - Saves the modified files in-place
|
|
38
|
+
*/
|
|
39
|
+
const ts_morph_1 = require("ts-morph");
|
|
40
|
+
const path_1 = __importDefault(require("path"));
|
|
41
|
+
const INHERENT_FLAGS_ENUM_NAME = 'InherentFlags';
|
|
42
|
+
const PENDING_CERTIFICATION_MEMBER = 'PENDING_CERTIFICATION';
|
|
43
|
+
function isPendingCertificationFlag(node) {
|
|
44
|
+
if (!ts_morph_1.Node.isPropertyAccessExpression(node))
|
|
45
|
+
return false;
|
|
46
|
+
const obj = node.getExpression();
|
|
47
|
+
const member = node.getName();
|
|
48
|
+
return (ts_morph_1.Node.isIdentifier(obj) &&
|
|
49
|
+
obj.getText() === INHERENT_FLAGS_ENUM_NAME &&
|
|
50
|
+
member === PENDING_CERTIFICATION_MEMBER);
|
|
51
|
+
}
|
|
52
|
+
function processFile(filePath, project) {
|
|
53
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
54
|
+
if (!sourceFile)
|
|
55
|
+
return 0;
|
|
56
|
+
let removedCount = 0;
|
|
57
|
+
const arrayLiterals = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.ArrayLiteralExpression);
|
|
58
|
+
for (const array of arrayLiterals) {
|
|
59
|
+
// Collect indices in reverse order so removal doesn't shift remaining indices
|
|
60
|
+
const indicesToRemove = [];
|
|
61
|
+
array.getElements().forEach((element, index) => {
|
|
62
|
+
if (isPendingCertificationFlag(element)) {
|
|
63
|
+
indicesToRemove.push(index);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
for (const index of indicesToRemove.reverse()) {
|
|
67
|
+
array.removeElement(index);
|
|
68
|
+
removedCount++;
|
|
69
|
+
console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Removed InherentFlags.PENDING_CERTIFICATION from array`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return removedCount;
|
|
73
|
+
}
|
|
74
|
+
function main() {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
const srcDir = path_1.default.join(process.cwd(), 'src');
|
|
77
|
+
console.log(`Scanning for InherentFlags.PENDING_CERTIFICATION array elements in: ${srcDir}\n`);
|
|
78
|
+
const project = new ts_morph_1.Project({
|
|
79
|
+
tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
|
|
80
|
+
skipAddingFilesFromTsConfig: false
|
|
81
|
+
});
|
|
82
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
83
|
+
const fp = sf.getFilePath();
|
|
84
|
+
return fp.includes('/src/') && !fp.includes('/node_modules/');
|
|
85
|
+
});
|
|
86
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
|
|
87
|
+
let totalRemoved = 0;
|
|
88
|
+
const modifiedFiles = [];
|
|
89
|
+
for (const sourceFile of sourceFiles) {
|
|
90
|
+
const filePath = sourceFile.getFilePath();
|
|
91
|
+
const removed = processFile(filePath, project);
|
|
92
|
+
if (removed > 0) {
|
|
93
|
+
totalRemoved += removed;
|
|
94
|
+
modifiedFiles.push(filePath);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (modifiedFiles.length === 0) {
|
|
98
|
+
console.log('No InherentFlags.PENDING_CERTIFICATION elements found in any array. Nothing to do.');
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
|
|
102
|
+
for (const filePath of modifiedFiles) {
|
|
103
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
104
|
+
yield sourceFile.save();
|
|
105
|
+
console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
|
|
106
|
+
}
|
|
107
|
+
console.log(`\nDone. Removed ${totalRemoved} InherentFlags.PENDING_CERTIFICATION element(s) from array(s).`);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-review-from-register-action.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/remove-review-from-register-action.ts"],"names":[],"mappings":"AAkJA,iBAAe,IAAI,kBAkDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
4
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
5
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
6
|
+
*
|
|
7
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
8
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
9
|
+
*
|
|
10
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
11
|
+
*/
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.main = main;
|
|
26
|
+
/**
|
|
27
|
+
* Codemod: Remove `review` property from `REGISTER` type actions inside `defineConfig` calls.
|
|
28
|
+
*
|
|
29
|
+
* Usage:
|
|
30
|
+
* ts-node -r tsconfig-paths/register src/remove-review-from-register-action.ts
|
|
31
|
+
*
|
|
32
|
+
* What it does:
|
|
33
|
+
* - Scans all TypeScript files under `src/`
|
|
34
|
+
* - Finds every `defineConfig({ ... })` call expression
|
|
35
|
+
* - Inside the `actions` array of that config, locates object literals
|
|
36
|
+
* whose `type` property resolves to `ActionType.REGISTER` or the string literal `"REGISTER"`
|
|
37
|
+
* - Removes the `review` property assignment from those objects
|
|
38
|
+
* - Saves the modified files in-place
|
|
39
|
+
*/
|
|
40
|
+
const ts_morph_1 = require("ts-morph");
|
|
41
|
+
const path_1 = __importDefault(require("path"));
|
|
42
|
+
const DEFINE_CONFIG_NAME = 'defineConfig';
|
|
43
|
+
const ACTIONS_PROPERTY_NAME = 'actions';
|
|
44
|
+
const TYPE_PROPERTY_NAME = 'type';
|
|
45
|
+
const REVIEW_PROPERTY_NAME = 'review';
|
|
46
|
+
const REGISTER_ENUM_NAME = 'ActionType';
|
|
47
|
+
const REGISTER_MEMBER_NAME = 'REGISTER';
|
|
48
|
+
const REGISTER_STRING_LITERAL = 'REGISTER';
|
|
49
|
+
function isRegisterType(typeInitializer) {
|
|
50
|
+
// Matches: ActionType.REGISTER
|
|
51
|
+
if (typeInitializer.getKind() === ts_morph_1.SyntaxKind.PropertyAccessExpression) {
|
|
52
|
+
const propAccess = typeInitializer.asKindOrThrow(ts_morph_1.SyntaxKind.PropertyAccessExpression);
|
|
53
|
+
const obj = propAccess.getExpression();
|
|
54
|
+
const member = propAccess.getName();
|
|
55
|
+
return (ts_morph_1.Node.isIdentifier(obj) &&
|
|
56
|
+
obj.getText() === REGISTER_ENUM_NAME &&
|
|
57
|
+
member === REGISTER_MEMBER_NAME);
|
|
58
|
+
}
|
|
59
|
+
// Matches: "REGISTER"
|
|
60
|
+
if (typeInitializer.getKind() === ts_morph_1.SyntaxKind.StringLiteral) {
|
|
61
|
+
return (typeInitializer
|
|
62
|
+
.asKindOrThrow(ts_morph_1.SyntaxKind.StringLiteral)
|
|
63
|
+
.getLiteralValue() === REGISTER_STRING_LITERAL);
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
function removeReviewFromRegisterActions(obj) {
|
|
68
|
+
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME);
|
|
69
|
+
if (!typeProperty || !ts_morph_1.Node.isPropertyAssignment(typeProperty)) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
const typeInitializer = typeProperty.getInitializer();
|
|
73
|
+
if (!typeInitializer || !isRegisterType(typeInitializer)) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
const reviewProperty = obj.getProperty(REVIEW_PROPERTY_NAME);
|
|
77
|
+
if (!reviewProperty) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
reviewProperty.remove();
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
function processFile(filePath, project) {
|
|
84
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
85
|
+
if (!sourceFile)
|
|
86
|
+
return 0;
|
|
87
|
+
let removedCount = 0;
|
|
88
|
+
// Find all call expressions named `defineConfig`
|
|
89
|
+
const callExpressions = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
90
|
+
for (const call of callExpressions) {
|
|
91
|
+
const expression = call.getExpression();
|
|
92
|
+
// Only interested in bare `defineConfig(...)` calls
|
|
93
|
+
if (!ts_morph_1.Node.isIdentifier(expression) ||
|
|
94
|
+
expression.getText() !== DEFINE_CONFIG_NAME) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
const args = call.getArguments();
|
|
98
|
+
if (args.length === 0)
|
|
99
|
+
continue;
|
|
100
|
+
// The first argument should be the config object literal
|
|
101
|
+
const configArg = args[0];
|
|
102
|
+
if (!ts_morph_1.Node.isObjectLiteralExpression(configArg))
|
|
103
|
+
continue;
|
|
104
|
+
// Find the `actions` property inside the config object
|
|
105
|
+
const actionsProperty = configArg.getProperty(ACTIONS_PROPERTY_NAME);
|
|
106
|
+
if (!actionsProperty || !ts_morph_1.Node.isPropertyAssignment(actionsProperty))
|
|
107
|
+
continue;
|
|
108
|
+
const actionsInitializer = actionsProperty.getInitializer();
|
|
109
|
+
if (!actionsInitializer ||
|
|
110
|
+
!ts_morph_1.Node.isArrayLiteralExpression(actionsInitializer))
|
|
111
|
+
continue;
|
|
112
|
+
// Iterate over every element in the `actions` array
|
|
113
|
+
for (const element of actionsInitializer.getElements()) {
|
|
114
|
+
if (!ts_morph_1.Node.isObjectLiteralExpression(element))
|
|
115
|
+
continue;
|
|
116
|
+
const wasRemoved = removeReviewFromRegisterActions(element);
|
|
117
|
+
if (wasRemoved) {
|
|
118
|
+
removedCount++;
|
|
119
|
+
console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Removed 'review' from REGISTER action`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return removedCount;
|
|
124
|
+
}
|
|
125
|
+
function main() {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
const srcDir = path_1.default.join(process.cwd(), 'src');
|
|
128
|
+
console.log(`Scanning for defineConfig calls in: ${srcDir}\n`);
|
|
129
|
+
const project = new ts_morph_1.Project({
|
|
130
|
+
tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
|
|
131
|
+
// Do not emit — we only manipulate source files
|
|
132
|
+
skipAddingFilesFromTsConfig: false
|
|
133
|
+
// addFilesFromTsConfig: true
|
|
134
|
+
});
|
|
135
|
+
// Restrict to source files only (exclude node_modules, build artefacts, etc.)
|
|
136
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
137
|
+
const fp = sf.getFilePath();
|
|
138
|
+
return fp.includes('/src/') && !fp.includes('/node_modules/');
|
|
139
|
+
});
|
|
140
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
|
|
141
|
+
let totalRemoved = 0;
|
|
142
|
+
const modifiedFiles = [];
|
|
143
|
+
for (const sourceFile of sourceFiles) {
|
|
144
|
+
const filePath = sourceFile.getFilePath();
|
|
145
|
+
const removed = processFile(filePath, project);
|
|
146
|
+
if (removed > 0) {
|
|
147
|
+
totalRemoved += removed;
|
|
148
|
+
modifiedFiles.push(filePath);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (modifiedFiles.length === 0) {
|
|
152
|
+
console.log("No 'review' properties found on REGISTER actions. Nothing to do.");
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
|
|
156
|
+
for (const filePath of modifiedFiles) {
|
|
157
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
158
|
+
yield sourceFile.save();
|
|
159
|
+
console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
|
|
160
|
+
}
|
|
161
|
+
console.log(`\nDone. Removed ${totalRemoved} 'review' property assignment(s) from REGISTER action(s).`);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-unused-environment-variables.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/remove-unused-environment-variables.ts"],"names":[],"mappings":"AAsJA,iBAAe,IAAI,kBAmDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
4
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
5
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
6
|
+
*
|
|
7
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
8
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
9
|
+
*
|
|
10
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
11
|
+
*/
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.main = main;
|
|
26
|
+
/**
|
|
27
|
+
* Codemod: Remove environment variables that are no longer consumed by
|
|
28
|
+
* country config code in v2.0.
|
|
29
|
+
*
|
|
30
|
+
* Targets:
|
|
31
|
+
* - APPLICATION_CONFIG_URL
|
|
32
|
+
* - FHIR_URL
|
|
33
|
+
* - CONFIRM_REGISTRATION_URL
|
|
34
|
+
*
|
|
35
|
+
* What it does:
|
|
36
|
+
* 1. In `src/environment.ts`, removes the matching properties from the
|
|
37
|
+
* `cleanEnv(process.env, { ... })` schema object.
|
|
38
|
+
* 2. In `src/constants.ts`, removes the matching top-level `const`
|
|
39
|
+
* declarations — by name OR by `env.<NAME>` reference (so that
|
|
40
|
+
* country forks that renamed the constant but still read the same env
|
|
41
|
+
* var are also cleaned up).
|
|
42
|
+
*
|
|
43
|
+
* Caveats:
|
|
44
|
+
* - Removing these constants may produce TypeScript errors at usage
|
|
45
|
+
* sites elsewhere in `src/` (e.g. files that imported `FHIR_URL` from
|
|
46
|
+
* `@countryconfig/constants`). Those usages are intentionally left
|
|
47
|
+
* for the developer to resolve, since the right replacement is
|
|
48
|
+
* country-specific.
|
|
49
|
+
* - The codemod is a no-op when the target files or properties don't
|
|
50
|
+
* exist (e.g. the country config has already removed them).
|
|
51
|
+
*/
|
|
52
|
+
const path_1 = __importDefault(require("path"));
|
|
53
|
+
const ts_morph_1 = require("ts-morph");
|
|
54
|
+
const UNUSED_ENV_VARS = new Set([
|
|
55
|
+
'APPLICATION_CONFIG_URL',
|
|
56
|
+
'FHIR_URL',
|
|
57
|
+
'CONFIRM_REGISTRATION_URL'
|
|
58
|
+
]);
|
|
59
|
+
const ENVIRONMENT_FILE_RELATIVE = 'src/environment.ts';
|
|
60
|
+
const CONSTANTS_FILE_RELATIVE = 'src/constants.ts';
|
|
61
|
+
/**
|
|
62
|
+
* Strip matching properties from the `cleanEnv(process.env, { ... })` call
|
|
63
|
+
* in `src/environment.ts`. Returns the names that were removed.
|
|
64
|
+
*/
|
|
65
|
+
function cleanEnvironmentFile(project, filePath) {
|
|
66
|
+
var _a;
|
|
67
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
68
|
+
if (!sourceFile)
|
|
69
|
+
return [];
|
|
70
|
+
const removed = [];
|
|
71
|
+
// IMPORTANT: never iterate all call expressions while mutating this object.
|
|
72
|
+
// Removing a property deletes nested `url(...)` nodes, and touching those
|
|
73
|
+
// forgotten nodes later causes `InvalidOperationError`.
|
|
74
|
+
const cleanEnvCall = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression).find((call) => {
|
|
75
|
+
const expr = call.getExpression();
|
|
76
|
+
return ts_morph_1.Node.isIdentifier(expr) && expr.getText() === 'cleanEnv';
|
|
77
|
+
});
|
|
78
|
+
if (!cleanEnvCall)
|
|
79
|
+
return removed;
|
|
80
|
+
const schemaArg = (_a = cleanEnvCall
|
|
81
|
+
.getArguments()[1]) === null || _a === void 0 ? void 0 : _a.asKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
|
|
82
|
+
if (!schemaArg)
|
|
83
|
+
return removed;
|
|
84
|
+
// Remove by explicit property-name lookup to avoid iterating over a live
|
|
85
|
+
// node list while mutating the object literal.
|
|
86
|
+
for (const name of UNUSED_ENV_VARS) {
|
|
87
|
+
const prop = schemaArg.getProperty(name);
|
|
88
|
+
if (!prop)
|
|
89
|
+
continue;
|
|
90
|
+
if (prop.isKind(ts_morph_1.SyntaxKind.PropertyAssignment) ||
|
|
91
|
+
prop.isKind(ts_morph_1.SyntaxKind.ShorthandPropertyAssignment)) {
|
|
92
|
+
prop.remove();
|
|
93
|
+
removed.push(name);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return removed;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Match `env.<NAME>` in an initializer (allowing surrounding parens / `as`
|
|
100
|
+
* casts that ts-morph emits in `getText()` as e.g. `(env.X as string)`).
|
|
101
|
+
* Returns the env var name if matched, or null.
|
|
102
|
+
*/
|
|
103
|
+
function extractEnvAccess(initText) {
|
|
104
|
+
if (!initText)
|
|
105
|
+
return null;
|
|
106
|
+
const match = /\benv\.([A-Z][A-Z0-9_]*)\b/.exec(initText);
|
|
107
|
+
return match ? match[1] : null;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Strip top-level `const` declarations in `src/constants.ts` whose name is
|
|
111
|
+
* in `UNUSED_ENV_VARS` OR whose initializer reads `env.<NAME>` for one of
|
|
112
|
+
* those names. Returns the declaration names that were removed.
|
|
113
|
+
*/
|
|
114
|
+
function cleanConstantsFile(project, filePath) {
|
|
115
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
116
|
+
if (!sourceFile)
|
|
117
|
+
return [];
|
|
118
|
+
const removed = [];
|
|
119
|
+
for (const stmt of [...sourceFile.getVariableStatements()]) {
|
|
120
|
+
const declarations = [...stmt.getDeclarations()];
|
|
121
|
+
const declarationsToRemove = declarations.filter((decl) => {
|
|
122
|
+
var _a;
|
|
123
|
+
const name = decl.getName();
|
|
124
|
+
const accessedEnvVar = extractEnvAccess((_a = decl.getInitializer()) === null || _a === void 0 ? void 0 : _a.getText());
|
|
125
|
+
return (UNUSED_ENV_VARS.has(name) ||
|
|
126
|
+
(accessedEnvVar !== null && UNUSED_ENV_VARS.has(accessedEnvVar)));
|
|
127
|
+
});
|
|
128
|
+
if (declarationsToRemove.length === 0)
|
|
129
|
+
continue;
|
|
130
|
+
// Resolve all names before mutating the AST; once a declaration or its
|
|
131
|
+
// parent statement is removed, ts-morph marks old nodes as forgotten.
|
|
132
|
+
const namesToRemove = declarationsToRemove.map((decl) => decl.getName());
|
|
133
|
+
removed.push(...namesToRemove);
|
|
134
|
+
if (declarationsToRemove.length === declarations.length) {
|
|
135
|
+
// All declarations in this statement are unused → drop the whole line
|
|
136
|
+
// (handles the dominant pattern: `export const X = env.X`).
|
|
137
|
+
stmt.remove();
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
// Mixed statement (e.g. `const A = env.A, B = somethingElse`) — keep
|
|
141
|
+
// the survivors by removing matching declarators in place.
|
|
142
|
+
for (const decl of declarationsToRemove) {
|
|
143
|
+
decl.remove();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return removed;
|
|
148
|
+
}
|
|
149
|
+
function main() {
|
|
150
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
+
const project = new ts_morph_1.Project({
|
|
152
|
+
tsConfigFilePath: path_1.default.resolve(process.cwd(), 'tsconfig.json'),
|
|
153
|
+
skipAddingFilesFromTsConfig: false
|
|
154
|
+
});
|
|
155
|
+
console.log(`Removing unused environment variable(s) (${[...UNUSED_ENV_VARS].join(', ')})...\n`);
|
|
156
|
+
const envFilePath = path_1.default.join(process.cwd(), ENVIRONMENT_FILE_RELATIVE);
|
|
157
|
+
const constsFilePath = path_1.default.join(process.cwd(), CONSTANTS_FILE_RELATIVE);
|
|
158
|
+
const envRemoved = cleanEnvironmentFile(project, envFilePath);
|
|
159
|
+
if (envRemoved.length > 0) {
|
|
160
|
+
yield project.getSourceFileOrThrow(envFilePath).save();
|
|
161
|
+
console.log(` [${ENVIRONMENT_FILE_RELATIVE}] Removed schema entr${envRemoved.length === 1 ? 'y' : 'ies'}: ${envRemoved.join(', ')}`);
|
|
162
|
+
}
|
|
163
|
+
else if (project.getSourceFile(envFilePath)) {
|
|
164
|
+
console.log(` [${ENVIRONMENT_FILE_RELATIVE}] No matching schema entries — nothing to remove.`);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
console.log(` [${ENVIRONMENT_FILE_RELATIVE}] File not found — skipping.`);
|
|
168
|
+
}
|
|
169
|
+
const constsRemoved = cleanConstantsFile(project, constsFilePath);
|
|
170
|
+
if (constsRemoved.length > 0) {
|
|
171
|
+
yield project.getSourceFileOrThrow(constsFilePath).save();
|
|
172
|
+
console.log(` [${CONSTANTS_FILE_RELATIVE}] Removed declaration(s): ${constsRemoved.join(', ')}`);
|
|
173
|
+
}
|
|
174
|
+
else if (project.getSourceFile(constsFilePath)) {
|
|
175
|
+
console.log(` [${CONSTANTS_FILE_RELATIVE}] No matching declarations — nothing to remove.`);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
console.log(` [${CONSTANTS_FILE_RELATIVE}] File not found — skipping.`);
|
|
179
|
+
}
|
|
180
|
+
if (envRemoved.length === 0 && constsRemoved.length === 0) {
|
|
181
|
+
console.log('\nNothing to do.');
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
console.log(`\nDone. NOTE: usages of these constants elsewhere in 'src/' may now produce TypeScript errors and need manual review.`);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rename-api-paths.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/rename-api-paths.ts"],"names":[],"mappings":"AAuJA,iBAAe,IAAI,kBAgDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
4
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
5
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
6
|
+
*
|
|
7
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
8
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
9
|
+
*
|
|
10
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
11
|
+
*/
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.main = main;
|
|
26
|
+
/**
|
|
27
|
+
* Codemod: Rename Hapi route `path` values inside route configuration objects.
|
|
28
|
+
*
|
|
29
|
+
* Usage:
|
|
30
|
+
* ts-node -r tsconfig-paths/register src/migrations/v2.0/rename-api-paths.ts
|
|
31
|
+
*
|
|
32
|
+
* What it does:
|
|
33
|
+
* - Scans all TypeScript files under `src/`
|
|
34
|
+
* - Finds every object literal that looks like a Hapi route config, i.e. one that
|
|
35
|
+
* has both a `method` property whose value is a recognised HTTP verb (or an array
|
|
36
|
+
* of them) and a `path` property whose value is a string literal
|
|
37
|
+
* - Applies every rename listed in PATH_RENAMES to the `path` value
|
|
38
|
+
* - Saves the modified files in-place
|
|
39
|
+
*
|
|
40
|
+
* Adding new renames:
|
|
41
|
+
* Add an entry to the PATH_RENAMES map below. Keys are the old path strings,
|
|
42
|
+
* values are the new path strings. Exact string matching is used — no wildcards.
|
|
43
|
+
*/
|
|
44
|
+
const ts_morph_1 = require("ts-morph");
|
|
45
|
+
const path_1 = __importDefault(require("path"));
|
|
46
|
+
// ─── Path rename table ────────────────────────────────────────────────────────
|
|
47
|
+
// Add new renames here as further API paths are changed between versions.
|
|
48
|
+
const PATH_RENAMES = {
|
|
49
|
+
'/events': '/config/events',
|
|
50
|
+
'/application-config': '/config/application',
|
|
51
|
+
'/workqueue': '/config/workqueues',
|
|
52
|
+
'/locations': '/config/locations',
|
|
53
|
+
'/users': '/config/users',
|
|
54
|
+
'/roles': '/config/roles'
|
|
55
|
+
};
|
|
56
|
+
// ─── Constants ────────────────────────────────────────────────────────────────
|
|
57
|
+
const METHOD_PROPERTY_NAME = 'method';
|
|
58
|
+
const PATH_PROPERTY_NAME = 'path';
|
|
59
|
+
const HTTP_VERBS = new Set([
|
|
60
|
+
'GET',
|
|
61
|
+
'POST',
|
|
62
|
+
'PUT',
|
|
63
|
+
'PATCH',
|
|
64
|
+
'DELETE',
|
|
65
|
+
'OPTIONS',
|
|
66
|
+
'HEAD',
|
|
67
|
+
'*'
|
|
68
|
+
]);
|
|
69
|
+
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
70
|
+
/**
|
|
71
|
+
* Returns true when the given object literal looks like a Hapi route config.
|
|
72
|
+
*
|
|
73
|
+
* A route config must have:
|
|
74
|
+
* - a `method` property whose value is either a recognised HTTP verb string
|
|
75
|
+
* literal, or an array literal whose elements are all recognised verb strings
|
|
76
|
+
* - a `path` property whose value is a string literal
|
|
77
|
+
*/
|
|
78
|
+
function isRouteConfig(obj) {
|
|
79
|
+
// ── method check ────────────────────────────────────────────────────────────
|
|
80
|
+
const methodProp = obj.getProperty(METHOD_PROPERTY_NAME);
|
|
81
|
+
if (!methodProp || !ts_morph_1.Node.isPropertyAssignment(methodProp))
|
|
82
|
+
return false;
|
|
83
|
+
const methodInit = methodProp.getInitializer();
|
|
84
|
+
if (!methodInit)
|
|
85
|
+
return false;
|
|
86
|
+
if (ts_morph_1.Node.isStringLiteral(methodInit)) {
|
|
87
|
+
if (!HTTP_VERBS.has(methodInit.getLiteralValue().toUpperCase()))
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
else if (ts_morph_1.Node.isArrayLiteralExpression(methodInit)) {
|
|
91
|
+
const allVerbs = methodInit
|
|
92
|
+
.getElements()
|
|
93
|
+
.every((el) => ts_morph_1.Node.isStringLiteral(el) &&
|
|
94
|
+
HTTP_VERBS.has(el.getLiteralValue().toUpperCase()));
|
|
95
|
+
if (!allVerbs)
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
// ── path check ──────────────────────────────────────────────────────────────
|
|
102
|
+
const pathProp = obj.getProperty(PATH_PROPERTY_NAME);
|
|
103
|
+
if (!pathProp || !ts_morph_1.Node.isPropertyAssignment(pathProp))
|
|
104
|
+
return false;
|
|
105
|
+
const pathInit = pathProp.getInitializer();
|
|
106
|
+
return !!pathInit && ts_morph_1.Node.isStringLiteral(pathInit);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Applies PATH_RENAMES to the `path` property of a confirmed route config object.
|
|
110
|
+
* Returns the new path string if a rename was applied, or null if no change was made.
|
|
111
|
+
*/
|
|
112
|
+
function renameRoutePath(obj) {
|
|
113
|
+
const pathProp = obj.getProperty(PATH_PROPERTY_NAME);
|
|
114
|
+
if (!pathProp || !ts_morph_1.Node.isPropertyAssignment(pathProp))
|
|
115
|
+
return null;
|
|
116
|
+
const pathInit = pathProp.getInitializer();
|
|
117
|
+
if (!pathInit || !ts_morph_1.Node.isStringLiteral(pathInit))
|
|
118
|
+
return null;
|
|
119
|
+
const oldPath = pathInit.getLiteralValue();
|
|
120
|
+
const newPath = PATH_RENAMES[oldPath];
|
|
121
|
+
if (!newPath)
|
|
122
|
+
return null;
|
|
123
|
+
pathInit.replaceWithText(`'${newPath}'`);
|
|
124
|
+
return newPath;
|
|
125
|
+
}
|
|
126
|
+
// ─── File processor ──────────────────────────────────────────────────────────
|
|
127
|
+
function processFile(filePath, project) {
|
|
128
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
129
|
+
if (!sourceFile)
|
|
130
|
+
return 0;
|
|
131
|
+
let renamedCount = 0;
|
|
132
|
+
const relPath = path_1.default.relative(process.cwd(), filePath);
|
|
133
|
+
// Collect candidates first to avoid iterating a mutating tree
|
|
134
|
+
const candidates = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
|
|
135
|
+
for (const obj of candidates) {
|
|
136
|
+
if (!isRouteConfig(obj))
|
|
137
|
+
continue;
|
|
138
|
+
const newPath = renameRoutePath(obj);
|
|
139
|
+
if (newPath) {
|
|
140
|
+
renamedCount++;
|
|
141
|
+
console.log(` [${relPath}] Renamed route path → '${newPath}'`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return renamedCount;
|
|
145
|
+
}
|
|
146
|
+
// ─── Entry point ─────────────────────────────────────────────────────────────
|
|
147
|
+
function main() {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
const srcDir = path_1.default.join(process.cwd(), 'src');
|
|
150
|
+
console.log(`Scanning for Hapi route configs in: ${srcDir}\n`);
|
|
151
|
+
console.log('Active path renames:');
|
|
152
|
+
for (const [from, to] of Object.entries(PATH_RENAMES)) {
|
|
153
|
+
console.log(` '${from}' → '${to}'`);
|
|
154
|
+
}
|
|
155
|
+
console.log();
|
|
156
|
+
const project = new ts_morph_1.Project({
|
|
157
|
+
tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
|
|
158
|
+
skipAddingFilesFromTsConfig: false
|
|
159
|
+
});
|
|
160
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
161
|
+
const fp = sf.getFilePath();
|
|
162
|
+
return fp.includes('/src/') && !fp.includes('/node_modules/');
|
|
163
|
+
});
|
|
164
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
|
|
165
|
+
let totalRenamed = 0;
|
|
166
|
+
const modifiedFiles = [];
|
|
167
|
+
for (const sourceFile of sourceFiles) {
|
|
168
|
+
const filePath = sourceFile.getFilePath();
|
|
169
|
+
const renamed = processFile(filePath, project);
|
|
170
|
+
if (renamed > 0) {
|
|
171
|
+
totalRenamed += renamed;
|
|
172
|
+
modifiedFiles.push(filePath);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (modifiedFiles.length === 0) {
|
|
176
|
+
console.log('No matching route paths found. Nothing to do.');
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
|
|
180
|
+
for (const filePath of modifiedFiles) {
|
|
181
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
182
|
+
yield sourceFile.save();
|
|
183
|
+
console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
|
|
184
|
+
}
|
|
185
|
+
console.log(`\nDone. Renamed ${totalRenamed} route path(s).`);
|
|
186
|
+
});
|
|
187
|
+
}
|