@opencrvs/toolkit 2.0.0-rc.fc7f7fc → 2.0.0-rc.fd8d9e7

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.
Files changed (80) hide show
  1. package/dist/application-config/index.js +39 -11
  2. package/dist/cli.js +1657 -318
  3. package/dist/commons/api/router.d.ts +44 -56
  4. package/dist/commons/application-config/index.d.ts +16 -4
  5. package/dist/commons/conditionals/conditionals.d.ts +3 -3
  6. package/dist/commons/events/FieldConfig.d.ts +5 -0
  7. package/dist/commons/events/locations.d.ts +17 -1
  8. package/dist/conditionals/index.js +35 -7
  9. package/dist/events/index.js +73 -7
  10. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -1
  11. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +63 -39
  12. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +3 -0
  13. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +1 -0
  14. package/dist/migrations/v2.0/add-resend-invite-notification.js +373 -0
  15. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +19 -0
  16. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
  17. package/dist/migrations/v2.0/checkout-upstream-files.js +17 -13
  18. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -1
  19. package/dist/migrations/v2.0/convert-config-files-to-ts.js +4 -5
  20. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -1
  21. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +4 -5
  22. package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -1
  23. package/dist/migrations/v2.0/create-events-index.js +1 -2
  24. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +3 -0
  25. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -0
  26. package/dist/migrations/v2.0/delete-infrastructure-directory.js +77 -0
  27. package/dist/migrations/v2.0/index.d.ts +8 -4
  28. package/dist/migrations/v2.0/index.d.ts.map +1 -1
  29. package/dist/migrations/v2.0/index.js +1625 -315
  30. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -1
  31. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +95 -7
  32. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +3 -0
  33. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -0
  34. package/dist/migrations/v2.0/merge-infrastructure-directory.js +221 -0
  35. package/dist/migrations/v2.0/migrate-application-config-url.d.ts +3 -0
  36. package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +1 -0
  37. package/dist/migrations/v2.0/migrate-application-config-url.js +342 -0
  38. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -1
  39. package/dist/migrations/v2.0/migrate-scopes.js +6 -7
  40. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -1
  41. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +3 -4
  42. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -1
  43. package/dist/migrations/v2.0/migrate-workqueue-configs.js +3 -4
  44. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -1
  45. package/dist/migrations/v2.0/remove-delete-actions.js +3 -4
  46. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -1
  47. package/dist/migrations/v2.0/remove-demo-scope.js +2 -3
  48. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -1
  49. package/dist/migrations/v2.0/remove-deprecated-imports.js +3 -4
  50. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +3 -0
  51. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +1 -0
  52. package/dist/migrations/v2.0/remove-fhir-url-helpers.js +163 -0
  53. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -1
  54. package/dist/migrations/v2.0/remove-hearth-migrations.js +1 -2
  55. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +3 -0
  56. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +1 -0
  57. package/dist/migrations/v2.0/remove-old-statistics-service.js +356 -0
  58. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -1
  59. package/dist/migrations/v2.0/remove-pending-certification-flag.js +3 -4
  60. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -1
  61. package/dist/migrations/v2.0/remove-review-from-register-action.js +3 -4
  62. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +3 -0
  63. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +1 -0
  64. package/dist/migrations/v2.0/remove-unused-environment-variables.js +186 -0
  65. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -1
  66. package/dist/migrations/v2.0/rename-api-paths.js +3 -4
  67. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -1
  68. package/dist/migrations/v2.0/rename-location-parent-id.js +3 -4
  69. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -1
  70. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +1 -2
  71. package/dist/migrations/v2.0/update-package-json.d.ts +3 -0
  72. package/dist/migrations/v2.0/update-package-json.d.ts.map +1 -0
  73. package/dist/migrations/v2.0/update-package-json.js +105 -0
  74. package/dist/notification/index.js +35 -7
  75. package/dist/scopes/index.d.ts +82 -10
  76. package/dist/scopes/index.js +41 -8
  77. package/opencrvs-toolkit-2.0.0-rc.fd8d9e7.tgz +0 -0
  78. package/package.json +1 -1
  79. package/tsconfig.tsbuildinfo +1 -1
  80. package/opencrvs-toolkit-2.0.0-rc.fc7f7fc.tgz +0 -0
