@railway-ts/pipelines 0.1.23 → 0.1.25
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 +6 -4
- package/dist/schema/index.cjs +85 -3
- package/dist/schema/index.cjs.map +1 -1
- package/dist/schema/index.d.cts +73 -3
- package/dist/schema/index.d.ts +73 -3
- package/dist/schema/index.mjs +81 -4
- package/dist/schema/index.mjs.map +1 -1
- package/docs/API.md +40 -0
- package/docs/RECIPES.md +21 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,12 +29,14 @@ Each layer works independently. Combine them when it makes sense.
|
|
|
29
29
|
|
|
30
30
|
Fully tree-shakable:
|
|
31
31
|
|
|
32
|
-
- `result` --
|
|
33
|
-
- `option` --
|
|
32
|
+
- `result` -- 631 B
|
|
33
|
+
- `option` -- 406 B
|
|
34
34
|
- `composition` -- 233 B
|
|
35
|
-
- `schema` --
|
|
35
|
+
- `schema` -- 3.51 kB
|
|
36
36
|
|
|
37
|
-
**~4.
|
|
37
|
+
**~4.8 kB total** (minified + brotli)
|
|
38
|
+
|
|
39
|
+
See how it compares at [schemabenchmarks.dev](https://schemabenchmarks.dev) — smallest bundle size of all benchmarked libraries.
|
|
38
40
|
|
|
39
41
|
## Install
|
|
40
42
|
|
package/dist/schema/index.cjs
CHANGED
|
@@ -300,7 +300,7 @@ function pattern(regex, message = "Invalid format") {
|
|
|
300
300
|
return ok(value);
|
|
301
301
|
};
|
|
302
302
|
}
|
|
303
|
-
function nonEmpty(message = "
|
|
303
|
+
function nonEmpty(message = "Field must not be empty") {
|
|
304
304
|
return (value, path = []) => {
|
|
305
305
|
if (value.trim().length === 0) {
|
|
306
306
|
return err([{ path, message }]);
|
|
@@ -323,10 +323,87 @@ function url(message = "Invalid URL format") {
|
|
|
323
323
|
};
|
|
324
324
|
}
|
|
325
325
|
function phoneNumber(message = "Invalid phone number format") {
|
|
326
|
-
const phoneRegex = /^\+?[\d
|
|
326
|
+
const phoneRegex = /^\+?[\d\-()]{8,20}$/;
|
|
327
327
|
return (value, path = []) => {
|
|
328
328
|
const cleanedValue = value.replaceAll(/\s+/g, "");
|
|
329
|
-
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")) {
|
|
330
407
|
return err([{ path, message }]);
|
|
331
408
|
}
|
|
332
409
|
return ok(value);
|
|
@@ -1017,6 +1094,10 @@ exports.formatErrors = formatErrors;
|
|
|
1017
1094
|
exports.futureDate = futureDate;
|
|
1018
1095
|
exports.integer = integer;
|
|
1019
1096
|
exports.is = is;
|
|
1097
|
+
exports.isoDate = isoDate;
|
|
1098
|
+
exports.isoDateTime = isoDateTime;
|
|
1099
|
+
exports.isoDuration = isoDuration;
|
|
1100
|
+
exports.isoTime = isoTime;
|
|
1020
1101
|
exports.literal = literal;
|
|
1021
1102
|
exports.matches = matches;
|
|
1022
1103
|
exports.max = max;
|
|
@@ -1063,6 +1144,7 @@ exports.tupleOf = tupleOf;
|
|
|
1063
1144
|
exports.union = union;
|
|
1064
1145
|
exports.unique = unique;
|
|
1065
1146
|
exports.url = url;
|
|
1147
|
+
exports.uuid = uuid;
|
|
1066
1148
|
exports.validate = validate;
|
|
1067
1149
|
exports.validateAndFormatResult = validateAndFormatResult;
|
|
1068
1150
|
//# sourceMappingURL=index.cjs.map
|