@supernova-studio/client 1.0.0-alpha.18 → 1.0.0-alpha.19

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.d.mts CHANGED
@@ -1822,7 +1822,7 @@ type LocalDocsPageGroup = OmitStrict<ElementGroup, "id" | "brandPersistentId" |
1822
1822
  userSlug?: undefined;
1823
1823
  };
1824
1824
  type NarrowedUnion<T, U extends T> = U;
1825
- type SupportedActionType = NarrowedUnion<DTOElementActionInput["type"], "DocumentationPageCreate" | "DocumentationPageUpdate" | "DocumentationPageDelete" | "DocumentationPageMove">;
1825
+ type SupportedActionType = NarrowedUnion<DTOElementActionInput["type"], "DocumentationPageCreate" | "DocumentationPageUpdate" | "DocumentationPageDelete" | "DocumentationPageMove" | "DocumentationGroupCreate" | "DocumentationGroupUpdate" | "DocumentationGroupDelete" | "DocumentationGroupMove">;
1826
1826
 
1827
1827
  declare const DTOColorTokenInlineData: z.ZodObject<{
1828
1828
  value: z.ZodString;
package/dist/index.d.ts CHANGED
@@ -1822,7 +1822,7 @@ type LocalDocsPageGroup = OmitStrict<ElementGroup, "id" | "brandPersistentId" |
1822
1822
  userSlug?: undefined;
1823
1823
  };
1824
1824
  type NarrowedUnion<T, U extends T> = U;
1825
- type SupportedActionType = NarrowedUnion<DTOElementActionInput["type"], "DocumentationPageCreate" | "DocumentationPageUpdate" | "DocumentationPageDelete" | "DocumentationPageMove">;
1825
+ type SupportedActionType = NarrowedUnion<DTOElementActionInput["type"], "DocumentationPageCreate" | "DocumentationPageUpdate" | "DocumentationPageDelete" | "DocumentationPageMove" | "DocumentationGroupCreate" | "DocumentationGroupUpdate" | "DocumentationGroupDelete" | "DocumentationGroupMove">;
1826
1826
 
