@web-ts-toolkit/access-router-client 0.32.0 → 0.34.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.
Files changed (7) hide show
  1. package/README.md +258 -14
  2. package/index.d.mts +453 -85
  3. package/index.d.ts +453 -85
  4. package/index.js +1133 -368
  5. package/index.mjs +1133 -368
  6. package/llms.txt +39 -5
  7. package/package.json +11 -4
package/llms.txt CHANGED
@@ -15,8 +15,10 @@ const userService = adapter.createModelService<User>({
15
15
  });
16
16
 
17
17
  const user = await userService.read('user-id-1');
18
- user.data.role = 'owner';
19
- await user.data.save();
18
+ if (user.success) {
19
+ user.data.role = 'owner';
20
+ await user.data.save();
21
+ }
20
22
  ```
21
23
 
22
24
  Data service for in-memory `access-router` data routes:
@@ -37,17 +39,49 @@ const grouped = await adapter.group(
37
39
  );
38
40
  ```
39
41
 
42
+ ## Unreleased Migration
43
+
44
+ - subdocument results are now plain data; replace subdocument `Model.save()` and `totalCount` usage with parent-scoped helper mutations and `SubDocumentListResponse.count`
45
+ - subdocument create always returns the post-create array; model `create`/`createAdvanced` preserve scalar-versus-array input cardinality
46
+ - narrow `Response` on `success`; failure `data` is `null` and structured errors live in `raw`
47
+ - enabled caches are GET-only, identity-partitioned for credentials, and bounded to 100 LRU entries by default; caching remains disabled when `cacheTTL: 0`
48
+ - each lazy request can execute directly or in one group, never both or repeatedly; grouped requests require one effective `throwOnError` policy, run all callbacks, and expose `{}` per-entry headers
49
+ - remove data-service `includePermissions`, use string data sort, and call `countAdvanced(filter, config?)`; use the named filter escape hatches only for intentional dynamic/cast filters
50
+ - pass raw dynamic path values, reuse caller configs safely, and handle `MissingPersistenceIdentityError` when an existing projected model has no recoverable id
51
+
40
52
  ## Gotchas
41
53
 
42
- - depends on `axios`; bring your own `axios`-compatible runtime
54
+ - supports **browsers and Node** (maintainer decision, ARC-19). Bundle target is `es2022`; `engines.node: ">=22"`, `browserslist: ["supports es2022-module"]`. The source imports no Node built-ins; the cache `unref()` guard is feature-detected and a no-op in browsers.
55
+ - `withCredentials: true` is the adapter default; in the browser this transmits cookies + `Authorization`. In Node it forces Axios to send the `Cookie` header you set manually. Credentialed caching still requires an explicit `cachePartition` token so one identity cannot receive another's cached response.
56
+ - caching is disabled by default (`cacheTTL: 0`). When enabled, only GET requests with supported JSON/text semantics cache or deduplicate, custom transforms/serializers and cancellation-sensitive requests bypass caching, and the default LRU capacity is 100 entries.
57
+ - `axios` is a regular runtime dependency (declared in `package.json` `dependencies`); an installed consumer does not need to add axios separately. Use it as a peer only if you intentionally dedupe against an existing axios install.
43
58
  - service methods return lazy requests; they do not execute until `await`, `.then()`, `.exec()`, etc.
44
59
  - `adapter.group(...)` only batches lazy requests from this client, not raw Axios calls
60
+ - grouped requests must have one effective `throwOnError` policy after per-call/service/adapter precedence; mixed policies reject before dispatch. Non-throwing groups return all partial-failure entries. Throwing groups invoke every executed entry callback once, then reject with the first failed entry's `ServiceError`. Group entry `headers` are `{}` because root responses do not carry per-operation headers
45
61
  - the client `basePath` is relative to the adapter `baseURL`, not the full server path
46
62
  - match `queryPath`/`mutationPath` to the server-side `queryRouteSegment` and mutation route configuration
