@flock/wirespec 0.18.12 → 0.18.14

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/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "@flock/wirespec",
3
- "version": "0.18.12",
3
+ "version": "0.18.14",
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
9
  "dependencies": {},
10
- "peerDependencies": {},
10
+ "peerDependencies": {
11
+ "msw": "^2.0.0"
12
+ },
11
13
  "optionalDependencies": {},
12
14
  "bundledDependencies": [],
13
15
  "bin": {
@@ -27,6 +29,15 @@
27
29
  "./serialization": {
28
30
  "types": "./wirespec-serialization.d.ts",
29
31
  "default": "./wirespec-serialization.mjs"
32
+ },
33
+ "./msw": {
34
+ "types": "./wirespec-msw.d.ts",
35
+ "default": "./wirespec-msw.mjs"
36
+ }
37
+ },
38
+ "peerDependenciesMeta": {
39
+ "msw": {
40
+ "optional": true
30
41
  }
31
42
  },
32
43
  "repository": {
@@ -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
+ }
@@ -183,7 +183,7 @@ initMetadataForClass(ParamType, 'ParamType', VOID, Enum);
183
183
  initMetadataForClass(Param, 'Param');
184
184
  initMetadataForClass(FileExtension, 'FileExtension', VOID, Enum);
185
185
  initMetadataForCompanion(Companion_0);
186
- initMetadataForClass(LanguageEmitter, 'LanguageEmitter', VOID, VOID, [TypeDefinitionEmitter, NotYetImplemented]);
186
+ initMetadataForClass(LanguageEmitter, 'LanguageEmitter', VOID, VOID, [NotYetImplemented, TypeDefinitionEmitter]);
187
187
  initMetadataForCompanion(Companion_1);
188
188
  initMetadataForClass(PackageName, 'PackageName');
189
189
  initMetadataForObject(Spacer, 'Spacer');
