Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@apimatic/core

Package Overview
Dependencies
Maintainers
3
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apimatic/core - npm Package Compare versions

Comparing version 0.7.9 to 0.8.0

170

es/http/queryString.js

@@ -1,2 +0,2 @@

import { __values, __spreadArray, __read } from 'tslib';
import { __spreadArray, __read, __values } from 'tslib';
import { isFileWrapper, cloneFileWrapper } from '../fileWrapper.js';

@@ -9,2 +9,13 @@ /**

function objectEncoding(key, iter, value, prefixFormat) {
var _a;
return formDataEncodeObject((_a = {}, _a[key + "[" + iter + "]"] = value, _a), prefixFormat);
}
function objectArrayEncoding(key, value, prefixFormat, result) {
for (var iter = 0; iter < value.length; iter += 1) {
result.push.apply(result, __spreadArray([], __read(objectEncoding(key, iter, value[iter], prefixFormat))));
}
}
/**

@@ -14,6 +25,131 @@ * Array prefix format: item[1]=1&item[2]=2

var indexedPrefix = function (prefix, key) {
return prefix + "[" + key + "]";
var indexedPrefix = function (key, value, result) {
for (var iter = 0; iter < value.length; iter += 1) {
result.push.apply(result, __spreadArray([], __read(objectEncoding(key, iter, value[iter], indexedPrefix))));
}
};
/**
* Array prefix format: item[]=1&item[]=2
*/
var unindexedPrefix = function (key, value, result) {
var e_1, _a, _b;
if (value.some(function (val) {
return typeof val === 'object';
})) {
objectArrayEncoding(key, value, unindexedPrefix, result);
} else {
try {
for (var value_1 = __values(value), value_1_1 = value_1.next(); !value_1_1.done; value_1_1 = value_1.next()) {
var val = value_1_1.value;
result.push.apply(result, __spreadArray([], __read(formDataEncodeObject((_b = {}, _b[key + '[]'] = val, _b), unindexedPrefix))));
}
} catch (e_1_1) {
e_1 = {
error: e_1_1
};
} finally {
try {
if (value_1_1 && !value_1_1.done && (_a = value_1.return)) _a.call(value_1);
} finally {
if (e_1) throw e_1.error;
}
}
}
};
/**
* Array prefix format: item=1&item=2
*/
var plainPrefix = function (key, value, result) {
var e_2, _a, _b;
if (value.some(function (val) {
return typeof val === 'object';
})) {
objectArrayEncoding(key, value, plainPrefix, result);
} else {
try {
for (var value_2 = __values(value), value_2_1 = value_2.next(); !value_2_1.done; value_2_1 = value_2.next()) {
var val = value_2_1.value;
result.push.apply(result, __spreadArray([], __read(formDataEncodeObject((_b = {}, _b[key] = val, _b), plainPrefix))));
}
} catch (e_2_1) {
e_2 = {
error: e_2_1
};
} finally {
try {
if (value_2_1 && !value_2_1.done && (_a = value_2.return)) _a.call(value_2);
} finally {
if (e_2) throw e_2.error;
}
}
}
};
/**
* Array prefix format: item=1\t2
*/
var tabPrefix = function (key, value, result) {
if (value.some(function (val) {
return typeof val === 'object';
})) {
objectArrayEncoding(key, value, tabPrefix, result);
} else {
var prefixedArray = value.map(function (element) {
return element.toString();
}).join('\t');
result.push.apply(result, [{
key: key,
value: prefixedArray
}]);
}
};
/**
* Array prefix format: item=1,2
*/
var commaPrefix = function (key, value, result) {
if (value.some(function (val) {
return typeof val === 'object';
})) {
objectArrayEncoding(key, value, commaPrefix, result);
} else {
var prefixedArray = value.map(function (element) {
return element.toString();
}).join(',');
result.push.apply(result, [{
key: key,
value: prefixedArray
}]);
}
};
/**
* Array prefix format: item=1|2
*/
var pipePrefix = function (key, value, result) {
if (value.some(function (val) {
return typeof val === 'object';
})) {
objectArrayEncoding(key, value, pipePrefix, result);
} else {
var prefixedArray = value.map(function (element) {
return element.toString();
}).join('|');
result.push.apply(result, [{
key: key,
value: prefixedArray
}]);
}
};
/**
* Converts an object to a list of key-value pairs for form-urlencoded serialization.

@@ -28,3 +164,3 @@ *

function formDataEncodeObject(obj, prefixFormat) {
var e_1, _a, _b, _c;
var e_3, _a, _b;

@@ -38,4 +174,4 @@ if (prefixFormat === void 0) {

try {
for (var _d = __values(Object.keys(obj)), _e = _d.next(); !_e.done; _e = _d.next()) {
var key = _e.value;
for (var _c = __values(Object.keys(obj)), _d = _c.next(); !_d.done; _d = _c.next()) {
var key = _d.value;
var value = obj[key];

@@ -56,5 +192,3 @@

} else if (Array.isArray(value)) {
for (var iter = 0; iter < value.length; iter += 1) {
result.push.apply(result, __spreadArray([], __read(formDataEncodeObject((_b = {}, _b[prefixFormat(key, iter)] = value[iter], _b)))));
}
prefixFormat(key, value, result);
} else if (typeof value === 'object') {

@@ -64,3 +198,3 @@ for (var objectKey in value) {

var element = value[objectKey];
result.push.apply(result, __spreadArray([], __read(formDataEncodeObject((_c = {}, _c[indexedPrefix(key, objectKey)] = element, _c)))));
result.push.apply(result, __spreadArray([], __read(formDataEncodeObject((_b = {}, _b[key + "[" + objectKey + "]"] = element, _b), prefixFormat))));
}

@@ -70,11 +204,11 @@ }

}
} catch (e_1_1) {
e_1 = {
error: e_1_1
} catch (e_3_1) {
e_3 = {
error: e_3_1
};
} finally {
try {
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
} finally {
if (e_1) throw e_1.error;
if (e_3) throw e_3.error;
}

@@ -107,4 +241,4 @@ }

function urlEncodeObject(obj) {
var params = formDataEncodeObject(obj);
function urlEncodeObject(obj, prefixFormat) {
var params = formDataEncodeObject(obj, prefixFormat);
return urlEncodeKeyValuePairs(params);

@@ -127,2 +261,2 @@ }

export { filterFileWrapperFromKeyValuePairs, formDataEncodeObject, indexedPrefix, urlEncodeKeyValuePairs, urlEncodeObject };
export { commaPrefix, filterFileWrapperFromKeyValuePairs, formDataEncodeObject, indexedPrefix, objectArrayEncoding, objectEncoding, pipePrefix, plainPrefix, tabPrefix, unindexedPrefix, urlEncodeKeyValuePairs, urlEncodeObject };

12

es/http/requestBuilder.js

@@ -114,3 +114,3 @@ import { __spreadArray, __read, __assign, __awaiter, __generator } from 'tslib';

DefaultRequestBuilder.prototype.query = function (nameOrParameters, value) {
DefaultRequestBuilder.prototype.query = function (nameOrParameters, value, prefixFormat) {
var _a;

@@ -122,3 +122,3 @@

var queryString = typeof nameOrParameters === 'string' ? urlEncodeObject((_a = {}, _a[nameOrParameters] = value, _a)) : urlEncodeObject(nameOrParameters);
var queryString = typeof nameOrParameters === 'string' ? urlEncodeObject((_a = {}, _a[nameOrParameters] = value, _a), prefixFormat) : urlEncodeObject(nameOrParameters, prefixFormat);

@@ -160,8 +160,8 @@ if (queryString) {

DefaultRequestBuilder.prototype.form = function (parameters) {
this._form = filterFileWrapperFromKeyValuePairs(formDataEncodeObject(parameters));
DefaultRequestBuilder.prototype.form = function (parameters, prefixFormat) {
this._form = filterFileWrapperFromKeyValuePairs(formDataEncodeObject(parameters, prefixFormat));
};
DefaultRequestBuilder.prototype.formData = function (parameters) {
this._formData = formDataEncodeObject(parameters);
DefaultRequestBuilder.prototype.formData = function (parameters, prefixFormat) {
this._formData = formDataEncodeObject(parameters, prefixFormat);
};

@@ -168,0 +168,0 @@

@@ -12,2 +12,3 @@ export { deprecated, isBlob, sanitizeUrl, updateUserAgent } from './apiHelper.js';

export { SkipEncode, pathTemplate } from './http/pathTemplate.js';
export { RequestRetryOption } from './http/retryConfiguration.js';
export { RequestRetryOption } from './http/retryConfiguration.js';
export { commaPrefix, indexedPrefix, pipePrefix, plainPrefix, tabPrefix, unindexedPrefix } from './http/queryString.js';

@@ -21,3 +21,5 @@ /**

*/
export declare type ArrayPrefixFunction = (prefix: string, key: number | string) => string;
export declare type ArrayPrefixFunction = (key: string, value: any[], result: FormKeyValuePairList) => void;
export declare function objectEncoding(key: string, iter: number, value: any, prefixFormat: ArrayPrefixFunction): FormKeyValuePairList;
export declare function objectArrayEncoding(key: string, value: any[], prefixFormat: ArrayPrefixFunction, result: FormKeyValuePairList): void;
/**

@@ -36,2 +38,14 @@ * Array prefix format: item[1]=1&item[2]=2

/**
* Array prefix format: item=1\t2
*/
export declare const tabPrefix: ArrayPrefixFunction;
/**
* Array prefix format: item=1,2
*/
export declare const commaPrefix: ArrayPrefixFunction;
/**
* Array prefix format: item=1|2
*/
export declare const pipePrefix: ArrayPrefixFunction;
/**
* Converts an object to a list of key-value pairs for form-urlencoded serialization.

@@ -61,3 +75,3 @@ *

*/
export declare function urlEncodeObject(obj: Record<string, unknown>): string;
export declare function urlEncodeObject(obj: Record<string, unknown>, prefixFormat?: ArrayPrefixFunction): string;
/**

@@ -64,0 +78,0 @@ * Serializes a list of key-value pairs for a form-urlencoded request.

@@ -8,10 +8,23 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.urlEncodeKeyValuePairs = exports.urlEncodeObject = exports.filterFileWrapperFromKeyValuePairs = exports.formDataEncodeObject = exports.plainPrefix = exports.unindexedPrefix = exports.indexedPrefix = void 0;
exports.urlEncodeKeyValuePairs = exports.urlEncodeObject = exports.filterFileWrapperFromKeyValuePairs = exports.formDataEncodeObject = exports.pipePrefix = exports.commaPrefix = exports.tabPrefix = exports.plainPrefix = exports.unindexedPrefix = exports.indexedPrefix = exports.objectArrayEncoding = exports.objectEncoding = void 0;
var tslib_1 = require("tslib");
var fileWrapper_1 = require("../fileWrapper");
function objectEncoding(key, iter, value, prefixFormat) {
var _a;
return formDataEncodeObject((_a = {}, _a[key + "[" + iter + "]"] = value, _a), prefixFormat);
}
exports.objectEncoding = objectEncoding;
function objectArrayEncoding(key, value, prefixFormat, result) {
for (var iter = 0; iter < value.length; iter += 1) {
result.push.apply(result, tslib_1.__spreadArray([], tslib_1.__read(objectEncoding(key, iter, value[iter], prefixFormat))));
}
}
exports.objectArrayEncoding = objectArrayEncoding;
/**
* Array prefix format: item[1]=1&item[2]=2
*/
var indexedPrefix = function (prefix, key) {
return prefix + "[" + key + "]";
var indexedPrefix = function (key, value, result) {
for (var iter = 0; iter < value.length; iter += 1) {
result.push.apply(result, tslib_1.__spreadArray([], tslib_1.__read(objectEncoding(key, iter, value[iter], exports.indexedPrefix))));
}
};

@@ -22,3 +35,23 @@ exports.indexedPrefix = indexedPrefix;

*/
var unindexedPrefix = function (prefix) { return prefix + '[]'; };
var unindexedPrefix = function (key, value, result) {
var e_1, _a, _b;
if (value.some(function (val) { return typeof val === 'object'; })) {
objectArrayEncoding(key, value, exports.unindexedPrefix, result);
}
else {
try {
for (var value_1 = tslib_1.__values(value), value_1_1 = value_1.next(); !value_1_1.done; value_1_1 = value_1.next()) {
var val = value_1_1.value;
result.push.apply(result, tslib_1.__spreadArray([], tslib_1.__read(formDataEncodeObject((_b = {}, _b[key + '[]'] = val, _b), exports.unindexedPrefix))));
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (value_1_1 && !value_1_1.done && (_a = value_1.return)) _a.call(value_1);
}
finally { if (e_1) throw e_1.error; }
}
}
};
exports.unindexedPrefix = unindexedPrefix;

@@ -28,5 +61,64 @@ /**

*/
var plainPrefix = function (prefix) { return prefix; };
var plainPrefix = function (key, value, result) {
var e_2, _a, _b;
if (value.some(function (val) { return typeof val === 'object'; })) {
objectArrayEncoding(key, value, exports.plainPrefix, result);
}
else {
try {
for (var value_2 = tslib_1.__values(value), value_2_1 = value_2.next(); !value_2_1.done; value_2_1 = value_2.next()) {
var val = value_2_1.value;
result.push.apply(result, tslib_1.__spreadArray([], tslib_1.__read(formDataEncodeObject((_b = {}, _b[key] = val, _b), exports.plainPrefix))));
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (value_2_1 && !value_2_1.done && (_a = value_2.return)) _a.call(value_2);
}
finally { if (e_2) throw e_2.error; }
}
}
};
exports.plainPrefix = plainPrefix;
/**
* Array prefix format: item=1\t2
*/
var tabPrefix = function (key, value, result) {
if (value.some(function (val) { return typeof val === 'object'; })) {
objectArrayEncoding(key, value, exports.tabPrefix, result);
}
else {
var prefixedArray = value.map(function (element) { return element.toString(); }).join('\t');
result.push.apply(result, [{ key: key, value: prefixedArray }]);
}
};
exports.tabPrefix = tabPrefix;
/**
* Array prefix format: item=1,2
*/
var commaPrefix = function (key, value, result) {
if (value.some(function (val) { return typeof val === 'object'; })) {
objectArrayEncoding(key, value, exports.commaPrefix, result);
}
else {
var prefixedArray = value.map(function (element) { return element.toString(); }).join(',');
result.push.apply(result, [{ key: key, value: prefixedArray }]);
}
};
exports.commaPrefix = commaPrefix;
/**
* Array prefix format: item=1|2
*/
var pipePrefix = function (key, value, result) {
if (value.some(function (val) { return typeof val === 'object'; })) {
objectArrayEncoding(key, value, exports.pipePrefix, result);
}
else {
var prefixedArray = value.map(function (element) { return element.toString(); }).join('|');
result.push.apply(result, [{ key: key, value: prefixedArray }]);
}
};
exports.pipePrefix = pipePrefix;
/**
* Converts an object to a list of key-value pairs for form-urlencoded serialization.

@@ -39,8 +131,8 @@ *

function formDataEncodeObject(obj, prefixFormat) {
var e_1, _a, _b, _c;
var e_3, _a, _b;
if (prefixFormat === void 0) { prefixFormat = exports.indexedPrefix; }
var result = [];
try {
for (var _d = tslib_1.__values(Object.keys(obj)), _e = _d.next(); !_e.done; _e = _d.next()) {
var key = _e.value;
for (var _c = tslib_1.__values(Object.keys(obj)), _d = _c.next(); !_d.done; _d = _c.next()) {
var key = _d.value;
var value = obj[key];

@@ -60,5 +152,3 @@ if (value === null || value === undefined) {

else if (Array.isArray(value)) {
for (var iter = 0; iter < value.length; iter += 1) {
result.push.apply(result, tslib_1.__spreadArray([], tslib_1.__read(formDataEncodeObject((_b = {}, _b[prefixFormat(key, iter)] = value[iter], _b)))));
}
prefixFormat(key, value, result);
}

@@ -69,5 +159,5 @@ else if (typeof value === 'object') {

var element = value[objectKey];
result.push.apply(result, tslib_1.__spreadArray([], tslib_1.__read(formDataEncodeObject((_c = {},
_c[exports.indexedPrefix(key, objectKey)] = element,
_c)))));
result.push.apply(result, tslib_1.__spreadArray([], tslib_1.__read(formDataEncodeObject((_b = {},
_b[key + "[" + objectKey + "]"] = element,
_b), prefixFormat))));
}

@@ -78,8 +168,8 @@ }

}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
}
finally { if (e_1) throw e_1.error; }
finally { if (e_3) throw e_3.error; }
}

@@ -106,4 +196,4 @@ return result;

*/
function urlEncodeObject(obj) {
var params = formDataEncodeObject(obj);
function urlEncodeObject(obj, prefixFormat) {
var params = formDataEncodeObject(obj, prefixFormat);
return urlEncodeKeyValuePairs(params);

@@ -110,0 +200,0 @@ }

@@ -15,2 +15,3 @@ /**

import { PathTemplatePrimitiveTypes, PathTemplateTypes, SkipEncode } from './pathTemplate';
import { ArrayPrefixFunction } from './queryString';
import { prepareArgs } from './validate';

@@ -54,6 +55,6 @@ import { RetryConfiguration, RequestRetryOption } from './retryConfiguration';

headers(headersToMerge: Record<string, string>): void;
query(name: string, value: QueryValue): void;
query(parameters?: Record<string, QueryValue> | null): void;
form(parameters: Record<string, unknown>): void;
formData(parameters: Record<string, unknown>): void;
query(name: string, value: QueryValue, prefixFormat?: ArrayPrefixFunction): void;
query(parameters?: Record<string, QueryValue> | null, prefixFormat?: ArrayPrefixFunction): void;
form(parameters: Record<string, unknown>, prefixFormat?: ArrayPrefixFunction): void;
formData(parameters: Record<string, unknown>, prefixFormat?: ArrayPrefixFunction): void;
text(body: string): void;

@@ -115,4 +116,4 @@ json(data: unknown): void;

headers(headersToMerge: Record<string, string>): void;
query(name: string, value: QueryValue): void;
query(parameters?: Record<string, QueryValue> | null): void;
query(name: string, value: QueryValue, prefixFormat?: ArrayPrefixFunction): void;
query(parameters?: Record<string, QueryValue> | null, prefixFormat?: ArrayPrefixFunction): void;
text(body: string): void;

@@ -122,4 +123,4 @@ json(data: unknown): void;

stream(file?: FileWrapper): void;
form(parameters: Record<string, unknown>): void;
formData(parameters: Record<string, unknown>): void;
form(parameters: Record<string, unknown>, prefixFormat?: ArrayPrefixFunction): void;
formData(parameters: Record<string, unknown>, prefixFormat?: ArrayPrefixFunction): void;
toRequest(): HttpRequest;

@@ -126,0 +127,0 @@ intercept(interceptor: HttpInterceptorInterface<RequestOptions | undefined>): void;

@@ -91,3 +91,3 @@ "use strict";

};
DefaultRequestBuilder.prototype.query = function (nameOrParameters, value) {
DefaultRequestBuilder.prototype.query = function (nameOrParameters, value, prefixFormat) {
var _a;

@@ -100,4 +100,4 @@ if (nameOrParameters === null || nameOrParameters === undefined) {

_a[nameOrParameters] = value,
_a))
: queryString_1.urlEncodeObject(nameOrParameters);
_a), prefixFormat)
: queryString_1.urlEncodeObject(nameOrParameters, prefixFormat);
if (queryString) {

@@ -127,7 +127,7 @@ this._query.push(queryString);

};
DefaultRequestBuilder.prototype.form = function (parameters) {
this._form = queryString_1.filterFileWrapperFromKeyValuePairs(queryString_1.formDataEncodeObject(parameters));
DefaultRequestBuilder.prototype.form = function (parameters, prefixFormat) {
this._form = queryString_1.filterFileWrapperFromKeyValuePairs(queryString_1.formDataEncodeObject(parameters, prefixFormat));
};
DefaultRequestBuilder.prototype.formData = function (parameters) {
this._formData = queryString_1.formDataEncodeObject(parameters);
DefaultRequestBuilder.prototype.formData = function (parameters, prefixFormat) {
this._formData = queryString_1.formDataEncodeObject(parameters, prefixFormat);
};

@@ -134,0 +134,0 @@ DefaultRequestBuilder.prototype.toRequest = function () {

@@ -17,2 +17,3 @@ /// <reference path="shim/index.d.ts" />

export { RetryConfiguration, RequestRetryOption, } from './http/retryConfiguration';
export { indexedPrefix, unindexedPrefix, plainPrefix, commaPrefix, tabPrefix, pipePrefix, } from './http/queryString';
//# sourceMappingURL=index.d.ts.map

@@ -5,3 +5,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.RequestRetryOption = void 0;
exports.pipePrefix = exports.tabPrefix = exports.commaPrefix = exports.plainPrefix = exports.unindexedPrefix = exports.indexedPrefix = exports.RequestRetryOption = void 0;
var tslib_1 = require("tslib");

@@ -24,1 +24,8 @@ tslib_1.__exportStar(require("./apiHelper"), exports);

Object.defineProperty(exports, "RequestRetryOption", { enumerable: true, get: function () { return retryConfiguration_1.RequestRetryOption; } });
var queryString_1 = require("./http/queryString");
Object.defineProperty(exports, "indexedPrefix", { enumerable: true, get: function () { return queryString_1.indexedPrefix; } });
Object.defineProperty(exports, "unindexedPrefix", { enumerable: true, get: function () { return queryString_1.unindexedPrefix; } });
Object.defineProperty(exports, "plainPrefix", { enumerable: true, get: function () { return queryString_1.plainPrefix; } });
Object.defineProperty(exports, "commaPrefix", { enumerable: true, get: function () { return queryString_1.commaPrefix; } });
Object.defineProperty(exports, "tabPrefix", { enumerable: true, get: function () { return queryString_1.tabPrefix; } });
Object.defineProperty(exports, "pipePrefix", { enumerable: true, get: function () { return queryString_1.pipePrefix; } });
{
"name": "@apimatic/core",
"author": "Wajahat Iqbal",
"version": "0.7.9",
"version": "0.8.0",
"license": "SEE LICENSE IN LICENSE.md",

@@ -6,0 +6,0 @@ "sideEffects": false,

@@ -26,11 +26,35 @@ /**

export type ArrayPrefixFunction = (
prefix: string,
key: number | string
) => string;
key: string,
value: any[],
result: FormKeyValuePairList
) => void;
export function objectEncoding(
key: string,
iter: number,
value: any,
prefixFormat: ArrayPrefixFunction
): FormKeyValuePairList {
return formDataEncodeObject({ [`${key}[${iter}]`]: value }, prefixFormat);
}
export function objectArrayEncoding(
key: string,
value: any[],
prefixFormat: ArrayPrefixFunction,
result: FormKeyValuePairList
) {
for (let iter = 0; iter < value.length; iter += 1) {
result.push(...objectEncoding(key, iter, value[iter], prefixFormat));
}
}
/**
* Array prefix format: item[1]=1&item[2]=2
*/
export const indexedPrefix: ArrayPrefixFunction = (prefix, key) =>
`${prefix}[${key}]`;
export const indexedPrefix: ArrayPrefixFunction = (key, value, result) => {
for (let iter = 0; iter < value.length; iter += 1) {
result.push(...objectEncoding(key, iter, value[iter], indexedPrefix));
}
};

@@ -40,3 +64,13 @@ /**

*/
export const unindexedPrefix: ArrayPrefixFunction = (prefix) => prefix + '[]';
export const unindexedPrefix: ArrayPrefixFunction = (key, value, result) => {
if (value.some((val) => typeof val === 'object')) {
objectArrayEncoding(key, value, unindexedPrefix, result);
} else {
for (const val of value) {
result.push(
...formDataEncodeObject({ [key + '[]']: val }, unindexedPrefix)
);
}
}
};

@@ -46,5 +80,49 @@ /**

*/
export const plainPrefix: ArrayPrefixFunction = (prefix) => prefix;
export const plainPrefix: ArrayPrefixFunction = (key, value, result) => {
if (value.some((val) => typeof val === 'object')) {
objectArrayEncoding(key, value, plainPrefix, result);
} else {
for (const val of value) {
result.push(...formDataEncodeObject({ [key]: val }, plainPrefix));
}
}
};
/**
* Array prefix format: item=1\t2
*/
export const tabPrefix: ArrayPrefixFunction = (key, value, result) => {
if (value.some((val) => typeof val === 'object')) {
objectArrayEncoding(key, value, tabPrefix, result);
} else {
const prefixedArray = value.map((element) => element.toString()).join('\t');
result.push(...[{ key, value: prefixedArray }]);
}
};
/**
* Array prefix format: item=1,2
*/
export const commaPrefix: ArrayPrefixFunction = (key, value, result) => {
if (value.some((val) => typeof val === 'object')) {
objectArrayEncoding(key, value, commaPrefix, result);
} else {
const prefixedArray = value.map((element) => element.toString()).join(',');
result.push(...[{ key, value: prefixedArray }]);
}
};
/**
* Array prefix format: item=1|2
*/
export const pipePrefix: ArrayPrefixFunction = (key, value, result) => {
if (value.some((val) => typeof val === 'object')) {
objectArrayEncoding(key, value, pipePrefix, result);
} else {
const prefixedArray = value.map((element) => element.toString()).join('|');
result.push(...[{ key, value: prefixedArray }]);
}
};
/**
* Converts an object to a list of key-value pairs for form-urlencoded serialization.

@@ -76,7 +154,3 @@ *

} else if (Array.isArray(value)) {
for (let iter = 0; iter < value.length; iter += 1) {
result.push(
...formDataEncodeObject({ [prefixFormat(key, iter)]: value[iter] })
);
}
prefixFormat(key, value, result);
} else if (typeof value === 'object') {

@@ -87,5 +161,8 @@ for (const objectKey in value) {

result.push(
...formDataEncodeObject({
[indexedPrefix(key, objectKey)]: element,
})
...formDataEncodeObject(
{
[`${key}[${objectKey}]`]: element,
},
prefixFormat
)
);

@@ -119,4 +196,7 @@ }

*/
export function urlEncodeObject(obj: Record<string, unknown>): string {
const params = formDataEncodeObject(obj);
export function urlEncodeObject(
obj: Record<string, unknown>,
prefixFormat?: ArrayPrefixFunction
): string {
const params = formDataEncodeObject(obj, prefixFormat);
return urlEncodeKeyValuePairs(params);

@@ -123,0 +203,0 @@ }

@@ -52,2 +52,3 @@ /**

urlEncodeObject,
ArrayPrefixFunction,
} from './queryString';

@@ -137,6 +138,19 @@ import { prepareArgs } from './validate';

headers(headersToMerge: Record<string, string>): void;
query(name: string, value: QueryValue): void;
query(parameters?: Record<string, QueryValue> | null): void;
form(parameters: Record<string, unknown>): void;
formData(parameters: Record<string, unknown>): void;
query(
name: string,
value: QueryValue,
prefixFormat?: ArrayPrefixFunction
): void;
query(
parameters?: Record<string, QueryValue> | null,
prefixFormat?: ArrayPrefixFunction
): void;
form(
parameters: Record<string, unknown>,
prefixFormat?: ArrayPrefixFunction
): void;
formData(
parameters: Record<string, unknown>,
prefixFormat?: ArrayPrefixFunction
): void;
text(body: string): void;

@@ -277,7 +291,15 @@ json(data: unknown): void;

}
public query(name: string, value: QueryValue): void;
public query(parameters?: Record<string, QueryValue> | null): void;
public query(
name: string,
value: QueryValue,
prefixFormat?: ArrayPrefixFunction
): void;
public query(
parameters?: Record<string, QueryValue> | null,
prefixFormat?: ArrayPrefixFunction
): void;
public query(
nameOrParameters: string | Record<string, QueryValue> | null | undefined,
value?: unknown
value?: unknown,
prefixFormat?: ArrayPrefixFunction
): void {

@@ -289,6 +311,9 @@ if (nameOrParameters === null || nameOrParameters === undefined) {

typeof nameOrParameters === 'string'
? urlEncodeObject({
[nameOrParameters]: value,
})
: urlEncodeObject(nameOrParameters);
? urlEncodeObject(
{
[nameOrParameters]: value,
},
prefixFormat
)
: urlEncodeObject(nameOrParameters, prefixFormat);
if (queryString) {

@@ -325,9 +350,15 @@ this._query.push(queryString);

}
public form(parameters: Record<string, unknown>): void {
public form(
parameters: Record<string, unknown>,
prefixFormat?: ArrayPrefixFunction
): void {
this._form = filterFileWrapperFromKeyValuePairs(
formDataEncodeObject(parameters)
formDataEncodeObject(parameters, prefixFormat)
);
}
public formData(parameters: Record<string, unknown>): void {
this._formData = formDataEncodeObject(parameters);
public formData(
parameters: Record<string, unknown>,
prefixFormat?: ArrayPrefixFunction
): void {
this._formData = formDataEncodeObject(parameters, prefixFormat);
}

@@ -334,0 +365,0 @@ public toRequest(): HttpRequest {

@@ -22,1 +22,9 @@ // tslint:disable-next-line:no-reference

} from './http/retryConfiguration';
export {
indexedPrefix,
unindexedPrefix,
plainPrefix,
commaPrefix,
tabPrefix,
pipePrefix,
} from './http/queryString';
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc