@parsrun/types 0.1.0
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 +133 -0
- package/dist/index.d.ts +2119 -0
- package/dist/index.js +1109 -0
- package/dist/index.js.map +1 -0
- package/package.json +51 -0
package/README.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# @parsrun/types
|
|
2
|
+
|
|
3
|
+
Core types and validation schemas for Pars framework using ArkType.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Type-Safe**: Full TypeScript support
|
|
8
|
+
- **Runtime Validation**: ArkType-based validation
|
|
9
|
+
- **Reusable Schemas**: Common validation patterns
|
|
10
|
+
- **Inference**: Automatic type inference from schemas
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @parsrun/types
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { type, createValidator } from '@parsrun/types';
|
|
22
|
+
|
|
23
|
+
// Define a schema
|
|
24
|
+
const userSchema = type({
|
|
25
|
+
id: 'string',
|
|
26
|
+
email: 'string.email',
|
|
27
|
+
name: 'string',
|
|
28
|
+
age: 'number >= 0',
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Infer TypeScript type
|
|
32
|
+
type User = typeof userSchema.infer;
|
|
33
|
+
|
|
34
|
+
// Validate data
|
|
35
|
+
const result = userSchema(data);
|
|
36
|
+
if (result.problems) {
|
|
37
|
+
console.error(result.problems);
|
|
38
|
+
} else {
|
|
39
|
+
console.log(result.data);
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## API Overview
|
|
44
|
+
|
|
45
|
+
### Common Types
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import {
|
|
49
|
+
// Primitives
|
|
50
|
+
StringType,
|
|
51
|
+
NumberType,
|
|
52
|
+
BooleanType,
|
|
53
|
+
DateType,
|
|
54
|
+
|
|
55
|
+
// Common patterns
|
|
56
|
+
EmailType,
|
|
57
|
+
UUIDType,
|
|
58
|
+
URLType,
|
|
59
|
+
|
|
60
|
+
// Pars-specific
|
|
61
|
+
TenantId,
|
|
62
|
+
UserId,
|
|
63
|
+
SessionId,
|
|
64
|
+
} from '@parsrun/types';
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Validation Helpers
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { createValidator, validate } from '@parsrun/types';
|
|
71
|
+
|
|
72
|
+
// Create reusable validator
|
|
73
|
+
const validateUser = createValidator(userSchema);
|
|
74
|
+
|
|
75
|
+
// Validate with detailed errors
|
|
76
|
+
const { data, errors } = validate(userSchema, input);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Schema Composition
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { type } from '@parsrun/types';
|
|
83
|
+
|
|
84
|
+
const addressSchema = type({
|
|
85
|
+
street: 'string',
|
|
86
|
+
city: 'string',
|
|
87
|
+
country: 'string',
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const userWithAddressSchema = type({
|
|
91
|
+
...userSchema.def,
|
|
92
|
+
address: addressSchema,
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Optional & Nullable
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
const schema = type({
|
|
100
|
+
required: 'string',
|
|
101
|
+
optional: 'string?', // string | undefined
|
|
102
|
+
nullable: 'string | null', // string | null
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Built-in Schemas
|
|
107
|
+
|
|
108
|
+
| Schema | Description |
|
|
109
|
+
|--------|-------------|
|
|
110
|
+
| `EmailSchema` | Email validation |
|
|
111
|
+
| `UUIDSchema` | UUID v4 format |
|
|
112
|
+
| `URLSchema` | Valid URL |
|
|
113
|
+
| `DateSchema` | ISO date string |
|
|
114
|
+
| `PaginationSchema` | `{ page, limit }` |
|
|
115
|
+
| `SortSchema` | `{ field, order }` |
|
|
116
|
+
|
|
117
|
+
## Exports
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import {
|
|
121
|
+
type,
|
|
122
|
+
createValidator,
|
|
123
|
+
validate,
|
|
124
|
+
// Built-in schemas
|
|
125
|
+
EmailSchema,
|
|
126
|
+
UUIDSchema,
|
|
127
|
+
PaginationSchema,
|
|
128
|
+
} from '@parsrun/types';
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## License
|
|
132
|
+
|
|
133
|
+
MIT
|