@confect/server 9.0.0-next.5 → 9.0.0-next.7

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.
Files changed (62) hide show
  1. package/CHANGELOG.md +163 -0
  2. package/dist/Auth.d.ts +1 -1
  3. package/dist/DatabaseReader.d.ts +4299 -26
  4. package/dist/DatabaseReader.d.ts.map +1 -1
  5. package/dist/DatabaseReader.js +5 -6
  6. package/dist/DatabaseReader.js.map +1 -1
  7. package/dist/DatabaseSchema.d.ts +25 -112
  8. package/dist/DatabaseSchema.d.ts.map +1 -1
  9. package/dist/DatabaseSchema.js +20 -30
  10. package/dist/DatabaseSchema.js.map +1 -1
  11. package/dist/DatabaseWriter.d.ts +4 -4
  12. package/dist/DatabaseWriter.d.ts.map +1 -1
  13. package/dist/DatabaseWriter.js +3 -4
  14. package/dist/DatabaseWriter.js.map +1 -1
  15. package/dist/FunctionImpl.d.ts +26 -17
  16. package/dist/FunctionImpl.d.ts.map +1 -1
  17. package/dist/FunctionImpl.js +22 -14
  18. package/dist/FunctionImpl.js.map +1 -1
  19. package/dist/GroupImpl.d.ts +22 -13
  20. package/dist/GroupImpl.d.ts.map +1 -1
  21. package/dist/GroupImpl.js +34 -35
  22. package/dist/GroupImpl.js.map +1 -1
  23. package/dist/Handler.d.ts +1 -1
  24. package/dist/QueryInitializer.d.ts.map +1 -1
  25. package/dist/QueryInitializer.js.map +1 -1
  26. package/dist/RegisteredConvexFunction.d.ts +1081 -14
  27. package/dist/RegisteredConvexFunction.d.ts.map +1 -1
  28. package/dist/RegisteredConvexFunction.js +4 -4
  29. package/dist/RegisteredConvexFunction.js.map +1 -1
  30. package/dist/RegisteredFunction.d.ts +3 -3
  31. package/dist/RegisteredFunction.d.ts.map +1 -1
  32. package/dist/RegisteredFunctions.d.ts +36 -12
  33. package/dist/RegisteredFunctions.d.ts.map +1 -1
  34. package/dist/RegisteredFunctions.js +21 -9
  35. package/dist/RegisteredFunctions.js.map +1 -1
  36. package/dist/RegisteredNodeFunction.d.ts +4 -4
  37. package/dist/RegisteredNodeFunction.d.ts.map +1 -1
  38. package/dist/RegisteredNodeFunction.js +2 -2
  39. package/dist/RegisteredNodeFunction.js.map +1 -1
  40. package/dist/Table.d.ts +39 -31
  41. package/dist/Table.d.ts.map +1 -1
  42. package/dist/Table.js +69 -60
  43. package/dist/Table.js.map +1 -1
  44. package/dist/index.d.ts +4 -5
  45. package/dist/index.js +4 -5
  46. package/package.json +51 -52
  47. package/src/DatabaseReader.ts +17 -21
  48. package/src/DatabaseSchema.ts +38 -98
  49. package/src/DatabaseWriter.ts +8 -5
  50. package/src/FunctionImpl.ts +33 -43
  51. package/src/GroupImpl.ts +45 -69
  52. package/src/QueryInitializer.ts +10 -2
  53. package/src/RegisteredConvexFunction.ts +5 -6
  54. package/src/RegisteredFunctions.ts +67 -93
  55. package/src/RegisteredNodeFunction.ts +3 -4
  56. package/src/Table.ts +251 -131
  57. package/src/index.ts +0 -1
  58. package/dist/Api.d.ts +0 -43
  59. package/dist/Api.d.ts.map +0 -1
  60. package/dist/Api.js +0 -43
  61. package/dist/Api.js.map +0 -1
  62. package/src/Api.ts +0 -102
@@ -2,18 +2,8 @@ import type * as FunctionSpec from "@confect/core/FunctionSpec";
2
2
  import type * as GroupSpec from "@confect/core/GroupSpec";
3
3
  import * as Registry from "@confect/core/Registry";
4
4
  import type * as Spec from "@confect/core/Spec";
5
- import {
6
- Array,
7
- Effect,
8
- type Layer,
9
- Option,
10
- pipe,
11
- Predicate,
12
- Ref,
13
- String,
14
- type Types,
15
- } from "effect";
16
- import type * as Api from "./Api";
5
+ import { Effect, type Layer, Ref, type Types } from "effect";
6
+ import type * as DatabaseSchema from "./DatabaseSchema";
17
7
  import type * as GroupImpl from "./GroupImpl";
18
8
  import { mapLeaves } from "./internal/utils";
19
9
  import type * as RegisteredFunction from "./RegisteredFunction";
