kintone-migrator 0.8.1 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.mjs +45 -19
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -316,7 +316,7 @@ const KNOWN_FIELD_TYPES = new Set([
316
316
  "SUBTABLE",
317
317
  "REFERENCE_TABLE"
318
318
  ]);
319
- const SYSTEM_FIELD_TYPES$1 = new Set([
319
+ const SYSTEM_FIELD_TYPES$2 = new Set([
320
320
  "RECORD_NUMBER",
321
321
  "CREATOR",
322
322
  "CREATED_TIME",
@@ -457,7 +457,7 @@ function fromKintoneLayoutElement(raw) {
457
457
  default: throw new SystemError(SystemErrorCode.ExternalApiError, `Unknown decoration type: ${type}`);
458
458
  }
459
459
  }
460
- if (SYSTEM_FIELD_TYPES$1.has(type)) return {
460
+ if (SYSTEM_FIELD_TYPES$2.has(type)) return {
461
461
  code: String(raw.code ?? ""),
462
462
  type,
463
463
  ...raw.size !== void 0 ? { size: parseElementSize(raw.size) } : {}
@@ -576,7 +576,7 @@ var KintoneFormConfigurator = class {
576
576
  const fields = /* @__PURE__ */ new Map();
577
577
  for (const [code, prop] of Object.entries(properties)) {
578
578
  const kintoneProp = prop;
579
- if (SYSTEM_FIELD_TYPES$1.has(kintoneProp.type)) continue;
579
+ if (SYSTEM_FIELD_TYPES$2.has(kintoneProp.type)) continue;
580
580
  const fieldDef = fromKintoneProperty(kintoneProp);
581
581
  fields.set(FieldCode.create(code), fieldDef);
582
582
  if (fieldDef.type === "SUBTABLE") for (const [subCode, subDef] of fieldDef.properties.fields) fields.set(subCode, subDef);
@@ -1645,7 +1645,7 @@ const DECORATION_TYPES = new Set([
1645
1645
  "SPACER",
1646
1646
  "HR"
1647
1647
  ]);
1648
- const SYSTEM_FIELD_TYPES = new Set([
1648
+ const SYSTEM_FIELD_TYPES$1 = new Set([
1649
1649
  "RECORD_NUMBER",
1650
1650
  "CREATOR",
1651
1651
  "CREATED_TIME",
@@ -1859,7 +1859,7 @@ function parseDecorationElement(raw) {
1859
1859
  function parseLayoutElement(raw) {
1860
1860
  const type = String(raw.type);
1861
1861
  if (DECORATION_TYPES.has(type)) return parseDecorationElement(raw);
1862
- if (SYSTEM_FIELD_TYPES.has(type)) return {
1862
+ if (SYSTEM_FIELD_TYPES$1.has(type)) return {
1863
1863
  code: String(raw.code),
1864
1864
  type,
1865
1865
  ...raw.size !== void 0 ? { size: parseSize(raw.size) } : {}
@@ -2525,6 +2525,18 @@ const SYSTEM_FIELDS = new Set([
2525
2525
  "STATUS_ASSIGNEE",
2526
2526
  "CATEGORY"
2527
2527
  ]);
2528
+ const SYSTEM_FIELD_TYPES = new Set([
2529
+ "RECORD_NUMBER",
2530
+ "__ID__",
2531
+ "__REVISION__",
2532
+ "CREATOR",
2533
+ "CREATED_TIME",
2534
+ "MODIFIER",
2535
+ "UPDATED_TIME",
2536
+ "STATUS",
2537
+ "STATUS_ASSIGNEE",
2538
+ "CATEGORY"
2539
+ ]);
2528
2540
  function isSubtableRowArray(value) {
2529
2541
  if (!Array.isArray(value)) return false;
2530
2542
  if (value.length === 0) return false;
@@ -2584,6 +2596,8 @@ const RecordConverter = {
2584
2596
  const seedRecord = {};
2585
2597
  for (const [fieldCode, cell] of Object.entries(record)) {
2586
2598
  if (SYSTEM_FIELDS.has(fieldCode)) continue;
2599
+ const fieldType = cell.type;
2600
+ if (fieldType !== void 0 && SYSTEM_FIELD_TYPES.has(fieldType)) continue;
2587
2601
  seedRecord[fieldCode] = fromKintoneFieldValue(cell.value);
2588
2602
  }
2589
2603
  return seedRecord;
@@ -2593,14 +2607,15 @@ const RecordConverter = {
2593
2607
  //#endregion
2594
2608
  //#region src/core/domain/seedData/services/seedSerializer.ts
2595
2609
  const SeedSerializer = { serialize: (seedData) => {
2596
- return stringify({
2610
+ const records = seedData.records.map((record) => {
2611
+ const plain = {};
2612
+ for (const [key, value] of Object.entries(record)) plain[key] = value;
2613
+ return plain;
2614
+ });
2615
+ return stringify(seedData.key !== null ? {
2597
2616
  key: seedData.key,
2598
- records: seedData.records.map((record) => {
2599
- const plain = {};
2600
- for (const [key, value] of Object.entries(record)) plain[key] = value;
2601
- return plain;
2602
- })
2603
- }, {
2617
+ records
2618
+ } : { records }, {
2604
2619
  lineWidth: 0,
2605
2620
  defaultKeyType: "PLAIN",
2606
2621
  defaultStringType: "PLAIN"
@@ -2674,18 +2689,19 @@ const SeedParser = { parse: (rawText) => {
2674
2689
  }
2675
2690
  if (typeof parsed !== "object" || parsed === null) throw new BusinessRuleError(SeedDataErrorCode.InvalidSeedStructure, "Seed data must be an object");
2676
2691
  const obj = parsed;
2677
- if (!("key" in obj) || typeof obj.key !== "string") throw new BusinessRuleError(SeedDataErrorCode.InvalidSeedStructure, "Seed data must have a \"key\" string field");
2678
- const key = UpsertKey.create(obj.key);
2692
+ const key = "key" in obj && typeof obj.key === "string" ? UpsertKey.create(obj.key) : null;
2679
2693
  if (!("records" in obj) || !Array.isArray(obj.records)) throw new BusinessRuleError(SeedDataErrorCode.InvalidSeedStructure, "Seed data must have a \"records\" array");
2680
2694
  const records = [];
2681
2695
  const seenKeys = /* @__PURE__ */ new Set();
2682
2696
  for (let i = 0; i < obj.records.length; i++) {
2683
2697
  const record = parseRecord(obj.records[i], i);
2684
- if (!(key in record)) throw new BusinessRuleError(SeedDataErrorCode.MissingKeyField, `Record at index ${i} is missing key field "${key}"`);
2685
- const keyValue = record[key];
2686
- if (typeof keyValue !== "string") throw new BusinessRuleError(SeedDataErrorCode.InvalidSeedStructure, `Key field "${key}" value at index ${i} must be a string`);
2687
- if (seenKeys.has(keyValue)) throw new BusinessRuleError(SeedDataErrorCode.DuplicateKeyValue, `Duplicate key value "${keyValue}" at index ${i}`);
2688
- seenKeys.add(keyValue);
2698
+ if (key !== null) {
2699
+ if (!(key in record)) throw new BusinessRuleError(SeedDataErrorCode.MissingKeyField, `Record at index ${i} is missing key field "${key}"`);
2700
+ const keyValue = record[key];
2701
+ if (typeof keyValue !== "string") throw new BusinessRuleError(SeedDataErrorCode.InvalidSeedStructure, `Key field "${key}" value at index ${i} must be a string`);
2702
+ if (seenKeys.has(keyValue)) throw new BusinessRuleError(SeedDataErrorCode.DuplicateKeyValue, `Duplicate key value "${keyValue}" at index ${i}`);
2703
+ seenKeys.add(keyValue);
2704
+ }
2689
2705
  records.push(record);
2690
2706
  }
2691
2707
  return {
@@ -2771,6 +2787,16 @@ const UpsertPlanner = { plan: (key, seedRecords, existingRecords) => {
2771
2787
  async function upsertSeed({ container }) {
2772
2788
  const rawText = await container.seedStorage.get();
2773
2789
  const seedData = SeedParser.parse(rawText);
2790
+ if (seedData.key === null) {
2791
+ const kintoneRecords = seedData.records.map(RecordConverter.toKintoneRecord);
2792
+ if (kintoneRecords.length > 0) await container.recordManager.addRecords(kintoneRecords);
2793
+ return {
2794
+ added: seedData.records.length,
2795
+ updated: 0,
2796
+ unchanged: 0,
2797
+ total: seedData.records.length
2798
+ };
2799
+ }
2774
2800
  const existingRecords = await container.recordManager.getAllRecords();
2775
2801
  const plan = UpsertPlanner.plan(seedData.key, seedData.records, existingRecords);
2776
2802
  if (plan.toAdd.length > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kintone-migrator",
3
- "version": "0.8.1",
3
+ "version": "0.9.1",
4
4
  "description": "kintone form schema migration tool",
5
5
  "license": "MIT",
6
6
  "author": "Hikaru Otabe",