@cedarjs/api-server 6.0.0-canary.2826 → 6.0.0-canary.2829

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/README.md CHANGED
@@ -16,7 +16,6 @@ From package.json
16
16
 
17
17
  ```
18
18
  "bin": {
19
- "cedarjs-api-server-watch": "./dist/watch.js",
20
19
  "cedarjs-log-formatter": "./dist/logFormatter/bin.js",
21
20
  "cedarjs-server": "./dist/bin.js",
22
21
  },
package/dist/bin.js CHANGED
@@ -524,7 +524,7 @@ import fastifyRawBody from "fastify-raw-body";
524
524
  import { getAsyncStoreInstance as getAsyncStoreInstance2 } from "@cedarjs/context/dist/store";
525
525
  import { coerceRootPath as coerceRootPath2 } from "@cedarjs/fastify-web/dist/helpers.js";
526
526
  async function cedarFastifyAPI(fastify2, opts) {
527
- const cedarOptions = opts.redwood ?? {};
527
+ const cedarOptions = opts.cedar ?? {};
528
528
  cedarOptions.apiRootPath ??= "/";
529
529
  cedarOptions.apiRootPath = coerceRootPath2(cedarOptions.apiRootPath);
530
530
  cedarOptions.fastGlobOptions ??= {};
@@ -569,7 +569,7 @@ var init_api = __esm({
569
569
  // src/plugins/graphql.ts
570
570
  var graphql_exports = {};
571
571
  __export(graphql_exports, {
572
- redwoodFastifyGraphQLServer: () => redwoodFastifyGraphQLServer
572
+ cedarFastifyGraphQLServer: () => cedarFastifyGraphQLServer
573
573
  });
574
574
  import { pathToFileURL as pathToFileURL3 } from "node:url";
575
575
  import fastifyMultiPart from "@fastify/multipart";
@@ -580,10 +580,10 @@ import { getAsyncStoreInstance as getAsyncStoreInstance3 } from "@cedarjs/contex
580
580
  import { coerceRootPath as coerceRootPath3 } from "@cedarjs/fastify-web/dist/helpers.js";
581
581
  import { createGraphQLYoga } from "@cedarjs/graphql-server";
582
582
  import { getPaths as getPaths3 } from "@cedarjs/project-config";
583
- async function redwoodFastifyGraphQLServer(fastify2, options) {
584
- const redwoodOptions = options.redwood ?? {};
585
- redwoodOptions.apiRootPath ??= "/";
586
- redwoodOptions.apiRootPath = coerceRootPath3(redwoodOptions.apiRootPath);
583
+ async function cedarFastifyGraphQLServer(fastify2, options) {
584
+ const cedarOptions = options.cedar ?? {};
585
+ cedarOptions.apiRootPath ??= "/";
586
+ cedarOptions.apiRootPath = coerceRootPath3(cedarOptions.apiRootPath);
587
587
  fastify2.register(fastifyUrlData2);
588
588
  fastify2.register(fastifyMultiPart);
589
589
  const method = ["GET", "POST", "OPTIONS"];
@@ -591,7 +591,7 @@ async function redwoodFastifyGraphQLServer(fastify2, options) {
591
591
  getAsyncStoreInstance3().run(/* @__PURE__ */ new Map(), done);
592
592
  });
593
593
  try {
594
- if (!redwoodOptions.graphql) {
594
+ if (!cedarOptions.graphql) {
595
595
  const [graphqlFunctionPath] = await fg2("dist/functions/graphql.{ts,js}", {
596
596
  cwd: getPaths3().api.base,
597
597
  absolute: true
@@ -601,9 +601,9 @@ async function redwoodFastifyGraphQLServer(fastify2, options) {
601
601
  if (!__cedar_graphqlOptions) {
602
602
  return;
603
603
  }
604
- redwoodOptions.graphql = __cedar_graphqlOptions;
604
+ cedarOptions.graphql = __cedar_graphqlOptions;
605
605
  }
606
- const graphqlOptions = redwoodOptions.graphql;
606
+ const graphqlOptions = cedarOptions.graphql;
607
607
  if (graphqlOptions?.realtime?.subscriptions) {
608
608
  method.push("PUT");
609
609
  }
@@ -612,7 +612,7 @@ async function redwoodFastifyGraphQLServer(fastify2, options) {
612
612
  const routePaths = ["", "/health", "/readiness", "/stream"];
613
613
  for (const routePath of routePaths) {
614
614
  fastify2.route({
615
- url: `${redwoodOptions.apiRootPath}${graphqlEndpoint}${routePath}`,
615
+ url: `${cedarOptions.apiRootPath}${graphqlEndpoint}${routePath}`,
616
616
  method,
617
617
  handler: async (req, reply) => {
618
618
  const request = createFetchRequest(req, reply);
@@ -732,7 +732,7 @@ async function createServer(options = {}) {
732
732
  getAsyncStoreInstance4().run(/* @__PURE__ */ new Map(), done);
733
733
  });
734
734
  await server.register(cedarFastifyAPI, {
735
- redwood: {
735
+ cedar: {
736
736
  apiRootPath,
737
737
  fastGlobOptions: {
738
738
  ignore: ["**/dist/functions/graphql.js"]
@@ -746,10 +746,10 @@ async function createServer(options = {}) {
746
746
  absolute: true
747
747
  });
748
748
  if (graphqlFunctionPath) {
749
- const { redwoodFastifyGraphQLServer: redwoodFastifyGraphQLServer2 } = await Promise.resolve().then(() => (init_graphql(), graphql_exports));
749
+ const { cedarFastifyGraphQLServer: cedarFastifyGraphQLServer2 } = await Promise.resolve().then(() => (init_graphql(), graphql_exports));
750
750
  const { __cedar_graphqlOptions } = await import(pathToFileURL4(graphqlFunctionPath).href);
751
- await server.register(redwoodFastifyGraphQLServer2, {
752
- redwood: {
751
+ await server.register(cedarFastifyGraphQLServer2, {
752
+ cedar: {
753
753
  apiRootPath,
754
754
  graphql: __cedar_graphqlOptions
755
755
  }
@@ -62,7 +62,7 @@ async function createServer(options = {}) {
62
62
  getAsyncStoreInstance().run(/* @__PURE__ */ new Map(), done);
63
63
  });
64
64
  await server.register(cedarFastifyAPI, {
65
- redwood: {
65
+ cedar: {
66
66
  apiRootPath,
67
67
  fastGlobOptions: {
68
68
  ignore: ["**/dist/functions/graphql.js"]
@@ -76,10 +76,10 @@ async function createServer(options = {}) {
76
76
  absolute: true
77
77
  });
78
78
  if (graphqlFunctionPath) {
79
- const { redwoodFastifyGraphQLServer } = await import("./plugins/graphql.js");
79
+ const { cedarFastifyGraphQLServer } = await import("./plugins/graphql.js");
80
80
  const { __cedar_graphqlOptions } = await import(pathToFileURL(graphqlFunctionPath).href);
81
- await server.register(redwoodFastifyGraphQLServer, {
82
- redwood: {
81
+ await server.register(cedarFastifyGraphQLServer, {
82
+ cedar: {
83
83
  apiRootPath,
84
84
  graphql: __cedar_graphqlOptions
85
85
  }
@@ -2,7 +2,7 @@ import type { Options as FastGlobOptions } from 'fast-glob';
2
2
  import type { FastifyInstance } from 'fastify';
3
3
  import type { Server } from '../createServerHelpers.js';
4
4
  export interface CedarFastifyAPIOptions {
5
- redwood: {
5
+ cedar: {
6
6
  apiRootPath?: string;
7
7
  fastGlobOptions?: FastGlobOptions;
8
8
  discoverFunctionsGlob?: string | string[];
@@ -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,sBAAsB;IAErC,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;KAI3D,CAAA;CACF;AAED,wBAAsB,eAAe,CACnC,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,sBAAsB,iBA4C7B"}
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,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,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;KAI3D,CAAA;CACF;AAED,wBAAsB,eAAe,CACnC,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,sBAAsB,iBA4C7B"}
@@ -5,7 +5,7 @@ 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
7
  async function cedarFastifyAPI(fastify, opts) {
8
- const cedarOptions = opts.redwood ?? {};
8
+ const cedarOptions = opts.cedar ?? {};
9
9
  cedarOptions.apiRootPath ??= "/";
10
10
  cedarOptions.apiRootPath = coerceRootPath(cedarOptions.apiRootPath);
11
11
  cedarOptions.fastGlobOptions ??= {};
@@ -1,10 +1,10 @@
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
7
  };
8
8
  }
9
- export declare function redwoodFastifyGraphQLServer(fastify: FastifyInstance, options: RedwoodFastifyGraphQLOptions): Promise<void>;
9
+ export declare function cedarFastifyGraphQLServer(fastify: FastifyInstance, options: CedarFastifyGraphQLOptions): Promise<void>;
10
10
  //# sourceMappingURL=graphql.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/plugins/graphql.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,eAAe,EAIhB,MAAM,SAAS,CAAA;AAOhB,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,iBA+HtC"}
1
+ {"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/plugins/graphql.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,eAAe,EAIhB,MAAM,SAAS,CAAA;AAOhB,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;KAC7B,CAAA;CACF;AAED,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,0BAA0B,iBA+HpC"}
@@ -8,10 +8,10 @@ import { coerceRootPath } from "@cedarjs/fastify-web/dist/helpers.js";
8
8
  import { createGraphQLYoga } from "@cedarjs/graphql-server";
9
9
  import { getPaths } from "@cedarjs/project-config";
10
10
  import { lambdaEventForFastifyRequest } from "../requestHandlers/awsLambdaFastify.js";
11
- async function redwoodFastifyGraphQLServer(fastify, options) {
12
- const redwoodOptions = options.redwood ?? {};
13
- redwoodOptions.apiRootPath ??= "/";
14
- redwoodOptions.apiRootPath = coerceRootPath(redwoodOptions.apiRootPath);
11
+ async function cedarFastifyGraphQLServer(fastify, options) {
12
+ const cedarOptions = options.cedar ?? {};
13
+ cedarOptions.apiRootPath ??= "/";
14
+ cedarOptions.apiRootPath = coerceRootPath(cedarOptions.apiRootPath);
15
15
  fastify.register(fastifyUrlData);
16
16
  fastify.register(fastifyMultiPart);
17
17
  const method = ["GET", "POST", "OPTIONS"];
@@ -19,7 +19,7 @@ async function redwoodFastifyGraphQLServer(fastify, options) {
19
19
  getAsyncStoreInstance().run(/* @__PURE__ */ new Map(), done);
20
20
  });
21
21
  try {
22
- if (!redwoodOptions.graphql) {
22
+ if (!cedarOptions.graphql) {
23
23
  const [graphqlFunctionPath] = await fg("dist/functions/graphql.{ts,js}", {
24
24
  cwd: getPaths().api.base,
25
25
  absolute: true
@@ -29,9 +29,9 @@ async function redwoodFastifyGraphQLServer(fastify, options) {
29
29
  if (!__cedar_graphqlOptions) {
30
30
  return;
31
31
  }
32
- redwoodOptions.graphql = __cedar_graphqlOptions;
32
+ cedarOptions.graphql = __cedar_graphqlOptions;
33
33
  }
34
- const graphqlOptions = redwoodOptions.graphql;
34
+ const graphqlOptions = cedarOptions.graphql;
35
35
  if (graphqlOptions?.realtime?.subscriptions) {
36
36
  method.push("PUT");
37
37
  }
@@ -40,7 +40,7 @@ async function redwoodFastifyGraphQLServer(fastify, options) {
40
40
  const routePaths = ["", "/health", "/readiness", "/stream"];
41
41
  for (const routePath of routePaths) {
42
42
  fastify.route({
43
- url: `${redwoodOptions.apiRootPath}${graphqlEndpoint}${routePath}`,
43
+ url: `${cedarOptions.apiRootPath}${graphqlEndpoint}${routePath}`,
44
44
  method,
45
45
  handler: async (req, reply) => {
46
46
  const request = createFetchRequest(req, reply);
@@ -99,5 +99,5 @@ function createFetchRequest(req, reply) {
99
99
  });
100
100
  }
101
101
  export {
102
- redwoodFastifyGraphQLServer
102
+ cedarFastifyGraphQLServer
103
103
  };
package/dist/types.d.ts CHANGED
@@ -3,17 +3,17 @@ import type { CedarFastifyAPIOptions } from './plugins/api.js';
3
3
  export type FastifySideConfigFnOptions = {
4
4
  side: 'api' | 'web';
5
5
  };
6
- export type FastifySideConfigFn = (fastify: FastifyInstance, options?: FastifySideConfigFnOptions & Pick<CedarFastifyAPIOptions['redwood'], 'apiRootPath'>) => Promise<FastifyInstance> | void;
6
+ export type FastifySideConfigFn = (fastify: FastifyInstance, options?: FastifySideConfigFnOptions & Pick<CedarFastifyAPIOptions['cedar'], 'apiRootPath'>) => Promise<FastifyInstance> | void;
7
7
  export type APIParsedOptions = {
8
8
  port?: number;
9
9
  host?: string;
10
10
  loadEnvFiles?: boolean;
11
- } & Omit<CedarFastifyAPIOptions['redwood'], 'fastGlobOptions'>;
11
+ } & Omit<CedarFastifyAPIOptions['cedar'], 'fastGlobOptions'>;
12
12
  export type BothParsedOptions = {
13
13
  webPort?: number;
14
14
  webHost?: string;
15
15
  apiPort?: number;
16
16
  apiHost?: string;
17
17
  apiRootPath?: string;
18
- } & Omit<CedarFastifyAPIOptions['redwood'], 'fastGlobOptions'>;
18
+ } & Omit<CedarFastifyAPIOptions['cedar'], 'fastGlobOptions'>;
19
19
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;AAG9D,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,EAAE,KAAK,GAAG,KAAK,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG,CAChC,OAAO,EAAE,eAAe,EACxB,OAAO,CAAC,EAAE,0BAA0B,GAClC,IAAI,CAAC,sBAAsB,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC,KACrD,OAAO,CAAC,eAAe,CAAC,GAAG,IAAI,CAAA;AAEpC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,GAAG,IAAI,CAAC,sBAAsB,CAAC,SAAS,CAAC,EAAE,iBAAiB,CAAC,CAAA;AAE9D,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,GAAG,IAAI,CAAC,sBAAsB,CAAC,SAAS,CAAC,EAAE,iBAAiB,CAAC,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;AAG9D,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,EAAE,KAAK,GAAG,KAAK,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG,CAChC,OAAO,EAAE,eAAe,EACxB,OAAO,CAAC,EAAE,0BAA0B,GAClC,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC,KACnD,OAAO,CAAC,eAAe,CAAC,GAAG,IAAI,CAAA;AAEpC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,GAAG,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAA;AAE5D,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,GAAG,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAA"}
package/dist/utils.d.ts CHANGED
@@ -1,6 +1,3 @@
1
- export declare function debounce<T extends (...args: any[]) => any>(func: T, wait: number): T & {
2
- cancel: () => void;
3
- };
4
1
  /** Escapes HTML characters to prevent XSS attacks */
5
2
  export declare function escape(string: string): string;
6
3
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACxD,IAAI,EAAE,CAAC,EACP,IAAI,EAAE,MAAM,GACX,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,IAAI,CAAA;CAAE,CAsB5B;AAED,qDAAqD;AACrD,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAU7C"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAU7C"}
package/dist/utils.js CHANGED
@@ -1,22 +1,3 @@
1
- function debounce(func, wait) {
2
- let timeoutId = null;
3
- const debounced = ((...args) => {
4
- if (timeoutId !== null) {
5
- clearTimeout(timeoutId);
6
- }
7
- timeoutId = setTimeout(() => {
8
- timeoutId = null;
9
- func(...args);
10
- }, wait);
11
- });
12
- debounced.cancel = () => {
13
- if (timeoutId !== null) {
14
- clearTimeout(timeoutId);
15
- timeoutId = null;
16
- }
17
- };
18
- return debounced;
19
- }
20
1
  function escape(string) {
21
2
  const htmlEscapes = {
22
3
  "&": "&amp;",
@@ -28,6 +9,5 @@ function escape(string) {
28
9
  return string.replace(/[&<>"']/g, (char) => htmlEscapes[char]);
29
10
  }
30
11
  export {
31
- debounce,
32
12
  escape
33
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/api-server",
3
- "version": "6.0.0-canary.2826",
3
+ "version": "6.0.0-canary.2829",
4
4
  "description": "CedarJS's HTTP server for Serverless Functions",
5
5
  "repository": {
6
6
  "type": "git",
@@ -53,12 +53,6 @@
53
53
  "default": "./dist/fastify.js"
54
54
  }
55
55
  },
56
- "./watch": {
57
- "default": {
58
- "types": "./dist/watch.d.ts",
59
- "default": "./dist/watch.js"
60
- }
61
- },
62
56
  "./logFormatter": {
63
57
  "default": {
64
58
  "types": "./dist/logFormatter/index.d.ts",
@@ -75,10 +69,8 @@
75
69
  "main": "./dist/createServer.js",
76
70
  "types": "./dist/createServer.d.ts",
77
71
  "bin": {
78
- "cedar-api-server-watch": "./dist/watch.js",
79
72
  "cedar-log-formatter": "./dist/logFormatter/bin.js",
80
73
  "cedar-server": "./dist/bin.js",
81
- "cedarjs-api-server-watch": "./dist/watch.js",
82
74
  "cedarjs-log-formatter": "./dist/logFormatter/bin.js",
83
75
  "cedarjs-server": "./dist/bin.js",
84
76
  "rw-log-formatter": "./dist/logFormatter/bin.js",
@@ -94,22 +86,20 @@
94
86
  "build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx\" --ignore dist --exec \"yarn build && yarn fix:permissions\"",
95
87
  "check:attw": "yarn cedar-fwtools-attw",
96
88
  "check:package": "concurrently npm:check:attw yarn:publint",
97
- "fix:permissions": "chmod +x dist/index.js; chmod +x dist/watch.js",
89
+ "fix:permissions": "chmod +x dist/index.js",
98
90
  "prepublishOnly": "NODE_ENV=production yarn build",
99
91
  "test": "vitest run",
100
92
  "test:watch": "vitest watch"
101
93
  },
102
94
  "dependencies": {
103
- "@cedarjs/api": "6.0.0-canary.2826",
104
- "@cedarjs/context": "6.0.0-canary.2826",
105
- "@cedarjs/fastify-web": "6.0.0-canary.2826",
106
- "@cedarjs/internal": "6.0.0-canary.2826",
107
- "@cedarjs/project-config": "6.0.0-canary.2826",
108
- "@cedarjs/web-server": "6.0.0-canary.2826",
95
+ "@cedarjs/api": "6.0.0-canary.2829",
96
+ "@cedarjs/context": "6.0.0-canary.2829",
97
+ "@cedarjs/fastify-web": "6.0.0-canary.2829",
98
+ "@cedarjs/project-config": "6.0.0-canary.2829",
99
+ "@cedarjs/web-server": "6.0.0-canary.2829",
109
100
  "@fastify/multipart": "9.4.0",
110
101
  "@fastify/url-data": "6.0.3",
111
102
  "ansis": "4.3.1",
112
- "chokidar": "3.6.0",
113
103
  "dotenv-defaults": "5.0.2",
114
104
  "fast-glob": "3.3.3",
115
105
  "fast-json-parse": "1.0.3",
@@ -123,7 +113,7 @@
123
113
  "yargs": "17.7.3"
124
114
  },
125
115
  "devDependencies": {
126
- "@cedarjs/framework-tools": "6.0.0-canary.2826",
116
+ "@cedarjs/framework-tools": "6.0.0-canary.2829",
127
117
  "@types/aws-lambda": "8.10.162",
128
118
  "@types/dotenv-defaults": "^5.0.0",
129
119
  "@types/split2": "4.2.3",
@@ -138,7 +128,7 @@
138
128
  "vitest": "4.1.10"
139
129
  },
140
130
  "peerDependencies": {
141
- "@cedarjs/graphql-server": "6.0.0-canary.2826"
131
+ "@cedarjs/graphql-server": "6.0.0-canary.2829"
142
132
  },
143
133
  "peerDependenciesMeta": {
144
134
  "@cedarjs/graphql-server": {
@@ -1,15 +0,0 @@
1
- export type BuildAndRestartOptions = {
2
- rebuild?: boolean;
3
- clean?: boolean;
4
- };
5
- declare class BuildManager {
6
- private shouldRebuild;
7
- private shouldClean;
8
- private debouncedBuild;
9
- private buildFn;
10
- constructor(buildFn: (options: BuildAndRestartOptions) => Promise<void>);
11
- run(options: BuildAndRestartOptions): Promise<void>;
12
- cancelScheduledBuild(): void;
13
- }
14
- export { BuildManager };
15
- //# sourceMappingURL=buildManager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"buildManager.d.ts","sourceRoot":"","sources":["../src/buildManager.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAED,cAAM,YAAY;IAChB,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,cAAc,CAA6B;IACnD,OAAO,CAAC,OAAO,CAAoD;gBAEvD,OAAO,EAAE,CAAC,OAAO,EAAE,sBAAsB,KAAK,OAAO,CAAC,IAAI,CAAC;IAsCjE,GAAG,CAAC,OAAO,EAAE,sBAAsB;IAWzC,oBAAoB;CAGrB;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
@@ -1,55 +0,0 @@
1
- import { debounce } from "./utils.js";
2
- class BuildManager {
3
- shouldRebuild;
4
- shouldClean;
5
- debouncedBuild;
6
- buildFn;
7
- constructor(buildFn) {
8
- this.shouldRebuild = true;
9
- this.shouldClean = false;
10
- this.buildFn = buildFn;
11
- if (process.env.RWJS_DELAY_RESTART) {
12
- console.warn(
13
- "[DEPRECATED] RWJS_DELAY_RESTART is deprecated and will be removed in the next major release. Please rename it to CEDAR_DELAY_API_RESTART in your .env file."
14
- );
15
- }
16
- const delay = process.env.CEDAR_DELAY_API_RESTART || process.env.RWJS_DELAY_RESTART;
17
- this.debouncedBuild = debounce(
18
- async (options) => {
19
- try {
20
- await this.buildFn({
21
- ...options,
22
- rebuild: this.shouldRebuild,
23
- clean: this.shouldClean
24
- });
25
- } finally {
26
- this.shouldRebuild = true;
27
- this.shouldClean = false;
28
- }
29
- },
30
- // We want to delay execution when multiple files are modified on the
31
- // filesystem. This usually happens when running Cedar generator commands.
32
- // Local writes are very fast, but writes in e2e environments are not, so
33
- // allow the default to be adjusted with an env-var.
34
- delay ? parseInt(delay, 10) : 500
35
- );
36
- }
37
- // Wrapper method to handle options and set precedence flags.
38
- // If we ever see a `rebuild: false` option while debouncing, we never want to rebuild.
39
- // If we ever see a `clean: true` option, we always want to clean.
40
- async run(options) {
41
- if (options.rebuild === false) {
42
- this.shouldRebuild = false;
43
- }
44
- if (options.clean) {
45
- this.shouldClean = true;
46
- }
47
- await this.debouncedBuild(options);
48
- }
49
- cancelScheduledBuild() {
50
- this.debouncedBuild.cancel();
51
- }
52
- }
53
- export {
54
- BuildManager
55
- };
@@ -1,8 +0,0 @@
1
- export declare class ServerManager {
2
- private httpServerProcess;
3
- private startApiServer;
4
- restartApiServer(): Promise<void>;
5
- killApiServer(): Promise<void>;
6
- }
7
- export declare const serverManager: ServerManager;
8
- //# sourceMappingURL=serverManager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"serverManager.d.ts","sourceRoot":"","sources":["../src/serverManager.ts"],"names":[],"mappings":"AA0BA,qBAAa,aAAa;IACxB,OAAO,CAAC,iBAAiB,CAA4B;YAEvC,cAAc;IAsDtB,gBAAgB;IAKhB,aAAa;CAmCpB;AAED,eAAO,MAAM,aAAa,eAAsB,CAAA"}
@@ -1,102 +0,0 @@
1
- import { fork } from "child_process";
2
- import fs from "node:fs";
3
- import path from "path";
4
- import ansis from "ansis";
5
- import yargs from "yargs";
6
- import { hideBin } from "yargs/helpers";
7
- import { getConfig, getPaths, resolveFile } from "@cedarjs/project-config";
8
- const argv = yargs(hideBin(process.argv)).option("debugPort", {
9
- description: "Port on which to expose API server debugger",
10
- type: "number",
11
- alias: ["debug-port", "dp"]
12
- }).option("port", {
13
- description: "The port to listen at",
14
- type: "number",
15
- alias: "p"
16
- }).parseSync();
17
- const rwjsPaths = getPaths();
18
- class ServerManager {
19
- httpServerProcess = null;
20
- async startApiServer() {
21
- const forkOpts = {
22
- execArgv: process.execArgv
23
- };
24
- if (getConfig().experimental.opentelemetry.enabled) {
25
- const opentelemetrySDKScriptPath = path.join(
26
- rwjsPaths.api.dist,
27
- "opentelemetry.js"
28
- );
29
- const opentelemetrySDKScriptPathRelative = path.relative(
30
- rwjsPaths.base,
31
- opentelemetrySDKScriptPath
32
- );
33
- console.log(
34
- `Setting up OpenTelemetry using the setup file: ${opentelemetrySDKScriptPathRelative}`
35
- );
36
- if (fs.existsSync(opentelemetrySDKScriptPath)) {
37
- forkOpts.execArgv = forkOpts.execArgv.concat([
38
- `--require=${opentelemetrySDKScriptPath}`
39
- ]);
40
- } else {
41
- console.error(
42
- `OpenTelemetry setup file does not exist at ${opentelemetrySDKScriptPathRelative}`
43
- );
44
- }
45
- }
46
- const debugPort = argv["debug-port"];
47
- if (debugPort) {
48
- forkOpts.execArgv = forkOpts.execArgv.concat([`--inspect=${debugPort}`]);
49
- }
50
- const port = argv.port ?? getConfig().api.port;
51
- const serverFile = resolveFile(`${rwjsPaths.api.dist}/server`);
52
- if (serverFile) {
53
- this.httpServerProcess = fork(
54
- serverFile,
55
- ["--apiPort", port.toString()],
56
- forkOpts
57
- );
58
- } else {
59
- const dirname = import.meta.dirname;
60
- const binPath = path.join(dirname, "bin.js");
61
- const args = ["api", "--port", port.toString()];
62
- this.httpServerProcess = fork(binPath, args, forkOpts);
63
- }
64
- }
65
- async restartApiServer() {
66
- await this.killApiServer();
67
- await this.startApiServer();
68
- }
69
- async killApiServer() {
70
- if (!this.httpServerProcess) {
71
- return;
72
- }
73
- await new Promise((resolve) => {
74
- console.log(ansis.yellow("Shutting down API server."));
75
- const cleanup = () => {
76
- this.httpServerProcess?.removeAllListeners("exit");
77
- clearTimeout(forceKillTimeout);
78
- };
79
- this.httpServerProcess?.on("exit", () => {
80
- console.log(ansis.yellow("API server exited."));
81
- cleanup();
82
- resolve();
83
- });
84
- const forceKillTimeout = setTimeout(() => {
85
- console.log(
86
- ansis.yellow(
87
- "API server did not exit within 2 seconds, forcefully closing it."
88
- )
89
- );
90
- cleanup();
91
- this.httpServerProcess?.kill("SIGKILL");
92
- resolve();
93
- }, 2e3);
94
- this.httpServerProcess?.kill();
95
- });
96
- }
97
- }
98
- const serverManager = new ServerManager();
99
- export {
100
- ServerManager,
101
- serverManager
102
- };
package/dist/watch.d.ts DELETED
@@ -1,10 +0,0 @@
1
- /**
2
- * Initialize the file watcher for the API server
3
- * Watches for changes in the API source directory and rebuilds/restarts as
4
- * needed
5
- *
6
- * Also watches package sources so that changes to workspace packages used by
7
- * the API trigger a rebuild/restart (HMR for API-side workspace packages).
8
- */
9
- export declare function startWatch(): Promise<void>;
10
- //# sourceMappingURL=watch.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../src/watch.ts"],"names":[],"mappings":"AAqEA;;;;;;;GAOG;AACH,wBAAsB,UAAU,kBAsD/B"}
package/dist/watch.js DELETED
@@ -1,375 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // src/watch.ts
4
- import path3 from "node:path";
5
- import ansis2 from "ansis";
6
- import chokidar from "chokidar";
7
- import { config } from "dotenv-defaults";
8
- import {
9
- buildApi,
10
- cleanApiBuild,
11
- rebuildApi
12
- } from "@cedarjs/internal/dist/build/api";
13
- import { loadAndValidateSdls } from "@cedarjs/internal/dist/validateSchema";
14
- import { getPaths as getPaths3 } from "@cedarjs/project-config";
15
-
16
- // src/utils.ts
17
- function debounce(func, wait) {
18
- let timeoutId = null;
19
- const debounced = ((...args) => {
20
- if (timeoutId !== null) {
21
- clearTimeout(timeoutId);
22
- }
23
- timeoutId = setTimeout(() => {
24
- timeoutId = null;
25
- func(...args);
26
- }, wait);
27
- });
28
- debounced.cancel = () => {
29
- if (timeoutId !== null) {
30
- clearTimeout(timeoutId);
31
- timeoutId = null;
32
- }
33
- };
34
- return debounced;
35
- }
36
-
37
- // src/buildManager.ts
38
- var BuildManager = class {
39
- shouldRebuild;
40
- shouldClean;
41
- debouncedBuild;
42
- buildFn;
43
- constructor(buildFn) {
44
- this.shouldRebuild = true;
45
- this.shouldClean = false;
46
- this.buildFn = buildFn;
47
- if (process.env.RWJS_DELAY_RESTART) {
48
- console.warn(
49
- "[DEPRECATED] RWJS_DELAY_RESTART is deprecated and will be removed in the next major release. Please rename it to CEDAR_DELAY_API_RESTART in your .env file."
50
- );
51
- }
52
- const delay = process.env.CEDAR_DELAY_API_RESTART || process.env.RWJS_DELAY_RESTART;
53
- this.debouncedBuild = debounce(
54
- async (options) => {
55
- try {
56
- await this.buildFn({
57
- ...options,
58
- rebuild: this.shouldRebuild,
59
- clean: this.shouldClean
60
- });
61
- } finally {
62
- this.shouldRebuild = true;
63
- this.shouldClean = false;
64
- }
65
- },
66
- // We want to delay execution when multiple files are modified on the
67
- // filesystem. This usually happens when running Cedar generator commands.
68
- // Local writes are very fast, but writes in e2e environments are not, so
69
- // allow the default to be adjusted with an env-var.
70
- delay ? parseInt(delay, 10) : 500
71
- );
72
- }
73
- // Wrapper method to handle options and set precedence flags.
74
- // If we ever see a `rebuild: false` option while debouncing, we never want to rebuild.
75
- // If we ever see a `clean: true` option, we always want to clean.
76
- async run(options) {
77
- if (options.rebuild === false) {
78
- this.shouldRebuild = false;
79
- }
80
- if (options.clean) {
81
- this.shouldClean = true;
82
- }
83
- await this.debouncedBuild(options);
84
- }
85
- cancelScheduledBuild() {
86
- this.debouncedBuild.cancel();
87
- }
88
- };
89
-
90
- // src/serverManager.ts
91
- import { fork } from "child_process";
92
- import fs from "node:fs";
93
- import path from "path";
94
- import ansis from "ansis";
95
- import yargs from "yargs";
96
- import { hideBin } from "yargs/helpers";
97
- import { getConfig, getPaths, resolveFile } from "@cedarjs/project-config";
98
- var argv = yargs(hideBin(process.argv)).option("debugPort", {
99
- description: "Port on which to expose API server debugger",
100
- type: "number",
101
- alias: ["debug-port", "dp"]
102
- }).option("port", {
103
- description: "The port to listen at",
104
- type: "number",
105
- alias: "p"
106
- }).parseSync();
107
- var rwjsPaths = getPaths();
108
- var ServerManager = class {
109
- httpServerProcess = null;
110
- async startApiServer() {
111
- const forkOpts = {
112
- execArgv: process.execArgv
113
- };
114
- if (getConfig().experimental.opentelemetry.enabled) {
115
- const opentelemetrySDKScriptPath = path.join(
116
- rwjsPaths.api.dist,
117
- "opentelemetry.js"
118
- );
119
- const opentelemetrySDKScriptPathRelative = path.relative(
120
- rwjsPaths.base,
121
- opentelemetrySDKScriptPath
122
- );
123
- console.log(
124
- `Setting up OpenTelemetry using the setup file: ${opentelemetrySDKScriptPathRelative}`
125
- );
126
- if (fs.existsSync(opentelemetrySDKScriptPath)) {
127
- forkOpts.execArgv = forkOpts.execArgv.concat([
128
- `--require=${opentelemetrySDKScriptPath}`
129
- ]);
130
- } else {
131
- console.error(
132
- `OpenTelemetry setup file does not exist at ${opentelemetrySDKScriptPathRelative}`
133
- );
134
- }
135
- }
136
- const debugPort = argv["debug-port"];
137
- if (debugPort) {
138
- forkOpts.execArgv = forkOpts.execArgv.concat([`--inspect=${debugPort}`]);
139
- }
140
- const port = argv.port ?? getConfig().api.port;
141
- const serverFile = resolveFile(`${rwjsPaths.api.dist}/server`);
142
- if (serverFile) {
143
- this.httpServerProcess = fork(
144
- serverFile,
145
- ["--apiPort", port.toString()],
146
- forkOpts
147
- );
148
- } else {
149
- const dirname = import.meta.dirname;
150
- const binPath = path.join(dirname, "bin.js");
151
- const args = ["api", "--port", port.toString()];
152
- this.httpServerProcess = fork(binPath, args, forkOpts);
153
- }
154
- }
155
- async restartApiServer() {
156
- await this.killApiServer();
157
- await this.startApiServer();
158
- }
159
- async killApiServer() {
160
- if (!this.httpServerProcess) {
161
- return;
162
- }
163
- await new Promise((resolve) => {
164
- console.log(ansis.yellow("Shutting down API server."));
165
- const cleanup = () => {
166
- this.httpServerProcess?.removeAllListeners("exit");
167
- clearTimeout(forceKillTimeout);
168
- };
169
- this.httpServerProcess?.on("exit", () => {
170
- console.log(ansis.yellow("API server exited."));
171
- cleanup();
172
- resolve();
173
- });
174
- const forceKillTimeout = setTimeout(() => {
175
- console.log(
176
- ansis.yellow(
177
- "API server did not exit within 2 seconds, forcefully closing it."
178
- )
179
- );
180
- cleanup();
181
- this.httpServerProcess?.kill("SIGKILL");
182
- resolve();
183
- }, 2e3);
184
- this.httpServerProcess?.kill();
185
- });
186
- }
187
- };
188
- var serverManager = new ServerManager();
189
-
190
- // src/watchPaths.ts
191
- import fs2 from "node:fs";
192
- import path2 from "node:path";
193
- import {
194
- getDbDir,
195
- getPaths as getPaths2,
196
- importStatementPath
197
- } from "@cedarjs/project-config";
198
- async function workspacePackagesPaths() {
199
- const cedarPaths2 = getPaths2();
200
- const packagesDir = path2.join(cedarPaths2.packages);
201
- const packages = [];
202
- try {
203
- const rootPackageJsonPath = path2.join(cedarPaths2.base, "package.json");
204
- const rootPackageJson = JSON.parse(
205
- fs2.readFileSync(rootPackageJsonPath, "utf8")
206
- );
207
- const hasPackageJsonWorkspaces = Array.isArray(rootPackageJson.workspaces) && rootPackageJson.workspaces.some((w) => w.startsWith("packages/"));
208
- if (!hasPackageJsonWorkspaces || !fs2.existsSync(packagesDir)) {
209
- return [];
210
- }
211
- const globPattern = path2.join(packagesDir, "*").replaceAll("\\", "/");
212
- const packageDirs = await Array.fromAsync(fs2.promises.glob(globPattern));
213
- const apiPackageJsonPath = path2.join(cedarPaths2.api.base, "package.json");
214
- const apiPackageJson = JSON.parse(
215
- fs2.readFileSync(apiPackageJsonPath, "utf8")
216
- );
217
- const deps = {
218
- ...apiPackageJson.dependencies ?? {},
219
- ...apiPackageJson.devDependencies ?? {},
220
- ...apiPackageJson.peerDependencies ?? {}
221
- };
222
- const workspaceDepNames = /* @__PURE__ */ new Set();
223
- for (const [name, version] of Object.entries(deps)) {
224
- if (String(version).startsWith("workspace:")) {
225
- workspaceDepNames.add(name);
226
- }
227
- }
228
- for (const packageDir of packageDirs) {
229
- const packageJsonPath = path2.join(packageDir, "package.json");
230
- if (!fs2.existsSync(packageJsonPath)) {
231
- continue;
232
- }
233
- const pkgJson = JSON.parse(fs2.readFileSync(packageJsonPath, "utf8"));
234
- if (workspaceDepNames.has(pkgJson.name)) {
235
- packages.push(path2.join(packageDir, "dist"));
236
- }
237
- }
238
- } catch {
239
- }
240
- return packages;
241
- }
242
- async function apiIgnorePaths() {
243
- const cedarPaths2 = getPaths2();
244
- const dbDir = await getDbDir(cedarPaths2.api.prismaConfig);
245
- if (dbDir === cedarPaths2.api.base) {
246
- throw new Error(
247
- "Database directory cannot be the same as the API directory"
248
- );
249
- }
250
- const ignoredApiPaths = [
251
- // TODO: Is this still true?
252
- // use this, because using cedarPaths.api.dist seems to not ignore on first
253
- // build
254
- "api/dist",
255
- cedarPaths2.api.types,
256
- dbDir
257
- ];
258
- return ignoredApiPaths;
259
- }
260
- async function getIgnoreFunction() {
261
- const cedarPaths2 = getPaths2();
262
- const ignoredApiPaths = await apiIgnorePaths();
263
- const ignoredExtensions = [
264
- ".DS_Store",
265
- ".db",
266
- ".sqlite",
267
- "-journal",
268
- ".test.js",
269
- ".test.ts",
270
- ".scenarios.ts",
271
- ".scenarios.js",
272
- ".d.ts",
273
- ".log"
274
- ];
275
- return (file) => {
276
- if (file.includes("node_modules")) {
277
- return true;
278
- }
279
- if (ignoredExtensions.some((ext) => file.endsWith(ext))) {
280
- return true;
281
- }
282
- if (file.includes(importStatementPath(cedarPaths2.packages)) && file.includes("/src/")) {
283
- return true;
284
- }
285
- if (ignoredApiPaths.some((ignoredPath) => file.includes(ignoredPath))) {
286
- return true;
287
- }
288
- return false;
289
- };
290
- }
291
- async function pathsToWatch() {
292
- const cedarPaths2 = getPaths2();
293
- const watchPaths = [cedarPaths2.api.src, ...await workspacePackagesPaths()];
294
- return watchPaths.map((p) => importStatementPath(p));
295
- }
296
-
297
- // src/watch.ts
298
- var cedarPaths = getPaths3();
299
- if (!process.env.CEDAR_ENV_FILES_LOADED) {
300
- config({
301
- path: path3.join(cedarPaths.base, ".env"),
302
- defaults: path3.join(cedarPaths.base, ".env.defaults"),
303
- multiline: true
304
- });
305
- process.env.CEDAR_ENV_FILES_LOADED = "true";
306
- }
307
- async function buildAndServe(options) {
308
- const buildTs = Date.now();
309
- console.log(ansis2.dim.italic("Building..."));
310
- if (options.clean) {
311
- await cleanApiBuild();
312
- }
313
- if (options.rebuild) {
314
- await rebuildApi();
315
- } else {
316
- await buildApi();
317
- }
318
- await serverManager.restartApiServer();
319
- console.log(ansis2.dim.italic("Took " + (Date.now() - buildTs) + " ms"));
320
- }
321
- var buildManager = new BuildManager(buildAndServe);
322
- async function validateSdls() {
323
- try {
324
- await loadAndValidateSdls();
325
- return true;
326
- } catch (e) {
327
- serverManager.killApiServer();
328
- console.error(
329
- ansis2.redBright(`[GQL Server Error] - Schema validation failed`)
330
- );
331
- console.error(ansis2.red(e?.message));
332
- console.error(ansis2.redBright("-".repeat(40)));
333
- buildManager.cancelScheduledBuild();
334
- return false;
335
- }
336
- }
337
- async function startWatch() {
338
- const patterns = await pathsToWatch();
339
- const watcher = chokidar.watch(patterns, {
340
- persistent: true,
341
- ignoreInitial: true,
342
- ignored: await getIgnoreFunction()
343
- });
344
- watcher.on("ready", async () => {
345
- await buildManager.run({ clean: true, rebuild: false });
346
- await validateSdls();
347
- });
348
- watcher.on("all", async (eventName, filePath) => {
349
- if (eventName === "addDir" && filePath === cedarPaths.api.base) {
350
- return;
351
- }
352
- if (eventName) {
353
- if (filePath.includes(".sdl")) {
354
- const isValid = await validateSdls();
355
- if (!isValid) {
356
- return;
357
- }
358
- }
359
- }
360
- const displayPath = path3.relative(cedarPaths.base, filePath);
361
- console.log(ansis2.dim(`[${eventName}] ${displayPath}`));
362
- buildManager.cancelScheduledBuild();
363
- if (eventName === "add" || eventName === "unlink") {
364
- await buildManager.run({ rebuild: false });
365
- } else {
366
- await buildManager.run({ rebuild: true });
367
- }
368
- });
369
- }
370
- if (import.meta.url === `file://${process.argv[1]}`) {
371
- startWatch();
372
- }
373
- export {
374
- startWatch
375
- };
@@ -1,3 +0,0 @@
1
- export declare function getIgnoreFunction(): Promise<(file: string) => boolean>;
2
- export declare function pathsToWatch(): Promise<string[]>;
3
- //# sourceMappingURL=watchPaths.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"watchPaths.d.ts","sourceRoot":"","sources":["../src/watchPaths.ts"],"names":[],"mappings":"AAmGA,wBAAsB,iBAAiB,mBAqBvB,MAAM,cAwBrB;AAED,wBAAsB,YAAY,sBAQjC"}
@@ -1,109 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import {
4
- getDbDir,
5
- getPaths,
6
- importStatementPath
7
- } from "@cedarjs/project-config";
8
- async function workspacePackagesPaths() {
9
- const cedarPaths = getPaths();
10
- const packagesDir = path.join(cedarPaths.packages);
11
- const packages = [];
12
- try {
13
- const rootPackageJsonPath = path.join(cedarPaths.base, "package.json");
14
- const rootPackageJson = JSON.parse(
15
- fs.readFileSync(rootPackageJsonPath, "utf8")
16
- );
17
- const hasPackageJsonWorkspaces = Array.isArray(rootPackageJson.workspaces) && rootPackageJson.workspaces.some((w) => w.startsWith("packages/"));
18
- if (!hasPackageJsonWorkspaces || !fs.existsSync(packagesDir)) {
19
- return [];
20
- }
21
- const globPattern = path.join(packagesDir, "*").replaceAll("\\", "/");
22
- const packageDirs = await Array.fromAsync(fs.promises.glob(globPattern));
23
- const apiPackageJsonPath = path.join(cedarPaths.api.base, "package.json");
24
- const apiPackageJson = JSON.parse(
25
- fs.readFileSync(apiPackageJsonPath, "utf8")
26
- );
27
- const deps = {
28
- ...apiPackageJson.dependencies ?? {},
29
- ...apiPackageJson.devDependencies ?? {},
30
- ...apiPackageJson.peerDependencies ?? {}
31
- };
32
- const workspaceDepNames = /* @__PURE__ */ new Set();
33
- for (const [name, version] of Object.entries(deps)) {
34
- if (String(version).startsWith("workspace:")) {
35
- workspaceDepNames.add(name);
36
- }
37
- }
38
- for (const packageDir of packageDirs) {
39
- const packageJsonPath = path.join(packageDir, "package.json");
40
- if (!fs.existsSync(packageJsonPath)) {
41
- continue;
42
- }
43
- const pkgJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
44
- if (workspaceDepNames.has(pkgJson.name)) {
45
- packages.push(path.join(packageDir, "dist"));
46
- }
47
- }
48
- } catch {
49
- }
50
- return packages;
51
- }
52
- async function apiIgnorePaths() {
53
- const cedarPaths = getPaths();
54
- const dbDir = await getDbDir(cedarPaths.api.prismaConfig);
55
- if (dbDir === cedarPaths.api.base) {
56
- throw new Error(
57
- "Database directory cannot be the same as the API directory"
58
- );
59
- }
60
- const ignoredApiPaths = [
61
- // TODO: Is this still true?
62
- // use this, because using cedarPaths.api.dist seems to not ignore on first
63
- // build
64
- "api/dist",
65
- cedarPaths.api.types,
66
- dbDir
67
- ];
68
- return ignoredApiPaths;
69
- }
70
- async function getIgnoreFunction() {
71
- const cedarPaths = getPaths();
72
- const ignoredApiPaths = await apiIgnorePaths();
73
- const ignoredExtensions = [
74
- ".DS_Store",
75
- ".db",
76
- ".sqlite",
77
- "-journal",
78
- ".test.js",
79
- ".test.ts",
80
- ".scenarios.ts",
81
- ".scenarios.js",
82
- ".d.ts",
83
- ".log"
84
- ];
85
- return (file) => {
86
- if (file.includes("node_modules")) {
87
- return true;
88
- }
89
- if (ignoredExtensions.some((ext) => file.endsWith(ext))) {
90
- return true;
91
- }
92
- if (file.includes(importStatementPath(cedarPaths.packages)) && file.includes("/src/")) {
93
- return true;
94
- }
95
- if (ignoredApiPaths.some((ignoredPath) => file.includes(ignoredPath))) {
96
- return true;
97
- }
98
- return false;
99
- };
100
- }
101
- async function pathsToWatch() {
102
- const cedarPaths = getPaths();
103
- const watchPaths = [cedarPaths.api.src, ...await workspacePackagesPaths()];
104
- return watchPaths.map((p) => importStatementPath(p));
105
- }
106
- export {
107
- getIgnoreFunction,
108
- pathsToWatch
109
- };