@fjell/client-api 4.4.2 → 4.4.4

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.
Files changed (76) hide show
  1. package/.kodrdriv/config.yaml +4 -0
  2. package/commit.sh +8 -0
  3. package/dist/AItemAPI.js +6 -1
  4. package/dist/AItemAPI.js.map +1 -1
  5. package/dist/CItemAPI.d.ts +13 -12
  6. package/dist/CItemAPI.js +1 -0
  7. package/dist/CItemAPI.js.map +1 -1
  8. package/dist/ClientApi.d.ts +13 -13
  9. package/dist/ClientApiOptions.d.ts +5 -0
  10. package/dist/PItemAPI.d.ts +14 -13
  11. package/dist/PItemAPI.js +13 -11
  12. package/dist/PItemAPI.js.map +1 -1
  13. package/dist/Utilities.js.map +1 -1
  14. package/dist/index.cjs +132 -91
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/logger.js.map +1 -1
  17. package/dist/ops/action.d.ts +2 -2
  18. package/dist/ops/action.js +6 -5
  19. package/dist/ops/action.js.map +1 -1
  20. package/dist/ops/all.d.ts +2 -2
  21. package/dist/ops/all.js +7 -6
  22. package/dist/ops/all.js.map +1 -1
  23. package/dist/ops/allAction.d.ts +2 -2
  24. package/dist/ops/allAction.js +6 -5
  25. package/dist/ops/allAction.js.map +1 -1
  26. package/dist/ops/allFacet.d.ts +5 -0
  27. package/dist/ops/allFacet.js +24 -0
  28. package/dist/ops/allFacet.js.map +1 -0
  29. package/dist/ops/create.d.ts +3 -3
  30. package/dist/ops/create.js +6 -5
  31. package/dist/ops/create.js.map +1 -1
  32. package/dist/ops/facet.d.ts +2 -2
  33. package/dist/ops/facet.js +7 -5
  34. package/dist/ops/facet.js.map +1 -1
  35. package/dist/ops/find.d.ts +2 -2
  36. package/dist/ops/find.js +10 -9
  37. package/dist/ops/find.js.map +1 -1
  38. package/dist/ops/findOne.d.ts +2 -2
  39. package/dist/ops/findOne.js +8 -7
  40. package/dist/ops/findOne.js.map +1 -1
  41. package/dist/ops/get.d.ts +2 -2
  42. package/dist/ops/get.js +6 -5
  43. package/dist/ops/get.js.map +1 -1
  44. package/dist/ops/index.js +2 -0
  45. package/dist/ops/index.js.map +1 -1
  46. package/dist/ops/one.d.ts +2 -2
  47. package/dist/ops/one.js +7 -6
  48. package/dist/ops/one.js.map +1 -1
  49. package/dist/ops/remove.d.ts +2 -2
  50. package/dist/ops/remove.js +6 -5
  51. package/dist/ops/remove.js.map +1 -1
  52. package/dist/ops/update.d.ts +3 -3
  53. package/dist/ops/update.js +6 -5
  54. package/dist/ops/update.js.map +1 -1
  55. package/dist/util/general.d.ts +4 -0
  56. package/package.json +13 -13
  57. package/release.sh +89 -0
  58. package/src/AItemAPI.ts +5 -0
  59. package/src/CItemAPI.ts +14 -22
  60. package/src/ClientApi.ts +60 -66
  61. package/src/ClientApiOptions.ts +5 -0
  62. package/src/PItemAPI.ts +38 -56
  63. package/src/ops/action.ts +19 -23
  64. package/src/ops/all.ts +17 -19
  65. package/src/ops/allAction.ts +18 -21
  66. package/src/ops/allFacet.ts +46 -0
  67. package/src/ops/create.ts +22 -25
  68. package/src/ops/facet.ts +4 -5
  69. package/src/ops/find.ts +20 -23
  70. package/src/ops/findOne.ts +4 -5
  71. package/src/ops/get.ts +17 -20
  72. package/src/ops/index.ts +6 -0
  73. package/src/ops/one.ts +3 -5
  74. package/src/ops/remove.ts +17 -20
  75. package/src/ops/update.ts +18 -21
  76. package/src/util/general.ts +65 -0
