@prismicio/types-internal 0.3.0 → 0.3.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.
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Slices = exports.DynamicSlices = exports.StaticSlices = exports.slicesReader = exports.DynamicSlicesConfig = exports.StaticSlicesConfig = exports.slicesConfigReader = exports.SlicesLabels = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const t = (0, tslib_1.__importStar)(require("io-ts"));
6
+ const widgets_1 = require("../../../documents/widgets");
6
7
  const validators_1 = require("../../../validators");
7
8
  const WidgetTypes_1 = (0, tslib_1.__importDefault)(require("../WidgetTypes"));
8
9
  const CompositeSlice_1 = (0, tslib_1.__importDefault)(require("./CompositeSlice"));
@@ -25,7 +26,7 @@ function slicesConfigReader(codec) {
25
26
  return t.exact(t.partial({
26
27
  label: validators_1.StringOrNull,
27
28
  labels: exports.SlicesLabels,
28
- choices: t.record(t.string, t.union([LegacySlice_1.default, CompositeSlice_1.default, codec])),
29
+ choices: t.record(widgets_1.WidgetKey, t.union([LegacySlice_1.default, CompositeSlice_1.default, codec])),
29
30
  }));
30
31
  }
31
32
  exports.slicesConfigReader = slicesConfigReader;
@@ -1,4 +1,5 @@
1
- import { SlicesContent } from "./slices/SlicesContent";
1
+ import * as t from "io-ts";
2
+ import { SlicesContent } from "./slices";
2
3
  import StaticWidgetContent from "./StaticWidgetContent";
3
4
  export * from "./EmptyContent";
4
5
  export * from "./GroupContent";
@@ -28,7 +29,8 @@ export declare const WidgetTypes: {
28
29
  readonly IntegrationFields: "IntegrationFieldsContent";
29
30
  readonly Separator: "SeparatorContent";
30
31
  };
31
- export declare type WidgetKey = string;
32
+ export declare const WidgetKey: t.Type<string, string, unknown>;
33
+ export declare type WidgetKey = t.TypeOf<typeof WidgetKey>;
32
34
  export declare type WidgetContent = SlicesContent | StaticWidgetContent;
33
35
  export declare const Widget: {
34
36
  fromJson(widgetKey: WidgetKey, widgetValue: unknown, widgetTypes: Map<WidgetKey, string>, widgetPositions: Map<WidgetKey, number>): import("fp-ts/lib/Option").None | import("fp-ts/lib/Option").Some<StaticWidgetContent> | import("fp-ts/lib/Option").Some<SlicesContent>;
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Widget = exports.WidgetTypes = exports.StaticWidgetContent = exports.Slices = exports.Nestable = void 0;
3
+ exports.Widget = exports.WidgetKey = exports.WidgetTypes = exports.StaticWidgetContent = exports.Slices = exports.Nestable = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
6
+ const function_1 = require("../../validators/function");
5
7
  const EmptyContent_1 = require("./EmptyContent");
6
8
  const GroupContent_1 = require("./GroupContent");
7
9
  const nestable_1 = require("./nestable");
8
- const SlicesContent_1 = require("./slices/SlicesContent");
10
+ const slices_1 = require("./slices");
9
11
  const StaticWidgetContent_1 = (0, tslib_1.__importDefault)(require("./StaticWidgetContent"));
10
12
  const UIDContent_1 = require("./UIDContent");
11
13
  (0, tslib_1.__exportStar)(require("./EmptyContent"), exports);
@@ -21,13 +23,15 @@ exports.WidgetTypes = {
21
23
  Empty: EmptyContent_1.EmptyContentType,
22
24
  UID: UIDContent_1.UIDContentType,
23
25
  Group: GroupContent_1.GroupContentType,
24
- slices: SlicesContent_1.SlicesContentType,
26
+ slices: slices_1.SlicesContentType,
25
27
  };
28
+ const widgetKeyRegex = new RegExp("^[^<>]+$");
29
+ exports.WidgetKey = (0, function_1.refineType)(t.string, "WidgetKey", (s) => widgetKeyRegex.test(s));
26
30
  exports.Widget = {
27
31
  fromJson(widgetKey, widgetValue, widgetTypes, widgetPositions) {
28
32
  const fieldType = widgetTypes.get(widgetKey);
29
33
  if (fieldType === "Slices") {
30
- return SlicesContent_1.SlicesContent.fromJson(widgetKey, widgetValue, widgetTypes, widgetPositions);
34
+ return slices_1.SlicesContent.fromJson(widgetKey, widgetValue, widgetTypes, widgetPositions);
31
35
  }
32
36
  else {
33
37
  return StaticWidgetContent_1.default.fromJson([], widgetKey, widgetValue, widgetTypes, widgetPositions);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/types-internal",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Prismic types for Custom Types and Prismic Data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -38,7 +38,7 @@ function customTypeReader<T extends StaticSection | DynamicSection>(
38
38
  id: t.string,
39
39
  label: StringOrNull,
40
40
  repeatable: withFallback(t.boolean, true),
41
- json: t.record(t.string, codec),
41
+ json: t.record(t.string, codec), //tab name => tab data
42
42
  status: withFallback(t.boolean, true),
43
43
  }),
44
44
  t.partial({
@@ -1,12 +1,13 @@
1
1
  import * as t from "io-ts"
2
2
 
3
- import type { SharedSlice } from "./widgets/slices/SharedSlice"
3
+ import { WidgetKey } from "../documents/widgets"
4
+ import type { SharedSlice } from "./widgets/slices"
4
5
  import { DynamicWidget, StaticWidget, Widgets } from "./widgets/Widget"
5
6
 
6
7
  export function sectionReader<T extends StaticWidget | DynamicWidget>(
7
8
  codec: t.Type<T, unknown>,
8
9
  ) {
9
- return t.record(t.string, codec)
10
+ return t.record(WidgetKey, codec) // WidgetId -> Widget Data
10
11
  }
11
12
 
12
13
  export const StaticSection = sectionReader(StaticWidget)
@@ -1,5 +1,6 @@
1
1
  import * as t from "io-ts"
2
2
 
3
+ import { WidgetKey } from "../../documents/widgets"
3
4
  import { StringOrNull } from "../../validators"
4
5
  import NestableWidget from "./nestable/NestableWidget"
5
6
  import WidgetTypes from "./WidgetTypes"
@@ -8,7 +9,7 @@ const GroupConfig = t.exact(
8
9
  t.partial({
9
10
  label: StringOrNull,
10
11
  repeat: t.boolean,
11
- fields: t.record(t.string, NestableWidget),
12
+ fields: t.record(WidgetKey, NestableWidget),
12
13
  }),
13
14
  )
14
15
  type GroupConfig = t.TypeOf<typeof GroupConfig>
@@ -1,5 +1,6 @@
1
1
  import * as t from "io-ts"
2
2
 
3
+ import { WidgetKey } from "../../../documents/widgets"
3
4
  import { StringOrNull } from "../../../validators"
4
5
  import NestableWidget from "../nestable/NestableWidget"
5
6
  import SlicesTypes from "./SlicesTypes"
@@ -21,8 +22,8 @@ const CompositeSlice = t.exact(
21
22
  description: t.string,
22
23
  icon: t.string,
23
24
  display: t.string,
24
- "non-repeat": t.record(t.string, NestableWidget),
25
- repeat: t.record(t.string, NestableWidget),
25
+ "non-repeat": t.record(WidgetKey, NestableWidget),
26
+ repeat: t.record(WidgetKey, NestableWidget),
26
27
  config: CompositeSliceConfig,
27
28
  }),
28
29
  ]),
@@ -1,6 +1,7 @@
1
1
  import * as t from "io-ts"
2
2
  import { withFallback } from "io-ts-types/lib/withFallback"
3
3
 
4
+ import { WidgetKey } from "../../../documents/widgets"
4
5
  import NestableWidget from "../nestable/NestableWidget"
5
6
  import SlicesTypes from "./SlicesTypes"
6
7
 
@@ -19,8 +20,8 @@ export const Variation = t.exact(
19
20
  }),
20
21
  t.partial({
21
22
  display: t.string,
22
- primary: t.record(t.string, NestableWidget),
23
- items: t.record(t.string, NestableWidget),
23
+ primary: t.record(WidgetKey, NestableWidget),
24
+ items: t.record(WidgetKey, NestableWidget),
24
25
  }),
25
26
  ]),
26
27
  )
@@ -1,5 +1,6 @@
1
1
  import * as t from "io-ts"
2
2
 
3
+ import { WidgetKey } from "../../../documents/widgets"
3
4
  import { StringOrNull } from "../../../validators"
4
5
  import WidgetTypes from "../WidgetTypes"
5
6
  import CompositeSlice from "./CompositeSlice"
@@ -36,7 +37,7 @@ export function slicesConfigReader<T extends SharedSlice | SharedSliceRef>(
36
37
  label: StringOrNull,
37
38
  labels: SlicesLabels,
38
39
  choices: t.record(
39
- t.string,
40
+ WidgetKey,
40
41
  t.union([LegacySlice, CompositeSlice, codec]),
41
42
  ),
42
43
  }),
@@ -1,7 +1,10 @@
1
+ import * as t from "io-ts"
2
+
3
+ import { refineType } from "../../validators/function"
1
4
  import { EmptyContentType } from "./EmptyContent"
2
5
  import { GroupContentType } from "./GroupContent"
3
6
  import { NestableTypes } from "./nestable"
4
- import { SlicesContent, SlicesContentType } from "./slices/SlicesContent"
7
+ import { SlicesContent, SlicesContentType } from "./slices"
5
8
  import StaticWidgetContent from "./StaticWidgetContent"
6
9
  import { UIDContentType } from "./UIDContent"
7
10
 
@@ -24,7 +27,12 @@ export const WidgetTypes = {
24
27
  slices: SlicesContentType,
25
28
  } as const
26
29
 
27
- export type WidgetKey = string
30
+ const widgetKeyRegex = new RegExp("^[^<>]+$")
31
+ export const WidgetKey = refineType(t.string, "WidgetKey", (s: string) =>
32
+ widgetKeyRegex.test(s),
33
+ )
34
+ export type WidgetKey = t.TypeOf<typeof WidgetKey>
35
+
28
36
  export type WidgetContent = SlicesContent | StaticWidgetContent
29
37
 
30
38
  export const Widget = {
@@ -1,4 +0,0 @@
1
- export declare enum Format {
2
- Static = "static",
3
- Dynamic = "dynamic"
4
- }
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Format = void 0;
4
- var Format;
5
- (function (Format) {
6
- Format["Static"] = "static";
7
- Format["Dynamic"] = "dynamic";
8
- })(Format = exports.Format || (exports.Format = {}));