@live-state/sync 0.0.7-canary-2 → 0.0.7-canary-4

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/server.d.cts CHANGED
@@ -216,19 +216,19 @@ declare function createServerDB<TSchema extends Schema<any>>(storage: Storage, s
216
216
  /** biome-ignore-all lint/suspicious/noExplicitAny: false positive */
217
217
  /** biome-ignore-all lint/style/noNonNullAssertion: false positive */
218
218
 
219
- type AnyProcedureRoute = ProcedureRoute<Middleware<any>, Record<string, any>, Record<string, any>, any>;
219
+ type AnyProcedureRoute = ProcedureRoute<Middleware<any>, Record<string, any>, Record<string, any>, any, any>;
220
220
  type AnyRouteOrProcedure = AnyRoute | AnyProcedureRoute;
221
221
  type RouteRecord = Record<string, AnyRouteOrProcedure>;
222
222
  declare class Router<TRoutes extends RouteRecord> {
223
223
  readonly routes: TRoutes;
224
- readonly hooksRegistry: Map<string, Hooks<any>>;
224
+ readonly hooksRegistry: Map<string, Hooks<any, any, any>>;
225
225
  private constructor();
226
226
  static create<TRoutes extends RouteRecord>(opts: {
227
227
  routes: TRoutes;
228
228
  }): Router<TRoutes>;
229
- getHooks(resourceName: string): Hooks<any> | undefined;
229
+ getHooks(resourceName: string): Hooks<any, any, any> | undefined;
230
230
  }
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: {
231
+ declare const router: <TSchema extends Schema<any>, TRoutes extends Record<keyof TSchema, Route<any, any, any, any, any, any>> & Record<string, Route<any, any, any, any, any, any> | ProcedureRoute<any, any, any, any, any>>>(opts: {
232
232
  schema: TSchema;
233
233
  routes: TRoutes;
234
234
  }) => Router<TRoutes>;
@@ -241,91 +241,90 @@ type MutationResult<TShape extends LiveObjectAny> = {
241
241
  data: MaterializedLiveType<TShape>;
242
242
  acceptedValues: Record<string, any> | null;
243
243
  };
244
- type Mutation<TInputValidator extends StandardSchemaV1<any, any> | never, TOutput> = {
244
+ type Mutation<TInputValidator extends StandardSchemaV1<any, any> | never, TOutput, TContext = Record<string, any>> = {
245
245
  _type: "mutation";
246
246
  inputValidator: TInputValidator;
247
247
  handler: (opts: {
248
- req: MutationRequest<TInputValidator extends StandardSchemaV1<any, any> ? StandardSchemaV1.InferOutput<TInputValidator> : undefined>;
248
+ req: MutationRequest<TInputValidator extends StandardSchemaV1<any, any> ? StandardSchemaV1.InferOutput<TInputValidator> : undefined, TContext>;
249
249
  db: ServerDB<any>;
250
250
  }) => TOutput;
251
251
  };
252
- interface QueryProcedureRequest<TInput = any> extends BaseRequest {
252
+ interface QueryProcedureRequest<TInput = any, TContext = Record<string, any>> extends BaseRequest<TContext> {
253
253
  type: "CUSTOM_QUERY";
254
254
  input: TInput;
255
255
  resource: string;
256
256
  procedure: string;
257
257
  }
258
- type Query<TInputValidator extends StandardSchemaV1<any, any> | never, TOutput> = {
258
+ type Query<TInputValidator extends StandardSchemaV1<any, any> | never, TOutput, TContext = Record<string, any>> = {
259
259
  _type: "query";
260
260
  inputValidator: TInputValidator;
261
261
  handler: (opts: {
262
- req: QueryProcedureRequest<TInputValidator extends StandardSchemaV1<any, any> ? StandardSchemaV1.InferOutput<TInputValidator> : undefined>;
262
+ req: QueryProcedureRequest<TInputValidator extends StandardSchemaV1<any, any> ? StandardSchemaV1.InferOutput<TInputValidator> : undefined, TContext>;
263
263
  db: ServerDB<any>;
264
264
  }) => TOutput;
265
265
  };
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>> = {
266
+ type Procedure<TInputValidator extends StandardSchemaV1<any, any> | never, TOutput, TContext = Record<string, any>> = Mutation<TInputValidator, TOutput, TContext> | Query<TInputValidator, TOutput, TContext>;
267
+ type QueryCreator<TSchema extends Schema<any> = Schema<any>, TContext = Record<string, any>> = {
268
268
  (): {
269
269
  handler: <TOutput>(handler: (opts: {
270
- req: QueryProcedureRequest<undefined>;
270
+ req: QueryProcedureRequest<undefined, TContext>;
271
271
  db: ServerDB<TSchema>;
272
- }) => TOutput) => Query<StandardSchemaV1<any, undefined>, TOutput>;
272
+ }) => TOutput) => Query<StandardSchemaV1<any, undefined>, TOutput, TContext>;
273
273
  };
274
274
  <TInputValidator extends StandardSchemaV1<any, any>>(validator: TInputValidator): {
275
275
  handler: <THandler extends (opts: {
276
- req: QueryProcedureRequest<StandardSchemaV1.InferOutput<TInputValidator>>;
276
+ req: QueryProcedureRequest<StandardSchemaV1.InferOutput<TInputValidator>, TContext>;
277
277
  db: ServerDB<TSchema>;
278
- }) => any>(handler: THandler) => Query<TInputValidator, ReturnType<THandler>>;
278
+ }) => any>(handler: THandler) => Query<TInputValidator, ReturnType<THandler>, TContext>;
279
279
  };
280
280
  };
281
- type MutationCreator<TSchema extends Schema<any> = Schema<any>> = {
281
+ type MutationCreator<TSchema extends Schema<any> = Schema<any>, TContext = Record<string, any>> = {
282
282
  (): {
283
283
  handler: <TOutput>(handler: (opts: {
284
- req: MutationRequest<undefined>;
284
+ req: MutationRequest<undefined, TContext>;
285
285
  db: ServerDB<TSchema>;
286
- }) => TOutput) => Mutation<StandardSchemaV1<any, undefined>, TOutput>;
286
+ }) => TOutput) => Mutation<StandardSchemaV1<any, undefined>, TOutput, TContext>;
287
287
  };
