@confect/server 3.0.0 → 5.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 (89) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/ActionRunner.d.ts +5 -3
  3. package/dist/ActionRunner.d.ts.map +1 -1
  4. package/dist/ActionRunner.js +2 -10
  5. package/dist/ActionRunner.js.map +1 -1
  6. package/dist/BlobNotFoundError.d.ts +17 -0
  7. package/dist/BlobNotFoundError.d.ts.map +1 -0
  8. package/dist/BlobNotFoundError.js +14 -0
  9. package/dist/BlobNotFoundError.js.map +1 -0
  10. package/dist/CronJob.d.ts +22 -0
  11. package/dist/CronJob.d.ts.map +1 -0
  12. package/dist/CronJob.js +23 -0
  13. package/dist/CronJob.js.map +1 -0
  14. package/dist/CronJobs.d.ts +20 -0
  15. package/dist/CronJobs.d.ts.map +1 -0
  16. package/dist/CronJobs.js +74 -0
  17. package/dist/CronJobs.js.map +1 -0
  18. package/dist/DatabaseReader.d.ts +5 -5
  19. package/dist/DatabaseWriter.d.ts +4 -4
  20. package/dist/DatabaseWriter.d.ts.map +1 -1
  21. package/dist/Handler.d.ts +4 -2
  22. package/dist/Handler.d.ts.map +1 -1
  23. package/dist/Handler.js.map +1 -1
  24. package/dist/HttpApi.d.ts +3 -1
  25. package/dist/HttpApi.d.ts.map +1 -1
  26. package/dist/HttpApi.js +3 -1
  27. package/dist/HttpApi.js.map +1 -1
  28. package/dist/MutationRunner.d.ts +5 -3
  29. package/dist/MutationRunner.d.ts.map +1 -1
  30. package/dist/MutationRunner.js +2 -10
  31. package/dist/MutationRunner.js.map +1 -1
  32. package/dist/OrderedQuery.d.ts +2 -2
  33. package/dist/OrderedQuery.d.ts.map +1 -1
  34. package/dist/OrderedQuery.js +3 -2
  35. package/dist/OrderedQuery.js.map +1 -1
  36. package/dist/QueryInitializer.d.ts +1 -1
  37. package/dist/QueryInitializer.d.ts.map +1 -1
  38. package/dist/QueryRunner.d.ts +5 -3
  39. package/dist/QueryRunner.d.ts.map +1 -1
  40. package/dist/QueryRunner.js +2 -10
  41. package/dist/QueryRunner.js.map +1 -1
  42. package/dist/RegisteredConvexFunction.d.ts +8 -7
  43. package/dist/RegisteredConvexFunction.d.ts.map +1 -1
  44. package/dist/RegisteredConvexFunction.js +2 -1
  45. package/dist/RegisteredConvexFunction.js.map +1 -1
  46. package/dist/RegisteredFunction.d.ts +9 -7
  47. package/dist/RegisteredFunction.d.ts.map +1 -1
  48. package/dist/RegisteredFunction.js +3 -1
  49. package/dist/RegisteredFunction.js.map +1 -1
  50. package/dist/Scheduler.d.ts +9 -7
  51. package/dist/Scheduler.d.ts.map +1 -1
  52. package/dist/Scheduler.js +9 -4
  53. package/dist/Scheduler.js.map +1 -1
  54. package/dist/StorageActionWriter.d.ts +35 -0
  55. package/dist/StorageActionWriter.d.ts.map +1 -0
  56. package/dist/StorageActionWriter.js +20 -0
  57. package/dist/StorageActionWriter.js.map +1 -0
  58. package/dist/StorageReader.d.ts +26 -0
  59. package/dist/StorageReader.d.ts.map +1 -0
  60. package/dist/StorageReader.js +17 -0
  61. package/dist/StorageReader.js.map +1 -0
  62. package/dist/StorageWriter.d.ts +29 -0
  63. package/dist/StorageWriter.d.ts.map +1 -0
  64. package/dist/StorageWriter.js +20 -0
  65. package/dist/StorageWriter.js.map +1 -0
  66. package/dist/index.d.ts +7 -2
  67. package/dist/index.js +7 -2
  68. package/package.json +4 -4
  69. package/src/ActionRunner.ts +5 -30
  70. package/src/BlobNotFoundError.ts +12 -0
  71. package/src/CronJob.ts +45 -0
  72. package/src/CronJobs.ts +147 -0
  73. package/src/Handler.ts +3 -5
  74. package/src/HttpApi.ts +3 -1
  75. package/src/MutationRunner.ts +5 -27
  76. package/src/OrderedQuery.ts +15 -6
  77. package/src/QueryRunner.ts +5 -30
  78. package/src/RegisteredConvexFunction.ts +2 -1
  79. package/src/RegisteredFunction.ts +3 -1
  80. package/src/Scheduler.ts +25 -13
  81. package/src/StorageActionWriter.ts +28 -0
  82. package/src/StorageReader.ts +27 -0
  83. package/src/StorageWriter.ts +26 -0
  84. package/src/index.ts +6 -1
  85. package/dist/Storage.d.ts +0 -69
  86. package/dist/Storage.d.ts.map +0 -1
  87. package/dist/Storage.js +0 -46
  88. package/dist/Storage.js.map +0 -1
  89. package/src/Storage.ts +0 -87
