node-tao 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +230 -0
  2. package/checks.d.ts +8 -0
  3. package/checks.d.ts.map +1 -0
  4. package/checks.js +37 -0
  5. package/checks.js.map +1 -0
  6. package/const.d.ts +24 -0
  7. package/const.d.ts.map +1 -0
  8. package/const.js +51 -0
  9. package/const.js.map +1 -0
  10. package/default-config.d.ts +4 -0
  11. package/default-config.d.ts.map +1 -0
  12. package/default-config.js +25 -0
  13. package/default-config.js.map +1 -0
  14. package/error/error.html +259 -0
  15. package/error-utils.d.ts +21 -0
  16. package/error-utils.d.ts.map +1 -0
  17. package/error-utils.js +163 -0
  18. package/error-utils.js.map +1 -0
  19. package/index.d.ts +3 -0
  20. package/index.d.ts.map +1 -0
  21. package/index.js +6 -0
  22. package/index.js.map +1 -0
  23. package/init.d.ts +12 -0
  24. package/init.d.ts.map +1 -0
  25. package/init.js +31 -0
  26. package/init.js.map +1 -0
  27. package/interfaces.d.ts +170 -0
  28. package/interfaces.d.ts.map +1 -0
  29. package/interfaces.js +3 -0
  30. package/interfaces.js.map +1 -0
  31. package/metrics.d.ts +16 -0
  32. package/metrics.d.ts.map +1 -0
  33. package/metrics.js +80 -0
  34. package/metrics.js.map +1 -0
  35. package/package.json +45 -0
  36. package/parsing-helpers.d.ts +8 -0
  37. package/parsing-helpers.d.ts.map +1 -0
  38. package/parsing-helpers.js +60 -0
  39. package/parsing-helpers.js.map +1 -0
  40. package/store.d.ts +29 -0
  41. package/store.d.ts.map +1 -0
  42. package/store.js +52 -0
  43. package/store.js.map +1 -0
  44. package/tao.d.ts +81 -0
  45. package/tao.d.ts.map +1 -0
  46. package/tao.js +533 -0
  47. package/tao.js.map +1 -0
  48. package/templates-access.d.ts +15 -0
  49. package/templates-access.d.ts.map +1 -0
  50. package/templates-access.js +38 -0
  51. package/templates-access.js.map +1 -0
  52. package/utils.d.ts +45 -0
  53. package/utils.d.ts.map +1 -0
  54. package/utils.js +227 -0
  55. package/utils.js.map +1 -0