1827
1827
  declare const DTOColorTokenInlineData: z.ZodObject<{
1828
1828
  value: z.ZodString;
package/dist/index.js CHANGED
@@ -13388,11 +13388,15 @@ var LocalDocsElementActionExecutor = class {
13388
13388
  applyTransaction(trx) {
13389
13389
  switch (trx.type) {
13390
13390
  case "DocumentationGroupCreate":
13391
+ return this.documentationGroupCreate(trx);
13392
+ case "DocumentationGroupUpdate":
13393
+ return this.documentationGroupUpdate(trx);
13391
13394
  case "DocumentationGroupDelete":
13392
- case "DocumentationGroupDuplicate":
13395
+ return this.documentationGroupDelete(trx);
13393
13396
  case "DocumentationGroupMove":
13397
+ return this.documentationGroupMove(trx);
13398
+ case "DocumentationGroupDuplicate":
13394
13399
  case "DocumentationGroupRestore":
13395
- case "DocumentationGroupUpdate":
13396
13400
  throw new Error(`Transaction type ${trx.type} is not yet implemented`);
13397
13401
  case "DocumentationPageCreate":
13398
13402
  return this.documentationPageCreate(trx);
@@ -13414,11 +13418,17 @@ var LocalDocsElementActionExecutor = class {
13414
13418
  throw new Error(`Transaction type ${trx.type} is not a documentation element action`);
13415
13419
  }
13416
13420
  }
13421
+ //
13422
+ // Pages
13423
+ //
13417
13424
  documentationPageCreate(trx) {
13418
13425
  const { input } = trx;
13419
13426
  if (this.pages.has(input.persistentId)) {
13420
13427
  return;
13421
13428
  }
13429
+ if (!this.groups.has(input.parentPersistentId)) {
13430
+ throw new Error(`Cannot create page: parent persistent id ${input.parentPersistentId} was not found`);
13431
+ }
13422
13432
  const localPage = {
13423
13433
  createdAt: /* @__PURE__ */ new Date(),
13424
13434
  parentPersistentId: input.parentPersistentId,
@@ -13480,6 +13490,77 @@ var LocalDocsElementActionExecutor = class {
13480
13490
  }
13481
13491
  }
13482
13492
  //
13493
+ // Group
13494
+ //
13495
+ documentationGroupCreate(trx) {
13496
+ const { input } = trx;
13497
+ if (this.groups.has(input.persistentId)) {
13498
+ return;
13499
+ }
13500
+ const localGroup = {
13501
+ parentPersistentId: input.parentPersistentId,
13502
+ persistentId: input.persistentId,
13503
+ shortPersistentId: generateShortPersistentId(),
13504
+ slug: slugify(input.title),
13505
+ meta: { name: input.title },
13506
+ createdAt: /* @__PURE__ */ new Date(),
13507
+ updatedAt: /* @__PURE__ */ new Date(),
13508
+ data: {
13509
+ // TODO Artem: move somewhere reusable
13510
+ configuration: input.configuration ? { ...defaultDocumentationItemConfigurationV2, ...input.configuration } : input.configuration
13511
+ },
13512
+ sortOrder: this.calculateSortOrder(input.parentPersistentId, input.afterPersistentId),
13513
+ designSystemVersionId: this.designSystemVersionId
13514
+ };
13515
+ this.groups.set(localGroup.persistentId, localGroup);
13516
+ }
13517
+ documentationGroupUpdate(trx) {
13518
+ const { input } = trx;
13519
+ const existingGroup = this.groups.get(input.id);
13520
+ if (!existingGroup) {
13521
+ throw new Error(`Cannot update group: group id ${input.id} was not found`);
13522
+ }
13523
+ const localGroup = {
13524
+ ...existingGroup,
13525
+ userSlug: void 0,
13526
+ meta: {
13527
+ ...existingGroup.meta,
13528
+ name: _nullishCoalesce(input.title, () => ( existingGroup.meta.name))
13529
+ },
13530
+ data: {
13531
+ // TODO Artem: move somewhere reusable
13532
+ configuration: input.configuration ? {
13533
+ ..._nullishCoalesce(_optionalChain([existingGroup, 'access', _86 => _86.data, 'optionalAccess', _87 => _87.configuration]), () => ( defaultDocumentationItemConfigurationV2)),
13534
+ ...input.configuration
13535
+ } : _optionalChain([existingGroup, 'access', _88 => _88.data, 'optionalAccess', _89 => _89.configuration])
13536
+ }
13537
+ };
13538
+ this.groups.set(localGroup.persistentId, localGroup);
13539
+ }
13540
+ documentationGroupMove(trx) {
13541
+ const { input } = trx;
13542
+ if (!this.groups.has(input.parentPersistentId)) {
13543
+ throw new Error(`Cannot move group: group parent id ${input.parentPersistentId} was not found`);
13544
+ }
13545
+ const existingGroup = this.groups.get(input.id);
13546
+ if (!existingGroup) {
13547
+ throw new Error(`Cannot update group: group id ${input.id} was not found`);
13548
+ }
13549
+ const localGroup = {
13550
+ ...existingGroup,
13551
+ userSlug: void 0,
13552
+ sortOrder: this.calculateSortOrder(input.parentPersistentId, input.afterPersistentId),
13553
+ parentPersistentId: input.parentPersistentId
13554
+ };
13555
+ this.groups.set(localGroup.persistentId, localGroup);
13556
+ }
13557
+ documentationGroupDelete(trx) {
13558
+ const { input } = trx;
13559
+ if (!this.groups.delete(trx.input.id)) {
13560
+ throw new Error(`Cannot delete group: group id ${input.id} was not found`);
13561
+ }
13562
+ }
13563
+ //
13483
13564
  // Utils
13484
13565
  //
13485
13566
  calculateSortOrder(parentPersistentId, afterPersistentId) {
@@ -13500,7 +13581,7 @@ var LocalDocsElementActionExecutor = class {
13500
13581
  return neighbours[neighbours.length - 1].sortOrder + sortOrderStep;
13501
13582
  }
13502
13583
  const left = neighbours[index].sortOrder;
13503
- const right = _nullishCoalesce(_optionalChain([neighbours, 'access', _86 => _86[index + 1], 'optionalAccess', _87 => _87.sortOrder]), () => ( left + sortOrderStep * 2));
13584
+ const right = _nullishCoalesce(_optionalChain([neighbours, 'access', _90 => _90[index + 1], 'optionalAccess', _91 => _91.sortOrder]), () => ( left + sortOrderStep * 2));
13504
13585
  return (right + left) / 2;
13505
13586
  }
13506
13587
  };