@lwrjs/server 0.6.2 → 0.7.0-alpha.1

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.
@@ -0,0 +1,45 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, {get: all[name], enumerable: true});
11
+ };
12
+ var __exportStar = (target, module2, desc) => {
13
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
+ for (let key of __getOwnPropNames(module2))
15
+ if (!__hasOwnProp.call(target, key) && key !== "default")
16
+ __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
17
+ }
18
+ return target;
19
+ };
20
+ var __toModule = (module2) => {
21
+ return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
22
+ };
23
+
24
+ // packages/@lwrjs/server/src/common/compression.ts
25
+ __markAsModule(exports);
26
+ __export(exports, {
27
+ default: () => compression_default
28
+ });
29
+ var import_compression = __toModule(require("compression"));
30
+ var compressionLibToUse;
31
+ var compression = async (req, res, next) => {
32
+ if (compressionLibToUse === void 0) {
33
+ try {
34
+ let shrinkRay = await Promise.resolve().then(() => __toModule(require("shrink-ray-current")));
35
+ shrinkRay = shrinkRay.default || shrinkRay;
36
+ compressionLibToUse = shrinkRay({useZopfliForGzip: false});
37
+ } catch (err) {
38
+ compressionLibToUse = (0, import_compression.default)();
39
+ }
40
+ }
41
+ compressionLibToUse(req, res, next);
42
+ };
43
+ function compression_default() {
44
+ return compression;
45
+ }
@@ -68,7 +68,7 @@ var ExpressRequest = class {
68
68
  return !this.hasJsonParam() || this.req.accepts("json") === "json";
69
69
  }
