@confect/core 10.0.0-next.8 → 10.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.
Files changed (103) hide show
  1. package/CHANGELOG.md +966 -46
  2. package/README.md +3 -1
  3. package/dist/FunctionProvenance.d.ts +166 -68
  4. package/dist/FunctionProvenance.d.ts.map +1 -1
  5. package/dist/FunctionProvenance.js +55 -13
  6. package/dist/FunctionProvenance.js.map +1 -1
  7. package/dist/FunctionSpec.d.ts +320 -138
  8. package/dist/FunctionSpec.d.ts.map +1 -1
  9. package/dist/FunctionSpec.js +56 -13
  10. package/dist/FunctionSpec.js.map +1 -1
  11. package/dist/GenericId.d.ts.map +1 -1
  12. package/dist/GenericId.js +1 -1
  13. package/dist/GroupPath.d.ts +6 -10
  14. package/dist/GroupPath.d.ts.map +1 -1
  15. package/dist/GroupPath.js.map +1 -1
  16. package/dist/GroupSpec.d.ts +25 -12
  17. package/dist/GroupSpec.d.ts.map +1 -1
  18. package/dist/GroupSpec.js +51 -14
  19. package/dist/GroupSpec.js.map +1 -1
  20. package/dist/Identifier.d.ts +6 -5
  21. package/dist/Identifier.d.ts.map +1 -1
  22. package/dist/Identifier.js +6 -5
  23. package/dist/Identifier.js.map +1 -1
  24. package/dist/Lazy.d.ts +11 -14
  25. package/dist/Lazy.d.ts.map +1 -1
  26. package/dist/Lazy.js +11 -14
  27. package/dist/Lazy.js.map +1 -1
  28. package/dist/MiddlewareAttachment.d.ts +171 -0
  29. package/dist/MiddlewareAttachment.d.ts.map +1 -0
  30. package/dist/MiddlewareAttachment.js +48 -0
  31. package/dist/MiddlewareAttachment.js.map +1 -0
  32. package/dist/MiddlewareSpec.d.ts +198 -0
  33. package/dist/MiddlewareSpec.d.ts.map +1 -0
  34. package/dist/MiddlewareSpec.js +60 -0
  35. package/dist/MiddlewareSpec.js.map +1 -0
  36. package/dist/PaginationError.d.ts +20 -0
  37. package/dist/PaginationError.d.ts.map +1 -0
  38. package/dist/PaginationError.js +31 -0
  39. package/dist/PaginationError.js.map +1 -0
  40. package/dist/PaginationOptions.d.ts +23 -0
  41. package/dist/PaginationOptions.d.ts.map +1 -0
  42. package/dist/PaginationOptions.js +29 -0
  43. package/dist/PaginationOptions.js.map +1 -0
  44. package/dist/PaginationResult.d.ts +1 -0
  45. package/dist/PaginationResult.d.ts.map +1 -1
  46. package/dist/PaginationResult.js.map +1 -1
  47. package/dist/Ref.d.ts +135 -47
  48. package/dist/Ref.d.ts.map +1 -1
  49. package/dist/Ref.js +104 -46
  50. package/dist/Ref.js.map +1 -1
  51. package/dist/Refs.d.ts +10 -5
  52. package/dist/Refs.d.ts.map +1 -1
  53. package/dist/Refs.js +5 -4
  54. package/dist/Refs.js.map +1 -1
  55. package/dist/SchemaToValidator.d.ts +99 -0
  56. package/dist/SchemaToValidator.d.ts.map +1 -0
  57. package/dist/SchemaToValidator.js +158 -0
  58. package/dist/SchemaToValidator.js.map +1 -0
  59. package/dist/Spec.d.ts +16 -12
  60. package/dist/Spec.d.ts.map +1 -1
  61. package/dist/Spec.js +14 -9
  62. package/dist/Spec.js.map +1 -1
  63. package/dist/SystemFields.d.ts +16 -15
  64. package/dist/SystemFields.d.ts.map +1 -1
  65. package/dist/SystemFields.js +16 -15
  66. package/dist/SystemFields.js.map +1 -1
  67. package/dist/Table.d.ts +75 -0
  68. package/dist/Table.d.ts.map +1 -0
  69. package/dist/Table.js +77 -0
  70. package/dist/Table.js.map +1 -0
  71. package/dist/Types.d.ts +8 -2
  72. package/dist/Types.d.ts.map +1 -1
  73. package/dist/Types.js.map +1 -1
  74. package/dist/UserIdentity.d.ts.map +1 -1
  75. package/dist/index.d.ts +6 -1
  76. package/dist/index.d.ts.map +1 -1
  77. package/dist/index.js +9 -4
  78. package/package.json +17 -15
  79. package/src/FunctionProvenance.ts +197 -34
  80. package/src/FunctionSpec.ts +332 -86
  81. package/src/GroupPath.ts +6 -12
  82. package/src/GroupSpec.ts +184 -25
  83. package/src/Identifier.ts +6 -5
  84. package/src/Lazy.ts +11 -14
  85. package/src/MiddlewareAttachment.ts +106 -0
  86. package/src/MiddlewareSpec.ts +392 -0
  87. package/src/PaginationError.ts +78 -0
  88. package/src/PaginationOptions.ts +23 -0
  89. package/src/PaginationResult.ts +4 -0
  90. package/src/Ref.ts +468 -236
  91. package/src/Refs.ts +43 -18
  92. package/src/SchemaToValidator.ts +612 -0
  93. package/src/Spec.ts +50 -39
  94. package/src/SystemFields.ts +32 -36
  95. package/src/Table.ts +427 -0
  96. package/src/Types.ts +9 -3
  97. package/src/index.ts +6 -1
  98. package/dist/Registry.d.ts +0 -24
  99. package/dist/Registry.d.ts.map +0 -1
  100. package/dist/Registry.js +0 -19
  101. package/dist/Registry.js.map +0 -1
  102. package/dist/tsconfig.src.tsbuildinfo +0 -1
  103. package/src/Registry.ts +0 -30
@@ -1,5 +1,5 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
- import { Confect, Convex } from "./FunctionProvenance.js";
2
+ import { Confect, ConfectPaginated, Convex } from "./FunctionProvenance.js";
3
3
  import { validateConfectFunctionIdentifier } from "./Identifier.js";
4
4
  import { ConvexAction, ConvexMutation, ConvexQuery, NodeAction } from "./RuntimeAndFunctionType.js";
5
5
  import * as Predicate from "effect/Predicate";
@@ -17,27 +17,69 @@ var FunctionSpec_exports = /* @__PURE__ */ __exportAll({
17
17
  internalAction: () => internalAction,
18
18
  internalMutation: () => internalMutation,
19
19
  internalNodeAction: () => internalNodeAction,
20
+ internalPaginatedQuery: () => internalPaginatedQuery,
20
21
  internalQuery: () => internalQuery,
21
22
  isFunctionSpec: () => isFunctionSpec,
22
23
  publicAction: () => publicAction,
23
24
  publicMutation: () => publicMutation,
24
25
  publicNodeAction: () => publicNodeAction,
26
+ publicPaginatedQuery: () => publicPaginatedQuery,
25
27
  publicQuery: () => publicQuery
26
28
  });
27
- const TypeId = "@confect/core/FunctionSpec";
29
+ const TypeId = "~@confect/core/FunctionSpec";
28
30
  const isFunctionSpec = (u) => Predicate.hasProperty(u, TypeId);
29
- const Proto = { [TypeId]: TypeId };
30
- const make = (runtimeAndFunctionType, functionVisibility) => ({ name, args, returns, error }) => {
31
- validateConfectFunctionIdentifier(name);
32
- return Object.assign(Object.create(Proto), {
33
- runtimeAndFunctionType,
34
- functionVisibility,
35
- name,
36
- functionProvenance: Confect(args, returns, error)
37
- });
31
+ const Proto = {
32
+ [TypeId]: TypeId,
33
+ get middlewareSpecs() {
34
+ return this.middlewareAttachments.map(({ spec }) => spec);
35
+ },
36
+ middleware(middlewareSpec, ...options) {
37
+ if (this.functionProvenance._tag === "Convex") throw new Error(`Plain Convex function "${this.name}" cannot have middleware`);
38
+ const functionType = this.runtimeAndFunctionType.functionType;
39
+ if (!middlewareSpec.functionTypes[functionType]) throw new Error(`Middleware "${middlewareSpec.key}" does not declare function type "${functionType}" of function "${this.name}"`);
40
+ if (!("options" in middlewareSpec) && this.middlewareAttachments.some(({ spec }) => spec.key === middlewareSpec.key)) throw new Error(`Middleware "${middlewareSpec.key}" is already attached to function "${this.name}"`);
41
+ return Object.assign(Object.create(Proto), {
42
+ runtimeAndFunctionType: this.runtimeAndFunctionType,
43
+ functionVisibility: this.functionVisibility,
44
+ name: this.name,
45
+ functionProvenance: this.functionProvenance,
46
+ middlewareAttachments: [...this.middlewareAttachments, {
47
+ spec: middlewareSpec,
48
+ options: options[0]
49
+ }]
50
+ });
51
+ }
52
+ };
53
+ const make = (runtimeAndFunctionType, functionVisibility) => {
54
+ function makeSpec({ name, args, returns, error }) {
55
+ validateConfectFunctionIdentifier(name);
56
+ return Object.assign(Object.create(Proto), {
57
+ runtimeAndFunctionType,
58
+ functionVisibility,
59
+ name,
60
+ functionProvenance: args === void 0 ? Confect(() => ({}), returns, error) : Confect(args, returns, error),
61
+ middlewareAttachments: []
62
+ });
63
+ }
64
+ return makeSpec;
65
+ };
66
+ const makePaginated = (runtimeAndFunctionType, functionVisibility) => {
67
+ function makeSpec({ name, args, item, error }) {
68
+ validateConfectFunctionIdentifier(name);
69
+ return Object.assign(Object.create(Proto), {
70
+ runtimeAndFunctionType,
71
+ functionVisibility,
72
+ name,
73
+ functionProvenance: args === void 0 ? ConfectPaginated(() => ({}), item, error) : ConfectPaginated(args, item, error),
74
+ middlewareAttachments: []
75
+ });
76
+ }
77
+ return makeSpec;
38
78
  };
39
79
  const publicQuery = make(ConvexQuery, "public");
40
80
  const internalQuery = make(ConvexQuery, "internal");
81
+ const publicPaginatedQuery = makePaginated(ConvexQuery, "public");
82
+ const internalPaginatedQuery = makePaginated(ConvexQuery, "internal");
41
83
  const publicMutation = make(ConvexMutation, "public");
42
84
  const internalMutation = make(ConvexMutation, "internal");
43
85
  const publicAction = make(ConvexAction, "public");
@@ -50,7 +92,8 @@ const makeConvex = (runtimeAndFunctionType, functionVisibility) => () => (name)
50
92
  runtimeAndFunctionType,
51
93
  functionVisibility,
52
94
  name,
53
- functionProvenance: Convex()
95
+ functionProvenance: Convex(),
96
+ middlewareAttachments: []
54
97
  });
55
98
  };
56
99
  const convexPublicQuery = makeConvex(ConvexQuery, "public");
@@ -62,6 +105,6 @@ const convexInternalAction = makeConvex(ConvexAction, "internal");
62
105
  const convexPublicNodeAction = makeConvex(NodeAction, "public");
63
106
  const convexInternalNodeAction = makeConvex(NodeAction, "internal");
64
107
  //#endregion
65
- export { FunctionSpec_exports, TypeId, convexInternalAction, convexInternalMutation, convexInternalNodeAction, convexInternalQuery, convexPublicAction, convexPublicMutation, convexPublicNodeAction, convexPublicQuery, internalAction, internalMutation, internalNodeAction, internalQuery, isFunctionSpec, publicAction, publicMutation, publicNodeAction, publicQuery };
108
+ export { FunctionSpec_exports, TypeId, convexInternalAction, convexInternalMutation, convexInternalNodeAction, convexInternalQuery, convexPublicAction, convexPublicMutation, convexPublicNodeAction, convexPublicQuery, internalAction, internalMutation, internalNodeAction, internalPaginatedQuery, internalQuery, isFunctionSpec, publicAction, publicMutation, publicNodeAction, publicPaginatedQuery, publicQuery };
66
109
 
