@cedarjs/testing 7.0.0-canary.3259 → 7.0.0-rc.127

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 (218) hide show
  1. package/config/jest/api/RedwoodApiJestEnv.d.ts +11 -0
  2. package/config/jest/api/RedwoodApiJestEnv.d.ts.map +1 -0
  3. package/config/jest/api/RedwoodApiJestEnv.js +48 -0
  4. package/config/jest/api/apiBabelConfig.d.ts +5 -0
  5. package/config/jest/api/apiBabelConfig.d.ts.map +1 -0
  6. package/config/jest/api/apiBabelConfig.js +34 -0
  7. package/config/jest/api/globalSetup.d.ts +3 -0
  8. package/config/jest/api/globalSetup.d.ts.map +1 -0
  9. package/config/jest/api/globalSetup.js +63 -0
  10. package/config/jest/api/index.d.ts +3 -0
  11. package/config/jest/api/index.d.ts.map +1 -0
  12. package/config/jest/api/index.js +25 -0
  13. package/config/jest/api/jest-preset.d.ts +4 -0
  14. package/config/jest/api/jest-preset.d.ts.map +1 -0
  15. package/config/jest/api/jest-preset.js +140 -0
  16. package/config/jest/api/jest.setup.d.ts +2 -0
  17. package/config/jest/api/jest.setup.d.ts.map +1 -0
  18. package/config/jest/api/jest.setup.js +267 -0
  19. package/config/jest/api/package.json +8 -0
  20. package/config/jest/babelPlugins/babel-plugin-redwood-cell.d.ts +11 -0
  21. package/config/jest/babelPlugins/babel-plugin-redwood-cell.d.ts.map +1 -0
  22. package/config/jest/babelPlugins/babel-plugin-redwood-cell.js +122 -0
  23. package/config/jest/jest-serial-runner.d.ts +8 -0
  24. package/config/jest/jest-serial-runner.d.ts.map +1 -0
  25. package/config/jest/jest-serial-runner.js +37 -0
  26. package/config/jest/web/RedwoodWebJestEnv.d.ts +6 -0
  27. package/config/jest/web/RedwoodWebJestEnv.d.ts.map +1 -0
  28. package/config/jest/web/RedwoodWebJestEnv.js +43 -0
  29. package/config/jest/web/index.d.ts +3 -0
  30. package/config/jest/web/index.d.ts.map +1 -0
  31. package/config/jest/web/index.js +25 -0
  32. package/config/jest/web/jest-fixed-jsdom.d.js +1 -0
  33. package/config/jest/web/jest-preset.d.ts +4 -0
  34. package/config/jest/web/jest-preset.d.ts.map +1 -0
  35. package/config/jest/web/jest-preset.js +224 -0
  36. package/config/jest/web/jest.setup.d.ts +7 -0
  37. package/config/jest/web/jest.setup.d.ts.map +1 -0
  38. package/config/jest/web/jest.setup.js +21 -0
  39. package/config/jest/web/package.json +8 -0
  40. package/config/jest/web/resolver.d.ts +4 -0
  41. package/config/jest/web/resolver.d.ts.map +1 -0
  42. package/config/jest/web/resolver.js +30 -0
  43. package/config/jest/web/webBabelConfig.d.ts +10 -0
  44. package/config/jest/web/webBabelConfig.d.ts.map +1 -0
  45. package/config/jest/web/webBabelConfig.js +48 -0
  46. package/config/package.json +1 -0
  47. package/dist/api/mockContext.d.ts +1 -1
  48. package/dist/api/mockContext.d.ts.map +1 -1
  49. package/dist/api/vitest/vite-plugin-cedar-vitest-api-config.d.ts.map +1 -1
  50. package/dist/api/vitest/vite-plugin-cedar-vitest-api-config.js +1 -6
  51. package/dist/api/vitest/vitest-api.setup.d.ts.map +1 -1
  52. package/dist/api/vitest/vitest-api.setup.js +22 -9
  53. package/dist/cjs/api/apiFunction.d.ts +37 -0
  54. package/dist/cjs/api/apiFunction.d.ts.map +1 -0
  55. package/dist/cjs/api/apiFunction.js +89 -0
  56. package/dist/cjs/api/checkTestDatabase.d.ts +50 -0
  57. package/dist/cjs/api/checkTestDatabase.d.ts.map +1 -0
  58. package/dist/cjs/api/checkTestDatabase.js +182 -0
  59. package/dist/cjs/api/directive.d.ts +51 -0
  60. package/dist/cjs/api/directive.d.ts.map +1 -0
  61. package/dist/cjs/api/directive.js +77 -0
  62. package/dist/cjs/api/index.d.ts +4 -0
  63. package/dist/cjs/api/index.d.ts.map +1 -0
  64. package/dist/cjs/api/index.js +26 -0
  65. package/dist/cjs/api/mockContext.d.ts +5 -0
  66. package/dist/cjs/api/mockContext.d.ts.map +1 -0
  67. package/dist/cjs/api/mockContext.js +58 -0
  68. package/dist/cjs/api/scenario.d.ts +108 -0
  69. package/dist/cjs/api/scenario.d.ts.map +1 -0
  70. package/dist/cjs/api/scenario.js +30 -0
  71. package/dist/cjs/api/vitest/CedarApiVitestEnv.js +86 -0
  72. package/dist/cjs/api/vitest/index.js +34 -0
  73. package/dist/cjs/api/vitest/vite-plugin-auto-import.js +71 -0
  74. package/dist/cjs/api/vitest/vite-plugin-cedar-vitest-api-config.js +69 -0
  75. package/dist/cjs/api/vitest/vite-plugin-track-db-imports.js +47 -0
  76. package/dist/cjs/api/vitest/vitest-api.setup.js +270 -0
  77. package/dist/cjs/cache/index.d.ts +50 -0
  78. package/dist/cjs/cache/index.d.ts.map +1 -0
  79. package/dist/cjs/cache/index.js +104 -0
  80. package/dist/cjs/config/jest/api/RedwoodApiJestEnv.d.ts +11 -0
  81. package/dist/cjs/config/jest/api/RedwoodApiJestEnv.d.ts.map +1 -0
  82. package/dist/cjs/config/jest/api/RedwoodApiJestEnv.js +48 -0
  83. package/dist/cjs/config/jest/api/apiBabelConfig.d.ts +5 -0
  84. package/dist/cjs/config/jest/api/apiBabelConfig.d.ts.map +1 -0
  85. package/dist/cjs/config/jest/api/apiBabelConfig.js +34 -0
  86. package/dist/cjs/config/jest/api/globalSetup.d.ts +3 -0
  87. package/dist/cjs/config/jest/api/globalSetup.d.ts.map +1 -0
  88. package/dist/cjs/config/jest/api/globalSetup.js +63 -0
  89. package/dist/cjs/config/jest/api/index.d.ts +3 -0
  90. package/dist/cjs/config/jest/api/index.d.ts.map +1 -0
  91. package/dist/cjs/config/jest/api/index.js +25 -0
  92. package/dist/cjs/config/jest/api/jest-preset.d.ts +4 -0
  93. package/dist/cjs/config/jest/api/jest-preset.d.ts.map +1 -0
  94. package/dist/cjs/config/jest/api/jest-preset.js +140 -0
  95. package/dist/cjs/config/jest/api/jest.setup.d.ts +2 -0
  96. package/dist/cjs/config/jest/api/jest.setup.d.ts.map +1 -0
  97. package/dist/cjs/config/jest/api/jest.setup.js +267 -0
  98. package/dist/cjs/config/jest/babelPlugins/babel-plugin-redwood-cell.d.ts +11 -0
  99. package/dist/cjs/config/jest/babelPlugins/babel-plugin-redwood-cell.d.ts.map +1 -0
  100. package/dist/cjs/config/jest/babelPlugins/babel-plugin-redwood-cell.js +122 -0
  101. package/dist/cjs/config/jest/jest-serial-runner.d.ts +8 -0
  102. package/dist/cjs/config/jest/jest-serial-runner.d.ts.map +1 -0
  103. package/dist/cjs/config/jest/jest-serial-runner.js +37 -0
  104. package/dist/cjs/config/jest/web/RedwoodWebJestEnv.d.ts +6 -0
  105. package/dist/cjs/config/jest/web/RedwoodWebJestEnv.d.ts.map +1 -0
  106. package/dist/cjs/config/jest/web/RedwoodWebJestEnv.js +43 -0
  107. package/dist/cjs/config/jest/web/index.d.ts +3 -0
  108. package/dist/cjs/config/jest/web/index.d.ts.map +1 -0
  109. package/dist/cjs/config/jest/web/index.js +25 -0
  110. package/dist/cjs/config/jest/web/jest-fixed-jsdom.d.js +1 -0
  111. package/dist/cjs/config/jest/web/jest-preset.d.ts +4 -0
  112. package/dist/cjs/config/jest/web/jest-preset.d.ts.map +1 -0
  113. package/dist/cjs/config/jest/web/jest-preset.js +224 -0
  114. package/dist/cjs/config/jest/web/jest.setup.d.ts +7 -0
  115. package/dist/cjs/config/jest/web/jest.setup.d.ts.map +1 -0
  116. package/dist/cjs/config/jest/web/jest.setup.js +21 -0
  117. package/dist/cjs/config/jest/web/resolver.d.ts +4 -0
  118. package/dist/cjs/config/jest/web/resolver.d.ts.map +1 -0
  119. package/dist/cjs/config/jest/web/resolver.js +30 -0
  120. package/dist/cjs/config/jest/web/webBabelConfig.d.ts +10 -0
  121. package/dist/cjs/config/jest/web/webBabelConfig.d.ts.map +1 -0
  122. package/dist/cjs/config/jest/web/webBabelConfig.js +48 -0
  123. package/dist/cjs/package.json +1 -0
  124. package/dist/cjs/web/MockParamsProvider.d.ts +7 -0
  125. package/dist/cjs/web/MockParamsProvider.d.ts.map +1 -0
  126. package/dist/cjs/web/MockParamsProvider.js +44 -0
  127. package/dist/cjs/web/MockProviders.d.ts +5 -0
  128. package/dist/cjs/web/MockProviders.d.ts.map +1 -0
  129. package/dist/cjs/web/MockProviders.js +66 -0
  130. package/dist/cjs/web/MockRouter.d.ts +11 -0
  131. package/dist/cjs/web/MockRouter.d.ts.map +1 -0
  132. package/dist/cjs/web/MockRouter.js +48 -0
  133. package/dist/cjs/web/customRender.d.ts +6 -0
  134. package/dist/cjs/web/customRender.d.ts.map +1 -0
  135. package/dist/cjs/web/customRender.js +54 -0
  136. package/dist/cjs/web/fileMock.d.ts +10 -0
  137. package/dist/cjs/web/fileMock.d.ts.map +1 -0
  138. package/dist/cjs/web/fileMock.js +24 -0
  139. package/dist/cjs/web/findCellMocks.d.ts +2 -0
  140. package/dist/cjs/web/findCellMocks.d.ts.map +1 -0
  141. package/dist/cjs/web/findCellMocks.js +45 -0
  142. package/dist/cjs/web/globRoutesImporter.d.ts +13 -0
  143. package/dist/cjs/web/globRoutesImporter.d.ts.map +1 -0
  144. package/dist/cjs/web/globRoutesImporter.js +46 -0
  145. package/dist/cjs/web/global.d.ts +6 -0
  146. package/dist/cjs/web/global.d.ts.map +1 -0
  147. package/dist/cjs/web/global.js +1 -0
  148. package/dist/cjs/web/index.d.ts +6 -0
  149. package/dist/cjs/web/index.d.ts.map +1 -0
  150. package/dist/cjs/web/index.js +41 -0
  151. package/dist/cjs/web/mockAuth.d.ts +29 -0
  152. package/dist/cjs/web/mockAuth.d.ts.map +1 -0
  153. package/dist/cjs/web/mockAuth.js +89 -0
  154. package/dist/cjs/web/mockRequests.d.ts +72 -0
  155. package/dist/cjs/web/mockRequests.d.ts.map +1 -0
  156. package/dist/cjs/web/mockRequests.js +210 -0
  157. package/dist/cjs/web/vitest/index.js +37 -0
  158. package/dist/cjs/web/vitest/vite-plugin-auto-import.js +60 -0
  159. package/dist/cjs/web/vitest/vite-plugin-cedar-vitest-web-config.js +51 -0
  160. package/dist/cjs/web/vitest/vite-plugin-cedarjs-router-import-transform.js +42 -0
  161. package/dist/cjs/web/vitest/vite-plugin-create-auth-import-transform.js +43 -0
  162. package/dist/cjs/web/vitest/vitest-web.setup.js +19 -0
  163. package/dist/config/jest/api/RedwoodApiJestEnv.d.ts +11 -0
  164. package/dist/config/jest/api/RedwoodApiJestEnv.d.ts.map +1 -0
  165. package/dist/config/jest/api/RedwoodApiJestEnv.js +28 -0
  166. package/dist/config/jest/api/apiBabelConfig.d.ts +5 -0
  167. package/dist/config/jest/api/apiBabelConfig.d.ts.map +1 -0
  168. package/dist/config/jest/api/apiBabelConfig.js +18 -0
  169. package/dist/config/jest/api/globalSetup.d.ts +3 -0
  170. package/dist/config/jest/api/globalSetup.d.ts.map +1 -0
  171. package/dist/config/jest/api/globalSetup.js +36 -0
  172. package/dist/config/jest/api/index.d.ts +3 -0
  173. package/dist/config/jest/api/index.d.ts.map +1 -0
  174. package/dist/config/jest/api/index.js +15 -0
  175. package/dist/config/jest/api/jest-preset.d.ts +4 -0
  176. package/dist/config/jest/api/jest-preset.d.ts.map +1 -0
  177. package/dist/config/jest/api/jest-preset.js +110 -0
  178. package/dist/config/jest/api/jest.setup.d.ts +2 -0
  179. package/dist/config/jest/api/jest.setup.d.ts.map +1 -0
  180. package/dist/config/jest/api/jest.setup.js +244 -0
  181. package/dist/config/jest/babelPlugins/babel-plugin-redwood-cell.d.ts +11 -0
  182. package/dist/config/jest/babelPlugins/babel-plugin-redwood-cell.d.ts.map +1 -0
  183. package/dist/config/jest/babelPlugins/babel-plugin-redwood-cell.js +102 -0
  184. package/dist/config/jest/jest-serial-runner.d.ts +8 -0
  185. package/dist/config/jest/jest-serial-runner.d.ts.map +1 -0
  186. package/dist/config/jest/jest-serial-runner.js +27 -0
  187. package/dist/config/jest/web/RedwoodWebJestEnv.d.ts +6 -0
  188. package/dist/config/jest/web/RedwoodWebJestEnv.d.ts.map +1 -0
  189. package/dist/config/jest/web/RedwoodWebJestEnv.js +13 -0
  190. package/dist/config/jest/web/index.d.ts +3 -0
  191. package/dist/config/jest/web/index.d.ts.map +1 -0
  192. package/dist/config/jest/web/index.js +15 -0
  193. package/dist/config/jest/web/jest-fixed-jsdom.d.js +0 -0
  194. package/dist/config/jest/web/jest-preset.d.ts +4 -0
  195. package/dist/config/jest/web/jest-preset.d.ts.map +1 -0
  196. package/dist/config/jest/web/jest-preset.js +194 -0
  197. package/dist/config/jest/web/jest.setup.d.ts +7 -0
  198. package/dist/config/jest/web/jest.setup.d.ts.map +1 -0
  199. package/dist/config/jest/web/jest.setup.js +27 -0
  200. package/dist/config/jest/web/resolver.d.ts +4 -0
  201. package/dist/config/jest/web/resolver.d.ts.map +1 -0
  202. package/dist/config/jest/web/resolver.js +42 -0
  203. package/dist/config/jest/web/webBabelConfig.d.ts +10 -0
  204. package/dist/config/jest/web/webBabelConfig.d.ts.map +1 -0
  205. package/dist/config/jest/web/webBabelConfig.js +18 -0
  206. package/dist/web/MockParamsProvider.d.ts.map +1 -1
  207. package/dist/web/MockParamsProvider.js +1 -10
  208. package/dist/web/MockRouter.d.ts.map +1 -1
  209. package/dist/web/fileMock.d.ts +10 -0
  210. package/dist/web/fileMock.d.ts.map +1 -0
  211. package/dist/web/fileMock.js +4 -0
  212. package/dist/web/mockRequests.d.ts +0 -14
  213. package/dist/web/mockRequests.d.ts.map +1 -1
  214. package/dist/web/mockRequests.js +0 -8
  215. package/package.json +95 -22
  216. package/dist/api/vitest/teardown.d.ts +0 -18
  217. package/dist/api/vitest/teardown.d.ts.map +0 -1
  218. package/dist/api/vitest/teardown.js +0 -43
