@gonvex/module-sdk 0.3.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/LICENSE +201 -0
- package/README.md +185 -0
- package/dist/identity-contract.test.d.ts +1 -0
- package/dist/identity-contract.test.js +18 -0
- package/dist/identity-contract.test.js.map +1 -0
- package/dist/index.d.ts +641 -0
- package/dist/index.js +805 -0
- package/dist/index.js.map +1 -0
- package/package.json +28 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,641 @@
|
|
|
1
|
+
/** JSON values accepted by the module ABI. */
|
|
2
|
+
export type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
3
|
+
[key: string]: JsonValue;
|
|
4
|
+
};
|
|
5
|
+
export type JsonObject = {
|
|
6
|
+
[key: string]: JsonValue;
|
|
7
|
+
};
|
|
8
|
+
export type ModuleLanguage = "typescript";
|
|
9
|
+
export type ModuleEngine = "v8";
|
|
10
|
+
export type PortableSchema = StringSchema | NumberSchema | BooleanSchema | NullSchema | AnySchema | IdSchema | LiteralSchema | ArraySchema | ObjectSchema | RecordSchema | OptionalSchema;
|
|
11
|
+
export type StringSchema = {
|
|
12
|
+
readonly kind: "string";
|
|
13
|
+
readonly format?: "email" | "uri" | "uuid" | "datetime";
|
|
14
|
+
readonly minLength?: number;
|
|
15
|
+
readonly maxLength?: number;
|
|
16
|
+
};
|
|
17
|
+
export type NumberSchema = {
|
|
18
|
+
readonly kind: "number";
|
|
19
|
+
readonly integer?: boolean;
|
|
20
|
+
readonly minimum?: number;
|
|
21
|
+
readonly maximum?: number;
|
|
22
|
+
};
|
|
23
|
+
export type BooleanSchema = {
|
|
24
|
+
readonly kind: "boolean";
|
|
25
|
+
};
|
|
26
|
+
export type NullSchema = {
|
|
27
|
+
readonly kind: "null";
|
|
28
|
+
};
|
|
29
|
+
export type AnySchema = {
|
|
30
|
+
readonly kind: "any";
|
|
31
|
+
};
|
|
32
|
+
export type IdSchema = {
|
|
33
|
+
readonly kind: "id";
|
|
34
|
+
readonly entity: string;
|
|
35
|
+
};
|
|
36
|
+
export type LiteralSchema = {
|
|
37
|
+
readonly kind: "literal";
|
|
38
|
+
readonly value: JsonValue;
|
|
39
|
+
};
|
|
40
|
+
export type ArraySchema = {
|
|
41
|
+
readonly kind: "array";
|
|
42
|
+
readonly items: PortableSchema;
|
|
43
|
+
};
|
|
44
|
+
export type ObjectSchema = {
|
|
45
|
+
readonly kind: "object";
|
|
46
|
+
readonly fields: Readonly<Record<string, PortableSchema>>;
|
|
47
|
+
readonly allowUnknown?: boolean;
|
|
48
|
+
};
|
|
49
|
+
export type RecordSchema = {
|
|
50
|
+
readonly kind: "record";
|
|
51
|
+
readonly values: PortableSchema;
|
|
52
|
+
};
|
|
53
|
+
export type OptionalSchema = {
|
|
54
|
+
readonly kind: "optional";
|
|
55
|
+
readonly value: PortableSchema;
|
|
56
|
+
};
|
|
57
|
+
export type InferSchema<S extends PortableSchema> = S extends StringSchema ? string : S extends NumberSchema ? number : S extends BooleanSchema ? boolean : S extends NullSchema ? null : S extends AnySchema ? JsonValue : S extends IdSchema ? string : S extends LiteralSchema ? S["value"] : S extends ArraySchema ? InferSchema<S["items"]>[] : S extends ObjectSchema ? {
|
|
58
|
+
[K in keyof S["fields"]]: S["fields"][K] extends OptionalSchema ? InferSchema<S["fields"][K]["value"]> | undefined : S["fields"][K] extends PortableSchema ? InferSchema<S["fields"][K]> : never;
|
|
59
|
+
} : S extends RecordSchema ? Record<string, InferSchema<S["values"]>> : S extends OptionalSchema ? InferSchema<S["value"]> | undefined : never;
|
|
60
|
+
/** Constructors for the language-neutral schema subset. */
|
|
61
|
+
export declare const schema: {
|
|
62
|
+
string(options?: Omit<StringSchema, "kind">): StringSchema;
|
|
63
|
+
email(): StringSchema;
|
|
64
|
+
uri(): StringSchema;
|
|
65
|
+
uuid(): StringSchema;
|
|
66
|
+
datetime(): StringSchema;
|
|
67
|
+
number(options?: Omit<NumberSchema, "kind">): NumberSchema;
|
|
68
|
+
integer(options?: Omit<NumberSchema, "kind" | "integer">): NumberSchema;
|
|
69
|
+
boolean(): BooleanSchema;
|
|
70
|
+
null(): NullSchema;
|
|
71
|
+
any(): AnySchema;
|
|
72
|
+
id(entity: string): IdSchema;
|
|
73
|
+
literal(value: JsonValue): LiteralSchema;
|
|
74
|
+
array(items: PortableSchema): ArraySchema;
|
|
75
|
+
object(fields: Record<string, PortableSchema>, options?: Omit<ObjectSchema, "kind" | "fields">): ObjectSchema;
|
|
76
|
+
record(values: PortableSchema): RecordSchema;
|
|
77
|
+
optional(value: PortableSchema): OptionalSchema;
|
|
78
|
+
};
|
|
79
|
+
export type Account = {
|
|
80
|
+
readonly id: string;
|
|
81
|
+
readonly email?: string;
|
|
82
|
+
readonly name?: string;
|
|
83
|
+
readonly avatarUrl?: string;
|
|
84
|
+
};
|
|
85
|
+
export type Tenant = {
|
|
86
|
+
readonly id: string;
|
|
87
|
+
readonly name?: string;
|
|
88
|
+
};
|
|
89
|
+
export type Member = {
|
|
90
|
+
readonly id: string;
|
|
91
|
+
readonly accountId: string;
|
|
92
|
+
readonly status?: "active" | "revoked" | "disabled" | (string & {});
|
|
93
|
+
readonly role?: string;
|
|
94
|
+
readonly displayName?: string;
|
|
95
|
+
readonly permissions: Readonly<Record<string, JsonValue>> | null;
|
|
96
|
+
};
|
|
97
|
+
/** Authentication identity exposed to a module. */
|
|
98
|
+
export type AuthContext = {
|
|
99
|
+
readonly auth: {
|
|
100
|
+
readonly account: Account | null;
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
/** Tenant and tenant-local member identity, both nullable at the ABI boundary. */
|
|
104
|
+
export type TenantContext = {
|
|
105
|
+
readonly tenant: Tenant | null;
|
|
106
|
+
readonly member: Member | null;
|
|
107
|
+
};
|
|
108
|
+
export type ReadDB = {
|
|
109
|
+
readonly query: <T = JsonValue>(statement: string, parameters?: readonly JsonValue[]) => Promise<readonly T[]>;
|
|
110
|
+
};
|
|
111
|
+
export type WriteDB = ReadDB & {
|
|
112
|
+
readonly insert: <T = JsonValue>(table: string, row: JsonObject) => Promise<T>;
|
|
113
|
+
readonly update: <T = JsonValue>(table: string, id: string, patch: JsonObject) => Promise<T>;
|
|
114
|
+
readonly delete: (table: string, id: string) => Promise<void>;
|
|
115
|
+
};
|
|
116
|
+
/** Durable external work recorded in the Reducer's current transaction. */
|
|
117
|
+
export type ReducerActions = {
|
|
118
|
+
readonly enqueue: (path: string, args: JsonValue) => Promise<string>;
|
|
119
|
+
};
|
|
120
|
+
/** One-shot work owned by the Gonvex scheduler. Timestamps are Unix milliseconds. */
|
|
121
|
+
export type Scheduler = {
|
|
122
|
+
readonly runAfter: (delayMs: number, functionPath: string, args?: JsonValue) => Promise<string>;
|
|
123
|
+
readonly runAt: (unixMs: number, functionPath: string, args?: JsonValue) => Promise<string>;
|
|
124
|
+
};
|
|
125
|
+
export type QueryContext = AuthContext & TenantContext & {
|
|
126
|
+
readonly db: ReadDB;
|
|
127
|
+
readonly now: number;
|
|
128
|
+
};
|
|
129
|
+
export type ReducerContext = AuthContext & TenantContext & {
|
|
130
|
+
readonly db: WriteDB;
|
|
131
|
+
readonly actions: ReducerActions;
|
|
132
|
+
readonly scheduler: Scheduler;
|
|
133
|
+
readonly now: number;
|
|
134
|
+
};
|
|
135
|
+
export type ActionStorage = {
|
|
136
|
+
readonly generateUploadUrl: (options?: JsonObject) => Promise<JsonValue>;
|
|
137
|
+
readonly getUrl: (fileId: string) => Promise<JsonValue>;
|
|
138
|
+
readonly generateDownloadUrl: (fileId: string, ttlMs?: number) => Promise<JsonValue>;
|
|
139
|
+
readonly getMetadata: (fileId: string) => Promise<JsonValue>;
|
|
140
|
+
readonly delete: (fileId: string) => Promise<JsonValue>;
|
|
141
|
+
readonly store: (contentBase64: string, options?: JsonObject) => Promise<JsonValue>;
|
|
142
|
+
readonly call: (operation: string, payload?: JsonValue) => Promise<JsonValue>;
|
|
143
|
+
};
|
|
144
|
+
export type ActionToolBinding = {
|
|
145
|
+
readonly kind: "query" | "reducer";
|
|
146
|
+
readonly function: string;
|
|
147
|
+
};
|
|
148
|
+
export type ActionToolBindings = Readonly<Record<string, ActionToolBinding>>;
|
|
149
|
+
export type SandboxStatus = "queued" | "running" | "succeeded" | "failed" | "cancelled" | "timedOut";
|
|
150
|
+
export type SandboxHandle = {
|
|
151
|
+
readonly sandboxId: string;
|
|
152
|
+
readonly expiresAt: number;
|
|
153
|
+
readonly duckdb: boolean;
|
|
154
|
+
};
|
|
155
|
+
export type SandboxExecution = {
|
|
156
|
+
readonly sandboxId: string;
|
|
157
|
+
readonly executionId: string;
|
|
158
|
+
readonly status: SandboxStatus;
|
|
159
|
+
};
|
|
160
|
+
export type SandboxExecutionStatus = SandboxExecution & {
|
|
161
|
+
readonly startedAt?: number;
|
|
162
|
+
readonly finishedAt?: number;
|
|
163
|
+
readonly result?: JsonValue;
|
|
164
|
+
readonly error?: string;
|
|
165
|
+
readonly logs: readonly {
|
|
166
|
+
readonly level: "log" | "warn" | "error";
|
|
167
|
+
readonly message: string;
|
|
168
|
+
}[];
|
|
169
|
+
};
|
|
170
|
+
export type ActionSandbox = {
|
|
171
|
+
/** Create one caller-owned, tenant-scoped ephemeral TypeScript workspace. */
|
|
172
|
+
readonly create: (options?: {
|
|
173
|
+
readonly ttlMs?: number;
|
|
174
|
+
}) => Promise<SandboxHandle>;
|
|
175
|
+
/** Start TypeScript code asynchronously. The code returns its JSON result with a top-level return statement. */
|
|
176
|
+
readonly run: (sandboxId: string, options: {
|
|
177
|
+
readonly code: string;
|
|
178
|
+
readonly timeoutMs?: number;
|
|
179
|
+
}) => Promise<SandboxExecution>;
|
|
180
|
+
readonly cancel: (sandboxId: string, executionId: string) => Promise<SandboxExecutionStatus>;
|
|
181
|
+
readonly status: (sandboxId: string, executionId: string) => Promise<SandboxExecutionStatus>;
|
|
182
|
+
readonly readFile: (sandboxId: string, path: string) => Promise<{
|
|
183
|
+
readonly contentBase64: string;
|
|
184
|
+
readonly size: number;
|
|
185
|
+
}>;
|
|
186
|
+
readonly writeFile: (sandboxId: string, path: string, contentBase64: string) => Promise<{
|
|
187
|
+
readonly path: string;
|
|
188
|
+
readonly size: number;
|
|
189
|
+
}>;
|
|
190
|
+
readonly readText: (sandboxId: string, path: string) => Promise<string>;
|
|
191
|
+
readonly writeText: (sandboxId: string, path: string, content: string) => Promise<{
|
|
192
|
+
readonly path: string;
|
|
193
|
+
readonly size: number;
|
|
194
|
+
}>;
|
|
195
|
+
/** Ingest an authorized Gonvex storage file into DuckDB without placing its bytes in model context. */
|
|
196
|
+
readonly importFile: (sandboxId: string, options: {
|
|
197
|
+
readonly fileId: string;
|
|
198
|
+
readonly filename: string;
|
|
199
|
+
}) => Promise<{
|
|
200
|
+
readonly alias: string;
|
|
201
|
+
readonly tables: readonly {
|
|
202
|
+
readonly tableName: string;
|
|
203
|
+
readonly rowCount: number;
|
|
204
|
+
readonly columns: readonly string[];
|
|
205
|
+
}[];
|
|
206
|
+
}>;
|
|
207
|
+
};
|
|
208
|
+
export type SandboxCapability = {
|
|
209
|
+
/** Bind a private DuckDB database into the TypeScript worker. */
|
|
210
|
+
readonly duckdb?: true;
|
|
211
|
+
};
|
|
212
|
+
export type ActionCapabilities<Tools extends ActionToolBindings = ActionToolBindings> = {
|
|
213
|
+
/** Exact URL origins this Action may call. No network access is granted when omitted. */
|
|
214
|
+
readonly networkOrigins?: readonly string[];
|
|
215
|
+
/** Exact project secret names copied into this invocation. No other environment values are exposed. */
|
|
216
|
+
readonly secrets?: readonly string[];
|
|
217
|
+
/** Named, statically bound Query and Reducer tools. Arbitrary function paths are never accepted. */
|
|
218
|
+
readonly tools?: Tools;
|
|
219
|
+
readonly scheduler?: true;
|
|
220
|
+
readonly storage?: true;
|
|
221
|
+
/** Run untrusted TypeScript in an out-of-process, tenant-scoped sandbox. Agent Actions only. */
|
|
222
|
+
readonly sandbox?: SandboxCapability;
|
|
223
|
+
};
|
|
224
|
+
type ActionToolFunctions<Tools extends ActionToolBindings> = {
|
|
225
|
+
readonly [Name in keyof Tools]: <Result = JsonValue>(args?: JsonValue) => Promise<Result>;
|
|
226
|
+
};
|
|
227
|
+
export type ActionContext<Capabilities extends ActionCapabilities = ActionCapabilities> = AuthContext & TenantContext & {
|
|
228
|
+
readonly now: number;
|
|
229
|
+
} & (Capabilities extends {
|
|
230
|
+
readonly networkOrigins: readonly string[];
|
|
231
|
+
} ? {
|
|
232
|
+
readonly fetch: (input: string | URL, init?: RequestInit) => Promise<Response>;
|
|
233
|
+
} : {}) & (Capabilities extends {
|
|
234
|
+
readonly secrets: readonly string[];
|
|
235
|
+
} ? {
|
|
236
|
+
readonly secrets: Readonly<Record<Capabilities["secrets"][number], string>>;
|
|
237
|
+
} : {}) & (Capabilities extends {
|
|
238
|
+
readonly tools: infer Tools extends ActionToolBindings;
|
|
239
|
+
} ? {
|
|
240
|
+
readonly tools: ActionToolFunctions<Tools>;
|
|
241
|
+
} : {}) & (Capabilities extends {
|
|
242
|
+
readonly scheduler: true;
|
|
243
|
+
} ? {
|
|
244
|
+
readonly scheduler: Scheduler;
|
|
245
|
+
} : {}) & (Capabilities extends {
|
|
246
|
+
readonly storage: true;
|
|
247
|
+
} ? {
|
|
248
|
+
readonly storage: ActionStorage;
|
|
249
|
+
} : {}) & (Capabilities extends {
|
|
250
|
+
readonly sandbox: SandboxCapability;
|
|
251
|
+
} ? {
|
|
252
|
+
readonly sandbox: ActionSandbox;
|
|
253
|
+
} : {});
|
|
254
|
+
export type Handler<Context, Args, Result> = (context: Context, args: Args) => Result | Promise<Result>;
|
|
255
|
+
export type OfflinePolicy = {
|
|
256
|
+
readonly mode: "forbidden";
|
|
257
|
+
} | {
|
|
258
|
+
readonly mode: "allowed";
|
|
259
|
+
readonly conflict?: "reject" | "expectedVersion" | "merge";
|
|
260
|
+
} | {
|
|
261
|
+
readonly mode: "onlineOnly";
|
|
262
|
+
readonly reason: string;
|
|
263
|
+
};
|
|
264
|
+
export type OptimisticID = string | readonly string[];
|
|
265
|
+
/** Resolve this value from Reducer arguments in the client Local Replica. */
|
|
266
|
+
export type OptimisticArgument = {
|
|
267
|
+
readonly $arg: string | readonly string[];
|
|
268
|
+
};
|
|
269
|
+
export type OptimisticValue = JsonValue | OptimisticArgument | readonly OptimisticValue[] | {
|
|
270
|
+
readonly [key: string]: OptimisticValue;
|
|
271
|
+
};
|
|
272
|
+
export type OptimisticObject = {
|
|
273
|
+
readonly [key: string]: OptimisticValue;
|
|
274
|
+
};
|
|
275
|
+
export type OptimisticEffect = {
|
|
276
|
+
readonly operation: "patch";
|
|
277
|
+
readonly entity: string;
|
|
278
|
+
readonly id: OptimisticID;
|
|
279
|
+
readonly fields: OptimisticObject;
|
|
280
|
+
} | {
|
|
281
|
+
readonly operation: "upsert";
|
|
282
|
+
readonly entity: string;
|
|
283
|
+
readonly id: OptimisticID;
|
|
284
|
+
readonly value: OptimisticObject;
|
|
285
|
+
} | {
|
|
286
|
+
readonly operation: "delete";
|
|
287
|
+
readonly entity: string;
|
|
288
|
+
readonly id: OptimisticID;
|
|
289
|
+
};
|
|
290
|
+
export type OptimisticTransaction = {
|
|
291
|
+
readonly effects: readonly OptimisticEffect[];
|
|
292
|
+
readonly expectedRevision?: number;
|
|
293
|
+
};
|
|
294
|
+
export type QueryOptions<Args, Result> = {
|
|
295
|
+
readonly args?: PortableSchema;
|
|
296
|
+
readonly result?: PortableSchema;
|
|
297
|
+
readonly delivery?: "oneShot" | "live" | "replica";
|
|
298
|
+
readonly liveQueryPlan?: LiveQueryPlan;
|
|
299
|
+
readonly replica?: ReplicaCollectionDefinition;
|
|
300
|
+
/** Internal Queries are callable only through a declared Action tool. */
|
|
301
|
+
readonly internal?: boolean;
|
|
302
|
+
readonly run?: Handler<QueryContext, Args, Result>;
|
|
303
|
+
};
|
|
304
|
+
/** Declarative contract for a bounded, locally materialized query collection. */
|
|
305
|
+
export type ReplicaCollectionDefinition = {
|
|
306
|
+
readonly table: string;
|
|
307
|
+
readonly key: string;
|
|
308
|
+
readonly columns: readonly string[];
|
|
309
|
+
readonly equalFilters?: Readonly<Record<string, string>>;
|
|
310
|
+
readonly excludeWhenSet?: readonly string[];
|
|
311
|
+
readonly visibilityTables?: readonly string[];
|
|
312
|
+
/** Assigned by the runtime; module authors do not set this. */
|
|
313
|
+
readonly visibilityPlanHash?: string;
|
|
314
|
+
readonly orderBy?: string;
|
|
315
|
+
readonly orderDirection?: "asc" | "desc";
|
|
316
|
+
/** `eager` is complete at initial delivery; `progressive` may fill incrementally. */
|
|
317
|
+
readonly mode?: "eager" | "progressive";
|
|
318
|
+
readonly maxRows?: number;
|
|
319
|
+
readonly maxBytes?: number;
|
|
320
|
+
readonly retentionMs?: number;
|
|
321
|
+
};
|
|
322
|
+
export type ReplicaCollectionOptions<Args, Result> = Omit<QueryOptions<Args, Result>, "delivery" | "replica"> & {
|
|
323
|
+
readonly replica: ReplicaCollectionDefinition;
|
|
324
|
+
};
|
|
325
|
+
export type ReducerOptions<Args, Result> = {
|
|
326
|
+
readonly args?: PortableSchema;
|
|
327
|
+
readonly result?: PortableSchema;
|
|
328
|
+
readonly offline: OfflinePolicy;
|
|
329
|
+
/** Set false for reducers that are not invoked directly by an interactive client. */
|
|
330
|
+
readonly interactive?: boolean;
|
|
331
|
+
readonly optimistic?: OptimisticTransaction;
|
|
332
|
+
/** Required exception for a public interactive reducer that cannot predict a safe local transaction. */
|
|
333
|
+
readonly nonOptimisticReason?: string;
|
|
334
|
+
readonly internal?: boolean;
|
|
335
|
+
readonly run?: Handler<ReducerContext, Args, Result>;
|
|
336
|
+
};
|
|
337
|
+
export type InternalReducerOptions<Args, Result> = Omit<ReducerOptions<Args, Result>, "offline" | "interactive" | "internal"> & {
|
|
338
|
+
readonly offline?: OfflinePolicy;
|
|
339
|
+
};
|
|
340
|
+
export type ActionOptions<Args, Result, Capabilities extends ActionCapabilities = ActionCapabilities> = {
|
|
341
|
+
/** Optional explicit public path used by static module artifact extraction. */
|
|
342
|
+
readonly name?: string;
|
|
343
|
+
readonly args?: PortableSchema;
|
|
344
|
+
readonly result?: PortableSchema;
|
|
345
|
+
/** Agent Actions are disabled unless the runtime operator explicitly enables them. */
|
|
346
|
+
readonly profile?: "standard" | "agent";
|
|
347
|
+
readonly capabilities?: Capabilities;
|
|
348
|
+
readonly run?: Handler<ActionContext<Capabilities>, Args, Result>;
|
|
349
|
+
};
|
|
350
|
+
export type LiveQueryValue = {
|
|
351
|
+
readonly argument?: string;
|
|
352
|
+
readonly literal?: JsonValue;
|
|
353
|
+
};
|
|
354
|
+
export type FilterOperator = "contains" | "notContains" | "equals" | "notEquals" | "startsWith" | "endsWith" | "empty" | "notEmpty" | "oneOf" | "lessThan" | "lessThanOrEqual" | "greaterThan" | "greaterThanOrEqual" | "inRange";
|
|
355
|
+
export type LiveQueryExpression = {
|
|
356
|
+
readonly operator: "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "range" | "in" | "contains" | "containsInsensitive" | "and" | "or" | "not" | "server";
|
|
357
|
+
readonly column?: string;
|
|
358
|
+
readonly value?: LiveQueryValue;
|
|
359
|
+
readonly valueTo?: LiveQueryValue;
|
|
360
|
+
readonly children?: readonly LiveQueryExpression[];
|
|
361
|
+
};
|
|
362
|
+
export type LiveQueryPlan = {
|
|
363
|
+
readonly table: string;
|
|
364
|
+
readonly key: string;
|
|
365
|
+
readonly columns?: readonly string[];
|
|
366
|
+
readonly resultPath?: readonly string[];
|
|
367
|
+
readonly where?: LiveQueryExpression;
|
|
368
|
+
readonly search?: {
|
|
369
|
+
readonly argument: string;
|
|
370
|
+
readonly columns: readonly string[];
|
|
371
|
+
};
|
|
372
|
+
readonly filters?: {
|
|
373
|
+
readonly argument: string;
|
|
374
|
+
readonly allowedColumns: readonly string[];
|
|
375
|
+
readonly allowedOperators: readonly FilterOperator[];
|
|
376
|
+
};
|
|
377
|
+
readonly sort?: {
|
|
378
|
+
readonly columnArgument?: string;
|
|
379
|
+
readonly directionArgument?: string;
|
|
380
|
+
readonly defaultColumn: string;
|
|
381
|
+
readonly defaultDirection: "asc" | "desc";
|
|
382
|
+
readonly allowedColumns: readonly string[];
|
|
383
|
+
};
|
|
384
|
+
readonly window?: {
|
|
385
|
+
readonly offsetArgument: string;
|
|
386
|
+
readonly limitArgument: string;
|
|
387
|
+
readonly defaultLimit: number;
|
|
388
|
+
readonly maxLimit: number;
|
|
389
|
+
/** Request exact total-count metadata alongside a shaped result window. */
|
|
390
|
+
readonly count?: "exact";
|
|
391
|
+
};
|
|
392
|
+
readonly serverOnly?: boolean;
|
|
393
|
+
};
|
|
394
|
+
export type VisibilityOperator = "public" | "permission" | "role" | "eqContext" | "inSet" | "and" | "or" | "not";
|
|
395
|
+
export type VisibilityContextKey = "account.id" | "member.id" | "tenant.id";
|
|
396
|
+
export type VisibilityPlan = {
|
|
397
|
+
readonly table: string;
|
|
398
|
+
readonly key: string;
|
|
399
|
+
readonly sets: Readonly<Record<string, VisibilitySet>>;
|
|
400
|
+
readonly where: VisibilityExpression;
|
|
401
|
+
};
|
|
402
|
+
export type VisibilitySet = {
|
|
403
|
+
readonly table: string;
|
|
404
|
+
readonly select: string;
|
|
405
|
+
readonly joins: readonly VisibilityJoin[];
|
|
406
|
+
readonly where: readonly VisibilityConstraint[];
|
|
407
|
+
};
|
|
408
|
+
export type VisibilityJoin = {
|
|
409
|
+
readonly table: string;
|
|
410
|
+
readonly leftColumn: string;
|
|
411
|
+
readonly rightColumn: string;
|
|
412
|
+
};
|
|
413
|
+
export type VisibilityConstraint = {
|
|
414
|
+
readonly table: string;
|
|
415
|
+
readonly column: string;
|
|
416
|
+
readonly context: VisibilityContextKey;
|
|
417
|
+
};
|
|
418
|
+
export type VisibilityExpression = {
|
|
419
|
+
readonly operator: VisibilityOperator;
|
|
420
|
+
readonly column?: string;
|
|
421
|
+
readonly context?: VisibilityContextKey;
|
|
422
|
+
readonly set?: string;
|
|
423
|
+
readonly value?: string;
|
|
424
|
+
readonly children?: readonly VisibilityExpression[];
|
|
425
|
+
};
|
|
426
|
+
export type ModuleFunctionKind = "query" | "reducer" | "action";
|
|
427
|
+
export type CronScope = "project" | "tenant";
|
|
428
|
+
export type CronSchedule = {
|
|
429
|
+
readonly intervalMs: number;
|
|
430
|
+
readonly expression?: never;
|
|
431
|
+
} | {
|
|
432
|
+
readonly expression: string;
|
|
433
|
+
readonly intervalMs?: never;
|
|
434
|
+
};
|
|
435
|
+
export type CronSpec = Readonly<{
|
|
436
|
+
name: string;
|
|
437
|
+
function: string;
|
|
438
|
+
args?: JsonValue;
|
|
439
|
+
scope: CronScope;
|
|
440
|
+
} & CronSchedule>;
|
|
441
|
+
export type CronOptions = Omit<CronSpec, "scope">;
|
|
442
|
+
export type ModuleFunctionManifest = {
|
|
443
|
+
readonly path: string;
|
|
444
|
+
readonly kind: ModuleFunctionKind;
|
|
445
|
+
readonly args?: PortableSchema;
|
|
446
|
+
readonly result?: PortableSchema;
|
|
447
|
+
readonly internal?: boolean;
|
|
448
|
+
readonly delivery?: "oneShot" | "live" | "replica";
|
|
449
|
+
readonly liveQueryPlan?: LiveQueryPlan;
|
|
450
|
+
readonly replica?: ReplicaCollectionDefinition;
|
|
451
|
+
readonly offline?: OfflinePolicy;
|
|
452
|
+
readonly interactive?: boolean;
|
|
453
|
+
readonly optimistic?: OptimisticTransaction;
|
|
454
|
+
readonly nonOptimisticReason?: string;
|
|
455
|
+
readonly actionProfile?: "standard" | "agent";
|
|
456
|
+
readonly actionCapabilities?: ActionCapabilities;
|
|
457
|
+
};
|
|
458
|
+
export type ModuleManifest = {
|
|
459
|
+
readonly format: "gonvex.module.v1";
|
|
460
|
+
readonly name: string;
|
|
461
|
+
readonly version: string;
|
|
462
|
+
readonly language: ModuleLanguage;
|
|
463
|
+
readonly engine: ModuleEngine;
|
|
464
|
+
readonly functions: Readonly<Record<string, ModuleFunctionManifest>>;
|
|
465
|
+
readonly crons?: readonly CronSpec[];
|
|
466
|
+
readonly schema?: PortableSchema;
|
|
467
|
+
readonly artifact?: {
|
|
468
|
+
readonly hash: string;
|
|
469
|
+
readonly mediaType: string;
|
|
470
|
+
readonly entrypoint: string;
|
|
471
|
+
};
|
|
472
|
+
readonly visibility?: Readonly<Record<string, VisibilityPlan>>;
|
|
473
|
+
readonly invitationAcceptanceReducer?: string;
|
|
474
|
+
};
|
|
475
|
+
/** Declare the host-invoked internal Reducer that applies invitation payloads. */
|
|
476
|
+
export declare function invitationAcceptance(reducerPath: string): Readonly<{
|
|
477
|
+
reducer: string;
|
|
478
|
+
}>;
|
|
479
|
+
export type ModuleArtifact = {
|
|
480
|
+
readonly manifest: ModuleManifest;
|
|
481
|
+
readonly bytes: Uint8Array;
|
|
482
|
+
};
|
|
483
|
+
export type ModuleFunctionHandler = Handler<QueryContext, unknown, unknown> | Handler<ReducerContext, unknown, unknown> | Handler<ActionContext, unknown, unknown>;
|
|
484
|
+
/** A manifest entry together with the executable function retained by the host. */
|
|
485
|
+
export type RuntimeFunctionRegistration = {
|
|
486
|
+
readonly path: string;
|
|
487
|
+
readonly kind: ModuleFunctionKind;
|
|
488
|
+
readonly definition: ModuleFunctionManifest;
|
|
489
|
+
readonly handler?: ModuleFunctionHandler;
|
|
490
|
+
};
|
|
491
|
+
export type ModuleRuntimeRegistration = {
|
|
492
|
+
readonly path: string;
|
|
493
|
+
readonly kind: ModuleFunctionKind;
|
|
494
|
+
readonly definition: ModuleFunctionManifest;
|
|
495
|
+
};
|
|
496
|
+
/** Deterministic, handler-free payload consumed by a module host during loading. */
|
|
497
|
+
export type ModuleRuntimeRegistrationPayload = {
|
|
498
|
+
readonly format: "gonvex.module.runtime.v1";
|
|
499
|
+
readonly manifest: ModuleManifest;
|
|
500
|
+
readonly registrations: readonly ModuleRuntimeRegistration[];
|
|
501
|
+
};
|
|
502
|
+
export type QueryInvocation<Args = unknown> = {
|
|
503
|
+
readonly path: string;
|
|
504
|
+
readonly kind: "query";
|
|
505
|
+
readonly context: QueryContext;
|
|
506
|
+
readonly args: Args;
|
|
507
|
+
};
|
|
508
|
+
export type ReducerInvocation<Args = unknown> = {
|
|
509
|
+
readonly path: string;
|
|
510
|
+
readonly kind: "reducer";
|
|
511
|
+
readonly context: ReducerContext;
|
|
512
|
+
readonly args: Args;
|
|
513
|
+
};
|
|
514
|
+
export type ActionInvocation<Args = unknown> = {
|
|
515
|
+
readonly path: string;
|
|
516
|
+
readonly kind: "action";
|
|
517
|
+
readonly context: ActionContext;
|
|
518
|
+
readonly args: Args;
|
|
519
|
+
};
|
|
520
|
+
export type ModuleInvocation<Args = unknown> = QueryInvocation<Args> | ReducerInvocation<Args> | ActionInvocation<Args>;
|
|
521
|
+
type AnyFunctionOptions = QueryOptions<unknown, unknown> | ReducerOptions<unknown, unknown> | ActionOptions<unknown, unknown>;
|
|
522
|
+
/** Declare and validate one source table's language-neutral visibility plan. */
|
|
523
|
+
export declare function visibility(options: VisibilityPlan): VisibilityPlan;
|
|
524
|
+
/** JSON serialization with recursively sorted object keys for reproducible artifacts. */
|
|
525
|
+
export declare const stableJsonStringify: (value: unknown, space?: number) => string;
|
|
526
|
+
/** Declare a project-wide recurring Reducer or Action. */
|
|
527
|
+
export declare function cron(options: CronOptions): CronSpec;
|
|
528
|
+
/** Declare a recurring Reducer or Action once for every tenant. */
|
|
529
|
+
export declare function tenantCron(options: CronOptions): CronSpec;
|
|
530
|
+
export declare class ModuleManifestCollector {
|
|
531
|
+
private readonly entries;
|
|
532
|
+
private readonly visibilityEntries;
|
|
533
|
+
private readonly cronEntries;
|
|
534
|
+
private readonly metadata;
|
|
535
|
+
constructor(metadata: Omit<ModuleManifest, "functions">);
|
|
536
|
+
register(path: string, entry: Omit<ModuleFunctionManifest, "path">): ModuleFunctionManifest;
|
|
537
|
+
registerVisibility(options: VisibilityPlan): VisibilityPlan;
|
|
538
|
+
registerCron(options: CronSpec): CronSpec;
|
|
539
|
+
manifest(): ModuleManifest;
|
|
540
|
+
serialize(space?: number): string;
|
|
541
|
+
}
|
|
542
|
+
export type RegisteredFunction<Args, Result> = {
|
|
543
|
+
readonly path: string;
|
|
544
|
+
readonly kind: ModuleFunctionKind;
|
|
545
|
+
readonly definition: ModuleFunctionManifest;
|
|
546
|
+
readonly handler?: Handler<QueryContext, Args, Result> | Handler<ReducerContext, Args, Result> | Handler<ActionContext, Args, Result>;
|
|
547
|
+
};
|
|
548
|
+
/**
|
|
549
|
+
* Executable definition returned by the top-level declaration helpers.
|
|
550
|
+
*
|
|
551
|
+
* The module loader uses the exported binding itself as the declaration and
|
|
552
|
+
* invokes `handler` when a V8 request arrives. `options` retains the
|
|
553
|
+
* declarative input so hosts can project it into a manifest without needing
|
|
554
|
+
* to evaluate TypeScript source again.
|
|
555
|
+
*/
|
|
556
|
+
export type ModuleDefinition<Kind extends ModuleFunctionKind, Options> = {
|
|
557
|
+
readonly kind: Kind;
|
|
558
|
+
readonly internal?: boolean;
|
|
559
|
+
readonly delivery?: "oneShot" | "live" | "replica";
|
|
560
|
+
readonly liveQueryPlan?: LiveQueryPlan;
|
|
561
|
+
readonly replica?: ReplicaCollectionDefinition;
|
|
562
|
+
readonly options: Readonly<Options>;
|
|
563
|
+
readonly handler?: Options extends {
|
|
564
|
+
readonly run?: infer HandlerType;
|
|
565
|
+
} ? HandlerType : never;
|
|
566
|
+
};
|
|
567
|
+
export type QueryDefinition<Args, Result> = ModuleDefinition<"query", QueryOptions<Args, Result>>;
|
|
568
|
+
export type ReducerDefinition<Args, Result> = ModuleDefinition<"reducer", ReducerOptions<Args, Result>>;
|
|
569
|
+
export type ActionDefinition<Args, Result, Capabilities extends ActionCapabilities = ActionCapabilities> = ModuleDefinition<"action", ActionOptions<Args, Result, Capabilities>>;
|
|
570
|
+
/** Declare an executable one-shot, live, or replica query export. */
|
|
571
|
+
export declare function query<Args = JsonValue, Result = JsonValue>(options?: QueryOptions<Args, Result>): QueryDefinition<Args, Result>;
|
|
572
|
+
/** Declare a one-shot Query that is unreachable from clients and may be bound to an Action tool. */
|
|
573
|
+
export declare function internalQuery<Args = JsonValue, Result = JsonValue>(options?: Omit<QueryOptions<Args, Result>, "internal" | "delivery" | "replica">): QueryDefinition<Args, Result>;
|
|
574
|
+
/** Declare an executable live query export with a structured live plan. */
|
|
575
|
+
export declare function liveQuery<Args = JsonValue, Result = JsonValue>(options?: Omit<QueryOptions<Args, Result>, "delivery">): QueryDefinition<Args, Result>;
|
|
576
|
+
/** Declare an executable bounded replica collection export. */
|
|
577
|
+
export declare function replicaCollection<Args = JsonValue, Result = JsonValue>(options: ReplicaCollectionOptions<Args, Result>): QueryDefinition<Args, Result>;
|
|
578
|
+
/** Declare an executable public reducer export. */
|
|
579
|
+
export declare function reducer<Args = JsonValue, Result = JsonValue>(options: ReducerOptions<Args, Result>): ReducerDefinition<Args, Result>;
|
|
580
|
+
/** Declare an executable non-interactive internal reducer export. */
|
|
581
|
+
export declare function internalReducer<Args = JsonValue, Result = JsonValue>(options: InternalReducerOptions<Args, Result>): ReducerDefinition<Args, Result>;
|
|
582
|
+
/** Declare an executable action export. */
|
|
583
|
+
export declare function action<Args = JsonValue, Result = JsonValue, const Capabilities extends ActionCapabilities = ActionCapabilities>(options?: ActionOptions<Args, Result, Capabilities>): ActionDefinition<Args, Result, Capabilities>;
|
|
584
|
+
export declare class ModuleBuilder {
|
|
585
|
+
readonly manifestCollector: ModuleManifestCollector;
|
|
586
|
+
private readonly runtimeEntries;
|
|
587
|
+
constructor(metadata: {
|
|
588
|
+
name: string;
|
|
589
|
+
version: string;
|
|
590
|
+
language?: ModuleLanguage;
|
|
591
|
+
engine?: ModuleEngine;
|
|
592
|
+
schema?: PortableSchema;
|
|
593
|
+
artifact?: ModuleManifest["artifact"];
|
|
594
|
+
visibility?: Readonly<Record<string, VisibilityPlan>>;
|
|
595
|
+
crons?: readonly CronSpec[];
|
|
596
|
+
});
|
|
597
|
+
visibility(options: VisibilityPlan): VisibilityPlan;
|
|
598
|
+
cron(options: CronOptions): CronSpec;
|
|
599
|
+
tenantCron(options: CronOptions): CronSpec;
|
|
600
|
+
query<Args = JsonValue, Result = JsonValue>(path: string, options?: QueryOptions<Args, Result>): RegisteredFunction<Args, Result>;
|
|
601
|
+
/** Register a Query delivered as a live, structured query stream. */
|
|
602
|
+
liveQuery<Args = JsonValue, Result = JsonValue>(path: string, options?: Omit<QueryOptions<Args, Result>, "delivery">): RegisteredFunction<Args, Result>;
|
|
603
|
+
/** Register a Query delivered as a bounded local replica collection. */
|
|
604
|
+
replicaCollection<Args = JsonValue, Result = JsonValue>(path: string, options: ReplicaCollectionOptions<Args, Result>): RegisteredFunction<Args, Result>;
|
|
605
|
+
reducer<Args = JsonValue, Result = JsonValue>(path: string, options: ReducerOptions<Args, Result>): RegisteredFunction<Args, Result>;
|
|
606
|
+
/** Register a non-public Reducer while retaining kind `reducer` in the manifest. */
|
|
607
|
+
internalReducer<Args = JsonValue, Result = JsonValue>(path: string, options: InternalReducerOptions<Args, Result>): RegisteredFunction<Args, Result>;
|
|
608
|
+
action<Args = JsonValue, Result = JsonValue, const Capabilities extends ActionCapabilities = ActionCapabilities>(path: string, options?: ActionOptions<Args, Result, Capabilities>): RegisteredFunction<Args, Result>;
|
|
609
|
+
manifest(): ModuleManifest;
|
|
610
|
+
serialize(space?: number): string;
|
|
611
|
+
/** Executable registrations sorted by path for deterministic host loading. */
|
|
612
|
+
runtimeRegistrations(): readonly RuntimeFunctionRegistration[];
|
|
613
|
+
runtimePayload(): ModuleRuntimeRegistrationPayload;
|
|
614
|
+
serializeRuntimePayload(space?: number): string;
|
|
615
|
+
createRuntimeRegistry(): ModuleRuntimeRegistry;
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Host-side executable registry. It is deliberately unaware of V8,
|
|
619
|
+
* Postgres, or network transport; an engine supplies the capability-bearing
|
|
620
|
+
* context and this registry only selects and invokes the registered handler.
|
|
621
|
+
*/
|
|
622
|
+
export declare class ModuleRuntimeRegistry {
|
|
623
|
+
private readonly entries;
|
|
624
|
+
private readonly baseManifest;
|
|
625
|
+
constructor(source: ModuleBuilder);
|
|
626
|
+
register(registration: RuntimeFunctionRegistration): void;
|
|
627
|
+
has(path: string, kind?: ModuleFunctionKind): boolean;
|
|
628
|
+
registration(path: string): RuntimeFunctionRegistration | undefined;
|
|
629
|
+
registrations(): readonly RuntimeFunctionRegistration[];
|
|
630
|
+
manifest(): ModuleManifest;
|
|
631
|
+
registrationPayload(): ModuleRuntimeRegistrationPayload;
|
|
632
|
+
serializeRegistrationPayload(space?: number): string;
|
|
633
|
+
query<Args, Result>(path: string, context: QueryContext, args: Args): Promise<Result>;
|
|
634
|
+
reducer<Args, Result>(path: string, context: ReducerContext, args: Args): Promise<Result>;
|
|
635
|
+
action<Args, Result>(path: string, context: ActionContext, args: Args): Promise<Result>;
|
|
636
|
+
dispatch<Args = unknown>(invocation: ModuleInvocation<Args>): Promise<unknown>;
|
|
637
|
+
}
|
|
638
|
+
export declare function createModule(metadata: ConstructorParameters<typeof ModuleBuilder>[0]): ModuleBuilder;
|
|
639
|
+
/** Type-only helper for APIs that accept any builder options. */
|
|
640
|
+
export type ModuleFunctionOptions = AnyFunctionOptions;
|
|
641
|
+
export {};
|