package/tao.js ADDED
@@ -0,0 +1,533 @@
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.Tao = void 0;
7
+ const default_config_1 = require("./default-config");
8
+ const checks_1 = require("./checks");
9
+ const templates_access_1 = require("./templates-access");
10
+ const node_fs_1 = __importDefault(require("node:fs"));
11
+ const utils_1 = require("./utils");
12
+ const const_1 = require("./const");
13
+ const store_1 = require("./store");
14
+ const error_utils_1 = require("./error-utils");
15
+ const node_path_1 = __importDefault(require("node:path"));
16
+ const node_perf_hooks_1 = require("node:perf_hooks");
17
+ const metrics_1 = require("./metrics");
18
+ const init_1 = require("./init");
19
+ const parsing_helpers_1 = require("./parsing-helpers");
20
+ class Tao {
21
+ constructor(customConfig = {}) {
22
+ this.templatePaths = [];
23
+ this.prefixBuild = '';
24
+ /**
25
+ * Stores already compiled templates.
26
+ */
27
+ this.compiledStore = new store_1.Store();
28
+ /**
29
+ * Stores dynamically defined templates.
30
+ */
31
+ this.dynamictemplatesStore = new store_1.Store();
32
+ /**
33
+ * Stores global helpers.
34
+ */
35
+ this.helpersStore = new store_1.Store();
36
+ // Metrics - DX
37
+ this.parentTemplate = '';
38
+ // Metrics - DX
39
+ this.childrenStore = new store_1.Store();
40
+ this.config = Object.assign(Object.assign({}, default_config_1.defaultConfig), customConfig);
41
+ this.initializeConfig();
42
+ }
43
+ initializeConfig() {
44
+ const { views, extension, tags, parse } = this.config;
45
+ this.config.tags = (0, init_1.assignTags)(tags);
46
+ this.config.parse = (0, init_1.assignParse)(parse);
47
+ this.config.extension = (0, checks_1.trimDotFromExtension)(extension);
48
+ (0, checks_1.checkOpeningAndClosingTag)(this.config.tags);
49
+ (0, checks_1.checkPrefixTemplateTags)(this.config.parse);
50
+ this.prefixBuild = (0, utils_1.buildPrefixRegex)(this.config.parse);
51
+ this.templatePaths = (0, templates_access_1.getFilesFromDirectory)(views, this.config.extension);
52
+ }
53
+ /**
54
+ * Get an array of absolute paths of the mapped files according to the view directory provided.
55
+ */
56
+ get mappedFiles() {
57
+ return this.templatePaths.slice();
58
+ }
59
+ getMetrics(filename) {
60
+ const { development, cache } = this.config;
61
+ const metricsData = {
62
+ development,
63
+ files: this.mappedFiles,
64
+ filename,
65
+ cacheEnabled: cache,
66
+ };
67
+ return metricsData;
68
+ }
69
+ compileChild(content, debugData) {
70
+ const compiledAST = this.parse(content, debugData);
71
+ const result = `
72
+ ${(0, utils_1.includeFn)()}
73
+
74
+ ${const_1.PLACEHOLDER_VAR_START}
75
+ ${const_1.PLACEHOLDER_VAR_END}
76
+
77
+ const ${const_1.TP_VARNAME_WITH_PREFIX} = {res: "", e: this.config.escapeFunction};
78
+
79
+ ${(0, utils_1.compileBody)(compiledAST, this.config)}
80
+
81
+ return ${const_1.TP_VARNAME_WITH_PREFIX}.res;
82
+ `;
83
+ return result;
84
+ }
85
+ compile(content, filename, debugData) {
86
+ const { development } = this.config;
87
+ const compiledAST = this.parse(content, debugData);
88
+ this.childrenStore.set(this.parentTemplate, []);
89
+ const metricsData = this.getMetrics(filename);
90
+ const result = `
91
+ ${(0, utils_1.includeFn)()}
92
+
93
+ ${const_1.PLACEHOLDER_VAR_START}
94
+ ${const_1.PLACEHOLDER_VAR_END}
95
+
96
+ const ${const_1.TP_VARNAME_WITH_PREFIX} = {res: "", e: this.config.escapeFunction};
97
+
98
+ ${(0, utils_1.compileBody)(compiledAST, this.config)}
99
+
100
+ ${(0, metrics_1.includeChildren)(development)}
101
+ ${(0, metrics_1.includeRenderTime)(development)}
102
+ ${const_1.TP_VARNAME_WITH_PREFIX}.res += ${(0, metrics_1.includeMetrics)(metricsData)}
103
+
104
+
105
+ return ${const_1.TP_VARNAME_WITH_PREFIX}.res;
106
+ `;
107
+ return result;
108
+ }
109
+ parse(expression, debugData) {
110
+ const { parse, tags } = this.config;
111
+ const { closing, opening } = tags;
112
+ let openingResult = null;
113
+ const compiledData = [];
114
+ let lastIndex = 0;
115
+ const parseOpenReg = new RegExp((0, utils_1.escapeRegExp)(opening) + '\\s*(' + this.prefixBuild + ')?\\s*', 'g');
116
+ const parseCloseReg = new RegExp('\'|"|`|(\\s*' + (0, utils_1.escapeRegExp)(closing) + ')', 'g');
117
+ while ((openingResult = parseOpenReg.exec(expression))) {
118
+ // openingPrefix by default either ~, =, or empty
119
+ const [originalOpen, openingPrefix = ''] = openingResult;
120
+ let closeResult = null;
121
+ let templateData = undefined;
122
+ const precedingExpression = expression.slice(lastIndex, openingResult.index);
123
+ lastIndex = originalOpen.length + openingResult.index;
124
+ const escapedExpression = (0, utils_1.escapeJSLiteral)(precedingExpression);
125
+ compiledData.push(escapedExpression);
126
+ parseCloseReg.lastIndex = lastIndex;
127
+ while ((closeResult = parseCloseReg.exec(expression))) {
128
+ const [originalClose, closePrefix] = closeResult;
129
+ if (closePrefix) {
130
+ const content = expression.slice(lastIndex, closeResult.index);
131
+ lastIndex = parseCloseReg.lastIndex;
132
+ parseOpenReg.lastIndex = lastIndex;
133
+ const currentType = (0, utils_1.getCurrentPrefixType)(openingPrefix, parse);
134
+ templateData = { type: currentType, content };
135
+ compiledData.push(templateData);
136
+ break;
137
+ }
138
+ parseCloseReg.lastIndex = (0, parsing_helpers_1.handleQuotes)(expression, originalClose, closeResult.index, debugData.fileContent);
139
+ }
140
+ (0, parsing_helpers_1.checkForUnclosedPrefix)(templateData, expression, originalOpen, openingResult.index, debugData.fileContent);
141
+ }
142
+ const endOfTemplate = expression.slice(lastIndex);
143
+ const escapedEndOfTemplate = (0, utils_1.escapeJSLiteral)(endOfTemplate);
144
+ compiledData.push(escapedEndOfTemplate);
145
+ return compiledData;
146
+ }
147
+ /**
148
+ * Render a template with data and helpers.
149
+ * @param template The path of your template to render.
150
+ * @param data The data to inject.
151
+ * @param helpers The helpers functions to inject.
152
+ */
153
+ render(template, data = {}, helpers = {}) {
154
+ const debugData = (0, init_1.initDebugData)();
155
+ if (typeof template !== 'string') {
156
+ const error = (0, error_utils_1.handleWrongTypeOfTemplate)(template);
157
+ const { errorHTML } = this.manageError(error, template, debugData);
158
+ return errorHTML;
159
+ }
160
+ let filename = (0, utils_1.normalizeFilesPath)(template);
161
+ const { views, extension, fileResolution } = this.config;
162
+ const ɵɵstart = node_perf_hooks_1.performance.now();
163
+ let ɵɵcacheHit = false;
164
+ const pathWithExtension = (0, checks_1.getPathWithExtension)(filename, extension);
165
+ this.parentTemplate = (0, utils_1.getFileName)(pathWithExtension);
166
+ this.childrenStore.remove(this.parentTemplate);
167
+ if ((0, checks_1.isTemplateDynamicallyDefined)(filename)) {
168
+ const cachedTemplate = this.compiledStore.get(filename);
169
+ if (cachedTemplate) {
170
+ ɵɵcacheHit = true;
171
+ const executeData = {
172
+ compiledContent: cachedTemplate,
173
+ data,
174
+ helpers,
175
+ ɵɵstart,
176
+ filename,
177
+ ɵɵcacheHit,
178
+ };
179
+ return this.executeFunction(executeData, debugData);
180
+ }
181
+ const templateLoaded = this.dynamictemplatesStore.get(filename);
182
+ if (!templateLoaded) {
183
+ const error = (0, error_utils_1.handleNotFoundDynamicTemplate)(filename);
184
+ const { errorHTML } = this.manageError(error, filename, debugData);
185
+ return errorHTML;
186
+ }
187
+ const templateData = {
188
+ templateLoaded,
189
+ data,
190
+ helpers,
191
+ ɵɵstart,
192
+ filename,
193
+ ɵɵcacheHit,
194
+ };
195
+ return this.handleLoadedTemplate(templateData, debugData);
196
+ }
197
+ if (this.templatePaths.length === 0) {
198
+ const error = (0, error_utils_1.handleNoTemplateFilesFound)(views, extension);
199
+ const { errorHTML } = this.manageError(error, filename, debugData);
200
+ return errorHTML;
201
+ }
202
+ const fullPath = (0, utils_1.getFullPath)(views, pathWithExtension, fileResolution);
203
+ filename = (0, utils_1.getFileName)(fullPath);
204
+ const files = (0, templates_access_1.checkAccessPermission)(this.templatePaths, fullPath);
205
+ if (!(0, templates_access_1.fileIsUnique)(files)) {
206
+ const error = (0, error_utils_1.handleNonUniqueFile)(files, filename);
207
+ const { errorHTML } = this.manageError(error, filename, debugData);
208
+ return errorHTML;
209
+ }
210
+ const cachedTemplate = this.compiledStore.get(filename);
211
+ if (cachedTemplate) {
212
+ ɵɵcacheHit = true;
213
+ const executeData = {
214
+ compiledContent: cachedTemplate,
215
+ data,
216
+ helpers,
217
+ ɵɵstart,
218
+ filename,
219
+ ɵɵcacheHit,
220
+ };
221
+ return this.executeFunction(executeData, debugData);
222
+ }
223
+ const file = files[0];
224
+ const compileData = {
225
+ filename,
226
+ fullPath: file,
227
+ data,
228
+ helpers,
229
+ ɵɵstart,
230
+ ɵɵcacheHit,
231
+ };
232
+ return this.compileAndExecute(compileData, debugData);
233
+ }
234
+ /**
235
+ * Render a child component. Called inside the parent template.
236
+ */
237
+ renderChild(template, data = {}, helpers = {}) {
238
+ const debugData = (0, init_1.initDebugData)();
239
+ if (typeof template !== 'string') {
240
+ const error = (0, error_utils_1.handleWrongTypeOfTemplate)(template);
241
+ const errorData = this.handleChildError(error, template, debugData);
242
+ return errorData;
243
+ }
244
+ template = (0, utils_1.normalizeFilesPath)(template);
245
+ const { views, extension, fileResolution } = this.config;
246
+ let filename = template;
247
+ const pathWithExtension = (0, checks_1.getPathWithExtension)(template, extension);
248
+ (0, metrics_1.updateChildrenStore)(this.childrenStore, filename, this.parentTemplate, this.config.development);
249
+ if ((0, checks_1.isTemplateDynamicallyDefined)(template)) {
250
+ const cachedTemplate = this.compiledStore.get(template);
251
+ if (cachedTemplate) {
252
+ const executeData = {
253
+ compiledContent: cachedTemplate,
254
+ data,
255
+ helpers,
256
+ filename,
257
+ };
258
+ return this.executeChildFunction(executeData, debugData);
259
+ }
260
+ const templateLoaded = this.dynamictemplatesStore.get(template);
261
+ if (!templateLoaded) {
262
+ const error = (0, error_utils_1.handleNotFoundDynamicTemplate)(template);
263
+ const errorData = this.handleChildError(error, template, debugData);
264
+ return errorData;
265
+ }
266
+ const templateData = {
267
+ templateLoaded,
268
+ data,
269
+ helpers,
270
+ filename,
271
+ };
272
+ return this.handleLoadedChildTemplate(templateData, debugData);
273
+ }
274
+ const fullPath = (0, utils_1.getFullPath)(views, pathWithExtension, fileResolution);
275
+ filename = (0, utils_1.getFileName)(fullPath);
276
+ const files = (0, templates_access_1.checkAccessPermission)(this.templatePaths, fullPath);
277
+ if (!(0, templates_access_1.fileIsUnique)(files)) {
278
+ const error = (0, error_utils_1.handleNonUniqueFile)(files, filename);
279
+ const errorData = this.handleChildError(error, filename, debugData);
280
+ return errorData;
281
+ }
282
+ const cachedTemplate = this.compiledStore.get(filename);
283
+ if (cachedTemplate) {
284
+ const executeData = {
285
+ compiledContent: cachedTemplate,
286
+ data,
287
+ helpers,
288
+ filename,
289
+ };
290
+ return this.executeChildFunction(executeData, debugData);
291
+ }
292
+ const file = files[0];
293
+ const compileData = {
294
+ filename,
295
+ fullPath: file,
296
+ data,
297
+ helpers,
298
+ };
299
+ return this.compileAndExecuteChild(compileData, debugData);
300
+ }
301
+ compileAndExecuteChild(compileData, debugData) {
302
+ const { data, filename, fullPath, helpers } = compileData;
303
+ try {
304
+ const templateFn = this.readChildFileAndGetCompiledFn(fullPath, data, helpers, filename, debugData);
305
+ const immutableData = structuredClone(data);
306
+ const html = templateFn.call(this, immutableData, helpers);
307
+ return html;
308
+ }
309
+ catch (error) {
310
+ const errorData = this.handleChildError(error, filename, debugData);
311
+ return errorData;
312
+ }
313
+ }
314
+ compileAndExecute(compileData, debugData) {
315
+ const { data, filename, fullPath, helpers, ɵɵstart, ɵɵcacheHit } = compileData;
316
+ try {
317
+ const templateFn = this.readFileAndGetCompiledFn(fullPath, data, helpers, filename, debugData);
318
+ const immutableData = structuredClone(data);
319
+ const html = templateFn.call(this, immutableData, helpers, ɵɵstart, ɵɵcacheHit);
320
+ return html;
321
+ }
322
+ catch (error) {
323
+ // An error occurred in a child component - return it
324
+ if ((0, utils_1.isAChildError)(error))
325
+ return error.errorHTML;
326
+ const { errorHTML } = this.manageError(error, filename, debugData);
327
+ return errorHTML;
328
+ }
329
+ }
330
+ manageError(error, filename, debugData) {
331
+ // this.compiledStore.remove(filename); => pourquoi ?
332
+ error.filename = filename;
333
+ const errorData = this.handleErrorMessage(error, debugData);
334
+ console.error(new Error(`Error in ${filename}: ${errorData.message}`));
335
+ const errorHTML = this.initErrorTemplate(errorData);
336
+ errorData.errorHTML = errorHTML;
337
+ return errorData;
338
+ }
339
+ executeChildFunction(executeData, debugData) {
340
+ const { data, filename, helpers, compiledContent } = executeData;
341
+ try {
342
+ const immutableData = structuredClone(data);
343
+ const contentReplaced = (0, utils_1.injectDataAndHelpersInTemplate)(data, helpers, this.helpersStore, compiledContent);
344
+ debugData.compiledAnonymousFnContent = contentReplaced;
345
+ const templateFn = (0, utils_1.compileChildToFunction)(contentReplaced);
346
+ const html = templateFn.call(this, immutableData, helpers);
347
+ return html;
348
+ }
349
+ catch (error) {
350
+ const errorData = this.handleChildError(error, filename, debugData);
351
+ return errorData;
352
+ }
353
+ }
354
+ handleChildError(error, filename, debugData) {
355
+ // Error in a nested child — bubble up to the parent
356
+ if ((0, utils_1.isAChildError)(error))
357
+ throw error;
358
+ // Error occurred in this child component - handle it
359
+ const errorData = this.manageError(error, filename, debugData);
360
+ errorData.isAChildError = true;
361
+ return errorData;
362
+ }
363
+ executeFunction(executeData, debugData) {
364
+ const { data, filename, helpers, ɵɵstart, compiledContent, ɵɵcacheHit } = executeData;
365
+ try {
366
+ const immutableData = structuredClone(data);
367
+ const contentReplaced = (0, utils_1.injectDataAndHelpersInTemplate)(data, helpers, this.helpersStore, compiledContent);
368
+ debugData.compiledAnonymousFnContent = contentReplaced;
369
+ const templateFn = (0, utils_1.compileToFunction)(contentReplaced);
370
+ const html = templateFn.call(this, immutableData, helpers, ɵɵstart, ɵɵcacheHit);
371
+ return html;
372
+ }
373
+ catch (error) {
374
+ // An error occurred in a child component - return it
375
+ if ((0, utils_1.isAChildError)(error))
376
+ return error.errorHTML;
377
+ const { errorHTML } = this.manageError(error, filename, debugData);
378
+ return errorHTML;
379
+ }
380
+ }
381
+ handleErrorMessage(error, debugData) {
382
+ var _a;
383
+ const [finalMessage, fileContentPerLine, correctedLineNumber] = (0, error_utils_1.findOriginalLineNumberWithMessage)(error, debugData.compiledAnonymousFnContent, debugData.fileContent);
384
+ const errorData = {
385
+ filename: error.filename,
386
+ fileContent: fileContentPerLine,
387
+ message: finalMessage,
388
+ lineNumber: correctedLineNumber,
389
+ // Execution error is the last possible error
390
+ type: (_a = error.type) !== null && _a !== void 0 ? _a : 'Execution Error',
391
+ isAChildError: false,
392
+ errorHTML: '',
393
+ };
394
+ return errorData;
395
+ }
396
+ initErrorTemplate(errorData) {
397
+ if (!this.config.development)
398
+ return '';
399
+ const templatesPath = node_path_1.default.join(__dirname, 'error');
400
+ const tao = new Tao({ views: templatesPath });
401
+ return tao.render('error', errorData);
402
+ }
403
+ compileChildAndCache(content, filename, debugData) {
404
+ const compiledContent = this.compileChild(content, debugData);
405
+ if (this.config.cache) {
406
+ this.compiledStore.set(filename, compiledContent);
407
+ }
408
+ return compiledContent;
409
+ }
410
+ compileAndCache(content, filename, debugData) {
411
+ const compiledContent = this.compile(content, filename, debugData);
412
+ if (this.config.cache) {
413
+ this.compiledStore.set(filename, compiledContent);
414
+ }
415
+ return compiledContent;
416
+ }
417
+ readChildFileAndGetCompiledFn(resolvedPath, data, helpers, filename, debugData) {
418
+ const content = this.readFile(resolvedPath);
419
+ debugData.fileContent = content;
420
+ const compiledContent = this.compileChildAndCache(content, filename, debugData);
421
+ const contentReplaced = (0, utils_1.injectDataAndHelpersInTemplate)(data, helpers, this.helpersStore, compiledContent);
422
+ debugData.compiledAnonymousFnContent = contentReplaced;
423
+ const templateFn = (0, utils_1.compileChildToFunction)(contentReplaced);
424
+ return templateFn;
425
+ }
426
+ readFileAndGetCompiledFn(resolvedPath, data, helpers, filename, debugData) {
427
+ const content = this.readFile(resolvedPath);
428
+ debugData.fileContent = content;
429
+ const compiledContent = this.compileAndCache(content, filename, debugData);
430
+ const contentReplaced = (0, utils_1.injectDataAndHelpersInTemplate)(data, helpers, this.helpersStore, compiledContent);
431
+ debugData.compiledAnonymousFnContent = contentReplaced;
432
+ const templateFn = (0, utils_1.compileToFunction)(contentReplaced);
433
+ return templateFn;
434
+ }
435
+ /**
436
+ * Sync version is preferable, since HTML file are normally small (<100 Ko)
437
+ * and should be cached.
438
+ */
439
+ readFile(path) {
440
+ try {
441
+ const file = node_fs_1.default.readFileSync(path, 'utf8');
442
+ return file;
443
+ }
444
+ catch (error) {
445
+ const type = 'ReadFile Error';
446
+ error.type = type;
447
+ throw error;
448
+ }
449
+ }
450
+ /**
451
+ * Handle dynamically defined templates
452
+ */
453
+ handleLoadedTemplate(templateData, debugData) {
454
+ const { data, filename, helpers, ɵɵstart, ɵɵcacheHit } = templateData;
455
+ try {
456
+ const contentReplaced = this.compileLoadedTemplate(templateData, debugData);
457
+ const templateFn = (0, utils_1.compileToFunction)(contentReplaced);
458
+ const immutableData = structuredClone(data);
459
+ const html = templateFn.call(this, immutableData, helpers, ɵɵstart, ɵɵcacheHit);
460
+ return html;
461
+ }
462
+ catch (error) {
463
+ // An error occurred in a child component - return it
464
+ if ((0, utils_1.isAChildError)(error))
465
+ return error.errorHTML;
466
+ const { errorHTML } = this.manageError(error, filename, debugData);
467
+ return errorHTML;
468
+ }
469
+ }
470
+ handleLoadedChildTemplate(templateData, debugData) {
471
+ const { data, filename, helpers } = templateData;
472
+ try {
473
+ const contentReplaced = this.compileLoadedChildTemplate(templateData, debugData);
474
+ const templateFn = (0, utils_1.compileChildToFunction)(contentReplaced);
475
+ const immutableData = structuredClone(data);
476
+ const html = templateFn.call(this, immutableData, helpers);
477
+ return html;
478
+ }
479
+ catch (error) {
480
+ const errorData = this.handleChildError(error, filename, debugData);
481
+ return errorData;
482
+ }
483
+ }
484
+ /**
485
+ * Handle dynamically defined templates
486
+ */
487
+ compileLoadedTemplate(templateData, debugData) {
488
+ const { data, filename, helpers, templateLoaded: content } = templateData;
489
+ const compiledContent = this.compileAndCache(content, filename, debugData);
490
+ const contentReplaced = (0, utils_1.injectDataAndHelpersInTemplate)(data, helpers, this.helpersStore, compiledContent);
491
+ debugData.compiledAnonymousFnContent = contentReplaced;
492
+ return contentReplaced;
493
+ }
494
+ compileLoadedChildTemplate(templateData, debugData) {
495
+ const { data, filename, helpers, templateLoaded: content } = templateData;
496
+ const compiledContent = this.compileChildAndCache(content, filename, debugData);
497
+ const contentReplaced = (0, utils_1.injectDataAndHelpersInTemplate)(data, helpers, this.helpersStore, compiledContent);
498
+ debugData.compiledAnonymousFnContent = contentReplaced;
499
+ return contentReplaced;
500
+ }
501
+ /**
502
+ * Define global helpers. Define once, use everywhere.
503
+ * @param helpers An object of helpers.
504
+ */
505
+ defineHelpers(helpers = {}) {
506
+ for (const key in helpers) {
507
+ if (!Object.prototype.hasOwnProperty.call(helpers, key))
508
+ continue;
509
+ const fn = helpers[key];
510
+ if (!(0, utils_1.valueIsAFunction)(fn)) {
511
+ throw new Error(`Provided helper ${key} is not a function`);
512
+ }
513
+ this.helpersStore.set(key, fn);
514
+ }
515
+ }
516
+ /**
517
+ * Load dynamically defined templates.
518
+ * @param name The name of your template. Should start with a '@'.
519
+ * @param template The template content.
520
+ */
521
+ loadTemplate(name, template) {
522
+ const duplicate = this.dynamictemplatesStore.get(name);
523
+ if (!(0, checks_1.isTemplateDynamicallyDefined)(name)) {
524
+ throw new Error(`Dynamically loaded template ${name} should start with a '@'`);
525
+ }
526
+ if (duplicate) {
527
+ console.warn(`⚠️ Duplicate template name ${name} provided. Template content has been erased.`);
528
+ }
529
+ this.dynamictemplatesStore.set(name, template);
530
+ }
531
+ }
532
+ exports.Tao = Tao;
533
+ //# sourceMappingURL=tao.js.map
package/tao.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tao.js","sourceRoot":"","sources":["../src/tao.ts"],"names":[],"mappings":";;;;;;AAAA,qDA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Y,CAAC,IAAY,EAAE,QAAgB;QACzC,MAAM,SAAS,GAAG,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACvD,IAAI,CAAC,IAAA,qCAA4B,EAAC,IAAI,CAAC,EAAE;YACvC,MAAM,IAAI,KAAK,CAAC,+BAA+B,IAAI,0BAA0B,CAAC,CAAC;SAChF;QAED,IAAI,SAAS,EAAE;YACb,OAAO,CAAC,IAAI,CACV,+BAA+B,IAAI,8CAA8C,CAClF,CAAC;SACH;QAED,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACjD,CAAC;CACF;AAzrBD,kBAyrBC"}
@@ -0,0 +1,15 @@
1
+ import { normalizeFilesPath } from './utils';
2
+ /**
3
+ * Perform once.
4
+ * Search for all files within a given directory.
5
+ * Normalize paths on Windows.
6
+ */
7
+ declare function getFilesFromDirectory(directory: string, extension: string): string[];
8
+ /**
9
+ * Security measure to allow access to only files in given directory that has been previously mapped.
10
+ */
11
+ declare function isTemplateFileInsideGivenDirectory(templatePaths: string[], templateFile: string): string[];
12
+ declare function checkAccessPermission(templatePaths: string[], templateFile: string): string[];
13
+ declare function fileIsUnique(files: string[]): boolean;
14
+ export { getFilesFromDirectory, checkAccessPermission, isTemplateFileInsideGivenDirectory, normalizeFilesPath, fileIsUnique, };
15
+ //# sourceMappingURL=templates-access.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates-access.d.ts","sourceRoot":"","sources":["../src/templates-access.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C;;;;GAIG;AACH,iBAAS,qBAAqB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,YASlE;AAED;;GAEG;AACH,iBAAS,kCAAkC,CAAC,aAAa,EAAE,MAAM,EAAE,EAAE,YAAY,EAAE,MAAM,YAExF;AAED,iBAAS,qBAAqB,CAAC,aAAa,EAAE,MAAM,EAAE,EAAE,YAAY,EAAE,MAAM,YAI3E;AAED,iBAAS,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,WAEpC;AAED,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,kCAAkC,EAClC,kBAAkB,EAClB,YAAY,GACb,CAAC"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fileIsUnique = exports.normalizeFilesPath = exports.isTemplateFileInsideGivenDirectory = exports.checkAccessPermission = exports.getFilesFromDirectory = void 0;
4
+ const glob_1 = require("glob");
5
+ const utils_1 = require("./utils");
6
+ Object.defineProperty(exports, "normalizeFilesPath", { enumerable: true, get: function () { return utils_1.normalizeFilesPath; } });
7
+ /**
8
+ * Perform once.
9
+ * Search for all files within a given directory.
10
+ * Normalize paths on Windows.
11
+ */
12
+ function getFilesFromDirectory(directory, extension) {
13
+ const files = (0, glob_1.globSync)(`${directory}/**/*${extension}`, {
14
+ absolute: true,
15
+ nodir: true,
16
+ ignore: ['node_modules/**'],
17
+ });
18
+ const normalizedPaths = files.map((file) => (0, utils_1.normalizeFilesPath)(file));
19
+ return normalizedPaths;
20
+ }
21
+ exports.getFilesFromDirectory = getFilesFromDirectory;
22
+ /**
23
+ * Security measure to allow access to only files in given directory that has been previously mapped.
24
+ */
25
+ function isTemplateFileInsideGivenDirectory(templatePaths, templateFile) {
26
+ return templatePaths.filter((path) => path.endsWith(templateFile));
27
+ }
28
+ exports.isTemplateFileInsideGivenDirectory = isTemplateFileInsideGivenDirectory;
29
+ function checkAccessPermission(templatePaths, templateFile) {
30
+ const files = isTemplateFileInsideGivenDirectory(templatePaths, templateFile);
31
+ return files;
32
+ }
33
+ exports.checkAccessPermission = checkAccessPermission;
34
+ function fileIsUnique(files) {
35
+ return files.length === 1;
36
+ }
37
+ exports.fileIsUnique = fileIsUnique;
38
+ //# sourceMappingURL=templates-access.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates-access.js","sourceRoot":"","sources":["../src/templates-access.ts"],"names":[],"mappings":";;;AAAA,+BAAgC;AAChC,mCAA6C;AAuC3C,mGAvCO,0BAAkB,OAuCP;AArCpB;;;;GAIG;AACH,SAAS,qBAAqB,CAAC,SAAiB,EAAE,SAAiB;IACjE,MAAM,KAAK,GAAG,IAAA,eAAQ,EAAC,GAAG,SAAS,QAAQ,SAAS,EAAE,EAAE;QACtD,QAAQ,EAAE,IAAI;QACd,KAAK,EAAE,IAAI;QACX,MAAM,EAAE,CAAC,iBAAiB,CAAC;KAC5B,CAAC,CAAC;IAEH,MAAM,eAAe,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,0BAAkB,EAAC,IAAI,CAAC,CAAC,CAAC;IACtE,OAAO,eAAe,CAAC;AACzB,CAAC;AAoBC,sDAAqB;AAlBvB;;GAEG;AACH,SAAS,kCAAkC,CAAC,aAAuB,EAAE,YAAoB;IACvF,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC;AACrE,CAAC;AAeC,gFAAkC;AAbpC,SAAS,qBAAqB,CAAC,aAAuB,EAAE,YAAoB;IAC1E,MAAM,KAAK,GAAG,kCAAkC,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC;IAE9E,OAAO,KAAK,CAAC;AACf,CAAC;AAQC,sDAAqB;AANvB,SAAS,YAAY,CAAC,KAAe;IACnC,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;AAC5B,CAAC;AAOC,oCAAY"}