@opencrvs/toolkit 1.9.12-rc.8a4bacb → 1.9.12-rc.8d336cc
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 +400 -4
- package/dist/commons/events/EventConfig.d.ts +3 -1
- package/dist/commons/events/FieldConfig.d.ts +2 -2
- package/dist/events/index.js +4 -1
- 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/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 +398 -2
- 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 +4 -1
- package/opencrvs-toolkit-1.9.12-rc.8d336cc.tgz +0 -0
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/opencrvs-toolkit-1.9.12-rc.8a4bacb.tgz +0 -0
|
@@ -1738,7 +1738,7 @@ var LocationInput = BaseField.extend({
|
|
|
1738
1738
|
configuration: import_v43.default.object({
|
|
1739
1739
|
locationTypes: import_v43.default.array(import_v43.default.string()).optional().describe("Types of the locations that are available for selection."),
|
|
1740
1740
|
allowedLocations: AllowedLocations
|
|
1741
|
-
})
|
|
1741
|
+
}).optional()
|
|
1742
1742
|
}).describe("Input field for a location");
|
|
1743
1743
|
var FileUploadWithOptions = BaseField.extend({
|
|
1744
1744
|
type: import_v43.default.literal(FieldType.FILE_WITH_OPTIONS),
|
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, path17) {
|
|
1817
1817
|
let current = configObj;
|
|
1818
|
-
for (const key of
|
|
1818
|
+
for (const key of path17) {
|
|
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,6 +3126,399 @@ async function main15() {
|
|
|
3126
3126
|
}
|
|
3127
3127
|
}
|
|
3128
3128
|
|
|
3129
|
+
// src/migrations/v2.0/create-events-index.ts
|
|
3130
|
+
var import_ts_morph15 = require("ts-morph");
|
|
3131
|
+
var import_fs = __toESM(require("fs"));
|
|
3132
|
+
var import_path16 = __toESM(require("path"));
|
|
3133
|
+
var DEFINE_CONFIG_NAME5 = "defineConfig";
|
|
3134
|
+
var HANDLER_FUNCTION_NAMES = /* @__PURE__ */ new Set([
|
|
3135
|
+
"getCustomEventsHandler",
|
|
3136
|
+
"getEventsHandler"
|
|
3137
|
+
]);
|
|
3138
|
+
var EVENT_CONFIGS_IDENTIFIER = "eventConfigs";
|
|
3139
|
+
var EVENTS_INDEX_IMPORT_PATH = "@countryconfig/events";
|
|
3140
|
+
var RESPONSE_METHOD_NAME = "response";
|
|
3141
|
+
var LICENSE_HEADER = `/*
|
|
3142
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
3143
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3144
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
3145
|
+
*
|
|
3146
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
3147
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
3148
|
+
*
|
|
3149
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
3150
|
+
*/
|
|
3151
|
+
`;
|
|
3152
|
+
function findEventConfigExports(project, srcDir) {
|
|
3153
|
+
const found = [];
|
|
3154
|
+
const eventsIndexAbs = import_path16.default.join(srcDir, "events", "index.ts");
|
|
3155
|
+
for (const sourceFile of project.getSourceFiles()) {
|
|
3156
|
+
const filePath = sourceFile.getFilePath();
|
|
3157
|
+
if (!filePath.startsWith(srcDir) || filePath.includes("/node_modules/")) {
|
|
3158
|
+
continue;
|
|
3159
|
+
}
|
|
3160
|
+
if (filePath === eventsIndexAbs) continue;
|
|
3161
|
+
for (const statement of sourceFile.getVariableStatements()) {
|
|
3162
|
+
if (!statement.hasExportKeyword()) continue;
|
|
3163
|
+
for (const decl of statement.getDeclarations()) {
|
|
3164
|
+
const initializer = decl.getInitializer();
|
|
3165
|
+
if (!initializer) continue;
|
|
3166
|
+
const unwrapped = import_ts_morph15.Node.isAsExpression(initializer) ? initializer.getExpression() : initializer;
|
|
3167
|
+
if (!import_ts_morph15.Node.isCallExpression(unwrapped)) continue;
|
|
3168
|
+
const callee = unwrapped.getExpression();
|
|
3169
|
+
if (!import_ts_morph15.Node.isIdentifier(callee)) continue;
|
|
3170
|
+
if (callee.getText() !== DEFINE_CONFIG_NAME5) continue;
|
|
3171
|
+
found.push({ name: decl.getName(), filePath });
|
|
3172
|
+
}
|
|
3173
|
+
}
|
|
3174
|
+
}
|
|
3175
|
+
return found;
|
|
3176
|
+
}
|
|
3177
|
+
function buildIndexImportSpecifier(eventConfigFilePath, srcDir) {
|
|
3178
|
+
const eventsIndexDir = import_path16.default.join(srcDir, "events");
|
|
3179
|
+
let rel = import_path16.default.relative(eventsIndexDir, eventConfigFilePath).split(import_path16.default.sep).join("/");
|
|
3180
|
+
if (rel.endsWith(".ts")) rel = rel.slice(0, -".ts".length);
|
|
3181
|
+
if (rel.endsWith("/index")) rel = rel.slice(0, -"/index".length);
|
|
3182
|
+
if (!rel.startsWith(".")) rel = "./" + rel;
|
|
3183
|
+
return rel;
|
|
3184
|
+
}
|
|
3185
|
+
function buildEventsIndexSource(exports, srcDir) {
|
|
3186
|
+
const imports = exports.map(
|
|
3187
|
+
(e) => `import { ${e.name} } from '${buildIndexImportSpecifier(
|
|
3188
|
+
e.filePath,
|
|
3189
|
+
srcDir
|
|
3190
|
+
)}'`
|
|
3191
|
+
).join("\n");
|
|
3192
|
+
const array3 = `export const ${EVENT_CONFIGS_IDENTIFIER} = [${exports.map((e) => e.name).join(", ")}]`;
|
|
3193
|
+
return `${LICENSE_HEADER}${imports}
|
|
3194
|
+
|
|
3195
|
+
${array3}
|
|
3196
|
+
`;
|
|
3197
|
+
}
|
|
3198
|
+
function findHandlerSourceFile(project, srcDir) {
|
|
3199
|
+
for (const sf of project.getSourceFiles()) {
|
|
3200
|
+
const fp = sf.getFilePath();
|
|
3201
|
+
if (!fp.startsWith(srcDir) || fp.includes("/node_modules/")) continue;
|
|
3202
|
+
for (const fn of sf.getFunctions()) {
|
|
3203
|
+
const name = fn.getName();
|
|
3204
|
+
if (name && HANDLER_FUNCTION_NAMES.has(name)) return sf;
|
|
3205
|
+
}
|
|
3206
|
+
for (const statement of sf.getVariableStatements()) {
|
|
3207
|
+
for (const decl of statement.getDeclarations()) {
|
|
3208
|
+
if (HANDLER_FUNCTION_NAMES.has(decl.getName())) return sf;
|
|
3209
|
+
}
|
|
3210
|
+
}
|
|
3211
|
+
}
|
|
3212
|
+
return void 0;
|
|
3213
|
+
}
|
|
3214
|
+
function modifyHandler(sourceFile, exportNames) {
|
|
3215
|
+
const changes = [];
|
|
3216
|
+
for (const importDecl of [...sourceFile.getImportDeclarations()]) {
|
|
3217
|
+
const namedImports = importDecl.getNamedImports();
|
|
3218
|
+
if (namedImports.length === 0) continue;
|
|
3219
|
+
const matched = namedImports.filter((ni) => exportNames.has(ni.getName()));
|
|
3220
|
+
if (matched.length === 0) continue;
|
|
3221
|
+
const removedNames = matched.map((ni) => ni.getName());
|
|
3222
|
+
for (const ni of matched) ni.remove();
|
|
3223
|
+
changes.push(`removed direct imports: ${removedNames.join(", ")}`);
|
|
3224
|
+
const stillUsed = importDecl.getNamedImports().length > 0 || importDecl.getDefaultImport() || importDecl.getNamespaceImport();
|
|
3225
|
+
if (!stillUsed) importDecl.remove();
|
|
3226
|
+
}
|
|
3227
|
+
for (const statement of [...sourceFile.getVariableStatements()]) {
|
|
3228
|
+
if (!statement.hasExportKeyword()) continue;
|
|
3229
|
+
const hasEventConfigs = statement.getDeclarations().some((d) => d.getName() === EVENT_CONFIGS_IDENTIFIER);
|
|
3230
|
+
if (hasEventConfigs) {
|
|
3231
|
+
statement.remove();
|
|
3232
|
+
changes.push(`removed inline 'export const ${EVENT_CONFIGS_IDENTIFIER}'`);
|
|
3233
|
+
}
|
|
3234
|
+
}
|
|
3235
|
+
const existing = sourceFile.getImportDeclaration(
|
|
3236
|
+
(imp) => imp.getModuleSpecifierValue() === EVENTS_INDEX_IMPORT_PATH
|
|
3237
|
+
);
|
|
3238
|
+
if (existing) {
|
|
3239
|
+
const already = existing.getNamedImports().some((ni) => ni.getName() === EVENT_CONFIGS_IDENTIFIER);
|
|
3240
|
+
if (!already) {
|
|
3241
|
+
existing.addNamedImport(EVENT_CONFIGS_IDENTIFIER);
|
|
3242
|
+
changes.push(
|
|
3243
|
+
`added '${EVENT_CONFIGS_IDENTIFIER}' to existing import from '${EVENTS_INDEX_IMPORT_PATH}'`
|
|
3244
|
+
);
|
|
3245
|
+
}
|
|
3246
|
+
} else {
|
|
3247
|
+
sourceFile.addImportDeclaration({
|
|
3248
|
+
moduleSpecifier: EVENTS_INDEX_IMPORT_PATH,
|
|
3249
|
+
namedImports: [EVENT_CONFIGS_IDENTIFIER]
|
|
3250
|
+
});
|
|
3251
|
+
changes.push(
|
|
3252
|
+
`added import { ${EVENT_CONFIGS_IDENTIFIER} } from '${EVENTS_INDEX_IMPORT_PATH}'`
|
|
3253
|
+
);
|
|
3254
|
+
}
|
|
3255
|
+
for (const call of sourceFile.getDescendantsOfKind(
|
|
3256
|
+
import_ts_morph15.SyntaxKind.CallExpression
|
|
3257
|
+
)) {
|
|
3258
|
+
const callee = call.getExpression();
|
|
3259
|
+
if (!import_ts_morph15.Node.isPropertyAccessExpression(callee)) continue;
|
|
3260
|
+
if (callee.getName() !== RESPONSE_METHOD_NAME) continue;
|
|
3261
|
+
const args2 = call.getArguments();
|
|
3262
|
+
if (args2.length !== 1) continue;
|
|
3263
|
+
const [arg] = args2;
|
|
3264
|
+
if (!import_ts_morph15.Node.isArrayLiteralExpression(arg)) continue;
|
|
3265
|
+
if (arg.getElements().length === 0) continue;
|
|
3266
|
+
if (!arg.getElements().every((el) => import_ts_morph15.Node.isIdentifier(el))) continue;
|
|
3267
|
+
arg.replaceWithText(EVENT_CONFIGS_IDENTIFIER);
|
|
3268
|
+
changes.push(
|
|
3269
|
+
`rewrote h.response([...]) \u2192 h.response(${EVENT_CONFIGS_IDENTIFIER})`
|
|
3270
|
+
);
|
|
3271
|
+
}
|
|
3272
|
+
return changes;
|
|
3273
|
+
}
|
|
3274
|
+
async function main16() {
|
|
3275
|
+
const cwd2 = getCwd();
|
|
3276
|
+
const srcDir = import_path16.default.join(cwd2, "src");
|
|
3277
|
+
console.log(`Scanning for defineConfig event exports in: ${srcDir}
|
|
3278
|
+
`);
|
|
3279
|
+
const project = new import_ts_morph15.Project({
|
|
3280
|
+
tsConfigFilePath: import_path16.default.resolve(srcDir, "../tsconfig.json"),
|
|
3281
|
+
skipAddingFilesFromTsConfig: false
|
|
3282
|
+
});
|
|
3283
|
+
const eventConfigExports = findEventConfigExports(project, srcDir);
|
|
3284
|
+
if (eventConfigExports.length === 0) {
|
|
3285
|
+
console.log(
|
|
3286
|
+
"No top-level `export const X = defineConfig(...)` declarations found. Nothing to do."
|
|
3287
|
+
);
|
|
3288
|
+
return;
|
|
3289
|
+
}
|
|
3290
|
+
console.log(`Found ${eventConfigExports.length} event config export(s):`);
|
|
3291
|
+
for (const e of eventConfigExports) {
|
|
3292
|
+
console.log(` ${e.name} \u2190 ${import_path16.default.relative(cwd2, e.filePath)}`);
|
|
3293
|
+
}
|
|
3294
|
+
const eventsIndexAbs = import_path16.default.join(srcDir, "events", "index.ts");
|
|
3295
|
+
const eventsIndexRel = import_path16.default.relative(cwd2, eventsIndexAbs);
|
|
3296
|
+
if (import_fs.default.existsSync(eventsIndexAbs)) {
|
|
3297
|
+
console.log(`
|
|
3298
|
+
[${eventsIndexRel}] already exists \u2014 leaving untouched.`);
|
|
3299
|
+
} else {
|
|
3300
|
+
import_fs.default.mkdirSync(import_path16.default.dirname(eventsIndexAbs), { recursive: true });
|
|
3301
|
+
const source = buildEventsIndexSource(eventConfigExports, srcDir);
|
|
3302
|
+
const eventsIndexFile = project.createSourceFile(eventsIndexAbs, source, {
|
|
3303
|
+
overwrite: false
|
|
3304
|
+
});
|
|
3305
|
+
await eventsIndexFile.save();
|
|
3306
|
+
console.log(
|
|
3307
|
+
`
|
|
3308
|
+
[${eventsIndexRel}] created with ${EVENT_CONFIGS_IDENTIFIER} of ${eventConfigExports.length} event(s).`
|
|
3309
|
+
);
|
|
3310
|
+
}
|
|
3311
|
+
const handler = findHandlerSourceFile(project, srcDir);
|
|
3312
|
+
if (!handler) {
|
|
3313
|
+
console.log(
|
|
3314
|
+
`
|
|
3315
|
+
No event-config handler file found (looked for exported function(s): ${Array.from(
|
|
3316
|
+
HANDLER_FUNCTION_NAMES
|
|
3317
|
+
).join(", ")}). Skipping handler rewrite.`
|
|
3318
|
+
);
|
|
3319
|
+
return;
|
|
3320
|
+
}
|
|
3321
|
+
const handlerRelPath = import_path16.default.relative(cwd2, handler.getFilePath());
|
|
3322
|
+
const exportNameSet = new Set(eventConfigExports.map((e) => e.name));
|
|
3323
|
+
const changes = modifyHandler(handler, exportNameSet);
|
|
3324
|
+
if (changes.length === 0) {
|
|
3325
|
+
console.log(`
|
|
3326
|
+
[${handlerRelPath}] already wired to ${EVENTS_INDEX_IMPORT_PATH} \u2014 no changes.`);
|
|
3327
|
+
return;
|
|
3328
|
+
}
|
|
3329
|
+
for (const c of changes) console.log(` [${handlerRelPath}] ${c}`);
|
|
3330
|
+
await handler.save();
|
|
3331
|
+
console.log(`
|
|
3332
|
+
Saved ${handlerRelPath}.`);
|
|
3333
|
+
}
|
|
3334
|
+
|
|
3335
|
+
// src/migrations/v2.0/checkout-upstream-files.ts
|
|
3336
|
+
var import_child_process = require("child_process");
|
|
3337
|
+
var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
|
|
3338
|
+
var UPSTREAM_BRANCH = "develop";
|
|
3339
|
+
var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
|
|
3340
|
+
var FILES_TO_CHECKOUT = [
|
|
3341
|
+
"infrastructure/postgres/setup-analytics.sh",
|
|
3342
|
+
"src/analytics/analytics.ts"
|
|
3343
|
+
];
|
|
3344
|
+
function runGit(args2, { silent = false } = {}) {
|
|
3345
|
+
return (0, import_child_process.execFileSync)("git", args2, {
|
|
3346
|
+
cwd: getCwd(),
|
|
3347
|
+
encoding: "utf8",
|
|
3348
|
+
stdio: silent ? ["ignore", "pipe", "pipe"] : ["ignore", "pipe", "inherit"]
|
|
3349
|
+
});
|
|
3350
|
+
}
|
|
3351
|
+
function tryGit(args2) {
|
|
3352
|
+
try {
|
|
3353
|
+
runGit(args2, { silent: true });
|
|
3354
|
+
return true;
|
|
3355
|
+
} catch {
|
|
3356
|
+
return false;
|
|
3357
|
+
}
|
|
3358
|
+
}
|
|
3359
|
+
function assertIsGitRepo() {
|
|
3360
|
+
if (!tryGit(["rev-parse", "--is-inside-work-tree"])) {
|
|
3361
|
+
throw new Error(
|
|
3362
|
+
`checkout-upstream-files: ${getCwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`
|
|
3363
|
+
);
|
|
3364
|
+
}
|
|
3365
|
+
}
|
|
3366
|
+
async function main17() {
|
|
3367
|
+
console.log(
|
|
3368
|
+
`Checking out ${FILES_TO_CHECKOUT.length} file(s) from ${UPSTREAM_URL}@${UPSTREAM_BRANCH}...
|
|
3369
|
+
`
|
|
3370
|
+
);
|
|
3371
|
+
assertIsGitRepo();
|
|
3372
|
+
tryGit(["remote", "remove", TEMP_REMOTE]);
|
|
3373
|
+
try {
|
|
3374
|
+
console.log(` Adding temporary remote '${TEMP_REMOTE}' \u2192 ${UPSTREAM_URL}`);
|
|
3375
|
+
runGit(["remote", "add", TEMP_REMOTE, UPSTREAM_URL], { silent: true });
|
|
3376
|
+
console.log(` Fetching ${TEMP_REMOTE}/${UPSTREAM_BRANCH} (depth 1)...`);
|
|
3377
|
+
runGit(["fetch", "--depth=1", TEMP_REMOTE, UPSTREAM_BRANCH]);
|
|
3378
|
+
const ref = `${TEMP_REMOTE}/${UPSTREAM_BRANCH}`;
|
|
3379
|
+
const missing = [];
|
|
3380
|
+
let checkedOut = 0;
|
|
3381
|
+
for (const file of FILES_TO_CHECKOUT) {
|
|
3382
|
+
if (tryGit(["checkout", ref, "--", file])) {
|
|
3383
|
+
console.log(` Checked out ${file} from ${ref}`);
|
|
3384
|
+
checkedOut++;
|
|
3385
|
+
} else {
|
|
3386
|
+
console.warn(
|
|
3387
|
+
` [warn] ${file} not found on ${ref} \u2014 skipping. Verify the path exists on that branch.`
|
|
3388
|
+
);
|
|
3389
|
+
missing.push(file);
|
|
3390
|
+
}
|
|
3391
|
+
}
|
|
3392
|
+
console.log(
|
|
3393
|
+
`
|
|
3394
|
+
Checked out ${checkedOut}/${FILES_TO_CHECKOUT.length} file(s) from ${ref}.`
|
|
3395
|
+
);
|
|
3396
|
+
if (missing.length > 0) {
|
|
3397
|
+
console.warn(` Missing on upstream branch: ${missing.join(", ")}`);
|
|
3398
|
+
}
|
|
3399
|
+
if (checkedOut > 0) {
|
|
3400
|
+
console.log(
|
|
3401
|
+
` Review the staged changes with: git diff --cached -- ${FILES_TO_CHECKOUT.map(
|
|
3402
|
+
(f) => `'${f}'`
|
|
3403
|
+
).join(" ")}
|
|
3404
|
+
`
|
|
3405
|
+
);
|
|
3406
|
+
}
|
|
3407
|
+
} finally {
|
|
3408
|
+
if (tryGit(["remote", "remove", TEMP_REMOTE])) {
|
|
3409
|
+
console.log(` Removed temporary remote '${TEMP_REMOTE}'.`);
|
|
3410
|
+
}
|
|
3411
|
+
}
|
|
3412
|
+
}
|
|
3413
|
+
|
|
3414
|
+
// src/migrations/v2.0/simplify-analytics-precalculations.ts
|
|
3415
|
+
var import_ts_morph16 = require("ts-morph");
|
|
3416
|
+
var import_fs2 = __toESM(require("fs"));
|
|
3417
|
+
var import_path17 = __toESM(require("path"));
|
|
3418
|
+
var ANALYTICS_FILE_REL = "src/analytics/analytics.ts";
|
|
3419
|
+
var FUNCTION_NAME = "precalculateAdditionalAnalytics";
|
|
3420
|
+
var IMPORT_NAMES_TO_REMOVE = /* @__PURE__ */ new Set(["Event", "precalculateBirthEvent"]);
|
|
3421
|
+
var RETURN_EXPRESSION_TEXT = "declaration";
|
|
3422
|
+
function removeTargetedNamedImports(sourceFile) {
|
|
3423
|
+
const log = [];
|
|
3424
|
+
for (const importDecl of [...sourceFile.getImportDeclarations()]) {
|
|
3425
|
+
const namedImports = importDecl.getNamedImports();
|
|
3426
|
+
if (namedImports.length === 0) continue;
|
|
3427
|
+
const matched = namedImports.filter(
|
|
3428
|
+
(ni) => IMPORT_NAMES_TO_REMOVE.has(ni.getName())
|
|
3429
|
+
);
|
|
3430
|
+
if (matched.length === 0) continue;
|
|
3431
|
+
const removedNames = matched.map((ni) => ni.getName());
|
|
3432
|
+
for (const ni of matched) ni.remove();
|
|
3433
|
+
log.push(
|
|
3434
|
+
`removed import(s) ${removedNames.join(", ")} from '${importDecl.getModuleSpecifierValue()}'`
|
|
3435
|
+
);
|
|
3436
|
+
const stillUsed = importDecl.getNamedImports().length > 0 || importDecl.getDefaultImport() || importDecl.getNamespaceImport();
|
|
3437
|
+
if (!stillUsed) importDecl.remove();
|
|
3438
|
+
}
|
|
3439
|
+
return log;
|
|
3440
|
+
}
|
|
3441
|
+
function findPrecalculateFunction(sourceFile) {
|
|
3442
|
+
for (const fn of sourceFile.getFunctions()) {
|
|
3443
|
+
if (fn.getName() === FUNCTION_NAME) return fn;
|
|
3444
|
+
}
|
|
3445
|
+
for (const statement of sourceFile.getVariableStatements()) {
|
|
3446
|
+
for (const decl of statement.getDeclarations()) {
|
|
3447
|
+
if (decl.getName() === FUNCTION_NAME) return decl;
|
|
3448
|
+
}
|
|
3449
|
+
}
|
|
3450
|
+
return void 0;
|
|
3451
|
+
}
|
|
3452
|
+
function getFunctionBodyBlock(fn) {
|
|
3453
|
+
if (import_ts_morph16.Node.isFunctionDeclaration(fn)) return fn.getBody();
|
|
3454
|
+
const initializer = fn.getInitializer();
|
|
3455
|
+
if (!initializer) return void 0;
|
|
3456
|
+
if (!import_ts_morph16.Node.isArrowFunction(initializer) && !import_ts_morph16.Node.isFunctionExpression(initializer)) {
|
|
3457
|
+
return void 0;
|
|
3458
|
+
}
|
|
3459
|
+
return initializer.getBody();
|
|
3460
|
+
}
|
|
3461
|
+
function simplifyPrecalculateFunction(sourceFile) {
|
|
3462
|
+
const log = [];
|
|
3463
|
+
const fn = findPrecalculateFunction(sourceFile);
|
|
3464
|
+
if (!fn) return log;
|
|
3465
|
+
const body = getFunctionBodyBlock(fn);
|
|
3466
|
+
if (!body || !import_ts_morph16.Node.isBlock(body)) return log;
|
|
3467
|
+
for (const statement of [...body.getStatements()]) {
|
|
3468
|
+
const references = statement.getDescendantsOfKind(import_ts_morph16.SyntaxKind.Identifier).some((id) => IMPORT_NAMES_TO_REMOVE.has(id.getText()));
|
|
3469
|
+
if (references) {
|
|
3470
|
+
statement.remove();
|
|
3471
|
+
log.push(`removed statement in ${FUNCTION_NAME} referencing removed imports`);
|
|
3472
|
+
}
|
|
3473
|
+
}
|
|
3474
|
+
const remaining = body.getStatements();
|
|
3475
|
+
const last = remaining[remaining.length - 1];
|
|
3476
|
+
const alreadyCorrect = last && import_ts_morph16.Node.isReturnStatement(last) && last.getExpression()?.getText() === RETURN_EXPRESSION_TEXT;
|
|
3477
|
+
if (!alreadyCorrect) {
|
|
3478
|
+
body.addStatements(`return ${RETURN_EXPRESSION_TEXT}`);
|
|
3479
|
+
log.push(
|
|
3480
|
+
`ensured '${FUNCTION_NAME}' ends with 'return ${RETURN_EXPRESSION_TEXT}'`
|
|
3481
|
+
);
|
|
3482
|
+
}
|
|
3483
|
+
return log;
|
|
3484
|
+
}
|
|
3485
|
+
async function main18() {
|
|
3486
|
+
const cwd2 = getCwd();
|
|
3487
|
+
const absPath = import_path17.default.join(cwd2, ANALYTICS_FILE_REL);
|
|
3488
|
+
if (!import_fs2.default.existsSync(absPath)) {
|
|
3489
|
+
console.log(
|
|
3490
|
+
`[${ANALYTICS_FILE_REL}] does not exist \u2014 nothing to clean up.`
|
|
3491
|
+
);
|
|
3492
|
+
return;
|
|
3493
|
+
}
|
|
3494
|
+
const project = new import_ts_morph16.Project({
|
|
3495
|
+
tsConfigFilePath: import_path17.default.resolve(cwd2, "tsconfig.json"),
|
|
3496
|
+
skipAddingFilesFromTsConfig: false
|
|
3497
|
+
});
|
|
3498
|
+
const sourceFile = project.getSourceFile(absPath);
|
|
3499
|
+
if (!sourceFile) {
|
|
3500
|
+
console.log(
|
|
3501
|
+
`[${ANALYTICS_FILE_REL}] is not part of the tsconfig project. Skipping.`
|
|
3502
|
+
);
|
|
3503
|
+
return;
|
|
3504
|
+
}
|
|
3505
|
+
console.log(`Cleaning up ${ANALYTICS_FILE_REL}...
|
|
3506
|
+
`);
|
|
3507
|
+
const importLogs = removeTargetedNamedImports(sourceFile);
|
|
3508
|
+
const fnLogs = simplifyPrecalculateFunction(sourceFile);
|
|
3509
|
+
const allLogs = [...importLogs, ...fnLogs];
|
|
3510
|
+
if (allLogs.length === 0) {
|
|
3511
|
+
console.log(`[${ANALYTICS_FILE_REL}] already clean \u2014 nothing to do.`);
|
|
3512
|
+
return;
|
|
3513
|
+
}
|
|
3514
|
+
for (const log of allLogs) {
|
|
3515
|
+
console.log(` [${ANALYTICS_FILE_REL}] ${log}`);
|
|
3516
|
+
}
|
|
3517
|
+
await sourceFile.save();
|
|
3518
|
+
console.log(`
|
|
3519
|
+
Saved ${ANALYTICS_FILE_REL}.`);
|
|
3520
|
+
}
|
|
3521
|
+
|
|
3129
3522
|
// src/migrations/v2.0/index.ts
|
|
3130
3523
|
var cwd;
|
|
3131
3524
|
function getCwd() {
|
|
@@ -3160,6 +3553,9 @@ async function runUpgrade(ccwd) {
|
|
|
3160
3553
|
await main12();
|
|
3161
3554
|
await main14();
|
|
3162
3555
|
await main15();
|
|
3556
|
+
await main16();
|
|
3557
|
+
await main17();
|
|
3558
|
+
await main18();
|
|
3163
3559
|
}
|
|
3164
3560
|
|
|
3165
3561
|
// src/cli.ts
|
|
@@ -3174,7 +3570,7 @@ Commands:
|
|
|
3174
3570
|
|
|
3175
3571
|
Run 'opencrvs <command> --help' for more information on a command.
|
|
3176
3572
|
`.trim();
|
|
3177
|
-
function
|
|
3573
|
+
function main19() {
|
|
3178
3574
|
const command = args[0];
|
|
3179
3575
|
if (!command || command === "--help" || command === "-h") {
|
|
3180
3576
|
console.log(USAGE);
|
|
@@ -3234,4 +3630,4 @@ function handleCheckTranslations() {
|
|
|
3234
3630
|
console.warn("This command is not implemented yet!");
|
|
3235
3631
|
process.exit(1);
|
|
3236
3632
|
}
|
|
3237
|
-
|
|
3633
|
+
main19();
|
|
@@ -29,14 +29,16 @@ export type EventConfig = {
|
|
|
29
29
|
declaration: DeclarationFormConfig;
|
|
30
30
|
advancedSearch: AdvancedSearchConfig[];
|
|
31
31
|
flags: FlagConfig[];
|
|
32
|
+
analytics: boolean;
|
|
32
33
|
};
|
|
33
|
-
export type EventConfigInput = Omit<EventConfig, 'advancedSearch' | 'flags' | 'declaration' | 'actions' | 'dateOfEvent' | 'placeOfEvent'> & {
|
|
34
|
+
export type EventConfigInput = Omit<EventConfig, 'advancedSearch' | 'flags' | 'declaration' | 'actions' | 'dateOfEvent' | 'placeOfEvent' | 'analytics'> & {
|
|
34
35
|
dateOfEvent?: z.input<typeof FieldReference> | z.infer<typeof EventFieldReference>;
|
|
35
36
|
placeOfEvent?: z.input<typeof FieldReference>;
|
|
36
37
|
advancedSearch?: AdvancedSearchConfig[];
|
|
37
38
|
flags?: FlagConfig[];
|
|
38
39
|
declaration: DeclarationFormConfigInput;
|
|
39
40
|
actions: z.input<typeof ActionConfig>[];
|
|
41
|
+
analytics?: boolean;
|
|
40
42
|
};
|
|
41
43
|
export declare const EventConfig: z.ZodType<EventConfig, EventConfigInput>;
|
|
42
44
|
//# sourceMappingURL=EventConfig.d.ts.map
|
|
@@ -1799,7 +1799,7 @@ declare const LocationInput: z.ZodObject<{
|
|
|
1799
1799
|
}>;
|
|
1800
1800
|
$location: z.ZodOptional<z.ZodString>;
|
|
1801
1801
|
}, z.core.$strip>]>>;
|
|
1802
|
-
configuration: z.ZodObject<{
|
|
1802
|
+
configuration: z.ZodOptional<z.ZodObject<{
|
|
1803
1803
|
locationTypes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
1804
1804
|
allowedLocations: z.ZodOptional<z.ZodObject<{
|
|
1805
1805
|
$jurisdiction: z.ZodUnion<[z.ZodEnum<{
|
|
@@ -1856,7 +1856,7 @@ declare const LocationInput: z.ZodObject<{
|
|
|
1856
1856
|
}>;
|
|
1857
1857
|
}, z.core.$strip>]>;
|
|
1858
1858
|
}, z.core.$strip>>;
|
|
1859
|
-
}, z.core.$strip
|
|
1859
|
+
}, z.core.$strip>>;
|
|
1860
1860
|
}, z.core.$strip>;
|
|
1861
1861
|
export type LocationInput = z.infer<typeof LocationInput>;
|
|
1862
1862
|
declare const FileUploadWithOptions: z.ZodObject<{
|
package/dist/events/index.js
CHANGED
|
@@ -2500,7 +2500,7 @@ var LocationInput = BaseField.extend({
|
|
|
2500
2500
|
configuration: import_v43.default.object({
|
|
2501
2501
|
locationTypes: import_v43.default.array(import_v43.default.string()).optional().describe("Types of the locations that are available for selection."),
|
|
2502
2502
|
allowedLocations: AllowedLocations
|
|
2503
|
-
})
|
|
2503
|
+
}).optional()
|
|
2504
2504
|
}).describe("Input field for a location");
|
|
2505
2505
|
var FileUploadWithOptions = BaseField.extend({
|
|
2506
2506
|
type: import_v43.default.literal(FieldType.FILE_WITH_OPTIONS),
|
|
@@ -5342,6 +5342,9 @@ 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(true).describe(
|
|
5347
|
+
"Indicates whether the records of this event type are included in analytics"
|
|
5345
5348
|
)
|
|
5346
5349
|
});
|
|
5347
5350
|
var EventConfig = _EventConfigBase.superRefine((event2, ctx) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkout-upstream-files.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/checkout-upstream-files.ts"],"names":[],"mappings":"AA0GA,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAuDnC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1,143 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.main = main;
|
|
23
|
+
/**
|
|
24
|
+
* Codemod: Replace selected files with their upstream v2.0 versions from
|
|
25
|
+
* opencrvs/opencrvs-countryconfig.
|
|
26
|
+
*
|
|
27
|
+
* Usage:
|
|
28
|
+
* ts-node -r tsconfig-paths/register src/migrations/v2.0/checkout-upstream-files.ts
|
|
29
|
+
*
|
|
30
|
+
* What it does:
|
|
31
|
+
* 1. Registers a temporary git remote that points at the canonical
|
|
32
|
+
* opencrvs-countryconfig repository.
|
|
33
|
+
* 2. Fetches the chosen upstream branch at --depth=1 to keep it fast.
|
|
34
|
+
* 3. Path-scoped checkouts each listed file from that branch. The upstream
|
|
35
|
+
* version is written to the working tree AND staged in the index, so
|
|
36
|
+
* the dev can review the diff afterwards with:
|
|
37
|
+
* git diff --cached -- <file>
|
|
38
|
+
* 4. Removes the temporary remote in all cases (success, failure, or
|
|
39
|
+
* unexpected error) via a `finally` block.
|
|
40
|
+
*
|
|
41
|
+
* Why a git-based approach (as opposed to a raw HTTPS download):
|
|
42
|
+
* - Git handles text, binary, and line endings correctly.
|
|
43
|
+
* - The checked-out files end up staged, giving an obvious review UX.
|
|
44
|
+
* - `git checkout <ref> -- <paths>` is a blob-level copy, so it works
|
|
45
|
+
* whether or not the target repo shares history with
|
|
46
|
+
* opencrvs-countryconfig (e.g. country implementations started from
|
|
47
|
+
* scratch rather than forked).
|
|
48
|
+
*
|
|
49
|
+
* Caveats:
|
|
50
|
+
* - Overwrites any local modifications to the listed files. Run the
|
|
51
|
+
* upgrade on a clean working tree, or accept that the upstream version
|
|
52
|
+
* replaces yours.
|
|
53
|
+
* - Requires git to be installed and network access to github.com.
|
|
54
|
+
* - Requires the country config working directory to be a git repo.
|
|
55
|
+
*/
|
|
56
|
+
const child_process_1 = require("child_process");
|
|
57
|
+
const _1 = require(".");
|
|
58
|
+
const UPSTREAM_URL = 'https://github.com/opencrvs/opencrvs-countryconfig.git';
|
|
59
|
+
// @TODO: This needs to be changed to 'release-v2.0.0' once the branch is created
|
|
60
|
+
const UPSTREAM_BRANCH = 'develop';
|
|
61
|
+
// Remote name used only for the duration of this codemod. Prefixed to avoid
|
|
62
|
+
// clashing with remotes the user may have (origin, upstream, etc.).
|
|
63
|
+
const TEMP_REMOTE = 'opencrvs-upgrade-v19-v20-codemod';
|
|
64
|
+
const FILES_TO_CHECKOUT = [
|
|
65
|
+
'infrastructure/postgres/setup-analytics.sh',
|
|
66
|
+
'src/analytics/analytics.ts'
|
|
67
|
+
];
|
|
68
|
+
// ─── Git helpers ─────────────────────────────────────────────────────────────
|
|
69
|
+
/**
|
|
70
|
+
* Runs a git command in the country config working directory.
|
|
71
|
+
*
|
|
72
|
+
* By default stderr is inherited so the user sees progress output from
|
|
73
|
+
* long-running commands (e.g. `git fetch`). Pass `silent: true` to suppress
|
|
74
|
+
* both stdout and stderr when you only care about the exit code.
|
|
75
|
+
*/
|
|
76
|
+
function runGit(args, { silent = false } = {}) {
|
|
77
|
+
return (0, child_process_1.execFileSync)('git', args, {
|
|
78
|
+
cwd: (0, _1.getCwd)(),
|
|
79
|
+
encoding: 'utf8',
|
|
80
|
+
stdio: silent ? ['ignore', 'pipe', 'pipe'] : ['ignore', 'pipe', 'inherit']
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Runs a git command and returns true on success, false on failure.
|
|
85
|
+
* Stderr/stdout are suppressed — use only when the exit code is the only
|
|
86
|
+
* signal you care about.
|
|
87
|
+
*/
|
|
88
|
+
function tryGit(args) {
|
|
89
|
+
try {
|
|
90
|
+
runGit(args, { silent: true });
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
catch (_a) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function assertIsGitRepo() {
|
|
98
|
+
if (!tryGit(['rev-parse', '--is-inside-work-tree'])) {
|
|
99
|
+
throw new Error(`checkout-upstream-files: ${(0, _1.getCwd)()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// ─── Entry point ─────────────────────────────────────────────────────────────
|
|
103
|
+
function main() {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
console.log(`Checking out ${FILES_TO_CHECKOUT.length} file(s) from ${UPSTREAM_URL}@${UPSTREAM_BRANCH}...\n`);
|
|
106
|
+
assertIsGitRepo();
|
|
107
|
+
// Best-effort cleanup of a stale temp remote from a previous aborted run.
|
|
108
|
+
tryGit(['remote', 'remove', TEMP_REMOTE]);
|
|
109
|
+
try {
|
|
110
|
+
console.log(` Adding temporary remote '${TEMP_REMOTE}' → ${UPSTREAM_URL}`);
|
|
111
|
+
runGit(['remote', 'add', TEMP_REMOTE, UPSTREAM_URL], { silent: true });
|
|
112
|
+
console.log(` Fetching ${TEMP_REMOTE}/${UPSTREAM_BRANCH} (depth 1)...`);
|
|
113
|
+
runGit(['fetch', '--depth=1', TEMP_REMOTE, UPSTREAM_BRANCH]);
|
|
114
|
+
const ref = `${TEMP_REMOTE}/${UPSTREAM_BRANCH}`;
|
|
115
|
+
const missing = [];
|
|
116
|
+
let checkedOut = 0;
|
|
117
|
+
for (const file of FILES_TO_CHECKOUT) {
|
|
118
|
+
// `--` separates paths from refs and avoids ambiguity when a path
|
|
119
|
+
// happens to match a branch/tag name.
|
|
120
|
+
if (tryGit(['checkout', ref, '--', file])) {
|
|
121
|
+
console.log(` Checked out ${file} from ${ref}`);
|
|
122
|
+
checkedOut++;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
console.warn(` [warn] ${file} not found on ${ref} — skipping. Verify the path exists on that branch.`);
|
|
126
|
+
missing.push(file);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
console.log(`\n Checked out ${checkedOut}/${FILES_TO_CHECKOUT.length} file(s) from ${ref}.`);
|
|
130
|
+
if (missing.length > 0) {
|
|
131
|
+
console.warn(` Missing on upstream branch: ${missing.join(', ')}`);
|
|
132
|
+
}
|
|
133
|
+
if (checkedOut > 0) {
|
|
134
|
+
console.log(` Review the staged changes with: git diff --cached -- ${FILES_TO_CHECKOUT.map((f) => `'${f}'`).join(' ')}\n`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
finally {
|
|
138
|
+
if (tryGit(['remote', 'remove', TEMP_REMOTE])) {
|
|
139
|
+
console.log(` Removed temporary remote '${TEMP_REMOTE}'.`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-events-index.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/create-events-index.ts"],"names":[],"mappings":"AAqTA,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAmEnC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|