@opencrvs/toolkit 1.9.12-rc.ba2ea5c → 1.9.12-rc.ba81d1a
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 +2038 -45
- package/dist/cli.js +497 -25
- package/dist/commons/api/router.d.ts +247 -233
- package/dist/commons/application-config/index.d.ts +6 -4
- package/dist/commons/events/ActionDocument.d.ts +6 -6
- package/dist/commons/events/ActionType.d.ts +3 -3
- package/dist/commons/events/AdvancedSearchConfig.d.ts +10 -10
- package/dist/commons/events/CountryConfigQueryInput.d.ts +222 -222
- package/dist/commons/events/Draft.d.ts +8 -8
- package/dist/commons/events/EventConfig.d.ts +4 -2
- package/dist/commons/events/EventDocument.d.ts +3 -3
- package/dist/commons/events/EventIndex.d.ts +15 -15
- package/dist/commons/events/EventMetadata.d.ts +12 -12
- package/dist/commons/events/FieldConfig.d.ts +28 -28
- package/dist/commons/events/FieldType.d.ts +1 -1
- package/dist/commons/events/FieldTypeMapping.d.ts +4 -4
- package/dist/commons/events/WorkqueueColumnConfig.d.ts +13 -13
- package/dist/commons/events/WorkqueueConfig.d.ts +239 -239
- package/dist/commons/events/scopes.d.ts +1 -1
- package/dist/commons/events/state/index.d.ts +2 -2
- package/dist/commons/events/state/utils.d.ts +3 -3
- package/dist/commons/events/utils.d.ts +3 -3
- package/dist/events/index.js +17 -4
- 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.map +1 -1
- package/dist/migrations/v2.0/convert-config-files-to-ts.js +97 -21
- 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 +495 -23
- 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/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 +5 -2
- package/opencrvs-toolkit-1.9.12-rc.ba81d1a.tgz +0 -0
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/opencrvs-toolkit-1.9.12-rc.ba2ea5c.tgz +0 -0
|
@@ -1636,25 +1636,6 @@ ${elementParts.join(",\n")}
|
|
|
1636
1636
|
]`;
|
|
1637
1637
|
}
|
|
1638
1638
|
function generateTsContent(configObj, exportName, group, isProd) {
|
|
1639
|
-
const headerLines = [];
|
|
1640
|
-
if (isProd) {
|
|
1641
|
-
headerLines.push(`import { env } from './environment'`);
|
|
1642
|
-
}
|
|
1643
|
-
headerLines.push(`import { ${group.defineFn} } from '${group.importFrom}'`);
|
|
1644
|
-
if (group.applicationConfigImportPath) {
|
|
1645
|
-
headerLines.push(
|
|
1646
|
-
`import { applicationConfig } from '${group.applicationConfigImportPath}'`
|
|
1647
|
-
);
|
|
1648
|
-
}
|
|
1649
|
-
headerLines.push("");
|
|
1650
|
-
if (isProd) {
|
|
1651
|
-
headerLines.push(`const scheme = 'https'`);
|
|
1652
|
-
headerLines.push(`const hostname = env.DOMAIN`);
|
|
1653
|
-
headerLines.push(`const sentry = env.SENTRY_DSN`);
|
|
1654
|
-
} else {
|
|
1655
|
-
headerLines.push(`const scheme = 'http'`);
|
|
1656
|
-
headerLines.push(`const hostname = 'localhost'`);
|
|
1657
|
-
}
|
|
1658
1639
|
const propertyLines = [];
|
|
1659
1640
|
const seenKeys = /* @__PURE__ */ new Set();
|
|
1660
1641
|
const appConfigKeySet = new Set(group.applicationConfigKeys ?? []);
|
|
@@ -1690,6 +1671,27 @@ function generateTsContent(configObj, exportName, group, isProd) {
|
|
|
1690
1671
|
propertyLines.push(` ${key}: applicationConfig.${key}`);
|
|
1691
1672
|
}
|
|
1692
1673
|
const body = propertyLines.join(",\n");
|
|
1674
|
+
const headerLines = [];
|
|
1675
|
+
headerLines.push(`import * as fs from 'fs'`);
|
|
1676
|
+
headerLines.push(`import { join } from 'path'`);
|
|
1677
|
+
if (isProd) {
|
|
1678
|
+
headerLines.push(`import { env } from './environment'`);
|
|
1679
|
+
}
|
|
1680
|
+
headerLines.push(`import { ${group.defineFn} } from '${group.importFrom}'`);
|
|
1681
|
+
if (group.applicationConfigImportPath) {
|
|
1682
|
+
headerLines.push(
|
|
1683
|
+
`import { applicationConfig } from '${group.applicationConfigImportPath}'`
|
|
1684
|
+
);
|
|
1685
|
+
}
|
|
1686
|
+
headerLines.push("");
|
|
1687
|
+
if (isProd) {
|
|
1688
|
+
headerLines.push(`const scheme = 'https'`);
|
|
1689
|
+
headerLines.push(`const hostname = env.DOMAIN`);
|
|
1690
|
+
headerLines.push(`const sentry = env.SENTRY_DSN`);
|
|
1691
|
+
} else {
|
|
1692
|
+
headerLines.push(`const scheme = 'http'`);
|
|
1693
|
+
headerLines.push(`const hostname = 'localhost'`);
|
|
1694
|
+
}
|
|
1693
1695
|
return [
|
|
1694
1696
|
...headerLines,
|
|
1695
1697
|
"",
|
|
@@ -1824,9 +1826,9 @@ function updateRouteHandlers(sourceFiles, group, srcDir, relCwd) {
|
|
|
1824
1826
|
}
|
|
1825
1827
|
return replacedCount;
|
|
1826
1828
|
}
|
|
1827
|
-
function resolveConfigChain(configObj,
|
|
1829
|
+
function resolveConfigChain(configObj, path17) {
|
|
1828
1830
|
let current = configObj;
|
|
1829
|
-
for (const key of
|
|
1831
|
+
for (const key of path17) {
|
|
1830
1832
|
if (!import_ts_morph10.Node.isObjectLiteralExpression(current)) return null;
|
|
1831
1833
|
const prop = current.getProperty(key);
|
|
1832
1834
|
if (!prop || !import_ts_morph10.Node.isPropertyAssignment(prop)) return null;
|
|
@@ -1836,6 +1838,40 @@ function resolveConfigChain(configObj, path14) {
|
|
|
1836
1838
|
}
|
|
1837
1839
|
return current.getText();
|
|
1838
1840
|
}
|
|
1841
|
+
function rewriteDirnameRefs(text, relDir) {
|
|
1842
|
+
if (!relDir || relDir === ".") return text;
|
|
1843
|
+
const relForward = relDir.replace(/\\/g, "/");
|
|
1844
|
+
return text.replace(
|
|
1845
|
+
/\b((?:path\.)?(?:join|resolve))\s*\(\s*__dirname\s*,/g,
|
|
1846
|
+
`$1(__dirname, '${relForward}',`
|
|
1847
|
+
);
|
|
1848
|
+
}
|
|
1849
|
+
function ensureFsImport(sf) {
|
|
1850
|
+
const hasFs = sf.getImportDeclarations().some(
|
|
1851
|
+
(d) => d.getModuleSpecifierValue() === "fs" && (d.getNamespaceImport() || d.getDefaultImport())
|
|
1852
|
+
);
|
|
1853
|
+
if (hasFs) return;
|
|
1854
|
+
sf.addImportDeclaration({
|
|
1855
|
+
moduleSpecifier: "fs",
|
|
1856
|
+
namespaceImport: "fs"
|
|
1857
|
+
});
|
|
1858
|
+
}
|
|
1859
|
+
function ensureJoinImport(sf) {
|
|
1860
|
+
const pathImports = sf.getImportDeclarations().filter((d) => d.getModuleSpecifierValue() === "path");
|
|
1861
|
+
if (pathImports.some(
|
|
1862
|
+
(d) => d.getNamedImports().some((ni) => ni.getName() === "join")
|
|
1863
|
+
)) {
|
|
1864
|
+
return;
|
|
1865
|
+
}
|
|
1866
|
+
if (pathImports.length > 0) {
|
|
1867
|
+
pathImports[0].addNamedImport("join");
|
|
1868
|
+
return;
|
|
1869
|
+
}
|
|
1870
|
+
sf.addImportDeclaration({
|
|
1871
|
+
moduleSpecifier: "path",
|
|
1872
|
+
namedImports: ["join"]
|
|
1873
|
+
});
|
|
1874
|
+
}
|
|
1839
1875
|
async function main10() {
|
|
1840
1876
|
const srcDir = import_path10.default.join(getCwd(), "src");
|
|
1841
1877
|
const relCwd = (fp) => import_path10.default.relative(getCwd(), fp);
|
|
@@ -1881,12 +1917,15 @@ async function main10() {
|
|
|
1881
1917
|
});
|
|
1882
1918
|
if (propsToRemove.length > 0) {
|
|
1883
1919
|
const filesToSaveAfterInlining = /* @__PURE__ */ new Set();
|
|
1920
|
+
const appConfigDir = import_path10.default.dirname(appConfigAbsPath);
|
|
1884
1921
|
for (const removedProp of propsToRemove) {
|
|
1885
1922
|
const key = removedProp.getName();
|
|
1886
1923
|
for (const sf of appConfigProject.getSourceFiles()) {
|
|
1887
1924
|
if (sf.getFilePath() === appConfigAbsPath) continue;
|
|
1888
1925
|
if (!sf.getFilePath().includes("/src/")) continue;
|
|
1889
1926
|
if (sf.getFilePath().includes("/node_modules/")) continue;
|
|
1927
|
+
const targetDir = import_path10.default.dirname(sf.getFilePath());
|
|
1928
|
+
const relDirFromTarget = import_path10.default.relative(targetDir, appConfigDir);
|
|
1890
1929
|
let madeReplacement = true;
|
|
1891
1930
|
while (madeReplacement) {
|
|
1892
1931
|
madeReplacement = false;
|
|
@@ -1911,9 +1950,19 @@ async function main10() {
|
|
|
1911
1950
|
);
|
|
1912
1951
|
continue;
|
|
1913
1952
|
}
|
|
1914
|
-
|
|
1953
|
+
const adjustedValue = rewriteDirnameRefs(
|
|
1954
|
+
resolvedValue,
|
|
1955
|
+
relDirFromTarget
|
|
1956
|
+
);
|
|
1957
|
+
node.replaceWithText(adjustedValue);
|
|
1958
|
+
if (/\bfs\s*\./.test(adjustedValue)) {
|
|
1959
|
+
ensureFsImport(sf);
|
|
1960
|
+
}
|
|
1961
|
+
if (/\bjoin\s*\(/.test(adjustedValue)) {
|
|
1962
|
+
ensureJoinImport(sf);
|
|
1963
|
+
}
|
|
1915
1964
|
console.log(
|
|
1916
|
-
` Inlined applicationConfig.${accessPath.join(".")} \u2192 ${
|
|
1965
|
+
` Inlined applicationConfig.${accessPath.join(".")} \u2192 ${adjustedValue} in ${import_path10.default.relative(getCwd(), sf.getFilePath())}`
|
|
1917
1966
|
);
|
|
1918
1967
|
filesToSaveAfterInlining.add(sf);
|
|
1919
1968
|
madeReplacement = true;
|
|
@@ -3064,6 +3113,425 @@ async function main14() {
|
|
|
3064
3113
|
);
|
|
3065
3114
|
}
|
|
3066
3115
|
|
|
3116
|
+
// src/migrations/v2.0/remove-hearth-migrations.ts
|
|
3117
|
+
var fs2 = __toESM(require("fs"));
|
|
3118
|
+
var import_path15 = __toESM(require("path"));
|
|
3119
|
+
var PATHS_TO_REMOVE = [
|
|
3120
|
+
{
|
|
3121
|
+
relativePath: "src/migrations/hearth",
|
|
3122
|
+
label: "Hearth migrations directory"
|
|
3123
|
+
},
|
|
3124
|
+
{
|
|
3125
|
+
relativePath: "src/migrations/user-mgnt",
|
|
3126
|
+
label: "user-mgnt migrations directory"
|
|
3127
|
+
},
|
|
3128
|
+
{ relativePath: "src/utils/hearth-helpers.ts", label: "Hearth helpers file" }
|
|
3129
|
+
];
|
|
3130
|
+
async function main15() {
|
|
3131
|
+
for (const { relativePath, label } of PATHS_TO_REMOVE) {
|
|
3132
|
+
const absolutePath = import_path15.default.join(getCwd(), relativePath);
|
|
3133
|
+
if (fs2.existsSync(absolutePath)) {
|
|
3134
|
+
fs2.rmSync(absolutePath, { recursive: true, force: true });
|
|
3135
|
+
console.log(`Removed ${label} '${relativePath}'.`);
|
|
3136
|
+
} else {
|
|
3137
|
+
console.log(`No ${label} found at '${relativePath}'.`);
|
|
3138
|
+
}
|
|
3139
|
+
}
|
|
3140
|
+
}
|
|
3141
|
+
|
|
3142
|
+
// src/migrations/v2.0/create-events-index.ts
|
|
3143
|
+
var import_ts_morph15 = require("ts-morph");
|
|
3144
|
+
var import_fs = __toESM(require("fs"));
|
|
3145
|
+
var import_path16 = __toESM(require("path"));
|
|
3146
|
+
var DEFINE_CONFIG_NAME5 = "defineConfig";
|
|
3147
|
+
var HANDLER_FUNCTION_NAMES = /* @__PURE__ */ new Set([
|
|
3148
|
+
"getCustomEventsHandler",
|
|
3149
|
+
"getEventsHandler"
|
|
3150
|
+
]);
|
|
3151
|
+
var EVENT_CONFIGS_IDENTIFIER = "eventConfigs";
|
|
3152
|
+
var EVENTS_INDEX_IMPORT_PATH = "@countryconfig/events";
|
|
3153
|
+
var RESPONSE_METHOD_NAME = "response";
|
|
3154
|
+
var LICENSE_HEADER = `/*
|
|
3155
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
3156
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3157
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
3158
|
+
*
|
|
3159
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
3160
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
3161
|
+
*
|
|
3162
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
3163
|
+
*/
|
|
3164
|
+
`;
|
|
3165
|
+
function findEventConfigExports(project, srcDir) {
|
|
3166
|
+
const found = [];
|
|
3167
|
+
const eventsIndexAbs = import_path16.default.join(srcDir, "events", "index.ts");
|
|
3168
|
+
for (const sourceFile of project.getSourceFiles()) {
|
|
3169
|
+
const filePath = sourceFile.getFilePath();
|
|
3170
|
+
if (!filePath.startsWith(srcDir) || filePath.includes("/node_modules/")) {
|
|
3171
|
+
continue;
|
|
3172
|
+
}
|
|
3173
|
+
if (filePath === eventsIndexAbs) continue;
|
|
3174
|
+
for (const statement of sourceFile.getVariableStatements()) {
|
|
3175
|
+
if (!statement.hasExportKeyword()) continue;
|
|
3176
|
+
for (const decl of statement.getDeclarations()) {
|
|
3177
|
+
const initializer = decl.getInitializer();
|
|
3178
|
+
if (!initializer) continue;
|
|
3179
|
+
const unwrapped = import_ts_morph15.Node.isAsExpression(initializer) ? initializer.getExpression() : initializer;
|
|
3180
|
+
if (!import_ts_morph15.Node.isCallExpression(unwrapped)) continue;
|
|
3181
|
+
const callee = unwrapped.getExpression();
|
|
3182
|
+
if (!import_ts_morph15.Node.isIdentifier(callee)) continue;
|
|
3183
|
+
if (callee.getText() !== DEFINE_CONFIG_NAME5) continue;
|
|
3184
|
+
found.push({ name: decl.getName(), filePath });
|
|
3185
|
+
}
|
|
3186
|
+
}
|
|
3187
|
+
}
|
|
3188
|
+
return found;
|
|
3189
|
+
}
|
|
3190
|
+
function buildIndexImportSpecifier(eventConfigFilePath, srcDir) {
|
|
3191
|
+
const eventsIndexDir = import_path16.default.join(srcDir, "events");
|
|
3192
|
+
let rel = import_path16.default.relative(eventsIndexDir, eventConfigFilePath).split(import_path16.default.sep).join("/");
|
|
3193
|
+
if (rel.endsWith(".ts")) rel = rel.slice(0, -".ts".length);
|
|
3194
|
+
if (rel.endsWith("/index")) rel = rel.slice(0, -"/index".length);
|
|
3195
|
+
if (!rel.startsWith(".")) rel = "./" + rel;
|
|
3196
|
+
return rel;
|
|
3197
|
+
}
|
|
3198
|
+
function buildEventsIndexSource(exports, srcDir) {
|
|
3199
|
+
const imports = exports.map(
|
|
3200
|
+
(e) => `import { ${e.name} } from '${buildIndexImportSpecifier(
|
|
3201
|
+
e.filePath,
|
|
3202
|
+
srcDir
|
|
3203
|
+
)}'`
|
|
3204
|
+
).join("\n");
|
|
3205
|
+
const array3 = `export const ${EVENT_CONFIGS_IDENTIFIER} = [${exports.map((e) => e.name).join(", ")}]`;
|
|
3206
|
+
return `${LICENSE_HEADER}${imports}
|
|
3207
|
+
|
|
3208
|
+
${array3}
|
|
3209
|
+
`;
|
|
3210
|
+
}
|
|
3211
|
+
function findHandlerSourceFile(project, srcDir) {
|
|
3212
|
+
for (const sf of project.getSourceFiles()) {
|
|
3213
|
+
const fp = sf.getFilePath();
|
|
3214
|
+
if (!fp.startsWith(srcDir) || fp.includes("/node_modules/")) continue;
|
|
3215
|
+
for (const fn of sf.getFunctions()) {
|
|
3216
|
+
const name = fn.getName();
|
|
3217
|
+
if (name && HANDLER_FUNCTION_NAMES.has(name)) return sf;
|
|
3218
|
+
}
|
|
3219
|
+
for (const statement of sf.getVariableStatements()) {
|
|
3220
|
+
for (const decl of statement.getDeclarations()) {
|
|
3221
|
+
if (HANDLER_FUNCTION_NAMES.has(decl.getName())) return sf;
|
|
3222
|
+
}
|
|
3223
|
+
}
|
|
3224
|
+
}
|
|
3225
|
+
return void 0;
|
|
3226
|
+
}
|
|
3227
|
+
function modifyHandler(sourceFile, exportNames) {
|
|
3228
|
+
const changes = [];
|
|
3229
|
+
for (const importDecl of [...sourceFile.getImportDeclarations()]) {
|
|
3230
|
+
const namedImports = importDecl.getNamedImports();
|
|
3231
|
+
if (namedImports.length === 0) continue;
|
|
3232
|
+
const matched = namedImports.filter((ni) => exportNames.has(ni.getName()));
|
|
3233
|
+
if (matched.length === 0) continue;
|
|
3234
|
+
const removedNames = matched.map((ni) => ni.getName());
|
|
3235
|
+
for (const ni of matched) ni.remove();
|
|
3236
|
+
changes.push(`removed direct imports: ${removedNames.join(", ")}`);
|
|
3237
|
+
const stillUsed = importDecl.getNamedImports().length > 0 || importDecl.getDefaultImport() || importDecl.getNamespaceImport();
|
|
3238
|
+
if (!stillUsed) importDecl.remove();
|
|
3239
|
+
}
|
|
3240
|
+
for (const statement of [...sourceFile.getVariableStatements()]) {
|
|
3241
|
+
if (!statement.hasExportKeyword()) continue;
|
|
3242
|
+
const hasEventConfigs = statement.getDeclarations().some((d) => d.getName() === EVENT_CONFIGS_IDENTIFIER);
|
|
3243
|
+
if (hasEventConfigs) {
|
|
3244
|
+
statement.remove();
|
|
3245
|
+
changes.push(`removed inline 'export const ${EVENT_CONFIGS_IDENTIFIER}'`);
|
|
3246
|
+
}
|
|
3247
|
+
}
|
|
3248
|
+
const existing = sourceFile.getImportDeclaration(
|
|
3249
|
+
(imp) => imp.getModuleSpecifierValue() === EVENTS_INDEX_IMPORT_PATH
|
|
3250
|
+
);
|
|
3251
|
+
if (existing) {
|
|
3252
|
+
const already = existing.getNamedImports().some((ni) => ni.getName() === EVENT_CONFIGS_IDENTIFIER);
|
|
3253
|
+
if (!already) {
|
|
3254
|
+
existing.addNamedImport(EVENT_CONFIGS_IDENTIFIER);
|
|
3255
|
+
changes.push(
|
|
3256
|
+
`added '${EVENT_CONFIGS_IDENTIFIER}' to existing import from '${EVENTS_INDEX_IMPORT_PATH}'`
|
|
3257
|
+
);
|
|
3258
|
+
}
|
|
3259
|
+
} else {
|
|
3260
|
+
sourceFile.addImportDeclaration({
|
|
3261
|
+
moduleSpecifier: EVENTS_INDEX_IMPORT_PATH,
|
|
3262
|
+
namedImports: [EVENT_CONFIGS_IDENTIFIER]
|
|
3263
|
+
});
|
|
3264
|
+
changes.push(
|
|
3265
|
+
`added import { ${EVENT_CONFIGS_IDENTIFIER} } from '${EVENTS_INDEX_IMPORT_PATH}'`
|
|
3266
|
+
);
|
|
3267
|
+
}
|
|
3268
|
+
for (const call of sourceFile.getDescendantsOfKind(
|
|
3269
|
+
import_ts_morph15.SyntaxKind.CallExpression
|
|
3270
|
+
)) {
|
|
3271
|
+
const callee = call.getExpression();
|
|
3272
|
+
if (!import_ts_morph15.Node.isPropertyAccessExpression(callee)) continue;
|
|
3273
|
+
if (callee.getName() !== RESPONSE_METHOD_NAME) continue;
|
|
3274
|
+
const args = call.getArguments();
|
|
3275
|
+
if (args.length !== 1) continue;
|
|
3276
|
+
const [arg] = args;
|
|
3277
|
+
if (!import_ts_morph15.Node.isArrayLiteralExpression(arg)) continue;
|
|
3278
|
+
if (arg.getElements().length === 0) continue;
|
|
3279
|
+
if (!arg.getElements().every((el) => import_ts_morph15.Node.isIdentifier(el))) continue;
|
|
3280
|
+
arg.replaceWithText(EVENT_CONFIGS_IDENTIFIER);
|
|
3281
|
+
changes.push(
|
|
3282
|
+
`rewrote h.response([...]) \u2192 h.response(${EVENT_CONFIGS_IDENTIFIER})`
|
|
3283
|
+
);
|
|
3284
|
+
}
|
|
3285
|
+
return changes;
|
|
3286
|
+
}
|
|
3287
|
+
async function main16() {
|
|
3288
|
+
const cwd2 = getCwd();
|
|
3289
|
+
const srcDir = import_path16.default.join(cwd2, "src");
|
|
3290
|
+
console.log(`Scanning for defineConfig event exports in: ${srcDir}
|
|
3291
|
+
`);
|
|
3292
|
+
const project = new import_ts_morph15.Project({
|
|
3293
|
+
tsConfigFilePath: import_path16.default.resolve(srcDir, "../tsconfig.json"),
|
|
3294
|
+
skipAddingFilesFromTsConfig: false
|
|
3295
|
+
});
|
|
3296
|
+
const eventConfigExports = findEventConfigExports(project, srcDir);
|
|
3297
|
+
if (eventConfigExports.length === 0) {
|
|
3298
|
+
console.log(
|
|
3299
|
+
"No top-level `export const X = defineConfig(...)` declarations found. Nothing to do."
|
|
3300
|
+
);
|
|
3301
|
+
return;
|
|
3302
|
+
}
|
|
3303
|
+
console.log(`Found ${eventConfigExports.length} event config export(s):`);
|
|
3304
|
+
for (const e of eventConfigExports) {
|
|
3305
|
+
console.log(` ${e.name} \u2190 ${import_path16.default.relative(cwd2, e.filePath)}`);
|
|
3306
|
+
}
|
|
3307
|
+
const eventsIndexAbs = import_path16.default.join(srcDir, "events", "index.ts");
|
|
3308
|
+
const eventsIndexRel = import_path16.default.relative(cwd2, eventsIndexAbs);
|
|
3309
|
+
if (import_fs.default.existsSync(eventsIndexAbs)) {
|
|
3310
|
+
console.log(`
|
|
3311
|
+
[${eventsIndexRel}] already exists \u2014 leaving untouched.`);
|
|
3312
|
+
} else {
|
|
3313
|
+
import_fs.default.mkdirSync(import_path16.default.dirname(eventsIndexAbs), { recursive: true });
|
|
3314
|
+
const source = buildEventsIndexSource(eventConfigExports, srcDir);
|
|
3315
|
+
const eventsIndexFile = project.createSourceFile(eventsIndexAbs, source, {
|
|
3316
|
+
overwrite: false
|
|
3317
|
+
});
|
|
3318
|
+
await eventsIndexFile.save();
|
|
3319
|
+
console.log(
|
|
3320
|
+
`
|
|
3321
|
+
[${eventsIndexRel}] created with ${EVENT_CONFIGS_IDENTIFIER} of ${eventConfigExports.length} event(s).`
|
|
3322
|
+
);
|
|
3323
|
+
}
|
|
3324
|
+
const handler = findHandlerSourceFile(project, srcDir);
|
|
3325
|
+
if (!handler) {
|
|
3326
|
+
console.log(
|
|
3327
|
+
`
|
|
3328
|
+
No event-config handler file found (looked for exported function(s): ${Array.from(
|
|
3329
|
+
HANDLER_FUNCTION_NAMES
|
|
3330
|
+
).join(", ")}). Skipping handler rewrite.`
|
|
3331
|
+
);
|
|
3332
|
+
return;
|
|
3333
|
+
}
|
|
3334
|
+
const handlerRelPath = import_path16.default.relative(cwd2, handler.getFilePath());
|
|
3335
|
+
const exportNameSet = new Set(eventConfigExports.map((e) => e.name));
|
|
3336
|
+
const changes = modifyHandler(handler, exportNameSet);
|
|
3337
|
+
if (changes.length === 0) {
|
|
3338
|
+
console.log(`
|
|
3339
|
+
[${handlerRelPath}] already wired to ${EVENTS_INDEX_IMPORT_PATH} \u2014 no changes.`);
|
|
3340
|
+
return;
|
|
3341
|
+
}
|
|
3342
|
+
for (const c of changes) console.log(` [${handlerRelPath}] ${c}`);
|
|
3343
|
+
await handler.save();
|
|
3344
|
+
console.log(`
|
|
3345
|
+
Saved ${handlerRelPath}.`);
|
|
3346
|
+
}
|
|
3347
|
+
|
|
3348
|
+
// src/migrations/v2.0/checkout-upstream-files.ts
|
|
3349
|
+
var import_child_process = require("child_process");
|
|
3350
|
+
var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
|
|
3351
|
+
var UPSTREAM_BRANCH = "develop";
|
|
3352
|
+
var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
|
|
3353
|
+
var FILES_TO_CHECKOUT = [
|
|
3354
|
+
"infrastructure/postgres/setup-analytics.sh",
|
|
3355
|
+
"src/analytics/analytics.ts"
|
|
3356
|
+
];
|
|
3357
|
+
function runGit(args, { silent = false } = {}) {
|
|
3358
|
+
return (0, import_child_process.execFileSync)("git", args, {
|
|
3359
|
+
cwd: getCwd(),
|
|
3360
|
+
encoding: "utf8",
|
|
3361
|
+
stdio: silent ? ["ignore", "pipe", "pipe"] : ["ignore", "pipe", "inherit"]
|
|
3362
|
+
});
|
|
3363
|
+
}
|
|
3364
|
+
function tryGit(args) {
|
|
3365
|
+
try {
|
|
3366
|
+
runGit(args, { silent: true });
|
|
3367
|
+
return true;
|
|
3368
|
+
} catch {
|
|
3369
|
+
return false;
|
|
3370
|
+
}
|
|
3371
|
+
}
|
|
3372
|
+
function assertIsGitRepo() {
|
|
3373
|
+
if (!tryGit(["rev-parse", "--is-inside-work-tree"])) {
|
|
3374
|
+
throw new Error(
|
|
3375
|
+
`checkout-upstream-files: ${getCwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`
|
|
3376
|
+
);
|
|
3377
|
+
}
|
|
3378
|
+
}
|
|
3379
|
+
async function main17() {
|
|
3380
|
+
console.log(
|
|
3381
|
+
`Checking out ${FILES_TO_CHECKOUT.length} file(s) from ${UPSTREAM_URL}@${UPSTREAM_BRANCH}...
|
|
3382
|
+
`
|
|
3383
|
+
);
|
|
3384
|
+
assertIsGitRepo();
|
|
3385
|
+
tryGit(["remote", "remove", TEMP_REMOTE]);
|
|
3386
|
+
try {
|
|
3387
|
+
console.log(` Adding temporary remote '${TEMP_REMOTE}' \u2192 ${UPSTREAM_URL}`);
|
|
3388
|
+
runGit(["remote", "add", TEMP_REMOTE, UPSTREAM_URL], { silent: true });
|
|
3389
|
+
console.log(` Fetching ${TEMP_REMOTE}/${UPSTREAM_BRANCH} (depth 1)...`);
|
|
3390
|
+
runGit(["fetch", "--depth=1", TEMP_REMOTE, UPSTREAM_BRANCH]);
|
|
3391
|
+
const ref = `${TEMP_REMOTE}/${UPSTREAM_BRANCH}`;
|
|
3392
|
+
const missing = [];
|
|
3393
|
+
let checkedOut = 0;
|
|
3394
|
+
for (const file of FILES_TO_CHECKOUT) {
|
|
3395
|
+
if (tryGit(["checkout", ref, "--", file])) {
|
|
3396
|
+
console.log(` Checked out ${file} from ${ref}`);
|
|
3397
|
+
checkedOut++;
|
|
3398
|
+
} else {
|
|
3399
|
+
console.warn(
|
|
3400
|
+
` [warn] ${file} not found on ${ref} \u2014 skipping. Verify the path exists on that branch.`
|
|
3401
|
+
);
|
|
3402
|
+
missing.push(file);
|
|
3403
|
+
}
|
|
3404
|
+
}
|
|
3405
|
+
console.log(
|
|
3406
|
+
`
|
|
3407
|
+
Checked out ${checkedOut}/${FILES_TO_CHECKOUT.length} file(s) from ${ref}.`
|
|
3408
|
+
);
|
|
3409
|
+
if (missing.length > 0) {
|
|
3410
|
+
console.warn(` Missing on upstream branch: ${missing.join(", ")}`);
|
|
3411
|
+
}
|
|
3412
|
+
if (checkedOut > 0) {
|
|
3413
|
+
console.log(
|
|
3414
|
+
` Review the staged changes with: git diff --cached -- ${FILES_TO_CHECKOUT.map(
|
|
3415
|
+
(f) => `'${f}'`
|
|
3416
|
+
).join(" ")}
|
|
3417
|
+
`
|
|
3418
|
+
);
|
|
3419
|
+
}
|
|
3420
|
+
} finally {
|
|
3421
|
+
if (tryGit(["remote", "remove", TEMP_REMOTE])) {
|
|
3422
|
+
console.log(` Removed temporary remote '${TEMP_REMOTE}'.`);
|
|
3423
|
+
}
|
|
3424
|
+
}
|
|
3425
|
+
}
|
|
3426
|
+
|
|
3427
|
+
// src/migrations/v2.0/simplify-analytics-precalculations.ts
|
|
3428
|
+
var import_ts_morph16 = require("ts-morph");
|
|
3429
|
+
var import_fs2 = __toESM(require("fs"));
|
|
3430
|
+
var import_path17 = __toESM(require("path"));
|
|
3431
|
+
var ANALYTICS_FILE_REL = "src/analytics/analytics.ts";
|
|
3432
|
+
var FUNCTION_NAME = "precalculateAdditionalAnalytics";
|
|
3433
|
+
var IMPORT_NAMES_TO_REMOVE = /* @__PURE__ */ new Set(["Event", "precalculateBirthEvent"]);
|
|
3434
|
+
var RETURN_EXPRESSION_TEXT = "declaration";
|
|
3435
|
+
function removeTargetedNamedImports(sourceFile) {
|
|
3436
|
+
const log = [];
|
|
3437
|
+
for (const importDecl of [...sourceFile.getImportDeclarations()]) {
|
|
3438
|
+
const namedImports = importDecl.getNamedImports();
|
|
3439
|
+
if (namedImports.length === 0) continue;
|
|
3440
|
+
const matched = namedImports.filter(
|
|
3441
|
+
(ni) => IMPORT_NAMES_TO_REMOVE.has(ni.getName())
|
|
3442
|
+
);
|
|
3443
|
+
if (matched.length === 0) continue;
|
|
3444
|
+
const removedNames = matched.map((ni) => ni.getName());
|
|
3445
|
+
for (const ni of matched) ni.remove();
|
|
3446
|
+
log.push(
|
|
3447
|
+
`removed import(s) ${removedNames.join(", ")} from '${importDecl.getModuleSpecifierValue()}'`
|
|
3448
|
+
);
|
|
3449
|
+
const stillUsed = importDecl.getNamedImports().length > 0 || importDecl.getDefaultImport() || importDecl.getNamespaceImport();
|
|
3450
|
+
if (!stillUsed) importDecl.remove();
|
|
3451
|
+
}
|
|
3452
|
+
return log;
|
|
3453
|
+
}
|
|
3454
|
+
function findPrecalculateFunction(sourceFile) {
|
|
3455
|
+
for (const fn of sourceFile.getFunctions()) {
|
|
3456
|
+
if (fn.getName() === FUNCTION_NAME) return fn;
|
|
3457
|
+
}
|
|
3458
|
+
for (const statement of sourceFile.getVariableStatements()) {
|
|
3459
|
+
for (const decl of statement.getDeclarations()) {
|
|
3460
|
+
if (decl.getName() === FUNCTION_NAME) return decl;
|
|
3461
|
+
}
|
|
3462
|
+
}
|
|
3463
|
+
return void 0;
|
|
3464
|
+
}
|
|
3465
|
+
function getFunctionBodyBlock(fn) {
|
|
3466
|
+
if (import_ts_morph16.Node.isFunctionDeclaration(fn)) return fn.getBody();
|
|
3467
|
+
const initializer = fn.getInitializer();
|
|
3468
|
+
if (!initializer) return void 0;
|
|
3469
|
+
if (!import_ts_morph16.Node.isArrowFunction(initializer) && !import_ts_morph16.Node.isFunctionExpression(initializer)) {
|
|
3470
|
+
return void 0;
|
|
3471
|
+
}
|
|
3472
|
+
return initializer.getBody();
|
|
3473
|
+
}
|
|
3474
|
+
function simplifyPrecalculateFunction(sourceFile) {
|
|
3475
|
+
const log = [];
|
|
3476
|
+
const fn = findPrecalculateFunction(sourceFile);
|
|
3477
|
+
if (!fn) return log;
|
|
3478
|
+
const body = getFunctionBodyBlock(fn);
|
|
3479
|
+
if (!body || !import_ts_morph16.Node.isBlock(body)) return log;
|
|
3480
|
+
for (const statement of [...body.getStatements()]) {
|
|
3481
|
+
const references = statement.getDescendantsOfKind(import_ts_morph16.SyntaxKind.Identifier).some((id) => IMPORT_NAMES_TO_REMOVE.has(id.getText()));
|
|
3482
|
+
if (references) {
|
|
3483
|
+
statement.remove();
|
|
3484
|
+
log.push(`removed statement in ${FUNCTION_NAME} referencing removed imports`);
|
|
3485
|
+
}
|
|
3486
|
+
}
|
|
3487
|
+
const remaining = body.getStatements();
|
|
3488
|
+
const last = remaining[remaining.length - 1];
|
|
3489
|
+
const alreadyCorrect = last && import_ts_morph16.Node.isReturnStatement(last) && last.getExpression()?.getText() === RETURN_EXPRESSION_TEXT;
|
|
3490
|
+
if (!alreadyCorrect) {
|
|
3491
|
+
body.addStatements(`return ${RETURN_EXPRESSION_TEXT}`);
|
|
3492
|
+
log.push(
|
|
3493
|
+
`ensured '${FUNCTION_NAME}' ends with 'return ${RETURN_EXPRESSION_TEXT}'`
|
|
3494
|
+
);
|
|
3495
|
+
}
|
|
3496
|
+
return log;
|
|
3497
|
+
}
|
|
3498
|
+
async function main18() {
|
|
3499
|
+
const cwd2 = getCwd();
|
|
3500
|
+
const absPath = import_path17.default.join(cwd2, ANALYTICS_FILE_REL);
|
|
3501
|
+
if (!import_fs2.default.existsSync(absPath)) {
|
|
3502
|
+
console.log(
|
|
3503
|
+
`[${ANALYTICS_FILE_REL}] does not exist \u2014 nothing to clean up.`
|
|
3504
|
+
);
|
|
3505
|
+
return;
|
|
3506
|
+
}
|
|
3507
|
+
const project = new import_ts_morph16.Project({
|
|
3508
|
+
tsConfigFilePath: import_path17.default.resolve(cwd2, "tsconfig.json"),
|
|
3509
|
+
skipAddingFilesFromTsConfig: false
|
|
3510
|
+
});
|
|
3511
|
+
const sourceFile = project.getSourceFile(absPath);
|
|
3512
|
+
if (!sourceFile) {
|
|
3513
|
+
console.log(
|
|
3514
|
+
`[${ANALYTICS_FILE_REL}] is not part of the tsconfig project. Skipping.`
|
|
3515
|
+
);
|
|
3516
|
+
return;
|
|
3517
|
+
}
|
|
3518
|
+
console.log(`Cleaning up ${ANALYTICS_FILE_REL}...
|
|
3519
|
+
`);
|
|
3520
|
+
const importLogs = removeTargetedNamedImports(sourceFile);
|
|
3521
|
+
const fnLogs = simplifyPrecalculateFunction(sourceFile);
|
|
3522
|
+
const allLogs = [...importLogs, ...fnLogs];
|
|
3523
|
+
if (allLogs.length === 0) {
|
|
3524
|
+
console.log(`[${ANALYTICS_FILE_REL}] already clean \u2014 nothing to do.`);
|
|
3525
|
+
return;
|
|
3526
|
+
}
|
|
3527
|
+
for (const log of allLogs) {
|
|
3528
|
+
console.log(` [${ANALYTICS_FILE_REL}] ${log}`);
|
|
3529
|
+
}
|
|
3530
|
+
await sourceFile.save();
|
|
3531
|
+
console.log(`
|
|
3532
|
+
Saved ${ANALYTICS_FILE_REL}.`);
|
|
3533
|
+
}
|
|
3534
|
+
|
|
3067
3535
|
// src/migrations/v2.0/index.ts
|
|
3068
3536
|
var cwd;
|
|
3069
3537
|
function getCwd() {
|
|
@@ -3097,4 +3565,8 @@ async function runUpgrade(ccwd) {
|
|
|
3097
3565
|
await main11();
|
|
3098
3566
|
await main12();
|
|
3099
3567
|
await main14();
|
|
3568
|
+
await main15();
|
|
3569
|
+
await main16();
|
|
3570
|
+
await main17();
|
|
3571
|
+
await main18();
|
|
3100
3572
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-hearth-migrations.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/remove-hearth-migrations.ts"],"names":[],"mappings":"AA2BA,iBAAe,IAAI,kBAalB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1,78 @@
|
|
|
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
15
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
16
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
17
|
+
}
|
|
18
|
+
Object.defineProperty(o, k2, desc);
|
|
19
|
+
}) : (function(o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k;
|
|
21
|
+
o[k2] = m[k];
|
|
22
|
+
}));
|
|
23
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
24
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
25
|
+
}) : function(o, v) {
|
|
26
|
+
o["default"] = v;
|
|
27
|
+
});
|
|
28
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.main = main;
|
|
49
|
+
const fs = __importStar(require("fs"));
|
|
50
|
+
const path_1 = __importDefault(require("path"));
|
|
51
|
+
const _1 = require(".");
|
|
52
|
+
const PATHS_TO_REMOVE = [
|
|
53
|
+
{
|
|
54
|
+
relativePath: 'src/migrations/hearth',
|
|
55
|
+
label: 'Hearth migrations directory'
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
relativePath: 'src/migrations/user-mgnt',
|
|
59
|
+
label: 'user-mgnt migrations directory'
|
|
60
|
+
},
|
|
61
|
+
{ relativePath: 'src/utils/hearth-helpers.ts', label: 'Hearth helpers file' }
|
|
62
|
+
];
|
|
63
|
+
function main() {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
for (const { relativePath, label } of PATHS_TO_REMOVE) {
|
|
66
|
+
const absolutePath = path_1.default.join((0, _1.getCwd)(), relativePath);
|
|
67
|
+
if (fs.existsSync(absolutePath)) {
|
|
68
|
+
fs.rmSync(absolutePath, { recursive: true, force: true });
|
|
69
|
+
// eslint-disable-next-line no-console
|
|
70
|
+
console.log(`Removed ${label} '${relativePath}'.`);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
// eslint-disable-next-line no-console
|
|
74
|
+
console.log(`No ${label} found at '${relativePath}'.`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simplify-analytics-precalculations.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/simplify-analytics-precalculations.ts"],"names":[],"mappings":"AAuLA,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAyCnC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|