@opencrvs/toolkit 2.0.0-rc.e6ee324 → 2.0.0-rc.e94ba6c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -3674,6 +3674,10 @@ var ACTION_PROPERTY_NAME2 = "action";
3674
3674
  var CONDITIONALS_PROPERTY_NAME = "conditionals";
3675
3675
  var TYPE_PROPERTY_NAME7 = "type";
3676
3676
  var SLUG_PROPERTY_NAME = "slug";
3677
+ var READ_ACTION_TYPE = "READ";
3678
+ var ACTION_TYPE_IMPORT_NAME = "ActionType";
3679
+ var TOOLKIT_EVENTS_MODULE2 = "@opencrvs/toolkit/events";
3680
+ var READ_ACTION_FALLBACK_INITIALIZER = `{ type: ${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE} }`;
3677
3681
  var SUPPORTED_WORKQUEUE_ACTION_TYPES = /* @__PURE__ */ new Set([
3678
3682
  "READ",
3679
3683
  "DELETE",
@@ -3721,91 +3725,137 @@ function isUnsupportedActionType(action) {
3721
3725
  }
3722
3726
  return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
3723
3727
  }
3724
- function migrateWorkqueueActions(workqueue, relPath) {
3725
- const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME5);
3726
- if (!actionsProperty || !import_ts_morph17.Node.isPropertyAssignment(actionsProperty)) {
3727
- return 0;
3728
- }
3729
- const actionsInitializer = actionsProperty.getInitializer();
3730
- if (!actionsInitializer || !import_ts_morph17.Node.isArrayLiteralExpression(actionsInitializer)) {
3731
- return 0;
3728
+ function ensureValidAction(workqueue, relPath) {
3729
+ const workqueueLabel = getWorkqueueLabel(workqueue);
3730
+ const actionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
3731
+ if (actionProperty && import_ts_morph17.Node.isPropertyAssignment(actionProperty)) {
3732
+ const initializer = actionProperty.getInitializer();
3733
+ if (initializer && import_ts_morph17.Node.isObjectLiteralExpression(initializer)) {
3734
+ if (!isUnsupportedActionType(initializer)) {
3735
+ return { changed: false, usedReadFallback: false };
3736
+ }
3737
+ actionProperty.set({
3738
+ name: ACTION_PROPERTY_NAME2,
3739
+ initializer: READ_ACTION_FALLBACK_INITIALIZER
3740
+ });
3741
+ console.log(
3742
+ ` [${relPath}] Replaced unsupported 'action' type with '${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE}' on workqueue '${workqueueLabel}'`
3743
+ );
3744
+ return { changed: true, usedReadFallback: true };
3745
+ }
3732
3746
  }
3747
+ workqueue.addPropertyAssignment({
3748
+ name: ACTION_PROPERTY_NAME2,
3749
+ initializer: READ_ACTION_FALLBACK_INITIALIZER
3750
+ });
3751
+ console.log(
3752
+ ` [${relPath}] Added default 'action: ${READ_ACTION_FALLBACK_INITIALIZER}' to workqueue '${workqueueLabel}'`
3753
+ );
3754
+ return { changed: true, usedReadFallback: true };
3755
+ }
3756
+ function migrateWorkqueueActions(workqueue, relPath) {
3733
3757
  const workqueueLabel = getWorkqueueLabel(workqueue);
3734
- const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
3735
- if (existingActionProperty) {
3736
- if (import_ts_morph17.Node.isPropertyAssignment(existingActionProperty)) {
3737
- const existingActionInitializer = existingActionProperty.getInitializer();
3738
- if (existingActionInitializer && import_ts_morph17.Node.isObjectLiteralExpression(existingActionInitializer)) {
3739
- const conditionalsProperty2 = existingActionInitializer.getProperty(
3740
- CONDITIONALS_PROPERTY_NAME
3758
+ const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME5);
3759
+ let actionsArrayMigrated = false;
3760
+ if (actionsProperty && import_ts_morph17.Node.isPropertyAssignment(actionsProperty)) {
3761
+ const actionsInitializer = actionsProperty.getInitializer();
3762
+ if (actionsInitializer && import_ts_morph17.Node.isArrayLiteralExpression(actionsInitializer)) {
3763
+ const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
3764
+ if (existingActionProperty) {
3765
+ if (import_ts_morph17.Node.isPropertyAssignment(existingActionProperty)) {
3766
+ const existingActionInitializer = existingActionProperty.getInitializer();
3767
+ if (existingActionInitializer && import_ts_morph17.Node.isObjectLiteralExpression(existingActionInitializer)) {
3768
+ const conditionalsProperty = existingActionInitializer.getProperty(
3769
+ CONDITIONALS_PROPERTY_NAME
3770
+ );
3771
+ if (conditionalsProperty) {
3772
+ conditionalsProperty.remove();
3773
+ console.log(
3774
+ ` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`
3775
+ );
3776
+ }
3777
+ }
3778
+ }
3779
+ actionsProperty.remove();
3780
+ console.log(
3781
+ ` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
3782
+ );
3783
+ actionsArrayMigrated = true;
3784
+ } else {
3785
+ const actionCandidates = actionsInitializer.getElements().filter(
3786
+ (element) => import_ts_morph17.Node.isObjectLiteralExpression(element)
3741
3787
  );
3742
- if (conditionalsProperty2) {
3743
- conditionalsProperty2.remove();
3788
+ if (actionCandidates.length === 0) {
3789
+ actionsProperty.remove();
3744
3790
  console.log(
3745
- ` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`
3791
+ ` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`
3746
3792
  );
3747
- }
3748
- if (isUnsupportedActionType(existingActionInitializer)) {
3749
- existingActionProperty.remove();
3750
- console.log(
3751
- ` [${relPath}] Removed unsupported 'action' type on workqueue '${workqueueLabel}'`
3793
+ actionsArrayMigrated = true;
3794
+ } else {
3795
+ if (actionCandidates.length > 1) {
3796
+ const droppedCount = actionCandidates.length - 1;
3797
+ console.warn(
3798
+ ` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
3799
+ );
3800
+ }
3801
+ const conditionalsProperty = actionCandidates[0].getProperty(
3802
+ CONDITIONALS_PROPERTY_NAME
3752
3803
  );
3804
+ if (conditionalsProperty) {
3805
+ conditionalsProperty.remove();
3806
+ console.log(
3807
+ ` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`
3808
+ );
3809
+ }
3810
+ if (isUnsupportedActionType(actionCandidates[0])) {
3811
+ actionsProperty.remove();
3812
+ console.log(
3813
+ ` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`
3814
+ );
3815
+ actionsArrayMigrated = true;
3816
+ } else {
3817
+ const firstActionText = actionCandidates[0].getText();
3818
+ workqueue.addPropertyAssignment({
3819
+ name: ACTION_PROPERTY_NAME2,
3820
+ initializer: firstActionText
3821
+ });
3822
+ actionsProperty.remove();
3823
+ console.log(
3824
+ ` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
3825
+ );
3826
+ actionsArrayMigrated = true;
3827
+ }
3753
3828
  }
3754
3829
  }
3755
3830
  }
3756
- actionsProperty.remove();
3757
- console.log(
3758
- ` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
3759
- );
3760
- return 1;
3761
- }
3762
- const actionCandidates = actionsInitializer.getElements().filter(
3763
- (element) => import_ts_morph17.Node.isObjectLiteralExpression(element)
3764
- );
3765
- if (actionCandidates.length === 0) {
3766
- actionsProperty.remove();
3767
- console.log(
3768
- ` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`
3769
- );
3770
- return 1;
3771
3831
  }
3772
- if (actionCandidates.length > 1) {
3773
- const droppedCount = actionCandidates.length - 1;
3774
- console.warn(
3775
- ` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
3776
- );
3777
- }
3778
- const conditionalsProperty = actionCandidates[0].getProperty(
3779
- CONDITIONALS_PROPERTY_NAME
3832
+ const fallback = ensureValidAction(workqueue, relPath);
3833
+ return {
3834
+ changed: actionsArrayMigrated || fallback.changed,
3835
+ usedReadFallback: fallback.usedReadFallback
3836
+ };
3837
+ }
3838
+ function ensureActionTypeImport(sourceFile) {
3839
+ const existingImport = sourceFile.getImportDeclaration(
3840
+ (decl) => decl.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE2
3780
3841
  );
3781
- if (conditionalsProperty) {
3782
- conditionalsProperty.remove();
3783
- console.log(
3784
- ` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`
3785
- );
3786
- }
3787
- if (isUnsupportedActionType(actionCandidates[0])) {
3788
- actionsProperty.remove();
3789
- console.log(
3790
- ` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`
3791
- );
3792
- return 1;
3842
+ if (existingImport) {
3843
+ const alreadyImported = existingImport.getNamedImports().some((ni) => ni.getName() === ACTION_TYPE_IMPORT_NAME);
3844
+ if (!alreadyImported) {
3845
+ existingImport.addNamedImport(ACTION_TYPE_IMPORT_NAME);
3846
+ }
3847
+ return;
3793
3848
  }
3794
- const firstActionText = actionCandidates[0].getText();
3795
- workqueue.addPropertyAssignment({
3796
- name: ACTION_PROPERTY_NAME2,
3797
- initializer: firstActionText
3849
+ sourceFile.addImportDeclaration({
3850
+ moduleSpecifier: TOOLKIT_EVENTS_MODULE2,
3851
+ namedImports: [ACTION_TYPE_IMPORT_NAME]
3798
3852
  });
3799
- actionsProperty.remove();
3800
- console.log(
3801
- ` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
3802
- );
3803
- return 1;
3804
3853
  }
3805
3854
  function processFile13(filePath, project) {
3806
3855
  const sourceFile = project.getSourceFile(filePath);
3807
3856
  if (!sourceFile) return 0;
3808
3857
  let migratedWorkqueues = 0;
3858
+ let needsActionTypeImport = false;
3809
3859
  const relPath = import_path18.default.relative(process.cwd(), filePath);
3810
3860
  const callExpressions = sourceFile.getDescendantsOfKind(
3811
3861
  import_ts_morph17.SyntaxKind.CallExpression
@@ -3821,9 +3871,14 @@ function processFile13(filePath, project) {
3821
3871
  if (!import_ts_morph17.Node.isArrayLiteralExpression(workqueuesArg)) continue;
3822
3872
  for (const element of workqueuesArg.getElements()) {
3823
3873
  if (!import_ts_morph17.Node.isObjectLiteralExpression(element)) continue;
3824
- migratedWorkqueues += migrateWorkqueueActions(element, relPath);
3874
+ const result = migrateWorkqueueActions(element, relPath);
3875
+ if (result.changed) migratedWorkqueues++;
3876
+ if (result.usedReadFallback) needsActionTypeImport = true;
3825
3877
  }
3826
3878
  }
3879
+ if (needsActionTypeImport) {
3880
+ ensureActionTypeImport(sourceFile);
3881
+ }
3827
3882
  return migratedWorkqueues;
3828
3883
  }
3829
3884
  async function main18() {
@@ -4158,7 +4213,7 @@ Saved ${handlerRelPath}.`);
4158
4213
  // src/migrations/v2.0/checkout-upstream-files.ts
4159
4214
  var import_child_process = require("child_process");
4160
4215
  var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
4161
- var UPSTREAM_BRANCH = "develop";
4216
+ var UPSTREAM_BRANCH = "release-v2.0.0";
4162
4217
  var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
4163
4218
  var FILES_TO_CHECKOUT = [
4164
4219
  "src/analytics/analytics.ts",
@@ -4708,9 +4763,13 @@ function gitShowBytes(ref, path23) {
4708
4763
  return null;
4709
4764
  }
4710
4765
  }
4711
- async function main25() {
4766
+ async function main25({
4767
+ subdirs = []
4768
+ } = {}) {
4769
+ const pathspecs = subdirs.length > 0 ? subdirs.map((s) => `${INFRASTRUCTURE_DIR}/${s}/`) : [`${INFRASTRUCTURE_DIR}/`];
4770
+ const scopeLabel = pathspecs.map((p) => `'${p}'`).join(", ");
4712
4771
  console.log(
4713
- `Merging '${INFRASTRUCTURE_DIR}/' from ${UPSTREAM_URL}@${UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...
4772
+ `Merging ${scopeLabel} from ${UPSTREAM_URL}@${UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...
4714
4773
  `
4715
4774
  );
4716
4775
  assertIsGitRepo();
@@ -4725,20 +4784,12 @@ async function main25() {
4725
4784
  const ref = `${TEMP_REMOTE2}/${UPSTREAM_BRANCH}`;
4726
4785
  const baseRef = `${TEMP_REMOTE2}/${BASE_BRANCH}`;
4727
4786
  const upstreamFiles = runGit(
4728
- [
4729
- "ls-tree",
4730
- "-r",
4731
- "--name-only",
4732
- "-z",
4733
- ref,
4734
- "--",
4735
- `${INFRASTRUCTURE_DIR}/`
4736
- ],
4787
+ ["ls-tree", "-r", "--name-only", "-z", ref, "--", ...pathspecs],
4737
4788
  { silent: true }
4738
4789
  ).split("\0").filter(Boolean);
4739
4790
  if (upstreamFiles.length === 0) {
4740
4791
  console.log(
4741
- ` No files found under '${INFRASTRUCTURE_DIR}/' on ${ref}. Nothing to merge.`
4792
+ ` No files found under ${scopeLabel} on ${ref}. Nothing to merge.`
4742
4793
  );
4743
4794
  return;
4744
4795
  }
@@ -4813,7 +4864,9 @@ async function main25() {
4813
4864
  var import_fs6 = require("fs");
4814
4865
  var import_path25 = require("path");
4815
4866
  var INFRASTRUCTURE_DIR2 = "infrastructure";
4816
- async function main26() {
4867
+ async function main26({
4868
+ keep = []
4869
+ } = {}) {
4817
4870
  const fullPath = (0, import_path25.join)(process.cwd(), INFRASTRUCTURE_DIR2);
4818
4871
  if (!(0, import_fs6.existsSync)(fullPath)) {
4819
4872
  console.log(
@@ -4821,24 +4874,64 @@ async function main26() {
4821
4874
  );
4822
4875
  return;
4823
4876
  }
4824
- console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
4825
- `);
4826
4877
  assertIsGitRepo();
4827
- runGit(["rm", "-rf", "--ignore-unmatch", "--", `${INFRASTRUCTURE_DIR2}/`], {
4828
- silent: true
4829
- });
4830
- console.log(` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR2}/'.`);
4831
- if ((0, import_fs6.existsSync)(fullPath)) {
4832
- (0, import_fs6.rmSync)(fullPath, { recursive: true, force: true });
4833
- console.log(` Removed remaining untracked files under '${INFRASTRUCTURE_DIR2}/'.`);
4878
+ if (keep.length === 0) {
4879
+ console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
4880
+ `);
4881
+ runGit(["rm", "-rf", "--ignore-unmatch", "--", `${INFRASTRUCTURE_DIR2}/`], {
4882
+ silent: true
4883
+ });
4884
+ console.log(
4885
+ ` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR2}/'.`
4886
+ );
4887
+ if ((0, import_fs6.existsSync)(fullPath)) {
4888
+ (0, import_fs6.rmSync)(fullPath, { recursive: true, force: true });
4889
+ console.log(
4890
+ ` Removed remaining untracked files under '${INFRASTRUCTURE_DIR2}/'.`
4891
+ );
4892
+ }
4893
+ console.log(
4894
+ `
4895
+ Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
4896
+ );
4897
+ return;
4898
+ }
4899
+ const keepSet = new Set(keep);
4900
+ console.log(
4901
+ `Deleting contents of '${INFRASTRUCTURE_DIR2}/' except: ${[...keepSet].map((name) => `'${name}'`).join(", ")}
4902
+ `
4903
+ );
4904
+ const topLevelEntries = (0, import_fs6.readdirSync)(fullPath, { withFileTypes: true });
4905
+ let deleted = 0;
4906
+ for (const entry of topLevelEntries) {
4907
+ if (keepSet.has(entry.name)) {
4908
+ console.log(` Keeping '${INFRASTRUCTURE_DIR2}/${entry.name}'.`);
4909
+ continue;
4910
+ }
4911
+ const relPath = `${INFRASTRUCTURE_DIR2}/${entry.name}${entry.isDirectory() ? "/" : ""}`;
4912
+ runGit(["rm", "-rf", "--ignore-unmatch", "--", relPath], { silent: true });
4913
+ const fullEntryPath = (0, import_path25.join)(fullPath, entry.name);
4914
+ if ((0, import_fs6.existsSync)(fullEntryPath)) {
4915
+ (0, import_fs6.rmSync)(fullEntryPath, { recursive: true, force: true });
4916
+ }
4917
+ console.log(` Deleted '${relPath}'.`);
4918
+ deleted++;
4919
+ }
4920
+ const presentNames = new Set(topLevelEntries.map((e) => e.name));
4921
+ const missingKeeps = [...keepSet].filter((name) => !presentNames.has(name));
4922
+ if (missingKeeps.length > 0) {
4923
+ console.warn(
4924
+ ` [warn] Requested to keep ${missingKeeps.map((n) => `'${n}'`).join(", ")} but they don't exist under '${INFRASTRUCTURE_DIR2}/'.`
4925
+ );
4834
4926
  }
4835
4927
  console.log(
4836
4928
  `
4837
- Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
4929
+ Done. Deleted ${deleted} top-level entr${deleted === 1 ? "y" : "ies"}. Review the staged deletions with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
4838
4930
  );
4839
4931
  }
4840
4932
 
4841
4933
  // src/migrations/v2.0/index.ts
4934
+ var NON_SWARM_INFRA_SUBDIRS = ["postgres", "metabase"];
4842
4935
  async function runUpgrade(dockerSwarm) {
4843
4936
  await main18();
4844
4937
  await main();
@@ -4867,7 +4960,8 @@ async function runUpgrade(dockerSwarm) {
4867
4960
  if (dockerSwarm) {
4868
4961
  await main25();
4869
4962
  } else {
4870
- await main26();
4963
+ await main26({ keep: NON_SWARM_INFRA_SUBDIRS });
4964
+ await main25({ subdirs: NON_SWARM_INFRA_SUBDIRS });
4871
4965
  }
4872
4966
  }
4873
4967
 
@@ -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-'));
@@ -1 +1 @@
1
- {"version":3,"file":"migrate-workqueue-configs.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/migrate-workqueue-configs.ts"],"names":[],"mappings":"AA+OA,iBAAe,IAAI,kBAqDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
1
+ {"version":3,"file":"migrate-workqueue-configs.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/migrate-workqueue-configs.ts"],"names":[],"mappings":"AAgVA,iBAAe,IAAI,kBAqDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -39,6 +39,10 @@ exports.main = main;
39
39
  * - `actions: [{...}, {...}, ...]` -> keeps first as `action`, warns about dropped extras
40
40
  * - If `action` already exists, removes deprecated `actions` and keeps `action`
41
41
  * - Removes unsupported `action.type` values (`DEFAULT`, `VALIDATE`, etc.)
42
+ * - Ensures every workqueue ends up with a valid `action`. When none is
43
+ * present (or the existing one is unsupported), falls back to
44
+ * `action: { type: ActionType.READ }` and ensures `ActionType` is imported
45
+ * from `@opencrvs/toolkit/events` in the file.
42
46
  * - Saves modified files in-place
43
47
  */
44
48
  const ts_morph_1 = require("ts-morph");
@@ -49,6 +53,10 @@ const ACTION_PROPERTY_NAME = 'action';
49
53
  const CONDITIONALS_PROPERTY_NAME = 'conditionals';
50
54
  const TYPE_PROPERTY_NAME = 'type';
51
55
  const SLUG_PROPERTY_NAME = 'slug';
56
+ const READ_ACTION_TYPE = 'READ';
57
+ const ACTION_TYPE_IMPORT_NAME = 'ActionType';
58
+ const TOOLKIT_EVENTS_MODULE = '@opencrvs/toolkit/events';
59
+ const READ_ACTION_FALLBACK_INITIALIZER = `{ type: ${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE} }`;
52
60
  const SUPPORTED_WORKQUEUE_ACTION_TYPES = new Set([
53
61
  'READ',
54
62
  'DELETE',
@@ -96,80 +104,146 @@ function isUnsupportedActionType(action) {
96
104
  }
97
105
  return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
98
106
  }
99
- function migrateWorkqueueActions(workqueue, relPath) {
100
- const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME);
101
- if (!actionsProperty || !ts_morph_1.Node.isPropertyAssignment(actionsProperty)) {
102
- return 0;
103
- }
104
- const actionsInitializer = actionsProperty.getInitializer();
105
- if (!actionsInitializer || !ts_morph_1.Node.isArrayLiteralExpression(actionsInitializer)) {
106
- return 0;
107
+ /**
108
+ * Ensures the workqueue has a valid singular `action` property. When the
109
+ * existing `action` is missing or has an unsupported type, replaces it with
110
+ * `action: { type: ActionType.READ }`.
111
+ *
112
+ * Returns whether anything was changed and whether the READ fallback was
113
+ * applied (so the caller can ensure `ActionType` is imported in the file).
114
+ */
115
+ function ensureValidAction(workqueue, relPath) {
116
+ const workqueueLabel = getWorkqueueLabel(workqueue);
117
+ const actionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME);
118
+ if (actionProperty && ts_morph_1.Node.isPropertyAssignment(actionProperty)) {
119
+ const initializer = actionProperty.getInitializer();
120
+ if (initializer && ts_morph_1.Node.isObjectLiteralExpression(initializer)) {
121
+ if (!isUnsupportedActionType(initializer)) {
122
+ return { changed: false, usedReadFallback: false };
123
+ }
124
+ actionProperty.set({
125
+ name: ACTION_PROPERTY_NAME,
126
+ initializer: READ_ACTION_FALLBACK_INITIALIZER
127
+ });
128
+ // eslint-disable-next-line no-console
129
+ console.log(` [${relPath}] Replaced unsupported 'action' type with '${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE}' on workqueue '${workqueueLabel}'`);
130
+ return { changed: true, usedReadFallback: true };
131
+ }
107
132
  }
133
+ workqueue.addPropertyAssignment({
134
+ name: ACTION_PROPERTY_NAME,
135
+ initializer: READ_ACTION_FALLBACK_INITIALIZER
136
+ });
137
+ // eslint-disable-next-line no-console
138
+ console.log(` [${relPath}] Added default 'action: ${READ_ACTION_FALLBACK_INITIALIZER}' to workqueue '${workqueueLabel}'`);
139
+ return { changed: true, usedReadFallback: true };
140
+ }
141
+ function migrateWorkqueueActions(workqueue, relPath) {
108
142
  const workqueueLabel = getWorkqueueLabel(workqueue);
109
- const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME);
110
- if (existingActionProperty) {
111
- if (ts_morph_1.Node.isPropertyAssignment(existingActionProperty)) {
112
- const existingActionInitializer = existingActionProperty.getInitializer();
113
- if (existingActionInitializer && ts_morph_1.Node.isObjectLiteralExpression(existingActionInitializer)) {
114
- const conditionalsProperty = existingActionInitializer.getProperty(CONDITIONALS_PROPERTY_NAME);
115
- if (conditionalsProperty) {
116
- conditionalsProperty.remove();
117
- // eslint-disable-next-line no-console
118
- console.log(` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`);
143
+ const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME);
144
+ let actionsArrayMigrated = false;
145
+ if (actionsProperty && ts_morph_1.Node.isPropertyAssignment(actionsProperty)) {
146
+ const actionsInitializer = actionsProperty.getInitializer();
147
+ if (actionsInitializer &&
148
+ ts_morph_1.Node.isArrayLiteralExpression(actionsInitializer)) {
149
+ const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME);
150
+ if (existingActionProperty) {
151
+ if (ts_morph_1.Node.isPropertyAssignment(existingActionProperty)) {
152
+ const existingActionInitializer = existingActionProperty.getInitializer();
153
+ if (existingActionInitializer &&
154
+ ts_morph_1.Node.isObjectLiteralExpression(existingActionInitializer)) {
155
+ const conditionalsProperty = existingActionInitializer.getProperty(CONDITIONALS_PROPERTY_NAME);
156
+ if (conditionalsProperty) {
157
+ conditionalsProperty.remove();
158
+ // eslint-disable-next-line no-console
159
+ console.log(` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`);
160
+ }
161
+ }
119
162
  }
120
- if (isUnsupportedActionType(existingActionInitializer)) {
121
- existingActionProperty.remove();
163
+ actionsProperty.remove();
164
+ // eslint-disable-next-line no-console
165
+ console.log(` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`);
166
+ actionsArrayMigrated = true;
167
+ }
168
+ else {
169
+ const actionCandidates = actionsInitializer
170
+ .getElements()
171
+ .filter((element) => ts_morph_1.Node.isObjectLiteralExpression(element));
172
+ if (actionCandidates.length === 0) {
173
+ actionsProperty.remove();
122
174
  // eslint-disable-next-line no-console
123
- console.log(` [${relPath}] Removed unsupported 'action' type on workqueue '${workqueueLabel}'`);
175
+ console.log(` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`);
176
+ actionsArrayMigrated = true;
177
+ }
178
+ else {
179
+ if (actionCandidates.length > 1) {
180
+ const droppedCount = actionCandidates.length - 1;
181
+ // eslint-disable-next-line no-console
182
+ console.warn(` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`);
183
+ }
184
+ const conditionalsProperty = actionCandidates[0].getProperty(CONDITIONALS_PROPERTY_NAME);
185
+ if (conditionalsProperty) {
186
+ conditionalsProperty.remove();
187
+ // eslint-disable-next-line no-console
188
+ console.log(` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`);
189
+ }
190
+ if (isUnsupportedActionType(actionCandidates[0])) {
191
+ actionsProperty.remove();
192
+ // eslint-disable-next-line no-console
193
+ console.log(` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`);
194
+ actionsArrayMigrated = true;
195
+ }
196
+ else {
197
+ const firstActionText = actionCandidates[0].getText();
198
+ workqueue.addPropertyAssignment({
199
+ name: ACTION_PROPERTY_NAME,
200
+ initializer: firstActionText
201
+ });
202
+ actionsProperty.remove();
203
+ // eslint-disable-next-line no-console
204
+ console.log(` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`);
205
+ actionsArrayMigrated = true;
206
+ }
124
207
  }
125
208
  }
126
209
  }
127
- actionsProperty.remove();
128
- // eslint-disable-next-line no-console
129
- console.log(` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`);
130
- return 1;
131
- }
132
- const actionCandidates = actionsInitializer
133
- .getElements()
134
- .filter((element) => ts_morph_1.Node.isObjectLiteralExpression(element));
135
- if (actionCandidates.length === 0) {
136
- actionsProperty.remove();
137
- // eslint-disable-next-line no-console
138
- console.log(` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`);
139
- return 1;
140
- }
141
- if (actionCandidates.length > 1) {
142
- const droppedCount = actionCandidates.length - 1;
143
- // eslint-disable-next-line no-console
144
- console.warn(` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`);
145
- }
146
- const conditionalsProperty = actionCandidates[0].getProperty(CONDITIONALS_PROPERTY_NAME);
147
- if (conditionalsProperty) {
148
- conditionalsProperty.remove();
149
- // eslint-disable-next-line no-console
150
- console.log(` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`);
151
210
  }
152
- if (isUnsupportedActionType(actionCandidates[0])) {
153
- actionsProperty.remove();
154
- // eslint-disable-next-line no-console
155
- console.log(` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`);
156
- return 1;
211
+ // Always ensure the workqueue ends up with a valid `action`. This both
212
+ // covers workqueues that never had an `actions` array, and patches up
213
+ // workqueues whose existing/migrated action type is unsupported.
214
+ const fallback = ensureValidAction(workqueue, relPath);
215
+ return {
216
+ changed: actionsArrayMigrated || fallback.changed,
217
+ usedReadFallback: fallback.usedReadFallback
218
+ };
219
+ }
220
+ /**
221
+ * Ensures `import { ActionType } from '@opencrvs/toolkit/events'` exists in
222
+ * the source file, merging into any existing import declaration from the
223
+ * same module specifier.
224
+ */
225
+ function ensureActionTypeImport(sourceFile) {
226
+ const existingImport = sourceFile.getImportDeclaration((decl) => decl.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE);
227
+ if (existingImport) {
228
+ const alreadyImported = existingImport
229
+ .getNamedImports()
230
+ .some((ni) => ni.getName() === ACTION_TYPE_IMPORT_NAME);
231
+ if (!alreadyImported) {
232
+ existingImport.addNamedImport(ACTION_TYPE_IMPORT_NAME);
233
+ }
234
+ return;
157
235
  }
158
- const firstActionText = actionCandidates[0].getText();
159
- workqueue.addPropertyAssignment({
160
- name: ACTION_PROPERTY_NAME,
161
- initializer: firstActionText
236
+ sourceFile.addImportDeclaration({
237
+ moduleSpecifier: TOOLKIT_EVENTS_MODULE,
238
+ namedImports: [ACTION_TYPE_IMPORT_NAME]
162
239
  });
163
- actionsProperty.remove();
164
- // eslint-disable-next-line no-console
165
- console.log(` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`);
166
- return 1;
167
240
  }
168
241
  function processFile(filePath, project) {
169
242
  const sourceFile = project.getSourceFile(filePath);
170
243
  if (!sourceFile)
171
244
  return 0;
172
245
  let migratedWorkqueues = 0;
246
+ let needsActionTypeImport = false;
173
247
  const relPath = path_1.default.relative(process.cwd(), filePath);
174
248
  const callExpressions = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
175
249
  for (const call of callExpressions) {
@@ -187,9 +261,16 @@ function processFile(filePath, project) {
187
261
  for (const element of workqueuesArg.getElements()) {
188
262
  if (!ts_morph_1.Node.isObjectLiteralExpression(element))
189
263
  continue;
190
- migratedWorkqueues += migrateWorkqueueActions(element, relPath);
264
+ const result = migrateWorkqueueActions(element, relPath);
265
+ if (result.changed)
266
+ migratedWorkqueues++;
267
+ if (result.usedReadFallback)
268
+ needsActionTypeImport = true;
191
269
  }
192
270
  }
271
+ if (needsActionTypeImport) {
272
+ ensureActionTypeImport(sourceFile);
273
+ }
193
274
  return migratedWorkqueues;
194
275
  }
195
276
  function main() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/toolkit",
3
- "version": "2.0.0-rc.e6ee324",
3
+ "version": "2.0.0-rc.e94ba6c",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "bin": {