fauxbase 0.5.4 → 0.5.5
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.cjs +12 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -141,6 +141,7 @@ interface Driver {
|
|
|
141
141
|
method?: string;
|
|
142
142
|
body?: any;
|
|
143
143
|
query?: Record<string, string>;
|
|
144
|
+
local?: () => R | Promise<R>;
|
|
144
145
|
}): Promise<R>;
|
|
145
146
|
seed(resource: string, data: Array<Record<string, any>>, entityClass: Function): void;
|
|
146
147
|
getSeedVersion(): string | null;
|
|
@@ -232,6 +233,7 @@ declare abstract class Service<T extends Entity> {
|
|
|
232
233
|
method?: string;
|
|
233
234
|
body?: any;
|
|
234
235
|
query?: Record<string, string>;
|
|
236
|
+
local?: () => R | Promise<R>;
|
|
235
237
|
}): Promise<R>;
|
|
236
238
|
private emitEvent;
|
|
237
239
|
private runHooks;
|
|
@@ -283,6 +285,7 @@ declare class HttpDriver implements Driver {
|
|
|
283
285
|
method?: string;
|
|
284
286
|
body?: any;
|
|
285
287
|
query?: Record<string, string>;
|
|
288
|
+
local?: () => R | Promise<R>;
|
|
286
289
|
}): Promise<R>;
|
|
287
290
|
seed(): void;
|
|
288
291
|
getSeedVersion(): string | null;
|
|
@@ -395,10 +398,11 @@ declare class LocalDriver implements Driver {
|
|
|
395
398
|
bulkDelete(resource: string, ids: string[]): Promise<ApiResponse<{
|
|
396
399
|
count: number;
|
|
397
400
|
}>>;
|
|
398
|
-
request<R = any>(_resource: string, _path: string,
|
|
401
|
+
request<R = any>(_resource: string, _path: string, options?: {
|
|
399
402
|
method?: string;
|
|
400
403
|
body?: any;
|
|
401
404
|
query?: Record<string, string>;
|
|
405
|
+
local?: () => R | Promise<R>;
|
|
402
406
|
}): Promise<R>;
|
|
403
407
|
seed(resource: string, data: Array<Record<string, any>>, entityClass: Function): void;
|
|
404
408
|
getSeedVersion(): string | null;
|
package/dist/index.d.ts
CHANGED
|
@@ -141,6 +141,7 @@ interface Driver {
|
|
|
141
141
|
method?: string;
|
|
142
142
|
body?: any;
|
|
143
143
|
query?: Record<string, string>;
|
|
144
|
+
local?: () => R | Promise<R>;
|
|
144
145
|
}): Promise<R>;
|
|
145
146
|
seed(resource: string, data: Array<Record<string, any>>, entityClass: Function): void;
|
|
146
147
|
getSeedVersion(): string | null;
|
|
@@ -232,6 +233,7 @@ declare abstract class Service<T extends Entity> {
|
|
|
232
233
|
method?: string;
|
|
233
234
|
body?: any;
|
|
234
235
|
query?: Record<string, string>;
|
|
236
|
+
local?: () => R | Promise<R>;
|
|
235
237
|
}): Promise<R>;
|
|
236
238
|
private emitEvent;
|
|
237
239
|
private runHooks;
|
|
@@ -283,6 +285,7 @@ declare class HttpDriver implements Driver {
|
|
|
283
285
|
method?: string;
|
|
284
286
|
body?: any;
|
|
285
287
|
query?: Record<string, string>;
|
|
288
|
+
local?: () => R | Promise<R>;
|
|
286
289
|
}): Promise<R>;
|
|
287
290
|
seed(): void;
|
|
288
291
|
getSeedVersion(): string | null;
|
|
@@ -395,10 +398,11 @@ declare class LocalDriver implements Driver {
|
|
|
395
398
|
bulkDelete(resource: string, ids: string[]): Promise<ApiResponse<{
|
|
396
399
|
count: number;
|
|
397
400
|
}>>;
|
|
398
|
-
request<R = any>(_resource: string, _path: string,
|
|
401
|
+
request<R = any>(_resource: string, _path: string, options?: {
|
|
399
402
|
method?: string;
|
|
400
403
|
body?: any;
|
|
401
404
|
query?: Record<string, string>;
|
|
405
|
+
local?: () => R | Promise<R>;
|
|
402
406
|
}): Promise<R>;
|
|
403
407
|
seed(resource: string, data: Array<Record<string, any>>, entityClass: Function): void;
|
|
404
408
|
getSeedVersion(): string | null;
|
package/dist/index.js
CHANGED
|
@@ -242,6 +242,13 @@ var Service = class {
|
|
|
242
242
|
};
|
|
243
243
|
}
|
|
244
244
|
async request(path, options) {
|
|
245
|
+
if (options?.local) {
|
|
246
|
+
try {
|
|
247
|
+
return this.driver.request(this.resourceName, path, options);
|
|
248
|
+
} catch {
|
|
249
|
+
return options.local();
|
|
250
|
+
}
|
|
251
|
+
}
|
|
245
252
|
return this.driver.request(this.resourceName, path, options);
|
|
246
253
|
}
|
|
247
254
|
emitEvent(action, extra) {
|
|
@@ -888,9 +895,12 @@ var LocalDriver = class {
|
|
|
888
895
|
}
|
|
889
896
|
return { data: { count } };
|
|
890
897
|
}
|
|
891
|
-
async request(_resource, _path,
|
|
898
|
+
async request(_resource, _path, options) {
|
|
899
|
+
if (options?.local) {
|
|
900
|
+
return options.local();
|
|
901
|
+
}
|
|
892
902
|
throw new Error(
|
|
893
|
-
"service.request() is only available with the HTTP driver.
|
|
903
|
+
"service.request() is only available with the HTTP driver. Provide a `local` handler or switch to HTTP driver."
|
|
894
904
|
);
|
|
895
905
|
}
|
|
896
906
|
// --- Seed management (synchronous) ---
|