@aigne/core 0.0.3 → 0.0.4

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 (168) hide show
  1. package/lib/cjs/index.js +1 -1
  2. package/lib/cjs/types/index.js +2 -4
  3. package/lib/esm/index.js +1 -1
  4. package/lib/esm/types/index.js +2 -4
  5. package/lib/types/index.d.ts +1 -1
  6. package/lib/types/types/agent.d.ts +5 -0
  7. package/lib/types/types/index.d.ts +2 -4
  8. package/lib/types/types/runnable.d.ts +20 -0
  9. package/package.json +3 -4
  10. package/lib/cjs/assistant/generate-output.js +0 -101
  11. package/lib/cjs/assistant/select-agent.js +0 -76
  12. package/lib/cjs/assistant/type.js +0 -11
  13. package/lib/cjs/common/aid.js +0 -42
  14. package/lib/cjs/common/index.js +0 -238
  15. package/lib/cjs/common/resource-manager.js +0 -199
  16. package/lib/cjs/constants.js +0 -9
  17. package/lib/cjs/executor/agent.js +0 -10
  18. package/lib/cjs/executor/aigc.js +0 -28
  19. package/lib/cjs/executor/api.js +0 -64
  20. package/lib/cjs/executor/base.js +0 -676
  21. package/lib/cjs/executor/blocklet.js +0 -25
  22. package/lib/cjs/executor/call-agent.js +0 -105
  23. package/lib/cjs/executor/decision.js +0 -478
  24. package/lib/cjs/executor/image-blender.js +0 -32
  25. package/lib/cjs/executor/index.js +0 -81
  26. package/lib/cjs/executor/llm.js +0 -379
  27. package/lib/cjs/executor/logic.js +0 -167
  28. package/lib/cjs/libs/blocklet/vc.js +0 -92
  29. package/lib/cjs/libs/openapi/request/index.js +0 -24
  30. package/lib/cjs/libs/openapi/request/util.js +0 -146
  31. package/lib/cjs/libs/openapi/types/index.js +0 -17
  32. package/lib/cjs/libs/openapi/util/call.js +0 -15
  33. package/lib/cjs/libs/openapi/util/check-schema.js +0 -67
  34. package/lib/cjs/libs/openapi/util/convert-schema.js +0 -44
  35. package/lib/cjs/libs/openapi/util/flatten-open-api.js +0 -21
  36. package/lib/cjs/libs/openapi/util/get-open-api-i18n-text.js +0 -7
  37. package/lib/cjs/runtime/resource-blocklet.js +0 -5
  38. package/lib/cjs/runtime/runtime.js +0 -143
  39. package/lib/cjs/types/assistant/index.js +0 -31
  40. package/lib/cjs/types/assistant/mustache/ReadableMustache.js +0 -69
  41. package/lib/cjs/types/assistant/mustache/directive.js +0 -35
  42. package/lib/cjs/types/assistant/mustache/mustache.js +0 -688
  43. package/lib/cjs/types/resource/index.js +0 -47
  44. package/lib/cjs/types/resource/project.js +0 -35
  45. package/lib/cjs/types/runtime/error.js +0 -18
  46. package/lib/cjs/types/runtime/index.js +0 -37
  47. package/lib/cjs/types/runtime/runtime-resource-blocklet-state.js +0 -4
  48. package/lib/cjs/types/runtime/schema.js +0 -259
  49. package/lib/cjs/utils/cron-job.js +0 -48
  50. package/lib/cjs/utils/extract-metadata-transform.js +0 -58
  51. package/lib/cjs/utils/extract-metadata-transform.test.js +0 -61
  52. package/lib/cjs/utils/fs.js +0 -49
  53. package/lib/cjs/utils/get-blocklet-agent.js +0 -351
  54. package/lib/cjs/utils/geti.js +0 -37
  55. package/lib/cjs/utils/is-non-nullable.js +0 -20
  56. package/lib/cjs/utils/render-message.js +0 -23
  57. package/lib/cjs/utils/resolve-secret-inputs.js +0 -49
  58. package/lib/cjs/utils/retry.js +0 -19
  59. package/lib/cjs/utils/task-id.js +0 -7
  60. package/lib/cjs/utils/tool-calls-transform.js +0 -18
  61. package/lib/esm/assistant/generate-output.js +0 -91
  62. package/lib/esm/assistant/select-agent.js +0 -71
  63. package/lib/esm/assistant/type.js +0 -7
  64. package/lib/esm/common/aid.js +0 -38
  65. package/lib/esm/common/index.js +0 -232
  66. package/lib/esm/common/resource-manager.js +0 -192
  67. package/lib/esm/constants.js +0 -6
  68. package/lib/esm/executor/agent.js +0 -6
  69. package/lib/esm/executor/aigc.js +0 -24
  70. package/lib/esm/executor/api.js +0 -34
  71. package/lib/esm/executor/base.js +0 -668
  72. package/lib/esm/executor/blocklet.js +0 -21
  73. package/lib/esm/executor/call-agent.js +0 -98
  74. package/lib/esm/executor/decision.js +0 -471
  75. package/lib/esm/executor/image-blender.js +0 -25
  76. package/lib/esm/executor/index.js +0 -74
  77. package/lib/esm/executor/llm.js +0 -372
  78. package/lib/esm/executor/logic.js +0 -160
  79. package/lib/esm/libs/blocklet/vc.js +0 -85
  80. package/lib/esm/libs/openapi/request/index.js +0 -20
  81. package/lib/esm/libs/openapi/request/util.js +0 -136
  82. package/lib/esm/libs/openapi/types/index.js +0 -1
  83. package/lib/esm/libs/openapi/util/call.js +0 -8
  84. package/lib/esm/libs/openapi/util/check-schema.js +0 -62
  85. package/lib/esm/libs/openapi/util/convert-schema.js +0 -42
  86. package/lib/esm/libs/openapi/util/flatten-open-api.js +0 -19
  87. package/lib/esm/libs/openapi/util/get-open-api-i18n-text.js +0 -5
  88. package/lib/esm/runtime/resource-blocklet.js +0 -2
  89. package/lib/esm/runtime/runtime.js +0 -136
  90. package/lib/esm/types/assistant/index.js +0 -9
  91. package/lib/esm/types/assistant/mustache/ReadableMustache.js +0 -63
  92. package/lib/esm/types/assistant/mustache/directive.js +0 -29
  93. package/lib/esm/types/assistant/mustache/mustache.js +0 -686
  94. package/lib/esm/types/resource/index.js +0 -26
  95. package/lib/esm/types/resource/project.js +0 -29
  96. package/lib/esm/types/runtime/error.js +0 -14
  97. package/lib/esm/types/runtime/index.js +0 -20
  98. package/lib/esm/types/runtime/runtime-resource-blocklet-state.js +0 -1
  99. package/lib/esm/types/runtime/schema.js +0 -249
  100. package/lib/esm/utils/cron-job.js +0 -44
  101. package/lib/esm/utils/extract-metadata-transform.js +0 -54
  102. package/lib/esm/utils/extract-metadata-transform.test.js +0 -59
  103. package/lib/esm/utils/fs.js +0 -41
  104. package/lib/esm/utils/get-blocklet-agent.js +0 -344
  105. package/lib/esm/utils/geti.js +0 -30
  106. package/lib/esm/utils/is-non-nullable.js +0 -13
  107. package/lib/esm/utils/render-message.js +0 -20
  108. package/lib/esm/utils/resolve-secret-inputs.js +0 -46
  109. package/lib/esm/utils/retry.js +0 -16
  110. package/lib/esm/utils/task-id.js +0 -3
  111. package/lib/esm/utils/tool-calls-transform.js +0 -15
  112. package/lib/types/assistant/generate-output.d.ts +0 -29
  113. package/lib/types/assistant/select-agent.d.ts +0 -14
  114. package/lib/types/assistant/type.d.ts +0 -61
  115. package/lib/types/common/aid.d.ts +0 -18
  116. package/lib/types/common/index.d.ts +0 -7
  117. package/lib/types/common/resource-manager.d.ts +0 -88
  118. package/lib/types/constants.d.ts +0 -6
  119. package/lib/types/executor/agent.d.ts +0 -5
  120. package/lib/types/executor/aigc.d.ts +0 -9
  121. package/lib/types/executor/api.d.ts +0 -9
  122. package/lib/types/executor/base.d.ts +0 -209
  123. package/lib/types/executor/blocklet.d.ts +0 -9
  124. package/lib/types/executor/call-agent.d.ts +0 -12
  125. package/lib/types/executor/decision.d.ts +0 -20
  126. package/lib/types/executor/image-blender.d.ts +0 -9
  127. package/lib/types/executor/index.d.ts +0 -8
  128. package/lib/types/executor/llm.d.ts +0 -38
  129. package/lib/types/executor/logic.d.ts +0 -9
  130. package/lib/types/libs/blocklet/vc.d.ts +0 -17
  131. package/lib/types/libs/openapi/request/index.d.ts +0 -17
  132. package/lib/types/libs/openapi/request/util.d.ts +0 -40
  133. package/lib/types/libs/openapi/types/index.d.ts +0 -20
  134. package/lib/types/libs/openapi/util/call.d.ts +0 -2
  135. package/lib/types/libs/openapi/util/check-schema.d.ts +0 -3
  136. package/lib/types/libs/openapi/util/convert-schema.d.ts +0 -8
  137. package/lib/types/libs/openapi/util/flatten-open-api.d.ts +0 -3
  138. package/lib/types/libs/openapi/util/get-open-api-i18n-text.d.ts +0 -2
  139. package/lib/types/runtime/resource-blocklet.d.ts +0 -2
  140. package/lib/types/runtime/runtime.d.ts +0 -20
  141. package/lib/types/types/assistant/index.d.ts +0 -405
  142. package/lib/types/types/assistant/mustache/ReadableMustache.d.ts +0 -2
  143. package/lib/types/types/assistant/mustache/directive.d.ts +0 -6
  144. package/lib/types/types/assistant/mustache/mustache.d.ts +0 -2
  145. package/lib/types/types/common/index.d.ts +0 -45
  146. package/lib/types/types/resource/index.d.ts +0 -17
  147. package/lib/types/types/resource/project.d.ts +0 -41
  148. package/lib/types/types/runtime/agent.d.ts +0 -33
  149. package/lib/types/types/runtime/error.d.ts +0 -10
  150. package/lib/types/types/runtime/index.d.ts +0 -116
  151. package/lib/types/types/runtime/runtime-resource-blocklet-state.d.ts +0 -5
  152. package/lib/types/types/runtime/schema.d.ts +0 -110
  153. package/lib/types/utils/cron-job.d.ts +0 -22
  154. package/lib/types/utils/extract-metadata-transform.d.ts +0 -16
  155. package/lib/types/utils/extract-metadata-transform.test.d.ts +0 -1
  156. package/lib/types/utils/fs.d.ts +0 -9
  157. package/lib/types/utils/get-blocklet-agent.d.ts +0 -219
  158. package/lib/types/utils/geti.d.ts +0 -1
  159. package/lib/types/utils/is-non-nullable.d.ts +0 -2
  160. package/lib/types/utils/render-message.d.ts +0 -6
  161. package/lib/types/utils/resolve-secret-inputs.d.ts +0 -11
  162. package/lib/types/utils/retry.d.ts +0 -1
  163. package/lib/types/utils/task-id.d.ts +0 -1
  164. package/lib/types/utils/tool-calls-transform.d.ts +0 -2
  165. /package/lib/cjs/types/{runtime/agent.js → agent.js} +0 -0
  166. /package/lib/cjs/types/{common/index.js → runnable.js} +0 -0
  167. /package/lib/esm/types/{runtime/agent.js → agent.js} +0 -0
  168. /package/lib/esm/types/{common/index.js → runnable.js} +0 -0
