@lorikeetai/node-sdk 0.1.0-alpha.2 → 0.1.0-alpha.7
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 +58 -0
- package/README.md +26 -21
- package/_shims/MultipartBody.js.map +1 -1
- package/_shims/MultipartBody.mjs.map +1 -1
- package/_shims/auto/runtime-bun.d.ts.map +1 -1
- package/_shims/auto/runtime-bun.js.map +1 -1
- package/_shims/auto/runtime-node.d.ts.map +1 -1
- package/_shims/auto/runtime-node.js.map +1 -1
- package/_shims/auto/runtime.d.ts.map +1 -1
- package/_shims/auto/runtime.js.map +1 -1
- package/_shims/auto/types-node.d.ts.map +1 -1
- package/_shims/auto/types-node.js.map +1 -1
- package/_shims/auto/types.d.ts +52 -52
- package/_shims/bun-runtime.d.ts.map +1 -1
- package/_shims/bun-runtime.js +1 -2
- package/_shims/bun-runtime.js.map +1 -1
- package/_shims/bun-runtime.mjs.map +1 -1
- package/_shims/index.d.ts +36 -36
- package/_shims/index.js +5 -5
- package/_shims/index.mjs +4 -4
- package/_shims/node-runtime.d.ts.map +1 -1
- package/_shims/node-runtime.js +1 -2
- package/_shims/node-runtime.js.map +1 -1
- package/_shims/node-runtime.mjs.map +1 -1
- package/_shims/node-types.d.ts +27 -27
- package/_shims/registry.d.ts.map +1 -1
- package/_shims/registry.js +2 -2
- package/_shims/registry.js.map +1 -1
- package/_shims/registry.mjs.map +1 -1
- package/_shims/web-runtime.d.ts.map +1 -1
- package/_shims/web-runtime.js +1 -2
- package/_shims/web-runtime.js.map +1 -1
- package/_shims/web-runtime.mjs.map +1 -1
- package/_shims/web-types.d.ts +52 -52
- package/core.d.ts +2 -4
- package/core.d.ts.map +1 -1
- package/core.js +7 -6
- package/core.js.map +1 -1
- package/core.mjs +2 -1
- package/core.mjs.map +1 -1
- package/error.d.ts.map +1 -1
- package/error.js.map +1 -1
- package/error.mjs.map +1 -1
- package/index.d.mts +1 -5
- package/index.d.ts +1 -5
- package/index.d.ts.map +1 -1
- package/index.js +4 -14
- package/index.js.map +1 -1
- package/index.mjs +3 -13
- package/index.mjs.map +1 -1
- package/internal/qs/formats.d.ts.map +1 -1
- package/internal/qs/formats.js.map +1 -1
- package/internal/qs/formats.mjs.map +1 -1
- package/internal/qs/index.d.ts.map +1 -1
- package/internal/qs/index.js.map +1 -1
- package/internal/qs/index.mjs.map +1 -1
- package/internal/qs/stringify.d.ts.map +1 -1
- package/internal/qs/stringify.js +1 -2
- package/internal/qs/stringify.js.map +1 -1
- package/internal/qs/stringify.mjs.map +1 -1
- package/internal/qs/types.d.ts.map +1 -1
- package/internal/qs/utils.d.ts.map +1 -1
- package/internal/qs/utils.js +9 -9
- package/internal/qs/utils.js.map +1 -1
- package/internal/qs/utils.mjs.map +1 -1
- package/lib/generate-signature.d.ts +5 -0
- package/lib/generate-signature.d.ts.map +1 -0
- package/lib/generate-signature.js +19 -0
- package/lib/generate-signature.js.map +1 -0
- package/lib/generate-signature.mjs +13 -0
- package/lib/generate-signature.mjs.map +1 -0
- package/package.json +15 -13
- package/resource.d.ts.map +1 -1
- package/resource.js.map +1 -1
- package/resource.mjs.map +1 -1
- package/resources/conversation/chat.d.ts +53 -33
- package/resources/conversation/chat.d.ts.map +1 -1
- package/resources/conversation/chat.js +6 -15
- package/resources/conversation/chat.js.map +1 -1
- package/resources/conversation/chat.mjs +5 -14
- package/resources/conversation/chat.mjs.map +1 -1
- package/resources/conversation/conversation.d.ts +3 -1
- package/resources/conversation/conversation.d.ts.map +1 -1
- package/resources/conversation/conversation.js +1 -1
- package/resources/conversation/conversation.js.map +1 -1
- package/resources/conversation/conversation.mjs.map +1 -1
- package/resources/conversation/index.d.ts +1 -1
- package/resources/conversation/index.d.ts.map +1 -1
- package/resources/conversation/index.js +3 -3
- package/resources/conversation/index.js.map +1 -1
- package/resources/conversation/index.mjs +1 -1
- package/resources/conversation/index.mjs.map +1 -1
- package/resources/conversation.d.ts.map +1 -1
- package/resources/conversation.js.map +1 -1
- package/resources/index.d.ts +1 -1
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs.map +1 -1
- package/resources/ingest.d.ts +1 -34
- package/resources/ingest.d.ts.map +1 -1
- package/resources/ingest.js +2 -15
- package/resources/ingest.js.map +1 -1
- package/resources/ingest.mjs +2 -15
- package/resources/ingest.mjs.map +1 -1
- package/resources/token.d.ts +0 -4
- package/resources/token.d.ts.map +1 -1
- package/resources/token.js +1 -5
- package/resources/token.js.map +1 -1
- package/resources/token.mjs +0 -4
- package/resources/token.mjs.map +1 -1
- package/shims/node.d.ts +0 -4
- package/shims/node.d.ts.map +1 -1
- package/shims/node.js +0 -25
- package/shims/node.js.map +1 -1
- package/shims/node.mjs +0 -1
- package/shims/node.mjs.map +1 -1
- package/shims/web.d.ts.map +1 -1
- package/shims/web.js +0 -25
- package/shims/web.js.map +1 -1
- package/shims/web.mjs +0 -1
- package/shims/web.mjs.map +1 -1
- package/src/_shims/MultipartBody.ts +1 -1
- package/src/_shims/auto/runtime-bun.ts +1 -1
- package/src/_shims/auto/runtime-node.ts +1 -1
- package/src/_shims/auto/runtime.ts +1 -1
- package/src/_shims/auto/types-node.ts +1 -1
- package/src/_shims/auto/types.d.ts +52 -52
- package/src/_shims/bun-runtime.ts +6 -6
- package/src/_shims/index.d.ts +36 -36
- package/src/_shims/index.js +5 -5
- package/src/_shims/index.mjs +4 -4
- package/src/_shims/node-runtime.ts +32 -32
- package/src/_shims/node-types.d.ts +27 -27
- package/src/_shims/registry.ts +44 -44
- package/src/_shims/web-runtime.ts +16 -16
- package/src/_shims/web-types.d.ts +52 -52
- package/src/core.ts +373 -373
- package/src/error.ts +37 -37
- package/src/index.ts +61 -78
- package/src/internal/qs/formats.ts +5 -5
- package/src/internal/qs/index.ts +5 -5
- package/src/internal/qs/stringify.ts +98 -98
- package/src/internal/qs/types.ts +52 -52
- package/src/internal/qs/utils.ts +87 -87
- package/src/lib/generate-signature.ts +13 -0
- package/src/resource.ts +3 -3
- package/src/resources/conversation/chat.ts +70 -51
- package/src/resources/conversation/conversation.ts +10 -8
- package/src/resources/conversation/index.ts +10 -2
- package/src/resources/conversation.ts +1 -1
- package/src/resources/index.ts +3 -3
- package/src/resources/ingest.ts +5 -55
- package/src/resources/token.ts +9 -13
- package/src/shims/node.ts +24 -24
- package/src/shims/web.ts +24 -24
- package/src/uploads.ts +75 -74
- package/src/version.ts +1 -1
- package/uploads.d.ts +2 -2
- package/uploads.d.ts.map +1 -1
- package/uploads.js +3 -4
- package/uploads.js.map +1 -1
- package/uploads.mjs +1 -2
- package/uploads.mjs.map +1 -1
- package/version.d.ts +1 -1
- package/version.d.ts.map +1 -1
- package/version.js +1 -1
- package/version.js.map +1 -1
- package/version.mjs +1 -1
- package/version.mjs.map +1 -1
- package/resources/pets.d.ts +0 -157
- package/resources/pets.d.ts.map +0 -1
- package/resources/pets.js +0 -75
- package/resources/pets.js.map +0 -1
- package/resources/pets.mjs +0 -71
- package/resources/pets.mjs.map +0 -1
- package/resources/shared.d.ts +0 -12
- package/resources/shared.d.ts.map +0 -1
- package/resources/shared.js +0 -4
- package/resources/shared.js.map +0 -1
- package/resources/shared.mjs +0 -3
- package/resources/shared.mjs.map +0 -1
- package/resources/store/index.d.ts +0 -3
- package/resources/store/index.d.ts.map +0 -1
- package/resources/store/index.js +0 -9
- package/resources/store/index.js.map +0 -1
- package/resources/store/index.mjs +0 -4
- package/resources/store/index.mjs.map +0 -1
- package/resources/store/order.d.ts +0 -16
- package/resources/store/order.d.ts.map +0 -1
- package/resources/store/order.js +0 -26
- package/resources/store/order.js.map +0 -1
- package/resources/store/order.mjs +0 -22
- package/resources/store/order.mjs.map +0 -1
- package/resources/store/store.d.ts +0 -35
- package/resources/store/store.d.ts.map +0 -1
- package/resources/store/store.js +0 -53
- package/resources/store/store.js.map +0 -1
- package/resources/store/store.mjs +0 -26
- package/resources/store/store.mjs.map +0 -1
- package/resources/user.d.ts +0 -96
- package/resources/user.d.ts.map +0 -1
- package/resources/user.js +0 -65
- package/resources/user.js.map +0 -1
- package/resources/user.mjs +0 -61
- package/resources/user.mjs.map +0 -1
- package/src/resources/pets.ts +0 -276
- package/src/resources/shared.ts +0 -18
- package/src/resources/store/index.ts +0 -4
- package/src/resources/store/order.ts +0 -26
- package/src/resources/store/store.ts +0 -59
- package/src/resources/user.ts +0 -185
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { encode, is_buffer, maybe_map } from './utils'
|
|
2
|
-
import { default_format, formatters } from './formats'
|
|
3
|
-
import type { NonNullableProperties, StringifyOptions } from './types'
|
|
1
|
+
import { encode, is_buffer, maybe_map } from './utils'
|
|
2
|
+
import { default_format, formatters } from './formats'
|
|
3
|
+
import type { NonNullableProperties, StringifyOptions } from './types'
|
|
4
4
|
|
|
5
|
-
const has = Object.prototype.hasOwnProperty
|
|
5
|
+
const has = Object.prototype.hasOwnProperty
|
|
6
6
|
|
|
7
7
|
const array_prefix_generators = {
|
|
8
8
|
brackets(prefix: PropertyKey) {
|
|
9
|
-
return String(prefix) + '[]'
|
|
9
|
+
return String(prefix) + '[]'
|
|
10
10
|
},
|
|
11
11
|
comma: 'comma',
|
|
12
12
|
indices(prefix: PropertyKey, key: string) {
|
|
13
|
-
return String(prefix) + '[' + key + ']'
|
|
13
|
+
return String(prefix) + '[' + key + ']'
|
|
14
14
|
},
|
|
15
15
|
repeat(prefix: PropertyKey) {
|
|
16
|
-
return String(prefix)
|
|
16
|
+
return String(prefix)
|
|
17
17
|
},
|
|
18
|
-
}
|
|
18
|
+
}
|
|
19
19
|
|
|
20
|
-
const is_array = Array.isArray
|
|
21
|
-
const push = Array.prototype.push
|
|
20
|
+
const is_array = Array.isArray
|
|
21
|
+
const push = Array.prototype.push
|
|
22
22
|
const push_to_array = function (arr: any[], value_or_array: any) {
|
|
23
|
-
push.apply(arr, is_array(value_or_array) ? value_or_array : [value_or_array])
|
|
24
|
-
}
|
|
23
|
+
push.apply(arr, is_array(value_or_array) ? value_or_array : [value_or_array])
|
|
24
|
+
}
|
|
25
25
|
|
|
26
|
-
const to_ISO = Date.prototype.toISOString
|
|
26
|
+
const to_ISO = Date.prototype.toISOString
|
|
27
27
|
|
|
28
28
|
const defaults = {
|
|
29
29
|
addQueryPrefix: false,
|
|
@@ -42,11 +42,11 @@ const defaults = {
|
|
|
42
42
|
/** @deprecated */
|
|
43
43
|
indices: false,
|
|
44
44
|
serializeDate(date) {
|
|
45
|
-
return to_ISO.call(date)
|
|
45
|
+
return to_ISO.call(date)
|
|
46
46
|
},
|
|
47
47
|
skipNulls: false,
|
|
48
48
|
strictNullHandling: false,
|
|
49
|
-
} as NonNullableProperties<StringifyOptions & { formatter: (typeof formatters)['RFC1738'] }
|
|
49
|
+
} as NonNullableProperties<StringifyOptions & { formatter: (typeof formatters)['RFC1738'] }>
|
|
50
50
|
|
|
51
51
|
function is_non_nullish_primitive(v: unknown): v is string | number | boolean | symbol | bigint {
|
|
52
52
|
return (
|
|
@@ -55,10 +55,10 @@ function is_non_nullish_primitive(v: unknown): v is string | number | boolean |
|
|
|
55
55
|
typeof v === 'boolean' ||
|
|
56
56
|
typeof v === 'symbol' ||
|
|
57
57
|
typeof v === 'bigint'
|
|
58
|
-
)
|
|
58
|
+
)
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
const sentinel = {}
|
|
61
|
+
const sentinel = {}
|
|
62
62
|
|
|
63
63
|
function inner_stringify(
|
|
64
64
|
object: any,
|
|
@@ -80,38 +80,38 @@ function inner_stringify(
|
|
|
80
80
|
charset: StringifyOptions['charset'],
|
|
81
81
|
sideChannel: WeakMap<any, any>,
|
|
82
82
|
) {
|
|
83
|
-
let obj = object
|
|
83
|
+
let obj = object
|
|
84
84
|
|
|
85
|
-
let tmp_sc = sideChannel
|
|
86
|
-
let step = 0
|
|
87
|
-
let find_flag = false
|
|
85
|
+
let tmp_sc = sideChannel
|
|
86
|
+
let step = 0
|
|
87
|
+
let find_flag = false
|
|
88
88
|
while ((tmp_sc = tmp_sc.get(sentinel)) !== void undefined && !find_flag) {
|
|
89
89
|
// Where object last appeared in the ref tree
|
|
90
|
-
const pos = tmp_sc.get(object)
|
|
91
|
-
step += 1
|
|
90
|
+
const pos = tmp_sc.get(object)
|
|
91
|
+
step += 1
|
|
92
92
|
if (typeof pos !== 'undefined') {
|
|
93
93
|
if (pos === step) {
|
|
94
|
-
throw new RangeError('Cyclic object value')
|
|
94
|
+
throw new RangeError('Cyclic object value')
|
|
95
95
|
} else {
|
|
96
|
-
find_flag = true
|
|
96
|
+
find_flag = true // Break while
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
if (typeof tmp_sc.get(sentinel) === 'undefined') {
|
|
100
|
-
step = 0
|
|
100
|
+
step = 0
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
if (typeof filter === 'function') {
|
|
105
|
-
obj = filter(prefix, obj)
|
|
105
|
+
obj = filter(prefix, obj)
|
|
106
106
|
} else if (obj instanceof Date) {
|
|
107
|
-
obj = serializeDate?.(obj)
|
|
107
|
+
obj = serializeDate?.(obj)
|
|
108
108
|
} else if (generateArrayPrefix === 'comma' && is_array(obj)) {
|
|
109
109
|
obj = maybe_map(obj, function (value) {
|
|
110
110
|
if (value instanceof Date) {
|
|
111
|
-
return serializeDate?.(value)
|
|
111
|
+
return serializeDate?.(value)
|
|
112
112
|
}
|
|
113
|
-
return value
|
|
114
|
-
})
|
|
113
|
+
return value
|
|
114
|
+
})
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
if (obj === null) {
|
|
@@ -119,10 +119,10 @@ function inner_stringify(
|
|
|
119
119
|
return encoder && !encodeValuesOnly ?
|
|
120
120
|
// @ts-expect-error
|
|
121
121
|
encoder(prefix, defaults.encoder, charset, 'key', format)
|
|
122
|
-
: prefix
|
|
122
|
+
: prefix
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
obj = ''
|
|
125
|
+
obj = ''
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
if (is_non_nullish_primitive(obj) || is_buffer(obj)) {
|
|
@@ -130,69 +130,69 @@ function inner_stringify(
|
|
|
130
130
|
const key_value =
|
|
131
131
|
encodeValuesOnly ? prefix
|
|
132
132
|
// @ts-expect-error
|
|
133
|
-
: encoder(prefix, defaults.encoder, charset, 'key', format)
|
|
133
|
+
: encoder(prefix, defaults.encoder, charset, 'key', format)
|
|
134
134
|
return [
|
|
135
135
|
formatter?.(key_value) +
|
|
136
136
|
'=' +
|
|
137
137
|
// @ts-expect-error
|
|
138
138
|
formatter?.(encoder(obj, defaults.encoder, charset, 'value', format)),
|
|
139
|
-
]
|
|
139
|
+
]
|
|
140
140
|
}
|
|
141
|
-
return [formatter?.(prefix) + '=' + formatter?.(String(obj))]
|
|
141
|
+
return [formatter?.(prefix) + '=' + formatter?.(String(obj))]
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
const values: string[] = []
|
|
144
|
+
const values: string[] = []
|
|
145
145
|
|
|
146
146
|
if (typeof obj === 'undefined') {
|
|
147
|
-
return values
|
|
147
|
+
return values
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
let obj_keys
|
|
150
|
+
let obj_keys
|
|
151
151
|
if (generateArrayPrefix === 'comma' && is_array(obj)) {
|
|
152
152
|
// we need to join elements in
|
|
153
153
|
if (encodeValuesOnly && encoder) {
|
|
154
154
|
// @ts-expect-error values only
|
|
155
|
-
obj = maybe_map(obj, encoder)
|
|
155
|
+
obj = maybe_map(obj, encoder)
|
|
156
156
|
}
|
|
157
|
-
obj_keys = [{ value: obj.length > 0 ? obj.join(',') || null : void undefined }]
|
|
157
|
+
obj_keys = [{ value: obj.length > 0 ? obj.join(',') || null : void undefined }]
|
|
158
158
|
} else if (is_array(filter)) {
|
|
159
|
-
obj_keys = filter
|
|
159
|
+
obj_keys = filter
|
|
160
160
|
} else {
|
|
161
|
-
const keys = Object.keys(obj)
|
|
162
|
-
obj_keys = sort ? keys.sort(sort) : keys
|
|
161
|
+
const keys = Object.keys(obj)
|
|
162
|
+
obj_keys = sort ? keys.sort(sort) : keys
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
const encoded_prefix = encodeDotInKeys ? String(prefix).replace(/\./g, '%2E') : String(prefix)
|
|
165
|
+
const encoded_prefix = encodeDotInKeys ? String(prefix).replace(/\./g, '%2E') : String(prefix)
|
|
166
166
|
|
|
167
167
|
const adjusted_prefix =
|
|
168
|
-
commaRoundTrip && is_array(obj) && obj.length === 1 ? encoded_prefix + '[]' : encoded_prefix
|
|
168
|
+
commaRoundTrip && is_array(obj) && obj.length === 1 ? encoded_prefix + '[]' : encoded_prefix
|
|
169
169
|
|
|
170
170
|
if (allowEmptyArrays && is_array(obj) && obj.length === 0) {
|
|
171
|
-
return adjusted_prefix + '[]'
|
|
171
|
+
return adjusted_prefix + '[]'
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
for (let j = 0; j < obj_keys.length; ++j) {
|
|
175
|
-
const key = obj_keys[j]
|
|
175
|
+
const key = obj_keys[j]
|
|
176
176
|
const value =
|
|
177
177
|
// @ts-ignore
|
|
178
|
-
typeof key === 'object' && typeof key.value !== 'undefined' ? key.value : obj[key as any]
|
|
178
|
+
typeof key === 'object' && typeof key.value !== 'undefined' ? key.value : obj[key as any]
|
|
179
179
|
|
|
180
180
|
if (skipNulls && value === null) {
|
|
181
|
-
continue
|
|
181
|
+
continue
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
// @ts-ignore
|
|
185
|
-
const encoded_key = allowDots && encodeDotInKeys ? (key as any).replace(/\./g, '%2E') : key
|
|
185
|
+
const encoded_key = allowDots && encodeDotInKeys ? (key as any).replace(/\./g, '%2E') : key
|
|
186
186
|
const key_prefix =
|
|
187
187
|
is_array(obj) ?
|
|
188
188
|
typeof generateArrayPrefix === 'function' ?
|
|
189
189
|
generateArrayPrefix(adjusted_prefix, encoded_key)
|
|
190
190
|
: adjusted_prefix
|
|
191
|
-
: adjusted_prefix + (allowDots ? '.' + encoded_key : '[' + encoded_key + ']')
|
|
191
|
+
: adjusted_prefix + (allowDots ? '.' + encoded_key : '[' + encoded_key + ']')
|
|
192
192
|
|
|
193
|
-
sideChannel.set(object, step)
|
|
194
|
-
const valueSideChannel = new WeakMap()
|
|
195
|
-
valueSideChannel.set(sentinel, sideChannel)
|
|
193
|
+
sideChannel.set(object, step)
|
|
194
|
+
const valueSideChannel = new WeakMap()
|
|
195
|
+
valueSideChannel.set(sentinel, sideChannel)
|
|
196
196
|
push_to_array(
|
|
197
197
|
values,
|
|
198
198
|
inner_stringify(
|
|
@@ -216,57 +216,57 @@ function inner_stringify(
|
|
|
216
216
|
charset,
|
|
217
217
|
valueSideChannel,
|
|
218
218
|
),
|
|
219
|
-
)
|
|
219
|
+
)
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
-
return values
|
|
222
|
+
return values
|
|
223
223
|
}
|
|
224
224
|
|
|
225
225
|
function normalize_stringify_options(
|
|
226
226
|
opts: StringifyOptions = defaults,
|
|
227
227
|
): NonNullableProperties<Omit<StringifyOptions, 'indices'>> & { indices?: boolean } {
|
|
228
228
|
if (typeof opts.allowEmptyArrays !== 'undefined' && typeof opts.allowEmptyArrays !== 'boolean') {
|
|
229
|
-
throw new TypeError('`allowEmptyArrays` option can only be `true` or `false`, when provided')
|
|
229
|
+
throw new TypeError('`allowEmptyArrays` option can only be `true` or `false`, when provided')
|
|
230
230
|
}
|
|
231
231
|
|
|
232
232
|
if (typeof opts.encodeDotInKeys !== 'undefined' && typeof opts.encodeDotInKeys !== 'boolean') {
|
|
233
|
-
throw new TypeError('`encodeDotInKeys` option can only be `true` or `false`, when provided')
|
|
233
|
+
throw new TypeError('`encodeDotInKeys` option can only be `true` or `false`, when provided')
|
|
234
234
|
}
|
|
235
235
|
|
|
236
236
|
if (opts.encoder !== null && typeof opts.encoder !== 'undefined' && typeof opts.encoder !== 'function') {
|
|
237
|
-
throw new TypeError('Encoder has to be a function.')
|
|
237
|
+
throw new TypeError('Encoder has to be a function.')
|
|
238
238
|
}
|
|
239
239
|
|
|
240
|
-
const charset = opts.charset || defaults.charset
|
|
240
|
+
const charset = opts.charset || defaults.charset
|
|
241
241
|
if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
|
|
242
|
-
throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined')
|
|
242
|
+
throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined')
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
-
let format = default_format
|
|
245
|
+
let format = default_format
|
|
246
246
|
if (typeof opts.format !== 'undefined') {
|
|
247
247
|
if (!has.call(formatters, opts.format)) {
|
|
248
|
-
throw new TypeError('Unknown format option provided.')
|
|
248
|
+
throw new TypeError('Unknown format option provided.')
|
|
249
249
|
}
|
|
250
|
-
format = opts.format
|
|
250
|
+
format = opts.format
|
|
251
251
|
}
|
|
252
|
-
const formatter = formatters[format]
|
|
252
|
+
const formatter = formatters[format]
|
|
253
253
|
|
|
254
|
-
let filter = defaults.filter
|
|
254
|
+
let filter = defaults.filter
|
|
255
255
|
if (typeof opts.filter === 'function' || is_array(opts.filter)) {
|
|
256
|
-
filter = opts.filter
|
|
256
|
+
filter = opts.filter
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
-
let arrayFormat: StringifyOptions['arrayFormat']
|
|
259
|
+
let arrayFormat: StringifyOptions['arrayFormat']
|
|
260
260
|
if (opts.arrayFormat && opts.arrayFormat in array_prefix_generators) {
|
|
261
|
-
arrayFormat = opts.arrayFormat
|
|
261
|
+
arrayFormat = opts.arrayFormat
|
|
262
262
|
} else if ('indices' in opts) {
|
|
263
|
-
arrayFormat = opts.indices ? 'indices' : 'repeat'
|
|
263
|
+
arrayFormat = opts.indices ? 'indices' : 'repeat'
|
|
264
264
|
} else {
|
|
265
|
-
arrayFormat = defaults.arrayFormat
|
|
265
|
+
arrayFormat = defaults.arrayFormat
|
|
266
266
|
}
|
|
267
267
|
|
|
268
268
|
if ('commaRoundTrip' in opts && typeof opts.commaRoundTrip !== 'boolean') {
|
|
269
|
-
throw new TypeError('`commaRoundTrip` must be a boolean, or absent')
|
|
269
|
+
throw new TypeError('`commaRoundTrip` must be a boolean, or absent')
|
|
270
270
|
}
|
|
271
271
|
|
|
272
272
|
const allowDots =
|
|
@@ -274,7 +274,7 @@ function normalize_stringify_options(
|
|
|
274
274
|
!!opts.encodeDotInKeys === true ?
|
|
275
275
|
true
|
|
276
276
|
: defaults.allowDots
|
|
277
|
-
: !!opts.allowDots
|
|
277
|
+
: !!opts.allowDots
|
|
278
278
|
|
|
279
279
|
return {
|
|
280
280
|
addQueryPrefix: typeof opts.addQueryPrefix === 'boolean' ? opts.addQueryPrefix : defaults.addQueryPrefix,
|
|
@@ -303,47 +303,47 @@ function normalize_stringify_options(
|
|
|
303
303
|
sort: typeof opts.sort === 'function' ? opts.sort : null,
|
|
304
304
|
strictNullHandling:
|
|
305
305
|
typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling,
|
|
306
|
-
}
|
|
306
|
+
}
|
|
307
307
|
}
|
|
308
308
|
|
|
309
309
|
export function stringify(object: any, opts: StringifyOptions = {}) {
|
|
310
|
-
let obj = object
|
|
311
|
-
const options = normalize_stringify_options(opts)
|
|
310
|
+
let obj = object
|
|
311
|
+
const options = normalize_stringify_options(opts)
|
|
312
312
|
|
|
313
|
-
let obj_keys: PropertyKey[] | undefined
|
|
314
|
-
let filter
|
|
313
|
+
let obj_keys: PropertyKey[] | undefined
|
|
314
|
+
let filter
|
|
315
315
|
|
|
316
316
|
if (typeof options.filter === 'function') {
|
|
317
|
-
filter = options.filter
|
|
318
|
-
obj = filter('', obj)
|
|
317
|
+
filter = options.filter
|
|
318
|
+
obj = filter('', obj)
|
|
319
319
|
} else if (is_array(options.filter)) {
|
|
320
|
-
filter = options.filter
|
|
321
|
-
obj_keys = filter
|
|
320
|
+
filter = options.filter
|
|
321
|
+
obj_keys = filter
|
|
322
322
|
}
|
|
323
323
|
|
|
324
|
-
const keys: string[] = []
|
|
324
|
+
const keys: string[] = []
|
|
325
325
|
|
|
326
326
|
if (typeof obj !== 'object' || obj === null) {
|
|
327
|
-
return ''
|
|
327
|
+
return ''
|
|
328
328
|
}
|
|
329
329
|
|
|
330
|
-
const generateArrayPrefix = array_prefix_generators[options.arrayFormat]
|
|
331
|
-
const commaRoundTrip = generateArrayPrefix === 'comma' && options.commaRoundTrip
|
|
330
|
+
const generateArrayPrefix = array_prefix_generators[options.arrayFormat]
|
|
331
|
+
const commaRoundTrip = generateArrayPrefix === 'comma' && options.commaRoundTrip
|
|
332
332
|
|
|
333
333
|
if (!obj_keys) {
|
|
334
|
-
obj_keys = Object.keys(obj)
|
|
334
|
+
obj_keys = Object.keys(obj)
|
|
335
335
|
}
|
|
336
336
|
|
|
337
337
|
if (options.sort) {
|
|
338
|
-
obj_keys.sort(options.sort)
|
|
338
|
+
obj_keys.sort(options.sort)
|
|
339
339
|
}
|
|
340
340
|
|
|
341
|
-
const sideChannel = new WeakMap()
|
|
341
|
+
const sideChannel = new WeakMap()
|
|
342
342
|
for (let i = 0; i < obj_keys.length; ++i) {
|
|
343
|
-
const key = obj_keys[i]
|
|
343
|
+
const key = obj_keys[i]!
|
|
344
344
|
|
|
345
345
|
if (options.skipNulls && obj[key] === null) {
|
|
346
|
-
continue
|
|
346
|
+
continue
|
|
347
347
|
}
|
|
348
348
|
push_to_array(
|
|
349
349
|
keys,
|
|
@@ -368,21 +368,21 @@ export function stringify(object: any, opts: StringifyOptions = {}) {
|
|
|
368
368
|
options.charset,
|
|
369
369
|
sideChannel,
|
|
370
370
|
),
|
|
371
|
-
)
|
|
371
|
+
)
|
|
372
372
|
}
|
|
373
373
|
|
|
374
|
-
const joined = keys.join(options.delimiter)
|
|
375
|
-
let prefix = options.addQueryPrefix === true ? '?' : ''
|
|
374
|
+
const joined = keys.join(options.delimiter)
|
|
375
|
+
let prefix = options.addQueryPrefix === true ? '?' : ''
|
|
376
376
|
|
|
377
377
|
if (options.charsetSentinel) {
|
|
378
378
|
if (options.charset === 'iso-8859-1') {
|
|
379
379
|
// encodeURIComponent('✓'), the "numeric entity" representation of a checkmark
|
|
380
|
-
prefix += 'utf8=%26%2310003%3B&'
|
|
380
|
+
prefix += 'utf8=%26%2310003%3B&'
|
|
381
381
|
} else {
|
|
382
382
|
// encodeURIComponent('✓')
|
|
383
|
-
prefix += 'utf8=%E2%9C%93&'
|
|
383
|
+
prefix += 'utf8=%E2%9C%93&'
|
|
384
384
|
}
|
|
385
385
|
}
|
|
386
386
|
|
|
387
|
-
return joined.length > 0 ? prefix + joined : ''
|
|
387
|
+
return joined.length > 0 ? prefix + joined : ''
|
|
388
388
|
}
|
package/src/internal/qs/types.ts
CHANGED
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
export type Format = 'RFC1738' | 'RFC3986'
|
|
1
|
+
export type Format = 'RFC1738' | 'RFC3986'
|
|
2
2
|
|
|
3
|
-
export type DefaultEncoder = (str: any, defaultEncoder?: any, charset?: string) => string
|
|
4
|
-
export type DefaultDecoder = (str: string, decoder?: any, charset?: string) => string
|
|
3
|
+
export type DefaultEncoder = (str: any, defaultEncoder?: any, charset?: string) => string
|
|
4
|
+
export type DefaultDecoder = (str: string, decoder?: any, charset?: string) => string
|
|
5
5
|
|
|
6
|
-
export type BooleanOptional = boolean | undefined
|
|
6
|
+
export type BooleanOptional = boolean | undefined
|
|
7
7
|
|
|
8
8
|
export type StringifyBaseOptions = {
|
|
9
|
-
delimiter?: string
|
|
10
|
-
allowDots?: boolean
|
|
11
|
-
encodeDotInKeys?: boolean
|
|
12
|
-
strictNullHandling?: boolean
|
|
13
|
-
skipNulls?: boolean
|
|
14
|
-
encode?: boolean
|
|
9
|
+
delimiter?: string
|
|
10
|
+
allowDots?: boolean
|
|
11
|
+
encodeDotInKeys?: boolean
|
|
12
|
+
strictNullHandling?: boolean
|
|
13
|
+
skipNulls?: boolean
|
|
14
|
+
encode?: boolean
|
|
15
15
|
encoder?: (
|
|
16
16
|
str: any,
|
|
17
17
|
defaultEncoder: DefaultEncoder,
|
|
18
18
|
charset: string,
|
|
19
19
|
type: 'key' | 'value',
|
|
20
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
|
-
}
|
|
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
36
|
|
|
37
|
-
export type StringifyOptions = StringifyBaseOptions
|
|
37
|
+
export type StringifyOptions = StringifyBaseOptions
|
|
38
38
|
|
|
39
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
|
-
}
|
|
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
61
|
|
|
62
|
-
export type ParseOptions = ParseBaseOptions
|
|
62
|
+
export type ParseOptions = ParseBaseOptions
|
|
63
63
|
|
|
64
64
|
export type ParsedQs = {
|
|
65
|
-
[key: string]: undefined | string | string[] | ParsedQs | ParsedQs[]
|
|
66
|
-
}
|
|
65
|
+
[key: string]: undefined | string | string[] | ParsedQs | ParsedQs[]
|
|
66
|
+
}
|
|
67
67
|
|
|
68
68
|
// Type to remove null or undefined union from each property
|
|
69
69
|
export type NonNullableProperties<T> = {
|
|
70
|
-
[K in keyof T]-?: Exclude<T[K], undefined | null
|
|
71
|
-
}
|
|
70
|
+
[K in keyof T]-?: Exclude<T[K], undefined | null>
|
|
71
|
+
}
|