conversationalist 0.0.2 → 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.
- package/README.md +521 -287
- package/dist/context.d.ts +22 -19
- package/dist/context.d.ts.map +1 -1
- package/dist/conversation.d.ts.map +1 -1
- package/dist/environment.d.ts +13 -1
- package/dist/environment.d.ts.map +1 -1
- package/dist/history.d.ts +165 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4196 -159
- package/dist/index.js.map +53 -8
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/pii-redaction.d.ts +36 -0
- package/dist/plugins/pii-redaction.d.ts.map +1 -0
- package/dist/types.d.ts +22 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utilities.d.ts +75 -1
- package/dist/utilities.d.ts.map +1 -1
- package/dist/with-conversation.d.ts +3 -3
- package/dist/with-conversation.d.ts.map +1 -1
- package/package.json +10 -2
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3496 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
+
for (let key of __getOwnPropNames(mod))
|
|
11
|
+
if (!__hasOwnProp.call(to, key))
|
|
12
|
+
__defProp(to, key, {
|
|
13
|
+
get: () => mod[key],
|
|
14
|
+
enumerable: true
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
19
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
20
|
+
|
|
21
|
+
// node_modules/kind-of/index.js
|
|
22
|
+
var require_kind_of = __commonJS((exports, module) => {
|
|
23
|
+
var toString = Object.prototype.toString;
|
|
24
|
+
module.exports = function kindOf(val) {
|
|
25
|
+
if (val === undefined)
|
|
26
|
+
return "undefined";
|
|
27
|
+
if (val === null)
|
|
28
|
+
return "null";
|
|
29
|
+
var type = typeof val;
|
|
30
|
+
if (type === "boolean")
|
|
31
|
+
return "boolean";
|
|
32
|
+
if (type === "string")
|
|
33
|
+
return "string";
|
|
34
|
+
if (type === "number")
|
|
35
|
+
return "number";
|
|
36
|
+
if (type === "symbol")
|
|
37
|
+
return "symbol";
|
|
38
|
+
if (type === "function") {
|
|
39
|
+
return isGeneratorFn(val) ? "generatorfunction" : "function";
|
|
40
|
+
}
|
|
41
|
+
if (isArray(val))
|
|
42
|
+
return "array";
|
|
43
|
+
if (isBuffer(val))
|
|
44
|
+
return "buffer";
|
|
45
|
+
if (isArguments(val))
|
|
46
|
+
return "arguments";
|
|
47
|
+
if (isDate(val))
|
|
48
|
+
return "date";
|
|
49
|
+
if (isError(val))
|
|
50
|
+
return "error";
|
|
51
|
+
if (isRegexp(val))
|
|
52
|
+
return "regexp";
|
|
53
|
+
switch (ctorName(val)) {
|
|
54
|
+
case "Symbol":
|
|
55
|
+
return "symbol";
|
|
56
|
+
case "Promise":
|
|
57
|
+
return "promise";
|
|
58
|
+
case "WeakMap":
|
|
59
|
+
return "weakmap";
|
|
60
|
+
case "WeakSet":
|
|
61
|
+
return "weakset";
|
|
62
|
+
case "Map":
|
|
63
|
+
return "map";
|
|
64
|
+
case "Set":
|
|
65
|
+
return "set";
|
|
66
|
+
case "Int8Array":
|
|
67
|
+
return "int8array";
|
|
68
|
+
case "Uint8Array":
|
|
69
|
+
return "uint8array";
|
|
70
|
+
case "Uint8ClampedArray":
|
|
71
|
+
return "uint8clampedarray";
|
|
72
|
+
case "Int16Array":
|
|
73
|
+
return "int16array";
|
|
74
|
+
case "Uint16Array":
|
|
75
|
+
return "uint16array";
|
|
76
|
+
case "Int32Array":
|
|
77
|
+
return "int32array";
|
|
78
|
+
case "Uint32Array":
|
|
79
|
+
return "uint32array";
|
|
80
|
+
case "Float32Array":
|
|
81
|
+
return "float32array";
|
|
82
|
+
case "Float64Array":
|
|
83
|
+
return "float64array";
|
|
84
|
+
}
|
|
85
|
+
if (isGeneratorObj(val)) {
|
|
86
|
+
return "generator";
|
|
87
|
+
}
|
|
88
|
+
type = toString.call(val);
|
|
89
|
+
switch (type) {
|
|
90
|
+
case "[object Object]":
|
|
91
|
+
return "object";
|
|
92
|
+
case "[object Map Iterator]":
|
|
93
|
+
return "mapiterator";
|
|
94
|
+
case "[object Set Iterator]":
|
|
95
|
+
return "setiterator";
|
|
96
|
+
case "[object String Iterator]":
|
|
97
|
+
return "stringiterator";
|
|
98
|
+
case "[object Array Iterator]":
|
|
99
|
+
return "arrayiterator";
|
|
100
|
+
}
|
|
101
|
+
return type.slice(8, -1).toLowerCase().replace(/\s/g, "");
|
|
102
|
+
};
|
|
103
|
+
function ctorName(val) {
|
|
104
|
+
return typeof val.constructor === "function" ? val.constructor.name : null;
|
|
105
|
+
}
|
|
106
|
+
function isArray(val) {
|
|
107
|
+
if (Array.isArray)
|
|
108
|
+
return Array.isArray(val);
|
|
109
|
+
return val instanceof Array;
|
|
110
|
+
}
|
|
111
|
+
function isError(val) {
|
|
112
|
+
return val instanceof Error || typeof val.message === "string" && val.constructor && typeof val.constructor.stackTraceLimit === "number";
|
|
113
|
+
}
|
|
114
|
+
function isDate(val) {
|
|
115
|
+
if (val instanceof Date)
|
|
116
|
+
return true;
|
|
117
|
+
return typeof val.toDateString === "function" && typeof val.getDate === "function" && typeof val.setDate === "function";
|
|
118
|
+
}
|
|
119
|
+
function isRegexp(val) {
|
|
120
|
+
if (val instanceof RegExp)
|
|
121
|
+
return true;
|
|
122
|
+
return typeof val.flags === "string" && typeof val.ignoreCase === "boolean" && typeof val.multiline === "boolean" && typeof val.global === "boolean";
|
|
123
|
+
}
|
|
124
|
+
function isGeneratorFn(name, val) {
|
|
125
|
+
return ctorName(name) === "GeneratorFunction";
|
|
126
|
+
}
|
|
127
|
+
function isGeneratorObj(val) {
|
|
128
|
+
return typeof val.throw === "function" && typeof val.return === "function" && typeof val.next === "function";
|
|
129
|
+
}
|
|
130
|
+
function isArguments(val) {
|
|
131
|
+
try {
|
|
132
|
+
if (typeof val.length === "number" && typeof val.callee === "function") {
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
} catch (err) {
|
|
136
|
+
if (err.message.indexOf("callee") !== -1) {
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
function isBuffer(val) {
|
|
143
|
+
if (val.constructor && typeof val.constructor.isBuffer === "function") {
|
|
144
|
+
return val.constructor.isBuffer(val);
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// node_modules/is-extendable/index.js
|
|
151
|
+
var require_is_extendable = __commonJS((exports, module) => {
|
|
152
|
+
/*!
|
|
153
|
+
* is-extendable <https://github.com/jonschlinkert/is-extendable>
|
|
154
|
+
*
|
|
155
|
+
* Copyright (c) 2015, Jon Schlinkert.
|
|
156
|
+
* Licensed under the MIT License.
|
|
157
|
+
*/
|
|
158
|
+
module.exports = function isExtendable(val) {
|
|
159
|
+
return typeof val !== "undefined" && val !== null && (typeof val === "object" || typeof val === "function");
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// node_modules/extend-shallow/index.js
|
|
164
|
+
var require_extend_shallow = __commonJS((exports, module) => {
|
|
165
|
+
var isObject = require_is_extendable();
|
|
166
|
+
module.exports = function extend(o) {
|
|
167
|
+
if (!isObject(o)) {
|
|
168
|
+
o = {};
|
|
169
|
+
}
|
|
170
|
+
var len = arguments.length;
|
|
171
|
+
for (var i = 1;i < len; i++) {
|
|
172
|
+
var obj = arguments[i];
|
|
173
|
+
if (isObject(obj)) {
|
|
174
|
+
assign(o, obj);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return o;
|
|
178
|
+
};
|
|
179
|
+
function assign(a, b) {
|
|
180
|
+
for (var key in b) {
|
|
181
|
+
if (hasOwn(b, key)) {
|
|
182
|
+
a[key] = b[key];
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function hasOwn(obj, key) {
|
|
187
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
// node_modules/section-matter/index.js
|
|
192
|
+
var require_section_matter = __commonJS((exports, module) => {
|
|
193
|
+
var typeOf = require_kind_of();
|
|
194
|
+
var extend = require_extend_shallow();
|
|
195
|
+
module.exports = function(input, options2) {
|
|
196
|
+
if (typeof options2 === "function") {
|
|
197
|
+
options2 = { parse: options2 };
|
|
198
|
+
}
|
|
199
|
+
var file = toObject(input);
|
|
200
|
+
var defaults = { section_delimiter: "---", parse: identity };
|
|
201
|
+
var opts = extend({}, defaults, options2);
|
|
202
|
+
var delim = opts.section_delimiter;
|
|
203
|
+
var lines = file.content.split(/\r?\n/);
|
|
204
|
+
var sections = null;
|
|
205
|
+
var section = createSection();
|
|
206
|
+
var content = [];
|
|
207
|
+
var stack = [];
|
|
208
|
+
function initSections(val) {
|
|
209
|
+
file.content = val;
|
|
210
|
+
sections = [];
|
|
211
|
+
content = [];
|
|
212
|
+
}
|
|
213
|
+
function closeSection(val) {
|
|
214
|
+
if (stack.length) {
|
|
215
|
+
section.key = getKey(stack[0], delim);
|
|
216
|
+
section.content = val;
|
|
217
|
+
opts.parse(section, sections);
|
|
218
|
+
sections.push(section);
|
|
219
|
+
section = createSection();
|
|
220
|
+
content = [];
|
|
221
|
+
stack = [];
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
for (var i = 0;i < lines.length; i++) {
|
|
225
|
+
var line = lines[i];
|
|
226
|
+
var len = stack.length;
|
|
227
|
+
var ln = line.trim();
|
|
228
|
+
if (isDelimiter(ln, delim)) {
|
|
229
|
+
if (ln.length === 3 && i !== 0) {
|
|
230
|
+
if (len === 0 || len === 2) {
|
|
231
|
+
content.push(line);
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
stack.push(ln);
|
|
235
|
+
section.data = content.join(`
|
|
236
|
+
`);
|
|
237
|
+
content = [];
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
if (sections === null) {
|
|
241
|
+
initSections(content.join(`
|
|
242
|
+
`));
|
|
243
|
+
}
|
|
244
|
+
if (len === 2) {
|
|
245
|
+
closeSection(content.join(`
|
|
246
|
+
`));
|
|
247
|
+
}
|
|
248
|
+
stack.push(ln);
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
content.push(line);
|
|
252
|
+
}
|
|
253
|
+
if (sections === null) {
|
|
254
|
+
initSections(content.join(`
|
|
255
|
+
`));
|
|
256
|
+
} else {
|
|
257
|
+
closeSection(content.join(`
|
|
258
|
+
`));
|
|
259
|
+
}
|
|
260
|
+
file.sections = sections;
|
|
261
|
+
return file;
|
|
262
|
+
};
|
|
263
|
+
function isDelimiter(line, delim) {
|
|
264
|
+
if (line.slice(0, delim.length) !== delim) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
if (line.charAt(delim.length + 1) === delim.slice(-1)) {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
function toObject(input) {
|
|
273
|
+
if (typeOf(input) !== "object") {
|
|
274
|
+
input = { content: input };
|
|
275
|
+
}
|
|
276
|
+
if (typeof input.content !== "string" && !isBuffer(input.content)) {
|
|
277
|
+
throw new TypeError("expected a buffer or string");
|
|
278
|
+
}
|
|
279
|
+
input.content = input.content.toString();
|
|
280
|
+
input.sections = [];
|
|
281
|
+
return input;
|
|
282
|
+
}
|
|
283
|
+
function getKey(val, delim) {
|
|
284
|
+
return val ? val.slice(delim.length).trim() : "";
|
|
285
|
+
}
|
|
286
|
+
function createSection() {
|
|
287
|
+
return { key: "", data: "", content: "" };
|
|
288
|
+
}
|
|
289
|
+
function identity(val) {
|
|
290
|
+
return val;
|
|
291
|
+
}
|
|
292
|
+
function isBuffer(val) {
|
|
293
|
+
if (val && val.constructor && typeof val.constructor.isBuffer === "function") {
|
|
294
|
+
return val.constructor.isBuffer(val);
|
|
295
|
+
}
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/common.js
|
|
301
|
+
var require_common = __commonJS((exports, module) => {
|
|
302
|
+
function isNothing(subject) {
|
|
303
|
+
return typeof subject === "undefined" || subject === null;
|
|
304
|
+
}
|
|
305
|
+
function isObject(subject) {
|
|
306
|
+
return typeof subject === "object" && subject !== null;
|
|
307
|
+
}
|
|
308
|
+
function toArray(sequence) {
|
|
309
|
+
if (Array.isArray(sequence))
|
|
310
|
+
return sequence;
|
|
311
|
+
else if (isNothing(sequence))
|
|
312
|
+
return [];
|
|
313
|
+
return [sequence];
|
|
314
|
+
}
|
|
315
|
+
function extend(target, source) {
|
|
316
|
+
var index, length, key, sourceKeys;
|
|
317
|
+
if (source) {
|
|
318
|
+
sourceKeys = Object.keys(source);
|
|
319
|
+
for (index = 0, length = sourceKeys.length;index < length; index += 1) {
|
|
320
|
+
key = sourceKeys[index];
|
|
321
|
+
target[key] = source[key];
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return target;
|
|
325
|
+
}
|
|
326
|
+
function repeat(string, count) {
|
|
327
|
+
var result = "", cycle;
|
|
328
|
+
for (cycle = 0;cycle < count; cycle += 1) {
|
|
329
|
+
result += string;
|
|
330
|
+
}
|
|
331
|
+
return result;
|
|
332
|
+
}
|
|
333
|
+
function isNegativeZero(number) {
|
|
334
|
+
return number === 0 && Number.NEGATIVE_INFINITY === 1 / number;
|
|
335
|
+
}
|
|
336
|
+
exports.isNothing = isNothing;
|
|
337
|
+
exports.isObject = isObject;
|
|
338
|
+
exports.toArray = toArray;
|
|
339
|
+
exports.repeat = repeat;
|
|
340
|
+
exports.isNegativeZero = isNegativeZero;
|
|
341
|
+
exports.extend = extend;
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/exception.js
|
|
345
|
+
var require_exception = __commonJS((exports, module) => {
|
|
346
|
+
function YAMLException(reason, mark) {
|
|
347
|
+
Error.call(this);
|
|
348
|
+
this.name = "YAMLException";
|
|
349
|
+
this.reason = reason;
|
|
350
|
+
this.mark = mark;
|
|
351
|
+
this.message = (this.reason || "(unknown reason)") + (this.mark ? " " + this.mark.toString() : "");
|
|
352
|
+
if (Error.captureStackTrace) {
|
|
353
|
+
Error.captureStackTrace(this, this.constructor);
|
|
354
|
+
} else {
|
|
355
|
+
this.stack = new Error().stack || "";
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
YAMLException.prototype = Object.create(Error.prototype);
|
|
359
|
+
YAMLException.prototype.constructor = YAMLException;
|
|
360
|
+
YAMLException.prototype.toString = function toString(compact) {
|
|
361
|
+
var result = this.name + ": ";
|
|
362
|
+
result += this.reason || "(unknown reason)";
|
|
363
|
+
if (!compact && this.mark) {
|
|
364
|
+
result += " " + this.mark.toString();
|
|
365
|
+
}
|
|
366
|
+
return result;
|
|
367
|
+
};
|
|
368
|
+
module.exports = YAMLException;
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/mark.js
|
|
372
|
+
var require_mark = __commonJS((exports, module) => {
|
|
373
|
+
var common = require_common();
|
|
374
|
+
function Mark(name, buffer, position, line, column) {
|
|
375
|
+
this.name = name;
|
|
376
|
+
this.buffer = buffer;
|
|
377
|
+
this.position = position;
|
|
378
|
+
this.line = line;
|
|
379
|
+
this.column = column;
|
|
380
|
+
}
|
|
381
|
+
Mark.prototype.getSnippet = function getSnippet(indent, maxLength) {
|
|
382
|
+
var head, start, tail, end, snippet;
|
|
383
|
+
if (!this.buffer)
|
|
384
|
+
return null;
|
|
385
|
+
indent = indent || 4;
|
|
386
|
+
maxLength = maxLength || 75;
|
|
387
|
+
head = "";
|
|
388
|
+
start = this.position;
|
|
389
|
+
while (start > 0 && `\x00\r
|
|
390
|
+
\u2028\u2029`.indexOf(this.buffer.charAt(start - 1)) === -1) {
|
|
391
|
+
start -= 1;
|
|
392
|
+
if (this.position - start > maxLength / 2 - 1) {
|
|
393
|
+
head = " ... ";
|
|
394
|
+
start += 5;
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
tail = "";
|
|
399
|
+
end = this.position;
|
|
400
|
+
while (end < this.buffer.length && `\x00\r
|
|
401
|
+
\u2028\u2029`.indexOf(this.buffer.charAt(end)) === -1) {
|
|
402
|
+
end += 1;
|
|
403
|
+
if (end - this.position > maxLength / 2 - 1) {
|
|
404
|
+
tail = " ... ";
|
|
405
|
+
end -= 5;
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
snippet = this.buffer.slice(start, end);
|
|
410
|
+
return common.repeat(" ", indent) + head + snippet + tail + `
|
|
411
|
+
` + common.repeat(" ", indent + this.position - start + head.length) + "^";
|
|
412
|
+
};
|
|
413
|
+
Mark.prototype.toString = function toString(compact) {
|
|
414
|
+
var snippet, where = "";
|
|
415
|
+
if (this.name) {
|
|
416
|
+
where += 'in "' + this.name + '" ';
|
|
417
|
+
}
|
|
418
|
+
where += "at line " + (this.line + 1) + ", column " + (this.column + 1);
|
|
419
|
+
if (!compact) {
|
|
420
|
+
snippet = this.getSnippet();
|
|
421
|
+
if (snippet) {
|
|
422
|
+
where += `:
|
|
423
|
+
` + snippet;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
return where;
|
|
427
|
+
};
|
|
428
|
+
module.exports = Mark;
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type.js
|
|
432
|
+
var require_type = __commonJS((exports, module) => {
|
|
433
|
+
var YAMLException = require_exception();
|
|
434
|
+
var TYPE_CONSTRUCTOR_OPTIONS = [
|
|
435
|
+
"kind",
|
|
436
|
+
"resolve",
|
|
437
|
+
"construct",
|
|
438
|
+
"instanceOf",
|
|
439
|
+
"predicate",
|
|
440
|
+
"represent",
|
|
441
|
+
"defaultStyle",
|
|
442
|
+
"styleAliases"
|
|
443
|
+
];
|
|
444
|
+
var YAML_NODE_KINDS = [
|
|
445
|
+
"scalar",
|
|
446
|
+
"sequence",
|
|
447
|
+
"mapping"
|
|
448
|
+
];
|
|
449
|
+
function compileStyleAliases(map) {
|
|
450
|
+
var result = {};
|
|
451
|
+
if (map !== null) {
|
|
452
|
+
Object.keys(map).forEach(function(style) {
|
|
453
|
+
map[style].forEach(function(alias) {
|
|
454
|
+
result[String(alias)] = style;
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
return result;
|
|
459
|
+
}
|
|
460
|
+
function Type(tag, options2) {
|
|
461
|
+
options2 = options2 || {};
|
|
462
|
+
Object.keys(options2).forEach(function(name) {
|
|
463
|
+
if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
|
|
464
|
+
throw new YAMLException('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
this.tag = tag;
|
|
468
|
+
this.kind = options2["kind"] || null;
|
|
469
|
+
this.resolve = options2["resolve"] || function() {
|
|
470
|
+
return true;
|
|
471
|
+
};
|
|
472
|
+
this.construct = options2["construct"] || function(data) {
|
|
473
|
+
return data;
|
|
474
|
+
};
|
|
475
|
+
this.instanceOf = options2["instanceOf"] || null;
|
|
476
|
+
this.predicate = options2["predicate"] || null;
|
|
477
|
+
this.represent = options2["represent"] || null;
|
|
478
|
+
this.defaultStyle = options2["defaultStyle"] || null;
|
|
479
|
+
this.styleAliases = compileStyleAliases(options2["styleAliases"] || null);
|
|
480
|
+
if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
|
|
481
|
+
throw new YAMLException('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
module.exports = Type;
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/schema.js
|
|
488
|
+
var require_schema = __commonJS((exports, module) => {
|
|
489
|
+
var common = require_common();
|
|
490
|
+
var YAMLException = require_exception();
|
|
491
|
+
var Type = require_type();
|
|
492
|
+
function compileList(schema, name, result) {
|
|
493
|
+
var exclude = [];
|
|
494
|
+
schema.include.forEach(function(includedSchema) {
|
|
495
|
+
result = compileList(includedSchema, name, result);
|
|
496
|
+
});
|
|
497
|
+
schema[name].forEach(function(currentType) {
|
|
498
|
+
result.forEach(function(previousType, previousIndex) {
|
|
499
|
+
if (previousType.tag === currentType.tag && previousType.kind === currentType.kind) {
|
|
500
|
+
exclude.push(previousIndex);
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
result.push(currentType);
|
|
504
|
+
});
|
|
505
|
+
return result.filter(function(type, index) {
|
|
506
|
+
return exclude.indexOf(index) === -1;
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
function compileMap() {
|
|
510
|
+
var result = {
|
|
511
|
+
scalar: {},
|
|
512
|
+
sequence: {},
|
|
513
|
+
mapping: {},
|
|
514
|
+
fallback: {}
|
|
515
|
+
}, index, length;
|
|
516
|
+
function collectType(type) {
|
|
517
|
+
result[type.kind][type.tag] = result["fallback"][type.tag] = type;
|
|
518
|
+
}
|
|
519
|
+
for (index = 0, length = arguments.length;index < length; index += 1) {
|
|
520
|
+
arguments[index].forEach(collectType);
|
|
521
|
+
}
|
|
522
|
+
return result;
|
|
523
|
+
}
|
|
524
|
+
function Schema(definition) {
|
|
525
|
+
this.include = definition.include || [];
|
|
526
|
+
this.implicit = definition.implicit || [];
|
|
527
|
+
this.explicit = definition.explicit || [];
|
|
528
|
+
this.implicit.forEach(function(type) {
|
|
529
|
+
if (type.loadKind && type.loadKind !== "scalar") {
|
|
530
|
+
throw new YAMLException("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");
|
|
531
|
+
}
|
|
532
|
+
});
|
|
533
|
+
this.compiledImplicit = compileList(this, "implicit", []);
|
|
534
|
+
this.compiledExplicit = compileList(this, "explicit", []);
|
|
535
|
+
this.compiledTypeMap = compileMap(this.compiledImplicit, this.compiledExplicit);
|
|
536
|
+
}
|
|
537
|
+
Schema.DEFAULT = null;
|
|
538
|
+
Schema.create = function createSchema() {
|
|
539
|
+
var schemas, types;
|
|
540
|
+
switch (arguments.length) {
|
|
541
|
+
case 1:
|
|
542
|
+
schemas = Schema.DEFAULT;
|
|
543
|
+
types = arguments[0];
|
|
544
|
+
break;
|
|
545
|
+
case 2:
|
|
546
|
+
schemas = arguments[0];
|
|
547
|
+
types = arguments[1];
|
|
548
|
+
break;
|
|
549
|
+
default:
|
|
550
|
+
throw new YAMLException("Wrong number of arguments for Schema.create function");
|
|
551
|
+
}
|
|
552
|
+
schemas = common.toArray(schemas);
|
|
553
|
+
types = common.toArray(types);
|
|
554
|
+
if (!schemas.every(function(schema) {
|
|
555
|
+
return schema instanceof Schema;
|
|
556
|
+
})) {
|
|
557
|
+
throw new YAMLException("Specified list of super schemas (or a single Schema object) contains a non-Schema object.");
|
|
558
|
+
}
|
|
559
|
+
if (!types.every(function(type) {
|
|
560
|
+
return type instanceof Type;
|
|
561
|
+
})) {
|
|
562
|
+
throw new YAMLException("Specified list of YAML types (or a single Type object) contains a non-Type object.");
|
|
563
|
+
}
|
|
564
|
+
return new Schema({
|
|
565
|
+
include: schemas,
|
|
566
|
+
explicit: types
|
|
567
|
+
});
|
|
568
|
+
};
|
|
569
|
+
module.exports = Schema;
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/str.js
|
|
573
|
+
var require_str = __commonJS((exports, module) => {
|
|
574
|
+
var Type = require_type();
|
|
575
|
+
module.exports = new Type("tag:yaml.org,2002:str", {
|
|
576
|
+
kind: "scalar",
|
|
577
|
+
construct: function(data) {
|
|
578
|
+
return data !== null ? data : "";
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/seq.js
|
|
584
|
+
var require_seq = __commonJS((exports, module) => {
|
|
585
|
+
var Type = require_type();
|
|
586
|
+
module.exports = new Type("tag:yaml.org,2002:seq", {
|
|
587
|
+
kind: "sequence",
|
|
588
|
+
construct: function(data) {
|
|
589
|
+
return data !== null ? data : [];
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/map.js
|
|
595
|
+
var require_map = __commonJS((exports, module) => {
|
|
596
|
+
var Type = require_type();
|
|
597
|
+
module.exports = new Type("tag:yaml.org,2002:map", {
|
|
598
|
+
kind: "mapping",
|
|
599
|
+
construct: function(data) {
|
|
600
|
+
return data !== null ? data : {};
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/schema/failsafe.js
|
|
606
|
+
var require_failsafe = __commonJS((exports, module) => {
|
|
607
|
+
var Schema = require_schema();
|
|
608
|
+
module.exports = new Schema({
|
|
609
|
+
explicit: [
|
|
610
|
+
require_str(),
|
|
611
|
+
require_seq(),
|
|
612
|
+
require_map()
|
|
613
|
+
]
|
|
614
|
+
});
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/null.js
|
|
618
|
+
var require_null = __commonJS((exports, module) => {
|
|
619
|
+
var Type = require_type();
|
|
620
|
+
function resolveYamlNull(data) {
|
|
621
|
+
if (data === null)
|
|
622
|
+
return true;
|
|
623
|
+
var max = data.length;
|
|
624
|
+
return max === 1 && data === "~" || max === 4 && (data === "null" || data === "Null" || data === "NULL");
|
|
625
|
+
}
|
|
626
|
+
function constructYamlNull() {
|
|
627
|
+
return null;
|
|
628
|
+
}
|
|
629
|
+
function isNull(object) {
|
|
630
|
+
return object === null;
|
|
631
|
+
}
|
|
632
|
+
module.exports = new Type("tag:yaml.org,2002:null", {
|
|
633
|
+
kind: "scalar",
|
|
634
|
+
resolve: resolveYamlNull,
|
|
635
|
+
construct: constructYamlNull,
|
|
636
|
+
predicate: isNull,
|
|
637
|
+
represent: {
|
|
638
|
+
canonical: function() {
|
|
639
|
+
return "~";
|
|
640
|
+
},
|
|
641
|
+
lowercase: function() {
|
|
642
|
+
return "null";
|
|
643
|
+
},
|
|
644
|
+
uppercase: function() {
|
|
645
|
+
return "NULL";
|
|
646
|
+
},
|
|
647
|
+
camelcase: function() {
|
|
648
|
+
return "Null";
|
|
649
|
+
}
|
|
650
|
+
},
|
|
651
|
+
defaultStyle: "lowercase"
|
|
652
|
+
});
|
|
653
|
+
});
|
|
654
|
+
|
|
655
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/bool.js
|
|
656
|
+
var require_bool = __commonJS((exports, module) => {
|
|
657
|
+
var Type = require_type();
|
|
658
|
+
function resolveYamlBoolean(data) {
|
|
659
|
+
if (data === null)
|
|
660
|
+
return false;
|
|
661
|
+
var max = data.length;
|
|
662
|
+
return max === 4 && (data === "true" || data === "True" || data === "TRUE") || max === 5 && (data === "false" || data === "False" || data === "FALSE");
|
|
663
|
+
}
|
|
664
|
+
function constructYamlBoolean(data) {
|
|
665
|
+
return data === "true" || data === "True" || data === "TRUE";
|
|
666
|
+
}
|
|
667
|
+
function isBoolean(object) {
|
|
668
|
+
return Object.prototype.toString.call(object) === "[object Boolean]";
|
|
669
|
+
}
|
|
670
|
+
module.exports = new Type("tag:yaml.org,2002:bool", {
|
|
671
|
+
kind: "scalar",
|
|
672
|
+
resolve: resolveYamlBoolean,
|
|
673
|
+
construct: constructYamlBoolean,
|
|
674
|
+
predicate: isBoolean,
|
|
675
|
+
represent: {
|
|
676
|
+
lowercase: function(object) {
|
|
677
|
+
return object ? "true" : "false";
|
|
678
|
+
},
|
|
679
|
+
uppercase: function(object) {
|
|
680
|
+
return object ? "TRUE" : "FALSE";
|
|
681
|
+
},
|
|
682
|
+
camelcase: function(object) {
|
|
683
|
+
return object ? "True" : "False";
|
|
684
|
+
}
|
|
685
|
+
},
|
|
686
|
+
defaultStyle: "lowercase"
|
|
687
|
+
});
|
|
688
|
+
});
|
|
689
|
+
|
|
690
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/int.js
|
|
691
|
+
var require_int = __commonJS((exports, module) => {
|
|
692
|
+
var common = require_common();
|
|
693
|
+
var Type = require_type();
|
|
694
|
+
function isHexCode(c) {
|
|
695
|
+
return 48 <= c && c <= 57 || 65 <= c && c <= 70 || 97 <= c && c <= 102;
|
|
696
|
+
}
|
|
697
|
+
function isOctCode(c) {
|
|
698
|
+
return 48 <= c && c <= 55;
|
|
699
|
+
}
|
|
700
|
+
function isDecCode(c) {
|
|
701
|
+
return 48 <= c && c <= 57;
|
|
702
|
+
}
|
|
703
|
+
function resolveYamlInteger(data) {
|
|
704
|
+
if (data === null)
|
|
705
|
+
return false;
|
|
706
|
+
var max = data.length, index = 0, hasDigits = false, ch;
|
|
707
|
+
if (!max)
|
|
708
|
+
return false;
|
|
709
|
+
ch = data[index];
|
|
710
|
+
if (ch === "-" || ch === "+") {
|
|
711
|
+
ch = data[++index];
|
|
712
|
+
}
|
|
713
|
+
if (ch === "0") {
|
|
714
|
+
if (index + 1 === max)
|
|
715
|
+
return true;
|
|
716
|
+
ch = data[++index];
|
|
717
|
+
if (ch === "b") {
|
|
718
|
+
index++;
|
|
719
|
+
for (;index < max; index++) {
|
|
720
|
+
ch = data[index];
|
|
721
|
+
if (ch === "_")
|
|
722
|
+
continue;
|
|
723
|
+
if (ch !== "0" && ch !== "1")
|
|
724
|
+
return false;
|
|
725
|
+
hasDigits = true;
|
|
726
|
+
}
|
|
727
|
+
return hasDigits && ch !== "_";
|
|
728
|
+
}
|
|
729
|
+
if (ch === "x") {
|
|
730
|
+
index++;
|
|
731
|
+
for (;index < max; index++) {
|
|
732
|
+
ch = data[index];
|
|
733
|
+
if (ch === "_")
|
|
734
|
+
continue;
|
|
735
|
+
if (!isHexCode(data.charCodeAt(index)))
|
|
736
|
+
return false;
|
|
737
|
+
hasDigits = true;
|
|
738
|
+
}
|
|
739
|
+
return hasDigits && ch !== "_";
|
|
740
|
+
}
|
|
741
|
+
for (;index < max; index++) {
|
|
742
|
+
ch = data[index];
|
|
743
|
+
if (ch === "_")
|
|
744
|
+
continue;
|
|
745
|
+
if (!isOctCode(data.charCodeAt(index)))
|
|
746
|
+
return false;
|
|
747
|
+
hasDigits = true;
|
|
748
|
+
}
|
|
749
|
+
return hasDigits && ch !== "_";
|
|
750
|
+
}
|
|
751
|
+
if (ch === "_")
|
|
752
|
+
return false;
|
|
753
|
+
for (;index < max; index++) {
|
|
754
|
+
ch = data[index];
|
|
755
|
+
if (ch === "_")
|
|
756
|
+
continue;
|
|
757
|
+
if (ch === ":")
|
|
758
|
+
break;
|
|
759
|
+
if (!isDecCode(data.charCodeAt(index))) {
|
|
760
|
+
return false;
|
|
761
|
+
}
|
|
762
|
+
hasDigits = true;
|
|
763
|
+
}
|
|
764
|
+
if (!hasDigits || ch === "_")
|
|
765
|
+
return false;
|
|
766
|
+
if (ch !== ":")
|
|
767
|
+
return true;
|
|
768
|
+
return /^(:[0-5]?[0-9])+$/.test(data.slice(index));
|
|
769
|
+
}
|
|
770
|
+
function constructYamlInteger(data) {
|
|
771
|
+
var value = data, sign = 1, ch, base, digits = [];
|
|
772
|
+
if (value.indexOf("_") !== -1) {
|
|
773
|
+
value = value.replace(/_/g, "");
|
|
774
|
+
}
|
|
775
|
+
ch = value[0];
|
|
776
|
+
if (ch === "-" || ch === "+") {
|
|
777
|
+
if (ch === "-")
|
|
778
|
+
sign = -1;
|
|
779
|
+
value = value.slice(1);
|
|
780
|
+
ch = value[0];
|
|
781
|
+
}
|
|
782
|
+
if (value === "0")
|
|
783
|
+
return 0;
|
|
784
|
+
if (ch === "0") {
|
|
785
|
+
if (value[1] === "b")
|
|
786
|
+
return sign * parseInt(value.slice(2), 2);
|
|
787
|
+
if (value[1] === "x")
|
|
788
|
+
return sign * parseInt(value, 16);
|
|
789
|
+
return sign * parseInt(value, 8);
|
|
790
|
+
}
|
|
791
|
+
if (value.indexOf(":") !== -1) {
|
|
792
|
+
value.split(":").forEach(function(v) {
|
|
793
|
+
digits.unshift(parseInt(v, 10));
|
|
794
|
+
});
|
|
795
|
+
value = 0;
|
|
796
|
+
base = 1;
|
|
797
|
+
digits.forEach(function(d) {
|
|
798
|
+
value += d * base;
|
|
799
|
+
base *= 60;
|
|
800
|
+
});
|
|
801
|
+
return sign * value;
|
|
802
|
+
}
|
|
803
|
+
return sign * parseInt(value, 10);
|
|
804
|
+
}
|
|
805
|
+
function isInteger(object) {
|
|
806
|
+
return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 === 0 && !common.isNegativeZero(object));
|
|
807
|
+
}
|
|
808
|
+
module.exports = new Type("tag:yaml.org,2002:int", {
|
|
809
|
+
kind: "scalar",
|
|
810
|
+
resolve: resolveYamlInteger,
|
|
811
|
+
construct: constructYamlInteger,
|
|
812
|
+
predicate: isInteger,
|
|
813
|
+
represent: {
|
|
814
|
+
binary: function(obj) {
|
|
815
|
+
return obj >= 0 ? "0b" + obj.toString(2) : "-0b" + obj.toString(2).slice(1);
|
|
816
|
+
},
|
|
817
|
+
octal: function(obj) {
|
|
818
|
+
return obj >= 0 ? "0" + obj.toString(8) : "-0" + obj.toString(8).slice(1);
|
|
819
|
+
},
|
|
820
|
+
decimal: function(obj) {
|
|
821
|
+
return obj.toString(10);
|
|
822
|
+
},
|
|
823
|
+
hexadecimal: function(obj) {
|
|
824
|
+
return obj >= 0 ? "0x" + obj.toString(16).toUpperCase() : "-0x" + obj.toString(16).toUpperCase().slice(1);
|
|
825
|
+
}
|
|
826
|
+
},
|
|
827
|
+
defaultStyle: "decimal",
|
|
828
|
+
styleAliases: {
|
|
829
|
+
binary: [2, "bin"],
|
|
830
|
+
octal: [8, "oct"],
|
|
831
|
+
decimal: [10, "dec"],
|
|
832
|
+
hexadecimal: [16, "hex"]
|
|
833
|
+
}
|
|
834
|
+
});
|
|
835
|
+
});
|
|
836
|
+
|
|
837
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/float.js
|
|
838
|
+
var require_float = __commonJS((exports, module) => {
|
|
839
|
+
var common = require_common();
|
|
840
|
+
var Type = require_type();
|
|
841
|
+
var YAML_FLOAT_PATTERN = new RegExp("^(?:[-+]?(?:0|[1-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?" + "|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?" + "|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*" + "|[-+]?\\.(?:inf|Inf|INF)" + "|\\.(?:nan|NaN|NAN))$");
|
|
842
|
+
function resolveYamlFloat(data) {
|
|
843
|
+
if (data === null)
|
|
844
|
+
return false;
|
|
845
|
+
if (!YAML_FLOAT_PATTERN.test(data) || data[data.length - 1] === "_") {
|
|
846
|
+
return false;
|
|
847
|
+
}
|
|
848
|
+
return true;
|
|
849
|
+
}
|
|
850
|
+
function constructYamlFloat(data) {
|
|
851
|
+
var value, sign, base, digits;
|
|
852
|
+
value = data.replace(/_/g, "").toLowerCase();
|
|
853
|
+
sign = value[0] === "-" ? -1 : 1;
|
|
854
|
+
digits = [];
|
|
855
|
+
if ("+-".indexOf(value[0]) >= 0) {
|
|
856
|
+
value = value.slice(1);
|
|
857
|
+
}
|
|
858
|
+
if (value === ".inf") {
|
|
859
|
+
return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
|
|
860
|
+
} else if (value === ".nan") {
|
|
861
|
+
return NaN;
|
|
862
|
+
} else if (value.indexOf(":") >= 0) {
|
|
863
|
+
value.split(":").forEach(function(v) {
|
|
864
|
+
digits.unshift(parseFloat(v, 10));
|
|
865
|
+
});
|
|
866
|
+
value = 0;
|
|
867
|
+
base = 1;
|
|
868
|
+
digits.forEach(function(d) {
|
|
869
|
+
value += d * base;
|
|
870
|
+
base *= 60;
|
|
871
|
+
});
|
|
872
|
+
return sign * value;
|
|
873
|
+
}
|
|
874
|
+
return sign * parseFloat(value, 10);
|
|
875
|
+
}
|
|
876
|
+
var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
|
|
877
|
+
function representYamlFloat(object, style) {
|
|
878
|
+
var res;
|
|
879
|
+
if (isNaN(object)) {
|
|
880
|
+
switch (style) {
|
|
881
|
+
case "lowercase":
|
|
882
|
+
return ".nan";
|
|
883
|
+
case "uppercase":
|
|
884
|
+
return ".NAN";
|
|
885
|
+
case "camelcase":
|
|
886
|
+
return ".NaN";
|
|
887
|
+
}
|
|
888
|
+
} else if (Number.POSITIVE_INFINITY === object) {
|
|
889
|
+
switch (style) {
|
|
890
|
+
case "lowercase":
|
|
891
|
+
return ".inf";
|
|
892
|
+
case "uppercase":
|
|
893
|
+
return ".INF";
|
|
894
|
+
case "camelcase":
|
|
895
|
+
return ".Inf";
|
|
896
|
+
}
|
|
897
|
+
} else if (Number.NEGATIVE_INFINITY === object) {
|
|
898
|
+
switch (style) {
|
|
899
|
+
case "lowercase":
|
|
900
|
+
return "-.inf";
|
|
901
|
+
case "uppercase":
|
|
902
|
+
return "-.INF";
|
|
903
|
+
case "camelcase":
|
|
904
|
+
return "-.Inf";
|
|
905
|
+
}
|
|
906
|
+
} else if (common.isNegativeZero(object)) {
|
|
907
|
+
return "-0.0";
|
|
908
|
+
}
|
|
909
|
+
res = object.toString(10);
|
|
910
|
+
return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace("e", ".e") : res;
|
|
911
|
+
}
|
|
912
|
+
function isFloat(object) {
|
|
913
|
+
return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 !== 0 || common.isNegativeZero(object));
|
|
914
|
+
}
|
|
915
|
+
module.exports = new Type("tag:yaml.org,2002:float", {
|
|
916
|
+
kind: "scalar",
|
|
917
|
+
resolve: resolveYamlFloat,
|
|
918
|
+
construct: constructYamlFloat,
|
|
919
|
+
predicate: isFloat,
|
|
920
|
+
represent: representYamlFloat,
|
|
921
|
+
defaultStyle: "lowercase"
|
|
922
|
+
});
|
|
923
|
+
});
|
|
924
|
+
|
|
925
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/schema/json.js
|
|
926
|
+
var require_json = __commonJS((exports, module) => {
|
|
927
|
+
var Schema = require_schema();
|
|
928
|
+
module.exports = new Schema({
|
|
929
|
+
include: [
|
|
930
|
+
require_failsafe()
|
|
931
|
+
],
|
|
932
|
+
implicit: [
|
|
933
|
+
require_null(),
|
|
934
|
+
require_bool(),
|
|
935
|
+
require_int(),
|
|
936
|
+
require_float()
|
|
937
|
+
]
|
|
938
|
+
});
|
|
939
|
+
});
|
|
940
|
+
|
|
941
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/schema/core.js
|
|
942
|
+
var require_core = __commonJS((exports, module) => {
|
|
943
|
+
var Schema = require_schema();
|
|
944
|
+
module.exports = new Schema({
|
|
945
|
+
include: [
|
|
946
|
+
require_json()
|
|
947
|
+
]
|
|
948
|
+
});
|
|
949
|
+
});
|
|
950
|
+
|
|
951
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/timestamp.js
|
|
952
|
+
var require_timestamp = __commonJS((exports, module) => {
|
|
953
|
+
var Type = require_type();
|
|
954
|
+
var YAML_DATE_REGEXP = new RegExp("^([0-9][0-9][0-9][0-9])" + "-([0-9][0-9])" + "-([0-9][0-9])$");
|
|
955
|
+
var YAML_TIMESTAMP_REGEXP = new RegExp("^([0-9][0-9][0-9][0-9])" + "-([0-9][0-9]?)" + "-([0-9][0-9]?)" + "(?:[Tt]|[ \\t]+)" + "([0-9][0-9]?)" + ":([0-9][0-9])" + ":([0-9][0-9])" + "(?:\\.([0-9]*))?" + "(?:[ \\t]*(Z|([-+])([0-9][0-9]?)" + "(?::([0-9][0-9]))?))?$");
|
|
956
|
+
function resolveYamlTimestamp(data) {
|
|
957
|
+
if (data === null)
|
|
958
|
+
return false;
|
|
959
|
+
if (YAML_DATE_REGEXP.exec(data) !== null)
|
|
960
|
+
return true;
|
|
961
|
+
if (YAML_TIMESTAMP_REGEXP.exec(data) !== null)
|
|
962
|
+
return true;
|
|
963
|
+
return false;
|
|
964
|
+
}
|
|
965
|
+
function constructYamlTimestamp(data) {
|
|
966
|
+
var match, year, month, day, hour, minute, second, fraction = 0, delta = null, tz_hour, tz_minute, date;
|
|
967
|
+
match = YAML_DATE_REGEXP.exec(data);
|
|
968
|
+
if (match === null)
|
|
969
|
+
match = YAML_TIMESTAMP_REGEXP.exec(data);
|
|
970
|
+
if (match === null)
|
|
971
|
+
throw new Error("Date resolve error");
|
|
972
|
+
year = +match[1];
|
|
973
|
+
month = +match[2] - 1;
|
|
974
|
+
day = +match[3];
|
|
975
|
+
if (!match[4]) {
|
|
976
|
+
return new Date(Date.UTC(year, month, day));
|
|
977
|
+
}
|
|
978
|
+
hour = +match[4];
|
|
979
|
+
minute = +match[5];
|
|
980
|
+
second = +match[6];
|
|
981
|
+
if (match[7]) {
|
|
982
|
+
fraction = match[7].slice(0, 3);
|
|
983
|
+
while (fraction.length < 3) {
|
|
984
|
+
fraction += "0";
|
|
985
|
+
}
|
|
986
|
+
fraction = +fraction;
|
|
987
|
+
}
|
|
988
|
+
if (match[9]) {
|
|
989
|
+
tz_hour = +match[10];
|
|
990
|
+
tz_minute = +(match[11] || 0);
|
|
991
|
+
delta = (tz_hour * 60 + tz_minute) * 60000;
|
|
992
|
+
if (match[9] === "-")
|
|
993
|
+
delta = -delta;
|
|
994
|
+
}
|
|
995
|
+
date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
|
|
996
|
+
if (delta)
|
|
997
|
+
date.setTime(date.getTime() - delta);
|
|
998
|
+
return date;
|
|
999
|
+
}
|
|
1000
|
+
function representYamlTimestamp(object) {
|
|
1001
|
+
return object.toISOString();
|
|
1002
|
+
}
|
|
1003
|
+
module.exports = new Type("tag:yaml.org,2002:timestamp", {
|
|
1004
|
+
kind: "scalar",
|
|
1005
|
+
resolve: resolveYamlTimestamp,
|
|
1006
|
+
construct: constructYamlTimestamp,
|
|
1007
|
+
instanceOf: Date,
|
|
1008
|
+
represent: representYamlTimestamp
|
|
1009
|
+
});
|
|
1010
|
+
});
|
|
1011
|
+
|
|
1012
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/merge.js
|
|
1013
|
+
var require_merge = __commonJS((exports, module) => {
|
|
1014
|
+
var Type = require_type();
|
|
1015
|
+
function resolveYamlMerge(data) {
|
|
1016
|
+
return data === "<<" || data === null;
|
|
1017
|
+
}
|
|
1018
|
+
module.exports = new Type("tag:yaml.org,2002:merge", {
|
|
1019
|
+
kind: "scalar",
|
|
1020
|
+
resolve: resolveYamlMerge
|
|
1021
|
+
});
|
|
1022
|
+
});
|
|
1023
|
+
|
|
1024
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/binary.js
|
|
1025
|
+
var require_binary = __commonJS((exports, module) => {
|
|
1026
|
+
var NodeBuffer;
|
|
1027
|
+
try {
|
|
1028
|
+
_require = __require;
|
|
1029
|
+
NodeBuffer = _require("buffer").Buffer;
|
|
1030
|
+
} catch (__) {}
|
|
1031
|
+
var _require;
|
|
1032
|
+
var Type = require_type();
|
|
1033
|
+
var BASE64_MAP = `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=
|
|
1034
|
+
\r`;
|
|
1035
|
+
function resolveYamlBinary(data) {
|
|
1036
|
+
if (data === null)
|
|
1037
|
+
return false;
|
|
1038
|
+
var code, idx, bitlen = 0, max = data.length, map = BASE64_MAP;
|
|
1039
|
+
for (idx = 0;idx < max; idx++) {
|
|
1040
|
+
code = map.indexOf(data.charAt(idx));
|
|
1041
|
+
if (code > 64)
|
|
1042
|
+
continue;
|
|
1043
|
+
if (code < 0)
|
|
1044
|
+
return false;
|
|
1045
|
+
bitlen += 6;
|
|
1046
|
+
}
|
|
1047
|
+
return bitlen % 8 === 0;
|
|
1048
|
+
}
|
|
1049
|
+
function constructYamlBinary(data) {
|
|
1050
|
+
var idx, tailbits, input = data.replace(/[\r\n=]/g, ""), max = input.length, map = BASE64_MAP, bits = 0, result = [];
|
|
1051
|
+
for (idx = 0;idx < max; idx++) {
|
|
1052
|
+
if (idx % 4 === 0 && idx) {
|
|
1053
|
+
result.push(bits >> 16 & 255);
|
|
1054
|
+
result.push(bits >> 8 & 255);
|
|
1055
|
+
result.push(bits & 255);
|
|
1056
|
+
}
|
|
1057
|
+
bits = bits << 6 | map.indexOf(input.charAt(idx));
|
|
1058
|
+
}
|
|
1059
|
+
tailbits = max % 4 * 6;
|
|
1060
|
+
if (tailbits === 0) {
|
|
1061
|
+
result.push(bits >> 16 & 255);
|
|
1062
|
+
result.push(bits >> 8 & 255);
|
|
1063
|
+
result.push(bits & 255);
|
|
1064
|
+
} else if (tailbits === 18) {
|
|
1065
|
+
result.push(bits >> 10 & 255);
|
|
1066
|
+
result.push(bits >> 2 & 255);
|
|
1067
|
+
} else if (tailbits === 12) {
|
|
1068
|
+
result.push(bits >> 4 & 255);
|
|
1069
|
+
}
|
|
1070
|
+
if (NodeBuffer) {
|
|
1071
|
+
return NodeBuffer.from ? NodeBuffer.from(result) : new NodeBuffer(result);
|
|
1072
|
+
}
|
|
1073
|
+
return result;
|
|
1074
|
+
}
|
|
1075
|
+
function representYamlBinary(object) {
|
|
1076
|
+
var result = "", bits = 0, idx, tail, max = object.length, map = BASE64_MAP;
|
|
1077
|
+
for (idx = 0;idx < max; idx++) {
|
|
1078
|
+
if (idx % 3 === 0 && idx) {
|
|
1079
|
+
result += map[bits >> 18 & 63];
|
|
1080
|
+
result += map[bits >> 12 & 63];
|
|
1081
|
+
result += map[bits >> 6 & 63];
|
|
1082
|
+
result += map[bits & 63];
|
|
1083
|
+
}
|
|
1084
|
+
bits = (bits << 8) + object[idx];
|
|
1085
|
+
}
|
|
1086
|
+
tail = max % 3;
|
|
1087
|
+
if (tail === 0) {
|
|
1088
|
+
result += map[bits >> 18 & 63];
|
|
1089
|
+
result += map[bits >> 12 & 63];
|
|
1090
|
+
result += map[bits >> 6 & 63];
|
|
1091
|
+
result += map[bits & 63];
|
|
1092
|
+
} else if (tail === 2) {
|
|
1093
|
+
result += map[bits >> 10 & 63];
|
|
1094
|
+
result += map[bits >> 4 & 63];
|
|
1095
|
+
result += map[bits << 2 & 63];
|
|
1096
|
+
result += map[64];
|
|
1097
|
+
} else if (tail === 1) {
|
|
1098
|
+
result += map[bits >> 2 & 63];
|
|
1099
|
+
result += map[bits << 4 & 63];
|
|
1100
|
+
result += map[64];
|
|
1101
|
+
result += map[64];
|
|
1102
|
+
}
|
|
1103
|
+
return result;
|
|
1104
|
+
}
|
|
1105
|
+
function isBinary(object) {
|
|
1106
|
+
return NodeBuffer && NodeBuffer.isBuffer(object);
|
|
1107
|
+
}
|
|
1108
|
+
module.exports = new Type("tag:yaml.org,2002:binary", {
|
|
1109
|
+
kind: "scalar",
|
|
1110
|
+
resolve: resolveYamlBinary,
|
|
1111
|
+
construct: constructYamlBinary,
|
|
1112
|
+
predicate: isBinary,
|
|
1113
|
+
represent: representYamlBinary
|
|
1114
|
+
});
|
|
1115
|
+
});
|
|
1116
|
+
|
|
1117
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/omap.js
|
|
1118
|
+
var require_omap = __commonJS((exports, module) => {
|
|
1119
|
+
var Type = require_type();
|
|
1120
|
+
var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
1121
|
+
var _toString = Object.prototype.toString;
|
|
1122
|
+
function resolveYamlOmap(data) {
|
|
1123
|
+
if (data === null)
|
|
1124
|
+
return true;
|
|
1125
|
+
var objectKeys = [], index, length, pair, pairKey, pairHasKey, object = data;
|
|
1126
|
+
for (index = 0, length = object.length;index < length; index += 1) {
|
|
1127
|
+
pair = object[index];
|
|
1128
|
+
pairHasKey = false;
|
|
1129
|
+
if (_toString.call(pair) !== "[object Object]")
|
|
1130
|
+
return false;
|
|
1131
|
+
for (pairKey in pair) {
|
|
1132
|
+
if (_hasOwnProperty.call(pair, pairKey)) {
|
|
1133
|
+
if (!pairHasKey)
|
|
1134
|
+
pairHasKey = true;
|
|
1135
|
+
else
|
|
1136
|
+
return false;
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
if (!pairHasKey)
|
|
1140
|
+
return false;
|
|
1141
|
+
if (objectKeys.indexOf(pairKey) === -1)
|
|
1142
|
+
objectKeys.push(pairKey);
|
|
1143
|
+
else
|
|
1144
|
+
return false;
|
|
1145
|
+
}
|
|
1146
|
+
return true;
|
|
1147
|
+
}
|
|
1148
|
+
function constructYamlOmap(data) {
|
|
1149
|
+
return data !== null ? data : [];
|
|
1150
|
+
}
|
|
1151
|
+
module.exports = new Type("tag:yaml.org,2002:omap", {
|
|
1152
|
+
kind: "sequence",
|
|
1153
|
+
resolve: resolveYamlOmap,
|
|
1154
|
+
construct: constructYamlOmap
|
|
1155
|
+
});
|
|
1156
|
+
});
|
|
1157
|
+
|
|
1158
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/pairs.js
|
|
1159
|
+
var require_pairs = __commonJS((exports, module) => {
|
|
1160
|
+
var Type = require_type();
|
|
1161
|
+
var _toString = Object.prototype.toString;
|
|
1162
|
+
function resolveYamlPairs(data) {
|
|
1163
|
+
if (data === null)
|
|
1164
|
+
return true;
|
|
1165
|
+
var index, length, pair, keys, result, object = data;
|
|
1166
|
+
result = new Array(object.length);
|
|
1167
|
+
for (index = 0, length = object.length;index < length; index += 1) {
|
|
1168
|
+
pair = object[index];
|
|
1169
|
+
if (_toString.call(pair) !== "[object Object]")
|
|
1170
|
+
return false;
|
|
1171
|
+
keys = Object.keys(pair);
|
|
1172
|
+
if (keys.length !== 1)
|
|
1173
|
+
return false;
|
|
1174
|
+
result[index] = [keys[0], pair[keys[0]]];
|
|
1175
|
+
}
|
|
1176
|
+
return true;
|
|
1177
|
+
}
|
|
1178
|
+
function constructYamlPairs(data) {
|
|
1179
|
+
if (data === null)
|
|
1180
|
+
return [];
|
|
1181
|
+
var index, length, pair, keys, result, object = data;
|
|
1182
|
+
result = new Array(object.length);
|
|
1183
|
+
for (index = 0, length = object.length;index < length; index += 1) {
|
|
1184
|
+
pair = object[index];
|
|
1185
|
+
keys = Object.keys(pair);
|
|
1186
|
+
result[index] = [keys[0], pair[keys[0]]];
|
|
1187
|
+
}
|
|
1188
|
+
return result;
|
|
1189
|
+
}
|
|
1190
|
+
module.exports = new Type("tag:yaml.org,2002:pairs", {
|
|
1191
|
+
kind: "sequence",
|
|
1192
|
+
resolve: resolveYamlPairs,
|
|
1193
|
+
construct: constructYamlPairs
|
|
1194
|
+
});
|
|
1195
|
+
});
|
|
1196
|
+
|
|
1197
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/set.js
|
|
1198
|
+
var require_set = __commonJS((exports, module) => {
|
|
1199
|
+
var Type = require_type();
|
|
1200
|
+
var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
1201
|
+
function resolveYamlSet(data) {
|
|
1202
|
+
if (data === null)
|
|
1203
|
+
return true;
|
|
1204
|
+
var key, object = data;
|
|
1205
|
+
for (key in object) {
|
|
1206
|
+
if (_hasOwnProperty.call(object, key)) {
|
|
1207
|
+
if (object[key] !== null)
|
|
1208
|
+
return false;
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
return true;
|
|
1212
|
+
}
|
|
1213
|
+
function constructYamlSet(data) {
|
|
1214
|
+
return data !== null ? data : {};
|
|
1215
|
+
}
|
|
1216
|
+
module.exports = new Type("tag:yaml.org,2002:set", {
|
|
1217
|
+
kind: "mapping",
|
|
1218
|
+
resolve: resolveYamlSet,
|
|
1219
|
+
construct: constructYamlSet
|
|
1220
|
+
});
|
|
1221
|
+
});
|
|
1222
|
+
|
|
1223
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/schema/default_safe.js
|
|
1224
|
+
var require_default_safe = __commonJS((exports, module) => {
|
|
1225
|
+
var Schema = require_schema();
|
|
1226
|
+
module.exports = new Schema({
|
|
1227
|
+
include: [
|
|
1228
|
+
require_core()
|
|
1229
|
+
],
|
|
1230
|
+
implicit: [
|
|
1231
|
+
require_timestamp(),
|
|
1232
|
+
require_merge()
|
|
1233
|
+
],
|
|
1234
|
+
explicit: [
|
|
1235
|
+
require_binary(),
|
|
1236
|
+
require_omap(),
|
|
1237
|
+
require_pairs(),
|
|
1238
|
+
require_set()
|
|
1239
|
+
]
|
|
1240
|
+
});
|
|
1241
|
+
});
|
|
1242
|
+
|
|
1243
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/js/undefined.js
|
|
1244
|
+
var require_undefined = __commonJS((exports, module) => {
|
|
1245
|
+
var Type = require_type();
|
|
1246
|
+
function resolveJavascriptUndefined() {
|
|
1247
|
+
return true;
|
|
1248
|
+
}
|
|
1249
|
+
function constructJavascriptUndefined() {
|
|
1250
|
+
return;
|
|
1251
|
+
}
|
|
1252
|
+
function representJavascriptUndefined() {
|
|
1253
|
+
return "";
|
|
1254
|
+
}
|
|
1255
|
+
function isUndefined(object) {
|
|
1256
|
+
return typeof object === "undefined";
|
|
1257
|
+
}
|
|
1258
|
+
module.exports = new Type("tag:yaml.org,2002:js/undefined", {
|
|
1259
|
+
kind: "scalar",
|
|
1260
|
+
resolve: resolveJavascriptUndefined,
|
|
1261
|
+
construct: constructJavascriptUndefined,
|
|
1262
|
+
predicate: isUndefined,
|
|
1263
|
+
represent: representJavascriptUndefined
|
|
1264
|
+
});
|
|
1265
|
+
});
|
|
1266
|
+
|
|
1267
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/js/regexp.js
|
|
1268
|
+
var require_regexp = __commonJS((exports, module) => {
|
|
1269
|
+
var Type = require_type();
|
|
1270
|
+
function resolveJavascriptRegExp(data) {
|
|
1271
|
+
if (data === null)
|
|
1272
|
+
return false;
|
|
1273
|
+
if (data.length === 0)
|
|
1274
|
+
return false;
|
|
1275
|
+
var regexp = data, tail = /\/([gim]*)$/.exec(data), modifiers = "";
|
|
1276
|
+
if (regexp[0] === "/") {
|
|
1277
|
+
if (tail)
|
|
1278
|
+
modifiers = tail[1];
|
|
1279
|
+
if (modifiers.length > 3)
|
|
1280
|
+
return false;
|
|
1281
|
+
if (regexp[regexp.length - modifiers.length - 1] !== "/")
|
|
1282
|
+
return false;
|
|
1283
|
+
}
|
|
1284
|
+
return true;
|
|
1285
|
+
}
|
|
1286
|
+
function constructJavascriptRegExp(data) {
|
|
1287
|
+
var regexp = data, tail = /\/([gim]*)$/.exec(data), modifiers = "";
|
|
1288
|
+
if (regexp[0] === "/") {
|
|
1289
|
+
if (tail)
|
|
1290
|
+
modifiers = tail[1];
|
|
1291
|
+
regexp = regexp.slice(1, regexp.length - modifiers.length - 1);
|
|
1292
|
+
}
|
|
1293
|
+
return new RegExp(regexp, modifiers);
|
|
1294
|
+
}
|
|
1295
|
+
function representJavascriptRegExp(object) {
|
|
1296
|
+
var result = "/" + object.source + "/";
|
|
1297
|
+
if (object.global)
|
|
1298
|
+
result += "g";
|
|
1299
|
+
if (object.multiline)
|
|
1300
|
+
result += "m";
|
|
1301
|
+
if (object.ignoreCase)
|
|
1302
|
+
result += "i";
|
|
1303
|
+
return result;
|
|
1304
|
+
}
|
|
1305
|
+
function isRegExp(object) {
|
|
1306
|
+
return Object.prototype.toString.call(object) === "[object RegExp]";
|
|
1307
|
+
}
|
|
1308
|
+
module.exports = new Type("tag:yaml.org,2002:js/regexp", {
|
|
1309
|
+
kind: "scalar",
|
|
1310
|
+
resolve: resolveJavascriptRegExp,
|
|
1311
|
+
construct: constructJavascriptRegExp,
|
|
1312
|
+
predicate: isRegExp,
|
|
1313
|
+
represent: representJavascriptRegExp
|
|
1314
|
+
});
|
|
1315
|
+
});
|
|
1316
|
+
|
|
1317
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/type/js/function.js
|
|
1318
|
+
var require_function = __commonJS((exports, module) => {
|
|
1319
|
+
var esprima;
|
|
1320
|
+
try {
|
|
1321
|
+
_require = __require;
|
|
1322
|
+
esprima = _require("esprima");
|
|
1323
|
+
} catch (_) {
|
|
1324
|
+
if (typeof window !== "undefined")
|
|
1325
|
+
esprima = window.esprima;
|
|
1326
|
+
}
|
|
1327
|
+
var _require;
|
|
1328
|
+
var Type = require_type();
|
|
1329
|
+
function resolveJavascriptFunction(data) {
|
|
1330
|
+
if (data === null)
|
|
1331
|
+
return false;
|
|
1332
|
+
try {
|
|
1333
|
+
var source = "(" + data + ")", ast = esprima.parse(source, { range: true });
|
|
1334
|
+
if (ast.type !== "Program" || ast.body.length !== 1 || ast.body[0].type !== "ExpressionStatement" || ast.body[0].expression.type !== "ArrowFunctionExpression" && ast.body[0].expression.type !== "FunctionExpression") {
|
|
1335
|
+
return false;
|
|
1336
|
+
}
|
|
1337
|
+
return true;
|
|
1338
|
+
} catch (err) {
|
|
1339
|
+
return false;
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
function constructJavascriptFunction(data) {
|
|
1343
|
+
var source = "(" + data + ")", ast = esprima.parse(source, { range: true }), params = [], body;
|
|
1344
|
+
if (ast.type !== "Program" || ast.body.length !== 1 || ast.body[0].type !== "ExpressionStatement" || ast.body[0].expression.type !== "ArrowFunctionExpression" && ast.body[0].expression.type !== "FunctionExpression") {
|
|
1345
|
+
throw new Error("Failed to resolve function");
|
|
1346
|
+
}
|
|
1347
|
+
ast.body[0].expression.params.forEach(function(param) {
|
|
1348
|
+
params.push(param.name);
|
|
1349
|
+
});
|
|
1350
|
+
body = ast.body[0].expression.body.range;
|
|
1351
|
+
if (ast.body[0].expression.body.type === "BlockStatement") {
|
|
1352
|
+
return new Function(params, source.slice(body[0] + 1, body[1] - 1));
|
|
1353
|
+
}
|
|
1354
|
+
return new Function(params, "return " + source.slice(body[0], body[1]));
|
|
1355
|
+
}
|
|
1356
|
+
function representJavascriptFunction(object) {
|
|
1357
|
+
return object.toString();
|
|
1358
|
+
}
|
|
1359
|
+
function isFunction(object) {
|
|
1360
|
+
return Object.prototype.toString.call(object) === "[object Function]";
|
|
1361
|
+
}
|
|
1362
|
+
module.exports = new Type("tag:yaml.org,2002:js/function", {
|
|
1363
|
+
kind: "scalar",
|
|
1364
|
+
resolve: resolveJavascriptFunction,
|
|
1365
|
+
construct: constructJavascriptFunction,
|
|
1366
|
+
predicate: isFunction,
|
|
1367
|
+
represent: representJavascriptFunction
|
|
1368
|
+
});
|
|
1369
|
+
});
|
|
1370
|
+
|
|
1371
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/schema/default_full.js
|
|
1372
|
+
var require_default_full = __commonJS((exports, module) => {
|
|
1373
|
+
var Schema = require_schema();
|
|
1374
|
+
module.exports = Schema.DEFAULT = new Schema({
|
|
1375
|
+
include: [
|
|
1376
|
+
require_default_safe()
|
|
1377
|
+
],
|
|
1378
|
+
explicit: [
|
|
1379
|
+
require_undefined(),
|
|
1380
|
+
require_regexp(),
|
|
1381
|
+
require_function()
|
|
1382
|
+
]
|
|
1383
|
+
});
|
|
1384
|
+
});
|
|
1385
|
+
|
|
1386
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/loader.js
|
|
1387
|
+
var require_loader = __commonJS((exports, module) => {
|
|
1388
|
+
var common = require_common();
|
|
1389
|
+
var YAMLException = require_exception();
|
|
1390
|
+
var Mark = require_mark();
|
|
1391
|
+
var DEFAULT_SAFE_SCHEMA = require_default_safe();
|
|
1392
|
+
var DEFAULT_FULL_SCHEMA = require_default_full();
|
|
1393
|
+
var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
1394
|
+
var CONTEXT_FLOW_IN = 1;
|
|
1395
|
+
var CONTEXT_FLOW_OUT = 2;
|
|
1396
|
+
var CONTEXT_BLOCK_IN = 3;
|
|
1397
|
+
var CONTEXT_BLOCK_OUT = 4;
|
|
1398
|
+
var CHOMPING_CLIP = 1;
|
|
1399
|
+
var CHOMPING_STRIP = 2;
|
|
1400
|
+
var CHOMPING_KEEP = 3;
|
|
1401
|
+
var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
|
|
1402
|
+
var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/;
|
|
1403
|
+
var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
|
|
1404
|
+
var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
|
|
1405
|
+
var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
|
|
1406
|
+
function _class(obj) {
|
|
1407
|
+
return Object.prototype.toString.call(obj);
|
|
1408
|
+
}
|
|
1409
|
+
function is_EOL(c) {
|
|
1410
|
+
return c === 10 || c === 13;
|
|
1411
|
+
}
|
|
1412
|
+
function is_WHITE_SPACE(c) {
|
|
1413
|
+
return c === 9 || c === 32;
|
|
1414
|
+
}
|
|
1415
|
+
function is_WS_OR_EOL(c) {
|
|
1416
|
+
return c === 9 || c === 32 || c === 10 || c === 13;
|
|
1417
|
+
}
|
|
1418
|
+
function is_FLOW_INDICATOR(c) {
|
|
1419
|
+
return c === 44 || c === 91 || c === 93 || c === 123 || c === 125;
|
|
1420
|
+
}
|
|
1421
|
+
function fromHexCode(c) {
|
|
1422
|
+
var lc;
|
|
1423
|
+
if (48 <= c && c <= 57) {
|
|
1424
|
+
return c - 48;
|
|
1425
|
+
}
|
|
1426
|
+
lc = c | 32;
|
|
1427
|
+
if (97 <= lc && lc <= 102) {
|
|
1428
|
+
return lc - 97 + 10;
|
|
1429
|
+
}
|
|
1430
|
+
return -1;
|
|
1431
|
+
}
|
|
1432
|
+
function escapedHexLen(c) {
|
|
1433
|
+
if (c === 120) {
|
|
1434
|
+
return 2;
|
|
1435
|
+
}
|
|
1436
|
+
if (c === 117) {
|
|
1437
|
+
return 4;
|
|
1438
|
+
}
|
|
1439
|
+
if (c === 85) {
|
|
1440
|
+
return 8;
|
|
1441
|
+
}
|
|
1442
|
+
return 0;
|
|
1443
|
+
}
|
|
1444
|
+
function fromDecimalCode(c) {
|
|
1445
|
+
if (48 <= c && c <= 57) {
|
|
1446
|
+
return c - 48;
|
|
1447
|
+
}
|
|
1448
|
+
return -1;
|
|
1449
|
+
}
|
|
1450
|
+
function simpleEscapeSequence(c) {
|
|
1451
|
+
return c === 48 ? "\x00" : c === 97 ? "\x07" : c === 98 ? "\b" : c === 116 ? "\t" : c === 9 ? "\t" : c === 110 ? `
|
|
1452
|
+
` : c === 118 ? "\v" : c === 102 ? "\f" : c === 114 ? "\r" : c === 101 ? "\x1B" : c === 32 ? " " : c === 34 ? '"' : c === 47 ? "/" : c === 92 ? "\\" : c === 78 ? "
" : c === 95 ? " " : c === 76 ? "\u2028" : c === 80 ? "\u2029" : "";
|
|
1453
|
+
}
|
|
1454
|
+
function charFromCodepoint(c) {
|
|
1455
|
+
if (c <= 65535) {
|
|
1456
|
+
return String.fromCharCode(c);
|
|
1457
|
+
}
|
|
1458
|
+
return String.fromCharCode((c - 65536 >> 10) + 55296, (c - 65536 & 1023) + 56320);
|
|
1459
|
+
}
|
|
1460
|
+
function setProperty(object, key, value) {
|
|
1461
|
+
if (key === "__proto__") {
|
|
1462
|
+
Object.defineProperty(object, key, {
|
|
1463
|
+
configurable: true,
|
|
1464
|
+
enumerable: true,
|
|
1465
|
+
writable: true,
|
|
1466
|
+
value
|
|
1467
|
+
});
|
|
1468
|
+
} else {
|
|
1469
|
+
object[key] = value;
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
var simpleEscapeCheck = new Array(256);
|
|
1473
|
+
var simpleEscapeMap = new Array(256);
|
|
1474
|
+
for (i = 0;i < 256; i++) {
|
|
1475
|
+
simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
|
|
1476
|
+
simpleEscapeMap[i] = simpleEscapeSequence(i);
|
|
1477
|
+
}
|
|
1478
|
+
var i;
|
|
1479
|
+
function State(input, options2) {
|
|
1480
|
+
this.input = input;
|
|
1481
|
+
this.filename = options2["filename"] || null;
|
|
1482
|
+
this.schema = options2["schema"] || DEFAULT_FULL_SCHEMA;
|
|
1483
|
+
this.onWarning = options2["onWarning"] || null;
|
|
1484
|
+
this.legacy = options2["legacy"] || false;
|
|
1485
|
+
this.json = options2["json"] || false;
|
|
1486
|
+
this.listener = options2["listener"] || null;
|
|
1487
|
+
this.implicitTypes = this.schema.compiledImplicit;
|
|
1488
|
+
this.typeMap = this.schema.compiledTypeMap;
|
|
1489
|
+
this.length = input.length;
|
|
1490
|
+
this.position = 0;
|
|
1491
|
+
this.line = 0;
|
|
1492
|
+
this.lineStart = 0;
|
|
1493
|
+
this.lineIndent = 0;
|
|
1494
|
+
this.documents = [];
|
|
1495
|
+
}
|
|
1496
|
+
function generateError(state, message) {
|
|
1497
|
+
return new YAMLException(message, new Mark(state.filename, state.input, state.position, state.line, state.position - state.lineStart));
|
|
1498
|
+
}
|
|
1499
|
+
function throwError(state, message) {
|
|
1500
|
+
throw generateError(state, message);
|
|
1501
|
+
}
|
|
1502
|
+
function throwWarning(state, message) {
|
|
1503
|
+
if (state.onWarning) {
|
|
1504
|
+
state.onWarning.call(null, generateError(state, message));
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
var directiveHandlers = {
|
|
1508
|
+
YAML: function handleYamlDirective(state, name, args) {
|
|
1509
|
+
var match, major, minor;
|
|
1510
|
+
if (state.version !== null) {
|
|
1511
|
+
throwError(state, "duplication of %YAML directive");
|
|
1512
|
+
}
|
|
1513
|
+
if (args.length !== 1) {
|
|
1514
|
+
throwError(state, "YAML directive accepts exactly one argument");
|
|
1515
|
+
}
|
|
1516
|
+
match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
|
|
1517
|
+
if (match === null) {
|
|
1518
|
+
throwError(state, "ill-formed argument of the YAML directive");
|
|
1519
|
+
}
|
|
1520
|
+
major = parseInt(match[1], 10);
|
|
1521
|
+
minor = parseInt(match[2], 10);
|
|
1522
|
+
if (major !== 1) {
|
|
1523
|
+
throwError(state, "unacceptable YAML version of the document");
|
|
1524
|
+
}
|
|
1525
|
+
state.version = args[0];
|
|
1526
|
+
state.checkLineBreaks = minor < 2;
|
|
1527
|
+
if (minor !== 1 && minor !== 2) {
|
|
1528
|
+
throwWarning(state, "unsupported YAML version of the document");
|
|
1529
|
+
}
|
|
1530
|
+
},
|
|
1531
|
+
TAG: function handleTagDirective(state, name, args) {
|
|
1532
|
+
var handle, prefix;
|
|
1533
|
+
if (args.length !== 2) {
|
|
1534
|
+
throwError(state, "TAG directive accepts exactly two arguments");
|
|
1535
|
+
}
|
|
1536
|
+
handle = args[0];
|
|
1537
|
+
prefix = args[1];
|
|
1538
|
+
if (!PATTERN_TAG_HANDLE.test(handle)) {
|
|
1539
|
+
throwError(state, "ill-formed tag handle (first argument) of the TAG directive");
|
|
1540
|
+
}
|
|
1541
|
+
if (_hasOwnProperty.call(state.tagMap, handle)) {
|
|
1542
|
+
throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
|
|
1543
|
+
}
|
|
1544
|
+
if (!PATTERN_TAG_URI.test(prefix)) {
|
|
1545
|
+
throwError(state, "ill-formed tag prefix (second argument) of the TAG directive");
|
|
1546
|
+
}
|
|
1547
|
+
state.tagMap[handle] = prefix;
|
|
1548
|
+
}
|
|
1549
|
+
};
|
|
1550
|
+
function captureSegment(state, start, end, checkJson) {
|
|
1551
|
+
var _position, _length, _character, _result;
|
|
1552
|
+
if (start < end) {
|
|
1553
|
+
_result = state.input.slice(start, end);
|
|
1554
|
+
if (checkJson) {
|
|
1555
|
+
for (_position = 0, _length = _result.length;_position < _length; _position += 1) {
|
|
1556
|
+
_character = _result.charCodeAt(_position);
|
|
1557
|
+
if (!(_character === 9 || 32 <= _character && _character <= 1114111)) {
|
|
1558
|
+
throwError(state, "expected valid JSON character");
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
} else if (PATTERN_NON_PRINTABLE.test(_result)) {
|
|
1562
|
+
throwError(state, "the stream contains non-printable characters");
|
|
1563
|
+
}
|
|
1564
|
+
state.result += _result;
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
function mergeMappings(state, destination, source, overridableKeys) {
|
|
1568
|
+
var sourceKeys, key, index, quantity;
|
|
1569
|
+
if (!common.isObject(source)) {
|
|
1570
|
+
throwError(state, "cannot merge mappings; the provided source object is unacceptable");
|
|
1571
|
+
}
|
|
1572
|
+
sourceKeys = Object.keys(source);
|
|
1573
|
+
for (index = 0, quantity = sourceKeys.length;index < quantity; index += 1) {
|
|
1574
|
+
key = sourceKeys[index];
|
|
1575
|
+
if (!_hasOwnProperty.call(destination, key)) {
|
|
1576
|
+
setProperty(destination, key, source[key]);
|
|
1577
|
+
overridableKeys[key] = true;
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startPos) {
|
|
1582
|
+
var index, quantity;
|
|
1583
|
+
if (Array.isArray(keyNode)) {
|
|
1584
|
+
keyNode = Array.prototype.slice.call(keyNode);
|
|
1585
|
+
for (index = 0, quantity = keyNode.length;index < quantity; index += 1) {
|
|
1586
|
+
if (Array.isArray(keyNode[index])) {
|
|
1587
|
+
throwError(state, "nested arrays are not supported inside keys");
|
|
1588
|
+
}
|
|
1589
|
+
if (typeof keyNode === "object" && _class(keyNode[index]) === "[object Object]") {
|
|
1590
|
+
keyNode[index] = "[object Object]";
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
if (typeof keyNode === "object" && _class(keyNode) === "[object Object]") {
|
|
1595
|
+
keyNode = "[object Object]";
|
|
1596
|
+
}
|
|
1597
|
+
keyNode = String(keyNode);
|
|
1598
|
+
if (_result === null) {
|
|
1599
|
+
_result = {};
|
|
1600
|
+
}
|
|
1601
|
+
if (keyTag === "tag:yaml.org,2002:merge") {
|
|
1602
|
+
if (Array.isArray(valueNode)) {
|
|
1603
|
+
for (index = 0, quantity = valueNode.length;index < quantity; index += 1) {
|
|
1604
|
+
mergeMappings(state, _result, valueNode[index], overridableKeys);
|
|
1605
|
+
}
|
|
1606
|
+
} else {
|
|
1607
|
+
mergeMappings(state, _result, valueNode, overridableKeys);
|
|
1608
|
+
}
|
|
1609
|
+
} else {
|
|
1610
|
+
if (!state.json && !_hasOwnProperty.call(overridableKeys, keyNode) && _hasOwnProperty.call(_result, keyNode)) {
|
|
1611
|
+
state.line = startLine || state.line;
|
|
1612
|
+
state.position = startPos || state.position;
|
|
1613
|
+
throwError(state, "duplicated mapping key");
|
|
1614
|
+
}
|
|
1615
|
+
setProperty(_result, keyNode, valueNode);
|
|
1616
|
+
delete overridableKeys[keyNode];
|
|
1617
|
+
}
|
|
1618
|
+
return _result;
|
|
1619
|
+
}
|
|
1620
|
+
function readLineBreak(state) {
|
|
1621
|
+
var ch;
|
|
1622
|
+
ch = state.input.charCodeAt(state.position);
|
|
1623
|
+
if (ch === 10) {
|
|
1624
|
+
state.position++;
|
|
1625
|
+
} else if (ch === 13) {
|
|
1626
|
+
state.position++;
|
|
1627
|
+
if (state.input.charCodeAt(state.position) === 10) {
|
|
1628
|
+
state.position++;
|
|
1629
|
+
}
|
|
1630
|
+
} else {
|
|
1631
|
+
throwError(state, "a line break is expected");
|
|
1632
|
+
}
|
|
1633
|
+
state.line += 1;
|
|
1634
|
+
state.lineStart = state.position;
|
|
1635
|
+
}
|
|
1636
|
+
function skipSeparationSpace(state, allowComments, checkIndent) {
|
|
1637
|
+
var lineBreaks = 0, ch = state.input.charCodeAt(state.position);
|
|
1638
|
+
while (ch !== 0) {
|
|
1639
|
+
while (is_WHITE_SPACE(ch)) {
|
|
1640
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1641
|
+
}
|
|
1642
|
+
if (allowComments && ch === 35) {
|
|
1643
|
+
do {
|
|
1644
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1645
|
+
} while (ch !== 10 && ch !== 13 && ch !== 0);
|
|
1646
|
+
}
|
|
1647
|
+
if (is_EOL(ch)) {
|
|
1648
|
+
readLineBreak(state);
|
|
1649
|
+
ch = state.input.charCodeAt(state.position);
|
|
1650
|
+
lineBreaks++;
|
|
1651
|
+
state.lineIndent = 0;
|
|
1652
|
+
while (ch === 32) {
|
|
1653
|
+
state.lineIndent++;
|
|
1654
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1655
|
+
}
|
|
1656
|
+
} else {
|
|
1657
|
+
break;
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
|
|
1661
|
+
throwWarning(state, "deficient indentation");
|
|
1662
|
+
}
|
|
1663
|
+
return lineBreaks;
|
|
1664
|
+
}
|
|
1665
|
+
function testDocumentSeparator(state) {
|
|
1666
|
+
var _position = state.position, ch;
|
|
1667
|
+
ch = state.input.charCodeAt(_position);
|
|
1668
|
+
if ((ch === 45 || ch === 46) && ch === state.input.charCodeAt(_position + 1) && ch === state.input.charCodeAt(_position + 2)) {
|
|
1669
|
+
_position += 3;
|
|
1670
|
+
ch = state.input.charCodeAt(_position);
|
|
1671
|
+
if (ch === 0 || is_WS_OR_EOL(ch)) {
|
|
1672
|
+
return true;
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
return false;
|
|
1676
|
+
}
|
|
1677
|
+
function writeFoldedLines(state, count) {
|
|
1678
|
+
if (count === 1) {
|
|
1679
|
+
state.result += " ";
|
|
1680
|
+
} else if (count > 1) {
|
|
1681
|
+
state.result += common.repeat(`
|
|
1682
|
+
`, count - 1);
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
function readPlainScalar(state, nodeIndent, withinFlowCollection) {
|
|
1686
|
+
var preceding, following, captureStart, captureEnd, hasPendingContent, _line, _lineStart, _lineIndent, _kind = state.kind, _result = state.result, ch;
|
|
1687
|
+
ch = state.input.charCodeAt(state.position);
|
|
1688
|
+
if (is_WS_OR_EOL(ch) || is_FLOW_INDICATOR(ch) || ch === 35 || ch === 38 || ch === 42 || ch === 33 || ch === 124 || ch === 62 || ch === 39 || ch === 34 || ch === 37 || ch === 64 || ch === 96) {
|
|
1689
|
+
return false;
|
|
1690
|
+
}
|
|
1691
|
+
if (ch === 63 || ch === 45) {
|
|
1692
|
+
following = state.input.charCodeAt(state.position + 1);
|
|
1693
|
+
if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
|
|
1694
|
+
return false;
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
state.kind = "scalar";
|
|
1698
|
+
state.result = "";
|
|
1699
|
+
captureStart = captureEnd = state.position;
|
|
1700
|
+
hasPendingContent = false;
|
|
1701
|
+
while (ch !== 0) {
|
|
1702
|
+
if (ch === 58) {
|
|
1703
|
+
following = state.input.charCodeAt(state.position + 1);
|
|
1704
|
+
if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
|
|
1705
|
+
break;
|
|
1706
|
+
}
|
|
1707
|
+
} else if (ch === 35) {
|
|
1708
|
+
preceding = state.input.charCodeAt(state.position - 1);
|
|
1709
|
+
if (is_WS_OR_EOL(preceding)) {
|
|
1710
|
+
break;
|
|
1711
|
+
}
|
|
1712
|
+
} else if (state.position === state.lineStart && testDocumentSeparator(state) || withinFlowCollection && is_FLOW_INDICATOR(ch)) {
|
|
1713
|
+
break;
|
|
1714
|
+
} else if (is_EOL(ch)) {
|
|
1715
|
+
_line = state.line;
|
|
1716
|
+
_lineStart = state.lineStart;
|
|
1717
|
+
_lineIndent = state.lineIndent;
|
|
1718
|
+
skipSeparationSpace(state, false, -1);
|
|
1719
|
+
if (state.lineIndent >= nodeIndent) {
|
|
1720
|
+
hasPendingContent = true;
|
|
1721
|
+
ch = state.input.charCodeAt(state.position);
|
|
1722
|
+
continue;
|
|
1723
|
+
} else {
|
|
1724
|
+
state.position = captureEnd;
|
|
1725
|
+
state.line = _line;
|
|
1726
|
+
state.lineStart = _lineStart;
|
|
1727
|
+
state.lineIndent = _lineIndent;
|
|
1728
|
+
break;
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
if (hasPendingContent) {
|
|
1732
|
+
captureSegment(state, captureStart, captureEnd, false);
|
|
1733
|
+
writeFoldedLines(state, state.line - _line);
|
|
1734
|
+
captureStart = captureEnd = state.position;
|
|
1735
|
+
hasPendingContent = false;
|
|
1736
|
+
}
|
|
1737
|
+
if (!is_WHITE_SPACE(ch)) {
|
|
1738
|
+
captureEnd = state.position + 1;
|
|
1739
|
+
}
|
|
1740
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1741
|
+
}
|
|
1742
|
+
captureSegment(state, captureStart, captureEnd, false);
|
|
1743
|
+
if (state.result) {
|
|
1744
|
+
return true;
|
|
1745
|
+
}
|
|
1746
|
+
state.kind = _kind;
|
|
1747
|
+
state.result = _result;
|
|
1748
|
+
return false;
|
|
1749
|
+
}
|
|
1750
|
+
function readSingleQuotedScalar(state, nodeIndent) {
|
|
1751
|
+
var ch, captureStart, captureEnd;
|
|
1752
|
+
ch = state.input.charCodeAt(state.position);
|
|
1753
|
+
if (ch !== 39) {
|
|
1754
|
+
return false;
|
|
1755
|
+
}
|
|
1756
|
+
state.kind = "scalar";
|
|
1757
|
+
state.result = "";
|
|
1758
|
+
state.position++;
|
|
1759
|
+
captureStart = captureEnd = state.position;
|
|
1760
|
+
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
|
1761
|
+
if (ch === 39) {
|
|
1762
|
+
captureSegment(state, captureStart, state.position, true);
|
|
1763
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1764
|
+
if (ch === 39) {
|
|
1765
|
+
captureStart = state.position;
|
|
1766
|
+
state.position++;
|
|
1767
|
+
captureEnd = state.position;
|
|
1768
|
+
} else {
|
|
1769
|
+
return true;
|
|
1770
|
+
}
|
|
1771
|
+
} else if (is_EOL(ch)) {
|
|
1772
|
+
captureSegment(state, captureStart, captureEnd, true);
|
|
1773
|
+
writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
|
1774
|
+
captureStart = captureEnd = state.position;
|
|
1775
|
+
} else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
1776
|
+
throwError(state, "unexpected end of the document within a single quoted scalar");
|
|
1777
|
+
} else {
|
|
1778
|
+
state.position++;
|
|
1779
|
+
captureEnd = state.position;
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
throwError(state, "unexpected end of the stream within a single quoted scalar");
|
|
1783
|
+
}
|
|
1784
|
+
function readDoubleQuotedScalar(state, nodeIndent) {
|
|
1785
|
+
var captureStart, captureEnd, hexLength, hexResult, tmp, ch;
|
|
1786
|
+
ch = state.input.charCodeAt(state.position);
|
|
1787
|
+
if (ch !== 34) {
|
|
1788
|
+
return false;
|
|
1789
|
+
}
|
|
1790
|
+
state.kind = "scalar";
|
|
1791
|
+
state.result = "";
|
|
1792
|
+
state.position++;
|
|
1793
|
+
captureStart = captureEnd = state.position;
|
|
1794
|
+
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
|
1795
|
+
if (ch === 34) {
|
|
1796
|
+
captureSegment(state, captureStart, state.position, true);
|
|
1797
|
+
state.position++;
|
|
1798
|
+
return true;
|
|
1799
|
+
} else if (ch === 92) {
|
|
1800
|
+
captureSegment(state, captureStart, state.position, true);
|
|
1801
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1802
|
+
if (is_EOL(ch)) {
|
|
1803
|
+
skipSeparationSpace(state, false, nodeIndent);
|
|
1804
|
+
} else if (ch < 256 && simpleEscapeCheck[ch]) {
|
|
1805
|
+
state.result += simpleEscapeMap[ch];
|
|
1806
|
+
state.position++;
|
|
1807
|
+
} else if ((tmp = escapedHexLen(ch)) > 0) {
|
|
1808
|
+
hexLength = tmp;
|
|
1809
|
+
hexResult = 0;
|
|
1810
|
+
for (;hexLength > 0; hexLength--) {
|
|
1811
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1812
|
+
if ((tmp = fromHexCode(ch)) >= 0) {
|
|
1813
|
+
hexResult = (hexResult << 4) + tmp;
|
|
1814
|
+
} else {
|
|
1815
|
+
throwError(state, "expected hexadecimal character");
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
state.result += charFromCodepoint(hexResult);
|
|
1819
|
+
state.position++;
|
|
1820
|
+
} else {
|
|
1821
|
+
throwError(state, "unknown escape sequence");
|
|
1822
|
+
}
|
|
1823
|
+
captureStart = captureEnd = state.position;
|
|
1824
|
+
} else if (is_EOL(ch)) {
|
|
1825
|
+
captureSegment(state, captureStart, captureEnd, true);
|
|
1826
|
+
writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
|
1827
|
+
captureStart = captureEnd = state.position;
|
|
1828
|
+
} else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
1829
|
+
throwError(state, "unexpected end of the document within a double quoted scalar");
|
|
1830
|
+
} else {
|
|
1831
|
+
state.position++;
|
|
1832
|
+
captureEnd = state.position;
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
throwError(state, "unexpected end of the stream within a double quoted scalar");
|
|
1836
|
+
}
|
|
1837
|
+
function readFlowCollection(state, nodeIndent) {
|
|
1838
|
+
var readNext = true, _line, _tag = state.tag, _result, _anchor = state.anchor, following, terminator, isPair, isExplicitPair, isMapping, overridableKeys = {}, keyNode, keyTag, valueNode, ch;
|
|
1839
|
+
ch = state.input.charCodeAt(state.position);
|
|
1840
|
+
if (ch === 91) {
|
|
1841
|
+
terminator = 93;
|
|
1842
|
+
isMapping = false;
|
|
1843
|
+
_result = [];
|
|
1844
|
+
} else if (ch === 123) {
|
|
1845
|
+
terminator = 125;
|
|
1846
|
+
isMapping = true;
|
|
1847
|
+
_result = {};
|
|
1848
|
+
} else {
|
|
1849
|
+
return false;
|
|
1850
|
+
}
|
|
1851
|
+
if (state.anchor !== null) {
|
|
1852
|
+
state.anchorMap[state.anchor] = _result;
|
|
1853
|
+
}
|
|
1854
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1855
|
+
while (ch !== 0) {
|
|
1856
|
+
skipSeparationSpace(state, true, nodeIndent);
|
|
1857
|
+
ch = state.input.charCodeAt(state.position);
|
|
1858
|
+
if (ch === terminator) {
|
|
1859
|
+
state.position++;
|
|
1860
|
+
state.tag = _tag;
|
|
1861
|
+
state.anchor = _anchor;
|
|
1862
|
+
state.kind = isMapping ? "mapping" : "sequence";
|
|
1863
|
+
state.result = _result;
|
|
1864
|
+
return true;
|
|
1865
|
+
} else if (!readNext) {
|
|
1866
|
+
throwError(state, "missed comma between flow collection entries");
|
|
1867
|
+
}
|
|
1868
|
+
keyTag = keyNode = valueNode = null;
|
|
1869
|
+
isPair = isExplicitPair = false;
|
|
1870
|
+
if (ch === 63) {
|
|
1871
|
+
following = state.input.charCodeAt(state.position + 1);
|
|
1872
|
+
if (is_WS_OR_EOL(following)) {
|
|
1873
|
+
isPair = isExplicitPair = true;
|
|
1874
|
+
state.position++;
|
|
1875
|
+
skipSeparationSpace(state, true, nodeIndent);
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
_line = state.line;
|
|
1879
|
+
composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
|
1880
|
+
keyTag = state.tag;
|
|
1881
|
+
keyNode = state.result;
|
|
1882
|
+
skipSeparationSpace(state, true, nodeIndent);
|
|
1883
|
+
ch = state.input.charCodeAt(state.position);
|
|
1884
|
+
if ((isExplicitPair || state.line === _line) && ch === 58) {
|
|
1885
|
+
isPair = true;
|
|
1886
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1887
|
+
skipSeparationSpace(state, true, nodeIndent);
|
|
1888
|
+
composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
|
1889
|
+
valueNode = state.result;
|
|
1890
|
+
}
|
|
1891
|
+
if (isMapping) {
|
|
1892
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode);
|
|
1893
|
+
} else if (isPair) {
|
|
1894
|
+
_result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode));
|
|
1895
|
+
} else {
|
|
1896
|
+
_result.push(keyNode);
|
|
1897
|
+
}
|
|
1898
|
+
skipSeparationSpace(state, true, nodeIndent);
|
|
1899
|
+
ch = state.input.charCodeAt(state.position);
|
|
1900
|
+
if (ch === 44) {
|
|
1901
|
+
readNext = true;
|
|
1902
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1903
|
+
} else {
|
|
1904
|
+
readNext = false;
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
throwError(state, "unexpected end of the stream within a flow collection");
|
|
1908
|
+
}
|
|
1909
|
+
function readBlockScalar(state, nodeIndent) {
|
|
1910
|
+
var captureStart, folding, chomping = CHOMPING_CLIP, didReadContent = false, detectedIndent = false, textIndent = nodeIndent, emptyLines = 0, atMoreIndented = false, tmp, ch;
|
|
1911
|
+
ch = state.input.charCodeAt(state.position);
|
|
1912
|
+
if (ch === 124) {
|
|
1913
|
+
folding = false;
|
|
1914
|
+
} else if (ch === 62) {
|
|
1915
|
+
folding = true;
|
|
1916
|
+
} else {
|
|
1917
|
+
return false;
|
|
1918
|
+
}
|
|
1919
|
+
state.kind = "scalar";
|
|
1920
|
+
state.result = "";
|
|
1921
|
+
while (ch !== 0) {
|
|
1922
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1923
|
+
if (ch === 43 || ch === 45) {
|
|
1924
|
+
if (CHOMPING_CLIP === chomping) {
|
|
1925
|
+
chomping = ch === 43 ? CHOMPING_KEEP : CHOMPING_STRIP;
|
|
1926
|
+
} else {
|
|
1927
|
+
throwError(state, "repeat of a chomping mode identifier");
|
|
1928
|
+
}
|
|
1929
|
+
} else if ((tmp = fromDecimalCode(ch)) >= 0) {
|
|
1930
|
+
if (tmp === 0) {
|
|
1931
|
+
throwError(state, "bad explicit indentation width of a block scalar; it cannot be less than one");
|
|
1932
|
+
} else if (!detectedIndent) {
|
|
1933
|
+
textIndent = nodeIndent + tmp - 1;
|
|
1934
|
+
detectedIndent = true;
|
|
1935
|
+
} else {
|
|
1936
|
+
throwError(state, "repeat of an indentation width identifier");
|
|
1937
|
+
}
|
|
1938
|
+
} else {
|
|
1939
|
+
break;
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
if (is_WHITE_SPACE(ch)) {
|
|
1943
|
+
do {
|
|
1944
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1945
|
+
} while (is_WHITE_SPACE(ch));
|
|
1946
|
+
if (ch === 35) {
|
|
1947
|
+
do {
|
|
1948
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1949
|
+
} while (!is_EOL(ch) && ch !== 0);
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
while (ch !== 0) {
|
|
1953
|
+
readLineBreak(state);
|
|
1954
|
+
state.lineIndent = 0;
|
|
1955
|
+
ch = state.input.charCodeAt(state.position);
|
|
1956
|
+
while ((!detectedIndent || state.lineIndent < textIndent) && ch === 32) {
|
|
1957
|
+
state.lineIndent++;
|
|
1958
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1959
|
+
}
|
|
1960
|
+
if (!detectedIndent && state.lineIndent > textIndent) {
|
|
1961
|
+
textIndent = state.lineIndent;
|
|
1962
|
+
}
|
|
1963
|
+
if (is_EOL(ch)) {
|
|
1964
|
+
emptyLines++;
|
|
1965
|
+
continue;
|
|
1966
|
+
}
|
|
1967
|
+
if (state.lineIndent < textIndent) {
|
|
1968
|
+
if (chomping === CHOMPING_KEEP) {
|
|
1969
|
+
state.result += common.repeat(`
|
|
1970
|
+
`, didReadContent ? 1 + emptyLines : emptyLines);
|
|
1971
|
+
} else if (chomping === CHOMPING_CLIP) {
|
|
1972
|
+
if (didReadContent) {
|
|
1973
|
+
state.result += `
|
|
1974
|
+
`;
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
break;
|
|
1978
|
+
}
|
|
1979
|
+
if (folding) {
|
|
1980
|
+
if (is_WHITE_SPACE(ch)) {
|
|
1981
|
+
atMoreIndented = true;
|
|
1982
|
+
state.result += common.repeat(`
|
|
1983
|
+
`, didReadContent ? 1 + emptyLines : emptyLines);
|
|
1984
|
+
} else if (atMoreIndented) {
|
|
1985
|
+
atMoreIndented = false;
|
|
1986
|
+
state.result += common.repeat(`
|
|
1987
|
+
`, emptyLines + 1);
|
|
1988
|
+
} else if (emptyLines === 0) {
|
|
1989
|
+
if (didReadContent) {
|
|
1990
|
+
state.result += " ";
|
|
1991
|
+
}
|
|
1992
|
+
} else {
|
|
1993
|
+
state.result += common.repeat(`
|
|
1994
|
+
`, emptyLines);
|
|
1995
|
+
}
|
|
1996
|
+
} else {
|
|
1997
|
+
state.result += common.repeat(`
|
|
1998
|
+
`, didReadContent ? 1 + emptyLines : emptyLines);
|
|
1999
|
+
}
|
|
2000
|
+
didReadContent = true;
|
|
2001
|
+
detectedIndent = true;
|
|
2002
|
+
emptyLines = 0;
|
|
2003
|
+
captureStart = state.position;
|
|
2004
|
+
while (!is_EOL(ch) && ch !== 0) {
|
|
2005
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2006
|
+
}
|
|
2007
|
+
captureSegment(state, captureStart, state.position, false);
|
|
2008
|
+
}
|
|
2009
|
+
return true;
|
|
2010
|
+
}
|
|
2011
|
+
function readBlockSequence(state, nodeIndent) {
|
|
2012
|
+
var _line, _tag = state.tag, _anchor = state.anchor, _result = [], following, detected = false, ch;
|
|
2013
|
+
if (state.anchor !== null) {
|
|
2014
|
+
state.anchorMap[state.anchor] = _result;
|
|
2015
|
+
}
|
|
2016
|
+
ch = state.input.charCodeAt(state.position);
|
|
2017
|
+
while (ch !== 0) {
|
|
2018
|
+
if (ch !== 45) {
|
|
2019
|
+
break;
|
|
2020
|
+
}
|
|
2021
|
+
following = state.input.charCodeAt(state.position + 1);
|
|
2022
|
+
if (!is_WS_OR_EOL(following)) {
|
|
2023
|
+
break;
|
|
2024
|
+
}
|
|
2025
|
+
detected = true;
|
|
2026
|
+
state.position++;
|
|
2027
|
+
if (skipSeparationSpace(state, true, -1)) {
|
|
2028
|
+
if (state.lineIndent <= nodeIndent) {
|
|
2029
|
+
_result.push(null);
|
|
2030
|
+
ch = state.input.charCodeAt(state.position);
|
|
2031
|
+
continue;
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
_line = state.line;
|
|
2035
|
+
composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
|
|
2036
|
+
_result.push(state.result);
|
|
2037
|
+
skipSeparationSpace(state, true, -1);
|
|
2038
|
+
ch = state.input.charCodeAt(state.position);
|
|
2039
|
+
if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
|
|
2040
|
+
throwError(state, "bad indentation of a sequence entry");
|
|
2041
|
+
} else if (state.lineIndent < nodeIndent) {
|
|
2042
|
+
break;
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
if (detected) {
|
|
2046
|
+
state.tag = _tag;
|
|
2047
|
+
state.anchor = _anchor;
|
|
2048
|
+
state.kind = "sequence";
|
|
2049
|
+
state.result = _result;
|
|
2050
|
+
return true;
|
|
2051
|
+
}
|
|
2052
|
+
return false;
|
|
2053
|
+
}
|
|
2054
|
+
function readBlockMapping(state, nodeIndent, flowIndent) {
|
|
2055
|
+
var following, allowCompact, _line, _pos, _tag = state.tag, _anchor = state.anchor, _result = {}, overridableKeys = {}, keyTag = null, keyNode = null, valueNode = null, atExplicitKey = false, detected = false, ch;
|
|
2056
|
+
if (state.anchor !== null) {
|
|
2057
|
+
state.anchorMap[state.anchor] = _result;
|
|
2058
|
+
}
|
|
2059
|
+
ch = state.input.charCodeAt(state.position);
|
|
2060
|
+
while (ch !== 0) {
|
|
2061
|
+
following = state.input.charCodeAt(state.position + 1);
|
|
2062
|
+
_line = state.line;
|
|
2063
|
+
_pos = state.position;
|
|
2064
|
+
if ((ch === 63 || ch === 58) && is_WS_OR_EOL(following)) {
|
|
2065
|
+
if (ch === 63) {
|
|
2066
|
+
if (atExplicitKey) {
|
|
2067
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
|
|
2068
|
+
keyTag = keyNode = valueNode = null;
|
|
2069
|
+
}
|
|
2070
|
+
detected = true;
|
|
2071
|
+
atExplicitKey = true;
|
|
2072
|
+
allowCompact = true;
|
|
2073
|
+
} else if (atExplicitKey) {
|
|
2074
|
+
atExplicitKey = false;
|
|
2075
|
+
allowCompact = true;
|
|
2076
|
+
} else {
|
|
2077
|
+
throwError(state, "incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line");
|
|
2078
|
+
}
|
|
2079
|
+
state.position += 1;
|
|
2080
|
+
ch = following;
|
|
2081
|
+
} else if (composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
|
|
2082
|
+
if (state.line === _line) {
|
|
2083
|
+
ch = state.input.charCodeAt(state.position);
|
|
2084
|
+
while (is_WHITE_SPACE(ch)) {
|
|
2085
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2086
|
+
}
|
|
2087
|
+
if (ch === 58) {
|
|
2088
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2089
|
+
if (!is_WS_OR_EOL(ch)) {
|
|
2090
|
+
throwError(state, "a whitespace character is expected after the key-value separator within a block mapping");
|
|
2091
|
+
}
|
|
2092
|
+
if (atExplicitKey) {
|
|
2093
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
|
|
2094
|
+
keyTag = keyNode = valueNode = null;
|
|
2095
|
+
}
|
|
2096
|
+
detected = true;
|
|
2097
|
+
atExplicitKey = false;
|
|
2098
|
+
allowCompact = false;
|
|
2099
|
+
keyTag = state.tag;
|
|
2100
|
+
keyNode = state.result;
|
|
2101
|
+
} else if (detected) {
|
|
2102
|
+
throwError(state, "can not read an implicit mapping pair; a colon is missed");
|
|
2103
|
+
} else {
|
|
2104
|
+
state.tag = _tag;
|
|
2105
|
+
state.anchor = _anchor;
|
|
2106
|
+
return true;
|
|
2107
|
+
}
|
|
2108
|
+
} else if (detected) {
|
|
2109
|
+
throwError(state, "can not read a block mapping entry; a multiline key may not be an implicit key");
|
|
2110
|
+
} else {
|
|
2111
|
+
state.tag = _tag;
|
|
2112
|
+
state.anchor = _anchor;
|
|
2113
|
+
return true;
|
|
2114
|
+
}
|
|
2115
|
+
} else {
|
|
2116
|
+
break;
|
|
2117
|
+
}
|
|
2118
|
+
if (state.line === _line || state.lineIndent > nodeIndent) {
|
|
2119
|
+
if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
|
|
2120
|
+
if (atExplicitKey) {
|
|
2121
|
+
keyNode = state.result;
|
|
2122
|
+
} else {
|
|
2123
|
+
valueNode = state.result;
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
if (!atExplicitKey) {
|
|
2127
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _pos);
|
|
2128
|
+
keyTag = keyNode = valueNode = null;
|
|
2129
|
+
}
|
|
2130
|
+
skipSeparationSpace(state, true, -1);
|
|
2131
|
+
ch = state.input.charCodeAt(state.position);
|
|
2132
|
+
}
|
|
2133
|
+
if (state.lineIndent > nodeIndent && ch !== 0) {
|
|
2134
|
+
throwError(state, "bad indentation of a mapping entry");
|
|
2135
|
+
} else if (state.lineIndent < nodeIndent) {
|
|
2136
|
+
break;
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
if (atExplicitKey) {
|
|
2140
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
|
|
2141
|
+
}
|
|
2142
|
+
if (detected) {
|
|
2143
|
+
state.tag = _tag;
|
|
2144
|
+
state.anchor = _anchor;
|
|
2145
|
+
state.kind = "mapping";
|
|
2146
|
+
state.result = _result;
|
|
2147
|
+
}
|
|
2148
|
+
return detected;
|
|
2149
|
+
}
|
|
2150
|
+
function readTagProperty(state) {
|
|
2151
|
+
var _position, isVerbatim = false, isNamed = false, tagHandle, tagName, ch;
|
|
2152
|
+
ch = state.input.charCodeAt(state.position);
|
|
2153
|
+
if (ch !== 33)
|
|
2154
|
+
return false;
|
|
2155
|
+
if (state.tag !== null) {
|
|
2156
|
+
throwError(state, "duplication of a tag property");
|
|
2157
|
+
}
|
|
2158
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2159
|
+
if (ch === 60) {
|
|
2160
|
+
isVerbatim = true;
|
|
2161
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2162
|
+
} else if (ch === 33) {
|
|
2163
|
+
isNamed = true;
|
|
2164
|
+
tagHandle = "!!";
|
|
2165
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2166
|
+
} else {
|
|
2167
|
+
tagHandle = "!";
|
|
2168
|
+
}
|
|
2169
|
+
_position = state.position;
|
|
2170
|
+
if (isVerbatim) {
|
|
2171
|
+
do {
|
|
2172
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2173
|
+
} while (ch !== 0 && ch !== 62);
|
|
2174
|
+
if (state.position < state.length) {
|
|
2175
|
+
tagName = state.input.slice(_position, state.position);
|
|
2176
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2177
|
+
} else {
|
|
2178
|
+
throwError(state, "unexpected end of the stream within a verbatim tag");
|
|
2179
|
+
}
|
|
2180
|
+
} else {
|
|
2181
|
+
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
|
2182
|
+
if (ch === 33) {
|
|
2183
|
+
if (!isNamed) {
|
|
2184
|
+
tagHandle = state.input.slice(_position - 1, state.position + 1);
|
|
2185
|
+
if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
|
|
2186
|
+
throwError(state, "named tag handle cannot contain such characters");
|
|
2187
|
+
}
|
|
2188
|
+
isNamed = true;
|
|
2189
|
+
_position = state.position + 1;
|
|
2190
|
+
} else {
|
|
2191
|
+
throwError(state, "tag suffix cannot contain exclamation marks");
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2195
|
+
}
|
|
2196
|
+
tagName = state.input.slice(_position, state.position);
|
|
2197
|
+
if (PATTERN_FLOW_INDICATORS.test(tagName)) {
|
|
2198
|
+
throwError(state, "tag suffix cannot contain flow indicator characters");
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2201
|
+
if (tagName && !PATTERN_TAG_URI.test(tagName)) {
|
|
2202
|
+
throwError(state, "tag name cannot contain such characters: " + tagName);
|
|
2203
|
+
}
|
|
2204
|
+
if (isVerbatim) {
|
|
2205
|
+
state.tag = tagName;
|
|
2206
|
+
} else if (_hasOwnProperty.call(state.tagMap, tagHandle)) {
|
|
2207
|
+
state.tag = state.tagMap[tagHandle] + tagName;
|
|
2208
|
+
} else if (tagHandle === "!") {
|
|
2209
|
+
state.tag = "!" + tagName;
|
|
2210
|
+
} else if (tagHandle === "!!") {
|
|
2211
|
+
state.tag = "tag:yaml.org,2002:" + tagName;
|
|
2212
|
+
} else {
|
|
2213
|
+
throwError(state, 'undeclared tag handle "' + tagHandle + '"');
|
|
2214
|
+
}
|
|
2215
|
+
return true;
|
|
2216
|
+
}
|
|
2217
|
+
function readAnchorProperty(state) {
|
|
2218
|
+
var _position, ch;
|
|
2219
|
+
ch = state.input.charCodeAt(state.position);
|
|
2220
|
+
if (ch !== 38)
|
|
2221
|
+
return false;
|
|
2222
|
+
if (state.anchor !== null) {
|
|
2223
|
+
throwError(state, "duplication of an anchor property");
|
|
2224
|
+
}
|
|
2225
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2226
|
+
_position = state.position;
|
|
2227
|
+
while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
|
|
2228
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2229
|
+
}
|
|
2230
|
+
if (state.position === _position) {
|
|
2231
|
+
throwError(state, "name of an anchor node must contain at least one character");
|
|
2232
|
+
}
|
|
2233
|
+
state.anchor = state.input.slice(_position, state.position);
|
|
2234
|
+
return true;
|
|
2235
|
+
}
|
|
2236
|
+
function readAlias(state) {
|
|
2237
|
+
var _position, alias, ch;
|
|
2238
|
+
ch = state.input.charCodeAt(state.position);
|
|
2239
|
+
if (ch !== 42)
|
|
2240
|
+
return false;
|
|
2241
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2242
|
+
_position = state.position;
|
|
2243
|
+
while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
|
|
2244
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2245
|
+
}
|
|
2246
|
+
if (state.position === _position) {
|
|
2247
|
+
throwError(state, "name of an alias node must contain at least one character");
|
|
2248
|
+
}
|
|
2249
|
+
alias = state.input.slice(_position, state.position);
|
|
2250
|
+
if (!_hasOwnProperty.call(state.anchorMap, alias)) {
|
|
2251
|
+
throwError(state, 'unidentified alias "' + alias + '"');
|
|
2252
|
+
}
|
|
2253
|
+
state.result = state.anchorMap[alias];
|
|
2254
|
+
skipSeparationSpace(state, true, -1);
|
|
2255
|
+
return true;
|
|
2256
|
+
}
|
|
2257
|
+
function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
|
|
2258
|
+
var allowBlockStyles, allowBlockScalars, allowBlockCollections, indentStatus = 1, atNewLine = false, hasContent = false, typeIndex, typeQuantity, type, flowIndent, blockIndent;
|
|
2259
|
+
if (state.listener !== null) {
|
|
2260
|
+
state.listener("open", state);
|
|
2261
|
+
}
|
|
2262
|
+
state.tag = null;
|
|
2263
|
+
state.anchor = null;
|
|
2264
|
+
state.kind = null;
|
|
2265
|
+
state.result = null;
|
|
2266
|
+
allowBlockStyles = allowBlockScalars = allowBlockCollections = CONTEXT_BLOCK_OUT === nodeContext || CONTEXT_BLOCK_IN === nodeContext;
|
|
2267
|
+
if (allowToSeek) {
|
|
2268
|
+
if (skipSeparationSpace(state, true, -1)) {
|
|
2269
|
+
atNewLine = true;
|
|
2270
|
+
if (state.lineIndent > parentIndent) {
|
|
2271
|
+
indentStatus = 1;
|
|
2272
|
+
} else if (state.lineIndent === parentIndent) {
|
|
2273
|
+
indentStatus = 0;
|
|
2274
|
+
} else if (state.lineIndent < parentIndent) {
|
|
2275
|
+
indentStatus = -1;
|
|
2276
|
+
}
|
|
2277
|
+
}
|
|
2278
|
+
}
|
|
2279
|
+
if (indentStatus === 1) {
|
|
2280
|
+
while (readTagProperty(state) || readAnchorProperty(state)) {
|
|
2281
|
+
if (skipSeparationSpace(state, true, -1)) {
|
|
2282
|
+
atNewLine = true;
|
|
2283
|
+
allowBlockCollections = allowBlockStyles;
|
|
2284
|
+
if (state.lineIndent > parentIndent) {
|
|
2285
|
+
indentStatus = 1;
|
|
2286
|
+
} else if (state.lineIndent === parentIndent) {
|
|
2287
|
+
indentStatus = 0;
|
|
2288
|
+
} else if (state.lineIndent < parentIndent) {
|
|
2289
|
+
indentStatus = -1;
|
|
2290
|
+
}
|
|
2291
|
+
} else {
|
|
2292
|
+
allowBlockCollections = false;
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2296
|
+
if (allowBlockCollections) {
|
|
2297
|
+
allowBlockCollections = atNewLine || allowCompact;
|
|
2298
|
+
}
|
|
2299
|
+
if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
|
|
2300
|
+
if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) {
|
|
2301
|
+
flowIndent = parentIndent;
|
|
2302
|
+
} else {
|
|
2303
|
+
flowIndent = parentIndent + 1;
|
|
2304
|
+
}
|
|
2305
|
+
blockIndent = state.position - state.lineStart;
|
|
2306
|
+
if (indentStatus === 1) {
|
|
2307
|
+
if (allowBlockCollections && (readBlockSequence(state, blockIndent) || readBlockMapping(state, blockIndent, flowIndent)) || readFlowCollection(state, flowIndent)) {
|
|
2308
|
+
hasContent = true;
|
|
2309
|
+
} else {
|
|
2310
|
+
if (allowBlockScalars && readBlockScalar(state, flowIndent) || readSingleQuotedScalar(state, flowIndent) || readDoubleQuotedScalar(state, flowIndent)) {
|
|
2311
|
+
hasContent = true;
|
|
2312
|
+
} else if (readAlias(state)) {
|
|
2313
|
+
hasContent = true;
|
|
2314
|
+
if (state.tag !== null || state.anchor !== null) {
|
|
2315
|
+
throwError(state, "alias node should not have any properties");
|
|
2316
|
+
}
|
|
2317
|
+
} else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
|
|
2318
|
+
hasContent = true;
|
|
2319
|
+
if (state.tag === null) {
|
|
2320
|
+
state.tag = "?";
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
if (state.anchor !== null) {
|
|
2324
|
+
state.anchorMap[state.anchor] = state.result;
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
} else if (indentStatus === 0) {
|
|
2328
|
+
hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
if (state.tag !== null && state.tag !== "!") {
|
|
2332
|
+
if (state.tag === "?") {
|
|
2333
|
+
if (state.result !== null && state.kind !== "scalar") {
|
|
2334
|
+
throwError(state, 'unacceptable node kind for !<?> tag; it should be "scalar", not "' + state.kind + '"');
|
|
2335
|
+
}
|
|
2336
|
+
for (typeIndex = 0, typeQuantity = state.implicitTypes.length;typeIndex < typeQuantity; typeIndex += 1) {
|
|
2337
|
+
type = state.implicitTypes[typeIndex];
|
|
2338
|
+
if (type.resolve(state.result)) {
|
|
2339
|
+
state.result = type.construct(state.result);
|
|
2340
|
+
state.tag = type.tag;
|
|
2341
|
+
if (state.anchor !== null) {
|
|
2342
|
+
state.anchorMap[state.anchor] = state.result;
|
|
2343
|
+
}
|
|
2344
|
+
break;
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
} else if (_hasOwnProperty.call(state.typeMap[state.kind || "fallback"], state.tag)) {
|
|
2348
|
+
type = state.typeMap[state.kind || "fallback"][state.tag];
|
|
2349
|
+
if (state.result !== null && type.kind !== state.kind) {
|
|
2350
|
+
throwError(state, "unacceptable node kind for !<" + state.tag + '> tag; it should be "' + type.kind + '", not "' + state.kind + '"');
|
|
2351
|
+
}
|
|
2352
|
+
if (!type.resolve(state.result)) {
|
|
2353
|
+
throwError(state, "cannot resolve a node with !<" + state.tag + "> explicit tag");
|
|
2354
|
+
} else {
|
|
2355
|
+
state.result = type.construct(state.result);
|
|
2356
|
+
if (state.anchor !== null) {
|
|
2357
|
+
state.anchorMap[state.anchor] = state.result;
|
|
2358
|
+
}
|
|
2359
|
+
}
|
|
2360
|
+
} else {
|
|
2361
|
+
throwError(state, "unknown tag !<" + state.tag + ">");
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2364
|
+
if (state.listener !== null) {
|
|
2365
|
+
state.listener("close", state);
|
|
2366
|
+
}
|
|
2367
|
+
return state.tag !== null || state.anchor !== null || hasContent;
|
|
2368
|
+
}
|
|
2369
|
+
function readDocument(state) {
|
|
2370
|
+
var documentStart = state.position, _position, directiveName, directiveArgs, hasDirectives = false, ch;
|
|
2371
|
+
state.version = null;
|
|
2372
|
+
state.checkLineBreaks = state.legacy;
|
|
2373
|
+
state.tagMap = {};
|
|
2374
|
+
state.anchorMap = {};
|
|
2375
|
+
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
|
2376
|
+
skipSeparationSpace(state, true, -1);
|
|
2377
|
+
ch = state.input.charCodeAt(state.position);
|
|
2378
|
+
if (state.lineIndent > 0 || ch !== 37) {
|
|
2379
|
+
break;
|
|
2380
|
+
}
|
|
2381
|
+
hasDirectives = true;
|
|
2382
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2383
|
+
_position = state.position;
|
|
2384
|
+
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
|
2385
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2386
|
+
}
|
|
2387
|
+
directiveName = state.input.slice(_position, state.position);
|
|
2388
|
+
directiveArgs = [];
|
|
2389
|
+
if (directiveName.length < 1) {
|
|
2390
|
+
throwError(state, "directive name must not be less than one character in length");
|
|
2391
|
+
}
|
|
2392
|
+
while (ch !== 0) {
|
|
2393
|
+
while (is_WHITE_SPACE(ch)) {
|
|
2394
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2395
|
+
}
|
|
2396
|
+
if (ch === 35) {
|
|
2397
|
+
do {
|
|
2398
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2399
|
+
} while (ch !== 0 && !is_EOL(ch));
|
|
2400
|
+
break;
|
|
2401
|
+
}
|
|
2402
|
+
if (is_EOL(ch))
|
|
2403
|
+
break;
|
|
2404
|
+
_position = state.position;
|
|
2405
|
+
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
|
2406
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2407
|
+
}
|
|
2408
|
+
directiveArgs.push(state.input.slice(_position, state.position));
|
|
2409
|
+
}
|
|
2410
|
+
if (ch !== 0)
|
|
2411
|
+
readLineBreak(state);
|
|
2412
|
+
if (_hasOwnProperty.call(directiveHandlers, directiveName)) {
|
|
2413
|
+
directiveHandlers[directiveName](state, directiveName, directiveArgs);
|
|
2414
|
+
} else {
|
|
2415
|
+
throwWarning(state, 'unknown document directive "' + directiveName + '"');
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
skipSeparationSpace(state, true, -1);
|
|
2419
|
+
if (state.lineIndent === 0 && state.input.charCodeAt(state.position) === 45 && state.input.charCodeAt(state.position + 1) === 45 && state.input.charCodeAt(state.position + 2) === 45) {
|
|
2420
|
+
state.position += 3;
|
|
2421
|
+
skipSeparationSpace(state, true, -1);
|
|
2422
|
+
} else if (hasDirectives) {
|
|
2423
|
+
throwError(state, "directives end mark is expected");
|
|
2424
|
+
}
|
|
2425
|
+
composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
|
|
2426
|
+
skipSeparationSpace(state, true, -1);
|
|
2427
|
+
if (state.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
|
|
2428
|
+
throwWarning(state, "non-ASCII line breaks are interpreted as content");
|
|
2429
|
+
}
|
|
2430
|
+
state.documents.push(state.result);
|
|
2431
|
+
if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
2432
|
+
if (state.input.charCodeAt(state.position) === 46) {
|
|
2433
|
+
state.position += 3;
|
|
2434
|
+
skipSeparationSpace(state, true, -1);
|
|
2435
|
+
}
|
|
2436
|
+
return;
|
|
2437
|
+
}
|
|
2438
|
+
if (state.position < state.length - 1) {
|
|
2439
|
+
throwError(state, "end of the stream or a document separator is expected");
|
|
2440
|
+
} else {
|
|
2441
|
+
return;
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
function loadDocuments(input, options2) {
|
|
2445
|
+
input = String(input);
|
|
2446
|
+
options2 = options2 || {};
|
|
2447
|
+
if (input.length !== 0) {
|
|
2448
|
+
if (input.charCodeAt(input.length - 1) !== 10 && input.charCodeAt(input.length - 1) !== 13) {
|
|
2449
|
+
input += `
|
|
2450
|
+
`;
|
|
2451
|
+
}
|
|
2452
|
+
if (input.charCodeAt(0) === 65279) {
|
|
2453
|
+
input = input.slice(1);
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
var state = new State(input, options2);
|
|
2457
|
+
var nullpos = input.indexOf("\x00");
|
|
2458
|
+
if (nullpos !== -1) {
|
|
2459
|
+
state.position = nullpos;
|
|
2460
|
+
throwError(state, "null byte is not allowed in input");
|
|
2461
|
+
}
|
|
2462
|
+
state.input += "\x00";
|
|
2463
|
+
while (state.input.charCodeAt(state.position) === 32) {
|
|
2464
|
+
state.lineIndent += 1;
|
|
2465
|
+
state.position += 1;
|
|
2466
|
+
}
|
|
2467
|
+
while (state.position < state.length - 1) {
|
|
2468
|
+
readDocument(state);
|
|
2469
|
+
}
|
|
2470
|
+
return state.documents;
|
|
2471
|
+
}
|
|
2472
|
+
function loadAll(input, iterator, options2) {
|
|
2473
|
+
if (iterator !== null && typeof iterator === "object" && typeof options2 === "undefined") {
|
|
2474
|
+
options2 = iterator;
|
|
2475
|
+
iterator = null;
|
|
2476
|
+
}
|
|
2477
|
+
var documents = loadDocuments(input, options2);
|
|
2478
|
+
if (typeof iterator !== "function") {
|
|
2479
|
+
return documents;
|
|
2480
|
+
}
|
|
2481
|
+
for (var index = 0, length = documents.length;index < length; index += 1) {
|
|
2482
|
+
iterator(documents[index]);
|
|
2483
|
+
}
|
|
2484
|
+
}
|
|
2485
|
+
function load(input, options2) {
|
|
2486
|
+
var documents = loadDocuments(input, options2);
|
|
2487
|
+
if (documents.length === 0) {
|
|
2488
|
+
return;
|
|
2489
|
+
} else if (documents.length === 1) {
|
|
2490
|
+
return documents[0];
|
|
2491
|
+
}
|
|
2492
|
+
throw new YAMLException("expected a single document in the stream, but found more");
|
|
2493
|
+
}
|
|
2494
|
+
function safeLoadAll(input, iterator, options2) {
|
|
2495
|
+
if (typeof iterator === "object" && iterator !== null && typeof options2 === "undefined") {
|
|
2496
|
+
options2 = iterator;
|
|
2497
|
+
iterator = null;
|
|
2498
|
+
}
|
|
2499
|
+
return loadAll(input, iterator, common.extend({ schema: DEFAULT_SAFE_SCHEMA }, options2));
|
|
2500
|
+
}
|
|
2501
|
+
function safeLoad(input, options2) {
|
|
2502
|
+
return load(input, common.extend({ schema: DEFAULT_SAFE_SCHEMA }, options2));
|
|
2503
|
+
}
|
|
2504
|
+
exports.loadAll = loadAll;
|
|
2505
|
+
exports.load = load;
|
|
2506
|
+
exports.safeLoadAll = safeLoadAll;
|
|
2507
|
+
exports.safeLoad = safeLoad;
|
|
2508
|
+
});
|
|
2509
|
+
|
|
2510
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/dumper.js
|
|
2511
|
+
var require_dumper = __commonJS((exports, module) => {
|
|
2512
|
+
var common = require_common();
|
|
2513
|
+
var YAMLException = require_exception();
|
|
2514
|
+
var DEFAULT_FULL_SCHEMA = require_default_full();
|
|
2515
|
+
var DEFAULT_SAFE_SCHEMA = require_default_safe();
|
|
2516
|
+
var _toString = Object.prototype.toString;
|
|
2517
|
+
var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
2518
|
+
var CHAR_TAB = 9;
|
|
2519
|
+
var CHAR_LINE_FEED = 10;
|
|
2520
|
+
var CHAR_CARRIAGE_RETURN = 13;
|
|
2521
|
+
var CHAR_SPACE = 32;
|
|
2522
|
+
var CHAR_EXCLAMATION = 33;
|
|
2523
|
+
var CHAR_DOUBLE_QUOTE = 34;
|
|
2524
|
+
var CHAR_SHARP = 35;
|
|
2525
|
+
var CHAR_PERCENT = 37;
|
|
2526
|
+
var CHAR_AMPERSAND = 38;
|
|
2527
|
+
var CHAR_SINGLE_QUOTE = 39;
|
|
2528
|
+
var CHAR_ASTERISK = 42;
|
|
2529
|
+
var CHAR_COMMA = 44;
|
|
2530
|
+
var CHAR_MINUS = 45;
|
|
2531
|
+
var CHAR_COLON = 58;
|
|
2532
|
+
var CHAR_EQUALS = 61;
|
|
2533
|
+
var CHAR_GREATER_THAN = 62;
|
|
2534
|
+
var CHAR_QUESTION = 63;
|
|
2535
|
+
var CHAR_COMMERCIAL_AT = 64;
|
|
2536
|
+
var CHAR_LEFT_SQUARE_BRACKET = 91;
|
|
2537
|
+
var CHAR_RIGHT_SQUARE_BRACKET = 93;
|
|
2538
|
+
var CHAR_GRAVE_ACCENT = 96;
|
|
2539
|
+
var CHAR_LEFT_CURLY_BRACKET = 123;
|
|
2540
|
+
var CHAR_VERTICAL_LINE = 124;
|
|
2541
|
+
var CHAR_RIGHT_CURLY_BRACKET = 125;
|
|
2542
|
+
var ESCAPE_SEQUENCES = {};
|
|
2543
|
+
ESCAPE_SEQUENCES[0] = "\\0";
|
|
2544
|
+
ESCAPE_SEQUENCES[7] = "\\a";
|
|
2545
|
+
ESCAPE_SEQUENCES[8] = "\\b";
|
|
2546
|
+
ESCAPE_SEQUENCES[9] = "\\t";
|
|
2547
|
+
ESCAPE_SEQUENCES[10] = "\\n";
|
|
2548
|
+
ESCAPE_SEQUENCES[11] = "\\v";
|
|
2549
|
+
ESCAPE_SEQUENCES[12] = "\\f";
|
|
2550
|
+
ESCAPE_SEQUENCES[13] = "\\r";
|
|
2551
|
+
ESCAPE_SEQUENCES[27] = "\\e";
|
|
2552
|
+
ESCAPE_SEQUENCES[34] = "\\\"";
|
|
2553
|
+
ESCAPE_SEQUENCES[92] = "\\\\";
|
|
2554
|
+
ESCAPE_SEQUENCES[133] = "\\N";
|
|
2555
|
+
ESCAPE_SEQUENCES[160] = "\\_";
|
|
2556
|
+
ESCAPE_SEQUENCES[8232] = "\\L";
|
|
2557
|
+
ESCAPE_SEQUENCES[8233] = "\\P";
|
|
2558
|
+
var DEPRECATED_BOOLEANS_SYNTAX = [
|
|
2559
|
+
"y",
|
|
2560
|
+
"Y",
|
|
2561
|
+
"yes",
|
|
2562
|
+
"Yes",
|
|
2563
|
+
"YES",
|
|
2564
|
+
"on",
|
|
2565
|
+
"On",
|
|
2566
|
+
"ON",
|
|
2567
|
+
"n",
|
|
2568
|
+
"N",
|
|
2569
|
+
"no",
|
|
2570
|
+
"No",
|
|
2571
|
+
"NO",
|
|
2572
|
+
"off",
|
|
2573
|
+
"Off",
|
|
2574
|
+
"OFF"
|
|
2575
|
+
];
|
|
2576
|
+
function compileStyleMap(schema, map) {
|
|
2577
|
+
var result, keys, index, length, tag, style, type;
|
|
2578
|
+
if (map === null)
|
|
2579
|
+
return {};
|
|
2580
|
+
result = {};
|
|
2581
|
+
keys = Object.keys(map);
|
|
2582
|
+
for (index = 0, length = keys.length;index < length; index += 1) {
|
|
2583
|
+
tag = keys[index];
|
|
2584
|
+
style = String(map[tag]);
|
|
2585
|
+
if (tag.slice(0, 2) === "!!") {
|
|
2586
|
+
tag = "tag:yaml.org,2002:" + tag.slice(2);
|
|
2587
|
+
}
|
|
2588
|
+
type = schema.compiledTypeMap["fallback"][tag];
|
|
2589
|
+
if (type && _hasOwnProperty.call(type.styleAliases, style)) {
|
|
2590
|
+
style = type.styleAliases[style];
|
|
2591
|
+
}
|
|
2592
|
+
result[tag] = style;
|
|
2593
|
+
}
|
|
2594
|
+
return result;
|
|
2595
|
+
}
|
|
2596
|
+
function encodeHex(character) {
|
|
2597
|
+
var string, handle, length;
|
|
2598
|
+
string = character.toString(16).toUpperCase();
|
|
2599
|
+
if (character <= 255) {
|
|
2600
|
+
handle = "x";
|
|
2601
|
+
length = 2;
|
|
2602
|
+
} else if (character <= 65535) {
|
|
2603
|
+
handle = "u";
|
|
2604
|
+
length = 4;
|
|
2605
|
+
} else if (character <= 4294967295) {
|
|
2606
|
+
handle = "U";
|
|
2607
|
+
length = 8;
|
|
2608
|
+
} else {
|
|
2609
|
+
throw new YAMLException("code point within a string may not be greater than 0xFFFFFFFF");
|
|
2610
|
+
}
|
|
2611
|
+
return "\\" + handle + common.repeat("0", length - string.length) + string;
|
|
2612
|
+
}
|
|
2613
|
+
function State(options2) {
|
|
2614
|
+
this.schema = options2["schema"] || DEFAULT_FULL_SCHEMA;
|
|
2615
|
+
this.indent = Math.max(1, options2["indent"] || 2);
|
|
2616
|
+
this.noArrayIndent = options2["noArrayIndent"] || false;
|
|
2617
|
+
this.skipInvalid = options2["skipInvalid"] || false;
|
|
2618
|
+
this.flowLevel = common.isNothing(options2["flowLevel"]) ? -1 : options2["flowLevel"];
|
|
2619
|
+
this.styleMap = compileStyleMap(this.schema, options2["styles"] || null);
|
|
2620
|
+
this.sortKeys = options2["sortKeys"] || false;
|
|
2621
|
+
this.lineWidth = options2["lineWidth"] || 80;
|
|
2622
|
+
this.noRefs = options2["noRefs"] || false;
|
|
2623
|
+
this.noCompatMode = options2["noCompatMode"] || false;
|
|
2624
|
+
this.condenseFlow = options2["condenseFlow"] || false;
|
|
2625
|
+
this.implicitTypes = this.schema.compiledImplicit;
|
|
2626
|
+
this.explicitTypes = this.schema.compiledExplicit;
|
|
2627
|
+
this.tag = null;
|
|
2628
|
+
this.result = "";
|
|
2629
|
+
this.duplicates = [];
|
|
2630
|
+
this.usedDuplicates = null;
|
|
2631
|
+
}
|
|
2632
|
+
function indentString(string, spaces) {
|
|
2633
|
+
var ind = common.repeat(" ", spaces), position = 0, next = -1, result = "", line, length = string.length;
|
|
2634
|
+
while (position < length) {
|
|
2635
|
+
next = string.indexOf(`
|
|
2636
|
+
`, position);
|
|
2637
|
+
if (next === -1) {
|
|
2638
|
+
line = string.slice(position);
|
|
2639
|
+
position = length;
|
|
2640
|
+
} else {
|
|
2641
|
+
line = string.slice(position, next + 1);
|
|
2642
|
+
position = next + 1;
|
|
2643
|
+
}
|
|
2644
|
+
if (line.length && line !== `
|
|
2645
|
+
`)
|
|
2646
|
+
result += ind;
|
|
2647
|
+
result += line;
|
|
2648
|
+
}
|
|
2649
|
+
return result;
|
|
2650
|
+
}
|
|
2651
|
+
function generateNextLine(state, level) {
|
|
2652
|
+
return `
|
|
2653
|
+
` + common.repeat(" ", state.indent * level);
|
|
2654
|
+
}
|
|
2655
|
+
function testImplicitResolving(state, str2) {
|
|
2656
|
+
var index, length, type;
|
|
2657
|
+
for (index = 0, length = state.implicitTypes.length;index < length; index += 1) {
|
|
2658
|
+
type = state.implicitTypes[index];
|
|
2659
|
+
if (type.resolve(str2)) {
|
|
2660
|
+
return true;
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
return false;
|
|
2664
|
+
}
|
|
2665
|
+
function isWhitespace(c) {
|
|
2666
|
+
return c === CHAR_SPACE || c === CHAR_TAB;
|
|
2667
|
+
}
|
|
2668
|
+
function isPrintable(c) {
|
|
2669
|
+
return 32 <= c && c <= 126 || 161 <= c && c <= 55295 && c !== 8232 && c !== 8233 || 57344 <= c && c <= 65533 && c !== 65279 || 65536 <= c && c <= 1114111;
|
|
2670
|
+
}
|
|
2671
|
+
function isNsChar(c) {
|
|
2672
|
+
return isPrintable(c) && !isWhitespace(c) && c !== 65279 && c !== CHAR_CARRIAGE_RETURN && c !== CHAR_LINE_FEED;
|
|
2673
|
+
}
|
|
2674
|
+
function isPlainSafe(c, prev) {
|
|
2675
|
+
return isPrintable(c) && c !== 65279 && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET && c !== CHAR_COLON && (c !== CHAR_SHARP || prev && isNsChar(prev));
|
|
2676
|
+
}
|
|
2677
|
+
function isPlainSafeFirst(c) {
|
|
2678
|
+
return isPrintable(c) && c !== 65279 && !isWhitespace(c) && c !== CHAR_MINUS && c !== CHAR_QUESTION && c !== CHAR_COLON && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET && c !== CHAR_SHARP && c !== CHAR_AMPERSAND && c !== CHAR_ASTERISK && c !== CHAR_EXCLAMATION && c !== CHAR_VERTICAL_LINE && c !== CHAR_EQUALS && c !== CHAR_GREATER_THAN && c !== CHAR_SINGLE_QUOTE && c !== CHAR_DOUBLE_QUOTE && c !== CHAR_PERCENT && c !== CHAR_COMMERCIAL_AT && c !== CHAR_GRAVE_ACCENT;
|
|
2679
|
+
}
|
|
2680
|
+
function needIndentIndicator(string) {
|
|
2681
|
+
var leadingSpaceRe = /^\n* /;
|
|
2682
|
+
return leadingSpaceRe.test(string);
|
|
2683
|
+
}
|
|
2684
|
+
var STYLE_PLAIN = 1;
|
|
2685
|
+
var STYLE_SINGLE = 2;
|
|
2686
|
+
var STYLE_LITERAL = 3;
|
|
2687
|
+
var STYLE_FOLDED = 4;
|
|
2688
|
+
var STYLE_DOUBLE = 5;
|
|
2689
|
+
function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType) {
|
|
2690
|
+
var i;
|
|
2691
|
+
var char, prev_char;
|
|
2692
|
+
var hasLineBreak = false;
|
|
2693
|
+
var hasFoldableLine = false;
|
|
2694
|
+
var shouldTrackWidth = lineWidth !== -1;
|
|
2695
|
+
var previousLineBreak = -1;
|
|
2696
|
+
var plain = isPlainSafeFirst(string.charCodeAt(0)) && !isWhitespace(string.charCodeAt(string.length - 1));
|
|
2697
|
+
if (singleLineOnly) {
|
|
2698
|
+
for (i = 0;i < string.length; i++) {
|
|
2699
|
+
char = string.charCodeAt(i);
|
|
2700
|
+
if (!isPrintable(char)) {
|
|
2701
|
+
return STYLE_DOUBLE;
|
|
2702
|
+
}
|
|
2703
|
+
prev_char = i > 0 ? string.charCodeAt(i - 1) : null;
|
|
2704
|
+
plain = plain && isPlainSafe(char, prev_char);
|
|
2705
|
+
}
|
|
2706
|
+
} else {
|
|
2707
|
+
for (i = 0;i < string.length; i++) {
|
|
2708
|
+
char = string.charCodeAt(i);
|
|
2709
|
+
if (char === CHAR_LINE_FEED) {
|
|
2710
|
+
hasLineBreak = true;
|
|
2711
|
+
if (shouldTrackWidth) {
|
|
2712
|
+
hasFoldableLine = hasFoldableLine || i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ";
|
|
2713
|
+
previousLineBreak = i;
|
|
2714
|
+
}
|
|
2715
|
+
} else if (!isPrintable(char)) {
|
|
2716
|
+
return STYLE_DOUBLE;
|
|
2717
|
+
}
|
|
2718
|
+
prev_char = i > 0 ? string.charCodeAt(i - 1) : null;
|
|
2719
|
+
plain = plain && isPlainSafe(char, prev_char);
|
|
2720
|
+
}
|
|
2721
|
+
hasFoldableLine = hasFoldableLine || shouldTrackWidth && (i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ");
|
|
2722
|
+
}
|
|
2723
|
+
if (!hasLineBreak && !hasFoldableLine) {
|
|
2724
|
+
return plain && !testAmbiguousType(string) ? STYLE_PLAIN : STYLE_SINGLE;
|
|
2725
|
+
}
|
|
2726
|
+
if (indentPerLevel > 9 && needIndentIndicator(string)) {
|
|
2727
|
+
return STYLE_DOUBLE;
|
|
2728
|
+
}
|
|
2729
|
+
return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
|
|
2730
|
+
}
|
|
2731
|
+
function writeScalar(state, string, level, iskey) {
|
|
2732
|
+
state.dump = function() {
|
|
2733
|
+
if (string.length === 0) {
|
|
2734
|
+
return "''";
|
|
2735
|
+
}
|
|
2736
|
+
if (!state.noCompatMode && DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1) {
|
|
2737
|
+
return "'" + string + "'";
|
|
2738
|
+
}
|
|
2739
|
+
var indent = state.indent * Math.max(1, level);
|
|
2740
|
+
var lineWidth = state.lineWidth === -1 ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent);
|
|
2741
|
+
var singleLineOnly = iskey || state.flowLevel > -1 && level >= state.flowLevel;
|
|
2742
|
+
function testAmbiguity(string2) {
|
|
2743
|
+
return testImplicitResolving(state, string2);
|
|
2744
|
+
}
|
|
2745
|
+
switch (chooseScalarStyle(string, singleLineOnly, state.indent, lineWidth, testAmbiguity)) {
|
|
2746
|
+
case STYLE_PLAIN:
|
|
2747
|
+
return string;
|
|
2748
|
+
case STYLE_SINGLE:
|
|
2749
|
+
return "'" + string.replace(/'/g, "''") + "'";
|
|
2750
|
+
case STYLE_LITERAL:
|
|
2751
|
+
return "|" + blockHeader(string, state.indent) + dropEndingNewline(indentString(string, indent));
|
|
2752
|
+
case STYLE_FOLDED:
|
|
2753
|
+
return ">" + blockHeader(string, state.indent) + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
|
|
2754
|
+
case STYLE_DOUBLE:
|
|
2755
|
+
return '"' + escapeString(string, lineWidth) + '"';
|
|
2756
|
+
default:
|
|
2757
|
+
throw new YAMLException("impossible error: invalid scalar style");
|
|
2758
|
+
}
|
|
2759
|
+
}();
|
|
2760
|
+
}
|
|
2761
|
+
function blockHeader(string, indentPerLevel) {
|
|
2762
|
+
var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : "";
|
|
2763
|
+
var clip = string[string.length - 1] === `
|
|
2764
|
+
`;
|
|
2765
|
+
var keep = clip && (string[string.length - 2] === `
|
|
2766
|
+
` || string === `
|
|
2767
|
+
`);
|
|
2768
|
+
var chomp = keep ? "+" : clip ? "" : "-";
|
|
2769
|
+
return indentIndicator + chomp + `
|
|
2770
|
+
`;
|
|
2771
|
+
}
|
|
2772
|
+
function dropEndingNewline(string) {
|
|
2773
|
+
return string[string.length - 1] === `
|
|
2774
|
+
` ? string.slice(0, -1) : string;
|
|
2775
|
+
}
|
|
2776
|
+
function foldString(string, width) {
|
|
2777
|
+
var lineRe = /(\n+)([^\n]*)/g;
|
|
2778
|
+
var result = function() {
|
|
2779
|
+
var nextLF = string.indexOf(`
|
|
2780
|
+
`);
|
|
2781
|
+
nextLF = nextLF !== -1 ? nextLF : string.length;
|
|
2782
|
+
lineRe.lastIndex = nextLF;
|
|
2783
|
+
return foldLine(string.slice(0, nextLF), width);
|
|
2784
|
+
}();
|
|
2785
|
+
var prevMoreIndented = string[0] === `
|
|
2786
|
+
` || string[0] === " ";
|
|
2787
|
+
var moreIndented;
|
|
2788
|
+
var match;
|
|
2789
|
+
while (match = lineRe.exec(string)) {
|
|
2790
|
+
var prefix = match[1], line = match[2];
|
|
2791
|
+
moreIndented = line[0] === " ";
|
|
2792
|
+
result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? `
|
|
2793
|
+
` : "") + foldLine(line, width);
|
|
2794
|
+
prevMoreIndented = moreIndented;
|
|
2795
|
+
}
|
|
2796
|
+
return result;
|
|
2797
|
+
}
|
|
2798
|
+
function foldLine(line, width) {
|
|
2799
|
+
if (line === "" || line[0] === " ")
|
|
2800
|
+
return line;
|
|
2801
|
+
var breakRe = / [^ ]/g;
|
|
2802
|
+
var match;
|
|
2803
|
+
var start = 0, end, curr = 0, next = 0;
|
|
2804
|
+
var result = "";
|
|
2805
|
+
while (match = breakRe.exec(line)) {
|
|
2806
|
+
next = match.index;
|
|
2807
|
+
if (next - start > width) {
|
|
2808
|
+
end = curr > start ? curr : next;
|
|
2809
|
+
result += `
|
|
2810
|
+
` + line.slice(start, end);
|
|
2811
|
+
start = end + 1;
|
|
2812
|
+
}
|
|
2813
|
+
curr = next;
|
|
2814
|
+
}
|
|
2815
|
+
result += `
|
|
2816
|
+
`;
|
|
2817
|
+
if (line.length - start > width && curr > start) {
|
|
2818
|
+
result += line.slice(start, curr) + `
|
|
2819
|
+
` + line.slice(curr + 1);
|
|
2820
|
+
} else {
|
|
2821
|
+
result += line.slice(start);
|
|
2822
|
+
}
|
|
2823
|
+
return result.slice(1);
|
|
2824
|
+
}
|
|
2825
|
+
function escapeString(string) {
|
|
2826
|
+
var result = "";
|
|
2827
|
+
var char, nextChar;
|
|
2828
|
+
var escapeSeq;
|
|
2829
|
+
for (var i = 0;i < string.length; i++) {
|
|
2830
|
+
char = string.charCodeAt(i);
|
|
2831
|
+
if (char >= 55296 && char <= 56319) {
|
|
2832
|
+
nextChar = string.charCodeAt(i + 1);
|
|
2833
|
+
if (nextChar >= 56320 && nextChar <= 57343) {
|
|
2834
|
+
result += encodeHex((char - 55296) * 1024 + nextChar - 56320 + 65536);
|
|
2835
|
+
i++;
|
|
2836
|
+
continue;
|
|
2837
|
+
}
|
|
2838
|
+
}
|
|
2839
|
+
escapeSeq = ESCAPE_SEQUENCES[char];
|
|
2840
|
+
result += !escapeSeq && isPrintable(char) ? string[i] : escapeSeq || encodeHex(char);
|
|
2841
|
+
}
|
|
2842
|
+
return result;
|
|
2843
|
+
}
|
|
2844
|
+
function writeFlowSequence(state, level, object) {
|
|
2845
|
+
var _result = "", _tag = state.tag, index, length;
|
|
2846
|
+
for (index = 0, length = object.length;index < length; index += 1) {
|
|
2847
|
+
if (writeNode(state, level, object[index], false, false)) {
|
|
2848
|
+
if (index !== 0)
|
|
2849
|
+
_result += "," + (!state.condenseFlow ? " " : "");
|
|
2850
|
+
_result += state.dump;
|
|
2851
|
+
}
|
|
2852
|
+
}
|
|
2853
|
+
state.tag = _tag;
|
|
2854
|
+
state.dump = "[" + _result + "]";
|
|
2855
|
+
}
|
|
2856
|
+
function writeBlockSequence(state, level, object, compact) {
|
|
2857
|
+
var _result = "", _tag = state.tag, index, length;
|
|
2858
|
+
for (index = 0, length = object.length;index < length; index += 1) {
|
|
2859
|
+
if (writeNode(state, level + 1, object[index], true, true)) {
|
|
2860
|
+
if (!compact || index !== 0) {
|
|
2861
|
+
_result += generateNextLine(state, level);
|
|
2862
|
+
}
|
|
2863
|
+
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
2864
|
+
_result += "-";
|
|
2865
|
+
} else {
|
|
2866
|
+
_result += "- ";
|
|
2867
|
+
}
|
|
2868
|
+
_result += state.dump;
|
|
2869
|
+
}
|
|
2870
|
+
}
|
|
2871
|
+
state.tag = _tag;
|
|
2872
|
+
state.dump = _result || "[]";
|
|
2873
|
+
}
|
|
2874
|
+
function writeFlowMapping(state, level, object) {
|
|
2875
|
+
var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, pairBuffer;
|
|
2876
|
+
for (index = 0, length = objectKeyList.length;index < length; index += 1) {
|
|
2877
|
+
pairBuffer = "";
|
|
2878
|
+
if (index !== 0)
|
|
2879
|
+
pairBuffer += ", ";
|
|
2880
|
+
if (state.condenseFlow)
|
|
2881
|
+
pairBuffer += '"';
|
|
2882
|
+
objectKey = objectKeyList[index];
|
|
2883
|
+
objectValue = object[objectKey];
|
|
2884
|
+
if (!writeNode(state, level, objectKey, false, false)) {
|
|
2885
|
+
continue;
|
|
2886
|
+
}
|
|
2887
|
+
if (state.dump.length > 1024)
|
|
2888
|
+
pairBuffer += "? ";
|
|
2889
|
+
pairBuffer += state.dump + (state.condenseFlow ? '"' : "") + ":" + (state.condenseFlow ? "" : " ");
|
|
2890
|
+
if (!writeNode(state, level, objectValue, false, false)) {
|
|
2891
|
+
continue;
|
|
2892
|
+
}
|
|
2893
|
+
pairBuffer += state.dump;
|
|
2894
|
+
_result += pairBuffer;
|
|
2895
|
+
}
|
|
2896
|
+
state.tag = _tag;
|
|
2897
|
+
state.dump = "{" + _result + "}";
|
|
2898
|
+
}
|
|
2899
|
+
function writeBlockMapping(state, level, object, compact) {
|
|
2900
|
+
var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, explicitPair, pairBuffer;
|
|
2901
|
+
if (state.sortKeys === true) {
|
|
2902
|
+
objectKeyList.sort();
|
|
2903
|
+
} else if (typeof state.sortKeys === "function") {
|
|
2904
|
+
objectKeyList.sort(state.sortKeys);
|
|
2905
|
+
} else if (state.sortKeys) {
|
|
2906
|
+
throw new YAMLException("sortKeys must be a boolean or a function");
|
|
2907
|
+
}
|
|
2908
|
+
for (index = 0, length = objectKeyList.length;index < length; index += 1) {
|
|
2909
|
+
pairBuffer = "";
|
|
2910
|
+
if (!compact || index !== 0) {
|
|
2911
|
+
pairBuffer += generateNextLine(state, level);
|
|
2912
|
+
}
|
|
2913
|
+
objectKey = objectKeyList[index];
|
|
2914
|
+
objectValue = object[objectKey];
|
|
2915
|
+
if (!writeNode(state, level + 1, objectKey, true, true, true)) {
|
|
2916
|
+
continue;
|
|
2917
|
+
}
|
|
2918
|
+
explicitPair = state.tag !== null && state.tag !== "?" || state.dump && state.dump.length > 1024;
|
|
2919
|
+
if (explicitPair) {
|
|
2920
|
+
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
2921
|
+
pairBuffer += "?";
|
|
2922
|
+
} else {
|
|
2923
|
+
pairBuffer += "? ";
|
|
2924
|
+
}
|
|
2925
|
+
}
|
|
2926
|
+
pairBuffer += state.dump;
|
|
2927
|
+
if (explicitPair) {
|
|
2928
|
+
pairBuffer += generateNextLine(state, level);
|
|
2929
|
+
}
|
|
2930
|
+
if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
|
|
2931
|
+
continue;
|
|
2932
|
+
}
|
|
2933
|
+
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
2934
|
+
pairBuffer += ":";
|
|
2935
|
+
} else {
|
|
2936
|
+
pairBuffer += ": ";
|
|
2937
|
+
}
|
|
2938
|
+
pairBuffer += state.dump;
|
|
2939
|
+
_result += pairBuffer;
|
|
2940
|
+
}
|
|
2941
|
+
state.tag = _tag;
|
|
2942
|
+
state.dump = _result || "{}";
|
|
2943
|
+
}
|
|
2944
|
+
function detectType(state, object, explicit) {
|
|
2945
|
+
var _result, typeList, index, length, type, style;
|
|
2946
|
+
typeList = explicit ? state.explicitTypes : state.implicitTypes;
|
|
2947
|
+
for (index = 0, length = typeList.length;index < length; index += 1) {
|
|
2948
|
+
type = typeList[index];
|
|
2949
|
+
if ((type.instanceOf || type.predicate) && (!type.instanceOf || typeof object === "object" && object instanceof type.instanceOf) && (!type.predicate || type.predicate(object))) {
|
|
2950
|
+
state.tag = explicit ? type.tag : "?";
|
|
2951
|
+
if (type.represent) {
|
|
2952
|
+
style = state.styleMap[type.tag] || type.defaultStyle;
|
|
2953
|
+
if (_toString.call(type.represent) === "[object Function]") {
|
|
2954
|
+
_result = type.represent(object, style);
|
|
2955
|
+
} else if (_hasOwnProperty.call(type.represent, style)) {
|
|
2956
|
+
_result = type.represent[style](object, style);
|
|
2957
|
+
} else {
|
|
2958
|
+
throw new YAMLException("!<" + type.tag + '> tag resolver accepts not "' + style + '" style');
|
|
2959
|
+
}
|
|
2960
|
+
state.dump = _result;
|
|
2961
|
+
}
|
|
2962
|
+
return true;
|
|
2963
|
+
}
|
|
2964
|
+
}
|
|
2965
|
+
return false;
|
|
2966
|
+
}
|
|
2967
|
+
function writeNode(state, level, object, block, compact, iskey) {
|
|
2968
|
+
state.tag = null;
|
|
2969
|
+
state.dump = object;
|
|
2970
|
+
if (!detectType(state, object, false)) {
|
|
2971
|
+
detectType(state, object, true);
|
|
2972
|
+
}
|
|
2973
|
+
var type = _toString.call(state.dump);
|
|
2974
|
+
if (block) {
|
|
2975
|
+
block = state.flowLevel < 0 || state.flowLevel > level;
|
|
2976
|
+
}
|
|
2977
|
+
var objectOrArray = type === "[object Object]" || type === "[object Array]", duplicateIndex, duplicate;
|
|
2978
|
+
if (objectOrArray) {
|
|
2979
|
+
duplicateIndex = state.duplicates.indexOf(object);
|
|
2980
|
+
duplicate = duplicateIndex !== -1;
|
|
2981
|
+
}
|
|
2982
|
+
if (state.tag !== null && state.tag !== "?" || duplicate || state.indent !== 2 && level > 0) {
|
|
2983
|
+
compact = false;
|
|
2984
|
+
}
|
|
2985
|
+
if (duplicate && state.usedDuplicates[duplicateIndex]) {
|
|
2986
|
+
state.dump = "*ref_" + duplicateIndex;
|
|
2987
|
+
} else {
|
|
2988
|
+
if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
|
|
2989
|
+
state.usedDuplicates[duplicateIndex] = true;
|
|
2990
|
+
}
|
|
2991
|
+
if (type === "[object Object]") {
|
|
2992
|
+
if (block && Object.keys(state.dump).length !== 0) {
|
|
2993
|
+
writeBlockMapping(state, level, state.dump, compact);
|
|
2994
|
+
if (duplicate) {
|
|
2995
|
+
state.dump = "&ref_" + duplicateIndex + state.dump;
|
|
2996
|
+
}
|
|
2997
|
+
} else {
|
|
2998
|
+
writeFlowMapping(state, level, state.dump);
|
|
2999
|
+
if (duplicate) {
|
|
3000
|
+
state.dump = "&ref_" + duplicateIndex + " " + state.dump;
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
} else if (type === "[object Array]") {
|
|
3004
|
+
var arrayLevel = state.noArrayIndent && level > 0 ? level - 1 : level;
|
|
3005
|
+
if (block && state.dump.length !== 0) {
|
|
3006
|
+
writeBlockSequence(state, arrayLevel, state.dump, compact);
|
|
3007
|
+
if (duplicate) {
|
|
3008
|
+
state.dump = "&ref_" + duplicateIndex + state.dump;
|
|
3009
|
+
}
|
|
3010
|
+
} else {
|
|
3011
|
+
writeFlowSequence(state, arrayLevel, state.dump);
|
|
3012
|
+
if (duplicate) {
|
|
3013
|
+
state.dump = "&ref_" + duplicateIndex + " " + state.dump;
|
|
3014
|
+
}
|
|
3015
|
+
}
|
|
3016
|
+
} else if (type === "[object String]") {
|
|
3017
|
+
if (state.tag !== "?") {
|
|
3018
|
+
writeScalar(state, state.dump, level, iskey);
|
|
3019
|
+
}
|
|
3020
|
+
} else {
|
|
3021
|
+
if (state.skipInvalid)
|
|
3022
|
+
return false;
|
|
3023
|
+
throw new YAMLException("unacceptable kind of an object to dump " + type);
|
|
3024
|
+
}
|
|
3025
|
+
if (state.tag !== null && state.tag !== "?") {
|
|
3026
|
+
state.dump = "!<" + state.tag + "> " + state.dump;
|
|
3027
|
+
}
|
|
3028
|
+
}
|
|
3029
|
+
return true;
|
|
3030
|
+
}
|
|
3031
|
+
function getDuplicateReferences(object, state) {
|
|
3032
|
+
var objects = [], duplicatesIndexes = [], index, length;
|
|
3033
|
+
inspectNode(object, objects, duplicatesIndexes);
|
|
3034
|
+
for (index = 0, length = duplicatesIndexes.length;index < length; index += 1) {
|
|
3035
|
+
state.duplicates.push(objects[duplicatesIndexes[index]]);
|
|
3036
|
+
}
|
|
3037
|
+
state.usedDuplicates = new Array(length);
|
|
3038
|
+
}
|
|
3039
|
+
function inspectNode(object, objects, duplicatesIndexes) {
|
|
3040
|
+
var objectKeyList, index, length;
|
|
3041
|
+
if (object !== null && typeof object === "object") {
|
|
3042
|
+
index = objects.indexOf(object);
|
|
3043
|
+
if (index !== -1) {
|
|
3044
|
+
if (duplicatesIndexes.indexOf(index) === -1) {
|
|
3045
|
+
duplicatesIndexes.push(index);
|
|
3046
|
+
}
|
|
3047
|
+
} else {
|
|
3048
|
+
objects.push(object);
|
|
3049
|
+
if (Array.isArray(object)) {
|
|
3050
|
+
for (index = 0, length = object.length;index < length; index += 1) {
|
|
3051
|
+
inspectNode(object[index], objects, duplicatesIndexes);
|
|
3052
|
+
}
|
|
3053
|
+
} else {
|
|
3054
|
+
objectKeyList = Object.keys(object);
|
|
3055
|
+
for (index = 0, length = objectKeyList.length;index < length; index += 1) {
|
|
3056
|
+
inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
|
|
3057
|
+
}
|
|
3058
|
+
}
|
|
3059
|
+
}
|
|
3060
|
+
}
|
|
3061
|
+
}
|
|
3062
|
+
function dump(input, options2) {
|
|
3063
|
+
options2 = options2 || {};
|
|
3064
|
+
var state = new State(options2);
|
|
3065
|
+
if (!state.noRefs)
|
|
3066
|
+
getDuplicateReferences(input, state);
|
|
3067
|
+
if (writeNode(state, 0, input, true, true))
|
|
3068
|
+
return state.dump + `
|
|
3069
|
+
`;
|
|
3070
|
+
return "";
|
|
3071
|
+
}
|
|
3072
|
+
function safeDump(input, options2) {
|
|
3073
|
+
return dump(input, common.extend({ schema: DEFAULT_SAFE_SCHEMA }, options2));
|
|
3074
|
+
}
|
|
3075
|
+
exports.dump = dump;
|
|
3076
|
+
exports.safeDump = safeDump;
|
|
3077
|
+
});
|
|
3078
|
+
|
|
3079
|
+
// node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml.js
|
|
3080
|
+
var require_js_yaml = __commonJS((exports, module) => {
|
|
3081
|
+
var loader = require_loader();
|
|
3082
|
+
var dumper = require_dumper();
|
|
3083
|
+
function deprecated(name) {
|
|
3084
|
+
return function() {
|
|
3085
|
+
throw new Error("Function " + name + " is deprecated and cannot be used.");
|
|
3086
|
+
};
|
|
3087
|
+
}
|
|
3088
|
+
exports.Type = require_type();
|
|
3089
|
+
exports.Schema = require_schema();
|
|
3090
|
+
exports.FAILSAFE_SCHEMA = require_failsafe();
|
|
3091
|
+
exports.JSON_SCHEMA = require_json();
|
|
3092
|
+
exports.CORE_SCHEMA = require_core();
|
|
3093
|
+
exports.DEFAULT_SAFE_SCHEMA = require_default_safe();
|
|
3094
|
+
exports.DEFAULT_FULL_SCHEMA = require_default_full();
|
|
3095
|
+
exports.load = loader.load;
|
|
3096
|
+
exports.loadAll = loader.loadAll;
|
|
3097
|
+
exports.safeLoad = loader.safeLoad;
|
|
3098
|
+
exports.safeLoadAll = loader.safeLoadAll;
|
|
3099
|
+
exports.dump = dumper.dump;
|
|
3100
|
+
exports.safeDump = dumper.safeDump;
|
|
3101
|
+
exports.YAMLException = require_exception();
|
|
3102
|
+
exports.MINIMAL_SCHEMA = require_failsafe();
|
|
3103
|
+
exports.SAFE_SCHEMA = require_default_safe();
|
|
3104
|
+
exports.DEFAULT_SCHEMA = require_default_full();
|
|
3105
|
+
exports.scan = deprecated("scan");
|
|
3106
|
+
exports.parse = deprecated("parse");
|
|
3107
|
+
exports.compose = deprecated("compose");
|
|
3108
|
+
exports.addConstructor = deprecated("addConstructor");
|
|
3109
|
+
});
|
|
3110
|
+
|
|
3111
|
+
// node_modules/gray-matter/node_modules/js-yaml/index.js
|
|
3112
|
+
var require_js_yaml2 = __commonJS((exports, module) => {
|
|
3113
|
+
var yaml = require_js_yaml();
|
|
3114
|
+
module.exports = yaml;
|
|
3115
|
+
});
|
|
3116
|
+
|
|
3117
|
+
// node_modules/gray-matter/lib/engines.js
|
|
3118
|
+
var require_engines = __commonJS((exports, module) => {
|
|
3119
|
+
var yaml = require_js_yaml2();
|
|
3120
|
+
var engines = exports = module.exports;
|
|
3121
|
+
engines.yaml = {
|
|
3122
|
+
parse: yaml.safeLoad.bind(yaml),
|
|
3123
|
+
stringify: yaml.safeDump.bind(yaml)
|
|
3124
|
+
};
|
|
3125
|
+
engines.json = {
|
|
3126
|
+
parse: JSON.parse.bind(JSON),
|
|
3127
|
+
stringify: function(obj, options2) {
|
|
3128
|
+
const opts = Object.assign({ replacer: null, space: 2 }, options2);
|
|
3129
|
+
return JSON.stringify(obj, opts.replacer, opts.space);
|
|
3130
|
+
}
|
|
3131
|
+
};
|
|
3132
|
+
engines.javascript = {
|
|
3133
|
+
parse: function parse(str, options, wrap) {
|
|
3134
|
+
try {
|
|
3135
|
+
if (wrap !== false) {
|
|
3136
|
+
str = `(function() {
|
|
3137
|
+
return ` + str.trim() + `;
|
|
3138
|
+
}());`;
|
|
3139
|
+
}
|
|
3140
|
+
return eval(str) || {};
|
|
3141
|
+
} catch (err) {
|
|
3142
|
+
if (wrap !== false && /(unexpected|identifier)/i.test(err.message)) {
|
|
3143
|
+
return parse(str, options, false);
|
|
3144
|
+
}
|
|
3145
|
+
throw new SyntaxError(err);
|
|
3146
|
+
}
|
|
3147
|
+
},
|
|
3148
|
+
stringify: function() {
|
|
3149
|
+
throw new Error("stringifying JavaScript is not supported");
|
|
3150
|
+
}
|
|
3151
|
+
};
|
|
3152
|
+
});
|
|
3153
|
+
|
|
3154
|
+
// node_modules/strip-bom-string/index.js
|
|
3155
|
+
var require_strip_bom_string = __commonJS((exports, module) => {
|
|
3156
|
+
/*!
|
|
3157
|
+
* strip-bom-string <https://github.com/jonschlinkert/strip-bom-string>
|
|
3158
|
+
*
|
|
3159
|
+
* Copyright (c) 2015, 2017, Jon Schlinkert.
|
|
3160
|
+
* Released under the MIT License.
|
|
3161
|
+
*/
|
|
3162
|
+
module.exports = function(str2) {
|
|
3163
|
+
if (typeof str2 === "string" && str2.charAt(0) === "\uFEFF") {
|
|
3164
|
+
return str2.slice(1);
|
|
3165
|
+
}
|
|
3166
|
+
return str2;
|
|
3167
|
+
};
|
|
3168
|
+
});
|
|
3169
|
+
|
|
3170
|
+
// node_modules/gray-matter/lib/utils.js
|
|
3171
|
+
var require_utils = __commonJS((exports) => {
|
|
3172
|
+
var stripBom = require_strip_bom_string();
|
|
3173
|
+
var typeOf = require_kind_of();
|
|
3174
|
+
exports.define = function(obj, key, val) {
|
|
3175
|
+
Reflect.defineProperty(obj, key, {
|
|
3176
|
+
enumerable: false,
|
|
3177
|
+
configurable: true,
|
|
3178
|
+
writable: true,
|
|
3179
|
+
value: val
|
|
3180
|
+
});
|
|
3181
|
+
};
|
|
3182
|
+
exports.isBuffer = function(val) {
|
|
3183
|
+
return typeOf(val) === "buffer";
|
|
3184
|
+
};
|
|
3185
|
+
exports.isObject = function(val) {
|
|
3186
|
+
return typeOf(val) === "object";
|
|
3187
|
+
};
|
|
3188
|
+
exports.toBuffer = function(input) {
|
|
3189
|
+
return typeof input === "string" ? Buffer.from(input) : input;
|
|
3190
|
+
};
|
|
3191
|
+
exports.toString = function(input) {
|
|
3192
|
+
if (exports.isBuffer(input))
|
|
3193
|
+
return stripBom(String(input));
|
|
3194
|
+
if (typeof input !== "string") {
|
|
3195
|
+
throw new TypeError("expected input to be a string or buffer");
|
|
3196
|
+
}
|
|
3197
|
+
return stripBom(input);
|
|
3198
|
+
};
|
|
3199
|
+
exports.arrayify = function(val) {
|
|
3200
|
+
return val ? Array.isArray(val) ? val : [val] : [];
|
|
3201
|
+
};
|
|
3202
|
+
exports.startsWith = function(str2, substr, len) {
|
|
3203
|
+
if (typeof len !== "number")
|
|
3204
|
+
len = substr.length;
|
|
3205
|
+
return str2.slice(0, len) === substr;
|
|
3206
|
+
};
|
|
3207
|
+
});
|
|
3208
|
+
|
|
3209
|
+
// node_modules/gray-matter/lib/defaults.js
|
|
3210
|
+
var require_defaults = __commonJS((exports, module) => {
|
|
3211
|
+
var engines = require_engines();
|
|
3212
|
+
var utils = require_utils();
|
|
3213
|
+
module.exports = function(options2) {
|
|
3214
|
+
const opts = Object.assign({}, options2);
|
|
3215
|
+
opts.delimiters = utils.arrayify(opts.delims || opts.delimiters || "---");
|
|
3216
|
+
if (opts.delimiters.length === 1) {
|
|
3217
|
+
opts.delimiters.push(opts.delimiters[0]);
|
|
3218
|
+
}
|
|
3219
|
+
opts.language = (opts.language || opts.lang || "yaml").toLowerCase();
|
|
3220
|
+
opts.engines = Object.assign({}, engines, opts.parsers, opts.engines);
|
|
3221
|
+
return opts;
|
|
3222
|
+
};
|
|
3223
|
+
});
|
|
3224
|
+
|
|
3225
|
+
// node_modules/gray-matter/lib/engine.js
|
|
3226
|
+
var require_engine = __commonJS((exports, module) => {
|
|
3227
|
+
module.exports = function(name, options2) {
|
|
3228
|
+
let engine = options2.engines[name] || options2.engines[aliase(name)];
|
|
3229
|
+
if (typeof engine === "undefined") {
|
|
3230
|
+
throw new Error('gray-matter engine "' + name + '" is not registered');
|
|
3231
|
+
}
|
|
3232
|
+
if (typeof engine === "function") {
|
|
3233
|
+
engine = { parse: engine };
|
|
3234
|
+
}
|
|
3235
|
+
return engine;
|
|
3236
|
+
};
|
|
3237
|
+
function aliase(name) {
|
|
3238
|
+
switch (name.toLowerCase()) {
|
|
3239
|
+
case "js":
|
|
3240
|
+
case "javascript":
|
|
3241
|
+
return "javascript";
|
|
3242
|
+
case "coffee":
|
|
3243
|
+
case "coffeescript":
|
|
3244
|
+
case "cson":
|
|
3245
|
+
return "coffee";
|
|
3246
|
+
case "yaml":
|
|
3247
|
+
case "yml":
|
|
3248
|
+
return "yaml";
|
|
3249
|
+
default: {
|
|
3250
|
+
return name;
|
|
3251
|
+
}
|
|
3252
|
+
}
|
|
3253
|
+
}
|
|
3254
|
+
});
|
|
3255
|
+
|
|
3256
|
+
// node_modules/gray-matter/lib/stringify.js
|
|
3257
|
+
var require_stringify = __commonJS((exports, module) => {
|
|
3258
|
+
var typeOf = require_kind_of();
|
|
3259
|
+
var getEngine = require_engine();
|
|
3260
|
+
var defaults = require_defaults();
|
|
3261
|
+
module.exports = function(file, data, options2) {
|
|
3262
|
+
if (data == null && options2 == null) {
|
|
3263
|
+
switch (typeOf(file)) {
|
|
3264
|
+
case "object":
|
|
3265
|
+
data = file.data;
|
|
3266
|
+
options2 = {};
|
|
3267
|
+
break;
|
|
3268
|
+
case "string":
|
|
3269
|
+
return file;
|
|
3270
|
+
default: {
|
|
3271
|
+
throw new TypeError("expected file to be a string or object");
|
|
3272
|
+
}
|
|
3273
|
+
}
|
|
3274
|
+
}
|
|
3275
|
+
const str2 = file.content;
|
|
3276
|
+
const opts = defaults(options2);
|
|
3277
|
+
if (data == null) {
|
|
3278
|
+
if (!opts.data)
|
|
3279
|
+
return file;
|
|
3280
|
+
data = opts.data;
|
|
3281
|
+
}
|
|
3282
|
+
const language = file.language || opts.language;
|
|
3283
|
+
const engine = getEngine(language, opts);
|
|
3284
|
+
if (typeof engine.stringify !== "function") {
|
|
3285
|
+
throw new TypeError('expected "' + language + '.stringify" to be a function');
|
|
3286
|
+
}
|
|
3287
|
+
data = Object.assign({}, file.data, data);
|
|
3288
|
+
const open = opts.delimiters[0];
|
|
3289
|
+
const close = opts.delimiters[1];
|
|
3290
|
+
const matter = engine.stringify(data, options2).trim();
|
|
3291
|
+
let buf = "";
|
|
3292
|
+
if (matter !== "{}") {
|
|
3293
|
+
buf = newline(open) + newline(matter) + newline(close);
|
|
3294
|
+
}
|
|
3295
|
+
if (typeof file.excerpt === "string" && file.excerpt !== "") {
|
|
3296
|
+
if (str2.indexOf(file.excerpt.trim()) === -1) {
|
|
3297
|
+
buf += newline(file.excerpt) + newline(close);
|
|
3298
|
+
}
|
|
3299
|
+
}
|
|
3300
|
+
return buf + newline(str2);
|
|
3301
|
+
};
|
|
3302
|
+
function newline(str2) {
|
|
3303
|
+
return str2.slice(-1) !== `
|
|
3304
|
+
` ? str2 + `
|
|
3305
|
+
` : str2;
|
|
3306
|
+
}
|
|
3307
|
+
});
|
|
3308
|
+
|
|
3309
|
+
// node_modules/gray-matter/lib/excerpt.js
|
|
3310
|
+
var require_excerpt = __commonJS((exports, module) => {
|
|
3311
|
+
var defaults = require_defaults();
|
|
3312
|
+
module.exports = function(file, options2) {
|
|
3313
|
+
const opts = defaults(options2);
|
|
3314
|
+
if (file.data == null) {
|
|
3315
|
+
file.data = {};
|
|
3316
|
+
}
|
|
3317
|
+
if (typeof opts.excerpt === "function") {
|
|
3318
|
+
return opts.excerpt(file, opts);
|
|
3319
|
+
}
|
|
3320
|
+
const sep = file.data.excerpt_separator || opts.excerpt_separator;
|
|
3321
|
+
if (sep == null && (opts.excerpt === false || opts.excerpt == null)) {
|
|
3322
|
+
return file;
|
|
3323
|
+
}
|
|
3324
|
+
const delimiter = typeof opts.excerpt === "string" ? opts.excerpt : sep || opts.delimiters[0];
|
|
3325
|
+
const idx = file.content.indexOf(delimiter);
|
|
3326
|
+
if (idx !== -1) {
|
|
3327
|
+
file.excerpt = file.content.slice(0, idx);
|
|
3328
|
+
}
|
|
3329
|
+
return file;
|
|
3330
|
+
};
|
|
3331
|
+
});
|
|
3332
|
+
|
|
3333
|
+
// node_modules/gray-matter/lib/to-file.js
|
|
3334
|
+
var require_to_file = __commonJS((exports, module) => {
|
|
3335
|
+
var typeOf = require_kind_of();
|
|
3336
|
+
var stringify = require_stringify();
|
|
3337
|
+
var utils = require_utils();
|
|
3338
|
+
module.exports = function(file) {
|
|
3339
|
+
if (typeOf(file) !== "object") {
|
|
3340
|
+
file = { content: file };
|
|
3341
|
+
}
|
|
3342
|
+
if (typeOf(file.data) !== "object") {
|
|
3343
|
+
file.data = {};
|
|
3344
|
+
}
|
|
3345
|
+
if (file.contents && file.content == null) {
|
|
3346
|
+
file.content = file.contents;
|
|
3347
|
+
}
|
|
3348
|
+
utils.define(file, "orig", utils.toBuffer(file.content));
|
|
3349
|
+
utils.define(file, "language", file.language || "");
|
|
3350
|
+
utils.define(file, "matter", file.matter || "");
|
|
3351
|
+
utils.define(file, "stringify", function(data, options2) {
|
|
3352
|
+
if (options2 && options2.language) {
|
|
3353
|
+
file.language = options2.language;
|
|
3354
|
+
}
|
|
3355
|
+
return stringify(file, data, options2);
|
|
3356
|
+
});
|
|
3357
|
+
file.content = utils.toString(file.content);
|
|
3358
|
+
file.isEmpty = false;
|
|
3359
|
+
file.excerpt = "";
|
|
3360
|
+
return file;
|
|
3361
|
+
};
|
|
3362
|
+
});
|
|
3363
|
+
|
|
3364
|
+
// node_modules/gray-matter/lib/parse.js
|
|
3365
|
+
var require_parse = __commonJS((exports, module) => {
|
|
3366
|
+
var getEngine = require_engine();
|
|
3367
|
+
var defaults = require_defaults();
|
|
3368
|
+
module.exports = function(language, str2, options2) {
|
|
3369
|
+
const opts = defaults(options2);
|
|
3370
|
+
const engine = getEngine(language, opts);
|
|
3371
|
+
if (typeof engine.parse !== "function") {
|
|
3372
|
+
throw new TypeError('expected "' + language + '.parse" to be a function');
|
|
3373
|
+
}
|
|
3374
|
+
return engine.parse(str2, opts);
|
|
3375
|
+
};
|
|
3376
|
+
});
|
|
3377
|
+
|
|
3378
|
+
// node_modules/gray-matter/index.js
|
|
3379
|
+
var require_gray_matter = __commonJS((exports, module) => {
|
|
3380
|
+
var fs = __require("fs");
|
|
3381
|
+
var sections = require_section_matter();
|
|
3382
|
+
var defaults = require_defaults();
|
|
3383
|
+
var stringify = require_stringify();
|
|
3384
|
+
var excerpt = require_excerpt();
|
|
3385
|
+
var engines = require_engines();
|
|
3386
|
+
var toFile = require_to_file();
|
|
3387
|
+
var parse2 = require_parse();
|
|
3388
|
+
var utils = require_utils();
|
|
3389
|
+
function matter(input, options2) {
|
|
3390
|
+
if (input === "") {
|
|
3391
|
+
return { data: {}, content: input, excerpt: "", orig: input };
|
|
3392
|
+
}
|
|
3393
|
+
let file = toFile(input);
|
|
3394
|
+
const cached = matter.cache[file.content];
|
|
3395
|
+
if (!options2) {
|
|
3396
|
+
if (cached) {
|
|
3397
|
+
file = Object.assign({}, cached);
|
|
3398
|
+
file.orig = cached.orig;
|
|
3399
|
+
return file;
|
|
3400
|
+
}
|
|
3401
|
+
matter.cache[file.content] = file;
|
|
3402
|
+
}
|
|
3403
|
+
return parseMatter(file, options2);
|
|
3404
|
+
}
|
|
3405
|
+
function parseMatter(file, options2) {
|
|
3406
|
+
const opts = defaults(options2);
|
|
3407
|
+
const open = opts.delimiters[0];
|
|
3408
|
+
const close = `
|
|
3409
|
+
` + opts.delimiters[1];
|
|
3410
|
+
let str2 = file.content;
|
|
3411
|
+
if (opts.language) {
|
|
3412
|
+
file.language = opts.language;
|
|
3413
|
+
}
|
|
3414
|
+
const openLen = open.length;
|
|
3415
|
+
if (!utils.startsWith(str2, open, openLen)) {
|
|
3416
|
+
excerpt(file, opts);
|
|
3417
|
+
return file;
|
|
3418
|
+
}
|
|
3419
|
+
if (str2.charAt(openLen) === open.slice(-1)) {
|
|
3420
|
+
return file;
|
|
3421
|
+
}
|
|
3422
|
+
str2 = str2.slice(openLen);
|
|
3423
|
+
const len = str2.length;
|
|
3424
|
+
const language = matter.language(str2, opts);
|
|
3425
|
+
if (language.name) {
|
|
3426
|
+
file.language = language.name;
|
|
3427
|
+
str2 = str2.slice(language.raw.length);
|
|
3428
|
+
}
|
|
3429
|
+
let closeIndex = str2.indexOf(close);
|
|
3430
|
+
if (closeIndex === -1) {
|
|
3431
|
+
closeIndex = len;
|
|
3432
|
+
}
|
|
3433
|
+
file.matter = str2.slice(0, closeIndex);
|
|
3434
|
+
const block = file.matter.replace(/^\s*#[^\n]+/gm, "").trim();
|
|
3435
|
+
if (block === "") {
|
|
3436
|
+
file.isEmpty = true;
|
|
3437
|
+
file.empty = file.content;
|
|
3438
|
+
file.data = {};
|
|
3439
|
+
} else {
|
|
3440
|
+
file.data = parse2(file.language, file.matter, opts);
|
|
3441
|
+
}
|
|
3442
|
+
if (closeIndex === len) {
|
|
3443
|
+
file.content = "";
|
|
3444
|
+
} else {
|
|
3445
|
+
file.content = str2.slice(closeIndex + close.length);
|
|
3446
|
+
if (file.content[0] === "\r") {
|
|
3447
|
+
file.content = file.content.slice(1);
|
|
3448
|
+
}
|
|
3449
|
+
if (file.content[0] === `
|
|
3450
|
+
`) {
|
|
3451
|
+
file.content = file.content.slice(1);
|
|
3452
|
+
}
|
|
3453
|
+
}
|
|
3454
|
+
excerpt(file, opts);
|
|
3455
|
+
if (opts.sections === true || typeof opts.section === "function") {
|
|
3456
|
+
sections(file, opts.section);
|
|
3457
|
+
}
|
|
3458
|
+
return file;
|
|
3459
|
+
}
|
|
3460
|
+
matter.engines = engines;
|
|
3461
|
+
matter.stringify = function(file, data, options2) {
|
|
3462
|
+
if (typeof file === "string")
|
|
3463
|
+
file = matter(file, options2);
|
|
3464
|
+
return stringify(file, data, options2);
|
|
3465
|
+
};
|
|
3466
|
+
matter.read = function(filepath, options2) {
|
|
3467
|
+
const str2 = fs.readFileSync(filepath, "utf8");
|
|
3468
|
+
const file = matter(str2, options2);
|
|
3469
|
+
file.path = filepath;
|
|
3470
|
+
return file;
|
|
3471
|
+
};
|
|
3472
|
+
matter.test = function(str2, options2) {
|
|
3473
|
+
return utils.startsWith(str2, defaults(options2).delimiters[0]);
|
|
3474
|
+
};
|
|
3475
|
+
matter.language = function(str2, options2) {
|
|
3476
|
+
const opts = defaults(options2);
|
|
3477
|
+
const open = opts.delimiters[0];
|
|
3478
|
+
if (matter.test(str2)) {
|
|
3479
|
+
str2 = str2.slice(open.length);
|
|
3480
|
+
}
|
|
3481
|
+
const language = str2.slice(0, str2.search(/\r?\n/));
|
|
3482
|
+
return {
|
|
3483
|
+
raw: language,
|
|
3484
|
+
name: language ? language.trim() : ""
|
|
3485
|
+
};
|
|
3486
|
+
};
|
|
3487
|
+
matter.cache = {};
|
|
3488
|
+
matter.clearCache = function() {
|
|
3489
|
+
matter.cache = {};
|
|
3490
|
+
};
|
|
3491
|
+
module.exports = matter;
|
|
3492
|
+
});
|
|
3493
|
+
|
|
1
3494
|
// src/multi-modal.ts
|
|
2
3495
|
function copyMultiModalContent(item) {
|
|
3
3496
|
if (item.type === "text") {
|
|
@@ -95,24 +3588,324 @@ var conversationShape = {
|
|
|
95
3588
|
updatedAt: z.string()
|
|
96
3589
|
};
|
|
97
3590
|
var conversationSchema = z.object(conversationShape);
|
|
3591
|
+
// src/utilities.ts
|
|
3592
|
+
var import_gray_matter = __toESM(require_gray_matter(), 1);
|
|
3593
|
+
function pairToolCallsWithResults(messages) {
|
|
3594
|
+
const pairs = [];
|
|
3595
|
+
const resultsMap = new Map;
|
|
3596
|
+
for (const msg of messages) {
|
|
3597
|
+
if (msg.toolResult) {
|
|
3598
|
+
resultsMap.set(msg.toolResult.callId, msg.toolResult);
|
|
3599
|
+
}
|
|
3600
|
+
}
|
|
3601
|
+
for (const msg of messages) {
|
|
3602
|
+
if (msg.toolCall) {
|
|
3603
|
+
pairs.push({
|
|
3604
|
+
call: msg.toolCall,
|
|
3605
|
+
result: resultsMap.get(msg.toolCall.id)
|
|
3606
|
+
});
|
|
3607
|
+
}
|
|
3608
|
+
}
|
|
3609
|
+
return pairs;
|
|
3610
|
+
}
|
|
3611
|
+
function toReadonly(value) {
|
|
3612
|
+
return value;
|
|
3613
|
+
}
|
|
3614
|
+
function createMessage(props) {
|
|
3615
|
+
const content = Array.isArray(props.content) ? toReadonly([...props.content]) : props.content;
|
|
3616
|
+
const message = {
|
|
3617
|
+
id: props.id,
|
|
3618
|
+
role: props.role,
|
|
3619
|
+
content,
|
|
3620
|
+
position: props.position,
|
|
3621
|
+
createdAt: props.createdAt,
|
|
3622
|
+
metadata: toReadonly({ ...props.metadata }),
|
|
3623
|
+
hidden: props.hidden,
|
|
3624
|
+
toolCall: props.toolCall ? toReadonly({ ...props.toolCall }) : undefined,
|
|
3625
|
+
toolResult: props.toolResult ? toReadonly({ ...props.toolResult }) : undefined,
|
|
3626
|
+
tokenUsage: props.tokenUsage ? toReadonly({ ...props.tokenUsage }) : undefined,
|
|
3627
|
+
goalCompleted: props.goalCompleted
|
|
3628
|
+
};
|
|
3629
|
+
return toReadonly(message);
|
|
3630
|
+
}
|
|
3631
|
+
function toMultiModalArray(input) {
|
|
3632
|
+
if (typeof input === "string")
|
|
3633
|
+
return [{ type: "text", text: input }];
|
|
3634
|
+
return Array.isArray(input) ? input : [input];
|
|
3635
|
+
}
|
|
3636
|
+
function normalizeContent(content) {
|
|
3637
|
+
if (content === undefined)
|
|
3638
|
+
return;
|
|
3639
|
+
if (typeof content === "string")
|
|
3640
|
+
return content;
|
|
3641
|
+
return Array.isArray(content) ? content : [content];
|
|
3642
|
+
}
|
|
3643
|
+
function messageParts(message) {
|
|
3644
|
+
if (typeof message.content === "string") {
|
|
3645
|
+
return message.content ? [{ type: "text", text: message.content }] : [];
|
|
3646
|
+
}
|
|
3647
|
+
return message.content;
|
|
3648
|
+
}
|
|
3649
|
+
function messageText(message, joiner = `
|
|
3650
|
+
|
|
3651
|
+
`) {
|
|
3652
|
+
if (typeof message.content === "string")
|
|
3653
|
+
return message.content;
|
|
3654
|
+
return messageParts(message).filter((p) => p.type === "text").map((p) => p.type === "text" ? p.text : "").join(joiner);
|
|
3655
|
+
}
|
|
3656
|
+
function messageHasImages(message) {
|
|
3657
|
+
return messageParts(message).some((p) => p.type === "image");
|
|
3658
|
+
}
|
|
3659
|
+
var ROLE_DISPLAY_NAMES = {
|
|
3660
|
+
user: "User",
|
|
3661
|
+
assistant: "Assistant",
|
|
3662
|
+
system: "System",
|
|
3663
|
+
developer: "Developer",
|
|
3664
|
+
"tool-use": "Tool Use",
|
|
3665
|
+
"tool-result": "Tool Result",
|
|
3666
|
+
snapshot: "Snapshot"
|
|
3667
|
+
};
|
|
3668
|
+
var DISPLAY_NAME_TO_ROLE = {
|
|
3669
|
+
User: "user",
|
|
3670
|
+
Assistant: "assistant",
|
|
3671
|
+
System: "system",
|
|
3672
|
+
Developer: "developer",
|
|
3673
|
+
"Tool Use": "tool-use",
|
|
3674
|
+
"Tool Result": "tool-result",
|
|
3675
|
+
Snapshot: "snapshot"
|
|
3676
|
+
};
|
|
3677
|
+
function formatMessageContent(message) {
|
|
3678
|
+
if (typeof message.content === "string")
|
|
3679
|
+
return message.content;
|
|
3680
|
+
const parts = messageParts(message);
|
|
3681
|
+
const lines = [];
|
|
3682
|
+
for (const part of parts) {
|
|
3683
|
+
if (part.type === "text" && part.text) {
|
|
3684
|
+
lines.push(part.text);
|
|
3685
|
+
} else if (part.type === "image") {
|
|
3686
|
+
const imageUrl = part.url;
|
|
3687
|
+
const altText = part.text ?? "image";
|
|
3688
|
+
lines.push(``);
|
|
3689
|
+
}
|
|
3690
|
+
}
|
|
3691
|
+
return lines.join(`
|
|
3692
|
+
|
|
3693
|
+
`);
|
|
3694
|
+
}
|
|
3695
|
+
function toMarkdown(conversation, options2 = {}) {
|
|
3696
|
+
const { includeMetadata = false } = options2;
|
|
3697
|
+
if (includeMetadata) {
|
|
3698
|
+
return toMarkdownWithMetadata(conversation);
|
|
3699
|
+
}
|
|
3700
|
+
return toMarkdownSimple(conversation);
|
|
3701
|
+
}
|
|
3702
|
+
function toMarkdownSimple(conversation) {
|
|
3703
|
+
const sections = [];
|
|
3704
|
+
for (const message of conversation.messages) {
|
|
3705
|
+
const roleName = ROLE_DISPLAY_NAMES[message.role];
|
|
3706
|
+
const header = `### ${roleName}`;
|
|
3707
|
+
const content = formatMessageContent(message);
|
|
3708
|
+
sections.push(`${header}
|
|
3709
|
+
|
|
3710
|
+
${content}`);
|
|
3711
|
+
}
|
|
3712
|
+
return sections.join(`
|
|
3713
|
+
|
|
3714
|
+
`);
|
|
3715
|
+
}
|
|
3716
|
+
function toMarkdownWithMetadata(conversation) {
|
|
3717
|
+
const messagesMetadata = {};
|
|
3718
|
+
for (const message of conversation.messages) {
|
|
3719
|
+
const messageMeta = {
|
|
3720
|
+
position: message.position,
|
|
3721
|
+
createdAt: message.createdAt,
|
|
3722
|
+
metadata: { ...message.metadata },
|
|
3723
|
+
hidden: message.hidden
|
|
3724
|
+
};
|
|
3725
|
+
if (Array.isArray(message.content)) {
|
|
3726
|
+
messageMeta.content = copyContent(message.content);
|
|
3727
|
+
}
|
|
3728
|
+
if (message.toolCall) {
|
|
3729
|
+
messageMeta.toolCall = { ...message.toolCall };
|
|
3730
|
+
}
|
|
3731
|
+
if (message.toolResult) {
|
|
3732
|
+
messageMeta.toolResult = { ...message.toolResult };
|
|
3733
|
+
}
|
|
3734
|
+
if (message.tokenUsage) {
|
|
3735
|
+
messageMeta.tokenUsage = { ...message.tokenUsage };
|
|
3736
|
+
}
|
|
3737
|
+
if (message.goalCompleted !== undefined) {
|
|
3738
|
+
messageMeta.goalCompleted = message.goalCompleted;
|
|
3739
|
+
}
|
|
3740
|
+
messagesMetadata[message.id] = messageMeta;
|
|
3741
|
+
}
|
|
3742
|
+
const frontmatterData = {
|
|
3743
|
+
id: conversation.id,
|
|
3744
|
+
status: conversation.status,
|
|
3745
|
+
metadata: { ...conversation.metadata },
|
|
3746
|
+
tags: [...conversation.tags],
|
|
3747
|
+
createdAt: conversation.createdAt,
|
|
3748
|
+
updatedAt: conversation.updatedAt,
|
|
3749
|
+
messages: messagesMetadata
|
|
3750
|
+
};
|
|
3751
|
+
if (conversation.title !== undefined) {
|
|
3752
|
+
frontmatterData.title = conversation.title;
|
|
3753
|
+
}
|
|
3754
|
+
const messageSections = [];
|
|
3755
|
+
for (const message of conversation.messages) {
|
|
3756
|
+
const roleName = ROLE_DISPLAY_NAMES[message.role];
|
|
3757
|
+
const header = `### ${roleName} (${message.id})`;
|
|
3758
|
+
const content = formatMessageContent(message);
|
|
3759
|
+
messageSections.push(`${header}
|
|
3760
|
+
|
|
3761
|
+
${content}`);
|
|
3762
|
+
}
|
|
3763
|
+
const body = messageSections.join(`
|
|
3764
|
+
|
|
3765
|
+
`);
|
|
3766
|
+
return import_gray_matter.default.stringify(body, frontmatterData);
|
|
3767
|
+
}
|
|
3768
|
+
|
|
3769
|
+
class MarkdownParseError extends Error {
|
|
3770
|
+
constructor(message) {
|
|
3771
|
+
super(message);
|
|
3772
|
+
this.name = "MarkdownParseError";
|
|
3773
|
+
}
|
|
3774
|
+
}
|
|
3775
|
+
function generateId() {
|
|
3776
|
+
return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
|
|
3777
|
+
}
|
|
3778
|
+
function fromMarkdown(markdown) {
|
|
3779
|
+
const trimmed = markdown.trim();
|
|
3780
|
+
const hasFrontmatter = trimmed.startsWith("---");
|
|
3781
|
+
if (hasFrontmatter) {
|
|
3782
|
+
return parseMarkdownWithMetadata(trimmed);
|
|
3783
|
+
}
|
|
3784
|
+
return parseMarkdownSimple(trimmed);
|
|
3785
|
+
}
|
|
3786
|
+
function parseMarkdownWithMetadata(trimmed) {
|
|
3787
|
+
let parsed;
|
|
3788
|
+
try {
|
|
3789
|
+
parsed = import_gray_matter.default(trimmed);
|
|
3790
|
+
} catch {
|
|
3791
|
+
throw new MarkdownParseError("Invalid frontmatter: failed to parse YAML");
|
|
3792
|
+
}
|
|
3793
|
+
const frontmatter = parsed.data;
|
|
3794
|
+
const body = parsed.content.trim();
|
|
3795
|
+
if (!frontmatter.id) {
|
|
3796
|
+
throw new MarkdownParseError('Invalid frontmatter: missing required field "id"');
|
|
3797
|
+
}
|
|
3798
|
+
const messages = [];
|
|
3799
|
+
const messagePattern = /^### ([\w\s]+) \(([^)]+)\)\n\n([\s\S]*?)(?=\n\n### |\n*$)/gm;
|
|
3800
|
+
let match;
|
|
3801
|
+
while ((match = messagePattern.exec(body)) !== null) {
|
|
3802
|
+
const [, roleDisplay, messageId, contentBody] = match;
|
|
3803
|
+
const role = DISPLAY_NAME_TO_ROLE[roleDisplay];
|
|
3804
|
+
if (!role) {
|
|
3805
|
+
throw new MarkdownParseError(`Unknown role: ${roleDisplay}`);
|
|
3806
|
+
}
|
|
3807
|
+
const messageMeta = frontmatter.messages?.[messageId];
|
|
3808
|
+
if (!messageMeta) {
|
|
3809
|
+
throw new MarkdownParseError(`Missing metadata for message: ${messageId}`);
|
|
3810
|
+
}
|
|
3811
|
+
let content;
|
|
3812
|
+
if (messageMeta.content) {
|
|
3813
|
+
content = toReadonly([...messageMeta.content]);
|
|
3814
|
+
} else {
|
|
3815
|
+
content = contentBody?.trim() ?? "";
|
|
3816
|
+
}
|
|
3817
|
+
const message = {
|
|
3818
|
+
id: messageId,
|
|
3819
|
+
role,
|
|
3820
|
+
content,
|
|
3821
|
+
position: messageMeta.position,
|
|
3822
|
+
createdAt: messageMeta.createdAt,
|
|
3823
|
+
metadata: toReadonly({ ...messageMeta.metadata }),
|
|
3824
|
+
hidden: messageMeta.hidden,
|
|
3825
|
+
toolCall: messageMeta.toolCall ? toReadonly({ ...messageMeta.toolCall }) : undefined,
|
|
3826
|
+
toolResult: messageMeta.toolResult ? toReadonly({ ...messageMeta.toolResult }) : undefined,
|
|
3827
|
+
tokenUsage: messageMeta.tokenUsage ? toReadonly({ ...messageMeta.tokenUsage }) : undefined,
|
|
3828
|
+
goalCompleted: messageMeta.goalCompleted
|
|
3829
|
+
};
|
|
3830
|
+
messages.push(toReadonly(message));
|
|
3831
|
+
}
|
|
3832
|
+
const conversation = {
|
|
3833
|
+
id: frontmatter.id,
|
|
3834
|
+
title: frontmatter.title,
|
|
3835
|
+
status: frontmatter.status ?? "active",
|
|
3836
|
+
metadata: toReadonly({ ...frontmatter.metadata }),
|
|
3837
|
+
tags: toReadonly([...frontmatter.tags ?? []]),
|
|
3838
|
+
messages: toReadonly(messages),
|
|
3839
|
+
createdAt: frontmatter.createdAt,
|
|
3840
|
+
updatedAt: frontmatter.updatedAt
|
|
3841
|
+
};
|
|
3842
|
+
return toReadonly(conversation);
|
|
3843
|
+
}
|
|
3844
|
+
function parseMarkdownSimple(body) {
|
|
3845
|
+
const now = new Date().toISOString();
|
|
3846
|
+
const messages = [];
|
|
3847
|
+
const messagePattern = /^### ([^\n]+)\n\n([\s\S]*?)(?=\n\n### |\n*$)/gm;
|
|
3848
|
+
let match;
|
|
3849
|
+
let position = 0;
|
|
3850
|
+
while ((match = messagePattern.exec(body)) !== null) {
|
|
3851
|
+
const [, roleDisplay, contentBody] = match;
|
|
3852
|
+
const role = DISPLAY_NAME_TO_ROLE[roleDisplay];
|
|
3853
|
+
if (!role) {
|
|
3854
|
+
throw new MarkdownParseError(`Unknown role: ${roleDisplay}`);
|
|
3855
|
+
}
|
|
3856
|
+
const message = {
|
|
3857
|
+
id: generateId(),
|
|
3858
|
+
role,
|
|
3859
|
+
content: contentBody?.trim() ?? "",
|
|
3860
|
+
position,
|
|
3861
|
+
createdAt: now,
|
|
3862
|
+
metadata: toReadonly({}),
|
|
3863
|
+
hidden: false
|
|
3864
|
+
};
|
|
3865
|
+
messages.push(toReadonly(message));
|
|
3866
|
+
position++;
|
|
3867
|
+
}
|
|
3868
|
+
const conversation = {
|
|
3869
|
+
id: generateId(),
|
|
3870
|
+
status: "active",
|
|
3871
|
+
metadata: toReadonly({}),
|
|
3872
|
+
tags: toReadonly([]),
|
|
3873
|
+
messages: toReadonly(messages),
|
|
3874
|
+
createdAt: now,
|
|
3875
|
+
updatedAt: now
|
|
3876
|
+
};
|
|
3877
|
+
return toReadonly(conversation);
|
|
3878
|
+
}
|
|
3879
|
+
|
|
98
3880
|
// src/environment.ts
|
|
3881
|
+
function simpleTokenEstimator(message) {
|
|
3882
|
+
const text = messageText(message);
|
|
3883
|
+
return Math.ceil(text.length / 4);
|
|
3884
|
+
}
|
|
99
3885
|
var defaultConversationEnvironment = {
|
|
100
3886
|
now: () => new Date().toISOString(),
|
|
101
|
-
randomId: () => crypto.randomUUID()
|
|
3887
|
+
randomId: () => crypto.randomUUID(),
|
|
3888
|
+
estimateTokens: simpleTokenEstimator,
|
|
3889
|
+
plugins: []
|
|
102
3890
|
};
|
|
103
3891
|
function resolveConversationEnvironment(environment) {
|
|
104
3892
|
return {
|
|
105
3893
|
now: environment?.now ?? defaultConversationEnvironment.now,
|
|
106
|
-
randomId: environment?.randomId ?? defaultConversationEnvironment.randomId
|
|
3894
|
+
randomId: environment?.randomId ?? defaultConversationEnvironment.randomId,
|
|
3895
|
+
estimateTokens: environment?.estimateTokens ?? defaultConversationEnvironment.estimateTokens,
|
|
3896
|
+
plugins: [...environment?.plugins ?? defaultConversationEnvironment.plugins]
|
|
107
3897
|
};
|
|
108
3898
|
}
|
|
109
3899
|
function isConversationEnvironmentParameter(value) {
|
|
110
|
-
if (!value || typeof value !== "object")
|
|
3900
|
+
if (!value || typeof value !== "object" || value === null)
|
|
111
3901
|
return false;
|
|
112
3902
|
if ("role" in value)
|
|
113
3903
|
return false;
|
|
114
3904
|
const candidate = value;
|
|
115
|
-
return typeof candidate
|
|
3905
|
+
return typeof candidate["now"] === "function" || typeof candidate["randomId"] === "function" || typeof candidate["estimateTokens"] === "function" || Array.isArray(candidate["plugins"]) && candidate["plugins"].length > 0;
|
|
3906
|
+
}
|
|
3907
|
+
function withEnvironment(environment, fn) {
|
|
3908
|
+
return (...args) => fn(...args, environment);
|
|
116
3909
|
}
|
|
117
3910
|
|
|
118
3911
|
// src/errors.ts
|
|
@@ -120,12 +3913,12 @@ class ConversationalistError extends Error {
|
|
|
120
3913
|
code;
|
|
121
3914
|
context;
|
|
122
3915
|
cause;
|
|
123
|
-
constructor(code, message,
|
|
3916
|
+
constructor(code, message, options2) {
|
|
124
3917
|
super(message);
|
|
125
3918
|
this.name = "ConversationalistError";
|
|
126
3919
|
this.code = code;
|
|
127
|
-
this.context =
|
|
128
|
-
this.cause =
|
|
3920
|
+
this.context = options2?.context;
|
|
3921
|
+
this.cause = options2?.cause;
|
|
129
3922
|
if (Error.captureStackTrace) {
|
|
130
3923
|
Error.captureStackTrace(this, ConversationalistError);
|
|
131
3924
|
}
|
|
@@ -169,74 +3962,6 @@ function createValidationError(message, context, cause) {
|
|
|
169
3962
|
return new ConversationalistError("error:validation", message, { context, cause });
|
|
170
3963
|
}
|
|
171
3964
|
|
|
172
|
-
// src/utilities.ts
|
|
173
|
-
function pairToolCallsWithResults(messages) {
|
|
174
|
-
const pairs = [];
|
|
175
|
-
const resultsMap = new Map;
|
|
176
|
-
for (const msg of messages) {
|
|
177
|
-
if (msg.toolResult) {
|
|
178
|
-
resultsMap.set(msg.toolResult.callId, msg.toolResult);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
for (const msg of messages) {
|
|
182
|
-
if (msg.toolCall) {
|
|
183
|
-
pairs.push({
|
|
184
|
-
call: msg.toolCall,
|
|
185
|
-
result: resultsMap.get(msg.toolCall.id)
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
return pairs;
|
|
190
|
-
}
|
|
191
|
-
function toReadonly(value) {
|
|
192
|
-
return value;
|
|
193
|
-
}
|
|
194
|
-
function createMessage(props) {
|
|
195
|
-
const content = Array.isArray(props.content) ? toReadonly([...props.content]) : props.content;
|
|
196
|
-
const message = {
|
|
197
|
-
id: props.id,
|
|
198
|
-
role: props.role,
|
|
199
|
-
content,
|
|
200
|
-
position: props.position,
|
|
201
|
-
createdAt: props.createdAt,
|
|
202
|
-
metadata: toReadonly({ ...props.metadata }),
|
|
203
|
-
hidden: props.hidden,
|
|
204
|
-
toolCall: props.toolCall ? toReadonly({ ...props.toolCall }) : undefined,
|
|
205
|
-
toolResult: props.toolResult ? toReadonly({ ...props.toolResult }) : undefined,
|
|
206
|
-
tokenUsage: props.tokenUsage ? toReadonly({ ...props.tokenUsage }) : undefined,
|
|
207
|
-
goalCompleted: props.goalCompleted
|
|
208
|
-
};
|
|
209
|
-
return toReadonly(message);
|
|
210
|
-
}
|
|
211
|
-
function toMultiModalArray(input) {
|
|
212
|
-
if (typeof input === "string")
|
|
213
|
-
return [{ type: "text", text: input }];
|
|
214
|
-
return Array.isArray(input) ? input : [input];
|
|
215
|
-
}
|
|
216
|
-
function normalizeContent(content) {
|
|
217
|
-
if (content === undefined)
|
|
218
|
-
return;
|
|
219
|
-
if (typeof content === "string")
|
|
220
|
-
return content;
|
|
221
|
-
return Array.isArray(content) ? content : [content];
|
|
222
|
-
}
|
|
223
|
-
function messageParts(message) {
|
|
224
|
-
if (typeof message.content === "string") {
|
|
225
|
-
return message.content ? [{ type: "text", text: message.content }] : [];
|
|
226
|
-
}
|
|
227
|
-
return message.content;
|
|
228
|
-
}
|
|
229
|
-
function messageText(message, joiner = `
|
|
230
|
-
|
|
231
|
-
`) {
|
|
232
|
-
if (typeof message.content === "string")
|
|
233
|
-
return message.content;
|
|
234
|
-
return messageParts(message).filter((p) => p.type === "text").map((p) => p.type === "text" ? p.text : "").join(joiner);
|
|
235
|
-
}
|
|
236
|
-
function messageHasImages(message) {
|
|
237
|
-
return messageParts(message).some((p) => p.type === "image");
|
|
238
|
-
}
|
|
239
|
-
|
|
240
3965
|
// src/conversation.ts
|
|
241
3966
|
var buildToolUseIndex = (messages) => messages.reduce((index, message) => {
|
|
242
3967
|
if (message.role === "tool-use" && message.toolCall) {
|
|
@@ -267,15 +3992,15 @@ function partitionAppendArgs(args) {
|
|
|
267
3992
|
}
|
|
268
3993
|
return { inputs: args };
|
|
269
3994
|
}
|
|
270
|
-
function createConversation(
|
|
3995
|
+
function createConversation(options2, environment) {
|
|
271
3996
|
const resolvedEnvironment = resolveConversationEnvironment(environment);
|
|
272
3997
|
const now = resolvedEnvironment.now();
|
|
273
3998
|
const conv = {
|
|
274
|
-
id:
|
|
275
|
-
title:
|
|
276
|
-
status:
|
|
277
|
-
metadata: { ...
|
|
278
|
-
tags: [...
|
|
3999
|
+
id: options2?.id ?? resolvedEnvironment.randomId(),
|
|
4000
|
+
title: options2?.title,
|
|
4001
|
+
status: options2?.status ?? "active",
|
|
4002
|
+
metadata: { ...options2?.metadata ?? {} },
|
|
4003
|
+
tags: [...options2?.tags ?? []],
|
|
279
4004
|
messages: [],
|
|
280
4005
|
createdAt: now,
|
|
281
4006
|
updatedAt: now
|
|
@@ -289,24 +4014,25 @@ function appendMessages(conversation, ...args) {
|
|
|
289
4014
|
const startPosition = conversation.messages.length;
|
|
290
4015
|
const initialToolUses = buildToolUseIndex(conversation.messages);
|
|
291
4016
|
const { messages } = inputs.reduce((state, input, index) => {
|
|
292
|
-
|
|
293
|
-
|
|
4017
|
+
const processedInput = resolvedEnvironment.plugins.reduce((acc, plugin) => plugin(acc), input);
|
|
4018
|
+
if (processedInput.role === "tool-result" && processedInput.toolResult) {
|
|
4019
|
+
assertToolReference(state.toolUses, processedInput.toolResult.callId);
|
|
294
4020
|
}
|
|
295
|
-
const normalizedContent = normalizeContent(
|
|
4021
|
+
const normalizedContent = normalizeContent(processedInput.content);
|
|
296
4022
|
const message = createMessage({
|
|
297
4023
|
id: resolvedEnvironment.randomId(),
|
|
298
|
-
role:
|
|
4024
|
+
role: processedInput.role,
|
|
299
4025
|
content: normalizedContent,
|
|
300
4026
|
position: startPosition + index,
|
|
301
4027
|
createdAt: now,
|
|
302
|
-
metadata: { ...
|
|
303
|
-
hidden:
|
|
304
|
-
toolCall:
|
|
305
|
-
toolResult:
|
|
306
|
-
tokenUsage:
|
|
307
|
-
goalCompleted:
|
|
4028
|
+
metadata: { ...processedInput.metadata ?? {} },
|
|
4029
|
+
hidden: processedInput.hidden ?? false,
|
|
4030
|
+
toolCall: processedInput.toolCall,
|
|
4031
|
+
toolResult: processedInput.toolResult,
|
|
4032
|
+
tokenUsage: processedInput.tokenUsage,
|
|
4033
|
+
goalCompleted: processedInput.goalCompleted
|
|
308
4034
|
});
|
|
309
|
-
const toolUses =
|
|
4035
|
+
const toolUses = processedInput.role === "tool-use" && processedInput.toolCall ? registerToolUse(state.toolUses, processedInput.toolCall) : state.toolUses;
|
|
310
4036
|
return {
|
|
311
4037
|
toolUses,
|
|
312
4038
|
messages: [...state.messages, message]
|
|
@@ -328,8 +4054,8 @@ function appendAssistantMessage(conversation, content, metadata, environment) {
|
|
|
328
4054
|
function appendSystemMessage(conversation, content, metadata, environment) {
|
|
329
4055
|
return environment ? appendMessages(conversation, { role: "system", content, metadata }, environment) : appendMessages(conversation, { role: "system", content, metadata });
|
|
330
4056
|
}
|
|
331
|
-
function getConversationMessages(conversation,
|
|
332
|
-
const includeHidden =
|
|
4057
|
+
function getConversationMessages(conversation, options2) {
|
|
4058
|
+
const includeHidden = options2?.includeHidden ?? false;
|
|
333
4059
|
return includeHidden ? [...conversation.messages] : conversation.messages.filter((m) => !m.hidden);
|
|
334
4060
|
}
|
|
335
4061
|
function getMessageAtPosition(conversation, position) {
|
|
@@ -583,73 +4309,57 @@ function toChatMessages(conversation) {
|
|
|
583
4309
|
return result;
|
|
584
4310
|
}
|
|
585
4311
|
// src/context.ts
|
|
586
|
-
function
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
return filtered.slice(-count);
|
|
597
|
-
}
|
|
598
|
-
function truncateFromPosition(conversation, position, options, environment) {
|
|
599
|
-
const preserveSystem = options?.preserveSystemMessages ?? true;
|
|
600
|
-
const resolvedEnvironment = resolveConversationEnvironment(environment);
|
|
601
|
-
const now = resolvedEnvironment.now();
|
|
602
|
-
const systemMessages = preserveSystem ? conversation.messages.filter((m) => m.role === "system" && m.position < position) : [];
|
|
603
|
-
const keptMessages = conversation.messages.filter((m) => m.position >= position);
|
|
604
|
-
const allMessages = [...systemMessages, ...keptMessages];
|
|
605
|
-
const renumbered = allMessages.map((message, index) => createMessage({
|
|
606
|
-
id: message.id,
|
|
607
|
-
role: message.role,
|
|
608
|
-
content: typeof message.content === "string" ? message.content : [...message.content],
|
|
609
|
-
position: index,
|
|
610
|
-
createdAt: message.createdAt,
|
|
611
|
-
metadata: { ...message.metadata },
|
|
612
|
-
hidden: message.hidden,
|
|
613
|
-
toolCall: message.toolCall ? { ...message.toolCall } : undefined,
|
|
614
|
-
toolResult: message.toolResult ? { ...message.toolResult } : undefined,
|
|
615
|
-
tokenUsage: message.tokenUsage ? { ...message.tokenUsage } : undefined,
|
|
616
|
-
goalCompleted: message.goalCompleted
|
|
617
|
-
}));
|
|
618
|
-
return toReadonly({
|
|
619
|
-
...conversation,
|
|
620
|
-
messages: renumbered,
|
|
621
|
-
updatedAt: now
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
function estimateConversationTokens(conversation, estimateTokens) {
|
|
625
|
-
return conversation.messages.reduce((total, message) => total + estimateTokens(message), 0);
|
|
626
|
-
}
|
|
627
|
-
function simpleTokenEstimator(message) {
|
|
628
|
-
const text = messageText(message);
|
|
629
|
-
return Math.ceil(text.length / 4);
|
|
4312
|
+
function estimateConversationTokens(conversation, estimateTokens, environment) {
|
|
4313
|
+
let estimator = estimateTokens;
|
|
4314
|
+
let env = environment;
|
|
4315
|
+
if (!environment && estimateTokens && isConversationEnvironmentParameter(estimateTokens)) {
|
|
4316
|
+
env = estimateTokens;
|
|
4317
|
+
estimator = undefined;
|
|
4318
|
+
}
|
|
4319
|
+
const resolvedEnvironment = resolveConversationEnvironment(env);
|
|
4320
|
+
const finalEstimator = typeof estimator === "function" ? estimator : resolvedEnvironment.estimateTokens;
|
|
4321
|
+
return conversation.messages.reduce((total, message) => total + finalEstimator(message), 0);
|
|
630
4322
|
}
|
|
631
|
-
function truncateToTokenLimit(conversation, maxTokens,
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
4323
|
+
function truncateToTokenLimit(conversation, maxTokens, optionsOrEstimator, environment) {
|
|
4324
|
+
let options2 = {};
|
|
4325
|
+
let env = environment;
|
|
4326
|
+
if (typeof optionsOrEstimator === "function") {
|
|
4327
|
+
options2 = { estimateTokens: optionsOrEstimator };
|
|
4328
|
+
} else if (optionsOrEstimator) {
|
|
4329
|
+
if (!environment && isConversationEnvironmentParameter(optionsOrEstimator)) {
|
|
4330
|
+
const candidate = optionsOrEstimator;
|
|
4331
|
+
const hasEnvFields = !!(candidate["now"] || candidate["randomId"] || Array.isArray(candidate["plugins"]) && candidate["plugins"].length > 0);
|
|
4332
|
+
if (hasEnvFields) {
|
|
4333
|
+
env = optionsOrEstimator;
|
|
4334
|
+
} else {
|
|
4335
|
+
options2 = optionsOrEstimator;
|
|
4336
|
+
}
|
|
4337
|
+
} else {
|
|
4338
|
+
options2 = optionsOrEstimator;
|
|
4339
|
+
}
|
|
4340
|
+
}
|
|
4341
|
+
const resolvedEnvironment = resolveConversationEnvironment(env);
|
|
4342
|
+
const estimator = options2.estimateTokens ?? resolvedEnvironment.estimateTokens;
|
|
4343
|
+
const preserveSystem = options2.preserveSystemMessages ?? true;
|
|
4344
|
+
const preserveLastN = options2.preserveLastN ?? 0;
|
|
4345
|
+
const currentTokens = estimateConversationTokens(conversation, estimator, resolvedEnvironment);
|
|
635
4346
|
if (currentTokens <= maxTokens) {
|
|
636
4347
|
return conversation;
|
|
637
4348
|
}
|
|
638
|
-
const resolvedEnvironment = resolveConversationEnvironment(environment);
|
|
639
4349
|
const now = resolvedEnvironment.now();
|
|
640
4350
|
const systemMessages = preserveSystem ? conversation.messages.filter((m) => m.role === "system") : [];
|
|
641
4351
|
const nonSystemMessages = conversation.messages.filter((m) => m.role !== "system");
|
|
642
4352
|
const protectedMessages = preserveLastN > 0 ? nonSystemMessages.slice(-preserveLastN) : [];
|
|
643
4353
|
const removableMessages = preserveLastN > 0 ? nonSystemMessages.slice(0, -preserveLastN) : nonSystemMessages;
|
|
644
|
-
const systemTokens = systemMessages.reduce((sum, m) => sum +
|
|
645
|
-
const protectedTokens = protectedMessages.reduce((sum, m) => sum +
|
|
4354
|
+
const systemTokens = systemMessages.reduce((sum, m) => sum + estimator(m), 0);
|
|
4355
|
+
const protectedTokens = protectedMessages.reduce((sum, m) => sum + estimator(m), 0);
|
|
646
4356
|
const availableTokens = maxTokens - systemTokens - protectedTokens;
|
|
647
4357
|
if (availableTokens <= 0) {
|
|
648
4358
|
const allMessages2 = [...systemMessages, ...protectedMessages];
|
|
649
4359
|
const renumbered2 = allMessages2.map((message, index) => createMessage({
|
|
650
4360
|
id: message.id,
|
|
651
4361
|
role: message.role,
|
|
652
|
-
content:
|
|
4362
|
+
content: copyContent(message.content),
|
|
653
4363
|
position: index,
|
|
654
4364
|
createdAt: message.createdAt,
|
|
655
4365
|
metadata: { ...message.metadata },
|
|
@@ -669,7 +4379,7 @@ function truncateToTokenLimit(conversation, maxTokens, estimateTokens, options,
|
|
|
669
4379
|
let usedTokens = 0;
|
|
670
4380
|
for (let i = removableMessages.length - 1;i >= 0; i--) {
|
|
671
4381
|
const message = removableMessages[i];
|
|
672
|
-
const messageTokens =
|
|
4382
|
+
const messageTokens = estimator(message);
|
|
673
4383
|
if (usedTokens + messageTokens <= availableTokens) {
|
|
674
4384
|
keptRemovable.unshift(message);
|
|
675
4385
|
usedTokens += messageTokens;
|
|
@@ -682,7 +4392,45 @@ function truncateToTokenLimit(conversation, maxTokens, estimateTokens, options,
|
|
|
682
4392
|
const renumbered = allMessages.map((message, index) => createMessage({
|
|
683
4393
|
id: message.id,
|
|
684
4394
|
role: message.role,
|
|
685
|
-
content:
|
|
4395
|
+
content: copyContent(message.content),
|
|
4396
|
+
position: index,
|
|
4397
|
+
createdAt: message.createdAt,
|
|
4398
|
+
metadata: { ...message.metadata },
|
|
4399
|
+
hidden: message.hidden,
|
|
4400
|
+
toolCall: message.toolCall ? { ...message.toolCall } : undefined,
|
|
4401
|
+
toolResult: message.toolResult ? { ...message.toolResult } : undefined,
|
|
4402
|
+
tokenUsage: message.tokenUsage ? { ...message.tokenUsage } : undefined,
|
|
4403
|
+
goalCompleted: message.goalCompleted
|
|
4404
|
+
}));
|
|
4405
|
+
return toReadonly({
|
|
4406
|
+
...conversation,
|
|
4407
|
+
messages: renumbered,
|
|
4408
|
+
updatedAt: now
|
|
4409
|
+
});
|
|
4410
|
+
}
|
|
4411
|
+
function getRecentMessages(conversation, count, options2) {
|
|
4412
|
+
const includeHidden = options2?.includeHidden ?? false;
|
|
4413
|
+
const includeSystem = options2?.includeSystem ?? false;
|
|
4414
|
+
const filtered = conversation.messages.filter((m) => {
|
|
4415
|
+
if (!includeHidden && m.hidden)
|
|
4416
|
+
return false;
|
|
4417
|
+
if (!includeSystem && m.role === "system")
|
|
4418
|
+
return false;
|
|
4419
|
+
return true;
|
|
4420
|
+
});
|
|
4421
|
+
return filtered.slice(-count);
|
|
4422
|
+
}
|
|
4423
|
+
function truncateFromPosition(conversation, position, options2, environment) {
|
|
4424
|
+
const preserveSystem = options2?.preserveSystemMessages ?? true;
|
|
4425
|
+
const resolvedEnvironment = resolveConversationEnvironment(environment);
|
|
4426
|
+
const now = resolvedEnvironment.now();
|
|
4427
|
+
const systemMessages = preserveSystem ? conversation.messages.filter((m) => m.role === "system" && m.position < position) : [];
|
|
4428
|
+
const keptMessages = conversation.messages.filter((m) => m.position >= position);
|
|
4429
|
+
const allMessages = [...systemMessages, ...keptMessages];
|
|
4430
|
+
const renumbered = allMessages.map((message, index) => createMessage({
|
|
4431
|
+
id: message.id,
|
|
4432
|
+
role: message.role,
|
|
4433
|
+
content: copyContent(message.content),
|
|
686
4434
|
position: index,
|
|
687
4435
|
createdAt: message.createdAt,
|
|
688
4436
|
metadata: { ...message.metadata },
|
|
@@ -758,7 +4506,7 @@ function updateStreamingMessage(conversation, messageId, content, environment) {
|
|
|
758
4506
|
updatedAt: now
|
|
759
4507
|
});
|
|
760
4508
|
}
|
|
761
|
-
function finalizeStreamingMessage(conversation, messageId,
|
|
4509
|
+
function finalizeStreamingMessage(conversation, messageId, options2, environment) {
|
|
762
4510
|
const resolvedEnvironment = resolveConversationEnvironment(environment);
|
|
763
4511
|
const now = resolvedEnvironment.now();
|
|
764
4512
|
const messageIndex = conversation.messages.findIndex((m) => m.id === messageId);
|
|
@@ -767,7 +4515,7 @@ function finalizeStreamingMessage(conversation, messageId, options, environment)
|
|
|
767
4515
|
}
|
|
768
4516
|
const original = conversation.messages[messageIndex];
|
|
769
4517
|
const { [STREAMING_KEY]: _, ...restMetadata } = original.metadata;
|
|
770
|
-
const finalMetadata = { ...restMetadata, ...
|
|
4518
|
+
const finalMetadata = { ...restMetadata, ...options2?.metadata ?? {} };
|
|
771
4519
|
const updated = createMessage({
|
|
772
4520
|
id: original.id,
|
|
773
4521
|
role: original.role,
|
|
@@ -778,7 +4526,7 @@ function finalizeStreamingMessage(conversation, messageId, options, environment)
|
|
|
778
4526
|
hidden: original.hidden,
|
|
779
4527
|
toolCall: original.toolCall ? { ...original.toolCall } : undefined,
|
|
780
4528
|
toolResult: original.toolResult ? { ...original.toolResult } : undefined,
|
|
781
|
-
tokenUsage:
|
|
4529
|
+
tokenUsage: options2?.tokenUsage ? { ...options2.tokenUsage } : undefined,
|
|
782
4530
|
goalCompleted: original.goalCompleted
|
|
783
4531
|
});
|
|
784
4532
|
const messages = conversation.messages.map((m, i) => i === messageIndex ? updated : m);
|
|
@@ -863,20 +4611,20 @@ function createDraft(initial) {
|
|
|
863
4611
|
current = updateStreamingMessage(current, messageId, content);
|
|
864
4612
|
return draft;
|
|
865
4613
|
},
|
|
866
|
-
finalizeStreamingMessage: (messageId,
|
|
867
|
-
current = finalizeStreamingMessage(current, messageId,
|
|
4614
|
+
finalizeStreamingMessage: (messageId, options2) => {
|
|
4615
|
+
current = finalizeStreamingMessage(current, messageId, options2);
|
|
868
4616
|
return draft;
|
|
869
4617
|
},
|
|
870
4618
|
cancelStreamingMessage: (messageId) => {
|
|
871
4619
|
current = cancelStreamingMessage(current, messageId);
|
|
872
4620
|
return draft;
|
|
873
4621
|
},
|
|
874
|
-
truncateFromPosition: (position,
|
|
875
|
-
current = truncateFromPosition(current, position,
|
|
4622
|
+
truncateFromPosition: (position, options2) => {
|
|
4623
|
+
current = truncateFromPosition(current, position, options2);
|
|
876
4624
|
return draft;
|
|
877
4625
|
},
|
|
878
|
-
truncateToTokenLimit: (maxTokens,
|
|
879
|
-
current = truncateToTokenLimit(current, maxTokens,
|
|
4626
|
+
truncateToTokenLimit: (maxTokens, options2) => {
|
|
4627
|
+
current = truncateToTokenLimit(current, maxTokens, options2);
|
|
880
4628
|
return draft;
|
|
881
4629
|
}
|
|
882
4630
|
};
|
|
@@ -893,7 +4641,291 @@ function withConversation(conversation, fn) {
|
|
|
893
4641
|
function pipeConversation(conversation, ...fns) {
|
|
894
4642
|
return fns.reduce((current, fn) => fn(current), conversation);
|
|
895
4643
|
}
|
|
4644
|
+
// src/history.ts
|
|
4645
|
+
class ConversationHistoryEvent extends CustomEvent {
|
|
4646
|
+
constructor(type, detail) {
|
|
4647
|
+
super(type, { detail });
|
|
4648
|
+
}
|
|
4649
|
+
}
|
|
4650
|
+
|
|
4651
|
+
class ConversationHistory extends EventTarget {
|
|
4652
|
+
currentNode;
|
|
4653
|
+
environment;
|
|
4654
|
+
constructor(initial, environment) {
|
|
4655
|
+
super();
|
|
4656
|
+
this.environment = resolveConversationEnvironment(environment);
|
|
4657
|
+
this.currentNode = {
|
|
4658
|
+
conversation: initial,
|
|
4659
|
+
parent: null,
|
|
4660
|
+
children: []
|
|
4661
|
+
};
|
|
4662
|
+
}
|
|
4663
|
+
notifyChange(type) {
|
|
4664
|
+
const detail = {
|
|
4665
|
+
type,
|
|
4666
|
+
conversation: this.current
|
|
4667
|
+
};
|
|
4668
|
+
this.dispatchEvent(new ConversationHistoryEvent("change", detail));
|
|
4669
|
+
this.dispatchEvent(new ConversationHistoryEvent(type, detail));
|
|
4670
|
+
}
|
|
4671
|
+
addEventListener(type, callback, options2) {
|
|
4672
|
+
if (!callback)
|
|
4673
|
+
return;
|
|
4674
|
+
super.addEventListener(type, callback, options2);
|
|
4675
|
+
const unsubscribe = () => this.removeEventListener(type, callback, options2);
|
|
4676
|
+
return unsubscribe;
|
|
4677
|
+
}
|
|
4678
|
+
subscribe(run) {
|
|
4679
|
+
run(this.current);
|
|
4680
|
+
const handler = (event) => {
|
|
4681
|
+
if (event instanceof ConversationHistoryEvent) {
|
|
4682
|
+
run(event.detail.conversation);
|
|
4683
|
+
}
|
|
4684
|
+
};
|
|
4685
|
+
const unsubscribe = this.addEventListener("change", handler);
|
|
4686
|
+
return unsubscribe || (() => {});
|
|
4687
|
+
}
|
|
4688
|
+
getSnapshot() {
|
|
4689
|
+
return this.current;
|
|
4690
|
+
}
|
|
4691
|
+
get current() {
|
|
4692
|
+
return this.currentNode.conversation;
|
|
4693
|
+
}
|
|
4694
|
+
get canUndo() {
|
|
4695
|
+
return this.currentNode.parent !== null;
|
|
4696
|
+
}
|
|
4697
|
+
get canRedo() {
|
|
4698
|
+
return this.currentNode.children.length > 0;
|
|
4699
|
+
}
|
|
4700
|
+
get env() {
|
|
4701
|
+
return this.environment;
|
|
4702
|
+
}
|
|
4703
|
+
get branchCount() {
|
|
4704
|
+
return this.currentNode.parent ? this.currentNode.parent.children.length : 1;
|
|
4705
|
+
}
|
|
4706
|
+
get branchIndex() {
|
|
4707
|
+
if (!this.currentNode.parent)
|
|
4708
|
+
return 0;
|
|
4709
|
+
return this.currentNode.parent.children.indexOf(this.currentNode);
|
|
4710
|
+
}
|
|
4711
|
+
get redoCount() {
|
|
4712
|
+
return this.currentNode.children.length;
|
|
4713
|
+
}
|
|
4714
|
+
push(next) {
|
|
4715
|
+
const newNode = {
|
|
4716
|
+
conversation: next,
|
|
4717
|
+
parent: this.currentNode,
|
|
4718
|
+
children: []
|
|
4719
|
+
};
|
|
4720
|
+
this.currentNode.children.push(newNode);
|
|
4721
|
+
this.currentNode = newNode;
|
|
4722
|
+
this.notifyChange("push");
|
|
4723
|
+
}
|
|
4724
|
+
undo() {
|
|
4725
|
+
if (this.currentNode.parent) {
|
|
4726
|
+
this.currentNode = this.currentNode.parent;
|
|
4727
|
+
this.notifyChange("undo");
|
|
4728
|
+
return this.current;
|
|
4729
|
+
}
|
|
4730
|
+
return;
|
|
4731
|
+
}
|
|
4732
|
+
redo(childIndex = 0) {
|
|
4733
|
+
const next = this.currentNode.children[childIndex];
|
|
4734
|
+
if (next) {
|
|
4735
|
+
this.currentNode = next;
|
|
4736
|
+
this.notifyChange("redo");
|
|
4737
|
+
return this.current;
|
|
4738
|
+
}
|
|
4739
|
+
return;
|
|
4740
|
+
}
|
|
4741
|
+
switchToBranch(index) {
|
|
4742
|
+
if (this.currentNode.parent) {
|
|
4743
|
+
const target = this.currentNode.parent.children[index];
|
|
4744
|
+
if (target) {
|
|
4745
|
+
this.currentNode = target;
|
|
4746
|
+
this.notifyChange("switch");
|
|
4747
|
+
return this.current;
|
|
4748
|
+
}
|
|
4749
|
+
}
|
|
4750
|
+
return;
|
|
4751
|
+
}
|
|
4752
|
+
getPath() {
|
|
4753
|
+
const path = [];
|
|
4754
|
+
let curr = this.currentNode;
|
|
4755
|
+
while (curr) {
|
|
4756
|
+
path.unshift(curr.conversation);
|
|
4757
|
+
curr = curr.parent;
|
|
4758
|
+
}
|
|
4759
|
+
return path;
|
|
4760
|
+
}
|
|
4761
|
+
getMessages(options2) {
|
|
4762
|
+
return getConversationMessages(this.current, options2);
|
|
4763
|
+
}
|
|
4764
|
+
getMessageAtPosition(position) {
|
|
4765
|
+
return getMessageAtPosition(this.current, position);
|
|
4766
|
+
}
|
|
4767
|
+
getMessageByIdentifier(id) {
|
|
4768
|
+
return getMessageByIdentifier(this.current, id);
|
|
4769
|
+
}
|
|
4770
|
+
searchMessages(predicate) {
|
|
4771
|
+
return searchConversationMessages(this.current, predicate);
|
|
4772
|
+
}
|
|
4773
|
+
getStatistics() {
|
|
4774
|
+
return computeConversationStatistics(this.current);
|
|
4775
|
+
}
|
|
4776
|
+
hasSystemMessage() {
|
|
4777
|
+
return hasSystemMessage(this.current);
|
|
4778
|
+
}
|
|
4779
|
+
getFirstSystemMessage() {
|
|
4780
|
+
return getFirstSystemMessage(this.current);
|
|
4781
|
+
}
|
|
4782
|
+
getSystemMessages() {
|
|
4783
|
+
return getSystemMessages(this.current);
|
|
4784
|
+
}
|
|
4785
|
+
serialize() {
|
|
4786
|
+
return serializeConversation(this.current);
|
|
4787
|
+
}
|
|
4788
|
+
toChatMessages() {
|
|
4789
|
+
return toChatMessages(this.current);
|
|
4790
|
+
}
|
|
4791
|
+
estimateTokens(estimator) {
|
|
4792
|
+
return estimateConversationTokens(this.current, estimator, this.env);
|
|
4793
|
+
}
|
|
4794
|
+
getRecentMessages(count, options2) {
|
|
4795
|
+
return getRecentMessages(this.current, count, options2);
|
|
4796
|
+
}
|
|
4797
|
+
getStreamingMessage() {
|
|
4798
|
+
return getStreamingMessage(this.current);
|
|
4799
|
+
}
|
|
4800
|
+
appendMessages(...inputs) {
|
|
4801
|
+
this.push(appendMessages(this.current, ...inputs, this.env));
|
|
4802
|
+
}
|
|
4803
|
+
appendUserMessage(content, metadata) {
|
|
4804
|
+
this.push(appendUserMessage(this.current, content, metadata, this.env));
|
|
4805
|
+
}
|
|
4806
|
+
appendAssistantMessage(content, metadata) {
|
|
4807
|
+
this.push(appendAssistantMessage(this.current, content, metadata, this.env));
|
|
4808
|
+
}
|
|
4809
|
+
appendSystemMessage(content, metadata) {
|
|
4810
|
+
this.push(appendSystemMessage(this.current, content, metadata, this.env));
|
|
4811
|
+
}
|
|
4812
|
+
prependSystemMessage(content, metadata) {
|
|
4813
|
+
this.push(prependSystemMessage(this.current, content, metadata, this.env));
|
|
4814
|
+
}
|
|
4815
|
+
replaceSystemMessage(content, metadata) {
|
|
4816
|
+
this.push(replaceSystemMessage(this.current, content, metadata, this.env));
|
|
4817
|
+
}
|
|
4818
|
+
collapseSystemMessages() {
|
|
4819
|
+
this.push(collapseSystemMessages(this.current, this.env));
|
|
4820
|
+
}
|
|
4821
|
+
redactMessageAtPosition(position, placeholder) {
|
|
4822
|
+
this.push(redactMessageAtPosition(this.current, position, placeholder, this.env));
|
|
4823
|
+
}
|
|
4824
|
+
truncateFromPosition(position, options2) {
|
|
4825
|
+
this.push(truncateFromPosition(this.current, position, options2, this.env));
|
|
4826
|
+
}
|
|
4827
|
+
truncateToTokenLimit(maxTokens, options2) {
|
|
4828
|
+
this.push(truncateToTokenLimit(this.current, maxTokens, options2, this.env));
|
|
4829
|
+
}
|
|
4830
|
+
appendStreamingMessage(role, metadata) {
|
|
4831
|
+
const { conversation, messageId } = appendStreamingMessage(this.current, role, metadata, this.env);
|
|
4832
|
+
this.push(conversation);
|
|
4833
|
+
return messageId;
|
|
4834
|
+
}
|
|
4835
|
+
updateStreamingMessage(messageId, content) {
|
|
4836
|
+
this.push(updateStreamingMessage(this.current, messageId, content, this.env));
|
|
4837
|
+
}
|
|
4838
|
+
finalizeStreamingMessage(messageId, options2) {
|
|
4839
|
+
this.push(finalizeStreamingMessage(this.current, messageId, options2, this.env));
|
|
4840
|
+
}
|
|
4841
|
+
cancelStreamingMessage(messageId) {
|
|
4842
|
+
this.push(cancelStreamingMessage(this.current, messageId, this.env));
|
|
4843
|
+
}
|
|
4844
|
+
toJSON() {
|
|
4845
|
+
const getPath = (node) => {
|
|
4846
|
+
const path = [];
|
|
4847
|
+
let curr = node;
|
|
4848
|
+
while (curr.parent) {
|
|
4849
|
+
path.unshift(curr.parent.children.indexOf(curr));
|
|
4850
|
+
curr = curr.parent;
|
|
4851
|
+
}
|
|
4852
|
+
return path;
|
|
4853
|
+
};
|
|
4854
|
+
const serializeNode = (node) => ({
|
|
4855
|
+
conversation: serializeConversation(node.conversation),
|
|
4856
|
+
children: node.children.map(serializeNode)
|
|
4857
|
+
});
|
|
4858
|
+
let root = this.currentNode;
|
|
4859
|
+
while (root.parent) {
|
|
4860
|
+
root = root.parent;
|
|
4861
|
+
}
|
|
4862
|
+
return {
|
|
4863
|
+
root: serializeNode(root),
|
|
4864
|
+
currentPath: getPath(this.currentNode)
|
|
4865
|
+
};
|
|
4866
|
+
}
|
|
4867
|
+
static from(json, environment) {
|
|
4868
|
+
const rootConv = deserializeConversation(json.root.conversation);
|
|
4869
|
+
const history = new ConversationHistory(rootConv, environment);
|
|
4870
|
+
const buildTree = (nodeJSON, parentNode) => {
|
|
4871
|
+
const nodeConv = deserializeConversation(nodeJSON.conversation);
|
|
4872
|
+
const node = {
|
|
4873
|
+
conversation: nodeConv,
|
|
4874
|
+
parent: parentNode,
|
|
4875
|
+
children: []
|
|
4876
|
+
};
|
|
4877
|
+
node.children = nodeJSON.children.map((child) => buildTree(child, node));
|
|
4878
|
+
return node;
|
|
4879
|
+
};
|
|
4880
|
+
const h = history;
|
|
4881
|
+
const rootNode = h.currentNode;
|
|
4882
|
+
rootNode.children = json.root.children.map((child) => buildTree(child, rootNode));
|
|
4883
|
+
let current = rootNode;
|
|
4884
|
+
for (const index of json.currentPath) {
|
|
4885
|
+
const target = current.children[index];
|
|
4886
|
+
if (target) {
|
|
4887
|
+
current = target;
|
|
4888
|
+
}
|
|
4889
|
+
}
|
|
4890
|
+
h.currentNode = current;
|
|
4891
|
+
return history;
|
|
4892
|
+
}
|
|
4893
|
+
bind(fn) {
|
|
4894
|
+
return bindToConversationHistory(this, fn);
|
|
4895
|
+
}
|
|
4896
|
+
[Symbol.dispose]() {
|
|
4897
|
+
let root = this.currentNode;
|
|
4898
|
+
while (root?.parent) {
|
|
4899
|
+
root = root.parent;
|
|
4900
|
+
}
|
|
4901
|
+
const clearNode = (node) => {
|
|
4902
|
+
for (const child of node.children) {
|
|
4903
|
+
clearNode(child);
|
|
4904
|
+
}
|
|
4905
|
+
node.children = [];
|
|
4906
|
+
const n = node;
|
|
4907
|
+
n.parent = null;
|
|
4908
|
+
n.conversation = null;
|
|
4909
|
+
};
|
|
4910
|
+
if (root)
|
|
4911
|
+
clearNode(root);
|
|
4912
|
+
}
|
|
4913
|
+
}
|
|
4914
|
+
function bindToConversationHistory(history, fn) {
|
|
4915
|
+
return (...args) => {
|
|
4916
|
+
const boundFn = fn;
|
|
4917
|
+
const result = boundFn(history.current, ...args, history.env);
|
|
4918
|
+
if (isConversation(result)) {
|
|
4919
|
+
history.push(result);
|
|
4920
|
+
}
|
|
4921
|
+
return result;
|
|
4922
|
+
};
|
|
4923
|
+
}
|
|
4924
|
+
function isConversation(value) {
|
|
4925
|
+
return value !== null && typeof value === "object" && typeof value.id === "string" && typeof value.status === "string" && value.metadata !== null && typeof value.metadata === "object" && Array.isArray(value.tags) && Array.isArray(value.messages) && typeof value.createdAt === "string" && typeof value.updatedAt === "string";
|
|
4926
|
+
}
|
|
896
4927
|
export {
|
|
4928
|
+
withEnvironment,
|
|
897
4929
|
withConversation,
|
|
898
4930
|
updateStreamingMessage,
|
|
899
4931
|
truncateToTokenLimit,
|
|
@@ -902,6 +4934,7 @@ export {
|
|
|
902
4934
|
toolCallSchema,
|
|
903
4935
|
tokenUsageSchema,
|
|
904
4936
|
toMultiModalArray,
|
|
4937
|
+
toMarkdown,
|
|
905
4938
|
toChatMessages,
|
|
906
4939
|
simpleTokenEstimator,
|
|
907
4940
|
serializeConversation,
|
|
@@ -925,6 +4958,7 @@ export {
|
|
|
925
4958
|
getMessageAtPosition,
|
|
926
4959
|
getFirstSystemMessage,
|
|
927
4960
|
getConversationMessages,
|
|
4961
|
+
fromMarkdown,
|
|
928
4962
|
finalizeStreamingMessage,
|
|
929
4963
|
estimateConversationTokens,
|
|
930
4964
|
deserializeConversation,
|
|
@@ -945,12 +4979,15 @@ export {
|
|
|
945
4979
|
computeConversationStatistics,
|
|
946
4980
|
collapseSystemMessages,
|
|
947
4981
|
cancelStreamingMessage,
|
|
4982
|
+
bindToConversationHistory,
|
|
948
4983
|
appendUserMessage,
|
|
949
4984
|
appendSystemMessage,
|
|
950
4985
|
appendStreamingMessage,
|
|
951
4986
|
appendMessages,
|
|
952
4987
|
appendAssistantMessage,
|
|
953
|
-
|
|
4988
|
+
MarkdownParseError,
|
|
4989
|
+
ConversationalistError,
|
|
4990
|
+
ConversationHistory
|
|
954
4991
|
};
|
|
955
4992
|
|
|
956
|
-
//# debugId=
|
|
4993
|
+
//# debugId=50FF32F5809AA07D64756E2164756E21
|