@kanjijs/contracts 0.2.0-beta.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 (3) hide show
  1. package/README.md +46 -0
  2. package/dist/index.js +1 -0
  3. package/package.json +21 -0
package/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # @kanjijs/contracts
2
+
3
+ This package defines the pure interfaces and types that power the **Contract-First** architecture of Kanjijs. It contains zero runtime logic and is designed to be lightweight.
4
+
5
+ ## 🔑 Key Concepts
6
+
7
+ ### `SchemaLike`
8
+
9
+ An abstract type (`unknown` by default) representing a validation schema.
10
+ This allows the framework to be agnostic of the validation library (Zod, Yup, TypeBox, etc.).
11
+
12
+ ```typescript
13
+ export type SchemaLike = unknown;
14
+ ```
15
+
16
+ ### `ContractSpec<T>`
17
+
18
+ The blueprint of an API endpoint. It defines what strict shapes are expected for inputs and outputs.
19
+ It uses Generics `<T>` (defaulting to `SchemaLike`) to allow you to pass specific Schema types if needed.
20
+
21
+ ```typescript
22
+ export interface ContractSpec<T = SchemaLike> {
23
+ request?: {
24
+ params?: T;
25
+ query?: T;
26
+ headers?: T;
27
+ body?: T;
28
+ };
29
+ response?: {
30
+ [status: number]: T;
31
+ };
32
+ }
33
+ ```
34
+
35
+ ### `ValidatorAdapter<S>`
36
+
37
+ The interface that any validation library must implement to work with Kanjijs.
38
+
39
+ ```typescript
40
+ export interface ValidatorAdapter<S = SchemaLike> {
41
+ parse<O = unknown>(
42
+ schema: S,
43
+ data: unknown,
44
+ ): Promise<{ success: true; data: O } | { success: false; issues: unknown[] }>;
45
+ }
46
+ ```
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ // @bun
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@kanjijs/contracts",
3
+ "version": "0.2.0-beta.1",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "README.md",
10
+ "LICENSE"
11
+ ],
12
+ "scripts": {
13
+ "build": "bun build src/index.ts --outdir dist --target bun"
14
+ },
15
+ "dependencies": {
16
+ "@kanjijs/common": "workspace:*"
17
+ },
18
+ "devDependencies": {
19
+ "zod": "^3.0.0"
20
+ }
21
+ }