@r_masseater/masseater-utils 0.1.3 → 0.1.5
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.
- package/dist/plugin-kit.d.mts +48 -19
- package/dist/plugin-kit.mjs +466 -10
- package/dist/plugin-kit.mjs.map +1 -1
- package/package.json +3 -3
package/dist/plugin-kit.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Record, String as String$1, Unknown, decodeOption, fromJsonString, is } from "effect/Schema";
|
|
2
1
|
// ../../node_modules/.pnpm/effect@4.1.7/node_modules/effect/dist/Pipeable.js
|
|
3
2
|
/**
|
|
4
3
|
* The `Pipeable` module defines the shared interface and implementation helpers
|
|
@@ -1177,6 +1176,73 @@ function isNumber(input) {
|
|
|
1177
1176
|
return typeof input === "number";
|
|
1178
1177
|
}
|
|
1179
1178
|
/**
|
|
1179
|
+
* Checks whether a value is a `symbol`.
|
|
1180
|
+
*
|
|
1181
|
+
* **When to use**
|
|
1182
|
+
*
|
|
1183
|
+
* Use when you need a `Predicate` guard to narrow an `unknown` value to a
|
|
1184
|
+
* symbol.
|
|
1185
|
+
*
|
|
1186
|
+
* **Details**
|
|
1187
|
+
*
|
|
1188
|
+
* Uses `typeof input === "symbol"`.
|
|
1189
|
+
*
|
|
1190
|
+
* **Example** (Guarding symbols)
|
|
1191
|
+
*
|
|
1192
|
+
* ```ts import.meta.vitest
|
|
1193
|
+
* import { Predicate } from "effect"
|
|
1194
|
+
*
|
|
1195
|
+
* const data: unknown = Symbol.for("id")
|
|
1196
|
+
*
|
|
1197
|
+
* if (Predicate.isSymbol(data)) {
|
|
1198
|
+
* data.description // => "id"
|
|
1199
|
+
* }
|
|
1200
|
+
* ```
|
|
1201
|
+
*
|
|
1202
|
+
* @see {@link isPropertyKey}
|
|
1203
|
+
* @stability stable
|
|
1204
|
+
* @category guards
|
|
1205
|
+
* @since 2.0.0
|
|
1206
|
+
*/
|
|
1207
|
+
function isSymbol(input) {
|
|
1208
|
+
return typeof input === "symbol";
|
|
1209
|
+
}
|
|
1210
|
+
/**
|
|
1211
|
+
* Checks whether a value is a valid `PropertyKey` (string, number, or symbol).
|
|
1212
|
+
*
|
|
1213
|
+
* **When to use**
|
|
1214
|
+
*
|
|
1215
|
+
* Use when you need a `Predicate` guard for unknown property keys before
|
|
1216
|
+
* indexing.
|
|
1217
|
+
*
|
|
1218
|
+
* **Details**
|
|
1219
|
+
*
|
|
1220
|
+
* Uses `isString`, `isNumber`, and `isSymbol`.
|
|
1221
|
+
*
|
|
1222
|
+
* **Example** (Guarding property keys)
|
|
1223
|
+
*
|
|
1224
|
+
* ```ts import.meta.vitest
|
|
1225
|
+
* import { Predicate } from "effect"
|
|
1226
|
+
*
|
|
1227
|
+
* const key: unknown = "name"
|
|
1228
|
+
* const obj: Record<PropertyKey, unknown> = { name: "Ada" }
|
|
1229
|
+
*
|
|
1230
|
+
* if (Predicate.isPropertyKey(key) && key in obj) {
|
|
1231
|
+
* obj[key] // => "Ada"
|
|
1232
|
+
* }
|
|
1233
|
+
* ```
|
|
1234
|
+
*
|
|
1235
|
+
* @see {@link isString}
|
|
1236
|
+
* @see {@link isNumber}
|
|
1237
|
+
* @see {@link isSymbol}
|
|
1238
|
+
* @stability stable
|
|
1239
|
+
* @category guards
|
|
1240
|
+
* @since 4.0.0
|
|
1241
|
+
*/
|
|
1242
|
+
function isPropertyKey(u) {
|
|
1243
|
+
return isString$1(u) || isNumber(u) || isSymbol(u);
|
|
1244
|
+
}
|
|
1245
|
+
/**
|
|
1180
1246
|
* Checks whether a value is a `function`.
|
|
1181
1247
|
*
|
|
1182
1248
|
* **When to use**
|
|
@@ -2577,7 +2643,7 @@ function make$12(compare) {
|
|
|
2577
2643
|
* @category instances
|
|
2578
2644
|
* @since 4.0.0
|
|
2579
2645
|
*/
|
|
2580
|
-
const String$
|
|
2646
|
+
const String$5 = /*#__PURE__*/ make$12((self, that) => self < that ? -1 : 1);
|
|
2581
2647
|
// ../../node_modules/.pnpm/effect@4.1.7/node_modules/effect/dist/Option.js
|
|
2582
2648
|
/**
|
|
2583
2649
|
* Creates an `Option` representing the absence of a value.
|
|
@@ -4631,6 +4697,18 @@ const failCauseSync$1 = (evaluate) => suspend$1(() => failCause$2(evaluate()));
|
|
|
4631
4697
|
const die$2 = (defect) => exitDie(defect);
|
|
4632
4698
|
/** @internal */
|
|
4633
4699
|
const void_$1 = /*#__PURE__*/ succeed$3(void 0);
|
|
4700
|
+
/** @internal */
|
|
4701
|
+
const try_$1 = (options) => {
|
|
4702
|
+
const evaluate = typeof options === "function" ? options : options.try;
|
|
4703
|
+
const catcher = typeof options === "function" ? (cause) => new UnknownError(cause, "An error occurred in Effect.try") : options.catch;
|
|
4704
|
+
return suspend$1(() => {
|
|
4705
|
+
try {
|
|
4706
|
+
return succeed$3(evaluate());
|
|
4707
|
+
} catch (err) {
|
|
4708
|
+
return fail$3(catcher(err));
|
|
4709
|
+
}
|
|
4710
|
+
});
|
|
4711
|
+
};
|
|
4634
4712
|
const callbackOptions = /*#__PURE__*/ function() {
|
|
4635
4713
|
const Proto = /*#__PURE__*/ makePrimitiveProto({
|
|
4636
4714
|
op: "Async",
|
|
@@ -5109,6 +5187,18 @@ var AsyncFiberError = class extends (/*#__PURE__*/ TaggedError$2("AsyncFiberErro
|
|
|
5109
5187
|
});
|
|
5110
5188
|
}
|
|
5111
5189
|
};
|
|
5190
|
+
/** @internal */
|
|
5191
|
+
const UnknownErrorTypeId = "~effect/Cause/UnknownError";
|
|
5192
|
+
/** @internal */
|
|
5193
|
+
var UnknownError = class extends (/*#__PURE__*/ TaggedError$2("UnknownError")) {
|
|
5194
|
+
[UnknownErrorTypeId] = UnknownErrorTypeId;
|
|
5195
|
+
constructor(cause, message) {
|
|
5196
|
+
super({
|
|
5197
|
+
message,
|
|
5198
|
+
cause
|
|
5199
|
+
});
|
|
5200
|
+
}
|
|
5201
|
+
};
|
|
5112
5202
|
const colors = {
|
|
5113
5203
|
bold: "1",
|
|
5114
5204
|
red: "31",
|
|
@@ -5910,6 +6000,7 @@ const failCauseSync = failCauseSync$1;
|
|
|
5910
6000
|
* @since 2.0.0
|
|
5911
6001
|
*/
|
|
5912
6002
|
const die = die$2;
|
|
6003
|
+
const try_ = try_$1;
|
|
5913
6004
|
/**
|
|
5914
6005
|
* Converts a `Result` to an `Effect`.
|
|
5915
6006
|
*
|
|
@@ -6724,7 +6815,7 @@ const compareMagnitude = (self, that) => {
|
|
|
6724
6815
|
const exponentDifference = BigInt(selfDigits.length - thatDigits.length) - BigInt(self.scale) + BigInt(that.scale);
|
|
6725
6816
|
if (exponentDifference !== bigint0) return exponentDifference < bigint0 ? -1 : 1;
|
|
6726
6817
|
const length = Math.max(selfDigits.length, thatDigits.length);
|
|
6727
|
-
return String$
|
|
6818
|
+
return String$5(selfDigits.padEnd(length, "0"), thatDigits.padEnd(length, "0"));
|
|
6728
6819
|
};
|
|
6729
6820
|
const compare = (self, that) => {
|
|
6730
6821
|
if (self.scale === that.scale) return compareBigInt(self.value, that.value);
|
|
@@ -7525,7 +7616,7 @@ function transformEffect$1(f) {
|
|
|
7525
7616
|
* @category converting
|
|
7526
7617
|
* @since 4.0.0
|
|
7527
7618
|
*/
|
|
7528
|
-
function String$
|
|
7619
|
+
function String$3() {
|
|
7529
7620
|
return transform$1(globalThis.String);
|
|
7530
7621
|
}
|
|
7531
7622
|
/**
|
|
@@ -7559,6 +7650,61 @@ function String$4() {
|
|
|
7559
7650
|
function Number$3() {
|
|
7560
7651
|
return transform$1(globalThis.Number);
|
|
7561
7652
|
}
|
|
7653
|
+
function parseJson$1(options) {
|
|
7654
|
+
return transformEffect$1((input, parseOptions) => try_({
|
|
7655
|
+
try: () => JSON.parse(input, options?.reviver),
|
|
7656
|
+
catch: () => new InvalidValue({ expected: "a valid JSON string" }, input, parseOptions)
|
|
7657
|
+
}));
|
|
7658
|
+
}
|
|
7659
|
+
/**
|
|
7660
|
+
* Stringifies a present value using `JSON.stringify`.
|
|
7661
|
+
*
|
|
7662
|
+
* **When to use**
|
|
7663
|
+
*
|
|
7664
|
+
* Use when you need a schema getter to serialize a present decoded value to
|
|
7665
|
+
* JSON text during encoding.
|
|
7666
|
+
*
|
|
7667
|
+
* **Details**
|
|
7668
|
+
*
|
|
7669
|
+
* - Skips `None` inputs.
|
|
7670
|
+
* - If `JSON.stringify` throws or returns `undefined`, fails with
|
|
7671
|
+
* `SchemaIssue.InvalidValue`.
|
|
7672
|
+
* - Supports optional `replacer` and `space` options, matching
|
|
7673
|
+
* `JSON.stringify`.
|
|
7674
|
+
*
|
|
7675
|
+
* **Example** (Stringifying JSON)
|
|
7676
|
+
*
|
|
7677
|
+
* ```ts import.meta.vitest
|
|
7678
|
+
* import { Effect, Option, SchemaGetter } from "effect"
|
|
7679
|
+
*
|
|
7680
|
+
* const stringify = SchemaGetter.stringifyJson()
|
|
7681
|
+
* const result = await Effect.runPromise(SchemaGetter.run(stringify, Option.some({ a: 1 }), {}))
|
|
7682
|
+
* result // => Option.some("{\"a\":1}")
|
|
7683
|
+
* ```
|
|
7684
|
+
*
|
|
7685
|
+
* @see {@link parseJson} for the inverse operation
|
|
7686
|
+
*
|
|
7687
|
+
* @stability stable
|
|
7688
|
+
* @category encoding
|
|
7689
|
+
* @since 4.0.0
|
|
7690
|
+
*/
|
|
7691
|
+
function stringifyJson(options) {
|
|
7692
|
+
return transformEffect$1((input, parseOptions) => try_({
|
|
7693
|
+
try: () => {
|
|
7694
|
+
const output = JSON.stringify(input, options?.replacer, options?.space);
|
|
7695
|
+
if (output === void 0) throw new TypeError("Value cannot be represented as JSON");
|
|
7696
|
+
return output;
|
|
7697
|
+
},
|
|
7698
|
+
catch: () => new InvalidValue({ expected: "a JSON-serializable value" }, input, parseOptions)
|
|
7699
|
+
}));
|
|
7700
|
+
}
|
|
7701
|
+
// ../../node_modules/.pnpm/effect@4.1.7/node_modules/effect/dist/internal/schema/content.js
|
|
7702
|
+
const ContentTypeId = /*#__PURE__*/ Symbol.for("~effect/Schema/content");
|
|
7703
|
+
/** @internal */
|
|
7704
|
+
function setContent(operation, content) {
|
|
7705
|
+
Object.defineProperty(operation, ContentTypeId, { value: content });
|
|
7706
|
+
return operation;
|
|
7707
|
+
}
|
|
7562
7708
|
// ../../node_modules/.pnpm/effect@4.1.7/node_modules/effect/dist/SchemaTransformation.js
|
|
7563
7709
|
/**
|
|
7564
7710
|
* Constructs schema middleware from its decode and encode functions.
|
|
@@ -7711,6 +7857,47 @@ function passthrough() {
|
|
|
7711
7857
|
* @since 4.0.0
|
|
7712
7858
|
*/
|
|
7713
7859
|
const numberFromString = /*#__PURE__*/ new Transformation(/*#__PURE__*/ Number$3(), /*#__PURE__*/ transform$1((n) => Object.is(n, -0) ? "-0" : globalThis.String(n)));
|
|
7860
|
+
/**
|
|
7861
|
+
* Decodes a JSON string with `JSON.parse` and encodes a value with
|
|
7862
|
+
* `JSON.stringify`.
|
|
7863
|
+
*
|
|
7864
|
+
* **When to use**
|
|
7865
|
+
*
|
|
7866
|
+
* Use when you need a schema transformation to decode JSON stored or
|
|
7867
|
+
* transmitted as a string, usually before composing with another schema that
|
|
7868
|
+
* validates the parsed structure.
|
|
7869
|
+
*
|
|
7870
|
+
* **Details**
|
|
7871
|
+
*
|
|
7872
|
+
* The `reviver` option is passed to `JSON.parse` during decoding. The
|
|
7873
|
+
* `replacer` and `space` options are passed to `JSON.stringify` during
|
|
7874
|
+
* encoding. Decode fails with `InvalidValue` for invalid JSON, and encode can
|
|
7875
|
+
* fail with `InvalidValue` when `JSON.stringify` cannot serialize the value.
|
|
7876
|
+
*
|
|
7877
|
+
* **Example** (Parsing JSON)
|
|
7878
|
+
*
|
|
7879
|
+
* ```ts import.meta.vitest
|
|
7880
|
+
* import { Schema, SchemaTransformation } from "effect"
|
|
7881
|
+
*
|
|
7882
|
+
* const schema = Schema.String.pipe(
|
|
7883
|
+
* Schema.decodeTo(Schema.Unknown, SchemaTransformation.fromJsonString())
|
|
7884
|
+
* )
|
|
7885
|
+
* Schema.decodeSync(schema)("{\"ok\":true}") // => { ok: true }
|
|
7886
|
+
* ```
|
|
7887
|
+
*
|
|
7888
|
+
* @see {@link uint8ArrayFromBase64String}
|
|
7889
|
+
* @see {@link fromFormData}
|
|
7890
|
+
*
|
|
7891
|
+
* @stability stable
|
|
7892
|
+
* @category decoding
|
|
7893
|
+
* @since 4.0.0
|
|
7894
|
+
*/
|
|
7895
|
+
function fromJsonString$1(options) {
|
|
7896
|
+
return new Transformation(parseJson$1(options ?? {}), setContent(stringifyJson(options), {
|
|
7897
|
+
mediaType: "application/json",
|
|
7898
|
+
preserveSchema: options?.reviver === void 0 && options?.replacer === void 0
|
|
7899
|
+
}));
|
|
7900
|
+
}
|
|
7714
7901
|
// ../../node_modules/.pnpm/effect@4.1.7/node_modules/effect/dist/SchemaAST.js
|
|
7715
7902
|
/**
|
|
7716
7903
|
* Represents Effect schemas as runtime trees.
|
|
@@ -8015,7 +8202,7 @@ function literalToString(ast) {
|
|
|
8015
8202
|
* @category constructors
|
|
8016
8203
|
* @since 4.0.0
|
|
8017
8204
|
*/
|
|
8018
|
-
const String$
|
|
8205
|
+
const String$2 = class extends ASTNodeImpl {
|
|
8019
8206
|
_tag = "String";
|
|
8020
8207
|
/** @internal */
|
|
8021
8208
|
getParser() {
|
|
@@ -8045,7 +8232,7 @@ const String$3 = class extends ASTNodeImpl {
|
|
|
8045
8232
|
* @category constructors
|
|
8046
8233
|
* @since 4.0.0
|
|
8047
8234
|
*/
|
|
8048
|
-
const string = /*#__PURE__*/ new String$
|
|
8235
|
+
const string = /*#__PURE__*/ new String$2();
|
|
8049
8236
|
/**
|
|
8050
8237
|
* Constructs a {@link Number}.
|
|
8051
8238
|
*
|
|
@@ -9242,6 +9429,41 @@ function withConstructorDefault$1(ast, defaultValue) {
|
|
|
9242
9429
|
function decodeTo$1(from, to, transformation) {
|
|
9243
9430
|
return appendTransformation(from, transformation, to);
|
|
9244
9431
|
}
|
|
9432
|
+
function parseParameter(ast) {
|
|
9433
|
+
const literals = [];
|
|
9434
|
+
const parameters = [];
|
|
9435
|
+
function addLiteral(literal) {
|
|
9436
|
+
if (!literals.includes(literal)) literals.push(literal);
|
|
9437
|
+
}
|
|
9438
|
+
function go(ast) {
|
|
9439
|
+
switch (ast._tag) {
|
|
9440
|
+
case "Literal":
|
|
9441
|
+
if (isPropertyKey(ast.literal)) addLiteral(ast.literal);
|
|
9442
|
+
return;
|
|
9443
|
+
case "UniqueSymbol":
|
|
9444
|
+
addLiteral(ast.symbol);
|
|
9445
|
+
return;
|
|
9446
|
+
case "Enum":
|
|
9447
|
+
for (const [, value] of ast.enums) addLiteral(value);
|
|
9448
|
+
return;
|
|
9449
|
+
case "Never": return;
|
|
9450
|
+
case "Union":
|
|
9451
|
+
for (let i = 0; i < ast.types.length; i++) go(ast.types[i]);
|
|
9452
|
+
return;
|
|
9453
|
+
default: parameters.push(ast);
|
|
9454
|
+
}
|
|
9455
|
+
}
|
|
9456
|
+
go(ast);
|
|
9457
|
+
return {
|
|
9458
|
+
literals,
|
|
9459
|
+
parameters
|
|
9460
|
+
};
|
|
9461
|
+
}
|
|
9462
|
+
/** @internal */
|
|
9463
|
+
function record(key, value) {
|
|
9464
|
+
const { literals, parameters: indexSignatures } = parseParameter(key);
|
|
9465
|
+
return new Objects(literals.map((literal) => new PropertySignature(literal, value)), indexSignatures.map((parameter) => new IndexSignature(parameter, value)));
|
|
9466
|
+
}
|
|
9245
9467
|
/**
|
|
9246
9468
|
* Returns `true` if the AST node represents an optional property.
|
|
9247
9469
|
*
|
|
@@ -9865,6 +10087,55 @@ function make$4(schema) {
|
|
|
9865
10087
|
return makeConstructorSync(toType(schema.ast));
|
|
9866
10088
|
}
|
|
9867
10089
|
/**
|
|
10090
|
+
* Creates a type guard that checks whether an input satisfies the schema's decoded
|
|
10091
|
+
* type side.
|
|
10092
|
+
*
|
|
10093
|
+
* **When to use**
|
|
10094
|
+
*
|
|
10095
|
+
* Use to build a type guard for checking the decoded side of a schema without
|
|
10096
|
+
* exposing issue details.
|
|
10097
|
+
*
|
|
10098
|
+
* **Details**
|
|
10099
|
+
*
|
|
10100
|
+
* The guard returns `true` on successful validation and `false` when validation
|
|
10101
|
+
* fails only with schema issues, without exposing issue details.
|
|
10102
|
+
*
|
|
10103
|
+
* **Gotchas**
|
|
10104
|
+
*
|
|
10105
|
+
* Only causes made entirely of schema issues are converted to `false`. Causes
|
|
10106
|
+
* that contain defects, interruptions, or asynchronous work at this synchronous
|
|
10107
|
+
* boundary throw an `Error` whose cause is the underlying `Cause`.
|
|
10108
|
+
*
|
|
10109
|
+
* @stability stable
|
|
10110
|
+
* @category guards
|
|
10111
|
+
* @since 3.10.0
|
|
10112
|
+
*/
|
|
10113
|
+
function is$1(schema) {
|
|
10114
|
+
return _is(schema.ast);
|
|
10115
|
+
}
|
|
10116
|
+
function makeIs(ast) {
|
|
10117
|
+
{
|
|
10118
|
+
const parser = asExit(run(ast));
|
|
10119
|
+
return (input) => {
|
|
10120
|
+
const exit = parser(input, defaultParseOptions);
|
|
10121
|
+
if (isSuccess(exit)) return true;
|
|
10122
|
+
getSchemaIssueOrThrow(exit.cause, "Type guard adapter can only return false for schema issues");
|
|
10123
|
+
return false;
|
|
10124
|
+
};
|
|
10125
|
+
}
|
|
10126
|
+
}
|
|
10127
|
+
/** @internal */
|
|
10128
|
+
function _is(ast) {
|
|
10129
|
+
const typeAST = toType(ast);
|
|
10130
|
+
let guard = (input) => {
|
|
10131
|
+
guard = makeIs(typeAST);
|
|
10132
|
+
return guard(input);
|
|
10133
|
+
};
|
|
10134
|
+
return (input) => {
|
|
10135
|
+
return guard(input);
|
|
10136
|
+
};
|
|
10137
|
+
}
|
|
10138
|
+
/**
|
|
9868
10139
|
* Creates an effectful decoder for `unknown` input.
|
|
9869
10140
|
*
|
|
9870
10141
|
* **When to use**
|
|
@@ -9889,6 +10160,12 @@ function make$4(schema) {
|
|
|
9889
10160
|
function decodeUnknownEffect(schema, options) {
|
|
9890
10161
|
return withParseOptions(run(schema.ast), options);
|
|
9891
10162
|
}
|
|
10163
|
+
/** @internal */
|
|
10164
|
+
function decodeUnknownOption(schema, options) {
|
|
10165
|
+
return asOption(decodeUnknownEffect(schema, options));
|
|
10166
|
+
}
|
|
10167
|
+
/** @internal */
|
|
10168
|
+
const decodeOption$1 = decodeUnknownOption;
|
|
9892
10169
|
function withParseOptions(parse, options) {
|
|
9893
10170
|
return options === void 0 ? parse : (input, overrides) => parse(input, overrides ? {
|
|
9894
10171
|
...options,
|
|
@@ -9914,6 +10191,19 @@ function runWithCompiler(compiler, ast) {
|
|
|
9914
10191
|
return parserResult((parser ??= compiler(ast))(input, options ?? defaultParseOptions), input);
|
|
9915
10192
|
};
|
|
9916
10193
|
}
|
|
10194
|
+
function asExit(parser) {
|
|
10195
|
+
return (input, options) => runSyncExit(parser(input, options));
|
|
10196
|
+
}
|
|
10197
|
+
/** @internal */
|
|
10198
|
+
function asOption(parser) {
|
|
10199
|
+
const parserExit = asExit(parser);
|
|
10200
|
+
return (input, options) => {
|
|
10201
|
+
const exit = parserExit(input, options);
|
|
10202
|
+
if (isSuccess(exit)) return some(exit.value);
|
|
10203
|
+
getSchemaIssueOrThrow(exit.cause, "Option adapter can only return none for schema issues");
|
|
10204
|
+
return none();
|
|
10205
|
+
};
|
|
10206
|
+
}
|
|
9917
10207
|
function exitToOption(exit) {
|
|
9918
10208
|
if (isSuccess(exit)) return some(exit.value);
|
|
9919
10209
|
getSchemaIssueOrThrow(exit.cause, "Option adapter can only return none for schema issues");
|
|
@@ -10106,7 +10396,7 @@ function toCodecStringTreeASTStep(ast, recur, onMissingAnnotation) {
|
|
|
10106
10396
|
return ast;
|
|
10107
10397
|
}
|
|
10108
10398
|
const nullToString = /*#__PURE__*/ new Link(/*#__PURE__*/ new Literal$1("null"), /*#__PURE__*/ new Transformation(/*#__PURE__*/ transform$1(() => null), /*#__PURE__*/ transform$1(() => "null")));
|
|
10109
|
-
const booleanToString = /*#__PURE__*/ new Link(/*#__PURE__*/ new Union$1([/*#__PURE__*/ new Literal$1("true"), /*#__PURE__*/ new Literal$1("false")]), /*#__PURE__*/ new Transformation(/*#__PURE__*/ transform$1((s) => s === "true"), /*#__PURE__*/ String$
|
|
10399
|
+
const booleanToString = /*#__PURE__*/ new Link(/*#__PURE__*/ new Union$1([/*#__PURE__*/ new Literal$1("true"), /*#__PURE__*/ new Literal$1("false")]), /*#__PURE__*/ new Transformation(/*#__PURE__*/ transform$1((s) => s === "true"), /*#__PURE__*/ String$3()));
|
|
10110
10400
|
const arrayFromSingleTransformation = /*#__PURE__*/ new Transformation(/*#__PURE__*/ transform$1((input) => typeof input === "string" ? [input] : input), /*#__PURE__*/ passthrough$1());
|
|
10111
10401
|
const isCodecArrayFromSingleLink = (link) => link.transformation === arrayFromSingleTransformation;
|
|
10112
10402
|
const toCodecStringTreeAST = /*#__PURE__*/ makeCodecDerivation((ast, recur) => toCodecStringTreeASTStep(ast, recur, (ast) => {
|
|
@@ -10183,6 +10473,72 @@ var SchemaError = class extends (/*#__PURE__*/ TaggedError$1("SchemaError")) {
|
|
|
10183
10473
|
}
|
|
10184
10474
|
};
|
|
10185
10475
|
/**
|
|
10476
|
+
* Creates a type guard function that checks if a value conforms to a given
|
|
10477
|
+
* schema.
|
|
10478
|
+
*
|
|
10479
|
+
* **Details**
|
|
10480
|
+
*
|
|
10481
|
+
* This function returns a predicate that performs a type-safe check, narrowing
|
|
10482
|
+
* the type of the input value if the check passes. The predicate returns `false`
|
|
10483
|
+
* for schema mismatches.
|
|
10484
|
+
*
|
|
10485
|
+
* **Gotchas**
|
|
10486
|
+
*
|
|
10487
|
+
* Only causes made entirely of schema issues are converted to `false`. Causes
|
|
10488
|
+
* that contain defects, interruptions, or other non-schema reasons throw
|
|
10489
|
+
* instead.
|
|
10490
|
+
*
|
|
10491
|
+
* **Example** (Defining a basic type guard)
|
|
10492
|
+
*
|
|
10493
|
+
* ```ts import.meta.vitest
|
|
10494
|
+
* import { Schema } from "effect"
|
|
10495
|
+
*
|
|
10496
|
+
* const isString = Schema.is(Schema.String)
|
|
10497
|
+
*
|
|
10498
|
+
* isString("hello") // => true
|
|
10499
|
+
* isString(42) // => false
|
|
10500
|
+
*
|
|
10501
|
+
* // Type narrowing in action
|
|
10502
|
+
* const value: unknown = "hello"
|
|
10503
|
+
* if (isString(value)) {
|
|
10504
|
+
* // value is now typed as string
|
|
10505
|
+
* value.toUpperCase() // => "HELLO"
|
|
10506
|
+
* }
|
|
10507
|
+
* ```
|
|
10508
|
+
*
|
|
10509
|
+
* @stability stable
|
|
10510
|
+
* @category guards
|
|
10511
|
+
* @since 3.10.0
|
|
10512
|
+
*/
|
|
10513
|
+
const is = is$1;
|
|
10514
|
+
/**
|
|
10515
|
+
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
10516
|
+
* returning an `Option` that is `Some` with the decoded value on success or
|
|
10517
|
+
* `None` for schema mismatches.
|
|
10518
|
+
*
|
|
10519
|
+
* **When to use**
|
|
10520
|
+
*
|
|
10521
|
+
* Use when you already have input typed as the schema's `Encoded` type and
|
|
10522
|
+
* only need to know whether decoding succeeded.
|
|
10523
|
+
*
|
|
10524
|
+
* **Details**
|
|
10525
|
+
*
|
|
10526
|
+
* For `unknown` input use {@link decodeUnknownOption}.
|
|
10527
|
+
* Options may be provided either when creating the decoder or when applying it;
|
|
10528
|
+
* application options override creation options.
|
|
10529
|
+
*
|
|
10530
|
+
* **Gotchas**
|
|
10531
|
+
*
|
|
10532
|
+
* Only causes made entirely of schema issues are converted to `None`. Causes
|
|
10533
|
+
* that contain defects, interruptions, or other non-schema reasons throw
|
|
10534
|
+
* instead.
|
|
10535
|
+
*
|
|
10536
|
+
* @stability stable
|
|
10537
|
+
* @category decoding
|
|
10538
|
+
* @since 3.10.0
|
|
10539
|
+
*/
|
|
10540
|
+
const decodeOption = decodeOption$1;
|
|
10541
|
+
/**
|
|
10186
10542
|
* Creates a schema from an AST (Abstract Syntax Tree) node.
|
|
10187
10543
|
*
|
|
10188
10544
|
* **Details**
|
|
@@ -10244,13 +10600,27 @@ function Literal(literal) {
|
|
|
10244
10600
|
return out;
|
|
10245
10601
|
}
|
|
10246
10602
|
/**
|
|
10603
|
+
* Schema for the `unknown` type. Accepts any value without validation.
|
|
10604
|
+
*
|
|
10605
|
+
* **When to use**
|
|
10606
|
+
*
|
|
10607
|
+
* Use as a top schema when you need to accept any input while preserving
|
|
10608
|
+
* TypeScript's `unknown` safety at use sites.
|
|
10609
|
+
*
|
|
10610
|
+
* @see {@link Any} for the `any` variant.
|
|
10611
|
+
* @stability stable
|
|
10612
|
+
* @category schemas
|
|
10613
|
+
* @since 3.10.0
|
|
10614
|
+
*/
|
|
10615
|
+
const Unknown = /*#__PURE__*/ make$2(unknown);
|
|
10616
|
+
/**
|
|
10247
10617
|
* Schema for `string` values. Validates that the input is `typeof` `"string"`.
|
|
10248
10618
|
*
|
|
10249
10619
|
* @stability stable
|
|
10250
10620
|
* @category schemas
|
|
10251
10621
|
* @since 4.0.0
|
|
10252
10622
|
*/
|
|
10253
|
-
const String$
|
|
10623
|
+
const String$1 = /*#__PURE__*/ make$2(string);
|
|
10254
10624
|
function makeStruct(ast, fields) {
|
|
10255
10625
|
return make$2(ast, {
|
|
10256
10626
|
fields,
|
|
@@ -10301,6 +10671,58 @@ function makeStruct(ast, fields) {
|
|
|
10301
10671
|
function Struct(fields) {
|
|
10302
10672
|
return makeStruct(struct(fields, void 0), fields);
|
|
10303
10673
|
}
|
|
10674
|
+
/**
|
|
10675
|
+
* Defines a record schema whose dynamic properties are selected by a key schema
|
|
10676
|
+
* and decoded with a value schema.
|
|
10677
|
+
*
|
|
10678
|
+
* **Details**
|
|
10679
|
+
*
|
|
10680
|
+
* For dynamic keys, the key schema selects matching own properties and the
|
|
10681
|
+
* value schema decodes or encodes only those selected properties. Checks on
|
|
10682
|
+
* string, number, symbol, and template literal key schemas narrow which
|
|
10683
|
+
* properties are selected.
|
|
10684
|
+
*
|
|
10685
|
+
* For transformed key schemas, property selection is based on encoded property
|
|
10686
|
+
* names before the selected key is decoded.
|
|
10687
|
+
*
|
|
10688
|
+
* **Gotchas**
|
|
10689
|
+
*
|
|
10690
|
+
* Dynamic records reject value schemas wrapped with {@link optionalKey} or
|
|
10691
|
+
* {@link optional}. Index signatures already allow keys to be absent; use
|
|
10692
|
+
* {@link UndefinedOr} when existing entries may contain `undefined`. Optional
|
|
10693
|
+
* value schemas remain valid for finite literal keys, which become declared
|
|
10694
|
+
* properties.
|
|
10695
|
+
*
|
|
10696
|
+
* When decoded or encoded key transformations produce the same property key,
|
|
10697
|
+
* sequential parsing applies selected own properties in selection order, so
|
|
10698
|
+
* the later selected property overwrites the earlier value. Dynamic key
|
|
10699
|
+
* selection always examines own properties. Finite literal and enum keys are
|
|
10700
|
+
* declared fields and may therefore be inherited. Output key order is not
|
|
10701
|
+
* guaranteed.
|
|
10702
|
+
*
|
|
10703
|
+
* **Example** (Defining a string-keyed record of numbers)
|
|
10704
|
+
*
|
|
10705
|
+
* ```ts import.meta.vitest
|
|
10706
|
+
* import { Schema } from "effect"
|
|
10707
|
+
*
|
|
10708
|
+
* const schema = Schema.Record(Schema.String, Schema.Number)
|
|
10709
|
+
*
|
|
10710
|
+
* // { readonly [x: string]: number }
|
|
10711
|
+
* type R = typeof schema.Type
|
|
10712
|
+
*
|
|
10713
|
+
* Schema.decodeUnknownSync(schema)({ a: 1, b: 2 }) // => { a: 1, b: 2 }
|
|
10714
|
+
* ```
|
|
10715
|
+
*
|
|
10716
|
+
* @stability stable
|
|
10717
|
+
* @category constructors
|
|
10718
|
+
* @since 3.10.0
|
|
10719
|
+
*/
|
|
10720
|
+
function Record(key, value) {
|
|
10721
|
+
return make$2(record(key.ast, value.ast), {
|
|
10722
|
+
key,
|
|
10723
|
+
value
|
|
10724
|
+
});
|
|
10725
|
+
}
|
|
10304
10726
|
function decodeTo(to, transformation) {
|
|
10305
10727
|
return (from) => {
|
|
10306
10728
|
return make$2(decodeTo$1(from.ast, to.ast, transformation ? makeTransformation(transformation) : passthrough()), {
|
|
@@ -10524,9 +10946,43 @@ function isNonEmpty(annotations) {
|
|
|
10524
10946
|
* @category schemas
|
|
10525
10947
|
* @since 3.10.0
|
|
10526
10948
|
*/
|
|
10527
|
-
const NonEmptyString$1 = /*#__PURE__*/ String$
|
|
10949
|
+
const NonEmptyString$1 = /*#__PURE__*/ String$1.check(/*#__PURE__*/ isNonEmpty());
|
|
10528
10950
|
globalThis.RegExp;
|
|
10529
10951
|
globalThis.URL;
|
|
10952
|
+
const JsonString = /*#__PURE__*/ String$1.annotate({ expected: "a string that will be decoded as JSON" });
|
|
10953
|
+
/**
|
|
10954
|
+
* Returns a schema that decodes a JSON string and then decodes the parsed value
|
|
10955
|
+
* using the given schema.
|
|
10956
|
+
*
|
|
10957
|
+
* **Details**
|
|
10958
|
+
*
|
|
10959
|
+
* This is useful when working with JSON-encoded strings where the actual
|
|
10960
|
+
* structure of the value is known and described by an existing schema.
|
|
10961
|
+
*
|
|
10962
|
+
* During decoding, the resulting schema first parses the input string as JSON,
|
|
10963
|
+
* using `reviver` when provided, and then runs the provided schema on the
|
|
10964
|
+
* parsed result. During encoding, it first encodes with the provided schema and
|
|
10965
|
+
* then passes the result to `JSON.stringify` with the optional `replacer` and
|
|
10966
|
+
* `space`.
|
|
10967
|
+
*
|
|
10968
|
+
* **Example** (Formatting encoded JSON)
|
|
10969
|
+
*
|
|
10970
|
+
* ```ts import.meta.vitest
|
|
10971
|
+
* import { Schema } from "effect"
|
|
10972
|
+
*
|
|
10973
|
+
* const schema = Schema.Struct({ a: Schema.Number })
|
|
10974
|
+
* const schemaFromJsonString = Schema.fromJsonString(schema, { space: 2 })
|
|
10975
|
+
*
|
|
10976
|
+
* Schema.encodeSync(schemaFromJsonString)({ a: 1 }) // => "{\n \"a\": 1\n}"
|
|
10977
|
+
* ```
|
|
10978
|
+
*
|
|
10979
|
+
* @stability stable
|
|
10980
|
+
* @category schemas
|
|
10981
|
+
* @since 4.0.0
|
|
10982
|
+
*/
|
|
10983
|
+
function fromJsonString(schema, options) {
|
|
10984
|
+
return JsonString.pipe(decodeTo(schema, fromJsonString$1(options)));
|
|
10985
|
+
}
|
|
10530
10986
|
globalThis.File;
|
|
10531
10987
|
globalThis.URLSearchParams;
|
|
10532
10988
|
globalThis.Uint8Array;
|
|
@@ -11478,7 +11934,7 @@ function NonEmptyString(name) {
|
|
|
11478
11934
|
}
|
|
11479
11935
|
// src/shared/lib/cache.ts
|
|
11480
11936
|
const taggedError = TaggedError;
|
|
11481
|
-
var CacheRootError = class extends taggedError()("CacheRootError", { message: String$
|
|
11937
|
+
var CacheRootError = class extends taggedError()("CacheRootError", { message: String$1 }) {};
|
|
11482
11938
|
const SEPARATOR = "/";
|
|
11483
11939
|
const CACHE_DIRECTORY_NAME = ".cache";
|
|
11484
11940
|
const variable = (name) => option(NonEmptyString(name)).pipe(orElseSucceed(none));
|