@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/browser/cjs/core.js
CHANGED
|
@@ -2078,7 +2078,7 @@ var require_utils = __commonJS({
|
|
|
2078
2078
|
function isObject(val) {
|
|
2079
2079
|
return val !== null && typeof val === "object";
|
|
2080
2080
|
}
|
|
2081
|
-
function
|
|
2081
|
+
function isPlainObject2(val) {
|
|
2082
2082
|
if (kindOf(val) !== "object") {
|
|
2083
2083
|
return false;
|
|
2084
2084
|
}
|
|
@@ -2131,9 +2131,9 @@ var require_utils = __commonJS({
|
|
|
2131
2131
|
function merge() {
|
|
2132
2132
|
var result = {};
|
|
2133
2133
|
function assignValue(val, key) {
|
|
2134
|
-
if (
|
|
2134
|
+
if (isPlainObject2(result[key]) && isPlainObject2(val)) {
|
|
2135
2135
|
result[key] = merge(result[key], val);
|
|
2136
|
-
} else if (
|
|
2136
|
+
} else if (isPlainObject2(val)) {
|
|
2137
2137
|
result[key] = merge({}, val);
|
|
2138
2138
|
} else if (isArray(val)) {
|
|
2139
2139
|
result[key] = val.slice();
|
|
@@ -2222,7 +2222,7 @@ var require_utils = __commonJS({
|
|
|
2222
2222
|
isString,
|
|
2223
2223
|
isNumber,
|
|
2224
2224
|
isObject,
|
|
2225
|
-
isPlainObject,
|
|
2225
|
+
isPlainObject: isPlainObject2,
|
|
2226
2226
|
isUndefined,
|
|
2227
2227
|
isDate,
|
|
2228
2228
|
isFile,
|
|
@@ -3519,18 +3519,16 @@ module.exports = __toCommonJS(core_exports);
|
|
|
3519
3519
|
// src/core/schemas/index.ts
|
|
3520
3520
|
var schemas_exports = {};
|
|
3521
3521
|
__export(schemas_exports, {
|
|
3522
|
-
|
|
3523
|
-
|
|
3522
|
+
JsonError: () => JsonError,
|
|
3523
|
+
ParseError: () => ParseError,
|
|
3524
3524
|
any: () => any,
|
|
3525
3525
|
boolean: () => boolean,
|
|
3526
|
-
createIdentitySchemaCreator: () => createIdentitySchemaCreator,
|
|
3527
3526
|
date: () => date,
|
|
3528
3527
|
discriminant: () => discriminant,
|
|
3529
3528
|
enum_: () => enum_,
|
|
3530
3529
|
getObjectLikeUtils: () => getObjectLikeUtils,
|
|
3531
3530
|
getObjectUtils: () => getObjectUtils,
|
|
3532
3531
|
getSchemaUtils: () => getSchemaUtils,
|
|
3533
|
-
identity: () => identity,
|
|
3534
3532
|
isProperty: () => isProperty,
|
|
3535
3533
|
lazy: () => lazy,
|
|
3536
3534
|
lazyObject: () => lazyObject,
|
|
@@ -3546,26 +3544,97 @@ __export(schemas_exports, {
|
|
|
3546
3544
|
transform: () => transform,
|
|
3547
3545
|
union: () => union,
|
|
3548
3546
|
unknown: () => unknown,
|
|
3549
|
-
|
|
3547
|
+
withParsedProperties: () => withParsedProperties
|
|
3550
3548
|
});
|
|
3551
3549
|
|
|
3552
|
-
// src/core/schemas/
|
|
3553
|
-
var
|
|
3550
|
+
// src/core/schemas/Schema.ts
|
|
3551
|
+
var SchemaType = {
|
|
3552
|
+
DATE: "date",
|
|
3553
|
+
ENUM: "enum",
|
|
3554
|
+
LIST: "list",
|
|
3555
|
+
STRING_LITERAL: "stringLiteral",
|
|
3556
|
+
OBJECT: "object",
|
|
3557
|
+
ANY: "any",
|
|
3558
|
+
BOOLEAN: "boolean",
|
|
3559
|
+
NUMBER: "number",
|
|
3560
|
+
STRING: "string",
|
|
3561
|
+
UNKNOWN: "unknown",
|
|
3562
|
+
RECORD: "record",
|
|
3563
|
+
SET: "set",
|
|
3564
|
+
UNION: "union",
|
|
3565
|
+
OPTIONAL: "optional"
|
|
3566
|
+
};
|
|
3567
|
+
|
|
3568
|
+
// src/core/schemas/builders/schema-utils/stringifyValidationErrors.ts
|
|
3569
|
+
function stringifyValidationError(error) {
|
|
3570
|
+
if (error.path.length === 0) {
|
|
3571
|
+
return error.message;
|
|
3572
|
+
}
|
|
3573
|
+
return `${error.path.join(" -> ")}: ${error.message}`;
|
|
3574
|
+
}
|
|
3575
|
+
|
|
3576
|
+
// src/core/schemas/builders/schema-utils/JsonError.ts
|
|
3577
|
+
var JsonError = class extends Error {
|
|
3578
|
+
constructor(errors) {
|
|
3579
|
+
super(errors.map(stringifyValidationError).join("; "));
|
|
3580
|
+
this.errors = errors;
|
|
3581
|
+
Object.setPrototypeOf(this, JsonError.prototype);
|
|
3582
|
+
}
|
|
3583
|
+
};
|
|
3584
|
+
|
|
3585
|
+
// src/core/schemas/builders/schema-utils/ParseError.ts
|
|
3586
|
+
var ParseError = class extends Error {
|
|
3587
|
+
constructor(errors) {
|
|
3588
|
+
super(errors.map(stringifyValidationError).join("; "));
|
|
3589
|
+
this.errors = errors;
|
|
3590
|
+
Object.setPrototypeOf(this, ParseError.prototype);
|
|
3591
|
+
}
|
|
3592
|
+
};
|
|
3554
3593
|
|
|
3555
3594
|
// src/core/schemas/builders/schema-utils/getSchemaUtils.ts
|
|
3556
3595
|
function getSchemaUtils(schema) {
|
|
3557
3596
|
return {
|
|
3558
3597
|
optional: () => optional(schema),
|
|
3559
|
-
transform: (transformer) => transform(schema, transformer)
|
|
3598
|
+
transform: (transformer) => transform(schema, transformer),
|
|
3599
|
+
parseOrThrow: async (raw, opts) => {
|
|
3600
|
+
const parsed = await schema.parse(raw, opts);
|
|
3601
|
+
if (parsed.ok) {
|
|
3602
|
+
return parsed.value;
|
|
3603
|
+
}
|
|
3604
|
+
throw new ParseError(parsed.errors);
|
|
3605
|
+
},
|
|
3606
|
+
jsonOrThrow: async (parsed, opts) => {
|
|
3607
|
+
const raw = await schema.json(parsed, opts);
|
|
3608
|
+
if (raw.ok) {
|
|
3609
|
+
return raw.value;
|
|
3610
|
+
}
|
|
3611
|
+
throw new JsonError(raw.errors);
|
|
3612
|
+
}
|
|
3560
3613
|
};
|
|
3561
3614
|
}
|
|
3562
3615
|
function optional(schema) {
|
|
3563
3616
|
const baseSchema = {
|
|
3564
|
-
parse: (raw, opts) =>
|
|
3565
|
-
|
|
3617
|
+
parse: (raw, opts) => {
|
|
3618
|
+
if (raw == null) {
|
|
3619
|
+
return {
|
|
3620
|
+
ok: true,
|
|
3621
|
+
value: void 0
|
|
3622
|
+
};
|
|
3623
|
+
}
|
|
3624
|
+
return schema.parse(raw, opts);
|
|
3625
|
+
},
|
|
3626
|
+
json: (parsed, opts) => {
|
|
3627
|
+
if (parsed == null) {
|
|
3628
|
+
return {
|
|
3629
|
+
ok: true,
|
|
3630
|
+
value: null
|
|
3631
|
+
};
|
|
3632
|
+
}
|
|
3633
|
+
return schema.json(parsed, opts);
|
|
3634
|
+
},
|
|
3635
|
+
getType: () => SchemaType.OPTIONAL
|
|
3566
3636
|
};
|
|
3567
3637
|
return {
|
|
3568
|
-
...OPTIONAL_BRAND,
|
|
3569
3638
|
...baseSchema,
|
|
3570
3639
|
...getSchemaUtils(baseSchema)
|
|
3571
3640
|
};
|
|
@@ -3573,13 +3642,20 @@ function optional(schema) {
|
|
|
3573
3642
|
function transform(schema, transformer) {
|
|
3574
3643
|
const baseSchema = {
|
|
3575
3644
|
parse: async (raw, opts) => {
|
|
3576
|
-
const
|
|
3577
|
-
|
|
3645
|
+
const parsed = await schema.parse(raw, opts);
|
|
3646
|
+
if (!parsed.ok) {
|
|
3647
|
+
return parsed;
|
|
3648
|
+
}
|
|
3649
|
+
return {
|
|
3650
|
+
ok: true,
|
|
3651
|
+
value: transformer.transform(parsed.value)
|
|
3652
|
+
};
|
|
3578
3653
|
},
|
|
3579
|
-
json: async (
|
|
3580
|
-
const
|
|
3581
|
-
return schema.json(
|
|
3582
|
-
}
|
|
3654
|
+
json: async (transformed, opts) => {
|
|
3655
|
+
const parsed = await transformer.untransform(transformed);
|
|
3656
|
+
return schema.json(parsed, opts);
|
|
3657
|
+
},
|
|
3658
|
+
getType: () => schema.getType()
|
|
3583
3659
|
};
|
|
3584
3660
|
return {
|
|
3585
3661
|
...baseSchema,
|
|
@@ -3588,10 +3664,46 @@ function transform(schema, transformer) {
|
|
|
3588
3664
|
}
|
|
3589
3665
|
|
|
3590
3666
|
// src/core/schemas/builders/date/date.ts
|
|
3667
|
+
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)?)?)?)?$/;
|
|
3591
3668
|
function date() {
|
|
3592
3669
|
const baseSchema = {
|
|
3593
|
-
parse: (raw) =>
|
|
3594
|
-
|
|
3670
|
+
parse: (raw) => {
|
|
3671
|
+
if (typeof raw === "string" && ISO_8601_REGEX.test(raw)) {
|
|
3672
|
+
return {
|
|
3673
|
+
ok: true,
|
|
3674
|
+
value: new Date(raw)
|
|
3675
|
+
};
|
|
3676
|
+
} else {
|
|
3677
|
+
return {
|
|
3678
|
+
ok: false,
|
|
3679
|
+
errors: [
|
|
3680
|
+
{
|
|
3681
|
+
path: [],
|
|
3682
|
+
message: "Not an ISO 8601 date string"
|
|
3683
|
+
}
|
|
3684
|
+
]
|
|
3685
|
+
};
|
|
3686
|
+
}
|
|
3687
|
+
},
|
|
3688
|
+
json: (date2) => {
|
|
3689
|
+
if (date2 instanceof Date) {
|
|
3690
|
+
return {
|
|
3691
|
+
ok: true,
|
|
3692
|
+
value: date2.toISOString()
|
|
3693
|
+
};
|
|
3694
|
+
} else {
|
|
3695
|
+
return {
|
|
3696
|
+
ok: false,
|
|
3697
|
+
errors: [
|
|
3698
|
+
{
|
|
3699
|
+
path: [],
|
|
3700
|
+
message: "Not a Date object"
|
|
3701
|
+
}
|
|
3702
|
+
]
|
|
3703
|
+
};
|
|
3704
|
+
}
|
|
3705
|
+
},
|
|
3706
|
+
getType: () => SchemaType.DATE
|
|
3595
3707
|
};
|
|
3596
3708
|
return {
|
|
3597
3709
|
...baseSchema,
|
|
@@ -3599,26 +3711,43 @@ function date() {
|
|
|
3599
3711
|
};
|
|
3600
3712
|
}
|
|
3601
3713
|
|
|
3602
|
-
// src/core/schemas/
|
|
3603
|
-
function
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3714
|
+
// src/core/schemas/utils/createIdentitySchemaCreator.ts
|
|
3715
|
+
function createIdentitySchemaCreator(schemaType, validate) {
|
|
3716
|
+
return () => {
|
|
3717
|
+
const baseSchema = {
|
|
3718
|
+
parse: validate,
|
|
3719
|
+
json: validate,
|
|
3720
|
+
getType: () => schemaType
|
|
3721
|
+
};
|
|
3722
|
+
return {
|
|
3723
|
+
...baseSchema,
|
|
3724
|
+
...getSchemaUtils(baseSchema)
|
|
3725
|
+
};
|
|
3611
3726
|
};
|
|
3612
3727
|
}
|
|
3613
3728
|
|
|
3614
|
-
// src/core/schemas/builders/identity/createIdentitySchemaCreator.ts
|
|
3615
|
-
function createIdentitySchemaCreator() {
|
|
3616
|
-
return () => identity();
|
|
3617
|
-
}
|
|
3618
|
-
|
|
3619
3729
|
// src/core/schemas/builders/enum/enum.ts
|
|
3620
|
-
function enum_(
|
|
3621
|
-
|
|
3730
|
+
function enum_(values) {
|
|
3731
|
+
const validValues = new Set(values);
|
|
3732
|
+
const schemaCreator = createIdentitySchemaCreator(SchemaType.ENUM, (value, { allowUnknownKeys = false } = {}) => {
|
|
3733
|
+
if (typeof value === "string" && (validValues.has(value) || allowUnknownKeys)) {
|
|
3734
|
+
return {
|
|
3735
|
+
ok: true,
|
|
3736
|
+
value
|
|
3737
|
+
};
|
|
3738
|
+
} else {
|
|
3739
|
+
return {
|
|
3740
|
+
ok: false,
|
|
3741
|
+
errors: [
|
|
3742
|
+
{
|
|
3743
|
+
path: [],
|
|
3744
|
+
message: "Not one of the allowed values"
|
|
3745
|
+
}
|
|
3746
|
+
]
|
|
3747
|
+
};
|
|
3748
|
+
}
|
|
3749
|
+
});
|
|
3750
|
+
return schemaCreator();
|
|
3622
3751
|
}
|
|
3623
3752
|
|
|
3624
3753
|
// src/core/schemas/builders/lazy/lazy.ts
|
|
@@ -3631,8 +3760,9 @@ function lazy(getter) {
|
|
|
3631
3760
|
}
|
|
3632
3761
|
function constructLazyBaseSchema(getter) {
|
|
3633
3762
|
return {
|
|
3634
|
-
parse: async (raw) => (await getMemoizedSchema(getter)).parse(raw),
|
|
3635
|
-
json: async (parsed) => (await getMemoizedSchema(getter)).json(parsed)
|
|
3763
|
+
parse: async (raw, opts) => (await getMemoizedSchema(getter)).parse(raw, opts),
|
|
3764
|
+
json: async (parsed, opts) => (await getMemoizedSchema(getter)).json(parsed, opts),
|
|
3765
|
+
getType: async () => (await getMemoizedSchema(getter)).getType()
|
|
3636
3766
|
};
|
|
3637
3767
|
}
|
|
3638
3768
|
async function getMemoizedSchema(getter) {
|
|
@@ -3659,6 +3789,22 @@ function filterObject(obj, keysToInclude) {
|
|
|
3659
3789
|
}, {});
|
|
3660
3790
|
}
|
|
3661
3791
|
|
|
3792
|
+
// src/core/schemas/utils/isPlainObject.ts
|
|
3793
|
+
var NOT_AN_OBJECT_ERROR_MESSAGE = "Not an object";
|
|
3794
|
+
function isPlainObject(value) {
|
|
3795
|
+
if (typeof value !== "object" || value === null) {
|
|
3796
|
+
return false;
|
|
3797
|
+
}
|
|
3798
|
+
if (Object.getPrototypeOf(value) === null) {
|
|
3799
|
+
return true;
|
|
3800
|
+
}
|
|
3801
|
+
let proto = value;
|
|
3802
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
3803
|
+
proto = Object.getPrototypeOf(proto);
|
|
3804
|
+
}
|
|
3805
|
+
return Object.getPrototypeOf(value) === proto;
|
|
3806
|
+
}
|
|
3807
|
+
|
|
3662
3808
|
// src/core/schemas/utils/keys.ts
|
|
3663
3809
|
function keys(object2) {
|
|
3664
3810
|
return Object.keys(object2);
|
|
@@ -3677,47 +3823,56 @@ function partition(items, predicate) {
|
|
|
3677
3823
|
return [trueItems, falseItems];
|
|
3678
3824
|
}
|
|
3679
3825
|
|
|
3680
|
-
// src/core/schemas/builders/object-like/types.ts
|
|
3681
|
-
var OBJECT_LIKE_BRAND = void 0;
|
|
3682
|
-
|
|
3683
3826
|
// src/core/schemas/builders/object-like/getObjectLikeUtils.ts
|
|
3684
3827
|
function getObjectLikeUtils(schema) {
|
|
3685
3828
|
return {
|
|
3686
|
-
|
|
3829
|
+
withParsedProperties: (properties) => withParsedProperties(schema, properties)
|
|
3687
3830
|
};
|
|
3688
3831
|
}
|
|
3689
|
-
function
|
|
3832
|
+
function withParsedProperties(objectLike, properties) {
|
|
3690
3833
|
const objectSchema = {
|
|
3691
|
-
...OBJECT_LIKE_BRAND,
|
|
3692
3834
|
parse: async (raw, opts) => {
|
|
3693
3835
|
const parsedObject = await objectLike.parse(raw, opts);
|
|
3836
|
+
if (!parsedObject.ok) {
|
|
3837
|
+
return parsedObject;
|
|
3838
|
+
}
|
|
3694
3839
|
const additionalProperties = Object.entries(properties).reduce(
|
|
3695
3840
|
(processed, [key, value]) => {
|
|
3696
3841
|
return {
|
|
3697
3842
|
...processed,
|
|
3698
|
-
[key]: typeof value === "function" ? value(parsedObject) : value
|
|
3843
|
+
[key]: typeof value === "function" ? value(parsedObject.value) : value
|
|
3699
3844
|
};
|
|
3700
3845
|
},
|
|
3701
3846
|
{}
|
|
3702
3847
|
);
|
|
3703
3848
|
return {
|
|
3704
|
-
|
|
3705
|
-
|
|
3849
|
+
ok: true,
|
|
3850
|
+
value: {
|
|
3851
|
+
...parsedObject.value,
|
|
3852
|
+
...additionalProperties
|
|
3853
|
+
}
|
|
3706
3854
|
};
|
|
3707
3855
|
},
|
|
3708
3856
|
json: (parsed, opts) => {
|
|
3857
|
+
if (!isPlainObject(parsed)) {
|
|
3858
|
+
return {
|
|
3859
|
+
ok: false,
|
|
3860
|
+
errors: [
|
|
3861
|
+
{
|
|
3862
|
+
path: [],
|
|
3863
|
+
message: NOT_AN_OBJECT_ERROR_MESSAGE
|
|
3864
|
+
}
|
|
3865
|
+
]
|
|
3866
|
+
};
|
|
3867
|
+
}
|
|
3709
3868
|
const addedPropertyKeys = new Set(Object.keys(properties));
|
|
3710
|
-
const parsedWithoutAddedProperties =
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
filtered[key] = value;
|
|
3714
|
-
}
|
|
3715
|
-
return filtered;
|
|
3716
|
-
},
|
|
3717
|
-
{}
|
|
3869
|
+
const parsedWithoutAddedProperties = filterObject(
|
|
3870
|
+
parsed,
|
|
3871
|
+
Object.keys(parsed).filter((key) => !addedPropertyKeys.has(key))
|
|
3718
3872
|
);
|
|
3719
3873
|
return objectLike.json(parsedWithoutAddedProperties, opts);
|
|
3720
|
-
}
|
|
3874
|
+
},
|
|
3875
|
+
getType: () => objectLike.getType()
|
|
3721
3876
|
};
|
|
3722
3877
|
return {
|
|
3723
3878
|
...objectSchema,
|
|
@@ -3741,54 +3896,76 @@ function isProperty(maybeProperty) {
|
|
|
3741
3896
|
// src/core/schemas/builders/object/object.ts
|
|
3742
3897
|
function object(schemas) {
|
|
3743
3898
|
const baseSchema = {
|
|
3744
|
-
...OBJECT_LIKE_BRAND,
|
|
3745
3899
|
_getRawProperties: () => Promise.resolve(
|
|
3746
3900
|
Object.entries(schemas).map(
|
|
3747
3901
|
([parsedKey, propertySchema]) => isProperty(propertySchema) ? propertySchema.rawKey : parsedKey
|
|
3748
3902
|
)
|
|
3749
3903
|
),
|
|
3750
3904
|
_getParsedProperties: () => Promise.resolve(keys(schemas)),
|
|
3751
|
-
parse: async (raw,
|
|
3905
|
+
parse: async (raw, opts) => {
|
|
3752
3906
|
const rawKeyToProperty = {};
|
|
3907
|
+
const requiredKeys = [];
|
|
3753
3908
|
for (const [parsedKey, schemaOrObjectProperty] of entries(schemas)) {
|
|
3754
3909
|
const rawKey = isProperty(schemaOrObjectProperty) ? schemaOrObjectProperty.rawKey : parsedKey;
|
|
3910
|
+
const valueSchema = isProperty(schemaOrObjectProperty) ? schemaOrObjectProperty.valueSchema : schemaOrObjectProperty;
|
|
3755
3911
|
const property2 = {
|
|
3756
3912
|
rawKey,
|
|
3757
3913
|
parsedKey,
|
|
3758
|
-
valueSchema
|
|
3914
|
+
valueSchema
|
|
3759
3915
|
};
|
|
3760
3916
|
rawKeyToProperty[rawKey] = property2;
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
for (const [rawKey, rawPropertyValue] of Object.entries(raw)) {
|
|
3764
|
-
const property2 = rawKeyToProperty[rawKey];
|
|
3765
|
-
if (property2 != null) {
|
|
3766
|
-
const value = await property2.valueSchema.parse(rawPropertyValue);
|
|
3767
|
-
parsed[property2.parsedKey] = value;
|
|
3768
|
-
} else if (!skipUnknownKeysOnParse && rawPropertyValue != null) {
|
|
3769
|
-
parsed[rawKey] = rawPropertyValue;
|
|
3917
|
+
if (await valueSchema.getType() !== "optional") {
|
|
3918
|
+
requiredKeys.push(rawKey);
|
|
3770
3919
|
}
|
|
3771
3920
|
}
|
|
3772
|
-
return
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
if (isProperty(schemaOrObjectProperty)) {
|
|
3780
|
-
const value = await schemaOrObjectProperty.valueSchema.json(parsedPropertyValue);
|
|
3781
|
-
raw[schemaOrObjectProperty.rawKey] = value;
|
|
3782
|
-
} else {
|
|
3783
|
-
const value = await schemaOrObjectProperty.json(parsedPropertyValue);
|
|
3784
|
-
raw[parsedKey] = value;
|
|
3921
|
+
return validateAndTransformObject({
|
|
3922
|
+
value: raw,
|
|
3923
|
+
requiredKeys,
|
|
3924
|
+
getProperty: (rawKey) => {
|
|
3925
|
+
const property2 = rawKeyToProperty[rawKey];
|
|
3926
|
+
if (property2 == null) {
|
|
3927
|
+
return void 0;
|
|
3785
3928
|
}
|
|
3786
|
-
|
|
3787
|
-
|
|
3929
|
+
return {
|
|
3930
|
+
transformedKey: property2.parsedKey,
|
|
3931
|
+
transform: (propertyValue) => property2.valueSchema.parse(propertyValue, opts)
|
|
3932
|
+
};
|
|
3933
|
+
},
|
|
3934
|
+
allowUnknownKeys: opts?.allowUnknownKeys ?? false
|
|
3935
|
+
});
|
|
3936
|
+
},
|
|
3937
|
+
json: async (parsed, opts) => {
|
|
3938
|
+
const requiredKeys = [];
|
|
3939
|
+
for (const [parsedKey, schemaOrObjectProperty] of entries(schemas)) {
|
|
3940
|
+
const valueSchema = isProperty(schemaOrObjectProperty) ? schemaOrObjectProperty.valueSchema : schemaOrObjectProperty;
|
|
3941
|
+
if (await valueSchema.getType() !== "optional") {
|
|
3942
|
+
requiredKeys.push(parsedKey);
|
|
3788
3943
|
}
|
|
3789
3944
|
}
|
|
3790
|
-
return
|
|
3791
|
-
|
|
3945
|
+
return validateAndTransformObject({
|
|
3946
|
+
value: parsed,
|
|
3947
|
+
requiredKeys,
|
|
3948
|
+
getProperty: (parsedKey) => {
|
|
3949
|
+
const property2 = schemas[parsedKey];
|
|
3950
|
+
if (property2 == null) {
|
|
3951
|
+
return void 0;
|
|
3952
|
+
}
|
|
3953
|
+
if (isProperty(property2)) {
|
|
3954
|
+
return {
|
|
3955
|
+
transformedKey: property2.rawKey,
|
|
3956
|
+
transform: (propertyValue) => property2.valueSchema.json(propertyValue, opts)
|
|
3957
|
+
};
|
|
3958
|
+
} else {
|
|
3959
|
+
return {
|
|
3960
|
+
transformedKey: parsedKey,
|
|
3961
|
+
transform: (propertyValue) => property2.json(propertyValue, opts)
|
|
3962
|
+
};
|
|
3963
|
+
}
|
|
3964
|
+
},
|
|
3965
|
+
allowUnknownKeys: opts?.allowUnknownKeys ?? false
|
|
3966
|
+
});
|
|
3967
|
+
},
|
|
3968
|
+
getType: () => SchemaType.OBJECT
|
|
3792
3969
|
};
|
|
3793
3970
|
return {
|
|
3794
3971
|
...baseSchema,
|
|
@@ -3797,11 +3974,72 @@ function object(schemas) {
|
|
|
3797
3974
|
...getObjectUtils(baseSchema)
|
|
3798
3975
|
};
|
|
3799
3976
|
}
|
|
3977
|
+
async function validateAndTransformObject({
|
|
3978
|
+
value,
|
|
3979
|
+
requiredKeys,
|
|
3980
|
+
getProperty,
|
|
3981
|
+
allowUnknownKeys
|
|
3982
|
+
}) {
|
|
3983
|
+
if (!isPlainObject(value)) {
|
|
3984
|
+
return {
|
|
3985
|
+
ok: false,
|
|
3986
|
+
errors: [
|
|
3987
|
+
{
|
|
3988
|
+
path: [],
|
|
3989
|
+
message: NOT_AN_OBJECT_ERROR_MESSAGE
|
|
3990
|
+
}
|
|
3991
|
+
]
|
|
3992
|
+
};
|
|
3993
|
+
}
|
|
3994
|
+
const missingRequiredKeys = new Set(requiredKeys);
|
|
3995
|
+
const errors = [];
|
|
3996
|
+
const transformed = {};
|
|
3997
|
+
for (const [preTransformedKey, preTransformedItemValue] of Object.entries(value)) {
|
|
3998
|
+
const property2 = getProperty(preTransformedKey);
|
|
3999
|
+
if (property2 != null) {
|
|
4000
|
+
missingRequiredKeys.delete(preTransformedKey);
|
|
4001
|
+
const value2 = await property2.transform(preTransformedItemValue);
|
|
4002
|
+
if (value2.ok) {
|
|
4003
|
+
transformed[property2.transformedKey] = value2.value;
|
|
4004
|
+
} else {
|
|
4005
|
+
errors.push(
|
|
4006
|
+
...value2.errors.map((error) => ({
|
|
4007
|
+
path: [preTransformedKey, ...error.path],
|
|
4008
|
+
message: error.message
|
|
4009
|
+
}))
|
|
4010
|
+
);
|
|
4011
|
+
}
|
|
4012
|
+
} else if (allowUnknownKeys) {
|
|
4013
|
+
transformed[preTransformedKey] = preTransformedItemValue;
|
|
4014
|
+
} else {
|
|
4015
|
+
errors.push({
|
|
4016
|
+
path: [preTransformedKey],
|
|
4017
|
+
message: `Unrecognized key "${preTransformedKey}"`
|
|
4018
|
+
});
|
|
4019
|
+
}
|
|
4020
|
+
}
|
|
4021
|
+
errors.push(
|
|
4022
|
+
...requiredKeys.filter((key) => missingRequiredKeys.has(key)).map((key) => ({
|
|
4023
|
+
path: [],
|
|
4024
|
+
message: `Missing required key "${key}"`
|
|
4025
|
+
}))
|
|
4026
|
+
);
|
|
4027
|
+
if (errors.length === 0) {
|
|
4028
|
+
return {
|
|
4029
|
+
ok: true,
|
|
4030
|
+
value: transformed
|
|
4031
|
+
};
|
|
4032
|
+
} else {
|
|
4033
|
+
return {
|
|
4034
|
+
ok: false,
|
|
4035
|
+
errors
|
|
4036
|
+
};
|
|
4037
|
+
}
|
|
4038
|
+
}
|
|
3800
4039
|
function getObjectUtils(schema) {
|
|
3801
4040
|
return {
|
|
3802
4041
|
extend: (extension) => {
|
|
3803
4042
|
const baseSchema = {
|
|
3804
|
-
...OBJECT_LIKE_BRAND,
|
|
3805
4043
|
_getParsedProperties: async () => [
|
|
3806
4044
|
...await schema._getParsedProperties(),
|
|
3807
4045
|
...await extension._getParsedProperties()
|
|
@@ -3811,27 +4049,22 @@ function getObjectUtils(schema) {
|
|
|
3811
4049
|
...await extension._getRawProperties()
|
|
3812
4050
|
],
|
|
3813
4051
|
parse: async (raw, opts) => {
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
(
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
...await schema.parse(filterObject(raw, otherProperties), opts),
|
|
3821
|
-
...await extension.parse(filterObject(raw, extensionProperties), opts)
|
|
3822
|
-
};
|
|
4052
|
+
return validateAndTransformExtendedObject({
|
|
4053
|
+
extensionKeys: await extension._getRawProperties(),
|
|
4054
|
+
value: raw,
|
|
4055
|
+
transformBase: (rawBase) => schema.parse(rawBase, opts),
|
|
4056
|
+
transformExtension: (rawExtension) => extension.parse(rawExtension, opts)
|
|
4057
|
+
});
|
|
3823
4058
|
},
|
|
3824
4059
|
json: async (parsed, opts) => {
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
(
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
};
|
|
3834
|
-
}
|
|
4060
|
+
return validateAndTransformExtendedObject({
|
|
4061
|
+
extensionKeys: await extension._getParsedProperties(),
|
|
4062
|
+
value: parsed,
|
|
4063
|
+
transformBase: (parsedBase) => schema.json(parsedBase, opts),
|
|
4064
|
+
transformExtension: (parsedExtension) => extension.json(parsedExtension, opts)
|
|
4065
|
+
});
|
|
4066
|
+
},
|
|
4067
|
+
getType: () => SchemaType.OBJECT
|
|
3835
4068
|
};
|
|
3836
4069
|
return {
|
|
3837
4070
|
...baseSchema,
|
|
@@ -3842,11 +4075,41 @@ function getObjectUtils(schema) {
|
|
|
3842
4075
|
}
|
|
3843
4076
|
};
|
|
3844
4077
|
}
|
|
4078
|
+
async function validateAndTransformExtendedObject({
|
|
4079
|
+
extensionKeys,
|
|
4080
|
+
value,
|
|
4081
|
+
transformBase,
|
|
4082
|
+
transformExtension
|
|
4083
|
+
}) {
|
|
4084
|
+
const extensionPropertiesSet = new Set(extensionKeys);
|
|
4085
|
+
const [extensionProperties, baseProperties] = partition(
|
|
4086
|
+
keys(value),
|
|
4087
|
+
(key) => extensionPropertiesSet.has(key)
|
|
4088
|
+
);
|
|
4089
|
+
const transformedBase = await transformBase(filterObject(value, baseProperties));
|
|
4090
|
+
const transformedExtension = await transformExtension(filterObject(value, extensionProperties));
|
|
4091
|
+
if (transformedBase.ok && transformedExtension.ok) {
|
|
4092
|
+
return {
|
|
4093
|
+
ok: true,
|
|
4094
|
+
value: {
|
|
4095
|
+
...transformedBase.value,
|
|
4096
|
+
...transformedExtension.value
|
|
4097
|
+
}
|
|
4098
|
+
};
|
|
4099
|
+
} else {
|
|
4100
|
+
return {
|
|
4101
|
+
ok: false,
|
|
4102
|
+
errors: [
|
|
4103
|
+
...transformedBase.ok ? [] : transformedBase.errors,
|
|
4104
|
+
...transformedExtension.ok ? [] : transformedExtension.errors
|
|
4105
|
+
]
|
|
4106
|
+
};
|
|
4107
|
+
}
|
|
4108
|
+
}
|
|
3845
4109
|
|
|
3846
4110
|
// src/core/schemas/builders/lazy/lazyObject.ts
|
|
3847
4111
|
function lazyObject(getter) {
|
|
3848
4112
|
const baseSchema = {
|
|
3849
|
-
...OBJECT_LIKE_BRAND,
|
|
3850
4113
|
...constructLazyBaseSchema(getter),
|
|
3851
4114
|
_getRawProperties: async () => (await getMemoizedSchema(getter))._getRawProperties(),
|
|
3852
4115
|
_getParsedProperties: async () => (await getMemoizedSchema(getter))._getParsedProperties()
|
|
@@ -3862,66 +4125,273 @@ function lazyObject(getter) {
|
|
|
3862
4125
|
// src/core/schemas/builders/list/list.ts
|
|
3863
4126
|
function list(schema) {
|
|
3864
4127
|
const baseSchema = {
|
|
3865
|
-
parse: (raw, opts) =>
|
|
3866
|
-
json: (parsed, opts) =>
|
|
4128
|
+
parse: async (raw, opts) => validateAndTransformArray(raw, (item) => schema.parse(item, opts)),
|
|
4129
|
+
json: (parsed, opts) => validateAndTransformArray(parsed, (item) => schema.json(item, opts)),
|
|
4130
|
+
getType: () => SchemaType.LIST
|
|
3867
4131
|
};
|
|
3868
4132
|
return {
|
|
3869
4133
|
...baseSchema,
|
|
3870
4134
|
...getSchemaUtils(baseSchema)
|
|
3871
4135
|
};
|
|
3872
4136
|
}
|
|
4137
|
+
async function validateAndTransformArray(value, transformItem) {
|
|
4138
|
+
if (!Array.isArray(value)) {
|
|
4139
|
+
return {
|
|
4140
|
+
ok: false,
|
|
4141
|
+
errors: [
|
|
4142
|
+
{
|
|
4143
|
+
message: "Not a list",
|
|
4144
|
+
path: []
|
|
4145
|
+
}
|
|
4146
|
+
]
|
|
4147
|
+
};
|
|
4148
|
+
}
|
|
4149
|
+
const maybeValidItems = await Promise.all(value.map((item) => transformItem(item)));
|
|
4150
|
+
return maybeValidItems.reduce(
|
|
4151
|
+
(acc, item, index) => {
|
|
4152
|
+
if (acc.ok && item.ok) {
|
|
4153
|
+
return {
|
|
4154
|
+
ok: true,
|
|
4155
|
+
value: [...acc.value, item.value]
|
|
4156
|
+
};
|
|
4157
|
+
}
|
|
4158
|
+
const errors = [];
|
|
4159
|
+
if (!acc.ok) {
|
|
4160
|
+
errors.push(...acc.errors);
|
|
4161
|
+
}
|
|
4162
|
+
if (!item.ok) {
|
|
4163
|
+
errors.push(
|
|
4164
|
+
...item.errors.map((error) => ({
|
|
4165
|
+
path: [`[${index}]`, ...error.path],
|
|
4166
|
+
message: error.message
|
|
4167
|
+
}))
|
|
4168
|
+
);
|
|
4169
|
+
}
|
|
4170
|
+
return {
|
|
4171
|
+
ok: false,
|
|
4172
|
+
errors
|
|
4173
|
+
};
|
|
4174
|
+
},
|
|
4175
|
+
{ ok: true, value: [] }
|
|
4176
|
+
);
|
|
4177
|
+
}
|
|
3873
4178
|
|
|
3874
4179
|
// src/core/schemas/builders/literals/stringLiteral.ts
|
|
3875
|
-
function stringLiteral(
|
|
3876
|
-
|
|
4180
|
+
function stringLiteral(literal) {
|
|
4181
|
+
const schemaCreator = createIdentitySchemaCreator(SchemaType.STRING_LITERAL, (value) => {
|
|
4182
|
+
if (value === literal) {
|
|
4183
|
+
return {
|
|
4184
|
+
ok: true,
|
|
4185
|
+
value: literal
|
|
4186
|
+
};
|
|
4187
|
+
} else {
|
|
4188
|
+
return {
|
|
4189
|
+
ok: false,
|
|
4190
|
+
errors: [
|
|
4191
|
+
{
|
|
4192
|
+
path: [],
|
|
4193
|
+
message: `Not equal to "${literal}"`
|
|
4194
|
+
}
|
|
4195
|
+
]
|
|
4196
|
+
};
|
|
4197
|
+
}
|
|
4198
|
+
});
|
|
4199
|
+
return schemaCreator();
|
|
3877
4200
|
}
|
|
3878
4201
|
|
|
3879
4202
|
// src/core/schemas/builders/primitives/any.ts
|
|
3880
|
-
var any = createIdentitySchemaCreator();
|
|
4203
|
+
var any = createIdentitySchemaCreator(SchemaType.ANY, (value) => ({ ok: true, value }));
|
|
3881
4204
|
|
|
3882
4205
|
// src/core/schemas/builders/primitives/boolean.ts
|
|
3883
|
-
var boolean = createIdentitySchemaCreator()
|
|
4206
|
+
var boolean = createIdentitySchemaCreator(SchemaType.BOOLEAN, (value) => {
|
|
4207
|
+
if (typeof value === "boolean") {
|
|
4208
|
+
return {
|
|
4209
|
+
ok: true,
|
|
4210
|
+
value
|
|
4211
|
+
};
|
|
4212
|
+
} else {
|
|
4213
|
+
return {
|
|
4214
|
+
ok: false,
|
|
4215
|
+
errors: [
|
|
4216
|
+
{
|
|
4217
|
+
path: [],
|
|
4218
|
+
message: "Not a boolean"
|
|
4219
|
+
}
|
|
4220
|
+
]
|
|
4221
|
+
};
|
|
4222
|
+
}
|
|
4223
|
+
});
|
|
3884
4224
|
|
|
3885
4225
|
// src/core/schemas/builders/primitives/number.ts
|
|
3886
|
-
var number = createIdentitySchemaCreator()
|
|
4226
|
+
var number = createIdentitySchemaCreator(SchemaType.NUMBER, (value) => {
|
|
4227
|
+
if (typeof value === "number") {
|
|
4228
|
+
return {
|
|
4229
|
+
ok: true,
|
|
4230
|
+
value
|
|
4231
|
+
};
|
|
4232
|
+
} else {
|
|
4233
|
+
return {
|
|
4234
|
+
ok: false,
|
|
4235
|
+
errors: [
|
|
4236
|
+
{
|
|
4237
|
+
path: [],
|
|
4238
|
+
message: "Not a number"
|
|
4239
|
+
}
|
|
4240
|
+
]
|
|
4241
|
+
};
|
|
4242
|
+
}
|
|
4243
|
+
});
|
|
3887
4244
|
|
|
3888
4245
|
// src/core/schemas/builders/primitives/string.ts
|
|
3889
|
-
var string = createIdentitySchemaCreator()
|
|
4246
|
+
var string = createIdentitySchemaCreator(SchemaType.STRING, (value) => {
|
|
4247
|
+
if (typeof value === "string") {
|
|
4248
|
+
return {
|
|
4249
|
+
ok: true,
|
|
4250
|
+
value
|
|
4251
|
+
};
|
|
4252
|
+
} else {
|
|
4253
|
+
return {
|
|
4254
|
+
ok: false,
|
|
4255
|
+
errors: [
|
|
4256
|
+
{
|
|
4257
|
+
path: [],
|
|
4258
|
+
message: "Not a string"
|
|
4259
|
+
}
|
|
4260
|
+
]
|
|
4261
|
+
};
|
|
4262
|
+
}
|
|
4263
|
+
});
|
|
3890
4264
|
|
|
3891
4265
|
// src/core/schemas/builders/primitives/unknown.ts
|
|
3892
|
-
var unknown = createIdentitySchemaCreator();
|
|
4266
|
+
var unknown = createIdentitySchemaCreator(SchemaType.UNKNOWN, (value) => ({ ok: true, value }));
|
|
3893
4267
|
|
|
3894
4268
|
// src/core/schemas/builders/record/record.ts
|
|
3895
4269
|
function record(keySchema, valueSchema) {
|
|
3896
4270
|
const baseSchema = {
|
|
3897
|
-
parse: (raw, opts) => {
|
|
3898
|
-
return
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
}
|
|
4271
|
+
parse: async (raw, opts) => {
|
|
4272
|
+
return validateAndTransformRecord({
|
|
4273
|
+
value: raw,
|
|
4274
|
+
isKeyNumeric: await keySchema.getType() === SchemaType.NUMBER,
|
|
4275
|
+
transformKey: (key) => keySchema.parse(key, opts),
|
|
4276
|
+
transformValue: (value) => valueSchema.parse(value, opts)
|
|
4277
|
+
});
|
|
3904
4278
|
},
|
|
3905
|
-
json: (parsed, opts) => {
|
|
3906
|
-
return
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
}
|
|
3912
|
-
}
|
|
4279
|
+
json: async (parsed, opts) => {
|
|
4280
|
+
return validateAndTransformRecord({
|
|
4281
|
+
value: parsed,
|
|
4282
|
+
isKeyNumeric: await keySchema.getType() === SchemaType.NUMBER,
|
|
4283
|
+
transformKey: (key) => keySchema.json(key, opts),
|
|
4284
|
+
transformValue: (value) => valueSchema.json(value, opts)
|
|
4285
|
+
});
|
|
4286
|
+
},
|
|
4287
|
+
getType: () => SchemaType.RECORD
|
|
3913
4288
|
};
|
|
3914
4289
|
return {
|
|
3915
4290
|
...baseSchema,
|
|
3916
4291
|
...getSchemaUtils(baseSchema)
|
|
3917
4292
|
};
|
|
3918
4293
|
}
|
|
4294
|
+
async function validateAndTransformRecord({
|
|
4295
|
+
value,
|
|
4296
|
+
isKeyNumeric,
|
|
4297
|
+
transformKey,
|
|
4298
|
+
transformValue
|
|
4299
|
+
}) {
|
|
4300
|
+
if (!isPlainObject(value)) {
|
|
4301
|
+
return {
|
|
4302
|
+
ok: false,
|
|
4303
|
+
errors: [
|
|
4304
|
+
{
|
|
4305
|
+
path: [],
|
|
4306
|
+
message: NOT_AN_OBJECT_ERROR_MESSAGE
|
|
4307
|
+
}
|
|
4308
|
+
]
|
|
4309
|
+
};
|
|
4310
|
+
}
|
|
4311
|
+
return entries(value).reduce(
|
|
4312
|
+
async (accPromise, [stringKey, value2]) => {
|
|
4313
|
+
if (value2 == null) {
|
|
4314
|
+
return accPromise;
|
|
4315
|
+
}
|
|
4316
|
+
const acc = await accPromise;
|
|
4317
|
+
let key = stringKey;
|
|
4318
|
+
if (isKeyNumeric) {
|
|
4319
|
+
const numberKey = stringKey.length > 0 ? Number(stringKey) : NaN;
|
|
4320
|
+
if (!isNaN(numberKey)) {
|
|
4321
|
+
key = numberKey;
|
|
4322
|
+
}
|
|
4323
|
+
}
|
|
4324
|
+
const transformedKey = await transformKey(key);
|
|
4325
|
+
const transformedValue = await transformValue(value2);
|
|
4326
|
+
if (acc.ok && transformedKey.ok && transformedValue.ok) {
|
|
4327
|
+
return {
|
|
4328
|
+
ok: true,
|
|
4329
|
+
value: {
|
|
4330
|
+
...acc.value,
|
|
4331
|
+
[transformedKey.value]: transformedValue.value
|
|
4332
|
+
}
|
|
4333
|
+
};
|
|
4334
|
+
}
|
|
4335
|
+
const errors = [];
|
|
4336
|
+
if (!acc.ok) {
|
|
4337
|
+
errors.push(...acc.errors);
|
|
4338
|
+
}
|
|
4339
|
+
if (!transformedKey.ok) {
|
|
4340
|
+
errors.push(
|
|
4341
|
+
...transformedKey.errors.map((error) => ({
|
|
4342
|
+
path: [`${key} (key)`, ...error.path],
|
|
4343
|
+
message: error.message
|
|
4344
|
+
}))
|
|
4345
|
+
);
|
|
4346
|
+
}
|
|
4347
|
+
if (!transformedValue.ok) {
|
|
4348
|
+
errors.push(
|
|
4349
|
+
...transformedValue.errors.map((error) => ({
|
|
4350
|
+
path: [stringKey, ...error.path],
|
|
4351
|
+
message: error.message
|
|
4352
|
+
}))
|
|
4353
|
+
);
|
|
4354
|
+
}
|
|
4355
|
+
return {
|
|
4356
|
+
ok: false,
|
|
4357
|
+
errors
|
|
4358
|
+
};
|
|
4359
|
+
},
|
|
4360
|
+
Promise.resolve({ ok: true, value: {} })
|
|
4361
|
+
);
|
|
4362
|
+
}
|
|
3919
4363
|
|
|
3920
4364
|
// src/core/schemas/builders/set/set.ts
|
|
3921
4365
|
function set(schema) {
|
|
4366
|
+
const listSchema = list(schema);
|
|
3922
4367
|
const baseSchema = {
|
|
3923
|
-
parse: async (raw, opts) =>
|
|
3924
|
-
|
|
4368
|
+
parse: async (raw, opts) => {
|
|
4369
|
+
const parsedList = await listSchema.parse(raw, opts);
|
|
4370
|
+
if (parsedList.ok) {
|
|
4371
|
+
return {
|
|
4372
|
+
ok: true,
|
|
4373
|
+
value: new Set(parsedList.value)
|
|
4374
|
+
};
|
|
4375
|
+
} else {
|
|
4376
|
+
return parsedList;
|
|
4377
|
+
}
|
|
4378
|
+
},
|
|
4379
|
+
json: async (parsed, opts) => {
|
|
4380
|
+
if (!(parsed instanceof Set)) {
|
|
4381
|
+
return {
|
|
4382
|
+
ok: false,
|
|
4383
|
+
errors: [
|
|
4384
|
+
{
|
|
4385
|
+
path: [],
|
|
4386
|
+
message: "Not a Set"
|
|
4387
|
+
}
|
|
4388
|
+
]
|
|
4389
|
+
};
|
|
4390
|
+
}
|
|
4391
|
+
const jsonList = await listSchema.json([...parsed], opts);
|
|
4392
|
+
return jsonList;
|
|
4393
|
+
},
|
|
4394
|
+
getType: () => SchemaType.SET
|
|
3925
4395
|
};
|
|
3926
4396
|
return {
|
|
3927
4397
|
...baseSchema,
|
|
@@ -3941,36 +4411,31 @@ function discriminant(parsedDiscriminant, rawDiscriminant) {
|
|
|
3941
4411
|
function union(discriminant2, union2) {
|
|
3942
4412
|
const rawDiscriminant = typeof discriminant2 === "string" ? discriminant2 : discriminant2.rawDiscriminant;
|
|
3943
4413
|
const parsedDiscriminant = typeof discriminant2 === "string" ? discriminant2 : discriminant2.parsedDiscriminant;
|
|
4414
|
+
const discriminantValueSchema = enum_(keys(union2));
|
|
3944
4415
|
const baseSchema = {
|
|
3945
|
-
...OBJECT_LIKE_BRAND,
|
|
3946
4416
|
parse: async (raw, opts) => {
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
...await additionalPropertySchemas.parse(additionalProperties, opts),
|
|
3957
|
-
[parsedDiscriminant]: discriminantValue
|
|
3958
|
-
};
|
|
4417
|
+
return transformAndValidateUnion(
|
|
4418
|
+
raw,
|
|
4419
|
+
rawDiscriminant,
|
|
4420
|
+
parsedDiscriminant,
|
|
4421
|
+
(discriminantValue) => discriminantValueSchema.parse(discriminantValue, opts),
|
|
4422
|
+
(discriminantValue) => union2[discriminantValue],
|
|
4423
|
+
opts?.allowUnknownKeys ?? false,
|
|
4424
|
+
(additionalProperties, additionalPropertiesSchema) => additionalPropertiesSchema.parse(additionalProperties, opts)
|
|
4425
|
+
);
|
|
3959
4426
|
},
|
|
3960
4427
|
json: async (parsed, opts) => {
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
};
|
|
3973
|
-
}
|
|
4428
|
+
return transformAndValidateUnion(
|
|
4429
|
+
parsed,
|
|
4430
|
+
parsedDiscriminant,
|
|
4431
|
+
rawDiscriminant,
|
|
4432
|
+
(discriminantValue) => discriminantValueSchema.json(discriminantValue, opts),
|
|
4433
|
+
(discriminantValue) => union2[discriminantValue],
|
|
4434
|
+
opts?.allowUnknownKeys ?? false,
|
|
4435
|
+
(additionalProperties, additionalPropertiesSchema) => additionalPropertiesSchema.json(additionalProperties, opts)
|
|
4436
|
+
);
|
|
4437
|
+
},
|
|
4438
|
+
getType: () => SchemaType.UNION
|
|
3974
4439
|
};
|
|
3975
4440
|
return {
|
|
3976
4441
|
...baseSchema,
|
|
@@ -3978,12 +4443,83 @@ function union(discriminant2, union2) {
|
|
|
3978
4443
|
...getObjectLikeUtils(baseSchema)
|
|
3979
4444
|
};
|
|
3980
4445
|
}
|
|
4446
|
+
async function transformAndValidateUnion(value, discriminant2, transformedDiscriminant, transformDiscriminantValue, getAdditionalPropertiesSchema, allowUnknownKeys, transformAdditionalProperties) {
|
|
4447
|
+
if (!isPlainObject(value)) {
|
|
4448
|
+
return {
|
|
4449
|
+
ok: false,
|
|
4450
|
+
errors: [
|
|
4451
|
+
{
|
|
4452
|
+
path: [],
|
|
4453
|
+
message: NOT_AN_OBJECT_ERROR_MESSAGE
|
|
4454
|
+
}
|
|
4455
|
+
]
|
|
4456
|
+
};
|
|
4457
|
+
}
|
|
4458
|
+
const { [discriminant2]: discriminantValue, ...additionalProperties } = value;
|
|
4459
|
+
if (discriminantValue == null) {
|
|
4460
|
+
return {
|
|
4461
|
+
ok: false,
|
|
4462
|
+
errors: [
|
|
4463
|
+
{
|
|
4464
|
+
path: [],
|
|
4465
|
+
message: `Missing discriminant ("${discriminant2}")`
|
|
4466
|
+
}
|
|
4467
|
+
]
|
|
4468
|
+
};
|
|
4469
|
+
}
|
|
4470
|
+
const transformedDiscriminantValue = await transformDiscriminantValue(discriminantValue);
|
|
4471
|
+
if (!transformedDiscriminantValue.ok) {
|
|
4472
|
+
return {
|
|
4473
|
+
ok: false,
|
|
4474
|
+
errors: transformedDiscriminantValue.errors.map((error) => ({
|
|
4475
|
+
path: [discriminant2, ...error.path],
|
|
4476
|
+
message: error.message
|
|
4477
|
+
}))
|
|
4478
|
+
};
|
|
4479
|
+
}
|
|
4480
|
+
const additionalPropertiesSchema = getAdditionalPropertiesSchema(transformedDiscriminantValue.value);
|
|
4481
|
+
if (additionalPropertiesSchema == null) {
|
|
4482
|
+
if (allowUnknownKeys) {
|
|
4483
|
+
return {
|
|
4484
|
+
ok: true,
|
|
4485
|
+
value: {
|
|
4486
|
+
[transformedDiscriminant]: transformedDiscriminantValue.value,
|
|
4487
|
+
...additionalProperties
|
|
4488
|
+
}
|
|
4489
|
+
};
|
|
4490
|
+
} else {
|
|
4491
|
+
return {
|
|
4492
|
+
ok: false,
|
|
4493
|
+
errors: [
|
|
4494
|
+
{
|
|
4495
|
+
path: [discriminant2],
|
|
4496
|
+
message: "Unrecognized discriminant value"
|
|
4497
|
+
}
|
|
4498
|
+
]
|
|
4499
|
+
};
|
|
4500
|
+
}
|
|
4501
|
+
}
|
|
4502
|
+
const transformedAdditionalProperties = await transformAdditionalProperties(
|
|
4503
|
+
additionalProperties,
|
|
4504
|
+
additionalPropertiesSchema
|
|
4505
|
+
);
|
|
4506
|
+
if (!transformedAdditionalProperties.ok) {
|
|
4507
|
+
return transformedAdditionalProperties;
|
|
4508
|
+
}
|
|
4509
|
+
return {
|
|
4510
|
+
ok: true,
|
|
4511
|
+
value: {
|
|
4512
|
+
[transformedDiscriminant]: discriminantValue,
|
|
4513
|
+
...transformedAdditionalProperties.value
|
|
4514
|
+
}
|
|
4515
|
+
};
|
|
4516
|
+
}
|
|
3981
4517
|
|
|
3982
4518
|
// src/core/auth/BasicAuth.ts
|
|
3983
4519
|
var import_basic_auth = __toESM(require_basic_auth());
|
|
3984
4520
|
|
|
3985
|
-
// .yarn/cache/js-base64-npm-3.7.
|
|
3986
|
-
var version = "3.7.
|
|
4521
|
+
// .yarn/cache/js-base64-npm-3.7.5-81a9ad2ffd-67a78c8b1c.zip/node_modules/js-base64/base64.mjs
|
|
4522
|
+
var version = "3.7.5";
|
|
3987
4523
|
var VERSION = version;
|
|
3988
4524
|
var _hasatob = typeof atob === "function";
|
|
3989
4525
|
var _hasbtoa = typeof btoa === "function";
|
|
@@ -3999,7 +4535,7 @@ var b64tab = ((a) => {
|
|
|
3999
4535
|
})(b64chs);
|
|
4000
4536
|
var b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
|
|
4001
4537
|
var _fromCC = String.fromCharCode.bind(String);
|
|
4002
|
-
var _U8Afrom = typeof Uint8Array.from === "function" ? Uint8Array.from.bind(Uint8Array) : (it
|
|
4538
|
+
var _U8Afrom = typeof Uint8Array.from === "function" ? Uint8Array.from.bind(Uint8Array) : (it) => new Uint8Array(Array.prototype.slice.call(it, 0));
|
|
4003
4539
|
var _mkUriSafe = (src) => src.replace(/=/g, "").replace(/[+\/]/g, (m0) => m0 == "+" ? "-" : "_");
|
|
4004
4540
|
var _tidyB64 = (s) => s.replace(/[^A-Za-z0-9\+\/]/g, "");
|
|
4005
4541
|
var btoaPolyfill = (bin) => {
|
|
@@ -4063,7 +4599,7 @@ var atobPolyfill = (asc) => {
|
|
|
4063
4599
|
return bin;
|
|
4064
4600
|
};
|
|
4065
4601
|
var _atob = _hasatob ? (asc) => atob(_tidyB64(asc)) : _hasBuffer ? (asc) => Buffer.from(asc, "base64").toString("binary") : atobPolyfill;
|
|
4066
|
-
var _toUint8Array = _hasBuffer ? (a) => _U8Afrom(Buffer.from(a, "base64")) : (a) => _U8Afrom(_atob(a)
|
|
4602
|
+
var _toUint8Array = _hasBuffer ? (a) => _U8Afrom(Buffer.from(a, "base64")) : (a) => _U8Afrom(_atob(a).split("").map((c) => c.charCodeAt(0)));
|
|
4067
4603
|
var toUint8Array = (a) => _toUint8Array(_unURI(a));
|
|
4068
4604
|
var _decode = _hasBuffer ? (a) => Buffer.from(a, "base64").toString("utf8") : _TD ? (a) => _TD.decode(_toUint8Array(a)) : (a) => btou(_atob(a));
|
|
4069
4605
|
var _unURI = (a) => _tidyB64(a.replace(/[-_]/g, (m0) => m0 == "-" ? "+" : "/"));
|
|
@@ -4200,7 +4736,7 @@ var fetcher = async (args) => {
|
|
|
4200
4736
|
transitional: {
|
|
4201
4737
|
clarifyTimeoutError: true
|
|
4202
4738
|
},
|
|
4203
|
-
withCredentials:
|
|
4739
|
+
withCredentials: args.withCredentials
|
|
4204
4740
|
});
|
|
4205
4741
|
let body;
|
|
4206
4742
|
if (response.data != null && response.data.length > 0) {
|
|
@@ -4228,7 +4764,6 @@ var fetcher = async (args) => {
|
|
|
4228
4764
|
error: {
|
|
4229
4765
|
reason: "status-code",
|
|
4230
4766
|
statusCode: response.status,
|
|
4231
|
-
rawBody: response.data,
|
|
4232
4767
|
body
|
|
4233
4768
|
}
|
|
4234
4769
|
};
|