@confect/core 4.0.0 → 6.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 +12 -0
- package/dist/FunctionProvenance.d.ts +2 -5
- package/dist/FunctionProvenance.d.ts.map +1 -1
- package/dist/GroupSpec.d.ts +6 -6
- package/dist/Ref.d.ts +20 -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/dist/Spec.d.ts +4 -4
- package/dist/Types.d.ts +3 -2
- package/dist/Types.d.ts.map +1 -1
- package/dist/Types.js.map +1 -1
- package/package.json +1 -1
- package/src/Ref.ts +122 -22
- package/src/Refs.ts +5 -5
- package/src/Types.ts +19 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @confect/core
|
|
2
2
|
|
|
3
|
+
## 6.0.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- df95ce7: Add `Ref.OptionalArgs` type utility to `@confect/core` for conditionally optional function args. `QueryRunner`, `MutationRunner`, and `ActionRunner` now accept optional args for no-arg Confect functions. `useQuery`, `useMutation`, and `useAction` now accept optional args for no-arg Confect functions. `TestConfect` `query`/`mutation`/`action` helpers now accept optional args for no-arg Confect functions.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- a8083e8: Fix table field path inference when a schema has a `name` field and an optional Convex ID or bytes field.
|
|
12
|
+
|
|
13
|
+
## 5.0.0
|
|
14
|
+
|
|
3
15
|
## 4.0.0
|
|
4
16
|
|
|
5
17
|
## 3.0.0
|
|
@@ -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/GroupSpec.d.ts
CHANGED
|
@@ -8,20 +8,20 @@ declare namespace GroupSpec_d_exports {
|
|
|
8
8
|
declare const TypeId = "@confect/core/GroupSpec";
|
|
9
9
|
type TypeId = typeof TypeId;
|
|
10
10
|
declare const isGroupSpec: (u: unknown) => u is Any;
|
|
11
|
-
interface GroupSpec<Runtime$
|
|
11
|
+
interface GroupSpec<Runtime$1 extends Runtime, Name_ extends string, Functions_ extends AnyWithPropsWithRuntime$1<Runtime$1> = never, Groups_ extends AnyWithPropsWithRuntime<Runtime$1> = never> {
|
|
12
12
|
readonly [TypeId]: TypeId;
|
|
13
|
-
readonly runtime: Runtime$
|
|
13
|
+
readonly runtime: Runtime$1;
|
|
14
14
|
readonly name: Name_;
|
|
15
|
-
readonly functions: { [FunctionName in Name$1<AnyWithPropsWithRuntime$1<Runtime$
|
|
15
|
+
readonly functions: { [FunctionName in Name$1<AnyWithPropsWithRuntime$1<Runtime$1>>]: WithName$1<Functions_, FunctionName> };
|
|
16
16
|
readonly groups: { [GroupName in Name<Groups_>]: WithName<Groups_, GroupName> };
|
|
17
|
-
addFunction<Function extends AnyWithPropsWithRuntime$1<Runtime$
|
|
18
|
-
addGroup<Group extends AnyWithPropsWithRuntime<Runtime$
|
|
17
|
+
addFunction<Function extends AnyWithPropsWithRuntime$1<Runtime$1>>(function_: Function): GroupSpec<Runtime$1, Name_, Functions_ | Function, Groups_>;
|
|
18
|
+
addGroup<Group extends AnyWithPropsWithRuntime<Runtime$1>>(group: Group): GroupSpec<Runtime$1, Name_, Functions_, Groups_ | Group>;
|
|
19
19
|
}
|
|
20
20
|
interface Any {
|
|
21
21
|
readonly [TypeId]: TypeId;
|
|
22
22
|
}
|
|
23
23
|
interface AnyWithProps extends GroupSpec<Runtime, string, AnyWithProps$1, AnyWithProps> {}
|
|
24
|
-
interface AnyWithPropsWithRuntime<Runtime$
|
|
24
|
+
interface AnyWithPropsWithRuntime<Runtime$2 extends Runtime> extends GroupSpec<Runtime$2, string, AnyWithPropsWithRuntime$1<Runtime$2>, AnyWithPropsWithRuntime<Runtime$2>> {}
|
|
25
25
|
type Name<Group extends AnyWithProps> = Group["name"];
|
|
26
26
|
type Functions<Group extends AnyWithProps> = Group["functions"][keyof Group["functions"]];
|
|
27
27
|
type Groups<Group extends AnyWithProps> = Group["groups"][keyof Group["groups"]];
|
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, OptionalArgs, 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;
|
|
@@ -26,16 +27,28 @@ type GetRuntime<Ref_> = Ref_ extends Ref<infer RuntimeAndFunctionType_, infer _F
|
|
|
26
27
|
type GetFunctionType<Ref_> = Ref_ extends Ref<infer RuntimeAndFunctionType_, infer _FunctionVisibility, infer _Args, infer _Returns> ? GetFunctionType$1<RuntimeAndFunctionType_> : never;
|
|
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;
|
|
30
|
+
type OptionalArgs<Ref_ extends Any> = keyof Args<Ref_> extends never ? [args?: Args<Ref_>] : [args: Args<Ref_>];
|
|
29
31
|
type Returns<Ref_> = Ref_ extends Ref<infer _RuntimeAndFunctionType, infer _FunctionVisibility, infer _Args, infer Returns_> ? Returns_ : never;
|
|
30
|
-
type
|
|
32
|
+
type FunctionReference<Ref_ extends Any> = FunctionReference$1<GetFunctionType<Ref_>, GetFunctionVisibility<Ref_>>;
|
|
33
|
+
type FromFunctionSpec<FunctionSpec_ extends AnyWithProps> = Ref<GetRuntimeAndFunctionType$1<FunctionSpec_>, GetFunctionVisibility$1<FunctionSpec_>, Args$1<FunctionSpec_>, Returns$1<FunctionSpec_>>;
|
|
31
34
|
declare const make: <FunctionSpec_ extends AnyWithProps>(
|
|
32
35
|
/**
|
|
33
|
-
*
|
|
36
|
+
* The namespace portion of a Convex function name, i.e. the part before the
|
|
37
|
+
* colon. For example, for `myGroupDir/myGroupMod:myFunc` this would be
|
|
38
|
+
* `myGroupDir/myGroupMod`.
|
|
34
39
|
*/
|
|
35
40
|
|
|
36
|
-
|
|
37
|
-
declare const getFunctionSpec: (ref: Any) => AnyWithProps;
|
|
41
|
+
functionNamespace: string, functionSpec: FunctionSpec_) => FromFunctionSpec<FunctionSpec_>;
|
|
38
42
|
declare const getConvexFunctionName: (ref: Any) => string;
|
|
43
|
+
declare const getFunctionReference: <Ref_ extends Any>(ref: Ref_) => FunctionReference<Ref_>;
|
|
44
|
+
declare const encodeArgs: <Ref_ extends Any>(ref: Ref_, args: Args<Ref_>) => Effect.Effect<unknown, ParseResult.ParseError>;
|
|
45
|
+
declare const decodeReturns: <Ref_ extends Any>(ref: Ref_, returns: unknown) => Effect.Effect<Returns<Ref_>, ParseResult.ParseError>;
|
|
46
|
+
declare const encodeArgsSync: <Ref_ extends Any>(ref: Ref_, args: Args<Ref_>) => unknown;
|
|
47
|
+
declare const decodeReturnsSync: <Ref_ extends Any>(ref: Ref_, encodedReturns: unknown) => Returns<Ref_>;
|
|
48
|
+
declare const runWithCodec: {
|
|
49
|
+
<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>;
|
|
50
|
+
<Ref_ extends Any>(ref: Ref_, args: Args<Ref_>, f: (functionReference: FunctionReference<Ref_>, encodedArgs: unknown) => PromiseLike<unknown>): Effect.Effect<Returns<Ref_>, ParseResult.ParseError>;
|
|
51
|
+
};
|
|
39
52
|
//#endregion
|
|
40
|
-
export { Any, AnyAction, AnyInternal, AnyMutation, AnyPublic, AnyPublicAction, AnyPublicMutation, AnyPublicQuery, AnyQuery, Args, FromFunctionSpec, GetFunctionType, GetFunctionVisibility, GetRuntime, GetRuntimeAndFunctionType, Ref, Ref_d_exports, Returns, getConvexFunctionName,
|
|
53
|
+
export { Any, AnyAction, AnyInternal, AnyMutation, AnyPublic, AnyPublicAction, AnyPublicMutation, AnyPublicQuery, AnyQuery, Args, FromFunctionSpec, FunctionReference, GetFunctionType, GetFunctionVisibility, GetRuntime, GetRuntimeAndFunctionType, OptionalArgs, Ref, Ref_d_exports, Returns, decodeReturns, decodeReturnsSync, encodeArgs, encodeArgsSync, getConvexFunctionName, getFunctionReference, make, runWithCodec };
|
|
41
54
|
//# 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":";;;;;;;;;UAUiB,GAAA,iCACiB,sBAAA,8BACJ,kBAAA;EAAA,SAInB,uBAAA,GAA0B,uBAAA;EAAA,SAC1B,mBAAA,GAAsB,mBAAA;EAAA,SACtB,KAAA,GAAQ,KAAA;EAAA,SACR,QAAA,GAAW,QAAA;AAAA;AAAA,UAOL,GAAA,SAAY,GAAA;AAAA,UAEZ,WAAA,SAAoB,GAAA;AAAA,UAEpB,SAAA,SAAkB,GAAA;AAAA,UAElB,QAAA,SAAiB,GAAA,CAChC,UAAA,EACA,kBAAA;AAAA,UAKe,WAAA,SAAoB,GAAA,CACnC,aAAA,EACA,kBAAA;AAAA,UAKe,SAAA,SAAkB,GAAA,CACjC,WAAA,EACA,kBAAA;AAAA,UAKe,cAAA,SAAuB,GAAA,CACtC,UAAA;AAAA,UAMe,iBAAA,SAA0B,GAAA,CACzC,aAAA;AAAA,UAMe,eAAA,SAAwB,GAAA,CACvC,WAAA;AAAA,KAMU,yBAAA,SACV,IAAA,SAAa,GAAA,0FAMT,uBAAA;AAAA,KAGM,UAAA,SACV,IAAA,SAAa,GAAA,0FAMT,YAAA,CAAkC,uBAAA;AAAA,KAG5B,eAAA,SACV,IAAA,SAAa,GAAA,0FAMT,iBAAA,CAAuC,uBAAA;AAAA,KAGjC,qBAAA,SACV,IAAA,SAAa,GAAA,0FAMT,mBAAA;AAAA,KAGM,IAAA,SACV,IAAA,SAAa,GAAA,0FAMT,KAAA;AAAA,KAGM,YAAA,cAA0B,GAAA,UAAa,IAAA,CAAK,IAAA,mBACnD,IAAA,GAAO,IAAA,CAAK,IAAA,MACZ,IAAA,EAAM,IAAA,CAAK,IAAA;AAAA,KAEJ,OAAA,SACV,IAAA,SAAa,GAAA,0FAMT,QAAA;AAAA,KAGM,iBAAA,cAA+B,GAAA,IAAO,mBAAA,CAChD,eAAA,CAAgB,IAAA,GAChB,qBAAA,CAAsB,IAAA;AAAA,KAGZ,gBAAA,uBAAuC,YAAA,IACjD,GAAA,CACE,2BAAA,CAAuC,aAAA,GACvC,uBAAA,CAAmC,aAAA,GACnC,MAAA,CAAkB,aAAA,GAClB,SAAA,CAAqB,aAAA;AAAA,cAGZ,IAAA,yBAA8B,YAAA;;;;;;;AAMzC,iBAAA,UACA,YAAA,EAAc,aAAA,KACb,gBAAA,CAAiB,aAAA;AAAA,cAEP,qBAAA,GAAyB,GAAA,EAAK,GAAA;AAAA,cAG9B,oBAAA,gBAAqC,GAAA,EAChD,GAAA,EAAK,IAAA,KACJ,iBAAA,CAAkB,IAAA;AAAA,cAGR,UAAA,gBAA2B,GAAA,EACtC,GAAA,EAAK,IAAA,EACL,IAAA,EAAM,IAAA,CAAK,IAAA,MACV,MAAA,CAAO,MAAA,UAAgB,WAAA,CAAY,UAAA;AAAA,cAOzB,aAAA,gBAA8B,GAAA,EACzC,GAAA,EAAK,IAAA,EACL,OAAA,cACC,MAAA,CAAO,MAAA,CAAO,OAAA,CAAQ,IAAA,GAAO,WAAA,CAAY,UAAA;AAAA,cAO/B,cAAA,gBAA+B,GAAA,EAC1C,GAAA,EAAK,IAAA,EACL,IAAA,EAAM,IAAA,CAAK,IAAA;AAAA,cAQA,iBAAA,gBAAkC,GAAA,EAC7C,GAAA,EAAK,IAAA,EACL,cAAA,cACC,OAAA,CAAQ,IAAA;AAAA,cAOE,YAAA;EAAA,cACG,GAAA,KACZ,GAAA,EAAK,IAAA,EACL,IAAA,EAAM,IAAA,CAAK,IAAA,GACX,CAAA,GACE,iBAAA,EAAmB,iBAAA,CAAkB,IAAA,GACrC,WAAA,cACG,MAAA,CAAO,MAAA,UAAgB,CAAA,IAC3B,MAAA,CAAO,MAAA,CAAO,OAAA,CAAQ,IAAA,GAAO,CAAA,GAAI,WAAA,CAAY,UAAA;EAAA,cAClC,GAAA,EACZ,GAAA,EAAK,IAAA,EACL,IAAA,EAAM,IAAA,CAAK,IAAA,GACX,CAAA,GACE,iBAAA,EAAmB,iBAAA,CAAkB,IAAA,GACrC,WAAA,cACG,WAAA,YACJ,MAAA,CAAO,MAAA,CAAO,OAAA,CAAQ,IAAA,GAAO,WAAA,CAAY,UAAA;AAAA"}
|
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 OptionalArgs<Ref_ extends Any> = keyof Args<Ref_> extends never\n ? [args?: Args<Ref_>]\n : [args: Args<Ref_>];\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":";;;;;;;;;;;;;;;AAuJA,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/dist/Spec.d.ts
CHANGED
|
@@ -10,17 +10,17 @@ type TypeId = typeof TypeId;
|
|
|
10
10
|
declare const isSpec: (u: unknown) => u is AnyWithProps;
|
|
11
11
|
declare const isConvexSpec: (u: unknown) => u is AnyWithPropsWithRuntime<"Convex">;
|
|
12
12
|
declare const isNodeSpec: (u: unknown) => u is AnyWithPropsWithRuntime<"Node">;
|
|
13
|
-
interface Spec<Runtime$
|
|
13
|
+
interface Spec<Runtime$1 extends Runtime, Groups_ extends AnyWithPropsWithRuntime$1<Runtime$1> = never> {
|
|
14
14
|
readonly [TypeId]: TypeId;
|
|
15
|
-
readonly runtime: Runtime$
|
|
15
|
+
readonly runtime: Runtime$1;
|
|
16
16
|
readonly groups: { [GroupName in Name<Groups_>]: WithName<Groups_, GroupName> };
|
|
17
|
-
add<Group extends AnyWithPropsWithRuntime$1<Runtime$
|
|
17
|
+
add<Group extends AnyWithPropsWithRuntime$1<Runtime$1>>(group: Group): Spec<Runtime$1, Groups_ | Group>;
|
|
18
18
|
}
|
|
19
19
|
interface Any {
|
|
20
20
|
readonly [TypeId]: TypeId;
|
|
21
21
|
}
|
|
22
22
|
interface AnyWithProps extends Spec<Runtime, AnyWithProps$1> {}
|
|
23
|
-
interface AnyWithPropsWithRuntime<Runtime$
|
|
23
|
+
interface AnyWithPropsWithRuntime<Runtime$2 extends Runtime> extends Spec<Runtime$2, AnyWithPropsWithRuntime$1<Runtime$2>> {}
|
|
24
24
|
type Groups<Spec_ extends AnyWithProps> = Spec_["groups"][keyof Spec_["groups"]];
|
|
25
25
|
declare const make: () => Spec<"Convex">;
|
|
26
26
|
declare const makeNode: () => Spec<"Node">;
|
package/dist/Types.d.ts
CHANGED
|
@@ -14,11 +14,12 @@ type IsValueLiteral<Vl> = [Vl] extends [never] ? never : IsUnion<Vl> extends tru
|
|
|
14
14
|
* Only checks for records with string keys.
|
|
15
15
|
*/
|
|
16
16
|
type IsRecord<T> = [T] extends [never] ? false : IsUnion<T> extends true ? false : T extends Record<string, infer V> ? string extends keyof T ? keyof T extends string ? T extends Record<string, V> ? Record<string, V> extends T ? true : false : false : false : false : false;
|
|
17
|
-
type DeepMutable<T> = IsAny<T> extends true ? any : T extends
|
|
17
|
+
type DeepMutable<T> = IsAny<T> extends true ? any : T extends NonRecursiveLeaf ? T : T extends ReadonlyMap<infer K, infer V> ? Map<DeepMutable<K>, DeepMutable<V>> : T extends ReadonlySet<infer V> ? Set<DeepMutable<V>> : [keyof T] extends [never] ? T : { -readonly [K in keyof T]: DeepMutable<T[K]> };
|
|
18
18
|
type TypeError<Message extends string, T = never> = [Message, T];
|
|
19
19
|
type TypeDefect<Message extends string, T = never> = [Message, T];
|
|
20
20
|
type IsRecursive<T> = true extends DetectCycle<T> ? true : false;
|
|
21
|
-
type
|
|
21
|
+
type NonRecursiveLeaf = Brand.Brand<any> | GenericId<any> | ArrayBuffer;
|
|
22
|
+
type DetectCycle<T, Cache extends any[] = []> = IsAny<T> extends true ? false : [T] extends [any] ? T extends NonRecursiveLeaf ? false : T extends Cache[number] ? true : T extends Array<infer U> ? DetectCycle<U, [...Cache, T]> : T extends Map<infer _U, infer V> ? DetectCycle<V, [...Cache, T]> : T extends Set<infer U> ? DetectCycle<U, [...Cache, T]> : T extends object ? true extends { [K in keyof T]: DetectCycle<T[K], [...Cache, T]> }[keyof T] ? true : false : false : never;
|
|
22
23
|
type UnionToTuple<t> = _unionToTuple<t, []> extends infer result ? conform<result, t[]> : never;
|
|
23
24
|
type _unionToTuple<t, result extends unknown[]> = getLastBranch<t> extends infer current ? [t] extends [never] ? result : _unionToTuple<Exclude<t, current>, [current, ...result]> : never;
|
|
24
25
|
type getLastBranch<t> = intersectUnion<t extends unknown ? (x: t) => void : never> extends ((x: infer branch) => void) ? branch : never;
|
package/dist/Types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Types.d.ts","names":[],"sources":["../src/Types.ts"],"mappings":";;;;;;;;KAUY,UAAA,oBAA8B,CAAA,eAC7B,IAAA,CAAK,CAAA,EAAG,CAAA;AAAA,KAET,KAAA,oBAAyB,CAAA;AAAA,KAEzB,OAAA,cAAqB,CAAA,GAAI,CAAA,IAAK,CAAA,oBACrC,CAAA,WAAY,CAAA;AAAA,KAML,cAAA,QAAsB,EAAA,4BAE9B,OAAA,CAAQ,EAAA,0BAEL,EAAA,mEACmB,EAAA,8BAEE,EAAA,+BAEG,EAAA,8BAEC,EAAA;;;;KAQpB,QAAA,OAAe,CAAA,4BAEvB,OAAA,CAAQ,CAAA,yBAEN,CAAA,SAAU,MAAA,yCACa,CAAA,SACb,CAAA,kBACJ,CAAA,SAAU,MAAA,SAAe,CAAA,IACvB,MAAA,SAAe,CAAA,UAAW,CAAA;AAAA,KAQ5B,WAAA,MACV,KAAA,CAAM,CAAA,uBAEF,CAAA,SAAU,
|
|
1
|
+
{"version":3,"file":"Types.d.ts","names":[],"sources":["../src/Types.ts"],"mappings":";;;;;;;;KAUY,UAAA,oBAA8B,CAAA,eAC7B,IAAA,CAAK,CAAA,EAAG,CAAA;AAAA,KAET,KAAA,oBAAyB,CAAA;AAAA,KAEzB,OAAA,cAAqB,CAAA,GAAI,CAAA,IAAK,CAAA,oBACrC,CAAA,WAAY,CAAA;AAAA,KAML,cAAA,QAAsB,EAAA,4BAE9B,OAAA,CAAQ,EAAA,0BAEL,EAAA,mEACmB,EAAA,8BAEE,EAAA,+BAEG,EAAA,8BAEC,EAAA;;;;KAQpB,QAAA,OAAe,CAAA,4BAEvB,OAAA,CAAQ,CAAA,yBAEN,CAAA,SAAU,MAAA,yCACa,CAAA,SACb,CAAA,kBACJ,CAAA,SAAU,MAAA,SAAe,CAAA,IACvB,MAAA,SAAe,CAAA,UAAW,CAAA;AAAA,KAQ5B,WAAA,MACV,KAAA,CAAM,CAAA,uBAEF,CAAA,SAAU,gBAAA,GACR,CAAA,GACA,CAAA,SAAU,WAAA,qBACR,GAAA,CAAI,WAAA,CAAY,CAAA,GAAI,WAAA,CAAY,CAAA,KAChC,CAAA,SAAU,WAAA,YACR,GAAA,CAAI,WAAA,CAAY,CAAA,YACT,CAAA,oBACL,CAAA,2BACwB,CAAA,GAAI,WAAA,CAAY,CAAA,CAAE,CAAA;AAAA,KAE5C,SAAA,uCAAgD,OAAA,EAAS,CAAA;AAAA,KAEzD,UAAA,uCAAiD,OAAA,EAAS,CAAA;AAAA,KAE1D,WAAA,mBAA8B,WAAA,CAAY,CAAA;AAAA,KAEjD,gBAAA,GAAmB,KAAA,CAAM,KAAA,QAAa,SAAA,QAAiB,WAAA;AAAA,KAEvD,WAAA,gCACH,KAAA,CAAM,CAAA,0BAED,CAAA,kBACC,CAAA,SAAU,gBAAA,WAER,CAAA,SAAU,KAAA,kBAER,CAAA,SAAU,KAAA,YACR,WAAA,CAAY,CAAA,MAAO,KAAA,EAAO,CAAA,KAC1B,CAAA,SAAU,GAAA,sBACR,WAAA,CAAY,CAAA,MAAO,KAAA,EAAO,CAAA,KAC1B,CAAA,SAAU,GAAA,YACR,WAAA,CAAY,CAAA,MAAO,KAAA,EAAO,CAAA,KAC1B,CAAA,6CAEgB,CAAA,GAAI,WAAA,CAAY,CAAA,CAAE,CAAA,OAAQ,KAAA,EAAO,CAAA,WACvC,CAAA;AAAA,KAYhB,YAAA,MACV,aAAA,CAAc,CAAA,6BAA8B,OAAA,CAAQ,MAAA,EAAQ,CAAA;AAAA,KAEzD,aAAA,gCACH,aAAA,CAAc,CAAA,2BACT,CAAA,oBACC,MAAA,GACA,aAAA,CAAc,OAAA,CAAQ,CAAA,EAAG,OAAA,IAAW,OAAA,KAAY,MAAA;AAAA,KAGnD,aAAA,MACH,cAAA,CAAe,CAAA,oBAAqB,CAAA,EAAG,CAAA,6BACrC,CAAA,2BAEE,MAAA;AAAA,KAGD,cAAA,OAAqB,CAAA,oBAAqB,CAAA,EAAG,CAAA,6BAChD,CAAA,iCAEE,YAAA;AAAA,KAGC,OAAA,YAAmB,CAAA,SAAU,IAAA,GAAO,CAAA,GAAI,IAAA;AAAA,KAMjC,oBAAA,yBACc,gBAAA,gBACV,qBAAA,CAAsB,eAAA,yBAElC,CAAA,yCACA,IAAA,2CAEgB,IAAA,GAAO,sBAAA,CACjB,cAAA,CAAe,eAAA,EAAiB,KAAA,GAChC,IAAA,CAAK,CAAA;AAAA,KAOH,kBAAA,mBAAqC,gBAAA;EAC/C,GAAA,EAAK,qBAAA,CAAsB,SAAA;EAC3B,KAAA,EAAO,qBAAA,CAAsB,SAAA;AAAA"}
|
package/dist/Types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Types.js","names":[],"sources":["../src/Types.ts"],"sourcesContent":["import type {\n DocumentByName,\n FieldTypeFromFieldPath,\n GenericDatabaseReader,\n GenericDataModel,\n TableNamesInDataModel,\n} from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\nimport type { Brand } from \"effect\";\n\nexport type IsOptional<T, K extends keyof T> =\n {} extends Pick<T, K> ? true : false;\n\nexport type IsAny<T> = 0 extends 1 & T ? true : false;\n\nexport type IsUnion<T, U extends T = T> = T extends unknown\n ? [U] extends [T]\n ? false\n : true\n : never;\n\n// https://stackoverflow.com/a/52806744\nexport type IsValueLiteral<Vl> = [Vl] extends [never]\n ? never\n : IsUnion<Vl> extends true\n ? false\n : [Vl] extends [string | number | bigint | boolean]\n ? [string] extends [Vl]\n ? false\n : [number] extends [Vl]\n ? false\n : [boolean] extends [Vl]\n ? false\n : [bigint] extends [Vl]\n ? false\n : true\n : false;\n\n/**\n * Only checks for records with string keys.\n */\nexport type IsRecord<T> = [T] extends [never]\n ? false\n : IsUnion<T> extends true\n ? false\n : T extends Record<string, infer V>\n ? string extends keyof T\n ? keyof T extends string\n ? T extends Record<string, V>\n ? Record<string, V> extends T\n ? true\n : false\n : false\n : false\n : false\n : false;\n\nexport type DeepMutable<T> =\n IsAny<T> extends true\n ? any\n : T extends
|
|
1
|
+
{"version":3,"file":"Types.js","names":[],"sources":["../src/Types.ts"],"sourcesContent":["import type {\n DocumentByName,\n FieldTypeFromFieldPath,\n GenericDatabaseReader,\n GenericDataModel,\n TableNamesInDataModel,\n} from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\nimport type { Brand } from \"effect\";\n\nexport type IsOptional<T, K extends keyof T> =\n {} extends Pick<T, K> ? true : false;\n\nexport type IsAny<T> = 0 extends 1 & T ? true : false;\n\nexport type IsUnion<T, U extends T = T> = T extends unknown\n ? [U] extends [T]\n ? false\n : true\n : never;\n\n// https://stackoverflow.com/a/52806744\nexport type IsValueLiteral<Vl> = [Vl] extends [never]\n ? never\n : IsUnion<Vl> extends true\n ? false\n : [Vl] extends [string | number | bigint | boolean]\n ? [string] extends [Vl]\n ? false\n : [number] extends [Vl]\n ? false\n : [boolean] extends [Vl]\n ? false\n : [bigint] extends [Vl]\n ? false\n : true\n : false;\n\n/**\n * Only checks for records with string keys.\n */\nexport type IsRecord<T> = [T] extends [never]\n ? false\n : IsUnion<T> extends true\n ? false\n : T extends Record<string, infer V>\n ? string extends keyof T\n ? keyof T extends string\n ? T extends Record<string, V>\n ? Record<string, V> extends T\n ? true\n : false\n : false\n : false\n : false\n : false;\n\nexport type DeepMutable<T> =\n IsAny<T> extends true\n ? any\n : T extends NonRecursiveLeaf\n ? T\n : T extends ReadonlyMap<infer K, infer V>\n ? Map<DeepMutable<K>, DeepMutable<V>>\n : T extends ReadonlySet<infer V>\n ? Set<DeepMutable<V>>\n : [keyof T] extends [never]\n ? T\n : { -readonly [K in keyof T]: DeepMutable<T[K]> };\n\nexport type TypeError<Message extends string, T = never> = [Message, T];\n\nexport type TypeDefect<Message extends string, T = never> = [Message, T];\n\nexport type IsRecursive<T> = true extends DetectCycle<T> ? true : false;\n\ntype NonRecursiveLeaf = Brand.Brand<any> | GenericId<any> | ArrayBuffer;\n\ntype DetectCycle<T, Cache extends any[] = []> =\n IsAny<T> extends true\n ? false\n : [T] extends [any]\n ? T extends NonRecursiveLeaf\n ? false\n : T extends Cache[number]\n ? true\n : T extends Array<infer U>\n ? DetectCycle<U, [...Cache, T]>\n : T extends Map<infer _U, infer V>\n ? DetectCycle<V, [...Cache, T]>\n : T extends Set<infer U>\n ? DetectCycle<U, [...Cache, T]>\n : T extends object\n ? true extends {\n [K in keyof T]: DetectCycle<T[K], [...Cache, T]>;\n }[keyof T]\n ? true\n : false\n : false\n : never;\n\n//////////////////////////////////\n// START: Vendored from Arktype //\n//////////////////////////////////\n\n// https://github.com/arktypeio/arktype/blob/2e911d01a741ccee7a17e31ee144049817fabbb8/ark/util/unionToTuple.ts#L9\n\nexport type UnionToTuple<t> =\n _unionToTuple<t, []> extends infer result ? conform<result, t[]> : never;\n\ntype _unionToTuple<t, result extends unknown[]> =\n getLastBranch<t> extends infer current\n ? [t] extends [never]\n ? result\n : _unionToTuple<Exclude<t, current>, [current, ...result]>\n : never;\n\ntype getLastBranch<t> =\n intersectUnion<t extends unknown ? (x: t) => void : never> extends (\n x: infer branch,\n ) => void\n ? branch\n : never;\n\ntype intersectUnion<t> = (t extends unknown ? (_: t) => void : never) extends (\n _: infer intersection,\n) => void\n ? intersection\n : never;\n\ntype conform<t, base> = t extends base ? t : base;\n\n////////////////////////////////\n// END: Vendored from Arktype //\n////////////////////////////////\n\nexport type IndexFieldTypesForEq<\n ConvexDataModel extends GenericDataModel,\n Table extends TableNamesInDataModel<ConvexDataModel>,\n T extends string[],\n> = T extends readonly [...infer Rest, any]\n ? Rest extends readonly string[]\n ? {\n [K in keyof Rest]: FieldTypeFromFieldPath<\n DocumentByName<ConvexDataModel, Table>,\n Rest[K]\n >;\n }\n : never\n : never;\n\n// Would prefer to use `BaseDatabaseReader` from the `convex` package, but it's not exported.\nexport type BaseDatabaseReader<DataModel extends GenericDataModel> = {\n get: GenericDatabaseReader<DataModel>[\"get\"];\n query: GenericDatabaseReader<DataModel>[\"query\"];\n};\n"],"mappings":""}
|
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> {}
|
|
@@ -112,6 +122,10 @@ export type Args<Ref_> =
|
|
|
112
122
|
? Args_
|
|
113
123
|
: never;
|
|
114
124
|
|
|
125
|
+
export type OptionalArgs<Ref_ extends Any> = keyof Args<Ref_> extends never
|
|
126
|
+
? [args?: Args<Ref_>]
|
|
127
|
+
: [args: Args<Ref_>];
|
|
128
|
+
|
|
115
129
|
export type Returns<Ref_> =
|
|
116
130
|
Ref_ extends Ref<
|
|
117
131
|
infer _RuntimeAndFunctionType,
|
|
@@ -122,32 +136,118 @@ export type Returns<Ref_> =
|
|
|
122
136
|
? Returns_
|
|
123
137
|
: never;
|
|
124
138
|
|
|
125
|
-
export type
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
FunctionSpec.Args<F>,
|
|
129
|
-
FunctionSpec.Returns<F>
|
|
139
|
+
export type FunctionReference<Ref_ extends Any> = ConvexFunctionReference<
|
|
140
|
+
GetFunctionType<Ref_>,
|
|
141
|
+
GetFunctionVisibility<Ref_>
|
|
130
142
|
>;
|
|
131
143
|
|
|
144
|
+
export type FromFunctionSpec<FunctionSpec_ extends FunctionSpec.AnyWithProps> =
|
|
145
|
+
Ref<
|
|
146
|
+
FunctionSpec.GetRuntimeAndFunctionType<FunctionSpec_>,
|
|
147
|
+
FunctionSpec.GetFunctionVisibility<FunctionSpec_>,
|
|
148
|
+
FunctionSpec.Args<FunctionSpec_>,
|
|
149
|
+
FunctionSpec.Returns<FunctionSpec_>
|
|
150
|
+
>;
|
|
151
|
+
|
|
132
152
|
export const make = <FunctionSpec_ extends FunctionSpec.AnyWithProps>(
|
|
133
153
|
/**
|
|
134
|
-
*
|
|
154
|
+
* The namespace portion of a Convex function name, i.e. the part before the
|
|
155
|
+
* colon. For example, for `myGroupDir/myGroupMod:myFunc` this would be
|
|
156
|
+
* `myGroupDir/myGroupMod`.
|
|
135
157
|
*/
|
|
136
|
-
|
|
158
|
+
functionNamespace: string,
|
|
137
159
|
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";
|
|
160
|
+
): FromFunctionSpec<FunctionSpec_> => ({ functionSpec, functionNamespace });
|
|
151
161
|
|
|
152
162
|
export const getConvexFunctionName = (ref: Any): string =>
|
|
153
|
-
|
|
163
|
+
`${ref.functionNamespace}:${ref.functionSpec.name}`;
|
|
164
|
+
|
|
165
|
+
export const getFunctionReference = <Ref_ extends Any>(
|
|
166
|
+
ref: Ref_,
|
|
167
|
+
): FunctionReference<Ref_> =>
|
|
168
|
+
makeFunctionReference(getConvexFunctionName(ref)) as FunctionReference<Ref_>;
|
|
169
|
+
|
|
170
|
+
export const encodeArgs = <Ref_ extends Any>(
|
|
171
|
+
ref: Ref_,
|
|
172
|
+
args: Args<Ref_>,
|
|
173
|
+
): Effect.Effect<unknown, ParseResult.ParseError> =>
|
|
174
|
+
Match.value(ref.functionSpec.functionProvenance).pipe(
|
|
175
|
+
Match.tag("Confect", (c) => Schema.encode(c.args)(args)),
|
|
176
|
+
Match.tag("Convex", () => Effect.succeed(args)),
|
|
177
|
+
Match.exhaustive,
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
export const decodeReturns = <Ref_ extends Any>(
|
|
181
|
+
ref: Ref_,
|
|
182
|
+
returns: unknown,
|
|
183
|
+
): Effect.Effect<Returns<Ref_>, ParseResult.ParseError> =>
|
|
184
|
+
Match.value(ref.functionSpec.functionProvenance).pipe(
|
|
185
|
+
Match.tag("Confect", (c) => Schema.decode(c.returns)(returns)),
|
|
186
|
+
Match.tag("Convex", () => Effect.succeed(returns)),
|
|
187
|
+
Match.exhaustive,
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
export const encodeArgsSync = <Ref_ extends Any>(
|
|
191
|
+
ref: Ref_,
|
|
192
|
+
args: Args<Ref_>,
|
|
193
|
+
): unknown =>
|
|
194
|
+
Match.value(ref.functionSpec.functionProvenance).pipe(
|
|
195
|
+
Match.tag("Confect", (c) => Schema.encodeSync(c.args)(args)),
|
|
196
|
+
Match.tag("Convex", () => args),
|
|
197
|
+
Match.exhaustive,
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
export const decodeReturnsSync = <Ref_ extends Any>(
|
|
201
|
+
ref: Ref_,
|
|
202
|
+
encodedReturns: unknown,
|
|
203
|
+
): Returns<Ref_> =>
|
|
204
|
+
Match.value(ref.functionSpec.functionProvenance).pipe(
|
|
205
|
+
Match.tag("Confect", (c) => Schema.decodeSync(c.returns)(encodedReturns)),
|
|
206
|
+
Match.tag("Convex", () => encodedReturns),
|
|
207
|
+
Match.exhaustive,
|
|
208
|
+
) as Returns<Ref_>;
|
|
209
|
+
|
|
210
|
+
export const runWithCodec: {
|
|
211
|
+
<Ref_ extends Any, E>(
|
|
212
|
+
ref: Ref_,
|
|
213
|
+
args: Args<Ref_>,
|
|
214
|
+
f: (
|
|
215
|
+
functionReference: FunctionReference<Ref_>,
|
|
216
|
+
encodedArgs: unknown,
|
|
217
|
+
) => Effect.Effect<unknown, E>,
|
|
218
|
+
): Effect.Effect<Returns<Ref_>, E | ParseResult.ParseError>;
|
|
219
|
+
<Ref_ extends Any>(
|
|
220
|
+
ref: Ref_,
|
|
221
|
+
args: Args<Ref_>,
|
|
222
|
+
f: (
|
|
223
|
+
functionReference: FunctionReference<Ref_>,
|
|
224
|
+
encodedArgs: unknown,
|
|
225
|
+
) => PromiseLike<unknown>,
|
|
226
|
+
): Effect.Effect<Returns<Ref_>, ParseResult.ParseError>;
|
|
227
|
+
} = <Ref_ extends Any, E>(
|
|
228
|
+
ref: Ref_,
|
|
229
|
+
args: Args<Ref_>,
|
|
230
|
+
f: (
|
|
231
|
+
functionReference: FunctionReference<Ref_>,
|
|
232
|
+
encodedArgs: unknown,
|
|
233
|
+
) => Effect.Effect<unknown, E> | PromiseLike<unknown>,
|
|
234
|
+
): Effect.Effect<Returns<Ref_>, E | ParseResult.ParseError> =>
|
|
235
|
+
Effect.gen(function* () {
|
|
236
|
+
const functionReference = getFunctionReference(ref);
|
|
237
|
+
const functionProvenance = ref.functionSpec.functionProvenance;
|
|
238
|
+
const call = (encodedArgs: unknown) => {
|
|
239
|
+
const result = f(functionReference, encodedArgs);
|
|
240
|
+
return Effect.isEffect(result) ? result : Effect.promise(() => result);
|
|
241
|
+
};
|
|
242
|
+
return yield* Match.value(functionProvenance).pipe(
|
|
243
|
+
Match.tag("Confect", (confect) =>
|
|
244
|
+
Effect.gen(function* () {
|
|
245
|
+
const encodedArgs = yield* Schema.encode(confect.args)(args);
|
|
246
|
+
const encodedReturns = yield* call(encodedArgs);
|
|
247
|
+
return yield* Schema.decode(confect.returns)(encodedReturns);
|
|
248
|
+
}),
|
|
249
|
+
),
|
|
250
|
+
Match.tag("Convex", () => call(args)),
|
|
251
|
+
Match.exhaustive,
|
|
252
|
+
);
|
|
253
|
+
});
|
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(
|
package/src/Types.ts
CHANGED
|
@@ -58,7 +58,7 @@ export type IsRecord<T> = [T] extends [never]
|
|
|
58
58
|
export type DeepMutable<T> =
|
|
59
59
|
IsAny<T> extends true
|
|
60
60
|
? any
|
|
61
|
-
: T extends
|
|
61
|
+
: T extends NonRecursiveLeaf
|
|
62
62
|
? T
|
|
63
63
|
: T extends ReadonlyMap<infer K, infer V>
|
|
64
64
|
? Map<DeepMutable<K>, DeepMutable<V>>
|
|
@@ -74,25 +74,29 @@ export type TypeDefect<Message extends string, T = never> = [Message, T];
|
|
|
74
74
|
|
|
75
75
|
export type IsRecursive<T> = true extends DetectCycle<T> ? true : false;
|
|
76
76
|
|
|
77
|
+
type NonRecursiveLeaf = Brand.Brand<any> | GenericId<any> | ArrayBuffer;
|
|
78
|
+
|
|
77
79
|
type DetectCycle<T, Cache extends any[] = []> =
|
|
78
80
|
IsAny<T> extends true
|
|
79
81
|
? false
|
|
80
82
|
: [T] extends [any]
|
|
81
|
-
? T extends
|
|
82
|
-
?
|
|
83
|
-
: T extends
|
|
84
|
-
?
|
|
85
|
-
: T extends
|
|
86
|
-
? DetectCycle<
|
|
87
|
-
: T extends
|
|
88
|
-
? DetectCycle<
|
|
89
|
-
: T extends
|
|
90
|
-
?
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
83
|
+
? T extends NonRecursiveLeaf
|
|
84
|
+
? false
|
|
85
|
+
: T extends Cache[number]
|
|
86
|
+
? true
|
|
87
|
+
: T extends Array<infer U>
|
|
88
|
+
? DetectCycle<U, [...Cache, T]>
|
|
89
|
+
: T extends Map<infer _U, infer V>
|
|
90
|
+
? DetectCycle<V, [...Cache, T]>
|
|
91
|
+
: T extends Set<infer U>
|
|
92
|
+
? DetectCycle<U, [...Cache, T]>
|
|
93
|
+
: T extends object
|
|
94
|
+
? true extends {
|
|
95
|
+
[K in keyof T]: DetectCycle<T[K], [...Cache, T]>;
|
|
96
|
+
}[keyof T]
|
|
97
|
+
? true
|
|
98
|
+
: false
|
|
94
99
|
: false
|
|
95
|
-
: false
|
|
96
100
|
: never;
|
|
97
101
|
|
|
98
102
|
//////////////////////////////////
|