@prismicio/types-internal 2.2.0-alpha.23 → 2.2.0-alpha.24

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.
@@ -10,8 +10,8 @@ const ImportContent = (type, valueCodec) => new t.Type("ImportField", (u) => {
10
10
  if (!(0, Objects_1.isObject)(u))
11
11
  return false;
12
12
  return type === u["type"] && valueCodec.is(u["value"]);
13
- }, (u) => {
14
- return (0, function_1.pipe)(valueCodec.decode(u), fp_ts_1.either.map((decodedValue) => {
13
+ }, (u, c) => {
14
+ return (0, function_1.pipe)(valueCodec.validate(u, c), fp_ts_1.either.map((decodedValue) => {
15
15
  return {
16
16
  type,
17
17
  value: decodedValue,
@@ -14,7 +14,7 @@ const ImportSlices = (staticSlices) => {
14
14
  // For now we only support the SharedSlice, however if we want to support more in the future
15
15
  // we would have to change the codec here to something like this: t.array(t.union([ImportSharedSlice(sharedSlices), NewSliceCodec(newSliceCustomTypes)])).
16
16
  const SlicesArrayCodec = t.array((0, SharedSlice_1.SharedSlice)(supportedSlices));
17
- return (0, ImportContent_1.ImportContent)("Slices", (0, validators_1.EmptyObjectOrElse)(new t.Type("ImportSlices", (u) => SlicesArrayCodec.is(u), (u, c) => {
17
+ return (0, ImportContent_1.ImportContent)("Slices", (0, validators_1.EmptyArrayOrElse)(new t.Type("ImportSlices", (u) => SlicesArrayCodec.is(u), (u, c) => {
18
18
  return (0, function_1.pipe)(SlicesArrayCodec.validate(u, c), E.chain((slices) => {
19
19
  // This part might not make sense for all Slice types in the future, but for now we only support the SharedSlice
20
20
  // In case we support more in the future, we would have to filter only the relevant type for this check
@@ -58,8 +58,8 @@ const SharedSliceContentEntry = (sliceName, sliceContentField, sliceFieldModels)
58
58
  ]), E.mapLeft((errors) => errors.map((error) => {
59
59
  const context = [
60
60
  ...c,
61
- ...error.context.filter(({ key }) => !!key),
62
61
  { key, actual: content, type: codec },
62
+ ...error.context.slice(1), // We ignore the first context element with "" key coming from ImportNestable decoder
63
63
  ];
64
64
  const updatedError = { ...error, context };
65
65
  return updatedError;
@@ -6,10 +6,10 @@ const Either_1 = require("fp-ts/lib/Either");
6
6
  const t = (0, tslib_1.__importStar)(require("io-ts"));
7
7
  const BasicTypes_1 = require("./BasicTypes");
8
8
  const DefaultOrElse = (inputValidator) => {
9
- return (codec) => new t.Type("DefaultOrElse", (u) => null === u || codec.is(u), (u) => {
10
- if ((0, Either_1.isRight)(inputValidator.decode(u)))
9
+ return (codec) => new t.Type("DefaultOrElse", (u) => null === u || codec.is(u), (u, c) => {
10
+ if ((0, Either_1.isRight)(inputValidator.validate(u, c)))
11
11
  return t.success(null);
12
- return codec.decode(u);
12
+ return codec.validate(u, c);
13
13
  }, (chunk) => (chunk ? codec.encode(chunk) : undefined));
14
14
  };
15
15
  exports.DefaultOrElse = DefaultOrElse;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/types-internal",
3
- "version": "2.2.0-alpha.23",
3
+ "version": "2.2.0-alpha.24",
4
4
  "description": "Prismic types for Custom Types and Prismic Data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -15,9 +15,9 @@ export const ImportContent = <T extends FieldType, A, O = A>(
15
15
  if (!isObject(u)) return false
16
16
  return type === u["type"] && valueCodec.is(u["value"])
17
17
  },
18
- (u: unknown) => {
18
+ (u: unknown, c) => {
19
19
  return pipe(
20
- valueCodec.decode(u),
20
+ valueCodec.validate(u, c),
21
21
  either.map((decodedValue) => {
22
22
  return {
23
23
  type,
@@ -3,7 +3,7 @@ import { pipe } from "fp-ts/function"
3
3
  import * as t from "io-ts"
4
4
 
5
5
  import type { StaticSlices } from "../../../../customtypes"
6
- import { EmptyObjectOrElse } from "../../../../validators"
6
+ import { EmptyArrayOrElse } from "../../../../validators"
7
7
  import { ImportContent } from "../ImportContent"
8
8
  import { SharedSlice } from "./SharedSlice"
9
9
  import {
@@ -20,7 +20,7 @@ export const ImportSlices = (staticSlices: StaticSlices) => {
20
20
 
21
21
  return ImportContent(
22
22
  "Slices",
23
- EmptyObjectOrElse(
23
+ EmptyArrayOrElse(
24
24
  new t.Type<SharedSlice[]>(
25
25
  "ImportSlices",
26
26
  (u): u is SharedSlice[] => SlicesArrayCodec.is(u),
@@ -83,8 +83,8 @@ export const SharedSliceContentEntry = (
83
83
  errors.map((error) => {
84
84
  const context = [
85
85
  ...c,
86
- ...error.context.filter(({ key }) => !!key), // We replace the "" key coming from ImportNestable decoder
87
86
  { key, actual: content, type: codec },
87
+ ...error.context.slice(1), // We ignore the first context element with "" key coming from ImportNestable decoder
88
88
  ]
89
89
 
90
90
  const updatedError: t.ValidationError = { ...error, context }
@@ -8,9 +8,9 @@ export const DefaultOrElse = <I, A, O = A>(inputValidator: t.Type<I>) => {
8
8
  new t.Type<A | null, O | undefined>(
9
9
  "DefaultOrElse",
10
10
  (u: unknown): u is A | null => null === u || codec.is(u),
11
- (u: unknown) => {
12
- if (isRight(inputValidator.decode(u))) return t.success(null)
13
- return codec.decode(u)
11
+ (u: unknown, c) => {
12
+ if (isRight(inputValidator.validate(u, c))) return t.success(null)
13
+ return codec.validate(u, c)
14
14
  },
15
15
  (chunk) => (chunk ? codec.encode(chunk) : undefined),
16
16
  )