exisjs 0.7.12 → 0.7.14

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 (132) hide show
  1. package/README.md +195 -39
  2. package/dist/cli/commands/run.d.ts.map +1 -1
  3. package/dist/cli/commands/run.js +3 -1
  4. package/dist/cli/commands/run.js.map +1 -1
  5. package/dist/config/types.d.ts +2 -2
  6. package/dist/config/types.d.ts.map +1 -1
  7. package/dist/decorators/params.d.ts +21 -0
  8. package/dist/decorators/params.d.ts.map +1 -1
  9. package/dist/decorators/params.js +21 -1
  10. package/dist/decorators/params.js.map +1 -1
  11. package/dist/di/container.d.ts +15 -6
  12. package/dist/di/container.d.ts.map +1 -1
  13. package/dist/di/container.js +26 -3
  14. package/dist/di/container.js.map +1 -1
  15. package/dist/di/index.d.ts +1 -1
  16. package/dist/di/index.d.ts.map +1 -1
  17. package/dist/di/index.js.map +1 -1
  18. package/dist/di/inject.d.ts +2 -1
  19. package/dist/di/inject.d.ts.map +1 -1
  20. package/dist/di/inject.js +2 -1
  21. package/dist/di/inject.js.map +1 -1
  22. package/dist/docs/ARCHITECTURE.md +130 -78
  23. package/dist/docs/BENCHMARKS.md +4 -4
  24. package/dist/docs/content/README.md +43 -44
  25. package/dist/docs/content/boundaries.mdx +138 -61
  26. package/dist/docs/content/cli/commands.mdx +151 -128
  27. package/dist/docs/content/cli/overview.mdx +61 -47
  28. package/dist/docs/content/cli/usage.mdx +107 -30
  29. package/dist/docs/content/config.mdx +145 -158
  30. package/dist/docs/content/controllers.mdx +193 -464
  31. package/dist/docs/content/cron.mdx +183 -69
  32. package/dist/docs/content/decorators.mdx +449 -154
  33. package/dist/docs/content/errors.mdx +202 -305
  34. package/dist/docs/content/exisjs-mcp.mdx +59 -49
  35. package/dist/docs/content/installation.mdx +243 -157
  36. package/dist/docs/content/introduction.mdx +220 -48
  37. package/dist/docs/content/middleware.mdx +171 -497
  38. package/dist/docs/content/modules.mdx +141 -83
  39. package/dist/docs/content/providers.mdx +216 -180
  40. package/dist/docs/content/requests.mdx +168 -488
  41. package/dist/docs/content/responses.mdx +200 -533
  42. package/dist/docs/content/routing.mdx +235 -598
  43. package/dist/docs/content/security.mdx +233 -57
  44. package/dist/docs/content/structure.mdx +151 -240
  45. package/dist/docs/content/swagger.mdx +192 -91
  46. package/dist/docs/content/testing.mdx +205 -74
  47. package/dist/docs/content/validation.mdx +479 -341
  48. package/dist/docs/reference/README.md +34 -2
  49. package/dist/docs/reference/config.mdx +277 -75
  50. package/dist/docs/reference/context.mdx +197 -106
  51. package/dist/docs/reference/cron.mdx +266 -152
  52. package/dist/docs/reference/database.mdx +135 -53
  53. package/dist/docs/reference/decorators.mdx +234 -116
  54. package/dist/docs/reference/di.mdx +146 -112
  55. package/dist/docs/reference/error.mdx +155 -178
  56. package/dist/docs/reference/exis.mdx +141 -70
  57. package/dist/docs/reference/logger.mdx +110 -126
  58. package/dist/docs/reference/middleware.mdx +235 -158
  59. package/dist/docs/reference/plugin.mdx +136 -64
  60. package/dist/docs/reference/router.mdx +275 -293
  61. package/dist/docs/reference/sanitize.mdx +91 -87
  62. package/dist/docs/reference/swagger.mdx +280 -100
  63. package/dist/docs/reference/testing.mdx +223 -89
  64. package/dist/docs/reference/validator.mdx +194 -206
  65. package/dist/lib/start-server.js +22 -8
  66. package/dist/lib/start-server.js.map +1 -1
  67. package/dist/module/module.d.ts +6 -3
  68. package/dist/module/module.d.ts.map +1 -1
  69. package/dist/module/module.js +17 -3
  70. package/dist/module/module.js.map +1 -1
  71. package/dist/router/controller-registrar.d.ts.map +1 -1
  72. package/dist/router/controller-registrar.js +26 -4
  73. package/dist/router/controller-registrar.js.map +1 -1
  74. package/dist/router/scanner/fs-scanner.d.ts.map +1 -1
  75. package/dist/router/scanner/fs-scanner.js +22 -0
  76. package/dist/router/scanner/fs-scanner.js.map +1 -1
  77. package/dist/router/types.d.ts +6 -4
  78. package/dist/router/types.d.ts.map +1 -1
  79. package/dist/server/app.d.ts +3 -1
  80. package/dist/server/app.d.ts.map +1 -1
  81. package/dist/server/app.js +24 -8
  82. package/dist/server/app.js.map +1 -1
  83. package/dist/server/bootstrapper.d.ts.map +1 -1
  84. package/dist/server/bootstrapper.js +19 -0
  85. package/dist/server/bootstrapper.js.map +1 -1
  86. package/dist/server/request.d.ts +2 -0
  87. package/dist/server/request.d.ts.map +1 -1
  88. package/dist/server/request.js +11 -0
  89. package/dist/server/request.js.map +1 -1
  90. package/dist/server/response.d.ts +10 -5
  91. package/dist/server/response.d.ts.map +1 -1
  92. package/dist/server/response.js +65 -18
  93. package/dist/server/response.js.map +1 -1
  94. package/dist/swagger/generator.d.ts.map +1 -1
  95. package/dist/swagger/generator.js +130 -10
  96. package/dist/swagger/generator.js.map +1 -1
  97. package/dist/telemetry/index.d.ts +12 -0
  98. package/dist/telemetry/index.d.ts.map +1 -0
  99. package/dist/telemetry/index.js +121 -0
  100. package/dist/telemetry/index.js.map +1 -0
  101. package/dist/testing/client.d.ts +1 -0
  102. package/dist/testing/client.d.ts.map +1 -1
  103. package/dist/testing/client.js +4 -1
  104. package/dist/testing/client.js.map +1 -1
  105. package/dist/testing/index.d.ts.map +1 -1
  106. package/dist/testing/index.js +11 -4
  107. package/dist/testing/index.js.map +1 -1
  108. package/dist/validator/builder.d.ts +26 -1
  109. package/dist/validator/builder.d.ts.map +1 -1
  110. package/dist/validator/builder.js +31 -0
  111. package/dist/validator/builder.js.map +1 -1
  112. package/dist/validator/engine.d.ts +23 -0
  113. package/dist/validator/engine.d.ts.map +1 -1
  114. package/dist/validator/engine.js +228 -31
  115. package/dist/validator/engine.js.map +1 -1
  116. package/dist/validator/index.d.ts +8 -4
  117. package/dist/validator/index.d.ts.map +1 -1
  118. package/dist/validator/index.js +4 -1
  119. package/dist/validator/index.js.map +1 -1
  120. package/dist/validator/tex-types.d.ts +19 -4
  121. package/dist/validator/tex-types.d.ts.map +1 -1
  122. package/dist/validator/tex-types.js +102 -0
  123. package/dist/validator/tex-types.js.map +1 -1
  124. package/dist/validator/tex.d.ts +1 -1
  125. package/dist/validator/tex.d.ts.map +1 -1
  126. package/dist/validator/tex.js +3 -1
  127. package/dist/validator/tex.js.map +1 -1
  128. package/dist/validator/types.d.ts +1 -0
  129. package/dist/validator/types.d.ts.map +1 -1
  130. package/package.json +46 -14
  131. package/dist/docs/content/dataloader.mdx +0 -170
  132. package/dist/docs/reference/dataloader.mdx +0 -91
