Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS: Fix browser build #66

Merged
merged 2 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ module.exports = {
[
"@babel/preset-env",
{
targets: {
node: "current"
}
useBuiltIns: "entry",
corejs: "3.22"
}
]
]
Expand Down
61 changes: 31 additions & 30 deletions dist/alchemy-json_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau

var structuredClone__default = /*#__PURE__*/_interopDefaultLegacy(structuredClone);

function deserialize(originalResponse, options = {}) {
const response = structuredClone__default["default"](originalResponse);
function deserialize(originalResponse) {
var response = structuredClone__default["default"](originalResponse);

if (!options) {
options = {};
}

const included = response.included || [];
var included = response.included || [];

if (Array.isArray(response.data)) {
return response.data.map(data => {
return response.data.map(function (data) {
return parseJsonApiSimpleResourceData(data, included, false);
});
} else {
Expand All @@ -39,22 +35,25 @@ function parseJsonApiSimpleResourceData(data, included, useCache, options) {
return included.cached[data.type][data.id];
}

const attributes = data.attributes || {};
const resource = attributes;
var attributes = data.attributes || {};
var resource = attributes;
resource.id = data.id;
included.cached[data.type][data.id] = resource;

if (data.relationships) {
for (const relationName of Object.keys(data.relationships)) {
const relationRef = data.relationships[relationName];
for (var _i = 0, _Object$keys = Object.keys(data.relationships); _i < _Object$keys.length; _i++) {
var relationName = _Object$keys[_i];
var relationRef = data.relationships[relationName];

if (Array.isArray(relationRef.data)) {
const items = [];
relationRef.data.forEach(relationData => {
const item = findJsonApiIncluded(included, relationData.type, relationData.id);
items.push(item);
});
resource[relationName] = items;
(function () {
var items = [];
relationRef.data.forEach(function (relationData) {
var item = findJsonApiIncluded(included, relationData.type, relationData.id);
items.push(item);
});
resource[relationName] = items;
})();
} else if (relationRef && relationRef.data) {
resource[relationName] = findJsonApiIncluded(included, relationRef.data.type, relationRef.data.id);
} else {
Expand All @@ -67,35 +66,37 @@ function parseJsonApiSimpleResourceData(data, included, useCache, options) {
}

function findJsonApiIncluded(included, type, id, options) {
let found = null;
included.forEach(item => {
var found = null;
included.forEach(function (item) {
if (item.type === type && item.id === id) {
found = parseJsonApiSimpleResourceData(item, included, true);
}
});

if (!found) {
found = {
id
id: id
};
}

return found;
}

function filterDeprecatedElements(elements) {
const els = [];
elements.forEach(element => {
if (element.nested_elements?.length > 0) {
var els = [];
elements.forEach(function (element) {
var _element$nested_eleme, _element$nestedElemen, _element$essences;

if (((_element$nested_eleme = element.nested_elements) === null || _element$nested_eleme === void 0 ? void 0 : _element$nested_eleme.length) > 0) {
element.nested_elements = filterDeprecatedElements(element.nested_elements);
}

if (element.nestedElements?.length > 0) {
if (((_element$nestedElemen = element.nestedElements) === null || _element$nestedElemen === void 0 ? void 0 : _element$nestedElemen.length) > 0) {
element.nestedElements = filterDeprecatedElements(element.nestedElements);
}

if (element.essences?.length > 0) {
element.essences = element.essences.filter(essence => {
if (((_element$essences = element.essences) === null || _element$essences === void 0 ? void 0 : _element$essences.length) > 0) {
element.essences = element.essences.filter(function (essence) {
return !essence.deprecated;
});
}
Expand All @@ -109,14 +110,14 @@ function filterDeprecatedElements(elements) {


function deserializePage(pageData) {
const page = deserialize(pageData);
var page = deserialize(pageData);
page.elements = filterDeprecatedElements(page.elements);
return page;
} // Returns deserialized pages without deprecated content

function deserializePages(pagesData) {
const pages = deserialize(pagesData);
pages.forEach(page => {
var pages = deserialize(pagesData);
pages.forEach(function (page) {
page.elements = filterDeprecatedElements(page.elements);
});
return pages;
Expand Down
41 changes: 20 additions & 21 deletions dist/deserialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau

var structuredClone__default = /*#__PURE__*/_interopDefaultLegacy(structuredClone);

function deserialize(originalResponse, options = {}) {
const response = structuredClone__default["default"](originalResponse);
function deserialize(originalResponse) {
var response = structuredClone__default["default"](originalResponse);

if (!options) {
options = {};
}

const included = response.included || [];
var included = response.included || [];

if (Array.isArray(response.data)) {
return response.data.map(data => {
return response.data.map(function (data) {
return parseJsonApiSimpleResourceData(data, included, false);
});
} else {
Expand All @@ -39,22 +35,25 @@ function parseJsonApiSimpleResourceData(data, included, useCache, options) {
return included.cached[data.type][data.id];
}

const attributes = data.attributes || {};
const resource = attributes;
var attributes = data.attributes || {};
var resource = attributes;
resource.id = data.id;
included.cached[data.type][data.id] = resource;

if (data.relationships) {
for (const relationName of Object.keys(data.relationships)) {
const relationRef = data.relationships[relationName];
for (var _i = 0, _Object$keys = Object.keys(data.relationships); _i < _Object$keys.length; _i++) {
var relationName = _Object$keys[_i];
var relationRef = data.relationships[relationName];

if (Array.isArray(relationRef.data)) {
const items = [];
relationRef.data.forEach(relationData => {
const item = findJsonApiIncluded(included, relationData.type, relationData.id);
items.push(item);
});
resource[relationName] = items;
(function () {
var items = [];
relationRef.data.forEach(function (relationData) {
var item = findJsonApiIncluded(included, relationData.type, relationData.id);
items.push(item);
});
resource[relationName] = items;
})();
} else if (relationRef && relationRef.data) {
resource[relationName] = findJsonApiIncluded(included, relationRef.data.type, relationRef.data.id);
} else {
Expand All @@ -67,16 +66,16 @@ function parseJsonApiSimpleResourceData(data, included, useCache, options) {
}

function findJsonApiIncluded(included, type, id, options) {
let found = null;
included.forEach(item => {
var found = null;
included.forEach(function (item) {
if (item.type === type && item.id === id) {
found = parseJsonApiSimpleResourceData(item, included, true);
}
});

if (!found) {
found = {
id
id: id
};
}

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@
"scripts": {
"build": "rollup --config",
"test": "jest"
}
},
"browserslist": "> 0.25%, not dead"
}