@@ -0,0 +1,20 @@
1
+ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
+ import { BlobNotFoundError } from "./BlobNotFoundError.js";
3
+ import { Effect, Layer, Option, flow } from "effect";
4
+
5
+ //#region src/StorageActionWriter.ts
6
+ var StorageActionWriter_exports = /* @__PURE__ */ __exportAll({ StorageActionWriter: () => StorageActionWriter });
7
+ const make = (storageActionWriter) => ({
8
+ get: (storageId) => Effect.promise(() => storageActionWriter.get(storageId)).pipe(Effect.andThen(flow(Option.fromNullable, Option.match({
9
+ onNone: () => Effect.fail(new BlobNotFoundError({ id: storageId })),
10
+ onSome: Effect.succeed
11
+ })))),
12
+ store: (blob, options) => Effect.promise(() => storageActionWriter.store(blob, options))
13
+ });
14
+ var StorageActionWriter = class extends Effect.Tag("@confect/server/StorageActionWriter")() {
15
+ static layer = (storageActionWriter) => Layer.succeed(this, make(storageActionWriter));
16
+ };
17
+
18
+ //#endregion
19
+ export { StorageActionWriter, StorageActionWriter_exports };
20
+ //# sourceMappingURL=StorageActionWriter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StorageActionWriter.js","names":[],"sources":["../src/StorageActionWriter.ts"],"sourcesContent":["import type { StorageActionWriter as ConvexStorageActionWriter } from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\nimport { Effect, flow, Layer, Option } from \"effect\";\nimport { BlobNotFoundError } from \"./BlobNotFoundError\";\n\nconst make = (storageActionWriter: ConvexStorageActionWriter) => ({\n get: (storageId: GenericId<\"_storage\">) =>\n Effect.promise(() => storageActionWriter.get(storageId)).pipe(\n Effect.andThen(\n flow(\n Option.fromNullable,\n Option.match({\n onNone: () => Effect.fail(new BlobNotFoundError({ id: storageId })),\n onSome: Effect.succeed,\n }),\n ),\n ),\n ),\n store: (blob: Blob, options?: { sha256?: string }) =>\n Effect.promise(() => storageActionWriter.store(blob, options)),\n});\n\nexport class StorageActionWriter extends Effect.Tag(\n \"@confect/server/StorageActionWriter\",\n)<StorageActionWriter, ReturnType<typeof make>>() {\n static readonly layer = (storageActionWriter: ConvexStorageActionWriter) =>\n Layer.succeed(this, make(storageActionWriter));\n}\n"],"mappings":";;;;;;AAKA,MAAM,QAAQ,yBAAoD;CAChE,MAAM,cACJ,OAAO,cAAc,oBAAoB,IAAI,UAAU,CAAC,CAAC,KACvD,OAAO,QACL,KACE,OAAO,cACP,OAAO,MAAM;EACX,cAAc,OAAO,KAAK,IAAI,kBAAkB,EAAE,IAAI,WAAW,CAAC,CAAC;EACnE,QAAQ,OAAO;EAChB,CAAC,CACH,CACF,CACF;CACH,QAAQ,MAAY,YAClB,OAAO,cAAc,oBAAoB,MAAM,MAAM,QAAQ,CAAC;CACjE;AAED,IAAa,sBAAb,cAAyC,OAAO,IAC9C,sCACD,EAAgD,CAAC;CAChD,OAAgB,SAAS,wBACvB,MAAM,QAAQ,MAAM,KAAK,oBAAoB,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { BlobNotFoundError } from "./BlobNotFoundError.js";
2
+ import { Effect, Layer } from "effect";
3
+ import { StorageReader as StorageReader$1 } from "convex/server";
4
+ import { GenericId } from "convex/values";
5
+ import * as effect_Context0 from "effect/Context";
6
+ import * as effect_Cause0 from "effect/Cause";
7
+
8
+ //#region src/StorageReader.d.ts
9
+ declare namespace StorageReader_d_exports {
10
+ export { StorageReader };
11
+ }
12
+ declare const StorageReader_base: effect_Context0.TagClass<StorageReader, "@confect/server/StorageReader", {
13
+ getUrl: (storageId: GenericId<"_storage">) => Effect.Effect<URL, BlobNotFoundError, never>;
14
+ }> & Effect.Tag.Proxy<StorageReader, {
15
+ getUrl: (storageId: GenericId<"_storage">) => Effect.Effect<URL, BlobNotFoundError, never>;
16
+ }> & {
17
+ use: <X>(body: (_: {
18
+ getUrl: (storageId: GenericId<"_storage">) => Effect.Effect<URL, BlobNotFoundError, never>;
19
+ }) => X) => [X] extends [Effect.Effect<infer A, infer E, infer R>] ? Effect.Effect<A, E, R | StorageReader> : [X] extends [PromiseLike<infer A_1>] ? Effect.Effect<A_1, effect_Cause0.UnknownException, StorageReader> : Effect.Effect<X, never, StorageReader>;
20
+ };
21
+ declare class StorageReader extends StorageReader_base {
22
+ static readonly layer: (storageReader: StorageReader$1) => Layer.Layer<StorageReader, never, never>;
23
+ }
24
+ //#endregion
25
+ export { StorageReader, StorageReader_d_exports };
26
+ //# sourceMappingURL=StorageReader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StorageReader.d.ts","names":[],"sources":["../src/StorageReader.ts"],"mappings":";;;;;;;;;;;cAGwD,kBAAA,EAGb,eAAA,CAAA,QAAA;sBAArB,SAAA,iBAAqB,MAAA,CAAA,MAAA,CAAA,GAAA,EAAA,iBAAA;AAAA;sBAArB,SAAA,iBAAqB,MAAA,CAAA,MAAA,CAAA,GAAA,EAAA,iBAAA;AAAA;;wBAArB,SAAA,iBAAqB,MAAA,CAAA,MAAA,CAAA,GAAA,EAAA,iBAAA;EAAA;;cAc9B,aAAA,SAAsB,kBAAA;EAAA,gBAIjB,KAAA,GAAS,aAAA,EAAe,eAAA,KAAmB,KAAA,CAAA,KAAA,CAAA,aAAA;AAAA"}
@@ -0,0 +1,17 @@
1
+ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
+ import { BlobNotFoundError } from "./BlobNotFoundError.js";
3
+ import { Effect, Layer, Option, Schema, flow, pipe } from "effect";
4
+
5
+ //#region src/StorageReader.ts
6
+ var StorageReader_exports = /* @__PURE__ */ __exportAll({ StorageReader: () => StorageReader });
7
+ const make = (storageReader) => ({ getUrl: (storageId) => Effect.promise(() => storageReader.getUrl(storageId)).pipe(Effect.andThen(flow(Option.fromNullable, Option.match({
8
+ onNone: () => Effect.fail(new BlobNotFoundError({ id: storageId })),
9
+ onSome: (doc) => pipe(doc, Schema.decode(Schema.URL), Effect.orDie)
10
+ })))) });
11
+ var StorageReader = class extends Effect.Tag("@confect/server/StorageReader")() {
12
+ static layer = (storageReader) => Layer.succeed(this, make(storageReader));
13
+ };
14
+
15
+ //#endregion
16
+ export { StorageReader, StorageReader_exports };
17
+ //# sourceMappingURL=StorageReader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StorageReader.js","names":[],"sources":["../src/StorageReader.ts"],"sourcesContent":["import type { StorageReader as ConvexStorageReader } from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\nimport { Effect, flow, Layer, Option, pipe, Schema } from \"effect\";\nimport { BlobNotFoundError } from \"./BlobNotFoundError\";\n\nconst make = (storageReader: ConvexStorageReader) => ({\n getUrl: (storageId: GenericId<\"_storage\">) =>\n Effect.promise(() => storageReader.getUrl(storageId)).pipe(\n Effect.andThen(\n flow(\n Option.fromNullable,\n Option.match({\n onNone: () => Effect.fail(new BlobNotFoundError({ id: storageId })),\n onSome: (doc) => pipe(doc, Schema.decode(Schema.URL), Effect.orDie),\n }),\n ),\n ),\n ),\n});\n\nexport class StorageReader extends Effect.Tag(\"@confect/server/StorageReader\")<\n StorageReader,\n ReturnType<typeof make>\n>() {\n static readonly layer = (storageReader: ConvexStorageReader) =>\n Layer.succeed(this, make(storageReader));\n}\n"],"mappings":";;;;;;AAKA,MAAM,QAAQ,mBAAwC,EACpD,SAAS,cACP,OAAO,cAAc,cAAc,OAAO,UAAU,CAAC,CAAC,KACpD,OAAO,QACL,KACE,OAAO,cACP,OAAO,MAAM;CACX,cAAc,OAAO,KAAK,IAAI,kBAAkB,EAAE,IAAI,WAAW,CAAC,CAAC;CACnE,SAAS,QAAQ,KAAK,KAAK,OAAO,OAAO,OAAO,IAAI,EAAE,OAAO,MAAM;CACpE,CAAC,CACH,CACF,CACF,EACJ;AAED,IAAa,gBAAb,cAAmC,OAAO,IAAI,gCAAgC,EAG3E,CAAC;CACF,OAAgB,SAAS,kBACvB,MAAM,QAAQ,MAAM,KAAK,cAAc,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { BlobNotFoundError } from "./BlobNotFoundError.js";
2
+ import { Effect, Layer } from "effect";
3
+ import { StorageWriter as StorageWriter$1 } from "convex/server";
4
+ import { GenericId } from "convex/values";
5
+ import * as effect_Context0 from "effect/Context";
6
+ import * as effect_Cause0 from "effect/Cause";
7
+
8
+ //#region src/StorageWriter.d.ts
9
+ declare namespace StorageWriter_d_exports {
10
+ export { StorageWriter };
11
+ }
12
+ declare const StorageWriter_base: effect_Context0.TagClass<StorageWriter, "@confect/server/StorageWriter", {
13
+ generateUploadUrl: () => Effect.Effect<URL, never, never>;
14
+ delete: (storageId: GenericId<"_storage">) => Effect.Effect<void, BlobNotFoundError, never>;
15
+ }> & Effect.Tag.Proxy<StorageWriter, {
16
+ generateUploadUrl: () => Effect.Effect<URL, never, never>;
17
+ delete: (storageId: GenericId<"_storage">) => Effect.Effect<void, BlobNotFoundError, never>;
18
+ }> & {
19
+ use: <X>(body: (_: {
20
+ generateUploadUrl: () => Effect.Effect<URL, never, never>;
21
+ delete: (storageId: GenericId<"_storage">) => Effect.Effect<void, BlobNotFoundError, never>;
22
+ }) => X) => [X] extends [Effect.Effect<infer A, infer E, infer R>] ? Effect.Effect<A, E, R | StorageWriter> : [X] extends [PromiseLike<infer A_1>] ? Effect.Effect<A_1, effect_Cause0.UnknownException, StorageWriter> : Effect.Effect<X, never, StorageWriter>;
23
+ };
24
+ declare class StorageWriter extends StorageWriter_base {
25
+ static readonly layer: (storageWriter: StorageWriter$1) => Layer.Layer<StorageWriter, never, never>;
26
+ }
27
+ //#endregion
28
+ export { StorageWriter, StorageWriter_d_exports };
29
+ //# sourceMappingURL=StorageWriter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StorageWriter.d.ts","names":[],"sources":["../src/StorageWriter.ts"],"mappings":";;;;;;;;;;;cAGwD,kBAAA,EASb,eAAA,CAAA,QAAA;;sBAArB,SAAA,iBAAqB,MAAA,CAAA,MAAA,OAAA,iBAAA;AAAA;;sBAArB,SAAA,iBAAqB,MAAA,CAAA,MAAA,OAAA,iBAAA;AAAA;;;wBAArB,SAAA,iBAAqB,MAAA,CAAA,MAAA,OAAA,iBAAA;EAAA;;cAO9B,aAAA,SAAsB,kBAAA;EAAA,gBAIjB,KAAA,GAAS,aAAA,EAAe,eAAA,KAAmB,KAAA,CAAA,KAAA,CAAA,aAAA;AAAA"}
@@ -0,0 +1,20 @@
1
+ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
+ import { BlobNotFoundError } from "./BlobNotFoundError.js";
3
+ import { Effect, Layer, Schema, pipe } from "effect";
4
+
5
+ //#region src/StorageWriter.ts
6
+ var StorageWriter_exports = /* @__PURE__ */ __exportAll({ StorageWriter: () => StorageWriter });
7
+ const make = (storageWriter) => ({
8
+ generateUploadUrl: () => Effect.promise(() => storageWriter.generateUploadUrl()).pipe(Effect.andThen((url) => pipe(url, Schema.decode(Schema.URL), Effect.orDie))),
9
+ delete: (storageId) => Effect.tryPromise({
10
+ try: () => storageWriter.delete(storageId),
11
+ catch: () => new BlobNotFoundError({ id: storageId })
12
+ })
13
+ });
14
+ var StorageWriter = class extends Effect.Tag("@confect/server/StorageWriter")() {
15
+ static layer = (storageWriter) => Layer.succeed(this, make(storageWriter));
16
+ };
17
+
18
+ //#endregion
19
+ export { StorageWriter, StorageWriter_exports };
20
+ //# sourceMappingURL=StorageWriter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StorageWriter.js","names":[],"sources":["../src/StorageWriter.ts"],"sourcesContent":["import type { StorageWriter as ConvexStorageWriter } from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\nimport { Effect, Layer, pipe, Schema } from \"effect\";\nimport { BlobNotFoundError } from \"./BlobNotFoundError\";\n\nconst make = (storageWriter: ConvexStorageWriter) => ({\n generateUploadUrl: () =>\n Effect.promise(() => storageWriter.generateUploadUrl()).pipe(\n Effect.andThen((url) =>\n pipe(url, Schema.decode(Schema.URL), Effect.orDie),\n ),\n ),\n delete: (storageId: GenericId<\"_storage\">) =>\n Effect.tryPromise({\n try: () => storageWriter.delete(storageId),\n catch: () => new BlobNotFoundError({ id: storageId }),\n }),\n});\n\nexport class StorageWriter extends Effect.Tag(\"@confect/server/StorageWriter\")<\n StorageWriter,\n ReturnType<typeof make>\n>() {\n static readonly layer = (storageWriter: ConvexStorageWriter) =>\n Layer.succeed(this, make(storageWriter));\n}\n"],"mappings":";;;;;;AAKA,MAAM,QAAQ,mBAAwC;CACpD,yBACE,OAAO,cAAc,cAAc,mBAAmB,CAAC,CAAC,KACtD,OAAO,SAAS,QACd,KAAK,KAAK,OAAO,OAAO,OAAO,IAAI,EAAE,OAAO,MAAM,CACnD,CACF;CACH,SAAS,cACP,OAAO,WAAW;EAChB,WAAW,cAAc,OAAO,UAAU;EAC1C,aAAa,IAAI,kBAAkB,EAAE,IAAI,WAAW,CAAC;EACtD,CAAC;CACL;AAED,IAAa,gBAAb,cAAmC,OAAO,IAAI,gCAAgC,EAG3E,CAAC;CACF,OAAgB,SAAS,kBACvB,MAAM,QAAQ,MAAM,KAAK,cAAc,CAAC"}
package/dist/index.d.ts CHANGED
@@ -5,7 +5,10 @@ import { Table_d_exports } from "./Table.js";
5
5
  import { DatabaseSchema_d_exports } from "./DatabaseSchema.js";
