@opencrvs/toolkit 1.9.12-rc.bcebfd3 → 1.9.12-rc.bda22f7
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/cli.js +4 -493
- package/dist/commons/events/EventConfig.d.ts +0 -1
- package/dist/events/index.js +0 -3
- package/dist/migrations/v2.0/index.d.ts.map +1 -1
- package/dist/migrations/v2.0/index.js +2 -491
- package/dist/notification/index.js +0 -3
- package/opencrvs-toolkit-1.9.12-rc.bda22f7.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/dist/migrations/v2.0/checkout-upstream-files.d.ts +0 -3
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +0 -1
- package/dist/migrations/v2.0/checkout-upstream-files.js +0 -143
- package/dist/migrations/v2.0/create-events-index.d.ts +0 -3
- package/dist/migrations/v2.0/create-events-index.d.ts.map +0 -1
- package/dist/migrations/v2.0/create-events-index.js +0 -326
- package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +0 -3
- package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +0 -1
- package/dist/migrations/v2.0/simplify-analytics-precalculations.js +0 -196
- package/opencrvs-toolkit-1.9.12-rc.bcebfd3.tgz +0 -0
package/dist/cli.js
CHANGED
|
@@ -1813,9 +1813,9 @@ function updateRouteHandlers(sourceFiles, group, srcDir, relCwd) {
|
|
|
1813
1813
|
}
|
|
1814
1814
|
return replacedCount;
|
|
1815
1815
|
}
|
|
1816
|
-
function resolveConfigChain(configObj,
|
|
1816
|
+
function resolveConfigChain(configObj, path15) {
|
|
1817
1817
|
let current = configObj;
|
|
1818
|
-
for (const key of
|
|
1818
|
+
for (const key of path15) {
|
|
1819
1819
|
if (!import_ts_morph10.Node.isObjectLiteralExpression(current)) return null;
|
|
1820
1820
|
const prop = current.getProperty(key);
|
|
1821
1821
|
if (!prop || !import_ts_morph10.Node.isPropertyAssignment(prop)) return null;
|
|
@@ -3126,491 +3126,6 @@ async function main15() {
|
|
|
3126
3126
|
}
|
|
3127
3127
|
}
|
|
3128
3128
|
|
|
3129
|
-
// src/migrations/v2.0/add-analytics-option-to-event-configs.ts
|
|
3130
|
-
var import_ts_morph15 = require("ts-morph");
|
|
3131
|
-
var import_path16 = __toESM(require("path"));
|
|
3132
|
-
var DEFINE_CONFIG_NAME5 = "defineConfig";
|
|
3133
|
-
var ID_PROPERTY_NAME = "id";
|
|
3134
|
-
var ANALYTICS_PROPERTY_NAME = "analytics";
|
|
3135
|
-
function getEventLabel(configArg) {
|
|
3136
|
-
const idProp = configArg.getProperty(ID_PROPERTY_NAME);
|
|
3137
|
-
if (!idProp || !import_ts_morph15.Node.isPropertyAssignment(idProp)) return "<unknown event>";
|
|
3138
|
-
const initializer = idProp.getInitializer();
|
|
3139
|
-
if (!initializer) return "<unknown event>";
|
|
3140
|
-
if (import_ts_morph15.Node.isStringLiteral(initializer)) {
|
|
3141
|
-
return initializer.getLiteralValue();
|
|
3142
|
-
}
|
|
3143
|
-
return initializer.getText();
|
|
3144
|
-
}
|
|
3145
|
-
function hasAnalyticsProperty(configArg) {
|
|
3146
|
-
return configArg.getProperty(ANALYTICS_PROPERTY_NAME) !== void 0;
|
|
3147
|
-
}
|
|
3148
|
-
function processFile12(filePath, project) {
|
|
3149
|
-
const sourceFile = project.getSourceFile(filePath);
|
|
3150
|
-
if (!sourceFile) return 0;
|
|
3151
|
-
const relPath = import_path16.default.relative(getCwd(), filePath);
|
|
3152
|
-
let changes = 0;
|
|
3153
|
-
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
3154
|
-
import_ts_morph15.SyntaxKind.CallExpression
|
|
3155
|
-
);
|
|
3156
|
-
for (const call of callExpressions) {
|
|
3157
|
-
const expression = call.getExpression();
|
|
3158
|
-
if (!import_ts_morph15.Node.isIdentifier(expression)) continue;
|
|
3159
|
-
if (expression.getText() !== DEFINE_CONFIG_NAME5) continue;
|
|
3160
|
-
const args2 = call.getArguments();
|
|
3161
|
-
if (args2.length === 0) continue;
|
|
3162
|
-
const configArg = args2[0];
|
|
3163
|
-
if (!import_ts_morph15.Node.isObjectLiteralExpression(configArg)) continue;
|
|
3164
|
-
const eventLabel = getEventLabel(configArg);
|
|
3165
|
-
if (hasAnalyticsProperty(configArg)) {
|
|
3166
|
-
console.log(
|
|
3167
|
-
` [${relPath}] Skipped '${eventLabel}' \u2014 'analytics' already declared.`
|
|
3168
|
-
);
|
|
3169
|
-
continue;
|
|
3170
|
-
}
|
|
3171
|
-
configArg.addPropertyAssignment({
|
|
3172
|
-
name: ANALYTICS_PROPERTY_NAME,
|
|
3173
|
-
initializer: "true"
|
|
3174
|
-
});
|
|
3175
|
-
console.log(` [${relPath}] Added 'analytics: true' to '${eventLabel}'.`);
|
|
3176
|
-
changes++;
|
|
3177
|
-
}
|
|
3178
|
-
return changes;
|
|
3179
|
-
}
|
|
3180
|
-
async function main16() {
|
|
3181
|
-
const srcDir = import_path16.default.join(getCwd(), "src");
|
|
3182
|
-
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
3183
|
-
`);
|
|
3184
|
-
const project = new import_ts_morph15.Project({
|
|
3185
|
-
tsConfigFilePath: import_path16.default.resolve(srcDir, "../tsconfig.json"),
|
|
3186
|
-
skipAddingFilesFromTsConfig: false
|
|
3187
|
-
});
|
|
3188
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3189
|
-
const fp = sf.getFilePath();
|
|
3190
|
-
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3191
|
-
});
|
|
3192
|
-
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
3193
|
-
`);
|
|
3194
|
-
let totalChanges = 0;
|
|
3195
|
-
const modifiedFiles = [];
|
|
3196
|
-
for (const sourceFile of sourceFiles) {
|
|
3197
|
-
const filePath = sourceFile.getFilePath();
|
|
3198
|
-
const changes = processFile12(filePath, project);
|
|
3199
|
-
if (changes > 0) {
|
|
3200
|
-
totalChanges += changes;
|
|
3201
|
-
modifiedFiles.push(filePath);
|
|
3202
|
-
}
|
|
3203
|
-
}
|
|
3204
|
-
if (modifiedFiles.length === 0) {
|
|
3205
|
-
console.log("No event configs needed updating. Nothing to do.");
|
|
3206
|
-
return;
|
|
3207
|
-
}
|
|
3208
|
-
console.log(`
|
|
3209
|
-
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
3210
|
-
for (const filePath of modifiedFiles) {
|
|
3211
|
-
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
3212
|
-
await sourceFile.save();
|
|
3213
|
-
console.log(` Saved: ${import_path16.default.relative(getCwd(), filePath)}`);
|
|
3214
|
-
}
|
|
3215
|
-
console.log(
|
|
3216
|
-
`
|
|
3217
|
-
Done. Added 'analytics: true' to ${totalChanges} event config(s) across ${modifiedFiles.length} file(s).`
|
|
3218
|
-
);
|
|
3219
|
-
}
|
|
3220
|
-
|
|
3221
|
-
// src/migrations/v2.0/create-events-index.ts
|
|
3222
|
-
var import_ts_morph16 = require("ts-morph");
|
|
3223
|
-
var import_fs = __toESM(require("fs"));
|
|
3224
|
-
var import_path17 = __toESM(require("path"));
|
|
3225
|
-
var DEFINE_CONFIG_NAME6 = "defineConfig";
|
|
3226
|
-
var HANDLER_FUNCTION_NAMES = /* @__PURE__ */ new Set([
|
|
3227
|
-
"getCustomEventsHandler",
|
|
3228
|
-
"getEventsHandler"
|
|
3229
|
-
]);
|
|
3230
|
-
var EVENT_CONFIGS_IDENTIFIER = "eventConfigs";
|
|
3231
|
-
var EVENTS_INDEX_IMPORT_PATH = "@countryconfig/events";
|
|
3232
|
-
var RESPONSE_METHOD_NAME = "response";
|
|
3233
|
-
var LICENSE_HEADER = `/*
|
|
3234
|
-
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
3235
|
-
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3236
|
-
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
3237
|
-
*
|
|
3238
|
-
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
3239
|
-
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
3240
|
-
*
|
|
3241
|
-
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
3242
|
-
*/
|
|
3243
|
-
`;
|
|
3244
|
-
function findEventConfigExports(project, srcDir) {
|
|
3245
|
-
const found = [];
|
|
3246
|
-
const eventsIndexAbs = import_path17.default.join(srcDir, "events", "index.ts");
|
|
3247
|
-
for (const sourceFile of project.getSourceFiles()) {
|
|
3248
|
-
const filePath = sourceFile.getFilePath();
|
|
3249
|
-
if (!filePath.startsWith(srcDir) || filePath.includes("/node_modules/")) {
|
|
3250
|
-
continue;
|
|
3251
|
-
}
|
|
3252
|
-
if (filePath === eventsIndexAbs) continue;
|
|
3253
|
-
for (const statement of sourceFile.getVariableStatements()) {
|
|
3254
|
-
if (!statement.hasExportKeyword()) continue;
|
|
3255
|
-
for (const decl of statement.getDeclarations()) {
|
|
3256
|
-
const initializer = decl.getInitializer();
|
|
3257
|
-
if (!initializer) continue;
|
|
3258
|
-
const unwrapped = import_ts_morph16.Node.isAsExpression(initializer) ? initializer.getExpression() : initializer;
|
|
3259
|
-
if (!import_ts_morph16.Node.isCallExpression(unwrapped)) continue;
|
|
3260
|
-
const callee = unwrapped.getExpression();
|
|
3261
|
-
if (!import_ts_morph16.Node.isIdentifier(callee)) continue;
|
|
3262
|
-
if (callee.getText() !== DEFINE_CONFIG_NAME6) continue;
|
|
3263
|
-
found.push({ name: decl.getName(), filePath });
|
|
3264
|
-
}
|
|
3265
|
-
}
|
|
3266
|
-
}
|
|
3267
|
-
return found;
|
|
3268
|
-
}
|
|
3269
|
-
function buildIndexImportSpecifier(eventConfigFilePath, srcDir) {
|
|
3270
|
-
const eventsIndexDir = import_path17.default.join(srcDir, "events");
|
|
3271
|
-
let rel = import_path17.default.relative(eventsIndexDir, eventConfigFilePath).split(import_path17.default.sep).join("/");
|
|
3272
|
-
if (rel.endsWith(".ts")) rel = rel.slice(0, -".ts".length);
|
|
3273
|
-
if (rel.endsWith("/index")) rel = rel.slice(0, -"/index".length);
|
|
3274
|
-
if (!rel.startsWith(".")) rel = "./" + rel;
|
|
3275
|
-
return rel;
|
|
3276
|
-
}
|
|
3277
|
-
function buildEventsIndexSource(exports, srcDir) {
|
|
3278
|
-
const imports = exports.map(
|
|
3279
|
-
(e) => `import { ${e.name} } from '${buildIndexImportSpecifier(
|
|
3280
|
-
e.filePath,
|
|
3281
|
-
srcDir
|
|
3282
|
-
)}'`
|
|
3283
|
-
).join("\n");
|
|
3284
|
-
const array3 = `export const ${EVENT_CONFIGS_IDENTIFIER} = [${exports.map((e) => e.name).join(", ")}]`;
|
|
3285
|
-
return `${LICENSE_HEADER}${imports}
|
|
3286
|
-
|
|
3287
|
-
${array3}
|
|
3288
|
-
`;
|
|
3289
|
-
}
|
|
3290
|
-
function findHandlerSourceFile(project, srcDir) {
|
|
3291
|
-
for (const sf of project.getSourceFiles()) {
|
|
3292
|
-
const fp = sf.getFilePath();
|
|
3293
|
-
if (!fp.startsWith(srcDir) || fp.includes("/node_modules/")) continue;
|
|
3294
|
-
for (const fn of sf.getFunctions()) {
|
|
3295
|
-
const name = fn.getName();
|
|
3296
|
-
if (name && HANDLER_FUNCTION_NAMES.has(name)) return sf;
|
|
3297
|
-
}
|
|
3298
|
-
for (const statement of sf.getVariableStatements()) {
|
|
3299
|
-
for (const decl of statement.getDeclarations()) {
|
|
3300
|
-
if (HANDLER_FUNCTION_NAMES.has(decl.getName())) return sf;
|
|
3301
|
-
}
|
|
3302
|
-
}
|
|
3303
|
-
}
|
|
3304
|
-
return void 0;
|
|
3305
|
-
}
|
|
3306
|
-
function modifyHandler(sourceFile, exportNames) {
|
|
3307
|
-
const changes = [];
|
|
3308
|
-
for (const importDecl of [...sourceFile.getImportDeclarations()]) {
|
|
3309
|
-
const namedImports = importDecl.getNamedImports();
|
|
3310
|
-
if (namedImports.length === 0) continue;
|
|
3311
|
-
const matched = namedImports.filter((ni) => exportNames.has(ni.getName()));
|
|
3312
|
-
if (matched.length === 0) continue;
|
|
3313
|
-
const removedNames = matched.map((ni) => ni.getName());
|
|
3314
|
-
for (const ni of matched) ni.remove();
|
|
3315
|
-
changes.push(`removed direct imports: ${removedNames.join(", ")}`);
|
|
3316
|
-
const stillUsed = importDecl.getNamedImports().length > 0 || importDecl.getDefaultImport() || importDecl.getNamespaceImport();
|
|
3317
|
-
if (!stillUsed) importDecl.remove();
|
|
3318
|
-
}
|
|
3319
|
-
for (const statement of [...sourceFile.getVariableStatements()]) {
|
|
3320
|
-
if (!statement.hasExportKeyword()) continue;
|
|
3321
|
-
const hasEventConfigs = statement.getDeclarations().some((d) => d.getName() === EVENT_CONFIGS_IDENTIFIER);
|
|
3322
|
-
if (hasEventConfigs) {
|
|
3323
|
-
statement.remove();
|
|
3324
|
-
changes.push(`removed inline 'export const ${EVENT_CONFIGS_IDENTIFIER}'`);
|
|
3325
|
-
}
|
|
3326
|
-
}
|
|
3327
|
-
const existing = sourceFile.getImportDeclaration(
|
|
3328
|
-
(imp) => imp.getModuleSpecifierValue() === EVENTS_INDEX_IMPORT_PATH
|
|
3329
|
-
);
|
|
3330
|
-
if (existing) {
|
|
3331
|
-
const already = existing.getNamedImports().some((ni) => ni.getName() === EVENT_CONFIGS_IDENTIFIER);
|
|
3332
|
-
if (!already) {
|
|
3333
|
-
existing.addNamedImport(EVENT_CONFIGS_IDENTIFIER);
|
|
3334
|
-
changes.push(
|
|
3335
|
-
`added '${EVENT_CONFIGS_IDENTIFIER}' to existing import from '${EVENTS_INDEX_IMPORT_PATH}'`
|
|
3336
|
-
);
|
|
3337
|
-
}
|
|
3338
|
-
} else {
|
|
3339
|
-
sourceFile.addImportDeclaration({
|
|
3340
|
-
moduleSpecifier: EVENTS_INDEX_IMPORT_PATH,
|
|
3341
|
-
namedImports: [EVENT_CONFIGS_IDENTIFIER]
|
|
3342
|
-
});
|
|
3343
|
-
changes.push(
|
|
3344
|
-
`added import { ${EVENT_CONFIGS_IDENTIFIER} } from '${EVENTS_INDEX_IMPORT_PATH}'`
|
|
3345
|
-
);
|
|
3346
|
-
}
|
|
3347
|
-
for (const call of sourceFile.getDescendantsOfKind(
|
|
3348
|
-
import_ts_morph16.SyntaxKind.CallExpression
|
|
3349
|
-
)) {
|
|
3350
|
-
const callee = call.getExpression();
|
|
3351
|
-
if (!import_ts_morph16.Node.isPropertyAccessExpression(callee)) continue;
|
|
3352
|
-
if (callee.getName() !== RESPONSE_METHOD_NAME) continue;
|
|
3353
|
-
const args2 = call.getArguments();
|
|
3354
|
-
if (args2.length !== 1) continue;
|
|
3355
|
-
const [arg] = args2;
|
|
3356
|
-
if (!import_ts_morph16.Node.isArrayLiteralExpression(arg)) continue;
|
|
3357
|
-
if (arg.getElements().length === 0) continue;
|
|
3358
|
-
if (!arg.getElements().every((el) => import_ts_morph16.Node.isIdentifier(el))) continue;
|
|
3359
|
-
arg.replaceWithText(EVENT_CONFIGS_IDENTIFIER);
|
|
3360
|
-
changes.push(
|
|
3361
|
-
`rewrote h.response([...]) \u2192 h.response(${EVENT_CONFIGS_IDENTIFIER})`
|
|
3362
|
-
);
|
|
3363
|
-
}
|
|
3364
|
-
return changes;
|
|
3365
|
-
}
|
|
3366
|
-
async function main17() {
|
|
3367
|
-
const cwd2 = getCwd();
|
|
3368
|
-
const srcDir = import_path17.default.join(cwd2, "src");
|
|
3369
|
-
console.log(`Scanning for defineConfig event exports in: ${srcDir}
|
|
3370
|
-
`);
|
|
3371
|
-
const project = new import_ts_morph16.Project({
|
|
3372
|
-
tsConfigFilePath: import_path17.default.resolve(srcDir, "../tsconfig.json"),
|
|
3373
|
-
skipAddingFilesFromTsConfig: false
|
|
3374
|
-
});
|
|
3375
|
-
const eventConfigExports = findEventConfigExports(project, srcDir);
|
|
3376
|
-
if (eventConfigExports.length === 0) {
|
|
3377
|
-
console.log(
|
|
3378
|
-
"No top-level `export const X = defineConfig(...)` declarations found. Nothing to do."
|
|
3379
|
-
);
|
|
3380
|
-
return;
|
|
3381
|
-
}
|
|
3382
|
-
console.log(`Found ${eventConfigExports.length} event config export(s):`);
|
|
3383
|
-
for (const e of eventConfigExports) {
|
|
3384
|
-
console.log(` ${e.name} \u2190 ${import_path17.default.relative(cwd2, e.filePath)}`);
|
|
3385
|
-
}
|
|
3386
|
-
const eventsIndexAbs = import_path17.default.join(srcDir, "events", "index.ts");
|
|
3387
|
-
const eventsIndexRel = import_path17.default.relative(cwd2, eventsIndexAbs);
|
|
3388
|
-
if (import_fs.default.existsSync(eventsIndexAbs)) {
|
|
3389
|
-
console.log(`
|
|
3390
|
-
[${eventsIndexRel}] already exists \u2014 leaving untouched.`);
|
|
3391
|
-
} else {
|
|
3392
|
-
import_fs.default.mkdirSync(import_path17.default.dirname(eventsIndexAbs), { recursive: true });
|
|
3393
|
-
const source = buildEventsIndexSource(eventConfigExports, srcDir);
|
|
3394
|
-
const eventsIndexFile = project.createSourceFile(eventsIndexAbs, source, {
|
|
3395
|
-
overwrite: false
|
|
3396
|
-
});
|
|
3397
|
-
await eventsIndexFile.save();
|
|
3398
|
-
console.log(
|
|
3399
|
-
`
|
|
3400
|
-
[${eventsIndexRel}] created with ${EVENT_CONFIGS_IDENTIFIER} of ${eventConfigExports.length} event(s).`
|
|
3401
|
-
);
|
|
3402
|
-
}
|
|
3403
|
-
const handler = findHandlerSourceFile(project, srcDir);
|
|
3404
|
-
if (!handler) {
|
|
3405
|
-
console.log(
|
|
3406
|
-
`
|
|
3407
|
-
No event-config handler file found (looked for exported function(s): ${Array.from(
|
|
3408
|
-
HANDLER_FUNCTION_NAMES
|
|
3409
|
-
).join(", ")}). Skipping handler rewrite.`
|
|
3410
|
-
);
|
|
3411
|
-
return;
|
|
3412
|
-
}
|
|
3413
|
-
const handlerRelPath = import_path17.default.relative(cwd2, handler.getFilePath());
|
|
3414
|
-
const exportNameSet = new Set(eventConfigExports.map((e) => e.name));
|
|
3415
|
-
const changes = modifyHandler(handler, exportNameSet);
|
|
3416
|
-
if (changes.length === 0) {
|
|
3417
|
-
console.log(`
|
|
3418
|
-
[${handlerRelPath}] already wired to ${EVENTS_INDEX_IMPORT_PATH} \u2014 no changes.`);
|
|
3419
|
-
return;
|
|
3420
|
-
}
|
|
3421
|
-
for (const c of changes) console.log(` [${handlerRelPath}] ${c}`);
|
|
3422
|
-
await handler.save();
|
|
3423
|
-
console.log(`
|
|
3424
|
-
Saved ${handlerRelPath}.`);
|
|
3425
|
-
}
|
|
3426
|
-
|
|
3427
|
-
// src/migrations/v2.0/checkout-upstream-files.ts
|
|
3428
|
-
var import_child_process = require("child_process");
|
|
3429
|
-
var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
|
|
3430
|
-
var UPSTREAM_BRANCH = "codemod-analytics";
|
|
3431
|
-
var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
|
|
3432
|
-
var FILES_TO_CHECKOUT = [
|
|
3433
|
-
"infrastructure/postgres/setup-analytics.sh",
|
|
3434
|
-
"src/analytics/analytics.ts"
|
|
3435
|
-
];
|
|
3436
|
-
function runGit(args2, { silent = false } = {}) {
|
|
3437
|
-
return (0, import_child_process.execFileSync)("git", args2, {
|
|
3438
|
-
cwd: getCwd(),
|
|
3439
|
-
encoding: "utf8",
|
|
3440
|
-
stdio: silent ? ["ignore", "pipe", "pipe"] : ["ignore", "pipe", "inherit"]
|
|
3441
|
-
});
|
|
3442
|
-
}
|
|
3443
|
-
function tryGit(args2) {
|
|
3444
|
-
try {
|
|
3445
|
-
runGit(args2, { silent: true });
|
|
3446
|
-
return true;
|
|
3447
|
-
} catch {
|
|
3448
|
-
return false;
|
|
3449
|
-
}
|
|
3450
|
-
}
|
|
3451
|
-
function assertIsGitRepo() {
|
|
3452
|
-
if (!tryGit(["rev-parse", "--is-inside-work-tree"])) {
|
|
3453
|
-
throw new Error(
|
|
3454
|
-
`checkout-upstream-files: ${getCwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`
|
|
3455
|
-
);
|
|
3456
|
-
}
|
|
3457
|
-
}
|
|
3458
|
-
async function main18() {
|
|
3459
|
-
console.log(
|
|
3460
|
-
`Checking out ${FILES_TO_CHECKOUT.length} file(s) from ${UPSTREAM_URL}@${UPSTREAM_BRANCH}...
|
|
3461
|
-
`
|
|
3462
|
-
);
|
|
3463
|
-
assertIsGitRepo();
|
|
3464
|
-
tryGit(["remote", "remove", TEMP_REMOTE]);
|
|
3465
|
-
try {
|
|
3466
|
-
console.log(` Adding temporary remote '${TEMP_REMOTE}' \u2192 ${UPSTREAM_URL}`);
|
|
3467
|
-
runGit(["remote", "add", TEMP_REMOTE, UPSTREAM_URL], { silent: true });
|
|
3468
|
-
console.log(` Fetching ${TEMP_REMOTE}/${UPSTREAM_BRANCH} (depth 1)...`);
|
|
3469
|
-
runGit(["fetch", "--depth=1", TEMP_REMOTE, UPSTREAM_BRANCH]);
|
|
3470
|
-
const ref = `${TEMP_REMOTE}/${UPSTREAM_BRANCH}`;
|
|
3471
|
-
const missing = [];
|
|
3472
|
-
let checkedOut = 0;
|
|
3473
|
-
for (const file of FILES_TO_CHECKOUT) {
|
|
3474
|
-
if (tryGit(["checkout", ref, "--", file])) {
|
|
3475
|
-
console.log(` Checked out ${file} from ${ref}`);
|
|
3476
|
-
checkedOut++;
|
|
3477
|
-
} else {
|
|
3478
|
-
console.warn(
|
|
3479
|
-
` [warn] ${file} not found on ${ref} \u2014 skipping. Verify the path exists on that branch.`
|
|
3480
|
-
);
|
|
3481
|
-
missing.push(file);
|
|
3482
|
-
}
|
|
3483
|
-
}
|
|
3484
|
-
console.log(
|
|
3485
|
-
`
|
|
3486
|
-
Checked out ${checkedOut}/${FILES_TO_CHECKOUT.length} file(s) from ${ref}.`
|
|
3487
|
-
);
|
|
3488
|
-
if (missing.length > 0) {
|
|
3489
|
-
console.warn(` Missing on upstream branch: ${missing.join(", ")}`);
|
|
3490
|
-
}
|
|
3491
|
-
if (checkedOut > 0) {
|
|
3492
|
-
console.log(
|
|
3493
|
-
` Review the staged changes with: git diff --cached -- ${FILES_TO_CHECKOUT.map(
|
|
3494
|
-
(f) => `'${f}'`
|
|
3495
|
-
).join(" ")}
|
|
3496
|
-
`
|
|
3497
|
-
);
|
|
3498
|
-
}
|
|
3499
|
-
} finally {
|
|
3500
|
-
if (tryGit(["remote", "remove", TEMP_REMOTE])) {
|
|
3501
|
-
console.log(` Removed temporary remote '${TEMP_REMOTE}'.`);
|
|
3502
|
-
}
|
|
3503
|
-
}
|
|
3504
|
-
}
|
|
3505
|
-
|
|
3506
|
-
// src/migrations/v2.0/simplify-analytics-precalculations.ts
|
|
3507
|
-
var import_ts_morph17 = require("ts-morph");
|
|
3508
|
-
var import_fs2 = __toESM(require("fs"));
|
|
3509
|
-
var import_path18 = __toESM(require("path"));
|
|
3510
|
-
var ANALYTICS_FILE_REL = "src/analytics/analytics.ts";
|
|
3511
|
-
var FUNCTION_NAME = "precalculateAdditionalAnalytics";
|
|
3512
|
-
var IMPORT_NAMES_TO_REMOVE = /* @__PURE__ */ new Set(["Event", "precalculateBirthEvent"]);
|
|
3513
|
-
var RETURN_EXPRESSION_TEXT = "declaration";
|
|
3514
|
-
function removeTargetedNamedImports(sourceFile) {
|
|
3515
|
-
const log = [];
|
|
3516
|
-
for (const importDecl of [...sourceFile.getImportDeclarations()]) {
|
|
3517
|
-
const namedImports = importDecl.getNamedImports();
|
|
3518
|
-
if (namedImports.length === 0) continue;
|
|
3519
|
-
const matched = namedImports.filter(
|
|
3520
|
-
(ni) => IMPORT_NAMES_TO_REMOVE.has(ni.getName())
|
|
3521
|
-
);
|
|
3522
|
-
if (matched.length === 0) continue;
|
|
3523
|
-
const removedNames = matched.map((ni) => ni.getName());
|
|
3524
|
-
for (const ni of matched) ni.remove();
|
|
3525
|
-
log.push(
|
|
3526
|
-
`removed import(s) ${removedNames.join(", ")} from '${importDecl.getModuleSpecifierValue()}'`
|
|
3527
|
-
);
|
|
3528
|
-
const stillUsed = importDecl.getNamedImports().length > 0 || importDecl.getDefaultImport() || importDecl.getNamespaceImport();
|
|
3529
|
-
if (!stillUsed) importDecl.remove();
|
|
3530
|
-
}
|
|
3531
|
-
return log;
|
|
3532
|
-
}
|
|
3533
|
-
function findPrecalculateFunction(sourceFile) {
|
|
3534
|
-
for (const fn of sourceFile.getFunctions()) {
|
|
3535
|
-
if (fn.getName() === FUNCTION_NAME) return fn;
|
|
3536
|
-
}
|
|
3537
|
-
for (const statement of sourceFile.getVariableStatements()) {
|
|
3538
|
-
for (const decl of statement.getDeclarations()) {
|
|
3539
|
-
if (decl.getName() === FUNCTION_NAME) return decl;
|
|
3540
|
-
}
|
|
3541
|
-
}
|
|
3542
|
-
return void 0;
|
|
3543
|
-
}
|
|
3544
|
-
function getFunctionBodyBlock(fn) {
|
|
3545
|
-
if (import_ts_morph17.Node.isFunctionDeclaration(fn)) return fn.getBody();
|
|
3546
|
-
const initializer = fn.getInitializer();
|
|
3547
|
-
if (!initializer) return void 0;
|
|
3548
|
-
if (!import_ts_morph17.Node.isArrowFunction(initializer) && !import_ts_morph17.Node.isFunctionExpression(initializer)) {
|
|
3549
|
-
return void 0;
|
|
3550
|
-
}
|
|
3551
|
-
return initializer.getBody();
|
|
3552
|
-
}
|
|
3553
|
-
function simplifyPrecalculateFunction(sourceFile) {
|
|
3554
|
-
const log = [];
|
|
3555
|
-
const fn = findPrecalculateFunction(sourceFile);
|
|
3556
|
-
if (!fn) return log;
|
|
3557
|
-
const body = getFunctionBodyBlock(fn);
|
|
3558
|
-
if (!body || !import_ts_morph17.Node.isBlock(body)) return log;
|
|
3559
|
-
for (const statement of [...body.getStatements()]) {
|
|
3560
|
-
const references = statement.getDescendantsOfKind(import_ts_morph17.SyntaxKind.Identifier).some((id) => IMPORT_NAMES_TO_REMOVE.has(id.getText()));
|
|
3561
|
-
if (references) {
|
|
3562
|
-
statement.remove();
|
|
3563
|
-
log.push(`removed statement in ${FUNCTION_NAME} referencing removed imports`);
|
|
3564
|
-
}
|
|
3565
|
-
}
|
|
3566
|
-
const remaining = body.getStatements();
|
|
3567
|
-
const last = remaining[remaining.length - 1];
|
|
3568
|
-
const alreadyCorrect = last && import_ts_morph17.Node.isReturnStatement(last) && last.getExpression()?.getText() === RETURN_EXPRESSION_TEXT;
|
|
3569
|
-
if (!alreadyCorrect) {
|
|
3570
|
-
body.addStatements(`return ${RETURN_EXPRESSION_TEXT}`);
|
|
3571
|
-
log.push(
|
|
3572
|
-
`ensured '${FUNCTION_NAME}' ends with 'return ${RETURN_EXPRESSION_TEXT}'`
|
|
3573
|
-
);
|
|
3574
|
-
}
|
|
3575
|
-
return log;
|
|
3576
|
-
}
|
|
3577
|
-
async function main19() {
|
|
3578
|
-
const cwd2 = getCwd();
|
|
3579
|
-
const absPath = import_path18.default.join(cwd2, ANALYTICS_FILE_REL);
|
|
3580
|
-
if (!import_fs2.default.existsSync(absPath)) {
|
|
3581
|
-
console.log(
|
|
3582
|
-
`[${ANALYTICS_FILE_REL}] does not exist \u2014 nothing to clean up.`
|
|
3583
|
-
);
|
|
3584
|
-
return;
|
|
3585
|
-
}
|
|
3586
|
-
const project = new import_ts_morph17.Project({
|
|
3587
|
-
tsConfigFilePath: import_path18.default.resolve(cwd2, "tsconfig.json"),
|
|
3588
|
-
skipAddingFilesFromTsConfig: false
|
|
3589
|
-
});
|
|
3590
|
-
const sourceFile = project.getSourceFile(absPath);
|
|
3591
|
-
if (!sourceFile) {
|
|
3592
|
-
console.log(
|
|
3593
|
-
`[${ANALYTICS_FILE_REL}] is not part of the tsconfig project. Skipping.`
|
|
3594
|
-
);
|
|
3595
|
-
return;
|
|
3596
|
-
}
|
|
3597
|
-
console.log(`Cleaning up ${ANALYTICS_FILE_REL}...
|
|
3598
|
-
`);
|
|
3599
|
-
const importLogs = removeTargetedNamedImports(sourceFile);
|
|
3600
|
-
const fnLogs = simplifyPrecalculateFunction(sourceFile);
|
|
3601
|
-
const allLogs = [...importLogs, ...fnLogs];
|
|
3602
|
-
if (allLogs.length === 0) {
|
|
3603
|
-
console.log(`[${ANALYTICS_FILE_REL}] already clean \u2014 nothing to do.`);
|
|
3604
|
-
return;
|
|
3605
|
-
}
|
|
3606
|
-
for (const log of allLogs) {
|
|
3607
|
-
console.log(` [${ANALYTICS_FILE_REL}] ${log}`);
|
|
3608
|
-
}
|
|
3609
|
-
await sourceFile.save();
|
|
3610
|
-
console.log(`
|
|
3611
|
-
Saved ${ANALYTICS_FILE_REL}.`);
|
|
3612
|
-
}
|
|
3613
|
-
|
|
3614
3129
|
// src/migrations/v2.0/index.ts
|
|
3615
3130
|
var cwd;
|
|
3616
3131
|
function getCwd() {
|
|
@@ -3645,10 +3160,6 @@ async function runUpgrade(ccwd) {
|
|
|
3645
3160
|
await main12();
|
|
3646
3161
|
await main14();
|
|
3647
3162
|
await main15();
|
|
3648
|
-
await main16();
|
|
3649
|
-
await main17();
|
|
3650
|
-
await main18();
|
|
3651
|
-
await main19();
|
|
3652
3163
|
}
|
|
3653
3164
|
|
|
3654
3165
|
// src/cli.ts
|
|
@@ -3663,7 +3174,7 @@ Commands:
|
|
|
3663
3174
|
|
|
3664
3175
|
Run 'opencrvs <command> --help' for more information on a command.
|
|
3665
3176
|
`.trim();
|
|
3666
|
-
function
|
|
3177
|
+
function main16() {
|
|
3667
3178
|
const command = args[0];
|
|
3668
3179
|
if (!command || command === "--help" || command === "-h") {
|
|
3669
3180
|
console.log(USAGE);
|
|
@@ -3723,4 +3234,4 @@ function handleCheckTranslations() {
|
|
|
3723
3234
|
console.warn("This command is not implemented yet!");
|
|
3724
3235
|
process.exit(1);
|
|
3725
3236
|
}
|
|
3726
|
-
|
|
3237
|
+
main16();
|
|
@@ -29,7 +29,6 @@ export type EventConfig = {
|
|
|
29
29
|
declaration: DeclarationFormConfig;
|
|
30
30
|
advancedSearch: AdvancedSearchConfig[];
|
|
31
31
|
flags: FlagConfig[];
|
|
32
|
-
analytics?: boolean;
|
|
33
32
|
};
|
|
34
33
|
export type EventConfigInput = Omit<EventConfig, 'advancedSearch' | 'flags' | 'declaration' | 'actions' | 'dateOfEvent' | 'placeOfEvent'> & {
|
|
35
34
|
dateOfEvent?: z.input<typeof FieldReference> | z.infer<typeof EventFieldReference>;
|
package/dist/events/index.js
CHANGED
|
@@ -5342,9 +5342,6 @@ var _EventConfigBase = z33.object({
|
|
|
5342
5342
|
),
|
|
5343
5343
|
flags: z33.array(FlagConfig).optional().default([]).describe(
|
|
5344
5344
|
"Configuration of flags associated with the actions of this event type."
|
|
5345
|
-
),
|
|
5346
|
-
analytics: z33.boolean().optional().default(false).describe(
|
|
5347
|
-
"Indicates whether the recors of this event type are included in analytics"
|
|
5348
5345
|
)
|
|
5349
5346
|
});
|
|
5350
5347
|
var EventConfig = _EventConfigBase.superRefine((event2, ctx) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/index.ts"],"names":[],"mappings":"AA4BA,wBAAgB,MAAM,WAMrB;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,iBA2BxD"}
|