@opencrvs/toolkit 2.1.2 → 2.2.0-rc.1a111f2
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 +2 -12
- package/create-countryconfig/package.json +1 -1
- package/dist/application-config/index.js +41 -9
- package/dist/authentication/index.d.ts +1 -0
- package/dist/authentication/index.js +30 -6
- package/dist/cli.js +1489 -2020
- package/dist/commons/api/router.d.ts +1551 -248
- package/dist/commons/application-config/index.d.ts +2 -2
- package/dist/commons/conditionals/conditionals.d.ts +3 -3
- package/dist/commons/conditionals/index.d.ts +1 -0
- package/dist/commons/conditionals/validate.d.ts +5 -0
- 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/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 +412 -6
- package/dist/commons/events/EventDocument.d.ts +88 -0
- package/dist/commons/events/EventIndex.d.ts +43 -6
- package/dist/commons/events/EventMetadata.d.ts +23 -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 +6 -6
- package/dist/commons/events/Flag.d.ts +1 -7
- package/dist/commons/events/PlainDate.d.ts +1 -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 +4 -1
- package/dist/commons/events/eventConfigValidation.d.ts +26 -1
- package/dist/commons/events/field.d.ts +5 -0
- package/dist/commons/events/index.d.ts +3 -0
- package/dist/commons/events/scopes.d.ts +3 -0
- package/dist/commons/events/state/flags.d.ts +1 -1
- package/dist/commons/events/state/index.d.ts +10 -2
- package/dist/commons/events/state/utils.d.ts +11 -1
- package/dist/commons/events/test.utils.d.ts +87 -6
- package/dist/commons/events/toNotificationForm.d.ts +17 -0
- package/dist/commons/events/utils.d.ts +75 -8
- package/dist/conditionals/index.js +16 -4
- 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 +159 -35
- package/dist/environment/templates.d.ts.map +1 -1
- package/dist/events/index.js +944 -214
- 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 +887 -129
- package/dist/scopes/index.d.ts +83 -90
- package/dist/scopes/index.js +26 -6
- package/dist/templates/charts-values/dependencies/values.yaml +3 -2
- package/dist/templates/charts-values/opencrvs-services/values.yaml +5 -7
- 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.1a111f2.tgz +0 -0
- package/package.json +3 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- 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,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codemod: Give every NOTIFY action the `notificationForm` and `review` it
|
|
3
|
+
* requires.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* ts-node -r tsconfig-paths/register src/migrations/add-notify-config.ts
|
|
7
|
+
*
|
|
8
|
+
* Why:
|
|
9
|
+
* As of v2.2 a NOTIFY action must configure its `notificationForm` and
|
|
10
|
+
* `review`. A notification form is validated like any form, so a plain copy
|
|
11
|
+
* of the declaration would make NOTIFY reject incomplete records.
|
|
12
|
+
* `toNotificationForm` and `toNotificationReview` copy the DECLARE form and
|
|
13
|
+
* review with every field optional, which keeps NOTIFY accepting them.
|
|
14
|
+
*
|
|
15
|
+
* What it does:
|
|
16
|
+
* - Scans all TypeScript files under `src/`
|
|
17
|
+
* - Finds the NOTIFY action in the `actions` of every call to the toolkit's
|
|
18
|
+
* `defineConfig`
|
|
19
|
+
* - Adds `notificationForm: toNotificationForm(<DECLARE declaration>)` and
|
|
20
|
+
* `review: toNotificationReview(<DECLARE review>)` when missing, after its
|
|
21
|
+
* `label` (or its `type` when it has no `label`)
|
|
22
|
+
* - Adds the helpers to the file's `@opencrvs/toolkit/events` import
|
|
23
|
+
* - Logs events without a NOTIFY action, which cannot be notified
|
|
24
|
+
* - Logs, without changing, configs it cannot rewrite safely: a config not
|
|
25
|
+
* given as an object literal, `actions` that is not an array literal, a
|
|
26
|
+
* NOTIFY action not written inline, and a DECLARE `declaration` or
|
|
27
|
+
* `review` not given as a name (e.g. written inline)
|
|
28
|
+
* - Saves the modified files in-place
|
|
29
|
+
*/
|
|
30
|
+
import { SourceFile } from 'ts-morph';
|
|
31
|
+
/**
|
|
32
|
+
* Adds the missing `notificationForm` and `review` to the NOTIFY action of
|
|
33
|
+
* every toolkit `defineConfig` call in the file.
|
|
34
|
+
*
|
|
35
|
+
* @returns the number of NOTIFY actions rewritten.
|
|
36
|
+
*/
|
|
37
|
+
export declare function addNotifyConfig(sourceFile: SourceFile): number;
|
|
38
|
+
declare function main(): Promise<void>;
|
|
39
|
+
export { main };
|
|
40
|
+
//# sourceMappingURL=add-notify-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-notify-config.d.ts","sourceRoot":"","sources":["../../src/migrations/add-notify-config.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAOL,UAAU,EAEX,MAAM,UAAU,CAAA;AA8IjB;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAqG9D;AAED,iBAAe,IAAI,kBA6ClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1,249 @@
|
|
|
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.addNotifyConfig = addNotifyConfig;
|
|
26
|
+
exports.main = main;
|
|
27
|
+
/**
|
|
28
|
+
* Codemod: Give every NOTIFY action the `notificationForm` and `review` it
|
|
29
|
+
* requires.
|
|
30
|
+
*
|
|
31
|
+
* Usage:
|
|
32
|
+
* ts-node -r tsconfig-paths/register src/migrations/add-notify-config.ts
|
|
33
|
+
*
|
|
34
|
+
* Why:
|
|
35
|
+
* As of v2.2 a NOTIFY action must configure its `notificationForm` and
|
|
36
|
+
* `review`. A notification form is validated like any form, so a plain copy
|
|
37
|
+
* of the declaration would make NOTIFY reject incomplete records.
|
|
38
|
+
* `toNotificationForm` and `toNotificationReview` copy the DECLARE form and
|
|
39
|
+
* review with every field optional, which keeps NOTIFY accepting them.
|
|
40
|
+
*
|
|
41
|
+
* What it does:
|
|
42
|
+
* - Scans all TypeScript files under `src/`
|
|
43
|
+
* - Finds the NOTIFY action in the `actions` of every call to the toolkit's
|
|
44
|
+
* `defineConfig`
|
|
45
|
+
* - Adds `notificationForm: toNotificationForm(<DECLARE declaration>)` and
|
|
46
|
+
* `review: toNotificationReview(<DECLARE review>)` when missing, after its
|
|
47
|
+
* `label` (or its `type` when it has no `label`)
|
|
48
|
+
* - Adds the helpers to the file's `@opencrvs/toolkit/events` import
|
|
49
|
+
* - Logs events without a NOTIFY action, which cannot be notified
|
|
50
|
+
* - Logs, without changing, configs it cannot rewrite safely: a config not
|
|
51
|
+
* given as an object literal, `actions` that is not an array literal, a
|
|
52
|
+
* NOTIFY action not written inline, and a DECLARE `declaration` or
|
|
53
|
+
* `review` not given as a name (e.g. written inline)
|
|
54
|
+
* - Saves the modified files in-place
|
|
55
|
+
*/
|
|
56
|
+
const ts_morph_1 = require("ts-morph");
|
|
57
|
+
const path_1 = __importDefault(require("path"));
|
|
58
|
+
const utils_1 = require("./utils");
|
|
59
|
+
const DEFINE_CONFIG_NAME = 'defineConfig';
|
|
60
|
+
const ACTIONS_PROPERTY_NAME = 'actions';
|
|
61
|
+
const DECLARATION_PROPERTY_NAME = 'declaration';
|
|
62
|
+
const NOTIFY_ACTION_TYPE = 'NOTIFY';
|
|
63
|
+
const DECLARE_ACTION_TYPE = 'DECLARE';
|
|
64
|
+
/** The NOTIFY properties added, each copied from a DECLARE property through a toolkit helper. */
|
|
65
|
+
const NOTIFY_PROPERTIES = [
|
|
66
|
+
{
|
|
67
|
+
name: 'notificationForm',
|
|
68
|
+
helper: 'toNotificationForm',
|
|
69
|
+
declareProperty: DECLARATION_PROPERTY_NAME
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: 'review',
|
|
73
|
+
helper: 'toNotificationReview',
|
|
74
|
+
declareProperty: 'review'
|
|
75
|
+
}
|
|
76
|
+
];
|
|
77
|
+
/**
|
|
78
|
+
* Returns the value of the property as text when it is a name or a property
|
|
79
|
+
* access, which can be referred to again from the NOTIFY action.
|
|
80
|
+
*/
|
|
81
|
+
function referenceOf(property) {
|
|
82
|
+
if (ts_morph_1.Node.isShorthandPropertyAssignment(property)) {
|
|
83
|
+
return property.getName();
|
|
84
|
+
}
|
|
85
|
+
const value = property === null || property === void 0 ? void 0 : property.getInitializer();
|
|
86
|
+
return ts_morph_1.Node.isIdentifier(value) || ts_morph_1.Node.isPropertyAccessExpression(value)
|
|
87
|
+
? value.getText()
|
|
88
|
+
: undefined;
|
|
89
|
+
}
|
|
90
|
+
function findConfigLiteral(call) {
|
|
91
|
+
const config = call.getArguments()[0];
|
|
92
|
+
if (ts_morph_1.Node.isObjectLiteralExpression(config)) {
|
|
93
|
+
return config;
|
|
94
|
+
}
|
|
95
|
+
console.warn(` [${(0, utils_1.location)(call)}] Skipped: \`${DEFINE_CONFIG_NAME}\` is not given an object literal. If the event has a NOTIFY action, give it a \`notificationForm\` and \`review\` by hand.`);
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Finds the NOTIFY action in `actions`, or logs why the config is not
|
|
100
|
+
* rewritten and returns undefined.
|
|
101
|
+
*/
|
|
102
|
+
function findNotifyAction(config, actions) {
|
|
103
|
+
const candidates = actions.filter((action) => (0, utils_1.mayBeAction)(action, NOTIFY_ACTION_TYPE));
|
|
104
|
+
if (candidates.length === 0) {
|
|
105
|
+
console.warn(` [${(0, utils_1.location)(config)}] No ${NOTIFY_ACTION_TYPE} action: the event cannot be notified. If a role has \`record.notify\` for it, add a ${NOTIFY_ACTION_TYPE} action with a \`notificationForm\` and \`review\`.`);
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
if (candidates.length !== 1 ||
|
|
109
|
+
!ts_morph_1.Node.isObjectLiteralExpression(candidates[0])) {
|
|
110
|
+
console.warn(` [${(0, utils_1.location)(config)}] Skipped: could not find exactly one ${NOTIFY_ACTION_TYPE} action written as an object literal in \`${ACTIONS_PROPERTY_NAME}\`. Give it a \`notificationForm\` and \`review\` by hand.`);
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
return candidates[0];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Returns the edit inserting the properties into the action after its `label`,
|
|
117
|
+
* or after its `type` when it has no `label`, in the action's own layout: on
|
|
118
|
+
* lines of their own at the anchor's indentation, or inline when the action is
|
|
119
|
+
* on one line.
|
|
120
|
+
*/
|
|
121
|
+
function insertIntoAction(action, properties) {
|
|
122
|
+
var _a;
|
|
123
|
+
// `type` is always there: it is how the action was found
|
|
124
|
+
const anchor = (_a = action.getProperty('label')) !== null && _a !== void 0 ? _a : action.getPropertyOrThrow('type');
|
|
125
|
+
const text = action.getSourceFile().getFullText();
|
|
126
|
+
const anchorLayout = (0, utils_1.layoutOf)(anchor);
|
|
127
|
+
const indent = (0, utils_1.indentationOf)(anchor);
|
|
128
|
+
if (anchorLayout.ownsLines) {
|
|
129
|
+
const position = anchorLayout.end + (0, utils_1.restOfLine)(text, anchorLayout.end).length;
|
|
130
|
+
const lines = properties.map((property) => `\n${indent}${property}`);
|
|
131
|
+
if (anchorLayout.hasComma) {
|
|
132
|
+
return [(0, utils_1.insertAt)(position, `${lines.join(',')},`)];
|
|
133
|
+
}
|
|
134
|
+
// The anchor was the last property: it needs a comma now
|
|
135
|
+
return position === anchor.getEnd()
|
|
136
|
+
? [(0, utils_1.insertAt)(position, `,${lines.join(',')}`)]
|
|
137
|
+
: [(0, utils_1.insertAt)(anchor.getEnd(), ','), (0, utils_1.insertAt)(position, lines.join(','))];
|
|
138
|
+
}
|
|
139
|
+
const separator = action.getText().includes('\n') ? `,\n${indent}` : ', ';
|
|
140
|
+
return [
|
|
141
|
+
(0, utils_1.insertAt)(anchor.getEnd(), properties.map((property) => `${separator}${property}`).join(''))
|
|
142
|
+
];
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Adds the missing `notificationForm` and `review` to the NOTIFY action of
|
|
146
|
+
* every toolkit `defineConfig` call in the file.
|
|
147
|
+
*
|
|
148
|
+
* @returns the number of NOTIFY actions rewritten.
|
|
149
|
+
*/
|
|
150
|
+
function addNotifyConfig(sourceFile) {
|
|
151
|
+
const configs = sourceFile
|
|
152
|
+
.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression)
|
|
153
|
+
.filter(utils_1.isToolkitDefineConfigCall)
|
|
154
|
+
.map(findConfigLiteral)
|
|
155
|
+
.filter(ts_morph_1.Node.isObjectLiteralExpression);
|
|
156
|
+
const helperNames = Object.fromEntries(NOTIFY_PROPERTIES.map(({ helper }) => [
|
|
157
|
+
helper,
|
|
158
|
+
(0, utils_1.findToolkitImportName)(sourceFile, helper)
|
|
159
|
+
]));
|
|
160
|
+
const edits = [];
|
|
161
|
+
const usedHelpers = new Set();
|
|
162
|
+
let changes = 0;
|
|
163
|
+
for (const config of configs) {
|
|
164
|
+
const actions = (0, utils_1.findProperty)(config, ACTIONS_PROPERTY_NAME);
|
|
165
|
+
const actionsValue = ts_morph_1.Node.isPropertyAssignment(actions)
|
|
166
|
+
? actions.getInitializer()
|
|
167
|
+
: undefined;
|
|
168
|
+
if (!ts_morph_1.Node.isArrayLiteralExpression(actionsValue)) {
|
|
169
|
+
console.warn(` [${(0, utils_1.location)(config)}] Skipped: \`${ACTIONS_PROPERTY_NAME}\` is not an array literal. If the event has a ${NOTIFY_ACTION_TYPE} action, give it a \`notificationForm\` and \`review\` by hand.`);
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
const notifyAction = findNotifyAction(config, actionsValue.getElements());
|
|
173
|
+
if (!notifyAction) {
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
const declareAction = actionsValue
|
|
177
|
+
.getElements()
|
|
178
|
+
.find((action) => ts_morph_1.Node.isObjectLiteralExpression(action) &&
|
|
179
|
+
(0, utils_1.isAction)(action, DECLARE_ACTION_TYPE));
|
|
180
|
+
const properties = NOTIFY_PROPERTIES.filter(({ name }) => !(0, utils_1.findProperty)(notifyAction, name)).flatMap(({ name, helper, declareProperty }) => {
|
|
181
|
+
var _a;
|
|
182
|
+
const helperName = helperNames[helper];
|
|
183
|
+
// A `declaration` not yet moved onto the DECLARE action is still at the top level
|
|
184
|
+
const reference = referenceOf((_a = (declareAction && (0, utils_1.findProperty)(declareAction, declareProperty))) !== null && _a !== void 0 ? _a : (declareProperty === DECLARATION_PROPERTY_NAME
|
|
185
|
+
? (0, utils_1.findProperty)(config, declareProperty)
|
|
186
|
+
: undefined));
|
|
187
|
+
if (!helperName) {
|
|
188
|
+
console.warn(` [${(0, utils_1.location)(notifyAction)}] Skipped \`${name}\`: the file already declares its own \`${helper}\`. Add \`${name}\` to the ${NOTIFY_ACTION_TYPE} action by hand, using the toolkit's \`${helper}\`.`);
|
|
189
|
+
return [];
|
|
190
|
+
}
|
|
191
|
+
if (!reference) {
|
|
192
|
+
console.warn(` [${(0, utils_1.location)(notifyAction)}] Skipped \`${name}\`: the ${DECLARE_ACTION_TYPE} action's \`${declareProperty}\` is not given as a name. Add \`${name}: ${helper}(<${DECLARE_ACTION_TYPE} ${declareProperty}>)\` to the ${NOTIFY_ACTION_TYPE} action by hand.`);
|
|
193
|
+
return [];
|
|
194
|
+
}
|
|
195
|
+
if (helperName === helper) {
|
|
196
|
+
usedHelpers.add(helper);
|
|
197
|
+
}
|
|
198
|
+
return [`${name}: ${helperName}(${reference})`];
|
|
199
|
+
});
|
|
200
|
+
if (properties.length === 0) {
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
console.log(` [${(0, utils_1.location)(notifyAction)}] Added \`${properties.join('`, `')}\` to the ${NOTIFY_ACTION_TYPE} action`);
|
|
204
|
+
edits.push(...insertIntoAction(notifyAction, properties));
|
|
205
|
+
changes++;
|
|
206
|
+
}
|
|
207
|
+
if (changes === 0) {
|
|
208
|
+
return 0;
|
|
209
|
+
}
|
|
210
|
+
(0, utils_1.applyTextEdits)(sourceFile, edits);
|
|
211
|
+
for (const helper of usedHelpers) {
|
|
212
|
+
(0, utils_1.addToolkitImport)(sourceFile, helper);
|
|
213
|
+
}
|
|
214
|
+
return changes;
|
|
215
|
+
}
|
|
216
|
+
function main() {
|
|
217
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
218
|
+
const srcDir = path_1.default.join(process.cwd(), 'src');
|
|
219
|
+
console.log(`Scanning for NOTIFY actions in: ${srcDir}\n`);
|
|
220
|
+
const project = new ts_morph_1.Project({
|
|
221
|
+
tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
|
|
222
|
+
skipAddingFilesFromTsConfig: false
|
|
223
|
+
});
|
|
224
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
225
|
+
const fp = sf.getFilePath();
|
|
226
|
+
return fp.includes('/src/') && !fp.includes('/node_modules/');
|
|
227
|
+
});
|
|
228
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
|
|
229
|
+
let totalChanges = 0;
|
|
230
|
+
const modifiedFiles = [];
|
|
231
|
+
for (const sourceFile of sourceFiles) {
|
|
232
|
+
const changes = addNotifyConfig(sourceFile);
|
|
233
|
+
if (changes > 0) {
|
|
234
|
+
totalChanges += changes;
|
|
235
|
+
modifiedFiles.push(sourceFile);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (modifiedFiles.length === 0) {
|
|
239
|
+
console.log('No NOTIFY actions to update. Nothing to do.');
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
|
|
243
|
+
for (const sourceFile of modifiedFiles) {
|
|
244
|
+
yield sourceFile.save();
|
|
245
|
+
console.log(` Saved: ${path_1.default.relative(process.cwd(), sourceFile.getFilePath())}`);
|
|
246
|
+
}
|
|
247
|
+
console.log(`\nDone. Updated ${totalChanges} NOTIFY action(s) across ${modifiedFiles.length} file(s).`);
|
|
248
|
+
});
|
|
249
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run the upgrade process for the country config in the current working
|
|
3
|
+
* directory.
|
|
4
|
+
*
|
|
5
|
+
* @param toolkitVersion the version of the toolkit running the upgrade, e.g.
|
|
6
|
+
* `2.2.0` or `2.2.0-rc.1`. The country config is upgraded to its major.minor.
|
|
7
|
+
*/
|
|
8
|
+
export declare function runUpgrade(toolkitVersion: string): Promise<void>;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/migrations/index.ts"],"names":[],"mappings":"AAkBA;;;;;;GAMG;AACH,wBAAsB,UAAU,CAAC,cAAc,EAAE,MAAM,iBActD"}
|