@krak-stack/registry 0.1.16 → 0.1.17
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/dist/lib/httpapi-cli.d.ts +9 -8
- package/dist/lib/httpapi-cli.js +13 -4
- package/package.json +1 -1
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import { Context, Effect, FileSystem, Layer, Path, Stdio, Terminal } from "effect";
|
|
2
2
|
import { Command } from "effect/unstable/cli";
|
|
3
3
|
import { ChildProcessSpawner } from "effect/unstable/process/ChildProcessSpawner";
|
|
4
|
-
import { ApiClient } from "./httpapi-client.js";
|
|
5
|
-
import { HttpApiSpec } from "./httpapi-helpers.js";
|
|
4
|
+
import { ApiClient, type ApiClientService } from "./httpapi-client.js";
|
|
5
|
+
import { HttpApiSpec, type HttpApiOperationEntry } from "./httpapi-helpers.js";
|
|
6
6
|
declare const HttpApiCli_base: Context.ServiceClass<HttpApiCli, "HttpApiCli", {
|
|
7
|
-
command: Command.Command<string, {}, {},
|
|
8
|
-
run: (args: ReadonlyArray<string>) => Effect.Effect<void,
|
|
7
|
+
command: Command.Command<string, {}, {}, unknown, never>;
|
|
8
|
+
run: (args: ReadonlyArray<string>) => Effect.Effect<void, unknown, Command.Environment>;
|
|
9
9
|
}> & {
|
|
10
10
|
readonly make: () => Effect.Effect<{
|
|
11
|
-
command: Command.Command<string, {}, {},
|
|
12
|
-
run: (args: ReadonlyArray<string>) => Effect.Effect<void,
|
|
11
|
+
command: Command.Command<string, {}, {}, unknown, never>;
|
|
12
|
+
run: (args: ReadonlyArray<string>) => Effect.Effect<void, unknown, Command.Environment>;
|
|
13
13
|
}, never, ApiClient | HttpApiSpec>;
|
|
14
14
|
};
|
|
15
15
|
export declare class HttpApiCli extends HttpApiCli_base {
|
|
16
16
|
static readonly layer: Layer.Layer<HttpApiCli, never, ApiClient | HttpApiSpec>;
|
|
17
17
|
}
|
|
18
|
-
export declare const
|
|
18
|
+
export declare const printHttpApiCliResult: (response: unknown, operation: HttpApiOperationEntry, client: ApiClientService) => Effect.Effect<void, unknown, never>;
|
|
19
|
+
export declare const makeHttpApiCliCommand: () => Effect.Effect<Command.Command<string, {}, {}, unknown, never>, never, ApiClient | HttpApiSpec>;
|
|
19
20
|
export declare const httpApiCliEnvironmentLayer: (args: ReadonlyArray<string>) => Layer.Layer<ChildProcessSpawner | FileSystem.FileSystem | Path.Path | Stdio.Stdio | Terminal.Terminal, never, never>;
|
|
20
|
-
export declare const httpApiCli: (args?: string[]) => Effect.Effect<void,
|
|
21
|
+
export declare const httpApiCli: (args?: string[]) => Effect.Effect<void, unknown, HttpApiCli | Command.Environment>;
|
|
21
22
|
export declare const runHttpApiCli: <E>(layer: Layer.Layer<HttpApiCli, E>, args?: string[]) => void;
|
|
22
23
|
export {};
|
package/dist/lib/httpapi-cli.js
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
FileSystem,
|
|
7
7
|
Layer as Layer3,
|
|
8
8
|
Path,
|
|
9
|
+
Schema as Schema3,
|
|
9
10
|
Stdio,
|
|
10
11
|
Stream,
|
|
11
12
|
Terminal
|
|
@@ -406,6 +407,15 @@ var print = (value) => Console.log(value);
|
|
|
406
407
|
var formatOperations = (operations) => operations.map((operation) => `${operation.groupName} ${operation.name} ${operation.method.toUpperCase()} ${operation.path} ${operation.summary}`).join(`
|
|
407
408
|
`);
|
|
408
409
|
var listOperations = (operations) => print(formatOperations(operations));
|
|
410
|
+
var HttpApiCliResultStream = Schema3.declare((value) => Stream.isStream(value)).annotate({ identifier: "HttpApiCliResultStream" });
|
|
411
|
+
var printHttpApiCliResult = Effect3.fn("HttpApiCli.printResult")(function* (response, operation, client) {
|
|
412
|
+
const stream = Schema3.decodeUnknownOption(HttpApiCliResultStream)(response);
|
|
413
|
+
if (stream._tag === "Some") {
|
|
414
|
+
return yield* stream.value.pipe(Stream.mapEffect((event) => client.encodeResult(event, operation)), Stream.runForEach((event) => print(JSON.stringify(event))));
|
|
415
|
+
}
|
|
416
|
+
const encoded = yield* client.encodeResult(response, operation);
|
|
417
|
+
return yield* print(JSON.stringify(encoded, null, 2) ?? "null");
|
|
418
|
+
});
|
|
409
419
|
var callOperation = (operation, callConfig, client) => Effect3.gen(function* () {
|
|
410
420
|
const body = yield* parseJsonValue(callConfig.body, "--body");
|
|
411
421
|
const headers = yield* parseJsonObject(callConfig.headers, "--headers");
|
|
@@ -419,13 +429,11 @@ var callOperation = (operation, callConfig, client) => Effect3.gen(function* ()
|
|
|
419
429
|
},
|
|
420
430
|
input: { body, headers, params, query }
|
|
421
431
|
});
|
|
422
|
-
|
|
432
|
+
return yield* printHttpApiCliResult(response, {
|
|
423
433
|
method: operation.method,
|
|
424
434
|
path: operation.path,
|
|
425
435
|
operation: operation.operation
|
|
426
|
-
});
|
|
427
|
-
const formatted = JSON.stringify(encoded, null, 2) ?? "null";
|
|
428
|
-
return yield* print(formatted);
|
|
436
|
+
}, client);
|
|
429
437
|
});
|
|
430
438
|
var listCommand = (groups) => Command.make("list", {}, () => print(groups.map((group) => `${group.name} ${group.title} ${group.operations.length}`).join(`
|
|
431
439
|
`))).pipe(Command.withDescription("List command groups"));
|
|
@@ -477,6 +485,7 @@ var runHttpApiCli = (layer, args = process.argv.slice(2)) => {
|
|
|
477
485
|
};
|
|
478
486
|
export {
|
|
479
487
|
runHttpApiCli,
|
|
488
|
+
printHttpApiCliResult,
|
|
480
489
|
makeHttpApiCliCommand,
|
|
481
490
|
httpApiCliEnvironmentLayer,
|
|
482
491
|
httpApiCli,
|