@gaganref/confect-server 10.3.1-fork.9 → 10.3.1-fork.91

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 (183) hide show
  1. package/dist/ActionCall.d.ts +30 -0
  2. package/dist/ActionCall.d.ts.map +1 -0
  3. package/dist/ActionCall.js +41 -0
  4. package/dist/ActionCall.js.map +1 -0
  5. package/dist/ActionRunner.d.ts +1 -1
  6. package/dist/ActionRunner.d.ts.map +1 -1
  7. package/dist/ActionRunner.js +3 -3
  8. package/dist/ActionRunner.js.map +1 -1
  9. package/dist/AiGatewayDecisionClient.js +1 -1
  10. package/dist/AiGatewayLanguageClient.js +1 -1
  11. package/dist/Auth.d.ts +31 -2
  12. package/dist/Auth.d.ts.map +1 -1
  13. package/dist/Auth.js +23 -3
  14. package/dist/Auth.js.map +1 -1
  15. package/dist/Callback.d.ts +1 -1
  16. package/dist/Callback.d.ts.map +1 -1
  17. package/dist/Callback.js +6 -6
  18. package/dist/Callback.js.map +1 -1
  19. package/dist/ComponentCtx.d.ts +4 -0
  20. package/dist/ComponentCtx.d.ts.map +1 -1
  21. package/dist/ConvexConfigProvider.js +2 -2
  22. package/dist/ConvexFunctionDefinitions.d.ts.map +1 -1
  23. package/dist/ConvexFunctionDefinitions.js +4 -4
  24. package/dist/ConvexFunctionDefinitions.js.map +1 -1
  25. package/dist/ConvexLogger.js +1 -1
  26. package/dist/CronJobs.d.ts.map +1 -1
  27. package/dist/CronJobs.js +7 -6
  28. package/dist/CronJobs.js.map +1 -1
  29. package/dist/DatabaseSchema.js +2 -2
  30. package/dist/DatabaseWriter.d.ts +44 -2
  31. package/dist/DatabaseWriter.d.ts.map +1 -1
  32. package/dist/DatabaseWriter.js +59 -9
  33. package/dist/DatabaseWriter.js.map +1 -1
  34. package/dist/ExecutionMetadata.js +1 -1
  35. package/dist/FunctionImpl.js +2 -2
  36. package/dist/FunctionRegistryItem.d.ts +1 -0
  37. package/dist/FunctionRegistryItem.d.ts.map +1 -1
  38. package/dist/FunctionRegistryItem.js +2 -1
  39. package/dist/FunctionRegistryItem.js.map +1 -1
  40. package/dist/GroupImpl.d.ts +21 -2
  41. package/dist/GroupImpl.d.ts.map +1 -1
  42. package/dist/GroupImpl.js +21 -22
  43. package/dist/GroupImpl.js.map +1 -1
  44. package/dist/GroupRegistry.d.ts +1 -0
  45. package/dist/GroupRegistry.d.ts.map +1 -1
  46. package/dist/GroupRegistry.js +10 -3
  47. package/dist/GroupRegistry.js.map +1 -1
  48. package/dist/Handler.d.ts +8 -4
  49. package/dist/Handler.d.ts.map +1 -1
  50. package/dist/Handler.js.map +1 -1
  51. package/dist/HttpRouter.d.ts +3 -0
  52. package/dist/HttpRouter.d.ts.map +1 -1
  53. package/dist/HttpRouter.js +29 -10
  54. package/dist/HttpRouter.js.map +1 -1
  55. package/dist/MiddlewareImpl.js +1 -1
  56. package/dist/MountInit.d.ts +31 -0
  57. package/dist/MountInit.d.ts.map +1 -0
  58. package/dist/MountInit.js +49 -0
  59. package/dist/MountInit.js.map +1 -0
  60. package/dist/MutationRunner.d.ts +1 -1
  61. package/dist/MutationRunner.d.ts.map +1 -1
  62. package/dist/MutationRunner.js +3 -3
  63. package/dist/MutationRunner.js.map +1 -1
  64. package/dist/MutationTransactionContext.d.ts.map +1 -1
  65. package/dist/MutationTransactionContext.js +4 -3
  66. package/dist/MutationTransactionContext.js.map +1 -1
  67. package/dist/OfficialComponent.d.ts +60 -0
  68. package/dist/OfficialComponent.d.ts.map +1 -0
  69. package/dist/OfficialComponent.js +72 -0
  70. package/dist/OfficialComponent.js.map +1 -0
  71. package/dist/OrderedQuery.d.ts +4 -5
  72. package/dist/OrderedQuery.d.ts.map +1 -1
  73. package/dist/OrderedQuery.js.map +1 -1
  74. package/dist/QueryInitializer.js +2 -2
  75. package/dist/QueryRunner.js +2 -2
  76. package/dist/QueryStream.d.ts +120 -12
  77. package/dist/QueryStream.d.ts.map +1 -1
  78. package/dist/QueryStream.js +143 -41
  79. package/dist/QueryStream.js.map +1 -1
  80. package/dist/QueryStreamCursor.js +1 -1
  81. package/dist/QueryStreamIndexPrefix.js +1 -1
  82. package/dist/QueryStreamIndexRange.js +2 -2
  83. package/dist/QueryStreamKey.js +1 -1
  84. package/dist/QueryStreamKeyBounds.js +2 -2
  85. package/dist/QueryStreamKeyLayout.js +2 -2
  86. package/dist/QueryStreamKeyValues.js +2 -2
  87. package/dist/QueryStreamPagination.js +1 -1
  88. package/dist/QueryStreamReadBudget.d.ts +3 -2
  89. package/dist/QueryStreamReadBudget.d.ts.map +1 -1
  90. package/dist/QueryStreamReadBudget.js +8 -5
  91. package/dist/QueryStreamReadBudget.js.map +1 -1
  92. package/dist/QueryTransactionContext.js +2 -2
  93. package/dist/RegisteredConvexFunction.d.ts +10 -5
  94. package/dist/RegisteredConvexFunction.d.ts.map +1 -1
  95. package/dist/RegisteredConvexFunction.js +49 -29
  96. package/dist/RegisteredConvexFunction.js.map +1 -1
  97. package/dist/RegisteredFunction.d.ts +48 -22
  98. package/dist/RegisteredFunction.d.ts.map +1 -1
  99. package/dist/RegisteredFunction.js +163 -42
  100. package/dist/RegisteredFunction.js.map +1 -1
  101. package/dist/RegisteredNodeFunction.d.ts +1 -1
  102. package/dist/RegisteredNodeFunction.d.ts.map +1 -1
  103. package/dist/RegisteredNodeFunction.js +10 -6
  104. package/dist/RegisteredNodeFunction.js.map +1 -1
  105. package/dist/RegistryItems.d.ts +7 -0
  106. package/dist/RegistryItems.d.ts.map +1 -1
  107. package/dist/RegistryItems.js +8 -3
  108. package/dist/RegistryItems.js.map +1 -1
  109. package/dist/RequestMetadata.js +1 -1
  110. package/dist/Scheduler.d.ts +1 -1
  111. package/dist/Scheduler.d.ts.map +1 -1
  112. package/dist/Scheduler.js +14 -13
  113. package/dist/Scheduler.js.map +1 -1
  114. package/dist/Storage.js +1 -1
  115. package/dist/StorageActionWriter.js +1 -1
  116. package/dist/StorageReader.js +1 -1
  117. package/dist/StorageWriter.js +1 -1
  118. package/dist/Table.d.ts +6 -6
  119. package/dist/Table.d.ts.map +1 -1
  120. package/dist/TableInfo.d.ts +7 -7
  121. package/dist/TableInfo.d.ts.map +1 -1
  122. package/dist/TableInfo.js.map +1 -1
  123. package/dist/TransactionMetadata.js +1 -1
  124. package/dist/VectorSearch.js +1 -1
  125. package/dist/index.d.ts +3 -0
  126. package/dist/index.d.ts.map +1 -1
  127. package/dist/index.js +21 -18
  128. package/dist/internal/AiGatewayDecisionClient.js +1 -1
  129. package/dist/internal/AiGatewayLanguageClient.js +1 -1
  130. package/dist/internal/AiGatewayServiceToken.js +1 -1
  131. package/dist/internal/DocumentPatch.d.ts +16 -0
  132. package/dist/internal/DocumentPatch.d.ts.map +1 -0
  133. package/dist/internal/DocumentPatch.js +36 -0
  134. package/dist/internal/DocumentPatch.js.map +1 -0
  135. package/dist/internal/httpBody.d.ts +13 -0
  136. package/dist/internal/httpBody.d.ts.map +1 -0
  137. package/dist/internal/httpBody.js +47 -0
  138. package/dist/internal/httpBody.js.map +1 -0
  139. package/dist/internal/httpOptions.d.ts +4 -0
  140. package/dist/internal/httpOptions.d.ts.map +1 -0
  141. package/dist/internal/httpOptions.js +83 -0
  142. package/dist/internal/httpOptions.js.map +1 -0
  143. package/dist/internal/observability.d.ts +5 -0
  144. package/dist/internal/observability.d.ts.map +1 -0
  145. package/dist/internal/observability.js +21 -0
  146. package/dist/internal/observability.js.map +1 -0
  147. package/dist/internal/reservedArgument.d.ts +8 -0
  148. package/dist/internal/reservedArgument.d.ts.map +1 -0
  149. package/dist/internal/reservedArgument.js +30 -0
  150. package/dist/internal/reservedArgument.js.map +1 -0
  151. package/package.json +5 -5
  152. package/src/ActionCall.ts +83 -0
  153. package/src/ActionRunner.ts +3 -2
  154. package/src/Auth.ts +49 -1
  155. package/src/Callback.ts +3 -2
  156. package/src/ComponentCtx.ts +2 -0
  157. package/src/ConvexFunctionDefinitions.ts +2 -1
  158. package/src/CronJobs.ts +2 -1
  159. package/src/DatabaseWriter.ts +190 -26
  160. package/src/FunctionRegistryItem.ts +4 -0
  161. package/src/GroupImpl.ts +61 -8
  162. package/src/GroupRegistry.ts +7 -3
  163. package/src/Handler.ts +21 -5
  164. package/src/HttpRouter.ts +69 -5
  165. package/src/MountInit.ts +80 -0
  166. package/src/MutationRunner.ts +3 -2
  167. package/src/MutationTransactionContext.ts +2 -1
  168. package/src/OfficialComponent.ts +168 -0
  169. package/src/OrderedQuery.ts +4 -5
  170. package/src/QueryStream.ts +391 -61
  171. package/src/QueryStreamReadBudget.ts +19 -6
  172. package/src/RegisteredConvexFunction.ts +39 -2
  173. package/src/RegisteredFunction.ts +305 -49
  174. package/src/RegisteredNodeFunction.ts +11 -1
  175. package/src/RegistryItems.ts +31 -0
  176. package/src/Scheduler.ts +17 -19
  177. package/src/TableInfo.ts +18 -22
  178. package/src/index.ts +3 -0
  179. package/src/internal/DocumentPatch.ts +87 -0
  180. package/src/internal/httpBody.ts +72 -0
  181. package/src/internal/httpOptions.ts +154 -0
  182. package/src/internal/observability.ts +27 -0
  183. package/src/internal/reservedArgument.ts +56 -0