@@ -27,106 +17,90 @@ type RegisteredFunctionsHelper<Groups extends GroupSpec.AnyWithProps> = {
27
17
  Groups,
28
18
  GroupName
29
19
  > extends infer Group extends GroupSpec.AnyWithProps
30
- ? GroupSpec.Groups<Group> extends infer SubGroups extends
31
- GroupSpec.AnyWithProps
32
- ? Types.Simplify<
33
- RegisteredFunctionsHelper<SubGroups> & {
34
- [FunctionName in FunctionSpec.Name<
35
- GroupSpec.Functions<Group>
36
- >]: FunctionSpec.WithName<
37
- GroupSpec.Functions<Group>,
38
- FunctionName
39
- > extends infer FunctionSpec_ extends FunctionSpec.AnyWithProps
40
- ? RegisteredFunction.RegisteredFunction<FunctionSpec_>
41
- : never;
42
- }
43
- >
44
- : {
45
- [FunctionName in FunctionSpec.Name<
46
- GroupSpec.Functions<Group>
47
- >]: FunctionSpec.WithName<
48
- GroupSpec.Functions<Group>,
49
- FunctionName
50
- > extends infer FunctionSpec_ extends FunctionSpec.AnyWithProps
51
- ? RegisteredFunction.RegisteredFunction<FunctionSpec_>
52
- : never;
53
- }
20
+ ? RegisteredFunctionsForGroupSpec<Group>
54
21
  : never;
55
22
  };
56
23
 
24
+ /** The `RegisteredFunction` record for a group's own declared functions. */
25
+ type RegisteredFunctionsOf<Group extends GroupSpec.AnyWithProps> = {
26
+ [FunctionName in FunctionSpec.Name<
27
+ GroupSpec.Functions<Group>
28
+ >]: FunctionSpec.WithName<
29
+ GroupSpec.Functions<Group>,
30
+ FunctionName
31
+ > extends infer FunctionSpec_ extends FunctionSpec.AnyWithProps
32
+ ? RegisteredFunction.RegisteredFunction<FunctionSpec_>
33
+ : never;
34
+ };
35
+
36
+ /**
37
+ * The registered-functions record for a single group, derived from the group's
38
+ * own `GroupSpec`: its declared functions, plus any nested subgroups it carries
39
+ * directly. This is the node that `buildForGroup` returns — computed from the
40
+ * leaf `GroupSpec` itself rather than by navigating the project-wide assembled
41
+ * `Spec` to a dot-path, so the per-group registry's type depends only on its
42
+ * own leaf. For the filesystem layout a leaf `GroupSpec` carries no subgroups
43
+ * (subdirectory children are assembled separately into `_generated/spec.ts`),
44
+ * so this resolves to just the leaf's functions.
45
+ */
46
+ export type RegisteredFunctionsForGroupSpec<
47
+ Group extends GroupSpec.AnyWithProps,
48
+ > =
49
+ GroupSpec.Groups<Group> extends infer SubGroups extends GroupSpec.AnyWithProps
50
+ ? Types.Simplify<
51
+ RegisteredFunctionsHelper<SubGroups> & RegisteredFunctionsOf<Group>
52
+ >
53
+ : RegisteredFunctionsOf<Group>;
54
+
57
55
  export interface AnyWithProps {
58
56
  readonly [key: string]: RegisteredFunction.Any | AnyWithProps;
59
57
  }
60
58
 
61
- type RegisteredFunctionsAtPath<
62
- Tree,
63
- Path extends string,
64
- > = Path extends `${infer Head}.${infer Tail}`
65
- ? Head extends keyof Tree
66
- ? Tree[Head] extends AnyWithProps
67
- ? RegisteredFunctionsAtPath<Tree[Head], Tail>
68
- : never
69
- : never
70
- : Path extends keyof Tree
71
- ? Tree[Path]
72
- : never;
73
-
74
- export type ForGroupPath<
75
- Spec_ extends Spec.AnyWithProps,
76
- Path extends string,
77
- > = RegisteredFunctionsAtPath<RegisteredFunctions<Spec_>, Path>;
78
-
79
59
  /**
80
60
  * Build the registered Convex functions for a single group from its finalized
81
61
  * `GroupImpl` layer.
82
62
  *
83
- * The `groupLayer` parameter requires `GroupImpl<string, "Finalized">`, so
84
- * impls that were never piped through `GroupImpl.finalize` (and impls with
85
- * unmet `FunctionImpl` requirements, which cannot be finalized) are rejected
86
- * at the codegen boundary, not just deep inside Convex at runtime.
63
+ * The `groupLayer` parameter requires `GroupImpl<"Finalized">`, so impls that
64
+ * were never piped through `GroupImpl.finalize` (and impls with unmet
65
+ * `FunctionImpl` requirements, which cannot be finalized) are rejected at the
66
+ * codegen boundary, not just deep inside Convex at runtime.
67
+ *
68
+ * The group layer is built with a fresh, isolated `Registry` (rather than the
69
+ * globally-cached default `Context.Reference`), so each `FunctionImpl.make`
70
+ * registers under its flat, single-segment function-name key without colliding
71
+ * with any other group built in the same process — the built registry holds
72
+ * exactly this group's functions at the top level.
73
+ *
74
+ * Only the runtime `databaseSchema` value is needed at runtime (it is forwarded
75
+ * to `makeRegisteredFunction` to build each function's ctx services); the
76
+ * group's `GroupSpec` is supplied purely as the `Group` type parameter to shape
77
+ * the returned record. The generated caller passes it explicitly and imports
78
+ * the leaf spec type-only (`typeof import("…/<group>.spec")["default"]`), so a
79
+ * function's bundle never imports a spec module at runtime.
87
80
  */
