vocs 2.1.6 → 2.1.8

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 (54) hide show
  1. package/dist/internal/openapi/openapi.d.ts +7 -0
  2. package/dist/internal/openapi/openapi.d.ts.map +1 -1
  3. package/dist/internal/openapi/openapi.js.map +1 -1
  4. package/dist/internal/openapi/registry.d.ts.map +1 -1
  5. package/dist/internal/openapi/registry.js +5 -2
  6. package/dist/internal/openapi/registry.js.map +1 -1
  7. package/dist/internal/openapi/sample.d.ts +7 -1
  8. package/dist/internal/openapi/sample.d.ts.map +1 -1
  9. package/dist/internal/openapi/sample.js +6 -1
  10. package/dist/internal/openapi/sample.js.map +1 -1
  11. package/dist/react/OpenApi.d.ts +2 -0
  12. package/dist/react/OpenApi.d.ts.map +1 -1
  13. package/dist/react/OpenApi.js +2 -0
  14. package/dist/react/OpenApi.js.map +1 -1
  15. package/dist/react/internal/openapi/CodeSample.client.d.ts +8 -0
  16. package/dist/react/internal/openapi/CodeSample.client.d.ts.map +1 -1
  17. package/dist/react/internal/openapi/CodeSample.client.js +20 -14
  18. package/dist/react/internal/openapi/CodeSample.client.js.map +1 -1
  19. package/dist/react/internal/openapi/Operation.d.ts +13 -0
  20. package/dist/react/internal/openapi/Operation.d.ts.map +1 -1
  21. package/dist/react/internal/openapi/Operation.js +3 -3
  22. package/dist/react/internal/openapi/Operation.js.map +1 -1
  23. package/dist/react/internal/openapi/OperationStandalone.d.ts +56 -0
  24. package/dist/react/internal/openapi/OperationStandalone.d.ts.map +1 -0
  25. package/dist/react/internal/openapi/OperationStandalone.js +41 -0
  26. package/dist/react/internal/openapi/OperationStandalone.js.map +1 -0
  27. package/dist/react/internal/openapi/PlaygroundStandalone.d.ts +55 -0
  28. package/dist/react/internal/openapi/PlaygroundStandalone.d.ts.map +1 -0
  29. package/dist/react/internal/openapi/PlaygroundStandalone.js +49 -0
  30. package/dist/react/internal/openapi/PlaygroundStandalone.js.map +1 -0
  31. package/dist/react/internal/openapi/find-operation.d.ts +18 -0
  32. package/dist/react/internal/openapi/find-operation.d.ts.map +1 -0
  33. package/dist/react/internal/openapi/find-operation.js +22 -0
  34. package/dist/react/internal/openapi/find-operation.js.map +1 -0
  35. package/dist/server/openapi/assets.generated.js +1 -1
  36. package/dist/server/openapi/assets.generated.js.map +1 -1
  37. package/dist/waku/internal/patches/router.d.ts.map +1 -1
  38. package/dist/waku/internal/patches/router.js +8 -3
  39. package/dist/waku/internal/patches/router.js.map +1 -1
  40. package/package.json +1 -1
  41. package/src/internal/openapi/openapi.ts +7 -0
  42. package/src/internal/openapi/registry.test.ts +22 -0
  43. package/src/internal/openapi/registry.ts +5 -2
  44. package/src/internal/openapi/sample.test.ts +13 -0
  45. package/src/internal/openapi/sample.ts +16 -1
  46. package/src/react/OpenApi.tsx +2 -0
  47. package/src/react/internal/openapi/CodeSample.client.tsx +34 -24
  48. package/src/react/internal/openapi/Operation.tsx +23 -2
  49. package/src/react/internal/openapi/OperationStandalone.tsx +100 -0
  50. package/src/react/internal/openapi/PlaygroundStandalone.tsx +111 -0
  51. package/src/react/internal/openapi/find-operation.test.ts +49 -0
  52. package/src/react/internal/openapi/find-operation.ts +38 -0
  53. package/src/server/openapi/assets.generated.ts +1 -1
  54. package/src/waku/internal/patches/router.ts +7 -3
@@ -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,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,4CAAiC,gBAAW,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAC3D,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,MAAM,OAAO,GAAG,WAAW,CAAC,SAAS,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE;QACzD,eAAe,EAAE,KAAK,CAAC,eAAe;KACvC,CAAC,CAAA;IACF,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IACrC,MAAM,SAAS,GAAG,eAAe,CAAC,SAAS,CAAC,CAAA;IAE5C,OAAO,CACL,gDACE,KAAC,kBAAkB,IAAC,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,YACnD,KAAC,UAAU,IACT,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,KAAK,CAAC,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"}