67
110
  //# sourceMappingURL=FunctionSpec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionSpec.js","names":["FunctionProvenance.Confect","RuntimeAndFunctionType.ConvexQuery","RuntimeAndFunctionType.ConvexMutation","RuntimeAndFunctionType.ConvexAction","RuntimeAndFunctionType.NodeAction","FunctionProvenance.Convex"],"sources":["../src/FunctionSpec.ts"],"sourcesContent":["import type {\n FunctionType,\n FunctionVisibility,\n RegisteredAction,\n RegisteredMutation,\n RegisteredQuery,\n} from \"convex/server\";\nimport type { Schema } from \"effect\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as FunctionProvenance from \"./FunctionProvenance\";\nimport { validateConfectFunctionIdentifier } from \"./Identifier\";\nimport * as RuntimeAndFunctionType from \"./RuntimeAndFunctionType\";\n\nexport const TypeId = \"@confect/core/FunctionSpec\";\nexport type TypeId = typeof TypeId;\n\nexport const isFunctionSpec = (u: unknown): u is AnyWithProps =>\n Predicate.hasProperty(u, TypeId);\n\nexport interface FunctionSpec<\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n Name_ extends string,\n FunctionProvenance_ extends FunctionProvenance.FunctionProvenance,\n> {\n readonly [TypeId]: TypeId;\n readonly runtimeAndFunctionType: RuntimeAndFunctionType_;\n readonly functionVisibility: FunctionVisibility_;\n readonly name: Name_;\n readonly functionProvenance: FunctionProvenance_;\n}\n\nexport interface Any {\n readonly [TypeId]: TypeId;\n}\n\nexport interface AnyWithProps extends FunctionSpec<\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility,\n string,\n FunctionProvenance.FunctionProvenance\n> {}\n\nexport interface AnyConfect extends FunctionSpec<\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility,\n string,\n FunctionProvenance.AnyConfect\n> {}\n\nexport interface AnyConvex extends FunctionSpec<\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility,\n string,\n FunctionProvenance.AnyConvex\n> {}\n\nexport interface AnyWithPropsWithRuntime<\n Runtime extends RuntimeAndFunctionType.Runtime,\n> extends FunctionSpec<\n RuntimeAndFunctionType.WithRuntime<Runtime>,\n FunctionVisibility,\n string,\n FunctionProvenance.FunctionProvenance\n> {}\n\nexport interface AnyWithPropsWithFunctionType<\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n> extends FunctionSpec<\n RuntimeAndFunctionType_,\n FunctionVisibility,\n string,\n FunctionProvenance.FunctionProvenance\n> {}\n\nexport interface AnyWithPropsWithFunctionProvenance<\n FunctionProvenance_ extends FunctionProvenance.FunctionProvenance,\n> extends FunctionSpec<\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility,\n string,\n FunctionProvenance_\n> {}\n\nexport type GetRuntimeAndFunctionType<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_[\"runtimeAndFunctionType\"];\n\nexport type GetFunctionVisibility<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_[\"functionVisibility\"];\n\nexport type Name<FunctionSpec_ extends AnyWithProps> = FunctionSpec_[\"name\"];\n\nexport type Args<FunctionSpec_ extends AnyWithProps> = FunctionSpec_ extends {\n functionProvenance: {\n _tag: \"Confect\";\n args: infer ArgsSchema_ extends Schema.Codec<any, any>;\n };\n}\n ? ArgsSchema_[\"Type\"]\n : FunctionSpec_ extends {\n functionProvenance: { _tag: \"Convex\"; _args: infer Args_ };\n }\n ? Args_\n : never;\n\nexport type Returns<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_ extends {\n functionProvenance: {\n _tag: \"Confect\";\n returns: infer ReturnsSchema_ extends Schema.Codec<any, any>;\n };\n }\n ? ReturnsSchema_[\"Type\"]\n : FunctionSpec_ extends {\n functionProvenance: { _tag: \"Convex\"; _returns: infer Returns_ };\n }\n ? Awaited<Returns_>\n : never;\n\nexport type EncodedArgs<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_ extends {\n functionProvenance: {\n _tag: \"Confect\";\n args: infer ArgsSchema_ extends Schema.Codec<any, any>;\n };\n }\n ? ArgsSchema_[\"Encoded\"]\n : FunctionSpec_ extends {\n functionProvenance: { _tag: \"Convex\"; _args: infer Args_ };\n }\n ? Args_\n : never;\n\nexport type EncodedReturns<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_ extends {\n functionProvenance: {\n _tag: \"Confect\";\n returns: infer ReturnsSchema_ extends Schema.Codec<any, any>;\n };\n }\n ? ReturnsSchema_[\"Encoded\"]\n : FunctionSpec_ extends {\n functionProvenance: { _tag: \"Convex\"; _returns: infer Returns_ };\n }\n ? Returns_\n : never;\n\nexport type Error<FunctionSpec_ extends AnyWithProps> = FunctionSpec_ extends {\n functionProvenance: FunctionProvenance.Confect<\n any,\n any,\n infer ErrorSchema_ extends Schema.Codec<any, any>\n >;\n}\n ? ErrorSchema_[\"Type\"]\n : never;\n\nexport type EncodedError<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_ extends {\n functionProvenance: FunctionProvenance.Confect<\n any,\n any,\n infer ErrorSchema_ extends Schema.Codec<any, any>\n >;\n }\n ? ErrorSchema_[\"Encoded\"]\n : never;\n\nexport type WithName<\n FunctionSpec_ extends AnyWithProps,\n Name_ extends string,\n> = Extract<FunctionSpec_, { readonly name: Name_ }>;\n\nexport type WithRuntimeAndFunctionType<\n FunctionSpec_ extends AnyWithProps,\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n> = Extract<\n FunctionSpec_,\n { readonly runtimeAndFunctionType: RuntimeAndFunctionType_ }\n>;\n\nexport type WithFunctionType<\n FunctionSpec_ extends AnyWithProps,\n FunctionType_ extends FunctionType,\n> = Extract<\n FunctionSpec_,\n { readonly runtimeAndFunctionType: { readonly functionType: FunctionType_ } }\n>;\n\nexport type WithFunctionProvenance<\n FunctionSpec_ extends AnyWithProps,\n FunctionProvenance_ extends FunctionProvenance.FunctionProvenance,\n> = Extract<\n FunctionSpec_,\n { readonly functionProvenance: FunctionProvenance_ }\n>;\n\nexport type WithoutName<\n FunctionSpec_ extends AnyWithProps,\n Name_ extends Name<FunctionSpec_>,\n> = Exclude<FunctionSpec_, { readonly name: Name_ }>;\n\nconst Proto = {\n [TypeId]: TypeId,\n};\n\nconst make =\n <\n RuntimeAndFunctionType_ extends\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n >(\n runtimeAndFunctionType: RuntimeAndFunctionType_,\n functionVisibility: FunctionVisibility_,\n ) =>\n <\n const Name_ extends string,\n Args_ extends Schema.Codec<any, any>,\n Returns_ extends Schema.Codec<any, any>,\n Error_ extends Schema.Codec<any, any> = never,\n >({\n name,\n args,\n returns,\n error,\n }: {\n name: Name_;\n args: () => Args_;\n returns: () => Returns_;\n error?: () => Error_;\n }): FunctionSpec<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Name_,\n FunctionProvenance.Confect<Args_, Returns_, Error_>\n > => {\n validateConfectFunctionIdentifier(name);\n\n return Object.assign(Object.create(Proto), {\n runtimeAndFunctionType,\n functionVisibility,\n name,\n functionProvenance: FunctionProvenance.Confect(args, returns, error),\n });\n };\n\nexport const publicQuery = make(RuntimeAndFunctionType.ConvexQuery, \"public\");\nexport const internalQuery = make(\n RuntimeAndFunctionType.ConvexQuery,\n \"internal\",\n);\nexport const publicMutation = make(\n RuntimeAndFunctionType.ConvexMutation,\n \"public\",\n);\nexport const internalMutation = make(\n RuntimeAndFunctionType.ConvexMutation,\n \"internal\",\n);\nexport const publicAction = make(RuntimeAndFunctionType.ConvexAction, \"public\");\nexport const internalAction = make(\n RuntimeAndFunctionType.ConvexAction,\n \"internal\",\n);\n\nexport const publicNodeAction = make(\n RuntimeAndFunctionType.NodeAction,\n \"public\",\n);\nexport const internalNodeAction = make(\n RuntimeAndFunctionType.NodeAction,\n \"internal\",\n);\n\ntype MatchingRegisteredFunction<\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n> =\n RuntimeAndFunctionType.GetFunctionType<RuntimeAndFunctionType_> extends \"query\"\n ? RegisteredQuery<FunctionVisibility_, any, any>\n : RuntimeAndFunctionType.GetFunctionType<RuntimeAndFunctionType_> extends \"mutation\"\n ? RegisteredMutation<FunctionVisibility_, any, any>\n : RuntimeAndFunctionType.GetFunctionType<RuntimeAndFunctionType_> extends \"action\"\n ? RegisteredAction<FunctionVisibility_, any, any>\n : never;\n\ntype ExtractArgs<F> =\n F extends RegisteredQuery<any, infer A, any>\n ? A\n : F extends RegisteredMutation<any, infer A, any>\n ? A\n : F extends RegisteredAction<any, infer A, any>\n ? A\n : never;\n\ntype ExtractReturns<F> =\n F extends RegisteredQuery<any, any, infer R>\n ? R\n : F extends RegisteredMutation<any, any, infer R>\n ? R\n : F extends RegisteredAction<any, any, infer R>\n ? R\n : never;\n\nconst makeConvex =\n <\n RuntimeAndFunctionType_ extends\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n >(\n runtimeAndFunctionType: RuntimeAndFunctionType_,\n functionVisibility: FunctionVisibility_,\n ) =>\n <\n F extends MatchingRegisteredFunction<\n RuntimeAndFunctionType_,\n FunctionVisibility_\n >,\n >() =>\n <const Name_ extends string>(\n name: Name_,\n ): FunctionSpec<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Name_,\n FunctionProvenance.Convex<ExtractArgs<F>, ExtractReturns<F>>\n > => {\n validateConfectFunctionIdentifier(name);\n\n return Object.assign(Object.create(Proto), {\n runtimeAndFunctionType,\n functionVisibility,\n name,\n functionProvenance: FunctionProvenance.Convex<\n ExtractArgs<F>,\n ExtractReturns<F>\n >(),\n }) as any;\n };\n\nexport const convexPublicQuery = makeConvex(\n RuntimeAndFunctionType.ConvexQuery,\n \"public\",\n);\nexport const convexInternalQuery = makeConvex(\n RuntimeAndFunctionType.ConvexQuery,\n \"internal\",\n);\nexport const convexPublicMutation = makeConvex(\n RuntimeAndFunctionType.ConvexMutation,\n \"public\",\n);\nexport const convexInternalMutation = makeConvex(\n RuntimeAndFunctionType.ConvexMutation,\n \"internal\",\n);\nexport const convexPublicAction = makeConvex(\n RuntimeAndFunctionType.ConvexAction,\n \"public\",\n);\nexport const convexInternalAction = makeConvex(\n RuntimeAndFunctionType.ConvexAction,\n \"internal\",\n);\nexport const convexPublicNodeAction = makeConvex(\n RuntimeAndFunctionType.NodeAction,\n \"public\",\n);\nexport const convexInternalNodeAction = makeConvex(\n RuntimeAndFunctionType.NodeAction,\n \"internal\",\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,MAAa,SAAS;AAGtB,MAAa,kBAAkB,MAC7B,UAAU,YAAY,GAAG,MAAM;AAyLjC,MAAM,QAAQ,GACX,SAAS,OACZ;AAEA,MAAM,QAMF,wBACA,wBAOA,EACA,MACA,MACA,SACA,YAWG;CACH,kCAAkC,IAAI;CAEtC,OAAO,OAAO,OAAO,OAAO,OAAO,KAAK,GAAG;EACzC;EACA;EACA;EACA,oBAAoBA,QAA2B,MAAM,SAAS,KAAK;CACrE,CAAC;AACH;AAEF,MAAa,cAAc,KAAKC,aAAoC,QAAQ;AAC5E,MAAa,gBAAgB,KAC3BA,aACA,UACF;AACA,MAAa,iBAAiB,KAC5BC,gBACA,QACF;AACA,MAAa,mBAAmB,KAC9BA,gBACA,UACF;AACA,MAAa,eAAe,KAAKC,cAAqC,QAAQ;AAC9E,MAAa,iBAAiB,KAC5BA,cACA,UACF;AAEA,MAAa,mBAAmB,KAC9BC,YACA,QACF;AACA,MAAa,qBAAqB,KAChCA,YACA,UACF;AAgCA,MAAM,cAMF,wBACA,8BASA,SAMG;CACH,kCAAkC,IAAI;CAEtC,OAAO,OAAO,OAAO,OAAO,OAAO,KAAK,GAAG;EACzC;EACA;EACA;EACA,oBAAoBC,OAGlB;CACJ,CAAC;AACH;AAEF,MAAa,oBAAoB,WAC/BJ,aACA,QACF;AACA,MAAa,sBAAsB,WACjCA,aACA,UACF;AACA,MAAa,uBAAuB,WAClCC,gBACA,QACF;AACA,MAAa,yBAAyB,WACpCA,gBACA,UACF;AACA,MAAa,qBAAqB,WAChCC,cACA,QACF;AACA,MAAa,uBAAuB,WAClCA,cACA,UACF;AACA,MAAa,yBAAyB,WACpCC,YACA,QACF;AACA,MAAa,2BAA2B,WACtCA,YACA,UACF"}