@@ -0,0 +1,80 @@
1
+ import * as Mount from "@confect/core/Mount";
2
+ import { internalMutationGeneric } from "convex/server";
3
+ import * as Cause from "effect/Cause";
4
+ import * as Effect from "effect/Effect";
5
+ import * as Exit from "effect/Exit";
6
+ import * as Option from "effect/Option";
7
+ import * as Callback from "./Callback.js";
8
+
9
+ /**
10
+ * A mount the push visits: its `init`, if its component declares one, and
11
+ * whether its component lists mounts of its own.
12
+ */
13
+ export interface Entry {
14
+ readonly mount: Mount.Any;
15
+ readonly nested: boolean;
16
+ }
17
+
18
+ /**
19
+ * What the push does at one mount, in order. A mount whose callback handles
20
+ * cannot be made ends the list with its failure, so no later mount runs.
21
+ */
22
+ export type Step =
23
+ | {
24
+ readonly componentPath: string;
25
+ readonly nested: boolean;
26
+ readonly init: {
27
+ readonly functionName: string;
28
+ readonly args: unknown;
29
+ } | null;
30
+ }
31
+ | { readonly componentPath: string; readonly failure: string };
32
+
33
+ const failure = (cause: Cause.Cause<unknown>) => {
34
+ const error = Cause.squash(cause);
35
+ return error instanceof Error ? error.message : String(error);
36
+ };
37
+
38
+ const step = (entry: Entry) =>
39
+ Mount.initCall(entry.mount, (contract, ref) =>
40
+ Callback.create(contract, ref as never),
41
+ ).pipe(
42
+ Effect.exit,
43
+ Effect.map((exit): Step =>
44
+ Exit.isSuccess(exit)
45
+ ? {
46
+ componentPath: Mount.data(entry.mount).name,
47
+ nested: entry.nested,
48
+ init: Option.match(exit.value, {
49
+ onNone: () => null,
50
+ onSome: ({ functionName, args }) => ({ functionName, args }),
51
+ }),
52
+ }
53
+ : {
54
+ componentPath: Mount.data(entry.mount).name,
55
+ failure: failure(exit.cause),
56
+ },
57
+ ),
58
+ );
59
+
60
+ /**
61
+ * The internal mutation codegen writes to `convex/confectDeploy.ts`. It makes
62
+ * each mount's callback handles and returns the steps a push runs, in
63
+ * declaration order.
64
+ */
65
+ export const mutation = (entries: ReadonlyArray<Entry>) =>
66
+ internalMutationGeneric({
67
+ args: {},
68
+ handler: () =>
69
+ Effect.runPromise(
70
+ Effect.gen(function* () {
71
+ const steps: Array<Step> = [];
72
+ for (const entry of entries) {
73
+ const next = yield* step(entry);
74
+ steps.push(next);
75
+ if ("failure" in next) break;
76
+ }
77
+ return steps;
78
+ }),
79
+ ),
80
+ });
@@ -1,4 +1,5 @@
1
- import * as Ref from "@confect/core/Ref";
1
+ import * as ReservedArgument from "./internal/reservedArgument.js";
2
+ import type * as Ref from "@confect/core/Ref";
2
3
  import type { GenericActionCtx } from "convex/server";
