@live-state/sync 0.0.6 → 0.0.7-canary-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-LSAVBBUS.js +1 -0
- package/dist/chunk-NKM6VWL7.js +1 -0
- package/dist/chunk-RSSRYEM3.js +1 -0
- package/dist/client.d.ts +2 -2
- package/dist/client.js +1 -1
- package/dist/fetch-client.d.ts +2 -2
- package/dist/fetch-client.js +1 -1
- package/dist/index-CLkafi56.d.ts +1016 -0
- package/dist/index-hO1iQ-VU.d.cts +608 -0
- package/dist/index-hO1iQ-VU.d.ts +608 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/optimistic-client.d.ts +3 -0
- package/dist/optimistic-client.js +1 -0
- package/dist/server.cjs +10 -4
- package/dist/server.d.cts +262 -86
- package/dist/server.d.ts +262 -86
- package/dist/server.js +8 -2
- package/package.json +6 -1
- package/dist/chunk-AHF6GNMI.js +0 -1
- package/dist/chunk-IT5UC7TA.js +0 -1
- package/dist/index-BtsKDfTE.d.cts +0 -282
- package/dist/index-BtsKDfTE.d.ts +0 -282
- package/dist/index-P-s1Yf1S.d.ts +0 -520
package/dist/server.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { L as LiveObjectAny, W as WhereClause, S as Simplify,
|
|
2
|
+
import { L as LiveObjectAny, I as IncludeClause, a as InferLiveObject, W as WhereClause, S as Simplify, b as InferInsert, c as InferUpdate, M as MaterializedLiveType, d as Schema, e as LiveCollectionAny, f as InferLiveCollection, g as InferLiveObjectWithRelationalIds, h as Logger, i as LogLevel } from './index-hO1iQ-VU.cjs';
|
|
3
3
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
4
4
|
import { PostgresPool, Kysely } from 'kysely';
|
|
5
5
|
import { Application } from 'express-ws';
|
|
@@ -34,17 +34,191 @@ declare const defaultMutationSchema: z.ZodObject<{
|
|
|
34
34
|
timestamp: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
35
35
|
}, z.core.$strip>>;
|
|
36
36
|
}, z.core.$strip>>;
|
|
37
|
+
meta: z.ZodOptional<z.ZodObject<{
|
|
38
|
+
timestamp: z.ZodOptional<z.ZodString>;
|
|
39
|
+
}, z.core.$strip>>;
|
|
37
40
|
}, z.core.$strip>;
|
|
38
41
|
type DefaultMutation = Omit<z.infer<typeof defaultMutationSchema>, "resourceId"> & {
|
|
39
42
|
resourceId: string;
|
|
40
43
|
};
|
|
41
44
|
|
|
45
|
+
type ConditionalPromise<T, P extends boolean> = P extends true ? Promise<T> : T;
|
|
42
46
|
type PromiseOrSync<T> = T | Promise<T>;
|
|
43
47
|
|
|
48
|
+
/** biome-ignore-all lint/suspicious/noExplicitAny: false positive */
|
|
49
|
+
|
|
50
|
+
declare abstract class Storage implements DataSource {
|
|
51
|
+
/**
|
|
52
|
+
* @deprecated Use db.[collection].one(id).get() instead
|
|
53
|
+
*/
|
|
54
|
+
abstract findOne<T extends LiveObjectAny, TInclude extends IncludeClause<T> | undefined = undefined>(resource: T, id: string, options?: {
|
|
55
|
+
include?: TInclude;
|
|
56
|
+
}): Promise<InferLiveObject<T, TInclude> | undefined>;
|
|
57
|
+
/**
|
|
58
|
+
* @deprecated Use db.[collection].where({...}).get() instead
|
|
59
|
+
*/
|
|
60
|
+
abstract find<T extends LiveObjectAny, TInclude extends IncludeClause<T> | undefined = undefined>(resource: T, options?: {
|
|
61
|
+
where?: WhereClause<T>;
|
|
62
|
+
include?: TInclude;
|
|
63
|
+
limit?: number;
|
|
64
|
+
sort?: {
|
|
65
|
+
key: string;
|
|
66
|
+
direction: "asc" | "desc";
|
|
67
|
+
}[];
|
|
68
|
+
}): Promise<InferLiveObject<T, TInclude>[]>;
|
|
69
|
+
/**
|
|
70
|
+
* @deprecated Use db.[collection].insert({...}) instead
|
|
71
|
+
*/
|
|
72
|
+
insert<T extends LiveObjectAny>(resource: T, value: Simplify<InferInsert<T>>): Promise<InferLiveObject<T>>;
|
|
73
|
+
/**
|
|
74
|
+
* @deprecated Use db.[collection].update(id, {...}) instead
|
|
75
|
+
*/
|
|
76
|
+
update<T extends LiveObjectAny>(resource: T, resourceId: string, value: InferUpdate<T>): Promise<Partial<InferLiveObject<T>>>;
|
|
77
|
+
abstract transaction<T>(fn: (opts: {
|
|
78
|
+
trx: Storage;
|
|
79
|
+
commit: () => Promise<void>;
|
|
80
|
+
rollback: () => Promise<void>;
|
|
81
|
+
}) => Promise<T>): Promise<T>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** biome-ignore-all lint/suspicious/noExplicitAny: false positive */
|
|
85
|
+
|
|
86
|
+
declare class Batcher {
|
|
87
|
+
private storage;
|
|
88
|
+
private queue;
|
|
89
|
+
private scheduled;
|
|
90
|
+
constructor(storage: Storage);
|
|
91
|
+
rawFind<T extends LiveObjectAny>({ resource, commonWhere, uniqueWhere, ...rest }: {
|
|
92
|
+
resource: string;
|
|
93
|
+
commonWhere?: Record<string, any>;
|
|
94
|
+
uniqueWhere?: Record<string, any>;
|
|
95
|
+
include?: Record<string, any>;
|
|
96
|
+
limit?: number;
|
|
97
|
+
sort?: {
|
|
98
|
+
key: string;
|
|
99
|
+
direction: "asc" | "desc";
|
|
100
|
+
}[];
|
|
101
|
+
}): Promise<MaterializedLiveType<T>[]>;
|
|
102
|
+
private getBatchKey;
|
|
103
|
+
private processBatch;
|
|
104
|
+
private executeBatchedRequests;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
interface DataSource {
|
|
108
|
+
get(query: RawQueryRequest, extra?: {
|
|
109
|
+
context?: any;
|
|
110
|
+
batcher?: Batcher;
|
|
111
|
+
}): PromiseOrSync<any[]>;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** biome-ignore-all lint/complexity/noBannedTypes: <explanation> */
|
|
115
|
+
|
|
116
|
+
type InferQueryResult<TCollection extends LiveObjectAny, TInclude extends IncludeClause<TCollection>, TSingle extends boolean = false> = TSingle extends true ? Simplify<InferLiveObject<TCollection, TInclude>> | undefined : Simplify<InferLiveObject<TCollection, TInclude>>[];
|
|
117
|
+
declare class QueryBuilder<TCollection extends LiveObjectAny, TInclude extends IncludeClause<TCollection> = {}, TSingle extends boolean = false, TShouldAwait extends boolean = false> {
|
|
118
|
+
private _collection;
|
|
119
|
+
private _client;
|
|
120
|
+
private _where;
|
|
121
|
+
private _include;
|
|
122
|
+
private _limit?;
|
|
123
|
+
private _single?;
|
|
124
|
+
private _sort?;
|
|
125
|
+
private _shouldAwait?;
|
|
126
|
+
private constructor();
|
|
127
|
+
where(where: WhereClause<TCollection>): QueryBuilder<TCollection, TInclude, TSingle, TShouldAwait>;
|
|
128
|
+
include<TNewInclude extends IncludeClause<TCollection>>(include: TNewInclude): QueryBuilder<TCollection, TInclude & TNewInclude, TSingle, TShouldAwait>;
|
|
129
|
+
limit(limit: number): QueryBuilder<TCollection, TInclude, TSingle, TShouldAwait>;
|
|
130
|
+
one(id: string): QueryBuilder<TCollection, TInclude, true, TShouldAwait>;
|
|
131
|
+
first(where?: WhereClause<TCollection>): QueryBuilder<TCollection, TInclude, true, TShouldAwait>;
|
|
132
|
+
orderBy(key: keyof TCollection["fields"], direction?: "asc" | "desc"): QueryBuilder<TCollection, TInclude, TSingle, TShouldAwait>;
|
|
133
|
+
toJSON(): {
|
|
134
|
+
resource: string;
|
|
135
|
+
where: WhereClause<TCollection>;
|
|
136
|
+
include: TInclude;
|
|
137
|
+
limit: number | undefined;
|
|
138
|
+
sort: {
|
|
139
|
+
key: string;
|
|
140
|
+
direction: "asc" | "desc";
|
|
141
|
+
}[] | undefined;
|
|
142
|
+
};
|
|
143
|
+
buildQueryRequest(): RawQueryRequest;
|
|
144
|
+
get(): ConditionalPromise<InferQueryResult<TCollection, TInclude, TSingle>, TShouldAwait>;
|
|
145
|
+
subscribe(callback: (value: InferQueryResult<TCollection, TInclude, TSingle>) => void): () => void;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** biome-ignore-all lint/suspicious/noExplicitAny: false positive */
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* A QueryBuilder with added insert() and update() mutation methods for server-side use.
|
|
152
|
+
*/
|
|
153
|
+
type ServerCollection<T extends LiveCollectionAny> = QueryBuilder<T, {}, false, true> & {
|
|
154
|
+
/**
|
|
155
|
+
* Insert a new record into this collection.
|
|
156
|
+
*/
|
|
157
|
+
insert(value: Simplify<InferInsert<T>>): Promise<InferLiveCollection<T>>;
|
|
158
|
+
/**
|
|
159
|
+
* Update an existing record in this collection.
|
|
160
|
+
*/
|
|
161
|
+
update(id: string, value: InferUpdate<T>): Promise<Partial<InferLiveCollection<T>>>;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Server database interface that provides collection properties and deprecated methods.
|
|
165
|
+
* Each collection property (e.g., db.users, db.posts) is a ServerCollection with
|
|
166
|
+
* QueryBuilder methods plus insert/update mutations.
|
|
167
|
+
*/
|
|
168
|
+
type ServerDB<TSchema extends Schema<any>> = {
|
|
169
|
+
[K in keyof TSchema]: ServerCollection<TSchema[K]>;
|
|
170
|
+
} & {
|
|
171
|
+
/**
|
|
172
|
+
* @deprecated Use db.[collection].one(id).get() instead
|
|
173
|
+
*/
|
|
174
|
+
findOne: Storage['findOne'];
|
|
175
|
+
/**
|
|
176
|
+
* @deprecated Use db.[collection].where({...}).get() instead
|
|
177
|
+
*/
|
|
178
|
+
find: Storage['find'];
|
|
179
|
+
/**
|
|
180
|
+
* @deprecated Use db.[collection].insert({...}) instead
|
|
181
|
+
*/
|
|
182
|
+
insert: Storage['insert'];
|
|
183
|
+
/**
|
|
184
|
+
* @deprecated Use db.[collection].update(id, {...}) instead
|
|
185
|
+
*/
|
|
186
|
+
update: Storage['update'];
|
|
187
|
+
/**
|
|
188
|
+
* Execute operations within a transaction.
|
|
189
|
+
* The transaction wrapper provides a ServerDB interface for the transaction.
|
|
190
|
+
*/
|
|
191
|
+
transaction: <T>(fn: (opts: {
|
|
192
|
+
trx: ServerDB<TSchema>;
|
|
193
|
+
commit: () => Promise<void>;
|
|
194
|
+
rollback: () => Promise<void>;
|
|
195
|
+
}) => Promise<T>) => Promise<T>;
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* Creates a ServerDB proxy that wraps a Storage instance with QueryBuilder-based syntax.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```typescript
|
|
202
|
+
* const db = createServerDB(storage, schema);
|
|
203
|
+
*
|
|
204
|
+
* // New syntax
|
|
205
|
+
* const user = await db.users.one(userId).get();
|
|
206
|
+
* const posts = await db.posts.where({ authorId: userId }).limit(10).get();
|
|
207
|
+
* await db.users.insert({ id: '...', name: '...' });
|
|
208
|
+
*
|
|
209
|
+
* // Deprecated syntax (still works)
|
|
210
|
+
* const user = await db.findOne(schema.users, userId);
|
|
211
|
+
* const posts = await db.find(schema.posts, { where: { authorId: userId }, limit: 10 });
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
declare function createServerDB<TSchema extends Schema<any>>(storage: Storage, schema: TSchema): ServerDB<TSchema>;
|
|
215
|
+
|
|
44
216
|
/** biome-ignore-all lint/suspicious/noExplicitAny: false positive */
|
|
45
217
|
/** biome-ignore-all lint/style/noNonNullAssertion: false positive */
|
|
46
218
|
|
|
47
|
-
type
|
|
219
|
+
type AnyProcedureRoute = ProcedureRoute<Middleware<any>, Record<string, any>, Record<string, any>, any>;
|
|
220
|
+
type AnyRouteOrProcedure = AnyRoute | AnyProcedureRoute;
|
|
221
|
+
type RouteRecord = Record<string, AnyRouteOrProcedure>;
|
|
48
222
|
declare class Router<TRoutes extends RouteRecord> {
|
|
49
223
|
readonly routes: TRoutes;
|
|
50
224
|
readonly hooksRegistry: Map<string, Hooks<any>>;
|
|
@@ -54,7 +228,7 @@ declare class Router<TRoutes extends RouteRecord> {
|
|
|
54
228
|
}): Router<TRoutes>;
|
|
55
229
|
getHooks(resourceName: string): Hooks<any> | undefined;
|
|
56
230
|
}
|
|
57
|
-
declare const router: <TSchema extends Schema<any>, TRoutes extends Record<keyof TSchema, Route<any, any, any>>>(opts: {
|
|
231
|
+
declare const router: <TSchema extends Schema<any>, TRoutes extends Record<keyof TSchema, Route<any, any, any, any, any>> & Record<string, Route<any, any, any, any, any> | ProcedureRoute<any, any, any, any>>>(opts: {
|
|
58
232
|
schema: TSchema;
|
|
59
233
|
routes: TRoutes;
|
|
60
234
|
}) => Router<TRoutes>;
|
|
@@ -68,23 +242,53 @@ type MutationResult<TShape extends LiveObjectAny> = {
|
|
|
68
242
|
acceptedValues: Record<string, any> | null;
|
|
69
243
|
};
|
|
70
244
|
type Mutation<TInputValidator extends StandardSchemaV1<any, any> | never, TOutput> = {
|
|
245
|
+
_type: "mutation";
|
|
71
246
|
inputValidator: TInputValidator;
|
|
72
247
|
handler: (opts: {
|
|
73
248
|
req: MutationRequest<TInputValidator extends StandardSchemaV1<any, any> ? StandardSchemaV1.InferOutput<TInputValidator> : undefined>;
|
|
74
|
-
db:
|
|
249
|
+
db: ServerDB<any>;
|
|
250
|
+
}) => TOutput;
|
|
251
|
+
};
|
|
252
|
+
interface QueryProcedureRequest<TInput = any> extends BaseRequest {
|
|
253
|
+
type: "CUSTOM_QUERY";
|
|
254
|
+
input: TInput;
|
|
255
|
+
resource: string;
|
|
256
|
+
procedure: string;
|
|
257
|
+
}
|
|
258
|
+
type Query<TInputValidator extends StandardSchemaV1<any, any> | never, TOutput> = {
|
|
259
|
+
_type: "query";
|
|
260
|
+
inputValidator: TInputValidator;
|
|
261
|
+
handler: (opts: {
|
|
262
|
+
req: QueryProcedureRequest<TInputValidator extends StandardSchemaV1<any, any> ? StandardSchemaV1.InferOutput<TInputValidator> : undefined>;
|
|
263
|
+
db: ServerDB<any>;
|
|
75
264
|
}) => TOutput;
|
|
76
265
|
};
|
|
77
|
-
type
|
|
266
|
+
type Procedure<TInputValidator extends StandardSchemaV1<any, any> | never, TOutput> = Mutation<TInputValidator, TOutput> | Query<TInputValidator, TOutput>;
|
|
267
|
+
type QueryCreator<TSchema extends Schema<any> = Schema<any>> = {
|
|
268
|
+
(): {
|
|
269
|
+
handler: <TOutput>(handler: (opts: {
|
|
270
|
+
req: QueryProcedureRequest<undefined>;
|
|
271
|
+
db: ServerDB<TSchema>;
|
|
272
|
+
}) => TOutput) => Query<StandardSchemaV1<any, undefined>, TOutput>;
|
|
273
|
+
};
|
|
274
|
+
<TInputValidator extends StandardSchemaV1<any, any>>(validator: TInputValidator): {
|
|
275
|
+
handler: <THandler extends (opts: {
|
|
276
|
+
req: QueryProcedureRequest<StandardSchemaV1.InferOutput<TInputValidator>>;
|
|
277
|
+
db: ServerDB<TSchema>;
|
|
278
|
+
}) => any>(handler: THandler) => Query<TInputValidator, ReturnType<THandler>>;
|
|
279
|
+
};
|
|
280
|
+
};
|
|
281
|
+
type MutationCreator<TSchema extends Schema<any> = Schema<any>> = {
|
|
78
282
|
(): {
|
|
79
283
|
handler: <TOutput>(handler: (opts: {
|
|
80
284
|
req: MutationRequest<undefined>;
|
|
81
|
-
db:
|
|
285
|
+
db: ServerDB<TSchema>;
|
|
82
286
|
}) => TOutput) => Mutation<StandardSchemaV1<any, undefined>, TOutput>;
|
|
83
287
|
};
|
|
84
288
|
<TInputValidator extends StandardSchemaV1<any, any>>(validator: TInputValidator): {
|
|
85
289
|
handler: <THandler extends (opts: {
|
|
86
290
|
req: MutationRequest<StandardSchemaV1.InferOutput<TInputValidator>>;
|
|
87
|
-
db:
|
|
291
|
+
db: ServerDB<TSchema>;
|
|
88
292
|
}) => any>(handler: THandler) => Mutation<TInputValidator, ReturnType<THandler>>;
|
|
89
293
|
};
|
|
90
294
|
};
|
|
@@ -104,23 +308,23 @@ type Authorization<TShape extends LiveObjectAny> = {
|
|
|
104
308
|
postMutation?: MutationAuthorizationHandler<TShape>;
|
|
105
309
|
};
|
|
106
310
|
};
|
|
107
|
-
type BeforeInsertHook<TShape extends LiveObjectAny> = (opts: {
|
|
311
|
+
type BeforeInsertHook<TShape extends LiveObjectAny, TSchema extends Schema<any> = Schema<any>> = (opts: {
|
|
108
312
|
ctx?: Record<string, any>;
|
|
109
313
|
value: Simplify<InferLiveObjectWithRelationalIds<TShape>> & {
|
|
110
314
|
id: string;
|
|
111
315
|
};
|
|
112
316
|
rawValue: MaterializedLiveType<TShape>;
|
|
113
|
-
db:
|
|
317
|
+
db: ServerDB<TSchema>;
|
|
114
318
|
}) => Promise<MaterializedLiveType<TShape> | void> | MaterializedLiveType<TShape> | void;
|
|
115
|
-
type AfterInsertHook<TShape extends LiveObjectAny> = (opts: {
|
|
319
|
+
type AfterInsertHook<TShape extends LiveObjectAny, TSchema extends Schema<any> = Schema<any>> = (opts: {
|
|
116
320
|
ctx?: Record<string, any>;
|
|
117
321
|
value: Simplify<InferLiveObjectWithRelationalIds<TShape>> & {
|
|
118
322
|
id: string;
|
|
119
323
|
};
|
|
120
324
|
rawValue: MaterializedLiveType<TShape>;
|
|
121
|
-
db:
|
|
325
|
+
db: ServerDB<TSchema>;
|
|
122
326
|
}) => Promise<void> | void;
|
|
123
|
-
type BeforeUpdateHook<TShape extends LiveObjectAny> = (opts: {
|
|
327
|
+
type BeforeUpdateHook<TShape extends LiveObjectAny, TSchema extends Schema<any> = Schema<any>> = (opts: {
|
|
124
328
|
ctx?: Record<string, any>;
|
|
125
329
|
value: Simplify<InferLiveObjectWithRelationalIds<TShape>> & {
|
|
126
330
|
id: string;
|
|
@@ -130,9 +334,9 @@ type BeforeUpdateHook<TShape extends LiveObjectAny> = (opts: {
|
|
|
130
334
|
id: string;
|
|
131
335
|
};
|
|
132
336
|
previousRawValue?: MaterializedLiveType<TShape>;
|
|
133
|
-
db:
|
|
337
|
+
db: ServerDB<TSchema>;
|
|
134
338
|
}) => Promise<MaterializedLiveType<TShape> | void> | MaterializedLiveType<TShape> | void;
|
|
135
|
-
type AfterUpdateHook<TShape extends LiveObjectAny> = (opts: {
|
|
339
|
+
type AfterUpdateHook<TShape extends LiveObjectAny, TSchema extends Schema<any> = Schema<any>> = (opts: {
|
|
136
340
|
ctx?: Record<string, any>;
|
|
137
341
|
value: Simplify<InferLiveObjectWithRelationalIds<TShape>> & {
|
|
138
342
|
id: string;
|
|
@@ -142,93 +346,61 @@ type AfterUpdateHook<TShape extends LiveObjectAny> = (opts: {
|
|
|
142
346
|
id: string;
|
|
143
347
|
};
|
|
144
348
|
previousRawValue?: MaterializedLiveType<TShape>;
|
|
145
|
-
db:
|
|
349
|
+
db: ServerDB<TSchema>;
|
|
146
350
|
}) => Promise<void> | void;
|
|
147
|
-
type Hooks<TShape extends LiveObjectAny> = {
|
|
148
|
-
beforeInsert?: BeforeInsertHook<TShape>;
|
|
149
|
-
afterInsert?: AfterInsertHook<TShape>;
|
|
150
|
-
beforeUpdate?: BeforeUpdateHook<TShape>;
|
|
151
|
-
afterUpdate?: AfterUpdateHook<TShape>;
|
|
351
|
+
type Hooks<TShape extends LiveObjectAny, TSchema extends Schema<any> = Schema<any>> = {
|
|
352
|
+
beforeInsert?: BeforeInsertHook<TShape, TSchema>;
|
|
353
|
+
afterInsert?: AfterInsertHook<TShape, TSchema>;
|
|
354
|
+
beforeUpdate?: BeforeUpdateHook<TShape, TSchema>;
|
|
355
|
+
afterUpdate?: AfterUpdateHook<TShape, TSchema>;
|
|
152
356
|
};
|
|
153
|
-
declare class Route<TResourceSchema extends LiveObjectAny, TMiddleware extends Middleware<any>, TCustomMutations extends Record<string, Mutation<any, any
|
|
357
|
+
declare class Route<TResourceSchema extends LiveObjectAny, TMiddleware extends Middleware<any>, TCustomMutations extends Record<string, Mutation<any, any>>, TCustomQueries extends Record<string, Query<any, any>>, TSchema extends Schema<any> = Schema<any>> {
|
|
154
358
|
readonly resourceSchema: TResourceSchema;
|
|
155
359
|
readonly middlewares: Set<TMiddleware>;
|
|
156
360
|
readonly customMutations: TCustomMutations;
|
|
361
|
+
readonly customQueries: TCustomQueries;
|
|
157
362
|
readonly authorization?: Authorization<TResourceSchema>;
|
|
158
|
-
readonly hooks?: Hooks<TResourceSchema>;
|
|
159
|
-
constructor(resourceSchema: TResourceSchema, customMutations?: TCustomMutations, authorization?: Authorization<TResourceSchema>, hooks?: Hooks<TResourceSchema>);
|
|
363
|
+
readonly hooks?: Hooks<TResourceSchema, TSchema>;
|
|
364
|
+
constructor(resourceSchema: TResourceSchema, customMutations?: TCustomMutations, customQueries?: TCustomQueries, authorization?: Authorization<TResourceSchema>, hooks?: Hooks<TResourceSchema, TSchema>);
|
|
160
365
|
use(...middlewares: TMiddleware[]): this;
|
|
366
|
+
withProcedures<T extends Record<string, Procedure<any, any>>>(procedureFactory: (opts: {
|
|
367
|
+
mutation: MutationCreator<TSchema>;
|
|
368
|
+
query: QueryCreator<TSchema>;
|
|
369
|
+
}) => T): Route<TResourceSchema, TMiddleware, { [K in keyof T as T[K] extends Mutation<any, any> ? K : never]: T[K]; } & Record<string, Mutation<any, any>>, { [K_1 in keyof T as T[K_1] extends Query<any, any> ? K_1 : never]: T[K_1]; } & Record<string, Query<any, any>>, TSchema>;
|
|
370
|
+
/**
|
|
371
|
+
* @deprecated Use `withProcedures` instead
|
|
372
|
+
*/
|
|
161
373
|
withMutations<T extends Record<string, Mutation<any, any>>>(mutationFactory: (opts: {
|
|
162
374
|
mutation: typeof mutationCreator;
|
|
163
|
-
}) => T): Route<TResourceSchema, TMiddleware, T>;
|
|
164
|
-
withHooks(hooks: Hooks<TResourceSchema>): Route<TResourceSchema, TMiddleware, TCustomMutations>;
|
|
375
|
+
}) => T): Route<TResourceSchema, TMiddleware, { [K in keyof T as T[K] extends Mutation<any, any> ? K : never]: T[K]; } & Record<string, Mutation<any, any>>, { [K_1 in keyof T as T[K_1] extends Query<any, any> ? K_1 : never]: T[K_1]; } & Record<string, Query<any, any>>, TSchema>;
|
|
376
|
+
withHooks(hooks: Hooks<TResourceSchema, TSchema>): Route<TResourceSchema, TMiddleware, TCustomMutations, TCustomQueries, TSchema>;
|
|
165
377
|
getAuthorizationClause(req: QueryRequest): WhereClause<TResourceSchema> | undefined | boolean;
|
|
166
378
|
private handleSet;
|
|
167
379
|
private wrapInMiddlewares;
|
|
168
380
|
}
|
|
169
|
-
declare class
|
|
381
|
+
declare class ProcedureRoute<TMiddleware extends Middleware<any>, TCustomMutations extends Record<string, Mutation<any, any>>, TCustomQueries extends Record<string, Query<any, any>>, TSchema extends Schema<any> = Schema<any>> {
|
|
382
|
+
readonly resourceSchema: undefined;
|
|
383
|
+
readonly middlewares: Set<TMiddleware>;
|
|
384
|
+
readonly customMutations: TCustomMutations;
|
|
385
|
+
readonly customQueries: TCustomQueries;
|
|
386
|
+
constructor(customMutations?: TCustomMutations, customQueries?: TCustomQueries);
|
|
387
|
+
use(...middlewares: TMiddleware[]): this;
|
|
388
|
+
getAuthorizationClause(): undefined;
|
|
389
|
+
private wrapInMiddlewares;
|
|
390
|
+
}
|
|
391
|
+
declare class RouteFactory<TSchema extends Schema<any> = Schema<any>> {
|
|
170
392
|
private middlewares;
|
|
171
393
|
private constructor();
|
|
172
|
-
collectionRoute<T extends LiveObjectAny>(shape: T, authorization?: Authorization<T>): Route<T, Middleware<any>, Record<string, never
|
|
173
|
-
|
|
174
|
-
|
|
394
|
+
collectionRoute<T extends LiveObjectAny>(shape: T, authorization?: Authorization<T>): Route<T, Middleware<any>, Record<string, never>, Record<string, never>, TSchema>;
|
|
395
|
+
withProcedures<T extends Record<string, Procedure<any, any>>>(procedureFactory: (opts: {
|
|
396
|
+
mutation: MutationCreator<TSchema>;
|
|
397
|
+
query: QueryCreator<TSchema>;
|
|
398
|
+
}) => T): ProcedureRoute<Middleware<any>, { [K in keyof T as T[K] extends Mutation<any, any> ? K : never]: T[K]; } & Record<string, Mutation<any, any>>, { [K_1 in keyof T as T[K_1] extends Query<any, any> ? K_1 : never]: T[K_1]; } & Record<string, Query<any, any>>, TSchema>;
|
|
399
|
+
use(...middlewares: Middleware<any>[]): RouteFactory<TSchema>;
|
|
400
|
+
static create<TSchema extends Schema<any> = Schema<any>>(): RouteFactory<TSchema>;
|
|
175
401
|
}
|
|
176
402
|
declare const routeFactory: typeof RouteFactory.create;
|
|
177
|
-
type AnyRoute = Route<LiveObjectAny, Middleware<any>, Record<string, any
|
|
178
|
-
|
|
179
|
-
/** biome-ignore-all lint/suspicious/noExplicitAny: false positive */
|
|
180
|
-
|
|
181
|
-
declare class Batcher {
|
|
182
|
-
private storage;
|
|
183
|
-
private queue;
|
|
184
|
-
private scheduled;
|
|
185
|
-
constructor(storage: Storage);
|
|
186
|
-
rawFind<T extends LiveObjectAny>({ resource, commonWhere, uniqueWhere, ...rest }: {
|
|
187
|
-
resource: string;
|
|
188
|
-
commonWhere?: Record<string, any>;
|
|
189
|
-
uniqueWhere?: Record<string, any>;
|
|
190
|
-
include?: Record<string, any>;
|
|
191
|
-
limit?: number;
|
|
192
|
-
sort?: {
|
|
193
|
-
key: string;
|
|
194
|
-
direction: "asc" | "desc";
|
|
195
|
-
}[];
|
|
196
|
-
}): Promise<MaterializedLiveType<T>[]>;
|
|
197
|
-
private getBatchKey;
|
|
198
|
-
private processBatch;
|
|
199
|
-
private executeBatchedRequests;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
interface DataSource {
|
|
203
|
-
get(query: RawQueryRequest, extra?: {
|
|
204
|
-
context?: any;
|
|
205
|
-
batcher?: Batcher;
|
|
206
|
-
}): PromiseOrSync<any[]>;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/** biome-ignore-all lint/suspicious/noExplicitAny: false positive */
|
|
210
|
-
|
|
211
|
-
declare abstract class Storage implements DataSource {
|
|
212
|
-
abstract findOne<T extends LiveObjectAny, TInclude extends IncludeClause<T> | undefined = undefined>(resource: T, id: string, options?: {
|
|
213
|
-
include?: TInclude;
|
|
214
|
-
}): Promise<InferLiveObject<T, TInclude> | undefined>;
|
|
215
|
-
abstract find<T extends LiveObjectAny, TInclude extends IncludeClause<T> | undefined = undefined>(resource: T, options?: {
|
|
216
|
-
where?: WhereClause<T>;
|
|
217
|
-
include?: TInclude;
|
|
218
|
-
limit?: number;
|
|
219
|
-
sort?: {
|
|
220
|
-
key: string;
|
|
221
|
-
direction: "asc" | "desc";
|
|
222
|
-
}[];
|
|
223
|
-
}): Promise<InferLiveObject<T, TInclude>[]>;
|
|
224
|
-
insert<T extends LiveObjectAny>(resource: T, value: Simplify<InferInsert<T>>): Promise<InferLiveObject<T>>;
|
|
225
|
-
update<T extends LiveObjectAny>(resource: T, resourceId: string, value: InferUpdate<T>): Promise<Partial<InferLiveObject<T>>>;
|
|
226
|
-
abstract transaction<T>(fn: (opts: {
|
|
227
|
-
trx: Storage;
|
|
228
|
-
commit: () => Promise<void>;
|
|
229
|
-
rollback: () => Promise<void>;
|
|
230
|
-
}) => Promise<T>): Promise<T>;
|
|
231
|
-
}
|
|
403
|
+
type AnyRoute = Route<LiveObjectAny, Middleware<any>, Record<string, any>, Record<string, any>, any>;
|
|
232
404
|
|
|
233
405
|
/** biome-ignore-all lint/suspicious/noExplicitAny: false positive */
|
|
234
406
|
|
|
@@ -301,7 +473,7 @@ interface MutationRequest<TInput = any> extends BaseRequest {
|
|
|
301
473
|
resourceId?: string;
|
|
302
474
|
procedure: string;
|
|
303
475
|
}
|
|
304
|
-
type Request = QueryRequest | MutationRequest;
|
|
476
|
+
type Request = QueryRequest | MutationRequest | QueryProcedureRequest;
|
|
305
477
|
type ContextProvider = (req: Omit<BaseRequest, "context"> & {
|
|
306
478
|
transport: "HTTP" | "WEBSOCKET";
|
|
307
479
|
}) => Record<string, any>;
|
|
@@ -333,10 +505,14 @@ declare class Server<TRouter extends AnyRouter> {
|
|
|
333
505
|
handleMutation(opts: {
|
|
334
506
|
req: MutationRequest;
|
|
335
507
|
}): Promise<any>;
|
|
508
|
+
handleCustomQuery(opts: {
|
|
509
|
+
req: QueryProcedureRequest;
|
|
510
|
+
subscription?: (mutation: DefaultMutation) => void;
|
|
511
|
+
}): Promise<any>;
|
|
336
512
|
use(middleware: Middleware<any>): this;
|
|
337
513
|
context(contextProvider: ContextProvider): this;
|
|
338
514
|
private wrapInMiddlewares;
|
|
339
515
|
}
|
|
340
516
|
declare const server: typeof Server.create;
|
|
341
517
|
|
|
342
|
-
export { type AfterInsertHook, type AfterUpdateHook, type AnyRoute, type AnyRouter, type Authorization, type BaseRequest, type BeforeInsertHook, type BeforeUpdateHook, type ContextProvider, type Hooks, type Middleware, type Mutation, type MutationAuthorizationHandler, type MutationRequest, type MutationResult, type NextFunction, type QueryRequest, type QueryResult, type ReadAuthorizationHandler, type Request, Route, RouteFactory, type RouteRecord, Router, SQLStorage, Server, Storage, expressAdapter, routeFactory, router, server };
|
|
518
|
+
export { type AfterInsertHook, type AfterUpdateHook, type AnyProcedureRoute, type AnyRoute, type AnyRouteOrProcedure, type AnyRouter, type Authorization, type BaseRequest, type BeforeInsertHook, type BeforeUpdateHook, type ContextProvider, type Hooks, type Middleware, type Mutation, type MutationAuthorizationHandler, type MutationRequest, type MutationResult, type NextFunction, type Procedure, ProcedureRoute, type Query, type QueryProcedureRequest, type QueryRequest, type QueryResult, type ReadAuthorizationHandler, type Request, Route, RouteFactory, type RouteRecord, Router, SQLStorage, Server, type ServerCollection, type ServerDB, Storage, createServerDB, expressAdapter, routeFactory, router, server };
|