@railway-ts/pipelines 0.1.22 → 0.1.24

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.
@@ -246,6 +246,21 @@ declare function validate<T>(value: unknown, validator: MaybeAsyncValidator<unkn
246
246
  declare function validate<T>(value: unknown, validator: MaybeAsyncValidator<unknown, T>, path: string[]): Result<T, ValidationError[]> | Promise<Result<T, ValidationError[]>>;
247
247
  declare function validate<T>(value: unknown, validator: MaybeAsyncValidator<unknown, T>, options: ValidateOptions): Result<T, ValidationError[]> | Promise<Result<T, ValidationError[]>>;
248
248
  declare function validate<T>(value: unknown, validator: MaybeAsyncValidator<unknown, T>, path: string[], options: ValidateOptions): Result<T, ValidationError[]> | Promise<Result<T, ValidationError[]>>;
249
+ /**
250
+ * Check whether a value satisfies a validator, returning a boolean.
251
+ * Always short-circuits on first error for maximum performance.
252
+ *
253
+ * @example
254
+ * is('hello', string()); // true
255
+ * is(42, string()); // false
256
+ * is(input, asyncValidator()); // Promise<boolean>
257
+ *
258
+ * @param value - The value to check
259
+ * @param validator - The validator to apply
260
+ * @returns `true` if valid, `false` otherwise (or a Promise for async validators)
261
+ */
262
+ declare function is(value: unknown, validator: Validator<unknown, unknown>): boolean;
263
+ declare function is(value: unknown, validator: MaybeAsyncValidator<unknown, unknown>): boolean | Promise<boolean>;
249
264
  /**
250
265
  * Format validation errors into a user-friendly object.
251
266
  * Converts array paths to dot/bracket notation strings.
@@ -697,8 +712,8 @@ declare function pattern(regex: RegExp, message?: string): Validator<string>;
697
712
  * @example
698
713
  * const validate = nonEmpty();
699
714
  * validate('John'); // ok("John")
700
- * validate(''); // err([{ path: [], message: 'String must not be empty' }])
701
- * validate(' '); // err([{ path: [], message: 'String must not be empty' }])
715
+ * validate(''); // err([{ path: [], message: 'Field must not be empty' }])
716
+ * validate(' '); // err([{ path: [], message: 'Field must not be empty' }])
702
717
  *
703
718
  * @param message - Custom error message
704
719
  * @returns A validator that checks if a string is not empty
@@ -741,6 +756,76 @@ declare function url(message?: string): Validator<string>;
741
756
  * @returns A validator that checks if a string is a valid phone number
742
757
  */
743
758
  declare function phoneNumber(message?: string): Validator<string>;
759
+ /**
760
+ * Create a validator that ensures a string is a valid UUID (RFC 4122).
761
+ * Accepts any UUID version including NIL UUIDs (all zeros).
762
+ *
763
+ * @example
764
+ * const validate = uuid();
765
+ * validate('550e8400-e29b-41d4-a716-446655440000'); // ok(...)
766
+ * validate('not-a-uuid'); // err([{ path: [], message: 'Invalid UUID format' }])
767
+ *
768
+ * @param message - Custom error message
769
+ * @returns A validator that checks if a string is a valid UUID
770
+ */
771
+ declare function uuid(message?: string): Validator<string>;
772
+ /**
773
+ * Create a validator that ensures a string is a valid ISO 8601 date (YYYY-MM-DD).
774
+ * Validates both format and calendar correctness (e.g., rejects Feb 30).
775
+ *
776
+ * @example
777
+ * const validate = isoDate();
778
+ * validate('2024-01-15'); // ok("2024-01-15")
779
+ * validate('2024-02-30'); // err([{ path: [], message: 'Invalid ISO date format' }])
780
+ *
781
+ * @param message - Custom error message
782
+ * @returns A validator that checks if a string is a valid ISO date
783
+ */
784
+ declare function isoDate(message?: string): Validator<string>;
785
+ /**
786
+ * Create a validator that ensures a string is a valid ISO 8601 / RFC 3339 time.
787
+ * Format: `HH:mm:ss[.fractional][Z|±HH:mm]`. Timezone is optional.
788
+ *
789
+ * @example
790
+ * const validate = isoTime();
791
+ * validate('14:30:00'); // ok("14:30:00")
792
+ * validate('14:30:00Z'); // ok("14:30:00Z")
793
+ * validate('14:30:00+05:30'); // ok("14:30:00+05:30")
794
+ * validate('25:00:00'); // err([{ path: [], message: 'Invalid ISO time format' }])
795
+ *
796
+ * @param message - Custom error message
797
+ * @returns A validator that checks if a string is a valid ISO time
798
+ */
799
+ declare function isoTime(message?: string): Validator<string>;
800
+ /**
801
+ * Create a validator that ensures a string is a valid ISO 8601 / RFC 3339 datetime.
802
+ * Format: `YYYY-MM-DDTHH:mm:ss[.fractional][Z|±HH:mm]`.
803
+ *
804
+ * @example
805
+ * const validate = isoDateTime();
806
+ * validate('2024-01-15T14:30:00Z'); // ok(...)
807
+ * validate('2024-01-15T14:30:00+05:30'); // ok(...)
808
+ * validate('2024-02-30T14:30:00Z'); // err([{ path: [], message: 'Invalid ISO datetime format' }])
809
+ *
810
+ * @param message - Custom error message
811
+ * @returns A validator that checks if a string is a valid ISO datetime
812
+ */
813
+ declare function isoDateTime(message?: string): Validator<string>;
814
+ /**
815
+ * Create a validator that ensures a string is a valid ISO 8601 duration.
816
+ * Format: `PnYnMnDTnHnMnS` or `PnW`.
817
+ *
818
+ * @example
819
+ * const validate = isoDuration();
820
+ * validate('P1Y2M3D'); // ok("P1Y2M3D")
821
+ * validate('PT1H30M'); // ok("PT1H30M")
822
+ * validate('P4W'); // ok("P4W")
823
+ * validate('P'); // err([{ path: [], message: 'Invalid ISO duration format' }])
824
+ *
825
+ * @param message - Custom error message
826
+ * @returns A validator that checks if a string is a valid ISO duration
827
+ */
828
+ declare function isoDuration(message?: string): Validator<string>;
744
829
 
745
830
  /**
746
831
  * Create a validator that parses input into a number.
@@ -1143,4 +1228,4 @@ declare namespace StandardSchemaV1 {
1143
1228
  declare function toStandardSchema<O>(validator: Validator<unknown, O>): StandardSchemaV1<unknown, O>;
1144
1229
  declare function toStandardSchema<O>(validator: MaybeAsyncValidator<unknown, O>): StandardSchemaV1<unknown, O>;
1145
1230
 
1146
- 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, 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, validate, validateAndFormatResult };
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 };
@@ -246,6 +246,21 @@ declare function validate<T>(value: unknown, validator: MaybeAsyncValidator<unkn
246
246
  declare function validate<T>(value: unknown, validator: MaybeAsyncValidator<unknown, T>, path: string[]): Result<T, ValidationError[]> | Promise<Result<T, ValidationError[]>>;
247
247
  declare function validate<T>(value: unknown, validator: MaybeAsyncValidator<unknown, T>, options: ValidateOptions): Result<T, ValidationError[]> | Promise<Result<T, ValidationError[]>>;
248
248
  declare function validate<T>(value: unknown, validator: MaybeAsyncValidator<unknown, T>, path: string[], options: ValidateOptions): Result<T, ValidationError[]> | Promise<Result<T, ValidationError[]>>;
249
+ /**
250
+ * Check whether a value satisfies a validator, returning a boolean.
251
+ * Always short-circuits on first error for maximum performance.
252
+ *
253
+ * @example
254
+ * is('hello', string()); // true
255
+ * is(42, string()); // false
256
+ * is(input, asyncValidator()); // Promise<boolean>
257
+ *
258
+ * @param value - The value to check
259
+ * @param validator - The validator to apply
260
+ * @returns `true` if valid, `false` otherwise (or a Promise for async validators)
261
+ */
262
+ declare function is(value: unknown, validator: Validator<unknown, unknown>): boolean;
263
+ declare function is(value: unknown, validator: MaybeAsyncValidator<unknown, unknown>): boolean | Promise<boolean>;
249
264
  /**
250
265
  * Format validation errors into a user-friendly object.
251
266
  * Converts array paths to dot/bracket notation strings.
@@ -697,8 +712,8 @@ declare function pattern(regex: RegExp, message?: string): Validator<string>;
697
712
  * @example
698
713
  * const validate = nonEmpty();
699
714
  * validate('John'); // ok("John")
700
- * validate(''); // err([{ path: [], message: 'String must not be empty' }])
701
- * validate(' '); // err([{ path: [], message: 'String must not be empty' }])
715
+ * validate(''); // err([{ path: [], message: 'Field must not be empty' }])
716
+ * validate(' '); // err([{ path: [], message: 'Field must not be empty' }])
702
717
  *
703
718
  * @param message - Custom error message
704
719
  * @returns A validator that checks if a string is not empty
@@ -741,6 +756,76 @@ declare function url(message?: string): Validator<string>;
741
756
  * @returns A validator that checks if a string is a valid phone number
742
757
  */
743
758
  declare function phoneNumber(message?: string): Validator<string>;
759
+ /**
760
+ * Create a validator that ensures a string is a valid UUID (RFC 4122).
761
+ * Accepts any UUID version including NIL UUIDs (all zeros).
762
+ *
763
+ * @example
764
+ * const validate = uuid();
765
+ * validate('550e8400-e29b-41d4-a716-446655440000'); // ok(...)
766
+ * validate('not-a-uuid'); // err([{ path: [], message: 'Invalid UUID format' }])
767
+ *
768
+ * @param message - Custom error message
769
+ * @returns A validator that checks if a string is a valid UUID
770
+ */
771
+ declare function uuid(message?: string): Validator<string>;
772
+ /**
773
+ * Create a validator that ensures a string is a valid ISO 8601 date (YYYY-MM-DD).
774
+ * Validates both format and calendar correctness (e.g., rejects Feb 30).
775
+ *
776
+ * @example
777
+ * const validate = isoDate();
778
+ * validate('2024-01-15'); // ok("2024-01-15")
779
+ * validate('2024-02-30'); // err([{ path: [], message: 'Invalid ISO date format' }])
780
+ *
781
+ * @param message - Custom error message
782
+ * @returns A validator that checks if a string is a valid ISO date
783
+ */
784
+ declare function isoDate(message?: string): Validator<string>;
785
+ /**
786
+ * Create a validator that ensures a string is a valid ISO 8601 / RFC 3339 time.
787
+ * Format: `HH:mm:ss[.fractional][Z|±HH:mm]`. Timezone is optional.
788
+ *
789
+ * @example
790
+ * const validate = isoTime();
791
+ * validate('14:30:00'); // ok("14:30:00")
792
+ * validate('14:30:00Z'); // ok("14:30:00Z")
793
+ * validate('14:30:00+05:30'); // ok("14:30:00+05:30")
794
+ * validate('25:00:00'); // err([{ path: [], message: 'Invalid ISO time format' }])
795
+ *
796
+ * @param message - Custom error message
797
+ * @returns A validator that checks if a string is a valid ISO time
798
+ */
799
+ declare function isoTime(message?: string): Validator<string>;
800
+ /**
801
+ * Create a validator that ensures a string is a valid ISO 8601 / RFC 3339 datetime.
802
+ * Format: `YYYY-MM-DDTHH:mm:ss[.fractional][Z|±HH:mm]`.
803
+ *
804
+ * @example
805
+ * const validate = isoDateTime();
806
+ * validate('2024-01-15T14:30:00Z'); // ok(...)
807
+ * validate('2024-01-15T14:30:00+05:30'); // ok(...)
808
+ * validate('2024-02-30T14:30:00Z'); // err([{ path: [], message: 'Invalid ISO datetime format' }])
809
+ *
810
+ * @param message - Custom error message
811
+ * @returns A validator that checks if a string is a valid ISO datetime
812
+ */
813
+ declare function isoDateTime(message?: string): Validator<string>;
814
+ /**
815
+ * Create a validator that ensures a string is a valid ISO 8601 duration.
816
+ * Format: `PnYnMnDTnHnMnS` or `PnW`.
817
+ *
818
+ * @example
819
+ * const validate = isoDuration();
820
+ * validate('P1Y2M3D'); // ok("P1Y2M3D")
821
+ * validate('PT1H30M'); // ok("PT1H30M")
822
+ * validate('P4W'); // ok("P4W")
823
+ * validate('P'); // err([{ path: [], message: 'Invalid ISO duration format' }])
824
+ *
825
+ * @param message - Custom error message
826
+ * @returns A validator that checks if a string is a valid ISO duration
827
+ */
828
+ declare function isoDuration(message?: string): Validator<string>;
744
829
 
745
830
  /**
746
831
  * Create a validator that parses input into a number.
@@ -1143,4 +1228,4 @@ declare namespace StandardSchemaV1 {
1143
1228
  declare function toStandardSchema<O>(validator: Validator<unknown, O>): StandardSchemaV1<unknown, O>;
1144
1229
  declare function toStandardSchema<O>(validator: MaybeAsyncValidator<unknown, O>): StandardSchemaV1<unknown, O>;
1145
1230
 
1146
- 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, 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, validate, validateAndFormatResult };
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 };
@@ -183,6 +183,13 @@ function validate(value, validator, pathOrOptions = [], maybeOptions) {
183
183
  }
184
184
  return validator(value, path);
185
185
  }
186
+ function is(value, validator) {
187
+ const result = _withAbortEarly(true, () => validator(value));
188
+ if (result instanceof Promise) {
189
+ return result.then((r) => r.ok);
190
+ }
191
+ return result.ok;
192
+ }
186
193
  function formatErrors(errors) {
187
194
  return errors.reduce(
188
195
  (acc, error) => {
@@ -291,7 +298,7 @@ function pattern(regex, message = "Invalid format") {
291
298
  return ok(value);
292
299
  };
293
300
  }
294
- function nonEmpty(message = "String must not be empty") {
301
+ function nonEmpty(message = "Field must not be empty") {
295
302
  return (value, path = []) => {
296
303
  if (value.trim().length === 0) {
297
304
  return err([{ path, message }]);
@@ -314,10 +321,87 @@ function url(message = "Invalid URL format") {
314
321
  };
315
322
  }
316
323
  function phoneNumber(message = "Invalid phone number format") {
317
- const phoneRegex = /^\+?[\d\s\-()]{8,20}$/;
324
+ const phoneRegex = /^\+?[\d\-()]{8,20}$/;
318
325
  return (value, path = []) => {
319
326
  const cleanedValue = value.replaceAll(/\s+/g, "");
320
- if (!phoneRegex.test(cleanedValue)) {
327
+ if (!phoneRegex.test(cleanedValue) || cleanedValue.replaceAll(/\D/g, "").length < 7) {
328
+ return err([{ path, message }]);
329
+ }
330
+ return ok(value);
331
+ };
332
+ }
333
+ function uuid(message = "Invalid UUID format") {
334
+ const uuidRegex = /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/i;
335
+ return pattern(uuidRegex, message);
336
+ }
337
+ function isoDate(message = "Invalid ISO date format") {
338
+ const isoDateRegex = /^\d{4}-\d{2}-\d{2}$/;
339
+ return (value, path = []) => {
340
+ if (!isoDateRegex.test(value)) {
341
+ return err([{ path, message }]);
342
+ }
343
+ const date2 = /* @__PURE__ */ new Date(value + "T00:00:00Z");
344
+ if (Number.isNaN(date2.getTime()) || date2.toISOString().slice(0, 10) !== value) {
345
+ return err([{ path, message }]);
346
+ }
347
+ return ok(value);
348
+ };
349
+ }
350
+ function isoTime(message = "Invalid ISO time format") {
351
+ const isoTimeRegex = /^(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:Z|([+-])(\d{2}):(\d{2}))?$/;
352
+ return (value, path = []) => {
353
+ const match2 = isoTimeRegex.exec(value);
354
+ if (!match2) {
355
+ return err([{ path, message }]);
356
+ }
357
+ const hours = Number(match2[1]);
358
+ const minutes = Number(match2[2]);
359
+ const seconds = Number(match2[3]);
360
+ if (hours > 23 || minutes > 59 || seconds > 59) {
361
+ return err([{ path, message }]);
362
+ }
363
+ if (match2[4]) {
364
+ const tzHours = Number(match2[5]);
365
+ const tzMinutes = Number(match2[6]);
366
+ if (tzHours > 23 || tzMinutes > 59) {
367
+ return err([{ path, message }]);
368
+ }
369
+ }
370
+ return ok(value);
371
+ };
372
+ }
373
+ function isoDateTime(message = "Invalid ISO datetime format") {
374
+ const isoDateTimeRegex = /^(\d{4}-\d{2}-\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:Z|([+-])(\d{2}):(\d{2}))?$/;
375
+ return (value, path = []) => {
376
+ const match2 = isoDateTimeRegex.exec(value);
377
+ if (!match2) {
378
+ return err([{ path, message }]);
379
+ }
380
+ const datePart = match2[1];
381
+ const date2 = /* @__PURE__ */ new Date(datePart + "T00:00:00Z");
382
+ if (Number.isNaN(date2.getTime()) || date2.toISOString().slice(0, 10) !== datePart) {
383
+ return err([{ path, message }]);
384
+ }
385
+ const hours = Number(match2[2]);
386
+ const minutes = Number(match2[3]);
387
+ const seconds = Number(match2[4]);
388
+ if (hours > 23 || minutes > 59 || seconds > 59) {
389
+ return err([{ path, message }]);
390
+ }
391
+ if (match2[5]) {
392
+ const tzHours = Number(match2[6]);
393
+ const tzMinutes = Number(match2[7]);
394
+ if (tzHours > 23 || tzMinutes > 59) {
395
+ return err([{ path, message }]);
396
+ }
397
+ }
398
+ return ok(value);
399
+ };
400
+ }
401
+ function isoDuration(message = "Invalid ISO duration format") {
402
+ const isoDurationRegex = /^P(?:\d+W|(?:\d+Y)?(?:\d+M)?(?:\d+D)?(?:T(?:\d+H)?(?:\d+M)?(?:\d+(?:\.\d+)?S)?)?)$/;
403
+ return (value, path = []) => {
404
+ if (!isoDurationRegex.test(value) || value === "P" || value.endsWith("T")) {
321
405
  return err([{ path, message }]);
322
406
  }
323
407
  return ok(value);
@@ -987,6 +1071,6 @@ function toStandardSchema(validator) {
987
1071
  };
988
1072
  }
989
1073
 
990
- export { ROOT_ERROR_KEY, _getAbortEarly, _withAbortEarly, array, between, bigint, boolean, chain, chainAsync, date, dateRange, discriminatedUnion, divisibleBy, email, emptyAsOptional, enumValue, finite, formatErrors, futureDate, integer, 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, validate, validateAndFormatResult };
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 };
991
1075
  //# sourceMappingURL=index.mjs.map
992
1076
  //# sourceMappingURL=index.mjs.map