@@ -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 legacy FHIR URL helpers after `FHIR_URL` env cleanup.
28
+ *
29
+ * Targets:
30
+ * - `FHIR_URL` named imports
31
+ * - functions: `getFromFhir`, `updateResourceFromHearth`, `updateResourceInHearth`
32
+ *
33
+ * What it does:
34
+ * 1. Removes top-level declarations with one of the helper names.
35
+ * Supported declaration forms:
36
+ * - `function getFromFhir(...) {}`
37
+ * - `const getFromFhir = (...) => {}`
38
+ * - `export const getFromFhir = (...) => {}`
39
+ * 2. Removes `FHIR_URL` named imports from any import declaration.
40
+ * Empty import declarations are dropped.
41
+ * 3. Reports any remaining `FHIR_URL` identifier references so developers
42
+ * can manually clean up unusual patterns.
43
+ */
44
+ const path_1 = __importDefault(require("path"));
45
+ const ts_morph_1 = require("ts-morph");
46
+ const FHIR_IMPORT = 'FHIR_URL';
47
+ const HELPER_NAMES = new Set([
48
+ 'getFromFhir',
49
+ 'updateResourceFromHearth',
50
+ 'updateResourceInHearth'
51
+ ]);
52
+ function removeHelpers(sourceFilePath, project) {
53
+ const sourceFile = project.getSourceFile(sourceFilePath);
54
+ if (!sourceFile) {
55
+ return {
56
+ removedHelpers: [],
57
+ removedImportCount: 0,
58
+ remainingFhirReferences: 0
59
+ };
60
+ }
61
+ const removedHelpers = [];
62
+ let removedImportCount = 0;
63
+ // Function declarations: `function getFromFhir(...) { ... }`
64
+ for (const fn of sourceFile.getFunctions()) {
65
+ const name = fn.getName();
66
+ if (!name || !HELPER_NAMES.has(name))
67
+ continue;
68
+ removedHelpers.push(name);
69
+ fn.remove();
70
+ }
71
+ // Variable declarations: `const getFromFhir = ...`
72
+ for (const stmt of [...sourceFile.getVariableStatements()]) {
73
+ const declarations = [...stmt.getDeclarations()];
74
+ const toRemove = declarations.filter((decl) => HELPER_NAMES.has(decl.getName()));
75
+ if (toRemove.length === 0)
76
+ continue;
77
+ removedHelpers.push(...toRemove.map((decl) => decl.getName()));
78
+ if (toRemove.length === declarations.length) {
79
+ stmt.remove();
80
+ }
81
+ else {
82
+ for (const decl of toRemove)
83
+ decl.remove();
84
+ }
85
+ }
86
+ // Remove FHIR_URL named imports.
87
+ for (const decl of sourceFile.getImportDeclarations()) {
88
+ const matches = decl
89
+ .getNamedImports()
90
+ .filter((ni) => ni.getName() === FHIR_IMPORT);
91
+ if (matches.length === 0)
92
+ continue;
93
+ for (const named of matches) {
94
+ named.remove();
95
+ removedImportCount++;
96
+ }
97
+ const hasAnyNamedImportsLeft = decl.getNamedImports().length > 0;
98
+ const hasDefaultImport = !!decl.getDefaultImport();
99
+ const hasNamespaceImport = !!decl.getNamespaceImport();
100
+ if (!hasAnyNamedImportsLeft && !hasDefaultImport && !hasNamespaceImport) {
101
+ decl.remove();
102
+ }
103
+ }
104
+ const remainingFhirReferences = sourceFile
105
+ .getDescendantsOfKind(ts_morph_1.SyntaxKind.Identifier)
106
+ .filter((id) => id.getText() === FHIR_IMPORT)
107
+ .filter((id) => !id.getFirstAncestorByKind(ts_morph_1.SyntaxKind.ImportDeclaration))
108
+ .length;
109
+ return { removedHelpers, removedImportCount, remainingFhirReferences };
110
+ }
111
+ function main() {
112
+ return __awaiter(this, void 0, void 0, function* () {
113
+ const project = new ts_morph_1.Project({
114
+ tsConfigFilePath: path_1.default.resolve(process.cwd(), 'tsconfig.json'),
115
+ skipAddingFilesFromTsConfig: false
116
+ });
117
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
118
+ const fp = sf.getFilePath();
119
+ return fp.includes('/src/') && !fp.includes('/node_modules/');
120
+ });
121
+ console.log(`Removing legacy FHIR_URL helpers in ${sourceFiles.length} source file(s)...\n`);
122
+ let totalRemovedImports = 0;
123
+ let totalRemovedHelpers = 0;
124
+ const modifiedFiles = [];
125
+ const warnings = [];
126
+ for (const sourceFile of sourceFiles) {
127
+ const filePath = sourceFile.getFilePath();
128
+ const rel = path_1.default.relative(process.cwd(), filePath);
129
+ const result = removeHelpers(filePath, project);
130
+ const changed = result.removedImportCount > 0 || result.removedHelpers.length > 0;
131
+ if (changed) {
132
+ modifiedFiles.push(filePath);
133
+ totalRemovedImports += result.removedImportCount;
134
+ totalRemovedHelpers += result.removedHelpers.length;
135
+ if (result.removedHelpers.length > 0) {
136
+ console.log(` [${rel}] Removed helper(s): ${result.removedHelpers.join(', ')}`);
137
+ }
138
+ if (result.removedImportCount > 0) {
139
+ console.log(` [${rel}] Removed ${result.removedImportCount} '${FHIR_IMPORT}' import(s)`);
140
+ }
141
+ }
142
+ if (result.remainingFhirReferences > 0) {
143
+ warnings.push(`${rel}: ${result.remainingFhirReferences} remaining '${FHIR_IMPORT}' reference(s)`);
144
+ }
145
+ }
146
+ if (modifiedFiles.length === 0 && warnings.length === 0) {
147
+ console.log('No FHIR_URL imports/helpers found. Nothing to do.');
148
+ return;
149
+ }
150
+ if (modifiedFiles.length > 0) {
151
+ console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
152
+ for (const filePath of modifiedFiles) {
153
+ yield project.getSourceFileOrThrow(filePath).save();
154
+ console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
155
+ }
156
+ }
157
+ if (warnings.length > 0) {
158
+ console.warn(`\n WARNING: Some '${FHIR_IMPORT}' usages remain and need manual cleanup:\n` +
159
+ warnings.map((line) => ` - ${line}`).join('\n'));
160
+ }
161
+ console.log(`\nDone. Removed ${totalRemovedHelpers} helper declaration(s) and ${totalRemovedImports} '${FHIR_IMPORT}' import(s).`);
162
+ });
163
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"remove-hearth-migrations.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/remove-hearth-migrations.ts"],"names":[],"mappings":"AA2BA,iBAAe,IAAI,kBAalB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
1
+ {"version":3,"file":"remove-hearth-migrations.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/remove-hearth-migrations.ts"],"names":[],"mappings":"AAyBA,iBAAe,IAAI,kBAalB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -48,7 +48,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
48
48
  exports.main = main;
