@opencrvs/toolkit 1.9.12-rc.f8f1dc7 → 1.9.12-rc.fa99dc7
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/dist/application-config/index.js +1 -1
- package/dist/cli.js +298 -75
- package/dist/commons/api/router.d.ts +211 -204
- package/dist/commons/events/EventConfig.d.ts +3 -2
- package/dist/commons/events/FieldConfig.d.ts +2 -2
- package/dist/events/index.js +15 -5
- package/dist/migrations/v2.0/checkout-upstream-files.js +1 -1
- 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.map +1 -1
- package/dist/migrations/v2.0/index.js +296 -73
- 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.js +3 -3
- package/opencrvs-toolkit-1.9.12-rc.fa99dc7.tgz +0 -0
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/migrations/v2.0/add-analytics-option-to-event-configs.d.ts +0 -3
- package/dist/migrations/v2.0/add-analytics-option-to-event-configs.d.ts.map +0 -1
- package/dist/migrations/v2.0/add-analytics-option-to-event-configs.js +0 -139
- package/opencrvs-toolkit-1.9.12-rc.f8f1dc7.tgz +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"add-analytics-option-to-event-configs.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/add-analytics-option-to-event-configs.ts"],"names":[],"mappings":"AA4GA,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CA6CnC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
4
|
-
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
5
|
-
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
6
|
-
*
|
|
7
|
-
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
8
|
-
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
9
|
-
*
|
|
10
|
-
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
11
|
-
*/
|
|
12
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
-
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.main = main;
|
|
26
|
-
/**
|
|
27
|
-
* Codemod: Add `analytics: true` option to event configs.
|
|
28
|
-
*
|
|
29
|
-
* Usage:
|
|
30
|
-
* ts-node -r tsconfig-paths/register src/migrations/v2.0/add-analytics-option-to-event-configs.ts
|
|
31
|
-
*
|
|
32
|
-
* What it does:
|
|
33
|
-
* 1. Scans the country config `src/` directory for `defineConfig({...})` calls.
|
|
34
|
-
* 2. For every event config that does not yet declare an `analytics` property,
|
|
35
|
-
* inserts `analytics: true` into the config object literal.
|
|
36
|
-
* 3. Saves the modified files in-place.
|
|
37
|
-
*
|
|
38
|
-
* Event configs that already declare `analytics` are left untouched so this
|
|
39
|
-
* codemod is safe to re-run.
|
|
40
|
-
*/
|
|
41
|
-
const ts_morph_1 = require("ts-morph");
|
|
42
|
-
const path_1 = __importDefault(require("path"));
|
|
43
|
-
const _1 = require(".");
|
|
44
|
-
const DEFINE_CONFIG_NAME = 'defineConfig';
|
|
45
|
-
const ID_PROPERTY_NAME = 'id';
|
|
46
|
-
const ANALYTICS_PROPERTY_NAME = 'analytics';
|
|
47
|
-
// ─── AST helpers ─────────────────────────────────────────────────────────────
|
|
48
|
-
/**
|
|
49
|
-
* Returns a human-readable label for an event config, derived from its `id`
|
|
50
|
-
* property. Used only for log output. Falls back to `<unknown event>` when the
|
|
51
|
-
* id can't be statically resolved.
|
|
52
|
-
*/
|
|
53
|
-
function getEventLabel(configArg) {
|
|
54
|
-
const idProp = configArg.getProperty(ID_PROPERTY_NAME);
|
|
55
|
-
if (!idProp || !ts_morph_1.Node.isPropertyAssignment(idProp))
|
|
56
|
-
return '<unknown event>';
|
|
57
|
-
const initializer = idProp.getInitializer();
|
|
58
|
-
if (!initializer)
|
|
59
|
-
return '<unknown event>';
|
|
60
|
-
if (ts_morph_1.Node.isStringLiteral(initializer)) {
|
|
61
|
-
return initializer.getLiteralValue();
|
|
62
|
-
}
|
|
63
|
-
// Handles `Event.Birth`, `EventType.BIRTH`, etc.
|
|
64
|
-
return initializer.getText();
|
|
65
|
-
}
|
|
66
|
-
function hasAnalyticsProperty(configArg) {
|
|
67
|
-
return configArg.getProperty(ANALYTICS_PROPERTY_NAME) !== undefined;
|
|
68
|
-
}
|
|
69
|
-
// ─── File processor ──────────────────────────────────────────────────────────
|
|
70
|
-
function processFile(filePath, project) {
|
|
71
|
-
const sourceFile = project.getSourceFile(filePath);
|
|
72
|
-
if (!sourceFile)
|
|
73
|
-
return 0;
|
|
74
|
-
const relPath = path_1.default.relative((0, _1.getCwd)(), filePath);
|
|
75
|
-
let changes = 0;
|
|
76
|
-
const callExpressions = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
77
|
-
for (const call of callExpressions) {
|
|
78
|
-
const expression = call.getExpression();
|
|
79
|
-
if (!ts_morph_1.Node.isIdentifier(expression))
|
|
80
|
-
continue;
|
|
81
|
-
if (expression.getText() !== DEFINE_CONFIG_NAME)
|
|
82
|
-
continue;
|
|
83
|
-
const args = call.getArguments();
|
|
84
|
-
if (args.length === 0)
|
|
85
|
-
continue;
|
|
86
|
-
const configArg = args[0];
|
|
87
|
-
if (!ts_morph_1.Node.isObjectLiteralExpression(configArg))
|
|
88
|
-
continue;
|
|
89
|
-
const eventLabel = getEventLabel(configArg);
|
|
90
|
-
if (hasAnalyticsProperty(configArg)) {
|
|
91
|
-
console.log(` [${relPath}] Skipped '${eventLabel}' — 'analytics' already declared.`);
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
configArg.addPropertyAssignment({
|
|
95
|
-
name: ANALYTICS_PROPERTY_NAME,
|
|
96
|
-
initializer: 'true'
|
|
97
|
-
});
|
|
98
|
-
console.log(` [${relPath}] Added 'analytics: true' to '${eventLabel}'.`);
|
|
99
|
-
changes++;
|
|
100
|
-
}
|
|
101
|
-
return changes;
|
|
102
|
-
}
|
|
103
|
-
// ─── Entry point ─────────────────────────────────────────────────────────────
|
|
104
|
-
function main() {
|
|
105
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
const srcDir = path_1.default.join((0, _1.getCwd)(), 'src');
|
|
107
|
-
console.log(`Scanning for defineConfig calls in: ${srcDir}\n`);
|
|
108
|
-
const project = new ts_morph_1.Project({
|
|
109
|
-
tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
|
|
110
|
-
skipAddingFilesFromTsConfig: false
|
|
111
|
-
});
|
|
112
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
113
|
-
const fp = sf.getFilePath();
|
|
114
|
-
return fp.includes('/src/') && !fp.includes('/node_modules/');
|
|
115
|
-
});
|
|
116
|
-
console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
|
|
117
|
-
let totalChanges = 0;
|
|
118
|
-
const modifiedFiles = [];
|
|
119
|
-
for (const sourceFile of sourceFiles) {
|
|
120
|
-
const filePath = sourceFile.getFilePath();
|
|
121
|
-
const changes = processFile(filePath, project);
|
|
122
|
-
if (changes > 0) {
|
|
123
|
-
totalChanges += changes;
|
|
124
|
-
modifiedFiles.push(filePath);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (modifiedFiles.length === 0) {
|
|
128
|
-
console.log('No event configs needed updating. Nothing to do.');
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
|
|
132
|
-
for (const filePath of modifiedFiles) {
|
|
133
|
-
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
134
|
-
yield sourceFile.save();
|
|
135
|
-
console.log(` Saved: ${path_1.default.relative((0, _1.getCwd)(), filePath)}`);
|
|
136
|
-
}
|
|
137
|
-
console.log(`\nDone. Added 'analytics: true' to ${totalChanges} event config(s) across ${modifiedFiles.length} file(s).`);
|
|
138
|
-
});
|
|
139
|
-
}
|
|
Binary file
|