@opencrvs/toolkit 1.9.13-rc.fc5374d → 2.0.0-rc.e0918cb
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/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 +2128 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +3633 -0
- package/dist/commons/api/router.d.ts +3438 -2300
- package/dist/commons/application-config/index.d.ts +84 -0
- package/dist/commons/conditionals/conditionals.d.ts +27 -3
- package/dist/commons/conditionals/validate.d.ts +13 -3
- package/dist/commons/events/ActionConfig.d.ts +415 -1555
- package/dist/commons/events/ActionDocument.d.ts +888 -1941
- package/dist/commons/events/ActionInput.d.ts +277 -1073
- package/dist/commons/events/ActionType.d.ts +91 -11
- package/dist/commons/events/AdvancedSearchConfig.d.ts +294 -1496
- package/dist/commons/events/AuditLog.d.ts +405 -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 -107
- package/dist/commons/events/DynamicFieldValue.d.ts +12 -78
- package/dist/commons/events/EventConfig.d.ts +37 -2420
- package/dist/commons/events/EventConfigInput.d.ts +0 -3
- package/dist/commons/events/EventDocument.d.ts +354 -1366
- package/dist/commons/events/EventIndex.d.ts +212 -1010
- package/dist/commons/events/EventInput.d.ts +3 -8
- package/dist/commons/events/EventMetadata.d.ts +130 -357
- package/dist/commons/events/FieldConfig.d.ts +2892 -12892
- 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 +149 -527
- 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 +2208 -7553
- package/dist/commons/events/deduplication.d.ts +3 -3
- package/dist/commons/events/defineConfig.d.ts +2 -247
- package/dist/commons/events/eventConfigValidation.d.ts +8 -0
- package/dist/commons/events/index.d.ts +3 -0
- package/dist/commons/events/locations.d.ts +57 -20
- package/dist/commons/events/scopes.d.ts +36 -35
- package/dist/commons/events/state/availableActions.d.ts +7 -2
- package/dist/commons/events/state/flags.d.ts +21 -3
- package/dist/commons/events/state/index.d.ts +30 -27
- package/dist/commons/events/state/utils.d.ts +190 -172
- 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 +373 -273
- package/dist/commons/notification/UserNotifications.d.ts +61 -637
- package/dist/conditionals/index.d.ts.map +1 -1
- package/dist/conditionals/index.js +302 -14
- package/dist/events/deduplication.d.ts +3 -3
- package/dist/events/index.js +2860 -2115
- 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 +405 -0
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts +3 -0
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -0
- package/dist/migrations/v2.0/checkout-upstream-files.js +143 -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 +829 -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 +159 -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 +326 -0
- package/dist/migrations/v2.0/index.d.ts +7 -0
- package/dist/migrations/v2.0/index.d.ts.map +1 -0
- package/dist/migrations/v2.0/index.js +3572 -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 +344 -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 +282 -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 +268 -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 +237 -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 +157 -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 +75 -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 +97 -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 +78 -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 +110 -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 +164 -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 +188 -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 +181 -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 +196 -0
- package/dist/notification/index.d.ts.map +1 -1
- package/dist/notification/index.js +2076 -1767
- package/dist/scopes/index.d.ts +640 -353
- package/dist/scopes/index.d.ts.map +1 -1
- package/dist/scopes/index.js +340 -300
- package/opencrvs-toolkit-2.0.0-rc.e0918cb.tgz +0 -0
- package/package.json +18 -8
- package/tsconfig.json +12 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/commons/events/CreatedAtLocation.d.ts +0 -2
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
4
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
5
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
6
|
+
*
|
|
7
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
8
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
9
|
+
*
|
|
10
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
11
|
+
*/
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.main = main;
|
|
26
|
+
/**
|
|
27
|
+
* Codemod: Migrate `VALIDATED` status references to flags inside `defineWorkqueues` calls.
|
|
28
|
+
*
|
|
29
|
+
* Usage:
|
|
30
|
+
* ts-node -r tsconfig-paths/register src/migrations/v2.0/migrate-validated-workqueue-status-to-flag.ts
|
|
31
|
+
*
|
|
32
|
+
* What it does:
|
|
33
|
+
* - Scans all TypeScript files under `src/`
|
|
34
|
+
* - Finds every `defineWorkqueues([...])` call expression
|
|
35
|
+
* - For each workqueue config's `query`, recursively walks `or`/`and` containers
|
|
36
|
+
* and processes every leaf clause object
|
|
37
|
+
* - In each clause:
|
|
38
|
+
* - `status: { type: 'anyOf', terms: [..., 'VALIDATED', ...] }`
|
|
39
|
+
* → removes `'VALIDATED'` from `terms`; removes `status` entirely if `terms`
|
|
40
|
+
* becomes empty; adds `'validated'` to `flags.anyOf`
|
|
41
|
+
* - `status: { type: 'exact', term: 'VALIDATED' }`
|
|
42
|
+
* → removes `status` entirely; adds `'validated'` to `flags.anyOf`
|
|
43
|
+
* - When adding to `flags.anyOf`, merges with an existing `flags` object if present
|
|
44
|
+
* - Saves the modified files in-place
|
|
45
|
+
*/
|
|
46
|
+
const ts_morph_1 = require("ts-morph");
|
|
47
|
+
const path_1 = __importDefault(require("path"));
|
|
48
|
+
const _1 = require(".");
|
|
49
|
+
const DEFINE_WORKQUEUES_NAME = 'defineWorkqueues';
|
|
50
|
+
const QUERY_PROPERTY_NAME = 'query';
|
|
51
|
+
const TYPE_PROPERTY_NAME = 'type';
|
|
52
|
+
const CLAUSES_PROPERTY_NAME = 'clauses';
|
|
53
|
+
const STATUS_PROPERTY_NAME = 'status';
|
|
54
|
+
const FLAGS_PROPERTY_NAME = 'flags';
|
|
55
|
+
const TERMS_PROPERTY_NAME = 'terms';
|
|
56
|
+
const TERM_PROPERTY_NAME = 'term';
|
|
57
|
+
const ANY_OF_PROPERTY_NAME = 'anyOf';
|
|
58
|
+
const VALIDATED_STATUS_VALUE = 'VALIDATED';
|
|
59
|
+
const VALIDATED_FLAG_VALUE = 'validated';
|
|
60
|
+
// ─── Helpers ─────────────────────────────────────────────────────────────────
|
|
61
|
+
/**
|
|
62
|
+
* Adds `'validated'` to `flags.anyOf` on a clause object, merging with
|
|
63
|
+
* whatever `flags` shape already exists.
|
|
64
|
+
*/
|
|
65
|
+
function addValidatedFlag(clause) {
|
|
66
|
+
const flagsProperty = clause.getProperty(FLAGS_PROPERTY_NAME);
|
|
67
|
+
if (flagsProperty && ts_morph_1.Node.isPropertyAssignment(flagsProperty)) {
|
|
68
|
+
const flagsInit = flagsProperty.getInitializer();
|
|
69
|
+
if (flagsInit && ts_morph_1.Node.isObjectLiteralExpression(flagsInit)) {
|
|
70
|
+
const anyOfProperty = flagsInit.getProperty(ANY_OF_PROPERTY_NAME);
|
|
71
|
+
if (anyOfProperty && ts_morph_1.Node.isPropertyAssignment(anyOfProperty)) {
|
|
72
|
+
// Append to existing anyOf array
|
|
73
|
+
const anyOfInit = anyOfProperty.getInitializer();
|
|
74
|
+
if (anyOfInit && ts_morph_1.Node.isArrayLiteralExpression(anyOfInit)) {
|
|
75
|
+
anyOfInit.addElement(`'${VALIDATED_FLAG_VALUE}'`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
// flags exists but has no anyOf — add it
|
|
80
|
+
flagsInit.addPropertyAssignment({
|
|
81
|
+
name: ANY_OF_PROPERTY_NAME,
|
|
82
|
+
initializer: `['${VALIDATED_FLAG_VALUE}']`
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
// No flags property at all — add one
|
|
89
|
+
clause.addPropertyAssignment({
|
|
90
|
+
name: FLAGS_PROPERTY_NAME,
|
|
91
|
+
initializer: `{ ${ANY_OF_PROPERTY_NAME}: ['${VALIDATED_FLAG_VALUE}'] }`
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Processes a single leaf clause object.
|
|
97
|
+
* Returns true if any change was made.
|
|
98
|
+
*/
|
|
99
|
+
function migrateClause(clause) {
|
|
100
|
+
const statusProperty = clause.getProperty(STATUS_PROPERTY_NAME);
|
|
101
|
+
if (!statusProperty || !ts_morph_1.Node.isPropertyAssignment(statusProperty)) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
const statusInit = statusProperty.getInitializer();
|
|
105
|
+
if (!statusInit || !ts_morph_1.Node.isObjectLiteralExpression(statusInit)) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
const statusTypeProperty = statusInit.getProperty(TYPE_PROPERTY_NAME);
|
|
109
|
+
if (!statusTypeProperty || !ts_morph_1.Node.isPropertyAssignment(statusTypeProperty)) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
const statusTypeInit = statusTypeProperty.getInitializer();
|
|
113
|
+
if (!statusTypeInit || !ts_morph_1.Node.isStringLiteral(statusTypeInit)) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
const statusType = statusTypeInit.getLiteralValue();
|
|
117
|
+
// ── anyOf case ──────────────────────────────────────────────────────────────
|
|
118
|
+
if (statusType === 'anyOf') {
|
|
119
|
+
const termsProperty = statusInit.getProperty(TERMS_PROPERTY_NAME);
|
|
120
|
+
if (!termsProperty || !ts_morph_1.Node.isPropertyAssignment(termsProperty)) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
const termsInit = termsProperty.getInitializer();
|
|
124
|
+
if (!termsInit || !ts_morph_1.Node.isArrayLiteralExpression(termsInit)) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
const elements = termsInit.getElements();
|
|
128
|
+
const validatedIndex = elements.findIndex((el) => ts_morph_1.Node.isStringLiteral(el) &&
|
|
129
|
+
el.getLiteralValue() === VALIDATED_STATUS_VALUE);
|
|
130
|
+
if (validatedIndex === -1)
|
|
131
|
+
return false;
|
|
132
|
+
// Remove 'VALIDATED' from terms
|
|
133
|
+
termsInit.removeElement(validatedIndex);
|
|
134
|
+
// If terms is now empty, drop the whole status property
|
|
135
|
+
if (termsInit.getElements().length === 0) {
|
|
136
|
+
statusProperty.remove();
|
|
137
|
+
}
|
|
138
|
+
addValidatedFlag(clause);
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
// ── exact case ──────────────────────────────────────────────────────────────
|
|
142
|
+
if (statusType === 'exact') {
|
|
143
|
+
const termProperty = statusInit.getProperty(TERM_PROPERTY_NAME);
|
|
144
|
+
if (!termProperty || !ts_morph_1.Node.isPropertyAssignment(termProperty)) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
const termInit = termProperty.getInitializer();
|
|
148
|
+
if (!termInit || !ts_morph_1.Node.isStringLiteral(termInit)) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
if (termInit.getLiteralValue() !== VALIDATED_STATUS_VALUE)
|
|
152
|
+
return false;
|
|
153
|
+
// Remove the entire status property
|
|
154
|
+
statusProperty.remove();
|
|
155
|
+
addValidatedFlag(clause);
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Recursively walks a query node.
|
|
162
|
+
* - If it is an `or`/`and` container, recurses into `clauses`
|
|
163
|
+
* - Otherwise treats it as a leaf clause and calls `migrateClause`
|
|
164
|
+
* Returns the number of clauses changed.
|
|
165
|
+
*/
|
|
166
|
+
function walkQuery(queryObj) {
|
|
167
|
+
const typeProperty = queryObj.getProperty(TYPE_PROPERTY_NAME);
|
|
168
|
+
if (typeProperty && ts_morph_1.Node.isPropertyAssignment(typeProperty)) {
|
|
169
|
+
const typeInit = typeProperty.getInitializer();
|
|
170
|
+
if (typeInit &&
|
|
171
|
+
ts_morph_1.Node.isStringLiteral(typeInit) &&
|
|
172
|
+
(typeInit.getLiteralValue() === 'or' ||
|
|
173
|
+
typeInit.getLiteralValue() === 'and')) {
|
|
174
|
+
const clausesProperty = queryObj.getProperty(CLAUSES_PROPERTY_NAME);
|
|
175
|
+
if (!clausesProperty || !ts_morph_1.Node.isPropertyAssignment(clausesProperty)) {
|
|
176
|
+
return 0;
|
|
177
|
+
}
|
|
178
|
+
const clausesInit = clausesProperty.getInitializer();
|
|
179
|
+
if (!clausesInit || !ts_morph_1.Node.isArrayLiteralExpression(clausesInit)) {
|
|
180
|
+
return 0;
|
|
181
|
+
}
|
|
182
|
+
let changed = 0;
|
|
183
|
+
for (const clause of clausesInit.getElements()) {
|
|
184
|
+
if (ts_morph_1.Node.isObjectLiteralExpression(clause)) {
|
|
185
|
+
changed += walkQuery(clause);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return changed;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// Leaf clause
|
|
192
|
+
return migrateClause(queryObj) ? 1 : 0;
|
|
193
|
+
}
|
|
194
|
+
// ─── File processor ──────────────────────────────────────────────────────────
|
|
195
|
+
function processFile(filePath, project) {
|
|
196
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
197
|
+
if (!sourceFile)
|
|
198
|
+
return 0;
|
|
199
|
+
let migratedCount = 0;
|
|
200
|
+
const callExpressions = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
201
|
+
for (const call of callExpressions) {
|
|
202
|
+
const expression = call.getExpression();
|
|
203
|
+
if (!ts_morph_1.Node.isIdentifier(expression) ||
|
|
204
|
+
expression.getText() !== DEFINE_WORKQUEUES_NAME) {
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
const args = call.getArguments();
|
|
208
|
+
if (args.length === 0)
|
|
209
|
+
continue;
|
|
210
|
+
// The argument must be an array literal of workqueue config objects
|
|
211
|
+
const workqueuesArg = args[0];
|
|
212
|
+
if (!ts_morph_1.Node.isArrayLiteralExpression(workqueuesArg))
|
|
213
|
+
continue;
|
|
214
|
+
for (const workqueueElement of workqueuesArg.getElements()) {
|
|
215
|
+
if (!ts_morph_1.Node.isObjectLiteralExpression(workqueueElement))
|
|
216
|
+
continue;
|
|
217
|
+
const queryProperty = workqueueElement.getProperty(QUERY_PROPERTY_NAME);
|
|
218
|
+
if (!queryProperty || !ts_morph_1.Node.isPropertyAssignment(queryProperty))
|
|
219
|
+
continue;
|
|
220
|
+
const queryInit = queryProperty.getInitializer();
|
|
221
|
+
if (!queryInit || !ts_morph_1.Node.isObjectLiteralExpression(queryInit))
|
|
222
|
+
continue;
|
|
223
|
+
const changed = walkQuery(queryInit);
|
|
224
|
+
if (changed > 0) {
|
|
225
|
+
migratedCount += changed;
|
|
226
|
+
console.log(` [${path_1.default.relative((0, _1.getCwd)(), filePath)}] Migrated ${changed} clause(s): VALIDATED status → flags.anyOf`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return migratedCount;
|
|
231
|
+
}
|
|
232
|
+
// ─── Entry point ─────────────────────────────────────────────────────────────
|
|
233
|
+
function main() {
|
|
234
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
235
|
+
const srcDir = path_1.default.join((0, _1.getCwd)(), 'src');
|
|
236
|
+
console.log(`Scanning for defineWorkqueues calls in: ${srcDir}\n`);
|
|
237
|
+
const project = new ts_morph_1.Project({
|
|
238
|
+
tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
|
|
239
|
+
skipAddingFilesFromTsConfig: false
|
|
240
|
+
});
|
|
241
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
242
|
+
const fp = sf.getFilePath();
|
|
243
|
+
return fp.includes('/src/') && !fp.includes('/node_modules/');
|
|
244
|
+
});
|
|
245
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
|
|
246
|
+
let totalMigrated = 0;
|
|
247
|
+
const modifiedFiles = [];
|
|
248
|
+
for (const sourceFile of sourceFiles) {
|
|
249
|
+
const filePath = sourceFile.getFilePath();
|
|
250
|
+
const migrated = processFile(filePath, project);
|
|
251
|
+
if (migrated > 0) {
|
|
252
|
+
totalMigrated += migrated;
|
|
253
|
+
modifiedFiles.push(filePath);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
if (modifiedFiles.length === 0) {
|
|
257
|
+
console.log('No VALIDATED status references found in defineWorkqueues calls. Nothing to do.');
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
|
|
261
|
+
for (const filePath of modifiedFiles) {
|
|
262
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
263
|
+
yield sourceFile.save();
|
|
264
|
+
console.log(` Saved: ${path_1.default.relative((0, _1.getCwd)(), filePath)}`);
|
|
265
|
+
}
|
|
266
|
+
console.log(`\nDone. Migrated ${totalMigrated} clause(s) from VALIDATED status to flags.anyOf['validated'].`);
|
|
267
|
+
});
|
|
268
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate-workqueue-configs.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/migrate-workqueue-configs.ts"],"names":[],"mappings":"AAiPA,iBAAe,IAAI,kBAqDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
4
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
5
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
6
|
+
*
|
|
7
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
8
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
9
|
+
*
|
|
10
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
11
|
+
*/
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.main = main;
|
|
26
|
+
/**
|
|
27
|
+
* Codemod: migrate deprecated workqueue `actions` array to singular `action`.
|
|
28
|
+
*
|
|
29
|
+
* Usage:
|
|
30
|
+
* ts-node -r tsconfig-paths/register src/migrations/v2.0/migrate-workqueue-configs.ts
|
|
31
|
+
*
|
|
32
|
+
* What it does:
|
|
33
|
+
* - Scans TypeScript files under `src/`
|
|
34
|
+
* - Finds `defineWorkqueues([...])` calls
|
|
35
|
+
* - For each workqueue object:
|
|
36
|
+
* - `actions: []` -> removes `actions`
|
|
37
|
+
* - `actions: [{ ... }]` -> replaces with `action: { ... }` if type is supported
|
|
38
|
+
* - `actions: [{ type: 'DEFAULT' }]` -> removes `actions` and does not create `action`
|
|
39
|
+
* - `actions: [{...}, {...}, ...]` -> keeps first as `action`, warns about dropped extras
|
|
40
|
+
* - If `action` already exists, removes deprecated `actions` and keeps `action`
|
|
41
|
+
* - Removes unsupported `action.type` values (`DEFAULT`, `VALIDATE`, etc.)
|
|
42
|
+
* - Saves modified files in-place
|
|
43
|
+
*/
|
|
44
|
+
const ts_morph_1 = require("ts-morph");
|
|
45
|
+
const path_1 = __importDefault(require("path"));
|
|
46
|
+
const _1 = require(".");
|
|
47
|
+
const DEFINE_WORKQUEUES_NAME = 'defineWorkqueues';
|
|
48
|
+
const ACTIONS_PROPERTY_NAME = 'actions';
|
|
49
|
+
const ACTION_PROPERTY_NAME = 'action';
|
|
50
|
+
const CONDITIONALS_PROPERTY_NAME = 'conditionals';
|
|
51
|
+
const TYPE_PROPERTY_NAME = 'type';
|
|
52
|
+
const SLUG_PROPERTY_NAME = 'slug';
|
|
53
|
+
const SUPPORTED_WORKQUEUE_ACTION_TYPES = new Set([
|
|
54
|
+
'READ',
|
|
55
|
+
'DELETE',
|
|
56
|
+
'DECLARE',
|
|
57
|
+
'REGISTER',
|
|
58
|
+
'EDIT',
|
|
59
|
+
'REJECT',
|
|
60
|
+
'MARK_AS_DUPLICATE',
|
|
61
|
+
'ARCHIVE',
|
|
62
|
+
'PRINT_CERTIFICATE',
|
|
63
|
+
'REQUEST_CORRECTION'
|
|
64
|
+
]);
|
|
65
|
+
function getWorkqueueLabel(workqueue) {
|
|
66
|
+
const slugProperty = workqueue.getProperty(SLUG_PROPERTY_NAME);
|
|
67
|
+
if (!slugProperty || !ts_morph_1.Node.isPropertyAssignment(slugProperty)) {
|
|
68
|
+
return '(unknown slug)';
|
|
69
|
+
}
|
|
70
|
+
const slugInitializer = slugProperty.getInitializer();
|
|
71
|
+
if (!slugInitializer || !ts_morph_1.Node.isStringLiteral(slugInitializer)) {
|
|
72
|
+
return '(unknown slug)';
|
|
73
|
+
}
|
|
74
|
+
return slugInitializer.getLiteralValue();
|
|
75
|
+
}
|
|
76
|
+
function getActionTypeName(action) {
|
|
77
|
+
const typeProperty = action.getProperty(TYPE_PROPERTY_NAME);
|
|
78
|
+
if (!typeProperty || !ts_morph_1.Node.isPropertyAssignment(typeProperty)) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
const typeInitializer = typeProperty.getInitializer();
|
|
82
|
+
if (!typeInitializer) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
if (ts_morph_1.Node.isStringLiteral(typeInitializer)) {
|
|
86
|
+
return typeInitializer.getLiteralValue();
|
|
87
|
+
}
|
|
88
|
+
if (ts_morph_1.Node.isPropertyAccessExpression(typeInitializer)) {
|
|
89
|
+
return typeInitializer.getName();
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
function isUnsupportedActionType(action) {
|
|
94
|
+
const typeName = getActionTypeName(action);
|
|
95
|
+
if (!typeName) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
|
|
99
|
+
}
|
|
100
|
+
function migrateWorkqueueActions(workqueue, relPath) {
|
|
101
|
+
const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME);
|
|
102
|
+
if (!actionsProperty || !ts_morph_1.Node.isPropertyAssignment(actionsProperty)) {
|
|
103
|
+
return 0;
|
|
104
|
+
}
|
|
105
|
+
const actionsInitializer = actionsProperty.getInitializer();
|
|
106
|
+
if (!actionsInitializer || !ts_morph_1.Node.isArrayLiteralExpression(actionsInitializer)) {
|
|
107
|
+
return 0;
|
|
108
|
+
}
|
|
109
|
+
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
110
|
+
const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME);
|
|
111
|
+
if (existingActionProperty) {
|
|
112
|
+
if (ts_morph_1.Node.isPropertyAssignment(existingActionProperty)) {
|
|
113
|
+
const existingActionInitializer = existingActionProperty.getInitializer();
|
|
114
|
+
if (existingActionInitializer && ts_morph_1.Node.isObjectLiteralExpression(existingActionInitializer)) {
|
|
115
|
+
const conditionalsProperty = existingActionInitializer.getProperty(CONDITIONALS_PROPERTY_NAME);
|
|
116
|
+
if (conditionalsProperty) {
|
|
117
|
+
conditionalsProperty.remove();
|
|
118
|
+
// eslint-disable-next-line no-console
|
|
119
|
+
console.log(` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`);
|
|
120
|
+
}
|
|
121
|
+
if (isUnsupportedActionType(existingActionInitializer)) {
|
|
122
|
+
existingActionProperty.remove();
|
|
123
|
+
// eslint-disable-next-line no-console
|
|
124
|
+
console.log(` [${relPath}] Removed unsupported 'action' type on workqueue '${workqueueLabel}'`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
actionsProperty.remove();
|
|
129
|
+
// eslint-disable-next-line no-console
|
|
130
|
+
console.log(` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`);
|
|
131
|
+
return 1;
|
|
132
|
+
}
|
|
133
|
+
const actionCandidates = actionsInitializer
|
|
134
|
+
.getElements()
|
|
135
|
+
.filter((element) => ts_morph_1.Node.isObjectLiteralExpression(element));
|
|
136
|
+
if (actionCandidates.length === 0) {
|
|
137
|
+
actionsProperty.remove();
|
|
138
|
+
// eslint-disable-next-line no-console
|
|
139
|
+
console.log(` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`);
|
|
140
|
+
return 1;
|
|
141
|
+
}
|
|
142
|
+
if (actionCandidates.length > 1) {
|
|
143
|
+
const droppedCount = actionCandidates.length - 1;
|
|
144
|
+
// eslint-disable-next-line no-console
|
|
145
|
+
console.warn(` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`);
|
|
146
|
+
}
|
|
147
|
+
const conditionalsProperty = actionCandidates[0].getProperty(CONDITIONALS_PROPERTY_NAME);
|
|
148
|
+
if (conditionalsProperty) {
|
|
149
|
+
conditionalsProperty.remove();
|
|
150
|
+
// eslint-disable-next-line no-console
|
|
151
|
+
console.log(` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`);
|
|
152
|
+
}
|
|
153
|
+
if (isUnsupportedActionType(actionCandidates[0])) {
|
|
154
|
+
actionsProperty.remove();
|
|
155
|
+
// eslint-disable-next-line no-console
|
|
156
|
+
console.log(` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`);
|
|
157
|
+
return 1;
|
|
158
|
+
}
|
|
159
|
+
const firstActionText = actionCandidates[0].getText();
|
|
160
|
+
workqueue.addPropertyAssignment({
|
|
161
|
+
name: ACTION_PROPERTY_NAME,
|
|
162
|
+
initializer: firstActionText
|
|
163
|
+
});
|
|
164
|
+
actionsProperty.remove();
|
|
165
|
+
// eslint-disable-next-line no-console
|
|
166
|
+
console.log(` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`);
|
|
167
|
+
return 1;
|
|
168
|
+
}
|
|
169
|
+
function processFile(filePath, project) {
|
|
170
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
171
|
+
if (!sourceFile)
|
|
172
|
+
return 0;
|
|
173
|
+
let migratedWorkqueues = 0;
|
|
174
|
+
const relPath = path_1.default.relative((0, _1.getCwd)(), filePath);
|
|
175
|
+
const callExpressions = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
176
|
+
for (const call of callExpressions) {
|
|
177
|
+
const expression = call.getExpression();
|
|
178
|
+
if (!ts_morph_1.Node.isIdentifier(expression) ||
|
|
179
|
+
expression.getText() !== DEFINE_WORKQUEUES_NAME) {
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
const args = call.getArguments();
|
|
183
|
+
if (args.length === 0)
|
|
184
|
+
continue;
|
|
185
|
+
const workqueuesArg = args[0];
|
|
186
|
+
if (!ts_morph_1.Node.isArrayLiteralExpression(workqueuesArg))
|
|
187
|
+
continue;
|
|
188
|
+
for (const element of workqueuesArg.getElements()) {
|
|
189
|
+
if (!ts_morph_1.Node.isObjectLiteralExpression(element))
|
|
190
|
+
continue;
|
|
191
|
+
migratedWorkqueues += migrateWorkqueueActions(element, relPath);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return migratedWorkqueues;
|
|
195
|
+
}
|
|
196
|
+
function main() {
|
|
197
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
198
|
+
const srcDir = path_1.default.join((0, _1.getCwd)(), 'src');
|
|
199
|
+
// eslint-disable-next-line no-console
|
|
200
|
+
console.log(`Scanning for defineWorkqueues calls in: ${srcDir}\n`);
|
|
201
|
+
const project = new ts_morph_1.Project({
|
|
202
|
+
tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
|
|
203
|
+
skipAddingFilesFromTsConfig: false
|
|
204
|
+
});
|
|
205
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
206
|
+
const fp = sf.getFilePath();
|
|
207
|
+
return fp.includes('/src/') && !fp.includes('/node_modules/');
|
|
208
|
+
});
|
|
209
|
+
// eslint-disable-next-line no-console
|
|
210
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
|
|
211
|
+
let totalMigrated = 0;
|
|
212
|
+
const modifiedFiles = [];
|
|
213
|
+
for (const sourceFile of sourceFiles) {
|
|
214
|
+
const filePath = sourceFile.getFilePath();
|
|
215
|
+
const migrated = processFile(filePath, project);
|
|
216
|
+
if (migrated > 0) {
|
|
217
|
+
totalMigrated += migrated;
|
|
218
|
+
modifiedFiles.push(filePath);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (modifiedFiles.length === 0) {
|
|
222
|
+
// eslint-disable-next-line no-console
|
|
223
|
+
console.log("No deprecated workqueue 'actions' arrays found inside defineWorkqueues calls. Nothing to do.");
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
// eslint-disable-next-line no-console
|
|
227
|
+
console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
|
|
228
|
+
for (const filePath of modifiedFiles) {
|
|
229
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
230
|
+
yield sourceFile.save();
|
|
231
|
+
// eslint-disable-next-line no-console
|
|
232
|
+
console.log(` Saved: ${path_1.default.relative((0, _1.getCwd)(), filePath)}`);
|
|
233
|
+
}
|
|
234
|
+
// eslint-disable-next-line no-console
|
|
235
|
+
console.log(`\nDone. Migrated ${totalMigrated} deprecated workqueue 'actions' definition(s) to 'action'.`);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-delete-actions.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/remove-delete-actions.ts"],"names":[],"mappings":"AA2IA,iBAAe,IAAI,kBAiDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
4
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
5
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
6
|
+
*
|
|
7
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
8
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
9
|
+
*
|
|
10
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
11
|
+
*/
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.main = main;
|
|
26
|
+
/**
|
|
27
|
+
* Codemod: Remove `DELETE` type actions from the `actions` array inside `defineConfig` calls.
|
|
28
|
+
*
|
|
29
|
+
* Usage:
|
|
30
|
+
* ts-node -r tsconfig-paths/register src/migrations/v2.0/remove-delete-actions.ts
|
|
31
|
+
*
|
|
32
|
+
* What it does:
|
|
33
|
+
* - Scans all TypeScript files under `src/`
|
|
34
|
+
* - Finds every `defineConfig({ ... })` call expression
|
|
35
|
+
* - Inside the `actions` array of that config, locates object literals
|
|
36
|
+
* whose `type` property resolves to `ActionType.DELETE` or the string literal `"DELETE"`
|
|
37
|
+
* - Removes those action objects entirely from the array
|
|
38
|
+
* - Saves the modified files in-place
|
|
39
|
+
*/
|
|
40
|
+
const ts_morph_1 = require("ts-morph");
|
|
41
|
+
const path_1 = __importDefault(require("path"));
|
|
42
|
+
const _1 = require(".");
|
|
43
|
+
const DEFINE_CONFIG_NAME = 'defineConfig';
|
|
44
|
+
const ACTIONS_PROPERTY_NAME = 'actions';
|
|
45
|
+
const TYPE_PROPERTY_NAME = 'type';
|
|
46
|
+
const ACTION_TYPE_ENUM_NAME = 'ActionType';
|
|
47
|
+
const DELETE_MEMBER_NAME = 'DELETE';
|
|
48
|
+
const DELETE_STRING_LITERAL = 'DELETE';
|
|
49
|
+
function isDeleteType(typeInitializer) {
|
|
50
|
+
// Matches: ActionType.DELETE
|
|
51
|
+
if (typeInitializer.getKind() === ts_morph_1.SyntaxKind.PropertyAccessExpression) {
|
|
52
|
+
const propAccess = typeInitializer.asKindOrThrow(ts_morph_1.SyntaxKind.PropertyAccessExpression);
|
|
53
|
+
const obj = propAccess.getExpression();
|
|
54
|
+
const member = propAccess.getName();
|
|
55
|
+
return (ts_morph_1.Node.isIdentifier(obj) &&
|
|
56
|
+
obj.getText() === ACTION_TYPE_ENUM_NAME &&
|
|
57
|
+
member === DELETE_MEMBER_NAME);
|
|
58
|
+
}
|
|
59
|
+
// Matches: "DELETE"
|
|
60
|
+
if (typeInitializer.getKind() === ts_morph_1.SyntaxKind.StringLiteral) {
|
|
61
|
+
return (typeInitializer
|
|
62
|
+
.asKindOrThrow(ts_morph_1.SyntaxKind.StringLiteral)
|
|
63
|
+
.getLiteralValue() === DELETE_STRING_LITERAL);
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
function isDeleteAction(obj) {
|
|
68
|
+
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME);
|
|
69
|
+
if (!typeProperty || !ts_morph_1.Node.isPropertyAssignment(typeProperty)) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
const typeInitializer = typeProperty.getInitializer();
|
|
73
|
+
return !!typeInitializer && isDeleteType(typeInitializer);
|
|
74
|
+
}
|
|
75
|
+
function processFile(filePath, project) {
|
|
76
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
77
|
+
if (!sourceFile)
|
|
78
|
+
return 0;
|
|
79
|
+
let removedCount = 0;
|
|
80
|
+
// Find all call expressions named `defineConfig`
|
|
81
|
+
const callExpressions = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
82
|
+
for (const call of callExpressions) {
|
|
83
|
+
const expression = call.getExpression();
|
|
84
|
+
// Only interested in bare `defineConfig(...)` calls
|
|
85
|
+
if (!ts_morph_1.Node.isIdentifier(expression) ||
|
|
86
|
+
expression.getText() !== DEFINE_CONFIG_NAME) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const args = call.getArguments();
|
|
90
|
+
if (args.length === 0)
|
|
91
|
+
continue;
|
|
92
|
+
// The first argument should be the config object literal
|
|
93
|
+
const configArg = args[0];
|
|
94
|
+
if (!ts_morph_1.Node.isObjectLiteralExpression(configArg))
|
|
95
|
+
continue;
|
|
96
|
+
// Find the `actions` property inside the config object
|
|
97
|
+
const actionsProperty = configArg.getProperty(ACTIONS_PROPERTY_NAME);
|
|
98
|
+
if (!actionsProperty || !ts_morph_1.Node.isPropertyAssignment(actionsProperty))
|
|
99
|
+
continue;
|
|
100
|
+
const actionsInitializer = actionsProperty.getInitializer();
|
|
101
|
+
if (!actionsInitializer ||
|
|
102
|
+
!ts_morph_1.Node.isArrayLiteralExpression(actionsInitializer))
|
|
103
|
+
continue;
|
|
104
|
+
// Collect indices of DELETE actions in reverse order so removal doesn't
|
|
105
|
+
// shift the indices of elements yet to be processed
|
|
106
|
+
const indicesToRemove = [];
|
|
107
|
+
actionsInitializer.getElements().forEach((element, index) => {
|
|
108
|
+
if (ts_morph_1.Node.isObjectLiteralExpression(element) && isDeleteAction(element)) {
|
|
109
|
+
indicesToRemove.push(index);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
for (const index of indicesToRemove.reverse()) {
|
|
113
|
+
actionsInitializer.removeElement(index);
|
|
114
|
+
removedCount++;
|
|
115
|
+
console.log(` [${path_1.default.relative((0, _1.getCwd)(), filePath)}] Removed DELETE action at index ${index}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return removedCount;
|
|
119
|
+
}
|
|
120
|
+
function main() {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
const srcDir = path_1.default.join((0, _1.getCwd)(), 'src');
|
|
123
|
+
console.log(`Scanning for defineConfig calls in: ${srcDir}\n`);
|
|
124
|
+
const project = new ts_morph_1.Project({
|
|
125
|
+
tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
|
|
126
|
+
// Do not emit — we only manipulate source files
|
|
127
|
+
skipAddingFilesFromTsConfig: false
|
|
128
|
+
});
|
|
129
|
+
// Restrict to source files only (exclude node_modules, build artefacts, etc.)
|
|
130
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
131
|
+
const fp = sf.getFilePath();
|
|
132
|
+
return fp.includes('/src/') && !fp.includes('/node_modules/');
|
|
133
|
+
});
|
|
134
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
|
|
135
|
+
let totalRemoved = 0;
|
|
136
|
+
const modifiedFiles = [];
|
|
137
|
+
for (const sourceFile of sourceFiles) {
|
|
138
|
+
const filePath = sourceFile.getFilePath();
|
|
139
|
+
const removed = processFile(filePath, project);
|
|
140
|
+
if (removed > 0) {
|
|
141
|
+
totalRemoved += removed;
|
|
142
|
+
modifiedFiles.push(filePath);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (modifiedFiles.length === 0) {
|
|
146
|
+
console.log('No DELETE actions found inside defineConfig calls. Nothing to do.');
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
|
|
150
|
+
for (const filePath of modifiedFiles) {
|
|
151
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
152
|
+
yield sourceFile.save();
|
|
153
|
+
console.log(` Saved: ${path_1.default.relative((0, _1.getCwd)(), filePath)}`);
|
|
154
|
+
}
|
|
155
|
+
console.log(`\nDone. Removed ${totalRemoved} DELETE action(s) from defineConfig call(s).`);
|
|
156
|
+
});
|
|
157
|
+
}
|