exisjs 0.7.11 → 0.7.13
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 +195 -39
- package/dist/cli/commands/dev.d.ts +4 -0
- package/dist/cli/commands/dev.d.ts.map +1 -1
- package/dist/cli/commands/dev.js +136 -32
- package/dist/cli/commands/dev.js.map +1 -1
- package/dist/cli/commands/run.d.ts +7 -0
- package/dist/cli/commands/run.d.ts.map +1 -0
- package/dist/cli/commands/run.js +99 -0
- package/dist/cli/commands/run.js.map +1 -0
- package/dist/cli/index.js +29 -13
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/manifest.d.ts.map +1 -1
- package/dist/cli/manifest.js +18 -3
- package/dist/cli/manifest.js.map +1 -1
- package/dist/cli/routes.d.ts +6 -0
- package/dist/cli/routes.d.ts.map +1 -1
- package/dist/cli/routes.js +224 -135
- package/dist/cli/routes.js.map +1 -1
- package/dist/config/config.d.ts +2 -1
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js.map +1 -1
- package/dist/config/types.d.ts +30 -9
- package/dist/config/types.d.ts.map +1 -1
- package/dist/database/lifecycle.d.ts +6 -1
- package/dist/database/lifecycle.d.ts.map +1 -1
- package/dist/database/lifecycle.js +15 -4
- package/dist/database/lifecycle.js.map +1 -1
- package/dist/decorators/params.d.ts +21 -0
- package/dist/decorators/params.d.ts.map +1 -1
- package/dist/decorators/params.js +21 -1
- package/dist/decorators/params.js.map +1 -1
- package/dist/di/container.d.ts +15 -6
- package/dist/di/container.d.ts.map +1 -1
- package/dist/di/container.js +26 -3
- package/dist/di/container.js.map +1 -1
- package/dist/di/index.d.ts +1 -1
- package/dist/di/index.d.ts.map +1 -1
- package/dist/di/index.js.map +1 -1
- package/dist/di/inject.d.ts +2 -1
- package/dist/di/inject.d.ts.map +1 -1
- package/dist/di/inject.js +2 -1
- package/dist/di/inject.js.map +1 -1
- package/dist/docs/BENCHMARKS.md +4 -4
- package/dist/docs/content/README.md +43 -44
- package/dist/docs/content/boundaries.mdx +141 -48
- package/dist/docs/content/cli/commands.mdx +161 -107
- package/dist/docs/content/cli/overview.mdx +61 -46
- package/dist/docs/content/cli/usage.mdx +107 -30
- package/dist/docs/content/config.mdx +145 -147
- package/dist/docs/content/controllers.mdx +193 -464
- package/dist/docs/content/cron.mdx +183 -69
- package/dist/docs/content/decorators.mdx +449 -154
- package/dist/docs/content/errors.mdx +202 -305
- package/dist/docs/content/exisjs-mcp.mdx +59 -49
- package/dist/docs/content/installation.mdx +243 -157
- package/dist/docs/content/introduction.mdx +220 -48
- package/dist/docs/content/middleware.mdx +171 -497
- package/dist/docs/content/modules.mdx +141 -83
- package/dist/docs/content/providers.mdx +216 -180
- package/dist/docs/content/requests.mdx +168 -488
- package/dist/docs/content/responses.mdx +200 -533
- package/dist/docs/content/routing.mdx +239 -558
- package/dist/docs/content/security.mdx +233 -57
- package/dist/docs/content/structure.mdx +151 -240
- package/dist/docs/content/swagger.mdx +192 -91
- package/dist/docs/content/testing.mdx +205 -74
- package/dist/docs/content/validation.mdx +479 -341
- package/dist/docs/reference/README.md +34 -2
- package/dist/docs/reference/config.mdx +277 -73
- package/dist/docs/reference/context.mdx +197 -106
- package/dist/docs/reference/cron.mdx +266 -152
- package/dist/docs/reference/database.mdx +135 -53
- package/dist/docs/reference/decorators.mdx +234 -116
- package/dist/docs/reference/di.mdx +146 -112
- package/dist/docs/reference/error.mdx +155 -178
- package/dist/docs/reference/exis.mdx +141 -70
- package/dist/docs/reference/logger.mdx +110 -126
- package/dist/docs/reference/middleware.mdx +235 -158
- package/dist/docs/reference/plugin.mdx +136 -64
- package/dist/docs/reference/router.mdx +277 -251
- package/dist/docs/reference/sanitize.mdx +91 -87
- package/dist/docs/reference/swagger.mdx +280 -100
- package/dist/docs/reference/testing.mdx +223 -89
- package/dist/docs/reference/validator.mdx +194 -206
- package/dist/lib/inspect-routes.d.ts +2 -0
- package/dist/lib/inspect-routes.d.ts.map +1 -0
- package/dist/lib/inspect-routes.js +148 -0
- package/dist/lib/inspect-routes.js.map +1 -0
- package/dist/lib/start-server.js +13 -8
- package/dist/lib/start-server.js.map +1 -1
- package/dist/module/module.d.ts +6 -3
- package/dist/module/module.d.ts.map +1 -1
- package/dist/module/module.js +17 -3
- package/dist/module/module.js.map +1 -1
- package/dist/router/controller-registrar.d.ts.map +1 -1
- package/dist/router/controller-registrar.js +26 -4
- package/dist/router/controller-registrar.js.map +1 -1
- package/dist/router/scanner/cron-mounter.d.ts.map +1 -1
- package/dist/router/scanner/cron-mounter.js +9 -2
- package/dist/router/scanner/cron-mounter.js.map +1 -1
- package/dist/server/app.d.ts +3 -1
- package/dist/server/app.d.ts.map +1 -1
- package/dist/server/app.js +29 -8
- package/dist/server/app.js.map +1 -1
- package/dist/server/define.d.ts.map +1 -1
- package/dist/server/define.js +5 -0
- package/dist/server/define.js.map +1 -1
- package/dist/server/request.d.ts +2 -0
- package/dist/server/request.d.ts.map +1 -1
- package/dist/server/request.js +11 -0
- package/dist/server/request.js.map +1 -1
- package/dist/swagger/generator.d.ts.map +1 -1
- package/dist/swagger/generator.js +130 -10
- package/dist/swagger/generator.js.map +1 -1
- package/dist/telemetry/index.d.ts +12 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +121 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/testing/client.d.ts +1 -0
- package/dist/testing/client.d.ts.map +1 -1
- package/dist/testing/client.js +4 -1
- package/dist/testing/client.js.map +1 -1
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +20 -4
- package/dist/testing/index.js.map +1 -1
- package/dist/validator/builder.d.ts +26 -1
- package/dist/validator/builder.d.ts.map +1 -1
- package/dist/validator/builder.js +31 -0
- package/dist/validator/builder.js.map +1 -1
- package/dist/validator/engine.d.ts +23 -0
- package/dist/validator/engine.d.ts.map +1 -1
- package/dist/validator/engine.js +228 -31
- package/dist/validator/engine.js.map +1 -1
- package/dist/validator/index.d.ts +8 -4
- package/dist/validator/index.d.ts.map +1 -1
- package/dist/validator/index.js +4 -1
- package/dist/validator/index.js.map +1 -1
- package/dist/validator/tex-types.d.ts +15 -0
- package/dist/validator/tex-types.d.ts.map +1 -1
- package/dist/validator/tex-types.js +102 -0
- package/dist/validator/tex-types.js.map +1 -1
- package/dist/validator/tex.d.ts +1 -1
- package/dist/validator/tex.d.ts.map +1 -1
- package/dist/validator/tex.js +3 -1
- package/dist/validator/tex.js.map +1 -1
- package/dist/validator/types.d.ts +1 -0
- package/dist/validator/types.d.ts.map +1 -1
- package/package.json +47 -14
- package/dist/docs/content/dataloader.mdx +0 -170
- package/dist/docs/reference/dataloader.mdx +0 -91
|
@@ -1,130 +1,134 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "
|
|
3
|
-
description: "API Reference for ExisJS
|
|
2
|
+
title: "exisjs/sanitize"
|
|
3
|
+
description: "API Reference for ExisJS data sanitization engine: Rust-accelerated string cleaners, safeSanitize, and object transformers."
|
|
4
|
+
nextUrl: "/docs/reference/swagger"
|
|
5
|
+
nextTitle: "Swagger Reference"
|
|
4
6
|
---
|
|
5
7
|
|
|
6
|
-
#
|
|
8
|
+
# `exisjs/sanitize`
|
|
7
9
|
|
|
8
|
-
The `exisjs/sanitize` module provides
|
|
10
|
+
The `exisjs/sanitize` module provides pure data sanitization functions for cleaning and normalizing input strings, numbers, dates, arrays, and complex objects before business logic execution. High-throughput security transforms (XSS escaping, HTML stripping, SQL prevention, path traversal blocking) are backed by native Rust acceleration (`@exisjs/rs`).
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Module Exports
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
import { sanitize } from 'exisjs/sanitize'
|
|
18
|
+
```
|
|
11
19
|
|
|
12
20
|
---
|
|
13
21
|
|
|
14
|
-
##
|
|
22
|
+
## 1. Rust-Accelerated Security Sanitizers
|
|
15
23
|
|
|
16
|
-
|
|
24
|
+
These sanitizers interface with `@exisjs/rs` to ensure high-performance text cleansing.
|
|
17
25
|
|
|
18
|
-
|
|
26
|
+
| Function | Signature | Description |
|
|
27
|
+
| :--- | :--- | :--- |
|
|
28
|
+
| `sanitize.escapeHtml` | `(val: string) => string` | Escapes `&`, `<`, `>`, `"`, and `'` into HTML entity equivalents. |
|
|
29
|
+
| `sanitize.stripHtml` | `(val: string) => string` | Strips all HTML tags and markup characters from the string. |
|
|
30
|
+
| `sanitize.preventSql` | `(val: string) => string` | Neutralizes common SQL injection sequences and comment tokens. |
|
|
31
|
+
| `sanitize.preventTraversal` | `(val: string) => string` | Strips directory traversal sequences (`../`, `..\\`, null bytes). |
|
|
32
|
+
| `sanitize.maskEmail` | `(val: string) => string` | Obfuscates email addresses (e.g., `al***@example.com`). |
|
|
33
|
+
| `sanitize.maskString` | `(val: string) => string` | Masks sensitive string segments for logging or auditing. |
|
|
19
34
|
|
|
20
|
-
|
|
21
|
-
- `sanitize.toLowerCase`: Converts the string to lower case.
|
|
22
|
-
- `sanitize.toUpperCase`: Converts the string to upper case.
|
|
23
|
-
- `sanitize.collapseWhitespace`: Replaces multiple consecutive spaces, tabs, or newlines with a single space.
|
|
24
|
-
- `sanitize.stripHtml`: Removes all HTML tags from the string.
|
|
25
|
-
- `sanitize.escapeHtml`: Escapes dangerous characters (`&`, `<`, `>`, `"`, `'`) into HTML entities.
|
|
26
|
-
- `sanitize.normalizeUnicode`: Normalizes unicode characters to their canonical form (NFC).
|
|
27
|
-
- `sanitize.slugify`: Converts a string into a URL-friendly slug (e.g., `Hello World!` -> `hello-world`).
|
|
28
|
-
- `sanitize.truncate(length)`: Hard-truncates a string to a specific maximum length.
|
|
29
|
-
- `sanitize.removeNonAlphanumeric`: Removes all characters except letters and numbers.
|
|
30
|
-
- `sanitize.normalizeLineEndings`: Converts Windows line endings (`\r\n`) to Unix line endings (`\n`).
|
|
35
|
+
---
|
|
31
36
|
|
|
32
|
-
|
|
37
|
+
## 2. Text & String Sanitizers
|
|
33
38
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
| Function | Signature | Description |
|
|
40
|
+
| :--- | :--- | :--- |
|
|
41
|
+
| `sanitize.trim` | `(val: string) => string` | Strips leading and trailing whitespace. |
|
|
42
|
+
| `sanitize.toLowerCase` | `(val: string) => string` | Converts all characters to lowercase. |
|
|
43
|
+
| `sanitize.toUpperCase` | `(val: string) => string` | Converts all characters to uppercase. |
|
|
44
|
+
| `sanitize.collapseWhitespace`| `(val: string) => string` | Collapses consecutive whitespace, tabs, and newlines into a single space. |
|
|
45
|
+
| `sanitize.normalizeUnicode` | `(val: string) => string` | Normalizes Unicode characters to Canonical Decomposition followed by Canonical Composition (NFC). |
|
|
46
|
+
| `sanitize.slugify` | `(val: string) => string` | Converts strings into clean URL-friendly slugs (`"Hello World!"` $\to$ `"hello-world"`). |
|
|
47
|
+
| `sanitize.truncate(length)` | `(length: number) => (val: string) => string` | Truncates strings exceeding the specified maximum length. |
|
|
48
|
+
| `sanitize.removeNonAlphanumeric` | `(val: string) => string` | Strips all characters except standard ASCII letters and numbers. |
|
|
49
|
+
| `sanitize.normalizeLineEndings` | `(val: string) => string` | Converts Windows CRLF (`\r\n`) to POSIX LF (`\n`). |
|
|
37
50
|
|
|
38
|
-
|
|
51
|
+
---
|
|
39
52
|
|
|
40
|
-
|
|
41
|
-
- `sanitize.stripTime`: Resets the time portion of a Date object to `00:00:00:000` (midnight local time).
|
|
53
|
+
## 3. Numbers & Dates
|
|
42
54
|
|
|
43
|
-
###
|
|
55
|
+
### Number Transforms
|
|
44
56
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
57
|
+
| Function | Signature | Description |
|
|
58
|
+
| :--- | :--- | :--- |
|
|
59
|
+
| `sanitize.round` | `(val: number) => number` | Rounds a float to the nearest integer. |
|
|
60
|
+
| `sanitize.clamp(min, max)` | `(min: number, max: number) => (val: number) => number` | Constrains numeric input to fall within `[min, max]`. |
|
|
61
|
+
| `sanitize.defaultIfNaN(fallback)` | `(fallback: number) => (val: number) => number` | Returns the fallback number if input evaluates to `NaN`. |
|
|
49
62
|
|
|
50
|
-
###
|
|
63
|
+
### Date Transforms
|
|
51
64
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
65
|
+
| Function | Signature | Description |
|
|
66
|
+
| :--- | :--- | :--- |
|
|
67
|
+
| `sanitize.normalizeToIsoString` | `(val: Date) => string` | Formats a Date object into an ISO 8601 string representation. |
|
|
68
|
+
| `sanitize.stripTime` | `(val: Date) => Date` | Resets hours, minutes, seconds, and milliseconds to `00:00:00.000`. |
|
|
56
69
|
|
|
57
70
|
---
|
|
58
71
|
|
|
59
|
-
##
|
|
72
|
+
## 4. Arrays & Complex Objects
|
|
73
|
+
|
|
74
|
+
### Array Transforms
|
|
60
75
|
|
|
61
|
-
|
|
76
|
+
| Function | Signature | Description |
|
|
77
|
+
| :--- | :--- | :--- |
|
|
78
|
+
| `sanitize.dedupe` | `<T>(val: T[]) => T[]` | Removes duplicate values preserving first-seen ordering. |
|
|
79
|
+
| `sanitize.compact` | `<T>(val: T[]) => T[]` | Removes `null`, `undefined`, and empty strings (`""`). |
|
|
80
|
+
| `sanitize.trimElements` | `(val: string[]) => string[]` | Trims whitespace from all string elements in an array. |
|
|
81
|
+
| `sanitize.limitLength(n)` | `<T>(length: number) => (val: T[]) => T[]` | Slices an array to at most `length` elements. |
|
|
62
82
|
|
|
63
|
-
|
|
83
|
+
### Object Transforms
|
|
84
|
+
|
|
85
|
+
| Function | Signature | Description |
|
|
86
|
+
| :--- | :--- | :--- |
|
|
87
|
+
| `sanitize.stripUnknownKeys(keys)` | `<T>(allowedKeys: (keyof T)[]) => (val: T) => T` | Strips unlisted properties from an object. |
|
|
88
|
+
| `sanitize.deepTrimStringValues` | `<T>(val: T) => T` | Recursively walks an object graph and trims all nested string properties. |
|
|
89
|
+
| `sanitize.omit(keys)` | `<T, K extends keyof T>(keys: K[]) => (val: T) => Omit<T, K>` | Removes specified keys from an object. |
|
|
90
|
+
| `sanitize.pick(keys)` | `<T, K extends keyof T>(keys: K[]) => (val: T) => Pick<T, K>` | Returns an object containing only the specified keys. |
|
|
91
|
+
|
|
92
|
+
---
|
|
64
93
|
|
|
65
|
-
|
|
66
|
-
|
|
94
|
+
## 5. Integration with TexEngine Validation
|
|
95
|
+
|
|
96
|
+
Sanitizers integrate with `tex` validator chains using the `.sanitize()` modifier. Sanitization occurs **before** rule validation checks:
|
|
97
|
+
|
|
98
|
+
```typescript filename="src/http/articles/schema.ts"
|
|
67
99
|
import { tex } from 'exisjs/validator'
|
|
68
100
|
import { sanitize } from 'exisjs/sanitize'
|
|
69
101
|
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
102
|
+
export const CreateArticleSchema = tex.object({
|
|
103
|
+
title: tex
|
|
104
|
+
.string({ min: 5, max: 120 })
|
|
73
105
|
.sanitize(sanitize.trim, sanitize.collapseWhitespace),
|
|
74
106
|
|
|
75
|
-
|
|
76
|
-
|
|
107
|
+
slug: tex
|
|
108
|
+
.string()
|
|
77
109
|
.sanitize(sanitize.slugify),
|
|
78
110
|
|
|
79
|
-
|
|
80
|
-
|
|
111
|
+
content: tex
|
|
112
|
+
.string()
|
|
81
113
|
.sanitize(sanitize.stripHtml),
|
|
82
114
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
.sanitize(sanitize.dedupe, sanitize.compact)
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
// === Class-Based (OOP) Example ===
|
|
89
|
-
@Controller('/api/posts')
|
|
90
|
-
export default class PostController {
|
|
91
|
-
@Post('/', { body: CreatePostSchema })
|
|
92
|
-
createPost(@Body() data: any) {
|
|
93
|
-
// data.title will be trimmed
|
|
94
|
-
// data.content will have zero HTML tags
|
|
95
|
-
// data.tags will contain no duplicates
|
|
96
|
-
return data
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// === Functional Example ===
|
|
101
|
-
import { controller, route } from 'exisjs/router'
|
|
102
|
-
|
|
103
|
-
export default controller({
|
|
104
|
-
createPostFn: route.post('/api/posts/functional', {
|
|
105
|
-
body: CreatePostSchema,
|
|
106
|
-
async handle(ctx) {
|
|
107
|
-
// ctx.body is fully sanitized and strongly typed!
|
|
108
|
-
return ctx.body
|
|
109
|
-
}
|
|
110
|
-
})
|
|
115
|
+
tags: tex
|
|
116
|
+
.array(tex.string())
|
|
117
|
+
.sanitize(sanitize.dedupe, sanitize.compact),
|
|
111
118
|
})
|
|
112
119
|
```
|
|
113
120
|
|
|
114
121
|
---
|
|
115
122
|
|
|
116
|
-
## Standalone Usage
|
|
123
|
+
## 6. Standalone Usage Example
|
|
117
124
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
```typescript
|
|
125
|
+
```typescript filename="src/services/import.service.ts"
|
|
121
126
|
import { sanitize } from 'exisjs/sanitize'
|
|
122
127
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
console.log(safeInput) // "Hello World!"
|
|
128
|
+
export function processUserInput(rawContent: string): string {
|
|
129
|
+
const step1 = sanitize.stripHtml(rawContent)
|
|
130
|
+
const step2 = sanitize.collapseWhitespace(step1)
|
|
131
|
+
const clean = sanitize.trim(step2)
|
|
132
|
+
return clean
|
|
133
|
+
}
|
|
130
134
|
```
|