6
6
  import { Api_d_exports } from "./Api.js";
7
7
  import { Auth_d_exports } from "./Auth.js";
8
+ import { BlobNotFoundError_d_exports } from "./BlobNotFoundError.js";
8
9
  import { ConvexConfigProvider_d_exports } from "./ConvexConfigProvider.js";
10
+ import { CronJob_d_exports } from "./CronJob.js";
11
+ import { CronJobs_d_exports } from "./CronJobs.js";
9
12
  import { Document_d_exports } from "./Document.js";
10
13
  import { TableInfo_d_exports } from "./TableInfo.js";
11
14
  import { DataModel_d_exports } from "./DataModel.js";
@@ -18,7 +21,9 @@ import { MutationRunner_d_exports } from "./MutationRunner.js";
18
21
  import { QueryCtx_d_exports } from "./QueryCtx.js";
19
22
  import { QueryRunner_d_exports } from "./QueryRunner.js";
20
23
  import { Scheduler_d_exports } from "./Scheduler.js";
21
- import { Storage_d_exports } from "./Storage.js";
24
+ import { StorageActionWriter_d_exports } from "./StorageActionWriter.js";
25
+ import { StorageReader_d_exports } from "./StorageReader.js";
26
+ import { StorageWriter_d_exports } from "./StorageWriter.js";
22
27
  import { VectorSearch_d_exports } from "./VectorSearch.js";
