@slicemachine/manager 0.24.16-alpha.jp-fix-cr-modal-rules-of-hooks.3 → 0.24.16-alpha.jp-cr-sync-groups.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.
@@ -37,6 +37,22 @@ type SliceMachineManagerUpdateCustomTypeMocksConfigArgs = {
37
37
  customTypeID: string;
38
38
  mocksConfig: Record<string, unknown>;
39
39
  };
40
+ export type SliceMachineManagerUpdateCustomTypeArgs = CustomTypeUpdateHookData & {
41
+ updateMeta?: {
42
+ fieldIdChanged?: {
43
+ /**
44
+ * Previous path of the changed field. Can be used to identify the field
45
+ * that had an API ID rename (e.g. ["page", "title"])
46
+ */
47
+ previousPath: string[];
48
+ /**
49
+ * New path of the changed field. Can be used to identify the field that
50
+ * had an API ID rename (e.g. ["page", "title2"])
51
+ */
52
+ newPath: string[];
53
+ };
54
+ };
55
+ };
40
56
  type SliceMachineManagerUpdateCustomTypeMocksConfigArgsReturnType = {
41
57
  errors: HookError[];
42
58
  };
@@ -64,7 +80,7 @@ export declare class CustomTypesManager extends BaseManager {
64
80
  * property.
65
81
  */
66
82
  private updateContentRelationships;
67
- updateCustomType(args: CustomTypeUpdateHookData): Promise<CustomTypesMachineManagerUpdateCustomTypeReturnType>;
83
+ updateCustomType(args: SliceMachineManagerUpdateCustomTypeArgs): Promise<CustomTypesMachineManagerUpdateCustomTypeReturnType>;
68
84
  renameCustomType(args: CustomTypeRenameHookData): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeRenameHook>>>;
69
85
  deleteCustomType(args: CustomTypesMachineManagerDeleteCustomTypeArgs): Promise<CustomTypesMachineManagerDeleteCustomTypeReturnType>;
70
86
  pushCustomType(args: SliceMachineManagerPushCustomTypeArgs): Promise<void>;
@@ -221,18 +237,31 @@ declare const InferSliceResponse: z.ZodObject<{
221
237
  useAsTitle?: boolean | undefined;
222
238
  placeholder?: string | undefined;
223
239
  select?: "media" | "document" | "web" | null | undefined;
224
- customtypes?: readonly (string | ({
240
+ customtypes?: readonly (string | {
225
241
  id: string;
226
- } & {
227
- fields?: readonly (string | {
242
+ fields: readonly (string | {
228
243
  id: string;
229
- customtypes: readonly (string | ({
244
+ customtypes: readonly (string | {
230
245
  id: string;
231
- } & {
232
- fields?: readonly string[] | undefined;
233
- }))[];
234
- })[] | undefined;
235
- }))[] | undefined;
246
+ fields: readonly (string | {
247
+ id: string;
248
+ fields: readonly string[];
249
+ })[];
250
+ })[];
251
+ } | {
252
+ id: string;
253
+ fields: readonly (string | {
254
+ id: string;
255
+ customtypes: readonly (string | {
256
+ id: string;
257
+ fields: readonly (string | {
258
+ id: string;
259
+ fields: readonly string[];
260
+ })[];
261
+ })[];
262
+ })[];
263
+ })[];
264
+ })[] | undefined;
236
265
  masks?: readonly string[] | undefined;
237
266
  tags?: readonly string[] | undefined;
238
267
  allowTargetBlank?: boolean | undefined;
@@ -407,18 +436,31 @@ declare const InferSliceResponse: z.ZodObject<{
407
436
  useAsTitle?: boolean | undefined;
408
437
  placeholder?: string | undefined;
409
438
  select?: "media" | "document" | "web" | null | undefined;
410
- customtypes?: readonly (string | ({
439
+ customtypes?: readonly (string | {
411
440
  id: string;
412
- } & {
413
- fields?: readonly (string | {
441
+ fields: readonly (string | {
442
+ id: string;
443
+ customtypes: readonly (string | {
444
+ id: string;
445
+ fields: readonly (string | {
446
+ id: string;
447
+ fields: readonly string[];
448
+ })[];
449
+ })[];
450
+ } | {
414
451
  id: string;
415
- customtypes: readonly (string | ({
452
+ fields: readonly (string | {
416
453
  id: string;
417
- } & {
418
- fields?: readonly string[] | undefined;
419
- }))[];
420
- })[] | undefined;
421
- }))[] | undefined;
454
+ customtypes: readonly (string | {
455
+ id: string;
456
+ fields: readonly (string | {
457
+ id: string;
458
+ fields: readonly string[];
459
+ })[];
460
+ })[];
461
+ })[];
462
+ })[];
463
+ })[] | undefined;
422
464
  masks?: readonly string[] | undefined;
423
465
  tags?: readonly string[] | undefined;
424
466
  allowTargetBlank?: boolean | undefined;
@@ -593,18 +635,31 @@ declare const InferSliceResponse: z.ZodObject<{
593
635
  useAsTitle?: boolean | undefined;
594
636
  placeholder?: string | undefined;
595
637
  select?: "media" | "document" | "web" | null | undefined;
596
- customtypes?: readonly (string | ({
638
+ customtypes?: readonly (string | {
597
639
  id: string;
598
- } & {
599
- fields?: readonly (string | {
640
+ fields: readonly (string | {
600
641
  id: string;
601
- customtypes: readonly (string | ({
642
+ customtypes: readonly (string | {
602
643
  id: string;
603
- } & {
604
- fields?: readonly string[] | undefined;
605
- }))[];
606
- })[] | undefined;
607
- }))[] | undefined;
644
+ fields: readonly (string | {
645
+ id: string;
646
+ fields: readonly string[];
647
+ })[];
648
+ })[];
649
+ } | {
650
+ id: string;
651
+ fields: readonly (string | {
652
+ id: string;
653
+ customtypes: readonly (string | {
654
+ id: string;
655
+ fields: readonly (string | {
656
+ id: string;
657
+ fields: readonly string[];
658
+ })[];
659
+ })[];
660
+ })[];
661
+ })[];
662
+ })[] | undefined;
608
663
  masks?: readonly string[] | undefined;
609
664
  tags?: readonly string[] | undefined;
610
665
  allowTargetBlank?: boolean | undefined;
@@ -778,18 +833,31 @@ declare const InferSliceResponse: z.ZodObject<{
778
833
  useAsTitle?: boolean | undefined;
779
834
  placeholder?: string | undefined;
780
835
  select?: "media" | "document" | "web" | null | undefined;
781
- customtypes?: readonly (string | ({
836
+ customtypes?: readonly (string | {
782
837
  id: string;
783
- } & {
784
- fields?: readonly (string | {
838
+ fields: readonly (string | {
839
+ id: string;
840
+ customtypes: readonly (string | {
841
+ id: string;
842
+ fields: readonly (string | {
843
+ id: string;
844
+ fields: readonly string[];
845
+ })[];
846
+ })[];
847
+ } | {
785
848
  id: string;
786
- customtypes: readonly (string | ({
849
+ fields: readonly (string | {
787
850
  id: string;
788
- } & {
789
- fields?: readonly string[] | undefined;
790
- }))[];
791
- })[] | undefined;
792
- }))[] | undefined;
851
+ customtypes: readonly (string | {
852
+ id: string;
853
+ fields: readonly (string | {
854
+ id: string;
855
+ fields: readonly string[];
856
+ })[];
857
+ })[];
858
+ })[];
859
+ })[];
860
+ })[] | undefined;
793
861
  masks?: readonly string[] | undefined;
794
862
  tags?: readonly string[] | undefined;
795
863
  allowTargetBlank?: boolean | undefined;
@@ -979,18 +1047,31 @@ declare const InferSliceResponse: z.ZodObject<{
979
1047
  useAsTitle?: boolean | undefined;
980
1048
  placeholder?: string | undefined;
981
1049
  select?: "media" | "document" | "web" | null | undefined;
982
- customtypes?: readonly (string | ({
1050
+ customtypes?: readonly (string | {
983
1051
  id: string;
984
- } & {
985
- fields?: readonly (string | {
1052
+ fields: readonly (string | {
986
1053
  id: string;
987
- customtypes: readonly (string | ({
1054
+ customtypes: readonly (string | {
988
1055
  id: string;
989
- } & {
990
- fields?: readonly string[] | undefined;
991
- }))[];
992
- })[] | undefined;
993
- }))[] | undefined;
1056
+ fields: readonly (string | {
1057
+ id: string;
1058
+ fields: readonly string[];
1059
+ })[];
1060
+ })[];
1061
+ } | {
1062
+ id: string;
1063
+ fields: readonly (string | {
1064
+ id: string;
1065
+ customtypes: readonly (string | {
1066
+ id: string;
1067
+ fields: readonly (string | {
1068
+ id: string;
1069
+ fields: readonly string[];
1070
+ })[];
1071
+ })[];
1072
+ })[];
1073
+ })[];
1074
+ })[] | undefined;
994
1075
  masks?: readonly string[] | undefined;
995
1076
  tags?: readonly string[] | undefined;
996
1077
  allowTargetBlank?: boolean | undefined;
@@ -1165,18 +1246,31 @@ declare const InferSliceResponse: z.ZodObject<{
1165
1246
  useAsTitle?: boolean | undefined;
1166
1247
  placeholder?: string | undefined;
1167
1248
  select?: "media" | "document" | "web" | null | undefined;
1168
- customtypes?: readonly (string | ({
1249
+ customtypes?: readonly (string | {
1169
1250
  id: string;
1170
- } & {
1171
- fields?: readonly (string | {
1251
+ fields: readonly (string | {
1252
+ id: string;
1253
+ customtypes: readonly (string | {
1254
+ id: string;
1255
+ fields: readonly (string | {
1256
+ id: string;
1257
+ fields: readonly string[];
1258
+ })[];
1259
+ })[];
1260
+ } | {
1172
1261
  id: string;
1173
- customtypes: readonly (string | ({
1262
+ fields: readonly (string | {
1174
1263
  id: string;
1175
- } & {
1176
- fields?: readonly string[] | undefined;
1177
- }))[];
1178
- })[] | undefined;
1179
- }))[] | undefined;
1264
+ customtypes: readonly (string | {
1265
+ id: string;
1266
+ fields: readonly (string | {
1267
+ id: string;
1268
+ fields: readonly string[];
1269
+ })[];
1270
+ })[];
1271
+ })[];
1272
+ })[];
1273
+ })[] | undefined;
1180
1274
  masks?: readonly string[] | undefined;
1181
1275
  tags?: readonly string[] | undefined;
1182
1276
  allowTargetBlank?: boolean | undefined;
@@ -1351,18 +1445,31 @@ declare const InferSliceResponse: z.ZodObject<{
1351
1445
  useAsTitle?: boolean | undefined;
1352
1446
  placeholder?: string | undefined;
1353
1447
  select?: "media" | "document" | "web" | null | undefined;
1354
- customtypes?: readonly (string | ({
1448
+ customtypes?: readonly (string | {
1355
1449
  id: string;
1356
- } & {
1357
- fields?: readonly (string | {
1450
+ fields: readonly (string | {
1358
1451
  id: string;
1359
- customtypes: readonly (string | ({
1452
+ customtypes: readonly (string | {
1360
1453
  id: string;
1361
- } & {
1362
- fields?: readonly string[] | undefined;
1363
- }))[];
1364
- })[] | undefined;
1365
- }))[] | undefined;
1454
+ fields: readonly (string | {
1455
+ id: string;
1456
+ fields: readonly string[];
1457
+ })[];
1458
+ })[];
1459
+ } | {
1460
+ id: string;
1461
+ fields: readonly (string | {
1462
+ id: string;
1463
+ customtypes: readonly (string | {
1464
+ id: string;
1465
+ fields: readonly (string | {
1466
+ id: string;
1467
+ fields: readonly string[];
1468
+ })[];
1469
+ })[];
1470
+ })[];
1471
+ })[];
1472
+ })[] | undefined;
1366
1473
  masks?: readonly string[] | undefined;
1367
1474
  tags?: readonly string[] | undefined;
1368
1475
  allowTargetBlank?: boolean | undefined;
@@ -1536,18 +1643,31 @@ declare const InferSliceResponse: z.ZodObject<{
1536
1643
  useAsTitle?: boolean | undefined;
1537
1644
  placeholder?: string | undefined;
1538
1645
  select?: "media" | "document" | "web" | null | undefined;
1539
- customtypes?: readonly (string | ({
1646
+ customtypes?: readonly (string | {
1540
1647
  id: string;
1541
- } & {
1542
- fields?: readonly (string | {
1648
+ fields: readonly (string | {
1543
1649
  id: string;
1544
- customtypes: readonly (string | ({
1650
+ customtypes: readonly (string | {
1545
1651
  id: string;
1546
- } & {
1547
- fields?: readonly string[] | undefined;
1548
- }))[];
1549
- })[] | undefined;
1550
- }))[] | undefined;
1652
+ fields: readonly (string | {
1653
+ id: string;
1654
+ fields: readonly string[];
1655
+ })[];
1656
+ })[];
1657
+ } | {
1658
+ id: string;
1659
+ fields: readonly (string | {
1660
+ id: string;
1661
+ customtypes: readonly (string | {
1662
+ id: string;
1663
+ fields: readonly (string | {
1664
+ id: string;
1665
+ fields: readonly string[];
1666
+ })[];
1667
+ })[];
1668
+ })[];
1669
+ })[];
1670
+ })[] | undefined;
1551
1671
  masks?: readonly string[] | undefined;
1552
1672
  tags?: readonly string[] | undefined;
1553
1673
  allowTargetBlank?: boolean | undefined;
@@ -309,54 +309,113 @@ const InferSliceResponse = z.object({
309
309
  langSmithUrl: z.string().url().optional()
310
310
  });
311
311
  function updateCRCustomType(args) {
312
- const [previousCustomTypeId, previousFieldId] = args.previousPath;
313
- const [newCustomTypeId, newFieldId] = args.newPath;
314
- if (!previousCustomTypeId || !newCustomTypeId) {
312
+ const previousPath = getPathIds(args.previousPath);
313
+ const newPath = getPathIds(args.newPath);
314
+ if (!previousPath.customTypeId || !newPath.customTypeId) {
315
315
  throw new Error("Could not find a customtype id in previousPath and/or newPath, which should not be possible.");
316
316
  }
317
- if (!previousFieldId || !newFieldId) {
317
+ if (!previousPath.fieldId || !newPath.fieldId) {
318
318
  throw new Error("Could not find a field id in previousPath and/or newPath, which should not be possible.");
319
319
  }
320
320
  const customType = shallowCloneIfObject(args.customType);
321
- if (typeof customType === "string" || !customType.fields) {
321
+ if (typeof customType === "string") {
322
322
  return customType;
323
323
  }
324
- const matchedCustomTypeId = customType.id === previousCustomTypeId;
325
- const newFields = customType.fields.map((fieldArg) => {
326
- const customTypeField = shallowCloneIfObject(fieldArg);
327
- if (typeof customTypeField === "string") {
328
- if (matchedCustomTypeId && customTypeField === previousFieldId && customTypeField !== newFieldId) {
329
- return newFieldId;
324
+ const matchedCustomTypeId = customType.id === previousPath.customTypeId;
325
+ return {
326
+ ...customType,
327
+ fields: customType.fields.map((fieldArg) => {
328
+ const customTypeField = shallowCloneIfObject(fieldArg);
329
+ if (typeof customTypeField === "string") {
330
+ if (matchedCustomTypeId && customTypeField === previousPath.fieldId && customTypeField !== newPath.fieldId) {
331
+ return newPath.fieldId;
332
+ }
333
+ return customTypeField;
330
334
  }
331
- return customTypeField;
332
- }
333
- if (matchedCustomTypeId && customTypeField.id === previousFieldId && customTypeField.id !== newFieldId) {
334
- customTypeField.id = newFieldId;
335
+ if (matchedCustomTypeId && customTypeField.id === previousPath.fieldId && customTypeField.id !== newPath.fieldId) {
336
+ customTypeField.id = newPath.fieldId;
337
+ }
338
+ if ("fields" in customTypeField) {
339
+ if (!previousPath.groupId && !newPath.groupId && customTypeField.id === previousPath.fieldId && customTypeField.id !== newPath.fieldId) {
340
+ return newPath.fieldId;
341
+ }
342
+ const matchedGroupId = customTypeField.id === previousPath.groupId;
343
+ if (previousPath.groupId && newPath.groupId && matchedGroupId && customTypeField.id !== newPath.groupId) {
344
+ customTypeField.id = newPath.groupId;
345
+ }
346
+ return {
347
+ ...customTypeField,
348
+ fields: customTypeField.fields.map((groupFieldArg) => {
349
+ const groupField = shallowCloneIfObject(groupFieldArg);
350
+ if (typeof groupField === "string") {
351
+ if (matchedGroupId && groupField === previousPath.fieldId && groupField !== newPath.fieldId) {
352
+ return newPath.fieldId;
353
+ }
354
+ return groupField;
355
+ }
356
+ return {
357
+ ...groupField,
358
+ fields: updateContentRelationshipFields({
359
+ customtypes: groupField.customtypes,
360
+ previousPath,
361
+ newPath
362
+ })
363
+ };
364
+ })
365
+ };
366
+ }
367
+ return {
368
+ ...customTypeField,
369
+ customtypes: updateContentRelationshipFields({
370
+ customtypes: customTypeField.customtypes,
371
+ previousPath,
372
+ newPath
373
+ })
374
+ };
375
+ })
376
+ };
377
+ }
378
+ function updateContentRelationshipFields(args) {
379
+ const { customtypes, previousPath, newPath } = args;
380
+ return customtypes.map((nestedCtArg) => {
381
+ const nestedCt = shallowCloneIfObject(nestedCtArg);
382
+ if (typeof nestedCt === "string" || // Since we are entering a new custom type, if the previous id
383
+ // doesn't match, we can return early, because it's not the
384
+ // custom type we are looking for.
385
+ nestedCt.id !== previousPath.customTypeId) {
386
+ return nestedCt;
335
387
  }
336
388
  return {
337
- ...customTypeField,
338
- customtypes: customTypeField.customtypes.map((customTypeArg) => {
339
- const nestedCustomType = shallowCloneIfObject(customTypeArg);
340
- if (typeof nestedCustomType === "string" || !nestedCustomType.fields || // Since we are on the last level, if we don't start matching right
341
- // at the custom type id, we can return exit early because it's not
342
- // a match.
343
- nestedCustomType.id !== previousCustomTypeId) {
344
- return nestedCustomType;
389
+ ...nestedCt,
390
+ fields: nestedCt.fields.map((nestedCtFieldArg) => {
391
+ const nestedCtField = shallowCloneIfObject(nestedCtFieldArg);
392
+ if (typeof nestedCtField === "string") {
393
+ if (nestedCtField === previousPath.fieldId && nestedCtField !== newPath.fieldId) {
394
+ return newPath.fieldId;
395
+ }
396
+ return nestedCtField;
397
+ }
398
+ if (nestedCtField.id === previousPath.fieldId && nestedCtField.id !== newPath.fieldId) {
399
+ nestedCtField.id = newPath.fieldId;
400
+ }
401
+ if (!previousPath.groupId || !newPath.groupId || nestedCtField.id !== previousPath.groupId) {
402
+ return nestedCtField;
403
+ }
404
+ if (nestedCtField.id !== newPath.groupId) {
405
+ nestedCtField.id = newPath.groupId;
345
406
  }
346
407
  return {
347
- ...nestedCustomType,
348
- fields: nestedCustomType.fields.map((fieldArg2) => {
349
- const nestedCustomTypeField = shallowCloneIfObject(fieldArg2);
350
- if (nestedCustomTypeField === previousFieldId && nestedCustomTypeField !== newFieldId) {
351
- return newFieldId;
408
+ ...nestedCtField,
409
+ fields: nestedCtField.fields.map((nestedCtGroupFieldId) => {
410
+ if (nestedCtGroupFieldId === previousPath.fieldId && nestedCtGroupFieldId !== newPath.fieldId) {
411
+ return newPath.fieldId;
352
412
  }
353
- return nestedCustomTypeField;
413
+ return nestedCtGroupFieldId;
354
414
  })
355
415
  };
356
416
  })
357
417
  };
358
418
  });
359
- return { ...customType, fields: newFields };
360
419
  }
361
420
  function updateFieldContentRelationships(args) {
362
421
  var _a, _b;
@@ -394,7 +453,7 @@ function updateSharedSliceContentRelationships(args) {
394
453
  const { models, previousPath, newPath, onUpdate } = args;
395
454
  for (const { model: slice } of models) {
396
455
  const updateSlice = traverseSharedSlice({
397
- path: ["."],
456
+ path: [],
398
457
  slice,
399
458
  onField: ({ field }) => {
400
459
  return updateFieldContentRelationships({
@@ -409,6 +468,19 @@ function updateSharedSliceContentRelationships(args) {
409
468
  }
410
469
  }
411
470
  }
471
+ function getPathIds(path) {
472
+ const [customTypeId, groupOrFieldId, fieldId] = path;
473
+ return {
474
+ customTypeId,
475
+ /**
476
+ * Id of a changed group. If it's defined, it means that a group or a field
477
+ * inside a group had its API ID renamed. It's defined when the path has a
478
+ * third element (e.g. `["customtypeA", "groupA", "fieldA"]`).
479
+ */
480
+ groupId: fieldId ? groupOrFieldId : void 0,
481
+ fieldId: fieldId || groupOrFieldId
482
+ };
483
+ }
412
484
  function isEqualModel(modelA, modelB) {
413
485
  return JSON.stringify(modelA) === JSON.stringify(modelB);
414
486
  }