effect-start 0.20.1 → 0.22.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 +1 -4
- package/dist/Cookies.js +392 -0
- package/dist/FileSystem.js +131 -0
- package/dist/Socket.js +37 -0
- package/package.json +39 -40
- package/src/Commander.ts +73 -130
- package/src/ContentNegotiation.ts +68 -100
- package/src/Cookies.ts +408 -0
- package/src/Development.ts +48 -63
- package/src/Effectify.ts +222 -206
- package/src/Entity.ts +59 -86
- package/src/FilePathPattern.ts +5 -5
- package/src/FileRouter.ts +38 -63
- package/src/FileRouterCodegen.ts +64 -56
- package/src/FileSystem.ts +390 -0
- package/src/Http.ts +17 -50
- package/src/PathPattern.ts +33 -41
- package/src/PlatformError.ts +29 -50
- package/src/PlatformRuntime.ts +39 -47
- package/src/Route.ts +68 -187
- package/src/RouteBody.ts +45 -161
- package/src/RouteHook.ts +22 -45
- package/src/RouteHttp.ts +88 -142
- package/src/RouteHttpTracer.ts +25 -26
- package/src/RouteMount.ts +100 -238
- package/src/RouteSchema.ts +67 -201
- package/src/RouteSse.ts +28 -82
- package/src/RouteTree.ts +31 -79
- package/src/RouteTrie.ts +13 -32
- package/src/SchemaExtra.ts +3 -5
- package/src/Socket.ts +51 -0
- package/src/Start.ts +20 -21
- package/src/StreamExtra.ts +93 -96
- package/src/TuplePathPattern.ts +54 -43
- package/src/Unique.ts +9 -15
- package/src/Values.ts +26 -30
- package/src/bun/BunBundle.ts +27 -73
- package/src/bun/BunImportTrackerPlugin.ts +67 -65
- package/src/bun/BunRoute.ts +12 -31
- package/src/bun/BunRuntime.ts +3 -10
- package/src/bun/BunServer.ts +50 -60
- package/src/bun/BunVirtualFilesPlugin.ts +1 -4
- package/src/bun/_BunEnhancedResolve.ts +17 -42
- package/src/bun/_empty.html +0 -1
- package/src/bundler/Bundle.ts +20 -36
- package/src/bundler/BundleFiles.ts +36 -56
- package/src/client/Overlay.ts +1 -2
- package/src/client/ScrollState.ts +5 -9
- package/src/client/index.ts +10 -13
- package/src/datastar/actions/fetch.ts +29 -48
- package/src/datastar/actions/peek.ts +1 -5
- package/src/datastar/actions/setAll.ts +2 -2
- package/src/datastar/actions/toggleAll.ts +2 -2
- package/src/datastar/attributes/attr.ts +17 -18
- package/src/datastar/attributes/bind.ts +41 -61
- package/src/datastar/attributes/class.ts +2 -5
- package/src/datastar/attributes/computed.ts +2 -10
- package/src/datastar/attributes/effect.ts +1 -2
- package/src/datastar/attributes/indicator.ts +2 -8
- package/src/datastar/attributes/init.ts +2 -10
- package/src/datastar/attributes/jsonSignals.ts +1 -6
- package/src/datastar/attributes/on.ts +4 -13
- package/src/datastar/attributes/onIntersect.ts +10 -22
- package/src/datastar/attributes/onInterval.ts +2 -10
- package/src/datastar/attributes/onSignalPatch.ts +18 -28
- package/src/datastar/attributes/ref.ts +1 -2
- package/src/datastar/attributes/show.ts +1 -2
- package/src/datastar/attributes/signals.ts +1 -5
- package/src/datastar/attributes/style.ts +6 -12
- package/src/datastar/attributes/text.ts +1 -2
- package/src/datastar/engine.ts +102 -158
- package/src/datastar/index.ts +2 -2
- package/src/datastar/utils.ts +16 -51
- package/src/datastar/watchers/patchElements.ts +35 -93
- package/src/datastar/watchers/patchSignals.ts +1 -2
- package/src/experimental/EncryptedCookies.ts +81 -175
- package/src/experimental/index.ts +0 -1
- package/src/hyper/Hyper.ts +14 -33
- package/src/hyper/HyperHtml.ts +13 -10
- package/src/hyper/HyperNode.ts +2 -7
- package/src/hyper/HyperRoute.ts +2 -5
- package/src/hyper/jsx-runtime.ts +2 -10
- package/src/hyper/jsx.d.ts +171 -440
- package/src/lint/plugin.js +276 -0
- package/src/node/NodeFileSystem.ts +140 -202
- package/src/node/NodeUtils.ts +1 -3
- package/src/testing/TestLogger.ts +9 -22
- package/src/testing/index.ts +0 -1
- package/src/testing/utils.ts +30 -31
- package/src/x/cloudflare/CloudflareTunnel.ts +53 -65
- package/src/x/datastar/Datastar.ts +3 -10
- package/src/x/datastar/index.ts +1 -3
- package/src/x/datastar/jsx-datastar.d.ts +1 -4
- package/src/x/tailwind/TailwindPlugin.ts +119 -112
- package/src/x/tailwind/compile.ts +10 -33
- package/src/x/tailwind/plugin.ts +2 -2
- package/src/HttpAppExtra.ts +0 -478
- package/src/HttpUtils.ts +0 -17
- package/src/bun/BunPlatformHttpServer.ts +0 -88
- package/src/bun/BunServerRequest.ts +0 -396
- package/src/bundler/BundleHttp.ts +0 -259
- package/src/experimental/SseHttpResponse.ts +0 -55
- package/src/middlewares/BasicAuthMiddleware.ts +0 -36
- package/src/middlewares/index.ts +0 -1
- package/src/testing/TestHttpClient.ts +0 -148
package/package.json
CHANGED
|
@@ -1,114 +1,113 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "effect-start",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"type": "module",
|
|
3
|
+
"version": "0.22.0",
|
|
5
4
|
"license": "MIT",
|
|
5
|
+
"files": [
|
|
6
|
+
"src/",
|
|
7
|
+
"!src/**/*.test.ts",
|
|
8
|
+
"!src/**/*.test.tsx",
|
|
9
|
+
"dist/",
|
|
10
|
+
"README.md",
|
|
11
|
+
"package.json"
|
|
12
|
+
],
|
|
13
|
+
"type": "module",
|
|
6
14
|
"exports": {
|
|
7
15
|
".": {
|
|
8
|
-
"bun": "./src/index.ts",
|
|
9
16
|
"types": "./dist/index.d.ts",
|
|
17
|
+
"bun": "./src/index.ts",
|
|
10
18
|
"default": "./dist/index.js"
|
|
11
19
|
},
|
|
12
20
|
"./bun": {
|
|
13
|
-
"bun": "./src/bun/index.ts",
|
|
14
21
|
"types": "./dist/bun/index.d.ts",
|
|
22
|
+
"bun": "./src/bun/index.ts",
|
|
15
23
|
"default": "./dist/bun/index.js"
|
|
16
24
|
},
|
|
17
25
|
"./client": {
|
|
18
|
-
"bun": "./src/client/index.ts",
|
|
19
26
|
"types": "./dist/client/index.d.ts",
|
|
27
|
+
"bun": "./src/client/index.ts",
|
|
20
28
|
"default": "./dist/client/index.js"
|
|
21
29
|
},
|
|
22
30
|
"./testing": {
|
|
23
|
-
"bun": "./src/testing/index.ts",
|
|
24
31
|
"types": "./dist/testing/index.d.ts",
|
|
32
|
+
"bun": "./src/testing/index.ts",
|
|
25
33
|
"default": "./dist/testing/index.js"
|
|
26
34
|
},
|
|
27
35
|
"./x/*": {
|
|
28
|
-
"bun": "./src/x/*/index.ts",
|
|
29
36
|
"types": "./dist/x/*/index.d.ts",
|
|
37
|
+
"bun": "./src/x/*/index.ts",
|
|
30
38
|
"default": "./dist/x/*/index.js"
|
|
31
39
|
},
|
|
32
40
|
"./x/tailwind/plugin": {
|
|
33
|
-
"bun": "./src/x/tailwind/plugin.ts",
|
|
34
41
|
"types": "./dist/x/tailwind/plugin.d.ts",
|
|
42
|
+
"bun": "./src/x/tailwind/plugin.ts",
|
|
35
43
|
"default": "./dist/x/tailwind/plugin.js"
|
|
36
44
|
},
|
|
37
|
-
"./middlewares": {
|
|
38
|
-
"bun": "./src/middlewares/index.ts",
|
|
39
|
-
"types": "./dist/middlewares/index.d.ts",
|
|
40
|
-
"default": "./dist/middlewares/index.js"
|
|
41
|
-
},
|
|
42
45
|
"./Unique": {
|
|
43
|
-
"bun": "./src/Unique.ts",
|
|
44
46
|
"types": "./dist/Unique.d.ts",
|
|
47
|
+
"bun": "./src/Unique.ts",
|
|
45
48
|
"default": "./dist/Unique.js"
|
|
46
49
|
},
|
|
47
50
|
"./FileRouter": {
|
|
48
|
-
"bun": "./src/FileRouter.ts",
|
|
49
51
|
"types": "./dist/FileRouter.d.ts",
|
|
52
|
+
"bun": "./src/FileRouter.ts",
|
|
50
53
|
"default": "./dist/FileRouter.js"
|
|
51
54
|
},
|
|
55
|
+
"./FileSystem": {
|
|
56
|
+
"types": "./dist/FileSystem.d.ts",
|
|
57
|
+
"bun": "./src/FileSystem.ts",
|
|
58
|
+
"default": "./dist/FileSystem.js"
|
|
59
|
+
},
|
|
52
60
|
"./experimental": {
|
|
53
|
-
"bun": "./src/experimental/index.ts",
|
|
54
61
|
"types": "./dist/experimental/index.d.ts",
|
|
62
|
+
"bun": "./src/experimental/index.ts",
|
|
55
63
|
"default": "./dist/experimental/index.js"
|
|
56
64
|
},
|
|
57
65
|
"./client/assets.d.ts": "./src/assets.d.ts",
|
|
58
66
|
"./hyper": {
|
|
59
|
-
"bun": "./src/hyper/index.ts",
|
|
60
67
|
"types": "./dist/hyper/index.d.ts",
|
|
68
|
+
"bun": "./src/hyper/index.ts",
|
|
61
69
|
"default": "./dist/hyper/index.js"
|
|
62
70
|
},
|
|
63
71
|
"./jsx-runtime": {
|
|
64
|
-
"bun": "./src/hyper/jsx-runtime.ts",
|
|
65
72
|
"types": "./dist/hyper/jsx-runtime.d.ts",
|
|
73
|
+
"bun": "./src/hyper/jsx-runtime.ts",
|
|
66
74
|
"default": "./dist/hyper/jsx-runtime.js"
|
|
67
75
|
},
|
|
68
76
|
"./jsx-dev-runtime": {
|
|
69
|
-
"bun": "./src/hyper/jsx-runtime.ts",
|
|
70
77
|
"types": "./dist/hyper/jsx-runtime.d.ts",
|
|
78
|
+
"bun": "./src/hyper/jsx-runtime.ts",
|
|
71
79
|
"default": "./dist/hyper/jsx-runtime.js"
|
|
72
80
|
},
|
|
73
81
|
"./datastar": {
|
|
74
|
-
"bun": "./src/datastar/index.ts",
|
|
75
82
|
"types": "./dist/datastar/index.d.ts",
|
|
83
|
+
"bun": "./src/datastar/index.ts",
|
|
76
84
|
"default": "./dist/datastar/index.js"
|
|
77
85
|
},
|
|
86
|
+
"./lint/plugin": "./src/lint/plugin.js",
|
|
78
87
|
"./package.json": "./package.json"
|
|
79
88
|
},
|
|
80
89
|
"scripts": {
|
|
81
90
|
"build": "bunx --bun tsc -p tsconfig.build.json",
|
|
82
|
-
"format": "bunx
|
|
91
|
+
"format": "bunx oxfmt",
|
|
92
|
+
"lint": "oxlint --import-plugin --tsconfig tsconfig.json src/",
|
|
83
93
|
"test": "bun test ./src/",
|
|
84
94
|
"deploy": "bunx --bun npm publish --access public"
|
|
85
95
|
},
|
|
86
|
-
"peerDependencies": {
|
|
87
|
-
"effect": ">=3.19.0",
|
|
88
|
-
"@effect/platform": ">=0.93.0"
|
|
89
|
-
},
|
|
90
96
|
"devDependencies": {
|
|
91
|
-
"typescript": "^5.9.3",
|
|
92
|
-
"@dprint/json": "^0.21.0",
|
|
93
|
-
"@dprint/markdown": "^0.20.0",
|
|
94
|
-
"@dprint/typescript": "^0.95.13",
|
|
95
97
|
"@effect/language-service": "^0.62.3",
|
|
96
98
|
"@types/bun": "^1.3.4",
|
|
97
99
|
"@types/react": "^19.2.7",
|
|
98
100
|
"@types/react-dom": "^19.2.3",
|
|
99
|
-
"dprint-cli": "^0.4.1",
|
|
100
|
-
"dprint-markup": "nounder/dprint-markup",
|
|
101
101
|
"effect-memfs": "^0.8.0",
|
|
102
102
|
"expect-type": "^1.3.0",
|
|
103
|
+
"oxfmt": "latest",
|
|
104
|
+
"oxlint": "^1.43.0",
|
|
103
105
|
"tailwindcss": "^4.1.18",
|
|
104
|
-
"ts-namespace-import": "nounder/ts-namespace-import#140c405"
|
|
106
|
+
"ts-namespace-import": "nounder/ts-namespace-import#140c405",
|
|
107
|
+
"typescript": "^5.9.3"
|
|
105
108
|
},
|
|
106
|
-
"
|
|
107
|
-
"
|
|
108
|
-
"
|
|
109
|
-
|
|
110
|
-
"dist/",
|
|
111
|
-
"README.md",
|
|
112
|
-
"package.json"
|
|
113
|
-
]
|
|
109
|
+
"peerDependencies": {
|
|
110
|
+
"@effect/platform": ">=0.93.0",
|
|
111
|
+
"effect": ">=3.19.0"
|
|
112
|
+
}
|
|
114
113
|
}
|
package/src/Commander.ts
CHANGED
|
@@ -15,9 +15,11 @@ type KebabToCamel<S extends string> = S extends `${infer First}-${infer Rest}`
|
|
|
15
15
|
? `${First}${KebabToCamel<Capitalize<Rest>>}`
|
|
16
16
|
: S
|
|
17
17
|
|
|
18
|
-
type StripPrefix<S extends string> = S extends `--${infer Name}`
|
|
19
|
-
|
|
20
|
-
: S
|
|
18
|
+
type StripPrefix<S extends string> = S extends `--${infer Name}`
|
|
19
|
+
? Name
|
|
20
|
+
: S extends `-${infer Name}`
|
|
21
|
+
? Name
|
|
22
|
+
: S
|
|
21
23
|
|
|
22
24
|
type OptionNameToCamelCase<S extends string> = KebabToCamel<StripPrefix<S>>
|
|
23
25
|
|
|
@@ -31,15 +33,13 @@ export interface OptionBuilder<A = any, Name extends string = string> {
|
|
|
31
33
|
readonly defaultValue?: A
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
type OptionBuilderWithSchema<A, Name extends string> =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
>
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
readonly defaultValue?: A
|
|
42
|
-
}
|
|
36
|
+
type OptionBuilderWithSchema<A, Name extends string> = Omit<
|
|
37
|
+
OptionBuilder<A, Name>,
|
|
38
|
+
"schema" | "defaultValue"
|
|
39
|
+
> & {
|
|
40
|
+
readonly schema: Schema.Schema<A, any>
|
|
41
|
+
readonly defaultValue?: A
|
|
42
|
+
}
|
|
43
43
|
|
|
44
44
|
export const option = <
|
|
45
45
|
const Long extends `--${string}`,
|
|
@@ -54,32 +54,24 @@ export const option = <
|
|
|
54
54
|
schema: Schema.Schema<A, I>,
|
|
55
55
|
): OptionBuilderWithSchema<A, Long>
|
|
56
56
|
|
|
57
|
-
description(
|
|
58
|
-
desc: string,
|
|
59
|
-
): {
|
|
57
|
+
description(desc: string): {
|
|
60
58
|
schema<A, I extends string = string>(
|
|
61
59
|
schema: Schema.Schema<A, I>,
|
|
62
60
|
): OptionBuilderWithSchema<A, Long>
|
|
63
61
|
|
|
64
|
-
default<A>(
|
|
65
|
-
value: A,
|
|
66
|
-
): {
|
|
62
|
+
default<A>(value: A): {
|
|
67
63
|
schema<A2 extends A, I extends string = string>(
|
|
68
64
|
schema: Schema.Schema<A2, I>,
|
|
69
65
|
): OptionBuilderWithSchema<A2, Long>
|
|
70
66
|
}
|
|
71
67
|
}
|
|
72
68
|
|
|
73
|
-
default<A>(
|
|
74
|
-
value: A,
|
|
75
|
-
): {
|
|
69
|
+
default<A>(value: A): {
|
|
76
70
|
schema<A2 extends A, I extends string = string>(
|
|
77
71
|
schema: Schema.Schema<A2, I>,
|
|
78
72
|
): OptionBuilderWithSchema<A2, Long>
|
|
79
73
|
|
|
80
|
-
description(
|
|
81
|
-
desc: string,
|
|
82
|
-
): {
|
|
74
|
+
description(desc: string): {
|
|
83
75
|
schema<A2 extends A, I extends string = string>(
|
|
84
76
|
schema: Schema.Schema<A2, I>,
|
|
85
77
|
): OptionBuilderWithSchema<A2, Long>
|
|
@@ -110,9 +102,7 @@ export const option = <
|
|
|
110
102
|
}),
|
|
111
103
|
|
|
112
104
|
default: <A>(value: A) => ({
|
|
113
|
-
schema: <A2 extends A, I extends string = string>(
|
|
114
|
-
schema: Schema.Schema<A2, I>,
|
|
115
|
-
) => ({
|
|
105
|
+
schema: <A2 extends A, I extends string = string>(schema: Schema.Schema<A2, I>) => ({
|
|
116
106
|
_tag: "OptionBuilder" as const,
|
|
117
107
|
name: longName,
|
|
118
108
|
long: longName,
|
|
@@ -125,9 +115,7 @@ export const option = <
|
|
|
125
115
|
}),
|
|
126
116
|
|
|
127
117
|
default: <A>(value: A) => ({
|
|
128
|
-
schema: <A2 extends A, I extends string = string>(
|
|
129
|
-
schema: Schema.Schema<A2, I>,
|
|
130
|
-
) => ({
|
|
118
|
+
schema: <A2 extends A, I extends string = string>(schema: Schema.Schema<A2, I>) => ({
|
|
131
119
|
_tag: "OptionBuilder" as const,
|
|
132
120
|
name: longName,
|
|
133
121
|
long: longName,
|
|
@@ -138,9 +126,7 @@ export const option = <
|
|
|
138
126
|
}),
|
|
139
127
|
|
|
140
128
|
description: (desc) => ({
|
|
141
|
-
schema: <A2 extends A, I extends string = string>(
|
|
142
|
-
schema: Schema.Schema<A2, I>,
|
|
143
|
-
) => ({
|
|
129
|
+
schema: <A2 extends A, I extends string = string>(schema: Schema.Schema<A2, I>) => ({
|
|
144
130
|
_tag: "OptionBuilder" as const,
|
|
145
131
|
name: longName,
|
|
146
132
|
long: longName,
|
|
@@ -157,15 +143,12 @@ export const option = <
|
|
|
157
143
|
export type OptionsMap = Record<string, OptionBuilder<any, any>>
|
|
158
144
|
|
|
159
145
|
type ExtractOptionsFromBuilders<Opts extends OptionsMap> = {
|
|
160
|
-
[
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
: never
|
|
164
|
-
]: Opts[K] extends OptionBuilder<infer A, any> ? A : never
|
|
146
|
+
[K in keyof Opts as Opts[K] extends OptionBuilder<any, infer Name>
|
|
147
|
+
? OptionNameToCamelCase<Name>
|
|
148
|
+
: never]: Opts[K] extends OptionBuilder<infer A, any> ? A : never
|
|
165
149
|
}
|
|
166
150
|
|
|
167
|
-
export type ExtractOptionValues<Opts extends OptionsMap> =
|
|
168
|
-
ExtractOptionsFromBuilders<Opts>
|
|
151
|
+
export type ExtractOptionValues<Opts extends OptionsMap> = ExtractOptionsFromBuilders<Opts>
|
|
169
152
|
|
|
170
153
|
export interface SubcommandDef<Handled extends boolean = boolean> {
|
|
171
154
|
readonly _tag: "SubcommandDef"
|
|
@@ -177,13 +160,10 @@ type Extend<
|
|
|
177
160
|
NewOpts extends OptionsMap,
|
|
178
161
|
NewSubs extends ReadonlyArray<SubcommandDef> = [],
|
|
179
162
|
Handled extends boolean = false,
|
|
180
|
-
> =
|
|
181
|
-
|
|
182
|
-
& NewOpts,
|
|
183
|
-
|
|
184
|
-
Handled
|
|
185
|
-
>
|
|
186
|
-
: CommanderSet<NewOpts, NewSubs, Handled>
|
|
163
|
+
> =
|
|
164
|
+
S extends CommanderSet<infer Opts, infer Subs, infer _H>
|
|
165
|
+
? CommanderSet<Opts & NewOpts, [...Subs, ...NewSubs], Handled>
|
|
166
|
+
: CommanderSet<NewOpts, NewSubs, Handled>
|
|
187
167
|
|
|
188
168
|
type CommanderBuilder = {
|
|
189
169
|
option: typeof optionMethod
|
|
@@ -197,13 +177,10 @@ export type CommanderSet<
|
|
|
197
177
|
Opts extends OptionsMap = {},
|
|
198
178
|
Subcommands extends ReadonlyArray<SubcommandDef> = [],
|
|
199
179
|
Handled extends boolean = false,
|
|
200
|
-
> =
|
|
201
|
-
&
|
|
202
|
-
& CommanderSet.Instance<Opts, Subcommands, Handled>
|
|
203
|
-
& {
|
|
180
|
+
> = Pipeable.Pipeable &
|
|
181
|
+
CommanderSet.Instance<Opts, Subcommands, Handled> & {
|
|
204
182
|
[TypeId]: typeof TypeId
|
|
205
|
-
}
|
|
206
|
-
& CommanderBuilder
|
|
183
|
+
} & CommanderBuilder
|
|
207
184
|
|
|
208
185
|
export namespace CommanderSet {
|
|
209
186
|
export type Instance<
|
|
@@ -229,16 +206,11 @@ export namespace CommanderSet {
|
|
|
229
206
|
} & CommanderBuilder
|
|
230
207
|
}
|
|
231
208
|
|
|
232
|
-
const optionMethod = function<
|
|
233
|
-
S,
|
|
234
|
-
Opt extends OptionBuilder<any, any>,
|
|
235
|
-
>(
|
|
209
|
+
const optionMethod = function <S, Opt extends OptionBuilder<any, any>>(
|
|
236
210
|
this: S,
|
|
237
211
|
opt: Opt,
|
|
238
212
|
): Extend<S, { [K in Opt["name"] as OptionNameToCamelCase<K>]: Opt }> {
|
|
239
|
-
const base = (this && typeof this === "object" ? this : {}) as Partial<
|
|
240
|
-
CommanderSet.Instance
|
|
241
|
-
>
|
|
213
|
+
const base = (this && typeof this === "object" ? this : {}) as Partial<CommanderSet.Instance>
|
|
242
214
|
const baseName = base.name ?? ""
|
|
243
215
|
const baseOptions: OptionsMap = base.options ?? {}
|
|
244
216
|
const baseSubcommands = base.subcommands ?? []
|
|
@@ -256,12 +228,10 @@ const optionMethod = function<
|
|
|
256
228
|
}) as Extend<S, { [K in Opt["name"] as OptionNameToCamelCase<K>]: Opt }>
|
|
257
229
|
}
|
|
258
230
|
|
|
259
|
-
export const optionHelp = function<S>(
|
|
231
|
+
export const optionHelp = function <S>(
|
|
260
232
|
this: S,
|
|
261
|
-
): Extend<S, {
|
|
262
|
-
const base = (this && typeof this === "object" ? this : {}) as Partial<
|
|
263
|
-
CommanderSet.Instance
|
|
264
|
-
>
|
|
233
|
+
): Extend<S, { help: OptionBuilder<boolean, "--help"> }> {
|
|
234
|
+
const base = (this && typeof this === "object" ? this : {}) as Partial<CommanderSet.Instance>
|
|
265
235
|
const baseName = base.name ?? ""
|
|
266
236
|
const baseOptions: OptionsMap = base.options ?? {}
|
|
267
237
|
const baseSubcommands = base.subcommands ?? []
|
|
@@ -283,15 +253,13 @@ export const optionHelp = function<S>(
|
|
|
283
253
|
version: baseVersion,
|
|
284
254
|
options: { ...baseOptions, help: helpOption },
|
|
285
255
|
subcommands: baseSubcommands,
|
|
286
|
-
}) as Extend<S, {
|
|
256
|
+
}) as Extend<S, { help: OptionBuilder<boolean, "--help"> }>
|
|
287
257
|
}
|
|
288
258
|
|
|
289
|
-
export const optionVersion = function<S>(
|
|
259
|
+
export const optionVersion = function <S>(
|
|
290
260
|
this: S,
|
|
291
|
-
): Extend<S, {
|
|
292
|
-
const base = (this && typeof this === "object" ? this : {}) as Partial<
|
|
293
|
-
CommanderSet.Instance
|
|
294
|
-
>
|
|
261
|
+
): Extend<S, { version: OptionBuilder<boolean, "--version"> }> {
|
|
262
|
+
const base = (this && typeof this === "object" ? this : {}) as Partial<CommanderSet.Instance>
|
|
295
263
|
const baseName = base.name ?? ""
|
|
296
264
|
const baseOptions: OptionsMap = base.options ?? {}
|
|
297
265
|
const baseSubcommands = base.subcommands ?? []
|
|
@@ -313,10 +281,10 @@ export const optionVersion = function<S>(
|
|
|
313
281
|
version: baseVersion,
|
|
314
282
|
options: { ...baseOptions, version: versionOption },
|
|
315
283
|
subcommands: baseSubcommands,
|
|
316
|
-
}) as Extend<S, {
|
|
284
|
+
}) as Extend<S, { version: OptionBuilder<boolean, "--version"> }>
|
|
317
285
|
}
|
|
318
286
|
|
|
319
|
-
export const subcommand = function<
|
|
287
|
+
export const subcommand = function <
|
|
320
288
|
S,
|
|
321
289
|
SubOpts extends OptionsMap,
|
|
322
290
|
SubSubs extends ReadonlyArray<SubcommandDef>,
|
|
@@ -325,9 +293,7 @@ export const subcommand = function<
|
|
|
325
293
|
this: S,
|
|
326
294
|
cmd: CommanderSet<SubOpts, SubSubs, SubHandled>,
|
|
327
295
|
): Extend<S, {}, [SubcommandDef<SubHandled>]> {
|
|
328
|
-
const base = (this && typeof this === "object" ? this : {}) as Partial<
|
|
329
|
-
CommanderSet.Instance
|
|
330
|
-
>
|
|
296
|
+
const base = (this && typeof this === "object" ? this : {}) as Partial<CommanderSet.Instance>
|
|
331
297
|
const baseName = base.name ?? ""
|
|
332
298
|
const baseOptions = base.options ?? {}
|
|
333
299
|
const baseSubcommands = base.subcommands ?? []
|
|
@@ -348,10 +314,7 @@ export const subcommand = function<
|
|
|
348
314
|
}) as Extend<S, {}, [SubcommandDef<SubHandled>]>
|
|
349
315
|
}
|
|
350
316
|
|
|
351
|
-
export const handle = function<
|
|
352
|
-
Opts extends OptionsMap,
|
|
353
|
-
Subs extends ReadonlyArray<SubcommandDef>,
|
|
354
|
-
>(
|
|
317
|
+
export const handle = function <Opts extends OptionsMap, Subs extends ReadonlyArray<SubcommandDef>>(
|
|
355
318
|
this: CommanderSet<Opts, Subs, false>,
|
|
356
319
|
handler: (args: ExtractOptionValues<Opts>) => Effect.Effect<void>,
|
|
357
320
|
): CommanderSet<Opts, Subs, true> {
|
|
@@ -406,15 +369,10 @@ function makeSet<
|
|
|
406
369
|
readonly subcommands: Subs
|
|
407
370
|
readonly handler?: (args: ExtractOptionValues<Opts>) => Effect.Effect<void>
|
|
408
371
|
}): CommanderSet<Opts, Subs, Handled> {
|
|
409
|
-
return Object.assign(
|
|
410
|
-
Object.create(CommanderProto),
|
|
411
|
-
config,
|
|
412
|
-
) as CommanderSet<Opts, Subs, Handled>
|
|
372
|
+
return Object.assign(Object.create(CommanderProto), config) as CommanderSet<Opts, Subs, Handled>
|
|
413
373
|
}
|
|
414
374
|
|
|
415
|
-
export function isCommanderSet(
|
|
416
|
-
input: unknown,
|
|
417
|
-
): input is CommanderSet<any, any, any> {
|
|
375
|
+
export function isCommanderSet(input: unknown): input is CommanderSet<any, any, any> {
|
|
418
376
|
return Predicate.hasProperty(input, TypeId)
|
|
419
377
|
}
|
|
420
378
|
|
|
@@ -434,10 +392,8 @@ interface ParsedArgs {
|
|
|
434
392
|
readonly positional: ReadonlyArray<string>
|
|
435
393
|
}
|
|
436
394
|
|
|
437
|
-
const parseRawArgs = (
|
|
438
|
-
|
|
439
|
-
): Effect.Effect<ParsedArgs, CommanderError> =>
|
|
440
|
-
Effect.gen(function*() {
|
|
395
|
+
const parseRawArgs = (args: ReadonlyArray<string>): Effect.Effect<ParsedArgs, CommanderError> =>
|
|
396
|
+
Effect.gen(function* () {
|
|
441
397
|
const flags: Record<string, boolean> = {}
|
|
442
398
|
const options: Record<string, string> = {}
|
|
443
399
|
const positional: Array<string> = []
|
|
@@ -470,10 +426,7 @@ const parseRawArgs = (
|
|
|
470
426
|
const chars = arg.slice(1)
|
|
471
427
|
for (let j = 0; j < chars.length; j++) {
|
|
472
428
|
const char = chars[j]!
|
|
473
|
-
if (
|
|
474
|
-
j === chars.length - 1 && i + 1 < args.length && !args[i + 1]!
|
|
475
|
-
.startsWith("-")
|
|
476
|
-
) {
|
|
429
|
+
if (j === chars.length - 1 && i + 1 < args.length && !args[i + 1]!.startsWith("-")) {
|
|
477
430
|
options[char] = args[i + 1]!
|
|
478
431
|
i++
|
|
479
432
|
} else {
|
|
@@ -498,7 +451,7 @@ export const parse = <
|
|
|
498
451
|
cmd: CommanderSet<Opts, Subs, Handled>,
|
|
499
452
|
args: ReadonlyArray<string>,
|
|
500
453
|
): Effect.Effect<ExtractOptionValues<Opts>, CommanderError> =>
|
|
501
|
-
Effect.gen(function*() {
|
|
454
|
+
Effect.gen(function* () {
|
|
502
455
|
const parsed = yield* parseRawArgs(args)
|
|
503
456
|
|
|
504
457
|
const result: Record<string, any> = {}
|
|
@@ -509,7 +462,7 @@ export const parse = <
|
|
|
509
462
|
|
|
510
463
|
const longMatch = parsed.options[longName] || parsed.flags[longName]
|
|
511
464
|
const shortMatch = shortName
|
|
512
|
-
?
|
|
465
|
+
? parsed.options[shortName] || parsed.flags[shortName]
|
|
513
466
|
: undefined
|
|
514
467
|
|
|
515
468
|
const rawValue = longMatch ?? shortMatch
|
|
@@ -520,18 +473,15 @@ export const parse = <
|
|
|
520
473
|
if (typeof rawValue === "boolean") {
|
|
521
474
|
result[camelKey] = rawValue
|
|
522
475
|
} else if (optBuilder.schema) {
|
|
523
|
-
const decoded = yield* Schema
|
|
524
|
-
.
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
}),
|
|
533
|
-
),
|
|
534
|
-
)
|
|
476
|
+
const decoded = yield* Schema.decode(optBuilder.schema)(rawValue).pipe(
|
|
477
|
+
Effect.mapError(
|
|
478
|
+
(error) =>
|
|
479
|
+
new CommanderError({
|
|
480
|
+
message: `Invalid value for option ${optBuilder.long}: ${error.message}`,
|
|
481
|
+
cause: error,
|
|
482
|
+
}),
|
|
483
|
+
),
|
|
484
|
+
)
|
|
535
485
|
result[camelKey] = decoded
|
|
536
486
|
} else {
|
|
537
487
|
result[camelKey] = rawValue
|
|
@@ -544,13 +494,10 @@ export const parse = <
|
|
|
544
494
|
return result as ExtractOptionValues<Opts>
|
|
545
495
|
})
|
|
546
496
|
|
|
547
|
-
export const runMain = <
|
|
548
|
-
Opts extends OptionsMap,
|
|
549
|
-
Subs extends ReadonlyArray<SubcommandDef>,
|
|
550
|
-
>(
|
|
497
|
+
export const runMain = <Opts extends OptionsMap, Subs extends ReadonlyArray<SubcommandDef>>(
|
|
551
498
|
cmd: CommanderSet<Opts, Subs, true>,
|
|
552
499
|
): Effect.Effect<void, CommanderError> =>
|
|
553
|
-
Effect.gen(function*() {
|
|
500
|
+
Effect.gen(function* () {
|
|
554
501
|
const args = typeof process !== "undefined" ? process.argv.slice(2) : []
|
|
555
502
|
|
|
556
503
|
const parsedOptions = yield* parse(cmd, args)
|
|
@@ -560,11 +507,7 @@ export const runMain = <
|
|
|
560
507
|
return
|
|
561
508
|
}
|
|
562
509
|
|
|
563
|
-
if (
|
|
564
|
-
Predicate.hasProperty(parsedOptions, "version")
|
|
565
|
-
&& parsedOptions.version
|
|
566
|
-
&& cmd.version
|
|
567
|
-
) {
|
|
510
|
+
if (Predicate.hasProperty(parsedOptions, "version") && parsedOptions.version && cmd.version) {
|
|
568
511
|
console.log(`${cmd.name} v${cmd.version}`)
|
|
569
512
|
return
|
|
570
513
|
}
|
|
@@ -578,7 +521,9 @@ const generateHelp = <
|
|
|
578
521
|
Opts extends OptionsMap,
|
|
579
522
|
Subs extends ReadonlyArray<SubcommandDef>,
|
|
580
523
|
Handled extends boolean,
|
|
581
|
-
>(
|
|
524
|
+
>(
|
|
525
|
+
cmd: CommanderSet<Opts, Subs, Handled>,
|
|
526
|
+
): string => {
|
|
582
527
|
const lines: Array<string> = []
|
|
583
528
|
|
|
584
529
|
if (cmd.description) {
|
|
@@ -620,7 +565,9 @@ export const help = <
|
|
|
620
565
|
Opts extends OptionsMap,
|
|
621
566
|
Subs extends ReadonlyArray<SubcommandDef>,
|
|
622
567
|
Handled extends boolean,
|
|
623
|
-
>(
|
|
568
|
+
>(
|
|
569
|
+
cmd: CommanderSet<Opts, Subs, Handled>,
|
|
570
|
+
): string => generateHelp(cmd)
|
|
624
571
|
|
|
625
572
|
export const NumberFromString = Schema.NumberFromString
|
|
626
573
|
|
|
@@ -631,12 +578,8 @@ export const choice = <const Choices extends ReadonlyArray<string>>(
|
|
|
631
578
|
export const repeatable = <A>(
|
|
632
579
|
schema: Schema.Schema<A, string>,
|
|
633
580
|
): Schema.Schema<ReadonlyArray<A>, string> =>
|
|
634
|
-
Schema
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
})
|
|
640
|
-
.pipe(
|
|
641
|
-
Schema.compose(Schema.Array(schema)),
|
|
642
|
-
)
|
|
581
|
+
Schema.transform(Schema.String, Schema.Array(Schema.String), {
|
|
582
|
+
strict: true,
|
|
583
|
+
decode: (s) => s.split(",").map((part) => part.trim()),
|
|
584
|
+
encode: (arr) => arr.join(","),
|
|
585
|
+
}).pipe(Schema.compose(Schema.Array(schema)))
|