@venizia/ignis-docs 0.0.1-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.
Files changed (123) hide show
  1. package/mcp-server/dist/common/config.d.ts +27 -0
  2. package/mcp-server/dist/common/config.d.ts.map +1 -0
  3. package/mcp-server/dist/common/config.js +27 -0
  4. package/mcp-server/dist/common/config.js.map +1 -0
  5. package/mcp-server/dist/common/index.d.ts +3 -0
  6. package/mcp-server/dist/common/index.d.ts.map +1 -0
  7. package/mcp-server/dist/common/index.js +19 -0
  8. package/mcp-server/dist/common/index.js.map +1 -0
  9. package/mcp-server/dist/common/paths.d.ts +13 -0
  10. package/mcp-server/dist/common/paths.d.ts.map +1 -0
  11. package/mcp-server/dist/common/paths.js +23 -0
  12. package/mcp-server/dist/common/paths.js.map +1 -0
  13. package/mcp-server/dist/helpers/docs.helper.d.ts +81 -0
  14. package/mcp-server/dist/helpers/docs.helper.d.ts.map +1 -0
  15. package/mcp-server/dist/helpers/docs.helper.js +171 -0
  16. package/mcp-server/dist/helpers/docs.helper.js.map +1 -0
  17. package/mcp-server/dist/helpers/index.d.ts +3 -0
  18. package/mcp-server/dist/helpers/index.d.ts.map +1 -0
  19. package/mcp-server/dist/helpers/index.js +19 -0
  20. package/mcp-server/dist/helpers/index.js.map +1 -0
  21. package/mcp-server/dist/helpers/logger.helper.d.ts +7 -0
  22. package/mcp-server/dist/helpers/logger.helper.d.ts.map +1 -0
  23. package/mcp-server/dist/helpers/logger.helper.js +22 -0
  24. package/mcp-server/dist/helpers/logger.helper.js.map +1 -0
  25. package/mcp-server/dist/index.d.ts +3 -0
  26. package/mcp-server/dist/index.d.ts.map +1 -0
  27. package/mcp-server/dist/index.js +62 -0
  28. package/mcp-server/dist/index.js.map +1 -0
  29. package/mcp-server/dist/tools/base.tool.d.ts +98 -0
  30. package/mcp-server/dist/tools/base.tool.d.ts.map +1 -0
  31. package/mcp-server/dist/tools/base.tool.js +47 -0
  32. package/mcp-server/dist/tools/base.tool.js.map +1 -0
  33. package/mcp-server/dist/tools/get-doc-content.tool.d.ts +30 -0
  34. package/mcp-server/dist/tools/get-doc-content.tool.d.ts.map +1 -0
  35. package/mcp-server/dist/tools/get-doc-content.tool.js +127 -0
  36. package/mcp-server/dist/tools/get-doc-content.tool.js.map +1 -0
  37. package/mcp-server/dist/tools/get-doc-metadata.tool.d.ts +40 -0
  38. package/mcp-server/dist/tools/get-doc-metadata.tool.d.ts.map +1 -0
  39. package/mcp-server/dist/tools/get-doc-metadata.tool.js +121 -0
  40. package/mcp-server/dist/tools/get-doc-metadata.tool.js.map +1 -0
  41. package/mcp-server/dist/tools/index.d.ts +8 -0
  42. package/mcp-server/dist/tools/index.d.ts.map +1 -0
  43. package/mcp-server/dist/tools/index.js +18 -0
  44. package/mcp-server/dist/tools/index.js.map +1 -0
  45. package/mcp-server/dist/tools/list-categories.tool.d.ts +20 -0
  46. package/mcp-server/dist/tools/list-categories.tool.d.ts.map +1 -0
  47. package/mcp-server/dist/tools/list-categories.tool.js +105 -0
  48. package/mcp-server/dist/tools/list-categories.tool.js.map +1 -0
  49. package/mcp-server/dist/tools/list-docs.tool.d.ts +32 -0
  50. package/mcp-server/dist/tools/list-docs.tool.d.ts.map +1 -0
  51. package/mcp-server/dist/tools/list-docs.tool.js +121 -0
  52. package/mcp-server/dist/tools/list-docs.tool.js.map +1 -0
  53. package/mcp-server/dist/tools/search-docs.tool.d.ts +32 -0
  54. package/mcp-server/dist/tools/search-docs.tool.d.ts.map +1 -0
  55. package/mcp-server/dist/tools/search-docs.tool.js +120 -0
  56. package/mcp-server/dist/tools/search-docs.tool.js.map +1 -0
  57. package/package.json +102 -0
  58. package/wiki/get-started/5-minute-quickstart.md +266 -0
  59. package/wiki/get-started/best-practices/api-usage-examples.md +222 -0
  60. package/wiki/get-started/best-practices/architectural-patterns.md +129 -0
  61. package/wiki/get-started/best-practices/code-style-standards.md +122 -0
  62. package/wiki/get-started/best-practices/common-pitfalls.md +136 -0
  63. package/wiki/get-started/best-practices/contribution-workflow.md +145 -0
  64. package/wiki/get-started/best-practices/deployment-strategies.md +121 -0
  65. package/wiki/get-started/best-practices/performance-optimization.md +88 -0
  66. package/wiki/get-started/best-practices/security-guidelines.md +97 -0
  67. package/wiki/get-started/best-practices/troubleshooting-tips.md +100 -0
  68. package/wiki/get-started/building-a-crud-api.md +717 -0
  69. package/wiki/get-started/core-concepts/application.md +168 -0
  70. package/wiki/get-started/core-concepts/components.md +96 -0
  71. package/wiki/get-started/core-concepts/controllers.md +441 -0
  72. package/wiki/get-started/core-concepts/dependency-injection.md +160 -0
  73. package/wiki/get-started/core-concepts/persistent.md +591 -0
  74. package/wiki/get-started/core-concepts/services.md +88 -0
  75. package/wiki/get-started/index.md +65 -0
  76. package/wiki/get-started/mcp-docs-server.md +840 -0
  77. package/wiki/get-started/philosophy.md +123 -0
  78. package/wiki/get-started/prerequisites.md +113 -0
  79. package/wiki/get-started/quickstart.md +382 -0
  80. package/wiki/index.md +48 -0
  81. package/wiki/references/base/application.md +67 -0
  82. package/wiki/references/base/components.md +80 -0
  83. package/wiki/references/base/controllers.md +361 -0
  84. package/wiki/references/base/datasources.md +105 -0
  85. package/wiki/references/base/dependency-injection.md +83 -0
  86. package/wiki/references/base/models.md +104 -0
  87. package/wiki/references/base/repositories.md +118 -0
  88. package/wiki/references/base/services.md +97 -0
  89. package/wiki/references/components/authentication.md +224 -0
  90. package/wiki/references/components/health-check.md +190 -0
  91. package/wiki/references/components/index.md +61 -0
  92. package/wiki/references/components/request-tracker.md +35 -0
  93. package/wiki/references/components/socket-io.md +127 -0
  94. package/wiki/references/components/swagger.md +175 -0
  95. package/wiki/references/helpers/cron.md +94 -0
  96. package/wiki/references/helpers/crypto.md +117 -0
  97. package/wiki/references/helpers/env.md +67 -0
  98. package/wiki/references/helpers/error.md +80 -0
  99. package/wiki/references/helpers/index.md +21 -0
  100. package/wiki/references/helpers/inversion.md +141 -0
  101. package/wiki/references/helpers/logger.md +98 -0
  102. package/wiki/references/helpers/network.md +143 -0
  103. package/wiki/references/helpers/queue.md +131 -0
  104. package/wiki/references/helpers/redis.md +121 -0
  105. package/wiki/references/helpers/socket-io.md +103 -0
  106. package/wiki/references/helpers/storage.md +130 -0
  107. package/wiki/references/helpers/testing.md +115 -0
  108. package/wiki/references/helpers/worker-thread.md +162 -0
  109. package/wiki/references/src-details/core.md +249 -0
  110. package/wiki/references/src-details/dev-configs.md +302 -0
  111. package/wiki/references/src-details/docs.md +61 -0
  112. package/wiki/references/src-details/helpers.md +211 -0
  113. package/wiki/references/src-details/inversion.md +345 -0
  114. package/wiki/references/src-details/mcp-server.md +726 -0
  115. package/wiki/references/utilities/crypto.md +39 -0
  116. package/wiki/references/utilities/date.md +72 -0
  117. package/wiki/references/utilities/index.md +12 -0
  118. package/wiki/references/utilities/module.md +40 -0
  119. package/wiki/references/utilities/parse.md +68 -0
  120. package/wiki/references/utilities/performance.md +64 -0
  121. package/wiki/references/utilities/promise.md +83 -0
  122. package/wiki/references/utilities/request.md +66 -0
  123. package/wiki/references/utilities/schema.md +88 -0
