syncorejs 0.2.2 → 0.2.3
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/dist/_vendor/cli/app.d.mts.map +1 -1
- package/dist/_vendor/cli/app.mjs +8 -5
- package/dist/_vendor/cli/app.mjs.map +1 -1
- package/dist/_vendor/cli/context.mjs.map +1 -1
- package/dist/_vendor/cli/dev-session.mjs.map +1 -1
- package/dist/_vendor/cli/doctor.mjs.map +1 -1
- package/dist/_vendor/cli/errors.mjs.map +1 -1
- package/dist/_vendor/cli/help.mjs.map +1 -1
- package/dist/_vendor/cli/index.mjs +9 -2
- package/dist/_vendor/cli/index.mjs.map +1 -1
- package/dist/_vendor/cli/messages.mjs.map +1 -1
- package/dist/_vendor/cli/preflight.mjs.map +1 -1
- package/dist/_vendor/cli/project.mjs +20 -20
- package/dist/_vendor/cli/project.mjs.map +1 -1
- package/dist/_vendor/cli/render.mjs.map +1 -1
- package/dist/_vendor/cli/targets.mjs.map +1 -1
- package/dist/_vendor/core/cli.d.mts +8 -2
- package/dist/_vendor/core/cli.d.mts.map +1 -1
- package/dist/_vendor/core/cli.mjs +238 -64
- package/dist/_vendor/core/cli.mjs.map +1 -1
- package/dist/_vendor/core/devtools-auth.mjs.map +1 -1
- package/dist/_vendor/core/runtime/components.d.mts.map +1 -1
- package/dist/_vendor/core/runtime/components.mjs.map +1 -1
- package/dist/_vendor/core/runtime/devtools.d.mts.map +1 -1
- package/dist/_vendor/core/runtime/devtools.mjs +130 -23
- package/dist/_vendor/core/runtime/devtools.mjs.map +1 -1
- package/dist/_vendor/core/runtime/functions.d.mts +388 -6
- package/dist/_vendor/core/runtime/functions.d.mts.map +1 -1
- package/dist/_vendor/core/runtime/functions.mjs +72 -1
- package/dist/_vendor/core/runtime/functions.mjs.map +1 -1
- package/dist/_vendor/core/runtime/id.d.mts.map +1 -1
- package/dist/_vendor/core/runtime/id.mjs.map +1 -1
- package/dist/_vendor/core/runtime/internal/engines/devtoolsEngine.mjs +11 -5
- package/dist/_vendor/core/runtime/internal/engines/devtoolsEngine.mjs.map +1 -1
- package/dist/_vendor/core/runtime/internal/engines/executionEngine.mjs +123 -20
- package/dist/_vendor/core/runtime/internal/engines/executionEngine.mjs.map +1 -1
- package/dist/_vendor/core/runtime/internal/engines/reactivityEngine.mjs +56 -8
- package/dist/_vendor/core/runtime/internal/engines/reactivityEngine.mjs.map +1 -1
- package/dist/_vendor/core/runtime/internal/engines/schedulerEngine.mjs +49 -14
- package/dist/_vendor/core/runtime/internal/engines/schedulerEngine.mjs.map +1 -1
- package/dist/_vendor/core/runtime/internal/engines/schemaEngine.mjs +4 -7
- package/dist/_vendor/core/runtime/internal/engines/schemaEngine.mjs.map +1 -1
- package/dist/_vendor/core/runtime/internal/engines/shared.mjs +76 -1
- package/dist/_vendor/core/runtime/internal/engines/shared.mjs.map +1 -1
- package/dist/_vendor/core/runtime/internal/engines/storageEngine.mjs +1 -0
- package/dist/_vendor/core/runtime/internal/engines/storageEngine.mjs.map +1 -1
- package/dist/_vendor/core/runtime/internal/runtimeKernel.mjs +4 -3
- package/dist/_vendor/core/runtime/internal/runtimeKernel.mjs.map +1 -1
- package/dist/_vendor/core/runtime/internal/runtimeStatus.mjs.map +1 -1
- package/dist/_vendor/core/runtime/internal/systemMeta.mjs.map +1 -1
- package/dist/_vendor/core/runtime/internal/transactionCoordinator.mjs +4 -0
- package/dist/_vendor/core/runtime/internal/transactionCoordinator.mjs.map +1 -1
- package/dist/_vendor/core/runtime/runtime.d.mts +1040 -9
- package/dist/_vendor/core/runtime/runtime.d.mts.map +1 -1
- package/dist/_vendor/core/runtime/runtime.mjs +63 -0
- package/dist/_vendor/core/runtime/runtime.mjs.map +1 -1
- package/dist/_vendor/core/transport.d.mts +2 -0
- package/dist/_vendor/core/transport.d.mts.map +1 -1
- package/dist/_vendor/core/transport.mjs +33 -24
- package/dist/_vendor/core/transport.mjs.map +1 -1
- package/dist/_vendor/devtools-protocol/index.d.ts +149 -4
- package/dist/_vendor/devtools-protocol/index.d.ts.map +1 -1
- package/dist/_vendor/devtools-protocol/index.js.map +1 -1
- package/dist/_vendor/next/config.d.ts +3 -4
- package/dist/_vendor/next/config.d.ts.map +1 -1
- package/dist/_vendor/next/config.js +37 -19
- package/dist/_vendor/next/config.js.map +1 -1
- package/dist/_vendor/next/index.d.ts +109 -29
- package/dist/_vendor/next/index.d.ts.map +1 -1
- package/dist/_vendor/next/index.js +77 -17
- package/dist/_vendor/next/index.js.map +1 -1
- package/dist/_vendor/platform-expo/index.d.ts +146 -27
- package/dist/_vendor/platform-expo/index.d.ts.map +1 -1
- package/dist/_vendor/platform-expo/index.js +76 -10
- package/dist/_vendor/platform-expo/index.js.map +1 -1
- package/dist/_vendor/platform-expo/react.js.map +1 -1
- package/dist/_vendor/platform-expo/web-sqljs-wasm.js +16 -0
- package/dist/_vendor/platform-expo/web-sqljs-wasm.js.map +1 -0
- package/dist/_vendor/platform-node/index.d.mts +173 -9
- package/dist/_vendor/platform-node/index.d.mts.map +1 -1
- package/dist/_vendor/platform-node/index.mjs +225 -94
- package/dist/_vendor/platform-node/index.mjs.map +1 -1
- package/dist/_vendor/platform-node/ipc-react.mjs.map +1 -1
- package/dist/_vendor/platform-node/ipc.d.mts.map +1 -1
- package/dist/_vendor/platform-node/ipc.mjs.map +1 -1
- package/dist/_vendor/platform-web/external-change.d.ts +41 -0
- package/dist/_vendor/platform-web/external-change.d.ts.map +1 -1
- package/dist/_vendor/platform-web/external-change.js +30 -0
- package/dist/_vendor/platform-web/external-change.js.map +1 -1
- package/dist/_vendor/platform-web/index.d.ts +307 -35
- package/dist/_vendor/platform-web/index.d.ts.map +1 -1
- package/dist/_vendor/platform-web/index.js +189 -23
- package/dist/_vendor/platform-web/index.js.map +1 -1
- package/dist/_vendor/platform-web/indexeddb.d.ts +12 -0
- package/dist/_vendor/platform-web/indexeddb.d.ts.map +1 -1
- package/dist/_vendor/platform-web/indexeddb.js +10 -0
- package/dist/_vendor/platform-web/indexeddb.js.map +1 -1
- package/dist/_vendor/platform-web/opfs.d.ts +13 -0
- package/dist/_vendor/platform-web/opfs.d.ts.map +1 -1
- package/dist/_vendor/platform-web/opfs.js +12 -0
- package/dist/_vendor/platform-web/opfs.js.map +1 -1
- package/dist/_vendor/platform-web/persistence.d.ts +54 -0
- package/dist/_vendor/platform-web/persistence.d.ts.map +1 -1
- package/dist/_vendor/platform-web/persistence.js +15 -0
- package/dist/_vendor/platform-web/persistence.js.map +1 -1
- package/dist/_vendor/platform-web/react.d.ts +1 -2
- package/dist/_vendor/platform-web/react.d.ts.map +1 -1
- package/dist/_vendor/platform-web/react.js +2 -4
- package/dist/_vendor/platform-web/react.js.map +1 -1
- package/dist/_vendor/platform-web/sqljs.js +10 -1
- package/dist/_vendor/platform-web/sqljs.js.map +1 -1
- package/dist/_vendor/platform-web/web-sqljs-wasm.js +8 -0
- package/dist/_vendor/platform-web/web-sqljs-wasm.js.map +1 -0
- package/dist/_vendor/platform-web/worker.d.ts +60 -9
- package/dist/_vendor/platform-web/worker.d.ts.map +1 -1
- package/dist/_vendor/platform-web/worker.js +37 -4
- package/dist/_vendor/platform-web/worker.js.map +1 -1
- package/dist/_vendor/react/index.d.ts +196 -13
- package/dist/_vendor/react/index.d.ts.map +1 -1
- package/dist/_vendor/react/index.js +208 -17
- package/dist/_vendor/react/index.js.map +1 -1
- package/dist/_vendor/schema/definition.d.ts +129 -0
- package/dist/_vendor/schema/definition.d.ts.map +1 -1
- package/dist/_vendor/schema/definition.js +99 -0
- package/dist/_vendor/schema/definition.js.map +1 -1
- package/dist/_vendor/schema/planner.d.ts.map +1 -1
- package/dist/_vendor/schema/planner.js.map +1 -1
- package/dist/_vendor/schema/validators.d.ts +180 -4
- package/dist/_vendor/schema/validators.d.ts.map +1 -1
- package/dist/_vendor/schema/validators.js +35 -1
- package/dist/_vendor/schema/validators.js.map +1 -1
- package/dist/_vendor/svelte/index.d.ts +205 -7
- package/dist/_vendor/svelte/index.d.ts.map +1 -1
- package/dist/_vendor/svelte/index.js +199 -6
- package/dist/_vendor/svelte/index.js.map +1 -1
- package/dist/browser.d.ts.map +1 -1
- package/dist/cli.js +3 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +24 -21
|
@@ -1,12 +1,56 @@
|
|
|
1
1
|
import { Infer, Validator, ValidatorMap } from "../../schema/index.d.ts";
|
|
2
2
|
|
|
3
3
|
//#region src/runtime/functions.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Discriminates the three function kinds Syncore supports.
|
|
6
|
+
*
|
|
7
|
+
* - `"query"` — read-only handler that observes local state. Syncore re-runs it
|
|
8
|
+
* automatically whenever any table it read changes, keeping connected clients
|
|
9
|
+
* up to date without manual cache invalidation.
|
|
10
|
+
* - `"mutation"` — transactional write handler. Runs inside a single SQLite
|
|
11
|
+
* transaction and automatically invalidates every query that read the tables it
|
|
12
|
+
* modified.
|
|
13
|
+
* - `"action"` — arbitrary async handler that may call external services, invoke
|
|
14
|
+
* other Syncore functions, or schedule deferred work. Actions do not run inside
|
|
15
|
+
* a transaction and cannot directly write to the database — they must delegate
|
|
16
|
+
* writes to mutations.
|
|
17
|
+
*/
|
|
4
18
|
type SyncoreFunctionKind = "query" | "mutation" | "action";
|
|
19
|
+
/**
|
|
20
|
+
* Convenience type representing a function that accepts no arguments.
|
|
21
|
+
*
|
|
22
|
+
* Used as the default `TArgs` for {@link FunctionReference} so that calling
|
|
23
|
+
* `client.query(api.tasks.list)` without a second argument is type-safe.
|
|
24
|
+
*/
|
|
5
25
|
type EmptyArgs = Record<never, never>;
|
|
6
26
|
/**
|
|
7
|
-
* A typed
|
|
27
|
+
* A typed, serialisable handle to a registered Syncore function.
|
|
28
|
+
*
|
|
29
|
+
* `FunctionReference` objects are how you address Syncore functions across the
|
|
30
|
+
* entire API surface: hooks, client calls, scheduler helpers, and `ctx.runQuery`
|
|
31
|
+
* / `ctx.runMutation` inside other functions all accept them. They carry the
|
|
32
|
+
* function's kind and its fully-inferred arg / result types at the type level,
|
|
33
|
+
* but at runtime they hold only the function's string name, making them safe to
|
|
34
|
+
* pass across IPC channels.
|
|
35
|
+
*
|
|
36
|
+
* In almost every case you get references from the auto-generated `api` object
|
|
37
|
+
* rather than constructing them manually:
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { api } from "../syncore/_generated/api";
|
|
41
|
+
*
|
|
42
|
+
* // In a React component:
|
|
43
|
+
* const tasks = useQuery(api.tasks.list);
|
|
44
|
+
*
|
|
45
|
+
* // Inside a mutation that calls another function:
|
|
46
|
+
* const id = await ctx.runMutation(api.tasks.create, { title: "Buy milk" });
|
|
8
47
|
*
|
|
9
|
-
*
|
|
48
|
+
* // Scheduling deferred work:
|
|
49
|
+
* await ctx.scheduler.runAfter(60_000, api.notifications.send, { userId });
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* When you need to type a parameter that accepts a function reference, derive
|
|
53
|
+
* the correct type with {@link FunctionReferenceFor}.
|
|
10
54
|
*/
|
|
11
55
|
interface FunctionReference<TKind extends SyncoreFunctionKind = SyncoreFunctionKind, TArgs = EmptyArgs, TResult = unknown> {
|
|
12
56
|
kind: TKind;
|
|
@@ -14,34 +58,161 @@ interface FunctionReference<TKind extends SyncoreFunctionKind = SyncoreFunctionK
|
|
|
14
58
|
readonly __args?: TArgs;
|
|
15
59
|
readonly __result?: TResult;
|
|
16
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* The full definition of a Syncore function as produced by {@link query},
|
|
63
|
+
* {@link mutation}, or {@link action}.
|
|
64
|
+
*
|
|
65
|
+
* This is the value you export from files inside `syncore/functions/`. Syncore
|
|
66
|
+
* stores it in the function registry and uses the validators at runtime to parse
|
|
67
|
+
* incoming arguments and optionally validate return values.
|
|
68
|
+
*
|
|
69
|
+
* You rarely reference this type directly in application code — use
|
|
70
|
+
* {@link FunctionReferenceFor} when you need a type-level handle, or the
|
|
71
|
+
* generated `api` object for runtime usage.
|
|
72
|
+
*/
|
|
17
73
|
interface SyncoreFunctionDefinition<TKind extends SyncoreFunctionKind, TContext, TArgs, TResult> {
|
|
18
74
|
kind: TKind;
|
|
19
75
|
argsValidator: Validator<TArgs, TArgs, string>;
|
|
20
76
|
returnsValidator?: Validator<TResult, TResult, string>;
|
|
21
77
|
handler: (ctx: TContext, args: TArgs) => Promise<TResult> | TResult;
|
|
22
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Extracts the argument type from a {@link FunctionReference}.
|
|
81
|
+
*
|
|
82
|
+
* Useful when writing generic helpers that accept a function reference and need
|
|
83
|
+
* to type the corresponding arguments:
|
|
84
|
+
*
|
|
85
|
+
* ```ts
|
|
86
|
+
* async function run<TRef extends FunctionReference<"mutation">>(
|
|
87
|
+
* ref: TRef,
|
|
88
|
+
* args: FunctionArgs<TRef>
|
|
89
|
+
* ) { ... }
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
23
92
|
type FunctionArgs<TReference> = TReference extends FunctionReference<SyncoreFunctionKind, infer TArgs, unknown> ? TArgs : never;
|
|
93
|
+
/**
|
|
94
|
+
* Extracts the result type from a {@link FunctionReference}.
|
|
95
|
+
*
|
|
96
|
+
* ```ts
|
|
97
|
+
* type TaskList = FunctionResult<typeof api.tasks.list>; // Task[]
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
24
100
|
type FunctionResult<TReference> = TReference extends FunctionReference<SyncoreFunctionKind, unknown, infer TResult> ? TResult : never;
|
|
101
|
+
/**
|
|
102
|
+
* Extracts the {@link SyncoreFunctionKind} from a function definition object.
|
|
103
|
+
*
|
|
104
|
+
* Used internally by {@link FunctionReferenceFor} and the code generator.
|
|
105
|
+
*/
|
|
25
106
|
type FunctionKindFromDefinition<TDefinition> = TDefinition extends {
|
|
26
107
|
kind: infer TKind;
|
|
27
108
|
} ? Extract<TKind, SyncoreFunctionKind> : never;
|
|
109
|
+
/**
|
|
110
|
+
* Extracts the validated argument type from a function definition object.
|
|
111
|
+
*
|
|
112
|
+
* Used internally by {@link FunctionReferenceFor} and the code generator.
|
|
113
|
+
*/
|
|
28
114
|
type FunctionArgsFromDefinition<TDefinition> = TDefinition extends {
|
|
29
115
|
argsValidator: Validator<infer TArgs, unknown, string>;
|
|
30
116
|
} ? TArgs : never;
|
|
117
|
+
/**
|
|
118
|
+
* Extracts the return type from a function definition object.
|
|
119
|
+
*
|
|
120
|
+
* Used internally by {@link FunctionReferenceFor} and the code generator.
|
|
121
|
+
*/
|
|
31
122
|
type FunctionResultFromDefinition<TDefinition> = TDefinition extends {
|
|
32
123
|
returnsValidator?: Validator<infer TResult, unknown, string>;
|
|
33
124
|
} ? TResult : never;
|
|
125
|
+
/**
|
|
126
|
+
* Derives a fully-typed {@link FunctionReference} from a function definition.
|
|
127
|
+
*
|
|
128
|
+
* Use this when you need a typed reference to a function you have imported
|
|
129
|
+
* directly — for example when writing test helpers or custom wrappers:
|
|
130
|
+
*
|
|
131
|
+
* ```ts
|
|
132
|
+
* import type { create } from "../syncore/functions/tasks";
|
|
133
|
+
*
|
|
134
|
+
* type CreateRef = FunctionReferenceFor<typeof create>;
|
|
135
|
+
* // FunctionReference<"mutation", { title: string }, string>
|
|
136
|
+
* ```
|
|
137
|
+
*
|
|
138
|
+
* The generated `api` object already exposes `FunctionReferenceFor`-derived
|
|
139
|
+
* values for every exported function, so you rarely need this in application
|
|
140
|
+
* code.
|
|
141
|
+
*/
|
|
34
142
|
type FunctionReferenceFor<TDefinition> = FunctionKindFromDefinition<TDefinition> extends never ? never : FunctionReference<FunctionKindFromDefinition<TDefinition>, FunctionArgsFromDefinition<TDefinition>, FunctionResultFromDefinition<TDefinition>>;
|
|
143
|
+
/**
|
|
144
|
+
* Configuration object accepted by {@link query}, {@link mutation}, and
|
|
145
|
+
* {@link action}.
|
|
146
|
+
*
|
|
147
|
+
* @template TContext - The execution context injected by the runtime
|
|
148
|
+
* (`QueryCtx`, `MutationCtx`, or `ActionCtx`).
|
|
149
|
+
* @template TArgs - The validated argument shape after parsing.
|
|
150
|
+
* @template TResult - The return type of the handler.
|
|
151
|
+
*/
|
|
35
152
|
interface FunctionConfig<TContext, TArgs, TResult> {
|
|
153
|
+
/**
|
|
154
|
+
* Schema that validates and types the arguments this function accepts.
|
|
155
|
+
*
|
|
156
|
+
* You can pass either a single `Validator` or a plain object ("validator map")
|
|
157
|
+
* whose keys map to individual field validators — both forms are equivalent:
|
|
158
|
+
*
|
|
159
|
+
* ```ts
|
|
160
|
+
* // Validator map (most common)
|
|
161
|
+
* args: { title: s.string(), done: s.boolean() }
|
|
162
|
+
*
|
|
163
|
+
* // Single object validator (same result)
|
|
164
|
+
* args: s.object({ title: s.string(), done: s.boolean() })
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
36
167
|
args: Validator<TArgs, TArgs, string> | ValidatorMap;
|
|
168
|
+
/**
|
|
169
|
+
* Optional schema that validates the value returned by the handler.
|
|
170
|
+
*
|
|
171
|
+
* When provided, Syncore validates the return value before sending it to
|
|
172
|
+
* clients. Omitting `returns` disables return-value validation but does not
|
|
173
|
+
* affect the TypeScript return type inferred from the handler.
|
|
174
|
+
*/
|
|
37
175
|
returns?: Validator<TResult, TResult, string>;
|
|
176
|
+
/**
|
|
177
|
+
* The function body. Receives a typed context object and the validated
|
|
178
|
+
* arguments and must return (or resolve to) the function's result.
|
|
179
|
+
*/
|
|
38
180
|
handler: (ctx: TContext, args: TArgs) => Promise<TResult> | TResult;
|
|
39
181
|
}
|
|
40
182
|
type InferArgs<TArgs extends Validator<unknown, unknown, string> | ValidatorMap> = TArgs extends Validator<unknown, unknown, string> ? Infer<TArgs> : TArgs extends ValidatorMap ? { [TKey in keyof TArgs]: Infer<TArgs[TKey]> } : never;
|
|
41
183
|
/**
|
|
42
184
|
* Define a Syncore query.
|
|
43
185
|
*
|
|
44
|
-
* Queries
|
|
186
|
+
* Queries are the read layer of Syncore. They run inside a read-only database
|
|
187
|
+
* transaction, may call other queries via `ctx.runQuery`, and are
|
|
188
|
+
* **automatically reactive**: whenever a table that a query read changes,
|
|
189
|
+
* every active subscription to that query is invalidated and re-executed.
|
|
190
|
+
*
|
|
191
|
+
* Export one query per named export in a file under `syncore/functions/`.
|
|
192
|
+
* After running `npx syncorejs codegen` a typed reference will be available
|
|
193
|
+
* on the generated `api` object.
|
|
194
|
+
*
|
|
195
|
+
* ```ts
|
|
196
|
+
* // syncore/functions/tasks.ts
|
|
197
|
+
* import { query } from "syncorejs";
|
|
198
|
+
* import { s } from "syncorejs";
|
|
199
|
+
* import type { QueryCtx } from "../_generated/server";
|
|
200
|
+
*
|
|
201
|
+
* export const list = query({
|
|
202
|
+
* args: { projectId: s.optional(s.id("projects")) },
|
|
203
|
+
* handler: async (ctx: QueryCtx, { projectId }) => {
|
|
204
|
+
* return ctx.db
|
|
205
|
+
* .query("tasks")
|
|
206
|
+
* .withIndex("by_project", (q) =>
|
|
207
|
+
* projectId ? q.eq("projectId", projectId) : q
|
|
208
|
+
* )
|
|
209
|
+
* .collect();
|
|
210
|
+
* },
|
|
211
|
+
* });
|
|
212
|
+
* ```
|
|
213
|
+
*
|
|
214
|
+
* @param config - The {@link FunctionConfig} describing the args schema,
|
|
215
|
+
* optional return-value schema, and handler function.
|
|
45
216
|
*/
|
|
46
217
|
declare function query<TContext = unknown, TValidator extends Validator<unknown, unknown, string> = Validator<unknown, unknown, string>, TResult = unknown>(config: FunctionConfig<TContext, Infer<TValidator>, TResult> & {
|
|
47
218
|
args: TValidator;
|
|
@@ -52,7 +223,36 @@ declare function query<TContext = unknown, TArgsShape extends ValidatorMap = Val
|
|
|
52
223
|
/**
|
|
53
224
|
* Define a Syncore mutation.
|
|
54
225
|
*
|
|
55
|
-
* Mutations
|
|
226
|
+
* Mutations are the write layer of Syncore. Every mutation runs inside an
|
|
227
|
+
* **atomic SQLite transaction**: if the handler throws, all writes are rolled
|
|
228
|
+
* back. After a successful commit Syncore automatically invalidates and
|
|
229
|
+
* re-executes every active query whose read-set overlaps the changed tables.
|
|
230
|
+
*
|
|
231
|
+
* Mutations receive a {@link MutationCtx}, which extends the query context
|
|
232
|
+
* with `ctx.db` write methods and a `ctx.scheduler` for scheduling deferred
|
|
233
|
+
* work.
|
|
234
|
+
*
|
|
235
|
+
* ```ts
|
|
236
|
+
* // syncore/functions/tasks.ts
|
|
237
|
+
* import { mutation } from "syncorejs";
|
|
238
|
+
* import { s } from "syncorejs";
|
|
239
|
+
* import type { MutationCtx } from "../_generated/server";
|
|
240
|
+
*
|
|
241
|
+
* export const create = mutation({
|
|
242
|
+
* args: { title: s.string() },
|
|
243
|
+
* returns: s.id("tasks"),
|
|
244
|
+
* handler: async (ctx: MutationCtx, { title }) => {
|
|
245
|
+
* return ctx.db.insert("tasks", {
|
|
246
|
+
* title,
|
|
247
|
+
* status: "todo",
|
|
248
|
+
* projectId: null,
|
|
249
|
+
* });
|
|
250
|
+
* },
|
|
251
|
+
* });
|
|
252
|
+
* ```
|
|
253
|
+
*
|
|
254
|
+
* @param config - The {@link FunctionConfig} describing the args schema,
|
|
255
|
+
* optional return-value schema, and handler function.
|
|
56
256
|
*/
|
|
57
257
|
declare function mutation<TContext = unknown, TValidator extends Validator<unknown, unknown, string> = Validator<unknown, unknown, string>, TResult = unknown>(config: FunctionConfig<TContext, Infer<TValidator>, TResult> & {
|
|
58
258
|
args: TValidator;
|
|
@@ -63,7 +263,38 @@ declare function mutation<TContext = unknown, TArgsShape extends ValidatorMap =
|
|
|
63
263
|
/**
|
|
64
264
|
* Define a Syncore action.
|
|
65
265
|
*
|
|
66
|
-
* Actions
|
|
266
|
+
* Actions are the escape hatch for work that goes beyond reading and writing
|
|
267
|
+
* the local database. They run **outside** of any transaction, which means
|
|
268
|
+
* they can:
|
|
269
|
+
*
|
|
270
|
+
* - Call external APIs (HTTP, WebSocket, etc.)
|
|
271
|
+
* - Perform CPU-intensive or long-running work
|
|
272
|
+
* - Invoke other Syncore functions via `ctx.runMutation` / `ctx.runQuery`
|
|
273
|
+
* - Schedule deferred jobs via `ctx.scheduler`
|
|
274
|
+
*
|
|
275
|
+
* Because actions are non-transactional, database writes must be delegated to
|
|
276
|
+
* a mutation. This keeps write atomicity in mutations while actions handle
|
|
277
|
+
* side effects.
|
|
278
|
+
*
|
|
279
|
+
* ```ts
|
|
280
|
+
* // syncore/functions/ai.ts
|
|
281
|
+
* import { action } from "syncorejs";
|
|
282
|
+
* import { s } from "syncorejs";
|
|
283
|
+
* import type { ActionCtx } from "../_generated/server";
|
|
284
|
+
* import { api } from "../_generated/api";
|
|
285
|
+
*
|
|
286
|
+
* export const summarise = action({
|
|
287
|
+
* args: { taskId: s.id("tasks") },
|
|
288
|
+
* handler: async (ctx: ActionCtx, { taskId }) => {
|
|
289
|
+
* const task = await ctx.runQuery(api.tasks.get, { id: taskId });
|
|
290
|
+
* const summary = await fetchSummaryFromApi(task.title);
|
|
291
|
+
* await ctx.runMutation(api.tasks.setSummary, { taskId, summary });
|
|
292
|
+
* },
|
|
293
|
+
* });
|
|
294
|
+
* ```
|
|
295
|
+
*
|
|
296
|
+
* @param config - The {@link FunctionConfig} describing the args schema,
|
|
297
|
+
* optional return-value schema, and handler function.
|
|
67
298
|
*/
|
|
68
299
|
declare function action<TContext = unknown, TValidator extends Validator<unknown, unknown, string> = Validator<unknown, unknown, string>, TResult = unknown>(config: FunctionConfig<TContext, Infer<TValidator>, TResult> & {
|
|
69
300
|
args: TValidator;
|
|
@@ -71,26 +302,95 @@ declare function action<TContext = unknown, TValidator extends Validator<unknown
|
|
|
71
302
|
declare function action<TContext = unknown, TArgsShape extends ValidatorMap = ValidatorMap, TResult = unknown>(config: FunctionConfig<TContext, InferArgs<TArgsShape>, TResult> & {
|
|
72
303
|
args: TArgsShape;
|
|
73
304
|
}): SyncoreFunctionDefinition<"action", TContext, InferArgs<TArgsShape>, TResult>;
|
|
305
|
+
/**
|
|
306
|
+
* Runs a recurring job repeatedly at a fixed time interval.
|
|
307
|
+
*
|
|
308
|
+
* At least one of `seconds`, `minutes`, or `hours` must be provided; multiple
|
|
309
|
+
* fields are additive (e.g. `{ hours: 1, minutes: 30 }` fires every 90 minutes).
|
|
310
|
+
*
|
|
311
|
+
* ```ts
|
|
312
|
+
* crons.interval("refresh-cache", { minutes: 15 }, api.cache.refresh);
|
|
313
|
+
* ```
|
|
314
|
+
*/
|
|
74
315
|
interface RecurringIntervalSchedule {
|
|
75
316
|
type: "interval";
|
|
317
|
+
/** Number of seconds to add to the interval. */
|
|
76
318
|
seconds?: number;
|
|
319
|
+
/** Number of minutes to add to the interval. */
|
|
77
320
|
minutes?: number;
|
|
321
|
+
/** Number of hours to add to the interval. */
|
|
78
322
|
hours?: number;
|
|
79
323
|
}
|
|
324
|
+
/**
|
|
325
|
+
* Runs a recurring job once a day at a specific wall-clock time.
|
|
326
|
+
*
|
|
327
|
+
* ```ts
|
|
328
|
+
* crons.daily("nightly-report", { hour: 2, minute: 0 }, api.reports.generate);
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
80
331
|
interface RecurringDailySchedule {
|
|
81
332
|
type: "daily";
|
|
333
|
+
/** Hour of day to run (0–23, in UTC unless `timezone` is provided). */
|
|
82
334
|
hour: number;
|
|
335
|
+
/** Minute of hour to run (0–59). */
|
|
83
336
|
minute: number;
|
|
337
|
+
/**
|
|
338
|
+
* IANA timezone name (e.g. `"America/New_York"`). Defaults to UTC when
|
|
339
|
+
* omitted.
|
|
340
|
+
*/
|
|
84
341
|
timezone?: string;
|
|
85
342
|
}
|
|
343
|
+
/**
|
|
344
|
+
* Runs a recurring job once a week on a specific day and time.
|
|
345
|
+
*
|
|
346
|
+
* ```ts
|
|
347
|
+
* crons.weekly(
|
|
348
|
+
* "weekly-digest",
|
|
349
|
+
* { dayOfWeek: "monday", hour: 9, minute: 0, timezone: "Europe/London" },
|
|
350
|
+
* api.email.weeklyDigest
|
|
351
|
+
* );
|
|
352
|
+
* ```
|
|
353
|
+
*/
|
|
86
354
|
interface RecurringWeeklySchedule {
|
|
87
355
|
type: "weekly";
|
|
356
|
+
/** Day of the week on which to fire. */
|
|
88
357
|
dayOfWeek: "sunday" | "monday" | "tuesday" | "wednesday" | "thursday" | "friday" | "saturday";
|
|
358
|
+
/** Hour of day to run (0–23, in UTC unless `timezone` is provided). */
|
|
89
359
|
hour: number;
|
|
360
|
+
/** Minute of hour to run (0–59). */
|
|
90
361
|
minute: number;
|
|
362
|
+
/**
|
|
363
|
+
* IANA timezone name (e.g. `"America/New_York"`). Defaults to UTC when
|
|
364
|
+
* omitted.
|
|
365
|
+
*/
|
|
91
366
|
timezone?: string;
|
|
92
367
|
}
|
|
368
|
+
/**
|
|
369
|
+
* Union of all supported recurring-schedule shapes.
|
|
370
|
+
*
|
|
371
|
+
* Pass this (or one of its members) to {@link RecurringJobDefinition.schedule}
|
|
372
|
+
* or to the fluent helpers on {@link CronJobs}.
|
|
373
|
+
*/
|
|
93
374
|
type RecurringSchedule = RecurringIntervalSchedule | RecurringDailySchedule | RecurringWeeklySchedule;
|
|
375
|
+
/**
|
|
376
|
+
* Determines how the scheduler reacts when a job run is missed (e.g. because
|
|
377
|
+
* the runtime was offline when the job was supposed to fire).
|
|
378
|
+
*
|
|
379
|
+
* - `"catch_up"` — Run the job once for every missed execution window. Use for
|
|
380
|
+
* jobs where every run matters (e.g. per-minute metrics collection).
|
|
381
|
+
* - `"skip"` — Skip all missed runs and resume on the next scheduled tick.
|
|
382
|
+
* Safe default when running the job twice in quick succession would be
|
|
383
|
+
* harmful.
|
|
384
|
+
* - `"run_once_if_missed"` — If any runs were missed, execute the job exactly
|
|
385
|
+
* once to “catch up”, then continue on the normal schedule.
|
|
386
|
+
* - `"windowed"` — Catch up, but only within a specific time window. Missed
|
|
387
|
+
* runs older than `windowMs` milliseconds are discarded.
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* ```ts
|
|
391
|
+
* const policy: MisfirePolicy = { type: "windowed", windowMs: 5 * 60_000 };
|
|
392
|
+
* ```
|
|
393
|
+
*/
|
|
94
394
|
type MisfirePolicy = {
|
|
95
395
|
type: "catch_up";
|
|
96
396
|
} | {
|
|
@@ -101,21 +401,103 @@ type MisfirePolicy = {
|
|
|
101
401
|
type: "windowed";
|
|
102
402
|
windowMs: number;
|
|
103
403
|
};
|
|
404
|
+
/**
|
|
405
|
+
* A single entry in the recurring-job registry.
|
|
406
|
+
*
|
|
407
|
+
* You can construct these manually and pass them to `scheduler.recurringJobs`,
|
|
408
|
+
* but the fluent {@link CronJobs} builder is usually more readable.
|
|
409
|
+
*/
|
|
104
410
|
interface RecurringJobDefinition {
|
|
411
|
+
/** Unique name used to identify this job in the scheduler and devtools UI. */
|
|
105
412
|
name: string;
|
|
413
|
+
/** When and how often this job should run. */
|
|
106
414
|
schedule: RecurringSchedule;
|
|
415
|
+
/** The function to invoke. Must be a mutation or action reference. */
|
|
107
416
|
function: FunctionReference<"mutation" | "action">;
|
|
417
|
+
/** Arguments forwarded to the function on every invocation. */
|
|
108
418
|
args: Record<string, unknown>;
|
|
419
|
+
/** How to handle missed executions. */
|
|
109
420
|
misfirePolicy: MisfirePolicy;
|
|
110
421
|
}
|
|
422
|
+
/**
|
|
423
|
+
* Fluent builder for declaring the recurring (cron) jobs of a Syncore app.
|
|
424
|
+
*
|
|
425
|
+
* Instantiate with {@link cronJobs} and chain calls to `.interval()`, `.daily()`,
|
|
426
|
+
* or `.weekly()`. Pass the resulting instance's `.jobs` array to
|
|
427
|
+
* `scheduler.recurringJobs` in your runtime options.
|
|
428
|
+
*
|
|
429
|
+
* ```ts
|
|
430
|
+
* // syncore/crons.ts
|
|
431
|
+
* import { cronJobs } from "syncorejs";
|
|
432
|
+
* import { api } from "./_generated/api";
|
|
433
|
+
*
|
|
434
|
+
* const crons = cronJobs();
|
|
435
|
+
*
|
|
436
|
+
* crons.interval("refresh-feed", { minutes: 10 }, api.feed.refresh);
|
|
437
|
+
* crons.daily("send-digest", { hour: 8, minute: 0 }, api.email.digest);
|
|
438
|
+
* crons.weekly("weekly-cleanup", { dayOfWeek: "sunday", hour: 3, minute: 0 }, api.db.vacuum);
|
|
439
|
+
*
|
|
440
|
+
* export default crons;
|
|
441
|
+
* ```
|
|
442
|
+
*
|
|
443
|
+
* Then in your runtime setup:
|
|
444
|
+
* ```ts
|
|
445
|
+
* createNodeSyncoreRuntime({
|
|
446
|
+
* ...,
|
|
447
|
+
* scheduler: { recurringJobs: crons.jobs },
|
|
448
|
+
* });
|
|
449
|
+
* ```
|
|
450
|
+
*/
|
|
111
451
|
declare class CronJobs {
|
|
112
452
|
readonly jobs: RecurringJobDefinition[];
|
|
453
|
+
/**
|
|
454
|
+
* Register a job that fires repeatedly at a fixed time interval.
|
|
455
|
+
*
|
|
456
|
+
* @param name - Unique identifier for this job.
|
|
457
|
+
* @param schedule - Interval fields (`seconds`, `minutes`, `hours`).
|
|
458
|
+
* @param functionReference - Mutation or action to invoke.
|
|
459
|
+
* @param args - Arguments forwarded on every invocation.
|
|
460
|
+
* @param misfirePolicy - How to handle runs missed while the runtime was
|
|
461
|
+
* offline. Defaults to `{ type: "catch_up" }`.
|
|
462
|
+
*/
|
|
113
463
|
interval(name: string, schedule: Omit<RecurringIntervalSchedule, "type">, functionReference: FunctionReference<"mutation" | "action">, args?: Record<string, unknown>, misfirePolicy?: MisfirePolicy): this;
|
|
464
|
+
/**
|
|
465
|
+
* Register a job that fires once a day at a given wall-clock time.
|
|
466
|
+
*
|
|
467
|
+
* @param name - Unique identifier for this job.
|
|
468
|
+
* @param schedule - `hour` (0–23), `minute` (0–59), optional `timezone`.
|
|
469
|
+
* @param functionReference - Mutation or action to invoke.
|
|
470
|
+
* @param args - Arguments forwarded on every invocation.
|
|
471
|
+
* @param misfirePolicy - How to handle runs missed while the runtime was
|
|
472
|
+
* offline. Defaults to `{ type: "catch_up" }`.
|
|
473
|
+
*/
|
|
114
474
|
daily(name: string, schedule: Omit<RecurringDailySchedule, "type">, functionReference: FunctionReference<"mutation" | "action">, args?: Record<string, unknown>, misfirePolicy?: MisfirePolicy): this;
|
|
475
|
+
/**
|
|
476
|
+
* Register a job that fires once a week on a given day and time.
|
|
477
|
+
*
|
|
478
|
+
* @param name - Unique identifier for this job.
|
|
479
|
+
* @param schedule - `dayOfWeek`, `hour` (0–23), `minute` (0–59),
|
|
480
|
+
* optional `timezone`.
|
|
481
|
+
* @param functionReference - Mutation or action to invoke.
|
|
482
|
+
* @param args - Arguments forwarded on every invocation.
|
|
483
|
+
* @param misfirePolicy - How to handle runs missed while the runtime was
|
|
484
|
+
* offline. Defaults to `{ type: "catch_up" }`.
|
|
485
|
+
*/
|
|
115
486
|
weekly(name: string, schedule: Omit<RecurringWeeklySchedule, "type">, functionReference: FunctionReference<"mutation" | "action">, args?: Record<string, unknown>, misfirePolicy?: MisfirePolicy): this;
|
|
116
487
|
}
|
|
117
488
|
/**
|
|
118
|
-
* Create a
|
|
489
|
+
* Create a new {@link CronJobs} builder for declaring recurring Syncore jobs.
|
|
490
|
+
*
|
|
491
|
+
* @example
|
|
492
|
+
* ```ts
|
|
493
|
+
* // syncore/crons.ts
|
|
494
|
+
* import { cronJobs } from "syncorejs";
|
|
495
|
+
* import { api } from "./_generated/api";
|
|
496
|
+
*
|
|
497
|
+
* const crons = cronJobs();
|
|
498
|
+
* crons.interval("sync", { minutes: 5 }, api.sync.run);
|
|
499
|
+
* export default crons;
|
|
500
|
+
* ```
|
|
119
501
|
*/
|
|
120
502
|
declare function cronJobs(): CronJobs;
|
|
121
503
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.d.mts","names":[],"sources":["../../src/runtime/functions.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"functions.d.mts","names":[],"sources":["../../src/runtime/functions.ts"],"mappings":";;;;;AAsBA;;;;AAA+B;AAQ/B;;;;AAA8B;AA+B9B;;KAvCY,mBAAA;;;;;;;KAQA,SAAA,GAAY,MAAM;;;;;;;;;;;;;;;;AAuCD;AAe7B;;;;;;;;;;;;;UAvBiB,iBAAA,eACD,mBAAA,GAAsB,mBAAA,UAC5B,SAAA;EAGR,IAAA,EAAM,KAAA;EACN,IAAA;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AA;EAAA,SACF,IAAA,EAAM,sBAAA;EAzLyC;;;;;;;;;;EAqMxD,QAAA,CACE,IAAA,UACA,QAAA,EAAU,IAAA,CAAK,yBAAA,WACf,iBAAA,EAAmB,iBAAA,yBACnB,IAAA,GAAM,MAAA,mBACN,aAAA,GAAe,aAAA;EA7MjB;;;;;;;;;;EAmOA,KAAA,CACE,IAAA,UACA,QAAA,EAAU,IAAA,CAAK,sBAAA,WACf,iBAAA,EAAmB,iBAAA,yBACnB,IAAA,GAAM,MAAA,mBACN,aAAA,GAAe,aAAA;EArOjB;;;;;;;AAOO;AA8BT;;;EAuNE,MAAA,CACE,IAAA,UACA,QAAA,EAAU,IAAA,CAAK,uBAAA,WACf,iBAAA,EAAmB,iBAAA,yBACnB,IAAA,GAAM,MAAA,mBACN,aAAA,GAAe,aAAA;AAAA;;;;;AArNZ;AAUP;;;;;;;;;iBAsOgB,QAAA,CAAA,GAAY,QAAQ"}
|
|
@@ -17,8 +17,47 @@ function mutation(config) {
|
|
|
17
17
|
function action(config) {
|
|
18
18
|
return createFunctionDefinition("action", config);
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Fluent builder for declaring the recurring (cron) jobs of a Syncore app.
|
|
22
|
+
*
|
|
23
|
+
* Instantiate with {@link cronJobs} and chain calls to `.interval()`, `.daily()`,
|
|
24
|
+
* or `.weekly()`. Pass the resulting instance's `.jobs` array to
|
|
25
|
+
* `scheduler.recurringJobs` in your runtime options.
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* // syncore/crons.ts
|
|
29
|
+
* import { cronJobs } from "syncorejs";
|
|
30
|
+
* import { api } from "./_generated/api";
|
|
31
|
+
*
|
|
32
|
+
* const crons = cronJobs();
|
|
33
|
+
*
|
|
34
|
+
* crons.interval("refresh-feed", { minutes: 10 }, api.feed.refresh);
|
|
35
|
+
* crons.daily("send-digest", { hour: 8, minute: 0 }, api.email.digest);
|
|
36
|
+
* crons.weekly("weekly-cleanup", { dayOfWeek: "sunday", hour: 3, minute: 0 }, api.db.vacuum);
|
|
37
|
+
*
|
|
38
|
+
* export default crons;
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* Then in your runtime setup:
|
|
42
|
+
* ```ts
|
|
43
|
+
* createNodeSyncoreRuntime({
|
|
44
|
+
* ...,
|
|
45
|
+
* scheduler: { recurringJobs: crons.jobs },
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
20
49
|
var CronJobs = class {
|
|
21
50
|
jobs = [];
|
|
51
|
+
/**
|
|
52
|
+
* Register a job that fires repeatedly at a fixed time interval.
|
|
53
|
+
*
|
|
54
|
+
* @param name - Unique identifier for this job.
|
|
55
|
+
* @param schedule - Interval fields (`seconds`, `minutes`, `hours`).
|
|
56
|
+
* @param functionReference - Mutation or action to invoke.
|
|
57
|
+
* @param args - Arguments forwarded on every invocation.
|
|
58
|
+
* @param misfirePolicy - How to handle runs missed while the runtime was
|
|
59
|
+
* offline. Defaults to `{ type: "catch_up" }`.
|
|
60
|
+
*/
|
|
22
61
|
interval(name, schedule, functionReference, args = {}, misfirePolicy = { type: "catch_up" }) {
|
|
23
62
|
this.jobs.push({
|
|
24
63
|
name,
|
|
@@ -32,6 +71,16 @@ var CronJobs = class {
|
|
|
32
71
|
});
|
|
33
72
|
return this;
|
|
34
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Register a job that fires once a day at a given wall-clock time.
|
|
76
|
+
*
|
|
77
|
+
* @param name - Unique identifier for this job.
|
|
78
|
+
* @param schedule - `hour` (0–23), `minute` (0–59), optional `timezone`.
|
|
79
|
+
* @param functionReference - Mutation or action to invoke.
|
|
80
|
+
* @param args - Arguments forwarded on every invocation.
|
|
81
|
+
* @param misfirePolicy - How to handle runs missed while the runtime was
|
|
82
|
+
* offline. Defaults to `{ type: "catch_up" }`.
|
|
83
|
+
*/
|
|
35
84
|
daily(name, schedule, functionReference, args = {}, misfirePolicy = { type: "catch_up" }) {
|
|
36
85
|
this.jobs.push({
|
|
37
86
|
name,
|
|
@@ -45,6 +94,17 @@ var CronJobs = class {
|
|
|
45
94
|
});
|
|
46
95
|
return this;
|
|
47
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Register a job that fires once a week on a given day and time.
|
|
99
|
+
*
|
|
100
|
+
* @param name - Unique identifier for this job.
|
|
101
|
+
* @param schedule - `dayOfWeek`, `hour` (0–23), `minute` (0–59),
|
|
102
|
+
* optional `timezone`.
|
|
103
|
+
* @param functionReference - Mutation or action to invoke.
|
|
104
|
+
* @param args - Arguments forwarded on every invocation.
|
|
105
|
+
* @param misfirePolicy - How to handle runs missed while the runtime was
|
|
106
|
+
* offline. Defaults to `{ type: "catch_up" }`.
|
|
107
|
+
*/
|
|
48
108
|
weekly(name, schedule, functionReference, args = {}, misfirePolicy = { type: "catch_up" }) {
|
|
49
109
|
this.jobs.push({
|
|
50
110
|
name,
|
|
@@ -60,7 +120,18 @@ var CronJobs = class {
|
|
|
60
120
|
}
|
|
61
121
|
};
|
|
62
122
|
/**
|
|
63
|
-
* Create a
|
|
123
|
+
* Create a new {@link CronJobs} builder for declaring recurring Syncore jobs.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* // syncore/crons.ts
|
|
128
|
+
* import { cronJobs } from "syncorejs";
|
|
129
|
+
* import { api } from "./_generated/api";
|
|
130
|
+
*
|
|
131
|
+
* const crons = cronJobs();
|
|
132
|
+
* crons.interval("sync", { minutes: 5 }, api.sync.run);
|
|
133
|
+
* export default crons;
|
|
134
|
+
* ```
|
|
64
135
|
*/
|
|
65
136
|
function cronJobs() {
|
|
66
137
|
return new CronJobs();
|