@confect/core 9.0.0-next.5 → 9.0.0-next.7
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 +162 -0
- package/dist/FunctionProvenance.d.ts +47 -36
- package/dist/FunctionProvenance.d.ts.map +1 -1
- package/dist/FunctionProvenance.js +24 -5
- package/dist/FunctionProvenance.js.map +1 -1
- package/dist/FunctionSpec.d.ts +24 -24
- package/dist/FunctionSpec.js +1 -1
- package/dist/FunctionSpec.js.map +1 -1
- package/dist/GroupSpec.js +1 -1
- package/dist/GroupSpec.js.map +1 -1
- package/dist/Identifier.d.ts +19 -0
- package/dist/Identifier.d.ts.map +1 -0
- package/dist/{internal/utils.js → Identifier.js} +26 -3
- package/dist/Identifier.js.map +1 -0
- package/dist/Lazy.d.ts +27 -0
- package/dist/Lazy.d.ts.map +1 -0
- package/dist/Lazy.js +44 -0
- package/dist/Lazy.js.map +1 -0
- package/dist/Ref.d.ts.map +1 -1
- package/dist/Ref.js +13 -5
- package/dist/Ref.js.map +1 -1
- package/dist/Spec.d.ts +8 -27
- package/dist/Spec.d.ts.map +1 -1
- package/dist/Spec.js +11 -45
- package/dist/Spec.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/package.json +41 -42
- package/src/FunctionProvenance.ts +31 -9
- package/src/FunctionSpec.ts +4 -4
- package/src/GroupSpec.ts +1 -1
- package/src/{internal/utils.ts → Identifier.ts} +34 -0
- package/src/Lazy.ts +40 -0
- package/src/Ref.ts +19 -7
- package/src/Spec.ts +6 -84
- package/src/index.ts +2 -0
- package/dist/internal/utils.d.ts +0 -5
- package/dist/internal/utils.d.ts.map +0 -1
- package/dist/internal/utils.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,167 @@
|
|
|
1
1
|
# @confect/core
|
|
2
2
|
|
|
3
|
+
## 9.0.0-next.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5d19484: Stabilize the identity of `@confect/react` hook results across renders.
|
|
8
|
+
|
|
9
|
+
`useQuery` previously decoded and wrapped the Convex result on every render, handing consumers a brand new `QueryResult` even when the underlying Convex data was unchanged. Effects and memoization that depend on the result's identity (e.g. `useEffect(..., [user])` derived via `QueryResult.match`) would re-run on every render, which could escalate into `Maximum update depth exceeded`. The decoded `QueryResult` is now memoized by the (referentially stable) Convex result, so unchanged data keeps a stable identity.
|
|
10
|
+
|
|
11
|
+
`useMutation` and `useAction` now return a stable callback via `useCallback`, matching the identity contract of Convex's own hooks, instead of allocating a fresh function each render.
|
|
12
|
+
|
|
13
|
+
`Ref.getFunctionReference` now caches the Convex function reference by function name, so repeated calls for the same ref return the same reference.
|
|
14
|
+
|
|
15
|
+
## 9.0.0-next.6
|
|
16
|
+
|
|
17
|
+
### Major Changes
|
|
18
|
+
|
|
19
|
+
- 46045a9: Reduce per-function cold-start cost: make `FunctionSpec` schemas lazy and keep each Convex function's bundle scoped to its own group.
|
|
20
|
+
|
|
21
|
+
Previously, loading a single Convex function still paid for the whole project — importing the codegen-assembled `_generated/spec.ts` ran `Schema.Struct(...)` / `Schema.Array(...)` for every function at module load, and each per-function bundle transitively imported `_generated/api.ts` → `_generated/spec.ts` (every spec). A function's cold-start cost now scales with its own group rather than the size of the project.
|
|
22
|
+
|
|
23
|
+
### Lazy `FunctionSpec` schemas
|
|
24
|
+
|
|
25
|
+
`FunctionSpec.*` (`publicQuery` / `internalQuery` / `publicMutation` / `internalMutation` / `publicAction` / `internalAction` / `publicNodeAction` / `internalNodeAction`) takes `args`, `returns`, and (optional) `error` as `() => Schema` thunks instead of bare schemas. The resulting provenance exposes them as sync lazy memoised getters (the same pattern `Table.make` uses), so importing `_generated/spec.ts` builds no schemas — construction is deferred to the first invocation that compiles validators or runs a codec.
|
|
26
|
+
|
|
27
|
+
Migration — wrap each schema in `() =>`:
|
|
28
|
+
|
|
29
|
+
```diff
|
|
30
|
+
FunctionSpec.publicQuery({
|
|
31
|
+
name: "list",
|
|
32
|
+
- args: Schema.Struct({}),
|
|
33
|
+
- returns: Schema.Array(notes.Doc),
|
|
34
|
+
+ args: () => Schema.Struct({}),
|
|
35
|
+
+ returns: () => Schema.Array(notes.Doc),
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Impls take the `DatabaseSchema`, and group paths resolve impl-side
|
|
40
|
+
|
|
41
|
+
`FunctionImpl.make` and `GroupImpl.make` now take the runtime `DatabaseSchema` (the default export of `_generated/schema.ts`) as their first argument instead of the whole `Api`. The handler's ctx-service types only ever depended on the database schema, and switching impls to import `_generated/schema` instead of `_generated/api` removes `_generated/spec.ts` (and the function specs it transitively imports) from every per-function bundle.
|
|
42
|
+
|
|
43
|
+
Each function also registers under a flat, single-segment key into a fresh, isolated `Registry` provided per group by `RegisteredFunctions.buildForGroup` (and the CLI's impl validation), so no group-path lookup against `api.spec` is needed. As a result `Spec#addPath`, `Spec#paths`, and `Api.resolveGroupPathUnsafe` are removed; `GroupImpl` / `FunctionImpl` drop their group-path type parameter; and the codegen-emitted `_generated/spec.ts` / `nodeSpec.ts` no longer contain a `.addPath(...)` chain (the `.addAt(...)` / `.addGroupAt(...)` assembly tree that `Refs.make` consumes is unchanged).
|
|
44
|
+
|
|
45
|
+
Migration — in each `*.impl.ts`, import the database schema and pass it where you passed `api` / `nodeApi`:
|
|
46
|
+
|
|
47
|
+
```diff
|
|
48
|
+
- import api from "../_generated/api"; // (or nodeApi from "../_generated/nodeApi")
|
|
49
|
+
+ import databaseSchema from "../_generated/schema";
|
|
50
|
+
|
|
51
|
+
- const insert = FunctionImpl.make(api, notes, "insert", handler);
|
|
52
|
+
+ const insert = FunctionImpl.make(databaseSchema, notes, "insert", handler);
|
|
53
|
+
|
|
54
|
+
- export default GroupImpl.make(api, notes).pipe(Layer.provide(insert), GroupImpl.finalize);
|
|
55
|
+
+ export default GroupImpl.make(databaseSchema, notes).pipe(Layer.provide(insert), GroupImpl.finalize);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Node impls migrate identically (from `nodeApi` to the same `_generated/schema`); only their specs differ (`GroupSpec.makeNode()`). Hand-rolled tests that built a `Spec` via `.addPath(group, "dot.path")` should drop those calls.
|
|
59
|
+
|
|
60
|
+
### `buildForGroup` and the generated registries
|
|
61
|
+
|
|
62
|
+
`RegisteredFunctions.buildForGroup` takes the `DatabaseSchema` value plus the group's own `GroupSpec` as a single type argument (`buildForGroup<typeof groupSpec>(…)`, returning `RegisteredFunctionsForGroupSpec<Group>`); the `api` / `groupPath` parameters and the `ForGroupPath` dot-path navigation are gone. `RegisteredConvexFunction.make` / `RegisteredNodeFunction.make` take the `DatabaseSchema` rather than the `Api`. Each `_generated/registeredFunctions/{path}.ts` imports the runtime schema and references its group's leaf spec **type-only** (`typeof import("…/{group}.spec")["default"]`), so it never imports a spec module at runtime.
|
|
63
|
+
|
|
64
|
+
### `_generated/api.ts` / `nodeApi.ts` are no longer emitted, and `Api` is removed
|
|
65
|
+
|
|
66
|
+
Nothing imports them anymore, so `confect codegen` no longer emits `_generated/api.ts` / `_generated/nodeApi.ts` and deletes any copies left over from earlier versions. The `Api` module itself (`@confect/server/Api` — `Api.make`, the `Api` type, `Api.resolveGroupPathUnsafe`, etc.) is **removed entirely**: impls and the generated registries take the `DatabaseSchema` value and the spec directly, so the combined database-schema-plus-spec `Api` is no longer used anywhere.
|
|
67
|
+
|
|
68
|
+
### Net effect
|
|
69
|
+
|
|
70
|
+
A function's `convex/{path}.ts` bundle now imports only its own group's registry → its own `.impl` + `_generated/schema` (table schemas, built lazily) + its own group's spec. No `_generated/api.ts`, no project-wide `_generated/spec.ts`, and no sibling-group impls/specs. Re-run `confect codegen` after upgrading.
|
|
71
|
+
|
|
72
|
+
- 762f7eb: Split the deploy-time Convex schema from the runtime `DatabaseSchema`, make `confect/tables/` the single source of truth — including the table name, which is now derived from the filename — and make per-table schema construction lazy.
|
|
73
|
+
|
|
74
|
+
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.
|
|
75
|
+
|
|
76
|
+
Codegen now scans `confect/tables/*.ts` (every file must default-export a `Table`) and emits two siblings:
|
|
77
|
+
- `confect/_generated/schema.ts` — the runtime `DatabaseSchema`, consumed by `_generated/api.ts`. Imports `@confect/server` but never `convex/server`.
|
|
78
|
+
- `confect/_generated/convexSchema.ts` — the Convex deploy `SchemaDefinition`, re-exported one-line from `convex/schema.ts`. Imports `convex/server` but never `@confect/server`.
|
|
79
|
+
|
|
80
|
+
The `convexSchemaDefinition` field is removed from `DatabaseSchema` and `Api`. `TestConfect.layer` now takes the Convex schema definition as a separate argument so it can stay aligned with the deploy artifact without bringing the runtime schema along for the ride.
|
|
81
|
+
|
|
82
|
+
### Filename-derived table names
|
|
83
|
+
|
|
84
|
+
The table name is now derived from the file's basename — `confect/tables/notes.ts` defines a table called `notes`. `Table.make` no longer accepts a name argument and returns an _unnamed_ `Table` value; codegen invokes that value with the filename to produce the bound table.
|
|
85
|
+
|
|
86
|
+
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.
|
|
87
|
+
|
|
88
|
+
Codegen now emits two new sets of files alongside `_generated/schema.ts` and `_generated/convexSchema.ts`:
|
|
89
|
+
- `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")`.
|
|
90
|
+
- `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`.
|
|
91
|
+
|
|
92
|
+
Table filenames must be valid JS identifiers, may not start with `_` (Convex reserves underscore-prefixed names for system tables), and may not collide with reserved JS keywords like `import.ts`. Pick a casing convention you like — Confect's example code uses `snake_case` (`notes.ts`, `user_profiles.ts`).
|
|
93
|
+
|
|
94
|
+
The bound `Table`'s `name` property has been renamed to `tableName`. This avoids a silent collision with the built-in `Function.prototype.name` that JavaScript carries on every function value (including the new unnamed-callable `UnnamedTable`).
|
|
95
|
+
|
|
96
|
+
### Lazy per-table schema construction
|
|
97
|
+
|
|
98
|
+
`Table.make` takes a `() => Schema.Struct({...})` callback rather than a bare struct, and a bound `Table`'s `Fields`, `Doc`, and `tableDefinition` are lazy memoised getters that only invoke that callback on first access.
|
|
99
|
+
|
|
100
|
+
Previously, every `confect/tables/<name>.ts` module ran `Schema.Struct({...})` (and the corresponding `compileTableSchema` / `defineTable` work) at module-load time. Because the codegen-emitted `_generated/schema.ts` is imported transitively from every per-group function bundle, loading any one function eagerly built _every_ table's schema graph — paying a cold-start cost proportional to the whole project, not just the function being invoked.
|
|
101
|
+
|
|
102
|
+
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).
|
|
103
|
+
|
|
104
|
+
### Migration
|
|
105
|
+
1. Delete your `confect/schema.ts`. Codegen will refuse to run while a stray copy is present.
|
|
106
|
+
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.
|
|
107
|
+
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`:
|
|
108
|
+
|
|
109
|
+
```diff
|
|
110
|
+
- import { GenericId } from "@confect/core";
|
|
111
|
+
import { Table } from "@confect/server";
|
|
112
|
+
import { Schema } from "effect";
|
|
113
|
+
+ import { Id } from "../_generated/id";
|
|
114
|
+
|
|
115
|
+
- export default Table.make(
|
|
116
|
+
- "notes",
|
|
117
|
+
- Schema.Struct({
|
|
118
|
+
- userId: Schema.optional(GenericId.GenericId("users")),
|
|
119
|
+
- text: Schema.String,
|
|
120
|
+
- }),
|
|
121
|
+
- );
|
|
122
|
+
+ export default Table.make(() =>
|
|
123
|
+
+ Schema.Struct({
|
|
124
|
+
+ userId: Schema.optional(Id("users")),
|
|
125
|
+
+ text: Schema.String,
|
|
126
|
+
+ }),
|
|
127
|
+
+ );
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
4. Rewire every consumer site (specs, impls, integration tests, HTTP handlers, etc.) to import from the generated wrapper rather than directly from `tables/`. The wrapper is also where you now read `Doc` / `Fields` / `tableDefinition` (the unnamed `Table.make(...)` callable no longer exposes them):
|
|
131
|
+
|
|
132
|
+
```diff
|
|
133
|
+
- import Notes from "../tables/Notes";
|
|
134
|
+
+ import notes from "../_generated/tables/notes";
|
|
135
|
+
|
|
136
|
+
- returns: Schema.Array(Notes.Doc),
|
|
137
|
+
+ returns: Schema.Array(notes.Doc),
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
5. Replace every remaining `GenericId.GenericId("x")` call site with `Id("x")` from `_generated/id` (in spec `args`/`returns`, in `TaggedError` schemas, in `TestConfect.run`, etc.).
|
|
141
|
+
6. If you read `table.name` anywhere off a bound `Table`, rename it to `table.tableName`.
|
|
142
|
+
7. Re-run `confect codegen`. It will create `confect/_generated/schema.ts`, `confect/_generated/convexSchema.ts`, `confect/_generated/id.ts`, and one `confect/_generated/tables/<name>.ts` wrapper per table; and it will rewrite `convex/schema.ts` to a one-line re-export.
|
|
143
|
+
8. If you use `@confect/test`, pass the generated Convex schema definition to `TestConfect.layer`:
|
|
144
|
+
|
|
145
|
+
```diff
|
|
146
|
+
- import confectSchema from "./confect/schema";
|
|
147
|
+
+ import confectSchema from "./confect/_generated/schema";
|
|
148
|
+
+ import convexSchema from "./confect/_generated/convexSchema";
|
|
149
|
+
|
|
150
|
+
export const layer = TestConfect_.layer(
|
|
151
|
+
confectSchema,
|
|
152
|
+
+ convexSchema,
|
|
153
|
+
import.meta.glob("./convex/**/!(*.*.*)*.*s"),
|
|
154
|
+
);
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### New warning: no tables discovered
|
|
158
|
+
|
|
159
|
+
If a Confect project has no tables — either `confect/tables/` is missing entirely or it exists but contains no `.ts` files — codegen now emits a yellow `⚠` warning and continues, producing an empty `DatabaseSchema.make()` / `defineSchema({})`. Table-free backends (e.g. action-only proxies, webhook bridges) are still legal; the warning just catches the much more common case of a typoed directory name or files placed at the wrong path. To silence it, add at least one `Table.make(...)` module under `confect/tables/`.
|
|
160
|
+
|
|
161
|
+
### New error: invalid table filename
|
|
162
|
+
|
|
163
|
+
Codegen now rejects table files whose basename is not a valid JS identifier (e.g. `user-profiles.ts`), starts with `_` (reserved for Convex system tables), or shadows a reserved JS keyword (e.g. `import.ts`). Rename the offending file to fix it — for example, `user-profiles.ts` → `user_profiles.ts` or `userProfiles.ts`.
|
|
164
|
+
|
|
3
165
|
## 9.0.0-next.5
|
|
4
166
|
|
|
5
167
|
## 9.0.0-next.4
|
|
@@ -28,84 +28,95 @@ interface Convex<Args extends DefaultFunctionArgs, Returns> {
|
|
|
28
28
|
}
|
|
29
29
|
interface AnyConvex extends Convex<DefaultFunctionArgs, any> {}
|
|
30
30
|
declare const FunctionProvenance: {
|
|
31
|
+
readonly Convex: Data.Case.Constructor<{
|
|
32
|
+
readonly _tag: "Convex";
|
|
33
|
+
readonly _args: DefaultFunctionArgs;
|
|
34
|
+
readonly _returns: any;
|
|
35
|
+
}, "_tag">;
|
|
31
36
|
readonly Confect: Data.Case.Constructor<{
|
|
32
37
|
readonly _tag: "Confect";
|
|
33
38
|
readonly args: Schema.Schema.AnyNoContext;
|
|
34
39
|
readonly returns: Schema.Schema.AnyNoContext;
|
|
35
40
|
readonly error?: Schema.Schema.AnyNoContext;
|
|
36
41
|
}, "_tag">;
|
|
37
|
-
readonly Convex:
|
|
42
|
+
readonly $is: <Tag extends "Convex" | "Confect">(tag: Tag) => (u: unknown) => u is Extract<{
|
|
38
43
|
readonly _tag: "Convex";
|
|
39
44
|
readonly _args: DefaultFunctionArgs;
|
|
40
45
|
readonly _returns: any;
|
|
41
|
-
},
|
|
42
|
-
|
|
46
|
+
}, {
|
|
47
|
+
readonly _tag: Tag;
|
|
48
|
+
}> | Extract<{
|
|
43
49
|
readonly _tag: "Confect";
|
|
44
50
|
readonly args: Schema.Schema.AnyNoContext;
|
|
45
51
|
readonly returns: Schema.Schema.AnyNoContext;
|
|
46
52
|
readonly error?: Schema.Schema.AnyNoContext;
|
|
47
53
|
}, {
|
|
48
54
|
readonly _tag: Tag;
|
|
49
|
-
}> | Extract<{
|
|
50
|
-
readonly _tag: "Convex";
|
|
51
|
-
readonly _args: DefaultFunctionArgs;
|
|
52
|
-
readonly _returns: any;
|
|
53
|
-
}, {
|
|
54
|
-
readonly _tag: Tag;
|
|
55
55
|
}>;
|
|
56
56
|
readonly $match: {
|
|
57
57
|
<const Cases extends {
|
|
58
|
+
readonly Convex: (args: {
|
|
59
|
+
readonly _tag: "Convex";
|
|
60
|
+
readonly _args: DefaultFunctionArgs;
|
|
61
|
+
readonly _returns: any;
|
|
62
|
+
}) => any;
|
|
58
63
|
readonly Confect: (args: {
|
|
59
64
|
readonly _tag: "Confect";
|
|
60
65
|
readonly args: Schema.Schema.AnyNoContext;
|
|
61
66
|
readonly returns: Schema.Schema.AnyNoContext;
|
|
62
67
|
readonly error?: Schema.Schema.AnyNoContext;
|
|
63
68
|
}) => any;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}>(cases: Cases & { [K in Exclude<keyof Cases, "Confect" | "Convex">]: never }): (value: {
|
|
69
|
+
}>(cases: Cases & { [K in Exclude<keyof Cases, "Convex" | "Confect">]: never }): (value: {
|
|
70
|
+
readonly _tag: "Convex";
|
|
71
|
+
readonly _args: DefaultFunctionArgs;
|
|
72
|
+
readonly _returns: any;
|
|
73
|
+
} | {
|
|
70
74
|
readonly _tag: "Confect";
|
|
71
75
|
readonly args: Schema.Schema.AnyNoContext;
|
|
72
76
|
readonly returns: Schema.Schema.AnyNoContext;
|
|
73
77
|
readonly error?: Schema.Schema.AnyNoContext;
|
|
74
|
-
} |
|
|
75
|
-
readonly _tag: "Convex";
|
|
76
|
-
readonly _args: DefaultFunctionArgs;
|
|
77
|
-
readonly _returns: any;
|
|
78
|
-
}) => effect_Unify0.Unify<ReturnType<Cases["Confect" | "Convex"]>>;
|
|
78
|
+
}) => effect_Unify0.Unify<ReturnType<Cases["Convex" | "Confect"]>>;
|
|
79
79
|
<const Cases extends {
|
|
80
|
+
readonly Convex: (args: {
|
|
81
|
+
readonly _tag: "Convex";
|
|
82
|
+
readonly _args: DefaultFunctionArgs;
|
|
83
|
+
readonly _returns: any;
|
|
84
|
+
}) => any;
|
|
80
85
|
readonly Confect: (args: {
|
|
81
86
|
readonly _tag: "Confect";
|
|
82
87
|
readonly args: Schema.Schema.AnyNoContext;
|
|
83
88
|
readonly returns: Schema.Schema.AnyNoContext;
|
|
84
89
|
readonly error?: Schema.Schema.AnyNoContext;
|
|
85
90
|
}) => any;
|
|
86
|
-
readonly Convex: (args: {
|
|
87
|
-
readonly _tag: "Convex";
|
|
88
|
-
readonly _args: DefaultFunctionArgs;
|
|
89
|
-
readonly _returns: any;
|
|
90
|
-
}) => any;
|
|
91
91
|
}>(value: {
|
|
92
|
+
readonly _tag: "Convex";
|
|
93
|
+
readonly _args: DefaultFunctionArgs;
|
|
94
|
+
readonly _returns: any;
|
|
95
|
+
} | {
|
|
92
96
|
readonly _tag: "Confect";
|
|
93
97
|
readonly args: Schema.Schema.AnyNoContext;
|
|
94
98
|
readonly returns: Schema.Schema.AnyNoContext;
|
|
95
99
|
readonly error?: Schema.Schema.AnyNoContext;
|
|
96
|
-
} |
|
|
97
|
-
readonly _tag: "Convex";
|
|
98
|
-
readonly _args: DefaultFunctionArgs;
|
|
99
|
-
readonly _returns: any;
|
|
100
|
-
}, cases: Cases & { [K in Exclude<keyof Cases, "Confect" | "Convex">]: never }): effect_Unify0.Unify<ReturnType<Cases["Confect" | "Convex"]>>;
|
|
100
|
+
}, cases: Cases & { [K in Exclude<keyof Cases, "Convex" | "Confect">]: never }): effect_Unify0.Unify<ReturnType<Cases["Convex" | "Confect"]>>;
|
|
101
101
|
};
|
|
102
102
|
};
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
103
|
+
/**
|
|
104
|
+
* Build a `Confect` provenance from lazy schema thunks. `args`, `returns`,
|
|
105
|
+
* and `error` are exposed as sync lazy memoised getters (via {@link Lazy.defineProperty})
|
|
106
|
+
* that only evaluate their thunk on first access, mirroring how `Table`
|
|
107
|
+
* defers `Fields`/`Doc`/`tableDefinition`. This keeps importing the assembled
|
|
108
|
+
* `_generated/spec.ts` cheap — no `Schema.Struct(...)` / `Schema.Array(...)`
|
|
109
|
+
* work runs at module load; it is deferred to the first invocation that
|
|
110
|
+
* actually compiles validators or runs a codec.
|
|
111
|
+
*
|
|
112
|
+
* The object is built by hand rather than through `FunctionProvenance.Confect`
|
|
113
|
+
* because the `Data` constructor copies its input with `Object.assign`, which
|
|
114
|
+
* would force the getters at construction time and defeat the laziness.
|
|
115
|
+
* `error` is only installed when an `errorThunk` is provided, so its absence
|
|
116
|
+
* is observable via `"error" in provenance` without forcing anything; nothing
|
|
117
|
+
* relies on `Data`'s structural `Equal`/`Hash` for provenance values.
|
|
118
|
+
*/
|
|
119
|
+
declare const Confect: <Args extends Schema.Schema.AnyNoContext, Returns extends Schema.Schema.AnyNoContext, Error extends Schema.Schema.AnyNoContext = never>(args: () => Args, returns: () => Returns, error?: () => Error) => Confect<Args, Returns, Error>;
|
|
109
120
|
declare const Convex: <_Args extends DefaultFunctionArgs, _Returns>() => {
|
|
110
121
|
readonly _tag: "Convex";
|
|
111
122
|
readonly _args: DefaultFunctionArgs;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FunctionProvenance.d.ts","names":[],"sources":["../src/FunctionProvenance.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"FunctionProvenance.d.ts","names":[],"sources":["../src/FunctionProvenance.ts"],"mappings":";;;;;;;;KAKY,kBAAA,GAAqB,IAAA,CAAK,UAAA;EACpC,OAAA;IACE,IAAA,EAAM,MAAA,CAAO,MAAA,CAAO,YAAA;IACpB,OAAA,EAAS,MAAA,CAAO,MAAA,CAAO,YAAA;IACvB,KAAA,GAAQ,MAAA,CAAO,MAAA,CAAO,YAAA;EAAA;EAExB,MAAA;AAAA;AAAA,UAQe,OAAA,cACF,MAAA,CAAO,MAAA,CAAO,YAAA,kBACX,MAAA,CAAO,MAAA,CAAO,YAAA,gBAChB,MAAA,CAAO,MAAA,CAAO,YAAA;EAAA,SAEnB,IAAA;EAAA,SACA,IAAA,EAAM,IAAA;EAAA,SACN,OAAA,EAAS,OAAA;EAAA,SACT,KAAA,GAAQ,KAAA;AAAA;AAAA,UAGF,UAAA,SAAmB,OAAA,CAClC,MAAA,CAAO,MAAA,CAAO,YAAA,EACd,MAAA,CAAO,MAAA,CAAO,YAAA,EACd,MAAA,CAAO,MAAA,CAAO,YAAA;AAAA,UAGC,MAAA,cAAoB,mBAAA;EAAA,SAC1B,IAAA;EAAA,SACA,KAAA,EAAO,IAAA;EAAA,SACP,QAAA,EAAU,OAAA;AAAA;AAAA,UAGJ,SAAA,SAAkB,MAAA,CAAO,mBAAA;AAAA,cAE7B,kBAAA;EAAA;;oBA/BF,mBAAA;IAAA;;;;mBAND,MAAA,CAAO,MAAA,CAAO,YAAA;IAAA,kBACX,MAAA,CAAO,MAAA,CAAO,YAAA;IAAA,iBACf,MAAA,CAAO,MAAA,CAAO,YAAA;EAAA;EAAA;;oBAIf,mBAAA;IAAA;;;;;mBAND,MAAA,CAAO,MAAA,CAAO,YAAA;IAAA,kBACX,MAAA,CAAO,MAAA,CAAO,YAAA;IAAA,iBACf,MAAA,CAAO,MAAA,CAAO,YAAA;EAAA;IAAA;;;;;;wBAIf,mBAAA;QAAA;;;;uBAND,MAAA,CAAO,MAAA,CAAO,YAAA;QAAA,kBACX,MAAA,CAAO,MAAA,CAAO,YAAA;QAAA,iBACf,MAAA,CAAO,MAAA,CAAO,YAAA;MAAA;IAAA;;sBAIf,mBAAA;MAAA;;;qBAND,MAAA,CAAO,MAAA,CAAO,YAAA;MAAA,kBACX,MAAA,CAAO,MAAA,CAAO,YAAA;MAAA,iBACf,MAAA,CAAO,MAAA,CAAO,YAAA;IAAA;;;;wBAIf,mBAAA;QAAA;;;;uBAND,MAAA,CAAO,MAAA,CAAO,YAAA;QAAA,kBACX,MAAA,CAAO,MAAA,CAAO,YAAA;QAAA,iBACf,MAAA,CAAO,MAAA,CAAO,YAAA;MAAA;IAAA;;sBAIf,mBAAA;MAAA;;;qBAND,MAAA,CAAO,MAAA,CAAO,YAAA;MAAA,kBACX,MAAA,CAAO,MAAA,CAAO,YAAA;MAAA,iBACf,MAAA,CAAO,MAAA,CAAO,YAAA;IAAA;;;;;;;;;;;;;;;AAiC1B;;;;cAoBa,OAAA,gBACE,MAAA,CAAO,MAAA,CAAO,YAAA,kBACX,MAAA,CAAO,MAAA,CAAO,YAAA,gBAChB,MAAA,CAAO,MAAA,CAAO,YAAA,UAE5B,IAAA,QAAY,IAAA,EACZ,OAAA,QAAe,OAAA,EACf,KAAA,SAAc,KAAA,KACb,OAAA,CAAQ,IAAA,EAAM,OAAA,EAAS,KAAA;AAAA,cAYb,MAAA,iBAAwB,mBAAA;EAAA;kBArE1B,mBAAA;EAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { defineProperty } from "./Lazy.js";
|
|
2
3
|
import { Data } from "effect";
|
|
3
4
|
|
|
4
5
|
//#region src/FunctionProvenance.ts
|
|
@@ -8,11 +9,29 @@ var FunctionProvenance_exports = /* @__PURE__ */ __exportAll({
|
|
|
8
9
|
FunctionProvenance: () => FunctionProvenance
|
|
9
10
|
});
|
|
10
11
|
const FunctionProvenance = Data.taggedEnum();
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Build a `Confect` provenance from lazy schema thunks. `args`, `returns`,
|
|
14
|
+
* and `error` are exposed as sync lazy memoised getters (via {@link Lazy.defineProperty})
|
|
15
|
+
* that only evaluate their thunk on first access, mirroring how `Table`
|
|
16
|
+
* defers `Fields`/`Doc`/`tableDefinition`. This keeps importing the assembled
|
|
17
|
+
* `_generated/spec.ts` cheap — no `Schema.Struct(...)` / `Schema.Array(...)`
|
|
18
|
+
* work runs at module load; it is deferred to the first invocation that
|
|
19
|
+
* actually compiles validators or runs a codec.
|
|
20
|
+
*
|
|
21
|
+
* The object is built by hand rather than through `FunctionProvenance.Confect`
|
|
22
|
+
* because the `Data` constructor copies its input with `Object.assign`, which
|
|
23
|
+
* would force the getters at construction time and defeat the laziness.
|
|
24
|
+
* `error` is only installed when an `errorThunk` is provided, so its absence
|
|
25
|
+
* is observable via `"error" in provenance` without forcing anything; nothing
|
|
26
|
+
* relies on `Data`'s structural `Equal`/`Hash` for provenance values.
|
|
27
|
+
*/
|
|
28
|
+
const Confect = (args, returns, error) => {
|
|
29
|
+
const provenance = { _tag: "Confect" };
|
|
30
|
+
defineProperty(provenance, "args", args);
|
|
31
|
+
defineProperty(provenance, "returns", returns);
|
|
32
|
+
if (error !== void 0) defineProperty(provenance, "error", error);
|
|
33
|
+
return provenance;
|
|
34
|
+
};
|
|
16
35
|
const Convex = () => FunctionProvenance.Convex({});
|
|
17
36
|
|
|
18
37
|
//#endregion
|
|
@@ -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 { Data } from \"effect\";\n\nexport type FunctionProvenance = Data.TaggedEnum<{\n Confect: {\n args: Schema.Schema.AnyNoContext;\n returns: Schema.Schema.AnyNoContext;\n error?: Schema.Schema.AnyNoContext;\n };\n Convex: {\n /** @internal */\n _args: DefaultFunctionArgs;\n /** @internal */\n _returns: any;\n };\n}>;\n\nexport interface Confect<\n Args extends Schema.Schema.AnyNoContext,\n Returns extends Schema.Schema.AnyNoContext,\n Error extends Schema.Schema.AnyNoContext = 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.Schema.AnyNoContext,\n Schema.Schema.AnyNoContext,\n Schema.Schema.AnyNoContext\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\nexport const Confect = <\n Args extends Schema.Schema.AnyNoContext,\n Returns extends Schema.Schema.AnyNoContext,\n Error extends Schema.Schema.AnyNoContext = never,\n>(\n args: Args,\n returns: Returns,\n error?: Error,\n)
|
|
1
|
+
{"version":3,"file":"FunctionProvenance.js","names":[],"sources":["../src/FunctionProvenance.ts"],"sourcesContent":["import type { DefaultFunctionArgs } from \"convex/server\";\nimport type { Schema } from \"effect\";\nimport { Data } from \"effect\";\nimport * as Lazy from \"./Lazy\";\n\nexport type FunctionProvenance = Data.TaggedEnum<{\n Confect: {\n args: Schema.Schema.AnyNoContext;\n returns: Schema.Schema.AnyNoContext;\n error?: Schema.Schema.AnyNoContext;\n };\n Convex: {\n /** @internal */\n _args: DefaultFunctionArgs;\n /** @internal */\n _returns: any;\n };\n}>;\n\nexport interface Confect<\n Args extends Schema.Schema.AnyNoContext,\n Returns extends Schema.Schema.AnyNoContext,\n Error extends Schema.Schema.AnyNoContext = 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.Schema.AnyNoContext,\n Schema.Schema.AnyNoContext,\n Schema.Schema.AnyNoContext\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.Schema.AnyNoContext,\n Returns extends Schema.Schema.AnyNoContext,\n Error extends Schema.Schema.AnyNoContext = 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,YAAgC;;;;;;;;;;;;;;;;;AAkBvE,MAAa,WAKX,MACA,SACA,UACkC;CAClC,MAAM,aAAa,EAAE,MAAM,WAAoB;AAE/C,gBAAoB,YAAY,QAAQ,KAAK;AAC7C,gBAAoB,YAAY,WAAW,QAAQ;AACnD,KAAI,UAAU,OACZ,gBAAoB,YAAY,SAAS,MAAM;AAGjD,QAAO;;AAGT,MAAa,eACX,mBAAmB,OACjB,EAAE,CAIH"}
|
package/dist/FunctionSpec.d.ts
CHANGED
|
@@ -103,9 +103,9 @@ declare const publicQuery: <const Name_ extends string, Args_ extends Schema.Sch
|
|
|
103
103
|
error
|
|
104
104
|
}: {
|
|
105
105
|
name: Name_;
|
|
106
|
-
args: Args_;
|
|
107
|
-
returns: Returns_;
|
|
108
|
-
error?: Error_;
|
|
106
|
+
args: () => Args_;
|
|
107
|
+
returns: () => Returns_;
|
|
108
|
+
error?: () => Error_;
|
|
109
109
|
}) => FunctionSpec<{
|
|
110
110
|
readonly runtime: "Convex";
|
|
111
111
|
readonly functionType: "query";
|
|
@@ -117,9 +117,9 @@ declare const internalQuery: <const Name_ extends string, Args_ extends Schema.S
|
|
|
117
117
|
error
|
|
118
118
|
}: {
|
|
119
119
|
name: Name_;
|
|
120
|
-
args: Args_;
|
|
121
|
-
returns: Returns_;
|
|
122
|
-
error?: Error_;
|
|
120
|
+
args: () => Args_;
|
|
121
|
+
returns: () => Returns_;
|
|
122
|
+
error?: () => Error_;
|
|
123
123
|
}) => FunctionSpec<{
|
|
124
124
|
readonly runtime: "Convex";
|
|
125
125
|
readonly functionType: "query";
|
|
@@ -131,9 +131,9 @@ declare const publicMutation: <const Name_ extends string, Args_ extends Schema.
|
|
|
131
131
|
error
|
|
132
132
|
}: {
|
|
133
133
|
name: Name_;
|
|
134
|
-
args: Args_;
|
|
135
|
-
returns: Returns_;
|
|
136
|
-
error?: Error_;
|
|
134
|
+
args: () => Args_;
|
|
135
|
+
returns: () => Returns_;
|
|
136
|
+
error?: () => Error_;
|
|
137
137
|
}) => FunctionSpec<{
|
|
138
138
|
readonly runtime: "Convex";
|
|
139
139
|
readonly functionType: "mutation";
|
|
@@ -145,9 +145,9 @@ declare const internalMutation: <const Name_ extends string, Args_ extends Schem
|
|
|
145
145
|
error
|
|
146
146
|
}: {
|
|
147
147
|
name: Name_;
|
|
148
|
-
args: Args_;
|
|
149
|
-
returns: Returns_;
|
|
150
|
-
error?: Error_;
|
|
148
|
+
args: () => Args_;
|
|
149
|
+
returns: () => Returns_;
|
|
150
|
+
error?: () => Error_;
|
|
151
151
|
}) => FunctionSpec<{
|
|
152
152
|
readonly runtime: "Convex";
|
|
153
153
|
readonly functionType: "mutation";
|
|
@@ -159,9 +159,9 @@ declare const publicAction: <const Name_ extends string, Args_ extends Schema.Sc
|
|
|
159
159
|
error
|
|
160
160
|
}: {
|
|
161
161
|
name: Name_;
|
|
162
|
-
args: Args_;
|
|
163
|
-
returns: Returns_;
|
|
164
|
-
error?: Error_;
|
|
162
|
+
args: () => Args_;
|
|
163
|
+
returns: () => Returns_;
|
|
164
|
+
error?: () => Error_;
|
|
165
165
|
}) => FunctionSpec<{
|
|
166
166
|
readonly runtime: "Convex";
|
|
167
167
|
readonly functionType: "action";
|
|
@@ -173,9 +173,9 @@ declare const internalAction: <const Name_ extends string, Args_ extends Schema.
|
|
|
173
173
|
error
|
|
174
174
|
}: {
|
|
175
175
|
name: Name_;
|
|
176
|
-
args: Args_;
|
|
177
|
-
returns: Returns_;
|
|
178
|
-
error?: Error_;
|
|
176
|
+
args: () => Args_;
|
|
177
|
+
returns: () => Returns_;
|
|
178
|
+
error?: () => Error_;
|
|
179
179
|
}) => FunctionSpec<{
|
|
180
180
|
readonly runtime: "Convex";
|
|
181
181
|
readonly functionType: "action";
|
|
@@ -187,9 +187,9 @@ declare const publicNodeAction: <const Name_ extends string, Args_ extends Schem
|
|
|
187
187
|
error
|
|
188
188
|
}: {
|
|
189
189
|
name: Name_;
|
|
190
|
-
args: Args_;
|
|
191
|
-
returns: Returns_;
|
|
192
|
-
error?: Error_;
|
|
190
|
+
args: () => Args_;
|
|
191
|
+
returns: () => Returns_;
|
|
192
|
+
error?: () => Error_;
|
|
193
193
|
}) => FunctionSpec<{
|
|
194
194
|
readonly runtime: "Node";
|
|
195
195
|
readonly functionType: "action";
|
|
@@ -201,9 +201,9 @@ declare const internalNodeAction: <const Name_ extends string, Args_ extends Sch
|
|
|
201
201
|
error
|
|
202
202
|
}: {
|
|
203
203
|
name: Name_;
|
|
204
|
-
args: Args_;
|
|
205
|
-
returns: Returns_;
|
|
206
|
-
error?: Error_;
|
|
204
|
+
args: () => Args_;
|
|
205
|
+
returns: () => Returns_;
|
|
206
|
+
error?: () => Error_;
|
|
207
207
|
}) => FunctionSpec<{
|
|
208
208
|
readonly runtime: "Node";
|
|
209
209
|
readonly functionType: "action";
|
package/dist/FunctionSpec.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { Confect, Convex } from "./FunctionProvenance.js";
|
|
3
|
-
import { validateConfectFunctionIdentifier } from "./
|
|
3
|
+
import { validateConfectFunctionIdentifier } from "./Identifier.js";
|
|
4
4
|
import { ConvexAction, ConvexMutation, ConvexQuery, NodeAction } from "./RuntimeAndFunctionType.js";
|
|
5
5
|
import { Predicate } from "effect";
|
|
6
6
|
|
package/dist/FunctionSpec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FunctionSpec.js","names":["FunctionProvenance.Confect","RuntimeAndFunctionType.ConvexQuery","RuntimeAndFunctionType.ConvexMutation","RuntimeAndFunctionType.ConvexAction","RuntimeAndFunctionType.NodeAction","FunctionProvenance.Convex"],"sources":["../src/FunctionSpec.ts"],"sourcesContent":["import type {\n FunctionType,\n FunctionVisibility,\n RegisteredAction,\n RegisteredMutation,\n RegisteredQuery,\n} from \"convex/server\";\nimport type { Schema } from \"effect\";\nimport { Predicate } from \"effect\";\nimport * as FunctionProvenance from \"./FunctionProvenance\";\nimport { validateConfectFunctionIdentifier } from \"./internal/utils\";\nimport * as RuntimeAndFunctionType from \"./RuntimeAndFunctionType\";\n\nexport const TypeId = \"@confect/core/FunctionSpec\";\nexport type TypeId = typeof TypeId;\n\nexport const isFunctionSpec = (u: unknown): u is AnyWithProps =>\n Predicate.hasProperty(u, TypeId);\n\nexport interface FunctionSpec<\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n Name_ extends string,\n FunctionProvenance_ extends FunctionProvenance.FunctionProvenance,\n> {\n readonly [TypeId]: TypeId;\n readonly runtimeAndFunctionType: RuntimeAndFunctionType_;\n readonly functionVisibility: FunctionVisibility_;\n readonly name: Name_;\n readonly functionProvenance: FunctionProvenance_;\n}\n\nexport interface Any {\n readonly [TypeId]: TypeId;\n}\n\nexport interface AnyWithProps extends FunctionSpec<\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility,\n string,\n FunctionProvenance.FunctionProvenance\n> {}\n\nexport interface AnyConfect extends FunctionSpec<\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility,\n string,\n FunctionProvenance.AnyConfect\n> {}\n\nexport interface AnyConvex extends FunctionSpec<\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility,\n string,\n FunctionProvenance.AnyConvex\n> {}\n\nexport interface AnyWithPropsWithRuntime<\n Runtime extends RuntimeAndFunctionType.Runtime,\n> extends FunctionSpec<\n RuntimeAndFunctionType.WithRuntime<Runtime>,\n FunctionVisibility,\n string,\n FunctionProvenance.FunctionProvenance\n> {}\n\nexport interface AnyWithPropsWithFunctionType<\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n> extends FunctionSpec<\n RuntimeAndFunctionType_,\n FunctionVisibility,\n string,\n FunctionProvenance.FunctionProvenance\n> {}\n\nexport interface AnyWithPropsWithFunctionProvenance<\n FunctionProvenance_ extends FunctionProvenance.FunctionProvenance,\n> extends FunctionSpec<\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility,\n string,\n FunctionProvenance_\n> {}\n\nexport type GetRuntimeAndFunctionType<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_[\"runtimeAndFunctionType\"];\n\nexport type GetFunctionVisibility<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_[\"functionVisibility\"];\n\nexport type Name<FunctionSpec_ extends AnyWithProps> = FunctionSpec_[\"name\"];\n\nexport type Args<FunctionSpec_ extends AnyWithProps> = FunctionSpec_ extends {\n functionProvenance: {\n _tag: \"Confect\";\n args: infer ArgsSchema_ extends Schema.Schema.AnyNoContext;\n };\n}\n ? ArgsSchema_[\"Type\"]\n : FunctionSpec_ extends {\n functionProvenance: { _tag: \"Convex\"; _args: infer Args_ };\n }\n ? Args_\n : never;\n\nexport type Returns<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_ extends {\n functionProvenance: {\n _tag: \"Confect\";\n returns: infer ReturnsSchema_ extends Schema.Schema.AnyNoContext;\n };\n }\n ? ReturnsSchema_[\"Type\"]\n : FunctionSpec_ extends {\n functionProvenance: { _tag: \"Convex\"; _returns: infer Returns_ };\n }\n ? Awaited<Returns_>\n : never;\n\nexport type EncodedArgs<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_ extends {\n functionProvenance: {\n _tag: \"Confect\";\n args: infer ArgsSchema_ extends Schema.Schema.AnyNoContext;\n };\n }\n ? ArgsSchema_[\"Encoded\"]\n : FunctionSpec_ extends {\n functionProvenance: { _tag: \"Convex\"; _args: infer Args_ };\n }\n ? Args_\n : never;\n\nexport type EncodedReturns<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_ extends {\n functionProvenance: {\n _tag: \"Confect\";\n returns: infer ReturnsSchema_ extends Schema.Schema.AnyNoContext;\n };\n }\n ? ReturnsSchema_[\"Encoded\"]\n : FunctionSpec_ extends {\n functionProvenance: { _tag: \"Convex\"; _returns: infer Returns_ };\n }\n ? Returns_\n : never;\n\nexport type Error<FunctionSpec_ extends AnyWithProps> = FunctionSpec_ extends {\n functionProvenance: FunctionProvenance.Confect<\n any,\n any,\n infer ErrorSchema_ extends Schema.Schema.AnyNoContext\n >;\n}\n ? ErrorSchema_[\"Type\"]\n : never;\n\nexport type EncodedError<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_ extends {\n functionProvenance: FunctionProvenance.Confect<\n any,\n any,\n infer ErrorSchema_ extends Schema.Schema.AnyNoContext\n >;\n }\n ? ErrorSchema_[\"Encoded\"]\n : never;\n\nexport type WithName<\n FunctionSpec_ extends AnyWithProps,\n Name_ extends string,\n> = Extract<FunctionSpec_, { readonly name: Name_ }>;\n\nexport type WithRuntimeAndFunctionType<\n FunctionSpec_ extends AnyWithProps,\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n> = Extract<\n FunctionSpec_,\n { readonly runtimeAndFunctionType: RuntimeAndFunctionType_ }\n>;\n\nexport type WithFunctionType<\n FunctionSpec_ extends AnyWithProps,\n FunctionType_ extends FunctionType,\n> = Extract<\n FunctionSpec_,\n { readonly runtimeAndFunctionType: { readonly functionType: FunctionType_ } }\n>;\n\nexport type WithFunctionProvenance<\n FunctionSpec_ extends AnyWithProps,\n FunctionProvenance_ extends FunctionProvenance.FunctionProvenance,\n> = Extract<\n FunctionSpec_,\n { readonly functionProvenance: FunctionProvenance_ }\n>;\n\nexport type WithoutName<\n FunctionSpec_ extends AnyWithProps,\n Name_ extends Name<FunctionSpec_>,\n> = Exclude<FunctionSpec_, { readonly name: Name_ }>;\n\nconst Proto = {\n [TypeId]: TypeId,\n};\n\nconst make =\n <\n RuntimeAndFunctionType_ extends\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n >(\n runtimeAndFunctionType: RuntimeAndFunctionType_,\n functionVisibility: FunctionVisibility_,\n ) =>\n <\n const Name_ extends string,\n Args_ extends Schema.Schema.AnyNoContext,\n Returns_ extends Schema.Schema.AnyNoContext,\n Error_ extends Schema.Schema.AnyNoContext = never,\n >({\n name,\n args,\n returns,\n error,\n }: {\n name: Name_;\n args: Args_;\n returns: Returns_;\n error?: Error_;\n }): FunctionSpec<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Name_,\n FunctionProvenance.Confect<Args_, Returns_, Error_>\n > => {\n validateConfectFunctionIdentifier(name);\n\n return Object.assign(Object.create(Proto), {\n runtimeAndFunctionType,\n functionVisibility,\n name,\n functionProvenance: FunctionProvenance.Confect(args, returns, error),\n });\n };\n\nexport const publicQuery = make(RuntimeAndFunctionType.ConvexQuery, \"public\");\nexport const internalQuery = make(\n RuntimeAndFunctionType.ConvexQuery,\n \"internal\",\n);\nexport const publicMutation = make(\n RuntimeAndFunctionType.ConvexMutation,\n \"public\",\n);\nexport const internalMutation = make(\n RuntimeAndFunctionType.ConvexMutation,\n \"internal\",\n);\nexport const publicAction = make(RuntimeAndFunctionType.ConvexAction, \"public\");\nexport const internalAction = make(\n RuntimeAndFunctionType.ConvexAction,\n \"internal\",\n);\n\nexport const publicNodeAction = make(\n RuntimeAndFunctionType.NodeAction,\n \"public\",\n);\nexport const internalNodeAction = make(\n RuntimeAndFunctionType.NodeAction,\n \"internal\",\n);\n\ntype MatchingRegisteredFunction<\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n> =\n RuntimeAndFunctionType.GetFunctionType<RuntimeAndFunctionType_> extends \"query\"\n ? RegisteredQuery<FunctionVisibility_, any, any>\n : RuntimeAndFunctionType.GetFunctionType<RuntimeAndFunctionType_> extends \"mutation\"\n ? RegisteredMutation<FunctionVisibility_, any, any>\n : RuntimeAndFunctionType.GetFunctionType<RuntimeAndFunctionType_> extends \"action\"\n ? RegisteredAction<FunctionVisibility_, any, any>\n : never;\n\ntype ExtractArgs<F> =\n F extends RegisteredQuery<any, infer A, any>\n ? A\n : F extends RegisteredMutation<any, infer A, any>\n ? A\n : F extends RegisteredAction<any, infer A, any>\n ? A\n : never;\n\ntype ExtractReturns<F> =\n F extends RegisteredQuery<any, any, infer R>\n ? R\n : F extends RegisteredMutation<any, any, infer R>\n ? R\n : F extends RegisteredAction<any, any, infer R>\n ? R\n : never;\n\nconst makeConvex =\n <\n RuntimeAndFunctionType_ extends\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n >(\n runtimeAndFunctionType: RuntimeAndFunctionType_,\n functionVisibility: FunctionVisibility_,\n ) =>\n <\n F extends MatchingRegisteredFunction<\n RuntimeAndFunctionType_,\n FunctionVisibility_\n >,\n >() =>\n <const Name_ extends string>(\n name: Name_,\n ): FunctionSpec<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Name_,\n FunctionProvenance.Convex<ExtractArgs<F>, ExtractReturns<F>>\n > => {\n validateConfectFunctionIdentifier(name);\n\n return Object.assign(Object.create(Proto), {\n runtimeAndFunctionType,\n functionVisibility,\n name,\n functionProvenance: FunctionProvenance.Convex<\n ExtractArgs<F>,\n ExtractReturns<F>\n >(),\n }) as any;\n };\n\nexport const convexPublicQuery = makeConvex(\n RuntimeAndFunctionType.ConvexQuery,\n \"public\",\n);\nexport const convexInternalQuery = makeConvex(\n RuntimeAndFunctionType.ConvexQuery,\n \"internal\",\n);\nexport const convexPublicMutation = makeConvex(\n RuntimeAndFunctionType.ConvexMutation,\n \"public\",\n);\nexport const convexInternalMutation = makeConvex(\n RuntimeAndFunctionType.ConvexMutation,\n \"internal\",\n);\nexport const convexPublicAction = makeConvex(\n RuntimeAndFunctionType.ConvexAction,\n \"public\",\n);\nexport const convexInternalAction = makeConvex(\n RuntimeAndFunctionType.ConvexAction,\n \"internal\",\n);\nexport const convexPublicNodeAction = makeConvex(\n RuntimeAndFunctionType.NodeAction,\n \"public\",\n);\nexport const convexInternalNodeAction = makeConvex(\n RuntimeAndFunctionType.NodeAction,\n \"internal\",\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,MAAa,SAAS;AAGtB,MAAa,kBAAkB,MAC7B,UAAU,YAAY,GAAG,OAAO;AAyLlC,MAAM,QAAQ,GACX,SAAS,QACX;AAED,MAAM,QAMF,wBACA,wBAOA,EACA,MACA,MACA,SACA,YAWG;AACH,mCAAkC,KAAK;AAEvC,QAAO,OAAO,OAAO,OAAO,OAAO,MAAM,EAAE;EACzC;EACA;EACA;EACA,oBAAoBA,QAA2B,MAAM,SAAS,MAAM;EACrE,CAAC;;AAGN,MAAa,cAAc,KAAKC,aAAoC,SAAS;AAC7E,MAAa,gBAAgB,KAC3BA,aACA,WACD;AACD,MAAa,iBAAiB,KAC5BC,gBACA,SACD;AACD,MAAa,mBAAmB,KAC9BA,gBACA,WACD;AACD,MAAa,eAAe,KAAKC,cAAqC,SAAS;AAC/E,MAAa,iBAAiB,KAC5BA,cACA,WACD;AAED,MAAa,mBAAmB,KAC9BC,YACA,SACD;AACD,MAAa,qBAAqB,KAChCA,YACA,WACD;AAgCD,MAAM,cAMF,wBACA,8BASA,SAMG;AACH,mCAAkC,KAAK;AAEvC,QAAO,OAAO,OAAO,OAAO,OAAO,MAAM,EAAE;EACzC;EACA;EACA;EACA,oBAAoBC,QAGjB;EACJ,CAAC;;AAGN,MAAa,oBAAoB,WAC/BJ,aACA,SACD;AACD,MAAa,sBAAsB,WACjCA,aACA,WACD;AACD,MAAa,uBAAuB,WAClCC,gBACA,SACD;AACD,MAAa,yBAAyB,WACpCA,gBACA,WACD;AACD,MAAa,qBAAqB,WAChCC,cACA,SACD;AACD,MAAa,uBAAuB,WAClCA,cACA,WACD;AACD,MAAa,yBAAyB,WACpCC,YACA,SACD;AACD,MAAa,2BAA2B,WACtCA,YACA,WACD"}
|
|
1
|
+
{"version":3,"file":"FunctionSpec.js","names":["FunctionProvenance.Confect","RuntimeAndFunctionType.ConvexQuery","RuntimeAndFunctionType.ConvexMutation","RuntimeAndFunctionType.ConvexAction","RuntimeAndFunctionType.NodeAction","FunctionProvenance.Convex"],"sources":["../src/FunctionSpec.ts"],"sourcesContent":["import type {\n FunctionType,\n FunctionVisibility,\n RegisteredAction,\n RegisteredMutation,\n RegisteredQuery,\n} from \"convex/server\";\nimport type { Schema } from \"effect\";\nimport { Predicate } from \"effect\";\nimport * as FunctionProvenance from \"./FunctionProvenance\";\nimport { validateConfectFunctionIdentifier } from \"./Identifier\";\nimport * as RuntimeAndFunctionType from \"./RuntimeAndFunctionType\";\n\nexport const TypeId = \"@confect/core/FunctionSpec\";\nexport type TypeId = typeof TypeId;\n\nexport const isFunctionSpec = (u: unknown): u is AnyWithProps =>\n Predicate.hasProperty(u, TypeId);\n\nexport interface FunctionSpec<\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n Name_ extends string,\n FunctionProvenance_ extends FunctionProvenance.FunctionProvenance,\n> {\n readonly [TypeId]: TypeId;\n readonly runtimeAndFunctionType: RuntimeAndFunctionType_;\n readonly functionVisibility: FunctionVisibility_;\n readonly name: Name_;\n readonly functionProvenance: FunctionProvenance_;\n}\n\nexport interface Any {\n readonly [TypeId]: TypeId;\n}\n\nexport interface AnyWithProps extends FunctionSpec<\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility,\n string,\n FunctionProvenance.FunctionProvenance\n> {}\n\nexport interface AnyConfect extends FunctionSpec<\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility,\n string,\n FunctionProvenance.AnyConfect\n> {}\n\nexport interface AnyConvex extends FunctionSpec<\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility,\n string,\n FunctionProvenance.AnyConvex\n> {}\n\nexport interface AnyWithPropsWithRuntime<\n Runtime extends RuntimeAndFunctionType.Runtime,\n> extends FunctionSpec<\n RuntimeAndFunctionType.WithRuntime<Runtime>,\n FunctionVisibility,\n string,\n FunctionProvenance.FunctionProvenance\n> {}\n\nexport interface AnyWithPropsWithFunctionType<\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n> extends FunctionSpec<\n RuntimeAndFunctionType_,\n FunctionVisibility,\n string,\n FunctionProvenance.FunctionProvenance\n> {}\n\nexport interface AnyWithPropsWithFunctionProvenance<\n FunctionProvenance_ extends FunctionProvenance.FunctionProvenance,\n> extends FunctionSpec<\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility,\n string,\n FunctionProvenance_\n> {}\n\nexport type GetRuntimeAndFunctionType<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_[\"runtimeAndFunctionType\"];\n\nexport type GetFunctionVisibility<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_[\"functionVisibility\"];\n\nexport type Name<FunctionSpec_ extends AnyWithProps> = FunctionSpec_[\"name\"];\n\nexport type Args<FunctionSpec_ extends AnyWithProps> = FunctionSpec_ extends {\n functionProvenance: {\n _tag: \"Confect\";\n args: infer ArgsSchema_ extends Schema.Schema.AnyNoContext;\n };\n}\n ? ArgsSchema_[\"Type\"]\n : FunctionSpec_ extends {\n functionProvenance: { _tag: \"Convex\"; _args: infer Args_ };\n }\n ? Args_\n : never;\n\nexport type Returns<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_ extends {\n functionProvenance: {\n _tag: \"Confect\";\n returns: infer ReturnsSchema_ extends Schema.Schema.AnyNoContext;\n };\n }\n ? ReturnsSchema_[\"Type\"]\n : FunctionSpec_ extends {\n functionProvenance: { _tag: \"Convex\"; _returns: infer Returns_ };\n }\n ? Awaited<Returns_>\n : never;\n\nexport type EncodedArgs<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_ extends {\n functionProvenance: {\n _tag: \"Confect\";\n args: infer ArgsSchema_ extends Schema.Schema.AnyNoContext;\n };\n }\n ? ArgsSchema_[\"Encoded\"]\n : FunctionSpec_ extends {\n functionProvenance: { _tag: \"Convex\"; _args: infer Args_ };\n }\n ? Args_\n : never;\n\nexport type EncodedReturns<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_ extends {\n functionProvenance: {\n _tag: \"Confect\";\n returns: infer ReturnsSchema_ extends Schema.Schema.AnyNoContext;\n };\n }\n ? ReturnsSchema_[\"Encoded\"]\n : FunctionSpec_ extends {\n functionProvenance: { _tag: \"Convex\"; _returns: infer Returns_ };\n }\n ? Returns_\n : never;\n\nexport type Error<FunctionSpec_ extends AnyWithProps> = FunctionSpec_ extends {\n functionProvenance: FunctionProvenance.Confect<\n any,\n any,\n infer ErrorSchema_ extends Schema.Schema.AnyNoContext\n >;\n}\n ? ErrorSchema_[\"Type\"]\n : never;\n\nexport type EncodedError<FunctionSpec_ extends AnyWithProps> =\n FunctionSpec_ extends {\n functionProvenance: FunctionProvenance.Confect<\n any,\n any,\n infer ErrorSchema_ extends Schema.Schema.AnyNoContext\n >;\n }\n ? ErrorSchema_[\"Encoded\"]\n : never;\n\nexport type WithName<\n FunctionSpec_ extends AnyWithProps,\n Name_ extends string,\n> = Extract<FunctionSpec_, { readonly name: Name_ }>;\n\nexport type WithRuntimeAndFunctionType<\n FunctionSpec_ extends AnyWithProps,\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n> = Extract<\n FunctionSpec_,\n { readonly runtimeAndFunctionType: RuntimeAndFunctionType_ }\n>;\n\nexport type WithFunctionType<\n FunctionSpec_ extends AnyWithProps,\n FunctionType_ extends FunctionType,\n> = Extract<\n FunctionSpec_,\n { readonly runtimeAndFunctionType: { readonly functionType: FunctionType_ } }\n>;\n\nexport type WithFunctionProvenance<\n FunctionSpec_ extends AnyWithProps,\n FunctionProvenance_ extends FunctionProvenance.FunctionProvenance,\n> = Extract<\n FunctionSpec_,\n { readonly functionProvenance: FunctionProvenance_ }\n>;\n\nexport type WithoutName<\n FunctionSpec_ extends AnyWithProps,\n Name_ extends Name<FunctionSpec_>,\n> = Exclude<FunctionSpec_, { readonly name: Name_ }>;\n\nconst Proto = {\n [TypeId]: TypeId,\n};\n\nconst make =\n <\n RuntimeAndFunctionType_ extends\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n >(\n runtimeAndFunctionType: RuntimeAndFunctionType_,\n functionVisibility: FunctionVisibility_,\n ) =>\n <\n const Name_ extends string,\n Args_ extends Schema.Schema.AnyNoContext,\n Returns_ extends Schema.Schema.AnyNoContext,\n Error_ extends Schema.Schema.AnyNoContext = never,\n >({\n name,\n args,\n returns,\n error,\n }: {\n name: Name_;\n args: () => Args_;\n returns: () => Returns_;\n error?: () => Error_;\n }): FunctionSpec<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Name_,\n FunctionProvenance.Confect<Args_, Returns_, Error_>\n > => {\n validateConfectFunctionIdentifier(name);\n\n return Object.assign(Object.create(Proto), {\n runtimeAndFunctionType,\n functionVisibility,\n name,\n functionProvenance: FunctionProvenance.Confect(args, returns, error),\n });\n };\n\nexport const publicQuery = make(RuntimeAndFunctionType.ConvexQuery, \"public\");\nexport const internalQuery = make(\n RuntimeAndFunctionType.ConvexQuery,\n \"internal\",\n);\nexport const publicMutation = make(\n RuntimeAndFunctionType.ConvexMutation,\n \"public\",\n);\nexport const internalMutation = make(\n RuntimeAndFunctionType.ConvexMutation,\n \"internal\",\n);\nexport const publicAction = make(RuntimeAndFunctionType.ConvexAction, \"public\");\nexport const internalAction = make(\n RuntimeAndFunctionType.ConvexAction,\n \"internal\",\n);\n\nexport const publicNodeAction = make(\n RuntimeAndFunctionType.NodeAction,\n \"public\",\n);\nexport const internalNodeAction = make(\n RuntimeAndFunctionType.NodeAction,\n \"internal\",\n);\n\ntype MatchingRegisteredFunction<\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n> =\n RuntimeAndFunctionType.GetFunctionType<RuntimeAndFunctionType_> extends \"query\"\n ? RegisteredQuery<FunctionVisibility_, any, any>\n : RuntimeAndFunctionType.GetFunctionType<RuntimeAndFunctionType_> extends \"mutation\"\n ? RegisteredMutation<FunctionVisibility_, any, any>\n : RuntimeAndFunctionType.GetFunctionType<RuntimeAndFunctionType_> extends \"action\"\n ? RegisteredAction<FunctionVisibility_, any, any>\n : never;\n\ntype ExtractArgs<F> =\n F extends RegisteredQuery<any, infer A, any>\n ? A\n : F extends RegisteredMutation<any, infer A, any>\n ? A\n : F extends RegisteredAction<any, infer A, any>\n ? A\n : never;\n\ntype ExtractReturns<F> =\n F extends RegisteredQuery<any, any, infer R>\n ? R\n : F extends RegisteredMutation<any, any, infer R>\n ? R\n : F extends RegisteredAction<any, any, infer R>\n ? R\n : never;\n\nconst makeConvex =\n <\n RuntimeAndFunctionType_ extends\n RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionVisibility_ extends FunctionVisibility,\n >(\n runtimeAndFunctionType: RuntimeAndFunctionType_,\n functionVisibility: FunctionVisibility_,\n ) =>\n <\n F extends MatchingRegisteredFunction<\n RuntimeAndFunctionType_,\n FunctionVisibility_\n >,\n >() =>\n <const Name_ extends string>(\n name: Name_,\n ): FunctionSpec<\n RuntimeAndFunctionType_,\n FunctionVisibility_,\n Name_,\n FunctionProvenance.Convex<ExtractArgs<F>, ExtractReturns<F>>\n > => {\n validateConfectFunctionIdentifier(name);\n\n return Object.assign(Object.create(Proto), {\n runtimeAndFunctionType,\n functionVisibility,\n name,\n functionProvenance: FunctionProvenance.Convex<\n ExtractArgs<F>,\n ExtractReturns<F>\n >(),\n }) as any;\n };\n\nexport const convexPublicQuery = makeConvex(\n RuntimeAndFunctionType.ConvexQuery,\n \"public\",\n);\nexport const convexInternalQuery = makeConvex(\n RuntimeAndFunctionType.ConvexQuery,\n \"internal\",\n);\nexport const convexPublicMutation = makeConvex(\n RuntimeAndFunctionType.ConvexMutation,\n \"public\",\n);\nexport const convexInternalMutation = makeConvex(\n RuntimeAndFunctionType.ConvexMutation,\n \"internal\",\n);\nexport const convexPublicAction = makeConvex(\n RuntimeAndFunctionType.ConvexAction,\n \"public\",\n);\nexport const convexInternalAction = makeConvex(\n RuntimeAndFunctionType.ConvexAction,\n \"internal\",\n);\nexport const convexPublicNodeAction = makeConvex(\n RuntimeAndFunctionType.NodeAction,\n \"public\",\n);\nexport const convexInternalNodeAction = makeConvex(\n RuntimeAndFunctionType.NodeAction,\n \"internal\",\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,MAAa,SAAS;AAGtB,MAAa,kBAAkB,MAC7B,UAAU,YAAY,GAAG,OAAO;AAyLlC,MAAM,QAAQ,GACX,SAAS,QACX;AAED,MAAM,QAMF,wBACA,wBAOA,EACA,MACA,MACA,SACA,YAWG;AACH,mCAAkC,KAAK;AAEvC,QAAO,OAAO,OAAO,OAAO,OAAO,MAAM,EAAE;EACzC;EACA;EACA;EACA,oBAAoBA,QAA2B,MAAM,SAAS,MAAM;EACrE,CAAC;;AAGN,MAAa,cAAc,KAAKC,aAAoC,SAAS;AAC7E,MAAa,gBAAgB,KAC3BA,aACA,WACD;AACD,MAAa,iBAAiB,KAC5BC,gBACA,SACD;AACD,MAAa,mBAAmB,KAC9BA,gBACA,WACD;AACD,MAAa,eAAe,KAAKC,cAAqC,SAAS;AAC/E,MAAa,iBAAiB,KAC5BA,cACA,WACD;AAED,MAAa,mBAAmB,KAC9BC,YACA,SACD;AACD,MAAa,qBAAqB,KAChCA,YACA,WACD;AAgCD,MAAM,cAMF,wBACA,8BASA,SAMG;AACH,mCAAkC,KAAK;AAEvC,QAAO,OAAO,OAAO,OAAO,OAAO,MAAM,EAAE;EACzC;EACA;EACA;EACA,oBAAoBC,QAGjB;EACJ,CAAC;;AAGN,MAAa,oBAAoB,WAC/BJ,aACA,SACD;AACD,MAAa,sBAAsB,WACjCA,aACA,WACD;AACD,MAAa,uBAAuB,WAClCC,gBACA,SACD;AACD,MAAa,yBAAyB,WACpCA,gBACA,WACD;AACD,MAAa,qBAAqB,WAChCC,cACA,SACD;AACD,MAAa,uBAAuB,WAClCA,cACA,WACD;AACD,MAAa,yBAAyB,WACpCC,YACA,SACD;AACD,MAAa,2BAA2B,WACtCA,YACA,WACD"}
|
package/dist/GroupSpec.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
-
import { validateConfectFunctionIdentifier } from "./
|
|
2
|
+
import { validateConfectFunctionIdentifier } from "./Identifier.js";
|
|
3
3
|
import { Predicate, Record } from "effect";
|
|
4
4
|
|
|
5
5
|
//#region src/GroupSpec.ts
|
package/dist/GroupSpec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GroupSpec.js","names":[],"sources":["../src/GroupSpec.ts"],"sourcesContent":["import { Predicate, Record } from \"effect\";\nimport type * as FunctionSpec from \"./FunctionSpec\";\nimport type * as RuntimeAndFunctionType from \"./RuntimeAndFunctionType\";\nimport { validateConfectFunctionIdentifier } from \"./
|
|
1
|
+
{"version":3,"file":"GroupSpec.js","names":[],"sources":["../src/GroupSpec.ts"],"sourcesContent":["import { Predicate, Record } from \"effect\";\nimport type * as FunctionSpec from \"./FunctionSpec\";\nimport type * as RuntimeAndFunctionType from \"./RuntimeAndFunctionType\";\nimport { validateConfectFunctionIdentifier } from \"./Identifier\";\n\nexport const TypeId = \"@confect/core/GroupSpec\";\nexport type TypeId = typeof TypeId;\n\nexport const isGroupSpec = (u: unknown): u is AnyWithProps =>\n Predicate.hasProperty(u, TypeId);\n\nexport interface GroupSpec<\n Runtime extends RuntimeAndFunctionType.Runtime,\n Name_ extends string,\n Functions_ extends FunctionSpec.AnyWithPropsWithRuntime<Runtime> = never,\n Groups_ extends AnyWithPropsWithRuntime<Runtime> = never,\n> {\n readonly [TypeId]: TypeId;\n readonly runtime: Runtime;\n readonly name: Name_;\n readonly functions: {\n [FunctionName in FunctionSpec.Name<\n FunctionSpec.AnyWithPropsWithRuntime<Runtime>\n >]: FunctionSpec.WithName<Functions_, FunctionName>;\n };\n readonly groups: {\n [GroupName in Name<Groups_>]: WithName<Groups_, GroupName>;\n };\n\n addFunction<Function extends FunctionSpec.AnyWithPropsWithRuntime<Runtime>>(\n function_: Function,\n ): GroupSpec<Runtime, Name_, Functions_ | Function, Groups_>;\n\n addGroup<Group extends AnyWithPropsWithRuntime<Runtime>>(\n group: Group,\n ): GroupSpec<Runtime, Name_, Functions_, Groups_ | Group>;\n\n addGroupAt<\n const AtName extends string,\n Group extends AnyWithPropsWithRuntime<Runtime>,\n >(\n name: AtName,\n group: Group,\n ): GroupSpec<Runtime, Name_, Functions_, Groups_ | NamedAt<Group, AtName>>;\n}\n\nexport interface Any {\n readonly [TypeId]: TypeId;\n}\n\nexport interface AnyWithProps extends GroupSpec<\n RuntimeAndFunctionType.Runtime,\n string,\n FunctionSpec.AnyWithProps,\n AnyWithProps\n> {}\n\nexport interface AnyWithPropsWithRuntime<\n Runtime extends RuntimeAndFunctionType.Runtime,\n> extends GroupSpec<\n Runtime,\n string,\n FunctionSpec.AnyWithPropsWithRuntime<Runtime>,\n AnyWithPropsWithRuntime<Runtime>\n> {}\n\nexport type Name<Group extends AnyWithProps> = Group[\"name\"];\n\nexport type Functions<Group extends AnyWithProps> =\n Group[\"functions\"][keyof Group[\"functions\"]];\n\nexport type Groups<Group extends AnyWithProps> =\n Group[\"groups\"][keyof Group[\"groups\"]];\n\nexport type GroupNames<Group extends AnyWithProps> = [Groups<Group>] extends [\n never,\n]\n ? never\n : Name<Groups<Group>>;\n\nexport type WithName<\n Group extends AnyWithProps,\n Name_ extends Name<Group>,\n> = Extract<Group, { readonly name: Name_ }>;\n\n/** Assigns a segment name to a leaf group created with {@link make} for typing and refs. */\nexport type NamedAt<Group extends Any, Name_ extends string> = Omit<\n Group,\n \"name\"\n> & {\n readonly name: Name_;\n};\n\nconst Proto = {\n [TypeId]: TypeId,\n\n addFunction<Function extends FunctionSpec.AnyWithProps>(\n this: Any,\n function_: Function,\n ) {\n const this_ = this as AnyWithProps;\n\n return makeProto({\n runtime: this_.runtime,\n name: this_.name,\n functions: Record.set(this_.functions, function_.name, function_),\n groups: this_.groups,\n });\n },\n\n addGroup<Group extends Any>(this: Any, group: Group) {\n const this_ = this as AnyWithProps;\n const group_ = group as unknown as AnyWithProps;\n\n return makeProto({\n runtime: this_.runtime,\n name: this_.name,\n functions: this_.functions,\n groups: Record.set(this_.groups, group_.name, group_),\n });\n },\n\n addGroupAt<Group extends Any>(this: Any, name: string, group: Group) {\n const this_ = this as AnyWithProps;\n const group_ = group as unknown as AnyWithProps;\n\n return makeProto({\n runtime: this_.runtime,\n name: this_.name,\n functions: this_.functions,\n groups: Record.set(this_.groups, name, withName(name, group_)),\n });\n },\n};\n\nconst makeProto = <\n Runtime extends RuntimeAndFunctionType.Runtime,\n Name_ extends string,\n Functions_ extends FunctionSpec.AnyWithPropsWithRuntime<Runtime>,\n Groups_ extends AnyWithPropsWithRuntime<Runtime>,\n>({\n runtime,\n name,\n functions,\n groups,\n}: {\n runtime: Runtime;\n name: Name_;\n functions: Record.ReadonlyRecord<string, Functions_>;\n groups: Record.ReadonlyRecord<string, Groups_>;\n}): GroupSpec<Runtime, Name_, Functions_, Groups_> =>\n Object.assign(Object.create(Proto), {\n runtime,\n name,\n functions,\n groups,\n });\n\nexport const make = (): GroupSpec<\"Convex\", \"\"> =>\n makeProto({\n runtime: \"Convex\",\n name: \"\",\n functions: Record.empty(),\n groups: Record.empty(),\n });\n\nexport const makeAt = <const Name_ extends string>(\n name: Name_,\n): GroupSpec<\"Convex\", Name_> => {\n validateConfectFunctionIdentifier(name);\n\n return makeProto({\n runtime: \"Convex\",\n name,\n functions: Record.empty(),\n groups: Record.empty(),\n });\n};\n\nexport const makeNode = (): GroupSpec<\"Node\", \"\"> =>\n makeProto({\n runtime: \"Node\",\n name: \"\",\n functions: Record.empty(),\n groups: Record.empty(),\n });\n\nexport const makeNodeAt = <const Name_ extends string>(\n name: Name_,\n): GroupSpec<\"Node\", Name_> => {\n validateConfectFunctionIdentifier(name);\n\n return makeProto({\n runtime: \"Node\",\n name,\n functions: Record.empty(),\n groups: Record.empty(),\n });\n};\n\nexport const withName = <const Name_ extends string>(\n name: Name_,\n group: Any,\n): AnyWithProps => {\n validateConfectFunctionIdentifier(name);\n const group_ = group as AnyWithProps;\n\n if (group_.name === name) {\n return group_;\n }\n\n return makeProto({\n runtime: group_.runtime,\n name,\n functions: group_.functions,\n groups: group_.groups,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;AAKA,MAAa,SAAS;AAGtB,MAAa,eAAe,MAC1B,UAAU,YAAY,GAAG,OAAO;AAoFlC,MAAM,QAAQ;EACX,SAAS;CAEV,YAEE,WACA;EACA,MAAM,QAAQ;AAEd,SAAO,UAAU;GACf,SAAS,MAAM;GACf,MAAM,MAAM;GACZ,WAAW,OAAO,IAAI,MAAM,WAAW,UAAU,MAAM,UAAU;GACjE,QAAQ,MAAM;GACf,CAAC;;CAGJ,SAAuC,OAAc;EACnD,MAAM,QAAQ;EACd,MAAM,SAAS;AAEf,SAAO,UAAU;GACf,SAAS,MAAM;GACf,MAAM,MAAM;GACZ,WAAW,MAAM;GACjB,QAAQ,OAAO,IAAI,MAAM,QAAQ,OAAO,MAAM,OAAO;GACtD,CAAC;;CAGJ,WAAyC,MAAc,OAAc;EACnE,MAAM,QAAQ;EACd,MAAM,SAAS;AAEf,SAAO,UAAU;GACf,SAAS,MAAM;GACf,MAAM,MAAM;GACZ,WAAW,MAAM;GACjB,QAAQ,OAAO,IAAI,MAAM,QAAQ,MAAM,SAAS,MAAM,OAAO,CAAC;GAC/D,CAAC;;CAEL;AAED,MAAM,aAKJ,EACA,SACA,MACA,WACA,aAOA,OAAO,OAAO,OAAO,OAAO,MAAM,EAAE;CAClC;CACA;CACA;CACA;CACD,CAAC;AAEJ,MAAa,aACX,UAAU;CACR,SAAS;CACT,MAAM;CACN,WAAW,OAAO,OAAO;CACzB,QAAQ,OAAO,OAAO;CACvB,CAAC;AAEJ,MAAa,UACX,SAC+B;AAC/B,mCAAkC,KAAK;AAEvC,QAAO,UAAU;EACf,SAAS;EACT;EACA,WAAW,OAAO,OAAO;EACzB,QAAQ,OAAO,OAAO;EACvB,CAAC;;AAGJ,MAAa,iBACX,UAAU;CACR,SAAS;CACT,MAAM;CACN,WAAW,OAAO,OAAO;CACzB,QAAQ,OAAO,OAAO;CACvB,CAAC;AAEJ,MAAa,cACX,SAC6B;AAC7B,mCAAkC,KAAK;AAEvC,QAAO,UAAU;EACf,SAAS;EACT;EACA,WAAW,OAAO,OAAO;EACzB,QAAQ,OAAO,OAAO;EACvB,CAAC;;AAGJ,MAAa,YACX,MACA,UACiB;AACjB,mCAAkC,KAAK;CACvC,MAAM,SAAS;AAEf,KAAI,OAAO,SAAS,KAClB,QAAO;AAGT,QAAO,UAAU;EACf,SAAS,OAAO;EAChB;EACA,WAAW,OAAO;EAClB,QAAQ,OAAO;EAChB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
declare namespace Identifier_d_exports {
|
|
2
|
+
export { validateConfectFunctionIdentifier, validateConfectTableIdentifier };
|
|
3
|
+
}
|
|
4
|
+
declare const validateConfectFunctionIdentifier: (identifier: string) => void;
|
|
5
|
+
/**
|
|
6
|
+
* Validate that `identifier` is suitable as a Convex table name (and, equivalently,
|
|
7
|
+
* as a `confect/tables/<identifier>.ts` filename).
|
|
8
|
+
*
|
|
9
|
+
* Rules:
|
|
10
|
+
* - Must match `/^[A-Za-z][A-Za-z0-9_]*$/` — letter-leading, alphanumeric plus
|
|
11
|
+
* underscore. No `$` (not a valid Convex table name character); no leading
|
|
12
|
+
* `_` (Convex reserves `_<name>` for its system tables).
|
|
13
|
+
* - Must not be a reserved JavaScript identifier, so the name can also be used
|
|
14
|
+
* as a binding name in generated code without escaping.
|
|
15
|
+
*/
|
|
16
|
+
declare const validateConfectTableIdentifier: (identifier: string) => void;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { Identifier_d_exports, validateConfectFunctionIdentifier, validateConfectTableIdentifier };
|
|
19
|
+
//# sourceMappingURL=Identifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Identifier.d.ts","names":[],"sources":["../src/Identifier.ts"],"mappings":";;;cA4Ea,iCAAA,GAAqC,UAAA;;;;;;;AAAlD;;;;;cA+Ba,8BAAA,GAAkC,UAAA"}
|