@prismicio/types-internal
Advanced tools
Comparing version 0.2.6 to 0.2.7
@@ -7,3 +7,12 @@ import * as O from "fp-ts/lib/Option"; | ||
fromJson(widgets: Map<WidgetKey, unknown>, widgetTypes: Map<WidgetKey, string>, widgetPositions: Map<WidgetKey, number>): DocumentData; | ||
partitionData(data: { | ||
[p: string]: unknown; | ||
}): { | ||
types: Map<string, string>; | ||
positions: Map<string, number>; | ||
widgets: Map<WidgetKey, unknown>; | ||
slugs: ReadonlyArray<string>; | ||
uid: string | undefined; | ||
}; | ||
}; | ||
export default DocumentData; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const Either_1 = require("fp-ts/lib/Either"); | ||
const O = (0, tslib_1.__importStar)(require("fp-ts/lib/Option")); | ||
const t = (0, tslib_1.__importStar)(require("io-ts")); | ||
const widgets_1 = require("./widgets"); | ||
@@ -27,3 +29,43 @@ function computeWidget(key, widgets, widgetTypes, widgetPositions) { | ||
}, | ||
partitionData(data) { | ||
const fields = Object.entries(data); | ||
const { types, positions, widgets } = fields.reduce((acc, [k, v]) => { | ||
if (k.endsWith("_TYPE")) { | ||
const decodedValue = t.string.decode(v); | ||
if ((0, Either_1.isRight)(decodedValue)) { | ||
return { | ||
...acc, | ||
types: acc.types.set(k.substring(0, k.length - 5), decodedValue.right), | ||
}; | ||
} | ||
} | ||
if (k.endsWith("_POSITION") && typeof v === "number") { | ||
return { | ||
...acc, | ||
positions: acc.positions.set(k.substring(0, k.length - 9), v), | ||
}; | ||
} | ||
if (!k.endsWith("_POSITION") && !k.endsWith("_TYPE")) { | ||
return { | ||
...acc, | ||
widgets: acc.widgets.set(k, v), | ||
}; | ||
} | ||
return acc; | ||
}, { | ||
types: new Map(), | ||
positions: new Map(), | ||
widgets: new Map(), | ||
}); | ||
const slugs = data["slugs_INTERNAL"] || []; | ||
const uid = data["uid"]; | ||
return { | ||
widgets, | ||
types, | ||
positions, | ||
uid, | ||
slugs, | ||
}; | ||
}, | ||
}; | ||
exports.default = DocumentData; |
{ | ||
"name": "@prismicio/types-internal", | ||
"version": "0.2.6", | ||
"version": "0.2.7", | ||
"description": "Prismic types for Custom Types and Prismic Data", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -0,2 +1,4 @@ | ||
import { isRight } from "fp-ts/lib/Either" | ||
import * as O from "fp-ts/lib/Option" | ||
import * as t from "io-ts" | ||
@@ -52,4 +54,60 @@ import { type WidgetContent, type WidgetKey, Widget } from "./widgets" | ||
}, | ||
partitionData(data: { [p: string]: unknown }): { | ||
types: Map<string, string> | ||
positions: Map<string, number> | ||
widgets: Map<WidgetKey, unknown> | ||
slugs: ReadonlyArray<string> | ||
uid: string | undefined | ||
} { | ||
const fields: [string, unknown][] = Object.entries(data) | ||
const { types, positions, widgets } = fields.reduce( | ||
(acc, [k, v]) => { | ||
if (k.endsWith("_TYPE")) { | ||
const decodedValue = t.string.decode(v) | ||
if (isRight(decodedValue)) { | ||
return { | ||
...acc, | ||
types: acc.types.set( | ||
k.substring(0, k.length - 5), | ||
decodedValue.right, | ||
), | ||
} | ||
} | ||
} | ||
if (k.endsWith("_POSITION") && typeof v === "number") { | ||
return { | ||
...acc, | ||
positions: acc.positions.set(k.substring(0, k.length - 9), v), | ||
} | ||
} | ||
if (!k.endsWith("_POSITION") && !k.endsWith("_TYPE")) { | ||
return { | ||
...acc, | ||
widgets: acc.widgets.set(k, v), | ||
} | ||
} | ||
return acc | ||
}, | ||
{ | ||
types: new Map<string, string>(), | ||
positions: new Map<string, number>(), | ||
widgets: new Map<string, unknown>(), | ||
}, | ||
) | ||
const slugs = (data["slugs_INTERNAL"] as string[]) || [] | ||
const uid = data["uid"] as string | undefined | ||
return { | ||
widgets, | ||
types, | ||
positions, | ||
uid, | ||
slugs, | ||
} | ||
}, | ||
} | ||
export default DocumentData |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1246631
24542