@prismicio/types-internal 0.2.3 → 0.2.7

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 (48) hide show
  1. package/lib/customtypes/CustomType.d.ts +2 -1
  2. package/lib/customtypes/CustomType.js +7 -4
  3. package/lib/customtypes/Section.d.ts +1 -1
  4. package/lib/customtypes/widgets/Widget.d.ts +1 -1
  5. package/lib/customtypes/widgets/nestable/NestableWidget.js +2 -2
  6. package/lib/customtypes/widgets/nestable/RichText.d.ts +22 -3
  7. package/lib/customtypes/widgets/nestable/RichText.js +64 -24
  8. package/lib/customtypes/widgets/nestable/index.d.ts +2 -1
  9. package/lib/customtypes/widgets/nestable/index.js +19 -20
  10. package/lib/customtypes/widgets/slices/SharedSlice.d.ts +327 -3
  11. package/lib/customtypes/widgets/slices/SharedSlice.js +4 -4
  12. package/lib/customtypes/widgets/slices/Slice.d.ts +1 -1
  13. package/lib/customtypes/widgets/slices/Slices.d.ts +1 -1
  14. package/lib/customtypes/widgets/slices/Slices.js +2 -2
  15. package/lib/customtypes/widgets/slices/index.d.ts +1 -1
  16. package/lib/customtypes/widgets/slices/index.js +2 -3
  17. package/lib/documents/DocumentData.d.ts +9 -0
  18. package/lib/documents/DocumentData.js +42 -0
  19. package/lib/documents/widgets/SimpleWidgetContent.d.ts +2 -2
  20. package/lib/documents/widgets/SimpleWidgetContent.js +2 -2
  21. package/lib/documents/widgets/index.d.ts +18 -18
  22. package/lib/documents/widgets/nestable/EmbedContent.d.ts +6 -3
  23. package/lib/documents/widgets/nestable/EmbedContent.js +2 -3
  24. package/lib/documents/widgets/nestable/FieldContent.d.ts +3 -2
  25. package/lib/documents/widgets/nestable/Link/index.d.ts +5 -5
  26. package/lib/documents/widgets/nestable/StructuredTextContent/Block.d.ts +2 -3
  27. package/lib/documents/widgets/nestable/StructuredTextContent/Block.js +2 -2
  28. package/lib/documents/widgets/nestable/index.d.ts +15 -15
  29. package/lib/documents/widgets/nestable/index.js +2 -3
  30. package/package.json +1 -1
  31. package/src/customtypes/CustomType.ts +8 -7
  32. package/src/customtypes/Section.ts +1 -1
  33. package/src/customtypes/widgets/Widget.ts +1 -1
  34. package/src/customtypes/widgets/nestable/NestableWidget.ts +1 -1
  35. package/src/customtypes/widgets/nestable/RichText.ts +64 -24
  36. package/src/customtypes/widgets/nestable/index.ts +2 -1
  37. package/src/customtypes/widgets/slices/SharedSlice.ts +4 -6
  38. package/src/customtypes/widgets/slices/Slice.ts +1 -1
  39. package/src/customtypes/widgets/slices/Slices.ts +1 -1
  40. package/src/customtypes/widgets/slices/index.ts +1 -1
  41. package/src/documents/DocumentData.ts +58 -0
  42. package/src/documents/widgets/SimpleWidgetContent.ts +4 -4
  43. package/src/documents/widgets/index.ts +1 -1
  44. package/src/documents/widgets/nestable/EmbedContent.ts +8 -6
  45. package/src/documents/widgets/nestable/FieldContent.ts +10 -2
  46. package/src/documents/widgets/nestable/Link/index.ts +1 -1
  47. package/src/documents/widgets/nestable/StructuredTextContent/Block.ts +1 -1
  48. package/src/documents/widgets/nestable/index.ts +2 -2
@@ -7,7 +7,7 @@ import SlicesTypes from "./SlicesTypes"
7
7
  const IMAGE_PLACEHOLDER_URL =
8
8
  "https://images.prismic.io/slice-machine/621a5ec4-0387-4bc5-9860-2dd46cbc07cd_default_ss.png?auto=compress,format"
9
9
 
