@gaganref/confect-server 10.3.1-fork.25 → 10.3.1-fork.27

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 (70) 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.js +2 -2
  6. package/dist/AiGatewayDecisionClient.js +1 -1
  7. package/dist/AiGatewayLanguageClient.js +1 -1
  8. package/dist/Auth.js +1 -1
  9. package/dist/Callback.js +3 -3
  10. package/dist/ConvexConfigProvider.js +2 -2
  11. package/dist/ConvexFunctionDefinitions.js +2 -2
  12. package/dist/ConvexLogger.js +1 -1
  13. package/dist/CronJobs.js +6 -6
  14. package/dist/DatabaseSchema.js +2 -2
  15. package/dist/DatabaseWriter.d.ts +36 -2
  16. package/dist/DatabaseWriter.d.ts.map +1 -1
  17. package/dist/DatabaseWriter.js +33 -6
  18. package/dist/DatabaseWriter.js.map +1 -1
  19. package/dist/ExecutionMetadata.js +1 -1
  20. package/dist/FunctionImpl.js +2 -2
  21. package/dist/FunctionRegistryItem.js +1 -1
  22. package/dist/GroupImpl.js +5 -5
  23. package/dist/Handler.d.ts +7 -3
  24. package/dist/Handler.d.ts.map +1 -1
  25. package/dist/Handler.js.map +1 -1
  26. package/dist/HttpRouter.js +2 -2
  27. package/dist/MiddlewareImpl.js +1 -1
  28. package/dist/MutationRunner.js +2 -2
  29. package/dist/MutationTransactionContext.js +2 -2
  30. package/dist/QueryInitializer.js +2 -2
  31. package/dist/QueryRunner.js +2 -2
  32. package/dist/QueryStream.js +3 -3
  33. package/dist/QueryStreamCursor.js +1 -1
  34. package/dist/QueryStreamIndexPrefix.js +1 -1
  35. package/dist/QueryStreamIndexRange.js +2 -2
  36. package/dist/QueryStreamKey.js +1 -1
  37. package/dist/QueryStreamKeyBounds.js +2 -2
  38. package/dist/QueryStreamKeyLayout.js +2 -2
  39. package/dist/QueryStreamKeyValues.js +1 -1
  40. package/dist/QueryStreamPagination.js +1 -1
  41. package/dist/QueryStreamReadBudget.js +2 -2
  42. package/dist/QueryTransactionContext.js +2 -2
  43. package/dist/RegisteredConvexFunction.js +19 -19
  44. package/dist/RegisteredConvexFunction.js.map +1 -1
  45. package/dist/RegisteredFunction.d.ts.map +1 -1
  46. package/dist/RegisteredFunction.js +55 -13
  47. package/dist/RegisteredFunction.js.map +1 -1
  48. package/dist/RegisteredNodeFunction.js +1 -1
  49. package/dist/RegistryItems.js +1 -1
  50. package/dist/RequestMetadata.js +1 -1
  51. package/dist/Scheduler.js +2 -2
  52. package/dist/Storage.js +1 -1
  53. package/dist/StorageActionWriter.js +1 -1
  54. package/dist/StorageReader.js +1 -1
  55. package/dist/StorageWriter.js +1 -1
  56. package/dist/TransactionMetadata.js +1 -1
  57. package/dist/VectorSearch.js +1 -1
  58. package/dist/index.d.ts +1 -0
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +10 -9
  61. package/dist/internal/AiGatewayDecisionClient.js +1 -1
  62. package/dist/internal/AiGatewayLanguageClient.js +1 -1
  63. package/dist/internal/AiGatewayServiceToken.js +1 -1
  64. package/dist/internal/DocumentPatch.js +1 -1
  65. package/package.json +2 -2
  66. package/src/ActionCall.ts +82 -0
  67. package/src/DatabaseWriter.ts +90 -5
  68. package/src/Handler.ts +20 -5
  69. package/src/RegisteredFunction.ts +54 -1
  70. package/src/index.ts +1 -0
