@crvouga/mockingbird-service-junction 2.1.0 → 2.2.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog — @crvouga/mockingbird-service-junction
2
2
 
3
+ ## 2.2.1 (2026-10-05)
4
+
5
+ ### Fixes and improvements
6
+
7
+ - preserve webhook mismatch context ([af69481](https://github.com/crvouga/mockingbird/commit/af694811b3840a16810915ad0c155e60b45087cf))
8
+
9
+ ## 2.2.0 (2026-10-04)
10
+
11
+ ### Features
12
+
13
+ - add scripted local API mock ([4a76a11](https://github.com/crvouga/mockingbird/commit/4a76a114e2efad45934e0a93cf29576fd418e15c))
14
+
15
+ ### Fixes and improvements
16
+
17
+ - support embedded route parameters ([127cad9](https://github.com/crvouga/mockingbird/commit/127cad997ef106950c1b866070eea191ba54403f))
18
+
3
19
  ## 2.1.0 (2026-10-04)
4
20
 
5
21
  ### Features
@@ -12,10 +28,6 @@
12
28
  - fill the embedded viewport ([c1a35a4](https://github.com/crvouga/mockingbird/commit/c1a35a4789389ee9cd06c286d09bd47c4d06c71e))
13
29
  - make dialog cleanup immediate ([0c1a3c5](https://github.com/crvouga/mockingbird/commit/0c1a3c5b12584d50c19dcae595b951b8e5417b9c))
14
30
 
15
- ### Dependencies
16
-
17
- - `@crvouga/mockingbird-service-sqlite`
18
-
19
31
  ## 2.0.0 (2026-10-04)
20
32
 
21
33
  ### ⚠️ Breaking changes
@@ -824,7 +824,40 @@ var decodeBody = (contentType, bytes) => {
824
824
  return { kind: "bytes", value: bytes };
825
825
  };
826
826
  var readBody = async (message) => {
827
- const bytes = new Uint8Array(await message.arrayBuffer());
827
+ if (!(message instanceof Request) || !message.body) {
828
+ if (message instanceof Request)
829
+ message.signal.throwIfAborted();
830
+ return decodeBody(message.headers.get("content-type"), new Uint8Array(await message.arrayBuffer()));
831
+ }
832
+ message.signal.throwIfAborted();
833
+ const reader = message.body.getReader();
834
+ const cancel = () => {
835
+ void reader.cancel(message.signal.reason).catch(() => {
836
+ });
837
+ };
838
+ message.signal.addEventListener("abort", cancel, { once: true });
839
+ const chunks = [];
840
+ let size = 0;
841
+ try {
842
+ for (; ; ) {
843
+ message.signal.throwIfAborted();
844
+ const { done, value } = await reader.read();
845
+ message.signal.throwIfAborted();
846
+ if (done)
847
+ break;
848
+ chunks.push(value);
849
+ size += value.byteLength;
850
+ }
851
+ } finally {
852
+ message.signal.removeEventListener("abort", cancel);
853
+ reader.releaseLock();
854
+ }
855
+ const bytes = new Uint8Array(size);
856
+ let offset = 0;
857
+ for (const chunk of chunks) {
858
+ bytes.set(chunk, offset);
859
+ offset += chunk.byteLength;
860
+ }
828
861
  return decodeBody(message.headers.get("content-type"), bytes);
829
862
  };
830
863
 
@@ -1488,7 +1521,42 @@ var verifyOperations = (document2, handlers) => {
1488
1521
  }
1489
1522
  return problems;
1490
1523
  };
1491
- var honoPath = (template) => template.replace(/\{([^}]+)\}/g, ":$1");
1524
+ var escapePattern = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1525
+ var serviceRoute = (template) => {
1526
+ const names = [];
1527
+ let pattern = "", end = 0;
1528
+ for (const match of template.matchAll(/\{([^}]+)\}/g)) {
1529
+ pattern += `${escapePattern(template.slice(end, match.index))}([^/]+?)`;
1530
+ const name = match[1];
1531
+ if (!name)
1532
+ throw new Error(`Invalid OpenAPI route template: ${template}`);
1533
+ names.push(name);
1534
+ end = match.index + match[0].length;
1535
+ }
1536
+ pattern += escapePattern(template.slice(end));
1537
+ const matcher = new RegExp(`^${pattern}$`);
1538
+ const path = template.split("/").map((segment, index) => {
1539
+ if (!segment.includes("{"))
1540
+ return segment;
1541
+ const literal = /^\{([^}]+)\}$/.exec(segment);
1542
+ if (literal)
1543
+ return `:${literal[1]}`;
1544
+ let expression = "", offset = 0;
1545
+ for (const match of segment.matchAll(/\{[^}]+\}/g)) {
1546
+ expression += `${escapePattern(segment.slice(offset, match.index))}[^/]+?`;
1547
+ offset = match.index + match[0].length;
1548
+ }
1549
+ expression += escapePattern(segment.slice(offset));
1550
+ return `:mockingbirdSegment${index}{${expression}}`;
1551
+ }).join("/");
1552
+ return {
1553
+ path,
1554
+ params: (pathname) => {
1555
+ const values = matcher.exec(pathname);
1556
+ return Object.fromEntries(names.map((name, index) => [name, decodeURIComponent(values?.[index + 1] ?? "")]));
1557
+ }
1558
+ };
1559
+ };
1492
1560
  var routeOrder = (a, b) => {
1493
1561
  const sa = a.path.split("/");
1494
1562
  const sb = b.path.split("/");
@@ -1523,6 +1591,7 @@ var createService = (options) => {
1523
1591
  for (const operation of operations) {
1524
1592
  const metadata = operationMetadata(operation.operation);
1525
1593
  const handler = options.handlers[operation.operationId];
1594
+ const registeredRoute = serviceRoute(operation.path);
1526
1595
  const route = async (c) => {
1527
1596
  const request2 = c.req.raw;
1528
1597
  if (!metadata.supported || !handler) {
@@ -1532,7 +1601,7 @@ var createService = (options) => {
1532
1601
  const context = {
1533
1602
  request: request2,
1534
1603
  url,
1535
- params: c.req.param(),
1604
+ params: registeredRoute.params(url.pathname),
1536
1605
  query: queryOf(url),
1537
1606
  body: await readBody(request2),
1538
1607
  sqlite: options.sqlite,
@@ -1544,7 +1613,7 @@ var createService = (options) => {
1544
1613
  const short = await options.before?.(context);
1545
1614
  return withIssues(request2, short ?? await handler(context));
1546
1615
  };
1547
- app.on(operation.method.toUpperCase(), honoPath(operation.path), route);
1616
+ app.on(operation.method.toUpperCase(), registeredRoute.path, route);
1548
1617
  }
1549
1618
  return {
1550
1619
  app,
@@ -2013,7 +2082,7 @@ var stateAdminRoutes = (routes) => {
2013
2082
  };
2014
2083
 
2015
2084
  // ../core/dist/version.js
2016
- var PACKAGE_VERSION = true ? "2.1.0" : UNRELEASED_VERSION;
2085
+ var PACKAGE_VERSION = true ? "2.2.1" : UNRELEASED_VERSION;
2017
2086
 
2018
2087
  // ../core/dist/webhooks.js
2019
2088
  var json4 = (status, body) => new Response(JSON.stringify(body), {
@@ -10749,4 +10818,4 @@ export {
10749
10818
  JunctionAPI,
10750
10819
  LabAccountConflict
10751
10820
  };
10752
- //# sourceMappingURL=chunk-5QNXPRLG.js.map
10821
+ //# sourceMappingURL=chunk-5EF324W7.js.map