@confect/core 10.0.0-next.9 → 10.1.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 +964 -47
  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 +20 -19
  64. package/dist/SystemFields.d.ts.map +1 -1
  65. package/dist/SystemFields.js +22 -21
  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 +40 -42
  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
package/README.md CHANGED
@@ -5,7 +5,9 @@ Confect is a framework that deeply integrates Effect with Convex. It's more than
5
5
  - Define your Convex database schema using Effect schemas.
6
6
  - Write Convex function args and returns validators using Effect's schema library.
7
7
  - Use Confect functions to automatically decode and encode your data according to your Effect schema definitions for end-to-end rich types, from client to function to database (and back).
8
- - Use Effect's HTTP API modules to define your HTTP API(s). Includes interactive OpenAPI documentation powered by [Scalar](https://github.com/scalar/scalar).
8
+ - Add reusable, type-safe middleware to function groups or individual functions to provide Effect services and run logic around handlers.
9
+ - Declare typed errors on functions and middleware using Effect schemas, then handle the decoded errors at every call site.
10
+ - Use Effect's native HTTP API modules to define your HTTP API.
9
11
  - Access Convex platform capabilities via Effect services.
10
12
 
11
13
  Want to learn more? Read the [docs](https://confect.dev)!
@@ -1,122 +1,220 @@
1
1
  import type { DefaultFunctionArgs } from "convex/server";
2
- import type { Schema } from "effect";
3
2
  import * as Data from "effect/Data";
3
+ import * as Schema from "effect/Schema";
4
+ import * as PaginationOptions from "./PaginationOptions";
5
+ import * as PaginationResult from "./PaginationResult";
6
+ /**
7
+ * A field map accepted as Confect function args. Restricting each field to a
8
+ * context-free codec means the struct assembled from the fields can always be
9
+ * encoded and decoded synchronously at a Convex boundary.
10
+ */
11
+ export type ArgsFields = {
12
+ readonly [key: PropertyKey]: Schema.ConstraintCodec<any, any>;
13
+ };
14
+ /**
15
+ * A struct-shaped Confect args schema that keeps its exact field map while
16
+ * erasing the rest of `Schema.Struct`'s large implementation type. Decoded and
17
+ * encoded args are derived directly from `ArgsFields_`; keeping the runtime
18
+ * codec structural prevents every ref lookup from expanding the full Effect
19
+ * schema type.
20
+ */
21
+ export interface ArgsSchema<ArgsFields_ extends ArgsFields> extends Schema.Codec<any, any> {
22
+ readonly fields: ArgsFields_;
23
+ }
24
+ /**
25
+ * Erased structural view used after the exact field map is no longer needed.
26
+ */
27
+ export type AnyArgsSchema = ArgsSchema<ArgsFields>;
4
28
  export type FunctionProvenance = Data.TaggedEnum<{
5
29
  Confect: {
6
- args: Schema.Codec<any, any>;
30
+ args: AnyArgsSchema;
7
31
  returns: Schema.Codec<any, any>;
8
32
  error?: Schema.Codec<any, any>;
33
+ kind: ConfectKind;
34
+ };
35
+ Convex: {
36
+ "~args": DefaultFunctionArgs;
37
+ "~returns": any;
9
38
  };
10
- Convex: {};
11
39
  }>;
12
- export interface Confect<Args extends Schema.Codec<any, any>, Returns extends Schema.Codec<any, any>, Error extends Schema.Codec<any, any> = never> {
40
+ /**
41
+ * The declaration shape of a Confect function—orthogonal to both the provenance
42
+ * origin (Confect vs Convex) and the function type (query/mutation/action). A
43
+ * `Standard` function declares its args fields and returns schema directly; a
44
+ * `Paginated` function declares user-args fields and an item schema from which
45
+ * the Convex-facing `args`/`returns` are composed.
46
+ */
47
+ export type ConfectKind = Standard | Paginated;
48
+ export interface Standard {
49
+ readonly _tag: "Standard";
50
+ }
51
+ export interface Paginated<UserArgsFields_ extends ArgsFields = ArgsFields, Item extends Schema.Codec<any, any> = Schema.Codec<any, any>> {
52
+ readonly _tag: "Paginated";
53
+ /**
54
+ * User-declared args—no `paginationOpts`.
55
+ */
56
+ readonly userArgs: ArgsSchema<UserArgsFields_>;
57
+ /**
58
+ * Page element schema.
59
+ */
60
+ readonly item: Item;
61
+ /**
62
+ * Mutable array of items—the page decode target.
63
+ */
64
+ readonly page: Schema.Codec<any, any>;
65
+ }
66
+ export interface Confect<ArgsFields_ extends ArgsFields, Returns extends Schema.Codec<any, any>, Error extends Schema.Codec<any, any> = never, Kind extends ConfectKind = ConfectKind> {
13
67
  readonly _tag: "Confect";
14
- readonly args: Args;
68
+ readonly "~ArgsFields": ArgsFields_;
69
+ readonly args: ArgsSchema<ArgsFields_>;
15
70
  readonly returns: Returns;
16
71
  readonly error?: Error;
72
+ readonly kind: Kind;
17
73
  }
18
- export interface AnyConfect extends Confect<Schema.Codec<any, any>, Schema.Codec<any, any>, Schema.Codec<any, any>> {
74
+ export interface AnyConfect {
75
+ readonly _tag: "Confect";
76
+ readonly args: AnyArgsSchema;
77
+ readonly returns: Schema.Codec<any, any>;
78
+ readonly error?: Schema.Codec<any, any>;
79
+ readonly kind: ConfectKind;
19
80
  }
20
81
  export interface Convex<Args extends DefaultFunctionArgs, Returns> {
21
82
  readonly _tag: "Convex";
22
- readonly _args: Args;
23
- readonly _returns: Returns;
83
+ readonly "~args": Args;
84
+ readonly "~returns": Returns;
24
85
  }
25
86
  export interface AnyConvex extends Convex<DefaultFunctionArgs, any> {
26
87
  }
27
88
  export declare const FunctionProvenance: {
28
- readonly Confect: Data.TaggedEnum.ConstructorFrom<{
29
- readonly _tag: "Confect";
30
- readonly args: Schema.Codec<any, any>;
31
- readonly returns: Schema.Codec<any, any>;
32
- readonly error?: Schema.Codec<any, any>;
33
- }, "_tag">;
34
- readonly Convex: Data.TaggedEnum.ConstructorFrom<{
35
- readonly _tag: "Convex";
36
- readonly _args: DefaultFunctionArgs;
37
- readonly _returns: any;
38
- }, "_tag">;
39
89
  readonly $is: <Tag extends "Confect" | "Convex">(tag: Tag) => (u: unknown) => u is Extract<{
40
90
  readonly _tag: "Confect";
41
- readonly args: Schema.Codec<any, any>;
91
+ readonly args: AnyArgsSchema;
42
92
  readonly returns: Schema.Codec<any, any>;
43
93
  readonly error?: Schema.Codec<any, any>;
94
+ readonly kind: ConfectKind;
44
95
  }, {
45
96
  readonly _tag: Tag;
46
97
  }> | Extract<{
47
98
  readonly _tag: "Convex";
48
- readonly _args: DefaultFunctionArgs;
49
- readonly _returns: any;
99
+ readonly "~args": DefaultFunctionArgs;
100
+ readonly "~returns": any;
50
101
  }, {
51
102
  readonly _tag: Tag;
52
103
  }>;
53
104
  readonly $match: {
54
- <Cases extends {
55
- readonly Confect: (args: {
56
- readonly _tag: "Confect";
57
- readonly args: Schema.Codec<any, any>;
58
- readonly returns: Schema.Codec<any, any>;
59
- readonly error?: Schema.Codec<any, any>;
60
- }) => any;
61
- readonly Convex: (args: {
62
- readonly _tag: "Convex";
63
- readonly _args: DefaultFunctionArgs;
64
- readonly _returns: any;
65
- }) => any;
66
- }>(cases: Cases): (value: {
105
+ <Cases extends { readonly [Tag in "Confect" | "Convex"]: (args: Extract<{
106
+ readonly _tag: "Confect";
107
+ readonly args: AnyArgsSchema;
108
+ readonly returns: Schema.Codec<any, any>;
109
+ readonly error?: Schema.Codec<any, any>;
110
+ readonly kind: ConfectKind;
111
+ } | {
112
+ readonly _tag: "Convex";
113
+ readonly "~args": DefaultFunctionArgs;
114
+ readonly "~returns": any;
115
+ }, {
116
+ readonly _tag: Tag;
117
+ }>) => any; }>(cases: Cases): (value: {
67
118
  readonly _tag: "Confect";
68
- readonly args: Schema.Codec<any, any>;
119
+ readonly args: AnyArgsSchema;
69
120
  readonly returns: Schema.Codec<any, any>;
70
121
  readonly error?: Schema.Codec<any, any>;
122
+ readonly kind: ConfectKind;
71
123
  } | {
72
124
  readonly _tag: "Convex";
73
- readonly _args: DefaultFunctionArgs;
74
- readonly _returns: any;
125
+ readonly "~args": DefaultFunctionArgs;
126
+ readonly "~returns": any;
75
127
  }) => import("effect/Unify").Unify<ReturnType<Cases["Confect" | "Convex"]>>;
76
- <Cases extends {
77
- readonly Confect: (args: {
78
- readonly _tag: "Confect";
79
- readonly args: Schema.Codec<any, any>;
80
- readonly returns: Schema.Codec<any, any>;
81
- readonly error?: Schema.Codec<any, any>;
82
- }) => any;
83
- readonly Convex: (args: {
84
- readonly _tag: "Convex";
85
- readonly _args: DefaultFunctionArgs;
86
- readonly _returns: any;
87
- }) => any;
88
- }>(value: {
128
+ <Cases extends { readonly [Tag in "Confect" | "Convex"]: (args: Extract<{
129
+ readonly _tag: "Confect";
130
+ readonly args: AnyArgsSchema;
131
+ readonly returns: Schema.Codec<any, any>;
132
+ readonly error?: Schema.Codec<any, any>;
133
+ readonly kind: ConfectKind;
134
+ } | {
135
+ readonly _tag: "Convex";
136
+ readonly "~args": DefaultFunctionArgs;
137
+ readonly "~returns": any;
138
+ }, {
139
+ readonly _tag: Tag;
140
+ }>) => any; }>(value: {
89
141
  readonly _tag: "Confect";
90
- readonly args: Schema.Codec<any, any>;
142
+ readonly args: AnyArgsSchema;
91
143
  readonly returns: Schema.Codec<any, any>;
92
144
  readonly error?: Schema.Codec<any, any>;
145
+ readonly kind: ConfectKind;
93
146
  } | {
94
147
  readonly _tag: "Convex";
95
- readonly _args: DefaultFunctionArgs;
96
- readonly _returns: any;
148
+ readonly "~args": DefaultFunctionArgs;
149
+ readonly "~returns": any;
97
150
  }, cases: Cases): import("effect/Unify").Unify<ReturnType<Cases["Confect" | "Convex"]>>;
98
151
  };
152
+ readonly Confect: Data.TaggedEnum.ConstructorFrom<{
153
+ readonly _tag: "Confect";
154
+ readonly args: AnyArgsSchema;
155
+ readonly returns: Schema.Codec<any, any>;
156
+ readonly error?: Schema.Codec<any, any>;
157
+ readonly kind: ConfectKind;
158
+ }, "_tag">;
159
+ readonly Convex: Data.TaggedEnum.ConstructorFrom<{
160
+ readonly _tag: "Convex";
161
+ readonly "~args": DefaultFunctionArgs;
162
+ readonly "~returns": any;
163
+ }, "_tag">;
99
164
  };
100
165
  /**
101
- * Build a `Confect` provenance from lazy schema thunks. `args`, `returns`,
102
- * and `error` are exposed as sync lazy memoised getters (via {@link Lazy.defineProperty})
103
- * that only evaluate their thunk on first access, mirroring how `Table`
104
- * defers `Fields`/`Doc`/`tableDefinition`. This keeps importing the assembled
105
- * `_generated/spec.ts` cheap — no `Schema.Struct(...)` / `Schema.Array(...)`
106
- * work runs at module load; it is deferred to the first invocation that
107
- * actually compiles validators or runs a codec.
166
+ * Build a `Confect` provenance from lazy args-fields and schema thunks. `args`,
167
+ * `returns`, and `error` are exposed as sync lazy memoised getters (via
168
+ * {@link Lazy.defineProperty}) that only evaluate their thunk on first access,
169
+ * mirroring how `Table` defers `Fields`/`Doc`. This keeps importing the
170
+ * assembled `_generated/spec.ts` cheap—no
171
+ * `Schema.Struct(...)`/`Schema.Array(...)` work runs at module load; it is
172
+ * deferred to the first invocation that actually compiles validators or runs a
173
+ * codec.
108
174
  *
109
175
  * The object is built by hand rather than through `FunctionProvenance.Confect`
110
176
  * because the `Data` constructor copies its input with `Object.assign`, which
111
- * would force the getters at construction time and defeat the laziness.
112
- * `error` is only installed when an `errorThunk` is provided, so its absence
113
- * is observable via `"error" in provenance` without forcing anything; nothing
177
+ * would force the getters at construction time and defeat the laziness. `error`
178
+ * is only installed when an `errorThunk` is provided, so its absence is
179
+ * observable via `"error" in provenance` without forcing anything; nothing
114
180
  * relies on `Data`'s structural `Equal`/`Hash` for provenance values.
115
181
  */
116
- export declare const Confect: <Args extends Schema.Codec<any, any>, Returns extends Schema.Codec<any, any>, Error extends Schema.Codec<any, any> = never>(args: () => Args, returns: () => Returns, error?: () => Error) => Confect<Args, Returns, Error>;
117
- export declare const Convex: <_Args extends DefaultFunctionArgs, _Returns>() => {
182
+ export declare const Confect: <const ArgsFields_ extends ArgsFields, Returns extends Schema.Codec<any, any>, Error extends Schema.Codec<any, any> = never>(args: () => ArgsFields_, returns: () => Returns, error?: () => Error) => Confect<ArgsFields_, Returns, Error, Standard>;
183
+ /**
184
+ * The composed args schema of a paginated query: the user-declared fields plus
185
+ * the `paginationOpts` field managed by Convex's pagination protocol.
186
+ *
187
+ * The fields-first representation keeps the user-declared map available for
188
+ * type-level composition without reconstructing it from an erased schema.
189
+ */
190
+ export type PaginatedArgsFields<UserArgsFields extends ArgsFields> = UserArgsFields & {
191
+ readonly paginationOpts: typeof PaginationOptions.PaginationOptions;
192
+ };
193
+ export type PaginatedArgs<UserArgsFields extends ArgsFields> = Schema.Struct<PaginatedArgsFields<UserArgsFields>>;
194
+ /**
195
+ * The composed returns schema of a paginated query: a `PaginationResult` of the
196
+ * item schema. Same deferred-conditional device as {@link PaginatedArgs}.
197
+ */
198
+ export type PaginatedReturns<Item extends Schema.Codec<any, any>> = PaginationResult.PaginationResult<Item> extends infer ComposedReturns extends Schema.Codec<any, any> ? ComposedReturns : never;
199
+ export interface ConfectPaginated<UserArgsFields extends ArgsFields, Item extends Schema.Codec<any, any>, Error extends Schema.Codec<any, any> = never> extends Confect<PaginatedArgsFields<UserArgsFields>, PaginatedReturns<Item>, Error, Paginated<UserArgsFields, Item>> {
200
+ }
201
+ export interface AnyConfectPaginated extends AnyConfect {
202
+ readonly kind: Paginated;
203
+ }
204
+ /**
205
+ * Build the provenance of a paginated query from lazy schema thunks, with the
206
+ * same laziness contract as {@link Confect}. The user-facing schemas live on the
207
+ * `Paginated` kind (`kind.userArgs`, `kind.item`, `kind.page`)—the kind
208
+ * container is built eagerly (it is cheap) while the schemas inside it stay
209
+ * lazy. The composed Convex-facing `args`/`returns` are derived lazily from
210
+ * them: `args` spreads the user fields plus `paginationOpts`, and `returns`
211
+ * wraps the item in `PaginationResult`. Composition living here means the
212
+ * composed schemas can never drift from the stored user schemas.
213
+ */
214
+ export declare const ConfectPaginated: <const UserArgsFields_ extends ArgsFields, Item extends Schema.Codec<any, any>, Error extends Schema.Codec<any, any> = never>(userArgs: () => UserArgsFields_, item: () => Item, error?: () => Error) => ConfectPaginated<UserArgsFields_, Item, Error>;
215
+ export declare const Convex: <Args extends DefaultFunctionArgs, Returns>() => {
118
216
  readonly _tag: "Convex";
119
- readonly _args: DefaultFunctionArgs;
120
- readonly _returns: any;
217
+ readonly "~args": DefaultFunctionArgs;
218
+ readonly "~returns": any;
121
219
  };
122
220
  //# sourceMappingURL=FunctionProvenance.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionProvenance.d.ts","sourceRoot":"","sources":["../src/FunctionProvenance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AAGpC,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,UAAU,CAAC;IAC/C,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC7B,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAChC,KAAK,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;KAChC,CAAC;IACF,MAAM,EAAE,EAKP,CAAC;CACH,CAAC,CAAC;AAEH,MAAM,WAAW,OAAO,CACtB,IAAI,SAAS,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,EACnC,OAAO,SAAS,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,EACtC,KAAK,SAAS,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,KAAK;IAE5C,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;CACxB;AAED,MAAM,WAAW,UAAW,SAAQ,OAAO,CACzC,MAAM,CAAC,KA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AE,GAAG,CAAC,GAAG,KAAK,YAElC,MAAM,eAAe,QACzB,MAAM,IAAI,UACR,MAAM,KAAK,KAClB,gBAAgB,CAAC,eAAe,EAAE,IAAI,EAAE,KAAK,CAkC/C,CAAC;AAEF,eAAO,MAAM,MAAM,GAAI,IAAI,SAAS,mBAAmB,EAAE,OAAO;;sBA3MnD,mBAAmB;yBAChB,GAAG;CAgNhB,CAAC"}
@@ -1,38 +1,80 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
2
  import { defineProperty } from "./Lazy.js";
3
+ import { PaginationOptions } from "./PaginationOptions.js";
4
+ import { PaginationResult } from "./PaginationResult.js";
3
5
  import * as Data from "effect/Data";
6
+ import * as Schema from "effect/Schema";
4
7
  //#region src/FunctionProvenance.ts
5
8
  var FunctionProvenance_exports = /* @__PURE__ */ __exportAll({
6
9
  Confect: () => Confect,
10
+ ConfectPaginated: () => ConfectPaginated,
7
11
  Convex: () => Convex,
8
12
  FunctionProvenance: () => FunctionProvenance
9
13
  });
10
14
  const FunctionProvenance = Data.taggedEnum();
15
+ const Standard = { _tag: "Standard" };
11
16
  /**
12
- * Build a `Confect` provenance from lazy schema thunks. `args`, `returns`,
13
- * and `error` are exposed as sync lazy memoised getters (via {@link Lazy.defineProperty})
14
- * that only evaluate their thunk on first access, mirroring how `Table`
15
- * defers `Fields`/`Doc`/`tableDefinition`. This keeps importing the assembled
16
- * `_generated/spec.ts` cheap — no `Schema.Struct(...)` / `Schema.Array(...)`
17
- * work runs at module load; it is deferred to the first invocation that
18
- * actually compiles validators or runs a codec.
17
+ * Build a `Confect` provenance from lazy args-fields and schema thunks. `args`,
18
+ * `returns`, and `error` are exposed as sync lazy memoised getters (via
19
+ * {@link Lazy.defineProperty}) that only evaluate their thunk on first access,
20
+ * mirroring how `Table` defers `Fields`/`Doc`. This keeps importing the
21
+ * assembled `_generated/spec.ts` cheap—no
22
+ * `Schema.Struct(...)`/`Schema.Array(...)` work runs at module load; it is
23
+ * deferred to the first invocation that actually compiles validators or runs a
24
+ * codec.
19
25
  *
20
26
  * The object is built by hand rather than through `FunctionProvenance.Confect`
21
27
  * because the `Data` constructor copies its input with `Object.assign`, which
22
- * would force the getters at construction time and defeat the laziness.
23
- * `error` is only installed when an `errorThunk` is provided, so its absence
24
- * is observable via `"error" in provenance` without forcing anything; nothing
28
+ * would force the getters at construction time and defeat the laziness. `error`
29
+ * is only installed when an `errorThunk` is provided, so its absence is
30
+ * observable via `"error" in provenance` without forcing anything; nothing
25
31
  * relies on `Data`'s structural `Equal`/`Hash` for provenance values.
26
32
  */
27
33
  const Confect = (args, returns, error) => {
28
- const provenance = { _tag: "Confect" };
29
- defineProperty(provenance, "args", args);
34
+ const provenance = {
35
+ _tag: "Confect",
36
+ kind: Standard
37
+ };
38
+ defineProperty(provenance, "args", () => Schema.Struct(args()));
30
39
  defineProperty(provenance, "returns", returns);
31
40
  if (error !== void 0) defineProperty(provenance, "error", error);
32
41
  return provenance;
33
42
  };
43
+ /**
44
+ * Build the provenance of a paginated query from lazy schema thunks, with the
45
+ * same laziness contract as {@link Confect}. The user-facing schemas live on the
46
+ * `Paginated` kind (`kind.userArgs`, `kind.item`, `kind.page`)—the kind
47
+ * container is built eagerly (it is cheap) while the schemas inside it stay
48
+ * lazy. The composed Convex-facing `args`/`returns` are derived lazily from
49
+ * them: `args` spreads the user fields plus `paginationOpts`, and `returns`
50
+ * wraps the item in `PaginationResult`. Composition living here means the
51
+ * composed schemas can never drift from the stored user schemas.
52
+ */
53
+ const ConfectPaginated = (userArgs, item, error) => {
54
+ const kind = { _tag: "Paginated" };
55
+ const paginatedKind = kind;
56
+ defineProperty(kind, "userArgs", () => Schema.Struct(userArgs()));
57
+ defineProperty(kind, "item", item);
58
+ defineProperty(kind, "page", () => Schema.mutable(Schema.Array(paginatedKind.item)));
59
+ const provenance = {
60
+ _tag: "Confect",
61
+ kind: paginatedKind
62
+ };
63
+ const self = provenance;
64
+ defineProperty(provenance, "args", () => {
65
+ const fields = paginatedKind.userArgs.fields;
66
+ if ("paginationOpts" in fields) throw new globalThis.Error("A paginated query's args schema must not declare `paginationOpts`—it is added automatically from the `PaginationOptions` schema");
67
+ return Schema.Struct({
68
+ ...fields,
69
+ paginationOpts: PaginationOptions
70
+ });
71
+ });
72
+ defineProperty(provenance, "returns", () => PaginationResult(paginatedKind.item));
73
+ if (error !== void 0) defineProperty(provenance, "error", error);
74
+ return self;
75
+ };
34
76
  const Convex = () => FunctionProvenance.Convex({});
35
77
  //#endregion
36
- export { Confect, Convex, FunctionProvenance, FunctionProvenance_exports };
78
+ export { Confect, ConfectPaginated, Convex, FunctionProvenance, FunctionProvenance_exports };
37
79
 
38
80
  //# sourceMappingURL=FunctionProvenance.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionProvenance.js","names":[],"sources":["../src/FunctionProvenance.ts"],"sourcesContent":["import type { DefaultFunctionArgs } from \"convex/server\";\nimport type { Schema } from \"effect\";\nimport * as Data from \"effect/Data\";\nimport * as Lazy from \"./Lazy\";\n\nexport type FunctionProvenance = Data.TaggedEnum<{\n Confect: {\n args: Schema.Codec<any, any>;\n returns: Schema.Codec<any, any>;\n error?: Schema.Codec<any, any>;\n };\n Convex: {\n /** @internal */\n _args: DefaultFunctionArgs;\n /** @internal */\n _returns: any;\n };\n}>;\n\nexport interface Confect<\n Args extends Schema.Codec<any, any>,\n Returns extends Schema.Codec<any, any>,\n Error extends Schema.Codec<any, any> = never,\n> {\n readonly _tag: \"Confect\";\n readonly args: Args;\n readonly returns: Returns;\n readonly error?: Error;\n}\n\nexport interface AnyConfect extends Confect<\n Schema.Codec<any, any>,\n Schema.Codec<any, any>,\n Schema.Codec<any, any>\n> {}\n\nexport interface Convex<Args extends DefaultFunctionArgs, Returns> {\n readonly _tag: \"Convex\";\n readonly _args: Args;\n readonly _returns: Returns;\n}\n\nexport interface AnyConvex extends Convex<DefaultFunctionArgs, any> {}\n\nexport const FunctionProvenance = Data.taggedEnum<FunctionProvenance>();\n\n/**\n * Build a `Confect` provenance from lazy schema thunks. `args`, `returns`,\n * and `error` are exposed as sync lazy memoised getters (via {@link Lazy.defineProperty})\n * that only evaluate their thunk on first access, mirroring how `Table`\n * defers `Fields`/`Doc`/`tableDefinition`. This keeps importing the assembled\n * `_generated/spec.ts` cheap — no `Schema.Struct(...)` / `Schema.Array(...)`\n * work runs at module load; it is deferred to the first invocation that\n * actually compiles validators or runs a codec.\n *\n * The object is built by hand rather than through `FunctionProvenance.Confect`\n * because the `Data` constructor copies its input with `Object.assign`, which\n * would force the getters at construction time and defeat the laziness.\n * `error` is only installed when an `errorThunk` is provided, so its absence\n * is observable via `\"error\" in provenance` without forcing anything; nothing\n * relies on `Data`'s structural `Equal`/`Hash` for provenance values.\n */\nexport const Confect = <\n Args extends Schema.Codec<any, any>,\n Returns extends Schema.Codec<any, any>,\n Error extends Schema.Codec<any, any> = never,\n>(\n args: () => Args,\n returns: () => Returns,\n error?: () => Error,\n): Confect<Args, Returns, Error> => {\n const provenance = { _tag: \"Confect\" as const };\n\n Lazy.defineProperty(provenance, \"args\", args);\n Lazy.defineProperty(provenance, \"returns\", returns);\n if (error !== undefined) {\n Lazy.defineProperty(provenance, \"error\", error);\n }\n\n return provenance as Confect<Args, Returns, Error>;\n};\n\nexport const Convex = <_Args extends DefaultFunctionArgs, _Returns>() =>\n FunctionProvenance.Convex(\n {} as {\n _args: _Args;\n _returns: _Returns;\n },\n );\n"],"mappings":";;;;;;;;;AA4CA,MAAa,qBAAqB,KAAK,WAA+B;;;;;;;;;;;;;;;;;AAkBtE,MAAa,WAKX,MACA,SACA,UACkC;CAClC,MAAM,aAAa,EAAE,MAAM,UAAmB;CAE9C,eAAoB,YAAY,QAAQ,IAAI;CAC5C,eAAoB,YAAY,WAAW,OAAO;CAClD,IAAI,UAAU,KAAA,GACZ,eAAoB,YAAY,SAAS,KAAK;CAGhD,OAAO;AACT;AAEA,MAAa,eACX,mBAAmB,OACjB,CAAC,CAIH"}
1
+ {"version":3,"file":"FunctionProvenance.js","names":["PaginationOptions.PaginationOptions","PaginationResult.PaginationResult"],"sources":["../src/FunctionProvenance.ts"],"sourcesContent":["import type { DefaultFunctionArgs } from \"convex/server\";\nimport * as Data from \"effect/Data\";\nimport * as Schema from \"effect/Schema\";\nimport * as Lazy from \"./Lazy\";\nimport * as PaginationOptions from \"./PaginationOptions\";\nimport * as PaginationResult from \"./PaginationResult\";\n\n/**\n * A field map accepted as Confect function args. Restricting each field to a\n * context-free codec means the struct assembled from the fields can always be\n * encoded and decoded synchronously at a Convex boundary.\n */\nexport type ArgsFields = {\n readonly [key: PropertyKey]: Schema.ConstraintCodec<any, any>;\n};\n\n/**\n * A struct-shaped Confect args schema that keeps its exact field map while\n * erasing the rest of `Schema.Struct`'s large implementation type. Decoded and\n * encoded args are derived directly from `ArgsFields_`; keeping the runtime\n * codec structural prevents every ref lookup from expanding the full Effect\n * schema type.\n */\nexport interface ArgsSchema<\n ArgsFields_ extends ArgsFields,\n> extends Schema.Codec<any, any> {\n readonly fields: ArgsFields_;\n}\n\n/**\n * Erased structural view used after the exact field map is no longer needed.\n */\nexport type AnyArgsSchema = ArgsSchema<ArgsFields>;\n\nexport type FunctionProvenance = Data.TaggedEnum<{\n Confect: {\n args: AnyArgsSchema;\n returns: Schema.Codec<any, any>;\n error?: Schema.Codec<any, any>;\n kind: ConfectKind;\n };\n Convex: {\n \"~args\": DefaultFunctionArgs;\n \"~returns\": any;\n };\n}>;\n\n/**\n * The declaration shape of a Confect function—orthogonal to both the provenance\n * origin (Confect vs Convex) and the function type (query/mutation/action). A\n * `Standard` function declares its args fields and returns schema directly; a\n * `Paginated` function declares user-args fields and an item schema from which\n * the Convex-facing `args`/`returns` are composed.\n */\nexport type ConfectKind = Standard | Paginated;\n\nexport interface Standard {\n readonly _tag: \"Standard\";\n}\n\nexport interface Paginated<\n UserArgsFields_ extends ArgsFields = ArgsFields,\n Item extends Schema.Codec<any, any> = Schema.Codec<any, any>,\n> {\n readonly _tag: \"Paginated\";\n /**\n * User-declared args—no `paginationOpts`.\n */\n readonly userArgs: ArgsSchema<UserArgsFields_>;\n /**\n * Page element schema.\n */\n readonly item: Item;\n /**\n * Mutable array of items—the page decode target.\n */\n readonly page: Schema.Codec<any, any>;\n}\n\nexport interface Confect<\n ArgsFields_ extends ArgsFields,\n Returns extends Schema.Codec<any, any>,\n Error extends Schema.Codec<any, any> = never,\n Kind extends ConfectKind = ConfectKind,\n> {\n readonly _tag: \"Confect\";\n readonly \"~ArgsFields\": ArgsFields_;\n readonly args: ArgsSchema<ArgsFields_>;\n readonly returns: Returns;\n readonly error?: Error;\n readonly kind: Kind;\n}\n\nexport interface AnyConfect {\n readonly _tag: \"Confect\";\n readonly args: AnyArgsSchema;\n readonly returns: Schema.Codec<any, any>;\n readonly error?: Schema.Codec<any, any>;\n readonly kind: ConfectKind;\n}\n\nexport interface Convex<Args extends DefaultFunctionArgs, Returns> {\n readonly _tag: \"Convex\";\n readonly \"~args\": Args;\n readonly \"~returns\": Returns;\n}\n\nexport interface AnyConvex extends Convex<DefaultFunctionArgs, any> {}\n\nexport const FunctionProvenance = Data.taggedEnum<FunctionProvenance>();\n\nconst Standard: Standard = { _tag: \"Standard\" };\n\n/**\n * Build a `Confect` provenance from lazy args-fields and schema thunks. `args`,\n * `returns`, and `error` are exposed as sync lazy memoised getters (via\n * {@link Lazy.defineProperty}) that only evaluate their thunk on first access,\n * mirroring how `Table` defers `Fields`/`Doc`. This keeps importing the\n * assembled `_generated/spec.ts` cheap—no\n * `Schema.Struct(...)`/`Schema.Array(...)` work runs at module load; it is\n * deferred to the first invocation that actually compiles validators or runs a\n * codec.\n *\n * The object is built by hand rather than through `FunctionProvenance.Confect`\n * because the `Data` constructor copies its input with `Object.assign`, which\n * would force the getters at construction time and defeat the laziness. `error`\n * is only installed when an `errorThunk` is provided, so its absence is\n * observable via `\"error\" in provenance` without forcing anything; nothing\n * relies on `Data`'s structural `Equal`/`Hash` for provenance values.\n */\nexport const Confect = <\n const ArgsFields_ extends ArgsFields,\n Returns extends Schema.Codec<any, any>,\n Error extends Schema.Codec<any, any> = never,\n>(\n args: () => ArgsFields_,\n returns: () => Returns,\n error?: () => Error,\n): Confect<ArgsFields_, Returns, Error, Standard> => {\n const provenance = { _tag: \"Confect\" as const, kind: Standard };\n\n Lazy.defineProperty(provenance, \"args\", () => Schema.Struct(args()));\n Lazy.defineProperty(provenance, \"returns\", returns);\n if (error !== undefined) {\n Lazy.defineProperty(provenance, \"error\", error);\n }\n\n return provenance as Confect<ArgsFields_, Returns, Error, Standard>;\n};\n\n/**\n * The composed args schema of a paginated query: the user-declared fields plus\n * the `paginationOpts` field managed by Convex's pagination protocol.\n *\n * The fields-first representation keeps the user-declared map available for\n * type-level composition without reconstructing it from an erased schema.\n */\nexport type PaginatedArgsFields<UserArgsFields extends ArgsFields> =\n UserArgsFields & {\n readonly paginationOpts: typeof PaginationOptions.PaginationOptions;\n };\n\nexport type PaginatedArgs<UserArgsFields extends ArgsFields> = Schema.Struct<\n PaginatedArgsFields<UserArgsFields>\n>;\n\n/**\n * The composed returns schema of a paginated query: a `PaginationResult` of the\n * item schema. Same deferred-conditional device as {@link PaginatedArgs}.\n */\nexport type PaginatedReturns<Item extends Schema.Codec<any, any>> =\n PaginationResult.PaginationResult<Item> extends infer ComposedReturns extends\n Schema.Codec<any, any>\n ? ComposedReturns\n : never;\n\nexport interface ConfectPaginated<\n UserArgsFields extends ArgsFields,\n Item extends Schema.Codec<any, any>,\n Error extends Schema.Codec<any, any> = never,\n> extends Confect<\n PaginatedArgsFields<UserArgsFields>,\n PaginatedReturns<Item>,\n Error,\n Paginated<UserArgsFields, Item>\n> {}\n\nexport interface AnyConfectPaginated extends AnyConfect {\n readonly kind: Paginated;\n}\n\n/**\n * Build the provenance of a paginated query from lazy schema thunks, with the\n * same laziness contract as {@link Confect}. The user-facing schemas live on the\n * `Paginated` kind (`kind.userArgs`, `kind.item`, `kind.page`)—the kind\n * container is built eagerly (it is cheap) while the schemas inside it stay\n * lazy. The composed Convex-facing `args`/`returns` are derived lazily from\n * them: `args` spreads the user fields plus `paginationOpts`, and `returns`\n * wraps the item in `PaginationResult`. Composition living here means the\n * composed schemas can never drift from the stored user schemas.\n */\nexport const ConfectPaginated = <\n const UserArgsFields_ extends ArgsFields,\n Item extends Schema.Codec<any, any>,\n Error extends Schema.Codec<any, any> = never,\n>(\n userArgs: () => UserArgsFields_,\n item: () => Item,\n error?: () => Error,\n): ConfectPaginated<UserArgsFields_, Item, Error> => {\n const kind = { _tag: \"Paginated\" as const };\n const paginatedKind = kind as Paginated<UserArgsFields_, Item>;\n\n Lazy.defineProperty(kind, \"userArgs\", () => Schema.Struct(userArgs()));\n Lazy.defineProperty(kind, \"item\", item);\n Lazy.defineProperty(kind, \"page\", () =>\n Schema.mutable(Schema.Array(paginatedKind.item)),\n );\n\n const provenance = { _tag: \"Confect\" as const, kind: paginatedKind };\n const self = provenance as ConfectPaginated<UserArgsFields_, Item, Error>;\n\n Lazy.defineProperty(provenance, \"args\", () => {\n const fields = paginatedKind.userArgs.fields;\n if (\"paginationOpts\" in fields) {\n throw new globalThis.Error(\n \"A paginated query's args schema must not declare `paginationOpts`—\" +\n \"it is added automatically from the `PaginationOptions` schema\",\n );\n }\n return Schema.Struct({\n ...fields,\n paginationOpts: PaginationOptions.PaginationOptions,\n });\n });\n Lazy.defineProperty(provenance, \"returns\", () =>\n PaginationResult.PaginationResult(paginatedKind.item),\n );\n if (error !== undefined) {\n Lazy.defineProperty(provenance, \"error\", error);\n }\n\n return self;\n};\n\nexport const Convex = <Args extends DefaultFunctionArgs, Returns>() =>\n FunctionProvenance.Convex(\n {} as {\n \"~args\": Args;\n \"~returns\": Returns;\n },\n );\n"],"mappings":";;;;;;;;;;;;;AA6GA,MAAa,qBAAqB,KAAK,WAA+B;AAEtE,MAAM,WAAqB,EAAE,MAAM,WAAW;;;;;;;;;;;;;;;;;;AAmB9C,MAAa,WAKX,MACA,SACA,UACmD;CACnD,MAAM,aAAa;EAAE,MAAM;EAAoB,MAAM;CAAS;CAE9D,eAAoB,YAAY,cAAc,OAAO,OAAO,KAAK,CAAC,CAAC;CACnE,eAAoB,YAAY,WAAW,OAAO;CAClD,IAAI,UAAU,KAAA,GACZ,eAAoB,YAAY,SAAS,KAAK;CAGhD,OAAO;AACT;;;;;;;;;;;AAqDA,MAAa,oBAKX,UACA,MACA,UACmD;CACnD,MAAM,OAAO,EAAE,MAAM,YAAqB;CAC1C,MAAM,gBAAgB;CAEtB,eAAoB,MAAM,kBAAkB,OAAO,OAAO,SAAS,CAAC,CAAC;CACrE,eAAoB,MAAM,QAAQ,IAAI;CACtC,eAAoB,MAAM,cACxB,OAAO,QAAQ,OAAO,MAAM,cAAc,IAAI,CAAC,CACjD;CAEA,MAAM,aAAa;EAAE,MAAM;EAAoB,MAAM;CAAc;CACnE,MAAM,OAAO;CAEb,eAAoB,YAAY,cAAc;EAC5C,MAAM,SAAS,cAAc,SAAS;EACtC,IAAI,oBAAoB,QACtB,MAAM,IAAI,WAAW,MACnB,iIAEF;EAEF,OAAO,OAAO,OAAO;GACnB,GAAG;GACH,gBAAgBA;EAClB,CAAC;CACH,CAAC;CACD,eAAoB,YAAY,iBAC9BC,iBAAkC,cAAc,IAAI,CACtD;CACA,IAAI,UAAU,KAAA,GACZ,eAAoB,YAAY,SAAS,KAAK;CAGhD,OAAO;AACT;AAEA,MAAa,eACX,mBAAmB,OACjB,CAAC,CAIH"}