@confect/core 1.0.3 → 3.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/src/Ref.ts CHANGED
@@ -1,13 +1,12 @@
1
1
  import type { FunctionVisibility } from "convex/server";
2
- import type { Schema } from "effect";
3
2
  import type * as FunctionSpec from "./FunctionSpec";
4
3
  import type * as RuntimeAndFunctionType from "./RuntimeAndFunctionType";
5
4
 
6
5
  export interface Ref<
7
6
  _RuntimeAndFunctionType extends RuntimeAndFunctionType.RuntimeAndFunctionType,
8
7
  _FunctionVisibility extends FunctionVisibility,
9
- _Args extends Schema.Schema.AnyNoContext,
10
- _Returns extends Schema.Schema.AnyNoContext,
8
+ _Args,
9
+ _Returns,
11
10
  > {
12
11
  readonly _RuntimeAndFunctionType?: _RuntimeAndFunctionType;
13
12
  readonly _FunctionVisibility?: _FunctionVisibility;
@@ -24,43 +23,43 @@ export interface AnyPublic extends Ref<any, "public", any, any> {}
24
23
  export interface AnyQuery extends Ref<
25
24
  RuntimeAndFunctionType.AnyQuery,
26
25
  FunctionVisibility,
27
- Schema.Schema.AnyNoContext,
28
- Schema.Schema.AnyNoContext
26
+ any,
27
+ any
29
28
  > {}
30
29
 
31
30
  export interface AnyMutation extends Ref<
32
31
  RuntimeAndFunctionType.AnyMutation,
33
32
  FunctionVisibility,
34
- Schema.Schema.AnyNoContext,
35
- Schema.Schema.AnyNoContext
33
+ any,
34
+ any
36
35
  > {}
37
36
 
38
37
  export interface AnyAction extends Ref<
39
38
  RuntimeAndFunctionType.AnyAction,
40
39
  FunctionVisibility,
41
- Schema.Schema.AnyNoContext,
42
- Schema.Schema.AnyNoContext
40
+ any,
41
+ any
43
42
  > {}
44
43
 
45
44
  export interface AnyPublicQuery extends Ref<
46
45
  RuntimeAndFunctionType.AnyQuery,
47
46
  "public",
48
- Schema.Schema.AnyNoContext,
49
- Schema.Schema.AnyNoContext
47
+ any,
48
+ any
50
49
  > {}
51
50
 
52
51
  export interface AnyPublicMutation extends Ref<
53
52
  RuntimeAndFunctionType.AnyMutation,
54
53
  "public",
55
- Schema.Schema.AnyNoContext,
56
- Schema.Schema.AnyNoContext
54
+ any,
55
+ any
57
56
  > {}
58
57
 
59
58
  export interface AnyPublicAction extends Ref<
60
59
  RuntimeAndFunctionType.AnyAction,
61
60
  "public",
62
- Schema.Schema.AnyNoContext,
63
- Schema.Schema.AnyNoContext
61
+ any,
62
+ any
64
63
  > {}
65
64
 
66
65
  export type GetRuntimeAndFunctionType<Ref_> =
@@ -130,64 +129,25 @@ export type FromFunctionSpec<F extends FunctionSpec.AnyWithProps> = Ref<
130
129
  FunctionSpec.Returns<F>
131
130
  >;
132
131
 
133
- export const make = <
134
- RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,
135
- FunctionVisibility_ extends FunctionVisibility,
136
- Args_ extends Schema.Schema.AnyNoContext,
137
- Returns_ extends Schema.Schema.AnyNoContext,
138
- >(
132
+ export const make = <FunctionSpec_ extends FunctionSpec.AnyWithProps>(
139
133
  /**
140
- * This is a Convex "function name" of the format "myGroupDir/myGroupMod:myFunc".
134
+ * This is a Convex "function name" of the format `myGroupDir/myGroupMod:myFunc`.
141
135
  */
142
136
  convexFunctionName: string,
143
- function_: FunctionSpec.FunctionSpec<
144
- RuntimeAndFunctionType_,
145
- FunctionVisibility_,
146
- string,
147
- Args_,
148
- Returns_
149
- >,
150
- ): Ref<RuntimeAndFunctionType_, FunctionVisibility_, Args_, Returns_> =>
137
+ functionSpec: FunctionSpec_,
138
+ ): FromFunctionSpec<FunctionSpec_> =>
151
139
  ({
152
- [HiddenFunctionKey]: function_,
140
+ [HiddenFunctionSpecKey]: functionSpec,
153
141
  [HiddenConvexFunctionNameKey]: convexFunctionName,
154
- }) as Ref<RuntimeAndFunctionType_, FunctionVisibility_, Args_, Returns_>;
155
-
156
- const HiddenFunctionKey = "@confect/core/api/HiddenFunctionKey";
157
- type HiddenFunctionKey = typeof HiddenFunctionKey;
158
- type HiddenFunction<Ref_ extends Any> = FunctionSpec.FunctionSpec<
159
- GetRuntimeAndFunctionType<Ref_>,
160
- GetFunctionVisibility<Ref_>,
161
- string,
162
- Args<Ref_>,
163
- Returns<Ref_>
164
- >;
142
+ }) as FromFunctionSpec<FunctionSpec_>;
165
143
 
