@gaganref/confect-core 10.3.1-fork.77 → 10.3.1-fork.78
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/Component.js +2 -2
- package/dist/GenericId.js +2 -2
- package/dist/Mount.d.ts +20 -2
- package/dist/Mount.d.ts.map +1 -1
- package/dist/Mount.js +61 -2
- package/dist/Mount.js.map +1 -1
- package/dist/PaginationError.js +1 -1
- package/dist/Ref.js +2 -2
- package/dist/Refs.js +1 -1
- package/dist/SchemaToValidator.js +5 -5
- package/dist/SystemFields.js +3 -3
- package/dist/index.js +2 -2
- package/package.json +1 -1
- package/src/Mount.ts +119 -2
package/dist/Component.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { defineProperty } from "./Lazy.js";
|
|
3
|
+
import { fromProvenance, isRef, make as make$1 } from "./Ref.js";
|
|
3
4
|
import { app, instance } from "./IdScope.js";
|
|
4
5
|
import { GenericId, rebase } from "./GenericId.js";
|
|
5
|
-
import { fromProvenance, isRef, make as make$1 } from "./Ref.js";
|
|
6
6
|
import { groups as groups$1 } from "./Spec.js";
|
|
7
7
|
import * as Schema from "effect/Schema";
|
|
8
8
|
import * as Data from "effect/Data";
|
|
9
9
|
import { getFunctionAddress } from "convex/server";
|
|
10
|
+
import * as Match from "effect/Match";
|
|
10
11
|
import * as Array from "effect/Array";
|
|
11
12
|
import * as Result from "effect/Result";
|
|
12
13
|
import { memoize, pipe } from "effect/Function";
|
|
13
|
-
import * as Match from "effect/Match";
|
|
14
14
|
import * as Record from "effect/Record";
|
|
15
15
|
//#region src/Component.ts
|
|
16
16
|
var Component_exports = /* @__PURE__ */ __exportAll({
|
package/dist/GenericId.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { app } from "./IdScope.js";
|
|
3
3
|
import * as Schema from "effect/Schema";
|
|
4
|
+
import * as Option from "effect/Option";
|
|
4
5
|
import * as SchemaAST from "effect/SchemaAST";
|
|
6
|
+
import * as Match from "effect/Match";
|
|
5
7
|
import * as Array from "effect/Array";
|
|
6
8
|
import { memoize } from "effect/Function";
|
|
7
|
-
import * as Match from "effect/Match";
|
|
8
|
-
import * as Option from "effect/Option";
|
|
9
9
|
//#region src/GenericId.ts
|
|
10
10
|
var GenericId_exports = /* @__PURE__ */ __exportAll({
|
|
11
11
|
GenericId: () => GenericId,
|
package/dist/Mount.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import * as Context from "effect/Context";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Option from "effect/Option";
|
|
2
4
|
import * as Schema from "effect/Schema";
|
|
3
5
|
import type * as App from "./App.js";
|
|
4
|
-
import
|
|
6
|
+
import * as Callback from "./Callback.js";
|
|
5
7
|
import * as Component from "./Component.js";
|
|
6
8
|
import type * as Env from "./Env.js";
|
|
7
9
|
import type * as GenericId from "./GenericId.js";
|
|
8
10
|
import type * as IdScope from "./IdScope.js";
|
|
9
|
-
import
|
|
11
|
+
import * as Ref from "./Ref.js";
|
|
10
12
|
declare const TypeId = "~@confect/core/Mount";
|
|
11
13
|
type Handle = Ref.AnyConfect & {
|
|
12
14
|
readonly "~@confect/core/Callback/Handle": Callback.Id;
|
|
@@ -178,5 +180,21 @@ export declare const make: <C extends Component.Descriptor, const Name extends s
|
|
|
178
180
|
export declare const data: <C extends Component.Descriptor, Name extends string>(mount: Mount<C, Name, Declared>) => Data<C> & {
|
|
179
181
|
readonly name: Name;
|
|
180
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>;
|
|
181
199
|
export {};
|
|
182
200
|
//# sourceMappingURL=Mount.d.ts.map
|
package/dist/Mount.d.ts.map
CHANGED
|
@@ -1 +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;AAExC,OAAO,KAAK,KAAK,GAAG,MAAM,UAAU,CAAC;AACrC,OAAO,KAAK,
|
|
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;AAExC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,KAAK,GAAG,MAAM,UAAU,CAAC;AACrC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,KAAK,GAAG,MAAM,UAAU,CAAC;AACrC,OAAO,KAAK,KAAK,SAAS,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,KAAK,OAAO,MAAM,cAAc,CAAC;AAE7C,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AA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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
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
-
import {
|
|
2
|
+
import { isRef } from "./Ref.js";
|
|
3
3
|
import { CallbackContract } from "./internal/annotations.js";
|
|
4
|
+
import { handle } from "./Callback.js";
|
|
5
|
+
import { bind, schema } from "./Component.js";
|
|
4
6
|
import * as Context from "effect/Context";
|
|
5
7
|
import * as Schema from "effect/Schema";
|
|
8
|
+
import * as Predicate from "effect/Predicate";
|
|
6
9
|
import { componentsGeneric } from "convex/server";
|
|
10
|
+
import * as Effect from "effect/Effect";
|
|
11
|
+
import * as Option from "effect/Option";
|
|
7
12
|
import * as SchemaAST from "effect/SchemaAST";
|
|
8
13
|
//#region src/Mount.ts
|
|
9
14
|
var Mount_exports = /* @__PURE__ */ __exportAll({
|
|
10
15
|
data: () => data,
|
|
16
|
+
initCall: () => initCall,
|
|
11
17
|
make: () => make
|
|
12
18
|
});
|
|
13
19
|
const TypeId = "~@confect/core/Mount";
|
|
@@ -51,7 +57,60 @@ const make = (component, options) => {
|
|
|
51
57
|
* and options.
|
|
52
58
|
*/
|
|
53
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
|
+
};
|
|
54
113
|
//#endregion
|
|
55
|
-
export { Mount_exports, data, make };
|
|
114
|
+
export { Mount_exports, data, initCall, make };
|
|
56
115
|
|
|
57
116
|
//# sourceMappingURL=Mount.js.map
|
package/dist/Mount.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Mount.js","names":["Component.bind","Component.schema"],"sources":["../src/Mount.ts"],"sourcesContent":["import { componentsGeneric } from \"convex/server\";\nimport * as Context from \"effect/Context\";\nimport * as Schema from \"effect/Schema\";\nimport * as SchemaAST from \"effect/SchemaAST\";\nimport type * as App from \"./App.js\";\nimport type * 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 type * 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"],"mappings":";;;;;;;;;;;;AAaA,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"}
|
|
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 );\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AAM,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 Match from "effect/Match";
|
|
4
3
|
import * as Option from "effect/Option";
|
|
5
4
|
import { ConvexError } from "convex/values";
|
|
5
|
+
import * as Match from "effect/Match";
|
|
6
6
|
//#region src/PaginationError.ts
|
|
7
7
|
var PaginationError_exports = /* @__PURE__ */ __exportAll({
|
|
8
8
|
InvalidCursor: () => InvalidCursor,
|
package/dist/Ref.js
CHANGED
|
@@ -5,10 +5,10 @@ import { getFunctionReference } from "./RefInternal.js";
|
|
|
5
5
|
import * as Schema from "effect/Schema";
|
|
6
6
|
import * as Predicate from "effect/Predicate";
|
|
7
7
|
import { getFunctionAddress } from "convex/server";
|
|
8
|
-
import * as
|
|
8
|
+
import * as Effect from "effect/Effect";
|
|
9
9
|
import * as Option from "effect/Option";
|
|
10
10
|
import { ConvexError } from "convex/values";
|
|
11
|
-
import * as
|
|
11
|
+
import * as Match from "effect/Match";
|
|
12
12
|
//#region src/Ref.ts
|
|
13
13
|
var Ref_exports = /* @__PURE__ */ __exportAll({
|
|
14
14
|
TypeId: () => TypeId,
|
package/dist/Refs.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { getConvexFunctionName, make as make$1 } from "./Ref.js";
|
|
3
3
|
import { groups } from "./Spec.js";
|
|
4
|
+
import * as Option from "effect/Option";
|
|
4
5
|
import { pipe } from "effect/Function";
|
|
5
6
|
import * as Record from "effect/Record";
|
|
6
|
-
import * as Option from "effect/Option";
|
|
7
7
|
//#region src/Refs.ts
|
|
8
8
|
var Refs_exports = /* @__PURE__ */ __exportAll({ make: () => make });
|
|
9
9
|
const make = (spec) => {
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { CallbackContract } from "./internal/annotations.js";
|
|
2
3
|
import { app } from "./IdScope.js";
|
|
3
4
|
import { scope, tableName } from "./GenericId.js";
|
|
4
|
-
import { CallbackContract } from "./internal/annotations.js";
|
|
5
5
|
import * as Schema from "effect/Schema";
|
|
6
6
|
import * as Predicate from "effect/Predicate";
|
|
7
7
|
import * as Data from "effect/Data";
|
|
8
|
+
import * as Effect from "effect/Effect";
|
|
9
|
+
import * as Option from "effect/Option";
|
|
8
10
|
import * as SchemaAST from "effect/SchemaAST";
|
|
11
|
+
import { v } from "convex/values";
|
|
12
|
+
import * as Match from "effect/Match";
|
|
9
13
|
import * as Array from "effect/Array";
|
|
10
14
|
import { pipe } from "effect/Function";
|
|
11
|
-
import * as Match from "effect/Match";
|
|
12
|
-
import * as Option from "effect/Option";
|
|
13
|
-
import { v } from "convex/values";
|
|
14
|
-
import * as Effect from "effect/Effect";
|
|
15
15
|
import * as Number from "effect/Number";
|
|
16
16
|
import * as String from "effect/String";
|
|
17
17
|
//#region src/SchemaToValidator.ts
|
package/dist/SystemFields.js
CHANGED
|
@@ -2,13 +2,13 @@ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
|
2
2
|
import { GenericId } from "./GenericId.js";
|
|
3
3
|
import * as Schema from "effect/Schema";
|
|
4
4
|
import * as Predicate from "effect/Predicate";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Option from "effect/Option";
|
|
5
7
|
import * as SchemaAST from "effect/SchemaAST";
|
|
8
|
+
import * as SchemaGetter from "effect/SchemaGetter";
|
|
6
9
|
import * as Array from "effect/Array";
|
|
7
10
|
import { pipe } from "effect/Function";
|
|
8
11
|
import * as Record from "effect/Record";
|
|
9
|
-
import * as Option from "effect/Option";
|
|
10
|
-
import * as Effect from "effect/Effect";
|
|
11
|
-
import * as SchemaGetter from "effect/SchemaGetter";
|
|
12
12
|
import * as SchemaTransformation from "effect/SchemaTransformation";
|
|
13
13
|
import * as Struct from "effect/Struct";
|
|
14
14
|
//#region src/SystemFields.ts
|
package/dist/index.js
CHANGED
|
@@ -7,9 +7,10 @@ import { MiddlewareSpec_exports } from "./MiddlewareSpec.js";
|
|
|
7
7
|
import { RuntimeAndFunctionType_exports } from "./RuntimeAndFunctionType.js";
|
|
8
8
|
import { FunctionSpec_exports } from "./FunctionSpec.js";
|
|
9
9
|
import { ActionCall_exports } from "./ActionCall.js";
|
|
10
|
+
import { Ref_exports } from "./Ref.js";
|
|
11
|
+
import { Callback_exports } from "./Callback.js";
|
|
10
12
|
import { IdScope_exports } from "./IdScope.js";
|
|
11
13
|
import { GenericId_exports } from "./GenericId.js";
|
|
12
|
-
import { Ref_exports } from "./Ref.js";
|
|
13
14
|
import { MiddlewareAttachment_exports } from "./MiddlewareAttachment.js";
|
|
14
15
|
import { GroupSpec_exports } from "./GroupSpec.js";
|
|
15
16
|
import { Spec_exports } from "./Spec.js";
|
|
@@ -17,7 +18,6 @@ import { Component_exports } from "./Component.js";
|
|
|
17
18
|
import { Mount_exports } from "./Mount.js";
|
|
18
19
|
import { App_exports } from "./App.js";
|
|
19
20
|
import { Auth_exports } from "./Auth.js";
|
|
20
|
-
import { Callback_exports } from "./Callback.js";
|
|
21
21
|
import { Env_exports } from "./Env.js";
|
|
22
22
|
import { GroupPath_exports } from "./GroupPath.js";
|
|
23
23
|
import { Http_exports } from "./Http.js";
|
package/package.json
CHANGED
package/src/Mount.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { componentsGeneric } from "convex/server";
|
|
2
2
|
import * as Context from "effect/Context";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Option from "effect/Option";
|
|
5
|
+
import * as Predicate from "effect/Predicate";
|
|
3
6
|
import * as Schema from "effect/Schema";
|
|
4
7
|
import * as SchemaAST from "effect/SchemaAST";
|
|
5
8
|
import type * as App from "./App.js";
|
|
6
|
-
import
|
|
9
|
+
import * as Callback from "./Callback.js";
|
|
7
10
|
import * as Component from "./Component.js";
|
|
8
11
|
import type * as Env from "./Env.js";
|
|
9
12
|
import type * as GenericId from "./GenericId.js";
|
|
10
13
|
import type * as IdScope from "./IdScope.js";
|
|
11
14
|
import { CallbackContract } from "./internal/annotations.js";
|
|
12
|
-
import
|
|
15
|
+
import * as Ref from "./Ref.js";
|
|
13
16
|
|
|
14
17
|
const TypeId = "~@confect/core/Mount";
|
|
15
18
|
|
|
@@ -282,3 +285,117 @@ export const make = <
|
|
|
282
285
|
export const data = <C extends Component.Descriptor, Name extends string>(
|
|
283
286
|
mount: Mount<C, Name, Declared>,
|
|
284
287
|
): Data<C> & { readonly name: Name } => mount[TypeId];
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* What a push runs for a mount: its component's `init`, at the mount's
|
|
291
|
+
* component path, with the install args encoded.
|
|
292
|
+
*/
|
|
293
|
+
export interface InitCall {
|
|
294
|
+
readonly componentPath: string;
|
|
295
|
+
readonly functionName: string;
|
|
296
|
+
readonly args: unknown;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const contractOf = (schema: Schema.Top) =>
|
|
300
|
+
SchemaAST.resolveAt<Callback.Any>(CallbackContract)(
|
|
301
|
+
Schema.toEncoded(schema).ast,
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
type Create<E, R> = (
|
|
305
|
+
contract: Callback.Any,
|
|
306
|
+
ref: Ref.Any,
|
|
307
|
+
) => Effect.Effect<unknown, E, R>;
|
|
308
|
+
|
|
309
|
+
const placeholderHandle: Create<never, never> = (contract) =>
|
|
310
|
+
Schema.decodeEffect(Callback.handle(contract))("").pipe(Effect.orDie);
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Handles for the union member `value` takes: the first member that fits once
|
|
314
|
+
* its callback slots hold placeholder handles and whose handles `create` makes.
|
|
315
|
+
* A target that satisfies only a later member's contract takes that member.
|
|
316
|
+
*/
|
|
317
|
+
const withMemberHandles = <E, R>(
|
|
318
|
+
members: ReadonlyArray<Schema.Top>,
|
|
319
|
+
value: unknown,
|
|
320
|
+
create: Create<E, R>,
|
|
321
|
+
): Effect.Effect<unknown, E, R> => {
|
|
322
|
+
const fitting = members.filter((member) =>
|
|
323
|
+
Schema.is(member)(
|
|
324
|
+
Effect.runSync(withHandles(member, value, placeholderHandle)),
|
|
325
|
+
),
|
|
326
|
+
);
|
|
327
|
+
return fitting.length === 0
|
|
328
|
+
? Effect.succeed(value)
|
|
329
|
+
: Effect.firstSuccessOf(
|
|
330
|
+
fitting.map((member) => withHandles(member, value, create)),
|
|
331
|
+
);
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* The schema of each key's value in a struct or a record.
|
|
336
|
+
*/
|
|
337
|
+
const entrySchema = (
|
|
338
|
+
schema: Schema.Top,
|
|
339
|
+
): ((key: string) => Schema.Top | undefined) | undefined => {
|
|
340
|
+
if (Predicate.hasProperty(schema, "fields")) {
|
|
341
|
+
const fields = schema.fields as Readonly<Record<string, Schema.Top>>;
|
|
342
|
+
return (key) => fields[key];
|
|
343
|
+
}
|
|
344
|
+
if (SchemaAST.isObjects(schema.ast) && Predicate.hasProperty(schema, "value"))
|
|
345
|
+
return () => schema.value as Schema.Top;
|
|
346
|
+
return undefined;
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Put a handle in each callback slot: a host ref in a field whose schema
|
|
351
|
+
* carries a callback contract, at any depth of struct fields and record values,
|
|
352
|
+
* through `optionalKey`, `optional` and the union member the value takes.
|
|
353
|
+
*/
|
|
354
|
+
const withHandles = <E, R>(
|
|
355
|
+
schema: Schema.Top,
|
|
356
|
+
value: unknown,
|
|
357
|
+
create: Create<E, R>,
|
|
358
|
+
): Effect.Effect<unknown, E, R> => {
|
|
359
|
+
const contract = contractOf(schema);
|
|
360
|
+
if (contract !== undefined && Ref.isRef(value))
|
|
361
|
+
return create(contract, value);
|
|
362
|
+
if (Predicate.hasProperty(schema, "schema"))
|
|
363
|
+
return withHandles(schema.schema as Schema.Top, value, create);
|
|
364
|
+
if (Predicate.hasProperty(schema, "members") && Array.isArray(schema.members))
|
|
365
|
+
return withMemberHandles(schema.members, value, create);
|
|
366
|
+
const at = entrySchema(schema);
|
|
367
|
+
if (at === undefined || !Predicate.isObject(value))
|
|
368
|
+
return Effect.succeed(value);
|
|
369
|
+
return Effect.forEach(Object.entries(value), ([key, field]) => {
|
|
370
|
+
const fieldSchema = at(key);
|
|
371
|
+
return fieldSchema === undefined
|
|
372
|
+
? Effect.succeed([key, field] as const)
|
|
373
|
+
: withHandles(fieldSchema, field, create).pipe(
|
|
374
|
+
Effect.map((resolved) => [key, resolved] as const),
|
|
375
|
+
);
|
|
376
|
+
}).pipe(Effect.map(Object.fromEntries));
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* The `init` call a mount's install args make, with each callback slot's host
|
|
381
|
+
* ref replaced by the handle `create` makes for the slot's contract. None for a
|
|
382
|
+
* component without `init`.
|
|
383
|
+
*/
|
|
384
|
+
export const initCall = <E, R>(
|
|
385
|
+
mount: Any,
|
|
386
|
+
create: Create<E, R>,
|
|
387
|
+
): Effect.Effect<Option.Option<InitCall>, E | Schema.SchemaError, R> => {
|
|
388
|
+
const { component, name, args } = data(mount);
|
|
389
|
+
const init = component.init;
|
|
390
|
+
if (init === undefined) return Effect.succeedNone;
|
|
391
|
+
return withHandles(init.args, args ?? {}, create).pipe(
|
|
392
|
+
Effect.flatMap(Schema.encodeUnknownEffect(init.args)),
|
|
393
|
+
Effect.map((encoded) =>
|
|
394
|
+
Option.some({
|
|
395
|
+
componentPath: name,
|
|
396
|
+
functionName: init.convexFunctionName,
|
|
397
|
+
args: encoded,
|
|
398
|
+
}),
|
|
399
|
+
),
|
|
400
|
+
);
|
|
401
|
+
};
|