@remit/backend 0.0.146 → 0.0.147

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 (2) hide show
  1. package/dist/src/api.js +19 -1
  2. package/package.json +1 -1
package/dist/src/api.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import spec from "@remit/api-openapi-spec/openapi.json" with { type: "json" };
2
+ import { requestValidators } from "@remit/api-openapi-spec/request-validators";
2
3
  import { redactCalendarFeedPath } from "@remit/calendar-service";
3
4
  import { logger } from "@remit/logger";
4
5
  import { OpenAPIBackend, } from "openapi-backend";
@@ -16,7 +17,24 @@ if (!isDocument(spec)) {
16
17
  }
17
18
  // Typed as a Document so importers do not see the JSON literal type.
18
19
  export const OpenAPISpec = spec;
19
- const api = new OpenAPIBackend({
20
+ // ajv compiles a validator with `new Function`, which a Cloudflare Worker
21
+ // refuses, so every init hands the router the validators codegen compiled ahead
22
+ // of time. A host may call init again; in quick mode it builds the validator
23
+ // before its first await, so the validators land before any request does.
24
+ class PrecompiledOpenAPIBackend extends OpenAPIBackend {
25
+ init() {
26
+ const initialized = super.init();
27
+ for (const { operationId } of this.router.getOperations()) {
28
+ if (!operationId || !Object.hasOwn(requestValidators, operationId)) {
29
+ throw new Error(`No precompiled request validator for ${operationId}; run npm run codegen`);
30
+ }
31
+ this.validator.requestValidators[operationId] =
32
+ requestValidators[operationId];
33
+ }
34
+ return initialized;
35
+ }
36
+ }
37
+ const api = new PrecompiledOpenAPIBackend({
20
38
  definition: OpenAPISpec,
21
39
  quick: true,
22
40
  // Coerce query/path params to their schema types. API Gateway delivers every
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/backend",
3
- "version": "0.0.146",
3
+ "version": "0.0.147",
4
4
  "description": "Remit Mail Inspector API backend",
5
5
  "license": "MIT",
6
6
  "author": "",