@plurid/plurid-react-server 0.0.0-4 → 0.0.0-7

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.
@@ -1,7 +1,6 @@
1
1
  import express from 'express';
2
2
  import { Helmet } from 'react-helmet-async';
3
- import { PluridRoute, PluridRoutePlane, PluridPreserve } from '@plurid/plurid-data';
4
- import { routing } from '@plurid/plurid-engine';
3
+ import { PluridRoute, PluridRoutePlane, PluridPreserve, IsoMatcherRouteResult } from '@plurid/plurid-data';
5
4
  import { PluridReactComponent } from '@plurid/plurid-react';
6
5
  export declare type PluridServerMiddleware = (request: express.Request, response: express.Response, next: express.NextFunction) => void;
7
6
  export declare type ServerRequest = express.Request & {
@@ -141,4 +140,7 @@ export interface PluridStillerOptions {
141
140
  */
142
141
  ignore: string[];
143
142
  }
144
- export declare type PluridPreserveReact = PluridPreserve<routing.IsoMatcherRouteResult<PluridReactComponent<any>> | undefined, express.Request, express.Response>;
143
+ export declare type PluridPreserveReact = PluridPreserve<IsoMatcherRouteResult<PluridReactComponent<any>> | undefined, express.Request, express.Response>;
144
+ export interface PluridLiveServerOptions {
145
+ server: string;
146
+ }
@@ -1,5 +1,6 @@
1
1
  import PluridServer from './objects/Server';
2
+ import PluridLiveServer from './objects/LiveServer';
2
3
  import PluridStillsGenerator from './objects/StillsGenerator';
3
4
  export * from './data/interfaces/external';
4
- export { PluridStillsGenerator, };
5
+ export { PluridLiveServer, PluridStillsGenerator, };
5
6
  export default PluridServer;
@@ -24,6 +24,8 @@ import { renderToString } from "react-dom/server";
24
24
 
25
25
  import { HelmetProvider } from "react-helmet-async";
26
26
 
27
+ import http from "http";
28
+
27
29
  import { fork } from "child_process";
28
30
 
29
31
  import detectPort from "detect-port";
@@ -722,8 +724,9 @@ class PluridServer {
722
724
  renderApplication(isoMatch, preserveResult, matchedPlane) {
723
725
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
724
726
  return __awaiter(this, void 0, void 0, (function*() {
727
+ const globals = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.globals;
725
728
  const mergedHtmlLanguage = ((_a = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.template) === null || _a === void 0 ? void 0 : _a.htmlLanguage) || ((_b = this.template) === null || _b === void 0 ? void 0 : _b.htmlLanguage);
726
- const pluridMetastate = serverComputeMetastate(isoMatch, this.routes);
729
+ const pluridMetastate = serverComputeMetastate(isoMatch, this.routes, globals);
727
730
  const {content: content, styles: styles} = yield this.getContentAndStyles(isoMatch, pluridMetastate, preserveResult, matchedPlane);
728
731
  const stringedStyles = this.styles.reduce(((accumulator, style) => accumulator + style), "");
729
732
  const preserveStyles = ((_d = (_c = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.template) === null || _c === void 0 ? void 0 : _c.styles) === null || _d === void 0 ? void 0 : _d.join(" ")) || "";
@@ -739,7 +742,6 @@ class PluridServer {
739
742
  const mergedHeadScripts = [ ...headScripts, ...((_j = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.template) === null || _j === void 0 ? void 0 : _j.headScripts) || [] ];
740
743
  const bodyScripts = ((_k = this.template) === null || _k === void 0 ? void 0 : _k.bodyScripts) || [];
741
744
  const mergedBodyScripts = [ ...bodyScripts, ...((_l = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.template) === null || _l === void 0 ? void 0 : _l.bodyScripts) || [] ];
742
- const globals = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.globals;
743
745
  const renderer = new PluridRenderer({
744
746
  htmlLanguage: mergedHtmlLanguage,
745
747
  head: head,
@@ -913,6 +915,37 @@ class PluridServer {
913
915
  }
914
916
  }
915
917
 
918
+ class LiveServer {
919
+ constructor(options) {
920
+ this.sockets = [];
921
+ this.resolveOptions = options => {
922
+ const defaultServerPath = "./source/server/index.ts";
923
+ const resolvedOptions = {
924
+ server: (options === null || options === void 0 ? void 0 : options.server) || defaultServerPath
925
+ };
926
+ return resolvedOptions;
927
+ };
928
+ this.options = this.resolveOptions(options);
929
+ this.expressServer = express();
930
+ this.setupExpressServer();
931
+ this.httpServer = http.createServer(this.expressServer);
932
+ this.setupHttpServer();
933
+ }
934
+ setupExpressServer() {}
935
+ setupHttpServer() {
936
+ this.httpServer.on("connection", (socket => {
937
+ this.sockets.push(socket);
938
+ socket.once("close", (() => {
939
+ this.sockets.splice(this.sockets.indexOf(socket), 1);
940
+ }));
941
+ }));
942
+ this.httpServer.on("error", (error => {
943
+ throw error;
944
+ }));
945
+ }
946
+ start() {}
947
+ }
948
+
916
949
  const replacePluridResolution = html => {
917
950
  const normalResolution = "width: 1366px; height: 768px;";
918
951
  const zeroResolution = "width: 0px; height: 0px;";
@@ -955,7 +988,11 @@ const render = (puppeteer, host, route, configuration) => __awaiter(void 0, void
955
988
 
956
989
  class Stiller {
957
990
  constructor(options) {
958
- this.puppeteer = require("puppeteer");
991
+ try {
992
+ this.puppeteer = require("puppeteer");
993
+ } catch (error) {
994
+ console.error("could not load puppeteer: check puppeteer is installed");
995
+ }
959
996
  const {host: host, routes: routes, configuration: configuration} = options;
960
997
  this.host = host;
961
998
  this.routes = routes;
@@ -1061,4 +1098,4 @@ class StillsGenerator {
1061
1098
  }
1062
1099
  }
1063
1100
 
1064
- export { StillsGenerator as PluridStillsGenerator, PluridServer as default };
1101
+ export { LiveServer as PluridLiveServer, StillsGenerator as PluridStillsGenerator, PluridServer as default };
@@ -30,6 +30,8 @@ var server = require("react-dom/server");
30
30
 
31
31
  var reactHelmetAsync = require("react-helmet-async");
32
32
 
33
+ var http = require("http");
34
+
33
35
  var child_process = require("child_process");
34
36
 
35
37
  var detectPort = require("detect-port");
@@ -72,6 +74,8 @@ var open__default = _interopDefaultLegacy(open);
72
74
 
73
75
  var React__default = _interopDefaultLegacy(React);
74
76
 
77
+ var http__default = _interopDefaultLegacy(http);
78
+
75
79
  var detectPort__default = _interopDefaultLegacy(detectPort);
76
80
 
77
81
  function __awaiter(thisArg, _arguments, P, generator) {
@@ -772,8 +776,9 @@ class PluridServer {
772
776
  renderApplication(isoMatch, preserveResult, matchedPlane) {
773
777
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
774
778
  return __awaiter(this, void 0, void 0, (function*() {
779
+ const globals = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.globals;
775
780
  const mergedHtmlLanguage = ((_a = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.template) === null || _a === void 0 ? void 0 : _a.htmlLanguage) || ((_b = this.template) === null || _b === void 0 ? void 0 : _b.htmlLanguage);
776
- const pluridMetastate = pluridReact.serverComputeMetastate(isoMatch, this.routes);
781
+ const pluridMetastate = pluridReact.serverComputeMetastate(isoMatch, this.routes, globals);
777
782
  const {content: content, styles: styles} = yield this.getContentAndStyles(isoMatch, pluridMetastate, preserveResult, matchedPlane);
778
783
  const stringedStyles = this.styles.reduce(((accumulator, style) => accumulator + style), "");
779
784
  const preserveStyles = ((_d = (_c = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.template) === null || _c === void 0 ? void 0 : _c.styles) === null || _d === void 0 ? void 0 : _d.join(" ")) || "";
@@ -789,7 +794,6 @@ class PluridServer {
789
794
  const mergedHeadScripts = [ ...headScripts, ...((_j = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.template) === null || _j === void 0 ? void 0 : _j.headScripts) || [] ];
790
795
  const bodyScripts = ((_k = this.template) === null || _k === void 0 ? void 0 : _k.bodyScripts) || [];
791
796
  const mergedBodyScripts = [ ...bodyScripts, ...((_l = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.template) === null || _l === void 0 ? void 0 : _l.bodyScripts) || [] ];
792
- const globals = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.globals;
793
797
  const renderer = new PluridRenderer({
794
798
  htmlLanguage: mergedHtmlLanguage,
795
799
  head: head,
@@ -963,6 +967,37 @@ class PluridServer {
963
967
  }
964
968
  }
965
969
 
970
+ class LiveServer {
971
+ constructor(options) {
972
+ this.sockets = [];
973
+ this.resolveOptions = options => {
974
+ const defaultServerPath = "./source/server/index.ts";
975
+ const resolvedOptions = {
976
+ server: (options === null || options === void 0 ? void 0 : options.server) || defaultServerPath
977
+ };
978
+ return resolvedOptions;
979
+ };
980
+ this.options = this.resolveOptions(options);
981
+ this.expressServer = express__default["default"]();
982
+ this.setupExpressServer();
983
+ this.httpServer = http__default["default"].createServer(this.expressServer);
984
+ this.setupHttpServer();
985
+ }
986
+ setupExpressServer() {}
987
+ setupHttpServer() {
988
+ this.httpServer.on("connection", (socket => {
989
+ this.sockets.push(socket);
990
+ socket.once("close", (() => {
991
+ this.sockets.splice(this.sockets.indexOf(socket), 1);
992
+ }));
993
+ }));
994
+ this.httpServer.on("error", (error => {
995
+ throw error;
996
+ }));
997
+ }
998
+ start() {}
999
+ }
1000
+
966
1001
  const replacePluridResolution = html => {
967
1002
  const normalResolution = "width: 1366px; height: 768px;";
968
1003
  const zeroResolution = "width: 0px; height: 0px;";
@@ -1005,7 +1040,11 @@ const render = (puppeteer, host, route, configuration) => __awaiter(void 0, void
1005
1040
 
1006
1041
  class Stiller {
1007
1042
  constructor(options) {
1008
- this.puppeteer = require("puppeteer");
1043
+ try {
1044
+ this.puppeteer = require("puppeteer");
1045
+ } catch (error) {
1046
+ console.error("could not load puppeteer: check puppeteer is installed");
1047
+ }
1009
1048
  const {host: host, routes: routes, configuration: configuration} = options;
1010
1049
  this.host = host;
1011
1050
  this.routes = routes;
@@ -1111,6 +1150,8 @@ class StillsGenerator {
1111
1150
  }
1112
1151
  }
1113
1152
 
1153
+ exports.PluridLiveServer = LiveServer;
1154
+
1114
1155
  exports.PluridStillsGenerator = StillsGenerator;
1115
1156
 
1116
1157
  exports["default"] = PluridServer;
@@ -0,0 +1,13 @@
1
+ import { PluridLiveServerOptions } from "../../data/interfaces";
2
+ declare class LiveServer {
3
+ private options;
4
+ private expressServer;
5
+ private httpServer;
6
+ private sockets;
7
+ constructor(options?: Partial<PluridLiveServerOptions>);
8
+ private resolveOptions;
9
+ private setupExpressServer;
10
+ private setupHttpServer;
11
+ start(): void;
12
+ }
13
+ export default LiveServer;
@@ -25,7 +25,7 @@ declare class PluridServer {
25
25
  private isoMatcher;
26
26
  constructor(configuration: PluridServerConfiguration);
27
27
  static analysis(pluridServer: PluridServer): {
28
- routes: PluridRoute<PluridReactComponent<any, import("@plurid/plurid-data").PluridPlaneComponentProperty | import("@plurid/plurid-data").PluridRouteComponentProperty>>[];
28
+ routes: PluridRoute<PluridReactComponent<any, import("@plurid/plurid-data").PluridPlaneComponentProperty | import("@plurid/plurid-data").PluridRouteComponentProperty>, any>[];
29
29
  options: PluridServerOptions;
30
30
  };
31
31
  start(port?: string | number): Server;
@@ -1,6 +1,6 @@
1
- import { routing } from '@plurid/plurid-engine';
1
+ import { IsoMatcherPlaneResult } from '@plurid/plurid-data';
2
2
  import { PluridReactComponent } from '@plurid/plurid-react';
3
- export declare const resolveElementFromPlaneMatch: (planeMatch: routing.IsoMatcherPlaneResult<PluridReactComponent<any>>, elementqlEndpoint: string | undefined) => {
3
+ export declare const resolveElementFromPlaneMatch: (planeMatch: IsoMatcherPlaneResult<PluridReactComponent<any>>, elementqlEndpoint: string | undefined) => {
4
4
  name: string;
5
5
  url: string | undefined;
6
6
  } | undefined;
@@ -2,12 +2,10 @@ import React from 'react';
2
2
  declare const wrapping: (WrappedComponent: any, WrappeeComponent: any, properties: any) => {
3
3
  new (props: any): {
4
4
  render(): JSX.Element;
5
- context: any;
5
+ context: unknown;
6
6
  setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<{}>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
7
7
  forceUpdate(callback?: (() => void) | undefined): void;
8
- readonly props: Readonly<{}> & Readonly<{
9
- children?: React.ReactNode;
10
- }>;
8
+ readonly props: Readonly<{}>;
11
9
  state: Readonly<{}>;
12
10
  refs: {
13
11
  [key: string]: React.ReactInstance;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plurid/plurid-react-server",
3
- "version": "0.0.0-4",
3
+ "version": "0.0.0-7",
4
4
  "description": "React implementation of Plurid to view and explore the web in three dimensions with server-side rendering",
5
5
  "keywords": [
6
6
  "plurid",
@@ -39,12 +39,12 @@
39
39
  "clean": "rm -rf ./distribution",
40
40
  "test": "jest ./source --config ./configurations/jest.config.js --rootDir ./",
41
41
  "lint": "eslint -c ./configurations/.eslintrc.js ./source --ext .ts,.tsx",
42
- "start": "yarn clean && rollup -c ./scripts/rollup.development.js -w --environment ENV_MODE:local",
43
- "build.development": "yarn clean && rollup -c ./scripts/rollup.config.js --environment ENV_MODE:development",
44
- "build.production": "yarn clean && rollup -c ./scripts/rollup.config.js --environment ENV_MODE:production",
45
- "build": "yarn clean && yarn lint && yarn test && yarn build.production",
42
+ "start": "pnpm clean && rollup -c ./scripts/rollup.development.js -w --environment ENV_MODE:local",
43
+ "build.development": "pnpm clean && rollup -c ./scripts/rollup.config.js --environment ENV_MODE:development",
44
+ "build.production": "pnpm clean && rollup -c ./scripts/rollup.config.js --environment ENV_MODE:production",
45
+ "build": "pnpm clean && pnpm lint && pnpm test && pnpm build.production",
46
46
  "esbuild": "esbuild source/index.ts --bundle --platform=node --outfile=distribution/index.js --external:react",
47
- "prepublishOnly": "yarn build"
47
+ "prepublishOnly": "pnpm build"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "@plurid/elementql": "*",
@@ -68,65 +68,66 @@
68
68
  "styled-components": ">=5"
69
69
  },
70
70
  "dependencies": {
71
- "body-parser": "^1.19.0",
71
+ "body-parser": "^1.20.0",
72
72
  "compression": "^1.7.4",
73
73
  "detect-port": "^1.3.0",
74
- "express": "^4.17.1",
75
- "open": "^8.2.1"
74
+ "express": "^4.17.3",
75
+ "open": "^8.4.0"
76
76
  },
77
77
  "devDependencies": {
78
- "@apollo/client": "^3.4.13",
79
- "@babel/core": "^7.15.5",
78
+ "@apollo/client": "^3.5.10",
79
+ "@babel/core": "^7.17.9",
80
80
  "@plurid/elementql": "^0.0.0-1",
81
81
  "@plurid/elementql-client-react": "^0.0.0-1",
82
- "@plurid/plurid-data": "0.0.0-5",
83
- "@plurid/plurid-engine": "0.0.0-7",
84
- "@plurid/plurid-functions": "0.0.0-9",
85
- "@plurid/plurid-functions-react": "0.0.0-4",
86
- "@plurid/plurid-icons-react": "0.0.0-1",
87
- "@plurid/plurid-pubsub": "0.0.0-5",
88
- "@plurid/plurid-react": "0.0.0-8",
89
- "@plurid/plurid-themes": "0.0.0-0",
90
- "@plurid/plurid-ui-components-react": "0.0.0-3",
91
- "@plurid/plurid-ui-state-react": "0.0.0-1",
92
- "@rollup/plugin-node-resolve": "^13.0.5",
93
- "@types/body-parser": "^1.19.1",
82
+ "@plurid/plurid-data": "0.0.0-13",
83
+ "@plurid/plurid-engine": "0.0.0-11",
84
+ "@plurid/plurid-functions": "0.0.0-22",
85
+ "@plurid/plurid-functions-react": "0.0.0-5",
86
+ "@plurid/plurid-icons-react": "0.0.0-3",
87
+ "@plurid/plurid-pubsub": "0.0.0-6",
88
+ "@plurid/plurid-react": "0.0.0-19",
89
+ "@plurid/plurid-themes": "0.0.0-2",
90
+ "@plurid/plurid-ui-components-react": "0.0.0-11",
91
+ "@plurid/plurid-ui-state-react": "0.0.0-2",
92
+ "@redux-devtools/extension": "^3.2.2",
93
+ "@rollup/plugin-node-resolve": "^13.2.1",
94
+ "@types/body-parser": "^1.19.2",
94
95
  "@types/compression": "^1.7.2",
95
- "@types/detect-port": "^1.3.1",
96
+ "@types/detect-port": "^1.3.2",
96
97
  "@types/express": "^4.17.13",
97
- "@types/hammerjs": "^2.0.40",
98
- "@types/jest": "^27.0.2",
99
- "@types/node": "^16.9.6",
100
- "@types/react": "^17.0.24",
101
- "@types/react-dom": "^17.0.9",
102
- "@types/react-redux": "^7.1.18",
103
- "@types/react-stripe-elements": "^6.0.5",
104
- "@types/styled-components": "^5.1.14",
105
- "@typescript-eslint/eslint-plugin": "^4.31.2",
106
- "@typescript-eslint/parser": "^4.31.2",
98
+ "@types/hammerjs": "^2.0.41",
99
+ "@types/jest": "^27.4.1",
100
+ "@types/node": "^17.0.24",
101
+ "@types/react": "^18.0.5",
102
+ "@types/react-dom": "^18.0.1",
103
+ "@types/react-redux": "^7.1.24",
104
+ "@types/react-stripe-elements": "^6.0.6",
105
+ "@types/styled-components": "^5.1.25",
106
+ "@typescript-eslint/eslint-plugin": "^5.19.0",
107
+ "@typescript-eslint/parser": "^5.19.0",
107
108
  "@zerollup/ts-transform-paths": "^1.7.18",
108
- "cross-fetch": "^3.1.4",
109
- "eslint": "^7.32.0",
110
- "graphql": "^15.6.0",
109
+ "cross-fetch": "^3.1.5",
110
+ "eslint": "^8.13.0",
111
+ "graphql": "^16.3.0",
111
112
  "hammerjs": "^2.0.8",
112
- "jest": "^27.2.1",
113
- "jest-config": "^27.2.1",
114
- "react": "^17.0.2",
115
- "react-dom": "^17.0.2",
116
- "react-helmet-async": "^1.1.2",
117
- "react-redux": "^7.2.5",
118
- "redux": "^4.1.1",
119
- "redux-devtools-extension": "^2.13.9",
120
- "redux-thunk": "^2.3.0",
121
- "rollup": "^2.57.0",
113
+ "jest": "^27.5.1",
114
+ "jest-config": "^27.5.1",
115
+ "react": "^18.0.0",
116
+ "react-dom": "^18.0.0",
117
+ "react-helmet-async": "^1.3.0",
118
+ "react-redux": "^8.0.0",
119
+ "redux": "^4.1.2",
120
+ "redux-thunk": "^2.4.1",
121
+ "rollup": "^2.70.2",
122
122
  "rollup-plugin-peer-deps-external": "^2.2.4",
123
123
  "rollup-plugin-terser": "^7.0.2",
124
- "rollup-plugin-typescript2": "^0.30.0",
125
- "styled-components": "^5.3.1",
126
- "ts-jest": "^27.0.5",
127
- "ts-node": "^10.2.1",
128
- "ttypescript": "^1.5.12",
129
- "typescript": "^4.4.3",
124
+ "rollup-plugin-typescript2": "^0.31.2",
125
+ "styled-components": "^5.3.5",
126
+ "ts-jest": "^27.1.4",
127
+ "ts-node": "^10.7.0",
128
+ "tslib": "^2.3.1",
129
+ "ttypescript": "^1.5.13",
130
+ "typescript": "^4.6.3",
130
131
  "typescript-transform-paths": "^3.3.1"
131
132
  }
132
133
  }