@@ -0,0 +1,46 @@
1
+ import {
2
+ Item,
3
+ LocKeyArray
4
+ } from "@fjell/core";
5
+ import { HttpApi } from "@fjell/http-api";
6
+
7
+ import { ClientApiOptions } from "@/ClientApiOptions";
8
+ import LibLogger from "@/logger";
9
+ import { Utilities } from "@/Utilities";
10
+
11
+ const logger = LibLogger.get('client-api', 'ops', 'allFacet');
12
+
13
+ export const getAllFacetOperation = <
14
+ V extends Item<S, L1, L2, L3, L4, L5>,
15
+ S extends string,
16
+ L1 extends string = never,
17
+ L2 extends string = never,
18
+ L3 extends string = never,
19
+ L4 extends string = never,
20
+ L5 extends string = never>(
21
+ api: HttpApi,
22
+ apiOptions: ClientApiOptions,
23
+ utilities: Utilities<V, S, L1, L2, L3, L4, L5>
24
+
25
+ ) => {
26
+
27
+ const allFacet = async (
28
+ facet: string,
29
+ params: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>> = {},
30
+ locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
31
+ ): Promise<V[]> => {
32
+ const requestOptions = Object.assign({}, apiOptions.getOptions, { isAuthenticated: apiOptions.writeAuthenticated, params });
33
+ logger.default('allFacet', { facet, locations, requestOptions });
34
+ utilities.verifyLocations(locations);
35
+
36
+ const loc: LocKeyArray<L1, L2, L3, L4, L5> | [] = locations;
37
+
38
+ // TODO: This should respond to either a single object, or multiple objects in an array.
39
+ return api.httpGet<V[]>(
40
+ utilities.getPath(loc),
41
+ requestOptions,
42
+ )
43
+ };
44
+
45
+ return allFacet;
46
+ }
package/src/ops/create.ts CHANGED
@@ -1,50 +1,47 @@
1
1
  import {
2
2
  Item,
3
- ItemProperties,
4
3
  LocKeyArray
5
4
  } from "@fjell/core";
6
- import { HttpApi, PostMethodOptions } from "@fjell/http-api";
7
-
5
+ import { HttpApi } from "@fjell/http-api";
6
+
8
7
  import { ClientApiOptions } from "@/ClientApiOptions";
9
8
  import LibLogger from "@/logger";
10
9
  import { Utilities } from "@/Utilities";
11
-
10
+
12
11
  const logger = LibLogger.get('client-api', 'ops', 'create');
13
12
 
14
13
  export const getCreateOperation = <
15
- V extends Item<S, L1, L2, L3, L4, L5>,
16
- S extends string,
17
- L1 extends string = never,
18
- L2 extends string = never,
19
- L3 extends string = never,
20
- L4 extends string = never,
21
- L5 extends string = never>(
14
+ V extends Item<S, L1, L2, L3, L4, L5>,
15
+ S extends string,
16
+ L1 extends string = never,
17
+ L2 extends string = never,
18
+ L3 extends string = never,
19
+ L4 extends string = never,
20
+ L5 extends string = never>(
22
21
  api: HttpApi,
23
22
  apiOptions: ClientApiOptions,
24
23
  utilities: Utilities<V, S, L1, L2, L3, L4, L5>
25
-
24
+
26
25
  ) => {
27
-
26
+
28
27
  const create = async (
29
- item: ItemProperties<S, L1, L2, L3, L4, L5>,
30
- options: Partial<PostMethodOptions> = {},
28
+ item: Partial<Item<S, L1, L2, L3, L4, L5>>,
31
29
  locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
32
30
  ): Promise<V> => {
33
- logger.default('create', { item, locations });
31
+ const requestOptions = Object.assign({}, apiOptions.postOptions, { isAuthenticated: apiOptions.writeAuthenticated });
32
+ logger.default('create', { item, locations, requestOptions });
34
33
  utilities.verifyLocations(locations);
35
-
34
+
36
35
  const loc: LocKeyArray<L1, L2, L3, L4, L5> | [] = locations;
37
- const requestOptions = Object.assign({}, options, { isAuthenticated: apiOptions.writeAuthenticated });
38
-
36
+
39
37
  const created: V =
40
- utilities.validatePK(await utilities.processOne(api.httpPost<V>(
41
- utilities.getPath(loc),
42
- item,
43
- requestOptions,
44
- ))) as V;
38
+ utilities.validatePK(await utilities.processOne(api.httpPost<V>(
39
+ utilities.getPath(loc),
40
+ item,
41
+ requestOptions,
42
+ ))) as V;
45
43
  return created;
46
44
  };
47
45
 
48
46
  return create;
49
47
  }
50
-
package/src/ops/facet.ts CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  Item,
4
4
  PriKey,
5
5
  } from "@fjell/core";
