@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.
- package/dist/schema/index.cjs +93 -3
- package/dist/schema/index.cjs.map +1 -1
- package/dist/schema/index.d.cts +88 -3
- package/dist/schema/index.d.ts +88 -3
- package/dist/schema/index.mjs +88 -4
- package/dist/schema/index.mjs.map +1 -1
- package/docs/API.md +57 -0
- package/docs/GETTING_STARTED.md +12 -0
- package/docs/RECIPES.md +48 -0
- package/package.json +1 -1
package/dist/schema/index.cjs
CHANGED
|
@@ -185,6 +185,13 @@ function validate(value, validator, pathOrOptions = [], maybeOptions) {
|
|
|
185
185
|
}
|
|
186
186
|
return validator(value, path);
|
|
187
187
|
}
|
|
188
|
+
function is(value, validator) {
|
|
189
|
+
const result = _withAbortEarly(true, () => validator(value));
|
|
190
|
+
if (result instanceof Promise) {
|
|
191
|
+
return result.then((r) => r.ok);
|
|
192
|
+
}
|
|
193
|
+
return result.ok;
|
|
194
|
+
}
|
|
188
195
|
function formatErrors(errors) {
|
|
189
196
|
return errors.reduce(
|
|
190
197
|
(acc, error) => {
|
|
@@ -293,7 +300,7 @@ function pattern(regex, message = "Invalid format") {
|
|
|
293
300
|
return ok(value);
|
|
294
301
|
};
|
|
295
302
|
}
|
|
296
|
-
function nonEmpty(message = "
|
|
303
|
+
function nonEmpty(message = "Field must not be empty") {
|
|
297
304
|
return (value, path = []) => {
|
|
298
305
|
if (value.trim().length === 0) {
|
|
299
306
|
return err([{ path, message }]);
|
|
@@ -316,10 +323,87 @@ function url(message = "Invalid URL format") {
|
|
|
316
323
|
};
|
|
317
324
|
}
|
|
318
325
|
function phoneNumber(message = "Invalid phone number format") {
|
|
319
|
-
const phoneRegex = /^\+?[\d
|
|
326
|
+
const phoneRegex = /^\+?[\d\-()]{8,20}$/;
|
|
320
327
|
return (value, path = []) => {
|
|
321
328
|
const cleanedValue = value.replaceAll(/\s+/g, "");
|
|
322
|
-
if (!phoneRegex.test(cleanedValue)) {
|
|
329
|
+
if (!phoneRegex.test(cleanedValue) || cleanedValue.replaceAll(/\D/g, "").length < 7) {
|
|
330
|
+
return err([{ path, message }]);
|
|
331
|
+
}
|
|
332
|
+
return ok(value);
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
function uuid(message = "Invalid UUID format") {
|
|
336
|
+
const uuidRegex = /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/i;
|
|
337
|
+
return pattern(uuidRegex, message);
|
|
338
|
+
}
|
|
339
|
+
function isoDate(message = "Invalid ISO date format") {
|
|
340
|
+
const isoDateRegex = /^\d{4}-\d{2}-\d{2}$/;
|
|
341
|
+
return (value, path = []) => {
|
|
342
|
+
if (!isoDateRegex.test(value)) {
|
|
343
|
+
return err([{ path, message }]);
|
|
344
|
+
}
|
|
345
|
+
const date2 = /* @__PURE__ */ new Date(value + "T00:00:00Z");
|
|
346
|
+
if (Number.isNaN(date2.getTime()) || date2.toISOString().slice(0, 10) !== value) {
|
|
347
|
+
return err([{ path, message }]);
|
|
348
|
+
}
|
|
349
|
+
return ok(value);
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
function isoTime(message = "Invalid ISO time format") {
|
|
353
|
+
const isoTimeRegex = /^(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:Z|([+-])(\d{2}):(\d{2}))?$/;
|
|
354
|
+
return (value, path = []) => {
|
|
355
|
+
const match2 = isoTimeRegex.exec(value);
|
|
356
|
+
if (!match2) {
|
|
357
|
+
return err([{ path, message }]);
|
|
358
|
+
}
|
|
359
|
+
const hours = Number(match2[1]);
|
|
360
|
+
const minutes = Number(match2[2]);
|
|
361
|
+
const seconds = Number(match2[3]);
|
|
362
|
+
if (hours > 23 || minutes > 59 || seconds > 59) {
|
|
363
|
+
return err([{ path, message }]);
|
|
364
|
+
}
|
|
365
|
+
if (match2[4]) {
|
|
366
|
+
const tzHours = Number(match2[5]);
|
|
367
|
+
const tzMinutes = Number(match2[6]);
|
|
368
|
+
if (tzHours > 23 || tzMinutes > 59) {
|
|
369
|
+
return err([{ path, message }]);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return ok(value);
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
function isoDateTime(message = "Invalid ISO datetime format") {
|
|
376
|
+
const isoDateTimeRegex = /^(\d{4}-\d{2}-\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:Z|([+-])(\d{2}):(\d{2}))?$/;
|
|
377
|
+
return (value, path = []) => {
|
|
378
|
+
const match2 = isoDateTimeRegex.exec(value);
|
|
379
|
+
if (!match2) {
|
|
380
|
+
return err([{ path, message }]);
|
|
381
|
+
}
|
|
382
|
+
const datePart = match2[1];
|
|
383
|
+
const date2 = /* @__PURE__ */ new Date(datePart + "T00:00:00Z");
|
|
384
|
+
if (Number.isNaN(date2.getTime()) || date2.toISOString().slice(0, 10) !== datePart) {
|
|
385
|
+
return err([{ path, message }]);
|
|
386
|
+
}
|
|
387
|
+
const hours = Number(match2[2]);
|
|
388
|
+
const minutes = Number(match2[3]);
|
|
389
|
+
const seconds = Number(match2[4]);
|
|
390
|
+
if (hours > 23 || minutes > 59 || seconds > 59) {
|
|
391
|
+
return err([{ path, message }]);
|
|
392
|
+
}
|
|
393
|
+
if (match2[5]) {
|
|
394
|
+
const tzHours = Number(match2[6]);
|
|
395
|
+
const tzMinutes = Number(match2[7]);
|
|
396
|
+
if (tzHours > 23 || tzMinutes > 59) {
|
|
397
|
+
return err([{ path, message }]);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return ok(value);
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
function isoDuration(message = "Invalid ISO duration format") {
|
|
404
|
+
const isoDurationRegex = /^P(?:\d+W|(?:\d+Y)?(?:\d+M)?(?:\d+D)?(?:T(?:\d+H)?(?:\d+M)?(?:\d+(?:\.\d+)?S)?)?)$/;
|
|
405
|
+
return (value, path = []) => {
|
|
406
|
+
if (!isoDurationRegex.test(value) || value === "P" || value.endsWith("T")) {
|
|
323
407
|
return err([{ path, message }]);
|
|
324
408
|
}
|
|
325
409
|
return ok(value);
|
|
@@ -1009,6 +1093,11 @@ exports.finite = finite;
|
|
|
1009
1093
|
exports.formatErrors = formatErrors;
|
|
1010
1094
|
exports.futureDate = futureDate;
|
|
1011
1095
|
exports.integer = integer;
|
|
1096
|
+
exports.is = is;
|
|
1097
|
+
exports.isoDate = isoDate;
|
|
1098
|
+
exports.isoDateTime = isoDateTime;
|
|
1099
|
+
exports.isoDuration = isoDuration;
|
|
1100
|
+
exports.isoTime = isoTime;
|
|
1012
1101
|
exports.literal = literal;
|
|
1013
1102
|
exports.matches = matches;
|
|
1014
1103
|
exports.max = max;
|
|
@@ -1055,6 +1144,7 @@ exports.tupleOf = tupleOf;
|
|
|
1055
1144
|
exports.union = union;
|
|
1056
1145
|
exports.unique = unique;
|
|
1057
1146
|
exports.url = url;
|
|
1147
|
+
exports.uuid = uuid;
|
|
1058
1148
|
exports.validate = validate;
|
|
1059
1149
|
exports.validateAndFormatResult = validateAndFormatResult;
|
|
1060
1150
|
//# sourceMappingURL=index.cjs.map
|