polyapi 0.16.16 → 0.17.0
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/build/client/src/api.d.ts +9 -3
- package/build/client/src/api.d.ts.map +1 -1
- package/build/client/src/api.js +57 -3
- package/build/client/src/api.js.map +1 -1
- package/build/client/src/cli.js +40 -0
- package/build/client/src/cli.js.map +1 -1
- package/build/client/src/commands/function.d.ts.map +1 -1
- package/build/client/src/commands/function.js +5 -250
- package/build/client/src/commands/function.js.map +1 -1
- package/build/client/src/commands/generate.d.ts +2 -0
- package/build/client/src/commands/generate.d.ts.map +1 -1
- package/build/client/src/commands/generate.js +4 -3
- package/build/client/src/commands/generate.js.map +1 -1
- package/build/client/src/commands/prepare.d.ts +2 -0
- package/build/client/src/commands/prepare.d.ts.map +1 -0
- package/build/client/src/commands/prepare.js +94 -0
- package/build/client/src/commands/prepare.js.map +1 -0
- package/build/client/src/commands/setup.d.ts.map +1 -1
- package/build/client/src/commands/setup.js +1 -0
- package/build/client/src/commands/setup.js.map +1 -1
- package/build/client/src/commands/snippet.d.ts.map +1 -1
- package/build/client/src/commands/snippet.js +2 -1
- package/build/client/src/commands/snippet.js.map +1 -1
- package/build/client/src/commands/sync.d.ts +2 -0
- package/build/client/src/commands/sync.d.ts.map +1 -0
- package/build/client/src/commands/sync.js +108 -0
- package/build/client/src/commands/sync.js.map +1 -0
- package/build/client/src/deployables.d.ts +82 -0
- package/build/client/src/deployables.d.ts.map +1 -0
- package/build/client/src/deployables.js +185 -0
- package/build/client/src/deployables.js.map +1 -0
- package/build/client/src/transpiler.d.ts +10 -0
- package/build/client/src/transpiler.d.ts.map +1 -0
- package/build/client/src/transpiler.js +460 -0
- package/build/client/src/transpiler.js.map +1 -0
- package/build/model/src/dto/activity/activity-detail.dto.d.ts +13 -0
- package/build/model/src/dto/activity/activity-detail.dto.d.ts.map +1 -0
- package/build/model/src/dto/activity/activity-detail.dto.js +7 -0
- package/build/model/src/dto/activity/activity-detail.dto.js.map +1 -0
- package/build/model/src/dto/activity/activity-list.dto.d.ts +12 -0
- package/build/model/src/dto/activity/activity-list.dto.d.ts.map +1 -0
- package/build/model/src/dto/activity/activity-list.dto.js +7 -0
- package/build/model/src/dto/activity/activity-list.dto.js.map +1 -0
- package/build/model/src/dto/activity/index.d.ts +3 -0
- package/build/model/src/dto/activity/index.d.ts.map +1 -0
- package/build/model/src/dto/activity/index.js +19 -0
- package/build/model/src/dto/activity/index.js.map +1 -0
- package/build/model/src/dto/auth-provider/auth-provider.dto.d.ts +6 -0
- package/build/model/src/dto/auth-provider/auth-provider.dto.d.ts.map +1 -1
- package/build/model/src/dto/auth-provider/auth-provider.dto.js +7 -1
- package/build/model/src/dto/auth-provider/auth-provider.dto.js.map +1 -1
- package/build/model/src/dto/environment/create-environment.dto.d.ts +1 -0
- package/build/model/src/dto/environment/create-environment.dto.d.ts.map +1 -1
- package/build/model/src/dto/environment/create-environment.dto.js +8 -0
- package/build/model/src/dto/environment/create-environment.dto.js.map +1 -1
- package/build/model/src/dto/environment/environment.dto.d.ts +1 -0
- package/build/model/src/dto/environment/environment.dto.d.ts.map +1 -1
- package/build/model/src/dto/environment/environment.dto.js.map +1 -1
- package/build/model/src/dto/environment/update-environment.dto.d.ts +2 -1
- package/build/model/src/dto/environment/update-environment.dto.d.ts.map +1 -1
- package/build/model/src/dto/environment/update-environment.dto.js +6 -0
- package/build/model/src/dto/environment/update-environment.dto.js.map +1 -1
- package/build/model/src/dto/function/{execute-api-function-description-generation.dto.d.ts → execute-function-description-generation.dto.d.ts} +7 -1
- package/build/model/src/dto/function/execute-function-description-generation.dto.d.ts.map +1 -0
- package/build/model/src/dto/function/{execute-api-function-description-generation.dto.js → execute-function-description-generation.dto.js} +23 -2
- package/build/model/src/dto/function/execute-function-description-generation.dto.js.map +1 -0
- package/build/model/src/dto/function/function-description-generation.dto.d.ts +15 -0
- package/build/model/src/dto/function/function-description-generation.dto.d.ts.map +1 -0
- package/build/model/src/dto/function/function-description-generation.dto.js +10 -0
- package/build/model/src/dto/function/function-description-generation.dto.js.map +1 -0
- package/build/model/src/dto/function/function.dto.d.ts +11 -2
- package/build/model/src/dto/function/function.dto.d.ts.map +1 -1
- package/build/model/src/dto/function/function.dto.js +11 -1
- package/build/model/src/dto/function/function.dto.js.map +1 -1
- package/build/model/src/dto/function/index.d.ts +2 -2
- package/build/model/src/dto/function/index.d.ts.map +1 -1
- package/build/model/src/dto/function/index.js +2 -2
- package/build/model/src/dto/function/index.js.map +1 -1
- package/build/model/src/dto/index.d.ts +1 -0
- package/build/model/src/dto/index.d.ts.map +1 -1
- package/build/model/src/dto/index.js +1 -0
- package/build/model/src/dto/index.js.map +1 -1
- package/build/model/src/dto/snippet/snippet-details.dto.d.ts +7 -0
- package/build/model/src/dto/snippet/snippet-details.dto.d.ts.map +1 -1
- package/build/model/src/dto/snippet/snippet-details.dto.js +7 -1
- package/build/model/src/dto/snippet/snippet-details.dto.js.map +1 -1
- package/build/model/src/dto/snippet/snippet.dto.d.ts +8 -0
- package/build/model/src/dto/snippet/snippet.dto.d.ts.map +1 -1
- package/build/model/src/dto/snippet/snippet.dto.js +7 -1
- package/build/model/src/dto/snippet/snippet.dto.js.map +1 -1
- package/build/model/src/dto/snippet/update-snippet.dto.d.ts +1 -0
- package/build/model/src/dto/snippet/update-snippet.dto.d.ts.map +1 -1
- package/build/model/src/dto/snippet/update-snippet.dto.js +5 -0
- package/build/model/src/dto/snippet/update-snippet.dto.js.map +1 -1
- package/build/model/src/dto/specification-input/specification-input.dto.d.ts +5 -1
- package/build/model/src/dto/specification-input/specification-input.dto.d.ts.map +1 -1
- package/build/model/src/dto/specification-input/specification-input.dto.js +3 -0
- package/build/model/src/dto/specification-input/specification-input.dto.js.map +1 -1
- package/build/model/src/dto/trigger/create-trigger.dto.d.ts.map +1 -1
- package/build/model/src/dto/trigger/create-trigger.dto.js +3 -1
- package/build/model/src/dto/trigger/create-trigger.dto.js.map +1 -1
- package/build/model/src/dto/trigger/trigger.dto.d.ts +7 -0
- package/build/model/src/dto/trigger/trigger.dto.d.ts.map +1 -1
- package/build/model/src/dto/trigger/trigger.dto.js +51 -1
- package/build/model/src/dto/trigger/trigger.dto.js.map +1 -1
- package/build/model/src/dto/variable/variable.dto.d.ts +6 -0
- package/build/model/src/dto/variable/variable.dto.d.ts.map +1 -1
- package/build/model/src/dto/variable/variable.dto.js +7 -1
- package/build/model/src/dto/variable/variable.dto.js.map +1 -1
- package/build/model/src/dto/webhook/create-webhook-handle.dto.d.ts +7 -2
- package/build/model/src/dto/webhook/create-webhook-handle.dto.d.ts.map +1 -1
- package/build/model/src/dto/webhook/create-webhook-handle.dto.js +31 -7
- package/build/model/src/dto/webhook/create-webhook-handle.dto.js.map +1 -1
- package/build/model/src/dto/webhook/train-webhook-handle.dto.d.ts +3 -25
- package/build/model/src/dto/webhook/train-webhook-handle.dto.d.ts.map +1 -1
- package/build/model/src/dto/webhook/train-webhook-handle.dto.js +3 -102
- package/build/model/src/dto/webhook/train-webhook-handle.dto.js.map +1 -1
- package/build/model/src/dto/webhook/update-webhook-handle.dto.d.ts +1 -1
- package/build/model/src/dto/webhook/update-webhook-handle.dto.d.ts.map +1 -1
- package/build/model/src/dto/webhook/update-webhook-handle.dto.js +2 -2
- package/build/model/src/dto/webhook/update-webhook-handle.dto.js.map +1 -1
- package/build/model/src/dto/webhook/webhook-handle.dto.d.ts +7 -1
- package/build/model/src/dto/webhook/webhook-handle.dto.d.ts.map +1 -1
- package/build/model/src/dto/webhook/webhook-handle.dto.js +7 -1
- package/build/model/src/dto/webhook/webhook-handle.dto.js.map +1 -1
- package/build/model/src/specs.d.ts +3 -1
- package/build/model/src/specs.d.ts.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/index.d.ts +1 -0
- package/package.json +1 -1
- package/build/model/src/dto/function/api-function-description-generation.dto.d.ts +0 -9
- package/build/model/src/dto/function/api-function-description-generation.dto.d.ts.map +0 -1
- package/build/model/src/dto/function/api-function-description-generation.dto.js +0 -7
- package/build/model/src/dto/function/api-function-description-generation.dto.js.map +0 -1
- package/build/model/src/dto/function/execute-api-function-description-generation.dto.d.ts.map +0 -1
- package/build/model/src/dto/function/execute-api-function-description-generation.dto.js.map +0 -1
|
@@ -0,0 +1,185 @@
|
|
|
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
|
+
exports.writeUpdatedDeployable = exports.writeDeployComments = exports.isCacheUpToDate = exports.writeCacheRevision = exports.getCacheDeploymentsRevision = exports.getGitRevision = exports.getAllDeployableFiles = exports.getAllDeployableFilesLinux = exports.getAllDeployableFilesWindows = exports.removeDeployableRecords = exports.saveDeployableRecords = exports.loadDeployableRecords = exports.DeployableTsTypeToName = exports.DeployableTypeEntries = exports.CACHE_DIR = exports.CACHE_VERSION_FILE = void 0;
|
|
7
|
+
const os_1 = __importDefault(require("os"));
|
|
8
|
+
const promises_1 = require("node:fs/promises");
|
|
9
|
+
const shelljs_1 = __importDefault(require("shelljs"));
|
|
10
|
+
const child_process_1 = require("child_process");
|
|
11
|
+
exports.CACHE_VERSION_FILE = './node_modules/.poly/deployments_revision';
|
|
12
|
+
exports.CACHE_DIR = './node_modules/.poly/deployables';
|
|
13
|
+
exports.DeployableTypeEntries = [];
|
|
14
|
+
exports.DeployableTypeEntries.push(['PolyServerFunction', 'server-function']);
|
|
15
|
+
exports.DeployableTypeEntries.push(['PolyClientFunction', 'client-function']);
|
|
16
|
+
exports.DeployableTsTypeToName = Object.fromEntries(exports.DeployableTypeEntries);
|
|
17
|
+
const loadDeployableRecords = async () => {
|
|
18
|
+
const cachedRecords = (await (0, promises_1.readdir)(exports.CACHE_DIR, { withFileTypes: true }))
|
|
19
|
+
.filter(d => d.isFile() && d.name.endsWith('.json'))
|
|
20
|
+
.map(d => d.name);
|
|
21
|
+
return Promise.all(cachedRecords.map(name => readJsonFile(`${exports.CACHE_DIR}/${name}`)));
|
|
22
|
+
};
|
|
23
|
+
exports.loadDeployableRecords = loadDeployableRecords;
|
|
24
|
+
const saveDeployableRecords = async (records) => {
|
|
25
|
+
await Promise.all(records.map(record => writeJsonFile(`${exports.CACHE_DIR}/${record.context}.${record.name}.json`, record)));
|
|
26
|
+
};
|
|
27
|
+
exports.saveDeployableRecords = saveDeployableRecords;
|
|
28
|
+
const removeDeployableRecords = async (records) => {
|
|
29
|
+
shelljs_1.default.rm('-f', ...records.map(record => `${exports.CACHE_DIR}/${record.context}.${record.name}.json`));
|
|
30
|
+
};
|
|
31
|
+
exports.removeDeployableRecords = removeDeployableRecords;
|
|
32
|
+
const readJsonFile = async (path) => {
|
|
33
|
+
const file = await (0, promises_1.readFile)(path, { encoding: 'utf8' });
|
|
34
|
+
return JSON.parse(file);
|
|
35
|
+
};
|
|
36
|
+
const writeJsonFile = async (path, contents) => {
|
|
37
|
+
await (0, promises_1.open)(path, 'w');
|
|
38
|
+
return (0, promises_1.writeFile)(path, JSON.stringify(contents, undefined, 2), { encoding: 'utf8', flag: 'w' });
|
|
39
|
+
};
|
|
40
|
+
const getAllDeployableFilesWindows = ({ typeNames, includeDirs, includeFilesOrExtensions, excludeDirs, }) => {
|
|
41
|
+
const includePattern = includeFilesOrExtensions.length > 0 ? includeFilesOrExtensions.map(f => f.includes('.') ? f : `*.${f}`).join(' ') : '*';
|
|
42
|
+
const excludePattern = excludeDirs.length > 0 ? excludeDirs.join('|') : '';
|
|
43
|
+
const pattern = typeNames.length > 0
|
|
44
|
+
? typeNames.map((name) => `polyConfig: ${name}`).join('|')
|
|
45
|
+
: 'polyConfig';
|
|
46
|
+
const excludeCommand = excludePattern ? ` | findstr /V /I "${excludePattern}"` : '';
|
|
47
|
+
const searchCommand = ` | findstr /M /I /F:/ /C:"${pattern}"`;
|
|
48
|
+
let result = [];
|
|
49
|
+
for (const dir of includeDirs) {
|
|
50
|
+
const dirCommand = `dir /S /P /B ${includePattern} ${dir}`;
|
|
51
|
+
const fullCommand = `${dirCommand}${excludeCommand}${searchCommand}`;
|
|
52
|
+
try {
|
|
53
|
+
const output = (0, child_process_1.execSync)(fullCommand).toString('utf8');
|
|
54
|
+
result = result.concat(output.split(/\r?\n/).filter(Boolean));
|
|
55
|
+
}
|
|
56
|
+
catch { }
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
};
|
|
60
|
+
exports.getAllDeployableFilesWindows = getAllDeployableFilesWindows;
|
|
61
|
+
const getAllDeployableFilesLinux = ({ typeNames, includeDirs, includeFilesOrExtensions, excludeDirs, }) => {
|
|
62
|
+
const include = includeFilesOrExtensions.length
|
|
63
|
+
? `--include={${includeFilesOrExtensions.map((f) => {
|
|
64
|
+
return f.includes('.') ? f : `*.${f}`;
|
|
65
|
+
}).join(',')}}`
|
|
66
|
+
: '';
|
|
67
|
+
const excludeDir = excludeDirs.length ? `--exclude-dir={${excludeDirs.join(',')}}` : '';
|
|
68
|
+
const searchPath = includeDirs.length
|
|
69
|
+
? includeDirs.join(' ')
|
|
70
|
+
: '.';
|
|
71
|
+
const patterns = typeNames.length > 0
|
|
72
|
+
? typeNames.map((name) => `-e 'polyConfig: ${name}'`).join(' ')
|
|
73
|
+
: '-e \'polyConfig\'';
|
|
74
|
+
const grepCommand = `grep ${include} ${excludeDir} -Rl ${patterns} ${searchPath}`;
|
|
75
|
+
const output = (0, child_process_1.execSync)(grepCommand).toString('utf8');
|
|
76
|
+
return output.split('\n').filter(Boolean);
|
|
77
|
+
};
|
|
78
|
+
exports.getAllDeployableFilesLinux = getAllDeployableFilesLinux;
|
|
79
|
+
const getAllDeployableFiles = (config = {}) => {
|
|
80
|
+
config.typeNames = config.typeNames = exports.DeployableTypeEntries.map(p => p[0]);
|
|
81
|
+
config.includeDirs = config.includeDirs = ['.'];
|
|
82
|
+
config.includeFilesOrExtensions = config.includeFilesOrExtensions = ['ts', 'js'];
|
|
83
|
+
config.excludeDirs = config.excludeDirs = [
|
|
84
|
+
'node_modules',
|
|
85
|
+
'dist',
|
|
86
|
+
'build',
|
|
87
|
+
'output',
|
|
88
|
+
'.vscode',
|
|
89
|
+
'.poly',
|
|
90
|
+
'.github',
|
|
91
|
+
'.husky',
|
|
92
|
+
'.yarn',
|
|
93
|
+
];
|
|
94
|
+
const isWindows = os_1.default.platform() === 'win32';
|
|
95
|
+
return isWindows
|
|
96
|
+
? (0, exports.getAllDeployableFilesWindows)(config)
|
|
97
|
+
: (0, exports.getAllDeployableFilesLinux)(config);
|
|
98
|
+
};
|
|
99
|
+
exports.getAllDeployableFiles = getAllDeployableFiles;
|
|
100
|
+
const getGitRevision = (branchOrTag = 'HEAD') => {
|
|
101
|
+
try {
|
|
102
|
+
return (0, child_process_1.execSync)(`git rev-parse --short ${branchOrTag}`).toString('utf8').trim();
|
|
103
|
+
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
console.warn('Failed to get git revision. Falling back to random hash.');
|
|
106
|
+
return Array.from({ length: 8 }, () => Math.floor(Math.random() * 16).toString(16)).join('');
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
exports.getGitRevision = getGitRevision;
|
|
110
|
+
const getCacheDeploymentsRevision = () => {
|
|
111
|
+
return (0, promises_1.readFile)(exports.CACHE_VERSION_FILE, {
|
|
112
|
+
flag: 'r',
|
|
113
|
+
encoding: 'utf8',
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
exports.getCacheDeploymentsRevision = getCacheDeploymentsRevision;
|
|
117
|
+
const writeCacheRevision = async (gitRevision = (0, exports.getGitRevision)()) => {
|
|
118
|
+
await (0, promises_1.open)(exports.CACHE_VERSION_FILE, 'w');
|
|
119
|
+
await (0, promises_1.writeFile)(exports.CACHE_VERSION_FILE, gitRevision, {
|
|
120
|
+
flag: 'w',
|
|
121
|
+
encoding: 'utf8',
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
exports.writeCacheRevision = writeCacheRevision;
|
|
125
|
+
const isCacheUpToDate = async () => {
|
|
126
|
+
const cachedRevision = await (0, exports.getCacheDeploymentsRevision)();
|
|
127
|
+
const gitRevision = (0, exports.getGitRevision)();
|
|
128
|
+
return cachedRevision === gitRevision;
|
|
129
|
+
};
|
|
130
|
+
exports.isCacheUpToDate = isCacheUpToDate;
|
|
131
|
+
const writeDeployComments = (deployments) => {
|
|
132
|
+
const canopyPath = process.env.POLY_API_BASE_URL?.includes('localhost')
|
|
133
|
+
? 'polyui/collections'
|
|
134
|
+
: 'canopy/polyui/collections';
|
|
135
|
+
return deployments
|
|
136
|
+
.map(d => `// Poly deployed @ ${d.deployed} - ${d.context}.${d.name} - ${d.instance.endsWith(':8000') ? d.instance.replace(':8000', ':3000') : d.instance}/${canopyPath}/${d.type}s/${d.id}`).join('\n');
|
|
137
|
+
};
|
|
138
|
+
exports.writeDeployComments = writeDeployComments;
|
|
139
|
+
const printJSDocFunctionComment = ({ description, params, returns }) => {
|
|
140
|
+
return `/**\n${[
|
|
141
|
+
...description.split('\n').filter(Boolean),
|
|
142
|
+
...params.map(p => `@param {${p.type}} ${p.name}${p.description ? ' - ' : ''}${p.description}`),
|
|
143
|
+
`@returns {${returns.type}} ${returns.description}`,
|
|
144
|
+
].map(l => ` * ${l}`).join('\n')}\n */\n`;
|
|
145
|
+
};
|
|
146
|
+
const updateDeploymentComments = (fileContent, deployable) => {
|
|
147
|
+
while (deployable.deploymentCommentRanges.length > 0) {
|
|
148
|
+
const range = deployable.deploymentCommentRanges.pop();
|
|
149
|
+
fileContent = `${fileContent.substring(0, range[0])}${fileContent.substring(range[1])}`;
|
|
150
|
+
}
|
|
151
|
+
if (deployable.deployments.length) {
|
|
152
|
+
const deploymentComments = (0, exports.writeDeployComments)(deployable.deployments);
|
|
153
|
+
deployable.deploymentCommentRanges.push([0, deploymentComments.length + 1]);
|
|
154
|
+
fileContent = `${deploymentComments}\n${fileContent}`;
|
|
155
|
+
}
|
|
156
|
+
return fileContent;
|
|
157
|
+
};
|
|
158
|
+
const updateDeployableFunctionComments = (fileContent, deployable, disableDocs = false) => {
|
|
159
|
+
if (!disableDocs) {
|
|
160
|
+
fileContent = `${fileContent.substring(0, deployable.docStartIndex)}${printJSDocFunctionComment(deployable.types)}${fileContent.substring(deployable.docEndIndex)}`;
|
|
161
|
+
}
|
|
162
|
+
return fileContent;
|
|
163
|
+
};
|
|
164
|
+
const writeUpdatedDeployable = async (deployable, disableDocs = false) => {
|
|
165
|
+
let fileContent = await (0, promises_1.readFile)(deployable.file, {
|
|
166
|
+
flag: 'r',
|
|
167
|
+
encoding: 'utf8',
|
|
168
|
+
});
|
|
169
|
+
switch (deployable.type) {
|
|
170
|
+
case 'client-function':
|
|
171
|
+
case 'server-function': {
|
|
172
|
+
fileContent = updateDeployableFunctionComments(fileContent, deployable, disableDocs);
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
default:
|
|
176
|
+
throw new Error(`Unsupported deployable type: '${deployable.type}'`);
|
|
177
|
+
}
|
|
178
|
+
fileContent = updateDeploymentComments(fileContent, deployable);
|
|
179
|
+
return (0, promises_1.writeFile)(deployable.file, fileContent, {
|
|
180
|
+
flag: 'w',
|
|
181
|
+
encoding: 'utf8',
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
exports.writeUpdatedDeployable = writeUpdatedDeployable;
|
|
185
|
+
//# sourceMappingURL=deployables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deployables.js","sourceRoot":"","sources":["../../../src/deployables.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,+CAAsE;AACtE,sDAA4B;AAC5B,iDAAyC;AAE5B,QAAA,kBAAkB,GAAG,2CAA2C,CAAC;AACjE,QAAA,SAAS,GAAG,kCAAkC,CAAC;AAsB/C,QAAA,qBAAqB,GAA6C,EAAE,CAAC;AAElF,6BAAqB,CAAC,IAAI,CAAC,CAAC,oBAAoB,EAAE,iBAAiB,CAAC,CAAC,CAAC;AACtE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E;IAC1H,IAAI,CAAC,WAAW,EAAE;QAEhB,WAAW,GAAG,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC,EAAE,UAAU,CAAC,aAAa,CAChE,GAAG,yBAAyB,CAAC,UAAU,CAAC,KAAK,CAC7C,GAAG,WAAW,CAAC,SAAS,CAAC,UAAU,CAAC,WAAW,CAC/C,EAAE,CAAC;KACN;IACD,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AAEK,MAAM,sBAAsB,GAAG,KAAK,EAAE,UAA4B,EAAE,WAAW,GAAG,KAAK,EAAE,EAAE;IAChG,IAAI,WAAW,GAAG,MAAM,IAAA,mBAAQ,EAAC,UAAU,CAAC,IAAI,EAAE;QAChD,IAAI,EAAE,GAAG;QACT,QAAQ,EAAE,MAAM;KACjB,CAAC,CAAC;IACH,QAAQ,UAAU,CAAC,IAAI,EAAE;QACvB,KAAK,iBAAiB,CAAC;QACvB,KAAK,iBAAiB,CAAC,CAAC;YACtB,WAAW,GAAG,gCAAgC,CAAC,WAAW,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;YACrF,MAAM;SACP;QACD;YACE,MAAM,IAAI,KAAK,CAAC,iCAAiC,UAAU,CAAC,IAAI,GAAG,CAAC,CAAC;KACxE;IAED,WAAW,GAAG,wBAAwB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IAChE,OAAO,IAAA,oBAAS,EAAC,UAAU,CAAC,IAAI,EAAE,WAAW,EAAE;QAC7C,IAAI,EAAE,GAAG;QACT,QAAQ,EAAE,MAAM;KACjB,CAAC,CAAC;AACL,CAAC,CAAC;AApBW,QAAA,sBAAsB,0BAoBjC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DeployableRecord, Deployment } from './deployables';
|
|
2
|
+
export declare const getTSConfig: () => any;
|
|
3
|
+
export declare const getTSBaseUrl: (config?: any) => any;
|
|
4
|
+
export declare const getDependencies: (code: string, fileName: string, baseUrl: string | undefined) => string[];
|
|
5
|
+
export declare const generateTypeSchemas: (fileName: string, baseUrl: string | undefined, ignoreTypeNames?: string[]) => {
|
|
6
|
+
[typeName: string]: any;
|
|
7
|
+
};
|
|
8
|
+
export declare const parseDeployComment: (comment: string) => Deployment;
|
|
9
|
+
export declare const parseDeployable: (filePath: string, baseUrl: string, gitRevision: string) => Promise<[DeployableRecord, string]>;
|
|
10
|
+
//# sourceMappingURL=transpiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transpiler.d.ts","sourceRoot":"","sources":["../../../src/transpiler.ts"],"names":[],"mappings":"AAQA,OAAO,EAAyB,gBAAgB,EAAE,UAAU,EAAmE,MAAM,eAAe,CAAC;AAErJ,eAAO,MAAM,WAAW,WAMvB,CAAC;AAEF,eAAO,MAAM,YAAY,uBAA2E,CAAC;AAarG,eAAO,MAAM,eAAe,SAAU,MAAM,YAAY,MAAM,WAAW,MAAM,GAAG,SAAS,aAoF1F,CAAC;AAEF,eAAO,MAAM,mBAAmB,aAAc,MAAM,WAAW,MAAM,GAAG,SAAS,oBAAoB,MAAM,EAAE;;CAkI5G,CAAC;AAoDF,eAAO,MAAM,kBAAkB,YAAa,MAAM,KAAG,UAcpD,CAAC;AAoLF,eAAO,MAAM,eAAe,aAAoB,MAAM,WAAW,MAAM,eAAe,MAAM,KAAG,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAgBhI,CAAC"}
|
|
@@ -0,0 +1,460 @@
|
|
|
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 (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.parseDeployable = exports.parseDeployComment = exports.generateTypeSchemas = exports.getDependencies = exports.getTSBaseUrl = exports.getTSConfig = void 0;
|
|
30
|
+
const fs_1 = __importDefault(require("fs"));
|
|
31
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
32
|
+
const shelljs_1 = __importDefault(require("shelljs"));
|
|
33
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
34
|
+
const TJS = __importStar(require("typescript-json-schema"));
|
|
35
|
+
const transpiler_1 = require("../../common/src/transpiler");
|
|
36
|
+
const path_1 = __importDefault(require("path"));
|
|
37
|
+
const deployables_1 = require("./deployables");
|
|
38
|
+
const getTSConfig = () => {
|
|
39
|
+
const tsConfig = typescript_1.default.findConfigFile('./', typescript_1.default.sys.fileExists, 'tsconfig.json');
|
|
40
|
+
if (tsConfig) {
|
|
41
|
+
return typescript_1.default.readConfigFile(tsConfig, typescript_1.default.sys.readFile).config;
|
|
42
|
+
}
|
|
43
|
+
return {};
|
|
44
|
+
};
|
|
45
|
+
exports.getTSConfig = getTSConfig;
|
|
46
|
+
const getTSBaseUrl = (config = (0, exports.getTSConfig)()) => config.compilerOptions?.baseUrl || undefined;
|
|
47
|
+
exports.getTSBaseUrl = getTSBaseUrl;
|
|
48
|
+
const loadTsSourceFile = (filePath) => {
|
|
49
|
+
const fileContent = fs_1.default.readFileSync(filePath, 'utf8');
|
|
50
|
+
const sourceFile = typescript_1.default.createSourceFile(filePath, fileContent, typescript_1.default.ScriptTarget.Latest, true, typescript_1.default.ScriptKind.TS);
|
|
51
|
+
return sourceFile;
|
|
52
|
+
};
|
|
53
|
+
const getDependencies = (code, fileName, baseUrl) => {
|
|
54
|
+
const importedLibraries = new Set();
|
|
55
|
+
const compilerOptions = {
|
|
56
|
+
module: typescript_1.default.ModuleKind.CommonJS,
|
|
57
|
+
esModuleInterop: true,
|
|
58
|
+
noImplicitUseStrict: true,
|
|
59
|
+
baseUrl,
|
|
60
|
+
};
|
|
61
|
+
const compilerHost = typescript_1.default.createCompilerHost(compilerOptions);
|
|
62
|
+
typescript_1.default.transpileModule(code, {
|
|
63
|
+
compilerOptions,
|
|
64
|
+
transformers: {
|
|
65
|
+
before: [
|
|
66
|
+
(context) => {
|
|
67
|
+
return (sourceFile) => {
|
|
68
|
+
const visitor = (node) => {
|
|
69
|
+
if (typescript_1.default.isImportDeclaration(node)) {
|
|
70
|
+
const moduleName = node.moduleSpecifier.text;
|
|
71
|
+
const resolvedModule = typescript_1.default.resolveModuleName(moduleName, fileName, compilerOptions, compilerHost);
|
|
72
|
+
if (resolvedModule.resolvedModule) {
|
|
73
|
+
if (resolvedModule.resolvedModule.isExternalLibraryImport) {
|
|
74
|
+
importedLibraries.add(moduleName);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
if (!moduleName.startsWith('.')) {
|
|
79
|
+
importedLibraries.add(moduleName);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return node;
|
|
84
|
+
};
|
|
85
|
+
return typescript_1.default.visitEachChild(sourceFile, visitor, context);
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
let dependencies = Array.from(importedLibraries)
|
|
92
|
+
.filter(library => !transpiler_1.EXCLUDED_REQUIREMENTS.includes(library));
|
|
93
|
+
if (dependencies.length) {
|
|
94
|
+
let packageJson = fs_1.default.readFileSync(path_1.default.join(process.cwd(), 'package.json'), 'utf-8');
|
|
95
|
+
try {
|
|
96
|
+
packageJson = JSON.parse(packageJson);
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
shelljs_1.default.echo(chalk_1.default.yellow('\nWarning:'), 'Failed to parse package.json file in order to read dependencies, there could be issues with some dependencies at the time of deploying the server function.');
|
|
100
|
+
}
|
|
101
|
+
const packageJsonDependencies = packageJson.dependencies || {};
|
|
102
|
+
const packageJsonDevDependencies = packageJson.devDependencies || {};
|
|
103
|
+
for (const dependency of dependencies) {
|
|
104
|
+
if (packageJsonDependencies[dependency] || packageJsonDevDependencies[dependency]) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const dependencyParts = dependency.split('/');
|
|
108
|
+
while (dependencyParts.length > 0) {
|
|
109
|
+
dependencyParts.pop();
|
|
110
|
+
const newDependencyPath = dependencyParts.join('/');
|
|
111
|
+
if (packageJsonDependencies[newDependencyPath] || packageJsonDevDependencies[newDependencyPath]) {
|
|
112
|
+
dependencies = dependencies.map(currentDependency => {
|
|
113
|
+
if (currentDependency === dependency) {
|
|
114
|
+
return dependencyParts.join('/');
|
|
115
|
+
}
|
|
116
|
+
return currentDependency;
|
|
117
|
+
});
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return dependencies;
|
|
124
|
+
};
|
|
125
|
+
exports.getDependencies = getDependencies;
|
|
126
|
+
const generateTypeSchemas = (fileName, baseUrl, ignoreTypeNames) => {
|
|
127
|
+
const sourceFile = loadTsSourceFile(fileName);
|
|
128
|
+
const program = typescript_1.default.createProgram([fileName], {
|
|
129
|
+
allowJs: true,
|
|
130
|
+
lib: ['es2015'],
|
|
131
|
+
baseUrl,
|
|
132
|
+
});
|
|
133
|
+
const schemaDefs = {};
|
|
134
|
+
const settings = {
|
|
135
|
+
required: true,
|
|
136
|
+
noExtraProps: true,
|
|
137
|
+
ignoreErrors: true,
|
|
138
|
+
};
|
|
139
|
+
const generator = TJS.buildGenerator(program, settings);
|
|
140
|
+
const consolidateGeneratorSymbolType = (typeName, symbolRefs) => {
|
|
141
|
+
const tryConsolidationByFile = (fileName) => {
|
|
142
|
+
const symbolRef = symbolRefs.find(symbolRef => {
|
|
143
|
+
return symbolRef.symbol.declarations.some(declaration => declaration.getSourceFile().fileName.includes(fileName));
|
|
144
|
+
});
|
|
145
|
+
if (symbolRef) {
|
|
146
|
+
const declaredType = program.getTypeChecker().getDeclaredTypeOfSymbol(symbolRef.symbol);
|
|
147
|
+
if (declaredType) {
|
|
148
|
+
generator.allSymbols[typeName] = declaredType;
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return false;
|
|
153
|
+
};
|
|
154
|
+
if (tryConsolidationByFile(fileName)) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
tryConsolidationByFile('/node_modules/.poly/');
|
|
158
|
+
};
|
|
159
|
+
const isInnerFunctionNode = (node) => {
|
|
160
|
+
let parent = node.parent;
|
|
161
|
+
let insideBlock = false;
|
|
162
|
+
while (parent) {
|
|
163
|
+
if (parent.kind === typescript_1.default.SyntaxKind.Block) {
|
|
164
|
+
insideBlock = true;
|
|
165
|
+
}
|
|
166
|
+
else if (parent.kind === typescript_1.default.SyntaxKind.FunctionDeclaration && insideBlock) {
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
parent = parent.parent;
|
|
170
|
+
}
|
|
171
|
+
return false;
|
|
172
|
+
};
|
|
173
|
+
const visitor = (node) => {
|
|
174
|
+
if (typescript_1.default.isTypeReferenceNode(node) && !isInnerFunctionNode(node)) {
|
|
175
|
+
const typeName = node.typeName.getText();
|
|
176
|
+
if (ignoreTypeNames?.includes(typeName))
|
|
177
|
+
return;
|
|
178
|
+
const symbolRefs = generator.getSymbols(typeName);
|
|
179
|
+
const isGenericType = node.typeArguments?.length > 0;
|
|
180
|
+
if (!symbolRefs.length) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
consolidateGeneratorSymbolType(typeName, symbolRefs);
|
|
184
|
+
const typeParameterVariations = schemaDefs[typeName]?.typeParameterVariations || [];
|
|
185
|
+
if (isGenericType) {
|
|
186
|
+
const symbolRef = symbolRefs[0];
|
|
187
|
+
const typeParameters = [];
|
|
188
|
+
if (typeParameters.length === 0 && symbolRef) {
|
|
189
|
+
symbolRef.symbol.declarations.forEach(declaration => {
|
|
190
|
+
if (typescript_1.default.isTypeAliasDeclaration(declaration) || typescript_1.default.isInterfaceDeclaration(declaration) || typescript_1.default.isClassDeclaration(declaration)) {
|
|
191
|
+
if (declaration.parent && typescript_1.default.isSourceFile(declaration.parent) && declaration.parent.hasNoDefaultLib) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
typeParameters.push(...declaration.typeParameters?.map(typeParameter => typeParameter.name.text) || []);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
if (typeParameters.length) {
|
|
199
|
+
const parameterSchemaTypes = {};
|
|
200
|
+
typeParameters.forEach((typeParameter, index) => {
|
|
201
|
+
const typeArgument = node.typeArguments[index];
|
|
202
|
+
if (typeArgument) {
|
|
203
|
+
parameterSchemaTypes[typeParameter] = typeArgument.getText();
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
typeParameterVariations.push(parameterSchemaTypes);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
const schema = schemaDefs[typeName]?.schema || TJS.generateSchema(program, typeName, settings, undefined, generator);
|
|
210
|
+
if (schema) {
|
|
211
|
+
schemaDefs[typeName] = {
|
|
212
|
+
schema,
|
|
213
|
+
typeParameterVariations,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
typescript_1.default.forEachChild(node, visitor);
|
|
218
|
+
};
|
|
219
|
+
typescript_1.default.forEachChild(sourceFile, visitor);
|
|
220
|
+
enhanceWithParameterTypeSchemas(schemaDefs);
|
|
221
|
+
return extractSchemas(schemaDefs);
|
|
222
|
+
};
|
|
223
|
+
exports.generateTypeSchemas = generateTypeSchemas;
|
|
224
|
+
const enhanceWithParameterTypeSchemas = (schemaDefs) => {
|
|
225
|
+
Object.keys(schemaDefs)
|
|
226
|
+
.forEach(typeName => {
|
|
227
|
+
const schemaDef = schemaDefs[typeName];
|
|
228
|
+
const typeVariations = schemaDef.typeParameterVariations;
|
|
229
|
+
if (!typeVariations.length) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
typeVariations.forEach(typeVariation => {
|
|
233
|
+
const typeParameters = Object.keys(typeVariation);
|
|
234
|
+
if (!typeParameters.length) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const parameterTypes = `${Object.values(typeVariation).join(', ')}`;
|
|
238
|
+
const updatedDefinitions = {
|
|
239
|
+
...schemaDef.schema.definitions,
|
|
240
|
+
...typeParameters.reduce((acc, typeParameter) => {
|
|
241
|
+
const typeParameterSchemaDef = schemaDefs[typeVariation[typeParameter]];
|
|
242
|
+
return ({
|
|
243
|
+
...acc,
|
|
244
|
+
...typeParameterSchemaDef?.schema.definitions,
|
|
245
|
+
[typeParameter]: {
|
|
246
|
+
...typeParameterSchemaDef?.schema,
|
|
247
|
+
$schema: undefined,
|
|
248
|
+
definitions: undefined,
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
}, {}),
|
|
252
|
+
};
|
|
253
|
+
schemaDefs[`${typeName}<${parameterTypes}>`] = {
|
|
254
|
+
schema: {
|
|
255
|
+
...schemaDef.schema,
|
|
256
|
+
definitions: updatedDefinitions,
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
const extractSchemas = (schemaDefs) => Object.keys(schemaDefs)
|
|
263
|
+
.reduce((acc, typeName) => {
|
|
264
|
+
return {
|
|
265
|
+
...acc,
|
|
266
|
+
[typeName]: schemaDefs[typeName].schema,
|
|
267
|
+
};
|
|
268
|
+
}, {});
|
|
269
|
+
const parseDeployComment = (comment) => {
|
|
270
|
+
const match = comment.match(/^\s*(?:\/\/\s*)*Poly deployed @ (\S+) - (\S+)\.([^.]+) - (https?:\/\/[^/]+)\/\S+\/(\S+)s\/(\S+)$/);
|
|
271
|
+
if (!match)
|
|
272
|
+
return null;
|
|
273
|
+
const [, deployed, context, name, instance, type, id] = match;
|
|
274
|
+
return {
|
|
275
|
+
name,
|
|
276
|
+
context,
|
|
277
|
+
type: type,
|
|
278
|
+
id,
|
|
279
|
+
deployed,
|
|
280
|
+
instance: instance.endsWith('localhost:3000') ? instance.replace(':3000', ':8000') : instance,
|
|
281
|
+
};
|
|
282
|
+
};
|
|
283
|
+
exports.parseDeployComment = parseDeployComment;
|
|
284
|
+
const getDeployComments = (sourceFile) => {
|
|
285
|
+
const text = sourceFile.getFullText();
|
|
286
|
+
const matches = [];
|
|
287
|
+
const ranges = [];
|
|
288
|
+
const leadingRanges = typescript_1.default.getLeadingCommentRanges(text, 0);
|
|
289
|
+
if (leadingRanges) {
|
|
290
|
+
for (const range of leadingRanges) {
|
|
291
|
+
const comment = text.substring(range.pos, range.end);
|
|
292
|
+
const match = (0, exports.parseDeployComment)(comment.trim());
|
|
293
|
+
if (match) {
|
|
294
|
+
matches.push(match);
|
|
295
|
+
ranges.push([range.pos, range.end + (range.hasTrailingNewLine ? 1 : 0)]);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return [matches, ranges];
|
|
300
|
+
};
|
|
301
|
+
const getPolyConfig = (types, sourceFile) => {
|
|
302
|
+
let config = null;
|
|
303
|
+
const visit = (node) => {
|
|
304
|
+
if (typescript_1.default.isVariableStatement(node)) {
|
|
305
|
+
const declaration = node.declarationList.declarations[0];
|
|
306
|
+
const name = declaration.name.getText(sourceFile);
|
|
307
|
+
const type = declaration.type?.getText(sourceFile);
|
|
308
|
+
if (name === 'polyConfig' && type && types.includes(type)) {
|
|
309
|
+
const initializer = node.declarationList.declarations[0].initializer;
|
|
310
|
+
if (initializer && typescript_1.default.isObjectLiteralExpression(initializer)) {
|
|
311
|
+
config = eval(`(${initializer.getText()})`);
|
|
312
|
+
config.type = type;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
typescript_1.default.forEachChild(node, visit);
|
|
317
|
+
};
|
|
318
|
+
visit(sourceFile);
|
|
319
|
+
const { name, context, type, ...other } = config;
|
|
320
|
+
if (!name)
|
|
321
|
+
throw new Error("polyConfig is missing 'name'.");
|
|
322
|
+
if (!context)
|
|
323
|
+
throw new Error("polyConfig is missing 'context'.");
|
|
324
|
+
return { name, context, type, config: other };
|
|
325
|
+
};
|
|
326
|
+
const parseJSDoc = (node) => {
|
|
327
|
+
let jsDocTags = null;
|
|
328
|
+
const jsDoc = node.getChildren().filter(typescript_1.default.isJSDoc);
|
|
329
|
+
if (jsDoc.length > 0) {
|
|
330
|
+
jsDocTags = {};
|
|
331
|
+
const firstJsDoc = jsDoc[0];
|
|
332
|
+
jsDocTags.description = firstJsDoc.comment ? typescript_1.default.getTextOfJSDocComment(firstJsDoc.comment) : '';
|
|
333
|
+
firstJsDoc.tags?.forEach(tag => {
|
|
334
|
+
const tagName = tag.tagName.text;
|
|
335
|
+
const tagComment = typescript_1.default.getTextOfJSDocComment(tag.comment) || '';
|
|
336
|
+
if (tagName === 'param' && typescript_1.default.isJSDocParameterTag(tag)) {
|
|
337
|
+
const paramDetails = tagComment.split(/[\s-]+/);
|
|
338
|
+
const paramName = tag.name.getText();
|
|
339
|
+
const paramType = tag.typeExpression?.getText().replace(/^{|}$/g, '') || '';
|
|
340
|
+
const paramDescription = paramDetails.join(' ').trim();
|
|
341
|
+
if (!jsDocTags.params) {
|
|
342
|
+
jsDocTags.params = [];
|
|
343
|
+
}
|
|
344
|
+
jsDocTags.params.push({
|
|
345
|
+
name: paramName,
|
|
346
|
+
type: paramType,
|
|
347
|
+
description: paramDescription,
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
else if (tagName === 'returns' && typescript_1.default.isJSDocReturnTag(tag)) {
|
|
351
|
+
jsDocTags.returns = {
|
|
352
|
+
type: tag.typeExpression?.getText().replace(/^{|}$/g, '') || '',
|
|
353
|
+
description: tagComment.trim(),
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
jsDocTags[tagName] = tagComment.trim();
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
return jsDocTags;
|
|
362
|
+
};
|
|
363
|
+
const parseTSTypes = (node, sourceFile) => {
|
|
364
|
+
const params = node.parameters.map(param => {
|
|
365
|
+
const name = param.name.getText(sourceFile);
|
|
366
|
+
const type = param.type?.getText(sourceFile);
|
|
367
|
+
if (!type)
|
|
368
|
+
throw new Error(`Missing type for function argument '${name}' in file '${sourceFile.fileName}'.`);
|
|
369
|
+
return {
|
|
370
|
+
name,
|
|
371
|
+
type,
|
|
372
|
+
description: '',
|
|
373
|
+
};
|
|
374
|
+
});
|
|
375
|
+
const type = node.type?.getText(sourceFile);
|
|
376
|
+
if (!type)
|
|
377
|
+
throw new Error(`Missing return type for function in file '${sourceFile.fileName}'. Use 'void' if no return type.`);
|
|
378
|
+
const returns = {
|
|
379
|
+
type,
|
|
380
|
+
description: '',
|
|
381
|
+
};
|
|
382
|
+
return {
|
|
383
|
+
params,
|
|
384
|
+
returns,
|
|
385
|
+
description: '',
|
|
386
|
+
};
|
|
387
|
+
};
|
|
388
|
+
const getFunctionDetails = (sourceFile, functionName) => {
|
|
389
|
+
let functionDetails = null;
|
|
390
|
+
let dirty = false;
|
|
391
|
+
const visit = (node) => {
|
|
392
|
+
if (typescript_1.default.isFunctionDeclaration(node) && node.name?.getText(sourceFile) === functionName) {
|
|
393
|
+
const jsDoc = parseJSDoc(node);
|
|
394
|
+
const types = parseTSTypes(node, sourceFile);
|
|
395
|
+
if (jsDoc &&
|
|
396
|
+
types.params.every((p, i) => p.type === jsDoc.params[i].type && p.name === jsDoc.params[i].name) &&
|
|
397
|
+
types.returns.type === jsDoc.returns.type) {
|
|
398
|
+
jsDoc.params.forEach((p, i) => {
|
|
399
|
+
types.params[i].description = p.description;
|
|
400
|
+
});
|
|
401
|
+
types.returns.description = jsDoc.returns.description;
|
|
402
|
+
types.description = jsDoc.description;
|
|
403
|
+
dirty = types.params.some((p, i) => p.type !== jsDoc.params[i].type || p.name !== jsDoc.params[i].name);
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
dirty = true;
|
|
407
|
+
}
|
|
408
|
+
const docStartIndex = node.getStart(sourceFile, true);
|
|
409
|
+
const docEndIndex = node.getStart(sourceFile, false);
|
|
410
|
+
functionDetails = {
|
|
411
|
+
types,
|
|
412
|
+
docStartIndex,
|
|
413
|
+
docEndIndex,
|
|
414
|
+
dirty,
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
typescript_1.default.forEachChild(node, visit);
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
visit(sourceFile);
|
|
422
|
+
if (!functionDetails)
|
|
423
|
+
throw new Error(`Failed to find a function named '${functionName}' within file '${sourceFile.fileName}'. Verify that your polyConfig name matches a valid function declared within the same file.`);
|
|
424
|
+
return functionDetails;
|
|
425
|
+
};
|
|
426
|
+
const parseDeployableFunction = (sourceFile, polyConfig, baseUrl, gitRevision) => {
|
|
427
|
+
const [deployments, deploymentCommentRanges] = getDeployComments(sourceFile);
|
|
428
|
+
const functionDetails = getFunctionDetails(sourceFile, polyConfig.name);
|
|
429
|
+
const dependencies = (0, exports.getDependencies)(sourceFile.getFullText(), sourceFile.fileName, baseUrl);
|
|
430
|
+
const typeSchemas = (0, exports.generateTypeSchemas)(sourceFile.fileName, baseUrl, deployables_1.DeployableTypeEntries.map(d => d[0]));
|
|
431
|
+
return {
|
|
432
|
+
...polyConfig,
|
|
433
|
+
...functionDetails,
|
|
434
|
+
deployments,
|
|
435
|
+
deploymentCommentRanges,
|
|
436
|
+
dependencies,
|
|
437
|
+
typeSchemas,
|
|
438
|
+
gitRevision,
|
|
439
|
+
file: sourceFile.fileName,
|
|
440
|
+
};
|
|
441
|
+
};
|
|
442
|
+
const parseDeployable = async (filePath, baseUrl, gitRevision) => {
|
|
443
|
+
const sourceFile = await loadTsSourceFile(filePath);
|
|
444
|
+
const polyConfig = getPolyConfig(deployables_1.DeployableTypeEntries.map(e => e[0]), sourceFile);
|
|
445
|
+
polyConfig.type = deployables_1.DeployableTsTypeToName[polyConfig.type];
|
|
446
|
+
try {
|
|
447
|
+
switch (polyConfig.type) {
|
|
448
|
+
case 'server-function':
|
|
449
|
+
case 'client-function':
|
|
450
|
+
return [parseDeployableFunction(sourceFile, polyConfig, baseUrl, gitRevision), sourceFile.getFullText()];
|
|
451
|
+
}
|
|
452
|
+
throw new Error('Invalid Poly deployment with unsupported type');
|
|
453
|
+
}
|
|
454
|
+
catch (err) {
|
|
455
|
+
console.error(`Prepared ${polyConfig.type.replaceAll('-', ' ')} ${polyConfig.context}.${polyConfig.name}: ERROR`);
|
|
456
|
+
console.error(err);
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
exports.parseDeployable = parseDeployable;
|
|
460
|
+
//# sourceMappingURL=transpiler.js.map
|