@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.
- package/arrow-arrow-atomic.mjs +12 -12
- package/arrow-arrow-core.mjs +163 -163
- package/clikt-clikt-mordant.mjs +80 -80
- package/clikt-clikt-mordant.mjs.map +1 -1
- package/clikt-clikt.mjs +1566 -1566
- package/clikt-clikt.mjs.map +1 -1
- package/colormath-root-colormath.mjs +444 -444
- package/kotlin-kotlin-stdlib.mjs +2571 -5539
- package/kotlin-kotlin-stdlib.mjs.map +1 -1
- package/kotlin-openapi-bindings.mjs +20696 -6702
- package/kotlin-openapi-bindings.mjs.map +1 -1
- package/kotlin-rgxgen.mjs +1818 -1818
- package/kotlinx-io-kotlinx-io-core.mjs +453 -453
- package/kotlinx-io-kotlinx-io-core.mjs.map +1 -1
- package/kotlinx-serialization-kotlinx-serialization-core.mjs +2224 -2061
- package/kotlinx-serialization-kotlinx-serialization-core.mjs.map +1 -1
- package/kotlinx-serialization-kotlinx-serialization-json.mjs +1956 -1481
- package/kotlinx-serialization-kotlinx-serialization-json.mjs.map +1 -1
- package/mordant-mordant.mjs +1361 -1361
- package/package.json +14 -9
- package/wirespec-lsp.mjs +7 -0
- package/wirespec-msw.d.ts +53 -0
- package/wirespec-msw.mjs +83 -0
- package/wirespec-src-compiler-core.mjs +1760 -1696
- package/wirespec-src-compiler-core.mjs.map +1 -1
- package/wirespec-src-compiler-emitters-java.mjs +461 -425
- package/wirespec-src-compiler-emitters-java.mjs.map +1 -1
- package/wirespec-src-compiler-emitters-kotlin.mjs +408 -309
- package/wirespec-src-compiler-emitters-kotlin.mjs.map +1 -1
- package/wirespec-src-compiler-emitters-python.mjs +382 -383
- package/wirespec-src-compiler-emitters-python.mjs.map +1 -1
- package/wirespec-src-compiler-emitters-rust.mjs +448 -425
- package/wirespec-src-compiler-emitters-rust.mjs.map +1 -1
- package/wirespec-src-compiler-emitters-scala.mjs +171 -172
- package/wirespec-src-compiler-emitters-scala.mjs.map +1 -1
- package/wirespec-src-compiler-emitters-typescript.mjs +508 -477
- package/wirespec-src-compiler-emitters-typescript.mjs.map +1 -1
- package/wirespec-src-compiler-emitters-wirespec.mjs +83 -83
- package/wirespec-src-compiler-emitters-wirespec.mjs.map +1 -1
- package/wirespec-src-compiler-ir.mjs +3869 -3919
- package/wirespec-src-compiler-ir.mjs.map +1 -1
- package/wirespec-src-compiler-lib.mjs +418 -418
- package/wirespec-src-compiler-lib.mjs.map +1 -1
- package/wirespec-src-converter-avro.mjs +512 -512
- package/wirespec-src-converter-avro.mjs.map +1 -1
- package/wirespec-src-converter-openapi.mjs +1596 -1522
- package/wirespec-src-converter-openapi.mjs.map +1 -1
- package/wirespec-src-ide-lsp.mjs +4928 -0
- package/wirespec-src-ide-lsp.mjs.map +1 -0
- package/wirespec-src-plugin-arguments.mjs +185 -185
- package/wirespec-src-plugin-arguments.mjs.map +1 -1
- package/wirespec-src-plugin-cli.mjs +106 -106
- package/wirespec-src-plugin-npm.d.mts +2 -11
- package/wirespec-src-plugin-npm.mjs +47 -42
- package/wirespec-src-plugin-npm.mjs.map +1 -1
- package/wirespec-src-tools-generator.mjs +53 -53
- package/wirespec-src-tools-generator.mjs.map +1 -1
- package/Kotlin-DateTime-library-kotlinx-datetime.mjs +0 -4
- package/Kotlin-DateTime-library-kotlinx-datetime.mjs.map +0 -1
- package/kotest-kotest-assertions-kotest-assertions-core.mjs +0 -4
- package/kotest-kotest-assertions-kotest-assertions-core.mjs.map +0 -1
- package/kotest-kotest-assertions-kotest-assertions-shared.mjs +0 -4
- package/kotest-kotest-assertions-kotest-assertions-shared.mjs.map +0 -1
- package/kotest-kotest-common.mjs +0 -56
- package/kotest-kotest-common.mjs.map +0 -1
- package/kotest-kotest-framework-kotest-framework-engine.mjs +0 -4
- package/kotest-kotest-framework-kotest-framework-engine.mjs.map +0 -1
- package/kotest-kotest-property-kotest-property-datetime.mjs +0 -4
- package/kotest-kotest-property-kotest-property-datetime.mjs.map +0 -1
- package/kotest-kotest-property.mjs +0 -3230
- package/kotest-kotest-property.mjs.map +0 -1
- package/kotest-property-arbs.mjs +0 -482
- package/kotest-property-arbs.mjs.map +0 -1
- package/kotlinx-coroutines-test.mjs +0 -4
- package/kotlinx-coroutines-test.mjs.map +0 -1
- package/wirespec-generator.d.ts +0 -52
- package/wirespec-generator.mjs +0 -9
- package/wirespec-src-integration-kotest.mjs +0 -1537
- package/wirespec-src-integration-kotest.mjs.map +0 -1
- package/xmlutil-core.mjs +0 -4
- package/xmlutil-core.mjs.map +0 -1
- package/xmlutil-serialization.mjs +0 -4
- 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
|
|
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
|
-
|
|
11
|
-
"
|
|
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
|
-
"./
|
|
34
|
-
"types": "./wirespec-
|
|
35
|
-
"default": "./wirespec-
|
|
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": {
|
package/wirespec-lsp.mjs
ADDED
|
@@ -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
|
package/wirespec-msw.mjs
ADDED
|
@@ -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
|
+
}
|