6
- import { GetMethodOptions, HttpApi } from "@fjell/http-api";
6
+ import { HttpApi } from "@fjell/http-api";
7
7
 
8
8
  import { ClientApiOptions } from "@/ClientApiOptions";
9
9
  import LibLogger from "@/logger";
@@ -42,11 +42,10 @@ export const getFacetOperation = <
42
42
  const facet = async (
43
43
  ik: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>,
44
44
  facet: string,
45
- options: Partial<GetMethodOptions> = {}
45
+ params: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>> = {},
46
46
  ): Promise<any> => {
47
- logger.default('facet', { ik, facet });
48
-
49
- const requestOptions = Object.assign({}, options, { isAuthenticated: apiOptions.writeAuthenticated });
47
+ const requestOptions = Object.assign({}, apiOptions.getOptions, { isAuthenticated: apiOptions.writeAuthenticated, params });
48
+ logger.default('facet', { ik, facet, requestOptions });
50
49
 
51
50
  return api.httpGet<any>(
52
51
  `${utilities.getPath(ik)}/${facet}`,
package/src/ops/find.ts CHANGED
@@ -3,50 +3,47 @@ import {
3
3
  LocKeyArray,
4
4
  QueryParams
5
5
  } from "@fjell/core";
6
- import { GetMethodOptions, HttpApi } from "@fjell/http-api";
7
-
6
+ import { HttpApi } from "@fjell/http-api";
7
+
8
8
  import { finderToParams } from "@/AItemAPI";
9
9
  import { ClientApiOptions } from "@/ClientApiOptions";
10
10
  import LibLogger from "@/logger";
11
11
  import { Utilities } from "@/Utilities";
12
-
12
+
13
13
  const logger = LibLogger.get('client-api', 'ops', 'find');
14
-
14
+
15
15
  export const getFindOperation = <
16
- V extends Item<S, L1, L2, L3, L4, L5>,
17
- S extends string,
18
- L1 extends string = never,
19
- L2 extends string = never,
20
- L3 extends string = never,
21
- L4 extends string = never,
22
- L5 extends string = never>(
16
+ V extends Item<S, L1, L2, L3, L4, L5>,
17
+ S extends string,
18
+ L1 extends string = never,
19
+ L2 extends string = never,
20
+ L3 extends string = never,
21
+ L4 extends string = never,
22
+ L5 extends string = never>(
23
23
  api: HttpApi,
24
24
  apiOptions: ClientApiOptions,
25
25
  utilities: Utilities<V, S, L1, L2, L3, L4, L5>
26
-
26
+
27
27
  ) => {
28
-
28
+
29
29
  const find = async (
30
30
  finder: string,
31
- finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,
32
- options: Partial<GetMethodOptions> = {},
31
+ finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>> = {},
33
32
  locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
34
33
  ): Promise<V[]> => {
35
- logger.default('find', { finder, finderParams, locations });
36
34
  utilities.verifyLocations(locations);
37
35
  const loc: LocKeyArray<L1, L2, L3, L4, L5> | [] = locations;
38
-
39
- const params: QueryParams = finderToParams(finder, finderParams);
40
-
41
- const requestOptions = Object.assign({}, options, { isAuthenticated: apiOptions.allAuthenticated, params });
42
-
36
+
37
+ const mergedParams: QueryParams = finderToParams(finder, finderParams);
38
+ const requestOptions = Object.assign({}, apiOptions.getOptions, { isAuthenticated: apiOptions.allAuthenticated, params: mergedParams });
39
+ logger.default('find', { finder, finderParams, locations, requestOptions });
40
+
43
41
  return utilities.validatePK(await utilities.processArray(
44
42
  api.httpGet<V[]>(
45
43
  utilities.getPath(loc),
46
44
  requestOptions,
47
45
  ))) as V[];
48
46
  }
49
-
47
+
50
48
  return find;
51
49
  }
52
-
@@ -3,7 +3,7 @@ import {
3
3
  LocKeyArray,
4
4
  QueryParams
5
5
  } from "@fjell/core";
6
- import { GetMethodOptions, HttpApi } from "@fjell/http-api";
6
+ import { HttpApi } from "@fjell/http-api";
7
7
 
8
8
  import { finderToParams } from "@/AItemAPI";
9
9
  import { ClientApiOptions } from "@/ClientApiOptions";
@@ -28,18 +28,17 @@ export const getFindOneOperation = <
28
28
 
29
29
  const findOne = async (
30
30
  finder: string,
31
- finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,
32
- options: Partial<GetMethodOptions> = {},
31
+ finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>> = {},
33
32
  locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
34
33
  ): Promise<V> => {
35
- logger.default('findOne', { finder, finderParams, locations });
36
34
  utilities.verifyLocations(locations);
37
35
  const loc: LocKeyArray<L1, L2, L3, L4, L5> | [] = locations;
38
36
 
39
37
  const params: QueryParams = finderToParams(finder, finderParams);
40
38
  params.one = true;
41
39
 
42
- const requestOptions = Object.assign({}, options, { isAuthenticated: apiOptions.allAuthenticated, params });
40
+ const requestOptions = Object.assign({}, apiOptions.getOptions, { isAuthenticated: apiOptions.allAuthenticated, params });
41
+ logger.default('findOne', { finder, finderParams, locations, requestOptions });
43
42
 
44
43
  return (utilities.validatePK(await utilities.processArray(
45
44
  api.httpGet<V[]>(
package/src/ops/get.ts CHANGED
@@ -3,43 +3,40 @@ import {
3
3
  Item,
4
4
  PriKey,
5
5
  } from "@fjell/core";
6
- import { GetMethodOptions, HttpApi } from "@fjell/http-api";
7
-
6
+ import { HttpApi } from "@fjell/http-api";
7
+
8
8
  import { ClientApiOptions } from "@/ClientApiOptions";
9
9
  import LibLogger from "@/logger";
10
10
  import { Utilities } from "@/Utilities";
11
-
11
+
12
12
  const logger = LibLogger.get('client-api', 'ops', 'get');
13
-
13
+
14
14
  export const getGetOperation = <
15
- V extends Item<S, L1, L2, L3, L4, L5>,
16
- S extends string,
17
- L1 extends string = never,
18
- L2 extends string = never,
19
- L3 extends string = never,
20
- L4 extends string = never,
21
- L5 extends string = never>(
15
+ V extends Item<S, L1, L2, L3, L4, L5>,
16
+ S extends string,
17
+ L1 extends string = never,
18
+ L2 extends string = never,
19
+ L3 extends string = never,
20
+ L4 extends string = never,
21
+ L5 extends string = never>(
22
22
  api: HttpApi,
23
23
  apiOptions: ClientApiOptions,
24
24
  utilities: Utilities<V, S, L1, L2, L3, L4, L5>
25
-
25
+
26
26
  ) => {
27
-
27
+
28
28
  const get = async (
29
29
  ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
30
- options: Partial<GetMethodOptions> = {},
31
30
  ): Promise<V | null> => {
32
- logger.default('get', { ik });
33
-
34
- const requestOptions = Object.assign({}, options, { isAuthenticated: apiOptions.readAuthenticated });
35
-
31
+ const requestOptions = Object.assign({}, apiOptions.getOptions, { isAuthenticated: apiOptions.readAuthenticated });
32
+ logger.default('get', { ik, requestOptions });
33
+
36
34
  return utilities.validatePK(await utilities.processOne(
37
35
  api.httpGet<V>(
38
36
  utilities.getPath(ik),
39
37
  requestOptions,
40
38
  ))) as V;
41
39
  }
42
-
40
+
43
41
  return get;
44
42
  }
45
-
package/src/ops/index.ts CHANGED
@@ -15,6 +15,7 @@ import { ClientApiOptions } from "@/ClientApiOptions"
15
15
  import { ClientApi } from "@/ClientApi"
16
16
  import { getFindOneOperation } from "./findOne"
17
17
  import { getFacetOperation } from "./facet"
18
+ import { getAllFacetOperation } from "./allFacet"
18
19
 
19
20
  export const getOperations =
20
21
  <
@@ -46,6 +47,11 @@ export const getOperations =
46
47
  apiOptions,
47
48
  utilities,
48
49
  ),
50
+ allFacet: getAllFacetOperation<V, S, L1, L2, L3, L4, L5>(
51
+ api,
52
+ apiOptions,
53
+ utilities,
54
+ ),
49
55
  create: getCreateOperation<V, S, L1, L2, L3, L4, L5>(
50
56
  api,
51
57
  apiOptions,
package/src/ops/one.ts CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  QueryParams,
6
6
  queryToParams
7
7
  } from "@fjell/core";
8
- import { GetMethodOptions, HttpApi } from "@fjell/http-api";
8
+ import { HttpApi } from "@fjell/http-api";
9
9
 
10
10
  import { ClientApiOptions } from "@/ClientApiOptions";
11
11
  import LibLogger from "@/logger";
@@ -27,22 +27,20 @@ export const getOneOperation = <
27
27
 
28
28
  ): (
29
29
  query: ItemQuery,
30
- options?: Partial<GetMethodOptions>,
31
30
  locations?: LocKeyArray<L1, L2, L3, L4, L5> | []
32
31
  ) => Promise<V | null> => {
33
32
 
34
33
  const one = async (
35
34
  query: ItemQuery = {} as ItemQuery,
36
- options: Partial<GetMethodOptions> = {},
37
35
  locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
38
36
  ): Promise<V | null> => {
39
- logger.default('one', { query, locations });
40
37
  utilities.verifyLocations(locations);
41
38
 
42
39
  const loc: LocKeyArray<L1, L2, L3, L4, L5> | [] = locations;
43
40
 
44
41
  const params: QueryParams = queryToParams(query);
45
- const requestOptions = Object.assign({}, options, { isAuthenticated: apiOptions.readAuthenticated, params });
42
+ const requestOptions = Object.assign({}, apiOptions.getOptions, { isAuthenticated: apiOptions.readAuthenticated, params });
43
+ logger.default('one', { query, locations, requestOptions });
46
44
 
47
45
  let item: V | null = null;
48
46
 
package/src/ops/remove.ts CHANGED
@@ -3,39 +3,36 @@ import {
3
3
  Item,
4
4
  PriKey,
5
5
  } from "@fjell/core";
6
- import { DeleteMethodOptions, HttpApi } from "@fjell/http-api";
7
-
6
+ import { HttpApi } from "@fjell/http-api";
7
+
8
8
  import { ClientApiOptions } from "@/ClientApiOptions";
9
9
  import LibLogger from "@/logger";
10
10
  import { Utilities } from "@/Utilities";
11
-
11
+
12
12
  const logger = LibLogger.get('client-api', 'ops', 'remove');
13
-
13
+
14
14
  export const getRemoveOperation = <
15
- V extends Item<S, L1, L2, L3, L4, L5>,
16
- S extends string,
17
- L1 extends string = never,
18
- L2 extends string = never,
19
- L3 extends string = never,
20
- L4 extends string = never,
21
- L5 extends string = never>(
15
+ V extends Item<S, L1, L2, L3, L4, L5>,
16
+ S extends string,
17
+ L1 extends string = never,
18
+ L2 extends string = never,
19
+ L3 extends string = never,
20
+ L4 extends string = never,
21
+ L5 extends string = never>(
22
22
  api: HttpApi,
23
23
  apiOptions: ClientApiOptions,
24
24
  utilities: Utilities<V, S, L1, L2, L3, L4, L5>
25
-
25
+
26
26
  ) => {
27
-
27
+
28
28
  const remove = async (
29
29
  ik: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>,
30
- options: Partial<DeleteMethodOptions> = {},
31
30
  ): Promise<boolean> => {
32
- logger.default('remove', { ik });
33
-
34
- const requestOptions = Object.assign({}, options, { isAuthenticated: apiOptions.writeAuthenticated });
35
-
31
+ const requestOptions = Object.assign({}, apiOptions.deleteOptions, { isAuthenticated: apiOptions.writeAuthenticated });
32
+ logger.default('remove', { ik, requestOptions });
33
+
36
34
  return api.httpDelete<boolean>(utilities.getPath(ik), requestOptions);
37
35
  }
38
-
36
+
39
37
  return remove;
40
38
  }
41
-
package/src/ops/update.ts CHANGED
@@ -1,39 +1,37 @@
1
1
  import {
2
2
  ComKey,
3
3
  Item,
4
- ItemProperties,
5
4
  PriKey
6
5
  } from "@fjell/core";
7
- import { HttpApi, PutMethodOptions } from "@fjell/http-api";
8
-
6
+ import { HttpApi } from "@fjell/http-api";
7
+
9
8
  import { ClientApiOptions } from "@/ClientApiOptions";
10
9
  import LibLogger from "@/logger";
11
10
  import { Utilities } from "@/Utilities";
12
-
11
+
13
12
  const logger = LibLogger.get('client-api', 'ops', 'update');
14
-
13
+
15
14
  export const getUpdateOperation = <
16
- V extends Item<S, L1, L2, L3, L4, L5>,
17
- S extends string,
18
- L1 extends string = never,
19
- L2 extends string = never,
20
- L3 extends string = never,
21
- L4 extends string = never,
22
- L5 extends string = never>(
15
+ V extends Item<S, L1, L2, L3, L4, L5>,
16
+ S extends string,
17
+ L1 extends string = never,
18
+ L2 extends string = never,
19
+ L3 extends string = never,
20
+ L4 extends string = never,
21
+ L5 extends string = never>(
23
22
  api: HttpApi,
24
23
  apiOptions: ClientApiOptions,
25
24
  utilities: Utilities<V, S, L1, L2, L3, L4, L5>
26
-
25
+
27
26
  ) => {
28
-
27
+
29
28
  const update = async (
30
29
  ik: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>,
31
- item: ItemProperties<S, L1, L2, L3, L4, L5>,
32
- options: Partial<PutMethodOptions> = {},
30
+ item: Partial<Item<S, L1, L2, L3, L4, L5>>,
33
31
  ): Promise<V> => {
34
- logger.default('update', { ik, item });
35
- const requestOptions = Object.assign({}, options, { isAuthenticated: apiOptions.writeAuthenticated });
36
-
32
+ const requestOptions = Object.assign({}, apiOptions.putOptions, { isAuthenticated: apiOptions.writeAuthenticated });
33
+ logger.default('update', { ik, item, requestOptions });
34
+
37
35
  return utilities.validatePK(await utilities.processOne(
38
36
  api.httpPut<V>(
39
37
  utilities.getPath(ik),
@@ -41,7 +39,6 @@ export const getUpdateOperation = <
41
39
  requestOptions,
42
40
  ))) as V;
43
41
  }
44
-
42
+
45
43
  return update;
46
44
  }
47
-
@@ -0,0 +1,65 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
+ /* eslint-disable no-undefined */
3
+ export const clean = (obj: any) => {
4
+ return Object.fromEntries(
5
+ Object.entries(obj).filter(([_, v]) => v !== undefined)
6
+ );
7
+ }
8
+
9
+ //Recursive implementation of jSON.stringify;
10
+ export const stringifyJSON = function (obj: any, visited: Set<any> = new Set()): string {
11
+ const arrOfKeyVals: string[] = [];
12
+ const arrVals: string[] = [];
13
+ let objKeys: string[] = [];
14
+
15
+ /*********CHECK FOR PRIMITIVE TYPES**********/
16
+ if (typeof obj === 'number' || typeof obj === 'boolean' || obj === null)
17
+ return '' + obj;
18
+ else if (typeof obj === 'string')
19
+ return '"' + obj + '"';
20
+
21
+ /*********DETECT CIRCULAR REFERENCES**********/
22
+ if (obj instanceof Object && visited.has(obj)) {
23
+ return '"(circular)"';
24
+ }
25
+
26
+ /*********CHECK FOR ARRAY**********/
27
+ else if (Array.isArray(obj)) {
28
+ //check for empty array
29
+ if (obj[0] === undefined)
30
+ return '[]';
31
+ else {
32
+ // Add array to visited before processing its elements
33
+ visited.add(obj);
34
+ obj.forEach(function (el) {
35
+ arrVals.push(stringifyJSON(el, visited));
36
+ });
37
+ return '[' + arrVals + ']';
38
+ }
39
+ }
40
+ /*********CHECK FOR OBJECT**********/
41
+ else if (obj instanceof Object) {
42
+ // Add object to visited before processing its properties
43
+ visited.add(obj);
44
+ //get object keys
45
+ objKeys = Object.keys(obj);
46
+ //set key output;
47
+ objKeys.forEach(function (key) {
48
+ const keyOut = '"' + key + '":';
49
+ const keyValOut = obj[key];
50
+ //skip functions and undefined properties
51
+ if (keyValOut instanceof Function || keyValOut === undefined)
52
+ return; // Skip this entry entirely instead of pushing an empty string
53
+ else if (typeof keyValOut === 'string')
54
+ arrOfKeyVals.push(keyOut + '"' + keyValOut + '"');
55
+ else if (typeof keyValOut === 'boolean' || typeof keyValOut === 'number' || keyValOut === null)
56
+ arrOfKeyVals.push(keyOut + keyValOut);
57
+ //check for nested objects, call recursively until no more objects
58
+ else if (keyValOut instanceof Object) {
59
+ arrOfKeyVals.push(keyOut + stringifyJSON(keyValOut, visited));
60
+ }
61
+ });
62
+ return '{' + arrOfKeyVals + '}';
63
+ }
64
+ return '';
65
+ };