@supernova-studio/model 0.48.13 → 0.48.14
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 +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +951 -935
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +894 -878
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/dsm/element-snapshots/base.ts +18 -0
- package/src/dsm/element-snapshots/documentation-page-snapshot.ts +9 -1
- package/src/dsm/element-snapshots/group-snapshot.ts +9 -1
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { groupBy } from "../../utils";
|
|
2
3
|
|
|
3
4
|
export const DesignElementSnapshotReason = z.enum(["Publish", "Deletion"]);
|
|
4
5
|
|
|
@@ -14,3 +15,20 @@ export const DesignElementSnapshotBase = z.object({
|
|
|
14
15
|
|
|
15
16
|
export type DesignElementSnapshotBase = z.infer<typeof DesignElementSnapshotBase>;
|
|
16
17
|
export type DesignElementSnapshotReason = z.infer<typeof DesignElementSnapshotReason>;
|
|
18
|
+
|
|
19
|
+
//
|
|
20
|
+
// Util functions
|
|
21
|
+
//
|
|
22
|
+
|
|
23
|
+
export function pickLatestSnapshots<T extends DesignElementSnapshotBase>(
|
|
24
|
+
snapshots: T[],
|
|
25
|
+
getSnapshotElementId: (snapshot: T) => string
|
|
26
|
+
): T[] {
|
|
27
|
+
const groupedSnapshots = groupBy(snapshots, getSnapshotElementId);
|
|
28
|
+
|
|
29
|
+
return Array.from(groupedSnapshots.entries()).map(([_, snapshots]) => {
|
|
30
|
+
// Sort snapshots by created at date desc
|
|
31
|
+
const sorted = snapshots.sort((lhs, rhs) => rhs.createdAt.getTime() - lhs.createdAt.getTime());
|
|
32
|
+
return sorted[0];
|
|
33
|
+
});
|
|
34
|
+
}
|
|
@@ -2,7 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
import { DbCreateInputOmit, DbUpdate } from "../../helpers";
|
|
3
3
|
import { OmitStrict } from "../../utils";
|
|
4
4
|
import { DocumentationPageV2 } from "../elements";
|
|
5
|
-
import { DesignElementSnapshotBase } from "./base";
|
|
5
|
+
import { DesignElementSnapshotBase, pickLatestSnapshots } from "./base";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Snapshot of a documentation page.
|
|
@@ -19,3 +19,11 @@ export type DocumentationPageSnapshot = z.infer<typeof DocumentationPageSnapshot
|
|
|
19
19
|
|
|
20
20
|
export type CreateDocumentationPageSnapshot = DbCreateInputOmit<DocumentationPageSnapshot>;
|
|
21
21
|
export type UpdateDocumentationPageSnapshot = OmitStrict<DbUpdate<DocumentationPageSnapshot>, "designSystemVersionId">;
|
|
22
|
+
|
|
23
|
+
//
|
|
24
|
+
// Util functions
|
|
25
|
+
//
|
|
26
|
+
|
|
27
|
+
export function pickLatestPageSnapshots(snapshots: DocumentationPageSnapshot[]): DocumentationPageSnapshot[] {
|
|
28
|
+
return pickLatestSnapshots(snapshots, s => s.page.id);
|
|
29
|
+
}
|
|
@@ -2,7 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
import { DbCreateInputOmit, DbUpdate } from "../../helpers";
|
|
3
3
|
import { OmitStrict } from "../../utils";
|
|
4
4
|
import { ElementGroup } from "../elements";
|
|
5
|
-
import { DesignElementSnapshotBase } from "./base";
|
|
5
|
+
import { DesignElementSnapshotBase, pickLatestSnapshots } from "./base";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Snapshot of an element group.
|
|
@@ -17,3 +17,11 @@ export type ElementGroupSnapshot = z.infer<typeof ElementGroupSnapshot>;
|
|
|
17
17
|
|
|
18
18
|
export type CreateElementGroupSnapshot = DbCreateInputOmit<ElementGroupSnapshot>;
|
|
19
19
|
export type UpdateElementGroupSnapshot = OmitStrict<DbUpdate<ElementGroupSnapshot>, "designSystemVersionId">;
|
|
20
|
+
|
|
21
|
+
//
|
|
22
|
+
// Util functions
|
|
23
|
+
//
|
|
24
|
+
|
|
25
|
+
export function pickLatestGroupSnapshots(snapshots: ElementGroupSnapshot[]): ElementGroupSnapshot[] {
|
|
26
|
+
return pickLatestSnapshots(snapshots, s => s.group.id);
|
|
27
|
+
}
|