MCPcopy Create free account
hub / github.com/Effect-TS/effect / Redacted

Function Redacted

packages/effect/src/Schema.ts:16818–16891  ·  view source on GitHub ↗
(value: S, options?: {
  readonly label?: string | undefined
  readonly disallowJsonEncode?: boolean | undefined
})

Source from the content-addressed store, hash-verified

16816 * @since 3.10.0
16817 */
16818export function Redacted<S extends Constraint>(value: S, options?: {
16819 readonly label?: string | undefined
16820 readonly disallowJsonEncode?: boolean | undefined
16821}): Redacted<S> {
16822 const label = typeof options?.label === "string" ? options.label : undefined
16823 const disallowJsonEncode = options?.disallowJsonEncode === true
16824 const normalizedOptions: NormalizedRedactedOptions | undefined = label !== undefined
16825 ? disallowJsonEncode ? { label, disallowJsonEncode: true } : { label }
16826 : disallowJsonEncode
16827 ? { disallowJsonEncode: true }
16828 : undefined
16829 const decodeLabel = label !== undefined
16830 ? SchemaParser.decodeUnknownEffect(Literal(label))
16831 : undefined
16832 const schema = declareConstructor<Redacted_.Redacted<S["Type"]>, Redacted_.Redacted<S["Encoded"]>>()(
16833 [value],
16834 ([value]) => (input, ast, poptions) => {
16835 if (Redacted_.isRedacted(input)) {
16836 const label: Effect.Effect<void, SchemaIssue.Issue, never> = decodeLabel !== undefined
16837 ? Effect.mapErrorEager(
16838 decodeLabel(input.label, poptions),
16839 (issue) => new SchemaIssue.Pointer(["label"], issue)
16840 )
16841 : Effect.void
16842 return Effect.flatMapEager(
16843 label,
16844 () =>
16845 Effect.mapBothEager(
16846 SchemaParser.decodeUnknownEffect(value)(Redacted_.value(input), poptions),
16847 {
16848 onSuccess: (value) => Redacted_.make(value, { label: input.label }),
16849 onFailure: () => {
16850 return new SchemaIssue.Composite(
16851 ast,
16852 [
16853 new SchemaIssue.Pointer(
16854 ["value"],
16855 new SchemaIssue.InvalidValue(undefined, input, poptions)
16856 )
16857 ],
16858 input,
16859 poptions
16860 )
16861 }
16862 }
16863 )
16864 )
16865 }
16866 return Effect.fail(new SchemaIssue.InvalidType(ast, input, poptions))
16867 },
16868 {
16869 representation: {
16870 id: "effect/schema/Redacted",
16871 payload: normalizedOptions ?? null
16872 },
16873 expected: "Redacted",
16874 toCodecJson: ([value]) =>
16875 link<Redacted_.Redacted<S["Encoded"]>>()(

Callers 1

RedactedFromValueFunction · 0.70

Calls 8

LiteralFunction · 0.70
declareConstructorFunction · 0.70
linkFunction · 0.70
makeFunction · 0.70
makeMethod · 0.65
failMethod · 0.65
transformMethod · 0.65
valueMethod · 0.45

Tested by

no test coverage detected