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
|
@@ -96,7 +96,7 @@ class Batch {
|
|
|
96
96
|
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
|
|
97
97
|
url: (0, url_join_1.default)((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.HumeEnvironment.Production, "v0/batch/jobs"),
|
|
98
98
|
method: "GET",
|
|
99
|
-
headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.
|
|
99
|
+
headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.7.3", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())),
|
|
100
100
|
contentType: "application/json",
|
|
101
101
|
queryParameters: _queryParams,
|
|
102
102
|
timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
|
|
@@ -104,7 +104,7 @@ class Batch {
|
|
|
104
104
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
105
105
|
});
|
|
106
106
|
if (_response.ok) {
|
|
107
|
-
return
|
|
107
|
+
return serializers.expressionMeasurement.batch.listJobs.Response.parseOrThrow(_response.body, {
|
|
108
108
|
unrecognizedObjectKeys: "passthrough",
|
|
109
109
|
allowUnrecognizedUnionMembers: true,
|
|
110
110
|
allowUnrecognizedEnumValues: true,
|
|
@@ -150,9 +150,9 @@ class Batch {
|
|
|
150
150
|
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
|
|
151
151
|
url: (0, url_join_1.default)((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.HumeEnvironment.Production, "v0/batch/jobs"),
|
|
152
152
|
method: "POST",
|
|
153
|
-
headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.
|
|
153
|
+
headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.7.3", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())),
|
|
154
154
|
contentType: "application/json",
|
|
155
|
-
body:
|
|
155
|
+
body: serializers.expressionMeasurement.InferenceBaseRequest.jsonOrThrow(request, {
|
|
156
156
|
unrecognizedObjectKeys: "strip",
|
|
157
157
|
}),
|
|
158
158
|
timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
|
|
@@ -160,7 +160,7 @@ class Batch {
|
|
|
160
160
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
161
161
|
});
|
|
162
162
|
if (_response.ok) {
|
|
163
|
-
return
|
|
163
|
+
return serializers.expressionMeasurement.JobId.parseOrThrow(_response.body, {
|
|
164
164
|
unrecognizedObjectKeys: "passthrough",
|
|
165
165
|
allowUnrecognizedUnionMembers: true,
|
|
166
166
|
allowUnrecognizedEnumValues: true,
|
|
@@ -203,14 +203,14 @@ class Batch {
|
|
|
203
203
|
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
|
|
204
204
|
url: (0, url_join_1.default)((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.HumeEnvironment.Production, `v0/batch/jobs/${encodeURIComponent(id)}`),
|
|
205
205
|
method: "GET",
|
|
206
|
-
headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.
|
|
206
|
+
headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.7.3", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())),
|
|
207
207
|
contentType: "application/json",
|
|
208
208
|
timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
|
|
209
209
|
maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
|
|
210
210
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
211
211
|
});
|
|
212
212
|
if (_response.ok) {
|
|
213
|
-
return
|
|
213
|
+
return serializers.expressionMeasurement.UnionJob.parseOrThrow(_response.body, {
|
|
214
214
|
unrecognizedObjectKeys: "passthrough",
|
|
215
215
|
allowUnrecognizedUnionMembers: true,
|
|
216
216
|
allowUnrecognizedEnumValues: true,
|
|
@@ -253,14 +253,14 @@ class Batch {
|
|
|
253
253
|
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
|
|
254
254
|
url: (0, url_join_1.default)((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.HumeEnvironment.Production, `v0/batch/jobs/${encodeURIComponent(id)}/predictions`),
|
|
255
255
|
method: "GET",
|
|
256
|
-
headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.
|
|
256
|
+
headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.7.3", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())),
|
|
257
257
|
contentType: "application/json",
|
|
258
258
|
timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
|
|
259
259
|
maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
|
|
260
260
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
261
261
|
});
|
|
262
262
|
if (_response.ok) {
|
|
263
|
-
return
|
|
263
|
+
return serializers.expressionMeasurement.batch.getJobPredictions.Response.parseOrThrow(_response.body, {
|
|
264
264
|
unrecognizedObjectKeys: "passthrough",
|
|
265
265
|
allowUnrecognizedUnionMembers: true,
|
|
266
266
|
allowUnrecognizedEnumValues: true,
|
|
@@ -297,7 +297,7 @@ class Batch {
|
|
|
297
297
|
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
|
|
298
298
|
url: (0, url_join_1.default)((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.HumeEnvironment.Production, `v0/batch/jobs/${encodeURIComponent(id)}/artifacts`),
|
|
299
299
|
method: "GET",
|
|
300
|
-
headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.
|
|
300
|
+
headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.7.3", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())),
|
|
301
301
|
contentType: "application/json",
|
|
302
302
|
responseType: "streaming",
|
|
303
303
|
timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
|
|
@@ -352,14 +352,14 @@ class Batch {
|
|
|
352
352
|
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
|
|
353
353
|
url: (0, url_join_1.default)((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.HumeEnvironment.Production, "v0/batch/jobs"),
|
|
354
354
|
method: "POST",
|
|
355
|
-
headers: Object.assign(Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.
|
|
355
|
+
headers: Object.assign(Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.7.3", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())), (yield _maybeEncodedRequest.getHeaders())),
|
|
356
356
|
body: yield _maybeEncodedRequest.getBody(),
|
|
357
357
|
timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
|
|
358
358
|
maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
|
|
359
359
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
360
360
|
});
|
|
361
361
|
if (_response.ok) {
|
|
362
|
-
return
|
|
362
|
+
return serializers.expressionMeasurement.JobId.parseOrThrow(_response.body, {
|
|
363
363
|
unrecognizedObjectKeys: "passthrough",
|
|
364
364
|
allowUnrecognizedUnionMembers: true,
|
|
365
365
|
allowUnrecognizedEnumValues: true,
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { SchemaUtils } from "./builders";
|
|
2
|
-
import { MaybePromise } from "./utils/MaybePromise";
|
|
3
2
|
export declare type Schema<Raw = unknown, Parsed = unknown> = BaseSchema<Raw, Parsed> & SchemaUtils<Raw, Parsed>;
|
|
4
3
|
export declare type inferRaw<S extends Schema> = S extends Schema<infer Raw, any> ? Raw : never;
|
|
5
4
|
export declare type inferParsed<S extends Schema> = S extends Schema<any, infer Parsed> ? Parsed : never;
|
|
6
5
|
export interface BaseSchema<Raw, Parsed> {
|
|
7
|
-
parse: (raw: unknown, opts?: SchemaOptions) =>
|
|
8
|
-
json: (parsed: unknown, opts?: SchemaOptions) =>
|
|
9
|
-
getType: () => SchemaType |
|
|
6
|
+
parse: (raw: unknown, opts?: SchemaOptions) => MaybeValid<Parsed>;
|
|
7
|
+
json: (parsed: unknown, opts?: SchemaOptions) => MaybeValid<Raw>;
|
|
8
|
+
getType: () => SchemaType | SchemaType;
|
|
10
9
|
}
|
|
11
10
|
export declare const SchemaType: {
|
|
12
11
|
readonly DATE: "date";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseSchema, Schema } from "../../Schema";
|
|
2
|
-
export declare type SchemaGetter<SchemaType extends Schema<any, any>> = () => SchemaType
|
|
2
|
+
export declare type SchemaGetter<SchemaType extends Schema<any, any>> = () => SchemaType;
|
|
3
3
|
export declare function lazy<Raw, Parsed>(getter: SchemaGetter<Schema<Raw, Parsed>>): Schema<Raw, Parsed>;
|
|
4
4
|
export declare function constructLazyBaseSchema<Raw, Parsed>(getter: SchemaGetter<Schema<Raw, Parsed>>): BaseSchema<Raw, Parsed>;
|
|
5
|
-
export declare function getMemoizedSchema<SchemaType extends Schema<any, any>>(getter: SchemaGetter<SchemaType>):
|
|
5
|
+
export declare function getMemoizedSchema<SchemaType extends Schema<any, any>>(getter: SchemaGetter<SchemaType>): SchemaType;
|
|
@@ -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.getMemoizedSchema = exports.constructLazyBaseSchema = exports.lazy = void 0;
|
|
13
4
|
const schema_utils_1 = require("../schema-utils");
|
|
@@ -18,19 +9,17 @@ function lazy(getter) {
|
|
|
18
9
|
exports.lazy = lazy;
|
|
19
10
|
function constructLazyBaseSchema(getter) {
|
|
20
11
|
return {
|
|
21
|
-
parse: (raw, opts) =>
|
|
22
|
-
json: (parsed, opts) =>
|
|
23
|
-
getType: () =>
|
|
12
|
+
parse: (raw, opts) => getMemoizedSchema(getter).parse(raw, opts),
|
|
13
|
+
json: (parsed, opts) => getMemoizedSchema(getter).json(parsed, opts),
|
|
14
|
+
getType: () => getMemoizedSchema(getter).getType(),
|
|
24
15
|
};
|
|
25
16
|
}
|
|
26
17
|
exports.constructLazyBaseSchema = constructLazyBaseSchema;
|
|
27
18
|
function getMemoizedSchema(getter) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return castedGetter.__zurg_memoized;
|
|
34
|
-
});
|
|
19
|
+
const castedGetter = getter;
|
|
20
|
+
if (castedGetter.__zurg_memoized == null) {
|
|
21
|
+
castedGetter.__zurg_memoized = getter();
|
|
22
|
+
}
|
|
23
|
+
return castedGetter.__zurg_memoized;
|
|
35
24
|
}
|
|
36
25
|
exports.getMemoizedSchema = getMemoizedSchema;
|
|
@@ -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.lazyObject = void 0;
|
|
13
4
|
const object_1 = require("../object");
|
|
@@ -15,7 +6,7 @@ const object_like_1 = require("../object-like");
|
|
|
15
6
|
const schema_utils_1 = require("../schema-utils");
|
|
16
7
|
const lazy_1 = require("./lazy");
|
|
17
8
|
function lazyObject(getter) {
|
|
18
|
-
const baseSchema = Object.assign(Object.assign({}, (0, lazy_1.constructLazyBaseSchema)(getter)), { _getRawProperties: () =>
|
|
9
|
+
const baseSchema = Object.assign(Object.assign({}, (0, lazy_1.constructLazyBaseSchema)(getter)), { _getRawProperties: () => (0, lazy_1.getMemoizedSchema)(getter)._getRawProperties(), _getParsedProperties: () => (0, lazy_1.getMemoizedSchema)(getter)._getParsedProperties() });
|
|
19
10
|
return Object.assign(Object.assign(Object.assign(Object.assign({}, baseSchema), (0, schema_utils_1.getSchemaUtils)(baseSchema)), (0, object_like_1.getObjectLikeUtils)(baseSchema)), (0, object_1.getObjectUtils)(baseSchema));
|
|
20
11
|
}
|
|
21
12
|
exports.lazyObject = lazyObject;
|
|
@@ -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)) {
|