@effect/schema
Advanced tools
Comparing version 0.5.0 to 0.6.0
{ | ||
"name": "@effect/schema", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"license": "MIT", | ||
@@ -10,4 +10,4 @@ "repository": { | ||
"dependencies": { | ||
"@effect/data": "~0.5.0", | ||
"@effect/io": "^0.10.0", | ||
"@effect/data": "^0.6.0", | ||
"@effect/io": "^0.13.0", | ||
"fast-check": "^3.7.1" | ||
@@ -14,0 +14,0 @@ }, |
@@ -335,3 +335,3 @@ /** | ||
*/ | ||
export declare const brand: <B extends string, A>(brand: B, options?: AnnotationOptions<A> | undefined) => <I>(self: Schema<I, A>) => BrandSchema<I, A & Brand<B>>; | ||
export declare const brand: <B extends string | symbol, A>(brand: B, options?: AnnotationOptions<A> | undefined) => <I>(self: Schema<I, A>) => BrandSchema<I, A & Brand<B>>; | ||
/** | ||
@@ -625,3 +625,3 @@ * @category combinators | ||
*/ | ||
export declare const fromBrand: <C extends Brand<string>>(constructor: Brand.Constructor<C>, options?: AnnotationOptions<Brand.Unbranded<C>> | undefined) => <I, A extends Brand.Unbranded<C>>(self: Schema<I, A>) => Schema<I, A & C>; | ||
export declare const fromBrand: <C extends Brand<string | symbol>>(constructor: Brand.Constructor<C>, options?: AnnotationOptions<Brand.Unbranded<C>> | undefined) => <I, A extends Brand.Unbranded<C>>(self: Schema<I, A>) => Schema<I, A & C>; | ||
/** | ||
@@ -628,0 +628,0 @@ * @category constructors |
@@ -1363,31 +1363,51 @@ "use strict"; | ||
const optionsFromOptionals = fields => schema => { | ||
if (AST.isTypeLiteral(schema.ast)) { | ||
const propertySignatures = schema.ast.propertySignatures; | ||
const ast = schema.ast; | ||
if (AST.isTypeLiteral(ast) || AST.isTransform(ast)) { | ||
const ownKeys = I.ownKeys(fields); | ||
const from = AST.createTypeLiteral(propertySignatures.concat(ownKeys.map(key => AST.createPropertySignature(key, AST.createUnion([_undefined.ast, _null.ast, fields[key].ast]), true, true))), schema.ast.indexSignatures); | ||
const to = AST.createTypeLiteral(propertySignatures.concat(ownKeys.map(key => AST.createPropertySignature(key, optionFromSelf(fields[key]).ast, true, true))), schema.ast.indexSignatures); | ||
const out = AST.createTransform(from, to, o => { | ||
const out = { | ||
...o | ||
}; | ||
for (const key of ownKeys) { | ||
out[key] = O.fromNullable(o[key]); | ||
const len = ownKeys.length; | ||
const from = AST.getFrom(schema.ast); | ||
const to = AST.getTo(schema.ast); | ||
if (AST.isTypeLiteral(from) && AST.isTypeLiteral(to)) { | ||
if (from.propertySignatures.some(px => ownKeys.some(name => px.name === name)) || to.propertySignatures.some(px => ownKeys.some(name => px.name === name))) { | ||
throw new Error("`optionsFromOptionals` cannot handle overlapping property signatures"); | ||
} | ||
return PR.success(out); | ||
}, o => { | ||
const out = { | ||
...o | ||
}; | ||
for (const key of ownKeys) { | ||
if (O.isSome(o[key])) { | ||
out[key] = o[key].value; | ||
} else { | ||
delete out[key]; | ||
const decode = AST.isTypeLiteral(ast) ? PR.success : ast.decode; | ||
const encode = AST.isTypeLiteral(ast) ? PR.success : ast.encode; | ||
const from2 = AST.createTypeLiteral(from.propertySignatures.concat(ownKeys.map(key => AST.createPropertySignature(key, fields[key].ast, true, true))), from.indexSignatures); | ||
const to2 = AST.createTypeLiteral(to.propertySignatures.concat(ownKeys.map(key => AST.createPropertySignature(key, optionFromSelf(fields[key]).ast, false, true))), to.indexSignatures); | ||
const out = AST.createTransform(from2, to2, input => { | ||
const o = { | ||
...input | ||
}; | ||
const n = {}; | ||
for (let i = 0; i < len; i++) { | ||
const key = ownKeys[i]; | ||
delete o[key]; | ||
n[key] = O.fromNullable(input[key]); | ||
} | ||
} | ||
return PR.success(out); | ||
}); | ||
return make(out); | ||
return PR.map(decode(o), o => ({ | ||
...o, | ||
...n | ||
})); | ||
}, a => { | ||
const o = { | ||
...a | ||
}; | ||
const n = {}; | ||
for (let i = 0; i < len; i++) { | ||
const key = ownKeys[i]; | ||
delete o[key]; | ||
if (O.isSome(a[key])) { | ||
n[key] = a[key].value; | ||
} | ||
} | ||
return PR.map(encode(o), o => ({ | ||
...o, | ||
...n | ||
})); | ||
}); | ||
return make(out); | ||
} | ||
} | ||
throw new Error("`parseOptional` can only handle type literals"); | ||
throw new Error("`optionsFromOptionals` can only handle type literals or transformations between type literals"); | ||
}; | ||
@@ -1394,0 +1414,0 @@ // --------------------------------------------- |
@@ -573,3 +573,3 @@ /** | ||
*/ | ||
export const brand = <B extends string, A>( | ||
export const brand = <B extends string | symbol, A>( | ||
brand: B, | ||
@@ -1221,3 +1221,3 @@ options?: AnnotationOptions<A> | ||
*/ | ||
export const fromBrand = <C extends Brand<string>>( | ||
export const fromBrand = <C extends Brand<string | symbol>>( | ||
constructor: Brand.Constructor<C>, | ||
@@ -1960,51 +1960,58 @@ options?: AnnotationOptions<Brand.Unbranded<C>> | ||
> => { | ||
if (AST.isTypeLiteral(schema.ast)) { | ||
const propertySignatures = schema.ast.propertySignatures | ||
const ast = schema.ast | ||
if (AST.isTypeLiteral(ast) || AST.isTransform(ast)) { | ||
const ownKeys = I.ownKeys(fields) | ||
const from = AST.createTypeLiteral( | ||
propertySignatures.concat( | ||
ownKeys.map((key) => | ||
AST.createPropertySignature( | ||
key, | ||
AST.createUnion([_undefined.ast, _null.ast, fields[key].ast]), | ||
true, | ||
true | ||
const len = ownKeys.length | ||
const from = AST.getFrom(schema.ast) | ||
const to = AST.getTo(schema.ast) | ||
if (AST.isTypeLiteral(from) && AST.isTypeLiteral(to)) { | ||
if ( | ||
(from.propertySignatures.some((px) => ownKeys.some((name) => px.name === name))) || | ||
(to.propertySignatures.some((px) => ownKeys.some((name) => px.name === name))) | ||
) { | ||
throw new Error("`optionsFromOptionals` cannot handle overlapping property signatures") | ||
} | ||
const decode = AST.isTypeLiteral(ast) ? PR.success : ast.decode | ||
const encode = AST.isTypeLiteral(ast) ? PR.success : ast.encode | ||
const from2 = AST.createTypeLiteral( | ||
from.propertySignatures.concat( | ||
ownKeys.map((key) => AST.createPropertySignature(key, fields[key].ast, true, true)) | ||
), | ||
from.indexSignatures | ||
) | ||
const to2 = AST.createTypeLiteral( | ||
to.propertySignatures.concat( | ||
ownKeys.map((key) => | ||
AST.createPropertySignature(key, optionFromSelf(fields[key]).ast, false, true) | ||
) | ||
) | ||
), | ||
schema.ast.indexSignatures | ||
) | ||
const to = AST.createTypeLiteral( | ||
propertySignatures.concat( | ||
ownKeys.map((key) => | ||
AST.createPropertySignature( | ||
key, | ||
optionFromSelf(fields[key]).ast, | ||
true, | ||
true | ||
) | ||
) | ||
), | ||
schema.ast.indexSignatures | ||
) | ||
const out = AST.createTransform(from, to, (o: any) => { | ||
const out = { ...o } | ||
for (const key of ownKeys) { | ||
out[key] = O.fromNullable(o[key]) | ||
} | ||
return PR.success(out) | ||
}, (o) => { | ||
const out = { ...o } | ||
for (const key of ownKeys) { | ||
if (O.isSome(o[key])) { | ||
out[key] = o[key].value | ||
} else { | ||
delete out[key] | ||
), | ||
to.indexSignatures | ||
) | ||
const out = AST.createTransform(from2, to2, (input) => { | ||
const o = { ...input } | ||
const n: any = {} | ||
for (let i = 0; i < len; i++) { | ||
const key = ownKeys[i] | ||
delete o[key] | ||
n[key] = O.fromNullable(input[key]) | ||
} | ||
} | ||
return PR.success(out) | ||
}) | ||
return make(out) | ||
return PR.map(decode(o), (o) => ({ ...o, ...n })) | ||
}, (a) => { | ||
const o = { ...a } | ||
const n: any = {} | ||
for (let i = 0; i < len; i++) { | ||
const key = ownKeys[i] | ||
delete o[key] | ||
if (O.isSome(a[key])) { | ||
n[key] = a[key].value | ||
} | ||
} | ||
return PR.map(encode(o), (o) => ({ ...o, ...n })) | ||
}) | ||
return make(out) | ||
} | ||
} | ||
throw new Error("`parseOptional` can only handle type literals") | ||
throw new Error( | ||
"`optionsFromOptionals` can only handle type literals or transformations between type literals" | ||
) | ||
} | ||
@@ -2011,0 +2018,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
833154
15915
+ Added@effect/data@0.6.0(transitive)
+ Added@effect/io@0.13.0(transitive)
- Removed@effect/data@0.5.1(transitive)
- Removed@effect/io@0.10.0(transitive)
Updated@effect/data@^0.6.0
Updated@effect/io@^0.13.0