@confect/server 8.0.0 → 9.0.0-next.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.
Files changed (45) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/dist/DatabaseSchema.d.ts +9 -4
  3. package/dist/DatabaseSchema.d.ts.map +1 -1
  4. package/dist/DatabaseSchema.js +4 -3
  5. package/dist/DatabaseSchema.js.map +1 -1
  6. package/dist/FunctionImpl.d.ts +10 -7
  7. package/dist/FunctionImpl.d.ts.map +1 -1
  8. package/dist/FunctionImpl.js +8 -8
  9. package/dist/FunctionImpl.js.map +1 -1
  10. package/dist/GroupImpl.d.ts +51 -12
  11. package/dist/GroupImpl.d.ts.map +1 -1
  12. package/dist/GroupImpl.js +72 -4
  13. package/dist/GroupImpl.js.map +1 -1
  14. package/dist/GroupPath.d.ts +8 -0
  15. package/dist/GroupPath.d.ts.map +1 -0
  16. package/dist/GroupPath.js +10 -0
  17. package/dist/GroupPath.js.map +1 -0
  18. package/dist/RegisteredConvexFunction.d.ts +6 -6
  19. package/dist/RegisteredConvexFunction.d.ts.map +1 -1
  20. package/dist/RegisteredFunction.d.ts +3 -3
  21. package/dist/RegisteredFunction.d.ts.map +1 -1
  22. package/dist/RegisteredFunctions.d.ts +15 -4
  23. package/dist/RegisteredFunctions.d.ts.map +1 -1
  24. package/dist/RegisteredFunctions.js +20 -11
  25. package/dist/RegisteredFunctions.js.map +1 -1
  26. package/dist/StorageActionWriter.d.ts +1 -1
  27. package/dist/index.d.ts +1 -3
  28. package/dist/index.js +1 -3
  29. package/package.json +4 -6
  30. package/src/DatabaseSchema.ts +10 -7
  31. package/src/FunctionImpl.ts +27 -36
  32. package/src/GroupImpl.ts +168 -32
  33. package/src/GroupPath.ts +43 -0
  34. package/src/RegisteredFunctions.ts +78 -28
  35. package/src/index.ts +0 -2
  36. package/dist/Impl.d.ts +0 -24
  37. package/dist/Impl.d.ts.map +0 -1
  38. package/dist/Impl.js +0 -28
  39. package/dist/Impl.js.map +0 -1
  40. package/dist/Registry.d.ts +0 -15
  41. package/dist/Registry.d.ts.map +0 -1
  42. package/dist/Registry.js +0 -10
  43. package/dist/Registry.js.map +0 -1
  44. package/src/Impl.ts +0 -59
  45. package/src/Registry.ts +0 -13
@@ -1,13 +1,22 @@
1
1
  import type * as FunctionSpec from "@confect/core/FunctionSpec";
2
2
  import type * as GroupSpec from "@confect/core/GroupSpec";
3
+ import * as Registry from "@confect/core/Registry";
3
4
  import type * as Spec from "@confect/core/Spec";
4
- import type { Layer } from "effect";
5
- import { Effect, Match, Ref, type Types } from "effect";
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";
6
16
  import type * as Api from "./Api";
7
- import * as Impl from "./Impl";
17
+ import type * as GroupImpl from "./GroupImpl";
8
18
  import { mapLeaves } from "./internal/utils";
9
19
  import type * as RegisteredFunction from "./RegisteredFunction";
10
- import * as Registry from "./Registry";
11
20
  import * as RegistryItem from "./RegistryItem";
12
21
 
13
22
  export type RegisteredFunctions<Spec_ extends Spec.AnyWithProps> =
@@ -49,34 +58,75 @@ export interface AnyWithProps {
49
58
  readonly [key: string]: RegisteredFunction.Any | AnyWithProps;
50
59
  }
51
60
 