88
- export const buildForGroup = <
89
- Api_ extends Api.AnyWithProps,
90
- const GroupPath_ extends string,
91
- >(
92
- api: Api_,
93
- groupPath: GroupPath_,
94
- groupLayer: Layer.Layer<GroupImpl.GroupImpl<string, "Finalized">>,
81
+ export const buildForGroup = <Group extends GroupSpec.AnyWithProps>(
82
+ databaseSchema: DatabaseSchema.AnyWithProps,
83
+ groupLayer: Layer.Layer<GroupImpl.GroupImpl<"Finalized">>,
95
84
  makeRegisteredFunction: (
96
- api: Api_,
85
+ databaseSchema: DatabaseSchema.AnyWithProps,
97
86
  registryItem: RegistryItem.AnyWithProps,
98
87
  ) => RegisteredFunction.Any,
99
- ): ForGroupPath<Api_["spec"], GroupPath_> => {
88
+ ): RegisteredFunctionsForGroupSpec<Group> => {
100
89
  const registryItems = Effect.gen(function* () {
101
90
  const registry = yield* Registry.Registry;
102
91
  return yield* Ref.get(registry);
103
- }).pipe(Effect.provide(groupLayer), Effect.runSync);
92
+ }).pipe(
93
+ Effect.provide(groupLayer),
94
+ Effect.provideService(
95
+ Registry.Registry,
96
+ Ref.unsafeMake<Registry.RegistryItems>({}),
97
+ ),
98
+ Effect.runSync,
99
+ );
104
100
 
105
- const registeredFunctions = mapLeaves<
106
- RegistryItem.AnyWithProps,
107
- RegisteredFunction.Any
108
- >(
101
+ return mapLeaves<RegistryItem.AnyWithProps, RegisteredFunction.Any>(
109
102
  registryItems as { [key: string]: RegistryItem.AnyWithProps },
110
103
  RegistryItem.isRegistryItem,
111
- (registryItem) => makeRegisteredFunction(api, registryItem),
112
- );
113
-
114
- return pipe(
115
- String.split(groupPath, "."),
116
- Array.reduce(
117
- Option.some<unknown>(registeredFunctions),
118
- (currentNode, segment) =>
119
- currentNode.pipe(
120
- Option.filter(Predicate.isRecord),
121
- Option.flatMap((nodeRecord) =>
122
- segment in nodeRecord
123
- ? Option.some(nodeRecord[segment])
124
- : Option.none(),
125
- ),
126
- ),
127
- ),
128
- Option.getOrThrowWith(
129
- () => new Error(`No functions registered for group path "${groupPath}"`),
130
- ),
131
- ) as ForGroupPath<Api_["spec"], GroupPath_>;
104
+ (registryItem) => makeRegisteredFunction(databaseSchema, registryItem),
105
+ ) as RegisteredFunctionsForGroupSpec<Group>;
132
106
  };
@@ -7,14 +7,13 @@ import {
7
7
  } from "convex/server";
8
8
  import type { Effect } from "effect";
9
9
  import { Layer, Match, type Schema } from "effect";
10
- import type * as Api from "./Api";
11
10
  import type * as DatabaseSchema from "./DatabaseSchema";
12
11
  import type * as Handler from "./Handler";
13
12
  import * as RegisteredFunction from "./RegisteredFunction";
14
13
  import type * as RegistryItem from "./RegistryItem";
15
14
 
16
- export const make = <Api_ extends Api.AnyWithPropsWithRuntime<"Node">>(
17
- api: Api_,
15
+ export const make = (
16
+ databaseSchema: DatabaseSchema.AnyWithProps,
18
17
  { functionSpec, handler }: RegistryItem.AnyWithProps,
19
18
  ): RegisteredFunction.Any =>
20
19
  Match.value(functionSpec.functionProvenance).pipe(
@@ -30,7 +29,7 @@ export const make = <Api_ extends Api.AnyWithPropsWithRuntime<"Node">>(
30
29
  );
31
30
 
32
31
  return genericFunction(
33
- nodeActionFunction(api.databaseSchema, {
32
+ nodeActionFunction(databaseSchema, {
34
33
  args: functionProvenance.args,
35
34
  returns: functionProvenance.returns,
36
35
  error: functionProvenance.error,