@confect/core 9.0.1 → 9.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.
package/CHANGELOG.md CHANGED
@@ -1,11 +1,18 @@
1
1
  # @confect/core
2
2
 
3
+ ## 9.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 4d8a568: Add `withOptimisticUpdate` to `@confect/react`'s `useMutation`, mirroring Convex's API. The mutation handle returned by `useMutation` is now both callable and exposes `.withOptimisticUpdate(fn)` for attaching an optimistic update. Inside the callback, the `OptimisticLocalStore`'s `getQuery`/`setQuery`/`getAllQueries` accept Confect query `Ref`s and operate on decoded (Effect Schema) values wrapped in `Option`; the wrapper handles encoding/decoding against Convex's local store.
8
+
9
+ ## 9.0.2
10
+
3
11
  ## 9.0.1
4
12
 
5
13
  ### Patch Changes
6
14
 
7
15
  - 445ea9b: Loosen and align dependency ranges across all packages:
8
-
9
16
  - The `convex` peer dependency is now `^1.32.0` in every package (previously pinned exactly to `1.39.1`, or `^1.30.0` in `@confect/react`). The range is validated against convex 1.32.0 through 1.40.0.
10
17
  - `@confect/server`'s `@effect/platform-node` peer dependency is now optional — it is only needed when using the `@confect/server/node` entrypoint.
11
18
  - `@confect/cli` now uses caret ranges for its `@effect/platform` and `@effect/platform-node` dependencies so they can deduplicate with the versions resolved for `@confect/server`, and no longer declares an unused direct dependency on `@effect/platform-node-shared`.
@@ -22,7 +29,6 @@
22
29
  ### Filesystem-driven groups
23
30
 
24
31
  Your API is now authored as colocated `*.spec.ts`/`*.impl.ts` pairs, one pair per group, and **the file's path within `confect/` is the group's name** (its stem for top-level groups, the dot-joined directory path for nested groups). `GroupSpec.make()` and `GroupSpec.makeNode()` no longer take a name argument.
25
-
26
32
  - Each `*.spec.ts` `export default`s its `GroupSpec` (named co-exports like error classes are still allowed).
27
33
  - Each `*.impl.ts` default-imports its sibling spec, passes it to `FunctionImpl.make` / `GroupImpl.make`, and ends the layer pipeline with `GroupImpl.finalize`—a compile-time completeness check that only typechecks once every function the spec declares has a `FunctionImpl` provided.
28
34
  - The root `confect/spec.ts`, `confect/impl.ts`, `confect/nodeSpec.ts`, and `confect/nodeImpl.ts` files are gone, along with `Impl.make` and `Impl.finalize`. `confect codegen` deletes any of these (and the stale aggregate `_generated/registeredFunctions.ts` / `_generated/nodeRegisteredFunctions.ts`) on upgrade.
@@ -42,12 +48,11 @@
42
48
  Schema.Struct({
43
49
  userId: Schema.optional(Id("users")),
44
50
  text: Schema.String,
45
- })
51
+ }),
46
52
  );
47
53
  ```
48
54
 
49
55
  Codegen emits, alongside it:
50
-
51
56
  - `_generated/schema.ts`—the runtime `DatabaseSchema`. Never imports `convex/server`, so a runtime cold start no longer evaluates `defineSchema(...)`.
52
57
  - `_generated/convexSchema.ts`—the Convex deploy `SchemaDefinition`, re-exported from `convex/schema.ts`.
53
58
  - `_generated/id.ts`—a type-safe `Id` constructor whose argument is constrained to your table names. Use `Id("notes")` everywhere you previously wrote `GenericId.GenericId("notes")`; cross-table `_id` typos are now caught at compile time.
@@ -67,7 +72,7 @@
67
72
  name: "list",
68
73
  args: Schema.Struct({}),
69
74
  returns: Schema.Array(Notes.Doc),
70
- })
75
+ }),
71
76
  );
72
77
  ```
73
78
 
@@ -86,7 +91,7 @@
86
91
  name: "list",
87
92
  args: () => Schema.Struct({}),
88
93
  returns: () => Schema.Array(notes.Doc),
89
- })
94
+ }),
90
95
  );
91
96
  ```
92
97
 
@@ -97,14 +102,13 @@
97
102
  const list = FunctionImpl.make(databaseSchema, notes, "list", handler);
98
103
  export default GroupImpl.make(databaseSchema, notes).pipe(
99
104
  Layer.provide(list),
100
- GroupImpl.finalize
105
+ GroupImpl.finalize,
101
106
  );
102
107
  ```
103
108
 
104
109
  ### Node functions are first-class
105
110
 
106
111
  A group's runtime is now declared solely by its spec—`GroupSpec.makeNode()` for a Node action group, `GroupSpec.make()` otherwise—mirroring vanilla Convex's per-file `"use node"` directive. The separate `node` namespace is gone: Node specs/impls are ordinary colocated pairs that can live anywhere in `confect/`, and codegen emits the `"use node"` directive based on the spec.
107
-
108
112
  - A Node group at `confect/email.spec.ts` is now reached at `refs.public.email.send` instead of `refs.public.node.email.send`.
109
113
  - `@confect/core` removes `Spec.makeNode`, `Spec.merge`, and `Spec.isConvexSpec` / `Spec.isNodeSpec`; `Spec.make()` is a single mixed-runtime container and `Refs.make(spec)` takes one argument. `GroupSpec.makeNode()`, `FunctionSpec.publicNodeAction()` / `internalNodeAction()` are unchanged.
110
114
 
