@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,317 +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: migrate deprecated workqueue `actions` array to singular `action`.
|
|
28
|
-
*
|
|
29
|
-
* Usage:
|
|
30
|
-
* ts-node -r tsconfig-paths/register src/migrations/v2.0/migrate-workqueue-configs.ts
|
|
31
|
-
*
|
|
32
|
-
* What it does:
|
|
33
|
-
* - Scans TypeScript files under `src/`
|
|
34
|
-
* - Finds `defineWorkqueues([...])` calls
|
|
35
|
-
* - For each workqueue object:
|
|
36
|
-
* - `actions: []` -> removes `actions`
|
|
37
|
-
* - `actions: [{ ... }]` -> replaces with `action: { ... }` if type is supported
|
|
38
|
-
* - `actions: [{ type: 'DEFAULT' }]` -> removes `actions` and does not create `action`
|
|
39
|
-
* - `actions: [{...}, {...}, ...]` -> keeps first as `action`, warns about dropped extras
|
|
40
|
-
* - If `action` already exists, removes deprecated `actions` and keeps `action`
|
|
41
|
-
* - Removes unsupported `action.type` values (`DEFAULT`, `VALIDATE`, etc.)
|
|
42
|
-
* - Ensures every workqueue ends up with a valid `action`. When none is
|
|
43
|
-
* present (or the existing one is unsupported), falls back to
|
|
44
|
-
* `action: { type: ActionType.READ }` and ensures `ActionType` is imported
|
|
45
|
-
* from `@opencrvs/toolkit/events` in the file.
|
|
46
|
-
* - Saves modified files in-place
|
|
47
|
-
*/
|
|
48
|
-
const ts_morph_1 = require("ts-morph");
|
|
49
|
-
const path_1 = __importDefault(require("path"));
|
|
50
|
-
const DEFINE_WORKQUEUES_NAME = 'defineWorkqueues';
|
|
51
|
-
const ACTIONS_PROPERTY_NAME = 'actions';
|
|
52
|
-
const ACTION_PROPERTY_NAME = 'action';
|
|
53
|
-
const CONDITIONALS_PROPERTY_NAME = 'conditionals';
|
|
54
|
-
const TYPE_PROPERTY_NAME = 'type';
|
|
55
|
-
const SLUG_PROPERTY_NAME = 'slug';
|
|
56
|
-
const READ_ACTION_TYPE = 'READ';
|
|
57
|
-
const ACTION_TYPE_IMPORT_NAME = 'ActionType';
|
|
58
|
-
const TOOLKIT_EVENTS_MODULE = '@opencrvs/toolkit/events';
|
|
59
|
-
const READ_ACTION_FALLBACK_INITIALIZER = `{ type: ${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE} }`;
|
|
60
|
-
const SUPPORTED_WORKQUEUE_ACTION_TYPES = new Set([
|
|
61
|
-
'READ',
|
|
62
|
-
'DELETE',
|
|
63
|
-
'DECLARE',
|
|
64
|
-
'REGISTER',
|
|
65
|
-
'EDIT',
|
|
66
|
-
'REJECT',
|
|
67
|
-
'MARK_AS_DUPLICATE',
|
|
68
|
-
'ARCHIVE',
|
|
69
|
-
'PRINT_CERTIFICATE',
|
|
70
|
-
'REQUEST_CORRECTION'
|
|
71
|
-
]);
|
|
72
|
-
function getWorkqueueLabel(workqueue) {
|
|
73
|
-
const slugProperty = workqueue.getProperty(SLUG_PROPERTY_NAME);
|
|
74
|
-
if (!slugProperty || !ts_morph_1.Node.isPropertyAssignment(slugProperty)) {
|
|
75
|
-
return '(unknown slug)';
|
|
76
|
-
}
|
|
77
|
-
const slugInitializer = slugProperty.getInitializer();
|
|
78
|
-
if (!slugInitializer || !ts_morph_1.Node.isStringLiteral(slugInitializer)) {
|
|
79
|
-
return '(unknown slug)';
|
|
80
|
-
}
|
|
81
|
-
return slugInitializer.getLiteralValue();
|
|
82
|
-
}
|
|
83
|
-
function getActionTypeName(action) {
|
|
84
|
-
const typeProperty = action.getProperty(TYPE_PROPERTY_NAME);
|
|
85
|
-
if (!typeProperty || !ts_morph_1.Node.isPropertyAssignment(typeProperty)) {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
const typeInitializer = typeProperty.getInitializer();
|
|
89
|
-
if (!typeInitializer) {
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
if (ts_morph_1.Node.isStringLiteral(typeInitializer)) {
|
|
93
|
-
return typeInitializer.getLiteralValue();
|
|
94
|
-
}
|
|
95
|
-
if (ts_morph_1.Node.isPropertyAccessExpression(typeInitializer)) {
|
|
96
|
-
return typeInitializer.getName();
|
|
97
|
-
}
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
function isUnsupportedActionType(action) {
|
|
101
|
-
const typeName = getActionTypeName(action);
|
|
102
|
-
if (!typeName) {
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Ensures the workqueue has a valid singular `action` property. When the
|
|
109
|
-
* existing `action` is missing or has an unsupported type, replaces it with
|
|
110
|
-
* `action: { type: ActionType.READ }`.
|
|
111
|
-
*
|
|
112
|
-
* Returns whether anything was changed and whether the READ fallback was
|
|
113
|
-
* applied (so the caller can ensure `ActionType` is imported in the file).
|
|
114
|
-
*/
|
|
115
|
-
function ensureValidAction(workqueue, relPath) {
|
|
116
|
-
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
117
|
-
const actionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME);
|
|
118
|
-
if (actionProperty && ts_morph_1.Node.isPropertyAssignment(actionProperty)) {
|
|
119
|
-
const initializer = actionProperty.getInitializer();
|
|
120
|
-
if (initializer && ts_morph_1.Node.isObjectLiteralExpression(initializer)) {
|
|
121
|
-
if (!isUnsupportedActionType(initializer)) {
|
|
122
|
-
return { changed: false, usedReadFallback: false };
|
|
123
|
-
}
|
|
124
|
-
actionProperty.set({
|
|
125
|
-
name: ACTION_PROPERTY_NAME,
|
|
126
|
-
initializer: READ_ACTION_FALLBACK_INITIALIZER
|
|
127
|
-
});
|
|
128
|
-
// eslint-disable-next-line no-console
|
|
129
|
-
console.log(` [${relPath}] Replaced unsupported 'action' type with '${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE}' on workqueue '${workqueueLabel}'`);
|
|
130
|
-
return { changed: true, usedReadFallback: true };
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
workqueue.addPropertyAssignment({
|
|
134
|
-
name: ACTION_PROPERTY_NAME,
|
|
135
|
-
initializer: READ_ACTION_FALLBACK_INITIALIZER
|
|
136
|
-
});
|
|
137
|
-
// eslint-disable-next-line no-console
|
|
138
|
-
console.log(` [${relPath}] Added default 'action: ${READ_ACTION_FALLBACK_INITIALIZER}' to workqueue '${workqueueLabel}'`);
|
|
139
|
-
return { changed: true, usedReadFallback: true };
|
|
140
|
-
}
|
|
141
|
-
function migrateWorkqueueActions(workqueue, relPath) {
|
|
142
|
-
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
143
|
-
const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME);
|
|
144
|
-
let actionsArrayMigrated = false;
|
|
145
|
-
if (actionsProperty && ts_morph_1.Node.isPropertyAssignment(actionsProperty)) {
|
|
146
|
-
const actionsInitializer = actionsProperty.getInitializer();
|
|
147
|
-
if (actionsInitializer &&
|
|
148
|
-
ts_morph_1.Node.isArrayLiteralExpression(actionsInitializer)) {
|
|
149
|
-
const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME);
|
|
150
|
-
if (existingActionProperty) {
|
|
151
|
-
if (ts_morph_1.Node.isPropertyAssignment(existingActionProperty)) {
|
|
152
|
-
const existingActionInitializer = existingActionProperty.getInitializer();
|
|
153
|
-
if (existingActionInitializer &&
|
|
154
|
-
ts_morph_1.Node.isObjectLiteralExpression(existingActionInitializer)) {
|
|
155
|
-
const conditionalsProperty = existingActionInitializer.getProperty(CONDITIONALS_PROPERTY_NAME);
|
|
156
|
-
if (conditionalsProperty) {
|
|
157
|
-
conditionalsProperty.remove();
|
|
158
|
-
// eslint-disable-next-line no-console
|
|
159
|
-
console.log(` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
actionsProperty.remove();
|
|
164
|
-
// eslint-disable-next-line no-console
|
|
165
|
-
console.log(` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`);
|
|
166
|
-
actionsArrayMigrated = true;
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
const actionCandidates = actionsInitializer
|
|
170
|
-
.getElements()
|
|
171
|
-
.filter((element) => ts_morph_1.Node.isObjectLiteralExpression(element));
|
|
172
|
-
if (actionCandidates.length === 0) {
|
|
173
|
-
actionsProperty.remove();
|
|
174
|
-
// eslint-disable-next-line no-console
|
|
175
|
-
console.log(` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`);
|
|
176
|
-
actionsArrayMigrated = true;
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
if (actionCandidates.length > 1) {
|
|
180
|
-
const droppedCount = actionCandidates.length - 1;
|
|
181
|
-
// eslint-disable-next-line no-console
|
|
182
|
-
console.warn(` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`);
|
|
183
|
-
}
|
|
184
|
-
const conditionalsProperty = actionCandidates[0].getProperty(CONDITIONALS_PROPERTY_NAME);
|
|
185
|
-
if (conditionalsProperty) {
|
|
186
|
-
conditionalsProperty.remove();
|
|
187
|
-
// eslint-disable-next-line no-console
|
|
188
|
-
console.log(` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`);
|
|
189
|
-
}
|
|
190
|
-
if (isUnsupportedActionType(actionCandidates[0])) {
|
|
191
|
-
actionsProperty.remove();
|
|
192
|
-
// eslint-disable-next-line no-console
|
|
193
|
-
console.log(` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`);
|
|
194
|
-
actionsArrayMigrated = true;
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
const firstActionText = actionCandidates[0].getText();
|
|
198
|
-
workqueue.addPropertyAssignment({
|
|
199
|
-
name: ACTION_PROPERTY_NAME,
|
|
200
|
-
initializer: firstActionText
|
|
201
|
-
});
|
|
202
|
-
actionsProperty.remove();
|
|
203
|
-
// eslint-disable-next-line no-console
|
|
204
|
-
console.log(` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`);
|
|
205
|
-
actionsArrayMigrated = true;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
// Always ensure the workqueue ends up with a valid `action`. This both
|
|
212
|
-
// covers workqueues that never had an `actions` array, and patches up
|
|
213
|
-
// workqueues whose existing/migrated action type is unsupported.
|
|
214
|
-
const fallback = ensureValidAction(workqueue, relPath);
|
|
215
|
-
return {
|
|
216
|
-
changed: actionsArrayMigrated || fallback.changed,
|
|
217
|
-
usedReadFallback: fallback.usedReadFallback
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Ensures `import { ActionType } from '@opencrvs/toolkit/events'` exists in
|
|
222
|
-
* the source file, merging into any existing import declaration from the
|
|
223
|
-
* same module specifier.
|
|
224
|
-
*/
|
|
225
|
-
function ensureActionTypeImport(sourceFile) {
|
|
226
|
-
const existingImport = sourceFile.getImportDeclaration((decl) => decl.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE);
|
|
227
|
-
if (existingImport) {
|
|
228
|
-
const alreadyImported = existingImport
|
|
229
|
-
.getNamedImports()
|
|
230
|
-
.some((ni) => ni.getName() === ACTION_TYPE_IMPORT_NAME);
|
|
231
|
-
if (!alreadyImported) {
|
|
232
|
-
existingImport.addNamedImport(ACTION_TYPE_IMPORT_NAME);
|
|
233
|
-
}
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
sourceFile.addImportDeclaration({
|
|
237
|
-
moduleSpecifier: TOOLKIT_EVENTS_MODULE,
|
|
238
|
-
namedImports: [ACTION_TYPE_IMPORT_NAME]
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
function processFile(filePath, project) {
|
|
242
|
-
const sourceFile = project.getSourceFile(filePath);
|
|
243
|
-
if (!sourceFile)
|
|
244
|
-
return 0;
|
|
245
|
-
let migratedWorkqueues = 0;
|
|
246
|
-
let needsActionTypeImport = false;
|
|
247
|
-
const relPath = path_1.default.relative(process.cwd(), filePath);
|
|
248
|
-
const callExpressions = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
249
|
-
for (const call of callExpressions) {
|
|
250
|
-
const expression = call.getExpression();
|
|
251
|
-
if (!ts_morph_1.Node.isIdentifier(expression) ||
|
|
252
|
-
expression.getText() !== DEFINE_WORKQUEUES_NAME) {
|
|
253
|
-
continue;
|
|
254
|
-
}
|
|
255
|
-
const args = call.getArguments();
|
|
256
|
-
if (args.length === 0)
|
|
257
|
-
continue;
|
|
258
|
-
const workqueuesArg = args[0];
|
|
259
|
-
if (!ts_morph_1.Node.isArrayLiteralExpression(workqueuesArg))
|
|
260
|
-
continue;
|
|
261
|
-
for (const element of workqueuesArg.getElements()) {
|
|
262
|
-
if (!ts_morph_1.Node.isObjectLiteralExpression(element))
|
|
263
|
-
continue;
|
|
264
|
-
const result = migrateWorkqueueActions(element, relPath);
|
|
265
|
-
if (result.changed)
|
|
266
|
-
migratedWorkqueues++;
|
|
267
|
-
if (result.usedReadFallback)
|
|
268
|
-
needsActionTypeImport = true;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
if (needsActionTypeImport) {
|
|
272
|
-
ensureActionTypeImport(sourceFile);
|
|
273
|
-
}
|
|
274
|
-
return migratedWorkqueues;
|
|
275
|
-
}
|
|
276
|
-
function main() {
|
|
277
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
278
|
-
const srcDir = path_1.default.join(process.cwd(), 'src');
|
|
279
|
-
// eslint-disable-next-line no-console
|
|
280
|
-
console.log(`Scanning for defineWorkqueues calls in: ${srcDir}\n`);
|
|
281
|
-
const project = new ts_morph_1.Project({
|
|
282
|
-
tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
|
|
283
|
-
skipAddingFilesFromTsConfig: false
|
|
284
|
-
});
|
|
285
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
286
|
-
const fp = sf.getFilePath();
|
|
287
|
-
return fp.includes('/src/') && !fp.includes('/node_modules/');
|
|
288
|
-
});
|
|
289
|
-
// eslint-disable-next-line no-console
|
|
290
|
-
console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
|
|
291
|
-
let totalMigrated = 0;
|
|
292
|
-
const modifiedFiles = [];
|
|
293
|
-
for (const sourceFile of sourceFiles) {
|
|
294
|
-
const filePath = sourceFile.getFilePath();
|
|
295
|
-
const migrated = processFile(filePath, project);
|
|
296
|
-
if (migrated > 0) {
|
|
297
|
-
totalMigrated += migrated;
|
|
298
|
-
modifiedFiles.push(filePath);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
if (modifiedFiles.length === 0) {
|
|
302
|
-
// eslint-disable-next-line no-console
|
|
303
|
-
console.log("No deprecated workqueue 'actions' arrays found inside defineWorkqueues calls. Nothing to do.");
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
// eslint-disable-next-line no-console
|
|
307
|
-
console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
|
|
308
|
-
for (const filePath of modifiedFiles) {
|
|
309
|
-
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
310
|
-
yield sourceFile.save();
|
|
311
|
-
// eslint-disable-next-line no-console
|
|
312
|
-
console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
|
|
313
|
-
}
|
|
314
|
-
// eslint-disable-next-line no-console
|
|
315
|
-
console.log(`\nDone. Migrated ${totalMigrated} deprecated workqueue 'actions' definition(s) to 'action'.`);
|
|
316
|
-
});
|
|
317
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"remove-delete-actions.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/remove-delete-actions.ts"],"names":[],"mappings":"AAyIA,iBAAe,IAAI,kBAiDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -1,156 +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 `DELETE` type actions from the `actions` array inside `defineConfig` calls.
|
|
28
|
-
*
|
|
29
|
-
* Usage:
|
|
30
|
-
* ts-node -r tsconfig-paths/register src/migrations/v2.0/remove-delete-actions.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.DELETE` or the string literal `"DELETE"`
|
|
37
|
-
* - Removes those action objects entirely from the array
|
|
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 ACTION_TYPE_ENUM_NAME = 'ActionType';
|
|
46
|
-
const DELETE_MEMBER_NAME = 'DELETE';
|
|
47
|
-
const DELETE_STRING_LITERAL = 'DELETE';
|
|
48
|
-
function isDeleteType(typeInitializer) {
|
|
49
|
-
// Matches: ActionType.DELETE
|
|
50
|
-
if (typeInitializer.getKind() === ts_morph_1.SyntaxKind.PropertyAccessExpression) {
|
|
51
|
-
const propAccess = typeInitializer.asKindOrThrow(ts_morph_1.SyntaxKind.PropertyAccessExpression);
|
|
52
|
-
const obj = propAccess.getExpression();
|
|
53
|
-
const member = propAccess.getName();
|
|
54
|
-
return (ts_morph_1.Node.isIdentifier(obj) &&
|
|
55
|
-
obj.getText() === ACTION_TYPE_ENUM_NAME &&
|
|
56
|
-
member === DELETE_MEMBER_NAME);
|
|
57
|
-
}
|
|
58
|
-
// Matches: "DELETE"
|
|
59
|
-
if (typeInitializer.getKind() === ts_morph_1.SyntaxKind.StringLiteral) {
|
|
60
|
-
return (typeInitializer
|
|
61
|
-
.asKindOrThrow(ts_morph_1.SyntaxKind.StringLiteral)
|
|
62
|
-
.getLiteralValue() === DELETE_STRING_LITERAL);
|
|
63
|
-
}
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
function isDeleteAction(obj) {
|
|
67
|
-
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME);
|
|
68
|
-
if (!typeProperty || !ts_morph_1.Node.isPropertyAssignment(typeProperty)) {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
const typeInitializer = typeProperty.getInitializer();
|
|
72
|
-
return !!typeInitializer && isDeleteType(typeInitializer);
|
|
73
|
-
}
|
|
74
|
-
function processFile(filePath, project) {
|
|
75
|
-
const sourceFile = project.getSourceFile(filePath);
|
|
76
|
-
if (!sourceFile)
|
|
77
|
-
return 0;
|
|
78
|
-
let removedCount = 0;
|
|
79
|
-
// Find all call expressions named `defineConfig`
|
|
80
|
-
const callExpressions = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
81
|
-
for (const call of callExpressions) {
|
|
82
|
-
const expression = call.getExpression();
|
|
83
|
-
// Only interested in bare `defineConfig(...)` calls
|
|
84
|
-
if (!ts_morph_1.Node.isIdentifier(expression) ||
|
|
85
|
-
expression.getText() !== DEFINE_CONFIG_NAME) {
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
const args = call.getArguments();
|
|
89
|
-
if (args.length === 0)
|
|
90
|
-
continue;
|
|
91
|
-
// The first argument should be the config object literal
|
|
92
|
-
const configArg = args[0];
|
|
93
|
-
if (!ts_morph_1.Node.isObjectLiteralExpression(configArg))
|
|
94
|
-
continue;
|
|
95
|
-
// Find the `actions` property inside the config object
|
|
96
|
-
const actionsProperty = configArg.getProperty(ACTIONS_PROPERTY_NAME);
|
|
97
|
-
if (!actionsProperty || !ts_morph_1.Node.isPropertyAssignment(actionsProperty))
|
|
98
|
-
continue;
|
|
99
|
-
const actionsInitializer = actionsProperty.getInitializer();
|
|
100
|
-
if (!actionsInitializer ||
|
|
101
|
-
!ts_morph_1.Node.isArrayLiteralExpression(actionsInitializer))
|
|
102
|
-
continue;
|
|
103
|
-
// Collect indices of DELETE actions in reverse order so removal doesn't
|
|
104
|
-
// shift the indices of elements yet to be processed
|
|
105
|
-
const indicesToRemove = [];
|
|
106
|
-
actionsInitializer.getElements().forEach((element, index) => {
|
|
107
|
-
if (ts_morph_1.Node.isObjectLiteralExpression(element) && isDeleteAction(element)) {
|
|
108
|
-
indicesToRemove.push(index);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
for (const index of indicesToRemove.reverse()) {
|
|
112
|
-
actionsInitializer.removeElement(index);
|
|
113
|
-
removedCount++;
|
|
114
|
-
console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Removed DELETE action at index ${index}`);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return removedCount;
|
|
118
|
-
}
|
|
119
|
-
function main() {
|
|
120
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
-
const srcDir = path_1.default.join(process.cwd(), 'src');
|
|
122
|
-
console.log(`Scanning for defineConfig calls in: ${srcDir}\n`);
|
|
123
|
-
const project = new ts_morph_1.Project({
|
|
124
|
-
tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
|
|
125
|
-
// Do not emit — we only manipulate source files
|
|
126
|
-
skipAddingFilesFromTsConfig: false
|
|
127
|
-
});
|
|
128
|
-
// Restrict to source files only (exclude node_modules, build artefacts, etc.)
|
|
129
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
130
|
-
const fp = sf.getFilePath();
|
|
131
|
-
return fp.includes('/src/') && !fp.includes('/node_modules/');
|
|
132
|
-
});
|
|
133
|
-
console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
|
|
134
|
-
let totalRemoved = 0;
|
|
135
|
-
const modifiedFiles = [];
|
|
136
|
-
for (const sourceFile of sourceFiles) {
|
|
137
|
-
const filePath = sourceFile.getFilePath();
|
|
138
|
-
const removed = processFile(filePath, project);
|
|
139
|
-
if (removed > 0) {
|
|
140
|
-
totalRemoved += removed;
|
|
141
|
-
modifiedFiles.push(filePath);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
if (modifiedFiles.length === 0) {
|
|
145
|
-
console.log('No DELETE actions found inside defineConfig calls. Nothing to do.');
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
|
|
149
|
-
for (const filePath of modifiedFiles) {
|
|
150
|
-
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
151
|
-
yield sourceFile.save();
|
|
152
|
-
console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
|
|
153
|
-
}
|
|
154
|
-
console.log(`\nDone. Removed ${totalRemoved} DELETE action(s) from defineConfig call(s).`);
|
|
155
|
-
});
|
|
156
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"remove-demo-scope.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/remove-demo-scope.ts"],"names":[],"mappings":"AAeA,iBAAe,IAAI,kBA8DlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -1,74 +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
|
-
const path_1 = __importDefault(require("path"));
|
|
27
|
-
const ts_morph_1 = require("ts-morph");
|
|
28
|
-
const ROLES_HANDLER_RELATIVE_PATH = 'src/data-seeding/roles/handler.ts';
|
|
29
|
-
function main() {
|
|
30
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
var _a;
|
|
32
|
-
const rolesHandlerPath = path_1.default.join(process.cwd(), ROLES_HANDLER_RELATIVE_PATH);
|
|
33
|
-
const project = new ts_morph_1.Project({
|
|
34
|
-
tsConfigFilePath: path_1.default.resolve(process.cwd(), 'tsconfig.json'),
|
|
35
|
-
skipAddingFilesFromTsConfig: false
|
|
36
|
-
});
|
|
37
|
-
const sourceFile = project.getSourceFile(rolesHandlerPath);
|
|
38
|
-
if (!sourceFile) {
|
|
39
|
-
// eslint-disable-next-line no-console
|
|
40
|
-
console.log(`No roles handler found at '${ROLES_HANDLER_RELATIVE_PATH}'. Nothing to do.`);
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
let changed = false;
|
|
44
|
-
const constantsImport = sourceFile.getImportDeclaration((decl) => decl.getModuleSpecifierValue() === '@countryconfig/constants');
|
|
45
|
-
if (constantsImport) {
|
|
46
|
-
constantsImport.remove();
|
|
47
|
-
changed = true;
|
|
48
|
-
}
|
|
49
|
-
const rolesHandler = sourceFile.getFunction('rolesHandler');
|
|
50
|
-
if (!rolesHandler) {
|
|
51
|
-
// eslint-disable-next-line no-console
|
|
52
|
-
console.log(`No rolesHandler export found in '${ROLES_HANDLER_RELATIVE_PATH}'. Nothing to do.`);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
const secondParam = rolesHandler.getParameters()[1];
|
|
56
|
-
const secondParamName = secondParam === null || secondParam === void 0 ? void 0 : secondParam.getName();
|
|
57
|
-
const responseToolkitIdentifier = secondParamName || 'h';
|
|
58
|
-
const currentBodyText = rolesHandler.getBodyText();
|
|
59
|
-
const normalizedCurrent = (_a = currentBodyText === null || currentBodyText === void 0 ? void 0 : currentBodyText.replace(/\s+/g, ' ').trim()) !== null && _a !== void 0 ? _a : '';
|
|
60
|
-
const normalizedDesired = `return ${responseToolkitIdentifier}.response(roles)`;
|
|
61
|
-
if (normalizedCurrent !== normalizedDesired) {
|
|
62
|
-
rolesHandler.setBodyText(`return ${responseToolkitIdentifier}.response(roles)`);
|
|
63
|
-
changed = true;
|
|
64
|
-
}
|
|
65
|
-
if (!changed) {
|
|
66
|
-
// eslint-disable-next-line no-console
|
|
67
|
-
console.log(`No changes needed in '${ROLES_HANDLER_RELATIVE_PATH}'.`);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
yield sourceFile.save();
|
|
71
|
-
// eslint-disable-next-line no-console
|
|
72
|
-
console.log(`Updated '${ROLES_HANDLER_RELATIVE_PATH}' to remove demo scope behavior while preserving file structure.`);
|
|
73
|
-
});
|
|
74
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"remove-deprecated-imports.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/remove-deprecated-imports.ts"],"names":[],"mappings":"AAyDA,iBAAe,IAAI,kBAyClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -1,96 +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
|
-
const ts_morph_1 = require("ts-morph");
|
|
27
|
-
const path_1 = __importDefault(require("path"));
|
|
28
|
-
const DEPRECATED_IMPORT = 'SCOPES';
|
|
29
|
-
const TARGET_MODULES = new Set([
|
|
30
|
-
'@opencrvs/toolkit/scopes',
|
|
31
|
-
'@opencrvs/toolkit'
|
|
32
|
-
]);
|
|
33
|
-
function processFile(filePath, project) {
|
|
34
|
-
const sourceFile = project.getSourceFile(filePath);
|
|
35
|
-
if (!sourceFile)
|
|
36
|
-
return 0;
|
|
37
|
-
let removedCount = 0;
|
|
38
|
-
const importDecls = sourceFile
|
|
39
|
-
.getImportDeclarations()
|
|
40
|
-
.filter((decl) => TARGET_MODULES.has(decl.getModuleSpecifierValue()));
|
|
41
|
-
for (const decl of importDecls) {
|
|
42
|
-
const matchingNamedImports = decl
|
|
43
|
-
.getNamedImports()
|
|
44
|
-
.filter((ni) => ni.getName() === DEPRECATED_IMPORT);
|
|
45
|
-
if (matchingNamedImports.length === 0)
|
|
46
|
-
continue;
|
|
47
|
-
for (const namedImport of matchingNamedImports) {
|
|
48
|
-
namedImport.remove();
|
|
49
|
-
removedCount++;
|
|
50
|
-
}
|
|
51
|
-
const hasAnyNamedImportsLeft = decl.getNamedImports().length > 0;
|
|
52
|
-
const hasDefaultImport = !!decl.getDefaultImport();
|
|
53
|
-
const hasNamespaceImport = !!decl.getNamespaceImport();
|
|
54
|
-
// If the declaration only contained SCOPE, remove the now-empty import line.
|
|
55
|
-
if (!hasAnyNamedImportsLeft && !hasDefaultImport && !hasNamespaceImport) {
|
|
56
|
-
decl.remove();
|
|
57
|
-
}
|
|
58
|
-
console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Removed ${matchingNamedImports.length} deprecated '${DEPRECATED_IMPORT}' import(s) from '${decl.getModuleSpecifierValue()}'`);
|
|
59
|
-
}
|
|
60
|
-
return removedCount;
|
|
61
|
-
}
|
|
62
|
-
function main() {
|
|
63
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
-
const srcDir = path_1.default.join(process.cwd(), 'src');
|
|
65
|
-
console.log(`Scanning for deprecated imports in: ${srcDir}\n`);
|
|
66
|
-
const project = new ts_morph_1.Project({
|
|
67
|
-
tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
|
|
68
|
-
skipAddingFilesFromTsConfig: false
|
|
69
|
-
});
|
|
70
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
71
|
-
const fp = sf.getFilePath();
|
|
72
|
-
return fp.includes('/src/') && !fp.includes('/node_modules/');
|
|
73
|
-
});
|
|
74
|
-
console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
|
|
75
|
-
let totalRemoved = 0;
|
|
76
|
-
const modifiedFiles = [];
|
|
77
|
-
for (const sourceFile of sourceFiles) {
|
|
78
|
-
const filePath = sourceFile.getFilePath();
|
|
79
|
-
const removed = processFile(filePath, project);
|
|
80
|
-
if (removed > 0) {
|
|
81
|
-
totalRemoved += removed;
|
|
82
|
-
modifiedFiles.push(filePath);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (modifiedFiles.length === 0) {
|
|
86
|
-
console.log('No deprecated imports found. Nothing to do.');
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
|
|
90
|
-
for (const filePath of modifiedFiles) {
|
|
91
|
-
yield project.getSourceFileOrThrow(filePath).save();
|
|
92
|
-
console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
|
|
93
|
-
}
|
|
94
|
-
console.log(`\nDone. Removed ${totalRemoved} deprecated import(s).`);
|
|
95
|
-
});
|
|
96
|
-
}
|