vellum-ai 0.6.7 → 0.6.11
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/Client.d.ts +9 -6
- package/Client.js +40 -37
- package/api/client/requests/ExecutePromptRequest.d.ts +7 -5
- package/api/client/requests/ExecutePromptStreamRequest.d.ts +7 -5
- package/api/resources/deployments/client/Client.d.ts +8 -5
- package/api/resources/deployments/client/Client.js +22 -17
- package/api/resources/documentIndexes/client/Client.d.ts +37 -12
- package/api/resources/documentIndexes/client/Client.js +128 -30
- package/api/resources/documents/client/Client.d.ts +11 -7
- package/api/resources/documents/client/Client.js +25 -22
- package/api/resources/folderEntities/client/Client.d.ts +4 -1
- package/api/resources/folderEntities/client/Client.js +4 -3
- package/api/resources/sandboxes/client/Client.d.ts +7 -4
- package/api/resources/sandboxes/client/Client.js +14 -13
- package/api/resources/testSuiteRuns/client/Client.d.ts +6 -3
- package/api/resources/testSuiteRuns/client/Client.js +13 -10
- package/api/resources/testSuites/client/Client.d.ts +6 -3
- package/api/resources/testSuites/client/Client.js +16 -14
- package/api/resources/workflowDeployments/client/Client.d.ts +7 -4
- package/api/resources/workflowDeployments/client/Client.js +17 -13
- package/api/resources/workflowSandboxes/client/Client.d.ts +4 -1
- package/api/resources/workflowSandboxes/client/Client.js +5 -6
- package/api/types/IterationStateEnum.d.ts +12 -0
- package/api/types/IterationStateEnum.js +10 -0
- package/api/types/MapNodeResultData.d.ts +2 -0
- package/api/types/PromptNodeResultData.d.ts +1 -0
- package/api/types/TestSuiteRunMetricNumberOutput.d.ts +1 -1
- package/api/types/TestSuiteRunMetricStringOutput.d.ts +1 -1
- package/api/types/TestSuiteTestCaseRejectedBulkResult.d.ts +1 -1
- package/api/types/index.d.ts +1 -0
- package/api/types/index.js +1 -0
- package/core/fetcher/Fetcher.d.ts +2 -0
- package/core/fetcher/Fetcher.js +19 -185
- package/core/fetcher/createRequestUrl.d.ts +1 -0
- package/core/fetcher/createRequestUrl.js +13 -0
- package/core/fetcher/getFetchFn.d.ts +4 -0
- package/core/fetcher/getFetchFn.js +55 -0
- package/core/fetcher/getRequestBody.d.ts +7 -0
- package/core/fetcher/getRequestBody.js +23 -0
- package/core/fetcher/getResponseBody.d.ts +1 -0
- package/core/fetcher/getResponseBody.js +48 -0
- package/core/fetcher/makeRequest.d.ts +1 -0
- package/core/fetcher/makeRequest.js +40 -0
- package/core/fetcher/requestWithRetries.d.ts +1 -0
- package/core/fetcher/requestWithRetries.js +32 -0
- package/core/fetcher/signals.d.ts +12 -0
- package/core/fetcher/signals.js +37 -0
- package/core/form-data-utils/FormDataWrapper.d.ts +10 -21
- package/core/form-data-utils/FormDataWrapper.js +82 -49
- package/core/runtime/runtime.d.ts +1 -0
- package/core/runtime/runtime.js +1 -0
- package/core/schemas/Schema.d.ts +7 -4
- package/core/schemas/builders/lazy/lazy.d.ts +2 -2
- package/core/schemas/builders/lazy/lazy.js +8 -19
- package/core/schemas/builders/lazy/lazyObject.js +1 -10
- package/core/schemas/builders/list/list.js +31 -44
- package/core/schemas/builders/object/object.js +90 -111
- package/core/schemas/builders/object/types.d.ts +2 -2
- package/core/schemas/builders/object-like/getObjectLikeUtils.js +3 -12
- package/core/schemas/builders/record/record.js +49 -60
- package/core/schemas/builders/schema-utils/getSchemaUtils.d.ts +2 -2
- package/core/schemas/builders/schema-utils/getSchemaUtils.js +18 -21
- package/core/schemas/builders/set/set.js +6 -15
- package/core/schemas/builders/undiscriminated-union/undiscriminatedUnion.js +21 -32
- package/core/schemas/builders/union/union.js +51 -62
- package/core/schemas/utils/maybeSkipValidation.js +3 -12
- package/dist/Client.d.ts +9 -6
- package/dist/Client.js +40 -37
- package/dist/api/client/requests/ExecutePromptRequest.d.ts +7 -5
- package/dist/api/client/requests/ExecutePromptStreamRequest.d.ts +7 -5
- package/dist/api/resources/deployments/client/Client.d.ts +8 -5
- package/dist/api/resources/deployments/client/Client.js +22 -17
- package/dist/api/resources/documentIndexes/client/Client.d.ts +37 -12
- package/dist/api/resources/documentIndexes/client/Client.js +128 -30
- package/dist/api/resources/documents/client/Client.d.ts +11 -7
- package/dist/api/resources/documents/client/Client.js +25 -22
- package/dist/api/resources/folderEntities/client/Client.d.ts +4 -1
- package/dist/api/resources/folderEntities/client/Client.js +4 -3
- package/dist/api/resources/sandboxes/client/Client.d.ts +7 -4
- package/dist/api/resources/sandboxes/client/Client.js +14 -13
- package/dist/api/resources/testSuiteRuns/client/Client.d.ts +6 -3
- package/dist/api/resources/testSuiteRuns/client/Client.js +13 -10
- package/dist/api/resources/testSuites/client/Client.d.ts +6 -3
- package/dist/api/resources/testSuites/client/Client.js +16 -14
- package/dist/api/resources/workflowDeployments/client/Client.d.ts +7 -4
- package/dist/api/resources/workflowDeployments/client/Client.js +17 -13
- package/dist/api/resources/workflowSandboxes/client/Client.d.ts +4 -1
- package/dist/api/resources/workflowSandboxes/client/Client.js +5 -6
- package/dist/api/types/IterationStateEnum.d.ts +12 -0
- package/dist/api/types/IterationStateEnum.js +10 -0
- package/dist/api/types/MapNodeResultData.d.ts +2 -0
- package/dist/api/types/PromptNodeResultData.d.ts +1 -0
- package/dist/api/types/TestSuiteRunMetricNumberOutput.d.ts +1 -1
- package/dist/api/types/TestSuiteRunMetricStringOutput.d.ts +1 -1
- package/dist/api/types/TestSuiteTestCaseRejectedBulkResult.d.ts +1 -1
- package/dist/api/types/index.d.ts +1 -0
- package/dist/api/types/index.js +1 -0
- package/dist/core/fetcher/Fetcher.d.ts +2 -0
- package/dist/core/fetcher/Fetcher.js +19 -185
- package/dist/core/fetcher/createRequestUrl.d.ts +1 -0
- package/dist/core/fetcher/createRequestUrl.js +13 -0
- package/dist/core/fetcher/getFetchFn.d.ts +4 -0
- package/dist/core/fetcher/getFetchFn.js +55 -0
- package/dist/core/fetcher/getRequestBody.d.ts +7 -0
- package/dist/core/fetcher/getRequestBody.js +23 -0
- package/dist/core/fetcher/getResponseBody.d.ts +1 -0
- package/dist/core/fetcher/getResponseBody.js +48 -0
- package/dist/core/fetcher/makeRequest.d.ts +1 -0
- package/dist/core/fetcher/makeRequest.js +40 -0
- package/dist/core/fetcher/requestWithRetries.d.ts +1 -0
- package/dist/core/fetcher/requestWithRetries.js +32 -0
- package/dist/core/fetcher/signals.d.ts +12 -0
- package/dist/core/fetcher/signals.js +37 -0
- package/dist/core/form-data-utils/FormDataWrapper.d.ts +10 -21
- package/dist/core/form-data-utils/FormDataWrapper.js +82 -49
- package/dist/core/runtime/runtime.d.ts +1 -0
- package/dist/core/runtime/runtime.js +1 -0
- package/dist/core/schemas/Schema.d.ts +7 -4
- package/dist/core/schemas/builders/lazy/lazy.d.ts +2 -2
- package/dist/core/schemas/builders/lazy/lazy.js +8 -19
- package/dist/core/schemas/builders/lazy/lazyObject.js +1 -10
- package/dist/core/schemas/builders/list/list.js +31 -44
- package/dist/core/schemas/builders/object/object.js +90 -111
- package/dist/core/schemas/builders/object/types.d.ts +2 -2
- package/dist/core/schemas/builders/object-like/getObjectLikeUtils.js +3 -12
- package/dist/core/schemas/builders/record/record.js +49 -60
- package/dist/core/schemas/builders/schema-utils/getSchemaUtils.d.ts +2 -2
- package/dist/core/schemas/builders/schema-utils/getSchemaUtils.js +18 -21
- package/dist/core/schemas/builders/set/set.js +6 -15
- package/dist/core/schemas/builders/undiscriminated-union/undiscriminatedUnion.js +21 -32
- package/dist/core/schemas/builders/union/union.js +51 -62
- package/dist/core/schemas/utils/maybeSkipValidation.js +3 -12
- package/dist/serialization/types/IterationStateEnum.d.ts +10 -0
- package/dist/serialization/types/IterationStateEnum.js +31 -0
- package/dist/serialization/types/MapNodeResultData.d.ts +2 -0
- package/dist/serialization/types/MapNodeResultData.js +2 -0
- package/dist/serialization/types/MetadataFilterConfigRequest.js +2 -10
- package/dist/serialization/types/MetadataFilterRuleRequest.js +2 -10
- package/dist/serialization/types/PromptNodeResultData.d.ts +1 -0
- package/dist/serialization/types/PromptNodeResultData.js +1 -0
- package/dist/serialization/types/TestSuiteRunMetricNumberOutput.d.ts +1 -1
- package/dist/serialization/types/TestSuiteRunMetricNumberOutput.js +1 -1
- package/dist/serialization/types/TestSuiteRunMetricStringOutput.d.ts +1 -1
- package/dist/serialization/types/TestSuiteRunMetricStringOutput.js +1 -1
- package/dist/serialization/types/TestSuiteTestCaseRejectedBulkResult.d.ts +1 -1
- package/dist/serialization/types/TestSuiteTestCaseRejectedBulkResult.js +1 -1
- package/dist/serialization/types/index.d.ts +1 -0
- package/dist/serialization/types/index.js +1 -0
- package/package.json +6 -1
- package/reference.md +2418 -0
- package/serialization/types/IterationStateEnum.d.ts +10 -0
- package/serialization/types/IterationStateEnum.js +31 -0
- package/serialization/types/MapNodeResultData.d.ts +2 -0
- package/serialization/types/MapNodeResultData.js +2 -0
- package/serialization/types/MetadataFilterConfigRequest.js +2 -10
- package/serialization/types/MetadataFilterRuleRequest.js +2 -10
- package/serialization/types/PromptNodeResultData.d.ts +1 -0
- package/serialization/types/PromptNodeResultData.js +1 -0
- package/serialization/types/TestSuiteRunMetricNumberOutput.d.ts +1 -1
- package/serialization/types/TestSuiteRunMetricNumberOutput.js +1 -1
- package/serialization/types/TestSuiteRunMetricStringOutput.d.ts +1 -1
- package/serialization/types/TestSuiteRunMetricStringOutput.js +1 -1
- package/serialization/types/TestSuiteTestCaseRejectedBulkResult.d.ts +1 -1
- package/serialization/types/TestSuiteTestCaseRejectedBulkResult.js +1 -1
- package/serialization/types/index.d.ts +1 -0
- package/serialization/types/index.js +1 -0
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.getObjectUtils = exports.object = void 0;
|
|
13
4
|
const Schema_1 = require("../../Schema");
|
|
@@ -23,9 +14,9 @@ const schema_utils_1 = require("../schema-utils");
|
|
|
23
14
|
const property_1 = require("./property");
|
|
24
15
|
function object(schemas) {
|
|
25
16
|
const baseSchema = {
|
|
26
|
-
_getRawProperties: () =>
|
|
27
|
-
_getParsedProperties: () =>
|
|
28
|
-
parse: (raw, opts) =>
|
|
17
|
+
_getRawProperties: () => Object.entries(schemas).map(([parsedKey, propertySchema]) => (0, property_1.isProperty)(propertySchema) ? propertySchema.rawKey : parsedKey),
|
|
18
|
+
_getParsedProperties: () => (0, keys_1.keys)(schemas),
|
|
19
|
+
parse: (raw, opts) => {
|
|
29
20
|
const rawKeyToProperty = {};
|
|
30
21
|
const requiredKeys = [];
|
|
31
22
|
for (const [parsedKey, schemaOrObjectProperty] of (0, entries_1.entries)(schemas)) {
|
|
@@ -62,9 +53,10 @@ function object(schemas) {
|
|
|
62
53
|
unrecognizedObjectKeys: opts === null || opts === void 0 ? void 0 : opts.unrecognizedObjectKeys,
|
|
63
54
|
skipValidation: opts === null || opts === void 0 ? void 0 : opts.skipValidation,
|
|
64
55
|
breadcrumbsPrefix: opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix,
|
|
56
|
+
omitUndefined: opts === null || opts === void 0 ? void 0 : opts.omitUndefined,
|
|
65
57
|
});
|
|
66
|
-
}
|
|
67
|
-
json: (parsed, opts) =>
|
|
58
|
+
},
|
|
59
|
+
json: (parsed, opts) => {
|
|
68
60
|
const requiredKeys = [];
|
|
69
61
|
for (const [parsedKey, schemaOrObjectProperty] of (0, entries_1.entries)(schemas)) {
|
|
70
62
|
const valueSchema = (0, property_1.isProperty)(schemaOrObjectProperty)
|
|
@@ -105,110 +97,99 @@ function object(schemas) {
|
|
|
105
97
|
unrecognizedObjectKeys: opts === null || opts === void 0 ? void 0 : opts.unrecognizedObjectKeys,
|
|
106
98
|
skipValidation: opts === null || opts === void 0 ? void 0 : opts.skipValidation,
|
|
107
99
|
breadcrumbsPrefix: opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix,
|
|
100
|
+
omitUndefined: opts === null || opts === void 0 ? void 0 : opts.omitUndefined,
|
|
108
101
|
});
|
|
109
|
-
}
|
|
102
|
+
},
|
|
110
103
|
getType: () => Schema_1.SchemaType.OBJECT,
|
|
111
104
|
};
|
|
112
105
|
return Object.assign(Object.assign(Object.assign(Object.assign({}, (0, maybeSkipValidation_1.maybeSkipValidation)(baseSchema)), (0, schema_utils_1.getSchemaUtils)(baseSchema)), (0, object_like_1.getObjectLikeUtils)(baseSchema)), getObjectUtils(baseSchema));
|
|
113
106
|
}
|
|
114
107
|
exports.object = object;
|
|
115
108
|
function validateAndTransformObject({ value, requiredKeys, getProperty, unrecognizedObjectKeys = "fail", skipValidation = false, breadcrumbsPrefix = [], }) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
transformed[property.transformedKey] = value.value;
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
transformed[preTransformedKey] = preTransformedItemValue;
|
|
141
|
-
errors.push(...value.errors);
|
|
142
|
-
}
|
|
109
|
+
if (!(0, isPlainObject_1.isPlainObject)(value)) {
|
|
110
|
+
return {
|
|
111
|
+
ok: false,
|
|
112
|
+
errors: [
|
|
113
|
+
{
|
|
114
|
+
path: breadcrumbsPrefix,
|
|
115
|
+
message: (0, getErrorMessageForIncorrectType_1.getErrorMessageForIncorrectType)(value, "object"),
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const missingRequiredKeys = new Set(requiredKeys);
|
|
121
|
+
const errors = [];
|
|
122
|
+
const transformed = {};
|
|
123
|
+
for (const [preTransformedKey, preTransformedItemValue] of Object.entries(value)) {
|
|
124
|
+
const property = getProperty(preTransformedKey);
|
|
125
|
+
if (property != null) {
|
|
126
|
+
missingRequiredKeys.delete(preTransformedKey);
|
|
127
|
+
const value = property.transform(preTransformedItemValue);
|
|
128
|
+
if (value.ok) {
|
|
129
|
+
transformed[property.transformedKey] = value.value;
|
|
143
130
|
}
|
|
144
131
|
else {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
errors.push({
|
|
148
|
-
path: [...breadcrumbsPrefix, preTransformedKey],
|
|
149
|
-
message: `Unexpected key "${preTransformedKey}"`,
|
|
150
|
-
});
|
|
151
|
-
break;
|
|
152
|
-
case "strip":
|
|
153
|
-
break;
|
|
154
|
-
case "passthrough":
|
|
155
|
-
transformed[preTransformedKey] = preTransformedItemValue;
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
132
|
+
transformed[preTransformedKey] = preTransformedItemValue;
|
|
133
|
+
errors.push(...value.errors);
|
|
158
134
|
}
|
|
159
135
|
}
|
|
160
|
-
errors.push(...requiredKeys
|
|
161
|
-
.filter((key) => missingRequiredKeys.has(key))
|
|
162
|
-
.map((key) => ({
|
|
163
|
-
path: breadcrumbsPrefix,
|
|
164
|
-
message: `Missing required key "${key}"`,
|
|
165
|
-
})));
|
|
166
|
-
if (errors.length === 0 || skipValidation) {
|
|
167
|
-
return {
|
|
168
|
-
ok: true,
|
|
169
|
-
value: transformed,
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
136
|
else {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
137
|
+
switch (unrecognizedObjectKeys) {
|
|
138
|
+
case "fail":
|
|
139
|
+
errors.push({
|
|
140
|
+
path: [...breadcrumbsPrefix, preTransformedKey],
|
|
141
|
+
message: `Unexpected key "${preTransformedKey}"`,
|
|
142
|
+
});
|
|
143
|
+
break;
|
|
144
|
+
case "strip":
|
|
145
|
+
break;
|
|
146
|
+
case "passthrough":
|
|
147
|
+
transformed[preTransformedKey] = preTransformedItemValue;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
177
150
|
}
|
|
178
|
-
}
|
|
151
|
+
}
|
|
152
|
+
errors.push(...requiredKeys
|
|
153
|
+
.filter((key) => missingRequiredKeys.has(key))
|
|
154
|
+
.map((key) => ({
|
|
155
|
+
path: breadcrumbsPrefix,
|
|
156
|
+
message: `Missing required key "${key}"`,
|
|
157
|
+
})));
|
|
158
|
+
if (errors.length === 0 || skipValidation) {
|
|
159
|
+
return {
|
|
160
|
+
ok: true,
|
|
161
|
+
value: transformed,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
return {
|
|
166
|
+
ok: false,
|
|
167
|
+
errors,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
179
170
|
}
|
|
180
171
|
function getObjectUtils(schema) {
|
|
181
172
|
return {
|
|
182
173
|
extend: (extension) => {
|
|
183
174
|
const baseSchema = {
|
|
184
|
-
_getParsedProperties: () =>
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
...(yield extension._getParsedProperties()),
|
|
188
|
-
];
|
|
189
|
-
}),
|
|
190
|
-
_getRawProperties: () => __awaiter(this, void 0, void 0, function* () {
|
|
191
|
-
return [
|
|
192
|
-
...(yield schema._getRawProperties()),
|
|
193
|
-
...(yield extension._getRawProperties()),
|
|
194
|
-
];
|
|
195
|
-
}),
|
|
196
|
-
parse: (raw, opts) => __awaiter(this, void 0, void 0, function* () {
|
|
175
|
+
_getParsedProperties: () => [...schema._getParsedProperties(), ...extension._getParsedProperties()],
|
|
176
|
+
_getRawProperties: () => [...schema._getRawProperties(), ...extension._getRawProperties()],
|
|
177
|
+
parse: (raw, opts) => {
|
|
197
178
|
return validateAndTransformExtendedObject({
|
|
198
|
-
extensionKeys:
|
|
179
|
+
extensionKeys: extension._getRawProperties(),
|
|
199
180
|
value: raw,
|
|
200
181
|
transformBase: (rawBase) => schema.parse(rawBase, opts),
|
|
201
182
|
transformExtension: (rawExtension) => extension.parse(rawExtension, opts),
|
|
202
183
|
});
|
|
203
|
-
}
|
|
204
|
-
json: (parsed, opts) =>
|
|
184
|
+
},
|
|
185
|
+
json: (parsed, opts) => {
|
|
205
186
|
return validateAndTransformExtendedObject({
|
|
206
|
-
extensionKeys:
|
|
187
|
+
extensionKeys: extension._getParsedProperties(),
|
|
207
188
|
value: parsed,
|
|
208
189
|
transformBase: (parsedBase) => schema.json(parsedBase, opts),
|
|
209
190
|
transformExtension: (parsedExtension) => extension.json(parsedExtension, opts),
|
|
210
191
|
});
|
|
211
|
-
}
|
|
192
|
+
},
|
|
212
193
|
getType: () => Schema_1.SchemaType.OBJECT,
|
|
213
194
|
};
|
|
214
195
|
return Object.assign(Object.assign(Object.assign(Object.assign({}, baseSchema), (0, schema_utils_1.getSchemaUtils)(baseSchema)), (0, object_like_1.getObjectLikeUtils)(baseSchema)), getObjectUtils(baseSchema));
|
|
@@ -217,27 +198,25 @@ function getObjectUtils(schema) {
|
|
|
217
198
|
}
|
|
218
199
|
exports.getObjectUtils = getObjectUtils;
|
|
219
200
|
function validateAndTransformExtendedObject({ extensionKeys, value, transformBase, transformExtension, }) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
});
|
|
201
|
+
const extensionPropertiesSet = new Set(extensionKeys);
|
|
202
|
+
const [extensionProperties, baseProperties] = (0, partition_1.partition)((0, keys_1.keys)(value), (key) => extensionPropertiesSet.has(key));
|
|
203
|
+
const transformedBase = transformBase((0, filterObject_1.filterObject)(value, baseProperties));
|
|
204
|
+
const transformedExtension = transformExtension((0, filterObject_1.filterObject)(value, extensionProperties));
|
|
205
|
+
if (transformedBase.ok && transformedExtension.ok) {
|
|
206
|
+
return {
|
|
207
|
+
ok: true,
|
|
208
|
+
value: Object.assign(Object.assign({}, transformedBase.value), transformedExtension.value),
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
return {
|
|
213
|
+
ok: false,
|
|
214
|
+
errors: [
|
|
215
|
+
...(transformedBase.ok ? [] : transformedBase.errors),
|
|
216
|
+
...(transformedExtension.ok ? [] : transformedExtension.errors),
|
|
217
|
+
],
|
|
218
|
+
};
|
|
219
|
+
}
|
|
241
220
|
}
|
|
242
221
|
function isSchemaRequired(schema) {
|
|
243
222
|
return !isSchemaOptional(schema);
|
|
@@ -5,8 +5,8 @@ import { SchemaUtils } from "../schema-utils";
|
|
|
5
5
|
import { Property } from "./property";
|
|
6
6
|
export declare type ObjectSchema<Raw, Parsed> = BaseObjectSchema<Raw, Parsed> & ObjectLikeUtils<Raw, Parsed> & ObjectUtils<Raw, Parsed> & SchemaUtils<Raw, Parsed>;
|
|
7
7
|
export interface BaseObjectSchema<Raw, Parsed> extends BaseSchema<Raw, Parsed> {
|
|
8
|
-
_getRawProperties: () =>
|
|
9
|
-
_getParsedProperties: () =>
|
|
8
|
+
_getRawProperties: () => (keyof Raw)[];
|
|
9
|
+
_getParsedProperties: () => (keyof Parsed)[];
|
|
10
10
|
}
|
|
11
11
|
export interface ObjectUtils<Raw, Parsed> {
|
|
12
12
|
extend: <RawExtension, ParsedExtension>(schemas: ObjectSchema<RawExtension, ParsedExtension>) => ObjectSchema<Raw & RawExtension, Parsed & ParsedExtension>;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.withParsedProperties = exports.getObjectLikeUtils = void 0;
|
|
13
4
|
const filterObject_1 = require("../../utils/filterObject");
|
|
@@ -25,8 +16,8 @@ exports.getObjectLikeUtils = getObjectLikeUtils;
|
|
|
25
16
|
*/
|
|
26
17
|
function withParsedProperties(objectLike, properties) {
|
|
27
18
|
const objectSchema = {
|
|
28
|
-
parse: (raw, opts) =>
|
|
29
|
-
const parsedObject =
|
|
19
|
+
parse: (raw, opts) => {
|
|
20
|
+
const parsedObject = objectLike.parse(raw, opts);
|
|
30
21
|
if (!parsedObject.ok) {
|
|
31
22
|
return parsedObject;
|
|
32
23
|
}
|
|
@@ -37,7 +28,7 @@ function withParsedProperties(objectLike, properties) {
|
|
|
37
28
|
ok: true,
|
|
38
29
|
value: Object.assign(Object.assign({}, parsedObject.value), additionalProperties),
|
|
39
30
|
};
|
|
40
|
-
}
|
|
31
|
+
},
|
|
41
32
|
json: (parsed, opts) => {
|
|
42
33
|
var _a;
|
|
43
34
|
if (!(0, isPlainObject_1.isPlainObject)(parsed)) {
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.record = void 0;
|
|
13
4
|
const Schema_1 = require("../../Schema");
|
|
@@ -18,10 +9,10 @@ const maybeSkipValidation_1 = require("../../utils/maybeSkipValidation");
|
|
|
18
9
|
const schema_utils_1 = require("../schema-utils");
|
|
19
10
|
function record(keySchema, valueSchema) {
|
|
20
11
|
const baseSchema = {
|
|
21
|
-
parse: (raw, opts) =>
|
|
12
|
+
parse: (raw, opts) => {
|
|
22
13
|
return validateAndTransformRecord({
|
|
23
14
|
value: raw,
|
|
24
|
-
isKeyNumeric:
|
|
15
|
+
isKeyNumeric: keySchema.getType() === Schema_1.SchemaType.NUMBER,
|
|
25
16
|
transformKey: (key) => {
|
|
26
17
|
var _a;
|
|
27
18
|
return keySchema.parse(key, Object.assign(Object.assign({}, opts), { breadcrumbsPrefix: [...((_a = opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix) !== null && _a !== void 0 ? _a : []), `${key} (key)`] }));
|
|
@@ -32,11 +23,11 @@ function record(keySchema, valueSchema) {
|
|
|
32
23
|
},
|
|
33
24
|
breadcrumbsPrefix: opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix,
|
|
34
25
|
});
|
|
35
|
-
}
|
|
36
|
-
json: (parsed, opts) =>
|
|
26
|
+
},
|
|
27
|
+
json: (parsed, opts) => {
|
|
37
28
|
return validateAndTransformRecord({
|
|
38
29
|
value: parsed,
|
|
39
|
-
isKeyNumeric:
|
|
30
|
+
isKeyNumeric: keySchema.getType() === Schema_1.SchemaType.NUMBER,
|
|
40
31
|
transformKey: (key) => {
|
|
41
32
|
var _a;
|
|
42
33
|
return keySchema.json(key, Object.assign(Object.assign({}, opts), { breadcrumbsPrefix: [...((_a = opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix) !== null && _a !== void 0 ? _a : []), `${key} (key)`] }));
|
|
@@ -47,60 +38,58 @@ function record(keySchema, valueSchema) {
|
|
|
47
38
|
},
|
|
48
39
|
breadcrumbsPrefix: opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix,
|
|
49
40
|
});
|
|
50
|
-
}
|
|
41
|
+
},
|
|
51
42
|
getType: () => Schema_1.SchemaType.RECORD,
|
|
52
43
|
};
|
|
53
44
|
return Object.assign(Object.assign({}, (0, maybeSkipValidation_1.maybeSkipValidation)(baseSchema)), (0, schema_utils_1.getSchemaUtils)(baseSchema));
|
|
54
45
|
}
|
|
55
46
|
exports.record = record;
|
|
56
47
|
function validateAndTransformRecord({ value, isKeyNumeric, transformKey, transformValue, breadcrumbsPrefix = [], }) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
48
|
+
if (!(0, isPlainObject_1.isPlainObject)(value)) {
|
|
49
|
+
return {
|
|
50
|
+
ok: false,
|
|
51
|
+
errors: [
|
|
52
|
+
{
|
|
53
|
+
path: breadcrumbsPrefix,
|
|
54
|
+
message: (0, getErrorMessageForIncorrectType_1.getErrorMessageForIncorrectType)(value, "object"),
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return (0, entries_1.entries)(value).reduce((accPromise, [stringKey, value]) => {
|
|
60
|
+
// skip nullish keys
|
|
61
|
+
if (value == null) {
|
|
62
|
+
return accPromise;
|
|
68
63
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
let key = stringKey;
|
|
76
|
-
if (isKeyNumeric) {
|
|
77
|
-
const numberKey = stringKey.length > 0 ? Number(stringKey) : NaN;
|
|
78
|
-
if (!isNaN(numberKey)) {
|
|
79
|
-
key = numberKey;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
const transformedKey = yield transformKey(key);
|
|
83
|
-
const transformedValue = yield transformValue(value, key);
|
|
84
|
-
if (acc.ok && transformedKey.ok && transformedValue.ok) {
|
|
85
|
-
return {
|
|
86
|
-
ok: true,
|
|
87
|
-
value: Object.assign(Object.assign({}, acc.value), { [transformedKey.value]: transformedValue.value }),
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
const errors = [];
|
|
91
|
-
if (!acc.ok) {
|
|
92
|
-
errors.push(...acc.errors);
|
|
93
|
-
}
|
|
94
|
-
if (!transformedKey.ok) {
|
|
95
|
-
errors.push(...transformedKey.errors);
|
|
96
|
-
}
|
|
97
|
-
if (!transformedValue.ok) {
|
|
98
|
-
errors.push(...transformedValue.errors);
|
|
64
|
+
const acc = accPromise;
|
|
65
|
+
let key = stringKey;
|
|
66
|
+
if (isKeyNumeric) {
|
|
67
|
+
const numberKey = stringKey.length > 0 ? Number(stringKey) : NaN;
|
|
68
|
+
if (!isNaN(numberKey)) {
|
|
69
|
+
key = numberKey;
|
|
99
70
|
}
|
|
71
|
+
}
|
|
72
|
+
const transformedKey = transformKey(key);
|
|
73
|
+
const transformedValue = transformValue(value, key);
|
|
74
|
+
if (acc.ok && transformedKey.ok && transformedValue.ok) {
|
|
100
75
|
return {
|
|
101
|
-
ok:
|
|
102
|
-
|
|
76
|
+
ok: true,
|
|
77
|
+
value: Object.assign(Object.assign({}, acc.value), { [transformedKey.value]: transformedValue.value }),
|
|
103
78
|
};
|
|
104
|
-
}
|
|
105
|
-
|
|
79
|
+
}
|
|
80
|
+
const errors = [];
|
|
81
|
+
if (!acc.ok) {
|
|
82
|
+
errors.push(...acc.errors);
|
|
83
|
+
}
|
|
84
|
+
if (!transformedKey.ok) {
|
|
85
|
+
errors.push(...transformedKey.errors);
|
|
86
|
+
}
|
|
87
|
+
if (!transformedValue.ok) {
|
|
88
|
+
errors.push(...transformedValue.errors);
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
ok: false,
|
|
92
|
+
errors,
|
|
93
|
+
};
|
|
94
|
+
}, { ok: true, value: {} });
|
|
106
95
|
}
|
|
@@ -2,8 +2,8 @@ import { BaseSchema, Schema, SchemaOptions } from "../../Schema";
|
|
|
2
2
|
export interface SchemaUtils<Raw, Parsed> {
|
|
3
3
|
optional: () => Schema<Raw | null | undefined, Parsed | undefined>;
|
|
4
4
|
transform: <Transformed>(transformer: SchemaTransformer<Parsed, Transformed>) => Schema<Raw, Transformed>;
|
|
5
|
-
parseOrThrow: (raw: unknown, opts?: SchemaOptions) =>
|
|
6
|
-
jsonOrThrow: (raw: unknown, opts?: SchemaOptions) =>
|
|
5
|
+
parseOrThrow: (raw: unknown, opts?: SchemaOptions) => Parsed;
|
|
6
|
+
jsonOrThrow: (raw: unknown, opts?: SchemaOptions) => Raw;
|
|
7
7
|
}
|
|
8
8
|
export interface SchemaTransformer<Parsed, Transformed> {
|
|
9
9
|
transform: (parsed: Parsed) => Transformed;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.transform = exports.optional = exports.getSchemaUtils = void 0;
|
|
13
4
|
const Schema_1 = require("../../Schema");
|
|
@@ -17,20 +8,20 @@ function getSchemaUtils(schema) {
|
|
|
17
8
|
return {
|
|
18
9
|
optional: () => optional(schema),
|
|
19
10
|
transform: (transformer) => transform(schema, transformer),
|
|
20
|
-
parseOrThrow: (raw, opts) =>
|
|
21
|
-
const parsed =
|
|
11
|
+
parseOrThrow: (raw, opts) => {
|
|
12
|
+
const parsed = schema.parse(raw, opts);
|
|
22
13
|
if (parsed.ok) {
|
|
23
14
|
return parsed.value;
|
|
24
15
|
}
|
|
25
16
|
throw new ParseError_1.ParseError(parsed.errors);
|
|
26
|
-
}
|
|
27
|
-
jsonOrThrow: (parsed, opts) =>
|
|
28
|
-
const raw =
|
|
17
|
+
},
|
|
18
|
+
jsonOrThrow: (parsed, opts) => {
|
|
19
|
+
const raw = schema.json(parsed, opts);
|
|
29
20
|
if (raw.ok) {
|
|
30
21
|
return raw.value;
|
|
31
22
|
}
|
|
32
23
|
throw new JsonError_1.JsonError(raw.errors);
|
|
33
|
-
}
|
|
24
|
+
},
|
|
34
25
|
};
|
|
35
26
|
}
|
|
36
27
|
exports.getSchemaUtils = getSchemaUtils;
|
|
@@ -49,6 +40,12 @@ function optional(schema) {
|
|
|
49
40
|
return schema.parse(raw, opts);
|
|
50
41
|
},
|
|
51
42
|
json: (parsed, opts) => {
|
|
43
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.omitUndefined) && parsed === undefined) {
|
|
44
|
+
return {
|
|
45
|
+
ok: true,
|
|
46
|
+
value: undefined,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
52
49
|
if (parsed == null) {
|
|
53
50
|
return {
|
|
54
51
|
ok: true,
|
|
@@ -64,8 +61,8 @@ function optional(schema) {
|
|
|
64
61
|
exports.optional = optional;
|
|
65
62
|
function transform(schema, transformer) {
|
|
66
63
|
const baseSchema = {
|
|
67
|
-
parse: (raw, opts) =>
|
|
68
|
-
const parsed =
|
|
64
|
+
parse: (raw, opts) => {
|
|
65
|
+
const parsed = schema.parse(raw, opts);
|
|
69
66
|
if (!parsed.ok) {
|
|
70
67
|
return parsed;
|
|
71
68
|
}
|
|
@@ -73,11 +70,11 @@ function transform(schema, transformer) {
|
|
|
73
70
|
ok: true,
|
|
74
71
|
value: transformer.transform(parsed.value),
|
|
75
72
|
};
|
|
76
|
-
}
|
|
77
|
-
json: (transformed, opts) =>
|
|
78
|
-
const parsed =
|
|
73
|
+
},
|
|
74
|
+
json: (transformed, opts) => {
|
|
75
|
+
const parsed = transformer.untransform(transformed);
|
|
79
76
|
return schema.json(parsed, opts);
|
|
80
|
-
}
|
|
77
|
+
},
|
|
81
78
|
getType: () => schema.getType(),
|
|
82
79
|
};
|
|
83
80
|
return Object.assign(Object.assign({}, baseSchema), getSchemaUtils(baseSchema));
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.set = void 0;
|
|
13
4
|
const Schema_1 = require("../../Schema");
|
|
@@ -18,8 +9,8 @@ const schema_utils_1 = require("../schema-utils");
|
|
|
18
9
|
function set(schema) {
|
|
19
10
|
const listSchema = (0, list_1.list)(schema);
|
|
20
11
|
const baseSchema = {
|
|
21
|
-
parse: (raw, opts) =>
|
|
22
|
-
const parsedList =
|
|
12
|
+
parse: (raw, opts) => {
|
|
13
|
+
const parsedList = listSchema.parse(raw, opts);
|
|
23
14
|
if (parsedList.ok) {
|
|
24
15
|
return {
|
|
25
16
|
ok: true,
|
|
@@ -29,8 +20,8 @@ function set(schema) {
|
|
|
29
20
|
else {
|
|
30
21
|
return parsedList;
|
|
31
22
|
}
|
|
32
|
-
}
|
|
33
|
-
json: (parsed, opts) =>
|
|
23
|
+
},
|
|
24
|
+
json: (parsed, opts) => {
|
|
34
25
|
var _a;
|
|
35
26
|
if (!(parsed instanceof Set)) {
|
|
36
27
|
return {
|
|
@@ -43,9 +34,9 @@ function set(schema) {
|
|
|
43
34
|
],
|
|
44
35
|
};
|
|
45
36
|
}
|
|
46
|
-
const jsonList =
|
|
37
|
+
const jsonList = listSchema.json([...parsed], opts);
|
|
47
38
|
return jsonList;
|
|
48
|
-
}
|
|
39
|
+
},
|
|
49
40
|
getType: () => Schema_1.SchemaType.SET,
|
|
50
41
|
};
|
|
51
42
|
return Object.assign(Object.assign({}, (0, maybeSkipValidation_1.maybeSkipValidation)(baseSchema)), (0, schema_utils_1.getSchemaUtils)(baseSchema));
|