temba 0.18.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. package/README.md +14 -2
  2. package/package.json +6 -8
  3. package/{config → src/config}/index.d.ts +7 -5
  4. package/src/config/index.d.ts.map +1 -0
  5. package/{config → src/config}/index.js +11 -39
  6. package/src/config/index.js.map +1 -0
  7. package/src/delay/delayMiddleware.d.ts +3 -0
  8. package/src/delay/delayMiddleware.d.ts.map +1 -0
  9. package/src/delay/delayMiddleware.js +13 -0
  10. package/src/delay/delayMiddleware.js.map +1 -0
  11. package/src/index.d.ts +6 -0
  12. package/src/index.d.ts.map +1 -0
  13. package/src/index.js +83 -0
  14. package/src/index.js.map +1 -0
  15. package/src/queries/in-memory.d.ts +3 -0
  16. package/src/queries/in-memory.d.ts.map +1 -0
  17. package/src/queries/in-memory.js +61 -0
  18. package/src/queries/in-memory.js.map +1 -0
  19. package/src/queries/mongo.d.ts +3 -0
  20. package/src/queries/mongo.d.ts.map +1 -0
  21. package/src/queries/mongo.js +75 -0
  22. package/src/queries/mongo.js.map +1 -0
  23. package/src/queries/queries.d.ts +2 -0
  24. package/src/queries/queries.d.ts.map +1 -0
  25. package/src/queries/queries.js +10 -0
  26. package/src/queries/queries.js.map +1 -0
  27. package/src/queries/types.d.ts +15 -0
  28. package/src/queries/types.d.ts.map +1 -0
  29. package/src/queries/types.js +2 -0
  30. package/{routes → src/queries}/types.js.map +1 -1
  31. package/src/requestBodyInterceptor/interceptRequestBody.d.ts +3 -0
  32. package/src/requestBodyInterceptor/interceptRequestBody.d.ts.map +1 -0
  33. package/src/requestBodyInterceptor/interceptRequestBody.js +14 -0
  34. package/src/requestBodyInterceptor/interceptRequestBody.js.map +1 -0
  35. package/src/requestBodyInterceptor/types.d.ts +12 -0
  36. package/src/requestBodyInterceptor/types.d.ts.map +1 -0
  37. package/src/requestBodyInterceptor/types.js +2 -0
  38. package/src/requestBodyInterceptor/types.js.map +1 -0
  39. package/src/requestHandlers/delete.d.ts +12 -0
  40. package/src/requestHandlers/delete.d.ts.map +1 -0
  41. package/src/requestHandlers/delete.js +22 -0
  42. package/src/requestHandlers/delete.js.map +1 -0
  43. package/src/requestHandlers/get.d.ts +22 -0
  44. package/src/requestHandlers/get.d.ts.map +1 -0
  45. package/src/requestHandlers/get.js +47 -0
  46. package/src/requestHandlers/get.js.map +1 -0
  47. package/src/requestHandlers/index.d.ts +54 -0
  48. package/src/requestHandlers/index.d.ts.map +1 -0
  49. package/src/requestHandlers/index.js +21 -0
  50. package/src/requestHandlers/index.js.map +1 -0
  51. package/src/requestHandlers/patch.d.ts +9 -0
  52. package/src/requestHandlers/patch.d.ts.map +1 -0
  53. package/src/requestHandlers/patch.js +35 -0
  54. package/src/requestHandlers/patch.js.map +1 -0
  55. package/src/requestHandlers/post.d.ts +18 -0
  56. package/src/requestHandlers/post.d.ts.map +1 -0
  57. package/src/requestHandlers/post.js +37 -0
  58. package/src/requestHandlers/post.js.map +1 -0
  59. package/src/requestHandlers/put.d.ts +9 -0
  60. package/src/requestHandlers/put.d.ts.map +1 -0
  61. package/src/requestHandlers/put.js +35 -0
  62. package/src/requestHandlers/put.js.map +1 -0
  63. package/src/requestHandlers/types.d.ts +38 -0
  64. package/src/requestHandlers/types.d.ts.map +1 -0
  65. package/src/requestHandlers/types.js +2 -0
  66. package/{schema → src/requestHandlers}/types.js.map +1 -1
  67. package/{routes → src/requestHandlers}/utils.d.ts +1 -0
  68. package/src/requestHandlers/utils.d.ts.map +1 -0
  69. package/src/requestHandlers/utils.js +6 -0
  70. package/src/requestHandlers/utils.js.map +1 -0
  71. package/src/resourceRouter.d.ts +5 -0
  72. package/src/resourceRouter.d.ts.map +1 -0
  73. package/src/resourceRouter.js +95 -0
  74. package/src/resourceRouter.js.map +1 -0
  75. package/src/responseBodyInterceptor/interceptResponseBody.d.ts +3 -0
  76. package/src/responseBodyInterceptor/interceptResponseBody.d.ts.map +1 -0
  77. package/src/responseBodyInterceptor/interceptResponseBody.js +7 -0
  78. package/src/responseBodyInterceptor/interceptResponseBody.js.map +1 -0
  79. package/src/responseBodyInterceptor/types.d.ts +11 -0
  80. package/src/responseBodyInterceptor/types.d.ts.map +1 -0
  81. package/src/responseBodyInterceptor/types.js +2 -0
  82. package/src/responseBodyInterceptor/types.js.map +1 -0
  83. package/src/schema/compile.d.ts +3 -0
  84. package/src/schema/compile.d.ts.map +1 -0
  85. package/src/schema/compile.js +26 -0
  86. package/src/schema/compile.js.map +1 -0
  87. package/{schema → src/schema}/types.d.ts +4 -14
  88. package/src/schema/types.d.ts.map +1 -0
  89. package/src/schema/types.js +2 -0
  90. package/{queries → src/schema}/types.js.map +1 -1
  91. package/{schema → src/schema}/validate.d.ts +1 -0
  92. package/src/schema/validate.d.ts.map +1 -0
  93. package/src/schema/validate.js +14 -0
  94. package/src/schema/validate.js.map +1 -0
  95. package/src/urls/urlParser.d.ts +5 -0
  96. package/src/urls/urlParser.d.ts.map +1 -0
  97. package/src/urls/urlParser.js +9 -0
  98. package/src/urls/urlParser.js.map +1 -0
  99. package/test/integration/api-prefix.test.d.ts +2 -0
  100. package/test/integration/api-prefix.test.d.ts.map +1 -0
  101. package/test/integration/api-prefix.test.js +69 -0
  102. package/test/integration/api-prefix.test.js.map +1 -0
  103. package/test/integration/createServer.d.ts +4 -0
  104. package/test/integration/createServer.d.ts.map +1 -0
  105. package/test/integration/createServer.js +4 -0
  106. package/test/integration/createServer.js.map +1 -0
  107. package/test/integration/crud.test.d.ts +2 -0
  108. package/test/integration/crud.test.d.ts.map +1 -0
  109. package/test/integration/crud.test.js +173 -0
  110. package/test/integration/crud.test.js.map +1 -0
  111. package/test/integration/custom-router.test.d.ts +2 -0
  112. package/test/integration/custom-router.test.d.ts.map +1 -0
  113. package/test/integration/custom-router.test.js +74 -0
  114. package/test/integration/custom-router.test.js.map +1 -0
  115. package/test/integration/head-method.test.d.ts +2 -0
  116. package/test/integration/head-method.test.d.ts.map +1 -0
  117. package/test/integration/head-method.test.js +38 -0
  118. package/test/integration/head-method.test.js.map +1 -0
  119. package/test/integration/options-method.test.d.ts +2 -0
  120. package/test/integration/options-method.test.d.ts.map +1 -0
  121. package/test/integration/options-method.test.js +30 -0
  122. package/test/integration/options-method.test.js.map +1 -0
  123. package/test/integration/requestBodyInterceptor/requestBodyInterceptor-change-requestBody.test.d.ts +2 -0
  124. package/test/integration/requestBodyInterceptor/requestBodyInterceptor-change-requestBody.test.d.ts.map +1 -0
  125. package/test/integration/requestBodyInterceptor/requestBodyInterceptor-change-requestBody.test.js +76 -0
  126. package/test/integration/requestBodyInterceptor/requestBodyInterceptor-change-requestBody.test.js.map +1 -0
  127. package/test/integration/requestBodyInterceptor/requestBodyInterceptor-error-string.test.d.ts +2 -0
  128. package/test/integration/requestBodyInterceptor/requestBodyInterceptor-error-string.test.d.ts.map +1 -0
  129. package/test/integration/requestBodyInterceptor/requestBodyInterceptor-error-string.test.js +60 -0
  130. package/test/integration/requestBodyInterceptor/requestBodyInterceptor-error-string.test.js.map +1 -0
  131. package/test/integration/requestBodyInterceptor/requestBodyInterceptor-invalid-return-types.test.d.ts +2 -0
  132. package/test/integration/requestBodyInterceptor/requestBodyInterceptor-invalid-return-types.test.d.ts.map +1 -0
  133. package/test/integration/requestBodyInterceptor/requestBodyInterceptor-invalid-return-types.test.js +89 -0
  134. package/test/integration/requestBodyInterceptor/requestBodyInterceptor-invalid-return-types.test.js.map +1 -0
  135. package/test/integration/requestBodyInterceptor/requestBodyInterceptor-void.test.d.ts +2 -0
  136. package/test/integration/requestBodyInterceptor/requestBodyInterceptor-void.test.d.ts.map +1 -0
  137. package/test/integration/requestBodyInterceptor/requestBodyInterceptor-void.test.js +47 -0
  138. package/test/integration/requestBodyInterceptor/requestBodyInterceptor-void.test.js.map +1 -0
  139. package/test/integration/responseBodyInterceptor.test.d.ts +2 -0
  140. package/test/integration/responseBodyInterceptor.test.d.ts.map +1 -0
  141. package/test/integration/responseBodyInterceptor.test.js +107 -0
  142. package/test/integration/responseBodyInterceptor.test.js.map +1 -0
  143. package/test/integration/returnNullFields.test.d.ts +2 -0
  144. package/test/integration/returnNullFields.test.d.ts.map +1 -0
  145. package/test/integration/returnNullFields.test.js +51 -0
  146. package/test/integration/returnNullFields.test.js.map +1 -0
  147. package/test/integration/root-url.test.d.ts +2 -0
  148. package/test/integration/root-url.test.d.ts.map +1 -0
  149. package/test/integration/root-url.test.js +29 -0
  150. package/test/integration/root-url.test.js.map +1 -0
  151. package/test/integration/schema-validation.test.d.ts +2 -0
  152. package/test/integration/schema-validation.test.d.ts.map +1 -0
  153. package/test/integration/schema-validation.test.js +169 -0
  154. package/test/integration/schema-validation.test.js.map +1 -0
  155. package/test/unit/config/config.test.d.ts +2 -0
  156. package/test/unit/config/config.test.d.ts.map +1 -0
  157. package/test/unit/config/config.test.js +121 -0
  158. package/test/unit/config/config.test.js.map +1 -0
  159. package/test/unit/urls/urlParser.test.d.ts +2 -0
  160. package/test/unit/urls/urlParser.test.d.ts.map +1 -0
  161. package/test/unit/urls/urlParser.test.js +43 -0
  162. package/test/unit/urls/urlParser.test.js.map +1 -0
  163. package/tsconfig.tsbuildinfo +1 -0
  164. package/vitest.config.d.ts +3 -0
  165. package/vitest.config.d.ts.map +1 -0
  166. package/vitest.config.js +10 -0
  167. package/vitest.config.js.map +1 -0
  168. package/config/index.js.map +0 -1
  169. package/delay/delayMiddleware.d.ts +0 -2
  170. package/delay/delayMiddleware.js +0 -16
  171. package/delay/delayMiddleware.js.map +0 -1
  172. package/index.d.ts +0 -5
  173. package/index.js +0 -98
  174. package/index.js.map +0 -1
  175. package/queries/in-memory.d.ts +0 -20
  176. package/queries/in-memory.js +0 -88
  177. package/queries/in-memory.js.map +0 -1
  178. package/queries/mongo.d.ts +0 -19
  179. package/queries/mongo.js +0 -218
  180. package/queries/mongo.js.map +0 -1
  181. package/queries/queries.d.ts +0 -11
  182. package/queries/queries.js +0 -17
  183. package/queries/queries.js.map +0 -1
  184. package/queries/types.d.ts +0 -14
  185. package/queries/types.js +0 -3
  186. package/routes/delete.d.ts +0 -7
  187. package/routes/delete.js +0 -77
  188. package/routes/delete.js.map +0 -1
  189. package/routes/get.d.ts +0 -7
  190. package/routes/get.js +0 -115
  191. package/routes/get.js.map +0 -1
  192. package/routes/interceptRequestBody.d.ts +0 -3
  193. package/routes/interceptRequestBody.js +0 -19
  194. package/routes/interceptRequestBody.js.map +0 -1
  195. package/routes/patch.d.ts +0 -8
  196. package/routes/patch.js +0 -102
  197. package/routes/patch.js.map +0 -1
  198. package/routes/post.d.ts +0 -8
  199. package/routes/post.js +0 -87
  200. package/routes/post.js.map +0 -1
  201. package/routes/put.d.ts +0 -8
  202. package/routes/put.js +0 -102
  203. package/routes/put.js.map +0 -1
  204. package/routes/routes.d.ts +0 -8
  205. package/routes/routes.js +0 -90
  206. package/routes/routes.js.map +0 -1
  207. package/routes/types.d.ts +0 -23
  208. package/routes/types.js +0 -3
  209. package/routes/utils.js +0 -13
  210. package/routes/utils.js.map +0 -1
  211. package/schema/compile.d.ts +0 -2
  212. package/schema/compile.js +0 -41
  213. package/schema/compile.js.map +0 -1
  214. package/schema/transformConfig.d.ts +0 -2
  215. package/schema/transformConfig.js +0 -17
  216. package/schema/transformConfig.js.map +0 -1
  217. package/schema/types.js +0 -3
  218. package/schema/validate.js +0 -19
  219. package/schema/validate.js.map +0 -1
  220. package/urls/urlMiddleware.d.ts +0 -5
  221. package/urls/urlMiddleware.js +0 -41
  222. package/urls/urlMiddleware.js.map +0 -1
  223. package/urls/urlParser.d.ts +0 -5
  224. package/urls/urlParser.js +0 -13
  225. package/urls/urlParser.js.map +0 -1