23
28
  import { RegisteredFunction_d_exports } from "./RegisteredFunction.js";
24
29
  import { Handler_d_exports } from "./Handler.js";
@@ -30,4 +35,4 @@ import { RegistryItem_d_exports } from "./RegistryItem.js";
30
35
  import { RegisteredConvexFunction_d_exports } from "./RegisteredConvexFunction.js";
31
36
  import { RegisteredFunctions_d_exports } from "./RegisteredFunctions.js";
32
37
  import { Registry_d_exports } from "./Registry.js";
33
- export { ActionCtx_d_exports as ActionCtx, ActionRunner_d_exports as ActionRunner, Api_d_exports as Api, Auth_d_exports as Auth, ConvexConfigProvider_d_exports as ConvexConfigProvider, DataModel_d_exports as DataModel, DatabaseReader_d_exports as DatabaseReader, DatabaseSchema_d_exports as DatabaseSchema, DatabaseWriter_d_exports as DatabaseWriter, Document_d_exports as Document, FunctionImpl_d_exports as FunctionImpl, GroupImpl_d_exports as GroupImpl, Handler_d_exports as Handler, HttpApi_d_exports as HttpApi, Impl_d_exports as Impl, MutationCtx_d_exports as MutationCtx, MutationRunner_d_exports as MutationRunner, OrderedQuery_d_exports as OrderedQuery, QueryCtx_d_exports as QueryCtx, QueryInitializer_d_exports as QueryInitializer, QueryRunner_d_exports as QueryRunner, RegisteredConvexFunction_d_exports as RegisteredConvexFunction, RegisteredFunction_d_exports as RegisteredFunction, RegisteredFunctions_d_exports as RegisteredFunctions, Registry_d_exports as Registry, RegistryItem_d_exports as RegistryItem, Scheduler_d_exports as Scheduler, SchemaToValidator_d_exports as SchemaToValidator, Storage_d_exports as Storage, Table_d_exports as Table, TableInfo_d_exports as TableInfo, VectorSearch_d_exports as VectorSearch };
38
+ export { ActionCtx_d_exports as ActionCtx, ActionRunner_d_exports as ActionRunner, Api_d_exports as Api, Auth_d_exports as Auth, BlobNotFoundError_d_exports as BlobNotFoundError, ConvexConfigProvider_d_exports as ConvexConfigProvider, CronJob_d_exports as CronJob, CronJobs_d_exports as CronJobs, DataModel_d_exports as DataModel, DatabaseReader_d_exports as DatabaseReader, DatabaseSchema_d_exports as DatabaseSchema, DatabaseWriter_d_exports as DatabaseWriter, Document_d_exports as Document, FunctionImpl_d_exports as FunctionImpl, GroupImpl_d_exports as GroupImpl, Handler_d_exports as Handler, HttpApi_d_exports as HttpApi, Impl_d_exports as Impl, MutationCtx_d_exports as MutationCtx, MutationRunner_d_exports as MutationRunner, OrderedQuery_d_exports as OrderedQuery, QueryCtx_d_exports as QueryCtx, QueryInitializer_d_exports as QueryInitializer, QueryRunner_d_exports as QueryRunner, RegisteredConvexFunction_d_exports as RegisteredConvexFunction, RegisteredFunction_d_exports as RegisteredFunction, RegisteredFunctions_d_exports as RegisteredFunctions, Registry_d_exports as Registry, RegistryItem_d_exports as RegistryItem, Scheduler_d_exports as Scheduler, SchemaToValidator_d_exports as SchemaToValidator, StorageActionWriter_d_exports as StorageActionWriter, StorageReader_d_exports as StorageReader, StorageWriter_d_exports as StorageWriter, Table_d_exports as Table, TableInfo_d_exports as TableInfo, VectorSearch_d_exports as VectorSearch };
package/dist/index.js CHANGED
@@ -2,7 +2,10 @@ import { ActionCtx_exports } from "./ActionCtx.js";
2
2
  import { ActionRunner_exports } from "./ActionRunner.js";
