@opencrvs/toolkit 2.1.2 → 2.2.0-rc.19ec10b
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 +9 -14
- package/create-countryconfig/package.json +1 -1
- package/dist/application-config/index.js +57 -14
- package/dist/authentication/index.d.ts +2 -1
- package/dist/authentication/index.js +34 -14
- package/dist/cli.js +1491 -2020
- package/dist/commons/api/router.d.ts +1564 -248
- package/dist/commons/application-config/index.d.ts +3 -3
- package/dist/commons/conditionals/conditionals.d.ts +58 -7
- package/dist/commons/conditionals/index.d.ts +1 -0
- package/dist/commons/conditionals/validate.d.ts +6 -1
- package/dist/commons/events/ActionConfig.d.ts +146 -20
- package/dist/commons/events/ActionDocument.d.ts +89 -0
- package/dist/commons/events/ActionInput.d.ts +56 -4
- package/dist/commons/events/ActionStatus.d.ts +2 -2
- package/dist/commons/events/ActionType.d.ts +13 -1
- package/dist/commons/events/AdvancedSearchConfig.d.ts +15 -0
- package/dist/commons/events/AuditLog.d.ts +4 -0
- package/dist/commons/events/CompositeFieldValue.d.ts +5 -1
- package/dist/commons/events/CountryConfigQueryInput.d.ts +192 -18
- package/dist/commons/events/Draft.d.ts +36 -1
- package/dist/commons/events/EventConfig.d.ts +473 -6
- package/dist/commons/events/EventDocument.d.ts +90 -0
- package/dist/commons/events/EventIndex.d.ts +44 -6
- package/dist/commons/events/EventInput.d.ts +1 -0
- package/dist/commons/events/EventMetadata.d.ts +24 -1
- package/dist/commons/events/EventStatus.d.ts +1 -0
- package/dist/commons/events/FieldConfig.d.ts +11 -1
- package/dist/commons/events/FieldTypeMapping.d.ts +17 -17
- package/dist/commons/events/Flag.d.ts +1 -7
- package/dist/commons/events/PlainDate.d.ts +6 -0
- package/dist/commons/events/WorkqueueConfig.d.ts +224 -33
- package/dist/commons/events/defineConfig.d.ts +7 -2
- package/dist/commons/events/event.d.ts +20 -1
- package/dist/commons/events/eventConfigValidation.d.ts +26 -1
- package/dist/commons/events/field.d.ts +37 -0
- package/dist/commons/events/index.d.ts +3 -0
- package/dist/commons/events/locations.d.ts +1 -1
- package/dist/commons/events/scopes.d.ts +4 -1
- package/dist/commons/events/state/flags.d.ts +1 -1
- package/dist/commons/events/state/index.d.ts +11 -2
- package/dist/commons/events/state/utils.d.ts +11 -1
- package/dist/commons/events/test.utils.d.ts +89 -7
- package/dist/commons/events/toNotificationForm.d.ts +17 -0
- package/dist/commons/events/utils.d.ts +90 -10
- package/dist/commons/users/Role.d.ts +23 -0
- package/dist/commons/users/User.d.ts +263 -0
- package/dist/commons/users/authentication.d.ts +67 -0
- package/dist/commons/users/index.d.ts +5 -0
- package/dist/commons/users/roleValidations.d.ts +15 -0
- package/dist/commons/users/scopes.d.ts +1402 -0
- package/dist/commons/users/userReferences.d.ts +176 -0
- package/dist/conditionals/index.js +29 -9
- package/dist/environment/custom-types.d.ts +1 -0
- package/dist/environment/custom-types.d.ts.map +1 -1
- package/dist/environment/derived-variables.d.ts +24 -4
- package/dist/environment/derived-variables.d.ts.map +1 -1
- package/dist/environment/derived-variables.js +27 -4
- package/dist/environment/questions.d.ts +42 -9
- package/dist/environment/questions.d.ts.map +1 -1
- package/dist/environment/questions.js +71 -48
- package/dist/environment/registry.d.ts +15 -0
- package/dist/environment/registry.d.ts.map +1 -0
- package/dist/environment/registry.js +112 -0
- package/dist/environment/setup-environment.d.ts.map +1 -1
- package/dist/environment/setup-environment.js +165 -35
- package/dist/environment/templates.d.ts.map +1 -1
- package/dist/events/index.js +2050 -1156
- package/dist/migrations/add-notify-config.d.ts +40 -0
- package/dist/migrations/add-notify-config.d.ts.map +1 -0
- package/dist/migrations/add-notify-config.js +249 -0
- package/dist/migrations/index.d.ts +9 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/index.js +1306 -0
- package/dist/migrations/move-declaration-to-declare-action.d.ts +38 -0
- package/dist/migrations/move-declaration-to-declare-action.d.ts.map +1 -0
- package/dist/migrations/move-declaration-to-declare-action.js +260 -0
- package/dist/migrations/{v2.1 → persistent}/add-translations.d.ts +7 -1
- package/dist/migrations/persistent/add-translations.d.ts.map +1 -0
- package/dist/migrations/{v2.1 → persistent}/add-translations.js +14 -12
- package/dist/migrations/persistent/check-upgrade-path.d.ts +36 -0
- package/dist/migrations/persistent/check-upgrade-path.d.ts.map +1 -0
- package/dist/migrations/persistent/check-upgrade-path.js +105 -0
- package/dist/migrations/persistent/update-toolkit-dependency.d.ts +7 -0
- package/dist/migrations/persistent/update-toolkit-dependency.d.ts.map +1 -0
- package/dist/migrations/persistent/update-toolkit-dependency.js +77 -0
- package/dist/migrations/read-declaration-through-helper.d.ts +39 -0
- package/dist/migrations/read-declaration-through-helper.d.ts.map +1 -0
- package/dist/migrations/read-declaration-through-helper.js +199 -0
- package/dist/migrations/replace-incomplete-flag.d.ts +26 -0
- package/dist/migrations/replace-incomplete-flag.d.ts.map +1 -0
- package/dist/migrations/replace-incomplete-flag.js +126 -0
- package/dist/migrations/resolve-versioned-event-config.d.ts +56 -0
- package/dist/migrations/resolve-versioned-event-config.d.ts.map +1 -0
- package/dist/migrations/resolve-versioned-event-config.js +353 -0
- package/dist/migrations/utils.d.ts +61 -0
- package/dist/migrations/utils.d.ts.map +1 -0
- package/dist/migrations/utils.js +218 -0
- package/dist/notification/index.js +1081 -209
- package/dist/roles/index.d.ts +2 -0
- package/dist/roles/index.d.ts.map +1 -0
- package/dist/roles/index.js +730 -0
- package/dist/scopes/index.d.ts +83 -100
- package/dist/scopes/index.js +29 -13
- package/dist/templates/charts-values/dependencies/values.yaml +6 -3
- package/dist/templates/charts-values/opencrvs-services/values.yaml +5 -10
- package/dist/templates/charts-values/traefik/values.yaml +4 -3
- package/dist/verify/endpoints.d.ts +11 -0
- package/dist/verify/endpoints.d.ts.map +1 -1
- package/dist/verify/endpoints.js +21 -27
- package/opencrvs-toolkit-2.2.0-rc.19ec10b.tgz +0 -0
- package/package.json +5 -3
- package/tsconfig.build.tsbuildinfo +1 -1
- package/tsconfig.json +3 -5
- package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts +0 -3
- package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts.map +0 -1
- package/dist/migrations/v2.1/add-explicit-correction-flags.js +0 -234
- package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +0 -3
- package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +0 -1
- package/dist/migrations/v2.1/add-recovery-link-notifications.js +0 -511
- package/dist/migrations/v2.1/add-translations.d.ts.map +0 -1
- package/dist/migrations/v2.1/enable-telemetry.d.ts +0 -3
- package/dist/migrations/v2.1/enable-telemetry.d.ts.map +0 -1
- package/dist/migrations/v2.1/enable-telemetry.js +0 -455
- package/dist/migrations/v2.1/index.d.ts +0 -6
- package/dist/migrations/v2.1/index.d.ts.map +0 -1
- package/dist/migrations/v2.1/index.js +0 -2170
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts +0 -14
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts.map +0 -1
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.js +0 -348
- package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts +0 -2
- package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts.map +0 -1
- package/dist/migrations/v2.1/remove-metabase-package-installs.js +0 -161
- package/dist/migrations/v2.1/remove-sentry.d.ts +0 -3
- package/dist/migrations/v2.1/remove-sentry.d.ts.map +0 -1
- package/dist/migrations/v2.1/remove-sentry.js +0 -354
- package/dist/migrations/v2.1/rename-trigger-paths.d.ts +0 -3
- package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +0 -1
- package/dist/migrations/v2.1/rename-trigger-paths.js +0 -216
- package/dist/migrations/v2.1/template-files.d.ts +0 -8
- package/dist/migrations/v2.1/template-files.d.ts.map +0 -1
- package/dist/migrations/v2.1/template-files.js +0 -49
- package/dist/migrations/v2.1/upgrade-tilt.d.ts +0 -8
- package/dist/migrations/v2.1/upgrade-tilt.d.ts.map +0 -1
- package/dist/migrations/v2.1/upgrade-tilt.js +0 -139
- package/dist/templates/countryconfig-template/.tiltignore +0 -1
- package/dist/templates/countryconfig-template/Dockerfile.assets +0 -7
- package/dist/templates/countryconfig-template/Tiltfile +0 -112
- package/dist/templates/countryconfig-template/assets/README.md +0 -1
- package/dist/templates/countryconfig-template/assets/clear-all-data-dev.sh +0 -61
- package/dist/templates/countryconfig-template/assets/deployment/deploy.sh +0 -455
- package/dist/templates/countryconfig-template/assets/deployment/reindex.sh +0 -168
- package/dist/templates/countryconfig-template/assets/deployment/validate-required-variables-in-compose-files.ts +0 -67
- package/dist/templates/countryconfig-template/assets/elasticsearch/reindex.sh +0 -168
- package/dist/templates/countryconfig-template/assets/metabase/README.md +0 -34
- package/dist/templates/countryconfig-template/assets/metabase/environment-configuration.sql +0 -36
- package/dist/templates/countryconfig-template/assets/metabase/initialize-database.sh +0 -46
- package/dist/templates/countryconfig-template/assets/metabase/metabase.init.db.sql +0 -27737
- package/dist/templates/countryconfig-template/assets/metabase/open-shell.sh +0 -21
- package/dist/templates/countryconfig-template/assets/metabase/package.json +0 -13
- package/dist/templates/countryconfig-template/assets/metabase/run-dev.sh +0 -108
- package/dist/templates/countryconfig-template/assets/metabase/run.sh +0 -120
- package/dist/templates/countryconfig-template/assets/metabase/update-database.sh +0 -40
- package/dist/templates/countryconfig-template/assets/postgres/setup-analytics.sh +0 -135
- package/dist/templates/countryconfig-template/assets/postgres/setup-reference-data.sh +0 -108
- package/dist/templates/countryconfig-template/tilt/clear-all-data.ps1 +0 -50
- package/dist/templates/countryconfig-template/tilt/clear-all-data.sh +0 -35
- package/dist/templates/countryconfig-template/tilt/common.tilt +0 -145
- package/dist/templates/countryconfig-template/tilt/examples/dependencies/values.yaml +0 -15
- package/dist/templates/countryconfig-template/tilt/examples/opencrvs-services/values.yaml +0 -56
- package/dist/templates/countryconfig-template/tilt/examples/traefik/values-minikube.yaml +0 -21
- package/dist/templates/countryconfig-template/tilt/examples/traefik/values.yaml +0 -38
- package/dist/templates/countryconfig-template/tilt/helm/dependencies/values.yaml +0 -17
- package/dist/templates/countryconfig-template/tilt/helm/opencrvs-services/values.yaml +0 -16
- package/dist/templates/countryconfig-template/tilt/lib.tilt +0 -95
- package/dist/templates/countryconfig-template/tilt/opencrvs.tilt +0 -136
- package/opencrvs-toolkit-2.1.2.tgz +0 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codemod: Read an event configuration's declaration form through
|
|
3
|
+
* `getDeclaration()` instead of the top-level `declaration` property.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* ts-node -r tsconfig-paths/register src/migrations/read-declaration-through-helper.ts
|
|
7
|
+
*
|
|
8
|
+
* Why:
|
|
9
|
+
* As of v2.2 the declaration form lives on the DECLARE action. `defineConfig`
|
|
10
|
+
* still accepts a top-level `declaration` and moves it there, but the parsed
|
|
11
|
+
* `EventConfig` no longer has a top-level `declaration` property, so code
|
|
12
|
+
* reading `eventConfig.declaration` stops compiling.
|
|
13
|
+
*
|
|
14
|
+
* What it does:
|
|
15
|
+
* - Scans all TypeScript files under `src/`
|
|
16
|
+
* - Rewrites `x.declaration` to `getDeclaration(x)` wherever `x` is the
|
|
17
|
+
* toolkit's `EventConfig`. Record data (e.g. `event.declaration`) is a
|
|
18
|
+
* different type and is left alone.
|
|
19
|
+
* - Adds `getDeclaration` to the file's `@opencrvs/toolkit/events` import
|
|
20
|
+
* - Logs, without changing, reads it cannot rewrite safely: optional chains
|
|
21
|
+
* (`x?.declaration`), writes to `x.declaration` (`=`, `??=`, `delete`...)
|
|
22
|
+
* and destructuring `{ declaration }` out of an `EventConfig`
|
|
23
|
+
* - Logs object literals that spread an `EventConfig` and set `declaration`
|
|
24
|
+
* next to it, which `defineConfig` now rejects
|
|
25
|
+
* - Leaves a file alone, and logs it, when it already declares its own
|
|
26
|
+
* `getDeclaration`
|
|
27
|
+
* - Saves the modified files in-place
|
|
28
|
+
*/
|
|
29
|
+
import { SourceFile } from 'ts-morph';
|
|
30
|
+
/**
|
|
31
|
+
* Rewrites every `x.declaration` read on an `EventConfig` in the file to
|
|
32
|
+
* `getDeclaration(x)`.
|
|
33
|
+
*
|
|
34
|
+
* @returns the number of reads rewritten.
|
|
35
|
+
*/
|
|
36
|
+
export declare function rewriteDeclarationReads(sourceFile: SourceFile): number;
|
|
37
|
+
declare function main(): Promise<void>;
|
|
38
|
+
export { main };
|
|
39
|
+
//# sourceMappingURL=read-declaration-through-helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-declaration-through-helper.d.ts","sourceRoot":"","sources":["../../src/migrations/read-declaration-through-helper.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAIL,UAAU,EAGX,MAAM,UAAU,CAAA;AA8GjB;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAwDtE;AAED,iBAAe,IAAI,kBA6ClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1,199 @@
|
|
|
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.rewriteDeclarationReads = rewriteDeclarationReads;
|
|
26
|
+
exports.main = main;
|
|
27
|
+
/**
|
|
28
|
+
* Codemod: Read an event configuration's declaration form through
|
|
29
|
+
* `getDeclaration()` instead of the top-level `declaration` property.
|
|
30
|
+
*
|
|
31
|
+
* Usage:
|
|
32
|
+
* ts-node -r tsconfig-paths/register src/migrations/read-declaration-through-helper.ts
|
|
33
|
+
*
|
|
34
|
+
* Why:
|
|
35
|
+
* As of v2.2 the declaration form lives on the DECLARE action. `defineConfig`
|
|
36
|
+
* still accepts a top-level `declaration` and moves it there, but the parsed
|
|
37
|
+
* `EventConfig` no longer has a top-level `declaration` property, so code
|
|
38
|
+
* reading `eventConfig.declaration` stops compiling.
|
|
39
|
+
*
|
|
40
|
+
* What it does:
|
|
41
|
+
* - Scans all TypeScript files under `src/`
|
|
42
|
+
* - Rewrites `x.declaration` to `getDeclaration(x)` wherever `x` is the
|
|
43
|
+
* toolkit's `EventConfig`. Record data (e.g. `event.declaration`) is a
|
|
44
|
+
* different type and is left alone.
|
|
45
|
+
* - Adds `getDeclaration` to the file's `@opencrvs/toolkit/events` import
|
|
46
|
+
* - Logs, without changing, reads it cannot rewrite safely: optional chains
|
|
47
|
+
* (`x?.declaration`), writes to `x.declaration` (`=`, `??=`, `delete`...)
|
|
48
|
+
* and destructuring `{ declaration }` out of an `EventConfig`
|
|
49
|
+
* - Logs object literals that spread an `EventConfig` and set `declaration`
|
|
50
|
+
* next to it, which `defineConfig` now rejects
|
|
51
|
+
* - Leaves a file alone, and logs it, when it already declares its own
|
|
52
|
+
* `getDeclaration`
|
|
53
|
+
* - Saves the modified files in-place
|
|
54
|
+
*/
|
|
55
|
+
const ts_morph_1 = require("ts-morph");
|
|
56
|
+
const path_1 = __importDefault(require("path"));
|
|
57
|
+
const utils_1 = require("./utils");
|
|
58
|
+
const EVENT_CONFIG_TYPE_NAME = 'EventConfig';
|
|
59
|
+
const DECLARATION_PROPERTY_NAME = 'declaration';
|
|
60
|
+
const GET_DECLARATION_NAME = 'getDeclaration';
|
|
61
|
+
/**
|
|
62
|
+
* Returns true if the type is the `EventConfig` type published by the toolkit,
|
|
63
|
+
* as opposed to a type of the same name declared in the country config itself.
|
|
64
|
+
*/
|
|
65
|
+
function isToolkitEventConfig(type) {
|
|
66
|
+
var _a;
|
|
67
|
+
const nonNullableType = type.getNonNullableType();
|
|
68
|
+
const symbol = (_a = nonNullableType.getAliasSymbol()) !== null && _a !== void 0 ? _a : nonNullableType.getSymbol();
|
|
69
|
+
if ((symbol === null || symbol === void 0 ? void 0 : symbol.getName()) !== EVENT_CONFIG_TYPE_NAME) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
return symbol
|
|
73
|
+
.getDeclarations()
|
|
74
|
+
.some((declaration) => declaration.getSourceFile().isDeclarationFile());
|
|
75
|
+
}
|
|
76
|
+
function isDeclarationReadOnEventConfig(node) {
|
|
77
|
+
return (node.getName() === DECLARATION_PROPERTY_NAME &&
|
|
78
|
+
isToolkitEventConfig(node.getExpression().getType()));
|
|
79
|
+
}
|
|
80
|
+
function isAssignmentOperator(kind) {
|
|
81
|
+
return kind >= ts_morph_1.SyntaxKind.FirstAssignment && kind <= ts_morph_1.SyntaxKind.LastAssignment;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Returns true if the node is written to rather than read: the target of `=` or
|
|
85
|
+
* a compound assignment (`??=`, `||=`...), or the operand of `delete`.
|
|
86
|
+
* `getDeclaration(x)` is a call, so rewriting any of these does not compile.
|
|
87
|
+
*/
|
|
88
|
+
function isWriteTarget(node) {
|
|
89
|
+
const parent = node.getParent();
|
|
90
|
+
if (ts_morph_1.Node.isDeleteExpression(parent)) {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
return (ts_morph_1.Node.isBinaryExpression(parent) &&
|
|
94
|
+
parent.getLeft() === node &&
|
|
95
|
+
isAssignmentOperator(parent.getOperatorToken().getKind()));
|
|
96
|
+
}
|
|
97
|
+
function location(node) {
|
|
98
|
+
const relPath = path_1.default.relative(process.cwd(), node.getSourceFile().getFilePath());
|
|
99
|
+
return `${relPath}:${node.getStartLineNumber()}`;
|
|
100
|
+
}
|
|
101
|
+
function warnDestructuredDeclarations(sourceFile) {
|
|
102
|
+
for (const pattern of sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.ObjectBindingPattern)) {
|
|
103
|
+
const destructuresDeclaration = pattern
|
|
104
|
+
.getElements()
|
|
105
|
+
.some((element) => { var _a; var _b; return ((_b = (_a = element.getPropertyNameNode()) === null || _a === void 0 ? void 0 : _a.getText()) !== null && _b !== void 0 ? _b : element.getName()) ===
|
|
106
|
+
DECLARATION_PROPERTY_NAME; });
|
|
107
|
+
if (destructuresDeclaration && isToolkitEventConfig(pattern.getType())) {
|
|
108
|
+
console.warn(` [${location(pattern)}] Destructures \`${DECLARATION_PROPERTY_NAME}\` from an EventConfig. Rewrite it to use \`${GET_DECLARATION_NAME}(config)\` by hand.`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function warnSpreadDeclarations(sourceFile) {
|
|
113
|
+
for (const literal of sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression)) {
|
|
114
|
+
const properties = literal.getProperties();
|
|
115
|
+
const spreadsEventConfig = properties.some((property) => ts_morph_1.Node.isSpreadAssignment(property) &&
|
|
116
|
+
isToolkitEventConfig(property.getExpression().getType()));
|
|
117
|
+
const setsDeclaration = properties.some((property) => (ts_morph_1.Node.isPropertyAssignment(property) ||
|
|
118
|
+
ts_morph_1.Node.isShorthandPropertyAssignment(property)) &&
|
|
119
|
+
property.getName() === DECLARATION_PROPERTY_NAME);
|
|
120
|
+
if (spreadsEventConfig && setsDeclaration) {
|
|
121
|
+
console.warn(` [${location(literal)}] Spreads an EventConfig and sets \`${DECLARATION_PROPERTY_NAME}\` next to it. The spread config already has a \`${DECLARATION_PROPERTY_NAME}\` on its DECLARE action, so replace that one by hand.`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Rewrites every `x.declaration` read on an `EventConfig` in the file to
|
|
127
|
+
* `getDeclaration(x)`.
|
|
128
|
+
*
|
|
129
|
+
* @returns the number of reads rewritten.
|
|
130
|
+
*/
|
|
131
|
+
function rewriteDeclarationReads(sourceFile) {
|
|
132
|
+
warnDestructuredDeclarations(sourceFile);
|
|
133
|
+
warnSpreadDeclarations(sourceFile);
|
|
134
|
+
const reads = sourceFile
|
|
135
|
+
.getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertyAccessExpression)
|
|
136
|
+
.filter(isDeclarationReadOnEventConfig)
|
|
137
|
+
.filter((node) => {
|
|
138
|
+
if (node.hasQuestionDotToken()) {
|
|
139
|
+
console.warn(` [${location(node)}] Skipped optional chain \`${node.getText()}\`. Rewrite it to use \`${GET_DECLARATION_NAME}()\` by hand.`);
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
if (isWriteTarget(node)) {
|
|
143
|
+
console.warn(` [${location(node)}] Skipped write to \`${node.getText()}\`. Set \`${DECLARATION_PROPERTY_NAME}\` on the DECLARE action instead.`);
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
return true;
|
|
147
|
+
})
|
|
148
|
+
// Replace the innermost reads first, so replacing an outer read does not
|
|
149
|
+
// invalidate nodes still waiting to be replaced.
|
|
150
|
+
.sort((a, b) => b.getStart() - a.getStart());
|
|
151
|
+
if (reads.length === 0) {
|
|
152
|
+
return 0;
|
|
153
|
+
}
|
|
154
|
+
const getDeclarationName = (0, utils_1.findToolkitImportName)(sourceFile, GET_DECLARATION_NAME);
|
|
155
|
+
if (!getDeclarationName) {
|
|
156
|
+
console.warn(` [${location(reads[reads.length - 1])}] Skipped ${reads.length} read(s): the file already declares its own \`${GET_DECLARATION_NAME}\`. Rewrite them to use the toolkit's \`${GET_DECLARATION_NAME}()\` by hand.`);
|
|
157
|
+
return 0;
|
|
158
|
+
}
|
|
159
|
+
for (const read of reads) {
|
|
160
|
+
console.log(` [${location(read)}] ${read.getText()} -> ${getDeclarationName}(${read.getExpression().getText()})`);
|
|
161
|
+
read.replaceWithText(`${getDeclarationName}(${read.getExpression().getText()})`);
|
|
162
|
+
}
|
|
163
|
+
(0, utils_1.addToolkitImport)(sourceFile, GET_DECLARATION_NAME);
|
|
164
|
+
return reads.length;
|
|
165
|
+
}
|
|
166
|
+
function main() {
|
|
167
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
const srcDir = path_1.default.join(process.cwd(), 'src');
|
|
169
|
+
console.log(`Scanning for EventConfig declaration reads in: ${srcDir}\n`);
|
|
170
|
+
const project = new ts_morph_1.Project({
|
|
171
|
+
tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
|
|
172
|
+
skipAddingFilesFromTsConfig: false
|
|
173
|
+
});
|
|
174
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
175
|
+
const fp = sf.getFilePath();
|
|
176
|
+
return fp.includes('/src/') && !fp.includes('/node_modules/');
|
|
177
|
+
});
|
|
178
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
|
|
179
|
+
let totalChanges = 0;
|
|
180
|
+
const modifiedFiles = [];
|
|
181
|
+
for (const sourceFile of sourceFiles) {
|
|
182
|
+
const changes = rewriteDeclarationReads(sourceFile);
|
|
183
|
+
if (changes > 0) {
|
|
184
|
+
totalChanges += changes;
|
|
185
|
+
modifiedFiles.push(sourceFile);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (modifiedFiles.length === 0) {
|
|
189
|
+
console.log('No EventConfig declaration reads found. Nothing to do.');
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
|
|
193
|
+
for (const sourceFile of modifiedFiles) {
|
|
194
|
+
yield sourceFile.save();
|
|
195
|
+
console.log(` Saved: ${path_1.default.relative(process.cwd(), sourceFile.getFilePath())}`);
|
|
196
|
+
}
|
|
197
|
+
console.log(`\nDone. Rewrote ${totalChanges} declaration read(s) across ${modifiedFiles.length} file(s).`);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codemod: replace the removed `incomplete` flag with the NOTIFIED status.
|
|
3
|
+
*
|
|
4
|
+
* Why:
|
|
5
|
+
* `InherentFlags.INCOMPLETE` mirrored the NOTIFIED status and has been
|
|
6
|
+
* removed. See CHANGELOG.md ("The `incomplete` flag is removed").
|
|
7
|
+
*
|
|
8
|
+
* What it does:
|
|
9
|
+
* - In every query object of the form
|
|
10
|
+
* `{ flags: { anyOf: [InherentFlags.INCOMPLETE, ...] }, ... }`, removes
|
|
11
|
+
* the flag (and `anyOf` / `flags` if left empty) and adds
|
|
12
|
+
* `status: { type: 'exact', term: EventStatus.enum.NOTIFIED }`
|
|
13
|
+
* - Imports `EventStatus` next to `InherentFlags` when missing
|
|
14
|
+
* - Lists any other `InherentFlags.INCOMPLETE` reference for manual update
|
|
15
|
+
*/
|
|
16
|
+
import { SourceFile } from 'ts-morph';
|
|
17
|
+
/**
|
|
18
|
+
* Rewrites `flags.anyOf` uses of the incomplete flag in place.
|
|
19
|
+
* Returns the line numbers of references it could not rewrite.
|
|
20
|
+
*/
|
|
21
|
+
export declare function replaceIncompleteFlag(sourceFile: SourceFile): {
|
|
22
|
+
changed: boolean;
|
|
23
|
+
remaining: number[];
|
|
24
|
+
};
|
|
25
|
+
export declare function main(): Promise<void>;
|
|
26
|
+
//# sourceMappingURL=replace-incomplete-flag.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replace-incomplete-flag.d.ts","sourceRoot":"","sources":["../../src/migrations/replace-incomplete-flag.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAiB,UAAU,EAAc,MAAM,UAAU,CAAA;AAsBhE;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,UAAU;;;EAuD3D;AAED,wBAAsB,IAAI,kBAwBzB"}
|
|
@@ -0,0 +1,126 @@
|
|
|
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.replaceIncompleteFlag = replaceIncompleteFlag;
|
|
26
|
+
exports.main = main;
|
|
27
|
+
/**
|
|
28
|
+
* Codemod: replace the removed `incomplete` flag with the NOTIFIED status.
|
|
29
|
+
*
|
|
30
|
+
* Why:
|
|
31
|
+
* `InherentFlags.INCOMPLETE` mirrored the NOTIFIED status and has been
|
|
32
|
+
* removed. See CHANGELOG.md ("The `incomplete` flag is removed").
|
|
33
|
+
*
|
|
34
|
+
* What it does:
|
|
35
|
+
* - In every query object of the form
|
|
36
|
+
* `{ flags: { anyOf: [InherentFlags.INCOMPLETE, ...] }, ... }`, removes
|
|
37
|
+
* the flag (and `anyOf` / `flags` if left empty) and adds
|
|
38
|
+
* `status: { type: 'exact', term: EventStatus.enum.NOTIFIED }`
|
|
39
|
+
* - Imports `EventStatus` next to `InherentFlags` when missing
|
|
40
|
+
* - Lists any other `InherentFlags.INCOMPLETE` reference for manual update
|
|
41
|
+
*/
|
|
42
|
+
const ts_morph_1 = require("ts-morph");
|
|
43
|
+
const path_1 = __importDefault(require("path"));
|
|
44
|
+
const INCOMPLETE = 'InherentFlags.INCOMPLETE';
|
|
45
|
+
const NOTIFIED_STATUS = `{ type: 'exact', term: EventStatus.enum.NOTIFIED }`;
|
|
46
|
+
function ensureEventStatusImport(sourceFile) {
|
|
47
|
+
const importDeclaration = sourceFile
|
|
48
|
+
.getImportDeclarations()
|
|
49
|
+
.find((declaration) => declaration
|
|
50
|
+
.getNamedImports()
|
|
51
|
+
.some((named) => named.getName() === 'InherentFlags'));
|
|
52
|
+
const hasEventStatus = importDeclaration === null || importDeclaration === void 0 ? void 0 : importDeclaration.getNamedImports().some((named) => named.getName() === 'EventStatus');
|
|
53
|
+
if (importDeclaration && !hasEventStatus) {
|
|
54
|
+
importDeclaration.addNamedImport('EventStatus');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Rewrites `flags.anyOf` uses of the incomplete flag in place.
|
|
59
|
+
* Returns the line numbers of references it could not rewrite.
|
|
60
|
+
*/
|
|
61
|
+
function replaceIncompleteFlag(sourceFile) {
|
|
62
|
+
let changed = false;
|
|
63
|
+
const anyOfIncomplete = sourceFile
|
|
64
|
+
.getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertyAccessExpression)
|
|
65
|
+
.filter((node) => node.getText() === INCOMPLETE)
|
|
66
|
+
.map((node) => node.getParent())
|
|
67
|
+
.filter(ts_morph_1.Node.isArrayLiteralExpression)
|
|
68
|
+
.filter((array) => {
|
|
69
|
+
var _a;
|
|
70
|
+
const anyOf = array.getParent();
|
|
71
|
+
const flags = (_a = anyOf === null || anyOf === void 0 ? void 0 : anyOf.getParent()) === null || _a === void 0 ? void 0 : _a.getParent();
|
|
72
|
+
return (ts_morph_1.Node.isPropertyAssignment(anyOf) &&
|
|
73
|
+
anyOf.getName() === 'anyOf' &&
|
|
74
|
+
ts_morph_1.Node.isPropertyAssignment(flags) &&
|
|
75
|
+
flags.getName() === 'flags');
|
|
76
|
+
});
|
|
77
|
+
for (const array of anyOfIncomplete) {
|
|
78
|
+
const anyOf = array.getParentIfKindOrThrow(ts_morph_1.SyntaxKind.PropertyAssignment);
|
|
79
|
+
const flagsObject = anyOf.getParentIfKindOrThrow(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
|
|
80
|
+
const flags = flagsObject.getParentIfKindOrThrow(ts_morph_1.SyntaxKind.PropertyAssignment);
|
|
81
|
+
const query = flags.getParentIfKindOrThrow(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
|
|
82
|
+
array
|
|
83
|
+
.getElements()
|
|
84
|
+
.filter((element) => element.getText() === INCOMPLETE)
|
|
85
|
+
.forEach((element) => array.removeElement(element));
|
|
86
|
+
if (array.getElements().length === 0)
|
|
87
|
+
anyOf.remove();
|
|
88
|
+
if (flagsObject.getProperties().length === 0)
|
|
89
|
+
flags.remove();
|
|
90
|
+
if (!query.getProperty('status')) {
|
|
91
|
+
query.addPropertyAssignment({
|
|
92
|
+
name: 'status',
|
|
93
|
+
initializer: NOTIFIED_STATUS
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
changed = true;
|
|
97
|
+
}
|
|
98
|
+
if (changed)
|
|
99
|
+
ensureEventStatusImport(sourceFile);
|
|
100
|
+
const remaining = sourceFile
|
|
101
|
+
.getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertyAccessExpression)
|
|
102
|
+
.filter((node) => node.getText() === INCOMPLETE)
|
|
103
|
+
.map((node) => node.getStartLineNumber());
|
|
104
|
+
return { changed, remaining };
|
|
105
|
+
}
|
|
106
|
+
function main() {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
const project = new ts_morph_1.Project({
|
|
109
|
+
tsConfigFilePath: path_1.default.join(process.cwd(), 'tsconfig.json')
|
|
110
|
+
});
|
|
111
|
+
const sourceFiles = project
|
|
112
|
+
.getSourceFiles()
|
|
113
|
+
.filter((sf) => !sf.getFilePath().includes('/node_modules/'));
|
|
114
|
+
for (const sourceFile of sourceFiles) {
|
|
115
|
+
const relPath = path_1.default.relative(process.cwd(), sourceFile.getFilePath());
|
|
116
|
+
const { changed, remaining } = replaceIncompleteFlag(sourceFile);
|
|
117
|
+
if (changed) {
|
|
118
|
+
yield sourceFile.save();
|
|
119
|
+
console.log(` [${relPath}] Replaced the incomplete flag with the NOTIFIED status`);
|
|
120
|
+
}
|
|
121
|
+
for (const line of remaining) {
|
|
122
|
+
console.warn(` [${relPath}:${line}] ${INCOMPLETE} was removed, update this reference to use the NOTIFIED status`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codemod: Read a `VersionedEventConfig` through `resolveEventConfig()` wherever
|
|
3
|
+
* the country config uses it as a flat `EventConfig`.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* ts-node -r tsconfig-paths/register src/migrations/resolve-versioned-event-config.ts
|
|
7
|
+
*
|
|
8
|
+
* Why:
|
|
9
|
+
* As of v2.2 an event configuration can have several versions, each with an
|
|
10
|
+
* `effectiveFrom` date. `defineConfig` still accepts a flat configuration and
|
|
11
|
+
* wraps it in a single version, but it now returns a `VersionedEventConfig`:
|
|
12
|
+
* `{ id, label, advancedSearch, versions }`. Fields such as `actions` or
|
|
13
|
+
* `analytics` live on each version, so code that reads them straight off the
|
|
14
|
+
* result of `defineConfig`, or passes it to a function expecting an
|
|
15
|
+
* `EventConfig`, stops compiling.
|
|
16
|
+
*
|
|
17
|
+
* What it does:
|
|
18
|
+
* - Scans all TypeScript files under `src/`
|
|
19
|
+
* - Reads `@opencrvs/toolkit/events` from the toolkit running it, not the one the
|
|
20
|
+
* country config has installed, which predates `VersionedEventConfig`
|
|
21
|
+
* - Rewrites `x.field` to `resolveEventConfig(x).field` wherever `x` is the
|
|
22
|
+
* toolkit's `VersionedEventConfig` and `field` is not one of its own fields
|
|
23
|
+
* (`id`, `label`, `advancedSearch` and `versions` are left alone)
|
|
24
|
+
* - Rewrites `x` to `resolveEventConfig(x)` wherever a `VersionedEventConfig` is
|
|
25
|
+
* passed, assigned or returned where an `EventConfig` is expected, and `xs` to
|
|
26
|
+
* `xs.map(resolveEventConfig)` for arrays of them
|
|
27
|
+
* - Adds `resolveEventConfig` to the file's `@opencrvs/toolkit/events` import
|
|
28
|
+
* - Logs, without changing: optional chains (`x?.actions`), writes
|
|
29
|
+
* (`x.actions = ...`, `delete x.actions`...), destructuring `{ actions }` out
|
|
30
|
+
* of a `VersionedEventConfig`, and a possibly undefined `VersionedEventConfig`
|
|
31
|
+
* passed where an `EventConfig` is expected
|
|
32
|
+
* - Leaves a file alone, and logs it, when it already declares its own
|
|
33
|
+
* `resolveEventConfig`
|
|
34
|
+
* - Saves the modified files in-place
|
|
35
|
+
*
|
|
36
|
+
* Runs before `read-declaration-through-helper`, which then rewrites
|
|
37
|
+
* `resolveEventConfig(x).declaration` to `getDeclaration(resolveEventConfig(x))`.
|
|
38
|
+
*/
|
|
39
|
+
import { CompilerOptions, SourceFile } from 'ts-morph';
|
|
40
|
+
/**
|
|
41
|
+
* Resolves `@opencrvs/toolkit/events` to `toolkitEventsPath`, keeping the country
|
|
42
|
+
* config's other `paths`. The country config still has the toolkit it upgrades from
|
|
43
|
+
* installed, whose types have no `VersionedEventConfig`, so the codemod reads the
|
|
44
|
+
* types of the toolkit running it instead.
|
|
45
|
+
*/
|
|
46
|
+
export declare function withToolkitEventsAt(compilerOptions: CompilerOptions, toolkitEventsPath: string): CompilerOptions;
|
|
47
|
+
/**
|
|
48
|
+
* Rewrites every use of a `VersionedEventConfig` as a flat `EventConfig` in the
|
|
49
|
+
* file to go through `resolveEventConfig()`.
|
|
50
|
+
*
|
|
51
|
+
* @returns the number of uses rewritten.
|
|
52
|
+
*/
|
|
53
|
+
export declare function rewriteVersionedEventConfigUses(sourceFile: SourceFile): number;
|
|
54
|
+
declare function main(): Promise<void>;
|
|
55
|
+
export { main };
|
|
56
|
+
//# sourceMappingURL=resolve-versioned-event-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-versioned-event-config.d.ts","sourceRoot":"","sources":["../../src/migrations/resolve-versioned-event-config.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,EACL,eAAe,EAMf,UAAU,EAGX,MAAM,UAAU,CAAA;AAsRjB;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,eAAe,EAAE,eAAe,EAChC,iBAAiB,EAAE,MAAM,GACxB,eAAe,CAQjB;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAC7C,UAAU,EAAE,UAAU,GACrB,MAAM,CAiDR;AAED,iBAAe,IAAI,kBAuDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|