@seam-rpc/server 1.0.3 → 1.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.
- package/package.json +41 -40
- package/dist/bin/bin.d.ts +0 -2
- package/dist/bin/bin.js +0 -19
- package/dist/bin/gen-client.js +0 -122
- package/dist/bin/gen-config.js +0 -55
- package/dist/bin/index.js +0 -19
- package/dist/index.js +0 -141
package/package.json
CHANGED
|
@@ -1,40 +1,41 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@seam-rpc/server",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"main": "dist/index.js",
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"@types/
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@seam-rpc/server",
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"seam-rpc": "dist/bin/index.js"
|
|
8
|
+
},
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [],
|
|
17
|
+
"author": "Daniel Clímaco",
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"description": "",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/DanielC49/seam-rpc.git",
|
|
23
|
+
"directory": "packages/client"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/DanielC49/seam-rpc#readme",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/DanielC49/seam-rpc/issues"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/express": "^5.0.3",
|
|
31
|
+
"@types/node": "^24.3.1",
|
|
32
|
+
"express": "^5.1.0",
|
|
33
|
+
"multer": "^2.0.2"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@seam-rpc/core": "^1.0.0",
|
|
37
|
+
"fast-glob": "^3.3.3",
|
|
38
|
+
"form-data": "^4.0.5",
|
|
39
|
+
"typescript": "^5.9.3"
|
|
40
|
+
}
|
|
41
|
+
}
|
package/dist/bin/bin.d.ts
DELETED
package/dist/bin/bin.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const gen_client_1 = require("./gen-client");
|
|
5
|
-
const gen_config_1 = require("./gen-config");
|
|
6
|
-
main();
|
|
7
|
-
function main() {
|
|
8
|
-
const args = process.argv;
|
|
9
|
-
switch (args[3]) {
|
|
10
|
-
case "gen-client":
|
|
11
|
-
(0, gen_client_1.genClient)();
|
|
12
|
-
break;
|
|
13
|
-
case "gen-config":
|
|
14
|
-
(0, gen_config_1.genConfig)();
|
|
15
|
-
break;
|
|
16
|
-
default:
|
|
17
|
-
console.log("Commands:\n- seam-rpc gen-client <input-files> [output-folder]\n- seam-rpc gen-config [input-files] [output-folder]");
|
|
18
|
-
}
|
|
19
|
-
}
|
package/dist/bin/gen-client.js
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.genClient = genClient;
|
|
16
|
-
const fs_1 = __importDefault(require("fs"));
|
|
17
|
-
const typescript_1 = __importDefault(require("typescript"));
|
|
18
|
-
const path_1 = __importDefault(require("path"));
|
|
19
|
-
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
20
|
-
function genClient() {
|
|
21
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
const args = process.argv;
|
|
23
|
-
let config;
|
|
24
|
-
if (args.length == 3) {
|
|
25
|
-
if (!fs_1.default.existsSync("./seam-rpc.config.json"))
|
|
26
|
-
return console.error("\x1b[31mCommand arguments omitted and no config file found.\x1b[0m\n"
|
|
27
|
-
+ "Either define a config file with \x1b[36mseam-rpc gen-config\x1b[0m or generate the client files using \x1b[36mseam-rpc gen-client <input-files> <output-folder> [global-types-file]\x1b[0m.");
|
|
28
|
-
config = JSON.parse(fs_1.default.readFileSync("./seam-rpc.config.json", "utf-8"));
|
|
29
|
-
}
|
|
30
|
-
else if (args.length == 5 || args.length == 6) {
|
|
31
|
-
config = {
|
|
32
|
-
inputFiles: args[3],
|
|
33
|
-
outputFolder: args[4]
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
return console.error("Usage: seam-rpc gen-client <input-files> <output-folder>");
|
|
38
|
-
}
|
|
39
|
-
const inputFiles = yield (0, fast_glob_1.default)(config.inputFiles);
|
|
40
|
-
const outputPath = path_1.default.resolve(config.outputFolder);
|
|
41
|
-
const rootPath = path_1.default.resolve(".");
|
|
42
|
-
try {
|
|
43
|
-
const outputFiles = [];
|
|
44
|
-
for (const inputFile of inputFiles) {
|
|
45
|
-
const outputFile = generateClientFile(inputFile, outputPath);
|
|
46
|
-
outputFiles.push(removeRootPath(outputFile, rootPath));
|
|
47
|
-
}
|
|
48
|
-
console.log("\x1b[32m%s\x1b[0m\n\x1b[36m%s\x1b[0m", `✅ Successfully generated client files at ${removeRootPath(outputPath, rootPath)}`, `${outputFiles.join("\n")}`);
|
|
49
|
-
}
|
|
50
|
-
catch (err) {
|
|
51
|
-
console.error("❌ Failed to generate client file:", err.message);
|
|
52
|
-
process.exit(1);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
function removeRootPath(path, rootPath) {
|
|
57
|
-
return "." + path.slice(rootPath.length);
|
|
58
|
-
}
|
|
59
|
-
function generateClientFile(inputFile, outputPath) {
|
|
60
|
-
const file = path_1.default.resolve(process.cwd(), inputFile);
|
|
61
|
-
if (!fs_1.default.existsSync(file)) {
|
|
62
|
-
console.error(`File ${file} not found`);
|
|
63
|
-
process.exit(1);
|
|
64
|
-
}
|
|
65
|
-
const imports = ["import { callApi, SeamFile, ISeamFile } from \"@seam-rpc/client\";"];
|
|
66
|
-
const apiDef = [];
|
|
67
|
-
const typeDefs = [];
|
|
68
|
-
const routerName = path_1.default.basename(file, path_1.default.extname(file));
|
|
69
|
-
const fileContent = fs_1.default.readFileSync(file, "utf-8");
|
|
70
|
-
const sourceFile = typescript_1.default.createSourceFile(file, fileContent, typescript_1.default.ScriptTarget.Latest, true, typescript_1.default.ScriptKind.TS);
|
|
71
|
-
typescript_1.default.forEachChild(sourceFile, (node) => {
|
|
72
|
-
var _a, _b;
|
|
73
|
-
if (typescript_1.default.isImportDeclaration(node)) {
|
|
74
|
-
const moduleSpecifier = node.moduleSpecifier.getText().replace(/['"]/g, "");
|
|
75
|
-
if (moduleSpecifier.startsWith("./"))
|
|
76
|
-
imports.push(node.getText());
|
|
77
|
-
}
|
|
78
|
-
else if (typescript_1.default.isFunctionDeclaration(node) && hasExportModifier(node)) {
|
|
79
|
-
if (!node.name) {
|
|
80
|
-
console.error("Missing function name.");
|
|
81
|
-
process.exit(1);
|
|
82
|
-
}
|
|
83
|
-
const funcName = node.name.getText();
|
|
84
|
-
const jsDoc = typescript_1.default.getJSDocCommentsAndTags(node).map(e => e.getFullText()).filter(Boolean).join("\n");
|
|
85
|
-
let signature = `${jsDoc}\nexport function ${funcName}(`;
|
|
86
|
-
const paramsText = node.parameters
|
|
87
|
-
.map((p) => {
|
|
88
|
-
const paramName = p.name.getText();
|
|
89
|
-
const optional = p.questionToken ? "?" : "";
|
|
90
|
-
const type = p.type ? p.type.getText() : "any";
|
|
91
|
-
return `${paramName}${optional}: ${type}`;
|
|
92
|
-
})
|
|
93
|
-
.join(", ");
|
|
94
|
-
const returnTypeText = (_b = (_a = node.type) === null || _a === void 0 ? void 0 : _a.getText()) !== null && _b !== void 0 ? _b : "any";
|
|
95
|
-
const finalReturnType = returnTypeText.startsWith("Promise<")
|
|
96
|
-
? returnTypeText
|
|
97
|
-
: `Promise<${returnTypeText}>`;
|
|
98
|
-
signature += `${paramsText}): ${finalReturnType} { return callApi("${routerName}", "${funcName}", [${node.parameters.map(e => e.name.getText()).join(", ")}]); }`;
|
|
99
|
-
apiDef.push(signature);
|
|
100
|
-
}
|
|
101
|
-
else if ((typescript_1.default.isInterfaceDeclaration(node) ||
|
|
102
|
-
typescript_1.default.isTypeAliasDeclaration(node) ||
|
|
103
|
-
typescript_1.default.isEnumDeclaration(node))
|
|
104
|
-
&& hasExportModifier(node)) {
|
|
105
|
-
const text = node.getFullText(sourceFile).trim();
|
|
106
|
-
typeDefs.push(text);
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
const content = [imports.join("\n"), typeDefs.join("\n"), apiDef.join("\n")].join("\n");
|
|
110
|
-
fs_1.default.writeFileSync(path_1.default.resolve(outputPath, path_1.default.basename(file)), content, "utf-8");
|
|
111
|
-
return file;
|
|
112
|
-
}
|
|
113
|
-
function hasExportModifier(node) {
|
|
114
|
-
var _a;
|
|
115
|
-
if (typescript_1.default.isVariableStatement(node) ||
|
|
116
|
-
typescript_1.default.isFunctionDeclaration(node) ||
|
|
117
|
-
typescript_1.default.isClassDeclaration(node) ||
|
|
118
|
-
typescript_1.default.isInterfaceDeclaration(node)) {
|
|
119
|
-
return !!((_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.some((m) => m.kind === typescript_1.default.SyntaxKind.ExportKeyword));
|
|
120
|
-
}
|
|
121
|
-
return false;
|
|
122
|
-
}
|
package/dist/bin/gen-config.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.genConfig = genConfig;
|
|
16
|
-
const fs_1 = __importDefault(require("fs"));
|
|
17
|
-
const readline_1 = __importDefault(require("readline"));
|
|
18
|
-
function genConfig() {
|
|
19
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
const args = process.argv;
|
|
21
|
-
let inputFiles = "./src/api/*";
|
|
22
|
-
let outputFolder = "../client/src/api";
|
|
23
|
-
if (args.length == 5) {
|
|
24
|
-
inputFiles = args[3];
|
|
25
|
-
outputFolder = args[4];
|
|
26
|
-
}
|
|
27
|
-
else if (args.length > 3) {
|
|
28
|
-
return console.error("Usage: seam-rpc gen-config [input-files] [output-folder]");
|
|
29
|
-
}
|
|
30
|
-
if (fs_1.default.existsSync("./seam-rpc.config.json")) {
|
|
31
|
-
const rl = readline_1.default.createInterface({
|
|
32
|
-
input: process.stdin,
|
|
33
|
-
output: process.stdout,
|
|
34
|
-
});
|
|
35
|
-
rl.question("Config file already exists. Do you want to overwrite it? [Y/n] ", answer => {
|
|
36
|
-
if (answer && answer.toLowerCase() != "y" && answer.toLowerCase() != "yes") {
|
|
37
|
-
console.log("Operation canceled.");
|
|
38
|
-
process.exit(0);
|
|
39
|
-
}
|
|
40
|
-
rl.close();
|
|
41
|
-
const config = {
|
|
42
|
-
inputFiles,
|
|
43
|
-
outputFolder
|
|
44
|
-
};
|
|
45
|
-
try {
|
|
46
|
-
fs_1.default.writeFileSync("./seam-rpc.config.json", JSON.stringify(config, null, 4), "utf-8");
|
|
47
|
-
}
|
|
48
|
-
catch (e) {
|
|
49
|
-
console.log("\x1b[31mFailed to generate config file ./seam-rpc.config.json\x1b[0m\n" + e);
|
|
50
|
-
}
|
|
51
|
-
console.log(`\x1b[32mSuccessfully generated config file ./seam-rpc.config.json\x1b[0m`);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}
|
package/dist/bin/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const gen_client_1 = require("./gen-client");
|
|
5
|
-
const gen_config_1 = require("./gen-config");
|
|
6
|
-
main();
|
|
7
|
-
function main() {
|
|
8
|
-
const args = process.argv;
|
|
9
|
-
switch (args[2]) {
|
|
10
|
-
case "gen-client":
|
|
11
|
-
(0, gen_client_1.genClient)();
|
|
12
|
-
break;
|
|
13
|
-
case "gen-config":
|
|
14
|
-
(0, gen_config_1.genConfig)();
|
|
15
|
-
break;
|
|
16
|
-
default:
|
|
17
|
-
console.log("Commands:\n- seam-rpc gen-client <input-files> <output-folder>\n- seam-rpc gen-config [input-files] [output-folder]");
|
|
18
|
-
}
|
|
19
|
-
}
|
package/dist/index.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
-
};
|
|
47
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.SeamSpace = exports.SeamFile = void 0;
|
|
49
|
-
exports.createSeamSpace = createSeamSpace;
|
|
50
|
-
const core_1 = require("@seam-rpc/core");
|
|
51
|
-
Object.defineProperty(exports, "SeamFile", { enumerable: true, get: function () { return core_1.SeamFile; } });
|
|
52
|
-
const express_1 = __importStar(require("express"));
|
|
53
|
-
const form_data_1 = __importDefault(require("form-data"));
|
|
54
|
-
;
|
|
55
|
-
function createSeamSpace(app, fileHandler) {
|
|
56
|
-
if (!fileHandler) {
|
|
57
|
-
let multer;
|
|
58
|
-
try {
|
|
59
|
-
multer = require("multer");
|
|
60
|
-
}
|
|
61
|
-
catch (_a) {
|
|
62
|
-
throw new Error("Multer is required as default file handler. Install it or provide a custom fileHandler.");
|
|
63
|
-
}
|
|
64
|
-
const upload = multer();
|
|
65
|
-
fileHandler = upload.any();
|
|
66
|
-
}
|
|
67
|
-
return new SeamSpace(app, fileHandler);
|
|
68
|
-
}
|
|
69
|
-
class SeamSpace {
|
|
70
|
-
constructor(app, fileHandler) {
|
|
71
|
-
this.app = app;
|
|
72
|
-
this.fileHandler = fileHandler;
|
|
73
|
-
this.jsonParser = express_1.default.json();
|
|
74
|
-
}
|
|
75
|
-
createRouter(path, routerDefinition) {
|
|
76
|
-
const router = (0, express_1.Router)();
|
|
77
|
-
router.post("/:funcName", (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
var _a;
|
|
79
|
-
if (!(req.params.funcName in routerDefinition))
|
|
80
|
-
return res.sendStatus(404);
|
|
81
|
-
const contentType = req.headers["content-type"] || "";
|
|
82
|
-
const runMiddleware = (middleware) => new Promise((resolve, reject) => middleware(req, res, err => (err ? reject(err) : resolve())));
|
|
83
|
-
if (contentType.startsWith("application/json")) {
|
|
84
|
-
yield runMiddleware(this.jsonParser);
|
|
85
|
-
}
|
|
86
|
-
else if (contentType.startsWith("multipart/form-data")) {
|
|
87
|
-
yield runMiddleware(this.fileHandler);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
return res.status(415).send("Unsupported content type");
|
|
91
|
-
}
|
|
92
|
-
let args;
|
|
93
|
-
if (contentType.startsWith("application/json")) {
|
|
94
|
-
args = req.body;
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
// multipart/form-data
|
|
98
|
-
args = JSON.parse(req.body.json);
|
|
99
|
-
const paths = JSON.parse(req.body.paths);
|
|
100
|
-
const files = ((_a = req.files) !== null && _a !== void 0 ? _a : []).map((file, index) => ({
|
|
101
|
-
path: paths[index],
|
|
102
|
-
file: new core_1.SeamFile(file.buffer, file.originalname, file.mimetype),
|
|
103
|
-
}));
|
|
104
|
-
(0, core_1.injectFiles)(args, files);
|
|
105
|
-
}
|
|
106
|
-
let result;
|
|
107
|
-
try {
|
|
108
|
-
result = yield routerDefinition[req.params.funcName](...args);
|
|
109
|
-
}
|
|
110
|
-
catch (error) {
|
|
111
|
-
console.error(`Error at API function at router "${path}". Sent error to client.`, error);
|
|
112
|
-
res.status(400).send({ error: String(error) });
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
try {
|
|
116
|
-
const { json, files, paths } = (0, core_1.extractFiles)({ result });
|
|
117
|
-
if (files.length === 0) {
|
|
118
|
-
res.json(json);
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
const form = new form_data_1.default();
|
|
122
|
-
form.append("json", JSON.stringify(json));
|
|
123
|
-
form.append("paths", JSON.stringify(paths));
|
|
124
|
-
files.forEach((file, i) => {
|
|
125
|
-
form.append(`file-${i}`, Buffer.from(file.data), {
|
|
126
|
-
filename: file.fileName || `file-${i}`,
|
|
127
|
-
contentType: file.mimeType || "application/octet-stream",
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
res.writeHead(200, form.getHeaders());
|
|
131
|
-
form.pipe(res);
|
|
132
|
-
}
|
|
133
|
-
catch (error) {
|
|
134
|
-
console.error(`Internal error at API function at router "${path}". Returned 500 Internal Server Error to client.`, error);
|
|
135
|
-
res.status(500).send({ error: String(error) });
|
|
136
|
-
}
|
|
137
|
-
}));
|
|
138
|
-
this.app.use(path, router);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
exports.SeamSpace = SeamSpace;
|