vocs 2.1.5 → 2.1.7

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 (45) hide show
  1. package/dist/internal/openapi/sample.d.ts +7 -1
  2. package/dist/internal/openapi/sample.d.ts.map +1 -1
  3. package/dist/internal/openapi/sample.js +6 -1
  4. package/dist/internal/openapi/sample.js.map +1 -1
  5. package/dist/react/OpenApi.d.ts +2 -0
  6. package/dist/react/OpenApi.d.ts.map +1 -1
  7. package/dist/react/OpenApi.js +2 -0
  8. package/dist/react/OpenApi.js.map +1 -1
  9. package/dist/react/internal/Sidebar.d.ts.map +1 -1
  10. package/dist/react/internal/Sidebar.js +32 -3
  11. package/dist/react/internal/Sidebar.js.map +1 -1
  12. package/dist/react/internal/openapi/CodeSample.client.d.ts +8 -0
  13. package/dist/react/internal/openapi/CodeSample.client.d.ts.map +1 -1
  14. package/dist/react/internal/openapi/CodeSample.client.js +20 -14
  15. package/dist/react/internal/openapi/CodeSample.client.js.map +1 -1
  16. package/dist/react/internal/openapi/Operation.d.ts +13 -0
  17. package/dist/react/internal/openapi/Operation.d.ts.map +1 -1
  18. package/dist/react/internal/openapi/Operation.js +3 -3
  19. package/dist/react/internal/openapi/Operation.js.map +1 -1
  20. package/dist/react/internal/openapi/OperationStandalone.d.ts +56 -0
  21. package/dist/react/internal/openapi/OperationStandalone.d.ts.map +1 -0
  22. package/dist/react/internal/openapi/OperationStandalone.js +41 -0
  23. package/dist/react/internal/openapi/OperationStandalone.js.map +1 -0
  24. package/dist/react/internal/openapi/PlaygroundStandalone.d.ts +55 -0
  25. package/dist/react/internal/openapi/PlaygroundStandalone.d.ts.map +1 -0
  26. package/dist/react/internal/openapi/PlaygroundStandalone.js +49 -0
  27. package/dist/react/internal/openapi/PlaygroundStandalone.js.map +1 -0
  28. package/dist/react/internal/openapi/find-operation.d.ts +18 -0
  29. package/dist/react/internal/openapi/find-operation.d.ts.map +1 -0
  30. package/dist/react/internal/openapi/find-operation.js +22 -0
  31. package/dist/react/internal/openapi/find-operation.js.map +1 -0
  32. package/dist/server/openapi/assets.generated.js +1 -1
  33. package/dist/server/openapi/assets.generated.js.map +1 -1
  34. package/package.json +1 -1
  35. package/src/internal/openapi/sample.test.ts +13 -0
  36. package/src/internal/openapi/sample.ts +16 -1
  37. package/src/react/OpenApi.tsx +2 -0
  38. package/src/react/internal/Sidebar.tsx +52 -22
  39. package/src/react/internal/openapi/CodeSample.client.tsx +34 -24
  40. package/src/react/internal/openapi/Operation.tsx +23 -2
  41. package/src/react/internal/openapi/OperationStandalone.tsx +100 -0
  42. package/src/react/internal/openapi/PlaygroundStandalone.tsx +111 -0
  43. package/src/react/internal/openapi/find-operation.test.ts +49 -0
  44. package/src/react/internal/openapi/find-operation.ts +38 -0
  45. package/src/server/openapi/assets.generated.ts +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OperationStandalone.js","sourceRoot":"","sources":["../../../../src/react/internal/openapi/OperationStandalone.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAE3D;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,SAAS,CAAC,KAAsB;IAC9C,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACjC,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IAEzE,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,yDAAqC,CAAA;QACrE,OAAO,CACL,0EACgD,kCAAiB,SAAI,GAAG,EACtE,2CAAgC,gBAAW,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAC1D,CACL,CAAA;IACH,CAAC;IAED,MAAM,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAA;IACvB,IAAI,CAAC,EAAE;QAAE,OAAO,0DAAkC,KAAK,SAAM,CAAA;IAE7D,MAAM,SAAS,GAAG,aAAa,CAAC,EAAE,EAAE,KAAK,CAAC,CAAA;IAC1C,IAAI,CAAC,SAAS;QACZ,OAAO,CACL,8EACqD,KAAK,gBAAW,yCAAwB,aACtF,oCAAmB,WAAK,kCAAiB,SAC5C,CACL,CAAA;IAEH,OAAO,CACL,gDACE,KAAC,kBAAkB,IAAC,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,YACnD,KAAC,aAAa,IACZ,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,EAC1B,YAAY,EAAE,KAAK,CAAC,YAAY,IAAI,CAAC,EACrC,OAAO,EAAE,KAAK,CAAC,OAAO,EACtB,eAAe,EAAE,KAAK,CAAC,eAAe,GACtC,GACiB,GACjB,CACP,CAAA;AACH,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Renders just the interactive request/response code sample for a single
