@crvouga/mockingbird-service-edamam 2.1.0 → 2.2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog — @crvouga/mockingbird-service-edamam
2
2
 
3
+ ## 2.2.0 (2026-10-05)
4
+
5
+ ### Features
6
+
7
+ - add scripted local API mock ([4a76a11](https://github.com/crvouga/mockingbird/commit/4a76a114e2efad45934e0a93cf29576fd418e15c))
8
+
9
+ ### Fixes and improvements
10
+
11
+ - support embedded route parameters ([127cad9](https://github.com/crvouga/mockingbird/commit/127cad997ef106950c1b866070eea191ba54403f))
12
+
3
13
  ## 2.1.0 (2026-10-04)
4
14
 
5
15
  ### Features
@@ -12,10 +22,6 @@
12
22
  - fill the embedded viewport ([c1a35a4](https://github.com/crvouga/mockingbird/commit/c1a35a4789389ee9cd06c286d09bd47c4d06c71e))
13
23
  - make dialog cleanup immediate ([0c1a3c5](https://github.com/crvouga/mockingbird/commit/0c1a3c5b12584d50c19dcae595b951b8e5417b9c))
14
24
 
15
- ### Dependencies
16
-
17
- - `@crvouga/mockingbird-service-sqlite`
18
-
19
25
  ## 2.0.0 (2026-10-04)
20
26
 
21
27
  ### ⚠️ Breaking changes
@@ -1029,7 +1029,40 @@ var decodeBody = (contentType, bytes) => {
1029
1029
  return { kind: "bytes", value: bytes };
1030
1030
  };
1031
1031
  var readBody = async (message) => {
1032
- const bytes = new Uint8Array(await message.arrayBuffer());
1032
+ if (!(message instanceof Request) || !message.body) {
1033
+ if (message instanceof Request)
1034
+ message.signal.throwIfAborted();
1035
+ return decodeBody(message.headers.get("content-type"), new Uint8Array(await message.arrayBuffer()));
1036
+ }
1037
+ message.signal.throwIfAborted();
1038
+ const reader = message.body.getReader();
1039
+ const cancel = () => {
1040
+ void reader.cancel(message.signal.reason).catch(() => {
1041
+ });
1042
+ };
1043
+ message.signal.addEventListener("abort", cancel, { once: true });
1044
+ const chunks = [];
1045
+ let size = 0;
1046
+ try {
1047
+ for (; ; ) {
1048
+ message.signal.throwIfAborted();
1049
+ const { done, value } = await reader.read();
1050
+ message.signal.throwIfAborted();
1051
+ if (done)
1052
+ break;
1053
+ chunks.push(value);
1054
+ size += value.byteLength;
1055
+ }
1056
+ } finally {
1057
+ message.signal.removeEventListener("abort", cancel);
1058
+ reader.releaseLock();
1059
+ }
1060
+ const bytes = new Uint8Array(size);
1061
+ let offset = 0;
1062
+ for (const chunk of chunks) {
1063
+ bytes.set(chunk, offset);
1064
+ offset += chunk.byteLength;
1065
+ }
1033
1066
  return decodeBody(message.headers.get("content-type"), bytes);
1034
1067
  };
1035
1068
 
@@ -1748,7 +1781,42 @@ var verifyOperations = (document2, handlers) => {
1748
1781
  }
1749
1782
  return problems;
1750
1783
  };
1751
- var honoPath = (template) => template.replace(/\{([^}]+)\}/g, ":$1");
1784
+ var escapePattern = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1785
+ var serviceRoute = (template) => {
1786
+ const names = [];
1787
+ let pattern = "", end = 0;
1788
+ for (const match of template.matchAll(/\{([^}]+)\}/g)) {
1789
+ pattern += `${escapePattern(template.slice(end, match.index))}([^/]+?)`;
1790
+ const name = match[1];
1791
+ if (!name)
1792
+ throw new Error(`Invalid OpenAPI route template: ${template}`);
1793
+ names.push(name);
1794
+ end = match.index + match[0].length;
1795
+ }
1796
+ pattern += escapePattern(template.slice(end));
1797
+ const matcher = new RegExp(`^${pattern}$`);
1798
+ const path = template.split("/").map((segment, index) => {
1799
+ if (!segment.includes("{"))
1800
+ return segment;
1801
+ const literal = /^\{([^}]+)\}$/.exec(segment);
1802
+ if (literal)
1803
+ return `:${literal[1]}`;
1804
+ let expression = "", offset = 0;
1805
+ for (const match of segment.matchAll(/\{[^}]+\}/g)) {
1806
+ expression += `${escapePattern(segment.slice(offset, match.index))}[^/]+?`;
1807
+ offset = match.index + match[0].length;
1808
+ }
1809
+ expression += escapePattern(segment.slice(offset));
1810
+ return `:mockingbirdSegment${index}{${expression}}`;
1811
+ }).join("/");
1812
+ return {
1813
+ path,
1814
+ params: (pathname) => {
1815
+ const values = matcher.exec(pathname);
1816
+ return Object.fromEntries(names.map((name, index) => [name, decodeURIComponent(values?.[index + 1] ?? "")]));
1817
+ }
1818
+ };
1819
+ };
1752
1820
  var routeOrder = (a, b) => {
1753
1821
  const sa = a.path.split("/");
1754
1822
  const sb = b.path.split("/");
@@ -1783,6 +1851,7 @@ var createService = (options) => {
1783
1851
  for (const operation of operations) {
1784
1852
  const metadata = operationMetadata(operation.operation);
1785
1853
  const handler = options.handlers[operation.operationId];
1854
+ const registeredRoute = serviceRoute(operation.path);
1786
1855
  const route = async (c) => {
1787
1856
  const request = c.req.raw;
1788
1857
  if (!metadata.supported || !handler) {
@@ -1792,7 +1861,7 @@ var createService = (options) => {
1792
1861
  const context = {
1793
1862
  request,
1794
1863
  url,
1795
- params: c.req.param(),
1864
+ params: registeredRoute.params(url.pathname),
1796
1865
  query: queryOf(url),
1797
1866
  body: await readBody(request),
1798
1867
  sqlite: options.sqlite,
@@ -1804,7 +1873,7 @@ var createService = (options) => {
1804
1873
  const short = await options.before?.(context);
1805
1874
  return withIssues(request, short ?? await handler(context));
1806
1875
  };
1807
- app.on(operation.method.toUpperCase(), honoPath(operation.path), route);
1876
+ app.on(operation.method.toUpperCase(), registeredRoute.path, route);
1808
1877
  }
1809
1878
  return {
1810
1879
  app,
@@ -2273,7 +2342,7 @@ var stateAdminRoutes = (routes) => {
2273
2342
  };
2274
2343
 
2275
2344
  // ../core/dist/version.js
2276
- var PACKAGE_VERSION = true ? "2.1.0" : UNRELEASED_VERSION;
2345
+ var PACKAGE_VERSION = true ? "2.2.0" : UNRELEASED_VERSION;
2277
2346
 
2278
2347
  // ../core/dist/signing.js
2279
2348
  var encoder = new TextEncoder();
@@ -4413,4 +4482,4 @@ export {
4413
4482
  appIdCredential,
4414
4483
  EdamamAPI
4415
4484
  };
4416
- //# sourceMappingURL=chunk-6C4GHWO7.js.map
4485
+ //# sourceMappingURL=chunk-4KEW5NZ2.js.map