@wentools/zli 0.2.0-beta.2dc33a43
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/LICENSE +21 -0
- package/README.md +226 -0
- package/esm/_dnt.shims.d.ts +6 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +61 -0
- package/esm/arg.d.ts +9 -0
- package/esm/arg.d.ts.map +1 -0
- package/esm/arg.js +4 -0
- package/esm/create_command.d.ts +28 -0
- package/esm/create_command.d.ts.map +1 -0
- package/esm/create_command.js +17 -0
- package/esm/create_command_directory.d.ts +35 -0
- package/esm/create_command_directory.d.ts.map +1 -0
- package/esm/create_command_directory.js +31 -0
- package/esm/create_flag_arg.d.ts +23 -0
- package/esm/create_flag_arg.d.ts.map +1 -0
- package/esm/create_flag_arg.js +14 -0
- package/esm/create_positional_arg.d.ts +24 -0
- package/esm/create_positional_arg.d.ts.map +1 -0
- package/esm/create_positional_arg.js +15 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/err/err.d.ts +38 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/err/err.d.ts.map +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/err/err.js +38 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/err/index.d.ts +2 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/err/index.d.ts.map +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/err/index.js +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/index.d.ts +156 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/index.d.ts.map +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/index.js +65 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/is_result/index.d.ts +2 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/is_result/index.d.ts.map +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/is_result/index.js +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/is_result/is_result.d.ts +11 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/is_result/is_result.d.ts.map +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/is_result/is_result.js +14 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/propagate_err/index.d.ts +2 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/propagate_err/index.d.ts.map +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/propagate_err/index.js +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/propagate_err/propagate_err.d.ts +28 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/propagate_err/propagate_err.d.ts.map +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/propagate_err/propagate_err.js +30 -0
- package/esm/detect_arg_conflicts/detect_arg_conflicts.d.ts +19 -0
- package/esm/detect_arg_conflicts/detect_arg_conflicts.d.ts.map +1 -0
- package/esm/detect_arg_conflicts/detect_arg_conflicts.js +54 -0
- package/esm/detect_arg_conflicts/mod.d.ts +3 -0
- package/esm/detect_arg_conflicts/mod.d.ts.map +1 -0
- package/esm/detect_arg_conflicts/mod.js +1 -0
- package/esm/generate_help_text/generate_help_text.d.ts +13 -0
- package/esm/generate_help_text/generate_help_text.d.ts.map +1 -0
- package/esm/generate_help_text/generate_help_text.js +54 -0
- package/esm/generate_help_text/mod.d.ts +2 -0
- package/esm/generate_help_text/mod.d.ts.map +1 -0
- package/esm/generate_help_text/mod.js +1 -0
- package/esm/infer_args_type.d.ts +29 -0
- package/esm/infer_args_type.d.ts.map +1 -0
- package/esm/infer_args_type.js +6 -0
- package/esm/is_boolean_schema/is_boolean_schema.d.ts +12 -0
- package/esm/is_boolean_schema/is_boolean_schema.d.ts.map +1 -0
- package/esm/is_boolean_schema/is_boolean_schema.js +21 -0
- package/esm/is_boolean_schema/mod.d.ts +2 -0
- package/esm/is_boolean_schema/mod.d.ts.map +1 -0
- package/esm/is_boolean_schema/mod.js +1 -0
- package/esm/mod.d.ts +8 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +1 -0
- package/esm/package.json +3 -0
- package/esm/parse_args/mod.d.ts +3 -0
- package/esm/parse_args/mod.d.ts.map +1 -0
- package/esm/parse_args/mod.js +1 -0
- package/esm/parse_args/parse_args.d.ts +24 -0
- package/esm/parse_args/parse_args.d.ts.map +1 -0
- package/esm/parse_args/parse_args.js +89 -0
- package/esm/run.d.ts +19 -0
- package/esm/run.d.ts.map +1 -0
- package/esm/run.js +152 -0
- package/esm/validate_args/mod.d.ts +3 -0
- package/esm/validate_args/mod.d.ts.map +1 -0
- package/esm/validate_args/mod.js +1 -0
- package/esm/validate_args/validate_args.d.ts +20 -0
- package/esm/validate_args/validate_args.d.ts.map +1 -0
- package/esm/validate_args/validate_args.js +23 -0
- package/esm/zli.d.ts +118 -0
- package/esm/zli.d.ts.map +1 -0
- package/esm/zli.js +124 -0
- package/package.json +39 -0
- package/script/_dnt.shims.d.ts +6 -0
- package/script/_dnt.shims.d.ts.map +1 -0
- package/script/_dnt.shims.js +65 -0
- package/script/arg.d.ts +9 -0
- package/script/arg.d.ts.map +1 -0
- package/script/arg.js +5 -0
- package/script/create_command.d.ts +28 -0
- package/script/create_command.d.ts.map +1 -0
- package/script/create_command.js +20 -0
- package/script/create_command_directory.d.ts +35 -0
- package/script/create_command_directory.d.ts.map +1 -0
- package/script/create_command_directory.js +34 -0
- package/script/create_flag_arg.d.ts +23 -0
- package/script/create_flag_arg.d.ts.map +1 -0
- package/script/create_flag_arg.js +17 -0
- package/script/create_positional_arg.d.ts +24 -0
- package/script/create_positional_arg.d.ts.map +1 -0
- package/script/create_positional_arg.js +18 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/err/err.d.ts +38 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/err/err.d.ts.map +1 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/err/err.js +41 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/err/index.d.ts +2 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/err/index.d.ts.map +1 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/err/index.js +5 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/index.d.ts +156 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/index.d.ts.map +1 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/index.js +77 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/is_result/index.d.ts +2 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/is_result/index.d.ts.map +1 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/is_result/index.js +5 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/is_result/is_result.d.ts +11 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/is_result/is_result.d.ts.map +1 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/is_result/is_result.js +17 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/propagate_err/index.d.ts +2 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/propagate_err/index.d.ts.map +1 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/propagate_err/index.js +5 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/propagate_err/propagate_err.d.ts +28 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/propagate_err/propagate_err.d.ts.map +1 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/propagate_err/propagate_err.js +33 -0
- package/script/detect_arg_conflicts/detect_arg_conflicts.d.ts +19 -0
- package/script/detect_arg_conflicts/detect_arg_conflicts.d.ts.map +1 -0
- package/script/detect_arg_conflicts/detect_arg_conflicts.js +57 -0
- package/script/detect_arg_conflicts/mod.d.ts +3 -0
- package/script/detect_arg_conflicts/mod.d.ts.map +1 -0
- package/script/detect_arg_conflicts/mod.js +5 -0
- package/script/generate_help_text/generate_help_text.d.ts +13 -0
- package/script/generate_help_text/generate_help_text.d.ts.map +1 -0
- package/script/generate_help_text/generate_help_text.js +57 -0
- package/script/generate_help_text/mod.d.ts +2 -0
- package/script/generate_help_text/mod.d.ts.map +1 -0
- package/script/generate_help_text/mod.js +5 -0
- package/script/infer_args_type.d.ts +29 -0
- package/script/infer_args_type.d.ts.map +1 -0
- package/script/infer_args_type.js +7 -0
- package/script/is_boolean_schema/is_boolean_schema.d.ts +12 -0
- package/script/is_boolean_schema/is_boolean_schema.d.ts.map +1 -0
- package/script/is_boolean_schema/is_boolean_schema.js +24 -0
- package/script/is_boolean_schema/mod.d.ts +2 -0
- package/script/is_boolean_schema/mod.d.ts.map +1 -0
- package/script/is_boolean_schema/mod.js +5 -0
- package/script/mod.d.ts +8 -0
- package/script/mod.d.ts.map +1 -0
- package/script/mod.js +5 -0
- package/script/package.json +3 -0
- package/script/parse_args/mod.d.ts +3 -0
- package/script/parse_args/mod.d.ts.map +1 -0
- package/script/parse_args/mod.js +5 -0
- package/script/parse_args/parse_args.d.ts +24 -0
- package/script/parse_args/parse_args.d.ts.map +1 -0
- package/script/parse_args/parse_args.js +92 -0
- package/script/run.d.ts +19 -0
- package/script/run.d.ts.map +1 -0
- package/script/run.js +189 -0
- package/script/validate_args/mod.d.ts +3 -0
- package/script/validate_args/mod.d.ts.map +1 -0
- package/script/validate_args/mod.js +5 -0
- package/script/validate_args/validate_args.d.ts +20 -0
- package/script/validate_args/validate_args.d.ts.map +1 -0
- package/script/validate_args/validate_args.js +26 -0
- package/script/zli.d.ts +118 -0
- package/script/zli.d.ts.map +1 -0
- package/script/zli.js +127 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 wentools
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
# @wentools/zli
|
|
2
|
+
|
|
3
|
+
Lightweight CLI builder with Zod validation and type-safe argument parsing.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx jsr add @wentools/zli
|
|
9
|
+
pnpm add zod@4
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- **Type-safe arguments** inferred from Zod schemas
|
|
15
|
+
- **Flexible parsing**: positional args by order OR by `--name`
|
|
16
|
+
- **Short flags**: `--verbose` or `-v`
|
|
17
|
+
- **Copy-paste friendly**: easy to expand from simple to multi-command scripts
|
|
18
|
+
- **Auto-generated help text**
|
|
19
|
+
- **Pretty validation error messages**
|
|
20
|
+
- **Conflict detection** for duplicate names/shorts
|
|
21
|
+
- **Result integration** for error handling
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
### Simple Single Command
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { zli } from '@wentools/zli'
|
|
29
|
+
import { z } from 'zod'
|
|
30
|
+
|
|
31
|
+
const command = zli.c(
|
|
32
|
+
[
|
|
33
|
+
zli.p('email', z.string().email(), {
|
|
34
|
+
description: 'User email address',
|
|
35
|
+
short: 'e'
|
|
36
|
+
}),
|
|
37
|
+
zli.f('verbose', z.boolean().optional().default(false), {
|
|
38
|
+
description: 'Verbose output',
|
|
39
|
+
short: 'v'
|
|
40
|
+
})
|
|
41
|
+
],
|
|
42
|
+
(args) => {
|
|
43
|
+
console.log(args.email) // typed as string
|
|
44
|
+
console.log(args.verbose) // typed as boolean
|
|
45
|
+
},
|
|
46
|
+
{ description: 'Check user permissions' }
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
zli.run(command)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Invocation:**
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# Positional
|
|
56
|
+
pnpm tsx script.ts user@example.com
|
|
57
|
+
|
|
58
|
+
# Named
|
|
59
|
+
pnpm tsx script.ts --email user@example.com
|
|
60
|
+
|
|
61
|
+
# Short flag
|
|
62
|
+
pnpm tsx script.ts -e user@example.com
|
|
63
|
+
|
|
64
|
+
# With flags
|
|
65
|
+
pnpm tsx script.ts user@example.com --verbose
|
|
66
|
+
|
|
67
|
+
# Help
|
|
68
|
+
pnpm tsx script.ts --help
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Multi-Command Script
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { zli } from '@wentools/zli'
|
|
75
|
+
import { z } from 'zod'
|
|
76
|
+
|
|
77
|
+
const check = zli.c(
|
|
78
|
+
[zli.p('email', z.string().email())],
|
|
79
|
+
(args) => console.log(`Checking ${args.email}`),
|
|
80
|
+
{ description: 'Check user permissions' }
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
const promote = zli.c(
|
|
84
|
+
[zli.p('email', z.string().email())],
|
|
85
|
+
(args) => console.log(`Promoting ${args.email}`),
|
|
86
|
+
{ description: 'Promote user to admin' }
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
zli.run({
|
|
90
|
+
name: 'user',
|
|
91
|
+
description: 'User management commands',
|
|
92
|
+
commands: {
|
|
93
|
+
check,
|
|
94
|
+
promote
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Nested Command Directories
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
const cli = zli.d('app', {
|
|
103
|
+
description: 'Application CLI',
|
|
104
|
+
commands: {
|
|
105
|
+
db: zli.d('db', {
|
|
106
|
+
description: 'Database commands',
|
|
107
|
+
commands: {
|
|
108
|
+
migrate: zli.c([], () => console.log('Migrating...')),
|
|
109
|
+
seed: zli.c([], () => console.log('Seeding...')),
|
|
110
|
+
}
|
|
111
|
+
}),
|
|
112
|
+
version: zli.c([], () => console.log('1.0.0'))
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
zli.run(cli)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**Usage:**
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
pnpm tsx script.ts db migrate
|
|
123
|
+
pnpm tsx script.ts db --help
|
|
124
|
+
pnpm tsx script.ts version
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## API
|
|
128
|
+
|
|
129
|
+
### `zli.p(name, schema, options?)` - Positional Argument
|
|
130
|
+
|
|
131
|
+
Creates a positional argument that can be specified by position, `--name`, or `-short`.
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
zli.p('email', z.string().email(), {
|
|
135
|
+
short: 'e',
|
|
136
|
+
description: 'User email address'
|
|
137
|
+
})
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### `zli.f(name, schema, options?)` - Flag Argument
|
|
141
|
+
|
|
142
|
+
Creates a flag argument specified with `--name` or `-short`.
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
zli.f('verbose', z.boolean().optional().default(false), {
|
|
146
|
+
short: 'v',
|
|
147
|
+
description: 'Enable verbose output'
|
|
148
|
+
})
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### `zli.c(args, handler, options?)` - Command
|
|
152
|
+
|
|
153
|
+
Creates a command with arguments and handler.
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
zli.c(
|
|
157
|
+
[zli.p('name', z.string())],
|
|
158
|
+
async (args) => {
|
|
159
|
+
// Handler can be sync or async
|
|
160
|
+
// Can return void or Result
|
|
161
|
+
},
|
|
162
|
+
{ description: 'Command description' }
|
|
163
|
+
)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### `zli.d(name, options)` - Command Directory
|
|
167
|
+
|
|
168
|
+
Creates a directory of commands for hierarchical organization.
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
zli.d('admin', {
|
|
172
|
+
description: 'Admin commands',
|
|
173
|
+
commands: {
|
|
174
|
+
users: usersDirectory,
|
|
175
|
+
config: configCommand
|
|
176
|
+
}
|
|
177
|
+
})
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### `zli.run(input)` - Execute CLI
|
|
181
|
+
|
|
182
|
+
Runs a command or command directory.
|
|
183
|
+
|
|
184
|
+
## Error Handling with Results
|
|
185
|
+
|
|
186
|
+
Handlers can return `Result` types from `@wentools/result`:
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
import { err } from '@wentools/result'
|
|
190
|
+
|
|
191
|
+
const command = zli.c(
|
|
192
|
+
[zli.p('email', z.string().email())],
|
|
193
|
+
async (args) => {
|
|
194
|
+
const user = await findUser(args.email)
|
|
195
|
+
if (!user) {
|
|
196
|
+
return err('user_not_found', 'User not found')
|
|
197
|
+
}
|
|
198
|
+
console.log(`Found: ${user.name}`)
|
|
199
|
+
}
|
|
200
|
+
)
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
If the handler returns `err()`, zli will:
|
|
204
|
+
- Log the error as JSON
|
|
205
|
+
- Exit with code 1
|
|
206
|
+
|
|
207
|
+
## Argument Parsing Behavior
|
|
208
|
+
|
|
209
|
+
- Positional args fill slots left-to-right
|
|
210
|
+
- Named flags (`--name` or `-short`) can fill any slot
|
|
211
|
+
- Explicit (named) overrides implicit (positional)
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
# These are equivalent:
|
|
215
|
+
script.ts user@example.com
|
|
216
|
+
script.ts --email user@example.com
|
|
217
|
+
script.ts -e user@example.com
|
|
218
|
+
|
|
219
|
+
# Override positional with flag:
|
|
220
|
+
script.ts wrong@example.com --email correct@example.com
|
|
221
|
+
# Result: args.email = "correct@example.com"
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## License
|
|
225
|
+
|
|
226
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAKvC,eAAO,MAAM,aAAa;;CAA2C,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Deno } from "@deno/shim-deno";
|
|
2
|
+
export { Deno } from "@deno/shim-deno";
|
|
3
|
+
const dntGlobals = {
|
|
4
|
+
Deno,
|
|
5
|
+
};
|
|
6
|
+
export const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
|
|
7
|
+
function createMergeProxy(baseObj, extObj) {
|
|
8
|
+
return new Proxy(baseObj, {
|
|
9
|
+
get(_target, prop, _receiver) {
|
|
10
|
+
if (prop in extObj) {
|
|
11
|
+
return extObj[prop];
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
return baseObj[prop];
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
set(_target, prop, value) {
|
|
18
|
+
if (prop in extObj) {
|
|
19
|
+
delete extObj[prop];
|
|
20
|
+
}
|
|
21
|
+
baseObj[prop] = value;
|
|
22
|
+
return true;
|
|
23
|
+
},
|
|
24
|
+
deleteProperty(_target, prop) {
|
|
25
|
+
let success = false;
|
|
26
|
+
if (prop in extObj) {
|
|
27
|
+
delete extObj[prop];
|
|
28
|
+
success = true;
|
|
29
|
+
}
|
|
30
|
+
if (prop in baseObj) {
|
|
31
|
+
delete baseObj[prop];
|
|
32
|
+
success = true;
|
|
33
|
+
}
|
|
34
|
+
return success;
|
|
35
|
+
},
|
|
36
|
+
ownKeys(_target) {
|
|
37
|
+
const baseKeys = Reflect.ownKeys(baseObj);
|
|
38
|
+
const extKeys = Reflect.ownKeys(extObj);
|
|
39
|
+
const extKeysSet = new Set(extKeys);
|
|
40
|
+
return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
|
|
41
|
+
},
|
|
42
|
+
defineProperty(_target, prop, desc) {
|
|
43
|
+
if (prop in extObj) {
|
|
44
|
+
delete extObj[prop];
|
|
45
|
+
}
|
|
46
|
+
Reflect.defineProperty(baseObj, prop, desc);
|
|
47
|
+
return true;
|
|
48
|
+
},
|
|
49
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
50
|
+
if (prop in extObj) {
|
|
51
|
+
return Reflect.getOwnPropertyDescriptor(extObj, prop);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return Reflect.getOwnPropertyDescriptor(baseObj, prop);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
has(_target, prop) {
|
|
58
|
+
return prop in extObj || prop in baseObj;
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
package/esm/arg.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Arg type - union of positional and flag args
|
|
3
|
+
*/
|
|
4
|
+
import type { PositionalArg } from './create_positional_arg.js';
|
|
5
|
+
import type { FlagArg } from './create_flag_arg.js';
|
|
6
|
+
import type { ZodSchema } from 'zod';
|
|
7
|
+
type Arg = PositionalArg<ZodSchema> | FlagArg<ZodSchema>;
|
|
8
|
+
export type { Arg };
|
|
9
|
+
//# sourceMappingURL=arg.d.ts.map
|
package/esm/arg.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arg.d.ts","sourceRoot":"","sources":["../src/arg.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAEpC,KAAK,GAAG,GAAG,aAAa,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;AAExD,YAAY,EAAE,GAAG,EAAE,CAAA"}
|
package/esm/arg.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a command configuration
|
|
3
|
+
*
|
|
4
|
+
* A command consists of:
|
|
5
|
+
* - Args (positional and flags)
|
|
6
|
+
* - Handler function (sync or async)
|
|
7
|
+
* - Optional description
|
|
8
|
+
*
|
|
9
|
+
* Type inference: The handler args are automatically typed based on the Zod schemas
|
|
10
|
+
* in the args array. This provides full autocomplete and type safety.
|
|
11
|
+
*/
|
|
12
|
+
import type { Arg } from './arg.js';
|
|
13
|
+
import type { InferArgsType } from './infer_args_type.js';
|
|
14
|
+
import type { Result } from './deps/jsr.io/@wentools/result/0.1.0/src/index.js';
|
|
15
|
+
type MaybeResult<TValue = void, TError = unknown> = TValue | Result<TValue, TError>;
|
|
16
|
+
type CommandHandler<TArgs> = (args: TArgs) => MaybeResult<void> | Promise<MaybeResult<void>>;
|
|
17
|
+
type Command<TArgs extends readonly Arg[] = readonly Arg[]> = {
|
|
18
|
+
args: TArgs;
|
|
19
|
+
handler: CommandHandler<InferArgsType<TArgs>>;
|
|
20
|
+
description?: string;
|
|
21
|
+
};
|
|
22
|
+
type CommandOptions = {
|
|
23
|
+
description?: string;
|
|
24
|
+
};
|
|
25
|
+
declare const createCommand: <const TArgs extends readonly Arg[]>(args: TArgs, handler: CommandHandler<InferArgsType<TArgs>>, options?: CommandOptions) => Command<TArgs>;
|
|
26
|
+
export { createCommand };
|
|
27
|
+
export type { Command, CommandHandler, CommandOptions, MaybeResult };
|
|
28
|
+
//# sourceMappingURL=create_command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_command.d.ts","sourceRoot":"","sources":["../src/create_command.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AACnC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mDAAmD,CAAA;AAE/E,KAAK,WAAW,CAAC,MAAM,GAAG,IAAI,EAAE,MAAM,GAAG,OAAO,IAAI,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAEnF,KAAK,cAAc,CAAC,KAAK,IAAI,CAAC,IAAI,EAAE,KAAK,KAAK,WAAW,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAA;AAE5F,KAAK,OAAO,CAAC,KAAK,SAAS,SAAS,GAAG,EAAE,GAAG,SAAS,GAAG,EAAE,IAAI;IAC7D,IAAI,EAAE,KAAK,CAAA;IACX,OAAO,EAAE,cAAc,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAA;IAC7C,WAAW,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,KAAK,cAAc,GAAG;IACrB,WAAW,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,QAAA,MAAM,aAAa,GAAI,KAAK,CAAC,KAAK,SAAS,SAAS,GAAG,EAAE,EACxD,MAAM,KAAK,EACX,SAAS,cAAc,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,EAC7C,UAAU,cAAc,KACtB,OAAO,CAAC,KAAK,CAId,CAAA;AAEF,OAAO,EAAE,aAAa,EAAE,CAAA;AACxB,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a command configuration
|
|
3
|
+
*
|
|
4
|
+
* A command consists of:
|
|
5
|
+
* - Args (positional and flags)
|
|
6
|
+
* - Handler function (sync or async)
|
|
7
|
+
* - Optional description
|
|
8
|
+
*
|
|
9
|
+
* Type inference: The handler args are automatically typed based on the Zod schemas
|
|
10
|
+
* in the args array. This provides full autocomplete and type safety.
|
|
11
|
+
*/
|
|
12
|
+
const createCommand = (args, handler, options) => ({
|
|
13
|
+
args,
|
|
14
|
+
handler,
|
|
15
|
+
description: options?.description,
|
|
16
|
+
});
|
|
17
|
+
export { createCommand };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a command directory configuration
|
|
3
|
+
*
|
|
4
|
+
* A command directory can contain both leaf commands and nested directories,
|
|
5
|
+
* allowing for hierarchical CLI organization.
|
|
6
|
+
*
|
|
7
|
+
* Think of it like a file system:
|
|
8
|
+
* - zli.c() = executable file (does work)
|
|
9
|
+
* - zli.d() = directory (organizes commands)
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const collaborators = zli.d('collaborators', {
|
|
13
|
+
* description: 'Manage collaborators',
|
|
14
|
+
* commands: {
|
|
15
|
+
* add: addCommand,
|
|
16
|
+
* remove: removeCommand,
|
|
17
|
+
* }
|
|
18
|
+
* })
|
|
19
|
+
*/
|
|
20
|
+
import type { CommandEntry } from './run.js';
|
|
21
|
+
type CommandDirectory = {
|
|
22
|
+
name: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
commands: Record<string, CommandEntry>;
|
|
25
|
+
};
|
|
26
|
+
type CommandDirectoryOptions = {
|
|
27
|
+
description?: string;
|
|
28
|
+
commands: Record<string, CommandEntry>;
|
|
29
|
+
};
|
|
30
|
+
declare const createCommandDirectory: <const TCommands extends Record<string, CommandEntry>>(name: string, options: CommandDirectoryOptions & {
|
|
31
|
+
commands: TCommands;
|
|
32
|
+
}) => CommandDirectory;
|
|
33
|
+
export { createCommandDirectory };
|
|
34
|
+
export type { CommandDirectory, CommandDirectoryOptions };
|
|
35
|
+
//# sourceMappingURL=create_command_directory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_command_directory.d.ts","sourceRoot":"","sources":["../src/create_command_directory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAE5C,KAAK,gBAAgB,GAAG;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;CACtC,CAAA;AAED,KAAK,uBAAuB,GAAG;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;CACtC,CAAA;AAED,QAAA,MAAM,sBAAsB,GAAI,KAAK,CAAC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,EACnF,MAAM,MAAM,EACZ,SAAS,uBAAuB,GAAG;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,KACxD,gBAWF,CAAA;AAED,OAAO,EAAE,sBAAsB,EAAE,CAAA;AACjC,YAAY,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a command directory configuration
|
|
3
|
+
*
|
|
4
|
+
* A command directory can contain both leaf commands and nested directories,
|
|
5
|
+
* allowing for hierarchical CLI organization.
|
|
6
|
+
*
|
|
7
|
+
* Think of it like a file system:
|
|
8
|
+
* - zli.c() = executable file (does work)
|
|
9
|
+
* - zli.d() = directory (organizes commands)
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const collaborators = zli.d('collaborators', {
|
|
13
|
+
* description: 'Manage collaborators',
|
|
14
|
+
* commands: {
|
|
15
|
+
* add: addCommand,
|
|
16
|
+
* remove: removeCommand,
|
|
17
|
+
* }
|
|
18
|
+
* })
|
|
19
|
+
*/
|
|
20
|
+
const createCommandDirectory = (name, options) => {
|
|
21
|
+
// Validation
|
|
22
|
+
if (Object.keys(options.commands).length === 0) {
|
|
23
|
+
throw new Error(`Command directory '${name}' must have at least one command`);
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
name,
|
|
27
|
+
description: options.description,
|
|
28
|
+
commands: options.commands,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export { createCommandDirectory };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a flag argument configuration
|
|
3
|
+
*
|
|
4
|
+
* Flags are specified with -- or - prefix:
|
|
5
|
+
* - Long name: script.ts --verbose
|
|
6
|
+
* - Short name: script.ts -v
|
|
7
|
+
*/
|
|
8
|
+
import type { ZodSchema } from 'zod';
|
|
9
|
+
type FlagArg<TSchema extends ZodSchema> = {
|
|
10
|
+
type: 'flag';
|
|
11
|
+
name: string;
|
|
12
|
+
schema: TSchema;
|
|
13
|
+
short?: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
};
|
|
16
|
+
type FlagArgOptions = {
|
|
17
|
+
short?: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
};
|
|
20
|
+
declare const createFlagArg: <TSchema extends ZodSchema>(name: string, schema: TSchema, options?: FlagArgOptions) => FlagArg<TSchema>;
|
|
21
|
+
export { createFlagArg };
|
|
22
|
+
export type { FlagArg, FlagArgOptions };
|
|
23
|
+
//# sourceMappingURL=create_flag_arg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_flag_arg.d.ts","sourceRoot":"","sources":["../src/create_flag_arg.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAEpC,KAAK,OAAO,CAAC,OAAO,SAAS,SAAS,IAAI;IACzC,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,OAAO,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,KAAK,cAAc,GAAG;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,QAAA,MAAM,aAAa,GAAI,OAAO,SAAS,SAAS,EAC/C,MAAM,MAAM,EACZ,QAAQ,OAAO,EACf,UAAU,cAAc,KACtB,OAAO,CAAC,OAAO,CAKhB,CAAA;AAEF,OAAO,EAAE,aAAa,EAAE,CAAA;AACxB,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a flag argument configuration
|
|
3
|
+
*
|
|
4
|
+
* Flags are specified with -- or - prefix:
|
|
5
|
+
* - Long name: script.ts --verbose
|
|
6
|
+
* - Short name: script.ts -v
|
|
7
|
+
*/
|
|
8
|
+
const createFlagArg = (name, schema, options) => ({
|
|
9
|
+
type: 'flag',
|
|
10
|
+
name,
|
|
11
|
+
schema,
|
|
12
|
+
...options,
|
|
13
|
+
});
|
|
14
|
+
export { createFlagArg };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a positional argument configuration
|
|
3
|
+
*
|
|
4
|
+
* Positional args can be specified:
|
|
5
|
+
* - By position: script.ts value
|
|
6
|
+
* - By long name: script.ts --name value
|
|
7
|
+
* - By short name: script.ts -n value
|
|
8
|
+
*/
|
|
9
|
+
import type { ZodSchema } from 'zod';
|
|
10
|
+
type PositionalArg<TSchema extends ZodSchema> = {
|
|
11
|
+
type: 'positional';
|
|
12
|
+
name: string;
|
|
13
|
+
schema: TSchema;
|
|
14
|
+
short?: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
};
|
|
17
|
+
type PositionalArgOptions = {
|
|
18
|
+
short?: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
};
|
|
21
|
+
declare const createPositionalArg: <TSchema extends ZodSchema>(name: string, schema: TSchema, options?: PositionalArgOptions) => PositionalArg<TSchema>;
|
|
22
|
+
export { createPositionalArg };
|
|
23
|
+
export type { PositionalArg, PositionalArgOptions };
|
|
24
|
+
//# sourceMappingURL=create_positional_arg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_positional_arg.d.ts","sourceRoot":"","sources":["../src/create_positional_arg.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAEpC,KAAK,aAAa,CAAC,OAAO,SAAS,SAAS,IAAI;IAC/C,IAAI,EAAE,YAAY,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,OAAO,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,KAAK,oBAAoB,GAAG;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,QAAA,MAAM,mBAAmB,GAAI,OAAO,SAAS,SAAS,EACrD,MAAM,MAAM,EACZ,QAAQ,OAAO,EACf,UAAU,oBAAoB,KAC5B,aAAa,CAAC,OAAO,CAKtB,CAAA;AAEF,OAAO,EAAE,mBAAmB,EAAE,CAAA;AAC9B,YAAY,EAAE,aAAa,EAAE,oBAAoB,EAAE,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a positional argument configuration
|
|
3
|
+
*
|
|
4
|
+
* Positional args can be specified:
|
|
5
|
+
* - By position: script.ts value
|
|
6
|
+
* - By long name: script.ts --name value
|
|
7
|
+
* - By short name: script.ts -n value
|
|
8
|
+
*/
|
|
9
|
+
const createPositionalArg = (name, schema, options) => ({
|
|
10
|
+
type: 'positional',
|
|
11
|
+
name,
|
|
12
|
+
schema,
|
|
13
|
+
...options,
|
|
14
|
+
});
|
|
15
|
+
export { createPositionalArg };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type Err } from 'neverthrow';
|
|
2
|
+
/**
|
|
3
|
+
* Create an Err Result with automatic literal type preservation
|
|
4
|
+
*
|
|
5
|
+
* Uses TypeScript 5.0+ const type parameters to preserve literal types automatically.
|
|
6
|
+
* No need for 'as const' - the type parameter is inferred as a literal!
|
|
7
|
+
*
|
|
8
|
+
* Returns Err<never, E> (not Result<never, E>) so .error is directly accessible.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // ✅ Simple error
|
|
12
|
+
* return err('not_found', 'User not found')
|
|
13
|
+
* // Type: Err<never, { type: 'not_found', message: string }>
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // ✅ Error with additional properties
|
|
17
|
+
* return err('not_found', 'User not found', { userId: '123' })
|
|
18
|
+
* // Type: Err<never, { type: 'not_found', message: string, userId: string }>
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // ✅ Direct .error access (no narrowing needed)
|
|
22
|
+
* const error = err('not_found', 'User not found').error
|
|
23
|
+
* // error.type is 'not_found'
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // ✅ Error with complex additional data
|
|
27
|
+
* return err('validation_failed', 'Invalid input', {
|
|
28
|
+
* field: 'email',
|
|
29
|
+
* errors: ['Invalid format']
|
|
30
|
+
* })
|
|
31
|
+
* // Type: Err<never, { type: 'validation_failed', message: string, field: string, errors: string[] }>
|
|
32
|
+
*/
|
|
33
|
+
declare const err: <const TType extends string, TAdditional extends Record<string, unknown> = Record<string, never>>(type: TType, message: string, additional?: TAdditional) => Err<never, {
|
|
34
|
+
type: TType;
|
|
35
|
+
message: string;
|
|
36
|
+
} & TAdditional>;
|
|
37
|
+
export { err };
|
|
38
|
+
//# sourceMappingURL=err.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"err.d.ts","sourceRoot":"","sources":["../../../../../../../../src/deps/jsr.io/@wentools/result/0.1.0/src/err/err.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,GAAG,EAAE,MAAM,YAAY,CAAA;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,QAAA,MAAM,GAAG,GACR,KAAK,CAAC,KAAK,SAAS,MAAM,EAC1B,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAEnE,MAAM,KAAK,EACX,SAAS,MAAM,EACf,aAAa,WAAW,KACtB,GAAG,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,WAAW,CAKP,CAAA;AAErD,OAAO,EAAE,GAAG,EAAE,CAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { err as _Err } from 'neverthrow';
|
|
2
|
+
/**
|
|
3
|
+
* Create an Err Result with automatic literal type preservation
|
|
4
|
+
*
|
|
5
|
+
* Uses TypeScript 5.0+ const type parameters to preserve literal types automatically.
|
|
6
|
+
* No need for 'as const' - the type parameter is inferred as a literal!
|
|
7
|
+
*
|
|
8
|
+
* Returns Err<never, E> (not Result<never, E>) so .error is directly accessible.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // ✅ Simple error
|
|
12
|
+
* return err('not_found', 'User not found')
|
|
13
|
+
* // Type: Err<never, { type: 'not_found', message: string }>
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // ✅ Error with additional properties
|
|
17
|
+
* return err('not_found', 'User not found', { userId: '123' })
|
|
18
|
+
* // Type: Err<never, { type: 'not_found', message: string, userId: string }>
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // ✅ Direct .error access (no narrowing needed)
|
|
22
|
+
* const error = err('not_found', 'User not found').error
|
|
23
|
+
* // error.type is 'not_found'
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // ✅ Error with complex additional data
|
|
27
|
+
* return err('validation_failed', 'Invalid input', {
|
|
28
|
+
* field: 'email',
|
|
29
|
+
* errors: ['Invalid format']
|
|
30
|
+
* })
|
|
31
|
+
* // Type: Err<never, { type: 'validation_failed', message: string, field: string, errors: string[] }>
|
|
32
|
+
*/
|
|
33
|
+
const err = (type, message, additional) => _Err({
|
|
34
|
+
...additional,
|
|
35
|
+
type,
|
|
36
|
+
message,
|
|
37
|
+
});
|
|
38
|
+
export { err };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../src/deps/jsr.io/@wentools/result/0.1.0/src/err/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { err } from './err.js';
|