70
70
  getRuntimeContext(defaultRuntimeEnvironment) {
71
- const {format, apiVersion, compat, locale, environment} = this.req.params;
71
+ const {format, apiVersion, compat, locale, environment, bundleSpecifier} = this.req.params;
72
72
  const {debug} = this.req.query;
73
73
  return {
74
74
  runtimeEnvironment: {
@@ -76,7 +76,8 @@ var ExpressRequest = class {
76
76
  format: format ? format : defaultRuntimeEnvironment.format,
77
77
  compat: compat !== void 0 ? compat : defaultRuntimeEnvironment.compat,
78
78
  debug: debug !== void 0 ? true : defaultRuntimeEnvironment.debug,
79
- apiVersion: apiVersion ? apiVersion : defaultRuntimeEnvironment.apiVersion
79
+ apiVersion: apiVersion ? apiVersion : defaultRuntimeEnvironment.apiVersion,
80
+ bundle: bundleSpecifier !== void 0 ? true : false
80
81
  },
81
82
  runtimeParams: {
82
83
  locale: locale ? locale : this.req.locale ? this.req.locale : defaultRuntimeEnvironment.defaultLocale,
@@ -29,7 +29,7 @@ __export(exports, {
29
29
  var import_express = __toModule(require("express"));
30
30
  var import_spdy = __toModule(require("spdy"));
31
31
  var import_http = __toModule(require("http"));
32
- var import_shrink_ray_current = __toModule(require("shrink-ray-current"));
32
+ var import_compression = __toModule(require("../common/compression.cjs"));
33
33
  var import_abstract_internal_app_server = __toModule(require("../common/abstract-internal-app-server.cjs"));
34
34
  var import_express_request = __toModule(require("./express-request.cjs"));
35
35
  var import_express_response = __toModule(require("./express-response.cjs"));
@@ -91,7 +91,7 @@ var ExpressInternalServer = class extends import_abstract_internal_app_server.de
91
91
  });
92
92
  }
93
93
  useCompression() {
94
- this.expressApp.use((0, import_shrink_ray_current.default)({useZopfliForGzip: false}));
94
+ this.expressApp.use((0, import_compression.default)());
95
95
  }
96
96
  getRegexWildcard() {
97
97
  return "*";
@@ -66,7 +66,7 @@ var KoaRequest = class {
66
66
  return !this.hasJsonParam() || this.ctx.request.accepts("json") === "json";
67
67
  }
68
68
  getRuntimeContext(defaultRuntimeEnvironment) {
69
- const {format, apiVersion, compat, locale, environment} = this.params;
69
+ const {format, apiVersion, compat, locale, environment, bundleSpecifier} = this.params;
70
70
  const {debug} = this.ctx.request.query;
71
71
  return {
72
72
  runtimeEnvironment: {
@@ -74,7 +74,8 @@ var KoaRequest = class {
74
74
  format: format ? format : defaultRuntimeEnvironment.format,
75
75
  compat: compat !== void 0 ? compat : defaultRuntimeEnvironment.compat,
76
76
  debug: debug !== void 0 ? true : defaultRuntimeEnvironment.debug,
77
- apiVersion: apiVersion ? apiVersion : defaultRuntimeEnvironment.apiVersion
77
+ apiVersion: apiVersion ? apiVersion : defaultRuntimeEnvironment.apiVersion,
78
+ bundle: bundleSpecifier !== void 0 ? true : false
78
79
  },
79
80
  runtimeParams: {
80
81
  locale: locale ? locale : this.ctx.locale ? this.ctx.locale : defaultRuntimeEnvironment.defaultLocale,
@@ -0,0 +1,3 @@
1
+ import { RequestHandler } from 'express';
2
+ export default function (): RequestHandler;
3
+ //# sourceMappingURL=compression.d.ts.map
@@ -0,0 +1,25 @@
1
+ import expressCompression from 'compression';
2
+ let compressionLibToUse;
3
+ const compression = async (req, res, next) => {
4
+ if (compressionLibToUse === undefined) {
5
+ // TODO: Unfortunately the compression story for express is a mess.
6
+ // shrink-ray-current is a fork of compression with brotlli support, we will use it until the
7
+ // "official" one accepts a PR to support it: https://github.com/expressjs/compression/issues/71
8
+ // Since it has some native dependencies (node-zopfli-es, iltorb) that may fail to compile in
9
+ // certain environments, we make it an optional dependency and fall back to vanilla compression.
10
+ try {
11
+ let shrinkRay = await import('shrink-ray-current');
12
+ shrinkRay = shrinkRay.default || shrinkRay;
13
+ compressionLibToUse = shrinkRay({ useZopfliForGzip: false });
14
+ }
15
+ catch (err) {
16
+ compressionLibToUse = expressCompression();
17
+ }
18
+ }
19
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
20
+ compressionLibToUse(req, res, next);
21
+ };
22
+ export default function () {
23
+ return compression;
24
+ }
25
+ //# sourceMappingURL=compression.js.map
@@ -58,7 +58,7 @@ export default class ExpressRequest {
58
58
  return !this.hasJsonParam() || this.req.accepts('json') === 'json';
59
59
  }
60
60
  getRuntimeContext(defaultRuntimeEnvironment) {
61
- const { format, apiVersion, compat, locale, environment } = this.req.params;
61
+ const { format, apiVersion, compat, locale, environment, bundleSpecifier } = this.req.params;
62
62
  const { debug } = this.req.query;
63
63
  return {
64
64
  runtimeEnvironment: {
@@ -67,6 +67,7 @@ export default class ExpressRequest {
67
67
  compat: compat !== undefined ? compat : defaultRuntimeEnvironment.compat,
68
68
  debug: debug !== undefined ? true : defaultRuntimeEnvironment.debug,
69
69
  apiVersion: apiVersion ? apiVersion : defaultRuntimeEnvironment.apiVersion,
70
+ bundle: bundleSpecifier !== undefined ? true : false, // the absence of a bundle strategy means bundling is off
70
71
  },
71
72
  runtimeParams: {
72
73
  locale: locale
@@ -1,7 +1,7 @@
1
1
  import express from 'express';
2
2
  import spdy from 'spdy';
3
3
  import http from 'http';
4
- import compression from 'shrink-ray-current';
4
+ import compression from '../common/compression.js';
5
5
  import AbstractInternalAppServer from '../common/abstract-internal-app-server.js';
6
6
  import ExpressRequest from './express-request.js';
7
7
  import ExpressResponse from './express-response.js';
@@ -68,10 +68,7 @@ export default class ExpressInternalServer extends AbstractInternalAppServer {
68
68
  });
69
69
  }
70
70
  useCompression() {
71
- // TODO: Unfortunately the compression story for express is a mess
72
- // shrink-ray is a fork of compression with brotlli support, we will use it
73
- // until the "official" one accepts a PR to support it
74
- this.expressApp.use(compression({ useZopfliForGzip: false }));
71
+ this.expressApp.use(compression());
75
72
  }
76
73
  getRegexWildcard() {
77
74
  return '*';
@@ -54,7 +54,7 @@ export default class KoaRequest {
54
54
  return !this.hasJsonParam() || this.ctx.request.accepts('json') === 'json';
55
55
  }
56
56
  getRuntimeContext(defaultRuntimeEnvironment) {
57
- const { format, apiVersion, compat, locale, environment } = this.params;
57
+ const { format, apiVersion, compat, locale, environment, bundleSpecifier } = this.params;
58
58
  const { debug } = this.ctx.request.query;
59
59
  return {
60
60
  runtimeEnvironment: {
@@ -63,6 +63,7 @@ export default class KoaRequest {
63
63
  compat: compat !== undefined ? compat : defaultRuntimeEnvironment.compat,
64
64
  debug: debug !== undefined ? true : defaultRuntimeEnvironment.debug,
65
65
  apiVersion: apiVersion ? apiVersion : defaultRuntimeEnvironment.apiVersion,
66
+ bundle: bundleSpecifier !== undefined ? true : false, // the absence of a bundle strategy means bundling is off
66
67
  },
67
68
  runtimeParams: {
68
69
  locale: locale
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.6.2",
7
+ "version": "0.7.0-alpha.1",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -30,7 +30,7 @@
30
30
  "build/**/*.d.ts"
31
31
  ],
32
32
  "devDependencies": {
33
- "@lwrjs/types": "0.6.2",
33
+ "@lwrjs/types": "0.7.0-alpha.1",
34
34
  "@types/koa-compress": "^4.0.1",
35
35
  "@types/koa__router": "^8.0.4",
36
36
  "@types/spdy": "^3.4.4",
@@ -38,18 +38,22 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@koa/router": "^10.0.0",
41
- "@lwrjs/shared-utils": "0.6.2",
41
+ "@lwrjs/shared-utils": "0.7.0-alpha.1",
42
+ "@types/compression": "^1.7.2",
42
43
  "@types/express": "^4.17.11",
43
44
  "@types/koa": "^2.11.7",
45
+ "compression": "^1.7.4",
44
46
  "express": "^4.17.1",
45
47
  "koa": "^2.13.1",
46
48
  "koa-compose": "^4.1.0",
47
49
  "koa-compress": "^5.0.1",
48
- "shrink-ray-current": "^4.1.2",
49
50
  "spdy": "^4.0.2"
50
51
  },
52
+ "optionalDependencies": {
53
+ "shrink-ray-current": "^4.1.2"
54
+ },
51
55
  "engines": {
52
56
  "node": ">=14.15.4 <17"
53
57
  },
54
- "gitHead": "ef85bdc48adde58b7c648561d67acbb408bbe189"
58
+ "gitHead": "24245670d6908d37e465f2316f92385df63d22aa"
55
59
  }