@opencrvs/toolkit 2.0.0-rc.c22cdf5 → 2.0.0-rc.c298173

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.
Files changed (45) hide show
  1. package/create-countryconfig/index.js +50 -20
  2. package/create-countryconfig/package.json +12 -2
  3. package/dist/application-config/index.js +273 -120
  4. package/dist/cli.js +164 -69
  5. package/dist/commons/api/router.d.ts +3359 -217
  6. package/dist/commons/application-config/index.d.ts +1 -0
  7. package/dist/commons/conditionals/conditionals.d.ts +354 -4
  8. package/dist/commons/conditionals/validate.d.ts +52 -2
  9. package/dist/commons/events/ActionConfig.d.ts +28 -2
  10. package/dist/commons/events/ActionDocument.d.ts +6 -0
  11. package/dist/commons/events/ActionInput.d.ts +114 -0
  12. package/dist/commons/events/AdvancedSearchConfig.d.ts +342 -0
  13. package/dist/commons/events/CountryConfigQueryInput.d.ts +42 -0
  14. package/dist/commons/events/Draft.d.ts +4 -2
  15. package/dist/commons/events/EventDocument.d.ts +3 -0
  16. package/dist/commons/events/EventIndex.d.ts +14 -3
  17. package/dist/commons/events/EventMetadata.d.ts +0 -7
  18. package/dist/commons/events/FieldConfig.d.ts +378 -50
  19. package/dist/commons/events/FieldType.d.ts +1 -0
  20. package/dist/commons/events/FieldTypeMapping.d.ts +1 -1
  21. package/dist/commons/events/FieldValue.d.ts +6 -0
  22. package/dist/commons/events/WorkqueueConfig.d.ts +189 -150
  23. package/dist/commons/events/field.d.ts +53 -1
  24. package/dist/commons/events/index.d.ts +2 -0
  25. package/dist/commons/events/state/flags.d.ts +16 -0
  26. package/dist/commons/events/state/index.d.ts +0 -4
  27. package/dist/commons/events/state/utils.d.ts +12 -289
  28. package/dist/commons/events/utils.d.ts +13 -2
  29. package/dist/conditionals/index.js +55 -2
  30. package/dist/events/index.js +1077 -285
  31. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +1 -1
  32. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
  33. package/dist/migrations/v2.0/checkout-upstream-files.js +1 -1
  34. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts +3 -0
  35. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts.map +1 -0
  36. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.js +110 -0
  37. package/dist/migrations/v2.0/index.d.ts.map +1 -1
  38. package/dist/migrations/v2.0/index.js +162 -67
  39. package/dist/notification/index.js +901 -156
  40. package/dist/scopes/index.d.ts +4 -6
  41. package/dist/scopes/index.js +12 -4
  42. package/opencrvs-toolkit-2.0.0-rc.c298173.tgz +0 -0
  43. package/package.json +6 -2
  44. package/tsconfig.tsbuildinfo +1 -1
  45. package/opencrvs-toolkit-2.0.0-rc.c22cdf5.tgz +0 -0
@@ -1,5 +1,5 @@
1
1
  export declare const UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
2
- export declare const UPSTREAM_BRANCH = "release-v2.0.0";
2
+ export declare const UPSTREAM_BRANCH = "release/2.0.0";
3
3
  /**
4
4
  * Runs a git command in the country config working directory.
5
5
  *
@@ -1 +1 @@
1
- {"version":3,"file":"checkout-upstream-files.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/checkout-upstream-files.ts"],"names":[],"mappings":"AA8CA,eAAO,MAAM,YAAY,2DACiC,CAAA;AAE1D,eAAO,MAAM,eAAe,mBAAmB,CAAA;AAc/C;;;;;;GAMG;AACH,wBAAgB,MAAM,CACpB,IAAI,EAAE,MAAM,EAAE,EACd,EAAE,MAAc,EAAE,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GAC5C,MAAM,CAMR;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAO9C;AAED,wBAAgB,eAAe,IAAI,IAAI,CAMtC;AAID,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAuDnC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
1
+ {"version":3,"file":"checkout-upstream-files.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/checkout-upstream-files.ts"],"names":[],"mappings":"AA8CA,eAAO,MAAM,YAAY,2DACiC,CAAA;AAE1D,eAAO,MAAM,eAAe,kBAAkB,CAAA;AAc9C;;;;;;GAMG;AACH,wBAAgB,MAAM,CACpB,IAAI,EAAE,MAAM,EAAE,EACd,EAAE,MAAc,EAAE,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GAC5C,MAAM,CAMR;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAO9C;AAED,wBAAgB,eAAe,IAAI,IAAI,CAMtC;AAID,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAuDnC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -59,7 +59,7 @@ exports.main = main;
59
59
  */
