This repository has been archived by the owner on Sep 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c3183e
commit 2444a64
Showing
12 changed files
with
113 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import * as Z from "../../deps/zones.ts"; | ||
|
||
// TODO: move this into zones | ||
export function option<Target, UseResult>( | ||
target: Target, | ||
use: (resolved: NonNullable<Z.T<Target>>) => UseResult, | ||
): Z.Effect<undefined | Exclude<UseResult, Error>, Z.E<Target> | Extract<UseResult, Error>> { | ||
return Z.call(target, (resolved) => { | ||
return resolved ? use(resolved) : undefined; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as $ from "../../deps/scale.ts"; | ||
import * as Z from "../../deps/zones.ts"; | ||
|
||
export function decoded< | ||
Codec extends Z.$<$.Codec<unknown>>, | ||
Encoded extends Z.$<Uint8Array>, | ||
Key extends Z.$<PropertyKey>, | ||
>( | ||
codec: Codec, | ||
encoded: Encoded, | ||
key: Key, | ||
) { | ||
return Z.call( | ||
Z.ls(codec, encoded, key), | ||
function decodedImpl([codec, encoded, key]): Record<Z.T<Key>, any> { | ||
return { [key]: codec.decode(encoded) } as any; | ||
}, | ||
); | ||
} | ||
|
||
// TODO: eventually, utilize `V` to toggle runtime validation | ||
export function encoded<Codec extends Z.$<$.Codec<any>>, Decoded>( | ||
codec: Codec, | ||
decoded: Decoded, | ||
isAsync?: boolean, | ||
) { | ||
return Z.call(Z.ls(codec, decoded, isAsync), function encodedImpl([codec, decoded]) { | ||
try { | ||
$.assert(codec, decoded); | ||
} catch (e) { | ||
return e as $.ScaleAssertError; | ||
} | ||
return codec[isAsync ? "encodeAsync" : "encode"](decoded); | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters