@opencrvs/toolkit 1.9.15-rc.fc1c0fb → 2.0.0-rc.004e65c
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 +13 -0
- package/create-countryconfig/index.js +103 -0
- package/create-countryconfig/package.json +21 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/application-config/index.d.ts +2 -0
- package/dist/application-config/index.d.ts.map +1 -0
- package/dist/application-config/index.js +2304 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +5244 -0
- package/dist/commons/api/router.d.ts +5630 -3673
- package/dist/commons/application-config/index.d.ts +97 -0
- package/dist/commons/conditionals/conditionals.d.ts +33 -3
- package/dist/commons/conditionals/validate.d.ts +20 -1
- package/dist/commons/events/ActionConfig.d.ts +415 -1555
- package/dist/commons/events/ActionDocument.d.ts +894 -1941
- package/dist/commons/events/ActionInput.d.ts +326 -1212
- package/dist/commons/events/ActionType.d.ts +91 -11
- package/dist/commons/events/AdvancedSearchConfig.d.ts +636 -1496
- package/dist/commons/events/AuditLog.d.ts +407 -0
- package/dist/commons/events/CompositeFieldValue.d.ts +30 -190
- package/dist/commons/events/Conditional.d.ts +26 -38
- package/dist/commons/events/Constants.d.ts +1 -1
- package/dist/commons/events/CountryConfigQueryInput.d.ts +1592 -4471
- package/dist/commons/events/DeduplicationConfig.d.ts +15 -171
- package/dist/commons/events/Draft.d.ts +72 -111
- package/dist/commons/events/DynamicFieldValue.d.ts +12 -78
- package/dist/commons/events/EventConfig.d.ts +37 -2427
- package/dist/commons/events/EventConfigInput.d.ts +0 -3
- package/dist/commons/events/EventDocument.d.ts +357 -1366
- package/dist/commons/events/EventIndex.d.ts +211 -1012
- package/dist/commons/events/EventInput.d.ts +3 -8
- package/dist/commons/events/EventMetadata.d.ts +129 -363
- package/dist/commons/events/FieldConfig.d.ts +3147 -14211
- package/dist/commons/events/FieldType.d.ts +26 -4
- package/dist/commons/events/FieldTypeMapping.d.ts +314 -906
- package/dist/commons/events/FieldValue.d.ts +154 -526
- package/dist/commons/events/FileUtils.d.ts +2 -2
- package/dist/commons/events/Flag.d.ts +67 -0
- package/dist/commons/events/FormConfig.d.ts +54 -721
- package/dist/commons/events/PageConfig.d.ts +58 -320
- package/dist/commons/events/PlainDate.d.ts +1 -1
- package/dist/commons/events/SummaryConfig.d.ts +14 -161
- package/dist/commons/events/TemplateConfig.d.ts +2 -3
- package/dist/commons/events/TranslationConfig.d.ts +2 -2
- package/dist/commons/events/WorkqueueColumnConfig.d.ts +74 -37
- package/dist/commons/events/WorkqueueConfig.d.ts +2232 -7577
- package/dist/commons/events/deduplication.d.ts +3 -3
- package/dist/commons/events/defineConfig.d.ts +2 -248
- package/dist/commons/events/eventConfigValidation.d.ts +8 -0
- package/dist/commons/events/field.d.ts +6 -0
- package/dist/commons/events/index.d.ts +5 -0
- package/dist/commons/events/locations.d.ts +93 -19
- package/dist/commons/events/mocks.test.utils.d.ts +19 -0
- package/dist/commons/events/scopes.d.ts +56 -32
- package/dist/commons/events/state/availableActions.d.ts +7 -2
- package/dist/commons/events/state/flags.d.ts +37 -3
- package/dist/commons/events/state/index.d.ts +29 -30
- package/dist/commons/events/state/utils.d.ts +25 -284
- package/dist/commons/events/test.utils.d.ts +52 -11
- package/dist/commons/events/transactions.d.ts +1 -1
- package/dist/commons/events/utils.d.ts +383 -273
- package/dist/commons/notification/UserNotifications.d.ts +76 -637
- package/dist/conditionals/index.d.ts.map +1 -1
- package/dist/conditionals/index.js +338 -14
- package/dist/events/deduplication.d.ts +3 -3
- package/dist/events/index.js +3700 -2236
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts +3 -0
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -0
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +429 -0
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +3 -0
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +1 -0
- package/dist/migrations/v2.0/add-resend-invite-notification.js +373 -0
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts +22 -0
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -0
- package/dist/migrations/v2.0/checkout-upstream-files.js +146 -0
- package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts +2 -0
- package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -0
- package/dist/migrations/v2.0/convert-config-files-to-ts.js +828 -0
- package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +3 -0
- package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -0
- package/dist/migrations/v2.0/convert-paragraph-to-heading.js +158 -0
- package/dist/migrations/v2.0/create-events-index.d.ts +3 -0
- package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -0
- package/dist/migrations/v2.0/create-events-index.js +325 -0
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +11 -0
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -0
- package/dist/migrations/v2.0/delete-infrastructure-directory.js +123 -0
- package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts +3 -0
- package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts.map +1 -0
- package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.js +110 -0
- package/dist/migrations/v2.0/index.d.ts +13 -0
- package/dist/migrations/v2.0/index.d.ts.map +1 -0
- package/dist/migrations/v2.0/index.js +5154 -0
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +3 -0
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -0
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +432 -0
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +13 -0
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -0
- package/dist/migrations/v2.0/merge-infrastructure-directory.js +222 -0
- package/dist/migrations/v2.0/migrate-application-config-url.d.ts +3 -0
- package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +1 -0
- package/dist/migrations/v2.0/migrate-application-config-url.js +342 -0
- package/dist/migrations/v2.0/migrate-scopes.d.ts +3 -0
- package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -0
- package/dist/migrations/v2.0/migrate-scopes.js +305 -0
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +3 -0
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -0
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +267 -0
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +3 -0
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -0
- package/dist/migrations/v2.0/migrate-workqueue-configs.js +317 -0
- package/dist/migrations/v2.0/remove-delete-actions.d.ts +3 -0
- package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-delete-actions.js +156 -0
- package/dist/migrations/v2.0/remove-demo-scope.d.ts +3 -0
- package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-demo-scope.js +74 -0
- package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +3 -0
- package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-deprecated-imports.js +96 -0
- package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +3 -0
- package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-fhir-url-helpers.js +163 -0
- package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +3 -0
- package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-hearth-migrations.js +77 -0
- package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +3 -0
- package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-old-statistics-service.js +356 -0
- package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +3 -0
- package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-pending-certification-flag.js +109 -0
- package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +3 -0
- package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-review-from-register-action.js +163 -0
- package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +3 -0
- package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-unused-environment-variables.js +186 -0
- package/dist/migrations/v2.0/rename-api-paths.d.ts +3 -0
- package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -0
- package/dist/migrations/v2.0/rename-api-paths.js +187 -0
- package/dist/migrations/v2.0/rename-location-parent-id.d.ts +3 -0
- package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -0
- package/dist/migrations/v2.0/rename-location-parent-id.js +180 -0
- package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +3 -0
- package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -0
- package/dist/migrations/v2.0/simplify-analytics-precalculations.js +195 -0
- package/dist/migrations/v2.0/update-package-json.d.ts +3 -0
- package/dist/migrations/v2.0/update-package-json.d.ts.map +1 -0
- package/dist/migrations/v2.0/update-package-json.js +105 -0
- package/dist/notification/index.d.ts.map +1 -1
- package/dist/notification/index.js +2731 -1849
- package/dist/scopes/index.d.ts +714 -352
- package/dist/scopes/index.d.ts.map +1 -1
- package/dist/scopes/index.js +381 -298
- package/opencrvs-toolkit-2.0.0-rc.004e65c.tgz +0 -0
- package/package.json +14 -4
- package/tsconfig.json +12 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/commons/events/CreatedAtLocation.d.ts +0 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-built-in-validate-actions-custom.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/make-built-in-validate-actions-custom.ts"],"names":[],"mappings":"AAodA,iBAAe,IAAI,kBAiDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1,432 @@
|
|
|
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: Transform `VALIDATE` type actions into `CUSTOM` actions inside `defineConfig` calls.
|
|
28
|
+
*
|
|
29
|
+
* Usage:
|
|
30
|
+
* ts-node -r tsconfig-paths/register src/migrations/v2.0/make-built-in-validate-actions-custom.ts
|
|
31
|
+
*
|
|
32
|
+
* What it does:
|
|
33
|
+
* - Scans all TypeScript files under `src/`
|
|
34
|
+
* - Finds every `defineConfig({ ... })` call expression
|
|
35
|
+
* - Inside the `actions` array of that config, locates object literals
|
|
36
|
+
* whose `type` property resolves to `ActionType.VALIDATE` or the string literal `"VALIDATE"`
|
|
37
|
+
* - Changes the `type` value to `ActionType.CUSTOM` (or `"CUSTOM"` for string literals)
|
|
38
|
+
* - Adds a `customActionType: 'VALIDATE_DECLARATION'` property to those objects
|
|
39
|
+
* - Adds an `auditHistoryLabel` intl descriptor whose `id` is derived from the
|
|
40
|
+
* root `type` value of the `defineConfig` config object
|
|
41
|
+
* - Removes the `deduplication` property from those objects
|
|
42
|
+
* - Replaces `review: { fields: <value> }` with `form: <value>`, or
|
|
43
|
+
* `review: <expr>` with `form: <expr>.fields` when the value is not an inline object
|
|
44
|
+
* - Adds the top-level `validated` flag definition and `{ id: 'validated',
|
|
45
|
+
* operation: 'add' }` to the (now custom) validate action
|
|
46
|
+
* - Adds `{ id: 'validated', operation: 'remove' }` to every `REGISTER` action
|
|
47
|
+
* in the same config, closing the flag's lifecycle when registration happens
|
|
48
|
+
* - Saves the modified files in-place
|
|
49
|
+
*/
|
|
50
|
+
const ts_morph_1 = require("ts-morph");
|
|
51
|
+
const path_1 = __importDefault(require("path"));
|
|
52
|
+
const TOOLKIT_EVENTS_MODULE = '@opencrvs/toolkit/events';
|
|
53
|
+
const REQUIRED_SYMBOLS = [
|
|
54
|
+
'ConditionalType',
|
|
55
|
+
'and',
|
|
56
|
+
'status',
|
|
57
|
+
'not',
|
|
58
|
+
'flag',
|
|
59
|
+
'InherentFlags'
|
|
60
|
+
];
|
|
61
|
+
function ensureImports(sourceFile) {
|
|
62
|
+
const existingImport = sourceFile.getImportDeclaration((decl) => decl.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE);
|
|
63
|
+
if (existingImport) {
|
|
64
|
+
const existingNames = new Set(existingImport.getNamedImports().map((ni) => ni.getName()));
|
|
65
|
+
for (const name of REQUIRED_SYMBOLS) {
|
|
66
|
+
if (!existingNames.has(name)) {
|
|
67
|
+
existingImport.addNamedImport(name);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
sourceFile.addImportDeclaration({
|
|
73
|
+
moduleSpecifier: TOOLKIT_EVENTS_MODULE,
|
|
74
|
+
namedImports: REQUIRED_SYMBOLS
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const DEFINE_CONFIG_NAME = 'defineConfig';
|
|
79
|
+
const ACTIONS_PROPERTY_NAME = 'actions';
|
|
80
|
+
const TYPE_PROPERTY_NAME = 'type';
|
|
81
|
+
const ID_PROPERTY_NAME = 'id';
|
|
82
|
+
const FLAGS_PROPERTY_NAME = 'flags';
|
|
83
|
+
const CUSTOM_ACTION_TYPE_PROPERTY_NAME = 'customActionType';
|
|
84
|
+
const AUDIT_HISTORY_LABEL_PROPERTY_NAME = 'auditHistoryLabel';
|
|
85
|
+
const DEDUPLICATION_PROPERTY_NAME = 'deduplication';
|
|
86
|
+
const REVIEW_PROPERTY_NAME = 'review';
|
|
87
|
+
const FIELDS_PROPERTY_NAME = 'fields';
|
|
88
|
+
const FORM_PROPERTY_NAME = 'form';
|
|
89
|
+
const ACTION_TYPE_ENUM_NAME = 'ActionType';
|
|
90
|
+
const VALIDATE_MEMBER_NAME = 'VALIDATE';
|
|
91
|
+
const CUSTOM_MEMBER_NAME = 'CUSTOM';
|
|
92
|
+
const REGISTER_MEMBER_NAME = 'REGISTER';
|
|
93
|
+
const VALIDATE_STRING_LITERAL = 'VALIDATE';
|
|
94
|
+
const CUSTOM_STRING_LITERAL = 'CUSTOM';
|
|
95
|
+
const REGISTER_STRING_LITERAL = 'REGISTER';
|
|
96
|
+
const VALIDATE_DECLARATION_VALUE = 'VALIDATE_DECLARATION';
|
|
97
|
+
const VALIDATED_FLAG_VALUE = 'validated';
|
|
98
|
+
function isValidateType(typeInitializer) {
|
|
99
|
+
// Matches: ActionType.VALIDATE
|
|
100
|
+
if (typeInitializer.getKind() === ts_morph_1.SyntaxKind.PropertyAccessExpression) {
|
|
101
|
+
const propAccess = typeInitializer.asKindOrThrow(ts_morph_1.SyntaxKind.PropertyAccessExpression);
|
|
102
|
+
const obj = propAccess.getExpression();
|
|
103
|
+
const member = propAccess.getName();
|
|
104
|
+
return (ts_morph_1.Node.isIdentifier(obj) &&
|
|
105
|
+
obj.getText() === ACTION_TYPE_ENUM_NAME &&
|
|
106
|
+
member === VALIDATE_MEMBER_NAME);
|
|
107
|
+
}
|
|
108
|
+
// Matches: "VALIDATE"
|
|
109
|
+
if (typeInitializer.getKind() === ts_morph_1.SyntaxKind.StringLiteral) {
|
|
110
|
+
return (typeInitializer
|
|
111
|
+
.asKindOrThrow(ts_morph_1.SyntaxKind.StringLiteral)
|
|
112
|
+
.getLiteralValue() === VALIDATE_STRING_LITERAL);
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
function resolveEventType(configArg) {
|
|
117
|
+
const typeProperty = configArg.getProperty(TYPE_PROPERTY_NAME);
|
|
118
|
+
if (!typeProperty || !ts_morph_1.Node.isPropertyAssignment(typeProperty))
|
|
119
|
+
return null;
|
|
120
|
+
const initializer = typeProperty.getInitializer();
|
|
121
|
+
if (!initializer)
|
|
122
|
+
return null;
|
|
123
|
+
// 'birth' / 'death' etc. — use the literal value directly
|
|
124
|
+
if (ts_morph_1.Node.isStringLiteral(initializer)) {
|
|
125
|
+
return initializer.getLiteralValue().toLowerCase();
|
|
126
|
+
}
|
|
127
|
+
// EventType.BIRTH — extract and lowercase the member name
|
|
128
|
+
if (initializer.getKind() === ts_morph_1.SyntaxKind.PropertyAccessExpression &&
|
|
129
|
+
ts_morph_1.Node.isPropertyAccessExpression(initializer)) {
|
|
130
|
+
return initializer.getName().toLowerCase();
|
|
131
|
+
}
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
function transformValidateActionToCustom(obj, eventType) {
|
|
135
|
+
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME);
|
|
136
|
+
if (!typeProperty || !ts_morph_1.Node.isPropertyAssignment(typeProperty)) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
const typeInitializer = typeProperty.getInitializer();
|
|
140
|
+
if (!typeInitializer || !isValidateType(typeInitializer)) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
// Replace the type value: ActionType.VALIDATE -> ActionType.CUSTOM, "VALIDATE" -> "CUSTOM"
|
|
144
|
+
if (typeInitializer.getKind() === ts_morph_1.SyntaxKind.PropertyAccessExpression) {
|
|
145
|
+
typeInitializer.replaceWithText(`${ACTION_TYPE_ENUM_NAME}.${CUSTOM_MEMBER_NAME}`);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
typeInitializer.replaceWithText(`'${CUSTOM_STRING_LITERAL}'`);
|
|
149
|
+
}
|
|
150
|
+
// Add customActionType: 'VALIDATE_DECLARATION' if not already present
|
|
151
|
+
if (!obj.getProperty(CUSTOM_ACTION_TYPE_PROPERTY_NAME)) {
|
|
152
|
+
obj.addPropertyAssignment({
|
|
153
|
+
name: CUSTOM_ACTION_TYPE_PROPERTY_NAME,
|
|
154
|
+
initializer: `'${VALIDATE_DECLARATION_VALUE}'`
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
// Add auditHistoryLabel intl descriptor if not already present
|
|
158
|
+
if (!obj.getProperty(AUDIT_HISTORY_LABEL_PROPERTY_NAME)) {
|
|
159
|
+
const messageId = `event.${eventType}.custom.action.validate-declaration.audit-history-label`;
|
|
160
|
+
obj.addPropertyAssignment({
|
|
161
|
+
name: AUDIT_HISTORY_LABEL_PROPERTY_NAME,
|
|
162
|
+
initializer: `{
|
|
163
|
+
defaultMessage: 'Validated',
|
|
164
|
+
description: 'The label to show in audit history for the validate action',
|
|
165
|
+
id: '${messageId}'
|
|
166
|
+
}`
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
// Add supportingCopy intl descriptor if not already present
|
|
170
|
+
if (!obj.getProperty('supportingCopy')) {
|
|
171
|
+
const supportingCopyId = `event.${eventType}.custom.action.validate-declaration.supportingCopy`;
|
|
172
|
+
obj.addPropertyAssignment({
|
|
173
|
+
name: 'supportingCopy',
|
|
174
|
+
initializer: `{
|
|
175
|
+
defaultMessage:
|
|
176
|
+
'Approving this declaration confirms it as legally accepted and eligible for registration.',
|
|
177
|
+
description:
|
|
178
|
+
'This is the supporting copy for the Validate declaration -action',
|
|
179
|
+
id: '${supportingCopyId}'
|
|
180
|
+
}`
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
// Add conditionals if not already present
|
|
184
|
+
if (!obj.getProperty('conditionals')) {
|
|
185
|
+
obj.addPropertyAssignment({
|
|
186
|
+
name: 'conditionals',
|
|
187
|
+
initializer: `[
|
|
188
|
+
{
|
|
189
|
+
type: ConditionalType.SHOW,
|
|
190
|
+
conditional: and(status('DECLARED'), not(flag('validated')))
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
type: ConditionalType.ENABLE,
|
|
194
|
+
conditional: not(flag(InherentFlags.POTENTIAL_DUPLICATE))
|
|
195
|
+
}
|
|
196
|
+
]`
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
// Add flags if not already present
|
|
200
|
+
if (!obj.getProperty('flags')) {
|
|
201
|
+
obj.addPropertyAssignment({
|
|
202
|
+
name: 'flags',
|
|
203
|
+
initializer: `[{ id: 'validated', operation: 'add' }]`
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
// Remove the `deduplication` property if present
|
|
207
|
+
const deduplicationProperty = obj.getProperty(DEDUPLICATION_PROPERTY_NAME);
|
|
208
|
+
if (deduplicationProperty) {
|
|
209
|
+
deduplicationProperty.remove();
|
|
210
|
+
}
|
|
211
|
+
// Replace `review` with `form`:
|
|
212
|
+
// - `review: { fields: <value> }` → `form: <value>`
|
|
213
|
+
// - `review: <expr>` → `form: <expr>.fields`
|
|
214
|
+
const reviewProperty = obj.getProperty(REVIEW_PROPERTY_NAME);
|
|
215
|
+
if (reviewProperty && ts_morph_1.Node.isPropertyAssignment(reviewProperty)) {
|
|
216
|
+
const reviewInitializer = reviewProperty.getInitializer();
|
|
217
|
+
if (reviewInitializer) {
|
|
218
|
+
if (ts_morph_1.Node.isObjectLiteralExpression(reviewInitializer)) {
|
|
219
|
+
// Inline object: extract the `fields` value directly
|
|
220
|
+
const fieldsProperty = reviewInitializer.getProperty(FIELDS_PROPERTY_NAME);
|
|
221
|
+
if (fieldsProperty && ts_morph_1.Node.isPropertyAssignment(fieldsProperty)) {
|
|
222
|
+
const fieldsInitializer = fieldsProperty.getInitializer();
|
|
223
|
+
if (fieldsInitializer) {
|
|
224
|
+
reviewProperty.set({
|
|
225
|
+
name: FORM_PROPERTY_NAME,
|
|
226
|
+
initializer: fieldsInitializer.getText()
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
// Reference or other expression: append `.fields`
|
|
233
|
+
reviewProperty.set({
|
|
234
|
+
name: FORM_PROPERTY_NAME,
|
|
235
|
+
initializer: `${reviewInitializer.getText()}.fields`
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
function isRegisterAction(action) {
|
|
243
|
+
const typeProperty = action.getProperty(TYPE_PROPERTY_NAME);
|
|
244
|
+
if (!typeProperty || !ts_morph_1.Node.isPropertyAssignment(typeProperty))
|
|
245
|
+
return false;
|
|
246
|
+
const typeInit = typeProperty.getInitializer();
|
|
247
|
+
if (!typeInit)
|
|
248
|
+
return false;
|
|
249
|
+
// Matches: ActionType.REGISTER
|
|
250
|
+
if (ts_morph_1.Node.isPropertyAccessExpression(typeInit)) {
|
|
251
|
+
const enumExpr = typeInit.getExpression();
|
|
252
|
+
return (ts_morph_1.Node.isIdentifier(enumExpr) &&
|
|
253
|
+
enumExpr.getText() === ACTION_TYPE_ENUM_NAME &&
|
|
254
|
+
typeInit.getName() === REGISTER_MEMBER_NAME);
|
|
255
|
+
}
|
|
256
|
+
// Matches: "REGISTER"
|
|
257
|
+
if (ts_morph_1.Node.isStringLiteral(typeInit)) {
|
|
258
|
+
return typeInit.getLiteralValue() === REGISTER_STRING_LITERAL;
|
|
259
|
+
}
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Returns true if an array literal contains an object literal with `id: <id>`.
|
|
264
|
+
*/
|
|
265
|
+
function arrayHasElementWithId(array, id) {
|
|
266
|
+
for (const el of array.getElements()) {
|
|
267
|
+
if (!ts_morph_1.Node.isObjectLiteralExpression(el))
|
|
268
|
+
continue;
|
|
269
|
+
const idProp = el.getProperty(ID_PROPERTY_NAME);
|
|
270
|
+
if (!idProp || !ts_morph_1.Node.isPropertyAssignment(idProp))
|
|
271
|
+
continue;
|
|
272
|
+
const idInit = idProp.getInitializer();
|
|
273
|
+
if (idInit &&
|
|
274
|
+
ts_morph_1.Node.isStringLiteral(idInit) &&
|
|
275
|
+
idInit.getLiteralValue() === id) {
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Adds `{ id: 'validated', operation: 'remove' }` to a REGISTER action's
|
|
283
|
+
* `flags` array. Skips if any `validated` flag entry is already present —
|
|
284
|
+
* this keeps the codemod idempotent and avoids stomping on an intentional
|
|
285
|
+
* `add` op a maintainer may have authored manually.
|
|
286
|
+
*
|
|
287
|
+
* Returns true if a change was made.
|
|
288
|
+
*/
|
|
289
|
+
function ensureRegisterRemovesValidatedFlag(action) {
|
|
290
|
+
const entry = `{ id: '${VALIDATED_FLAG_VALUE}', operation: 'remove' }`;
|
|
291
|
+
const flagsProp = action.getProperty(FLAGS_PROPERTY_NAME);
|
|
292
|
+
if (flagsProp && ts_morph_1.Node.isPropertyAssignment(flagsProp)) {
|
|
293
|
+
const flagsInit = flagsProp.getInitializer();
|
|
294
|
+
if (flagsInit && ts_morph_1.Node.isArrayLiteralExpression(flagsInit)) {
|
|
295
|
+
if (arrayHasElementWithId(flagsInit, VALIDATED_FLAG_VALUE))
|
|
296
|
+
return false;
|
|
297
|
+
flagsInit.addElement(entry);
|
|
298
|
+
return true;
|
|
299
|
+
}
|
|
300
|
+
return false;
|
|
301
|
+
}
|
|
302
|
+
action.addPropertyAssignment({
|
|
303
|
+
name: FLAGS_PROPERTY_NAME,
|
|
304
|
+
initializer: `[${entry}]`
|
|
305
|
+
});
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
function processFile(filePath, project) {
|
|
309
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
310
|
+
if (!sourceFile)
|
|
311
|
+
return 0;
|
|
312
|
+
let transformedCount = 0;
|
|
313
|
+
// Find all call expressions named `defineConfig`
|
|
314
|
+
const callExpressions = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
315
|
+
for (const call of callExpressions) {
|
|
316
|
+
const expression = call.getExpression();
|
|
317
|
+
// Only interested in bare `defineConfig(...)` calls
|
|
318
|
+
if (!ts_morph_1.Node.isIdentifier(expression) ||
|
|
319
|
+
expression.getText() !== DEFINE_CONFIG_NAME) {
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
const args = call.getArguments();
|
|
323
|
+
if (args.length === 0)
|
|
324
|
+
continue;
|
|
325
|
+
// The first argument should be the config object literal
|
|
326
|
+
const configArg = args[0];
|
|
327
|
+
if (!ts_morph_1.Node.isObjectLiteralExpression(configArg))
|
|
328
|
+
continue;
|
|
329
|
+
// Find the `actions` property inside the config object
|
|
330
|
+
const actionsProperty = configArg.getProperty(ACTIONS_PROPERTY_NAME);
|
|
331
|
+
if (!actionsProperty || !ts_morph_1.Node.isPropertyAssignment(actionsProperty))
|
|
332
|
+
continue;
|
|
333
|
+
const actionsInitializer = actionsProperty.getInitializer();
|
|
334
|
+
if (!actionsInitializer ||
|
|
335
|
+
!ts_morph_1.Node.isArrayLiteralExpression(actionsInitializer))
|
|
336
|
+
continue;
|
|
337
|
+
// Resolve the root event type for use in the auditHistoryLabel id
|
|
338
|
+
const eventType = resolveEventType(configArg);
|
|
339
|
+
if (!eventType) {
|
|
340
|
+
console.warn(` [${path_1.default.relative(process.cwd(), configArg.getSourceFile().getFilePath())}] Could not resolve root 'type' from defineConfig — skipping auditHistoryLabel id generation`);
|
|
341
|
+
}
|
|
342
|
+
// Iterate over every element in the `actions` array
|
|
343
|
+
let fileNeedsImports = false;
|
|
344
|
+
let configHadValidateAction = false;
|
|
345
|
+
for (const element of actionsInitializer.getElements()) {
|
|
346
|
+
if (!ts_morph_1.Node.isObjectLiteralExpression(element))
|
|
347
|
+
continue;
|
|
348
|
+
const wasTransformed = transformValidateActionToCustom(element, eventType !== null && eventType !== void 0 ? eventType : 'unknown');
|
|
349
|
+
if (wasTransformed) {
|
|
350
|
+
transformedCount++;
|
|
351
|
+
fileNeedsImports = true;
|
|
352
|
+
configHadValidateAction = true;
|
|
353
|
+
console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Transformed VALIDATE action to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'`);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
// Add top-level flags array to the config object if a VALIDATE action was found
|
|
357
|
+
if (configHadValidateAction && !configArg.getProperty('flags')) {
|
|
358
|
+
const resolvedEventType = eventType !== null && eventType !== void 0 ? eventType : 'unknown';
|
|
359
|
+
configArg.addPropertyAssignment({
|
|
360
|
+
name: 'flags',
|
|
361
|
+
initializer: `[
|
|
362
|
+
{
|
|
363
|
+
id: 'validated',
|
|
364
|
+
label: {
|
|
365
|
+
id: 'event.${resolvedEventType}.flag.validated',
|
|
366
|
+
defaultMessage: 'Validated',
|
|
367
|
+
description: 'Flag label for validated'
|
|
368
|
+
},
|
|
369
|
+
requiresAction: true
|
|
370
|
+
}
|
|
371
|
+
]`
|
|
372
|
+
});
|
|
373
|
+
console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Added top-level 'flags' array to defineConfig`);
|
|
374
|
+
}
|
|
375
|
+
// Close the `validated` flag's lifecycle: when the validate action adds the
|
|
376
|
+
// flag, the matching REGISTER action(s) must remove it on registration.
|
|
377
|
+
if (configHadValidateAction) {
|
|
378
|
+
for (const element of actionsInitializer.getElements()) {
|
|
379
|
+
if (!ts_morph_1.Node.isObjectLiteralExpression(element))
|
|
380
|
+
continue;
|
|
381
|
+
if (!isRegisterAction(element))
|
|
382
|
+
continue;
|
|
383
|
+
if (ensureRegisterRemovesValidatedFlag(element)) {
|
|
384
|
+
transformedCount++;
|
|
385
|
+
console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Added '${VALIDATED_FLAG_VALUE}' remove-flag to REGISTER action`);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
if (fileNeedsImports) {
|
|
390
|
+
ensureImports(sourceFile);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return transformedCount;
|
|
394
|
+
}
|
|
395
|
+
function main() {
|
|
396
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
397
|
+
const srcDir = path_1.default.join(process.cwd(), 'src');
|
|
398
|
+
console.log(`Scanning for defineConfig calls in: ${srcDir}\n`);
|
|
399
|
+
const project = new ts_morph_1.Project({
|
|
400
|
+
tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
|
|
401
|
+
// Do not emit — we only manipulate source files
|
|
402
|
+
skipAddingFilesFromTsConfig: false
|
|
403
|
+
});
|
|
404
|
+
// Restrict to source files only (exclude node_modules, build artefacts, etc.)
|
|
405
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
406
|
+
const fp = sf.getFilePath();
|
|
407
|
+
return fp.includes('/src/') && !fp.includes('/node_modules/');
|
|
408
|
+
});
|
|
409
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
|
|
410
|
+
let totalTransformed = 0;
|
|
411
|
+
const modifiedFiles = [];
|
|
412
|
+
for (const sourceFile of sourceFiles) {
|
|
413
|
+
const filePath = sourceFile.getFilePath();
|
|
414
|
+
const transformed = processFile(filePath, project);
|
|
415
|
+
if (transformed > 0) {
|
|
416
|
+
totalTransformed += transformed;
|
|
417
|
+
modifiedFiles.push(filePath);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
if (modifiedFiles.length === 0) {
|
|
421
|
+
console.log('No VALIDATE actions found inside defineConfig calls. Nothing to do.');
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
|
|
425
|
+
for (const filePath of modifiedFiles) {
|
|
426
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
427
|
+
yield sourceFile.save();
|
|
428
|
+
console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
|
|
429
|
+
}
|
|
430
|
+
console.log(`\nDone. Applied ${totalTransformed} change(s): VALIDATE → CUSTOM (${VALIDATE_DECLARATION_VALUE}) and '${VALIDATED_FLAG_VALUE}' remove-flag on matching REGISTER actions.`);
|
|
431
|
+
});
|
|
432
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface MergeInfrastructureOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Top-level subdirectories of `infrastructure/` to scope the merge to.
|
|
4
|
+
* When omitted or empty, the entire `infrastructure/` tree is merged
|
|
5
|
+
* (legacy behavior). Each name is relative to `infrastructure/` —
|
|
6
|
+
* e.g. `['postgres', 'metabase']` merges only
|
|
7
|
+
* `infrastructure/postgres/` and `infrastructure/metabase/`.
|
|
8
|
+
*/
|
|
9
|
+
subdirs?: string[];
|
|
10
|
+
}
|
|
11
|
+
declare function main({ subdirs }?: MergeInfrastructureOptions): Promise<void>;
|
|
12
|
+
export { main };
|
|
13
|
+
//# sourceMappingURL=merge-infrastructure-directory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-infrastructure-directory.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/merge-infrastructure-directory.ts"],"names":[],"mappings":"AAsHA,UAAU,0BAA0B;IAClC;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;CACnB;AAID,iBAAe,IAAI,CAAC,EAClB,OAAY,EACb,GAAE,0BAA+B,GAAG,OAAO,CAAC,IAAI,CAAC,CAoIjD;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|