@sleekcms/client 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -1
- package/index.cjs +9 -8
- package/index.d.cts +6 -3
- package/index.d.ts +6 -3
- package/index.global.js +1824 -0
- package/index.global.js.map +1 -0
- package/index.global.min.js +2 -0
- package/index.global.min.js.map +1 -0
- package/index.mjs +9 -8
- package/package.json +8 -2
package/index.global.js
ADDED
|
@@ -0,0 +1,1824 @@
|
|
|
1
|
+
var SleekCMS = (() => {
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
31
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
+
|
|
33
|
+
// node_modules/jmespath/jmespath.js
|
|
34
|
+
var require_jmespath = __commonJS({
|
|
35
|
+
"node_modules/jmespath/jmespath.js"(exports) {
|
|
36
|
+
(function(exports2) {
|
|
37
|
+
"use strict";
|
|
38
|
+
function isArray(obj) {
|
|
39
|
+
if (obj !== null) {
|
|
40
|
+
return Object.prototype.toString.call(obj) === "[object Array]";
|
|
41
|
+
} else {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function isObject(obj) {
|
|
46
|
+
if (obj !== null) {
|
|
47
|
+
return Object.prototype.toString.call(obj) === "[object Object]";
|
|
48
|
+
} else {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function strictDeepEqual(first, second) {
|
|
53
|
+
if (first === second) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
var firstType = Object.prototype.toString.call(first);
|
|
57
|
+
if (firstType !== Object.prototype.toString.call(second)) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
if (isArray(first) === true) {
|
|
61
|
+
if (first.length !== second.length) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
for (var i = 0; i < first.length; i++) {
|
|
65
|
+
if (strictDeepEqual(first[i], second[i]) === false) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
if (isObject(first) === true) {
|
|
72
|
+
var keysSeen = {};
|
|
73
|
+
for (var key in first) {
|
|
74
|
+
if (hasOwnProperty.call(first, key)) {
|
|
75
|
+
if (strictDeepEqual(first[key], second[key]) === false) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
keysSeen[key] = true;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
for (var key2 in second) {
|
|
82
|
+
if (hasOwnProperty.call(second, key2)) {
|
|
83
|
+
if (keysSeen[key2] !== true) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
function isFalse(obj) {
|
|
93
|
+
if (obj === "" || obj === false || obj === null) {
|
|
94
|
+
return true;
|
|
95
|
+
} else if (isArray(obj) && obj.length === 0) {
|
|
96
|
+
return true;
|
|
97
|
+
} else if (isObject(obj)) {
|
|
98
|
+
for (var key in obj) {
|
|
99
|
+
if (obj.hasOwnProperty(key)) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return true;
|
|
104
|
+
} else {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function objValues(obj) {
|
|
109
|
+
var keys = Object.keys(obj);
|
|
110
|
+
var values = [];
|
|
111
|
+
for (var i = 0; i < keys.length; i++) {
|
|
112
|
+
values.push(obj[keys[i]]);
|
|
113
|
+
}
|
|
114
|
+
return values;
|
|
115
|
+
}
|
|
116
|
+
function merge(a, b) {
|
|
117
|
+
var merged = {};
|
|
118
|
+
for (var key in a) {
|
|
119
|
+
merged[key] = a[key];
|
|
120
|
+
}
|
|
121
|
+
for (var key2 in b) {
|
|
122
|
+
merged[key2] = b[key2];
|
|
123
|
+
}
|
|
124
|
+
return merged;
|
|
125
|
+
}
|
|
126
|
+
var trimLeft;
|
|
127
|
+
if (typeof String.prototype.trimLeft === "function") {
|
|
128
|
+
trimLeft = function(str) {
|
|
129
|
+
return str.trimLeft();
|
|
130
|
+
};
|
|
131
|
+
} else {
|
|
132
|
+
trimLeft = function(str) {
|
|
133
|
+
return str.match(/^\s*(.*)/)[1];
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
var TYPE_NUMBER = 0;
|
|
137
|
+
var TYPE_ANY = 1;
|
|
138
|
+
var TYPE_STRING = 2;
|
|
139
|
+
var TYPE_ARRAY = 3;
|
|
140
|
+
var TYPE_OBJECT = 4;
|
|
141
|
+
var TYPE_BOOLEAN = 5;
|
|
142
|
+
var TYPE_EXPREF = 6;
|
|
143
|
+
var TYPE_NULL = 7;
|
|
144
|
+
var TYPE_ARRAY_NUMBER = 8;
|
|
145
|
+
var TYPE_ARRAY_STRING = 9;
|
|
146
|
+
var TYPE_NAME_TABLE = {
|
|
147
|
+
0: "number",
|
|
148
|
+
1: "any",
|
|
149
|
+
2: "string",
|
|
150
|
+
3: "array",
|
|
151
|
+
4: "object",
|
|
152
|
+
5: "boolean",
|
|
153
|
+
6: "expression",
|
|
154
|
+
7: "null",
|
|
155
|
+
8: "Array<number>",
|
|
156
|
+
9: "Array<string>"
|
|
157
|
+
};
|
|
158
|
+
var TOK_EOF = "EOF";
|
|
159
|
+
var TOK_UNQUOTEDIDENTIFIER = "UnquotedIdentifier";
|
|
160
|
+
var TOK_QUOTEDIDENTIFIER = "QuotedIdentifier";
|
|
161
|
+
var TOK_RBRACKET = "Rbracket";
|
|
162
|
+
var TOK_RPAREN = "Rparen";
|
|
163
|
+
var TOK_COMMA = "Comma";
|
|
164
|
+
var TOK_COLON = "Colon";
|
|
165
|
+
var TOK_RBRACE = "Rbrace";
|
|
166
|
+
var TOK_NUMBER = "Number";
|
|
167
|
+
var TOK_CURRENT = "Current";
|
|
168
|
+
var TOK_EXPREF = "Expref";
|
|
169
|
+
var TOK_PIPE = "Pipe";
|
|
170
|
+
var TOK_OR = "Or";
|
|
171
|
+
var TOK_AND = "And";
|
|
172
|
+
var TOK_EQ = "EQ";
|
|
173
|
+
var TOK_GT = "GT";
|
|
174
|
+
var TOK_LT = "LT";
|
|
175
|
+
var TOK_GTE = "GTE";
|
|
176
|
+
var TOK_LTE = "LTE";
|
|
177
|
+
var TOK_NE = "NE";
|
|
178
|
+
var TOK_FLATTEN = "Flatten";
|
|
179
|
+
var TOK_STAR = "Star";
|
|
180
|
+
var TOK_FILTER = "Filter";
|
|
181
|
+
var TOK_DOT = "Dot";
|
|
182
|
+
var TOK_NOT = "Not";
|
|
183
|
+
var TOK_LBRACE = "Lbrace";
|
|
184
|
+
var TOK_LBRACKET = "Lbracket";
|
|
185
|
+
var TOK_LPAREN = "Lparen";
|
|
186
|
+
var TOK_LITERAL = "Literal";
|
|
187
|
+
var basicTokens = {
|
|
188
|
+
".": TOK_DOT,
|
|
189
|
+
"*": TOK_STAR,
|
|
190
|
+
",": TOK_COMMA,
|
|
191
|
+
":": TOK_COLON,
|
|
192
|
+
"{": TOK_LBRACE,
|
|
193
|
+
"}": TOK_RBRACE,
|
|
194
|
+
"]": TOK_RBRACKET,
|
|
195
|
+
"(": TOK_LPAREN,
|
|
196
|
+
")": TOK_RPAREN,
|
|
197
|
+
"@": TOK_CURRENT
|
|
198
|
+
};
|
|
199
|
+
var operatorStartToken = {
|
|
200
|
+
"<": true,
|
|
201
|
+
">": true,
|
|
202
|
+
"=": true,
|
|
203
|
+
"!": true
|
|
204
|
+
};
|
|
205
|
+
var skipChars = {
|
|
206
|
+
" ": true,
|
|
207
|
+
" ": true,
|
|
208
|
+
"\n": true
|
|
209
|
+
};
|
|
210
|
+
function isAlpha(ch) {
|
|
211
|
+
return ch >= "a" && ch <= "z" || ch >= "A" && ch <= "Z" || ch === "_";
|
|
212
|
+
}
|
|
213
|
+
function isNum(ch) {
|
|
214
|
+
return ch >= "0" && ch <= "9" || ch === "-";
|
|
215
|
+
}
|
|
216
|
+
function isAlphaNum(ch) {
|
|
217
|
+
return ch >= "a" && ch <= "z" || ch >= "A" && ch <= "Z" || ch >= "0" && ch <= "9" || ch === "_";
|
|
218
|
+
}
|
|
219
|
+
function Lexer() {
|
|
220
|
+
}
|
|
221
|
+
Lexer.prototype = {
|
|
222
|
+
tokenize: function(stream) {
|
|
223
|
+
var tokens = [];
|
|
224
|
+
this._current = 0;
|
|
225
|
+
var start;
|
|
226
|
+
var identifier;
|
|
227
|
+
var token;
|
|
228
|
+
while (this._current < stream.length) {
|
|
229
|
+
if (isAlpha(stream[this._current])) {
|
|
230
|
+
start = this._current;
|
|
231
|
+
identifier = this._consumeUnquotedIdentifier(stream);
|
|
232
|
+
tokens.push({
|
|
233
|
+
type: TOK_UNQUOTEDIDENTIFIER,
|
|
234
|
+
value: identifier,
|
|
235
|
+
start
|
|
236
|
+
});
|
|
237
|
+
} else if (basicTokens[stream[this._current]] !== void 0) {
|
|
238
|
+
tokens.push({
|
|
239
|
+
type: basicTokens[stream[this._current]],
|
|
240
|
+
value: stream[this._current],
|
|
241
|
+
start: this._current
|
|
242
|
+
});
|
|
243
|
+
this._current++;
|
|
244
|
+
} else if (isNum(stream[this._current])) {
|
|
245
|
+
token = this._consumeNumber(stream);
|
|
246
|
+
tokens.push(token);
|
|
247
|
+
} else if (stream[this._current] === "[") {
|
|
248
|
+
token = this._consumeLBracket(stream);
|
|
249
|
+
tokens.push(token);
|
|
250
|
+
} else if (stream[this._current] === '"') {
|
|
251
|
+
start = this._current;
|
|
252
|
+
identifier = this._consumeQuotedIdentifier(stream);
|
|
253
|
+
tokens.push({
|
|
254
|
+
type: TOK_QUOTEDIDENTIFIER,
|
|
255
|
+
value: identifier,
|
|
256
|
+
start
|
|
257
|
+
});
|
|
258
|
+
} else if (stream[this._current] === "'") {
|
|
259
|
+
start = this._current;
|
|
260
|
+
identifier = this._consumeRawStringLiteral(stream);
|
|
261
|
+
tokens.push({
|
|
262
|
+
type: TOK_LITERAL,
|
|
263
|
+
value: identifier,
|
|
264
|
+
start
|
|
265
|
+
});
|
|
266
|
+
} else if (stream[this._current] === "`") {
|
|
267
|
+
start = this._current;
|
|
268
|
+
var literal = this._consumeLiteral(stream);
|
|
269
|
+
tokens.push({
|
|
270
|
+
type: TOK_LITERAL,
|
|
271
|
+
value: literal,
|
|
272
|
+
start
|
|
273
|
+
});
|
|
274
|
+
} else if (operatorStartToken[stream[this._current]] !== void 0) {
|
|
275
|
+
tokens.push(this._consumeOperator(stream));
|
|
276
|
+
} else if (skipChars[stream[this._current]] !== void 0) {
|
|
277
|
+
this._current++;
|
|
278
|
+
} else if (stream[this._current] === "&") {
|
|
279
|
+
start = this._current;
|
|
280
|
+
this._current++;
|
|
281
|
+
if (stream[this._current] === "&") {
|
|
282
|
+
this._current++;
|
|
283
|
+
tokens.push({ type: TOK_AND, value: "&&", start });
|
|
284
|
+
} else {
|
|
285
|
+
tokens.push({ type: TOK_EXPREF, value: "&", start });
|
|
286
|
+
}
|
|
287
|
+
} else if (stream[this._current] === "|") {
|
|
288
|
+
start = this._current;
|
|
289
|
+
this._current++;
|
|
290
|
+
if (stream[this._current] === "|") {
|
|
291
|
+
this._current++;
|
|
292
|
+
tokens.push({ type: TOK_OR, value: "||", start });
|
|
293
|
+
} else {
|
|
294
|
+
tokens.push({ type: TOK_PIPE, value: "|", start });
|
|
295
|
+
}
|
|
296
|
+
} else {
|
|
297
|
+
var error = new Error("Unknown character:" + stream[this._current]);
|
|
298
|
+
error.name = "LexerError";
|
|
299
|
+
throw error;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return tokens;
|
|
303
|
+
},
|
|
304
|
+
_consumeUnquotedIdentifier: function(stream) {
|
|
305
|
+
var start = this._current;
|
|
306
|
+
this._current++;
|
|
307
|
+
while (this._current < stream.length && isAlphaNum(stream[this._current])) {
|
|
308
|
+
this._current++;
|
|
309
|
+
}
|
|
310
|
+
return stream.slice(start, this._current);
|
|
311
|
+
},
|
|
312
|
+
_consumeQuotedIdentifier: function(stream) {
|
|
313
|
+
var start = this._current;
|
|
314
|
+
this._current++;
|
|
315
|
+
var maxLength = stream.length;
|
|
316
|
+
while (stream[this._current] !== '"' && this._current < maxLength) {
|
|
317
|
+
var current = this._current;
|
|
318
|
+
if (stream[current] === "\\" && (stream[current + 1] === "\\" || stream[current + 1] === '"')) {
|
|
319
|
+
current += 2;
|
|
320
|
+
} else {
|
|
321
|
+
current++;
|
|
322
|
+
}
|
|
323
|
+
this._current = current;
|
|
324
|
+
}
|
|
325
|
+
this._current++;
|
|
326
|
+
return JSON.parse(stream.slice(start, this._current));
|
|
327
|
+
},
|
|
328
|
+
_consumeRawStringLiteral: function(stream) {
|
|
329
|
+
var start = this._current;
|
|
330
|
+
this._current++;
|
|
331
|
+
var maxLength = stream.length;
|
|
332
|
+
while (stream[this._current] !== "'" && this._current < maxLength) {
|
|
333
|
+
var current = this._current;
|
|
334
|
+
if (stream[current] === "\\" && (stream[current + 1] === "\\" || stream[current + 1] === "'")) {
|
|
335
|
+
current += 2;
|
|
336
|
+
} else {
|
|
337
|
+
current++;
|
|
338
|
+
}
|
|
339
|
+
this._current = current;
|
|
340
|
+
}
|
|
341
|
+
this._current++;
|
|
342
|
+
var literal = stream.slice(start + 1, this._current - 1);
|
|
343
|
+
return literal.replace("\\'", "'");
|
|
344
|
+
},
|
|
345
|
+
_consumeNumber: function(stream) {
|
|
346
|
+
var start = this._current;
|
|
347
|
+
this._current++;
|
|
348
|
+
var maxLength = stream.length;
|
|
349
|
+
while (isNum(stream[this._current]) && this._current < maxLength) {
|
|
350
|
+
this._current++;
|
|
351
|
+
}
|
|
352
|
+
var value = parseInt(stream.slice(start, this._current));
|
|
353
|
+
return { type: TOK_NUMBER, value, start };
|
|
354
|
+
},
|
|
355
|
+
_consumeLBracket: function(stream) {
|
|
356
|
+
var start = this._current;
|
|
357
|
+
this._current++;
|
|
358
|
+
if (stream[this._current] === "?") {
|
|
359
|
+
this._current++;
|
|
360
|
+
return { type: TOK_FILTER, value: "[?", start };
|
|
361
|
+
} else if (stream[this._current] === "]") {
|
|
362
|
+
this._current++;
|
|
363
|
+
return { type: TOK_FLATTEN, value: "[]", start };
|
|
364
|
+
} else {
|
|
365
|
+
return { type: TOK_LBRACKET, value: "[", start };
|
|
366
|
+
}
|
|
367
|
+
},
|
|
368
|
+
_consumeOperator: function(stream) {
|
|
369
|
+
var start = this._current;
|
|
370
|
+
var startingChar = stream[start];
|
|
371
|
+
this._current++;
|
|
372
|
+
if (startingChar === "!") {
|
|
373
|
+
if (stream[this._current] === "=") {
|
|
374
|
+
this._current++;
|
|
375
|
+
return { type: TOK_NE, value: "!=", start };
|
|
376
|
+
} else {
|
|
377
|
+
return { type: TOK_NOT, value: "!", start };
|
|
378
|
+
}
|
|
379
|
+
} else if (startingChar === "<") {
|
|
380
|
+
if (stream[this._current] === "=") {
|
|
381
|
+
this._current++;
|
|
382
|
+
return { type: TOK_LTE, value: "<=", start };
|
|
383
|
+
} else {
|
|
384
|
+
return { type: TOK_LT, value: "<", start };
|
|
385
|
+
}
|
|
386
|
+
} else if (startingChar === ">") {
|
|
387
|
+
if (stream[this._current] === "=") {
|
|
388
|
+
this._current++;
|
|
389
|
+
return { type: TOK_GTE, value: ">=", start };
|
|
390
|
+
} else {
|
|
391
|
+
return { type: TOK_GT, value: ">", start };
|
|
392
|
+
}
|
|
393
|
+
} else if (startingChar === "=") {
|
|
394
|
+
if (stream[this._current] === "=") {
|
|
395
|
+
this._current++;
|
|
396
|
+
return { type: TOK_EQ, value: "==", start };
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
},
|
|
400
|
+
_consumeLiteral: function(stream) {
|
|
401
|
+
this._current++;
|
|
402
|
+
var start = this._current;
|
|
403
|
+
var maxLength = stream.length;
|
|
404
|
+
var literal;
|
|
405
|
+
while (stream[this._current] !== "`" && this._current < maxLength) {
|
|
406
|
+
var current = this._current;
|
|
407
|
+
if (stream[current] === "\\" && (stream[current + 1] === "\\" || stream[current + 1] === "`")) {
|
|
408
|
+
current += 2;
|
|
409
|
+
} else {
|
|
410
|
+
current++;
|
|
411
|
+
}
|
|
412
|
+
this._current = current;
|
|
413
|
+
}
|
|
414
|
+
var literalString = trimLeft(stream.slice(start, this._current));
|
|
415
|
+
literalString = literalString.replace("\\`", "`");
|
|
416
|
+
if (this._looksLikeJSON(literalString)) {
|
|
417
|
+
literal = JSON.parse(literalString);
|
|
418
|
+
} else {
|
|
419
|
+
literal = JSON.parse('"' + literalString + '"');
|
|
420
|
+
}
|
|
421
|
+
this._current++;
|
|
422
|
+
return literal;
|
|
423
|
+
},
|
|
424
|
+
_looksLikeJSON: function(literalString) {
|
|
425
|
+
var startingChars = '[{"';
|
|
426
|
+
var jsonLiterals = ["true", "false", "null"];
|
|
427
|
+
var numberLooking = "-0123456789";
|
|
428
|
+
if (literalString === "") {
|
|
429
|
+
return false;
|
|
430
|
+
} else if (startingChars.indexOf(literalString[0]) >= 0) {
|
|
431
|
+
return true;
|
|
432
|
+
} else if (jsonLiterals.indexOf(literalString) >= 0) {
|
|
433
|
+
return true;
|
|
434
|
+
} else if (numberLooking.indexOf(literalString[0]) >= 0) {
|
|
435
|
+
try {
|
|
436
|
+
JSON.parse(literalString);
|
|
437
|
+
return true;
|
|
438
|
+
} catch (ex) {
|
|
439
|
+
return false;
|
|
440
|
+
}
|
|
441
|
+
} else {
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
var bindingPower = {};
|
|
447
|
+
bindingPower[TOK_EOF] = 0;
|
|
448
|
+
bindingPower[TOK_UNQUOTEDIDENTIFIER] = 0;
|
|
449
|
+
bindingPower[TOK_QUOTEDIDENTIFIER] = 0;
|
|
450
|
+
bindingPower[TOK_RBRACKET] = 0;
|
|
451
|
+
bindingPower[TOK_RPAREN] = 0;
|
|
452
|
+
bindingPower[TOK_COMMA] = 0;
|
|
453
|
+
bindingPower[TOK_RBRACE] = 0;
|
|
454
|
+
bindingPower[TOK_NUMBER] = 0;
|
|
455
|
+
bindingPower[TOK_CURRENT] = 0;
|
|
456
|
+
bindingPower[TOK_EXPREF] = 0;
|
|
457
|
+
bindingPower[TOK_PIPE] = 1;
|
|
458
|
+
bindingPower[TOK_OR] = 2;
|
|
459
|
+
bindingPower[TOK_AND] = 3;
|
|
460
|
+
bindingPower[TOK_EQ] = 5;
|
|
461
|
+
bindingPower[TOK_GT] = 5;
|
|
462
|
+
bindingPower[TOK_LT] = 5;
|
|
463
|
+
bindingPower[TOK_GTE] = 5;
|
|
464
|
+
bindingPower[TOK_LTE] = 5;
|
|
465
|
+
bindingPower[TOK_NE] = 5;
|
|
466
|
+
bindingPower[TOK_FLATTEN] = 9;
|
|
467
|
+
bindingPower[TOK_STAR] = 20;
|
|
468
|
+
bindingPower[TOK_FILTER] = 21;
|
|
469
|
+
bindingPower[TOK_DOT] = 40;
|
|
470
|
+
bindingPower[TOK_NOT] = 45;
|
|
471
|
+
bindingPower[TOK_LBRACE] = 50;
|
|
472
|
+
bindingPower[TOK_LBRACKET] = 55;
|
|
473
|
+
bindingPower[TOK_LPAREN] = 60;
|
|
474
|
+
function Parser() {
|
|
475
|
+
}
|
|
476
|
+
Parser.prototype = {
|
|
477
|
+
parse: function(expression) {
|
|
478
|
+
this._loadTokens(expression);
|
|
479
|
+
this.index = 0;
|
|
480
|
+
var ast = this.expression(0);
|
|
481
|
+
if (this._lookahead(0) !== TOK_EOF) {
|
|
482
|
+
var t = this._lookaheadToken(0);
|
|
483
|
+
var error = new Error(
|
|
484
|
+
"Unexpected token type: " + t.type + ", value: " + t.value
|
|
485
|
+
);
|
|
486
|
+
error.name = "ParserError";
|
|
487
|
+
throw error;
|
|
488
|
+
}
|
|
489
|
+
return ast;
|
|
490
|
+
},
|
|
491
|
+
_loadTokens: function(expression) {
|
|
492
|
+
var lexer = new Lexer();
|
|
493
|
+
var tokens = lexer.tokenize(expression);
|
|
494
|
+
tokens.push({ type: TOK_EOF, value: "", start: expression.length });
|
|
495
|
+
this.tokens = tokens;
|
|
496
|
+
},
|
|
497
|
+
expression: function(rbp) {
|
|
498
|
+
var leftToken = this._lookaheadToken(0);
|
|
499
|
+
this._advance();
|
|
500
|
+
var left = this.nud(leftToken);
|
|
501
|
+
var currentToken = this._lookahead(0);
|
|
502
|
+
while (rbp < bindingPower[currentToken]) {
|
|
503
|
+
this._advance();
|
|
504
|
+
left = this.led(currentToken, left);
|
|
505
|
+
currentToken = this._lookahead(0);
|
|
506
|
+
}
|
|
507
|
+
return left;
|
|
508
|
+
},
|
|
509
|
+
_lookahead: function(number) {
|
|
510
|
+
return this.tokens[this.index + number].type;
|
|
511
|
+
},
|
|
512
|
+
_lookaheadToken: function(number) {
|
|
513
|
+
return this.tokens[this.index + number];
|
|
514
|
+
},
|
|
515
|
+
_advance: function() {
|
|
516
|
+
this.index++;
|
|
517
|
+
},
|
|
518
|
+
nud: function(token) {
|
|
519
|
+
var left;
|
|
520
|
+
var right;
|
|
521
|
+
var expression;
|
|
522
|
+
switch (token.type) {
|
|
523
|
+
case TOK_LITERAL:
|
|
524
|
+
return { type: "Literal", value: token.value };
|
|
525
|
+
case TOK_UNQUOTEDIDENTIFIER:
|
|
526
|
+
return { type: "Field", name: token.value };
|
|
527
|
+
case TOK_QUOTEDIDENTIFIER:
|
|
528
|
+
var node = { type: "Field", name: token.value };
|
|
529
|
+
if (this._lookahead(0) === TOK_LPAREN) {
|
|
530
|
+
throw new Error("Quoted identifier not allowed for function names.");
|
|
531
|
+
}
|
|
532
|
+
return node;
|
|
533
|
+
case TOK_NOT:
|
|
534
|
+
right = this.expression(bindingPower.Not);
|
|
535
|
+
return { type: "NotExpression", children: [right] };
|
|
536
|
+
case TOK_STAR:
|
|
537
|
+
left = { type: "Identity" };
|
|
538
|
+
right = null;
|
|
539
|
+
if (this._lookahead(0) === TOK_RBRACKET) {
|
|
540
|
+
right = { type: "Identity" };
|
|
541
|
+
} else {
|
|
542
|
+
right = this._parseProjectionRHS(bindingPower.Star);
|
|
543
|
+
}
|
|
544
|
+
return { type: "ValueProjection", children: [left, right] };
|
|
545
|
+
case TOK_FILTER:
|
|
546
|
+
return this.led(token.type, { type: "Identity" });
|
|
547
|
+
case TOK_LBRACE:
|
|
548
|
+
return this._parseMultiselectHash();
|
|
549
|
+
case TOK_FLATTEN:
|
|
550
|
+
left = { type: TOK_FLATTEN, children: [{ type: "Identity" }] };
|
|
551
|
+
right = this._parseProjectionRHS(bindingPower.Flatten);
|
|
552
|
+
return { type: "Projection", children: [left, right] };
|
|
553
|
+
case TOK_LBRACKET:
|
|
554
|
+
if (this._lookahead(0) === TOK_NUMBER || this._lookahead(0) === TOK_COLON) {
|
|
555
|
+
right = this._parseIndexExpression();
|
|
556
|
+
return this._projectIfSlice({ type: "Identity" }, right);
|
|
557
|
+
} else if (this._lookahead(0) === TOK_STAR && this._lookahead(1) === TOK_RBRACKET) {
|
|
558
|
+
this._advance();
|
|
559
|
+
this._advance();
|
|
560
|
+
right = this._parseProjectionRHS(bindingPower.Star);
|
|
561
|
+
return {
|
|
562
|
+
type: "Projection",
|
|
563
|
+
children: [{ type: "Identity" }, right]
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
return this._parseMultiselectList();
|
|
567
|
+
case TOK_CURRENT:
|
|
568
|
+
return { type: TOK_CURRENT };
|
|
569
|
+
case TOK_EXPREF:
|
|
570
|
+
expression = this.expression(bindingPower.Expref);
|
|
571
|
+
return { type: "ExpressionReference", children: [expression] };
|
|
572
|
+
case TOK_LPAREN:
|
|
573
|
+
var args = [];
|
|
574
|
+
while (this._lookahead(0) !== TOK_RPAREN) {
|
|
575
|
+
if (this._lookahead(0) === TOK_CURRENT) {
|
|
576
|
+
expression = { type: TOK_CURRENT };
|
|
577
|
+
this._advance();
|
|
578
|
+
} else {
|
|
579
|
+
expression = this.expression(0);
|
|
580
|
+
}
|
|
581
|
+
args.push(expression);
|
|
582
|
+
}
|
|
583
|
+
this._match(TOK_RPAREN);
|
|
584
|
+
return args[0];
|
|
585
|
+
default:
|
|
586
|
+
this._errorToken(token);
|
|
587
|
+
}
|
|
588
|
+
},
|
|
589
|
+
led: function(tokenName, left) {
|
|
590
|
+
var right;
|
|
591
|
+
switch (tokenName) {
|
|
592
|
+
case TOK_DOT:
|
|
593
|
+
var rbp = bindingPower.Dot;
|
|
594
|
+
if (this._lookahead(0) !== TOK_STAR) {
|
|
595
|
+
right = this._parseDotRHS(rbp);
|
|
596
|
+
return { type: "Subexpression", children: [left, right] };
|
|
597
|
+
}
|
|
598
|
+
this._advance();
|
|
599
|
+
right = this._parseProjectionRHS(rbp);
|
|
600
|
+
return { type: "ValueProjection", children: [left, right] };
|
|
601
|
+
case TOK_PIPE:
|
|
602
|
+
right = this.expression(bindingPower.Pipe);
|
|
603
|
+
return { type: TOK_PIPE, children: [left, right] };
|
|
604
|
+
case TOK_OR:
|
|
605
|
+
right = this.expression(bindingPower.Or);
|
|
606
|
+
return { type: "OrExpression", children: [left, right] };
|
|
607
|
+
case TOK_AND:
|
|
608
|
+
right = this.expression(bindingPower.And);
|
|
609
|
+
return { type: "AndExpression", children: [left, right] };
|
|
610
|
+
case TOK_LPAREN:
|
|
611
|
+
var name = left.name;
|
|
612
|
+
var args = [];
|
|
613
|
+
var expression, node;
|
|
614
|
+
while (this._lookahead(0) !== TOK_RPAREN) {
|
|
615
|
+
if (this._lookahead(0) === TOK_CURRENT) {
|
|
616
|
+
expression = { type: TOK_CURRENT };
|
|
617
|
+
this._advance();
|
|
618
|
+
} else {
|
|
619
|
+
expression = this.expression(0);
|
|
620
|
+
}
|
|
621
|
+
if (this._lookahead(0) === TOK_COMMA) {
|
|
622
|
+
this._match(TOK_COMMA);
|
|
623
|
+
}
|
|
624
|
+
args.push(expression);
|
|
625
|
+
}
|
|
626
|
+
this._match(TOK_RPAREN);
|
|
627
|
+
node = { type: "Function", name, children: args };
|
|
628
|
+
return node;
|
|
629
|
+
case TOK_FILTER:
|
|
630
|
+
var condition = this.expression(0);
|
|
631
|
+
this._match(TOK_RBRACKET);
|
|
632
|
+
if (this._lookahead(0) === TOK_FLATTEN) {
|
|
633
|
+
right = { type: "Identity" };
|
|
634
|
+
} else {
|
|
635
|
+
right = this._parseProjectionRHS(bindingPower.Filter);
|
|
636
|
+
}
|
|
637
|
+
return { type: "FilterProjection", children: [left, right, condition] };
|
|
638
|
+
case TOK_FLATTEN:
|
|
639
|
+
var leftNode = { type: TOK_FLATTEN, children: [left] };
|
|
640
|
+
var rightNode = this._parseProjectionRHS(bindingPower.Flatten);
|
|
641
|
+
return { type: "Projection", children: [leftNode, rightNode] };
|
|
642
|
+
case TOK_EQ:
|
|
643
|
+
case TOK_NE:
|
|
644
|
+
case TOK_GT:
|
|
645
|
+
case TOK_GTE:
|
|
646
|
+
case TOK_LT:
|
|
647
|
+
case TOK_LTE:
|
|
648
|
+
return this._parseComparator(left, tokenName);
|
|
649
|
+
case TOK_LBRACKET:
|
|
650
|
+
var token = this._lookaheadToken(0);
|
|
651
|
+
if (token.type === TOK_NUMBER || token.type === TOK_COLON) {
|
|
652
|
+
right = this._parseIndexExpression();
|
|
653
|
+
return this._projectIfSlice(left, right);
|
|
654
|
+
}
|
|
655
|
+
this._match(TOK_STAR);
|
|
656
|
+
this._match(TOK_RBRACKET);
|
|
657
|
+
right = this._parseProjectionRHS(bindingPower.Star);
|
|
658
|
+
return { type: "Projection", children: [left, right] };
|
|
659
|
+
default:
|
|
660
|
+
this._errorToken(this._lookaheadToken(0));
|
|
661
|
+
}
|
|
662
|
+
},
|
|
663
|
+
_match: function(tokenType) {
|
|
664
|
+
if (this._lookahead(0) === tokenType) {
|
|
665
|
+
this._advance();
|
|
666
|
+
} else {
|
|
667
|
+
var t = this._lookaheadToken(0);
|
|
668
|
+
var error = new Error("Expected " + tokenType + ", got: " + t.type);
|
|
669
|
+
error.name = "ParserError";
|
|
670
|
+
throw error;
|
|
671
|
+
}
|
|
672
|
+
},
|
|
673
|
+
_errorToken: function(token) {
|
|
674
|
+
var error = new Error("Invalid token (" + token.type + '): "' + token.value + '"');
|
|
675
|
+
error.name = "ParserError";
|
|
676
|
+
throw error;
|
|
677
|
+
},
|
|
678
|
+
_parseIndexExpression: function() {
|
|
679
|
+
if (this._lookahead(0) === TOK_COLON || this._lookahead(1) === TOK_COLON) {
|
|
680
|
+
return this._parseSliceExpression();
|
|
681
|
+
} else {
|
|
682
|
+
var node = {
|
|
683
|
+
type: "Index",
|
|
684
|
+
value: this._lookaheadToken(0).value
|
|
685
|
+
};
|
|
686
|
+
this._advance();
|
|
687
|
+
this._match(TOK_RBRACKET);
|
|
688
|
+
return node;
|
|
689
|
+
}
|
|
690
|
+
},
|
|
691
|
+
_projectIfSlice: function(left, right) {
|
|
692
|
+
var indexExpr = { type: "IndexExpression", children: [left, right] };
|
|
693
|
+
if (right.type === "Slice") {
|
|
694
|
+
return {
|
|
695
|
+
type: "Projection",
|
|
696
|
+
children: [indexExpr, this._parseProjectionRHS(bindingPower.Star)]
|
|
697
|
+
};
|
|
698
|
+
} else {
|
|
699
|
+
return indexExpr;
|
|
700
|
+
}
|
|
701
|
+
},
|
|
702
|
+
_parseSliceExpression: function() {
|
|
703
|
+
var parts = [null, null, null];
|
|
704
|
+
var index = 0;
|
|
705
|
+
var currentToken = this._lookahead(0);
|
|
706
|
+
while (currentToken !== TOK_RBRACKET && index < 3) {
|
|
707
|
+
if (currentToken === TOK_COLON) {
|
|
708
|
+
index++;
|
|
709
|
+
this._advance();
|
|
710
|
+
} else if (currentToken === TOK_NUMBER) {
|
|
711
|
+
parts[index] = this._lookaheadToken(0).value;
|
|
712
|
+
this._advance();
|
|
713
|
+
} else {
|
|
714
|
+
var t = this._lookahead(0);
|
|
715
|
+
var error = new Error("Syntax error, unexpected token: " + t.value + "(" + t.type + ")");
|
|
716
|
+
error.name = "Parsererror";
|
|
717
|
+
throw error;
|
|
718
|
+
}
|
|
719
|
+
currentToken = this._lookahead(0);
|
|
720
|
+
}
|
|
721
|
+
this._match(TOK_RBRACKET);
|
|
722
|
+
return {
|
|
723
|
+
type: "Slice",
|
|
724
|
+
children: parts
|
|
725
|
+
};
|
|
726
|
+
},
|
|
727
|
+
_parseComparator: function(left, comparator) {
|
|
728
|
+
var right = this.expression(bindingPower[comparator]);
|
|
729
|
+
return { type: "Comparator", name: comparator, children: [left, right] };
|
|
730
|
+
},
|
|
731
|
+
_parseDotRHS: function(rbp) {
|
|
732
|
+
var lookahead = this._lookahead(0);
|
|
733
|
+
var exprTokens = [TOK_UNQUOTEDIDENTIFIER, TOK_QUOTEDIDENTIFIER, TOK_STAR];
|
|
734
|
+
if (exprTokens.indexOf(lookahead) >= 0) {
|
|
735
|
+
return this.expression(rbp);
|
|
736
|
+
} else if (lookahead === TOK_LBRACKET) {
|
|
737
|
+
this._match(TOK_LBRACKET);
|
|
738
|
+
return this._parseMultiselectList();
|
|
739
|
+
} else if (lookahead === TOK_LBRACE) {
|
|
740
|
+
this._match(TOK_LBRACE);
|
|
741
|
+
return this._parseMultiselectHash();
|
|
742
|
+
}
|
|
743
|
+
},
|
|
744
|
+
_parseProjectionRHS: function(rbp) {
|
|
745
|
+
var right;
|
|
746
|
+
if (bindingPower[this._lookahead(0)] < 10) {
|
|
747
|
+
right = { type: "Identity" };
|
|
748
|
+
} else if (this._lookahead(0) === TOK_LBRACKET) {
|
|
749
|
+
right = this.expression(rbp);
|
|
750
|
+
} else if (this._lookahead(0) === TOK_FILTER) {
|
|
751
|
+
right = this.expression(rbp);
|
|
752
|
+
} else if (this._lookahead(0) === TOK_DOT) {
|
|
753
|
+
this._match(TOK_DOT);
|
|
754
|
+
right = this._parseDotRHS(rbp);
|
|
755
|
+
} else {
|
|
756
|
+
var t = this._lookaheadToken(0);
|
|
757
|
+
var error = new Error("Sytanx error, unexpected token: " + t.value + "(" + t.type + ")");
|
|
758
|
+
error.name = "ParserError";
|
|
759
|
+
throw error;
|
|
760
|
+
}
|
|
761
|
+
return right;
|
|
762
|
+
},
|
|
763
|
+
_parseMultiselectList: function() {
|
|
764
|
+
var expressions = [];
|
|
765
|
+
while (this._lookahead(0) !== TOK_RBRACKET) {
|
|
766
|
+
var expression = this.expression(0);
|
|
767
|
+
expressions.push(expression);
|
|
768
|
+
if (this._lookahead(0) === TOK_COMMA) {
|
|
769
|
+
this._match(TOK_COMMA);
|
|
770
|
+
if (this._lookahead(0) === TOK_RBRACKET) {
|
|
771
|
+
throw new Error("Unexpected token Rbracket");
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
this._match(TOK_RBRACKET);
|
|
776
|
+
return { type: "MultiSelectList", children: expressions };
|
|
777
|
+
},
|
|
778
|
+
_parseMultiselectHash: function() {
|
|
779
|
+
var pairs = [];
|
|
780
|
+
var identifierTypes = [TOK_UNQUOTEDIDENTIFIER, TOK_QUOTEDIDENTIFIER];
|
|
781
|
+
var keyToken, keyName, value, node;
|
|
782
|
+
for (; ; ) {
|
|
783
|
+
keyToken = this._lookaheadToken(0);
|
|
784
|
+
if (identifierTypes.indexOf(keyToken.type) < 0) {
|
|
785
|
+
throw new Error("Expecting an identifier token, got: " + keyToken.type);
|
|
786
|
+
}
|
|
787
|
+
keyName = keyToken.value;
|
|
788
|
+
this._advance();
|
|
789
|
+
this._match(TOK_COLON);
|
|
790
|
+
value = this.expression(0);
|
|
791
|
+
node = { type: "KeyValuePair", name: keyName, value };
|
|
792
|
+
pairs.push(node);
|
|
793
|
+
if (this._lookahead(0) === TOK_COMMA) {
|
|
794
|
+
this._match(TOK_COMMA);
|
|
795
|
+
} else if (this._lookahead(0) === TOK_RBRACE) {
|
|
796
|
+
this._match(TOK_RBRACE);
|
|
797
|
+
break;
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
return { type: "MultiSelectHash", children: pairs };
|
|
801
|
+
}
|
|
802
|
+
};
|
|
803
|
+
function TreeInterpreter(runtime) {
|
|
804
|
+
this.runtime = runtime;
|
|
805
|
+
}
|
|
806
|
+
TreeInterpreter.prototype = {
|
|
807
|
+
search: function(node, value) {
|
|
808
|
+
return this.visit(node, value);
|
|
809
|
+
},
|
|
810
|
+
visit: function(node, value) {
|
|
811
|
+
var matched, current, result, first, second, field, left, right, collected, i;
|
|
812
|
+
switch (node.type) {
|
|
813
|
+
case "Field":
|
|
814
|
+
if (value !== null && isObject(value)) {
|
|
815
|
+
field = value[node.name];
|
|
816
|
+
if (field === void 0) {
|
|
817
|
+
return null;
|
|
818
|
+
} else {
|
|
819
|
+
return field;
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
return null;
|
|
823
|
+
case "Subexpression":
|
|
824
|
+
result = this.visit(node.children[0], value);
|
|
825
|
+
for (i = 1; i < node.children.length; i++) {
|
|
826
|
+
result = this.visit(node.children[1], result);
|
|
827
|
+
if (result === null) {
|
|
828
|
+
return null;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
return result;
|
|
832
|
+
case "IndexExpression":
|
|
833
|
+
left = this.visit(node.children[0], value);
|
|
834
|
+
right = this.visit(node.children[1], left);
|
|
835
|
+
return right;
|
|
836
|
+
case "Index":
|
|
837
|
+
if (!isArray(value)) {
|
|
838
|
+
return null;
|
|
839
|
+
}
|
|
840
|
+
var index = node.value;
|
|
841
|
+
if (index < 0) {
|
|
842
|
+
index = value.length + index;
|
|
843
|
+
}
|
|
844
|
+
result = value[index];
|
|
845
|
+
if (result === void 0) {
|
|
846
|
+
result = null;
|
|
847
|
+
}
|
|
848
|
+
return result;
|
|
849
|
+
case "Slice":
|
|
850
|
+
if (!isArray(value)) {
|
|
851
|
+
return null;
|
|
852
|
+
}
|
|
853
|
+
var sliceParams = node.children.slice(0);
|
|
854
|
+
var computed = this.computeSliceParams(value.length, sliceParams);
|
|
855
|
+
var start = computed[0];
|
|
856
|
+
var stop = computed[1];
|
|
857
|
+
var step = computed[2];
|
|
858
|
+
result = [];
|
|
859
|
+
if (step > 0) {
|
|
860
|
+
for (i = start; i < stop; i += step) {
|
|
861
|
+
result.push(value[i]);
|
|
862
|
+
}
|
|
863
|
+
} else {
|
|
864
|
+
for (i = start; i > stop; i += step) {
|
|
865
|
+
result.push(value[i]);
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
return result;
|
|
869
|
+
case "Projection":
|
|
870
|
+
var base = this.visit(node.children[0], value);
|
|
871
|
+
if (!isArray(base)) {
|
|
872
|
+
return null;
|
|
873
|
+
}
|
|
874
|
+
collected = [];
|
|
875
|
+
for (i = 0; i < base.length; i++) {
|
|
876
|
+
current = this.visit(node.children[1], base[i]);
|
|
877
|
+
if (current !== null) {
|
|
878
|
+
collected.push(current);
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
return collected;
|
|
882
|
+
case "ValueProjection":
|
|
883
|
+
base = this.visit(node.children[0], value);
|
|
884
|
+
if (!isObject(base)) {
|
|
885
|
+
return null;
|
|
886
|
+
}
|
|
887
|
+
collected = [];
|
|
888
|
+
var values = objValues(base);
|
|
889
|
+
for (i = 0; i < values.length; i++) {
|
|
890
|
+
current = this.visit(node.children[1], values[i]);
|
|
891
|
+
if (current !== null) {
|
|
892
|
+
collected.push(current);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
return collected;
|
|
896
|
+
case "FilterProjection":
|
|
897
|
+
base = this.visit(node.children[0], value);
|
|
898
|
+
if (!isArray(base)) {
|
|
899
|
+
return null;
|
|
900
|
+
}
|
|
901
|
+
var filtered = [];
|
|
902
|
+
var finalResults = [];
|
|
903
|
+
for (i = 0; i < base.length; i++) {
|
|
904
|
+
matched = this.visit(node.children[2], base[i]);
|
|
905
|
+
if (!isFalse(matched)) {
|
|
906
|
+
filtered.push(base[i]);
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
for (var j = 0; j < filtered.length; j++) {
|
|
910
|
+
current = this.visit(node.children[1], filtered[j]);
|
|
911
|
+
if (current !== null) {
|
|
912
|
+
finalResults.push(current);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
return finalResults;
|
|
916
|
+
case "Comparator":
|
|
917
|
+
first = this.visit(node.children[0], value);
|
|
918
|
+
second = this.visit(node.children[1], value);
|
|
919
|
+
switch (node.name) {
|
|
920
|
+
case TOK_EQ:
|
|
921
|
+
result = strictDeepEqual(first, second);
|
|
922
|
+
break;
|
|
923
|
+
case TOK_NE:
|
|
924
|
+
result = !strictDeepEqual(first, second);
|
|
925
|
+
break;
|
|
926
|
+
case TOK_GT:
|
|
927
|
+
result = first > second;
|
|
928
|
+
break;
|
|
929
|
+
case TOK_GTE:
|
|
930
|
+
result = first >= second;
|
|
931
|
+
break;
|
|
932
|
+
case TOK_LT:
|
|
933
|
+
result = first < second;
|
|
934
|
+
break;
|
|
935
|
+
case TOK_LTE:
|
|
936
|
+
result = first <= second;
|
|
937
|
+
break;
|
|
938
|
+
default:
|
|
939
|
+
throw new Error("Unknown comparator: " + node.name);
|
|
940
|
+
}
|
|
941
|
+
return result;
|
|
942
|
+
case TOK_FLATTEN:
|
|
943
|
+
var original = this.visit(node.children[0], value);
|
|
944
|
+
if (!isArray(original)) {
|
|
945
|
+
return null;
|
|
946
|
+
}
|
|
947
|
+
var merged = [];
|
|
948
|
+
for (i = 0; i < original.length; i++) {
|
|
949
|
+
current = original[i];
|
|
950
|
+
if (isArray(current)) {
|
|
951
|
+
merged.push.apply(merged, current);
|
|
952
|
+
} else {
|
|
953
|
+
merged.push(current);
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
return merged;
|
|
957
|
+
case "Identity":
|
|
958
|
+
return value;
|
|
959
|
+
case "MultiSelectList":
|
|
960
|
+
if (value === null) {
|
|
961
|
+
return null;
|
|
962
|
+
}
|
|
963
|
+
collected = [];
|
|
964
|
+
for (i = 0; i < node.children.length; i++) {
|
|
965
|
+
collected.push(this.visit(node.children[i], value));
|
|
966
|
+
}
|
|
967
|
+
return collected;
|
|
968
|
+
case "MultiSelectHash":
|
|
969
|
+
if (value === null) {
|
|
970
|
+
return null;
|
|
971
|
+
}
|
|
972
|
+
collected = {};
|
|
973
|
+
var child;
|
|
974
|
+
for (i = 0; i < node.children.length; i++) {
|
|
975
|
+
child = node.children[i];
|
|
976
|
+
collected[child.name] = this.visit(child.value, value);
|
|
977
|
+
}
|
|
978
|
+
return collected;
|
|
979
|
+
case "OrExpression":
|
|
980
|
+
matched = this.visit(node.children[0], value);
|
|
981
|
+
if (isFalse(matched)) {
|
|
982
|
+
matched = this.visit(node.children[1], value);
|
|
983
|
+
}
|
|
984
|
+
return matched;
|
|
985
|
+
case "AndExpression":
|
|
986
|
+
first = this.visit(node.children[0], value);
|
|
987
|
+
if (isFalse(first) === true) {
|
|
988
|
+
return first;
|
|
989
|
+
}
|
|
990
|
+
return this.visit(node.children[1], value);
|
|
991
|
+
case "NotExpression":
|
|
992
|
+
first = this.visit(node.children[0], value);
|
|
993
|
+
return isFalse(first);
|
|
994
|
+
case "Literal":
|
|
995
|
+
return node.value;
|
|
996
|
+
case TOK_PIPE:
|
|
997
|
+
left = this.visit(node.children[0], value);
|
|
998
|
+
return this.visit(node.children[1], left);
|
|
999
|
+
case TOK_CURRENT:
|
|
1000
|
+
return value;
|
|
1001
|
+
case "Function":
|
|
1002
|
+
var resolvedArgs = [];
|
|
1003
|
+
for (i = 0; i < node.children.length; i++) {
|
|
1004
|
+
resolvedArgs.push(this.visit(node.children[i], value));
|
|
1005
|
+
}
|
|
1006
|
+
return this.runtime.callFunction(node.name, resolvedArgs);
|
|
1007
|
+
case "ExpressionReference":
|
|
1008
|
+
var refNode = node.children[0];
|
|
1009
|
+
refNode.jmespathType = TOK_EXPREF;
|
|
1010
|
+
return refNode;
|
|
1011
|
+
default:
|
|
1012
|
+
throw new Error("Unknown node type: " + node.type);
|
|
1013
|
+
}
|
|
1014
|
+
},
|
|
1015
|
+
computeSliceParams: function(arrayLength, sliceParams) {
|
|
1016
|
+
var start = sliceParams[0];
|
|
1017
|
+
var stop = sliceParams[1];
|
|
1018
|
+
var step = sliceParams[2];
|
|
1019
|
+
var computed = [null, null, null];
|
|
1020
|
+
if (step === null) {
|
|
1021
|
+
step = 1;
|
|
1022
|
+
} else if (step === 0) {
|
|
1023
|
+
var error = new Error("Invalid slice, step cannot be 0");
|
|
1024
|
+
error.name = "RuntimeError";
|
|
1025
|
+
throw error;
|
|
1026
|
+
}
|
|
1027
|
+
var stepValueNegative = step < 0 ? true : false;
|
|
1028
|
+
if (start === null) {
|
|
1029
|
+
start = stepValueNegative ? arrayLength - 1 : 0;
|
|
1030
|
+
} else {
|
|
1031
|
+
start = this.capSliceRange(arrayLength, start, step);
|
|
1032
|
+
}
|
|
1033
|
+
if (stop === null) {
|
|
1034
|
+
stop = stepValueNegative ? -1 : arrayLength;
|
|
1035
|
+
} else {
|
|
1036
|
+
stop = this.capSliceRange(arrayLength, stop, step);
|
|
1037
|
+
}
|
|
1038
|
+
computed[0] = start;
|
|
1039
|
+
computed[1] = stop;
|
|
1040
|
+
computed[2] = step;
|
|
1041
|
+
return computed;
|
|
1042
|
+
},
|
|
1043
|
+
capSliceRange: function(arrayLength, actualValue, step) {
|
|
1044
|
+
if (actualValue < 0) {
|
|
1045
|
+
actualValue += arrayLength;
|
|
1046
|
+
if (actualValue < 0) {
|
|
1047
|
+
actualValue = step < 0 ? -1 : 0;
|
|
1048
|
+
}
|
|
1049
|
+
} else if (actualValue >= arrayLength) {
|
|
1050
|
+
actualValue = step < 0 ? arrayLength - 1 : arrayLength;
|
|
1051
|
+
}
|
|
1052
|
+
return actualValue;
|
|
1053
|
+
}
|
|
1054
|
+
};
|
|
1055
|
+
function Runtime(interpreter) {
|
|
1056
|
+
this._interpreter = interpreter;
|
|
1057
|
+
this.functionTable = {
|
|
1058
|
+
// name: [function, <signature>]
|
|
1059
|
+
// The <signature> can be:
|
|
1060
|
+
//
|
|
1061
|
+
// {
|
|
1062
|
+
// args: [[type1, type2], [type1, type2]],
|
|
1063
|
+
// variadic: true|false
|
|
1064
|
+
// }
|
|
1065
|
+
//
|
|
1066
|
+
// Each arg in the arg list is a list of valid types
|
|
1067
|
+
// (if the function is overloaded and supports multiple
|
|
1068
|
+
// types. If the type is "any" then no type checking
|
|
1069
|
+
// occurs on the argument. Variadic is optional
|
|
1070
|
+
// and if not provided is assumed to be false.
|
|
1071
|
+
abs: { _func: this._functionAbs, _signature: [{ types: [TYPE_NUMBER] }] },
|
|
1072
|
+
avg: { _func: this._functionAvg, _signature: [{ types: [TYPE_ARRAY_NUMBER] }] },
|
|
1073
|
+
ceil: { _func: this._functionCeil, _signature: [{ types: [TYPE_NUMBER] }] },
|
|
1074
|
+
contains: {
|
|
1075
|
+
_func: this._functionContains,
|
|
1076
|
+
_signature: [
|
|
1077
|
+
{ types: [TYPE_STRING, TYPE_ARRAY] },
|
|
1078
|
+
{ types: [TYPE_ANY] }
|
|
1079
|
+
]
|
|
1080
|
+
},
|
|
1081
|
+
"ends_with": {
|
|
1082
|
+
_func: this._functionEndsWith,
|
|
1083
|
+
_signature: [{ types: [TYPE_STRING] }, { types: [TYPE_STRING] }]
|
|
1084
|
+
},
|
|
1085
|
+
floor: { _func: this._functionFloor, _signature: [{ types: [TYPE_NUMBER] }] },
|
|
1086
|
+
length: {
|
|
1087
|
+
_func: this._functionLength,
|
|
1088
|
+
_signature: [{ types: [TYPE_STRING, TYPE_ARRAY, TYPE_OBJECT] }]
|
|
1089
|
+
},
|
|
1090
|
+
map: {
|
|
1091
|
+
_func: this._functionMap,
|
|
1092
|
+
_signature: [{ types: [TYPE_EXPREF] }, { types: [TYPE_ARRAY] }]
|
|
1093
|
+
},
|
|
1094
|
+
max: {
|
|
1095
|
+
_func: this._functionMax,
|
|
1096
|
+
_signature: [{ types: [TYPE_ARRAY_NUMBER, TYPE_ARRAY_STRING] }]
|
|
1097
|
+
},
|
|
1098
|
+
"merge": {
|
|
1099
|
+
_func: this._functionMerge,
|
|
1100
|
+
_signature: [{ types: [TYPE_OBJECT], variadic: true }]
|
|
1101
|
+
},
|
|
1102
|
+
"max_by": {
|
|
1103
|
+
_func: this._functionMaxBy,
|
|
1104
|
+
_signature: [{ types: [TYPE_ARRAY] }, { types: [TYPE_EXPREF] }]
|
|
1105
|
+
},
|
|
1106
|
+
sum: { _func: this._functionSum, _signature: [{ types: [TYPE_ARRAY_NUMBER] }] },
|
|
1107
|
+
"starts_with": {
|
|
1108
|
+
_func: this._functionStartsWith,
|
|
1109
|
+
_signature: [{ types: [TYPE_STRING] }, { types: [TYPE_STRING] }]
|
|
1110
|
+
},
|
|
1111
|
+
min: {
|
|
1112
|
+
_func: this._functionMin,
|
|
1113
|
+
_signature: [{ types: [TYPE_ARRAY_NUMBER, TYPE_ARRAY_STRING] }]
|
|
1114
|
+
},
|
|
1115
|
+
"min_by": {
|
|
1116
|
+
_func: this._functionMinBy,
|
|
1117
|
+
_signature: [{ types: [TYPE_ARRAY] }, { types: [TYPE_EXPREF] }]
|
|
1118
|
+
},
|
|
1119
|
+
type: { _func: this._functionType, _signature: [{ types: [TYPE_ANY] }] },
|
|
1120
|
+
keys: { _func: this._functionKeys, _signature: [{ types: [TYPE_OBJECT] }] },
|
|
1121
|
+
values: { _func: this._functionValues, _signature: [{ types: [TYPE_OBJECT] }] },
|
|
1122
|
+
sort: { _func: this._functionSort, _signature: [{ types: [TYPE_ARRAY_STRING, TYPE_ARRAY_NUMBER] }] },
|
|
1123
|
+
"sort_by": {
|
|
1124
|
+
_func: this._functionSortBy,
|
|
1125
|
+
_signature: [{ types: [TYPE_ARRAY] }, { types: [TYPE_EXPREF] }]
|
|
1126
|
+
},
|
|
1127
|
+
join: {
|
|
1128
|
+
_func: this._functionJoin,
|
|
1129
|
+
_signature: [
|
|
1130
|
+
{ types: [TYPE_STRING] },
|
|
1131
|
+
{ types: [TYPE_ARRAY_STRING] }
|
|
1132
|
+
]
|
|
1133
|
+
},
|
|
1134
|
+
reverse: {
|
|
1135
|
+
_func: this._functionReverse,
|
|
1136
|
+
_signature: [{ types: [TYPE_STRING, TYPE_ARRAY] }]
|
|
1137
|
+
},
|
|
1138
|
+
"to_array": { _func: this._functionToArray, _signature: [{ types: [TYPE_ANY] }] },
|
|
1139
|
+
"to_string": { _func: this._functionToString, _signature: [{ types: [TYPE_ANY] }] },
|
|
1140
|
+
"to_number": { _func: this._functionToNumber, _signature: [{ types: [TYPE_ANY] }] },
|
|
1141
|
+
"not_null": {
|
|
1142
|
+
_func: this._functionNotNull,
|
|
1143
|
+
_signature: [{ types: [TYPE_ANY], variadic: true }]
|
|
1144
|
+
}
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1147
|
+
Runtime.prototype = {
|
|
1148
|
+
callFunction: function(name, resolvedArgs) {
|
|
1149
|
+
var functionEntry = this.functionTable[name];
|
|
1150
|
+
if (functionEntry === void 0) {
|
|
1151
|
+
throw new Error("Unknown function: " + name + "()");
|
|
1152
|
+
}
|
|
1153
|
+
this._validateArgs(name, resolvedArgs, functionEntry._signature);
|
|
1154
|
+
return functionEntry._func.call(this, resolvedArgs);
|
|
1155
|
+
},
|
|
1156
|
+
_validateArgs: function(name, args, signature) {
|
|
1157
|
+
var pluralized;
|
|
1158
|
+
if (signature[signature.length - 1].variadic) {
|
|
1159
|
+
if (args.length < signature.length) {
|
|
1160
|
+
pluralized = signature.length === 1 ? " argument" : " arguments";
|
|
1161
|
+
throw new Error("ArgumentError: " + name + "() takes at least" + signature.length + pluralized + " but received " + args.length);
|
|
1162
|
+
}
|
|
1163
|
+
} else if (args.length !== signature.length) {
|
|
1164
|
+
pluralized = signature.length === 1 ? " argument" : " arguments";
|
|
1165
|
+
throw new Error("ArgumentError: " + name + "() takes " + signature.length + pluralized + " but received " + args.length);
|
|
1166
|
+
}
|
|
1167
|
+
var currentSpec;
|
|
1168
|
+
var actualType;
|
|
1169
|
+
var typeMatched;
|
|
1170
|
+
for (var i = 0; i < signature.length; i++) {
|
|
1171
|
+
typeMatched = false;
|
|
1172
|
+
currentSpec = signature[i].types;
|
|
1173
|
+
actualType = this._getTypeName(args[i]);
|
|
1174
|
+
for (var j = 0; j < currentSpec.length; j++) {
|
|
1175
|
+
if (this._typeMatches(actualType, currentSpec[j], args[i])) {
|
|
1176
|
+
typeMatched = true;
|
|
1177
|
+
break;
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
if (!typeMatched) {
|
|
1181
|
+
var expected = currentSpec.map(function(typeIdentifier) {
|
|
1182
|
+
return TYPE_NAME_TABLE[typeIdentifier];
|
|
1183
|
+
}).join(",");
|
|
1184
|
+
throw new Error("TypeError: " + name + "() expected argument " + (i + 1) + " to be type " + expected + " but received type " + TYPE_NAME_TABLE[actualType] + " instead.");
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
},
|
|
1188
|
+
_typeMatches: function(actual, expected, argValue) {
|
|
1189
|
+
if (expected === TYPE_ANY) {
|
|
1190
|
+
return true;
|
|
1191
|
+
}
|
|
1192
|
+
if (expected === TYPE_ARRAY_STRING || expected === TYPE_ARRAY_NUMBER || expected === TYPE_ARRAY) {
|
|
1193
|
+
if (expected === TYPE_ARRAY) {
|
|
1194
|
+
return actual === TYPE_ARRAY;
|
|
1195
|
+
} else if (actual === TYPE_ARRAY) {
|
|
1196
|
+
var subtype;
|
|
1197
|
+
if (expected === TYPE_ARRAY_NUMBER) {
|
|
1198
|
+
subtype = TYPE_NUMBER;
|
|
1199
|
+
} else if (expected === TYPE_ARRAY_STRING) {
|
|
1200
|
+
subtype = TYPE_STRING;
|
|
1201
|
+
}
|
|
1202
|
+
for (var i = 0; i < argValue.length; i++) {
|
|
1203
|
+
if (!this._typeMatches(
|
|
1204
|
+
this._getTypeName(argValue[i]),
|
|
1205
|
+
subtype,
|
|
1206
|
+
argValue[i]
|
|
1207
|
+
)) {
|
|
1208
|
+
return false;
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
return true;
|
|
1212
|
+
}
|
|
1213
|
+
} else {
|
|
1214
|
+
return actual === expected;
|
|
1215
|
+
}
|
|
1216
|
+
},
|
|
1217
|
+
_getTypeName: function(obj) {
|
|
1218
|
+
switch (Object.prototype.toString.call(obj)) {
|
|
1219
|
+
case "[object String]":
|
|
1220
|
+
return TYPE_STRING;
|
|
1221
|
+
case "[object Number]":
|
|
1222
|
+
return TYPE_NUMBER;
|
|
1223
|
+
case "[object Array]":
|
|
1224
|
+
return TYPE_ARRAY;
|
|
1225
|
+
case "[object Boolean]":
|
|
1226
|
+
return TYPE_BOOLEAN;
|
|
1227
|
+
case "[object Null]":
|
|
1228
|
+
return TYPE_NULL;
|
|
1229
|
+
case "[object Object]":
|
|
1230
|
+
if (obj.jmespathType === TOK_EXPREF) {
|
|
1231
|
+
return TYPE_EXPREF;
|
|
1232
|
+
} else {
|
|
1233
|
+
return TYPE_OBJECT;
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
},
|
|
1237
|
+
_functionStartsWith: function(resolvedArgs) {
|
|
1238
|
+
return resolvedArgs[0].lastIndexOf(resolvedArgs[1]) === 0;
|
|
1239
|
+
},
|
|
1240
|
+
_functionEndsWith: function(resolvedArgs) {
|
|
1241
|
+
var searchStr = resolvedArgs[0];
|
|
1242
|
+
var suffix = resolvedArgs[1];
|
|
1243
|
+
return searchStr.indexOf(suffix, searchStr.length - suffix.length) !== -1;
|
|
1244
|
+
},
|
|
1245
|
+
_functionReverse: function(resolvedArgs) {
|
|
1246
|
+
var typeName = this._getTypeName(resolvedArgs[0]);
|
|
1247
|
+
if (typeName === TYPE_STRING) {
|
|
1248
|
+
var originalStr = resolvedArgs[0];
|
|
1249
|
+
var reversedStr = "";
|
|
1250
|
+
for (var i = originalStr.length - 1; i >= 0; i--) {
|
|
1251
|
+
reversedStr += originalStr[i];
|
|
1252
|
+
}
|
|
1253
|
+
return reversedStr;
|
|
1254
|
+
} else {
|
|
1255
|
+
var reversedArray = resolvedArgs[0].slice(0);
|
|
1256
|
+
reversedArray.reverse();
|
|
1257
|
+
return reversedArray;
|
|
1258
|
+
}
|
|
1259
|
+
},
|
|
1260
|
+
_functionAbs: function(resolvedArgs) {
|
|
1261
|
+
return Math.abs(resolvedArgs[0]);
|
|
1262
|
+
},
|
|
1263
|
+
_functionCeil: function(resolvedArgs) {
|
|
1264
|
+
return Math.ceil(resolvedArgs[0]);
|
|
1265
|
+
},
|
|
1266
|
+
_functionAvg: function(resolvedArgs) {
|
|
1267
|
+
var sum = 0;
|
|
1268
|
+
var inputArray = resolvedArgs[0];
|
|
1269
|
+
for (var i = 0; i < inputArray.length; i++) {
|
|
1270
|
+
sum += inputArray[i];
|
|
1271
|
+
}
|
|
1272
|
+
return sum / inputArray.length;
|
|
1273
|
+
},
|
|
1274
|
+
_functionContains: function(resolvedArgs) {
|
|
1275
|
+
return resolvedArgs[0].indexOf(resolvedArgs[1]) >= 0;
|
|
1276
|
+
},
|
|
1277
|
+
_functionFloor: function(resolvedArgs) {
|
|
1278
|
+
return Math.floor(resolvedArgs[0]);
|
|
1279
|
+
},
|
|
1280
|
+
_functionLength: function(resolvedArgs) {
|
|
1281
|
+
if (!isObject(resolvedArgs[0])) {
|
|
1282
|
+
return resolvedArgs[0].length;
|
|
1283
|
+
} else {
|
|
1284
|
+
return Object.keys(resolvedArgs[0]).length;
|
|
1285
|
+
}
|
|
1286
|
+
},
|
|
1287
|
+
_functionMap: function(resolvedArgs) {
|
|
1288
|
+
var mapped = [];
|
|
1289
|
+
var interpreter = this._interpreter;
|
|
1290
|
+
var exprefNode = resolvedArgs[0];
|
|
1291
|
+
var elements = resolvedArgs[1];
|
|
1292
|
+
for (var i = 0; i < elements.length; i++) {
|
|
1293
|
+
mapped.push(interpreter.visit(exprefNode, elements[i]));
|
|
1294
|
+
}
|
|
1295
|
+
return mapped;
|
|
1296
|
+
},
|
|
1297
|
+
_functionMerge: function(resolvedArgs) {
|
|
1298
|
+
var merged = {};
|
|
1299
|
+
for (var i = 0; i < resolvedArgs.length; i++) {
|
|
1300
|
+
var current = resolvedArgs[i];
|
|
1301
|
+
for (var key in current) {
|
|
1302
|
+
merged[key] = current[key];
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
return merged;
|
|
1306
|
+
},
|
|
1307
|
+
_functionMax: function(resolvedArgs) {
|
|
1308
|
+
if (resolvedArgs[0].length > 0) {
|
|
1309
|
+
var typeName = this._getTypeName(resolvedArgs[0][0]);
|
|
1310
|
+
if (typeName === TYPE_NUMBER) {
|
|
1311
|
+
return Math.max.apply(Math, resolvedArgs[0]);
|
|
1312
|
+
} else {
|
|
1313
|
+
var elements = resolvedArgs[0];
|
|
1314
|
+
var maxElement = elements[0];
|
|
1315
|
+
for (var i = 1; i < elements.length; i++) {
|
|
1316
|
+
if (maxElement.localeCompare(elements[i]) < 0) {
|
|
1317
|
+
maxElement = elements[i];
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
return maxElement;
|
|
1321
|
+
}
|
|
1322
|
+
} else {
|
|
1323
|
+
return null;
|
|
1324
|
+
}
|
|
1325
|
+
},
|
|
1326
|
+
_functionMin: function(resolvedArgs) {
|
|
1327
|
+
if (resolvedArgs[0].length > 0) {
|
|
1328
|
+
var typeName = this._getTypeName(resolvedArgs[0][0]);
|
|
1329
|
+
if (typeName === TYPE_NUMBER) {
|
|
1330
|
+
return Math.min.apply(Math, resolvedArgs[0]);
|
|
1331
|
+
} else {
|
|
1332
|
+
var elements = resolvedArgs[0];
|
|
1333
|
+
var minElement = elements[0];
|
|
1334
|
+
for (var i = 1; i < elements.length; i++) {
|
|
1335
|
+
if (elements[i].localeCompare(minElement) < 0) {
|
|
1336
|
+
minElement = elements[i];
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
return minElement;
|
|
1340
|
+
}
|
|
1341
|
+
} else {
|
|
1342
|
+
return null;
|
|
1343
|
+
}
|
|
1344
|
+
},
|
|
1345
|
+
_functionSum: function(resolvedArgs) {
|
|
1346
|
+
var sum = 0;
|
|
1347
|
+
var listToSum = resolvedArgs[0];
|
|
1348
|
+
for (var i = 0; i < listToSum.length; i++) {
|
|
1349
|
+
sum += listToSum[i];
|
|
1350
|
+
}
|
|
1351
|
+
return sum;
|
|
1352
|
+
},
|
|
1353
|
+
_functionType: function(resolvedArgs) {
|
|
1354
|
+
switch (this._getTypeName(resolvedArgs[0])) {
|
|
1355
|
+
case TYPE_NUMBER:
|
|
1356
|
+
return "number";
|
|
1357
|
+
case TYPE_STRING:
|
|
1358
|
+
return "string";
|
|
1359
|
+
case TYPE_ARRAY:
|
|
1360
|
+
return "array";
|
|
1361
|
+
case TYPE_OBJECT:
|
|
1362
|
+
return "object";
|
|
1363
|
+
case TYPE_BOOLEAN:
|
|
1364
|
+
return "boolean";
|
|
1365
|
+
case TYPE_EXPREF:
|
|
1366
|
+
return "expref";
|
|
1367
|
+
case TYPE_NULL:
|
|
1368
|
+
return "null";
|
|
1369
|
+
}
|
|
1370
|
+
},
|
|
1371
|
+
_functionKeys: function(resolvedArgs) {
|
|
1372
|
+
return Object.keys(resolvedArgs[0]);
|
|
1373
|
+
},
|
|
1374
|
+
_functionValues: function(resolvedArgs) {
|
|
1375
|
+
var obj = resolvedArgs[0];
|
|
1376
|
+
var keys = Object.keys(obj);
|
|
1377
|
+
var values = [];
|
|
1378
|
+
for (var i = 0; i < keys.length; i++) {
|
|
1379
|
+
values.push(obj[keys[i]]);
|
|
1380
|
+
}
|
|
1381
|
+
return values;
|
|
1382
|
+
},
|
|
1383
|
+
_functionJoin: function(resolvedArgs) {
|
|
1384
|
+
var joinChar = resolvedArgs[0];
|
|
1385
|
+
var listJoin = resolvedArgs[1];
|
|
1386
|
+
return listJoin.join(joinChar);
|
|
1387
|
+
},
|
|
1388
|
+
_functionToArray: function(resolvedArgs) {
|
|
1389
|
+
if (this._getTypeName(resolvedArgs[0]) === TYPE_ARRAY) {
|
|
1390
|
+
return resolvedArgs[0];
|
|
1391
|
+
} else {
|
|
1392
|
+
return [resolvedArgs[0]];
|
|
1393
|
+
}
|
|
1394
|
+
},
|
|
1395
|
+
_functionToString: function(resolvedArgs) {
|
|
1396
|
+
if (this._getTypeName(resolvedArgs[0]) === TYPE_STRING) {
|
|
1397
|
+
return resolvedArgs[0];
|
|
1398
|
+
} else {
|
|
1399
|
+
return JSON.stringify(resolvedArgs[0]);
|
|
1400
|
+
}
|
|
1401
|
+
},
|
|
1402
|
+
_functionToNumber: function(resolvedArgs) {
|
|
1403
|
+
var typeName = this._getTypeName(resolvedArgs[0]);
|
|
1404
|
+
var convertedValue;
|
|
1405
|
+
if (typeName === TYPE_NUMBER) {
|
|
1406
|
+
return resolvedArgs[0];
|
|
1407
|
+
} else if (typeName === TYPE_STRING) {
|
|
1408
|
+
convertedValue = +resolvedArgs[0];
|
|
1409
|
+
if (!isNaN(convertedValue)) {
|
|
1410
|
+
return convertedValue;
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
return null;
|
|
1414
|
+
},
|
|
1415
|
+
_functionNotNull: function(resolvedArgs) {
|
|
1416
|
+
for (var i = 0; i < resolvedArgs.length; i++) {
|
|
1417
|
+
if (this._getTypeName(resolvedArgs[i]) !== TYPE_NULL) {
|
|
1418
|
+
return resolvedArgs[i];
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
return null;
|
|
1422
|
+
},
|
|
1423
|
+
_functionSort: function(resolvedArgs) {
|
|
1424
|
+
var sortedArray = resolvedArgs[0].slice(0);
|
|
1425
|
+
sortedArray.sort();
|
|
1426
|
+
return sortedArray;
|
|
1427
|
+
},
|
|
1428
|
+
_functionSortBy: function(resolvedArgs) {
|
|
1429
|
+
var sortedArray = resolvedArgs[0].slice(0);
|
|
1430
|
+
if (sortedArray.length === 0) {
|
|
1431
|
+
return sortedArray;
|
|
1432
|
+
}
|
|
1433
|
+
var interpreter = this._interpreter;
|
|
1434
|
+
var exprefNode = resolvedArgs[1];
|
|
1435
|
+
var requiredType = this._getTypeName(
|
|
1436
|
+
interpreter.visit(exprefNode, sortedArray[0])
|
|
1437
|
+
);
|
|
1438
|
+
if ([TYPE_NUMBER, TYPE_STRING].indexOf(requiredType) < 0) {
|
|
1439
|
+
throw new Error("TypeError");
|
|
1440
|
+
}
|
|
1441
|
+
var that = this;
|
|
1442
|
+
var decorated = [];
|
|
1443
|
+
for (var i = 0; i < sortedArray.length; i++) {
|
|
1444
|
+
decorated.push([i, sortedArray[i]]);
|
|
1445
|
+
}
|
|
1446
|
+
decorated.sort(function(a, b) {
|
|
1447
|
+
var exprA = interpreter.visit(exprefNode, a[1]);
|
|
1448
|
+
var exprB = interpreter.visit(exprefNode, b[1]);
|
|
1449
|
+
if (that._getTypeName(exprA) !== requiredType) {
|
|
1450
|
+
throw new Error(
|
|
1451
|
+
"TypeError: expected " + requiredType + ", received " + that._getTypeName(exprA)
|
|
1452
|
+
);
|
|
1453
|
+
} else if (that._getTypeName(exprB) !== requiredType) {
|
|
1454
|
+
throw new Error(
|
|
1455
|
+
"TypeError: expected " + requiredType + ", received " + that._getTypeName(exprB)
|
|
1456
|
+
);
|
|
1457
|
+
}
|
|
1458
|
+
if (exprA > exprB) {
|
|
1459
|
+
return 1;
|
|
1460
|
+
} else if (exprA < exprB) {
|
|
1461
|
+
return -1;
|
|
1462
|
+
} else {
|
|
1463
|
+
return a[0] - b[0];
|
|
1464
|
+
}
|
|
1465
|
+
});
|
|
1466
|
+
for (var j = 0; j < decorated.length; j++) {
|
|
1467
|
+
sortedArray[j] = decorated[j][1];
|
|
1468
|
+
}
|
|
1469
|
+
return sortedArray;
|
|
1470
|
+
},
|
|
1471
|
+
_functionMaxBy: function(resolvedArgs) {
|
|
1472
|
+
var exprefNode = resolvedArgs[1];
|
|
1473
|
+
var resolvedArray = resolvedArgs[0];
|
|
1474
|
+
var keyFunction = this.createKeyFunction(exprefNode, [TYPE_NUMBER, TYPE_STRING]);
|
|
1475
|
+
var maxNumber = -Infinity;
|
|
1476
|
+
var maxRecord;
|
|
1477
|
+
var current;
|
|
1478
|
+
for (var i = 0; i < resolvedArray.length; i++) {
|
|
1479
|
+
current = keyFunction(resolvedArray[i]);
|
|
1480
|
+
if (current > maxNumber) {
|
|
1481
|
+
maxNumber = current;
|
|
1482
|
+
maxRecord = resolvedArray[i];
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
return maxRecord;
|
|
1486
|
+
},
|
|
1487
|
+
_functionMinBy: function(resolvedArgs) {
|
|
1488
|
+
var exprefNode = resolvedArgs[1];
|
|
1489
|
+
var resolvedArray = resolvedArgs[0];
|
|
1490
|
+
var keyFunction = this.createKeyFunction(exprefNode, [TYPE_NUMBER, TYPE_STRING]);
|
|
1491
|
+
var minNumber = Infinity;
|
|
1492
|
+
var minRecord;
|
|
1493
|
+
var current;
|
|
1494
|
+
for (var i = 0; i < resolvedArray.length; i++) {
|
|
1495
|
+
current = keyFunction(resolvedArray[i]);
|
|
1496
|
+
if (current < minNumber) {
|
|
1497
|
+
minNumber = current;
|
|
1498
|
+
minRecord = resolvedArray[i];
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
return minRecord;
|
|
1502
|
+
},
|
|
1503
|
+
createKeyFunction: function(exprefNode, allowedTypes) {
|
|
1504
|
+
var that = this;
|
|
1505
|
+
var interpreter = this._interpreter;
|
|
1506
|
+
var keyFunc = function(x) {
|
|
1507
|
+
var current = interpreter.visit(exprefNode, x);
|
|
1508
|
+
if (allowedTypes.indexOf(that._getTypeName(current)) < 0) {
|
|
1509
|
+
var msg = "TypeError: expected one of " + allowedTypes + ", received " + that._getTypeName(current);
|
|
1510
|
+
throw new Error(msg);
|
|
1511
|
+
}
|
|
1512
|
+
return current;
|
|
1513
|
+
};
|
|
1514
|
+
return keyFunc;
|
|
1515
|
+
}
|
|
1516
|
+
};
|
|
1517
|
+
function compile(stream) {
|
|
1518
|
+
var parser = new Parser();
|
|
1519
|
+
var ast = parser.parse(stream);
|
|
1520
|
+
return ast;
|
|
1521
|
+
}
|
|
1522
|
+
function tokenize(stream) {
|
|
1523
|
+
var lexer = new Lexer();
|
|
1524
|
+
return lexer.tokenize(stream);
|
|
1525
|
+
}
|
|
1526
|
+
function search2(data, expression) {
|
|
1527
|
+
var parser = new Parser();
|
|
1528
|
+
var runtime = new Runtime();
|
|
1529
|
+
var interpreter = new TreeInterpreter(runtime);
|
|
1530
|
+
runtime._interpreter = interpreter;
|
|
1531
|
+
var node = parser.parse(expression);
|
|
1532
|
+
return interpreter.search(node, data);
|
|
1533
|
+
}
|
|
1534
|
+
exports2.tokenize = tokenize;
|
|
1535
|
+
exports2.compile = compile;
|
|
1536
|
+
exports2.search = search2;
|
|
1537
|
+
exports2.strictDeepEqual = strictDeepEqual;
|
|
1538
|
+
})(typeof exports === "undefined" ? exports.jmespath = {} : exports);
|
|
1539
|
+
}
|
|
1540
|
+
});
|
|
1541
|
+
|
|
1542
|
+
// src/index.ts
|
|
1543
|
+
var index_exports = {};
|
|
1544
|
+
__export(index_exports, {
|
|
1545
|
+
createAsyncClient: () => createAsyncClient,
|
|
1546
|
+
createSyncClient: () => createSyncClient
|
|
1547
|
+
});
|
|
1548
|
+
|
|
1549
|
+
// src/lib.ts
|
|
1550
|
+
var jmespath = __toESM(require_jmespath(), 1);
|
|
1551
|
+
var envTagCache = /* @__PURE__ */ new Map();
|
|
1552
|
+
function getBaseUrl(token, devEnv) {
|
|
1553
|
+
let [env, siteId, ...rest] = token.split("-");
|
|
1554
|
+
if (devEnv === "production") return `https://pub.sleekcms.com/${siteId}`;
|
|
1555
|
+
else if (devEnv === "development") return `https://pub.sleekcms.net/${siteId}`;
|
|
1556
|
+
else if (devEnv === "localhost") return `http://localhost:9001/localhost/${siteId}`;
|
|
1557
|
+
else throw new Error(`[SleekCMS] Unknown devEnv: ${devEnv}`);
|
|
1558
|
+
}
|
|
1559
|
+
function applyJmes(data, query) {
|
|
1560
|
+
if (!query) return data;
|
|
1561
|
+
return jmespath.search(data, query);
|
|
1562
|
+
}
|
|
1563
|
+
function getUrl({ siteToken, env, search: search2, lang, devEnv = "production" }) {
|
|
1564
|
+
const baseUrl = getBaseUrl(siteToken, devEnv).replace(/\/$/, "");
|
|
1565
|
+
const url = new URL(`${baseUrl}/${env ?? "latest"}`);
|
|
1566
|
+
if (search2) url.searchParams.append("search", search2);
|
|
1567
|
+
if (lang) url.searchParams.append("lang", lang);
|
|
1568
|
+
return url.toString();
|
|
1569
|
+
}
|
|
1570
|
+
async function fetchEnvTag({ siteToken, env }) {
|
|
1571
|
+
const url = getUrl({ siteToken, env });
|
|
1572
|
+
try {
|
|
1573
|
+
let res = await fetch(url, {
|
|
1574
|
+
method: "POST",
|
|
1575
|
+
headers: {
|
|
1576
|
+
"Content-Type": "application/json",
|
|
1577
|
+
Authorization: siteToken
|
|
1578
|
+
}
|
|
1579
|
+
});
|
|
1580
|
+
if (res.ok) {
|
|
1581
|
+
let data = await res.json();
|
|
1582
|
+
if (data.tag) {
|
|
1583
|
+
return data.tag;
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
} catch (e) {
|
|
1587
|
+
console.error("[SleekCMS] Unable to resolve env tag.");
|
|
1588
|
+
}
|
|
1589
|
+
return env;
|
|
1590
|
+
}
|
|
1591
|
+
async function fetchSiteContent(options) {
|
|
1592
|
+
const { siteToken, env = "latest", resolveEnv = false, search: search2, lang, cache, cacheMinutes } = options;
|
|
1593
|
+
let url = getUrl({ siteToken, env, search: search2, lang });
|
|
1594
|
+
if (resolveEnv) {
|
|
1595
|
+
const cacheKey2 = `${siteToken}:${env}`;
|
|
1596
|
+
let tag = envTagCache.get(cacheKey2);
|
|
1597
|
+
try {
|
|
1598
|
+
if (!tag) {
|
|
1599
|
+
tag = await fetchEnvTag({ siteToken, env });
|
|
1600
|
+
envTagCache.set(cacheKey2, tag);
|
|
1601
|
+
}
|
|
1602
|
+
url = getUrl({ siteToken, env: tag, search: search2, lang });
|
|
1603
|
+
} catch (error) {
|
|
1604
|
+
console.warn("[SleekCMS] Failed to resolve env tag, using cached content instead.");
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
const cacheKey = url;
|
|
1608
|
+
const fetchAndCache = async () => {
|
|
1609
|
+
const res = await fetch(url, {
|
|
1610
|
+
method: "GET",
|
|
1611
|
+
headers: {
|
|
1612
|
+
"Content-Type": "application/json",
|
|
1613
|
+
Authorization: siteToken
|
|
1614
|
+
}
|
|
1615
|
+
});
|
|
1616
|
+
if (!res.ok) {
|
|
1617
|
+
let message = res.statusText;
|
|
1618
|
+
try {
|
|
1619
|
+
const data2 = await res.json();
|
|
1620
|
+
if (data2 && data2.message) message = data2.message;
|
|
1621
|
+
} catch {
|
|
1622
|
+
}
|
|
1623
|
+
throw new Error(`[SleekCMS] Request failed (${res.status}): ${message}`);
|
|
1624
|
+
}
|
|
1625
|
+
const data = await res.json();
|
|
1626
|
+
if (cache) {
|
|
1627
|
+
try {
|
|
1628
|
+
const cacheData = { data, _ts: Date.now() };
|
|
1629
|
+
await Promise.resolve(cache.setItem(cacheKey, JSON.stringify(cacheData)));
|
|
1630
|
+
} catch (e) {
|
|
1631
|
+
console.warn("[SleekCMS] Cache write failed:", e);
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
return data;
|
|
1635
|
+
};
|
|
1636
|
+
if (cache) {
|
|
1637
|
+
try {
|
|
1638
|
+
const cached = await Promise.resolve(cache.getItem(cacheKey));
|
|
1639
|
+
if (cached) {
|
|
1640
|
+
try {
|
|
1641
|
+
const cachedData = JSON.parse(cached);
|
|
1642
|
+
if (cachedData._ts !== void 0) {
|
|
1643
|
+
if (cacheMinutes) {
|
|
1644
|
+
const now = Date.now();
|
|
1645
|
+
const expiryMs = cacheMinutes * 60 * 1e3;
|
|
1646
|
+
const age = now - cachedData._ts;
|
|
1647
|
+
if (age >= expiryMs) {
|
|
1648
|
+
try {
|
|
1649
|
+
return await fetchAndCache();
|
|
1650
|
+
} catch (error) {
|
|
1651
|
+
console.warn("[SleekCMS] Fetch failed, using expired cache:", error);
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
return cachedData.data;
|
|
1656
|
+
} else {
|
|
1657
|
+
return cachedData;
|
|
1658
|
+
}
|
|
1659
|
+
} catch (e) {
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
} catch (e) {
|
|
1663
|
+
console.warn("[SleekCMS] Cache read failed:", e);
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
return await fetchAndCache();
|
|
1667
|
+
}
|
|
1668
|
+
function extractSlugs(pages, path) {
|
|
1669
|
+
const slugs = [];
|
|
1670
|
+
const pagesList = pages ?? [];
|
|
1671
|
+
for (const page of pagesList) {
|
|
1672
|
+
const pth = typeof page._path === "string" ? page._path : "";
|
|
1673
|
+
if (pth.startsWith(path) && "_slug" in page && typeof page._slug === "string") {
|
|
1674
|
+
slugs.push(page._slug);
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
return slugs;
|
|
1678
|
+
}
|
|
1679
|
+
function filterPagesByPath(pages, path, options) {
|
|
1680
|
+
const pagesList = pages ?? [];
|
|
1681
|
+
return pagesList.filter((p) => {
|
|
1682
|
+
const pth = typeof p._path === "string" ? p._path : "";
|
|
1683
|
+
if (path && !pth.startsWith(path)) return false;
|
|
1684
|
+
if (options?.collection && !("_slug" in p)) return false;
|
|
1685
|
+
return true;
|
|
1686
|
+
});
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
// src/index.ts
|
|
1690
|
+
var MemoryCache = class {
|
|
1691
|
+
cache = /* @__PURE__ */ new Map();
|
|
1692
|
+
getItem(key) {
|
|
1693
|
+
return this.cache.get(key) ?? null;
|
|
1694
|
+
}
|
|
1695
|
+
setItem(key, value) {
|
|
1696
|
+
this.cache.set(key, value);
|
|
1697
|
+
}
|
|
1698
|
+
};
|
|
1699
|
+
async function createSyncClient(options) {
|
|
1700
|
+
const cache = options.cache ?? new MemoryCache();
|
|
1701
|
+
const data = await fetchSiteContent({ ...options, cache });
|
|
1702
|
+
function getContent(query) {
|
|
1703
|
+
return applyJmes(data, query);
|
|
1704
|
+
}
|
|
1705
|
+
function getPages(path, options2) {
|
|
1706
|
+
if (!path) {
|
|
1707
|
+
throw new Error("[SleekCMS] path is required for getPages");
|
|
1708
|
+
}
|
|
1709
|
+
return filterPagesByPath(data.pages, path, options2);
|
|
1710
|
+
}
|
|
1711
|
+
function getPage(path) {
|
|
1712
|
+
if (!path) {
|
|
1713
|
+
throw new Error("[SleekCMS] path is required for getPage");
|
|
1714
|
+
}
|
|
1715
|
+
const pages = data.pages ?? [];
|
|
1716
|
+
const page = pages.find((p) => {
|
|
1717
|
+
const pth = typeof p._path === "string" ? p._path : "";
|
|
1718
|
+
return pth === path;
|
|
1719
|
+
});
|
|
1720
|
+
return page ?? null;
|
|
1721
|
+
}
|
|
1722
|
+
function getEntry(handle) {
|
|
1723
|
+
if (!handle) {
|
|
1724
|
+
throw new Error("[SleekCMS] handle is required for getEntry");
|
|
1725
|
+
}
|
|
1726
|
+
const entries = data.entries ?? {};
|
|
1727
|
+
const entry = entries[handle] ?? null;
|
|
1728
|
+
return entry;
|
|
1729
|
+
}
|
|
1730
|
+
function getSlugs(path) {
|
|
1731
|
+
if (!path) {
|
|
1732
|
+
throw new Error("[SleekCMS] path is required for getSlugs");
|
|
1733
|
+
}
|
|
1734
|
+
return extractSlugs(data.pages, path);
|
|
1735
|
+
}
|
|
1736
|
+
function getImage(name) {
|
|
1737
|
+
if (!name) return null;
|
|
1738
|
+
return data.images ? data.images[name] : null;
|
|
1739
|
+
}
|
|
1740
|
+
function getOptions(name) {
|
|
1741
|
+
if (!name) return null;
|
|
1742
|
+
const options2 = data.options ?? {};
|
|
1743
|
+
const optionSet = options2[name];
|
|
1744
|
+
return Array.isArray(optionSet) ? optionSet : null;
|
|
1745
|
+
}
|
|
1746
|
+
return {
|
|
1747
|
+
getContent,
|
|
1748
|
+
getPages,
|
|
1749
|
+
getPage,
|
|
1750
|
+
getEntry,
|
|
1751
|
+
getSlugs,
|
|
1752
|
+
getImage,
|
|
1753
|
+
getOptions
|
|
1754
|
+
};
|
|
1755
|
+
}
|
|
1756
|
+
function createAsyncClient(options) {
|
|
1757
|
+
const { siteToken, env = "latest", resolveEnv, lang } = options;
|
|
1758
|
+
const cache = options.cache ?? new MemoryCache();
|
|
1759
|
+
let syncClient = null;
|
|
1760
|
+
async function getContent(search2) {
|
|
1761
|
+
if (!search2 && !syncClient) {
|
|
1762
|
+
syncClient = await createSyncClient({ siteToken, env, resolveEnv, lang, cache });
|
|
1763
|
+
}
|
|
1764
|
+
if (syncClient) return syncClient.getContent(search2);
|
|
1765
|
+
if (!search2) return null;
|
|
1766
|
+
return await fetchSiteContent({ siteToken, env, search: search2, lang, cache, resolveEnv });
|
|
1767
|
+
}
|
|
1768
|
+
async function getPages(path, options2) {
|
|
1769
|
+
if (syncClient) return syncClient.getPages(path, options2);
|
|
1770
|
+
const pages = await fetchSiteContent({ siteToken, env, search: "pages", lang, cache, resolveEnv });
|
|
1771
|
+
return filterPagesByPath(pages, path, options2);
|
|
1772
|
+
}
|
|
1773
|
+
async function getPage(path) {
|
|
1774
|
+
if (syncClient) return syncClient.getPage(path);
|
|
1775
|
+
const pages = await fetchSiteContent({ siteToken, env, search: "pages", lang, cache, resolveEnv });
|
|
1776
|
+
const page = pages?.find((p) => {
|
|
1777
|
+
const pth = typeof p._path === "string" ? p._path : "";
|
|
1778
|
+
return pth === path;
|
|
1779
|
+
});
|
|
1780
|
+
return page ?? null;
|
|
1781
|
+
}
|
|
1782
|
+
async function getEntry(handle) {
|
|
1783
|
+
if (syncClient) return syncClient.getEntry(handle);
|
|
1784
|
+
let search2 = `entries.${handle}`;
|
|
1785
|
+
return await fetchSiteContent({ siteToken, env, search: search2, lang, cache, resolveEnv });
|
|
1786
|
+
}
|
|
1787
|
+
async function getSlugs(path) {
|
|
1788
|
+
if (syncClient) return syncClient.getSlugs(path);
|
|
1789
|
+
const pages = await fetchSiteContent({ siteToken, env, search: "pages", lang, cache, resolveEnv });
|
|
1790
|
+
return extractSlugs(pages, path);
|
|
1791
|
+
}
|
|
1792
|
+
async function getImage(name) {
|
|
1793
|
+
if (syncClient) return syncClient.getImage(name);
|
|
1794
|
+
const images = await fetchSiteContent({ siteToken, env, search: "images", lang, cache, resolveEnv });
|
|
1795
|
+
return images ? images[name] : null;
|
|
1796
|
+
}
|
|
1797
|
+
async function getOptions(name) {
|
|
1798
|
+
if (syncClient) return syncClient.getOptions(name);
|
|
1799
|
+
const options2 = await fetchSiteContent({ siteToken, env, search: "options", lang, cache, resolveEnv });
|
|
1800
|
+
const optionSet = options2[name];
|
|
1801
|
+
return Array.isArray(optionSet) ? optionSet : null;
|
|
1802
|
+
}
|
|
1803
|
+
async function _getEnvTag() {
|
|
1804
|
+
let resp = await fetchEnvTag({ siteToken, env });
|
|
1805
|
+
return resp;
|
|
1806
|
+
}
|
|
1807
|
+
function _getFetchUrl() {
|
|
1808
|
+
return getUrl(options);
|
|
1809
|
+
}
|
|
1810
|
+
return {
|
|
1811
|
+
getContent,
|
|
1812
|
+
getPages,
|
|
1813
|
+
getPage,
|
|
1814
|
+
getEntry,
|
|
1815
|
+
getSlugs,
|
|
1816
|
+
getImage,
|
|
1817
|
+
getOptions,
|
|
1818
|
+
_getFetchUrl,
|
|
1819
|
+
_getEnvTag
|
|
1820
|
+
};
|
|
1821
|
+
}
|
|
1822
|
+
return __toCommonJS(index_exports);
|
|
1823
|
+
})();
|
|
1824
|
+
//# sourceMappingURL=index.global.js.map
|