Comparing version 0.1.0-next.14 to 0.1.0-next.15
@@ -64,6 +64,10 @@ "use strict"; | ||
is: (x) => (0, helpers_1.is)(x, symbol), | ||
decode: (data) => { | ||
decode: (value) => { | ||
if (!v.codec) | ||
throw new Error(`Codec not implemented.`); | ||
return api.create(v.codec.decode(data)); | ||
const data = v.codec.decode(value); | ||
// TODO inspect the value for better rendering. | ||
if (data === null) | ||
throw new Error(`Failed to decode value \`${value}\` into a ${name}.`); | ||
return api.create(data); | ||
}, | ||
@@ -70,0 +74,0 @@ encode: (data) => { |
@@ -45,3 +45,3 @@ /** | ||
export declare type Encoder<V extends StoredVariant> = (decodedData: StoredVariant.GetType<V>) => string; | ||
export declare type Decoder<V extends StoredVariant> = (encodedData: string) => GetConstructorInput<V>; | ||
export declare type Decoder<V extends StoredVariant> = (encodedData: string) => null | GetConstructorInput<V>; | ||
/** | ||
@@ -48,0 +48,0 @@ * The builder API when it is a state of having at least one variant defined. |
@@ -60,6 +60,10 @@ import { Errors } from './Errors'; | ||
is: (x) => is(x, symbol), | ||
decode: (data) => { | ||
decode: (value) => { | ||
if (!v.codec) | ||
throw new Error(`Codec not implemented.`); | ||
return api.create(v.codec.decode(data)); | ||
const data = v.codec.decode(value); | ||
// TODO inspect the value for better rendering. | ||
if (data === null) | ||
throw new Error(`Failed to decode value \`${value}\` into a ${name}.`); | ||
return api.create(data); | ||
}, | ||
@@ -66,0 +70,0 @@ encode: (data) => { |
@@ -45,3 +45,3 @@ /** | ||
export declare type Encoder<V extends StoredVariant> = (decodedData: StoredVariant.GetType<V>) => string; | ||
export declare type Decoder<V extends StoredVariant> = (encodedData: string) => GetConstructorInput<V>; | ||
export declare type Decoder<V extends StoredVariant> = (encodedData: string) => null | GetConstructorInput<V>; | ||
/** | ||
@@ -48,0 +48,0 @@ * The builder API when it is a state of having at least one variant defined. |
{ | ||
"name": "alge", | ||
"version": "0.1.0-next.14", | ||
"version": "0.1.0-next.15", | ||
"repository": "git@github.com:jasonkuhrt/alge.git", | ||
@@ -60,3 +60,3 @@ "author": "Jason Kuhrt", | ||
"dripip": "0.10.0", | ||
"eslint": "8.12.0", | ||
"eslint": "^8.13.0", | ||
"eslint-config-prettier": "8.5.0", | ||
@@ -63,0 +63,0 @@ "eslint-plugin-codegen": "0.16.1", |
@@ -49,3 +49,3 @@ import { Alge } from '.' | ||
encode: (data) => data.m, | ||
decode: (data) => ({ m: data }), | ||
decode: (data) => (data === `m` ? { m: data } : null), | ||
}) | ||
@@ -58,2 +58,5 @@ .done() | ||
expect(A.M.decode(`m`)).toEqual(m) | ||
expect(() => A.M.decode(``)).toThrowErrorMatchingInlineSnapshot( | ||
`"Failed to decode value \`\` into a A."` | ||
) | ||
}) | ||
@@ -60,0 +63,0 @@ it(`cannot define codec multiple times in the chain`, () => { |
@@ -202,5 +202,8 @@ import { CodecParams, Initial, StoredVariant } from './Builder' | ||
is: (x: unknown) => is(x, symbol), | ||
decode: (data: string) => { | ||
decode: (value: string) => { | ||
if (!v.codec) throw new Error(`Codec not implemented.`) | ||
return api.create(v.codec.decode(data)) | ||
const data = v.codec.decode(value) | ||
// TODO inspect the value for better rendering. | ||
if (data === null) throw new Error(`Failed to decode value \`${value}\` into a ${name}.`) | ||
return api.create(data) | ||
}, | ||
@@ -207,0 +210,0 @@ encode: (data: object) => { |
@@ -65,3 +65,3 @@ /** | ||
export type Decoder<V extends StoredVariant> = (encodedData: string) => GetConstructorInput<V> | ||
export type Decoder<V extends StoredVariant> = (encodedData: string) => null | GetConstructorInput<V> | ||
@@ -68,0 +68,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
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
101406
1713