@fc3/server 0.1.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.
Files changed (82) hide show
  1. package/LICENSE +673 -0
  2. package/README.md +3 -0
  3. package/bin/compile +55 -0
  4. package/bin/install +5 -0
  5. package/bin/lint +12 -0
  6. package/bin/postpublish +5 -0
  7. package/bin/precompile +55 -0
  8. package/bin/prepublish +7 -0
  9. package/bin/remap-paths +120 -0
  10. package/bin/test +9 -0
  11. package/bin/test-one +32 -0
  12. package/dist/.keep +0 -0
  13. package/dist/.last-compile-time +1 -0
  14. package/dist/.last-publish-time +1 -0
  15. package/dist/src/base.d.ts +36 -0
  16. package/dist/src/base.js +136 -0
  17. package/dist/src/base.js.map +1 -0
  18. package/dist/src/enum/server-event.d.ts +4 -0
  19. package/dist/src/enum/server-event.js +8 -0
  20. package/dist/src/enum/server-event.js.map +1 -0
  21. package/dist/src/enum/server-status.d.ts +9 -0
  22. package/dist/src/enum/server-status.js +13 -0
  23. package/dist/src/enum/server-status.js.map +1 -0
  24. package/dist/src/http/endpoint/ping.d.ts +12 -0
  25. package/dist/src/http/endpoint/ping.js +22 -0
  26. package/dist/src/http/endpoint/ping.js.map +1 -0
  27. package/dist/src/http/endpoint.d.ts +47 -0
  28. package/dist/src/http/endpoint.js +216 -0
  29. package/dist/src/http/endpoint.js.map +1 -0
  30. package/dist/src/http/interface/endpoint-constructor.d.ts +5 -0
  31. package/dist/src/http/interface/endpoint-constructor.js +4 -0
  32. package/dist/src/http/interface/endpoint-constructor.js.map +1 -0
  33. package/dist/src/http/interface/result-serializer.d.ts +4 -0
  34. package/dist/src/http/interface/result-serializer.js +3 -0
  35. package/dist/src/http/interface/result-serializer.js.map +1 -0
  36. package/dist/src/http/middleware.d.ts +6 -0
  37. package/dist/src/http/middleware.js +9 -0
  38. package/dist/src/http/middleware.js.map +1 -0
  39. package/dist/src/http/result-serializer/html.d.ts +16 -0
  40. package/dist/src/http/result-serializer/html.js +74 -0
  41. package/dist/src/http/result-serializer/html.js.map +1 -0
  42. package/dist/src/http/result-serializer/json.d.ts +8 -0
  43. package/dist/src/http/result-serializer/json.js +17 -0
  44. package/dist/src/http/result-serializer/json.js.map +1 -0
  45. package/dist/src/http/route.d.ts +21 -0
  46. package/dist/src/http/route.js +73 -0
  47. package/dist/src/http/route.js.map +1 -0
  48. package/dist/src/http/router.d.ts +20 -0
  49. package/dist/src/http/router.js +78 -0
  50. package/dist/src/http/router.js.map +1 -0
  51. package/dist/src/http/type/session-resolver.d.ts +6 -0
  52. package/dist/src/http/type/session-resolver.js +3 -0
  53. package/dist/src/http/type/session-resolver.js.map +1 -0
  54. package/dist/src/http/utility/create-server.d.ts +10 -0
  55. package/dist/src/http/utility/create-server.js +27 -0
  56. package/dist/src/http/utility/create-server.js.map +1 -0
  57. package/dist/src/http/utility/path-parser.d.ts +11 -0
  58. package/dist/src/http/utility/path-parser.js +34 -0
  59. package/dist/src/http/utility/path-parser.js.map +1 -0
  60. package/dist/src/http/utility/standardize-html-indentation.d.ts +2 -0
  61. package/dist/src/http/utility/standardize-html-indentation.js +44 -0
  62. package/dist/src/http/utility/standardize-html-indentation.js.map +1 -0
  63. package/dist/src/http/websocket-wrapper.d.ts +21 -0
  64. package/dist/src/http/websocket-wrapper.js +56 -0
  65. package/dist/src/http/websocket-wrapper.js.map +1 -0
  66. package/dist/src/http.d.ts +40 -0
  67. package/dist/src/http.js +209 -0
  68. package/dist/src/http.js.map +1 -0
  69. package/dist/src/index.d.ts +5 -0
  70. package/dist/src/index.js +17 -0
  71. package/dist/src/index.js.map +1 -0
  72. package/dist/src/tcp.d.ts +13 -0
  73. package/dist/src/tcp.js +41 -0
  74. package/dist/src/tcp.js.map +1 -0
  75. package/dist/src/type/server-options.d.ts +7 -0
  76. package/dist/src/type/server-options.js +3 -0
  77. package/dist/src/type/server-options.js.map +1 -0
  78. package/dist/test/unit/index.d.ts +1 -0
  79. package/dist/test/unit/index.js +12 -0
  80. package/dist/test/unit/index.js.map +1 -0
  81. package/dist/tsconfig.tsbuildinfo +1 -0
  82. package/package.json +47 -0
