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