@alchemy_cms/json_api 2.0.0 → 3.0.0

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/README.md CHANGED
@@ -13,11 +13,13 @@ gem 'alchemy-json_api'
13
13
  ```
14
14
 
15
15
  And then execute:
16
+
16
17
  ```bash
17
18
  $ bundle
18
19
  ```
19
20
 
20
21
  Or install it yourself as:
22
+
21
23
  ```bash
22
24
  $ gem install alchemy-json_api
23
25
  ```
@@ -27,9 +29,11 @@ $ gem install alchemy-json_api
27
29
  Run this in your application:
28
30
 
29
31
  ```
30
- yarn add "@alchemy_cms/json_api"
32
+ npm install @alchemy_cms/json_api --save
31
33
  ```
32
34
 
35
+ or with the package manager of your choice
36
+
33
37
  ## Usage
34
38
 
35
39
  ### In your Rails app
@@ -68,7 +72,9 @@ Alchemy::JsonApi.key_transform = :camel_lower
68
72
  It defaults to `:underscore`.
69
73
 
70
74
  ## Contributing
75
+
71
76
  Contribution directions go here.
72
77
 
73
78
  ## License
79
+
74
80
  The gem is available as open source under the terms of the [BSD-3-Clause license](https://opensource.org/licenses/BSD-3-Clause).
@@ -1,132 +1,25 @@
1
- import structuredClone from '@ungap/structured-clone';
2
-
3
- function deserialize(originalResponse, options = {}) {
4
- const response = structuredClone(originalResponse);
5
- if (!options) {
6
- options = {};
7
- }
8
-
9
- const included = response.included || [];
10
-
11
- if (Array.isArray(response.data)) {
12
- return response.data.map((data) => {
13
- return parseJsonApiSimpleResourceData(data, included, false)
14
- })
15
- } else {
16
- return parseJsonApiSimpleResourceData(
17
- response.data,
18
- included,
19
- false)
20
- }
1
+ import { deserialize as d } from "./deserialize.js";
2
+ function n(t) {
3
+ const s = [];
4
+ return t.forEach((e) => {
5
+ var r, i, c;
6
+ ((r = e.nested_elements) == null ? void 0 : r.length) > 0 && (e.nested_elements = n(
7
+ e.nested_elements
8
+ )), ((i = e.nestedElements) == null ? void 0 : i.length) > 0 && (e.nestedElements = n(e.nestedElements)), ((c = e.essences) == null ? void 0 : c.length) > 0 && (e.essences = e.essences.filter((f) => !f.deprecated)), e.deprecated || s.push(e);
9
+ }), s;
21
10
  }
22
-
23
- function parseJsonApiSimpleResourceData(data, included, useCache, options) {
24
- if (!included.cached) {
25
- included.cached = {};
26
- }
27
-
28
- if (!(data.type in included.cached)) {
29
- included.cached[data.type] = {};
30
- }
31
-
32
- if (useCache && data.id in included.cached[data.type]) {
33
- return included.cached[data.type][data.id]
34
- }
35
-
36
- const attributes = data.attributes || {};
37
-
38
- const resource = attributes;
39
- resource.id = data.id;
40
-
41
- included.cached[data.type][data.id] = resource;
42
-
43
- if (data.relationships) {
44
- for (const relationName of Object.keys(data.relationships)) {
45
- const relationRef = data.relationships[relationName];
46
-
47
- if (Array.isArray(relationRef.data)) {
48
- const items = [];
49
-
50
- relationRef.data.forEach((relationData) => {
51
- const item = findJsonApiIncluded(
52
- included,
53
- relationData.type,
54
- relationData.id);
55
-
56
- items.push(item);
57
- });
58
-
59
- resource[relationName] = items;
60
- } else if (relationRef && relationRef.data) {
61
- resource[relationName] = findJsonApiIncluded(
62
- included,
63
- relationRef.data.type,
64
- relationRef.data.id);
65
- } else {
66
- resource[relationName] = null;
67
- }
68
- }
69
- }
70
-
71
- return resource
11
+ function o(t) {
12
+ const s = d(t);
13
+ return s.elements = n(s.elements), s;
72
14
  }
73
-
74
- function findJsonApiIncluded(included, type, id, options) {
75
- let found = null;
76
-
77
- included.forEach((item) => {
78
- if (item.type === type && item.id === id) {
79
- found = parseJsonApiSimpleResourceData(item, included, true);
80
- }
81
- });
82
-
83
- if (!found) {
84
- found = { id };
85
- }
86
-
87
- return found
15
+ function l(t) {
16
+ const s = d(t);
17
+ return s.forEach((e) => {
18
+ e.elements = n(e.elements);
19
+ }), s;
88
20
  }
89
-
90
- // Recursively filters all deprecated elements and essences from collection
91
- function filterDeprecatedElements(elements) {
92
- const els = [];
93
-
94
- elements.forEach((element) => {
95
- if (element.nested_elements?.length > 0) {
96
- element.nested_elements = filterDeprecatedElements(
97
- element.nested_elements
98
- );
99
- }
100
- if (element.nestedElements?.length > 0) {
101
- element.nestedElements = filterDeprecatedElements(element.nestedElements);
102
- }
103
- if (element.essences?.length > 0) {
104
- element.essences = element.essences.filter((essence) => {
105
- return !essence.deprecated
106
- });
107
- }
108
- if (!element.deprecated) {
109
- els.push(element);
110
- }
111
- });
112
-
113
- return els
114
- }
115
-
116
- // Returns deserialized page without deprecated content
117
- function deserializePage(pageData) {
118
- const page = deserialize(pageData);
119
- page.elements = filterDeprecatedElements(page.elements);
120
- return page
121
- }
122
-
123
- // Returns deserialized pages without deprecated content
124
- function deserializePages(pagesData) {
125
- const pages = deserialize(pagesData);
126
- pages.forEach((page) => {
127
- page.elements = filterDeprecatedElements(page.elements);
128
- });
129
- return pages
130
- }
131
-
132
- export { deserialize, deserializePage, deserializePages };
21
+ export {
22
+ d as deserialize,
23
+ o as deserializePage,
24
+ l as deserializePages
25
+ };
@@ -1,90 +1,45 @@
1
- import structuredClone from '@ungap/structured-clone';
2
-
3
- function deserialize(originalResponse, options = {}) {
4
- const response = structuredClone(originalResponse);
5
- if (!options) {
6
- options = {};
7
- }
8
-
9
- const included = response.included || [];
10
-
11
- if (Array.isArray(response.data)) {
12
- return response.data.map((data) => {
13
- return parseJsonApiSimpleResourceData(data, included, false)
14
- })
15
- } else {
16
- return parseJsonApiSimpleResourceData(
17
- response.data,
18
- included,
19
- false)
20
- }
1
+ import y from "@ungap/structured-clone";
2
+ function A(e, r = {}) {
3
+ const s = y(e);
4
+ r || (r = {});
5
+ const n = s.included || [];
6
+ return Array.isArray(s.data) ? s.data.map((i) => f(i, n, !1)) : f(
7
+ s.data,
8
+ n,
9
+ !1
10
+ );
21
11
  }
22
-
23
- function parseJsonApiSimpleResourceData(data, included, useCache, options) {
24
- if (!included.cached) {
25
- included.cached = {};
26
- }
27
-
28
- if (!(data.type in included.cached)) {
29
- included.cached[data.type] = {};
30
- }
31
-
32
- if (useCache && data.id in included.cached[data.type]) {
33
- return included.cached[data.type][data.id]
34
- }
35
-
36
- const attributes = data.attributes || {};
37
-
38
- const resource = attributes;
39
- resource.id = data.id;
40
-
41
- included.cached[data.type][data.id] = resource;
42
-
43
- if (data.relationships) {
44
- for (const relationName of Object.keys(data.relationships)) {
45
- const relationRef = data.relationships[relationName];
46
-
47
- if (Array.isArray(relationRef.data)) {
48
- const items = [];
49
-
50
- relationRef.data.forEach((relationData) => {
51
- const item = findJsonApiIncluded(
52
- included,
53
- relationData.type,
54
- relationData.id);
55
-
56
- items.push(item);
57
- });
58
-
59
- resource[relationName] = items;
60
- } else if (relationRef && relationRef.data) {
61
- resource[relationName] = findJsonApiIncluded(
62
- included,
63
- relationRef.data.type,
64
- relationRef.data.id);
65
- } else {
66
- resource[relationName] = null;
67
- }
12
+ function f(e, r, s, n) {
13
+ if (r.cached || (r.cached = {}), e.type in r.cached || (r.cached[e.type] = {}), s && e.id in r.cached[e.type])
14
+ return r.cached[e.type][e.id];
15
+ const t = e.attributes || {};
16
+ if (t.id = e.id, r.cached[e.type][e.id] = t, e.relationships)
17
+ for (const c of Object.keys(e.relationships)) {
18
+ const o = e.relationships[c];
19
+ if (Array.isArray(o.data)) {
20
+ const p = [];
21
+ o.data.forEach((a) => {
22
+ const h = u(
23
+ r,
24
+ a.type,
25
+ a.id
26
+ );
27
+ p.push(h);
28
+ }), t[c] = p;
29
+ } else o && o.data ? t[c] = u(
30
+ r,
31
+ o.data.type,
32
+ o.data.id
33
+ ) : t[c] = null;
68
34
  }
69
- }
70
-
71
- return resource
35
+ return t;
72
36
  }
73
-
74
- function findJsonApiIncluded(included, type, id, options) {
75
- let found = null;
76
-
77
- included.forEach((item) => {
78
- if (item.type === type && item.id === id) {
79
- found = parseJsonApiSimpleResourceData(item, included, true);
80
- }
81
- });
82
-
83
- if (!found) {
84
- found = { id };
85
- }
86
-
87
- return found
37
+ function u(e, r, s, n) {
38
+ let i = null;
39
+ return e.forEach((t) => {
40
+ t.type === r && t.id === s && (i = f(t, e, !0));
41
+ }), i || (i = { id: s }), i;
88
42
  }
89
-
90
- export { deserialize };
43
+ export {
44
+ A as deserialize
45
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alchemy_cms/json_api",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "description": "JSON API deserializer for AlchemyCMS",
5
5
  "license": "BSD-3-Clause",
6
6
  "repository": {
@@ -14,6 +14,7 @@
14
14
  "headless"
15
15
  ],
16
16
  "authors": [
17
+ "Lasse Diercks",
17
18
  "Martin Meyerhoff",
18
19
  "Thomas von Deyen"
19
20
  ],
@@ -26,18 +27,14 @@
26
27
  "@ungap/structured-clone": "^1.0.1"
27
28
  },
28
29
  "devDependencies": {
29
- "@babel/core": "^7.19.0",
30
- "@babel/preset-env": "^7.19.0",
31
- "@rollup/plugin-babel": "^6.0.4",
32
- "babel-jest": "^29.0.2",
33
- "jest": "^29.0.2",
34
30
  "prettier": "^3.3.3",
35
- "rollup": "^4.24.4"
31
+ "vite": "^6.3.5",
32
+ "vitest": "^3.2.4"
36
33
  },
37
34
  "scripts": {
38
- "build": "rollup --config",
35
+ "build": "vite build",
39
36
  "lint": "prettier --check 'src/**/*.js'",
40
- "test": "jest"
37
+ "test": "vitest"
41
38
  },
42
- "browserslist": "> 0.25%, not dead"
39
+ "packageManager": "pnpm@10.12.1"
43
40
  }