@@ -0,0 +1,39 @@
1
+ # Crypto Utility
2
+
3
+ The Crypto utility provides simple, stateless functions for cryptographic hashing.
4
+
5
+ ## `hash`
6
+
7
+ The `hash` function allows you to create a hash of a string using either `SHA256` (with a secret for HMAC) or `MD5`.
8
+
9
+ ### `hash(text, options)`
10
+
11
+ - `text` (string): The input string to hash.
12
+ - `options` (object):
13
+ - `algorithm` ('SHA256' | 'MD5'): The hashing algorithm to use.
14
+ - `secret` (string, optional): The secret key for HMAC-SHA256.
15
+ - `outputType` (BinaryToTextEncoding): The output encoding (e.g., 'hex', 'base64').
16
+
17
+ ### Examples
18
+
19
+ **MD5 Hash**
20
+
21
+ ```typescript
22
+ import { hash } from '@venizia/ignis';
23
+
24
+ const md5Hash = hash('some text', { algorithm: 'MD5', outputType: 'hex' });
25
+ // => '552e21cd4cd99186789c2370c7482837'
26
+ ```
27
+
28
+ **SHA256 HMAC**
29
+
30
+ ```typescript
31
+ import { hash } from '@venizia/ignis';
32
+
33
+ const sha256Hash = hash('some text', {
34
+ algorithm: 'SHA256',
35
+ secret: 'a-secret-key',
36
+ outputType: 'hex',
37
+ });
38
+ // => 'b8a1c3f2... (64-character hex string)'
39
+ ```
@@ -0,0 +1,72 @@
1
+ # Date Utility
2
+
3
+ The Date utility provides a set of functions for date and time manipulation, built on top of the powerful `dayjs` library. It also configures `dayjs` with useful plugins and a default timezone.
4
+
5
+ ## `dayjs`
6
+
7
+ The `dayjs` object is re-exported, so you can use it directly for any date and time operations. It is pre-configured with the following plugins: `CustomParseFormat`, `UTC`, `Timezone`, `Weekday`, and `IsoWeek`.
8
+
9
+ ```typescript
10
+ import { dayjs } from '@venizia/ignis';
11
+
12
+ // Get the current date and time
13
+ const now = dayjs();
14
+
15
+ // Format a date
16
+ const formatted = now.format('YYYY-MM-DD HH:mm:ss');
17
+ ```
18
+
19
+ ## `sleep`
20
+
21
+ The `sleep` function pauses execution for a specified number of milliseconds.
22
+
23
+ ```typescript
24
+ import { sleep } from '@venizia/ignis';
25
+
26
+ async function myAsyncFunction() {
27
+ console.log('Start');
28
+ await sleep(2000); // Wait for 2 seconds
29
+ console.log('End');
30
+ }
31
+ ```
32
+
33
+ ## Weekday Functions
34
+
35
+ - **`isWeekday(date)`**: Checks if a given date is a weekday (Monday to Friday).
36
+ - **`getPreviousWeekday(opts)`**: Returns the previous weekday from a given date.
37
+ - **`getNextWeekday(opts)`**: Returns the next weekday from a given date.
38
+
39
+ ```typescript
40
+ import { isWeekday, getPreviousWeekday } from '@venizia/ignis';
41
+
42
+ const isTodayWeekday = isWeekday(new Date());
43
+
44
+ const lastBusinessDay = getPreviousWeekday();
45
+ ```
46
+
47
+ ## `getDateTz`
48
+
49
+ The `getDateTz` function allows you to get a `dayjs` object in a specific timezone, with an optional offset.
50
+
51
+ ```typescript
52
+ import { getDateTz } from '@venizia/ignis';
53
+
54
+ const tokyoTime = getDateTz({
55
+ date: '2023-10-27T10:00:00Z',
56
+ timezone: 'Asia/Tokyo',
57
+ });
58
+ ```
59
+
60
+ ## `hrTime`
61
+
62
+ The `hrTime` function returns a high-resolution time measurement in seconds, useful for performance benchmarking.
63
+
64
+ ```typescript
65
+ import { hrTime } from '@venizia/ignis';
66
+
67
+ const start = hrTime();
68
+ // ... some long-running operation
69
+ const end = hrTime();
70
+
71
+ console.log(`Operation took ${end - start} seconds.`);
72
+ ```
@@ -0,0 +1,12 @@
1
+ # Utilities
2
+
3
+ Utilities are pure, standalone functions that provide common, reusable logic for various tasks within the Ignis framework. They are designed to be simple, stateless, and easy to use.
4
+
5
+ - [Crypto](./crypto.md): Simple, stateless cryptographic functions.
6
+ - [Date](./date.md): Provides date and time manipulation functions, built on `dayjs`.
7
+ - [Module](./module.md): A utility for checking if a Node.js module is installed.
8
+ - [Parse](./parse.md): A collection of functions for parsing and converting data types.
9
+ - [Performance](./performance.md): Utilities for measuring code execution time.
10
+ - [Promise](./promise.md): Helper functions for working with Promises.
11
+ - [Request](./request.md): Utilities for handling HTTP requests, such as parsing multipart form data.
12
+ - [Schema](./schema.md): Helpers for creating and validating Zod schemas, especially for request and response validation in an OpenAPI context.
@@ -0,0 +1,40 @@
1
+ # Module Utility
2
+
3
+ The Module utility provides a simple function to validate the existence of a Node.js module at runtime.
4
+
5
+ ## `validateModule`
6
+
7
+ The `validateModule` function checks if a list of modules can be resolved. If a module is not found, it throws a descriptive error, prompting the developer to install it. This is particularly useful for features that have optional peer dependencies.
8
+
9
+ ### `validateModule(opts)`
10
+
11
+ - `opts` (object):
12
+ - `scope` (string, optional): A string to identify the feature or component that requires the module, making the error message more informative.
13
+ - `modules` (Array<string>): An array of module names to validate.
14
+
15
+ ### Example
16
+
17
+ The `SwaggerComponent` uses `validateModule` to ensure that `@hono/swagger-ui` is installed before attempting to use it.
18
+
19
+ ```typescript
20
+ import { validateModule } from '@venizia/ignis';
21
+
22
+ export class SwaggerComponent extends BaseComponent {
23
+ // ...
24
+
25
+ override async binding() {
26
+ // This will throw an error if '@hono/swagger-ui' is not installed
27
+ validateModule({ scope: SwaggerComponent.name, modules: ['@hono/swagger-ui'] });
28
+
29
+ const { swaggerUI } = await import('@hono/swagger-ui');
30
+
31
+ // ... rest of the setup
32
+ }
33
+ }
34
+ ```
35
+
36
+ If the module is missing, the application will fail to start with an error message like:
37
+
38
+ ```
39
+ [validateModule] @hono/swagger-ui is required for SwaggerComponent. Please install '@hono/swagger-ui'
40
+ ```
@@ -0,0 +1,68 @@
1
+ # Parse Utility
2
+
3
+ The Parse utility provides a collection of functions for data type checking, conversion, and transformation.
4
+
5
+ ## Type Checking
6
+
7
+ - **`isInt(n)`**: Checks if a value is an integer.
8
+ - **`isFloat(n)`**: Checks if a value is a float.
9
+
10
+ ## Type Conversion
11
+
12
+ - **`int(input)`**: Parses a value to an integer. Handles string with commas and defaults to `0` if the input is invalid.
13
+ - **`float(input, digit = 2)`**: Parses a value to a float, rounding to a specified number of digits. Handles string with commas and defaults to `0` if the input is invalid.
14
+ - **`toBoolean(input)`**: Converts various string/number representations (e.g., `'true'`, `'1'`, `1`) to a boolean.
15
+ - **`toStringDecimal(input, digit = 2)`**: Formats a number to a string with a specified number of decimal places, using locale-specific formatting.
16
+
17
+ ```typescript
18
+ import { int, float, toBoolean } from '@venizia/ignis';
19
+
20
+ const myInt = int('1,000'); // => 1000
21
+ const myFloat = float('1,234.567', 2); // => 1234.57
22
+ const myBool = toBoolean('true'); // => true
23
+ ```
24
+
25
+ ## String and Object Transformation
26
+
27
+ - **`toCamel(s)`**: Converts a string from snake_case or kebab-case to camelCase.
28
+ - **`keysToCamel(object)`**: Recursively converts all keys in an object (and nested objects) to camelCase.
29
+
30
+ ```typescript
31
+ import { toCamel, keysToCamel } from '@venizia/ignis';
32
+
33
+ const camelString = toCamel('my-snake_case-string');
34
+ // => 'mySnakeCaseString'
35
+
36
+ const camelObject = keysToCamel({ 'first-name': 'John', 'last_name': 'Doe' });
37
+ // => { firstName: 'John', lastName: 'Doe' }
38
+ ```
39
+
40
+ ## Array Transformation
41
+
42
+ - **`parseArrayToRecordWithKey(opts)`**: Transforms an array of objects into a record (plain object), using a specified property of the objects as keys.
43
+ - **`parseArrayToMapWithKey(arr, keyMap)`**: Transforms an array of objects into a `Map`, using a specified property of the objects as keys. This is useful for efficient lookups.
44
+
45
+ ```typescript
46
+ import { parseArrayToMapWithKey } from '@venizia/ignis';
47
+
48
+ const users = [
49
+ { id: 1, name: 'Alice' },
50
+ { id: 2, name: 'Bob' },
51
+ ];
52
+
53
+ const usersMap = parseArrayToMapWithKey(users, 'id');
54
+ // => Map { 1 => { id: 1, name: 'Alice' }, 2 => { id: 2, name: 'Bob' } }
55
+
56
+ const user = usersMap.get(1);
57
+ // => { id: 1, name: 'Alice' }
58
+ ```
59
+
60
+ ## Unique ID
61
+
62
+ - **`getUID()`**: Generates a simple, short unique ID string.
63
+
64
+ ```typescript
65
+ import { getUID } from '@venizia/ignis';
66
+
67
+ const uniqueId = getUID(); // => e.g., 'A1B2C3D4'
68
+ ```
@@ -0,0 +1,64 @@
1
+ # Performance Utility
2
+
3
+ The Performance utility provides functions for measuring and logging the execution time of code blocks, which is useful for identifying bottlenecks and optimizing your application.
4
+
5
+ ## `executeWithPerformanceMeasure`
6
+
7
+ This is a higher-order function that wraps a task (a function returning a Promise), automatically logging its start time, end time, and total execution duration.
8
+
9
+ ### `executeWithPerformanceMeasure(opts)`
10
+
11
+ - `opts` (object):
12
+ - `logger` (ApplicationLogger, optional): A logger instance to use for logging. Defaults to `console`.
13
+ - `description` (string, optional): A description of the task being measured.
14
+ - `scope` (string): A scope to identify the context of the measurement.
15
+ - `task` (Function): The asynchronous function (or a function that returns a Promise) to be executed and measured.
16
+
17
+ ### Example
18
+
19
+ The `BaseApplication` uses this utility to measure the time taken to register components, controllers, and data sources during the startup process.
20
+
21
+ ```typescript
22
+ // Inside BaseApplication class
23
+ import { executeWithPerformanceMeasure } from '@venizia/ignis';
24
+
25
+ // ...
26
+
27
+ async registerComponents() {
28
+ await executeWithPerformanceMeasure({
29
+ logger: this.logger,
30
+ scope: this.registerComponents.name,
31
+ description: 'Register application components',
32
+ task: async () => {
33
+ // ... logic to register components
34
+ },
35
+ });
36
+ }
37
+ ```
38
+
39
+ When `registerComponents` is called, it will produce log output similar to this:
40
+
41
+ ```
42
+ [RegisterComponents] START | Register application components ...
43
+ [RegisterComponents] DONE | Register application components | Took: 12.3456 (ms)
44
+ ```
45
+
46
+ ## Low-Level Utilities
47
+
48
+ For more granular measurements, you can use the lower-level functions:
49
+
50
+ - **`getPerformanceCheckpoint()`**: Returns a high-resolution timestamp, which you can use as a starting point.
51
+ - **`getExecutedPerformance(opts)`**: Calculates the elapsed time in milliseconds since a given checkpoint.
52
+
53
+ ### Example
54
+
55
+ ```typescript
56
+ import { getPerformanceCheckpoint, getExecutedPerformance } from '@venizia/ignis';
57
+
58
+ const start = getPerformanceCheckpoint();
59
+
60
+ // ... perform some work
61
+
62
+ const duration = getExecutedPerformance({ from: start });
63
+ console.log(`The work took ${duration} ms.`);
64
+ ```
@@ -0,0 +1,83 @@
1
+ # Promise Utility
2
+
3
+ The Promise utility provides helper functions for working with Promises, particularly for managing concurrency and transforming values.
4
+
5
+ ## `executePromiseWithLimit`
6
+
7
+ This function executes an array of asynchronous tasks concurrently, but with a specified limit on the number of promises running at any given time. This is useful for throttling asynchronous operations to avoid overwhelming a system (e.g., making a large number of concurrent API calls).
8
+
9
+ ### `executePromiseWithLimit(opts)`
10
+
11
+ - `opts` (object):
12
+ - `tasks` (Array<() => Promise<T>>): An array of functions that each return a Promise.
13
+ - `limit` (number): The maximum number of promises to execute in parallel.
14
+ - `onTaskDone` (<R>(opts: { result: R }) => ValueOrPromise<void>, optional): A callback function that is executed whenever a task is completed.
15
+
16
+ ### Example
17
+
18
+ ```typescript
19
+ import { executePromiseWithLimit, sleep } from '@venizia/ignis';
20
+
21
+ const tasks = [
22
+ () => sleep(1000).then(() => 'Task 1 done'),
23
+ () => sleep(500).then(() => 'Task 2 done'),
24
+ () => sleep(1200).then(() => 'Task 3 done'),
25
+ () => sleep(800).then(() => 'Task 4 done'),
26
+ ];
27
+
28
+ console.log('Starting tasks with a limit of 2...');
29
+
30
+ const results = await executePromiseWithLimit({
31
+ tasks,
32
+ limit: 2,
33
+ onTaskDone: ({ result }) => {
34
+ console.log('A task finished:', result);
35
+ },
36
+ });
37
+
38
+ console.log('All tasks finished:', results);
39
+ ```
40
+
41
+ ## `isPromiseLike`
42
+
43
+ A type guard function to check if a given value is a Promise-like object (i.e., it has a `then` method).
44
+
45
+ ```typescript
46
+ import { isPromiseLike } from '@venizia/ignis';
47
+
48
+ const a = Promise.resolve(1);
49
+ const b = 2;
50
+
51
+ if (isPromiseLike(a)) {
52
+ // This will run
53
+ }
54
+
55
+ if (isPromiseLike(b)) {
56
+ // This will not run
57
+ }
58
+ ```
59
+
60
+ ## `transformValueOrPromise`
61
+
62
+ This function applies a transformation function to a value that might be a direct value or a Promise.
63
+
64
+ ```typescript
65
+ import { transformValueOrPromise, isPromiseLike } from '@venizia/ignis';
66
+
67
+ const double = (n: number) => n * 2;
68
+
69
+ const result1 = await transformValueOrPromise(5, double); // => 10
70
+ const result2 = await transformValueOrPromise(Promise.resolve(5), double); // => 10
71
+ ```
72
+
73
+ ## `getDeepProperty`
74
+
75
+ Safely retrieves a deeply nested property from an object using a dot-separated path string. It throws an error if any part of the path is null or undefined.
76
+
77
+ ```typescript
78
+ import { getDeepProperty } from '@venizia/ignis';
79
+
80
+ const obj = { a: { b: { c: 'hello' } } };
81
+
82
+ const value = getDeepProperty(obj, 'a.b.c'); // => 'hello'
83
+ ```
@@ -0,0 +1,66 @@
1
+ # Request Utility
2
+
3
+ The Request utility provides functions for handling HTTP request data, such as parsing multipart form data.
4
+
5
+ ## `parseMultipartBody`
6
+
7
+ The `parseMultipartBody` function is an asynchronous utility for parsing `multipart/form-data` request bodies, which is essential for handling file uploads. It can store the uploaded files in memory or on disk.
8
+
9
+ ### `parseMultipartBody(opts)`
10
+
11
+ - `opts` (object):
12
+ - `context` (Hono.Context): The Hono context object for the current request.
13
+ - `storage` ('memory' | 'disk', optional): The storage strategy for uploaded files. Defaults to `'memory'`.
14
+ - `uploadDir` (string, optional): The directory to save files to when using the `'disk'` storage strategy. Defaults to `'./uploads'`.
15
+
16
+ The function returns a `Promise` that resolves to an array of `IParsedFile` objects.
17
+
18
+ ### `IParsedFile` Interface
19
+
20
+ - `fieldname`: The name of the form field.
21
+ - `originalname`: The original name of the uploaded file.
22
+ - `encoding`: The file's encoding.
23
+ - `mimetype`: The MIME type of the file.
24
+ - `size`: The size of the file in bytes.
25
+ - `buffer` (Buffer, optional): The file's content as a Buffer (if `storage` is `'memory'`).
26
+ - `filename` (string, optional): The name of the file on disk (if `storage` is `'disk'`).
27
+ - `path` (string, optional): The full path to the file on disk (if `storage` is `'disk'`).
28
+
29
+ ### Example
30
+
31
+ Here is an example of how to use `parseMultipartBody` in a controller to handle a file upload.
32
+
33
+ ```typescript
34
+ import { BaseController, controller, ... } from '@venizia/ignis';
35
+ import { parseMultipartBody } from '@venizia/ignis';
36
+
37
+ @controller({ path: '/files' })
38
+ export class FileController extends BaseController {
39
+ // ...
40
+ override binding() {
41
+ this.defineRoute({
42
+ configs: {
43
+ path: '/upload',
44
+ method: 'post',
45
+ // Note: You would typically define a request body schema
46
+ // for multipart/form-data in your OpenAPI spec.
47
+ },
48
+ handler: async (c) => {
49
+ try {
50
+ const files = await parseMultipartBody({
51
+ context: c,
52
+ storage: 'disk', // or 'memory'
53
+ uploadDir: './my-uploads',
54
+ });
55
+
56
+ console.log('Uploaded files:', files);
57
+
58
+ return c.json({ message: `${files.length} file(s) uploaded successfully.` });
59
+ } catch (error) {
60
+ return c.json({ message: 'Failed to upload files', error: error.message }, 500);
61
+ }
62
+ },
63
+ });
64
+ }
65
+ }
66
+ ```
@@ -0,0 +1,88 @@
1
+ # Schema Utility
2
+
3
+ The Schema utility provides a set of helper functions and predefined schemas for working with `zod` and `@hono/zod-openapi`. These utilities simplify the process of defining API request/response schemas and improve consistency in your API documentation.
4
+
5
+ ## `jsonContent`
6
+
7
+ The `jsonContent` function creates a standard OpenAPI content object for `application/json` payloads.
8
+
9
+ ```typescript
10
+ import { jsonContent, z } from '@venizia/ignis';
11
+
12
+ const UserSchema = z.object({
13
+ id: z.number(),
14
+ name: z.string(),
15
+ });
16
+
17
+ const userResponse = {
18
+ description: 'A single user object',
19
+ ...jsonContent({ schema: UserSchema }),
20
+ };
21
+ ```
22
+
23
+ ## `jsonResponse`
24
+
25
+ The `jsonResponse` function generates a standard OpenAPI response object that includes a success (200 OK) response and a default error response for 4xx/5xx status codes.
26
+
27
+ ```typescript
28
+ import { jsonResponse, z } from '@venizia/ignis';
29
+
30
+ const UserSchema = z.object({
31
+ id: z.number(),
32
+ name: z.string(),
33
+ });
34
+
35
+ this.defineRoute({
36
+ configs: {
37
+ path: '/',
38
+ method: 'get',
39
+ responses: jsonResponse({
40
+ description: 'A single user object',
41
+ schema: UserSchema,
42
+ }),
43
+ },
44
+ // ...
45
+ });
46
+ ```
47
+
48
+ ## `requiredString`
49
+
50
+ This function creates a `zod` string schema that is non-empty and can be further constrained by length.
51
+
52
+ ```typescript
53
+ import { requiredString } from '@venizia/ignis';
54
+
55
+ const schema = z.object({
56
+ username: requiredString({ min: 3, max: 20 }),
57
+ password: requiredString({ min: 8 }),
58
+ });
59
+ ```
60
+
61
+ ## Predefined Schemas
62
+
63
+ The utility also provides several predefined schemas for common use cases.
64
+
65
+ - **`AnyObjectSchema`**: A flexible schema for any object (`z.object().catchall(z.any())`).
66
+ - **`IdParamsSchema`**: A schema for a numeric path parameter named `id`.
67
+ - **`UUIDParamsSchema`**: A schema for a UUID path parameter named `id`.
68
+
69
+ ### Example
70
+
71
+ ```typescript
72
+ import { IdParamsSchema } from '@venizia/ignis';
73
+
74
+ this.defineRoute({
75
+ configs: {
76
+ path: '/{id}',
77
+ method: 'get',
78
+ request: {
79
+ params: IdParamsSchema,
80
+ },
81
+ // ...
82
+ },
83
+ handler: (c) => {
84
+ const { id } = c.req.valid('param'); // id is a number
85
+ // ...
86
+ },
87
+ });
88
+ ```