@@ -121,7 +125,6 @@
121
125
  The codegen bundler now uses [`bundle-require`](https://github.com/egoist/bundle-require), so impls may import third-party packages and use `tsconfig.json` `paths` aliases (`~/*`, `@/*`, …) for their own source. A parent `confect/{path}.spec.ts` may now declare functions alongside a sibling `confect/{path}/` subdirectory of further specs, and codegen reports a clear error on a name collision between the two.
122
126
 
123
127
  ### Migration
124
-
125
128
  1. **Tables.** Delete `confect/schema.ts`. Rename each table file to a valid JS identifier (e.g. `confect/tables/notes.ts`); the basename becomes the table name. Drop the name argument from `Table.make`, wrap the field struct in `() =>`, and replace `GenericId.GenericId("x")` with `Id("x")` from `_generated/id`. If you read `table.name` off a bound table, rename it to `table.tableName`.
126
129
  2. **Specs.** Split each group into a colocated `*.spec.ts` that `export default`s `GroupSpec.make()` (no name). Wrap every `args`/`returns`/`error` in `() =>`. Import a table's `Doc`/`Fields` from its wrapper, `import notes from "./_generated/tables/notes"`.
127
130
  3. **Impls.** In each `*.impl.ts`, default-import the sibling spec, import `databaseSchema` from `_generated/schema`, pass it to `FunctionImpl.make` / `GroupImpl.make` in place of `api`, end the pipeline with `GroupImpl.finalize`, and `export default` it. Delete the root `confect/spec.ts`, `impl.ts`, `nodeSpec.ts`, and `nodeImpl.ts` (codegen will also remove them).
@@ -157,13 +160,11 @@
157
160
  The `node` namespace existed only because the pre-v9 architecture aggregated every function's impl into one module that all generated `convex/` modules imported; Node functions had to be quarantined into a separate spec/impl/registry tree so Convex-runtime functions wouldn't transitively import Node-only code. v9's per-group isolation removed that constraint, so the namespace was no longer load-bearing — only ergonomic overhead that diverged from vanilla Convex (which identifies Node modules per-file, with no directory requirement).
158
161
 
159
162
  ### Breaking changes
160
-
161
163
  - **API namespace removed.** A Node group at `confect/email.spec.ts` is now referenced as `refs.public.email.send` instead of `refs.public.node.email.send`. Node groups are ordinary groups in the refs tree, nesting preserved like any other group.
162
164
  - **Generated layout changed.** Node modules are emitted at `convex/<path>.ts` (carrying `"use node"`) instead of `convex/node/<path>.ts`, and their registries at `confect/_generated/registeredFunctions/<path>.ts`. The single assembled `confect/_generated/spec.ts` now contains every group regardless of runtime; `confect/_generated/nodeSpec.ts` is no longer generated (codegen deletes any stale copy on upgrade).
163
165
  - **`@confect/core` API.** Removed `Spec.makeNode`, `Spec.merge`, and `Spec.isConvexSpec`/`Spec.isNodeSpec`. `Spec` is now a single mixed-runtime container (`Spec.make()` accepts groups of any runtime). `Refs.make(spec)` takes a single argument (the unified spec) instead of `(convexSpec, nodeSpec)`. `GroupSpec.makeNode()`/`makeNodeAt()` and `FunctionSpec.publicNodeAction()`/`internalNodeAction()` are unchanged; `GroupSpec` subgroups may now be of any runtime (a group is just a namespace for its children).
164
166
 
165
167
  ### Migration
166
-
167
168
  1. Move any `confect/node/<path>.spec.ts`/`.impl.ts` files to wherever you want them under `confect/` (e.g. `confect/<path>.spec.ts`); the `node/` directory has no special meaning anymore. Their specs already use `GroupSpec.makeNode()`, so no spec-body change is needed — only fix the impl's relative import of `_generated/schema` if its depth changed.
168
169
  2. Update call sites to drop the `node` segment: `refs.public.node.<group>.<fn>` → `refs.public.<group>.<fn>`.
169
170
  3. Replace `Refs.make(spec, nodeSpec)` with `Refs.make(spec)` (codegen does this for `_generated/refs.ts` automatically).
@@ -270,7 +271,6 @@
270
271
  Previously, `confect/schema.ts` was user-authored and `DatabaseSchema` carried a `convexSchemaDefinition` field that was eagerly rebuilt on every `.addTable(...)`. That field was an `O(n²)` allocation for `n` tables, and it forced both the deploy CLI (which only needs `defineSchema(...)`) and the runtime (which only needs the table codec lookup) through the same module — so any runtime function bundle dragged in `convex/server`'s `defineSchema`. Issue 1.
271
272
 
272
273
  Codegen now scans `confect/tables/*.ts` (every file must default-export a `Table`) and emits two siblings:
273
-
274
274
  - `confect/_generated/schema.ts` — the runtime `DatabaseSchema`, consumed by `_generated/api.ts`. Imports `@confect/server` but never `convex/server`.
275
275
  - `confect/_generated/convexSchema.ts` — the Convex deploy `SchemaDefinition`, re-exported one-line from `convex/schema.ts`. Imports `convex/server` but never `@confect/server`.
276
276
 
@@ -283,7 +283,6 @@
283
283
  This eliminates a class of subtle infelicities: the file basename and the table name can never drift out of sync, cross-table `_id` references are type-constrained against the actual set of declared tables (catching typos at compile time), and ESM cycle hazards for mutual cross-table `Id` references are gone because authoring files no longer transitively import each other.
284
284
 
285
285
  Codegen now emits two new sets of files alongside `_generated/schema.ts` and `_generated/convexSchema.ts`:
286
-
287
286
  - `confect/_generated/id.ts` — a single `Id` constructor whose argument is type-constrained to the union of your table names. Use `Id("notes")` everywhere you previously wrote `GenericId.GenericId("notes")`.
288
287
  - `confect/_generated/tables/<name>.ts` — one thin wrapper per table that binds the unnamed value from `confect/tables/<name>.ts` to its filename. This is what other modules (specs, impls, HTTP handlers) default-import to reach a table's `Doc`, `Fields`, and `tableName`.
289
288
 
@@ -300,7 +299,6 @@
300
299
  The bound `Table` now exposes `Fields` / `Doc` / `tableDefinition` as lazy getters that compute their value on first access, then replace themselves with a plain non-writable data property so second-and-subsequent accesses are observably indistinguishable from a plain property (and skip all function-call overhead). The result: a function bundle only pays the schema-construction cost for tables it actually touches via `db.table(name)` (which reaches `Fields` through `Document.decode`). The `UnnamedTable` callable no longer exposes `Fields` or `tableDefinition` — read these off the bound `Table` (the generated `_generated/tables/<name>.ts` wrapper already binds the name).
301
300
 
302
301
  ### Migration
303
-
304
302
  1. Delete your `confect/schema.ts`. Codegen will refuse to run while a stray copy is present.
305
303
  2. Rename each `confect/tables/<Name>.ts` to a valid JS identifier in your chosen casing convention (e.g. `confect/tables/notes.ts`). The basename becomes the table name; you no longer pass it as an argument.
306
304
  3. Convert each table file to a **default-export-only** unnamed module: drop the name argument from `Table.make`, wrap the field-schema struct in a `() => ...` callback, and switch any `GenericId.GenericId("users")` references to `Id("users")` imported from `../_generated/id`:
@@ -376,7 +374,6 @@
376
374
  Since `9.0.0-next.1`, codegen has wrapped every parent leaf that has sibling subdirectory specs in `<parent>.addGroupAt("child", <child>)`. Because `GroupSpec.addGroupAt` is immutable, that produced a fresh object in the assembled tree, while the parent's `*.impl.ts` continued to hold a reference to the original imported leaf. The runtime resolver compared by `===`, so every such impl failed `validateImpl` with "Could not resolve group path for the provided GroupSpec." Child impls happened to work only because `GroupSpec.withName` was secretly mutating its argument in place to keep the child's identity stable — an asymmetry that was load-bearing for one half of the API and broken for the other.
377
375
 
378
376
  ### What changed
379
-
380
377
  - `@confect/core/Spec` carries a new `readonly paths: ReadonlyMap<GroupSpec.AnyWithProps, string>` field and exposes a chainable `Spec#addPath(group, path)` builder. `add` / `addAt` / `merge` propagate `paths` unchanged; `merge` re-prefixes a node spec's entries with `"node."` to match the merged tree.
381
378
  - `@confect/core/GroupSpec.withName` is now pure: it returns a fresh copy when the name differs and no longer rewrites the input in place. No new identity-tracking machinery is introduced.
382
379
  - `@confect/server/FunctionImpl.make` and `GroupImpl.make` resolve their group path via `api.spec.paths.get(group)` — an O(1) map lookup instead of a tree walk — and throw a clearer error pointing at `Spec.addPath` when the spec hasn't been registered.
@@ -384,7 +381,6 @@
384
381
  - `@confect/cli` codegen emits one `.addPath(<binding>, "<dot.path>")` call per leaf in `_generated/spec.ts` (and `_generated/nodeSpec.ts`) so the imported leaves carry their full paths into the assembled spec value.
385
382
 
386
383
  ### User-facing impact
387
-
388
384
  - Spec authoring (`*.spec.ts`) and impl authoring (`*.impl.ts`) APIs are unchanged. `FunctionImpl.make(api, spec, name, handler)` and `GroupImpl.make(api, spec)` keep their exact signatures.
389
385
  - Generated `_generated/spec.ts` (and `_generated/nodeSpec.ts`) pick up one `.addPath(...)` chain entry per leaf on the next `confect codegen` run. The shape is fully immutable — no module-load mutation, no hidden side effects.
390
386
  - Hand-rolled tests that construct a `Spec` and pass it to `Api.make` must now also call `.addPath(spec, "dot.path")` for any group they intend to look up.
@@ -412,7 +408,6 @@
412
408
  Splitting impl across colocated `*.impl.ts` files is the vehicle for fixing that. With this change, `confect codegen` emits one `_generated/registeredFunctions/{path}.ts` per group, and each generated `convex/` module imports only its own group's per-group registry — which in turn imports only its own sibling `.impl.ts`. A Convex function's cold-start bundle now scales with its own group's impl rather than with the size of the whole project.
413
409
 
414
410
  ### Breaking changes
415
-
416
411
  - `GroupSpec.make()` and `GroupSpec.makeNode()` no longer take a name argument; the group name is derived from the spec file's path within `confect/`.
417
412
  - `FunctionImpl.make(api, groupSpec, fn, handler)` and `GroupImpl.make(api, groupSpec)` now take the imported sibling spec object as their second argument instead of a dot-path string.
418
413
  - Every `GroupImpl` pipeline must end with `GroupImpl.finalize`, which only typechecks once every function declared by the spec has a corresponding `FunctionImpl` provided to the group layer. `GroupImpl.finalize` snapshots the names of every registered function onto the produced `Finalized` `GroupImpl` service value, and `confect codegen` reads those names to verify per-function coverage against the spec at runtime.
@@ -421,7 +416,6 @@
421
416
  - Every module under `convex/` is re-emitted to import from `_generated/registeredFunctions/{path}` instead of the previous aggregate file. Users who commit `convex/` to source control should expect a full rewrite of that directory on first codegen.
422
417
 
423
418
  ### Migration
424
-
425
419
  1. For each existing group, create a colocated `confect/{path}.spec.ts` and `confect/{path}.impl.ts` pair (under a subdirectory for nested groups).
426
420
  - In each spec, call `GroupSpec.make()` (or `GroupSpec.makeNode()`) without a name and `export default` the result.
427
421
  - In each impl, default-import the sibling spec (e.g. `import notes from "./notes.spec"`), pass it to `FunctionImpl.make`/`GroupImpl.make` in place of the previous dot-path string, append `GroupImpl.finalize` to the pipeline, and `export default` the resulting `GroupImpl` layer:
@@ -429,7 +423,7 @@
429
423
  export default GroupImpl.make(api, notes).pipe(
430
424
  Layer.provide(list),
431
425
  Layer.provide(insert),
432
- GroupImpl.finalize
426
+ GroupImpl.finalize,
433
427
  );
434
428
  ```
435
429
  2. Delete root `confect/spec.ts`, `confect/impl.ts`, `confect/nodeSpec.ts`, `confect/nodeImpl.ts`, and any parent aggregator spec/impl files. (`confect codegen` will also delete any of these it finds, plus the stale `_generated/registeredFunctions.ts` and `_generated/nodeRegisteredFunctions.ts`, so this step can be skipped.)
@@ -467,7 +461,7 @@
467
461
 
468
462
  export class NoteNotFound extends Schema.TaggedError<NoteNotFound>()(
469
463
  "NoteNotFound",
470
- { noteId: GenericId.GenericId("notes") }
464
+ { noteId: GenericId.GenericId("notes") },
471
465
  ) {}
472
466
 
473
467
  export const notes = GroupSpec.make("notes").addFunction(
@@ -476,7 +470,7 @@
476
470
  args: Schema.Struct({ noteId: GenericId.GenericId("notes") }),
477
471
  returns: Notes.Doc,
478
472
  error: NoteNotFound,
479
- })
473
+ }),
480
474
  );
481
475
  ```
482
476
 
@@ -496,7 +490,7 @@
496
490
  .table("notes")
497
491
  .get(noteId)
498
492
  .pipe(Effect.mapError(() => new NoteNotFound({ noteId })));
499
- })
493
+ }),
500
494
  );
