@gaganref/confect-core 10.3.1-fork.9 → 10.3.1-fork.91
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ActionCall.d.ts +18 -0
- package/dist/ActionCall.d.ts.map +1 -0
- package/dist/ActionCall.js +21 -0
- package/dist/ActionCall.js.map +1 -0
- package/dist/App.d.ts +38 -93
- package/dist/App.d.ts.map +1 -1
- package/dist/App.js +30 -38
- package/dist/App.js.map +1 -1
- package/dist/Auth.d.ts +33 -9
- package/dist/Auth.d.ts.map +1 -1
- package/dist/Auth.js +17 -2
- package/dist/Auth.js.map +1 -1
- package/dist/Callback.d.ts +7 -2
- package/dist/Callback.d.ts.map +1 -1
- package/dist/Callback.js +11 -6
- package/dist/Callback.js.map +1 -1
- package/dist/CommitTs.d.ts +18 -0
- package/dist/CommitTs.d.ts.map +1 -0
- package/dist/CommitTs.js +20 -0
- package/dist/CommitTs.js.map +1 -0
- package/dist/Component.d.ts +106 -2
- package/dist/Component.d.ts.map +1 -1
- package/dist/Component.js +44 -18
- package/dist/Component.js.map +1 -1
- package/dist/FunctionSpec.d.ts +361 -2
- package/dist/FunctionSpec.d.ts.map +1 -1
- package/dist/FunctionSpec.js +68 -3
- package/dist/FunctionSpec.js.map +1 -1
- package/dist/GenericId.js +2 -2
- package/dist/GroupSpec.js +1 -1
- package/dist/Http.d.ts +4 -8
- package/dist/Http.d.ts.map +1 -1
- package/dist/Http.js +15 -22
- package/dist/Http.js.map +1 -1
- package/dist/ManifestSection.d.ts +101 -0
- package/dist/ManifestSection.d.ts.map +1 -0
- package/dist/ManifestSection.js +7 -0
- package/dist/ManifestSection.js.map +1 -0
- package/dist/Mount.d.ts +200 -0
- package/dist/Mount.d.ts.map +1 -0
- package/dist/Mount.js +116 -0
- package/dist/Mount.js.map +1 -0
- package/dist/PaginationError.js +1 -1
- package/dist/Profile.d.ts +95 -0
- package/dist/Profile.d.ts.map +1 -0
- package/dist/Profile.js +15 -0
- package/dist/Profile.js.map +1 -0
- package/dist/Ref.d.ts +4 -3
- package/dist/Ref.d.ts.map +1 -1
- package/dist/Ref.js +13 -19
- package/dist/Ref.js.map +1 -1
- package/dist/RefInternal.d.ts +3 -0
- package/dist/RefInternal.d.ts.map +1 -0
- package/dist/RefInternal.js +16 -0
- package/dist/RefInternal.js.map +1 -0
- package/dist/SchemaToValidator.d.ts +20 -6
- package/dist/SchemaToValidator.d.ts.map +1 -1
- package/dist/SchemaToValidator.js +45 -14
- package/dist/SchemaToValidator.js.map +1 -1
- package/dist/SystemFields.js +3 -3
- package/dist/Table.d.ts +48 -9
- package/dist/Table.d.ts.map +1 -1
- package/dist/Table.js +41 -13
- package/dist/Table.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -6
- package/dist/internal/annotations.d.ts +2 -0
- package/dist/internal/annotations.d.ts.map +1 -0
- package/dist/internal/annotations.js +6 -0
- package/dist/internal/annotations.js.map +1 -0
- package/dist/internal/scalarDocs.d.ts +5 -0
- package/dist/internal/scalarDocs.d.ts.map +1 -0
- package/dist/internal/scalarDocs.js +43 -0
- package/dist/internal/scalarDocs.js.map +1 -0
- package/package.json +3 -3
- package/src/ActionCall.ts +25 -0
- package/src/App.ts +45 -136
- package/src/Auth.ts +54 -11
- package/src/Callback.ts +17 -4
- package/src/CommitTs.ts +26 -0
- package/src/Component.ts +204 -11
- package/src/FunctionSpec.ts +562 -5
- package/src/Http.ts +15 -37
- package/src/ManifestSection.ts +108 -0
- package/src/Mount.ts +401 -0
- package/src/Profile.ts +141 -0
- package/src/Ref.ts +19 -26
- package/src/RefInternal.ts +26 -0
- package/src/SchemaToValidator.ts +97 -22
- package/src/Table.ts +157 -23
- package/src/index.ts +5 -0
- package/src/internal/annotations.ts +1 -0
- package/src/internal/scalarDocs.ts +72 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type * as FunctionSpec from "./FunctionSpec.js";
|
|
2
|
+
import type * as MiddlewareSpec from "./MiddlewareSpec.js";
|
|
3
|
+
export interface Data<Value = unknown> {
|
|
4
|
+
readonly format: number;
|
|
5
|
+
readonly functions: Readonly<Record<string, Value>>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The backend codegen generates: the app, or a component under the name its
|
|
9
|
+
* `defineComponent` gives it.
|
|
10
|
+
*/
|
|
11
|
+
export type Target = {
|
|
12
|
+
readonly kind: "app";
|
|
13
|
+
} | {
|
|
14
|
+
readonly kind: "component";
|
|
15
|
+
readonly name: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* What codegen hands a section's `render`: the exports of each `confect/` file
|
|
19
|
+
* it matched, every registered function with the spec file declaring it, each
|
|
20
|
+
* mounted component with the specifier of its definition, every file `match`
|
|
21
|
+
* was offered, the backend it generates and the absolute path of `confect/`.
|
|
22
|
+
*/
|
|
23
|
+
export interface GenerateInput {
|
|
24
|
+
readonly modules: ReadonlyArray<{
|
|
25
|
+
readonly relativePath: string;
|
|
26
|
+
readonly exports: Readonly<Record<string, unknown>>;
|
|
27
|
+
}>;
|
|
28
|
+
readonly functions: ReadonlyArray<{
|
|
29
|
+
readonly path: string;
|
|
30
|
+
readonly source: string;
|
|
31
|
+
}>;
|
|
32
|
+
readonly mounts: ReadonlyArray<{
|
|
33
|
+
readonly name: string;
|
|
34
|
+
readonly definition: string;
|
|
35
|
+
}>;
|
|
36
|
+
readonly files: ReadonlyArray<string>;
|
|
37
|
+
readonly target: Target;
|
|
38
|
+
readonly confectDirectory: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* What codegen hands a section's `verify.check`: the exports of each `confect/`
|
|
42
|
+
* file `verify.match` selected, each mounted component with the specifier of
|
|
43
|
+
* its definition, and the backend it generates.
|
|
44
|
+
*/
|
|
45
|
+
export interface VerifyInput {
|
|
46
|
+
readonly modules: GenerateInput["modules"];
|
|
47
|
+
readonly mounts: GenerateInput["mounts"];
|
|
48
|
+
readonly target: Target;
|
|
49
|
+
}
|
|
50
|
+
export interface Generate {
|
|
51
|
+
readonly file: string;
|
|
52
|
+
match(relativePath: string): boolean;
|
|
53
|
+
render(input: GenerateInput): {
|
|
54
|
+
readonly contents: string;
|
|
55
|
+
readonly errors: ReadonlyArray<string>;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* A check codegen runs once every `_generated` file exists, so the files
|
|
59
|
+
* `match` selects may import this section's file or any other. Codegen fails
|
|
60
|
+
* with each string `check` returns.
|
|
61
|
+
*/
|
|
62
|
+
readonly verify?: {
|
|
63
|
+
match(relativePath: string): boolean;
|
|
64
|
+
check(input: VerifyInput): ReadonlyArray<string>;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* What codegen hands a section's `summarize`: the `confect/` files its
|
|
69
|
+
* `generate` matched, each function's description by path, and the spec file
|
|
70
|
+
* declaring each function by path, relative to `confect/`.
|
|
71
|
+
*/
|
|
72
|
+
export interface SummarizeInput<Value = unknown> {
|
|
73
|
+
readonly modules: GenerateInput["modules"];
|
|
74
|
+
readonly functions: Readonly<Record<string, Value>>;
|
|
75
|
+
readonly sources: Readonly<Record<string, string>>;
|
|
76
|
+
}
|
|
77
|
+
export interface ManifestSection<Value = unknown, Data_ extends {
|
|
78
|
+
readonly format: number;
|
|
79
|
+
} = Data<Value>> {
|
|
80
|
+
readonly owner: string;
|
|
81
|
+
readonly format: number;
|
|
82
|
+
describe(input: {
|
|
83
|
+
readonly path: string;
|
|
84
|
+
readonly spec: FunctionSpec.AnyWithProps;
|
|
85
|
+
readonly middleware: ReadonlyArray<MiddlewareSpec.AnyMiddlewareSpec>;
|
|
86
|
+
}): Value;
|
|
87
|
+
summarize?(input: SummarizeInput<Value>): Data_;
|
|
88
|
+
check?(next: Data_, previous: unknown): {
|
|
89
|
+
readonly errors: ReadonlyArray<string>;
|
|
90
|
+
readonly notes: ReadonlyArray<string>;
|
|
91
|
+
};
|
|
92
|
+
readonly generate?: Generate;
|
|
93
|
+
}
|
|
94
|
+
export type Any = ManifestSection<unknown, {
|
|
95
|
+
readonly format: number;
|
|
96
|
+
}>;
|
|
97
|
+
export interface Entry {
|
|
98
|
+
readonly key: string;
|
|
99
|
+
readonly section: Any;
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=ManifestSection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ManifestSection.d.ts","sourceRoot":"","sources":["../src/ManifestSection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,YAAY,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,KAAK,cAAc,MAAM,qBAAqB,CAAC;AAE3D,MAAM,WAAW,IAAI,CAAC,KAAK,GAAG,OAAO;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;CACrD;AAED;;;GAGG;AACH,MAAM,MAAM,MAAM,GACd;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAA;CAAE,GACxB;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1D;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;QAC9B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;QAC9B,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;KACrD,CAAC,CAAC;IACH,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC;QAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;KACzB,CAAC,CAAC;IACH,QAAQ,CAAC,MAAM,EAAE,a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CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACpD;AAED,MAAM,WAAW,eAAe,CAC9B,KAAK,GAAG,OAAO,EACf,KAAK,SAAS;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,KAAK,CAAC;IAEvD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE;QACd,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC,YAAY,CAAC;QACzC,QAAQ,CAAC,UAAU,EAAE,aAAa,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;KACtE,GAAG,KAAK,CAAC;IACV,SAAS,CAAC,CAAC,KAAK,EAAE,cAAc,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;IAChD,KAAK,CAAC,CACJ,IAAI,EAAE,KAAK,EACX,QAAQ,EAAE,OAAO,GAChB;QACD,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;QACvC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;KACvC,CAAC;IACF,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;CAC9B;AAED,MAAM,MAAM,GAAG,GAAG,eAAe,CAAC,OAAO,EAAE;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAExE,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC;CACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ManifestSection.js","names":[],"sources":["../src/ManifestSection.ts"],"sourcesContent":["import type * as FunctionSpec from \"./FunctionSpec.js\";\nimport type * as MiddlewareSpec from \"./MiddlewareSpec.js\";\n\nexport interface Data<Value = unknown> {\n readonly format: number;\n readonly functions: Readonly<Record<string, Value>>;\n}\n\n/**\n * The backend codegen generates: the app, or a component under the name its\n * `defineComponent` gives it.\n */\nexport type Target =\n | { readonly kind: \"app\" }\n | { readonly kind: \"component\"; readonly name: string };\n\n/**\n * What codegen hands a section's `render`: the exports of each `confect/` file\n * it matched, every registered function with the spec file declaring it, each\n * mounted component with the specifier of its definition, every file `match`\n * was offered, the backend it generates and the absolute path of `confect/`.\n */\nexport interface GenerateInput {\n readonly modules: ReadonlyArray<{\n readonly relativePath: string;\n readonly exports: Readonly<Record<string, unknown>>;\n }>;\n readonly functions: ReadonlyArray<{\n readonly path: string;\n readonly source: string;\n }>;\n readonly mounts: ReadonlyArray<{\n readonly name: string;\n readonly definition: string;\n }>;\n readonly files: ReadonlyArray<string>;\n readonly target: Target;\n readonly confectDirectory: string;\n}\n\n/**\n * What codegen hands a section's `verify.check`: the exports of each `confect/`\n * file `verify.match` selected, each mounted component with the specifier of\n * its definition, and the backend it generates.\n */\nexport interface VerifyInput {\n readonly modules: GenerateInput[\"modules\"];\n readonly mounts: GenerateInput[\"mounts\"];\n readonly target: Target;\n}\n\nexport interface Generate {\n readonly file: string;\n match(relativePath: string): boolean;\n render(input: GenerateInput): {\n readonly contents: string;\n readonly errors: ReadonlyArray<string>;\n };\n /**\n * A check codegen runs once every `_generated` file exists, so the files\n * `match` selects may import this section's file or any other. Codegen fails\n * with each string `check` returns.\n */\n readonly verify?: {\n match(relativePath: string): boolean;\n check(input: VerifyInput): ReadonlyArray<string>;\n };\n}\n\n/**\n * What codegen hands a section's `summarize`: the `confect/` files its\n * `generate` matched, each function's description by path, and the spec file\n * declaring each function by path, relative to `confect/`.\n */\nexport interface SummarizeInput<Value = unknown> {\n readonly modules: GenerateInput[\"modules\"];\n readonly functions: Readonly<Record<string, Value>>;\n readonly sources: Readonly<Record<string, string>>;\n}\n\nexport interface ManifestSection<\n Value = unknown,\n Data_ extends { readonly format: number } = Data<Value>,\n> {\n readonly owner: string;\n readonly format: number;\n describe(input: {\n readonly path: string;\n readonly spec: FunctionSpec.AnyWithProps;\n readonly middleware: ReadonlyArray<MiddlewareSpec.AnyMiddlewareSpec>;\n }): Value;\n summarize?(input: SummarizeInput<Value>): Data_;\n check?(\n next: Data_,\n previous: unknown,\n ): {\n readonly errors: ReadonlyArray<string>;\n readonly notes: ReadonlyArray<string>;\n };\n readonly generate?: Generate;\n}\n\nexport type Any = ManifestSection<unknown, { readonly format: number }>;\n\nexport interface Entry {\n readonly key: string;\n readonly section: Any;\n}\n"],"mappings":""}
|
package/dist/Mount.d.ts
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import * as Context from "effect/Context";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Option from "effect/Option";
|
|
4
|
+
import * as Schema from "effect/Schema";
|
|
5
|
+
import type * as App from "./App.js";
|
|
6
|
+
import * as Callback from "./Callback.js";
|
|
7
|
+
import * as Component from "./Component.js";
|
|
8
|
+
import type * as Env from "./Env.js";
|
|
9
|
+
import type * as GenericId from "./GenericId.js";
|
|
10
|
+
import type * as IdScope from "./IdScope.js";
|
|
11
|
+
import * as Ref from "./Ref.js";
|
|
12
|
+
declare const TypeId = "~@confect/core/Mount";
|
|
13
|
+
type Handle = Ref.AnyConfect & {
|
|
14
|
+
readonly "~@confect/core/Callback/Handle": Callback.Id;
|
|
15
|
+
};
|
|
16
|
+
type ContractOf<H extends Handle> = Callback.Contract<H["~@confect/core/Callback/Handle"], Ref.GetFunctionType<H>, H["args"]["fields"], H["returns"], Extract<NonNullable<H["error"]>, Schema.Top>>;
|
|
17
|
+
/**
|
|
18
|
+
* What a mount passes for `init`'s args: the same shape, with a host ref in
|
|
19
|
+
* each callback slot.
|
|
20
|
+
*/
|
|
21
|
+
type Input<T> = T extends Handle ? Ref.AnyConfect : T extends object ? {
|
|
22
|
+
readonly [K in keyof T]: Input<T[K]>;
|
|
23
|
+
} : T;
|
|
24
|
+
/**
|
|
25
|
+
* `A` when every alternative of `A` fits `T`; otherwise a type that refuses
|
|
26
|
+
* each alternative that does not. A callback slot takes an internal host ref
|
|
27
|
+
* that satisfies the slot's contract. Whether a slot may be left `undefined` is
|
|
28
|
+
* `Input`'s to say.
|
|
29
|
+
*/
|
|
30
|
+
type Check<T, A> = A extends unknown ? Fit<T, A> : never;
|
|
31
|
+
/**
|
|
32
|
+
* Distributes over the members of `T`, so a value is checked against the
|
|
33
|
+
* members whose shape it has and fits when it fits one of them.
|
|
34
|
+
*/
|
|
35
|
+
type Fit<T, A> = T extends Handle ? A extends Ref.AnyConfect ? A & Callback.Check<ContractOf<T>, A> & (Ref.GetFunctionVisibility<A> extends "internal" ? unknown : {
|
|
36
|
+
readonly callbackMustBeInternal: never;
|
|
37
|
+
}) : never : T extends object ? A extends Input<T> ? {
|
|
38
|
+
readonly [K in keyof A]: K extends keyof T ? Check<T[K], A[K]> : never;
|
|
39
|
+
} : never : A extends T ? A : never;
|
|
40
|
+
type ArgsOf<C> = C extends {
|
|
41
|
+
readonly init: infer I extends Component.Init;
|
|
42
|
+
} ? Ref.Args<I> : never;
|
|
43
|
+
/**
|
|
44
|
+
* `[C]`, not a bare `C`, so the conditional is not distributive. A distributive
|
|
45
|
+
* one resolves against `Component.Descriptor` while `C` is inferred, drops `A`
|
|
46
|
+
* from the contextual type, and widens inline literals until `A` falls back to
|
|
47
|
+
* its constraint.
|
|
48
|
+
*/
|
|
49
|
+
type ArgsField<C, A> = [C] extends [
|
|
50
|
+
{
|
|
51
|
+
readonly init: infer I extends Component.Init;
|
|
52
|
+
}
|
|
53
|
+
] ? {
|
|
54
|
+
readonly args: A & NoInfer<Check<Ref.Args<I>, A>>;
|
|
55
|
+
} : {
|
|
56
|
+
readonly args?: never;
|
|
57
|
+
};
|
|
58
|
+
type IsOptional<S> = S extends {
|
|
59
|
+
readonly "~type.optionality": "optional";
|
|
60
|
+
} ? true : false;
|
|
61
|
+
type RequiredKeys<E> = {
|
|
62
|
+
[K in keyof E]: IsOptional<E[K]> extends true ? never : K;
|
|
63
|
+
}[keyof E];
|
|
64
|
+
type SlotValue<S> = Extract<Schema.Schema.Type<S & Schema.Top>, string>;
|
|
65
|
+
/**
|
|
66
|
+
* What one env slot accepts: a constant, or an entry of the host's env whose
|
|
67
|
+
* value fits. A required slot takes only a required entry.
|
|
68
|
+
*/
|
|
69
|
+
type Slot<S> = IsOptional<S> extends true ? SlotValue<S> | undefined | Env.Entry<string, any, SlotValue<S>, boolean> : SlotValue<S> | Env.Entry<string, any, SlotValue<S>, false>;
|
|
70
|
+
type Bindings<E> = {
|
|
71
|
+
readonly [K in RequiredKeys<E>]: Slot<E[K]>;
|
|
72
|
+
} & {
|
|
73
|
+
readonly [K in Exclude<keyof E, RequiredKeys<E>>]?: Slot<E[K]>;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* `B` keeps the bindings as written, so `App.make` can see which backends their
|
|
77
|
+
* entries come from. `[C]` for the reason `ArgsField` gives: a bare `C` widens
|
|
78
|
+
* an inline constant to `string`.
|
|
79
|
+
*/
|
|
80
|
+
type EnvField<C, B> = [C] extends [{
|
|
81
|
+
readonly env: infer E;
|
|
82
|
+
}] ? [RequiredKeys<E>] extends [never] ? {
|
|
83
|
+
readonly env?: B & Bindings<E> & NoExtra<B, E>;
|
|
84
|
+
} : {
|
|
85
|
+
readonly env: B & Bindings<E> & NoExtra<B, E>;
|
|
86
|
+
} : {
|
|
87
|
+
readonly env?: never;
|
|
88
|
+
};
|
|
89
|
+
type NoExtra<B, E> = {
|
|
90
|
+
readonly [K in Exclude<keyof B, keyof E>]: never;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* The client constructor's parameters after the native mount decide whether
|
|
94
|
+
* `options` is absent, optional or required. A client that takes no native
|
|
95
|
+
* mount cannot be mounted. That branch is an object, not `never`, so the
|
|
96
|
+
* literal `name` and `args` beside it keep their types.
|
|
97
|
+
*/
|
|
98
|
+
type OptionsField<C extends Component.Descriptor> = Parameters<C["client"]> extends [unknown, ...infer Rest] ? Rest extends [] ? {
|
|
99
|
+
readonly options?: never;
|
|
100
|
+
} : Rest extends [infer O] ? {
|
|
101
|
+
readonly options: O;
|
|
102
|
+
} : Rest extends [options?: infer O] ? {
|
|
103
|
+
readonly options?: Exclude<O, undefined>;
|
|
104
|
+
} : never : {
|
|
105
|
+
readonly options: never;
|
|
106
|
+
};
|
|
107
|
+
export type Client<C extends Component.Descriptor> = ReturnType<C["client"]>;
|
|
108
|
+
export interface Data<C extends Component.Descriptor = Component.Descriptor> {
|
|
109
|
+
readonly component: C;
|
|
110
|
+
readonly name: string;
|
|
111
|
+
readonly httpPrefix?: App.HttpPrefix;
|
|
112
|
+
readonly env?: Readonly<Record<string, string | Env.AnyEntry | undefined>>;
|
|
113
|
+
readonly args?: unknown;
|
|
114
|
+
readonly options?: unknown;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* What a mount was declared with, as written: its HTTP prefix and env bindings.
|
|
118
|
+
*/
|
|
119
|
+
export interface Declared<P extends App.HttpPrefix | undefined = App.HttpPrefix | undefined, B = unknown> {
|
|
120
|
+
readonly httpPrefix: P;
|
|
121
|
+
readonly env: B;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* A mounted Convex component. Yield it for its client. Its default is the
|
|
125
|
+
* component's client over this mount, and `Effect.provideService` replaces it.
|
|
126
|
+
*/
|
|
127
|
+
export interface Mount<C extends Component.Descriptor, Name extends string, D extends Declared = Declared> extends Context.Reference<Client<C>> {
|
|
128
|
+
readonly [TypeId]: Data<C> & {
|
|
129
|
+
readonly name: Name;
|
|
130
|
+
};
|
|
131
|
+
readonly "~declared"?: D;
|
|
132
|
+
}
|
|
133
|
+
export type Any = Mount<Component.Descriptor, string>;
|
|
134
|
+
export type NameOf<M> = M extends Mount<any, infer N, any> ? N : never;
|
|
135
|
+
type InitArgs<C> = C extends {
|
|
136
|
+
readonly init: infer I extends Component.Init;
|
|
137
|
+
} ? Ref.Args<I> : never;
|
|
138
|
+
type CallbackSlot<C> = {
|
|
139
|
+
[K in keyof InitArgs<C>]-?: NonNullable<InitArgs<C>[K]> extends Handle ? K : never;
|
|
140
|
+
}[keyof InitArgs<C>] & string;
|
|
141
|
+
type SlotArgs<C, K extends PropertyKey> = Extract<NonNullable<InitArgs<C>[K & keyof InitArgs<C>]>, Handle>["args"]["fields"];
|
|
142
|
+
/**
|
|
143
|
+
* `callbackArgs`, on a mount whose descriptor carries its contract.
|
|
144
|
+
*/
|
|
145
|
+
type CallbackArgs<C, Name extends string> = C extends {
|
|
146
|
+
readonly contract: Component.Component<any, infer From, any>;
|
|
147
|
+
} ? {
|
|
148
|
+
/**
|
|
149
|
+
* A callback slot's contract args, with the component's ids typed for
|
|
150
|
+
* this mount, for the host function that answers the callback.
|
|
151
|
+
*/
|
|
152
|
+
readonly callbackArgs: <const K extends CallbackSlot<C>>(slot: K) => GenericId.RebaseSchema<Schema.Struct<SlotArgs<C, K>>, From, Component.MountScope<IdScope.App, Name>>["fields"];
|
|
153
|
+
} : unknown;
|
|
154
|
+
/**
|
|
155
|
+
* Mount a Convex component, as Convex's `app.use` does, in the host's
|
|
156
|
+
* `confect/<mount>.ts`. `args` is typed from the component's `init`, `env` from
|
|
157
|
+
* its env slots, and `options` from its client constructor. A handler reaches
|
|
158
|
+
* the client with `yield* BulkEmail`.
|
|
159
|
+
*
|
|
160
|
+
* ```ts
|
|
161
|
+
* export const BulkEmail = Mount.make(Email, {
|
|
162
|
+
* name: "bulkEmail",
|
|
163
|
+
* httpPrefix: "/bulk-email",
|
|
164
|
+
* env: { RESEND_API_KEY: env.BULK_RESEND_KEY },
|
|
165
|
+
* args: {
|
|
166
|
+
* fromName: "School office",
|
|
167
|
+
* onEvent: refs.internal.circulars.onEmailEvent,
|
|
168
|
+
* },
|
|
169
|
+
* });
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export declare const make: <C extends Component.Descriptor, const Name extends string, const A extends Input<ArgsOf<C>>, const P extends App.HttpPrefix = never, const B = {}>(component: C, options: {
|
|
173
|
+
readonly name: Name;
|
|
174
|
+
readonly httpPrefix?: P;
|
|
175
|
+
} & EnvField<C, B> & ArgsField<C, A> & OptionsField<C>) => Mount<C, Name, Declared<[P] extends [never] ? undefined : P, B>> & CallbackArgs<C, Name>;
|
|
176
|
+
/**
|
|
177
|
+
* What a mount was declared with: its component, name, HTTP prefix, env, args
|
|
178
|
+
* and options.
|
|
179
|
+
*/
|
|
180
|
+
export declare const data: <C extends Component.Descriptor, Name extends string>(mount: Mount<C, Name, Declared>) => Data<C> & {
|
|
181
|
+
readonly name: Name;
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* What a push runs for a mount: its component's `init`, at the mount's
|
|
185
|
+
* component path, with the install args encoded.
|
|
186
|
+
*/
|
|
187
|
+
export interface InitCall {
|
|
188
|
+
readonly componentPath: string;
|
|
189
|
+
readonly functionName: string;
|
|
190
|
+
readonly args: unknown;
|
|
191
|
+
}
|
|
192
|
+
type Create<E, R> = (contract: Callback.Any, ref: Ref.Any) => Effect.Effect<unknown, E, R>;
|
|
193
|
+
/**
|
|
194
|
+
* The `init` call a mount's install args make, with each callback slot's host
|
|
195
|
+
* ref replaced by the handle `create` makes for the slot's contract. None for a
|
|
196
|
+
* component without `init`.
|
|
197
|
+
*/
|
|
198
|
+
export declare const initCall: <E, R>(mount: Any, create: Create<E, R>) => Effect.Effect<Option.Option<InitCall>, E | Schema.SchemaError, R>;
|
|
199
|
+
export {};
|
|
200
|
+
//# sourceMappingURL=Mount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Mount.d.ts","sourceRoot":"","sources":["../src/Mount.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAEx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QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CACxB;AAOD,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,CAClB,QAAQ,EAAE,QAAQ,CAAC,GAAG,EACtB,GAAG,EAAE,GAAG,CAAC,GAAG,KACT,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAwElC;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,CAAC,SACpB,GAAG,UACF,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KACnB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC,CAclE,CAAC"}
|
package/dist/Mount.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { isRef } from "./Ref.js";
|
|
3
|
+
import { CallbackContract } from "./internal/annotations.js";
|
|
4
|
+
import { handle } from "./Callback.js";
|
|
5
|
+
import { bind, schema } from "./Component.js";
|
|
6
|
+
import * as Context from "effect/Context";
|
|
7
|
+
import * as Schema from "effect/Schema";
|
|
8
|
+
import * as Predicate from "effect/Predicate";
|
|
9
|
+
import { componentsGeneric } from "convex/server";
|
|
10
|
+
import * as Effect from "effect/Effect";
|
|
11
|
+
import * as Option from "effect/Option";
|
|
12
|
+
import * as SchemaAST from "effect/SchemaAST";
|
|
13
|
+
//#region src/Mount.ts
|
|
14
|
+
var Mount_exports = /* @__PURE__ */ __exportAll({
|
|
15
|
+
data: () => data,
|
|
16
|
+
initCall: () => initCall,
|
|
17
|
+
make: () => make
|
|
18
|
+
});
|
|
19
|
+
const TypeId = "~@confect/core/Mount";
|
|
20
|
+
/**
|
|
21
|
+
* Mount a Convex component, as Convex's `app.use` does, in the host's
|
|
22
|
+
* `confect/<mount>.ts`. `args` is typed from the component's `init`, `env` from
|
|
23
|
+
* its env slots, and `options` from its client constructor. A handler reaches
|
|
24
|
+
* the client with `yield* BulkEmail`.
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* export const BulkEmail = Mount.make(Email, {
|
|
28
|
+
* name: "bulkEmail",
|
|
29
|
+
* httpPrefix: "/bulk-email",
|
|
30
|
+
* env: { RESEND_API_KEY: env.BULK_RESEND_KEY },
|
|
31
|
+
* args: {
|
|
32
|
+
* fromName: "School office",
|
|
33
|
+
* onEvent: refs.internal.circulars.onEmailEvent,
|
|
34
|
+
* },
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
const make = (component, options) => {
|
|
39
|
+
const data = {
|
|
40
|
+
...options,
|
|
41
|
+
component
|
|
42
|
+
};
|
|
43
|
+
const client = component.client;
|
|
44
|
+
const native = () => componentsGeneric()[data.name];
|
|
45
|
+
const mount = Context.Reference(`mount/${data.name}`, { defaultValue: () => client(native(), data.options) });
|
|
46
|
+
const { contract, init } = component;
|
|
47
|
+
const callbackArgs = (slot) => {
|
|
48
|
+
const field = init.args.fields[slot];
|
|
49
|
+
const callback = SchemaAST.resolveAt(CallbackContract)(Schema.toEncoded(field).ast);
|
|
50
|
+
const bound = bind(contract, native());
|
|
51
|
+
return schema(bound, callback.functionProvenance.args).fields;
|
|
52
|
+
};
|
|
53
|
+
return Object.assign(mount, { [TypeId]: data }, contract === void 0 ? {} : { callbackArgs });
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* What a mount was declared with: its component, name, HTTP prefix, env, args
|
|
57
|
+
* and options.
|
|
58
|
+
*/
|
|
59
|
+
const data = (mount) => mount[TypeId];
|
|
60
|
+
const contractOf = (schema) => SchemaAST.resolveAt(CallbackContract)(Schema.toEncoded(schema).ast);
|
|
61
|
+
const placeholderHandle = (contract) => Schema.decodeEffect(handle(contract))("").pipe(Effect.orDie);
|
|
62
|
+
/**
|
|
63
|
+
* Handles for the union member `value` takes: the first member that fits once
|
|
64
|
+
* its callback slots hold placeholder handles and whose handles `create` makes.
|
|
65
|
+
* A target that satisfies only a later member's contract takes that member.
|
|
66
|
+
*/
|
|
67
|
+
const withMemberHandles = (members, value, create) => {
|
|
68
|
+
const fitting = members.filter((member) => Schema.is(member)(Effect.runSync(withHandles(member, value, placeholderHandle))));
|
|
69
|
+
return fitting.length === 0 ? Effect.succeed(value) : Effect.firstSuccessOf(fitting.map((member) => withHandles(member, value, create)));
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* The schema of each key's value in a struct or a record.
|
|
73
|
+
*/
|
|
74
|
+
const entrySchema = (schema) => {
|
|
75
|
+
if (Predicate.hasProperty(schema, "fields")) {
|
|
76
|
+
const fields = schema.fields;
|
|
77
|
+
return (key) => fields[key];
|
|
78
|
+
}
|
|
79
|
+
if (SchemaAST.isObjects(schema.ast) && Predicate.hasProperty(schema, "value")) return () => schema.value;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Put a handle in each callback slot: a host ref in a field whose schema
|
|
83
|
+
* carries a callback contract, at any depth of struct fields and record values,
|
|
84
|
+
* through `optionalKey`, `optional` and the union member the value takes.
|
|
85
|
+
*/
|
|
86
|
+
const withHandles = (schema, value, create) => {
|
|
87
|
+
const contract = contractOf(schema);
|
|
88
|
+
if (contract !== void 0 && isRef(value)) return create(contract, value);
|
|
89
|
+
if (Predicate.hasProperty(schema, "schema")) return withHandles(schema.schema, value, create);
|
|
90
|
+
if (Predicate.hasProperty(schema, "members") && Array.isArray(schema.members)) return withMemberHandles(schema.members, value, create);
|
|
91
|
+
const at = entrySchema(schema);
|
|
92
|
+
if (at === void 0 || !Predicate.isObject(value)) return Effect.succeed(value);
|
|
93
|
+
return Effect.forEach(Object.entries(value), ([key, field]) => {
|
|
94
|
+
const fieldSchema = at(key);
|
|
95
|
+
return fieldSchema === void 0 ? Effect.succeed([key, field]) : withHandles(fieldSchema, field, create).pipe(Effect.map((resolved) => [key, resolved]));
|
|
96
|
+
}).pipe(Effect.map(Object.fromEntries));
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* The `init` call a mount's install args make, with each callback slot's host
|
|
100
|
+
* ref replaced by the handle `create` makes for the slot's contract. None for a
|
|
101
|
+
* component without `init`.
|
|
102
|
+
*/
|
|
103
|
+
const initCall = (mount, create) => {
|
|
104
|
+
const { component, name, args } = data(mount);
|
|
105
|
+
const init = component.init;
|
|
106
|
+
if (init === void 0) return Effect.succeedNone;
|
|
107
|
+
return withHandles(init.args, args ?? {}, create).pipe(Effect.flatMap(Schema.encodeUnknownEffect(init.args)), Effect.map((encoded) => Option.some({
|
|
108
|
+
componentPath: name,
|
|
109
|
+
functionName: init.convexFunctionName,
|
|
110
|
+
args: encoded
|
|
111
|
+
})));
|
|
112
|
+
};
|
|
113
|
+
//#endregion
|
|
114
|
+
export { Mount_exports, data, initCall, make };
|
|
115
|
+
|
|
116
|
+
//# sourceMappingURL=Mount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Mount.js","names":["Component.bind","Component.schema","Callback.handle","Ref.isRef"],"sources":["../src/Mount.ts"],"sourcesContent":["import { componentsGeneric } from \"convex/server\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Option from \"effect/Option\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Schema from \"effect/Schema\";\nimport * as SchemaAST from \"effect/SchemaAST\";\nimport type * as App from \"./App.js\";\nimport * as Callback from \"./Callback.js\";\nimport * as Component from \"./Component.js\";\nimport type * as Env from \"./Env.js\";\nimport type * as GenericId from \"./GenericId.js\";\nimport type * as IdScope from \"./IdScope.js\";\nimport { CallbackContract } from \"./internal/annotations.js\";\nimport * as Ref from \"./Ref.js\";\n\nconst TypeId = \"~@confect/core/Mount\";\n\ntype Handle = Ref.AnyConfect & {\n readonly \"~@confect/core/Callback/Handle\": Callback.Id;\n};\n\ntype ContractOf<H extends Handle> = Callback.Contract<\n H[\"~@confect/core/Callback/Handle\"],\n Ref.GetFunctionType<H>,\n H[\"args\"][\"fields\"],\n H[\"returns\"],\n Extract<NonNullable<H[\"error\"]>, Schema.Top>\n>;\n\n/**\n * What a mount passes for `init`'s args: the same shape, with a host ref in\n * each callback slot.\n */\ntype Input<T> = T extends Handle\n ? Ref.AnyConfect\n : T extends object\n ? { readonly [K in keyof T]: Input<T[K]> }\n : T;\n\n/**\n * `A` when every alternative of `A` fits `T`; otherwise a type that refuses\n * each alternative that does not. A callback slot takes an internal host ref\n * that satisfies the slot's contract. Whether a slot may be left `undefined` is\n * `Input`'s to say.\n */\ntype Check<T, A> = A extends unknown ? Fit<T, A> : never;\n\n/**\n * Distributes over the members of `T`, so a value is checked against the\n * members whose shape it has and fits when it fits one of them.\n */\ntype Fit<T, A> = T extends Handle\n ? A extends Ref.AnyConfect\n ? A &\n Callback.Check<ContractOf<T>, A> &\n (Ref.GetFunctionVisibility<A> extends \"internal\"\n ? unknown\n : { readonly callbackMustBeInternal: never })\n : never\n : T extends object\n ? A extends Input<T>\n ? {\n readonly [K in keyof A]: K extends keyof T\n ? Check<T[K], A[K]>\n : never;\n }\n : never\n : A extends T\n ? A\n : never;\n\ntype ArgsOf<C> = C extends { readonly init: infer I extends Component.Init }\n ? Ref.Args<I>\n : never;\n\n/**\n * `[C]`, not a bare `C`, so the conditional is not distributive. A distributive\n * one resolves against `Component.Descriptor` while `C` is inferred, drops `A`\n * from the contextual type, and widens inline literals until `A` falls back to\n * its constraint.\n */\ntype ArgsField<C, A> = [C] extends [\n { readonly init: infer I extends Component.Init },\n]\n ? { readonly args: A & NoInfer<Check<Ref.Args<I>, A>> }\n : { readonly args?: never };\n\ntype IsOptional<S> = S extends { readonly \"~type.optionality\": \"optional\" }\n ? true\n : false;\n\ntype RequiredKeys<E> = {\n [K in keyof E]: IsOptional<E[K]> extends true ? never : K;\n}[keyof E];\n\ntype SlotValue<S> = Extract<Schema.Schema.Type<S & Schema.Top>, string>;\n\n/**\n * What one env slot accepts: a constant, or an entry of the host's env whose\n * value fits. A required slot takes only a required entry.\n */\ntype Slot<S> =\n IsOptional<S> extends true\n ? SlotValue<S> | undefined | Env.Entry<string, any, SlotValue<S>, boolean>\n : SlotValue<S> | Env.Entry<string, any, SlotValue<S>, false>;\n\ntype Bindings<E> = { readonly [K in RequiredKeys<E>]: Slot<E[K]> } & {\n readonly [K in Exclude<keyof E, RequiredKeys<E>>]?: Slot<E[K]>;\n};\n\n/**\n * `B` keeps the bindings as written, so `App.make` can see which backends their\n * entries come from. `[C]` for the reason `ArgsField` gives: a bare `C` widens\n * an inline constant to `string`.\n */\ntype EnvField<C, B> = [C] extends [{ readonly env: infer E }]\n ? [RequiredKeys<E>] extends [never]\n ? { readonly env?: B & Bindings<E> & NoExtra<B, E> }\n : { readonly env: B & Bindings<E> & NoExtra<B, E> }\n : { readonly env?: never };\n\ntype NoExtra<B, E> = { readonly [K in Exclude<keyof B, keyof E>]: never };\n\n/**\n * The client constructor's parameters after the native mount decide whether\n * `options` is absent, optional or required. A client that takes no native\n * mount cannot be mounted. That branch is an object, not `never`, so the\n * literal `name` and `args` beside it keep their types.\n */\ntype OptionsField<C extends Component.Descriptor> =\n Parameters<C[\"client\"]> extends [unknown, ...infer Rest]\n ? Rest extends []\n ? { readonly options?: never }\n : Rest extends [infer O]\n ? { readonly options: O }\n : Rest extends [options?: infer O]\n ? { readonly options?: Exclude<O, undefined> }\n : never\n : { readonly options: never };\n\nexport type Client<C extends Component.Descriptor> = ReturnType<C[\"client\"]>;\n\nexport interface Data<C extends Component.Descriptor = Component.Descriptor> {\n readonly component: C;\n readonly name: string;\n readonly httpPrefix?: App.HttpPrefix;\n readonly env?: Readonly<Record<string, string | Env.AnyEntry | undefined>>;\n readonly args?: unknown;\n readonly options?: unknown;\n}\n\n/**\n * What a mount was declared with, as written: its HTTP prefix and env bindings.\n */\nexport interface Declared<\n P extends App.HttpPrefix | undefined = App.HttpPrefix | undefined,\n B = unknown,\n> {\n readonly httpPrefix: P;\n readonly env: B;\n}\n\n/**\n * A mounted Convex component. Yield it for its client. Its default is the\n * component's client over this mount, and `Effect.provideService` replaces it.\n */\nexport interface Mount<\n C extends Component.Descriptor,\n Name extends string,\n D extends Declared = Declared,\n> extends Context.Reference<Client<C>> {\n readonly [TypeId]: Data<C> & { readonly name: Name };\n readonly \"~declared\"?: D;\n}\n\nexport type Any = Mount<Component.Descriptor, string>;\n\nexport type NameOf<M> = M extends Mount<any, infer N, any> ? N : never;\n\ntype InitArgs<C> = C extends { readonly init: infer I extends Component.Init }\n ? Ref.Args<I>\n : never;\n\ntype CallbackSlot<C> = {\n [K in keyof InitArgs<C>]-?: NonNullable<InitArgs<C>[K]> extends Handle\n ? K\n : never;\n}[keyof InitArgs<C>] &\n string;\n\ntype SlotArgs<C, K extends PropertyKey> = Extract<\n NonNullable<InitArgs<C>[K & keyof InitArgs<C>]>,\n Handle\n>[\"args\"][\"fields\"];\n\n/**\n * `callbackArgs`, on a mount whose descriptor carries its contract.\n */\ntype CallbackArgs<C, Name extends string> = C extends {\n readonly contract: Component.Component<any, infer From, any>;\n}\n ? {\n /**\n * A callback slot's contract args, with the component's ids typed for\n * this mount, for the host function that answers the callback.\n */\n readonly callbackArgs: <const K extends CallbackSlot<C>>(\n slot: K,\n ) => GenericId.RebaseSchema<\n Schema.Struct<SlotArgs<C, K>>,\n From,\n Component.MountScope<IdScope.App, Name>\n >[\"fields\"];\n }\n : unknown;\n\n/**\n * Mount a Convex component, as Convex's `app.use` does, in the host's\n * `confect/<mount>.ts`. `args` is typed from the component's `init`, `env` from\n * its env slots, and `options` from its client constructor. A handler reaches\n * the client with `yield* BulkEmail`.\n *\n * ```ts\n * export const BulkEmail = Mount.make(Email, {\n * name: \"bulkEmail\",\n * httpPrefix: \"/bulk-email\",\n * env: { RESEND_API_KEY: env.BULK_RESEND_KEY },\n * args: {\n * fromName: \"School office\",\n * onEvent: refs.internal.circulars.onEmailEvent,\n * },\n * });\n * ```\n */\nexport const make = <\n C extends Component.Descriptor,\n const Name extends string,\n const A extends Input<ArgsOf<C>>,\n const P extends App.HttpPrefix = never,\n const B = {},\n>(\n component: C,\n options: {\n readonly name: Name;\n readonly httpPrefix?: P;\n } & EnvField<C, B> &\n ArgsField<C, A> &\n OptionsField<C>,\n): Mount<C, Name, Declared<[P] extends [never] ? undefined : P, B>> &\n CallbackArgs<C, Name> => {\n const data = { ...(options as object), component } as Data<C> & {\n readonly name: Name;\n };\n // The options were checked against the constructor's parameters above.\n const client = component.client as unknown as (\n native: unknown,\n options?: unknown,\n ) => Client<C>;\n const native = () => componentsGeneric()[data.name];\n const mount = Context.Reference<Client<C>>(`mount/${data.name}`, {\n defaultValue: () => client(native(), data.options),\n });\n const { contract, init } = component;\n const callbackArgs = (slot: string) => {\n const field = init!.args.fields[slot]!;\n const callback = SchemaAST.resolveAt<Callback.Any>(CallbackContract)(\n Schema.toEncoded(field).ast,\n )!;\n const bound = Component.bind(contract!, native() as never);\n return Component.schema(bound, callback.functionProvenance.args).fields;\n };\n return Object.assign(\n mount,\n { [TypeId]: data },\n contract === undefined ? {} : { callbackArgs },\n ) as Mount<C, Name, Declared<[P] extends [never] ? undefined : P, B>> &\n CallbackArgs<C, Name>;\n};\n\n/**\n * What a mount was declared with: its component, name, HTTP prefix, env, args\n * and options.\n */\nexport const data = <C extends Component.Descriptor, Name extends string>(\n mount: Mount<C, Name, Declared>,\n): Data<C> & { readonly name: Name } => mount[TypeId];\n\n/**\n * What a push runs for a mount: its component's `init`, at the mount's\n * component path, with the install args encoded.\n */\nexport interface InitCall {\n readonly componentPath: string;\n readonly functionName: string;\n readonly args: unknown;\n}\n\nconst contractOf = (schema: Schema.Top) =>\n SchemaAST.resolveAt<Callback.Any>(CallbackContract)(\n Schema.toEncoded(schema).ast,\n );\n\ntype Create<E, R> = (\n contract: Callback.Any,\n ref: Ref.Any,\n) => Effect.Effect<unknown, E, R>;\n\nconst placeholderHandle: Create<never, never> = (contract) =>\n Schema.decodeEffect(Callback.handle(contract))(\"\").pipe(Effect.orDie);\n\n/**\n * Handles for the union member `value` takes: the first member that fits once\n * its callback slots hold placeholder handles and whose handles `create` makes.\n * A target that satisfies only a later member's contract takes that member.\n */\nconst withMemberHandles = <E, R>(\n members: ReadonlyArray<Schema.Top>,\n value: unknown,\n create: Create<E, R>,\n): Effect.Effect<unknown, E, R> => {\n const fitting = members.filter((member) =>\n Schema.is(member)(\n Effect.runSync(withHandles(member, value, placeholderHandle)),\n ),\n );\n return fitting.length === 0\n ? Effect.succeed(value)\n : Effect.firstSuccessOf(\n fitting.map((member) => withHandles(member, value, create)),\n );\n};\n\n/**\n * The schema of each key's value in a struct or a record.\n */\nconst entrySchema = (\n schema: Schema.Top,\n): ((key: string) => Schema.Top | undefined) | undefined => {\n if (Predicate.hasProperty(schema, \"fields\")) {\n const fields = schema.fields as Readonly<Record<string, Schema.Top>>;\n return (key) => fields[key];\n }\n if (SchemaAST.isObjects(schema.ast) && Predicate.hasProperty(schema, \"value\"))\n return () => schema.value as Schema.Top;\n return undefined;\n};\n\n/**\n * Put a handle in each callback slot: a host ref in a field whose schema\n * carries a callback contract, at any depth of struct fields and record values,\n * through `optionalKey`, `optional` and the union member the value takes.\n */\nconst withHandles = <E, R>(\n schema: Schema.Top,\n value: unknown,\n create: Create<E, R>,\n): Effect.Effect<unknown, E, R> => {\n const contract = contractOf(schema);\n if (contract !== undefined && Ref.isRef(value))\n return create(contract, value);\n if (Predicate.hasProperty(schema, \"schema\"))\n return withHandles(schema.schema as Schema.Top, value, create);\n if (Predicate.hasProperty(schema, \"members\") && Array.isArray(schema.members))\n return withMemberHandles(schema.members, value, create);\n const at = entrySchema(schema);\n if (at === undefined || !Predicate.isObject(value))\n return Effect.succeed(value);\n return Effect.forEach(Object.entries(value), ([key, field]) => {\n const fieldSchema = at(key);\n return fieldSchema === undefined\n ? Effect.succeed([key, field] as const)\n : withHandles(fieldSchema, field, create).pipe(\n Effect.map((resolved) => [key, resolved] as const),\n );\n }).pipe(Effect.map(Object.fromEntries));\n};\n\n/**\n * The `init` call a mount's install args make, with each callback slot's host\n * ref replaced by the handle `create` makes for the slot's contract. None for a\n * component without `init`.\n */\nexport const initCall = <E, R>(\n mount: Any,\n create: Create<E, R>,\n): Effect.Effect<Option.Option<InitCall>, E | Schema.SchemaError, R> => {\n const { component, name, args } = data(mount);\n const init = component.init;\n if (init === undefined) return Effect.succeedNone;\n return withHandles(init.args, args ?? {}, create).pipe(\n Effect.flatMap(Schema.encodeUnknownEffect(init.args)),\n Effect.map((encoded) =>\n Option.some({\n componentPath: name,\n functionName: init.convexFunctionName,\n args: encoded,\n }),\n ),\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAgBA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;AA2Nf,MAAa,QAOX,WACA,YAOyB;CACzB,MAAM,OAAO;EAAE,GAAI;EAAoB;CAAU;CAIjD,MAAM,SAAS,UAAU;CAIzB,MAAM,eAAe,kBAAkB,CAAC,CAAC,KAAK;CAC9C,MAAM,QAAQ,QAAQ,UAAqB,SAAS,KAAK,QAAQ,EAC/D,oBAAoB,OAAO,OAAO,GAAG,KAAK,OAAO,EACnD,CAAC;CACD,MAAM,EAAE,UAAU,SAAS;CAC3B,MAAM,gBAAgB,SAAiB;EACrC,MAAM,QAAQ,KAAM,KAAK,OAAO;EAChC,MAAM,WAAW,UAAU,UAAwB,gBAAgB,CAAC,CAClE,OAAO,UAAU,KAAK,CAAC,CAAC,GAC1B;EACA,MAAM,QAAQA,KAAe,UAAW,OAAO,CAAU;EACzD,OAAOC,OAAiB,OAAO,SAAS,mBAAmB,IAAI,CAAC,CAAC;CACnE;CACA,OAAO,OAAO,OACZ,OACA,GAAG,SAAS,KAAK,GACjB,aAAa,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa,CAC/C;AAEF;;;;;AAMA,MAAa,QACX,UACsC,MAAM;AAY9C,MAAM,cAAc,WAClB,UAAU,UAAwB,gBAAgB,CAA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,GAAG;EAC1B,OAAO,gBAAgB,KAAA,IACnB,OAAO,QAAQ,CAAC,KAAK,KAAK,CAAU,IACpC,YAAY,aAAa,OAAO,MAAM,CAAC,CAAC,KACtC,OAAO,KAAK,aAAa,CAAC,KAAK,QAAQ,CAAU,CACnD;CACN,CAAC,CAAC,CAAC,KAAK,OAAO,IAAI,OAAO,WAAW,CAAC;AACxC;;;;;;AAOA,MAAa,YACX,OACA,WACsE;CACtE,MAAM,EAAE,WAAW,MAAM,SAAS,KAAK,KAAK;CAC5C,MAAM,OAAO,UAAU;CACvB,IAAI,SAAS,KAAA,GAAW,OAAO,OAAO;CACtC,OAAO,YAAY,KAAK,MAAM,QAAQ,CAAC,GAAG,MAAM,CAAC,CAAC,KAChD,OAAO,QAAQ,OAAO,oBAAoB,KAAK,IAAI,CAAC,GACpD,OAAO,KAAK,YACV,OAAO,KAAK;EACV,eAAe;EACf,cAAc,KAAK;EACnB,MAAM;CACR,CAAC,CACH,CACF;AACF"}
|
package/dist/PaginationError.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
2
|
import * as Schema from "effect/Schema";
|
|
3
|
+
import * as Option from "effect/Option";
|
|
3
4
|
import { ConvexError } from "convex/values";
|
|
4
5
|
import * as Match from "effect/Match";
|
|
5
|
-
import * as Option from "effect/Option";
|
|
6
6
|
//#region src/PaginationError.ts
|
|
7
7
|
var PaginationError_exports = /* @__PURE__ */ __exportAll({
|
|
8
8
|
InvalidCursor: () => InvalidCursor,
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type * as Schema from "effect/Schema";
|
|
2
|
+
import type * as FunctionProvenance from "./FunctionProvenance.js";
|
|
3
|
+
import type * as MiddlewareSpec from "./MiddlewareSpec.js";
|
|
4
|
+
/**
|
|
5
|
+
* A type-level function from a function's name and args fields to the fields a
|
|
6
|
+
* profile's builders require. Read `this["Name"]` and `this["Args"]` directly
|
|
7
|
+
* in `Type`, passing them to a type alias; a nested object type cannot name
|
|
8
|
+
* `this`.
|
|
9
|
+
*/
|
|
10
|
+
export interface Fields {
|
|
11
|
+
readonly Name: string;
|
|
12
|
+
readonly Args: unknown;
|
|
13
|
+
readonly Type: object;
|
|
14
|
+
}
|
|
15
|
+
export interface NoFields extends Fields {
|
|
16
|
+
readonly Type: {};
|
|
17
|
+
}
|
|
18
|
+
export type Apply<Fields_ extends Fields, Name_ extends string, Args_> = (Fields_ & {
|
|
19
|
+
readonly Name: Name_;
|
|
20
|
+
readonly Args: Args_;
|
|
21
|
+
})["Type"];
|
|
22
|
+
/**
|
|
23
|
+
* A base profile's fields and its extension's, for one function.
|
|
24
|
+
*/
|
|
25
|
+
export interface Both<Base extends Fields, Extension extends Fields> extends Fields {
|
|
26
|
+
readonly Type: Apply<Base, this["Name"], this["Args"]> & Apply<Extension, this["Name"], this["Args"]>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* What a profile callback sees. `args` stays a thunk.
|
|
30
|
+
*/
|
|
31
|
+
export interface Info<FieldsType> {
|
|
32
|
+
readonly name: string;
|
|
33
|
+
readonly description?: string;
|
|
34
|
+
readonly args: () => FunctionProvenance.ArgsFields;
|
|
35
|
+
readonly fields: "description" extends keyof FieldsType ? Omit<FieldsType, "description"> : FieldsType;
|
|
36
|
+
}
|
|
37
|
+
export interface Attachment<MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec, FieldsType> {
|
|
38
|
+
readonly spec: MiddlewareSpec_;
|
|
39
|
+
readonly options: (info: Info<FieldsType>) => MiddlewareSpec.Options<MiddlewareSpec_>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A middleware without options has none to compute and is attached at most
|
|
43
|
+
* once, so it joins a profile's list directly.
|
|
44
|
+
*/
|
|
45
|
+
type TakesOptions<MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec> = [
|
|
46
|
+
MiddlewareSpec.WithoutOptions<MiddlewareSpec_>
|
|
47
|
+
] extends [never] ? unknown : MiddlewareSpec.AttachmentError<`Middleware "${MiddlewareSpec.Key<MiddlewareSpec_>}" takes no options, so list it without Profile.attach`>;
|
|
48
|
+
/**
|
|
49
|
+
* Attach a middleware that takes options to every function a profile builds,
|
|
50
|
+
* with options computed from each function's fields.
|
|
51
|
+
*/
|
|
52
|
+
export declare const attach: <MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec, FieldsType>(spec: MiddlewareSpec_ & TakesOptions<MiddlewareSpec_>, options: (info: Info<FieldsType>) => MiddlewareSpec.Options<NoInfer<MiddlewareSpec_>>) => Attachment<MiddlewareSpec_, FieldsType>;
|
|
53
|
+
/**
|
|
54
|
+
* A type function for a schema wrapper, applied to each declared codec.
|
|
55
|
+
*/
|
|
56
|
+
export interface SchemaTransform {
|
|
57
|
+
readonly Input: Schema.Codec<unknown, unknown>;
|
|
58
|
+
readonly Type: Schema.Codec<any, any>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Args wrappers transform the declared field map, before Struct composition.
|
|
62
|
+
*/
|
|
63
|
+
export interface ArgsTransform {
|
|
64
|
+
readonly Input: unknown;
|
|
65
|
+
readonly Type: FunctionProvenance.ArgsFields;
|
|
66
|
+
}
|
|
67
|
+
export interface Transforms {
|
|
68
|
+
readonly args?: ArgsTransform;
|
|
69
|
+
readonly returns?: SchemaTransform;
|
|
70
|
+
readonly item?: SchemaTransform;
|
|
71
|
+
readonly error?: SchemaTransform;
|
|
72
|
+
}
|
|
73
|
+
export type Transform<T, Input> = (T & {
|
|
74
|
+
readonly Input: Input;
|
|
75
|
+
})["Type" & keyof T];
|
|
76
|
+
/**
|
|
77
|
+
* Error wrappers opt into Schema.Never when no error thunk was declared.
|
|
78
|
+
*/
|
|
79
|
+
export type Wrappers<T extends Transforms, FieldsType> = {
|
|
80
|
+
readonly [K in keyof T]-?: K extends keyof Transforms ? <Input extends (K extends "args" ? FunctionProvenance.ArgsFields : Schema.Codec<any, any>)>(thunk: () => Input, info: Info<FieldsType>) => () => Transform<T[K], Input> : never;
|
|
81
|
+
} & {
|
|
82
|
+
readonly [K in Exclude<keyof Transforms, keyof T>]?: never;
|
|
83
|
+
};
|
|
84
|
+
type NonemptyError<T extends Transforms> = T extends {
|
|
85
|
+
readonly error: infer E extends SchemaTransform;
|
|
86
|
+
} ? [Transform<E, typeof Schema.Never>["Type"]] extends [never] ? MiddlewareSpec.AttachmentError<"Profile error wrapper must add an error to Schema.Never"> : unknown : unknown;
|
|
87
|
+
export type SchemaConfig<T extends Transforms, FieldsType> = ([
|
|
88
|
+
keyof T
|
|
89
|
+
] extends [never] ? {
|
|
90
|
+
readonly schemas?: never;
|
|
91
|
+
} : {
|
|
92
|
+
readonly schemas: Wrappers<T, FieldsType>;
|
|
93
|
+
}) & NonemptyError<T>;
|
|
94
|
+
export {};
|
|
95
|
+
//# sourceMappingURL=Profile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Profile.d.ts","sourceRoot":"","sources":["../src/Profile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,KAAK,kBAAkB,MAAM,yBAAyB,CAAC;AACnE,OAAO,KAAK,KAAK,cAAc,MAAM,qBAAqB,CAAC;AAE3D;;;;;GAKG;AACH,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAGtB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,QAAS,SAAQ,MAAM;IACtC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC;CACnB;AAED,MAAM,MAAM,KAAK,CACf,OAAO,SAAS,MAAM,EACtB,KAAK,SAAS,MAAM,EACpB,KAAK,IACH,CAAC,OAAO,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IA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CAAC,SAAS,MAAM,GAC3B,kBAAkB,CAAC,UAAU,GAC7B,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,EAE3B,KAAK,EAAE,MAAM,KAAK,EAClB,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,KACnB,MAAM,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,GACjC,KAAK;CACV,GAAG;IAAE,QAAQ,EAAE,CAAC,IAAI,OAAO,CAAC,MAAM,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK;CAAE,CAAC;AAEnE,KAAK,aAAa,CAAC,CAAC,SAAS,UAAU,IAAI,CAAC,SAAS;IACnD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,SAAS,eAAe,CAAC;CACjD,GACG,CAAC,SAAS,CAAC,CAAC,EAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACzD,cAAc,CAAC,eAAe,CAAC,yDAAyD,CAAC,GACzF,OAAO,GACT,OAAO,CAAC;AAEZ,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,UAAU,EAAE,UAAU,IAAI,CAAC;IAC5D,MAAM,CAAC;CACR,SAAS,CAAC,KAAK,CAAC,GACb;IAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,KAAK,CAAA;CAAE,GAC5B;IAAE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,EAAE,UAAU,CAAC,CAAA;CAAE,CAAC,GAChD,aAAa,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/Profile.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
//#region src/Profile.ts
|
|
3
|
+
var Profile_exports = /* @__PURE__ */ __exportAll({ attach: () => attach });
|
|
4
|
+
/**
|
|
5
|
+
* Attach a middleware that takes options to every function a profile builds,
|
|
6
|
+
* with options computed from each function's fields.
|
|
7
|
+
*/
|
|
8
|
+
const attach = (spec, options) => ({
|
|
9
|
+
spec,
|
|
10
|
+
options
|
|
11
|
+
});
|
|
12
|
+
//#endregion
|
|
13
|
+
export { Profile_exports, attach };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=Profile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Profile.js","names":[],"sources":["../src/Profile.ts"],"sourcesContent":["import type * as Schema from \"effect/Schema\";\nimport type * as FunctionProvenance from \"./FunctionProvenance.js\";\nimport type * as MiddlewareSpec from \"./MiddlewareSpec.js\";\n\n/**\n * A type-level function from a function's name and args fields to the fields a\n * profile's builders require. Read `this[\"Name\"]` and `this[\"Args\"]` directly\n * in `Type`, passing them to a type alias; a nested object type cannot name\n * `this`.\n */\nexport interface Fields {\n readonly Name: string;\n // `unknown`, not `ArgsFields`: an index signature here would leak into\n // `keyof this[\"Args\"]`.\n readonly Args: unknown;\n readonly Type: object;\n}\n\nexport interface NoFields extends Fields {\n readonly Type: {};\n}\n\nexport type Apply<\n Fields_ extends Fields,\n Name_ extends string,\n Args_,\n> = (Fields_ & { readonly Name: Name_; readonly Args: Args_ })[\"Type\"];\n\n/**\n * A base profile's fields and its extension's, for one function.\n */\nexport interface Both<\n Base extends Fields,\n Extension extends Fields,\n> extends Fields {\n readonly Type: Apply<Base, this[\"Name\"], this[\"Args\"]> &\n Apply<Extension, this[\"Name\"], this[\"Args\"]>;\n}\n\n/**\n * What a profile callback sees. `args` stays a thunk.\n */\nexport interface Info<FieldsType> {\n readonly name: string;\n readonly description?: string;\n readonly args: () => FunctionProvenance.ArgsFields;\n readonly fields: \"description\" extends keyof FieldsType\n ? Omit<FieldsType, \"description\">\n : FieldsType;\n}\n\nexport interface Attachment<\n MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec,\n FieldsType,\n> {\n readonly spec: MiddlewareSpec_;\n readonly options: (\n info: Info<FieldsType>,\n ) => MiddlewareSpec.Options<MiddlewareSpec_>;\n}\n\n/**\n * A middleware without options has none to compute and is attached at most\n * once, so it joins a profile's list directly.\n */\ntype TakesOptions<MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec> = [\n MiddlewareSpec.WithoutOptions<MiddlewareSpec_>,\n] extends [never]\n ? unknown\n : MiddlewareSpec.AttachmentError<`Middleware \"${MiddlewareSpec.Key<MiddlewareSpec_>}\" takes no options, so list it without Profile.attach`>;\n\n/**\n * Attach a middleware that takes options to every function a profile builds,\n * with options computed from each function's fields.\n */\nexport const attach = <\n MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec,\n FieldsType,\n>(\n spec: MiddlewareSpec_ & TakesOptions<MiddlewareSpec_>,\n options: (\n info: Info<FieldsType>,\n ) => MiddlewareSpec.Options<NoInfer<MiddlewareSpec_>>,\n): Attachment<MiddlewareSpec_, FieldsType> => ({ spec, options });\n\n/**\n * A type function for a schema wrapper, applied to each declared codec.\n */\nexport interface SchemaTransform {\n readonly Input: Schema.Codec<unknown, unknown>;\n readonly Type: Schema.Codec<any, any>;\n}\n\n/**\n * Args wrappers transform the declared field map, before Struct composition.\n */\nexport interface ArgsTransform {\n readonly Input: unknown;\n readonly Type: FunctionProvenance.ArgsFields;\n}\n\nexport interface Transforms {\n readonly args?: ArgsTransform;\n readonly returns?: SchemaTransform;\n readonly item?: SchemaTransform;\n readonly error?: SchemaTransform;\n}\n\nexport type Transform<T, Input> = (T & { readonly Input: Input })[\"Type\" &\n keyof T];\n\n/**\n * Error wrappers opt into Schema.Never when no error thunk was declared.\n */\nexport type Wrappers<T extends Transforms, FieldsType> = {\n readonly [K in keyof T]-?: K extends keyof Transforms\n ? <\n Input extends (K extends \"args\"\n ? FunctionProvenance.ArgsFields\n : Schema.Codec<any, any>),\n >(\n thunk: () => Input,\n info: Info<FieldsType>,\n ) => () => Transform<T[K], Input>\n : never;\n} & { readonly [K in Exclude<keyof Transforms, keyof T>]?: never };\n\ntype NonemptyError<T extends Transforms> = T extends {\n readonly error: infer E extends SchemaTransform;\n}\n ? [Transform<E, typeof Schema.Never>[\"Type\"]] extends [never]\n ? MiddlewareSpec.AttachmentError<\"Profile error wrapper must add an error to Schema.Never\">\n : unknown\n : unknown;\n\nexport type SchemaConfig<T extends Transforms, FieldsType> = ([\n keyof T,\n] extends [never]\n ? { readonly schemas?: never }\n : { readonly schemas: Wrappers<T, FieldsType> }) &\n NonemptyError<T>;\n"],"mappings":";;;;;;;AA2EA,MAAa,UAIX,MACA,aAG6C;CAAE;CAAM;AAAQ"}
|