60
60
  const child_process_1 = require("child_process");
61
61
  exports.UPSTREAM_URL = 'https://github.com/opencrvs/opencrvs-countryconfig.git';
62
- exports.UPSTREAM_BRANCH = 'release-v2.0.0';
62
+ exports.UPSTREAM_BRANCH = 'release/2.0.0';
63
63
  // Remote name used only for the duration of this codemod. Prefixed to avoid
64
64
  // clashing with remotes the user may have (origin, upstream, etc.).
65
65
  const TEMP_REMOTE = 'opencrvs-upgrade-v19-v20-codemod';
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=fix-accept-requested-registration-function-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fix-accept-requested-registration-function-type.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/fix-accept-requested-registration-function-type.ts"],"names":[],"mappings":"AAuFA,iBAAe,IAAI,kBA6ClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ /*
3
+ * This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
+ *
7
+ * OpenCRVS is also distributed under the terms of the Civil Registration
8
+ * & Healthcare Disclaimer located at http://opencrvs.org/license.
9
+ *
10
+ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
11
+ */
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.main = main;
26
+ /**
27
+ * Codemod: In `acceptRequestedRegistration`, update the `action` parameter type from:
28
+ * action: ActionInput
29
+ * to:
30
+ * action: Extract<ActionInput, { type?: 'REGISTER' }>
31
+ *
32
+ * What it does:
33
+ * - Scans all TypeScript files under `src/`
34
+ * - Finds `acceptRequestedRegistration` (function declaration or const assignment)
35
+ * - Rewrites only the `action` parameter when its type is exactly `ActionInput`
36
+ * - Saves modified files in-place
37
+ */
38
+ /* eslint-disable no-console */
39
+ const ts_morph_1 = require("ts-morph");
40
+ const path_1 = __importDefault(require("path"));
41
+ const TARGET_FUNCTION_NAME = 'acceptRequestedRegistration';
42
+ const ACTION_PARAMETER_NAME = 'action';
43
+ const OLD_TYPE = 'ActionInput';
44
+ const NEW_TYPE = "Extract<ActionInput, { type?: 'REGISTER' }>";
45
+ function isAcceptRequestedRegistrationParameter(parameter) {
46
+ const functionDeclaration = parameter.getFirstAncestorByKind(ts_morph_1.SyntaxKind.FunctionDeclaration);
47
+ if ((functionDeclaration === null || functionDeclaration === void 0 ? void 0 : functionDeclaration.getName()) === TARGET_FUNCTION_NAME) {
48
+ return true;
49
+ }
50
+ const arrowFunction = parameter.getFirstAncestorByKind(ts_morph_1.SyntaxKind.ArrowFunction);
51
+ const variableDeclaration = arrowFunction === null || arrowFunction === void 0 ? void 0 : arrowFunction.getFirstAncestorByKind(ts_morph_1.SyntaxKind.VariableDeclaration);
52
+ return (variableDeclaration === null || variableDeclaration === void 0 ? void 0 : variableDeclaration.getName()) === TARGET_FUNCTION_NAME;
53
+ }
54
+ function processFile(filePath, project) {
55
+ const sourceFile = project.getSourceFile(filePath);
56
+ if (!sourceFile)
57
+ return 0;
58
+ let updatedCount = 0;
59
+ for (const parameter of sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.Parameter)) {
60
+ if (parameter.getName() !== ACTION_PARAMETER_NAME) {
61
+ continue;
62
+ }
63
+ if (!isAcceptRequestedRegistrationParameter(parameter)) {
64
+ continue;
65
+ }
66
+ const typeNode = parameter.getTypeNode();
67
+ if (!typeNode || typeNode.getText() !== OLD_TYPE) {
68
+ continue;
69
+ }
70
+ parameter.setType(NEW_TYPE);
71
+ updatedCount++;
72
+ console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Updated '${ACTION_PARAMETER_NAME}' in ${TARGET_FUNCTION_NAME} to ${NEW_TYPE}`);
73
+ }
74
+ return updatedCount;
75
+ }
76
+ function main() {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ const srcDir = path_1.default.join(process.cwd(), 'src');
79
+ console.log(`Scanning for ${TARGET_FUNCTION_NAME} in: ${srcDir}\n`);
80
+ const project = new ts_morph_1.Project({
81
+ tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
82
+ skipAddingFilesFromTsConfig: false
83
+ });
84
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
85
+ const filePath = sf.getFilePath();
86
+ return filePath.includes('/src/') && !filePath.includes('/node_modules/');
87
+ });
88
+ let totalUpdated = 0;
89
+ const modifiedFiles = [];
90
+ for (const sourceFile of sourceFiles) {
91
+ const filePath = sourceFile.getFilePath();
92
+ const updated = processFile(filePath, project);
93
+ if (updated > 0) {
94
+ totalUpdated += updated;
95
+ modifiedFiles.push(filePath);
96
+ }
97
+ }
98
+ if (modifiedFiles.length === 0) {
99
+ console.log(`No '${ACTION_PARAMETER_NAME}: ${OLD_TYPE}' parameter in ${TARGET_FUNCTION_NAME} found. Nothing to do.`);
100
+ return;
101
+ }
102
+ console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
103
+ for (const filePath of modifiedFiles) {
104
+ const sourceFile = project.getSourceFileOrThrow(filePath);
105
+ yield sourceFile.save();
106
+ console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
107
+ }
108
+ console.log(`\nDone. Updated ${totalUpdated} parameter type annotation(s) in ${TARGET_FUNCTION_NAME}.`);
109
+ });
110
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/index.ts"],"names":[],"mappings":"AA6CA;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAAC,WAAW,EAAE,OAAO,iBAgCpD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/index.ts"],"names":[],"mappings":"AA8CA;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAAC,WAAW,EAAE,OAAO,iBAiCpD"}
@@ -1895,9 +1895,9 @@ function updateRouteHandlers(sourceFiles, group, srcDir, relCwd) {
1895
1895
  }
1896
1896
  return replacedCount;
1897
1897
  }
1898
- function resolveConfigChain(configObj, path23) {
1898
+ function resolveConfigChain(configObj, path24) {
1899
1899
  let current = configObj;
1900
- for (const key of path23) {
1900
+ for (const key of path24) {
1901
1901
  if (!import_ts_morph10.Node.isObjectLiteralExpression(current)) return null;
1902
1902
  const prop = current.getProperty(key);
1903
1903
  if (!prop || !import_ts_morph10.Node.isPropertyAssignment(prop)) return null;
@@ -2394,18 +2394,26 @@ var encodeScope = (scope) => {
2394
2394
  encode: false
2395
2395
  });
2396
2396
  };
2397
- var decodeScope = (query) => {
2398
- const scope = qs.parse(query, {
2397
+ var decodedScopeCache = /* @__PURE__ */ new Map();
2398
+ var decodeScope = (encodedScope) => {
2399
+ if (decodedScopeCache.has(encodedScope)) {
2400
+ return decodedScopeCache.get(encodedScope);
2401
+ }
2402
+ const scope = qs.parse(encodedScope, {
2399
2403
  ignoreQueryPrefix: true,
2400
2404
  comma: true,
2401
2405
  allowDots: true
2402
2406
  });
2403
2407
  const unflattenedScope = unflattenScope(scope);
2404
- return Scope2.safeParse(unflattenedScope)?.data;
2408
+ const result = Scope2.safeParse(unflattenedScope)?.data;
2409
+ decodedScopeCache.set(encodedScope, result);
2410
+ return result;
2405
2411
  };
2406
2412
  var DEFAULT_SCOPE_OPTIONS = {
2407
2413
  placeOfEvent: JurisdictionFilter.enum.all,
2408
- accessLevel: JurisdictionFilter.enum.all
2414
+ accessLevel: JurisdictionFilter.enum.all,
2415
+ registeredIn: JurisdictionFilter.enum.all,
2416
+ declaredIn: JurisdictionFilter.enum.all
2409
2417
  };
2410
2418
 
2411
2419
  // ../commons/src/scopes.deprecated.do-not-use.ts
@@ -2646,71 +2654,69 @@ var MERGEABLE_USER_SCOPE_TYPES = ["user.create", "user.edit"];
2646
2654
  function isMergeableUserScopeType(type) {
2647
2655
  return MERGEABLE_USER_SCOPE_TYPES.includes(type);
2648
2656
  }
2649
- function migrateLegacyScopesArrayToV2Scopes(legacyScopes) {
2650
- const decoded = legacyScopes.map(
2651
- (legacy) => {
2652
- const encoded = legacyScopeToV2Scope(legacy);
2653
- const scope = decodeScope(encoded);
2654
- if (!scope) {
2655
- throw new Error(
2656
- `Could not decode migrated scope from legacy '${legacy}' (encoded: '${encoded}').`
2657
- );
2658
- }
2659
- return { legacy, scope };
2660
- }
2657
+ function decodeLegacyScope(legacy) {
2658
+ const encoded = legacyScopeToV2Scope(legacy);
2659
+ const scope = decodeScope(encoded);
2660
+ if (!scope) {
2661
+ throw new Error(
2662
+ `Could not decode migrated scope from legacy '${legacy}' (encoded: '${encoded}').`
2663
+ );
2664
+ }
2665
+ return { legacy, scope };
2666
+ }
2667
+ function groupByType(entries) {
2668
+ return entries.reduce(
2669
+ (groups, entry) => ({
2670
+ ...groups,
2671
+ [entry.scope.type]: [...groups[entry.scope.type] ?? [], entry]
2672
+ }),
2673
+ {}
2674
+ );
2675
+ }
2676
+ function deduplicateEntries(entries) {
2677
+ return entries.filter(
2678
+ (entry, index) => entries.findIndex((e) => (0, import_lodash.isEqual)(e.scope, entry.scope)) === index
2679
+ );
2680
+ }
2681
+ function mergeEntries(type, entries) {
2682
+ const optionsList = entries.map(
2683
+ (e) => "options" in e.scope && e.scope.options ? e.scope.options : {}
2661
2684
  );
2662
- const groups = /* @__PURE__ */ new Map();
2663
- for (const entry of decoded) {
2664
- const list = groups.get(entry.scope.type) ?? [];
2665
- list.push(entry);
2666
- groups.set(entry.scope.type, list);
2685
+ const allKeys = optionsList.flatMap(
2686
+ (opts) => Object.keys(opts).filter((k) => opts[k] !== void 0)
2687
+ );
2688
+ const conflictKey = allKeys.find((key, i) => allKeys.indexOf(key) !== i);
2689
+ if (conflictKey) {
2690
+ const conflicting = entries.filter(
2691
+ (e) => conflictKey in ("options" in e.scope && e.scope.options || {})
2692
+ ).map((e) => JSON.stringify(e.legacy));
2693
+ throw new Error(
2694
+ `Cannot auto-merge two '${type}' scopes that both define '${conflictKey}'. Conflicting legacy scopes: [${conflicting.join(", ")}]. Resolve manually in roles.ts and re-run.`
2695
+ );
2667
2696
  }
2668
- const result = [];
2669
- for (const [type, entries] of groups) {
2670
- const deduped = [];
2671
- for (const entry of entries) {
2672
- if (!deduped.some((existing) => (0, import_lodash.isEqual)(existing.scope, entry.scope))) {
2673
- deduped.push(entry);
2674
- }
2675
- }
2676
- if (deduped.length <= 1) {
2677
- result.push(...deduped.map((e) => e.scope));
2678
- continue;
2679
- }
2697
+ const mergedOptions = Object.assign({}, ...optionsList);
2698
+ const merged = Object.keys(mergedOptions).length > 0 ? { type, options: mergedOptions } : { type };
2699
+ const parsed = Scope2.safeParse(merged);
2700
+ if (!parsed.success) {
2701
+ throw new Error(
2702
+ `Merged '${type}' scope failed schema validation: ${parsed.error.message}. Legacy scopes: [${entries.map((e) => JSON.stringify(e.legacy)).join(", ")}].`
2703
+ );
2704
+ }
2705
+ return parsed.data;
2706
+ }
2707
+ function migrateLegacyScopesArrayToV2Scopes(legacyScopes) {
2708
+ const groups = groupByType(legacyScopes.map(decodeLegacyScope));
2709
+ return Object.entries(groups).flatMap(([type, entries]) => {
2710
+ const deduped = deduplicateEntries(entries);
2711
+ if (deduped.length <= 1) return deduped.map((e) => e.scope);
2680
2712
  if (!isMergeableUserScopeType(type)) {
2681
2713
  console.warn(
2682
2714
  `Multiple non-mergeable '${type}' scopes detected after dedup \u2014 kept all as-is. Legacy scopes: [${deduped.map((e) => JSON.stringify(e.legacy)).join(", ")}]. Review whether the duplication is intentional.`
2683
2715
  );
2684
- result.push(...deduped.map((e) => e.scope));
2685
- continue;
2716
+ return deduped.map((e) => e.scope);
2686
2717
  }
2687
- const mergedOptions = {};
2688
- const optionSources = /* @__PURE__ */ new Map();
2689
- for (const entry of deduped) {
2690
- const opts = "options" in entry.scope && entry.scope.options ? entry.scope.options : {};
2691
- for (const [key, value] of Object.entries(opts)) {
2692
- if (value === void 0) continue;
2693
- if (key in mergedOptions) {
2694
- const previous = optionSources.get(key) ?? [];
2695
- const conflicting = [...previous, entry.legacy];
2696
- throw new Error(
2697
- `Cannot auto-merge two '${type}' scopes that both define '${key}'. Conflicting legacy scopes: [${conflicting.map((s) => JSON.stringify(s)).join(", ")}]. Resolve manually in roles.ts and re-run.`
2698
- );
2699
- }
2700
- mergedOptions[key] = value;
2701
- optionSources.set(key, [entry.legacy]);
2702
- }
2703
- }
2704
- const merged = Object.keys(mergedOptions).length > 0 ? { type, options: mergedOptions } : { type };
2705
- const parsed = Scope2.safeParse(merged);
2706
- if (!parsed.success) {
2707
- throw new Error(
2708
- `Merged '${type}' scope failed schema validation: ${parsed.error.message}. Legacy scopes: [${deduped.map((e) => JSON.stringify(e.legacy)).join(", ")}].`
2709
- );
2710
- }
2711
- result.push(parsed.data);
2712
- }
2713
- return result;
2718
+ return [mergeEntries(type, deduped)];
2719
+ });
2714
2720
  }
2715
2721
 
2716
2722
  // src/migrations/v2.0/migrate-scopes.ts
@@ -4306,7 +4312,7 @@ Saved ${handlerRelPath}.`);
4306
4312
  // src/migrations/v2.0/checkout-upstream-files.ts