@@ -160,8 +160,8 @@ import {
160
160
  Function21cuq8qizkin7 as Function,
161
161
  plusd54zq6f7l8fy as plus_3,
162
162
  Struct39wf79cwtn4ty as Struct,
163
- Interface3pn84xq686t2r as Interface,
164
163
  RawElement2yts1x2rbem1g as RawElement,
164
+ Interface3pn84xq686t2r as Interface,
165
165
  Assignment3kcxc8wlcbmkn as Assignment,
166
166
  ReturnStatement29qlfkn9kpy10 as ReturnStatement,
167
167
  Wildcard_instance2ga1ytfwj78ra as Wildcard_instance,
@@ -275,7 +275,107 @@ function emit_8(channel) {
275
275
  return trimMargin('\n |' + emitImports(this, channel) + '\n |\n |@FunctionalInterface\n |public interface ' + this.br(channel.qo_1) + ' {\n | void invoke(' + emitFullyQualified(this, channel, channel.ro_1) + this.j1v(channel.ro_1) + ' message);\n |}\n |\n ');
276
276
  }
277
277
  initMetadataForInterface(JavaChannelDefinitionEmitter, 'JavaChannelDefinitionEmitter', VOID, VOID, [JavaTypeDefinitionEmitter]);
278
- function emit_9(endpoint) {
278
+ function emit_9(refined) {
279
+ return trimMargin('\n |public record ' + this.br(refined.gr_1) + ' (' + this.bq(refined.hr_1) + ' value) implements Wirespec.Refined<' + this.bq(refined.hr_1) + '> {\n |' + Spacer_instance.toString() + '@Override\n |' + Spacer_instance.toString() + 'public String toString() { return value.toString(); }\n |' + Spacer_instance.toString() + 'public boolean validate() {\n |' + Spacer_instance.toString() + Spacer_instance.toString() + this.pr(refined) + '\n |' + Spacer_instance.toString() + '}\n |' + Spacer_instance.toString() + '@Override\n |' + Spacer_instance.toString() + 'public ' + this.bq(refined.hr_1) + ' value() { return value; }\n |}\n |\n ');
280
+ }
281
+ function emitValidator(_this__u8e3s4) {
282
+ var defaultReturn = 'return true;';
283
+ var type = _this__u8e3s4.hr_1.tu_1;
284
+ var tmp;
285
+ if (type instanceof Integer) {
286
+ var tmp0_safe_receiver = type.yt_1;
287
+ var tmp1_elvis_lhs = tmp0_safe_receiver == null ? null : this.cq(tmp0_safe_receiver);
288
+ tmp = tmp1_elvis_lhs == null ? defaultReturn : tmp1_elvis_lhs;
289
+ } else {
290
+ if (type instanceof Number_0) {
291
+ var tmp2_safe_receiver = type.bu_1;
292
+ var tmp3_elvis_lhs = tmp2_safe_receiver == null ? null : this.cq(tmp2_safe_receiver);
293
+ tmp = tmp3_elvis_lhs == null ? defaultReturn : tmp3_elvis_lhs;
294
+ } else {
295
+ if (type instanceof String_0) {
296
+ var tmp4_safe_receiver = type.vt_1;
297
+ var tmp_0;
298
+ var tmp_1 = tmp4_safe_receiver;
299
+ if ((tmp_1 == null ? null : new RegExp_0(tmp_1)) == null) {
300
+ tmp_0 = null;
301
+ } else {
302
+ tmp_0 = this.cq(new RegExp_0(tmp4_safe_receiver));
303
+ }
304
+ var tmp5_elvis_lhs = tmp_0;
305
+ tmp = tmp5_elvis_lhs == null ? defaultReturn : tmp5_elvis_lhs;
306
+ } else {
307
+ if (equals(type, Boolean_instance)) {
308
+ tmp = defaultReturn;
309
+ } else {
310
+ if (equals(type, Bytes_instance)) {
311
+ tmp = defaultReturn;
312
+ } else {
313
+ noWhenBranchMatchedException();
314
+ }
315
+ }
316
+ }
317
+ }
318
+ }
319
+ return tmp;
320
+ }
321
+ initMetadataForInterface(JavaRefinedTypeDefinitionEmitter, 'JavaRefinedTypeDefinitionEmitter', VOID, VOID, [JavaTypeDefinitionEmitter]);
322
+ function emit_10(identifier) {
323
+ var tmp;
324
+ if (identifier instanceof DefinitionIdentifier) {
325
+ tmp = this.u1v(identifier.l1());
326
+ } else {
327
+ if (identifier instanceof FieldIdentifier) {
328
+ tmp = this.y1v(this.u1v(identifier.l1()));
329
+ } else {
330
+ noWhenBranchMatchedException();
331
+ }
332
+ }
333
+ return tmp;
334
+ }
335
+ function sanitizeSymbol(_this__u8e3s4) {
336
+ // Inline function 'kotlin.collections.mapIndexed' call
337
+ var this_0 = split(_this__u8e3s4, ['.', ' ', '-']);
338
+ // Inline function 'kotlin.collections.mapIndexedTo' call
339
+ var destination = ArrayList_init_$Create$_0(collectionSizeOrDefault(this_0, 10));
340
+ var index = 0;
341
+ var _iterator__ex2g4s = this_0.t();
342
+ while (_iterator__ex2g4s.u()) {
343
+ var item = _iterator__ex2g4s.v();
344
+ var _unary__edvuaz = index;
345
+ index = _unary__edvuaz + 1 | 0;
346
+ var tmp$ret$0 = checkIndexOverflow(_unary__edvuaz) > 0 ? Companion_instance_1.sq(item) : item;
347
+ destination.x(tmp$ret$0);
348
+ }
349
+ var tmp = asSequence(joinToString(destination, ''));
350
+ return this.x1v(joinToString_0(filter(tmp, JavaIdentifierEmitter$sanitizeSymbol$lambda), ''));
351
+ }
352
+ function sanitizeFirstIsDigit(_this__u8e3s4) {
353
+ var tmp;
354
+ var tmp0_safe_receiver = firstOrNull(_this__u8e3s4);
355
+ var tmp_0;
356
+ var tmp_1 = tmp0_safe_receiver;
357
+ if ((tmp_1 == null ? null : new Char(tmp_1)) == null) {
358
+ tmp_0 = null;
359
+ } else {
360
+ tmp_0 = isDigit(tmp0_safe_receiver);
361
+ }
362
+ if (tmp_0 === true) {
363
+ tmp = '_' + _this__u8e3s4;
364
+ } else {
365
+ tmp = _this__u8e3s4;
366
+ }
367
+ return tmp;
368
+ }
369
+ function sanitizeKeywords(_this__u8e3s4) {
370
+ return Companion_getInstance_0().a1w_1.u1(_this__u8e3s4) ? '_' + _this__u8e3s4 : _this__u8e3s4;
371
+ }
372
+ initMetadataForInterface(JavaIdentifierEmitter, 'JavaIdentifierEmitter');
373
+ function emit_11(enum_0, module_0) {
374
+ var tmp = this.br(enum_0.lr_1);
375
+ return trimMargin('\n |public enum ' + tmp + ' implements Wirespec.Enum {\n |' + spacer(joinToString(enum_0.mr_1, ',\n', VOID, VOID, VOID, VOID, JavaEnumDefinitionEmitter$emit$lambda(this))) + ';\n |' + Spacer_instance.toString() + 'public final String label;\n |' + Spacer_instance.toString() + this.br(enum_0.lr_1) + '(String label) {\n |' + Spacer_instance.vr(2) + 'this.label = label;\n |' + Spacer_instance.toString() + '}\n |' + Spacer_instance.toString() + '@Override\n |' + Spacer_instance.toString() + 'public String toString() {\n |' + Spacer_instance.vr(2) + 'return label;\n |' + Spacer_instance.toString() + '}\n |' + Spacer_instance.toString() + '@Override\n |' + Spacer_instance.toString() + 'public String label() {\n |' + Spacer_instance.vr(2) + 'return label;\n |' + Spacer_instance.toString() + '}\n |}\n |\n ');
376
+ }
377
+ initMetadataForInterface(JavaEnumDefinitionEmitter, 'JavaEnumDefinitionEmitter', VOID, VOID, [JavaIdentifierEmitter]);
378
+ function emit_12(endpoint) {
279
379
  var tmp = emitImports_0(this, endpoint);
280
380
  var tmp_0 = this.br(endpoint.ip_1);
281
381
  var tmp_1 = get_pathParams(endpoint);
@@ -307,10 +407,10 @@ function emit_9(endpoint) {
307
407
  function emitHandleFunction(endpoint) {
308
408
  return 'java.util.concurrent.CompletableFuture<Response<?>> ' + Companion_instance_1.tq(this.br(endpoint.ip_1)) + '(Request request);';
309
409
  }
310
- function emit_10(_this__u8e3s4, endpoint) {
410
+ function emit_13(_this__u8e3s4, endpoint) {
311
411
  return trimMargin('\n |' + Spacer_instance.toString() + 'record Request (\n |' + Spacer_instance.vr(2) + 'Path path,\n |' + Spacer_instance.vr(2) + 'Wirespec.Method method,\n |' + Spacer_instance.vr(2) + 'Queries queries,\n |' + Spacer_instance.vr(2) + 'RequestHeaders headers,\n |' + Spacer_instance.vr(2) + emit_16(this, _this__u8e3s4.rp_1) + ' body\n |' + Spacer_instance.toString() + ') implements Wirespec.Request<' + emit_16(this, _this__u8e3s4.rp_1) + '> {\n |' + Spacer_instance.vr(2) + emitConstructor(this, _this__u8e3s4, endpoint) + '\n |' + Spacer_instance.toString() + '}\n ');
312
412
  }
313
- function emit_11(_this__u8e3s4) {
413
+ function emit_14(_this__u8e3s4) {
314
414
  var tmp = Spacer_instance.toString();
315
415
  var tmp_0 = Companion_instance_1.sq(_this__u8e3s4.up_1);
316
416
  var tmp_1 = Spacer_instance.vr(2);
@@ -343,112 +443,12 @@ function emit_11(_this__u8e3s4) {
343
443
  return trimMargin('\n |' + tmp + 'record Response' + tmp_0 + '(\n |' + tmp_1 + 'Integer status,\n |' + tmp_2 + 'Headers headers,\n |' + tmp_3 + tmp_4 + ' body\n |' + tmp_5 + ') implements Response' + tmp_6 + 'XX<' + tmp_7 + '>, Response' + tmp_8 + ' {\n |' + tmp_9 + 'public Response' + tmp_10 + '(' + tmp_13 + ') {\n |' + tmp_14 + 'this(' + tmp_15 + ', ' + tmp_16 + ', ' + tmp_17 + ');\n |' + tmp_18 + '}\n |' + tmp_19 + emitObject(this, _this__u8e3s4.vp_1, 'Headers', 'Wirespec.Response.Headers', JavaEndpointDefinitionEmitter$emit$lambda_7(this)) + '\n |' + Spacer_instance.toString() + '}\n ');
344
444
  }
345
445
  initMetadataForInterface(JavaEndpointDefinitionEmitter, 'JavaEndpointDefinitionEmitter', VOID, VOID, [JavaTypeDefinitionEmitter]);
346
- function emit_12(identifier) {
347
- var tmp;
348
- if (identifier instanceof DefinitionIdentifier) {
349
- tmp = this.u1v(identifier.l1());
350
- } else {
351
- if (identifier instanceof FieldIdentifier) {
352
- tmp = this.y1v(this.u1v(identifier.l1()));
353
- } else {
354
- noWhenBranchMatchedException();
355
- }
356
- }
357
- return tmp;
358
- }
359
- function sanitizeSymbol(_this__u8e3s4) {
360
- // Inline function 'kotlin.collections.mapIndexed' call
361
- var this_0 = split(_this__u8e3s4, ['.', ' ', '-']);
362
- // Inline function 'kotlin.collections.mapIndexedTo' call
363
- var destination = ArrayList_init_$Create$_0(collectionSizeOrDefault(this_0, 10));
364
- var index = 0;
365
- var _iterator__ex2g4s = this_0.t();
366
- while (_iterator__ex2g4s.u()) {
367
- var item = _iterator__ex2g4s.v();
368
- var _unary__edvuaz = index;
369
- index = _unary__edvuaz + 1 | 0;
370
- var tmp$ret$0 = checkIndexOverflow(_unary__edvuaz) > 0 ? Companion_instance_1.sq(item) : item;
371
- destination.x(tmp$ret$0);
372
- }
373
- var tmp = asSequence(joinToString(destination, ''));
374
- return this.x1v(joinToString_0(filter(tmp, JavaIdentifierEmitter$sanitizeSymbol$lambda), ''));
375
- }
376
- function sanitizeFirstIsDigit(_this__u8e3s4) {
377
- var tmp;
378
- var tmp0_safe_receiver = firstOrNull(_this__u8e3s4);
379
- var tmp_0;
380
- var tmp_1 = tmp0_safe_receiver;
381
- if ((tmp_1 == null ? null : new Char(tmp_1)) == null) {
382
- tmp_0 = null;
383
- } else {
384
- tmp_0 = isDigit(tmp0_safe_receiver);
385
- }
386
- if (tmp_0 === true) {
387
- tmp = '_' + _this__u8e3s4;
388
- } else {
389
- tmp = _this__u8e3s4;
390
- }
391
- return tmp;
392
- }
393
- function sanitizeKeywords(_this__u8e3s4) {
394
- return Companion_getInstance_0().a1w_1.u1(_this__u8e3s4) ? '_' + _this__u8e3s4 : _this__u8e3s4;
395
- }
396
- initMetadataForInterface(JavaIdentifierEmitter, 'JavaIdentifierEmitter');
397
- function emit_13(enum_0, module_0) {
398
- var tmp = this.br(enum_0.lr_1);
399
- return trimMargin('\n |public enum ' + tmp + ' implements Wirespec.Enum {\n |' + spacer(joinToString(enum_0.mr_1, ',\n', VOID, VOID, VOID, VOID, JavaEnumDefinitionEmitter$emit$lambda(this))) + ';\n |' + Spacer_instance.toString() + 'public final String label;\n |' + Spacer_instance.toString() + this.br(enum_0.lr_1) + '(String label) {\n |' + Spacer_instance.vr(2) + 'this.label = label;\n |' + Spacer_instance.toString() + '}\n |' + Spacer_instance.toString() + '@Override\n |' + Spacer_instance.toString() + 'public String toString() {\n |' + Spacer_instance.vr(2) + 'return label;\n |' + Spacer_instance.toString() + '}\n |' + Spacer_instance.toString() + '@Override\n |' + Spacer_instance.toString() + 'public String label() {\n |' + Spacer_instance.vr(2) + 'return label;\n |' + Spacer_instance.toString() + '}\n |}\n |\n ');
400
- }
401
- initMetadataForInterface(JavaEnumDefinitionEmitter, 'JavaEnumDefinitionEmitter', VOID, VOID, [JavaIdentifierEmitter]);
402
- function emit_14(union) {
446
+ function emit_15(union) {
403
447
  var tmp = this.br(union.uo_1);
404
448
  return trimMargin('\n |public sealed interface ' + tmp + ' permits ' + joinToString(union.vo_1, VOID, VOID, VOID, VOID, VOID, JavaUnionDefinitionEmitter$emit$lambda) + ' {}\n |\n ');
405
449
  }
406
450
  initMetadataForInterface(JavaUnionDefinitionEmitter, 'JavaUnionDefinitionEmitter', VOID, VOID, [JavaIdentifierEmitter]);
407
- function emit_15(refined) {
408
- return trimMargin('\n |public record ' + this.br(refined.gr_1) + ' (' + this.bq(refined.hr_1) + ' value) implements Wirespec.Refined<' + this.bq(refined.hr_1) + '> {\n |' + Spacer_instance.toString() + '@Override\n |' + Spacer_instance.toString() + 'public String toString() { return value.toString(); }\n |' + Spacer_instance.toString() + 'public boolean validate() {\n |' + Spacer_instance.toString() + Spacer_instance.toString() + this.pr(refined) + '\n |' + Spacer_instance.toString() + '}\n |' + Spacer_instance.toString() + '@Override\n |' + Spacer_instance.toString() + 'public ' + this.bq(refined.hr_1) + ' value() { return value; }\n |}\n |\n ');
409
- }
410
- function emitValidator(_this__u8e3s4) {
411
- var defaultReturn = 'return true;';
412
- var type = _this__u8e3s4.hr_1.tu_1;
413
- var tmp;
414
- if (type instanceof Integer) {
415
- var tmp0_safe_receiver = type.yt_1;
416
- var tmp1_elvis_lhs = tmp0_safe_receiver == null ? null : this.cq(tmp0_safe_receiver);
417
- tmp = tmp1_elvis_lhs == null ? defaultReturn : tmp1_elvis_lhs;
418
- } else {
419
- if (type instanceof Number_0) {
420
- var tmp2_safe_receiver = type.bu_1;
421
- var tmp3_elvis_lhs = tmp2_safe_receiver == null ? null : this.cq(tmp2_safe_receiver);
422
- tmp = tmp3_elvis_lhs == null ? defaultReturn : tmp3_elvis_lhs;
423
- } else {
424
- if (type instanceof String_0) {
425
- var tmp4_safe_receiver = type.vt_1;
426
- var tmp_0;
427
- var tmp_1 = tmp4_safe_receiver;
428
- if ((tmp_1 == null ? null : new RegExp_0(tmp_1)) == null) {
429
- tmp_0 = null;
430
- } else {
431
- tmp_0 = this.cq(new RegExp_0(tmp4_safe_receiver));
432
- }
433
- var tmp5_elvis_lhs = tmp_0;
434
- tmp = tmp5_elvis_lhs == null ? defaultReturn : tmp5_elvis_lhs;
435
- } else {
436
- if (equals(type, Boolean_instance)) {
437
- tmp = defaultReturn;
438
- } else {
439
- if (equals(type, Bytes_instance)) {
440
- tmp = defaultReturn;
441
- } else {
442
- noWhenBranchMatchedException();
443
- }
444
- }
445
- }
446
- }
447
- }
448
- return tmp;
449
- }
450
- initMetadataForInterface(JavaRefinedTypeDefinitionEmitter, 'JavaRefinedTypeDefinitionEmitter', VOID, VOID, [JavaTypeDefinitionEmitter]);
451
- initMetadataForClass(JavaEmitter, 'JavaEmitter', JavaEmitter, LanguageEmitter, [JavaEndpointDefinitionEmitter, JavaTypeDefinitionEmitter, JavaEnumDefinitionEmitter, JavaUnionDefinitionEmitter, JavaChannelDefinitionEmitter, JavaRefinedTypeDefinitionEmitter, JavaIdentifierEmitter, LanguageEmitter]);
451
+ initMetadataForClass(JavaEmitter, 'JavaEmitter', JavaEmitter, LanguageEmitter, [JavaChannelDefinitionEmitter, JavaRefinedTypeDefinitionEmitter, JavaEnumDefinitionEmitter, JavaEndpointDefinitionEmitter, JavaTypeDefinitionEmitter, JavaIdentifierEmitter, JavaUnionDefinitionEmitter, LanguageEmitter]);
452
452
  initMetadataForCompanion(Companion);
453
453
  initMetadataForCompanion(Companion_0);
454
454
  initMetadataForClass(JavaIrEmitter, 'JavaIrEmitter', JavaIrEmitter, VOID, [IrEmitter]);
@@ -1233,7 +1233,7 @@ protoOf(JavaIrEmitter).ir = function (refined) {
1233
1233
  return sanitizeNames(applyRefinedStructShape(convert_2(refined), refined), this.h1w_1);
1234
1234
  };
1235
1235
  protoOf(JavaIrEmitter).or = function (endpoint) {
1236
- var tmp = sanitizeNames(transformTypeDescriptors(injectHandleFunction(convert_3(endpoint), endpoint)), this.h1w_1);
1236
+ var tmp = sanitizeNames(transformTypeDescriptors(injectApiField(injectHandleFunction(convert_3(endpoint), endpoint))), this.h1w_1);
1237
1237
  // Inline function 'kotlin.takeIf' call
1238
1238
  var this_0 = buildModelImports(endpoint, this.i1v());
1239
1239
  var tmp_0;
@@ -1375,6 +1375,23 @@ function applyRefinedStructShape(_this__u8e3s4, refined) {
1375
1375
  var tmp_0 = scope.c1u_1;
1376
1376
  return isInterface(tmp_0, Element) ? tmp_0 : THROW_CCE();
1377
1377
  }
1378
+ function injectApiField(_this__u8e3s4) {
1379
+ // Inline function 'community.flock.wirespec.ir.core.transform' call
1380
+ var scope = new TransformScope(_this__u8e3s4);
1381
+ // Inline function 'community.flock.wirespec.ir.core.TransformScope.injectAfter' call
1382
+ var tmp = scope;
1383
+ // Inline function 'community.flock.wirespec.ir.core.injectAfter' call
1384
+ // Inline function 'community.flock.wirespec.ir.core.transformMatchingElements' call
1385
+ var this_0 = scope.c1u_1;
1386
+ // Inline function 'community.flock.wirespec.ir.core.transformer' call
1387
+ // Inline function 'kotlin.apply' call
1388
+ var this_1 = new TransformerBuilder();
1389
+ this_1.h1h(injectApiField$lambda);
1390
+ var tmp$ret$2 = this_1.i1h();
1391
+ tmp.c1u_1 = transform(this_0, tmp$ret$2);
1392
+ var tmp_0 = scope.c1u_1;
1393
+ return isInterface(tmp_0, Element) ? tmp_0 : THROW_CCE();
1394
+ }
1378
1395
  function injectHandleFunction(_this__u8e3s4, endpoint) {
1379
1396
  var handlersStruct = buildHandlersStruct(endpoint);
1380
1397
  // Inline function 'community.flock.wirespec.ir.core.transform' call
@@ -1625,6 +1642,24 @@ function applyRefinedStructShape$lambda($refined) {
1625
1642
  return transformChildren_0(transformed, transformer);
1626
1643
  };
1627
1644
  }
1645
+ function injectApiField$lambda(element, transformer) {
1646
+ var tmp;
1647
+ if (element instanceof Namespace) {
1648
+ var injected = listOf(new RawElement('Handler.Handlers api = new Handler.Handlers();\n'));
1649
+ var tmp_0;
1650
+ // Inline function 'kotlin.collections.isNotEmpty' call
1651
+ if (!injected.r()) {
1652
+ tmp_0 = withElements(element, plus_1(element.z1m(), injected));
1653
+ } else {
1654
+ tmp_0 = element;
1655
+ }
1656
+ tmp = tmp_0;
1657
+ } else {
1658
+ tmp = element;
1659
+ }
1660
+ var transformed = tmp;
1661
+ return transformChildren_0(transformed, transformer);
1662
+ }
1628
1663
  function injectHandleFunction$lambda$lambda($handlersStruct) {
1629
1664
  return function (element, transformer) {
1630
1665
  var tmp;
@@ -1650,7 +1685,7 @@ function injectHandleFunction$lambda($handlersStruct) {
1650
1685
  var tmp;
1651
1686
  if (element instanceof Interface) {
1652
1687
  var tmp_0;
1653
- if (element.p1n_1.equals(Companion_getInstance().k1h('Handler'))) {
1688
+ if (element.q1n_1.equals(Companion_getInstance().k1h('Handler'))) {
1654
1689
  // Inline function 'community.flock.wirespec.ir.core.transform' call
1655
1690
  var scope = new TransformScope(element);
1656
1691
  // Inline function 'community.flock.wirespec.ir.core.TransformScope.injectAfter' call
@@ -1940,19 +1975,19 @@ function JavaUnionDefinitionEmitter$emit$lambda(it) {
1940
1975
  function JavaUnionDefinitionEmitter() {
1941
1976
  }
1942
1977
  //region block: post-declaration
1943
- protoOf(JavaEmitter).br = emit_12;
1978
+ protoOf(JavaEmitter).br = emit_10;
1944
1979
  protoOf(JavaEmitter).yp = emit_3;
1945
1980
  protoOf(JavaEmitter).zp = emit_4;
1946
1981
  protoOf(JavaEmitter).aq = emit_5;
1947
1982
  protoOf(JavaEmitter).bq = emit_6;
1948
1983
  protoOf(JavaEmitter).cq = emit_7;
1949
- protoOf(JavaEmitter).or = emit_9;
1950
- protoOf(JavaEmitter).v1v = emit_10;
1951
- protoOf(JavaEmitter).w1v = emit_11;
1984
+ protoOf(JavaEmitter).or = emit_12;
1985
+ protoOf(JavaEmitter).v1v = emit_13;
1986
+ protoOf(JavaEmitter).w1v = emit_14;
1952
1987
  protoOf(JavaEmitter).cr = emit_8;
1953
- protoOf(JavaEmitter).nr = emit_13;
1954
- protoOf(JavaEmitter).dr = emit_14;
1955
- protoOf(JavaEmitter).ir = emit_15;
1988
+ protoOf(JavaEmitter).nr = emit_11;
1989
+ protoOf(JavaEmitter).dr = emit_15;
1990
+ protoOf(JavaEmitter).ir = emit_9;
1956
1991
  protoOf(JavaEmitter).u1v = sanitizeSymbol;
1957
1992
  protoOf(JavaEmitter).x1v = sanitizeFirstIsDigit;
1958
1993
  protoOf(JavaEmitter).y1v = sanitizeKeywords;