@furystack/rest 5.0.0 → 5.0.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.
@@ -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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Y,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAA;YAC5F,OAAO,CAAC,GAAG,IAAI,CAAC,CAAA;SACjB;QACD,MAAM,QAAQ,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAGtF,CAAA;QACD,OAAO,CAAC,GAAG,IAAI,EAAE,QAAQ,CAAC,CAAA;IAC5B,CAAC,EAAE,EAAwC,CAAC;SAC3C,GAAG,CAAC,CAAC,CAAC,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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=delete-endpoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delete-endpoint.js","sourceRoot":"","sources":["../../src/endpoint-models/delete-endpoint.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=get-collection-endpoint.js.map
@@ -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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=get-endpoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-endpoint.js","sourceRoot":"","sources":["../../src/endpoint-models/get-endpoint.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
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';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/endpoint-models/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,2BAA2B,CAAA;AACzC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=patch-endpoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patch-endpoint.js","sourceRoot":"","sources":["../../src/endpoint-models/patch-endpoint.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=post-endpoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"post-endpoint.js","sourceRoot":"","sources":["../../src/endpoint-models/post-endpoint.ts"],"names":[],"mappings":""}
package/esm/index.js ADDED
@@ -0,0 +1,7 @@
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';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","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"}
package/esm/methods.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=methods.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"methods.js","sourceRoot":"","sources":["../src/methods.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ export class RequestError extends Error {
2
+ constructor(msg, responseCode) {
3
+ super(msg);
4
+ this.responseCode = responseCode;
5
+ }
6
+ }
7
+ //# sourceMappingURL=request-error.js.map
@@ -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"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=rest-api.js.map
@@ -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.0",
3
+ "version": "5.0.1",
4
4
  "description": "Generic REST package",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -21,7 +21,7 @@
21
21
  }
22
22
  },
23
23
  "files": [
24
- "dist",
24
+ "esm",
25
25
  "types",
26
26
  "src"
27
27
  ],
@@ -46,8 +46,8 @@
46
46
  },
47
47
  "homepage": "https://github.com/furystack/furystack",
48
48
  "dependencies": {
49
- "@furystack/core": "^12.0.0",
50
- "@furystack/inject": "^8.0.0"
49
+ "@furystack/core": "^12.0.1",
50
+ "@furystack/inject": "^8.0.1"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/node": "^18.15.11",