fauxbase 0.1.2 → 0.5.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/dist/index.d.cts CHANGED
@@ -48,12 +48,19 @@ interface FieldOptions {
48
48
  }
49
49
  interface LocalDriverConfig {
50
50
  type: 'local';
51
- persist?: 'memory' | 'localStorage';
51
+ persist?: 'memory' | 'localStorage' | 'indexeddb';
52
+ dbName?: string;
52
53
  }
53
54
  interface HttpDriverConfig {
54
55
  type: 'http';
55
56
  baseUrl: string;
56
57
  preset?: string;
58
+ timeout?: number;
59
+ retry?: {
60
+ maxRetries?: number;
61
+ baseDelay?: number;
62
+ };
63
+ headers?: Record<string, string>;
57
64
  }
58
65
  type DriverConfig = LocalDriverConfig | HttpDriverConfig;
59
66
  interface SeedDefinition<T = any> {
@@ -81,6 +88,22 @@ declare class ValidationError extends FauxbaseError {
81
88
  declare class ForbiddenError extends FauxbaseError {
82
89
  constructor(message?: string);
83
90
  }
91
+ declare class NetworkError extends FauxbaseError {
92
+ constructor(message?: string);
93
+ }
94
+ declare class TimeoutError extends FauxbaseError {
95
+ constructor(message?: string);
96
+ }
97
+ declare class HttpError extends FauxbaseError {
98
+ readonly status: number;
99
+ constructor(message: string, status: number, details?: Record<string, string>);
100
+ toJSON(): {
101
+ status: number;
102
+ error: string;
103
+ code: string;
104
+ details?: Record<string, string>;
105
+ };
106
+ }
84
107
 
85
108
  declare abstract class Entity {
86
109
  id: string;
@@ -120,6 +143,51 @@ interface Driver {
120
143
  clear(resource: string): void;
121
144
  }
122
145
 
146
+ type EventAction = 'created' | 'updated' | 'deleted' | 'bulkCreated' | 'bulkUpdated' | 'bulkDeleted';
147
+ interface FauxbaseEvent<T = any> {
148
+ action: EventAction;
149
+ resource: string;
150
+ data?: T;
151
+ id?: string;
152
+ ids?: string[];
153
+ timestamp: number;
154
+ source: 'local' | 'remote';
155
+ }
156
+ type EventHandler<T = any> = (event: FauxbaseEvent<T>) => void;
157
+ interface EventSourceAdapter {
158
+ connect(): void;
159
+ disconnect(): void;
160
+ }
161
+ interface SSEConfig {
162
+ type: 'sse';
163
+ url: string;
164
+ eventMap: Record<string, string>;
165
+ withCredentials?: boolean;
166
+ }
167
+ interface STOMPConfig {
168
+ type: 'stomp';
169
+ brokerUrl: string;
170
+ subscriptions: Record<string, string>;
171
+ connectHeaders?: Record<string, string>;
172
+ }
173
+ type EventSourceConfig = SSEConfig | STOMPConfig;
174
+ interface EventHandlersConfig {
175
+ [resource: string]: EventHandler;
176
+ }
177
+ type EventsConfig = true | {
178
+ source?: EventSourceConfig;
179
+ handlers?: EventHandlersConfig;
180
+ };
181
+
182
+ declare class EventBus {
183
+ private listeners;
184
+ private anyListeners;
185
+ on(resource: string, handler: EventHandler): () => void;
186
+ onAny(handler: EventHandler): () => void;
187
+ emit(event: FauxbaseEvent): void;
188
+ destroy(): void;
189
+ }
190
+
123
191
  declare function beforeCreate(): MethodDecorator;
124
192
  declare function beforeUpdate(): MethodDecorator;
125
193
  declare function afterCreate(): MethodDecorator;
@@ -129,8 +197,13 @@ declare abstract class Service<T extends Entity> {
129
197
  abstract endpoint: string;
130
198
  protected driver: Driver;
131
199
  protected resourceName: string;
200
+ protected client: any;
201
+ /** @internal */
202
+ _eventBus?: EventBus;
132
203
  /** @internal — called by createClient to wire the service */
133
204
  _init(driver: Driver, resourceName: string): void;
205
+ /** @internal — called by createClient to give services access to the client */
206
+ _setClient(client: any): void;
134
207
  list(query?: QueryParams): Promise<PagedResponse<T>>;
135
208
  get(id: string): Promise<ApiResponse<T>>;
136
209
  create(data: Partial<T>): Promise<ApiResponse<T>>;
@@ -138,27 +211,229 @@ declare abstract class Service<T extends Entity> {
138
211
  delete(id: string): Promise<ApiResponse<T>>;
139
212
  count(filter?: Record<string, any>): Promise<number>;
140
213
  get bulk(): {
141
- create: (items: Array<Partial<T>>) => Promise<ApiResponse<T[]>>;
142
- update: (updates: Array<{
214
+ create(items: Array<Partial<T>>): Promise<ApiResponse<T[]>>;
215
+ update(updates: Array<{
143
216
  id: string;
144
217
  data: Partial<T>;
145
- }>) => Promise<ApiResponse<T[]>>;
146
- delete: (ids: string[]) => Promise<ApiResponse<{
218
+ }>): Promise<ApiResponse<T[]>>;
219
+ delete(ids: string[]): Promise<ApiResponse<{
147
220
  count: number;
148
221
  }>>;
149
222
  };
223
+ private emitEvent;
150
224
  private runHooks;
151
225
  }
152
226
 
227
+ type AuthProvider$1 = () => {
228
+ token: string;
229
+ } | null;
230
+ interface HttpDriverOptions extends HttpDriverConfig {
231
+ timeout?: number;
232
+ retry?: {
233
+ maxRetries?: number;
234
+ baseDelay?: number;
235
+ };
236
+ headers?: Record<string, string>;
237
+ }
238
+ declare class HttpDriver implements Driver {
239
+ private baseUrl;
240
+ private preset;
241
+ private timeout;
242
+ private maxRetries;
243
+ private baseDelay;
244
+ private defaultHeaders;
245
+ private endpoints;
246
+ private authProvider;
247
+ constructor(config: HttpDriverOptions);
248
+ setAuthProvider(provider: AuthProvider$1): void;
249
+ registerEndpoint(resource: string, endpoint: string): void;
250
+ private getEndpoint;
251
+ private buildUrl;
252
+ private buildHeaders;
253
+ private request;
254
+ private throwMappedError;
255
+ list<T>(resource: string, query: QueryParams): Promise<PagedResponse<T>>;
256
+ get<T>(resource: string, id: string): Promise<ApiResponse<T>>;
257
+ create<T>(resource: string, data: Partial<T>): Promise<ApiResponse<T>>;
258
+ update<T>(resource: string, id: string, data: Partial<T>): Promise<ApiResponse<T>>;
259
+ delete<T>(resource: string, id: string): Promise<ApiResponse<T>>;
260
+ count(resource: string, filter?: Record<string, any>): Promise<number>;
261
+ bulkCreate<T>(resource: string, data: Array<Partial<T>>): Promise<ApiResponse<T[]>>;
262
+ bulkUpdate<T>(resource: string, updates: Array<{
263
+ id: string;
264
+ data: Partial<T>;
265
+ }>): Promise<ApiResponse<T[]>>;
266
+ bulkDelete(resource: string, ids: string[]): Promise<ApiResponse<{
267
+ count: number;
268
+ }>>;
269
+ seed(): void;
270
+ getSeedVersion(): string | null;
271
+ setSeedVersion(): void;
272
+ clear(): void;
273
+ }
274
+
275
+ interface LoginCredentials {
276
+ email: string;
277
+ password: string;
278
+ }
279
+ interface AuthState {
280
+ userId: string;
281
+ email: string;
282
+ userName?: string;
283
+ role?: string;
284
+ token: string;
285
+ }
286
+ interface AuthContext {
287
+ userId: string;
288
+ userName?: string;
289
+ }
290
+ declare abstract class AuthService<T extends Entity> extends Service<T> {
291
+ private authState;
292
+ private saveState;
293
+ private httpDriver;
294
+ /** @internal — called by createClient to wire persistence */
295
+ _initAuth(loadState: () => AuthState | null, saveState: (state: AuthState | null) => void): void;
296
+ /** @internal — called by createClient when using HttpDriver */
297
+ _setHttpMode(driver: HttpDriver): void;
298
+ login(credentials: LoginCredentials): Promise<T>;
299
+ register(data: Partial<T>): Promise<T>;
300
+ logout(): void;
301
+ get currentUser(): T | null;
302
+ get isLoggedIn(): boolean;
303
+ get token(): string | null;
304
+ hasRole(role: string): boolean;
305
+ getAuthContext(): AuthContext | null;
306
+ private localLogin;
307
+ private localRegister;
308
+ private httpLogin;
309
+ private httpRegister;
310
+ private generateToken;
311
+ private persistState;
312
+ }
313
+
153
314
  type ClientServices<S extends Record<string, new (...args: any[]) => Service<any>>> = {
154
315
  [K in keyof S]: InstanceType<S[K]>;
155
316
  };
156
- declare function createClient<S extends Record<string, new (...args: any[]) => Service<any>>>(config: {
317
+ type ClientResult<S extends Record<string, new (...args: any[]) => Service<any>>, A extends (new (...args: any[]) => AuthService<any>) | undefined> = ClientServices<S> & (A extends new (...args: any[]) => AuthService<any> ? {
318
+ auth: InstanceType<A>;
319
+ } : {}) & {
320
+ readonly ready: Promise<void>;
321
+ } & {
322
+ _eventBus?: EventBus;
323
+ disconnect?: () => void;
324
+ };
325
+ declare function createClient<S extends Record<string, new (...args: any[]) => Service<any>>, A extends (new (...args: any[]) => AuthService<any>) | undefined = undefined>(config: {
157
326
  driver?: DriverConfig;
158
327
  services: S;
159
328
  seeds?: SeedDefinition[];
160
- }): ClientServices<S>;
329
+ auth?: A;
330
+ overrides?: Record<string, {
331
+ driver: DriverConfig;
332
+ }>;
333
+ events?: EventsConfig;
334
+ }): ClientResult<S, A>;
161
335
 
162
336
  declare function seed<T>(entityClass: new (...args: any[]) => T, data: Array<Partial<T>>): SeedDefinition<T>;
163
337
 
164
- export { type ApiResponse, type BaseFields, ConflictError, type Driver, type DriverConfig, Entity, FauxbaseError, type FauxbaseErrorPayload, type FieldOptions, type FilterOperator, ForbiddenError, type HookType, type HttpDriverConfig, type LocalDriverConfig, NotFoundError, type PageMeta, type PagedResponse, type QueryParams, type SeedDefinition, Service, type SortParams, ValidationError, afterCreate, afterUpdate, beforeCreate, beforeUpdate, computed, createClient, field, relation, seed };
338
+ interface StorageBackend {
339
+ getAll(resource: string): Record<string, any>[];
340
+ getById(resource: string, id: string): Record<string, any> | undefined;
341
+ set(resource: string, id: string, data: Record<string, any>): void;
342
+ remove(resource: string, id: string): void;
343
+ clear(resource: string): void;
344
+ getMeta(key: string): string | null;
345
+ setMeta(key: string, value: string): void;
346
+ }
347
+ type AuthProvider = () => {
348
+ userId: string;
349
+ userName?: string;
350
+ } | null;
351
+ declare class LocalDriver implements Driver {
352
+ private storage;
353
+ private entityClasses;
354
+ private authProvider;
355
+ private _ready;
356
+ private _isReady;
357
+ constructor(config: LocalDriverConfig);
358
+ get ready(): Promise<void>;
359
+ get isReady(): boolean;
360
+ setAuthProvider(provider: AuthProvider): void;
361
+ getStorageBackend(): StorageBackend;
362
+ registerEntity(resource: string, entityClass: Function): void;
363
+ list<T>(resource: string, query: QueryParams): Promise<PagedResponse<T>>;
364
+ get<T>(resource: string, id: string): Promise<ApiResponse<T>>;
365
+ create<T>(resource: string, data: Partial<T>): Promise<ApiResponse<T>>;
366
+ update<T>(resource: string, id: string, data: Partial<T>): Promise<ApiResponse<T>>;
367
+ delete<T>(resource: string, id: string): Promise<ApiResponse<T>>;
368
+ count(resource: string, filter?: Record<string, any>): Promise<number>;
369
+ bulkCreate<T>(resource: string, data: Array<Partial<T>>): Promise<ApiResponse<T[]>>;
370
+ bulkUpdate<T>(resource: string, updates: Array<{
371
+ id: string;
372
+ data: Partial<T>;
373
+ }>): Promise<ApiResponse<T[]>>;
374
+ bulkDelete(resource: string, ids: string[]): Promise<ApiResponse<{
375
+ count: number;
376
+ }>>;
377
+ seed(resource: string, data: Array<Record<string, any>>, entityClass: Function): void;
378
+ getSeedVersion(): string | null;
379
+ setSeedVersion(version: string): void;
380
+ clear(resource: string): void;
381
+ }
382
+
383
+ type FilterStyle = 'django' | 'dot' | 'bracket' | 'nestjs';
384
+ interface Preset {
385
+ name: string;
386
+ response: {
387
+ single: (raw: any) => {
388
+ data: any;
389
+ };
390
+ list: (raw: any) => {
391
+ items: any[];
392
+ meta: Record<string, any>;
393
+ };
394
+ error: (raw: any) => {
395
+ error: string;
396
+ code: string;
397
+ details?: Record<string, string>;
398
+ };
399
+ };
400
+ meta: {
401
+ page: string;
402
+ size: string;
403
+ totalItems: string;
404
+ totalPages: string;
405
+ };
406
+ query: {
407
+ filterStyle: FilterStyle;
408
+ pageParam: string;
409
+ sizeParam: string;
410
+ sortParam?: string;
411
+ sortFormat: string;
412
+ pageOffset?: number;
413
+ };
414
+ auth: {
415
+ loginUrl: string;
416
+ registerUrl: string;
417
+ logoutUrl?: string;
418
+ tokenField: string;
419
+ userField: string;
420
+ headerFormat: string;
421
+ };
422
+ }
423
+ declare function definePreset(config: Preset): Preset;
424
+
425
+ declare const defaultPreset: Preset;
426
+
427
+ declare const springBootPreset: Preset;
428
+
429
+ declare const laravelPreset: Preset;
430
+
431
+ declare const djangoPreset: Preset;
432
+
433
+ declare const nestjsPreset: Preset;
434
+
435
+ declare const expressPreset: Preset;
436
+
437
+ declare function getPreset(name: string): Preset;
438
+
439
+ export { type ApiResponse, type AuthContext, AuthService, type AuthState, type BaseFields, ConflictError, type Driver, type DriverConfig, Entity, type EventAction, EventBus, type EventHandler, type EventHandlersConfig, type EventSourceAdapter, type EventSourceConfig, type EventsConfig, FauxbaseError, type FauxbaseErrorPayload, type FauxbaseEvent, type FieldOptions, type FilterOperator, type FilterStyle, ForbiddenError, type HookType, HttpDriver, type HttpDriverConfig, HttpError, LocalDriver, type LocalDriverConfig, type LoginCredentials, NetworkError, NotFoundError, type PageMeta, type PagedResponse, type Preset, type QueryParams, type SSEConfig, type STOMPConfig, type SeedDefinition, Service, type SortParams, TimeoutError, ValidationError, afterCreate, afterUpdate, beforeCreate, beforeUpdate, computed, createClient, defaultPreset, definePreset, djangoPreset, expressPreset, field, getPreset, laravelPreset, nestjsPreset, relation, seed, springBootPreset };
package/dist/index.d.ts CHANGED
@@ -48,12 +48,19 @@ interface FieldOptions {
48
48
  }
49
49
  interface LocalDriverConfig {
50
50
  type: 'local';
51
- persist?: 'memory' | 'localStorage';
51
+ persist?: 'memory' | 'localStorage' | 'indexeddb';
52
+ dbName?: string;
52
53
  }
53
54
  interface HttpDriverConfig {
54
55
  type: 'http';
55
56
  baseUrl: string;
56
57
  preset?: string;
58
+ timeout?: number;
59
+ retry?: {
60
+ maxRetries?: number;
61
+ baseDelay?: number;
62
+ };
63
+ headers?: Record<string, string>;
57
64
  }
58
65
  type DriverConfig = LocalDriverConfig | HttpDriverConfig;
59
66
  interface SeedDefinition<T = any> {
@@ -81,6 +88,22 @@ declare class ValidationError extends FauxbaseError {
81
88
  declare class ForbiddenError extends FauxbaseError {
82
89
  constructor(message?: string);
83
90
  }
91
+ declare class NetworkError extends FauxbaseError {
92
+ constructor(message?: string);
93
+ }
94
+ declare class TimeoutError extends FauxbaseError {
95
+ constructor(message?: string);
96
+ }
97
+ declare class HttpError extends FauxbaseError {
98
+ readonly status: number;
99
+ constructor(message: string, status: number, details?: Record<string, string>);
100
+ toJSON(): {
101
+ status: number;
102
+ error: string;
103
+ code: string;
104
+ details?: Record<string, string>;
105
+ };
106
+ }
84
107
 
85
108
  declare abstract class Entity {
86
109
  id: string;
@@ -120,6 +143,51 @@ interface Driver {
120
143
  clear(resource: string): void;
121
144
  }
122
145
 
146
+ type EventAction = 'created' | 'updated' | 'deleted' | 'bulkCreated' | 'bulkUpdated' | 'bulkDeleted';
147
+ interface FauxbaseEvent<T = any> {
148
+ action: EventAction;
149
+ resource: string;
150
+ data?: T;
151
+ id?: string;
152
+ ids?: string[];
153
+ timestamp: number;
154
+ source: 'local' | 'remote';
155
+ }
156
+ type EventHandler<T = any> = (event: FauxbaseEvent<T>) => void;
157
+ interface EventSourceAdapter {
158
+ connect(): void;
159
+ disconnect(): void;
160
+ }
161
+ interface SSEConfig {
162
+ type: 'sse';
163
+ url: string;
164
+ eventMap: Record<string, string>;
165
+ withCredentials?: boolean;
166
+ }
167
+ interface STOMPConfig {
168
+ type: 'stomp';
169
+ brokerUrl: string;
170
+ subscriptions: Record<string, string>;
171
+ connectHeaders?: Record<string, string>;
172
+ }
173
+ type EventSourceConfig = SSEConfig | STOMPConfig;
174
+ interface EventHandlersConfig {
175
+ [resource: string]: EventHandler;
176
+ }
177
+ type EventsConfig = true | {
178
+ source?: EventSourceConfig;
179
+ handlers?: EventHandlersConfig;
180
+ };
181
+
182
+ declare class EventBus {
183
+ private listeners;
184
+ private anyListeners;
185
+ on(resource: string, handler: EventHandler): () => void;
186
+ onAny(handler: EventHandler): () => void;
187
+ emit(event: FauxbaseEvent): void;
188
+ destroy(): void;
189
+ }
190
+
123
191
  declare function beforeCreate(): MethodDecorator;
124
192
  declare function beforeUpdate(): MethodDecorator;
125
193
  declare function afterCreate(): MethodDecorator;
@@ -129,8 +197,13 @@ declare abstract class Service<T extends Entity> {
129
197
  abstract endpoint: string;
130
198
  protected driver: Driver;
131
199
  protected resourceName: string;
200
+ protected client: any;
201
+ /** @internal */
202
+ _eventBus?: EventBus;
132
203
  /** @internal — called by createClient to wire the service */
133
204
  _init(driver: Driver, resourceName: string): void;
205
+ /** @internal — called by createClient to give services access to the client */
206
+ _setClient(client: any): void;
134
207
  list(query?: QueryParams): Promise<PagedResponse<T>>;
135
208
  get(id: string): Promise<ApiResponse<T>>;
136
209
  create(data: Partial<T>): Promise<ApiResponse<T>>;
@@ -138,27 +211,229 @@ declare abstract class Service<T extends Entity> {
138
211
  delete(id: string): Promise<ApiResponse<T>>;
139
212
  count(filter?: Record<string, any>): Promise<number>;
140
213
  get bulk(): {
141
- create: (items: Array<Partial<T>>) => Promise<ApiResponse<T[]>>;
142
- update: (updates: Array<{
214
+ create(items: Array<Partial<T>>): Promise<ApiResponse<T[]>>;
215
+ update(updates: Array<{
143
216
  id: string;
144
217
  data: Partial<T>;
145
- }>) => Promise<ApiResponse<T[]>>;
146
- delete: (ids: string[]) => Promise<ApiResponse<{
218
+ }>): Promise<ApiResponse<T[]>>;
219
+ delete(ids: string[]): Promise<ApiResponse<{
147
220
  count: number;
148
221
  }>>;
149
222
  };
223
+ private emitEvent;
150
224
  private runHooks;
151
225
  }
152
226
 
227
+ type AuthProvider$1 = () => {
228
+ token: string;
229
+ } | null;
230
+ interface HttpDriverOptions extends HttpDriverConfig {
231
+ timeout?: number;
232
+ retry?: {
233
+ maxRetries?: number;
234
+ baseDelay?: number;
235
+ };
236
+ headers?: Record<string, string>;
237
+ }
238
+ declare class HttpDriver implements Driver {
239
+ private baseUrl;
240
+ private preset;
241
+ private timeout;
242
+ private maxRetries;
243
+ private baseDelay;
244
+ private defaultHeaders;
245
+ private endpoints;
246
+ private authProvider;
247
+ constructor(config: HttpDriverOptions);
248
+ setAuthProvider(provider: AuthProvider$1): void;
249
+ registerEndpoint(resource: string, endpoint: string): void;
250
+ private getEndpoint;
251
+ private buildUrl;
252
+ private buildHeaders;
253
+ private request;
254
+ private throwMappedError;
255
+ list<T>(resource: string, query: QueryParams): Promise<PagedResponse<T>>;
256
+ get<T>(resource: string, id: string): Promise<ApiResponse<T>>;
257
+ create<T>(resource: string, data: Partial<T>): Promise<ApiResponse<T>>;
258
+ update<T>(resource: string, id: string, data: Partial<T>): Promise<ApiResponse<T>>;
259
+ delete<T>(resource: string, id: string): Promise<ApiResponse<T>>;
260
+ count(resource: string, filter?: Record<string, any>): Promise<number>;
261
+ bulkCreate<T>(resource: string, data: Array<Partial<T>>): Promise<ApiResponse<T[]>>;
262
+ bulkUpdate<T>(resource: string, updates: Array<{
263
+ id: string;
264
+ data: Partial<T>;
265
+ }>): Promise<ApiResponse<T[]>>;
266
+ bulkDelete(resource: string, ids: string[]): Promise<ApiResponse<{
267
+ count: number;
268
+ }>>;
269
+ seed(): void;
270
+ getSeedVersion(): string | null;
271
+ setSeedVersion(): void;
272
+ clear(): void;
273
+ }
274
+
275
+ interface LoginCredentials {
276
+ email: string;
277
+ password: string;
278
+ }
279
+ interface AuthState {
280
+ userId: string;
281
+ email: string;
282
+ userName?: string;
283
+ role?: string;
284
+ token: string;
285
+ }
286
+ interface AuthContext {
287
+ userId: string;
288
+ userName?: string;
289
+ }
290
+ declare abstract class AuthService<T extends Entity> extends Service<T> {
291
+ private authState;
292
+ private saveState;
293
+ private httpDriver;
294
+ /** @internal — called by createClient to wire persistence */
295
+ _initAuth(loadState: () => AuthState | null, saveState: (state: AuthState | null) => void): void;
296
+ /** @internal — called by createClient when using HttpDriver */
297
+ _setHttpMode(driver: HttpDriver): void;
298
+ login(credentials: LoginCredentials): Promise<T>;
299
+ register(data: Partial<T>): Promise<T>;
300
+ logout(): void;
301
+ get currentUser(): T | null;
302
+ get isLoggedIn(): boolean;
303
+ get token(): string | null;
304
+ hasRole(role: string): boolean;
305
+ getAuthContext(): AuthContext | null;
306
+ private localLogin;
307
+ private localRegister;
308
+ private httpLogin;
309
+ private httpRegister;
310
+ private generateToken;
311
+ private persistState;
312
+ }
313
+
153
314
  type ClientServices<S extends Record<string, new (...args: any[]) => Service<any>>> = {
154
315
  [K in keyof S]: InstanceType<S[K]>;
155
316
  };
156
- declare function createClient<S extends Record<string, new (...args: any[]) => Service<any>>>(config: {
317
+ type ClientResult<S extends Record<string, new (...args: any[]) => Service<any>>, A extends (new (...args: any[]) => AuthService<any>) | undefined> = ClientServices<S> & (A extends new (...args: any[]) => AuthService<any> ? {
318
+ auth: InstanceType<A>;
319
+ } : {}) & {
320
+ readonly ready: Promise<void>;
321
+ } & {
322
+ _eventBus?: EventBus;
323
+ disconnect?: () => void;
324
+ };
325
+ declare function createClient<S extends Record<string, new (...args: any[]) => Service<any>>, A extends (new (...args: any[]) => AuthService<any>) | undefined = undefined>(config: {
157
326
  driver?: DriverConfig;
158
327
  services: S;
159
328
  seeds?: SeedDefinition[];
160
- }): ClientServices<S>;
329
+ auth?: A;
330
+ overrides?: Record<string, {
331
+ driver: DriverConfig;
332
+ }>;
333
+ events?: EventsConfig;
334
+ }): ClientResult<S, A>;
161
335
 
162
336
  declare function seed<T>(entityClass: new (...args: any[]) => T, data: Array<Partial<T>>): SeedDefinition<T>;
163
337
 
164
- export { type ApiResponse, type BaseFields, ConflictError, type Driver, type DriverConfig, Entity, FauxbaseError, type FauxbaseErrorPayload, type FieldOptions, type FilterOperator, ForbiddenError, type HookType, type HttpDriverConfig, type LocalDriverConfig, NotFoundError, type PageMeta, type PagedResponse, type QueryParams, type SeedDefinition, Service, type SortParams, ValidationError, afterCreate, afterUpdate, beforeCreate, beforeUpdate, computed, createClient, field, relation, seed };
338
+ interface StorageBackend {
339
+ getAll(resource: string): Record<string, any>[];
340
+ getById(resource: string, id: string): Record<string, any> | undefined;
341
+ set(resource: string, id: string, data: Record<string, any>): void;
342
+ remove(resource: string, id: string): void;
343
+ clear(resource: string): void;
344
+ getMeta(key: string): string | null;
345
+ setMeta(key: string, value: string): void;
346
+ }
347
+ type AuthProvider = () => {
348
+ userId: string;
349
+ userName?: string;
350
+ } | null;
351
+ declare class LocalDriver implements Driver {
352
+ private storage;
353
+ private entityClasses;
354
+ private authProvider;
355
+ private _ready;
356
+ private _isReady;
357
+ constructor(config: LocalDriverConfig);
358
+ get ready(): Promise<void>;
359
+ get isReady(): boolean;
360
+ setAuthProvider(provider: AuthProvider): void;
361
+ getStorageBackend(): StorageBackend;
362
+ registerEntity(resource: string, entityClass: Function): void;
363
+ list<T>(resource: string, query: QueryParams): Promise<PagedResponse<T>>;
364
+ get<T>(resource: string, id: string): Promise<ApiResponse<T>>;
365
+ create<T>(resource: string, data: Partial<T>): Promise<ApiResponse<T>>;
366
+ update<T>(resource: string, id: string, data: Partial<T>): Promise<ApiResponse<T>>;
367
+ delete<T>(resource: string, id: string): Promise<ApiResponse<T>>;
368
+ count(resource: string, filter?: Record<string, any>): Promise<number>;
369
+ bulkCreate<T>(resource: string, data: Array<Partial<T>>): Promise<ApiResponse<T[]>>;
370
+ bulkUpdate<T>(resource: string, updates: Array<{
371
+ id: string;
372
+ data: Partial<T>;
373
+ }>): Promise<ApiResponse<T[]>>;
374
+ bulkDelete(resource: string, ids: string[]): Promise<ApiResponse<{
375
+ count: number;
376
+ }>>;
377
+ seed(resource: string, data: Array<Record<string, any>>, entityClass: Function): void;
378
+ getSeedVersion(): string | null;
379
+ setSeedVersion(version: string): void;
380
+ clear(resource: string): void;
381
+ }
382
+
383
+ type FilterStyle = 'django' | 'dot' | 'bracket' | 'nestjs';
384
+ interface Preset {
385
+ name: string;
386
+ response: {
387
+ single: (raw: any) => {
388
+ data: any;
389
+ };
390
+ list: (raw: any) => {
391
+ items: any[];
392
+ meta: Record<string, any>;
393
+ };
394
+ error: (raw: any) => {
395
+ error: string;
396
+ code: string;
397
+ details?: Record<string, string>;
398
+ };
399
+ };
400
+ meta: {
401
+ page: string;
402
+ size: string;
403
+ totalItems: string;
404
+ totalPages: string;
405
+ };
406
+ query: {
407
+ filterStyle: FilterStyle;
408
+ pageParam: string;
409
+ sizeParam: string;
410
+ sortParam?: string;
411
+ sortFormat: string;
412
+ pageOffset?: number;
413
+ };
414
+ auth: {
415
+ loginUrl: string;
416
+ registerUrl: string;
417
+ logoutUrl?: string;
418
+ tokenField: string;
419
+ userField: string;
420
+ headerFormat: string;
421
+ };
422
+ }
423
+ declare function definePreset(config: Preset): Preset;
424
+
425
+ declare const defaultPreset: Preset;
426
+
427
+ declare const springBootPreset: Preset;
428
+
429
+ declare const laravelPreset: Preset;
430
+
431
+ declare const djangoPreset: Preset;
432
+
433
+ declare const nestjsPreset: Preset;
434
+
435
+ declare const expressPreset: Preset;
436
+
437
+ declare function getPreset(name: string): Preset;
438
+
439
+ export { type ApiResponse, type AuthContext, AuthService, type AuthState, type BaseFields, ConflictError, type Driver, type DriverConfig, Entity, type EventAction, EventBus, type EventHandler, type EventHandlersConfig, type EventSourceAdapter, type EventSourceConfig, type EventsConfig, FauxbaseError, type FauxbaseErrorPayload, type FauxbaseEvent, type FieldOptions, type FilterOperator, type FilterStyle, ForbiddenError, type HookType, HttpDriver, type HttpDriverConfig, HttpError, LocalDriver, type LocalDriverConfig, type LoginCredentials, NetworkError, NotFoundError, type PageMeta, type PagedResponse, type Preset, type QueryParams, type SSEConfig, type STOMPConfig, type SeedDefinition, Service, type SortParams, TimeoutError, ValidationError, afterCreate, afterUpdate, beforeCreate, beforeUpdate, computed, createClient, defaultPreset, definePreset, djangoPreset, expressPreset, field, getPreset, laravelPreset, nestjsPreset, relation, seed, springBootPreset };