package/README.md CHANGED
@@ -277,7 +277,7 @@ Example:
277
277
  const config = {
278
278
  requestBodyInterceptor: {
279
279
  post: ({ resource, body }) => {
280
- // Do not allow Pokemons to be created: 400 Bad Req best
280
+ // Do not allow Pokemons to be created: 400 Bad Request
281
281
  if (resource === 'pokemons') return 'You are not allowed to create new Pokemons'
282
282
 
283
283
  // Add a genre to Star Trek films:
@@ -424,6 +424,17 @@ const config = {
424
424
  // Change the response body before it is sent to the client
425
425
  },
426
426
  returnNullFields: false,
427
+ schema: {
428
+ movies: {
429
+ post: {
430
+ type: 'object',
431
+ properties: {
432
+ title: { type: 'string' },
433
+ },
434
+ required: ['title'],
435
+ },
436
+ },
437
+ },
427
438
  staticFolder: 'build',
428
439
  }
429
440
  const server = temba.create(config)
@@ -443,6 +454,7 @@ These are all the possible settings:
443
454
  | `resources` | See [Allowing specific resources only](#allowing-specific-resources-only) | `[]` |
444
455
  | `responseBodyInterceptor` | See [Response body interception](#request-body-validation-or-mutation) | `noop` |
445
456
  | `returnNullFields` | Whether fields with a `null` value should be returned in responses. | `true` |
457
+ | `schema` | See [JSON Schema request body validation](#json-schema-request-body-validation) | `null` |
446
458
  | `staticFolder` | See [Static assets](#static-assets) | `null` |
447
459
 
448
460
  ## Roadmap
@@ -461,7 +473,7 @@ Although I won't promise if and when, these are some things to consider for the
461
473
 
462
474
  ## Under the hood
463
475
 
464
- Temba is built with JavaScript, [Node](https://nodejs.org), [Express](https://expressjs.com/), [Jest](https://jestjs.io/), [Supertest](https://www.npmjs.com/package/supertest), and [@rakered/mongo](https://www.npmjs.com/package/@rakered/mongo).
476
+ Temba is built with JavaScript, [Node](https://nodejs.org), [Express](https://expressjs.com/), [Vitest](https://vitest.dev/), [Supertest](https://www.npmjs.com/package/supertest), and [@rakered/mongo](https://www.npmjs.com/package/@rakered/mongo).
465
477
 
466
478
  ## Contributors ✨
467
479
 
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "temba",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "description": "Get a simple MongoDB REST API with zero coding in less than 30 seconds (seriously).",
5
+ "type": "module",
5
6
  "main": "dist/index.js",
6
7
  "scripts": {
7
8
  "build": "rm -rf dist && tsc && cp package.json README.md ./dist",
8
- "test": "jest --silent --no-cache",
9
- "test:watch": "jest --watch --no-cache",
9
+ "test": "vitest",
10
+ "test:watch": "vitest --watch",
10
11
  "lint": "eslint --ignore-path .gitignore --ext .js,.ts .",
11
12
  "format": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json)\""
12
13
  },
@@ -20,20 +21,17 @@
20
21
  "devDependencies": {
21
22
  "@types/cors": "^2.8.15",
22
23
  "@types/express": "^4.17.20",
23
- "@types/jest": "^29.5.7",
24
24
  "@types/morgan": "^1.9.8",
25
25
  "@types/supertest": "^2.0.15",
26
26
  "@typescript-eslint/eslint-plugin": "^6.10.0",
27
27
  "@typescript-eslint/parser": "^6.10.0",
28
28
  "eslint": "^8.53.0",
29
29
  "eslint-config-prettier": "^9.0.0",
30
- "jest": "^29.7.0",
31
- "jest-extended": "^4.0.2",
32
30
  "prettier": "^3.0.3",
33
31
  "supertest": "^6.3.3",
34
- "ts-jest": "^29.1.1",
35
32
  "ts-node": "^10.9.1",
36
- "typescript": "^5.2.2"
33
+ "typescript": "^5.2.2",
34
+ "vitest": "^1.3.1"
37
35
  },
38
36
  "dependencies": {
39
37
  "@rakered/mongo": "^1.6.0",
@@ -1,13 +1,14 @@
1
1
  import { Router } from 'express';
2
- import { RequestBodyInterceptor, ResponseBodyInterceptor } from '../routes/types';
3
- import { ConfiguredSchemas } from '../schema/types';
2
+ import type { ConfiguredSchemas } from '../schema/types';
3
+ import { RequestBodyInterceptor } from '../requestBodyInterceptor/types';
4
+ import { ResponseBodyInterceptor } from '../responseBodyInterceptor/types';
4
5
  export type Config = {
5
6
  validateResources: boolean;
6
7
  resources: string[];
7
8
  apiPrefix: string | null;
8
9
  cacheControl: string;
9
- requestBodyInterceptor: RequestBodyInterceptor;
10
- responseBodyInterceptor: ResponseBodyInterceptor;
10
+ requestBodyInterceptor: RequestBodyInterceptor | null;
11
+ responseBodyInterceptor: ResponseBodyInterceptor | null;
11
12
  staticFolder: string | null;
12
13
  connectionString: string | null;
13
14
  delay: number;
@@ -34,5 +35,6 @@ export type UserConfig = {
34
35
  port?: number;
35
36
  schemas?: ConfiguredSchemas;
36
37
  };
37
- export declare function initConfig(userConfig?: UserConfig): Config;
38
+ export declare const initConfig: (userConfig?: UserConfig) => Config;
38
39
  export declare const isUndefined: (value: unknown) => value is undefined;
40
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAA;AACxE,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAA;AAE1E,MAAM,MAAM,MAAM,GAAG;IACnB,iBAAiB,EAAE,OAAO,CAAA;IAC1B,SAAS,EAAE,MAAM,EAAE,CAAA;IACnB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,YAAY,EAAE,MAAM,CAAA;IACpB,sBAAsB,EAAE,sBAAsB,GAAG,IAAI,CAAA;IACrD,uBAAuB,EAAE,uBAAuB,GAAG,IAAI,CAAA;IACvD,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,KAAK,EAAE,MAAM,CAAA;IACb,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,gBAAgB,EAAE,OAAO,CAAA;IACzB,SAAS,EAAE,OAAO,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAAA;CAClC,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,MAAM,MAAM,CAAA;AAEpC,MAAM,MAAM,YAAY,GAAG,IAAI,CAC7B,MAAM,EACJ,mBAAmB,GACnB,WAAW,GACX,WAAW,GACX,cAAc,GACd,wBAAwB,GACxB,yBAAyB,GACzB,kBAAkB,CACrB,CAAA;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,sBAAsB,CAAC,EAAE,sBAAsB,CAAA;IAC/C,uBAAuB,CAAC,EAAE,uBAAuB,CAAA;IACjD,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,iBAAiB,CAAA;CAC5B,CAAA;AAmBD,eAAO,MAAM,UAAU,gBAAiB,UAAU,KAAG,MAoFpD,CAAA;AAED,eAAO,MAAM,WAAW,UAAW,OAAO,uBAAqD,CAAA"}
@@ -1,18 +1,4 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.isUndefined = exports.initConfig = void 0;
15
- var defaultConfig = {
1
+ const defaultConfig = {
16
2
  resources: [],
17
3
  validateResources: false,
18
4
  staticFolder: null,
@@ -20,31 +6,18 @@ var defaultConfig = {
20
6
  connectionString: null,
21
7
  cacheControl: 'no-store',
22
8
  delay: 0,
23
- requestBodyInterceptor: {
24
- post: function () {
25
- // do nothing
26
- },
27
- patch: function () {
28
- // do nothing
29
- },
30
- put: function () {
31
- // do nothing
32
- },
33
- },
34
- responseBodyInterceptor: function (_a) {
35
- var body = _a.body;
36
- return body;
37
- },
9
+ requestBodyInterceptor: null,
10
+ responseBodyInterceptor: null,
38
11
  customRouter: null,
39
12
  returnNullFields: true,
40
13
  isTesting: false,
41
14
  port: 3000,
42
15
  schemas: null,
43
16
  };
44
- function initConfig(userConfig) {
17
+ export const initConfig = (userConfig) => {
45
18
  if (!userConfig)
46
19
  return defaultConfig;
47
- var config = __assign({}, defaultConfig);
20
+ const config = { ...defaultConfig };
48
21
  if (userConfig.resources && userConfig.resources.length > 0) {
49
22
  config.resources = userConfig.resources;
50
23
  config.validateResources = true;
@@ -69,6 +42,7 @@ function initConfig(userConfig) {
69
42
  config.delay = userConfig.delay;
70
43
  }
71
44
  if (userConfig.requestBodyInterceptor) {
45
+ config.requestBodyInterceptor = config.requestBodyInterceptor || {};
72
46
  if (userConfig.requestBodyInterceptor.post &&
73
47
  typeof userConfig.requestBodyInterceptor.post === 'function') {
74
48
  config.requestBodyInterceptor.post = userConfig.requestBodyInterceptor.post;
@@ -88,21 +62,19 @@ function initConfig(userConfig) {
88
62
  if (userConfig.customRouter) {
89
63
  config.customRouter = userConfig.customRouter;
90
64
  }
91
- if (!(0, exports.isUndefined)(userConfig.returnNullFields)) {
65
+ if (!isUndefined(userConfig.returnNullFields)) {
92
66
  config.returnNullFields = userConfig.returnNullFields;
93
67
  }
94
- if (!(0, exports.isUndefined)(userConfig.isTesting)) {
68
+ if (!isUndefined(userConfig.isTesting)) {
95
69
  config.isTesting = userConfig.isTesting;
96
70
  }
97
- if (!(0, exports.isUndefined)(userConfig.port)) {
71
+ if (!isUndefined(userConfig.port)) {
98
72
  config.port = userConfig.port;
99
73
  }
100
74
  if (userConfig.schemas) {
101
75
  config.schemas = userConfig.schemas;
102
76
  }
103
77
  return config;
104
- }
105
- exports.initConfig = initConfig;
106
- var isUndefined = function (value) { return typeof value === 'undefined'; };
107
- exports.isUndefined = isUndefined;
78
+ };
79
+ export const isUndefined = (value) => typeof value === 'undefined';
108
80
  //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":"AAmDA,MAAM,aAAa,GAAW;IAC5B,SAAS,EAAE,EAAE;IACb,iBAAiB,EAAE,KAAK;IACxB,YAAY,EAAE,IAAI;IAClB,SAAS,EAAE,IAAI;IACf,gBAAgB,EAAE,IAAI;IACtB,YAAY,EAAE,UAAU;IACxB,KAAK,EAAE,CAAC;IACR,sBAAsB,EAAE,IAAI;IAC5B,uBAAuB,EAAE,IAAI;IAC7B,YAAY,EAAE,IAAI;IAClB,gBAAgB,EAAE,IAAI;IACtB,SAAS,EAAE,KAAK;IAChB,IAAI,EAAE,IAAI;IACV,OAAO,EAAE,IAAI;CACd,CAAA;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,UAAuB,EAAU,EAAE;IAC5D,IAAI,CAAC,UAAU;QAAE,OAAO,aAAa,CAAA;IAErC,MAAM,MAAM,GAAG,EAAE,GAAG,aAAa,EAAY,CAAA;IAE7C,IAAI,UAAU,CAAC,SAAS,IAAI,UAAU,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5D,MAAM,CAAC,SAAS,GAAG,UAAU,CAAC,SAAS,CAAA;QACvC,MAAM,CAAC,iBAAiB,GAAG,IAAI,CAAA;IACjC,CAAC;IAED,IAAI,UAAU,CAAC,YAAY,EAAE,CAAC;QAC5B,MAAM,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAA;IAC5E,CAAC;IAED,IAAI,UAAU,CAAC,SAAS,EAAE,CAAC;QACzB,MAAM,CAAC,SAAS,GAAG,GAAG,GAAG,UAAU,CAAC,SAAS,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,GAAG,GAAG,CAAA;IAClF,CAAC;IAED,IAAI,UAAU,CAAC,gBAAgB,IAAI,UAAU,CAA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ACD,MAAM,CAAC,sBAAsB,CAAC,GAAG,GAAG,UAAU,CAAC,sBAAsB,CAAC,GAAG,CAAA;QAC3E,CAAC;IACH,CAAC;IAED,IAAI,UAAU,CAAC,uBAAuB,EAAE,CAAC;QACvC,MAAM,CAAC,uBAAuB,GAAG,UAAU,CAAC,uBAAuB,CAAA;IACrE,CAAC;IAED,IAAI,UAAU,CAAC,YAAY,EAAE,CAAC;QAC5B,MAAM,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,CAAA;IAC/C,CAAC;IAED,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAC9C,MAAM,CAAC,gBAAgB,GAAG,UAAU,CAAC,gBAAgB,CAAA;IACvD,CAAC;IAED,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QACvC,MAAM,CAAC,SAAS,GAAG,UAAU,CAAC,SAAS,CAAA;IACzC,CAAC;IAED,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAClC,MAAM,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAA;IAC/B,CAAC;IAED,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;QACvB,MAAM,CAAC,OAAO,GAAG,UAAU,CAAC,OAAO,CAAA;IACrC,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAc,EAAsB,EAAE,CAAC,OAAO,KAAK,KAAK,WAAW,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { NextFunction, Request, Response } from 'express';
2
+ export declare const createDelayMiddleware: (delay: number) => (req: Request, res: Response, next: NextFunction) => void;
3
+ //# sourceMappingURL=delayMiddleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delayMiddleware.d.ts","sourceRoot":"","sources":["../../../src/delay/delayMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAQ9D,eAAO,MAAM,qBAAqB,UAAW,MAAM,WACpC,OAAO,OAAO,QAAQ,QAAQ,YAAY,SAKxD,CAAA"}
@@ -0,0 +1,13 @@
1
+ const pause = (delay) => {
2
+ return (req, res, next) => {
3
+ setTimeout(next, delay);
4
+ };
5
+ };
6
+ export const createDelayMiddleware = (delay) => {
7
+ return (req, res, next) => {
8
+ console.log('Start delay...');
9
+ pause(delay)(req, res, next);
10
+ console.log('Delay finished!');
11
+ };
12
+ };
13
+ //# sourceMappingURL=delayMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delayMiddleware.js","sourceRoot":"","sources":["../../../src/delay/delayMiddleware.ts"],"names":[],"mappings":"AAEA,MAAM,KAAK,GAAG,CAAC,KAAa,EAAE,EAAE;IAC9B,OAAO,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;QACzD,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;IACzB,CAAC,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,KAAa,EAAE,EAAE;IACrD,OAAO,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;QACzD,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA;QAC7B,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;QAC5B,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;IAChC,CAAC,CAAA;AACH,CAAC,CAAA"}
package/src/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import type { UserConfig } from './config';
2
+ export declare const create: (userConfig?: UserConfig) => {
3
+ start: () => void;
4
+ Express: import("express-serve-static-core").Express | undefined;
5
+ };
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAiG1C,eAAO,MAAM,MAAM,gBAAiB,UAAU;;;CAA6B,CAAA"}
package/src/index.js ADDED
@@ -0,0 +1,83 @@
1
+ import express, { json } from 'express';
2
+ import morgan from 'morgan';
3
+ import { createQueries } from './queries/queries';
4
+ import { initConfig } from './config';
5
+ import cors from 'cors';
6
+ import { createDelayMiddleware } from './delay/delayMiddleware';
7
+ import { compileSchemas } from './schema/compile';
8
+ import { createResourceRouter } from './resourceRouter';
9
+ const createServer = (userConfig) => {
10
+ const config = initConfig(userConfig);
11
+ const queries = createQueries(config.connectionString);
12
+ const app = express();
13
+ app.use(json());
14
+ // Add HTTP request logging.
15
+ app.use(morgan('tiny'));
16
+ // Enable CORS for all requests.
17
+ app.use(cors({ origin: true, credentials: true }));
18
+ // Add a delay to every request, if configured.
19
+ if (config.delay > 0) {
20
+ const delayMiddleware = createDelayMiddleware(config.delay);
21
+ app.use(delayMiddleware);
22
+ }
23
+ // Serve a static folder, if configured.
24
+ if (config.staticFolder) {
25
+ app.use(express.static(config.staticFolder));
26
+ }
27
+ // On the root URL (with apiPrefix, if applicable) only a GET is allowed.
28
+ const rootRouter = express.Router();
29
+ const rootPath = config.apiPrefix ? `${config.apiPrefix}` : '/';
30
+ app.use(rootPath, rootRouter);
31
+ // Use a custom router, if configured.
32
+ if (config.customRouter) {
33
+ app.use(config.customRouter);
34
+ }
35
+ // Temba supports the GET, POST, PUT, PATCH, DELETE, and HEAD methods for resource URLs.
36
+ // HEAD is not implemented here, because Express supports it out of the box.
37
+ // Create a router on all other URLs, for all supported methods
38
+ const resourcePath = config.apiPrefix ? `${config.apiPrefix}*` : '*';
39
+ const schemas = compileSchemas(config.schemas);
40
+ const resourceRouter = createResourceRouter(queries, schemas, config);
41
+ app.use(resourcePath, resourceRouter);
42
+ // A GET to the root URL shows a default message.
43
+ rootRouter.get('/', async (_, res) => {
44
+ return res.send('It works! ツ');
45
+ });
46
+ // Route for handling not allowed methods.
47
+ const handleMethodNotAllowed = (_, res) => {
48
+ res.status(405).json({ message: 'Method Not Allowed' });
49
+ };
50
+ // Route for handling not found.
51
+ const handleNotFound = (_, res) => {
52
+ res.status(404).json({ message: 'Not Found' });
53
+ };
54
+ // All other requests to the root URL are not allowed.
55
+ rootRouter.all('/', handleMethodNotAllowed);
56
+ // In case of an API prefix, resource URLs outside of the API prefix return a 404 Not Found.
57
+ if (config.apiPrefix) {
58
+ app.get('*', handleNotFound);
59
+ app.post('*', handleNotFound);
60
+ app.put('*', handleNotFound);
61
+ app.delete('*', handleNotFound);
62
+ app.patch('*', handleNotFound);
63
+ }
64
+ // All other methods to any URL are not allowed.
65
+ app.all('*', handleMethodNotAllowed);
66
+ if (config.apiPrefix)
67
+ app.all(`${config.apiPrefix}*`, handleMethodNotAllowed);
68
+ return {
69
+ start: () => {
70
+ if (config.isTesting) {
71
+ console.log('⛔️ Server not started. Remove or disable isTesting from your config.');
72
+ return;
73
+ }
74
+ app.listen(config.port, () => {
75
+ console.log(`✅ Server listening on port ${config.port}`);
76
+ });
77
+ },
78
+ // Expose Express for testing purposes only, e.g. usage with supertest.
79
+ Express: config.isTesting ? app : undefined,
80
+ };
81
+ };
82
+ export const create = (userConfig) => createServer(userConfig);
83
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAqB,IAAI,EAAE,MAAM,SAAS,CAAA;AAC1D,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAErC,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,qBAAqB,EAAE,MAAM,y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E,cAAc,CAAC,CAAA;QAC5B,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAA;QAC7B,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,cAAc,CAAC,CAAA;QAC5B,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,cAAc,CAAC,CAAA;QAC/B,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,cAAc,CAAC,CAAA;IAChC,CAAC;IAED,gDAAgD;IAChD,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,sBAAsB,CAAC,CAAA;IACpC,IAAI,MAAM,CAAC,SAAS;QAAE,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,SAAS,GAAG,EAAE,sBAAsB,CAAC,CAAA;IAE7E,OAAO;QACL,KAAK,EAAE,GAAG,EAAE;YACV,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;gBACrB,OAAO,CAAC,GAAG,CAAC,sEAAsE,CAAC,CAAA;gBACnF,OAAM;YACR,CAAC;YAED,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;gBAC3B,OAAO,CAAC,GAAG,CAAC,8BAA8B,MAAM,CAAC,IAAI,EAAE,CAAC,CAAA;YAC1D,CAAC,CAAC,CAAA;QACJ,CAAC;QACD,uEAAuE;QACvE,OAAO,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS;KAC5C,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,UAAuB,EAAE,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { Queries } from './types';
2
+ export declare const inMemoryQueries: Queries;
3
+ //# sourceMappingURL=in-memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-memory.d.ts","sourceRoot":"","sources":["../../../src/queries/in-memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,OAAO,EAAE,MAAM,SAAS,CAAA;AAqEtD,eAAO,MAAM,eAAe,EAAE,OAQ7B,CAAA"}
@@ -0,0 +1,61 @@
1
+ const data = {};
2
+ const getAll = (resource) => {
3
+ createResourceArrayIfNecessary(resource);
4
+ return new Promise((resolve) => {
5
+ resolve(data[resource] || []);
6
+ });
7
+ };
8
+ const getById = (resource, id) => {
9
+ createResourceArrayIfNecessary(resource);
10
+ const item = (data[resource] || []).find((item) => item.id === id) || null;
11
+ return new Promise((resolve) => {
12
+ resolve(item);
13
+ });
14
+ };
15
+ const create = (resource, item) => {
16
+ createResourceArrayIfNecessary(resource);
17
+ const newItem = { ...item, id: String(new Date().getTime()) };
18
+ data[resource] = [...(data[resource] || []), newItem];
19
+ return new Promise((resolve) => {
20
+ resolve(newItem);
21
+ });
22
+ };
23
+ const update = (resource, item) => {
24
+ createResourceArrayIfNecessary(resource);
25
+ const updatedItem = { ...item };
26
+ data[resource] = [...(data[resource] || []).filter((r) => r.id !== item.id), updatedItem];
27
+ return new Promise((resolve) => {
28
+ resolve(updatedItem);
29
+ });
30
+ };
31
+ const replace = (resource, item) => {
32
+ return update(resource, item);
33
+ };
34
+ const deleteById = (resource, id) => {
35
+ createResourceArrayIfNecessary(resource);
36
+ data[resource] = (data[resource] || []).filter((item) => item.id !== id);
37
+ return new Promise((resolve) => {
38
+ resolve();
39
+ });
40
+ };
41
+ const deleteAll = (resource) => {
42
+ createResourceArrayIfNecessary(resource);
43
+ data[resource] = [];
44
+ return new Promise((resolve) => {
45
+ resolve();
46
+ });
47
+ };
48
+ const createResourceArrayIfNecessary = (resource) => {
49
+ if (!Object.hasOwn(data, resource))
50
+ data[resource] = [];
51
+ };
52
+ export const inMemoryQueries = {
53
+ getAll,
54
+ getById,
55
+ create,
56
+ update,
57
+ replace,
58
+ deleteById,
59
+ deleteAll,
60
+ };
61
+ //# sourceMappingURL=in-memory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-memory.js","sour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QACnC,OAAO,EAAE,CAAA;IACX,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,MAAM,8BAA8B,GAAG,CAAC,QAAgB,EAAE,EAAE;IAC1D,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC;QAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAA;AACzD,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,eAAe,GAAY;IACtC,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,OAAO;IACP,UAAU;IACV,SAAS;CACV,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { Queries } from './types';
2
+ export declare const createMongoQueries: (connectionString: string) => Queries;
3
+ //# sourceMappingURL=mongo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongo.d.ts","sourceRoot":"","sources":["../../../src/queries/mongo.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,OAAO,EAAE,MAAM,SAAS,CAAA;AA8FtD,eAAO,MAAM,kBAAkB,qBAAsB,MAAM,YAc1D,CAAA"}
@@ -0,0 +1,75 @@
1
+ import { connect } from '@rakered/mongo';
2
+ let uri;
3
+ let db;
4
+ const connectToDatabase = async () => {
5
+ if (!db) {
6
+ console.log('Connecting to MongoDB...');
7
+ try {
8
+ db = await connect(uri);
9
+ console.log('Connected to MongoDB!');
10
+ }
11
+ catch (error) {
12
+ console.log('Error connecting to MongoDB:');
13
+ console.error(error);
14
+ }
15
+ }
16
+ };
17
+ const getAll = async (resource) => {
18
+ await connectToDatabase();
19
+ const items = (await db[resource].find({}));
20
+ if (!items)
21
+ return [];
22
+ return items.map((item) => removeUnderscoreFromId(item));
23
+ };
24
+ const getById = async (resource, id) => {
25
+ await connectToDatabase();
26
+ const item = await db[resource].findOne({ _id: id });
27
+ if (!item)
28
+ return null;
29
+ return removeUnderscoreFromId(item);
30
+ };
31
+ const create = async (resource, item) => {
32
+ await connectToDatabase();
33
+ const createdItem = await db[resource].insertOne(item);
34
+ return removeUnderscoreFromId(createdItem.ops[0]);
35
+ };
36
+ const update = async (resource, item) => {
37
+ await connectToDatabase();
38
+ const { id, ...itemWithoutId } = item;
39
+ const updatedItem = await db[resource].findOneAndUpdate({ _id: id }, { $set: itemWithoutId }, { returnOriginal: false });
40
+ return removeUnderscoreFromId(updatedItem.value);
41
+ };
42
+ const replace = async (resource, item) => {
43
+ await connectToDatabase();
44
+ const { id, ...itemWithoutId } = item;
45
+ const replacedItem = await db[resource].findOneAndReplace({ _id: id }, itemWithoutId, {
46
+ returnOriginal: false,
47
+ });
48
+ return removeUnderscoreFromId(replacedItem.value);
49
+ };
50
+ const deleteById = async (resource, id) => {
51
+ await connectToDatabase();
52
+ await db[resource].deleteOne({ _id: id });
53
+ };
54
+ const deleteAll = async (resource) => {
55
+ await connectToDatabase();
56
+ await db[resource].deleteMany({});
57
+ };
58
+ const removeUnderscoreFromId = (item) => {
59
+ const { _id, ...updatedItem } = item;
60
+ return updatedItem;
61
+ };
62
+ export const createMongoQueries = (connectionString) => {
63
+ uri = connectionString;
64
+ const mongoQueries = {
65
+ getAll,
66
+ getById,
67
+ create,
68
+ update,
69
+ replace,
70
+ deleteById,
71
+ deleteAll,
72
+ };
73
+ return mongoQueries;
74
+ };
75
+ //# sourceMappingURL=mongo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongo.js","sourceRoot":"","sources":["../../../src/queries/mongo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAM,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAG5C,IAAI,GAAW,CAAA;AACf,IAAI,EAAM,CAAA;AAEV,MAAM,iBAAiB,GAAG,KAAK,IAAI,EAAE;IACnC,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAA;QACvC,IAAI,CAAC;YACH,EAAE,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAA;YACvB,OAAO,CAAC,GAAG,CAA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AAE;IACjD,MAAM,EAAE,GAAG,EAAE,GAAG,WAAW,EAAE,GAAG,IAAI,CAAA;IACpC,OAAO,WAAmB,CAAA;AAC5B,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,gBAAwB,EAAE,EAAE;IAC7D,GAAG,GAAG,gBAAgB,CAAA;IAEtB,MAAM,YAAY,GAAY;QAC5B,MAAM;QACN,OAAO;QACP,MAAM;QACN,MAAM;QACN,OAAO;QACP,UAAU;QACV,SAAS;KACV,CAAA;IAED,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare const createQueries: (connectionString: string | null) => import("./types").Queries;
2
+ //# sourceMappingURL=queries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../../src/queries/queries.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa,qBAAsB,MAAM,GAAG,IAAI,8BAO5D,CAAA"}
@@ -0,0 +1,10 @@
1
+ import { inMemoryQueries } from './in-memory';
2
+ import { createMongoQueries } from './mongo';
3
+ export const createQueries = (connectionString) => {
4
+ if (!connectionString) {
5
+ return inMemoryQueries;
6
+ }
7
+ const mongoQueries = createMongoQueries(connectionString);
8
+ return mongoQueries;
9
+ };
10
+ //# sourceMappingURL=queries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queries.js","sourceRoot":"","sources":["../../../src/queries/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAE5C,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,gBAA+B,EAAE,EAAE;IAC/D,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,OAAO,eAAe,CAAA;IACxB,CAAC;IAED,MAAM,YAAY,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,CAAA;IACzD,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA"}
@@ -0,0 +1,15 @@
1
+ export type Item = {
2
+ id: string;
3
+ [key: string]: unknown;
4
+ };
5
+ export type ItemWithoutId = Omit<Item, 'id'>;
6
+ export type Queries = {
7
+ getAll: (resource: string) => Promise<Item[]>;
8
+ getById: (resource: string, id: string) => Promise<Item | null>;
9
+ create: (resource: string, item: ItemWithoutId) => Promise<Item>;
10
+ update: (resource: string, item: Item) => Promise<Item>;
11
+ replace: (resource: string, item: Item) => Promise<Item>;
12
+ deleteById: (resource: string, id: string) => Promise<void>;
13
+ deleteAll: (resource: string) => Promise<void>;
14
+ };
15
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/queries/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,IAAI,GAAG;IACjB,EAAE,EAAE,MAAM,CAAA;IACV,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;AAE5C,MAAM,MAAM,OAAO,GAAG;IACpB,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;IAC7C,OAAO,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAAA;IAC/D,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAChE,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACvD,OAAO,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACxD,UAAU,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC3D,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAC/C,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/routes/types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/queries/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ import type { RequestBodyInterceptorCallback } from './types';
2
+ export declare const interceptRequestBody: (intercept: RequestBodyInterceptorCallback, resource: string, body: unknown) => unknown;
3
+ //# sourceMappingURL=interceptRequestBody.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interceptRequestBody.d.ts","sourceRoot":"","sources":["../../../src/requestBodyInterceptor/interceptRequestBody.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,SAAS,CAAA;AAE7D,eAAO,MAAM,oBAAoB,cACpB,8BAA8B,YAC/B,MAAM,QACV,OAAO,YAed,CAAA"}
@@ -0,0 +1,14 @@
1
+ export const interceptRequestBody = (intercept, resource, body) => {
2
+ const intercepted = intercept({ resource, body });
3
+ if (!intercepted && typeof body === 'object')
4
+ return body;
5
+ if (typeof intercepted === 'string')
6
+ return intercepted;
7
+ // The request body was replaced by an object
8
+ if (intercepted && typeof intercepted === 'object' && !Array.isArray(intercepted))
9
+ return intercepted;
10
+ // The request body was replaced by something else than an object or a string.
11
+ // This is not supported, so we return the original request body.
12
+ return body;
13
+ };
14
+ //# sourceMappingURL=interceptRequestBody.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interceptRequestBody.js","sourceRoot":"","sources":["../../../src/requestBodyInterceptor/interceptRequestBody.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,SAAyC,EACzC,QAAgB,EAChB,IAAa,EACb,EAAE;IACF,MAAM,WAAW,GAAG,SAAS,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;IAEjD,IAAI,CAAC,WAAW,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAA;IAEzD,IAAI,OAAO,WAAW,KAAK,QAAQ;QAAE,OAAO,WAAW,CAAA;IAEvD,6CAA6C;IAC7C,IAAI,WAAW,IAAI,OAAO,WAAW,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC;QAC/E,OAAO,WAAW,CAAA;IAEpB,8EAA8E;IAC9E,iEAAiE;IACjE,OAAO,IAAI,CAAA;AACb,CAAC,CAAA"}
@@ -0,0 +1,12 @@
1
+ type InterceptedRequest = {
2
+ resource: string;
3
+ body: unknown;
4
+ };
5
+ export type RequestBodyInterceptorCallback = (info: InterceptedRequest) => void | string | object;
6
+ export type RequestBodyInterceptor = {
7
+ post?: RequestBodyInterceptorCallback;
8
+ patch?: RequestBodyInterceptorCallback;
9
+ put?: RequestBodyInterceptorCallback;
10
+ };
11
+ export {};
12
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/requestBodyInterceptor/types.ts"],"names":[],"mappings":"AAAA,KAAK,kBAAkB,GAAG;IACxB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,OAAO,CAAA;CACd,CAAA;AAED,MAAM,MAAM,8BAA8B,GAAG,CAAC,IAAI,EAAE,kBAAkB,KAAK,IAAI,GAAG,MAAM,GAAG,MAAM,CAAA;AAEjG,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,CAAC,EAAE,8BAA8B,CAAA;IACrC,KAAK,CAAC,EAAE,8BAA8B,CAAA;IACtC,GAAG,CAAC,EAAE,8BAA8B,CAAA;CACrC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/requestBodyInterceptor/types.ts"],"names":[],"mappings":""}