@bessemer/cornerstone 0.5.86 → 0.5.88
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/aspect-ratio.d.ts +7 -4
- package/dist/aspect-ratio.d.ts.map +1 -1
- package/dist/aspect-ratio.js +16 -7
- package/dist/aspect-ratio.js.map +1 -1
- package/dist/async.d.ts +1 -1
- package/dist/async.d.ts.map +1 -1
- package/dist/async.js +1 -1
- package/dist/async.js.map +1 -1
- package/dist/cache.d.ts +7 -6
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +12 -12
- package/dist/cache.js.map +1 -1
- package/dist/comparator.js +1 -1
- package/dist/comparator.js.map +1 -1
- package/dist/content.d.ts +5 -5
- package/dist/content.d.ts.map +1 -1
- package/dist/content.js.map +1 -1
- package/dist/data-size.d.ts +2 -2
- package/dist/data-size.d.ts.map +1 -1
- package/dist/data-size.js.map +1 -1
- package/dist/{error-event.d.ts → error/error-event.d.ts} +42 -23
- package/dist/error/error-event.d.ts.map +1 -0
- package/dist/{error-event.js → error/error-event.js} +82 -60
- package/dist/error/error-event.js.map +1 -0
- package/dist/error/error-type.d.ts +11 -0
- package/dist/error/error-type.d.ts.map +1 -0
- package/dist/error/error-type.js +20 -0
- package/dist/error/error-type.js.map +1 -0
- package/dist/error/error.d.ts.map +1 -0
- package/dist/{error.js → error/error.js} +1 -1
- package/dist/error/error.js.map +1 -0
- package/dist/expression.d.ts +2 -2
- package/dist/expression.d.ts.map +1 -1
- package/dist/expression.js.map +1 -1
- package/dist/glob.d.ts +7 -3
- package/dist/glob.d.ts.map +1 -1
- package/dist/glob.js +23 -15
- package/dist/glob.js.map +1 -1
- package/dist/hash.d.ts +2 -2
- package/dist/hash.d.ts.map +1 -1
- package/dist/hash.js.map +1 -1
- package/dist/hex-code.d.ts +7 -4
- package/dist/hex-code.d.ts.map +1 -1
- package/dist/hex-code.js +19 -5
- package/dist/hex-code.js.map +1 -1
- package/dist/index.d.ts +12 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -4
- package/dist/index.js.map +1 -1
- package/dist/intl/country-code.d.ts +7 -4
- package/dist/intl/country-code.d.ts.map +1 -1
- package/dist/intl/country-code.js +52 -43
- package/dist/intl/country-code.js.map +1 -1
- package/dist/intl/country-subdivision-code.d.ts +7 -4
- package/dist/intl/country-subdivision-code.d.ts.map +1 -1
- package/dist/intl/country-subdivision-code.js +16 -5
- package/dist/intl/country-subdivision-code.js.map +1 -1
- package/dist/intl/currency-code.d.ts +7 -4
- package/dist/intl/currency-code.d.ts.map +1 -1
- package/dist/intl/currency-code.js +20 -11
- package/dist/intl/currency-code.js.map +1 -1
- package/dist/intl/language-code.d.ts +7 -4
- package/dist/intl/language-code.d.ts.map +1 -1
- package/dist/intl/language-code.js +39 -30
- package/dist/intl/language-code.js.map +1 -1
- package/dist/intl/locale.d.ts +8 -5
- package/dist/intl/locale.d.ts.map +1 -1
- package/dist/intl/locale.js +37 -30
- package/dist/intl/locale.js.map +1 -1
- package/dist/math.d.ts +2 -0
- package/dist/math.d.ts.map +1 -1
- package/dist/math.js +12 -1
- package/dist/math.js.map +1 -1
- package/dist/mime-type.d.ts +7 -4
- package/dist/mime-type.d.ts.map +1 -1
- package/dist/mime-type.js +44 -35
- package/dist/mime-type.js.map +1 -1
- package/dist/monetary-amount.d.ts +3 -3
- package/dist/monetary-amount.d.ts.map +1 -1
- package/dist/monetary-amount.js +4 -4
- package/dist/monetary-amount.js.map +1 -1
- package/dist/object/object-path.d.ts +2 -2
- package/dist/object/object-path.d.ts.map +1 -1
- package/dist/object/object-path.js.map +1 -1
- package/dist/object/type-path.d.ts +2 -2
- package/dist/object/type-path.d.ts.map +1 -1
- package/dist/object/type-path.js.map +1 -1
- package/dist/object.d.ts +2 -2
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +3 -2
- package/dist/object.js.map +1 -1
- package/dist/range.d.ts +2 -2
- package/dist/range.d.ts.map +1 -1
- package/dist/range.js.map +1 -1
- package/dist/reference.d.ts +2 -2
- package/dist/reference.d.ts.map +1 -1
- package/dist/reference.js.map +1 -1
- package/dist/resource-key.d.ts +17 -8
- package/dist/resource-key.d.ts.map +1 -1
- package/dist/resource-key.js +42 -13
- package/dist/resource-key.js.map +1 -1
- package/dist/result.d.ts +6 -5
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +4 -4
- package/dist/result.js.map +1 -1
- package/dist/retry.d.ts +1 -1
- package/dist/retry.d.ts.map +1 -1
- package/dist/retry.js +1 -1
- package/dist/retry.js.map +1 -1
- package/dist/rich-text.d.ts +2 -2
- package/dist/rich-text.d.ts.map +1 -1
- package/dist/rich-text.js.map +1 -1
- package/dist/signature.d.ts.map +1 -1
- package/dist/signature.js +5 -1
- package/dist/signature.js.map +1 -1
- package/dist/sql.d.ts +2 -2
- package/dist/sql.d.ts.map +1 -1
- package/dist/sql.js.map +1 -1
- package/dist/tag.d.ts +3 -3
- package/dist/tag.d.ts.map +1 -1
- package/dist/tag.js.map +1 -1
- package/dist/temporal/chrono.d.ts +34 -0
- package/dist/temporal/chrono.d.ts.map +1 -0
- package/dist/temporal/chrono.js +34 -0
- package/dist/temporal/chrono.js.map +1 -0
- package/dist/temporal/clock.d.ts +21 -0
- package/dist/temporal/clock.d.ts.map +1 -0
- package/dist/temporal/clock.js +76 -0
- package/dist/temporal/clock.js.map +1 -0
- package/dist/temporal/date.d.ts +2 -0
- package/dist/temporal/date.d.ts.map +1 -0
- package/dist/temporal/date.js +8 -0
- package/dist/temporal/date.js.map +1 -0
- package/dist/temporal/duration.d.ts +54 -0
- package/dist/temporal/duration.d.ts.map +1 -0
- package/dist/temporal/duration.js +162 -0
- package/dist/temporal/duration.js.map +1 -0
- package/dist/temporal/instant.d.ts +35 -0
- package/dist/temporal/instant.d.ts.map +1 -0
- package/dist/temporal/instant.js +91 -0
- package/dist/temporal/instant.js.map +1 -0
- package/dist/temporal/plain-time.d.ts +49 -0
- package/dist/temporal/plain-time.d.ts.map +1 -0
- package/dist/temporal/plain-time.js +110 -0
- package/dist/temporal/plain-time.js.map +1 -0
- package/dist/temporal/time-zone-id.d.ts +12 -0
- package/dist/temporal/time-zone-id.d.ts.map +1 -0
- package/dist/temporal/time-zone-id.js +35 -0
- package/dist/temporal/time-zone-id.js.map +1 -0
- package/dist/temporal/time-zone-offset.d.ts +22 -0
- package/dist/temporal/time-zone-offset.d.ts.map +1 -0
- package/dist/temporal/time-zone-offset.js +145 -0
- package/dist/temporal/time-zone-offset.js.map +1 -0
- package/dist/types.d.ts +12 -12
- package/dist/types.d.ts.map +1 -1
- package/dist/ulid.d.ts +7 -4
- package/dist/ulid.d.ts.map +1 -1
- package/dist/ulid.js +14 -5
- package/dist/ulid.js.map +1 -1
- package/dist/unit.d.ts +2 -2
- package/dist/unit.d.ts.map +1 -1
- package/dist/unit.js.map +1 -1
- package/dist/uri.d.ts +2 -2
- package/dist/uri.d.ts.map +1 -1
- package/dist/uri.js.map +1 -1
- package/dist/uuid.d.ts +7 -4
- package/dist/uuid.d.ts.map +1 -1
- package/dist/uuid.js +14 -5
- package/dist/uuid.js.map +1 -1
- package/dist/zod-util.d.ts +5 -0
- package/dist/zod-util.d.ts.map +1 -1
- package/dist/zod-util.js +28 -2
- package/dist/zod-util.js.map +1 -1
- package/package.json +2 -2
- package/dist/date.d.ts +0 -13
- package/dist/date.d.ts.map +0 -1
- package/dist/date.js +0 -40
- package/dist/date.js.map +0 -1
- package/dist/duration.d.ts +0 -18
- package/dist/duration.d.ts.map +0 -1
- package/dist/duration.js +0 -53
- package/dist/duration.js.map +0 -1
- package/dist/error-event.d.ts.map +0 -1
- package/dist/error-event.js.map +0 -1
- package/dist/error.d.ts.map +0 -1
- package/dist/error.js.map +0 -1
- /package/dist/{error.d.ts → error/error.d.ts} +0 -0
@@ -1,19 +1,36 @@
|
|
1
|
-
// src/error-event.ts
|
1
|
+
// src/error/error-event.ts
|
2
2
|
import { deepMerge, isNil, isObject, isPresent } from "@bessemer/cornerstone/object";
|
3
3
|
import Zod from "zod";
|
4
4
|
import { evaluate } from "@bessemer/cornerstone/lazy";
|
5
|
-
import { findInCausalChain as errorsFindInCausalChain, isError } from "@bessemer/cornerstone/error";
|
5
|
+
import { findInCausalChain as errorsFindInCausalChain, isError } from "@bessemer/cornerstone/error/error";
|
6
6
|
import { isPromise } from "@bessemer/cornerstone/promise";
|
7
|
-
import {
|
8
|
-
|
7
|
+
import { applyNamespace, emptyNamespace, splitNamespace } from "@bessemer/cornerstone/resource-key";
|
8
|
+
import { Forbidden, InvalidValue, Required, Unauthorized, Unhandled } from "@bessemer/cornerstone/error/error-type";
|
9
|
+
var ErrorCodeSchema = Zod.string().transform((it) => it);
|
10
|
+
var splitErrorCode = (code) => {
|
11
|
+
return splitNamespace(code);
|
12
|
+
};
|
13
|
+
var getErrorCodeType = (code) => {
|
14
|
+
const [errorType] = splitErrorCode(code);
|
15
|
+
return errorType;
|
16
|
+
};
|
17
|
+
var buildErrorCode = (builder) => {
|
18
|
+
if ("code" in builder) {
|
19
|
+
return builder.code;
|
20
|
+
} else {
|
21
|
+
return applyNamespace(builder.type, builder.namespace ?? emptyNamespace());
|
22
|
+
}
|
23
|
+
};
|
9
24
|
var ErrorAttributeSchema = Zod.string();
|
10
|
-
var
|
25
|
+
var ErrorEventCauseSchema = Zod.object({
|
11
26
|
code: ErrorCodeSchema,
|
12
27
|
message: Zod.string(),
|
13
|
-
attributes: Zod.record(
|
28
|
+
attributes: Zod.record(Zod.string(), Zod.unknown())
|
14
29
|
});
|
15
|
-
var
|
16
|
-
|
30
|
+
var Schema = Zod.object({
|
31
|
+
message: Zod.string(),
|
32
|
+
causes: Zod.array(ErrorEventCauseSchema),
|
33
|
+
attributes: Zod.record(ErrorAttributeSchema, Zod.unknown())
|
17
34
|
});
|
18
35
|
var ErrorEventException = class extends Error {
|
19
36
|
errorEvent;
|
@@ -27,19 +44,38 @@ var isErrorEvent = (throwable) => {
|
|
27
44
|
if (!isObject(throwable)) {
|
28
45
|
return false;
|
29
46
|
}
|
30
|
-
|
47
|
+
const errorEvent = throwable;
|
48
|
+
return isPresent(errorEvent.message) && isPresent(errorEvent.attributes) && isPresent(errorEvent.causes);
|
31
49
|
};
|
32
50
|
var isErrorEventException = (throwable) => {
|
33
51
|
return throwable instanceof ErrorEventException;
|
34
52
|
};
|
35
53
|
var of = (builder) => {
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
54
|
+
if ("causes" in builder) {
|
55
|
+
return {
|
56
|
+
causes: builder.causes.map((it) => {
|
57
|
+
return {
|
58
|
+
code: buildErrorCode(it),
|
59
|
+
message: it.message,
|
60
|
+
attributes: it.attributes ?? {}
|
61
|
+
};
|
62
|
+
}),
|
63
|
+
message: builder.message,
|
64
|
+
attributes: builder.attributes ?? {}
|
65
|
+
};
|
66
|
+
} else {
|
67
|
+
return {
|
68
|
+
causes: [
|
69
|
+
{
|
70
|
+
code: buildErrorCode(builder),
|
71
|
+
message: builder.message,
|
72
|
+
attributes: {}
|
73
|
+
}
|
74
|
+
],
|
75
|
+
message: builder.message,
|
76
|
+
attributes: builder.attributes ?? {}
|
77
|
+
};
|
78
|
+
}
|
43
79
|
};
|
44
80
|
var from = (throwable) => {
|
45
81
|
if (isErrorEvent(throwable)) {
|
@@ -77,43 +113,24 @@ var propagate = (throwable, attributes) => {
|
|
77
113
|
throw new ErrorEventException(contextualizedEvent, throwable);
|
78
114
|
}
|
79
115
|
};
|
80
|
-
var
|
81
|
-
return findInCausalChain(error, (it) => it.code === code);
|
82
|
-
};
|
83
|
-
var findInCausalChain = (error, predicate) => {
|
84
|
-
if (predicate(error)) {
|
85
|
-
return error;
|
86
|
-
}
|
87
|
-
return first(error.causes.map((it) => findInCausalChain(it, predicate)).filter(isPresent));
|
88
|
-
};
|
89
|
-
var aggregate = (builder, causes) => {
|
90
|
-
if (causes.length === 0) {
|
91
|
-
return void 0;
|
92
|
-
}
|
93
|
-
return of({ ...builder, causes });
|
94
|
-
};
|
95
|
-
var UnhandledErrorCode = "error-event.unhandled";
|
96
|
-
var NotFoundErrorCode = "error-event.not-found";
|
97
|
-
var ForbiddenErrorCode = "error-event.forbidden";
|
98
|
-
var UnauthorizedErrorCode = "error-event.unauthorized";
|
99
|
-
var BadRequestErrorCode = "error-event.bad-request";
|
116
|
+
var ValueAttribute = "value";
|
100
117
|
var RequestCorrelationIdAttribute = "requestCorrelationId";
|
101
118
|
var HttpStatusCodeAttribute = "httpStatusCode";
|
102
119
|
var unhandled = (builder) => of(
|
103
120
|
deepMerge(
|
104
121
|
{
|
105
|
-
|
122
|
+
type: Unhandled,
|
106
123
|
message: "An Unhandled Error has occurred.",
|
107
124
|
attributes: { [HttpStatusCodeAttribute]: 500 }
|
108
125
|
},
|
109
126
|
builder
|
110
127
|
)
|
111
128
|
);
|
112
|
-
var
|
129
|
+
var required = (builder) => of(
|
113
130
|
deepMerge(
|
114
131
|
{
|
115
|
-
|
116
|
-
message: "The
|
132
|
+
type: Required,
|
133
|
+
message: "The resource is required.",
|
117
134
|
attributes: { [HttpStatusCodeAttribute]: 404 }
|
118
135
|
},
|
119
136
|
builder
|
@@ -122,7 +139,7 @@ var notFound = (builder) => of(
|
|
122
139
|
var unauthorized = (builder) => of(
|
123
140
|
deepMerge(
|
124
141
|
{
|
125
|
-
|
142
|
+
type: Unauthorized,
|
126
143
|
message: "The requested Resource requires authentication.",
|
127
144
|
attributes: { [HttpStatusCodeAttribute]: 401 }
|
128
145
|
},
|
@@ -132,26 +149,26 @@ var unauthorized = (builder) => of(
|
|
132
149
|
var forbidden = (builder) => of(
|
133
150
|
deepMerge(
|
134
151
|
{
|
135
|
-
|
152
|
+
type: Forbidden,
|
136
153
|
message: "The requested Resource requires additional permissions to access.",
|
137
154
|
attributes: { [HttpStatusCodeAttribute]: 403 }
|
138
155
|
},
|
139
156
|
builder
|
140
157
|
)
|
141
158
|
);
|
142
|
-
var
|
159
|
+
var invalidValue = (value, builder) => of(
|
143
160
|
deepMerge(
|
144
161
|
{
|
145
|
-
|
146
|
-
message: "The
|
147
|
-
attributes: { [HttpStatusCodeAttribute]: 400 }
|
162
|
+
type: InvalidValue,
|
163
|
+
message: "The format is invalid and cannot be processed.",
|
164
|
+
attributes: { [HttpStatusCodeAttribute]: 400, [ValueAttribute]: value }
|
148
165
|
},
|
149
166
|
builder
|
150
167
|
)
|
151
168
|
);
|
152
169
|
function assertPresent(value, builder = () => void 0) {
|
153
170
|
if (isNil(value)) {
|
154
|
-
throw new ErrorEventException(
|
171
|
+
throw new ErrorEventException(required(evaluate(builder)));
|
155
172
|
}
|
156
173
|
}
|
157
174
|
function assertAuthorized(value, builder = () => void 0) {
|
@@ -164,9 +181,9 @@ function assertPermitted(value, builder = () => void 0) {
|
|
164
181
|
throw new ErrorEventException(forbidden(evaluate(builder)));
|
165
182
|
}
|
166
183
|
}
|
167
|
-
function assertValid(value, builder = () => void 0) {
|
168
|
-
if (!
|
169
|
-
throw new ErrorEventException(
|
184
|
+
function assertValid(valid, value, builder = () => void 0) {
|
185
|
+
if (!valid) {
|
186
|
+
throw new ErrorEventException(invalidValue(value, evaluate(builder)));
|
170
187
|
}
|
171
188
|
}
|
172
189
|
function assert(value, builder) {
|
@@ -174,35 +191,40 @@ function assert(value, builder) {
|
|
174
191
|
throw new ErrorEventException(of(evaluate(builder)));
|
175
192
|
}
|
176
193
|
}
|
194
|
+
var unpackResult = (result) => {
|
195
|
+
if (!result.isSuccess) {
|
196
|
+
throw new ErrorEventException(result.value);
|
197
|
+
}
|
198
|
+
return result.value;
|
199
|
+
};
|
177
200
|
export {
|
178
|
-
BadRequestErrorCode,
|
179
201
|
ErrorAttributeSchema,
|
180
202
|
ErrorCodeSchema,
|
203
|
+
ErrorEventCauseSchema,
|
181
204
|
ErrorEventException,
|
182
|
-
ForbiddenErrorCode,
|
183
205
|
HttpStatusCodeAttribute,
|
184
|
-
NotFoundErrorCode,
|
185
206
|
RequestCorrelationIdAttribute,
|
186
|
-
|
187
|
-
|
188
|
-
aggregate,
|
207
|
+
Schema,
|
208
|
+
ValueAttribute,
|
189
209
|
assert,
|
190
210
|
assertAuthorized,
|
191
211
|
assertPermitted,
|
192
212
|
assertPresent,
|
193
213
|
assertValid,
|
194
|
-
|
195
|
-
findByCodeInCausalChain,
|
196
|
-
findInCausalChain,
|
214
|
+
buildErrorCode,
|
197
215
|
forbidden,
|
198
216
|
from,
|
217
|
+
getErrorCodeType,
|
218
|
+
invalidValue,
|
199
219
|
isErrorEvent,
|
200
220
|
isErrorEventException,
|
201
|
-
notFound,
|
202
221
|
of,
|
203
222
|
propagate,
|
223
|
+
required,
|
224
|
+
splitErrorCode,
|
204
225
|
unauthorized,
|
205
226
|
unhandled,
|
227
|
+
unpackResult,
|
206
228
|
withPropagation
|
207
229
|
};
|
208
230
|
//# sourceMappingURL=error-event.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/error/error-event.ts"],"sourcesContent":["import { Dictionary, Throwable } from '@bessemer/cornerstone/types'\nimport { deepMerge, isNil, isObject, isPresent, RecordAttribute } from '@bessemer/cornerstone/object'\nimport Zod, { ZodType } from 'zod'\nimport { evaluate, LazyValue } from '@bessemer/cornerstone/lazy'\nimport { findInCausalChain as errorsFindInCausalChain, isError } from '@bessemer/cornerstone/error/error'\nimport { isPromise } from '@bessemer/cornerstone/promise'\nimport { applyNamespace, emptyNamespace, NamespacedKey, ResourceNamespace, splitNamespace } from '@bessemer/cornerstone/resource-key'\nimport { ErrorType, Forbidden, InvalidValue, Required, Unauthorized, Unhandled } from '@bessemer/cornerstone/error/error-type'\nimport { Result } from '@bessemer/cornerstone/result'\n\n/*\n Represents a structured error event. The code can be mapped to a unique type of error while the\n message and attributes can provide contextual information about the error. Finally,\n an ErrorEvent could have multiple causes which get aggregated into a single parent error.\n */\nexport type ErrorCode = NamespacedKey<ErrorType>\nexport const ErrorCodeSchema = Zod.string().transform((it) => it as NamespacedKey<ErrorType>)\n\nexport const splitErrorCode = (code: ErrorCode): [ErrorType, ResourceNamespace] => {\n return splitNamespace(code)\n}\n\nexport const getErrorCodeType = (code: ErrorCode): ErrorType => {\n const [errorType] = splitErrorCode(code)\n return errorType\n}\n\nexport type ErrorCodeBuilder =\n | {\n code: ErrorCode\n }\n | { type: ErrorType; namespace?: ResourceNamespace }\n\nexport const buildErrorCode = (builder: ErrorCodeBuilder): ErrorCode => {\n if ('code' in builder) {\n return builder.code\n } else {\n return applyNamespace(builder.type, builder.namespace ?? emptyNamespace())\n }\n}\n\nexport type ErrorAttribute<Type = unknown> = RecordAttribute<Type, 'ErrorAttribute'>\nexport const ErrorAttributeSchema: ZodType<ErrorAttribute, string> = Zod.string()\n\nexport const ErrorEventCauseSchema = Zod.object({\n code: ErrorCodeSchema,\n message: Zod.string(),\n attributes: Zod.record(Zod.string(), Zod.unknown()),\n})\n\nexport type ErrorEventCause = Zod.infer<typeof ErrorEventCauseSchema>\n\nexport const Schema = Zod.object({\n message: Zod.string(),\n causes: Zod.array(ErrorEventCauseSchema),\n attributes: Zod.record(ErrorAttributeSchema, Zod.unknown()),\n})\n\nexport type ErrorEvent = Zod.infer<typeof Schema>\n\nexport type ErrorEventCauseBuilder = ErrorCodeBuilder & {\n message: string\n attributes?: Dictionary<unknown>\n}\n\nexport type ErrorEventBuilder = {\n attributes?: Record<ErrorAttribute, unknown>\n} & (\n | {\n causes: Array<ErrorEventCauseBuilder>\n message: string\n }\n | (ErrorCodeBuilder & {\n message: string\n })\n)\n\nexport type ErrorEventAugment = Partial<ErrorEventBuilder>\n\n// An exception type that contains an ErrorEvent\nexport class ErrorEventException extends Error {\n readonly errorEvent: ErrorEvent\n\n constructor(errorEvent: ErrorEvent, cause?: unknown) {\n super(errorEvent.message ?? '', { cause })\n this.name = this.constructor.name\n this.errorEvent = errorEvent\n }\n}\n\nexport const isErrorEvent = (throwable: Throwable): throwable is ErrorEvent => {\n if (!isObject(throwable)) {\n return false\n }\n\n const errorEvent = throwable as ErrorEvent\n return isPresent(errorEvent.message) && isPresent(errorEvent.attributes) && isPresent(errorEvent.causes)\n}\n\nexport const isErrorEventException = (throwable: Throwable): throwable is ErrorEventException => {\n return throwable instanceof ErrorEventException\n}\n\nexport const of = (builder: ErrorEventBuilder): ErrorEvent => {\n if ('causes' in builder) {\n return {\n causes: builder.causes.map((it) => {\n return {\n code: buildErrorCode(it),\n message: it.message,\n attributes: it.attributes ?? {},\n }\n }),\n message: builder.message,\n attributes: builder.attributes ?? {},\n }\n } else {\n return {\n causes: [\n {\n code: buildErrorCode(builder),\n message: builder.message,\n attributes: {},\n },\n ],\n message: builder.message,\n attributes: builder.attributes ?? {},\n }\n }\n}\n\nexport const from = (throwable: Throwable): ErrorEvent => {\n if (isErrorEvent(throwable)) {\n return throwable\n }\n\n if (!isError(throwable)) {\n return unhandled()\n }\n\n const errorEventException = errorsFindInCausalChain(throwable, isErrorEventException) as ErrorEventException | undefined\n if (isNil(errorEventException)) {\n return unhandled()\n }\n\n return errorEventException.errorEvent\n}\n\nexport function withPropagation<ReturnType>(runnable: () => ReturnType, attributes: LazyValue<Dictionary<unknown>>): ReturnType\nexport function withPropagation<ReturnType>(runnable: () => Promise<ReturnType>, attributes: LazyValue<Dictionary<unknown>>): Promise<ReturnType>\nexport function withPropagation<ReturnType>(\n runnable: () => ReturnType | Promise<ReturnType>,\n attributes: LazyValue<Dictionary<unknown>>\n): ReturnType | Promise<ReturnType> {\n try {\n let result = runnable()\n if (isPromise(result)) {\n return result.then((it) => it).catch((it) => propagate(it, evaluate(attributes)))\n } else {\n return result\n }\n } catch (throwable: Throwable) {\n throw propagate(throwable, evaluate(attributes))\n }\n}\n\nexport const propagate = (throwable: Throwable, attributes: Dictionary<unknown>): never => {\n if (isErrorEventException(throwable)) {\n // We just mutate the existing error event to avoid nested exceptions\n const errorEvent = throwable.errorEvent\n errorEvent.attributes = { ...errorEvent.attributes, ...attributes }\n throw throwable\n } else {\n const errorEvent = from(throwable)\n const contextualizedEvent = of({ ...errorEvent, attributes: { ...errorEvent.attributes, ...attributes } })\n throw new ErrorEventException(contextualizedEvent, throwable)\n }\n}\n\nexport const ValueAttribute: ErrorAttribute = 'value'\nexport const RequestCorrelationIdAttribute: ErrorAttribute<string> = 'requestCorrelationId'\nexport const HttpStatusCodeAttribute: ErrorAttribute<number> = 'httpStatusCode'\n\nexport const unhandled = (builder?: ErrorEventAugment): ErrorEvent =>\n of(\n deepMerge(\n {\n type: Unhandled,\n message: 'An Unhandled Error has occurred.',\n attributes: { [HttpStatusCodeAttribute]: 500 },\n },\n builder\n )\n )\n\nexport const required = (builder?: ErrorEventAugment): ErrorEvent =>\n of(\n deepMerge(\n {\n type: Required,\n message: 'The resource is required.',\n attributes: { [HttpStatusCodeAttribute]: 404 },\n },\n builder\n )\n )\n\nexport const unauthorized = (builder?: ErrorEventAugment): ErrorEvent =>\n of(\n deepMerge(\n {\n type: Unauthorized,\n message: 'The requested Resource requires authentication.',\n attributes: { [HttpStatusCodeAttribute]: 401 },\n },\n builder\n )\n )\n\nexport const forbidden = (builder?: ErrorEventAugment): ErrorEvent =>\n of(\n deepMerge(\n {\n type: Forbidden,\n message: 'The requested Resource requires additional permissions to access.',\n attributes: { [HttpStatusCodeAttribute]: 403 },\n },\n builder\n )\n )\n\nexport const invalidValue = (value: unknown, builder?: ErrorEventAugment): ErrorEvent =>\n of(\n deepMerge(\n {\n type: InvalidValue,\n message: 'The format is invalid and cannot be processed.',\n attributes: { [HttpStatusCodeAttribute]: 400, [ValueAttribute]: value },\n },\n builder\n )\n )\n\nexport function assertPresent<T>(value: T, builder: LazyValue<ErrorEventAugment | undefined> = () => undefined): asserts value is NonNullable<T> {\n if (isNil(value)) {\n throw new ErrorEventException(required(evaluate(builder)))\n }\n}\n\nexport function assertAuthorized(value: boolean, builder: LazyValue<ErrorEventAugment | undefined> = () => undefined): asserts value is true {\n if (!value) {\n throw new ErrorEventException(unauthorized(evaluate(builder)))\n }\n}\n\nexport function assertPermitted(value: boolean, builder: LazyValue<ErrorEventAugment | undefined> = () => undefined): asserts value is true {\n if (!value) {\n throw new ErrorEventException(forbidden(evaluate(builder)))\n }\n}\n\nexport function assertValid(\n valid: boolean,\n value: unknown,\n builder: LazyValue<ErrorEventAugment | undefined> = () => undefined\n): asserts value is true {\n if (!valid) {\n throw new ErrorEventException(invalidValue(value, evaluate(builder)))\n }\n}\n\nexport function assert(value: boolean, builder: LazyValue<ErrorEventBuilder>): asserts value is true {\n if (!value) {\n throw new ErrorEventException(of(evaluate(builder)))\n }\n}\n\nexport const unpackResult = <T>(result: Result<T, ErrorEvent>): T => {\n if (!result.isSuccess) {\n throw new ErrorEventException(result.value)\n }\n\n return result.value\n}\n"],"mappings":";AACA,SAAS,WAAW,OAAO,UAAU,iBAAkC;AACvE,OAAO,SAAsB;AAC7B,SAAS,gBAA2B;AACpC,SAAS,qBAAqB,yBAAyB,eAAe;AACtE,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB,gBAAkD,sBAAsB;AACjG,SAAoB,WAAW,cAAc,UAAU,cAAc,iBAAiB;AAS/E,IAAM,kBAAkB,IAAI,OAAO,EAAE,UAAU,CAAC,OAAO,EAA8B;AAErF,IAAM,iBAAiB,CAAC,SAAoD;AACjF,SAAO,eAAe,IAAI;AAC5B;AAEO,IAAM,mBAAmB,CAAC,SAA+B;AAC9D,QAAM,CAAC,SAAS,IAAI,eAAe,IAAI;AACvC,SAAO;AACT;AAQO,IAAM,iBAAiB,CAAC,YAAyC;AACtE,MAAI,UAAU,SAAS;AACrB,WAAO,QAAQ;AAAA,EACjB,OAAO;AACL,WAAO,eAAe,QAAQ,MAAM,QAAQ,aAAa,eAAe,CAAC;AAAA,EAC3E;AACF;AAGO,IAAM,uBAAwD,IAAI,OAAO;AAEzE,IAAM,wBAAwB,IAAI,OAAO;AAAA,EAC9C,MAAM;AAAA,EACN,SAAS,IAAI,OAAO;AAAA,EACpB,YAAY,IAAI,OAAO,IAAI,OAAO,GAAG,IAAI,QAAQ,CAAC;AACpD,CAAC;AAIM,IAAM,SAAS,IAAI,OAAO;AA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SAAS,OAAO,OAAgB,SAA8D;AACnG,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,oBAAoB,GAAG,SAAS,OAAO,CAAC,CAAC;AAAA,EACrD;AACF;AAEO,IAAM,eAAe,CAAI,WAAqC;AACnE,MAAI,CAAC,OAAO,WAAW;AACrB,UAAM,IAAI,oBAAoB,OAAO,KAAK;AAAA,EAC5C;AAEA,SAAO,OAAO;AAChB;","names":[]}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { NominalType } from '@bessemer/cornerstone/types';
|
2
|
+
import Zod from 'zod';
|
3
|
+
export declare const Namespace: import("@bessemer/cornerstone/resource-key").ResourceNamespace<"error-type">;
|
4
|
+
export type ErrorType = NominalType<string, typeof Namespace>;
|
5
|
+
export declare const Schema: Zod.ZodPipe<Zod.ZodString, Zod.ZodTransform<ErrorType, string>>;
|
6
|
+
export declare const Unhandled: ErrorType;
|
7
|
+
export declare const Unauthorized: ErrorType;
|
8
|
+
export declare const Forbidden: ErrorType;
|
9
|
+
export declare const Required: ErrorType;
|
10
|
+
export declare const InvalidValue: ErrorType;
|
11
|
+
//# sourceMappingURL=error-type.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"error-type.d.ts","sourceRoot":"","sources":["../../src/error/error-type.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,GAAG,MAAM,KAAK,CAAA;AAErB,eAAO,MAAM,SAAS,8EAA0B,CAAA;AAChD,MAAM,MAAM,SAAS,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,SAAS,CAAC,CAAA;AAC7D,eAAO,MAAM,MAAM,iEAAkD,CAAA;AAErE,eAAO,MAAM,SAAS,EAAE,SAAoC,CAAA;AAC5D,eAAO,MAAM,YAAY,EAAE,SAAuC,CAAA;AAClE,eAAO,MAAM,SAAS,EAAE,SAAoC,CAAA;AAE5D,eAAO,MAAM,QAAQ,EAAE,SAAmC,CAAA;AAC1D,eAAO,MAAM,YAAY,EAAE,SAAwC,CAAA"}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
// src/error/error-type.ts
|
2
|
+
import { namespace } from "@bessemer/cornerstone/resource-key";
|
3
|
+
import Zod from "zod";
|
4
|
+
var Namespace = namespace("error-type");
|
5
|
+
var Schema = Zod.string().transform((it) => it);
|
6
|
+
var Unhandled = "unhandled";
|
7
|
+
var Unauthorized = "unauthorized";
|
8
|
+
var Forbidden = "forbidden";
|
9
|
+
var Required = "required";
|
10
|
+
var InvalidValue = "invalid-value";
|
11
|
+
export {
|
12
|
+
Forbidden,
|
13
|
+
InvalidValue,
|
14
|
+
Namespace,
|
15
|
+
Required,
|
16
|
+
Schema,
|
17
|
+
Unauthorized,
|
18
|
+
Unhandled
|
19
|
+
};
|
20
|
+
//# sourceMappingURL=error-type.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/error/error-type.ts"],"sourcesContent":["import { namespace } from '@bessemer/cornerstone/resource-key'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport Zod from 'zod'\n\nexport const Namespace = namespace('error-type')\nexport type ErrorType = NominalType<string, typeof Namespace>\nexport const Schema = Zod.string().transform((it) => it as ErrorType)\n\nexport const Unhandled: ErrorType = 'unhandled' as ErrorType\nexport const Unauthorized: ErrorType = 'unauthorized' as ErrorType\nexport const Forbidden: ErrorType = 'forbidden' as ErrorType\n\nexport const Required: ErrorType = 'required' as ErrorType\nexport const InvalidValue: ErrorType = 'invalid-value' as ErrorType\n"],"mappings":";AAAA,SAAS,iBAAiB;AAE1B,OAAO,SAAS;AAET,IAAM,YAAY,UAAU,YAAY;AAExC,IAAM,SAAS,IAAI,OAAO,EAAE,UAAU,CAAC,OAAO,EAAe;AAE7D,IAAM,YAAuB;AAC7B,IAAM,eAA0B;AAChC,IAAM,YAAuB;AAE7B,IAAM,WAAsB;AAC5B,IAAM,eAA0B;","names":[]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/error/error.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,KAEjD,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,OAAO,KAAK,KAAG,KAAK,CAAC,KAAK,CAexD,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAI,OAAO,KAAK,EAAE,WAAW,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,KAAG,KAAK,GAAG,SAE9F,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/error/error.ts"],"sourcesContent":["import { isPresent } from '@bessemer/cornerstone/object'\nimport { Throwable } from '@bessemer/cornerstone/types'\n\nexport const isError = (value: unknown): value is Error => {\n return value instanceof Error\n}\n\nexport const getCausalChain = (error: Error): Array<Error> => {\n const chain: Array<Error> = []\n let current: Error = error\n\n while (true) {\n chain.push(current)\n\n if (!isPresent(current.cause) || !isError(current.cause)) {\n break\n }\n\n current = current.cause\n }\n\n return chain\n}\n\nexport const findInCausalChain = (error: Error, predicate: (error: Error) => boolean): Error | undefined => {\n return getCausalChain(error).find(predicate)\n}\n\nconst serializeError = (error: Throwable): any => {\n if (!isPresent(error)) {\n return undefined\n }\n\n if (!isError(error)) {\n return error\n }\n\n const cause = isPresent(error.cause) ? serializeError(error.cause) : undefined\n\n const serialized = {\n name: error.name,\n message: error.message,\n stack: error.stack,\n cause,\n }\n\n return serialized\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAGnB,IAAM,UAAU,CAAC,UAAmC;AACzD,SAAO,iBAAiB;AAC1B;AAEO,IAAM,iBAAiB,CAAC,UAA+B;AAC5D,QAAM,QAAsB,CAAC;AAC7B,MAAI,UAAiB;AAErB,SAAO,MAAM;AACX,UAAM,KAAK,OAAO;AAElB,QAAI,CAAC,UAAU,QAAQ,KAAK,KAAK,CAAC,QAAQ,QAAQ,KAAK,GAAG;AACxD;AAAA,IACF;AAEA,cAAU,QAAQ;AAAA,EACpB;AAEA,SAAO;AACT;AAEO,IAAM,oBAAoB,CAAC,OAAc,cAA4D;AAC1G,SAAO,eAAe,KAAK,EAAE,KAAK,SAAS;AAC7C;","names":[]}
|
package/dist/expression.d.ts
CHANGED
@@ -2,11 +2,11 @@ import * as NumericExpressions from '@bessemer/cornerstone/expression/numeric-ex
|
|
2
2
|
import * as StringExpressions from '@bessemer/cornerstone/expression/string-expression';
|
3
3
|
import * as ArrayExpressions from '@bessemer/cornerstone/expression/array-expression';
|
4
4
|
import * as Expressions from '@bessemer/cornerstone/expression/expression';
|
5
|
-
import {
|
5
|
+
import { TaggedType } from '@bessemer/cornerstone/types';
|
6
6
|
import { Signable } from '@bessemer/cornerstone/signature';
|
7
7
|
import { UnknownRecord } from 'type-fest';
|
8
8
|
export { Expressions, NumericExpressions, StringExpressions, ArrayExpressions };
|
9
|
-
export type ExpressionKey<ReturnType, ArgumentType extends Array<unknown>> =
|
9
|
+
export type ExpressionKey<ReturnType, ArgumentType extends Array<unknown>> = TaggedType<string, ['ExpressionKey', ReturnType, ArgumentType]>;
|
10
10
|
export type Expression<ReturnType> = ReturnType | IExpression<ReturnType>;
|
11
11
|
export interface IExpression<ReturnType> {
|
12
12
|
expressionKey: ExpressionKey<ReturnType, Array<unknown>>;
|
package/dist/expression.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"expression.d.ts","sourceRoot":"","sources":["../src/expression.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,kBAAkB,MAAM,qDAAqD,CAAA;AACzF,OAAO,KAAK,iBAAiB,MAAM,oDAAoD,CAAA;AACvF,OAAO,KAAK,gBAAgB,MAAM,mDAAmD,CAAA;AACrF,OAAO,KAAK,WAAW,MAAM,6CAA6C,CAAA;AAC1E,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"expression.d.ts","sourceRoot":"","sources":["../src/expression.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,kBAAkB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K,CAAC,OAAO,CAAC,EACnC,cAAc,SAAS,UAAU,CAAC,UAAU,CAAC,IAC3C,mBAAmB,CAAC,UAAU,EAAE,YAAY,CAAC,GAAG;IAClD,aAAa,EAAE,aAAa,CAAC,UAAU,EAAE,YAAY,CAAC,CAAA;IACtD,OAAO,EAAE,CAAC,GAAG,UAAU,EAAE,YAAY,KAAK,cAAc,CAAA;IACxD,QAAQ,EAAE,CAAC,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,kBAAkB,EAAE,OAAO,EAAE,iBAAiB,KAAK,UAAU,CAAA;CAC/G,CAAA;AAED,MAAM,WAAW,kBAAkB,CAAC,CAAC,CAAE,SAAQ,WAAW,CAAC,CAAC,CAAC;IAC3D,aAAa,EAAE,UAAU,CAAA;IACzB,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,qBAAqB,CAAC,SAAS,EAAE,aAAa,SAAS,KAAK,CAAC,QAAQ,CAAC;IACrF,KAAK,CAAC,GAAG,UAAU,EAAE,aAAa,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAA;CACnE;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,EAAE,aAAa,CAAA;CACzB,CAAA"}
|
package/dist/expression.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/expression.ts"],"sourcesContent":["import * as NumericExpressions from '@bessemer/cornerstone/expression/numeric-expression'\nimport * as StringExpressions from '@bessemer/cornerstone/expression/string-expression'\nimport * as ArrayExpressions from '@bessemer/cornerstone/expression/array-expression'\nimport * as Expressions from '@bessemer/cornerstone/expression/expression'\nimport {
|
1
|
+
{"version":3,"sources":["../src/expression.ts"],"sourcesContent":["import * as NumericExpressions from '@bessemer/cornerstone/expression/numeric-expression'\nimport * as StringExpressions from '@bessemer/cornerstone/expression/string-expression'\nimport * as ArrayExpressions from '@bessemer/cornerstone/expression/array-expression'\nimport * as Expressions from '@bessemer/cornerstone/expression/expression'\nimport { TaggedType } from '@bessemer/cornerstone/types'\nimport { Signable } from '@bessemer/cornerstone/signature'\nimport { UnknownRecord } from 'type-fest'\n\nexport { Expressions, NumericExpressions, StringExpressions, ArrayExpressions }\n\nexport type ExpressionKey<ReturnType, ArgumentType extends Array<unknown>> = TaggedType<string, ['ExpressionKey', ReturnType, ArgumentType]>\n\nexport type Expression<ReturnType> = ReturnType | IExpression<ReturnType>\n\nexport interface IExpression<ReturnType> {\n expressionKey: ExpressionKey<ReturnType, Array<unknown>>\n}\n\nexport interface ExpressionReference<ReturnType, ArgumentType extends Array<unknown>> {\n expressionKey: ExpressionKey<ReturnType, ArgumentType>\n}\n\nexport interface ReducingExpression<ReturnType, ArgumentType> extends ExpressionReference<ReturnType, [Array<Expression<ArgumentType>>]> {}\n\nexport type EvaluateExpression = <T>(expression: Expression<T>) => T\n\nexport type ExpressionDefinition<\n ReturnType,\n ArgumentType extends Array<unknown>,\n ExpressionType extends Expression<ReturnType>\n> = ExpressionReference<ReturnType, ArgumentType> & {\n expressionKey: ExpressionKey<ReturnType, ArgumentType>\n builder: (...parameters: ArgumentType) => ExpressionType\n resolver: (expression: ExpressionType, evaluate: EvaluateExpression, context: ExpressionContext) => ReturnType\n}\n\nexport interface ExpressionVariable<T> extends IExpression<T> {\n expressionKey: 'Variable'\n name: string\n}\n\nexport interface ParameterizedVariable<ValueType, ParameterType extends Array<Signable>> {\n apply(...parameters: ParameterType): ExpressionVariable<ValueType>\n}\n\nexport type ExpressionContext = {\n variables: UnknownRecord\n}\n"],"mappings":";AAAA,YAAY,wBAAwB;AACpC,YAAY,uBAAuB;AACnC,YAAY,sBAAsB;AAClC,YAAY,iBAAiB;","names":[]}
|
package/dist/glob.d.ts
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
+
import Zod from 'zod';
|
2
|
+
import { Result } from '@bessemer/cornerstone/result';
|
1
3
|
import { NominalType } from '@bessemer/cornerstone/types';
|
2
|
-
import {
|
3
|
-
export
|
4
|
-
export
|
4
|
+
import { ErrorEvent } from '@bessemer/cornerstone/error/error-event';
|
5
|
+
export declare const Namespace: import("@bessemer/cornerstone/resource-key").ResourceNamespace<"glob-pattern">;
|
6
|
+
export type GlobPattern = NominalType<string, typeof Namespace>;
|
7
|
+
export declare const parseString: (value: string) => Result<GlobPattern, ErrorEvent>;
|
5
8
|
export declare const fromString: (value: string) => GlobPattern;
|
9
|
+
export declare const Schema: Zod.ZodPipe<Zod.ZodString, Zod.ZodTransform<GlobPattern, string>>;
|
6
10
|
export declare const match: (str: string, pattern: GlobPattern) => boolean;
|
7
11
|
export declare const anyMatch: (str: string, patterns: Array<GlobPattern>) => boolean;
|
8
12
|
//# sourceMappingURL=glob.d.ts.map
|
package/dist/glob.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"glob.d.ts","sourceRoot":"","sources":["../src/glob.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,
|
1
|
+
{"version":3,"file":"glob.d.ts","sourceRoot":"","sources":["../src/glob.ts"],"names":[],"mappings":"AACA,OAAO,GAAG,MAAM,KAAK,CAAA;AACrB,OAAO,EAAW,MAAM,EAAW,MAAM,8BAA8B,CAAA;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EAAE,UAAU,EAA8B,MAAM,yCAAyC,CAAA;AAIhG,eAAO,MAAM,SAAS,gFAA4B,CAAA;AAClD,MAAM,MAAM,WAAW,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,SAAS,CAAC,CAAA;AAE/D,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,MAAM,CAAC,WAAW,EAAE,UAAU,CA8BzE,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,WAE1C,CAAA;AAED,eAAO,MAAM,MAAM,mEAAiD,CAAA;AAEpE,eAAO,MAAM,KAAK,GAAI,KAAK,MAAM,EAAE,SAAS,WAAW,KAAG,OAEzD,CAAA;AAED,eAAO,MAAM,QAAQ,GAAI,KAAK,MAAM,EAAE,UAAU,KAAK,CAAC,WAAW,CAAC,KAAG,OAEpE,CAAA"}
|
package/dist/glob.js
CHANGED
@@ -1,32 +1,38 @@
|
|
1
1
|
// src/glob.ts
|
2
2
|
import { minimatch } from "minimatch";
|
3
3
|
import Zod from "zod";
|
4
|
-
|
4
|
+
import { failure, success } from "@bessemer/cornerstone/result";
|
5
|
+
import { invalidValue, unpackResult } from "@bessemer/cornerstone/error/error-event";
|
6
|
+
import { namespace } from "@bessemer/cornerstone/resource-key";
|
7
|
+
import { structuredTransform } from "@bessemer/cornerstone/zod-util";
|
8
|
+
var Namespace = namespace("glob-pattern");
|
9
|
+
var parseString = (value) => {
|
5
10
|
const validGlobPattern = /^[a-zA-Z0-9\-_.\/\\*?\[\]{}!,|]+$/;
|
6
|
-
if (!validGlobPattern.test(
|
7
|
-
return
|
11
|
+
if (!validGlobPattern.test(value)) {
|
12
|
+
return failure(invalidValue(value, { namespace: Namespace, message: `GlobPattern contains invalid characters.` }));
|
8
13
|
}
|
9
|
-
const brackets =
|
14
|
+
const brackets = value.match(/[\[\]]/g);
|
10
15
|
if (brackets) {
|
11
|
-
const openBrackets = (
|
12
|
-
const closeBrackets = (
|
16
|
+
const openBrackets = (value.match(/\[/g) || []).length;
|
17
|
+
const closeBrackets = (value.match(/]/g) || []).length;
|
13
18
|
if (openBrackets !== closeBrackets) {
|
14
|
-
return
|
19
|
+
return failure(invalidValue(value, { namespace: Namespace, message: `GlobPattern has unbalanced brackets.` }));
|
15
20
|
}
|
16
21
|
}
|
17
|
-
const braces =
|
22
|
+
const braces = value.match(/[{}]/g);
|
18
23
|
if (braces) {
|
19
|
-
const openBraces = (
|
20
|
-
const closeBraces = (
|
24
|
+
const openBraces = (value.match(/\{/g) || []).length;
|
25
|
+
const closeBraces = (value.match(/}/g) || []).length;
|
21
26
|
if (openBraces !== closeBraces) {
|
22
|
-
return
|
27
|
+
return failure(invalidValue(value, { namespace: Namespace, message: `GlobPattern has unbalanced braces.` }));
|
23
28
|
}
|
24
29
|
}
|
25
|
-
return
|
26
|
-
}
|
30
|
+
return success(value);
|
31
|
+
};
|
27
32
|
var fromString = (value) => {
|
28
|
-
return
|
33
|
+
return unpackResult(parseString(value));
|
29
34
|
};
|
35
|
+
var Schema = structuredTransform(Zod.string(), parseString);
|
30
36
|
var match = (str, pattern) => {
|
31
37
|
return minimatch(str, pattern);
|
32
38
|
};
|
@@ -34,9 +40,11 @@ var anyMatch = (str, patterns) => {
|
|
34
40
|
return patterns.some((it) => match(str, it));
|
35
41
|
};
|
36
42
|
export {
|
43
|
+
Namespace,
|
37
44
|
Schema,
|
38
45
|
anyMatch,
|
39
46
|
fromString,
|
40
|
-
match
|
47
|
+
match,
|
48
|
+
parseString
|
41
49
|
};
|
42
50
|
//# sourceMappingURL=glob.js.map
|
package/dist/glob.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/glob.ts"],"sourcesContent":["import { minimatch } from 'minimatch'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport
|
1
|
+
{"version":3,"sources":["../src/glob.ts"],"sourcesContent":["import { minimatch } from 'minimatch'\nimport Zod from 'zod'\nimport { failure, Result, success } from '@bessemer/cornerstone/result'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport { ErrorEvent, invalidValue, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport { namespace } from '@bessemer/cornerstone/resource-key'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\n\nexport const Namespace = namespace('glob-pattern')\nexport type GlobPattern = NominalType<string, typeof Namespace>\n\nexport const parseString = (value: string): Result<GlobPattern, ErrorEvent> => {\n // Check for valid glob characters and patterns\n const validGlobPattern = /^[a-zA-Z0-9\\-_.\\/\\\\*?\\[\\]{}!,|]+$/\n\n // Basic validation - contains valid characters\n if (!validGlobPattern.test(value)) {\n return failure(invalidValue(value, { namespace: Namespace, message: `GlobPattern contains invalid characters.` }))\n }\n\n // Check for balanced brackets\n const brackets = value.match(/[\\[\\]]/g)\n if (brackets) {\n const openBrackets = (value.match(/\\[/g) || []).length\n const closeBrackets = (value.match(/]/g) || []).length\n if (openBrackets !== closeBrackets) {\n return failure(invalidValue(value, { namespace: Namespace, message: `GlobPattern has unbalanced brackets.` }))\n }\n }\n\n // Check for balanced braces\n const braces = value.match(/[{}]/g)\n if (braces) {\n const openBraces = (value.match(/\\{/g) || []).length\n const closeBraces = (value.match(/}/g) || []).length\n if (openBraces !== closeBraces) {\n return failure(invalidValue(value, { namespace: Namespace, message: `GlobPattern has unbalanced braces.` }))\n }\n }\n\n return success(value as GlobPattern)\n}\n\nexport const fromString = (value: string): GlobPattern => {\n return unpackResult(parseString(value))\n}\n\nexport const Schema = structuredTransform(Zod.string(), parseString)\n\nexport const match = (str: string, pattern: GlobPattern): boolean => {\n return minimatch(str, pattern)\n}\n\nexport const anyMatch = (str: string, patterns: Array<GlobPattern>): boolean => {\n return patterns.some((it) => match(str, it))\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,OAAO,SAAS;AAChB,SAAS,SAAiB,eAAe;AAEzC,SAAqB,cAAc,oBAAoB;AACvD,SAAS,iBAAiB;AAC1B,SAAS,2BAA2B;AAE7B,IAAM,YAAY,UAAU,cAAc;AAG1C,IAAM,cAAc,CAAC,UAAmD;AAE7E,QAAM,mBAAmB;AAGzB,MAAI,CAAC,iBAAiB,KAAK,KAAK,GAAG;AACjC,WAAO,QAAQ,aAAa,OAAO,EAAE,WAAW,WAAW,SAAS,2CAA2C,CAAC,CAAC;AAAA,EACnH;AAGA,QAAM,WAAW,MAAM,MAAM,SAAS;AACtC,MAAI,UAAU;AACZ,UAAM,gBAAgB,MAAM,MAAM,KAAK,KAAK,CAAC,GAAG;AAChD,UAAM,iBAAiB,MAAM,MAAM,IAAI,KAAK,CAAC,GAAG;AAChD,QAAI,iBAAiB,eAAe;AAClC,aAAO,QAAQ,aAAa,OAAO,EAAE,WAAW,WAAW,SAAS,uCAAuC,CAAC,CAAC;AAAA,IAC/G;AAAA,EACF;AAGA,QAAM,SAAS,MAAM,MAAM,OAAO;AAClC,MAAI,QAAQ;AACV,UAAM,cAAc,MAAM,MAAM,KAAK,KAAK,CAAC,GAAG;AAC9C,UAAM,eAAe,MAAM,MAAM,IAAI,KAAK,CAAC,GAAG;AAC9C,QAAI,eAAe,aAAa;AAC9B,aAAO,QAAQ,aAAa,OAAO,EAAE,WAAW,WAAW,SAAS,qCAAqC,CAAC,CAAC;AAAA,IAC7G;AAAA,EACF;AAEA,SAAO,QAAQ,KAAoB;AACrC;AAEO,IAAM,aAAa,CAAC,UAA+B;AACxD,SAAO,aAAa,YAAY,KAAK,CAAC;AACxC;AAEO,IAAM,SAAS,oBAAoB,IAAI,OAAO,GAAG,WAAW;AAE5D,IAAM,QAAQ,CAAC,KAAa,YAAkC;AACnE,SAAO,UAAU,KAAK,OAAO;AAC/B;AAEO,IAAM,WAAW,CAAC,KAAa,aAA0C;AAC9E,SAAO,SAAS,KAAK,CAAC,OAAO,MAAM,KAAK,EAAE,CAAC;AAC7C;","names":[]}
|
package/dist/hash.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import {
|
2
|
-
export type Hash =
|
1
|
+
import { NominalType } from '@bessemer/cornerstone/types';
|
2
|
+
export type Hash = NominalType<string, 'Hash'>;
|
3
3
|
export declare enum HashAlgorithm {
|
4
4
|
SHA1 = "SHA-1",
|
5
5
|
SHA256 = "SHA-256"
|
package/dist/hash.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAEzD,MAAM,MAAM,IAAI,GAAG,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAE9C,oBAAY,aAAa;IACvB,IAAI,UAAU;IACd,MAAM,YAAY;CACnB;AAED,eAAO,MAAM,QAAQ,GAAI,OAAO,IAAI,KAAG,MAEtC,CAAA;AAED,eAAO,MAAM,YAAY,GAAU,SAAS,MAAM,KAAG,OAAO,CAAC,IAAI,CAEhE,CAAA;AAED,eAAO,MAAM,UAAU,GAAU,SAAS,MAAM,KAAG,OAAO,CAAC,IAAI,CAE9D,CAAA;AAED,eAAO,MAAM,IAAI,GAAU,SAAS,MAAM,EAAE,WAAW,aAAa,KAAG,OAAO,CAAC,IAAI,CAMlF,CAAA"}
|
package/dist/hash.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/hash.ts"],"sourcesContent":["import {
|
1
|
+
{"version":3,"sources":["../src/hash.ts"],"sourcesContent":["import { NominalType } from '@bessemer/cornerstone/types'\n\nexport type Hash = NominalType<string, 'Hash'>\n\nexport enum HashAlgorithm {\n SHA1 = 'SHA-1',\n SHA256 = 'SHA-256',\n}\n\nexport const asString = (value: Hash): string => {\n return value\n}\n\nexport const insecureHash = async (message: string): Promise<Hash> => {\n return hash(message, HashAlgorithm.SHA1)\n}\n\nexport const secureHash = async (message: string): Promise<Hash> => {\n return hash(message, HashAlgorithm.SHA256)\n}\n\nexport const hash = async (message: string, algorithm: HashAlgorithm): Promise<Hash> => {\n const msgBuffer = new TextEncoder().encode(message)\n const hashBuffer = await crypto.subtle.digest(algorithm, msgBuffer)\n const hashArray = Array.from(new Uint8Array(hashBuffer))\n const hashHex = hashArray.map((b) => b.toString(16).padStart(2, '0')).join('')\n return hashHex as Hash\n}\n"],"mappings":";AAIO,IAAK,gBAAL,kBAAKA,mBAAL;AACL,EAAAA,eAAA,UAAO;AACP,EAAAA,eAAA,YAAS;AAFC,SAAAA;AAAA,GAAA;AAKL,IAAM,WAAW,CAAC,UAAwB;AAC/C,SAAO;AACT;AAEO,IAAM,eAAe,OAAO,YAAmC;AACpE,SAAO,KAAK,SAAS,kBAAkB;AACzC;AAEO,IAAM,aAAa,OAAO,YAAmC;AAClE,SAAO,KAAK,SAAS,sBAAoB;AAC3C;AAEO,IAAM,OAAO,OAAO,SAAiB,cAA4C;AACtF,QAAM,YAAY,IAAI,YAAY,EAAE,OAAO,OAAO;AAClD,QAAM,aAAa,MAAM,OAAO,OAAO,OAAO,WAAW,SAAS;AAClE,QAAM,YAAY,MAAM,KAAK,IAAI,WAAW,UAAU,CAAC;AACvD,QAAM,UAAU,UAAU,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE,KAAK,EAAE;AAC7E,SAAO;AACT;","names":["HashAlgorithm"]}
|
package/dist/hex-code.d.ts
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
import Zod from 'zod';
|
2
|
-
import {
|
3
|
-
|
4
|
-
|
5
|
-
export declare const
|
2
|
+
import { NominalType } from '@bessemer/cornerstone/types';
|
3
|
+
import { Result } from '@bessemer/cornerstone/result';
|
4
|
+
import { ErrorEvent } from '@bessemer/cornerstone/error/error-event';
|
5
|
+
export declare const Namespace: import("@bessemer/cornerstone/resource-key").ResourceNamespace<"hex-code">;
|
6
|
+
export type HexCode = NominalType<string, typeof Namespace>;
|
7
|
+
export declare const parseString: (value: string) => Result<HexCode, ErrorEvent>;
|
6
8
|
export declare const fromString: (value: string) => HexCode;
|
9
|
+
export declare const Schema: Zod.ZodPipe<Zod.ZodString, Zod.ZodTransform<HexCode, string>>;
|
7
10
|
//# sourceMappingURL=hex-code.d.ts.map
|
package/dist/hex-code.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"hex-code.d.ts","sourceRoot":"","sources":["../src/hex-code.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAA;AACrB,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"hex-code.d.ts","sourceRoot":"","sources":["../src/hex-code.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAA;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EAAW,MAAM,EAAW,MAAM,8BAA8B,CAAA;AAEvE,OAAO,EAAE,UAAU,EAA8B,MAAM,yCAAyC,CAAA;AAGhG,eAAO,MAAM,SAAS,4EAAwB,CAAA;AAC9C,MAAM,MAAM,OAAO,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,SAAS,CAAC,CAAA;AAE3D,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,MAAM,CAAC,OAAO,EAAE,UAAU,CAarE,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,OAE1C,CAAA;AAED,eAAO,MAAM,MAAM,+DAAiD,CAAA"}
|
package/dist/hex-code.js
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
// src/hex-code.ts
|
2
2
|
import Zod from "zod";
|
3
|
-
|
4
|
-
|
3
|
+
import { failure, success } from "@bessemer/cornerstone/result";
|
4
|
+
import { namespace } from "@bessemer/cornerstone/resource-key";
|
5
|
+
import { invalidValue, unpackResult } from "@bessemer/cornerstone/error/error-event";
|
6
|
+
import { structuredTransform } from "@bessemer/cornerstone/zod-util";
|
7
|
+
var Namespace = namespace("hex-code");
|
8
|
+
var parseString = (value) => {
|
9
|
+
if (!/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(value)) {
|
10
|
+
return failure(invalidValue(value, { namespace: Namespace, message: `HexCode must be a valid hex code (# followed by 3 or 6 characters).` }));
|
11
|
+
}
|
12
|
+
let normalizedValue = value.toUpperCase();
|
13
|
+
if (normalizedValue.length === 4) {
|
14
|
+
const shortHex = normalizedValue.slice(1);
|
15
|
+
normalizedValue = `#${shortHex[0]}${shortHex[0]}${shortHex[1]}${shortHex[1]}${shortHex[2]}${shortHex[2]}`;
|
16
|
+
}
|
17
|
+
return success(normalizedValue);
|
5
18
|
};
|
6
|
-
var Schema = Zod.string().length(7).startsWith("#").describe("A 6-digit hex code starting a # sign").transform(of);
|
7
19
|
var fromString = (value) => {
|
8
|
-
return
|
20
|
+
return unpackResult(parseString(value));
|
9
21
|
};
|
22
|
+
var Schema = structuredTransform(Zod.string(), parseString);
|
10
23
|
export {
|
24
|
+
Namespace,
|
11
25
|
Schema,
|
12
26
|
fromString,
|
13
|
-
|
27
|
+
parseString
|
14
28
|
};
|
15
29
|
//# sourceMappingURL=hex-code.js.map
|
package/dist/hex-code.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/hex-code.ts"],"sourcesContent":["import Zod from 'zod'\nimport {
|
1
|
+
{"version":3,"sources":["../src/hex-code.ts"],"sourcesContent":["import Zod from 'zod'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport { failure, Result, success } from '@bessemer/cornerstone/result'\nimport { namespace } from '@bessemer/cornerstone/resource-key'\nimport { ErrorEvent, invalidValue, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\n\nexport const Namespace = namespace('hex-code')\nexport type HexCode = NominalType<string, typeof Namespace>\n\nexport const parseString = (value: string): Result<HexCode, ErrorEvent> => {\n if (!/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(value)) {\n return failure(invalidValue(value, { namespace: Namespace, message: `HexCode must be a valid hex code (# followed by 3 or 6 characters).` }))\n }\n\n let normalizedValue = value.toUpperCase()\n\n if (normalizedValue.length === 4) {\n const shortHex = normalizedValue.slice(1) // Remove the #\n normalizedValue = `#${shortHex[0]}${shortHex[0]}${shortHex[1]}${shortHex[1]}${shortHex[2]}${shortHex[2]}`\n }\n\n return success(normalizedValue as HexCode)\n}\n\nexport const fromString = (value: string): HexCode => {\n return unpackResult(parseString(value))\n}\n\nexport const Schema = structuredTransform(Zod.string(), parseString)\n"],"mappings":";AAAA,OAAO,SAAS;AAEhB,SAAS,SAAiB,eAAe;AACzC,SAAS,iBAAiB;AAC1B,SAAqB,cAAc,oBAAoB;AACvD,SAAS,2BAA2B;AAE7B,IAAM,YAAY,UAAU,UAAU;AAGtC,IAAM,cAAc,CAAC,UAA+C;AACzE,MAAI,CAAC,qCAAqC,KAAK,KAAK,GAAG;AACrD,WAAO,QAAQ,aAAa,OAAO,EAAE,WAAW,WAAW,SAAS,sEAAsE,CAAC,CAAC;AAAA,EAC9I;AAEA,MAAI,kBAAkB,MAAM,YAAY;AAExC,MAAI,gBAAgB,WAAW,GAAG;AAChC,UAAM,WAAW,gBAAgB,MAAM,CAAC;AACxC,sBAAkB,IAAI,SAAS,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;AAAA,EACzG;AAEA,SAAO,QAAQ,eAA0B;AAC3C;AAEO,IAAM,aAAa,CAAC,UAA2B;AACpD,SAAO,aAAa,YAAY,KAAK,CAAC;AACxC;AAEO,IAAM,SAAS,oBAAoB,IAAI,OAAO,GAAG,WAAW;","names":[]}
|