288
288
  <TInputValidator extends StandardSchemaV1<any, any>>(validator: TInputValidator): {
289
289
  handler: <THandler extends (opts: {
290
- req: MutationRequest<StandardSchemaV1.InferOutput<TInputValidator>>;
290
+ req: MutationRequest<StandardSchemaV1.InferOutput<TInputValidator>, TContext>;
291
291
  db: ServerDB<TSchema>;
292
- }) => any>(handler: THandler) => Mutation<TInputValidator, ReturnType<THandler>>;
292
+ }) => any>(handler: THandler) => Mutation<TInputValidator, ReturnType<THandler>, TContext>;
293
293
  };
294
294
  };
295
- declare const mutationCreator: MutationCreator;
296
- type ReadAuthorizationHandler<TShape extends LiveObjectAny> = (opts: {
297
- ctx: BaseRequest["context"];
295
+ type ReadAuthorizationHandler<TShape extends LiveObjectAny, TContext = Record<string, any>> = (opts: {
296
+ ctx: TContext;
298
297
  }) => WhereClause<TShape> | boolean;
299
- type MutationAuthorizationHandler<TShape extends LiveObjectAny> = (opts: {
300
- ctx: BaseRequest["context"];
298
+ type MutationAuthorizationHandler<TShape extends LiveObjectAny, TContext = Record<string, any>> = (opts: {
299
+ ctx: TContext;
301
300
  value: Simplify<InferLiveObjectWithRelationalIds<TShape>>;
302
301
  }) => WhereClause<TShape> | boolean;
303
- type Authorization<TShape extends LiveObjectAny> = {
304
- read?: ReadAuthorizationHandler<TShape>;
305
- insert?: MutationAuthorizationHandler<TShape>;
302
+ type Authorization<TShape extends LiveObjectAny, TContext = Record<string, any>> = {
303
+ read?: ReadAuthorizationHandler<TShape, TContext>;
304
+ insert?: MutationAuthorizationHandler<TShape, TContext>;
306
305
  update?: {
307
- preMutation?: MutationAuthorizationHandler<TShape>;
308
- postMutation?: MutationAuthorizationHandler<TShape>;
306
+ preMutation?: MutationAuthorizationHandler<TShape, TContext>;
307
+ postMutation?: MutationAuthorizationHandler<TShape, TContext>;
309
308
  };
310
309
  };
311
- type BeforeInsertHook<TShape extends LiveObjectAny, TSchema extends Schema<any> = Schema<any>> = (opts: {
312
- ctx?: Record<string, any>;
310
+ type BeforeInsertHook<TShape extends LiveObjectAny, TSchema extends Schema<any> = Schema<any>, TContext = Record<string, any>> = (opts: {
311
+ ctx?: TContext;
313
312
  value: Simplify<InferLiveObjectWithRelationalIds<TShape>> & {
314
313
  id: string;
315
314
  };
316
315
  rawValue: MaterializedLiveType<TShape>;
317
316
  db: ServerDB<TSchema>;
318
317
  }) => Promise<MaterializedLiveType<TShape> | void> | MaterializedLiveType<TShape> | void;
319
- type AfterInsertHook<TShape extends LiveObjectAny, TSchema extends Schema<any> = Schema<any>> = (opts: {
320
- ctx?: Record<string, any>;
318
+ type AfterInsertHook<TShape extends LiveObjectAny, TSchema extends Schema<any> = Schema<any>, TContext = Record<string, any>> = (opts: {
319
+ ctx?: TContext;
321
320
  value: Simplify<InferLiveObjectWithRelationalIds<TShape>> & {
322
321
  id: string;
323
322
  };
324
323
  rawValue: MaterializedLiveType<TShape>;
325
324
  db: ServerDB<TSchema>;
326
325
  }) => Promise<void> | void;
327
- type BeforeUpdateHook<TShape extends LiveObjectAny, TSchema extends Schema<any> = Schema<any>> = (opts: {
328
- ctx?: Record<string, any>;
326
+ type BeforeUpdateHook<TShape extends LiveObjectAny, TSchema extends Schema<any> = Schema<any>, TContext = Record<string, any>> = (opts: {
327
+ ctx?: TContext;
329
328
  value: Simplify<InferLiveObjectWithRelationalIds<TShape>> & {
330
329
  id: string;
331
330
  };
@@ -336,8 +335,8 @@ type BeforeUpdateHook<TShape extends LiveObjectAny, TSchema extends Schema<any>
336
335
  previousRawValue?: MaterializedLiveType<TShape>;
337
336
  db: ServerDB<TSchema>;
338
337
  }) => Promise<MaterializedLiveType<TShape> | void> | MaterializedLiveType<TShape> | void;
339
- type AfterUpdateHook<TShape extends LiveObjectAny, TSchema extends Schema<any> = Schema<any>> = (opts: {
340
- ctx?: Record<string, any>;
338
+ type AfterUpdateHook<TShape extends LiveObjectAny, TSchema extends Schema<any> = Schema<any>, TContext = Record<string, any>> = (opts: {
339
+ ctx?: TContext;
341
340
  value: Simplify<InferLiveObjectWithRelationalIds<TShape>> & {
342
341
  id: string;
343
342
  };
@@ -348,37 +347,37 @@ type AfterUpdateHook<TShape extends LiveObjectAny, TSchema extends Schema<any> =
348
347
  previousRawValue?: MaterializedLiveType<TShape>;
349
348
  db: ServerDB<TSchema>;
350
349
  }) => Promise<void> | void;
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>;
350
+ type Hooks<TShape extends LiveObjectAny, TSchema extends Schema<any> = Schema<any>, TContext = Record<string, any>> = {
351
+ beforeInsert?: BeforeInsertHook<TShape, TSchema, TContext>;
352
+ afterInsert?: AfterInsertHook<TShape, TSchema, TContext>;
353
+ beforeUpdate?: BeforeUpdateHook<TShape, TSchema, TContext>;
354
+ afterUpdate?: AfterUpdateHook<TShape, TSchema, TContext>;
356
355
  };
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>> {
356
+ 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>, TContext = Record<string, any>> {
358
357
  readonly resourceSchema: TResourceSchema;
359
358
  readonly middlewares: Set<TMiddleware>;
360
359
  readonly customMutations: TCustomMutations;
361
360
  readonly customQueries: TCustomQueries;
362
- readonly authorization?: Authorization<TResourceSchema>;
363
- readonly hooks?: Hooks<TResourceSchema, TSchema>;
364
- constructor(resourceSchema: TResourceSchema, customMutations?: TCustomMutations, customQueries?: TCustomQueries, authorization?: Authorization<TResourceSchema>, hooks?: Hooks<TResourceSchema, TSchema>);
361
+ readonly authorization?: Authorization<TResourceSchema, TContext>;
362
+ readonly hooks?: Hooks<TResourceSchema, TSchema, TContext>;
363
+ constructor(resourceSchema: TResourceSchema, customMutations?: TCustomMutations, customQueries?: TCustomQueries, authorization?: Authorization<TResourceSchema, TContext>, hooks?: Hooks<TResourceSchema, TSchema, TContext>);
365
364
  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>;
365
+ withProcedures<T extends Record<string, Procedure<any, any, any>>>(procedureFactory: (opts: {
366
+ mutation: MutationCreator<TSchema, TContext>;
367
+ query: QueryCreator<TSchema, TContext>;
368
+ }) => T): Route<TResourceSchema, TMiddleware, { [K in keyof T as T[K] extends Mutation<any, any, Record<string, any>> ? K : never]: T[K]; } & Record<string, Mutation<any, any, Record<string, any>>>, { [K_1 in keyof T as T[K_1] extends Query<any, any, Record<string, any>> ? K_1 : never]: T[K_1]; } & Record<string, Query<any, any, Record<string, any>>>, TSchema, TContext>;
370
369
  /**
371
370
  * @deprecated Use `withProcedures` instead
372
371
  */
373
372
  withMutations<T extends Record<string, Mutation<any, any>>>(mutationFactory: (opts: {
374
- mutation: typeof mutationCreator;
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>;
373
+ mutation: MutationCreator<TSchema, TContext>;
374
+ }) => T): Route<TResourceSchema, TMiddleware, { [K in keyof T as T[K] extends Mutation<any, any, Record<string, any>> ? K : never]: T[K]; } & Record<string, Mutation<any, any, Record<string, any>>>, { [K_1 in keyof T as T[K_1] extends Query<any, any, Record<string, any>> ? K_1 : never]: T[K_1]; } & Record<string, Query<any, any, Record<string, any>>>, TSchema, TContext>;
375
+ withHooks(hooks: Hooks<TResourceSchema, TSchema, TContext>): Route<TResourceSchema, TMiddleware, TCustomMutations, TCustomQueries, TSchema, TContext>;
377
376
  getAuthorizationClause(req: QueryRequest): WhereClause<TResourceSchema> | undefined | boolean;
378
377
  private handleSet;
379
378
  private wrapInMiddlewares;
380
379
  }
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>> {
380
+ 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>, TContext = Record<string, any>> {
382
381
  readonly resourceSchema: undefined;
383
382
  readonly middlewares: Set<TMiddleware>;
384
383
  readonly customMutations: TCustomMutations;
@@ -388,19 +387,31 @@ declare class ProcedureRoute<TMiddleware extends Middleware<any>, TCustomMutatio
388
387
  getAuthorizationClause(): undefined;
389
388
  private wrapInMiddlewares;
390
389
  }
391
- declare class RouteFactory<TSchema extends Schema<any> = Schema<any>> {
390
+ type TypedMiddleware<TContextIn, TContextOut> = {
391
+ _brand: "TypedMiddleware";
392
+ _rawMiddleware: Middleware<any>;
393
+ _contextIn?: TContextIn;
394
+ _contextOut?: TContextOut;
395
+ };
396
+ declare function createMiddleware<TContextIn, TContextOut = TContextIn>(fn: (opts: {
397
+ ctx: TContextIn;
398
+ req: Request<TContextIn>;
399
+ next: (ctx: TContextOut) => any;
400
+ }) => any): TypedMiddleware<TContextIn, TContextOut>;
401
+ declare class RouteFactory<TSchema extends Schema<any> = Schema<any>, TContext = Record<string, any>> {
392
402
  private middlewares;
393
403
  private constructor();
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>;
404
+ collectionRoute<T extends LiveObjectAny>(shape: T, authorization?: Authorization<T, TContext>): Route<T, Middleware<any>, Record<string, never>, Record<string, never>, TSchema, TContext>;
405
+ withProcedures<T extends Record<string, Procedure<any, any, any>>>(procedureFactory: (opts: {
406
+ mutation: MutationCreator<TSchema, TContext>;
407
+ query: QueryCreator<TSchema, TContext>;
408
+ }) => T): ProcedureRoute<Middleware<any>, { [K in keyof T as T[K] extends Mutation<any, any, Record<string, any>> ? K : never]: T[K]; } & Record<string, Mutation<any, any, Record<string, any>>>, { [K_1 in keyof T as T[K_1] extends Query<any, any, Record<string, any>> ? K_1 : never]: T[K_1]; } & Record<string, Query<any, any, Record<string, any>>>, TSchema, TContext>;
409
+ use<TNewContext>(mw: TypedMiddleware<TContext, TNewContext>): RouteFactory<TSchema, TNewContext>;
410
+ use(...middlewares: Middleware<any>[]): RouteFactory<TSchema, TContext>;
411
+ static create<TSchema extends Schema<any> = Schema<any>, TContext = Record<string, any>>(): RouteFactory<TSchema, TContext>;
401
412
  }
402
413
  declare const routeFactory: typeof RouteFactory.create;
403
- type AnyRoute = Route<LiveObjectAny, Middleware<any>, Record<string, any>, Record<string, any>, any>;
414
+ type AnyRoute = Route<LiveObjectAny, Middleware<any>, Record<string, any>, Record<string, any>, any, any>;
404
415
 
405
416
  /** biome-ignore-all lint/suspicious/noExplicitAny: false positive */
406
417
 
@@ -453,51 +464,58 @@ declare class SQLStorage extends Storage {
453
464
  private notifyMutations;
454
465
  }
455
466
 
456
- declare const expressAdapter: (app: Application, server: Server<AnyRouter>, options?: {
467
+ declare const expressAdapter: (app: Application, server: Server<AnyRouter, any>, options?: {
457
468
  basePath?: string;
458
469
  }) => void;
459
470
 
460
- interface BaseRequest {
471
+ interface BaseRequest<TContext = Record<string, any>> {
461
472
  headers: Record<string, string>;
462
473
  cookies: Record<string, string>;
463
474
  queryParams: Record<string, string>;
464
- context: Record<string, any>;
475
+ context: TContext;
465
476
  }
466
- interface QueryRequest extends BaseRequest, RawQueryRequest {
477
+ interface QueryRequest<TContext = Record<string, any>> extends BaseRequest<TContext>, RawQueryRequest {
467
478
  type: "QUERY";
468
479
  }
469
- interface MutationRequest<TInput = any> extends BaseRequest {
480
+ interface MutationRequest<TInput = any, TContext = Record<string, any>> extends BaseRequest<TContext> {
470
481
  type: "MUTATE";
471
482
  input: TInput;
472
483
  resource: string;
473
484
  resourceId?: string;
474
485
  procedure: string;
475
486
  }
476
- type Request = QueryRequest | MutationRequest | QueryProcedureRequest;
477
- type ContextProvider = (req: Omit<BaseRequest, "context"> & {
487
+ type Request<TContext = Record<string, any>> = QueryRequest<TContext> | MutationRequest<any, TContext> | QueryProcedureRequest<any, TContext>;
488
+ type ContextProvider<TContext = Record<string, any>> = (req: Omit<BaseRequest, "context"> & {
478
489
  transport: "HTTP" | "WEBSOCKET";
479
- }) => Record<string, any>;
490
+ }) => TContext | Promise<TContext>;
480
491
  type NextFunction<O, R = Request> = (req: R) => PromiseOrSync<O>;
481
492
  type Middleware<T = any> = (opts: {
482
493
  req: Request;
483
494
  next: NextFunction<T>;
484
495
  }) => ReturnType<NextFunction<T>>;
485
- declare class Server<TRouter extends AnyRouter> {
496
+ declare class Server<TRouter extends AnyRouter, TContext = Record<string, any>> {
486
497
  readonly router: TRouter;
487
498
  readonly storage: Storage;
488
499
  readonly schema: Schema<any>;
489
500
  readonly middlewares: Set<Middleware<any>>;
490
501
  readonly logger: Logger;
491
- contextProvider?: ContextProvider;
502
+ contextProvider?: ContextProvider<TContext>;
492
503
  private constructor();
493
504
  static create<TRouter extends AnyRouter>(opts: {
494
505
  router: TRouter;
495
506
  storage: Storage;
496
507
  schema: Schema<any>;
497
508
  middlewares?: Middleware<any>[];
498
- contextProvider?: ContextProvider;
499
509
  logLevel?: LogLevel;
500
- }): Server<TRouter>;
510
+ }): Server<TRouter, Record<string, any>>;
511
+ static create<TRouter extends AnyRouter, TContext>(opts: {
512
+ router: TRouter;
513
+ storage: Storage;
514
+ schema: Schema<any>;
515
+ middlewares?: Middleware<any>[];
516
+ contextProvider: ContextProvider<TContext>;
517
+ logLevel?: LogLevel;
518
+ }): Server<TRouter, TContext>;
501
519
  handleQuery(opts: {
502
520
  req: QueryRequest;
503
521
  subscription?: (mutation: DefaultMutation) => void;
@@ -510,9 +528,9 @@ declare class Server<TRouter extends AnyRouter> {
510
528
  subscription?: (mutation: DefaultMutation) => void;
511
529
  }): Promise<any>;
512
530
  use(middleware: Middleware<any>): this;
513
- context(contextProvider: ContextProvider): this;
531
+ context(contextProvider: ContextProvider<TContext>): this;
514
532
  private wrapInMiddlewares;
515
533
  }
516
534
  declare const server: typeof Server.create;
517
535
 
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 };
536
+ 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, type TypedMiddleware, createMiddleware, createServerDB, expressAdapter, routeFactory, router, server };