@@ -1,3 +1,5 @@
1
+ import * as ActionCallSpec from "@confect/core/ActionCall";
2
+ import * as ActionCall from "./ActionCall.js";
1
3
  import type { FunctionSpec, RuntimeAndFunctionType } from "@confect/core";
2
4
  import * as IdScope from "@confect/core/IdScope";
3
5
  import type * as FunctionProvenance from "@confect/core/FunctionProvenance";
@@ -299,6 +301,12 @@ export const actionFunctionBase = <
299
301
  Schema.decodeUnknownEffect(args),
300
302
  Effect.catchTag("SchemaError", Effect.die),
301
303
  );
304
+ const restricted = resolvedMiddlewares.some(
305
+ ({ middlewareSpec }) =>
306
+ middlewareSpec.key === ActionCallSpec.Middleware.key,
307
+ )
308
+ ? restrict(ctx)
309
+ : undefined;
302
310
  // oxlint-disable-next-line effecttsgo/any-unknown-in-error-context -- Middleware errors are intentionally erased here and validated by runHandlerPromise against the combined error schema below.
303
311
  const decodedReturns = yield* applyMiddleware(
304
312
  handler(decodedArgs),
@@ -309,7 +317,8 @@ export const actionFunctionBase = <
309
317
  functionVisibility,
310
318
  args: decodedArgs,
311
319
  },
312
- ).pipe(Effect.provide(createLayer(ctx)));
320
+ ).pipe(Effect.provide(createLayer(restricted?.ctx ?? ctx)));
321
+ if (restricted !== undefined) yield* restricted.check;
313
322
  return yield* pipe(
314
323
  decodedReturns,
315
324
  Schema.encodeEffect(returns),
@@ -389,3 +398,47 @@ export const storageLayer = <Scope extends IdScope.IdScope>(
389
398
  Storage.layer(reader) as Layer.Layer<
390
399
  Storage.Storage | StorageReader.ForScope<Scope>
391
400
  >;
401
+
402
+ /**
403
+ * Shares one dispatch budget across the entire middleware chain.
404
+ */
405
+ const restrict = <Model extends GenericDataModel>(
406
+ ctx: GenericActionCtx<Model>,
407
+ ) => {
408
+ let dispatched = false;
409
+ const claim = () => {
410
+ if (dispatched) throw new ActionCall.ActionCallAlreadyUsed();
411
+ dispatched = true;
412
+ };
413
+ const restricted: GenericActionCtx<Model> = {
414
+ ...ctx,
415
+ scheduler: {
416
+ runAfter: () => {
417
+ throw new ActionCall.SchedulingNotAllowed();
418
+ },
419
+ runAt: () => {
420
+ throw new ActionCall.SchedulingNotAllowed();
421
+ },
422
+ cancel: () => {
423
+ throw new ActionCall.SchedulingNotAllowed();
424
+ },
425
+ },
426
+ runQuery: (...args) => {
427
+ claim();
428
+ return ctx.runQuery(...args);
429
+ },
430
+ runMutation: (...args) => {
431
+ claim();
432
+ return ctx.runMutation(...args);
433
+ },
434
+ runAction: () => {
435
+ throw new ActionCall.NestedActionNotAllowed();
436
+ },
437
+ };
438
+ return {
439
+ ctx: restricted,
440
+ check: Effect.suspend(() =>
441
+ dispatched ? Effect.void : Effect.die(new ActionCall.ActionCallNotUsed()),
442
+ ),
443
+ };
444
+ };
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * as ActionCall from "./ActionCall.js";
1
2
  export * as AiGatewayDecisionClient from "./AiGatewayDecisionClient.js";
2
3
  export * as AiGatewayDecisionModel from "./AiGatewayDecisionModel.js";
3
4
  export * as AiGatewayLanguageClient from "./AiGatewayLanguageClient.js";