@opencrvs/toolkit 2.1.0-rc.12673aa → 2.1.0-rc.14fb6a5
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 +14 -4
- package/create-countryconfig/index.js +59 -30
- package/dist/application-config/index.js +26 -13
- package/dist/authentication/index.d.ts +8 -9
- package/dist/authentication/index.js +23 -8
- package/dist/cli.js +2268 -1385
- package/dist/commons/api/router.d.ts +252 -290
- package/dist/commons/application-config/index.d.ts +0 -2
- package/dist/commons/conditionals/conditionals.d.ts +6 -6
- package/dist/commons/conditionals/validate.d.ts +18 -3
- package/dist/commons/events/ActionConfig.d.ts +5 -14
- package/dist/commons/events/ActionDocument.d.ts +30 -4
- package/dist/commons/events/AdvancedSearchConfig.d.ts +24 -12
- package/dist/commons/events/AuditLog.d.ts +1 -0
- package/dist/commons/events/Draft.d.ts +1 -21
- package/dist/commons/events/EventDocument.d.ts +4 -4
- package/dist/commons/events/FieldConfig.d.ts +20 -10
- package/dist/commons/events/FieldTypeMapping.d.ts +10 -10
- package/dist/commons/events/FieldValue.d.ts +1 -0
- package/dist/commons/events/FormConfig.d.ts +6 -0
- package/dist/commons/events/PageConfig.d.ts +4 -0
- package/dist/commons/events/scopes.d.ts +21 -1
- package/dist/commons/events/test.utils.d.ts +53 -21
- package/dist/commons/events/utils.d.ts +26 -2
- package/dist/conditionals/index.js +21 -7
- package/dist/environment/index.d.ts.map +1 -1
- package/dist/environment/index.js +2 -1
- package/dist/environment/setup-environment.d.ts +1 -1
- package/dist/environment/setup-environment.d.ts.map +1 -1
- package/dist/environment/setup-environment.js +586 -569
- package/dist/environment/swarm-to-k8s.js +3 -4
- package/dist/events/index.js +282 -138
- package/dist/migrations/v2.1/add-recovery-link-notifications.js +4 -4
- package/dist/migrations/v2.1/add-translations.d.ts.map +1 -1
- package/dist/migrations/v2.1/add-translations.js +4 -68
- package/dist/migrations/v2.1/enable-telemetry.d.ts.map +1 -1
- package/dist/migrations/v2.1/enable-telemetry.js +30 -13
- package/dist/migrations/v2.1/index.d.ts.map +1 -1
- package/dist/migrations/v2.1/index.js +927 -33
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts +14 -0
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts.map +1 -0
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.js +348 -0
- package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts +2 -0
- package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts.map +1 -0
- package/dist/migrations/v2.1/remove-metabase-package-installs.js +161 -0
- package/dist/migrations/{v2.0/migrate-scopes.d.ts → v2.1/remove-sentry.d.ts} +1 -1
- package/dist/migrations/v2.1/remove-sentry.d.ts.map +1 -0
- package/dist/migrations/v2.1/remove-sentry.js +354 -0
- package/dist/migrations/{v2.0/rename-api-paths.d.ts → v2.1/rename-trigger-paths.d.ts} +1 -1
- package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +1 -0
- package/dist/migrations/{v2.0/rename-api-paths.js → v2.1/rename-trigger-paths.js} +69 -40
- package/dist/migrations/v2.1/template-files.d.ts +8 -0
- package/dist/migrations/v2.1/template-files.d.ts.map +1 -0
- package/dist/migrations/v2.1/template-files.js +49 -0
- package/dist/migrations/v2.1/upgrade-tilt.d.ts +8 -0
- package/dist/migrations/v2.1/upgrade-tilt.d.ts.map +1 -0
- package/dist/migrations/v2.1/upgrade-tilt.js +139 -0
- package/dist/notification/index.js +105 -61
- package/dist/scopes/index.d.ts +288 -5
- package/dist/scopes/index.js +22 -7
- package/dist/telemetry/index.js +4 -0
- package/dist/templates/charts-values/dependencies/values.yaml +6 -0
- package/dist/templates/charts-values/opencrvs-services/values.yaml +6 -0
- package/dist/templates/charts-values/opentelemetry/values.yaml +7 -0
- package/dist/templates/countryconfig-template/.tiltignore +1 -0
- package/dist/templates/countryconfig-template/Dockerfile.assets +7 -0
- package/dist/templates/countryconfig-template/Tiltfile +112 -0
- package/dist/templates/countryconfig-template/assets/README.md +1 -0
- package/dist/templates/countryconfig-template/assets/clear-all-data-dev.sh +61 -0
- package/dist/templates/countryconfig-template/assets/deployment/deploy.sh +455 -0
- package/dist/templates/countryconfig-template/assets/deployment/reindex.sh +168 -0
- package/dist/templates/countryconfig-template/assets/deployment/validate-required-variables-in-compose-files.ts +67 -0
- package/dist/templates/countryconfig-template/assets/elasticsearch/reindex.sh +168 -0
- package/dist/templates/countryconfig-template/assets/metabase/README.md +34 -0
- package/dist/templates/countryconfig-template/assets/metabase/environment-configuration.sql +36 -0
- package/dist/templates/countryconfig-template/assets/metabase/initialize-database.sh +46 -0
- package/dist/templates/countryconfig-template/assets/metabase/metabase.init.db.sql +27737 -0
- package/dist/templates/countryconfig-template/assets/metabase/open-shell.sh +21 -0
- package/dist/templates/countryconfig-template/assets/metabase/package.json +13 -0
- package/dist/templates/countryconfig-template/assets/metabase/run-dev.sh +108 -0
- package/dist/templates/countryconfig-template/assets/metabase/run.sh +120 -0
- package/dist/templates/countryconfig-template/assets/metabase/update-database.sh +40 -0
- package/dist/templates/countryconfig-template/assets/postgres/setup-analytics.sh +135 -0
- package/dist/templates/countryconfig-template/assets/postgres/setup-reference-data.sh +108 -0
- package/dist/templates/countryconfig-template/tilt/clear-all-data.ps1 +50 -0
- package/dist/templates/countryconfig-template/tilt/clear-all-data.sh +35 -0
- package/dist/templates/countryconfig-template/tilt/common.tilt +145 -0
- package/dist/templates/countryconfig-template/tilt/examples/dependencies/values.yaml +15 -0
- package/dist/templates/countryconfig-template/tilt/examples/opencrvs-services/values.yaml +56 -0
- package/dist/templates/countryconfig-template/tilt/examples/traefik/values-minikube.yaml +21 -0
- package/dist/templates/countryconfig-template/tilt/examples/traefik/values.yaml +38 -0
- package/dist/templates/countryconfig-template/tilt/helm/dependencies/values.yaml +17 -0
- package/dist/templates/countryconfig-template/tilt/helm/opencrvs-services/values.yaml +16 -0
- package/dist/templates/countryconfig-template/tilt/lib.tilt +95 -0
- package/dist/templates/countryconfig-template/tilt/opencrvs.tilt +136 -0
- package/dist/translations/template.d.ts +11 -0
- package/dist/translations/template.d.ts.map +1 -0
- package/dist/translations/template.js +100 -0
- package/dist/verify/endpoints.d.ts.map +1 -1
- package/dist/verify/endpoints.js +179 -14
- package/opencrvs-toolkit-2.1.0-rc.14fb6a5.tgz +0 -0
- package/package.json +2 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts +0 -3
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +0 -1
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +0 -429
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +0 -3
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +0 -1
- package/dist/migrations/v2.0/add-resend-invite-notification.js +0 -373
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts +0 -22
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +0 -1
- package/dist/migrations/v2.0/checkout-upstream-files.js +0 -146
- package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts +0 -2
- package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +0 -1
- package/dist/migrations/v2.0/convert-config-files-to-ts.js +0 -838
- package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +0 -3
- package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +0 -1
- package/dist/migrations/v2.0/convert-paragraph-to-heading.js +0 -158
- package/dist/migrations/v2.0/create-events-index.d.ts +0 -3
- package/dist/migrations/v2.0/create-events-index.d.ts.map +0 -1
- package/dist/migrations/v2.0/create-events-index.js +0 -325
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +0 -11
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +0 -1
- package/dist/migrations/v2.0/delete-infrastructure-directory.js +0 -123
- package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts +0 -3
- package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts.map +0 -1
- package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.js +0 -110
- package/dist/migrations/v2.0/index.d.ts +0 -13
- package/dist/migrations/v2.0/index.d.ts.map +0 -1
- package/dist/migrations/v2.0/index.js +0 -103
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +0 -3
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +0 -1
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +0 -432
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +0 -13
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +0 -1
- package/dist/migrations/v2.0/merge-infrastructure-directory.js +0 -222
- package/dist/migrations/v2.0/migrate-application-config-url.d.ts +0 -3
- package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +0 -1
- package/dist/migrations/v2.0/migrate-application-config-url.js +0 -343
- package/dist/migrations/v2.0/migrate-scopes.d.ts.map +0 -1
- package/dist/migrations/v2.0/migrate-scopes.js +0 -305
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +0 -3
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +0 -1
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +0 -267
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +0 -3
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +0 -1
- package/dist/migrations/v2.0/migrate-workqueue-configs.js +0 -317
- package/dist/migrations/v2.0/remove-delete-actions.d.ts +0 -3
- package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-delete-actions.js +0 -156
- package/dist/migrations/v2.0/remove-demo-scope.d.ts +0 -3
- package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-demo-scope.js +0 -74
- package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +0 -3
- package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-deprecated-imports.js +0 -96
- package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +0 -3
- package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-fhir-url-helpers.js +0 -163
- package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +0 -3
- package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-hearth-migrations.js +0 -87
- package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +0 -3
- package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-old-statistics-service.js +0 -356
- package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +0 -3
- package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-pending-certification-flag.js +0 -109
- package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +0 -3
- package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-review-from-register-action.js +0 -163
- package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +0 -3
- package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-unused-environment-variables.js +0 -186
- package/dist/migrations/v2.0/rename-api-paths.d.ts.map +0 -1
- package/dist/migrations/v2.0/rename-location-parent-id.d.ts +0 -3
- package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +0 -1
- package/dist/migrations/v2.0/rename-location-parent-id.js +0 -180
- package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +0 -3
- package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +0 -1
- package/dist/migrations/v2.0/simplify-analytics-precalculations.js +0 -195
- package/dist/migrations/v2.0/update-package-json.d.ts +0 -3
- package/dist/migrations/v2.0/update-package-json.d.ts.map +0 -1
- package/dist/migrations/v2.0/update-package-json.js +0 -105
- package/dist/translations/check.d.ts +0 -21
- package/dist/translations/check.d.ts.map +0 -1
- package/dist/translations/check.js +0 -132
- package/opencrvs-toolkit-2.1.0-rc.12673aa.tgz +0 -0
|
@@ -1,109 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,163 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,186 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rename-location-parent-id.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/rename-location-parent-id.ts"],"names":[],"mappings":"AAmJA,iBAAe,IAAI,kBAiDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -1,180 +0,0 @@
|
|
|
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 `parentId` to `administrativeAreaId` on `Location` typed expressions.
|
|
28
|
-
*
|
|
29
|
-
* Usage:
|
|
30
|
-
* ts-node -r tsconfig-paths/register src/migrations/v2.0/rename-location-parent-id.ts
|
|
31
|
-
*
|
|
32
|
-
* What it does:
|
|
33
|
-
* - Scans all TypeScript files under `src/`
|
|
34
|
-
* - Finds every property access expression whose property name is `parentId`
|
|
35
|
-
* - Uses the TypeScript type checker to resolve the type of the object being accessed
|
|
36
|
-
* - Only renames to `administrativeAreaId` when the type (or any union constituent) is
|
|
37
|
-
* the OpenCRVS `Location` type, identified via three strategies in order:
|
|
38
|
-
* 1. Alias symbol name equals 'Location' (works when TypeScript preserves alias info)
|
|
39
|
-
* 2. Direct symbol name equals 'Location'
|
|
40
|
-
* 3. Structural fallback: the type is an object with the property set that uniquely
|
|
41
|
-
* identifies the OpenCRVS Location shape (id, name, externalId, locationType, and
|
|
42
|
-
* either administrativeAreaId or parentId)
|
|
43
|
-
* - Skips `parentId` accesses on any other type (e.g. plain objects, other interfaces)
|
|
44
|
-
* - Saves the modified files in-place
|
|
45
|
-
*/
|
|
46
|
-
const ts_morph_1 = require("ts-morph");
|
|
47
|
-
const path_1 = __importDefault(require("path"));
|
|
48
|
-
const OLD_PROPERTY_NAME = 'parentId';
|
|
49
|
-
const NEW_PROPERTY_NAME = 'administrativeAreaId';
|
|
50
|
-
const LOCATION_TYPE_NAME = 'Location';
|
|
51
|
-
// Properties that together uniquely identify the OpenCRVS Location type.
|
|
52
|
-
// Used as a structural fallback when TypeScript loses the alias name through
|
|
53
|
-
// re-export chains (e.g. z.infer<…> re-exported via @opencrvs/toolkit/events).
|
|
54
|
-
const LOCATION_STRUCTURAL_PROPS = [
|
|
55
|
-
'id',
|
|
56
|
-
'name',
|
|
57
|
-
'externalId',
|
|
58
|
-
'locationType'
|
|
59
|
-
];
|
|
60
|
-
// At least one of these must also be present (old name or new name)
|
|
61
|
-
const LOCATION_AREA_ID_PROPS = ['administrativeAreaId', 'parentId'];
|
|
62
|
-
// ─── Type helpers ─────────────────────────────────────────────────────────────
|
|
63
|
-
/**
|
|
64
|
-
* Returns true if a single (non-union) type resolves to the OpenCRVS Location type.
|
|
65
|
-
*
|
|
66
|
-
* Three strategies are tried in order so that the check remains robust across
|
|
67
|
-
* different TypeScript/ts-morph resolution paths:
|
|
68
|
-
*
|
|
69
|
-
* 1. Alias symbol name — works when TypeScript preserves the `type Location =
|
|
70
|
-
* z.infer<typeof Location>` alias through the re-export chain.
|
|
71
|
-
* 2. Direct symbol name — works when the type is represented by a named interface
|
|
72
|
-
* or class rather than an alias.
|
|
73
|
-
* 3. Structural match — fallback for when both symbol lookups fail (e.g. the
|
|
74
|
-
* alias is lost because the type was re-exported through a barrel or because
|
|
75
|
-
* z.infer<…> fully unwraps the alias). Checks for the combination of
|
|
76
|
-
* properties that uniquely identify the OpenCRVS Location shape.
|
|
77
|
-
*/
|
|
78
|
-
function isSingleLocationType(t) {
|
|
79
|
-
var _a, _b;
|
|
80
|
-
// Strategy 1: alias symbol (zod-inferred type aliases surface here)
|
|
81
|
-
if (((_a = t.getAliasSymbol()) === null || _a === void 0 ? void 0 : _a.getName()) === LOCATION_TYPE_NAME)
|
|
82
|
-
return true;
|
|
83
|
-
// Strategy 2: direct symbol (plain interface / class)
|
|
84
|
-
if (((_b = t.getSymbol()) === null || _b === void 0 ? void 0 : _b.getName()) === LOCATION_TYPE_NAME)
|
|
85
|
-
return true;
|
|
86
|
-
// Strategy 3: structural fallback
|
|
87
|
-
if (t.isObject()) {
|
|
88
|
-
const propNames = new Set(t.getProperties().map((p) => p.getName()));
|
|
89
|
-
const hasCorePropNames = LOCATION_STRUCTURAL_PROPS.every((p) => propNames.has(p));
|
|
90
|
-
const hasAreaIdProp = LOCATION_AREA_ID_PROPS.some((p) => propNames.has(p));
|
|
91
|
-
if (hasCorePropNames && hasAreaIdProp)
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Returns true when the type of `node` is (or has a union constituent that is)
|
|
98
|
-
* the OpenCRVS Location type.
|
|
99
|
-
* Handles:
|
|
100
|
-
* - `Location`
|
|
101
|
-
* - `Location | undefined` (optional / nullable)
|
|
102
|
-
* - `Location | null | undefined`
|
|
103
|
-
*/
|
|
104
|
-
function isLocationType(node) {
|
|
105
|
-
let type;
|
|
106
|
-
try {
|
|
107
|
-
type = node.getType();
|
|
108
|
-
}
|
|
109
|
-
catch (_a) {
|
|
110
|
-
// getType() can throw on malformed/unresolvable nodes — skip them
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
113
|
-
if (isSingleLocationType(type))
|
|
114
|
-
return true;
|
|
115
|
-
// Walk union constituents (Location | undefined, Location | null, …)
|
|
116
|
-
for (const constituent of type.getUnionTypes()) {
|
|
117
|
-
if (isSingleLocationType(constituent))
|
|
118
|
-
return true;
|
|
119
|
-
}
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
// ─── File processor ──────────────────────────────────────────────────────────
|
|
123
|
-
function processFile(filePath, project) {
|
|
124
|
-
const sourceFile = project.getSourceFile(filePath);
|
|
125
|
-
if (!sourceFile)
|
|
126
|
-
return 0;
|
|
127
|
-
let renamedCount = 0;
|
|
128
|
-
// Collect all matching nodes first to avoid mutating the tree while iterating
|
|
129
|
-
const candidates = sourceFile
|
|
130
|
-
.getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertyAccessExpression)
|
|
131
|
-
.filter((propAccess) => propAccess.getName() === OLD_PROPERTY_NAME);
|
|
132
|
-
for (const propAccess of candidates) {
|
|
133
|
-
const obj = propAccess.getExpression();
|
|
134
|
-
if (!isLocationType(obj))
|
|
135
|
-
continue;
|
|
136
|
-
// Rename only the identifier node (the part after the dot) to preserve
|
|
137
|
-
// surrounding whitespace and optional-chain tokens (?.)
|
|
138
|
-
propAccess.getNameNode().replaceWithText(NEW_PROPERTY_NAME);
|
|
139
|
-
renamedCount++;
|
|
140
|
-
console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Renamed Location.${OLD_PROPERTY_NAME} → Location.${NEW_PROPERTY_NAME}`);
|
|
141
|
-
}
|
|
142
|
-
return renamedCount;
|
|
143
|
-
}
|
|
144
|
-
// ─── Entry point ─────────────────────────────────────────────────────────────
|
|
145
|
-
function main() {
|
|
146
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
-
const srcDir = path_1.default.join(process.cwd(), 'src');
|
|
148
|
-
console.log(`Scanning for Location.${OLD_PROPERTY_NAME} references in: ${srcDir}\n`);
|
|
149
|
-
const project = new ts_morph_1.Project({
|
|
150
|
-
tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
|
|
151
|
-
skipAddingFilesFromTsConfig: false
|
|
152
|
-
});
|
|
153
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
154
|
-
const fp = sf.getFilePath();
|
|
155
|
-
return fp.includes('/src/') && !fp.includes('/node_modules/');
|
|
156
|
-
});
|
|
157
|
-
console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
|
|
158
|
-
let totalRenamed = 0;
|
|
159
|
-
const modifiedFiles = [];
|
|
160
|
-
for (const sourceFile of sourceFiles) {
|
|
161
|
-
const filePath = sourceFile.getFilePath();
|
|
162
|
-
const renamed = processFile(filePath, project);
|
|
163
|
-
if (renamed > 0) {
|
|
164
|
-
totalRenamed += renamed;
|
|
165
|
-
modifiedFiles.push(filePath);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
if (modifiedFiles.length === 0) {
|
|
169
|
-
console.log(`No Location.${OLD_PROPERTY_NAME} references found. Nothing to do.`);
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
|
|
173
|
-
for (const filePath of modifiedFiles) {
|
|
174
|
-
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
175
|
-
yield sourceFile.save();
|
|
176
|
-
console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
|
|
177
|
-
}
|
|
178
|
-
console.log(`\nDone. Renamed ${totalRenamed} Location.${OLD_PROPERTY_NAME} reference(s) to Location.${NEW_PROPERTY_NAME}.`);
|
|
179
|
-
});
|
|
180
|
-
}
|