63
+ - each dynamic URL path segment (identifiers, `distinct` field, subdocument `id`/`sub`/`subId`, wrapper `pathParams` values) is `encodeURIComponent`-encoded exactly once; already-encoded inputs are re-encoded so a single server-side decode returns the literal input
64
+ - caller-owned `axiosRequestConfig`, headers (including `AxiosHeaders` instances), and wrapper default configs are never mutated by service methods or wrap helpers; the same config object can be reused across many requests without acquiring hidden cache controls or `params`
65
+ - the client request contract mirrors the sibling `@web-ts-toolkit/access-router` server:
66
+ - `distinctAdvanced(field, filter, ...)` sends `{ filter }` as the request body, not the bare conditions, so the server honors the filter
67
+ - `DataService<T>` does not advertise `includePermissions` — the data routers do not parse `include_permissions`; data records are returned without `_permissions`
68
+ - `DataService<T>` `listAdvanced.args.sort` is `string` (`'age'` / `'-age'`), not the general `Sort` union rejected by the server
69
+ - `ModelService<T>.update(...)` and `ModelService<T>.upsert(...)` accept `includePermissions` and transmit it as the `include_permissions` query parameter
70
+ - `countAdvanced(filter, axiosRequestConfig?)` no longer accepts an `access` argument the server rejects
71
+ - `SubDocumentListResponse<S>` carries `count` (the server's field), not `totalCount`; `ListModelResponse<T>` still carries `totalCount`
72
+ - subdocument `create(data | data[], ...)` accepts a single object or an array; the response is always the post-create subdocument array
73
+ - `Response<TRaw, TData = TRaw, TError = unknown>` is a discriminated union (`SuccessResult<TRaw, TData> | FailureResult<TError>`); branch on `result.success` to narrow `raw`/`data`. On `success: false`, `data` is always `null` and `raw` is the unknown (or opt-in typed) server error payload. Only model/data list responses carry `totalCount`; subdocument list-like responses carry `count`; scalar and single responses carry neither
47
74
  - this package targets `@web-ts-toolkit/access-router` servers; plain Axios is simpler for non-access-router APIs
48
75
  - imports are named-only (`import { createAdapter }`); there is no default export
76
+ - the public export surface is locked by `access-router-client.exports.unit.test.ts`. Only these names are part of the supported root API:
77
+ - runtime values: `createAdapter`, `ModelService`, `DataService`, `Service`, `ServiceError`, `MissingPersistenceIdentityError`, `Model`, `CustomHeaders`, `wrapLazyPromise`, `replaceItemById`, `removeItemById`
78
+ - type/interface exports (named via `import type`): `AdapterOptions`, `ModelServiceOptions`, `DataServiceOptions`, `CacheController`, `CachePartitioner`, `Response`, `SuccessResult`, `FailureResult`, `ModelResponse`, `ArrayModelResponse`, `ListModelResponse`, `DataResponse`, `ArrayDataResponse`, `ListDataResponse`, `SubDocumentResponse`, `SubDocumentListResponse`, `Document`, `Projection`, `KeyValueProjection`, `SelectedKeys`, `SelectedShape`, `ResolvedSelectedShape`, `Sort`, `SortOrder`, `FilterQuery`, `DottedPathFilter`, `ServerSideCast`, `Populate`, `PopulateAccess`, `Include`, `Task`, `SubQueryOptions`, `WrapOptions`, `ResultError`, `ResponseCallback`, `AdditionalReqConfig`, `Defaults`, `DataDefaults`, `LazyRequest`, `ModelRequest`, `DataRequest`, `ModelPromiseMeta`, `DataPromiseMeta`, `RootModelQueryMeta`, `RootDataQueryMeta`, `RootQueryMeta`, `ListArgs`, `ListOptions`, `ListAdvancedArgs`, `ListAdvancedOptions`, `ReadOptions`, `ReadAdvancedArgs`, `ReadAdvancedOptions`, `CreateOptions`, `CreateAdvancedArgs`, `CreateAdvancedOptions`, `UpdateOptions`, `UpdateAdvancedArgs`, `UpdateAdvancedOptions`, `UpsertOptions`, `UpsertAdvancedArgs`, `UpsertAdvancedOptions`, `DataListArgs`, `DataListOptions`, `DataListAdvancedArgs`, `DataListAdvancedOptions`, `DataReadOptions`, `DataReadAdvancedArgs`, `DataReadAdvancedOptions`
79
+
80
+ Model `create(...)` and `createAdvanced(...)` preserve cardinality: object input returns `ModelResponse<T>`; array input returns `ArrayModelResponse<T>`, even for one item.
81
+ - any name not listed above is implementation-internal and must not be relied on. Configure caching through `AdapterOptions` (`cacheTTL`, `cachePartition`, `cacheCapacity`); control an existing cache through the adapter's `clearCache()` and `disposeCache()` methods; configure `throwOnError` per-service or per-call rather than reaching for `applyResponseCallbacks` directly.
49
82
 
50
83
  ## Pointers
51
84
 
52
- - README: installation, quickstart, main exports
53
- - website/docs/packages/access-router-client/: full documentation (adapter, services, model, typing and errors)
85
+ - README: installation, quickstart, main exports, browser+Node runtime matrix
86
+ - website (not packed into the npm tarball; use the live URLs after install): full documentation online at https://web-ts-toolkit.pages.dev/docs/packages/access-router-client (adapter, services, model, typing and errors)
87
+ - `pnpm --filter @web-ts-toolkit/access-router-client test:browser-smoke`: jsdom+Vite browser smoke test that imports the built bundle
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.32.0",
5
+ "version": "0.34.0",
6
6
  "sideEffects": false,
7
7
  "keywords": [
8
8
  "axios",
@@ -16,17 +16,24 @@
16
16
  "types": "./index.d.ts",
17
17
  "exports": {
18
18
  ".": {
19
- "types": "./index.d.ts",
19
+ "types": {
20
+ "import": "./index.d.mts",
21
+ "require": "./index.d.ts",
22
+ "default": "./index.d.ts"
23
+ },
20
24
  "import": "./index.mjs",
21
25
  "require": "./index.js",
22
26
  "default": "./index.js"
23
27
  }
24
28
  },
25
29
  "engines": {
26
- "node": ">=20"
30
+ "node": ">=22"
27
31
  },
32
+ "browserslist": [
33
+ "supports es2022-module"
34
+ ],
28
35
  "dependencies": {
29
- "@web-ts-toolkit/utils": "0.32.0",
36
+ "@web-ts-toolkit/utils": "0.34.0",
30
37
  "axios": "^1.18.1"
31
38
  },
32
39
  "files": [