@@ -1,5 +1,5 @@
1
1
  export interface GlobalContext extends Record<string, unknown> {
2
2
  }
3
- export declare const context: GlobalContext;
3
+ export declare const context: {};
4
4
  export declare const setContext: (newContext: GlobalContext) => GlobalContext;
5
5
  //# sourceMappingURL=mockContext.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mockContext.d.ts","sourceRoot":"","sources":["../../src/api/mockContext.ts"],"names":[],"mappings":"AAiCA,MAAM,WAAW,aAAc,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAAG;AAEjE,eAAO,MAAM,OAAO,eAAc,CAAA;AAElC,eAAO,MAAM,UAAU,GAAI,YAAY,aAAa,KAAG,aAYtD,CAAA"}
1
+ {"version":3,"file":"mockContext.d.ts","sourceRoot":"","sources":["../../src/api/mockContext.ts"],"names":[],"mappings":"AAoCA,MAAM,WAAW,aAAc,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAAG;AAEjE,eAAO,MAAM,OAAO,IAAc,CAAA;AAElC,eAAO,MAAM,UAAU,GAAI,YAAY,aAAa,KAAG,aAKtD,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"vite-plugin-cedar-vitest-api-config.d.ts","sourceRoot":"","sources":["../../../src/api/vitest/vite-plugin-cedar-vitest-api-config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAIlC,wBAAgB,0BAA0B,IAAI,MAAM,CAiCnD"}
1
+ {"version":3,"file":"vite-plugin-cedar-vitest-api-config.d.ts","sourceRoot":"","sources":["../../../src/api/vitest/vite-plugin-cedar-vitest-api-config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAIlC,wBAAgB,0BAA0B,IAAI,MAAM,CA4BnD"}
@@ -7,12 +7,7 @@ function cedarVitestApiConfigPlugin() {
7
7
  return {
8
8
  define: getEnvVarDefinitions(),
9
9
  ssr: {
10
- // `@cedarjs/tenancy` reads and writes the request context, which
11
- // the api test setup replaces with a mock. The mock only reaches
12
- // code Vite processes, so the tenancy runtime has to be bundled
13
- // rather than loaded as an external dependency, or a service under
14
- // test and its Prisma extension would see different contexts.
15
- noExternal: ["@cedarjs/testing", "@cedarjs/tenancy"]
10
+ noExternal: ["@cedarjs/testing"]
16
11
  },
17
12
  resolve: {
18
13
  alias: {
@@ -1 +1 @@
1
- {"version":3,"file":"vitest-api.setup.d.ts","sourceRoot":"","sources":["../../../src/api/vitest/vitest-api.setup.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AA4C1D,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,eAAe,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,KAAK,IAAI,CAAA;CAC3E;AAUD,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,cAAc,EAAE,cAAc,CAAA;IAElC,IAAI,uBAAuB,EAAE,OAAO,CAAA;CACrC"}
1
+ {"version":3,"file":"vitest-api.setup.d.ts","sourceRoot":"","sources":["../../../src/api/vitest/vitest-api.setup.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AA0C1D,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,eAAe,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,KAAK,IAAI,CAAA;CAC3E;AAUD,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,cAAc,EAAE,cAAc,CAAA;IAElC,IAAI,uBAAuB,EAAE,OAAO,CAAA;CACrC"}
@@ -3,7 +3,6 @@ import path from "node:path";
3
3
  import { afterAll, beforeEach, it, describe, vi, beforeAll } from "vitest";
4
4
  import { getPaths, getPrismaSchemas } from "@cedarjs/project-config";
5
5
  import { defineScenario } from "@cedarjs/testing/api";
6
- import { emptyTablesInWorkingOrder } from "./teardown.js";
7
6
  const mockContextStore = vi.hoisted(() => /* @__PURE__ */ new Map());
8
7
  const mockContext = vi.hoisted(
9
8
  () => new Proxy(
@@ -39,6 +38,7 @@ globalThis.mockCurrentUser = (currentUser) => {
39
38
  };
40
39
  globalThis.defineScenario = defineScenario;
41
40
  const cedarPaths = getPaths();
41
+ const HANDLED_ERRORS = [1451, 1811, 23001, 23503];
42
42
  const TEARDOWN_CACHE_PATH = path.join(
43
43
  cedarPaths.generated.base,
44
44
  "scenarioTeardown.json"
@@ -132,12 +132,23 @@ async function teardown() {
132
132
  }
133
133
  const quoteStyle2 = await getQuoteStyle();
134
134
  const projectDb = await getProjectDb();
135
- teardownOrder = await emptyTablesInWorkingOrder(
136
- teardownOrder,
137
- (modelName) => projectDb.$executeRawUnsafe(
138
- `DELETE FROM ${quoteStyle2}${modelName}${quoteStyle2}`
139
- )
140
- );
135
+ for (const modelName of teardownOrder) {
136
+ try {
137
+ const query = `DELETE FROM ${quoteStyle2}${modelName}${quoteStyle2}`;
138
+ await projectDb.$executeRawUnsafe(query);
139
+ } catch (e) {
140
+ console.error("teardown error\n", e);
141
+ const match = isErrorWithMessage(e) && e.message.match(/Code: `(\d+)`/);
142
+ if (match && HANDLED_ERRORS.includes(parseInt(match[1]))) {
143
+ const index = teardownOrder.indexOf(modelName);
144
+ teardownOrder[index] = null;
145
+ teardownOrder.push(modelName);
146
+ } else {
147
+ throw e;
148
+ }
149
+ }
150
+ }
151
+ teardownOrder = teardownOrder.filter((val) => val);
141
152
  if (!isIdenticalArray(teardownOrder, originalTeardownOrder)) {
142
153
  originalTeardownOrder = deepCopy(teardownOrder);
143
154
  fs.writeFileSync(TEARDOWN_CACHE_PATH, JSON.stringify(teardownOrder));
@@ -216,8 +227,7 @@ async function getQuoteStyle() {
216
227
  }
217
228
  async function getProjectDb() {
218
229
  const libDb = await import(`${cedarPaths.api.lib}/db`);
219
- const db = libDb.db;
220
- return typeof db?.$withoutTenant === "function" ? db.$withoutTenant() : db;
230
+ return libDb.db;
221
231
  }
222
232
  function isIdenticalArray(a, b) {
223
233
  return JSON.stringify(a) === JSON.stringify(b);
@@ -225,6 +235,9 @@ function isIdenticalArray(a, b) {
225
235
  function deepCopy(obj) {
226
236
  return JSON.parse(JSON.stringify(obj));
227
237
  }
238
+ function isErrorWithMessage(e) {
239
+ return !!e && typeof e === "object" && "message" in e && typeof e.message === "string";
240
+ }
228
241
  function isErrorWithCode(e) {
229
242
  return !!e && typeof e === "object" && "code" in e && typeof e.code === "string";
230
243
  }
@@ -0,0 +1,37 @@
1
+ import type { APIGatewayProxyEvent, APIGatewayProxyEventHeaders, Context } from 'aws-lambda';
2
+ import type { SupportedVerifierTypes } from '@cedarjs/api/webhooks';
3
+ interface BuildEventParams extends Partial<APIGatewayProxyEvent> {
4
+ payload?: string | null | Record<any, any>;
5
+ signature?: string;
6
+ signatureHeader?: string;
7
+ headers?: APIGatewayProxyEventHeaders;
8
+ }
9
+ /**
10
+ * @description Use this to mock out the http request event that is received by your function in unit tests
11
+ *
12
+ * @example Mocking sending headers
13
+ * mockHttpEvent({header: {'X-Custom-Header': 'bazinga'}})
14
+ *
15
+ * @example Adding a JSON payload
16
+ * mockHttpEvent({payload: JSON.stringify(mockedRequestBody)})
17
+ *
18
+ * @returns APIGatewayProxyEvent
19
+ */
20
+ export declare const mockHttpEvent: ({ payload, signature, signatureHeader, queryStringParameters, httpMethod, headers, path, isBase64Encoded, ...others }: BuildEventParams) => APIGatewayProxyEvent;
21
+ /**
22
+ * @description Use this function to mock the http event's context
23
+ * @see: https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html
24
+ **/
25
+ export declare const mockContext: () => Context;
26
+ interface MockedSignedWebhookParams extends Omit<BuildEventParams, 'signature' | 'signatureHeader'> {
27
+ signatureType: Exclude<SupportedVerifierTypes, 'skipVerifier'>;
28
+ signatureHeader: string;
29
+ secret: string;
30
+ }
31
+ /**
32
+ * @description Use this function to mock a signed webhook
33
+ * @see https://cedarjs.com/docs/webhooks#webhooks
34
+ **/
35
+ export declare const mockSignedWebhook: ({ payload, signatureType, signatureHeader, secret, ...others }: MockedSignedWebhookParams) => APIGatewayProxyEvent;
36
+ export {};
37
+ //# sourceMappingURL=apiFunction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apiFunction.d.ts","sourceRoot":"","sources":["../../../src/api/apiFunction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,2BAA2B,EAC3B,OAAO,EACR,MAAM,YAAY,CAAA;AAEnB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAGnE,UAAU,gBAAiB,SAAQ,OAAO,CAAC,oBAAoB,CAAC;IAC9D,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,OAAO,CAAC,EAAE,2BAA2B,CAAA;CACtC;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,GAAI,uHAU3B,gBAAgB,KAAG,oBAgCrB,CAAA;AAED;;;IAGI;AACJ,eAAO,MAAM,WAAW,QAAO,OAI9B,CAAA;AAED,UAAU,yBAA0B,SAAQ,IAAI,CAC9C,gBAAgB,EAChB,WAAW,GAAG,iBAAiB,CAChC;IACC,aAAa,EAAE,OAAO,CAAC,sBAAsB,EAAE,cAAc,CAAC,CAAA;IAC9D,eAAe,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;IAGI;AACJ,eAAO,MAAM,iBAAiB,GAAI,gEAM/B,yBAAyB,yBAe3B,CAAA"}
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var apiFunction_exports = {};
20
+ __export(apiFunction_exports, {
21
+ mockContext: () => mockContext,
22
+ mockHttpEvent: () => mockHttpEvent,
23
+ mockSignedWebhook: () => mockSignedWebhook
24
+ });
25
+ module.exports = __toCommonJS(apiFunction_exports);
26
+ var import_webhooks = require("@cedarjs/api/webhooks");
27
+ const mockHttpEvent = ({
28
+ payload = null,
29
+ signature,
30
+ signatureHeader,
31
+ queryStringParameters = null,
32
+ httpMethod = "GET",
33
+ headers = {},
34
+ path = "",
35
+ isBase64Encoded = false,
36
+ ...others
37
+ }) => {
38
+ if (signature && signatureHeader) {
39
+ headers[signatureHeader.toLocaleLowerCase()] = signature;
40
+ }
41
+ const payloadAsString = typeof payload === "string" ? payload : JSON.stringify(payload);
42
+ const body = payload === null ? null : isBase64Encoded ? Buffer.from(payloadAsString || "").toString("base64") : payloadAsString;
43
+ return {
44
+ body,
45
+ headers,
46
+ multiValueHeaders: {},
47
+ isBase64Encoded,
48
+ path,
49
+ pathParameters: null,
50
+ stageVariables: null,
51
+ httpMethod,
52
+ queryStringParameters,
53
+ // @ts-expect-error not required for mocks
54
+ requestContext: null,
55
+ // @ts-expect-error not required for mocks
56
+ resource: null,
57
+ multiValueQueryStringParameters: null,
58
+ ...others
59
+ };
60
+ };
61
+ const mockContext = () => {
62
+ const context = {};
63
+ return context;
64
+ };
65
+ const mockSignedWebhook = ({
66
+ payload = null,
67
+ signatureType,
68
+ signatureHeader,
69
+ secret,
70
+ ...others
71
+ }) => {
72
+ const payloadAsString = typeof payload === "string" ? payload : JSON.stringify(payload);
73
+ const signature = (0, import_webhooks.signPayload)(signatureType, {
74
+ payload: payloadAsString,
75
+ secret
76
+ });
77
+ return mockHttpEvent({
78
+ payload,
79
+ signature,
80
+ signatureHeader,
81
+ ...others
82
+ });
83
+ };
84
+ // Annotate the CommonJS export names for ESM import in node:
85
+ 0 && (module.exports = {
86
+ mockContext,
87
+ mockHttpEvent,
88
+ mockSignedWebhook
89
+ });
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Redacts credentials from a database connection string so it's safe to
3
+ * print. Handles both URI-style authority credentials, e.g.
4
+ * `postgres://user:pass@host/db` -> `postgres://user:***@host/db`, and
5
+ * semicolon-delimited key/value credentials used by SQL Server connection
6
+ * strings, e.g. `Server=host;Password=secret;` -> `Server=host;Password=***;`.
7
+ */
8
+ export declare function redactDatabaseUrl(url: string): string;
9
+ /**
10
+ * Checks that the `DATABASE_URL` about to be used for tests matches the
11
+ * datasource provider configured in `schema.prisma`, and throws an
12
+ * actionable error if they don't match.
13
+ *
14
+ * Without this check, running `prisma db push`/`migrate reset` against a
15
+ * mismatched provider/URL combination (e.g. a leftover sqlite fallback URL
16
+ * with a `postgresql` schema) can hang indefinitely with no output, instead
17
+ * of failing fast. See https://github.com/cedarjs/cedar/issues/2284.
18
+ *
19
+ * If the provider can't be determined (e.g. `schema.prisma` doesn't exist
20
+ * yet), this is a no-op — Prisma itself will surface the problem.
21
+ */
22
+ export declare function checkTestDatabaseUrlMatchesProvider(databaseUrl: string, usedFallback: boolean): Promise<void>;
23
+ /**
24
+ * Guards `cedar test api`'s destructive database reset by *identity*, not
25
+ * just provider: refuses to run when the resolved test database is the same
26
+ * database as `DATABASE_URL` — same host, port, and database name, or the
27
+ * same sqlite file.
28
+ *
29
+ * This is deliberately the only check, rather than also requiring the
30
+ * database's *name* to look test-like (e.g. containing "test" or "e2e"). A
31
+ * naming convention doesn't hold for managed Postgres providers with a
32
+ * fixed default database name shared by every project — every Supabase
33
+ * project's database is named `postgres`, for instance — so it can't tell a
34
+ * real project's database apart from a dedicated test one by name alone.
35
+ * Whether the two connection strings resolve to the same database is the
36
+ * one fact that holds across every provider.
37
+ *
38
+ * When there's no `DATABASE_URL` at all to compare against, this fails
39
+ * closed rather than skipping the check: an explicit `TEST_DATABASE_URL`
40
+ * with nothing to confirm it's not the app's real database is refused,
41
+ * since there'd be no way to tell it apart from one that is. Cedar's own
42
+ * generated sqlite fallback (`usedFallback`) is exempt from that fail-closed
43
+ * refusal — it's a path only Cedar controls, so there's no need to force a
44
+ * `DATABASE_URL` to exist just to permit it — but it still runs through the
45
+ * same-database comparison below whenever a `DATABASE_URL` is present, so a
46
+ * project whose real database happens to live at that same generated path
47
+ * is still caught.
48
+ */
49
+ export declare function checkTestDatabaseIdentity(testDatabaseUrl: string, mainDatabaseUrl: string | undefined, usedFallback: boolean): void;
50
+ //# sourceMappingURL=checkTestDatabase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkTestDatabase.d.ts","sourceRoot":"","sources":["../../../src/api/checkTestDatabase.ts"],"names":[],"mappings":"AAoBA;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIrD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,mCAAmC,CACvD,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,OAAO,iBAmCtB;AAuHD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,yBAAyB,CACvC,eAAe,EAAE,MAAM,EACvB,eAAe,EAAE,MAAM,GAAG,SAAS,EACnC,YAAY,EAAE,OAAO,QAkCtB"}
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var checkTestDatabase_exports = {};
30
+ __export(checkTestDatabase_exports, {
31
+ checkTestDatabaseIdentity: () => checkTestDatabaseIdentity,
32
+ checkTestDatabaseUrlMatchesProvider: () => checkTestDatabaseUrlMatchesProvider,
33
+ redactDatabaseUrl: () => redactDatabaseUrl
34
+ });
35
+ module.exports = __toCommonJS(checkTestDatabase_exports);
36
+ var import_node_path = __toESM(require("node:path"), 1);
37
+ var import_project_config = require("@cedarjs/project-config");
38
+ const PROVIDER_URL_SCHEMES = {
39
+ sqlite: ["file:"],
40
+ postgresql: ["postgres:", "postgresql:"],
41
+ postgres: ["postgres:", "postgresql:"],
42
+ cockroachdb: ["postgres:", "postgresql:"],
43
+ mysql: ["mysql:"],
44
+ sqlserver: ["sqlserver:"],
45
+ mongodb: ["mongodb:", "mongodb+srv:"]
46
+ };
47
+ function getUrlScheme(url) {
48
+ const match = url.match(/^([a-z][a-z0-9+.-]*:)/i);
49
+ return match?.[1]?.toLowerCase();
50
+ }
51
+ function redactDatabaseUrl(url) {
52
+ return url.replace(/:\/\/([^:/?#]+):([^@/?#]+)@/, "://$1:***@").replace(/((?:^|;)\s*password\s*=)[^;]*/gi, "$1***");
53
+ }
54
+ async function checkTestDatabaseUrlMatchesProvider(databaseUrl, usedFallback) {
55
+ let provider;
56
+ try {
57
+ provider = await (0, import_project_config.getPrismaDatasourceProvider)();
58
+ } catch {
59
+ return;
60
+ }
61
+ const expectedSchemes = PROVIDER_URL_SCHEMES[provider];
62
+ if (!expectedSchemes) {
63
+ return;
64
+ }
65
+ const actualScheme = getUrlScheme(databaseUrl);
66
+ if (actualScheme && expectedSchemes.includes(actualScheme)) {
67
+ return;
68
+ }
69
+ const redactedUrl = redactDatabaseUrl(databaseUrl);
70
+ const reason = usedFallback ? `TEST_DATABASE_URL is not set, so the default sqlite test database was used (${redactedUrl}), but your schema.prisma is configured for "${provider}". Set TEST_DATABASE_URL to a "${provider}" connection string to run tests.` : `TEST_DATABASE_URL (${redactedUrl}) does not match the "${provider}" provider configured in schema.prisma. Update TEST_DATABASE_URL to a "${provider}" connection string.`;
71
+ throw new Error(
72
+ `Test database URL does not match your Prisma schema's provider.
73
+
74
+ ${reason}`
75
+ );
76
+ }
77
+ const DEFAULT_PORTS = {
78
+ "postgresql:": "5432",
79
+ "mysql:": "3306",
80
+ "sqlserver:": "1433",
81
+ "mongodb:": "27017"
82
+ };
83
+ function normalizeScheme(scheme) {
84
+ return scheme === "postgres:" ? "postgresql:" : scheme;
85
+ }
86
+ function normalizeHost(host) {
87
+ return host.toLowerCase().replace(/\.$/, "");
88
+ }
89
+ function parseSqlServerIdentity(url) {
90
+ const [authority, ...params] = url.split(";");
91
+ const match = authority.match(
92
+ /^([a-z][a-z0-9+.-]*:)\/\/([^:/?#]+)(?::(\d+))?/i
93
+ );
94
+ if (!match) {
95
+ return void 0;
96
+ }
97
+ const [, scheme, host, port] = match;
98
+ const databaseParam = params.find(
99
+ (param) => /^\s*(?:database|initial\s+catalog)\s*=/i.test(param)
100
+ );
101
+ const database = databaseParam?.slice(databaseParam.indexOf("=") + 1).trim();
102
+ return {
103
+ scheme: scheme.toLowerCase(),
104
+ host: normalizeHost(host),
105
+ port,
106
+ database
107
+ };
108
+ }
109
+ function parseUriIdentity(url) {
110
+ try {
111
+ const parsed = new URL(url);
112
+ const database = decodeURIComponent(parsed.pathname.replace(/^\//, "")).split("/")[0] || void 0;
113
+ return {
114
+ scheme: parsed.protocol.toLowerCase(),
115
+ host: parsed.hostname ? normalizeHost(parsed.hostname) : void 0,
116
+ port: parsed.port || void 0,
117
+ database
118
+ };
119
+ } catch {
120
+ return void 0;
121
+ }
122
+ }
123
+ function parseDatabaseIdentity(url) {
124
+ const scheme = getUrlScheme(url);
125
+ if (!scheme) {
126
+ return void 0;
127
+ }
128
+ if (scheme === "file:") {
129
+ return { scheme, database: import_node_path.default.resolve(url.slice("file:".length)) };
130
+ }
131
+ if (scheme === "sqlserver:") {
132
+ return parseSqlServerIdentity(url);
133
+ }
134
+ return parseUriIdentity(url);
135
+ }
136
+ function identitiesMatch(a, b) {
137
+ const schemeA = normalizeScheme(a.scheme);
138
+ const schemeB = normalizeScheme(b.scheme);
139
+ if (schemeA !== schemeB) {
140
+ return false;
141
+ }
142
+ if (schemeA === "file:") {
143
+ return !!a.database && a.database === b.database;
144
+ }
145
+ if (!a.database || !b.database || a.database !== b.database) {
146
+ return false;
147
+ }
148
+ const portA = a.port || DEFAULT_PORTS[schemeA] || "";
149
+ const portB = b.port || DEFAULT_PORTS[schemeA] || "";
150
+ return (a.host ?? "") === (b.host ?? "") && portA === portB;
151
+ }
152
+ function checkTestDatabaseIdentity(testDatabaseUrl, mainDatabaseUrl, usedFallback) {
153
+ if (!mainDatabaseUrl) {
154
+ if (usedFallback) {
155
+ return;
156
+ }
157
+ const redactedTestUrl = redactDatabaseUrl(testDatabaseUrl);
158
+ throw new Error(
159
+ `TEST_DATABASE_URL (${redactedTestUrl}) is set, but there's no DATABASE_URL to confirm it isn't the same database your app actually uses. Refusing to run a destructive reset without that confirmation.
160
+
161
+ Set DATABASE_URL (even to a placeholder) so Cedar can verify TEST_DATABASE_URL points somewhere different.`
162
+ );
163
+ }
164
+ const sameRawUrl = mainDatabaseUrl === testDatabaseUrl;
165
+ const testIdentity = parseDatabaseIdentity(testDatabaseUrl);
166
+ const mainIdentity = parseDatabaseIdentity(mainDatabaseUrl);
167
+ const sameParsedIdentity = !!testIdentity && !!mainIdentity && identitiesMatch(testIdentity, mainIdentity);
168
+ if (sameRawUrl || sameParsedIdentity) {
169
+ const redactedTestUrl = redactDatabaseUrl(testDatabaseUrl);
170
+ throw new Error(
171
+ `TEST_DATABASE_URL (${redactedTestUrl}) points at the same database as DATABASE_URL. Refusing to run a destructive reset against your app's main database.
172
+
173
+ Set TEST_DATABASE_URL to a dedicated test database.`
174
+ );
175
+ }
176
+ }
177
+ // Annotate the CommonJS export names for ESM import in node:
178
+ 0 && (module.exports = {
179
+ checkTestDatabaseIdentity,
180
+ checkTestDatabaseUrlMatchesProvider,
181
+ redactDatabaseUrl
182
+ });
@@ -0,0 +1,51 @@
1
+ import type { A } from 'ts-toolbelt';
2
+ import type { DirectiveParams, ValidatorDirective, TransformerDirective } from '@cedarjs/graphql-server';
3
+ export { getDirectiveName } from '@cedarjs/graphql-server';
4
+ interface DirectiveMocker {
5
+ (directive: ValidatorDirective, executionMock: A.Compute<Omit<Partial<DirectiveParams>, 'resolvedValue'>>): any;
6
+ }
7
+ type TransformerMock = A.Compute<Omit<Partial<DirectiveParams>, 'resolvedValue'>> & {
8
+ mockedResolvedValue: any;
9
+ };
10
+ interface DirectiveMocker {
11
+ (directive: TransformerDirective, executionMock: TransformerMock): any;
12
+ }
13
+ /**
14
+ * @description
15
+ *
16
+ * Used for writing both synchronous and asynchronous directive tests e.g.
17
+ *
18
+ * - Transformer directives can be passed mockedResolvedValue
19
+ * - Validator directives should check for errors thrown in certain situations
20
+ * - Can provide args, directiveArgs and context to mock directive execution
21
+ *
22
+ * @example
23
+ *
24
+ * Synchronous transformer directive:
25
+ *
26
+ * ```ts
27
+ * const mockExecution = mockRedwoodDirective(myTransformer, {
28
+ * context: currentUser,
29
+ * mockedResolvedValue: 'Original Value',
30
+ * })
31
+ *
32
+ * expect(mockExecution).not.toThrow()
33
+ * expect(mockExecution()).toEqual('Transformed Value')
34
+ * ```ts
35
+ *
36
+ * @example
37
+ *
38
+ * Asynchronous transformer directive:
39
+ *
40
+ * ```ts
41
+ * const mockExecution = mockRedwoodDirective(myTransformer, {
42
+ * context: currentUser,
43
+ * mockedResolvedValue: 'Original Value',
44
+ * })
45
+ *
46
+ * await expect(mockExecution).resolves.not.toThrow()
47
+ * await expect(mockExecution()).resolves.toEqual('Transformed Value')
48
+ * ```
49
+ */
50
+ export declare const mockRedwoodDirective: DirectiveMocker;
51
+ //# sourceMappingURL=directive.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directive.d.ts","sourceRoot":"","sources":["../../../src/api/directive.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,aAAa,CAAA;AAGpC,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACrB,MAAM,yBAAyB,CAAA;AAGhC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAG1D,UAAU,eAAe;IACvB,CACE,SAAS,EAAE,kBAAkB,EAC7B,aAAa,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,eAAe,CAAC,CAAC,GACxE,GAAG,CAAA;CACP;AAED,KAAK,eAAe,GAAG,CAAC,CAAC,OAAO,CAC9B,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,eAAe,CAAC,CAChD,GAAG;IACF,mBAAmB,EAAE,GAAG,CAAA;CACzB,CAAA;AAGD,UAAU,eAAe;IACvB,CAAC,SAAS,EAAE,oBAAoB,EAAE,aAAa,EAAE,eAAe,GAAG,GAAG,CAAA;CACvE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,oBAAoB,EAAE,eAmDlC,CAAA"}
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var directive_exports = {};
20
+ __export(directive_exports, {
21
+ getDirectiveName: () => import_graphql_server2.getDirectiveName,
22
+ mockRedwoodDirective: () => mockRedwoodDirective
23
+ });
24
+ module.exports = __toCommonJS(directive_exports);
25
+ var import_context = require("@cedarjs/context");
26
+ var import_graphql_server = require("@cedarjs/graphql-server");
27
+ var import_graphql_server2 = require("@cedarjs/graphql-server");
28
+ const mockRedwoodDirective = (directive, executionMock) => {
29
+ const { directiveArgs, context, ...others } = executionMock;
30
+ if (directive.onResolvedValue.constructor.name === "AsyncFunction") {
31
+ return async () => {
32
+ if (context !== void 0) {
33
+ (0, import_context.setContext)(context);
34
+ }
35
+ if (directive.type === import_graphql_server.DirectiveType.TRANSFORMER) {
36
+ const { mockedResolvedValue } = others;
37
+ return directive.onResolvedValue({
38
+ resolvedValue: mockedResolvedValue,
39
+ directiveArgs: directiveArgs ?? {},
40
+ context: import_context.context,
41
+ ...others
42
+ });
43
+ } else {
44
+ await directive.onResolvedValue({
45
+ directiveArgs: directiveArgs ?? {},
46
+ context: import_context.context,
47
+ ...others
48
+ });
49
+ }
50
+ };
51
+ }
52
+ return () => {
53
+ if (context !== void 0) {
54
+ (0, import_context.setContext)(context);
55
+ }
56
+ if (directive.type === import_graphql_server.DirectiveType.TRANSFORMER) {
57
+ const { mockedResolvedValue } = others;
58
+ return directive.onResolvedValue({
59
+ resolvedValue: mockedResolvedValue,
60
+ directiveArgs: directiveArgs ?? {},
61
+ context: import_context.context,
62
+ ...others
63
+ });
64
+ } else {
65
+ directive.onResolvedValue({
66
+ directiveArgs: directiveArgs ?? {},
67
+ context: import_context.context,
68
+ ...others
69
+ });
70
+ }
71
+ };
72
+ };
73
+ // Annotate the CommonJS export names for ESM import in node:
74
+ 0 && (module.exports = {
75
+ getDirectiveName,
76
+ mockRedwoodDirective
77
+ });
@@ -0,0 +1,4 @@
1
+ export * from './apiFunction.js';
2
+ export * from './scenario.js';
3
+ export * from './directive.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var api_exports = {};
17
+ module.exports = __toCommonJS(api_exports);
18
+ __reExport(api_exports, require("./apiFunction.js"), module.exports);
19
+ __reExport(api_exports, require("./scenario.js"), module.exports);
20
+ __reExport(api_exports, require("./directive.js"), module.exports);
21
+ // Annotate the CommonJS export names for ESM import in node:
22
+ 0 && (module.exports = {
23
+ ...require("./apiFunction.js"),
24
+ ...require("./scenario.js"),
25
+ ...require("./directive.js")
26
+ });
@@ -0,0 +1,5 @@
1
+ export interface GlobalContext extends Record<string, unknown> {
2
+ }
3
+ export declare const context: {};
4
+ export declare const setContext: (newContext: GlobalContext) => GlobalContext;
5
+ //# sourceMappingURL=mockContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mockContext.d.ts","sourceRoot":"","sources":["../../../src/api/mockContext.ts"],"names":[],"mappings":"AAoCA,MAAM,WAAW,aAAc,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAAG;AAEjE,eAAO,MAAM,OAAO,IAAc,CAAA;AAElC,eAAO,MAAM,UAAU,GAAI,YAAY,aAAa,KAAG,aAKtD,CAAA"}