52
- export const make = <Api_ extends Api.AnyWithProps>(
53
- impl: Layer.Layer<Impl.Impl<Api_, "Finalized">>,
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
+ /**
80
+ * Build the registered Convex functions for a single group from its finalized
81
+ * `GroupImpl` layer.
82
+ *
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.
87
+ */
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">>,
54
95
  makeRegisteredFunction: (
55
96
  api: Api_,
56
97
  registryItem: RegistryItem.AnyWithProps,
57
98
  ) => RegisteredFunction.Any,
58
- ) =>
59
- Effect.gen(function* () {
99
+ ): ForGroupPath<Api_["spec"], GroupPath_> => {
100
+ const registryItems = Effect.gen(function* () {
60
101
  const registry = yield* Registry.Registry;
61
- const functionImplItems = yield* Ref.get(registry);
62
- const { api, finalizationStatus } = yield* Impl.Impl<Api_, "Finalized">();
102
+ return yield* Ref.get(registry);
103
+ }).pipe(Effect.provide(groupLayer), Effect.runSync);
63
104
 
64
- return yield* Match.value(
65
- finalizationStatus as Impl.FinalizationStatus,
66
- ).pipe(
67
- Match.withReturnType<Effect.Effect<RegisteredFunctions<Api_["spec"]>>>(),
68
- Match.when("Unfinalized", () =>
69
- Effect.dieMessage("Impl is not finalized"),
70
- ),
71
- Match.when("Finalized", () =>
72
- Effect.succeed(
73
- mapLeaves<RegistryItem.AnyWithProps, RegisteredFunction.Any>(
74
- functionImplItems,
75
- RegistryItem.isRegistryItem,
76
- (registryItem) => makeRegisteredFunction(api, registryItem),
77
- ) as RegisteredFunctions<Api_["spec"]>,
105
+ const registeredFunctions = mapLeaves<
106
+ RegistryItem.AnyWithProps,
107
+ RegisteredFunction.Any
108
+ >(
109
+ registryItems as { [key: string]: RegistryItem.AnyWithProps },
110
+ 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
+ ),
78
126
  ),
79
- ),
80
- Match.exhaustive,
81
- );
82
- }).pipe(Effect.provide(impl), Effect.runSync);
127
+ ),
128
+ Option.getOrThrowWith(
129
+ () => new Error(`No functions registered for group path "${groupPath}"`),
130
+ ),
131
+ ) as ForGroupPath<Api_["spec"], GroupPath_>;
132
+ };
package/src/index.ts CHANGED
@@ -15,7 +15,6 @@ export * as FunctionImpl from "./FunctionImpl";
15
15
  export * as GroupImpl from "./GroupImpl";
16
16
  export * as Handler from "./Handler";
17
17
  export * as HttpApi from "./HttpApi";
18
- export * as Impl from "./Impl";
19
18
  export * as MutationCtx from "./MutationCtx";
20
19
  export * as MutationRunner from "./MutationRunner";
21
20
  export * as OrderedQuery from "./OrderedQuery";
@@ -25,7 +24,6 @@ export * as QueryRunner from "./QueryRunner";
25
24
  export * as RegisteredConvexFunction from "./RegisteredConvexFunction";
26
25
  export * as RegisteredFunction from "./RegisteredFunction";
27
26
  export * as RegisteredFunctions from "./RegisteredFunctions";
28
- export * as Registry from "./Registry";
29
27
  export * as RegistryItem from "./RegistryItem";
30
28
  export * as Scheduler from "./Scheduler";
31
29
  export * as SchemaToValidator from "./SchemaToValidator";