3
+ * OpenAPI operation — the bordered "playground" box (the cURL/response viewer
4
+ * with Copy, "Try", and per-status tabs) that normally sits in the right column
5
+ * of a generated operation page, with none of the surrounding documentation.
6
+ *
7
+ * This is an opt-in component for dropping the playground box into an authored
8
+ * MDX page. For the full operation block (title, parameters, responses, and this
9
+ * box together) use {@link file://./OperationStandalone.tsx `<OpenApi.Operation />`}.
10
+ *
11
+ * The target operation is located by either:
12
+ * - `operationId` — matched against the operation's anchor id (the slugified
13
+ * `operationId` from the spec), or
14
+ * - `method` + `path` — matched against the HTTP method and templated path
15
+ * (e.g. `method="GET" path="/v1/blocks"`).
16
+ *
17
+ * The spec is resolved from `spec` (the OpenAPI mount, e.g. `/api`). When
18
+ * omitted, it defaults to the only configured spec; if multiple specs exist,
19
+ * `spec` is required.
20
+ */
21
+ export declare function Playground(props: Playground.Props): import("react/jsx-runtime").JSX.Element | null;
22
+ export declare namespace Playground {
23
+ type Props = {
24
+ /**
25
+ * OpenAPI mount path identifying which spec to read (e.g. `/api`).
26
+ * Optional when only one spec is configured.
27
+ */
28
+ spec?: string | undefined;
29
+ /**
30
+ * Target operation by its anchor id — the slugified `operationId` from the
31
+ * spec (e.g. `operationId="getBlocks"`). Mutually exclusive with
32
+ * `method` + `path`.
33
+ */
34
+ operationId?: string | undefined;
35
+ /** HTTP method of the target operation (e.g. `GET`). Pairs with `path`. */
36
+ method?: string | undefined;
37
+ /** Templated path of the target operation (e.g. `/v1/blocks`). Pairs with `method`. */
38
+ path?: string | undefined;
39
+ /**
40
+ * Render the clickable schema cross-links in the request/response sample
41
+ * (the hover-highlighted spans/lines that jump to a parameter or property
42
+ * row). Set `false` for a static, non-interactive sample.
43
+ *
44
+ * @default true
45
+ */
46
+ anchors?: boolean | undefined;
47
+ /**
48
+ * Omit query parameters from the generated request sample.
49
+ *
50
+ * @default false
51
+ */
52
+ hideQueryParams?: boolean | undefined;
53
+ };
54
+ }
55
+ //# sourceMappingURL=PlaygroundStandalone.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlaygroundStandalone.d.ts","sourceRoot":"","sources":["../../../../src/react/internal/openapi/PlaygroundStandalone.tsx"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,KAAK,kDAkDjD;AAED,MAAM,CAAC,OAAO,WAAW,UAAU,CAAC;IAClC,KAAK,KAAK,GAAG;QACX;;;WAGG;QACH,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QACzB;;;;WAIG;QACH,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QAChC,2EAA2E;QAC3E,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QAC3B,uFAAuF;QACvF,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QACzB;;;;;;WAMG;QACH,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;QAC7B;;;;WAIG;QACH,eAAe,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;KACtC,CAAA;CACF"}
@@ -0,0 +1,49 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { specs } from 'virtual:vocs/openapi';
3
+ import { codeSamples, responseSamples } from '../../../internal/openapi/sample.js';
4
+ import { CodeSample } from './CodeSample.client.js';
5
+ import { findOperation } from './find-operation.js';
6
+ import { PlaygroundProvider, TestRequestButton } from './Playground.client.js';
7
+ /**
8
+ * Renders just the interactive request/response code sample for a single
9
+ * OpenAPI operation — the bordered "playground" box (the cURL/response viewer
10
+ * with Copy, "Try", and per-status tabs) that normally sits in the right column
11
+ * of a generated operation page, with none of the surrounding documentation.
12
+ *
13
+ * This is an opt-in component for dropping the playground box into an authored
14
+ * MDX page. For the full operation block (title, parameters, responses, and this
15
+ * box together) use {@link file://./OperationStandalone.tsx `<OpenApi.Operation />`}.
16
+ *
17
+ * The target operation is located by either:
18
+ * - `operationId` — matched against the operation's anchor id (the slugified
19
+ * `operationId` from the spec), or
20
+ * - `method` + `path` — matched against the HTTP method and templated path
21
+ * (e.g. `method="GET" path="/v1/blocks"`).
22
+ *
23
+ * The spec is resolved from `spec` (the OpenAPI mount, e.g. `/api`). When
24
+ * omitted, it defaults to the only configured spec; if multiple specs exist,
25
+ * `spec` is required.
26
+ */
27
+ export function Playground(props) {
28
+ const mounts = Object.keys(specs);
29
+ const mount = props.spec ?? (mounts.length === 1 ? mounts[0] : undefined);
30
+ if (!mount) {
31
+ if (mounts.length === 0)
32
+ return _jsx("p", { children: "No OpenAPI spec is configured." });
33
+ return (_jsxs("p", { children: ["Multiple OpenAPI specs are configured. Pass a ", _jsx("code", { children: "spec" }), " to", ' ', _jsx("code", { children: "<Playground />" }), " (one of: ", mounts.join(', '), ")."] }));
34
+ }
35
+ const ir = specs[mount];
36
+ if (!ir)
37
+ return _jsxs("p", { children: ["No OpenAPI spec is mounted at ", mount, "."] });
38
+ const operation = findOperation(ir, props);
39
+ if (!operation)
40
+ return (_jsxs("p", { children: ["No matching operation found in the API mounted at ", mount, ". Pass an ", _jsx("code", { children: "operationId" }), ", or a ", _jsx("code", { children: "method" }), " and ", _jsx("code", { children: "path" }), "."] }));
41
+ const samples = codeSamples(operation, ir.servers[0]?.url, {
42
+ hideQueryParams: props.hideQueryParams,
43
+ });
44
+ if (samples.length === 0)
45
+ return null;
46
+ const responses = responseSamples(operation);
47
+ return (_jsx("div", { "data-v-openapi": true, children: _jsx(PlaygroundProvider, { client: ir.client, mount: ir.path, children: _jsx(CodeSample, { samples: samples, responses: responses, anchors: props.anchors, action: _jsx(TestRequestButton, { method: operation.method, path: operation.path, example: operation.rpcExample }) }) }) }));
48
+ }
49
+ //# sourceMappingURL=PlaygroundStandalone.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlaygroundStandalone.js","sourceRoot":"","sources":["../../../../src/react/internal/openapi/PlaygroundStandalone.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAC5C,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAA;AAClF,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE9E;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,UAAU,CAAC,KAAuB;IAChD,MAAM,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C,OAAO,EACtB,MAAM,EACJ,KAAC,iBAAiB,IAChB,MAAM,EAAE,SAAS,CAAC,MAAM,EACxB,IAAI,EAAE,SAAS,CAAC,IAAI,EACpB,OAAO,EAAE,SAAS,CAAC,UAAU,GAC7B,GAEJ,GACiB,GACjB,CACP,CAAA;AACH,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { Ir, IrOperation } from '../../../internal/openapi/parser.js';
2
+ /**
3
+ * Locates a single operation within a parsed {@link Ir}, by either its
4
+ * `operationId` (matched against the operation's anchor id — the slugified
5
+ * `operationId` from the spec) or an exact `method` + `path` pair.
6
+ *
7
+ * Shared by the public `<OpenApi.Operation />` component so the matching logic
8
+ * stays free of the `virtual:vocs/openapi` module and is unit-testable.
9
+ */
10
+ export declare function findOperation(ir: Ir, target: findOperation.Target): IrOperation | undefined;
11
+ export declare namespace findOperation {
12
+ type Target = {
13
+ operationId?: string | undefined;
14
+ method?: string | undefined;
15
+ path?: string | undefined;
16
+ };
17
+ }
18
+ //# sourceMappingURL=find-operation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-operation.d.ts","sourceRoot":"","sources":["../../../../src/react/internal/openapi/find-operation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAA;AAE1E;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,aAAa,CAAC,MAAM,GAAG,WAAW,GAAG,SAAS,CAkB3F;AAED,MAAM,CAAC,OAAO,WAAW,aAAa,CAAC;IACrC,KAAK,MAAM,GAAG;QACZ,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QAChC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QAC3B,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAC1B,CAAA;CACF"}
@@ -0,0 +1,22 @@
1
+ import { slug } from '../../../internal/openapi/anchors.js';
2
+ /**
3
+ * Locates a single operation within a parsed {@link Ir}, by either its
4
+ * `operationId` (matched against the operation's anchor id — the slugified
5
+ * `operationId` from the spec) or an exact `method` + `path` pair.
6
+ *
7
+ * Shared by the public `<OpenApi.Operation />` component so the matching logic
8
+ * stays free of the `virtual:vocs/openapi` module and is unit-testable.
9
+ */
10
+ export function findOperation(ir, target) {
11
+ const operations = ir.groups.flatMap((group) => group.operations);
12
+ if (target.operationId) {
13
+ const id = slug(target.operationId);
14
+ return operations.find((operation) => operation.id === target.operationId || operation.id === id);
15
+ }
16
+ if (target.method && target.path) {
17
+ const method = target.method.toUpperCase();
18
+ return operations.find((operation) => operation.method === method && operation.path === target.path);
19
+ }
20
+ return undefined;
21
+ }
22
+ //# sourceMappingURL=find-operation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-operation.js","sourceRoot":"","sources":["../../../../src/react/internal/openapi/find-operation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,sCAAsC,CAAA;AAG3D;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,EAAM,EAAE,MAA4B;IAChE,MAAM,UAAU,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;IAEjE,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;QACvB,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;QACnC,OAAO,UAAU,CAAC,IAAI,CACpB,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,KAAK,MAAM,CAAC,WAAW,IAAI,SAAS,CAAC,EAAE,KAAK,EAAE,CAC1E,CAAA;IACH,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;QACjC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,CAAA;QAC1C,OAAO,UAAU,CAAC,IAAI,CACpB,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,KAAK,MAAM,IAAI,SAAS,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,CAC7E,CAAA;IACH,CAAC;IAED,OAAO,SAAS,CAAA;AAClB,CAAC"}