@railway-ts/pipelines 0.1.25 → 0.1.27
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/README.md +1 -1
- package/dist/option/index.cjs +2 -2
- package/dist/option/index.cjs.map +1 -1
- package/dist/option/index.mjs +2 -2
- package/dist/option/index.mjs.map +1 -1
- package/dist/result/index.cjs +2 -2
- package/dist/result/index.cjs.map +1 -1
- package/dist/result/index.mjs +2 -2
- package/dist/result/index.mjs.map +1 -1
- package/dist/schema/index.cjs +19 -1
- package/dist/schema/index.cjs.map +1 -1
- package/dist/schema/index.d.cts +35 -1
- package/dist/schema/index.d.ts +35 -1
- package/dist/schema/index.mjs +18 -2
- package/dist/schema/index.mjs.map +1 -1
- package/docs/API.md +100 -13
- package/docs/RECIPES.md +30 -1
- package/package.json +11 -11
package/dist/schema/index.d.cts
CHANGED
|
@@ -371,6 +371,40 @@ declare function refineAt<T>(targetPath: string | string[], predicate: (value: T
|
|
|
371
371
|
* @see refineAt - For synchronous cross-field validation
|
|
372
372
|
*/
|
|
373
373
|
declare function refineAtAsync<T>(targetPath: string | string[], predicate: (value: T) => Promise<boolean>, message: string): AsyncValidator<T, T>;
|
|
374
|
+
/**
|
|
375
|
+
* Create a conditional validator that applies different validators based on a predicate.
|
|
376
|
+
* When the predicate returns true, `thenValidator` is applied.
|
|
377
|
+
* When false, `elseValidator` is applied (if provided), otherwise the value passes through.
|
|
378
|
+
*
|
|
379
|
+
* @example
|
|
380
|
+
* const validate = when<FormData>(
|
|
381
|
+
* (data) => data.contactMethod === 'email',
|
|
382
|
+
* refineAt('email', (d) => d.email.includes('@'), 'Valid email required'),
|
|
383
|
+
* refineAt('phone', (d) => d.phone.length > 0, 'Phone required'),
|
|
384
|
+
* );
|
|
385
|
+
*
|
|
386
|
+
* @param predicate - A function that determines which validator to apply
|
|
387
|
+
* @param thenValidator - Validator applied when predicate returns true
|
|
388
|
+
* @param elseValidator - Optional validator applied when predicate returns false
|
|
389
|
+
* @returns A validator that conditionally applies validation
|
|
390
|
+
*/
|
|
391
|
+
declare function when<T>(predicate: (data: T) => boolean, thenValidator: Validator<T, T>, elseValidator?: Validator<T, T>): Validator<T, T>;
|
|
392
|
+
/**
|
|
393
|
+
* Create a conditional async validator that applies different validators based on a predicate.
|
|
394
|
+
* This is the async counterpart of {@link when}.
|
|
395
|
+
*
|
|
396
|
+
* @example
|
|
397
|
+
* const validate = whenAsync<FormData>(
|
|
398
|
+
* (data) => data.requiresVerification,
|
|
399
|
+
* refineAtAsync('code', async (d) => await verifyCode(d.code), 'Invalid code'),
|
|
400
|
+
* );
|
|
401
|
+
*
|
|
402
|
+
* @param predicate - A function that determines which validator to apply
|
|
403
|
+
* @param thenValidator - Validator applied when predicate returns true
|
|
404
|
+
* @param elseValidator - Optional validator applied when predicate returns false
|
|
405
|
+
* @returns An async validator that conditionally applies validation
|
|
406
|
+
*/
|
|
407
|
+
declare function whenAsync<T>(predicate: (data: T) => boolean, thenValidator: MaybeAsyncValidator<T, T>, elseValidator?: MaybeAsyncValidator<T, T>): AsyncValidator<T, T>;
|
|
374
408
|
|
|
375
409
|
/**
|
|
376
410
|
* Create a validator for arrays where each item is validated by the provided validator.
|
|
@@ -1228,4 +1262,4 @@ declare namespace StandardSchemaV1 {
|
|
|
1228
1262
|
declare function toStandardSchema<O>(validator: Validator<unknown, O>): StandardSchemaV1<unknown, O>;
|
|
1229
1263
|
declare function toStandardSchema<O>(validator: MaybeAsyncValidator<unknown, O>): StandardSchemaV1<unknown, O>;
|
|
1230
1264
|
|
|
1231
|
-
export { type AsyncValidator, type InferSchemaType, type MaybeAsyncValidator, ROOT_ERROR_KEY, type Schema, StandardSchemaV1, type SyncSchema, type ValidateOptions, type ValidationError, type ValidationResult, type Validator, type ValidatorMapOutput, array, between, bigint, boolean, chain, chainAsync, date, dateRange, discriminatedUnion, divisibleBy, email, emptyAsOptional, enumValue, finite, formatErrors, futureDate, integer, is, isoDate, isoDateTime, isoDuration, isoTime, literal, matches, max, maxItems, maxLength, min, minItems, minLength, negative, nonEmpty, nonZero, notEmpty, nullable, number, object, oneOf, optional, parseBigInt, parseBool, parseDate, parseEnum, parseISODate, parseJSON, parseNumber, parseString, parseURL, pastDate, pattern, phoneNumber, positive, precision, refine, refineAsync, refineAt, refineAtAsync, required, string, stringEnum, toStandardSchema, todayOrFuture, transform, tuple, tupleOf, union, unique, url, uuid, validate, validateAndFormatResult };
|
|
1265
|
+
export { type AsyncValidator, type InferSchemaType, type MaybeAsyncValidator, ROOT_ERROR_KEY, type Schema, StandardSchemaV1, type SyncSchema, type ValidateOptions, type ValidationError, type ValidationResult, type Validator, type ValidatorMapOutput, array, between, bigint, boolean, chain, chainAsync, date, dateRange, discriminatedUnion, divisibleBy, email, emptyAsOptional, enumValue, finite, formatErrors, futureDate, integer, is, isoDate, isoDateTime, isoDuration, isoTime, literal, matches, max, maxItems, maxLength, min, minItems, minLength, negative, nonEmpty, nonZero, notEmpty, nullable, number, object, oneOf, optional, parseBigInt, parseBool, parseDate, parseEnum, parseISODate, parseJSON, parseNumber, parseString, parseURL, pastDate, pattern, phoneNumber, positive, precision, refine, refineAsync, refineAt, refineAtAsync, required, string, stringEnum, toStandardSchema, todayOrFuture, transform, tuple, tupleOf, union, unique, url, uuid, validate, validateAndFormatResult, when, whenAsync };
|
package/dist/schema/index.d.ts
CHANGED
|
@@ -371,6 +371,40 @@ declare function refineAt<T>(targetPath: string | string[], predicate: (value: T
|
|
|
371
371
|
* @see refineAt - For synchronous cross-field validation
|
|
372
372
|
*/
|
|
373
373
|
declare function refineAtAsync<T>(targetPath: string | string[], predicate: (value: T) => Promise<boolean>, message: string): AsyncValidator<T, T>;
|
|
374
|
+
/**
|
|
375
|
+
* Create a conditional validator that applies different validators based on a predicate.
|
|
376
|
+
* When the predicate returns true, `thenValidator` is applied.
|
|
377
|
+
* When false, `elseValidator` is applied (if provided), otherwise the value passes through.
|
|
378
|
+
*
|
|
379
|
+
* @example
|
|
380
|
+
* const validate = when<FormData>(
|
|
381
|
+
* (data) => data.contactMethod === 'email',
|
|
382
|
+
* refineAt('email', (d) => d.email.includes('@'), 'Valid email required'),
|
|
383
|
+
* refineAt('phone', (d) => d.phone.length > 0, 'Phone required'),
|
|
384
|
+
* );
|
|
385
|
+
*
|
|
386
|
+
* @param predicate - A function that determines which validator to apply
|
|
387
|
+
* @param thenValidator - Validator applied when predicate returns true
|
|
388
|
+
* @param elseValidator - Optional validator applied when predicate returns false
|
|
389
|
+
* @returns A validator that conditionally applies validation
|
|
390
|
+
*/
|
|
391
|
+
declare function when<T>(predicate: (data: T) => boolean, thenValidator: Validator<T, T>, elseValidator?: Validator<T, T>): Validator<T, T>;
|
|
392
|
+
/**
|
|
393
|
+
* Create a conditional async validator that applies different validators based on a predicate.
|
|
394
|
+
* This is the async counterpart of {@link when}.
|
|
395
|
+
*
|
|
396
|
+
* @example
|
|
397
|
+
* const validate = whenAsync<FormData>(
|
|
398
|
+
* (data) => data.requiresVerification,
|
|
399
|
+
* refineAtAsync('code', async (d) => await verifyCode(d.code), 'Invalid code'),
|
|
400
|
+
* );
|
|
401
|
+
*
|
|
402
|
+
* @param predicate - A function that determines which validator to apply
|
|
403
|
+
* @param thenValidator - Validator applied when predicate returns true
|
|
404
|
+
* @param elseValidator - Optional validator applied when predicate returns false
|
|
405
|
+
* @returns An async validator that conditionally applies validation
|
|
406
|
+
*/
|
|
407
|
+
declare function whenAsync<T>(predicate: (data: T) => boolean, thenValidator: MaybeAsyncValidator<T, T>, elseValidator?: MaybeAsyncValidator<T, T>): AsyncValidator<T, T>;
|
|
374
408
|
|
|
375
409
|
/**
|
|
376
410
|
* Create a validator for arrays where each item is validated by the provided validator.
|
|
@@ -1228,4 +1262,4 @@ declare namespace StandardSchemaV1 {
|
|
|
1228
1262
|
declare function toStandardSchema<O>(validator: Validator<unknown, O>): StandardSchemaV1<unknown, O>;
|
|
1229
1263
|
declare function toStandardSchema<O>(validator: MaybeAsyncValidator<unknown, O>): StandardSchemaV1<unknown, O>;
|
|
1230
1264
|
|
|
1231
|
-
export { type AsyncValidator, type InferSchemaType, type MaybeAsyncValidator, ROOT_ERROR_KEY, type Schema, StandardSchemaV1, type SyncSchema, type ValidateOptions, type ValidationError, type ValidationResult, type Validator, type ValidatorMapOutput, array, between, bigint, boolean, chain, chainAsync, date, dateRange, discriminatedUnion, divisibleBy, email, emptyAsOptional, enumValue, finite, formatErrors, futureDate, integer, is, isoDate, isoDateTime, isoDuration, isoTime, literal, matches, max, maxItems, maxLength, min, minItems, minLength, negative, nonEmpty, nonZero, notEmpty, nullable, number, object, oneOf, optional, parseBigInt, parseBool, parseDate, parseEnum, parseISODate, parseJSON, parseNumber, parseString, parseURL, pastDate, pattern, phoneNumber, positive, precision, refine, refineAsync, refineAt, refineAtAsync, required, string, stringEnum, toStandardSchema, todayOrFuture, transform, tuple, tupleOf, union, unique, url, uuid, validate, validateAndFormatResult };
|
|
1265
|
+
export { type AsyncValidator, type InferSchemaType, type MaybeAsyncValidator, ROOT_ERROR_KEY, type Schema, StandardSchemaV1, type SyncSchema, type ValidateOptions, type ValidationError, type ValidationResult, type Validator, type ValidatorMapOutput, array, between, bigint, boolean, chain, chainAsync, date, dateRange, discriminatedUnion, divisibleBy, email, emptyAsOptional, enumValue, finite, formatErrors, futureDate, integer, is, isoDate, isoDateTime, isoDuration, isoTime, literal, matches, max, maxItems, maxLength, min, minItems, minLength, negative, nonEmpty, nonZero, notEmpty, nullable, number, object, oneOf, optional, parseBigInt, parseBool, parseDate, parseEnum, parseISODate, parseJSON, parseNumber, parseString, parseURL, pastDate, pattern, phoneNumber, positive, precision, refine, refineAsync, refineAt, refineAtAsync, required, string, stringEnum, toStandardSchema, todayOrFuture, transform, tuple, tupleOf, union, unique, url, uuid, validate, validateAndFormatResult, when, whenAsync };
|
package/dist/schema/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/result/result.ts
|
|
2
|
-
var RESULT_BRAND = Symbol("RESULT_BRAND");
|
|
2
|
+
var RESULT_BRAND = /* @__PURE__ */ Symbol("RESULT_BRAND");
|
|
3
3
|
function ok(value) {
|
|
4
4
|
return {
|
|
5
5
|
ok: true,
|
|
@@ -264,6 +264,22 @@ function refineAtAsync(targetPath, predicate, message) {
|
|
|
264
264
|
return ok(value);
|
|
265
265
|
};
|
|
266
266
|
}
|
|
267
|
+
function when(predicate, thenValidator, elseValidator) {
|
|
268
|
+
return (value, path = []) => {
|
|
269
|
+
if (predicate(value)) {
|
|
270
|
+
return thenValidator(value, path);
|
|
271
|
+
}
|
|
272
|
+
return elseValidator ? elseValidator(value, path) : ok(value);
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
function whenAsync(predicate, thenValidator, elseValidator) {
|
|
276
|
+
return async (value, path = []) => {
|
|
277
|
+
if (predicate(value)) {
|
|
278
|
+
return thenValidator(value, path);
|
|
279
|
+
}
|
|
280
|
+
return elseValidator ? elseValidator(value, path) : ok(value);
|
|
281
|
+
};
|
|
282
|
+
}
|
|
267
283
|
|
|
268
284
|
// src/schema/string.ts
|
|
269
285
|
function string(message = "Must be a string") {
|
|
@@ -1071,6 +1087,6 @@ function toStandardSchema(validator) {
|
|
|
1071
1087
|
};
|
|
1072
1088
|
}
|
|
1073
1089
|
|
|
1074
|
-
export { ROOT_ERROR_KEY, _getAbortEarly, _withAbortEarly, array, between, bigint, boolean, chain, chainAsync, date, dateRange, discriminatedUnion, divisibleBy, email, emptyAsOptional, enumValue, finite, formatErrors, futureDate, integer, is, isoDate, isoDateTime, isoDuration, isoTime, literal, matches, max, maxItems, maxLength, min, minItems, minLength, negative, nonEmpty, nonZero, notEmpty, nullable, number, object, oneOf, optional, parseBigInt, parseBool, parseDate, parseEnum, parseISODate, parseJSON, parseNumber, parseString, parseURL, pastDate, pattern, phoneNumber, positive, precision, refine, refineAsync, refineAt, refineAtAsync, required, string, stringEnum, toStandardSchema, todayOrFuture, transform, tuple, tupleOf, union, unique, url, uuid, validate, validateAndFormatResult };
|
|
1090
|
+
export { ROOT_ERROR_KEY, _getAbortEarly, _withAbortEarly, array, between, bigint, boolean, chain, chainAsync, date, dateRange, discriminatedUnion, divisibleBy, email, emptyAsOptional, enumValue, finite, formatErrors, futureDate, integer, is, isoDate, isoDateTime, isoDuration, isoTime, literal, matches, max, maxItems, maxLength, min, minItems, minLength, negative, nonEmpty, nonZero, notEmpty, nullable, number, object, oneOf, optional, parseBigInt, parseBool, parseDate, parseEnum, parseISODate, parseJSON, parseNumber, parseString, parseURL, pastDate, pattern, phoneNumber, positive, precision, refine, refineAsync, refineAt, refineAtAsync, required, string, stringEnum, toStandardSchema, todayOrFuture, transform, tuple, tupleOf, union, unique, url, uuid, validate, validateAndFormatResult, when, whenAsync };
|
|
1075
1091
|
//# sourceMappingURL=index.mjs.map
|
|
1076
1092
|
//# sourceMappingURL=index.mjs.map
|