@cedarjs/api-server 9.0.0-canary.1784 → 9.0.0-canary.3124

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.
Files changed (127) hide show
  1. package/README.md +0 -1
  2. package/dist/apiCLIConfig.d.ts.map +1 -1
  3. package/dist/apiCLIConfig.js +1 -1
  4. package/dist/apiCLIConfigHandler.d.ts.map +1 -1
  5. package/dist/apiCLIConfigHandler.js +5 -0
  6. package/dist/bin.js +316 -98
  7. package/dist/bothCLIConfig.d.ts.map +1 -1
  8. package/dist/bothCLIConfig.js +2 -2
  9. package/dist/bothCLIConfigHandler.d.ts.map +1 -1
  10. package/dist/bothCLIConfigHandler.js +8 -2
  11. package/dist/cliHelpers.d.ts +22 -4
  12. package/dist/cliHelpers.d.ts.map +1 -1
  13. package/dist/cliHelpers.js +43 -11
  14. package/dist/createServer.d.ts +19 -3
  15. package/dist/createServer.d.ts.map +1 -1
  16. package/dist/createServer.js +18 -11
  17. package/dist/createServerHelpers.d.ts +15 -2
  18. package/dist/createServerHelpers.d.ts.map +1 -1
  19. package/dist/createServerHelpers.js +14 -4
  20. package/dist/fastify.d.ts.map +1 -1
  21. package/dist/fastify.js +5 -0
  22. package/dist/logFormatter/formatters.d.ts +1 -1
  23. package/dist/logFormatter/formatters.d.ts.map +1 -1
  24. package/dist/logFormatter/index.d.ts.map +1 -1
  25. package/dist/plugins/api.d.ts +4 -5
  26. package/dist/plugins/api.d.ts.map +1 -1
  27. package/dist/plugins/api.js +15 -15
  28. package/dist/plugins/graphql.d.ts +20 -3
  29. package/dist/plugins/graphql.d.ts.map +1 -1
  30. package/dist/plugins/graphql.js +69 -28
  31. package/dist/plugins/lambdaLoader.d.ts +16 -6
  32. package/dist/plugins/lambdaLoader.d.ts.map +1 -1
  33. package/dist/plugins/lambdaLoader.js +73 -10
  34. package/dist/requestHandlers/awsLambdaFastify.d.ts.map +1 -1
  35. package/dist/requestHandlers/awsLambdaFastify.js +16 -4
  36. package/dist/serverFile.d.ts +23 -0
  37. package/dist/serverFile.d.ts.map +1 -0
  38. package/dist/serverFile.js +35 -0
  39. package/dist/types.d.ts +4 -4
  40. package/dist/types.d.ts.map +1 -1
  41. package/dist/utils.d.ts +0 -3
  42. package/dist/utils.d.ts.map +1 -1
  43. package/dist/utils.js +0 -20
  44. package/package.json +56 -72
  45. package/LICENSE +0 -21
  46. package/dist/buildManager.d.ts +0 -15
  47. package/dist/buildManager.d.ts.map +0 -1
  48. package/dist/buildManager.js +0 -50
  49. package/dist/cjs/apiCLIConfig.d.ts +0 -6
  50. package/dist/cjs/apiCLIConfig.d.ts.map +0 -1
  51. package/dist/cjs/apiCLIConfig.js +0 -71
  52. package/dist/cjs/apiCLIConfigHandler.d.ts +0 -3
  53. package/dist/cjs/apiCLIConfigHandler.d.ts.map +0 -1
  54. package/dist/cjs/apiCLIConfigHandler.js +0 -67
  55. package/dist/cjs/bin.d.ts +0 -2
  56. package/dist/cjs/bin.d.ts.map +0 -1
  57. package/dist/cjs/bin.js +0 -896
  58. package/dist/cjs/bothCLIConfig.d.ts +0 -6
  59. package/dist/cjs/bothCLIConfig.d.ts.map +0 -1
  60. package/dist/cjs/bothCLIConfig.js +0 -76
  61. package/dist/cjs/bothCLIConfigHandler.d.ts +0 -3
  62. package/dist/cjs/bothCLIConfigHandler.d.ts.map +0 -1
  63. package/dist/cjs/bothCLIConfigHandler.js +0 -107
  64. package/dist/cjs/buildManager.d.ts +0 -15
  65. package/dist/cjs/buildManager.d.ts.map +0 -1
  66. package/dist/cjs/buildManager.js +0 -74
  67. package/dist/cjs/cliHelpers.d.ts +0 -5
  68. package/dist/cjs/cliHelpers.d.ts.map +0 -1
  69. package/dist/cjs/cliHelpers.js +0 -52
  70. package/dist/cjs/createServer.d.ts +0 -30
  71. package/dist/cjs/createServer.d.ts.map +0 -1
  72. package/dist/cjs/createServer.js +0 -144
  73. package/dist/cjs/createServerHelpers.d.ts +0 -38
  74. package/dist/cjs/createServerHelpers.d.ts.map +0 -1
  75. package/dist/cjs/createServerHelpers.js +0 -112
  76. package/dist/cjs/fastify.d.ts +0 -13
  77. package/dist/cjs/fastify.d.ts.map +0 -1
  78. package/dist/cjs/fastify.js +0 -91
  79. package/dist/cjs/logFormatter/ambient.d.js +0 -1
  80. package/dist/cjs/logFormatter/bin.d.ts +0 -2
  81. package/dist/cjs/logFormatter/bin.d.ts.map +0 -1
  82. package/dist/cjs/logFormatter/bin.js +0 -369
  83. package/dist/cjs/logFormatter/formatters.d.ts +0 -30
  84. package/dist/cjs/logFormatter/formatters.d.ts.map +0 -1
  85. package/dist/cjs/logFormatter/formatters.js +0 -275
  86. package/dist/cjs/logFormatter/index.d.ts +0 -2
  87. package/dist/cjs/logFormatter/index.d.ts.map +0 -1
  88. package/dist/cjs/logFormatter/index.js +0 -184
  89. package/dist/cjs/package.json +0 -1
  90. package/dist/cjs/plugins/api.d.ts +0 -14
  91. package/dist/cjs/plugins/api.d.ts.map +0 -1
  92. package/dist/cjs/plugins/api.js +0 -78
  93. package/dist/cjs/plugins/graphql.d.ts +0 -10
  94. package/dist/cjs/plugins/graphql.d.ts.map +0 -1
  95. package/dist/cjs/plugins/graphql.js +0 -109
  96. package/dist/cjs/plugins/lambdaLoader.d.ts +0 -24
  97. package/dist/cjs/plugins/lambdaLoader.d.ts.map +0 -1
  98. package/dist/cjs/plugins/lambdaLoader.js +0 -134
  99. package/dist/cjs/requestHandlers/awsLambdaFastify.d.ts +0 -5
  100. package/dist/cjs/requestHandlers/awsLambdaFastify.d.ts.map +0 -1
  101. package/dist/cjs/requestHandlers/awsLambdaFastify.js +0 -103
  102. package/dist/cjs/requestHandlers/utils.d.ts +0 -26
  103. package/dist/cjs/requestHandlers/utils.d.ts.map +0 -1
  104. package/dist/cjs/requestHandlers/utils.js +0 -55
  105. package/dist/cjs/serverManager.d.ts +0 -8
  106. package/dist/cjs/serverManager.d.ts.map +0 -1
  107. package/dist/cjs/serverManager.js +0 -137
  108. package/dist/cjs/types.d.ts +0 -19
  109. package/dist/cjs/types.d.ts.map +0 -1
  110. package/dist/cjs/utils.d.ts +0 -6
  111. package/dist/cjs/utils.d.ts.map +0 -1
  112. package/dist/cjs/utils.js +0 -58
  113. package/dist/cjs/watch.d.ts +0 -10
  114. package/dist/cjs/watch.d.ts.map +0 -1
  115. package/dist/cjs/watch.js +0 -394
  116. package/dist/cjs/watchPaths.d.ts +0 -3
  117. package/dist/cjs/watchPaths.d.ts.map +0 -1
  118. package/dist/cjs/watchPaths.js +0 -140
  119. package/dist/serverManager.d.ts +0 -8
  120. package/dist/serverManager.d.ts.map +0 -1
  121. package/dist/serverManager.js +0 -102
  122. package/dist/watch.d.ts +0 -10
  123. package/dist/watch.d.ts.map +0 -1
  124. package/dist/watch.js +0 -370
  125. package/dist/watchPaths.d.ts +0 -3
  126. package/dist/watchPaths.d.ts.map +0 -1
  127. package/dist/watchPaths.js +0 -109