@@ -1,686 +0,0 @@
1
- /* eslint-disable */
2
- // @ts-nocheck
3
- /*!
4
- * mustache.js - Logic-less {{mustache}} templates with JavaScript
5
- * http://github.com/janl/mustache.js
6
- */
7
- var objectToString = Object.prototype.toString;
8
- var isArray = Array.isArray ||
9
- function isArrayPolyfill(object) {
10
- return objectToString.call(object) === '[object Array]';
11
- };
12
- function isFunction(object) {
13
- return typeof object === 'function';
14
- }
15
- /**
16
- * More correct typeof string handling array
17
- * which normally returns typeof 'object'
18
- */
19
- function typeStr(obj) {
20
- return isArray(obj) ? 'array' : typeof obj;
21
- }
22
- function escapeRegExp(string) {
23
- return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&');
24
- }
25
- /**
26
- * Null safe way of checking whether or not an object,
27
- * including its prototype, has a given property
28
- */
29
- function hasProperty(obj, propName) {
30
- return obj != null && typeof obj === 'object' && propName in obj;
31
- }
32
- /**
33
- * Safe way of detecting whether or not the given thing is a primitive and
34
- * whether it has the given property
35
- */
36
- function primitiveHasOwnProperty(primitive, propName) {
37
- return (primitive != null && typeof primitive !== 'object' && primitive.hasOwnProperty && primitive.hasOwnProperty(propName));
38
- }
39
- // Workaround for https://issues.apache.org/jira/browse/COUCHDB-577
40
- // See https://github.com/janl/mustache.js/issues/189
41
- var regExpTest = RegExp.prototype.test;
42
- function testRegExp(re, string) {
43
- return regExpTest.call(re, string);
44
- }
45
- var nonSpaceRe = /\S/;
46
- function isWhitespace(string) {
47
- return !testRegExp(nonSpaceRe, string);
48
- }
49
- var entityMap = {
50
- '&': '&',
51
- '<': '&lt;',
52
- '>': '&gt;',
53
- '"': '&quot;',
54
- "'": '&#39;',
55
- '/': '&#x2F;',
56
- '`': '&#x60;',
57
- '=': '&#x3D;',
58
- };
59
- function escapeHtml(string) {
60
- return String(string).replace(/[&<>"'`=\/]/g, function fromEntityMap(s) {
61
- return entityMap[s];
62
- });
63
- }
64
- var whiteRe = /\s*/;
65
- var spaceRe = /\s+/;
66
- var equalsRe = /\s*=/;
67
- var curlyRe = /\s*\}/;
68
- var tagRe = /#|\^|\/|>|\{|&|=|!/;
69
- /**
70
- * Breaks up the given `template` string into a tree of tokens. If the `tags`
71
- * argument is given here it must be an array with two string values: the
72
- * opening and closing tags used in the template (e.g. [ "<%", "%>" ]). Of
73
- * course, the default is to use mustaches (i.e. mustache.tags).
74
- *
75
- * A token is an array with at least 4 elements. The first element is the
76
- * mustache symbol that was used inside the tag, e.g. "#" or "&". If the tag
77
- * did not contain a symbol (i.e. {{myValue}}) this element is "name". For
78
- * all text that appears outside a symbol this element is "text".
79
- *
80
- * The second element of a token is its "value". For mustache tags this is
81
- * whatever else was inside the tag besides the opening symbol. For text tokens
82
- * this is the text itself.
83
- *
84
- * The third and fourth elements of the token are the start and end indices,
85
- * respectively, of the token in the original template.
86
- *
87
- * Tokens that are the root node of a subtree contain two more elements: 1) an
88
- * array of tokens in the subtree and 2) the index in the original template at
89
- * which the closing tag for that section begins.
90
- *
91
- * Tokens for partials also contain two more elements: 1) a string value of
92
- * indendation prior to that tag and 2) the index of that tag on that line -
93
- * eg a value of 2 indicates the partial is the third tag on this line.
94
- */
95
- function parseTemplate(template, tags) {
96
- if (!template)
97
- return [];
98
- var lineHasNonSpace = false;
99
- var sections = []; // Stack to hold section tokens
100
- var tokens = []; // Buffer to hold the tokens
101
- var spaces = []; // Indices of whitespace tokens on the current line
102
- var hasTag = false; // Is there a {{tag}} on the current line?
103
- var nonSpace = false; // Is there a non-space char on the current line?
104
- var indentation = ''; // Tracks indentation for tags that use it
105
- var tagIndex = 0; // Stores a count of number of tags encountered on a line
106
- // Strips all whitespace tokens array for the current line
107
- // if there was a {{#tag}} on it and otherwise only space.
108
- function stripSpace() {
109
- if (hasTag && !nonSpace) {
110
- while (spaces.length)
111
- delete tokens[spaces.pop()];
112
- }
113
- else {
114
- spaces = [];
115
- }
116
- hasTag = false;
117
- nonSpace = false;
118
- }
119
- var openingTagRe, closingTagRe, closingCurlyRe;
120
- function compileTags(tagsToCompile) {
121
- if (typeof tagsToCompile === 'string')
122
- tagsToCompile = tagsToCompile.split(spaceRe, 2);
123
- if (!isArray(tagsToCompile) || tagsToCompile.length !== 2)
124
- throw new Error('Invalid tags: ' + tagsToCompile);
125
- openingTagRe = new RegExp(escapeRegExp(tagsToCompile[0]) + '\\s*');
126
- closingTagRe = new RegExp('\\s*' + escapeRegExp(tagsToCompile[1]));
127
- closingCurlyRe = new RegExp('\\s*' + escapeRegExp('}' + tagsToCompile[1]));
128
- }
129
- compileTags(tags || mustache.tags);
130
- var scanner = new Scanner(template);
131
- var start, type, value, chr, token, openSection;
132
- while (!scanner.eos()) {
133
- start = scanner.pos;
134
- // Match any text between tags.
135
- value = scanner.scanUntil(openingTagRe);
136
- if (value) {
137
- for (var i = 0, valueLength = value.length; i < valueLength; ++i) {
138
- chr = value.charAt(i);
139
- if (isWhitespace(chr)) {
140
- spaces.push(tokens.length);
141
- indentation += chr;
142
- }
143
- else {
144
- nonSpace = true;
145
- lineHasNonSpace = true;
146
- indentation += ' ';
147
- }
148
- tokens.push(['text', chr, start, start + 1]);
149
- start += 1;
150
- // Check for whitespace on the current line.
151
- if (chr === '\n') {
152
- stripSpace();
153
- indentation = '';
154
- tagIndex = 0;
155
- lineHasNonSpace = false;
156
- }
157
- }
158
- }
159
- // Match the opening tag.
160
- if (!scanner.scan(openingTagRe))
161
- break;
162
- hasTag = true;
163
- // Get the tag type.
164
- type = scanner.scan(tagRe) || 'name';
165
- scanner.scan(whiteRe);
166
- // Get the tag value.
167
- if (type === '=') {
168
- value = scanner.scanUntil(equalsRe);
169
- scanner.scan(equalsRe);
170
- scanner.scanUntil(closingTagRe);
171
- }
172
- else if (type === '{') {
173
- value = scanner.scanUntil(closingCurlyRe);
174
- scanner.scan(curlyRe);
175
- scanner.scanUntil(closingTagRe);
176
- type = '&';
177
- }
178
- else {
179
- value = scanner.scanUntil(closingTagRe);
180
- }
181
- // Match the closing tag.
182
- if (!scanner.scan(closingTagRe))
183
- continue;
184
- // throw new Error('Unclosed tag at ' + scanner.pos);
185
- if (type == '>') {
186
- token = [type, value, start, scanner.pos, indentation, tagIndex, lineHasNonSpace];
187
- }
188
- else {
189
- token = [type, value, start, scanner.pos];
190
- }
191
- tagIndex++;
192
- tokens.push(token);
193
- if (type === '#' || type === '^') {
194
- sections.push(token);
195
- }
196
- else if (type === '/') {
197
- // Check section nesting.
198
- openSection = sections.pop();
199
- if (!openSection)
200
- throw new Error('Unopened section "' + value + '" at ' + start);
201
- if (openSection[1] !== value)
202
- throw new Error('Unclosed section "' + openSection[1] + '" at ' + start);
203
- }
204
- else if (type === 'name' || type === '{' || type === '&') {
205
- nonSpace = true;
206
- }
207
- else if (type === '=') {
208
- // Set the tags for the next time around.
209
- compileTags(value);
210
- }
211
- }
212
- stripSpace();
213
- // Make sure there are no open sections when we're done.
214
- openSection = sections.pop();
215
- if (openSection)
216
- throw new Error('Unclosed section "' + openSection[1] + '" at ' + scanner.pos);
217
- return nestTokens(squashTokens(tokens));
218
- }
219
- /**
220
- * Combines the values of consecutive text tokens in the given `tokens` array
221
- * to a single token.
222
- */
223
- function squashTokens(tokens) {
224
- var squashedTokens = [];
225
- var token, lastToken;
226
- for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {
227
- token = tokens[i];
228
- if (token) {
229
- if (token[0] === 'text' && lastToken && lastToken[0] === 'text') {
230
- lastToken[1] += token[1];
231
- lastToken[3] = token[3];
232
- }
233
- else {
234
- squashedTokens.push(token);
235
- lastToken = token;
236
- }
237
- }
238
- }
239
- return squashedTokens;
240
- }
241
- /**
242
- * Forms the given array of `tokens` into a nested tree structure where
243
- * tokens that represent a section have two additional items: 1) an array of
244
- * all tokens that appear in that section and 2) the index in the original
245
- * template that represents the end of that section.
246
- */
247
- function nestTokens(tokens) {
248
- var nestedTokens = [];
249
- var collector = nestedTokens;
250
- var sections = [];
251
- var token, section;
252
- for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {
253
- token = tokens[i];
254
- switch (token[0]) {
255
- case '#':
256
- case '^':
257
- collector.push(token);
258
- sections.push(token);
259
- collector = token[4] = [];
260
- break;
261
- case '/':
262
- section = sections.pop();
263
- section[5] = token[2];
264
- collector = sections.length > 0 ? sections[sections.length - 1][4] : nestedTokens;
265
- break;
266
- default:
267
- collector.push(token);
268
- }
269
- }
270
- return nestedTokens;
271
- }
272
- /**
273
- * A simple string scanner that is used by the template parser to find
274
- * tokens in template strings.
275
- */
276
- function Scanner(string) {
277
- this.string = string;
278
- this.tail = string;
279
- this.pos = 0;
280
- }
281
- /**
282
- * Returns `true` if the tail is empty (end of string).
283
- */
284
- Scanner.prototype.eos = function eos() {
285
- return this.tail === '';
286
- };
287
- /**
288
- * Tries to match the given regular expression at the current position.
289
- * Returns the matched text if it can match, the empty string otherwise.
290
- */
291
- Scanner.prototype.scan = function scan(re) {
292
- var match = this.tail.match(re);
293
- if (!match || match.index !== 0)
294
- return '';
295
- var string = match[0];
296
- this.tail = this.tail.substring(string.length);
297
- this.pos += string.length;
298
- return string;
299
- };
300
- /**
301
- * Skips all text until the given regular expression can be matched. Returns
302
- * the skipped string, which is the entire tail if no match can be made.
303
- */
304
- Scanner.prototype.scanUntil = function scanUntil(re) {
305
- var index = this.tail.search(re), match;
306
- switch (index) {
307
- case -1:
308
- match = this.tail;
309
- this.tail = '';
310
- break;
311
- case 0:
312
- match = '';
313
- break;
314
- default:
315
- match = this.tail.substring(0, index);
316
- this.tail = this.tail.substring(index);
317
- }
318
- this.pos += match.length;
319
- return match;
320
- };
321
- /**
322
- * Represents a rendering context by wrapping a view object and
323
- * maintaining a reference to the parent context.
324
- */
325
- function Context(view, parentContext) {
326
- this.view = view;
327
- this.cache = { '.': this.view };
328
- this.parent = parentContext;
329
- }
330
- /**
331
- * Creates a new context using the given view with this context
332
- * as the parent.
333
- */
334
- Context.prototype.push = function push(view) {
335
- return new Context(view, this);
336
- };
337
- /**
338
- * Returns the value of the given name in this context, traversing
339
- * up the context hierarchy if the value is absent in this context's view.
340
- */
341
- Context.prototype.lookup = async function lookup(name) {
342
- var cache = this.cache;
343
- var value;
344
- if (cache.hasOwnProperty(name)) {
345
- value = cache[name];
346
- }
347
- else {
348
- var context = this, intermediateValue, names, index, lookupHit = false;
349
- while (context) {
350
- if (name.indexOf('.') > 0) {
351
- intermediateValue = context.view;
352
- names = name.split('.');
353
- index = 0;
354
- /**
355
- * Using the dot notion path in `name`, we descend through the
356
- * nested objects.
357
- *
358
- * To be certain that the lookup has been successful, we have to
359
- * check if the last object in the path actually has the property
360
- * we are looking for. We store the result in `lookupHit`.
361
- *
362
- * This is specially necessary for when the value has been set to
363
- * `undefined` and we want to avoid looking up parent contexts.
364
- *
365
- * In the case where dot notation is used, we consider the lookup
366
- * to be successful even if the last "object" in the path is
367
- * not actually an object but a primitive (e.g., a string, or an
368
- * integer), because it is sometimes useful to access a property
369
- * of an autoboxed primitive, such as the length of a string.
370
- **/
371
- while (intermediateValue != null && index < names.length) {
372
- if (index === names.length - 1)
373
- lookupHit =
374
- hasProperty(intermediateValue, names[index]) || primitiveHasOwnProperty(intermediateValue, names[index]);
375
- intermediateValue = await intermediateValue[names[index++]];
376
- while (typeof intermediateValue === 'function') {
377
- intermediateValue = await intermediateValue(this.view);
378
- }
379
- }
380
- }
381
- else {
382
- intermediateValue = context.view[name];
383
- /**
384
- * Only checking against `hasProperty`, which always returns `false` if
385
- * `context.view` is not an object. Deliberately omitting the check
386
- * against `primitiveHasOwnProperty` if dot notation is not used.
387
- *
388
- * Consider this example:
389
- * ```
390
- * Mustache.render("The length of a football field is {{#length}}{{length}}{{/length}}.", {length: "100 yards"})
391
- * ```
392
- *
393
- * If we were to check also against `primitiveHasOwnProperty`, as we do
394
- * in the dot notation case, then render call would return:
395
- *
396
- * "The length of a football field is 9."
397
- *
398
- * rather than the expected:
399
- *
400
- * "The length of a football field is 100 yards."
401
- **/
402
- lookupHit = hasProperty(context.view, name);
403
- }
404
- if (lookupHit) {
405
- value = intermediateValue;
406
- break;
407
- }
408
- context = context.parent;
409
- }
410
- cache[name] = value;
411
- }
412
- if (isFunction(value))
413
- value = value.call(this.view);
414
- return value;
415
- };
416
- /**
417
- * A Writer knows how to take a stream of tokens and render them to a
418
- * string, given a context. It also maintains a cache of templates to
419
- * avoid the need to parse the same template twice.
420
- */
421
- function Writer() {
422
- this.templateCache = {
423
- _cache: {},
424
- set: function set(key, value) {
425
- this._cache[key] = value;
426
- },
427
- get: function get(key) {
428
- return this._cache[key];
429
- },
430
- clear: function clear() {
431
- this._cache = {};
432
- },
433
- };
434
- }
435
- /**
436
- * Clears all cached templates in this writer.
437
- */
438
- Writer.prototype.clearCache = function clearCache() {
439
- if (typeof this.templateCache !== 'undefined') {
440
- this.templateCache.clear();
441
- }
442
- };
443
- /**
444
- * Parses and caches the given `template` according to the given `tags` or
445
- * `mustache.tags` if `tags` is omitted, and returns the array of tokens
446
- * that is generated from the parse.
447
- */
448
- Writer.prototype.parse = function parse(template, tags) {
449
- var cache = this.templateCache;
450
- var cacheKey = template + ':' + (tags || mustache.tags).join(':');
451
- var isCacheEnabled = typeof cache !== 'undefined';
452
- var tokens = isCacheEnabled ? cache.get(cacheKey) : undefined;
453
- if (tokens == undefined) {
454
- tokens = parseTemplate(template, tags);
455
- isCacheEnabled && cache.set(cacheKey, tokens);
456
- }
457
- return tokens;
458
- };
459
- /**
460
- * High-level method that is used to render the given `template` with
461
- * the given `view`.
462
- *
463
- * The optional `partials` argument may be an object that contains the
464
- * names and templates of partials that are used in the template. It may
465
- * also be a function that is used to load partial templates on the fly
466
- * that takes a single argument: the name of the partial.
467
- *
468
- * If the optional `config` argument is given here, then it should be an
469
- * object with a `tags` attribute or an `escape` attribute or both.
470
- * If an array is passed, then it will be interpreted the same way as
471
- * a `tags` attribute on a `config` object.
472
- *
473
- * The `tags` attribute of a `config` object must be an array with two
474
- * string values: the opening and closing tags used in the template (e.g.
475
- * [ "<%", "%>" ]). The default is to mustache.tags.
476
- *
477
- * The `escape` attribute of a `config` object must be a function which
478
- * accepts a string as input and outputs a safely escaped string.
479
- * If an `escape` function is not provided, then an HTML-safe string
480
- * escaping function is used as the default.
481
- */
482
- Writer.prototype.render = function render(template, view, partials, config) {
483
- var tags = this.getConfigTags(config);
484
- var tokens = this.parse(template, tags);
485
- var context = view instanceof Context ? view : new Context(view, undefined);
486
- return this.renderTokens(tokens, context, partials, template, config);
487
- };
488
- /**
489
- * Low-level method that renders the given array of `tokens` using
490
- * the given `context` and `partials`.
491
- *
492
- * Note: The `originalTemplate` is only ever used to extract the portion
493
- * of the original template that was contained in a higher-order section.
494
- * If the template doesn't use higher-order sections, this argument may
495
- * be omitted.
496
- */
497
- Writer.prototype.renderTokens = async function renderTokens(tokens, context, partials, originalTemplate, config) {
498
- var buffer = '';
499
- var token, symbol, value;
500
- for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {
501
- value = undefined;
502
- token = tokens[i];
503
- symbol = token[0];
504
- if (symbol === '#')
505
- value = await this.renderSection(token, context, partials, originalTemplate, config);
506
- else if (symbol === '^')
507
- value = await this.renderInverted(token, context, partials, originalTemplate, config);
508
- else if (symbol === '>')
509
- value = await this.renderPartial(token, context, partials, config);
510
- else if (symbol === '&')
511
- value = await this.unescapedValue(token, context);
512
- else if (symbol === 'name')
513
- value = await this.escapedValue(token, context, config);
514
- else if (symbol === 'text')
515
- value = await this.rawValue(token);
516
- if (value !== undefined)
517
- buffer += value;
518
- }
519
- return buffer;
520
- };
521
- Writer.prototype.renderSection = async function renderSection(token, context, partials, originalTemplate, config) {
522
- var self = this;
523
- var buffer = '';
524
- var value = await context.lookup(token[1]);
525
- // This function is used to render an arbitrary template
526
- // in the current context by higher-order sections.
527
- function subRender(template) {
528
- return self.render(template, context, partials, config);
529
- }
530
- if (!value)
531
- return;
532
- if (isArray(value)) {
533
- for (var j = 0, valueLength = value.length; j < valueLength; ++j) {
534
- buffer += await this.renderTokens(token[4], context.push(value[j]), partials, originalTemplate, config);
535
- }
536
- }
537
- else if (typeof value === 'object' || typeof value === 'string' || typeof value === 'number') {
538
- buffer += await this.renderTokens(token[4], context.push(value), partials, originalTemplate, config);
539
- }
540
- else if (isFunction(value)) {
541
- if (typeof originalTemplate !== 'string')
542
- throw new Error('Cannot use higher-order sections without the original template');
543
- // Extract the portion of the original template that the section contains.
544
- value = await value.call(context.view, originalTemplate.slice(token[3], token[5]), subRender);
545
- if (value != null)
546
- buffer += value;
547
- }
548
- else {
549
- buffer += await this.renderTokens(token[4], context, partials, originalTemplate, config);
550
- }
551
- return buffer;
552
- };
553
- Writer.prototype.renderInverted = async function renderInverted(token, context, partials, originalTemplate, config) {
554
- var value = await context.lookup(token[1]);
555
- // Use JavaScript's definition of falsy. Include empty arrays.
556
- // See https://github.com/janl/mustache.js/issues/186
557
- if (!value || (isArray(value) && value.length === 0))
558
- return this.renderTokens(token[4], context, partials, originalTemplate, config);
559
- };
560
- Writer.prototype.indentPartial = function indentPartial(partial, indentation, lineHasNonSpace) {
561
- var filteredIndentation = indentation.replace(/[^ \t]/g, '');
562
- var partialByNl = partial.split('\n');
563
- for (var i = 0; i < partialByNl.length; i++) {
564
- if (partialByNl[i].length && (i > 0 || !lineHasNonSpace)) {
565
- partialByNl[i] = filteredIndentation + partialByNl[i];
566
- }
567
- }
568
- return partialByNl.join('\n');
569
- };
570
- Writer.prototype.renderPartial = function renderPartial(token, context, partials, config) {
571
- if (!partials)
572
- return;
573
- var tags = this.getConfigTags(config);
574
- var value = isFunction(partials) ? partials(token[1]) : partials[token[1]];
575
- if (value != null) {
576
- var lineHasNonSpace = token[6];
577
- var tagIndex = token[5];
578
- var indentation = token[4];
579
- var indentedValue = value;
580
- if (tagIndex == 0 && indentation) {
581
- indentedValue = this.indentPartial(value, indentation, lineHasNonSpace);
582
- }
583
- var tokens = this.parse(indentedValue, tags);
584
- return this.renderTokens(tokens, context, partials, indentedValue, config);
585
- }
586
- };
587
- Writer.prototype.unescapedValue = async function unescapedValue(token, context) {
588
- var value = await context.lookup(token[1]);
589
- if (value != null)
590
- return typeof value === 'object' ? JSON.stringify(value) : value;
591
- };
592
- Writer.prototype.escapedValue = async function escapedValue(token, context, config) {
593
- var escape = this.getConfigEscape(config) || mustache.escape;
594
- var value = await context.lookup(token[1]);
595
- if (typeof value === 'function') {
596
- value = await value.call(context.view);
597
- }
598
- if (value != null)
599
- return typeof value === 'number' && escape === mustache.escape ? String(value) : escape(value);
600
- };
601
- Writer.prototype.rawValue = function rawValue(token) {
602
- return token[1];
603
- };
604
- Writer.prototype.getConfigTags = function getConfigTags(config) {
605
- if (isArray(config)) {
606
- return config;
607
- }
608
- else if (config && typeof config === 'object') {
609
- return config.tags;
610
- }
611
- else {
612
- return undefined;
613
- }
614
- };
615
- Writer.prototype.getConfigEscape = function getConfigEscape(config) {
616
- if (config && typeof config === 'object' && !isArray(config)) {
617
- return config.escape;
618
- }
619
- else {
620
- return undefined;
621
- }
622
- };
623
- var mustache = {
624
- name: 'mustache.js',
625
- version: '4.2.0',
626
- tags: ['{{', '}}'],
627
- clearCache: undefined,
628
- escape: undefined,
629
- parse: undefined,
630
- render: undefined,
631
- Scanner: undefined,
632
- Context: undefined,
633
- Writer: undefined,
634
- /**
635
- * Allows a user to override the default caching strategy, by providing an
636
- * object with set, get and clear methods. This can also be used to disable
637
- * the cache by setting it to the literal `undefined`.
638
- */
639
- set templateCache(cache) {
640
- defaultWriter.templateCache = cache;
641
- },
642
- /**
643
- * Gets the default or overridden caching object from the default writer.
644
- */
645
- get templateCache() {
646
- return defaultWriter.templateCache;
647
- },
648
- };
649
- // All high-level mustache.* functions use this writer.
650
- var defaultWriter = new Writer();
651
- /**
652
- * Clears all cached templates in the default writer.
653
- */
654
- mustache.clearCache = function clearCache() {
655
- return defaultWriter.clearCache();
656
- };
657
- /**
658
- * Parses and caches the given template in the default writer and returns the
659
- * array of tokens it contains. Doing this ahead of time avoids the need to
660
- * parse templates on the fly as they are rendered.
661
- */
662
- mustache.parse = function parse(template, tags) {
663
- return defaultWriter.parse(template, tags);
664
- };
665
- /**
666
- * Renders the `template` with the given `view`, `partials`, and `config`
667
- * using the default writer.
668
- */
669
- mustache.render = function render(template, view, partials, config) {
670
- if (typeof template !== 'string') {
671
- throw new TypeError('Invalid template! Template should be a "string" ' +
672
- 'but "' +
673
- typeStr(template) +
674
- '" was given as the first ' +
675
- 'argument for mustache#render(template, view, partials)');
676
- }
677
- return defaultWriter.render(template, view, partials, config);
678
- };
679
- // Export the escaping function so that the user may override it.
680
- // See https://github.com/janl/mustache.js/issues/244
681
- mustache.escape = escapeHtml;
682
- // Export these mainly for testing, but also for advanced usage.
683
- mustache.Scanner = Scanner;
684
- mustache.Context = Context;
685
- mustache.Writer = Writer;
686
- export default mustache;