Skip to content

Commit

Permalink
docs: restructure docs layout, add additional content (#1207)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssalbdivad authored Nov 19, 2024
1 parent 1b395f3 commit fa2d2d6
Show file tree
Hide file tree
Showing 48 changed files with 1,423 additions and 612 deletions.
4 changes: 2 additions & 2 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github: [arktypeio]
drips:
ethereum:
ownedBy: "0xD5c5Fe5DF95adf8DA1Ae640fCAE8f72795657fa5"
ethereum:
ownedBy: "0xD5c5Fe5DF95adf8DA1Ae640fCAE8f72795657fa5"
15 changes: 6 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,12 @@ In the meantime, check out the examples here and use the type hints you get to l
ArkType can easily be used with tRPC via the `assert` prop:

```ts
...
t.procedure
.input(
type({
name: "string",
"age?": "number"
}).assert
)
...
t.procedure.input(
type({
name: "string",
"age?": "number"
}).assert
)
```

## How?
Expand Down
20 changes: 16 additions & 4 deletions ark/attest/__tests__/unwrap.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
import { attest, contextualize } from "@ark/attest"
import type { Completions } from "@ark/attest/internal/cache/writeAssertionCache.js"
import type { autocomplete } from "@ark/util"

contextualize(() => {
it("unwraps unversioned", () => {
attest(attest({ foo: "bar" }).unwrap()).equals({
const unwrapped = attest({ foo: "bar" }).unwrap()
attest<{ foo: string }>(unwrapped).equals({
foo: "bar"
})
})

it("unwraps serialized", () => {
attest(
attest({ foo: Symbol("unwrappedSymbol") }).unwrap({ serialize: true })
).snap({ foo: "Symbol(unwrappedSymbol)" })
const unwrapped = attest({ foo: Symbol("unwrappedSymbol") }).unwrap({
serialize: true
})
attest(unwrapped).snap({ foo: "Symbol(unwrappedSymbol)" })
})

it("unwraps completions", () => {
const unwrapped = attest({ foo: "b" } satisfies {
foo: autocomplete<"bar">
}).completions.unwrap()

attest<Completions>(unwrapped).snap({ b: ["bar"] })
})
})
19 changes: 15 additions & 4 deletions ark/attest/assert/chainableAssertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ export class ChainableAssertions implements AssertionRecord {

return this
}
return Object.assign(inline, { toFile })
return Object.assign(inline, {
toFile,
unwrap: this.unwrap.bind(this)
})
}

private immediateOrChained() {
Expand Down Expand Up @@ -314,18 +317,26 @@ type snapProperty<expected, kind extends AssertionKind> = {
id: string,
options?: ExternalSnapshotOptions
) => nextAssertions<kind>
unwrap: Unwrapper<expected>
}

export type Unwrapper<expected = unknown> = (opts?: UnwrapOptions) => expected

export type comparableValueAssertion<expected, kind extends AssertionKind> = {
snap: snapProperty<expected, kind>
equals: (value: expected) => nextAssertions<kind>
instanceOf: (constructor: Constructor) => nextAssertions<kind>
is: (value: expected) => nextAssertions<kind>
completions: (value?: Completions) => void
completions: CompletionsSnap
satisfies: <def>(def: type.validate<def>) => nextAssertions<kind>
// This can be used to assert values without type constraints
unknown: Omit<comparableValueAssertion<unknown, kind>, "unknown">
unwrap: (opts?: UnwrapOptions) => unknown
unwrap: Unwrapper<expected>
}

export interface CompletionsSnap {
(value?: Completions): void
unwrap: Unwrapper<Completions>
}

export type TypeAssertionsRoot = {
Expand All @@ -335,7 +346,7 @@ export type TypeAssertionsRoot = {
export type TypeAssertionProps = {
toString: valueFromTypeAssertion<string | RegExp>
errors: valueFromTypeAssertion<string | RegExp, string>
completions: (value?: Completions) => void
completions: CompletionsSnap
}

export type ExternalSnapshotOptions = {
Expand Down
2 changes: 1 addition & 1 deletion ark/attest/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ark/attest",
"version": "0.27.0",
"version": "0.28.0",
"license": "MIT",
"author": {
"name": "David Blass",
Expand Down
110 changes: 110 additions & 0 deletions ark/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,113 @@
Source code for ArkType's docs at [arktype.io](https://arktype.io)

Built with [Starlight](https://starlight.astro.build/)

# Definitions

- Primitives

- string
- keywords
- Autogenerate from JSDoc
- literals
- patterns
- lengths
- number
- keywords
- Autogenerate from JSDoc
- literals
- ranges
- divisors
- more
- bigint
- boolean
- symbol
- null
- undefined

- Objects

- properties
- required
- optional
- defaultable
- index
- undeclared
- more
- merge
- keyof
- get
- map
- arrays
- lengths
- tuples
- prefix
- optional
- variadic
- postfix
- dates
- keywords
- Autogenerate from JSDoc
- literals
- ranges
- instanceOf
- keywords
- Autogenerate from JSDoc

- Expressions

- intersection
- union
- brand
- narrow
- morph
- more
- unit
- enumerated
- meta
- cast
- parenthetical
- this

# Other stuff

- Types (how you can use existing types)

- Top-level type invocation

- Autogenerate from JSDoc <!-- properties of a Type instance -->

- define <!-- type utilities not attached to a type instance -->
- raw

- Configuration

- errors
- clone
- onUndeclaredKey
- jitless

- Scopes (advanced)

- syntax
- modules
- visibility
- submodules
- thunks

- Generics (advanced)

- keywords
- Autogenerate from JSDoc
- syntax
- hkt (advanced++)

- Integrations

- Standard Schema
- tRPC
- react-hook-form
- hono

- FAQ
- About the project
Loading

0 comments on commit fa2d2d6

Please sign in to comment.