guarden 1.0.0
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/LICENSE +21 -0
- package/README.md +370 -0
- package/dist/cjs/assert/assertions.js +82 -0
- package/dist/cjs/assert/assertions.js.map +1 -0
- package/dist/cjs/assert/index.js +13 -0
- package/dist/cjs/assert/index.js.map +1 -0
- package/dist/cjs/assert/invariant.js +43 -0
- package/dist/cjs/assert/invariant.js.map +1 -0
- package/dist/cjs/env/index.js +11 -0
- package/dist/cjs/env/index.js.map +1 -0
- package/dist/cjs/env/schema.js +313 -0
- package/dist/cjs/env/schema.js.map +1 -0
- package/dist/cjs/guards/advanced.js +190 -0
- package/dist/cjs/guards/advanced.js.map +1 -0
- package/dist/cjs/guards/combinators.js +195 -0
- package/dist/cjs/guards/combinators.js.map +1 -0
- package/dist/cjs/guards/index.js +68 -0
- package/dist/cjs/guards/index.js.map +1 -0
- package/dist/cjs/guards/primitives.js +123 -0
- package/dist/cjs/guards/primitives.js.map +1 -0
- package/dist/cjs/guards/structures.js +113 -0
- package/dist/cjs/guards/structures.js.map +1 -0
- package/dist/cjs/index.js +135 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/result/async.js +132 -0
- package/dist/cjs/result/async.js.map +1 -0
- package/dist/cjs/result/index.js +15 -0
- package/dist/cjs/result/index.js.map +1 -0
- package/dist/cjs/result/option.js +175 -0
- package/dist/cjs/result/option.js.map +1 -0
- package/dist/cjs/result/result.js +208 -0
- package/dist/cjs/result/result.js.map +1 -0
- package/dist/cjs/transform/coerce.js +151 -0
- package/dist/cjs/transform/coerce.js.map +1 -0
- package/dist/cjs/transform/index.js +36 -0
- package/dist/cjs/transform/index.js.map +1 -0
- package/dist/cjs/transform/pipe.js +18 -0
- package/dist/cjs/transform/pipe.js.map +1 -0
- package/dist/cjs/transform/sanitize.js +218 -0
- package/dist/cjs/transform/sanitize.js.map +1 -0
- package/dist/cjs/utils/errors.js +94 -0
- package/dist/cjs/utils/errors.js.map +1 -0
- package/dist/cjs/utils/types.js +6 -0
- package/dist/cjs/utils/types.js.map +1 -0
- package/dist/esm/assert/assertions.js +75 -0
- package/dist/esm/assert/assertions.js.map +1 -0
- package/dist/esm/assert/index.js +3 -0
- package/dist/esm/assert/index.js.map +1 -0
- package/dist/esm/assert/invariant.js +39 -0
- package/dist/esm/assert/invariant.js.map +1 -0
- package/dist/esm/env/index.js +2 -0
- package/dist/esm/env/index.js.map +1 -0
- package/dist/esm/env/schema.js +304 -0
- package/dist/esm/env/schema.js.map +1 -0
- package/dist/esm/guards/advanced.js +170 -0
- package/dist/esm/guards/advanced.js.map +1 -0
- package/dist/esm/guards/combinators.js +182 -0
- package/dist/esm/guards/combinators.js.map +1 -0
- package/dist/esm/guards/index.js +8 -0
- package/dist/esm/guards/index.js.map +1 -0
- package/dist/esm/guards/primitives.js +108 -0
- package/dist/esm/guards/primitives.js.map +1 -0
- package/dist/esm/guards/structures.js +97 -0
- package/dist/esm/guards/structures.js.map +1 -0
- package/dist/esm/index.js +17 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/result/async.js +127 -0
- package/dist/esm/result/async.js.map +1 -0
- package/dist/esm/result/index.js +4 -0
- package/dist/esm/result/index.js.map +1 -0
- package/dist/esm/result/option.js +170 -0
- package/dist/esm/result/option.js.map +1 -0
- package/dist/esm/result/result.js +203 -0
- package/dist/esm/result/result.js.map +1 -0
- package/dist/esm/transform/coerce.js +143 -0
- package/dist/esm/transform/coerce.js.map +1 -0
- package/dist/esm/transform/index.js +4 -0
- package/dist/esm/transform/index.js.map +1 -0
- package/dist/esm/transform/pipe.js +14 -0
- package/dist/esm/transform/pipe.js.map +1 -0
- package/dist/esm/transform/sanitize.js +195 -0
- package/dist/esm/transform/sanitize.js.map +1 -0
- package/dist/esm/utils/errors.js +84 -0
- package/dist/esm/utils/errors.js.map +1 -0
- package/dist/esm/utils/types.js +5 -0
- package/dist/esm/utils/types.js.map +1 -0
- package/dist/types/assert/assertions.d.ts +52 -0
- package/dist/types/assert/assertions.d.ts.map +1 -0
- package/dist/types/assert/index.d.ts +3 -0
- package/dist/types/assert/index.d.ts.map +1 -0
- package/dist/types/assert/invariant.d.ts +29 -0
- package/dist/types/assert/invariant.d.ts.map +1 -0
- package/dist/types/env/index.d.ts +2 -0
- package/dist/types/env/index.d.ts.map +1 -0
- package/dist/types/env/schema.d.ts +131 -0
- package/dist/types/env/schema.d.ts.map +1 -0
- package/dist/types/guards/advanced.d.ts +101 -0
- package/dist/types/guards/advanced.d.ts.map +1 -0
- package/dist/types/guards/combinators.d.ts +120 -0
- package/dist/types/guards/combinators.d.ts.map +1 -0
- package/dist/types/guards/index.d.ts +5 -0
- package/dist/types/guards/index.d.ts.map +1 -0
- package/dist/types/guards/primitives.d.ts +75 -0
- package/dist/types/guards/primitives.d.ts.map +1 -0
- package/dist/types/guards/structures.d.ts +58 -0
- package/dist/types/guards/structures.d.ts.map +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/result/async.d.ts +72 -0
- package/dist/types/result/async.d.ts.map +1 -0
- package/dist/types/result/index.d.ts +4 -0
- package/dist/types/result/index.d.ts.map +1 -0
- package/dist/types/result/option.d.ts +106 -0
- package/dist/types/result/option.d.ts.map +1 -0
- package/dist/types/result/result.d.ts +126 -0
- package/dist/types/result/result.d.ts.map +1 -0
- package/dist/types/transform/coerce.d.ts +73 -0
- package/dist/types/transform/coerce.d.ts.map +1 -0
- package/dist/types/transform/index.d.ts +4 -0
- package/dist/types/transform/index.d.ts.map +1 -0
- package/dist/types/transform/pipe.d.ts +44 -0
- package/dist/types/transform/pipe.d.ts.map +1 -0
- package/dist/types/transform/sanitize.d.ts +108 -0
- package/dist/types/transform/sanitize.d.ts.map +1 -0
- package/dist/types/utils/errors.d.ts +51 -0
- package/dist/types/utils/errors.d.ts.map +1 -0
- package/dist/types/utils/types.d.ts +29 -0
- package/dist/types/utils/types.d.ts.map +1 -0
- package/package.json +144 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================================
|
|
3
|
+
// Guarden — Main Entry Point
|
|
4
|
+
// TypeScript-First Runtime Safety Toolkit
|
|
5
|
+
// ============================================================================
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.tuple = exports.shape = exports.not = exports.or = exports.and = exports.isInstanceOf = exports.isMaxLength = exports.isMinLength = exports.isMatch = exports.isOneOf = exports.isInRange = exports.isNonEmptyArray = exports.isSafeInteger = exports.isInteger = exports.isNegativeNumber = exports.isPositiveNumber = exports.isHexColor = exports.isJSONString = exports.isISO8601 = exports.isUUID = exports.isURL = exports.isEmail = exports.isNonEmptyString = exports.isTypedArray = exports.isArrayBuffer = exports.isPromise = exports.isError = exports.isRegExp = exports.isValidDate = exports.isDate = exports.isWeakSet = exports.isWeakMap = exports.isSet = exports.isMap = exports.isPlainObject = exports.isObject = exports.isArray = exports.isPrimitive = exports.isFunction = exports.isNonNullish = exports.isNullish = exports.isUndefined = exports.isNull = exports.isSymbol = exports.isBigInt = exports.isBoolean = exports.isFiniteNumber = exports.isNumberIncludingNaN = exports.isNumber = exports.isString = void 0;
|
|
8
|
+
exports.countOccurrences = exports.reverse = exports.padEnd = exports.padStart = exports.collapseWhitespace = exports.removeWhitespace = exports.slugify = exports.truncate = exports.unescapeHtml = exports.escapeHtml = exports.stripHtml = exports.snakeCase = exports.kebabCase = exports.camelCase = exports.titleCase = exports.capitalize = exports.uppercase = exports.lowercase = exports.trimEnd = exports.trimStart = exports.trim = exports.toInteger = exports.toArray = exports.toDate = exports.toBoolean = exports.toString = exports.toNumber = exports.flow = exports.pipe = exports.OptionAsync = exports.ResultAsync = exports.OptionUtils = exports.None = exports.Some = exports.ResultUtils = exports.Err = exports.Ok = exports.unreachable = exports.invariant = exports.assertTruthy = exports.assertType = exports.assertNonNull = exports.assertDefined = exports.assert = exports.nullable = exports.optional = exports.refine = exports.recordOf = exports.mapOf = exports.arrayOf = void 0;
|
|
9
|
+
exports.UnreachableError = exports.EnvConfigError = exports.EnvValidationError = exports.CoercionError = exports.InvariantError = exports.AssertionError = exports.GuardenError = exports.EnvField = exports.envEnum = exports.envBoolean = exports.envNumber = exports.envString = exports.createEnv = void 0;
|
|
10
|
+
// Guards
|
|
11
|
+
var index_js_1 = require("./guards/index.js");
|
|
12
|
+
Object.defineProperty(exports, "isString", { enumerable: true, get: function () { return index_js_1.isString; } });
|
|
13
|
+
Object.defineProperty(exports, "isNumber", { enumerable: true, get: function () { return index_js_1.isNumber; } });
|
|
14
|
+
Object.defineProperty(exports, "isNumberIncludingNaN", { enumerable: true, get: function () { return index_js_1.isNumberIncludingNaN; } });
|
|
15
|
+
Object.defineProperty(exports, "isFiniteNumber", { enumerable: true, get: function () { return index_js_1.isFiniteNumber; } });
|
|
16
|
+
Object.defineProperty(exports, "isBoolean", { enumerable: true, get: function () { return index_js_1.isBoolean; } });
|
|
17
|
+
Object.defineProperty(exports, "isBigInt", { enumerable: true, get: function () { return index_js_1.isBigInt; } });
|
|
18
|
+
Object.defineProperty(exports, "isSymbol", { enumerable: true, get: function () { return index_js_1.isSymbol; } });
|
|
19
|
+
Object.defineProperty(exports, "isNull", { enumerable: true, get: function () { return index_js_1.isNull; } });
|
|
20
|
+
Object.defineProperty(exports, "isUndefined", { enumerable: true, get: function () { return index_js_1.isUndefined; } });
|
|
21
|
+
Object.defineProperty(exports, "isNullish", { enumerable: true, get: function () { return index_js_1.isNullish; } });
|
|
22
|
+
Object.defineProperty(exports, "isNonNullish", { enumerable: true, get: function () { return index_js_1.isNonNullish; } });
|
|
23
|
+
Object.defineProperty(exports, "isFunction", { enumerable: true, get: function () { return index_js_1.isFunction; } });
|
|
24
|
+
Object.defineProperty(exports, "isPrimitive", { enumerable: true, get: function () { return index_js_1.isPrimitive; } });
|
|
25
|
+
Object.defineProperty(exports, "isArray", { enumerable: true, get: function () { return index_js_1.isArray; } });
|
|
26
|
+
Object.defineProperty(exports, "isObject", { enumerable: true, get: function () { return index_js_1.isObject; } });
|
|
27
|
+
Object.defineProperty(exports, "isPlainObject", { enumerable: true, get: function () { return index_js_1.isPlainObject; } });
|
|
28
|
+
Object.defineProperty(exports, "isMap", { enumerable: true, get: function () { return index_js_1.isMap; } });
|
|
29
|
+
Object.defineProperty(exports, "isSet", { enumerable: true, get: function () { return index_js_1.isSet; } });
|
|
30
|
+
Object.defineProperty(exports, "isWeakMap", { enumerable: true, get: function () { return index_js_1.isWeakMap; } });
|
|
31
|
+
Object.defineProperty(exports, "isWeakSet", { enumerable: true, get: function () { return index_js_1.isWeakSet; } });
|
|
32
|
+
Object.defineProperty(exports, "isDate", { enumerable: true, get: function () { return index_js_1.isDate; } });
|
|
33
|
+
Object.defineProperty(exports, "isValidDate", { enumerable: true, get: function () { return index_js_1.isValidDate; } });
|
|
34
|
+
Object.defineProperty(exports, "isRegExp", { enumerable: true, get: function () { return index_js_1.isRegExp; } });
|
|
35
|
+
Object.defineProperty(exports, "isError", { enumerable: true, get: function () { return index_js_1.isError; } });
|
|
36
|
+
Object.defineProperty(exports, "isPromise", { enumerable: true, get: function () { return index_js_1.isPromise; } });
|
|
37
|
+
Object.defineProperty(exports, "isArrayBuffer", { enumerable: true, get: function () { return index_js_1.isArrayBuffer; } });
|
|
38
|
+
Object.defineProperty(exports, "isTypedArray", { enumerable: true, get: function () { return index_js_1.isTypedArray; } });
|
|
39
|
+
Object.defineProperty(exports, "isNonEmptyString", { enumerable: true, get: function () { return index_js_1.isNonEmptyString; } });
|
|
40
|
+
Object.defineProperty(exports, "isEmail", { enumerable: true, get: function () { return index_js_1.isEmail; } });
|
|
41
|
+
Object.defineProperty(exports, "isURL", { enumerable: true, get: function () { return index_js_1.isURL; } });
|
|
42
|
+
Object.defineProperty(exports, "isUUID", { enumerable: true, get: function () { return index_js_1.isUUID; } });
|
|
43
|
+
Object.defineProperty(exports, "isISO8601", { enumerable: true, get: function () { return index_js_1.isISO8601; } });
|
|
44
|
+
Object.defineProperty(exports, "isJSONString", { enumerable: true, get: function () { return index_js_1.isJSONString; } });
|
|
45
|
+
Object.defineProperty(exports, "isHexColor", { enumerable: true, get: function () { return index_js_1.isHexColor; } });
|
|
46
|
+
Object.defineProperty(exports, "isPositiveNumber", { enumerable: true, get: function () { return index_js_1.isPositiveNumber; } });
|
|
47
|
+
Object.defineProperty(exports, "isNegativeNumber", { enumerable: true, get: function () { return index_js_1.isNegativeNumber; } });
|
|
48
|
+
Object.defineProperty(exports, "isInteger", { enumerable: true, get: function () { return index_js_1.isInteger; } });
|
|
49
|
+
Object.defineProperty(exports, "isSafeInteger", { enumerable: true, get: function () { return index_js_1.isSafeInteger; } });
|
|
50
|
+
Object.defineProperty(exports, "isNonEmptyArray", { enumerable: true, get: function () { return index_js_1.isNonEmptyArray; } });
|
|
51
|
+
Object.defineProperty(exports, "isInRange", { enumerable: true, get: function () { return index_js_1.isInRange; } });
|
|
52
|
+
Object.defineProperty(exports, "isOneOf", { enumerable: true, get: function () { return index_js_1.isOneOf; } });
|
|
53
|
+
Object.defineProperty(exports, "isMatch", { enumerable: true, get: function () { return index_js_1.isMatch; } });
|
|
54
|
+
Object.defineProperty(exports, "isMinLength", { enumerable: true, get: function () { return index_js_1.isMinLength; } });
|
|
55
|
+
Object.defineProperty(exports, "isMaxLength", { enumerable: true, get: function () { return index_js_1.isMaxLength; } });
|
|
56
|
+
Object.defineProperty(exports, "isInstanceOf", { enumerable: true, get: function () { return index_js_1.isInstanceOf; } });
|
|
57
|
+
Object.defineProperty(exports, "and", { enumerable: true, get: function () { return index_js_1.and; } });
|
|
58
|
+
Object.defineProperty(exports, "or", { enumerable: true, get: function () { return index_js_1.or; } });
|
|
59
|
+
Object.defineProperty(exports, "not", { enumerable: true, get: function () { return index_js_1.not; } });
|
|
60
|
+
Object.defineProperty(exports, "shape", { enumerable: true, get: function () { return index_js_1.shape; } });
|
|
61
|
+
Object.defineProperty(exports, "tuple", { enumerable: true, get: function () { return index_js_1.tuple; } });
|
|
62
|
+
Object.defineProperty(exports, "arrayOf", { enumerable: true, get: function () { return index_js_1.arrayOf; } });
|
|
63
|
+
Object.defineProperty(exports, "mapOf", { enumerable: true, get: function () { return index_js_1.mapOf; } });
|
|
64
|
+
Object.defineProperty(exports, "recordOf", { enumerable: true, get: function () { return index_js_1.recordOf; } });
|
|
65
|
+
Object.defineProperty(exports, "refine", { enumerable: true, get: function () { return index_js_1.refine; } });
|
|
66
|
+
Object.defineProperty(exports, "optional", { enumerable: true, get: function () { return index_js_1.optional; } });
|
|
67
|
+
Object.defineProperty(exports, "nullable", { enumerable: true, get: function () { return index_js_1.nullable; } });
|
|
68
|
+
// Assert
|
|
69
|
+
var index_js_2 = require("./assert/index.js");
|
|
70
|
+
Object.defineProperty(exports, "assert", { enumerable: true, get: function () { return index_js_2.assert; } });
|
|
71
|
+
Object.defineProperty(exports, "assertDefined", { enumerable: true, get: function () { return index_js_2.assertDefined; } });
|
|
72
|
+
Object.defineProperty(exports, "assertNonNull", { enumerable: true, get: function () { return index_js_2.assertNonNull; } });
|
|
73
|
+
Object.defineProperty(exports, "assertType", { enumerable: true, get: function () { return index_js_2.assertType; } });
|
|
74
|
+
Object.defineProperty(exports, "assertTruthy", { enumerable: true, get: function () { return index_js_2.assertTruthy; } });
|
|
75
|
+
Object.defineProperty(exports, "invariant", { enumerable: true, get: function () { return index_js_2.invariant; } });
|
|
76
|
+
Object.defineProperty(exports, "unreachable", { enumerable: true, get: function () { return index_js_2.unreachable; } });
|
|
77
|
+
// Result & Option
|
|
78
|
+
var index_js_3 = require("./result/index.js");
|
|
79
|
+
Object.defineProperty(exports, "Ok", { enumerable: true, get: function () { return index_js_3.Ok; } });
|
|
80
|
+
Object.defineProperty(exports, "Err", { enumerable: true, get: function () { return index_js_3.Err; } });
|
|
81
|
+
Object.defineProperty(exports, "ResultUtils", { enumerable: true, get: function () { return index_js_3.ResultUtils; } });
|
|
82
|
+
Object.defineProperty(exports, "Some", { enumerable: true, get: function () { return index_js_3.Some; } });
|
|
83
|
+
Object.defineProperty(exports, "None", { enumerable: true, get: function () { return index_js_3.None; } });
|
|
84
|
+
Object.defineProperty(exports, "OptionUtils", { enumerable: true, get: function () { return index_js_3.OptionUtils; } });
|
|
85
|
+
Object.defineProperty(exports, "ResultAsync", { enumerable: true, get: function () { return index_js_3.ResultAsync; } });
|
|
86
|
+
Object.defineProperty(exports, "OptionAsync", { enumerable: true, get: function () { return index_js_3.OptionAsync; } });
|
|
87
|
+
// Transform
|
|
88
|
+
var index_js_4 = require("./transform/index.js");
|
|
89
|
+
Object.defineProperty(exports, "pipe", { enumerable: true, get: function () { return index_js_4.pipe; } });
|
|
90
|
+
Object.defineProperty(exports, "flow", { enumerable: true, get: function () { return index_js_4.flow; } });
|
|
91
|
+
Object.defineProperty(exports, "toNumber", { enumerable: true, get: function () { return index_js_4.toNumber; } });
|
|
92
|
+
Object.defineProperty(exports, "toString", { enumerable: true, get: function () { return index_js_4.toString; } });
|
|
93
|
+
Object.defineProperty(exports, "toBoolean", { enumerable: true, get: function () { return index_js_4.toBoolean; } });
|
|
94
|
+
Object.defineProperty(exports, "toDate", { enumerable: true, get: function () { return index_js_4.toDate; } });
|
|
95
|
+
Object.defineProperty(exports, "toArray", { enumerable: true, get: function () { return index_js_4.toArray; } });
|
|
96
|
+
Object.defineProperty(exports, "toInteger", { enumerable: true, get: function () { return index_js_4.toInteger; } });
|
|
97
|
+
Object.defineProperty(exports, "trim", { enumerable: true, get: function () { return index_js_4.trim; } });
|
|
98
|
+
Object.defineProperty(exports, "trimStart", { enumerable: true, get: function () { return index_js_4.trimStart; } });
|
|
99
|
+
Object.defineProperty(exports, "trimEnd", { enumerable: true, get: function () { return index_js_4.trimEnd; } });
|
|
100
|
+
Object.defineProperty(exports, "lowercase", { enumerable: true, get: function () { return index_js_4.lowercase; } });
|
|
101
|
+
Object.defineProperty(exports, "uppercase", { enumerable: true, get: function () { return index_js_4.uppercase; } });
|
|
102
|
+
Object.defineProperty(exports, "capitalize", { enumerable: true, get: function () { return index_js_4.capitalize; } });
|
|
103
|
+
Object.defineProperty(exports, "titleCase", { enumerable: true, get: function () { return index_js_4.titleCase; } });
|
|
104
|
+
Object.defineProperty(exports, "camelCase", { enumerable: true, get: function () { return index_js_4.camelCase; } });
|
|
105
|
+
Object.defineProperty(exports, "kebabCase", { enumerable: true, get: function () { return index_js_4.kebabCase; } });
|
|
106
|
+
Object.defineProperty(exports, "snakeCase", { enumerable: true, get: function () { return index_js_4.snakeCase; } });
|
|
107
|
+
Object.defineProperty(exports, "stripHtml", { enumerable: true, get: function () { return index_js_4.stripHtml; } });
|
|
108
|
+
Object.defineProperty(exports, "escapeHtml", { enumerable: true, get: function () { return index_js_4.escapeHtml; } });
|
|
109
|
+
Object.defineProperty(exports, "unescapeHtml", { enumerable: true, get: function () { return index_js_4.unescapeHtml; } });
|
|
110
|
+
Object.defineProperty(exports, "truncate", { enumerable: true, get: function () { return index_js_4.truncate; } });
|
|
111
|
+
Object.defineProperty(exports, "slugify", { enumerable: true, get: function () { return index_js_4.slugify; } });
|
|
112
|
+
Object.defineProperty(exports, "removeWhitespace", { enumerable: true, get: function () { return index_js_4.removeWhitespace; } });
|
|
113
|
+
Object.defineProperty(exports, "collapseWhitespace", { enumerable: true, get: function () { return index_js_4.collapseWhitespace; } });
|
|
114
|
+
Object.defineProperty(exports, "padStart", { enumerable: true, get: function () { return index_js_4.padStart; } });
|
|
115
|
+
Object.defineProperty(exports, "padEnd", { enumerable: true, get: function () { return index_js_4.padEnd; } });
|
|
116
|
+
Object.defineProperty(exports, "reverse", { enumerable: true, get: function () { return index_js_4.reverse; } });
|
|
117
|
+
Object.defineProperty(exports, "countOccurrences", { enumerable: true, get: function () { return index_js_4.countOccurrences; } });
|
|
118
|
+
// Env
|
|
119
|
+
var index_js_5 = require("./env/index.js");
|
|
120
|
+
Object.defineProperty(exports, "createEnv", { enumerable: true, get: function () { return index_js_5.createEnv; } });
|
|
121
|
+
Object.defineProperty(exports, "envString", { enumerable: true, get: function () { return index_js_5.envString; } });
|
|
122
|
+
Object.defineProperty(exports, "envNumber", { enumerable: true, get: function () { return index_js_5.envNumber; } });
|
|
123
|
+
Object.defineProperty(exports, "envBoolean", { enumerable: true, get: function () { return index_js_5.envBoolean; } });
|
|
124
|
+
Object.defineProperty(exports, "envEnum", { enumerable: true, get: function () { return index_js_5.envEnum; } });
|
|
125
|
+
Object.defineProperty(exports, "EnvField", { enumerable: true, get: function () { return index_js_5.EnvField; } });
|
|
126
|
+
// Errors
|
|
127
|
+
var errors_js_1 = require("./utils/errors.js");
|
|
128
|
+
Object.defineProperty(exports, "GuardenError", { enumerable: true, get: function () { return errors_js_1.GuardenError; } });
|
|
129
|
+
Object.defineProperty(exports, "AssertionError", { enumerable: true, get: function () { return errors_js_1.AssertionError; } });
|
|
130
|
+
Object.defineProperty(exports, "InvariantError", { enumerable: true, get: function () { return errors_js_1.InvariantError; } });
|
|
131
|
+
Object.defineProperty(exports, "CoercionError", { enumerable: true, get: function () { return errors_js_1.CoercionError; } });
|
|
132
|
+
Object.defineProperty(exports, "EnvValidationError", { enumerable: true, get: function () { return errors_js_1.EnvValidationError; } });
|
|
133
|
+
Object.defineProperty(exports, "EnvConfigError", { enumerable: true, get: function () { return errors_js_1.EnvConfigError; } });
|
|
134
|
+
Object.defineProperty(exports, "UnreachableError", { enumerable: true, get: function () { return errors_js_1.UnreachableError; } });
|
|
135
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,+EAA+E;AAC/E,6BAA6B;AAC7B,0CAA0C;AAC1C,+EAA+E;;;;;AAE/E,SAAS;AACT,8CAyD2B;AAxDzB,oGAAA,QAAQ,OAAA;AACR,oGAAA,QAAQ,OAAA;AACR,gHAAA,oBAAoB,OAAA;AACpB,0GAAA,cAAc,OAAA;AACd,qGAAA,SAAS,OAAA;AACT,oGAAA,QAAQ,OAA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AA,SAAS,OAAA;AACT,qGAAA,SAAS,OAAA;AACT,sGAAA,UAAU,OAAA;AACV,mGAAA,OAAO,OAAA;AACP,oGAAA,QAAQ,OAAA;AAGV,SAAS;AACT,+CAQ2B;AAPzB,yGAAA,YAAY,OAAA;AACZ,2GAAA,cAAc,OAAA;AACd,2GAAA,cAAc,OAAA;AACd,0GAAA,aAAa,OAAA;AACb,+GAAA,kBAAkB,OAAA;AAClB,2GAAA,cAAc,OAAA;AACd,6GAAA,gBAAgB,OAAA"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================================
|
|
3
|
+
// Guarden — Async Result & Option
|
|
4
|
+
// ============================================================================
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.OptionAsync = exports.ResultAsync = void 0;
|
|
7
|
+
const result_js_1 = require("./result.js");
|
|
8
|
+
const option_js_1 = require("./option.js");
|
|
9
|
+
/**
|
|
10
|
+
* A Result wrapped in a Promise, with chainable async operations.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const result = ResultAsync.from(fetch('/api/user'))
|
|
15
|
+
* .map(res => res.json())
|
|
16
|
+
* .mapErr(err => new ApiError(err.message));
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
class ResultAsync {
|
|
20
|
+
promise;
|
|
21
|
+
constructor(promise) {
|
|
22
|
+
this.promise = promise;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create from a Promise that may reject.
|
|
26
|
+
*/
|
|
27
|
+
static from(promise) {
|
|
28
|
+
return new ResultAsync(result_js_1.ResultUtils.fromPromise(promise));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Create from a Result.
|
|
32
|
+
*/
|
|
33
|
+
static fromResult(result) {
|
|
34
|
+
return new ResultAsync(Promise.resolve(result));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Create an Ok ResultAsync.
|
|
38
|
+
*/
|
|
39
|
+
static ok(value) {
|
|
40
|
+
return new ResultAsync(Promise.resolve((0, result_js_1.Ok)(value)));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Create an Err ResultAsync.
|
|
44
|
+
*/
|
|
45
|
+
static err(error) {
|
|
46
|
+
return new ResultAsync(Promise.resolve((0, result_js_1.Err)(error)));
|
|
47
|
+
}
|
|
48
|
+
/** Transform the success value. */
|
|
49
|
+
map(fn) {
|
|
50
|
+
return new ResultAsync(this.promise.then((r) => r.map(fn)));
|
|
51
|
+
}
|
|
52
|
+
/** Transform the error value. */
|
|
53
|
+
mapErr(fn) {
|
|
54
|
+
return new ResultAsync(this.promise.then((r) => r.mapErr(fn)));
|
|
55
|
+
}
|
|
56
|
+
/** Chain async operations. */
|
|
57
|
+
andThen(fn) {
|
|
58
|
+
return new ResultAsync(this.promise.then((r) => {
|
|
59
|
+
if (r.isErr())
|
|
60
|
+
return (0, result_js_1.Err)(r.unwrapErr());
|
|
61
|
+
return fn(r.unwrap()).toPromise();
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
/** Extract the underlying Promise<Result>. */
|
|
65
|
+
toPromise() {
|
|
66
|
+
return this.promise;
|
|
67
|
+
}
|
|
68
|
+
/** Unwrap or throw. */
|
|
69
|
+
async unwrap() {
|
|
70
|
+
const result = await this.promise;
|
|
71
|
+
return result.unwrap();
|
|
72
|
+
}
|
|
73
|
+
/** Unwrap or return default. */
|
|
74
|
+
async unwrapOr(defaultValue) {
|
|
75
|
+
const result = await this.promise;
|
|
76
|
+
return result.unwrapOr(defaultValue);
|
|
77
|
+
}
|
|
78
|
+
/** Pattern match on the resolved Result. */
|
|
79
|
+
async match(handlers) {
|
|
80
|
+
const result = await this.promise;
|
|
81
|
+
return result.match(handlers);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.ResultAsync = ResultAsync;
|
|
85
|
+
/**
|
|
86
|
+
* An Option wrapped in a Promise.
|
|
87
|
+
*/
|
|
88
|
+
class OptionAsync {
|
|
89
|
+
promise;
|
|
90
|
+
constructor(promise) {
|
|
91
|
+
this.promise = promise;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Create from a Promise that resolves to a nullable value.
|
|
95
|
+
*/
|
|
96
|
+
static from(promise) {
|
|
97
|
+
return new OptionAsync(promise.then((v) => v === null || v === undefined ? (0, option_js_1.None)() : (0, option_js_1.Some)(v)));
|
|
98
|
+
}
|
|
99
|
+
static some(value) {
|
|
100
|
+
return new OptionAsync(Promise.resolve((0, option_js_1.Some)(value)));
|
|
101
|
+
}
|
|
102
|
+
static none() {
|
|
103
|
+
return new OptionAsync(Promise.resolve((0, option_js_1.None)()));
|
|
104
|
+
}
|
|
105
|
+
map(fn) {
|
|
106
|
+
return new OptionAsync(this.promise.then((o) => o.map(fn)));
|
|
107
|
+
}
|
|
108
|
+
andThen(fn) {
|
|
109
|
+
return new OptionAsync(this.promise.then((o) => {
|
|
110
|
+
if (o.isNone())
|
|
111
|
+
return (0, option_js_1.None)();
|
|
112
|
+
return fn(o.unwrap()).toPromise();
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
toPromise() {
|
|
116
|
+
return this.promise;
|
|
117
|
+
}
|
|
118
|
+
async unwrap() {
|
|
119
|
+
const option = await this.promise;
|
|
120
|
+
return option.unwrap();
|
|
121
|
+
}
|
|
122
|
+
async unwrapOr(defaultValue) {
|
|
123
|
+
const option = await this.promise;
|
|
124
|
+
return option.unwrapOr(defaultValue);
|
|
125
|
+
}
|
|
126
|
+
async match(handlers) {
|
|
127
|
+
const option = await this.promise;
|
|
128
|
+
return option.match(handlers);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.OptionAsync = OptionAsync;
|
|
132
|
+
//# sourceMappingURL=async.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async.js","sourceRoot":"","sources":["../../../src/result/async.ts"],"names":[],"mapp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AAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC;QAClC,OAAO,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC;CACF;AArDD,kCAqDC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OptionAsync = exports.ResultAsync = exports.OptionUtils = exports.None = exports.Some = exports.ResultUtils = exports.Err = exports.Ok = void 0;
|
|
4
|
+
var result_js_1 = require("./result.js");
|
|
5
|
+
Object.defineProperty(exports, "Ok", { enumerable: true, get: function () { return result_js_1.Ok; } });
|
|
6
|
+
Object.defineProperty(exports, "Err", { enumerable: true, get: function () { return result_js_1.Err; } });
|
|
7
|
+
Object.defineProperty(exports, "ResultUtils", { enumerable: true, get: function () { return result_js_1.ResultUtils; } });
|
|
8
|
+
var option_js_1 = require("./option.js");
|
|
9
|
+
Object.defineProperty(exports, "Some", { enumerable: true, get: function () { return option_js_1.Some; } });
|
|
10
|
+
Object.defineProperty(exports, "None", { enumerable: true, get: function () { return option_js_1.None; } });
|
|
11
|
+
Object.defineProperty(exports, "OptionUtils", { enumerable: true, get: function () { return option_js_1.OptionUtils; } });
|
|
12
|
+
var async_js_1 = require("./async.js");
|
|
13
|
+
Object.defineProperty(exports, "ResultAsync", { enumerable: true, get: function () { return async_js_1.ResultAsync; } });
|
|
14
|
+
Object.defineProperty(exports, "OptionAsync", { enumerable: true, get: function () { return async_js_1.OptionAsync; } });
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/result/index.ts"],"names":[],"mappings":";;;AAAA,yCAAgE;AAAvD,+FAAA,EAAE,OAAA;AAAE,gGAAA,GAAG,OAAA;AAAE,wGAAA,WAAW,OAAA;AAC7B,yCAAmE;AAA1D,iGAAA,IAAI,OAAA;AAAE,iGAAA,IAAI,OAAA;AAAE,wGAAA,WAAW,OAAA;AAChC,uCAAsD;AAA7C,uGAAA,WAAW,OAAA;AAAE,uGAAA,WAAW,OAAA"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================================
|
|
3
|
+
// Guarden — Option<T> Monadic Null Handling
|
|
4
|
+
// ============================================================================
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.OptionUtils = void 0;
|
|
7
|
+
exports.Some = Some;
|
|
8
|
+
exports.None = None;
|
|
9
|
+
class SomeOption {
|
|
10
|
+
value;
|
|
11
|
+
_tag = 'Some';
|
|
12
|
+
constructor(value) {
|
|
13
|
+
this.value = value;
|
|
14
|
+
}
|
|
15
|
+
isSome() {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
isNone() {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
/** Transform the contained value. */
|
|
22
|
+
map(fn) {
|
|
23
|
+
return new SomeOption(fn(this.value));
|
|
24
|
+
}
|
|
25
|
+
/** Chain operations that return an Option (flatMap). */
|
|
26
|
+
andThen(fn) {
|
|
27
|
+
return fn(this.value);
|
|
28
|
+
}
|
|
29
|
+
/** Return this Option if Some, otherwise return the other. */
|
|
30
|
+
orElse(_fn) {
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
/** Get the value, or throw if None. */
|
|
34
|
+
unwrap() {
|
|
35
|
+
return this.value;
|
|
36
|
+
}
|
|
37
|
+
/** Get the value, or return a default. */
|
|
38
|
+
unwrapOr(_defaultValue) {
|
|
39
|
+
return this.value;
|
|
40
|
+
}
|
|
41
|
+
/** Get the value, or compute a default. */
|
|
42
|
+
unwrapOrElse(_fn) {
|
|
43
|
+
return this.value;
|
|
44
|
+
}
|
|
45
|
+
/** Pattern match on the Option. */
|
|
46
|
+
match(handlers) {
|
|
47
|
+
return handlers.some(this.value);
|
|
48
|
+
}
|
|
49
|
+
/** Filter: return None if the predicate fails. */
|
|
50
|
+
filter(predicate) {
|
|
51
|
+
return predicate(this.value) ? this : new NoneOption();
|
|
52
|
+
}
|
|
53
|
+
/** Apply a side-effect function if Some. */
|
|
54
|
+
tap(fn) {
|
|
55
|
+
fn(this.value);
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
/** Zip with another Option. */
|
|
59
|
+
zip(other) {
|
|
60
|
+
if (other.isSome()) {
|
|
61
|
+
return new SomeOption([this.value, other.value]);
|
|
62
|
+
}
|
|
63
|
+
return new NoneOption();
|
|
64
|
+
}
|
|
65
|
+
toJSON() {
|
|
66
|
+
return { tag: 'Some', value: this.value };
|
|
67
|
+
}
|
|
68
|
+
toString() {
|
|
69
|
+
return `Some(${JSON.stringify(this.value)})`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
class NoneOption {
|
|
73
|
+
_tag = 'None';
|
|
74
|
+
isSome() {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
isNone() {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
map(_fn) {
|
|
81
|
+
return new NoneOption();
|
|
82
|
+
}
|
|
83
|
+
andThen(_fn) {
|
|
84
|
+
return new NoneOption();
|
|
85
|
+
}
|
|
86
|
+
orElse(fn) {
|
|
87
|
+
return fn();
|
|
88
|
+
}
|
|
89
|
+
unwrap() {
|
|
90
|
+
throw new Error('Called unwrap on None');
|
|
91
|
+
}
|
|
92
|
+
unwrapOr(defaultValue) {
|
|
93
|
+
return defaultValue;
|
|
94
|
+
}
|
|
95
|
+
unwrapOrElse(fn) {
|
|
96
|
+
return fn();
|
|
97
|
+
}
|
|
98
|
+
match(handlers) {
|
|
99
|
+
return handlers.none();
|
|
100
|
+
}
|
|
101
|
+
filter(_predicate) {
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
tap(_fn) {
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
zip(_other) {
|
|
108
|
+
return new NoneOption();
|
|
109
|
+
}
|
|
110
|
+
toJSON() {
|
|
111
|
+
return { tag: 'None' };
|
|
112
|
+
}
|
|
113
|
+
toString() {
|
|
114
|
+
return 'None';
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// -- Public constructors -----------------------------------------------------
|
|
118
|
+
/**
|
|
119
|
+
* Create an Option containing a value.
|
|
120
|
+
*/
|
|
121
|
+
function Some(value) {
|
|
122
|
+
return new SomeOption(value);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Create an empty Option.
|
|
126
|
+
*/
|
|
127
|
+
function None() {
|
|
128
|
+
return new NoneOption();
|
|
129
|
+
}
|
|
130
|
+
// -- Static utilities --------------------------------------------------------
|
|
131
|
+
exports.OptionUtils = {
|
|
132
|
+
/**
|
|
133
|
+
* Create an Option from a nullable value.
|
|
134
|
+
* null | undefined → None, everything else → Some.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* Option.from(null) // None
|
|
139
|
+
* Option.from(undefined) // None
|
|
140
|
+
* Option.from(42) // Some(42)
|
|
141
|
+
* Option.from('') // Some('') (empty string is still Some)
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
from(value) {
|
|
145
|
+
return value === null || value === undefined
|
|
146
|
+
? new NoneOption()
|
|
147
|
+
: new SomeOption(value);
|
|
148
|
+
},
|
|
149
|
+
/**
|
|
150
|
+
* Create an Option from a predicate check.
|
|
151
|
+
*/
|
|
152
|
+
fromPredicate(value, predicate) {
|
|
153
|
+
return predicate(value) ? new SomeOption(value) : new NoneOption();
|
|
154
|
+
},
|
|
155
|
+
/**
|
|
156
|
+
* Check if a value is an Option.
|
|
157
|
+
*/
|
|
158
|
+
isOption(value) {
|
|
159
|
+
return value instanceof SomeOption || value instanceof NoneOption;
|
|
160
|
+
},
|
|
161
|
+
/**
|
|
162
|
+
* Collect an array of Options into an Option of array.
|
|
163
|
+
* Returns None if any Option is None.
|
|
164
|
+
*/
|
|
165
|
+
all(options) {
|
|
166
|
+
const values = [];
|
|
167
|
+
for (const opt of options) {
|
|
168
|
+
if (opt.isNone())
|
|
169
|
+
return new NoneOption();
|
|
170
|
+
values.push(opt.unwrap());
|
|
171
|
+
}
|
|
172
|
+
return new SomeOption(values);
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
//# sourceMappingURL=option.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"option.js","sourceRoot":"","sources":["../../../src/result/option.ts"],"names":[],"mappings":";AAAA,+EAA+E;AAC/E,4CAA4C;AAC5C,+EAA+E;;;AA0J/E,oBAEC;AAKD,oBAEC;AArJD,MAAM,UAAU;IAEc;IADnB,IAAI,GAAG,MAAe,CAAC;IAChC,YAA4B,KAAQ;QAAR,UAAK,GAAL,KAAK,CAAG;IAAG,CAAC;IAExC,MAAM;QACJ,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM;QACJ,OAAO,KAAK,CAAC;IACf,CAAC;IAED,qCAAqC;IACrC,GAAG,CAAI,EAAmB;QACxB,OAAO,IAAI,UAAU,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACxC,CAAC;IAED,wDAAwD;IACxD,OAAO,CAAI,EAA2B;QACpC,OAAO,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;IAED,8DAA8D;IAC9D,MAAM,CAAC,GAAoB;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,uCAAuC;IACvC,MAAM;QACJ,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,0CAA0C;IAC1C,QAAQ,CAAC,aAAgB;QACvB,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,2CAA2C;IAC3C,YAAY,CAAC,GAAY;QACvB,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,mCAAmC;IACnC,KAAK,CAAI,QAAkD;QACzD,OAAO,QAAQ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