@confect/core 5.0.0 → 7.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 +132 -0
- package/dist/FunctionProvenance.d.ts +12 -3
- package/dist/FunctionProvenance.d.ts.map +1 -1
- package/dist/FunctionProvenance.js +3 -2
- package/dist/FunctionProvenance.js.map +1 -1
- package/dist/FunctionSpec.d.ts +48 -26
- package/dist/FunctionSpec.d.ts.map +1 -1
- package/dist/FunctionSpec.js +2 -2
- package/dist/FunctionSpec.js.map +1 -1
- package/dist/Ref.d.ts +60 -25
- package/dist/Ref.d.ts.map +1 -1
- package/dist/Ref.js +70 -15
- package/dist/Ref.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/FunctionProvenance.ts +7 -0
- package/src/FunctionSpec.ts +26 -2
- package/src/Ref.ts +197 -45
- package/src/Types.ts +19 -15
package/dist/Ref.d.ts
CHANGED
|
@@ -1,35 +1,39 @@
|
|
|
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
|
-
import { AnyWithProps, Args as Args$1, GetFunctionVisibility as GetFunctionVisibility$1, GetRuntimeAndFunctionType as GetRuntimeAndFunctionType$1, Returns as Returns$1 } from "./FunctionSpec.js";
|
|
3
|
-
import { Effect, ParseResult } from "effect";
|
|
2
|
+
import { AnyWithProps, Args as Args$1, Error as Error$1, GetFunctionVisibility as GetFunctionVisibility$1, GetRuntimeAndFunctionType as GetRuntimeAndFunctionType$1, Returns as Returns$1 } from "./FunctionSpec.js";
|
|
3
|
+
import { Effect, Option, ParseResult } from "effect";
|
|
4
4
|
import { FunctionReference as FunctionReference$1, FunctionVisibility } from "convex/server";
|
|
5
|
+
import { ConvexError, Value } from "convex/values";
|
|
5
6
|
|
|
6
7
|
//#region src/Ref.d.ts
|
|
7
8
|
declare namespace Ref_d_exports {
|
|
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 };
|
|
9
|
+
export { Any, AnyAction, AnyInternal, AnyMutation, AnyPublic, AnyPublicAction, AnyPublicMutation, AnyPublicQuery, AnyQuery, Args, Error, FromFunctionSpec, FunctionReference, GetFunctionType, GetFunctionVisibility, GetRuntime, GetRuntimeAndFunctionType, OptionalArgs, Ref, Returns, decodeError, decodeErrorOrElse, decodeErrorSync, decodeReturns, decodeReturnsSync, encodeArgs, encodeArgsSync, getConvexFunctionName, getFunctionReference, hasErrorSchema, isConvexError, make, maybeDecodeErrorSync, runWithCodec };
|
|
9
10
|
}
|
|
10
|
-
interface Ref<_RuntimeAndFunctionType extends RuntimeAndFunctionType, _FunctionVisibility extends FunctionVisibility, _Args, _Returns> {
|
|
11
|
+
interface Ref<_RuntimeAndFunctionType extends RuntimeAndFunctionType, _FunctionVisibility extends FunctionVisibility, _Args, _Returns, _Error = never> {
|
|
11
12
|
readonly _RuntimeAndFunctionType?: _RuntimeAndFunctionType;
|
|
12
13
|
readonly _FunctionVisibility?: _FunctionVisibility;
|
|
13
14
|
readonly _Args?: _Args;
|
|
14
15
|
readonly _Returns?: _Returns;
|
|
16
|
+
readonly _Error?: _Error;
|
|
15
17
|
}
|
|
16
|
-
interface Any extends Ref<any, any, any, any> {}
|
|
17
|
-
interface AnyInternal extends Ref<any, "internal", any, any> {}
|
|
18
|
-
interface AnyPublic extends Ref<any, "public", any, any> {}
|
|
19
|
-
interface AnyQuery extends Ref<AnyQuery$1, FunctionVisibility, any, any> {}
|
|
20
|
-
interface AnyMutation extends Ref<AnyMutation$1, FunctionVisibility, any, any> {}
|
|
21
|
-
interface AnyAction extends Ref<AnyAction$1, FunctionVisibility, any, any> {}
|
|
22
|
-
interface AnyPublicQuery extends Ref<AnyQuery$1, "public", any, any> {}
|
|
23
|
-
interface AnyPublicMutation extends Ref<AnyMutation$1, "public", any, any> {}
|
|
24
|
-
interface AnyPublicAction extends Ref<AnyAction$1, "public", any, any> {}
|
|
25
|
-
type GetRuntimeAndFunctionType<Ref_> = Ref_ extends Ref<infer RuntimeAndFunctionType_, infer _FunctionVisibility, infer _Args, infer _Returns> ? RuntimeAndFunctionType_ : never;
|
|
26
|
-
type GetRuntime<Ref_> = Ref_ extends Ref<infer RuntimeAndFunctionType_, infer _FunctionVisibility, infer _Args, infer _Returns> ? GetRuntime$1<RuntimeAndFunctionType_> : never;
|
|
27
|
-
type GetFunctionType<Ref_> = Ref_ extends Ref<infer RuntimeAndFunctionType_, infer _FunctionVisibility, infer _Args, infer _Returns> ? GetFunctionType$1<RuntimeAndFunctionType_> : never;
|
|
28
|
-
type GetFunctionVisibility<Ref_> = Ref_ extends Ref<infer _RuntimeAndFunctionType, infer FunctionVisibility_, infer _Args, infer _Returns> ? FunctionVisibility_ : never;
|
|
29
|
-
type Args<Ref_> = Ref_ extends Ref<infer _RuntimeAndFunctionType, infer _FunctionVisibility, infer Args_, infer _Returns> ? Args_ : never;
|
|
30
|
-
type
|
|
18
|
+
interface Any extends Ref<any, any, any, any, any> {}
|
|
19
|
+
interface AnyInternal extends Ref<any, "internal", any, any, any> {}
|
|
20
|
+
interface AnyPublic extends Ref<any, "public", any, any, any> {}
|
|
21
|
+
interface AnyQuery extends Ref<AnyQuery$1, FunctionVisibility, any, any, any> {}
|
|
22
|
+
interface AnyMutation extends Ref<AnyMutation$1, FunctionVisibility, any, any, any> {}
|
|
23
|
+
interface AnyAction extends Ref<AnyAction$1, FunctionVisibility, any, any, any> {}
|
|
24
|
+
interface AnyPublicQuery extends Ref<AnyQuery$1, "public", any, any, any> {}
|
|
25
|
+
interface AnyPublicMutation extends Ref<AnyMutation$1, "public", any, any, any> {}
|
|
26
|
+
interface AnyPublicAction extends Ref<AnyAction$1, "public", any, any, any> {}
|
|
27
|
+
type GetRuntimeAndFunctionType<Ref_> = Ref_ extends Ref<infer RuntimeAndFunctionType_, infer _FunctionVisibility, infer _Args, infer _Returns, infer _Error> ? RuntimeAndFunctionType_ : never;
|
|
28
|
+
type GetRuntime<Ref_> = Ref_ extends Ref<infer RuntimeAndFunctionType_, infer _FunctionVisibility, infer _Args, infer _Returns, infer _Error> ? GetRuntime$1<RuntimeAndFunctionType_> : never;
|
|
29
|
+
type GetFunctionType<Ref_> = Ref_ extends Ref<infer RuntimeAndFunctionType_, infer _FunctionVisibility, infer _Args, infer _Returns, infer _Error> ? GetFunctionType$1<RuntimeAndFunctionType_> : never;
|
|
30
|
+
type GetFunctionVisibility<Ref_> = Ref_ extends Ref<infer _RuntimeAndFunctionType, infer FunctionVisibility_, infer _Args, infer _Returns, infer _Error> ? FunctionVisibility_ : never;
|
|
31
|
+
type Args<Ref_> = Ref_ extends Ref<infer _RuntimeAndFunctionType, infer _FunctionVisibility, infer Args_, infer _Returns, infer _Error> ? Args_ : never;
|
|
32
|
+
type OptionalArgs<Ref_ extends Any> = keyof Args<Ref_> extends never ? [args?: Args<Ref_>] : [args: Args<Ref_>];
|
|
33
|
+
type Returns<Ref_> = Ref_ extends Ref<infer _RuntimeAndFunctionType, infer _FunctionVisibility, infer _Args, infer Returns_, infer _Error> ? Returns_ : never;
|
|
34
|
+
type Error<Ref_> = Ref_ extends Ref<infer _RuntimeAndFunctionType, infer _FunctionVisibility, infer _Args, infer _Returns, infer Error_> ? Error_ : never;
|
|
31
35
|
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_>>;
|
|
36
|
+
type FromFunctionSpec<FunctionSpec_ extends AnyWithProps> = Ref<GetRuntimeAndFunctionType$1<FunctionSpec_>, GetFunctionVisibility$1<FunctionSpec_>, Args$1<FunctionSpec_>, Returns$1<FunctionSpec_>, Error$1<FunctionSpec_>>;
|
|
33
37
|
declare const make: <FunctionSpec_ extends AnyWithProps>(
|
|
34
38
|
/**
|
|
35
39
|
* The namespace portion of a Convex function name, i.e. the part before the
|
|
@@ -40,14 +44,45 @@ declare const make: <FunctionSpec_ extends AnyWithProps>(
|
|
|
40
44
|
functionNamespace: string, functionSpec: FunctionSpec_) => FromFunctionSpec<FunctionSpec_>;
|
|
41
45
|
declare const getConvexFunctionName: (ref: Any) => string;
|
|
42
46
|
declare const getFunctionReference: <Ref_ extends Any>(ref: Ref_) => FunctionReference<Ref_>;
|
|
47
|
+
declare const hasErrorSchema: (ref: Any) => boolean;
|
|
43
48
|
declare const encodeArgs: <Ref_ extends Any>(ref: Ref_, args: Args<Ref_>) => Effect.Effect<unknown, ParseResult.ParseError>;
|
|
44
49
|
declare const decodeReturns: <Ref_ extends Any>(ref: Ref_, returns: unknown) => Effect.Effect<Returns<Ref_>, ParseResult.ParseError>;
|
|
45
50
|
declare const encodeArgsSync: <Ref_ extends Any>(ref: Ref_, args: Args<Ref_>) => unknown;
|
|
46
51
|
declare const decodeReturnsSync: <Ref_ extends Any>(ref: Ref_, encodedReturns: unknown) => Returns<Ref_>;
|
|
47
|
-
declare const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
declare const isConvexError: (error: unknown) => error is ConvexError<Value>;
|
|
53
|
+
/**
|
|
54
|
+
* Build a callback-style handler that decodes the ref's typed error from a
|
|
55
|
+
* caught `ConvexError`, or else forwards the value to `mapUnknownError`. The
|
|
56
|
+
* fallback is also invoked when the input *is* a `ConvexError` but the ref
|
|
57
|
+
* doesn't declare a typed-error schema—by definition such a value falls
|
|
58
|
+
* outside the ref's error contract. Useful when adapting non-Effect APIs (e.g.
|
|
59
|
+
* emitter callbacks for streamed subscriptions) to the same error semantics
|
|
60
|
+
* that `runWithCodec` provides.
|
|
61
|
+
*/
|
|
62
|
+
declare const decodeErrorOrElse: <Ref_ extends Any, E>(ref: Ref_, mapUnknownError: (error: unknown) => E) => (error: unknown) => Error<Ref_> | E;
|
|
63
|
+
/**
|
|
64
|
+
* Decode `encodedError` against the ref's error schema. Returns `None` if the
|
|
65
|
+
* ref doesn't declare a typed error (Confect ref without an `error` schema, or
|
|
66
|
+
* a Convex-provenance ref)—by definition there's nothing to decode the value
|
|
67
|
+
* into, and the caller is responsible for deciding what to do (typically:
|
|
68
|
+
* surface the original value as a defect).
|
|
69
|
+
*/
|
|
70
|
+
declare const decodeError: <Ref_ extends Any>(ref: Ref_, encodedError: unknown) => Effect.Effect<Option.Option<Error<Ref_>>, ParseResult.ParseError>;
|
|
71
|
+
/**
|
|
72
|
+
* Synchronous counterpart to `decodeError`. Throws on schema decode failure;
|
|
73
|
+
* returns `None` when the ref doesn't declare a typed error.
|
|
74
|
+
*/
|
|
75
|
+
declare const decodeErrorSync: <Ref_ extends Any>(ref: Ref_, encodedError: unknown) => Option.Option<Error<Ref_>>;
|
|
76
|
+
declare const maybeDecodeErrorSync: <Ref_ extends Any>(ref: Ref_, error: unknown) => unknown;
|
|
77
|
+
/**
|
|
78
|
+
* Encode args via the ref's args schema, invoke `call`, decode returns via the
|
|
79
|
+
* ref's returns schema, and translate any thrown `ConvexError` into the ref's
|
|
80
|
+
* typed error. Anything else the Promise rejects with—network failures,
|
|
81
|
+
* server-side runtime errors, validation failures, etc.—is passed to
|
|
82
|
+
* `mapUnknownError` to be turned into a typed `E`, or surfaced as a defect when
|
|
83
|
+
* no handler is provided.
|
|
84
|
+
*/
|
|
85
|
+
declare const runWithCodec: <Ref_ extends Any, E = never>(ref: Ref_, args: Args<Ref_>, call: (functionReference: FunctionReference<Ref_>, encodedArgs: unknown) => PromiseLike<unknown>, mapUnknownError?: (error: unknown) => E) => Effect.Effect<Returns<Ref_>, E | Error<Ref_> | ParseResult.ParseError>;
|
|
51
86
|
//#endregion
|
|
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 };
|
|
87
|
+
export { Any, AnyAction, AnyInternal, AnyMutation, AnyPublic, AnyPublicAction, AnyPublicMutation, AnyPublicQuery, AnyQuery, Args, Error, FromFunctionSpec, FunctionReference, GetFunctionType, GetFunctionVisibility, GetRuntime, GetRuntimeAndFunctionType, OptionalArgs, Ref, Ref_d_exports, Returns, decodeError, decodeErrorOrElse, decodeErrorSync, decodeReturns, decodeReturnsSync, encodeArgs, encodeArgsSync, getConvexFunctionName, getFunctionReference, hasErrorSchema, isConvexError, make, maybeDecodeErrorSync, runWithCodec };
|
|
53
88
|
//# 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":";;;;;;;;;;UAYiB,GAAA,iCACiB,sBAAA,8BACJ,kBAAA;EAAA,SAKnB,uBAAA,GAA0B,uBAAA;EAAA,SAC1B,mBAAA,GAAsB,mBAAA;EAAA,SACtB,KAAA,GAAQ,KAAA;EAAA,SACR,QAAA,GAAW,QAAA;EAAA,SACX,MAAA,GAAS,MAAA;AAAA;AAAA,UA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AAAA,cAeV,oBAAA,gBAAqC,GAAA,EAChD,GAAA,EAAK,IAAA,EACL,KAAA;AA7SF;;;;;AAEA;;;AAFA,cAmUa,YAAA,gBAA6B,GAAA,aACxC,GAAA,EAAK,IAAA,EACL,IAAA,EAAM,IAAA,CAAK,IAAA,GACX,IAAA,GACE,iBAAA,EAAmB,iBAAA,CAAkB,IAAA,GACrC,WAAA,cACG,WAAA,WACL,eAAA,IAAmB,KAAA,cAAmB,CAAA,KACrC,MAAA,CAAO,MAAA,CAAO,OAAA,CAAQ,IAAA,GAAO,CAAA,GAAI,KAAA,CAAM,IAAA,IAAQ,WAAA,CAAY,UAAA"}
|
package/dist/Ref.js
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
-
import { Effect, Match, Schema } from "effect";
|
|
2
|
+
import { Effect, Match, Option, Schema } from "effect";
|
|
3
3
|
import { makeFunctionReference } from "convex/server";
|
|
4
|
+
import { ConvexError } from "convex/values";
|
|
4
5
|
|
|
5
6
|
//#region src/Ref.ts
|
|
6
7
|
var Ref_exports = /* @__PURE__ */ __exportAll({
|
|
8
|
+
decodeError: () => decodeError,
|
|
9
|
+
decodeErrorOrElse: () => decodeErrorOrElse,
|
|
10
|
+
decodeErrorSync: () => decodeErrorSync,
|
|
7
11
|
decodeReturns: () => decodeReturns,
|
|
8
12
|
decodeReturnsSync: () => decodeReturnsSync,
|
|
9
13
|
encodeArgs: () => encodeArgs,
|
|
10
14
|
encodeArgsSync: () => encodeArgsSync,
|
|
11
15
|
getConvexFunctionName: () => getConvexFunctionName,
|
|
12
16
|
getFunctionReference: () => getFunctionReference,
|
|
17
|
+
hasErrorSchema: () => hasErrorSchema,
|
|
18
|
+
isConvexError: () => isConvexError,
|
|
13
19
|
make: () => make,
|
|
20
|
+
maybeDecodeErrorSync: () => maybeDecodeErrorSync,
|
|
14
21
|
runWithCodec: () => runWithCodec
|
|
15
22
|
});
|
|
16
23
|
const make = (functionNamespace, functionSpec) => ({
|
|
@@ -19,23 +26,71 @@ const make = (functionNamespace, functionSpec) => ({
|
|
|
19
26
|
});
|
|
20
27
|
const getConvexFunctionName = (ref) => `${ref.functionNamespace}:${ref.functionSpec.name}`;
|
|
21
28
|
const getFunctionReference = (ref) => makeFunctionReference(getConvexFunctionName(ref));
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
29
|
+
const hasErrorSchema = (ref) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => confectFunctionProvenance.error !== void 0), Match.tag("Convex", () => false), Match.exhaustive);
|
|
30
|
+
const encodeArgs = (ref, args) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => Schema.encode(confectFunctionProvenance.args)(args)), Match.tag("Convex", () => Effect.succeed(args)), Match.exhaustive);
|
|
31
|
+
const decodeReturns = (ref, returns) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => Schema.decode(confectFunctionProvenance.returns)(returns)), Match.tag("Convex", () => Effect.succeed(returns)), Match.exhaustive);
|
|
32
|
+
const encodeArgsSync = (ref, args) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => Schema.encodeSync(confectFunctionProvenance.args)(args)), Match.tag("Convex", () => args), Match.exhaustive);
|
|
33
|
+
const decodeReturnsSync = (ref, encodedReturns) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => Schema.decodeSync(confectFunctionProvenance.returns)(encodedReturns)), Match.tag("Convex", () => encodedReturns), Match.exhaustive);
|
|
34
|
+
const ConvexErrorIdentifier = Symbol.for("ConvexError");
|
|
35
|
+
const isConvexError = (error) => error instanceof ConvexError || typeof error === "object" && error !== null && ConvexErrorIdentifier in error;
|
|
36
|
+
/**
|
|
37
|
+
* Build a callback-style handler that decodes the ref's typed error from a
|
|
38
|
+
* caught `ConvexError`, or else forwards the value to `mapUnknownError`. The
|
|
39
|
+
* fallback is also invoked when the input *is* a `ConvexError` but the ref
|
|
40
|
+
* doesn't declare a typed-error schema—by definition such a value falls
|
|
41
|
+
* outside the ref's error contract. Useful when adapting non-Effect APIs (e.g.
|
|
42
|
+
* emitter callbacks for streamed subscriptions) to the same error semantics
|
|
43
|
+
* that `runWithCodec` provides.
|
|
44
|
+
*/
|
|
45
|
+
const decodeErrorOrElse = (ref, mapUnknownError) => (error) => {
|
|
46
|
+
if (isConvexError(error)) {
|
|
47
|
+
const decoded = decodeErrorSync(ref, error.data);
|
|
48
|
+
if (Option.isSome(decoded)) return decoded.value;
|
|
49
|
+
}
|
|
50
|
+
return mapUnknownError(error);
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Decode `encodedError` against the ref's error schema. Returns `None` if the
|
|
54
|
+
* ref doesn't declare a typed error (Confect ref without an `error` schema, or
|
|
55
|
+
* a Convex-provenance ref)—by definition there's nothing to decode the value
|
|
56
|
+
* into, and the caller is responsible for deciding what to do (typically:
|
|
57
|
+
* surface the original value as a defect).
|
|
58
|
+
*/
|
|
59
|
+
const decodeError = (ref, encodedError) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => confectFunctionProvenance.error !== void 0 ? Effect.map(Schema.decode(confectFunctionProvenance.error)(encodedError), Option.some) : Effect.succeed(Option.none())), Match.tag("Convex", () => Effect.succeed(Option.none())), Match.exhaustive);
|
|
60
|
+
/**
|
|
61
|
+
* Synchronous counterpart to `decodeError`. Throws on schema decode failure;
|
|
62
|
+
* returns `None` when the ref doesn't declare a typed error.
|
|
63
|
+
*/
|
|
64
|
+
const decodeErrorSync = (ref, encodedError) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => confectFunctionProvenance.error !== void 0 ? Option.some(Schema.decodeSync(confectFunctionProvenance.error)(encodedError)) : Option.none()), Match.tag("Convex", () => Option.none()), Match.exhaustive);
|
|
65
|
+
const maybeDecodeErrorSync = (ref, error) => isConvexError(error) ? Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => confectFunctionProvenance.error !== void 0 ? Schema.decodeSync(confectFunctionProvenance.error)(error.data) : error), Match.tag("Convex", () => error), Match.exhaustive) : error;
|
|
66
|
+
/**
|
|
67
|
+
* Encode args via the ref's args schema, invoke `call`, decode returns via the
|
|
68
|
+
* ref's returns schema, and translate any thrown `ConvexError` into the ref's
|
|
69
|
+
* typed error. Anything else the Promise rejects with—network failures,
|
|
70
|
+
* server-side runtime errors, validation failures, etc.—is passed to
|
|
71
|
+
* `mapUnknownError` to be turned into a typed `E`, or surfaced as a defect when
|
|
72
|
+
* no handler is provided.
|
|
73
|
+
*/
|
|
74
|
+
const runWithCodec = (ref, args, call, mapUnknownError) => Effect.gen(function* () {
|
|
27
75
|
const functionReference = getFunctionReference(ref);
|
|
28
76
|
const functionProvenance = ref.functionSpec.functionProvenance;
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
77
|
+
const invoke = (encodedArgs) => Effect.tryPromise({
|
|
78
|
+
try: () => Promise.resolve(call(functionReference, encodedArgs)),
|
|
79
|
+
catch: (error) => {
|
|
80
|
+
if (isConvexError(error)) {
|
|
81
|
+
const decoded = decodeErrorSync(ref, error.data);
|
|
82
|
+
if (Option.isSome(decoded)) return decoded.value;
|
|
83
|
+
}
|
|
84
|
+
if (mapUnknownError !== void 0) return mapUnknownError(error);
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
return yield* Match.value(functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => Effect.gen(function* () {
|
|
89
|
+
const encodedReturns = yield* invoke(yield* Schema.encode(confectFunctionProvenance.args)(args));
|
|
90
|
+
return yield* Schema.decode(confectFunctionProvenance.returns)(encodedReturns);
|
|
91
|
+
})), Match.tag("Convex", () => invoke(args)), Match.exhaustive);
|
|
37
92
|
});
|
|
38
93
|
|
|
39
94
|
//#endregion
|
|
40
|
-
export { Ref_exports, decodeReturns, decodeReturnsSync, encodeArgs, encodeArgsSync, getConvexFunctionName, getFunctionReference, make, runWithCodec };
|
|
95
|
+
export { Ref_exports, decodeError, decodeErrorOrElse, decodeErrorSync, decodeReturns, decodeReturnsSync, encodeArgs, encodeArgsSync, getConvexFunctionName, getFunctionReference, hasErrorSchema, isConvexError, make, maybeDecodeErrorSync, runWithCodec };
|
|
41
96
|
//# 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 {\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,yBAAy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ACpB,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"}
|
|
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 { Value } from \"convex/values\";\nimport { ConvexError } from \"convex/values\";\nimport type { ParseResult } from \"effect\";\nimport { Effect, Match, Option, 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 _Error = never,\n> {\n readonly _RuntimeAndFunctionType?: _RuntimeAndFunctionType;\n readonly _FunctionVisibility?: _FunctionVisibility;\n readonly _Args?: _Args;\n readonly _Returns?: _Returns;\n readonly _Error?: _Error;\n /** @internal */\n readonly functionSpec: FunctionSpec.AnyWithProps;\n /** @internal */\n readonly functionNamespace: string;\n}\n\nexport interface Any extends Ref<any, any, any, any, any> {}\n\nexport interface AnyInternal extends Ref<any, \"internal\", any, any, any> {}\n\nexport interface AnyPublic extends Ref<any, \"public\", any, any, any> {}\n\nexport interface AnyQuery extends Ref<\n RuntimeAndFunctionType.AnyQuery,\n FunctionVisibility,\n any,\n any,\n any\n> {}\n\nexport interface AnyMutation extends Ref<\n RuntimeAndFunctionType.AnyMutation,\n FunctionVisibility,\n any,\n any,\n any\n> {}\n\nexport interface AnyAction extends Ref<\n RuntimeAndFunctionType.AnyAction,\n FunctionVisibility,\n any,\n any,\n any\n> {}\n\nexport interface AnyPublicQuery extends Ref<\n RuntimeAndFunctionType.AnyQuery,\n \"public\",\n any,\n any,\n any\n> {}\n\nexport interface AnyPublicMutation extends Ref<\n RuntimeAndFunctionType.AnyMutation,\n \"public\",\n any,\n any,\n any\n> {}\n\nexport interface AnyPublicAction extends Ref<\n RuntimeAndFunctionType.AnyAction,\n \"public\",\n any,\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 infer _Error\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 infer _Error\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 infer _Error\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 infer _Error\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 infer _Error\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 infer _Error\n >\n ? Returns_\n : never;\n\nexport type Error<Ref_> =\n Ref_ extends Ref<\n infer _RuntimeAndFunctionType,\n infer _FunctionVisibility,\n infer _Args,\n infer _Returns,\n infer Error_\n >\n ? Error_\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 FunctionSpec.Error<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 hasErrorSchema = (ref: Any): boolean =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\n \"Confect\",\n (confectFunctionProvenance) =>\n confectFunctionProvenance.error !== undefined,\n ),\n Match.tag(\"Convex\", () => false),\n Match.exhaustive,\n );\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\", (confectFunctionProvenance) =>\n Schema.encode(confectFunctionProvenance.args)(args),\n ),\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\", (confectFunctionProvenance) =>\n Schema.decode(confectFunctionProvenance.returns)(returns),\n ),\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\", (confectFunctionProvenance) =>\n Schema.encodeSync(confectFunctionProvenance.args)(args),\n ),\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\", (confectFunctionProvenance) =>\n Schema.decodeSync(confectFunctionProvenance.returns)(encodedReturns),\n ),\n Match.tag(\"Convex\", () => encodedReturns),\n Match.exhaustive,\n ) as Returns<Ref_>;\n\nconst ConvexErrorIdentifier = Symbol.for(\"ConvexError\");\n\nexport const isConvexError = (error: unknown): error is ConvexError<Value> =>\n error instanceof ConvexError ||\n (typeof error === \"object\" &&\n error !== null &&\n ConvexErrorIdentifier in error);\n\n/**\n * Build a callback-style handler that decodes the ref's typed error from a\n * caught `ConvexError`, or else forwards the value to `mapUnknownError`. The\n * fallback is also invoked when the input *is* a `ConvexError` but the ref\n * doesn't declare a typed-error schema—by definition such a value falls\n * outside the ref's error contract. Useful when adapting non-Effect APIs (e.g.\n * emitter callbacks for streamed subscriptions) to the same error semantics\n * that `runWithCodec` provides.\n */\nexport const decodeErrorOrElse =\n <Ref_ extends Any, E>(ref: Ref_, mapUnknownError: (error: unknown) => E) =>\n (error: unknown): Error<Ref_> | E => {\n if (isConvexError(error)) {\n const decoded = decodeErrorSync(ref, error.data);\n if (Option.isSome(decoded)) {\n return decoded.value;\n }\n }\n return mapUnknownError(error);\n };\n\n/**\n * Decode `encodedError` against the ref's error schema. Returns `None` if the\n * ref doesn't declare a typed error (Confect ref without an `error` schema, or\n * a Convex-provenance ref)—by definition there's nothing to decode the value\n * into, and the caller is responsible for deciding what to do (typically:\n * surface the original value as a defect).\n */\nexport const decodeError = <Ref_ extends Any>(\n ref: Ref_,\n encodedError: unknown,\n): Effect.Effect<Option.Option<Error<Ref_>>, ParseResult.ParseError> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n confectFunctionProvenance.error !== undefined\n ? Effect.map(\n Schema.decode(confectFunctionProvenance.error)(encodedError),\n Option.some,\n )\n : Effect.succeed(Option.none<Error<Ref_>>()),\n ),\n Match.tag(\"Convex\", () => Effect.succeed(Option.none<Error<Ref_>>())),\n Match.exhaustive,\n );\n\n/**\n * Synchronous counterpart to `decodeError`. Throws on schema decode failure;\n * returns `None` when the ref doesn't declare a typed error.\n */\nexport const decodeErrorSync = <Ref_ extends Any>(\n ref: Ref_,\n encodedError: unknown,\n): Option.Option<Error<Ref_>> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n confectFunctionProvenance.error !== undefined\n ? Option.some(\n Schema.decodeSync(confectFunctionProvenance.error)(\n encodedError,\n ) as Error<Ref_>,\n )\n : Option.none<Error<Ref_>>(),\n ),\n Match.tag(\"Convex\", () => Option.none<Error<Ref_>>()),\n Match.exhaustive,\n );\n\nexport const maybeDecodeErrorSync = <Ref_ extends Any>(\n ref: Ref_,\n error: unknown,\n): unknown =>\n isConvexError(error)\n ? Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n confectFunctionProvenance.error !== undefined\n ? Schema.decodeSync(confectFunctionProvenance.error)(error.data)\n : error,\n ),\n Match.tag(\"Convex\", () => error),\n Match.exhaustive,\n )\n : error;\n\n/**\n * Encode args via the ref's args schema, invoke `call`, decode returns via the\n * ref's returns schema, and translate any thrown `ConvexError` into the ref's\n * typed error. Anything else the Promise rejects with—network failures,\n * server-side runtime errors, validation failures, etc.—is passed to\n * `mapUnknownError` to be turned into a typed `E`, or surfaced as a defect when\n * no handler is provided.\n */\nexport const runWithCodec = <Ref_ extends Any, E = never>(\n ref: Ref_,\n args: Args<Ref_>,\n call: (\n functionReference: FunctionReference<Ref_>,\n encodedArgs: unknown,\n ) => PromiseLike<unknown>,\n mapUnknownError?: (error: unknown) => E,\n): Effect.Effect<Returns<Ref_>, E | Error<Ref_> | ParseResult.ParseError> =>\n Effect.gen(function* () {\n const functionReference = getFunctionReference(ref);\n const functionProvenance = ref.functionSpec.functionProvenance;\n const invoke = (\n encodedArgs: unknown,\n ): Effect.Effect<unknown, Error<Ref_> | E> =>\n Effect.tryPromise({\n try: () => Promise.resolve(call(functionReference, encodedArgs)),\n catch: (error): Error<Ref_> | E => {\n if (isConvexError(error)) {\n const decoded = decodeErrorSync(ref, error.data);\n if (Option.isSome(decoded)) {\n return decoded.value;\n }\n }\n if (mapUnknownError !== undefined) {\n return mapUnknownError(error);\n }\n throw error;\n },\n });\n return yield* Match.value(functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Effect.gen(function* () {\n const encodedArgs = yield* Schema.encode(\n confectFunctionProvenance.args,\n )(args);\n const encodedReturns = yield* invoke(encodedArgs);\n return yield* Schema.decode(confectFunctionProvenance.returns)(\n encodedReturns,\n );\n }),\n ),\n Match.tag(\"Convex\", () => invoke(args)),\n Match.exhaustive,\n );\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAmLA,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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AM,KAAK;AAChD,QAAI,OAAO,OAAO,QAAQ,CACxB,QAAO,QAAQ;;AAGnB,OAAI,oBAAoB,OACtB,QAAO,gBAAgB,MAAM;AAE/B,SAAM;;EAET,CAAC;AACJ,QAAO,OAAO,MAAM,MAAM,mBAAmB,CAAC,KAC5C,MAAM,IAAI,YAAY,8BACpB,OAAO,IAAI,aAAa;EAItB,MAAM,iBAAiB,OAAO,OAHV,OAAO,OAAO,OAChC,0BAA0B,KAC3B,CAAC,KAAK,CAC0C;AACjD,SAAO,OAAO,OAAO,OAAO,0BAA0B,QAAQ,CAC5D,eACD;GACD,CACH,EACD,MAAM,IAAI,gBAAgB,OAAO,KAAK,CAAC,EACvC,MAAM,WACP;EACD"}
|
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,cA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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
|
@@ -6,6 +6,7 @@ export type FunctionProvenance = Data.TaggedEnum<{
|
|
|
6
6
|
Confect: {
|
|
7
7
|
args: Schema.Schema.AnyNoContext;
|
|
8
8
|
returns: Schema.Schema.AnyNoContext;
|
|
9
|
+
error?: Schema.Schema.AnyNoContext;
|
|
9
10
|
};
|
|
10
11
|
Convex: {
|
|
11
12
|
/** @internal */
|
|
@@ -18,13 +19,16 @@ export type FunctionProvenance = Data.TaggedEnum<{
|
|
|
18
19
|
export interface Confect<
|
|
19
20
|
Args extends Schema.Schema.AnyNoContext,
|
|
20
21
|
Returns extends Schema.Schema.AnyNoContext,
|
|
22
|
+
Error extends Schema.Schema.AnyNoContext = never,
|
|
21
23
|
> {
|
|
22
24
|
readonly _tag: "Confect";
|
|
23
25
|
readonly args: Args;
|
|
24
26
|
readonly returns: Returns;
|
|
27
|
+
readonly error?: Error;
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
export interface AnyConfect extends Confect<
|
|
31
|
+
Schema.Schema.AnyNoContext,
|
|
28
32
|
Schema.Schema.AnyNoContext,
|
|
29
33
|
Schema.Schema.AnyNoContext
|
|
30
34
|
> {}
|
|
@@ -42,13 +46,16 @@ export const FunctionProvenance = Data.taggedEnum<FunctionProvenance>();
|
|
|
42
46
|
export const Confect = <
|
|
43
47
|
Args extends Schema.Schema.AnyNoContext,
|
|
44
48
|
Returns extends Schema.Schema.AnyNoContext,
|
|
49
|
+
Error extends Schema.Schema.AnyNoContext = never,
|
|
45
50
|
>(
|
|
46
51
|
args: Args,
|
|
47
52
|
returns: Returns,
|
|
53
|
+
error?: Error,
|
|
48
54
|
) =>
|
|
49
55
|
FunctionProvenance.Confect({
|
|
50
56
|
args,
|
|
51
57
|
returns,
|
|
58
|
+
...(error !== undefined ? { error } : {}),
|
|
52
59
|
});
|
|
53
60
|
|
|
54
61
|
export const Convex = <_Args extends DefaultFunctionArgs, _Returns>() =>
|
package/src/FunctionSpec.ts
CHANGED
|
@@ -145,6 +145,27 @@ export type EncodedReturns<FunctionSpec_ extends AnyWithProps> =
|
|
|
145
145
|
? Returns_
|
|
146
146
|
: never;
|
|
147
147
|
|
|
148
|
+
export type Error<FunctionSpec_ extends AnyWithProps> = FunctionSpec_ extends {
|
|
149
|
+
functionProvenance: FunctionProvenance.Confect<
|
|
150
|
+
any,
|
|
151
|
+
any,
|
|
152
|
+
infer ErrorSchema_ extends Schema.Schema.AnyNoContext
|
|
153
|
+
>;
|
|
154
|
+
}
|
|
155
|
+
? ErrorSchema_["Type"]
|
|
156
|
+
: never;
|
|
157
|
+
|
|
158
|
+
export type EncodedError<FunctionSpec_ extends AnyWithProps> =
|
|
159
|
+
FunctionSpec_ extends {
|
|
160
|
+
functionProvenance: FunctionProvenance.Confect<
|
|
161
|
+
any,
|
|
162
|
+
any,
|
|
163
|
+
infer ErrorSchema_ extends Schema.Schema.AnyNoContext
|
|
164
|
+
>;
|
|
165
|
+
}
|
|
166
|
+
? ErrorSchema_["Encoded"]
|
|
167
|
+
: never;
|
|
168
|
+
|
|
148
169
|
export type WithName<
|
|
149
170
|
FunctionSpec_ extends AnyWithProps,
|
|
150
171
|
Name_ extends string,
|
|
@@ -196,19 +217,22 @@ const make =
|
|
|
196
217
|
const Name_ extends string,
|
|
197
218
|
Args_ extends Schema.Schema.AnyNoContext,
|
|
198
219
|
Returns_ extends Schema.Schema.AnyNoContext,
|
|
220
|
+
Error_ extends Schema.Schema.AnyNoContext = never,
|
|
199
221
|
>({
|
|
200
222
|
name,
|
|
201
223
|
args,
|
|
202
224
|
returns,
|
|
225
|
+
error,
|
|
203
226
|
}: {
|
|
204
227
|
name: Name_;
|
|
205
228
|
args: Args_;
|
|
206
229
|
returns: Returns_;
|
|
230
|
+
error?: Error_;
|
|
207
231
|
}): FunctionSpec<
|
|
208
232
|
RuntimeAndFunctionType_,
|
|
209
233
|
FunctionVisibility_,
|
|
210
234
|
Name_,
|
|
211
|
-
FunctionProvenance.Confect<Args_, Returns_>
|
|
235
|
+
FunctionProvenance.Confect<Args_, Returns_, Error_>
|
|
212
236
|
> => {
|
|
213
237
|
validateConfectFunctionIdentifier(name);
|
|
214
238
|
|
|
@@ -216,7 +240,7 @@ const make =
|
|
|
216
240
|
runtimeAndFunctionType,
|
|
217
241
|
functionVisibility,
|
|
218
242
|
name,
|
|
219
|
-
functionProvenance: FunctionProvenance.Confect(args, returns),
|
|
243
|
+
functionProvenance: FunctionProvenance.Confect(args, returns, error),
|
|
220
244
|
});
|
|
221
245
|
};
|
|
222
246
|
|