@krak-stack/registry 0.1.61 → 0.2.1

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 (56) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/components/ui/color-picker.d.ts +30 -0
  3. package/dist/components/ui/color-picker.js +384 -0
  4. package/dist/components/ui/data-table.js +26 -14
  5. package/dist/components/ui/effect-form.js +2 -2
  6. package/dist/components/ui/error-component.js +4 -12
  7. package/dist/components/ui/form.d.ts +126 -330
  8. package/dist/components/ui/google-map.js +38 -6
  9. package/dist/components/ui/sidebar-layout.js +10 -13
  10. package/dist/lib/docs.d.ts +2 -2
  11. package/dist/lib/docs.js +16 -19
  12. package/dist/lib/docs.server.js +5 -5
  13. package/dist/lib/documentation-toolkit.d.ts +2 -2
  14. package/dist/lib/documentation-toolkit.js +4 -4
  15. package/dist/lib/httpapi-adapter.d.ts +11 -3
  16. package/dist/lib/httpapi-adapter.js +40 -13
  17. package/dist/lib/httpapi-cli.d.ts +13 -4
  18. package/dist/lib/httpapi-cli.js +63 -21
  19. package/dist/lib/httpapi-toolkit.js +40 -13
  20. package/dist/lib/query.d.ts +4 -4
  21. package/dist/lib/query.js +2 -2
  22. package/dist/lib/webfetch-toolkit.js +1 -1
  23. package/dist/services/agent/index.js +1 -1
  24. package/dist/services/events/browser.js +32 -17
  25. package/dist/services/events/client/audit-log-table.js +26 -14
  26. package/dist/services/events/client/tracking-notice.js +9 -4
  27. package/dist/services/events/index.d.ts +3 -1
  28. package/dist/services/events/index.js +22 -17
  29. package/dist/services/events/schema.d.ts +18 -10
  30. package/dist/services/events/schema.js +3 -3
  31. package/dist/services/file-extraction/schema.d.ts +3 -1
  32. package/dist/services/health/api.builder.d.ts +8 -8
  33. package/dist/services/health/api.group.d.ts +8 -8
  34. package/dist/services/health/index.d.ts +10 -6
  35. package/dist/services/health/index.js +8 -4
  36. package/dist/services/health/schema.d.ts +7 -7
  37. package/dist/services/notification/index.js +1 -1
  38. package/dist/services/notification/public.js +1 -1
  39. package/dist/services/notification/schema.d.ts +3 -1
  40. package/dist/services/opentelemetry/api.js +5 -3
  41. package/dist/services/opentelemetry/browser.js +2 -2
  42. package/dist/services/opentelemetry/index.js +2 -2
  43. package/dist/services/opentelemetry/processor.d.ts +3 -1
  44. package/dist/services/opentelemetry/web-vitals.js +10 -5
  45. package/dist/services/s3/schema.d.ts +3 -1
  46. package/dist/services/speech/api.js +3 -1
  47. package/dist/services/speech/index.js +15 -8
  48. package/dist/services/speech/schema.d.ts +3 -1
  49. package/dist/services/speech/schema.js +3 -1
  50. package/dist/services/webhooks/client/delivery-table.js +26 -14
  51. package/dist/services/webhooks/http-client.js +1 -1
  52. package/dist/services/webhooks/index.js +14 -14
  53. package/dist/services/webhooks/receiver.d.ts +6 -2
  54. package/dist/services/webhooks/schema.d.ts +7 -5
  55. package/dist/services/webhooks/schema.js +2 -2
  56. package/package.json +6 -1