49
49
  const fs = __importStar(require("fs"));
50
50
  const path_1 = __importDefault(require("path"));
51
- const _1 = require(".");
52
51
  const PATHS_TO_REMOVE = [
53
52
  {
54
53
  relativePath: 'src/migrations/hearth',
@@ -63,7 +62,7 @@ const PATHS_TO_REMOVE = [
63
62
  function main() {
64
63
  return __awaiter(this, void 0, void 0, function* () {
65
64
  for (const { relativePath, label } of PATHS_TO_REMOVE) {
66
- const absolutePath = path_1.default.join((0, _1.getCwd)(), relativePath);
65
+ const absolutePath = path_1.default.join(process.cwd(), relativePath);
67
66
  if (fs.existsSync(absolutePath)) {
68
67
  fs.rmSync(absolutePath, { recursive: true, force: true });
69
68
  // eslint-disable-next-line no-console
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=remove-old-statistics-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove-old-statistics-service.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/remove-old-statistics-service.ts"],"names":[],"mappings":"AAuUA,iBAAe,IAAI,kBA4FlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,356 @@
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 the legacy `GET /statistics` Hapi route and its handler.
28
+ *
29
+ * Background:
30
+ * In v1.x country configs exposed a `GET /statistics` route used by the
31
+ * demo data-generator script to seed location statistics. In v2.0 this is
32
+ * no longer part of the country config surface — the data-generator (where
33
+ * it remains) talks to the Core FHIR APIs directly.
34
+ *
35
+ * What it does (per source file under `src/`):
36
+ * 1. Removes any `<receiver>.route({ method: 'GET', path: '/statistics', ... })`
37
+ * call. Both single-route (`server.route({...})`) and array-route
38
+ * (`server.route([{...}, {...}])`) forms are handled — for the array
39
+ * form only the matching object is removed, the other routes stay.
40
+ * 2. Removes any `statisticsHandler` named import. If that empties an
41
+ * import declaration, the whole declaration is dropped.
42
+ * 3. Finds the file that defines `export async function statisticsHandler`
43
+ * (typically `src/api/data-generator/handler.ts`):
44
+ * - If `statisticsHandler` is the file's *only* export → the whole
45
+ * file is deleted.
46
+ * - Otherwise → just the function declaration is removed and a
47
+ * warning is logged so the developer can decide what to do with
48
+ * the rest of the file.
49
+ * 4. After deleting the handler file, performs a transitive orphan sweep
50
+ * bounded to the handler's directory subtree (e.g.
51
+ * `src/api/data-generator/`):
52
+ * - Each project-local import the handler had is checked. If no
53
+ * remaining file in the project imports that module, the module
54
+ * file is deleted too.
55
+ * - Recursive: a deleted file's own local imports are then checked
56
+ * the same way. The directory boundary prevents this from ever
57
+ * touching shared utilities outside the handler's subtree.
58
+ * This is what reaches `service.ts` (and friends) once nothing else
59
+ * uses it.
60
+ *
61
+ * Caveats:
62
+ * - Only project-local imports inside the handler's directory are
63
+ * considered for orphan deletion. Helpers in shared locations (e.g.
64
+ * `src/utils/`, `src/constants.ts`) are never auto-deleted.
65
+ * - Files that are still referenced by *anything* in the project (other
66
+ * handlers, scripts, demo/data-generators) are kept untouched.
67
+ * - The codemod is a no-op when the route doesn't exist (already
68
+ * migrated country configs).
69
+ */
70
+ const path_1 = __importDefault(require("path"));
71
+ const ts_morph_1 = require("ts-morph");
72
+ const ROUTE_PATH = '/statistics';
73
+ const HANDLER_NAME = 'statisticsHandler';
74
+ /**
75
+ * Returns true if the given object literal has a property `path` whose
76
+ * value (string literal or no-substitution template literal) equals
77
+ * `ROUTE_PATH`.
78
+ */
79
+ function isStatisticsRouteObject(obj) {
80
+ const pathProp = obj.getProperty('path');
81
+ if (!pathProp || !ts_morph_1.Node.isPropertyAssignment(pathProp))
82
+ return false;
83
+ const init = pathProp.getInitializer();
84
+ if (!init)
85
+ return false;
86
+ if (ts_morph_1.Node.isStringLiteral(init) || ts_morph_1.Node.isNoSubstitutionTemplateLiteral(init)) {
87
+ return init.getLiteralValue() === ROUTE_PATH;
88
+ }
89
+ return false;
90
+ }
91
+ /**
92
+ * Removes `<receiver>.route({...})` and `<receiver>.route([{...}, ...])`
93
+ * calls whose route object has `path: '/statistics'`. For the array form
94
+ * only the matching element is removed; siblings are preserved.
95
+ *
96
+ * Returns the number of routes removed in this file.
97
+ */
98
+ function removeStatisticsRoutes(sourceFile) {
99
+ let removed = 0;
100
+ // Snapshot first — we'll be mutating the AST during iteration.
101
+ const callExpressions = [
102
+ ...sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression)
103
+ ];
104
+ for (const call of callExpressions) {
105
+ if (call.wasForgotten())
106
+ continue;
107
+ const expr = call.getExpression();
108
+ if (!ts_morph_1.Node.isPropertyAccessExpression(expr))
109
+ continue;
110
+ if (expr.getName() !== 'route')
111
+ continue;
112
+ const args = call.getArguments();
113
+ if (args.length === 0)
114
+ continue;
115
+ const firstArg = args[0];
116
+ // Single-route form: `server.route({ method, path, handler, ... })`
117
+ if (ts_morph_1.Node.isObjectLiteralExpression(firstArg)) {
118
+ if (!isStatisticsRouteObject(firstArg))
119
+ continue;
120
+ // Drop the whole `server.route({...})` statement, not just the call,
121
+ // so we don't leave a dangling `;` behind.
122
+ const stmt = call.getFirstAncestorByKind(ts_morph_1.SyntaxKind.ExpressionStatement);
123
+ if (stmt) {
124
+ stmt.remove();
125
+ removed++;
126
+ }
127
+ else {
128
+ // Fallback (shouldn't happen at top level): replace the call.
129
+ call.replaceWithText('');
130
+ removed++;
131
+ }
132
+ continue;
133
+ }
134
+ // Array-route form: `server.route([{...}, {...}])`
135
+ if (ts_morph_1.Node.isArrayLiteralExpression(firstArg)) {
136
+ const matchingIndexes = firstArg
137
+ .getElements()
138
+ .map((el, idx) => ({ el, idx }))
139
+ .filter(({ el }) => ts_morph_1.Node.isObjectLiteralExpression(el) && isStatisticsRouteObject(el))
140
+ .map(({ idx }) => idx);
141
+ // Highest index first so each removal doesn't shift the index of
142
+ // matches we haven't dropped yet.
143
+ matchingIndexes
144
+ .sort((a, b) => b - a)
145
+ .forEach((idx) => {
146
+ firstArg.removeElement(idx);
147
+ removed++;
148
+ });
149
+ }
150
+ }
151
+ return removed;
152
+ }
153
+ /**
154
+ * Removes any `statisticsHandler` named import. Returns true if the file
155
+ * was modified.
156
+ */
157
+ function removeStatisticsHandlerImports(sourceFile) {
158
+ let changed = false;
159
+ for (const decl of sourceFile.getImportDeclarations()) {
160
+ const targetNamed = decl
161
+ .getNamedImports()
162
+ .find((ni) => ni.getName() === HANDLER_NAME);
163
+ if (!targetNamed)
164
+ continue;
165
+ targetNamed.remove();
166
+ changed = true;
167
+ const isNowEmpty = decl.getNamedImports().length === 0 &&
168
+ !decl.getDefaultImport() &&
169
+ !decl.getNamespaceImport();
170
+ if (isNowEmpty)
171
+ decl.remove();
172
+ }
173
+ return changed;
174
+ }
175
+ function processFile(sourceFile) {
176
+ const routesRemoved = removeStatisticsRoutes(sourceFile);
177
+ const importsCleaned = removeStatisticsHandlerImports(sourceFile);
178
+ return { routesRemoved, importsCleaned };
179
+ }
180
+ /**
181
+ * Returns local-project import paths from the given source file that
182
+ * resolve to a file inside `subtreeRoot`. External (npm) imports and
183
+ * imports outside the subtree are excluded.
184
+ */
185
+ function collectLocalImportsInSubtree(sourceFile, subtreeRoot) {
186
+ const result = [];
187
+ for (const decl of sourceFile.getImportDeclarations()) {
188
+ const moduleSf = decl.getModuleSpecifierSourceFile();
189
+ if (!moduleSf)
190
+ continue;
191
+ const fp = moduleSf.getFilePath();
192
+ if (!fp.startsWith(subtreeRoot))
193
+ continue;
194
+ result.push(fp);
195
+ }
196
+ return result;
197
+ }
198
+ /**
199
+ * Walks files reachable from a deleted starting file via local imports
200
+ * within `subtreeRoot`, deleting any that nobody else imports. Recursive
201
+ * via worklist — when a file is deleted, its own local imports become
202
+ * candidates for the next round.
203
+ */
204
+ function deleteOrphanedDescendants(project, startingFile, subtreeRoot) {
205
+ const initialCandidates = collectLocalImportsInSubtree(startingFile, subtreeRoot);
206
+ const startingPath = startingFile.getFilePath();
207
+ const deleted = new Set([startingPath]);
208
+ const seen = new Set();
209
+ const worklist = [...initialCandidates];
210
+ const orphans = [];
211
+ while (worklist.length > 0) {
212
+ const candidate = worklist.shift();
213
+ if (seen.has(candidate))
214
+ continue;
215
+ seen.add(candidate);
216
+ if (deleted.has(candidate))
217
+ continue;
218
+ if (!candidate.startsWith(subtreeRoot))
219
+ continue;
220
+ const candidateSf = project.getSourceFile(candidate);
221
+ if (!candidateSf)
222
+ continue;
223
+ // Anyone left in the project still importing this file (including
224
+ // files outside the subtree)? If so, it's not actually orphaned.
225
+ const stillImported = project.getSourceFiles().some((sf) => {
226
+ const sfPath = sf.getFilePath();
227
+ if (deleted.has(sfPath))
228
+ return false;
229
+ if (sfPath === candidate)
230
+ return false;
231
+ return sf
232
+ .getImportDeclarations()
233
+ .some((decl) => { var _a; return ((_a = decl.getModuleSpecifierSourceFile()) === null || _a === void 0 ? void 0 : _a.getFilePath()) === candidate; });
234
+ });
235
+ if (stillImported)
236
+ continue;
237
+ // Capture local imports BEFORE deletion — `delete()` invalidates the
238
+ // node, so we wouldn't be able to read them afterwards.
239
+ const next = collectLocalImportsInSubtree(candidateSf, subtreeRoot);
240
+ worklist.push(...next);
241
+ candidateSf.delete();
242
+ deleted.add(candidate);
243
+ orphans.push(candidate);
244
+ }
245
+ return orphans;
246
+ }
247
+ /**
248
+ * Finds the file that exports `statisticsHandler` and either deletes the
249
+ * whole file (when it's the sole export) or just removes the function
250
+ * declaration. When the file is deleted, also performs a transitive
251
+ * orphan sweep bounded to the file's directory.
252
+ */
253
+ function processHandlerFile(project) {
254
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
255
+ const fp = sf.getFilePath();
256
+ return fp.includes('/src/') && !fp.includes('/node_modules/');
257
+ });
258
+ for (const sf of sourceFiles) {
259
+ const fn = sf.getFunction(HANDLER_NAME);
260
+ if (!fn)
261
+ continue;
262
+ const filePath = sf.getFilePath();
263
+ const exportsByName = [...sf.getExportedDeclarations().keys()];
264
+ const otherExports = exportsByName.filter((name) => name !== HANDLER_NAME);
265
+ if (otherExports.length === 0) {
266
+ // Sole export — delete the file, then sweep orphans inside its
267
+ // directory subtree.
268
+ const subtreeRoot = path_1.default.dirname(filePath) + path_1.default.sep;
269
+ const orphansDeleted = deleteOrphanedDescendants(project, sf, subtreeRoot);
270
+ sf.delete();
271
+ return { filePath, action: 'deleted', orphansDeleted };
272
+ }
273
+ // Other exports exist; surgically remove just this function.
274
+ // We don't run the orphan sweep here — the file isn't gone, so
275
+ // anything it imports is presumably still in use.
276
+ fn.remove();
277
+ return {
278
+ filePath,
279
+ action: 'function-removed',
280
+ remainingExports: otherExports,
281
+ orphansDeleted: []
282
+ };
283
+ }
284
+ return { filePath: '', action: 'not-found', orphansDeleted: [] };
285
+ }
286
+ function main() {
287
+ return __awaiter(this, void 0, void 0, function* () {
288
+ var _a;
289
+ const project = new ts_morph_1.Project({
290
+ tsConfigFilePath: path_1.default.resolve(process.cwd(), 'tsconfig.json'),
291
+ skipAddingFilesFromTsConfig: false
292
+ });
293
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
294
+ const fp = sf.getFilePath();
295
+ return fp.includes('/src/') && !fp.includes('/node_modules/');
296
+ });
297
+ console.log(`Removing legacy 'GET ${ROUTE_PATH}' route and '${HANDLER_NAME}' across ${sourceFiles.length} source file(s)...\n`);
298
+ let totalRoutesRemoved = 0;
299
+ let totalFilesWithImportsCleaned = 0;
300
+ let totalFilesWithRoutesRemoved = 0;
301
+ for (const sourceFile of sourceFiles) {
302
+ const filePath = sourceFile.getFilePath();
303
+ const rel = path_1.default.relative(process.cwd(), filePath);
304
+ const result = processFile(sourceFile);
305
+ if (result.routesRemoved > 0) {
306
+ console.log(` [${rel}] Removed ${result.routesRemoved} '${ROUTE_PATH}' route(s)`);
307
+ totalRoutesRemoved += result.routesRemoved;
308
+ totalFilesWithRoutesRemoved++;
309
+ }
310
+ if (result.importsCleaned) {
311
+ console.log(` [${rel}] Cleaned up '${HANDLER_NAME}' import`);
312
+ totalFilesWithImportsCleaned++;
313
+ }
314
+ if (result.routesRemoved > 0 || result.importsCleaned) {
315
+ yield sourceFile.save();
316
+ }
317
+ }
318
+ const handlerResult = processHandlerFile(project);
319
+ switch (handlerResult.action) {
320
+ case 'deleted': {
321
+ const rel = path_1.default.relative(process.cwd(), handlerResult.filePath);
322
+ console.log(` [${rel}] Deleted handler file ('${HANDLER_NAME}' was the sole export).`);
323
+ for (const orphanPath of handlerResult.orphansDeleted) {
324
+ const orphanRel = path_1.default.relative(process.cwd(), orphanPath);
325
+ console.log(` [${orphanRel}] Deleted (no remaining importers in the project after handler removal).`);
326
+ }
327
+ // `delete()` schedules deletion; `save()` writes it to disk.
328
+ yield project.save();
329
+ break;
330
+ }
331
+ case 'function-removed': {
332
+ const rel = path_1.default.relative(process.cwd(), handlerResult.filePath);
333
+ console.warn(` [${rel}] Removed '${HANDLER_NAME}' function but kept the file (other exports remain: ${(_a = handlerResult.remainingExports) === null || _a === void 0 ? void 0 : _a.join(', ')}). Review whether the file is still needed.`);
334
+ // Save the source file with the function removed.
335
+ const sf = project.getSourceFile(handlerResult.filePath);
336
+ if (sf)
337
+ yield sf.save();
338
+ break;
339
+ }
340
+ case 'not-found':
341
+ // Either already migrated or the handler lives somewhere unexpected.
342
+ // Not an error — continue silently.
343
+ break;
344
+ }
345
+ if (totalRoutesRemoved === 0 &&
346
+ totalFilesWithImportsCleaned === 0 &&
347
+ handlerResult.action === 'not-found') {
348
+ console.log(`\nNo legacy '${ROUTE_PATH}' route or handler found. Nothing to do.`);
349
+ return;
350
+ }
351
+ const orphansSummary = handlerResult.orphansDeleted.length > 0
352
+ ? ` and ${handlerResult.orphansDeleted.length} orphaned helper file(s)`
353
+ : '';
354
+ console.log(`\nDone. Removed ${totalRoutesRemoved} route(s) across ${totalFilesWithRoutesRemoved} file(s); cleaned ${HANDLER_NAME} import in ${totalFilesWithImportsCleaned} file(s)${orphansSummary}.`);
355
+ });
356
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"remove-pending-certification-flag.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/remove-pending-certification-flag.ts"],"names":[],"mappings":"AA2EA,iBAAe,IAAI,kBAiDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
1
+ {"version":3,"file":"remove-pending-certification-flag.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/remove-pending-certification-flag.ts"],"names":[],"mappings":"AAyEA,iBAAe,IAAI,kBAiDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -38,7 +38,6 @@ exports.main = main;
38
38
  */
39
39
  const ts_morph_1 = require("ts-morph");
40
40
  const path_1 = __importDefault(require("path"));
41
- const _1 = require(".");
42
41
  const INHERENT_FLAGS_ENUM_NAME = 'InherentFlags';
43
42
  const PENDING_CERTIFICATION_MEMBER = 'PENDING_CERTIFICATION';
44
43
  function isPendingCertificationFlag(node) {
@@ -67,14 +66,14 @@ function processFile(filePath, project) {
67
66
  for (const index of indicesToRemove.reverse()) {
68
67
  array.removeElement(index);
69
68
  removedCount++;
70
- console.log(` [${path_1.default.relative((0, _1.getCwd)(), filePath)}] Removed InherentFlags.PENDING_CERTIFICATION from array`);
69
+ console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Removed InherentFlags.PENDING_CERTIFICATION from array`);
71
70
  }
72
71
  }
73
72
  return removedCount;
74
73
  }
75
74
  function main() {
76
75
  return __awaiter(this, void 0, void 0, function* () {
77
- const srcDir = path_1.default.join((0, _1.getCwd)(), 'src');
76
+ const srcDir = path_1.default.join(process.cwd(), 'src');
78
77
  console.log(`Scanning for InherentFlags.PENDING_CERTIFICATION array elements in: ${srcDir}\n`);
79
78
  const project = new ts_morph_1.Project({
80
79
  tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
@@ -103,7 +102,7 @@ function main() {
103
102
  for (const filePath of modifiedFiles) {
104
103
  const sourceFile = project.getSourceFileOrThrow(filePath);
105
104
  yield sourceFile.save();
106
- console.log(` Saved: ${path_1.default.relative((0, _1.getCwd)(), filePath)}`);
105
+ console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
107
106
  }
108
107
  console.log(`\nDone. Removed ${totalRemoved} InherentFlags.PENDING_CERTIFICATION element(s) from array(s).`);
109
108
  });
@@ -1 +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":"AAoJA,iBAAe,IAAI,kBAkDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
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"}
@@ -39,7 +39,6 @@ exports.main = main;
39
39
  */
40
40
  const ts_morph_1 = require("ts-morph");
41
41
  const path_1 = __importDefault(require("path"));
42
- const _1 = require(".");
43
42
  const DEFINE_CONFIG_NAME = 'defineConfig';
44
43
  const ACTIONS_PROPERTY_NAME = 'actions';
45
44
  const TYPE_PROPERTY_NAME = 'type';
@@ -117,7 +116,7 @@ function processFile(filePath, project) {
117
116
  const wasRemoved = removeReviewFromRegisterActions(element);
118
117
  if (wasRemoved) {
119
118
  removedCount++;
120
- console.log(` [${path_1.default.relative((0, _1.getCwd)(), filePath)}] Removed 'review' from REGISTER action`);
119
+ console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Removed 'review' from REGISTER action`);
121
120
  }
122
121
  }
123
122
  }
@@ -125,7 +124,7 @@ function processFile(filePath, project) {
125
124
  }
126
125
  function main() {
127
126
  return __awaiter(this, void 0, void 0, function* () {
128
- const srcDir = path_1.default.join((0, _1.getCwd)(), 'src');
127
+ const srcDir = path_1.default.join(process.cwd(), 'src');
129
128
  console.log(`Scanning for defineConfig calls in: ${srcDir}\n`);
130
129
  const project = new ts_morph_1.Project({
131
130
  tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
@@ -157,7 +156,7 @@ function main() {
157
156
  for (const filePath of modifiedFiles) {
158
157
  const sourceFile = project.getSourceFileOrThrow(filePath);
159
158
  yield sourceFile.save();
160
- console.log(` Saved: ${path_1.default.relative((0, _1.getCwd)(), filePath)}`);
159
+ console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
161
160
  }
162
161
  console.log(`\nDone. Removed ${totalRemoved} 'review' property assignment(s) from REGISTER action(s).`);
163
162
  });
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=remove-unused-environment-variables.d.ts.map
@@ -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"}