@gaganref/confect-server 10.3.1-fork.10 → 10.3.1-fork.12
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/OfficialComponent.d.ts +50 -0
- package/dist/OfficialComponent.d.ts.map +1 -0
- package/dist/OfficialComponent.js +70 -0
- package/dist/OfficialComponent.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/package.json +2 -2
- package/src/OfficialComponent.ts +151 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as Ref from "@confect/core/Ref";
|
|
2
|
+
import type { DefaultFunctionArgs, GenericActionCtx, GenericDataModel, GenericMutationCtx, GenericQueryCtx } from "convex/server";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Schema from "effect/Schema";
|
|
5
|
+
import type * as ActionRunner from "./ActionRunner.js";
|
|
6
|
+
import type * as MutationRunner from "./MutationRunner.js";
|
|
7
|
+
import type * as QueryRunner from "./QueryRunner.js";
|
|
8
|
+
declare const ComponentCallFailed_base: Schema.Class<ComponentCallFailed, Schema.TaggedStruct<"ComponentCallFailed", {
|
|
9
|
+
readonly component: Schema.String;
|
|
10
|
+
readonly method: Schema.String;
|
|
11
|
+
readonly cause: Schema.Defect;
|
|
12
|
+
}>, import("effect/Cause").YieldableError>;
|
|
13
|
+
/**
|
|
14
|
+
* An official component's method rejected. `cause` is the rejection as thrown.
|
|
15
|
+
*/
|
|
16
|
+
export declare class ComponentCallFailed extends ComponentCallFailed_base {
|
|
17
|
+
}
|
|
18
|
+
declare const unsupported: unique symbol;
|
|
19
|
+
type Unsupported = typeof unsupported;
|
|
20
|
+
type Needs<Param> = [GenericActionCtx<GenericDataModel>] extends [Param] ? [GenericMutationCtx<GenericDataModel>] extends [Param] ? [GenericQueryCtx<GenericDataModel>] extends [Param] ? QueryRunner.QueryRunner : MutationRunner.MutationRunner : [GenericQueryCtx<GenericDataModel>] extends [Param] ? Unsupported : ActionRunner.ActionRunner : Unsupported;
|
|
21
|
+
type Method<Official> = {
|
|
22
|
+
[K in keyof Official & string]: Official[K] extends (ctx: infer Ctx, ...args: infer _Args) => Promise<unknown> ? Needs<Ctx> extends Unsupported ? never : K : never;
|
|
23
|
+
}[keyof Official & string];
|
|
24
|
+
type Call<F> = F extends (ctx: infer Ctx, ...args: infer Args) => Promise<infer A> ? (...args: Args) => Effect.Effect<A, never, Needs<Ctx>> : never;
|
|
25
|
+
type Lifted<Official> = <M extends Method<Official>>(method: M, ...args: Parameters<Call<Official[M]>>) => ReturnType<Call<Official[M]>>;
|
|
26
|
+
/**
|
|
27
|
+
* Lift official promise methods, deriving each capability from its ctx
|
|
28
|
+
* parameter. A rejection is caller misuse, a limit or a platform fault rather
|
|
29
|
+
* than a domain fact, so it dies.
|
|
30
|
+
*/
|
|
31
|
+
export declare const make: <Official extends object>(component: string, official: Official) => Lifted<Official>;
|
|
32
|
+
/**
|
|
33
|
+
* A function reference with its encoded arguments, ready for an official method
|
|
34
|
+
* that takes both.
|
|
35
|
+
*/
|
|
36
|
+
export interface Fn<R extends Ref.Any> {
|
|
37
|
+
readonly reference: Ref.FunctionReference<R>;
|
|
38
|
+
readonly args: DefaultFunctionArgs;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Encode a ref's arguments through its codecs to the wire record an official
|
|
42
|
+
* method expects.
|
|
43
|
+
*/
|
|
44
|
+
export declare const encodeCall: <R extends Ref.Any>(ref: R, args: NoInfer<Ref.Args<R>>) => Effect.Effect<Fn<R>>;
|
|
45
|
+
/**
|
|
46
|
+
* Encode a callback's real field without fabricating the rest of its arguments.
|
|
47
|
+
*/
|
|
48
|
+
export declare const encodeField: <R extends Ref.AnyConfect, K extends keyof Ref.Args<R> & keyof Ref.ArgsFields<R>>(ref: R, key: K, value: NoInfer<Ref.Args<R>[K]>) => Effect.Effect<unknown>;
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=OfficialComponent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OfficialComponent.d.ts","sourceRoot":"","sources":["../src/OfficialComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,mBAAmB,CAAC;AACzC,OAAO,KAAK,EACV,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EAChB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAEvD,OAAO,KAAK,KAAK,cAAc,MAAM,qBAAqB,CAAC;AAE3D,OAAO,KAAK,KAAK,WAAW,MAAM,kBAAkB,CAAC;;;;;;AAErD;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,wBAGxC;CAAG;AAEJ,OAAO,CAAC,MAAM,WAAW,EAAE,OAAO,MAAM,CAAC;AACzC,KAAK,WAAW,GAAG,OAAO,WAAW,CAAC;AACtC,KAAK,KAAK,CAAC,KAAK,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACpE,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACpD,CAAC,eAAe,CAAC,gBAAgB,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACjD,WAAW,CAAC,WAAW,GACvB,cAAc,CAAC,cAAc,GAC/B,CAAC,eAAe,CAAC,gBAAgB,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACjD,WAAW,GACX,YAAY,CAAC,YAAY,GAC7B,WAAW,CAAC;AAEhB,KAAK,MAAM,CAAC,QAAQ,IAAI;KACrB,CAAC,IAAI,MAAM,QAAQ,GAAG,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,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C,CAAC,CAAC,CAAC,KACzB,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAUnB,CAAC;AAEJ;;GAEG;AACH,eAAO,MAAM,WAAW,GACtB,CAAC,SAAS,GAAG,CAAC,UAAU,EACxB,CAAC,SAAS,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,OAEhD,CAAC,OACD,CAAC,SACC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAC7B,MAAM,CAAC,MAAM,CAAC,OAAO,CAMvB,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { ActionCtx } from "./ActionCtx.js";
|
|
3
|
+
import { MutationCtx } from "./MutationCtx.js";
|
|
4
|
+
import { QueryCtx } from "./QueryCtx.js";
|
|
5
|
+
import * as Ref from "@confect/core/Ref";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
import * as Schema from "effect/Schema";
|
|
8
|
+
import * as Option from "effect/Option";
|
|
9
|
+
//#region src/OfficialComponent.ts
|
|
10
|
+
var OfficialComponent_exports = /* @__PURE__ */ __exportAll({
|
|
11
|
+
ComponentCallFailed: () => ComponentCallFailed,
|
|
12
|
+
encodeCall: () => encodeCall,
|
|
13
|
+
encodeField: () => encodeField,
|
|
14
|
+
make: () => make
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* An official component's method rejected. `cause` is the rejection as thrown.
|
|
18
|
+
*/
|
|
19
|
+
var ComponentCallFailed = class extends Schema.TaggedError()("ComponentCallFailed", {
|
|
20
|
+
component: Schema.String,
|
|
21
|
+
method: Schema.String,
|
|
22
|
+
cause: Schema.Defect()
|
|
23
|
+
}) {};
|
|
24
|
+
/**
|
|
25
|
+
* Lift official promise methods, deriving each capability from its ctx
|
|
26
|
+
* parameter. A rejection is caller misuse, a limit or a platform fault rather
|
|
27
|
+
* than a domain fact, so it dies.
|
|
28
|
+
*/
|
|
29
|
+
const make = (component, official) => {
|
|
30
|
+
const context = Effect.gen(function* () {
|
|
31
|
+
const action = yield* Effect.serviceOption(ActionCtx());
|
|
32
|
+
if (Option.isSome(action)) return action.value;
|
|
33
|
+
const mutation = yield* Effect.serviceOption(MutationCtx());
|
|
34
|
+
if (Option.isSome(mutation)) return mutation.value;
|
|
35
|
+
const query = yield* Effect.serviceOption(QueryCtx());
|
|
36
|
+
if (Option.isSome(query)) return query.value;
|
|
37
|
+
return yield* Effect.die(/* @__PURE__ */ new Error(`${component} called outside a Confect handler`));
|
|
38
|
+
});
|
|
39
|
+
return Effect.fn(`${component}.call`)(function* (method, ...args) {
|
|
40
|
+
const ctx = yield* context;
|
|
41
|
+
const invoke = official[method];
|
|
42
|
+
return yield* Effect.tryPromise({
|
|
43
|
+
try: () => invoke.call(official, ctx, ...args),
|
|
44
|
+
catch: (cause) => ComponentCallFailed.make({
|
|
45
|
+
component,
|
|
46
|
+
method,
|
|
47
|
+
cause
|
|
48
|
+
})
|
|
49
|
+
}).pipe(Effect.orDie);
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Encode a ref's arguments through its codecs to the wire record an official
|
|
54
|
+
* method expects.
|
|
55
|
+
*/
|
|
56
|
+
const encodeCall = (ref, args) => Ref.encodeArgs(ref, args).pipe(Effect.flatMap(Schema.decodeUnknownEffect(Schema.Record(Schema.String, Schema.Unknown))), Effect.map((encoded) => ({
|
|
57
|
+
reference: Ref.getFunctionReference(ref),
|
|
58
|
+
args: encoded
|
|
59
|
+
})), Effect.orDie);
|
|
60
|
+
/**
|
|
61
|
+
* Encode a callback's real field without fabricating the rest of its arguments.
|
|
62
|
+
*/
|
|
63
|
+
const encodeField = (ref, key, value) => {
|
|
64
|
+
const fields = ref.args.fields;
|
|
65
|
+
return Schema.encodeUnknownEffect(fields[key])(value).pipe(Effect.orDie);
|
|
66
|
+
};
|
|
67
|
+
//#endregion
|
|
68
|
+
export { ComponentCallFailed, OfficialComponent_exports, encodeCall, encodeField, make };
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=OfficialComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OfficialComponent.js","names":["ActionCtx.ActionCtx","MutationCtx.MutationCtx","QueryCtx.QueryCtx"],"sources":["../src/OfficialComponent.ts"],"sourcesContent":["import * as Ref from \"@confect/core/Ref\";\nimport type {\n DefaultFunctionArgs,\n GenericActionCtx,\n GenericDataModel,\n GenericMutationCtx,\n GenericQueryCtx,\n} from \"convex/server\";\nimport * as Effect from \"effect/Effect\";\nimport * as Option from \"effect/Option\";\nimport * as Schema from \"effect/Schema\";\nimport * as ActionCtx from \"./ActionCtx.js\";\nimport type * as ActionRunner from \"./ActionRunner.js\";\nimport * as MutationCtx from \"./MutationCtx.js\";\nimport type * as MutationRunner from \"./MutationRunner.js\";\nimport * as QueryCtx from \"./QueryCtx.js\";\nimport type * as QueryRunner from \"./QueryRunner.js\";\n\n/**\n * An official component's method rejected. `cause` is the rejection as thrown.\n */\nexport class ComponentCallFailed extends Schema.TaggedError<ComponentCallFailed>()(\n \"ComponentCallFailed\",\n { component: Schema.String, method: Schema.String, cause: Schema.Defect() },\n) {}\n\ndeclare const unsupported: unique symbol;\ntype Unsupported = typeof unsupported;\ntype Needs<Param> = [GenericActionCtx<GenericDataModel>] extends [Param]\n ? [GenericMutationCtx<GenericDataModel>] extends [Param]\n ? [GenericQueryCtx<GenericDataModel>] extends [Param]\n ? QueryRunner.QueryRunner\n : MutationRunner.MutationRunner\n : [GenericQueryCtx<GenericDataModel>] extends [Param]\n ? Unsupported\n : ActionRunner.ActionRunner\n : Unsupported;\n\ntype Method<Official> = {\n [K in keyof Official & string]: Official[K] extends (\n ctx: infer Ctx,\n ...args: infer _Args\n ) => Promise<unknown>\n ? Needs<Ctx> extends Unsupported\n ? never\n : K\n : never;\n}[keyof Official & string];\n\ntype Call<F> = F extends (\n ctx: infer Ctx,\n ...args: infer Args\n) => Promise<infer A>\n ? (...args: Args) => Effect.Effect<A, never, Needs<Ctx>>\n : never;\n\ntype Lifted<Official> = <M extends Method<Official>>(\n method: M,\n ...args: Parameters<Call<Official[M]>>\n) => ReturnType<Call<Official[M]>>;\n\n/**\n * Lift official promise methods, deriving each capability from its ctx\n * parameter. A rejection is caller misuse, a limit or a platform fault rather\n * than a domain fact, so it dies.\n */\nexport const make = <Official extends object>(\n component: string,\n official: Official,\n): Lifted<Official> => {\n const context = Effect.gen(function* () {\n const action = yield* Effect.serviceOption(\n ActionCtx.ActionCtx<GenericDataModel>(),\n );\n if (Option.isSome(action)) return action.value;\n const mutation = yield* Effect.serviceOption(\n MutationCtx.MutationCtx<GenericDataModel>(),\n );\n if (Option.isSome(mutation)) return mutation.value;\n const query = yield* Effect.serviceOption(\n QueryCtx.QueryCtx<GenericDataModel>(),\n );\n if (Option.isSome(query)) return query.value;\n return yield* Effect.die(\n new Error(`${component} called outside a Confect handler`),\n );\n });\n const call = Effect.fn(`${component}.call`)(function* (\n method: Method<Official>,\n ...args: unknown[]\n ) {\n const ctx = yield* context;\n // Method selects promise methods whose first argument accepts a native handler context.\n const invoke = official[method] as (\n native: typeof ctx,\n ...args: unknown[]\n ) => Promise<unknown>;\n return yield* Effect.tryPromise({\n try: () => invoke.call(official, ctx, ...args),\n catch: (cause) => ComponentCallFailed.make({ component, method, cause }),\n }).pipe(Effect.orDie);\n });\n // Confect installs the native ctx with the runner capability inferred by Needs.\n return call as unknown as Lifted<Official>;\n};\n\n/**\n * A function reference with its encoded arguments, ready for an official method\n * that takes both.\n */\nexport interface Fn<R extends Ref.Any> {\n readonly reference: Ref.FunctionReference<R>;\n readonly args: DefaultFunctionArgs;\n}\n\n/**\n * Encode a ref's arguments through its codecs to the wire record an official\n * method expects.\n */\nexport const encodeCall = <R extends Ref.Any>(\n ref: R,\n args: NoInfer<Ref.Args<R>>,\n): Effect.Effect<Fn<R>> =>\n Ref.encodeArgs(ref, args).pipe(\n Effect.flatMap(\n Schema.decodeUnknownEffect(Schema.Record(Schema.String, Schema.Unknown)),\n ),\n Effect.map((encoded) => ({\n reference: Ref.getFunctionReference(ref),\n args: encoded,\n })),\n Effect.orDie,\n );\n\n/**\n * Encode a callback's real field without fabricating the rest of its arguments.\n */\nexport const encodeField = <\n R extends Ref.AnyConfect,\n K extends keyof Ref.Args<R> & keyof Ref.ArgsFields<R>,\n>(\n ref: R,\n key: K,\n value: NoInfer<Ref.Args<R>[K]>,\n): Effect.Effect<unknown> => {\n const fields = ref.args.fields as Record<\n keyof Ref.ArgsFields<R>,\n Schema.Codec<unknown, unknown>\n >;\n return Schema.encodeUnknownEffect(fields[key])(value).pipe(Effect.orDie);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqBA,IAAa,sBAAb,cAAyC,OAAO,YAAiC,CAAC,CAChF,uBACA;CAAE,WAAW,OAAO;CAAQ,QAAQ,OAAO;CAAQ,OAAO,OAAO,OAAO;AAAE,CAC5E,CAAC,CAAC,CAAC;;;;;;AA0CH,MAAa,QACX,WACA,aACqB;CACrB,MAAM,UAAU,OAAO,IAAI,aAAa;EACtC,MAAM,SAAS,OAAO,OAAO,cAC3BA,UAAsC,CACxC;EACA,IAAI,OAAO,OAAO,MAAM,GAAG,OAAO,OAAO;EACzC,MAAM,WAAW,OAAO,OAAO,cAC7BC,YAA0C,CAC5C;EACA,IAAI,OAAO,OAAO,QAAQ,GAAG,OAAO,SAAS;EAC7C,MAAM,QAAQ,OAAO,OAAO,cAC1BC,SAAoC,CACtC;EACA,IAAI,OAAO,OAAO,KAAK,GAAG,OAAO,MAAM;EACvC,OAAO,OAAO,OAAO,oBACnB,IAAI,MAAM,GAAG,UAAU,kCAAkC,CAC3D;CACF,CAAC;CAiBD,OAhBa,OAAO,GAAG,GAAG,UAAU,MAAM,CAAC,CAAC,WAC1C,QACA,GAAG,MACH;EACA,MAAM,MAAM,OAAO;EAEnB,MAAM,SAAS,SAAS;EAIxB,OAAO,OAAO,OAAO,WAAW;GAC9B,WAAW,OAAO,KAAK,UAAU,KAAK,GAAG,IAAI;GAC7C,QAAQ,UAAU,oBAAoB,KAAK;IAAE;IAAW;IAAQ;GAAM,CAAC;EACzE,CAAC,CAAC,CAAC,KAAK,OAAO,KAAK;CACtB,CAEU;AACZ;;;;;AAeA,MAAa,cACX,KACA,SAEA,IAAI,WAAW,KAAK,IAAI,CAAC,CAAC,KACxB,OAAO,QACL,OAAO,oBAAoB,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO,CAAC,CACzE,GACA,OAAO,KAAK,aAAa;CACvB,WAAW,IAAI,qBAAqB,GAAG;CACvC,MAAM;AACR,EAAE,GACF,OAAO,KACT;;;;AAKF,MAAa,eAIX,KACA,KACA,UAC2B;CAC3B,MAAM,SAAS,IAAI,KAAK;CAIxB,OAAO,OAAO,oBAAoB,OAAO,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,OAAO,KAAK;AACzE"}
|
package/dist/index.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export * as MiddlewareRegistryItem from "./MiddlewareRegistryItem.js";
|
|
|
28
28
|
export * as MutationCtx from "./MutationCtx.js";
|
|
29
29
|
export * as MutationRunner from "./MutationRunner.js";
|
|
30
30
|
export * as MutationTransactionContext from "./MutationTransactionContext.js";
|
|
31
|
+
export * as OfficialComponent from "./OfficialComponent.js";
|
|
31
32
|
export * as OrderedQuery from "./OrderedQuery.js";
|
|
32
33
|
export * as QueryCtx from "./QueryCtx.js";
|
|
33
34
|
export * as QueryInitializer from "./QueryInitializer.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,uBAAuB,MAAM,8BAA8B,CAAC;AACxE,OAAO,KAAK,sBAAsB,MAAM,6BAA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AAqB,MAAM,4BAA4B,CAAC;AACpE;;GAEG;AACH,OAAO,KAAK,qBAAqB,MAAM,4BAA4B,CAAC;AACpE,OAAO,KAAK,wBAAwB,MAAM,+BAA+B,CAAC;AAC1E,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,mBAAmB,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,mBAAmB,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,mBAAmB,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -56,6 +56,7 @@ import { GroupImpl_exports } from "./GroupImpl.js";
|
|
|
56
56
|
import { Handler_exports } from "./Handler.js";
|
|
57
57
|
import { HttpRouter_exports } from "./HttpRouter.js";
|
|
58
58
|
import { MiddlewareImpl_exports } from "./MiddlewareImpl.js";
|
|
59
|
+
import { OfficialComponent_exports } from "./OfficialComponent.js";
|
|
59
60
|
import { RegisteredFunctions_exports } from "./RegisteredFunctions.js";
|
|
60
61
|
import { TableInfo_exports } from "./TableInfo.js";
|
|
61
|
-
export { ActionCtx_exports as ActionCtx, ActionRunner_exports as ActionRunner, AiGatewayDecisionClient_exports as AiGatewayDecisionClient, AiGatewayDecisionModel_exports as AiGatewayDecisionModel, AiGatewayLanguageClient_exports as AiGatewayLanguageClient, AiGatewayLanguageModel_exports as AiGatewayLanguageModel, Auth_exports as Auth, BlobNotFoundError_exports as BlobNotFoundError, Callback_exports as Callback, ConvexConfigProvider_exports as ConvexConfigProvider, ConvexFunctionDefinitions_exports as ConvexFunctionDefinitions, ConvexLogger_exports as ConvexLogger, CronJob_exports as CronJob, CronJobs_exports as CronJobs, DataModel_exports as DataModel, DatabaseReader_exports as DatabaseReader, DatabaseSchema_exports as DatabaseSchema, DatabaseWriter_exports as DatabaseWriter, Document_exports as Document, ExecutionMetadata_exports as ExecutionMetadata, FunctionImpl_exports as FunctionImpl, FunctionRegistryItem_exports as FunctionRegistryItem, GroupImpl_exports as GroupImpl, Handler_exports as Handler, HttpRouter_exports as HttpRouter, MiddlewareImpl_exports as MiddlewareImpl, MiddlewareRegistryItem_exports as MiddlewareRegistryItem, MutationCtx_exports as MutationCtx, MutationRunner_exports as MutationRunner, MutationTransactionContext_exports as MutationTransactionContext, OrderedQuery_exports as OrderedQuery, QueryCtx_exports as QueryCtx, QueryInitializer_exports as QueryInitializer, QueryRunner_exports as QueryRunner, QueryStream_exports as QueryStream, QueryStreamCursor_exports as QueryStreamCursor, QueryStreamIndexRange_exports as QueryStreamIndexRange, QueryStreamKeyBounds_exports as QueryStreamKeyBounds, QueryStreamKeyLabels_exports as QueryStreamKeyLabels, QueryStreamKeyLayout_exports as QueryStreamKeyLayout, QueryStreamKeyValues_exports as QueryStreamKeyValues, QueryStreamOrderDirection_exports as QueryStreamOrderDirection, QueryStreamReadBudget_exports as QueryStreamReadBudget, QueryTransactionContext_exports as QueryTransactionContext, RegisteredConvexFunction_exports as RegisteredConvexFunction, RegisteredFunction_exports as RegisteredFunction, RegisteredFunctions_exports as RegisteredFunctions, Registry_exports as Registry, RegistryItems_exports as RegistryItems, RequestMetadata_exports as RequestMetadata, ResolvedMiddleware_exports as ResolvedMiddleware, Scheduler_exports as Scheduler, Storage_exports as Storage, StorageActionWriter_exports as StorageActionWriter, StorageReader_exports as StorageReader, StorageWriter_exports as StorageWriter, Table_exports as Table, TableInfo_exports as TableInfo, TransactionMetadata_exports as TransactionMetadata, VectorSearch_exports as VectorSearch };
|
|
62
|
+
export { ActionCtx_exports as ActionCtx, ActionRunner_exports as ActionRunner, AiGatewayDecisionClient_exports as AiGatewayDecisionClient, AiGatewayDecisionModel_exports as AiGatewayDecisionModel, AiGatewayLanguageClient_exports as AiGatewayLanguageClient, AiGatewayLanguageModel_exports as AiGatewayLanguageModel, Auth_exports as Auth, BlobNotFoundError_exports as BlobNotFoundError, Callback_exports as Callback, ConvexConfigProvider_exports as ConvexConfigProvider, ConvexFunctionDefinitions_exports as ConvexFunctionDefinitions, ConvexLogger_exports as ConvexLogger, CronJob_exports as CronJob, CronJobs_exports as CronJobs, DataModel_exports as DataModel, DatabaseReader_exports as DatabaseReader, DatabaseSchema_exports as DatabaseSchema, DatabaseWriter_exports as DatabaseWriter, Document_exports as Document, ExecutionMetadata_exports as ExecutionMetadata, FunctionImpl_exports as FunctionImpl, FunctionRegistryItem_exports as FunctionRegistryItem, GroupImpl_exports as GroupImpl, Handler_exports as Handler, HttpRouter_exports as HttpRouter, MiddlewareImpl_exports as MiddlewareImpl, MiddlewareRegistryItem_exports as MiddlewareRegistryItem, MutationCtx_exports as MutationCtx, MutationRunner_exports as MutationRunner, MutationTransactionContext_exports as MutationTransactionContext, OfficialComponent_exports as OfficialComponent, OrderedQuery_exports as OrderedQuery, QueryCtx_exports as QueryCtx, QueryInitializer_exports as QueryInitializer, QueryRunner_exports as QueryRunner, QueryStream_exports as QueryStream, QueryStreamCursor_exports as QueryStreamCursor, QueryStreamIndexRange_exports as QueryStreamIndexRange, QueryStreamKeyBounds_exports as QueryStreamKeyBounds, QueryStreamKeyLabels_exports as QueryStreamKeyLabels, QueryStreamKeyLayout_exports as QueryStreamKeyLayout, QueryStreamKeyValues_exports as QueryStreamKeyValues, QueryStreamOrderDirection_exports as QueryStreamOrderDirection, QueryStreamReadBudget_exports as QueryStreamReadBudget, QueryTransactionContext_exports as QueryTransactionContext, RegisteredConvexFunction_exports as RegisteredConvexFunction, RegisteredFunction_exports as RegisteredFunction, RegisteredFunctions_exports as RegisteredFunctions, Registry_exports as Registry, RegistryItems_exports as RegistryItems, RequestMetadata_exports as RequestMetadata, ResolvedMiddleware_exports as ResolvedMiddleware, Scheduler_exports as Scheduler, Storage_exports as Storage, StorageActionWriter_exports as StorageActionWriter, StorageReader_exports as StorageReader, StorageWriter_exports as StorageWriter, Table_exports as Table, TableInfo_exports as TableInfo, TransactionMetadata_exports as TransactionMetadata, VectorSearch_exports as VectorSearch };
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gaganref/confect-server",
|
|
3
|
-
"version": "10.3.1-fork.
|
|
3
|
+
"version": "10.3.1-fork.12",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@effect/ai-openai-compat": "4.0.4",
|
|
6
6
|
"@effect/ai-openrouter": "4.0.4"
|
|
7
7
|
},
|
|
8
8
|
"peerDependencies": {
|
|
9
|
-
"@confect/core": "npm:@gaganref/confect-core@10.3.1-fork.
|
|
9
|
+
"@confect/core": "npm:@gaganref/confect-core@10.3.1-fork.12",
|
|
10
10
|
"@effect/platform-node": "^4.0.0",
|
|
11
11
|
"convex": "^1.45.0",
|
|
12
12
|
"effect": "^4.0.4"
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import * as Ref from "@confect/core/Ref";
|
|
2
|
+
import type {
|
|
3
|
+
DefaultFunctionArgs,
|
|
4
|
+
GenericActionCtx,
|
|
5
|
+
GenericDataModel,
|
|
6
|
+
GenericMutationCtx,
|
|
7
|
+
GenericQueryCtx,
|
|
8
|
+
} from "convex/server";
|
|
9
|
+
import * as Effect from "effect/Effect";
|
|
10
|
+
import * as Option from "effect/Option";
|
|
11
|
+
import * as Schema from "effect/Schema";
|
|
12
|
+
import * as ActionCtx from "./ActionCtx.js";
|
|
13
|
+
import type * as ActionRunner from "./ActionRunner.js";
|
|
14
|
+
import * as MutationCtx from "./MutationCtx.js";
|
|
15
|
+
import type * as MutationRunner from "./MutationRunner.js";
|
|
16
|
+
import * as QueryCtx from "./QueryCtx.js";
|
|
17
|
+
import type * as QueryRunner from "./QueryRunner.js";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* An official component's method rejected. `cause` is the rejection as thrown.
|
|
21
|
+
*/
|
|
22
|
+
export class ComponentCallFailed extends Schema.TaggedError<ComponentCallFailed>()(
|
|
23
|
+
"ComponentCallFailed",
|
|
24
|
+
{ component: Schema.String, method: Schema.String, cause: Schema.Defect() },
|
|
25
|
+
) {}
|
|
26
|
+
|
|
27
|
+
declare const unsupported: unique symbol;
|
|
28
|
+
type Unsupported = typeof unsupported;
|
|
29
|
+
type Needs<Param> = [GenericActionCtx<GenericDataModel>] extends [Param]
|
|
30
|
+
? [GenericMutationCtx<GenericDataModel>] extends [Param]
|
|
31
|
+
? [GenericQueryCtx<GenericDataModel>] extends [Param]
|
|
32
|
+
? QueryRunner.QueryRunner
|
|
33
|
+
: MutationRunner.MutationRunner
|
|
34
|
+
: [GenericQueryCtx<GenericDataModel>] extends [Param]
|
|
35
|
+
? Unsupported
|
|
36
|
+
: ActionRunner.ActionRunner
|
|
37
|
+
: Unsupported;
|
|
38
|
+
|
|
39
|
+
type Method<Official> = {
|
|
40
|
+
[K in keyof Official & string]: Official[K] extends (
|
|
41
|
+
ctx: infer Ctx,
|
|
42
|
+
...args: infer _Args
|
|
43
|
+
) => Promise<unknown>
|
|
44
|
+
? Needs<Ctx> extends Unsupported
|
|
45
|
+
? never
|
|
46
|
+
: K
|
|
47
|
+
: never;
|
|
48
|
+
}[keyof Official & string];
|
|
49
|
+
|
|
50
|
+
type Call<F> = F extends (
|
|
51
|
+
ctx: infer Ctx,
|
|
52
|
+
...args: infer Args
|
|
53
|
+
) => Promise<infer A>
|
|
54
|
+
? (...args: Args) => Effect.Effect<A, never, Needs<Ctx>>
|
|
55
|
+
: never;
|
|
56
|
+
|
|
57
|
+
type Lifted<Official> = <M extends Method<Official>>(
|
|
58
|
+
method: M,
|
|
59
|
+
...args: Parameters<Call<Official[M]>>
|
|
60
|
+
) => ReturnType<Call<Official[M]>>;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Lift official promise methods, deriving each capability from its ctx
|
|
64
|
+
* parameter. A rejection is caller misuse, a limit or a platform fault rather
|
|
65
|
+
* than a domain fact, so it dies.
|
|
66
|
+
*/
|
|
67
|
+
export const make = <Official extends object>(
|
|
68
|
+
component: string,
|
|
69
|
+
official: Official,
|
|
70
|
+
): Lifted<Official> => {
|
|
71
|
+
const context = Effect.gen(function* () {
|
|
72
|
+
const action = yield* Effect.serviceOption(
|
|
73
|
+
ActionCtx.ActionCtx<GenericDataModel>(),
|
|
74
|
+
);
|
|
75
|
+
if (Option.isSome(action)) return action.value;
|
|
76
|
+
const mutation = yield* Effect.serviceOption(
|
|
77
|
+
MutationCtx.MutationCtx<GenericDataModel>(),
|
|
78
|
+
);
|
|
79
|
+
if (Option.isSome(mutation)) return mutation.value;
|
|
80
|
+
const query = yield* Effect.serviceOption(
|
|
81
|
+
QueryCtx.QueryCtx<GenericDataModel>(),
|
|
82
|
+
);
|
|
83
|
+
if (Option.isSome(query)) return query.value;
|
|
84
|
+
return yield* Effect.die(
|
|
85
|
+
new Error(`${component} called outside a Confect handler`),
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
const call = Effect.fn(`${component}.call`)(function* (
|
|
89
|
+
method: Method<Official>,
|
|
90
|
+
...args: unknown[]
|
|
91
|
+
) {
|
|
92
|
+
const ctx = yield* context;
|
|
93
|
+
// Method selects promise methods whose first argument accepts a native handler context.
|
|
94
|
+
const invoke = official[method] as (
|
|
95
|
+
native: typeof ctx,
|
|
96
|
+
...args: unknown[]
|
|
97
|
+
) => Promise<unknown>;
|
|
98
|
+
return yield* Effect.tryPromise({
|
|
99
|
+
try: () => invoke.call(official, ctx, ...args),
|
|
100
|
+
catch: (cause) => ComponentCallFailed.make({ component, method, cause }),
|
|
101
|
+
}).pipe(Effect.orDie);
|
|
102
|
+
});
|
|
103
|
+
// Confect installs the native ctx with the runner capability inferred by Needs.
|
|
104
|
+
return call as unknown as Lifted<Official>;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* A function reference with its encoded arguments, ready for an official method
|
|
109
|
+
* that takes both.
|
|
110
|
+
*/
|
|
111
|
+
export interface Fn<R extends Ref.Any> {
|
|
112
|
+
readonly reference: Ref.FunctionReference<R>;
|
|
113
|
+
readonly args: DefaultFunctionArgs;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Encode a ref's arguments through its codecs to the wire record an official
|
|
118
|
+
* method expects.
|
|
119
|
+
*/
|
|
120
|
+
export const encodeCall = <R extends Ref.Any>(
|
|
121
|
+
ref: R,
|
|
122
|
+
args: NoInfer<Ref.Args<R>>,
|
|
123
|
+
): Effect.Effect<Fn<R>> =>
|
|
124
|
+
Ref.encodeArgs(ref, args).pipe(
|
|
125
|
+
Effect.flatMap(
|
|
126
|
+
Schema.decodeUnknownEffect(Schema.Record(Schema.String, Schema.Unknown)),
|
|
127
|
+
),
|
|
128
|
+
Effect.map((encoded) => ({
|
|
129
|
+
reference: Ref.getFunctionReference(ref),
|
|
130
|
+
args: encoded,
|
|
131
|
+
})),
|
|
132
|
+
Effect.orDie,
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Encode a callback's real field without fabricating the rest of its arguments.
|
|
137
|
+
*/
|
|
138
|
+
export const encodeField = <
|
|
139
|
+
R extends Ref.AnyConfect,
|
|
140
|
+
K extends keyof Ref.Args<R> & keyof Ref.ArgsFields<R>,
|
|
141
|
+
>(
|
|
142
|
+
ref: R,
|
|
143
|
+
key: K,
|
|
144
|
+
value: NoInfer<Ref.Args<R>[K]>,
|
|
145
|
+
): Effect.Effect<unknown> => {
|
|
146
|
+
const fields = ref.args.fields as Record<
|
|
147
|
+
keyof Ref.ArgsFields<R>,
|
|
148
|
+
Schema.Codec<unknown, unknown>
|
|
149
|
+
>;
|
|
150
|
+
return Schema.encodeUnknownEffect(fields[key])(value).pipe(Effect.orDie);
|
|
151
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -28,6 +28,7 @@ export * as MiddlewareRegistryItem from "./MiddlewareRegistryItem.js";
|
|
|
28
28
|
export * as MutationCtx from "./MutationCtx.js";
|
|
29
29
|
export * as MutationRunner from "./MutationRunner.js";
|
|
30
30
|
export * as MutationTransactionContext from "./MutationTransactionContext.js";
|
|
31
|
+
export * as OfficialComponent from "./OfficialComponent.js";
|
|
31
32
|
export * as OrderedQuery from "./OrderedQuery.js";
|
|
32
33
|
export * as QueryCtx from "./QueryCtx.js";
|
|
33
34
|
export * as QueryInitializer from "./QueryInitializer.js";
|