@flock/wirespec 0.19.0-RC.3 → 0.19.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 (83) hide show
  1. package/arrow-arrow-atomic.mjs +12 -12
  2. package/arrow-arrow-core.mjs +156 -156
  3. package/clikt-clikt-mordant.mjs +80 -80
  4. package/clikt-clikt-mordant.mjs.map +1 -1
  5. package/clikt-clikt.mjs +1547 -1547
  6. package/clikt-clikt.mjs.map +1 -1
  7. package/colormath-root-colormath.mjs +444 -444
  8. package/kotlin-kotlin-stdlib.mjs +2354 -5062
  9. package/kotlin-kotlin-stdlib.mjs.map +1 -1
  10. package/kotlin-openapi-bindings.mjs +20865 -6871
  11. package/kotlin-openapi-bindings.mjs.map +1 -1
  12. package/kotlin-rgxgen.mjs +1806 -1806
  13. package/kotlinx-io-kotlinx-io-core.mjs +432 -432
  14. package/kotlinx-io-kotlinx-io-core.mjs.map +1 -1
  15. package/kotlinx-serialization-kotlinx-serialization-core.mjs +2213 -2050
  16. package/kotlinx-serialization-kotlinx-serialization-core.mjs.map +1 -1
  17. package/kotlinx-serialization-kotlinx-serialization-json.mjs +1947 -1472
  18. package/kotlinx-serialization-kotlinx-serialization-json.mjs.map +1 -1
  19. package/mordant-mordant.mjs +1333 -1333
  20. package/package.json +14 -9
  21. package/wirespec-lsp.mjs +7 -0
  22. package/wirespec-msw.d.ts +53 -0
  23. package/wirespec-msw.mjs +108 -0
  24. package/wirespec-src-compiler-core.mjs +1752 -1688
  25. package/wirespec-src-compiler-core.mjs.map +1 -1
  26. package/wirespec-src-compiler-emitters-java.mjs +453 -417
  27. package/wirespec-src-compiler-emitters-java.mjs.map +1 -1
  28. package/wirespec-src-compiler-emitters-kotlin.mjs +440 -341
  29. package/wirespec-src-compiler-emitters-kotlin.mjs.map +1 -1
  30. package/wirespec-src-compiler-emitters-python.mjs +369 -370
  31. package/wirespec-src-compiler-emitters-python.mjs.map +1 -1
  32. package/wirespec-src-compiler-emitters-rust.mjs +447 -424
  33. package/wirespec-src-compiler-emitters-rust.mjs.map +1 -1
  34. package/wirespec-src-compiler-emitters-scala.mjs +172 -173
  35. package/wirespec-src-compiler-emitters-scala.mjs.map +1 -1
  36. package/wirespec-src-compiler-emitters-typescript.mjs +470 -439
  37. package/wirespec-src-compiler-emitters-typescript.mjs.map +1 -1
  38. package/wirespec-src-compiler-emitters-wirespec.mjs +87 -87
  39. package/wirespec-src-compiler-emitters-wirespec.mjs.map +1 -1
  40. package/wirespec-src-compiler-ir.mjs +3835 -3885
  41. package/wirespec-src-compiler-ir.mjs.map +1 -1
  42. package/wirespec-src-compiler-lib.mjs +418 -418
  43. package/wirespec-src-compiler-lib.mjs.map +1 -1
  44. package/wirespec-src-converter-avro.mjs +510 -510
  45. package/wirespec-src-converter-avro.mjs.map +1 -1
  46. package/wirespec-src-converter-openapi.mjs +1584 -1510
  47. package/wirespec-src-converter-openapi.mjs.map +1 -1
  48. package/wirespec-src-ide-lsp.mjs +4928 -0
  49. package/wirespec-src-ide-lsp.mjs.map +1 -0
  50. package/wirespec-src-plugin-arguments.mjs +183 -183
  51. package/wirespec-src-plugin-arguments.mjs.map +1 -1
  52. package/wirespec-src-plugin-cli.mjs +106 -106
  53. package/wirespec-src-plugin-npm.d.mts +2 -11
  54. package/wirespec-src-plugin-npm.mjs +47 -42
  55. package/wirespec-src-plugin-npm.mjs.map +1 -1
  56. package/wirespec-src-tools-generator.mjs +53 -53
  57. package/wirespec-src-tools-generator.mjs.map +1 -1
  58. package/Kotlin-DateTime-library-kotlinx-datetime.mjs +0 -4
  59. package/Kotlin-DateTime-library-kotlinx-datetime.mjs.map +0 -1
  60. package/kotest-kotest-assertions-kotest-assertions-core.mjs +0 -4
  61. package/kotest-kotest-assertions-kotest-assertions-core.mjs.map +0 -1
  62. package/kotest-kotest-assertions-kotest-assertions-shared.mjs +0 -4
  63. package/kotest-kotest-assertions-kotest-assertions-shared.mjs.map +0 -1
  64. package/kotest-kotest-common.mjs +0 -56
  65. package/kotest-kotest-common.mjs.map +0 -1
  66. package/kotest-kotest-framework-kotest-framework-engine.mjs +0 -4
  67. package/kotest-kotest-framework-kotest-framework-engine.mjs.map +0 -1
  68. package/kotest-kotest-property-kotest-property-datetime.mjs +0 -4
  69. package/kotest-kotest-property-kotest-property-datetime.mjs.map +0 -1
  70. package/kotest-kotest-property.mjs +0 -2400
  71. package/kotest-kotest-property.mjs.map +0 -1
  72. package/kotest-property-arbs.mjs +0 -4
  73. package/kotest-property-arbs.mjs.map +0 -1
  74. package/kotlinx-coroutines-test.mjs +0 -4
  75. package/kotlinx-coroutines-test.mjs.map +0 -1
  76. package/wirespec-generator.d.ts +0 -52
  77. package/wirespec-generator.mjs +0 -9
  78. package/wirespec-src-integration-kotest.mjs +0 -1455
  79. package/wirespec-src-integration-kotest.mjs.map +0 -1
  80. package/xmlutil-core.mjs +0 -4
  81. package/xmlutil-core.mjs.map +0 -1
  82. package/xmlutil-serialization.mjs +0 -4
  83. package/xmlutil-serialization.mjs.map +0 -1
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@flock/wirespec",
3
- "version": "0.19.0-RC.3",
3
+ "version": "0.19.1",
4
4
  "main": "wirespec-src-plugin-npm.mjs",
5
5
  "types": "wirespec-src-plugin-npm.d.mts",
6
6
  "devDependencies": {
7
7
  "typescript": "5.9.3"
8
8
  },
9
- "dependencies": {
10
- "@js-joda/core": "3.2.0",
11
- "format-util": "^1.0.5"
9
+ "dependencies": {},
10
+ "peerDependencies": {
11
+ "msw": "^2.0.0"
12
12
  },
13
- "peerDependencies": {},
14
13
  "optionalDependencies": {},
15
14
  "bundledDependencies": [],
16
15
  "bin": {
17
- "wirespec": "wirespec-bin.mjs"
16
+ "wirespec": "wirespec-bin.mjs",
17
+ "wirespec-lsp": "wirespec-lsp.mjs"
18
18
  },
19
19
  "description": "Simplify your API development workflows, accelerate implementation, and guarantee strict adherence to defined contract specifications",
20
20
  "exports": {
@@ -30,9 +30,14 @@
30
30
  "types": "./wirespec-serialization.d.ts",
31
31
  "default": "./wirespec-serialization.mjs"
32
32
  },
33
- "./generator": {
34
- "types": "./wirespec-generator.d.ts",
35
- "default": "./wirespec-generator.mjs"
33
+ "./msw": {
34
+ "types": "./wirespec-msw.d.ts",
35
+ "default": "./wirespec-msw.mjs"
36
+ }
37
+ },
38
+ "peerDependenciesMeta": {
39
+ "msw": {
40
+ "optional": true
36
41
  }
37
42
  },
38
43
  "repository": {
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import { startLsp } from "./wirespec-src-plugin-npm.mjs";
3
+
4
+ const args = process.argv.slice(2);
5
+ const useNodeIpc = args.includes("--node-ipc");
6
+
7
+ startLsp(useNodeIpc);
@@ -0,0 +1,53 @@
1
+ import type { RequestHandler } from 'msw'
2
+ import type { Serialization } from './wirespec-serialization'
3
+
4
+ // Mirrors the generated `Wirespec.RawRequest` / `RawResponse` so generated endpoint `api`
5
+ // objects are assignable to WirespecMswEndpoint (the method union must match exactly).
6
+ type Method = 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH' | 'TRACE'
7
+
8
+ type RawRequest = {
9
+ method: Method
10
+ path: string[]
11
+ queries: Record<string, string[]>
12
+ headers: Record<string, string[]>
13
+ body: Uint8Array | undefined
14
+ }
15
+
16
+ type RawResponse = {
17
+ statusCode: number
18
+ headers: Record<string, string[]>
19
+ body: Uint8Array | undefined
20
+ }
21
+
22
+ /**
23
+ * Structural mirror of the generated `Wirespec.Api<Req, Res>` type. The shipped module
24
+ * cannot import the consumer's per-project generated `Wirespec` namespace, so the shape
25
+ * is redeclared here; generated endpoint `api` objects are assignable to it.
26
+ */
27
+ export type WirespecMswEndpoint<Req, Res> = {
28
+ method: string
29
+ path: string
30
+ server: (serialization: Serialization) => {
31
+ from: (request: RawRequest) => Req
32
+ to: (response: Res) => RawResponse
33
+ }
34
+ }
35
+
36
+ export type WirespecMswOptions = {
37
+ /** Host or path prefix prepended to the contract path, e.g. "https://api.example.com" or "/api". */
38
+ baseUrl?: string
39
+ /** Override the serialization used to (de)serialize requests/responses. */
40
+ serialization?: Serialization
41
+ }
42
+
43
+ /**
44
+ * Build a typed MSW request handler for a generated Wirespec endpoint.
45
+ *
46
+ * The generics are inferred from `api.server`, constraining `resolver` to the endpoint's
47
+ * own request/response types: returning a response from a different endpoint is a compile error.
48
+ */
49
+ export declare function wirespec<Req, Res>(
50
+ api: WirespecMswEndpoint<Req, Res>,
51
+ resolver: (request: Req) => Res | Promise<Res>,
52
+ options?: WirespecMswOptions,
53
+ ): RequestHandler
@@ -0,0 +1,108 @@
1
+ import { http, HttpResponse } from 'msw'
2
+ import { wirespecSerialization } from './wirespec-serialization.mjs'
3
+
4
+ const METHODS = {
5
+ GET: 'get',
6
+ PUT: 'put',
7
+ POST: 'post',
8
+ DELETE: 'delete',
9
+ PATCH: 'patch',
10
+ HEAD: 'head',
11
+ OPTIONS: 'options',
12
+ }
13
+
14
+ const PARAM = /^:(.+)$/
15
+ const BRACE = /^\{(.+)\}$/
16
+
17
+ const segments = (path) => path.replace(/^\/+/, '').split('/').filter((s) => s.length > 0)
18
+
19
+ // Normalize a Wirespec contract path into an MSW matcher: `{id}` -> `:id`, single leading slash.
20
+ const normalizePath = (path) => {
21
+ const colon = path.replace(/\{([^/}]+)\}/g, ':$1')
22
+ return colon.startsWith('/') ? colon : `/${colon}`
23
+ }
24
+
25
+ // Without a baseUrl, prefix the contract path with `*` so it matches on any origin
26
+ // (a bare relative path is not matched against absolute request URLs in Node). With a
27
+ // baseUrl, pin the origin/prefix instead.
28
+ const matcher = (baseUrl, path) => {
29
+ const normalized = normalizePath(path)
30
+ return baseUrl ? `${baseUrl.replace(/\/+$/, '')}${normalized}` : `*${normalized}`
31
+ }
32
+
33
+ // Rebuild the positional RawRequest.path from the contract template, substituting MSW's
34
+ // matched params for `:name`/`{name}` segments. Using the template (not the raw URL) keeps
35
+ // path-param indices aligned with the contract even when a baseUrl prefix is present.
36
+ const buildPath = (templatePath, params) =>
37
+ segments(templatePath).map((segment) => {
38
+ const match = segment.match(PARAM) ?? segment.match(BRACE)
39
+ if (!match) return segment
40
+ const value = params[match[1]]
41
+ return Array.isArray(value) ? value[0] : value
42
+ })
43
+
44
+ // The generated `from()` reads queries/headers as `Record<string, string[]>` (it pulls
45
+ // `values[0]` through `deserializeParam`), so collect every value per key into an array.
46
+ const readParams = (entries) => {
47
+ const params = {}
48
+ for (const [key, value] of entries) {
49
+ if (params[key]) params[key].push(value)
50
+ else params[key] = [value]
51
+ }
52
+ return params
53
+ }
54
+
55
+ // The generated `from()` reads the body as a `Uint8Array` (`deserializeBody` does
56
+ // `TextDecoder().decode(raw)`), so hand it the raw bytes rather than decoded text.
57
+ const readBody = async (request) => {
58
+ if (request.method === 'GET' || request.method === 'HEAD') return undefined
59
+ const buffer = await request.arrayBuffer()
60
+ return buffer.byteLength > 0 ? new Uint8Array(buffer) : undefined
61
+ }
62
+
63
+ // The generated `to()` emits headers as `Record<string, string[]>`; flatten them into a
64
+ // `Headers` (each value appended) so they form a valid HeadersInit for MSW's HttpResponse.
65
+ const toHeaders = (rawHeaders) => {
66
+ const headers = new Headers()
67
+ for (const [key, values] of Object.entries(rawHeaders ?? {})) {
68
+ for (const value of Array.isArray(values) ? values : [values]) {
69
+ headers.append(key, String(value))
70
+ }
71
+ }
72
+ return headers
73
+ }
74
+
75
+ /**
76
+ * Build an MSW request handler for a generated Wirespec endpoint `api`.
77
+ *
78
+ * The resolver receives the deserialized, typed Wirespec request and must return one of
79
+ * that endpoint's responses; a response from a different endpoint is a compile error.
80
+ *
81
+ * Options:
82
+ * - baseUrl: host or path prefix to prepend to the contract path (e.g. "https://api.example.com").
83
+ * - serialization: override the (de)serializer (defaults to wirespecSerialization).
84
+ */
85
+ export function wirespec(api, resolver, options = {}) {
86
+ const serialization = options.serialization ?? wirespecSerialization
87
+ const pattern = matcher(options.baseUrl, api.path)
88
+ const method = METHODS[String(api.method).toUpperCase()] ?? 'all'
89
+ const endpoint = api.server(serialization)
90
+
91
+ return http[method](pattern, async ({ request, params }) => {
92
+ const url = new URL(request.url)
93
+ const rawRequest = {
94
+ method: request.method,
95
+ path: buildPath(api.path, params),
96
+ queries: readParams(url.searchParams),
97
+ headers: readParams(request.headers),
98
+ body: await readBody(request),
99
+ }
100
+ const typedRequest = endpoint.from(rawRequest)
101
+ const response = await resolver(typedRequest)
102
+ const rawResponse = endpoint.to(response)
103
+ return new HttpResponse(rawResponse.body ?? null, {
104
+ status: rawResponse.statusCode,
105
+ headers: toHeaders(rawResponse.headers),
106
+ })
107
+ })
108
+ }