166
- export const getFunction = <
167
- RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,
168
- FunctionVisibility_ extends FunctionVisibility,
169
- Args_ extends Schema.Schema.AnyNoContext,
170
- Returns_ extends Schema.Schema.AnyNoContext,
171
- Ref_ extends Ref<
172
- RuntimeAndFunctionType_,
173
- FunctionVisibility_,
174
- Args_,
175
- Returns_
176
- >,
177
- >(
178
- ref: Ref_,
179
- ): HiddenFunction<Ref_> => (ref as any)[HiddenFunctionKey];
144
+ const HiddenFunctionSpecKey = "@confect/core/api/HiddenFunctionSpecKey";
145
+
146
+ export const getFunctionSpec = (ref: Any): FunctionSpec.AnyWithProps =>
147
+ (ref as any)[HiddenFunctionSpecKey];
180
148
 
181
149
  const HiddenConvexFunctionNameKey =
182
150
  "@confect/core/api/HiddenConvexFunctionNameKey";
183
- type HiddenConvexFunctionNameKey = typeof HiddenConvexFunctionNameKey;
184
- type HiddenConvexFunctionName = string;
185
-
186
- export const getConvexFunctionName = <
187
- RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,
188
- FunctionVisibility_ extends FunctionVisibility,
189
- Args_ extends Schema.Schema.AnyNoContext,
190
- Returns_ extends Schema.Schema.AnyNoContext,
191
- >(
192
- ref: Ref<RuntimeAndFunctionType_, FunctionVisibility_, Args_, Returns_>,
193
- ): HiddenConvexFunctionName => (ref as any)[HiddenConvexFunctionNameKey];
151
+
152
+ export const getConvexFunctionName = (ref: Any): string =>
153
+ (ref as any)[HiddenConvexFunctionNameKey];
package/src/Refs.ts CHANGED
@@ -38,18 +38,31 @@ type OmitEmpty<T> = {
38
38
  [K in keyof T as keyof T[K] extends never ? never : K]: T[K];
39
39
  };
40
40
 
41
+ type FunctionSpecMatchesPredicate<
42
+ FunctionSpec_ extends FunctionSpec.AnyWithProps,
43
+ Predicate extends Ref.Any,
44
+ > =
45
+ Ref.Ref<
46
+ FunctionSpec.GetRuntimeAndFunctionType<FunctionSpec_>,
47
+ FunctionSpec.GetFunctionVisibility<FunctionSpec_>,
48
+ any,
49
+ any
50
+ > extends Predicate
51
+ ? true
52
+ : false;
53
+
41
54
  type FilteredFunctions<
42
- Functions extends FunctionSpec.AnyWithProps,
55
+ FunctionSpecs extends FunctionSpec.AnyWithProps,
43
56
  Predicate extends Ref.Any,
44
57
  > = {
45
- [Name in FunctionSpec.Name<Functions> as FunctionSpec.WithName<
46
- Functions,
58
+ [Name in FunctionSpec.Name<FunctionSpecs> as FunctionSpec.WithName<
59
+ FunctionSpecs,
47
60
  Name
48
- > extends infer F extends FunctionSpec.AnyWithProps
49
- ? Ref.FromFunctionSpec<F> extends Predicate
61
+ > extends infer FunctionSpec_ extends FunctionSpec.AnyWithProps
62
+ ? FunctionSpecMatchesPredicate<FunctionSpec_, Predicate> extends true
50
63
  ? Name
51
64
  : never
52
- : never]: FunctionSpec.WithName<Functions, Name> extends infer F extends
65
+ : never]: FunctionSpec.WithName<FunctionSpecs, Name> extends infer F extends
53
66
  FunctionSpec.AnyWithProps
54
67
  ? Ref.FromFunctionSpec<F>
55
68
  : never;
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * as FunctionProvenance from "./FunctionProvenance";
1
2
  export * as FunctionSpec from "./FunctionSpec";
2
3
  export * as GenericId from "./GenericId";
3
4
  export * as GroupPath from "./GroupPath";