@confect/core 4.0.0 → 5.0.0
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/CHANGELOG.md +2 -0
- package/dist/FunctionProvenance.d.ts +2 -5
- package/dist/FunctionProvenance.d.ts.map +1 -1
- package/dist/Ref.d.ts +19 -7
- package/dist/Ref.d.ts.map +1 -1
- package/dist/Ref.js +31 -10
- package/dist/Ref.js.map +1 -1
- package/dist/Refs.js +3 -3
- package/dist/Refs.js.map +1 -1
- package/package.json +1 -1
- package/src/Ref.ts +118 -22
- package/src/Refs.ts +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Data, Schema } from "effect";
|
|
2
|
-
import * as effect_Unify0 from "effect/Unify";
|
|
3
2
|
import { DefaultFunctionArgs } from "convex/server";
|
|
3
|
+
import * as effect_Unify0 from "effect/Unify";
|
|
4
4
|
|
|
5
5
|
//#region src/FunctionProvenance.d.ts
|
|
6
6
|
declare namespace FunctionProvenance_d_exports {
|
|
@@ -11,10 +11,7 @@ type FunctionProvenance = Data.TaggedEnum<{
|
|
|
11
11
|
args: Schema.Schema.AnyNoContext;
|
|
12
12
|
returns: Schema.Schema.AnyNoContext;
|
|
13
13
|
};
|
|
14
|
-
Convex: {
|
|
15
|
-
/** @internal */_args: DefaultFunctionArgs; /** @internal */
|
|
16
|
-
_returns: any;
|
|
17
|
-
};
|
|
14
|
+
Convex: {};
|
|
18
15
|
}>;
|
|
19
16
|
interface Confect<Args extends Schema.Schema.AnyNoContext, Returns extends Schema.Schema.AnyNoContext> {
|
|
20
17
|
readonly _tag: "Confect";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FunctionProvenance.d.ts","names":[],"sources":["../src/FunctionProvenance.ts"],"mappings":";;;;;;;;KAIY,kBAAA,GAAqB,IAAA,CAAK,UAAA;EACpC,OAAA;IACE,IAAA,EAAM,MAAA,CAAO,MAAA,CAAO,YAAA;IACpB,OAAA,EAAS,MAAA,CAAO,MAAA,CAAO,YAAA;EAAA;EAEzB,MAAA;
|
|
1
|
+
{"version":3,"file":"FunctionProvenance.d.ts","names":[],"sources":["../src/FunctionProvenance.ts"],"mappings":";;;;;;;;KAIY,kBAAA,GAAqB,IAAA,CAAK,UAAA;EACpC,OAAA;IACE,IAAA,EAAM,MAAA,CAAO,MAAA,CAAO,YAAA;IACpB,OAAA,EAAS,MAAA,CAAO,MAAA,CAAO,YAAA;EAAA;EAEzB,MAAA;AAAA;AAAA,UAQe,OAAA,cACF,MAAA,CAAO,MAAA,CAAO,YAAA,kBACX,MAAA,CAAO,MAAA,CAAO,YAAA;EAAA,SAErB,IAAA;EAAA,SACA,IAAA,EAAM,IAAA;EAAA,SACN,OAAA,EAAS,OAAA;AAAA;AAAA,UAGH,UAAA,SAAmB,OAAA,CAClC,MAAA,CAAO,MAAA,CAAO,YAAA,EACd,MAAA,CAAO,MAAA,CAAO,YAAA;AAAA,UAGC,MAAA,cAAoB,mBAAA;EAAA,SAC1B,IAAA;EAAA,SACA,KAAA,EAAO,IAAA;EAAA,SACP,QAAA,EAAU,OAAA;AAAA;AAAA,UAGJ,SAAA,SAAkB,MAAA,CAAO,mBAAA;AAAA,cAE7B,kBAAA;EAAA;;mBAjCH,MAAA,CAAO,MAAA,CAAO,YAAA;IAAA,kBACX,MAAA,CAAO,MAAA,CAAO,YAAA;EAAA;EAAA;;oBAIhB,mBAAA;IAAA;;;;mBALD,MAAA,CAAO,MAAA,CAAO,YAAA;IAAA,kBACX,MAAA,CAAO,MAAA,CAAO,YAAA;EAAA;IAAA;;;oBAIhB,mBAAA;IAAA;;;;;;;;uBALD,MAAA,CAAO,MAAA,CAAO,YAAA;QAAA,kBACX,MAAA,CAAO,MAAA,CAAO,YAAA;MAAA;MAAA;;wBAIhB,mBAAA;QAAA;;;;qBALD,MAAA,CAAO,MAAA,CAAO,YAAA;MAAA,kBACX,MAAA,CAAO,MAAA,CAAO,YAAA;IAAA;MAAA;sBAIhB,mBAAA;MAAA;;;;;uBALD,MAAA,CAAO,MAAA,CAAO,YAAA;QAAA,kBACX,MAAA,CAAO,MAAA,CAAO,YAAA;MAAA;MAAA;;wBAIhB,mBAAA;QAAA;;;;qBALD,MAAA,CAAO,MAAA,CAAO,YAAA;MAAA,kBACX,MAAA,CAAO,MAAA,CAAO,YAAA;IAAA;MAAA;sBAIhB,mBAAA;MAAA;;;;cA8BE,OAAA,gBACE,MAAA,CAAO,MAAA,CAAO,YAAA,kBACX,MAAA,CAAO,MAAA,CAAO,YAAA,EAE9B,IAAA,EAAM,IAAA,EACN,OAAA,EAAS,OAAA;EAAA;iBAxCD,MAAA,CAAO,MAAA,CAAO,YAAA;EAAA,kBACX,MAAA,CAAO,MAAA,CAAO,YAAA;AAAA;AAAA,cA8Cd,MAAA,iBAAwB,mBAAA;EAAA;kBA1C1B,mBAAA;EAAA"}
|
package/dist/Ref.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { AnyAction as AnyAction$1, AnyMutation as AnyMutation$1, AnyQuery as AnyQuery$1, GetFunctionType as GetFunctionType$1, GetRuntime as GetRuntime$1, RuntimeAndFunctionType } from "./RuntimeAndFunctionType.js";
|
|
2
2
|
import { AnyWithProps, Args as Args$1, GetFunctionVisibility as GetFunctionVisibility$1, GetRuntimeAndFunctionType as GetRuntimeAndFunctionType$1, Returns as Returns$1 } from "./FunctionSpec.js";
|
|
3
|
-
import {
|
|
3
|
+
import { Effect, ParseResult } from "effect";
|
|
4
|
+
import { FunctionReference as FunctionReference$1, FunctionVisibility } from "convex/server";
|
|
4
5
|
|
|
5
6
|
//#region src/Ref.d.ts
|
|
6
7
|
declare namespace Ref_d_exports {
|
|
7
|
-
export { Any, AnyAction, AnyInternal, AnyMutation, AnyPublic, AnyPublicAction, AnyPublicMutation, AnyPublicQuery, AnyQuery, Args, FromFunctionSpec, GetFunctionType, GetFunctionVisibility, GetRuntime, GetRuntimeAndFunctionType, Ref, Returns, getConvexFunctionName,
|
|
8
|
+
export { Any, AnyAction, AnyInternal, AnyMutation, AnyPublic, AnyPublicAction, AnyPublicMutation, AnyPublicQuery, AnyQuery, Args, FromFunctionSpec, FunctionReference, GetFunctionType, GetFunctionVisibility, GetRuntime, GetRuntimeAndFunctionType, Ref, Returns, decodeReturns, decodeReturnsSync, encodeArgs, encodeArgsSync, getConvexFunctionName, getFunctionReference, make, runWithCodec };
|
|
8
9
|
}
|
|
9
10
|
interface Ref<_RuntimeAndFunctionType extends RuntimeAndFunctionType, _FunctionVisibility extends FunctionVisibility, _Args, _Returns> {
|
|
10
11
|
readonly _RuntimeAndFunctionType?: _RuntimeAndFunctionType;
|
|
@@ -27,15 +28,26 @@ type GetFunctionType<Ref_> = Ref_ extends Ref<infer RuntimeAndFunctionType_, inf
|
|
|
27
28
|
type GetFunctionVisibility<Ref_> = Ref_ extends Ref<infer _RuntimeAndFunctionType, infer FunctionVisibility_, infer _Args, infer _Returns> ? FunctionVisibility_ : never;
|
|
28
29
|
type Args<Ref_> = Ref_ extends Ref<infer _RuntimeAndFunctionType, infer _FunctionVisibility, infer Args_, infer _Returns> ? Args_ : never;
|
|
29
30
|
type Returns<Ref_> = Ref_ extends Ref<infer _RuntimeAndFunctionType, infer _FunctionVisibility, infer _Args, infer Returns_> ? Returns_ : never;
|
|
30
|
-
type
|
|
31
|
+
type FunctionReference<Ref_ extends Any> = FunctionReference$1<GetFunctionType<Ref_>, GetFunctionVisibility<Ref_>>;
|
|
32
|
+
type FromFunctionSpec<FunctionSpec_ extends AnyWithProps> = Ref<GetRuntimeAndFunctionType$1<FunctionSpec_>, GetFunctionVisibility$1<FunctionSpec_>, Args$1<FunctionSpec_>, Returns$1<FunctionSpec_>>;
|
|
31
33
|
declare const make: <FunctionSpec_ extends AnyWithProps>(
|
|
32
34
|
/**
|
|
33
|
-
*
|
|
35
|
+
* The namespace portion of a Convex function name, i.e. the part before the
|
|
36
|
+
* colon. For example, for `myGroupDir/myGroupMod:myFunc` this would be
|
|
37
|
+
* `myGroupDir/myGroupMod`.
|
|
34
38
|
*/
|
|
35
39
|
|
|
36
|
-
|
|
37
|
-
declare const getFunctionSpec: (ref: Any) => AnyWithProps;
|
|
40
|
+
functionNamespace: string, functionSpec: FunctionSpec_) => FromFunctionSpec<FunctionSpec_>;
|
|
38
41
|
declare const getConvexFunctionName: (ref: Any) => string;
|
|
42
|
+
declare const getFunctionReference: <Ref_ extends Any>(ref: Ref_) => FunctionReference<Ref_>;
|
|
43
|
+
declare const encodeArgs: <Ref_ extends Any>(ref: Ref_, args: Args<Ref_>) => Effect.Effect<unknown, ParseResult.ParseError>;
|
|
44
|
+
declare const decodeReturns: <Ref_ extends Any>(ref: Ref_, returns: unknown) => Effect.Effect<Returns<Ref_>, ParseResult.ParseError>;
|
|
45
|
+
declare const encodeArgsSync: <Ref_ extends Any>(ref: Ref_, args: Args<Ref_>) => unknown;
|
|
46
|
+
declare const decodeReturnsSync: <Ref_ extends Any>(ref: Ref_, encodedReturns: unknown) => Returns<Ref_>;
|
|
47
|
+
declare const runWithCodec: {
|
|
48
|
+
<Ref_ extends Any, E>(ref: Ref_, args: Args<Ref_>, f: (functionReference: FunctionReference<Ref_>, encodedArgs: unknown) => Effect.Effect<unknown, E>): Effect.Effect<Returns<Ref_>, E | ParseResult.ParseError>;
|
|
49
|
+
<Ref_ extends Any>(ref: Ref_, args: Args<Ref_>, f: (functionReference: FunctionReference<Ref_>, encodedArgs: unknown) => PromiseLike<unknown>): Effect.Effect<Returns<Ref_>, ParseResult.ParseError>;
|
|
50
|
+
};
|
|
39
51
|
//#endregion
|
|
40
|
-
export { Any, AnyAction, AnyInternal, AnyMutation, AnyPublic, AnyPublicAction, AnyPublicMutation, AnyPublicQuery, AnyQuery, Args, FromFunctionSpec, GetFunctionType, GetFunctionVisibility, GetRuntime, GetRuntimeAndFunctionType, Ref, Ref_d_exports, Returns, getConvexFunctionName,
|
|
52
|
+
export { Any, AnyAction, AnyInternal, AnyMutation, AnyPublic, AnyPublicAction, AnyPublicMutation, AnyPublicQuery, AnyQuery, Args, FromFunctionSpec, FunctionReference, GetFunctionType, GetFunctionVisibility, GetRuntime, GetRuntimeAndFunctionType, Ref, Ref_d_exports, Returns, decodeReturns, decodeReturnsSync, encodeArgs, encodeArgsSync, getConvexFunctionName, getFunctionReference, make, runWithCodec };
|
|
41
53
|
//# sourceMappingURL=Ref.d.ts.map
|
package/dist/Ref.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Ref.d.ts","names":[],"sources":["../src/Ref.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"Ref.d.ts","names":[],"sources":["../src/Ref.ts"],"mappings":"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"}
|
package/dist/Ref.js
CHANGED
|
@@ -1,20 +1,41 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { Effect, Match, Schema } from "effect";
|
|
3
|
+
import { makeFunctionReference } from "convex/server";
|
|
2
4
|
|
|
3
5
|
//#region src/Ref.ts
|
|
4
6
|
var Ref_exports = /* @__PURE__ */ __exportAll({
|
|
7
|
+
decodeReturns: () => decodeReturns,
|
|
8
|
+
decodeReturnsSync: () => decodeReturnsSync,
|
|
9
|
+
encodeArgs: () => encodeArgs,
|
|
10
|
+
encodeArgsSync: () => encodeArgsSync,
|
|
5
11
|
getConvexFunctionName: () => getConvexFunctionName,
|
|
6
|
-
|
|
7
|
-
make: () => make
|
|
12
|
+
getFunctionReference: () => getFunctionReference,
|
|
13
|
+
make: () => make,
|
|
14
|
+
runWithCodec: () => runWithCodec
|
|
8
15
|
});
|
|
9
|
-
const make = (
|
|
10
|
-
|
|
11
|
-
|
|
16
|
+
const make = (functionNamespace, functionSpec) => ({
|
|
17
|
+
functionSpec,
|
|
18
|
+
functionNamespace
|
|
19
|
+
});
|
|
20
|
+
const getConvexFunctionName = (ref) => `${ref.functionNamespace}:${ref.functionSpec.name}`;
|
|
21
|
+
const getFunctionReference = (ref) => makeFunctionReference(getConvexFunctionName(ref));
|
|
22
|
+
const encodeArgs = (ref, args) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (c) => Schema.encode(c.args)(args)), Match.tag("Convex", () => Effect.succeed(args)), Match.exhaustive);
|
|
23
|
+
const decodeReturns = (ref, returns) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (c) => Schema.decode(c.returns)(returns)), Match.tag("Convex", () => Effect.succeed(returns)), Match.exhaustive);
|
|
24
|
+
const encodeArgsSync = (ref, args) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (c) => Schema.encodeSync(c.args)(args)), Match.tag("Convex", () => args), Match.exhaustive);
|
|
25
|
+
const decodeReturnsSync = (ref, encodedReturns) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (c) => Schema.decodeSync(c.returns)(encodedReturns)), Match.tag("Convex", () => encodedReturns), Match.exhaustive);
|
|
26
|
+
const runWithCodec = (ref, args, f) => Effect.gen(function* () {
|
|
27
|
+
const functionReference = getFunctionReference(ref);
|
|
28
|
+
const functionProvenance = ref.functionSpec.functionProvenance;
|
|
29
|
+
const call = (encodedArgs) => {
|
|
30
|
+
const result = f(functionReference, encodedArgs);
|
|
31
|
+
return Effect.isEffect(result) ? result : Effect.promise(() => result);
|
|
32
|
+
};
|
|
33
|
+
return yield* Match.value(functionProvenance).pipe(Match.tag("Confect", (confect) => Effect.gen(function* () {
|
|
34
|
+
const encodedReturns = yield* call(yield* Schema.encode(confect.args)(args));
|
|
35
|
+
return yield* Schema.decode(confect.returns)(encodedReturns);
|
|
36
|
+
})), Match.tag("Convex", () => call(args)), Match.exhaustive);
|
|
12
37
|
});
|
|
13
|
-
const HiddenFunctionSpecKey = "@confect/core/api/HiddenFunctionSpecKey";
|
|
14
|
-
const getFunctionSpec = (ref) => ref[HiddenFunctionSpecKey];
|
|
15
|
-
const HiddenConvexFunctionNameKey = "@confect/core/api/HiddenConvexFunctionNameKey";
|
|
16
|
-
const getConvexFunctionName = (ref) => ref[HiddenConvexFunctionNameKey];
|
|
17
38
|
|
|
18
39
|
//#endregion
|
|
19
|
-
export { Ref_exports, getConvexFunctionName,
|
|
40
|
+
export { Ref_exports, decodeReturns, decodeReturnsSync, encodeArgs, encodeArgsSync, getConvexFunctionName, getFunctionReference, make, runWithCodec };
|
|
20
41
|
//# sourceMappingURL=Ref.js.map
|
package/dist/Ref.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Ref.js","names":[],"sources":["../src/Ref.ts"],"sourcesContent":["import type { FunctionVisibility } from \"convex/server\";\nimport type * as FunctionSpec from \"./FunctionSpec\";\nimport type * as RuntimeAndFunctionType from \"./RuntimeAndFunctionType\";\n\nexport interface Ref<\n _RuntimeAndFunctionType extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n _FunctionVisibility extends FunctionVisibility,\n _Args,\n _Returns,\n> {\n readonly _RuntimeAndFunctionType?: _RuntimeAndFunctionType;\n readonly _FunctionVisibility?: _FunctionVisibility;\n readonly _Args?: _Args;\n readonly _Returns?: _Returns;\n}\n\nexport interface Any extends Ref<any, any, any, any> {}\n\nexport interface AnyInternal extends Ref<any, \"internal\", any, any> {}\n\nexport interface AnyPublic extends Ref<any, \"public\", any, any> {}\n\nexport interface AnyQuery extends Ref<\n RuntimeAndFunctionType.AnyQuery,\n FunctionVisibility,\n any,\n any\n> {}\n\nexport interface AnyMutation extends Ref<\n RuntimeAndFunctionType.AnyMutation,\n FunctionVisibility,\n any,\n any\n> {}\n\nexport interface AnyAction extends Ref<\n RuntimeAndFunctionType.AnyAction,\n FunctionVisibility,\n any,\n any\n> {}\n\nexport interface AnyPublicQuery extends Ref<\n RuntimeAndFunctionType.AnyQuery,\n \"public\",\n any,\n any\n> {}\n\nexport interface AnyPublicMutation extends Ref<\n RuntimeAndFunctionType.AnyMutation,\n \"public\",\n any,\n any\n> {}\n\nexport interface AnyPublicAction extends Ref<\n RuntimeAndFunctionType.AnyAction,\n \"public\",\n any,\n any\n> {}\n\nexport type GetRuntimeAndFunctionType<Ref_> =\n Ref_ extends Ref<\n infer RuntimeAndFunctionType_,\n infer _FunctionVisibility,\n infer _Args,\n infer _Returns\n >\n ? RuntimeAndFunctionType_\n : never;\n\nexport type GetRuntime<Ref_> =\n Ref_ extends Ref<\n infer RuntimeAndFunctionType_,\n infer _FunctionVisibility,\n infer _Args,\n infer _Returns\n >\n ? RuntimeAndFunctionType.GetRuntime<RuntimeAndFunctionType_>\n : never;\n\nexport type GetFunctionType<Ref_> =\n Ref_ extends Ref<\n infer RuntimeAndFunctionType_,\n infer _FunctionVisibility,\n infer _Args,\n infer _Returns\n >\n ? RuntimeAndFunctionType.GetFunctionType<RuntimeAndFunctionType_>\n : never;\n\nexport type GetFunctionVisibility<Ref_> =\n Ref_ extends Ref<\n infer _RuntimeAndFunctionType,\n infer FunctionVisibility_,\n infer _Args,\n infer _Returns\n >\n ? FunctionVisibility_\n : never;\n\nexport type Args<Ref_> =\n Ref_ extends Ref<\n infer _RuntimeAndFunctionType,\n infer _FunctionVisibility,\n infer Args_,\n infer _Returns\n >\n ? Args_\n : never;\n\nexport type Returns<Ref_> =\n Ref_ extends Ref<\n infer _RuntimeAndFunctionType,\n infer _FunctionVisibility,\n infer _Args,\n infer Returns_\n >\n ? Returns_\n : never;\n\nexport type FromFunctionSpec<
|
|
1
|
+
{"version":3,"file":"Ref.js","names":[],"sources":["../src/Ref.ts"],"sourcesContent":["import type {\n FunctionReference as ConvexFunctionReference,\n FunctionVisibility,\n} from \"convex/server\";\nimport { makeFunctionReference } from \"convex/server\";\nimport type { ParseResult } from \"effect\";\nimport { Effect, Match, Schema } from \"effect\";\nimport type * as FunctionSpec from \"./FunctionSpec\";\nimport type * as RuntimeAndFunctionType from \"./RuntimeAndFunctionType\";\n\nexport interface Ref<\n _RuntimeAndFunctionType extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n _FunctionVisibility extends FunctionVisibility,\n _Args,\n _Returns,\n> {\n readonly _RuntimeAndFunctionType?: _RuntimeAndFunctionType;\n readonly _FunctionVisibility?: _FunctionVisibility;\n readonly _Args?: _Args;\n readonly _Returns?: _Returns;\n /** @internal */\n readonly functionSpec: FunctionSpec.AnyWithProps;\n /** @internal */\n readonly functionNamespace: string;\n}\n\nexport interface Any extends Ref<any, any, any, any> {}\n\nexport interface AnyInternal extends Ref<any, \"internal\", any, any> {}\n\nexport interface AnyPublic extends Ref<any, \"public\", any, any> {}\n\nexport interface AnyQuery extends Ref<\n RuntimeAndFunctionType.AnyQuery,\n FunctionVisibility,\n any,\n any\n> {}\n\nexport interface AnyMutation extends Ref<\n RuntimeAndFunctionType.AnyMutation,\n FunctionVisibility,\n any,\n any\n> {}\n\nexport interface AnyAction extends Ref<\n RuntimeAndFunctionType.AnyAction,\n FunctionVisibility,\n any,\n any\n> {}\n\nexport interface AnyPublicQuery extends Ref<\n RuntimeAndFunctionType.AnyQuery,\n \"public\",\n any,\n any\n> {}\n\nexport interface AnyPublicMutation extends Ref<\n RuntimeAndFunctionType.AnyMutation,\n \"public\",\n any,\n any\n> {}\n\nexport interface AnyPublicAction extends Ref<\n RuntimeAndFunctionType.AnyAction,\n \"public\",\n any,\n any\n> {}\n\nexport type GetRuntimeAndFunctionType<Ref_> =\n Ref_ extends Ref<\n infer RuntimeAndFunctionType_,\n infer _FunctionVisibility,\n infer _Args,\n infer _Returns\n >\n ? RuntimeAndFunctionType_\n : never;\n\nexport type GetRuntime<Ref_> =\n Ref_ extends Ref<\n infer RuntimeAndFunctionType_,\n infer _FunctionVisibility,\n infer _Args,\n infer _Returns\n >\n ? RuntimeAndFunctionType.GetRuntime<RuntimeAndFunctionType_>\n : never;\n\nexport type GetFunctionType<Ref_> =\n Ref_ extends Ref<\n infer RuntimeAndFunctionType_,\n infer _FunctionVisibility,\n infer _Args,\n infer _Returns\n >\n ? RuntimeAndFunctionType.GetFunctionType<RuntimeAndFunctionType_>\n : never;\n\nexport type GetFunctionVisibility<Ref_> =\n Ref_ extends Ref<\n infer _RuntimeAndFunctionType,\n infer FunctionVisibility_,\n infer _Args,\n infer _Returns\n >\n ? FunctionVisibility_\n : never;\n\nexport type Args<Ref_> =\n Ref_ extends Ref<\n infer _RuntimeAndFunctionType,\n infer _FunctionVisibility,\n infer Args_,\n infer _Returns\n >\n ? Args_\n : never;\n\nexport type Returns<Ref_> =\n Ref_ extends Ref<\n infer _RuntimeAndFunctionType,\n infer _FunctionVisibility,\n infer _Args,\n infer Returns_\n >\n ? Returns_\n : never;\n\nexport type FunctionReference<Ref_ extends Any> = ConvexFunctionReference<\n GetFunctionType<Ref_>,\n GetFunctionVisibility<Ref_>\n>;\n\nexport type FromFunctionSpec<FunctionSpec_ extends FunctionSpec.AnyWithProps> =\n Ref<\n FunctionSpec.GetRuntimeAndFunctionType<FunctionSpec_>,\n FunctionSpec.GetFunctionVisibility<FunctionSpec_>,\n FunctionSpec.Args<FunctionSpec_>,\n FunctionSpec.Returns<FunctionSpec_>\n >;\n\nexport const make = <FunctionSpec_ extends FunctionSpec.AnyWithProps>(\n /**\n * The namespace portion of a Convex function name, i.e. the part before the\n * colon. For example, for `myGroupDir/myGroupMod:myFunc` this would be\n * `myGroupDir/myGroupMod`.\n */\n functionNamespace: string,\n functionSpec: FunctionSpec_,\n): FromFunctionSpec<FunctionSpec_> => ({ functionSpec, functionNamespace });\n\nexport const getConvexFunctionName = (ref: Any): string =>\n `${ref.functionNamespace}:${ref.functionSpec.name}`;\n\nexport const getFunctionReference = <Ref_ extends Any>(\n ref: Ref_,\n): FunctionReference<Ref_> =>\n makeFunctionReference(getConvexFunctionName(ref)) as FunctionReference<Ref_>;\n\nexport const encodeArgs = <Ref_ extends Any>(\n ref: Ref_,\n args: Args<Ref_>,\n): Effect.Effect<unknown, ParseResult.ParseError> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (c) => Schema.encode(c.args)(args)),\n Match.tag(\"Convex\", () => Effect.succeed(args)),\n Match.exhaustive,\n );\n\nexport const decodeReturns = <Ref_ extends Any>(\n ref: Ref_,\n returns: unknown,\n): Effect.Effect<Returns<Ref_>, ParseResult.ParseError> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (c) => Schema.decode(c.returns)(returns)),\n Match.tag(\"Convex\", () => Effect.succeed(returns)),\n Match.exhaustive,\n );\n\nexport const encodeArgsSync = <Ref_ extends Any>(\n ref: Ref_,\n args: Args<Ref_>,\n): unknown =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (c) => Schema.encodeSync(c.args)(args)),\n Match.tag(\"Convex\", () => args),\n Match.exhaustive,\n );\n\nexport const decodeReturnsSync = <Ref_ extends Any>(\n ref: Ref_,\n encodedReturns: unknown,\n): Returns<Ref_> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (c) => Schema.decodeSync(c.returns)(encodedReturns)),\n Match.tag(\"Convex\", () => encodedReturns),\n Match.exhaustive,\n ) as Returns<Ref_>;\n\nexport const runWithCodec: {\n <Ref_ extends Any, E>(\n ref: Ref_,\n args: Args<Ref_>,\n f: (\n functionReference: FunctionReference<Ref_>,\n encodedArgs: unknown,\n ) => Effect.Effect<unknown, E>,\n ): Effect.Effect<Returns<Ref_>, E | ParseResult.ParseError>;\n <Ref_ extends Any>(\n ref: Ref_,\n args: Args<Ref_>,\n f: (\n functionReference: FunctionReference<Ref_>,\n encodedArgs: unknown,\n ) => PromiseLike<unknown>,\n ): Effect.Effect<Returns<Ref_>, ParseResult.ParseError>;\n} = <Ref_ extends Any, E>(\n ref: Ref_,\n args: Args<Ref_>,\n f: (\n functionReference: FunctionReference<Ref_>,\n encodedArgs: unknown,\n ) => Effect.Effect<unknown, E> | PromiseLike<unknown>,\n): Effect.Effect<Returns<Ref_>, E | ParseResult.ParseError> =>\n Effect.gen(function* () {\n const functionReference = getFunctionReference(ref);\n const functionProvenance = ref.functionSpec.functionProvenance;\n const call = (encodedArgs: unknown) => {\n const result = f(functionReference, encodedArgs);\n return Effect.isEffect(result) ? result : Effect.promise(() => result);\n };\n return yield* Match.value(functionProvenance).pipe(\n Match.tag(\"Confect\", (confect) =>\n Effect.gen(function* () {\n const encodedArgs = yield* Schema.encode(confect.args)(args);\n const encodedReturns = yield* call(encodedArgs);\n return yield* Schema.decode(confect.returns)(encodedReturns);\n }),\n ),\n Match.tag(\"Convex\", () => call(args)),\n Match.exhaustive,\n );\n });\n"],"mappings":";;;;;;;;;;;;;;;AAmJA,MAAa,QAMX,mBACA,kBACqC;CAAE;CAAc;CAAmB;AAE1E,MAAa,yBAAyB,QACpC,GAAG,IAAI,kBAAkB,GAAG,IAAI,aAAa;AAE/C,MAAa,wBACX,QAEA,sBAAsB,sBAAsB,IAAI,CAAC;AAEnD,MAAa,cACX,KACA,SAEA,MAAM,MAAM,IAAI,aAAa,mBAAmB,CAAC,KAC/C,MAAM,IAAI,YAAY,MAAM,OAAO,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,EACxD,MAAM,IAAI,gBAAgB,OAAO,QAAQ,KAAK,CAAC,EAC/C,MAAM,WACP;AAEH,MAAa,iBACX,KACA,YAEA,MAAM,MAAM,IAAI,aAAa,mBAAmB,CAAC,KAC/C,MAAM,IAAI,YAAY,MAAM,OAAO,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAC9D,MAAM,IAAI,gBAAgB,OAAO,QAAQ,QAAQ,CAAC,EAClD,MAAM,WACP;AAEH,MAAa,kBACX,KACA,SAEA,MAAM,MAAM,IAAI,aAAa,mBAAmB,CAAC,KAC/C,MAAM,IAAI,YAAY,MAAM,OAAO,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,EAC5D,MAAM,IAAI,gBAAgB,KAAK,EAC/B,MAAM,WACP;AAEH,MAAa,qBACX,KACA,mBAEA,MAAM,MAAM,IAAI,aAAa,mBAAmB,CAAC,KAC/C,MAAM,IAAI,YAAY,MAAM,OAAO,WAAW,EAAE,QAAQ,CAAC,eAAe,CAAC,EACzE,MAAM,IAAI,gBAAgB,eAAe,EACzC,MAAM,WACP;AAEH,MAAa,gBAkBX,KACA,MACA,MAKA,OAAO,IAAI,aAAa;CACtB,MAAM,oBAAoB,qBAAqB,IAAI;CACnD,MAAM,qBAAqB,IAAI,aAAa;CAC5C,MAAM,QAAQ,gBAAyB;EACrC,MAAM,SAAS,EAAE,mBAAmB,YAAY;AAChD,SAAO,OAAO,SAAS,OAAO,GAAG,SAAS,OAAO,cAAc,OAAO;;AAExE,QAAO,OAAO,MAAM,MAAM,mBAAmB,CAAC,KAC5C,MAAM,IAAI,YAAY,YACpB,OAAO,IAAI,aAAa;EAEtB,MAAM,iBAAiB,OAAO,KADV,OAAO,OAAO,OAAO,QAAQ,KAAK,CAAC,KAAK,CACb;AAC/C,SAAO,OAAO,OAAO,OAAO,QAAQ,QAAQ,CAAC,eAAe;GAC5D,CACH,EACD,MAAM,IAAI,gBAAgB,KAAK,KAAK,CAAC,EACrC,MAAM,WACP;EACD"}
|
package/dist/Refs.js
CHANGED
|
@@ -16,9 +16,9 @@ const make = (convexSpec, nodeSpec) => {
|
|
|
16
16
|
internal: refs
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
|
-
const makeHelper = (groups,
|
|
20
|
-
const
|
|
21
|
-
return Record.union(makeHelper(group.groups,
|
|
19
|
+
const makeHelper = (groups, functionNamespace = null) => pipe(groups, Record.map((group) => {
|
|
20
|
+
const currentFunctionNamespace = functionNamespace ? `${functionNamespace}/${group.name}` : group.name;
|
|
21
|
+
return Record.union(makeHelper(group.groups, currentFunctionNamespace), Record.map(group.functions, (function_) => make$1(currentFunctionNamespace, function_)), (_subGroup, _function) => {
|
|
22
22
|
throw new Error(`Group and function at same level have same name ('${getConvexFunctionName(_function)}')`);
|
|
23
23
|
});
|
|
24
24
|
}));
|
package/dist/Refs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Refs.js","names":["GroupSpec.makeNode","Ref.make","Ref.getConvexFunctionName"],"sources":["../src/Refs.ts"],"sourcesContent":["import type { Types } from \"effect\";\nimport { Array, pipe, Record } from \"effect\";\nimport type * as FunctionSpec from \"./FunctionSpec\";\nimport * as GroupSpec from \"./GroupSpec\";\nimport * as Ref from \"./Ref\";\nimport type * as Spec from \"./Spec\";\n\nexport type Refs<\n ConvexSpec extends Spec.AnyWithPropsWithRuntime<\"Convex\">,\n NodeSpec extends Spec.AnyWithPropsWithRuntime<\"Node\"> = never,\n Predicate extends Ref.Any = Ref.Any,\n> = Types.Simplify<\n OmitEmpty<\n Helper<\n | Spec.Groups<ConvexSpec>\n | (NodeSpec extends never\n ? never\n : GroupSpec.GroupSpec<\n \"Node\",\n \"node\",\n never,\n NodeSpec[\"groups\"][keyof NodeSpec[\"groups\"]]\n >),\n Predicate\n >\n >\n>;\n\ntype GroupRefs<\n Group extends GroupSpec.AnyWithProps,\n Predicate extends Ref.Any,\n> = Types.Simplify<\n OmitEmpty<Helper<GroupSpec.Groups<Group>, Predicate>> &\n FilteredFunctions<GroupSpec.Functions<Group>, Predicate>\n>;\n\ntype OmitEmpty<T> = {\n [K in keyof T as keyof T[K] extends never ? never : K]: T[K];\n};\n\ntype FunctionSpecMatchesPredicate<\n FunctionSpec_ extends FunctionSpec.AnyWithProps,\n Predicate extends Ref.Any,\n> =\n Ref.Ref<\n FunctionSpec.GetRuntimeAndFunctionType<FunctionSpec_>,\n FunctionSpec.GetFunctionVisibility<FunctionSpec_>,\n any,\n any\n > extends Predicate\n ? true\n : false;\n\ntype FilteredFunctions<\n FunctionSpecs extends FunctionSpec.AnyWithProps,\n Predicate extends Ref.Any,\n> = {\n [Name in FunctionSpec.Name<FunctionSpecs> as FunctionSpec.WithName<\n FunctionSpecs,\n Name\n > extends infer FunctionSpec_ extends FunctionSpec.AnyWithProps\n ? FunctionSpecMatchesPredicate<FunctionSpec_, Predicate> extends true\n ? Name\n : never\n : never]: FunctionSpec.WithName<FunctionSpecs, Name> extends infer F extends\n FunctionSpec.AnyWithProps\n ? Ref.FromFunctionSpec<F>\n : never;\n};\n\ntype Helper<\n Groups extends GroupSpec.AnyWithProps,\n Predicate extends Ref.Any,\n> = {\n [GroupName in GroupSpec.Name<Groups>]: GroupSpec.WithName<\n Groups,\n GroupName\n > extends infer Group extends GroupSpec.AnyWithProps\n ? GroupRefs<Group, Predicate>\n : never;\n};\n\ntype Any =\n | {\n readonly [key: string]: Any;\n }\n | Ref.Any;\n\nexport const make = <\n ConvexSpec extends Spec.AnyWithPropsWithRuntime<\"Convex\">,\n NodeSpec extends Spec.AnyWithPropsWithRuntime<\"Node\"> = never,\n>(\n convexSpec: ConvexSpec,\n nodeSpec?: NodeSpec,\n): {\n public: Refs<ConvexSpec, NodeSpec, Ref.AnyPublic>;\n internal: Refs<ConvexSpec, NodeSpec, Ref.AnyInternal>;\n} => {\n const nodeGroup = nodeSpec\n ? Array.reduce(\n Record.values(nodeSpec.groups),\n GroupSpec.makeNode(\"node\"),\n (nodeGroupSpec, group) => nodeGroupSpec.addGroup(group),\n )\n : null;\n\n const groups = nodeGroup\n ? { ...convexSpec.groups, node: nodeGroup }\n : convexSpec.groups;\n const refs = makeHelper(groups);\n return {\n public: refs as Refs<ConvexSpec, NodeSpec, Ref.AnyPublic>,\n internal: refs as Refs<ConvexSpec, NodeSpec, Ref.AnyInternal>,\n };\n};\n\nconst makeHelper = (\n groups: Record.ReadonlyRecord<string, GroupSpec.Any>,\n
|
|
1
|
+
{"version":3,"file":"Refs.js","names":["GroupSpec.makeNode","Ref.make","Ref.getConvexFunctionName"],"sources":["../src/Refs.ts"],"sourcesContent":["import type { Types } from \"effect\";\nimport { Array, pipe, Record } from \"effect\";\nimport type * as FunctionSpec from \"./FunctionSpec\";\nimport * as GroupSpec from \"./GroupSpec\";\nimport * as Ref from \"./Ref\";\nimport type * as Spec from \"./Spec\";\n\nexport type Refs<\n ConvexSpec extends Spec.AnyWithPropsWithRuntime<\"Convex\">,\n NodeSpec extends Spec.AnyWithPropsWithRuntime<\"Node\"> = never,\n Predicate extends Ref.Any = Ref.Any,\n> = Types.Simplify<\n OmitEmpty<\n Helper<\n | Spec.Groups<ConvexSpec>\n | (NodeSpec extends never\n ? never\n : GroupSpec.GroupSpec<\n \"Node\",\n \"node\",\n never,\n NodeSpec[\"groups\"][keyof NodeSpec[\"groups\"]]\n >),\n Predicate\n >\n >\n>;\n\ntype GroupRefs<\n Group extends GroupSpec.AnyWithProps,\n Predicate extends Ref.Any,\n> = Types.Simplify<\n OmitEmpty<Helper<GroupSpec.Groups<Group>, Predicate>> &\n FilteredFunctions<GroupSpec.Functions<Group>, Predicate>\n>;\n\ntype OmitEmpty<T> = {\n [K in keyof T as keyof T[K] extends never ? never : K]: T[K];\n};\n\ntype FunctionSpecMatchesPredicate<\n FunctionSpec_ extends FunctionSpec.AnyWithProps,\n Predicate extends Ref.Any,\n> =\n Ref.Ref<\n FunctionSpec.GetRuntimeAndFunctionType<FunctionSpec_>,\n FunctionSpec.GetFunctionVisibility<FunctionSpec_>,\n any,\n any\n > extends Predicate\n ? true\n : false;\n\ntype FilteredFunctions<\n FunctionSpecs extends FunctionSpec.AnyWithProps,\n Predicate extends Ref.Any,\n> = {\n [Name in FunctionSpec.Name<FunctionSpecs> as FunctionSpec.WithName<\n FunctionSpecs,\n Name\n > extends infer FunctionSpec_ extends FunctionSpec.AnyWithProps\n ? FunctionSpecMatchesPredicate<FunctionSpec_, Predicate> extends true\n ? Name\n : never\n : never]: FunctionSpec.WithName<FunctionSpecs, Name> extends infer F extends\n FunctionSpec.AnyWithProps\n ? Ref.FromFunctionSpec<F>\n : never;\n};\n\ntype Helper<\n Groups extends GroupSpec.AnyWithProps,\n Predicate extends Ref.Any,\n> = {\n [GroupName in GroupSpec.Name<Groups>]: GroupSpec.WithName<\n Groups,\n GroupName\n > extends infer Group extends GroupSpec.AnyWithProps\n ? GroupRefs<Group, Predicate>\n : never;\n};\n\ntype Any =\n | {\n readonly [key: string]: Any;\n }\n | Ref.Any;\n\nexport const make = <\n ConvexSpec extends Spec.AnyWithPropsWithRuntime<\"Convex\">,\n NodeSpec extends Spec.AnyWithPropsWithRuntime<\"Node\"> = never,\n>(\n convexSpec: ConvexSpec,\n nodeSpec?: NodeSpec,\n): {\n public: Refs<ConvexSpec, NodeSpec, Ref.AnyPublic>;\n internal: Refs<ConvexSpec, NodeSpec, Ref.AnyInternal>;\n} => {\n const nodeGroup = nodeSpec\n ? Array.reduce(\n Record.values(nodeSpec.groups),\n GroupSpec.makeNode(\"node\"),\n (nodeGroupSpec, group) => nodeGroupSpec.addGroup(group),\n )\n : null;\n\n const groups = nodeGroup\n ? { ...convexSpec.groups, node: nodeGroup }\n : convexSpec.groups;\n const refs = makeHelper(groups);\n return {\n public: refs as Refs<ConvexSpec, NodeSpec, Ref.AnyPublic>,\n internal: refs as Refs<ConvexSpec, NodeSpec, Ref.AnyInternal>,\n };\n};\n\nconst makeHelper = (\n groups: Record.ReadonlyRecord<string, GroupSpec.Any>,\n functionNamespace: string | null = null,\n): Any =>\n pipe(\n groups as Record.ReadonlyRecord<string, GroupSpec.AnyWithProps>,\n Record.map((group) => {\n const currentFunctionNamespace = functionNamespace\n ? `${functionNamespace}/${group.name}`\n : group.name;\n\n return Record.union(\n makeHelper(group.groups, currentFunctionNamespace),\n Record.map(group.functions, (function_) =>\n Ref.make(currentFunctionNamespace, function_),\n ),\n (_subGroup, _function) => {\n throw new Error(\n `Group and function at same level have same name ('${Ref.getConvexFunctionName(_function)}')`,\n );\n },\n );\n }),\n );\n"],"mappings":";;;;;;;AAwFA,MAAa,QAIX,YACA,aAIG;CACH,MAAM,YAAY,WACd,MAAM,OACJ,OAAO,OAAO,SAAS,OAAO,EAC9BA,SAAmB,OAAO,GACzB,eAAe,UAAU,cAAc,SAAS,MAAM,CACxD,GACD;CAKJ,MAAM,OAAO,WAHE,YACX;EAAE,GAAG,WAAW;EAAQ,MAAM;EAAW,GACzC,WAAW,OACgB;AAC/B,QAAO;EACL,QAAQ;EACR,UAAU;EACX;;AAGH,MAAM,cACJ,QACA,oBAAmC,SAEnC,KACE,QACA,OAAO,KAAK,UAAU;CACpB,MAAM,2BAA2B,oBAC7B,GAAG,kBAAkB,GAAG,MAAM,SAC9B,MAAM;AAEV,QAAO,OAAO,MACZ,WAAW,MAAM,QAAQ,yBAAyB,EAClD,OAAO,IAAI,MAAM,YAAY,cAC3BC,OAAS,0BAA0B,UAAU,CAC9C,GACA,WAAW,cAAc;AACxB,QAAM,IAAI,MACR,qDAAqDC,sBAA0B,UAAU,CAAC,IAC3F;GAEJ;EACD,CACH"}
|
package/package.json
CHANGED
package/src/Ref.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
FunctionReference as ConvexFunctionReference,
|
|
3
|
+
FunctionVisibility,
|
|
4
|
+
} from "convex/server";
|
|
5
|
+
import { makeFunctionReference } from "convex/server";
|
|
6
|
+
import type { ParseResult } from "effect";
|
|
7
|
+
import { Effect, Match, Schema } from "effect";
|
|
2
8
|
import type * as FunctionSpec from "./FunctionSpec";
|
|
3
9
|
import type * as RuntimeAndFunctionType from "./RuntimeAndFunctionType";
|
|
4
10
|
|
|
@@ -12,6 +18,10 @@ export interface Ref<
|
|
|
12
18
|
readonly _FunctionVisibility?: _FunctionVisibility;
|
|
13
19
|
readonly _Args?: _Args;
|
|
14
20
|
readonly _Returns?: _Returns;
|
|
21
|
+
/** @internal */
|
|
22
|
+
readonly functionSpec: FunctionSpec.AnyWithProps;
|
|
23
|
+
/** @internal */
|
|
24
|
+
readonly functionNamespace: string;
|
|
15
25
|
}
|
|
16
26
|
|
|
17
27
|
export interface Any extends Ref<any, any, any, any> {}
|
|
@@ -122,32 +132,118 @@ export type Returns<Ref_> =
|
|
|
122
132
|
? Returns_
|
|
123
133
|
: never;
|
|
124
134
|
|
|
125
|
-
export type
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
FunctionSpec.Args<F>,
|
|
129
|
-
FunctionSpec.Returns<F>
|
|
135
|
+
export type FunctionReference<Ref_ extends Any> = ConvexFunctionReference<
|
|
136
|
+
GetFunctionType<Ref_>,
|
|
137
|
+
GetFunctionVisibility<Ref_>
|
|
130
138
|
>;
|
|
131
139
|
|
|
140
|
+
export type FromFunctionSpec<FunctionSpec_ extends FunctionSpec.AnyWithProps> =
|
|
141
|
+
Ref<
|
|
142
|
+
FunctionSpec.GetRuntimeAndFunctionType<FunctionSpec_>,
|
|
143
|
+
FunctionSpec.GetFunctionVisibility<FunctionSpec_>,
|
|
144
|
+
FunctionSpec.Args<FunctionSpec_>,
|
|
145
|
+
FunctionSpec.Returns<FunctionSpec_>
|
|
146
|
+
>;
|
|
147
|
+
|
|
132
148
|
export const make = <FunctionSpec_ extends FunctionSpec.AnyWithProps>(
|
|
133
149
|
/**
|
|
134
|
-
*
|
|
150
|
+
* The namespace portion of a Convex function name, i.e. the part before the
|
|
151
|
+
* colon. For example, for `myGroupDir/myGroupMod:myFunc` this would be
|
|
152
|
+
* `myGroupDir/myGroupMod`.
|
|
135
153
|
*/
|
|
136
|
-
|
|
154
|
+
functionNamespace: string,
|
|
137
155
|
functionSpec: FunctionSpec_,
|
|
138
|
-
): FromFunctionSpec<FunctionSpec_> =>
|
|
139
|
-
({
|
|
140
|
-
[HiddenFunctionSpecKey]: functionSpec,
|
|
141
|
-
[HiddenConvexFunctionNameKey]: convexFunctionName,
|
|
142
|
-
}) as FromFunctionSpec<FunctionSpec_>;
|
|
143
|
-
|
|
144
|
-
const HiddenFunctionSpecKey = "@confect/core/api/HiddenFunctionSpecKey";
|
|
145
|
-
|
|
146
|
-
export const getFunctionSpec = (ref: Any): FunctionSpec.AnyWithProps =>
|
|
147
|
-
(ref as any)[HiddenFunctionSpecKey];
|
|
148
|
-
|
|
149
|
-
const HiddenConvexFunctionNameKey =
|
|
150
|
-
"@confect/core/api/HiddenConvexFunctionNameKey";
|
|
156
|
+
): FromFunctionSpec<FunctionSpec_> => ({ functionSpec, functionNamespace });
|
|
151
157
|
|
|
152
158
|
export const getConvexFunctionName = (ref: Any): string =>
|
|
153
|
-
|
|
159
|
+
`${ref.functionNamespace}:${ref.functionSpec.name}`;
|
|
160
|
+
|
|
161
|
+
export const getFunctionReference = <Ref_ extends Any>(
|
|
162
|
+
ref: Ref_,
|
|
163
|
+
): FunctionReference<Ref_> =>
|
|
164
|
+
makeFunctionReference(getConvexFunctionName(ref)) as FunctionReference<Ref_>;
|
|
165
|
+
|
|
166
|
+
export const encodeArgs = <Ref_ extends Any>(
|
|
167
|
+
ref: Ref_,
|
|
168
|
+
args: Args<Ref_>,
|
|
169
|
+
): Effect.Effect<unknown, ParseResult.ParseError> =>
|
|
170
|
+
Match.value(ref.functionSpec.functionProvenance).pipe(
|
|
171
|
+
Match.tag("Confect", (c) => Schema.encode(c.args)(args)),
|
|
172
|
+
Match.tag("Convex", () => Effect.succeed(args)),
|
|
173
|
+
Match.exhaustive,
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
export const decodeReturns = <Ref_ extends Any>(
|
|
177
|
+
ref: Ref_,
|
|
178
|
+
returns: unknown,
|
|
179
|
+
): Effect.Effect<Returns<Ref_>, ParseResult.ParseError> =>
|
|
180
|
+
Match.value(ref.functionSpec.functionProvenance).pipe(
|
|
181
|
+
Match.tag("Confect", (c) => Schema.decode(c.returns)(returns)),
|
|
182
|
+
Match.tag("Convex", () => Effect.succeed(returns)),
|
|
183
|
+
Match.exhaustive,
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
export const encodeArgsSync = <Ref_ extends Any>(
|
|
187
|
+
ref: Ref_,
|
|
188
|
+
args: Args<Ref_>,
|
|
189
|
+
): unknown =>
|
|
190
|
+
Match.value(ref.functionSpec.functionProvenance).pipe(
|
|
191
|
+
Match.tag("Confect", (c) => Schema.encodeSync(c.args)(args)),
|
|
192
|
+
Match.tag("Convex", () => args),
|
|
193
|
+
Match.exhaustive,
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
export const decodeReturnsSync = <Ref_ extends Any>(
|
|
197
|
+
ref: Ref_,
|
|
198
|
+
encodedReturns: unknown,
|
|
199
|
+
): Returns<Ref_> =>
|
|
200
|
+
Match.value(ref.functionSpec.functionProvenance).pipe(
|
|
201
|
+
Match.tag("Confect", (c) => Schema.decodeSync(c.returns)(encodedReturns)),
|
|
202
|
+
Match.tag("Convex", () => encodedReturns),
|
|
203
|
+
Match.exhaustive,
|
|
204
|
+
) as Returns<Ref_>;
|
|
205
|
+
|
|
206
|
+
export const runWithCodec: {
|
|
207
|
+
<Ref_ extends Any, E>(
|
|
208
|
+
ref: Ref_,
|
|
209
|
+
args: Args<Ref_>,
|
|
210
|
+
f: (
|
|
211
|
+
functionReference: FunctionReference<Ref_>,
|
|
212
|
+
encodedArgs: unknown,
|
|
213
|
+
) => Effect.Effect<unknown, E>,
|
|
214
|
+
): Effect.Effect<Returns<Ref_>, E | ParseResult.ParseError>;
|
|
215
|
+
<Ref_ extends Any>(
|
|
216
|
+
ref: Ref_,
|
|
217
|
+
args: Args<Ref_>,
|
|
218
|
+
f: (
|
|
219
|
+
functionReference: FunctionReference<Ref_>,
|
|
220
|
+
encodedArgs: unknown,
|
|
221
|
+
) => PromiseLike<unknown>,
|
|
222
|
+
): Effect.Effect<Returns<Ref_>, ParseResult.ParseError>;
|
|
223
|
+
} = <Ref_ extends Any, E>(
|
|
224
|
+
ref: Ref_,
|
|
225
|
+
args: Args<Ref_>,
|
|
226
|
+
f: (
|
|
227
|
+
functionReference: FunctionReference<Ref_>,
|
|
228
|
+
encodedArgs: unknown,
|
|
229
|
+
) => Effect.Effect<unknown, E> | PromiseLike<unknown>,
|
|
230
|
+
): Effect.Effect<Returns<Ref_>, E | ParseResult.ParseError> =>
|
|
231
|
+
Effect.gen(function* () {
|
|
232
|
+
const functionReference = getFunctionReference(ref);
|
|
233
|
+
const functionProvenance = ref.functionSpec.functionProvenance;
|
|
234
|
+
const call = (encodedArgs: unknown) => {
|
|
235
|
+
const result = f(functionReference, encodedArgs);
|
|
236
|
+
return Effect.isEffect(result) ? result : Effect.promise(() => result);
|
|
237
|
+
};
|
|
238
|
+
return yield* Match.value(functionProvenance).pipe(
|
|
239
|
+
Match.tag("Confect", (confect) =>
|
|
240
|
+
Effect.gen(function* () {
|
|
241
|
+
const encodedArgs = yield* Schema.encode(confect.args)(args);
|
|
242
|
+
const encodedReturns = yield* call(encodedArgs);
|
|
243
|
+
return yield* Schema.decode(confect.returns)(encodedReturns);
|
|
244
|
+
}),
|
|
245
|
+
),
|
|
246
|
+
Match.tag("Convex", () => call(args)),
|
|
247
|
+
Match.exhaustive,
|
|
248
|
+
);
|
|
249
|
+
});
|
package/src/Refs.ts
CHANGED
|
@@ -116,19 +116,19 @@ export const make = <
|
|
|
116
116
|
|
|
117
117
|
const makeHelper = (
|
|
118
118
|
groups: Record.ReadonlyRecord<string, GroupSpec.Any>,
|
|
119
|
-
|
|
119
|
+
functionNamespace: string | null = null,
|
|
120
120
|
): Any =>
|
|
121
121
|
pipe(
|
|
122
122
|
groups as Record.ReadonlyRecord<string, GroupSpec.AnyWithProps>,
|
|
123
123
|
Record.map((group) => {
|
|
124
|
-
const
|
|
125
|
-
? `${
|
|
124
|
+
const currentFunctionNamespace = functionNamespace
|
|
125
|
+
? `${functionNamespace}/${group.name}`
|
|
126
126
|
: group.name;
|
|
127
127
|
|
|
128
128
|
return Record.union(
|
|
129
|
-
makeHelper(group.groups,
|
|
129
|
+
makeHelper(group.groups, currentFunctionNamespace),
|
|
130
130
|
Record.map(group.functions, (function_) =>
|
|
131
|
-
Ref.make(
|
|
131
|
+
Ref.make(currentFunctionNamespace, function_),
|
|
132
132
|
),
|
|
133
133
|
(_subGroup, _function) => {
|
|
134
134
|
throw new Error(
|