gemi 0.4.2 → 0.4.3

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/dist/app/App.d.ts CHANGED
@@ -1,6 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="bun-types" />
3
- /// <reference types="bun-types" />
4
1
  import type { ApiRouter } from "../http/ApiRouter";
5
2
  import { ViewRouter } from "../http/ViewRouter";
6
3
  import type { ComponentTree } from "../client/types";
@@ -10,9 +7,9 @@ import type { ServerWebSocket } from "bun";
10
7
  import { ComponentType } from "react";
11
8
  interface RenderParams {
12
9
  styles: string[];
13
- views: Record<string, string>;
14
10
  manifest: Record<string, any>;
15
11
  serverManifest: Record<string, any>;
12
+ bootstrapModules?: string[];
16
13
  }
17
14
  interface AppParams {
18
15
  viewRouter: new () => ViewRouter;
@@ -22,6 +19,7 @@ interface AppParams {
22
19
  root: ComponentType;
23
20
  }
24
21
  export declare class App {
22
+ private renderParams;
25
23
  private flatViewRoutes;
26
24
  private flatApiRoutes;
27
25
  private routeManifest;
@@ -36,11 +34,13 @@ export declare class App {
36
34
  private Root;
37
35
  constructor(params: AppParams);
38
36
  private prepare;
39
- printName(): void;
40
37
  getComponentTree(): ComponentTree;
38
+ setRenderParams(params: RenderParams): void;
41
39
  private resolvePageData;
42
- handleRequest(req: Request): Promise<any>;
43
- fetch(req: Request, renderParams: RenderParams): Promise<Response>;
40
+ private runMiddleware;
41
+ handleApiRequest(req: Request): Promise<Response>;
42
+ handleViewRequest(req: Request): Promise<Response>;
43
+ fetch(req: Request): Promise<Response>;
44
44
  private handleWebSocketMessage;
45
45
  private handleWebSocketOpen;
46
46
  private handleWebSocketClose;
@@ -1 +1 @@
1
- {"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../../app/App.ts"],"names":[],"mappings":";;;AAAA,OAAO,KAAK,EAGV,SAAS,EACV,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAsB,MAAM,oBAAoB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AM,EAAE,UAAU,UAAU,CAAC,CAAC;IACzD,IAAI,EAAE,aAAa,CAAC;CACrB;AAED,qBAAa,GAAG;IACd,OAAO,CAAC,YAAY,CAKlB;IACF,OAAO,CAAC,cAAc,CAGf;IACP,OAAO,CAAC,aAAa,CASd;IACP,OAAO,CAAC,aAAa,CAAgC;IAC9C,IAAI,SAAS;IACpB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,aAAa,CAAgB;IAC9B,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,UAAU,CAAC,CAAM;IAC7D,UAAU,SAAK;IACtB,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,SAAS,CAAsB;IACvC,OAAO,CAAC,UAAU,CAAuB;IACzC,OAAO,CAAC,IAAI,CAAgB;gBAEhB,MAAM,EAAE,SAAS;IAU7B,OAAO,CAAC,OAAO;IAkCR,gBAAgB;IAIhB,eAAe,CAAC,MAAM,EAAE,YAAY;YAI7B,eAAe;IAqC7B,OAAO,CAAC,aAAa;IAmCf,gBAAgB,CAAC,GAAG,EAAE,OAAO;IAwF7B,iBAAiB,CAAC,GAAG,EAAE,OAAO;IA+L9B,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;IAU5C,OAAO,CAAC,sBAAsB,CAGtB;IACR,OAAO,CAAC,mBAAmB,CAEzB;IACF,OAAO,CAAC,oBAAoB,CAM1B;IAEF,SAAS;sBAdH,eAAe,WACV,MAAM,GAAG,MAAM;mBAES,eAAe;oBAI5C,eAAe,QACb,MAAM,UACJ,MAAM;MASd;CACH"}
package/dist/app/index.js CHANGED
@@ -723,14 +723,14 @@ class ApiRouter {
723
723
  method,
724
724
  exec: async (req, params, app) => {
725
725
  let handler = (_req, params2) => Promise.resolve({});
726
- let httpRequest = new HttpRequest(req);
726
+ let httpRequest = new HttpRequest(req.rawRequest);
727
727
  if (isController(controller)) {
728
728
  const controllerInstance = new controller(app);
729
729
  const Req = controllerInstance.requests[methodName] ?? HttpRequest;
730
- httpRequest = new Req(req);
730
+ httpRequest = new Req(req.rawRequest);
731
731
  handler = controllerInstance[methodName].bind(controllerInstance);
732
732
  } else if (typeof controller === "function") {
733
- handler = (req2) => controller(new HttpRequest(req2));
733
+ handler = (req2) => controller(req2);
734
734
  }
735
735
  return await handler(httpRequest, params);
736
736
  }
@@ -1849,6 +1849,12 @@ function isConstructor(value) {
1849
1849
 
1850
1850
  // app/App.ts
1851
1851
  class App {
1852
+ renderParams = {
1853
+ styles: [],
1854
+ manifest: {},
1855
+ serverManifest: {},
1856
+ bootstrapModules: []
1857
+ };
1852
1858
  flatViewRoutes = {};
1853
1859
  flatApiRoutes = {};
1854
1860
  routeManifest = {};
@@ -1898,12 +1904,12 @@ class App {
1898
1904
  this.routeManifest = createRouteManifest(viewRouters);
1899
1905
  this.flatApiRoutes = createFlatApiRoutes(apiRouters);
1900
1906
  }
1901
- printName() {
1902
- console.log(this.name);
1903
- }
1904
1907
  getComponentTree() {
1905
1908
  return this.componentTree;
1906
1909
  }
1910
+ setRenderParams(params) {
1911
+ this.renderParams = params;
1912
+ }
1907
1913
  async resolvePageData(req) {
1908
1914
  const url = new URL(req.url);
1909
1915
  let handlers = [];
@@ -1920,19 +1926,7 @@ class App {
1920
1926
  middlewares = handler.middleware;
1921
1927
  }
1922
1928
  }
1923
- const reqWithMiddlewares = middlewares.map((middleware) => {
1924
- if (typeof middleware === "string") {
1925
- return new this.middlewareAliases[middleware]().run;
1926
- }
1927
- return middleware;
1928
- }).reduce((acc, middleware) => {
1929
- return async (req2, ctx) => {
1930
- return {
1931
- ...await acc(req2, ctx),
1932
- ...await middleware(req2, ctx)
1933
- };
1934
- };
1935
- }, (_req, _ctx) => Promise.resolve({}));
1929
+ const reqWithMiddlewares = this.runMiddleware(middlewares);
1936
1930
  const reqCtx = new Map;
1937
1931
  const data = await requestContext.run(reqCtx, async () => {
1938
1932
  await reqWithMiddlewares(new HttpRequest(req), reqCtx);
@@ -1945,247 +1939,259 @@ class App {
1945
1939
  user: reqCtx.get("user") ?? null
1946
1940
  };
1947
1941
  }
1948
- async handleRequest(req) {
1942
+ runMiddleware(middleware) {
1943
+ return middleware.map((aliasOrTest) => {
1944
+ if (typeof aliasOrTest === "string") {
1945
+ const alias = aliasOrTest;
1946
+ if (this.middlewareAliases?.[alias]) {
1947
+ const middleware2 = new this.middlewareAliases[alias];
1948
+ return middleware2.run;
1949
+ }
1950
+ } else {
1951
+ if (isConstructor(aliasOrTest)) {
1952
+ const middleware2 = new aliasOrTest;
1953
+ return middleware2.run;
1954
+ }
1955
+ return aliasOrTest;
1956
+ }
1957
+ }).filter(Boolean).reduce((acc, middleware2) => {
1958
+ return async (req, ctx) => {
1959
+ return {
1960
+ ...await acc(req, ctx),
1961
+ ...await middleware2(req, ctx)
1962
+ };
1963
+ };
1964
+ }, (_req) => Promise.resolve({}));
1965
+ }
1966
+ async handleApiRequest(req) {
1949
1967
  const url = new URL(req.url);
1950
- if (url.pathname.startsWith("/api")) {
1951
- const apiPath = url.pathname.replace("/api", "");
1952
- for (const [path, handler] of Object.entries(this.flatApiRoutes)) {
1953
- const pattern = new me({ pathname: path });
1954
- if (pattern.test({ pathname: apiPath })) {
1955
- const params = pattern.exec({ pathname: apiPath })?.pathname.groups;
1956
- if (!handler[req.method.toLowerCase()]) {
1957
- return {
1958
- kind: "api_404"
1959
- };
1960
- }
1961
- const exec = handler[req.method.toLowerCase()].exec;
1962
- const middlewares = handler[req.method.toLowerCase()].middleware;
1963
- const reqWithMiddlewares = middlewares.map((aliasOrTest) => {
1964
- if (typeof aliasOrTest === "string") {
1965
- const alias = aliasOrTest;
1966
- if (this.middlewareAliases?.[alias]) {
1967
- const middleware = new this.middlewareAliases[alias];
1968
- return middleware.run;
1969
- }
1968
+ const apiPath = url.pathname.replace("/api", "");
1969
+ for (const [path, handler] of Object.entries(this.flatApiRoutes)) {
1970
+ const pattern = new me({ pathname: path });
1971
+ if (pattern.test({ pathname: apiPath })) {
1972
+ const params = pattern.exec({ pathname: apiPath })?.pathname.groups;
1973
+ if (!handler[req.method.toLowerCase()]) {
1974
+ return new Response(JSON.stringify({ error: { message: "Not found" } }));
1975
+ }
1976
+ const exec = handler[req.method.toLowerCase()].exec;
1977
+ const middlewares = handler[req.method.toLowerCase()].middleware;
1978
+ const reqWithMiddlewares = this.runMiddleware(middlewares);
1979
+ const reqCtx = new Map;
1980
+ return await requestContext.run(reqCtx, async () => {
1981
+ const httpRequest = new HttpRequest(req);
1982
+ let handler2 = exec ? () => exec(httpRequest, params, this) : () => Promise.resolve({});
1983
+ try {
1984
+ await reqWithMiddlewares(httpRequest, reqCtx);
1985
+ } catch (err) {
1986
+ if (err.kind === GEMI_REQUEST_BREAKER_ERROR) {
1987
+ const { status = 400, data: data2, headers } = err.payload.api;
1988
+ return new Response(JSON.stringify(data2), {
1989
+ status,
1990
+ headers: {
1991
+ "Content-Type": "application/json",
1992
+ ...headers
1993
+ }
1994
+ });
1970
1995
  } else {
1971
- if (isConstructor(aliasOrTest)) {
1972
- const middleware = new aliasOrTest;
1973
- return middleware.run;
1974
- }
1975
- return aliasOrTest;
1976
- }
1977
- }).filter(Boolean).reduce((acc, middleware) => {
1978
- return async (req2, ctx) => {
1979
- return {
1980
- ...await acc(req2, ctx),
1981
- ...await middleware(req2, ctx)
1982
- };
1983
- };
1984
- }, (req2) => Promise.resolve({}));
1985
- const reqCtx = new Map;
1986
- return await requestContext.run(reqCtx, async () => {
1987
- try {
1988
- await reqWithMiddlewares(new HttpRequest(req), reqCtx);
1989
- } catch (err) {
1990
- if (err.kind === GEMI_REQUEST_BREAKER_ERROR) {
1991
- return {
1992
- kind: "apiError",
1993
- ...err.payload.api
1994
- };
1995
- } else {
1996
- throw err;
1997
- }
1996
+ throw err;
1998
1997
  }
1999
- if (exec) {
2000
- let data = {};
2001
- try {
2002
- data = await exec(req, params, this);
2003
- } catch (err) {
2004
- if (err.kind === GEMI_REQUEST_BREAKER_ERROR) {
2005
- return {
2006
- kind: "apiError",
2007
- ...err.payload.api
2008
- };
2009
- } else {
2010
- throw err;
2011
- }
2012
- }
2013
- return {
2014
- kind: "api",
2015
- data,
1998
+ }
1999
+ let data = {};
2000
+ try {
2001
+ data = await handler2();
2002
+ } catch (err) {
2003
+ if (err.kind === GEMI_REQUEST_BREAKER_ERROR) {
2004
+ const { status = 400, data: data2, headers } = err.payload.api;
2005
+ return new Response(JSON.stringify(data2), {
2006
+ status,
2016
2007
  headers: {
2017
- "Set-Cookie": Object.entries({}).map(([name, config]) => {
2018
- return `${name}=${config.value}; HttpOnly; SameSite=Strict; Path=/; Max-Age=${config.maxAge}`;
2019
- }).join(", ")
2008
+ "Content-Type": "application/json",
2009
+ ...headers
2020
2010
  }
2021
- };
2011
+ });
2012
+ } else {
2013
+ throw err;
2014
+ }
2015
+ }
2016
+ const result = {
2017
+ kind: "api",
2018
+ data,
2019
+ headers: {
2020
+ "Set-Cookie": Object.entries({}).map(([name, config]) => {
2021
+ return `${name}=${config.value}; HttpOnly; SameSite=Strict; Path=/; Max-Age=${config.maxAge}`;
2022
+ }).join(", ")
2023
+ }
2024
+ };
2025
+ return new Response(JSON.stringify(result.data), {
2026
+ headers: {
2027
+ "Content-Type": "application/json",
2028
+ ...result.headers
2022
2029
  }
2023
2030
  });
2024
- }
2031
+ });
2025
2032
  }
2026
- return {
2027
- kind: "api_404"
2028
- };
2029
- } else {
2030
- let pageData = null;
2031
- try {
2032
- pageData = await this.resolvePageData(req);
2033
- } catch (err) {
2034
- if (err instanceof RequestBreakerError) {
2035
- return {
2036
- kind: "viewError",
2037
- ...err.payload.view
2038
- };
2033
+ }
2034
+ return new Response(JSON.stringify({ error: { message: "Not found" } }), {
2035
+ status: 404
2036
+ });
2037
+ }
2038
+ async handleViewRequest(req) {
2039
+ const url = new URL(req.url);
2040
+ let pageData = null;
2041
+ try {
2042
+ let handlers = [];
2043
+ let middlewares = [];
2044
+ let currentPathName2 = null;
2045
+ let params2 = {};
2046
+ const sortedEntries = Object.entries(this.flatViewRoutes).sort(([pathA], [pathB]) => pathB.length - pathA.length);
2047
+ for (const [pathname, handler] of sortedEntries) {
2048
+ const pattern = new me({ pathname });
2049
+ if (pattern.test({ pathname: url.pathname })) {
2050
+ currentPathName2 = pathname;
2051
+ params2 = pattern.exec({ pathname: url.pathname })?.pathname.groups;
2052
+ handlers = handler.exec;
2053
+ middlewares = handler.middleware;
2039
2054
  }
2040
2055
  }
2041
- if (!pageData) {
2042
- return {
2043
- kind: "",
2044
- data: {},
2045
- meta: [],
2046
- headers: {}
2047
- };
2048
- }
2049
- const { data, params, currentPathName, user } = pageData;
2050
- const viewData = data.reduce((acc, data2) => {
2051
- return {
2052
- ...acc,
2053
- ...data2
2054
- };
2055
- }, {});
2056
- if (url.searchParams.get("json")) {
2057
- return {
2058
- kind: "viewData",
2059
- data: {
2060
- [url.pathname]: viewData
2061
- },
2062
- meta: [],
2063
- headers: {}
2064
- };
2056
+ if (!currentPathName2) {
2057
+ return new Response(null, {
2058
+ status: 404
2059
+ });
2065
2060
  }
2066
- let cookieHeaders = {};
2067
- const visitorIdExist = req.headers.get("cookie")?.includes("visitor_id");
2068
- if (!visitorIdExist) {
2069
- cookieHeaders = {
2070
- "Set-Cookie": `visitor_id=${v4()}; HttpOnly; SameSite=Strict; Path=/`
2071
- };
2061
+ const reqWithMiddlewares = this.runMiddleware(middlewares);
2062
+ const reqCtx = new Map;
2063
+ const data2 = await requestContext.run(reqCtx, async () => {
2064
+ await reqWithMiddlewares(new HttpRequest(req), reqCtx);
2065
+ return await Promise.all(handlers.map((fn) => fn(req, params2, this)));
2066
+ });
2067
+ pageData = {
2068
+ data: data2,
2069
+ currentPathName: currentPathName2,
2070
+ params: params2,
2071
+ user: reqCtx.get("user") ?? null
2072
+ };
2073
+ } catch (err) {
2074
+ if (err.kind === GEMI_REQUEST_BREAKER_ERROR) {
2075
+ return new Response(null, {
2076
+ ...err.payload.view
2077
+ });
2072
2078
  }
2079
+ }
2080
+ if (!pageData) {
2081
+ return new Response("<div>404</div>");
2082
+ }
2083
+ const { data, params, currentPathName, user } = pageData;
2084
+ const viewData = data.reduce((acc, data2) => {
2073
2085
  return {
2074
- kind: "view",
2086
+ ...acc,
2087
+ ...data2
2088
+ };
2089
+ }, {});
2090
+ if (url.searchParams.get("json")) {
2091
+ const result2 = {
2092
+ kind: "viewData",
2075
2093
  data: {
2076
- pageData: {
2077
- [url.pathname]: viewData
2078
- },
2079
- auth: { user },
2080
- routeManifest: this.routeManifest,
2081
- router: {
2082
- pathname: currentPathName,
2083
- params,
2084
- currentPath: url.pathname,
2085
- is404: false
2086
- },
2087
- componentTree: [["404", []], ...this.componentTree]
2088
- },
2089
- head: {},
2090
- headers: {
2091
- "Content-Type": "text/html",
2092
- "Cache-Control": user ? "private, no-cache, no-store, max-age=0, must-revalidate" : "public, max-age=864000, must-revalidate",
2093
- ETag: this.appId,
2094
- ...cookieHeaders
2094
+ [url.pathname]: viewData
2095
2095
  },
2096
- status: 200
2096
+ meta: [],
2097
+ headers: {}
2097
2098
  };
2098
- }
2099
- }
2100
- async fetch(req, renderParams) {
2101
- const result = await this.handleRequest(req);
2102
- if (result.kind === "api_404") {
2103
- return new Response("Not found", { status: 404 });
2104
- }
2105
- if (result.kind === "viewError") {
2106
- const { kind, ...payload } = result;
2107
- return new Response(null, {
2108
- ...payload
2109
- });
2110
- }
2111
- if (result.kind === "apiError") {
2112
- const { kind, data, ...payload } = result;
2113
- return new Response(JSON.stringify(data), {
2114
- ...payload
2115
- });
2116
- }
2117
- if (!result) {
2118
- return new Response("Not found", { status: 404 });
2119
- }
2120
- if (result.kind === "viewData") {
2121
- const { data, headers, head } = result;
2122
2099
  return new Response(JSON.stringify({
2123
- data,
2124
- head
2100
+ data: result2.data,
2101
+ head: {}
2125
2102
  }), {
2126
2103
  headers: {
2127
- ...headers,
2104
+ ...result2.headers,
2128
2105
  "Content-Type": "application/json"
2129
2106
  }
2130
2107
  });
2131
2108
  }
2132
- if (result.kind === "view") {
2133
- const { data, headers, status } = result;
2134
- const { styles, views, manifest, serverManifest, ...renderOptions } = renderParams;
2135
- const viewImportMap = {};
2136
- let appDir = null;
2137
- const template = (viewName, path) => `"${viewName}": () => import("${path}")`;
2138
- const templates = [];
2139
- for (const fileName of [
2140
- "404",
2141
- ...flattenComponentTree(this.componentTree)
2142
- ]) {
2143
- if (!manifest) {
2144
- appDir = `${process.env.APP_DIR}`;
2145
- const mod = await import(`${appDir}/views/${fileName}.tsx`);
2146
- viewImportMap[fileName] = mod.default;
2147
- templates.push(template(fileName, `${appDir}/views/${fileName}.tsx`));
2148
- } else {
2149
- const { file } = serverManifest[`app/views/${fileName}.tsx`];
2150
- const mod = await import(`${process.env.DIST_DIR}/server/${file}`);
2151
- viewImportMap[fileName] = mod.default;
2152
- const clientFile = manifest[`app/views/${fileName}.tsx`];
2153
- if (clientFile) {
2154
- templates.push(template(fileName, `/${clientFile.file}`));
2155
- }
2156
- }
2109
+ let cookieHeaders = {};
2110
+ const visitorIdExist = req.headers.get("cookie")?.includes("visitor_id");
2111
+ if (!visitorIdExist) {
2112
+ cookieHeaders = {
2113
+ "Set-Cookie": `visitor_id=${v4()}; HttpOnly; SameSite=Strict; Path=/`
2114
+ };
2115
+ }
2116
+ const { styles, manifest, serverManifest, bootstrapModules } = this.renderParams;
2117
+ const viewImportMap = {};
2118
+ let appDir = null;
2119
+ const template = (viewName, path) => `"${viewName}": () => import("${path}")`;
2120
+ const templates = [];
2121
+ for (const fileName of [
2122
+ "404",
2123
+ ...flattenComponentTree(this.componentTree)
2124
+ ]) {
2125
+ if (false) {
2157
2126
  }
2158
- const loaders = `{${templates.join(",")}}`;
2159
- const stream = await renderToReadableStream(createElement(Fragment, {
2160
- children: [
2161
- styles,
2162
- createElement(this.Root, {
2163
- data,
2164
- viewImportMap
2165
- })
2166
- ]
2167
- }), {
2168
- bootstrapScriptContent: `window.__GEMI_DATA__ = ${JSON.stringify(data)}; window.loaders=${loaders}`,
2169
- ...renderOptions
2170
- });
2171
- return new Response(stream, {
2172
- status,
2173
- headers: {
2174
- "Content-Type": "text/html",
2175
- ...headers
2127
+ if (!manifest) {
2128
+ appDir = `${process.env.APP_DIR}`;
2129
+ const mod = await import(`${appDir}/views/${fileName}.tsx`);
2130
+ viewImportMap[fileName] = mod.default;
2131
+ templates.push(template(fileName, `${appDir}/views/${fileName}.tsx`));
2132
+ } else {
2133
+ const serverFile = serverManifest[`app/views/${fileName}.tsx`];
2134
+ const mod = await import(`${process.env.DIST_DIR}/server/${serverFile?.file}`);
2135
+ viewImportMap[fileName] = mod.default;
2136
+ const clientFile = manifest[`app/views/${fileName}.tsx`];
2137
+ if (clientFile) {
2138
+ templates.push(template(fileName, `/${clientFile?.file}`));
2176
2139
  }
2177
- });
2140
+ }
2178
2141
  }
2179
- if (result.kind === "api") {
2180
- const { data, headers } = result;
2181
- return new Response(JSON.stringify(data), {
2182
- headers: {
2183
- "Content-Type": "application/json",
2184
- ...headers
2185
- }
2186
- });
2142
+ const loaders = `{${templates.join(",")}}`;
2143
+ const result = {
2144
+ kind: "view",
2145
+ data: {
2146
+ pageData: {
2147
+ [url.pathname]: viewData
2148
+ },
2149
+ auth: { user },
2150
+ routeManifest: this.routeManifest,
2151
+ router: {
2152
+ pathname: currentPathName,
2153
+ params,
2154
+ currentPath: url.pathname,
2155
+ is404: false
2156
+ },
2157
+ componentTree: [["404", []], ...this.componentTree]
2158
+ },
2159
+ head: {},
2160
+ headers: {
2161
+ "Content-Type": "text/html",
2162
+ "Cache-Control": user ? "private, no-cache, no-store, max-age=0, must-revalidate" : "public, max-age=864000, must-revalidate",
2163
+ ETag: this.appId,
2164
+ ...cookieHeaders
2165
+ },
2166
+ status: 200
2167
+ };
2168
+ const stream = await renderToReadableStream(createElement(Fragment, {
2169
+ children: [
2170
+ styles,
2171
+ createElement(this.Root, {
2172
+ data: result.data,
2173
+ viewImportMap
2174
+ })
2175
+ ]
2176
+ }), {
2177
+ bootstrapScriptContent: `window.__GEMI_DATA__ = ${JSON.stringify(result.data)}; window.loaders=${loaders}`,
2178
+ bootstrapModules
2179
+ });
2180
+ return new Response(stream, {
2181
+ status: result.status,
2182
+ headers: {
2183
+ "Content-Type": "text/html",
2184
+ ...result.headers
2185
+ }
2186
+ });
2187
+ }
2188
+ async fetch(req) {
2189
+ const url = new URL(req.url);
2190
+ if (url.pathname.startsWith("/api")) {
2191
+ return await this.handleApiRequest(req);
2192
+ } else {
2193
+ return await this.handleViewRequest(req);
2187
2194
  }
2188
- return new Response("Not found", { status: 404 });
2189
2195
  }
2190
2196
  handleWebSocketMessage = (ws, message) => {
2191
2197
  };
package/dist/bin/gemi CHANGED
Binary file
@@ -1 +1 @@
1
- {"version":3,"file":"ClientRouter.d.ts","sourceRoot":"","sources":["../../client/ClientRouter.tsx"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,aAAa,EACnB,MAAM,OAAO,CAAC;AAkFf,eAAO,MAAM,YAAY,UAAW;IAClC,aAAa,CAAC,EAAE,OAAO,MAAM,EAAE,GAAG,CAAC,CAAC;IACpC,UAAU,EAAE,cAAc,GAAG,CAAC,CAAC;CAChC,4CA2BA,CAAC"}
1
+ {"version":3,"file":"ClientRouter.d.ts","sourceRoot":"","sources":["../../client/ClientRouter.tsx"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,aAAa,EACnB,MAAM,OAAO,CAAC;AAkFf,eAAO,MAAM,YAAY,UAAW;IAClC,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACpC,UAAU,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;CAChC,4CA2BA,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"ClientRouterContext.d.ts","sourceRoot":"","sources":["../../client/ClientRouterContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,EAAE,EACP,KAAK,QAAQ,EAEd,MAAM,SAAS,CAAC;AACjB,OAAO,EAOL,KAAK,cAAc,EACnB,KAAK,iBAAiB,EAC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AAK,EAAE,MAAM,KAAK,KAAK,CAAC,SAAS,CAAC;CAC7C,8GAWF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"Image.d.ts","sourceRoot":"","sources":["../../client/Image.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAyC5C,UAAU,UAAU;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,KAAK,UAAW,eAAe,KAAK,CAAC,GAAG,UAAU,4CAwB9D,CAAC"}
1
+ {"version":3,"file":"Image.d.ts","sourceRoot":"","sources":["../../client/Image.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAyC5C,UAAU,UAAU;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,KAAK,UAAW,cAAc,CAAC,KAAK,CAAC,GAAG,UAAU,4CAwB9D,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"Mutation.d.ts","sourceRoot":"","sources":["../../client/Mutation.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,iBAAiB,EAItB,KAAK,cAAc,EAGpB,MAAM,OAAO,CAAC;AAcf,UAAU,aAAa;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;IACrD,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;CACnC;AAED,eAAO,MAAM,QAAQ,UAAW,kBAAkB,aAAa,CAAC,4CA2D/D,CAAC;AAEF,wBAAgB,iBAAiB;;EAIhC;AAED,eAAO,MAAM,gBAAgB,UAAW;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,CAAC,KAAK,WAAW,CAAC;CACxD,4CAwBA,CAAC;AAEF,eAAO,MAAM,SAAS,UAAW,eAAe,KAAK,CAAC,4CAQrD,CAAC"}
1
+ {"version":3,"file":"Mutation.d.ts","sourceRoot":"","sources":["../../client/Mutation.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,iBAAiB,EAItB,KAAK,cAAc,EAGpB,MAAM,OAAO,CAAC;AAcf,UAAU,aAAa;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;IACrD,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;CACnC;AAED,eAAO,MAAM,QAAQ,UAAW,iBAAiB,CAAC,aAAa,CAAC,4CA2D/D,CAAC;AAEF,wBAAgB,iBAAiB;;EAIhC;AAED,eAAO,MAAM,gBAAgB,UAAW;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,OAAO,CAAC;CACxD,4CAwBA,CAAC;AAEF,eAAO,MAAM,SAAS,UAAW,cAAc,CAAC,KAAK,CAAC,4CAQrD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"ServerDataProvider.d.ts","sourceRoot":"","sources":["../../client/ServerDataProvider.tsx"],"names":[],"mapp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AAM,SAAS,CAAC;AAE7C,KAAK,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAEhC,MAAM,WAAW,sBAAsB;IACrC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACxC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IAC/C,MAAM,EAAE;QACN,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC5B,WAAW,EAAE,MAAM,CAAC;QACpB,KAAK,EAAE,OAAO,CAAC;KAChB,CAAC;IACF,aAAa,EAAE,aAAa,CAAC;IAC7B,IAAI,EAAE;QACJ,IAAI,EAAE;YACJ,IAAI,EAAE,MAAM,CAAC;YACb,KAAK,EAAE,MAAM,CAAC;YACd,QAAQ,EAAE,KAAK,CAAC;gBACd,cAAc,EAAE,MAAM,CAAC;gBACvB,IAAI,EAAE,MAAM,CAAC;aACd,CAAC,CAAC;YACH,UAAU,EAAE,MAAM,CAAC;YACnB,EAAE,EAAE,MAAM,CAAC;SACZ,CAAC;KACH,CAAC;CACH;AAED,eAAO,MAAM,iBAAiB,iDAA8C,CAAC;AAE7E,UAAU,uBAAuB;IAC/B,KAAK,CAAC,EAAE,sBAAsB,CAAC;CAChC;AAED,eAAO,MAAM,kBAAkB,UACtB,iBAAiB,CAAC,uBAAuB,CAAC,4CAgBlD,CAAC"}
@@ -29381,7 +29381,7 @@ function flattenComponentTree(componentTree) {
29381
29381
  return Array.from(new Set(out));
29382
29382
  }
29383
29383
  let viewImportMap = null;
29384
- if (typeof window !== "undefined") {
29384
+ if (typeof window !== "undefined" && process.env.NODE_ENV !== "test") {
29385
29385
  viewImportMap = {};
29386
29386
  const { componentTree } = window.__GEMI_DATA__;
29387
29387
  for (const viewName of flattenComponentTree(componentTree)) {
@@ -8745,7 +8745,7 @@ var __async2 = (__this, __arguments, generator) => {
8745
8745
  step((generator = generator.apply(__this, __arguments)).next());
8746
8746
  });
8747
8747
  };
8748
- var version = "3.3.0";
8748
+ var version = "3.4.0";
8749
8749
  var ApiKeys = class {
8750
8750
  constructor(resend) {
8751
8751
  this.resend = resend;
@@ -8935,17 +8935,6 @@ var Emails = class {
8935
8935
  });
8936
8936
  }
8937
8937
  };
8938
- var isResendErrorResponse = (response) => {
8939
- if (typeof response !== "object" || response === null) {
8940
- return false;
8941
- }
8942
- const error = response;
8943
- if (typeof error !== "object" || error === null) {
8944
- return false;
8945
- }
8946
- const { message, name: name2 } = error;
8947
- return typeof message === "string" && typeof name2 === "string";
8948
- };
8949
8938
  var defaultBaseUrl = "https://api.resend.com";
8950
8939
  var defaultUserAgent = `resend-node:${version}`;
8951
8940
  var baseUrl = typeof process !== "undefined" && process.env ? process.env.RESEND_BASE_URL || defaultBaseUrl : defaultBaseUrl;
@@ -8975,27 +8964,43 @@ var Resend = class {
8975
8964
  }
8976
8965
  fetchRequest(_0) {
8977
8966
  return __async2(this, arguments, function* (path, options = {}) {
8978
- const response = yield fetch(`${baseUrl}${path}`, options);
8979
- if (!response.ok) {
8980
- let error = {
8981
- message: response.statusText,
8982
- name: "application_error"
8983
- };
8984
- try {
8985
- error = yield response.json();
8986
- if (isResendErrorResponse(error)) {
8967
+ try {
8968
+ const response = yield fetch(`${baseUrl}${path}`, options);
8969
+ if (!response.ok) {
8970
+ try {
8971
+ const rawError = yield response.text();
8972
+ return { data: null, error: JSON.parse(rawError) };
8973
+ } catch (err) {
8974
+ if (err instanceof SyntaxError) {
8975
+ return {
8976
+ data: null,
8977
+ error: {
8978
+ name: "application_error",
8979
+ message: "Internal server error. We are unable to process your request right now, please try again later."
8980
+ }
8981
+ };
8982
+ }
8983
+ const error = {
8984
+ message: response.statusText,
8985
+ name: "application_error"
8986
+ };
8987
+ if (err instanceof Error) {
8988
+ return { data: null, error: __spreadProps(__spreadValues2({}, error), { message: err.message }) };
8989
+ }
8987
8990
  return { data: null, error };
8988
8991
  }
8989
- return { data: null, error };
8990
- } catch (err) {
8991
- if (err instanceof Error) {
8992
- return { data: null, error: __spreadProps(__spreadValues2({}, error), { message: err.message }) };
8993
- }
8994
- return { data: null, error };
8995
8992
  }
8993
+ const data = yield response.json();
8994
+ return { data, error: null };
8995
+ } catch (error) {
8996
+ return {
8997
+ data: null,
8998
+ error: {
8999
+ name: "application_error",
9000
+ message: "Unable to fetch data. The request could not be resolved."
9001
+ }
9002
+ };
8996
9003
  }
8997
- const data = yield response.json();
8998
- return { data, error: null };
8999
9004
  });
9000
9005
  }
9001
9006
  post(_0, _1) {
@@ -13,7 +13,7 @@ type ErrorResponse = {
13
13
  type Prepare = (middleware?: (Middleware | string)[]) => {
14
14
  middleware: string[];
15
15
  method: string;
16
- exec: (req: Request, params: Record<string, any>, app: App) => Promise<Partial<DataResponse> | ErrorResponse>;
16
+ exec: (req: HttpRequest, params: Record<string, any>, app: App) => Promise<Partial<DataResponse> | ErrorResponse>;
17
17
  };
18
18
  type ApiHandler<T extends new (app: App) => Controller, U = {}> = {
19
19
  prepare: Prepare;
@@ -21,7 +21,7 @@ type ApiHandler<T extends new (app: App) => Controller, U = {}> = {
21
21
  prepare: Prepare;
22
22
  };
23
23
  };
24
- export type ApiRouteExec = (req: Request, params: Record<string, string>, app: App) => Promise<DataResponse | ErrorResponse>;
24
+ export type ApiRouteExec = (req: HttpRequest, params: Record<string, string>, app: App) => Promise<DataResponse | ErrorResponse>;
25
25
  type ApiRouteConfig = {
26
26
  prepare: Prepare;
27
27
  };
@@ -1 +1 @@
1
- {"version":3,"file":"ApiRouter.d.ts","sourceRoot":"","sources":["../../http/ApiRouter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC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S,KAAK,GAAG,EAAE,GAAG,KAAK,UAAU,EACrD,UAAU,EAAE,CAAC,EACb,UAAU,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC/B,UAAU,CAAC,CAAC,CAAC;IAShB,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC;IACnE,SAAS,CAAC,KAAK,CAAC,CAAC,SAAS,KAAK,GAAG,EAAE,GAAG,KAAK,UAAU,EACpD,UAAU,EAAE,CAAC,EACb,UAAU,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC/B,UAAU,CAAC,CAAC,CAAC;CAQjB"}
@@ -252,14 +252,14 @@ class ApiRouter {
252
252
  method,
253
253
  exec: async (req, params, app) => {
254
254
  let handler = (_req, params2) => Promise.resolve({});
255
- let httpRequest = new HttpRequest(req);
255
+ let httpRequest = new HttpRequest(req.rawRequest);
256
256
  if (isController(controller)) {
257
257
  const controllerInstance = new controller(app);
258
258
  const Req = controllerInstance.requests[methodName] ?? HttpRequest;
259
- httpRequest = new Req(req);
259
+ httpRequest = new Req(req.rawRequest);
260
260
  handler = controllerInstance[methodName].bind(controllerInstance);
261
261
  } else if (typeof controller === "function") {
262
- handler = (req2) => controller(new HttpRequest(req2));
262
+ handler = (req2) => controller(req2);
263
263
  }
264
264
  return await handler(httpRequest, params);
265
265
  }
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { AsyncLocalStorage } from "async_hooks";
3
2
  export declare const requestContext: AsyncLocalStorage<Map<string, any>>;
4
3
  //# sourceMappingURL=requestContext.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"requestContext.d.ts","sourceRoot":"","sources":["../../http/requestContext.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAYhD,eAAO,MAAM,cAAc,qCAA4C,CAAC"}
1
+ {"version":3,"file":"requestContext.d.ts","sourceRoot":"","sources":["../../http/requestContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAYhD,eAAO,MAAM,cAAc,qCAA4C,CAAC"}
package/package.json CHANGED
@@ -1,15 +1,19 @@
1
1
  {
2
2
  "name": "gemi",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "devDependencies": {
5
+ "@happy-dom/global-registrator": "^14.12.3",
5
6
  "@repo/eslint-config": "*",
6
7
  "@repo/typescript-config": "*",
7
8
  "@types/bun": "^1.1.4",
8
9
  "@types/eslint": "^8.56.5",
10
+ "@types/jsdom": "^21.1.7",
9
11
  "@types/node": "^20.11.24",
10
12
  "@types/react": "^18.2.61",
11
13
  "@types/react-dom": "^18.2.19",
12
14
  "eslint": "^8.57.0",
15
+ "happy-dom": "^14.12.3",
16
+ "jsdom": "^24.1.0",
13
17
  "typescript": "^5.3.3",
14
18
  "vitest": "^1.6.0"
15
19
  },