@opencrvs/toolkit 2.1.0-rc.d1b9774 → 2.1.0-rc.d235243
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/README.md +2 -12
- package/build.sh +15 -5
- package/create-countryconfig/index.js +164 -4
- package/dist/application-config/index.js +36 -25
- package/dist/authentication/index.d.ts +8 -9
- package/dist/authentication/index.js +23 -8
- package/dist/cli.js +1981 -2823
- 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 +19 -4
- 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 +26 -15
- 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/locations.d.ts +4 -0
- package/dist/commons/events/scopes.d.ts +21 -1
- package/dist/commons/events/test.utils.d.ts +71 -22
- package/dist/commons/events/utils.d.ts +37 -2
- package/dist/conditionals/index.js +21 -7
- package/dist/environment/derived-variables.d.ts +18 -0
- package/dist/environment/derived-variables.d.ts.map +1 -1
- package/dist/environment/derived-variables.js +21 -0
- package/dist/environment/index.d.ts.map +1 -1
- package/dist/environment/index.js +2 -1
- package/dist/environment/manage-users.js +1 -1
- package/dist/environment/questions.d.ts +16 -0
- package/dist/environment/questions.d.ts.map +1 -1
- package/dist/environment/questions.js +27 -2
- 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 +633 -560
- package/dist/environment/swarm-to-k8s.js +3 -4
- package/dist/environment/templates.d.ts +0 -1
- package/dist/environment/templates.d.ts.map +1 -1
- package/dist/environment/templates.js +3 -8
- package/dist/environment/update-workflows.d.ts.map +1 -1
- package/dist/environment/update-workflows.js +6 -1
- package/dist/environment/utils.d.ts +0 -12
- package/dist/environment/utils.d.ts.map +1 -1
- package/dist/environment/utils.js +1 -28
- package/dist/events/index.js +2115 -1884
- 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 +35 -1261
- 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/migrations/v2.2/add-e2e-tests.d.ts +19 -0
- package/dist/migrations/v2.2/add-e2e-tests.d.ts.map +1 -0
- package/dist/migrations/v2.2/add-e2e-tests.js +143 -0
- package/dist/migrations/v2.2/index.d.ts +6 -0
- package/dist/migrations/v2.2/index.d.ts.map +1 -0
- package/dist/migrations/v2.2/index.js +279 -0
- package/dist/migrations/v2.2/template-files.d.ts +8 -0
- package/dist/migrations/v2.2/template-files.d.ts.map +1 -0
- package/dist/migrations/v2.2/template-files.js +49 -0
- package/dist/migrations/v2.2/upgrade-tilt.d.ts +8 -0
- package/dist/migrations/v2.2/upgrade-tilt.d.ts.map +1 -0
- package/dist/migrations/v2.2/upgrade-tilt.js +139 -0
- package/dist/notification/index.js +249 -207
- 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 +8 -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/charts-values/traefik/values.yaml +2 -3
- 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/e2e/README.md +36 -0
- package/dist/templates/countryconfig-template/e2e/constants.ts +28 -0
- package/dist/templates/countryconfig-template/e2e/login.e2e.ts +59 -0
- package/dist/templates/countryconfig-template/package.json +153 -0
- package/dist/templates/countryconfig-template/playwright.config.ts +42 -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 +159 -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 +180 -15
- package/opencrvs-toolkit-2.1.0-rc.d235243.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 -19
- package/dist/translations/check.d.ts.map +0 -1
- package/dist/translations/check.js +0 -127
- package/opencrvs-toolkit-2.1.0-rc.d1b9774.tgz +0 -0
|
@@ -1,305 +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 scopes_deprecated_do_not_use_1 = require("../commons/scopes.deprecated.do-not-use");
|
|
29
|
-
const ROLES_FILE_RELATIVE_PATH = 'src/data-seeding/roles/roles.ts';
|
|
30
|
-
const SCOPES_PROPERTY_NAME = 'scopes';
|
|
31
|
-
const TOOLKIT_SCOPES_MODULE = '@opencrvs/toolkit/scopes';
|
|
32
|
-
const DEFINE_SCOPES_IMPORT_NAME = 'defineScopes';
|
|
33
|
-
const DEFINE_ROLES_IMPORT_NAME = 'defineRoles';
|
|
34
|
-
function resolveScopeKeyFromElementAccess(element) {
|
|
35
|
-
if (ts_morph_1.Node.isPropertyAccessExpression(element) &&
|
|
36
|
-
element.getExpression().getText() === 'SCOPES') {
|
|
37
|
-
return element.getName();
|
|
38
|
-
}
|
|
39
|
-
if (ts_morph_1.Node.isElementAccessExpression(element) &&
|
|
40
|
-
element.getExpression().getText() === 'SCOPES') {
|
|
41
|
-
const argumentExpression = element.getArgumentExpression();
|
|
42
|
-
if (argumentExpression &&
|
|
43
|
-
(ts_morph_1.Node.isStringLiteral(argumentExpression) ||
|
|
44
|
-
ts_morph_1.Node.isNoSubstitutionTemplateLiteral(argumentExpression))) {
|
|
45
|
-
return argumentExpression.getLiteralValue();
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
function resolveLegacyScopeFromElement(element) {
|
|
51
|
-
if (ts_morph_1.Node.isStringLiteral(element) ||
|
|
52
|
-
ts_morph_1.Node.isNoSubstitutionTemplateLiteral(element)) {
|
|
53
|
-
return element.getLiteralValue();
|
|
54
|
-
}
|
|
55
|
-
const scopeKey = resolveScopeKeyFromElementAccess(element);
|
|
56
|
-
if (scopeKey) {
|
|
57
|
-
const scopeValue = scopes_deprecated_do_not_use_1.SCOPES[scopeKey];
|
|
58
|
-
return typeof scopeValue === 'string' ? scopeValue : null;
|
|
59
|
-
}
|
|
60
|
-
const expressionType = element.getType();
|
|
61
|
-
if (expressionType.isStringLiteral()) {
|
|
62
|
-
const literalValue = expressionType.getLiteralValue();
|
|
63
|
-
return typeof literalValue === 'string' ? literalValue : null;
|
|
64
|
-
}
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Walks each `scopes: [...]` array in the roles file, classifies elements,
|
|
69
|
-
* and rewrites the whole array using `migrateLegacyScopesArrayToV2Scopes`
|
|
70
|
-
* (which preserves v1.9 AND semantics by merging pairs of legacy scopes
|
|
71
|
-
* that targeted the same v2 type). See issue #12489.
|
|
72
|
-
*
|
|
73
|
-
* Elements are partitioned into three kinds:
|
|
74
|
-
* - drop: `SCOPES.X` references where X is not in the SCOPES map (warned
|
|
75
|
-
* and removed, matching pre-refactor behavior).
|
|
76
|
-
* - raw: non-literal expressions we cannot statically resolve (e.g.
|
|
77
|
-
* `...sharedScopes` spreads). Preserved verbatim in output so authoring
|
|
78
|
-
* intent isn't lost.
|
|
79
|
-
* - legacy: literal strings or resolvable `SCOPES.X` references.
|
|
80
|
-
* Collected and passed as a batch to the merge function.
|
|
81
|
-
*
|
|
82
|
-
* The output array text is `[...rawTexts, ...mergedScopesAsJson]`. Order of
|
|
83
|
-
* legacy entries relative to raw expressions is not preserved — scopes in a
|
|
84
|
-
* v2 array compose with OR, so position is semantically irrelevant.
|
|
85
|
-
*/
|
|
86
|
-
function migrateScopesArrays(rolesFilePath, project) {
|
|
87
|
-
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
88
|
-
if (!sourceFile) {
|
|
89
|
-
return { migratedCount: 0, removedCount: 0, mergedCount: 0 };
|
|
90
|
-
}
|
|
91
|
-
let migratedCount = 0;
|
|
92
|
-
let removedCount = 0;
|
|
93
|
-
let mergedCount = 0;
|
|
94
|
-
const scopesProperties = sourceFile
|
|
95
|
-
.getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertyAssignment)
|
|
96
|
-
.filter((prop) => prop.getName() === SCOPES_PROPERTY_NAME);
|
|
97
|
-
const relPath = path_1.default.relative(process.cwd(), rolesFilePath);
|
|
98
|
-
for (const scopesProp of scopesProperties) {
|
|
99
|
-
const initializer = scopesProp.getInitializer();
|
|
100
|
-
if (!initializer || !ts_morph_1.Node.isArrayLiteralExpression(initializer))
|
|
101
|
-
continue;
|
|
102
|
-
const rawTexts = [];
|
|
103
|
-
const legacyStrings = [];
|
|
104
|
-
let anyChange = false;
|
|
105
|
-
for (const element of initializer.getElements()) {
|
|
106
|
-
const scopeKey = resolveScopeKeyFromElementAccess(element);
|
|
107
|
-
if (scopeKey && !(scopeKey in scopes_deprecated_do_not_use_1.SCOPES)) {
|
|
108
|
-
// eslint-disable-next-line no-console
|
|
109
|
-
console.warn(` [${relPath}] Removing unknown scope reference: SCOPES.${scopeKey}`);
|
|
110
|
-
removedCount++;
|
|
111
|
-
anyChange = true;
|
|
112
|
-
continue;
|
|
113
|
-
}
|
|
114
|
-
const legacyScope = resolveLegacyScopeFromElement(element);
|
|
115
|
-
if (!legacyScope) {
|
|
116
|
-
// eslint-disable-next-line no-console
|
|
117
|
-
console.warn(` [${relPath}] Preserving non-literal scope expression verbatim: ${element.getText()}`);
|
|
118
|
-
rawTexts.push(element.getText());
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
legacyStrings.push(legacyScope);
|
|
122
|
-
anyChange = true;
|
|
123
|
-
}
|
|
124
|
-
if (!anyChange)
|
|
125
|
-
continue;
|
|
126
|
-
let mergedScopes;
|
|
127
|
-
try {
|
|
128
|
-
mergedScopes = (0, scopes_deprecated_do_not_use_1.migrateLegacyScopesArrayToV2Scopes)(legacyStrings);
|
|
129
|
-
}
|
|
130
|
-
catch (error) {
|
|
131
|
-
throw new Error(`[${relPath}] Failed to migrate scopes for role: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
132
|
-
}
|
|
133
|
-
migratedCount += legacyStrings.length;
|
|
134
|
-
mergedCount += legacyStrings.length - mergedScopes.length;
|
|
135
|
-
const outputElements = [
|
|
136
|
-
...rawTexts,
|
|
137
|
-
...mergedScopes.map((s) => JSON.stringify(s))
|
|
138
|
-
];
|
|
139
|
-
scopesProp.setInitializer(`[${outputElements.join(', ')}]`);
|
|
140
|
-
}
|
|
141
|
-
if (removedCount > 0) {
|
|
142
|
-
// eslint-disable-next-line no-console
|
|
143
|
-
console.log(` Removed ${removedCount} unknown SCOPES reference(s) from '${relPath}'.`);
|
|
144
|
-
}
|
|
145
|
-
return { migratedCount, removedCount, mergedCount };
|
|
146
|
-
}
|
|
147
|
-
function ensureScopesHelpersImport(rolesFilePath, project) {
|
|
148
|
-
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
149
|
-
if (!sourceFile)
|
|
150
|
-
return false;
|
|
151
|
-
const existingImport = sourceFile.getImportDeclaration((decl) => decl.getModuleSpecifierValue() === TOOLKIT_SCOPES_MODULE);
|
|
152
|
-
let changed = false;
|
|
153
|
-
if (existingImport) {
|
|
154
|
-
const hasDefineScopesImport = existingImport
|
|
155
|
-
.getNamedImports()
|
|
156
|
-
.some((ni) => ni.getName() === DEFINE_SCOPES_IMPORT_NAME);
|
|
157
|
-
const hasDefineRolesImport = existingImport
|
|
158
|
-
.getNamedImports()
|
|
159
|
-
.some((ni) => ni.getName() === DEFINE_ROLES_IMPORT_NAME);
|
|
160
|
-
if (!hasDefineScopesImport) {
|
|
161
|
-
existingImport.addNamedImport(DEFINE_SCOPES_IMPORT_NAME);
|
|
162
|
-
changed = true;
|
|
163
|
-
}
|
|
164
|
-
if (!hasDefineRolesImport) {
|
|
165
|
-
existingImport.addNamedImport(DEFINE_ROLES_IMPORT_NAME);
|
|
166
|
-
changed = true;
|
|
167
|
-
}
|
|
168
|
-
const encodeScopeImport = existingImport
|
|
169
|
-
.getNamedImports()
|
|
170
|
-
.find((ni) => ni.getName() === 'encodeScope');
|
|
171
|
-
if (encodeScopeImport) {
|
|
172
|
-
encodeScopeImport.remove();
|
|
173
|
-
changed = true;
|
|
174
|
-
}
|
|
175
|
-
return changed;
|
|
176
|
-
}
|
|
177
|
-
sourceFile.addImportDeclaration({
|
|
178
|
-
moduleSpecifier: TOOLKIT_SCOPES_MODULE,
|
|
179
|
-
namedImports: [DEFINE_SCOPES_IMPORT_NAME, DEFINE_ROLES_IMPORT_NAME]
|
|
180
|
-
});
|
|
181
|
-
return true;
|
|
182
|
-
}
|
|
183
|
-
function wrapScopesArraysWithDefineScopes(rolesFilePath, project) {
|
|
184
|
-
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
185
|
-
if (!sourceFile)
|
|
186
|
-
return 0;
|
|
187
|
-
let wrappedCount = 0;
|
|
188
|
-
const scopesProperties = sourceFile
|
|
189
|
-
.getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertyAssignment)
|
|
190
|
-
.filter((prop) => prop.getName() === SCOPES_PROPERTY_NAME);
|
|
191
|
-
for (const scopesProp of scopesProperties) {
|
|
192
|
-
const initializer = scopesProp.getInitializer();
|
|
193
|
-
if (!initializer)
|
|
194
|
-
continue;
|
|
195
|
-
if (ts_morph_1.Node.isCallExpression(initializer) &&
|
|
196
|
-
initializer.getExpression().getText() === DEFINE_SCOPES_IMPORT_NAME) {
|
|
197
|
-
continue;
|
|
198
|
-
}
|
|
199
|
-
if (!ts_morph_1.Node.isArrayLiteralExpression(initializer))
|
|
200
|
-
continue;
|
|
201
|
-
scopesProp.setInitializer(`${DEFINE_SCOPES_IMPORT_NAME}(${initializer.getText()})`);
|
|
202
|
-
wrappedCount++;
|
|
203
|
-
}
|
|
204
|
-
return wrappedCount;
|
|
205
|
-
}
|
|
206
|
-
function wrapRolesWithDefineRoles(rolesFilePath, project) {
|
|
207
|
-
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
208
|
-
if (!sourceFile)
|
|
209
|
-
return false;
|
|
210
|
-
const rolesDeclaration = sourceFile.getVariableDeclaration('roles');
|
|
211
|
-
if (!rolesDeclaration)
|
|
212
|
-
return false;
|
|
213
|
-
const initializer = rolesDeclaration.getInitializer();
|
|
214
|
-
if (!initializer)
|
|
215
|
-
return false;
|
|
216
|
-
if (ts_morph_1.Node.isCallExpression(initializer) &&
|
|
217
|
-
initializer.getExpression().getText() === DEFINE_ROLES_IMPORT_NAME) {
|
|
218
|
-
return false;
|
|
219
|
-
}
|
|
220
|
-
if (!ts_morph_1.Node.isArrayLiteralExpression(initializer))
|
|
221
|
-
return false;
|
|
222
|
-
const typeNode = rolesDeclaration.getTypeNode();
|
|
223
|
-
if (typeNode === null || typeNode === void 0 ? void 0 : typeNode.getText().includes('Role')) {
|
|
224
|
-
rolesDeclaration.removeType();
|
|
225
|
-
}
|
|
226
|
-
rolesDeclaration.setInitializer(`${DEFINE_ROLES_IMPORT_NAME}(${initializer.getText()})`);
|
|
227
|
-
return true;
|
|
228
|
-
}
|
|
229
|
-
function pruneNamedImportIfUnused(sourceFile, moduleSpecifier, importName) {
|
|
230
|
-
const importDeclaration = sourceFile.getImportDeclaration((decl) => decl.getModuleSpecifierValue() === moduleSpecifier);
|
|
231
|
-
if (!importDeclaration)
|
|
232
|
-
return false;
|
|
233
|
-
const namedImport = importDeclaration
|
|
234
|
-
.getNamedImports()
|
|
235
|
-
.find((ni) => ni.getName() === importName);
|
|
236
|
-
if (!namedImport)
|
|
237
|
-
return false;
|
|
238
|
-
const references = sourceFile
|
|
239
|
-
.getDescendantsOfKind(ts_morph_1.SyntaxKind.Identifier)
|
|
240
|
-
.filter((identifier) => identifier.getText() === importName &&
|
|
241
|
-
!ts_morph_1.Node.isImportSpecifier(identifier.getParent()));
|
|
242
|
-
if (references.length > 0) {
|
|
243
|
-
return false;
|
|
244
|
-
}
|
|
245
|
-
namedImport.remove();
|
|
246
|
-
if (importDeclaration.getNamedImports().length === 0 &&
|
|
247
|
-
!importDeclaration.getDefaultImport() &&
|
|
248
|
-
!importDeclaration.getNamespaceImport()) {
|
|
249
|
-
importDeclaration.remove();
|
|
250
|
-
}
|
|
251
|
-
return true;
|
|
252
|
-
}
|
|
253
|
-
function removeRoleTypeDefinitionAndUnusedImports(rolesFilePath, project) {
|
|
254
|
-
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
255
|
-
if (!sourceFile)
|
|
256
|
-
return false;
|
|
257
|
-
let removed = false;
|
|
258
|
-
const roleTypeAlias = sourceFile.getTypeAlias('Role');
|
|
259
|
-
if (roleTypeAlias) {
|
|
260
|
-
roleTypeAlias.remove();
|
|
261
|
-
removed = true;
|
|
262
|
-
}
|
|
263
|
-
const roleInterface = sourceFile.getInterface('Role');
|
|
264
|
-
if (roleInterface) {
|
|
265
|
-
roleInterface.remove();
|
|
266
|
-
removed = true;
|
|
267
|
-
}
|
|
268
|
-
const removedScopeImport = pruneNamedImportIfUnused(sourceFile, TOOLKIT_SCOPES_MODULE, 'Scope');
|
|
269
|
-
const removedMessageDescriptorImport = pruneNamedImportIfUnused(sourceFile, 'react-intl', 'MessageDescriptor');
|
|
270
|
-
removed = removed || removedScopeImport || removedMessageDescriptorImport;
|
|
271
|
-
return removed;
|
|
272
|
-
}
|
|
273
|
-
function main() {
|
|
274
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
275
|
-
const cwd = process.cwd();
|
|
276
|
-
const srcDir = path_1.default.join(cwd, 'src');
|
|
277
|
-
const rolesFilePath = path_1.default.join(cwd, ROLES_FILE_RELATIVE_PATH);
|
|
278
|
-
console.log(`Scanning roles scopes in: ${rolesFilePath}`);
|
|
279
|
-
const project = new ts_morph_1.Project({
|
|
280
|
-
tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
|
|
281
|
-
skipAddingFilesFromTsConfig: false
|
|
282
|
-
});
|
|
283
|
-
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
284
|
-
if (!sourceFile) {
|
|
285
|
-
console.log(`No roles file found at '${ROLES_FILE_RELATIVE_PATH}'. Nothing to do.`);
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
const importChanged = ensureScopesHelpersImport(rolesFilePath, project);
|
|
289
|
-
const { migratedCount, removedCount, mergedCount } = migrateScopesArrays(rolesFilePath, project);
|
|
290
|
-
const wrappedScopesCount = wrapScopesArraysWithDefineScopes(rolesFilePath, project);
|
|
291
|
-
const wrappedRoles = wrapRolesWithDefineRoles(rolesFilePath, project);
|
|
292
|
-
const removedRoleType = removeRoleTypeDefinitionAndUnusedImports(rolesFilePath, project);
|
|
293
|
-
if (migratedCount === 0 &&
|
|
294
|
-
removedCount === 0 &&
|
|
295
|
-
wrappedScopesCount === 0 &&
|
|
296
|
-
!wrappedRoles &&
|
|
297
|
-
!removedRoleType &&
|
|
298
|
-
!importChanged) {
|
|
299
|
-
console.log('No migratable literal scopes found. Nothing to do.');
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
302
|
-
yield sourceFile.save();
|
|
303
|
-
console.log(`Done. Migrated ${migratedCount} legacy scope(s), merged ${mergedCount} AND-paired scope(s) into single v2 objects (privilege-escalation fix, see issue #12489), removed ${removedCount} unknown SCOPES reference(s), wrapped ${wrappedScopesCount} scope array(s) with defineScopes()${wrappedRoles ? ', wrapped roles with defineRoles()' : ''}${removedRoleType ? ', and removed Role type definition' : ''}${importChanged ? '. Updated toolkit/scopes imports.' : '.'}`);
|
|
304
|
-
});
|
|
305
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"migrate-validated-workqueue-status-to-flag.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/migrate-validated-workqueue-status-to-flag.ts"],"names":[],"mappings":"AAyQA,iBAAe,IAAI,kBA+ClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -1,267 +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 `VALIDATED` status references to flags inside `defineWorkqueues` calls.
|
|
28
|
-
*
|
|
29
|
-
* Usage:
|
|
30
|
-
* ts-node -r tsconfig-paths/register src/migrations/v2.0/migrate-validated-workqueue-status-to-flag.ts
|
|
31
|
-
*
|
|
32
|
-
* What it does:
|
|
33
|
-
* - Scans all TypeScript files under `src/`
|
|
34
|
-
* - Finds every `defineWorkqueues([...])` call expression
|
|
35
|
-
* - For each workqueue config's `query`, recursively walks `or`/`and` containers
|
|
36
|
-
* and processes every leaf clause object
|
|
37
|
-
* - In each clause:
|
|
38
|
-
* - `status: { type: 'anyOf', terms: [..., 'VALIDATED', ...] }`
|
|
39
|
-
* → removes `'VALIDATED'` from `terms`; removes `status` entirely if `terms`
|
|
40
|
-
* becomes empty; adds `'validated'` to `flags.anyOf`
|
|
41
|
-
* - `status: { type: 'exact', term: 'VALIDATED' }`
|
|
42
|
-
* → removes `status` entirely; adds `'validated'` to `flags.anyOf`
|
|
43
|
-
* - When adding to `flags.anyOf`, merges with an existing `flags` object if present
|
|
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 DEFINE_WORKQUEUES_NAME = 'defineWorkqueues';
|
|
49
|
-
const QUERY_PROPERTY_NAME = 'query';
|
|
50
|
-
const TYPE_PROPERTY_NAME = 'type';
|
|
51
|
-
const CLAUSES_PROPERTY_NAME = 'clauses';
|
|
52
|
-
const STATUS_PROPERTY_NAME = 'status';
|
|
53
|
-
const FLAGS_PROPERTY_NAME = 'flags';
|
|
54
|
-
const TERMS_PROPERTY_NAME = 'terms';
|
|
55
|
-
const TERM_PROPERTY_NAME = 'term';
|
|
56
|
-
const ANY_OF_PROPERTY_NAME = 'anyOf';
|
|
57
|
-
const VALIDATED_STATUS_VALUE = 'VALIDATED';
|
|
58
|
-
const VALIDATED_FLAG_VALUE = 'validated';
|
|
59
|
-
// ─── Helpers ─────────────────────────────────────────────────────────────────
|
|
60
|
-
/**
|
|
61
|
-
* Adds `'validated'` to `flags.anyOf` on a clause object, merging with
|
|
62
|
-
* whatever `flags` shape already exists.
|
|
63
|
-
*/
|
|
64
|
-
function addValidatedFlag(clause) {
|
|
65
|
-
const flagsProperty = clause.getProperty(FLAGS_PROPERTY_NAME);
|
|
66
|
-
if (flagsProperty && ts_morph_1.Node.isPropertyAssignment(flagsProperty)) {
|
|
67
|
-
const flagsInit = flagsProperty.getInitializer();
|
|
68
|
-
if (flagsInit && ts_morph_1.Node.isObjectLiteralExpression(flagsInit)) {
|
|
69
|
-
const anyOfProperty = flagsInit.getProperty(ANY_OF_PROPERTY_NAME);
|
|
70
|
-
if (anyOfProperty && ts_morph_1.Node.isPropertyAssignment(anyOfProperty)) {
|
|
71
|
-
// Append to existing anyOf array
|
|
72
|
-
const anyOfInit = anyOfProperty.getInitializer();
|
|
73
|
-
if (anyOfInit && ts_morph_1.Node.isArrayLiteralExpression(anyOfInit)) {
|
|
74
|
-
anyOfInit.addElement(`'${VALIDATED_FLAG_VALUE}'`);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
// flags exists but has no anyOf — add it
|
|
79
|
-
flagsInit.addPropertyAssignment({
|
|
80
|
-
name: ANY_OF_PROPERTY_NAME,
|
|
81
|
-
initializer: `['${VALIDATED_FLAG_VALUE}']`
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
// No flags property at all — add one
|
|
88
|
-
clause.addPropertyAssignment({
|
|
89
|
-
name: FLAGS_PROPERTY_NAME,
|
|
90
|
-
initializer: `{ ${ANY_OF_PROPERTY_NAME}: ['${VALIDATED_FLAG_VALUE}'] }`
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Processes a single leaf clause object.
|
|
96
|
-
* Returns true if any change was made.
|
|
97
|
-
*/
|
|
98
|
-
function migrateClause(clause) {
|
|
99
|
-
const statusProperty = clause.getProperty(STATUS_PROPERTY_NAME);
|
|
100
|
-
if (!statusProperty || !ts_morph_1.Node.isPropertyAssignment(statusProperty)) {
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
const statusInit = statusProperty.getInitializer();
|
|
104
|
-
if (!statusInit || !ts_morph_1.Node.isObjectLiteralExpression(statusInit)) {
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
const statusTypeProperty = statusInit.getProperty(TYPE_PROPERTY_NAME);
|
|
108
|
-
if (!statusTypeProperty || !ts_morph_1.Node.isPropertyAssignment(statusTypeProperty)) {
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
const statusTypeInit = statusTypeProperty.getInitializer();
|
|
112
|
-
if (!statusTypeInit || !ts_morph_1.Node.isStringLiteral(statusTypeInit)) {
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
const statusType = statusTypeInit.getLiteralValue();
|
|
116
|
-
// ── anyOf case ──────────────────────────────────────────────────────────────
|
|
117
|
-
if (statusType === 'anyOf') {
|
|
118
|
-
const termsProperty = statusInit.getProperty(TERMS_PROPERTY_NAME);
|
|
119
|
-
if (!termsProperty || !ts_morph_1.Node.isPropertyAssignment(termsProperty)) {
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
const termsInit = termsProperty.getInitializer();
|
|
123
|
-
if (!termsInit || !ts_morph_1.Node.isArrayLiteralExpression(termsInit)) {
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
const elements = termsInit.getElements();
|
|
127
|
-
const validatedIndex = elements.findIndex((el) => ts_morph_1.Node.isStringLiteral(el) &&
|
|
128
|
-
el.getLiteralValue() === VALIDATED_STATUS_VALUE);
|
|
129
|
-
if (validatedIndex === -1)
|
|
130
|
-
return false;
|
|
131
|
-
// Remove 'VALIDATED' from terms
|
|
132
|
-
termsInit.removeElement(validatedIndex);
|
|
133
|
-
// If terms is now empty, drop the whole status property
|
|
134
|
-
if (termsInit.getElements().length === 0) {
|
|
135
|
-
statusProperty.remove();
|
|
136
|
-
}
|
|
137
|
-
addValidatedFlag(clause);
|
|
138
|
-
return true;
|
|
139
|
-
}
|
|
140
|
-
// ── exact case ──────────────────────────────────────────────────────────────
|
|
141
|
-
if (statusType === 'exact') {
|
|
142
|
-
const termProperty = statusInit.getProperty(TERM_PROPERTY_NAME);
|
|
143
|
-
if (!termProperty || !ts_morph_1.Node.isPropertyAssignment(termProperty)) {
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
const termInit = termProperty.getInitializer();
|
|
147
|
-
if (!termInit || !ts_morph_1.Node.isStringLiteral(termInit)) {
|
|
148
|
-
return false;
|
|
149
|
-
}
|
|
150
|
-
if (termInit.getLiteralValue() !== VALIDATED_STATUS_VALUE)
|
|
151
|
-
return false;
|
|
152
|
-
// Remove the entire status property
|
|
153
|
-
statusProperty.remove();
|
|
154
|
-
addValidatedFlag(clause);
|
|
155
|
-
return true;
|
|
156
|
-
}
|
|
157
|
-
return false;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Recursively walks a query node.
|
|
161
|
-
* - If it is an `or`/`and` container, recurses into `clauses`
|
|
162
|
-
* - Otherwise treats it as a leaf clause and calls `migrateClause`
|
|
163
|
-
* Returns the number of clauses changed.
|
|
164
|
-
*/
|
|
165
|
-
function walkQuery(queryObj) {
|
|
166
|
-
const typeProperty = queryObj.getProperty(TYPE_PROPERTY_NAME);
|
|
167
|
-
if (typeProperty && ts_morph_1.Node.isPropertyAssignment(typeProperty)) {
|
|
168
|
-
const typeInit = typeProperty.getInitializer();
|
|
169
|
-
if (typeInit &&
|
|
170
|
-
ts_morph_1.Node.isStringLiteral(typeInit) &&
|
|
171
|
-
(typeInit.getLiteralValue() === 'or' ||
|
|
172
|
-
typeInit.getLiteralValue() === 'and')) {
|
|
173
|
-
const clausesProperty = queryObj.getProperty(CLAUSES_PROPERTY_NAME);
|
|
174
|
-
if (!clausesProperty || !ts_morph_1.Node.isPropertyAssignment(clausesProperty)) {
|
|
175
|
-
return 0;
|
|
176
|
-
}
|
|
177
|
-
const clausesInit = clausesProperty.getInitializer();
|
|
178
|
-
if (!clausesInit || !ts_morph_1.Node.isArrayLiteralExpression(clausesInit)) {
|
|
179
|
-
return 0;
|
|
180
|
-
}
|
|
181
|
-
let changed = 0;
|
|
182
|
-
for (const clause of clausesInit.getElements()) {
|
|
183
|
-
if (ts_morph_1.Node.isObjectLiteralExpression(clause)) {
|
|
184
|
-
changed += walkQuery(clause);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
return changed;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
// Leaf clause
|
|
191
|
-
return migrateClause(queryObj) ? 1 : 0;
|
|
192
|
-
}
|
|
193
|
-
// ─── File processor ──────────────────────────────────────────────────────────
|
|
194
|
-
function processFile(filePath, project) {
|
|
195
|
-
const sourceFile = project.getSourceFile(filePath);
|
|
196
|
-
if (!sourceFile)
|
|
197
|
-
return 0;
|
|
198
|
-
let migratedCount = 0;
|
|
199
|
-
const callExpressions = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
200
|
-
for (const call of callExpressions) {
|
|
201
|
-
const expression = call.getExpression();
|
|
202
|
-
if (!ts_morph_1.Node.isIdentifier(expression) ||
|
|
203
|
-
expression.getText() !== DEFINE_WORKQUEUES_NAME) {
|
|
204
|
-
continue;
|
|
205
|
-
}
|
|
206
|
-
const args = call.getArguments();
|
|
207
|
-
if (args.length === 0)
|
|
208
|
-
continue;
|
|
209
|
-
// The argument must be an array literal of workqueue config objects
|
|
210
|
-
const workqueuesArg = args[0];
|
|
211
|
-
if (!ts_morph_1.Node.isArrayLiteralExpression(workqueuesArg))
|
|
212
|
-
continue;
|
|
213
|
-
for (const workqueueElement of workqueuesArg.getElements()) {
|
|
214
|
-
if (!ts_morph_1.Node.isObjectLiteralExpression(workqueueElement))
|
|
215
|
-
continue;
|
|
216
|
-
const queryProperty = workqueueElement.getProperty(QUERY_PROPERTY_NAME);
|
|
217
|
-
if (!queryProperty || !ts_morph_1.Node.isPropertyAssignment(queryProperty))
|
|
218
|
-
continue;
|
|
219
|
-
const queryInit = queryProperty.getInitializer();
|
|
220
|
-
if (!queryInit || !ts_morph_1.Node.isObjectLiteralExpression(queryInit))
|
|
221
|
-
continue;
|
|
222
|
-
const changed = walkQuery(queryInit);
|
|
223
|
-
if (changed > 0) {
|
|
224
|
-
migratedCount += changed;
|
|
225
|
-
console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Migrated ${changed} clause(s): VALIDATED status → flags.anyOf`);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
return migratedCount;
|
|
230
|
-
}
|
|
231
|
-
// ─── Entry point ─────────────────────────────────────────────────────────────
|
|
232
|
-
function main() {
|
|
233
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
234
|
-
const srcDir = path_1.default.join(process.cwd(), 'src');
|
|
235
|
-
console.log(`Scanning for defineWorkqueues calls in: ${srcDir}\n`);
|
|
236
|
-
const project = new ts_morph_1.Project({
|
|
237
|
-
tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
|
|
238
|
-
skipAddingFilesFromTsConfig: false
|
|
239
|
-
});
|
|
240
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
241
|
-
const fp = sf.getFilePath();
|
|
242
|
-
return fp.includes('/src/') && !fp.includes('/node_modules/');
|
|
243
|
-
});
|
|
244
|
-
console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
|
|
245
|
-
let totalMigrated = 0;
|
|
246
|
-
const modifiedFiles = [];
|
|
247
|
-
for (const sourceFile of sourceFiles) {
|
|
248
|
-
const filePath = sourceFile.getFilePath();
|
|
249
|
-
const migrated = processFile(filePath, project);
|
|
250
|
-
if (migrated > 0) {
|
|
251
|
-
totalMigrated += migrated;
|
|
252
|
-
modifiedFiles.push(filePath);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
if (modifiedFiles.length === 0) {
|
|
256
|
-
console.log('No VALIDATED status references found in defineWorkqueues calls. Nothing to do.');
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
|
|
260
|
-
for (const filePath of modifiedFiles) {
|
|
261
|
-
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
262
|
-
yield sourceFile.save();
|
|
263
|
-
console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
|
|
264
|
-
}
|
|
265
|
-
console.log(`\nDone. Migrated ${totalMigrated} clause(s) from VALIDATED status to flags.anyOf['validated'].`);
|
|
266
|
-
});
|
|
267
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"migrate-workqueue-configs.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/migrate-workqueue-configs.ts"],"names":[],"mappings":"AAgVA,iBAAe,IAAI,kBAqDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|