hume 0.8.0 → 0.8.1-beta0
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/.mock/definition/empathic-voice/__package__.yml +3 -65
- package/Client.d.ts +3 -0
- package/api/resources/empathicVoice/client/Client.d.ts +3 -0
- package/api/resources/empathicVoice/resources/chat/client/Socket.d.ts +8 -8
- package/api/resources/empathicVoice/resources/chat/client/Socket.js +13 -40
- package/api/resources/empathicVoice/resources/chatGroups/client/Client.d.ts +3 -0
- package/api/resources/empathicVoice/resources/chatGroups/client/Client.js +4 -4
- package/api/resources/empathicVoice/resources/chats/client/Client.d.ts +3 -0
- package/api/resources/empathicVoice/resources/chats/client/Client.js +4 -4
- package/api/resources/empathicVoice/resources/configs/client/Client.d.ts +3 -0
- package/api/resources/empathicVoice/resources/configs/client/Client.js +19 -23
- package/api/resources/empathicVoice/resources/prompts/client/Client.d.ts +3 -0
- package/api/resources/empathicVoice/resources/prompts/client/Client.js +19 -23
- package/api/resources/empathicVoice/resources/tools/client/Client.d.ts +3 -0
- package/api/resources/empathicVoice/resources/tools/client/Client.js +19 -19
- package/api/resources/empathicVoice/types/SessionSettings.d.ts +2 -0
- package/api/resources/empathicVoice/types/VoiceArgs.d.ts +0 -2
- package/api/resources/empathicVoice/types/index.d.ts +0 -1
- package/api/resources/empathicVoice/types/index.js +0 -1
- package/api/resources/expressionMeasurement/client/Client.d.ts +3 -0
- package/api/resources/expressionMeasurement/resources/batch/client/Client.d.ts +3 -0
- package/api/resources/expressionMeasurement/resources/batch/client/Client.js +12 -12
- package/core/form-data-utils/FormDataWrapper.js +1 -3
- package/core/schemas/Schema.d.ts +3 -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 +88 -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 +12 -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 +3 -0
- package/dist/api/resources/empathicVoice/client/Client.d.ts +3 -0
- package/dist/api/resources/empathicVoice/resources/chat/client/Socket.d.ts +8 -8
- package/dist/api/resources/empathicVoice/resources/chat/client/Socket.js +13 -40
- package/dist/api/resources/empathicVoice/resources/chatGroups/client/Client.d.ts +3 -0
- package/dist/api/resources/empathicVoice/resources/chatGroups/client/Client.js +4 -4
- package/dist/api/resources/empathicVoice/resources/chats/client/Client.d.ts +3 -0
- package/dist/api/resources/empathicVoice/resources/chats/client/Client.js +4 -4
- package/dist/api/resources/empathicVoice/resources/configs/client/Client.d.ts +3 -0
- package/dist/api/resources/empathicVoice/resources/configs/client/Client.js +19 -23
- package/dist/api/resources/empathicVoice/resources/prompts/client/Client.d.ts +3 -0
- package/dist/api/resources/empathicVoice/resources/prompts/client/Client.js +19 -23
- package/dist/api/resources/empathicVoice/resources/tools/client/Client.d.ts +3 -0
- package/dist/api/resources/empathicVoice/resources/tools/client/Client.js +19 -19
- package/dist/api/resources/empathicVoice/types/SessionSettings.d.ts +2 -0
- package/dist/api/resources/empathicVoice/types/VoiceArgs.d.ts +0 -2
- package/dist/api/resources/empathicVoice/types/index.d.ts +0 -1
- package/dist/api/resources/empathicVoice/types/index.js +0 -1
- package/dist/api/resources/expressionMeasurement/client/Client.d.ts +3 -0
- package/dist/api/resources/expressionMeasurement/resources/batch/client/Client.d.ts +3 -0
- package/dist/api/resources/expressionMeasurement/resources/batch/client/Client.js +12 -12
- package/dist/core/form-data-utils/FormDataWrapper.js +1 -3
- package/dist/core/schemas/Schema.d.ts +3 -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 +88 -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 +12 -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/resources/empathicVoice/types/SessionSettings.d.ts +1 -0
- package/dist/serialization/resources/empathicVoice/types/SessionSettings.js +1 -0
- package/dist/serialization/resources/empathicVoice/types/VoiceArgs.d.ts +0 -3
- package/dist/serialization/resources/empathicVoice/types/VoiceArgs.js +0 -3
- package/dist/serialization/resources/empathicVoice/types/index.d.ts +0 -1
- package/dist/serialization/resources/empathicVoice/types/index.js +0 -1
- package/package.json +1 -1
- package/serialization/resources/empathicVoice/types/SessionSettings.d.ts +1 -0
- package/serialization/resources/empathicVoice/types/SessionSettings.js +1 -0
- package/serialization/resources/empathicVoice/types/VoiceArgs.d.ts +0 -3
- package/serialization/resources/empathicVoice/types/VoiceArgs.js +0 -3
- package/serialization/resources/empathicVoice/types/index.d.ts +0 -1
- package/serialization/resources/empathicVoice/types/index.js +0 -1
- package/api/resources/empathicVoice/types/Features.d.ts +0 -21
- package/api/resources/empathicVoice/types/Features.js +0 -5
- package/dist/api/resources/empathicVoice/types/Features.d.ts +0 -21
- package/dist/api/resources/empathicVoice/types/Features.js +0 -5
- package/dist/serialization/resources/empathicVoice/types/Features.d.ts +0 -19
- package/dist/serialization/resources/empathicVoice/types/Features.js +0 -40
- package/serialization/resources/empathicVoice/types/Features.d.ts +0 -19
- package/serialization/resources/empathicVoice/types/Features.js +0 -40
|
@@ -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.list = void 0;
|
|
13
4
|
const Schema_1 = require("../../Schema");
|
|
@@ -16,11 +7,9 @@ const maybeSkipValidation_1 = require("../../utils/maybeSkipValidation");
|
|
|
16
7
|
const schema_utils_1 = require("../schema-utils");
|
|
17
8
|
function list(schema) {
|
|
18
9
|
const baseSchema = {
|
|
19
|
-
parse: (raw, opts) =>
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return schema.parse(item, Object.assign(Object.assign({}, opts), { breadcrumbsPrefix: [...((_a = opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix) !== null && _a !== void 0 ? _a : []), `[${index}]`] }));
|
|
23
|
-
});
|
|
10
|
+
parse: (raw, opts) => validateAndTransformArray(raw, (item, index) => {
|
|
11
|
+
var _a;
|
|
12
|
+
return schema.parse(item, Object.assign(Object.assign({}, opts), { breadcrumbsPrefix: [...((_a = opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix) !== null && _a !== void 0 ? _a : []), `[${index}]`] }));
|
|
24
13
|
}),
|
|
25
14
|
json: (parsed, opts) => validateAndTransformArray(parsed, (item, index) => {
|
|
26
15
|
var _a;
|
|
@@ -32,37 +21,35 @@ function list(schema) {
|
|
|
32
21
|
}
|
|
33
22
|
exports.list = list;
|
|
34
23
|
function validateAndTransformArray(value, transformItem) {
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
if (!Array.isArray(value)) {
|
|
25
|
+
return {
|
|
26
|
+
ok: false,
|
|
27
|
+
errors: [
|
|
28
|
+
{
|
|
29
|
+
message: (0, getErrorMessageForIncorrectType_1.getErrorMessageForIncorrectType)(value, "list"),
|
|
30
|
+
path: [],
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const maybeValidItems = value.map((item, index) => transformItem(item, index));
|
|
36
|
+
return maybeValidItems.reduce((acc, item) => {
|
|
37
|
+
if (acc.ok && item.ok) {
|
|
37
38
|
return {
|
|
38
|
-
ok:
|
|
39
|
-
|
|
40
|
-
{
|
|
41
|
-
message: (0, getErrorMessageForIncorrectType_1.getErrorMessageForIncorrectType)(value, "list"),
|
|
42
|
-
path: [],
|
|
43
|
-
},
|
|
44
|
-
],
|
|
39
|
+
ok: true,
|
|
40
|
+
value: [...acc.value, item.value],
|
|
45
41
|
};
|
|
46
42
|
}
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (!item.ok) {
|
|
60
|
-
errors.push(...item.errors);
|
|
61
|
-
}
|
|
62
|
-
return {
|
|
63
|
-
ok: false,
|
|
64
|
-
errors,
|
|
65
|
-
};
|
|
66
|
-
}, { ok: true, value: [] });
|
|
67
|
-
});
|
|
43
|
+
const errors = [];
|
|
44
|
+
if (!acc.ok) {
|
|
45
|
+
errors.push(...acc.errors);
|
|
46
|
+
}
|
|
47
|
+
if (!item.ok) {
|
|
48
|
+
errors.push(...item.errors);
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
ok: false,
|
|
52
|
+
errors,
|
|
53
|
+
};
|
|
54
|
+
}, { ok: true, value: [] });
|
|
68
55
|
}
|
|
@@ -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)) {
|
|
@@ -63,8 +54,8 @@ function object(schemas) {
|
|
|
63
54
|
skipValidation: opts === null || opts === void 0 ? void 0 : opts.skipValidation,
|
|
64
55
|
breadcrumbsPrefix: opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix,
|
|
65
56
|
});
|
|
66
|
-
}
|
|
67
|
-
json: (parsed, opts) =>
|
|
57
|
+
},
|
|
58
|
+
json: (parsed, opts) => {
|
|
68
59
|
const requiredKeys = [];
|
|
69
60
|
for (const [parsedKey, schemaOrObjectProperty] of (0, entries_1.entries)(schemas)) {
|
|
70
61
|
const valueSchema = (0, property_1.isProperty)(schemaOrObjectProperty)
|
|
@@ -106,109 +97,97 @@ function object(schemas) {
|
|
|
106
97
|
skipValidation: opts === null || opts === void 0 ? void 0 : opts.skipValidation,
|
|
107
98
|
breadcrumbsPrefix: opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix,
|
|
108
99
|
});
|
|
109
|
-
}
|
|
100
|
+
},
|
|
110
101
|
getType: () => Schema_1.SchemaType.OBJECT,
|
|
111
102
|
};
|
|
112
103
|
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
104
|
}
|
|
114
105
|
exports.object = object;
|
|
115
106
|
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
|
-
}
|
|
107
|
+
if (!(0, isPlainObject_1.isPlainObject)(value)) {
|
|
108
|
+
return {
|
|
109
|
+
ok: false,
|
|
110
|
+
errors: [
|
|
111
|
+
{
|
|
112
|
+
path: breadcrumbsPrefix,
|
|
113
|
+
message: (0, getErrorMessageForIncorrectType_1.getErrorMessageForIncorrectType)(value, "object"),
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
const missingRequiredKeys = new Set(requiredKeys);
|
|
119
|
+
const errors = [];
|
|
120
|
+
const transformed = {};
|
|
121
|
+
for (const [preTransformedKey, preTransformedItemValue] of Object.entries(value)) {
|
|
122
|
+
const property = getProperty(preTransformedKey);
|
|
123
|
+
if (property != null) {
|
|
124
|
+
missingRequiredKeys.delete(preTransformedKey);
|
|
125
|
+
const value = property.transform(preTransformedItemValue);
|
|
126
|
+
if (value.ok) {
|
|
127
|
+
transformed[property.transformedKey] = value.value;
|
|
143
128
|
}
|
|
144
129
|
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
|
-
}
|
|
130
|
+
transformed[preTransformedKey] = preTransformedItemValue;
|
|
131
|
+
errors.push(...value.errors);
|
|
158
132
|
}
|
|
159
133
|
}
|
|
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
134
|
else {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
135
|
+
switch (unrecognizedObjectKeys) {
|
|
136
|
+
case "fail":
|
|
137
|
+
errors.push({
|
|
138
|
+
path: [...breadcrumbsPrefix, preTransformedKey],
|
|
139
|
+
message: `Unexpected key "${preTransformedKey}"`,
|
|
140
|
+
});
|
|
141
|
+
break;
|
|
142
|
+
case "strip":
|
|
143
|
+
break;
|
|
144
|
+
case "passthrough":
|
|
145
|
+
transformed[preTransformedKey] = preTransformedItemValue;
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
177
148
|
}
|
|
178
|
-
}
|
|
149
|
+
}
|
|
150
|
+
errors.push(...requiredKeys
|
|
151
|
+
.filter((key) => missingRequiredKeys.has(key))
|
|
152
|
+
.map((key) => ({
|
|
153
|
+
path: breadcrumbsPrefix,
|
|
154
|
+
message: `Missing required key "${key}"`,
|
|
155
|
+
})));
|
|
156
|
+
if (errors.length === 0 || skipValidation) {
|
|
157
|
+
return {
|
|
158
|
+
ok: true,
|
|
159
|
+
value: transformed,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
return {
|
|
164
|
+
ok: false,
|
|
165
|
+
errors,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
179
168
|
}
|
|
180
169
|
function getObjectUtils(schema) {
|
|
181
170
|
return {
|
|
182
171
|
extend: (extension) => {
|
|
183
172
|
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* () {
|
|
173
|
+
_getParsedProperties: () => [...schema._getParsedProperties(), ...extension._getParsedProperties()],
|
|
174
|
+
_getRawProperties: () => [...schema._getRawProperties(), ...extension._getRawProperties()],
|
|
175
|
+
parse: (raw, opts) => {
|
|
197
176
|
return validateAndTransformExtendedObject({
|
|
198
|
-
extensionKeys:
|
|
177
|
+
extensionKeys: extension._getRawProperties(),
|
|
199
178
|
value: raw,
|
|
200
179
|
transformBase: (rawBase) => schema.parse(rawBase, opts),
|
|
201
180
|
transformExtension: (rawExtension) => extension.parse(rawExtension, opts),
|
|
202
181
|
});
|
|
203
|
-
}
|
|
204
|
-
json: (parsed, opts) =>
|
|
182
|
+
},
|
|
183
|
+
json: (parsed, opts) => {
|
|
205
184
|
return validateAndTransformExtendedObject({
|
|
206
|
-
extensionKeys:
|
|
185
|
+
extensionKeys: extension._getParsedProperties(),
|
|
207
186
|
value: parsed,
|
|
208
187
|
transformBase: (parsedBase) => schema.json(parsedBase, opts),
|
|
209
188
|
transformExtension: (parsedExtension) => extension.json(parsedExtension, opts),
|
|
210
189
|
});
|
|
211
|
-
}
|
|
190
|
+
},
|
|
212
191
|
getType: () => Schema_1.SchemaType.OBJECT,
|
|
213
192
|
};
|
|
214
193
|
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 +196,25 @@ function getObjectUtils(schema) {
|
|
|
217
196
|
}
|
|
218
197
|
exports.getObjectUtils = getObjectUtils;
|
|
219
198
|
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
|
-
});
|
|
199
|
+
const extensionPropertiesSet = new Set(extensionKeys);
|
|
200
|
+
const [extensionProperties, baseProperties] = (0, partition_1.partition)((0, keys_1.keys)(value), (key) => extensionPropertiesSet.has(key));
|
|
201
|
+
const transformedBase = transformBase((0, filterObject_1.filterObject)(value, baseProperties));
|
|
202
|
+
const transformedExtension = transformExtension((0, filterObject_1.filterObject)(value, extensionProperties));
|
|
203
|
+
if (transformedBase.ok && transformedExtension.ok) {
|
|
204
|
+
return {
|
|
205
|
+
ok: true,
|
|
206
|
+
value: Object.assign(Object.assign({}, transformedBase.value), transformedExtension.value),
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
return {
|
|
211
|
+
ok: false,
|
|
212
|
+
errors: [
|
|
213
|
+
...(transformedBase.ok ? [] : transformedBase.errors),
|
|
214
|
+
...(transformedExtension.ok ? [] : transformedExtension.errors),
|
|
215
|
+
],
|
|
216
|
+
};
|
|
217
|
+
}
|
|
241
218
|
}
|
|
242
219
|
function isSchemaRequired(schema) {
|
|
243
220
|
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;
|
|
@@ -64,8 +55,8 @@ function optional(schema) {
|
|
|
64
55
|
exports.optional = optional;
|
|
65
56
|
function transform(schema, transformer) {
|
|
66
57
|
const baseSchema = {
|
|
67
|
-
parse: (raw, opts) =>
|
|
68
|
-
const parsed =
|
|
58
|
+
parse: (raw, opts) => {
|
|
59
|
+
const parsed = schema.parse(raw, opts);
|
|
69
60
|
if (!parsed.ok) {
|
|
70
61
|
return parsed;
|
|
71
62
|
}
|
|
@@ -73,11 +64,11 @@ function transform(schema, transformer) {
|
|
|
73
64
|
ok: true,
|
|
74
65
|
value: transformer.transform(parsed.value),
|
|
75
66
|
};
|
|
76
|
-
}
|
|
77
|
-
json: (transformed, opts) =>
|
|
78
|
-
const parsed =
|
|
67
|
+
},
|
|
68
|
+
json: (transformed, opts) => {
|
|
69
|
+
const parsed = transformer.untransform(transformed);
|
|
79
70
|
return schema.json(parsed, opts);
|
|
80
|
-
}
|
|
71
|
+
},
|
|
81
72
|
getType: () => schema.getType(),
|
|
82
73
|
};
|
|
83
74
|
return Object.assign(Object.assign({}, baseSchema), getSchemaUtils(baseSchema));
|