3
4
  import * as Context from "effect/Context";
4
5
  import * as Effect from "effect/Effect";
@@ -46,7 +47,7 @@ const make = (nativeRunMutation: GenericActionCtx<any>["runMutation"]) => {
46
47
  yield* MutationTransactionContext.MutationTransactionContext;
47
48
  return yield* controls.runMutation(mutation, actualArgs, options);
48
49
  }
49
- return yield* Ref.runWithCodec(
50
+ return yield* ReservedArgument.runWithCodec(
50
51
  mutation,
51
52
  actualArgs,
52
53
  (ref, encodedArgs) => nativeRunMutation(ref, encodedArgs),
@@ -1,3 +1,4 @@
1
+ import * as ReservedArgument from "./internal/reservedArgument.js";
1
2
  import * as Ref from "@confect/core/Ref";
2
3
  import type {
3
4
  AdvancedRunQueryOptions,
@@ -32,7 +33,7 @@ const make = (
32
33
  args: Ref.Args<Mutation>,
33
34
  options: MutationOptions,
34
35
  ) =>
35
- Ref.runWithCodec(mutation, args, (ref, encodedArgs) =>
36
+ ReservedArgument.runWithCodec(mutation, args, (ref, encodedArgs) =>
36
37
  ctx.runMutation(ref, encodedArgs, options),
37
38
  ),
38
39
  ),
@@ -0,0 +1,168 @@
1
+ import * as Ref from "@confect/core/Ref";
2
+ import { getFunctionReference } from "@confect/core/RefInternal";
3
+ import type {
4
+ DefaultFunctionArgs,
5
+ GenericActionCtx,
6
+ GenericDataModel,
7
+ GenericMutationCtx,
8
+ GenericQueryCtx,
9
+ } from "convex/server";
10
+ import * as Effect from "effect/Effect";
11
+ import * as Option from "effect/Option";
12
+ import * as Schema from "effect/Schema";
13
+ import * as ActionCtx from "./ActionCtx.js";
14
+ import type * as ActionRunner from "./ActionRunner.js";
15
+ import * as MutationCtx from "./MutationCtx.js";
16
+ import type * as MutationRunner from "./MutationRunner.js";
17
+ import * as QueryCtx from "./QueryCtx.js";
18
+ import type * as QueryRunner from "./QueryRunner.js";
19
+ import * as ReservedArgument from "./internal/reservedArgument.js";
20
+
21
+ /**
22
+ * An official component's method rejected. `cause` is the rejection as thrown.
23
+ */
24
+ export class ComponentCallFailed extends Schema.TaggedError<ComponentCallFailed>()(
25
+ "ComponentCallFailed",
26
+ { component: Schema.String, method: Schema.String, cause: Schema.Defect() },
27
+ ) {}
28
+
29
+ declare const unsupported: unique symbol;
30
+ type Unsupported = typeof unsupported;
31
+ type Needs<Param> = [GenericActionCtx<GenericDataModel>] extends [Param]
32
+ ? [GenericMutationCtx<GenericDataModel>] extends [Param]
33
+ ? [GenericQueryCtx<GenericDataModel>] extends [Param]
34
+ ? QueryRunner.QueryRunner
35
+ : MutationRunner.MutationRunner
36
+ : [GenericQueryCtx<GenericDataModel>] extends [Param]
37
+ ? Unsupported
38
+ : ActionRunner.ActionRunner
39
+ : Unsupported;
40
+
41
+ type Method<Official> = {
42
+ [K in keyof Official & string]: Official[K] extends (
43
+ ctx: infer Ctx,
44
+ ...args: infer _Args
45
+ ) => Promise<unknown>
46
+ ? Needs<Ctx> extends Unsupported
47
+ ? never
48
+ : K
49
+ : never;
50
+ }[keyof Official & string];
51
+
52
+ type Call<F> = F extends (
53
+ ctx: infer Ctx,
54
+ ...args: infer Args
55
+ ) => Promise<infer A>
56
+ ? (...args: Args) => Effect.Effect<A, never, Needs<Ctx>>
57
+ : never;
58
+
59
+ type Lifted<Official> = <M extends Method<Official>>(
60
+ method: M,
61
+ ...args: Parameters<Call<Official[M]>>
62
+ ) => ReturnType<Call<Official[M]>>;
63
+
64
+ /**
65
+ * Lift official promise methods, deriving each capability from its ctx
66
+ * parameter. A rejection is caller misuse, a limit or a platform fault rather
67
+ * than a domain fact, so it dies.
68
+ */
69
+ export const make = <Official extends object>(
70
+ component: string,
71
+ official: Official,
72
+ ): Lifted<Official> => {
73
+ const context = Effect.gen(function* () {
74
+ const action = yield* Effect.serviceOption(
75
+ ActionCtx.ActionCtx<GenericDataModel>(),
76
+ );
77
+ if (Option.isSome(action)) return action.value;
78
+ const mutation = yield* Effect.serviceOption(
79
+ MutationCtx.MutationCtx<GenericDataModel>(),
80
+ );
81
+ if (Option.isSome(mutation)) return mutation.value;
82
+ const query = yield* Effect.serviceOption(
83
+ QueryCtx.QueryCtx<GenericDataModel>(),
84
+ );
85
+ if (Option.isSome(query)) return query.value;
86
+ return yield* Effect.die(
87
+ new Error(`${component} called outside a Confect handler`),
88
+ );
89
+ });
90
+ const call = Effect.fn(`${component}.call`)(function* (
91
+ method: Method<Official>,
92
+ ...args: unknown[]
93
+ ) {
94
+ const ctx = yield* context;
95
+ // Method selects promise methods whose first argument accepts a native handler context.
96
+ const invoke = official[method] as (
97
+ native: typeof ctx,
98
+ ...args: unknown[]
99
+ ) => Promise<unknown>;
100
+ return yield* Effect.tryPromise({
101
+ try: () => invoke.call(official, ctx, ...args),
102
+ catch: (cause) => ComponentCallFailed.make({ component, method, cause }),
103
+ }).pipe(Effect.orDie);
104
+ });
105
+ // Confect installs the native ctx with the runner capability inferred by Needs.
106
+ return call as unknown as Lifted<Official>;
107
+ };
108
+
109
+ /**
110
+ * A function reference with its encoded arguments, ready for an official method
111
+ * that takes both.
112
+ */
113
+ export interface Fn<R extends Ref.Any> {
114
+ readonly reference: Ref.FunctionReference<R>;
115
+ readonly args: DefaultFunctionArgs;
116
+ }
117
+
118
+ /**
119
+ * Choose whether an official component call forwards the caller's carrier.
120
+ */
121
+ export interface EncodeCallOptions {
122
+ /**
123
+ * Forward the caller's carrier to reserving mutations and actions. Use `none`
124
+ * when the component replays or compares the stored arguments.
125
+ */
126
+ readonly carrier: "forward" | "none";
127
+ }
128
+
129
+ /**
130
+ * Encode a ref's arguments through its codecs to the wire record an official
131
+ * method expects, with an explicit carrier policy.
132
+ */
133
+ export const encodeCall = <R extends Ref.Any>(
134
+ ref: R,
135
+ args: NoInfer<Ref.Args<R>>,
136
+ options: EncodeCallOptions,
137
+ ): Effect.Effect<Fn<R>> =>
138
+ (options.carrier === "forward"
139
+ ? ReservedArgument.encodeArgs(ref, args)
140
+ : Ref.encodeArgs(ref, args)
141
+ ).pipe(
142
+ Effect.flatMap(
143
+ Schema.decodeUnknownEffect(Schema.Record(Schema.String, Schema.Unknown)),
144
+ ),
145
+ Effect.map((encoded) => ({
146
+ reference: getFunctionReference(ref),
147
+ args: encoded,
148
+ })),
149
+ Effect.orDie,
150
+ );
151
+
152
+ /**
153
+ * Encode a callback's real field without fabricating the rest of its arguments.
154
+ */
155
+ export const encodeField = <
156
+ R extends Ref.AnyConfect,
157
+ K extends keyof Ref.Args<R> & keyof Ref.ArgsFields<R>,
158
+ >(
159
+ ref: R,
160
+ key: K,
161
+ value: NoInfer<Ref.Args<R>[K]>,
162
+ ): Effect.Effect<unknown> => {
163
+ const fields = ref.args.fields as Record<
164
+ keyof Ref.ArgsFields<R>,
165
+ Schema.Codec<unknown, unknown>
166
+ >;
167
+ return Schema.encodeUnknownEffect(fields[key])(value).pipe(Effect.orDie);
168
+ };
@@ -40,14 +40,13 @@ export type OrderedQuery<
40
40
  >;
41
41
  readonly stream: () => Stream.Stream<Doc, Document.DocumentDecodeError>;
42
42
  /**
43
- * Native pagination is application-only. Use `QueryStream.paginate` for
44
- * component index queries.
43
+ * Native pagination works in applications and components. A query may call
44
+ * `.paginate()` once across the host and every component query it calls. A
45
+ * second call throws. Use `QueryStream.paginate` for another index read.
45
46
  */
46
47
  readonly paginate: {
47
48
  readonly app: NativePaginate<TableInfo_, Doc>;
48
- readonly component: {
49
- readonly "Native pagination is unavailable in components. Use QueryStream.paginate for index queries.": never;
50
- };
49
+ readonly component: NativePaginate<TableInfo_, Doc>;
51
50
  }[TargetKind];
52
51
  };
53
52