@web-ts-toolkit/access-router 0.32.0 → 0.33.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/README.md +101 -37
- package/advanced.d.mts +12 -1444
- package/advanced.d.ts +12 -1444
- package/advanced.js +1167 -269
- package/advanced.mjs +1178 -269
- package/index.d.mts +93 -1264
- package/index.d.ts +93 -1264
- package/index.js +1465 -489
- package/index.mjs +1354 -388
- package/llms.txt +34 -11
- package/package.json +10 -5
- package/parsers-D9B9dS0p.d.mts +1702 -0
- package/parsers-D9B9dS0p.d.ts +1702 -0
- package/processors.d.mts +72 -1
- package/processors.d.ts +72 -1
- package/processors.js +61 -13
- package/processors.mjs +62 -14
package/llms.txt
CHANGED
|
@@ -5,49 +5,72 @@ ACL-aware Express routers and in-memory data services for Mongoose-backed APIs.
|
|
|
5
5
|
## Main Patterns
|
|
6
6
|
|
|
7
7
|
```ts
|
|
8
|
-
import
|
|
8
|
+
import express from 'express';
|
|
9
|
+
import mongoose from 'mongoose';
|
|
10
|
+
import acl, { permissionsPlugin } from '@web-ts-toolkit/access-router';
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
acl.setGlobalOptions({
|
|
13
|
+
requestPermissionField: '_permissions',
|
|
14
|
+
globalPermissions(req) { return req.headers.user === 'admin' ? ['isAdmin'] : []; },
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const userSchema = new mongoose.Schema({ name: String, role: String, public: Boolean });
|
|
18
|
+
userSchema.plugin(permissionsPlugin, { modelName: 'User' });
|
|
19
|
+
mongoose.model('User', userSchema);
|
|
12
20
|
|
|
13
|
-
// model CRUD router from a Mongoose model name
|
|
14
21
|
const userRouter = acl.createRouter('User', { basePath: '/users' });
|
|
15
22
|
|
|
16
|
-
//
|
|
23
|
+
// Also: pass a mongoose.Model instance to preserve a non-default connection.
|
|
24
|
+
// acl.createRouter(UserModel, { basePath: '/users' });
|
|
25
|
+
|
|
17
26
|
const fruitRouter = acl.createDataRouter('fruit', {
|
|
18
27
|
basePath: '/fruit',
|
|
19
28
|
idField: 'id',
|
|
20
29
|
data: [{ id: 'apple', name: 'Apple' }],
|
|
21
30
|
});
|
|
22
31
|
|
|
23
|
-
// OpenAPI + Swagger UI
|
|
24
32
|
const docsRouter = acl.createOpenApiRouter({ title: 'Example API', version: '1.0.0' });
|
|
25
33
|
```
|
|
26
34
|
|
|
27
35
|
Validation adapters:
|
|
28
36
|
|
|
29
37
|
```ts
|
|
38
|
+
import { z } from 'zod';
|
|
30
39
|
import { fromZod, defineRequestSchema } from '@web-ts-toolkit/access-router';
|
|
31
|
-
|
|
32
40
|
const validator = fromZod(z.object({ name: z.string() }));
|
|
33
41
|
const schema = defineRequestSchema(validator);
|
|
34
42
|
```
|
|
35
43
|
|
|
44
|
+
Isolated runtime (no global state shared with default `acl`):
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { createAccessRuntime } from '@web-ts-toolkit/access-router';
|
|
48
|
+
import mongoose from 'mongoose';
|
|
49
|
+
const runtime = createAccessRuntime();
|
|
50
|
+
runtime.setGlobalOptions({ globalPermissions: () => [] });
|
|
51
|
+
runtime.createRouter('User', { basePath: '/users' });
|
|
52
|
+
const UserModel = mongoose.model('User', new mongoose.Schema({ name: String }));
|
|
53
|
+
runtime.registerModelInstance('User', UserModel);
|
|
54
|
+
```
|
|
55
|
+
|
|
36
56
|
Subpath imports:
|
|
37
57
|
|
|
38
58
|
```ts
|
|
39
59
|
import { copyAndDepopulate } from '@web-ts-toolkit/access-router/processors';
|
|
40
|
-
import {
|
|
60
|
+
import { parseBody, Codes, MIDDLEWARE } from '@web-ts-toolkit/access-router/advanced';
|
|
41
61
|
```
|
|
42
62
|
|
|
43
63
|
## Gotchas
|
|
44
64
|
|
|
45
65
|
- peer dependencies: `express >= 5` and `mongoose >= 8`
|
|
46
|
-
- default export `acl`
|
|
47
|
-
- `
|
|
66
|
+
- default export `acl` is preferred for the default-runtime API; named exports are also available
|
|
67
|
+
- `acl.createOpenApiRouter(options)` uses the default runtime; the standalone `createOpenApiRouter(runtime, options)` export requires the runtime as the first argument
|
|
68
|
+
- `createRouter('User', ...)` accepts a Mongoose model name OR a `mongoose.Model` instance — passing the instance registers the model with the runtime and preserves non-default `mongoose.createConnection()` instances
|
|
69
|
+
- `/advanced` does NOT export `acl`, `defaultRuntime`, `createRouter`, or `createAccessRuntime` — those live on the root entry only
|
|
48
70
|
- `createDataRouter(...)` holds data in-memory; use it for lightweight/non-persisted resources
|
|
71
|
+
- `package.json` declares `sideEffects` array listing the bundled runtime entries that run the lazy `mongoose-schema-jsonschema` patch on first runtime construction — bundlers must retain those entries
|
|
49
72
|
|
|
50
73
|
## Pointers
|
|
51
74
|
|
|
52
|
-
- README: installation, quickstart, main exports
|
|
75
|
+
- README: installation, quickstart (Express + Mongoose end-to-end), main exports, runtime isolation, createRouter overloads
|
|
53
76
|
- website/docs/packages/access-router/: full documentation (routing, configuration, hooks, validation, openapi)
|
package/package.json
CHANGED
|
@@ -2,8 +2,13 @@
|
|
|
2
2
|
"name": "@web-ts-toolkit/access-router",
|
|
3
3
|
"description": "ACL-aware Express routers and in-memory data services for Mongoose-backed APIs",
|
|
4
4
|
"homepage": "https://web-ts-toolkit.pages.dev/docs/packages/access-router",
|
|
5
|
-
"version": "0.
|
|
6
|
-
"sideEffects":
|
|
5
|
+
"version": "0.33.0",
|
|
6
|
+
"sideEffects": [
|
|
7
|
+
"./**/index.js",
|
|
8
|
+
"./**/index.mjs",
|
|
9
|
+
"./**/advanced.js",
|
|
10
|
+
"./**/advanced.mjs"
|
|
11
|
+
],
|
|
7
12
|
"keywords": [
|
|
8
13
|
"express",
|
|
9
14
|
"mongoose",
|
|
@@ -37,11 +42,11 @@
|
|
|
37
42
|
}
|
|
38
43
|
},
|
|
39
44
|
"engines": {
|
|
40
|
-
"node": ">=
|
|
45
|
+
"node": ">=22"
|
|
41
46
|
},
|
|
42
47
|
"dependencies": {
|
|
43
|
-
"@web-ts-toolkit/express-json-router": "0.
|
|
44
|
-
"@web-ts-toolkit/utils": "0.
|
|
48
|
+
"@web-ts-toolkit/express-json-router": "0.33.0",
|
|
49
|
+
"@web-ts-toolkit/utils": "0.33.0",
|
|
45
50
|
"just-diff": "^6.0.2",
|
|
46
51
|
"mongoose-schema-jsonschema": "^4.0.1",
|
|
47
52
|
"sift": "^17.1.3",
|