langsmith 0.7.8 → 0.7.10
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 +161 -15
- package/dist/_openapi_client/client.cjs +814 -0
- package/dist/_openapi_client/client.d.ts +247 -0
- package/dist/_openapi_client/client.js +777 -0
- package/dist/_openapi_client/core/api-promise.cjs +100 -0
- package/dist/_openapi_client/core/api-promise.d.ts +45 -0
- package/dist/_openapi_client/core/api-promise.js +96 -0
- package/dist/_openapi_client/core/error.cjs +134 -0
- package/dist/_openapi_client/core/error.d.ts +45 -0
- package/dist/_openapi_client/core/error.js +118 -0
- package/dist/_openapi_client/core/pagination.cjs +374 -0
- package/dist/_openapi_client/core/pagination.d.ts +157 -0
- package/dist/_openapi_client/core/pagination.js +361 -0
- package/dist/_openapi_client/core/resource.cjs +17 -0
- package/dist/_openapi_client/core/resource.d.ts +5 -0
- package/dist/_openapi_client/core/resource.js +13 -0
- package/dist/_openapi_client/core/uploads.cjs +5 -0
- package/dist/_openapi_client/core/uploads.d.ts +2 -0
- package/dist/_openapi_client/core/uploads.js +1 -0
- package/dist/_openapi_client/index.cjs +29 -0
- package/dist/_openapi_client/index.d.ts +6 -0
- package/dist/_openapi_client/index.js +8 -0
- package/dist/_openapi_client/internal/builtin-types.cjs +4 -0
- package/dist/_openapi_client/internal/builtin-types.d.ts +72 -0
- package/dist/_openapi_client/internal/builtin-types.js +3 -0
- package/dist/_openapi_client/internal/detect-platform.cjs +162 -0
- package/dist/_openapi_client/internal/detect-platform.d.ts +14 -0
- package/dist/_openapi_client/internal/detect-platform.js +157 -0
- package/dist/_openapi_client/internal/errors.cjs +41 -0
- package/dist/_openapi_client/internal/errors.d.ts +2 -0
- package/dist/_openapi_client/internal/errors.js +36 -0
- package/dist/_openapi_client/internal/headers.cjs +79 -0
- package/dist/_openapi_client/internal/headers.d.ts +18 -0
- package/dist/_openapi_client/internal/headers.js +74 -0
- package/dist/_openapi_client/internal/parse.cjs +40 -0
- package/dist/_openapi_client/internal/parse.d.ts +11 -0
- package/dist/_openapi_client/internal/parse.js +37 -0
- package/dist/_openapi_client/internal/qs/formats.cjs +12 -0
- package/dist/_openapi_client/internal/qs/formats.d.ts +6 -0
- package/dist/_openapi_client/internal/qs/formats.js +8 -0
- package/dist/_openapi_client/internal/qs/stringify.cjs +277 -0
- package/dist/_openapi_client/internal/qs/stringify.d.ts +2 -0
- package/dist/_openapi_client/internal/qs/stringify.js +274 -0
- package/dist/_openapi_client/internal/qs/types.cjs +2 -0
- package/dist/_openapi_client/internal/qs/types.d.ts +56 -0
- package/dist/_openapi_client/internal/qs/types.js +1 -0
- package/dist/_openapi_client/internal/qs/utils.cjs +230 -0
- package/dist/_openapi_client/internal/qs/utils.d.ts +14 -0
- package/dist/_openapi_client/internal/qs/utils.js +217 -0
- package/dist/_openapi_client/internal/request-options.cjs +14 -0
- package/dist/_openapi_client/internal/request-options.d.ts +74 -0
- package/dist/_openapi_client/internal/request-options.js +10 -0
- package/dist/_openapi_client/internal/shim-types.cjs +4 -0
- package/dist/_openapi_client/internal/shim-types.d.ts +16 -0
- package/dist/_openapi_client/internal/shim-types.js +3 -0
- package/dist/_openapi_client/internal/shims.cjs +92 -0
- package/dist/_openapi_client/internal/shims.d.ts +25 -0
- package/dist/_openapi_client/internal/shims.js +85 -0
- package/dist/_openapi_client/internal/to-file.cjs +91 -0
- package/dist/_openapi_client/internal/to-file.d.ts +44 -0
- package/dist/_openapi_client/internal/to-file.js +88 -0
- package/dist/_openapi_client/internal/types.cjs +4 -0
- package/dist/_openapi_client/internal/types.d.ts +35 -0
- package/dist/_openapi_client/internal/types.js +3 -0
- package/dist/_openapi_client/internal/uploads.cjs +140 -0
- package/dist/_openapi_client/internal/uploads.d.ts +41 -0
- package/dist/_openapi_client/internal/uploads.js +130 -0
- package/dist/_openapi_client/internal/utils/env.cjs +22 -0
- package/dist/_openapi_client/internal/utils/env.d.ts +8 -0
- package/dist/_openapi_client/internal/utils/env.js +18 -0
- package/dist/_openapi_client/internal/utils/log.cjs +88 -0
- package/dist/_openapi_client/internal/utils/log.d.ts +36 -0
- package/dist/_openapi_client/internal/utils/log.js +82 -0
- package/dist/_openapi_client/internal/utils/path.cjs +79 -0
- package/dist/_openapi_client/internal/utils/path.d.ts +14 -0
- package/dist/_openapi_client/internal/utils/path.js +74 -0
- package/dist/_openapi_client/internal/utils/query.cjs +42 -0
- package/dist/_openapi_client/internal/utils/query.d.ts +1 -0
- package/dist/_openapi_client/internal/utils/query.js +6 -0
- package/dist/_openapi_client/internal/utils/sleep.cjs +7 -0
- package/dist/_openapi_client/internal/utils/sleep.d.ts +1 -0
- package/dist/_openapi_client/internal/utils/sleep.js +3 -0
- package/dist/_openapi_client/internal/utils/uuid.cjs +19 -0
- package/dist/_openapi_client/internal/utils/uuid.d.ts +4 -0
- package/dist/_openapi_client/internal/utils/uuid.js +15 -0
- package/dist/_openapi_client/internal/utils/values.cjs +112 -0
- package/dist/_openapi_client/internal/utils/values.d.ts +17 -0
- package/dist/_openapi_client/internal/utils/values.js +94 -0
- package/dist/_openapi_client/resources/annotation-queues/annotation-queues.cjs +138 -0
- package/dist/_openapi_client/resources/annotation-queues/annotation-queues.d.ts +367 -0
- package/dist/_openapi_client/resources/annotation-queues/annotation-queues.js +101 -0
- package/dist/_openapi_client/resources/annotation-queues/runs.cjs +46 -0
- package/dist/_openapi_client/resources/annotation-queues/runs.d.ts +128 -0
- package/dist/_openapi_client/resources/annotation-queues/runs.js +42 -0
- package/dist/_openapi_client/resources/commits.cjs +44 -0
- package/dist/_openapi_client/resources/commits.d.ts +204 -0
- package/dist/_openapi_client/resources/commits.js +40 -0
- package/dist/_openapi_client/resources/datasets/comparative.cjs +22 -0
- package/dist/_openapi_client/resources/datasets/comparative.d.ts +55 -0
- package/dist/_openapi_client/resources/datasets/comparative.js +18 -0
- package/dist/_openapi_client/resources/datasets/datasets.cjs +193 -0
- package/dist/_openapi_client/resources/datasets/datasets.d.ts +374 -0
- package/dist/_openapi_client/resources/datasets/datasets.js +156 -0
- package/dist/_openapi_client/resources/datasets/experiments.cjs +16 -0
- package/dist/_openapi_client/resources/datasets/experiments.d.ts +23 -0
- package/dist/_openapi_client/resources/datasets/experiments.js +12 -0
- package/dist/_openapi_client/resources/datasets/group.cjs +17 -0
- package/dist/_openapi_client/resources/datasets/group.d.ts +160 -0
- package/dist/_openapi_client/resources/datasets/group.js +13 -0
- package/dist/_openapi_client/resources/datasets/runs.cjs +29 -0
- package/dist/_openapi_client/resources/datasets/runs.d.ts +216 -0
- package/dist/_openapi_client/resources/datasets/runs.js +25 -0
- package/dist/_openapi_client/resources/datasets/share.cjs +32 -0
- package/dist/_openapi_client/resources/datasets/share.d.ts +28 -0
- package/dist/_openapi_client/resources/datasets/share.js +28 -0
- package/dist/_openapi_client/resources/datasets/splits.cjs +22 -0
- package/dist/_openapi_client/resources/datasets/splits.d.ts +30 -0
- package/dist/_openapi_client/resources/datasets/splits.js +18 -0
- package/dist/_openapi_client/resources/datasets/versions.cjs +23 -0
- package/dist/_openapi_client/resources/datasets/versions.d.ts +36 -0
- package/dist/_openapi_client/resources/datasets/versions.js +19 -0
- package/dist/_openapi_client/resources/evaluators.cjs +15 -0
- package/dist/_openapi_client/resources/evaluators.d.ts +125 -0
- package/dist/_openapi_client/resources/evaluators.js +11 -0
- package/dist/_openapi_client/resources/examples/bulk.cjs +24 -0
- package/dist/_openapi_client/resources/examples/bulk.d.ts +78 -0
- package/dist/_openapi_client/resources/examples/bulk.js +20 -0
- package/dist/_openapi_client/resources/examples/examples.cjs +124 -0
- package/dist/_openapi_client/resources/examples/examples.d.ts +182 -0
- package/dist/_openapi_client/resources/examples/examples.js +87 -0
- package/dist/_openapi_client/resources/examples/validate.cjs +21 -0
- package/dist/_openapi_client/resources/examples/validate.d.ts +38 -0
- package/dist/_openapi_client/resources/examples/validate.js +17 -0
- package/dist/_openapi_client/resources/feedback/configs.cjs +24 -0
- package/dist/_openapi_client/resources/feedback/configs.d.ts +18 -0
- package/dist/_openapi_client/resources/feedback/configs.js +20 -0
- package/dist/_openapi_client/resources/feedback/feedback.cjs +98 -0
- package/dist/_openapi_client/resources/feedback/feedback.d.ts +275 -0
- package/dist/_openapi_client/resources/feedback/feedback.js +61 -0
- package/dist/_openapi_client/resources/feedback/tokens.cjs +35 -0
- package/dist/_openapi_client/resources/feedback/tokens.d.ts +130 -0
- package/dist/_openapi_client/resources/feedback/tokens.js +31 -0
- package/dist/_openapi_client/resources/index.cjs +35 -0
- package/dist/_openapi_client/resources/index.d.ts +15 -0
- package/dist/_openapi_client/resources/index.js +17 -0
- package/dist/_openapi_client/resources/info.cjs +15 -0
- package/dist/_openapi_client/resources/info.d.ts +51 -0
- package/dist/_openapi_client/resources/info.js +11 -0
- package/dist/_openapi_client/resources/online-evaluators.cjs +70 -0
- package/dist/_openapi_client/resources/online-evaluators.d.ts +284 -0
- package/dist/_openapi_client/resources/online-evaluators.js +66 -0
- package/dist/_openapi_client/resources/public/datasets.cjs +47 -0
- package/dist/_openapi_client/resources/public/datasets.d.ts +152 -0
- package/dist/_openapi_client/resources/public/datasets.js +43 -0
- package/dist/_openapi_client/resources/public/public.cjs +62 -0
- package/dist/_openapi_client/resources/public/public.d.ts +32 -0
- package/dist/_openapi_client/resources/public/public.js +25 -0
- package/dist/_openapi_client/resources/repos/directories.cjs +40 -0
- package/dist/_openapi_client/resources/repos/directories.d.ts +72 -0
- package/dist/_openapi_client/resources/repos/directories.js +36 -0
- package/dist/_openapi_client/resources/repos/repos.cjs +93 -0
- package/dist/_openapi_client/resources/repos/repos.d.ts +188 -0
- package/dist/_openapi_client/resources/repos/repos.js +56 -0
- package/dist/_openapi_client/resources/runs/rules.cjs +9 -0
- package/dist/_openapi_client/resources/runs/rules.d.ts +3 -0
- package/dist/_openapi_client/resources/runs/rules.js +5 -0
- package/dist/_openapi_client/resources/runs/runs.cjs +102 -0
- package/dist/_openapi_client/resources/runs/runs.d.ts +542 -0
- package/dist/_openapi_client/resources/runs/runs.js +65 -0
- package/dist/_openapi_client/resources/sandboxes/boxes.cjs +86 -0
- package/dist/_openapi_client/resources/sandboxes/boxes.d.ts +1121 -0
- package/dist/_openapi_client/resources/sandboxes/boxes.js +82 -0
- package/dist/_openapi_client/resources/sandboxes/sandboxes.cjs +63 -0
- package/dist/_openapi_client/resources/sandboxes/sandboxes.d.ts +13 -0
- package/dist/_openapi_client/resources/sandboxes/sandboxes.js +26 -0
- package/dist/_openapi_client/resources/sandboxes/snapshots.cjs +39 -0
- package/dist/_openapi_client/resources/sandboxes/snapshots.d.ts +130 -0
- package/dist/_openapi_client/resources/sandboxes/snapshots.js +35 -0
- package/dist/_openapi_client/resources/sessions/insights.cjs +54 -0
- package/dist/_openapi_client/resources/sessions/insights.d.ts +246 -0
- package/dist/_openapi_client/resources/sessions/insights.js +50 -0
- package/dist/_openapi_client/resources/sessions/sessions.cjs +109 -0
- package/dist/_openapi_client/resources/sessions/sessions.d.ts +674 -0
- package/dist/_openapi_client/resources/sessions/sessions.js +72 -0
- package/dist/_openapi_client/resources/settings.cjs +15 -0
- package/dist/_openapi_client/resources/settings.d.ts +18 -0
- package/dist/_openapi_client/resources/settings.js +11 -0
- package/dist/_openapi_client/resources/workspaces.cjs +35 -0
- package/dist/_openapi_client/resources/workspaces.d.ts +84 -0
- package/dist/_openapi_client/resources/workspaces.js +31 -0
- package/dist/_openapi_client/version.cjs +5 -0
- package/dist/_openapi_client/version.d.ts +1 -0
- package/dist/_openapi_client/version.js +2 -0
- package/dist/client.cjs +48 -19
- package/dist/client.d.ts +5 -0
- package/dist/client.js +29 -0
- package/dist/env.cjs +3 -3
- package/dist/env.d.ts +1 -1
- package/dist/env.js +1 -1
- package/dist/experimental/otel/exporter.cjs +1 -1
- package/dist/experimental/otel/exporter.js +2 -2
- package/dist/experimental/vercel/telemetry.cjs +1 -1
- package/dist/experimental/vercel/telemetry.js +2 -2
- package/dist/index.cjs +4 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/run_trees.cjs +1 -1
- package/dist/run_trees.js +2 -2
- package/dist/sandbox/client.cjs +11 -3
- package/dist/sandbox/client.js +11 -3
- package/dist/sandbox/index.cjs +8 -2
- package/dist/sandbox/index.d.ts +3 -2
- package/dist/sandbox/index.js +2 -1
- package/dist/sandbox/mounts.cjs +114 -0
- package/dist/sandbox/mounts.d.ts +24 -0
- package/dist/sandbox/mounts.js +109 -0
- package/dist/sandbox/proxy_config.cjs +90 -5
- package/dist/sandbox/proxy_config.d.ts +19 -4
- package/dist/sandbox/proxy_config.js +86 -4
- package/dist/sandbox/types.d.ts +92 -3
- package/dist/traceable.cjs +1 -1
- package/dist/traceable.js +2 -2
- package/dist/utils/guard.cjs +13 -0
- package/dist/utils/guard.d.ts +6 -0
- package/dist/utils/guard.js +10 -0
- package/dist/utils/jestlike/globals.cjs +1 -1
- package/dist/utils/jestlike/globals.js +2 -2
- package/package.json +2 -2
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
3
|
+
import { formatRequestDetails, loggerFor } from './utils/log.js';
|
|
4
|
+
export async function defaultParseResponse(client, props) {
|
|
5
|
+
const { response, requestLogID, retryOfRequestLogID, startTime } = props;
|
|
6
|
+
const body = await (async () => {
|
|
7
|
+
// fetch refuses to read the body when the status code is 204.
|
|
8
|
+
if (response.status === 204) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
if (props.options.__binaryResponse) {
|
|
12
|
+
return response;
|
|
13
|
+
}
|
|
14
|
+
const contentType = response.headers.get('content-type');
|
|
15
|
+
const mediaType = contentType?.split(';')[0]?.trim();
|
|
16
|
+
const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
|
|
17
|
+
if (isJSON) {
|
|
18
|
+
const contentLength = response.headers.get('content-length');
|
|
19
|
+
if (contentLength === '0') {
|
|
20
|
+
// if there is no content we can't do anything
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
const json = await response.json();
|
|
24
|
+
return json;
|
|
25
|
+
}
|
|
26
|
+
const text = await response.text();
|
|
27
|
+
return text;
|
|
28
|
+
})();
|
|
29
|
+
loggerFor(client).debug(`[${requestLogID}] response parsed`, formatRequestDetails({
|
|
30
|
+
retryOfRequestLogID,
|
|
31
|
+
url: response.url,
|
|
32
|
+
status: response.status,
|
|
33
|
+
body,
|
|
34
|
+
durationMs: Date.now() - startTime,
|
|
35
|
+
}));
|
|
36
|
+
return body;
|
|
37
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RFC3986 = exports.RFC1738 = exports.formatters = exports.default_formatter = exports.default_format = void 0;
|
|
4
|
+
exports.default_format = 'RFC3986';
|
|
5
|
+
const default_formatter = (v) => String(v);
|
|
6
|
+
exports.default_formatter = default_formatter;
|
|
7
|
+
exports.formatters = {
|
|
8
|
+
RFC1738: (v) => String(v).replace(/%20/g, '+'),
|
|
9
|
+
RFC3986: exports.default_formatter,
|
|
10
|
+
};
|
|
11
|
+
exports.RFC1738 = 'RFC1738';
|
|
12
|
+
exports.RFC3986 = 'RFC3986';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Format } from './types.js';
|
|
2
|
+
export declare const default_format: Format;
|
|
3
|
+
export declare const default_formatter: (v: PropertyKey) => string;
|
|
4
|
+
export declare const formatters: Record<Format, (str: PropertyKey) => string>;
|
|
5
|
+
export declare const RFC1738 = "RFC1738";
|
|
6
|
+
export declare const RFC3986 = "RFC3986";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const default_format = 'RFC3986';
|
|
2
|
+
export const default_formatter = (v) => String(v);
|
|
3
|
+
export const formatters = {
|
|
4
|
+
RFC1738: (v) => String(v).replace(/%20/g, '+'),
|
|
5
|
+
RFC3986: default_formatter,
|
|
6
|
+
};
|
|
7
|
+
export const RFC1738 = 'RFC1738';
|
|
8
|
+
export const RFC3986 = 'RFC3986';
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringify = stringify;
|
|
4
|
+
// @ts-nocheck
|
|
5
|
+
const utils_js_1 = require("./utils.cjs");
|
|
6
|
+
const formats_js_1 = require("./formats.cjs");
|
|
7
|
+
const values_js_1 = require("../utils/values.cjs");
|
|
8
|
+
const array_prefix_generators = {
|
|
9
|
+
brackets(prefix) {
|
|
10
|
+
return String(prefix) + '[]';
|
|
11
|
+
},
|
|
12
|
+
comma: 'comma',
|
|
13
|
+
indices(prefix, key) {
|
|
14
|
+
return String(prefix) + '[' + key + ']';
|
|
15
|
+
},
|
|
16
|
+
repeat(prefix) {
|
|
17
|
+
return String(prefix);
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
const push_to_array = function (arr, value_or_array) {
|
|
21
|
+
Array.prototype.push.apply(arr, (0, values_js_1.isArray)(value_or_array) ? value_or_array : [value_or_array]);
|
|
22
|
+
};
|
|
23
|
+
let toISOString;
|
|
24
|
+
const defaults = {
|
|
25
|
+
addQueryPrefix: false,
|
|
26
|
+
allowDots: false,
|
|
27
|
+
allowEmptyArrays: false,
|
|
28
|
+
arrayFormat: 'indices',
|
|
29
|
+
charset: 'utf-8',
|
|
30
|
+
charsetSentinel: false,
|
|
31
|
+
delimiter: '&',
|
|
32
|
+
encode: true,
|
|
33
|
+
encodeDotInKeys: false,
|
|
34
|
+
encoder: utils_js_1.encode,
|
|
35
|
+
encodeValuesOnly: false,
|
|
36
|
+
format: formats_js_1.default_format,
|
|
37
|
+
formatter: formats_js_1.default_formatter,
|
|
38
|
+
/** @deprecated */
|
|
39
|
+
indices: false,
|
|
40
|
+
serializeDate(date) {
|
|
41
|
+
return (toISOString ??= Function.prototype.call.bind(Date.prototype.toISOString))(date);
|
|
42
|
+
},
|
|
43
|
+
skipNulls: false,
|
|
44
|
+
strictNullHandling: false,
|
|
45
|
+
};
|
|
46
|
+
function is_non_nullish_primitive(v) {
|
|
47
|
+
return (typeof v === 'string' ||
|
|
48
|
+
typeof v === 'number' ||
|
|
49
|
+
typeof v === 'boolean' ||
|
|
50
|
+
typeof v === 'symbol' ||
|
|
51
|
+
typeof v === 'bigint');
|
|
52
|
+
}
|
|
53
|
+
const sentinel = {};
|
|
54
|
+
function inner_stringify(object, prefix, generateArrayPrefix, commaRoundTrip, allowEmptyArrays, strictNullHandling, skipNulls, encodeDotInKeys, encoder, filter, sort, allowDots, serializeDate, format, formatter, encodeValuesOnly, charset, sideChannel) {
|
|
55
|
+
let obj = object;
|
|
56
|
+
let tmp_sc = sideChannel;
|
|
57
|
+
let step = 0;
|
|
58
|
+
let find_flag = false;
|
|
59
|
+
while ((tmp_sc = tmp_sc.get(sentinel)) !== void undefined && !find_flag) {
|
|
60
|
+
// Where object last appeared in the ref tree
|
|
61
|
+
const pos = tmp_sc.get(object);
|
|
62
|
+
step += 1;
|
|
63
|
+
if (typeof pos !== 'undefined') {
|
|
64
|
+
if (pos === step) {
|
|
65
|
+
throw new RangeError('Cyclic object value');
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
find_flag = true; // Break while
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (typeof tmp_sc.get(sentinel) === 'undefined') {
|
|
72
|
+
step = 0;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (typeof filter === 'function') {
|
|
76
|
+
obj = filter(prefix, obj);
|
|
77
|
+
}
|
|
78
|
+
else if (obj instanceof Date) {
|
|
79
|
+
obj = serializeDate?.(obj);
|
|
80
|
+
}
|
|
81
|
+
else if (generateArrayPrefix === 'comma' && (0, values_js_1.isArray)(obj)) {
|
|
82
|
+
obj = (0, utils_js_1.maybe_map)(obj, function (value) {
|
|
83
|
+
if (value instanceof Date) {
|
|
84
|
+
return serializeDate?.(value);
|
|
85
|
+
}
|
|
86
|
+
return value;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (obj === null) {
|
|
90
|
+
if (strictNullHandling) {
|
|
91
|
+
return encoder && !encodeValuesOnly ?
|
|
92
|
+
// @ts-expect-error
|
|
93
|
+
encoder(prefix, defaults.encoder, charset, 'key', format)
|
|
94
|
+
: prefix;
|
|
95
|
+
}
|
|
96
|
+
obj = '';
|
|
97
|
+
}
|
|
98
|
+
if (is_non_nullish_primitive(obj) || (0, utils_js_1.is_buffer)(obj)) {
|
|
99
|
+
if (encoder) {
|
|
100
|
+
const key_value = encodeValuesOnly ? prefix
|
|
101
|
+
// @ts-expect-error
|
|
102
|
+
: encoder(prefix, defaults.encoder, charset, 'key', format);
|
|
103
|
+
return [
|
|
104
|
+
formatter?.(key_value) +
|
|
105
|
+
'=' +
|
|
106
|
+
// @ts-expect-error
|
|
107
|
+
formatter?.(encoder(obj, defaults.encoder, charset, 'value', format)),
|
|
108
|
+
];
|
|
109
|
+
}
|
|
110
|
+
return [formatter?.(prefix) + '=' + formatter?.(String(obj))];
|
|
111
|
+
}
|
|
112
|
+
const values = [];
|
|
113
|
+
if (typeof obj === 'undefined') {
|
|
114
|
+
return values;
|
|
115
|
+
}
|
|
116
|
+
let obj_keys;
|
|
117
|
+
if (generateArrayPrefix === 'comma' && (0, values_js_1.isArray)(obj)) {
|
|
118
|
+
// we need to join elements in
|
|
119
|
+
if (encodeValuesOnly && encoder) {
|
|
120
|
+
// @ts-expect-error values only
|
|
121
|
+
obj = (0, utils_js_1.maybe_map)(obj, encoder);
|
|
122
|
+
}
|
|
123
|
+
obj_keys = [{ value: obj.length > 0 ? obj.join(',') || null : void undefined }];
|
|
124
|
+
}
|
|
125
|
+
else if ((0, values_js_1.isArray)(filter)) {
|
|
126
|
+
obj_keys = filter;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
const keys = Object.keys(obj);
|
|
130
|
+
obj_keys = sort ? keys.sort(sort) : keys;
|
|
131
|
+
}
|
|
132
|
+
const encoded_prefix = encodeDotInKeys ? String(prefix).replace(/\./g, '%2E') : String(prefix);
|
|
133
|
+
const adjusted_prefix = commaRoundTrip && (0, values_js_1.isArray)(obj) && obj.length === 1 ? encoded_prefix + '[]' : encoded_prefix;
|
|
134
|
+
if (allowEmptyArrays && (0, values_js_1.isArray)(obj) && obj.length === 0) {
|
|
135
|
+
return adjusted_prefix + '[]';
|
|
136
|
+
}
|
|
137
|
+
for (let j = 0; j < obj_keys.length; ++j) {
|
|
138
|
+
const key = obj_keys[j];
|
|
139
|
+
const value =
|
|
140
|
+
// @ts-ignore
|
|
141
|
+
typeof key === 'object' && typeof key.value !== 'undefined' ? key.value : obj[key];
|
|
142
|
+
if (skipNulls && value === null) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
// @ts-ignore
|
|
146
|
+
const encoded_key = allowDots && encodeDotInKeys ? key.replace(/\./g, '%2E') : key;
|
|
147
|
+
const key_prefix = (0, values_js_1.isArray)(obj) ?
|
|
148
|
+
typeof generateArrayPrefix === 'function' ?
|
|
149
|
+
generateArrayPrefix(adjusted_prefix, encoded_key)
|
|
150
|
+
: adjusted_prefix
|
|
151
|
+
: adjusted_prefix + (allowDots ? '.' + encoded_key : '[' + encoded_key + ']');
|
|
152
|
+
sideChannel.set(object, step);
|
|
153
|
+
const valueSideChannel = new WeakMap();
|
|
154
|
+
valueSideChannel.set(sentinel, sideChannel);
|
|
155
|
+
push_to_array(values, inner_stringify(value, key_prefix, generateArrayPrefix, commaRoundTrip, allowEmptyArrays, strictNullHandling, skipNulls, encodeDotInKeys,
|
|
156
|
+
// @ts-ignore
|
|
157
|
+
generateArrayPrefix === 'comma' && encodeValuesOnly && (0, values_js_1.isArray)(obj) ? null : encoder, filter, sort, allowDots, serializeDate, format, formatter, encodeValuesOnly, charset, valueSideChannel));
|
|
158
|
+
}
|
|
159
|
+
return values;
|
|
160
|
+
}
|
|
161
|
+
function normalize_stringify_options(opts = defaults) {
|
|
162
|
+
if (typeof opts.allowEmptyArrays !== 'undefined' && typeof opts.allowEmptyArrays !== 'boolean') {
|
|
163
|
+
throw new TypeError('`allowEmptyArrays` option can only be `true` or `false`, when provided');
|
|
164
|
+
}
|
|
165
|
+
if (typeof opts.encodeDotInKeys !== 'undefined' && typeof opts.encodeDotInKeys !== 'boolean') {
|
|
166
|
+
throw new TypeError('`encodeDotInKeys` option can only be `true` or `false`, when provided');
|
|
167
|
+
}
|
|
168
|
+
if (opts.encoder !== null && typeof opts.encoder !== 'undefined' && typeof opts.encoder !== 'function') {
|
|
169
|
+
throw new TypeError('Encoder has to be a function.');
|
|
170
|
+
}
|
|
171
|
+
const charset = opts.charset || defaults.charset;
|
|
172
|
+
if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
|
|
173
|
+
throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined');
|
|
174
|
+
}
|
|
175
|
+
let format = formats_js_1.default_format;
|
|
176
|
+
if (typeof opts.format !== 'undefined') {
|
|
177
|
+
if (!(0, utils_js_1.has)(formats_js_1.formatters, opts.format)) {
|
|
178
|
+
throw new TypeError('Unknown format option provided.');
|
|
179
|
+
}
|
|
180
|
+
format = opts.format;
|
|
181
|
+
}
|
|
182
|
+
const formatter = formats_js_1.formatters[format];
|
|
183
|
+
let filter = defaults.filter;
|
|
184
|
+
if (typeof opts.filter === 'function' || (0, values_js_1.isArray)(opts.filter)) {
|
|
185
|
+
filter = opts.filter;
|
|
186
|
+
}
|
|
187
|
+
let arrayFormat;
|
|
188
|
+
if (opts.arrayFormat && opts.arrayFormat in array_prefix_generators) {
|
|
189
|
+
arrayFormat = opts.arrayFormat;
|
|
190
|
+
}
|
|
191
|
+
else if ('indices' in opts) {
|
|
192
|
+
arrayFormat = opts.indices ? 'indices' : 'repeat';
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
arrayFormat = defaults.arrayFormat;
|
|
196
|
+
}
|
|
197
|
+
if ('commaRoundTrip' in opts && typeof opts.commaRoundTrip !== 'boolean') {
|
|
198
|
+
throw new TypeError('`commaRoundTrip` must be a boolean, or absent');
|
|
199
|
+
}
|
|
200
|
+
const allowDots = typeof opts.allowDots === 'undefined' ?
|
|
201
|
+
!!opts.encodeDotInKeys === true ?
|
|
202
|
+
true
|
|
203
|
+
: defaults.allowDots
|
|
204
|
+
: !!opts.allowDots;
|
|
205
|
+
return {
|
|
206
|
+
addQueryPrefix: typeof opts.addQueryPrefix === 'boolean' ? opts.addQueryPrefix : defaults.addQueryPrefix,
|
|
207
|
+
// @ts-ignore
|
|
208
|
+
allowDots: allowDots,
|
|
209
|
+
allowEmptyArrays: typeof opts.allowEmptyArrays === 'boolean' ? !!opts.allowEmptyArrays : defaults.allowEmptyArrays,
|
|
210
|
+
arrayFormat: arrayFormat,
|
|
211
|
+
charset: charset,
|
|
212
|
+
charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
|
|
213
|
+
commaRoundTrip: !!opts.commaRoundTrip,
|
|
214
|
+
delimiter: typeof opts.delimiter === 'undefined' ? defaults.delimiter : opts.delimiter,
|
|
215
|
+
encode: typeof opts.encode === 'boolean' ? opts.encode : defaults.encode,
|
|
216
|
+
encodeDotInKeys: typeof opts.encodeDotInKeys === 'boolean' ? opts.encodeDotInKeys : defaults.encodeDotInKeys,
|
|
217
|
+
encoder: typeof opts.encoder === 'function' ? opts.encoder : defaults.encoder,
|
|
218
|
+
encodeValuesOnly: typeof opts.encodeValuesOnly === 'boolean' ? opts.encodeValuesOnly : defaults.encodeValuesOnly,
|
|
219
|
+
filter: filter,
|
|
220
|
+
format: format,
|
|
221
|
+
formatter: formatter,
|
|
222
|
+
serializeDate: typeof opts.serializeDate === 'function' ? opts.serializeDate : defaults.serializeDate,
|
|
223
|
+
skipNulls: typeof opts.skipNulls === 'boolean' ? opts.skipNulls : defaults.skipNulls,
|
|
224
|
+
// @ts-ignore
|
|
225
|
+
sort: typeof opts.sort === 'function' ? opts.sort : null,
|
|
226
|
+
strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
function stringify(object, opts = {}) {
|
|
230
|
+
let obj = object;
|
|
231
|
+
const options = normalize_stringify_options(opts);
|
|
232
|
+
let obj_keys;
|
|
233
|
+
let filter;
|
|
234
|
+
if (typeof options.filter === 'function') {
|
|
235
|
+
filter = options.filter;
|
|
236
|
+
obj = filter('', obj);
|
|
237
|
+
}
|
|
238
|
+
else if ((0, values_js_1.isArray)(options.filter)) {
|
|
239
|
+
filter = options.filter;
|
|
240
|
+
obj_keys = filter;
|
|
241
|
+
}
|
|
242
|
+
const keys = [];
|
|
243
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
244
|
+
return '';
|
|
245
|
+
}
|
|
246
|
+
const generateArrayPrefix = array_prefix_generators[options.arrayFormat];
|
|
247
|
+
const commaRoundTrip = generateArrayPrefix === 'comma' && options.commaRoundTrip;
|
|
248
|
+
if (!obj_keys) {
|
|
249
|
+
obj_keys = Object.keys(obj);
|
|
250
|
+
}
|
|
251
|
+
if (options.sort) {
|
|
252
|
+
obj_keys.sort(options.sort);
|
|
253
|
+
}
|
|
254
|
+
const sideChannel = new WeakMap();
|
|
255
|
+
for (let i = 0; i < obj_keys.length; ++i) {
|
|
256
|
+
const key = obj_keys[i];
|
|
257
|
+
if (options.skipNulls && obj[key] === null) {
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
push_to_array(keys, inner_stringify(obj[key], key,
|
|
261
|
+
// @ts-expect-error
|
|
262
|
+
generateArrayPrefix, commaRoundTrip, options.allowEmptyArrays, options.strictNullHandling, options.skipNulls, options.encodeDotInKeys, options.encode ? options.encoder : null, options.filter, options.sort, options.allowDots, options.serializeDate, options.format, options.formatter, options.encodeValuesOnly, options.charset, sideChannel));
|
|
263
|
+
}
|
|
264
|
+
const joined = keys.join(options.delimiter);
|
|
265
|
+
let prefix = options.addQueryPrefix === true ? '?' : '';
|
|
266
|
+
if (options.charsetSentinel) {
|
|
267
|
+
if (options.charset === 'iso-8859-1') {
|
|
268
|
+
// encodeURIComponent('✓'), the "numeric entity" representation of a checkmark
|
|
269
|
+
prefix += 'utf8=%26%2310003%3B&';
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
// encodeURIComponent('✓')
|
|
273
|
+
prefix += 'utf8=%E2%9C%93&';
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return joined.length > 0 ? prefix + joined : '';
|
|
277
|
+
}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import { encode, is_buffer, maybe_map, has } from './utils.js';
|
|
3
|
+
import { default_format, default_formatter, formatters } from './formats.js';
|
|
4
|
+
import { isArray } from '../utils/values.js';
|
|
5
|
+
const array_prefix_generators = {
|
|
6
|
+
brackets(prefix) {
|
|
7
|
+
return String(prefix) + '[]';
|
|
8
|
+
},
|
|
9
|
+
comma: 'comma',
|
|
10
|
+
indices(prefix, key) {
|
|
11
|
+
return String(prefix) + '[' + key + ']';
|
|
12
|
+
},
|
|
13
|
+
repeat(prefix) {
|
|
14
|
+
return String(prefix);
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
const push_to_array = function (arr, value_or_array) {
|
|
18
|
+
Array.prototype.push.apply(arr, isArray(value_or_array) ? value_or_array : [value_or_array]);
|
|
19
|
+
};
|
|
20
|
+
let toISOString;
|
|
21
|
+
const defaults = {
|
|
22
|
+
addQueryPrefix: false,
|
|
23
|
+
allowDots: false,
|
|
24
|
+
allowEmptyArrays: false,
|
|
25
|
+
arrayFormat: 'indices',
|
|
26
|
+
charset: 'utf-8',
|
|
27
|
+
charsetSentinel: false,
|
|
28
|
+
delimiter: '&',
|
|
29
|
+
encode: true,
|
|
30
|
+
encodeDotInKeys: false,
|
|
31
|
+
encoder: encode,
|
|
32
|
+
encodeValuesOnly: false,
|
|
33
|
+
format: default_format,
|
|
34
|
+
formatter: default_formatter,
|
|
35
|
+
/** @deprecated */
|
|
36
|
+
indices: false,
|
|
37
|
+
serializeDate(date) {
|
|
38
|
+
return (toISOString ??= Function.prototype.call.bind(Date.prototype.toISOString))(date);
|
|
39
|
+
},
|
|
40
|
+
skipNulls: false,
|
|
41
|
+
strictNullHandling: false,
|
|
42
|
+
};
|
|
43
|
+
function is_non_nullish_primitive(v) {
|
|
44
|
+
return (typeof v === 'string' ||
|
|
45
|
+
typeof v === 'number' ||
|
|
46
|
+
typeof v === 'boolean' ||
|
|
47
|
+
typeof v === 'symbol' ||
|
|
48
|
+
typeof v === 'bigint');
|
|
49
|
+
}
|
|
50
|
+
const sentinel = {};
|
|
51
|
+
function inner_stringify(object, prefix, generateArrayPrefix, commaRoundTrip, allowEmptyArrays, strictNullHandling, skipNulls, encodeDotInKeys, encoder, filter, sort, allowDots, serializeDate, format, formatter, encodeValuesOnly, charset, sideChannel) {
|
|
52
|
+
let obj = object;
|
|
53
|
+
let tmp_sc = sideChannel;
|
|
54
|
+
let step = 0;
|
|
55
|
+
let find_flag = false;
|
|
56
|
+
while ((tmp_sc = tmp_sc.get(sentinel)) !== void undefined && !find_flag) {
|
|
57
|
+
// Where object last appeared in the ref tree
|
|
58
|
+
const pos = tmp_sc.get(object);
|
|
59
|
+
step += 1;
|
|
60
|
+
if (typeof pos !== 'undefined') {
|
|
61
|
+
if (pos === step) {
|
|
62
|
+
throw new RangeError('Cyclic object value');
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
find_flag = true; // Break while
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (typeof tmp_sc.get(sentinel) === 'undefined') {
|
|
69
|
+
step = 0;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (typeof filter === 'function') {
|
|
73
|
+
obj = filter(prefix, obj);
|
|
74
|
+
}
|
|
75
|
+
else if (obj instanceof Date) {
|
|
76
|
+
obj = serializeDate?.(obj);
|
|
77
|
+
}
|
|
78
|
+
else if (generateArrayPrefix === 'comma' && isArray(obj)) {
|
|
79
|
+
obj = maybe_map(obj, function (value) {
|
|
80
|
+
if (value instanceof Date) {
|
|
81
|
+
return serializeDate?.(value);
|
|
82
|
+
}
|
|
83
|
+
return value;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if (obj === null) {
|
|
87
|
+
if (strictNullHandling) {
|
|
88
|
+
return encoder && !encodeValuesOnly ?
|
|
89
|
+
// @ts-expect-error
|
|
90
|
+
encoder(prefix, defaults.encoder, charset, 'key', format)
|
|
91
|
+
: prefix;
|
|
92
|
+
}
|
|
93
|
+
obj = '';
|
|
94
|
+
}
|
|
95
|
+
if (is_non_nullish_primitive(obj) || is_buffer(obj)) {
|
|
96
|
+
if (encoder) {
|
|
97
|
+
const key_value = encodeValuesOnly ? prefix
|
|
98
|
+
// @ts-expect-error
|
|
99
|
+
: encoder(prefix, defaults.encoder, charset, 'key', format);
|
|
100
|
+
return [
|
|
101
|
+
formatter?.(key_value) +
|
|
102
|
+
'=' +
|
|
103
|
+
// @ts-expect-error
|
|
104
|
+
formatter?.(encoder(obj, defaults.encoder, charset, 'value', format)),
|
|
105
|
+
];
|
|
106
|
+
}
|
|
107
|
+
return [formatter?.(prefix) + '=' + formatter?.(String(obj))];
|
|
108
|
+
}
|
|
109
|
+
const values = [];
|
|
110
|
+
if (typeof obj === 'undefined') {
|
|
111
|
+
return values;
|
|
112
|
+
}
|
|
113
|
+
let obj_keys;
|
|
114
|
+
if (generateArrayPrefix === 'comma' && isArray(obj)) {
|
|
115
|
+
// we need to join elements in
|
|
116
|
+
if (encodeValuesOnly && encoder) {
|
|
117
|
+
// @ts-expect-error values only
|
|
118
|
+
obj = maybe_map(obj, encoder);
|
|
119
|
+
}
|
|
120
|
+
obj_keys = [{ value: obj.length > 0 ? obj.join(',') || null : void undefined }];
|
|
121
|
+
}
|
|
122
|
+
else if (isArray(filter)) {
|
|
123
|
+
obj_keys = filter;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
const keys = Object.keys(obj);
|
|
127
|
+
obj_keys = sort ? keys.sort(sort) : keys;
|
|
128
|
+
}
|
|
129
|
+
const encoded_prefix = encodeDotInKeys ? String(prefix).replace(/\./g, '%2E') : String(prefix);
|
|
130
|
+
const adjusted_prefix = commaRoundTrip && isArray(obj) && obj.length === 1 ? encoded_prefix + '[]' : encoded_prefix;
|
|
131
|
+
if (allowEmptyArrays && isArray(obj) && obj.length === 0) {
|
|
132
|
+
return adjusted_prefix + '[]';
|
|
133
|
+
}
|
|
134
|
+
for (let j = 0; j < obj_keys.length; ++j) {
|
|
135
|
+
const key = obj_keys[j];
|
|
136
|
+
const value =
|
|
137
|
+
// @ts-ignore
|
|
138
|
+
typeof key === 'object' && typeof key.value !== 'undefined' ? key.value : obj[key];
|
|
139
|
+
if (skipNulls && value === null) {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
// @ts-ignore
|
|
143
|
+
const encoded_key = allowDots && encodeDotInKeys ? key.replace(/\./g, '%2E') : key;
|
|
144
|
+
const key_prefix = isArray(obj) ?
|
|
145
|
+
typeof generateArrayPrefix === 'function' ?
|
|
146
|
+
generateArrayPrefix(adjusted_prefix, encoded_key)
|
|
147
|
+
: adjusted_prefix
|
|
148
|
+
: adjusted_prefix + (allowDots ? '.' + encoded_key : '[' + encoded_key + ']');
|
|
149
|
+
sideChannel.set(object, step);
|
|
150
|
+
const valueSideChannel = new WeakMap();
|
|
151
|
+
valueSideChannel.set(sentinel, sideChannel);
|
|
152
|
+
push_to_array(values, inner_stringify(value, key_prefix, generateArrayPrefix, commaRoundTrip, allowEmptyArrays, strictNullHandling, skipNulls, encodeDotInKeys,
|
|
153
|
+
// @ts-ignore
|
|
154
|
+
generateArrayPrefix === 'comma' && encodeValuesOnly && isArray(obj) ? null : encoder, filter, sort, allowDots, serializeDate, format, formatter, encodeValuesOnly, charset, valueSideChannel));
|
|
155
|
+
}
|
|
156
|
+
return values;
|
|
157
|
+
}
|
|
158
|
+
function normalize_stringify_options(opts = defaults) {
|
|
159
|
+
if (typeof opts.allowEmptyArrays !== 'undefined' && typeof opts.allowEmptyArrays !== 'boolean') {
|
|
160
|
+
throw new TypeError('`allowEmptyArrays` option can only be `true` or `false`, when provided');
|
|
161
|
+
}
|
|
162
|
+
if (typeof opts.encodeDotInKeys !== 'undefined' && typeof opts.encodeDotInKeys !== 'boolean') {
|
|
163
|
+
throw new TypeError('`encodeDotInKeys` option can only be `true` or `false`, when provided');
|
|
164
|
+
}
|
|
165
|
+
if (opts.encoder !== null && typeof opts.encoder !== 'undefined' && typeof opts.encoder !== 'function') {
|
|
166
|
+
throw new TypeError('Encoder has to be a function.');
|
|
167
|
+
}
|
|
168
|
+
const charset = opts.charset || defaults.charset;
|
|
169
|
+
if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
|
|
170
|
+
throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined');
|
|
171
|
+
}
|
|
172
|
+
let format = default_format;
|
|
173
|
+
if (typeof opts.format !== 'undefined') {
|
|
174
|
+
if (!has(formatters, opts.format)) {
|
|
175
|
+
throw new TypeError('Unknown format option provided.');
|
|
176
|
+
}
|
|
177
|
+
format = opts.format;
|
|
178
|
+
}
|
|
179
|
+
const formatter = formatters[format];
|
|
180
|
+
let filter = defaults.filter;
|
|
181
|
+
if (typeof opts.filter === 'function' || isArray(opts.filter)) {
|
|
182
|
+
filter = opts.filter;
|
|
183
|
+
}
|
|
184
|
+
let arrayFormat;
|
|
185
|
+
if (opts.arrayFormat && opts.arrayFormat in array_prefix_generators) {
|
|
186
|
+
arrayFormat = opts.arrayFormat;
|
|
187
|
+
}
|
|
188
|
+
else if ('indices' in opts) {
|
|
189
|
+
arrayFormat = opts.indices ? 'indices' : 'repeat';
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
arrayFormat = defaults.arrayFormat;
|
|
193
|
+
}
|
|
194
|
+
if ('commaRoundTrip' in opts && typeof opts.commaRoundTrip !== 'boolean') {
|
|
195
|
+
throw new TypeError('`commaRoundTrip` must be a boolean, or absent');
|
|
196
|
+
}
|
|
197
|
+
const allowDots = typeof opts.allowDots === 'undefined' ?
|
|
198
|
+
!!opts.encodeDotInKeys === true ?
|
|
199
|
+
true
|
|
200
|
+
: defaults.allowDots
|
|
201
|
+
: !!opts.allowDots;
|
|
202
|
+
return {
|
|
203
|
+
addQueryPrefix: typeof opts.addQueryPrefix === 'boolean' ? opts.addQueryPrefix : defaults.addQueryPrefix,
|
|
204
|
+
// @ts-ignore
|
|
205
|
+
allowDots: allowDots,
|
|
206
|
+
allowEmptyArrays: typeof opts.allowEmptyArrays === 'boolean' ? !!opts.allowEmptyArrays : defaults.allowEmptyArrays,
|
|
207
|
+
arrayFormat: arrayFormat,
|
|
208
|
+
charset: charset,
|
|
209
|
+
charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
|
|
210
|
+
commaRoundTrip: !!opts.commaRoundTrip,
|
|
211
|
+
delimiter: typeof opts.delimiter === 'undefined' ? defaults.delimiter : opts.delimiter,
|
|
212
|
+
encode: typeof opts.encode === 'boolean' ? opts.encode : defaults.encode,
|
|
213
|
+
encodeDotInKeys: typeof opts.encodeDotInKeys === 'boolean' ? opts.encodeDotInKeys : defaults.encodeDotInKeys,
|
|
214
|
+
encoder: typeof opts.encoder === 'function' ? opts.encoder : defaults.encoder,
|
|
215
|
+
encodeValuesOnly: typeof opts.encodeValuesOnly === 'boolean' ? opts.encodeValuesOnly : defaults.encodeValuesOnly,
|
|
216
|
+
filter: filter,
|
|
217
|
+
format: format,
|
|
218
|
+
formatter: formatter,
|
|
219
|
+
serializeDate: typeof opts.serializeDate === 'function' ? opts.serializeDate : defaults.serializeDate,
|
|
220
|
+
skipNulls: typeof opts.skipNulls === 'boolean' ? opts.skipNulls : defaults.skipNulls,
|
|
221
|
+
// @ts-ignore
|
|
222
|
+
sort: typeof opts.sort === 'function' ? opts.sort : null,
|
|
223
|
+
strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
export function stringify(object, opts = {}) {
|
|
227
|
+
let obj = object;
|
|
228
|
+
const options = normalize_stringify_options(opts);
|
|
229
|
+
let obj_keys;
|
|
230
|
+
let filter;
|
|
231
|
+
if (typeof options.filter === 'function') {
|
|
232
|
+
filter = options.filter;
|
|
233
|
+
obj = filter('', obj);
|
|
234
|
+
}
|
|
235
|
+
else if (isArray(options.filter)) {
|
|
236
|
+
filter = options.filter;
|
|
237
|
+
obj_keys = filter;
|
|
238
|
+
}
|
|
239
|
+
const keys = [];
|
|
240
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
241
|
+
return '';
|
|
242
|
+
}
|
|
243
|
+
const generateArrayPrefix = array_prefix_generators[options.arrayFormat];
|
|
244
|
+
const commaRoundTrip = generateArrayPrefix === 'comma' && options.commaRoundTrip;
|
|
245
|
+
if (!obj_keys) {
|
|
246
|
+
obj_keys = Object.keys(obj);
|
|
247
|
+
}
|
|
248
|
+
if (options.sort) {
|
|
249
|
+
obj_keys.sort(options.sort);
|
|
250
|
+
}
|
|
251
|
+
const sideChannel = new WeakMap();
|
|
252
|
+
for (let i = 0; i < obj_keys.length; ++i) {
|
|
253
|
+
const key = obj_keys[i];
|
|
254
|
+
if (options.skipNulls && obj[key] === null) {
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
push_to_array(keys, inner_stringify(obj[key], key,
|
|
258
|
+
// @ts-expect-error
|
|
259
|
+
generateArrayPrefix, commaRoundTrip, options.allowEmptyArrays, options.strictNullHandling, options.skipNulls, options.encodeDotInKeys, options.encode ? options.encoder : null, options.filter, options.sort, options.allowDots, options.serializeDate, options.format, options.formatter, options.encodeValuesOnly, options.charset, sideChannel));
|
|
260
|
+
}
|
|
261
|
+
const joined = keys.join(options.delimiter);
|
|
262
|
+
let prefix = options.addQueryPrefix === true ? '?' : '';
|
|
263
|
+
if (options.charsetSentinel) {
|
|
264
|
+
if (options.charset === 'iso-8859-1') {
|
|
265
|
+
// encodeURIComponent('✓'), the "numeric entity" representation of a checkmark
|
|
266
|
+
prefix += 'utf8=%26%2310003%3B&';
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
// encodeURIComponent('✓')
|
|
270
|
+
prefix += 'utf8=%E2%9C%93&';
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return joined.length > 0 ? prefix + joined : '';
|
|
274
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export type Format = 'RFC1738' | 'RFC3986';
|
|
2
|
+
export type DefaultEncoder = (str: any, defaultEncoder?: any, charset?: string) => string;
|
|
3
|
+
export type DefaultDecoder = (str: string, decoder?: any, charset?: string) => string;
|
|
4
|
+
export type BooleanOptional = boolean | undefined;
|
|
5
|
+
export type StringifyBaseOptions = {
|
|
6
|
+
delimiter?: string;
|
|
7
|
+
allowDots?: boolean;
|
|
8
|
+
encodeDotInKeys?: boolean;
|
|
9
|
+
strictNullHandling?: boolean;
|
|
10
|
+
skipNulls?: boolean;
|
|
11
|
+
encode?: boolean;
|
|
12
|
+
encoder?: (str: any, defaultEncoder: DefaultEncoder, charset: string, type: 'key' | 'value', format?: Format) => string;
|
|
13
|
+
filter?: Array<PropertyKey> | ((prefix: PropertyKey, value: any) => any);
|
|
14
|
+
arrayFormat?: 'indices' | 'brackets' | 'repeat' | 'comma';
|
|
15
|
+
indices?: boolean;
|
|
16
|
+
sort?: ((a: PropertyKey, b: PropertyKey) => number) | null;
|
|
17
|
+
serializeDate?: (d: Date) => string;
|
|
18
|
+
format?: 'RFC1738' | 'RFC3986';
|
|
19
|
+
formatter?: (str: PropertyKey) => string;
|
|
20
|
+
encodeValuesOnly?: boolean;
|
|
21
|
+
addQueryPrefix?: boolean;
|
|
22
|
+
charset?: 'utf-8' | 'iso-8859-1';
|
|
23
|
+
charsetSentinel?: boolean;
|
|
24
|
+
allowEmptyArrays?: boolean;
|
|
25
|
+
commaRoundTrip?: boolean;
|
|
26
|
+
};
|
|
27
|
+
export type StringifyOptions = StringifyBaseOptions;
|
|
28
|
+
export type ParseBaseOptions = {
|
|
29
|
+
comma?: boolean;
|
|
30
|
+
delimiter?: string | RegExp;
|
|
31
|
+
depth?: number | false;
|
|
32
|
+
decoder?: (str: string, defaultDecoder: DefaultDecoder, charset: string, type: 'key' | 'value') => any;
|
|
33
|
+
arrayLimit?: number;
|
|
34
|
+
parseArrays?: boolean;
|
|
35
|
+
plainObjects?: boolean;
|
|
36
|
+
allowPrototypes?: boolean;
|
|
37
|
+
allowSparse?: boolean;
|
|
38
|
+
parameterLimit?: number;
|
|
39
|
+
strictDepth?: boolean;
|
|
40
|
+
strictNullHandling?: boolean;
|
|
41
|
+
ignoreQueryPrefix?: boolean;
|
|
42
|
+
charset?: 'utf-8' | 'iso-8859-1';
|
|
43
|
+
charsetSentinel?: boolean;
|
|
44
|
+
interpretNumericEntities?: boolean;
|
|
45
|
+
allowEmptyArrays?: boolean;
|
|
46
|
+
duplicates?: 'combine' | 'first' | 'last';
|
|
47
|
+
allowDots?: boolean;
|
|
48
|
+
decodeDotInKeys?: boolean;
|
|
49
|
+
};
|
|
50
|
+
export type ParseOptions = ParseBaseOptions;
|
|
51
|
+
export type ParsedQs = {
|
|
52
|
+
[key: string]: undefined | string | string[] | ParsedQs | ParsedQs[];
|
|
53
|
+
};
|
|
54
|
+
export type NonNullableProperties<T> = {
|
|
55
|
+
[K in keyof T]-?: Exclude<T[K], undefined | null>;
|
|
56
|
+
};
|