package/bin/compile ADDED
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env bash
2
+
3
+ if [[ $1 == '--help' ]]; then
4
+ echo "Triggers recompilation of the source code for the current project."
5
+ echo "Supported flags:"
6
+ echo "--force : Bypasses any precompilation checks (cache, mutex, etc)"
7
+ echo " Use this if you want to recompile no matter what."
8
+ echo " "
9
+ exit 0
10
+ fi
11
+
12
+ if [[ $1 != '--force' ]]; then
13
+ ./bin/precompile
14
+
15
+ case $? in
16
+ 1)
17
+ exit 1
18
+ ;;
19
+ 3)
20
+ exit 0
21
+ ;;
22
+ esac
23
+ fi
24
+
25
+ echo "Recompiling..."
26
+ mkdir -p dist
27
+ echo $$ > dist/.compile-lock
28
+ rm -f dist/.last-compile-time
29
+
30
+ project_dir="$(dirname $(dirname "$0"))"
31
+
32
+ if [[ $1 == '--force' ]]; then
33
+ rm -rf dist/src
34
+ rm -rf dist/test
35
+ ./node_modules/.bin/tsc --declaration --project "$project_dir/config/tsconfig.json"
36
+ else
37
+ ./node_modules/.bin/tsc --declaration --incremental --project "$project_dir/config/tsconfig.json"
38
+ fi
39
+
40
+ exit_status=$?
41
+
42
+ if [[ $exit_status -eq 0 ]]; then
43
+ ./bin/remap-paths
44
+ echo $(date +%s) > dist/.last-compile-time
45
+ fi
46
+
47
+ pid=$(cat dist/.compile-lock)
48
+
49
+ if [[ $pid == $$ ]]; then
50
+ rm dist/.compile-lock
51
+ exit $exit_status
52
+ else
53
+ echo "Detected a conflicting compile lock..."
54
+ exit 1
55
+ fi
package/bin/install ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ ./bin/compile
package/bin/lint ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ if [[ "${1:-}" == "--fix" ]]; then
6
+ ./node_modules/.bin/eslint "src/**/*.{ts,tsx}" "test/unit/**/*.{ts,tsx}" --fix
7
+ ./node_modules/.bin/prettier --write "src/**/*.{ts,tsx}" "test/unit/**/*.{ts,tsx}"
8
+ else
9
+ ./node_modules/.bin/eslint "src/**/*.{ts,tsx}" "test/unit/**/*.{ts,tsx}"
10
+ ./node_modules/.bin/prettier --check "src/**/*.{ts,tsx}" "test/unit/**/*.{ts,tsx}"
11
+ fi
12
+
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ rm ./dist/.last-publish-time
package/bin/precompile ADDED
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env bash
2
+
3
+ mkdir -p dist
4
+
5
+ if [ -f dist/.compile-lock ]; then
6
+ pid=$(cat dist/.compile-lock)
7
+ ticks=0
8
+ max_ticks=10
9
+
10
+ if ! ps -p $pid > /dev/null; then
11
+ echo "Detected a stale compile lock; deleting..."
12
+ rm -f dist/.compile-lock
13
+ else
14
+ echo "Compilation already in progress; waiting up to $max_ticks seconds..."
15
+ fi
16
+
17
+ while [ -f dist/.compile-lock ]; do
18
+ sleep 1
19
+ let ticks=ticks+1
20
+
21
+ if [ $ticks -ge $max_ticks ]; then
22
+ echo "Timed out waiting for compilation to clear"
23
+ exit 1
24
+ fi
25
+ done
26
+ fi
27
+
28
+ if [[ -f ./dist/.last-publish-time ]]; then
29
+ echo "Found publication compile artifact; skipping recompilation."
30
+ exit 3
31
+ fi
32
+
33
+ if [ -f dist/.last-compile-time ]; then
34
+ if [ ! -d src ]; then
35
+ # TODO: Confirm we're within a deploy environment
36
+ echo "src folder does not exist; skipping recompilation."
37
+ exit 3
38
+ fi
39
+
40
+ typeset -i last_modification_time=$(find src test -type f -print0 |
41
+ xargs -0 stat -c "%X %N" |
42
+ sort -rn |
43
+ head -1 |
44
+ awk '{ print $1 }')
45
+
46
+ typeset -i last_compile_time=$(cat dist/.last-compile-time)
47
+
48
+ if (( $last_compile_time > $last_modification_time )); then
49
+ echo "No changes since last compile; skipping recompilation."
50
+ exit 3
51
+ fi
52
+ fi
53
+
54
+ # Compilation should occur.
55
+ exit 0
package/bin/prepublish ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ ./bin/compile
6
+
7
+ date +%s > ./dist/.last-publish-time
@@ -0,0 +1,120 @@
1
+ #!/usr/bin/env node
2
+
3
+ const FS = require('fs');
4
+ const Path = require('path');
5
+
6
+ const JAVASCRIPT_EXTENSION = '.js';
7
+ const DECLARATION_EXTENSION = '.d.ts';
8
+ const UTF8_ENCODING = 'utf8';
9
+ const DIST_PATH = Path.resolve(__dirname, '../dist');
10
+
11
+ function processDirectory(directoryPath) {
12
+ const children = FS.readdirSync(directoryPath);
13
+
14
+ children.forEach(function each(child) {
15
+ // Ignore hidden files.
16
+ if (child[0] === '.') {
17
+ return;
18
+ }
19
+
20
+ const
21
+ childPath = Path.resolve(directoryPath, child),
22
+ parsedPath = Path.parse(childPath);
23
+
24
+ if (!parsedPath.ext) {
25
+ processDirectory(childPath);
26
+ } else if (parsedPath.ext === JAVASCRIPT_EXTENSION) {
27
+ processSourceFile(childPath);
28
+ } else if (childPath.slice(-5) === DECLARATION_EXTENSION) {
29
+ processDeclarationFile(childPath);
30
+ }
31
+ });
32
+ }
33
+
34
+ function processSourceFile(filePath) {
35
+ const contents = FS.readFileSync(filePath, UTF8_ENCODING);
36
+
37
+ const lines = contents.split('\n').map(function map(line) {
38
+ return line.replace(/require\("([^"]+)/g, function replacer(match, path) {
39
+ if (path[0] === '.') {
40
+ return match;
41
+ }
42
+
43
+ let dependencyPath = DIST_PATH + '/src/' + path + '.js';
44
+
45
+ if (!FS.existsSync(dependencyPath)) {
46
+ // Fall back to checking whether there's an index.js in a directory
47
+ // of this name, instead of a toplevel .js source file directly.
48
+ dependencyPath = DIST_PATH + '/src/' + path + '/index.js';
49
+
50
+ if (!FS.existsSync(dependencyPath)) {
51
+ // Well, we tried.
52
+ return match;
53
+ }
54
+ }
55
+
56
+ const parsedFile = Path.parse(filePath);
57
+ const parsedDependency = Path.parse(dependencyPath);
58
+
59
+ let relativeDirectory = Path.relative(parsedFile.dir, parsedDependency.dir);
60
+
61
+ if (relativeDirectory === '') {
62
+ relativeDirectory = '.';
63
+ } else {
64
+ relativeDirectory = './' + relativeDirectory;
65
+ }
66
+
67
+ const relativePath = relativeDirectory + '/' + parsedDependency.base;
68
+
69
+ return 'require("' + relativePath;
70
+ });
71
+ });
72
+
73
+ FS.writeFileSync(filePath, lines.join('\n'), UTF8_ENCODING);
74
+ }
75
+
76
+ function processDeclarationFile(filePath) {
77
+ const contents = FS.readFileSync(filePath, UTF8_ENCODING);
78
+
79
+ const lines = contents.split('\n').map(function map(line) {
80
+ return line.replace(/from '([^']+)/g, function replacer(match, path) {
81
+ if (path[0] === '.') {
82
+ return match;
83
+ }
84
+
85
+ let dependencyPath = DIST_PATH + '/src/' + path + '.d.ts';
86
+
87
+ if (!FS.existsSync(dependencyPath)) {
88
+ // Fall back to checking whether there's an index.js in a directory
89
+ // of this name, instead of a toplevel .d.ts source file directly.
90
+ dependencyPath = DIST_PATH + '/src/' + path + '/index.d.ts';
91
+
92
+ if (!FS.existsSync(dependencyPath)) {
93
+ // Well, we tried.
94
+ return match;
95
+ }
96
+ }
97
+
98
+ const parsedFile = Path.parse(filePath);
99
+ const parsedDependency = Path.parse(dependencyPath);
100
+
101
+ let relativeDirectory = Path.relative(parsedFile.dir, parsedDependency.dir);
102
+
103
+ if (relativeDirectory === '') {
104
+ relativeDirectory = '.';
105
+ } else {
106
+ relativeDirectory = './' + relativeDirectory;
107
+ }
108
+
109
+ let relativePath = relativeDirectory + '/' + parsedDependency.base;
110
+
111
+ relativePath = relativePath.replace(DECLARATION_EXTENSION, '');
112
+
113
+ return "from '" + relativePath;
114
+ });
115
+ });
116
+
117
+ FS.writeFileSync(filePath, lines.join('\n'), UTF8_ENCODING);
118
+ }
119
+
120
+ processDirectory('./dist', 0);
package/bin/test ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ bin/compile
6
+
7
+ # It's important that the glob be quoted so that the Node engine
8
+ # can evaluate it rather than it being done by the shell.
9
+ NODE_ENV=test node --test "dist/test/**/*.js"
package/bin/test-one ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ RED='\033[0;31m'
6
+ YELLOW='\033[0;33m'
7
+ RESET='\033[0m'
8
+
9
+ bin/compile
10
+
11
+ FILE_TO_TEST=$1
12
+
13
+ if [ -f "dist/$1.js" ]; then
14
+ TEST_FILEPATH="$FILE_TO_TEST.js"
15
+ else
16
+ # If someone enters the path to the corresponding Typescript file for a test,
17
+ # we should map this to the associated JS file in the dist/test directory:
18
+ FILE_WITH_CORRECTED_EXTENSION=${FILE_TO_TEST/.ts/.js}
19
+
20
+ if [ -f "dist/$FILE_WITH_CORRECTED_EXTENSION" ]; then
21
+ TEST_FILEPATH=$FILE_WITH_CORRECTED_EXTENSION
22
+ fi
23
+ fi
24
+
25
+ if [ -f "dist/$TEST_FILEPATH" ]; then
26
+ NODE_ENV=test node --test dist/$TEST_FILEPATH
27
+ else
28
+ echo ""
29
+ echo -e "${RED}[ERROR]${RESET} No test file(s) found matching '$1'"
30
+ echo -e "${YELLOW}Example:${RESET} dev test test/unit/logger"
31
+ echo ""
32
+ fi
package/dist/.keep ADDED
File without changes
@@ -0,0 +1 @@
1
+ 1764495321
@@ -0,0 +1 @@
1
+ 1764495336
@@ -0,0 +1,36 @@
1
+ import Net from 'net';
2
+ import { EventEmitter } from 'events';
3
+ import Logger from '@fc3/logger';
4
+ import { NetworkProtocol } from '@fc3/network';
5
+ import ServerOptions from './type/server-options';
6
+ declare abstract class Server extends EventEmitter {
7
+ private raw_server;
8
+ private options;
9
+ private status;
10
+ private logger;
11
+ constructor(options: ServerOptions, raw_server: Net.Server);
12
+ start(): Promise<void>;
13
+ stop(): Promise<void>;
14
+ setLogger(logger: Logger): void;
15
+ canStart(): boolean;
16
+ canStop(): boolean;
17
+ protected getConfig(): unknown;
18
+ protected getPort(): number;
19
+ protected getLabel(): string;
20
+ protected getLogger(): Logger;
21
+ protected getRawServer(): Net.Server;
22
+ protected getServerOptions(): ServerOptions;
23
+ private bindHandlersInternal;
24
+ private handleListening;
25
+ private handleError;
26
+ private handleClosed;
27
+ private validateCanStart;
28
+ private validateCanStop;
29
+ private isNotStarted;
30
+ private isStopped;
31
+ private getStatus;
32
+ private setStatus;
33
+ protected abstract bindHandlers(): void;
34
+ protected abstract getProtocol(): NetworkProtocol;
35
+ }
36
+ export default Server;
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const util_1 = __importDefault(require("util"));
7
+ const events_1 = require("events");
8
+ const logger_1 = __importDefault(require("@fc3/logger"));
9
+ const errors_1 = require("@fc3/errors");
10
+ const server_status_1 = __importDefault(require("./enum/server-status.js"));
11
+ class Server extends events_1.EventEmitter {
12
+ constructor(options, raw_server) {
13
+ super();
14
+ this.raw_server = raw_server;
15
+ this.status = server_status_1.default.NOT_STARTED;
16
+ this.options = options;
17
+ this.bindHandlersInternal();
18
+ }
19
+ async start() {
20
+ this.validateCanStart();
21
+ this.setStatus(server_status_1.default.STARTING);
22
+ const raw_server = this.getRawServer();
23
+ const logger = this.getLogger();
24
+ const port = this.getPort();
25
+ const protocol = this.getProtocol();
26
+ const label = this.getLabel();
27
+ raw_server.listen(port);
28
+ logger.info(`${label} ${protocol} server listening on port ${port}`);
29
+ }
30
+ async stop() {
31
+ const logger = this.getLogger();
32
+ const label = this.getLabel();
33
+ const protocol = this.getProtocol();
34
+ if (this.isNotStarted() || this.isStopped()) {
35
+ return void logger.warn(`
36
+ ${label} ${protocol} server was not running; skipping shutdown...
37
+ `);
38
+ }
39
+ logger.info(`Stopping ${label} ${protocol} server...`);
40
+ this.validateCanStop();
41
+ this.setStatus(server_status_1.default.STOPPING);
42
+ const raw_server = this.getRawServer();
43
+ const close = util_1.default.promisify(raw_server.close.bind(raw_server));
44
+ const promise = close();
45
+ await promise;
46
+ logger.info(`${label} ${protocol} server was stopped`);
47
+ }
48
+ setLogger(logger) {
49
+ this.logger = logger;
50
+ }
51
+ canStart() {
52
+ const status = this.getStatus();
53
+ return status === server_status_1.default.NOT_STARTED;
54
+ }
55
+ canStop() {
56
+ const status = this.getStatus();
57
+ switch (status) {
58
+ case server_status_1.default.STARTING:
59
+ case server_status_1.default.LISTENING:
60
+ return true;
61
+ default:
62
+ return false;
63
+ }
64
+ }
65
+ getConfig() {
66
+ const { config } = this.getServerOptions();
67
+ return config;
68
+ }
69
+ getPort() {
70
+ const { port } = this.getServerOptions();
71
+ return port;
72
+ }
73
+ getLabel() {
74
+ const { label } = this.getServerOptions();
75
+ return label;
76
+ }
77
+ getLogger() {
78
+ if (this.logger === undefined) {
79
+ this.logger = new logger_1.default();
80
+ }
81
+ return this.logger;
82
+ }
83
+ getRawServer() {
84
+ return this.raw_server;
85
+ }
86
+ getServerOptions() {
87
+ return this.options;
88
+ }
89
+ bindHandlersInternal() {
90
+ const raw_server = this.getRawServer();
91
+ raw_server.on('listening', this.handleListening.bind(this));
92
+ raw_server.on('error', this.handleError.bind(this));
93
+ raw_server.on('close', this.handleClosed.bind(this));
94
+ this.bindHandlers();
95
+ }
96
+ handleListening() {
97
+ this.setStatus(server_status_1.default.LISTENING);
98
+ }
99
+ handleError(error) {
100
+ const logger = this.getLogger();
101
+ logger.error(error);
102
+ }
103
+ handleClosed() {
104
+ this.setStatus(server_status_1.default.STOPPED);
105
+ }
106
+ validateCanStart() {
107
+ if (this.canStart()) {
108
+ return;
109
+ }
110
+ const status = this.getStatus();
111
+ throw new errors_1.GenericError(`Unable to start server in ${status} status`);
112
+ }
113
+ validateCanStop() {
114
+ if (this.canStop()) {
115
+ return;
116
+ }
117
+ const status = this.getStatus();
118
+ throw new errors_1.GenericError(`Unable to stop server in ${status} status`);
119
+ }
120
+ isNotStarted() {
121
+ const status = this.getStatus();
122
+ return status === server_status_1.default.NOT_STARTED;
123
+ }
124
+ isStopped() {
125
+ const status = this.getStatus();
126
+ return status === server_status_1.default.STOPPED;
127
+ }
128
+ getStatus() {
129
+ return this.status;
130
+ }
131
+ setStatus(status) {
132
+ this.status = status;
133
+ }
134
+ }
135
+ exports.default = Server;
136
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/base.ts"],"names":[],"mappings":";;;;;AACA,gDAAwB;AACxB,mCAAoC;AAEpC,yDAAiC;AACjC,wCAAyC;AAGzC,uEAA8C;AAG9C,MAAe,MAAO,SAAQ,qBAAY;IAMzC,YAAmB,OAAsB,EAAE,UAAsB;QAChE,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,uBAAY,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAC7B,CAAC;IAEM,KAAK,CAAC,KAAK;QACjB,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACxB,IAAI,CAAC,SAAS,CAAC,uBAAY,CAAC,QAAQ,CAAC,CAAC;QAEtC,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QACvC,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAChC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QACpC,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;QAE9B,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACxB,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK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ent;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var ServerEvent;
4
+ (function (ServerEvent) {
5
+ ServerEvent["CONNECTION"] = "connection";
6
+ })(ServerEvent || (ServerEvent = {}));
7
+ exports.default = ServerEvent;
8
+ //# sourceMappingURL=server-event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-event.js","sourceRoot":"","sources":["../../../src/enum/server-event.ts"],"names":[],"mappings":";;AAAA,IAAK,WAEJ;AAFD,WAAK,WAAW;IACf,wCAAyB,CAAA;AAC1B,CAAC,EAFI,WAAW,KAAX,WAAW,QAEf;AAED,kBAAe,WAAW,CAAC"}
@@ -0,0 +1,9 @@
1
+ declare enum ServerStatus {
2
+ NOT_STARTED = "not_started",
3
+ STARTING = "starting",
4
+ LISTENING = "listening",
5
+ STOPPING = "stopping",
6
+ STOPPED = "stopped",
7
+ CRASHED = "crashed"
8
+ }
9
+ export default ServerStatus;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var ServerStatus;
4
+ (function (ServerStatus) {
5
+ ServerStatus["NOT_STARTED"] = "not_started";
6
+ ServerStatus["STARTING"] = "starting";
7
+ ServerStatus["LISTENING"] = "listening";
8
+ ServerStatus["STOPPING"] = "stopping";
9
+ ServerStatus["STOPPED"] = "stopped";
10
+ ServerStatus["CRASHED"] = "crashed";
11
+ })(ServerStatus || (ServerStatus = {}));
12
+ exports.default = ServerStatus;
13
+ //# sourceMappingURL=server-status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-status.js","sourceRoot":"","sources":["../../../src/enum/server-status.ts"],"names":[],"mappings":";;AAAA,IAAK,YAOJ;AAPD,WAAK,YAAY;IAChB,2CAA2B,CAAA;IAC3B,qCAAqB,CAAA;IACrB,uCAAuB,CAAA;IACvB,qCAAqB,CAAA;IACrB,mCAAmB,CAAA;IACnB,mCAAmB,CAAA;AACpB,CAAC,EAPI,YAAY,KAAZ,YAAY,QAOhB;AAED,kBAAe,YAAY,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { HttpMethod, ContentType } from '@fc3/http';
2
+ import Endpoint from './../endpoint';
3
+ interface PingResult {
4
+ status: string;
5
+ }
6
+ declare class PingEndpoint extends Endpoint<unknown, PingResult> {
7
+ path: string;
8
+ method: HttpMethod;
9
+ content_types: ContentType[];
10
+ protected process(): Promise<PingResult>;
11
+ }
12
+ export default PingEndpoint;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const http_1 = require("@fc3/http");
7
+ const endpoint_1 = __importDefault(require("./../endpoint.js"));
8
+ class PingEndpoint extends endpoint_1.default {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.path = '/ping';
12
+ this.method = http_1.HttpMethod.GET;
13
+ this.content_types = [http_1.ContentType.JSON];
14
+ }
15
+ process() {
16
+ return Promise.resolve({
17
+ status: 'OK'
18
+ });
19
+ }
20
+ }
21
+ exports.default = PingEndpoint;
22
+ //# sourceMappingURL=ping.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ping.js","sourceRoot":"","sources":["../../../../src/http/endpoint/ping.ts"],"names":[],"mappings":";;;;;AAAA,oCAAkD;AAElD,6DAAqC;AAMrC,MAAM,YAAa,SAAQ,kBAA6B;IAAxD;;QACQ,SAAI,GAAG,OAAO,CAAC;QACf,WAAM,GAAG,iBAAU,CAAC,GAAG,CAAC;QACxB,kBAAa,GAAG,CAAC,kBAAW,CAAC,IAAI,CAAC,CAAC;IAO3C,CAAC;IALU,OAAO;QAChB,OAAO,OAAO,CAAC,OAAO,CAAC;YACtB,MAAM,EAAE,IAAI;SACZ,CAAC,CAAC;IACJ,CAAC;CACD;AAED,kBAAe,YAAY,CAAC"}
@@ -0,0 +1,47 @@
1
+ import HTTP from './../http';
2
+ import Logger from '@fc3/logger';
3
+ import ExecutionContext, { Session } from '@fc3/execution-context';
4
+ import { HttpMethod, StatusCode, ContentType, IncomingRequest, OutgoingResponse } from '@fc3/http';
5
+ import JsonResultSerializer from './result-serializer/json';
6
+ import HtmlResultSerializer from './result-serializer/html';
7
+ export type AllowedOutputs = string | Buffer | object;
8
+ declare abstract class Endpoint<Input, Output extends AllowedOutputs> {
9
+ private request;
10
+ private response;
11
+ private content_type;
12
+ abstract path: string;
13
+ abstract method: HttpMethod;
14
+ abstract content_types: ContentType[];
15
+ setRequest(request: IncomingRequest): void;
16
+ setResponse(response: OutgoingResponse): void;
17
+ serve(): Promise<void>;
18
+ protected getRequest(): IncomingRequest;
19
+ protected getNativeRequest(): HTTP.IncomingMessage;
20
+ protected getResponse(): OutgoingResponse;
21
+ protected getNativeResponse(): HTTP.ServerResponse;
22
+ protected getPathParameter(parameter: string): string;
23
+ protected getQueryParameter(parameter: string): string | string[] | undefined;
24
+ protected getNumericParameter(parameter: string, fallback?: number): number;
25
+ protected setStatusCode(status_code: StatusCode): void;
26
+ protected getRequestBody(): Input;
27
+ protected getLogger(): Logger;
28
+ protected getExecutionContext(): ExecutionContext;
29
+ protected applyCorsHeaders(request: IncomingRequest, response: OutgoingResponse): void;
30
+ protected getSessionId(): string;
31
+ protected setSession(session: Session): Session;
32
+ protected getSession(): Session;
33
+ protected getJsonResultSerializer(result: object): JsonResultSerializer<object>;
34
+ protected getHtmlResultSerializer(_result: object): HtmlResultSerializer<object> | Promise<HtmlResultSerializer<object>>;
35
+ protected authorize(): Promise<void>;
36
+ private serveInternal;
37
+ private serializeResult;
38
+ private getResultSerializer;
39
+ private parseBody;
40
+ private applyNecessaryHeaders;
41
+ private applyContentTypeHeader;
42
+ private getContentType;
43
+ private determineContentType;
44
+ private getContentTypes;
45
+ protected abstract process(): Promise<Output | void>;
46
+ }
47
+ export default Endpoint;