@rexeus/typeweaver-clients 0.0.2 → 0.0.3
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/index.d.ts +1 -1611
- package/dist/index.js +83 -924
- package/dist/templates/Client.ejs +2 -1
- package/dist/templates/RequestCommand.ejs +61 -0
- package/package.json +10 -5
package/dist/index.js
CHANGED
|
@@ -1,936 +1,27 @@
|
|
|
1
|
+
import { BasePlugin } from '@rexeus/typeweaver-gen';
|
|
1
2
|
import path from 'path';
|
|
2
|
-
import
|
|
3
|
+
import Case from 'case';
|
|
3
4
|
import { fileURLToPath } from 'url';
|
|
4
|
-
|
|
5
|
-
class BasePlugin {
|
|
6
|
-
description;
|
|
7
|
-
author;
|
|
8
|
-
depends;
|
|
9
|
-
config;
|
|
10
|
-
constructor(config = {}) {
|
|
11
|
-
this.config = config;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Default implementation - override in subclasses if needed
|
|
15
|
-
*/
|
|
16
|
-
async initialize(context) {
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Default implementation - override in subclasses if needed
|
|
20
|
-
*/
|
|
21
|
-
collectResources(resources) {
|
|
22
|
-
return resources;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Default implementation - override in subclasses if needed
|
|
26
|
-
*/
|
|
27
|
-
async finalize(context) {
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Copy lib files from plugin package to generated lib folder
|
|
31
|
-
*/
|
|
32
|
-
copyLibFiles(context, libSourceDir, libNamespace) {
|
|
33
|
-
const libDir = path.join(context.outputDir, "lib", libNamespace);
|
|
34
|
-
fs.mkdirSync(libDir, { recursive: true });
|
|
35
|
-
if (fs.existsSync(libSourceDir)) {
|
|
36
|
-
const files = fs.readdirSync(libSourceDir);
|
|
37
|
-
for (const file of files) {
|
|
38
|
-
const sourcePath = path.join(libSourceDir, file);
|
|
39
|
-
const targetPath = path.join(libDir, file);
|
|
40
|
-
if (fs.statSync(sourcePath).isFile()) {
|
|
41
|
-
fs.copyFileSync(sourcePath, targetPath);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
var ejs$1 = {};
|
|
48
|
-
var utils = {};
|
|
49
|
-
var hasRequiredUtils;
|
|
50
|
-
function requireUtils() {
|
|
51
|
-
if (hasRequiredUtils) return utils;
|
|
52
|
-
hasRequiredUtils = 1;
|
|
53
|
-
(function(exports) {
|
|
54
|
-
var regExpChars = /[|\\{}()[\]^$+*?.]/g;
|
|
55
|
-
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
56
|
-
var hasOwn = function(obj, key) {
|
|
57
|
-
return hasOwnProperty.apply(obj, [key]);
|
|
58
|
-
};
|
|
59
|
-
exports.escapeRegExpChars = function(string) {
|
|
60
|
-
if (!string) {
|
|
61
|
-
return "";
|
|
62
|
-
}
|
|
63
|
-
return String(string).replace(regExpChars, "\\$&");
|
|
64
|
-
};
|
|
65
|
-
var _ENCODE_HTML_RULES = {
|
|
66
|
-
"&": "&",
|
|
67
|
-
"<": "<",
|
|
68
|
-
">": ">",
|
|
69
|
-
'"': """,
|
|
70
|
-
"'": "'"
|
|
71
|
-
};
|
|
72
|
-
var _MATCH_HTML = /[&<>'"]/g;
|
|
73
|
-
function encode_char(c) {
|
|
74
|
-
return _ENCODE_HTML_RULES[c] || c;
|
|
75
|
-
}
|
|
76
|
-
var escapeFuncStr = `var _ENCODE_HTML_RULES = {
|
|
77
|
-
"&": "&"
|
|
78
|
-
, "<": "<"
|
|
79
|
-
, ">": ">"
|
|
80
|
-
, '"': """
|
|
81
|
-
, "'": "'"
|
|
82
|
-
}
|
|
83
|
-
, _MATCH_HTML = /[&<>'"]/g;
|
|
84
|
-
function encode_char(c) {
|
|
85
|
-
return _ENCODE_HTML_RULES[c] || c;
|
|
86
|
-
};
|
|
87
|
-
`;
|
|
88
|
-
exports.escapeXML = function(markup) {
|
|
89
|
-
return markup == void 0 ? "" : String(markup).replace(_MATCH_HTML, encode_char);
|
|
90
|
-
};
|
|
91
|
-
function escapeXMLToString() {
|
|
92
|
-
return Function.prototype.toString.call(this) + ";\n" + escapeFuncStr;
|
|
93
|
-
}
|
|
94
|
-
try {
|
|
95
|
-
if (typeof Object.defineProperty === "function") {
|
|
96
|
-
Object.defineProperty(exports.escapeXML, "toString", { value: escapeXMLToString });
|
|
97
|
-
} else {
|
|
98
|
-
exports.escapeXML.toString = escapeXMLToString;
|
|
99
|
-
}
|
|
100
|
-
} catch (err) {
|
|
101
|
-
console.warn("Unable to set escapeXML.toString (is the Function prototype frozen?)");
|
|
102
|
-
}
|
|
103
|
-
exports.shallowCopy = function(to, from) {
|
|
104
|
-
from = from || {};
|
|
105
|
-
if (to !== null && to !== void 0) {
|
|
106
|
-
for (var p in from) {
|
|
107
|
-
if (!hasOwn(from, p)) {
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
if (p === "__proto__" || p === "constructor") {
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
to[p] = from[p];
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return to;
|
|
117
|
-
};
|
|
118
|
-
exports.shallowCopyFromList = function(to, from, list) {
|
|
119
|
-
list = list || [];
|
|
120
|
-
from = from || {};
|
|
121
|
-
if (to !== null && to !== void 0) {
|
|
122
|
-
for (var i = 0; i < list.length; i++) {
|
|
123
|
-
var p = list[i];
|
|
124
|
-
if (typeof from[p] != "undefined") {
|
|
125
|
-
if (!hasOwn(from, p)) {
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
if (p === "__proto__" || p === "constructor") {
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
to[p] = from[p];
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return to;
|
|
136
|
-
};
|
|
137
|
-
exports.cache = {
|
|
138
|
-
_data: {},
|
|
139
|
-
set: function(key, val) {
|
|
140
|
-
this._data[key] = val;
|
|
141
|
-
},
|
|
142
|
-
get: function(key) {
|
|
143
|
-
return this._data[key];
|
|
144
|
-
},
|
|
145
|
-
remove: function(key) {
|
|
146
|
-
delete this._data[key];
|
|
147
|
-
},
|
|
148
|
-
reset: function() {
|
|
149
|
-
this._data = {};
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
exports.hyphenToCamel = function(str) {
|
|
153
|
-
return str.replace(/-[a-z]/g, function(match) {
|
|
154
|
-
return match[1].toUpperCase();
|
|
155
|
-
});
|
|
156
|
-
};
|
|
157
|
-
exports.createNullProtoObjWherePossible = function() {
|
|
158
|
-
if (typeof Object.create == "function") {
|
|
159
|
-
return function() {
|
|
160
|
-
return /* @__PURE__ */ Object.create(null);
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
if (!({ __proto__: null } instanceof Object)) {
|
|
164
|
-
return function() {
|
|
165
|
-
return { __proto__: null };
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
return function() {
|
|
169
|
-
return {};
|
|
170
|
-
};
|
|
171
|
-
}();
|
|
172
|
-
exports.hasOwnOnlyObject = function(obj) {
|
|
173
|
-
var o = exports.createNullProtoObjWherePossible();
|
|
174
|
-
for (var p in obj) {
|
|
175
|
-
if (hasOwn(obj, p)) {
|
|
176
|
-
o[p] = obj[p];
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return o;
|
|
180
|
-
};
|
|
181
|
-
})(utils);
|
|
182
|
-
return utils;
|
|
183
|
-
}
|
|
184
|
-
var version = "3.1.10";
|
|
185
|
-
var require$$3 = {
|
|
186
|
-
version
|
|
187
|
-
};
|
|
188
|
-
var hasRequiredEjs;
|
|
189
|
-
function requireEjs() {
|
|
190
|
-
if (hasRequiredEjs) return ejs$1;
|
|
191
|
-
hasRequiredEjs = 1;
|
|
192
|
-
(function(exports) {
|
|
193
|
-
/**
|
|
194
|
-
* @file Embedded JavaScript templating engine. {@link http://ejs.co}
|
|
195
|
-
* @author Matthew Eernisse <mde@fleegix.org>
|
|
196
|
-
* @author Tiancheng "Timothy" Gu <timothygu99@gmail.com>
|
|
197
|
-
* @project EJS
|
|
198
|
-
* @license {@link http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0}
|
|
199
|
-
*/
|
|
200
|
-
var fs$1 = fs;
|
|
201
|
-
var path$1 = path;
|
|
202
|
-
var utils2 = requireUtils();
|
|
203
|
-
var scopeOptionWarned = false;
|
|
204
|
-
var _VERSION_STRING = require$$3.version;
|
|
205
|
-
var _DEFAULT_OPEN_DELIMITER = "<";
|
|
206
|
-
var _DEFAULT_CLOSE_DELIMITER = ">";
|
|
207
|
-
var _DEFAULT_DELIMITER = "%";
|
|
208
|
-
var _DEFAULT_LOCALS_NAME = "locals";
|
|
209
|
-
var _NAME = "ejs";
|
|
210
|
-
var _REGEX_STRING = "(<%%|%%>|<%=|<%-|<%_|<%#|<%|%>|-%>|_%>)";
|
|
211
|
-
var _OPTS_PASSABLE_WITH_DATA = [
|
|
212
|
-
"delimiter",
|
|
213
|
-
"scope",
|
|
214
|
-
"context",
|
|
215
|
-
"debug",
|
|
216
|
-
"compileDebug",
|
|
217
|
-
"client",
|
|
218
|
-
"_with",
|
|
219
|
-
"rmWhitespace",
|
|
220
|
-
"strict",
|
|
221
|
-
"filename",
|
|
222
|
-
"async"
|
|
223
|
-
];
|
|
224
|
-
var _OPTS_PASSABLE_WITH_DATA_EXPRESS = _OPTS_PASSABLE_WITH_DATA.concat("cache");
|
|
225
|
-
var _BOM = /^\uFEFF/;
|
|
226
|
-
var _JS_IDENTIFIER = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
|
|
227
|
-
exports.cache = utils2.cache;
|
|
228
|
-
exports.fileLoader = fs$1.readFileSync;
|
|
229
|
-
exports.localsName = _DEFAULT_LOCALS_NAME;
|
|
230
|
-
exports.promiseImpl = new Function("return this;")().Promise;
|
|
231
|
-
exports.resolveInclude = function(name, filename, isDir) {
|
|
232
|
-
var dirname = path$1.dirname;
|
|
233
|
-
var extname = path$1.extname;
|
|
234
|
-
var resolve = path$1.resolve;
|
|
235
|
-
var includePath = resolve(isDir ? filename : dirname(filename), name);
|
|
236
|
-
var ext = extname(name);
|
|
237
|
-
if (!ext) {
|
|
238
|
-
includePath += ".ejs";
|
|
239
|
-
}
|
|
240
|
-
return includePath;
|
|
241
|
-
};
|
|
242
|
-
function resolvePaths(name, paths) {
|
|
243
|
-
var filePath;
|
|
244
|
-
if (paths.some(function(v) {
|
|
245
|
-
filePath = exports.resolveInclude(name, v, true);
|
|
246
|
-
return fs$1.existsSync(filePath);
|
|
247
|
-
})) {
|
|
248
|
-
return filePath;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
function getIncludePath(path2, options) {
|
|
252
|
-
var includePath;
|
|
253
|
-
var filePath;
|
|
254
|
-
var views = options.views;
|
|
255
|
-
var match = /^[A-Za-z]+:\\|^\//.exec(path2);
|
|
256
|
-
if (match && match.length) {
|
|
257
|
-
path2 = path2.replace(/^\/*/, "");
|
|
258
|
-
if (Array.isArray(options.root)) {
|
|
259
|
-
includePath = resolvePaths(path2, options.root);
|
|
260
|
-
} else {
|
|
261
|
-
includePath = exports.resolveInclude(path2, options.root || "/", true);
|
|
262
|
-
}
|
|
263
|
-
} else {
|
|
264
|
-
if (options.filename) {
|
|
265
|
-
filePath = exports.resolveInclude(path2, options.filename);
|
|
266
|
-
if (fs$1.existsSync(filePath)) {
|
|
267
|
-
includePath = filePath;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
if (!includePath && Array.isArray(views)) {
|
|
271
|
-
includePath = resolvePaths(path2, views);
|
|
272
|
-
}
|
|
273
|
-
if (!includePath && typeof options.includer !== "function") {
|
|
274
|
-
throw new Error('Could not find the include file "' + options.escapeFunction(path2) + '"');
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
return includePath;
|
|
278
|
-
}
|
|
279
|
-
function handleCache(options, template) {
|
|
280
|
-
var func;
|
|
281
|
-
var filename = options.filename;
|
|
282
|
-
var hasTemplate = arguments.length > 1;
|
|
283
|
-
if (options.cache) {
|
|
284
|
-
if (!filename) {
|
|
285
|
-
throw new Error("cache option requires a filename");
|
|
286
|
-
}
|
|
287
|
-
func = exports.cache.get(filename);
|
|
288
|
-
if (func) {
|
|
289
|
-
return func;
|
|
290
|
-
}
|
|
291
|
-
if (!hasTemplate) {
|
|
292
|
-
template = fileLoader(filename).toString().replace(_BOM, "");
|
|
293
|
-
}
|
|
294
|
-
} else if (!hasTemplate) {
|
|
295
|
-
if (!filename) {
|
|
296
|
-
throw new Error("Internal EJS error: no file name or template provided");
|
|
297
|
-
}
|
|
298
|
-
template = fileLoader(filename).toString().replace(_BOM, "");
|
|
299
|
-
}
|
|
300
|
-
func = exports.compile(template, options);
|
|
301
|
-
if (options.cache) {
|
|
302
|
-
exports.cache.set(filename, func);
|
|
303
|
-
}
|
|
304
|
-
return func;
|
|
305
|
-
}
|
|
306
|
-
function tryHandleCache(options, data, cb) {
|
|
307
|
-
var result;
|
|
308
|
-
if (!cb) {
|
|
309
|
-
if (typeof exports.promiseImpl == "function") {
|
|
310
|
-
return new exports.promiseImpl(function(resolve, reject) {
|
|
311
|
-
try {
|
|
312
|
-
result = handleCache(options)(data);
|
|
313
|
-
resolve(result);
|
|
314
|
-
} catch (err) {
|
|
315
|
-
reject(err);
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
|
-
} else {
|
|
319
|
-
throw new Error("Please provide a callback function");
|
|
320
|
-
}
|
|
321
|
-
} else {
|
|
322
|
-
try {
|
|
323
|
-
result = handleCache(options)(data);
|
|
324
|
-
} catch (err) {
|
|
325
|
-
return cb(err);
|
|
326
|
-
}
|
|
327
|
-
cb(null, result);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
function fileLoader(filePath) {
|
|
331
|
-
return exports.fileLoader(filePath);
|
|
332
|
-
}
|
|
333
|
-
function includeFile(path2, options) {
|
|
334
|
-
var opts = utils2.shallowCopy(utils2.createNullProtoObjWherePossible(), options);
|
|
335
|
-
opts.filename = getIncludePath(path2, opts);
|
|
336
|
-
if (typeof options.includer === "function") {
|
|
337
|
-
var includerResult = options.includer(path2, opts.filename);
|
|
338
|
-
if (includerResult) {
|
|
339
|
-
if (includerResult.filename) {
|
|
340
|
-
opts.filename = includerResult.filename;
|
|
341
|
-
}
|
|
342
|
-
if (includerResult.template) {
|
|
343
|
-
return handleCache(opts, includerResult.template);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
return handleCache(opts);
|
|
348
|
-
}
|
|
349
|
-
function rethrow(err, str, flnm, lineno, esc) {
|
|
350
|
-
var lines = str.split("\n");
|
|
351
|
-
var start = Math.max(lineno - 3, 0);
|
|
352
|
-
var end = Math.min(lines.length, lineno + 3);
|
|
353
|
-
var filename = esc(flnm);
|
|
354
|
-
var context = lines.slice(start, end).map(function(line, i) {
|
|
355
|
-
var curr = i + start + 1;
|
|
356
|
-
return (curr == lineno ? " >> " : " ") + curr + "| " + line;
|
|
357
|
-
}).join("\n");
|
|
358
|
-
err.path = filename;
|
|
359
|
-
err.message = (filename || "ejs") + ":" + lineno + "\n" + context + "\n\n" + err.message;
|
|
360
|
-
throw err;
|
|
361
|
-
}
|
|
362
|
-
function stripSemi(str) {
|
|
363
|
-
return str.replace(/;(\s*$)/, "$1");
|
|
364
|
-
}
|
|
365
|
-
exports.compile = function compile(template, opts) {
|
|
366
|
-
var templ;
|
|
367
|
-
if (opts && opts.scope) {
|
|
368
|
-
if (!scopeOptionWarned) {
|
|
369
|
-
console.warn("`scope` option is deprecated and will be removed in EJS 3");
|
|
370
|
-
scopeOptionWarned = true;
|
|
371
|
-
}
|
|
372
|
-
if (!opts.context) {
|
|
373
|
-
opts.context = opts.scope;
|
|
374
|
-
}
|
|
375
|
-
delete opts.scope;
|
|
376
|
-
}
|
|
377
|
-
templ = new Template(template, opts);
|
|
378
|
-
return templ.compile();
|
|
379
|
-
};
|
|
380
|
-
exports.render = function(template, d, o) {
|
|
381
|
-
var data = d || utils2.createNullProtoObjWherePossible();
|
|
382
|
-
var opts = o || utils2.createNullProtoObjWherePossible();
|
|
383
|
-
if (arguments.length == 2) {
|
|
384
|
-
utils2.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA);
|
|
385
|
-
}
|
|
386
|
-
return handleCache(opts, template)(data);
|
|
387
|
-
};
|
|
388
|
-
exports.renderFile = function() {
|
|
389
|
-
var args = Array.prototype.slice.call(arguments);
|
|
390
|
-
var filename = args.shift();
|
|
391
|
-
var cb;
|
|
392
|
-
var opts = { filename };
|
|
393
|
-
var data;
|
|
394
|
-
var viewOpts;
|
|
395
|
-
if (typeof arguments[arguments.length - 1] == "function") {
|
|
396
|
-
cb = args.pop();
|
|
397
|
-
}
|
|
398
|
-
if (args.length) {
|
|
399
|
-
data = args.shift();
|
|
400
|
-
if (args.length) {
|
|
401
|
-
utils2.shallowCopy(opts, args.pop());
|
|
402
|
-
} else {
|
|
403
|
-
if (data.settings) {
|
|
404
|
-
if (data.settings.views) {
|
|
405
|
-
opts.views = data.settings.views;
|
|
406
|
-
}
|
|
407
|
-
if (data.settings["view cache"]) {
|
|
408
|
-
opts.cache = true;
|
|
409
|
-
}
|
|
410
|
-
viewOpts = data.settings["view options"];
|
|
411
|
-
if (viewOpts) {
|
|
412
|
-
utils2.shallowCopy(opts, viewOpts);
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
utils2.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA_EXPRESS);
|
|
416
|
-
}
|
|
417
|
-
opts.filename = filename;
|
|
418
|
-
} else {
|
|
419
|
-
data = utils2.createNullProtoObjWherePossible();
|
|
420
|
-
}
|
|
421
|
-
return tryHandleCache(opts, data, cb);
|
|
422
|
-
};
|
|
423
|
-
exports.Template = Template;
|
|
424
|
-
exports.clearCache = function() {
|
|
425
|
-
exports.cache.reset();
|
|
426
|
-
};
|
|
427
|
-
function Template(text, optsParam) {
|
|
428
|
-
var opts = utils2.hasOwnOnlyObject(optsParam);
|
|
429
|
-
var options = utils2.createNullProtoObjWherePossible();
|
|
430
|
-
this.templateText = text;
|
|
431
|
-
this.mode = null;
|
|
432
|
-
this.truncate = false;
|
|
433
|
-
this.currentLine = 1;
|
|
434
|
-
this.source = "";
|
|
435
|
-
options.client = opts.client || false;
|
|
436
|
-
options.escapeFunction = opts.escape || opts.escapeFunction || utils2.escapeXML;
|
|
437
|
-
options.compileDebug = opts.compileDebug !== false;
|
|
438
|
-
options.debug = !!opts.debug;
|
|
439
|
-
options.filename = opts.filename;
|
|
440
|
-
options.openDelimiter = opts.openDelimiter || exports.openDelimiter || _DEFAULT_OPEN_DELIMITER;
|
|
441
|
-
options.closeDelimiter = opts.closeDelimiter || exports.closeDelimiter || _DEFAULT_CLOSE_DELIMITER;
|
|
442
|
-
options.delimiter = opts.delimiter || exports.delimiter || _DEFAULT_DELIMITER;
|
|
443
|
-
options.strict = opts.strict || false;
|
|
444
|
-
options.context = opts.context;
|
|
445
|
-
options.cache = opts.cache || false;
|
|
446
|
-
options.rmWhitespace = opts.rmWhitespace;
|
|
447
|
-
options.root = opts.root;
|
|
448
|
-
options.includer = opts.includer;
|
|
449
|
-
options.outputFunctionName = opts.outputFunctionName;
|
|
450
|
-
options.localsName = opts.localsName || exports.localsName || _DEFAULT_LOCALS_NAME;
|
|
451
|
-
options.views = opts.views;
|
|
452
|
-
options.async = opts.async;
|
|
453
|
-
options.destructuredLocals = opts.destructuredLocals;
|
|
454
|
-
options.legacyInclude = typeof opts.legacyInclude != "undefined" ? !!opts.legacyInclude : true;
|
|
455
|
-
if (options.strict) {
|
|
456
|
-
options._with = false;
|
|
457
|
-
} else {
|
|
458
|
-
options._with = typeof opts._with != "undefined" ? opts._with : true;
|
|
459
|
-
}
|
|
460
|
-
this.opts = options;
|
|
461
|
-
this.regex = this.createRegex();
|
|
462
|
-
}
|
|
463
|
-
Template.modes = {
|
|
464
|
-
EVAL: "eval",
|
|
465
|
-
ESCAPED: "escaped",
|
|
466
|
-
RAW: "raw",
|
|
467
|
-
COMMENT: "comment",
|
|
468
|
-
LITERAL: "literal"
|
|
469
|
-
};
|
|
470
|
-
Template.prototype = {
|
|
471
|
-
createRegex: function() {
|
|
472
|
-
var str = _REGEX_STRING;
|
|
473
|
-
var delim = utils2.escapeRegExpChars(this.opts.delimiter);
|
|
474
|
-
var open = utils2.escapeRegExpChars(this.opts.openDelimiter);
|
|
475
|
-
var close = utils2.escapeRegExpChars(this.opts.closeDelimiter);
|
|
476
|
-
str = str.replace(/%/g, delim).replace(/</g, open).replace(/>/g, close);
|
|
477
|
-
return new RegExp(str);
|
|
478
|
-
},
|
|
479
|
-
compile: function() {
|
|
480
|
-
var src;
|
|
481
|
-
var fn;
|
|
482
|
-
var opts = this.opts;
|
|
483
|
-
var prepended = "";
|
|
484
|
-
var appended = "";
|
|
485
|
-
var escapeFn = opts.escapeFunction;
|
|
486
|
-
var ctor;
|
|
487
|
-
var sanitizedFilename = opts.filename ? JSON.stringify(opts.filename) : "undefined";
|
|
488
|
-
if (!this.source) {
|
|
489
|
-
this.generateSource();
|
|
490
|
-
prepended += ' var __output = "";\n function __append(s) { if (s !== undefined && s !== null) __output += s }\n';
|
|
491
|
-
if (opts.outputFunctionName) {
|
|
492
|
-
if (!_JS_IDENTIFIER.test(opts.outputFunctionName)) {
|
|
493
|
-
throw new Error("outputFunctionName is not a valid JS identifier.");
|
|
494
|
-
}
|
|
495
|
-
prepended += " var " + opts.outputFunctionName + " = __append;\n";
|
|
496
|
-
}
|
|
497
|
-
if (opts.localsName && !_JS_IDENTIFIER.test(opts.localsName)) {
|
|
498
|
-
throw new Error("localsName is not a valid JS identifier.");
|
|
499
|
-
}
|
|
500
|
-
if (opts.destructuredLocals && opts.destructuredLocals.length) {
|
|
501
|
-
var destructuring = " var __locals = (" + opts.localsName + " || {}),\n";
|
|
502
|
-
for (var i = 0; i < opts.destructuredLocals.length; i++) {
|
|
503
|
-
var name = opts.destructuredLocals[i];
|
|
504
|
-
if (!_JS_IDENTIFIER.test(name)) {
|
|
505
|
-
throw new Error("destructuredLocals[" + i + "] is not a valid JS identifier.");
|
|
506
|
-
}
|
|
507
|
-
if (i > 0) {
|
|
508
|
-
destructuring += ",\n ";
|
|
509
|
-
}
|
|
510
|
-
destructuring += name + " = __locals." + name;
|
|
511
|
-
}
|
|
512
|
-
prepended += destructuring + ";\n";
|
|
513
|
-
}
|
|
514
|
-
if (opts._with !== false) {
|
|
515
|
-
prepended += " with (" + opts.localsName + " || {}) {\n";
|
|
516
|
-
appended += " }\n";
|
|
517
|
-
}
|
|
518
|
-
appended += " return __output;\n";
|
|
519
|
-
this.source = prepended + this.source + appended;
|
|
520
|
-
}
|
|
521
|
-
if (opts.compileDebug) {
|
|
522
|
-
src = "var __line = 1\n , __lines = " + JSON.stringify(this.templateText) + "\n , __filename = " + sanitizedFilename + ";\ntry {\n" + this.source + "} catch (e) {\n rethrow(e, __lines, __filename, __line, escapeFn);\n}\n";
|
|
523
|
-
} else {
|
|
524
|
-
src = this.source;
|
|
525
|
-
}
|
|
526
|
-
if (opts.client) {
|
|
527
|
-
src = "escapeFn = escapeFn || " + escapeFn.toString() + ";\n" + src;
|
|
528
|
-
if (opts.compileDebug) {
|
|
529
|
-
src = "rethrow = rethrow || " + rethrow.toString() + ";\n" + src;
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
if (opts.strict) {
|
|
533
|
-
src = '"use strict";\n' + src;
|
|
534
|
-
}
|
|
535
|
-
if (opts.debug) {
|
|
536
|
-
console.log(src);
|
|
537
|
-
}
|
|
538
|
-
if (opts.compileDebug && opts.filename) {
|
|
539
|
-
src = src + "\n//# sourceURL=" + sanitizedFilename + "\n";
|
|
540
|
-
}
|
|
541
|
-
try {
|
|
542
|
-
if (opts.async) {
|
|
543
|
-
try {
|
|
544
|
-
ctor = new Function("return (async function(){}).constructor;")();
|
|
545
|
-
} catch (e) {
|
|
546
|
-
if (e instanceof SyntaxError) {
|
|
547
|
-
throw new Error("This environment does not support async/await");
|
|
548
|
-
} else {
|
|
549
|
-
throw e;
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
} else {
|
|
553
|
-
ctor = Function;
|
|
554
|
-
}
|
|
555
|
-
fn = new ctor(opts.localsName + ", escapeFn, include, rethrow", src);
|
|
556
|
-
} catch (e) {
|
|
557
|
-
if (e instanceof SyntaxError) {
|
|
558
|
-
if (opts.filename) {
|
|
559
|
-
e.message += " in " + opts.filename;
|
|
560
|
-
}
|
|
561
|
-
e.message += " while compiling ejs\n\n";
|
|
562
|
-
e.message += "If the above error is not helpful, you may want to try EJS-Lint:\n";
|
|
563
|
-
e.message += "https://github.com/RyanZim/EJS-Lint";
|
|
564
|
-
if (!opts.async) {
|
|
565
|
-
e.message += "\n";
|
|
566
|
-
e.message += "Or, if you meant to create an async function, pass `async: true` as an option.";
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
throw e;
|
|
570
|
-
}
|
|
571
|
-
var returnedFn = opts.client ? fn : function anonymous(data) {
|
|
572
|
-
var include = function(path2, includeData) {
|
|
573
|
-
var d = utils2.shallowCopy(utils2.createNullProtoObjWherePossible(), data);
|
|
574
|
-
if (includeData) {
|
|
575
|
-
d = utils2.shallowCopy(d, includeData);
|
|
576
|
-
}
|
|
577
|
-
return includeFile(path2, opts)(d);
|
|
578
|
-
};
|
|
579
|
-
return fn.apply(
|
|
580
|
-
opts.context,
|
|
581
|
-
[data || utils2.createNullProtoObjWherePossible(), escapeFn, include, rethrow]
|
|
582
|
-
);
|
|
583
|
-
};
|
|
584
|
-
if (opts.filename && typeof Object.defineProperty === "function") {
|
|
585
|
-
var filename = opts.filename;
|
|
586
|
-
var basename = path$1.basename(filename, path$1.extname(filename));
|
|
587
|
-
try {
|
|
588
|
-
Object.defineProperty(returnedFn, "name", {
|
|
589
|
-
value: basename,
|
|
590
|
-
writable: false,
|
|
591
|
-
enumerable: false,
|
|
592
|
-
configurable: true
|
|
593
|
-
});
|
|
594
|
-
} catch (e) {
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
return returnedFn;
|
|
598
|
-
},
|
|
599
|
-
generateSource: function() {
|
|
600
|
-
var opts = this.opts;
|
|
601
|
-
if (opts.rmWhitespace) {
|
|
602
|
-
this.templateText = this.templateText.replace(/[\r\n]+/g, "\n").replace(/^\s+|\s+$/gm, "");
|
|
603
|
-
}
|
|
604
|
-
this.templateText = this.templateText.replace(/[ \t]*<%_/gm, "<%_").replace(/_%>[ \t]*/gm, "_%>");
|
|
605
|
-
var self = this;
|
|
606
|
-
var matches = this.parseTemplateText();
|
|
607
|
-
var d = this.opts.delimiter;
|
|
608
|
-
var o = this.opts.openDelimiter;
|
|
609
|
-
var c = this.opts.closeDelimiter;
|
|
610
|
-
if (matches && matches.length) {
|
|
611
|
-
matches.forEach(function(line, index) {
|
|
612
|
-
var closing;
|
|
613
|
-
if (line.indexOf(o + d) === 0 && line.indexOf(o + d + d) !== 0) {
|
|
614
|
-
closing = matches[index + 2];
|
|
615
|
-
if (!(closing == d + c || closing == "-" + d + c || closing == "_" + d + c)) {
|
|
616
|
-
throw new Error('Could not find matching close tag for "' + line + '".');
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
self.scanLine(line);
|
|
620
|
-
});
|
|
621
|
-
}
|
|
622
|
-
},
|
|
623
|
-
parseTemplateText: function() {
|
|
624
|
-
var str = this.templateText;
|
|
625
|
-
var pat = this.regex;
|
|
626
|
-
var result = pat.exec(str);
|
|
627
|
-
var arr = [];
|
|
628
|
-
var firstPos;
|
|
629
|
-
while (result) {
|
|
630
|
-
firstPos = result.index;
|
|
631
|
-
if (firstPos !== 0) {
|
|
632
|
-
arr.push(str.substring(0, firstPos));
|
|
633
|
-
str = str.slice(firstPos);
|
|
634
|
-
}
|
|
635
|
-
arr.push(result[0]);
|
|
636
|
-
str = str.slice(result[0].length);
|
|
637
|
-
result = pat.exec(str);
|
|
638
|
-
}
|
|
639
|
-
if (str) {
|
|
640
|
-
arr.push(str);
|
|
641
|
-
}
|
|
642
|
-
return arr;
|
|
643
|
-
},
|
|
644
|
-
_addOutput: function(line) {
|
|
645
|
-
if (this.truncate) {
|
|
646
|
-
line = line.replace(/^(?:\r\n|\r|\n)/, "");
|
|
647
|
-
this.truncate = false;
|
|
648
|
-
}
|
|
649
|
-
if (!line) {
|
|
650
|
-
return line;
|
|
651
|
-
}
|
|
652
|
-
line = line.replace(/\\/g, "\\\\");
|
|
653
|
-
line = line.replace(/\n/g, "\\n");
|
|
654
|
-
line = line.replace(/\r/g, "\\r");
|
|
655
|
-
line = line.replace(/"/g, '\\"');
|
|
656
|
-
this.source += ' ; __append("' + line + '")\n';
|
|
657
|
-
},
|
|
658
|
-
scanLine: function(line) {
|
|
659
|
-
var self = this;
|
|
660
|
-
var d = this.opts.delimiter;
|
|
661
|
-
var o = this.opts.openDelimiter;
|
|
662
|
-
var c = this.opts.closeDelimiter;
|
|
663
|
-
var newLineCount = 0;
|
|
664
|
-
newLineCount = line.split("\n").length - 1;
|
|
665
|
-
switch (line) {
|
|
666
|
-
case o + d:
|
|
667
|
-
case o + d + "_":
|
|
668
|
-
this.mode = Template.modes.EVAL;
|
|
669
|
-
break;
|
|
670
|
-
case o + d + "=":
|
|
671
|
-
this.mode = Template.modes.ESCAPED;
|
|
672
|
-
break;
|
|
673
|
-
case o + d + "-":
|
|
674
|
-
this.mode = Template.modes.RAW;
|
|
675
|
-
break;
|
|
676
|
-
case o + d + "#":
|
|
677
|
-
this.mode = Template.modes.COMMENT;
|
|
678
|
-
break;
|
|
679
|
-
case o + d + d:
|
|
680
|
-
this.mode = Template.modes.LITERAL;
|
|
681
|
-
this.source += ' ; __append("' + line.replace(o + d + d, o + d) + '")\n';
|
|
682
|
-
break;
|
|
683
|
-
case d + d + c:
|
|
684
|
-
this.mode = Template.modes.LITERAL;
|
|
685
|
-
this.source += ' ; __append("' + line.replace(d + d + c, d + c) + '")\n';
|
|
686
|
-
break;
|
|
687
|
-
case d + c:
|
|
688
|
-
case "-" + d + c:
|
|
689
|
-
case "_" + d + c:
|
|
690
|
-
if (this.mode == Template.modes.LITERAL) {
|
|
691
|
-
this._addOutput(line);
|
|
692
|
-
}
|
|
693
|
-
this.mode = null;
|
|
694
|
-
this.truncate = line.indexOf("-") === 0 || line.indexOf("_") === 0;
|
|
695
|
-
break;
|
|
696
|
-
default:
|
|
697
|
-
if (this.mode) {
|
|
698
|
-
switch (this.mode) {
|
|
699
|
-
case Template.modes.EVAL:
|
|
700
|
-
case Template.modes.ESCAPED:
|
|
701
|
-
case Template.modes.RAW:
|
|
702
|
-
if (line.lastIndexOf("//") > line.lastIndexOf("\n")) {
|
|
703
|
-
line += "\n";
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
switch (this.mode) {
|
|
707
|
-
// Just executing code
|
|
708
|
-
case Template.modes.EVAL:
|
|
709
|
-
this.source += " ; " + line + "\n";
|
|
710
|
-
break;
|
|
711
|
-
// Exec, esc, and output
|
|
712
|
-
case Template.modes.ESCAPED:
|
|
713
|
-
this.source += " ; __append(escapeFn(" + stripSemi(line) + "))\n";
|
|
714
|
-
break;
|
|
715
|
-
// Exec and output
|
|
716
|
-
case Template.modes.RAW:
|
|
717
|
-
this.source += " ; __append(" + stripSemi(line) + ")\n";
|
|
718
|
-
break;
|
|
719
|
-
case Template.modes.COMMENT:
|
|
720
|
-
break;
|
|
721
|
-
// Literal <%% mode, append as raw output
|
|
722
|
-
case Template.modes.LITERAL:
|
|
723
|
-
this._addOutput(line);
|
|
724
|
-
break;
|
|
725
|
-
}
|
|
726
|
-
} else {
|
|
727
|
-
this._addOutput(line);
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
if (self.opts.compileDebug && newLineCount) {
|
|
731
|
-
this.currentLine += newLineCount;
|
|
732
|
-
this.source += " ; __line = " + this.currentLine + "\n";
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
};
|
|
736
|
-
exports.escapeXML = utils2.escapeXML;
|
|
737
|
-
exports.__express = exports.renderFile;
|
|
738
|
-
exports.VERSION = _VERSION_STRING;
|
|
739
|
-
exports.name = _NAME;
|
|
740
|
-
if (typeof window != "undefined") {
|
|
741
|
-
window.ejs = exports;
|
|
742
|
-
}
|
|
743
|
-
})(ejs$1);
|
|
744
|
-
return ejs$1;
|
|
745
|
-
}
|
|
746
|
-
requireEjs();
|
|
747
|
-
|
|
748
|
-
function getDefaultExportFromCjs (x) {
|
|
749
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
var Case$2 = {exports: {}};
|
|
753
|
-
|
|
754
|
-
var Case$1 = Case$2.exports;
|
|
755
|
-
|
|
756
|
-
var hasRequiredCase;
|
|
757
|
-
|
|
758
|
-
function requireCase () {
|
|
759
|
-
if (hasRequiredCase) return Case$2.exports;
|
|
760
|
-
hasRequiredCase = 1;
|
|
761
|
-
(function (module) {
|
|
762
|
-
/*! Case - v1.6.2 - 2020-03-24
|
|
763
|
-
* Copyright (c) 2020 Nathan Bubna; Licensed MIT, GPL */
|
|
764
|
-
(function() {
|
|
765
|
-
var unicodes = function(s, prefix) {
|
|
766
|
-
prefix = prefix || "";
|
|
767
|
-
return s.replace(/(^|-)/g, "$1\\u" + prefix).replace(/,/g, "\\u" + prefix);
|
|
768
|
-
}, basicSymbols = unicodes("20-26,28-2F,3A-40,5B-60,7B-7E,A0-BF,D7,F7", "00"), baseLowerCase = "a-z" + unicodes("DF-F6,F8-FF", "00"), baseUpperCase = "A-Z" + unicodes("C0-D6,D8-DE", "00"), improperInTitle = "A|An|And|As|At|But|By|En|For|If|In|Of|On|Or|The|To|Vs?\\.?|Via", regexps = function(symbols, lowers, uppers, impropers) {
|
|
769
|
-
symbols = symbols || basicSymbols;
|
|
770
|
-
lowers = lowers || baseLowerCase;
|
|
771
|
-
uppers = uppers || baseUpperCase;
|
|
772
|
-
impropers = impropers || improperInTitle;
|
|
773
|
-
return {
|
|
774
|
-
capitalize: new RegExp("(^|[" + symbols + "])([" + lowers + "])", "g"),
|
|
775
|
-
pascal: new RegExp("(^|[" + symbols + "])+([" + lowers + uppers + "])", "g"),
|
|
776
|
-
fill: new RegExp("[" + symbols + "]+(.|$)", "g"),
|
|
777
|
-
sentence: new RegExp('(^\\s*|[\\?\\!\\.]+"?\\s+"?|,\\s+")([' + lowers + "])", "g"),
|
|
778
|
-
improper: new RegExp("\\b(" + impropers + ")\\b", "g"),
|
|
779
|
-
relax: new RegExp("([^" + uppers + "])([" + uppers + "]*)([" + uppers + "])(?=[^" + uppers + "]|$)", "g"),
|
|
780
|
-
upper: new RegExp("^[^" + lowers + "]+$"),
|
|
781
|
-
hole: /[^\s]\s[^\s]/,
|
|
782
|
-
apostrophe: /'/g,
|
|
783
|
-
room: new RegExp("[" + symbols + "]")
|
|
784
|
-
};
|
|
785
|
-
}, re = regexps(), _ = {
|
|
786
|
-
re,
|
|
787
|
-
unicodes,
|
|
788
|
-
regexps,
|
|
789
|
-
types: [],
|
|
790
|
-
up: String.prototype.toUpperCase,
|
|
791
|
-
low: String.prototype.toLowerCase,
|
|
792
|
-
cap: function(s) {
|
|
793
|
-
return _.up.call(s.charAt(0)) + s.slice(1);
|
|
794
|
-
},
|
|
795
|
-
decap: function(s) {
|
|
796
|
-
return _.low.call(s.charAt(0)) + s.slice(1);
|
|
797
|
-
},
|
|
798
|
-
deapostrophe: function(s) {
|
|
799
|
-
return s.replace(re.apostrophe, "");
|
|
800
|
-
},
|
|
801
|
-
fill: function(s, fill, deapostrophe) {
|
|
802
|
-
if (fill != null) {
|
|
803
|
-
s = s.replace(re.fill, function(m, next) {
|
|
804
|
-
return next ? fill + next : "";
|
|
805
|
-
});
|
|
806
|
-
}
|
|
807
|
-
if (deapostrophe) {
|
|
808
|
-
s = _.deapostrophe(s);
|
|
809
|
-
}
|
|
810
|
-
return s;
|
|
811
|
-
},
|
|
812
|
-
prep: function(s, fill, pascal, upper) {
|
|
813
|
-
s = s == null ? "" : s + "";
|
|
814
|
-
if (!upper && re.upper.test(s)) {
|
|
815
|
-
s = _.low.call(s);
|
|
816
|
-
}
|
|
817
|
-
if (!fill && !re.hole.test(s)) {
|
|
818
|
-
var holey = _.fill(s, " ");
|
|
819
|
-
if (re.hole.test(holey)) {
|
|
820
|
-
s = holey;
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
if (!pascal && !re.room.test(s)) {
|
|
824
|
-
s = s.replace(re.relax, _.relax);
|
|
825
|
-
}
|
|
826
|
-
return s;
|
|
827
|
-
},
|
|
828
|
-
relax: function(m, before, acronym, caps) {
|
|
829
|
-
return before + " " + (acronym ? acronym + " " : "") + caps;
|
|
830
|
-
}
|
|
831
|
-
}, Case = {
|
|
832
|
-
_,
|
|
833
|
-
of: function(s) {
|
|
834
|
-
for (var i = 0, m = _.types.length; i < m; i++) {
|
|
835
|
-
if (Case[_.types[i]].apply(Case, arguments) === s) {
|
|
836
|
-
return _.types[i];
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
},
|
|
840
|
-
flip: function(s) {
|
|
841
|
-
return s.replace(/\w/g, function(l) {
|
|
842
|
-
return (l == _.up.call(l) ? _.low : _.up).call(l);
|
|
843
|
-
});
|
|
844
|
-
},
|
|
845
|
-
random: function(s) {
|
|
846
|
-
return s.replace(/\w/g, function(l) {
|
|
847
|
-
return (Math.round(Math.random()) ? _.up : _.low).call(l);
|
|
848
|
-
});
|
|
849
|
-
},
|
|
850
|
-
type: function(type2, fn) {
|
|
851
|
-
Case[type2] = fn;
|
|
852
|
-
_.types.push(type2);
|
|
853
|
-
}
|
|
854
|
-
}, types = {
|
|
855
|
-
lower: function(s, fill, deapostrophe) {
|
|
856
|
-
return _.fill(_.low.call(_.prep(s, fill)), fill, deapostrophe);
|
|
857
|
-
},
|
|
858
|
-
snake: function(s) {
|
|
859
|
-
return Case.lower(s, "_", true);
|
|
860
|
-
},
|
|
861
|
-
constant: function(s) {
|
|
862
|
-
return Case.upper(s, "_", true);
|
|
863
|
-
},
|
|
864
|
-
camel: function(s) {
|
|
865
|
-
return _.decap(Case.pascal(s));
|
|
866
|
-
},
|
|
867
|
-
kebab: function(s) {
|
|
868
|
-
return Case.lower(s, "-", true);
|
|
869
|
-
},
|
|
870
|
-
upper: function(s, fill, deapostrophe) {
|
|
871
|
-
return _.fill(_.up.call(_.prep(s, fill, false, true)), fill, deapostrophe);
|
|
872
|
-
},
|
|
873
|
-
capital: function(s, fill, deapostrophe) {
|
|
874
|
-
return _.fill(_.prep(s).replace(re.capitalize, function(m, border, letter) {
|
|
875
|
-
return border + _.up.call(letter);
|
|
876
|
-
}), fill, deapostrophe);
|
|
877
|
-
},
|
|
878
|
-
header: function(s) {
|
|
879
|
-
return Case.capital(s, "-", true);
|
|
880
|
-
},
|
|
881
|
-
pascal: function(s) {
|
|
882
|
-
return _.fill(_.prep(s, false, true).replace(re.pascal, function(m, border, letter) {
|
|
883
|
-
return _.up.call(letter);
|
|
884
|
-
}), "", true);
|
|
885
|
-
},
|
|
886
|
-
title: function(s) {
|
|
887
|
-
return Case.capital(s).replace(re.improper, function(small, p, i, s2) {
|
|
888
|
-
return i > 0 && i < s2.lastIndexOf(" ") ? _.low.call(small) : small;
|
|
889
|
-
});
|
|
890
|
-
},
|
|
891
|
-
sentence: function(s, names, abbreviations) {
|
|
892
|
-
s = Case.lower(s).replace(re.sentence, function(m, prelude, letter) {
|
|
893
|
-
return prelude + _.up.call(letter);
|
|
894
|
-
});
|
|
895
|
-
if (names) {
|
|
896
|
-
names.forEach(function(name) {
|
|
897
|
-
s = s.replace(new RegExp("\\b" + Case.lower(name) + "\\b", "g"), _.cap);
|
|
898
|
-
});
|
|
899
|
-
}
|
|
900
|
-
if (abbreviations) {
|
|
901
|
-
abbreviations.forEach(function(abbr) {
|
|
902
|
-
s = s.replace(new RegExp("(\\b" + Case.lower(abbr) + "\\. +)(\\w)"), function(m, abbrAndSpace, letter) {
|
|
903
|
-
return abbrAndSpace + _.low.call(letter);
|
|
904
|
-
});
|
|
905
|
-
});
|
|
906
|
-
}
|
|
907
|
-
return s;
|
|
908
|
-
}
|
|
909
|
-
};
|
|
910
|
-
types.squish = types.pascal;
|
|
911
|
-
Case.default = Case;
|
|
912
|
-
for (var type in types) {
|
|
913
|
-
Case.type(type, types[type]);
|
|
914
|
-
}
|
|
915
|
-
var define = typeof define === "function" ? define : function() {
|
|
916
|
-
};
|
|
917
|
-
define(module.exports ? module.exports = Case : this.Case = Case);
|
|
918
|
-
}).call(Case$1);
|
|
919
|
-
} (Case$2));
|
|
920
|
-
return Case$2.exports;
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
var CaseExports = requireCase();
|
|
924
|
-
var Case = /*@__PURE__*/getDefaultExportFromCjs(CaseExports);
|
|
5
|
+
import { TsTypePrinter, TsTypeNode } from '@rexeus/typeweaver-zod-to-ts';
|
|
925
6
|
|
|
926
7
|
const __dirname$1 = path.dirname(fileURLToPath(import.meta.url));
|
|
927
8
|
class ClientGenerator {
|
|
928
9
|
static generate(context) {
|
|
929
|
-
const
|
|
10
|
+
const clientTemplatePath = path.join(__dirname$1, "templates", "Client.ejs");
|
|
11
|
+
const commandTemplatePath = path.join(
|
|
12
|
+
__dirname$1,
|
|
13
|
+
"templates",
|
|
14
|
+
"RequestCommand.ejs"
|
|
15
|
+
);
|
|
930
16
|
for (const [, operationResources] of Object.entries(
|
|
931
17
|
context.resources.entityResources
|
|
932
18
|
)) {
|
|
933
|
-
this.writeClient(
|
|
19
|
+
this.writeClient(clientTemplatePath, operationResources, context);
|
|
20
|
+
this.writeRequestCommands(
|
|
21
|
+
commandTemplatePath,
|
|
22
|
+
operationResources,
|
|
23
|
+
context
|
|
24
|
+
);
|
|
934
25
|
}
|
|
935
26
|
}
|
|
936
27
|
static writeClient(templateFilePath, operationResources, context) {
|
|
@@ -970,6 +61,74 @@ class ClientGenerator {
|
|
|
970
61
|
const relativePath = path.relative(context.outputDir, outputClientFile);
|
|
971
62
|
context.writeFile(relativePath, content);
|
|
972
63
|
}
|
|
64
|
+
static writeRequestCommands(templateFilePath, operationResources, context) {
|
|
65
|
+
for (const operationResource of operationResources) {
|
|
66
|
+
this.writeRequestCommand(templateFilePath, operationResource, context);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
static writeRequestCommand(templateFilePath, operationResource, context) {
|
|
70
|
+
const {
|
|
71
|
+
definition,
|
|
72
|
+
sourceDir,
|
|
73
|
+
sourceFile,
|
|
74
|
+
outputDir,
|
|
75
|
+
outputResponseFileName,
|
|
76
|
+
outputResponseValidationFileName,
|
|
77
|
+
outputRequestFileName
|
|
78
|
+
} = operationResource;
|
|
79
|
+
const { operationId, method, request, responses } = definition;
|
|
80
|
+
const pascalCaseOperationId = Case.pascal(operationId);
|
|
81
|
+
const allResponses = responses;
|
|
82
|
+
const ownSuccessResponses = allResponses.filter(
|
|
83
|
+
(r) => r.statusCode >= 200 && r.statusCode < 300 && !r.isShared
|
|
84
|
+
);
|
|
85
|
+
const ownErrorResponses = allResponses.filter(
|
|
86
|
+
(r) => (r.statusCode < 200 || r.statusCode >= 300) && !r.isShared
|
|
87
|
+
);
|
|
88
|
+
const sharedSuccessResponses = allResponses.filter(
|
|
89
|
+
(r) => r.statusCode >= 200 && r.statusCode < 300 && r.isShared
|
|
90
|
+
);
|
|
91
|
+
const sharedErrorResponses = allResponses.filter(
|
|
92
|
+
(r) => (r.statusCode < 200 || r.statusCode >= 300) && r.isShared
|
|
93
|
+
);
|
|
94
|
+
const headerTsType = request.header ? TsTypePrinter.print(TsTypeNode.fromZod(request.header)) : void 0;
|
|
95
|
+
const paramTsType = request.param ? TsTypePrinter.print(TsTypeNode.fromZod(request.param)) : void 0;
|
|
96
|
+
const queryTsType = request.query ? TsTypePrinter.print(TsTypeNode.fromZod(request.query)) : void 0;
|
|
97
|
+
const bodyTsType = request.body ? TsTypePrinter.print(TsTypeNode.fromZod(request.body)) : void 0;
|
|
98
|
+
const successResponseImportPath = (response) => {
|
|
99
|
+
if (response.isShared && response.path) {
|
|
100
|
+
return response.path;
|
|
101
|
+
}
|
|
102
|
+
return `./${path.basename(outputResponseFileName, ".ts")}`;
|
|
103
|
+
};
|
|
104
|
+
const requestFile = `./${path.basename(outputRequestFileName, ".ts")}`;
|
|
105
|
+
const responseValidatorFile = `./${path.basename(outputResponseValidationFileName, ".ts")}`;
|
|
106
|
+
const sourcePath = path.join(sourceDir, path.basename(sourceFile, ".ts"));
|
|
107
|
+
const relativeSourcePath = path.relative(outputDir, sourcePath);
|
|
108
|
+
const content = context.renderTemplate(templateFilePath, {
|
|
109
|
+
sourcePath: relativeSourcePath,
|
|
110
|
+
operationId,
|
|
111
|
+
pascalCaseOperationId,
|
|
112
|
+
method,
|
|
113
|
+
headerTsType,
|
|
114
|
+
paramTsType,
|
|
115
|
+
queryTsType,
|
|
116
|
+
bodyTsType,
|
|
117
|
+
ownSuccessResponses,
|
|
118
|
+
ownErrorResponses,
|
|
119
|
+
sharedSuccessResponses,
|
|
120
|
+
sharedErrorResponses,
|
|
121
|
+
requestFile,
|
|
122
|
+
responseValidatorFile,
|
|
123
|
+
successResponseImportPath
|
|
124
|
+
});
|
|
125
|
+
const outputCommandFile = path.join(
|
|
126
|
+
outputDir,
|
|
127
|
+
`${pascalCaseOperationId}RequestCommand.ts`
|
|
128
|
+
);
|
|
129
|
+
const relativePath = path.relative(context.outputDir, outputCommandFile);
|
|
130
|
+
context.writeFile(relativePath, content);
|
|
131
|
+
}
|
|
973
132
|
}
|
|
974
133
|
|
|
975
134
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|