@puku-ai/sdk 4.0.3 → 4.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -7
- package/dist/index.cjs +85 -0
- package/dist/vendor/_vendor/partial-json-parser/parser.cjs +225 -0
- package/dist/vendor/api-promise.cjs +18 -0
- package/dist/vendor/client.cjs +1013 -0
- package/dist/vendor/core/api-promise.cjs +80 -0
- package/dist/vendor/core/api.cjs +2 -0
- package/dist/vendor/core/credentials.cjs +313 -0
- package/dist/vendor/core/error.cjs +156 -0
- package/dist/vendor/core/middleware.cjs +173 -0
- package/dist/vendor/core/pagination.cjs +215 -0
- package/dist/vendor/core/resource.cjs +11 -0
- package/dist/vendor/core/streaming.cjs +346 -0
- package/dist/vendor/core/uploads.cjs +5 -0
- package/dist/vendor/error.cjs +18 -0
- package/dist/vendor/helpers/beta/environments.cjs +30 -0
- package/dist/vendor/helpers/beta/json-schema.cjs +56 -0
- package/dist/vendor/helpers/beta/mcp.cjs +418 -0
- package/dist/vendor/helpers/beta/memory.cjs +17 -0
- package/dist/vendor/helpers/beta/standard-schema.cjs +57 -0
- package/dist/vendor/helpers/beta/zod.cjs +88 -0
- package/dist/vendor/helpers/index.cjs +7 -0
- package/dist/vendor/helpers/json-schema.cjs +36 -0
- package/dist/vendor/helpers/zod.cjs +77 -0
- package/dist/vendor/index.cjs +54 -0
- package/dist/vendor/internal/builtin-types.cjs +3 -0
- package/dist/vendor/internal/constants.cjs +12 -0
- package/dist/vendor/internal/decoders/jsonl.cjs +40 -0
- package/dist/vendor/internal/decoders/line.cjs +109 -0
- package/dist/vendor/internal/detect-platform.cjs +159 -0
- package/dist/vendor/internal/errors.cjs +42 -0
- package/dist/vendor/internal/file-store.cjs +535 -0
- package/dist/vendor/internal/headers.cjs +119 -0
- package/dist/vendor/internal/message-stream-utils.cjs +33 -0
- package/dist/vendor/internal/node.browser.cjs +21 -0
- package/dist/vendor/internal/node.cjs +55 -0
- package/dist/vendor/internal/parse.cjs +65 -0
- package/dist/vendor/internal/qs/formats.cjs +12 -0
- package/dist/vendor/internal/qs/index.cjs +13 -0
- package/dist/vendor/internal/qs/stringify.cjs +276 -0
- package/dist/vendor/internal/qs/types.cjs +2 -0
- package/dist/vendor/internal/qs/utils.cjs +229 -0
- package/dist/vendor/internal/request-options.cjs +31 -0
- package/dist/vendor/internal/request-signal.cjs +49 -0
- package/dist/vendor/internal/shim-types.cjs +3 -0
- package/dist/vendor/internal/shims.cjs +91 -0
- package/dist/vendor/internal/stainless-helper-header.cjs +90 -0
- package/dist/vendor/internal/stream-utils.cjs +37 -0
- package/dist/vendor/internal/to-file.cjs +95 -0
- package/dist/vendor/internal/types.cjs +3 -0
- package/dist/vendor/internal/uploads.cjs +148 -0
- package/dist/vendor/internal/utils/abort.cjs +24 -0
- package/dist/vendor/internal/utils/async-queue.cjs +69 -0
- package/dist/vendor/internal/utils/backoff.cjs +43 -0
- package/dist/vendor/internal/utils/base64.cjs +37 -0
- package/dist/vendor/internal/utils/bytes.cjs +30 -0
- package/dist/vendor/internal/utils/env.cjs +21 -0
- package/dist/vendor/internal/utils/log.cjs +111 -0
- package/dist/vendor/internal/utils/path.cjs +78 -0
- package/dist/vendor/internal/utils/promise.cjs +17 -0
- package/dist/vendor/internal/utils/query.cjs +41 -0
- package/dist/vendor/internal/utils/sleep.cjs +27 -0
- package/dist/vendor/internal/utils/time.cjs +7 -0
- package/dist/vendor/internal/utils/uuid.cjs +18 -0
- package/dist/vendor/internal/utils/values.cjs +125 -0
- package/dist/vendor/internal/utils.cjs +24 -0
- package/dist/vendor/lib/BetaMessageStream.cjs +665 -0
- package/dist/vendor/lib/MessageStream.cjs +612 -0
- package/dist/vendor/lib/beta-parser.cjs +78 -0
- package/dist/vendor/lib/credentials/credential-chain.cjs +244 -0
- package/dist/vendor/lib/credentials/identity-token.cjs +71 -0
- package/dist/vendor/lib/credentials/oidc-federation.cjs +81 -0
- package/dist/vendor/lib/credentials/token-cache.cjs +113 -0
- package/dist/vendor/lib/credentials/types.cjs +267 -0
- package/dist/vendor/lib/credentials/user-oauth.cjs +129 -0
- package/dist/vendor/lib/credentials.cjs +7 -0
- package/dist/vendor/lib/environments/index.cjs +17 -0
- package/dist/vendor/lib/environments/poller.cjs +226 -0
- package/dist/vendor/lib/environments/worker.cjs +609 -0
- package/dist/vendor/lib/helper-client.cjs +57 -0
- package/dist/vendor/lib/middleware.cjs +779 -0
- package/dist/vendor/lib/parser.cjs +65 -0
- package/dist/vendor/lib/sessions/accumulate.cjs +44 -0
- package/dist/vendor/lib/standard-schema.cjs +44 -0
- package/dist/vendor/lib/tools/BetaRunnableTool.cjs +30 -0
- package/dist/vendor/lib/tools/BetaToolRunner.cjs +500 -0
- package/dist/vendor/lib/tools/CompactionControl.cjs +27 -0
- package/dist/vendor/lib/tools/SessionToolRunner.cjs +740 -0
- package/dist/vendor/lib/tools/ToolError.cjs +46 -0
- package/dist/vendor/lib/transform-json-schema.cjs +113 -0
- package/dist/vendor/pagination.cjs +18 -0
- package/dist/vendor/resource.cjs +18 -0
- package/dist/vendor/resources/beta/agents/agents.cjs +159 -0
- package/dist/vendor/resources/beta/agents/index.cjs +8 -0
- package/dist/vendor/resources/beta/agents/versions.cjs +35 -0
- package/dist/vendor/resources/beta/agents.cjs +18 -0
- package/dist/vendor/resources/beta/beta.cjs +105 -0
- package/dist/vendor/resources/beta/deployment-runs.cjs +54 -0
- package/dist/vendor/resources/beta/deployments.cjs +195 -0
- package/dist/vendor/resources/beta/dreams.cjs +115 -0
- package/dist/vendor/resources/beta/environments/environments.cjs +178 -0
- package/dist/vendor/resources/beta/environments/index.cjs +8 -0
- package/dist/vendor/resources/beta/environments/work.cjs +256 -0
- package/dist/vendor/resources/beta/environments.cjs +18 -0
- package/dist/vendor/resources/beta/files.cjs +123 -0
- package/dist/vendor/resources/beta/index.cjs +38 -0
- package/dist/vendor/resources/beta/memory-stores/index.cjs +10 -0
- package/dist/vendor/resources/beta/memory-stores/memories.cjs +129 -0
- package/dist/vendor/resources/beta/memory-stores/memory-stores.cjs +173 -0
- package/dist/vendor/resources/beta/memory-stores/memory-versions.cjs +80 -0
- package/dist/vendor/resources/beta/memory-stores.cjs +18 -0
- package/dist/vendor/resources/beta/messages/batches.cjs +206 -0
- package/dist/vendor/resources/beta/messages/index.cjs +11 -0
- package/dist/vendor/resources/beta/messages/messages.cjs +189 -0
- package/dist/vendor/resources/beta/messages.cjs +18 -0
- package/dist/vendor/resources/beta/models.cjs +59 -0
- package/dist/vendor/resources/beta/organization/api-keys.cjs +55 -0
- package/dist/vendor/resources/beta/organization/compliance-settings.cjs +51 -0
- package/dist/vendor/resources/beta/organization/external-keys.cjs +118 -0
- package/dist/vendor/resources/beta/organization/federation/federation.cjs +49 -0
- package/dist/vendor/resources/beta/organization/federation/index.cjs +10 -0
- package/dist/vendor/resources/beta/organization/federation/issuers.cjs +168 -0
- package/dist/vendor/resources/beta/organization/federation/rules/index.cjs +8 -0
- package/dist/vendor/resources/beta/organization/federation/rules/rules.cjs +226 -0
- package/dist/vendor/resources/beta/organization/federation/rules/workspaces.cjs +113 -0
- package/dist/vendor/resources/beta/organization/federation/rules.cjs +18 -0
- package/dist/vendor/resources/beta/organization/federation.cjs +18 -0
- package/dist/vendor/resources/beta/organization/index.cjs +24 -0
- package/dist/vendor/resources/beta/organization/invites.cjs +75 -0
- package/dist/vendor/resources/beta/organization/organization.cjs +90 -0
- package/dist/vendor/resources/beta/organization/rate-limits.cjs +30 -0
- package/dist/vendor/resources/beta/organization/service-accounts/index.cjs +8 -0
- package/dist/vendor/resources/beta/organization/service-accounts/service-accounts.cjs +202 -0
- package/dist/vendor/resources/beta/organization/service-accounts/workspaces.cjs +124 -0
- package/dist/vendor/resources/beta/organization/service-accounts.cjs +18 -0
- package/dist/vendor/resources/beta/organization/users.cjs +66 -0
- package/dist/vendor/resources/beta/organization/workspaces/index.cjs +12 -0
- package/dist/vendor/resources/beta/organization/workspaces/members.cjs +101 -0
- package/dist/vendor/resources/beta/organization/workspaces/rate-limits.cjs +33 -0
- package/dist/vendor/resources/beta/organization/workspaces/service-accounts.cjs +188 -0
- package/dist/vendor/resources/beta/organization/workspaces/workspaces.cjs +140 -0
- package/dist/vendor/resources/beta/organization/workspaces.cjs +18 -0
- package/dist/vendor/resources/beta/organization.cjs +18 -0
- package/dist/vendor/resources/beta/sessions/events.cjs +119 -0
- package/dist/vendor/resources/beta/sessions/index.cjs +12 -0
- package/dist/vendor/resources/beta/sessions/resources.cjs +131 -0
- package/dist/vendor/resources/beta/sessions/sessions.cjs +186 -0
- package/dist/vendor/resources/beta/sessions/threads/events.cjs +60 -0
- package/dist/vendor/resources/beta/sessions/threads/index.cjs +8 -0
- package/dist/vendor/resources/beta/sessions/threads/threads.cjs +116 -0
- package/dist/vendor/resources/beta/sessions/threads.cjs +18 -0
- package/dist/vendor/resources/beta/sessions.cjs +18 -0
- package/dist/vendor/resources/beta/skills/index.cjs +8 -0
- package/dist/vendor/resources/beta/skills/skills.cjs +132 -0
- package/dist/vendor/resources/beta/skills/versions.cjs +128 -0
- package/dist/vendor/resources/beta/skills.cjs +18 -0
- package/dist/vendor/resources/beta/tunnels/certificates.cjs +128 -0
- package/dist/vendor/resources/beta/tunnels/index.cjs +8 -0
- package/dist/vendor/resources/beta/tunnels/tunnels.cjs +209 -0
- package/dist/vendor/resources/beta/tunnels.cjs +18 -0
- package/dist/vendor/resources/beta/user-profiles.cjs +117 -0
- package/dist/vendor/resources/beta/vaults/credentials.cjs +176 -0
- package/dist/vendor/resources/beta/vaults/index.cjs +8 -0
- package/dist/vendor/resources/beta/vaults/vaults.cjs +177 -0
- package/dist/vendor/resources/beta/vaults.cjs +18 -0
- package/dist/vendor/resources/beta/webhooks.cjs +32 -0
- package/dist/vendor/resources/beta.cjs +18 -0
- package/dist/vendor/resources/completions.cjs +22 -0
- package/dist/vendor/resources/files.cjs +51 -0
- package/dist/vendor/resources/index.cjs +31 -0
- package/dist/vendor/resources/messages/batches.cjs +160 -0
- package/dist/vendor/resources/messages/index.cjs +8 -0
- package/dist/vendor/resources/messages/messages.cjs +159 -0
- package/dist/vendor/resources/messages.cjs +18 -0
- package/dist/vendor/resources/models.cjs +44 -0
- package/dist/vendor/resources/shared.cjs +3 -0
- package/dist/vendor/resources/skills/index.cjs +8 -0
- package/dist/vendor/resources/skills/skills.cjs +72 -0
- package/dist/vendor/resources/skills/versions.cjs +40 -0
- package/dist/vendor/resources/skills.cjs +18 -0
- package/dist/vendor/resources/top-level.cjs +3 -0
- package/dist/vendor/resources.cjs +17 -0
- package/dist/vendor/streaming.cjs +18 -0
- package/dist/vendor/tools/agent-toolset/fs-util.cjs +193 -0
- package/dist/vendor/tools/agent-toolset/memories.cjs +916 -0
- package/dist/vendor/tools/agent-toolset/node.browser.cjs +147 -0
- package/dist/vendor/tools/agent-toolset/node.cjs +939 -0
- package/dist/vendor/tools/agent-toolset/skills.cjs +325 -0
- package/dist/vendor/tools/agent-toolset/sync-interval.cjs +28 -0
- package/dist/vendor/tools/memory/node.browser.cjs +48 -0
- package/dist/vendor/tools/memory/node.cjs +364 -0
- package/dist/vendor/uploads.cjs +18 -0
- package/dist/vendor/version.cjs +4 -0
- package/package.json +12 -13
- package/sdk.cjs +0 -14271
- package/sdk.cjs.map +0 -149
- package/sdk.d.ts +0 -10866
- package/sdk.mjs +0 -68
- package/sdk.mjs.map +0 -149
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.util = exports.stream = exports.path = exports.os = exports.fs = exports.crypto = exports.child_process = void 0;
|
|
4
|
+
const error_1 = require("../core/error");
|
|
5
|
+
/** Substituted for `./node` by the package.json `browser` field; every property access throws. */
|
|
6
|
+
function unavailable(module) {
|
|
7
|
+
return new Proxy({}, {
|
|
8
|
+
get(_target, property) {
|
|
9
|
+
if (typeof property === 'symbol')
|
|
10
|
+
return undefined;
|
|
11
|
+
throw new error_1.PukuError(`\`${module}.${property}\` is not available in this environment; it needs a Node.js-compatible runtime`);
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
exports.child_process = unavailable('child_process');
|
|
16
|
+
exports.crypto = unavailable('crypto');
|
|
17
|
+
exports.fs = unavailable('fs');
|
|
18
|
+
exports.os = unavailable('os');
|
|
19
|
+
exports.path = unavailable('path');
|
|
20
|
+
exports.stream = unavailable('stream');
|
|
21
|
+
exports.util = unavailable('util');
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.util = exports.stream = exports.path = exports.os = exports.fs = exports.crypto = exports.child_process = void 0;
|
|
37
|
+
/**
|
|
38
|
+
* The one module under `src/` that may import Node built-ins (eslint enforces this).
|
|
39
|
+
* The package.json `browser` field swaps it for `./node.browser`, so only touch its
|
|
40
|
+
* exports on code paths that run on Node-compatible runtimes.
|
|
41
|
+
*/
|
|
42
|
+
const child_process = __importStar(require("node:child_process"));
|
|
43
|
+
exports.child_process = child_process;
|
|
44
|
+
const crypto = __importStar(require("node:crypto"));
|
|
45
|
+
exports.crypto = crypto;
|
|
46
|
+
const fs = __importStar(require("node:fs"));
|
|
47
|
+
exports.fs = fs;
|
|
48
|
+
const os = __importStar(require("node:os"));
|
|
49
|
+
exports.os = os;
|
|
50
|
+
const path = __importStar(require("node:path"));
|
|
51
|
+
exports.path = path;
|
|
52
|
+
const stream = __importStar(require("node:stream"));
|
|
53
|
+
exports.stream = stream;
|
|
54
|
+
const util = __importStar(require("node:util"));
|
|
55
|
+
exports.util = util;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.defaultParseResponse = defaultParseResponse;
|
|
5
|
+
exports.addResponseIDs = addResponseIDs;
|
|
6
|
+
const streaming_1 = require("../core/streaming");
|
|
7
|
+
const log_1 = require("./utils/log");
|
|
8
|
+
const request_signal_1 = require("./request-signal");
|
|
9
|
+
async function defaultParseResponse(client, props) {
|
|
10
|
+
const { response, requestLogID, retryOfRequestLogID, startTime } = props;
|
|
11
|
+
const body = await (async () => {
|
|
12
|
+
if (props.options.stream) {
|
|
13
|
+
(0, log_1.loggerFor)(client).debug('response', response.status, response.url, response.headers, response.body);
|
|
14
|
+
// Note: there is an invariant here that isn't represented in the type system
|
|
15
|
+
// that if you set `stream: true` the response type must also be `Stream<T>`
|
|
16
|
+
return streaming_1.Stream.fromSSEResponse(response, props.controller, client);
|
|
17
|
+
}
|
|
18
|
+
// fetch refuses to read the body when the status code is 204.
|
|
19
|
+
if (response.status === 204) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
if (props.options.__binaryResponse) {
|
|
23
|
+
return response;
|
|
24
|
+
}
|
|
25
|
+
const contentType = response.headers.get('content-type');
|
|
26
|
+
const mediaType = contentType?.split(';')[0]?.trim();
|
|
27
|
+
const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
|
|
28
|
+
if (isJSON) {
|
|
29
|
+
const contentLength = response.headers.get('content-length');
|
|
30
|
+
if (contentLength === '0') {
|
|
31
|
+
// if there is no content we can't do anything
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
const json = await response.json();
|
|
35
|
+
return addResponseIDs(json, response);
|
|
36
|
+
}
|
|
37
|
+
const text = await response.text();
|
|
38
|
+
return text;
|
|
39
|
+
})().finally(() => {
|
|
40
|
+
// The body is settled (or parsing threw), so the caller-signal abort
|
|
41
|
+
// listener has nothing left to cancel. Streams release in their own
|
|
42
|
+
// teardown; a raw Response (`__binaryResponse`) keeps the listener so
|
|
43
|
+
// aborting an in-flight download still works.
|
|
44
|
+
if (!props.options.stream && !props.options.__binaryResponse) {
|
|
45
|
+
(0, request_signal_1.releaseRequestSignal)(props.controller);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
(0, log_1.loggerFor)(client).debug(`[${requestLogID}] response parsed`, (0, log_1.formatRequestDetails)({
|
|
49
|
+
retryOfRequestLogID,
|
|
50
|
+
url: response.url,
|
|
51
|
+
status: response.status,
|
|
52
|
+
body,
|
|
53
|
+
durationMs: Date.now() - startTime,
|
|
54
|
+
}));
|
|
55
|
+
return body;
|
|
56
|
+
}
|
|
57
|
+
function addResponseIDs(value, response) {
|
|
58
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
return Object.defineProperties(value, {
|
|
62
|
+
_request_id: { value: response.headers.get('request-id'), enumerable: false },
|
|
63
|
+
_workspace_id: { value: response.headers.get('puku-workspace-id'), enumerable: false },
|
|
64
|
+
});
|
|
65
|
+
}
|
|
@@ -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,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formats = exports.stringify = void 0;
|
|
4
|
+
const formats_1 = require("./formats");
|
|
5
|
+
const formats = {
|
|
6
|
+
formatters: formats_1.formatters,
|
|
7
|
+
RFC1738: formats_1.RFC1738,
|
|
8
|
+
RFC3986: formats_1.RFC3986,
|
|
9
|
+
default: formats_1.default_format,
|
|
10
|
+
};
|
|
11
|
+
exports.formats = formats;
|
|
12
|
+
var stringify_1 = require("./stringify");
|
|
13
|
+
Object.defineProperty(exports, "stringify", { enumerable: true, get: function () { return stringify_1.stringify; } });
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringify = stringify;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
const formats_1 = require("./formats");
|
|
6
|
+
const values_1 = require("../utils/values");
|
|
7
|
+
const array_prefix_generators = {
|
|
8
|
+
brackets(prefix) {
|
|
9
|
+
return String(prefix) + '[]';
|
|
10
|
+
},
|
|
11
|
+
comma: 'comma',
|
|
12
|
+
indices(prefix, key) {
|
|
13
|
+
return String(prefix) + '[' + key + ']';
|
|
14
|
+
},
|
|
15
|
+
repeat(prefix) {
|
|
16
|
+
return String(prefix);
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
const push_to_array = function (arr, value_or_array) {
|
|
20
|
+
Array.prototype.push.apply(arr, (0, values_1.isArray)(value_or_array) ? value_or_array : [value_or_array]);
|
|
21
|
+
};
|
|
22
|
+
let toISOString;
|
|
23
|
+
const defaults = {
|
|
24
|
+
addQueryPrefix: false,
|
|
25
|
+
allowDots: false,
|
|
26
|
+
allowEmptyArrays: false,
|
|
27
|
+
arrayFormat: 'indices',
|
|
28
|
+
charset: 'utf-8',
|
|
29
|
+
charsetSentinel: false,
|
|
30
|
+
delimiter: '&',
|
|
31
|
+
encode: true,
|
|
32
|
+
encodeDotInKeys: false,
|
|
33
|
+
encoder: utils_1.encode,
|
|
34
|
+
encodeValuesOnly: false,
|
|
35
|
+
format: formats_1.default_format,
|
|
36
|
+
formatter: formats_1.default_formatter,
|
|
37
|
+
/** @deprecated */
|
|
38
|
+
indices: false,
|
|
39
|
+
serializeDate(date) {
|
|
40
|
+
return (toISOString ??= Function.prototype.call.bind(Date.prototype.toISOString))(date);
|
|
41
|
+
},
|
|
42
|
+
skipNulls: false,
|
|
43
|
+
strictNullHandling: false,
|
|
44
|
+
};
|
|
45
|
+
function is_non_nullish_primitive(v) {
|
|
46
|
+
return (typeof v === 'string' ||
|
|
47
|
+
typeof v === 'number' ||
|
|
48
|
+
typeof v === 'boolean' ||
|
|
49
|
+
typeof v === 'symbol' ||
|
|
50
|
+
typeof v === 'bigint');
|
|
51
|
+
}
|
|
52
|
+
const sentinel = {};
|
|
53
|
+
function inner_stringify(object, prefix, generateArrayPrefix, commaRoundTrip, allowEmptyArrays, strictNullHandling, skipNulls, encodeDotInKeys, encoder, filter, sort, allowDots, serializeDate, format, formatter, encodeValuesOnly, charset, sideChannel) {
|
|
54
|
+
let obj = object;
|
|
55
|
+
let tmp_sc = sideChannel;
|
|
56
|
+
let step = 0;
|
|
57
|
+
let find_flag = false;
|
|
58
|
+
while ((tmp_sc = tmp_sc.get(sentinel)) !== void undefined && !find_flag) {
|
|
59
|
+
// Where object last appeared in the ref tree
|
|
60
|
+
const pos = tmp_sc.get(object);
|
|
61
|
+
step += 1;
|
|
62
|
+
if (typeof pos !== 'undefined') {
|
|
63
|
+
if (pos === step) {
|
|
64
|
+
throw new RangeError('Cyclic object value');
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
find_flag = true; // Break while
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (typeof tmp_sc.get(sentinel) === 'undefined') {
|
|
71
|
+
step = 0;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (typeof filter === 'function') {
|
|
75
|
+
obj = filter(prefix, obj);
|
|
76
|
+
}
|
|
77
|
+
else if (obj instanceof Date) {
|
|
78
|
+
obj = serializeDate?.(obj);
|
|
79
|
+
}
|
|
80
|
+
else if (generateArrayPrefix === 'comma' && (0, values_1.isArray)(obj)) {
|
|
81
|
+
obj = (0, utils_1.maybe_map)(obj, function (value) {
|
|
82
|
+
if (value instanceof Date) {
|
|
83
|
+
return serializeDate?.(value);
|
|
84
|
+
}
|
|
85
|
+
return value;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
if (obj === null) {
|
|
89
|
+
if (strictNullHandling) {
|
|
90
|
+
return encoder && !encodeValuesOnly ?
|
|
91
|
+
// @ts-expect-error
|
|
92
|
+
encoder(prefix, defaults.encoder, charset, 'key', format)
|
|
93
|
+
: prefix;
|
|
94
|
+
}
|
|
95
|
+
obj = '';
|
|
96
|
+
}
|
|
97
|
+
if (is_non_nullish_primitive(obj) || (0, utils_1.is_buffer)(obj)) {
|
|
98
|
+
if (encoder) {
|
|
99
|
+
const key_value = encodeValuesOnly ? prefix
|
|
100
|
+
// @ts-expect-error
|
|
101
|
+
: encoder(prefix, defaults.encoder, charset, 'key', format);
|
|
102
|
+
return [
|
|
103
|
+
formatter?.(key_value) +
|
|
104
|
+
'=' +
|
|
105
|
+
// @ts-expect-error
|
|
106
|
+
formatter?.(encoder(obj, defaults.encoder, charset, 'value', format)),
|
|
107
|
+
];
|
|
108
|
+
}
|
|
109
|
+
return [formatter?.(prefix) + '=' + formatter?.(String(obj))];
|
|
110
|
+
}
|
|
111
|
+
const values = [];
|
|
112
|
+
if (typeof obj === 'undefined') {
|
|
113
|
+
return values;
|
|
114
|
+
}
|
|
115
|
+
let obj_keys;
|
|
116
|
+
if (generateArrayPrefix === 'comma' && (0, values_1.isArray)(obj)) {
|
|
117
|
+
// we need to join elements in
|
|
118
|
+
if (encodeValuesOnly && encoder) {
|
|
119
|
+
// @ts-expect-error values only
|
|
120
|
+
obj = (0, utils_1.maybe_map)(obj, encoder);
|
|
121
|
+
}
|
|
122
|
+
obj_keys = [{ value: obj.length > 0 ? obj.join(',') || null : void undefined }];
|
|
123
|
+
}
|
|
124
|
+
else if ((0, values_1.isArray)(filter)) {
|
|
125
|
+
obj_keys = filter;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
const keys = Object.keys(obj);
|
|
129
|
+
obj_keys = sort ? keys.sort(sort) : keys;
|
|
130
|
+
}
|
|
131
|
+
const encoded_prefix = encodeDotInKeys ? String(prefix).replace(/\./g, '%2E') : String(prefix);
|
|
132
|
+
const adjusted_prefix = commaRoundTrip && (0, values_1.isArray)(obj) && obj.length === 1 ? encoded_prefix + '[]' : encoded_prefix;
|
|
133
|
+
if (allowEmptyArrays && (0, values_1.isArray)(obj) && obj.length === 0) {
|
|
134
|
+
return adjusted_prefix + '[]';
|
|
135
|
+
}
|
|
136
|
+
for (let j = 0; j < obj_keys.length; ++j) {
|
|
137
|
+
const key = obj_keys[j];
|
|
138
|
+
const value =
|
|
139
|
+
// @ts-ignore
|
|
140
|
+
typeof key === 'object' && typeof key.value !== 'undefined' ? key.value : obj[key];
|
|
141
|
+
if (skipNulls && value === null) {
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
// @ts-ignore
|
|
145
|
+
const encoded_key = allowDots && encodeDotInKeys ? key.replace(/\./g, '%2E') : key;
|
|
146
|
+
const key_prefix = (0, values_1.isArray)(obj) ?
|
|
147
|
+
typeof generateArrayPrefix === 'function' ?
|
|
148
|
+
generateArrayPrefix(adjusted_prefix, encoded_key)
|
|
149
|
+
: adjusted_prefix
|
|
150
|
+
: adjusted_prefix + (allowDots ? '.' + encoded_key : '[' + encoded_key + ']');
|
|
151
|
+
sideChannel.set(object, step);
|
|
152
|
+
const valueSideChannel = new WeakMap();
|
|
153
|
+
valueSideChannel.set(sentinel, sideChannel);
|
|
154
|
+
push_to_array(values, inner_stringify(value, key_prefix, generateArrayPrefix, commaRoundTrip, allowEmptyArrays, strictNullHandling, skipNulls, encodeDotInKeys,
|
|
155
|
+
// @ts-ignore
|
|
156
|
+
generateArrayPrefix === 'comma' && encodeValuesOnly && (0, values_1.isArray)(obj) ? null : encoder, filter, sort, allowDots, serializeDate, format, formatter, encodeValuesOnly, charset, valueSideChannel));
|
|
157
|
+
}
|
|
158
|
+
return values;
|
|
159
|
+
}
|
|
160
|
+
function normalize_stringify_options(opts = defaults) {
|
|
161
|
+
if (typeof opts.allowEmptyArrays !== 'undefined' && typeof opts.allowEmptyArrays !== 'boolean') {
|
|
162
|
+
throw new TypeError('`allowEmptyArrays` option can only be `true` or `false`, when provided');
|
|
163
|
+
}
|
|
164
|
+
if (typeof opts.encodeDotInKeys !== 'undefined' && typeof opts.encodeDotInKeys !== 'boolean') {
|
|
165
|
+
throw new TypeError('`encodeDotInKeys` option can only be `true` or `false`, when provided');
|
|
166
|
+
}
|
|
167
|
+
if (opts.encoder !== null && typeof opts.encoder !== 'undefined' && typeof opts.encoder !== 'function') {
|
|
168
|
+
throw new TypeError('Encoder has to be a function.');
|
|
169
|
+
}
|
|
170
|
+
const charset = opts.charset || defaults.charset;
|
|
171
|
+
if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
|
|
172
|
+
throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined');
|
|
173
|
+
}
|
|
174
|
+
let format = formats_1.default_format;
|
|
175
|
+
if (typeof opts.format !== 'undefined') {
|
|
176
|
+
if (!(0, utils_1.has)(formats_1.formatters, opts.format)) {
|
|
177
|
+
throw new TypeError('Unknown format option provided.');
|
|
178
|
+
}
|
|
179
|
+
format = opts.format;
|
|
180
|
+
}
|
|
181
|
+
const formatter = formats_1.formatters[format];
|
|
182
|
+
let filter = defaults.filter;
|
|
183
|
+
if (typeof opts.filter === 'function' || (0, values_1.isArray)(opts.filter)) {
|
|
184
|
+
filter = opts.filter;
|
|
185
|
+
}
|
|
186
|
+
let arrayFormat;
|
|
187
|
+
if (opts.arrayFormat && opts.arrayFormat in array_prefix_generators) {
|
|
188
|
+
arrayFormat = opts.arrayFormat;
|
|
189
|
+
}
|
|
190
|
+
else if ('indices' in opts) {
|
|
191
|
+
arrayFormat = opts.indices ? 'indices' : 'repeat';
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
arrayFormat = defaults.arrayFormat;
|
|
195
|
+
}
|
|
196
|
+
if ('commaRoundTrip' in opts && typeof opts.commaRoundTrip !== 'boolean') {
|
|
197
|
+
throw new TypeError('`commaRoundTrip` must be a boolean, or absent');
|
|
198
|
+
}
|
|
199
|
+
const allowDots = typeof opts.allowDots === 'undefined' ?
|
|
200
|
+
!!opts.encodeDotInKeys === true ?
|
|
201
|
+
true
|
|
202
|
+
: defaults.allowDots
|
|
203
|
+
: !!opts.allowDots;
|
|
204
|
+
return {
|
|
205
|
+
addQueryPrefix: typeof opts.addQueryPrefix === 'boolean' ? opts.addQueryPrefix : defaults.addQueryPrefix,
|
|
206
|
+
// @ts-ignore
|
|
207
|
+
allowDots: allowDots,
|
|
208
|
+
allowEmptyArrays: typeof opts.allowEmptyArrays === 'boolean' ? !!opts.allowEmptyArrays : defaults.allowEmptyArrays,
|
|
209
|
+
arrayFormat: arrayFormat,
|
|
210
|
+
charset: charset,
|
|
211
|
+
charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
|
|
212
|
+
commaRoundTrip: !!opts.commaRoundTrip,
|
|
213
|
+
delimiter: typeof opts.delimiter === 'undefined' ? defaults.delimiter : opts.delimiter,
|
|
214
|
+
encode: typeof opts.encode === 'boolean' ? opts.encode : defaults.encode,
|
|
215
|
+
encodeDotInKeys: typeof opts.encodeDotInKeys === 'boolean' ? opts.encodeDotInKeys : defaults.encodeDotInKeys,
|
|
216
|
+
encoder: typeof opts.encoder === 'function' ? opts.encoder : defaults.encoder,
|
|
217
|
+
encodeValuesOnly: typeof opts.encodeValuesOnly === 'boolean' ? opts.encodeValuesOnly : defaults.encodeValuesOnly,
|
|
218
|
+
filter: filter,
|
|
219
|
+
format: format,
|
|
220
|
+
formatter: formatter,
|
|
221
|
+
serializeDate: typeof opts.serializeDate === 'function' ? opts.serializeDate : defaults.serializeDate,
|
|
222
|
+
skipNulls: typeof opts.skipNulls === 'boolean' ? opts.skipNulls : defaults.skipNulls,
|
|
223
|
+
// @ts-ignore
|
|
224
|
+
sort: typeof opts.sort === 'function' ? opts.sort : null,
|
|
225
|
+
strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
function stringify(object, opts = {}) {
|
|
229
|
+
let obj = object;
|
|
230
|
+
const options = normalize_stringify_options(opts);
|
|
231
|
+
let obj_keys;
|
|
232
|
+
let filter;
|
|
233
|
+
if (typeof options.filter === 'function') {
|
|
234
|
+
filter = options.filter;
|
|
235
|
+
obj = filter('', obj);
|
|
236
|
+
}
|
|
237
|
+
else if ((0, values_1.isArray)(options.filter)) {
|
|
238
|
+
filter = options.filter;
|
|
239
|
+
obj_keys = filter;
|
|
240
|
+
}
|
|
241
|
+
const keys = [];
|
|
242
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
243
|
+
return '';
|
|
244
|
+
}
|
|
245
|
+
const generateArrayPrefix = array_prefix_generators[options.arrayFormat];
|
|
246
|
+
const commaRoundTrip = generateArrayPrefix === 'comma' && options.commaRoundTrip;
|
|
247
|
+
if (!obj_keys) {
|
|
248
|
+
obj_keys = Object.keys(obj);
|
|
249
|
+
}
|
|
250
|
+
if (options.sort) {
|
|
251
|
+
obj_keys.sort(options.sort);
|
|
252
|
+
}
|
|
253
|
+
const sideChannel = new WeakMap();
|
|
254
|
+
for (let i = 0; i < obj_keys.length; ++i) {
|
|
255
|
+
const key = obj_keys[i];
|
|
256
|
+
if (options.skipNulls && obj[key] === null) {
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
push_to_array(keys, inner_stringify(obj[key], key,
|
|
260
|
+
// @ts-expect-error
|
|
261
|
+
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));
|
|
262
|
+
}
|
|
263
|
+
const joined = keys.join(options.delimiter);
|
|
264
|
+
let prefix = options.addQueryPrefix === true ? '?' : '';
|
|
265
|
+
if (options.charsetSentinel) {
|
|
266
|
+
if (options.charset === 'iso-8859-1') {
|
|
267
|
+
// encodeURIComponent('✓'), the "numeric entity" representation of a checkmark
|
|
268
|
+
prefix += 'utf8=%26%2310003%3B&';
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
// encodeURIComponent('✓')
|
|
272
|
+
prefix += 'utf8=%E2%9C%93&';
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return joined.length > 0 ? prefix + joined : '';
|
|
276
|
+
}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.encode = exports.has = void 0;
|
|
4
|
+
exports.merge = merge;
|
|
5
|
+
exports.assign_single_source = assign_single_source;
|
|
6
|
+
exports.decode = decode;
|
|
7
|
+
exports.compact = compact;
|
|
8
|
+
exports.is_regexp = is_regexp;
|
|
9
|
+
exports.is_buffer = is_buffer;
|
|
10
|
+
exports.combine = combine;
|
|
11
|
+
exports.maybe_map = maybe_map;
|
|
12
|
+
const formats_1 = require("./formats");
|
|
13
|
+
const values_1 = require("../utils/values");
|
|
14
|
+
let has = (obj, key) => ((exports.has = Object.hasOwn ?? Function.prototype.call.bind(Object.prototype.hasOwnProperty)),
|
|
15
|
+
(0, exports.has)(obj, key));
|
|
16
|
+
exports.has = has;
|
|
17
|
+
const hex_table = /* @__PURE__ */ (() => {
|
|
18
|
+
const array = [];
|
|
19
|
+
for (let i = 0; i < 256; ++i) {
|
|
20
|
+
array.push('%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase());
|
|
21
|
+
}
|
|
22
|
+
return array;
|
|
23
|
+
})();
|
|
24
|
+
function compact_queue(queue) {
|
|
25
|
+
while (queue.length > 1) {
|
|
26
|
+
const item = queue.pop();
|
|
27
|
+
if (!item)
|
|
28
|
+
continue;
|
|
29
|
+
const obj = item.obj[item.prop];
|
|
30
|
+
if ((0, values_1.isArray)(obj)) {
|
|
31
|
+
const compacted = [];
|
|
32
|
+
for (let j = 0; j < obj.length; ++j) {
|
|
33
|
+
if (typeof obj[j] !== 'undefined') {
|
|
34
|
+
compacted.push(obj[j]);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
item.obj[item.prop] = compacted;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function array_to_object(source, options) {
|
|
43
|
+
const obj = options && options.plainObjects ? Object.create(null) : {};
|
|
44
|
+
for (let i = 0; i < source.length; ++i) {
|
|
45
|
+
if (typeof source[i] !== 'undefined') {
|
|
46
|
+
obj[i] = source[i];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return obj;
|
|
50
|
+
}
|
|
51
|
+
function merge(target, source, options = {}) {
|
|
52
|
+
if (!source) {
|
|
53
|
+
return target;
|
|
54
|
+
}
|
|
55
|
+
if (typeof source !== 'object') {
|
|
56
|
+
if ((0, values_1.isArray)(target)) {
|
|
57
|
+
target.push(source);
|
|
58
|
+
}
|
|
59
|
+
else if (target && typeof target === 'object') {
|
|
60
|
+
if ((options && (options.plainObjects || options.allowPrototypes)) || !(0, exports.has)(Object.prototype, source)) {
|
|
61
|
+
target[source] = true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
return [target, source];
|
|
66
|
+
}
|
|
67
|
+
return target;
|
|
68
|
+
}
|
|
69
|
+
if (!target || typeof target !== 'object') {
|
|
70
|
+
return [target].concat(source);
|
|
71
|
+
}
|
|
72
|
+
let mergeTarget = target;
|
|
73
|
+
if ((0, values_1.isArray)(target) && !(0, values_1.isArray)(source)) {
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
mergeTarget = array_to_object(target, options);
|
|
76
|
+
}
|
|
77
|
+
if ((0, values_1.isArray)(target) && (0, values_1.isArray)(source)) {
|
|
78
|
+
source.forEach(function (item, i) {
|
|
79
|
+
if ((0, exports.has)(target, i)) {
|
|
80
|
+
const targetItem = target[i];
|
|
81
|
+
if (targetItem && typeof targetItem === 'object' && item && typeof item === 'object') {
|
|
82
|
+
target[i] = merge(targetItem, item, options);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
target.push(item);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
target[i] = item;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
return target;
|
|
93
|
+
}
|
|
94
|
+
return Object.keys(source).reduce(function (acc, key) {
|
|
95
|
+
const value = source[key];
|
|
96
|
+
if ((0, exports.has)(acc, key)) {
|
|
97
|
+
acc[key] = merge(acc[key], value, options);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
acc[key] = value;
|
|
101
|
+
}
|
|
102
|
+
return acc;
|
|
103
|
+
}, mergeTarget);
|
|
104
|
+
}
|
|
105
|
+
function assign_single_source(target, source) {
|
|
106
|
+
return Object.keys(source).reduce(function (acc, key) {
|
|
107
|
+
acc[key] = source[key];
|
|
108
|
+
return acc;
|
|
109
|
+
}, target);
|
|
110
|
+
}
|
|
111
|
+
function decode(str, _, charset) {
|
|
112
|
+
const strWithoutPlus = str.replace(/\+/g, ' ');
|
|
113
|
+
if (charset === 'iso-8859-1') {
|
|
114
|
+
// unescape never throws, no try...catch needed:
|
|
115
|
+
return strWithoutPlus.replace(/%[0-9a-f]{2}/gi, unescape);
|
|
116
|
+
}
|
|
117
|
+
// utf-8
|
|
118
|
+
try {
|
|
119
|
+
return decodeURIComponent(strWithoutPlus);
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
return strWithoutPlus;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const limit = 1024;
|
|
126
|
+
const encode = (str, _defaultEncoder, charset, _kind, format) => {
|
|
127
|
+
// This code was originally written by Brian White for the io.js core querystring library.
|
|
128
|
+
// It has been adapted here for stricter adherence to RFC 3986
|
|
129
|
+
if (str.length === 0) {
|
|
130
|
+
return str;
|
|
131
|
+
}
|
|
132
|
+
let string = str;
|
|
133
|
+
if (typeof str === 'symbol') {
|
|
134
|
+
string = Symbol.prototype.toString.call(str);
|
|
135
|
+
}
|
|
136
|
+
else if (typeof str !== 'string') {
|
|
137
|
+
string = String(str);
|
|
138
|
+
}
|
|
139
|
+
if (charset === 'iso-8859-1') {
|
|
140
|
+
return escape(string).replace(/%u[0-9a-f]{4}/gi, function ($0) {
|
|
141
|
+
return '%26%23' + parseInt($0.slice(2), 16) + '%3B';
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
let out = '';
|
|
145
|
+
for (let j = 0; j < string.length; j += limit) {
|
|
146
|
+
const segment = string.length >= limit ? string.slice(j, j + limit) : string;
|
|
147
|
+
const arr = [];
|
|
148
|
+
for (let i = 0; i < segment.length; ++i) {
|
|
149
|
+
let c = segment.charCodeAt(i);
|
|
150
|
+
if (c === 0x2d || // -
|
|
151
|
+
c === 0x2e || // .
|
|
152
|
+
c === 0x5f || // _
|
|
153
|
+
c === 0x7e || // ~
|
|
154
|
+
(c >= 0x30 && c <= 0x39) || // 0-9
|
|
155
|
+
(c >= 0x41 && c <= 0x5a) || // a-z
|
|
156
|
+
(c >= 0x61 && c <= 0x7a) || // A-Z
|
|
157
|
+
(format === formats_1.RFC1738 && (c === 0x28 || c === 0x29)) // ( )
|
|
158
|
+
) {
|
|
159
|
+
arr[arr.length] = segment.charAt(i);
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (c < 0x80) {
|
|
163
|
+
arr[arr.length] = hex_table[c];
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
if (c < 0x800) {
|
|
167
|
+
arr[arr.length] = hex_table[0xc0 | (c >> 6)] + hex_table[0x80 | (c & 0x3f)];
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (c < 0xd800 || c >= 0xe000) {
|
|
171
|
+
arr[arr.length] =
|
|
172
|
+
hex_table[0xe0 | (c >> 12)] + hex_table[0x80 | ((c >> 6) & 0x3f)] + hex_table[0x80 | (c & 0x3f)];
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
i += 1;
|
|
176
|
+
c = 0x10000 + (((c & 0x3ff) << 10) | (segment.charCodeAt(i) & 0x3ff));
|
|
177
|
+
arr[arr.length] =
|
|
178
|
+
hex_table[0xf0 | (c >> 18)] +
|
|
179
|
+
hex_table[0x80 | ((c >> 12) & 0x3f)] +
|
|
180
|
+
hex_table[0x80 | ((c >> 6) & 0x3f)] +
|
|
181
|
+
hex_table[0x80 | (c & 0x3f)];
|
|
182
|
+
}
|
|
183
|
+
out += arr.join('');
|
|
184
|
+
}
|
|
185
|
+
return out;
|
|
186
|
+
};
|
|
187
|
+
exports.encode = encode;
|
|
188
|
+
function compact(value) {
|
|
189
|
+
const queue = [{ obj: { o: value }, prop: 'o' }];
|
|
190
|
+
const refs = [];
|
|
191
|
+
for (let i = 0; i < queue.length; ++i) {
|
|
192
|
+
const item = queue[i];
|
|
193
|
+
// @ts-ignore
|
|
194
|
+
const obj = item.obj[item.prop];
|
|
195
|
+
const keys = Object.keys(obj);
|
|
196
|
+
for (let j = 0; j < keys.length; ++j) {
|
|
197
|
+
const key = keys[j];
|
|
198
|
+
const val = obj[key];
|
|
199
|
+
if (typeof val === 'object' && val !== null && refs.indexOf(val) === -1) {
|
|
200
|
+
queue.push({ obj: obj, prop: key });
|
|
201
|
+
refs.push(val);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
compact_queue(queue);
|
|
206
|
+
return value;
|
|
207
|
+
}
|
|
208
|
+
function is_regexp(obj) {
|
|
209
|
+
return Object.prototype.toString.call(obj) === '[object RegExp]';
|
|
210
|
+
}
|
|
211
|
+
function is_buffer(obj) {
|
|
212
|
+
if (!obj || typeof obj !== 'object') {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj));
|
|
216
|
+
}
|
|
217
|
+
function combine(a, b) {
|
|
218
|
+
return [].concat(a, b);
|
|
219
|
+
}
|
|
220
|
+
function maybe_map(val, fn) {
|
|
221
|
+
if ((0, values_1.isArray)(val)) {
|
|
222
|
+
const mapped = [];
|
|
223
|
+
for (let i = 0; i < val.length; i += 1) {
|
|
224
|
+
mapped.push(fn(val[i]));
|
|
225
|
+
}
|
|
226
|
+
return mapped;
|
|
227
|
+
}
|
|
228
|
+
return fn(val);
|
|
229
|
+
}
|