@web-ts-toolkit/access-router-client 0.5.0 → 0.6.1
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/index.d.mts +23 -5
- package/index.d.ts +23 -5
- package/index.js +0 -4
- package/index.mjs +0 -4
- package/llms.txt +53 -0
- package/package.json +2 -2
package/index.d.mts
CHANGED
|
@@ -232,6 +232,14 @@ interface Props$1 {
|
|
|
232
232
|
onFailure: ResponseCallback;
|
|
233
233
|
throwOnError: boolean;
|
|
234
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* Typed client for `access-router` model CRUD routes. Created by
|
|
237
|
+
* `adapter.createModelService<T>(...)`.
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* const userService = adapter.createModelService<User>({ modelName: 'User', basePath: 'users' });
|
|
241
|
+
* const user = await userService.read('user-id-1');
|
|
242
|
+
*/
|
|
235
243
|
declare class ModelService<T extends Document> extends Service {
|
|
236
244
|
private _modelName;
|
|
237
245
|
private _queryPath;
|
|
@@ -304,6 +312,13 @@ interface Props {
|
|
|
304
312
|
onFailure: ResponseCallback;
|
|
305
313
|
throwOnError: boolean;
|
|
306
314
|
}
|
|
315
|
+
/**
|
|
316
|
+
* Typed client for `access-router` in-memory data routes. Created by
|
|
317
|
+
* `adapter.createDataService<T>(...)`.
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* const fruitService = adapter.createDataService<Fruit>({ dataName: 'fruit', basePath: 'fruit' });
|
|
321
|
+
*/
|
|
307
322
|
declare class DataService<T> extends Service {
|
|
308
323
|
private _dataName;
|
|
309
324
|
private _queryPath;
|
|
@@ -541,6 +556,13 @@ interface DataServiceOptions {
|
|
|
541
556
|
onFailure?: ResponseCallback;
|
|
542
557
|
throwOnError?: boolean;
|
|
543
558
|
}
|
|
559
|
+
/**
|
|
560
|
+
* Creates a typed API adapter for `@web-ts-toolkit/access-router` model and data routes.
|
|
561
|
+
*
|
|
562
|
+
* @example
|
|
563
|
+
* const adapter = createAdapter({ baseURL: 'http://localhost:3000/api' });
|
|
564
|
+
* const userService = adapter.createModelService<User>({ modelName: 'User', basePath: 'users' });
|
|
565
|
+
*/
|
|
544
566
|
declare function createAdapter(axiosConfig?: AxiosRequestConfig, adapterOptions?: AdapterOptions): Readonly<{
|
|
545
567
|
axios: axios.AxiosInstance;
|
|
546
568
|
createModelService: <T>({ modelName, basePath, queryPath, mutationPath, onSuccess, onFailure, throwOnError, }: ModelServiceOptions, defaults?: Defaults) => ModelService<T>;
|
|
@@ -572,8 +594,4 @@ declare function removeItemById<T extends {
|
|
|
572
594
|
_id: string;
|
|
573
595
|
}>(items: T[], targetItem: T): T[];
|
|
574
596
|
|
|
575
|
-
|
|
576
|
-
createAdapter: typeof createAdapter;
|
|
577
|
-
};
|
|
578
|
-
|
|
579
|
-
export { type AdditionalReqConfig, type ArrayDataResponse, type ArrayModelResponse, type CreateAdvancedArgs, type CreateAdvancedOptions, type CreateOptions, CustomHeaders, type DataDefaults, type DataListAdvancedArgs, type DataListAdvancedOptions, type DataListArgs, type DataListOptions, type DataPromiseMeta, type DataReadAdvancedArgs, type DataReadAdvancedOptions, type DataReadOptions, type DataRequest, type DataResponse, DataService, type Defaults, type Document, type FilterQuery, type Include, type KeyValueProjection, type LazyRequest, type ListAdvancedArgs, type ListAdvancedOptions, type ListArgs, type ListDataResponse, type ListModelResponse, type ListOptions, Model, type ModelPromiseMeta, type ModelRequest, type ModelResponse, ModelService, type Populate, type PopulateAccess, type Projection, type ReadAdvancedArgs, type ReadAdvancedOptions, type ReadOptions, type ResolvedSelectedShape, type Response, type ResponseCallback, type ResultError, type RootDataQueryMeta, type RootModelQueryMeta, type RootQueryMeta, type SelectedKeys, type SelectedShape, Service, ServiceError, type Sort, type SortOrder, type SubQueryOptions, type Task, type UpdateAdvancedArgs, type UpdateAdvancedOptions, type UpdateOptions, type UpsertAdvancedArgs, type UpsertAdvancedOptions, type UpsertOptions, type WrapOptions, createAdapter, _default as default, removeItemById, replaceItemById, wrapLazyPromise };
|
|
597
|
+
export { type AdditionalReqConfig, type ArrayDataResponse, type ArrayModelResponse, type CreateAdvancedArgs, type CreateAdvancedOptions, type CreateOptions, CustomHeaders, type DataDefaults, type DataListAdvancedArgs, type DataListAdvancedOptions, type DataListArgs, type DataListOptions, type DataPromiseMeta, type DataReadAdvancedArgs, type DataReadAdvancedOptions, type DataReadOptions, type DataRequest, type DataResponse, DataService, type Defaults, type Document, type FilterQuery, type Include, type KeyValueProjection, type LazyRequest, type ListAdvancedArgs, type ListAdvancedOptions, type ListArgs, type ListDataResponse, type ListModelResponse, type ListOptions, Model, type ModelPromiseMeta, type ModelRequest, type ModelResponse, ModelService, type Populate, type PopulateAccess, type Projection, type ReadAdvancedArgs, type ReadAdvancedOptions, type ReadOptions, type ResolvedSelectedShape, type Response, type ResponseCallback, type ResultError, type RootDataQueryMeta, type RootModelQueryMeta, type RootQueryMeta, type SelectedKeys, type SelectedShape, Service, ServiceError, type Sort, type SortOrder, type SubQueryOptions, type Task, type UpdateAdvancedArgs, type UpdateAdvancedOptions, type UpdateOptions, type UpsertAdvancedArgs, type UpsertAdvancedOptions, type UpsertOptions, type WrapOptions, createAdapter, removeItemById, replaceItemById, wrapLazyPromise };
|
package/index.d.ts
CHANGED
|
@@ -232,6 +232,14 @@ interface Props$1 {
|
|
|
232
232
|
onFailure: ResponseCallback;
|
|
233
233
|
throwOnError: boolean;
|
|
234
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* Typed client for `access-router` model CRUD routes. Created by
|
|
237
|
+
* `adapter.createModelService<T>(...)`.
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* const userService = adapter.createModelService<User>({ modelName: 'User', basePath: 'users' });
|
|
241
|
+
* const user = await userService.read('user-id-1');
|
|
242
|
+
*/
|
|
235
243
|
declare class ModelService<T extends Document> extends Service {
|
|
236
244
|
private _modelName;
|
|
237
245
|
private _queryPath;
|
|
@@ -304,6 +312,13 @@ interface Props {
|
|
|
304
312
|
onFailure: ResponseCallback;
|
|
305
313
|
throwOnError: boolean;
|
|
306
314
|
}
|
|
315
|
+
/**
|
|
316
|
+
* Typed client for `access-router` in-memory data routes. Created by
|
|
317
|
+
* `adapter.createDataService<T>(...)`.
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* const fruitService = adapter.createDataService<Fruit>({ dataName: 'fruit', basePath: 'fruit' });
|
|
321
|
+
*/
|
|
307
322
|
declare class DataService<T> extends Service {
|
|
308
323
|
private _dataName;
|
|
309
324
|
private _queryPath;
|
|
@@ -541,6 +556,13 @@ interface DataServiceOptions {
|
|
|
541
556
|
onFailure?: ResponseCallback;
|
|
542
557
|
throwOnError?: boolean;
|
|
543
558
|
}
|
|
559
|
+
/**
|
|
560
|
+
* Creates a typed API adapter for `@web-ts-toolkit/access-router` model and data routes.
|
|
561
|
+
*
|
|
562
|
+
* @example
|
|
563
|
+
* const adapter = createAdapter({ baseURL: 'http://localhost:3000/api' });
|
|
564
|
+
* const userService = adapter.createModelService<User>({ modelName: 'User', basePath: 'users' });
|
|
565
|
+
*/
|
|
544
566
|
declare function createAdapter(axiosConfig?: AxiosRequestConfig, adapterOptions?: AdapterOptions): Readonly<{
|
|
545
567
|
axios: axios.AxiosInstance;
|
|
546
568
|
createModelService: <T>({ modelName, basePath, queryPath, mutationPath, onSuccess, onFailure, throwOnError, }: ModelServiceOptions, defaults?: Defaults) => ModelService<T>;
|
|
@@ -572,8 +594,4 @@ declare function removeItemById<T extends {
|
|
|
572
594
|
_id: string;
|
|
573
595
|
}>(items: T[], targetItem: T): T[];
|
|
574
596
|
|
|
575
|
-
|
|
576
|
-
createAdapter: typeof createAdapter;
|
|
577
|
-
};
|
|
578
|
-
|
|
579
|
-
export { type AdditionalReqConfig, type ArrayDataResponse, type ArrayModelResponse, type CreateAdvancedArgs, type CreateAdvancedOptions, type CreateOptions, CustomHeaders, type DataDefaults, type DataListAdvancedArgs, type DataListAdvancedOptions, type DataListArgs, type DataListOptions, type DataPromiseMeta, type DataReadAdvancedArgs, type DataReadAdvancedOptions, type DataReadOptions, type DataRequest, type DataResponse, DataService, type Defaults, type Document, type FilterQuery, type Include, type KeyValueProjection, type LazyRequest, type ListAdvancedArgs, type ListAdvancedOptions, type ListArgs, type ListDataResponse, type ListModelResponse, type ListOptions, Model, type ModelPromiseMeta, type ModelRequest, type ModelResponse, ModelService, type Populate, type PopulateAccess, type Projection, type ReadAdvancedArgs, type ReadAdvancedOptions, type ReadOptions, type ResolvedSelectedShape, type Response, type ResponseCallback, type ResultError, type RootDataQueryMeta, type RootModelQueryMeta, type RootQueryMeta, type SelectedKeys, type SelectedShape, Service, ServiceError, type Sort, type SortOrder, type SubQueryOptions, type Task, type UpdateAdvancedArgs, type UpdateAdvancedOptions, type UpdateOptions, type UpsertAdvancedArgs, type UpsertAdvancedOptions, type UpsertOptions, type WrapOptions, createAdapter, _default as default, removeItemById, replaceItemById, wrapLazyPromise };
|
|
597
|
+
export { type AdditionalReqConfig, type ArrayDataResponse, type ArrayModelResponse, type CreateAdvancedArgs, type CreateAdvancedOptions, type CreateOptions, CustomHeaders, type DataDefaults, type DataListAdvancedArgs, type DataListAdvancedOptions, type DataListArgs, type DataListOptions, type DataPromiseMeta, type DataReadAdvancedArgs, type DataReadAdvancedOptions, type DataReadOptions, type DataRequest, type DataResponse, DataService, type Defaults, type Document, type FilterQuery, type Include, type KeyValueProjection, type LazyRequest, type ListAdvancedArgs, type ListAdvancedOptions, type ListArgs, type ListDataResponse, type ListModelResponse, type ListOptions, Model, type ModelPromiseMeta, type ModelRequest, type ModelResponse, ModelService, type Populate, type PopulateAccess, type Projection, type ReadAdvancedArgs, type ReadAdvancedOptions, type ReadOptions, type ResolvedSelectedShape, type Response, type ResponseCallback, type ResultError, type RootDataQueryMeta, type RootModelQueryMeta, type RootQueryMeta, type SelectedKeys, type SelectedShape, Service, ServiceError, type Sort, type SortOrder, type SubQueryOptions, type Task, type UpdateAdvancedArgs, type UpdateAdvancedOptions, type UpdateOptions, type UpsertAdvancedArgs, type UpsertAdvancedOptions, type UpsertOptions, type WrapOptions, createAdapter, removeItemById, replaceItemById, wrapLazyPromise };
|
package/index.js
CHANGED
|
@@ -36,7 +36,6 @@ __export(index_exports, {
|
|
|
36
36
|
Service: () => Service,
|
|
37
37
|
ServiceError: () => ServiceError,
|
|
38
38
|
createAdapter: () => createAdapter,
|
|
39
|
-
default: () => index_default,
|
|
40
39
|
removeItemById: () => removeItemById,
|
|
41
40
|
replaceItemById: () => replaceItemById,
|
|
42
41
|
wrapLazyPromise: () => wrapLazyPromise
|
|
@@ -1878,9 +1877,6 @@ function removeItemById(items, targetItem) {
|
|
|
1878
1877
|
return item._id !== targetItem._id;
|
|
1879
1878
|
});
|
|
1880
1879
|
}
|
|
1881
|
-
|
|
1882
|
-
// src/index.ts
|
|
1883
|
-
var index_default = { createAdapter };
|
|
1884
1880
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1885
1881
|
0 && (module.exports = {
|
|
1886
1882
|
CustomHeaders,
|
package/index.mjs
CHANGED
|
@@ -1833,9 +1833,6 @@ function removeItemById(items, targetItem) {
|
|
|
1833
1833
|
return item._id !== targetItem._id;
|
|
1834
1834
|
});
|
|
1835
1835
|
}
|
|
1836
|
-
|
|
1837
|
-
// src/index.ts
|
|
1838
|
-
var index_default = { createAdapter };
|
|
1839
1836
|
export {
|
|
1840
1837
|
CustomHeaders,
|
|
1841
1838
|
DataService,
|
|
@@ -1844,7 +1841,6 @@ export {
|
|
|
1844
1841
|
Service,
|
|
1845
1842
|
ServiceError,
|
|
1846
1843
|
createAdapter,
|
|
1847
|
-
index_default as default,
|
|
1848
1844
|
removeItemById,
|
|
1849
1845
|
replaceItemById,
|
|
1850
1846
|
wrapLazyPromise
|
package/llms.txt
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# @web-ts-toolkit/access-router-client
|
|
2
|
+
|
|
3
|
+
Typed Axios-based client utilities for `@web-ts-toolkit/access-router` model routers, data routers, and root batch routes.
|
|
4
|
+
|
|
5
|
+
## Main Patterns
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { createAdapter } from '@web-ts-toolkit/access-router-client';
|
|
9
|
+
|
|
10
|
+
const adapter = createAdapter({ baseURL: 'http://localhost:3000/api' });
|
|
11
|
+
|
|
12
|
+
const userService = adapter.createModelService<User>({
|
|
13
|
+
modelName: 'User',
|
|
14
|
+
basePath: 'users',
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const user = await userService.read('user-id-1');
|
|
18
|
+
user.data.role = 'owner';
|
|
19
|
+
await user.data.save();
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Data service for in-memory `access-router` data routes:
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
const fruitService = adapter.createDataService<Fruit>({
|
|
26
|
+
dataName: 'fruit',
|
|
27
|
+
basePath: 'fruit',
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Batch grouped lazy requests into one root round trip:
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
const grouped = await adapter.group(
|
|
35
|
+
userService.readAdvanced('user-id-1', { select: ['name'] }),
|
|
36
|
+
userService.countAdvanced({ role: 'admin' }),
|
|
37
|
+
);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Gotchas
|
|
41
|
+
|
|
42
|
+
- depends on `axios`; bring your own `axios`-compatible runtime
|
|
43
|
+
- service methods return lazy requests; they do not execute until `await`, `.then()`, `.exec()`, etc.
|
|
44
|
+
- `adapter.group(...)` only batches lazy requests from this client, not raw Axios calls
|
|
45
|
+
- the client `basePath` is relative to the adapter `baseURL`, not the full server path
|
|
46
|
+
- match `queryPath`/`mutationPath` to the server-side `queryRouteSegment` and mutation route configuration
|
|
47
|
+
- this package targets `@web-ts-toolkit/access-router` servers; plain Axios is simpler for non-access-router APIs
|
|
48
|
+
- imports are named-only (`import { createAdapter }`); there is no default export
|
|
49
|
+
|
|
50
|
+
## Pointers
|
|
51
|
+
|
|
52
|
+
- README: installation, quickstart, main exports
|
|
53
|
+
- website/docs/packages/access-router-client/: full documentation (adapter, services, model, typing and errors)
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@web-ts-toolkit/access-router-client",
|
|
3
3
|
"description": "Typed client utilities for @web-ts-toolkit/access-router APIs",
|
|
4
4
|
"homepage": "https://web-ts-toolkit.pages.dev/docs/packages/access-router-client",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.6.1",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"keywords": [
|
|
8
8
|
"axios",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"node": ">=20"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@web-ts-toolkit/utils": "0.
|
|
29
|
+
"@web-ts-toolkit/utils": "0.6.1",
|
|
30
30
|
"axios": "^1.7.9"
|
|
31
31
|
},
|
|
32
32
|
"author": "Junmin Ahn",
|