syncorejs 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -0
- package/dist/_vendor/core/_virtual/_rolldown/runtime.mjs +27 -0
- package/dist/_vendor/core/cli.d.mts +5 -0
- package/dist/_vendor/core/cli.d.mts.map +1 -0
- package/dist/_vendor/core/cli.mjs +1196 -0
- package/dist/_vendor/core/cli.mjs.map +1 -0
- package/dist/_vendor/core/index.d.mts +7 -0
- package/dist/_vendor/core/index.mjs +25 -0
- package/dist/_vendor/core/index.mjs.map +1 -0
- package/dist/_vendor/core/runtime/devtools.d.mts +15 -0
- package/dist/_vendor/core/runtime/devtools.d.mts.map +1 -0
- package/dist/_vendor/core/runtime/devtools.mjs +300 -0
- package/dist/_vendor/core/runtime/devtools.mjs.map +1 -0
- package/dist/_vendor/core/runtime/functions.d.mts +123 -0
- package/dist/_vendor/core/runtime/functions.d.mts.map +1 -0
- package/dist/_vendor/core/runtime/functions.mjs +71 -0
- package/dist/_vendor/core/runtime/functions.mjs.map +1 -0
- package/dist/_vendor/core/runtime/id.d.mts +13 -0
- package/dist/_vendor/core/runtime/id.d.mts.map +1 -0
- package/dist/_vendor/core/runtime/id.mjs +28 -0
- package/dist/_vendor/core/runtime/id.mjs.map +1 -0
- package/dist/_vendor/core/runtime/runtime.d.mts +370 -0
- package/dist/_vendor/core/runtime/runtime.d.mts.map +1 -0
- package/dist/_vendor/core/runtime/runtime.mjs +1143 -0
- package/dist/_vendor/core/runtime/runtime.mjs.map +1 -0
- package/dist/_vendor/devtools-protocol/index.d.ts +230 -0
- package/dist/_vendor/devtools-protocol/index.d.ts.map +1 -0
- package/dist/_vendor/devtools-protocol/index.js +0 -0
- package/dist/_vendor/next/config.d.ts +17 -0
- package/dist/_vendor/next/config.d.ts.map +1 -0
- package/dist/_vendor/next/config.js +73 -0
- package/dist/_vendor/next/config.js.map +1 -0
- package/dist/_vendor/next/index.d.ts +80 -0
- package/dist/_vendor/next/index.d.ts.map +1 -0
- package/dist/_vendor/next/index.js +81 -0
- package/dist/_vendor/next/index.js.map +1 -0
- package/dist/_vendor/platform-expo/index.d.ts +97 -0
- package/dist/_vendor/platform-expo/index.d.ts.map +1 -0
- package/dist/_vendor/platform-expo/index.js +197 -0
- package/dist/_vendor/platform-expo/index.js.map +1 -0
- package/dist/_vendor/platform-expo/react.d.ts +26 -0
- package/dist/_vendor/platform-expo/react.d.ts.map +1 -0
- package/dist/_vendor/platform-expo/react.js +30 -0
- package/dist/_vendor/platform-expo/react.js.map +1 -0
- package/dist/_vendor/platform-node/index.d.mts +145 -0
- package/dist/_vendor/platform-node/index.d.mts.map +1 -0
- package/dist/_vendor/platform-node/index.mjs +405 -0
- package/dist/_vendor/platform-node/index.mjs.map +1 -0
- package/dist/_vendor/platform-node/ipc-react.d.mts +25 -0
- package/dist/_vendor/platform-node/ipc-react.d.mts.map +1 -0
- package/dist/_vendor/platform-node/ipc-react.mjs +21 -0
- package/dist/_vendor/platform-node/ipc-react.mjs.map +1 -0
- package/dist/_vendor/platform-node/ipc.d.mts +75 -0
- package/dist/_vendor/platform-node/ipc.d.mts.map +1 -0
- package/dist/_vendor/platform-node/ipc.mjs +343 -0
- package/dist/_vendor/platform-node/ipc.mjs.map +1 -0
- package/dist/_vendor/platform-web/index.d.ts +123 -0
- package/dist/_vendor/platform-web/index.d.ts.map +1 -0
- package/dist/_vendor/platform-web/index.js +309 -0
- package/dist/_vendor/platform-web/index.js.map +1 -0
- package/dist/_vendor/platform-web/indexeddb.d.ts +25 -0
- package/dist/_vendor/platform-web/indexeddb.d.ts.map +1 -0
- package/dist/_vendor/platform-web/indexeddb.js +125 -0
- package/dist/_vendor/platform-web/indexeddb.js.map +1 -0
- package/dist/_vendor/platform-web/opfs.d.ts +27 -0
- package/dist/_vendor/platform-web/opfs.d.ts.map +1 -0
- package/dist/_vendor/platform-web/opfs.js +146 -0
- package/dist/_vendor/platform-web/opfs.js.map +1 -0
- package/dist/_vendor/platform-web/persistence.d.ts +27 -0
- package/dist/_vendor/platform-web/persistence.d.ts.map +1 -0
- package/dist/_vendor/platform-web/persistence.js +23 -0
- package/dist/_vendor/platform-web/persistence.js.map +1 -0
- package/dist/_vendor/platform-web/react.d.ts +35 -0
- package/dist/_vendor/platform-web/react.d.ts.map +1 -0
- package/dist/_vendor/platform-web/react.js +42 -0
- package/dist/_vendor/platform-web/react.js.map +1 -0
- package/dist/_vendor/platform-web/sqljs.js +133 -0
- package/dist/_vendor/platform-web/sqljs.js.map +1 -0
- package/dist/_vendor/platform-web/worker.d.ts +78 -0
- package/dist/_vendor/platform-web/worker.d.ts.map +1 -0
- package/dist/_vendor/platform-web/worker.js +307 -0
- package/dist/_vendor/platform-web/worker.js.map +1 -0
- package/dist/_vendor/react/index.d.ts +58 -0
- package/dist/_vendor/react/index.d.ts.map +1 -0
- package/dist/_vendor/react/index.js +151 -0
- package/dist/_vendor/react/index.js.map +1 -0
- package/dist/_vendor/schema/definition.d.ts +98 -0
- package/dist/_vendor/schema/definition.d.ts.map +1 -0
- package/dist/_vendor/schema/definition.js +84 -0
- package/dist/_vendor/schema/definition.js.map +1 -0
- package/dist/_vendor/schema/index.d.ts +4 -0
- package/dist/_vendor/schema/index.js +4 -0
- package/dist/_vendor/schema/planner.d.ts +42 -0
- package/dist/_vendor/schema/planner.d.ts.map +1 -0
- package/dist/_vendor/schema/planner.js +131 -0
- package/dist/_vendor/schema/planner.js.map +1 -0
- package/dist/_vendor/schema/validators.d.ts +194 -0
- package/dist/_vendor/schema/validators.d.ts.map +1 -0
- package/dist/_vendor/schema/validators.js +158 -0
- package/dist/_vendor/schema/validators.js.map +1 -0
- package/dist/_vendor/svelte/index.d.ts +43 -0
- package/dist/_vendor/svelte/index.d.ts.map +1 -0
- package/dist/_vendor/svelte/index.js +75 -0
- package/dist/_vendor/svelte/index.js.map +1 -0
- package/dist/browser-react.d.ts +2 -0
- package/dist/browser-react.js +2 -0
- package/dist/browser.d.ts +12 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +10 -0
- package/dist/browser.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +11 -0
- package/dist/cli.js.map +1 -0
- package/dist/core/src/cli.d.ts +5 -0
- package/dist/core/src/cli.d.ts.map +1 -0
- package/dist/core/src/cli.js +1196 -0
- package/dist/core/src/cli.js.map +1 -0
- package/dist/core/src/index.js +7 -0
- package/dist/core/src/runtime/devtools.d.ts +7 -0
- package/dist/core/src/runtime/devtools.d.ts.map +1 -0
- package/dist/core/src/runtime/devtools.js +300 -0
- package/dist/core/src/runtime/devtools.js.map +1 -0
- package/dist/core/src/runtime/functions.d.ts +123 -0
- package/dist/core/src/runtime/functions.d.ts.map +1 -0
- package/dist/core/src/runtime/functions.js +71 -0
- package/dist/core/src/runtime/functions.js.map +1 -0
- package/dist/core/src/runtime/id.d.ts +13 -0
- package/dist/core/src/runtime/id.d.ts.map +1 -0
- package/dist/core/src/runtime/id.js +28 -0
- package/dist/core/src/runtime/id.js.map +1 -0
- package/dist/core/src/runtime/runtime.d.ts +371 -0
- package/dist/core/src/runtime/runtime.d.ts.map +1 -0
- package/dist/core/src/runtime/runtime.js +1143 -0
- package/dist/core/src/runtime/runtime.js.map +1 -0
- package/dist/devtools-protocol/src/index.d.ts +201 -0
- package/dist/devtools-protocol/src/index.d.ts.map +1 -0
- package/dist/expo-react.d.ts +2 -0
- package/dist/expo-react.js +2 -0
- package/dist/expo.d.ts +2 -0
- package/dist/expo.js +2 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/next/src/config.d.ts +17 -0
- package/dist/next/src/config.d.ts.map +1 -0
- package/dist/next/src/config.js +73 -0
- package/dist/next/src/config.js.map +1 -0
- package/dist/next/src/index.d.ts +80 -0
- package/dist/next/src/index.d.ts.map +1 -0
- package/dist/next/src/index.js +82 -0
- package/dist/next/src/index.js.map +1 -0
- package/dist/next-config.d.ts +2 -0
- package/dist/next-config.js +2 -0
- package/dist/next.d.ts +3 -0
- package/dist/next.js +3 -0
- package/dist/node-ipc-react.d.ts +2 -0
- package/dist/node-ipc-react.js +2 -0
- package/dist/node-ipc.d.ts +2 -0
- package/dist/node-ipc.js +2 -0
- package/dist/node.d.ts +4 -0
- package/dist/node.js +3 -0
- package/dist/platform-expo/src/index.d.ts +96 -0
- package/dist/platform-expo/src/index.d.ts.map +1 -0
- package/dist/platform-expo/src/index.js +198 -0
- package/dist/platform-expo/src/index.js.map +1 -0
- package/dist/platform-expo/src/react.d.ts +26 -0
- package/dist/platform-expo/src/react.d.ts.map +1 -0
- package/dist/platform-expo/src/react.js +30 -0
- package/dist/platform-expo/src/react.js.map +1 -0
- package/dist/platform-node/src/index.d.ts +145 -0
- package/dist/platform-node/src/index.d.ts.map +1 -0
- package/dist/platform-node/src/index.js +407 -0
- package/dist/platform-node/src/index.js.map +1 -0
- package/dist/platform-node/src/ipc-react.d.ts +25 -0
- package/dist/platform-node/src/ipc-react.d.ts.map +1 -0
- package/dist/platform-node/src/ipc-react.js +21 -0
- package/dist/platform-node/src/ipc-react.js.map +1 -0
- package/dist/platform-node/src/ipc.d.ts +76 -0
- package/dist/platform-node/src/ipc.d.ts.map +1 -0
- package/dist/platform-node/src/ipc.js +344 -0
- package/dist/platform-node/src/ipc.js.map +1 -0
- package/dist/platform-web/src/index.d.ts +106 -0
- package/dist/platform-web/src/index.d.ts.map +1 -0
- package/dist/platform-web/src/index.js +311 -0
- package/dist/platform-web/src/index.js.map +1 -0
- package/dist/platform-web/src/indexeddb.js +125 -0
- package/dist/platform-web/src/indexeddb.js.map +1 -0
- package/dist/platform-web/src/opfs.js +146 -0
- package/dist/platform-web/src/opfs.js.map +1 -0
- package/dist/platform-web/src/persistence.d.ts +20 -0
- package/dist/platform-web/src/persistence.d.ts.map +1 -0
- package/dist/platform-web/src/persistence.js +23 -0
- package/dist/platform-web/src/persistence.js.map +1 -0
- package/dist/platform-web/src/react.d.ts +35 -0
- package/dist/platform-web/src/react.d.ts.map +1 -0
- package/dist/platform-web/src/react.js +42 -0
- package/dist/platform-web/src/react.js.map +1 -0
- package/dist/platform-web/src/sqljs.js +133 -0
- package/dist/platform-web/src/sqljs.js.map +1 -0
- package/dist/platform-web/src/worker.d.ts +79 -0
- package/dist/platform-web/src/worker.d.ts.map +1 -0
- package/dist/platform-web/src/worker.js +308 -0
- package/dist/platform-web/src/worker.js.map +1 -0
- package/dist/react/src/index.d.ts +59 -0
- package/dist/react/src/index.d.ts.map +1 -0
- package/dist/react/src/index.js +151 -0
- package/dist/react/src/index.js.map +1 -0
- package/dist/react.d.ts +2 -0
- package/dist/react.js +2 -0
- package/dist/schema/src/definition.d.ts +98 -0
- package/dist/schema/src/definition.d.ts.map +1 -0
- package/dist/schema/src/definition.js +84 -0
- package/dist/schema/src/definition.js.map +1 -0
- package/dist/schema/src/planner.d.ts +42 -0
- package/dist/schema/src/planner.d.ts.map +1 -0
- package/dist/schema/src/planner.js +131 -0
- package/dist/schema/src/planner.js.map +1 -0
- package/dist/schema/src/validators.d.ts +194 -0
- package/dist/schema/src/validators.d.ts.map +1 -0
- package/dist/schema/src/validators.js +158 -0
- package/dist/schema/src/validators.js.map +1 -0
- package/dist/svelte/src/index.d.ts +44 -0
- package/dist/svelte/src/index.d.ts.map +1 -0
- package/dist/svelte/src/index.js +75 -0
- package/dist/svelte/src/index.js.map +1 -0
- package/dist/svelte.d.ts +2 -0
- package/dist/svelte.js +2 -0
- package/package.json +152 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { Infer, Validator, ValidatorMap } from "../../schema/index.d.ts";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/functions.d.ts
|
|
4
|
+
type SyncoreFunctionKind = "query" | "mutation" | "action";
|
|
5
|
+
type EmptyArgs = Record<never, never>;
|
|
6
|
+
/**
|
|
7
|
+
* A typed reference to a Syncore function.
|
|
8
|
+
*
|
|
9
|
+
* Most app code gets these references from the generated `api` object.
|
|
10
|
+
*/
|
|
11
|
+
interface FunctionReference<TKind extends SyncoreFunctionKind = SyncoreFunctionKind, TArgs = EmptyArgs, TResult = unknown> {
|
|
12
|
+
kind: TKind;
|
|
13
|
+
name: string;
|
|
14
|
+
readonly __args?: TArgs;
|
|
15
|
+
readonly __result?: TResult;
|
|
16
|
+
}
|
|
17
|
+
interface SyncoreFunctionDefinition<TKind extends SyncoreFunctionKind, TContext, TArgs, TResult> {
|
|
18
|
+
kind: TKind;
|
|
19
|
+
argsValidator: Validator<TArgs>;
|
|
20
|
+
returnsValidator?: Validator<TResult>;
|
|
21
|
+
handler: (ctx: TContext, args: TArgs) => Promise<TResult> | TResult;
|
|
22
|
+
}
|
|
23
|
+
type FunctionArgs<TReference> = TReference extends FunctionReference<SyncoreFunctionKind, infer TArgs, unknown> ? TArgs : never;
|
|
24
|
+
type FunctionResult<TReference> = TReference extends FunctionReference<SyncoreFunctionKind, unknown, infer TResult> ? TResult : never;
|
|
25
|
+
type FunctionKindFromDefinition<TDefinition> = TDefinition extends {
|
|
26
|
+
kind: infer TKind;
|
|
27
|
+
} ? Extract<TKind, SyncoreFunctionKind> : never;
|
|
28
|
+
type FunctionArgsFromDefinition<TDefinition> = TDefinition extends {
|
|
29
|
+
argsValidator: Validator<infer TArgs>;
|
|
30
|
+
} ? TArgs : never;
|
|
31
|
+
type FunctionResultFromDefinition<TDefinition> = TDefinition extends {
|
|
32
|
+
returnsValidator?: Validator<infer TResult>;
|
|
33
|
+
} ? TResult : never;
|
|
34
|
+
type FunctionReferenceFor<TDefinition> = FunctionKindFromDefinition<TDefinition> extends never ? never : FunctionReference<FunctionKindFromDefinition<TDefinition>, FunctionArgsFromDefinition<TDefinition>, FunctionResultFromDefinition<TDefinition>>;
|
|
35
|
+
interface FunctionConfig<TContext, TArgs, TResult> {
|
|
36
|
+
args: Validator<TArgs> | ValidatorMap;
|
|
37
|
+
returns?: Validator<TResult>;
|
|
38
|
+
handler: (ctx: TContext, args: TArgs) => Promise<TResult> | TResult;
|
|
39
|
+
}
|
|
40
|
+
type InferArgs<TArgs extends Validator<unknown> | ValidatorMap> = TArgs extends Validator<unknown> ? Infer<TArgs> : TArgs extends ValidatorMap ? { [TKey in keyof TArgs]: Infer<TArgs[TKey]> } : never;
|
|
41
|
+
/**
|
|
42
|
+
* Define a Syncore query.
|
|
43
|
+
*
|
|
44
|
+
* Queries can read local Syncore state and are available to clients.
|
|
45
|
+
*/
|
|
46
|
+
declare function query<TContext = unknown, TValidator extends Validator<unknown> = Validator<unknown>, TResult = unknown>(config: FunctionConfig<TContext, Infer<TValidator>, TResult> & {
|
|
47
|
+
args: TValidator;
|
|
48
|
+
}): SyncoreFunctionDefinition<"query", TContext, Infer<TValidator>, TResult>;
|
|
49
|
+
declare function query<TContext = unknown, TArgsShape extends ValidatorMap = ValidatorMap, TResult = unknown>(config: FunctionConfig<TContext, InferArgs<TArgsShape>, TResult> & {
|
|
50
|
+
args: TArgsShape;
|
|
51
|
+
}): SyncoreFunctionDefinition<"query", TContext, InferArgs<TArgsShape>, TResult>;
|
|
52
|
+
/**
|
|
53
|
+
* Define a Syncore mutation.
|
|
54
|
+
*
|
|
55
|
+
* Mutations can modify local Syncore state and are available to clients.
|
|
56
|
+
*/
|
|
57
|
+
declare function mutation<TContext = unknown, TValidator extends Validator<unknown> = Validator<unknown>, TResult = unknown>(config: FunctionConfig<TContext, Infer<TValidator>, TResult> & {
|
|
58
|
+
args: TValidator;
|
|
59
|
+
}): SyncoreFunctionDefinition<"mutation", TContext, Infer<TValidator>, TResult>;
|
|
60
|
+
declare function mutation<TContext = unknown, TArgsShape extends ValidatorMap = ValidatorMap, TResult = unknown>(config: FunctionConfig<TContext, InferArgs<TArgsShape>, TResult> & {
|
|
61
|
+
args: TArgsShape;
|
|
62
|
+
}): SyncoreFunctionDefinition<"mutation", TContext, InferArgs<TArgsShape>, TResult>;
|
|
63
|
+
/**
|
|
64
|
+
* Define a Syncore action.
|
|
65
|
+
*
|
|
66
|
+
* Actions can run arbitrary JavaScript and may call other Syncore functions.
|
|
67
|
+
*/
|
|
68
|
+
declare function action<TContext = unknown, TValidator extends Validator<unknown> = Validator<unknown>, TResult = unknown>(config: FunctionConfig<TContext, Infer<TValidator>, TResult> & {
|
|
69
|
+
args: TValidator;
|
|
70
|
+
}): SyncoreFunctionDefinition<"action", TContext, Infer<TValidator>, TResult>;
|
|
71
|
+
declare function action<TContext = unknown, TArgsShape extends ValidatorMap = ValidatorMap, TResult = unknown>(config: FunctionConfig<TContext, InferArgs<TArgsShape>, TResult> & {
|
|
72
|
+
args: TArgsShape;
|
|
73
|
+
}): SyncoreFunctionDefinition<"action", TContext, InferArgs<TArgsShape>, TResult>;
|
|
74
|
+
interface RecurringIntervalSchedule {
|
|
75
|
+
type: "interval";
|
|
76
|
+
seconds?: number;
|
|
77
|
+
minutes?: number;
|
|
78
|
+
hours?: number;
|
|
79
|
+
}
|
|
80
|
+
interface RecurringDailySchedule {
|
|
81
|
+
type: "daily";
|
|
82
|
+
hour: number;
|
|
83
|
+
minute: number;
|
|
84
|
+
timezone?: string;
|
|
85
|
+
}
|
|
86
|
+
interface RecurringWeeklySchedule {
|
|
87
|
+
type: "weekly";
|
|
88
|
+
dayOfWeek: "sunday" | "monday" | "tuesday" | "wednesday" | "thursday" | "friday" | "saturday";
|
|
89
|
+
hour: number;
|
|
90
|
+
minute: number;
|
|
91
|
+
timezone?: string;
|
|
92
|
+
}
|
|
93
|
+
type RecurringSchedule = RecurringIntervalSchedule | RecurringDailySchedule | RecurringWeeklySchedule;
|
|
94
|
+
type MisfirePolicy = {
|
|
95
|
+
type: "catch_up";
|
|
96
|
+
} | {
|
|
97
|
+
type: "skip";
|
|
98
|
+
} | {
|
|
99
|
+
type: "run_once_if_missed";
|
|
100
|
+
} | {
|
|
101
|
+
type: "windowed";
|
|
102
|
+
windowMs: number;
|
|
103
|
+
};
|
|
104
|
+
interface RecurringJobDefinition {
|
|
105
|
+
name: string;
|
|
106
|
+
schedule: RecurringSchedule;
|
|
107
|
+
function: FunctionReference<"mutation" | "action">;
|
|
108
|
+
args: Record<string, unknown>;
|
|
109
|
+
misfirePolicy: MisfirePolicy;
|
|
110
|
+
}
|
|
111
|
+
declare class CronJobs {
|
|
112
|
+
readonly jobs: RecurringJobDefinition[];
|
|
113
|
+
interval(name: string, schedule: Omit<RecurringIntervalSchedule, "type">, functionReference: FunctionReference<"mutation" | "action">, args?: Record<string, unknown>, misfirePolicy?: MisfirePolicy): this;
|
|
114
|
+
daily(name: string, schedule: Omit<RecurringDailySchedule, "type">, functionReference: FunctionReference<"mutation" | "action">, args?: Record<string, unknown>, misfirePolicy?: MisfirePolicy): this;
|
|
115
|
+
weekly(name: string, schedule: Omit<RecurringWeeklySchedule, "type">, functionReference: FunctionReference<"mutation" | "action">, args?: Record<string, unknown>, misfirePolicy?: MisfirePolicy): this;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Create a recurring job registry for Syncore scheduler definitions.
|
|
119
|
+
*/
|
|
120
|
+
declare function cronJobs(): CronJobs;
|
|
121
|
+
//#endregion
|
|
122
|
+
export { CronJobs, EmptyArgs, FunctionArgs, FunctionArgsFromDefinition, FunctionConfig, FunctionKindFromDefinition, FunctionReference, FunctionReferenceFor, FunctionResult, FunctionResultFromDefinition, InferArgs, MisfirePolicy, RecurringDailySchedule, RecurringIntervalSchedule, RecurringJobDefinition, RecurringSchedule, RecurringWeeklySchedule, SyncoreFunctionDefinition, SyncoreFunctionKind, action, cronJobs, mutation, query };
|
|
123
|
+
//# sourceMappingURL=functions.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functions.d.mts","names":[],"sources":["../../src/runtime/functions.ts"],"mappings":"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"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ensureObjectValidator } from "../../schema/index.js";
|
|
2
|
+
//#region src/runtime/functions.ts
|
|
3
|
+
function createFunctionDefinition(kind, config) {
|
|
4
|
+
return {
|
|
5
|
+
kind,
|
|
6
|
+
argsValidator: ensureObjectValidator(config.args),
|
|
7
|
+
...config.returns ? { returnsValidator: config.returns } : {},
|
|
8
|
+
handler: config.handler
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
function query(config) {
|
|
12
|
+
return createFunctionDefinition("query", config);
|
|
13
|
+
}
|
|
14
|
+
function mutation(config) {
|
|
15
|
+
return createFunctionDefinition("mutation", config);
|
|
16
|
+
}
|
|
17
|
+
function action(config) {
|
|
18
|
+
return createFunctionDefinition("action", config);
|
|
19
|
+
}
|
|
20
|
+
var CronJobs = class {
|
|
21
|
+
jobs = [];
|
|
22
|
+
interval(name, schedule, functionReference, args = {}, misfirePolicy = { type: "catch_up" }) {
|
|
23
|
+
this.jobs.push({
|
|
24
|
+
name,
|
|
25
|
+
schedule: {
|
|
26
|
+
type: "interval",
|
|
27
|
+
...schedule
|
|
28
|
+
},
|
|
29
|
+
function: functionReference,
|
|
30
|
+
args,
|
|
31
|
+
misfirePolicy
|
|
32
|
+
});
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
daily(name, schedule, functionReference, args = {}, misfirePolicy = { type: "catch_up" }) {
|
|
36
|
+
this.jobs.push({
|
|
37
|
+
name,
|
|
38
|
+
schedule: {
|
|
39
|
+
type: "daily",
|
|
40
|
+
...schedule
|
|
41
|
+
},
|
|
42
|
+
function: functionReference,
|
|
43
|
+
args,
|
|
44
|
+
misfirePolicy
|
|
45
|
+
});
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
weekly(name, schedule, functionReference, args = {}, misfirePolicy = { type: "catch_up" }) {
|
|
49
|
+
this.jobs.push({
|
|
50
|
+
name,
|
|
51
|
+
schedule: {
|
|
52
|
+
type: "weekly",
|
|
53
|
+
...schedule
|
|
54
|
+
},
|
|
55
|
+
function: functionReference,
|
|
56
|
+
args,
|
|
57
|
+
misfirePolicy
|
|
58
|
+
});
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Create a recurring job registry for Syncore scheduler definitions.
|
|
64
|
+
*/
|
|
65
|
+
function cronJobs() {
|
|
66
|
+
return new CronJobs();
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { CronJobs, action, cronJobs, mutation, query };
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=functions.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functions.mjs","names":[],"sources":["../../src/runtime/functions.ts"],"sourcesContent":["import {\r\n ensureObjectValidator,\r\n type Infer,\r\n type Validator,\r\n type ValidatorMap\r\n} from \"@syncore/schema\";\r\n\r\nexport type SyncoreFunctionKind = \"query\" | \"mutation\" | \"action\";\r\nexport type EmptyArgs = Record<never, never>;\r\n\r\n/**\r\n * A typed reference to a Syncore function.\r\n *\r\n * Most app code gets these references from the generated `api` object.\r\n */\r\nexport interface FunctionReference<\r\n TKind extends SyncoreFunctionKind = SyncoreFunctionKind,\r\n TArgs = EmptyArgs,\r\n TResult = unknown\r\n> {\r\n kind: TKind;\r\n name: string;\r\n readonly __args?: TArgs;\r\n readonly __result?: TResult;\r\n}\r\n\r\nexport interface SyncoreFunctionDefinition<\r\n TKind extends SyncoreFunctionKind,\r\n TContext,\r\n TArgs,\r\n TResult\r\n> {\r\n kind: TKind;\r\n argsValidator: Validator<TArgs>;\r\n returnsValidator?: Validator<TResult>;\r\n handler: (ctx: TContext, args: TArgs) => Promise<TResult> | TResult;\r\n}\r\n\r\nexport type FunctionArgs<TReference> =\r\n TReference extends FunctionReference<\r\n SyncoreFunctionKind,\r\n infer TArgs,\r\n unknown\r\n >\r\n ? TArgs\r\n : never;\r\n\r\nexport type FunctionResult<TReference> =\r\n TReference extends FunctionReference<\r\n SyncoreFunctionKind,\r\n unknown,\r\n infer TResult\r\n >\r\n ? TResult\r\n : never;\r\n\r\nexport type FunctionKindFromDefinition<TDefinition> = TDefinition extends {\r\n kind: infer TKind;\r\n}\r\n ? Extract<TKind, SyncoreFunctionKind>\r\n : never;\r\n\r\nexport type FunctionArgsFromDefinition<TDefinition> = TDefinition extends {\r\n argsValidator: Validator<infer TArgs>;\r\n}\r\n ? TArgs\r\n : never;\r\n\r\nexport type FunctionResultFromDefinition<TDefinition> = TDefinition extends {\r\n returnsValidator?: Validator<infer TResult>;\r\n}\r\n ? TResult\r\n : never;\r\n\r\nexport type FunctionReferenceFor<TDefinition> =\r\n FunctionKindFromDefinition<TDefinition> extends never\r\n ? never\r\n : FunctionReference<\r\n FunctionKindFromDefinition<TDefinition>,\r\n FunctionArgsFromDefinition<TDefinition>,\r\n FunctionResultFromDefinition<TDefinition>\r\n >;\r\n\r\nexport interface FunctionConfig<TContext, TArgs, TResult> {\r\n args: Validator<TArgs> | ValidatorMap;\r\n returns?: Validator<TResult>;\r\n handler: (ctx: TContext, args: TArgs) => Promise<TResult> | TResult;\r\n}\r\n\r\nexport type InferArgs<TArgs extends Validator<unknown> | ValidatorMap> =\r\n TArgs extends Validator<unknown>\r\n ? Infer<TArgs>\r\n : TArgs extends ValidatorMap\r\n ? {\r\n [TKey in keyof TArgs]: Infer<TArgs[TKey]>;\r\n }\r\n : never;\r\n\r\nfunction createFunctionDefinition<\r\n TKind extends SyncoreFunctionKind,\r\n TContext,\r\n TArgsShape extends Validator<unknown> | ValidatorMap,\r\n TResult\r\n>(\r\n kind: TKind,\r\n config: FunctionConfig<TContext, InferArgs<TArgsShape>, TResult> & {\r\n args: TArgsShape;\r\n }\r\n): SyncoreFunctionDefinition<TKind, TContext, InferArgs<TArgsShape>, TResult> {\r\n return {\r\n kind,\r\n argsValidator: ensureObjectValidator(config.args) as Validator<\r\n InferArgs<TArgsShape>\r\n >,\r\n ...(config.returns ? { returnsValidator: config.returns } : {}),\r\n handler: config.handler\r\n };\r\n}\r\n\r\n/**\r\n * Define a Syncore query.\r\n *\r\n * Queries can read local Syncore state and are available to clients.\r\n */\r\nexport function query<\r\n TContext = unknown,\r\n TValidator extends Validator<unknown> = Validator<unknown>,\r\n TResult = unknown\r\n>(\r\n config: FunctionConfig<TContext, Infer<TValidator>, TResult> & {\r\n args: TValidator;\r\n }\r\n): SyncoreFunctionDefinition<\"query\", TContext, Infer<TValidator>, TResult>;\r\nexport function query<\r\n TContext = unknown,\r\n TArgsShape extends ValidatorMap = ValidatorMap,\r\n TResult = unknown\r\n>(\r\n config: FunctionConfig<TContext, InferArgs<TArgsShape>, TResult> & {\r\n args: TArgsShape;\r\n }\r\n): SyncoreFunctionDefinition<\"query\", TContext, InferArgs<TArgsShape>, TResult>;\r\nexport function query<\r\n TContext = unknown,\r\n TArgsShape extends Validator<unknown> | ValidatorMap = ValidatorMap,\r\n TResult = unknown\r\n>(\r\n config: FunctionConfig<TContext, InferArgs<TArgsShape>, TResult> & {\r\n args: TArgsShape;\r\n }\r\n): SyncoreFunctionDefinition<\r\n \"query\",\r\n TContext,\r\n InferArgs<TArgsShape>,\r\n TResult\r\n> {\r\n return createFunctionDefinition(\"query\", config);\r\n}\r\n\r\n/**\r\n * Define a Syncore mutation.\r\n *\r\n * Mutations can modify local Syncore state and are available to clients.\r\n */\r\nexport function mutation<\r\n TContext = unknown,\r\n TValidator extends Validator<unknown> = Validator<unknown>,\r\n TResult = unknown\r\n>(\r\n config: FunctionConfig<TContext, Infer<TValidator>, TResult> & {\r\n args: TValidator;\r\n }\r\n): SyncoreFunctionDefinition<\"mutation\", TContext, Infer<TValidator>, TResult>;\r\nexport function mutation<\r\n TContext = unknown,\r\n TArgsShape extends ValidatorMap = ValidatorMap,\r\n TResult = unknown\r\n>(\r\n config: FunctionConfig<TContext, InferArgs<TArgsShape>, TResult> & {\r\n args: TArgsShape;\r\n }\r\n): SyncoreFunctionDefinition<\r\n \"mutation\",\r\n TContext,\r\n InferArgs<TArgsShape>,\r\n TResult\r\n>;\r\nexport function mutation<\r\n TContext = unknown,\r\n TArgsShape extends Validator<unknown> | ValidatorMap = ValidatorMap,\r\n TResult = unknown\r\n>(\r\n config: FunctionConfig<TContext, InferArgs<TArgsShape>, TResult> & {\r\n args: TArgsShape;\r\n }\r\n): SyncoreFunctionDefinition<\r\n \"mutation\",\r\n TContext,\r\n InferArgs<TArgsShape>,\r\n TResult\r\n> {\r\n return createFunctionDefinition(\"mutation\", config);\r\n}\r\n\r\n/**\r\n * Define a Syncore action.\r\n *\r\n * Actions can run arbitrary JavaScript and may call other Syncore functions.\r\n */\r\nexport function action<\r\n TContext = unknown,\r\n TValidator extends Validator<unknown> = Validator<unknown>,\r\n TResult = unknown\r\n>(\r\n config: FunctionConfig<TContext, Infer<TValidator>, TResult> & {\r\n args: TValidator;\r\n }\r\n): SyncoreFunctionDefinition<\"action\", TContext, Infer<TValidator>, TResult>;\r\nexport function action<\r\n TContext = unknown,\r\n TArgsShape extends ValidatorMap = ValidatorMap,\r\n TResult = unknown\r\n>(\r\n config: FunctionConfig<TContext, InferArgs<TArgsShape>, TResult> & {\r\n args: TArgsShape;\r\n }\r\n): SyncoreFunctionDefinition<\r\n \"action\",\r\n TContext,\r\n InferArgs<TArgsShape>,\r\n TResult\r\n>;\r\nexport function action<\r\n TContext = unknown,\r\n TArgsShape extends Validator<unknown> | ValidatorMap = ValidatorMap,\r\n TResult = unknown\r\n>(\r\n config: FunctionConfig<TContext, InferArgs<TArgsShape>, TResult> & {\r\n args: TArgsShape;\r\n }\r\n): SyncoreFunctionDefinition<\r\n \"action\",\r\n TContext,\r\n InferArgs<TArgsShape>,\r\n TResult\r\n> {\r\n return createFunctionDefinition(\"action\", config);\r\n}\r\n\r\nexport interface RecurringIntervalSchedule {\r\n type: \"interval\";\r\n seconds?: number;\r\n minutes?: number;\r\n hours?: number;\r\n}\r\n\r\nexport interface RecurringDailySchedule {\r\n type: \"daily\";\r\n hour: number;\r\n minute: number;\r\n timezone?: string;\r\n}\r\n\r\nexport interface RecurringWeeklySchedule {\r\n type: \"weekly\";\r\n dayOfWeek:\r\n | \"sunday\"\r\n | \"monday\"\r\n | \"tuesday\"\r\n | \"wednesday\"\r\n | \"thursday\"\r\n | \"friday\"\r\n | \"saturday\";\r\n hour: number;\r\n minute: number;\r\n timezone?: string;\r\n}\r\n\r\nexport type RecurringSchedule =\r\n | RecurringIntervalSchedule\r\n | RecurringDailySchedule\r\n | RecurringWeeklySchedule;\r\n\r\nexport type MisfirePolicy =\r\n | { type: \"catch_up\" }\r\n | { type: \"skip\" }\r\n | { type: \"run_once_if_missed\" }\r\n | { type: \"windowed\"; windowMs: number };\r\n\r\nexport interface RecurringJobDefinition {\r\n name: string;\r\n schedule: RecurringSchedule;\r\n function: FunctionReference<\"mutation\" | \"action\">;\r\n args: Record<string, unknown>;\r\n misfirePolicy: MisfirePolicy;\r\n}\r\n\r\nexport class CronJobs {\r\n readonly jobs: RecurringJobDefinition[] = [];\r\n\r\n interval(\r\n name: string,\r\n schedule: Omit<RecurringIntervalSchedule, \"type\">,\r\n functionReference: FunctionReference<\"mutation\" | \"action\">,\r\n args: Record<string, unknown> = {},\r\n misfirePolicy: MisfirePolicy = { type: \"catch_up\" }\r\n ): this {\r\n this.jobs.push({\r\n name,\r\n schedule: { type: \"interval\", ...schedule },\r\n function: functionReference,\r\n args,\r\n misfirePolicy\r\n });\r\n return this;\r\n }\r\n\r\n daily(\r\n name: string,\r\n schedule: Omit<RecurringDailySchedule, \"type\">,\r\n functionReference: FunctionReference<\"mutation\" | \"action\">,\r\n args: Record<string, unknown> = {},\r\n misfirePolicy: MisfirePolicy = { type: \"catch_up\" }\r\n ): this {\r\n this.jobs.push({\r\n name,\r\n schedule: { type: \"daily\", ...schedule },\r\n function: functionReference,\r\n args,\r\n misfirePolicy\r\n });\r\n return this;\r\n }\r\n\r\n weekly(\r\n name: string,\r\n schedule: Omit<RecurringWeeklySchedule, \"type\">,\r\n functionReference: FunctionReference<\"mutation\" | \"action\">,\r\n args: Record<string, unknown> = {},\r\n misfirePolicy: MisfirePolicy = { type: \"catch_up\" }\r\n ): this {\r\n this.jobs.push({\r\n name,\r\n schedule: { type: \"weekly\", ...schedule },\r\n function: functionReference,\r\n args,\r\n misfirePolicy\r\n });\r\n return this;\r\n }\r\n}\r\n\r\n/**\r\n * Create a recurring job registry for Syncore scheduler definitions.\r\n */\r\nexport function cronJobs(): CronJobs {\r\n return new CronJobs();\r\n}\r\n"],"mappings":";;AAkGA,SAAS,yBAMP,MACA,QAG4E;AAC5E,QAAO;EACL;EACA,eAAe,sBAAsB,OAAO,KAAK;EAGjD,GAAI,OAAO,UAAU,EAAE,kBAAkB,OAAO,SAAS,GAAG,EAAE;EAC9D,SAAS,OAAO;EACjB;;AA0BH,SAAgB,MAKd,QAQA;AACA,QAAO,yBAAyB,SAAS,OAAO;;AA+BlD,SAAgB,SAKd,QAQA;AACA,QAAO,yBAAyB,YAAY,OAAO;;AA+BrD,SAAgB,OAKd,QAQA;AACA,QAAO,yBAAyB,UAAU,OAAO;;AAmDnD,IAAa,WAAb,MAAsB;CACpB,OAA0C,EAAE;CAE5C,SACE,MACA,UACA,mBACA,OAAgC,EAAE,EAClC,gBAA+B,EAAE,MAAM,YAAY,EAC7C;AACN,OAAK,KAAK,KAAK;GACb;GACA,UAAU;IAAE,MAAM;IAAY,GAAG;IAAU;GAC3C,UAAU;GACV;GACA;GACD,CAAC;AACF,SAAO;;CAGT,MACE,MACA,UACA,mBACA,OAAgC,EAAE,EAClC,gBAA+B,EAAE,MAAM,YAAY,EAC7C;AACN,OAAK,KAAK,KAAK;GACb;GACA,UAAU;IAAE,MAAM;IAAS,GAAG;IAAU;GACxC,UAAU;GACV;GACA;GACD,CAAC;AACF,SAAO;;CAGT,OACE,MACA,UACA,mBACA,OAAgC,EAAE,EAClC,gBAA+B,EAAE,MAAM,YAAY,EAC7C;AACN,OAAK,KAAK,KAAK;GACb;GACA,UAAU;IAAE,MAAM;IAAU,GAAG;IAAU;GACzC,UAAU;GACV;GACA;GACD,CAAC;AACF,SAAO;;;;;;AAOX,SAAgB,WAAqB;AACnC,QAAO,IAAI,UAAU"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/runtime/id.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Generate a random UUID v4 string.
|
|
4
|
+
*
|
|
5
|
+
* Prefers `crypto.randomUUID()` when available (secure contexts, Node 19+,
|
|
6
|
+
* web workers). Falls back to building a v4 UUID from
|
|
7
|
+
* `crypto.getRandomValues()` for non-secure contexts such as `http://`
|
|
8
|
+
* dev servers.
|
|
9
|
+
*/
|
|
10
|
+
declare function generateId(): string;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { generateId };
|
|
13
|
+
//# sourceMappingURL=id.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.d.mts","names":[],"sources":["../../src/runtime/id.ts"],"mappings":";;AAQA;;;;;;;iBAAgB,UAAA,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/runtime/id.ts
|
|
2
|
+
/**
|
|
3
|
+
* Generate a random UUID v4 string.
|
|
4
|
+
*
|
|
5
|
+
* Prefers `crypto.randomUUID()` when available (secure contexts, Node 19+,
|
|
6
|
+
* web workers). Falls back to building a v4 UUID from
|
|
7
|
+
* `crypto.getRandomValues()` for non-secure contexts such as `http://`
|
|
8
|
+
* dev servers.
|
|
9
|
+
*/
|
|
10
|
+
function generateId() {
|
|
11
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") return crypto.randomUUID();
|
|
12
|
+
const bytes = new Uint8Array(16);
|
|
13
|
+
crypto.getRandomValues(bytes);
|
|
14
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
15
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
16
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
17
|
+
return [
|
|
18
|
+
hex.slice(0, 8),
|
|
19
|
+
hex.slice(8, 12),
|
|
20
|
+
hex.slice(12, 16),
|
|
21
|
+
hex.slice(16, 20),
|
|
22
|
+
hex.slice(20, 32)
|
|
23
|
+
].join("-");
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { generateId };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=id.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.mjs","names":[],"sources":["../../src/runtime/id.ts"],"sourcesContent":["/**\n * Generate a random UUID v4 string.\n *\n * Prefers `crypto.randomUUID()` when available (secure contexts, Node 19+,\n * web workers). Falls back to building a v4 UUID from\n * `crypto.getRandomValues()` for non-secure contexts such as `http://`\n * dev servers.\n */\nexport function generateId(): string {\n if (\n typeof crypto !== \"undefined\" &&\n typeof crypto.randomUUID === \"function\"\n ) {\n return crypto.randomUUID();\n }\n\n // Fallback: build a UUID v4 from getRandomValues.\n // Format: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\n const bytes = new Uint8Array(16);\n crypto.getRandomValues(bytes);\n\n // Set version (4) and variant (10xx) bits per RFC 4122.\n bytes[6] = (bytes[6]! & 0x0f) | 0x40;\n bytes[8] = (bytes[8]! & 0x3f) | 0x80;\n\n const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, \"0\")).join(\n \"\"\n );\n\n return [\n hex.slice(0, 8),\n hex.slice(8, 12),\n hex.slice(12, 16),\n hex.slice(16, 20),\n hex.slice(20, 32)\n ].join(\"-\");\n}\n"],"mappings":";;;;;;;;;AAQA,SAAgB,aAAqB;AACnC,KACE,OAAO,WAAW,eAClB,OAAO,OAAO,eAAe,WAE7B,QAAO,OAAO,YAAY;CAK5B,MAAM,QAAQ,IAAI,WAAW,GAAG;AAChC,QAAO,gBAAgB,MAAM;AAG7B,OAAM,KAAM,MAAM,KAAM,KAAQ;AAChC,OAAM,KAAM,MAAM,KAAM,KAAQ;CAEhC,MAAM,MAAM,MAAM,KAAK,QAAQ,MAAM,EAAE,SAAS,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC,KACpE,GACD;AAED,QAAO;EACL,IAAI,MAAM,GAAG,EAAE;EACf,IAAI,MAAM,GAAG,GAAG;EAChB,IAAI,MAAM,IAAI,GAAG;EACjB,IAAI,MAAM,IAAI,GAAG;EACjB,IAAI,MAAM,IAAI,GAAG;EAClB,CAAC,KAAK,IAAI"}
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import { FunctionArgsFromDefinition, FunctionKindFromDefinition, FunctionReference, FunctionResultFromDefinition, MisfirePolicy, RecurringJobDefinition, SyncoreFunctionKind } from "./functions.mjs";
|
|
2
|
+
import { InferDocument, InferTableInput, SyncoreSchema, Validator } from "../../schema/index.d.ts";
|
|
3
|
+
import { SyncoreDevtoolsEvent, SyncoreDevtoolsSnapshot } from "../../devtools-protocol/index.d.ts";
|
|
4
|
+
|
|
5
|
+
//#region src/runtime/runtime.d.ts
|
|
6
|
+
interface RegisteredSyncoreFunction {
|
|
7
|
+
kind: SyncoreFunctionKind;
|
|
8
|
+
argsValidator: Validator<unknown>;
|
|
9
|
+
returnsValidator?: Validator<unknown>;
|
|
10
|
+
handler: RegisteredSyncoreHandler;
|
|
11
|
+
}
|
|
12
|
+
interface SyncoreFunctionRegistry {
|
|
13
|
+
readonly [name: string]: RegisteredSyncoreFunction | undefined;
|
|
14
|
+
}
|
|
15
|
+
type RegisteredSyncoreHandler = {
|
|
16
|
+
bivarianceHack(ctx: unknown, args: unknown): unknown;
|
|
17
|
+
}["bivarianceHack"];
|
|
18
|
+
type JsonObject = Record<string, unknown>;
|
|
19
|
+
type ComparisonOperator = "=" | ">" | ">=" | "<" | "<=";
|
|
20
|
+
type QueryCondition = {
|
|
21
|
+
field: string;
|
|
22
|
+
operator: ComparisonOperator;
|
|
23
|
+
value: unknown;
|
|
24
|
+
};
|
|
25
|
+
type QueryExpression = {
|
|
26
|
+
type: "condition";
|
|
27
|
+
condition: QueryCondition;
|
|
28
|
+
} | {
|
|
29
|
+
type: "and";
|
|
30
|
+
expressions: QueryExpression[];
|
|
31
|
+
} | {
|
|
32
|
+
type: "or";
|
|
33
|
+
expressions: QueryExpression[];
|
|
34
|
+
};
|
|
35
|
+
type SearchQuery = {
|
|
36
|
+
searchField: string;
|
|
37
|
+
searchText: string;
|
|
38
|
+
filters: QueryCondition[];
|
|
39
|
+
};
|
|
40
|
+
interface RunResult {
|
|
41
|
+
changes: number;
|
|
42
|
+
lastInsertRowid?: number | string;
|
|
43
|
+
}
|
|
44
|
+
interface SyncoreSqlDriver {
|
|
45
|
+
exec(sql: string): Promise<void>;
|
|
46
|
+
run(sql: string, params?: unknown[]): Promise<RunResult>;
|
|
47
|
+
get<T>(sql: string, params?: unknown[]): Promise<T | undefined>;
|
|
48
|
+
all<T>(sql: string, params?: unknown[]): Promise<T[]>;
|
|
49
|
+
withTransaction<T>(callback: () => Promise<T>): Promise<T>;
|
|
50
|
+
withSavepoint<T>(name: string, callback: () => Promise<T>): Promise<T>;
|
|
51
|
+
close?(): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The binary or text payload written through Syncore storage APIs.
|
|
55
|
+
*/
|
|
56
|
+
interface StorageWriteInput {
|
|
57
|
+
data: Uint8Array | ArrayBuffer | string;
|
|
58
|
+
contentType?: string;
|
|
59
|
+
fileName?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Metadata about an object stored through Syncore storage APIs.
|
|
63
|
+
*/
|
|
64
|
+
interface StorageObject {
|
|
65
|
+
id: string;
|
|
66
|
+
path: string;
|
|
67
|
+
size: number;
|
|
68
|
+
contentType: string | null;
|
|
69
|
+
}
|
|
70
|
+
interface SyncoreStorageAdapter {
|
|
71
|
+
put(id: string, input: StorageWriteInput): Promise<StorageObject>;
|
|
72
|
+
get(id: string): Promise<StorageObject | null>;
|
|
73
|
+
read(id: string): Promise<Uint8Array | null>;
|
|
74
|
+
delete(id: string): Promise<void>;
|
|
75
|
+
list?(): Promise<StorageObject[]>;
|
|
76
|
+
}
|
|
77
|
+
interface DevtoolsSink {
|
|
78
|
+
emit(event: SyncoreDevtoolsEvent): void;
|
|
79
|
+
}
|
|
80
|
+
interface SchedulerOptions {
|
|
81
|
+
pollIntervalMs?: number;
|
|
82
|
+
recurringJobs?: RecurringJobDefinition[];
|
|
83
|
+
}
|
|
84
|
+
interface SyncoreCapabilities {
|
|
85
|
+
[name: string]: unknown;
|
|
86
|
+
}
|
|
87
|
+
interface SyncoreExperimentalPluginContext<TSchema extends AnySyncoreSchema> {
|
|
88
|
+
runtimeId: string;
|
|
89
|
+
platform: string;
|
|
90
|
+
schema: TSchema;
|
|
91
|
+
driver: SyncoreSqlDriver;
|
|
92
|
+
storage: SyncoreStorageAdapter;
|
|
93
|
+
scheduler?: SchedulerOptions;
|
|
94
|
+
devtools?: DevtoolsSink;
|
|
95
|
+
emitDevtools(event: SyncoreDevtoolsEvent): void;
|
|
96
|
+
}
|
|
97
|
+
interface SyncoreExperimentalPlugin<TSchema extends AnySyncoreSchema> {
|
|
98
|
+
name: string;
|
|
99
|
+
capabilities?: SyncoreCapabilities | ((context: SyncoreExperimentalPluginContext<TSchema>) => SyncoreCapabilities | void);
|
|
100
|
+
onStart?(context: SyncoreExperimentalPluginContext<TSchema>): Promise<void> | void;
|
|
101
|
+
onStop?(context: SyncoreExperimentalPluginContext<TSchema>): Promise<void> | void;
|
|
102
|
+
}
|
|
103
|
+
interface SyncoreRuntimeOptions<TSchema extends AnySyncoreSchema> {
|
|
104
|
+
schema: TSchema;
|
|
105
|
+
functions: SyncoreFunctionRegistry;
|
|
106
|
+
driver: SyncoreSqlDriver;
|
|
107
|
+
storage: SyncoreStorageAdapter;
|
|
108
|
+
capabilities?: SyncoreCapabilities;
|
|
109
|
+
experimentalPlugins?: Array<SyncoreExperimentalPlugin<TSchema>>;
|
|
110
|
+
platform?: string;
|
|
111
|
+
devtools?: DevtoolsSink;
|
|
112
|
+
scheduler?: SchedulerOptions;
|
|
113
|
+
}
|
|
114
|
+
interface PaginationOptions {
|
|
115
|
+
cursor?: string | null;
|
|
116
|
+
numItems: number;
|
|
117
|
+
}
|
|
118
|
+
interface PaginationResult<TItem> {
|
|
119
|
+
/** The current page of results. */
|
|
120
|
+
page: TItem[];
|
|
121
|
+
/** The cursor to pass to the next page request, or `null` when finished. */
|
|
122
|
+
cursor: string | null;
|
|
123
|
+
/** Whether there are no more pages to read. */
|
|
124
|
+
isDone: boolean;
|
|
125
|
+
}
|
|
126
|
+
interface SyncoreWatch<TValue> {
|
|
127
|
+
/** Subscribe to updates for this query watch. */
|
|
128
|
+
onUpdate(callback: () => void): () => void;
|
|
129
|
+
/** Read the latest local query result, if one is available. */
|
|
130
|
+
localQueryResult(): TValue | undefined;
|
|
131
|
+
/** Read the latest local query error, if one is available. */
|
|
132
|
+
localQueryError(): Error | undefined;
|
|
133
|
+
/** Dispose the watch if the implementation exposes explicit cleanup. */
|
|
134
|
+
dispose?(): void;
|
|
135
|
+
}
|
|
136
|
+
interface FilterBuilder {
|
|
137
|
+
/** Match documents whose field is exactly equal to a value. */
|
|
138
|
+
eq(field: string, value: unknown): QueryExpression;
|
|
139
|
+
/** Match documents whose field is greater than a value. */
|
|
140
|
+
gt(field: string, value: unknown): QueryExpression;
|
|
141
|
+
/** Match documents whose field is greater than or equal to a value. */
|
|
142
|
+
gte(field: string, value: unknown): QueryExpression;
|
|
143
|
+
/** Match documents whose field is less than a value. */
|
|
144
|
+
lt(field: string, value: unknown): QueryExpression;
|
|
145
|
+
/** Match documents whose field is less than or equal to a value. */
|
|
146
|
+
lte(field: string, value: unknown): QueryExpression;
|
|
147
|
+
/** Combine several filter expressions with logical AND. */
|
|
148
|
+
and(...expressions: QueryExpression[]): QueryExpression;
|
|
149
|
+
/** Combine several filter expressions with logical OR. */
|
|
150
|
+
or(...expressions: QueryExpression[]): QueryExpression;
|
|
151
|
+
}
|
|
152
|
+
interface IndexRangeBuilder {
|
|
153
|
+
/** Constrain an indexed field to an exact value. */
|
|
154
|
+
eq(field: string, value: unknown): IndexRangeBuilder;
|
|
155
|
+
/** Constrain an indexed field to values greater than a value. */
|
|
156
|
+
gt(field: string, value: unknown): IndexRangeBuilder;
|
|
157
|
+
/** Constrain an indexed field to values greater than or equal to a value. */
|
|
158
|
+
gte(field: string, value: unknown): IndexRangeBuilder;
|
|
159
|
+
/** Constrain an indexed field to values less than a value. */
|
|
160
|
+
lt(field: string, value: unknown): IndexRangeBuilder;
|
|
161
|
+
/** Constrain an indexed field to values less than or equal to a value. */
|
|
162
|
+
lte(field: string, value: unknown): IndexRangeBuilder;
|
|
163
|
+
/** Finish building the index range. */
|
|
164
|
+
build(): QueryCondition[];
|
|
165
|
+
}
|
|
166
|
+
interface SearchIndexBuilder {
|
|
167
|
+
/** Set the text field and text to search for. */
|
|
168
|
+
search(field: string, value: string): SearchIndexBuilder;
|
|
169
|
+
/** Add an equality filter alongside the text search. */
|
|
170
|
+
eq(field: string, value: unknown): SearchIndexBuilder;
|
|
171
|
+
/** Finish building the search query. */
|
|
172
|
+
build(): SearchQuery;
|
|
173
|
+
}
|
|
174
|
+
type AnySyncoreSchema = SyncoreSchema<any>;
|
|
175
|
+
type TableNames<TSchema extends AnySyncoreSchema> = Extract<keyof TSchema["tables"], string>;
|
|
176
|
+
type DocumentForTable<TSchema extends AnySyncoreSchema, TTableName extends TableNames<TSchema>> = InferDocument<TSchema["tables"][TTableName]>;
|
|
177
|
+
type InsertValueForTable<TSchema extends AnySyncoreSchema, TTableName extends TableNames<TSchema>> = InferTableInput<TSchema["tables"][TTableName]>;
|
|
178
|
+
type OptionalArgsTuple<TArgs> = Record<never, never> extends TArgs ? [args?: TArgs] : [args: TArgs];
|
|
179
|
+
interface SyncoreDatabaseReader<TSchema extends AnySyncoreSchema = AnySyncoreSchema> {
|
|
180
|
+
/** Read a single document by table name and id. */
|
|
181
|
+
get<TTableName extends TableNames<TSchema>>(table: TTableName, id: string): Promise<DocumentForTable<TSchema, TTableName> | null>;
|
|
182
|
+
/** Start building a table query. */
|
|
183
|
+
query<TTableName extends TableNames<TSchema>>(table: TTableName): QueryBuilder<DocumentForTable<TSchema, TTableName>>;
|
|
184
|
+
/** Run raw SQL against the local Syncore database. */
|
|
185
|
+
raw<TValue = unknown>(sql: string, params?: unknown[]): Promise<TValue[]>;
|
|
186
|
+
}
|
|
187
|
+
interface SyncoreDatabaseWriter<TSchema extends AnySyncoreSchema = AnySyncoreSchema> extends SyncoreDatabaseReader<TSchema> {
|
|
188
|
+
/** Insert a new document into a table and return its generated id. */
|
|
189
|
+
insert<TTableName extends TableNames<TSchema>>(table: TTableName, value: InsertValueForTable<TSchema, TTableName>): Promise<string>;
|
|
190
|
+
/** Apply a partial update to an existing document. */
|
|
191
|
+
patch<TTableName extends TableNames<TSchema>>(table: TTableName, id: string, value: Partial<InsertValueForTable<TSchema, TTableName>>): Promise<void>;
|
|
192
|
+
/** Replace an existing document with a full new value. */
|
|
193
|
+
replace<TTableName extends TableNames<TSchema>>(table: TTableName, id: string, value: InsertValueForTable<TSchema, TTableName>): Promise<void>;
|
|
194
|
+
/** Delete a document from a table. */
|
|
195
|
+
delete<TTableName extends TableNames<TSchema>>(table: TTableName, id: string): Promise<void>;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* The storage API exposed inside Syncore runtime contexts.
|
|
199
|
+
*/
|
|
200
|
+
interface SyncoreStorageApi {
|
|
201
|
+
/** Store a file-like payload locally and return its generated id. */
|
|
202
|
+
put(input: StorageWriteInput): Promise<string>;
|
|
203
|
+
/** Read metadata for a stored object. */
|
|
204
|
+
get(id: string): Promise<StorageObject | null>;
|
|
205
|
+
/** Read the stored bytes for an object. */
|
|
206
|
+
read(id: string): Promise<Uint8Array | null>;
|
|
207
|
+
/** Delete a stored object. */
|
|
208
|
+
delete(id: string): Promise<void>;
|
|
209
|
+
}
|
|
210
|
+
interface SchedulerApi {
|
|
211
|
+
/** Schedule a mutation or action to run after a delay. */
|
|
212
|
+
runAfter<TArgs, TResult>(delayMs: number, functionReference: FunctionReference<"mutation" | "action", TArgs, TResult>, ...args: [...OptionalArgsTuple<TArgs>, misfirePolicy?: MisfirePolicy]): Promise<string>;
|
|
213
|
+
/** Schedule a mutation or action to run at a specific time. */
|
|
214
|
+
runAt<TArgs, TResult>(timestamp: number | Date, functionReference: FunctionReference<"mutation" | "action", TArgs, TResult>, ...args: [...OptionalArgsTuple<TArgs>, misfirePolicy?: MisfirePolicy]): Promise<string>;
|
|
215
|
+
/** Cancel a previously scheduled job. */
|
|
216
|
+
cancel(id: string): Promise<void>;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* The context object available inside Syncore queries.
|
|
220
|
+
*/
|
|
221
|
+
interface QueryCtx<TSchema extends AnySyncoreSchema = AnySyncoreSchema> {
|
|
222
|
+
/** Read-only database access for this query. */
|
|
223
|
+
db: SyncoreDatabaseReader<TSchema>;
|
|
224
|
+
/** Local file/blob storage for this runtime. */
|
|
225
|
+
storage: SyncoreStorageApi;
|
|
226
|
+
/** Optional adapter or plugin capabilities exposed by the runtime. */
|
|
227
|
+
capabilities?: Readonly<SyncoreCapabilities>;
|
|
228
|
+
/** Call another Syncore query from inside this query. */
|
|
229
|
+
runQuery<TArgs, TResult>(reference: FunctionReference<"query", TArgs, TResult>, ...args: OptionalArgsTuple<TArgs>): Promise<TResult>;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* The context object available inside Syncore mutations.
|
|
233
|
+
*/
|
|
234
|
+
interface MutationCtx<TSchema extends AnySyncoreSchema = AnySyncoreSchema> extends QueryCtx<TSchema> {
|
|
235
|
+
db: SyncoreDatabaseWriter<TSchema>;
|
|
236
|
+
/** Schedule future work from this mutation. */
|
|
237
|
+
scheduler: SchedulerApi;
|
|
238
|
+
/** Call another mutation from inside this mutation. */
|
|
239
|
+
runMutation<TArgs, TResult>(reference: FunctionReference<"mutation", TArgs, TResult>, ...args: OptionalArgsTuple<TArgs>): Promise<TResult>;
|
|
240
|
+
/** Call an action from this mutation. */
|
|
241
|
+
runAction<TArgs, TResult>(reference: FunctionReference<"action", TArgs, TResult>, ...args: OptionalArgsTuple<TArgs>): Promise<TResult>;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* The context object available inside Syncore actions.
|
|
245
|
+
*/
|
|
246
|
+
interface ActionCtx<TSchema extends AnySyncoreSchema = AnySyncoreSchema> extends QueryCtx<TSchema> {
|
|
247
|
+
/** Schedule future work from this action. */
|
|
248
|
+
scheduler: SchedulerApi;
|
|
249
|
+
/** Call a mutation from this action. */
|
|
250
|
+
runMutation<TArgs, TResult>(reference: FunctionReference<"mutation", TArgs, TResult>, ...args: OptionalArgsTuple<TArgs>): Promise<TResult>;
|
|
251
|
+
/** Call another action from this action. */
|
|
252
|
+
runAction<TArgs, TResult>(reference: FunctionReference<"action", TArgs, TResult>, ...args: OptionalArgsTuple<TArgs>): Promise<TResult>;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* The typed client API exposed by a Syncore runtime.
|
|
256
|
+
*/
|
|
257
|
+
interface SyncoreClient {
|
|
258
|
+
/** Fetch a query result once. */
|
|
259
|
+
query<TArgs, TResult>(reference: FunctionReference<"query", TArgs, TResult>, ...args: OptionalArgsTuple<TArgs>): Promise<TResult>;
|
|
260
|
+
/** Execute a mutation. */
|
|
261
|
+
mutation<TArgs, TResult>(reference: FunctionReference<"mutation", TArgs, TResult>, ...args: OptionalArgsTuple<TArgs>): Promise<TResult>;
|
|
262
|
+
/** Execute an action. */
|
|
263
|
+
action<TArgs, TResult>(reference: FunctionReference<"action", TArgs, TResult>, ...args: OptionalArgsTuple<TArgs>): Promise<TResult>;
|
|
264
|
+
/** Subscribe to a query and receive reactive updates. */
|
|
265
|
+
watchQuery<TArgs, TResult>(reference: FunctionReference<"query", TArgs, TResult>, ...args: OptionalArgsTuple<TArgs>): SyncoreWatch<TResult>;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* A composable builder for Syncore table queries.
|
|
269
|
+
*/
|
|
270
|
+
interface QueryBuilder<TDocument> {
|
|
271
|
+
/** Query through a named index instead of scanning the whole table. */
|
|
272
|
+
withIndex(indexName: string, builder?: (range: IndexRangeBuilder) => IndexRangeBuilder): this;
|
|
273
|
+
/** Query through a named search index for text search. */
|
|
274
|
+
withSearchIndex(indexName: string, builder: (search: SearchIndexBuilder) => SearchIndexBuilder): this;
|
|
275
|
+
/** Set the result ordering. */
|
|
276
|
+
order(order: "asc" | "desc"): this;
|
|
277
|
+
/** Add a filter expression to the query. */
|
|
278
|
+
filter(builder: (filter: FilterBuilder) => QueryExpression): this;
|
|
279
|
+
/** Collect all matching documents. */
|
|
280
|
+
collect(): Promise<TDocument[]>;
|
|
281
|
+
/** Collect up to a fixed number of matching documents. */
|
|
282
|
+
take(count: number): Promise<TDocument[]>;
|
|
283
|
+
/** Return the first matching document, or `null` if none exist. */
|
|
284
|
+
first(): Promise<TDocument | null>;
|
|
285
|
+
/** Return one matching document and throw if multiple rows match. */
|
|
286
|
+
unique(): Promise<TDocument | null>;
|
|
287
|
+
/** Read a paginated slice of documents using a cursor. */
|
|
288
|
+
paginate(options: PaginationOptions): Promise<PaginationResult<TDocument>>;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* The local Syncore runtime that owns the database, storage, scheduler, and function execution.
|
|
292
|
+
*/
|
|
293
|
+
declare class SyncoreRuntime<TSchema extends AnySyncoreSchema> {
|
|
294
|
+
private readonly options;
|
|
295
|
+
private readonly runtimeId;
|
|
296
|
+
private readonly platform;
|
|
297
|
+
private readonly capabilities;
|
|
298
|
+
private readonly experimentalPlugins;
|
|
299
|
+
private readonly activeQueries;
|
|
300
|
+
private readonly disabledSearchIndexes;
|
|
301
|
+
private readonly recentEvents;
|
|
302
|
+
private schedulerTimer;
|
|
303
|
+
private readonly recurringJobs;
|
|
304
|
+
private readonly schedulerPollIntervalMs;
|
|
305
|
+
private started;
|
|
306
|
+
constructor(options: SyncoreRuntimeOptions<TSchema>);
|
|
307
|
+
/**
|
|
308
|
+
* Start the local Syncore runtime.
|
|
309
|
+
*/
|
|
310
|
+
start(): Promise<void>;
|
|
311
|
+
/**
|
|
312
|
+
* Stop the local Syncore runtime and release any open resources.
|
|
313
|
+
*/
|
|
314
|
+
stop(): Promise<void>;
|
|
315
|
+
/**
|
|
316
|
+
* Create a typed client for calling this runtime from the same process.
|
|
317
|
+
*/
|
|
318
|
+
createClient(): SyncoreClient;
|
|
319
|
+
getDevtoolsSnapshot(): SyncoreDevtoolsSnapshot;
|
|
320
|
+
getRuntimeId(): string;
|
|
321
|
+
runQuery<TArgs, TResult>(reference: FunctionReference<"query", TArgs, TResult>, args?: JsonObject): Promise<TResult>;
|
|
322
|
+
runMutation<TArgs, TResult>(reference: FunctionReference<"mutation", TArgs, TResult>, args?: JsonObject): Promise<TResult>;
|
|
323
|
+
runAction<TArgs, TResult>(reference: FunctionReference<"action", TArgs, TResult>, args?: JsonObject): Promise<TResult>;
|
|
324
|
+
watchQuery<TArgs, TResult>(reference: FunctionReference<"query", TArgs, TResult>, args?: JsonObject): SyncoreWatch<TResult>;
|
|
325
|
+
private executeQueryBuilder;
|
|
326
|
+
private invokeFunction;
|
|
327
|
+
private createContext;
|
|
328
|
+
private createDatabaseReader;
|
|
329
|
+
private createDatabaseWriter;
|
|
330
|
+
private createStorageApi;
|
|
331
|
+
private createSchedulerApi;
|
|
332
|
+
private ensureSystemTables;
|
|
333
|
+
private reconcileStorageState;
|
|
334
|
+
private applySchema;
|
|
335
|
+
private scheduleJob;
|
|
336
|
+
private syncRecurringJobs;
|
|
337
|
+
private processDueJobs;
|
|
338
|
+
private advanceOrFinalizeJob;
|
|
339
|
+
private refreshInvalidatedQueries;
|
|
340
|
+
private rerunActiveQuery;
|
|
341
|
+
private collectQueryDependencies;
|
|
342
|
+
private resolveFunction;
|
|
343
|
+
private validateDocument;
|
|
344
|
+
private deserializeDocument;
|
|
345
|
+
private syncSearchIndexes;
|
|
346
|
+
private removeSearchIndexes;
|
|
347
|
+
private renderExpression;
|
|
348
|
+
private renderCondition;
|
|
349
|
+
private createActiveQueryKey;
|
|
350
|
+
private emitDevtools;
|
|
351
|
+
private createPluginContext;
|
|
352
|
+
private buildCapabilities;
|
|
353
|
+
private runPluginHook;
|
|
354
|
+
private findSearchIndexKeyForStatement;
|
|
355
|
+
private getTableDefinition;
|
|
356
|
+
}
|
|
357
|
+
declare function createFunctionReference<TKind extends SyncoreFunctionKind, TArgs = Record<never, never>, TResult = unknown>(kind: TKind, name: string): FunctionReference<TKind, TArgs, TResult>;
|
|
358
|
+
/**
|
|
359
|
+
* Create a typed function reference from a concrete Syncore function definition.
|
|
360
|
+
*
|
|
361
|
+
* Generated code uses this helper to preserve function arg and result inference.
|
|
362
|
+
*/
|
|
363
|
+
declare function createFunctionReferenceFor<TDefinition extends {
|
|
364
|
+
kind: SyncoreFunctionKind;
|
|
365
|
+
argsValidator: Validator<unknown>;
|
|
366
|
+
returnsValidator?: Validator<unknown>;
|
|
367
|
+
}>(kind: FunctionKindFromDefinition<TDefinition>, name: string): FunctionReference<FunctionKindFromDefinition<TDefinition>, FunctionArgsFromDefinition<TDefinition>, FunctionResultFromDefinition<TDefinition>>;
|
|
368
|
+
//#endregion
|
|
369
|
+
export { ActionCtx, AnySyncoreSchema, ComparisonOperator, DevtoolsSink, DocumentForTable, FilterBuilder, IndexRangeBuilder, InsertValueForTable, JsonObject, MutationCtx, PaginationOptions, PaginationResult, QueryBuilder, QueryCondition, QueryCtx, QueryExpression, RegisteredSyncoreFunction, RegisteredSyncoreHandler, RunResult, SchedulerApi, SchedulerOptions, SearchIndexBuilder, SearchQuery, StorageObject, StorageWriteInput, SyncoreCapabilities, SyncoreClient, SyncoreDatabaseReader, SyncoreDatabaseWriter, SyncoreExperimentalPlugin, SyncoreExperimentalPluginContext, SyncoreFunctionRegistry, SyncoreRuntime, SyncoreRuntimeOptions, SyncoreSqlDriver, SyncoreStorageAdapter, SyncoreStorageApi, SyncoreWatch, TableNames, createFunctionReference, createFunctionReferenceFor };
|
|
370
|
+
//# sourceMappingURL=runtime.d.mts.map
|