10
- const Variation = t.exact(
10
+ export const Variation = t.exact(
11
11
  t.intersection([
12
12
  t.type({
13
13
  id: t.string,
@@ -25,9 +25,9 @@ const Variation = t.exact(
25
25
  ]),
26
26
  )
27
27
 
28
- type Variation = t.TypeOf<typeof Variation>
28
+ export type Variation = t.TypeOf<typeof Variation>
29
29
 
30
- const SharedSlice = t.exact(
30
+ export const SharedSlice = t.exact(
31
31
  t.intersection([
32
32
  t.type({
33
33
  id: t.string,
@@ -41,6 +41,4 @@ const SharedSlice = t.exact(
41
41
  ]),
42
42
  )
43
43
 
44
- type SharedSlice = t.TypeOf<typeof SharedSlice>
45
-
46
- export default SharedSlice
44
+ export type SharedSlice = t.TypeOf<typeof SharedSlice>
@@ -1,6 +1,6 @@
1
1
  import type CompositeSlice from "./CompositeSlice"
2
2
  import type LegacySlice from "./LegacySlice"
3
- import type SharedSlice from "./SharedSlice"
3
+ import type { SharedSlice } from "./SharedSlice"
4
4
  import type SharedSliceRef from "./SharedSliceRef"
5
5
 
6
6
  export type DynamicSlice = CompositeSlice | LegacySlice | SharedSliceRef
@@ -5,7 +5,7 @@ import { Format } from "../../Format"
5
5
  import WidgetTypes from "../WidgetTypes"
6
6
  import CompositeSlice from "./CompositeSlice"
7
7
  import LegacySlice from "./LegacySlice"
8
- import SharedSlice from "./SharedSlice"
8
+ import { SharedSlice } from "./SharedSlice"
9
9
  import SharedSliceRef from "./SharedSliceRef"
10
10
  import SlicesTypes from "./SlicesTypes"
11
11
 
@@ -1,6 +1,6 @@
1
1
  export { default as CompositeSlice } from "./CompositeSlice"
2
2
  export { default as LegacySlice } from "./LegacySlice"
3
- export { default as SharedSlice } from "./SharedSlice"
3
+ export * from "./SharedSlice"
4
4
  export { default as SharedSliceRef } from "./SharedSliceRef"
5
5
  export * as Slice from "./Slice"
6
6
  export * as SliceZone from "./Slices"
@@ -1,4 +1,6 @@
1
+ import { isRight } from "fp-ts/lib/Either"
1
2
  import * as O from "fp-ts/lib/Option"
3
+ import * as t from "io-ts"
2
4
 
3
5
  import { type WidgetContent, type WidgetKey, Widget } from "./widgets"
4
6
 
@@ -49,6 +51,62 @@ const DocumentData = {
49
51
  return new Map([...Array.from(acc.entries()), [widgetKey, parsedWidget]])
50
52
  }, new Map<WidgetKey, O.Option<WidgetContent>>())
51
53
  },
54
+
55
+ partitionData(data: { [p: string]: unknown }): {
56
+ types: Map<string, string>
57
+ positions: Map<string, number>
58
+ widgets: Map<WidgetKey, unknown>
59
+ slugs: ReadonlyArray<string>
60
+ uid: string | undefined
61
+ } {
62
+ const fields: [string, unknown][] = Object.entries(data)
63
+
64
+ const { types, positions, widgets } = fields.reduce(
65
+ (acc, [k, v]) => {
66
+ if (k.endsWith("_TYPE")) {
67
+ const decodedValue = t.string.decode(v)
68
+ if (isRight(decodedValue)) {
69
+ return {
70
+ ...acc,
71
+ types: acc.types.set(
72
+ k.substring(0, k.length - 5),
73
+ decodedValue.right,
74
+ ),
75
+ }
76
+ }
77
+ }
78
+ if (k.endsWith("_POSITION") && typeof v === "number") {
79
+ return {
80
+ ...acc,
81
+ positions: acc.positions.set(k.substring(0, k.length - 9), v),
82
+ }
83
+ }
84
+ if (!k.endsWith("_POSITION") && !k.endsWith("_TYPE")) {
85
+ return {
86
+ ...acc,
87
+ widgets: acc.widgets.set(k, v),
88
+ }
89
+ }
90
+ return acc
91
+ },
92
+ {
93
+ types: new Map<string, string>(),
94
+ positions: new Map<string, number>(),
95
+ widgets: new Map<string, unknown>(),
96
+ },
97
+ )
98
+
99
+ const slugs = (data["slugs_INTERNAL"] as string[]) || []
100
+ const uid = data["uid"] as string | undefined
101
+
102
+ return {
103
+ widgets,
104
+ types,
105
+ positions,
106
+ uid,
107
+ slugs,
108
+ }
109
+ },
52
110
  }
53
111
 
54
112
  export default DocumentData
@@ -4,8 +4,8 @@ import * as t from "io-ts"
4
4
 
5
5
  import type { EmptyContent } from "./EmptyContent"
6
6
  import BooleanContent from "./nestable/BooleanContent"
7
- import EmbedContent from "./nestable/EmbedContent"
8
- import FieldContent from "./nestable/FieldContent"
7
+ import { EmbedContent, EmbedContentO } from "./nestable/EmbedContent"
8
+ import FieldContent, { FieldType } from "./nestable/FieldContent"
9
9
  import { GeoPointContent, GeoPointContentO } from "./nestable/GeoPointContent"
10
10
  import { ImageContent, ImageContentO } from "./nestable/ImageContent"
11
11
  import IntegrationFieldsContent from "./nestable/IntegrationFieldsContent"
@@ -34,7 +34,7 @@ export type NonEmptySimpleWidgetContent =
34
34
  | StructuredTextContent
35
35
  | ImageContentO
36
36
  | GeoPointContentO
37
- | EmbedContent
37
+ | EmbedContentO
38
38
  | LinkContent
39
39
  | UIDContent
40
40
  | SeparatorContent
@@ -84,7 +84,7 @@ export const SimpleWidgetContent = {
84
84
  return O.fromEither(BooleanContent.decode(content))
85
85
  default:
86
86
  if (FieldContent.types.includes(type)) {
87
- return FieldContent.forType(type, content)
87
+ return FieldContent.forType(type as FieldType, content)
88
88
  } else {
89
89
  return O.none
90
90
  }
@@ -22,7 +22,7 @@ export const WidgetTypes = {
22
22
  UID: UIDContentType,
23
23
  Group: GroupContentType,
24
24
  slices: SlicesContentType,
25
- }
25
+ } as const
26
26
 
27
27
  export type WidgetKey = string
28
28
  export type WidgetContent = SlicesContent | StaticWidgetContent
@@ -7,13 +7,17 @@ import { addType } from "../../../validators/function"
7
7
 
8
8
  export const EmbedContentType = "EmbedContent"
9
9
 
10
- type EmbedContent = t.OutputOf<typeof EmbedContentC> & {
10
+ export type EmbedContent = t.TypeOf<typeof EmbedContentC> & {
11
11
  all: unknown
12
12
  }
13
13
 
14
- const EmbedContent = new t.Type<EmbedContent, unknown, unknown>(
14
+ export type EmbedContentO = t.OutputOf<typeof EmbedContentC> & {
15
+ all: unknown
16
+ }
17
+
18
+ export const EmbedContent = new t.Type<EmbedContentO, unknown, unknown>(
15
19
  "EmbedContent",
16
- (u): u is EmbedContent => (u as EmbedContent).__TYPE__ === EmbedContentType,
20
+ (u): u is EmbedContentO => (u as EmbedContentO).__TYPE__ === EmbedContentType,
17
21
  (u) => {
18
22
  return pipe(
19
23
  EmbedContentC.decode(u),
@@ -23,7 +27,7 @@ const EmbedContent = new t.Type<EmbedContent, unknown, unknown>(
23
27
  })),
24
28
  )
25
29
  },
26
- (ec: EmbedContent) => EmbedContentC.encode(ec),
30
+ (ec: EmbedContentO) => EmbedContentC.encode(ec),
27
31
  )
28
32
 
29
33
  const EmbedContentC = addType(
@@ -50,5 +54,3 @@ const EmbedContentC = addType(
50
54
  ),
51
55
  EmbedContentType,
52
56
  )
53
-
54
- export default EmbedContent
@@ -2,10 +2,18 @@ import { pipe } from "fp-ts/function"
2
2
  import * as O from "fp-ts/Option"
3
3
  import * as t from "io-ts"
4
4
 
5
+ export type FieldType =
6
+ | "Text"
7
+ | "Date"
8
+ | "Timestamp"
9
+ | "Color"
10
+ | "Number"
11
+ | "Range"
12
+ | "Select"
5
13
  export const FieldContentType = "FieldContent"
6
14
  type FieldContent = {
7
15
  value: string
8
- type: string
16
+ type: FieldType
9
17
  __TYPE__: typeof FieldContentType
10
18
  }
11
19
 
@@ -28,7 +36,7 @@ function trimScalaStyle(s: string): string {
28
36
 
29
37
  const FieldContent = {
30
38
  types: ["Text", "Date", "Timestamp", "Color", "Number", "Range", "Select"],
31
- forType: (type: string, value: unknown): O.Option<FieldContent> => {
39
+ forType: (type: FieldType, value: unknown): O.Option<FieldContent> => {
32
40
  return pipe(
33
41
  O.fromEither(t.string.decode(value)),
34
42
  O.map((r) => {
@@ -30,4 +30,4 @@ export const LinksTypes = {
30
30
  ExternalLink: ExternalLinkType,
31
31
  ImageLink: ImageLinkType,
32
32
  LinkContent: LinkContentType,
33
- }
33
+ } as const
@@ -3,7 +3,7 @@ import * as t from "io-ts"
3
3
 
4
4
  import { StringOrNull } from "../../../../validators"
5
5
  import { nullable, refineType } from "../../../../validators/function"
6
- import EmbedContent from "../EmbedContent"
6
+ import { EmbedContent } from "../EmbedContent"
7
7
  import { ImageContentView } from "../ImageContent"
8
8
  import { Link } from "../Link"
9
9
 
@@ -9,7 +9,7 @@ import { SeparatorContentType } from "./SeparatorContent"
9
9
  import { StructuredTextContentType } from "./StructuredTextContent"
10
10
 
11
11
  export { default as BooleanContent } from "./BooleanContent"
12
- export { default as EmbedContent } from "./EmbedContent"
12
+ export * from "./EmbedContent"
13
13
  export { default as FieldContent } from "./FieldContent"
14
14
  export { type GeoPointContentO, GeoPointContent } from "./GeoPointContent"
15
15
  export {
@@ -32,4 +32,4 @@ export const NestableTypes = {
32
32
  Image: ImageContentType,
33
33
  IntegrationFields: IntegrationFieldsContentType,
34
34
  Separator: SeparatorContentType,
35
- }
35
+ } as const