4307
4313
  var import_child_process = require("child_process");
4308
4314
  var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
4309
- var UPSTREAM_BRANCH = "release-v2.0.0";
4315
+ var UPSTREAM_BRANCH = "release/2.0.0";
4310
4316
  var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
4311
4317
  var FILES_TO_CHECKOUT = [
4312
4318
  "src/analytics/analytics.ts",
@@ -4845,9 +4851,9 @@ var import_path24 = require("path");
4845
4851
  var TEMP_REMOTE2 = "opencrvs-upgrade-v19-v20-codemod-merge-infra";
4846
4852
  var INFRASTRUCTURE_DIR = "infrastructure";
4847
4853
  var BASE_BRANCH = "release-v1.9";
4848
- function gitShowBytes(ref, path23) {
4854
+ function gitShowBytes(ref, path24) {
4849
4855
  try {
4850
- const buf = (0, import_child_process2.execFileSync)("git", ["show", `${ref}:${path23}`], {
4856
+ const buf = (0, import_child_process2.execFileSync)("git", ["show", `${ref}:${path24}`], {
4851
4857
  cwd: process.cwd(),
4852
4858
  stdio: ["ignore", "pipe", "pipe"]
4853
4859
  });
@@ -5023,6 +5029,94 @@ async function main26({
5023
5029
  );
5024
5030
  }
5025
5031
 
5032
+ // src/migrations/v2.0/fix-accept-requested-registration-function-type.ts
5033
+ var import_ts_morph22 = require("ts-morph");
5034
+ var import_path26 = __toESM(require("path"));
5035
+ var TARGET_FUNCTION_NAME = "acceptRequestedRegistration";
5036
+ var ACTION_PARAMETER_NAME = "action";
5037
+ var OLD_TYPE = "ActionInput";
5038
+ var NEW_TYPE = "Extract<ActionInput, { type?: 'REGISTER' }>";
5039
+ function isAcceptRequestedRegistrationParameter(parameter) {
5040
+ const functionDeclaration = parameter.getFirstAncestorByKind(
5041
+ import_ts_morph22.SyntaxKind.FunctionDeclaration
5042
+ );
5043
+ if (functionDeclaration?.getName() === TARGET_FUNCTION_NAME) {
5044
+ return true;
5045
+ }
5046
+ const arrowFunction = parameter.getFirstAncestorByKind(
5047
+ import_ts_morph22.SyntaxKind.ArrowFunction
5048
+ );
5049
+ const variableDeclaration = arrowFunction?.getFirstAncestorByKind(
5050
+ import_ts_morph22.SyntaxKind.VariableDeclaration
5051
+ );
5052
+ return variableDeclaration?.getName() === TARGET_FUNCTION_NAME;
5053
+ }
5054
+ function processFile14(filePath, project) {
5055
+ const sourceFile = project.getSourceFile(filePath);
5056
+ if (!sourceFile) return 0;
5057
+ let updatedCount = 0;
5058
+ for (const parameter of sourceFile.getDescendantsOfKind(
5059
+ import_ts_morph22.SyntaxKind.Parameter
5060
+ )) {
5061
+ if (parameter.getName() !== ACTION_PARAMETER_NAME) {
5062
+ continue;
5063
+ }
5064
+ if (!isAcceptRequestedRegistrationParameter(parameter)) {
5065
+ continue;
5066
+ }
5067
+ const typeNode = parameter.getTypeNode();
5068
+ if (!typeNode || typeNode.getText() !== OLD_TYPE) {
5069
+ continue;
5070
+ }
5071
+ parameter.setType(NEW_TYPE);
5072
+ updatedCount++;
5073
+ console.log(
5074
+ ` [${import_path26.default.relative(process.cwd(), filePath)}] Updated '${ACTION_PARAMETER_NAME}' in ${TARGET_FUNCTION_NAME} to ${NEW_TYPE}`
5075
+ );
5076
+ }
5077
+ return updatedCount;
5078
+ }
5079
+ async function main27() {
5080
+ const srcDir = import_path26.default.join(process.cwd(), "src");
5081
+ console.log(`Scanning for ${TARGET_FUNCTION_NAME} in: ${srcDir}
5082
+ `);
5083
+ const project = new import_ts_morph22.Project({
5084
+ tsConfigFilePath: import_path26.default.resolve(srcDir, "../tsconfig.json"),
5085
+ skipAddingFilesFromTsConfig: false
5086
+ });
5087
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
5088
+ const filePath = sf.getFilePath();
5089
+ return filePath.includes("/src/") && !filePath.includes("/node_modules/");
5090
+ });
5091
+ let totalUpdated = 0;
5092
+ const modifiedFiles = [];
5093
+ for (const sourceFile of sourceFiles) {
5094
+ const filePath = sourceFile.getFilePath();
5095
+ const updated = processFile14(filePath, project);
5096
+ if (updated > 0) {
5097
+ totalUpdated += updated;
5098
+ modifiedFiles.push(filePath);
5099
+ }
5100
+ }
5101
+ if (modifiedFiles.length === 0) {
5102
+ console.log(
5103
+ `No '${ACTION_PARAMETER_NAME}: ${OLD_TYPE}' parameter in ${TARGET_FUNCTION_NAME} found. Nothing to do.`
5104
+ );
5105
+ return;
5106
+ }
5107
+ console.log(`
5108
+ Saving ${modifiedFiles.length} modified file(s)...`);
5109
+ for (const filePath of modifiedFiles) {
5110
+ const sourceFile = project.getSourceFileOrThrow(filePath);
5111
+ await sourceFile.save();
5112
+ console.log(` Saved: ${import_path26.default.relative(process.cwd(), filePath)}`);
5113
+ }
5114
+ console.log(
5115
+ `
5116
+ Done. Updated ${totalUpdated} parameter type annotation(s) in ${TARGET_FUNCTION_NAME}.`
5117
+ );
5118
+ }
5119
+
5026
5120
  // src/migrations/v2.0/index.ts
5027
5121
  var NON_SWARM_INFRA_SUBDIRS = ["postgres", "metabase"];
5028
5122
  async function runUpgrade(dockerSwarm) {
@@ -5049,6 +5143,7 @@ async function runUpgrade(dockerSwarm) {
5049
5143
  await main22();
5050
5144
  await main23();
5051
5145
  await main24();
5146
+ await main27();
5052
5147
  await main17();
5053
5148
  if (dockerSwarm) {
5054
5149
  await main25();