@anthropic-ai/sdk 0.94.0 → 0.95.1
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/CHANGELOG.md +21 -0
- package/bin/migration-config.json +185 -0
- package/client.d.mts +7 -4
- package/client.d.mts.map +1 -1
- package/client.d.ts +7 -4
- package/client.d.ts.map +1 -1
- package/client.js +5 -4
- package/client.js.map +1 -1
- package/client.mjs +5 -4
- package/client.mjs.map +1 -1
- package/core/streaming.d.mts.map +1 -1
- package/core/streaming.d.ts.map +1 -1
- package/core/streaming.js +15 -1
- package/core/streaming.js.map +1 -1
- package/core/streaming.mjs +15 -1
- package/core/streaming.mjs.map +1 -1
- package/internal/qs/formats.d.mts +7 -0
- package/internal/qs/formats.d.mts.map +1 -0
- package/internal/qs/formats.d.ts +7 -0
- package/internal/qs/formats.d.ts.map +1 -0
- package/internal/qs/formats.js +13 -0
- package/internal/qs/formats.js.map +1 -0
- package/internal/qs/formats.mjs +9 -0
- package/internal/qs/formats.mjs.map +1 -0
- package/internal/qs/index.d.mts +10 -0
- package/internal/qs/index.d.mts.map +1 -0
- package/internal/qs/index.d.ts +10 -0
- package/internal/qs/index.d.ts.map +1 -0
- package/internal/qs/index.js +14 -0
- package/internal/qs/index.js.map +1 -0
- package/internal/qs/index.mjs +10 -0
- package/internal/qs/index.mjs.map +1 -0
- package/internal/qs/stringify.d.mts +3 -0
- package/internal/qs/stringify.d.mts.map +1 -0
- package/internal/qs/stringify.d.ts +3 -0
- package/internal/qs/stringify.d.ts.map +1 -0
- package/internal/qs/stringify.js +277 -0
- package/internal/qs/stringify.js.map +1 -0
- package/internal/qs/stringify.mjs +274 -0
- package/internal/qs/stringify.mjs.map +1 -0
- package/internal/qs/types.d.mts +57 -0
- package/internal/qs/types.d.mts.map +1 -0
- package/internal/qs/types.d.ts +57 -0
- package/internal/qs/types.d.ts.map +1 -0
- package/internal/qs/types.js +3 -0
- package/internal/qs/types.js.map +1 -0
- package/internal/qs/types.mjs +2 -0
- package/internal/qs/types.mjs.map +1 -0
- package/internal/qs/utils.d.mts +15 -0
- package/internal/qs/utils.d.mts.map +1 -0
- package/internal/qs/utils.d.ts +15 -0
- package/internal/qs/utils.d.ts.map +1 -0
- package/internal/qs/utils.js +230 -0
- package/internal/qs/utils.js.map +1 -0
- package/internal/qs/utils.mjs +217 -0
- package/internal/qs/utils.mjs.map +1 -0
- package/internal/utils/log.d.mts.map +1 -1
- package/internal/utils/log.d.ts.map +1 -1
- package/internal/utils/log.js +3 -2
- package/internal/utils/log.js.map +1 -1
- package/internal/utils/log.mjs +3 -2
- package/internal/utils/log.mjs.map +1 -1
- package/internal/utils/query.d.mts +0 -3
- package/internal/utils/query.d.mts.map +1 -1
- package/internal/utils/query.d.ts +0 -3
- package/internal/utils/query.d.ts.map +1 -1
- package/internal/utils/query.js +3 -16
- package/internal/utils/query.js.map +1 -1
- package/internal/utils/query.mjs +2 -16
- package/internal/utils/query.mjs.map +1 -1
- package/package.json +2 -1
- package/resources/beta/agents/agents.d.mts +60 -1
- package/resources/beta/agents/agents.d.mts.map +1 -1
- package/resources/beta/agents/agents.d.ts +60 -1
- package/resources/beta/agents/agents.d.ts.map +1 -1
- package/resources/beta/agents/agents.js.map +1 -1
- package/resources/beta/agents/agents.mjs.map +1 -1
- package/resources/beta/agents/index.d.mts +1 -1
- package/resources/beta/agents/index.d.mts.map +1 -1
- package/resources/beta/agents/index.d.ts +1 -1
- package/resources/beta/agents/index.d.ts.map +1 -1
- package/resources/beta/agents/index.js.map +1 -1
- package/resources/beta/agents/index.mjs.map +1 -1
- package/resources/beta/beta.d.mts +9 -5
- package/resources/beta/beta.d.mts.map +1 -1
- package/resources/beta/beta.d.ts +9 -5
- package/resources/beta/beta.d.ts.map +1 -1
- package/resources/beta/beta.js +4 -0
- package/resources/beta/beta.js.map +1 -1
- package/resources/beta/beta.mjs +4 -0
- package/resources/beta/beta.mjs.map +1 -1
- package/resources/beta/index.d.mts +3 -2
- package/resources/beta/index.d.mts.map +1 -1
- package/resources/beta/index.d.ts +3 -2
- package/resources/beta/index.d.ts.map +1 -1
- package/resources/beta/index.js +3 -1
- package/resources/beta/index.js.map +1 -1
- package/resources/beta/index.mjs +1 -0
- package/resources/beta/index.mjs.map +1 -1
- package/resources/beta/messages/messages.d.mts +88 -0
- package/resources/beta/messages/messages.d.mts.map +1 -1
- package/resources/beta/messages/messages.d.ts +88 -0
- package/resources/beta/messages/messages.d.ts.map +1 -1
- package/resources/beta/messages/messages.js.map +1 -1
- package/resources/beta/messages/messages.mjs.map +1 -1
- package/resources/beta/sessions/events.d.mts +436 -5
- package/resources/beta/sessions/events.d.mts.map +1 -1
- package/resources/beta/sessions/events.d.ts +436 -5
- package/resources/beta/sessions/events.d.ts.map +1 -1
- package/resources/beta/sessions/index.d.mts +3 -2
- package/resources/beta/sessions/index.d.mts.map +1 -1
- package/resources/beta/sessions/index.d.ts +3 -2
- package/resources/beta/sessions/index.d.ts.map +1 -1
- package/resources/beta/sessions/index.js +3 -1
- package/resources/beta/sessions/index.js.map +1 -1
- package/resources/beta/sessions/index.mjs +1 -0
- package/resources/beta/sessions/index.mjs.map +1 -1
- package/resources/beta/sessions/sessions.d.mts +99 -3
- package/resources/beta/sessions/sessions.d.mts.map +1 -1
- package/resources/beta/sessions/sessions.d.ts +99 -3
- package/resources/beta/sessions/sessions.d.ts.map +1 -1
- package/resources/beta/sessions/sessions.js +4 -0
- package/resources/beta/sessions/sessions.js.map +1 -1
- package/resources/beta/sessions/sessions.mjs +4 -0
- package/resources/beta/sessions/sessions.mjs.map +1 -1
- package/resources/beta/sessions/threads/events.d.mts +64 -0
- package/resources/beta/sessions/threads/events.d.mts.map +1 -0
- package/resources/beta/sessions/threads/events.d.ts +64 -0
- package/resources/beta/sessions/threads/events.d.ts.map +1 -0
- package/resources/beta/sessions/threads/events.js +60 -0
- package/resources/beta/sessions/threads/events.js.map +1 -0
- package/resources/beta/sessions/threads/events.mjs +56 -0
- package/resources/beta/sessions/threads/events.mjs.map +1 -0
- package/resources/beta/sessions/threads/index.d.mts +3 -0
- package/resources/beta/sessions/threads/index.d.mts.map +1 -0
- package/resources/beta/sessions/threads/index.d.ts +3 -0
- package/resources/beta/sessions/threads/index.d.ts.map +1 -0
- package/resources/beta/sessions/threads/index.js +9 -0
- package/resources/beta/sessions/threads/index.js.map +1 -0
- package/resources/beta/sessions/threads/index.mjs +4 -0
- package/resources/beta/sessions/threads/index.mjs.map +1 -0
- package/resources/beta/sessions/threads/threads.d.mts +203 -0
- package/resources/beta/sessions/threads/threads.d.mts.map +1 -0
- package/resources/beta/sessions/threads/threads.d.ts +203 -0
- package/resources/beta/sessions/threads/threads.d.ts.map +1 -0
- package/resources/beta/sessions/threads/threads.js +88 -0
- package/resources/beta/sessions/threads/threads.js.map +1 -0
- package/resources/beta/sessions/threads/threads.mjs +83 -0
- package/resources/beta/sessions/threads/threads.mjs.map +1 -0
- package/resources/beta/sessions/threads.d.mts +2 -0
- package/resources/beta/sessions/threads.d.mts.map +1 -0
- package/resources/beta/sessions/threads.d.ts +2 -0
- package/resources/beta/sessions/threads.d.ts.map +1 -0
- package/resources/beta/sessions/threads.js +6 -0
- package/resources/beta/sessions/threads.js.map +1 -0
- package/resources/beta/sessions/threads.mjs +3 -0
- package/resources/beta/sessions/threads.mjs.map +1 -0
- package/resources/beta/user-profiles.d.mts +36 -0
- package/resources/beta/user-profiles.d.mts.map +1 -1
- package/resources/beta/user-profiles.d.ts +36 -0
- package/resources/beta/user-profiles.d.ts.map +1 -1
- package/resources/beta/vaults/credentials.d.mts +109 -1
- package/resources/beta/vaults/credentials.d.mts.map +1 -1
- package/resources/beta/vaults/credentials.d.ts +109 -1
- package/resources/beta/vaults/credentials.d.ts.map +1 -1
- package/resources/beta/vaults/credentials.js +22 -0
- package/resources/beta/vaults/credentials.js.map +1 -1
- package/resources/beta/vaults/credentials.mjs +22 -0
- package/resources/beta/vaults/credentials.mjs.map +1 -1
- package/resources/beta/vaults/index.d.mts +1 -1
- package/resources/beta/vaults/index.d.mts.map +1 -1
- package/resources/beta/vaults/index.d.ts +1 -1
- package/resources/beta/vaults/index.d.ts.map +1 -1
- package/resources/beta/vaults/index.js.map +1 -1
- package/resources/beta/vaults/index.mjs.map +1 -1
- package/resources/beta/vaults/vaults.d.mts +2 -2
- package/resources/beta/vaults/vaults.d.mts.map +1 -1
- package/resources/beta/vaults/vaults.d.ts +2 -2
- package/resources/beta/vaults/vaults.d.ts.map +1 -1
- package/resources/beta/vaults/vaults.js.map +1 -1
- package/resources/beta/vaults/vaults.mjs.map +1 -1
- package/resources/beta/webhooks.d.mts +256 -0
- package/resources/beta/webhooks.d.mts.map +1 -0
- package/resources/beta/webhooks.d.ts +256 -0
- package/resources/beta/webhooks.d.ts.map +1 -0
- package/resources/beta/webhooks.js +20 -0
- package/resources/beta/webhooks.js.map +1 -0
- package/resources/beta/webhooks.mjs +16 -0
- package/resources/beta/webhooks.mjs.map +1 -0
- package/resources/messages/messages.d.mts +88 -0
- package/resources/messages/messages.d.mts.map +1 -1
- package/resources/messages/messages.d.ts +88 -0
- package/resources/messages/messages.d.ts.map +1 -1
- package/resources/messages/messages.js.map +1 -1
- package/resources/messages/messages.mjs.map +1 -1
- package/src/client.ts +17 -4
- package/src/core/streaming.ts +15 -1
- package/src/internal/qs/LICENSE.md +13 -0
- package/src/internal/qs/README.md +3 -0
- package/src/internal/qs/formats.ts +10 -0
- package/src/internal/qs/index.ts +13 -0
- package/src/internal/qs/stringify.ts +385 -0
- package/src/internal/qs/types.ts +71 -0
- package/src/internal/qs/utils.ts +265 -0
- package/src/internal/utils/log.ts +2 -1
- package/src/internal/utils/query.ts +2 -18
- package/src/resources/beta/agents/agents.ts +74 -0
- package/src/resources/beta/agents/index.ts +4 -0
- package/src/resources/beta/beta.ts +80 -1
- package/src/resources/beta/index.ts +37 -0
- package/src/resources/beta/messages/messages.ts +88 -0
- package/src/resources/beta/sessions/events.ts +565 -3
- package/src/resources/beta/sessions/index.ts +34 -0
- package/src/resources/beta/sessions/sessions.ts +179 -0
- package/src/resources/beta/sessions/threads/events.ts +107 -0
- package/src/resources/beta/sessions/threads/index.ts +16 -0
- package/src/resources/beta/sessions/threads/threads.ts +344 -0
- package/src/resources/beta/sessions/threads.ts +3 -0
- package/src/resources/beta/user-profiles.ts +42 -0
- package/src/resources/beta/vaults/credentials.ts +150 -0
- package/src/resources/beta/vaults/index.ts +6 -0
- package/src/resources/beta/vaults/vaults.ts +12 -0
- package/src/resources/beta/webhooks.ts +417 -0
- package/src/resources/messages/messages.ts +88 -0
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.mjs","sourceRoot":"","sources":["../../src/resources/messages/messages.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAG/E,EAAE,WAAW,EAAE;OAEf,EAAE,YAAY,EAAE;OAEhB,EAAE,qBAAqB,EAAE;OACzB,EAAE,aAAa,EAAE;OACjB,EACL,YAAY,GAIb;OACM,KAAK,UAAU;OACf,EAGL,OAAO,GAWR;OAGM,EAAE,yBAAyB,EAAE;AAEpC,MAAM,OAAO,QAAS,SAAQ,WAAW;IAAzC;;QACE,YAAO,GAAuB,IAAI,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAsJrE,CAAC;IAxHC,MAAM,CACJ,IAAyB,EACzB,OAAwB;QAExB,IAAI,IAAI,CAAC,KAAK,IAAI,iBAAiB,EAAE,CAAC;YACpC,OAAO,CAAC,IAAI,CACV,cAAc,IAAI,CAAC,KAAK,iDACtB,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAC9B,gIAAgI,CACjI,CAAC;QACJ,CAAC;QACD,IACE,oCAAoC,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;YACzD,IAAI,CAAC,QAAQ;YACb,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,SA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AAM,IAAI,OAAO,EAAE,CAC3C,CAAC;IACJ,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,WAAW,CAAC,IAA8B,EAAE,OAAwB;QAClE,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,2BAA2B,EAAE,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IAC9E,CAAC;CACF;AAm/BD,MAAM,iBAAiB,GAEnB;IACF,YAAY,EAAE,oBAAoB;IAClC,iBAAiB,EAAE,oBAAoB;IACvC,oBAAoB,EAAE,oBAAoB;IAC1C,yBAAyB,EAAE,oBAAoB;IAC/C,oBAAoB,EAAE,oBAAoB;IAC1C,0BAA0B,EAAE,iBAAiB;IAC7C,wBAAwB,EAAE,mBAAmB;IAC7C,YAAY,EAAE,iBAAiB;IAC/B,YAAY,EAAE,iBAAiB;IAC/B,0BAA0B,EAAE,qBAAqB;IACjD,4BAA4B,EAAE,qBAAqB;IACnD,yBAAyB,EAAE,qBAAqB;IAChD,2BAA2B,EAAE,qBAAqB;IAClD,iBAAiB,EAAE,iBAAiB;IACpC,wBAAwB,EAAE,iBAAiB;IAC3C,mBAAmB,EAAE,iBAAiB;IACtC,0BAA0B,EAAE,iBAAiB;CAC9C,CAAC;AAEF,MAAM,oCAAoC,GAAY,CAAC,uBAAuB,EAAE,iBAAiB,CAAC,CAAC;AAk/DnG,QAAQ,CAAC,OAAO,GAAG,OAAO,CAAC"}
|
package/src/client.ts
CHANGED
|
@@ -341,6 +341,11 @@ export interface ClientOptions {
|
|
|
341
341
|
*/
|
|
342
342
|
profile?: string | null | undefined;
|
|
343
343
|
|
|
344
|
+
/**
|
|
345
|
+
* Defaults to process.env['ANTHROPIC_WEBHOOK_SIGNING_KEY'].
|
|
346
|
+
*/
|
|
347
|
+
webhookKey?: string | null | undefined;
|
|
348
|
+
|
|
344
349
|
/**
|
|
345
350
|
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
|
|
346
351
|
*
|
|
@@ -425,6 +430,7 @@ export const AI_PROMPT = '\\n\\nAssistant:';
|
|
|
425
430
|
export class BaseAnthropic {
|
|
426
431
|
apiKey: string | null;
|
|
427
432
|
authToken: string | null;
|
|
433
|
+
webhookKey: string | null;
|
|
428
434
|
|
|
429
435
|
/**
|
|
430
436
|
* The active credential provider. Default credential resolution runs once
|
|
@@ -460,6 +466,7 @@ export class BaseAnthropic {
|
|
|
460
466
|
*
|
|
461
467
|
* @param {string | null | undefined} [opts.apiKey=process.env['ANTHROPIC_API_KEY'] ?? null]
|
|
462
468
|
* @param {string | null | undefined} [opts.authToken=process.env['ANTHROPIC_AUTH_TOKEN'] ?? null]
|
|
469
|
+
* @param {string | null | undefined} [opts.webhookKey=process.env['ANTHROPIC_WEBHOOK_SIGNING_KEY'] ?? null]
|
|
463
470
|
* @param {string} [opts.baseURL=process.env['ANTHROPIC_BASE_URL'] ?? https://api.anthropic.com] - Override the default base URL for the API.
|
|
464
471
|
* @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
|
465
472
|
* @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
|
|
@@ -469,7 +476,13 @@ export class BaseAnthropic {
|
|
|
469
476
|
* @param {Record<string, string | undefined>} opts.defaultQuery - Default query parameters to include with every request to the API.
|
|
470
477
|
* @param {boolean} [opts.dangerouslyAllowBrowser=false] - By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.
|
|
471
478
|
*/
|
|
472
|
-
constructor({
|
|
479
|
+
constructor({
|
|
480
|
+
baseURL = readEnv('ANTHROPIC_BASE_URL'),
|
|
481
|
+
apiKey,
|
|
482
|
+
authToken,
|
|
483
|
+
webhookKey = readEnv('ANTHROPIC_WEBHOOK_SIGNING_KEY') ?? null,
|
|
484
|
+
...opts
|
|
485
|
+
}: ClientOptions = {}) {
|
|
473
486
|
// An explicit `profile` is a constructor-level credential choice; when set,
|
|
474
487
|
// do not let env ANTHROPIC_API_KEY / ANTHROPIC_AUTH_TOKEN shadow it.
|
|
475
488
|
if (apiKey === undefined) {
|
|
@@ -484,6 +497,7 @@ export class BaseAnthropic {
|
|
|
484
497
|
const options: ClientOptions = {
|
|
485
498
|
apiKey,
|
|
486
499
|
authToken,
|
|
500
|
+
webhookKey,
|
|
487
501
|
...opts,
|
|
488
502
|
baseURL: baseURL || `https://api.anthropic.com`,
|
|
489
503
|
};
|
|
@@ -538,6 +552,7 @@ export class BaseAnthropic {
|
|
|
538
552
|
|
|
539
553
|
this.apiKey = typeof apiKey === 'string' ? apiKey : null;
|
|
540
554
|
this.authToken = authToken;
|
|
555
|
+
this.webhookKey = webhookKey;
|
|
541
556
|
|
|
542
557
|
if (inherited) {
|
|
543
558
|
this._authState = inherited;
|
|
@@ -644,6 +659,7 @@ export class BaseAnthropic {
|
|
|
644
659
|
fetchOptions: this.fetchOptions,
|
|
645
660
|
apiKey: this.apiKey,
|
|
646
661
|
authToken: this.authToken,
|
|
662
|
+
webhookKey: this.webhookKey,
|
|
647
663
|
// credentials: this.credentials is a no-op when __auth is shared (the
|
|
648
664
|
// ctor takes the inherited path and ignores options.credentials); when
|
|
649
665
|
// overridesAuth is true via apiKey/authToken only, it lets the clone
|
|
@@ -780,9 +796,6 @@ export class BaseAnthropic {
|
|
|
780
796
|
return buildHeaders([{ Authorization: `Bearer ${this.authToken}` }]);
|
|
781
797
|
}
|
|
782
798
|
|
|
783
|
-
/**
|
|
784
|
-
* Basic re-implementation of `qs.stringify` for primitive types.
|
|
785
|
-
*/
|
|
786
799
|
protected stringifyQuery(query: object | Record<string, unknown>): string {
|
|
787
800
|
return stringifyQuery(query);
|
|
788
801
|
}
|
package/src/core/streaming.ts
CHANGED
|
@@ -86,7 +86,21 @@ export class Stream<Item> implements AsyncIterable<Item> {
|
|
|
86
86
|
sse.event === 'session.error' ||
|
|
87
87
|
sse.event === 'session.deleted' ||
|
|
88
88
|
sse.event === 'span.model_request_start' ||
|
|
89
|
-
sse.event === 'span.model_request_end'
|
|
89
|
+
sse.event === 'span.model_request_end' ||
|
|
90
|
+
sse.event === 'span.outcome_evaluation_start' ||
|
|
91
|
+
sse.event === 'span.outcome_evaluation_ongoing' ||
|
|
92
|
+
sse.event === 'span.outcome_evaluation_end' ||
|
|
93
|
+
sse.event === 'user.define_outcome' ||
|
|
94
|
+
sse.event === 'agent.thread_message_received' ||
|
|
95
|
+
sse.event === 'agent.thread_message_sent' ||
|
|
96
|
+
sse.event === 'agent.session_thread_message_received' ||
|
|
97
|
+
sse.event === 'agent.session_thread_message_sent' ||
|
|
98
|
+
sse.event === 'session.thread_created' ||
|
|
99
|
+
sse.event === 'session.thread_status_created' ||
|
|
100
|
+
sse.event === 'session.thread_status_running' ||
|
|
101
|
+
sse.event === 'session.thread_status_idle' ||
|
|
102
|
+
sse.event === 'session.thread_status_rescheduled' ||
|
|
103
|
+
sse.event === 'session.thread_status_terminated'
|
|
90
104
|
) {
|
|
91
105
|
try {
|
|
92
106
|
yield JSON.parse(sse.data) as Item;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014, Nathan LaFreniere and other [contributors](https://github.com/puruvj/neoqs/graphs/contributors) All rights reserved.
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
8
|
+
|
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
10
|
+
|
|
11
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
12
|
+
|
|
13
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Format } from './types';
|
|
2
|
+
|
|
3
|
+
export const default_format: Format = 'RFC3986';
|
|
4
|
+
export const default_formatter = (v: PropertyKey) => String(v);
|
|
5
|
+
export const formatters: Record<Format, (str: PropertyKey) => string> = {
|
|
6
|
+
RFC1738: (v: PropertyKey) => String(v).replace(/%20/g, '+'),
|
|
7
|
+
RFC3986: default_formatter,
|
|
8
|
+
};
|
|
9
|
+
export const RFC1738 = 'RFC1738';
|
|
10
|
+
export const RFC3986 = 'RFC3986';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { default_format, formatters, RFC1738, RFC3986 } from './formats';
|
|
2
|
+
|
|
3
|
+
const formats = {
|
|
4
|
+
formatters,
|
|
5
|
+
RFC1738,
|
|
6
|
+
RFC3986,
|
|
7
|
+
default: default_format,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { stringify } from './stringify';
|
|
11
|
+
export { formats };
|
|
12
|
+
|
|
13
|
+
export type { DefaultDecoder, DefaultEncoder, Format, ParseOptions, StringifyOptions } from './types';
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
import { encode, is_buffer, maybe_map, has } from './utils';
|
|
2
|
+
import { default_format, default_formatter, formatters } from './formats';
|
|
3
|
+
import type { NonNullableProperties, StringifyOptions } from './types';
|
|
4
|
+
import { isArray } from '../utils/values';
|
|
5
|
+
|
|
6
|
+
const array_prefix_generators = {
|
|
7
|
+
brackets(prefix: PropertyKey) {
|
|
8
|
+
return String(prefix) + '[]';
|
|
9
|
+
},
|
|
10
|
+
comma: 'comma',
|
|
11
|
+
indices(prefix: PropertyKey, key: string) {
|
|
12
|
+
return String(prefix) + '[' + key + ']';
|
|
13
|
+
},
|
|
14
|
+
repeat(prefix: PropertyKey) {
|
|
15
|
+
return String(prefix);
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const push_to_array = function (arr: any[], value_or_array: any) {
|
|
20
|
+
Array.prototype.push.apply(arr, isArray(value_or_array) ? value_or_array : [value_or_array]);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
let toISOString;
|
|
24
|
+
|
|
25
|
+
const defaults = {
|
|
26
|
+
addQueryPrefix: false,
|
|
27
|
+
allowDots: false,
|
|
28
|
+
allowEmptyArrays: false,
|
|
29
|
+
arrayFormat: 'indices',
|
|
30
|
+
charset: 'utf-8',
|
|
31
|
+
charsetSentinel: false,
|
|
32
|
+
delimiter: '&',
|
|
33
|
+
encode: true,
|
|
34
|
+
encodeDotInKeys: false,
|
|
35
|
+
encoder: encode,
|
|
36
|
+
encodeValuesOnly: false,
|
|
37
|
+
format: default_format,
|
|
38
|
+
formatter: default_formatter,
|
|
39
|
+
/** @deprecated */
|
|
40
|
+
indices: false,
|
|
41
|
+
serializeDate(date) {
|
|
42
|
+
return (toISOString ??= Function.prototype.call.bind(Date.prototype.toISOString))(date);
|
|
43
|
+
},
|
|
44
|
+
skipNulls: false,
|
|
45
|
+
strictNullHandling: false,
|
|
46
|
+
} as NonNullableProperties<StringifyOptions & { formatter: (typeof formatters)['RFC1738'] }>;
|
|
47
|
+
|
|
48
|
+
function is_non_nullish_primitive(v: unknown): v is string | number | boolean | symbol | bigint {
|
|
49
|
+
return (
|
|
50
|
+
typeof v === 'string' ||
|
|
51
|
+
typeof v === 'number' ||
|
|
52
|
+
typeof v === 'boolean' ||
|
|
53
|
+
typeof v === 'symbol' ||
|
|
54
|
+
typeof v === 'bigint'
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const sentinel = {};
|
|
59
|
+
|
|
60
|
+
function inner_stringify(
|
|
61
|
+
object: any,
|
|
62
|
+
prefix: PropertyKey,
|
|
63
|
+
generateArrayPrefix: StringifyOptions['arrayFormat'] | ((prefix: string, key: string) => string),
|
|
64
|
+
commaRoundTrip: boolean,
|
|
65
|
+
allowEmptyArrays: boolean,
|
|
66
|
+
strictNullHandling: boolean,
|
|
67
|
+
skipNulls: boolean,
|
|
68
|
+
encodeDotInKeys: boolean,
|
|
69
|
+
encoder: StringifyOptions['encoder'],
|
|
70
|
+
filter: StringifyOptions['filter'],
|
|
71
|
+
sort: StringifyOptions['sort'],
|
|
72
|
+
allowDots: StringifyOptions['allowDots'],
|
|
73
|
+
serializeDate: StringifyOptions['serializeDate'],
|
|
74
|
+
format: StringifyOptions['format'],
|
|
75
|
+
formatter: StringifyOptions['formatter'],
|
|
76
|
+
encodeValuesOnly: boolean,
|
|
77
|
+
charset: StringifyOptions['charset'],
|
|
78
|
+
sideChannel: WeakMap<any, any>,
|
|
79
|
+
) {
|
|
80
|
+
let obj = object;
|
|
81
|
+
|
|
82
|
+
let tmp_sc = sideChannel;
|
|
83
|
+
let step = 0;
|
|
84
|
+
let find_flag = false;
|
|
85
|
+
while ((tmp_sc = tmp_sc.get(sentinel)) !== void undefined && !find_flag) {
|
|
86
|
+
// Where object last appeared in the ref tree
|
|
87
|
+
const pos = tmp_sc.get(object);
|
|
88
|
+
step += 1;
|
|
89
|
+
if (typeof pos !== 'undefined') {
|
|
90
|
+
if (pos === step) {
|
|
91
|
+
throw new RangeError('Cyclic object value');
|
|
92
|
+
} else {
|
|
93
|
+
find_flag = true; // Break while
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (typeof tmp_sc.get(sentinel) === 'undefined') {
|
|
97
|
+
step = 0;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (typeof filter === 'function') {
|
|
102
|
+
obj = filter(prefix, obj);
|
|
103
|
+
} else if (obj instanceof Date) {
|
|
104
|
+
obj = serializeDate?.(obj);
|
|
105
|
+
} else if (generateArrayPrefix === 'comma' && isArray(obj)) {
|
|
106
|
+
obj = maybe_map(obj, function (value) {
|
|
107
|
+
if (value instanceof Date) {
|
|
108
|
+
return serializeDate?.(value);
|
|
109
|
+
}
|
|
110
|
+
return value;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (obj === null) {
|
|
115
|
+
if (strictNullHandling) {
|
|
116
|
+
return encoder && !encodeValuesOnly ?
|
|
117
|
+
// @ts-expect-error
|
|
118
|
+
encoder(prefix, defaults.encoder, charset, 'key', format)
|
|
119
|
+
: prefix;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
obj = '';
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (is_non_nullish_primitive(obj) || is_buffer(obj)) {
|
|
126
|
+
if (encoder) {
|
|
127
|
+
const key_value =
|
|
128
|
+
encodeValuesOnly ? prefix
|
|
129
|
+
// @ts-expect-error
|
|
130
|
+
: encoder(prefix, defaults.encoder, charset, 'key', format);
|
|
131
|
+
return [
|
|
132
|
+
formatter?.(key_value) +
|
|
133
|
+
'=' +
|
|
134
|
+
// @ts-expect-error
|
|
135
|
+
formatter?.(encoder(obj, defaults.encoder, charset, 'value', format)),
|
|
136
|
+
];
|
|
137
|
+
}
|
|
138
|
+
return [formatter?.(prefix) + '=' + formatter?.(String(obj))];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const values: string[] = [];
|
|
142
|
+
|
|
143
|
+
if (typeof obj === 'undefined') {
|
|
144
|
+
return values;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
let obj_keys;
|
|
148
|
+
if (generateArrayPrefix === 'comma' && isArray(obj)) {
|
|
149
|
+
// we need to join elements in
|
|
150
|
+
if (encodeValuesOnly && encoder) {
|
|
151
|
+
// @ts-expect-error values only
|
|
152
|
+
obj = maybe_map(obj, encoder);
|
|
153
|
+
}
|
|
154
|
+
obj_keys = [{ value: obj.length > 0 ? obj.join(',') || null : void undefined }];
|
|
155
|
+
} else if (isArray(filter)) {
|
|
156
|
+
obj_keys = filter;
|
|
157
|
+
} else {
|
|
158
|
+
const keys = Object.keys(obj);
|
|
159
|
+
obj_keys = sort ? keys.sort(sort) : keys;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const encoded_prefix = encodeDotInKeys ? String(prefix).replace(/\./g, '%2E') : String(prefix);
|
|
163
|
+
|
|
164
|
+
const adjusted_prefix =
|
|
165
|
+
commaRoundTrip && isArray(obj) && obj.length === 1 ? encoded_prefix + '[]' : encoded_prefix;
|
|
166
|
+
|
|
167
|
+
if (allowEmptyArrays && isArray(obj) && obj.length === 0) {
|
|
168
|
+
return adjusted_prefix + '[]';
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
for (let j = 0; j < obj_keys.length; ++j) {
|
|
172
|
+
const key = obj_keys[j];
|
|
173
|
+
const value =
|
|
174
|
+
// @ts-ignore
|
|
175
|
+
typeof key === 'object' && typeof key.value !== 'undefined' ? key.value : obj[key as any];
|
|
176
|
+
|
|
177
|
+
if (skipNulls && value === null) {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// @ts-ignore
|
|
182
|
+
const encoded_key = allowDots && encodeDotInKeys ? (key as any).replace(/\./g, '%2E') : key;
|
|
183
|
+
const key_prefix =
|
|
184
|
+
isArray(obj) ?
|
|
185
|
+
typeof generateArrayPrefix === 'function' ?
|
|
186
|
+
generateArrayPrefix(adjusted_prefix, encoded_key)
|
|
187
|
+
: adjusted_prefix
|
|
188
|
+
: adjusted_prefix + (allowDots ? '.' + encoded_key : '[' + encoded_key + ']');
|
|
189
|
+
|
|
190
|
+
sideChannel.set(object, step);
|
|
191
|
+
const valueSideChannel = new WeakMap();
|
|
192
|
+
valueSideChannel.set(sentinel, sideChannel);
|
|
193
|
+
push_to_array(
|
|
194
|
+
values,
|
|
195
|
+
inner_stringify(
|
|
196
|
+
value,
|
|
197
|
+
key_prefix,
|
|
198
|
+
generateArrayPrefix,
|
|
199
|
+
commaRoundTrip,
|
|
200
|
+
allowEmptyArrays,
|
|
201
|
+
strictNullHandling,
|
|
202
|
+
skipNulls,
|
|
203
|
+
encodeDotInKeys,
|
|
204
|
+
// @ts-ignore
|
|
205
|
+
generateArrayPrefix === 'comma' && encodeValuesOnly && isArray(obj) ? null : encoder,
|
|
206
|
+
filter,
|
|
207
|
+
sort,
|
|
208
|
+
allowDots,
|
|
209
|
+
serializeDate,
|
|
210
|
+
format,
|
|
211
|
+
formatter,
|
|
212
|
+
encodeValuesOnly,
|
|
213
|
+
charset,
|
|
214
|
+
valueSideChannel,
|
|
215
|
+
),
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return values;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function normalize_stringify_options(
|
|
223
|
+
opts: StringifyOptions = defaults,
|
|
224
|
+
): NonNullableProperties<Omit<StringifyOptions, 'indices'>> & { indices?: boolean } {
|
|
225
|
+
if (typeof opts.allowEmptyArrays !== 'undefined' && typeof opts.allowEmptyArrays !== 'boolean') {
|
|
226
|
+
throw new TypeError('`allowEmptyArrays` option can only be `true` or `false`, when provided');
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (typeof opts.encodeDotInKeys !== 'undefined' && typeof opts.encodeDotInKeys !== 'boolean') {
|
|
230
|
+
throw new TypeError('`encodeDotInKeys` option can only be `true` or `false`, when provided');
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (opts.encoder !== null && typeof opts.encoder !== 'undefined' && typeof opts.encoder !== 'function') {
|
|
234
|
+
throw new TypeError('Encoder has to be a function.');
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const charset = opts.charset || defaults.charset;
|
|
238
|
+
if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
|
|
239
|
+
throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined');
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
let format = default_format;
|
|
243
|
+
if (typeof opts.format !== 'undefined') {
|
|
244
|
+
if (!has(formatters, opts.format)) {
|
|
245
|
+
throw new TypeError('Unknown format option provided.');
|
|
246
|
+
}
|
|
247
|
+
format = opts.format;
|
|
248
|
+
}
|
|
249
|
+
const formatter = formatters[format];
|
|
250
|
+
|
|
251
|
+
let filter = defaults.filter;
|
|
252
|
+
if (typeof opts.filter === 'function' || isArray(opts.filter)) {
|
|
253
|
+
filter = opts.filter;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
let arrayFormat: StringifyOptions['arrayFormat'];
|
|
257
|
+
if (opts.arrayFormat && opts.arrayFormat in array_prefix_generators) {
|
|
258
|
+
arrayFormat = opts.arrayFormat;
|
|
259
|
+
} else if ('indices' in opts) {
|
|
260
|
+
arrayFormat = opts.indices ? 'indices' : 'repeat';
|
|
261
|
+
} else {
|
|
262
|
+
arrayFormat = defaults.arrayFormat;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if ('commaRoundTrip' in opts && typeof opts.commaRoundTrip !== 'boolean') {
|
|
266
|
+
throw new TypeError('`commaRoundTrip` must be a boolean, or absent');
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const allowDots =
|
|
270
|
+
typeof opts.allowDots === 'undefined' ?
|
|
271
|
+
!!opts.encodeDotInKeys === true ?
|
|
272
|
+
true
|
|
273
|
+
: defaults.allowDots
|
|
274
|
+
: !!opts.allowDots;
|
|
275
|
+
|
|
276
|
+
return {
|
|
277
|
+
addQueryPrefix: typeof opts.addQueryPrefix === 'boolean' ? opts.addQueryPrefix : defaults.addQueryPrefix,
|
|
278
|
+
// @ts-ignore
|
|
279
|
+
allowDots: allowDots,
|
|
280
|
+
allowEmptyArrays:
|
|
281
|
+
typeof opts.allowEmptyArrays === 'boolean' ? !!opts.allowEmptyArrays : defaults.allowEmptyArrays,
|
|
282
|
+
arrayFormat: arrayFormat,
|
|
283
|
+
charset: charset,
|
|
284
|
+
charsetSentinel:
|
|
285
|
+
typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
|
|
286
|
+
commaRoundTrip: !!opts.commaRoundTrip,
|
|
287
|
+
delimiter: typeof opts.delimiter === 'undefined' ? defaults.delimiter : opts.delimiter,
|
|
288
|
+
encode: typeof opts.encode === 'boolean' ? opts.encode : defaults.encode,
|
|
289
|
+
encodeDotInKeys:
|
|
290
|
+
typeof opts.encodeDotInKeys === 'boolean' ? opts.encodeDotInKeys : defaults.encodeDotInKeys,
|
|
291
|
+
encoder: typeof opts.encoder === 'function' ? opts.encoder : defaults.encoder,
|
|
292
|
+
encodeValuesOnly:
|
|
293
|
+
typeof opts.encodeValuesOnly === 'boolean' ? opts.encodeValuesOnly : defaults.encodeValuesOnly,
|
|
294
|
+
filter: filter,
|
|
295
|
+
format: format,
|
|
296
|
+
formatter: formatter,
|
|
297
|
+
serializeDate: typeof opts.serializeDate === 'function' ? opts.serializeDate : defaults.serializeDate,
|
|
298
|
+
skipNulls: typeof opts.skipNulls === 'boolean' ? opts.skipNulls : defaults.skipNulls,
|
|
299
|
+
// @ts-ignore
|
|
300
|
+
sort: typeof opts.sort === 'function' ? opts.sort : null,
|
|
301
|
+
strictNullHandling:
|
|
302
|
+
typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling,
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export function stringify(object: any, opts: StringifyOptions = {}) {
|
|
307
|
+
let obj = object;
|
|
308
|
+
const options = normalize_stringify_options(opts);
|
|
309
|
+
|
|
310
|
+
let obj_keys: PropertyKey[] | undefined;
|
|
311
|
+
let filter;
|
|
312
|
+
|
|
313
|
+
if (typeof options.filter === 'function') {
|
|
314
|
+
filter = options.filter;
|
|
315
|
+
obj = filter('', obj);
|
|
316
|
+
} else if (isArray(options.filter)) {
|
|
317
|
+
filter = options.filter;
|
|
318
|
+
obj_keys = filter;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const keys: string[] = [];
|
|
322
|
+
|
|
323
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
324
|
+
return '';
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const generateArrayPrefix = array_prefix_generators[options.arrayFormat];
|
|
328
|
+
const commaRoundTrip = generateArrayPrefix === 'comma' && options.commaRoundTrip;
|
|
329
|
+
|
|
330
|
+
if (!obj_keys) {
|
|
331
|
+
obj_keys = Object.keys(obj);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (options.sort) {
|
|
335
|
+
obj_keys.sort(options.sort);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const sideChannel = new WeakMap();
|
|
339
|
+
for (let i = 0; i < obj_keys.length; ++i) {
|
|
340
|
+
const key = obj_keys[i]!;
|
|
341
|
+
|
|
342
|
+
if (options.skipNulls && obj[key] === null) {
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
push_to_array(
|
|
346
|
+
keys,
|
|
347
|
+
inner_stringify(
|
|
348
|
+
obj[key],
|
|
349
|
+
key,
|
|
350
|
+
// @ts-expect-error
|
|
351
|
+
generateArrayPrefix,
|
|
352
|
+
commaRoundTrip,
|
|
353
|
+
options.allowEmptyArrays,
|
|
354
|
+
options.strictNullHandling,
|
|
355
|
+
options.skipNulls,
|
|
356
|
+
options.encodeDotInKeys,
|
|
357
|
+
options.encode ? options.encoder : null,
|
|
358
|
+
options.filter,
|
|
359
|
+
options.sort,
|
|
360
|
+
options.allowDots,
|
|
361
|
+
options.serializeDate,
|
|
362
|
+
options.format,
|
|
363
|
+
options.formatter,
|
|
364
|
+
options.encodeValuesOnly,
|
|
365
|
+
options.charset,
|
|
366
|
+
sideChannel,
|
|
367
|
+
),
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
const joined = keys.join(options.delimiter);
|
|
372
|
+
let prefix = options.addQueryPrefix === true ? '?' : '';
|
|
373
|
+
|
|
374
|
+
if (options.charsetSentinel) {
|
|
375
|
+
if (options.charset === 'iso-8859-1') {
|
|
376
|
+
// encodeURIComponent('✓'), the "numeric entity" representation of a checkmark
|
|
377
|
+
prefix += 'utf8=%26%2310003%3B&';
|
|
378
|
+
} else {
|
|
379
|
+
// encodeURIComponent('✓')
|
|
380
|
+
prefix += 'utf8=%E2%9C%93&';
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
return joined.length > 0 ? prefix + joined : '';
|
|
385
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export type Format = 'RFC1738' | 'RFC3986';
|
|
2
|
+
|
|
3
|
+
export type DefaultEncoder = (str: any, defaultEncoder?: any, charset?: string) => string;
|
|
4
|
+
export type DefaultDecoder = (str: string, decoder?: any, charset?: string) => string;
|
|
5
|
+
|
|
6
|
+
export type BooleanOptional = boolean | undefined;
|
|
7
|
+
|
|
8
|
+
export type StringifyBaseOptions = {
|
|
9
|
+
delimiter?: string;
|
|
10
|
+
allowDots?: boolean;
|
|
11
|
+
encodeDotInKeys?: boolean;
|
|
12
|
+
strictNullHandling?: boolean;
|
|
13
|
+
skipNulls?: boolean;
|
|
14
|
+
encode?: boolean;
|
|
15
|
+
encoder?: (
|
|
16
|
+
str: any,
|
|
17
|
+
defaultEncoder: DefaultEncoder,
|
|
18
|
+
charset: string,
|
|
19
|
+
type: 'key' | 'value',
|
|
20
|
+
format?: Format,
|
|
21
|
+
) => string;
|
|
22
|
+
filter?: Array<PropertyKey> | ((prefix: PropertyKey, value: any) => any);
|
|
23
|
+
arrayFormat?: 'indices' | 'brackets' | 'repeat' | 'comma';
|
|
24
|
+
indices?: boolean;
|
|
25
|
+
sort?: ((a: PropertyKey, b: PropertyKey) => number) | null;
|
|
26
|
+
serializeDate?: (d: Date) => string;
|
|
27
|
+
format?: 'RFC1738' | 'RFC3986';
|
|
28
|
+
formatter?: (str: PropertyKey) => string;
|
|
29
|
+
encodeValuesOnly?: boolean;
|
|
30
|
+
addQueryPrefix?: boolean;
|
|
31
|
+
charset?: 'utf-8' | 'iso-8859-1';
|
|
32
|
+
charsetSentinel?: boolean;
|
|
33
|
+
allowEmptyArrays?: boolean;
|
|
34
|
+
commaRoundTrip?: boolean;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type StringifyOptions = StringifyBaseOptions;
|
|
38
|
+
|
|
39
|
+
export type ParseBaseOptions = {
|
|
40
|
+
comma?: boolean;
|
|
41
|
+
delimiter?: string | RegExp;
|
|
42
|
+
depth?: number | false;
|
|
43
|
+
decoder?: (str: string, defaultDecoder: DefaultDecoder, charset: string, type: 'key' | 'value') => any;
|
|
44
|
+
arrayLimit?: number;
|
|
45
|
+
parseArrays?: boolean;
|
|
46
|
+
plainObjects?: boolean;
|
|
47
|
+
allowPrototypes?: boolean;
|
|
48
|
+
allowSparse?: boolean;
|
|
49
|
+
parameterLimit?: number;
|
|
50
|
+
strictDepth?: boolean;
|
|
51
|
+
strictNullHandling?: boolean;
|
|
52
|
+
ignoreQueryPrefix?: boolean;
|
|
53
|
+
charset?: 'utf-8' | 'iso-8859-1';
|
|
54
|
+
charsetSentinel?: boolean;
|
|
55
|
+
interpretNumericEntities?: boolean;
|
|
56
|
+
allowEmptyArrays?: boolean;
|
|
57
|
+
duplicates?: 'combine' | 'first' | 'last';
|
|
58
|
+
allowDots?: boolean;
|
|
59
|
+
decodeDotInKeys?: boolean;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export type ParseOptions = ParseBaseOptions;
|
|
63
|
+
|
|
64
|
+
export type ParsedQs = {
|
|
65
|
+
[key: string]: undefined | string | string[] | ParsedQs | ParsedQs[];
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// Type to remove null or undefined union from each property
|
|
69
|
+
export type NonNullableProperties<T> = {
|
|
70
|
+
[K in keyof T]-?: Exclude<T[K], undefined | null>;
|
|
71
|
+
};
|