@@ -1,130 +1,134 @@
1
1
  ---
2
- title: "Sanitization"
3
- description: "API Reference for ExisJS built-in Sanitization Engine."
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
- # Sanitization (`sanitize`)
8
+ # `exisjs/sanitize`
7
9
 
8
- The `exisjs/sanitize` module provides a comprehensive suite of pure, dependency-free functions for transforming and cleaning data **before** it hits your business logic or database.
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
- Sanitizers are designed to be perfectly composable with the [ExisJS Validator](/docs/reference/validator) via the `.sanitize()` modifier, meaning you can strip HTML, trim whitespace, and enforce limits *while* validating request payloads.
12
+ ---
13
+
14
+ ## Module Exports
15
+
16
+ ```typescript
17
+ import { sanitize } from 'exisjs/sanitize'
18
+ ```
11
19
 
12
20
  ---
13
21
 
14
- ## Core Sanitizers
22
+ ## 1. Rust-Accelerated Security Sanitizers
15
23
 
16
- The `sanitize` object exposes pure functions grouped by their target data type.
24
+ These sanitizers interface with `@exisjs/rs` to ensure high-performance text cleansing.
17
25
 
18
- ### String Sanitizers
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
- - `sanitize.trim`: Trims leading and trailing whitespace.
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
- ### Number Sanitizers
37
+ ## 2. Text & String Sanitizers
33
38
 
