typed-bridge 2.0.6 → 2.0.8
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/dist/bridge/index.js +35 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/scripts/typedBridgeCleaner.js +19 -49
- package/package.json +1 -1
package/dist/bridge/index.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
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
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
@@ -8,7 +41,6 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
8
41
|
const compression_1 = __importDefault(require("compression"));
|
|
9
42
|
const cors_1 = __importDefault(require("cors"));
|
|
10
43
|
const express_1 = __importDefault(require("express"));
|
|
11
|
-
const path_1 = __importDefault(require("path"));
|
|
12
44
|
const __1 = require("..");
|
|
13
45
|
const helpers_1 = require("../helpers");
|
|
14
46
|
const middlewares = [];
|
|
@@ -73,9 +105,9 @@ const createBridge = (bridge, port, path = '/bridge') => {
|
|
|
73
105
|
setTimeout(next, __1.tbConfig.responseDelay);
|
|
74
106
|
});
|
|
75
107
|
// Server health
|
|
76
|
-
app.use(
|
|
108
|
+
Promise.resolve().then(() => __importStar(require('path'))).then(_path => app.use(_path.join(path, 'health'), (req, res) => {
|
|
77
109
|
res.sendStatus(200);
|
|
78
|
-
});
|
|
110
|
+
}));
|
|
79
111
|
app.use(path, bridgeHandler(bridge));
|
|
80
112
|
const server = app.listen(port, () => (0, helpers_1.printStartLogs)(port));
|
|
81
113
|
let shuttingDown = false;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'dotenv/config';
|
|
2
2
|
export { Application, default as express, Express, NextFunction, Request, Response, Router } from 'express';
|
|
3
|
-
export {
|
|
3
|
+
export { z as $z } from 'zod';
|
|
4
4
|
export { createBridge, createMiddleware, onShutdown } from './bridge';
|
|
5
5
|
export { config as tbConfig } from './config';
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var express_1 = require("express");
|
|
|
9
9
|
Object.defineProperty(exports, "express", { enumerable: true, get: function () { return __importDefault(express_1).default; } });
|
|
10
10
|
Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return express_1.Router; } });
|
|
11
11
|
var zod_1 = require("zod");
|
|
12
|
-
Object.defineProperty(exports, "$z", { enumerable: true, get: function () { return
|
|
12
|
+
Object.defineProperty(exports, "$z", { enumerable: true, get: function () { return zod_1.z; } });
|
|
13
13
|
var bridge_1 = require("./bridge");
|
|
14
14
|
Object.defineProperty(exports, "createBridge", { enumerable: true, get: function () { return bridge_1.createBridge; } });
|
|
15
15
|
Object.defineProperty(exports, "createMiddleware", { enumerable: true, get: function () { return bridge_1.createMiddleware; } });
|
|
@@ -1,42 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
})();
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
35
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
6
|
exports.default = cleanTsFile;
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
40
10
|
// Snippet to inject at the end
|
|
41
11
|
const proxySnippet = () => `
|
|
42
12
|
type typedBridgeConfig = {
|
|
@@ -90,12 +60,12 @@ export default typedBridge
|
|
|
90
60
|
const removeSecondParamTransformer = context => {
|
|
91
61
|
return sourceFile => {
|
|
92
62
|
function visitor(node) {
|
|
93
|
-
if (
|
|
94
|
-
return
|
|
63
|
+
if (typescript_1.default.isFunctionTypeNode(node) && node.parameters.length > 1) {
|
|
64
|
+
return typescript_1.default.factory.updateFunctionTypeNode(node, node.typeParameters, typescript_1.default.factory.createNodeArray([node.parameters[0]]), node.type);
|
|
95
65
|
}
|
|
96
|
-
return
|
|
66
|
+
return typescript_1.default.visitEachChild(node, visitor, context);
|
|
97
67
|
}
|
|
98
|
-
return
|
|
68
|
+
return typescript_1.default.visitEachChild(sourceFile, visitor, context);
|
|
99
69
|
};
|
|
100
70
|
};
|
|
101
71
|
/**
|
|
@@ -106,7 +76,7 @@ const removeDefaultExportTransformer = context => {
|
|
|
106
76
|
return sourceFile => {
|
|
107
77
|
function visitor(node) {
|
|
108
78
|
// Look for `export { _default as default }` and drop it
|
|
109
|
-
if (
|
|
79
|
+
if (typescript_1.default.isExportDeclaration(node) && node.exportClause && typescript_1.default.isNamedExports(node.exportClause)) {
|
|
110
80
|
const [el] = node.exportClause.elements;
|
|
111
81
|
if (node.exportClause.elements.length === 1 &&
|
|
112
82
|
el.propertyName?.text === '_default' &&
|
|
@@ -114,15 +84,15 @@ const removeDefaultExportTransformer = context => {
|
|
|
114
84
|
return undefined;
|
|
115
85
|
}
|
|
116
86
|
}
|
|
117
|
-
return
|
|
87
|
+
return typescript_1.default.visitEachChild(node, visitor, context);
|
|
118
88
|
}
|
|
119
89
|
const updatedStatements = [];
|
|
120
90
|
for (const stmt of sourceFile.statements) {
|
|
121
|
-
const newStmt =
|
|
91
|
+
const newStmt = typescript_1.default.visitNode(stmt, visitor);
|
|
122
92
|
if (newStmt)
|
|
123
93
|
updatedStatements.push(newStmt);
|
|
124
94
|
}
|
|
125
|
-
return
|
|
95
|
+
return typescript_1.default.factory.updateSourceFile(sourceFile, typescript_1.default.factory.createNodeArray(updatedStatements));
|
|
126
96
|
};
|
|
127
97
|
};
|
|
128
98
|
/**
|
|
@@ -132,20 +102,20 @@ const removeDefaultExportTransformer = context => {
|
|
|
132
102
|
* 3. Writes the final file output.
|
|
133
103
|
*/
|
|
134
104
|
function cleanTsFile(src) {
|
|
135
|
-
let sourceCode =
|
|
105
|
+
let sourceCode = fs_1.default.readFileSync(src, 'utf-8');
|
|
136
106
|
const eslintDisable = `/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any */`;
|
|
137
107
|
// Ensure the top comment is present if missing
|
|
138
108
|
if (!sourceCode.startsWith(eslintDisable)) {
|
|
139
109
|
sourceCode = eslintDisable + '\n' + sourceCode;
|
|
140
110
|
}
|
|
141
111
|
// Parse the source
|
|
142
|
-
const sourceFile =
|
|
112
|
+
const sourceFile = typescript_1.default.createSourceFile(path_1.default.basename(src), sourceCode, typescript_1.default.ScriptTarget.Latest, true, typescript_1.default.ScriptKind.TS);
|
|
143
113
|
// Run the transformers
|
|
144
|
-
const result =
|
|
114
|
+
const result = typescript_1.default.transform(sourceFile, [removeSecondParamTransformer, removeDefaultExportTransformer]);
|
|
145
115
|
// Print final code
|
|
146
|
-
const printer =
|
|
116
|
+
const printer = typescript_1.default.createPrinter();
|
|
147
117
|
const transformedCode = printer.printFile(result.transformed[0]).concat(proxySnippet());
|
|
148
118
|
// Write back to the same file
|
|
149
|
-
|
|
119
|
+
fs_1.default.writeFileSync(src, transformedCode, 'utf-8');
|
|
150
120
|
console.log(`Cleaned file: ${src}`);
|
|
151
121
|
}
|