| 10093 | * @since 3.10.0 |
| 10094 | */ |
| 10095 | export function Redacted<S extends Constraint>(value: S, options?: { |
| 10096 | readonly label?: string | undefined |
| 10097 | readonly disallowJsonEncode?: boolean | undefined |
| 10098 | }): Redacted<S> { |
| 10099 | const label = typeof options?.label === "string" ? options.label : undefined |
| 10100 | const disallowJsonEncode = options?.disallowJsonEncode === true |
| 10101 | const normalizedOptions: NormalizedRedactedOptions | undefined = label !== undefined |
| 10102 | ? disallowJsonEncode ? { label, disallowJsonEncode: true } : { label } |
| 10103 | : disallowJsonEncode |
| 10104 | ? { disallowJsonEncode: true } |
| 10105 | : undefined |
| 10106 | const decodeLabel = label !== undefined |
| 10107 | ? SchemaParser.decodeUnknownEffect(Literal(label)) |
| 10108 | : undefined |
| 10109 | const schema = declareConstructor<Redacted_.Redacted<S["Type"]>, Redacted_.Redacted<S["Encoded"]>>()( |
| 10110 | [value], |
| 10111 | ([value]) => (input, ast, poptions) => { |
| 10112 | if (Redacted_.isRedacted(input)) { |
| 10113 | const label: Effect.Effect<void, SchemaIssue.Issue, never> = decodeLabel !== undefined |
| 10114 | ? Effect.mapErrorEager( |
| 10115 | decodeLabel(input.label, poptions), |
| 10116 | (issue) => new SchemaIssue.Pointer(["label"], issue) |
| 10117 | ) |
| 10118 | : Effect.void |
| 10119 | return Effect.flatMapEager( |
| 10120 | label, |
| 10121 | () => |
| 10122 | Effect.mapBothEager( |
| 10123 | SchemaParser.decodeUnknownEffect(value)(Redacted_.value(input), poptions), |
| 10124 | { |
| 10125 | onSuccess: () => input, |
| 10126 | onFailure: (/** ignore the issue because of security reasons */) => { |
| 10127 | return new SchemaIssue.Composite( |
| 10128 | ast, |
| 10129 | [ |
| 10130 | new SchemaIssue.Pointer( |
| 10131 | ["value"], |
| 10132 | new SchemaIssue.InvalidValue(undefined, input, poptions) |
| 10133 | ) |
| 10134 | ], |
| 10135 | input, |
| 10136 | poptions |
| 10137 | ) |
| 10138 | } |
| 10139 | } |
| 10140 | ) |
| 10141 | ) |
| 10142 | } |
| 10143 | return Effect.fail(new SchemaIssue.InvalidType(ast, input, poptions)) |
| 10144 | }, |
| 10145 | { |
| 10146 | representation: { |
| 10147 | id: "effect/schema/Redacted", |
| 10148 | payload: normalizedOptions ?? null |
| 10149 | }, |
| 10150 | toCode: ({ typeParameters }) => ({ |
| 10151 | runtime: normalizedOptions !== undefined |
| 10152 | ? `Schema.Redacted(${typeParameters[0].runtime}, ${format(normalizedOptions)})` |