@@ -1 +1 @@
1
- {"version":3,"file":"bothCLIConfig.d.ts","sourceRoot":"","sources":["../src/bothCLIConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAEjC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEnD,eAAO,MAAM,WAAW,qDAAqD,CAAA;AAE7E,wBAAgB,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,iBAAiB,CAAC,QA+BrD;AAED,wBAAsB,OAAO,CAAC,OAAO,EAAE,iBAAiB,iBAGvD"}
1
+ {"version":3,"file":"bothCLIConfig.d.ts","sourceRoot":"","sources":["../src/bothCLIConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAEjC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEnD,eAAO,MAAM,WAAW,qDAAqD,CAAA;AAE7E,wBAAgB,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,iBAAiB,CAAC,QA6BrD;AAED,wBAAsB,OAAO,CAAC,OAAO,EAAE,iBAAiB,iBAGvD"}
@@ -7,7 +7,7 @@ function builder(yargs) {
7
7
  alias: ["web-port"]
8
8
  },
9
9
  webHost: {
10
- description: "The host for the web server to listen on. Note that you most likely want this to be '0.0.0.0' in production",
10
+ description: "The host for the web server to listen on",
11
11
  type: "string",
12
12
  alias: ["web-host"]
13
13
  },
@@ -17,7 +17,7 @@ function builder(yargs) {
17
17
  alias: ["api-port"]
18
18
  },
19
19
  apiHost: {
20
- description: "The host for the api server to listen on. Note that you most likely want this to be '0.0.0.0' in production",
20
+ description: "The host for the api server to listen on",
21
21
  type: "string",
22
22
  alias: ["api-host"]
23
23
  },
@@ -1 +1 @@
1
- {"version":3,"file":"bothCLIConfigHandler.d.ts","sourceRoot":"","sources":["../src/bothCLIConfigHandler.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEnD,wBAAsB,OAAO,CAAC,OAAO,EAAE,iBAAiB,iBAmEvD"}
1
+ {"version":3,"file":"bothCLIConfigHandler.d.ts","sourceRoot":"","sources":["../src/bothCLIConfigHandler.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEnD,wBAAsB,OAAO,CAAC,OAAO,EAAE,iBAAiB,iBA0FvD"}
@@ -3,11 +3,17 @@ import { redwoodFastifyWeb, coerceRootPath } from "@cedarjs/fastify-web";
3
3
  import { getWebHost, getWebPort, getAPIHost, getAPIPort } from "./cliHelpers.js";
4
4
  import { createServer as createApiServer } from "./createServer.js";
5
5
  import { createFastifyInstance } from "./fastify.js";
6
+ import { apiDistServerFileExists } from "./serverFile.js";
6
7
  async function handler(options) {
8
+ if (apiDistServerFileExists()) {
9
+ throw new Error(
10
+ "api/dist/server.js was found, but a custom server file is not supported when serving both sides from one process (`cedarjs-server` / `cedar serve`). It is a Fastify concept. Anything registered there (Realtime, custom plugins, custom middleware) would silently be skipped if this continued.\n\nRun the api and web sides as separate processes instead, so the api side goes through `cedarjs-server api`, which does run your server file:\n\n cedarjs-server api\n cedarjs-server web"
11
+ );
12
+ }
7
13
  const timeStart = Date.now();
8
14
  console.log(ansis.dim.italic("Starting API and Web Servers..."));
9
- options.webHost ??= getWebHost();
10
- options.webPort ??= getWebPort();
15
+ options.webHost ??= getWebHost({ isPublicSide: true });
16
+ options.webPort ??= getWebPort({ isPublicSide: true });
11
17
  options.apiHost ??= getAPIHost();
12
18
  options.apiPort ??= getAPIPort();
13
19
  options.apiRootPath = coerceRootPath(options.apiRootPath ?? "/");
@@ -1,5 +1,23 @@
1
- export declare function getAPIHost(): string;
2
- export declare function getAPIPort(): number;
3
- export declare function getWebHost(): string;
4
- export declare function getWebPort(): number;
1
+ interface SideOptions {
2
+ /**
3
+ * Whether this side receives the deployment's public traffic.
4
+ *
5
+ * Container hosts (Railway, Render, Fly.io, Cloud Run, Heroku) tell an app
6
+ * which host and port to bind with the `HOST` and `PORT` env vars. Only the
7
+ * side serving public traffic falls back to them — when the api and web
8
+ * servers run in the same deployment they would otherwise both bind to
9
+ * `PORT` and collide.
10
+ *
11
+ * The web side is the public one whenever both sides are served together,
12
+ * because it proxies api requests. The api side is only public when it is
13
+ * served on its own.
14
+ */
15
+ isPublicSide?: boolean;
16
+ }
17
+ export declare function getAPIHost({ isPublicSide }?: SideOptions): string;
18
+ export declare function getAPIPort({ isPublicSide }?: SideOptions): number;
19
+ export declare function getAPIRootPath(): string;
20
+ export declare function getWebHost({ isPublicSide }?: SideOptions): string;
21
+ export declare function getWebPort({ isPublicSide }?: SideOptions): number;
22
+ export {};
5
23
  //# sourceMappingURL=cliHelpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cliHelpers.d.ts","sourceRoot":"","sources":["../src/cliHelpers.ts"],"names":[],"mappings":"AAEA,wBAAgB,UAAU,WAKzB;AAED,wBAAgB,UAAU,WAIzB;AAED,wBAAgB,UAAU,WAKzB;AAED,wBAAgB,UAAU,WAIzB"}
1
+ {"version":3,"file":"cliHelpers.d.ts","sourceRoot":"","sources":["../src/cliHelpers.ts"],"names":[],"mappings":"AAEA,UAAU,WAAW;IACnB;;;;;;;;;;;;OAYG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAED,wBAAgB,UAAU,CAAC,EAAE,YAAoB,EAAE,GAAE,WAAgB,UAepE;AAED,wBAAgB,UAAU,CAAC,EAAE,YAAoB,EAAE,GAAE,WAAgB,UAcpE;AAED,wBAAgB,cAAc,WAE7B;AAED,wBAAgB,UAAU,CAAC,EAAE,YAAoB,EAAE,GAAE,WAAgB,UAepE;AAED,wBAAgB,UAAU,CAAC,EAAE,YAAoB,EAAE,GAAE,WAAgB,UAcpE"}
@@ -1,25 +1,57 @@
1
- import { getConfig } from "@cedarjs/project-config";
2
- function getAPIHost() {
3
- let host = process.env.REDWOOD_API_HOST;
1
+ import { getConfig, parsePort, readEnvVar } from "@cedarjs/project-config";
2
+ function getAPIHost({ isPublicSide = false } = {}) {
3
+ let host = readEnvVar("CEDAR_API_HOST", {
4
+ deprecatedAlias: "REDWOOD_API_HOST"
5
+ });
6
+ if (isPublicSide) {
7
+ host ??= process.env.HOST;
8
+ }
4
9
  host ??= getConfig().api.host;
5
- host ??= process.env.NODE_ENV === "production" ? "0.0.0.0" : "::";
10
+ host ??= "::";
6
11
  return host;
7
12
  }
8
- function getAPIPort() {
9
- return process.env.REDWOOD_API_PORT ? parseInt(process.env.REDWOOD_API_PORT) : getConfig().api.port;
13
+ function getAPIPort({ isPublicSide = false } = {}) {
14
+ const apiPort = readEnvVar("CEDAR_API_PORT", {
15
+ deprecatedAlias: "REDWOOD_API_PORT"
16
+ });
17
+ if (apiPort) {
18
+ return parsePort(apiPort, "CEDAR_API_PORT");
19
+ }
20
+ if (isPublicSide && process.env.PORT) {
21
+ return parsePort(process.env.PORT, "PORT");
22
+ }
23
+ return getConfig().api.port;
10
24
  }
11
- function getWebHost() {
12
- let host = process.env.REDWOOD_WEB_HOST;
25
+ function getAPIRootPath() {
26
+ return process.env.CEDAR_API_ROOT_PATH ?? "/";
27
+ }
28
+ function getWebHost({ isPublicSide = false } = {}) {
29
+ let host = readEnvVar("CEDAR_WEB_HOST", {
30
+ deprecatedAlias: "REDWOOD_WEB_HOST"
31
+ });
32
+ if (isPublicSide) {
33
+ host ??= process.env.HOST;
34
+ }
13
35
  host ??= getConfig().web.host;
14
- host ??= process.env.NODE_ENV === "production" ? "0.0.0.0" : "::";
36
+ host ??= "::";
15
37
  return host;
16
38
  }
17
- function getWebPort() {
18
- return process.env.REDWOOD_WEB_PORT ? parseInt(process.env.REDWOOD_WEB_PORT) : getConfig().web.port;
39
+ function getWebPort({ isPublicSide = false } = {}) {
40
+ const webPort = readEnvVar("CEDAR_WEB_PORT", {
41
+ deprecatedAlias: "REDWOOD_WEB_PORT"
42
+ });
43
+ if (webPort) {
44
+ return parsePort(webPort, "CEDAR_WEB_PORT");
45
+ }
46
+ if (isPublicSide && process.env.PORT) {
47
+ return parsePort(process.env.PORT, "PORT");
48
+ }
49
+ return getConfig().web.port;
19
50
  }
20
51
  export {
21
52
  getAPIHost,
22
53
  getAPIPort,
54
+ getAPIRootPath,
23
55
  getWebHost,
24
56
  getWebPort
25
57
  };
@@ -11,13 +11,29 @@ import type { CreateServerOptions, Server } from './createServerHelpers.js';
11
11
  * const server = await createServer({
12
12
  * logger,
13
13
  * apiRootPath: 'api'
14
+ * configureServer: (server) => {
15
+ * // Runs before the api functions and GraphQL plugins are
16
+ * // registered, i.e. before any routes exist. This is the right
17
+ * // place for plugins with a "global" mode that hooks `onRoute`
18
+ * // (e.g. `@fastify/compress`), since those only affect routes
19
+ * // registered *after* the plugin itself — registering them here
20
+ * // applies them to *both* api functions and the GraphQL endpoint:
21
+ * server.register(compress, { global: true })
22
+ * },
14
23
  * configureApiServer: (server) => {
15
- * // Configure the API server fastify instance, e.g. add content type parsers
24
+ * // Configure just the api functions' fastify instance, e.g. add
25
+ * // content type parsers. Doesn't apply to the GraphQL endpoint.
26
+ * },
27
+ * configureGraphQLServer: (server) => {
28
+ * // Configure just the GraphQL fastify instance. Doesn't apply to
29
+ * // api function routes.
16
30
  * },
17
31
  * })
18
32
  *
19
- * // Configure the returned fastify instance:
20
- * server.register(myPlugin)
33
+ * // Plain request-lifecycle hooks (onRequest, onSend, etc.) don't depend
34
+ * // on registration order, so they can also be added to the returned
35
+ * // instance after the fact and will still apply to both:
36
+ * server.addHook('onRequest', myHook)
21
37
  *
22
38
  * // When ready, start the server:
23
39
  * await server.start()
@@ -1 +1 @@
1
- {"version":3,"file":"createServer.d.ts","sourceRoot":"","sources":["../src/createServer.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EACV,mBAAmB,EACnB,MAAM,EAEP,MAAM,0BAA0B,CAAA;AAqBjC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,YAAY,CAAC,OAAO,GAAE,mBAAwB,mBAoHnE"}
1
+ {"version":3,"file":"createServer.d.ts","sourceRoot":"","sources":["../src/createServer.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACV,mBAAmB,EACnB,MAAM,EAEP,MAAM,0BAA0B,CAAA;AAsBjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAsB,YAAY,CAAC,OAAO,GAAE,mBAAwB,mBA4InE"}
@@ -1,5 +1,6 @@
1
1
  import fs from "node:fs";
2
- import path from "path";
2
+ import path from "node:path";
3
+ import { pathToFileURL } from "node:url";
3
4
  import ansis from "ansis";
4
5
  import { config } from "dotenv-defaults";
5
6
  import fg from "fast-glob";
@@ -7,21 +8,23 @@ import fastify from "fastify";
7
8
  import { getAsyncStoreInstance } from "@cedarjs/context/dist/store";
8
9
  import { getConfig, getPaths } from "@cedarjs/project-config";
9
10
  import { resolveOptions } from "./createServerHelpers.js";
10
- import { redwoodFastifyAPI } from "./plugins/api.js";
11
- if (!process.env.REDWOOD_ENV_FILES_LOADED) {
11
+ import { cedarFastifyAPI } from "./plugins/api.js";
12
+ if (!process.env.CEDAR_ENV_FILES_LOADED) {
12
13
  config({
13
14
  path: path.join(getPaths().base, ".env"),
14
15
  defaults: path.join(getPaths().base, ".env.defaults"),
15
16
  multiline: true
16
17
  });
17
- process.env.REDWOOD_ENV_FILES_LOADED = "true";
18
+ process.env.CEDAR_ENV_FILES_LOADED = "true";
18
19
  }
19
20
  async function createServer(options = {}) {
20
21
  const {
21
22
  apiRootPath,
22
23
  fastifyServerOptions,
23
24
  discoverFunctionsGlob,
25
+ configureServer,
24
26
  configureApiServer,
27
+ configureGraphQLServer,
25
28
  apiPort,
26
29
  apiHost
27
30
  } = resolveOptions(options);
@@ -60,8 +63,11 @@ async function createServer(options = {}) {
60
63
  server.addHook("onRequest", (_req, _reply, done) => {
61
64
  getAsyncStoreInstance().run(/* @__PURE__ */ new Map(), done);
62
65
  });
63
- await server.register(redwoodFastifyAPI, {
64
- redwood: {
66
+ if (configureServer) {
67
+ await configureServer(server);
68
+ }
69
+ await server.register(cedarFastifyAPI, {
70
+ cedar: {
65
71
  apiRootPath,
66
72
  fastGlobOptions: {
67
73
  ignore: ["**/dist/functions/graphql.js"]
@@ -75,12 +81,13 @@ async function createServer(options = {}) {
75
81
  absolute: true
76
82
  });
77
83
  if (graphqlFunctionPath) {
78
- const { redwoodFastifyGraphQLServer } = await import("./plugins/graphql.js");
79
- const { __rw_graphqlOptions } = await import(`file://${graphqlFunctionPath}`);
80
- await server.register(redwoodFastifyGraphQLServer, {
81
- redwood: {
84
+ const { cedarFastifyGraphQLServer } = await import("./plugins/graphql.js");
85
+ const { __cedar_graphqlOptions } = await import(pathToFileURL(graphqlFunctionPath).href);
86
+ await server.register(cedarFastifyGraphQLServer, {
87
+ cedar: {
82
88
  apiRootPath,
83
- graphql: __rw_graphqlOptions
89
+ graphql: __cedar_graphqlOptions,
90
+ configureServer: configureGraphQLServer
84
91
  }
85
92
  });
86
93
  }
@@ -18,8 +18,21 @@ export interface CreateServerOptions {
18
18
  * Defaults to: "dist/functions/**\/*.{ts,js}"
19
19
  */
20
20
  discoverFunctionsGlob?: string | string[];
21
- /** Customise the API server fastify plugin before it is registered */
22
- configureApiServer?: (server: Server) => void | Promise<void>;
21
+ /**
22
+ * Configure the root fastify instance *before* the api functions and
23
+ * GraphQL plugins are registered. Use this to register Fastify plugins
24
+ * that need to run before any routes exist — most notably plugins with a
25
+ * "global" mode that works by hooking `onRoute` (e.g. `@fastify/compress`),
26
+ * which only affects routes registered *after* the plugin itself. Simple
27
+ * request-lifecycle hooks (`onRequest`, `onSend`, etc.) don't have this
28
+ * restriction and can also be added to the returned server after
29
+ * `createServer()` resolves.
30
+ */
31
+ configureServer?: (server: FastifyInstance) => void | Promise<void>;
32
+ /** Customise the API functions fastify plugin before it is registered */
33
+ configureApiServer?: (server: FastifyInstance) => void | Promise<void>;
34
+ /** Customise the GraphQL fastify plugin before it is registered */
35
+ configureGraphQLServer?: (server: FastifyInstance) => void | Promise<void>;
23
36
  /** Whether to parse args or not. Defaults to `true` */
24
37
  parseArgs?: boolean;
25
38
  /** The port to listen on. Defaults to what's configured in cedar.toml */
@@ -1 +1 @@
1
- {"version":3,"file":"createServerHelpers.d.ts","sourceRoot":"","sources":["../src/createServerHelpers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EAChB,MAAM,SAAS,CAAA;AAMhB,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,oBAAoB,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;AAEtE,MAAM,WAAW,MAAO,SAAQ,eAAe;IAC7C,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CACnD;AAED,MAAM,WAAW,mBAAmB;IAClC,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAA;IAGpB,iCAAiC;IACjC,MAAM,CAAC,EACH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,WAAW,CAAC,EAAE,MAAM,CAAA;IAGpB,iCAAiC;IACjC,MAAM,CAAC,EACL,oBAAoB,CAAC,QAAQ,CAAC,GAAG,oBAAoB,CAAC,gBAAgB,CAAC,CAAA;IAEzE;;;OAGG;IACH,oBAAoB,CAAC,EAAE,IAAI,CAAC,oBAAoB,EAAE,QAAQ,CAAC,CAAA;IAE3D;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAEzC;;;;;;;;;OASG;IACH,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAEnE,yEAAyE;IACzE,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAEtE,mEAAmE;IACnE,sBAAsB,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE1E,uDAAuD;IACvD,SAAS,CAAC,EAAE,OAAO,CAAA;IAEnB,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,KAAK,0BAA0B,GAAG,QAAQ,CACxC,IAAI,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,GAAG;IAClD,oBAAoB,EAAE,oBAAoB,CAAA;CAC3C,CACF,CAAA;AAID,eAAO,MAAM,6BAA6B,EAAE,MAAM,0BAuB9C,CAAA;AAeJ,wBAAgB,cAAc,CAC5B,OAAO,GAAE,mBAAwB,EACjC,IAAI,CAAC,EAAE,MAAM,EAAE;0BAbS,oBAAoB;GA8F7C"}
@@ -1,8 +1,8 @@
1
1
  import { parseArgs } from "util";
2
2
  import { coerceRootPath } from "@cedarjs/fastify-web/dist/helpers.js";
3
- import { getAPIHost, getAPIPort } from "./cliHelpers.js";
3
+ import { getAPIHost, getAPIPort, getAPIRootPath } from "./cliHelpers.js";
4
4
  const getDefaultCreateServerOptions = () => ({
5
- apiRootPath: "/",
5
+ apiRootPath: getAPIRootPath(),
6
6
  logger: {
7
7
  level: process.env.LOG_LEVEL ?? (process.env.NODE_ENV === "development" ? "debug" : "warn")
8
8
  },
@@ -12,11 +12,19 @@ const getDefaultCreateServerOptions = () => ({
12
12
  // 100MB
13
13
  },
14
14
  discoverFunctionsGlob: "dist/functions/**/*.{ts,js}",
15
+ configureServer: () => {
16
+ },
15
17
  configureApiServer: () => {
16
18
  },
19
+ configureGraphQLServer: () => {
20
+ },
17
21
  parseArgs: true,
18
- apiHost: getAPIHost(),
19
- apiPort: getAPIPort()
22
+ // `createServer()`'s only callers are `cedarjs-server api` and custom
23
+ // `api/src/server.ts` files — both only ever run with the api side
24
+ // serving public traffic on its own, so they get to use the host's
25
+ // `HOST`/`PORT` env vars.
26
+ apiHost: getAPIHost({ isPublicSide: true }),
27
+ apiPort: getAPIPort({ isPublicSide: true })
20
28
  });
21
29
  function isCustomLoggerInstance(logger) {
22
30
  return !!logger && typeof logger === "object" && "info" in logger;
@@ -32,7 +40,9 @@ function resolveOptions(options = {}, args) {
32
40
  bodyLimit: defaults.fastifyServerOptions.bodyLimit
33
41
  },
34
42
  discoverFunctionsGlob: options.discoverFunctionsGlob ?? defaults.discoverFunctionsGlob,
43
+ configureServer: options.configureServer ?? defaults.configureServer,
35
44
  configureApiServer: options.configureApiServer ?? defaults.configureApiServer,
45
+ configureGraphQLServer: options.configureGraphQLServer ?? defaults.configureGraphQLServer,
36
46
  apiHost: options.apiHost ?? defaults.apiHost,
37
47
  apiPort: options.apiPort ?? defaults.apiPort
38
48
  };
@@ -1 +1 @@
1
- {"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAOpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAGrD,eAAO,MAAM,eAAe;;;;CAI3B,CAAA;AAiBD,wBAAsB,iBAAiB;YAb7B,oBAAoB;sBACV,mBAAmB;GAsCtC;AAED,eAAO,MAAM,qBAAqB,GAChC,UAAU,oBAAoB,KAC7B,OAAO,CAAC,eAAe,CAWzB,CAAA"}
1
+ {"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAOpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAGrD,eAAO,MAAM,eAAe;;;;CAI3B,CAAA;AAkBD,wBAAsB,iBAAiB;YAb7B,oBAAoB;sBACV,mBAAmB;GA2CtC;AAED,eAAO,MAAM,qBAAqB,GAChC,UAAU,oBAAoB,KAC7B,OAAO,CAAC,eAAe,CAWzB,CAAA"}
package/dist/fastify.js CHANGED
@@ -10,6 +10,7 @@ const DEFAULT_OPTIONS = {
10
10
  }
11
11
  };
12
12
  let isServerConfigLoaded = false;
13
+ let loadedServerConfigPath;
13
14
  let serverConfigFile = {
14
15
  config: DEFAULT_OPTIONS,
15
16
  configureFastify: async (fastify, options) => {
@@ -28,6 +29,9 @@ async function loadFastifyConfig() {
28
29
  if (!fs.existsSync(serverConfigPath)) {
29
30
  return serverConfigFile;
30
31
  }
32
+ if (loadedServerConfigPath !== serverConfigPath) {
33
+ isServerConfigLoaded = false;
34
+ }
31
35
  if (!isServerConfigLoaded) {
32
36
  console.log(`Loading server config from ${serverConfigPath}`);
33
37
  console.log(`Loading server config from URL file://${serverConfigPath}`);
@@ -36,6 +40,7 @@ async function loadFastifyConfig() {
36
40
  );
37
41
  const config = await import(pathToFileURL(serverConfigPath).href);
38
42
  serverConfigFile = { ...config.default };
43
+ loadedServerConfigPath = serverConfigPath;
39
44
  isServerConfigLoaded = true;
40
45
  }
41
46
  return serverConfigFile;
@@ -11,7 +11,7 @@ export declare const formatData: (data?: Record<string, unknown>) => string | un
11
11
  export declare const formatDate: (instant: Date) => string;
12
12
  export declare const formatErrorProp: (errorPropValue: Record<string, unknown>) => string;
13
13
  export declare const formatLevel: (level: any) => string;
14
- export declare const formatLoadTime: (elapsedTime: any) => string;
14
+ export declare const formatLoadTime: (elapsedTime: string) => string;
15
15
  export declare const formatMessage: (logData: any) => string | undefined;
16
16
  export declare const formatMethod: (method: string) => string;
17
17
  export declare const formatRequestId: (requestId: string) => string;
@@ -1 +1 @@
1
- {"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../src/logFormatter/formatters.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,OAAO,OAAO,CAAA;AAE3B,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAO3C,CAAA;AAED,eAAO,MAAM,iBAAiB,EAAE,MAAM,EASrC,CAAA;AAED,eAAO,MAAM,QAAQ,GAAI,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,wBAExD,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,wBAE7D,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,wBAEtD,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,WAAW,MAAM,YAE5C,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,WAI9C,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,uBAgB3D,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,uBAQxD,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,SAAS,IAAI,WAOvC,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,gBAAgB,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I,SAAS,MAAM,WAYhD,CAAA;AAED,eAAO,MAAM,mBAAmB,GAAI,eAAe,MAAM,WAExD,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,uBAQ1D,CAAA;AAED,eAAO,MAAM,mBAAmB,GAC9B,gBAAgB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,uBAYxC,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,YAAY,MAAM,WAGlD,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,QAAQ,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,WAMnE,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,uBAQ3D,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,KAAK,MAAM,WAEpC,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,WAAW,MAAM,WAEhD,CAAA;AAED,eAAO,MAAM,OAAO,GAAI,OAAO,GAAG,YAEjC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/logFormatter/index.ts"],"names":[],"mappings":"AA8BA,eAAO,MAAM,YAAY,oBACG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,WA0L3D,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/logFormatter/index.ts"],"names":[],"mappings":"AA8BA,eAAO,MAAM,YAAY,oBACG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,WA6L3D,CAAA"}
@@ -1,14 +1,13 @@
1
1
  import type { Options as FastGlobOptions } from 'fast-glob';
2
2
  import type { FastifyInstance } from 'fastify';
3
- import type { Server } from '../createServerHelpers.js';
4
- export interface RedwoodFastifyAPIOptions {
5
- redwood: {
3
+ export interface CedarFastifyAPIOptions {
4
+ cedar: {
6
5
  apiRootPath?: string;
7
6
  fastGlobOptions?: FastGlobOptions;
8
7
  discoverFunctionsGlob?: string | string[];
9
8
  loadUserConfig?: boolean;
10
- configureServer?: (server: Server) => void | Promise<void>;
9
+ configureServer?: (server: FastifyInstance) => void | Promise<void>;
11
10
  };
12
11
  }
13
- export declare function redwoodFastifyAPI(fastify: FastifyInstance, opts: RedwoodFastifyAPIOptions): Promise<void>;
12
+ export declare function cedarFastifyAPI(fastify: FastifyInstance, opts: CedarFastifyAPIOptions): Promise<void>;
14
13
  //# sourceMappingURL=api.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/plugins/api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAO9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAKvD,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE;QACP,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,eAAe,CAAC,EAAE,eAAe,CAAA;QACjC,qBAAqB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;QACzC,cAAc,CAAC,EAAE,OAAO,CAAA;QACxB,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;KAC3D,CAAA;CACF;AAED,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,wBAAwB,iBA4C/B"}
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/plugins/api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAW9C,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE;QACL,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,eAAe,CAAC,EAAE,eAAe,CAAA;QACjC,qBAAqB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;QACzC,cAAc,CAAC,EAAE,OAAO,CAAA;QACxB,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;KAIpE,CAAA;CACF;AAED,wBAAsB,eAAe,CACnC,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,sBAAsB,iBAgD7B"}
@@ -4,12 +4,12 @@ import { getAsyncStoreInstance } from "@cedarjs/context/dist/store";
4
4
  import { coerceRootPath } from "@cedarjs/fastify-web/dist/helpers.js";
5
5
  import { loadFastifyConfig } from "../fastify.js";
6
6
  import { lambdaRequestHandler, loadFunctionsFromDist } from "./lambdaLoader.js";
7
- async function redwoodFastifyAPI(fastify, opts) {
8
- const redwoodOptions = opts.redwood ?? {};
9
- redwoodOptions.apiRootPath ??= "/";
10
- redwoodOptions.apiRootPath = coerceRootPath(redwoodOptions.apiRootPath);
11
- redwoodOptions.fastGlobOptions ??= {};
12
- redwoodOptions.loadUserConfig ??= false;
7
+ async function cedarFastifyAPI(fastify, opts) {
8
+ const cedarOptions = opts.cedar ?? {};
9
+ cedarOptions.apiRootPath ??= "/";
10
+ cedarOptions.apiRootPath = coerceRootPath(cedarOptions.apiRootPath);
11
+ cedarOptions.fastGlobOptions ??= {};
12
+ cedarOptions.loadUserConfig ??= false;
13
13
  fastify.register(fastifyUrlData);
14
14
  await fastify.register(fastifyRawBody);
15
15
  fastify.addHook("onRequest", (_req, _reply, done) => {
@@ -20,25 +20,25 @@ async function redwoodFastifyAPI(fastify, opts) {
20
20
  { parseAs: "string" },
21
21
  fastify.defaultTextParser
22
22
  );
23
- if (redwoodOptions.loadUserConfig) {
23
+ if (cedarOptions.loadUserConfig) {
24
24
  const { configureFastify } = await loadFastifyConfig();
25
25
  if (configureFastify) {
26
26
  await configureFastify(fastify, {
27
27
  side: "api",
28
- apiRootPath: redwoodOptions.apiRootPath
28
+ apiRootPath: cedarOptions.apiRootPath
29
29
  });
30
30
  }
31
31
  }
32
- if (redwoodOptions.configureServer) {
33
- await redwoodOptions.configureServer(fastify);
32
+ if (cedarOptions.configureServer) {
33
+ await cedarOptions.configureServer(fastify);
34
34
  }
35
- fastify.all(`${redwoodOptions.apiRootPath}:routeName`, lambdaRequestHandler);
36
- fastify.all(`${redwoodOptions.apiRootPath}:routeName/*`, lambdaRequestHandler);
35
+ fastify.all(`${cedarOptions.apiRootPath}:routeName`, lambdaRequestHandler);
36
+ fastify.all(`${cedarOptions.apiRootPath}:routeName/*`, lambdaRequestHandler);
37
37
  await loadFunctionsFromDist({
38
- fastGlobOptions: redwoodOptions.fastGlobOptions,
39
- discoverFunctionsGlob: redwoodOptions.discoverFunctionsGlob
38
+ fastGlobOptions: cedarOptions.fastGlobOptions,
39
+ discoverFunctionsGlob: cedarOptions.discoverFunctionsGlob
40
40
  });
41
41
  }
42
42
  export {
43
- redwoodFastifyAPI
43
+ cedarFastifyAPI
44
44
  };
@@ -1,10 +1,27 @@
1
1
  import type { FastifyInstance } from 'fastify';
2
2
  import type { GraphQLYogaOptions } from '@cedarjs/graphql-server';
3
- export interface RedwoodFastifyGraphQLOptions {
4
- redwood: {
3
+ export interface CedarFastifyGraphQLOptions {
4
+ cedar: {
5
5
  apiRootPath?: string;
6
6
  graphql?: GraphQLYogaOptions;
7
+ configureServer?: (server: FastifyInstance) => void | Promise<void>;
7
8
  };
8
9
  }
9
- export declare function redwoodFastifyGraphQLServer(fastify: FastifyInstance, options: RedwoodFastifyGraphQLOptions): Promise<void>;
10
+ export declare function cedarFastifyGraphQLServer(fastify: FastifyInstance, options: CedarFastifyGraphQLOptions): Promise<void>;
11
+ /**
12
+ * Detects errors that indicate the client disconnected before the response
13
+ * finished, rather than a genuine server-side failure.
14
+ *
15
+ * `ERR_STREAM_PREMATURE_CLOSE` can surface from the underlying Node stream
16
+ * closing early. The `DOMException` named `AbortError` is thrown by Yoga
17
+ * when the AbortSignal wired up in `createFetchRequest`'s
18
+ * `reply.raw.on('close', ...)` handler is aborted, which only happens when
19
+ * the client itself has gone away.
20
+ *
21
+ * The `DOMException` check (rather than just `name === 'AbortError'`) is
22
+ * deliberate: a resolver or hook could throw a plain `Error` renamed to
23
+ * `AbortError`, which would otherwise be misclassified as a benign
24
+ * disconnect and hide a real server-side failure behind a 499.
25
+ */
26
+ export declare function isClientDisconnectError(e: unknown): boolean;
10
27
  //# sourceMappingURL=graphql.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/plugins/graphql.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,SAAS,CAAA;AAM3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAKjE,MAAM,WAAW,4BAA4B;IAC3C,OAAO,EAAE;QACP,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,OAAO,CAAC,EAAE,kBAAkB,CAAA;KAC7B,CAAA;CACF;AAED,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,4BAA4B,iBA8FtC"}
1
+ {"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/plugins/graphql.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,eAAe,EAIhB,MAAM,SAAS,CAAA;AAMhB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAKjE,MAAM,WAAW,0BAA0B;IACzC,KAAK,EAAE;QACL,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,OAAO,CAAC,EAAE,kBAAkB,CAAA;QAC5B,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;KACpE,CAAA;CACF;AAED,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,0BAA0B,iBAiIpC;AAMD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAc3D"}