@opencrvs/toolkit 2.0.0-rc.bba732d → 2.0.0-rc.bcb5fb2

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.
@@ -0,0 +1,2 @@
1
+ declare const translations: Record<string, { defaultMessage: string; description: string }>
2
+ export default translations
@@ -1,5 +1,5 @@
1
1
  export declare const UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
2
- export declare const UPSTREAM_BRANCH = "develop";
2
+ export declare const UPSTREAM_BRANCH = "release-v2.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;AAG1D,eAAO,MAAM,eAAe,YAAY,CAAA;AAcxC;;;;;;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,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"}
@@ -59,8 +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
- // @TODO: This needs to be changed to 'release-v2.0.0' once the branch is created
63
- exports.UPSTREAM_BRANCH = 'develop';
62
+ exports.UPSTREAM_BRANCH = 'release-v2.0.0';
64
63
  // Remote name used only for the duration of this codemod. Prefixed to avoid
65
64
  // clashing with remotes the user may have (origin, upstream, etc.).
66
65
  const TEMP_REMOTE = 'opencrvs-upgrade-v19-v20-codemod';
@@ -1,3 +1,11 @@
1
- declare function main(): Promise<void>;
1
+ interface DeleteInfrastructureOptions {
2
+ /**
3
+ * Top-level entries directly under `infrastructure/` to preserve. Names
4
+ * match against the basename of each entry (file or directory). When
5
+ * empty (the default), the whole `infrastructure/` directory is deleted.
6
+ */
7
+ keep?: string[];
8
+ }
9
+ declare function main({ keep }?: DeleteInfrastructureOptions): Promise<void>;
2
10
  export { main };
3
11
  //# sourceMappingURL=delete-infrastructure-directory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"delete-infrastructure-directory.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/delete-infrastructure-directory.ts"],"names":[],"mappings":"AA4CA,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAgCnC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
1
+ {"version":3,"file":"delete-infrastructure-directory.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/delete-infrastructure-directory.ts"],"names":[],"mappings":"AAoDA,UAAU,2BAA2B;IACnC;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;CAChB;AAED,iBAAe,IAAI,CAAC,EAClB,IAAS,EACV,GAAE,2BAAgC,GAAG,OAAO,CAAC,IAAI,CAAC,CA4FlD;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -27,20 +27,28 @@ exports.main = main;
27
27
  * via Docker Swarm. In that case the `infrastructure/` directory shipped
28
28
  * with opencrvs-countryconfig is no longer needed and can be removed.
29
29
  *
30
+ * Some non-Swarm deployments still need a small subset of
31
+ * `infrastructure/` (e.g. `postgres/` and `metabase/`). Pass `keep` to
32
+ * preserve those top-level subdirectories — everything else under
33
+ * `infrastructure/` is deleted, and the kept subdirectories can then be
34
+ * refreshed from upstream by `merge-infrastructure-directory.ts` with the
35
+ * matching `subdirs` option.
36
+ *
30
37
  * Usage:
31
38
  * ts-node -r tsconfig-paths/register src/migrations/v2.0/delete-infrastructure-directory.ts
32
39
  *
33
40
  * What it does:
34
41
  * 1. Stages deletion of all tracked files under `infrastructure/` via
35
- * `git rm -rf --ignore-unmatch -- infrastructure/`. This both removes
36
- * the files from the working tree and records the deletion in the
42
+ * `git rm -rf --ignore-unmatch -- <path>`. This both removes the
43
+ * files from the working tree and records the deletion in the
37
44
  * index, so it shows up in the upgrade commit alongside the other
38
- * codemod changes.
45
+ * codemod changes. When `keep` is provided, deletion is scoped to
46
+ * the top-level entries that are NOT in `keep`.
39
47
  * 2. Cleans up any untracked files / empty directory that `git rm` left
40
- * behind, so the path is fully gone from the working tree.
48
+ * behind, so the deleted paths are fully gone from the working tree.
41
49
  *
42
50
  * Caveats:
43
- * - Destructive: any local edits to `infrastructure/` are lost. Run on a
51
+ * - Destructive: any local edits to deleted paths are lost. Run on a
44
52
  * clean working tree (or after committing your local changes).
45
53
  * - If `infrastructure/` doesn't exist, this codemod is a no-op.
46
54
  * - Requires git to be installed and the country config working directory
