@gravito/mass 2.0.0 → 3.0.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.
@@ -1,18 +1,21 @@
1
1
  import type { Env, MiddlewareHandler } from '@gravito/photon';
2
2
  import type { Static, TSchema } from '@sinclair/typebox';
3
3
  /**
4
- * Validation source type.
4
+ * The source of the data to be validated.
5
+ * @public
5
6
  */
6
7
  export type ValidationSource = 'json' | 'query' | 'param' | 'form';
7
8
  /**
8
- * Create a validation middleware.
9
+ * Create a validation middleware using TypeBox.
9
10
  *
10
- * Validates the request data against the provided TypeBox schema.
11
+ * This function wraps the Hono TypeBox validator, providing a seamless
12
+ * integration with Gravito Photon for high-performance schema validation.
11
13
  *
12
- * @param source - Validation source (json, query, param, form)
13
- * @param schema - TypeBox Schema
14
- * @param hook - Optional callback to handle validation results
15
- * @returns Photon middleware handler that validates the request.
14
+ * @param source - The request part to validate (json, query, param, form)
15
+ * @param schema - The TypeBox schema to validate against
16
+ * @param hook - Optional callback to handle validation results manually
17
+ * @returns A Photon-compatible middleware handler.
18
+ * @public
16
19
  */
17
20
  export declare function validate<T extends TSchema, S extends ValidationSource, E extends Env = any, P extends string = any>(source: S, schema: T, hook?: (result: any, c: any) => any): MiddlewareHandler<E, P, {
18
21
  in: {
@@ -1 +1 @@
1
- {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../../src/validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAE7D,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAExD;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAAA;AAElE;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CACtB,CAAC,SAAS,OAAO,EACjB,CAAC,SAAS,gBAAgB,EAC1B,CAA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,CAAA;CAC7B,CACF,CAEA"}
@@ -1,3 +1,21 @@
1
+ /**
2
+ * @gravito/photon - High-performance web framework based on Hono.
3
+ *
4
+ * Photon is the primary web engine for Gravito, providing a fast,
5
+ * flexible, and standard-compliant API for building web applications.
6
+ * It re-exports Hono while adding enterprise-grade middleware and utilities.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { Photon } from '@gravito/photon'
11
+ * const app = new Photon()
12
+ * app.get('/', (c) => c.text('Hello!'))
13
+ * ```
14
+ */
1
15
  export * from 'hono';
2
16
  export { Hono as Photon } from 'hono';
17
+ /**
18
+ * Binary-related middleware for Photon.
19
+ */
20
+ export * from './middleware/binary';
3
21
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../photon/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAA;AACpB,OAAO,EAAE,IAAI,IAAI,MAAM,EAAE,MAAM,MAAM,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../photon/src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,cAAc,MAAM,CAAA;AACpB,OAAO,EAAE,IAAI,IAAI,MAAM,EAAE,MAAM,MAAM,CAAA;AACrC;;GAEG;AACH,cAAc,qBAAqB,CAAA"}
@@ -0,0 +1,35 @@
1
+ import type { MiddlewareHandler } from 'hono';
2
+ /**
3
+ * Binary Middleware for Photon
4
+ *
5
+ * Automatically detects 'Accept: application/cbor' and encodes
6
+ * JSON responses using the CBOR binary format for high-performance communication.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { Photon } from '@gravito/photon'
11
+ * import { binaryMiddleware } from '@gravito/photon/middleware/binary'
12
+ *
13
+ * const app = new Photon()
14
+ * app.use(binaryMiddleware())
15
+ *
16
+ * app.get('/api/data', (c) => c.json({ items: [...] }))
17
+ * ```
18
+ *
19
+ * @performance
20
+ * - CBOR encoding is ~2-3x faster than JSON.stringify for large objects
21
+ * - Binary format reduces payload size by 20-40% on average
22
+ * - Recommended for high-frequency API calls with large datasets
23
+ *
24
+ * @client_usage
25
+ * ```typescript
26
+ * import { decode } from 'cborg'
27
+ *
28
+ * const res = await fetch('/api/data', {
29
+ * headers: { Accept: 'application/cbor' }
30
+ * })
31
+ * const data = decode(new Uint8Array(await res.arrayBuffer()))
32
+ * ```
33
+ */
34
+ export declare const binaryMiddleware: () => MiddlewareHandler;
35
+ //# sourceMappingURL=binary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binary.d.ts","sourceRoot":"","sources":["../../../../../photon/src/middleware/binary.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAA;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,gBAAgB,QAAO,iBAyBnC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravito/mass",
3
- "version": "2.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "TypeBox-based validation for Gravito - High-performance schema validation with full TypeScript support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",