501
495
  ```
502
496
 
@@ -568,7 +562,6 @@
568
562
  Unspecified failures continue to reject the promise.
569
563
 
570
564
  ### Migration
571
-
572
565
  - For each `useQuery` call site, replace `result === undefined` checks and direct property access with `QueryResult.match` (or the lower-level `QueryResult.isLoading`/`isSuccess`/`isFailure` predicates).
573
566
  - For each `useMutation`/`useAction` call site whose ref now declares an `error` schema, unwrap the resolved `Either` (e.g. with `Either.match`); call sites against refs without an `error` schema need no change.
574
567
 
package/dist/Ref.d.ts CHANGED
@@ -54,6 +54,8 @@ export declare const hasErrorSchema: (ref: Any) => boolean;
54
54
  export declare const encodeArgs: <Ref_ extends Any>(ref: Ref_, args: Args<Ref_>) => Effect.Effect<unknown, ParseResult.ParseError>;
55
55
  export declare const decodeReturns: <Ref_ extends Any>(ref: Ref_, returns: unknown) => Effect.Effect<Returns<Ref_>, ParseResult.ParseError>;
56
56
  export declare const encodeArgsSync: <Ref_ extends Any>(ref: Ref_, args: Args<Ref_>) => unknown;
57
+ export declare const decodeArgsSync: <Ref_ extends Any>(ref: Ref_, encodedArgs: unknown) => Args<Ref_>;
58
+ export declare const encodeReturnsSync: <Ref_ extends Any>(ref: Ref_, returns: Returns<Ref_>) => unknown;
57
59
  export declare const decodeReturnsSync: <Ref_ extends Any>(ref: Ref_, encodedReturns: unknown) => Returns<Ref_>;
58
60
  export declare const isConvexError: (error: unknown) => error is ConvexError<Value>;
59
61
  /**
package/dist/Ref.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Ref.d.ts","sourceRoot":"","sources":["../src/Ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,IAAI,uBAAuB,EAC5C,kBAAkB,EACnB,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,KAAK,YAAY,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,KAAK,sBAAsB,MAAM,0BAA0B,CAAC;AAExE,MAAM,WAAW,GAAG,CAClB,uBAAuB,SAAS,sBAAsB,CAAC,sBAAsB,EAC7E,mBAAmB,SAAS,kBAAkB,EAC9C,KAAK,EACL,QAAQ,EACR,MAAM,GAAG,KAAK;IAEd,QAAQ,CAAC,uBAAuB,CAAC,EAAE,uBAAuB,CAAC;IAC3D,QAAQ,CAAC,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IACnD,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IACvB,QAAQ,CA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J;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,IAAI,SAAS,GAAG,EAC1C,KAAK,IAAI,EACT,cAAc,OAAO,KACpB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,WAAW,CAAC,UAAU,CAYhE,CAAC;AAEJ;;;GAGG;AACH,eAAO,MAAM,eAAe,GAAI,IAAI,SAAS,GAAG,EAC9C,KAAK,IAAI,EACT,cAAc,OAAO,KACpB,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAazB,CAAC;AAEJ,eAAO,MAAM,oBAAoB,GAAI,IAAI,SAAS,GAAG,EACnD,KAAK,IAAI,EACT,OAAO,OAAO,KACb,OAWQ,CAAC;AAEZ;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,GAAI,IAAI,SAAS,GAAG,EAAE,CAAC,GAAG,KAAK,EACtD,KAAK,IAAI,EACT,MAAM,IAAI,CAAC,IAAI,CAAC,EAChB,MAAM,CACJ,iBAAiB,EAAE,iBAAiB,CAAC,IAAI,CAAC,EAC1C,WAAW,EAAE,OAAO,KACjB,WAAW,CAAC,OAAO,CAAC,EACzB,kBAAkB,CAAC,KAAK,EAAE,OAAO,KAAK,CAAC,KACtC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,UAAU,CAqCpE,CAAC"}
package/dist/Ref.js CHANGED
@@ -8,6 +8,7 @@ import * as Option from "effect/Option";
8
8
 
9
9
  //#region src/Ref.ts
10
10
  var Ref_exports = /* @__PURE__ */ __exportAll({
11
+ decodeArgsSync: () => decodeArgsSync,
11
12
  decodeError: () => decodeError,
12
13
  decodeErrorOrElse: () => decodeErrorOrElse,
13
14
  decodeErrorSync: () => decodeErrorSync,
@@ -15,6 +16,7 @@ var Ref_exports = /* @__PURE__ */ __exportAll({
15
16
  decodeReturnsSync: () => decodeReturnsSync,
16
17
  encodeArgs: () => encodeArgs,
17
18
  encodeArgsSync: () => encodeArgsSync,
19
+ encodeReturnsSync: () => encodeReturnsSync,
18
20
  getConvexFunctionName: () => getConvexFunctionName,
19
21
  getFunctionReference: () => getFunctionReference,
20
22
  hasErrorSchema: () => hasErrorSchema,
@@ -41,6 +43,8 @@ const hasErrorSchema = (ref) => Match.value(ref.functionSpec.functionProvenance)
41
43
  const encodeArgs = (ref, args) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => Schema.encode(confectFunctionProvenance.args)(args)), Match.tag("Convex", () => Effect.succeed(args)), Match.exhaustive);
42
44
  const decodeReturns = (ref, returns) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => Schema.decode(confectFunctionProvenance.returns)(returns)), Match.tag("Convex", () => Effect.succeed(returns)), Match.exhaustive);
43
45
  const encodeArgsSync = (ref, args) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => Schema.encodeSync(confectFunctionProvenance.args)(args)), Match.tag("Convex", () => args), Match.exhaustive);
46
+ const decodeArgsSync = (ref, encodedArgs) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => Schema.decodeSync(confectFunctionProvenance.args)(encodedArgs)), Match.tag("Convex", () => encodedArgs), Match.exhaustive);
47
+ const encodeReturnsSync = (ref, returns) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => Schema.encodeSync(confectFunctionProvenance.returns)(returns)), Match.tag("Convex", () => returns), Match.exhaustive);
44
48
  const decodeReturnsSync = (ref, encodedReturns) => Match.value(ref.functionSpec.functionProvenance).pipe(Match.tag("Confect", (confectFunctionProvenance) => Schema.decodeSync(confectFunctionProvenance.returns)(encodedReturns)), Match.tag("Convex", () => encodedReturns), Match.exhaustive);
45
49
  const ConvexErrorIdentifier = Symbol.for("ConvexError");
46
50
  const isConvexError = (error) => error instanceof ConvexError || typeof error === "object" && error !== null && ConvexErrorIdentifier in error;
@@ -103,5 +107,5 @@ const runWithCodec = (ref, args, call, mapUnknownError) => Effect.gen(function*
103
107
  });
104
108
 
105
109
  //#endregion
106
- export { Ref_exports, decodeError, decodeErrorOrElse, decodeErrorSync, decodeReturns, decodeReturnsSync, encodeArgs, encodeArgsSync, getConvexFunctionName, getFunctionReference, hasErrorSchema, isConvexError, make, maybeDecodeErrorSync, runWithCodec };
110
+ export { Ref_exports, decodeArgsSync, decodeError, decodeErrorOrElse, decodeErrorSync, decodeReturns, decodeReturnsSync, encodeArgs, encodeArgsSync, encodeReturnsSync, getConvexFunctionName, getFunctionReference, hasErrorSchema, isConvexError, make, maybeDecodeErrorSync, runWithCodec };
107
111
  //# sourceMappingURL=Ref.js.map
package/dist/Ref.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Ref.js","names":[],"sources":["../src/Ref.ts"],"sourcesContent":["import type {\n FunctionReference as ConvexFunctionReference,\n FunctionVisibility,\n} from \"convex/server\";\nimport { makeFunctionReference } from \"convex/server\";\nimport type { Value } from \"convex/values\";\nimport { ConvexError } from \"convex/values\";\nimport type { ParseResult } from \"effect\";\nimport * as Effect from \"effect/Effect\";\nimport * as Match from \"effect/Match\";\nimport * as Option from \"effect/Option\";\nimport * as Schema from \"effect/Schema\";\nimport type * as FunctionSpec from \"./FunctionSpec\";\nimport type * as RuntimeAndFunctionType from \"./RuntimeAndFunctionType\";\n\nexport interface Ref<\n _RuntimeAndFunctionType extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n _FunctionVisibility extends FunctionVisibility,\n _Args,\n _Returns,\n _Error = never,\n> {\n readonly _RuntimeAndFunctionType?: _RuntimeAndFunctionType;\n readonly _FunctionVisibility?: _FunctionVisibility;\n readonly _Args?: _Args;\n readonly _Returns?: _Returns;\n readonly _Error?: _Error;\n /** @internal */\n readonly functionSpec: FunctionSpec.AnyWithProps;\n /** @internal */\n readonly functionNamespace: string;\n}\n\nexport interface Any extends Ref<any, any, any, any, any> {}\n\nexport interface AnyInternal extends Ref<any, \"internal\", any, any, any> {}\n\nexport interface AnyPublic extends Ref<any, \"public\", any, any, any> {}\n\nexport interface AnyQuery extends Ref<\n RuntimeAndFunctionType.AnyQuery,\n FunctionVisibility,\n any,\n any,\n any\n> {}\n\nexport interface AnyMutation extends Ref<\n RuntimeAndFunctionType.AnyMutation,\n FunctionVisibility,\n any,\n any,\n any\n> {}\n\nexport interface AnyAction extends Ref<\n RuntimeAndFunctionType.AnyAction,\n FunctionVisibility,\n any,\n any,\n any\n> {}\n\nexport interface AnyPublicQuery extends Ref<\n RuntimeAndFunctionType.AnyQuery,\n \"public\",\n any,\n any,\n any\n> {}\n\nexport interface AnyPublicMutation extends Ref<\n RuntimeAndFunctionType.AnyMutation,\n \"public\",\n any,\n any,\n any\n> {}\n\nexport interface AnyPublicAction extends Ref<\n RuntimeAndFunctionType.AnyAction,\n \"public\",\n any,\n any,\n any\n> {}\n\nexport type GetRuntimeAndFunctionType<Ref_> =\n Ref_ extends Ref<\n infer RuntimeAndFunctionType_,\n infer _FunctionVisibility,\n infer _Args,\n infer _Returns,\n infer _Error\n >\n ? RuntimeAndFunctionType_\n : never;\n\nexport type GetRuntime<Ref_> =\n Ref_ extends Ref<\n infer RuntimeAndFunctionType_,\n infer _FunctionVisibility,\n infer _Args,\n infer _Returns,\n infer _Error\n >\n ? RuntimeAndFunctionType.GetRuntime<RuntimeAndFunctionType_>\n : never;\n\nexport type GetFunctionType<Ref_> =\n Ref_ extends Ref<\n infer RuntimeAndFunctionType_,\n infer _FunctionVisibility,\n infer _Args,\n infer _Returns,\n infer _Error\n >\n ? RuntimeAndFunctionType.GetFunctionType<RuntimeAndFunctionType_>\n : never;\n\nexport type GetFunctionVisibility<Ref_> =\n Ref_ extends Ref<\n infer _RuntimeAndFunctionType,\n infer FunctionVisibility_,\n infer _Args,\n infer _Returns,\n infer _Error\n >\n ? FunctionVisibility_\n : never;\n\nexport type Args<Ref_> =\n Ref_ extends Ref<\n infer _RuntimeAndFunctionType,\n infer _FunctionVisibility,\n infer Args_,\n infer _Returns,\n infer _Error\n >\n ? Args_\n : never;\n\nexport type OptionalArgs<Ref_ extends Any> = keyof Args<Ref_> extends never\n ? [args?: Args<Ref_>]\n : [args: Args<Ref_>];\n\nexport type Returns<Ref_> =\n Ref_ extends Ref<\n infer _RuntimeAndFunctionType,\n infer _FunctionVisibility,\n infer _Args,\n infer Returns_,\n infer _Error\n >\n ? Returns_\n : never;\n\nexport type Error<Ref_> =\n Ref_ extends Ref<\n infer _RuntimeAndFunctionType,\n infer _FunctionVisibility,\n infer _Args,\n infer _Returns,\n infer Error_\n >\n ? Error_\n : never;\n\nexport type FunctionReference<Ref_ extends Any> = ConvexFunctionReference<\n GetFunctionType<Ref_>,\n GetFunctionVisibility<Ref_>\n>;\n\nexport type FromFunctionSpec<FunctionSpec_ extends FunctionSpec.AnyWithProps> =\n Ref<\n FunctionSpec.GetRuntimeAndFunctionType<FunctionSpec_>,\n FunctionSpec.GetFunctionVisibility<FunctionSpec_>,\n FunctionSpec.Args<FunctionSpec_>,\n FunctionSpec.Returns<FunctionSpec_>,\n FunctionSpec.Error<FunctionSpec_>\n >;\n\nexport const make = <FunctionSpec_ extends FunctionSpec.AnyWithProps>(\n /**\n * The namespace portion of a Convex function name, i.e. the part before the\n * colon. For example, for `myGroupDir/myGroupMod:myFunc` this would be\n * `myGroupDir/myGroupMod`.\n */\n functionNamespace: string,\n functionSpec: FunctionSpec_,\n): FromFunctionSpec<FunctionSpec_> => ({ functionSpec, functionNamespace });\n\nexport const getConvexFunctionName = (ref: Any): string =>\n `${ref.functionNamespace}:${ref.functionSpec.name}`;\n\nconst functionReferenceCache = new Map<string, FunctionReference<Any>>();\n\nexport const getFunctionReference = <Ref_ extends Any>(\n ref: Ref_,\n): FunctionReference<Ref_> => {\n const functionName = getConvexFunctionName(ref);\n\n const cached = functionReferenceCache.get(functionName);\n if (cached !== undefined) {\n return cached as FunctionReference<Ref_>;\n }\n\n const functionReference = makeFunctionReference(functionName);\n functionReferenceCache.set(functionName, functionReference);\n\n return functionReference as FunctionReference<Ref_>;\n};\n\nexport const hasErrorSchema = (ref: Any): boolean =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\n \"Confect\",\n (confectFunctionProvenance) => \"error\" in confectFunctionProvenance,\n ),\n Match.tag(\"Convex\", () => false),\n Match.exhaustive,\n );\n\nexport const encodeArgs = <Ref_ extends Any>(\n ref: Ref_,\n args: Args<Ref_>,\n): Effect.Effect<unknown, ParseResult.ParseError> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Schema.encode(confectFunctionProvenance.args)(args),\n ),\n Match.tag(\"Convex\", () => Effect.succeed(args)),\n Match.exhaustive,\n );\n\nexport const decodeReturns = <Ref_ extends Any>(\n ref: Ref_,\n returns: unknown,\n): Effect.Effect<Returns<Ref_>, ParseResult.ParseError> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Schema.decode(confectFunctionProvenance.returns)(returns),\n ),\n Match.tag(\"Convex\", () => Effect.succeed(returns)),\n Match.exhaustive,\n );\n\nexport const encodeArgsSync = <Ref_ extends Any>(\n ref: Ref_,\n args: Args<Ref_>,\n): unknown =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Schema.encodeSync(confectFunctionProvenance.args)(args),\n ),\n Match.tag(\"Convex\", () => args),\n Match.exhaustive,\n );\n\nexport const decodeReturnsSync = <Ref_ extends Any>(\n ref: Ref_,\n encodedReturns: unknown,\n): Returns<Ref_> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Schema.decodeSync(confectFunctionProvenance.returns)(encodedReturns),\n ),\n Match.tag(\"Convex\", () => encodedReturns),\n Match.exhaustive,\n ) as Returns<Ref_>;\n\nconst ConvexErrorIdentifier = Symbol.for(\"ConvexError\");\n\nexport const isConvexError = (error: unknown): error is ConvexError<Value> =>\n error instanceof ConvexError ||\n (typeof error === \"object\" &&\n error !== null &&\n ConvexErrorIdentifier in error);\n\n/**\n * Build a callback-style handler that decodes the ref's typed error from a\n * caught `ConvexError`, or else forwards the value to `mapUnknownError`. The\n * fallback is also invoked when the input *is* a `ConvexError` but the ref\n * doesn't declare a typed-error schema—by definition such a value falls\n * outside the ref's error contract. Useful when adapting non-Effect APIs (e.g.\n * emitter callbacks for streamed subscriptions) to the same error semantics\n * that `runWithCodec` provides.\n */\nexport const decodeErrorOrElse =\n <Ref_ extends Any, E>(ref: Ref_, mapUnknownError: (error: unknown) => E) =>\n (error: unknown): Error<Ref_> | E => {\n if (isConvexError(error)) {\n const decoded = decodeErrorSync(ref, error.data);\n if (Option.isSome(decoded)) {\n return decoded.value;\n }\n }\n return mapUnknownError(error);\n };\n\n/**\n * Decode `encodedError` against the ref's error schema. Returns `None` if the\n * ref doesn't declare a typed error (Confect ref without an `error` schema, or\n * a Convex-provenance ref)—by definition there's nothing to decode the value\n * into, and the caller is responsible for deciding what to do (typically:\n * surface the original value as a defect).\n */\nexport const decodeError = <Ref_ extends Any>(\n ref: Ref_,\n encodedError: unknown,\n): Effect.Effect<Option.Option<Error<Ref_>>, ParseResult.ParseError> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n \"error\" in confectFunctionProvenance\n ? Effect.map(\n Schema.decode(confectFunctionProvenance.error)(encodedError),\n Option.some,\n )\n : Effect.succeed(Option.none<Error<Ref_>>()),\n ),\n Match.tag(\"Convex\", () => Effect.succeed(Option.none<Error<Ref_>>())),\n Match.exhaustive,\n );\n\n/**\n * Synchronous counterpart to `decodeError`. Throws on schema decode failure;\n * returns `None` when the ref doesn't declare a typed error.\n */\nexport const decodeErrorSync = <Ref_ extends Any>(\n ref: Ref_,\n encodedError: unknown,\n): Option.Option<Error<Ref_>> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n \"error\" in confectFunctionProvenance\n ? Option.some(\n Schema.decodeSync(confectFunctionProvenance.error)(\n encodedError,\n ) as Error<Ref_>,\n )\n : Option.none<Error<Ref_>>(),\n ),\n Match.tag(\"Convex\", () => Option.none<Error<Ref_>>()),\n Match.exhaustive,\n );\n\nexport const maybeDecodeErrorSync = <Ref_ extends Any>(\n ref: Ref_,\n error: unknown,\n): unknown =>\n isConvexError(error)\n ? Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n \"error\" in confectFunctionProvenance\n ? Schema.decodeSync(confectFunctionProvenance.error)(error.data)\n : error,\n ),\n Match.tag(\"Convex\", () => error),\n Match.exhaustive,\n )\n : error;\n\n/**\n * Encode args via the ref's args schema, invoke `call`, decode returns via the\n * ref's returns schema, and translate any thrown `ConvexError` into the ref's\n * typed error. Anything else the Promise rejects with—network failures,\n * server-side runtime errors, validation failures, etc.—is passed to\n * `mapUnknownError` to be turned into a typed `E`, or surfaced as a defect when\n * no handler is provided.\n */\nexport const runWithCodec = <Ref_ extends Any, E = never>(\n ref: Ref_,\n args: Args<Ref_>,\n call: (\n functionReference: FunctionReference<Ref_>,\n encodedArgs: unknown,\n ) => PromiseLike<unknown>,\n mapUnknownError?: (error: unknown) => E,\n): Effect.Effect<Returns<Ref_>, E | Error<Ref_> | ParseResult.ParseError> =>\n Effect.gen(function* () {\n const functionReference = getFunctionReference(ref);\n const functionProvenance = ref.functionSpec.functionProvenance;\n const invoke = (\n encodedArgs: unknown,\n ): Effect.Effect<unknown, Error<Ref_> | E> =>\n Effect.tryPromise({\n try: () => Promise.resolve(call(functionReference, encodedArgs)),\n catch: (error): Error<Ref_> | E => {\n if (isConvexError(error)) {\n const decoded = decodeErrorSync(ref, error.data);\n if (Option.isSome(decoded)) {\n return decoded.value;\n }\n }\n if (mapUnknownError !== undefined) {\n return mapUnknownError(error);\n }\n throw error;\n },\n });\n return yield* Match.value(functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Effect.gen(function* () {\n const encodedArgs = yield* Schema.encode(\n confectFunctionProvenance.args,\n )(args);\n const encodedReturns = yield* invoke(encodedArgs);\n return yield* Schema.decode(confectFunctionProvenance.returns)(\n encodedReturns,\n );\n }),\n ),\n Match.tag(\"Convex\", () => invoke(args)),\n Match.exhaustive,\n );\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAsLA,MAAa,QAMX,mBACA,kBACqC;CAAE;CAAc;CAAmB;AAE1E,MAAa,yBAAyB,QACpC,GAAG,IAAI,kBAAkB,GAAG,IAAI,aAAa;AAE/C,MAAM,yCAAyB,IAAI,KAAqC;AAExE,MAAa,wBACX,QAC4B;CAC5B,MAAM,eAAe,sBAAsB,IAAI;CAE/C,MAAM,SAAS,uBAAuB,IAAI,aAAa;AACvD,KAAI,WAAW,OACb,QAAO;CAGT,MAAM,oBAAoB,sBAAsB,aAAa;AAC7D,wBAAuB,IAAI,cAAc,kBAAkB;AAE3D,QAAO;;AAGT,MAAa,kBAAkB,QAC7B,MAAM,MAAM,IAAI,aAAa,mBAAmB,CAAC,KAC/C,MAAM,IACJ,YACC,8BAA8B,WAAW,0BAC3C,EACD,MAAM,IAAI,gBAAgB,MAAM,EAChC,MAAM,WACP;AAEH,MAAa,cACX,KACA,SAEA,MAAM,MAAM,IAAI,aAAa,mBAAmB,CAAC,KAC/C,MAAM,IAAI,YAAY,8BACpB,OAAO,OAAO,0BAA0B,KAAK,CAAC,KAAK,CACpD,EACD,MAAM,IAAI,gBAAgB,OAAO,QAAQ,KAAK,CAAC,EAC/C,MAAM,WACP;AAEH,MAAa,iBACX,KACA,YAEA,MAAM,MAAM,IAAI,aAAa,mBAAmB,CAAC,KAC/C,MAAM,IAAI,YAAY,8BACpB,OAAO,OAAO,0BA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B,WAAW,4BACP,OAAO,KACL,OAAO,WAAW,0BAA0B,MAAM,CAChD,aACD,CACF,GACD,OAAO,MAAmB,CAC/B,EACD,MAAM,IAAI,gBAAgB,OAAO,MAAmB,CAAC,EACrD,MAAM,WACP;AAEH,MAAa,wBACX,KACA,UAEA,cAAc,MAAM,GAChB,MAAM,MAAM,IAAI,aAAa,mBAAmB,CAAC,KAC/C,MAAM,IAAI,YAAY,8BACpB,WAAW,4BACP,OAAO,WAAW,0BAA0B,MAAM,CAAC,MAAM,KAAK,GAC9D,MACL,EACD,MAAM,IAAI,gBAAgB,MAAM,EAChC,MAAM,WACP,GACD;;;;;;;;;AAUN,MAAa,gBACX,KACA,MACA,MAIA,oBAEA,OAAO,IAAI,aAAa;CACtB,MAAM,oBAAoB,qBAAqB,IAAI;CACnD,MAAM,qBAAqB,IAAI,aAAa;CAC5C,MAAM,UACJ,gBAEA,OAAO,WAAW;EAChB,WAAW,QAAQ,QAAQ,KAAK,mBAAmB,YAAY,CAAC;EAChE,QAAQ,UAA2B;AACjC,OAAI,cAAc,MAAM,EAAE;IACxB,MAAM,UAAU,gBAAgB,KAAK,MAAM,KAAK;AAChD,QAAI,OAAO,OAAO,QAAQ,CACxB,QAAO,QAAQ;;AAGnB,OAAI,oBAAoB,OACtB,QAAO,gBAAgB,MAAM;AAE/B,SAAM;;EAET,CAAC;AACJ,QAAO,OAAO,MAAM,MAAM,mBAAmB,CAAC,KAC5C,MAAM,IAAI,YAAY,8BACpB,OAAO,IAAI,aAAa;EAItB,MAAM,iBAAiB,OAAO,OAHV,OAAO,OAAO,OAChC,0BAA0B,KAC3B,CAAC,KAAK,CAC0C;AACjD,SAAO,OAAO,OAAO,OAAO,0BAA0B,QAAQ,CAC5D,eACD;GACD,CACH,EACD,MAAM,IAAI,gBAAgB,OAAO,KAAK,CAAC,EACvC,MAAM,WACP;EACD"}
1
+ {"version":3,"file":"Ref.js","names":[],"sources":["../src/Ref.ts"],"sourcesContent":["import type {\n FunctionReference as ConvexFunctionReference,\n FunctionVisibility,\n} from \"convex/server\";\nimport { makeFunctionReference } from \"convex/server\";\nimport type { Value } from \"convex/values\";\nimport { ConvexError } from \"convex/values\";\nimport type { ParseResult } from \"effect\";\nimport * as Effect from \"effect/Effect\";\nimport * as Match from \"effect/Match\";\nimport * as Option from \"effect/Option\";\nimport * as Schema from \"effect/Schema\";\nimport type * as FunctionSpec from \"./FunctionSpec\";\nimport type * as RuntimeAndFunctionType from \"./RuntimeAndFunctionType\";\n\nexport interface Ref<\n _RuntimeAndFunctionType extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n _FunctionVisibility extends FunctionVisibility,\n _Args,\n _Returns,\n _Error = never,\n> {\n readonly _RuntimeAndFunctionType?: _RuntimeAndFunctionType;\n readonly _FunctionVisibility?: _FunctionVisibility;\n readonly _Args?: _Args;\n readonly _Returns?: _Returns;\n readonly _Error?: _Error;\n /** @internal */\n readonly functionSpec: FunctionSpec.AnyWithProps;\n /** @internal */\n readonly functionNamespace: string;\n}\n\nexport interface Any extends Ref<any, any, any, any, any> {}\n\nexport interface AnyInternal extends Ref<any, \"internal\", any, any, any> {}\n\nexport interface AnyPublic extends Ref<any, \"public\", any, any, any> {}\n\nexport interface AnyQuery extends Ref<\n RuntimeAndFunctionType.AnyQuery,\n FunctionVisibility,\n any,\n any,\n any\n> {}\n\nexport interface AnyMutation extends Ref<\n RuntimeAndFunctionType.AnyMutation,\n FunctionVisibility,\n any,\n any,\n any\n> {}\n\nexport interface AnyAction extends Ref<\n RuntimeAndFunctionType.AnyAction,\n FunctionVisibility,\n any,\n any,\n any\n> {}\n\nexport interface AnyPublicQuery extends Ref<\n RuntimeAndFunctionType.AnyQuery,\n \"public\",\n any,\n any,\n any\n> {}\n\nexport interface AnyPublicMutation extends Ref<\n RuntimeAndFunctionType.AnyMutation,\n \"public\",\n any,\n any,\n any\n> {}\n\nexport interface AnyPublicAction extends Ref<\n RuntimeAndFunctionType.AnyAction,\n \"public\",\n any,\n any,\n any\n> {}\n\nexport type GetRuntimeAndFunctionType<Ref_> =\n Ref_ extends Ref<\n infer RuntimeAndFunctionType_,\n infer _FunctionVisibility,\n infer _Args,\n infer _Returns,\n infer _Error\n >\n ? RuntimeAndFunctionType_\n : never;\n\nexport type GetRuntime<Ref_> =\n Ref_ extends Ref<\n infer RuntimeAndFunctionType_,\n infer _FunctionVisibility,\n infer _Args,\n infer _Returns,\n infer _Error\n >\n ? RuntimeAndFunctionType.GetRuntime<RuntimeAndFunctionType_>\n : never;\n\nexport type GetFunctionType<Ref_> =\n Ref_ extends Ref<\n infer RuntimeAndFunctionType_,\n infer _FunctionVisibility,\n infer _Args,\n infer _Returns,\n infer _Error\n >\n ? RuntimeAndFunctionType.GetFunctionType<RuntimeAndFunctionType_>\n : never;\n\nexport type GetFunctionVisibility<Ref_> =\n Ref_ extends Ref<\n infer _RuntimeAndFunctionType,\n infer FunctionVisibility_,\n infer _Args,\n infer _Returns,\n infer _Error\n >\n ? FunctionVisibility_\n : never;\n\nexport type Args<Ref_> =\n Ref_ extends Ref<\n infer _RuntimeAndFunctionType,\n infer _FunctionVisibility,\n infer Args_,\n infer _Returns,\n infer _Error\n >\n ? Args_\n : never;\n\nexport type OptionalArgs<Ref_ extends Any> = keyof Args<Ref_> extends never\n ? [args?: Args<Ref_>]\n : [args: Args<Ref_>];\n\nexport type Returns<Ref_> =\n Ref_ extends Ref<\n infer _RuntimeAndFunctionType,\n infer _FunctionVisibility,\n infer _Args,\n infer Returns_,\n infer _Error\n >\n ? Returns_\n : never;\n\nexport type Error<Ref_> =\n Ref_ extends Ref<\n infer _RuntimeAndFunctionType,\n infer _FunctionVisibility,\n infer _Args,\n infer _Returns,\n infer Error_\n >\n ? Error_\n : never;\n\nexport type FunctionReference<Ref_ extends Any> = ConvexFunctionReference<\n GetFunctionType<Ref_>,\n GetFunctionVisibility<Ref_>\n>;\n\nexport type FromFunctionSpec<FunctionSpec_ extends FunctionSpec.AnyWithProps> =\n Ref<\n FunctionSpec.GetRuntimeAndFunctionType<FunctionSpec_>,\n FunctionSpec.GetFunctionVisibility<FunctionSpec_>,\n FunctionSpec.Args<FunctionSpec_>,\n FunctionSpec.Returns<FunctionSpec_>,\n FunctionSpec.Error<FunctionSpec_>\n >;\n\nexport const make = <FunctionSpec_ extends FunctionSpec.AnyWithProps>(\n /**\n * The namespace portion of a Convex function name, i.e. the part before the\n * colon. For example, for `myGroupDir/myGroupMod:myFunc` this would be\n * `myGroupDir/myGroupMod`.\n */\n functionNamespace: string,\n functionSpec: FunctionSpec_,\n): FromFunctionSpec<FunctionSpec_> => ({ functionSpec, functionNamespace });\n\nexport const getConvexFunctionName = (ref: Any): string =>\n `${ref.functionNamespace}:${ref.functionSpec.name}`;\n\nconst functionReferenceCache = new Map<string, FunctionReference<Any>>();\n\nexport const getFunctionReference = <Ref_ extends Any>(\n ref: Ref_,\n): FunctionReference<Ref_> => {\n const functionName = getConvexFunctionName(ref);\n\n const cached = functionReferenceCache.get(functionName);\n if (cached !== undefined) {\n return cached as FunctionReference<Ref_>;\n }\n\n const functionReference = makeFunctionReference(functionName);\n functionReferenceCache.set(functionName, functionReference);\n\n return functionReference as FunctionReference<Ref_>;\n};\n\nexport const hasErrorSchema = (ref: Any): boolean =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\n \"Confect\",\n (confectFunctionProvenance) => \"error\" in confectFunctionProvenance,\n ),\n Match.tag(\"Convex\", () => false),\n Match.exhaustive,\n );\n\nexport const encodeArgs = <Ref_ extends Any>(\n ref: Ref_,\n args: Args<Ref_>,\n): Effect.Effect<unknown, ParseResult.ParseError> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Schema.encode(confectFunctionProvenance.args)(args),\n ),\n Match.tag(\"Convex\", () => Effect.succeed(args)),\n Match.exhaustive,\n );\n\nexport const decodeReturns = <Ref_ extends Any>(\n ref: Ref_,\n returns: unknown,\n): Effect.Effect<Returns<Ref_>, ParseResult.ParseError> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Schema.decode(confectFunctionProvenance.returns)(returns),\n ),\n Match.tag(\"Convex\", () => Effect.succeed(returns)),\n Match.exhaustive,\n );\n\nexport const encodeArgsSync = <Ref_ extends Any>(\n ref: Ref_,\n args: Args<Ref_>,\n): unknown =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Schema.encodeSync(confectFunctionProvenance.args)(args),\n ),\n Match.tag(\"Convex\", () => args),\n Match.exhaustive,\n );\n\nexport const decodeArgsSync = <Ref_ extends Any>(\n ref: Ref_,\n encodedArgs: unknown,\n): Args<Ref_> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Schema.decodeSync(confectFunctionProvenance.args)(encodedArgs),\n ),\n Match.tag(\"Convex\", () => encodedArgs),\n Match.exhaustive,\n ) as Args<Ref_>;\n\nexport const encodeReturnsSync = <Ref_ extends Any>(\n ref: Ref_,\n returns: Returns<Ref_>,\n): unknown =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Schema.encodeSync(confectFunctionProvenance.returns)(returns),\n ),\n Match.tag(\"Convex\", () => returns),\n Match.exhaustive,\n );\n\nexport const decodeReturnsSync = <Ref_ extends Any>(\n ref: Ref_,\n encodedReturns: unknown,\n): Returns<Ref_> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Schema.decodeSync(confectFunctionProvenance.returns)(encodedReturns),\n ),\n Match.tag(\"Convex\", () => encodedReturns),\n Match.exhaustive,\n ) as Returns<Ref_>;\n\nconst ConvexErrorIdentifier = Symbol.for(\"ConvexError\");\n\nexport const isConvexError = (error: unknown): error is ConvexError<Value> =>\n error instanceof ConvexError ||\n (typeof error === \"object\" &&\n error !== null &&\n ConvexErrorIdentifier in error);\n\n/**\n * Build a callback-style handler that decodes the ref's typed error from a\n * caught `ConvexError`, or else forwards the value to `mapUnknownError`. The\n * fallback is also invoked when the input *is* a `ConvexError` but the ref\n * doesn't declare a typed-error schema—by definition such a value falls\n * outside the ref's error contract. Useful when adapting non-Effect APIs (e.g.\n * emitter callbacks for streamed subscriptions) to the same error semantics\n * that `runWithCodec` provides.\n */\nexport const decodeErrorOrElse =\n <Ref_ extends Any, E>(ref: Ref_, mapUnknownError: (error: unknown) => E) =>\n (error: unknown): Error<Ref_> | E => {\n if (isConvexError(error)) {\n const decoded = decodeErrorSync(ref, error.data);\n if (Option.isSome(decoded)) {\n return decoded.value;\n }\n }\n return mapUnknownError(error);\n };\n\n/**\n * Decode `encodedError` against the ref's error schema. Returns `None` if the\n * ref doesn't declare a typed error (Confect ref without an `error` schema, or\n * a Convex-provenance ref)—by definition there's nothing to decode the value\n * into, and the caller is responsible for deciding what to do (typically:\n * surface the original value as a defect).\n */\nexport const decodeError = <Ref_ extends Any>(\n ref: Ref_,\n encodedError: unknown,\n): Effect.Effect<Option.Option<Error<Ref_>>, ParseResult.ParseError> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n \"error\" in confectFunctionProvenance\n ? Effect.map(\n Schema.decode(confectFunctionProvenance.error)(encodedError),\n Option.some,\n )\n : Effect.succeed(Option.none<Error<Ref_>>()),\n ),\n Match.tag(\"Convex\", () => Effect.succeed(Option.none<Error<Ref_>>())),\n Match.exhaustive,\n );\n\n/**\n * Synchronous counterpart to `decodeError`. Throws on schema decode failure;\n * returns `None` when the ref doesn't declare a typed error.\n */\nexport const decodeErrorSync = <Ref_ extends Any>(\n ref: Ref_,\n encodedError: unknown,\n): Option.Option<Error<Ref_>> =>\n Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n \"error\" in confectFunctionProvenance\n ? Option.some(\n Schema.decodeSync(confectFunctionProvenance.error)(\n encodedError,\n ) as Error<Ref_>,\n )\n : Option.none<Error<Ref_>>(),\n ),\n Match.tag(\"Convex\", () => Option.none<Error<Ref_>>()),\n Match.exhaustive,\n );\n\nexport const maybeDecodeErrorSync = <Ref_ extends Any>(\n ref: Ref_,\n error: unknown,\n): unknown =>\n isConvexError(error)\n ? Match.value(ref.functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n \"error\" in confectFunctionProvenance\n ? Schema.decodeSync(confectFunctionProvenance.error)(error.data)\n : error,\n ),\n Match.tag(\"Convex\", () => error),\n Match.exhaustive,\n )\n : error;\n\n/**\n * Encode args via the ref's args schema, invoke `call`, decode returns via the\n * ref's returns schema, and translate any thrown `ConvexError` into the ref's\n * typed error. Anything else the Promise rejects with—network failures,\n * server-side runtime errors, validation failures, etc.—is passed to\n * `mapUnknownError` to be turned into a typed `E`, or surfaced as a defect when\n * no handler is provided.\n */\nexport const runWithCodec = <Ref_ extends Any, E = never>(\n ref: Ref_,\n args: Args<Ref_>,\n call: (\n functionReference: FunctionReference<Ref_>,\n encodedArgs: unknown,\n ) => PromiseLike<unknown>,\n mapUnknownError?: (error: unknown) => E,\n): Effect.Effect<Returns<Ref_>, E | Error<Ref_> | ParseResult.ParseError> =>\n Effect.gen(function* () {\n const functionReference = getFunctionReference(ref);\n const functionProvenance = ref.functionSpec.functionProvenance;\n const invoke = (\n encodedArgs: unknown,\n ): Effect.Effect<unknown, Error<Ref_> | E> =>\n Effect.tryPromise({\n try: () => Promise.resolve(call(functionReference, encodedArgs)),\n catch: (error): Error<Ref_> | E => {\n if (isConvexError(error)) {\n const decoded = decodeErrorSync(ref, error.data);\n if (Option.isSome(decoded)) {\n return decoded.value;\n }\n }\n if (mapUnknownError !== undefined) {\n return mapUnknownError(error);\n }\n throw error;\n },\n });\n return yield* Match.value(functionProvenance).pipe(\n Match.tag(\"Confect\", (confectFunctionProvenance) =>\n Effect.gen(function* () {\n const encodedArgs = yield* Schema.encode(\n confectFunctionProvenance.args,\n )(args);\n const encodedReturns = yield* invoke(encodedArgs);\n return yield* Schema.decode(confectFunctionProvenance.returns)(\n encodedReturns,\n );\n }),\n ),\n Match.tag(\"Convex\", () => invoke(args)),\n Match.exhaustive,\n );\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAsLA,MAAa,QAMX,mBACA,kBACqC;CAAE;CAAc;CAAmB;AAE1E,MAAa,yBAAyB,QACpC,GAAG,IAAI,kBAAkB,GAAG,IAAI,aAAa;AAE/C,MAAM,yCAAyB,IAAI,KAAqC;AAExE,MAAa,wBACX,QAC4B;CAC5B,MAAM,eAAe,sBAAsB,IAAI;CAE/C,MAAM,SAAS,uBAAuB,IAAI,aAAa;AACvD,KAAI,WAAW,OACb,QAAO;CAGT,MAAM,oBAAoB,sBAAsB,aAAa;AAC7D,wBAAuB,IAAI,cAAc,kBAAkB;AAE3D,QAAO;;AAGT,MAAa,kBAAkB,QAC7B,MAAM,MAAM,IAAI,aAAa,mBAAmB,CAAC,KAC/C,MAAM,IACJ,YACC,8BAA8B,WAAW,0BAC3C,EACD,MAAM,IAAI,gBAAgB,MAAM,EAChC,MAAM,WACP;AAEH,MAAa,cACX,KACA,SAEA,MAAM,MAAM,IAAI,aAAa,mBAAmB,CAAC,KAC/C,MAAM,IAAI,YAAY,8BACpB,OAAO,OAAO,0BAA0B,KAAK,CAAC,KAAK,CACpD,EACD,MAAM,IAAI,gBAAgB,OAAO,QAAQ,KAAK,CAAC,EAC/C,MAAM,WACP;AAEH,MAAa,iBACX,KACA,YAEA,MAAM,MAAM,IAAI,aAAa,mBAAmB,CAAC,KAC/C,MAAM,IAAI,YAAY,8BACpB,OAAO,OAAO,0BAA0B,QAAQ,CAAC,QAAQ,CAC1D,EACD,MAAM,IAAI,gBAAgB,OAAO,QAAQ,QAAQ,CAAC,EAClD,MAAM,WACP;AAEH,MAAa,kBACX,KACA,SAEA,MAAM,MAAM,IAAI,aAAa,mBAAmB,CA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