@@ -51,27 +59,65 @@ const path_1 = require("path");
51
59
  const checkout_upstream_files_1 = require("./checkout-upstream-files");
52
60
  const INFRASTRUCTURE_DIR = 'infrastructure';
53
61
  function main() {
54
- return __awaiter(this, void 0, void 0, function* () {
62
+ return __awaiter(this, arguments, void 0, function* ({ keep = [] } = {}) {
55
63
  const fullPath = (0, path_1.join)(process.cwd(), INFRASTRUCTURE_DIR);
56
64
  if (!(0, fs_1.existsSync)(fullPath)) {
57
65
  console.log(`'${INFRASTRUCTURE_DIR}/' not found in ${process.cwd()} — nothing to delete.`);
58
66
  return;
59
67
  }
60
- console.log(`Deleting '${INFRASTRUCTURE_DIR}/'...\n`);
61
68
  (0, checkout_upstream_files_1.assertIsGitRepo)();
62
- // `git rm -rf --ignore-unmatch` removes tracked files (working tree + index)
63
- // and is a no-op for paths with no tracked entries, so it's safe to run
64
- // even when `infrastructure/` exists only as untracked files.
65
- (0, checkout_upstream_files_1.runGit)(['rm', '-rf', '--ignore-unmatch', '--', `${INFRASTRUCTURE_DIR}/`], {
66
- silent: true
67
- });
68
- console.log(` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR}/'.`);
69
- // `git rm` leaves untracked files (and any now-empty directory) on disk;
70
- // remove whatever's left so the path is fully gone.
71
- if ((0, fs_1.existsSync)(fullPath)) {
72
- (0, fs_1.rmSync)(fullPath, { recursive: true, force: true });
73
- console.log(` Removed remaining untracked files under '${INFRASTRUCTURE_DIR}/'.`);
69
+ // ─── Whole-directory delete (legacy behavior) ────────────────────────
70
+ if (keep.length === 0) {
71
+ console.log(`Deleting '${INFRASTRUCTURE_DIR}/'...\n`);
72
+ // `git rm -rf --ignore-unmatch` removes tracked files (working tree +
73
+ // index) and is a no-op for paths with no tracked entries, so it's
74
+ // safe to run even when `infrastructure/` exists only as untracked
75
+ // files.
76
+ (0, checkout_upstream_files_1.runGit)(['rm', '-rf', '--ignore-unmatch', '--', `${INFRASTRUCTURE_DIR}/`], {
77
+ silent: true
78
+ });
79
+ console.log(` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR}/'.`);
80
+ // `git rm` leaves untracked files (and any now-empty directory) on
81
+ // disk; remove whatever's left so the path is fully gone.
82
+ if ((0, fs_1.existsSync)(fullPath)) {
83
+ (0, fs_1.rmSync)(fullPath, { recursive: true, force: true });
84
+ console.log(` Removed remaining untracked files under '${INFRASTRUCTURE_DIR}/'.`);
85
+ }
86
+ console.log(`\n Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR}/'`);
87
+ return;
88
+ }
89
+ // ─── Selective delete: keep listed top-level entries ─────────────────
90
+ const keepSet = new Set(keep);
91
+ console.log(`Deleting contents of '${INFRASTRUCTURE_DIR}/' except: ${[...keepSet]
92
+ .map((name) => `'${name}'`)
93
+ .join(', ')}\n`);
94
+ const topLevelEntries = (0, fs_1.readdirSync)(fullPath, { withFileTypes: true });
95
+ let deleted = 0;
96
+ for (const entry of topLevelEntries) {
97
+ if (keepSet.has(entry.name)) {
98
+ console.log(` Keeping '${INFRASTRUCTURE_DIR}/${entry.name}'.`);
99
+ continue;
100
+ }
101
+ // Append a trailing slash for directories so git treats it as a tree
102
+ // pathspec (matches the recursive behavior of `git rm -rf`).
103
+ const relPath = `${INFRASTRUCTURE_DIR}/${entry.name}${entry.isDirectory() ? '/' : ''}`;
104
+ (0, checkout_upstream_files_1.runGit)(['rm', '-rf', '--ignore-unmatch', '--', relPath], { silent: true });
105
+ const fullEntryPath = (0, path_1.join)(fullPath, entry.name);
106
+ if ((0, fs_1.existsSync)(fullEntryPath)) {
107
+ (0, fs_1.rmSync)(fullEntryPath, { recursive: true, force: true });
108
+ }
109
+ console.log(` Deleted '${relPath}'.`);
110
+ deleted++;
111
+ }
112
+ // Note any requested keeps that weren't actually present, so the dev
113
+ // notices typos / missing directories.
114
+ const presentNames = new Set(topLevelEntries.map((e) => e.name));
115
+ const missingKeeps = [...keepSet].filter((name) => !presentNames.has(name));
116
+ if (missingKeeps.length > 0) {
117
+ console.warn(` [warn] Requested to keep ${missingKeeps
118
+ .map((n) => `'${n}'`)
119
+ .join(', ')} but they don't exist under '${INFRASTRUCTURE_DIR}/'.`);
74
120
  }
75
- console.log(`\n Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR}/'`);
121
+ console.log(`\n Done. Deleted ${deleted} top-level entr${deleted === 1 ? 'y' : 'ies'}. Review the staged deletions with: git diff --cached -- '${INFRASTRUCTURE_DIR}/'`);
76
122
  });
77
123
  }
@@ -3,9 +3,11 @@
3
3
  * directory.
4
4
  *
5
5
  * @param dockerSwarm - When true, the local `infrastructure/` directory is
6
- * merged with upstream changes (Docker Swarm deployments still need it).
7
- * When false (the default), `infrastructure/` is deleted entirely, since
8
- * non-Swarm deployments no longer ship it.
6
+ * merged with upstream changes in its entirety (Docker Swarm deployments
7
+ * still need it all). When false (the default), everything under
8
+ * `infrastructure/` is deleted EXCEPT the subdirectories listed in
9
+ * `NON_SWARM_INFRA_SUBDIRS`, and those preserved subdirectories are then
10
+ * merged with upstream.
9
11
  */
10
12
  export declare function runUpgrade(dockerSwarm: boolean): Promise<void>;
11
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/index.ts"],"names":[],"mappings":"AAqCA;;;;;;;;GAQG;AACH,wBAAsB,UAAU,CAAC,WAAW,EAAE,OAAO,iBA+BpD"}
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"}
@@ -3686,6 +3686,10 @@ var ACTION_PROPERTY_NAME2 = "action";
3686
3686
  var CONDITIONALS_PROPERTY_NAME = "conditionals";
3687
3687
  var TYPE_PROPERTY_NAME7 = "type";
3688
3688
  var SLUG_PROPERTY_NAME = "slug";
3689
+ var READ_ACTION_TYPE = "READ";
3690
+ var ACTION_TYPE_IMPORT_NAME = "ActionType";
3691
+ var TOOLKIT_EVENTS_MODULE2 = "@opencrvs/toolkit/events";
3692
+ var READ_ACTION_FALLBACK_INITIALIZER = `{ type: ${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE} }`;
3689
3693
  var SUPPORTED_WORKQUEUE_ACTION_TYPES = /* @__PURE__ */ new Set([
3690
3694
  "READ",
3691
3695
  "DELETE",
@@ -3733,91 +3737,137 @@ function isUnsupportedActionType(action) {
3733
3737
  }
3734
3738
  return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
3735
3739
  }
3736
- function migrateWorkqueueActions(workqueue, relPath) {
3737
- const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME5);
3738
- if (!actionsProperty || !import_ts_morph17.Node.isPropertyAssignment(actionsProperty)) {
3739
- return 0;
3740
- }
3741
- const actionsInitializer = actionsProperty.getInitializer();
3742
- if (!actionsInitializer || !import_ts_morph17.Node.isArrayLiteralExpression(actionsInitializer)) {
3743
- return 0;
3740
+ function ensureValidAction(workqueue, relPath) {
3741
+ const workqueueLabel = getWorkqueueLabel(workqueue);
3742
+ const actionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
3743
+ if (actionProperty && import_ts_morph17.Node.isPropertyAssignment(actionProperty)) {
3744
+ const initializer = actionProperty.getInitializer();
3745
+ if (initializer && import_ts_morph17.Node.isObjectLiteralExpression(initializer)) {
3746
+ if (!isUnsupportedActionType(initializer)) {
3747
+ return { changed: false, usedReadFallback: false };
3748
+ }
3749
+ actionProperty.set({
3750
+ name: ACTION_PROPERTY_NAME2,
3751
+ initializer: READ_ACTION_FALLBACK_INITIALIZER
3752
+ });
3753
+ console.log(
3754
+ ` [${relPath}] Replaced unsupported 'action' type with '${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE}' on workqueue '${workqueueLabel}'`
3755
+ );
3756
+ return { changed: true, usedReadFallback: true };
3757
+ }
3744
3758
  }
3759
+ workqueue.addPropertyAssignment({
3760
+ name: ACTION_PROPERTY_NAME2,
3761
+ initializer: READ_ACTION_FALLBACK_INITIALIZER
3762
+ });
3763
+ console.log(
3764
+ ` [${relPath}] Added default 'action: ${READ_ACTION_FALLBACK_INITIALIZER}' to workqueue '${workqueueLabel}'`
3765
+ );
3766
+ return { changed: true, usedReadFallback: true };
3767
+ }
3768
+ function migrateWorkqueueActions(workqueue, relPath) {
3745
3769
  const workqueueLabel = getWorkqueueLabel(workqueue);
3746
- const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
3747
- if (existingActionProperty) {
3748
- if (import_ts_morph17.Node.isPropertyAssignment(existingActionProperty)) {
3749
- const existingActionInitializer = existingActionProperty.getInitializer();
3750
- if (existingActionInitializer && import_ts_morph17.Node.isObjectLiteralExpression(existingActionInitializer)) {
3751
- const conditionalsProperty2 = existingActionInitializer.getProperty(
3752
- CONDITIONALS_PROPERTY_NAME
3770
+ const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME5);
3771
+ let actionsArrayMigrated = false;
3772
+ if (actionsProperty && import_ts_morph17.Node.isPropertyAssignment(actionsProperty)) {
3773
+ const actionsInitializer = actionsProperty.getInitializer();
3774
+ if (actionsInitializer && import_ts_morph17.Node.isArrayLiteralExpression(actionsInitializer)) {
3775
+ const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
3776
+ if (existingActionProperty) {
3777
+ if (import_ts_morph17.Node.isPropertyAssignment(existingActionProperty)) {
3778
+ const existingActionInitializer = existingActionProperty.getInitializer();
3779
+ if (existingActionInitializer && import_ts_morph17.Node.isObjectLiteralExpression(existingActionInitializer)) {
3780
+ const conditionalsProperty = existingActionInitializer.getProperty(
3781
+ CONDITIONALS_PROPERTY_NAME
3782
+ );
3783
+ if (conditionalsProperty) {
3784
+ conditionalsProperty.remove();
3785
+ console.log(
3786
+ ` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`
3787
+ );
3788
+ }
3789
+ }
3790
+ }
3791
+ actionsProperty.remove();
3792
+ console.log(
3793
+ ` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
3794
+ );
3795
+ actionsArrayMigrated = true;
3796
+ } else {
3797
+ const actionCandidates = actionsInitializer.getElements().filter(
3798
+ (element) => import_ts_morph17.Node.isObjectLiteralExpression(element)
3753
3799
  );
3754
- if (conditionalsProperty2) {
3755
- conditionalsProperty2.remove();
3800
+ if (actionCandidates.length === 0) {
3801
+ actionsProperty.remove();
3756
3802
  console.log(
3757
- ` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`
3803
+ ` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`
3758
3804
  );
3759
- }
3760
- if (isUnsupportedActionType(existingActionInitializer)) {
3761
- existingActionProperty.remove();
3762
- console.log(
3763
- ` [${relPath}] Removed unsupported 'action' type on workqueue '${workqueueLabel}'`
3805
+ actionsArrayMigrated = true;
3806
+ } else {
3807
+ if (actionCandidates.length > 1) {
3808
+ const droppedCount = actionCandidates.length - 1;
3809
+ console.warn(
3810
+ ` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
3811
+ );
3812
+ }
3813
+ const conditionalsProperty = actionCandidates[0].getProperty(
3814
+ CONDITIONALS_PROPERTY_NAME
3764
3815
  );
3816
+ if (conditionalsProperty) {
3817
+ conditionalsProperty.remove();
3818
+ console.log(
3819
+ ` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`
3820
+ );
3821
+ }
3822
+ if (isUnsupportedActionType(actionCandidates[0])) {
3823
+ actionsProperty.remove();
3824
+ console.log(
3825
+ ` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`
3826
+ );
3827
+ actionsArrayMigrated = true;
3828
+ } else {
3829
+ const firstActionText = actionCandidates[0].getText();
3830
+ workqueue.addPropertyAssignment({
3831
+ name: ACTION_PROPERTY_NAME2,
3832
+ initializer: firstActionText
3833
+ });
3834
+ actionsProperty.remove();
3835
+ console.log(
3836
+ ` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
3837
+ );
3838
+ actionsArrayMigrated = true;
3839
+ }
3765
3840
  }
3766
3841
  }
3767
3842
  }
3768
- actionsProperty.remove();
3769
- console.log(
3770
- ` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
3771
- );
3772
- return 1;
3773
- }
3774
- const actionCandidates = actionsInitializer.getElements().filter(
3775
- (element) => import_ts_morph17.Node.isObjectLiteralExpression(element)
3776
- );
3777
- if (actionCandidates.length === 0) {
3778
- actionsProperty.remove();
3779
- console.log(
3780
- ` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`
3781
- );
3782
- return 1;
3783
3843
  }
3784
- if (actionCandidates.length > 1) {
3785
- const droppedCount = actionCandidates.length - 1;
3786
- console.warn(
3787
- ` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
3788
- );
3789
- }
3790
- const conditionalsProperty = actionCandidates[0].getProperty(
3791
- CONDITIONALS_PROPERTY_NAME
3844
+ const fallback = ensureValidAction(workqueue, relPath);
3845
+ return {
3846
+ changed: actionsArrayMigrated || fallback.changed,
3847
+ usedReadFallback: fallback.usedReadFallback
3848
+ };
3849
+ }
3850
+ function ensureActionTypeImport(sourceFile) {
3851
+ const existingImport = sourceFile.getImportDeclaration(
3852
+ (decl) => decl.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE2
3792
3853
  );
3793
- if (conditionalsProperty) {
3794
- conditionalsProperty.remove();
3795
- console.log(
3796
- ` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`
3797
- );
3798
- }
3799
- if (isUnsupportedActionType(actionCandidates[0])) {
3800
- actionsProperty.remove();
3801
- console.log(
3802
- ` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`
3803
- );
3804
- return 1;
3854
+ if (existingImport) {
3855
+ const alreadyImported = existingImport.getNamedImports().some((ni) => ni.getName() === ACTION_TYPE_IMPORT_NAME);
3856
+ if (!alreadyImported) {
3857
+ existingImport.addNamedImport(ACTION_TYPE_IMPORT_NAME);
3858
+ }
3859
+ return;
3805
3860
  }
3806
- const firstActionText = actionCandidates[0].getText();
3807
- workqueue.addPropertyAssignment({
3808
- name: ACTION_PROPERTY_NAME2,
3809
- initializer: firstActionText
3861
+ sourceFile.addImportDeclaration({
3862
+ moduleSpecifier: TOOLKIT_EVENTS_MODULE2,
3863
+ namedImports: [ACTION_TYPE_IMPORT_NAME]
3810
3864
  });
3811
- actionsProperty.remove();
3812
- console.log(
3813
- ` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
3814
- );
3815
- return 1;
3816
3865
  }
3817
3866
  function processFile13(filePath, project) {
3818
3867
  const sourceFile = project.getSourceFile(filePath);
3819
3868
  if (!sourceFile) return 0;
3820
3869
  let migratedWorkqueues = 0;
3870
+ let needsActionTypeImport = false;
3821
3871
  const relPath = import_path18.default.relative(process.cwd(), filePath);
3822
3872
  const callExpressions = sourceFile.getDescendantsOfKind(
3823
3873
  import_ts_morph17.SyntaxKind.CallExpression
@@ -3833,9 +3883,14 @@ function processFile13(filePath, project) {
3833
3883
  if (!import_ts_morph17.Node.isArrayLiteralExpression(workqueuesArg)) continue;
3834
3884
  for (const element of workqueuesArg.getElements()) {
3835
3885
  if (!import_ts_morph17.Node.isObjectLiteralExpression(element)) continue;
3836
- migratedWorkqueues += migrateWorkqueueActions(element, relPath);
3886
+ const result = migrateWorkqueueActions(element, relPath);
3887
+ if (result.changed) migratedWorkqueues++;
3888
+ if (result.usedReadFallback) needsActionTypeImport = true;
3837
3889
  }
3838
3890
  }
3891
+ if (needsActionTypeImport) {
3892
+ ensureActionTypeImport(sourceFile);
3893
+ }
3839
3894
  return migratedWorkqueues;
3840
3895
  }
3841
3896
  async function main18() {
@@ -4170,7 +4225,7 @@ Saved ${handlerRelPath}.`);
4170
4225
  // src/migrations/v2.0/checkout-upstream-files.ts
4171
4226
  var import_child_process = require("child_process");
4172
4227
  var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
4173
- var UPSTREAM_BRANCH = "develop";
4228
+ var UPSTREAM_BRANCH = "release-v2.0.0";
4174
4229
  var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
4175
4230
  var FILES_TO_CHECKOUT = [
4176
4231
  "src/analytics/analytics.ts",
@@ -4720,9 +4775,13 @@ function gitShowBytes(ref, path23) {
4720
4775
  return null;
4721
4776
  }
4722
4777
  }
4723
- async function main25() {
4778
+ async function main25({
4779
+ subdirs = []
4780
+ } = {}) {
4781
+ const pathspecs = subdirs.length > 0 ? subdirs.map((s) => `${INFRASTRUCTURE_DIR}/${s}/`) : [`${INFRASTRUCTURE_DIR}/`];
4782
+ const scopeLabel = pathspecs.map((p) => `'${p}'`).join(", ");
4724
4783
  console.log(
4725
- `Merging '${INFRASTRUCTURE_DIR}/' from ${UPSTREAM_URL}@${UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...
4784
+ `Merging ${scopeLabel} from ${UPSTREAM_URL}@${UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...
4726
4785
  `
4727
4786
  );
4728
4787
  assertIsGitRepo();
@@ -4737,20 +4796,12 @@ async function main25() {
4737
4796
  const ref = `${TEMP_REMOTE2}/${UPSTREAM_BRANCH}`;
4738
4797
  const baseRef = `${TEMP_REMOTE2}/${BASE_BRANCH}`;
4739
4798
  const upstreamFiles = runGit(
4740
- [
4741
- "ls-tree",
4742
- "-r",
4743
- "--name-only",
4744
- "-z",
4745
- ref,
4746
- "--",
4747
- `${INFRASTRUCTURE_DIR}/`
4748
- ],
4799
+ ["ls-tree", "-r", "--name-only", "-z", ref, "--", ...pathspecs],
4749
4800
  { silent: true }
4750
4801
  ).split("\0").filter(Boolean);
4751
4802
  if (upstreamFiles.length === 0) {
4752
4803
  console.log(
4753
- ` No files found under '${INFRASTRUCTURE_DIR}/' on ${ref}. Nothing to merge.`
4804
+ ` No files found under ${scopeLabel} on ${ref}. Nothing to merge.`
4754
4805
  );
4755
4806
  return;
4756
4807
  }
@@ -4825,7 +4876,9 @@ async function main25() {
4825
4876
  var import_fs6 = require("fs");
4826
4877
  var import_path25 = require("path");
4827
4878
  var INFRASTRUCTURE_DIR2 = "infrastructure";
4828
- async function main26() {
4879
+ async function main26({
4880
+ keep = []
4881
+ } = {}) {
4829
4882
  const fullPath = (0, import_path25.join)(process.cwd(), INFRASTRUCTURE_DIR2);
4830
4883
  if (!(0, import_fs6.existsSync)(fullPath)) {
4831
4884
  console.log(
@@ -4833,24 +4886,64 @@ async function main26() {
4833
4886
  );
4834
4887
  return;
4835
4888
  }
4836
- console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
4837
- `);
4838
4889
  assertIsGitRepo();
4839
- runGit(["rm", "-rf", "--ignore-unmatch", "--", `${INFRASTRUCTURE_DIR2}/`], {
4840
- silent: true
4841
- });
4842
- console.log(` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR2}/'.`);
4843
- if ((0, import_fs6.existsSync)(fullPath)) {
4844
- (0, import_fs6.rmSync)(fullPath, { recursive: true, force: true });
4845
- console.log(` Removed remaining untracked files under '${INFRASTRUCTURE_DIR2}/'.`);
4890
+ if (keep.length === 0) {
4891
+ console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
4892
+ `);
4893
+ runGit(["rm", "-rf", "--ignore-unmatch", "--", `${INFRASTRUCTURE_DIR2}/`], {
4894
+ silent: true
4895
+ });
4896
+ console.log(
4897
+ ` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR2}/'.`
4898
+ );
4899
+ if ((0, import_fs6.existsSync)(fullPath)) {
4900
+ (0, import_fs6.rmSync)(fullPath, { recursive: true, force: true });
4901
+ console.log(
4902
+ ` Removed remaining untracked files under '${INFRASTRUCTURE_DIR2}/'.`
4903
+ );
4904
+ }
4905
+ console.log(
4906
+ `
4907
+ Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
4908
+ );
4909
+ return;
4910
+ }
4911
+ const keepSet = new Set(keep);
4912
+ console.log(
4913
+ `Deleting contents of '${INFRASTRUCTURE_DIR2}/' except: ${[...keepSet].map((name) => `'${name}'`).join(", ")}
4914
+ `
4915
+ );
4916
+ const topLevelEntries = (0, import_fs6.readdirSync)(fullPath, { withFileTypes: true });
4917
+ let deleted = 0;
4918
+ for (const entry of topLevelEntries) {
4919
+ if (keepSet.has(entry.name)) {
4920
+ console.log(` Keeping '${INFRASTRUCTURE_DIR2}/${entry.name}'.`);
4921
+ continue;
4922
+ }
4923
+ const relPath = `${INFRASTRUCTURE_DIR2}/${entry.name}${entry.isDirectory() ? "/" : ""}`;
4924
+ runGit(["rm", "-rf", "--ignore-unmatch", "--", relPath], { silent: true });
4925
+ const fullEntryPath = (0, import_path25.join)(fullPath, entry.name);
4926
+ if ((0, import_fs6.existsSync)(fullEntryPath)) {
4927
+ (0, import_fs6.rmSync)(fullEntryPath, { recursive: true, force: true });
4928
+ }
4929
+ console.log(` Deleted '${relPath}'.`);
4930
+ deleted++;
4931
+ }
4932
+ const presentNames = new Set(topLevelEntries.map((e) => e.name));
4933
+ const missingKeeps = [...keepSet].filter((name) => !presentNames.has(name));
4934
+ if (missingKeeps.length > 0) {
4935
+ console.warn(
4936
+ ` [warn] Requested to keep ${missingKeeps.map((n) => `'${n}'`).join(", ")} but they don't exist under '${INFRASTRUCTURE_DIR2}/'.`
4937
+ );
4846
4938
  }
4847
4939
  console.log(
4848
4940
  `
4849
- Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
4941
+ Done. Deleted ${deleted} top-level entr${deleted === 1 ? "y" : "ies"}. Review the staged deletions with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
4850
4942
  );
4851
4943
  }
4852
4944
 
4853
4945
  // src/migrations/v2.0/index.ts
4946
+ var NON_SWARM_INFRA_SUBDIRS = ["postgres", "metabase"];
4854
4947
  async function runUpgrade(dockerSwarm) {
4855
4948
  await main18();
4856
4949
  await main();
@@ -4879,6 +4972,7 @@ async function runUpgrade(dockerSwarm) {
4879
4972
  if (dockerSwarm) {
4880
4973
  await main25();
4881
4974
  } else {
4882
- await main26();
4975
+ await main26({ keep: NON_SWARM_INFRA_SUBDIRS });
4976
+ await main25({ subdirs: NON_SWARM_INFRA_SUBDIRS });
4883
4977
  }
4884
4978
  }
@@ -1,3 +1,13 @@
1
- declare function main(): Promise<void>;
1
+ interface MergeInfrastructureOptions {
2
+ /**
3
+ * Top-level subdirectories of `infrastructure/` to scope the merge to.
4
+ * When omitted or empty, the entire `infrastructure/` tree is merged
5
+ * (legacy behavior). Each name is relative to `infrastructure/` —
6
+ * e.g. `['postgres', 'metabase']` merges only
7
+ * `infrastructure/postgres/` and `infrastructure/metabase/`.
8
+ */
9
+ subdirs?: string[];
10
+ }
11
+ declare function main({ subdirs }?: MergeInfrastructureOptions): Promise<void>;
2
12
  export { main };
3
13
  //# sourceMappingURL=merge-infrastructure-directory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"merge-infrastructure-directory.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/merge-infrastructure-directory.ts"],"names":[],"mappings":"AAsHA,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAkInC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
1
+ {"version":3,"file":"merge-infrastructure-directory.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/merge-infrastructure-directory.ts"],"names":[],"mappings":"AAsHA,UAAU,0BAA0B;IAClC;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;CACnB;AAID,iBAAe,IAAI,CAAC,EAClB,OAAY,EACb,GAAE,0BAA+B,GAAG,OAAO,CAAC,IAAI,CAAC,CAoIjD;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -22,7 +22,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
22
22
  exports.main = main;
23
23
  /**
24
24
  * Codemod: Merge upstream changes into the local `infrastructure/` directory
25
- * from opencrvs/opencrvs-countryconfig.
25
+ * (or selected subdirectories of it) from opencrvs/opencrvs-countryconfig.
26
26
  *
27
27
  * Usage:
28
28
  * ts-node -r tsconfig-paths/register src/migrations/v2.0/merge-infrastructure-directory.ts
@@ -33,8 +33,10 @@ exports.main = main;
33
33
  * - the upstream "theirs" branch (v2.0) → `UPSTREAM_BRANCH`
34
34
  * - the synthetic merge-base branch (latest 1.9 release line)
35
35
  * → `BASE_BRANCH`
36
- * 2. For every file under `infrastructure/` on upstream "theirs", performs
37
- * a file-scoped 3-way merge:
36
+ * 2. For every file under `infrastructure/` on upstream "theirs" (or, when
37
+ * `subdirs` is provided, only files under
38
+ * `infrastructure/<subdir>/` for each requested subdir), performs a
39
+ * file-scoped 3-way merge:
38
40
  * - new file on upstream → checked out and staged
39
41
  * - existing file → 3-way merged in place via `git merge-file`,
40
42
  * using the BASE_BRANCH version of the file
@@ -116,8 +118,14 @@ function gitShowBytes(ref, path) {
116
118
  }
117
119
  // ─── Entry point ─────────────────────────────────────────────────────────────
118
120
  function main() {
119
- return __awaiter(this, void 0, void 0, function* () {
120
- console.log(`Merging '${INFRASTRUCTURE_DIR}/' from ${checkout_upstream_files_1.UPSTREAM_URL}@${checkout_upstream_files_1.UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...\n`);
121
+ return __awaiter(this, arguments, void 0, function* ({ subdirs = [] } = {}) {
122
+ // Build the pathspec list passed to `git ls-tree`. Trailing slashes make
123
+ // git treat them as tree paths (recurse into them).
124
+ const pathspecs = subdirs.length > 0
125
+ ? subdirs.map((s) => `${INFRASTRUCTURE_DIR}/${s}/`)
126
+ : [`${INFRASTRUCTURE_DIR}/`];
127
+ const scopeLabel = pathspecs.map((p) => `'${p}'`).join(', ');
128
+ console.log(`Merging ${scopeLabel} from ${checkout_upstream_files_1.UPSTREAM_URL}@${checkout_upstream_files_1.UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...\n`);
121
129
  (0, checkout_upstream_files_1.assertIsGitRepo)();
122
130
  // Best-effort cleanup of a stale temp remote from a previous aborted run.
123
131
  (0, checkout_upstream_files_1.tryGit)(['remote', 'remove', TEMP_REMOTE]);
@@ -131,20 +139,13 @@ function main() {
131
139
  const ref = `${TEMP_REMOTE}/${checkout_upstream_files_1.UPSTREAM_BRANCH}`;
132
140
  const baseRef = `${TEMP_REMOTE}/${BASE_BRANCH}`;
133
141
  // -z gives NUL-separated paths so filenames with spaces or newlines
134
- // survive the round-trip.
135
- const upstreamFiles = (0, checkout_upstream_files_1.runGit)([
136
- 'ls-tree',
137
- '-r',
138
- '--name-only',
139
- '-z',
140
- ref,
141
- '--',
142
- `${INFRASTRUCTURE_DIR}/`
143
- ], { silent: true })
142
+ // survive the round-trip. Multiple pathspecs after `--` are unioned
143
+ // by git, which scopes the listing to the requested subdirectories.
144
+ const upstreamFiles = (0, checkout_upstream_files_1.runGit)(['ls-tree', '-r', '--name-only', '-z', ref, '--', ...pathspecs], { silent: true })
144
145
  .split('\0')
145
146
  .filter(Boolean);
146
147
  if (upstreamFiles.length === 0) {
147
- console.log(` No files found under '${INFRASTRUCTURE_DIR}/' on ${ref}. Nothing to merge.`);
148
+ console.log(` No files found under ${scopeLabel} on ${ref}. Nothing to merge.`);
148
149
  return;
149
150
  }
150
151
  const tmpDir = (0, fs_1.mkdtempSync)((0, path_1.join)((0, os_1.tmpdir)(), 'opencrvs-merge-infra-'));