@furystack/rest 5.0.0 → 5.0.2
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/esm/deserialize-query-string.js +43 -0
- package/esm/deserialize-query-string.js.map +1 -0
- package/esm/endpoint-models/delete-endpoint.js +2 -0
- package/esm/endpoint-models/delete-endpoint.js.map +1 -0
- package/esm/endpoint-models/get-collection-endpoint.js +2 -0
- package/esm/endpoint-models/get-collection-endpoint.js.map +1 -0
- package/esm/endpoint-models/get-endpoint.js +2 -0
- package/esm/endpoint-models/get-endpoint.js.map +1 -0
- package/esm/endpoint-models/index.d.ts +6 -0
- package/{types → esm}/endpoint-models/index.d.ts.map +1 -1
- package/esm/endpoint-models/index.js +6 -0
- package/esm/endpoint-models/index.js.map +1 -0
- package/esm/endpoint-models/patch-endpoint.js +2 -0
- package/esm/endpoint-models/patch-endpoint.js.map +1 -0
- package/esm/endpoint-models/post-endpoint.js +2 -0
- package/esm/endpoint-models/post-endpoint.js.map +1 -0
- package/esm/index.d.ts +7 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +7 -0
- package/esm/index.js.map +1 -0
- package/esm/methods.js +2 -0
- package/esm/methods.js.map +1 -0
- package/esm/request-error.js +7 -0
- package/esm/request-error.js.map +1 -0
- package/{types → esm}/rest-api.d.ts +1 -1
- package/{types → esm}/rest-api.d.ts.map +1 -1
- package/esm/rest-api.js +2 -0
- package/esm/rest-api.js.map +1 -0
- package/esm/serialize-to-query-string.js +18 -0
- package/esm/serialize-to-query-string.js.map +1 -0
- package/package.json +6 -15
- package/src/endpoint-models/index.ts +5 -5
- package/src/index.ts +6 -6
- package/src/rest-api.ts +1 -1
- package/types/endpoint-models/index.d.ts +0 -6
- package/types/index.d.ts +0 -7
- package/types/index.d.ts.map +0 -1
- /package/{types → esm}/deserialize-query-string.d.ts +0 -0
- /package/{types → esm}/deserialize-query-string.d.ts.map +0 -0
- /package/{types → esm}/endpoint-models/delete-endpoint.d.ts +0 -0
- /package/{types → esm}/endpoint-models/delete-endpoint.d.ts.map +0 -0
- /package/{types → esm}/endpoint-models/get-collection-endpoint.d.ts +0 -0
- /package/{types → esm}/endpoint-models/get-collection-endpoint.d.ts.map +0 -0
- /package/{types → esm}/endpoint-models/get-endpoint.d.ts +0 -0
- /package/{types → esm}/endpoint-models/get-endpoint.d.ts.map +0 -0
- /package/{types → esm}/endpoint-models/patch-endpoint.d.ts +0 -0
- /package/{types → esm}/endpoint-models/patch-endpoint.d.ts.map +0 -0
- /package/{types → esm}/endpoint-models/post-endpoint.d.ts +0 -0
- /package/{types → esm}/endpoint-models/post-endpoint.d.ts.map +0 -0
- /package/{types → esm}/methods.d.ts +0 -0
- /package/{types → esm}/methods.d.ts.map +0 -0
- /package/{types → esm}/request-error.d.ts +0 -0
- /package/{types → esm}/request-error.d.ts.map +0 -0
- /package/{types → esm}/serialize-to-query-string.d.ts +0 -0
- /package/{types → esm}/serialize-to-query-string.d.ts.map +0 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export const tryDecodeQueryParam = (queryParam) => {
|
|
2
|
+
try {
|
|
3
|
+
return JSON.parse(decodeURIComponent(queryParam.toString()));
|
|
4
|
+
}
|
|
5
|
+
catch {
|
|
6
|
+
try {
|
|
7
|
+
return JSON.parse(queryParam.toString());
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
try {
|
|
11
|
+
return decodeURIComponent(queryParam.toString());
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return queryParam;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
export const deserializeQueryString = (fullQueryString) => {
|
|
20
|
+
const queryString = fullQueryString?.replace?.('?', ''); // trim starting ?
|
|
21
|
+
if (!queryString) {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
const entries = queryString
|
|
25
|
+
.split('&')
|
|
26
|
+
.map((value) => value.split('='))
|
|
27
|
+
.filter(([key, value]) => key?.length && value?.length); // filter out empty keys
|
|
28
|
+
const dedupedValues = entries
|
|
29
|
+
.reduce((prev, current) => {
|
|
30
|
+
const currentKey = current[0];
|
|
31
|
+
const currentValue = tryDecodeQueryParam(current[1]);
|
|
32
|
+
const existing = prev.find(([key]) => key === currentKey);
|
|
33
|
+
if (existing) {
|
|
34
|
+
existing[1] instanceof Array ? existing[1].push(currentValue) : (existing[1] = currentValue);
|
|
35
|
+
return [...prev];
|
|
36
|
+
}
|
|
37
|
+
const newValue = [currentKey, currentKey.includes('[]') ? [currentValue] : currentValue];
|
|
38
|
+
return [...prev, newValue];
|
|
39
|
+
}, [])
|
|
40
|
+
.map(([key, value]) => [key.replace('[]', ''), value]);
|
|
41
|
+
return Object.fromEntries(dedupedValues);
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=deserialize-query-string.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deserialize-query-string.js","sourceRoot":"","sources":["../src/deserialize-query-string.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,UAAe,EAAE,EAAE;IACrD,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAE,UAAkB,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAA;KACtE;IAAC,MAAM;QACN,IAAI;YACF,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAA;SACzC;QAAC,MAAM;YACN,IAAI;gBACF,OAAO,kBAAkB,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAA;aACjD;YAAC,MAAM;gBACN,OAAO,UAAU,CAAA;aAClB;SACF;KACF;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,eAAuB,EAAE,EAAE;IAChE,MAAM,WAAW,GAAG,eAAe,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA,CA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,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,CAAA;IAExD,OAAO,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,CAAA;AAC1C,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-endpoint.js","sourceRoot":"","sources":["../../src/endpoint-models/delete-endpoint.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-collection-endpoint.js","sourceRoot":"","sources":["../../src/endpoint-models/get-collection-endpoint.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-endpoint.js","sourceRoot":"","sources":["../../src/endpoint-models/get-endpoint.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/endpoint-models/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/endpoint-models/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA;AACpC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/endpoint-models/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA;AACpC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch-endpoint.js","sourceRoot":"","sources":["../../src/endpoint-models/patch-endpoint.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"post-endpoint.js","sourceRoot":"","sources":["../../src/endpoint-models/post-endpoint.ts"],"names":[],"mappings":""}
|
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './deserialize-query-string.js';
|
|
2
|
+
export * from './methods.js';
|
|
3
|
+
export * from './rest-api.js';
|
|
4
|
+
export * from './request-error.js';
|
|
5
|
+
export * from './endpoint-models/index.js';
|
|
6
|
+
export * from './serialize-to-query-string.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAA;AAC7C,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA;AAClC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,gCAAgC,CAAA"}
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './deserialize-query-string.js';
|
|
2
|
+
export * from './methods.js';
|
|
3
|
+
export * from './rest-api.js';
|
|
4
|
+
export * from './request-error.js';
|
|
5
|
+
export * from './endpoint-models/index.js';
|
|
6
|
+
export * from './serialize-to-query-string.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAA;AAC7C,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA;AAClC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,gCAAgC,CAAA"}
|
package/esm/methods.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"methods.js","sourceRoot":"","sources":["../src/methods.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-error.js","sourceRoot":"","sources":["../src/request-error.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,GAAW,EAAS,YAAoB;QAClD,KAAK,CAAC,GAAG,CAAC,CAAA;QADoB,iBAAY,GAAZ,YAAY,CAAQ;IAEpD,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest-api.d.ts","sourceRoot":"","sources":["../src/rest-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"rest-api.d.ts","sourceRoot":"","sources":["../src/rest-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAE1C,MAAM,MAAM,OAAO,GAAG;KACnB,OAAO,IAAI,MAAM,CAAC,CAAC,EAAE;QACpB,CAAC,IAAI,EAAE,MAAM,GAAG;YAAE,MAAM,EAAE,OAAO,CAAC;YAAC,GAAG,CAAC,EAAE,OAAO,CAAC;YAAC,KAAK,CAAC,EAAE,OAAO,CAAC;YAAC,IAAI,CAAC,EAAE,OAAO,CAAC;YAAC,OAAO,CAAC,EAAE,OAAO,CAAA;SAAE,CAAA;KACvG;CACF,CAAA"}
|
package/esm/rest-api.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rest-api.js","sourceRoot":"","sources":["../src/rest-api.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const serializeValue = ([key, value]) => {
|
|
2
|
+
if (typeof value === 'object') {
|
|
3
|
+
if (value instanceof Array) {
|
|
4
|
+
if (!value.some((v) => typeof v === 'object')) {
|
|
5
|
+
return value.map((val) => `${key}[]=${encodeURIComponent(val)}`).join('&');
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
return `${key}=${encodeURIComponent(JSON.stringify(value))}`;
|
|
9
|
+
}
|
|
10
|
+
return `${key}=${encodeURIComponent(value)}`;
|
|
11
|
+
};
|
|
12
|
+
export const serializeToQueryString = (query) => {
|
|
13
|
+
return Object.entries(query)
|
|
14
|
+
.filter(([, value]) => value !== undefined)
|
|
15
|
+
.map(serializeValue)
|
|
16
|
+
.join('&');
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=serialize-to-query-string.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize-to-query-string.js","sourceRoot":"","sources":["../src/serialize-to-query-string.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK,CAA4B,EAAE,EAAE;IACxE,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,IAAI,KAAK,YAAY,KAAK,EAAE;YAC1B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,EAAE;gBAC7C,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,MAAM,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;aAC3E;SACF;QACD,OAAO,GAAG,GAAG,IAAI,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAA;KAC7D;IACD,OAAO,GAAG,GAAG,IAAI,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAA;AAC9C,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAmB,KAAQ,EAAU,EAAE;IAC3E,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;SACzB,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC;SAC1C,GAAG,CAAC,cAAc,CAAC;SACnB,IAAI,CAAC,GAAG,CAAC,CAAA;AACd,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@furystack/rest",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.2",
|
|
4
4
|
"description": "Generic REST package",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -8,20 +8,11 @@
|
|
|
8
8
|
},
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"import": "./esm/index.js"
|
|
12
|
-
"types": "./types/index.d.ts"
|
|
13
|
-
},
|
|
14
|
-
"./package.json": "./package.json"
|
|
15
|
-
},
|
|
16
|
-
"typesVersions": {
|
|
17
|
-
"*": {
|
|
18
|
-
"*": [
|
|
19
|
-
"types/*"
|
|
20
|
-
]
|
|
11
|
+
"import": "./esm/index.js"
|
|
21
12
|
}
|
|
22
13
|
},
|
|
23
14
|
"files": [
|
|
24
|
-
"
|
|
15
|
+
"esm",
|
|
25
16
|
"types",
|
|
26
17
|
"src"
|
|
27
18
|
],
|
|
@@ -46,11 +37,11 @@
|
|
|
46
37
|
},
|
|
47
38
|
"homepage": "https://github.com/furystack/furystack",
|
|
48
39
|
"dependencies": {
|
|
49
|
-
"@furystack/core": "^12.0.
|
|
50
|
-
"@furystack/inject": "^8.0.
|
|
40
|
+
"@furystack/core": "^12.0.2",
|
|
41
|
+
"@furystack/inject": "^8.0.2"
|
|
51
42
|
},
|
|
52
43
|
"devDependencies": {
|
|
53
|
-
"@types/node": "^18.
|
|
44
|
+
"@types/node": "^18.16.2",
|
|
54
45
|
"typescript": "^5.0.4",
|
|
55
46
|
"vitest": "^0.30.1"
|
|
56
47
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './delete-endpoint'
|
|
2
|
-
export * from './get-collection-endpoint'
|
|
3
|
-
export * from './get-endpoint'
|
|
4
|
-
export * from './patch-endpoint'
|
|
5
|
-
export * from './post-endpoint'
|
|
1
|
+
export * from './delete-endpoint.js'
|
|
2
|
+
export * from './get-collection-endpoint.js'
|
|
3
|
+
export * from './get-endpoint.js'
|
|
4
|
+
export * from './patch-endpoint.js'
|
|
5
|
+
export * from './post-endpoint.js'
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from './deserialize-query-string'
|
|
2
|
-
export * from './methods'
|
|
3
|
-
export * from './rest-api'
|
|
4
|
-
export * from './request-error'
|
|
5
|
-
export * from './endpoint-models'
|
|
6
|
-
export * from './serialize-to-query-string'
|
|
1
|
+
export * from './deserialize-query-string.js'
|
|
2
|
+
export * from './methods.js'
|
|
3
|
+
export * from './rest-api.js'
|
|
4
|
+
export * from './request-error.js'
|
|
5
|
+
export * from './endpoint-models/index.js'
|
|
6
|
+
export * from './serialize-to-query-string.js'
|
package/src/rest-api.ts
CHANGED
package/types/index.d.ts
DELETED
package/types/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAA;AAC1C,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA;AACjC,cAAc,6BAA6B,CAAA"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|