package/dist/Impl.d.ts DELETED
@@ -1,24 +0,0 @@
1
- import { AnyWithProps as AnyWithProps$1, Groups } from "./Api.js";
2
- import { FromGroups } from "./GroupImpl.js";
3
- import { Context, Layer } from "effect";
4
-
5
- //#region src/Impl.d.ts
6
- declare namespace Impl_d_exports {
7
- export { AnyWithProps, FinalizationStatus, Impl, TypeId, finalize, isImpl, make };
8
- }
9
- declare const TypeId = "@confect/server/Impl";
10
- type TypeId = typeof TypeId;
11
- declare const isImpl: (u: unknown) => u is AnyWithProps;
12
- interface Impl<Api_ extends AnyWithProps$1, FinalizationStatus_ extends FinalizationStatus> {
13
- readonly [TypeId]: TypeId;
14
- readonly api: Api_;
15
- readonly finalizationStatus: FinalizationStatus_;
16
- }
17
- type FinalizationStatus = "Unfinalized" | "Finalized";
18
- interface AnyWithProps extends Impl<AnyWithProps$1, FinalizationStatus> {}
19
- declare const Impl: <Api_ extends AnyWithProps$1, FinalizationStatus_ extends FinalizationStatus>() => Context.Tag<Impl<Api_, FinalizationStatus_>, Impl<Api_, FinalizationStatus_>>;
20
- declare const make: <Api_ extends AnyWithProps$1>(api: Api_) => Layer.Layer<Impl<Api_, "Unfinalized">, never, FromGroups<Groups<Api_>>>;
21
- declare const finalize: <Api_ extends AnyWithProps$1>(impl: Layer.Layer<Impl<Api_, "Unfinalized">>) => Layer.Layer<Impl<Api_, "Finalized">>;
22
- //#endregion
23
- export { AnyWithProps, FinalizationStatus, Impl, Impl_d_exports, TypeId, finalize, isImpl, make };
24
- //# sourceMappingURL=Impl.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Impl.d.ts","names":[],"sources":["../src/Impl.ts"],"mappings":";;;;;;;;cAKa,MAAA;AAAA,KACD,MAAA,UAAgB,MAAA;AAAA,cAEf,MAAA,GAAU,CAAA,cAAa,CAAA,IAAK,YAAA;AAAA,UAGxB,IAAA,cACF,cAAA,8BACe,kBAAA;EAAA,UAElB,MAAA,GAAS,MAAA;EAAA,SACV,GAAA,EAAK,IAAA;EAAA,SACL,kBAAA,EAAoB,mBAAA;AAAA;AAAA,KAGnB,kBAAA;AAAA,UAEK,YAAA,SAAqB,IAAA,CACpC,cAAA,EACA,kBAAA;AAAA,cAGW,IAAA,gBACE,cAAA,8BACe,kBAAA,OAAkB,OAAA,CAAA,GAAA,CAAA,IAAA,CAAA,IAAA,EAAA,mBAAA,GAAA,IAAA,CAAA,IAAA,EAAA,mBAAA;AAAA,cAInC,IAAA,gBAAqB,cAAA,EAChC,GAAA,EAAK,IAAA,KACJ,KAAA,CAAM,KAAA,CACP,IAAA,CAAK,IAAA,yBAEL,UAAA,CAAqB,MAAA,CAAU,IAAA;AAAA,cAWpB,QAAA,gBAAyB,cAAA,EACpC,IAAA,EAAM,KAAA,CAAM,KAAA,CAAM,IAAA,CAAK,IAAA,sBACtB,KAAA,CAAM,KAAA,CAAM,IAAA,CAAK,IAAA"}
package/dist/Impl.js DELETED
@@ -1,28 +0,0 @@
1
- import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
- import { Context, Effect, Layer, Predicate } from "effect";
3
-
4
- //#region src/Impl.ts
5
- var Impl_exports = /* @__PURE__ */ __exportAll({
6
- Impl: () => Impl,
7
- TypeId: () => TypeId,
8
- finalize: () => finalize,
9
- isImpl: () => isImpl,
10
- make: () => make
11
- });
12
- const TypeId = "@confect/server/Impl";
13
- const isImpl = (u) => Predicate.hasProperty(u, TypeId);
14
- const Impl = () => Context.GenericTag(`@confect/server/Impl`);
15
- const make = (api) => Layer.effect(Impl(), Effect.succeed({
16
- [TypeId]: TypeId,
17
- api,
18
- finalizationStatus: "Unfinalized"
19
- }));
20
- const finalize = (impl) => Layer.map(impl, (context) => Context.make(Impl(), {
21
- [TypeId]: TypeId,
22
- api: Context.get(context, Impl()).api,
23
- finalizationStatus: "Finalized"
24
- }));
25
-
26
- //#endregion
27
- export { Impl, Impl_exports, TypeId, finalize, isImpl, make };
28
- //# sourceMappingURL=Impl.js.map
package/dist/Impl.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"Impl.js","names":[],"sources":["../src/Impl.ts"],"sourcesContent":["import { Context, Effect, Layer, Predicate } from \"effect\";\nimport type * as Api from \"./Api\";\nimport type { Groups as ApiGroups } from \"./Api\";\nimport type * as GroupImpl from \"./GroupImpl\";\n\nexport const TypeId = \"@confect/server/Impl\";\nexport type TypeId = typeof TypeId;\n\nexport const isImpl = (u: unknown): u is AnyWithProps =>\n Predicate.hasProperty(u, TypeId);\n\nexport interface Impl<\n Api_ extends Api.AnyWithProps,\n FinalizationStatus_ extends FinalizationStatus,\n> {\n readonly [TypeId]: TypeId;\n readonly api: Api_;\n readonly finalizationStatus: FinalizationStatus_;\n}\n\nexport type FinalizationStatus = \"Unfinalized\" | \"Finalized\";\n\nexport interface AnyWithProps extends Impl<\n Api.AnyWithProps,\n FinalizationStatus\n> {}\n\nexport const Impl = <\n Api_ extends Api.AnyWithProps,\n FinalizationStatus_ extends FinalizationStatus,\n>() =>\n Context.GenericTag<Impl<Api_, FinalizationStatus_>>(`@confect/server/Impl`);\n\nexport const make = <Api_ extends Api.AnyWithProps>(\n api: Api_,\n): Layer.Layer<\n Impl<Api_, \"Unfinalized\">,\n never,\n GroupImpl.FromGroups<ApiGroups<Api_>>\n> =>\n Layer.effect(\n Impl<Api_, \"Unfinalized\">(),\n Effect.succeed({\n [TypeId]: TypeId,\n api,\n finalizationStatus: \"Unfinalized\" as const,\n }),\n );\n\nexport const finalize = <Api_ extends Api.AnyWithProps>(\n impl: Layer.Layer<Impl<Api_, \"Unfinalized\">>,\n): Layer.Layer<Impl<Api_, \"Finalized\">> =>\n Layer.map(impl, (context) =>\n Context.make(Impl<Api_, \"Finalized\">(), {\n [TypeId]: TypeId,\n api: Context.get(context, Impl<Api_, \"Unfinalized\">()).api,\n finalizationStatus: \"Finalized\",\n }),\n );\n"],"mappings":";;;;;;;;;;;AAKA,MAAa,SAAS;AAGtB,MAAa,UAAU,MACrB,UAAU,YAAY,GAAG,OAAO;AAkBlC,MAAa,aAIX,QAAQ,WAA4C,uBAAuB;AAE7E,MAAa,QACX,QAMA,MAAM,OACJ,MAA2B,EAC3B,OAAO,QAAQ;EACZ,SAAS;CACV;CACA,oBAAoB;CACrB,CAAC,CACH;AAEH,MAAa,YACX,SAEA,MAAM,IAAI,OAAO,YACf,QAAQ,KAAK,MAAyB,EAAE;EACrC,SAAS;CACV,KAAK,QAAQ,IAAI,SAAS,MAA2B,CAAC,CAAC;CACvD,oBAAoB;CACrB,CAAC,CACH"}
@@ -1,15 +0,0 @@
1
- import { AnyWithProps } from "./RegistryItem.js";
2
- import { Context, Ref } from "effect";
3
-
4
- //#region src/Registry.d.ts
5
- declare namespace Registry_d_exports {
6
- export { Registry, RegistryItems };
7
- }
8
- interface RegistryItems {
9
- readonly [key: string]: AnyWithProps | RegistryItems;
10
- }
11
- declare const Registry_base: Context.ReferenceClass<Registry, "@confect/server/Registry", Ref.Ref<RegistryItems>>;
12
- declare class Registry extends Registry_base {}
13
- //#endregion
14
- export { Registry, RegistryItems, Registry_d_exports };
15
- //# sourceMappingURL=Registry.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Registry.d.ts","names":[],"sources":["../src/Registry.ts"],"mappings":";;;;;;;UAGiB,aAAA;EAAA,UACL,GAAA,WAAc,YAAA,GAA4B,aAAA;AAAA;AAAA,cACrD,aAAA;cAEY,QAAA,SAAiB,aAAA"}
package/dist/Registry.js DELETED
@@ -1,10 +0,0 @@
1
- import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
- import { Context, Ref } from "effect";
3
-
4
- //#region src/Registry.ts
5
- var Registry_exports = /* @__PURE__ */ __exportAll({ Registry: () => Registry });
6
- var Registry = class extends Context.Reference()("@confect/server/Registry", { defaultValue: () => Ref.unsafeMake({}) }) {};
7
-
8
- //#endregion
9
- export { Registry, Registry_exports };
10
- //# sourceMappingURL=Registry.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Registry.js","names":[],"sources":["../src/Registry.ts"],"sourcesContent":["import { Context, Ref } from \"effect\";\nimport type * as RegistryItem from \"./RegistryItem\";\n\nexport interface RegistryItems {\n readonly [key: string]: RegistryItem.AnyWithProps | RegistryItems;\n}\n\nexport class Registry extends Context.Reference<Registry>()(\n \"@confect/server/Registry\",\n {\n defaultValue: () => Ref.unsafeMake<RegistryItems>({}),\n },\n) {}\n"],"mappings":";;;;;AAOA,IAAa,WAAb,cAA8B,QAAQ,WAAqB,CACzD,4BACA,EACE,oBAAoB,IAAI,WAA0B,EAAE,CAAC,EACtD,CACF,CAAC"}
package/src/Impl.ts DELETED
@@ -1,59 +0,0 @@
1
- import { Context, Effect, Layer, Predicate } from "effect";
2
- import type * as Api from "./Api";
3
- import type { Groups as ApiGroups } from "./Api";
4
- import type * as GroupImpl from "./GroupImpl";
5
-
6
- export const TypeId = "@confect/server/Impl";
7
- export type TypeId = typeof TypeId;
8
-
9
- export const isImpl = (u: unknown): u is AnyWithProps =>
10
- Predicate.hasProperty(u, TypeId);
11
-
12
- export interface Impl<
13
- Api_ extends Api.AnyWithProps,
14
- FinalizationStatus_ extends FinalizationStatus,
15
- > {
16
- readonly [TypeId]: TypeId;
17
- readonly api: Api_;
18
- readonly finalizationStatus: FinalizationStatus_;
19
- }
20
-
21
- export type FinalizationStatus = "Unfinalized" | "Finalized";
22
-
23
- export interface AnyWithProps extends Impl<
24
- Api.AnyWithProps,
25
- FinalizationStatus
26
- > {}
27
-
28
- export const Impl = <
29
- Api_ extends Api.AnyWithProps,
30
- FinalizationStatus_ extends FinalizationStatus,
31
- >() =>
32
- Context.GenericTag<Impl<Api_, FinalizationStatus_>>(`@confect/server/Impl`);
33
-
34
- export const make = <Api_ extends Api.AnyWithProps>(
35
- api: Api_,
36
- ): Layer.Layer<
37
- Impl<Api_, "Unfinalized">,
38
- never,
39
- GroupImpl.FromGroups<ApiGroups<Api_>>
40
- > =>
41
- Layer.effect(
42
- Impl<Api_, "Unfinalized">(),
43
- Effect.succeed({
44
- [TypeId]: TypeId,
45
- api,
46
- finalizationStatus: "Unfinalized" as const,
47
- }),
48
- );
49
-
50
- export const finalize = <Api_ extends Api.AnyWithProps>(
51
- impl: Layer.Layer<Impl<Api_, "Unfinalized">>,
52
- ): Layer.Layer<Impl<Api_, "Finalized">> =>
53
- Layer.map(impl, (context) =>
54
- Context.make(Impl<Api_, "Finalized">(), {
55
- [TypeId]: TypeId,
56
- api: Context.get(context, Impl<Api_, "Unfinalized">()).api,
57
- finalizationStatus: "Finalized",
58
- }),
59
- );
package/src/Registry.ts DELETED
@@ -1,13 +0,0 @@
1
- import { Context, Ref } from "effect";
2
- import type * as RegistryItem from "./RegistryItem";
3
-
4
- export interface RegistryItems {
5
- readonly [key: string]: RegistryItem.AnyWithProps | RegistryItems;
6
- }
7
-
8
- export class Registry extends Context.Reference<Registry>()(
9
- "@confect/server/Registry",
10
- {
11
- defaultValue: () => Ref.unsafeMake<RegistryItems>({}),
12
- },
13
- ) {}