effect 4.0.0-beta.97 → 4.0.0-beta.99
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 -3
- package/dist/Array.js +1 -1
- package/dist/Array.js.map +1 -1
- package/dist/Graph.d.ts +1187 -196
- package/dist/Graph.d.ts.map +1 -1
- package/dist/Graph.js +1031 -283
- package/dist/Graph.js.map +1 -1
- package/dist/Iterable.d.ts.map +1 -1
- package/dist/Iterable.js +41 -1
- package/dist/Iterable.js.map +1 -1
- package/dist/LayerRef.d.ts +4 -6
- package/dist/LayerRef.d.ts.map +1 -1
- package/dist/LayerRef.js +4 -6
- package/dist/LayerRef.js.map +1 -1
- package/dist/Number.d.ts.map +1 -1
- package/dist/Number.js +28 -10
- package/dist/Number.js.map +1 -1
- package/dist/Schema.d.ts +22 -22
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +37 -34
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +25 -10
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaError.d.ts +53 -0
- package/dist/SchemaError.d.ts.map +1 -0
- package/dist/SchemaError.js +61 -0
- package/dist/SchemaError.js.map +1 -0
- package/dist/SchemaGetter.d.ts.map +1 -1
- package/dist/SchemaGetter.js +17 -12
- package/dist/SchemaGetter.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +186 -224
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/effect.js +35 -11
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/schema/equivalence.js +1 -2
- package/dist/internal/schema/equivalence.js.map +1 -1
- package/dist/internal/schema/representation.js +1 -3
- package/dist/internal/schema/representation.js.map +1 -1
- package/dist/internal/schema/schema.d.ts +0 -13
- package/dist/internal/schema/schema.d.ts.map +1 -1
- package/dist/internal/schema/schema.js +4 -29
- package/dist/internal/schema/schema.js.map +1 -1
- package/dist/unstable/ai/Tool.d.ts.map +1 -1
- package/dist/unstable/ai/Tool.js +11 -13
- package/dist/unstable/ai/Tool.js.map +1 -1
- package/dist/unstable/cli/CliConfig.d.ts +76 -0
- package/dist/unstable/cli/CliConfig.d.ts.map +1 -0
- package/dist/unstable/cli/CliConfig.js +63 -0
- package/dist/unstable/cli/CliConfig.js.map +1 -0
- package/dist/unstable/cli/CliError.d.ts +8 -16
- package/dist/unstable/cli/CliError.d.ts.map +1 -1
- package/dist/unstable/cli/CliError.js +11 -16
- package/dist/unstable/cli/CliError.js.map +1 -1
- package/dist/unstable/cli/Command.d.ts +40 -4
- package/dist/unstable/cli/Command.d.ts.map +1 -1
- package/dist/unstable/cli/Command.js +63 -6
- package/dist/unstable/cli/Command.js.map +1 -1
- package/dist/unstable/cli/GlobalFlag.d.ts +24 -5
- package/dist/unstable/cli/GlobalFlag.d.ts.map +1 -1
- package/dist/unstable/cli/GlobalFlag.js +26 -10
- package/dist/unstable/cli/GlobalFlag.js.map +1 -1
- package/dist/unstable/cli/Param.js +6 -2
- package/dist/unstable/cli/Param.js.map +1 -1
- package/dist/unstable/cli/index.d.ts +4 -0
- package/dist/unstable/cli/index.d.ts.map +1 -1
- package/dist/unstable/cli/index.js +4 -0
- package/dist/unstable/cli/index.js.map +1 -1
- package/dist/unstable/cli/internal/ansi.d.ts.map +1 -1
- package/dist/unstable/cli/internal/ansi.js +2 -0
- package/dist/unstable/cli/internal/ansi.js.map +1 -1
- package/dist/unstable/cli/internal/parser.js +11 -2
- package/dist/unstable/cli/internal/parser.js.map +1 -1
- package/dist/unstable/cli/internal/wizard.d.ts +13 -0
- package/dist/unstable/cli/internal/wizard.d.ts.map +1 -0
- package/dist/unstable/cli/internal/wizard.js +212 -0
- package/dist/unstable/cli/internal/wizard.js.map +1 -0
- package/dist/unstable/cluster/EntityProxyServer.d.ts +1 -1
- package/dist/unstable/cluster/EntityProxyServer.d.ts.map +1 -1
- package/dist/unstable/cluster/EntityProxyServer.js +2 -4
- package/dist/unstable/cluster/EntityProxyServer.js.map +1 -1
- package/dist/unstable/cluster/RunnerStorage.js +1 -1
- package/dist/unstable/cluster/RunnerStorage.js.map +1 -1
- package/dist/unstable/cluster/internal/entityManager.js +15 -12
- package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
- package/dist/unstable/http/Multipart.d.ts.map +1 -1
- package/dist/unstable/http/Multipart.js +3 -1
- package/dist/unstable/http/Multipart.js.map +1 -1
- package/dist/unstable/httpapi/HttpApi.d.ts +36 -15
- package/dist/unstable/httpapi/HttpApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApi.js +19 -20
- package/dist/unstable/httpapi/HttpApi.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts +51 -62
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js +68 -58
- package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.d.ts +53 -53
- package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.js +40 -30
- package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +165 -164
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.js +31 -19
- package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.d.ts +22 -0
- package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.js +31 -0
- package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.d.ts +55 -30
- package/dist/unstable/httpapi/HttpApiGroup.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.js +22 -29
- package/dist/unstable/httpapi/HttpApiGroup.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +8 -8
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiScalar.d.ts +2 -2
- package/dist/unstable/httpapi/HttpApiScalar.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiScalar.js +4 -3
- package/dist/unstable/httpapi/HttpApiScalar.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.d.ts +8 -0
- package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiSwagger.d.ts +1 -1
- package/dist/unstable/httpapi/HttpApiSwagger.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiSwagger.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiTest.d.ts +4 -4
- package/dist/unstable/httpapi/HttpApiTest.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiTest.js +9 -8
- package/dist/unstable/httpapi/HttpApiTest.js.map +1 -1
- package/dist/unstable/httpapi/OpenApi.d.ts +1 -1
- package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/OpenApi.js +77 -37
- package/dist/unstable/httpapi/OpenApi.js.map +1 -1
- package/dist/unstable/httpapi/internal/html.js +6 -2
- package/dist/unstable/httpapi/internal/html.js.map +1 -1
- package/dist/unstable/httpapi/internal/mediaType.d.ts +2 -0
- package/dist/unstable/httpapi/internal/mediaType.d.ts.map +1 -0
- package/dist/unstable/httpapi/internal/mediaType.js +7 -0
- package/dist/unstable/httpapi/internal/mediaType.js.map +1 -0
- package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
- package/dist/unstable/persistence/PersistedQueue.js +16 -12
- package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
- package/dist/unstable/persistence/Redis.d.ts.map +1 -1
- package/dist/unstable/persistence/Redis.js +5 -3
- package/dist/unstable/persistence/Redis.js.map +1 -1
- package/dist/unstable/reactivity/Atom.js +1 -1
- package/dist/unstable/reactivity/Atom.js.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.d.ts +7 -7
- package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.js +3 -2
- package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
- package/dist/unstable/rpc/RpcServer.d.ts +3 -1
- package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcServer.js +6 -3
- package/dist/unstable/rpc/RpcServer.js.map +1 -1
- package/dist/unstable/sql/SqlClient.d.ts +1 -2
- package/dist/unstable/sql/SqlClient.d.ts.map +1 -1
- package/dist/unstable/sql/SqlClient.js.map +1 -1
- package/dist/unstable/workflow/DurableDeferred.js +1 -1
- package/dist/unstable/workflow/DurableDeferred.js.map +1 -1
- package/dist/unstable/workflow/WorkflowProxyServer.d.ts +1 -1
- package/dist/unstable/workflow/WorkflowProxyServer.d.ts.map +1 -1
- package/dist/unstable/workflow/WorkflowProxyServer.js +1 -2
- package/dist/unstable/workflow/WorkflowProxyServer.js.map +1 -1
- package/package.json +3 -3
- package/src/Array.ts +1 -1
- package/src/Graph.ts +2967 -457
- package/src/Iterable.ts +32 -2
- package/src/LayerRef.ts +4 -6
- package/src/Number.ts +29 -10
- package/src/Schema.ts +43 -35
- package/src/SchemaAST.ts +25 -13
- package/src/SchemaError.ts +64 -0
- package/src/SchemaGetter.ts +22 -16
- package/src/SchemaRepresentation.ts +165 -202
- package/src/index.ts +10 -0
- package/src/internal/effect.ts +48 -25
- package/src/internal/schema/equivalence.ts +1 -2
- package/src/internal/schema/representation.ts +4 -4
- package/src/internal/schema/schema.ts +4 -37
- package/src/unstable/ai/Tool.ts +13 -16
- package/src/unstable/cli/CliConfig.ts +85 -0
- package/src/unstable/cli/CliError.ts +27 -16
- package/src/unstable/cli/Command.ts +90 -14
- package/src/unstable/cli/GlobalFlag.ts +46 -29
- package/src/unstable/cli/Param.ts +15 -3
- package/src/unstable/cli/index.ts +5 -0
- package/src/unstable/cli/internal/ansi.ts +3 -0
- package/src/unstable/cli/internal/parser.ts +14 -2
- package/src/unstable/cli/internal/wizard.ts +283 -0
- package/src/unstable/cluster/EntityProxyServer.ts +15 -17
- package/src/unstable/cluster/RunnerStorage.ts +1 -1
- package/src/unstable/cluster/internal/entityManager.ts +48 -34
- package/src/unstable/http/Multipart.ts +3 -1
- package/src/unstable/httpapi/HttpApi.ts +72 -47
- package/src/unstable/httpapi/HttpApiBuilder.ts +320 -217
- package/src/unstable/httpapi/HttpApiClient.ts +196 -151
- package/src/unstable/httpapi/HttpApiEndpoint.ts +251 -447
- package/src/unstable/httpapi/HttpApiError.ts +33 -0
- package/src/unstable/httpapi/HttpApiGroup.ts +95 -74
- package/src/unstable/httpapi/HttpApiMiddleware.ts +10 -7
- package/src/unstable/httpapi/HttpApiScalar.ts +15 -12
- package/src/unstable/httpapi/HttpApiSchema.ts +8 -0
- package/src/unstable/httpapi/HttpApiSwagger.ts +2 -2
- package/src/unstable/httpapi/HttpApiTest.ts +15 -14
- package/src/unstable/httpapi/OpenApi.ts +74 -36
- package/src/unstable/httpapi/internal/html.ts +9 -2
- package/src/unstable/httpapi/internal/mediaType.ts +6 -0
- package/src/unstable/persistence/PersistedQueue.ts +16 -14
- package/src/unstable/persistence/Redis.ts +9 -4
- package/src/unstable/reactivity/Atom.ts +1 -1
- package/src/unstable/reactivity/AtomHttpApi.ts +164 -162
- package/src/unstable/rpc/RpcServer.ts +10 -4
- package/src/unstable/sql/SqlClient.ts +1 -2
- package/src/unstable/workflow/DurableDeferred.ts +1 -1
- package/src/unstable/workflow/WorkflowProxyServer.ts +11 -12
|
@@ -2898,9 +2898,19 @@ export const getUnderlyingSingleOrThrow = <Kind extends ParamKind, A>(
|
|
|
2898
2898
|
*/
|
|
2899
2899
|
export const getParamMetadata = <Kind extends ParamKind, A>(
|
|
2900
2900
|
param: Param<Kind, A>
|
|
2901
|
-
): {
|
|
2901
|
+
): {
|
|
2902
|
+
readonly isOptional: boolean
|
|
2903
|
+
readonly isVariadic: boolean
|
|
2904
|
+
readonly variadicMin: Option.Option<number>
|
|
2905
|
+
readonly variadicMax: Option.Option<number>
|
|
2906
|
+
} => {
|
|
2902
2907
|
return matchParam(param, {
|
|
2903
|
-
Single: () => ({
|
|
2908
|
+
Single: () => ({
|
|
2909
|
+
isOptional: false,
|
|
2910
|
+
isVariadic: false,
|
|
2911
|
+
variadicMin: Option.none(),
|
|
2912
|
+
variadicMax: Option.none()
|
|
2913
|
+
}),
|
|
2904
2914
|
Map: (mapped) => getParamMetadata(mapped.param),
|
|
2905
2915
|
Transform: (mapped) => getParamMetadata(mapped.param),
|
|
2906
2916
|
Optional: (optional) => ({
|
|
@@ -2909,7 +2919,9 @@ export const getParamMetadata = <Kind extends ParamKind, A>(
|
|
|
2909
2919
|
}),
|
|
2910
2920
|
Variadic: (variadic) => ({
|
|
2911
2921
|
...getParamMetadata(variadic.param),
|
|
2912
|
-
isVariadic: true
|
|
2922
|
+
isVariadic: true,
|
|
2923
|
+
variadicMin: variadic.min,
|
|
2924
|
+
variadicMax: variadic.max
|
|
2913
2925
|
})
|
|
2914
2926
|
})
|
|
2915
2927
|
}
|
|
@@ -391,6 +391,18 @@ const invalidNegatedFlagValue = (
|
|
|
391
391
|
kind: "flag"
|
|
392
392
|
})
|
|
393
393
|
|
|
394
|
+
const missingFlagValue = (spec: FlagParam): CliError.InvalidValue => {
|
|
395
|
+
const choices = Primitive.getChoiceKeys(spec.primitiveType)
|
|
396
|
+
return new CliError.InvalidValue({
|
|
397
|
+
option: spec.name,
|
|
398
|
+
value: "",
|
|
399
|
+
expected: choices === undefined
|
|
400
|
+
? spec.typeName ?? Primitive.getTypeName(spec.primitiveType)
|
|
401
|
+
: choices.join(" | "),
|
|
402
|
+
kind: "flag"
|
|
403
|
+
})
|
|
404
|
+
}
|
|
405
|
+
|
|
394
406
|
/**
|
|
395
407
|
* Checks whether a token is a boolean literal value.
|
|
396
408
|
* Recognizes: true/false, yes/no, on/off, 1/0
|
|
@@ -497,8 +509,8 @@ const consumeFlagValueWithTokens = (
|
|
|
497
509
|
}
|
|
498
510
|
|
|
499
511
|
return {
|
|
500
|
-
_tag: "
|
|
501
|
-
|
|
512
|
+
_tag: "Error",
|
|
513
|
+
error: missingFlagValue(spec),
|
|
502
514
|
tokens: []
|
|
503
515
|
}
|
|
504
516
|
}
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import * as Console from "../../../Console.ts"
|
|
2
|
+
import * as Effect from "../../../Effect.ts"
|
|
3
|
+
import * as Option from "../../../Option.ts"
|
|
4
|
+
import * as Redacted from "../../../Redacted.ts"
|
|
5
|
+
import type * as Terminal from "../../../Terminal.ts"
|
|
6
|
+
import type * as CliError from "../CliError.ts"
|
|
7
|
+
import type * as Command from "../Command.ts"
|
|
8
|
+
import * as Param from "../Param.ts"
|
|
9
|
+
import * as Primitive from "../Primitive.ts"
|
|
10
|
+
import * as Prompt from "../Prompt.ts"
|
|
11
|
+
import * as Ansi from "./ansi.ts"
|
|
12
|
+
import { toImpl } from "./command.ts"
|
|
13
|
+
|
|
14
|
+
export interface Options {
|
|
15
|
+
readonly commandPath?: ReadonlyArray<string> | undefined
|
|
16
|
+
readonly prefix?: ReadonlyArray<string> | undefined
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const run: (
|
|
20
|
+
command: Command.Command.Any,
|
|
21
|
+
options?: Options
|
|
22
|
+
) => Effect.Effect<Array<string>, CliError.CliError | Terminal.QuitError, Command.Environment> = Effect.fnUntraced(
|
|
23
|
+
function*(command, options) {
|
|
24
|
+
const commandPath = options?.commandPath ?? [command.name]
|
|
25
|
+
const selected = getCommandAtPath(command, commandPath)
|
|
26
|
+
const commandLine = [...(options?.prefix ?? commandPath)]
|
|
27
|
+
yield* logCurrentCommand(commandLine)
|
|
28
|
+
yield* promptCommand(selected, commandLine, selected === command ? "ROOT" : selected.name)
|
|
29
|
+
return commandLine
|
|
30
|
+
}
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
const getCommandAtPath = (
|
|
34
|
+
command: Command.Command.Any,
|
|
35
|
+
commandPath: ReadonlyArray<string>
|
|
36
|
+
): Command.Command.Any => {
|
|
37
|
+
let current = command
|
|
38
|
+
for (const name of commandPath.slice(1)) {
|
|
39
|
+
const child = current.subcommands
|
|
40
|
+
.flatMap((group) => group.commands)
|
|
41
|
+
.find((candidate) => candidate.name === name || candidate.alias === name)
|
|
42
|
+
if (child === undefined) {
|
|
43
|
+
break
|
|
44
|
+
}
|
|
45
|
+
current = child
|
|
46
|
+
}
|
|
47
|
+
return current
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const promptCommand: (
|
|
51
|
+
command: Command.Command.Any,
|
|
52
|
+
commandLine: Array<string>,
|
|
53
|
+
sectionName: string
|
|
54
|
+
) => Effect.Effect<void, CliError.CliError | Terminal.QuitError, Command.Environment> = Effect.fnUntraced(
|
|
55
|
+
function*(command, commandLine, sectionName) {
|
|
56
|
+
const impl = toImpl(command)
|
|
57
|
+
const visibleSubcommands = command.subcommands.flatMap((group) => group.commands.filter((child) => !child.hidden))
|
|
58
|
+
const config = visibleSubcommands.length === 0 ? impl.config : impl.contextConfig
|
|
59
|
+
|
|
60
|
+
if (config.flags.length > 0) {
|
|
61
|
+
yield* Console.log(renderSection(sectionName, "FLAGS"))
|
|
62
|
+
for (const param of config.flags) {
|
|
63
|
+
commandLine.push(...yield* promptParam(param))
|
|
64
|
+
}
|
|
65
|
+
if (config.arguments.length > 0 || visibleSubcommands.length > 0) {
|
|
66
|
+
yield* logCurrentCommand(commandLine)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (config.arguments.length > 0) {
|
|
71
|
+
yield* Console.log(renderSection(sectionName, "ARGUMENTS"))
|
|
72
|
+
for (const param of config.arguments) {
|
|
73
|
+
commandLine.push(...yield* promptParam(param))
|
|
74
|
+
}
|
|
75
|
+
if (visibleSubcommands.length > 0) {
|
|
76
|
+
yield* logCurrentCommand(commandLine)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (visibleSubcommands.length === 0) {
|
|
81
|
+
return
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const child = yield* Prompt.run(Prompt.select({
|
|
85
|
+
message: "Command",
|
|
86
|
+
choices: visibleSubcommands.map((command) => ({
|
|
87
|
+
title: command.name,
|
|
88
|
+
value: command,
|
|
89
|
+
...(command.shortDescription !== undefined
|
|
90
|
+
? { description: command.shortDescription }
|
|
91
|
+
: command.description !== undefined
|
|
92
|
+
? { description: command.description }
|
|
93
|
+
: {})
|
|
94
|
+
}))
|
|
95
|
+
}))
|
|
96
|
+
yield* Console.log()
|
|
97
|
+
commandLine.push(child.name)
|
|
98
|
+
if (hasWizardSteps(child)) {
|
|
99
|
+
yield* logCurrentCommand(commandLine)
|
|
100
|
+
}
|
|
101
|
+
yield* promptCommand(child, commandLine, child.name)
|
|
102
|
+
}
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
const hasWizardSteps = (command: Command.Command.Any): boolean => {
|
|
106
|
+
const hasVisibleSubcommands = command.subcommands.some((group) => group.commands.some((child) => !child.hidden))
|
|
107
|
+
return hasVisibleSubcommands || toImpl(command).config.orderedParams.length > 0
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const promptParam: (
|
|
111
|
+
param: Param.Any
|
|
112
|
+
) => Effect.Effect<Array<string>, CliError.CliError | Terminal.QuitError, Command.Environment> = Effect.fnUntraced(
|
|
113
|
+
function*(param) {
|
|
114
|
+
const single = Param.getUnderlyingSingleOrThrow(param)
|
|
115
|
+
const metadata = Param.getParamMetadata(param)
|
|
116
|
+
|
|
117
|
+
if (metadata.isOptional) {
|
|
118
|
+
const include = yield* Prompt.run(Prompt.confirm({
|
|
119
|
+
message: `Set ${renderParamLabel(single)}?`,
|
|
120
|
+
initial: false
|
|
121
|
+
}))
|
|
122
|
+
if (!include) {
|
|
123
|
+
yield* Console.log()
|
|
124
|
+
return []
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const count = !metadata.isVariadic
|
|
129
|
+
? 1
|
|
130
|
+
: yield* Prompt.run(Prompt.integer({
|
|
131
|
+
message: `${renderParamLabel(single)} count`,
|
|
132
|
+
default: Option.getOrElse(metadata.variadicMin, () => 0),
|
|
133
|
+
min: Option.getOrElse(metadata.variadicMin, () => 0),
|
|
134
|
+
...(Option.isSome(metadata.variadicMax) ? { max: metadata.variadicMax.value } : {})
|
|
135
|
+
}))
|
|
136
|
+
const values: Array<string> = []
|
|
137
|
+
for (let i = 0; i < count; i++) {
|
|
138
|
+
values.push(yield* promptSingle(single))
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const parsed = single.kind === Param.flagKind
|
|
142
|
+
? {
|
|
143
|
+
flags: { [single.name]: values },
|
|
144
|
+
arguments: []
|
|
145
|
+
}
|
|
146
|
+
: {
|
|
147
|
+
flags: {},
|
|
148
|
+
arguments: values
|
|
149
|
+
}
|
|
150
|
+
yield* param.parse(parsed)
|
|
151
|
+
yield* Console.log()
|
|
152
|
+
|
|
153
|
+
if (single.kind === Param.argumentKind) {
|
|
154
|
+
return values
|
|
155
|
+
}
|
|
156
|
+
return values.flatMap((value) => [`--${single.name}`, value])
|
|
157
|
+
}
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
const promptSingle = (
|
|
161
|
+
single: Param.Single<Param.ParamKind, unknown>
|
|
162
|
+
): Effect.Effect<string, Terminal.QuitError, Command.Environment> => {
|
|
163
|
+
const message = renderParamMessage(single)
|
|
164
|
+
switch (single.primitiveType._tag) {
|
|
165
|
+
case "Boolean":
|
|
166
|
+
return Effect.map(
|
|
167
|
+
Prompt.run(Prompt.confirm({
|
|
168
|
+
message,
|
|
169
|
+
label: {
|
|
170
|
+
confirm: "true",
|
|
171
|
+
deny: "false"
|
|
172
|
+
},
|
|
173
|
+
placeholder: {
|
|
174
|
+
defaultConfirm: "(T/f)",
|
|
175
|
+
defaultDeny: "(t/F)"
|
|
176
|
+
}
|
|
177
|
+
})),
|
|
178
|
+
String
|
|
179
|
+
)
|
|
180
|
+
case "Choice": {
|
|
181
|
+
const choices = Primitive.getChoiceKeys(single.primitiveType) ?? []
|
|
182
|
+
return Prompt.run(Prompt.select({
|
|
183
|
+
message,
|
|
184
|
+
choices: choices.map((choice) => ({ title: choice, value: choice }))
|
|
185
|
+
}))
|
|
186
|
+
}
|
|
187
|
+
case "Date":
|
|
188
|
+
return Effect.map(Prompt.run(Prompt.date({ message })), (date) => date.toISOString())
|
|
189
|
+
case "Float":
|
|
190
|
+
return Effect.map(Prompt.run(Prompt.float({ message })), String)
|
|
191
|
+
case "Integer":
|
|
192
|
+
return Effect.map(Prompt.run(Prompt.integer({ message })), String)
|
|
193
|
+
case "Redacted":
|
|
194
|
+
return Effect.map(Prompt.run(Prompt.password({ message })), Redacted.value)
|
|
195
|
+
default:
|
|
196
|
+
return Prompt.run(Prompt.text({ message }))
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const formatName = (single: Param.Single<Param.ParamKind, unknown>): string =>
|
|
201
|
+
single.kind === Param.flagKind ? `--${single.name}` : single.name
|
|
202
|
+
|
|
203
|
+
const renderParamMessage = (single: Param.Single<Param.ParamKind, unknown>): string => renderParamLabel(single)
|
|
204
|
+
|
|
205
|
+
const renderParamLabel = (single: Param.Single<Param.ParamKind, unknown>): string => {
|
|
206
|
+
const description = Option.getOrUndefined(single.description)?.trim()
|
|
207
|
+
const label = single.kind === Param.flagKind && description !== undefined && description.length <= 32
|
|
208
|
+
? description
|
|
209
|
+
: humanize(single.name)
|
|
210
|
+
return single.kind === Param.flagKind ? `${label} (${formatName(single)})` : label
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const humanize = (name: string): string => {
|
|
214
|
+
const words = name.split(/[-_]+/).filter((word) => word.length > 0)
|
|
215
|
+
if (words.length === 0) return name
|
|
216
|
+
return [words[0][0].toUpperCase() + words[0].slice(1), ...words.slice(1)].join(" ")
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const logCurrentCommand = (commandLine: ReadonlyArray<string>): Effect.Effect<void> =>
|
|
220
|
+
Console.log(renderCommandBlock("Current command", commandLine, Ansi.magenta))
|
|
221
|
+
|
|
222
|
+
const renderSection = (commandName: string, section: string): string =>
|
|
223
|
+
`${Ansi.annotate(commandName.toUpperCase(), Ansi.bold, Ansi.cyanBright)} ${Ansi.annotate("·", Ansi.blackBright)} ${
|
|
224
|
+
Ansi.annotate(section, Ansi.bold, Ansi.white)
|
|
225
|
+
}`
|
|
226
|
+
|
|
227
|
+
export const renderIntroduction = (name: string, version: string, summary: string | undefined): string => {
|
|
228
|
+
const title = `${Ansi.annotate(name, Ansi.bold, Ansi.cyanBright)} ${Ansi.annotate(`v${version}`, Ansi.white)} ${
|
|
229
|
+
Ansi.annotate("· Command wizard", Ansi.bold, Ansi.white)
|
|
230
|
+
}`
|
|
231
|
+
return [
|
|
232
|
+
title,
|
|
233
|
+
...(summary === undefined || summary.length === 0 ? [] : [summary]),
|
|
234
|
+
Ansi.annotate("Build a command interactively. Press Ctrl+C to cancel.", Ansi.blackBright),
|
|
235
|
+
""
|
|
236
|
+
].join("\n")
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export const renderCompletion = (commandLine: ReadonlyArray<string>): string =>
|
|
240
|
+
renderCommandBlock("Command ready", commandLine, Ansi.cyanBright, Ansi.green)
|
|
241
|
+
|
|
242
|
+
export const renderQuit = (): string => `\n${Ansi.annotate("Wizard cancelled.", Ansi.red)}`
|
|
243
|
+
|
|
244
|
+
const renderCommandBlock = (
|
|
245
|
+
label: string,
|
|
246
|
+
commandLine: ReadonlyArray<string>,
|
|
247
|
+
commandColor: string,
|
|
248
|
+
labelColor: string = Ansi.white
|
|
249
|
+
): string => {
|
|
250
|
+
const lines = wrapCommand(commandLine)
|
|
251
|
+
return [
|
|
252
|
+
Ansi.annotate(label, Ansi.bold, labelColor),
|
|
253
|
+
...lines.map((line) => Ansi.annotate(line, commandColor)),
|
|
254
|
+
""
|
|
255
|
+
].join("\n")
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const wrapCommand = (commandLine: ReadonlyArray<string>): Array<string> => {
|
|
259
|
+
const width = 88
|
|
260
|
+
const firstIndent = " $ "
|
|
261
|
+
const continuationIndent = " "
|
|
262
|
+
const args = commandLine.map(formatShellArg)
|
|
263
|
+
const lines: Array<string> = []
|
|
264
|
+
let current = firstIndent
|
|
265
|
+
|
|
266
|
+
for (const arg of args) {
|
|
267
|
+
const separator = current === firstIndent || current === continuationIndent ? "" : " "
|
|
268
|
+
if (current.length + separator.length + arg.length > width && current !== firstIndent) {
|
|
269
|
+
lines.push(`${current} \\`)
|
|
270
|
+
current = `${continuationIndent}${arg}`
|
|
271
|
+
} else {
|
|
272
|
+
current += `${separator}${arg}`
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (current !== firstIndent) {
|
|
277
|
+
lines.push(current)
|
|
278
|
+
}
|
|
279
|
+
return lines
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const formatShellArg = (arg: string): string =>
|
|
283
|
+
/^[A-Za-z0-9_./:@%+=,-]+$/.test(arg) ? arg : `'${arg.replaceAll("'", `'"'"'`)}'`
|
|
@@ -34,27 +34,25 @@ import type { Sharding } from "./Sharding.ts"
|
|
|
34
34
|
*/
|
|
35
35
|
export const layerHttpApi = <
|
|
36
36
|
ApiId extends string,
|
|
37
|
-
Groups extends HttpApiGroup.
|
|
38
|
-
|
|
37
|
+
Groups extends HttpApiGroup.Constraint,
|
|
38
|
+
Identifier extends HttpApiGroup.Identifier<Groups>,
|
|
39
39
|
Type extends string,
|
|
40
40
|
Rpcs extends Rpc.Any
|
|
41
41
|
>(
|
|
42
42
|
api: HttpApi.HttpApi<ApiId, Groups>,
|
|
43
|
-
|
|
43
|
+
identifier: Identifier,
|
|
44
44
|
entity: Entity.Entity<Type, Rpcs>
|
|
45
|
-
): Layer.Layer<HttpApiGroup.
|
|
45
|
+
): Layer.Layer<HttpApiGroup.Service<ApiId, Identifier>, never, Sharding | Rpc.ServicesServer<Rpcs>> =>
|
|
46
46
|
HttpApiBuilder.group(
|
|
47
47
|
api,
|
|
48
|
-
|
|
49
|
-
Effect.fnUntraced(function*(
|
|
48
|
+
identifier,
|
|
49
|
+
Effect.fnUntraced(function*(handlers: any) {
|
|
50
50
|
const client = yield* entity.client
|
|
51
|
-
|
|
52
|
-
for (const parentRpc_ of entity.protocol.requests.values()) {
|
|
53
|
-
const parentRpc = parentRpc_ as any as Rpc.AnyWithProps
|
|
51
|
+
for (const parentRpc of entity.protocol.requests.values()) {
|
|
54
52
|
handlers = handlers
|
|
55
53
|
.handle(
|
|
56
|
-
parentRpc._tag
|
|
57
|
-
(
|
|
54
|
+
parentRpc._tag,
|
|
55
|
+
({ params, payload }: { params: { entityId: string }; payload: any }) =>
|
|
58
56
|
(client(params.entityId) as any as Record<string, (p: any) => Effect.Effect<any>>)[parentRpc._tag](
|
|
59
57
|
payload
|
|
60
58
|
).pipe(
|
|
@@ -65,11 +63,11 @@ export const layerHttpApi = <
|
|
|
65
63
|
entityId: params.entityId,
|
|
66
64
|
method: parentRpc._tag
|
|
67
65
|
})
|
|
68
|
-
)
|
|
66
|
+
)
|
|
69
67
|
)
|
|
70
68
|
.handle(
|
|
71
|
-
`${parentRpc._tag}Discard
|
|
72
|
-
(
|
|
69
|
+
`${parentRpc._tag}Discard`,
|
|
70
|
+
({ params, payload }: { params: { entityId: string }; payload: any }) =>
|
|
73
71
|
(client(params.entityId) as any as Record<string, (p: any, o: {}) => Effect.Effect<any>>)[parentRpc._tag](
|
|
74
72
|
payload,
|
|
75
73
|
{ discard: true }
|
|
@@ -81,10 +79,10 @@ export const layerHttpApi = <
|
|
|
81
79
|
entityId: params.entityId,
|
|
82
80
|
method: `${parentRpc._tag}Discard`
|
|
83
81
|
})
|
|
84
|
-
)
|
|
85
|
-
)
|
|
82
|
+
)
|
|
83
|
+
)
|
|
86
84
|
}
|
|
87
|
-
return handlers as HttpApiBuilder.Handlers<never
|
|
85
|
+
return handlers as HttpApiBuilder.Handlers<never>
|
|
88
86
|
})
|
|
89
87
|
)
|
|
90
88
|
|
|
@@ -220,7 +220,7 @@ export const makeMemory = Effect.gen(function*() {
|
|
|
220
220
|
setRunnerHealth: () => Effect.void,
|
|
221
221
|
acquire: (_address, shardIds) => {
|
|
222
222
|
acquired = Array.from(shardIds)
|
|
223
|
-
return Effect.succeed(
|
|
223
|
+
return Effect.succeed(acquired)
|
|
224
224
|
},
|
|
225
225
|
refresh: () => Effect.sync(() => acquired),
|
|
226
226
|
release: () => Effect.void,
|
|
@@ -207,15 +207,21 @@ export const make = Effect.fnUntraced(function*<
|
|
|
207
207
|
(isShuttingDown || isUninterruptibleForServer(request.message.annotations))
|
|
208
208
|
) {
|
|
209
209
|
if (!isShuttingDown) {
|
|
210
|
-
return server.write(
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
tag: request.message.envelope.tag as any,
|
|
214
|
-
payload: new Request({
|
|
210
|
+
return server.write(
|
|
211
|
+
0,
|
|
212
|
+
{
|
|
215
213
|
...request.message.envelope,
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
214
|
+
id: request.message.envelope.requestId as any,
|
|
215
|
+
tag: request.message.envelope.tag as any,
|
|
216
|
+
payload: new Request({
|
|
217
|
+
...request.message.envelope,
|
|
218
|
+
lastSentChunk: request.lastSentChunk
|
|
219
|
+
} as any) as any
|
|
220
|
+
},
|
|
221
|
+
Context.get(request.rpc.annotations, WithTransaction)
|
|
222
|
+
? { onRequest: options.storage.withTransaction }
|
|
223
|
+
: undefined
|
|
224
|
+
).pipe(
|
|
219
225
|
Effect.forkIn(scope)
|
|
220
226
|
)
|
|
221
227
|
}
|
|
@@ -295,16 +301,22 @@ export const make = Effect.fnUntraced(function*<
|
|
|
295
301
|
for (const id of defectRequestIds) {
|
|
296
302
|
const request = activeRequests.get(id)
|
|
297
303
|
if (!request) continue
|
|
298
|
-
const { lastSentChunk, message } = request
|
|
299
|
-
yield* server.write(
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
tag: message.envelope.tag as any,
|
|
303
|
-
payload: new Request({
|
|
304
|
+
const { lastSentChunk, message, rpc } = request
|
|
305
|
+
yield* server.write(
|
|
306
|
+
0,
|
|
307
|
+
{
|
|
304
308
|
...message.envelope,
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
309
|
+
id: message.envelope.requestId as any,
|
|
310
|
+
tag: message.envelope.tag as any,
|
|
311
|
+
payload: new Request({
|
|
312
|
+
...message.envelope,
|
|
313
|
+
lastSentChunk
|
|
314
|
+
} as any) as any
|
|
315
|
+
},
|
|
316
|
+
Context.get(rpc.annotations, WithTransaction)
|
|
317
|
+
? { onRequest: options.storage.withTransaction }
|
|
318
|
+
: undefined
|
|
319
|
+
)
|
|
308
320
|
}
|
|
309
321
|
defectRequestIds.clear()
|
|
310
322
|
}
|
|
@@ -341,11 +353,11 @@ export const make = Effect.fnUntraced(function*<
|
|
|
341
353
|
const state: EntityState = {
|
|
342
354
|
scope,
|
|
343
355
|
address,
|
|
344
|
-
write(clientId, message) {
|
|
356
|
+
write(clientId, message, writeOptions) {
|
|
345
357
|
if (writeRef.state.current._tag !== "Acquired") {
|
|
346
|
-
return Effect.flatMap(writeRef.await, (write) => write(clientId, message))
|
|
358
|
+
return Effect.flatMap(writeRef.await, (write) => write(clientId, message, writeOptions))
|
|
347
359
|
}
|
|
348
|
-
return writeRef.state.current.value(clientId, message)
|
|
360
|
+
return writeRef.state.current.value(clientId, message, writeOptions)
|
|
349
361
|
},
|
|
350
362
|
activeRequests,
|
|
351
363
|
lastActiveCheck: clock.currentTimeMillisUnsafe(),
|
|
@@ -472,21 +484,23 @@ export const make = Effect.fnUntraced(function*<
|
|
|
472
484
|
})
|
|
473
485
|
}
|
|
474
486
|
server.activeRequests.set(message.envelope.requestId, entry)
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
payload: new Request({
|
|
487
|
+
return server.write(
|
|
488
|
+
0,
|
|
489
|
+
{
|
|
479
490
|
...message.envelope,
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
491
|
+
id: message.envelope.requestId as any,
|
|
492
|
+
payload: new Request({
|
|
493
|
+
...message.envelope,
|
|
494
|
+
lastSentChunk: Option.filter(
|
|
495
|
+
message.lastSentReply,
|
|
496
|
+
(reply): reply is Reply.Chunk<R> => reply._tag === "Chunk"
|
|
497
|
+
)
|
|
498
|
+
})
|
|
499
|
+
},
|
|
500
|
+
Context.get(message.annotations, WithTransaction)
|
|
501
|
+
? { onRequest: options.storage.withTransaction }
|
|
502
|
+
: undefined
|
|
503
|
+
)
|
|
490
504
|
}
|
|
491
505
|
case "IncomingEnvelope": {
|
|
492
506
|
const entry = server.activeRequests.get(message.envelope.requestId)
|
|
@@ -452,7 +452,9 @@ export const makeChannel = <IE>(headers: Record<string, string>): Channel.Channe
|
|
|
452
452
|
exit = Option.some(Exit.fail(convertError(error_)))
|
|
453
453
|
},
|
|
454
454
|
onDone() {
|
|
455
|
-
|
|
455
|
+
if (Option.isNone(exit)) {
|
|
456
|
+
exit = Option.some(Exit.fail(Cause.Done()))
|
|
457
|
+
}
|
|
456
458
|
}
|
|
457
459
|
})
|
|
458
460
|
|