@toshicloud/sdk 0.3.2 → 0.5.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.
Files changed (59) hide show
  1. package/README.md +189 -30
  2. package/dist/client.d.ts +30 -4
  3. package/dist/client.js +19 -6
  4. package/dist/errors.d.ts +47 -0
  5. package/dist/errors.js +136 -0
  6. package/dist/execute.js +15 -0
  7. package/dist/gen/toshi/permission_pb.d.ts +39 -0
  8. package/dist/gen/toshi/permission_pb.js +42 -0
  9. package/dist/gen/toshi/workspace/v1/artifacts_pb.d.ts +1 -1
  10. package/dist/gen/toshi/workspace/v1/artifacts_pb.js +3 -2
  11. package/dist/gen/toshi/workspace/v1/audit_events_pb.js +2 -1
  12. package/dist/gen/toshi/workspace/v1/channels_pb.js +2 -1
  13. package/dist/gen/toshi/workspace/v1/discovery_pb.d.ts +676 -0
  14. package/dist/gen/toshi/workspace/v1/discovery_pb.js +182 -0
  15. package/dist/gen/toshi/workspace/v1/display_pb.js +2 -1
  16. package/dist/gen/toshi/workspace/v1/fillers_pb.js +2 -1
  17. package/dist/gen/toshi/workspace/v1/hostjobs_pb.js +2 -1
  18. package/dist/gen/toshi/workspace/v1/hosts_pb.js +2 -1
  19. package/dist/gen/toshi/workspace/v1/products_pb.d.ts +703 -0
  20. package/dist/gen/toshi/workspace/v1/products_pb.js +106 -0
  21. package/dist/gen/toshi/workspace/v1/projects_pb.js +2 -1
  22. package/dist/gen/toshi/workspace/v1/recordings_pb.js +2 -1
  23. package/dist/gen/toshi/workspace/v1/secrets_pb.js +2 -1
  24. package/dist/gen/toshi/workspace/v1/storage_providers_pb.js +2 -1
  25. package/dist/gen/toshi/workspace/v1/tokens_pb.js +2 -1
  26. package/dist/gen/toshi/workspace/v1/volumes_pb.js +2 -1
  27. package/dist/gen/toshi/workspace/v1/webhook_pb.js +2 -1
  28. package/dist/gen/toshi/workspace/v1/workloads_pb.js +2 -1
  29. package/dist/gen/toshi/workspace/v1/workspace_pb.d.ts +2 -2
  30. package/dist/gen/toshi/workspace/v1/workspace_pb.js +1 -1
  31. package/dist/gen/toshi/workspace/v1/workspace_service_pb.js +2 -1
  32. package/dist/index.d.ts +6 -1
  33. package/dist/index.js +5 -1
  34. package/dist/interceptors.d.ts +17 -2
  35. package/dist/interceptors.js +69 -4
  36. package/dist/node/client.d.ts +35 -0
  37. package/dist/node/client.js +178 -0
  38. package/dist/node/index.d.ts +3 -0
  39. package/dist/node/index.js +4 -0
  40. package/dist/output.js +6 -1
  41. package/dist/paginate.d.ts +36 -0
  42. package/dist/paginate.js +37 -0
  43. package/dist/retry.js +4 -0
  44. package/dist/run.js +3 -2
  45. package/dist/stream.d.ts +8 -1
  46. package/dist/stream.js +24 -2
  47. package/dist/test/fake.d.ts +88 -0
  48. package/dist/test/fake.js +845 -0
  49. package/dist/test/index.d.ts +58 -0
  50. package/dist/test/index.js +57 -0
  51. package/dist/test/procedures.d.ts +18 -0
  52. package/dist/test/procedures.js +219 -0
  53. package/dist/timeout.d.ts +29 -0
  54. package/dist/timeout.js +67 -0
  55. package/dist/version.d.ts +2 -0
  56. package/dist/version.js +2 -0
  57. package/dist/wait.js +15 -12
  58. package/dist/watch.js +15 -2
  59. package/package.json +19 -3