@@ -17,7 +17,7 @@ export declare const DocsFrontmatter: Schema.Struct<{
17
17
  readonly title: Schema.String;
18
18
  readonly description: Schema.String;
19
19
  readonly icon: Schema.optional<Schema.String>;
20
- readonly order: Schema.Number;
20
+ readonly order: Schema.Finite;
21
21
  readonly locale: Schema.String;
22
22
  readonly section: Schema.String;
23
23
  readonly type: Schema.Literals<readonly ["concept", "tutorial", "how-to", "reference", "runbook"]>;
@@ -42,7 +42,7 @@ export declare const DocsPageSchema: Schema.Struct<{
42
42
  readonly title: Schema.String;
43
43
  readonly description: Schema.String;
44
44
  readonly icon: Schema.optional<Schema.String>;
45
- readonly order: Schema.Number;
45
+ readonly order: Schema.Finite;
46
46
  readonly locale: Schema.String;
47
47
  readonly section: Schema.String;
48
48
  readonly type: Schema.Literals<readonly ["concept", "tutorial", "how-to", "reference", "runbook"]>;
package/dist/lib/docs.js CHANGED
@@ -6,8 +6,8 @@ import { Cookies as Cookies2 } from "effect/http";
6
6
  import {
7
7
  forwardRef,
8
8
  useDeferredValue,
9
- useEffect as useEffect5,
10
- useState as useState6
9
+ useEffect as useEffect4,
10
+ useState as useState5
11
11
  } from "react";
12
12
 
13
13
  // ../../src/components/ui/app-brand.tsx
@@ -802,7 +802,7 @@ function SearchMenu({
802
802
  import { Link as Link2, Outlet } from "@tanstack/react-router";
803
803
  import { Option, Schema as Schema2 } from "effect";
804
804
  import { Cookies } from "effect/http";
805
- import { useState as useState5 } from "react";
805
+ import { useState as useState4 } from "react";
806
806
 
807
807
  // ../../src/components/ui/sidebar.tsx
808
808
  import * as React2 from "react";
@@ -813,18 +813,15 @@ import { cva as cva3 } from "class-variance-authority";
813
813
  // ../../src/hooks/use-mobile.ts
814
814
  import * as React from "react";
815
815
  var MOBILE_BREAKPOINT = 768;
816
+ var subscribe = (onChange) => {
817
+ const query = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
818
+ query.addEventListener("change", onChange);
819
+ return () => query.removeEventListener("change", onChange);
820
+ };
821
+ var getSnapshot = () => window.innerWidth < MOBILE_BREAKPOINT;
822
+ var getServerSnapshot = () => false;
816
823
  function useIsMobile() {
817
- const [isMobile, setIsMobile] = React.useState(undefined);
818
- React.useEffect(() => {
819
- const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
820
- const onChange = () => {
821
- setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
822
- };
823
- mql.addEventListener("change", onChange);
824
- setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
825
- return () => mql.removeEventListener("change", onChange);
826
- }, []);
827
- return !!isMobile;
824
+ return React.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
828
825
  }
829
826
 
830
827
  // ../../src/components/ui/input.tsx
@@ -1391,7 +1388,7 @@ function SidebarLayout({
1391
1388
  sidebarCollapsible = "icon",
1392
1389
  defaultOpen = true
1393
1390
  }) {
1394
- const [sidebarOpen, setSidebarOpen] = useState5(() => getSidebarDefaultOpen(defaultOpen));
1391
+ const [sidebarOpen, setSidebarOpen] = useState4(() => getSidebarDefaultOpen(defaultOpen));
1395
1392
  return /* @__PURE__ */ jsxs10(SidebarProvider, {
1396
1393
  open: sidebarOpen,
1397
1394
  onOpenChange: setSidebarOpen,
@@ -1635,7 +1632,7 @@ var DocsFrontmatter = Schema3.Struct({
1635
1632
  title: Schema3.String,
1636
1633
  description: Schema3.String,
1637
1634
  icon: Schema3.optional(Schema3.String),
1638
- order: Schema3.Number,
1635
+ order: Schema3.Finite,
1639
1636
  locale: Schema3.String,
1640
1637
  section: DocsSection,
1641
1638
  type: DocsPageType,
@@ -2011,8 +2008,8 @@ var DocsArticle = ({
2011
2008
  });
2012
2009
  };
2013
2010
  var useActiveDocsHeading = (headings) => {
2014
- const [activeHeadingId, setActiveHeadingId] = useState6();
2015
- useEffect5(() => {
2011
+ const [activeHeadingId, setActiveHeadingId] = useState5();
2012
+ useEffect4(() => {
2016
2013
  const elements = headings.flatMap((heading) => {
2017
2014
  const element = document.getElementById(heading.id);
2018
2015
  return element ? [element] : [];
@@ -2123,7 +2120,7 @@ var DocsSearch = ({
2123
2120
  locale,
2124
2121
  messages
2125
2122
  }) => {
2126
- const [query, setQuery] = useState6("");
2123
+ const [query, setQuery] = useState5("");
2127
2124
  const deferredQuery = useDeferredValue(query);
2128
2125
  const results = docs.search(deferredQuery, locale);
2129
2126
  const isSearching = deferredQuery.trim().length > 0;
@@ -10,8 +10,8 @@ import { Cookies as Cookies2 } from "effect/http";
10
10
  import {
11
11
  forwardRef,
12
12
  useDeferredValue,
13
- useEffect as useEffect5,
14
- useState as useState6
13
+ useEffect as useEffect4,
14
+ useState as useState5
15
15
  } from "react";
16
16
 
17
17
  // ../../src/components/ui/app-brand.tsx
@@ -122,7 +122,7 @@ import { useKrakstackLocale as useKrakstackLocale3 } from "@krak-stack/registry/
122
122
  import { Link as Link2, Outlet } from "@tanstack/react-router";
123
123
  import { Option, Schema as Schema2 } from "effect";
124
124
  import { Cookies } from "effect/http";
125
- import { useState as useState5 } from "react";
125
+ import { useState as useState4 } from "react";
126
126
 
127
127
  // ../../src/components/ui/sidebar.tsx
128
128
  import * as React2 from "react";
@@ -264,7 +264,7 @@ var DocsFrontmatter = Schema3.Struct({
264
264
  title: Schema3.String,
265
265
  description: Schema3.String,
266
266
  icon: Schema3.optional(Schema3.String),
267
- order: Schema3.Number,
267
+ order: Schema3.Finite,
268
268
  locale: Schema3.String,
269
269
  section: DocsSection,
270
270
  type: DocsPageType,
@@ -409,7 +409,7 @@ var compileMdxDocsPage = (sourceFile, source) => {
409
409
  throw new Error(`Body title does not match frontmatter in ${sourceFile}`);
410
410
  }
411
411
  const body = bodySource.replace(/^\s*#\s+.+?\r?\n+/, "");
412
- return Schema4.decodeUnknownSync(DocsPageSchema)({
412
+ return Schema4.decodeSync(DocsPageSchema)({
413
413
  ...frontmatter,
414
414
  ...compileDocsMarkdown(body),
415
415
  sourceFile
@@ -13,7 +13,7 @@ export declare const DocumentationToolkit: Toolkit.Toolkit<{
13
13
  readonly title: Schema.String;
14
14
  readonly description: Schema.String;
15
15
  readonly icon: Schema.optional<Schema.String>;
16
- readonly order: Schema.Number;
16
+ readonly order: Schema.Finite;
17
17
  readonly locale: Schema.String;
18
18
  readonly section: Schema.String;
19
19
  readonly type: Schema.Literals<readonly ["concept", "tutorial", "how-to", "reference", "runbook"]>;
@@ -115,7 +115,7 @@ export declare const DocumentationToolkitLayer: ({ docs, locale, }: Documentatio
115
115
  readonly title: Schema.String;
116
116
  readonly description: Schema.String;
117
117
  readonly icon: Schema.optional<Schema.String>;
118
- readonly order: Schema.Number;
118
+ readonly order: Schema.Finite;
119
119
  readonly locale: Schema.String;
120
120
  readonly section: Schema.String;
121
121
  readonly type: Schema.Literals<readonly ["concept", "tutorial", "how-to", "reference", "runbook"]>;
@@ -10,8 +10,8 @@ import { Cookies as Cookies2 } from "effect/http";
10
10
  import {
11
11
  forwardRef,
12
12
  useDeferredValue,
13
- useEffect as useEffect5,
14
- useState as useState6
13
+ useEffect as useEffect4,
14
+ useState as useState5
15
15
  } from "react";
16
16
 
17
17
  // ../../src/components/ui/app-brand.tsx
@@ -122,7 +122,7 @@ import { useKrakstackLocale as useKrakstackLocale3 } from "@krak-stack/registry/
122
122
  import { Link as Link2, Outlet } from "@tanstack/react-router";
123
123
  import { Option, Schema as Schema2 } from "effect";
124
124
  import { Cookies } from "effect/http";
125
- import { useState as useState5 } from "react";
125
+ import { useState as useState4 } from "react";
126
126
 
127
127
  // ../../src/components/ui/sidebar.tsx
128
128
  import * as React2 from "react";
@@ -264,7 +264,7 @@ var DocsFrontmatter = Schema3.Struct({
264
264
  title: Schema3.String,
265
265
  description: Schema3.String,
266
266
  icon: Schema3.optional(Schema3.String),
267
- order: Schema3.Number,
267
+ order: Schema3.Finite,
268
268
  locale: Schema3.String,
269
269
  section: DocsSection,
270
270
  type: DocsPageType,
@@ -2,6 +2,14 @@ import { Context, Effect, JsonSchema, Layer, Schema } from "effect";
2
2
  import type { Json } from "effect/Schema";
3
3
  import { HttpClient } from "effect/http";
4
4
  import { HttpApi, HttpApiGroup, OpenApi } from "effect/http-api";
5
+ declare const HttpApiAdapterError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
6
+ readonly _tag: "HttpApiAdapterError";
7
+ } & Readonly<A>;
8
+ declare class HttpApiAdapterError extends HttpApiAdapterError_base<{
9
+ readonly message: string;
10
+ readonly cause?: unknown;
11
+ }> {
12
+ }
5
13
  export type HttpApiMethod = "get" | "post" | "put" | "patch" | "delete";
6
14
  declare const HttpApiOperation: Schema.Struct<{
7
15
  readonly operationId: Schema.optional<Schema.String>;
@@ -64,10 +72,10 @@ export type HttpApiAdapterService = {
64
72
  readonly execute: (options: HttpApiAdapterExecuteOptions) => Effect.Effect<unknown, Error>;
65
73
  readonly encodeResult: (result: unknown, operation: HttpApiOperationDefinition) => Effect.Effect<Json, Error>;
66
74
  };
67
- export declare const encodeHttpApiOperationResult: (result: unknown) => Effect.Effect<string | number | boolean | Schema.JsonArray | Schema.JsonObject | null, Error, never>;
75
+ export declare const encodeHttpApiOperationResult: (result: unknown) => Effect.Effect<string | number | boolean | Schema.JsonArray | Schema.JsonObject | null, HttpApiAdapterError, never>;
68
76
  declare const HttpApiAdapter_base: Context.ServiceClass<HttpApiAdapter, "@krak-stack/registry/HttpApiAdapter", HttpApiAdapterService>;
69
77
  export declare class HttpApiAdapter extends HttpApiAdapter_base {
70
- static readonly make: <Id extends string, Groups extends HttpApiGroup.Constraint>(config: HttpApiAdapterConfig<Id, Groups>) => Effect.Effect<HttpApiAdapterService, Error, HttpClient.HttpClient | import("effect/http-api/HttpApiMiddleware").MiddlewareClient<import("effect/http-api/HttpApiEndpoint").Middleware<HttpApiGroup.Endpoints<Groups>>>>;
71
- static readonly layer: <Id extends string, Groups extends HttpApiGroup.Constraint>(config: HttpApiAdapterConfig<Id, Groups>) => Layer.Layer<HttpApiAdapter, Error, HttpClient.HttpClient | Exclude<import("effect/http-api/HttpApiMiddleware").MiddlewareClient<import("effect/http-api/HttpApiEndpoint").Middleware<HttpApiGroup.Endpoints<Groups>>>, import("effect/Scope").Scope>>;
78
+ static readonly make: <Id extends string, Groups extends HttpApiGroup.Constraint>(config: HttpApiAdapterConfig<Id, Groups>) => Effect.Effect<HttpApiAdapterService, HttpApiAdapterError, HttpClient.HttpClient | import("effect/http-api/HttpApiMiddleware").MiddlewareClient<import("effect/http-api/HttpApiEndpoint").Middleware<HttpApiGroup.Endpoints<Groups>>>>;
79
+ static readonly layer: <Id extends string, Groups extends HttpApiGroup.Constraint>(config: HttpApiAdapterConfig<Id, Groups>) => Layer.Layer<HttpApiAdapter, HttpApiAdapterError, HttpClient.HttpClient | Exclude<import("effect/http-api/HttpApiMiddleware").MiddlewareClient<import("effect/http-api/HttpApiEndpoint").Middleware<HttpApiGroup.Endpoints<Groups>>>, import("effect/Scope").Scope>>;
72
80
  }
73
81
  export {};
@@ -1,4 +1,5 @@
1
1
  // ../../src/lib/httpapi-adapter.ts
2
+ import * as Data from "effect/Data";
2
3
  import {
3
4
  Context,
4
5
  Effect,
@@ -9,6 +10,9 @@ import {
9
10
  } from "effect";
10
11
  import { HttpClient } from "effect/http";
11
12
  import { HttpApi, HttpApiClient, OpenApi } from "effect/http-api";
13
+
14
+ class HttpApiAdapterError extends Data.TaggedError("HttpApiAdapterError") {
15
+ }
12
16
  var HttpApiMethods = [
13
17
  "get",
14
18
  "post",
@@ -45,7 +49,7 @@ var HttpApiOperationResultValue = Schema.suspend(() => Schema.Union([
45
49
  Schema.Null,
46
50
  UndefinedFromNull,
47
51
  Schema.String,
48
- Schema.Number,
52
+ Schema.Finite,
49
53
  Schema.Boolean,
50
54
  Schema.DateFromString,
51
55
  Schema.Uint8ArrayFromBase64,
@@ -56,9 +60,15 @@ var HttpApiOperationResult = Schema.Union([
56
60
  HttpApiOperationResultValue,
57
61
  Schema.Undefined
58
62
  ]).annotate({ identifier: "HttpApiOperationResult" });
59
- var encodeHttpApiOperationResult = Effect.fn("HttpApiAdapter.encodeOperationResult")((result) => Schema.encodeUnknownEffect(HttpApiOperationResult)(result).pipe(Effect.map((encoded) => encoded ?? null), Effect.mapError((cause) => new Error("HTTP API result is not serializable", { cause }))));
60
- var encodeOperationResult = Effect.fn("HttpApiAdapter.encodeResult")((result, operation) => operation.successSchema ? Schema.encodeUnknownEffect(operation.successSchema)(result).pipe(Effect.flatMap(encodeHttpApiOperationResult), Effect.mapError((cause) => new Error("HTTP API result does not match its success schema", {
61
- cause
63
+ var encodeHttpApiOperationResult = Effect.fn("HttpApiAdapter.encodeOperationResult")((result) => Schema.encodeUnknownEffect(HttpApiOperationResult)(result).pipe(Effect.map((encoded) => encoded ?? null), Effect.mapError((cause) => new HttpApiAdapterError({
64
+ message: "HTTP API result is not serializable",
65
+ cause: { cause }.cause
66
+ }))));
67
+ var encodeOperationResult = Effect.fn("HttpApiAdapter.encodeResult")((result, operation) => operation.successSchema ? Schema.encodeUnknownEffect(operation.successSchema)(result).pipe(Effect.flatMap(encodeHttpApiOperationResult), Effect.mapError((cause) => new HttpApiAdapterError({
68
+ message: "HTTP API result does not match its success schema",
69
+ cause: {
70
+ cause
71
+ }.cause
62
72
  }))) : encodeHttpApiOperationResult(result));
63
73
  var reflectedSchema = (schema) => Schema.make(schema.ast);
64
74
  var sanitizeHttpName = (name) => name.replace(/[^a-zA-Z0-9_-]/g, "_").replace(/_+/g, "_").replace(/^_+|_+$/g, "");
@@ -66,7 +76,9 @@ var httpApiToolName = (entry) => (entry.operation.operationId || `${entry.method
66
76
  var makeCatalogue = (api, methods, include) => Effect.try({
67
77
  try: () => {
68
78
  if (!HttpApi.isHttpApi(api))
69
- throw new Error("HttpApiAdapter requires a valid HttpApi");
79
+ throw new HttpApiAdapterError({
80
+ message: "HttpApiAdapter requires a valid HttpApi"
81
+ });
70
82
  const spec = OpenApi.fromApi(api);
71
83
  const reflected = new Map;
72
84
  HttpApi.reflect(api, {
@@ -76,7 +88,9 @@ var makeCatalogue = (api, methods, include) => Effect.try({
76
88
  onEndpoint: ({ endpoint, group, successes }) => {
77
89
  const operationId = Context.getOrElse(endpoint.annotations, OpenApi.Identifier, () => group.topLevel ? endpoint.identifier : `${group.identifier}.${endpoint.identifier}`);
78
90
  if (reflected.has(operationId))
79
- throw new Error(`Duplicate HTTP API operation ID: ${operationId}`);
91
+ throw new HttpApiAdapterError({
92
+ message: `Duplicate HTTP API operation ID: ${operationId}`
93
+ });
80
94
  const fields = {};
81
95
  if (endpoint.params)
82
96
  fields.params = Schema.toType(reflectedSchema(endpoint.params));
@@ -115,10 +129,14 @@ var makeCatalogue = (api, methods, include) => Effect.try({
115
129
  continue;
116
130
  const metadata = entry.operation.operationId ? reflected.get(entry.operation.operationId) : undefined;
117
131
  if (!metadata)
118
- throw new Error(`Missing endpoint schema for ${entry.operation.operationId}`);
132
+ throw new HttpApiAdapterError({
133
+ message: `Missing endpoint schema for ${entry.operation.operationId}`
134
+ });
119
135
  const name = httpApiToolName(entry);
120
136
  if (!name || names.has(name))
121
- throw new Error(`Duplicate or empty HTTP API tool name: ${name}`);
137
+ throw new HttpApiAdapterError({
138
+ message: `Duplicate or empty HTTP API tool name: ${name}`
139
+ });
122
140
  names.add(name);
123
141
  const document = Schema.toJsonSchemaDocument(metadata.inputSchema.annotate({ identifier: undefined }));
124
142
  operations.push({
@@ -137,7 +155,10 @@ var makeCatalogue = (api, methods, include) => Effect.try({
137
155
  }
138
156
  return { info: spec.info, operations };
139
157
  },
140
- catch: (cause) => new Error("Failed to build HTTP API adapter catalogue", { cause })
158
+ catch: (cause) => new HttpApiAdapterError({
159
+ message: "Failed to build HTTP API adapter catalogue",
160
+ cause: { cause }.cause
161
+ })
141
162
  });
142
163
  var GeneratedOperation = Schema.declare((value) => value instanceof Function).annotate({ identifier: "GeneratedOperation" });
143
164
  var GeneratedOperationEffect = Schema.declare((value) => Effect.isEffect(value)).annotate({ identifier: "GeneratedOperationEffect" });
@@ -146,15 +167,19 @@ var executeGeneratedOperation = Effect.fn("HttpApiAdapter.executeGeneratedOperat
146
167
  const candidate = Object.entries(Object(group)).find(([name]) => name === operation.endpointIdentifier)?.[1];
147
168
  const endpoint = Schema.decodeUnknownOption(GeneratedOperation)(candidate);
148
169
  if (Option.isNone(endpoint))
149
- return yield* Effect.fail(new Error(`No generated API client operation for ${operation.operation.operationId}`));
150
- const result = Schema.decodeUnknownOption(GeneratedOperationEffect)(endpoint.value({
170
+ return yield* new HttpApiAdapterError({
171
+ message: `No generated API client operation for ${operation.operation.operationId}`
172
+ });
173
+ const result = Schema.decodeOption(GeneratedOperationEffect)(endpoint.value({
151
174
  headers: input.headers ?? {},
152
175
  params: input.params ?? {},
153
176
  query: input.query ?? {},
154
177
  payload: input.body
155
178
  }));
156
179
  if (Option.isNone(result))
157
- return yield* Effect.fail(new Error(`Generated API client operation ${operation.operation.operationId} is invalid`));
180
+ return yield* new HttpApiAdapterError({
181
+ message: `Generated API client operation ${operation.operation.operationId} is invalid`
182
+ });
158
183
  return yield* result.value;
159
184
  });
160
185
 
@@ -172,7 +197,9 @@ class HttpApiAdapter extends Context.Service()("@krak-stack/registry/HttpApiAdap
172
197
  execute: Effect.fn("HttpApiAdapter.execute")(function* (options) {
173
198
  const operation = catalogue.operations.find((entry) => entry.method === options.operation.method && entry.path === options.operation.path && entry.operation.operationId === options.operation.operation.operationId);
174
199
  if (!operation) {
175
- return yield* Effect.fail(new Error("Operation is not in this HTTP API adapter catalogue"));
200
+ return yield* new HttpApiAdapterError({
201
+ message: "Operation is not in this HTTP API adapter catalogue"
202
+ });
176
203
  }
177
204
  return yield* executeGeneratedOperation(client, {
178
205
  operation,
@@ -1,7 +1,16 @@
1
- import { Effect } from "effect";
1
+ import { Effect, Schema } from "effect";
2
2
  import { Command } from "effect/cli";
3
3
  import { HttpApiAdapter } from "./httpapi-adapter.js";
4
+ declare const HttpApiCliError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
5
+ readonly _tag: "HttpApiCliError";
6
+ } & Readonly<A>;
7
+ declare class HttpApiCliError extends HttpApiCliError_base<{
8
+ readonly message: string;
9
+ readonly cause?: unknown;
10
+ }> {
11
+ }
4
12
  export declare const makeHttpApiCli: () => Effect.Effect<{
5
- command: Command.Command<string, {}, {}, unknown, never>;
6
- run: (args: ReadonlyArray<string>) => Effect.Effect<void, unknown, Command.Environment>;
7
- }, Error, HttpApiAdapter>;
13
+ command: Command.Command<string, {}, {}, Error | Schema.SchemaError, never>;
14
+ run: (args: ReadonlyArray<string>) => Effect.Effect<void, Error | Schema.SchemaError | import("effect/cli/CliError").CliError, Command.Environment>;
15
+ }, HttpApiCliError, HttpApiAdapter>;
16
+ export {};
@@ -1,8 +1,10 @@
1
1
  // ../../src/lib/httpapi-cli.ts
2
+ import * as Data2 from "effect/Data";
2
3
  import { Console, Effect as Effect2, Option as Option2, Schema as Schema2, Stream } from "effect";
3
4
  import { Argument, Command, Flag } from "effect/cli";
4
5
 
5
6
  // ../../src/lib/httpapi-adapter.ts
7
+ import * as Data from "effect/Data";
6
8
  import {
7
9
  Context,
8
10
  Effect,
@@ -13,6 +15,9 @@ import {
13
15
  } from "effect";
14
16
  import { HttpClient } from "effect/http";
15
17
  import { HttpApi, HttpApiClient, OpenApi } from "effect/http-api";
18
+
19
+ class HttpApiAdapterError extends Data.TaggedError("HttpApiAdapterError") {
20
+ }
16
21
  var HttpApiMethods = [
17
22
  "get",
18
23
  "post",
@@ -49,7 +54,7 @@ var HttpApiOperationResultValue = Schema.suspend(() => Schema.Union([
49
54
  Schema.Null,
50
55
  UndefinedFromNull,
51
56
  Schema.String,
52
- Schema.Number,
57
+ Schema.Finite,
53
58
  Schema.Boolean,
54
59
  Schema.DateFromString,
55
60
  Schema.Uint8ArrayFromBase64,
@@ -60,9 +65,15 @@ var HttpApiOperationResult = Schema.Union([
60
65
  HttpApiOperationResultValue,
61
66
  Schema.Undefined
62
67
  ]).annotate({ identifier: "HttpApiOperationResult" });
63
- var encodeHttpApiOperationResult = Effect.fn("HttpApiAdapter.encodeOperationResult")((result) => Schema.encodeUnknownEffect(HttpApiOperationResult)(result).pipe(Effect.map((encoded) => encoded ?? null), Effect.mapError((cause) => new Error("HTTP API result is not serializable", { cause }))));
64
- var encodeOperationResult = Effect.fn("HttpApiAdapter.encodeResult")((result, operation) => operation.successSchema ? Schema.encodeUnknownEffect(operation.successSchema)(result).pipe(Effect.flatMap(encodeHttpApiOperationResult), Effect.mapError((cause) => new Error("HTTP API result does not match its success schema", {
65
- cause
68
+ var encodeHttpApiOperationResult = Effect.fn("HttpApiAdapter.encodeOperationResult")((result) => Schema.encodeUnknownEffect(HttpApiOperationResult)(result).pipe(Effect.map((encoded) => encoded ?? null), Effect.mapError((cause) => new HttpApiAdapterError({
69
+ message: "HTTP API result is not serializable",
70
+ cause: { cause }.cause
71
+ }))));
72
+ var encodeOperationResult = Effect.fn("HttpApiAdapter.encodeResult")((result, operation) => operation.successSchema ? Schema.encodeUnknownEffect(operation.successSchema)(result).pipe(Effect.flatMap(encodeHttpApiOperationResult), Effect.mapError((cause) => new HttpApiAdapterError({
73
+ message: "HTTP API result does not match its success schema",
74
+ cause: {
75
+ cause
76
+ }.cause
66
77
  }))) : encodeHttpApiOperationResult(result));
67
78
  var reflectedSchema = (schema) => Schema.make(schema.ast);
68
79
  var sanitizeHttpName = (name) => name.replace(/[^a-zA-Z0-9_-]/g, "_").replace(/_+/g, "_").replace(/^_+|_+$/g, "");
@@ -70,7 +81,9 @@ var httpApiToolName = (entry) => (entry.operation.operationId || `${entry.method
70
81
  var makeCatalogue = (api, methods, include) => Effect.try({
71
82
  try: () => {
72
83
  if (!HttpApi.isHttpApi(api))
73
- throw new Error("HttpApiAdapter requires a valid HttpApi");
84
+ throw new HttpApiAdapterError({
85
+ message: "HttpApiAdapter requires a valid HttpApi"
86
+ });
74
87
  const spec = OpenApi.fromApi(api);
75
88
  const reflected = new Map;
76
89
  HttpApi.reflect(api, {
@@ -80,7 +93,9 @@ var makeCatalogue = (api, methods, include) => Effect.try({
80
93
  onEndpoint: ({ endpoint, group, successes }) => {
81
94
  const operationId = Context.getOrElse(endpoint.annotations, OpenApi.Identifier, () => group.topLevel ? endpoint.identifier : `${group.identifier}.${endpoint.identifier}`);
82
95
  if (reflected.has(operationId))
83
- throw new Error(`Duplicate HTTP API operation ID: ${operationId}`);
96
+ throw new HttpApiAdapterError({
97
+ message: `Duplicate HTTP API operation ID: ${operationId}`
98
+ });
84
99
  const fields = {};
85
100
  if (endpoint.params)
86
101
  fields.params = Schema.toType(reflectedSchema(endpoint.params));
@@ -119,10 +134,14 @@ var makeCatalogue = (api, methods, include) => Effect.try({
119
134
  continue;
120
135
  const metadata = entry.operation.operationId ? reflected.get(entry.operation.operationId) : undefined;
121
136
  if (!metadata)
122
- throw new Error(`Missing endpoint schema for ${entry.operation.operationId}`);
137
+ throw new HttpApiAdapterError({
138
+ message: `Missing endpoint schema for ${entry.operation.operationId}`
139
+ });
123
140
  const name = httpApiToolName(entry);
124
141
  if (!name || names.has(name))
125
- throw new Error(`Duplicate or empty HTTP API tool name: ${name}`);
142
+ throw new HttpApiAdapterError({
143
+ message: `Duplicate or empty HTTP API tool name: ${name}`
144
+ });
126
145
  names.add(name);
127
146
  const document = Schema.toJsonSchemaDocument(metadata.inputSchema.annotate({ identifier: undefined }));
128
147
  operations.push({
@@ -141,7 +160,10 @@ var makeCatalogue = (api, methods, include) => Effect.try({
141
160
  }
142
161
  return { info: spec.info, operations };
143
162
  },
144
- catch: (cause) => new Error("Failed to build HTTP API adapter catalogue", { cause })
163
+ catch: (cause) => new HttpApiAdapterError({
164
+ message: "Failed to build HTTP API adapter catalogue",
165
+ cause: { cause }.cause
166
+ })
145
167
  });
146
168
  var GeneratedOperation = Schema.declare((value) => value instanceof Function).annotate({ identifier: "GeneratedOperation" });
147
169
  var GeneratedOperationEffect = Schema.declare((value) => Effect.isEffect(value)).annotate({ identifier: "GeneratedOperationEffect" });
@@ -150,15 +172,19 @@ var executeGeneratedOperation = Effect.fn("HttpApiAdapter.executeGeneratedOperat
150
172
  const candidate = Object.entries(Object(group)).find(([name]) => name === operation.endpointIdentifier)?.[1];
151
173
  const endpoint = Schema.decodeUnknownOption(GeneratedOperation)(candidate);
152
174
  if (Option.isNone(endpoint))
153
- return yield* Effect.fail(new Error(`No generated API client operation for ${operation.operation.operationId}`));
154
- const result = Schema.decodeUnknownOption(GeneratedOperationEffect)(endpoint.value({
175
+ return yield* new HttpApiAdapterError({
176
+ message: `No generated API client operation for ${operation.operation.operationId}`
177
+ });
178
+ const result = Schema.decodeOption(GeneratedOperationEffect)(endpoint.value({
155
179
  headers: input.headers ?? {},
156
180
  params: input.params ?? {},
157
181
  query: input.query ?? {},
158
182
  payload: input.body
159
183
  }));
160
184
  if (Option.isNone(result))
161
- return yield* Effect.fail(new Error(`Generated API client operation ${operation.operation.operationId} is invalid`));
185
+ return yield* new HttpApiAdapterError({
186
+ message: `Generated API client operation ${operation.operation.operationId} is invalid`
187
+ });
162
188
  return yield* result.value;
163
189
  });
164
190
 
@@ -176,7 +202,9 @@ class HttpApiAdapter extends Context.Service()("@krak-stack/registry/HttpApiAdap
176
202
  execute: Effect.fn("HttpApiAdapter.execute")(function* (options) {
177
203
  const operation = catalogue.operations.find((entry) => entry.method === options.operation.method && entry.path === options.operation.path && entry.operation.operationId === options.operation.operation.operationId);
178
204
  if (!operation) {
179
- return yield* Effect.fail(new Error("Operation is not in this HTTP API adapter catalogue"));
205
+ return yield* new HttpApiAdapterError({
206
+ message: "Operation is not in this HTTP API adapter catalogue"
207
+ });
180
208
  }
181
209
  return yield* executeGeneratedOperation(client, {
182
210
  operation,
@@ -189,6 +217,8 @@ class HttpApiAdapter extends Context.Service()("@krak-stack/registry/HttpApiAdap
189
217
  }
190
218
 
191
219
  // ../../src/lib/httpapi-cli.ts
220
+ class HttpApiCliError extends Data2.TaggedError("HttpApiCliError") {
221
+ }
192
222
  var CliJsonSchema = Schema2.Struct({
193
223
  type: Schema2.optional(Schema2.Union([Schema2.String, Schema2.Array(Schema2.String)])),
194
224
  description: Schema2.optional(Schema2.String),
@@ -236,7 +266,9 @@ var httpApiCliOperationGroups = (operations) => {
236
266
  const group = groups.get(operation.groupName);
237
267
  if (group) {
238
268
  if (group.operations.some((entry) => entry.name === operation.name)) {
239
- throw new Error(`Duplicate CLI command ${operation.groupName} ${operation.name}`);
269
+ throw new HttpApiCliError({
270
+ message: `Duplicate CLI command ${operation.groupName} ${operation.name}`
271
+ });
240
272
  }
241
273
  group.operations.push(operation);
242
274
  } else {
@@ -274,7 +306,7 @@ var schemaType = (schema) => {
274
306
  return schemaType(effectiveSchema(schema));
275
307
  };
276
308
  var schemaEnum = (schema) => Schema2.decodeUnknownOption(Schema2.Array(Schema2.String))(effectiveSchema(schema).enum).pipe(Option2.getOrElse(() => []));
277
- var jsonFlag = (name) => Flag.String(name).pipe(Flag.mapTryCatch((value) => Schema2.decodeUnknownSync(JsonFromString)(value), () => `--${name} must be valid JSON`));
309
+ var jsonFlag = (name) => Flag.String(name).pipe(Flag.mapTryCatch((value) => Schema2.decodeSync(JsonFromString)(value), () => `--${name} must be valid JSON`));
278
310
  var primitiveFlag = (name, schema, required) => {
279
311
  const type = schemaType(schema);
280
312
  const choices = schemaEnum(schema);
@@ -370,7 +402,9 @@ var operationInputs = (operation) => {
370
402
  return drafts.map((draft, index) => {
371
403
  const optionName = draft.location === "params" || preferredCounts.get(draft.preferredName) === 1 ? draft.preferredName : `${draft.location.replace(/s$/, "")}-${draft.preferredName}`;
372
404
  if (draft.location !== "params" && optionNames.has(optionName)) {
373
- throw new Error(`Duplicate CLI option --${optionName} for ${operation.groupName} ${operation.name}`);
405
+ throw new HttpApiCliError({
406
+ message: `Duplicate CLI option --${optionName} for ${operation.groupName} ${operation.name}`
407
+ });
374
408
  }
375
409
  optionNames.add(optionName);
376
410
  return {
@@ -386,7 +420,10 @@ var HttpApiCliResultStream = Schema2.declare((value) => Stream.isStream(value)).
386
420
  var printHttpApiCliResult = Effect2.fn("HttpApiCli.printResult")(function* (response, operation, client) {
387
421
  const stream = Schema2.decodeUnknownOption(HttpApiCliResultStream)(response);
388
422
  if (stream._tag === "Some") {
389
- return yield* stream.value.pipe(Stream.mapEffect((event) => client.encodeResult(event, operation)), Stream.runForEach((event) => print(JSON.stringify(event))));
423
+ return yield* stream.value.pipe(Stream.mapError((cause) => new HttpApiCliError({
424
+ message: cause instanceof Error ? cause.message : "HTTP API result stream failed",
425
+ cause
426
+ })), Stream.mapEffect((event) => client.encodeResult(event, operation)), Stream.runForEach((event) => print(JSON.stringify(event))));
390
427
  }
391
428
  const encoded = yield* client.encodeResult(response, operation);
392
429
  return yield* print(JSON.stringify(encoded, null, 2) ?? "null");
@@ -419,7 +456,9 @@ var callOperation = Effect2.fn("HttpApiCli.callOperation")(function* (operation,
419
456
  }
420
457
  if (bodyInput !== undefined)
421
458
  rawInput.body = bodyInput;
422
- const input = yield* Schema2.decodeUnknownEffect(operation.inputSchema)(rawInput).pipe(Effect2.mapError((error) => new Error(`Invalid input for ${operation.groupName} ${operation.name}: ${error.message}`)));
459
+ const input = yield* Schema2.decodeEffect(operation.inputSchema)(rawInput).pipe(Effect2.mapError((error) => new HttpApiCliError({
460
+ message: `Invalid input for ${operation.groupName} ${operation.name}: ${error.message}`
461
+ })));
423
462
  const response = yield* client.execute({ operation, input });
424
463
  return yield* printHttpApiCliResult(response, operation, client);
425
464
  });
@@ -439,7 +478,7 @@ var operationCommand = (operation, client) => Effect2.sync(() => {
439
478
  }
440
479
  ]));
441
480
  });
442
- var groupCommand = (group, client) => Effect2.all(group.operations.map((operation) => operationCommand(operation, client))).pipe(Effect2.map((operationCommands) => Command.make(group.name).pipe(Command.withDescription(group.title), Command.withSubcommands([
481
+ var groupCommand = (group, client) => Effect2.forEach(group.operations, (operation) => operationCommand(operation, client)).pipe(Effect2.map((operationCommands) => Command.make(group.name).pipe(Command.withDescription(group.title), Command.withSubcommands([
443
482
  groupListCommand(group),
444
483
  ...operationCommands
445
484
  ]))));
@@ -449,9 +488,12 @@ var makeHttpApiCliCommand = Effect2.fn("HttpApiCli.makeCommand")(function* () {
449
488
  const name = fallbackName(spec.info.title, "api");
450
489
  const groups = yield* Effect2.try({
451
490
  try: () => httpApiCliOperationGroups(spec.operations.map(toCliOperation)),
452
- catch: (error) => error instanceof Error ? error : new Error(String(error))
491
+ catch: (error) => new HttpApiCliError({
492
+ message: error instanceof Error ? error.message : String(error),
493
+ cause: error
494
+ })
453
495
  });
454
- const groupCommands = yield* Effect2.all(groups.map((group) => groupCommand(group, client)));
496
+ const groupCommands = yield* Effect2.forEach(groups, (group) => groupCommand(group, client));
455
497
  return Command.make(name).pipe(Command.withDescription(spec.info.description ?? spec.info.title), Command.withSubcommands([listCommand(groups), ...groupCommands]));
456
498
  });
457
499
  export {