-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: branding, implement standard-schema (#1178)
- Loading branch information
1 parent
0426c67
commit bfbb7ad
Showing
92 changed files
with
1,107 additions
and
571 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@ark/attest", | ||
"version": "0.22.0", | ||
"version": "0.23.0", | ||
"author": { | ||
"name": "David Blass", | ||
"email": "[email protected]", | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@ark/fs", | ||
"version": "0.17.0", | ||
"version": "0.18.0", | ||
"author": { | ||
"name": "David Blass", | ||
"email": "[email protected]", | ||
|
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 |
---|---|---|
@@ -1,14 +1,3 @@ | ||
import { type } from "arktype" | ||
|
||
console.log( | ||
type({ | ||
foo: type("string").pipe(() => 123) | ||
}) | ||
.pipe(c => c) | ||
.to({ | ||
foo: "123" | ||
})({ | ||
foo: "bar" | ||
}) + "" | ||
) | ||
// foo must be 123 (was "bar") | ||
const t = type("string.numeric.parse") |
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
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,39 @@ | ||
/** Subset of types from https://github.com/standard-schema/standard-schema */ | ||
export interface StandardSchema<In, Out> extends StandardSchema.ConstantProps { | ||
readonly "~types": StandardSchema.Types<In, Out> | ||
"~validate": StandardSchema.Validator<Out> | ||
} | ||
|
||
export declare namespace StandardSchema { | ||
export interface ConstantProps { | ||
readonly "~standard": 1 | ||
readonly "~vendor": "arktype" | ||
} | ||
|
||
export interface Types<In, Out> { | ||
input: In | ||
output: Out | ||
} | ||
|
||
export type Validator<Out> = (input: Input) => Result<Out> | ||
|
||
export interface Input { | ||
value: unknown | ||
} | ||
|
||
export type Result<Out> = Success<Out> | Failure | ||
|
||
export interface Success<Out> { | ||
value: Out | ||
issues?: undefined | ||
} | ||
|
||
export interface Failure { | ||
readonly issues: readonly Issue[] | ||
} | ||
|
||
export interface Issue { | ||
readonly message: string | ||
readonly path: readonly PropertyKey[] | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { attest, contextualize } from "@ark/attest" | ||
import { type } from "arktype" | ||
import type { number, string } from "arktype/internal/attributes.ts" | ||
|
||
contextualize(() => { | ||
it("chained", () => { | ||
const t = type("string").brand("foo") | ||
attest(t.t).type.toString.snap('branded<"foo">') | ||
|
||
// no effect at runtime | ||
attest(t.expression).equals("string") | ||
|
||
const out = t("moo") | ||
attest<string.branded<"foo"> | type.errors>(out) | ||
}) | ||
|
||
it("string-embedded", () => { | ||
const t = type("number#cool") | ||
attest(t.t).type.toString.snap('branded<"cool">') | ||
|
||
attest(t.expression).equals("number") | ||
|
||
const out = t(5) | ||
attest<number.branded<"cool"> | type.errors>(out) | ||
}) | ||
|
||
it("brandAttributes", () => { | ||
const unbranded = type({ | ||
age: "number.integer >= 0" | ||
}) | ||
|
||
attest(unbranded.t).type.toString.snap( | ||
"{ age: is<DivisibleBy<1> & AtLeast<0>> }" | ||
) | ||
|
||
const out = unbranded({ age: 5 }) | ||
|
||
attest< | ||
| type.errors | ||
| { | ||
age: number | ||
} | ||
>(out).equals({ age: 5 }) | ||
|
||
const branded = unbranded.brandAttributes() | ||
|
||
attest(branded.t).type.toString.snap( | ||
"{ age: brand<number, DivisibleBy<1> & AtLeast<0>> }" | ||
) | ||
|
||
const brandedOut = branded({ age: 5 }) | ||
|
||
attest(brandedOut).type.toString.snap(` | ArkErrors | ||
| { age: brand<number, DivisibleBy<1> & AtLeast<0>> }`) | ||
|
||
const reunbranded = branded.unbrandAttributes() | ||
|
||
attest(reunbranded.t).type.toString.snap( | ||
"{ age: is<DivisibleBy<1> & AtLeast<0>> }" | ||
) | ||
|
||
attest<typeof unbranded, typeof reunbranded>() | ||
attest(unbranded.json).equals(reunbranded.json) | ||
}) | ||
}) |
Oops, something went wrong.