@flock/wirespec 0.19.0-RC.2 → 0.19.0

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 +163 -163
  3. package/clikt-clikt-mordant.mjs +80 -80
  4. package/clikt-clikt-mordant.mjs.map +1 -1
  5. package/clikt-clikt.mjs +1566 -1566
  6. package/clikt-clikt.mjs.map +1 -1
  7. package/colormath-root-colormath.mjs +444 -444
  8. package/kotlin-kotlin-stdlib.mjs +2571 -5539
  9. package/kotlin-kotlin-stdlib.mjs.map +1 -1
  10. package/kotlin-openapi-bindings.mjs +20696 -6702
  11. package/kotlin-openapi-bindings.mjs.map +1 -1
  12. package/kotlin-rgxgen.mjs +1818 -1818
  13. package/kotlinx-io-kotlinx-io-core.mjs +453 -453
  14. package/kotlinx-io-kotlinx-io-core.mjs.map +1 -1
  15. package/kotlinx-serialization-kotlinx-serialization-core.mjs +2224 -2061
  16. package/kotlinx-serialization-kotlinx-serialization-core.mjs.map +1 -1
  17. package/kotlinx-serialization-kotlinx-serialization-json.mjs +1956 -1481
  18. package/kotlinx-serialization-kotlinx-serialization-json.mjs.map +1 -1
  19. package/mordant-mordant.mjs +1361 -1361
  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 +83 -0
  24. package/wirespec-src-compiler-core.mjs +1760 -1696
  25. package/wirespec-src-compiler-core.mjs.map +1 -1
  26. package/wirespec-src-compiler-emitters-java.mjs +461 -425
  27. package/wirespec-src-compiler-emitters-java.mjs.map +1 -1
  28. package/wirespec-src-compiler-emitters-kotlin.mjs +408 -309
  29. package/wirespec-src-compiler-emitters-kotlin.mjs.map +1 -1
  30. package/wirespec-src-compiler-emitters-python.mjs +382 -383
  31. package/wirespec-src-compiler-emitters-python.mjs.map +1 -1
  32. package/wirespec-src-compiler-emitters-rust.mjs +448 -425
  33. package/wirespec-src-compiler-emitters-rust.mjs.map +1 -1
  34. package/wirespec-src-compiler-emitters-scala.mjs +171 -172
  35. package/wirespec-src-compiler-emitters-scala.mjs.map +1 -1
  36. package/wirespec-src-compiler-emitters-typescript.mjs +508 -477
  37. package/wirespec-src-compiler-emitters-typescript.mjs.map +1 -1
  38. package/wirespec-src-compiler-emitters-wirespec.mjs +83 -83
  39. package/wirespec-src-compiler-emitters-wirespec.mjs.map +1 -1
  40. package/wirespec-src-compiler-ir.mjs +3869 -3919
  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 +512 -512
  45. package/wirespec-src-converter-avro.mjs.map +1 -1
  46. package/wirespec-src-converter-openapi.mjs +1596 -1522
  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 +185 -185
  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 -3230
  71. package/kotest-kotest-property.mjs.map +0 -1
  72. package/kotest-property-arbs.mjs +0 -482
  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 -1537
  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.2",
3
+ "version": "0.19.0",
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?: string
14
+ }
15
+
16
+ type RawResponse = {
17
+ status: number
18
+ headers: Record<string, string>
19
+ body?: string
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,83 @@
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
+ const readBody = async (request) => {
45
+ if (request.method === 'GET' || request.method === 'HEAD') return undefined
46
+ const text = await request.text()
47
+ return text.length > 0 ? text : undefined
48
+ }
49
+
50
+ /**
51
+ * Build an MSW request handler for a generated Wirespec endpoint `api`.
52
+ *
53
+ * The resolver receives the deserialized, typed Wirespec request and must return one of
54
+ * that endpoint's responses; a response from a different endpoint is a compile error.
55
+ *
56
+ * Options:
57
+ * - baseUrl: host or path prefix to prepend to the contract path (e.g. "https://api.example.com").
58
+ * - serialization: override the (de)serializer (defaults to wirespecSerialization).
59
+ */
60
+ export function wirespec(api, resolver, options = {}) {
61
+ const serialization = options.serialization ?? wirespecSerialization
62
+ const pattern = matcher(options.baseUrl, api.path)
63
+ const method = METHODS[String(api.method).toUpperCase()] ?? 'all'
64
+ const endpoint = api.server(serialization)
65
+
66
+ return http[method](pattern, async ({ request, params }) => {
67
+ const url = new URL(request.url)
68
+ const rawRequest = {
69
+ method: request.method,
70
+ path: buildPath(api.path, params),
71
+ queries: Object.fromEntries(url.searchParams),
72
+ headers: Object.fromEntries(request.headers),
73
+ body: await readBody(request),
74
+ }
75
+ const typedRequest = endpoint.from(rawRequest)
76
+ const response = await resolver(typedRequest)
77
+ const rawResponse = endpoint.to(response)
78
+ return new HttpResponse(rawResponse.body ?? null, {
79
+ status: rawResponse.status,
80
+ headers: rawResponse.headers,
81
+ })
82
+ })
83
+ }