3
3
  import { Api_exports } from "./Api.js";
4
4
  import { Auth_exports } from "./Auth.js";
5
+ import { BlobNotFoundError_exports } from "./BlobNotFoundError.js";
5
6
  import { ConvexConfigProvider_exports } from "./ConvexConfigProvider.js";
7
+ import { CronJob_exports } from "./CronJob.js";
8
+ import { CronJobs_exports } from "./CronJobs.js";
6
9
  import { DataModel_exports } from "./DataModel.js";
7
10
  import { SchemaToValidator_exports } from "./SchemaToValidator.js";
8
11
  import { Table_exports } from "./Table.js";
@@ -20,7 +23,9 @@ import { Handler_exports } from "./Handler.js";
20
23
  import { MutationRunner_exports } from "./MutationRunner.js";
21
24
  import { QueryRunner_exports } from "./QueryRunner.js";
22
25
  import { Scheduler_exports } from "./Scheduler.js";
23
- import { Storage_exports } from "./Storage.js";
26
+ import { StorageActionWriter_exports } from "./StorageActionWriter.js";
27
+ import { StorageReader_exports } from "./StorageReader.js";
28
+ import { StorageWriter_exports } from "./StorageWriter.js";
24
29
  import { HttpApi_exports } from "./HttpApi.js";
25
30
  import { Impl_exports } from "./Impl.js";
26
31
  import { MutationCtx_exports } from "./MutationCtx.js";
@@ -31,4 +36,4 @@ import { RegisteredConvexFunction_exports } from "./RegisteredConvexFunction.js"
31
36
  import { RegisteredFunctions_exports } from "./RegisteredFunctions.js";
32
37
  import { TableInfo_exports } from "./TableInfo.js";
33
38
 
34
- export { ActionCtx_exports as ActionCtx, ActionRunner_exports as ActionRunner, Api_exports as Api, Auth_exports as Auth, ConvexConfigProvider_exports as ConvexConfigProvider, DataModel_exports as DataModel, DatabaseReader_exports as DatabaseReader, DatabaseSchema_exports as DatabaseSchema, DatabaseWriter_exports as DatabaseWriter, Document_exports as Document, FunctionImpl_exports as FunctionImpl, GroupImpl_exports as GroupImpl, Handler_exports as Handler, HttpApi_exports as HttpApi, Impl_exports as Impl, MutationCtx_exports as MutationCtx, MutationRunner_exports as MutationRunner, OrderedQuery_exports as OrderedQuery, QueryCtx_exports as QueryCtx, QueryInitializer_exports as QueryInitializer, QueryRunner_exports as QueryRunner, RegisteredConvexFunction_exports as RegisteredConvexFunction, RegisteredFunction_exports as RegisteredFunction, RegisteredFunctions_exports as RegisteredFunctions, Registry_exports as Registry, RegistryItem_exports as RegistryItem, Scheduler_exports as Scheduler, SchemaToValidator_exports as SchemaToValidator, Storage_exports as Storage, Table_exports as Table, TableInfo_exports as TableInfo, VectorSearch_exports as VectorSearch };
39
+ export { ActionCtx_exports as ActionCtx, ActionRunner_exports as ActionRunner, Api_exports as Api, Auth_exports as Auth, BlobNotFoundError_exports as BlobNotFoundError, ConvexConfigProvider_exports as ConvexConfigProvider, CronJob_exports as CronJob, CronJobs_exports as CronJobs, DataModel_exports as DataModel, DatabaseReader_exports as DatabaseReader, DatabaseSchema_exports as DatabaseSchema, DatabaseWriter_exports as DatabaseWriter, Document_exports as Document, FunctionImpl_exports as FunctionImpl, GroupImpl_exports as GroupImpl, Handler_exports as Handler, HttpApi_exports as HttpApi, Impl_exports as Impl, MutationCtx_exports as MutationCtx, MutationRunner_exports as MutationRunner, OrderedQuery_exports as OrderedQuery, QueryCtx_exports as QueryCtx, QueryInitializer_exports as QueryInitializer, QueryRunner_exports as QueryRunner, RegisteredConvexFunction_exports as RegisteredConvexFunction, RegisteredFunction_exports as RegisteredFunction, RegisteredFunctions_exports as RegisteredFunctions, Registry_exports as Registry, RegistryItem_exports as RegistryItem, Scheduler_exports as Scheduler, SchemaToValidator_exports as SchemaToValidator, StorageActionWriter_exports as StorageActionWriter, StorageReader_exports as StorageReader, StorageWriter_exports as StorageWriter, Table_exports as Table, TableInfo_exports as TableInfo, VectorSearch_exports as VectorSearch };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@confect/server",
3
- "version": "3.0.0",
3
+ "version": "5.0.0",
4
4
  "description": "Backend bindings to the Convex platform",
