@powerduck/openapi-request 0.2.2

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.
@@ -0,0 +1,350 @@
1
+ import { E as ExecResult, P as ProtocolName, S as SendResult, O as OperationTarget, a as SendOptions, b as OpenApiDocument, M as ManualSessionOptions, A as AnyManualSession, J as Json, c as ScriptSource, G as GrpcTarget, d as GrpcEndpoint, e as GrpcManualSessionTarget, f as GrpcManualSession } from './types-C9ifzKqk.js';
2
+ export { g as AssertionResult, h as AuthConfig, C as Cloneable, i as CloneableError, j as ConsoleLog, k as CreateWsManualSessionOptions, D as DiscoverAndWriteResult, l as GeneratedOperation, m as GraphQLArg, n as GraphQLFieldInfo, o as GraphQLNamedType, p as GraphQLOptions, q as GraphQLTypeRef, r as GrpcCredentialsOptions, s as GrpcDescriptorSource, t as GrpcDescriptorSourceKind, u as GrpcEvent, v as GrpcEventDirection, w as GrpcManualSessionEvent, x as GrpcManualSessionState, y as GrpcMessageEvent, z as GrpcMetadataEvent, B as GrpcMetadataInput, F as GrpcMetadataOutput, H as GrpcMethodKind, I as GrpcProtoFileSource, K as GrpcReflectionSource, L as GrpcResult, N as GrpcSendOptions, Q as GrpcStatus, R as GrpcStatusEvent, T as GrpcStatusOrigin, U as GrpcTlsOptions, V as GrpcTruncatedReason, W as InitializeSessionInit, X as IntrospectedSchema, Y as IntrospectionResult, Z as JsonRpcOutcome, _ as ManualMessage, $ as ManualSession, a0 as ManualSessionKind, a1 as McpCapability, a2 as McpDiscoveryResult, a3 as McpListing, a4 as McpManualSession, a5 as McpManualSessionOptions, a6 as McpOptions, a7 as McpPrompt, a8 as McpRequestOptions, a9 as McpResource, aa as McpSessionEvent, ab as McpSessionState, ac as McpStdioSessionOptions, ad as McpTerminateOutcome, ae as McpTool, af as McpTransport, ag as ReplayRecord, ah as RequestValues, ai as RequesterOptions, aj as ResolvedGraphQLConfig, ak as ResolvedMcpConfig, al as ResolvedWsConfig, am as ResponseStartInfo, an as RuntimeRunOptions, ao as ScriptConfig, ap as ScriptOutcome, aq as ScriptReport, ar as SessionEventDTO, as as SessionState, at as SessionSubscription, au as StopReason, av as StreamEvent, aw as StreamParserOptions, ax as UnifiedSession, ay as WebSocketOptions, az as WebSocketSessionEvent, aA as WebSocketSessionState, aB as WriteGraphQLOptions, aC as WsManualSession, aD as WsSendOptions, aE as createEventHub, aF as toCloneable } from './types-C9ifzKqk.js';
3
+ import { P as ProtocolAdapter, A as AdapterContext, L as LocatedOperation, E as ExecuteContext } from './protocol-D7sEx8IP.js';
4
+ export { l as locateOperation } from './protocol-D7sEx8IP.js';
5
+ export { HttpAdapter, SseParser } from './protocols/http/index.js';
6
+ export { WebSocketAdapter, createWsManualSession, createWsManualSession as runWebSocketSession, createWsManualSession as wsManualSession } from './protocols/ws/index.js';
7
+ export { GraphQLAdapter, INTROSPECTION_QUERY, discoverAndWriteGraphQLSchema, generateAllOperations, generateOperation, introspectSchema, resolveGraphQLConfig, runGraphQL, writeGraphQLOperations } from './protocols/graphql/index.js';
8
+ export { M as MCP_PROTOCOL_VERSION, a as McpAdapter, c as createHttpMcpTransport, b as createMcpManualSession, d as createMcpStdioSession, e as createStdioMcpTransport, f as discoverAndWriteMcpCapabilities, g as discoverMcpCapabilities, h as generateAllMcpCalls, i as generateMcpCall, j as initializeMcpSession, b as mcpManualSession, r as resolveMcpConfig, k as runMcpManualSession, w as writeMcpOperations } from './index-CsRXyS7O.js';
9
+ import { D as DiscoveryResult } from './credentials-rqEKODvf.js';
10
+ export { a as DescriptorDecodeError, G as GrpcAdapter, b as GrpcDependencyBrokenError, c as GrpcDependencyMissingError, d as GrpcDiscoveredMethod, e as GrpcDiscoveredService, L as LOADER_OPTIONS, R as ReflectionProtocolError, f as ReflectionUnavailableError, g as buildCatalog, h as buildCredentials, i as buildCredentialsAsync, j as buildCredentialsChecked, k as buildCredentialsCheckedAsync, l as buildMessageTemplate, m as decodeFileDescriptorProto, n as decodeFileDescriptorSet, o as deriveIncludeDirsDetailed, p as discoverGrpc, q as fetchDescriptorSet, r as fetchFullDescriptorSet, s as grpcCall, p as grpcDiscover, t as isGrpcAvailable, u as listServices, v as listServicesDetailed, w as loadGrpc, x as requireCapability, y as resolveMethod, z as scanProtoFiles, A as serializeDescriptorSet } from './credentials-rqEKODvf.js';
11
+ import '@grpc/grpc-js';
12
+ import '@grpc/proto-loader';
13
+
14
+ declare class AdapterRegistry {
15
+ private readonly entries;
16
+ private nextSeq;
17
+ register(adapter: ProtocolAdapter<any>): this;
18
+ unregister(name: string): boolean;
19
+ get(name: string): ProtocolAdapter<any> | undefined;
20
+ list(): string[];
21
+ /** Ranked candidates, best first. Useful for diagnostics. */
22
+ rank(ctx: AdapterContext): Array<{
23
+ name: string;
24
+ score: number;
25
+ }>;
26
+ resolve(ctx: AdapterContext): ProtocolAdapter<any>;
27
+ /** Coerce a score into a usable finite number; any fault means "unsupported". */
28
+ private scoreOf;
29
+ }
30
+
31
+ interface ToResponseOptions {
32
+ /** Cap on the size of captured example payloads, in characters. */
33
+ maxExampleChars?: number;
34
+ /** Include a captured example under `content[mediaType].examples`. Defaults to true. */
35
+ includeExamples?: boolean;
36
+ /** Cap on characters retained per non-JSON stream event. Defaults to 200. */
37
+ maxEventPreviewChars?: number;
38
+ }
39
+ /** Convert a single execution result into an OpenAPI 3.2 Response Object. */
40
+ declare function toResponseObject(result: ExecResult, options?: ToResponseOptions): {
41
+ statusCode: string;
42
+ response: any;
43
+ };
44
+ interface WriteBackOptions {
45
+ /** 'merge' unions the new observation into the existing schema. Defaults to 'merge'. */
46
+ strategy?: "merge" | "replace";
47
+ /** Preserve a hand-written description instead of the HTTP reason phrase. Defaults to true. */
48
+ keepExistingDescription?: boolean;
49
+ /** Only write back these status codes. Empty means all. */
50
+ allowedStatusCodes?: string[];
51
+ /** Refuse to touch responses whose schema is a $ref to a shared component. Defaults to true. */
52
+ protectComponentRefs?: boolean;
53
+ /** Overwrite an existing captured example. Defaults to true. */
54
+ overwriteExamples?: boolean;
55
+ requirePassingTests?: boolean;
56
+ }
57
+ /**
58
+ * Merge a response fragment into a copy of the spec.
59
+ * The input document is never mutated.
60
+ *
61
+ * Note: gating on test results is the caller's responsibility; this function
62
+ * writes whatever fragment it is handed.
63
+ */
64
+ declare function writeBackResponse(spec: any, path: string, method: string, fragment: {
65
+ statusCode: string;
66
+ response: any;
67
+ }, options?: WriteBackOptions): any;
68
+
69
+ /**
70
+ * The full-featured debugger entry: adapter registry + protocol dispatch +
71
+ * OpenAPI write-back pipeline, plus `sendMany` and `toCollection`.
72
+ *
73
+ * `createClient` in "./client" is the UI-first surface (prepare/connect/
74
+ * discover); this one stays as the workhorse for scripted flows. Both share
75
+ * the same adapters and the same write-back machinery.
76
+ */
77
+
78
+ interface DebuggerOptions {
79
+ adapters?: ProtocolAdapter<any>[];
80
+ extraAdapters?: ProtocolAdapter<any>[];
81
+ writeBack?: WriteBackOptions;
82
+ response?: ToResponseOptions;
83
+ /**
84
+ * Write back a schema inferred from a truncated stream.
85
+ *
86
+ * @default true
87
+ */
88
+ writeBackTruncated?: boolean;
89
+ }
90
+ interface PlanResult {
91
+ protocol: ProtocolName | string;
92
+ located: LocatedOperation;
93
+ collection?: any;
94
+ environment?: any;
95
+ streaming?: boolean;
96
+ warnings?: string[];
97
+ plan: unknown;
98
+ }
99
+ interface SendManyFailure {
100
+ target: OperationTarget;
101
+ error: string;
102
+ }
103
+ interface SendManyResult {
104
+ spec: any;
105
+ results: Array<SendResult | SendManyFailure>;
106
+ }
107
+ declare function createDebugger(config?: DebuggerOptions): {
108
+ registry: AdapterRegistry;
109
+ toCollection: (spec: any, target: OperationTarget, overrides?: Partial<Omit<SendOptions, "spec" | "target">>) => PlanResult;
110
+ send: (options: SendOptions) => Promise<SendResult>;
111
+ sendMany: (spec: any, targets: Array<{
112
+ target: OperationTarget;
113
+ } & Partial<Omit<SendOptions, "spec" | "target">>>, shared?: Partial<Omit<SendOptions, "spec" | "target">>) => Promise<SendManyResult>;
114
+ };
115
+ type ProtoKit = ReturnType<typeof createDebugger>;
116
+
117
+ /**
118
+ * Decide, from the spec and caller intent, whether the operation is expected
119
+ * to stream. A caller-supplied Accept header wins, then an explicit
120
+ * `x-protocol` extension, then the declared response media types.
121
+ */
122
+ declare function isStreamingOperation(operation: any, values?: {
123
+ header?: Record<string, unknown>;
124
+ }): boolean;
125
+ declare function isSseContentType(contentType?: string): boolean;
126
+ declare function isStreamingContentType(contentType?: string): boolean;
127
+ /**
128
+ * Build an Accept header from the declared response media types.
129
+ *
130
+ * Only successful responses contribute: advertising an error media type such as
131
+ * `application/problem+json` would distort content negotiation. Streaming types
132
+ * are listed first so a server that offers both variants picks the stream.
133
+ */
134
+ declare function acceptHeaderFor(operation: any): string | undefined;
135
+ /**
136
+ * Fire a real probe request and classify the live response as stream or not.
137
+ *
138
+ * The caller keeps ownership of `response` — this is deliberately not a HEAD
139
+ * helper: many streaming servers answer GET with `text/event-stream` but HEAD
140
+ * with an empty 200, so the probe uses the same request the real call will
141
+ * make. UI flows use it to pre-select the renderer before committing to a
142
+ * session.
143
+ */
144
+ declare function probeStreamingResponse(input: RequestInfo | URL, init?: RequestInit): Promise<{
145
+ ok: boolean;
146
+ status: number;
147
+ contentType?: string;
148
+ kind: "none" | "sse" | "ndjson" | "chunked";
149
+ response: Response;
150
+ }>;
151
+
152
+ /** How the UI should render this call. */
153
+ type DisplayMode = "response" | "event-list" | "duplex-session";
154
+ /** Precise streaming taxonomy used to pick a renderer / message schema. */
155
+ type StreamKind = "none" | "sse" | "ndjson" | "chunked" | "websocket" | "graphql-stream" | "grpc-unary" | "grpc-server-stream" | "grpc-client-stream" | "grpc-bidi" | "mcp-http-stream" | "mcp-stdio";
156
+ interface PreparedRequest {
157
+ protocol: string;
158
+ transport: string;
159
+ target?: OperationTarget;
160
+ operation?: any;
161
+ display: {
162
+ mode: DisplayMode;
163
+ };
164
+ stream: {
165
+ kind: StreamKind;
166
+ expected: boolean;
167
+ };
168
+ openapi: {
169
+ extensions: Record<string, unknown>;
170
+ };
171
+ warnings: string[];
172
+ }
173
+ interface CreateClientOptions {
174
+ writeBack?: WriteBackOptions;
175
+ response?: ToResponseOptions;
176
+ }
177
+ declare function createClient(options?: CreateClientOptions): {
178
+ prepare: (sendOptions: SendOptions) => PreparedRequest;
179
+ send: (sendOptions: SendOptions) => Promise<SendResult>;
180
+ sendMany: (spec: OpenApiDocument, targets: Array<{
181
+ target: OperationTarget;
182
+ } & Partial<Omit<SendOptions, "spec" | "target">>>, shared?: Partial<Omit<SendOptions, "spec" | "target">>) => Promise<SendManyResult>;
183
+ connect: (connectOptions: ManualSessionOptions) => AnyManualSession;
184
+ discover: (discoverOptions: any) => Promise<any>;
185
+ writeback: (spec: OpenApiDocument, prepared: PreparedRequest, result: SendResult, writeOptions?: Partial<WriteBackOptions>) => OpenApiDocument;
186
+ dispose: () => void;
187
+ probeStreamingResponse: typeof probeStreamingResponse;
188
+ };
189
+ type ProtoClient = ReturnType<typeof createClient>;
190
+
191
+ /**
192
+ * Unified manual-session entry.
193
+ *
194
+ * `createManualSession(options)` routes by `options.kind` to the matching
195
+ * protocol factory (WebSocket / MCP / gRPC). The factories themselves stay
196
+ * protocol-specific so their richer contracts are preserved; this entry is
197
+ * for callers that want one surface across all three.
198
+ */
199
+
200
+ declare function createManualSession(options: ManualSessionOptions): AnyManualSession;
201
+
202
+ /**
203
+ * Unified error type for the whole toolkit.
204
+ * `code` is a stable machine-readable identifier; `message` is human-facing.
205
+ */
206
+ /**
207
+ * Brand used to identify our errors across module realms. Relying on
208
+ * `instanceof` alone is unsafe: a consumer may end up loading both the ESM and
209
+ * the CJS build, which creates two distinct classes.
210
+ */
211
+ declare const PROTOKIT_ERROR_BRAND: unique symbol;
212
+ declare class ProtoKitError extends Error {
213
+ readonly code: string;
214
+ readonly details?: unknown;
215
+ /** Brand marker; see PROTOKIT_ERROR_BRAND. */
216
+ readonly [PROTOKIT_ERROR_BRAND]: true;
217
+ constructor(message: string, code: string, details?: unknown, options?: {
218
+ cause?: unknown;
219
+ });
220
+ /**
221
+ * Realm-safe replacement for `instanceof ProtoKitError`.
222
+ * Use this everywhere instead of a bare instanceof check.
223
+ */
224
+ static isProtoKitError(value: unknown): value is ProtoKitError;
225
+ /** Plain, serializable projection. Safe to log or send over a wire. */
226
+ toJSON(): {
227
+ name: string;
228
+ code: string;
229
+ message: string;
230
+ details?: unknown;
231
+ };
232
+ }
233
+
234
+ interface InferOptions {
235
+ /** Maximum nesting depth to inspect. Defaults to 12. */
236
+ maxDepth?: number;
237
+ /** Number of array elements sampled when unifying item schemas. Defaults to 20. */
238
+ sampleArrayItems?: number;
239
+ /** Maximum characters retained in string examples. Defaults to 120. */
240
+ maxExampleLength?: number;
241
+ /** Emit example values alongside the inferred schema. Defaults to true. */
242
+ includeExamples?: boolean;
243
+ /** Maximum properties inspected per object. Defaults to 250. */
244
+ maxProperties?: number;
245
+ }
246
+ /**
247
+ * Derive a JSON Schema from an observed runtime value.
248
+ *
249
+ * `null` yields `{ type: "null" }` because it is a real observation, while
250
+ * `undefined` yields `{}` since the absence of a value proves nothing.
251
+ */
252
+ declare function inferSchema(value: Json | undefined, options?: InferOptions, depth?: number): any;
253
+ /** Fold a list of observed values into a single unified schema. */
254
+ declare function inferSchemaFromMany(values: Array<Json | undefined>, options?: InferOptions): any;
255
+
256
+ /**
257
+ * Least-upper-bound merge for two JSON Schemas.
258
+ *
259
+ * The guiding rule is that merging must never lose information a user wrote by
260
+ * hand. Keywords this module does not explicitly understand are carried over
261
+ * verbatim instead of being dropped, because `mergeSchema` is also used to fold
262
+ * a live observation into an author-maintained document.
263
+ */
264
+ /**
265
+ * Merge two JSON Schemas into their least upper bound.
266
+ *
267
+ * Types become a union, object properties are unioned, `required` shrinks to the
268
+ * intersection so optional fields stay optional, and numeric or length bounds
269
+ * widen to cover both inputs. Unknown keywords and `x-` extensions survive.
270
+ */
271
+ declare function mergeSchema(a: any, b: any, depth?: number): any;
272
+
273
+ /**
274
+ * Produce a representative value for a JSON Schema so that required
275
+ * parameters and request bodies are never left empty.
276
+ *
277
+ * Sampling is deterministic: the same schema always yields the same value, which
278
+ * keeps generated requests reproducible across runs. Values respect declared
279
+ * bounds (minimum, maxLength, minItems, ...) so a sample never violates the
280
+ * schema it came from.
281
+ */
282
+ interface SampleOptions {
283
+ /** Maximum recursion depth. Defaults to 12. */
284
+ maxDepth?: number;
285
+ /** Include readOnly properties. Defaults to false. */
286
+ includeReadOnly?: boolean;
287
+ /** Include writeOnly properties. Defaults to true. */
288
+ includeWriteOnly?: boolean;
289
+ }
290
+ declare function sampleFromSchema(schema: any, depth?: number, options?: SampleOptions): any;
291
+
292
+ /**
293
+ * Optional helper script that exposes the last response to subsequent requests.
294
+ * The captured body is truncated, since an environment value is serialized in
295
+ * full on every scope snapshot.
296
+ */
297
+ declare const BUILTIN_CAPTURE_TEST: ScriptSource;
298
+
299
+ interface WriteGrpcOptions {
300
+ pathPrefix?: string;
301
+ }
302
+ declare function writeGrpcOperations(spec: any, discovery: DiscoveryResult, endpoint: GrpcEndpoint, options?: WriteGrpcOptions): any;
303
+ declare function discoverAndWriteGrpcOperations(spec: any, endpoint: GrpcEndpoint, options?: WriteGrpcOptions): Promise<{
304
+ spec: any;
305
+ discovery: DiscoveryResult;
306
+ }>;
307
+ declare class GrpcProtocolAdapter implements ProtocolAdapter<any> {
308
+ readonly name = "grpc";
309
+ private readonly adapter;
310
+ supports(ctx: AdapterContext): number;
311
+ plan(ctx: AdapterContext): {
312
+ target: GrpcTarget;
313
+ environment: {
314
+ name: string;
315
+ values: {
316
+ key: string;
317
+ value: string;
318
+ type: string;
319
+ enabled: boolean;
320
+ }[];
321
+ };
322
+ collection: {
323
+ info: {
324
+ name: string;
325
+ };
326
+ item: {
327
+ name: string;
328
+ request: {
329
+ method: string;
330
+ url: string;
331
+ };
332
+ }[];
333
+ };
334
+ streaming: boolean;
335
+ warnings: string[];
336
+ };
337
+ execute(plan: any, options: SendOptions, _ctx?: ExecuteContext): Promise<ExecResult>;
338
+ }
339
+
340
+ /**
341
+ * Create a manual gRPC session.
342
+ *
343
+ * The factory is synchronous and performs no I/O: descriptor loading (proto
344
+ * files or reflection) happens lazily inside `open()`. This keeps the manual
345
+ * session contract uniform across protocols — construct first, drive later —
346
+ * and avoids a constructor that can throw network errors.
347
+ */
348
+ declare function createGrpcManualSession(target: GrpcManualSessionTarget): GrpcManualSession;
349
+
350
+ export { AdapterContext, AdapterRegistry, AnyManualSession, BUILTIN_CAPTURE_TEST, type CreateClientOptions, type DebuggerOptions, type DisplayMode, ExecResult, ExecuteContext, DiscoveryResult as GrpcDiscoveryResult, GrpcEndpoint, GrpcManualSession, GrpcManualSessionTarget, GrpcProtocolAdapter, GrpcTarget, Json, LocatedOperation, ManualSessionOptions, OpenApiDocument, OperationTarget, type PlanResult, type PreparedRequest, type ProtoClient, type ProtoKit, ProtoKitError, ProtocolAdapter, ProtocolName, ScriptSource, type SendManyFailure, type SendManyResult, SendOptions, SendResult, type StreamKind, type ToResponseOptions, type WriteBackOptions, acceptHeaderFor, createClient, createDebugger, createGrpcManualSession, createManualSession, discoverAndWriteGrpcOperations, createGrpcManualSession as grpcManualSession, inferSchema, inferSchemaFromMany, isSseContentType, isStreamingContentType, isStreamingOperation, mergeSchema, probeStreamingResponse, sampleFromSchema, toResponseObject, writeBackResponse, writeGrpcOperations };