misc sdk changes (#2934)

* misc sdk changes

* delete the store ☠️

* port comments

* fix build

* fix removing

* fix tests

* beta.20

---------

Co-authored-by: Matt Hill <mattnine@protonmail.com>
This commit is contained in:
Aiden McClelland
2025-05-09 15:10:51 -06:00
committed by GitHub
parent d2c4741f0b
commit 7750e33f82
62 changed files with 1255 additions and 2130 deletions

View File

@@ -9,11 +9,10 @@ import {
import { Parser, anyOf, literal, object } from "ts-matches"
export type UnionRes<
Store,
VariantValues extends {
[K in string]: {
name: string
spec: InputSpec<any, Store> | InputSpec<any, never>
spec: InputSpec<any>
}
},
K extends keyof VariantValues & string = keyof VariantValues & string,
@@ -81,23 +80,21 @@ export class Variants<
VariantValues extends {
[K in string]: {
name: string
spec: InputSpec<any, Store> | InputSpec<any, never>
spec: InputSpec<any>
}
},
Store,
> {
private constructor(
public build: LazyBuild<Store, ValueSpecUnion["variants"]>,
public validator: Parser<unknown, UnionRes<Store, VariantValues>>,
public build: LazyBuild<ValueSpecUnion["variants"]>,
public validator: Parser<unknown, UnionRes<VariantValues>>,
) {}
static of<
VariantValues extends {
[K in string]: {
name: string
spec: InputSpec<any, Store> | InputSpec<any, never>
spec: InputSpec<any>
}
},
Store = never,
>(a: VariantValues) {
const validator = anyOf(
...Object.entries(a).map(([id, { spec }]) =>
@@ -108,7 +105,7 @@ export class Variants<
),
) as Parser<unknown, any>
return new Variants<VariantValues, Store>(async (options) => {
return new Variants<VariantValues>(async (options) => {
const variants = {} as {
[K in keyof VariantValues]: {
name: string
@@ -125,21 +122,4 @@ export class Variants<
return variants
}, validator)
}
/**
* Use this during the times that the input needs a more specific type.
* Used in types that the value/ variant/ list/ inputSpec is constructed somewhere else.
```ts
const a = InputSpec.text({
name: "a",
required: false,
})
return InputSpec.of<Store>()({
myValue: a.withStore(),
})
```
*/
withStore<NewStore extends Store extends never ? any : Store>() {
return this as any as Variants<VariantValues, NewStore>
}
}