kintone-migrator 0.35.7 → 0.35.9

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/index.mjs CHANGED
@@ -1386,16 +1386,6 @@ function sanitizeForDisplay$1(s) {
1386
1386
  }
1387
1387
  //#endregion
1388
1388
  //#region src/core/domain/formSchema/valueObject.ts
1389
- const LookupRelatedApp = {
1390
- /**
1391
- * kintone returns `code: ""` for a related app without an app code, while a
1392
- * schema leaves `code` out for the same app. Both build a related app
1393
- * without `code`, so only a non-empty `code` is kept.
1394
- */
1395
- create: (app, code) => code === void 0 || code === "" ? { app } : {
1396
- app,
1397
- code
1398
- } };
1399
1389
  function hasInvalidFieldCodeChars(code) {
1400
1390
  if (hasControlChars(code)) return true;
1401
1391
  for (let i = 0; i < code.length; i++) {
@@ -1500,12 +1490,15 @@ function readKintoneQueryClause(value, fieldPath) {
1500
1490
  assertString(value, fieldPath);
1501
1491
  return value;
1502
1492
  }
1493
+ /** Reads `relatedApp` by its app ID; the returned `code` is dropped. */
1494
+ function fromKintoneRelatedApp(value, fieldPath) {
1495
+ assertRecord(value, fieldPath);
1496
+ assertString(value.app, `${fieldPath}.app`);
1497
+ return { app: value.app };
1498
+ }
1503
1499
  function fromKintoneLookup(value, fieldPath) {
1504
1500
  assertRecord(value, fieldPath);
1505
- assertRecord(value.relatedApp, `${fieldPath}.relatedApp`);
1506
- const { app, code } = value.relatedApp;
1507
- assertString(app, `${fieldPath}.relatedApp.app`);
1508
- if (code !== void 0) assertString(code, `${fieldPath}.relatedApp.code`);
1501
+ const relatedApp = fromKintoneRelatedApp(value.relatedApp, `${fieldPath}.relatedApp`);
1509
1502
  assertString(value.relatedKeyField, `${fieldPath}.relatedKeyField`);
1510
1503
  const fieldMappings = readKintoneLookupList(value.fieldMappings, `${fieldPath}.fieldMappings`).map((mapping, i) => {
1511
1504
  const mappingPath = `${fieldPath}.fieldMappings[${i}]`;
@@ -1520,7 +1513,7 @@ function fromKintoneLookup(value, fieldPath) {
1520
1513
  const lookupPickerFields = readKintoneLookupList(value.lookupPickerFields, `${fieldPath}.lookupPickerFields`);
1521
1514
  assertStringArray(lookupPickerFields, `${fieldPath}.lookupPickerFields`);
1522
1515
  return {
1523
- relatedApp: LookupRelatedApp.create(app, code),
1516
+ relatedApp,
1524
1517
  relatedKeyField: value.relatedKeyField,
1525
1518
  fieldMappings,
1526
1519
  lookupPickerFields,
@@ -1558,13 +1551,11 @@ function fromKintoneProperty(prop) {
1558
1551
  assertString(condition.relatedField, "REFERENCE_TABLE.referenceTable.condition.relatedField");
1559
1552
  assertStringArray(rt.displayFields, "REFERENCE_TABLE.referenceTable.displayFields");
1560
1553
  const displayFields = rt.displayFields.map((f) => FieldCode.create(f));
1561
- assertRecord(rt.relatedApp, "REFERENCE_TABLE.referenceTable.relatedApp");
1562
- assertString(rt.relatedApp.app, "REFERENCE_TABLE.referenceTable.relatedApp.app");
1563
1554
  return {
1564
1555
  ...base,
1565
1556
  type: "REFERENCE_TABLE",
1566
1557
  properties: { referenceTable: {
1567
- relatedApp: { app: rt.relatedApp.app },
1558
+ relatedApp: fromKintoneRelatedApp(rt.relatedApp, "REFERENCE_TABLE.referenceTable.relatedApp"),
1568
1559
  condition: {
1569
1560
  field: FieldCode.create(condition.field),
1570
1561
  relatedField: FieldCode.create(condition.relatedField)
@@ -2846,11 +2837,32 @@ function printDiffResult(result) {
2846
2837
  });
2847
2838
  p.note(lines.join("\n"), "Diff Details", { format: (v) => v });
2848
2839
  }
2840
+ const plainThreeWayKeyStyle = {
2841
+ bracket: (text) => text,
2842
+ key: (text) => text
2843
+ };
2844
+ /**
2845
+ * Frames a 3-way entry's key (its display form, see `ThreeWayDiffEntry.key`)
2846
+ * as it appears on the 3-way diff line. Pull prompts reuse it so a conflict is
2847
+ * named exactly as its diff line names it.
2848
+ */
2849
+ function frameThreeWayKey(key, style = plainThreeWayKeyStyle) {
2850
+ return `${style.bracket("[")}${style.key(key)}${style.bracket("]")}`;
2851
+ }
2849
2852
  function formatThreeWayEntry(entry) {
2850
2853
  switch (entry.kind) {
2851
- case "localOnly": return `${pc.green("L")} ${pc.dim("[")}${pc.green(entry.key)}${pc.dim("]")} ${entry.label}${pc.dim(":")} local change`;
2852
- case "remoteOnly": return `${pc.yellow("R")} ${pc.dim("[")}${pc.yellow(entry.key)}${pc.dim("]")} ${entry.label}${pc.dim(":")} remote drift`;
2853
- case "conflict": return `${pc.red("C")} ${pc.dim("[")}${pc.red(entry.key)}${pc.dim("]")} ${entry.label}${pc.dim(":")} conflict`;
2854
+ case "localOnly": return `${pc.green("L")} ${frameThreeWayKey(entry.key, {
2855
+ bracket: pc.dim,
2856
+ key: pc.green
2857
+ })} ${entry.label}${pc.dim(":")} local change`;
2858
+ case "remoteOnly": return `${pc.yellow("R")} ${frameThreeWayKey(entry.key, {
2859
+ bracket: pc.dim,
2860
+ key: pc.yellow
2861
+ })} ${entry.label}${pc.dim(":")} remote drift`;
2862
+ case "conflict": return `${pc.red("C")} ${frameThreeWayKey(entry.key, {
2863
+ bracket: pc.dim,
2864
+ key: pc.red
2865
+ })} ${entry.label}${pc.dim(":")} conflict`;
2854
2866
  }
2855
2867
  }
2856
2868
  function formatThreeWayExtra(extra) {
@@ -3567,41 +3579,42 @@ function resolveActionMerge(merge, resolution) {
3567
3579
  //#region src/core/application/threeWay/threeWayDiff.ts
3568
3580
  /**
3569
3581
  * Builds the three-way portion of a {@link ThreeWayDiffResult} from a
3570
- * record-keyed merge (view / report / action / plugin). The caller supplies a
3571
- * `label` extractor (e.g. the view's name) for display.
3582
+ * record-keyed merge (view / report / action / plugin / customization / field
3583
+ * permission / app permission / record permission). The caller supplies a
3584
+ * `label` extractor (e.g. the view's type) for display.
3572
3585
  */
3573
- function buildRecordThreeWayDiff(merge, label, extras = [], notes = []) {
3586
+ function buildRecordThreeWayDiff(merge, label, { describeKey = (key) => key, notes = [] } = {}) {
3574
3587
  const localChanges = [];
3575
3588
  const remoteDrift = [];
3576
3589
  const conflicts = [];
3577
3590
  for (const entry of merge.entries) switch (entry.change.kind) {
3578
3591
  case "localOnly":
3579
3592
  localChanges.push({
3580
- key: entry.key,
3593
+ key: describeKey(entry.key),
3581
3594
  label: label(entry),
3582
3595
  kind: "localOnly"
3583
3596
  });
3584
3597
  break;
3585
3598
  case "remoteOnly":
3586
3599
  remoteDrift.push({
3587
- key: entry.key,
3600
+ key: describeKey(entry.key),
3588
3601
  label: label(entry),
3589
3602
  kind: "remoteOnly"
3590
3603
  });
3591
3604
  break;
3592
3605
  case "conflict": conflicts.push({
3593
- key: entry.key,
3606
+ key: describeKey(entry.key),
3594
3607
  label: label(entry),
3595
3608
  kind: "conflict"
3596
3609
  });
3597
3610
  }
3598
- const isEmpty = localChanges.length === 0 && remoteDrift.length === 0 && conflicts.length === 0 && extras.length === 0;
3611
+ const isEmpty = localChanges.length === 0 && remoteDrift.length === 0 && conflicts.length === 0;
3599
3612
  return {
3600
3613
  mode: "three-way",
3601
3614
  localChanges,
3602
3615
  remoteDrift,
3603
3616
  conflicts,
3604
- extras,
3617
+ extras: [],
3605
3618
  ...notes.length > 0 ? { notes } : {},
3606
3619
  isEmpty
3607
3620
  };
@@ -3913,6 +3926,15 @@ async function applyPulledActionMerge({ container, input }) {
3913
3926
  //#endregion
3914
3927
  //#region src/cli/commands/pullCommandFactory.ts
3915
3928
  /**
3929
+ * Names a conflict as the 3-way diff line does ({@link frameThreeWayKey}), for
3930
+ * domains whose keys embed values quoted in display (see
3931
+ * `ThreeWayDiffEntry.key`): the display form carries its own quotes, so
3932
+ * wrapping it in more quotes would blur where it ends again.
3933
+ */
3934
+ function nameConflictAsDiffLine(describeKey) {
3935
+ return (key) => frameThreeWayKey(describeKey(key));
3936
+ }
3937
+ /**
3916
3938
  * Factory for `pull` commands.
3917
3939
  *
3918
3940
  * Absorbs the boilerplate shared by every config domain: the two-stage pull
@@ -3924,6 +3946,7 @@ async function applyPulledActionMerge({ container, input }) {
3924
3946
  * top-level pull dispatcher.
3925
3947
  */
3926
3948
  function createPullCommand(config) {
3949
+ const nameConflict = config.nameConflict ?? ((key) => `"${key}"`);
3927
3950
  const notSupportedAll = new ValidationError(ValidationErrorCode.InvalidInput, `${config.description} does not support --all yet. Use --app <name> or a single app.`);
3928
3951
  async function resolveConflicts(merge, options) {
3929
3952
  const resolution = /* @__PURE__ */ new Map();
@@ -3937,7 +3960,7 @@ function createPullCommand(config) {
3937
3960
  continue;
3938
3961
  }
3939
3962
  const selected = await p.select({
3940
- message: `Conflict on ${config.conflictNoun} "${conflict.key}". Keep which side?`,
3963
+ message: `Conflict on ${config.conflictNoun} ${nameConflict(conflict.key)}. Keep which side?`,
3941
3964
  options: [{
3942
3965
  value: "local",
3943
3966
  label: "local (ours)"
@@ -6303,6 +6326,10 @@ function optionalLookupList(code, key, value) {
6303
6326
  if (list === void 0) throw invalidLookup(code, `must have a "${key}" array`);
6304
6327
  return list;
6305
6328
  }
6329
+ /** Reads `relatedApp` by its app ID; a written `code` is dropped. */
6330
+ function parseRelatedApp(raw) {
6331
+ return { app: String(raw.app ?? "") };
6332
+ }
6306
6333
  function parseLookup(code, raw) {
6307
6334
  if (!isRecord(raw)) throw invalidLookup(code, "must be an object");
6308
6335
  if (!isRecord(raw.relatedApp)) throw invalidLookup(code, "must have a \"relatedApp\" object");
@@ -6316,7 +6343,7 @@ function parseLookup(code, raw) {
6316
6343
  };
6317
6344
  });
6318
6345
  return {
6319
- relatedApp: LookupRelatedApp.create(String(raw.relatedApp.app ?? ""), optionalString(raw.relatedApp.code)),
6346
+ relatedApp: parseRelatedApp(raw.relatedApp),
6320
6347
  relatedKeyField: String(raw.relatedKeyField ?? ""),
6321
6348
  fieldMappings,
6322
6349
  lookupPickerFields,
@@ -6332,7 +6359,6 @@ function parseReferenceTableField(raw, code, base) {
6332
6359
  if (!Array.isArray(refTable.displayFields)) throw new BusinessRuleError(FormSchemaErrorCode.FsInvalidSchemaStructure, `Field "${code}" of type REFERENCE_TABLE must have "referenceTable.displayFields" array`);
6333
6360
  const condition = refTable.condition;
6334
6361
  const displayFields = refTable.displayFields.map((f) => FieldCode.create(f));
6335
- const relatedApp = refTable.relatedApp;
6336
6362
  const conditionField = String(condition.field ?? "");
6337
6363
  const conditionRelatedField = String(condition.relatedField ?? "");
6338
6364
  const size = optionalString(refTable.size);
@@ -6342,7 +6368,7 @@ function parseReferenceTableField(raw, code, base) {
6342
6368
  ...base,
6343
6369
  type: "REFERENCE_TABLE",
6344
6370
  properties: { referenceTable: {
6345
- relatedApp: { app: String(relatedApp.app ?? "") },
6371
+ relatedApp: parseRelatedApp(refTable.relatedApp),
6346
6372
  condition: {
6347
6373
  field: FieldCode.create(conditionField),
6348
6374
  relatedField: FieldCode.create(conditionRelatedField)
@@ -12476,7 +12502,7 @@ async function detectCustomizationThreeWayDiff({ container, input }) {
12476
12502
  remote,
12477
12503
  basePath: input.basePath
12478
12504
  });
12479
- return buildRecordThreeWayDiff(merge, (entry) => entry.key, [], buildNotes(estimatedKeys, unreadableLocalKeys, new Set(merge.entries.filter((entry) => entry.change.kind === "localOnly" || entry.change.kind === "remoteOnly" || entry.change.kind === "conflict").map((entry) => entry.key))));
12505
+ return buildRecordThreeWayDiff(merge, (entry) => entry.key, { notes: buildNotes(estimatedKeys, unreadableLocalKeys, new Set(merge.entries.filter((entry) => entry.change.kind === "localOnly" || entry.change.kind === "remoteOnly" || entry.change.kind === "conflict").map((entry) => entry.key))) });
12480
12506
  }
12481
12507
  //#endregion
12482
12508
  //#region src/cli/commands/customize/diff.ts
@@ -13971,6 +13997,26 @@ var capture_default$8 = createCaptureCommand({
13971
13997
  resolveAppContainerConfig: resolveNotificationAppContainerConfig
13972
13998
  });
13973
13999
  //#endregion
14000
+ //#region src/core/domain/services/filterCondKey.ts
14001
+ /**
14002
+ * Merge key of the `index`-th entry among the entries sharing `filterCond`
14003
+ * (record permission rights, perRecord notifications). The index suffix comes
14004
+ * after the full filterCond, so the last `#` always starts the index even when
14005
+ * the filterCond itself contains `#`.
14006
+ */
14007
+ function filterCondKey(filterCond, index) {
14008
+ return `${filterCond}#${index}`;
14009
+ }
14010
+ /**
14011
+ * Display form of a {@link filterCondKey}: the filterCond quoted as a value,
14012
+ * then the index (`"status = \"A\""#0`). Quoting keeps a `]`, `#`, `"` or
14013
+ * newline in the filterCond from blurring where the key ends.
14014
+ */
14015
+ function describeFilterCondKey(key) {
14016
+ const indexStart = key.lastIndexOf("#");
14017
+ return `${formatValue(key.slice(0, indexStart))}${key.slice(indexStart)}`;
14018
+ }
14019
+ //#endregion
13974
14020
  //#region src/core/domain/notification/services/notificationMerge.ts
13975
14021
  /**
13976
14022
  * 3-way merge for the notification domain (general / perRecord / reminder).
@@ -13994,16 +14040,29 @@ var capture_default$8 = createCaptureCommand({
13994
14040
  * the `notifyToCommenter` scalar as a single whole-entity 3-way, so the scalar
13995
14041
  * is never dropped from the 3-way.
13996
14042
  */
13997
- const GENERAL_SCALAR_KEY = "general:notifyToCommenter";
13998
- const REMINDER_TIMEZONE_KEY = "reminder:timezone";
14043
+ const GENERAL_KEY_PREFIX = "general:";
14044
+ const PER_RECORD_KEY_PREFIX = "perRecord:";
14045
+ const REMINDER_KEY_PREFIX = "reminder:";
14046
+ const GENERAL_SCALAR_KEY = `${GENERAL_KEY_PREFIX}notifyToCommenter`;
14047
+ const REMINDER_TIMEZONE_KEY = `${REMINDER_KEY_PREFIX}timezone`;
13999
14048
  function generalEntityKey(notif) {
14000
- return `general:${notif.entity.type}:${notif.entity.code}`;
14049
+ return `${GENERAL_KEY_PREFIX}${notif.entity.type}:${notif.entity.code}`;
14001
14050
  }
14002
14051
  function perRecordCompositeKey(filterCond, index) {
14003
- return `perRecord:${filterCond}#${index}`;
14052
+ return `${PER_RECORD_KEY_PREFIX}${filterCondKey(filterCond, index)}`;
14004
14053
  }
14005
14054
  function reminderKey(notif) {
14006
- return `reminder:${notif.code}`;
14055
+ return `${REMINDER_KEY_PREFIX}${notif.code}`;
14056
+ }
14057
+ /**
14058
+ * Display form of a merge key. A perRecord key carries a filterCond, which is
14059
+ * quoted ({@link describeFilterCondKey}); the other keys are built from names
14060
+ * and are shown as they are.
14061
+ */
14062
+ function describeNotificationMergeKey(key) {
14063
+ if (!key.startsWith(PER_RECORD_KEY_PREFIX)) return key;
14064
+ const filterCondPart = key.slice(10);
14065
+ return `${PER_RECORD_KEY_PREFIX}${describeFilterCondKey(filterCondPart)}`;
14007
14066
  }
14008
14067
  /**
14009
14068
  * General notification equality, matching `compareGeneralNotification`:
@@ -14079,7 +14138,7 @@ function resolveEntryValue(entry, resolution) {
14079
14138
  function collectGeneralNotifications(entries, resolution) {
14080
14139
  const result = [];
14081
14140
  for (const entry of entries) {
14082
- if (!entry.key.startsWith("general:") || entry.key === GENERAL_SCALAR_KEY) continue;
14141
+ if (!entry.key.startsWith(GENERAL_KEY_PREFIX) || entry.key === GENERAL_SCALAR_KEY) continue;
14083
14142
  const value = resolveEntryValue(entry, resolution);
14084
14143
  if (value !== void 0) result.push(value);
14085
14144
  }
@@ -14088,7 +14147,7 @@ function collectGeneralNotifications(entries, resolution) {
14088
14147
  function collectPerRecordNotifications(entries, resolution) {
14089
14148
  const result = [];
14090
14149
  for (const entry of entries) {
14091
- if (!entry.key.startsWith("perRecord:")) continue;
14150
+ if (!entry.key.startsWith(PER_RECORD_KEY_PREFIX)) continue;
14092
14151
  const value = resolveEntryValue(entry, resolution);
14093
14152
  if (value !== void 0) result.push(value);
14094
14153
  }
@@ -14097,7 +14156,7 @@ function collectPerRecordNotifications(entries, resolution) {
14097
14156
  function collectReminderNotifications(entries, resolution) {
14098
14157
  const result = [];
14099
14158
  for (const entry of entries) {
14100
- if (!entry.key.startsWith("reminder:") || entry.key === REMINDER_TIMEZONE_KEY) continue;
14159
+ if (!entry.key.startsWith(REMINDER_KEY_PREFIX) || entry.key === REMINDER_TIMEZONE_KEY) continue;
14101
14160
  const value = resolveEntryValue(entry, resolution);
14102
14161
  if (value !== void 0) result.push(value);
14103
14162
  }
@@ -14222,7 +14281,7 @@ function buildThreeWay(merge) {
14222
14281
  const extras = [];
14223
14282
  for (const entry of merge.entries) {
14224
14283
  const base = {
14225
- key: entry.key,
14284
+ key: describeNotificationMergeKey(entry.key),
14226
14285
  label: entryLabel(entry)
14227
14286
  };
14228
14287
  switch (entry.change.kind) {
@@ -14395,6 +14454,7 @@ var pull_default$8 = createPullCommand({
14395
14454
  args: notificationArgs,
14396
14455
  subject: "notification config",
14397
14456
  conflictNoun: "notification",
14457
+ nameConflict: nameConflictAsDiffLine(describeNotificationMergeKey),
14398
14458
  createContainer: createNotificationCliContainer,
14399
14459
  pullFn: async ({ container, input }) => {
14400
14460
  const result = await pullNotification({
@@ -15835,15 +15895,16 @@ async function applyPulledGeneralSettingsMerge({ container, input }) {
15835
15895
  * means a reordering within a filterCond is seen as content changes at those
15836
15896
  * indices, matching the existing 2-way detector.
15837
15897
  */
15838
- function compositeKey(filterCond, index) {
15839
- return `${filterCond}#${index}`;
15898
+ /** Display form of a merge key, with its filterCond quoted. */
15899
+ function describeRecordPermissionMergeKey(key) {
15900
+ return describeFilterCondKey(key);
15840
15901
  }
15841
15902
  /** Converts the ordered `rights` list into a record keyed by `filterCond#i`. */
15842
15903
  function toRecord(config) {
15843
15904
  const record = {};
15844
15905
  const grouped = groupByKey(config.rights, (r) => r.filterCond);
15845
15906
  for (const [filterCond, group] of grouped) group.forEach((right, i) => {
15846
- record[compositeKey(filterCond, i)] = right;
15907
+ record[filterCondKey(filterCond, i)] = right;
15847
15908
  });
15848
15909
  return record;
15849
15910
  }
@@ -17602,7 +17663,7 @@ async function detectRecordPermissionThreeWayDiff({ container }) {
17602
17663
  return buildRecordThreeWayDiff(computeRecordPermissionThreeWayMerge(state, local, remote.config), (entry) => {
17603
17664
  const right = entry.local ?? entry.remote ?? entry.base;
17604
17665
  return right ? describeRecordPermissionFilter(right.filterCond) : entry.key;
17605
- });
17666
+ }, { describeKey: describeRecordPermissionMergeKey });
17606
17667
  }
17607
17668
  //#endregion
17608
17669
  //#region src/cli/commands/record-acl/diff.ts
@@ -17652,6 +17713,7 @@ var pull_default$4 = createPullCommand({
17652
17713
  args: recordAclArgs,
17653
17714
  subject: "record permission config",
17654
17715
  conflictNoun: "record permission",
17716
+ nameConflict: nameConflictAsDiffLine(describeRecordPermissionMergeKey),
17655
17717
  createContainer: createRecordPermissionCliContainer,
17656
17718
  pullFn: async ({ container, input }) => {
17657
17719
  const result = await pullRecordPermission({