@tachybase/module-multi-app 0.23.41 → 0.23.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/AppNameInput.d.ts +1 -1
- package/dist/externalVersion.js +6 -6
- package/dist/node_modules/mariadb/package.json +1 -1
- package/dist/node_modules/qs/.editorconfig +46 -0
- package/dist/node_modules/qs/.eslintrc +39 -0
- package/dist/node_modules/qs/.github/FUNDING.yml +12 -0
- package/dist/node_modules/qs/.nycrc +13 -0
- package/dist/node_modules/qs/dist/qs.js +90 -0
- package/dist/node_modules/qs/lib/formats.js +23 -0
- package/dist/node_modules/qs/lib/index.js +1 -0
- package/dist/node_modules/qs/lib/parse.js +297 -0
- package/dist/node_modules/qs/lib/stringify.js +356 -0
- package/dist/node_modules/qs/lib/utils.js +268 -0
- package/dist/node_modules/qs/package.json +1 -0
- package/dist/node_modules/qs/test/empty-keys-cases.js +267 -0
- package/dist/node_modules/qs/test/parse.js +1187 -0
- package/dist/node_modules/qs/test/stringify.js +1306 -0
- package/dist/node_modules/qs/test/utils.js +150 -0
- package/dist/server/middlewares/app-selector.d.ts +1 -1
- package/dist/server/middlewares/app-selector.js +27 -2
- package/dist/server/migrations/20240820153000-add-apps-tmpl.js +4 -1
- package/dist/server/migrations/20241126124904-add-createdBy.js +6 -3
- package/dist/server/server.js +6 -3
- package/package.json +11 -9
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('./utils');
|
|
4
|
+
|
|
5
|
+
var has = Object.prototype.hasOwnProperty;
|
|
6
|
+
var isArray = Array.isArray;
|
|
7
|
+
|
|
8
|
+
var defaults = {
|
|
9
|
+
allowDots: false,
|
|
10
|
+
allowEmptyArrays: false,
|
|
11
|
+
allowPrototypes: false,
|
|
12
|
+
allowSparse: false,
|
|
13
|
+
arrayLimit: 20,
|
|
14
|
+
charset: 'utf-8',
|
|
15
|
+
charsetSentinel: false,
|
|
16
|
+
comma: false,
|
|
17
|
+
decodeDotInKeys: false,
|
|
18
|
+
decoder: utils.decode,
|
|
19
|
+
delimiter: '&',
|
|
20
|
+
depth: 5,
|
|
21
|
+
duplicates: 'combine',
|
|
22
|
+
ignoreQueryPrefix: false,
|
|
23
|
+
interpretNumericEntities: false,
|
|
24
|
+
parameterLimit: 1000,
|
|
25
|
+
parseArrays: true,
|
|
26
|
+
plainObjects: false,
|
|
27
|
+
strictDepth: false,
|
|
28
|
+
strictNullHandling: false
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
var interpretNumericEntities = function (str) {
|
|
32
|
+
return str.replace(/&#(\d+);/g, function ($0, numberStr) {
|
|
33
|
+
return String.fromCharCode(parseInt(numberStr, 10));
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
var parseArrayValue = function (val, options) {
|
|
38
|
+
if (val && typeof val === 'string' && options.comma && val.indexOf(',') > -1) {
|
|
39
|
+
return val.split(',');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return val;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// This is what browsers will submit when the ✓ character occurs in an
|
|
46
|
+
// application/x-www-form-urlencoded body and the encoding of the page containing
|
|
47
|
+
// the form is iso-8859-1, or when the submitted form has an accept-charset
|
|
48
|
+
// attribute of iso-8859-1. Presumably also with other charsets that do not contain
|
|
49
|
+
// the ✓ character, such as us-ascii.
|
|
50
|
+
var isoSentinel = 'utf8=%26%2310003%3B'; // encodeURIComponent('✓')
|
|
51
|
+
|
|
52
|
+
// These are the percent-encoded utf-8 octets representing a checkmark, indicating that the request actually is utf-8 encoded.
|
|
53
|
+
var charsetSentinel = 'utf8=%E2%9C%93'; // encodeURIComponent('✓')
|
|
54
|
+
|
|
55
|
+
var parseValues = function parseQueryStringValues(str, options) {
|
|
56
|
+
var obj = { __proto__: null };
|
|
57
|
+
|
|
58
|
+
var cleanStr = options.ignoreQueryPrefix ? str.replace(/^\?/, '') : str;
|
|
59
|
+
cleanStr = cleanStr.replace(/%5B/gi, '[').replace(/%5D/gi, ']');
|
|
60
|
+
var limit = options.parameterLimit === Infinity ? undefined : options.parameterLimit;
|
|
61
|
+
var parts = cleanStr.split(options.delimiter, limit);
|
|
62
|
+
var skipIndex = -1; // Keep track of where the utf8 sentinel was found
|
|
63
|
+
var i;
|
|
64
|
+
|
|
65
|
+
var charset = options.charset;
|
|
66
|
+
if (options.charsetSentinel) {
|
|
67
|
+
for (i = 0; i < parts.length; ++i) {
|
|
68
|
+
if (parts[i].indexOf('utf8=') === 0) {
|
|
69
|
+
if (parts[i] === charsetSentinel) {
|
|
70
|
+
charset = 'utf-8';
|
|
71
|
+
} else if (parts[i] === isoSentinel) {
|
|
72
|
+
charset = 'iso-8859-1';
|
|
73
|
+
}
|
|
74
|
+
skipIndex = i;
|
|
75
|
+
i = parts.length; // The eslint settings do not allow break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
for (i = 0; i < parts.length; ++i) {
|
|
81
|
+
if (i === skipIndex) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
var part = parts[i];
|
|
85
|
+
|
|
86
|
+
var bracketEqualsPos = part.indexOf(']=');
|
|
87
|
+
var pos = bracketEqualsPos === -1 ? part.indexOf('=') : bracketEqualsPos + 1;
|
|
88
|
+
|
|
89
|
+
var key;
|
|
90
|
+
var val;
|
|
91
|
+
if (pos === -1) {
|
|
92
|
+
key = options.decoder(part, defaults.decoder, charset, 'key');
|
|
93
|
+
val = options.strictNullHandling ? null : '';
|
|
94
|
+
} else {
|
|
95
|
+
key = options.decoder(part.slice(0, pos), defaults.decoder, charset, 'key');
|
|
96
|
+
val = utils.maybeMap(
|
|
97
|
+
parseArrayValue(part.slice(pos + 1), options),
|
|
98
|
+
function (encodedVal) {
|
|
99
|
+
return options.decoder(encodedVal, defaults.decoder, charset, 'value');
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (val && options.interpretNumericEntities && charset === 'iso-8859-1') {
|
|
105
|
+
val = interpretNumericEntities(String(val));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (part.indexOf('[]=') > -1) {
|
|
109
|
+
val = isArray(val) ? [val] : val;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
var existing = has.call(obj, key);
|
|
113
|
+
if (existing && options.duplicates === 'combine') {
|
|
114
|
+
obj[key] = utils.combine(obj[key], val);
|
|
115
|
+
} else if (!existing || options.duplicates === 'last') {
|
|
116
|
+
obj[key] = val;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return obj;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
var parseObject = function (chain, val, options, valuesParsed) {
|
|
124
|
+
var leaf = valuesParsed ? val : parseArrayValue(val, options);
|
|
125
|
+
|
|
126
|
+
for (var i = chain.length - 1; i >= 0; --i) {
|
|
127
|
+
var obj;
|
|
128
|
+
var root = chain[i];
|
|
129
|
+
|
|
130
|
+
if (root === '[]' && options.parseArrays) {
|
|
131
|
+
obj = options.allowEmptyArrays && (leaf === '' || (options.strictNullHandling && leaf === null))
|
|
132
|
+
? []
|
|
133
|
+
: [].concat(leaf);
|
|
134
|
+
} else {
|
|
135
|
+
obj = options.plainObjects ? { __proto__: null } : {};
|
|
136
|
+
var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
|
|
137
|
+
var decodedRoot = options.decodeDotInKeys ? cleanRoot.replace(/%2E/g, '.') : cleanRoot;
|
|
138
|
+
var index = parseInt(decodedRoot, 10);
|
|
139
|
+
if (!options.parseArrays && decodedRoot === '') {
|
|
140
|
+
obj = { 0: leaf };
|
|
141
|
+
} else if (
|
|
142
|
+
!isNaN(index)
|
|
143
|
+
&& root !== decodedRoot
|
|
144
|
+
&& String(index) === decodedRoot
|
|
145
|
+
&& index >= 0
|
|
146
|
+
&& (options.parseArrays && index <= options.arrayLimit)
|
|
147
|
+
) {
|
|
148
|
+
obj = [];
|
|
149
|
+
obj[index] = leaf;
|
|
150
|
+
} else if (decodedRoot !== '__proto__') {
|
|
151
|
+
obj[decodedRoot] = leaf;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
leaf = obj;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return leaf;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
var parseKeys = function parseQueryStringKeys(givenKey, val, options, valuesParsed) {
|
|
162
|
+
if (!givenKey) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Transform dot notation to bracket notation
|
|
167
|
+
var key = options.allowDots ? givenKey.replace(/\.([^.[]+)/g, '[$1]') : givenKey;
|
|
168
|
+
|
|
169
|
+
// The regex chunks
|
|
170
|
+
|
|
171
|
+
var brackets = /(\[[^[\]]*])/;
|
|
172
|
+
var child = /(\[[^[\]]*])/g;
|
|
173
|
+
|
|
174
|
+
// Get the parent
|
|
175
|
+
|
|
176
|
+
var segment = options.depth > 0 && brackets.exec(key);
|
|
177
|
+
var parent = segment ? key.slice(0, segment.index) : key;
|
|
178
|
+
|
|
179
|
+
// Stash the parent if it exists
|
|
180
|
+
|
|
181
|
+
var keys = [];
|
|
182
|
+
if (parent) {
|
|
183
|
+
// If we aren't using plain objects, optionally prefix keys that would overwrite object prototype properties
|
|
184
|
+
if (!options.plainObjects && has.call(Object.prototype, parent)) {
|
|
185
|
+
if (!options.allowPrototypes) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
keys.push(parent);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Loop through children appending to the array until we hit depth
|
|
194
|
+
|
|
195
|
+
var i = 0;
|
|
196
|
+
while (options.depth > 0 && (segment = child.exec(key)) !== null && i < options.depth) {
|
|
197
|
+
i += 1;
|
|
198
|
+
if (!options.plainObjects && has.call(Object.prototype, segment[1].slice(1, -1))) {
|
|
199
|
+
if (!options.allowPrototypes) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
keys.push(segment[1]);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// If there's a remainder, check strictDepth option for throw, else just add whatever is left
|
|
207
|
+
|
|
208
|
+
if (segment) {
|
|
209
|
+
if (options.strictDepth === true) {
|
|
210
|
+
throw new RangeError('Input depth exceeded depth option of ' + options.depth + ' and strictDepth is true');
|
|
211
|
+
}
|
|
212
|
+
keys.push('[' + key.slice(segment.index) + ']');
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return parseObject(keys, val, options, valuesParsed);
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
var normalizeParseOptions = function normalizeParseOptions(opts) {
|
|
219
|
+
if (!opts) {
|
|
220
|
+
return defaults;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (typeof opts.allowEmptyArrays !== 'undefined' && typeof opts.allowEmptyArrays !== 'boolean') {
|
|
224
|
+
throw new TypeError('`allowEmptyArrays` option can only be `true` or `false`, when provided');
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (typeof opts.decodeDotInKeys !== 'undefined' && typeof opts.decodeDotInKeys !== 'boolean') {
|
|
228
|
+
throw new TypeError('`decodeDotInKeys` option can only be `true` or `false`, when provided');
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (opts.decoder !== null && typeof opts.decoder !== 'undefined' && typeof opts.decoder !== 'function') {
|
|
232
|
+
throw new TypeError('Decoder has to be a function.');
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
|
|
236
|
+
throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined');
|
|
237
|
+
}
|
|
238
|
+
var charset = typeof opts.charset === 'undefined' ? defaults.charset : opts.charset;
|
|
239
|
+
|
|
240
|
+
var duplicates = typeof opts.duplicates === 'undefined' ? defaults.duplicates : opts.duplicates;
|
|
241
|
+
|
|
242
|
+
if (duplicates !== 'combine' && duplicates !== 'first' && duplicates !== 'last') {
|
|
243
|
+
throw new TypeError('The duplicates option must be either combine, first, or last');
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
var allowDots = typeof opts.allowDots === 'undefined' ? opts.decodeDotInKeys === true ? true : defaults.allowDots : !!opts.allowDots;
|
|
247
|
+
|
|
248
|
+
return {
|
|
249
|
+
allowDots: allowDots,
|
|
250
|
+
allowEmptyArrays: typeof opts.allowEmptyArrays === 'boolean' ? !!opts.allowEmptyArrays : defaults.allowEmptyArrays,
|
|
251
|
+
allowPrototypes: typeof opts.allowPrototypes === 'boolean' ? opts.allowPrototypes : defaults.allowPrototypes,
|
|
252
|
+
allowSparse: typeof opts.allowSparse === 'boolean' ? opts.allowSparse : defaults.allowSparse,
|
|
253
|
+
arrayLimit: typeof opts.arrayLimit === 'number' ? opts.arrayLimit : defaults.arrayLimit,
|
|
254
|
+
charset: charset,
|
|
255
|
+
charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
|
|
256
|
+
comma: typeof opts.comma === 'boolean' ? opts.comma : defaults.comma,
|
|
257
|
+
decodeDotInKeys: typeof opts.decodeDotInKeys === 'boolean' ? opts.decodeDotInKeys : defaults.decodeDotInKeys,
|
|
258
|
+
decoder: typeof opts.decoder === 'function' ? opts.decoder : defaults.decoder,
|
|
259
|
+
delimiter: typeof opts.delimiter === 'string' || utils.isRegExp(opts.delimiter) ? opts.delimiter : defaults.delimiter,
|
|
260
|
+
// eslint-disable-next-line no-implicit-coercion, no-extra-parens
|
|
261
|
+
depth: (typeof opts.depth === 'number' || opts.depth === false) ? +opts.depth : defaults.depth,
|
|
262
|
+
duplicates: duplicates,
|
|
263
|
+
ignoreQueryPrefix: opts.ignoreQueryPrefix === true,
|
|
264
|
+
interpretNumericEntities: typeof opts.interpretNumericEntities === 'boolean' ? opts.interpretNumericEntities : defaults.interpretNumericEntities,
|
|
265
|
+
parameterLimit: typeof opts.parameterLimit === 'number' ? opts.parameterLimit : defaults.parameterLimit,
|
|
266
|
+
parseArrays: opts.parseArrays !== false,
|
|
267
|
+
plainObjects: typeof opts.plainObjects === 'boolean' ? opts.plainObjects : defaults.plainObjects,
|
|
268
|
+
strictDepth: typeof opts.strictDepth === 'boolean' ? !!opts.strictDepth : defaults.strictDepth,
|
|
269
|
+
strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling
|
|
270
|
+
};
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
module.exports = function (str, opts) {
|
|
274
|
+
var options = normalizeParseOptions(opts);
|
|
275
|
+
|
|
276
|
+
if (str === '' || str === null || typeof str === 'undefined') {
|
|
277
|
+
return options.plainObjects ? { __proto__: null } : {};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
var tempObj = typeof str === 'string' ? parseValues(str, options) : str;
|
|
281
|
+
var obj = options.plainObjects ? { __proto__: null } : {};
|
|
282
|
+
|
|
283
|
+
// Iterate over the keys and setup the new object
|
|
284
|
+
|
|
285
|
+
var keys = Object.keys(tempObj);
|
|
286
|
+
for (var i = 0; i < keys.length; ++i) {
|
|
287
|
+
var key = keys[i];
|
|
288
|
+
var newObj = parseKeys(key, tempObj[key], options, typeof str === 'string');
|
|
289
|
+
obj = utils.merge(obj, newObj, options);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (options.allowSparse === true) {
|
|
293
|
+
return obj;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return utils.compact(obj);
|
|
297
|
+
};
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var getSideChannel = require('side-channel');
|
|
4
|
+
var utils = require('./utils');
|
|
5
|
+
var formats = require('./formats');
|
|
6
|
+
var has = Object.prototype.hasOwnProperty;
|
|
7
|
+
|
|
8
|
+
var arrayPrefixGenerators = {
|
|
9
|
+
brackets: function brackets(prefix) {
|
|
10
|
+
return prefix + '[]';
|
|
11
|
+
},
|
|
12
|
+
comma: 'comma',
|
|
13
|
+
indices: function indices(prefix, key) {
|
|
14
|
+
return prefix + '[' + key + ']';
|
|
15
|
+
},
|
|
16
|
+
repeat: function repeat(prefix) {
|
|
17
|
+
return prefix;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
var isArray = Array.isArray;
|
|
22
|
+
var push = Array.prototype.push;
|
|
23
|
+
var pushToArray = function (arr, valueOrArray) {
|
|
24
|
+
push.apply(arr, isArray(valueOrArray) ? valueOrArray : [valueOrArray]);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
var toISO = Date.prototype.toISOString;
|
|
28
|
+
|
|
29
|
+
var defaultFormat = formats['default'];
|
|
30
|
+
var defaults = {
|
|
31
|
+
addQueryPrefix: false,
|
|
32
|
+
allowDots: false,
|
|
33
|
+
allowEmptyArrays: false,
|
|
34
|
+
arrayFormat: 'indices',
|
|
35
|
+
charset: 'utf-8',
|
|
36
|
+
charsetSentinel: false,
|
|
37
|
+
commaRoundTrip: false,
|
|
38
|
+
delimiter: '&',
|
|
39
|
+
encode: true,
|
|
40
|
+
encodeDotInKeys: false,
|
|
41
|
+
encoder: utils.encode,
|
|
42
|
+
encodeValuesOnly: false,
|
|
43
|
+
filter: void undefined,
|
|
44
|
+
format: defaultFormat,
|
|
45
|
+
formatter: formats.formatters[defaultFormat],
|
|
46
|
+
// deprecated
|
|
47
|
+
indices: false,
|
|
48
|
+
serializeDate: function serializeDate(date) {
|
|
49
|
+
return toISO.call(date);
|
|
50
|
+
},
|
|
51
|
+
skipNulls: false,
|
|
52
|
+
strictNullHandling: false
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
var isNonNullishPrimitive = function isNonNullishPrimitive(v) {
|
|
56
|
+
return typeof v === 'string'
|
|
57
|
+
|| typeof v === 'number'
|
|
58
|
+
|| typeof v === 'boolean'
|
|
59
|
+
|| typeof v === 'symbol'
|
|
60
|
+
|| typeof v === 'bigint';
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
var sentinel = {};
|
|
64
|
+
|
|
65
|
+
var stringify = function stringify(
|
|
66
|
+
object,
|
|
67
|
+
prefix,
|
|
68
|
+
generateArrayPrefix,
|
|
69
|
+
commaRoundTrip,
|
|
70
|
+
allowEmptyArrays,
|
|
71
|
+
strictNullHandling,
|
|
72
|
+
skipNulls,
|
|
73
|
+
encodeDotInKeys,
|
|
74
|
+
encoder,
|
|
75
|
+
filter,
|
|
76
|
+
sort,
|
|
77
|
+
allowDots,
|
|
78
|
+
serializeDate,
|
|
79
|
+
format,
|
|
80
|
+
formatter,
|
|
81
|
+
encodeValuesOnly,
|
|
82
|
+
charset,
|
|
83
|
+
sideChannel
|
|
84
|
+
) {
|
|
85
|
+
var obj = object;
|
|
86
|
+
|
|
87
|
+
var tmpSc = sideChannel;
|
|
88
|
+
var step = 0;
|
|
89
|
+
var findFlag = false;
|
|
90
|
+
while ((tmpSc = tmpSc.get(sentinel)) !== void undefined && !findFlag) {
|
|
91
|
+
// Where object last appeared in the ref tree
|
|
92
|
+
var pos = tmpSc.get(object);
|
|
93
|
+
step += 1;
|
|
94
|
+
if (typeof pos !== 'undefined') {
|
|
95
|
+
if (pos === step) {
|
|
96
|
+
throw new RangeError('Cyclic object value');
|
|
97
|
+
} else {
|
|
98
|
+
findFlag = true; // Break while
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (typeof tmpSc.get(sentinel) === 'undefined') {
|
|
102
|
+
step = 0;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (typeof filter === 'function') {
|
|
107
|
+
obj = filter(prefix, obj);
|
|
108
|
+
} else if (obj instanceof Date) {
|
|
109
|
+
obj = serializeDate(obj);
|
|
110
|
+
} else if (generateArrayPrefix === 'comma' && isArray(obj)) {
|
|
111
|
+
obj = utils.maybeMap(obj, function (value) {
|
|
112
|
+
if (value instanceof Date) {
|
|
113
|
+
return serializeDate(value);
|
|
114
|
+
}
|
|
115
|
+
return value;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (obj === null) {
|
|
120
|
+
if (strictNullHandling) {
|
|
121
|
+
return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder, charset, 'key', format) : prefix;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
obj = '';
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (isNonNullishPrimitive(obj) || utils.isBuffer(obj)) {
|
|
128
|
+
if (encoder) {
|
|
129
|
+
var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder, charset, 'key', format);
|
|
130
|
+
return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder, charset, 'value', format))];
|
|
131
|
+
}
|
|
132
|
+
return [formatter(prefix) + '=' + formatter(String(obj))];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
var values = [];
|
|
136
|
+
|
|
137
|
+
if (typeof obj === 'undefined') {
|
|
138
|
+
return values;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
var objKeys;
|
|
142
|
+
if (generateArrayPrefix === 'comma' && isArray(obj)) {
|
|
143
|
+
// we need to join elements in
|
|
144
|
+
if (encodeValuesOnly && encoder) {
|
|
145
|
+
obj = utils.maybeMap(obj, encoder);
|
|
146
|
+
}
|
|
147
|
+
objKeys = [{ value: obj.length > 0 ? obj.join(',') || null : void undefined }];
|
|
148
|
+
} else if (isArray(filter)) {
|
|
149
|
+
objKeys = filter;
|
|
150
|
+
} else {
|
|
151
|
+
var keys = Object.keys(obj);
|
|
152
|
+
objKeys = sort ? keys.sort(sort) : keys;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
var encodedPrefix = encodeDotInKeys ? String(prefix).replace(/\./g, '%2E') : String(prefix);
|
|
156
|
+
|
|
157
|
+
var adjustedPrefix = commaRoundTrip && isArray(obj) && obj.length === 1 ? encodedPrefix + '[]' : encodedPrefix;
|
|
158
|
+
|
|
159
|
+
if (allowEmptyArrays && isArray(obj) && obj.length === 0) {
|
|
160
|
+
return adjustedPrefix + '[]';
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
for (var j = 0; j < objKeys.length; ++j) {
|
|
164
|
+
var key = objKeys[j];
|
|
165
|
+
var value = typeof key === 'object' && key && typeof key.value !== 'undefined'
|
|
166
|
+
? key.value
|
|
167
|
+
: obj[key];
|
|
168
|
+
|
|
169
|
+
if (skipNulls && value === null) {
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
var encodedKey = allowDots && encodeDotInKeys ? String(key).replace(/\./g, '%2E') : String(key);
|
|
174
|
+
var keyPrefix = isArray(obj)
|
|
175
|
+
? typeof generateArrayPrefix === 'function' ? generateArrayPrefix(adjustedPrefix, encodedKey) : adjustedPrefix
|
|
176
|
+
: adjustedPrefix + (allowDots ? '.' + encodedKey : '[' + encodedKey + ']');
|
|
177
|
+
|
|
178
|
+
sideChannel.set(object, step);
|
|
179
|
+
var valueSideChannel = getSideChannel();
|
|
180
|
+
valueSideChannel.set(sentinel, sideChannel);
|
|
181
|
+
pushToArray(values, stringify(
|
|
182
|
+
value,
|
|
183
|
+
keyPrefix,
|
|
184
|
+
generateArrayPrefix,
|
|
185
|
+
commaRoundTrip,
|
|
186
|
+
allowEmptyArrays,
|
|
187
|
+
strictNullHandling,
|
|
188
|
+
skipNulls,
|
|
189
|
+
encodeDotInKeys,
|
|
190
|
+
generateArrayPrefix === 'comma' && encodeValuesOnly && isArray(obj) ? null : encoder,
|
|
191
|
+
filter,
|
|
192
|
+
sort,
|
|
193
|
+
allowDots,
|
|
194
|
+
serializeDate,
|
|
195
|
+
format,
|
|
196
|
+
formatter,
|
|
197
|
+
encodeValuesOnly,
|
|
198
|
+
charset,
|
|
199
|
+
valueSideChannel
|
|
200
|
+
));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return values;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
var normalizeStringifyOptions = function normalizeStringifyOptions(opts) {
|
|
207
|
+
if (!opts) {
|
|
208
|
+
return defaults;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (typeof opts.allowEmptyArrays !== 'undefined' && typeof opts.allowEmptyArrays !== 'boolean') {
|
|
212
|
+
throw new TypeError('`allowEmptyArrays` option can only be `true` or `false`, when provided');
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (typeof opts.encodeDotInKeys !== 'undefined' && typeof opts.encodeDotInKeys !== 'boolean') {
|
|
216
|
+
throw new TypeError('`encodeDotInKeys` option can only be `true` or `false`, when provided');
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (opts.encoder !== null && typeof opts.encoder !== 'undefined' && typeof opts.encoder !== 'function') {
|
|
220
|
+
throw new TypeError('Encoder has to be a function.');
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
var charset = opts.charset || defaults.charset;
|
|
224
|
+
if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
|
|
225
|
+
throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined');
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
var format = formats['default'];
|
|
229
|
+
if (typeof opts.format !== 'undefined') {
|
|
230
|
+
if (!has.call(formats.formatters, opts.format)) {
|
|
231
|
+
throw new TypeError('Unknown format option provided.');
|
|
232
|
+
}
|
|
233
|
+
format = opts.format;
|
|
234
|
+
}
|
|
235
|
+
var formatter = formats.formatters[format];
|
|
236
|
+
|
|
237
|
+
var filter = defaults.filter;
|
|
238
|
+
if (typeof opts.filter === 'function' || isArray(opts.filter)) {
|
|
239
|
+
filter = opts.filter;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
var arrayFormat;
|
|
243
|
+
if (opts.arrayFormat in arrayPrefixGenerators) {
|
|
244
|
+
arrayFormat = opts.arrayFormat;
|
|
245
|
+
} else if ('indices' in opts) {
|
|
246
|
+
arrayFormat = opts.indices ? 'indices' : 'repeat';
|
|
247
|
+
} else {
|
|
248
|
+
arrayFormat = defaults.arrayFormat;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if ('commaRoundTrip' in opts && typeof opts.commaRoundTrip !== 'boolean') {
|
|
252
|
+
throw new TypeError('`commaRoundTrip` must be a boolean, or absent');
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
var allowDots = typeof opts.allowDots === 'undefined' ? opts.encodeDotInKeys === true ? true : defaults.allowDots : !!opts.allowDots;
|
|
256
|
+
|
|
257
|
+
return {
|
|
258
|
+
addQueryPrefix: typeof opts.addQueryPrefix === 'boolean' ? opts.addQueryPrefix : defaults.addQueryPrefix,
|
|
259
|
+
allowDots: allowDots,
|
|
260
|
+
allowEmptyArrays: typeof opts.allowEmptyArrays === 'boolean' ? !!opts.allowEmptyArrays : defaults.allowEmptyArrays,
|
|
261
|
+
arrayFormat: arrayFormat,
|
|
262
|
+
charset: charset,
|
|
263
|
+
charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
|
|
264
|
+
commaRoundTrip: !!opts.commaRoundTrip,
|
|
265
|
+
delimiter: typeof opts.delimiter === 'undefined' ? defaults.delimiter : opts.delimiter,
|
|
266
|
+
encode: typeof opts.encode === 'boolean' ? opts.encode : defaults.encode,
|
|
267
|
+
encodeDotInKeys: typeof opts.encodeDotInKeys === 'boolean' ? opts.encodeDotInKeys : defaults.encodeDotInKeys,
|
|
268
|
+
encoder: typeof opts.encoder === 'function' ? opts.encoder : defaults.encoder,
|
|
269
|
+
encodeValuesOnly: typeof opts.encodeValuesOnly === 'boolean' ? opts.encodeValuesOnly : defaults.encodeValuesOnly,
|
|
270
|
+
filter: filter,
|
|
271
|
+
format: format,
|
|
272
|
+
formatter: formatter,
|
|
273
|
+
serializeDate: typeof opts.serializeDate === 'function' ? opts.serializeDate : defaults.serializeDate,
|
|
274
|
+
skipNulls: typeof opts.skipNulls === 'boolean' ? opts.skipNulls : defaults.skipNulls,
|
|
275
|
+
sort: typeof opts.sort === 'function' ? opts.sort : null,
|
|
276
|
+
strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling
|
|
277
|
+
};
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
module.exports = function (object, opts) {
|
|
281
|
+
var obj = object;
|
|
282
|
+
var options = normalizeStringifyOptions(opts);
|
|
283
|
+
|
|
284
|
+
var objKeys;
|
|
285
|
+
var filter;
|
|
286
|
+
|
|
287
|
+
if (typeof options.filter === 'function') {
|
|
288
|
+
filter = options.filter;
|
|
289
|
+
obj = filter('', obj);
|
|
290
|
+
} else if (isArray(options.filter)) {
|
|
291
|
+
filter = options.filter;
|
|
292
|
+
objKeys = filter;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
var keys = [];
|
|
296
|
+
|
|
297
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
298
|
+
return '';
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
var generateArrayPrefix = arrayPrefixGenerators[options.arrayFormat];
|
|
302
|
+
var commaRoundTrip = generateArrayPrefix === 'comma' && options.commaRoundTrip;
|
|
303
|
+
|
|
304
|
+
if (!objKeys) {
|
|
305
|
+
objKeys = Object.keys(obj);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (options.sort) {
|
|
309
|
+
objKeys.sort(options.sort);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
var sideChannel = getSideChannel();
|
|
313
|
+
for (var i = 0; i < objKeys.length; ++i) {
|
|
314
|
+
var key = objKeys[i];
|
|
315
|
+
var value = obj[key];
|
|
316
|
+
|
|
317
|
+
if (options.skipNulls && value === null) {
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
pushToArray(keys, stringify(
|
|
321
|
+
value,
|
|
322
|
+
key,
|
|
323
|
+
generateArrayPrefix,
|
|
324
|
+
commaRoundTrip,
|
|
325
|
+
options.allowEmptyArrays,
|
|
326
|
+
options.strictNullHandling,
|
|
327
|
+
options.skipNulls,
|
|
328
|
+
options.encodeDotInKeys,
|
|
329
|
+
options.encode ? options.encoder : null,
|
|
330
|
+
options.filter,
|
|
331
|
+
options.sort,
|
|
332
|
+
options.allowDots,
|
|
333
|
+
options.serializeDate,
|
|
334
|
+
options.format,
|
|
335
|
+
options.formatter,
|
|
336
|
+
options.encodeValuesOnly,
|
|
337
|
+
options.charset,
|
|
338
|
+
sideChannel
|
|
339
|
+
));
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
var joined = keys.join(options.delimiter);
|
|
343
|
+
var prefix = options.addQueryPrefix === true ? '?' : '';
|
|
344
|
+
|
|
345
|
+
if (options.charsetSentinel) {
|
|
346
|
+
if (options.charset === 'iso-8859-1') {
|
|
347
|
+
// encodeURIComponent('✓'), the "numeric entity" representation of a checkmark
|
|
348
|
+
prefix += 'utf8=%26%2310003%3B&';
|
|
349
|
+
} else {
|
|
350
|
+
// encodeURIComponent('✓')
|
|
351
|
+
prefix += 'utf8=%E2%9C%93&';
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return joined.length > 0 ? prefix + joined : '';
|
|
356
|
+
};
|