34
- - `sanitize.round`: Rounds the number to the nearest integer.
35
- - `sanitize.clamp(min, max)`: Restricts a number to fall within a specific range.
36
- - `sanitize.defaultIfNaN(fallback)`: Returns the fallback value if the provided number is `NaN`.
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
- ### Date Sanitizers
51
+ ---
39
52
 
40
- - `sanitize.normalizeToIsoString`: Converts a Date object into a standard ISO 8601 string.
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
- ### Array Sanitizers
55
+ ### Number Transforms
44
56
 
45
- - `sanitize.dedupe`: Removes duplicate elements from the array.
46
- - `sanitize.compact`: Removes `null`, `undefined`, and empty strings (`''`) from the array.
47
- - `sanitize.trimElements`: Trims whitespace from all string elements inside the array.
48
- - `sanitize.limitLength(length)`: Slices the array down to a maximum length.
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
- ### Object Sanitizers
63
+ ### Date Transforms
51
64
 
52
- - `sanitize.stripUnknownKeys(['allowedA', 'allowedB'])`: Strips out any keys from the object that are not explicitly allowed.
53
- - `sanitize.deepTrimStringValues`: Recursively walks through an object (and nested arrays/objects) and trims all string values found.
54
- - `sanitize.omit(['secret'])`: Removes specific keys from the object.
55
- - `sanitize.pick(['publicField'])`: Returns a new object containing only the specified keys.
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
- ## Using with Validation
72
+ ## 4. Arrays & Complex Objects
73
+
74
+ ### Array Transforms
60
75
 
61
- The most powerful way to use ExisJS sanitizers is to chain them directly into your schemas using the `.sanitize()` modifier.
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
- **Note that sanitization runs *before* final validation checks (like `.email()` or `.min()`).**
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
- ```typescript filename="src/http/posts/route.ts"
66
- import { Controller, Post, Body } from 'exisjs/decorators'
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 CreatePostSchema = tex.object({
71
- // Trim the title, then ensure it's still at least 5 characters
72
- title: tex.string({ min: 5 })
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
- // Automatically generate a URL slug from the input string
76
- slug: tex.string()
107
+ slug: tex
108
+ .string()
77
109
  .sanitize(sanitize.slugify),
78
110
 
79
- // Strip all HTML before saving to the database
80
- content: tex.string()
111
+ content: tex
112
+ .string()
81
113
  .sanitize(sanitize.stripHtml),
82
114
 
83
- // Deduplicate tags and remove empty strings
84
- tags: tex.array(tex.string())
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
- Because the `sanitize` methods are pure functions, you can easily use them independently anywhere in your application.
119
-
120
- ```typescript
125
+ ```typescript filename="src/services/import.service.ts"
121
126
  import { sanitize } from 'exisjs/sanitize'
122
127
 
123
- const rawInput = " <script>alert('hack')</script> Hello World! "
124
-
125
- let safeInput = sanitize.stripHtml(rawInput)
126
- safeInput = sanitize.collapseWhitespace(safeInput)
127
- safeInput = sanitize.trim(safeInput)
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
  ```