@fern-api/venus-api-sdk 0.0.18 → 0.0.20
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/core.d.ts +1 -0
- package/dist/browser/cjs/core.js +702 -167
- package/dist/browser/cjs/index.js +996 -391
- package/dist/browser/cjs/serialization.js +930 -329
- package/dist/browser/esm/core.js +702 -167
- package/dist/browser/esm/index.js +996 -391
- package/dist/browser/esm/serialization.js +936 -329
- package/dist/node/core.js +702 -167
- package/dist/node/index.js +996 -391
- package/dist/node/serialization.js +1002 -391
- package/package.json +2 -2
- package/serialization.d.ts +1 -0
- package/types/api/resources/organization/client/Client.d.ts +6 -6
- package/types/api/resources/organization/client/addUser.d.ts +0 -1
- package/types/api/resources/organization/client/create.d.ts +0 -1
- package/types/api/resources/organization/client/get.d.ts +0 -1
- package/types/api/resources/organization/client/getMyOrganizationFromScopedToken.d.ts +0 -1
- package/types/api/resources/organization/client/isMember.d.ts +0 -1
- package/types/api/resources/organization/client/update.d.ts +0 -1
- package/types/api/resources/registry/client/Client.d.ts +3 -3
- package/types/api/resources/registry/client/generateRegistryTokens.d.ts +0 -1
- package/types/api/resources/registry/client/hasRegistryPermission.d.ts +0 -1
- package/types/api/resources/registry/client/revokeToken.d.ts +0 -1
- package/types/api/resources/user/client/Client.d.ts +2 -2
- package/types/api/resources/user/client/getMyOrganizations.d.ts +0 -1
- package/types/api/resources/user/client/getMyself.d.ts +0 -1
- package/types/core/fetcher/Fetcher.d.ts +1 -1
- package/types/core/schemas/Schema.d.ts +35 -7
- package/types/core/schemas/builders/enum/enum.d.ts +1 -1
- package/types/core/schemas/builders/index.d.ts +0 -1
- package/types/core/schemas/builders/literals/stringLiteral.d.ts +1 -1
- package/types/core/schemas/builders/object/types.d.ts +5 -4
- package/types/core/schemas/builders/object-like/getObjectLikeUtils.d.ts +4 -3
- package/types/core/schemas/builders/object-like/index.d.ts +2 -2
- package/types/core/schemas/builders/object-like/types.d.ts +2 -8
- package/types/core/schemas/builders/primitives/any.d.ts +1 -1
- package/types/core/schemas/builders/primitives/boolean.d.ts +1 -1
- package/types/core/schemas/builders/primitives/number.d.ts +1 -1
- package/types/core/schemas/builders/primitives/string.d.ts +1 -1
- package/types/core/schemas/builders/primitives/unknown.d.ts +1 -1
- package/types/core/schemas/builders/record/index.d.ts +1 -0
- package/types/core/schemas/builders/record/record.d.ts +2 -1
- package/types/core/schemas/builders/record/types.d.ts +5 -0
- package/types/core/schemas/builders/schema-utils/JsonError.d.ts +5 -0
- package/types/core/schemas/builders/schema-utils/ParseError.d.ts +5 -0
- package/types/core/schemas/builders/schema-utils/getSchemaUtils.d.ts +11 -6
- package/types/core/schemas/builders/schema-utils/index.d.ts +2 -1
- package/types/core/schemas/builders/schema-utils/stringifyValidationErrors.d.ts +2 -0
- package/types/core/schemas/utils/MaybePromise.d.ts +1 -0
- package/types/core/schemas/utils/OptionalRecord.d.ts +1 -0
- package/types/core/schemas/utils/addQuestionMarksToNullableProperties.d.ts +3 -3
- package/types/core/schemas/utils/createIdentitySchemaCreator.d.ts +2 -0
- package/types/core/schemas/utils/isPlainObject.d.ts +2 -0
- package/types/serialization/resources/index.d.ts +2 -0
- package/types/serialization/resources/organization/client/addUser.d.ts +0 -7
- package/types/serialization/resources/organization/client/create.d.ts +0 -7
- package/types/serialization/resources/organization/client/get.d.ts +0 -4
- package/types/serialization/resources/organization/client/getMyOrganizationFromScopedToken.d.ts +0 -4
- package/types/serialization/resources/organization/client/index.d.ts +1 -0
- package/types/serialization/resources/organization/client/requests/AddUserToOrgRequest.d.ts +13 -0
- package/types/serialization/resources/organization/client/requests/CreateOrganizationRequest.d.ts +13 -0
- package/types/serialization/resources/organization/client/requests/UpdateOrganizationRequest.d.ts +12 -0
- package/types/serialization/resources/organization/client/requests/index.d.ts +3 -0
- package/types/serialization/resources/organization/client/update.d.ts +0 -6
- package/types/serialization/resources/registry/client/generateRegistryTokens.d.ts +0 -10
- package/types/serialization/resources/registry/client/hasRegistryPermission.d.ts +1 -8
- package/types/serialization/resources/registry/client/index.d.ts +1 -0
- package/types/serialization/resources/registry/client/requests/CheckRegistryPermissionRequest.d.ts +13 -0
- package/types/serialization/resources/registry/client/requests/GenerateRegistryTokensRequest.d.ts +12 -0
- package/types/serialization/resources/registry/client/requests/RevokeTokenRequest.d.ts +13 -0
- package/types/serialization/resources/registry/client/requests/index.d.ts +3 -0
- package/types/serialization/resources/registry/client/revokeToken.d.ts +0 -7
- package/types/serialization/resources/user/index.d.ts +0 -1
- package/types/core/schemas/builders/identity/createIdentitySchemaCreator.d.ts +0 -2
- package/types/core/schemas/builders/identity/identity.d.ts +0 -2
- package/types/core/schemas/builders/identity/index.d.ts +0 -2
- package/types/core/schemas/builders/schema-utils/types.d.ts +0 -7
- package/types/serialization/resources/user/client/getMyOrganizations.d.ts +0 -10
- package/types/serialization/resources/user/client/getMyself.d.ts +0 -10
- package/types/serialization/resources/user/client/index.d.ts +0 -2
package/dist/node/core.js
CHANGED
|
@@ -198,7 +198,7 @@ var require_utils = __commonJS({
|
|
|
198
198
|
function isObject(val) {
|
|
199
199
|
return val !== null && typeof val === "object";
|
|
200
200
|
}
|
|
201
|
-
function
|
|
201
|
+
function isPlainObject2(val) {
|
|
202
202
|
if (kindOf(val) !== "object") {
|
|
203
203
|
return false;
|
|
204
204
|
}
|
|
@@ -251,9 +251,9 @@ var require_utils = __commonJS({
|
|
|
251
251
|
function merge() {
|
|
252
252
|
var result = {};
|
|
253
253
|
function assignValue(val, key) {
|
|
254
|
-
if (
|
|
254
|
+
if (isPlainObject2(result[key]) && isPlainObject2(val)) {
|
|
255
255
|
result[key] = merge(result[key], val);
|
|
256
|
-
} else if (
|
|
256
|
+
} else if (isPlainObject2(val)) {
|
|
257
257
|
result[key] = merge({}, val);
|
|
258
258
|
} else if (isArray(val)) {
|
|
259
259
|
result[key] = val.slice();
|
|
@@ -342,7 +342,7 @@ var require_utils = __commonJS({
|
|
|
342
342
|
isString,
|
|
343
343
|
isNumber,
|
|
344
344
|
isObject,
|
|
345
|
-
isPlainObject,
|
|
345
|
+
isPlainObject: isPlainObject2,
|
|
346
346
|
isUndefined,
|
|
347
347
|
isDate,
|
|
348
348
|
isFile,
|
|
@@ -11863,18 +11863,16 @@ module.exports = __toCommonJS(core_exports);
|
|
|
11863
11863
|
// src/core/schemas/index.ts
|
|
11864
11864
|
var schemas_exports = {};
|
|
11865
11865
|
__export(schemas_exports, {
|
|
11866
|
-
|
|
11867
|
-
|
|
11866
|
+
JsonError: () => JsonError,
|
|
11867
|
+
ParseError: () => ParseError,
|
|
11868
11868
|
any: () => any,
|
|
11869
11869
|
boolean: () => boolean,
|
|
11870
|
-
createIdentitySchemaCreator: () => createIdentitySchemaCreator,
|
|
11871
11870
|
date: () => date,
|
|
11872
11871
|
discriminant: () => discriminant,
|
|
11873
11872
|
enum_: () => enum_,
|
|
11874
11873
|
getObjectLikeUtils: () => getObjectLikeUtils,
|
|
11875
11874
|
getObjectUtils: () => getObjectUtils,
|
|
11876
11875
|
getSchemaUtils: () => getSchemaUtils,
|
|
11877
|
-
identity: () => identity,
|
|
11878
11876
|
isProperty: () => isProperty,
|
|
11879
11877
|
lazy: () => lazy,
|
|
11880
11878
|
lazyObject: () => lazyObject,
|
|
@@ -11890,26 +11888,97 @@ __export(schemas_exports, {
|
|
|
11890
11888
|
transform: () => transform,
|
|
11891
11889
|
union: () => union,
|
|
11892
11890
|
unknown: () => unknown,
|
|
11893
|
-
|
|
11891
|
+
withParsedProperties: () => withParsedProperties
|
|
11894
11892
|
});
|
|
11895
11893
|
|
|
11896
|
-
// src/core/schemas/
|
|
11897
|
-
var
|
|
11894
|
+
// src/core/schemas/Schema.ts
|
|
11895
|
+
var SchemaType = {
|
|
11896
|
+
DATE: "date",
|
|
11897
|
+
ENUM: "enum",
|
|
11898
|
+
LIST: "list",
|
|
11899
|
+
STRING_LITERAL: "stringLiteral",
|
|
11900
|
+
OBJECT: "object",
|
|
11901
|
+
ANY: "any",
|
|
11902
|
+
BOOLEAN: "boolean",
|
|
11903
|
+
NUMBER: "number",
|
|
11904
|
+
STRING: "string",
|
|
11905
|
+
UNKNOWN: "unknown",
|
|
11906
|
+
RECORD: "record",
|
|
11907
|
+
SET: "set",
|
|
11908
|
+
UNION: "union",
|
|
11909
|
+
OPTIONAL: "optional"
|
|
11910
|
+
};
|
|
11911
|
+
|
|
11912
|
+
// src/core/schemas/builders/schema-utils/stringifyValidationErrors.ts
|
|
11913
|
+
function stringifyValidationError(error) {
|
|
11914
|
+
if (error.path.length === 0) {
|
|
11915
|
+
return error.message;
|
|
11916
|
+
}
|
|
11917
|
+
return `${error.path.join(" -> ")}: ${error.message}`;
|
|
11918
|
+
}
|
|
11919
|
+
|
|
11920
|
+
// src/core/schemas/builders/schema-utils/JsonError.ts
|
|
11921
|
+
var JsonError = class extends Error {
|
|
11922
|
+
constructor(errors) {
|
|
11923
|
+
super(errors.map(stringifyValidationError).join("; "));
|
|
11924
|
+
this.errors = errors;
|
|
11925
|
+
Object.setPrototypeOf(this, JsonError.prototype);
|
|
11926
|
+
}
|
|
11927
|
+
};
|
|
11928
|
+
|
|
11929
|
+
// src/core/schemas/builders/schema-utils/ParseError.ts
|
|
11930
|
+
var ParseError = class extends Error {
|
|
11931
|
+
constructor(errors) {
|
|
11932
|
+
super(errors.map(stringifyValidationError).join("; "));
|
|
11933
|
+
this.errors = errors;
|
|
11934
|
+
Object.setPrototypeOf(this, ParseError.prototype);
|
|
11935
|
+
}
|
|
11936
|
+
};
|
|
11898
11937
|
|
|
11899
11938
|
// src/core/schemas/builders/schema-utils/getSchemaUtils.ts
|
|
11900
11939
|
function getSchemaUtils(schema) {
|
|
11901
11940
|
return {
|
|
11902
11941
|
optional: () => optional(schema),
|
|
11903
|
-
transform: (transformer) => transform(schema, transformer)
|
|
11942
|
+
transform: (transformer) => transform(schema, transformer),
|
|
11943
|
+
parseOrThrow: async (raw, opts) => {
|
|
11944
|
+
const parsed = await schema.parse(raw, opts);
|
|
11945
|
+
if (parsed.ok) {
|
|
11946
|
+
return parsed.value;
|
|
11947
|
+
}
|
|
11948
|
+
throw new ParseError(parsed.errors);
|
|
11949
|
+
},
|
|
11950
|
+
jsonOrThrow: async (parsed, opts) => {
|
|
11951
|
+
const raw = await schema.json(parsed, opts);
|
|
11952
|
+
if (raw.ok) {
|
|
11953
|
+
return raw.value;
|
|
11954
|
+
}
|
|
11955
|
+
throw new JsonError(raw.errors);
|
|
11956
|
+
}
|
|
11904
11957
|
};
|
|
11905
11958
|
}
|
|
11906
11959
|
function optional(schema) {
|
|
11907
11960
|
const baseSchema = {
|
|
11908
|
-
parse: (raw, opts) =>
|
|
11909
|
-
|
|
11961
|
+
parse: (raw, opts) => {
|
|
11962
|
+
if (raw == null) {
|
|
11963
|
+
return {
|
|
11964
|
+
ok: true,
|
|
11965
|
+
value: void 0
|
|
11966
|
+
};
|
|
11967
|
+
}
|
|
11968
|
+
return schema.parse(raw, opts);
|
|
11969
|
+
},
|
|
11970
|
+
json: (parsed, opts) => {
|
|
11971
|
+
if (parsed == null) {
|
|
11972
|
+
return {
|
|
11973
|
+
ok: true,
|
|
11974
|
+
value: null
|
|
11975
|
+
};
|
|
11976
|
+
}
|
|
11977
|
+
return schema.json(parsed, opts);
|
|
11978
|
+
},
|
|
11979
|
+
getType: () => SchemaType.OPTIONAL
|
|
11910
11980
|
};
|
|
11911
11981
|
return {
|
|
11912
|
-
...OPTIONAL_BRAND,
|
|
11913
11982
|
...baseSchema,
|
|
11914
11983
|
...getSchemaUtils(baseSchema)
|
|
11915
11984
|
};
|
|
@@ -11917,13 +11986,20 @@ function optional(schema) {
|
|
|
11917
11986
|
function transform(schema, transformer) {
|
|
11918
11987
|
const baseSchema = {
|
|
11919
11988
|
parse: async (raw, opts) => {
|
|
11920
|
-
const
|
|
11921
|
-
|
|
11989
|
+
const parsed = await schema.parse(raw, opts);
|
|
11990
|
+
if (!parsed.ok) {
|
|
11991
|
+
return parsed;
|
|
11992
|
+
}
|
|
11993
|
+
return {
|
|
11994
|
+
ok: true,
|
|
11995
|
+
value: transformer.transform(parsed.value)
|
|
11996
|
+
};
|
|
11922
11997
|
},
|
|
11923
|
-
json: async (
|
|
11924
|
-
const
|
|
11925
|
-
return schema.json(
|
|
11926
|
-
}
|
|
11998
|
+
json: async (transformed, opts) => {
|
|
11999
|
+
const parsed = await transformer.untransform(transformed);
|
|
12000
|
+
return schema.json(parsed, opts);
|
|
12001
|
+
},
|
|
12002
|
+
getType: () => schema.getType()
|
|
11927
12003
|
};
|
|
11928
12004
|
return {
|
|
11929
12005
|
...baseSchema,
|
|
@@ -11932,10 +12008,46 @@ function transform(schema, transformer) {
|
|
|
11932
12008
|
}
|
|
11933
12009
|
|
|
11934
12010
|
// src/core/schemas/builders/date/date.ts
|
|
12011
|
+
var ISO_8601_REGEX = /^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)?(\17[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
|
|
11935
12012
|
function date() {
|
|
11936
12013
|
const baseSchema = {
|
|
11937
|
-
parse: (raw) =>
|
|
11938
|
-
|
|
12014
|
+
parse: (raw) => {
|
|
12015
|
+
if (typeof raw === "string" && ISO_8601_REGEX.test(raw)) {
|
|
12016
|
+
return {
|
|
12017
|
+
ok: true,
|
|
12018
|
+
value: new Date(raw)
|
|
12019
|
+
};
|
|
12020
|
+
} else {
|
|
12021
|
+
return {
|
|
12022
|
+
ok: false,
|
|
12023
|
+
errors: [
|
|
12024
|
+
{
|
|
12025
|
+
path: [],
|
|
12026
|
+
message: "Not an ISO 8601 date string"
|
|
12027
|
+
}
|
|
12028
|
+
]
|
|
12029
|
+
};
|
|
12030
|
+
}
|
|
12031
|
+
},
|
|
12032
|
+
json: (date2) => {
|
|
12033
|
+
if (date2 instanceof Date) {
|
|
12034
|
+
return {
|
|
12035
|
+
ok: true,
|
|
12036
|
+
value: date2.toISOString()
|
|
12037
|
+
};
|
|
12038
|
+
} else {
|
|
12039
|
+
return {
|
|
12040
|
+
ok: false,
|
|
12041
|
+
errors: [
|
|
12042
|
+
{
|
|
12043
|
+
path: [],
|
|
12044
|
+
message: "Not a Date object"
|
|
12045
|
+
}
|
|
12046
|
+
]
|
|
12047
|
+
};
|
|
12048
|
+
}
|
|
12049
|
+
},
|
|
12050
|
+
getType: () => SchemaType.DATE
|
|
11939
12051
|
};
|
|
11940
12052
|
return {
|
|
11941
12053
|
...baseSchema,
|
|
@@ -11943,26 +12055,43 @@ function date() {
|
|
|
11943
12055
|
};
|
|
11944
12056
|
}
|
|
11945
12057
|
|
|
11946
|
-
// src/core/schemas/
|
|
11947
|
-
function
|
|
11948
|
-
|
|
11949
|
-
|
|
11950
|
-
|
|
11951
|
-
|
|
11952
|
-
|
|
11953
|
-
|
|
11954
|
-
|
|
12058
|
+
// src/core/schemas/utils/createIdentitySchemaCreator.ts
|
|
12059
|
+
function createIdentitySchemaCreator(schemaType, validate) {
|
|
12060
|
+
return () => {
|
|
12061
|
+
const baseSchema = {
|
|
12062
|
+
parse: validate,
|
|
12063
|
+
json: validate,
|
|
12064
|
+
getType: () => schemaType
|
|
12065
|
+
};
|
|
12066
|
+
return {
|
|
12067
|
+
...baseSchema,
|
|
12068
|
+
...getSchemaUtils(baseSchema)
|
|
12069
|
+
};
|
|
11955
12070
|
};
|
|
11956
12071
|
}
|
|
11957
12072
|
|
|
11958
|
-
// src/core/schemas/builders/identity/createIdentitySchemaCreator.ts
|
|
11959
|
-
function createIdentitySchemaCreator() {
|
|
11960
|
-
return () => identity();
|
|
11961
|
-
}
|
|
11962
|
-
|
|
11963
12073
|
// src/core/schemas/builders/enum/enum.ts
|
|
11964
|
-
function enum_(
|
|
11965
|
-
|
|
12074
|
+
function enum_(values) {
|
|
12075
|
+
const validValues = new Set(values);
|
|
12076
|
+
const schemaCreator = createIdentitySchemaCreator(SchemaType.ENUM, (value, { allowUnknownKeys = false } = {}) => {
|
|
12077
|
+
if (typeof value === "string" && (validValues.has(value) || allowUnknownKeys)) {
|
|
12078
|
+
return {
|
|
12079
|
+
ok: true,
|
|
12080
|
+
value
|
|
12081
|
+
};
|
|
12082
|
+
} else {
|
|
12083
|
+
return {
|
|
12084
|
+
ok: false,
|
|
12085
|
+
errors: [
|
|
12086
|
+
{
|
|
12087
|
+
path: [],
|
|
12088
|
+
message: "Not one of the allowed values"
|
|
12089
|
+
}
|
|
12090
|
+
]
|
|
12091
|
+
};
|
|
12092
|
+
}
|
|
12093
|
+
});
|
|
12094
|
+
return schemaCreator();
|
|
11966
12095
|
}
|
|
11967
12096
|
|
|
11968
12097
|
// src/core/schemas/builders/lazy/lazy.ts
|
|
@@ -11975,8 +12104,9 @@ function lazy(getter) {
|
|
|
11975
12104
|
}
|
|
11976
12105
|
function constructLazyBaseSchema(getter) {
|
|
11977
12106
|
return {
|
|
11978
|
-
parse: async (raw) => (await getMemoizedSchema(getter)).parse(raw),
|
|
11979
|
-
json: async (parsed) => (await getMemoizedSchema(getter)).json(parsed)
|
|
12107
|
+
parse: async (raw, opts) => (await getMemoizedSchema(getter)).parse(raw, opts),
|
|
12108
|
+
json: async (parsed, opts) => (await getMemoizedSchema(getter)).json(parsed, opts),
|
|
12109
|
+
getType: async () => (await getMemoizedSchema(getter)).getType()
|
|
11980
12110
|
};
|
|
11981
12111
|
}
|
|
11982
12112
|
async function getMemoizedSchema(getter) {
|
|
@@ -12003,6 +12133,22 @@ function filterObject(obj, keysToInclude) {
|
|
|
12003
12133
|
}, {});
|
|
12004
12134
|
}
|
|
12005
12135
|
|
|
12136
|
+
// src/core/schemas/utils/isPlainObject.ts
|
|
12137
|
+
var NOT_AN_OBJECT_ERROR_MESSAGE = "Not an object";
|
|
12138
|
+
function isPlainObject(value) {
|
|
12139
|
+
if (typeof value !== "object" || value === null) {
|
|
12140
|
+
return false;
|
|
12141
|
+
}
|
|
12142
|
+
if (Object.getPrototypeOf(value) === null) {
|
|
12143
|
+
return true;
|
|
12144
|
+
}
|
|
12145
|
+
let proto = value;
|
|
12146
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
12147
|
+
proto = Object.getPrototypeOf(proto);
|
|
12148
|
+
}
|
|
12149
|
+
return Object.getPrototypeOf(value) === proto;
|
|
12150
|
+
}
|
|
12151
|
+
|
|
12006
12152
|
// src/core/schemas/utils/keys.ts
|
|
12007
12153
|
function keys(object2) {
|
|
12008
12154
|
return Object.keys(object2);
|
|
@@ -12021,47 +12167,56 @@ function partition(items, predicate) {
|
|
|
12021
12167
|
return [trueItems, falseItems];
|
|
12022
12168
|
}
|
|
12023
12169
|
|
|
12024
|
-
// src/core/schemas/builders/object-like/types.ts
|
|
12025
|
-
var OBJECT_LIKE_BRAND = void 0;
|
|
12026
|
-
|
|
12027
12170
|
// src/core/schemas/builders/object-like/getObjectLikeUtils.ts
|
|
12028
12171
|
function getObjectLikeUtils(schema) {
|
|
12029
12172
|
return {
|
|
12030
|
-
|
|
12173
|
+
withParsedProperties: (properties) => withParsedProperties(schema, properties)
|
|
12031
12174
|
};
|
|
12032
12175
|
}
|
|
12033
|
-
function
|
|
12176
|
+
function withParsedProperties(objectLike, properties) {
|
|
12034
12177
|
const objectSchema = {
|
|
12035
|
-
...OBJECT_LIKE_BRAND,
|
|
12036
12178
|
parse: async (raw, opts) => {
|
|
12037
12179
|
const parsedObject = await objectLike.parse(raw, opts);
|
|
12180
|
+
if (!parsedObject.ok) {
|
|
12181
|
+
return parsedObject;
|
|
12182
|
+
}
|
|
12038
12183
|
const additionalProperties = Object.entries(properties).reduce(
|
|
12039
12184
|
(processed, [key, value]) => {
|
|
12040
12185
|
return {
|
|
12041
12186
|
...processed,
|
|
12042
|
-
[key]: typeof value === "function" ? value(parsedObject) : value
|
|
12187
|
+
[key]: typeof value === "function" ? value(parsedObject.value) : value
|
|
12043
12188
|
};
|
|
12044
12189
|
},
|
|
12045
12190
|
{}
|
|
12046
12191
|
);
|
|
12047
12192
|
return {
|
|
12048
|
-
|
|
12049
|
-
|
|
12193
|
+
ok: true,
|
|
12194
|
+
value: {
|
|
12195
|
+
...parsedObject.value,
|
|
12196
|
+
...additionalProperties
|
|
12197
|
+
}
|
|
12050
12198
|
};
|
|
12051
12199
|
},
|
|
12052
12200
|
json: (parsed, opts) => {
|
|
12201
|
+
if (!isPlainObject(parsed)) {
|
|
12202
|
+
return {
|
|
12203
|
+
ok: false,
|
|
12204
|
+
errors: [
|
|
12205
|
+
{
|
|
12206
|
+
path: [],
|
|
12207
|
+
message: NOT_AN_OBJECT_ERROR_MESSAGE
|
|
12208
|
+
}
|
|
12209
|
+
]
|
|
12210
|
+
};
|
|
12211
|
+
}
|
|
12053
12212
|
const addedPropertyKeys = new Set(Object.keys(properties));
|
|
12054
|
-
const parsedWithoutAddedProperties =
|
|
12055
|
-
|
|
12056
|
-
|
|
12057
|
-
filtered[key] = value;
|
|
12058
|
-
}
|
|
12059
|
-
return filtered;
|
|
12060
|
-
},
|
|
12061
|
-
{}
|
|
12213
|
+
const parsedWithoutAddedProperties = filterObject(
|
|
12214
|
+
parsed,
|
|
12215
|
+
Object.keys(parsed).filter((key) => !addedPropertyKeys.has(key))
|
|
12062
12216
|
);
|
|
12063
12217
|
return objectLike.json(parsedWithoutAddedProperties, opts);
|
|
12064
|
-
}
|
|
12218
|
+
},
|
|
12219
|
+
getType: () => objectLike.getType()
|
|
12065
12220
|
};
|
|
12066
12221
|
return {
|
|
12067
12222
|
...objectSchema,
|
|
@@ -12085,54 +12240,76 @@ function isProperty(maybeProperty) {
|
|
|
12085
12240
|
// src/core/schemas/builders/object/object.ts
|
|
12086
12241
|
function object(schemas) {
|
|
12087
12242
|
const baseSchema = {
|
|
12088
|
-
...OBJECT_LIKE_BRAND,
|
|
12089
12243
|
_getRawProperties: () => Promise.resolve(
|
|
12090
12244
|
Object.entries(schemas).map(
|
|
12091
12245
|
([parsedKey, propertySchema]) => isProperty(propertySchema) ? propertySchema.rawKey : parsedKey
|
|
12092
12246
|
)
|
|
12093
12247
|
),
|
|
12094
12248
|
_getParsedProperties: () => Promise.resolve(keys(schemas)),
|
|
12095
|
-
parse: async (raw,
|
|
12249
|
+
parse: async (raw, opts) => {
|
|
12096
12250
|
const rawKeyToProperty = {};
|
|
12251
|
+
const requiredKeys = [];
|
|
12097
12252
|
for (const [parsedKey, schemaOrObjectProperty] of entries(schemas)) {
|
|
12098
12253
|
const rawKey = isProperty(schemaOrObjectProperty) ? schemaOrObjectProperty.rawKey : parsedKey;
|
|
12254
|
+
const valueSchema = isProperty(schemaOrObjectProperty) ? schemaOrObjectProperty.valueSchema : schemaOrObjectProperty;
|
|
12099
12255
|
const property2 = {
|
|
12100
12256
|
rawKey,
|
|
12101
12257
|
parsedKey,
|
|
12102
|
-
valueSchema
|
|
12258
|
+
valueSchema
|
|
12103
12259
|
};
|
|
12104
12260
|
rawKeyToProperty[rawKey] = property2;
|
|
12105
|
-
|
|
12106
|
-
|
|
12107
|
-
for (const [rawKey, rawPropertyValue] of Object.entries(raw)) {
|
|
12108
|
-
const property2 = rawKeyToProperty[rawKey];
|
|
12109
|
-
if (property2 != null) {
|
|
12110
|
-
const value = await property2.valueSchema.parse(rawPropertyValue);
|
|
12111
|
-
parsed[property2.parsedKey] = value;
|
|
12112
|
-
} else if (!skipUnknownKeysOnParse && rawPropertyValue != null) {
|
|
12113
|
-
parsed[rawKey] = rawPropertyValue;
|
|
12261
|
+
if (await valueSchema.getType() !== "optional") {
|
|
12262
|
+
requiredKeys.push(rawKey);
|
|
12114
12263
|
}
|
|
12115
12264
|
}
|
|
12116
|
-
return
|
|
12117
|
-
|
|
12118
|
-
|
|
12119
|
-
|
|
12120
|
-
|
|
12121
|
-
|
|
12122
|
-
|
|
12123
|
-
if (isProperty(schemaOrObjectProperty)) {
|
|
12124
|
-
const value = await schemaOrObjectProperty.valueSchema.json(parsedPropertyValue);
|
|
12125
|
-
raw[schemaOrObjectProperty.rawKey] = value;
|
|
12126
|
-
} else {
|
|
12127
|
-
const value = await schemaOrObjectProperty.json(parsedPropertyValue);
|
|
12128
|
-
raw[parsedKey] = value;
|
|
12265
|
+
return validateAndTransformObject({
|
|
12266
|
+
value: raw,
|
|
12267
|
+
requiredKeys,
|
|
12268
|
+
getProperty: (rawKey) => {
|
|
12269
|
+
const property2 = rawKeyToProperty[rawKey];
|
|
12270
|
+
if (property2 == null) {
|
|
12271
|
+
return void 0;
|
|
12129
12272
|
}
|
|
12130
|
-
|
|
12131
|
-
|
|
12273
|
+
return {
|
|
12274
|
+
transformedKey: property2.parsedKey,
|
|
12275
|
+
transform: (propertyValue) => property2.valueSchema.parse(propertyValue, opts)
|
|
12276
|
+
};
|
|
12277
|
+
},
|
|
12278
|
+
allowUnknownKeys: (opts == null ? void 0 : opts.allowUnknownKeys) ?? false
|
|
12279
|
+
});
|
|
12280
|
+
},
|
|
12281
|
+
json: async (parsed, opts) => {
|
|
12282
|
+
const requiredKeys = [];
|
|
12283
|
+
for (const [parsedKey, schemaOrObjectProperty] of entries(schemas)) {
|
|
12284
|
+
const valueSchema = isProperty(schemaOrObjectProperty) ? schemaOrObjectProperty.valueSchema : schemaOrObjectProperty;
|
|
12285
|
+
if (await valueSchema.getType() !== "optional") {
|
|
12286
|
+
requiredKeys.push(parsedKey);
|
|
12132
12287
|
}
|
|
12133
12288
|
}
|
|
12134
|
-
return
|
|
12135
|
-
|
|
12289
|
+
return validateAndTransformObject({
|
|
12290
|
+
value: parsed,
|
|
12291
|
+
requiredKeys,
|
|
12292
|
+
getProperty: (parsedKey) => {
|
|
12293
|
+
const property2 = schemas[parsedKey];
|
|
12294
|
+
if (property2 == null) {
|
|
12295
|
+
return void 0;
|
|
12296
|
+
}
|
|
12297
|
+
if (isProperty(property2)) {
|
|
12298
|
+
return {
|
|
12299
|
+
transformedKey: property2.rawKey,
|
|
12300
|
+
transform: (propertyValue) => property2.valueSchema.json(propertyValue, opts)
|
|
12301
|
+
};
|
|
12302
|
+
} else {
|
|
12303
|
+
return {
|
|
12304
|
+
transformedKey: parsedKey,
|
|
12305
|
+
transform: (propertyValue) => property2.json(propertyValue, opts)
|
|
12306
|
+
};
|
|
12307
|
+
}
|
|
12308
|
+
},
|
|
12309
|
+
allowUnknownKeys: (opts == null ? void 0 : opts.allowUnknownKeys) ?? false
|
|
12310
|
+
});
|
|
12311
|
+
},
|
|
12312
|
+
getType: () => SchemaType.OBJECT
|
|
12136
12313
|
};
|
|
12137
12314
|
return {
|
|
12138
12315
|
...baseSchema,
|
|
@@ -12141,11 +12318,72 @@ function object(schemas) {
|
|
|
12141
12318
|
...getObjectUtils(baseSchema)
|
|
12142
12319
|
};
|
|
12143
12320
|
}
|
|
12321
|
+
async function validateAndTransformObject({
|
|
12322
|
+
value,
|
|
12323
|
+
requiredKeys,
|
|
12324
|
+
getProperty,
|
|
12325
|
+
allowUnknownKeys
|
|
12326
|
+
}) {
|
|
12327
|
+
if (!isPlainObject(value)) {
|
|
12328
|
+
return {
|
|
12329
|
+
ok: false,
|
|
12330
|
+
errors: [
|
|
12331
|
+
{
|
|
12332
|
+
path: [],
|
|
12333
|
+
message: NOT_AN_OBJECT_ERROR_MESSAGE
|
|
12334
|
+
}
|
|
12335
|
+
]
|
|
12336
|
+
};
|
|
12337
|
+
}
|
|
12338
|
+
const missingRequiredKeys = new Set(requiredKeys);
|
|
12339
|
+
const errors = [];
|
|
12340
|
+
const transformed = {};
|
|
12341
|
+
for (const [preTransformedKey, preTransformedItemValue] of Object.entries(value)) {
|
|
12342
|
+
const property2 = getProperty(preTransformedKey);
|
|
12343
|
+
if (property2 != null) {
|
|
12344
|
+
missingRequiredKeys.delete(preTransformedKey);
|
|
12345
|
+
const value2 = await property2.transform(preTransformedItemValue);
|
|
12346
|
+
if (value2.ok) {
|
|
12347
|
+
transformed[property2.transformedKey] = value2.value;
|
|
12348
|
+
} else {
|
|
12349
|
+
errors.push(
|
|
12350
|
+
...value2.errors.map((error) => ({
|
|
12351
|
+
path: [preTransformedKey, ...error.path],
|
|
12352
|
+
message: error.message
|
|
12353
|
+
}))
|
|
12354
|
+
);
|
|
12355
|
+
}
|
|
12356
|
+
} else if (allowUnknownKeys) {
|
|
12357
|
+
transformed[preTransformedKey] = preTransformedItemValue;
|
|
12358
|
+
} else {
|
|
12359
|
+
errors.push({
|
|
12360
|
+
path: [preTransformedKey],
|
|
12361
|
+
message: `Unrecognized key "${preTransformedKey}"`
|
|
12362
|
+
});
|
|
12363
|
+
}
|
|
12364
|
+
}
|
|
12365
|
+
errors.push(
|
|
12366
|
+
...requiredKeys.filter((key) => missingRequiredKeys.has(key)).map((key) => ({
|
|
12367
|
+
path: [],
|
|
12368
|
+
message: `Missing required key "${key}"`
|
|
12369
|
+
}))
|
|
12370
|
+
);
|
|
12371
|
+
if (errors.length === 0) {
|
|
12372
|
+
return {
|
|
12373
|
+
ok: true,
|
|
12374
|
+
value: transformed
|
|
12375
|
+
};
|
|
12376
|
+
} else {
|
|
12377
|
+
return {
|
|
12378
|
+
ok: false,
|
|
12379
|
+
errors
|
|
12380
|
+
};
|
|
12381
|
+
}
|
|
12382
|
+
}
|
|
12144
12383
|
function getObjectUtils(schema) {
|
|
12145
12384
|
return {
|
|
12146
12385
|
extend: (extension) => {
|
|
12147
12386
|
const baseSchema = {
|
|
12148
|
-
...OBJECT_LIKE_BRAND,
|
|
12149
12387
|
_getParsedProperties: async () => [
|
|
12150
12388
|
...await schema._getParsedProperties(),
|
|
12151
12389
|
...await extension._getParsedProperties()
|
|
@@ -12155,27 +12393,22 @@ function getObjectUtils(schema) {
|
|
|
12155
12393
|
...await extension._getRawProperties()
|
|
12156
12394
|
],
|
|
12157
12395
|
parse: async (raw, opts) => {
|
|
12158
|
-
|
|
12159
|
-
|
|
12160
|
-
|
|
12161
|
-
(
|
|
12162
|
-
|
|
12163
|
-
|
|
12164
|
-
...await schema.parse(filterObject(raw, otherProperties), opts),
|
|
12165
|
-
...await extension.parse(filterObject(raw, extensionProperties), opts)
|
|
12166
|
-
};
|
|
12396
|
+
return validateAndTransformExtendedObject({
|
|
12397
|
+
extensionKeys: await extension._getRawProperties(),
|
|
12398
|
+
value: raw,
|
|
12399
|
+
transformBase: (rawBase) => schema.parse(rawBase, opts),
|
|
12400
|
+
transformExtension: (rawExtension) => extension.parse(rawExtension, opts)
|
|
12401
|
+
});
|
|
12167
12402
|
},
|
|
12168
12403
|
json: async (parsed, opts) => {
|
|
12169
|
-
|
|
12170
|
-
|
|
12171
|
-
|
|
12172
|
-
(
|
|
12173
|
-
|
|
12174
|
-
|
|
12175
|
-
|
|
12176
|
-
|
|
12177
|
-
};
|
|
12178
|
-
}
|
|
12404
|
+
return validateAndTransformExtendedObject({
|
|
12405
|
+
extensionKeys: await extension._getParsedProperties(),
|
|
12406
|
+
value: parsed,
|
|
12407
|
+
transformBase: (parsedBase) => schema.json(parsedBase, opts),
|
|
12408
|
+
transformExtension: (parsedExtension) => extension.json(parsedExtension, opts)
|
|
12409
|
+
});
|
|
12410
|
+
},
|
|
12411
|
+
getType: () => SchemaType.OBJECT
|
|
12179
12412
|
};
|
|
12180
12413
|
return {
|
|
12181
12414
|
...baseSchema,
|
|
@@ -12186,11 +12419,41 @@ function getObjectUtils(schema) {
|
|
|
12186
12419
|
}
|
|
12187
12420
|
};
|
|
12188
12421
|
}
|
|
12422
|
+
async function validateAndTransformExtendedObject({
|
|
12423
|
+
extensionKeys,
|
|
12424
|
+
value,
|
|
12425
|
+
transformBase,
|
|
12426
|
+
transformExtension
|
|
12427
|
+
}) {
|
|
12428
|
+
const extensionPropertiesSet = new Set(extensionKeys);
|
|
12429
|
+
const [extensionProperties, baseProperties] = partition(
|
|
12430
|
+
keys(value),
|
|
12431
|
+
(key) => extensionPropertiesSet.has(key)
|
|
12432
|
+
);
|
|
12433
|
+
const transformedBase = await transformBase(filterObject(value, baseProperties));
|
|
12434
|
+
const transformedExtension = await transformExtension(filterObject(value, extensionProperties));
|
|
12435
|
+
if (transformedBase.ok && transformedExtension.ok) {
|
|
12436
|
+
return {
|
|
12437
|
+
ok: true,
|
|
12438
|
+
value: {
|
|
12439
|
+
...transformedBase.value,
|
|
12440
|
+
...transformedExtension.value
|
|
12441
|
+
}
|
|
12442
|
+
};
|
|
12443
|
+
} else {
|
|
12444
|
+
return {
|
|
12445
|
+
ok: false,
|
|
12446
|
+
errors: [
|
|
12447
|
+
...transformedBase.ok ? [] : transformedBase.errors,
|
|
12448
|
+
...transformedExtension.ok ? [] : transformedExtension.errors
|
|
12449
|
+
]
|
|
12450
|
+
};
|
|
12451
|
+
}
|
|
12452
|
+
}
|
|
12189
12453
|
|
|
12190
12454
|
// src/core/schemas/builders/lazy/lazyObject.ts
|
|
12191
12455
|
function lazyObject(getter) {
|
|
12192
12456
|
const baseSchema = {
|
|
12193
|
-
...OBJECT_LIKE_BRAND,
|
|
12194
12457
|
...constructLazyBaseSchema(getter),
|
|
12195
12458
|
_getRawProperties: async () => (await getMemoizedSchema(getter))._getRawProperties(),
|
|
12196
12459
|
_getParsedProperties: async () => (await getMemoizedSchema(getter))._getParsedProperties()
|
|
@@ -12206,66 +12469,273 @@ function lazyObject(getter) {
|
|
|
12206
12469
|
// src/core/schemas/builders/list/list.ts
|
|
12207
12470
|
function list(schema) {
|
|
12208
12471
|
const baseSchema = {
|
|
12209
|
-
parse: (raw, opts) =>
|
|
12210
|
-
json: (parsed, opts) =>
|
|
12472
|
+
parse: async (raw, opts) => validateAndTransformArray(raw, (item) => schema.parse(item, opts)),
|
|
12473
|
+
json: (parsed, opts) => validateAndTransformArray(parsed, (item) => schema.json(item, opts)),
|
|
12474
|
+
getType: () => SchemaType.LIST
|
|
12211
12475
|
};
|
|
12212
12476
|
return {
|
|
12213
12477
|
...baseSchema,
|
|
12214
12478
|
...getSchemaUtils(baseSchema)
|
|
12215
12479
|
};
|
|
12216
12480
|
}
|
|
12481
|
+
async function validateAndTransformArray(value, transformItem) {
|
|
12482
|
+
if (!Array.isArray(value)) {
|
|
12483
|
+
return {
|
|
12484
|
+
ok: false,
|
|
12485
|
+
errors: [
|
|
12486
|
+
{
|
|
12487
|
+
message: "Not a list",
|
|
12488
|
+
path: []
|
|
12489
|
+
}
|
|
12490
|
+
]
|
|
12491
|
+
};
|
|
12492
|
+
}
|
|
12493
|
+
const maybeValidItems = await Promise.all(value.map((item) => transformItem(item)));
|
|
12494
|
+
return maybeValidItems.reduce(
|
|
12495
|
+
(acc, item, index) => {
|
|
12496
|
+
if (acc.ok && item.ok) {
|
|
12497
|
+
return {
|
|
12498
|
+
ok: true,
|
|
12499
|
+
value: [...acc.value, item.value]
|
|
12500
|
+
};
|
|
12501
|
+
}
|
|
12502
|
+
const errors = [];
|
|
12503
|
+
if (!acc.ok) {
|
|
12504
|
+
errors.push(...acc.errors);
|
|
12505
|
+
}
|
|
12506
|
+
if (!item.ok) {
|
|
12507
|
+
errors.push(
|
|
12508
|
+
...item.errors.map((error) => ({
|
|
12509
|
+
path: [`[${index}]`, ...error.path],
|
|
12510
|
+
message: error.message
|
|
12511
|
+
}))
|
|
12512
|
+
);
|
|
12513
|
+
}
|
|
12514
|
+
return {
|
|
12515
|
+
ok: false,
|
|
12516
|
+
errors
|
|
12517
|
+
};
|
|
12518
|
+
},
|
|
12519
|
+
{ ok: true, value: [] }
|
|
12520
|
+
);
|
|
12521
|
+
}
|
|
12217
12522
|
|
|
12218
12523
|
// src/core/schemas/builders/literals/stringLiteral.ts
|
|
12219
|
-
function stringLiteral(
|
|
12220
|
-
|
|
12524
|
+
function stringLiteral(literal) {
|
|
12525
|
+
const schemaCreator = createIdentitySchemaCreator(SchemaType.STRING_LITERAL, (value) => {
|
|
12526
|
+
if (value === literal) {
|
|
12527
|
+
return {
|
|
12528
|
+
ok: true,
|
|
12529
|
+
value: literal
|
|
12530
|
+
};
|
|
12531
|
+
} else {
|
|
12532
|
+
return {
|
|
12533
|
+
ok: false,
|
|
12534
|
+
errors: [
|
|
12535
|
+
{
|
|
12536
|
+
path: [],
|
|
12537
|
+
message: `Not equal to "${literal}"`
|
|
12538
|
+
}
|
|
12539
|
+
]
|
|
12540
|
+
};
|
|
12541
|
+
}
|
|
12542
|
+
});
|
|
12543
|
+
return schemaCreator();
|
|
12221
12544
|
}
|
|
12222
12545
|
|
|
12223
12546
|
// src/core/schemas/builders/primitives/any.ts
|
|
12224
|
-
var any = createIdentitySchemaCreator();
|
|
12547
|
+
var any = createIdentitySchemaCreator(SchemaType.ANY, (value) => ({ ok: true, value }));
|
|
12225
12548
|
|
|
12226
12549
|
// src/core/schemas/builders/primitives/boolean.ts
|
|
12227
|
-
var boolean = createIdentitySchemaCreator()
|
|
12550
|
+
var boolean = createIdentitySchemaCreator(SchemaType.BOOLEAN, (value) => {
|
|
12551
|
+
if (typeof value === "boolean") {
|
|
12552
|
+
return {
|
|
12553
|
+
ok: true,
|
|
12554
|
+
value
|
|
12555
|
+
};
|
|
12556
|
+
} else {
|
|
12557
|
+
return {
|
|
12558
|
+
ok: false,
|
|
12559
|
+
errors: [
|
|
12560
|
+
{
|
|
12561
|
+
path: [],
|
|
12562
|
+
message: "Not a boolean"
|
|
12563
|
+
}
|
|
12564
|
+
]
|
|
12565
|
+
};
|
|
12566
|
+
}
|
|
12567
|
+
});
|
|
12228
12568
|
|
|
12229
12569
|
// src/core/schemas/builders/primitives/number.ts
|
|
12230
|
-
var number = createIdentitySchemaCreator()
|
|
12570
|
+
var number = createIdentitySchemaCreator(SchemaType.NUMBER, (value) => {
|
|
12571
|
+
if (typeof value === "number") {
|
|
12572
|
+
return {
|
|
12573
|
+
ok: true,
|
|
12574
|
+
value
|
|
12575
|
+
};
|
|
12576
|
+
} else {
|
|
12577
|
+
return {
|
|
12578
|
+
ok: false,
|
|
12579
|
+
errors: [
|
|
12580
|
+
{
|
|
12581
|
+
path: [],
|
|
12582
|
+
message: "Not a number"
|
|
12583
|
+
}
|
|
12584
|
+
]
|
|
12585
|
+
};
|
|
12586
|
+
}
|
|
12587
|
+
});
|
|
12231
12588
|
|
|
12232
12589
|
// src/core/schemas/builders/primitives/string.ts
|
|
12233
|
-
var string = createIdentitySchemaCreator()
|
|
12590
|
+
var string = createIdentitySchemaCreator(SchemaType.STRING, (value) => {
|
|
12591
|
+
if (typeof value === "string") {
|
|
12592
|
+
return {
|
|
12593
|
+
ok: true,
|
|
12594
|
+
value
|
|
12595
|
+
};
|
|
12596
|
+
} else {
|
|
12597
|
+
return {
|
|
12598
|
+
ok: false,
|
|
12599
|
+
errors: [
|
|
12600
|
+
{
|
|
12601
|
+
path: [],
|
|
12602
|
+
message: "Not a string"
|
|
12603
|
+
}
|
|
12604
|
+
]
|
|
12605
|
+
};
|
|
12606
|
+
}
|
|
12607
|
+
});
|
|
12234
12608
|
|
|
12235
12609
|
// src/core/schemas/builders/primitives/unknown.ts
|
|
12236
|
-
var unknown = createIdentitySchemaCreator();
|
|
12610
|
+
var unknown = createIdentitySchemaCreator(SchemaType.UNKNOWN, (value) => ({ ok: true, value }));
|
|
12237
12611
|
|
|
12238
12612
|
// src/core/schemas/builders/record/record.ts
|
|
12239
12613
|
function record(keySchema, valueSchema) {
|
|
12240
12614
|
const baseSchema = {
|
|
12241
|
-
parse: (raw, opts) => {
|
|
12242
|
-
return
|
|
12243
|
-
|
|
12244
|
-
|
|
12245
|
-
|
|
12246
|
-
|
|
12247
|
-
}
|
|
12615
|
+
parse: async (raw, opts) => {
|
|
12616
|
+
return validateAndTransformRecord({
|
|
12617
|
+
value: raw,
|
|
12618
|
+
isKeyNumeric: await keySchema.getType() === SchemaType.NUMBER,
|
|
12619
|
+
transformKey: (key) => keySchema.parse(key, opts),
|
|
12620
|
+
transformValue: (value) => valueSchema.parse(value, opts)
|
|
12621
|
+
});
|
|
12248
12622
|
},
|
|
12249
|
-
json: (parsed, opts) => {
|
|
12250
|
-
return
|
|
12251
|
-
|
|
12252
|
-
|
|
12253
|
-
|
|
12254
|
-
|
|
12255
|
-
}
|
|
12256
|
-
}
|
|
12623
|
+
json: async (parsed, opts) => {
|
|
12624
|
+
return validateAndTransformRecord({
|
|
12625
|
+
value: parsed,
|
|
12626
|
+
isKeyNumeric: await keySchema.getType() === SchemaType.NUMBER,
|
|
12627
|
+
transformKey: (key) => keySchema.json(key, opts),
|
|
12628
|
+
transformValue: (value) => valueSchema.json(value, opts)
|
|
12629
|
+
});
|
|
12630
|
+
},
|
|
12631
|
+
getType: () => SchemaType.RECORD
|
|
12257
12632
|
};
|
|
12258
12633
|
return {
|
|
12259
12634
|
...baseSchema,
|
|
12260
12635
|
...getSchemaUtils(baseSchema)
|
|
12261
12636
|
};
|
|
12262
12637
|
}
|
|
12638
|
+
async function validateAndTransformRecord({
|
|
12639
|
+
value,
|
|
12640
|
+
isKeyNumeric,
|
|
12641
|
+
transformKey,
|
|
12642
|
+
transformValue
|
|
12643
|
+
}) {
|
|
12644
|
+
if (!isPlainObject(value)) {
|
|
12645
|
+
return {
|
|
12646
|
+
ok: false,
|
|
12647
|
+
errors: [
|
|
12648
|
+
{
|
|
12649
|
+
path: [],
|
|
12650
|
+
message: NOT_AN_OBJECT_ERROR_MESSAGE
|
|
12651
|
+
}
|
|
12652
|
+
]
|
|
12653
|
+
};
|
|
12654
|
+
}
|
|
12655
|
+
return entries(value).reduce(
|
|
12656
|
+
async (accPromise, [stringKey, value2]) => {
|
|
12657
|
+
if (value2 == null) {
|
|
12658
|
+
return accPromise;
|
|
12659
|
+
}
|
|
12660
|
+
const acc = await accPromise;
|
|
12661
|
+
let key = stringKey;
|
|
12662
|
+
if (isKeyNumeric) {
|
|
12663
|
+
const numberKey = stringKey.length > 0 ? Number(stringKey) : NaN;
|
|
12664
|
+
if (!isNaN(numberKey)) {
|
|
12665
|
+
key = numberKey;
|
|
12666
|
+
}
|
|
12667
|
+
}
|
|
12668
|
+
const transformedKey = await transformKey(key);
|
|
12669
|
+
const transformedValue = await transformValue(value2);
|
|
12670
|
+
if (acc.ok && transformedKey.ok && transformedValue.ok) {
|
|
12671
|
+
return {
|
|
12672
|
+
ok: true,
|
|
12673
|
+
value: {
|
|
12674
|
+
...acc.value,
|
|
12675
|
+
[transformedKey.value]: transformedValue.value
|
|
12676
|
+
}
|
|
12677
|
+
};
|
|
12678
|
+
}
|
|
12679
|
+
const errors = [];
|
|
12680
|
+
if (!acc.ok) {
|
|
12681
|
+
errors.push(...acc.errors);
|
|
12682
|
+
}
|
|
12683
|
+
if (!transformedKey.ok) {
|
|
12684
|
+
errors.push(
|
|
12685
|
+
...transformedKey.errors.map((error) => ({
|
|
12686
|
+
path: [`${key} (key)`, ...error.path],
|
|
12687
|
+
message: error.message
|
|
12688
|
+
}))
|
|
12689
|
+
);
|
|
12690
|
+
}
|
|
12691
|
+
if (!transformedValue.ok) {
|
|
12692
|
+
errors.push(
|
|
12693
|
+
...transformedValue.errors.map((error) => ({
|
|
12694
|
+
path: [stringKey, ...error.path],
|
|
12695
|
+
message: error.message
|
|
12696
|
+
}))
|
|
12697
|
+
);
|
|
12698
|
+
}
|
|
12699
|
+
return {
|
|
12700
|
+
ok: false,
|
|
12701
|
+
errors
|
|
12702
|
+
};
|
|
12703
|
+
},
|
|
12704
|
+
Promise.resolve({ ok: true, value: {} })
|
|
12705
|
+
);
|
|
12706
|
+
}
|
|
12263
12707
|
|
|
12264
12708
|
// src/core/schemas/builders/set/set.ts
|
|
12265
12709
|
function set(schema) {
|
|
12710
|
+
const listSchema = list(schema);
|
|
12266
12711
|
const baseSchema = {
|
|
12267
|
-
parse: async (raw, opts) =>
|
|
12268
|
-
|
|
12712
|
+
parse: async (raw, opts) => {
|
|
12713
|
+
const parsedList = await listSchema.parse(raw, opts);
|
|
12714
|
+
if (parsedList.ok) {
|
|
12715
|
+
return {
|
|
12716
|
+
ok: true,
|
|
12717
|
+
value: new Set(parsedList.value)
|
|
12718
|
+
};
|
|
12719
|
+
} else {
|
|
12720
|
+
return parsedList;
|
|
12721
|
+
}
|
|
12722
|
+
},
|
|
12723
|
+
json: async (parsed, opts) => {
|
|
12724
|
+
if (!(parsed instanceof Set)) {
|
|
12725
|
+
return {
|
|
12726
|
+
ok: false,
|
|
12727
|
+
errors: [
|
|
12728
|
+
{
|
|
12729
|
+
path: [],
|
|
12730
|
+
message: "Not a Set"
|
|
12731
|
+
}
|
|
12732
|
+
]
|
|
12733
|
+
};
|
|
12734
|
+
}
|
|
12735
|
+
const jsonList = await listSchema.json([...parsed], opts);
|
|
12736
|
+
return jsonList;
|
|
12737
|
+
},
|
|
12738
|
+
getType: () => SchemaType.SET
|
|
12269
12739
|
};
|
|
12270
12740
|
return {
|
|
12271
12741
|
...baseSchema,
|
|
@@ -12285,36 +12755,31 @@ function discriminant(parsedDiscriminant, rawDiscriminant) {
|
|
|
12285
12755
|
function union(discriminant2, union2) {
|
|
12286
12756
|
const rawDiscriminant = typeof discriminant2 === "string" ? discriminant2 : discriminant2.rawDiscriminant;
|
|
12287
12757
|
const parsedDiscriminant = typeof discriminant2 === "string" ? discriminant2 : discriminant2.parsedDiscriminant;
|
|
12758
|
+
const discriminantValueSchema = enum_(keys(union2));
|
|
12288
12759
|
const baseSchema = {
|
|
12289
|
-
...OBJECT_LIKE_BRAND,
|
|
12290
12760
|
parse: async (raw, opts) => {
|
|
12291
|
-
|
|
12292
|
-
|
|
12293
|
-
|
|
12294
|
-
|
|
12295
|
-
|
|
12296
|
-
|
|
12297
|
-
|
|
12298
|
-
|
|
12299
|
-
|
|
12300
|
-
...await additionalPropertySchemas.parse(additionalProperties, opts),
|
|
12301
|
-
[parsedDiscriminant]: discriminantValue
|
|
12302
|
-
};
|
|
12761
|
+
return transformAndValidateUnion(
|
|
12762
|
+
raw,
|
|
12763
|
+
rawDiscriminant,
|
|
12764
|
+
parsedDiscriminant,
|
|
12765
|
+
(discriminantValue) => discriminantValueSchema.parse(discriminantValue, opts),
|
|
12766
|
+
(discriminantValue) => union2[discriminantValue],
|
|
12767
|
+
(opts == null ? void 0 : opts.allowUnknownKeys) ?? false,
|
|
12768
|
+
(additionalProperties, additionalPropertiesSchema) => additionalPropertiesSchema.parse(additionalProperties, opts)
|
|
12769
|
+
);
|
|
12303
12770
|
},
|
|
12304
12771
|
json: async (parsed, opts) => {
|
|
12305
|
-
|
|
12306
|
-
|
|
12307
|
-
|
|
12308
|
-
|
|
12309
|
-
|
|
12310
|
-
|
|
12311
|
-
|
|
12312
|
-
|
|
12313
|
-
|
|
12314
|
-
|
|
12315
|
-
|
|
12316
|
-
};
|
|
12317
|
-
}
|
|
12772
|
+
return transformAndValidateUnion(
|
|
12773
|
+
parsed,
|
|
12774
|
+
parsedDiscriminant,
|
|
12775
|
+
rawDiscriminant,
|
|
12776
|
+
(discriminantValue) => discriminantValueSchema.json(discriminantValue, opts),
|
|
12777
|
+
(discriminantValue) => union2[discriminantValue],
|
|
12778
|
+
(opts == null ? void 0 : opts.allowUnknownKeys) ?? false,
|
|
12779
|
+
(additionalProperties, additionalPropertiesSchema) => additionalPropertiesSchema.json(additionalProperties, opts)
|
|
12780
|
+
);
|
|
12781
|
+
},
|
|
12782
|
+
getType: () => SchemaType.UNION
|
|
12318
12783
|
};
|
|
12319
12784
|
return {
|
|
12320
12785
|
...baseSchema,
|
|
@@ -12322,12 +12787,83 @@ function union(discriminant2, union2) {
|
|
|
12322
12787
|
...getObjectLikeUtils(baseSchema)
|
|
12323
12788
|
};
|
|
12324
12789
|
}
|
|
12790
|
+
async function transformAndValidateUnion(value, discriminant2, transformedDiscriminant, transformDiscriminantValue, getAdditionalPropertiesSchema, allowUnknownKeys, transformAdditionalProperties) {
|
|
12791
|
+
if (!isPlainObject(value)) {
|
|
12792
|
+
return {
|
|
12793
|
+
ok: false,
|
|
12794
|
+
errors: [
|
|
12795
|
+
{
|
|
12796
|
+
path: [],
|
|
12797
|
+
message: NOT_AN_OBJECT_ERROR_MESSAGE
|
|
12798
|
+
}
|
|
12799
|
+
]
|
|
12800
|
+
};
|
|
12801
|
+
}
|
|
12802
|
+
const { [discriminant2]: discriminantValue, ...additionalProperties } = value;
|
|
12803
|
+
if (discriminantValue == null) {
|
|
12804
|
+
return {
|
|
12805
|
+
ok: false,
|
|
12806
|
+
errors: [
|
|
12807
|
+
{
|
|
12808
|
+
path: [],
|
|
12809
|
+
message: `Missing discriminant ("${discriminant2}")`
|
|
12810
|
+
}
|
|
12811
|
+
]
|
|
12812
|
+
};
|
|
12813
|
+
}
|
|
12814
|
+
const transformedDiscriminantValue = await transformDiscriminantValue(discriminantValue);
|
|
12815
|
+
if (!transformedDiscriminantValue.ok) {
|
|
12816
|
+
return {
|
|
12817
|
+
ok: false,
|
|
12818
|
+
errors: transformedDiscriminantValue.errors.map((error) => ({
|
|
12819
|
+
path: [discriminant2, ...error.path],
|
|
12820
|
+
message: error.message
|
|
12821
|
+
}))
|
|
12822
|
+
};
|
|
12823
|
+
}
|
|
12824
|
+
const additionalPropertiesSchema = getAdditionalPropertiesSchema(transformedDiscriminantValue.value);
|
|
12825
|
+
if (additionalPropertiesSchema == null) {
|
|
12826
|
+
if (allowUnknownKeys) {
|
|
12827
|
+
return {
|
|
12828
|
+
ok: true,
|
|
12829
|
+
value: {
|
|
12830
|
+
[transformedDiscriminant]: transformedDiscriminantValue.value,
|
|
12831
|
+
...additionalProperties
|
|
12832
|
+
}
|
|
12833
|
+
};
|
|
12834
|
+
} else {
|
|
12835
|
+
return {
|
|
12836
|
+
ok: false,
|
|
12837
|
+
errors: [
|
|
12838
|
+
{
|
|
12839
|
+
path: [discriminant2],
|
|
12840
|
+
message: "Unrecognized discriminant value"
|
|
12841
|
+
}
|
|
12842
|
+
]
|
|
12843
|
+
};
|
|
12844
|
+
}
|
|
12845
|
+
}
|
|
12846
|
+
const transformedAdditionalProperties = await transformAdditionalProperties(
|
|
12847
|
+
additionalProperties,
|
|
12848
|
+
additionalPropertiesSchema
|
|
12849
|
+
);
|
|
12850
|
+
if (!transformedAdditionalProperties.ok) {
|
|
12851
|
+
return transformedAdditionalProperties;
|
|
12852
|
+
}
|
|
12853
|
+
return {
|
|
12854
|
+
ok: true,
|
|
12855
|
+
value: {
|
|
12856
|
+
[transformedDiscriminant]: discriminantValue,
|
|
12857
|
+
...transformedAdditionalProperties.value
|
|
12858
|
+
}
|
|
12859
|
+
};
|
|
12860
|
+
}
|
|
12325
12861
|
|
|
12326
12862
|
// src/core/auth/BasicAuth.ts
|
|
12327
12863
|
var import_basic_auth = __toESM(require_basic_auth());
|
|
12328
12864
|
|
|
12329
|
-
// .yarn/cache/js-base64-npm-3.7.
|
|
12330
|
-
var version = "3.7.
|
|
12865
|
+
// .yarn/cache/js-base64-npm-3.7.5-81a9ad2ffd-67a78c8b1c.zip/node_modules/js-base64/base64.mjs
|
|
12866
|
+
var version = "3.7.5";
|
|
12331
12867
|
var VERSION = version;
|
|
12332
12868
|
var _hasatob = typeof atob === "function";
|
|
12333
12869
|
var _hasbtoa = typeof btoa === "function";
|
|
@@ -12343,7 +12879,7 @@ var b64tab = ((a) => {
|
|
|
12343
12879
|
})(b64chs);
|
|
12344
12880
|
var b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
|
|
12345
12881
|
var _fromCC = String.fromCharCode.bind(String);
|
|
12346
|
-
var _U8Afrom = typeof Uint8Array.from === "function" ? Uint8Array.from.bind(Uint8Array) : (it
|
|
12882
|
+
var _U8Afrom = typeof Uint8Array.from === "function" ? Uint8Array.from.bind(Uint8Array) : (it) => new Uint8Array(Array.prototype.slice.call(it, 0));
|
|
12347
12883
|
var _mkUriSafe = (src) => src.replace(/=/g, "").replace(/[+\/]/g, (m0) => m0 == "+" ? "-" : "_");
|
|
12348
12884
|
var _tidyB64 = (s) => s.replace(/[^A-Za-z0-9\+\/]/g, "");
|
|
12349
12885
|
var btoaPolyfill = (bin) => {
|
|
@@ -12407,7 +12943,7 @@ var atobPolyfill = (asc) => {
|
|
|
12407
12943
|
return bin;
|
|
12408
12944
|
};
|
|
12409
12945
|
var _atob = _hasatob ? (asc) => atob(_tidyB64(asc)) : _hasBuffer ? (asc) => Buffer.from(asc, "base64").toString("binary") : atobPolyfill;
|
|
12410
|
-
var _toUint8Array = _hasBuffer ? (a) => _U8Afrom(Buffer.from(a, "base64")) : (a) => _U8Afrom(_atob(a)
|
|
12946
|
+
var _toUint8Array = _hasBuffer ? (a) => _U8Afrom(Buffer.from(a, "base64")) : (a) => _U8Afrom(_atob(a).split("").map((c) => c.charCodeAt(0)));
|
|
12411
12947
|
var toUint8Array = (a) => _toUint8Array(_unURI(a));
|
|
12412
12948
|
var _decode = _hasBuffer ? (a) => Buffer.from(a, "base64").toString("utf8") : _TD ? (a) => _TD.decode(_toUint8Array(a)) : (a) => btou(_atob(a));
|
|
12413
12949
|
var _unURI = (a) => _tidyB64(a.replace(/[-_]/g, (m0) => m0 == "-" ? "+" : "/"));
|
|
@@ -12544,7 +13080,7 @@ var fetcher = async (args) => {
|
|
|
12544
13080
|
transitional: {
|
|
12545
13081
|
clarifyTimeoutError: true
|
|
12546
13082
|
},
|
|
12547
|
-
withCredentials:
|
|
13083
|
+
withCredentials: args.withCredentials
|
|
12548
13084
|
});
|
|
12549
13085
|
let body;
|
|
12550
13086
|
if (response.data != null && response.data.length > 0) {
|
|
@@ -12572,7 +13108,6 @@ var fetcher = async (args) => {
|
|
|
12572
13108
|
error: {
|
|
12573
13109
|
reason: "status-code",
|
|
12574
13110
|
statusCode: response.status,
|
|
12575
|
-
rawBody: response.data,
|
|
12576
13111
|
body
|
|
12577
13112
|
}
|
|
12578
13113
|
};
|