1
+ {"version":3,"file":"FunctionSpec.js","names":["FunctionProvenance.Confect","FunctionProvenance.ConfectPaginated","RuntimeAndFunctionType.ConvexQuery","RuntimeAndFunctionType.ConvexMutation","RuntimeAndFunctionType.ConvexAction","RuntimeAndFunctionType.NodeAction","FunctionProvenance.Convex"],"sources":["../src/FunctionSpec.ts"],"sourcesContent":["import type * as MiddlewareAttachment from \"./MiddlewareAttachment\";\nimport type {\n DefaultFunctionArgs,\n FunctionType,\n FunctionVisibility,\n RegisteredAction,\n RegisteredMutation,\n RegisteredQuery,\n} from \"convex/server\";\nimport type * as Schema from \"effect/Schema\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as FunctionProvenance from \"./FunctionProvenance\";\nimport { validateConfectFunctionIdentifier } from \"./Identifier\";\nimport type * as MiddlewareSpec from \"./MiddlewareSpec\";\nimport * as RuntimeAndFunctionType from \"./RuntimeAndFunctionType\";\n\nexport const TypeId = \"~@confect/core/FunctionSpec\";\nexport type TypeId = typeof TypeId;\n\nexport const isFunctionSpec = (u: unknown): u is AnyWithProps =>\n Predicate.hasProperty(u, TypeId);\n\nexport interface FunctionSpec<\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n Name_ extends string,\n FunctionProvenance_ extends FunctionProvenance.FunctionProvenance,\n MiddlewareSpecs_ extends MiddlewareSpec.AnyMiddlewareSpec = never,\n> {\n readonly [TypeId]: TypeId;\n readonly runtimeAndFunctionType: RuntimeAndFunctionType_;\n readonly functionVisibility: FunctionVisibility_;\n readonly name: Name_;\n readonly functionProvenance: FunctionProvenance_;\n readonly middlewareSpecs: ReadonlyArray<MiddlewareSpecs_>;\n readonly middlewareAttachments: ReadonlyArray<\n MiddlewareAttachment.MiddlewareAttachment<MiddlewareSpecs_>\n >;\n}\n\nexport interface Builder<\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n Name_ extends string,\n FunctionProvenance_ extends FunctionProvenance.FunctionProvenance,\n MiddlewareSpecs_ extends MiddlewareSpec.AnyMiddlewareSpec = never,\n> extends FunctionSpec<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Name_,\n FunctionProvenance_,\n MiddlewareSpecs_\n> {\n middleware<MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec>(\n middlewareSpec: MiddlewareSpec_ &\n MiddlewareSpec.ValidateFunctionAttach<\n MiddlewareSpec_,\n RuntimeAndFunctionType_,\n FunctionProvenance_,\n MiddlewareSpecs_\n >,\n ...options: MiddlewareAttachment.Args<NoInfer<MiddlewareSpec_>>\n ): Builder<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Name_,\n FunctionProvenance_,\n MiddlewareSpecs_ | MiddlewareSpec_\n >;\n}\n\nexport interface Any {\n readonly [TypeId]: TypeId;\n}\n\nexport interface AnyWithProps extends FunctionSpec<\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility,\n string,\n FunctionProvenance.FunctionProvenance,\n MiddlewareSpec.AnyMiddlewareSpec\n> {}\n\nexport interface AnyConfect extends FunctionSpec<\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility,\n string,\n FunctionProvenance.AnyConfect,\n MiddlewareSpec.AnyMiddlewareSpec\n> {}\n\nexport interface AnyConvex extends FunctionSpec<\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility,\n string,\n FunctionProvenance.AnyConvex,\n MiddlewareSpec.AnyMiddlewareSpec\n> {}\n\nexport interface AnyWithPropsWithRuntime<\n Runtime extends RuntimeAndFunctionType.Runtime,\n> extends FunctionSpec<\n RuntimeAndFunctionType.WithRuntime<Runtime>,\n FunctionVisibility,\n string,\n FunctionProvenance.FunctionProvenance,\n MiddlewareSpec.AnyMiddlewareSpec\n> {}\n\nexport interface AnyWithPropsWithFunctionType<\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n> extends FunctionSpec<\n RuntimeAndFunctionType_,\n FunctionVisibility,\n string,\n FunctionProvenance.FunctionProvenance,\n MiddlewareSpec.AnyMiddlewareSpec\n> {}\n\nexport interface AnyWithPropsWithFunctionProvenance<\n FunctionProvenance_ extends FunctionProvenance.FunctionProvenance,\n> extends FunctionSpec<\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility,\n string,\n FunctionProvenance_,\n MiddlewareSpec.AnyMiddlewareSpec\n> {}\n\nexport type GetRuntimeAndFunctionType<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_[\"runtimeAndFunctionType\"];\n\nexport type GetFunctionVisibility<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_[\"functionVisibility\"];\n\nexport type GetFunctionProvenance<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_[\"functionProvenance\"];\n\nexport type Name<FunctionSpec_ extends AnyWithProps> = FunctionSpec_[\"name\"];\n\nexport type MiddlewareSpecs<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_[\"middlewareSpecs\"][number];\n\n/**\n * The field map declared by a Confect-provenance spec.\n */\nexport type ArgsFields<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_ extends {\n readonly functionProvenance: {\n readonly _tag: \"Confect\";\n readonly \"~ArgsFields\": infer ArgsFields_ extends\n FunctionProvenance.ArgsFields;\n };\n }\n ? ArgsFields_\n : FunctionSpec_ extends {\n readonly functionProvenance: { readonly _tag: \"Confect\" };\n }\n ? FunctionProvenance.ArgsFields\n : never;\n\n/**\n * The args schema assembled from a Confect-provenance spec's field map.\n */\nexport type ArgsSchema<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_ extends {\n readonly functionProvenance: {\n readonly _tag: \"Confect\";\n readonly \"~ArgsFields\": infer ArgsFields_ extends\n FunctionProvenance.ArgsFields;\n };\n }\n ? Schema.Struct<ArgsFields_>\n : FunctionSpec_ extends {\n readonly functionProvenance: {\n readonly _tag: \"Confect\";\n readonly args: infer ArgsSchema_ extends\n FunctionProvenance.AnyArgsSchema;\n };\n }\n ? ArgsSchema_\n : never;\n\nexport type ReturnsSchema<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_ extends {\n readonly functionProvenance: {\n readonly _tag: \"Confect\";\n readonly returns: infer ReturnsSchema_ extends Schema.Codec<any, any>;\n };\n }\n ? ReturnsSchema_\n : never;\n\nexport type ErrorSchema<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_ extends {\n readonly functionProvenance: {\n readonly _tag: \"Confect\";\n readonly error?: infer ErrorSchema_;\n };\n }\n ? Extract<ErrorSchema_, Schema.Codec<any, any>>\n : never;\n\nexport type Args<FunctionSpec_ extends AnyWithProps> = FunctionSpec_ extends {\n readonly functionProvenance: { readonly _tag: \"Confect\" };\n}\n ? ArgsSchema<FunctionSpec_>[\"Type\"]\n : GetFunctionProvenance<FunctionSpec_> extends FunctionProvenance.Convex<\n infer Args_,\n any\n >\n ? Args_\n : never;\n\nexport type Returns<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_ extends {\n readonly functionProvenance: { readonly _tag: \"Confect\" };\n }\n ? ReturnsSchema<FunctionSpec_>[\"Type\"]\n : GetFunctionProvenance<FunctionSpec_> extends FunctionProvenance.Convex<\n any,\n infer Returns_\n >\n ? Awaited<Returns_>\n : never;\n\nexport type EncodedArgs<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_ extends {\n readonly functionProvenance: { readonly _tag: \"Confect\" };\n }\n ? ArgsSchema<FunctionSpec_>[\"Encoded\"]\n : GetFunctionProvenance<FunctionSpec_> extends FunctionProvenance.Convex<\n infer Args_,\n any\n >\n ? Args_\n : never;\n\nexport type EncodedReturns<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_ extends {\n readonly functionProvenance: { readonly _tag: \"Confect\" };\n }\n ? ReturnsSchema<FunctionSpec_>[\"Encoded\"]\n : GetFunctionProvenance<FunctionSpec_> extends FunctionProvenance.Convex<\n any,\n infer Returns_\n >\n ? Returns_\n : never;\n\nexport type Error<FunctionSpec_ extends AnyWithProps> =\n ErrorSchema<FunctionSpec_>[\"Type\"];\n\nexport type EncodedError<FunctionSpec_ extends AnyWithProps> =\n ErrorSchema<FunctionSpec_>[\"Encoded\"];\n\nexport type WithName<\n FunctionSpec_ extends AnyWithProps,\n Name_ extends string,\n> = Extract<FunctionSpec_, { readonly name: Name_ }>;\n\nexport type WithRuntimeAndFunctionType<\n FunctionSpec_ extends AnyWithProps,\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n> = Extract<\n FunctionSpec_,\n { readonly runtimeAndFunctionType: RuntimeAndFunctionType_ }\n>;\n\nexport type WithFunctionType<\n FunctionSpec_ extends AnyWithProps,\n FunctionType_ extends FunctionType,\n> = Extract<\n FunctionSpec_,\n { readonly runtimeAndFunctionType: { readonly functionType: FunctionType_ } }\n>;\n\nexport type WithFunctionProvenance<\n FunctionSpec_ extends AnyWithProps,\n FunctionProvenance_ extends FunctionProvenance.FunctionProvenance,\n> = Extract<\n FunctionSpec_,\n { readonly functionProvenance: FunctionProvenance_ }\n>;\n\nexport type WithoutName<\n FunctionSpec_ extends AnyWithProps,\n Name_ extends Name<FunctionSpec_>,\n> = Exclude<FunctionSpec_, { readonly name: Name_ }>;\n\nconst Proto = {\n [TypeId]: TypeId,\n\n get middlewareSpecs() {\n return this.middlewareAttachments.map(({ spec }) => spec);\n },\n\n middleware(\n this: AnyWithProps,\n middlewareSpec: MiddlewareSpec.AnyMiddlewareSpec,\n ...options: ReadonlyArray<unknown>\n ) {\n if (this.functionProvenance._tag === \"Convex\") {\n throw new Error(\n `Plain Convex function \"${this.name}\" cannot have middleware`,\n );\n }\n const functionType = this.runtimeAndFunctionType.functionType;\n if (!middlewareSpec.functionTypes[functionType]) {\n throw new Error(\n `Middleware \"${middlewareSpec.key}\" does not declare function type \"${functionType}\" of function \"${this.name}\"`,\n );\n }\n if (\n !(\"options\" in middlewareSpec) &&\n this.middlewareAttachments.some(\n ({ spec }) => spec.key === middlewareSpec.key,\n )\n ) {\n throw new Error(\n `Middleware \"${middlewareSpec.key}\" is already attached to function \"${this.name}\"`,\n );\n }\n\n return Object.assign(Object.create(Proto), {\n runtimeAndFunctionType: this.runtimeAndFunctionType,\n functionVisibility: this.functionVisibility,\n name: this.name,\n functionProvenance: this.functionProvenance,\n middlewareAttachments: [\n ...this.middlewareAttachments,\n { spec: middlewareSpec, options: options[0] },\n ],\n });\n },\n} satisfies ThisType<AnyWithProps>;\n\ninterface Options {\n readonly name: string;\n readonly args?: () => FunctionProvenance.ArgsFields;\n readonly returns: () => Schema.Codec<any, any>;\n readonly error?: () => Schema.Codec<any, any>;\n}\n\nconst make = <\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n>(\n runtimeAndFunctionType: RuntimeAndFunctionType_,\n functionVisibility: FunctionVisibility_,\n) => {\n function makeSpec<\n const Name_ extends string,\n const ArgsFields_ extends FunctionProvenance.ArgsFields,\n Returns_ extends Schema.Codec<any, any>,\n Error_ extends Schema.Codec<any, any> = never,\n >(options: {\n name: Name_;\n args: () => ArgsFields_;\n returns: () => Returns_;\n error?: () => Error_;\n }): Builder<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Name_,\n FunctionProvenance.Confect<ArgsFields_, Returns_, Error_>\n >;\n function makeSpec<\n const Name_ extends string,\n Returns_ extends Schema.Codec<any, any>,\n Error_ extends Schema.Codec<any, any> = never,\n >(options: {\n name: Name_;\n args?: never;\n returns: () => Returns_;\n error?: () => Error_;\n }): Builder<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Name_,\n FunctionProvenance.Confect<{}, Returns_, Error_>\n >;\n function makeSpec({ name, args, returns, error }: Options) {\n validateConfectFunctionIdentifier(name);\n\n return Object.assign(Object.create(Proto), {\n runtimeAndFunctionType,\n functionVisibility,\n name,\n functionProvenance:\n args === undefined\n ? FunctionProvenance.Confect(() => ({}), returns, error)\n : FunctionProvenance.Confect(args, returns, error),\n middlewareAttachments: [],\n });\n }\n\n return makeSpec;\n};\n\n/**\n * `Schema.Struct` fields that must not declare `paginationOpts`. Used to reject\n * a user args schema that redeclares the field the paginated constructors add\n * themselves; the check reports at the `args` thunk with an unsatisfiable type\n * when violated.\n */\ntype ForbidPaginationOpts<\n UserArgsFields extends FunctionProvenance.ArgsFields,\n> = \"paginationOpts\" extends keyof UserArgsFields\n ? { readonly paginationOpts: never }\n : unknown;\n\ninterface PaginatedOptions {\n readonly name: string;\n readonly args?: () => FunctionProvenance.ArgsFields;\n readonly item: () => Schema.Codec<any, any>;\n readonly error?: () => Schema.Codec<any, any>;\n}\n\nconst makePaginated = <\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n>(\n runtimeAndFunctionType: RuntimeAndFunctionType_,\n functionVisibility: FunctionVisibility_,\n) => {\n function makeSpec<\n const Name_ extends string,\n const UserArgsFields_ extends FunctionProvenance.ArgsFields,\n Item_ extends Schema.Codec<any, any>,\n Error_ extends Schema.Codec<any, any> = never,\n >(options: {\n name: Name_;\n args: () => UserArgsFields_ & ForbidPaginationOpts<UserArgsFields_>;\n item: () => Item_;\n error?: () => Error_;\n }): Builder<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Name_,\n FunctionProvenance.ConfectPaginated<UserArgsFields_, Item_, Error_>\n >;\n function makeSpec<\n const Name_ extends string,\n Item_ extends Schema.Codec<any, any>,\n Error_ extends Schema.Codec<any, any> = never,\n >(options: {\n name: Name_;\n args?: never;\n item: () => Item_;\n error?: () => Error_;\n }): Builder<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Name_,\n FunctionProvenance.ConfectPaginated<{}, Item_, Error_>\n >;\n function makeSpec({ name, args, item, error }: PaginatedOptions) {\n validateConfectFunctionIdentifier(name);\n\n return Object.assign(Object.create(Proto), {\n runtimeAndFunctionType,\n functionVisibility,\n name,\n functionProvenance:\n args === undefined\n ? FunctionProvenance.ConfectPaginated(() => ({}), item, error)\n : FunctionProvenance.ConfectPaginated(args, item, error),\n middlewareAttachments: [],\n });\n }\n\n return makeSpec;\n};\n\nexport const publicQuery = make(RuntimeAndFunctionType.ConvexQuery, \"public\");\nexport const internalQuery = make(\n RuntimeAndFunctionType.ConvexQuery,\n \"internal\",\n);\nexport const publicPaginatedQuery = makePaginated(\n RuntimeAndFunctionType.ConvexQuery,\n \"public\",\n);\nexport const internalPaginatedQuery = makePaginated(\n RuntimeAndFunctionType.ConvexQuery,\n \"internal\",\n);\nexport const publicMutation = make(\n RuntimeAndFunctionType.ConvexMutation,\n \"public\",\n);\nexport const internalMutation = make(\n RuntimeAndFunctionType.ConvexMutation,\n \"internal\",\n);\nexport const publicAction = make(RuntimeAndFunctionType.ConvexAction, \"public\");\nexport const internalAction = make(\n RuntimeAndFunctionType.ConvexAction,\n \"internal\",\n);\n\nexport const publicNodeAction = make(\n RuntimeAndFunctionType.NodeAction,\n \"public\",\n);\nexport const internalNodeAction = make(\n RuntimeAndFunctionType.NodeAction,\n \"internal\",\n);\n\ntype MatchingRegisteredFunction<\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n> =\n RuntimeAndFunctionType.GetFunctionType<RuntimeAndFunctionType_> extends \"query\"\n ? RegisteredQuery<FunctionVisibility_, any, any>\n : RuntimeAndFunctionType.GetFunctionType<RuntimeAndFunctionType_> extends \"mutation\"\n ? RegisteredMutation<FunctionVisibility_, any, any>\n : RuntimeAndFunctionType.GetFunctionType<RuntimeAndFunctionType_> extends \"action\"\n ? RegisteredAction<FunctionVisibility_, any, any>\n : never;\n\ntype ExtractArgs<F> =\n F extends RegisteredQuery<any, infer A extends DefaultFunctionArgs, any>\n ? A\n : F extends RegisteredMutation<\n any,\n infer A extends DefaultFunctionArgs,\n any\n >\n ? A\n : F extends RegisteredAction<\n any,\n infer A extends DefaultFunctionArgs,\n any\n >\n ? A\n : never;\n\ntype ExtractReturns<F> =\n F extends RegisteredQuery<any, any, infer R>\n ? R\n : F extends RegisteredMutation<any, any, infer R>\n ? R\n : F extends RegisteredAction<any, any, infer R>\n ? R\n : never;\n\nconst makeConvex =\n <\n RuntimeAndFunctionType_ extends\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n >(\n runtimeAndFunctionType: RuntimeAndFunctionType_,\n functionVisibility: FunctionVisibility_,\n ) =>\n <\n F extends MatchingRegisteredFunction<\n RuntimeAndFunctionType_,\n FunctionVisibility_\n >,\n >() =>\n <const Name_ extends string>(\n name: Name_,\n ): Builder<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Name_,\n FunctionProvenance.Convex<ExtractArgs<F>, ExtractReturns<F>>\n > => {\n validateConfectFunctionIdentifier(name);\n\n return Object.assign(Object.create(Proto), {\n runtimeAndFunctionType,\n functionVisibility,\n name,\n functionProvenance: FunctionProvenance.Convex<\n ExtractArgs<F>,\n ExtractReturns<F>\n >(),\n middlewareAttachments: [],\n }) as any;\n };\n\nexport const convexPublicQuery = makeConvex(\n RuntimeAndFunctionType.ConvexQuery,\n \"public\",\n);\nexport const convexInternalQuery = makeConvex(\n RuntimeAndFunctionType.ConvexQuery,\n \"internal\",\n);\nexport const convexPublicMutation = makeConvex(\n RuntimeAndFunctionType.ConvexMutation,\n \"public\",\n);\nexport const convexInternalMutation = makeConvex(\n RuntimeAndFunctionType.ConvexMutation,\n \"internal\",\n);\nexport const convexPublicAction = makeConvex(\n RuntimeAndFunctionType.ConvexAction,\n \"public\",\n);\nexport const convexInternalAction = makeConvex(\n RuntimeAndFunctionType.ConvexAction,\n \"internal\",\n);\nexport const convexPublicNodeAction = makeConvex(\n RuntimeAndFunctionType.NodeAction,\n \"public\",\n);\nexport const convexInternalNodeAction = makeConvex(\n RuntimeAndFunctionType.NodeAction,\n \"internal\",\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAa,SAAS;AAGtB,MAAa,kBAAkB,MAC7B,UAAU,YAAY,GAAG,MAAM;AA8QjC,MAAM,QAAQ;EACX,SAAS;CAEV,IAAI,kBAAkB;EACpB,OAAO,KAAK,sBAAsB,KAAK,EAAE,WAAW,IAAI;CAC1D;CAEA,WAEE,gBACA,GAAG,SACH;EACA,IAAI,KAAK,mBAAmB,SAAS,UACnC,MAAM,IAAI,MACR,0BAA0B,KAAK,KAAK,yBACtC;EAEF,MAAM,eAAe,KAAK,uBAAuB;EACjD,IAAI,CAAC,eAAe,cAAc,eAChC,MAAM,IAAI,MACR,eAAe,eAAe,IAAI,oCAAoC,aAAa,iBAAiB,KAAK,KAAK,EAChH;EAEF,IACE,EAAE,aAAa,mBACf,KAAK,sBAAsB,MACxB,EAAE,WAAW,KAAK,QAAQ,eAAe,GAC5C,GAEA,MAAM,IAAI,MACR,eAAe,eAAe,IAAI,qCAAqC,KAAK,KAAK,EACnF;EAGF,OAAO,OAAO,OAAO,OAAO,OAAO,KAAK,GAAG;GACzC,wBAAwB,KAAK;GAC7B,oBAAoB,KAAK;GACzB,MAAM,KAAK;GACX,oBAAoB,KAAK;GACzB,uBAAuB,CACrB,GAAG,KAAK,uBACR;IAAE,MAAM;IAAgB,SAAS,QAAQ;GAAG,CAC9C;EACF,CAAC;CACH;AACF;AASA,MAAM,QAIJ,wBACA,uBACG;CAgCH,SAAS,SAAS,EAAE,MAAM,MAAM,SAAS,SAAkB;EACzD,kCAAkC,IAAI;EAEtC,OAAO,OAAO,OAAO,OAAO,OAAO,KAAK,GAAG;GACzC;GACA;GACA;GACA,oBACE,SAAS,KAAA,IACL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A,MAAa,yBAAyB,WACpCC,YACA,QACF;AACA,MAAa,2BAA2B,WACtCA,YACA,UACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"GenericId.d.ts","sourceRoot":"","sources":["../src/GenericId.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,IAAI,eAAe,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAC;AAI9C,eAAO,MAAM,SAAS,GAAI,SAAS,SAAS,MAAM,EAChD,WAAW,SAAS,KACnB,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,SAAS,CAAC,CAGiB,CAAC;AAE5D,MAAM,MAAM,SAAS,CAAC,SAAS,SAAS,MAAM,IAAI,eAAe,CAAC,SAAS,CAAC,CAAC;AAE7E,eAAO,MAAM,SAAS,GAAI,SAAS,SAAS,MAAM,EAChD,KAAK,SAAS,CAAC,GAAG,KACjB,MAAM,CAAC,MAAM,CAAC,SAAS,CAC2C,CAAC"}
1
+ {"version":3,"file":"GenericId.d.ts","sourceRoot":"","sources":["../src/GenericId.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,IAAI,eAAe,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAC;AAI9C,eAAO,MAAM,SAAS,GAAI,SAAS,SAAS,MAAM,aACrC,SAAS,KACnB,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,SAAS,CAAC,CAGiB,CAAC;AAE5D,MAAM,MAAM,SAAS,CAAC,SAAS,SAAS,MAAM,IAAI,eAAe,CAAC,SAAS,CAAC,CAAC;AAE7E,eAAO,MAAM,SAAS,GAAI,SAAS,SAAS,MAAM,OAC3C,SAAS,CAAC,GAAG,KACjB,MAAM,CAAC,MAAM,CAAC,SAAS,CAC2C,CAAC"}
package/dist/GenericId.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
- import * as Option from "effect/Option";
3
2
  import * as Schema from "effect/Schema";
3
+ import * as Option from "effect/Option";
4
4
  import * as SchemaAST from "effect/SchemaAST";
5
5
  //#region src/GenericId.ts
6
6
  var GenericId_exports = /* @__PURE__ */ __exportAll({
@@ -1,27 +1,23 @@
1
- import type { Record } from "effect";
2
1
  import type * as GroupSpec from "./GroupSpec";
3
2
  /**
4
3
  * Recursively generates paths for a group and its nested groups.
5
4
  *
6
5
  * - For a group with no subgroups, returns just the group name.
7
- * - For a group with subgroups, returns the group name plus all possible paths through its direct subgroups.
6
+ * - For a group with subgroups, returns the group name plus all possible paths
7
+ * through its direct subgroups.
8
8
  */
9
9
  export type All<Group extends GroupSpec.AnyWithProps, Depth extends 1[] = []> = Depth["length"] extends 15 ? string : Group extends any ? [GroupSpec.Groups<Group>] extends [never] ? GroupSpec.Name<Group> : GroupSpec.Name<Group> | AllHelper<Group, GroupSpec.Groups<Group>, Depth> : never;
10
10
  type AllHelper<Parent extends GroupSpec.AnyWithProps, Groups_ extends GroupSpec.AnyWithProps, Depth extends 1[] = []> = Groups_ extends GroupSpec.AnyWithProps ? `${GroupSpec.Name<Parent>}.${All<Groups_, [...Depth, 1]>}` : never;
11
11
  /**
12
- * Recursively extracts the group at the given dot-separated path.
13
- * Path must match the format defined in `Path` above, e.g. "group" or "group.subgroup".
12
+ * Recursively extracts the group at the given dot-separated path. Path must
13
+ * match the format defined in `Path` above, e.g. "group" or "group.subgroup".
14
14
  *
15
15
  * @example
16
- * ```ts
17
- * type G = WithPath<RootGroup, "group.subgroup">;
18
- * ```
16
+ * type G = WithPath<RootGroup, "group.subgroup">;
19
17
  */
20
18
  export type GroupAt<Group, Path extends string> = Group extends GroupSpec.AnyWithProps ? Path extends `${infer Head}.${infer Tail}` ? Group extends {
21
19
  readonly name: Head;
22
- } ? Group extends {
23
- readonly groups: Record.ReadonlyRecord<string, infer SubGroup>;
24
- } ? GroupAt<SubGroup, Tail> : never : never : GroupSpec.WithName<Group, Path> : never;
20
+ } ? GroupAt<GroupSpec.Groups<Group>, Tail> : never : GroupSpec.WithName<Group, Path> : never;
25
21
  export type SubGroupsAt<Group extends GroupSpec.AnyWithProps, GroupPath extends string> = GroupSpec.Groups<GroupAt<Group, GroupPath>> extends infer SubGroups ? SubGroups extends GroupSpec.AnyWithProps ? `${GroupPath}.${GroupSpec.Name<SubGroups>}` : never : never;
26
22
  export {};
27
23
  //# sourceMappingURL=GroupPath.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GroupPath.d.ts","sourceRoot":"","sources":["../src/GroupPath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,KAAK,SAAS,MAAM,aAAa,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,MAAM,GAAG,CACb,KAAK,SAAS,SAAS,CAAC,YAAY,EACpC,KAAK,SAAS,CAAC,EAAE,GAAG,EAAE,IACpB,KAAK,CAAC,QAAQ,CAAC,SAAS,EAAE,GAC1B,MAAM,GACN,KAAK,SAAS,GAAG,GACf,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACvC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,GACrB,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,GAC1E,KAAK,CAAC;AAEZ,KAAK,SAAS,CACZ,MAAM,SAAS,SAAS,CAAC,YAAY,EACrC,OAAO,SAAS,SAAS,CAAC,YAAY,EACtC,KAAK,SAAS,CAAC,EAAE,GAAG,EAAE,IAC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SAAS,SAAS,SAAS,CAAC,YAAY,GACtC,GAAG,SAAS,IAAI,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,GAC3C,KAAK,GACP,KAAK,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"GroupPath.js","names":[],"sources":["../src/GroupPath.ts"],"sourcesContent":["import type { Record } from \"effect\";\nimport type * as GroupSpec from \"./GroupSpec\";\n\n/**\n * Recursively generates paths for a group and its nested groups.\n *\n * - For a group with no subgroups, returns just the group name.\n * - For a group with subgroups, returns the group name plus all possible paths through its direct subgroups.\n */\nexport type All<\n Group extends GroupSpec.AnyWithProps,\n Depth extends 1[] = [],\n> = Depth[\"length\"] extends 15\n ? string\n : Group extends any\n ? [GroupSpec.Groups<Group>] extends [never]\n ? GroupSpec.Name<Group>\n : GroupSpec.Name<Group> | AllHelper<Group, GroupSpec.Groups<Group>, Depth>\n : never;\n\ntype AllHelper<\n Parent extends GroupSpec.AnyWithProps,\n Groups_ extends GroupSpec.AnyWithProps,\n Depth extends 1[] = [],\n> = Groups_ extends GroupSpec.AnyWithProps\n ? `${GroupSpec.Name<Parent>}.${All<Groups_, [...Depth, 1]>}`\n : never;\n\n/**\n * Recursively extracts the group at the given dot-separated path.\n * Path must match the format defined in `Path` above, e.g. \"group\" or \"group.subgroup\".\n *\n * @example\n * ```ts\n * type G = WithPath<RootGroup, \"group.subgroup\">;\n * ```\n */\nexport type GroupAt<\n Group,\n Path extends string,\n> = Group extends GroupSpec.AnyWithProps\n ? Path extends `${infer Head}.${infer Tail}`\n ? Group extends { readonly name: Head }\n ? Group extends {\n readonly groups: Record.ReadonlyRecord<string, infer SubGroup>;\n }\n ? GroupAt<SubGroup, Tail>\n : never\n : never\n : GroupSpec.WithName<Group, Path>\n : never;\n\nexport type SubGroupsAt<\n Group extends GroupSpec.AnyWithProps,\n GroupPath extends string,\n> =\n GroupSpec.Groups<GroupAt<Group, GroupPath>> extends infer SubGroups\n ? SubGroups extends GroupSpec.AnyWithProps\n ? `${GroupPath}.${GroupSpec.Name<SubGroups>}`\n : never\n : never;\n"],"mappings":""}
1
+ {"version":3,"file":"GroupPath.js","names":[],"sources":["../src/GroupPath.ts"],"sourcesContent":["import type * as GroupSpec from \"./GroupSpec\";\n\n/**\n * Recursively generates paths for a group and its nested groups.\n *\n * - For a group with no subgroups, returns just the group name.\n * - For a group with subgroups, returns the group name plus all possible paths\n * through its direct subgroups.\n */\nexport type All<\n Group extends GroupSpec.AnyWithProps,\n Depth extends 1[] = [],\n> = Depth[\"length\"] extends 15\n ? string\n : Group extends any\n ? [GroupSpec.Groups<Group>] extends [never]\n ? GroupSpec.Name<Group>\n : GroupSpec.Name<Group> | AllHelper<Group, GroupSpec.Groups<Group>, Depth>\n : never;\n\ntype AllHelper<\n Parent extends GroupSpec.AnyWithProps,\n Groups_ extends GroupSpec.AnyWithProps,\n Depth extends 1[] = [],\n> = Groups_ extends GroupSpec.AnyWithProps\n ? `${GroupSpec.Name<Parent>}.${All<Groups_, [...Depth, 1]>}`\n : never;\n\n/**\n * Recursively extracts the group at the given dot-separated path. Path must\n * match the format defined in `Path` above, e.g. \"group\" or \"group.subgroup\".\n *\n * @example\n * type G = WithPath<RootGroup, \"group.subgroup\">;\n */\nexport type GroupAt<\n Group,\n Path extends string,\n> = Group extends GroupSpec.AnyWithProps\n ? Path extends `${infer Head}.${infer Tail}`\n ? Group extends { readonly name: Head }\n ? GroupAt<GroupSpec.Groups<Group>, Tail>\n : never\n : GroupSpec.WithName<Group, Path>\n : never;\n\nexport type SubGroupsAt<\n Group extends GroupSpec.AnyWithProps,\n GroupPath extends string,\n> =\n GroupSpec.Groups<GroupAt<Group, GroupPath>> extends infer SubGroups\n ? SubGroups extends GroupSpec.AnyWithProps\n ? `${GroupPath}.${GroupSpec.Name<SubGroups>}`\n : never\n : never;\n"],"mappings":""}
@@ -1,9 +1,12 @@
1
+ import * as MiddlewareAttachment from "./MiddlewareAttachment";
2
+ import * as Result from "effect/Result";
1
3
  import type * as FunctionSpec from "./FunctionSpec";
4
+ import type * as MiddlewareSpec from "./MiddlewareSpec";
2
5
  import type * as RuntimeAndFunctionType from "./RuntimeAndFunctionType";
3
- export declare const TypeId = "@confect/core/GroupSpec";
6
+ export declare const TypeId = "~@confect/core/GroupSpec";
4
7
  export type TypeId = typeof TypeId;
5
8
  export declare const isGroupSpec: (u: unknown) => u is AnyWithProps;
6
- export interface GroupSpec<Runtime extends RuntimeAndFunctionType.Runtime, Name_ extends string, Functions_ extends FunctionSpec.AnyWithPropsWithRuntime<Runtime> = never, Groups_ extends AnyWithProps = never> {
9
+ export interface GroupSpec<Runtime extends RuntimeAndFunctionType.Runtime, Name_ extends string, Functions_ extends FunctionSpec.AnyWithPropsWithRuntime<Runtime> = never, Groups_ extends AnyWithProps = never, MiddlewareSpecs_ extends MiddlewareSpec.AnyMiddlewareSpec = never> {
7
10
  readonly [TypeId]: TypeId;
8
11
  readonly runtime: Runtime;
9
12
  readonly name: Name_;
@@ -13,34 +16,44 @@ export interface GroupSpec<Runtime extends RuntimeAndFunctionType.Runtime, Name_
13
16
  readonly groups: {
14
17
  [GroupName in Name<Groups_>]: WithName<Groups_, GroupName>;
15
18
  };
16
- addFunction<Function extends FunctionSpec.AnyWithPropsWithRuntime<Runtime>>(function_: Function): GroupSpec<Runtime, Name_, Functions_ | Function, Groups_>;
17
- addGroup<Group extends AnyWithProps>(group: Group): GroupSpec<Runtime, Name_, Functions_, Groups_ | Group>;
18
- addGroupAt<const AtName extends string, Group extends AnyWithProps>(name: AtName, group: Group): GroupSpec<Runtime, Name_, Functions_, Groups_ | NamedAt<Group, AtName>>;
19
+ readonly middlewareSpecs: ReadonlyArray<MiddlewareSpecs_>;
20
+ readonly middlewareAttachments: ReadonlyArray<MiddlewareAttachment.MiddlewareAttachment<MiddlewareSpecs_>>;
21
+ readonly "~Functions": Functions_;
22
+ readonly "~Groups": Groups_;
23
+ addFunction<Function extends FunctionSpec.AnyWithPropsWithRuntime<Runtime>>(function_: Function & MiddlewareSpec.ValidateAddedFunction<Function, MiddlewareSpecs_>): GroupSpec<Runtime, Name_, Functions_ | Function, Groups_, MiddlewareSpecs_>;
24
+ addGroup<Group extends AnyWithProps>(group: Group): GroupSpec<Runtime, Name_, Functions_, Groups_ | Group, MiddlewareSpecs_>;
25
+ addGroupAt<const AtName extends string, Group extends AnyWithProps>(name: AtName, group: Group): GroupSpec<Runtime, Name_, Functions_, Groups_ | NamedAt<Group, AtName>, MiddlewareSpecs_>;
26
+ middleware<MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec>(middlewareSpec: MiddlewareSpec_ & MiddlewareSpec.ValidateAttach<MiddlewareSpec_, Functions_, MiddlewareSpecs_>, ...options: MiddlewareAttachment.Args<NoInfer<MiddlewareSpec_>>): GroupSpec<Runtime, Name_, Functions_, Groups_, MiddlewareSpecs_ | MiddlewareSpec_>;
19
27
  }
20
28
  export interface Any {
21
29
  readonly [TypeId]: TypeId;
22
30
  }
23
- export interface AnyWithProps extends GroupSpec<RuntimeAndFunctionType.Runtime, string, FunctionSpec.AnyWithProps, AnyWithProps> {
31
+ export interface AnyWithProps extends GroupSpec<RuntimeAndFunctionType.Runtime, string, FunctionSpec.AnyWithProps, AnyWithProps, MiddlewareSpec.AnyMiddlewareSpec> {
24
32
  }
25
- export interface AnyWithPropsWithRuntime<Runtime extends RuntimeAndFunctionType.Runtime> extends GroupSpec<Runtime, string, FunctionSpec.AnyWithPropsWithRuntime<Runtime>, AnyWithPropsWithRuntime<Runtime>> {
33
+ export interface AnyWithPropsWithRuntime<Runtime extends RuntimeAndFunctionType.Runtime> extends GroupSpec<Runtime, string, FunctionSpec.AnyWithPropsWithRuntime<Runtime>, AnyWithPropsWithRuntime<Runtime>, MiddlewareSpec.AnyMiddlewareSpec> {
26
34
  }
27
35
  export type Name<Group extends AnyWithProps> = Group["name"];
28
- export type Functions<Group extends AnyWithProps> = Group["functions"][keyof Group["functions"]];
29
- export type Groups<Group extends AnyWithProps> = Group["groups"][keyof Group["groups"]];
36
+ export type Functions<Group extends AnyWithProps> = Group["~Functions"];
37
+ export type Groups<Group extends AnyWithProps> = Group["~Groups"];
38
+ export type MiddlewareSpecs<Group extends AnyWithProps> = Group["middlewareSpecs"][number];
30
39
  export type GroupNames<Group extends AnyWithProps> = [Groups<Group>] extends [
31
40
  never
32
41
  ] ? never : Name<Groups<Group>>;
33
42
  export type WithName<Group extends AnyWithProps, Name_ extends Name<Group>> = Extract<Group, {
34
43
  readonly name: Name_;
35
44
  }>;
36
- /** Assigns a segment name to a leaf group created with {@link make} for typing and refs. */
45
+ /**
46
+ * Assigns a segment name to a leaf group created with {@link make} for typing
47
+ * and refs.
48
+ */
37
49
  export type NamedAt<Group extends Any, Name_ extends string> = Omit<Group, "name"> & {
38
50
  readonly name: Name_;
39
51
  };
40
- export type AddGroups<Group extends AnyWithProps, ExtraGroups extends AnyWithProps> = Group extends GroupSpec<infer Runtime, infer Name_, infer Functions_, infer Groups_> ? GroupSpec<Runtime, Name_, Functions_, Groups_ | ExtraGroups> : never;
52
+ export type AddGroups<Group extends AnyWithProps, ExtraGroups extends AnyWithProps> = Group extends GroupSpec<infer Runtime, infer Name_, infer Functions_, infer Groups_, infer MiddlewareSpecs_> ? GroupSpec<Runtime, Name_, Functions_, Groups_ | ExtraGroups, MiddlewareSpecs_> : never;
41
53
  export declare const make: () => GroupSpec<"Convex", "">;
42
54
  export declare const makeAt: <const Name_ extends string>(name: Name_) => GroupSpec<"Convex", Name_>;
43
55
  export declare const makeNode: () => GroupSpec<"Node", "">;
44
56
  export declare const makeNodeAt: <const Name_ extends string>(name: Name_) => GroupSpec<"Node", Name_>;
45
- export declare const withName: <const Name_ extends string>(name: Name_, group: Any) => AnyWithProps;
57
+ export declare function withName<const Name_ extends string, Group extends Any>(name: Name_, group: Group): NamedAt<Group, Name_>;
58
+ export declare const validateMiddleware: (group: AnyWithProps) => Result.Result<void, MiddlewareAttachment.ValidationError>;
46
59
  //# sourceMappingURL=GroupSpec.d.ts.map
@@ -1 +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;IACF,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,SAAS,CACnB,KAAK,SAAS,YAAY,EAC1B,WAAW,SAAS,YAAY,IAEhC,KAAK,SAAS,SAAS,CACrB,MAAM,OAAO,EACb,MAAM,KAAK,EACX,MAAM,UAAU,EAChB,MAAM,OAAO,EACb,MAAM,gBAAgB,CACvB,GACG,SAAS,CACP,OAAO,EACP,KAAK,EACL,UAAU,EACV,OAAO,GAAG,WAAW,EACrB,gBAAgB,CACjB,GACD,KAAK,CAAC;AAoJZ,eAAO,MAAM,IAAI,QAAO,SAAS,CAAC,QAAQ,EAAE,EAAE,CAO1C,CAAC;AAEL,eAAO,MAAM,MAAM,GAAI,KAAK,CAAC,KAAK,SAAS,MAAM,QACzC,KAAK,KACV,SAAS,CAAC,QAAQ,EAAE,KAAK,CAU3B,CAAC;AAEF,eAAO,MAAM,QAAQ,QAAO,SAAS,CAAC,MAAM,EAAE,EAAE,CAO5C,CAAC;AAEL,eAAO,MAAM,UAAU,GAAI,KAAK,CAAC,KAAK,SAAS,MAAM,QAC7C,KAAK,KACV,SAAS,CAAC,MAAM,EAAE,KAAK,CAUzB,CAAC;AAEF,wBAAgB,QAAQ,CAAC,KAAK,CAAC,KAAK,SAAS,MAAM,EAAE,KAAK,SAAS,GAAG,EACpE,IAAI,EAAE,KAAK,EACX,KAAK,EAAE,KAAK,GACX,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAkBzB,eAAO,MAAM,kBAAkB,UACtB,YAAY,KAClB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,oBAAoB,CAAC,eAAe,CAcvD,CAAC"}
package/dist/GroupSpec.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
2
  import { validateConfectFunctionIdentifier } from "./Identifier.js";
3
+ import { validateAll } from "./MiddlewareAttachment.js";
3
4
  import * as Predicate from "effect/Predicate";
5
+ import * as Result from "effect/Result";
4
6
  import * as Record from "effect/Record";
5
7
  //#region src/GroupSpec.ts
6
8
  var GroupSpec_exports = /* @__PURE__ */ __exportAll({
@@ -10,19 +12,26 @@ var GroupSpec_exports = /* @__PURE__ */ __exportAll({
10
12
  makeAt: () => makeAt,
11
13
  makeNode: () => makeNode,
12
14
  makeNodeAt: () => makeNodeAt,
15
+ validateMiddleware: () => validateMiddleware,
13
16
  withName: () => withName
14
17
  });
15
- const TypeId = "@confect/core/GroupSpec";
18
+ const TypeId = "~@confect/core/GroupSpec";
16
19
  const isGroupSpec = (u) => Predicate.hasProperty(u, TypeId);
17
20
  const Proto = {
18
21
  [TypeId]: TypeId,
22
+ get middlewareSpecs() {
23
+ return this.middlewareAttachments.map(({ spec }) => spec);
24
+ },
19
25
  addFunction(function_) {
20
26
  const this_ = this;
27
+ const overlapping = function_.middlewareAttachments.find(({ spec: functionMiddlewareSpec }) => !("options" in functionMiddlewareSpec) && this_.middlewareAttachments.some(({ spec: groupMiddlewareSpec }) => groupMiddlewareSpec.key === functionMiddlewareSpec.key));
28
+ if (overlapping !== void 0) throw new Error(`Middleware "${overlapping.spec.key}" is attached to both function "${function_.name}" and its group`);
21
29
  return makeProto({
22
30
  runtime: this_.runtime,
23
31
  name: this_.name,
24
32
  functions: Record.set(this_.functions, function_.name, function_),
25
- groups: this_.groups
33
+ groups: this_.groups,
34
+ middlewareAttachments: this_.middlewareAttachments
26
35
  });
27
36
  },
28
37
  addGroup(group) {
@@ -32,7 +41,8 @@ const Proto = {
32
41
  runtime: this_.runtime,
33
42
  name: this_.name,
34
43
  functions: this_.functions,
35
- groups: Record.set(this_.groups, group_.name, group_)
44
+ groups: Record.set(this_.groups, group_.name, group_),
45
+ middlewareAttachments: this_.middlewareAttachments
36
46
  });
37
47
  },
38
48
  addGroupAt(name, group) {
@@ -42,21 +52,39 @@ const Proto = {
42
52
  runtime: this_.runtime,
43
53
  name: this_.name,
44
54
  functions: this_.functions,
45
- groups: Record.set(this_.groups, name, withName(name, group_))
55
+ groups: Record.set(this_.groups, name, withName(name, group_)),
56
+ middlewareAttachments: this_.middlewareAttachments
57
+ });
58
+ },
59
+ middleware(middlewareSpec, ...options) {
60
+ const this_ = this;
61
+ if (!("options" in middlewareSpec) && this_.middlewareAttachments.some(({ spec }) => spec.key === middlewareSpec.key)) throw new Error(`Middleware "${middlewareSpec.key}" is already attached to this group`);
62
+ for (const function_ of Object.values(this_.functions)) if (!("options" in middlewareSpec) && function_.middlewareAttachments.some(({ spec }) => spec.key === middlewareSpec.key)) throw new Error(`Middleware "${middlewareSpec.key}" is attached to both function "${function_.name}" and its group`);
63
+ return makeProto({
64
+ runtime: this_.runtime,
65
+ name: this_.name,
66
+ functions: this_.functions,
67
+ groups: this_.groups,
68
+ middlewareAttachments: [...this_.middlewareAttachments, {
69
+ spec: middlewareSpec,
70
+ options: options[0]
71
+ }]
46
72
  });
47
73
  }
48
74
  };
49
- const makeProto = ({ runtime, name, functions, groups }) => Object.assign(Object.create(Proto), {
75
+ const makeProto = ({ runtime, name, functions, groups, middlewareAttachments }) => Object.assign(Object.create(Proto), {
50
76
  runtime,
51
77
  name,
52
78
  functions,
53
- groups
79
+ groups,
80
+ middlewareAttachments
54
81
  });
55
82
  const make = () => makeProto({
56
83
  runtime: "Convex",
57
84
  name: "",
58
85
  functions: Record.empty(),
59
- groups: Record.empty()
86
+ groups: Record.empty(),
87
+ middlewareAttachments: []
60
88
  });
61
89
  const makeAt = (name) => {
62
90
  validateConfectFunctionIdentifier(name);
@@ -64,14 +92,16 @@ const makeAt = (name) => {
64
92
  runtime: "Convex",
65
93
  name,
66
94
  functions: Record.empty(),
67
- groups: Record.empty()
95
+ groups: Record.empty(),
96
+ middlewareAttachments: []
68
97
  });
69
98
  };
70
99
  const makeNode = () => makeProto({
71
100
  runtime: "Node",
72
101
  name: "",
73
102
  functions: Record.empty(),
74
- groups: Record.empty()
103
+ groups: Record.empty(),
104
+ middlewareAttachments: []
75
105
  });
76
106
  const makeNodeAt = (name) => {
77
107
  validateConfectFunctionIdentifier(name);
@@ -79,10 +109,11 @@ const makeNodeAt = (name) => {
79
109
  runtime: "Node",
80
110
  name,
81
111
  functions: Record.empty(),
82
- groups: Record.empty()
112
+ groups: Record.empty(),
113
+ middlewareAttachments: []
83
114
  });
84
115
  };
85
- const withName = (name, group) => {
116
+ function withName(name, group) {
86
117
  validateConfectFunctionIdentifier(name);
87
118
  const group_ = group;
88
119
  if (group_.name === name) return group_;
@@ -90,10 +121,16 @@ const withName = (name, group) => {
90
121
  runtime: group_.runtime,
91
122
  name,
92
123
  functions: group_.functions,
93
- groups: group_.groups
124
+ groups: group_.groups,
125
+ middlewareAttachments: group_.middlewareAttachments
94
126
  });
95
- };
127
+ }
128
+ const validateMiddleware = (group) => Result.gen(function* () {
129
+ yield* validateAll(group.middlewareAttachments, `group "${group.name}"`);
130
+ for (const function_ of Object.values(group.functions)) yield* validateAll([...group.middlewareAttachments, ...function_.middlewareAttachments], `function "${function_.name}"`);
131
+ for (const child of Object.values(group.groups)) yield* validateMiddleware(child);
132
+ });
96
133
  //#endregion
97
- export { GroupSpec_exports, TypeId, isGroupSpec, make, makeAt, makeNode, makeNodeAt, withName };
134
+ export { GroupSpec_exports, TypeId, isGroupSpec, make, makeAt, makeNode, makeNodeAt, validateMiddleware, withName };
98
135
 
99
136
  //# sourceMappingURL=GroupSpec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"GroupSpec.js","names":[],"sources":["../src/GroupSpec.ts"],"sourcesContent":["import * as Predicate from \"effect/Predicate\";\nimport * as Record from \"effect/Record\";\nimport type * as FunctionSpec from \"./FunctionSpec\";\nimport type * as RuntimeAndFunctionType from \"./RuntimeAndFunctionType\";\nimport { validateConfectFunctionIdentifier } from \"./Identifier\";\n\nexport const TypeId = \"@confect/core/GroupSpec\";\nexport type TypeId = typeof TypeId;\n\nexport const isGroupSpec = (u: unknown): u is AnyWithProps =>\n Predicate.hasProperty(u, TypeId);\n\nexport interface GroupSpec<\n Runtime extends RuntimeAndFunctionType.Runtime,\n Name_ extends string,\n Functions_ extends FunctionSpec.AnyWithPropsWithRuntime<Runtime> = never,\n // Subgroups may be of any runtime, independent of this group's own runtime: a\n // group is only a namespace for its children, which are otherwise-independent\n // modules. Functions, by contrast, stay homogeneous (a Node group only accepts\n // Node actions) — `addFunction` keeps the `<Runtime>` bound below.\n Groups_ extends AnyWithProps = never,\n> {\n readonly [TypeId]: TypeId;\n readonly runtime: Runtime;\n readonly name: Name_;\n readonly functions: {\n [FunctionName in FunctionSpec.Name<\n FunctionSpec.AnyWithPropsWithRuntime<Runtime>\n >]: FunctionSpec.WithName<Functions_, FunctionName>;\n };\n readonly groups: {\n [GroupName in Name<Groups_>]: WithName<Groups_, GroupName>;\n };\n\n addFunction<Function extends FunctionSpec.AnyWithPropsWithRuntime<Runtime>>(\n function_: Function,\n ): GroupSpec<Runtime, Name_, Functions_ | Function, Groups_>;\n\n addGroup<Group extends AnyWithProps>(\n group: Group,\n ): GroupSpec<Runtime, Name_, Functions_, Groups_ | Group>;\n\n addGroupAt<const AtName extends string, Group extends AnyWithProps>(\n name: AtName,\n group: Group,\n ): GroupSpec<Runtime, Name_, Functions_, Groups_ | NamedAt<Group, AtName>>;\n}\n\nexport interface Any {\n readonly [TypeId]: TypeId;\n}\n\nexport interface AnyWithProps extends GroupSpec<\n RuntimeAndFunctionType.Runtime,\n string,\n FunctionSpec.AnyWithProps,\n AnyWithProps\n> {}\n\nexport interface AnyWithPropsWithRuntime<\n Runtime extends RuntimeAndFunctionType.Runtime,\n> extends GroupSpec<\n Runtime,\n string,\n FunctionSpec.AnyWithPropsWithRuntime<Runtime>,\n AnyWithPropsWithRuntime<Runtime>\n> {}\n\nexport type Name<Group extends AnyWithProps> = Group[\"name\"];\n\nexport type Functions<Group extends AnyWithProps> =\n Group[\"functions\"][keyof Group[\"functions\"]];\n\nexport type Groups<Group extends AnyWithProps> =\n Group[\"groups\"][keyof Group[\"groups\"]];\n\nexport type GroupNames<Group extends AnyWithProps> = [Groups<Group>] extends [\n never,\n]\n ? never\n : Name<Groups<Group>>;\n\nexport type WithName<\n Group extends AnyWithProps,\n Name_ extends Name<Group>,\n> = Extract<Group, { readonly name: Name_ }>;\n\n/** Assigns a segment name to a leaf group created with {@link make} for typing and refs. */\nexport type NamedAt<Group extends Any, Name_ extends string> = Omit<\n Group,\n \"name\"\n> & {\n readonly name: Name_;\n};\n\nexport type AddGroups<\n Group extends AnyWithProps,\n ExtraGroups extends AnyWithProps,\n> =\n Group extends GroupSpec<\n infer Runtime,\n infer Name_,\n infer Functions_,\n infer Groups_\n >\n ? GroupSpec<Runtime, Name_, Functions_, Groups_ | ExtraGroups>\n : never;\n\nconst Proto = {\n [TypeId]: TypeId,\n\n addFunction<Function extends FunctionSpec.AnyWithProps>(\n this: Any,\n function_: Function,\n ) {\n const this_ = this as AnyWithProps;\n\n return makeProto({\n runtime: this_.runtime,\n name: this_.name,\n functions: Record.set(this_.functions, function_.name, function_),\n groups: this_.groups,\n });\n },\n\n addGroup<Group extends Any>(this: Any, group: Group) {\n const this_ = this as AnyWithProps;\n const group_ = group as unknown as AnyWithProps;\n\n return makeProto({\n runtime: this_.runtime,\n name: this_.name,\n functions: this_.functions,\n groups: Record.set(this_.groups, group_.name, group_),\n });\n },\n\n addGroupAt<Group extends Any>(this: Any, name: string, group: Group) {\n const this_ = this as AnyWithProps;\n const group_ = group as unknown as AnyWithProps;\n\n return makeProto({\n runtime: this_.runtime,\n name: this_.name,\n functions: this_.functions,\n groups: Record.set(this_.groups, name, withName(name, group_)),\n });\n },\n};\n\nconst makeProto = <\n Runtime extends RuntimeAndFunctionType.Runtime,\n Name_ extends string,\n Functions_ extends FunctionSpec.AnyWithPropsWithRuntime<Runtime>,\n Groups_ extends AnyWithPropsWithRuntime<Runtime>,\n>({\n runtime,\n name,\n functions,\n groups,\n}: {\n runtime: Runtime;\n name: Name_;\n functions: Record.ReadonlyRecord<string, Functions_>;\n groups: Record.ReadonlyRecord<string, Groups_>;\n}): GroupSpec<Runtime, Name_, Functions_, Groups_> =>\n Object.assign(Object.create(Proto), {\n runtime,\n name,\n functions,\n groups,\n });\n\nexport const make = (): GroupSpec<\"Convex\", \"\"> =>\n makeProto({\n runtime: \"Convex\",\n name: \"\",\n functions: Record.empty(),\n groups: Record.empty(),\n });\n\nexport const makeAt = <const Name_ extends string>(\n name: Name_,\n): GroupSpec<\"Convex\", Name_> => {\n validateConfectFunctionIdentifier(name);\n\n return makeProto({\n runtime: \"Convex\",\n name,\n functions: Record.empty(),\n groups: Record.empty(),\n });\n};\n\nexport const makeNode = (): GroupSpec<\"Node\", \"\"> =>\n makeProto({\n runtime: \"Node\",\n name: \"\",\n functions: Record.empty(),\n groups: Record.empty(),\n });\n\nexport const makeNodeAt = <const Name_ extends string>(\n name: Name_,\n): GroupSpec<\"Node\", Name_> => {\n validateConfectFunctionIdentifier(name);\n\n return makeProto({\n runtime: \"Node\",\n name,\n functions: Record.empty(),\n groups: Record.empty(),\n });\n};\n\nexport const withName = <const Name_ extends string>(\n name: Name_,\n group: Any,\n): AnyWithProps => {\n validateConfectFunctionIdentifier(name);\n const group_ = group as AnyWithProps;\n\n if (group_.name === name) {\n return group_;\n }\n\n return makeProto({\n runtime: group_.runtime,\n name,\n functions: group_.functions,\n groups: group_.groups,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;AAMA,MAAa,SAAS;AAGtB,MAAa,eAAe,MAC1B,UAAU,YAAY,GAAG,MAAM;AAkGjC,MAAM,QAAQ;EACX,SAAS;CAEV,YAEE,WACA;EACA,MAAM,QAAQ;EAEd,OAAO,UAAU;GACf,SAAS,MAAM;GACf,MAAM,MAAM;GACZ,WAAW,OAAO,IAAI,MAAM,WAAW,UAAU,MAAM,SAAS;GAChE,QAAQ,MAAM;EAChB,CAAC;CACH;CAEA,SAAuC,OAAc;EACnD,MAAM,QAAQ;EACd,MAAM,SAAS;EAEf,OAAO,UAAU;GACf,SAAS,MAAM;GACf,MAAM,MAAM;GACZ,WAAW,MAAM;GACjB,QAAQ,OAAO,IAAI,MAAM,QAAQ,OAAO,MAAM,MAAM;EACtD,CAAC;CACH;CAEA,WAAyC,MAAc,OAAc;EACnE,MAAM,QAAQ;EACd,MAAM,SAAS;EAEf,OAAO,UAAU;GACf,SAAS,MAAM;GACf,MAAM,MAAM;GACZ,WAAW,MAAM;GACjB,QAAQ,OAAO,IAAI,MAAM,QAAQ,MAAM,SAAS,MAAM,MAAM,CAAC;EAC/D,CAAC;CACH;AACF;AAEA,MAAM,aAKJ,EACA,SACA,MACA,WACA,aAOA,OAAO,OAAO,OAAO,OAAO,KAAK,GAAG;CAClC;CACA;CACA;CACA;AACF,CAAC;AAEH,MAAa,aACX,UAAU;CACR,SAAS;CACT,MAAM;CACN,WAAW,OAAO,MAAM;CACxB,QAAQ,OAAO,MAAM;AACvB,CAAC;AAEH,MAAa,UACX,SAC+B;CAC/B,kCAAkC,IAAI;CAEtC,OAAO,UAAU;EACf,SAAS;EACT;EACA,WAAW,OAAO,MAAM;EACxB,QAAQ,OAAO,MAAM;CACvB,CAAC;AACH;AAEA,MAAa,iBACX,UAAU;CACR,SAAS;CACT,MAAM;CACN,WAAW,OAAO,MAAM;CACxB,QAAQ,OAAO,MAAM;AACvB,CAAC;AAEH,MAAa,cACX,SAC6B;CAC7B,kCAAkC,IAAI;CAEtC,OAAO,UAAU;EACf,SAAS;EACT;EACA,WAAW,OAAO,MAAM;EACxB,QAAQ,OAAO,MAAM;CACvB,CAAC;AACH;AAEA,MAAa,YACX,MACA,UACiB;CACjB,kCAAkC,IAAI;CACtC,MAAM,SAAS;CAEf,IAAI,OAAO,SAAS,MAClB,OAAO;CAGT,OAAO,UAAU;EACf,SAAS,OAAO;EAChB;EACA,WAAW,OAAO;EAClB,QAAQ,OAAO;CACjB,CAAC;AACH"}
1
+ {"version":3,"file":"GroupSpec.js","names":["MiddlewareAttachment.validateAll"],"sources":["../src/GroupSpec.ts"],"sourcesContent":["import * as MiddlewareAttachment from \"./MiddlewareAttachment\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Record from \"effect/Record\";\nimport * as Result from \"effect/Result\";\nimport type * as FunctionSpec from \"./FunctionSpec\";\nimport type * as MiddlewareSpec from \"./MiddlewareSpec\";\nimport type * as RuntimeAndFunctionType from \"./RuntimeAndFunctionType\";\nimport { validateConfectFunctionIdentifier } from \"./Identifier\";\n\nexport const TypeId = \"~@confect/core/GroupSpec\";\nexport type TypeId = typeof TypeId;\n\nexport const isGroupSpec = (u: unknown): u is AnyWithProps =>\n Predicate.hasProperty(u, TypeId);\n\nexport interface GroupSpec<\n Runtime extends RuntimeAndFunctionType.Runtime,\n Name_ extends string,\n Functions_ extends FunctionSpec.AnyWithPropsWithRuntime<Runtime> = never,\n // Subgroups may be of any runtime, independent of this group's own runtime: a\n // group is only a namespace for its children, which are otherwise-independent\n // modules. Functions, by contrast, stay homogeneous (a Node group only accepts\n // Node actions)—`addFunction` keeps the `<Runtime>` bound below.\n Groups_ extends AnyWithProps = never,\n MiddlewareSpecs_ extends MiddlewareSpec.AnyMiddlewareSpec = never,\n> {\n readonly [TypeId]: TypeId;\n readonly runtime: Runtime;\n readonly name: Name_;\n readonly functions: {\n [\n FunctionName in FunctionSpec.Name<\n FunctionSpec.AnyWithPropsWithRuntime<Runtime>\n >\n ]: FunctionSpec.WithName<Functions_, FunctionName>;\n };\n readonly groups: {\n [GroupName in Name<Groups_>]: WithName<Groups_, GroupName>;\n };\n readonly middlewareSpecs: ReadonlyArray<MiddlewareSpecs_>;\n readonly middlewareAttachments: ReadonlyArray<\n MiddlewareAttachment.MiddlewareAttachment<MiddlewareSpecs_>\n >;\n readonly \"~Functions\": Functions_;\n readonly \"~Groups\": Groups_;\n\n addFunction<Function extends FunctionSpec.AnyWithPropsWithRuntime<Runtime>>(\n function_: Function &\n MiddlewareSpec.ValidateAddedFunction<Function, MiddlewareSpecs_>,\n ): GroupSpec<\n Runtime,\n Name_,\n Functions_ | Function,\n Groups_,\n MiddlewareSpecs_\n >;\n\n addGroup<Group extends AnyWithProps>(\n group: Group,\n ): GroupSpec<Runtime, Name_, Functions_, Groups_ | Group, MiddlewareSpecs_>;\n\n addGroupAt<const AtName extends string, Group extends AnyWithProps>(\n name: AtName,\n group: Group,\n ): GroupSpec<\n Runtime,\n Name_,\n Functions_,\n Groups_ | NamedAt<Group, AtName>,\n MiddlewareSpecs_\n >;\n\n middleware<MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec>(\n middlewareSpec: MiddlewareSpec_ &\n MiddlewareSpec.ValidateAttach<\n MiddlewareSpec_,\n Functions_,\n MiddlewareSpecs_\n >,\n ...options: MiddlewareAttachment.Args<NoInfer<MiddlewareSpec_>>\n ): GroupSpec<\n Runtime,\n Name_,\n Functions_,\n Groups_,\n MiddlewareSpecs_ | MiddlewareSpec_\n >;\n}\n\nexport interface Any {\n readonly [TypeId]: TypeId;\n}\n\nexport interface AnyWithProps extends GroupSpec<\n RuntimeAndFunctionType.Runtime,\n string,\n FunctionSpec.AnyWithProps,\n AnyWithProps,\n MiddlewareSpec.AnyMiddlewareSpec\n> {}\n\nexport interface AnyWithPropsWithRuntime<\n Runtime extends RuntimeAndFunctionType.Runtime,\n> extends GroupSpec<\n Runtime,\n string,\n FunctionSpec.AnyWithPropsWithRuntime<Runtime>,\n AnyWithPropsWithRuntime<Runtime>,\n MiddlewareSpec.AnyMiddlewareSpec\n> {}\n\nexport type Name<Group extends AnyWithProps> = Group[\"name\"];\n\nexport type Functions<Group extends AnyWithProps> = Group[\"~Functions\"];\n\nexport type Groups<Group extends AnyWithProps> = Group[\"~Groups\"];\n\nexport type MiddlewareSpecs<Group extends AnyWithProps> =\n Group[\"middlewareSpecs\"][number];\n\nexport type GroupNames<Group extends AnyWithProps> = [Groups<Group>] extends [\n never,\n]\n ? never\n : Name<Groups<Group>>;\n\nexport type WithName<\n Group extends AnyWithProps,\n Name_ extends Name<Group>,\n> = Extract<Group, { readonly name: Name_ }>;\n\n/**\n * Assigns a segment name to a leaf group created with {@link make} for typing\n * and refs.\n */\nexport type NamedAt<Group extends Any, Name_ extends string> = Omit<\n Group,\n \"name\"\n> & {\n readonly name: Name_;\n};\n\nexport type AddGroups<\n Group extends AnyWithProps,\n ExtraGroups extends AnyWithProps,\n> =\n Group extends GroupSpec<\n infer Runtime,\n infer Name_,\n infer Functions_,\n infer Groups_,\n infer MiddlewareSpecs_\n >\n ? GroupSpec<\n Runtime,\n Name_,\n Functions_,\n Groups_ | ExtraGroups,\n MiddlewareSpecs_\n >\n : never;\n\nconst Proto = {\n [TypeId]: TypeId,\n\n get middlewareSpecs() {\n return this.middlewareAttachments.map(({ spec }) => spec);\n },\n\n addFunction<Function extends FunctionSpec.AnyWithProps>(\n this: Any,\n function_: Function,\n ) {\n const this_ = this as AnyWithProps;\n\n const overlapping = function_.middlewareAttachments.find(\n ({ spec: functionMiddlewareSpec }) =>\n !(\"options\" in functionMiddlewareSpec) &&\n this_.middlewareAttachments.some(\n ({ spec: groupMiddlewareSpec }) =>\n groupMiddlewareSpec.key === functionMiddlewareSpec.key,\n ),\n );\n if (overlapping !== undefined) {\n throw new Error(\n `Middleware \"${overlapping.spec.key}\" is attached to both function \"${function_.name}\" and its group`,\n );\n }\n\n return makeProto({\n runtime: this_.runtime,\n name: this_.name,\n functions: Record.set(this_.functions, function_.name, function_),\n groups: this_.groups,\n middlewareAttachments: this_.middlewareAttachments,\n });\n },\n\n addGroup<Group extends Any>(this: Any, group: Group) {\n const this_ = this as AnyWithProps;\n const group_ = group as unknown as AnyWithProps;\n\n return makeProto({\n runtime: this_.runtime,\n name: this_.name,\n functions: this_.functions,\n groups: Record.set(this_.groups, group_.name, group_),\n middlewareAttachments: this_.middlewareAttachments,\n });\n },\n\n addGroupAt<Group extends Any>(this: Any, name: string, group: Group) {\n const this_ = this as AnyWithProps;\n const group_ = group as unknown as AnyWithProps;\n\n return makeProto({\n runtime: this_.runtime,\n name: this_.name,\n functions: this_.functions,\n groups: Record.set(this_.groups, name, withName(name, group_)),\n middlewareAttachments: this_.middlewareAttachments,\n });\n },\n\n middleware<MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec>(\n this: Any,\n middlewareSpec: MiddlewareSpec_,\n ...options: ReadonlyArray<unknown>\n ) {\n const this_ = this as AnyWithProps;\n\n if (\n !(\"options\" in middlewareSpec) &&\n this_.middlewareAttachments.some(\n ({ spec }) => spec.key === middlewareSpec.key,\n )\n ) {\n throw new Error(\n `Middleware \"${middlewareSpec.key}\" is already attached to this group`,\n );\n }\n\n for (const function_ of Object.values(this_.functions)) {\n if (\n !(\"options\" in middlewareSpec) &&\n function_.middlewareAttachments.some(\n ({ spec }) => spec.key === middlewareSpec.key,\n )\n ) {\n throw new Error(\n `Middleware \"${middlewareSpec.key}\" is attached to both function \"${function_.name}\" and its group`,\n );\n }\n }\n\n return makeProto({\n runtime: this_.runtime,\n name: this_.name,\n functions: this_.functions,\n groups: this_.groups,\n middlewareAttachments: [\n ...this_.middlewareAttachments,\n { spec: middlewareSpec, options: options[0] },\n ],\n });\n },\n} satisfies ThisType<AnyWithProps>;\n\nconst makeProto = <\n Runtime extends RuntimeAndFunctionType.Runtime,\n Name_ extends string,\n Functions_ extends FunctionSpec.AnyWithPropsWithRuntime<Runtime>,\n Groups_ extends AnyWithPropsWithRuntime<Runtime>,\n MiddlewareAttachments_ extends\n ReadonlyArray<MiddlewareAttachment.MiddlewareAttachment>,\n>({\n runtime,\n name,\n functions,\n groups,\n middlewareAttachments,\n}: {\n runtime: Runtime;\n name: Name_;\n functions: Record.ReadonlyRecord<string, Functions_>;\n groups: Record.ReadonlyRecord<string, Groups_>;\n middlewareAttachments: MiddlewareAttachments_;\n}): GroupSpec<\n Runtime,\n Name_,\n Functions_,\n Groups_,\n MiddlewareAttachments_[number][\"spec\"]\n> =>\n Object.assign(Object.create(Proto), {\n runtime,\n name,\n functions,\n groups,\n middlewareAttachments,\n }) as GroupSpec<\n Runtime,\n Name_,\n Functions_,\n Groups_,\n MiddlewareAttachments_[number][\"spec\"]\n >;\n\nexport const make = (): GroupSpec<\"Convex\", \"\"> =>\n makeProto({\n runtime: \"Convex\",\n name: \"\",\n functions: Record.empty(),\n groups: Record.empty(),\n middlewareAttachments: [],\n });\n\nexport const makeAt = <const Name_ extends string>(\n name: Name_,\n): GroupSpec<\"Convex\", Name_> => {\n validateConfectFunctionIdentifier(name);\n\n return makeProto({\n runtime: \"Convex\",\n name,\n functions: Record.empty(),\n groups: Record.empty(),\n middlewareAttachments: [],\n });\n};\n\nexport const makeNode = (): GroupSpec<\"Node\", \"\"> =>\n makeProto({\n runtime: \"Node\",\n name: \"\",\n functions: Record.empty(),\n groups: Record.empty(),\n middlewareAttachments: [],\n });\n\nexport const makeNodeAt = <const Name_ extends string>(\n name: Name_,\n): GroupSpec<\"Node\", Name_> => {\n validateConfectFunctionIdentifier(name);\n\n return makeProto({\n runtime: \"Node\",\n name,\n functions: Record.empty(),\n groups: Record.empty(),\n middlewareAttachments: [],\n });\n};\n\nexport function withName<const Name_ extends string, Group extends Any>(\n name: Name_,\n group: Group,\n): NamedAt<Group, Name_>;\nexport function withName(name: string, group: Any): AnyWithProps {\n validateConfectFunctionIdentifier(name);\n const group_ = group as AnyWithProps;\n\n if (group_.name === name) {\n return group_;\n }\n\n return makeProto({\n runtime: group_.runtime,\n name,\n functions: group_.functions,\n groups: group_.groups,\n middlewareAttachments: group_.middlewareAttachments,\n });\n}\n\nexport const validateMiddleware = (\n group: AnyWithProps,\n): Result.Result<void, MiddlewareAttachment.ValidationError> =>\n Result.gen(function* () {\n yield* MiddlewareAttachment.validateAll(\n group.middlewareAttachments,\n `group \"${group.name}\"`,\n );\n for (const function_ of Object.values(group.functions)) {\n yield* MiddlewareAttachment.validateAll(\n [...group.middlewareAttachments, ...function_.middlewareAttachments],\n `function \"${function_.name}\"`,\n );\n }\n for (const child of Object.values(group.groups))\n yield* validateMiddleware(child);\n });\n"],"mappings":";;;;;;;;;;;;;;;;;AASA,MAAa,SAAS;AAGtB,MAAa,eAAe,MAC1B,UAAU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S,OAAO;EAChB;EACA,WAAW,OAAO;EAClB,QAAQ,OAAO;EACf,uBAAuB,OAAO;CAChC,CAAC;AACH;AAEA,MAAa,sBACX,UAEA,OAAO,IAAI,aAAa;CACtB,OAAOA,YACL,MAAM,uBACN,UAAU,MAAM,KAAK,EACvB;CACA,KAAK,MAAM,aAAa,OAAO,OAAO,MAAM,SAAS,GACnD,OAAOA,YACL,CAAC,GAAG,MAAM,uBAAuB,GAAG,UAAU,qBAAqB,GACnE,aAAa,UAAU,KAAK,EAC9B;CAEF,KAAK,MAAM,SAAS,OAAO,OAAO,MAAM,MAAM,GAC5C,OAAO,mBAAmB,KAAK;AACnC,CAAC"}
@@ -1,14 +1,15 @@
1
1
  export declare const validateConfectFunctionIdentifier: (identifier: string) => void;
2
2
  /**
3
- * Validate that `identifier` is suitable as a Convex table name (and, equivalently,
4
- * as a `confect/tables/<identifier>.ts` filename).
3
+ * Validate that `identifier` is suitable as a Convex table name (and,
4
+ * equivalently, as a `confect/tables/<identifier>.ts` filename).
5
5
  *
6
6
  * Rules:
7
- * - Must match `/^[A-Za-z][A-Za-z0-9_]*$/` — letter-leading, alphanumeric plus
7
+ *
8
+ * - Must match `/^[A-Za-z][A-Za-z0-9_]*$/`—letter-leading, alphanumeric plus
8
9
  * underscore. No `$` (not a valid Convex table name character); no leading
9
10
  * `_` (Convex reserves `_<name>` for its system tables).
10
- * - Must not be a reserved JavaScript identifier, so the name can also be used
11
- * as a binding name in generated code without escaping.
11
+ * - Must not be a reserved JavaScript identifier, so the name can also be used as
12
+ * a binding name in generated code without escaping.
12
13
  */
13
14
  export declare const validateConfectTableIdentifier: (identifier: string) => void;
14
15
  //# sourceMappingURL=Identifier.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Identifier.d.ts","sourceRoot":"","sources":["../src/Identifier.ts"],"names":[],"mappings":"AA4EA,eAAO,MAAM,iCAAiC,GAAI,YAAY,MAAM,SAkBnE,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,8BAA8B,GAAI,YAAY,MAAM,SAYhE,CAAC"}
1
+ {"version":3,"file":"Identifier.d.ts","sourceRoot":"","sources":["../src/Identifier.ts"],"names":[],"mappings":"AA4EA,eAAO,MAAM,iCAAiC,eAAgB,MAAM,SAkBnE,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,8BAA8B,eAAgB,MAAM,SAYhE,CAAC"}
@@ -70,15 +70,16 @@ const validateConfectFunctionIdentifier = (identifier) => {
70
70
  if (isReservedConvexFileName(identifier)) throw new Error(`Expected a valid Confect function identifier, but received: "${identifier}". "${identifier}" is a reserved Convex file name.`);
71
71
  };
72
72
  /**
73
- * Validate that `identifier` is suitable as a Convex table name (and, equivalently,
74
- * as a `confect/tables/<identifier>.ts` filename).
73
+ * Validate that `identifier` is suitable as a Convex table name (and,
74
+ * equivalently, as a `confect/tables/<identifier>.ts` filename).
75
75
  *
76
76
  * Rules:
77
- * - Must match `/^[A-Za-z][A-Za-z0-9_]*$/` — letter-leading, alphanumeric plus
77
+ *
78
+ * - Must match `/^[A-Za-z][A-Za-z0-9_]*$/`—letter-leading, alphanumeric plus
78
79
  * underscore. No `$` (not a valid Convex table name character); no leading
79
80
  * `_` (Convex reserves `_<name>` for its system tables).
80
- * - Must not be a reserved JavaScript identifier, so the name can also be used
81
- * as a binding name in generated code without escaping.
81
+ * - Must not be a reserved JavaScript identifier, so the name can also be used as
82
+ * a binding name in generated code without escaping.
82
83
  */
83
84
  const validateConfectTableIdentifier = (identifier) => {
84
85
  if (!matchesTableNamePattern(identifier)) throw new Error(`Expected a valid Confect table identifier, but received: "${identifier}". Valid table identifiers must start with a letter and can only contain letters, numbers, and underscores. Leading underscores are reserved for Convex system tables.`);