@@ -0,0 +1,88 @@
1
+ import type { DescMethod, Message } from "@bufbuild/protobuf";
2
+ import type { Interceptor, MethodImpl, Transport } from "@connectrpc/connect";
3
+ import type { ToshiClient, ToshiOptions } from "../client.js";
4
+ import { JobState, SandboxState } from "../gen/toshi/workspace/v1/workspace_pb.js";
5
+ /** The token `client` sends. */
6
+ export declare const testToken = "test-token";
7
+ /** One call the fake received. */
8
+ export interface Call {
9
+ /** The procedure the client called, for example `/toshi.workspace.v1.WorkloadService/CreateJob`. */
10
+ readonly procedure: string;
11
+ /** The message the client sent. A bidirectional stream's call is recorded when its first message arrives. */
12
+ readonly request: Message;
13
+ /** The request headers the client sent. */
14
+ readonly header: Headers;
15
+ }
16
+ /** A job of the fake, and what it answers about it. */
17
+ export interface FakeJob {
18
+ /** Sets the state the fake reports for the job. */
19
+ state(state: JobState): FakeJob;
20
+ /** Sets the standard output WatchOutput streams. */
21
+ stdout(stdout: string): FakeJob;
22
+ /** Sets the standard error WatchOutput streams. */
23
+ stderr(stderr: string): FakeJob;
24
+ /** Ends the job with code: the state is ENDED and the end reason EXITED. */
25
+ exitCode(code: number): FakeJob;
26
+ }
27
+ /** A sandbox of the fake, and what it answers about it. */
28
+ export interface FakeSandbox {
29
+ /** Sets the state the fake reports for the sandbox. */
30
+ state(state: SandboxState): FakeSandbox;
31
+ }
32
+ /** What Execute answers in one sandbox. */
33
+ export interface FakeExecution {
34
+ /** Sets the standard output Execute streams. */
35
+ stdout(stdout: string): FakeExecution;
36
+ /** Sets the standard error Execute streams. */
37
+ stderr(stderr: string): FakeExecution;
38
+ /** Sets the exit code the execution ends with. */
39
+ exitCode(code: number): FakeExecution;
40
+ }
41
+ /** A fake Toshi, built with `createFake`. */
42
+ export interface Fake {
43
+ /**
44
+ * Builds the in-memory transport the client uses, with the interceptors it
45
+ * is handed. Pass it as `createToshiClient({ transport: fake.transport })`.
46
+ */
47
+ readonly transport: (interceptors: Interceptor[]) => Transport;
48
+ /**
49
+ * Returns the job with this id. A job the fake has not created yet is what
50
+ * the next CreateJob answers with. It is running until the test sets its
51
+ * state or its exit code.
52
+ */
53
+ job(id: string): FakeJob;
54
+ /**
55
+ * Returns the sandbox with this id. A sandbox the fake has not created yet
56
+ * is what the next CreateSandbox answers with. It is running until the test
57
+ * sets its state.
58
+ */
59
+ sandbox(id: string): FakeSandbox;
60
+ /**
61
+ * Returns what Execute answers in a sandbox: an empty command that exits 0
62
+ * until the test sets its output or its exit code. The sandbox is registered
63
+ * too, so a later GetSandbox finds it.
64
+ */
65
+ execute(sandboxId: string): FakeExecution;
66
+ /**
67
+ * Answers a method instead of the state machine. The implementation is typed
68
+ * by the method, as `router.rpc` is: one call for unary, server-stream and
69
+ * bidirectional methods. A method from outside the Workspace API throws.
70
+ */
71
+ on<M extends DescMethod>(method: M, impl: MethodImpl<M>): Fake;
72
+ /** Returns every call the fake received, oldest first. */
73
+ calls(): readonly Call[];
74
+ /**
75
+ * Returns a client wired to the fake: the token `testToken`, the scope
76
+ * default/production, and a retry policy that answers at once. options
77
+ * change any of that, and are applied last.
78
+ */
79
+ client(options?: FakeOptions): ToshiClient;
80
+ }
81
+ /** The options `client` takes: ToshiOptions without the transport, which the fake supplies. */
82
+ export type FakeOptions = Omit<ToshiOptions, "transport">;
83
+ /** Creates a fake Toshi: an in-memory Workspace API and the state its calls answer from. */
84
+ export declare function createFake(): Fake;
85
+ /** The procedures the state machine answers. The coverage test holds it against the API. */
86
+ export declare const answeredProcedures: readonly DescMethod[];
87
+ /** The methods the state machine does not answer, for the coverage test's comparison. */
88
+ export declare const hookOnlyProcedures: readonly DescMethod[];