5
5
  "repository": {
6
6
  "type": "git",
@@ -67,15 +67,15 @@
67
67
  "vite": "7.3.1",
68
68
  "vite-tsconfig-paths": "6.1.1",
69
69
  "vitest": "3.2.4",
70
- "@confect/cli": "3.0.0",
71
- "@confect/test": "3.0.0"
70
+ "@confect/cli": "5.0.0",
71
+ "@confect/test": "5.0.0"
72
72
  },
73
73
  "peerDependencies": {
74
74
  "@effect/platform": "^0.94.5",
75
75
  "@effect/platform-node": "^0.104.1",
76
76
  "convex": "^1.30.0",
77
77
  "effect": "^3.19.16",
78
- "@confect/core": "3.0.0"
78
+ "@confect/core": "5.0.0"
79
79
  },
80
80
  "engines": {
81
81
  "node": ">=22",
@@ -1,38 +1,13 @@
1
1
  import * as Ref from "@confect/core/Ref";
2
2
  import { type GenericActionCtx } from "convex/server";
3
- import type { ParseResult } from "effect";
4
- import { Context, Effect, Layer, Match, Schema } from "effect";
3
+ import { Context, Layer } from "effect";
5
4
 
6
5
  const make =
7
6
  (runAction: GenericActionCtx<any>["runAction"]) =>
8
- <Action extends Ref.AnyAction>(
9
- action: Action,
10
- args: Ref.Args<Action>,
11
- ): Effect.Effect<Ref.Returns<Action>, ParseResult.ParseError> =>
12
- Effect.gen(function* () {
13
- const functionSpec = Ref.getFunctionSpec(action);
14
- const functionName = Ref.getConvexFunctionName(action);
15
-
16
- return yield* Match.value(functionSpec.functionProvenance).pipe(
17
- Match.tag("Confect", (confectFunctionSpec) =>
18
- Effect.gen(function* () {
19
- const encodedArgs = yield* Schema.encode(confectFunctionSpec.args)(
20
- args,
21
- );
22
- const encodedReturns = yield* Effect.promise(() =>
23
- runAction(functionName as any, encodedArgs),
24
- );
25
- return yield* Schema.decode(confectFunctionSpec.returns)(
26
- encodedReturns,
27
- );
28
- }),
29
- ),
30
- Match.tag("Convex", () =>
31
- Effect.promise(() => runAction(functionName as any, args as any)),
32
- ),
33
- Match.exhaustive,
34
- );
35
- });
7
+ <Action extends Ref.AnyAction>(action: Action, args: Ref.Args<Action>) =>
8
+ Ref.runWithCodec(action, args, (functionReference, encodedArgs) =>
9
+ runAction(functionReference, encodedArgs),
10
+ );
36
11
 
37
12
  export const ActionRunner = Context.GenericTag<ReturnType<typeof make>>(
38
13
  "@confect/server/ActionRunner",
@@ -0,0 +1,12 @@
1
+ import { Schema } from "effect";
2
+
3
+ export class BlobNotFoundError extends Schema.TaggedError<BlobNotFoundError>()(
4
+ "BlobNotFoundError",
5
+ {
6
+ id: Schema.String,
7
+ },
8
+ ) {
9
+ override get message(): string {
10
+ return `File with ID '${this.id}' not found`;
11
+ }
12
+ }
package/src/CronJob.ts ADDED
@@ -0,0 +1,45 @@
1
+ import type { Ref } from "@confect/core";
2
+ import type { Cron, Duration } from "effect";
3
+ import { Predicate } from "effect";
4
+
5
+ export const TypeId = "@confect/server/CronJob";
6
+ export type TypeId = typeof TypeId;
7
+
8
+ export interface CronJob {
9
+ readonly [TypeId]: TypeId;
10
+
11
+ readonly identifier: string;
12
+ readonly schedule: Cron.Cron | Duration.Duration;
13
+ readonly ref: Ref.AnyMutation | Ref.AnyAction;
14
+ readonly args: Record<string, unknown>;
15
+ }
16
+
17
+ export const isCronJob = (u: unknown): u is CronJob =>
18
+ Predicate.hasProperty(u, TypeId);
19
+
20
+ type OptionalArgs<R extends Ref.AnyMutation | Ref.AnyAction> =
21
+ keyof Ref.Args<R> extends never ? [args?: Ref.Args<R>] : [args: Ref.Args<R>];
22
+
23
+ const Proto = {
24
+ [TypeId]: TypeId,
25
+ };
26
+
27
+ const makeProto = (
28
+ identifier: string,
29
+ schedule: Cron.Cron | Duration.Duration,
30
+ ref: Ref.AnyMutation | Ref.AnyAction,
31
+ args: Record<string, unknown>,
32
+ ): CronJob =>
33
+ Object.assign(Object.create(Proto), {
34
+ identifier,
35
+ schedule,
36
+ ref,
37
+ args,
38
+ });
39
+
40
+ export const make = <R extends Ref.AnyMutation | Ref.AnyAction>(
41
+ identifier: string,
42
+ schedule: Cron.Cron | Duration.Duration,
43
+ ref: R,
44
+ ...args: OptionalArgs<R>
45
+ ): CronJob => makeProto(identifier, schedule, ref, args[0] ?? {});
@@ -0,0 +1,147 @@
1
+ import { Ref } from "@confect/core";
2
+ import type { CronJob as ConvexCronJob } from "convex/server";
3
+ import { cronJobs as makeConvexCrons, type Crons } from "convex/server";
4
+ import {
5
+ Array,
6
+ Cron,
7
+ Duration,
8
+ Match,
9
+ Order,
10
+ pipe,
11
+ Predicate,
12
+ Record,
13
+ } from "effect";
14
+ import type * as CronJob from "./CronJob";
15
+
16
+ export const TypeId = "@confect/server/CronJobs";
17
+ export type TypeId = typeof TypeId;
18
+
19
+ export interface CronJobs {
20
+ readonly [TypeId]: TypeId;
21
+ readonly cronJobs: Record<string, CronJob.CronJob>;
22
+ readonly convexCronJobs: Crons;
23
+
24
+ add(cron: CronJob.CronJob): CronJobs;
25
+ }
26
+
27
+ export const isCronJobs = (u: unknown): u is CronJobs =>
28
+ Predicate.hasProperty(u, TypeId);
29
+
30
+ const Proto = {
31
+ [TypeId]: TypeId,
32
+
33
+ add(this: CronJobs, cronJob: CronJob.CronJob) {
34
+ const newConvexCrons = Object.assign(makeConvexCrons(), {
35
+ crons: { ...this.convexCronJobs.crons },
36
+ });
37
+
38
+ const functionReference = Ref.getFunctionReference(cronJob.ref);
39
+ const encodedArgs = Ref.encodeArgsSync(cronJob.ref, cronJob.args);
40
+
41
+ Match.value(cronJob.schedule).pipe(
42
+ Match.when(Cron.isCron, (cron) => {
43
+ newConvexCrons.cron(
44
+ cronJob.identifier,
45
+ cronToConvexCronString(cron),
46
+ functionReference,
47
+ encodedArgs,
48
+ );
49
+ }),
50
+ Match.when(Duration.isDuration, (duration) => {
51
+ newConvexCrons.interval(
52
+ cronJob.identifier,
53
+ durationToConvexIntervalSchedule(duration),
54
+ functionReference,
55
+ encodedArgs,
56
+ );
57
+ }),
58
+ Match.exhaustive,
59
+ );
60
+
61
+ return makeProto(
62
+ Record.set(this.cronJobs, cronJob.identifier, cronJob),
63
+ newConvexCrons,
64
+ );
65
+ },
66
+ };
67
+
68
+ const makeProto = (
69
+ cronJobs: Record<string, CronJob.CronJob>,
70
+ convexCronJobs: Crons,
71
+ ): CronJobs =>
72
+ Object.assign(Object.create(Proto), {
73
+ cronJobs,
74
+ convexCronJobs,
75
+ });
76
+
77
+ export const make = (): CronJobs => makeProto({}, makeConvexCrons());
78
+
79
+ /** @internal */
80
+ export const cronToConvexCronString = (cron: Cron.Cron): string => {
81
+ const hasNonDefaultSeconds = cron.seconds.size !== 1 || !cron.seconds.has(0);
82
+ if (hasNonDefaultSeconds) {
83
+ throw new Error(
84
+ "Convex cron expressions do not support a seconds field. " +
85
+ "The seconds field must be the default {0}. " +
86
+ "Sub-minute scheduling is supported only by interval schedules defined using a Duration.",
87
+ );
88
+ }
89
+
90
+ return Array.join(
91
+ [
92
+ setToField(cron.minutes),
93
+ setToField(cron.hours),
94
+ setToField(cron.days),
95
+ setToField(cron.months),
96
+ setToField(cron.weekdays),
97
+ ],
98
+ " ",
99
+ );
100
+ };
101
+
102
+ const setToField = (set: ReadonlySet<number>): string => {
103
+ if (set.size === 0) return "*";
104
+ return pipe(
105
+ set,
106
+ Array.sort(Order.number),
107
+ Array.map((n) => n.toString()),
108
+ Array.join(","),
109
+ );
110
+ };
111
+
112
+ /** @internal */
113
+ export const durationToConvexIntervalSchedule = (
114
+ duration: Duration.Duration,
115
+ ): IntervalSchedule => {
116
+ const millis = Duration.toMillis(duration);
117
+ if (millis <= 0) {
118
+ throw new Error("Interval must be a positive duration.");
119
+ }
120
+
121
+ const oneHourInMillis = Duration.hours(1).pipe(Duration.toMillis);
122
+ const hours = millis / oneHourInMillis;
123
+ if (Number.isInteger(hours)) {
124
+ return { type: "interval", hours };
125
+ }
126
+
127
+ const oneMinuteInMillis = Duration.minutes(1).pipe(Duration.toMillis);
128
+ const minutes = millis / oneMinuteInMillis;
129
+ if (Number.isInteger(minutes)) {
130
+ return { type: "interval", minutes };
131
+ }
132
+
133
+ const oneSecondInMillis = Duration.seconds(1).pipe(Duration.toMillis);
134
+ const seconds = millis / oneSecondInMillis;
135
+ if (Number.isInteger(seconds)) {
136
+ return { type: "interval", seconds };
137
+ }
138
+
139
+ throw new Error(
140
+ "Interval must be a whole number of seconds, minutes, or hours.",
141
+ );
142
+ };
143
+
144
+ type IntervalSchedule = Extract<
145
+ ConvexCronJob["schedule"],
146
+ { type: "interval" }
147
+ >;
package/src/Handler.ts CHANGED
@@ -15,11 +15,9 @@ import type * as QueryCtx from "./QueryCtx";
15
15
  import type * as QueryRunner from "./QueryRunner";
16
16
  import type * as RegisteredFunction from "./RegisteredFunction";
17
17
  import type * as Scheduler from "./Scheduler";
18
- import type {
19
- StorageActionWriter,
20
- StorageReader,
21
- StorageWriter,
22
- } from "./Storage";
18
+ import type { StorageActionWriter } from "./StorageActionWriter";
19
+ import type { StorageReader } from "./StorageReader";
20
+ import type { StorageWriter } from "./StorageWriter";
23
21
  import type * as VectorSearch from "./VectorSearch";
24
22
 
25
23
  export type Handler<
package/src/HttpApi.ts CHANGED
@@ -23,7 +23,9 @@ import * as ConvexConfigProvider from "./ConvexConfigProvider";
23
23
  import * as MutationRunner from "./MutationRunner";
24
24
  import * as QueryRunner from "./QueryRunner";
25
25
  import * as Scheduler from "./Scheduler";
26
- import { StorageActionWriter, StorageReader, StorageWriter } from "./Storage";
26
+ import { StorageActionWriter } from "./StorageActionWriter";
27
+ import { StorageReader } from "./StorageReader";
28
+ import { StorageWriter } from "./StorageWriter";
27
29
 
28
30
  type Middleware = (
29
31
  httpApp: HttpApp.Default,
@@ -1,38 +1,16 @@
1
1
  import * as Ref from "@confect/core/Ref";
2
2
  import { type GenericMutationCtx } from "convex/server";
3
- import type { ParseResult } from "effect";
4
- import { Context, Effect, Layer, Match, Schema } from "effect";
3
+ import { Context, Layer, Schema } from "effect";
5
4
 
6
5
  const make =
7
6
  (runMutation: GenericMutationCtx<any>["runMutation"]) =>
8
7
  <Mutation extends Ref.AnyMutation>(
9
8
  mutation: Mutation,
10
9
  args: Ref.Args<Mutation>,
11
- ): Effect.Effect<Ref.Returns<Mutation>, ParseResult.ParseError> =>
12
- Effect.gen(function* () {
13
- const functionSpec = Ref.getFunctionSpec(mutation);
14
- const functionName = Ref.getConvexFunctionName(mutation);
15
-
16
- return yield* Match.value(functionSpec.functionProvenance).pipe(
17
- Match.tag("Confect", (confectFunctionSpec) =>
18
- Effect.gen(function* () {
19
- const encodedArgs = yield* Schema.encode(confectFunctionSpec.args)(
20
- args,
21
- );
22
- const encodedReturns = yield* Effect.promise(() =>
23
- runMutation(functionName as any, encodedArgs),
24
- );
25
- return yield* Schema.decode(confectFunctionSpec.returns)(
26
- encodedReturns,
27
- );
28
- }),
29
- ),
30
- Match.tag("Convex", () =>
31
- Effect.promise(() => runMutation(functionName as any, args as any)),
32
- ),
33
- Match.exhaustive,
34
- );
35
- });
10
+ ) =>
11
+ Ref.runWithCodec(mutation, args, (functionReference, encodedArgs) =>
12
+ runMutation(functionReference, encodedArgs),
13
+ );
36
14
 
37
15
  export const MutationRunner = Context.GenericTag<ReturnType<typeof make>>(
38
16
  "@confect/server/MutationRunner",
@@ -1,4 +1,6 @@
1
1
  import type {
2
+ ExpressionOrValue,
3
+ FilterBuilder,
2
4
  OrderedQuery as ConvexOrderedQuery,
3
5
  PaginationResult,
4
6
  } from "convex/server";
@@ -28,10 +30,15 @@ export type OrderedQuery<
28
30
  TableInfo_["document"],
29
31
  Document.DocumentDecodeError
30
32
  >;
31
- readonly paginate: (options: {
32
- cursor: string | null;
33
- numItems: number;
34
- }) => Effect.Effect<
33
+ readonly paginate: (
34
+ options: {
35
+ cursor: string | null;
36
+ numItems: number;
37
+ },
38
+ filter?: (
39
+ q: FilterBuilder<TableInfo.ConvexTableInfo<TableInfo_>>,
40
+ ) => ExpressionOrValue<boolean>,
41
+ ) => Effect.Effect<
35
42
  PaginationResult<TableInfo_["document"]>,
36
43
  Document.DocumentDecodeError
37
44
  >;
@@ -73,10 +80,12 @@ export const make = <
73
80
  const collect: OrderedQueryFunction<"collect"> = () =>
74
81
  pipe(stream(), Stream.runCollect, Effect.map(Chunk.toReadonlyArray));
75
82
 
76
- const paginate: OrderedQueryFunction<"paginate"> = (options) =>
83
+ const paginate: OrderedQueryFunction<"paginate"> = (options, filter) =>
77
84
  Effect.gen(function* () {
85
+ const filteredQuery = filter !== undefined ? query.filter(filter) : query;
86
+
78
87
  const paginationResult = yield* Effect.promise(() =>
79
- query.paginate(options),
88
+ filteredQuery.paginate(options),
80
89
  );
81
90
 
82
91
  const parsedPage = yield* Effect.forEach(
@@ -1,38 +1,13 @@
1
1
  import * as Ref from "@confect/core/Ref";
2
2
  import { type GenericQueryCtx } from "convex/server";
3
- import type { ParseResult } from "effect";
4
- import { Context, Effect, Layer, Match, Schema } from "effect";
3
+ import { Context, Layer } from "effect";
5
4
 
6
5
  const make =
7
6
  (runQuery: GenericQueryCtx<any>["runQuery"]) =>
8
- <Query extends Ref.AnyQuery>(
9
- query: Query,
10
- args: Ref.Args<Query>,
11
- ): Effect.Effect<Ref.Returns<Query>, ParseResult.ParseError> =>
12
- Effect.gen(function* () {
13
- const functionSpec = Ref.getFunctionSpec(query);
14
- const functionName = Ref.getConvexFunctionName(query);
15
-
16
- return yield* Match.value(functionSpec.functionProvenance).pipe(
17
- Match.tag("Confect", (confectFunctionSpec) =>
18
- Effect.gen(function* () {
19
- const encodedArgs = yield* Schema.encode(confectFunctionSpec.args)(
20
- args,
21
- );
22
- const encodedReturns = yield* Effect.promise(() =>
23
- runQuery(functionName as any, encodedArgs),
24
- );
25
- return yield* Schema.decode(confectFunctionSpec.returns)(
26
- encodedReturns,
27
- );
28
- }),
29
- ),
30
- Match.tag("Convex", () =>
31
- Effect.promise(() => runQuery(functionName as any, args as any)),
32
- ),
33
- Match.exhaustive,
34
- );
35
- });
7
+ <Query extends Ref.AnyQuery>(query: Query, args: Ref.Args<Query>) =>
8
+ Ref.runWithCodec(query, args, (functionReference, encodedArgs) =>
9
+ runQuery(functionReference, encodedArgs),
10
+ );
36
11
 
37
12
  export const QueryRunner = Context.GenericTag<ReturnType<typeof make>>(
38
13
  "@confect/server/QueryRunner",