@teleporthq/teleport-plugin-common
Advanced tools
Comparing version 0.38.11 to 0.38.12
@@ -46,3 +46,3 @@ import * as types from '@babel/types'; | ||
export declare const wrapObjectPropertiesWithExpression: (properties: types.ObjectProperty[]) => types.ObjectExpression; | ||
export declare const generateRemoteResourceASTs: (resource: UIDLResourceItem) => types.VariableDeclaration[]; | ||
export declare const generateRemoteResourceASTs: (resource: UIDLResourceItem) => (types.IfStatement | types.VariableDeclaration)[]; | ||
export declare const generateMemberExpressionASTFromBase: (base: types.OptionalMemberExpression | types.MemberExpression | types.Identifier, path: string[]) => types.OptionalMemberExpression; | ||
@@ -49,0 +49,0 @@ export declare const generateMemberExpressionASTFromPath: (path: Array<string | number>) => types.OptionalMemberExpression | types.Identifier; |
@@ -434,3 +434,3 @@ "use strict"; | ||
var generateRemoteResourceASTs = function (resource) { | ||
var _a, _b, _c; | ||
var _a, _b, _c, _d; | ||
var fetchUrl = (0, exports.computeFetchUrl)(resource); | ||
@@ -461,3 +461,3 @@ var headersASTs = (resource === null || resource === void 0 ? void 0 : resource.headers) ? generateRESTHeadersAST(resource.headers) : []; | ||
} | ||
var fetchAST = types.variableDeclaration('const', [ | ||
var fetchAST = types.variableDeclaration('let', [ | ||
types.variableDeclarator(types.identifier('data'), types.awaitExpression(types.callExpression(types.identifier('fetch'), [ | ||
@@ -478,3 +478,27 @@ url, | ||
]); | ||
var responseType = (_c = (_b = resource === null || resource === void 0 ? void 0 : resource.response) === null || _b === void 0 ? void 0 : _b.type) !== null && _c !== void 0 ? _c : 'json'; | ||
// Fallback in case i18n interferes with normal CMS flows | ||
var fallbackParams = JSON.parse(JSON.stringify(resource)); | ||
(_b = fallbackParams === null || fallbackParams === void 0 ? void 0 : fallbackParams.params) === null || _b === void 0 ? true : delete _b.locale; | ||
var fallbackUrlParamsDeclaration = generateParamsAST(fallbackParams === null || fallbackParams === void 0 ? void 0 : fallbackParams.params); | ||
var assignmentOfNewUrlParams = types.expressionStatement(types.assignmentExpression('=', types.identifier('urlParams'), types.objectExpression(__spreadArray([], fallbackUrlParamsDeclaration, true)))); | ||
var assignmentExpressionAST = types.expressionStatement(types.assignmentExpression('=', types.identifier('data'), types.awaitExpression(types.callExpression(types.identifier('fetch'), [ | ||
url, | ||
types.objectExpression(__spreadArray(__spreadArray([ | ||
method | ||
], (allHeaders.length > 0 | ||
? [ | ||
types.objectProperty(types.identifier('headers'), types.objectExpression(allHeaders)), | ||
] | ||
: []), true), (bodyParamsDecleration.length > 0 && (resource === null || resource === void 0 ? void 0 : resource.method) === 'POST' | ||
? [ | ||
types.objectProperty(types.identifier('body'), types.callExpression(types.memberExpression(types.identifier('JSON'), types.identifier('stringify')), [types.identifier('bodyParams')])), | ||
] | ||
: []), true)), | ||
])))); | ||
var fallbackAST = types.ifStatement(types.binaryExpression('!==', // The operator !== | ||
types.memberExpression(types.identifier('data'), // Access data | ||
types.identifier('status') // Access data.status | ||
), types.numericLiteral(200) // Check if it is not equal to 200 | ||
), types.blockStatement([assignmentOfNewUrlParams, assignmentExpressionAST])); | ||
var responseType = (_d = (_c = resource === null || resource === void 0 ? void 0 : resource.response) === null || _c === void 0 ? void 0 : _c.type) !== null && _d !== void 0 ? _d : 'json'; | ||
var responseJSONAST; | ||
@@ -521,3 +545,3 @@ /** | ||
? [ | ||
types.variableDeclaration('const', [ | ||
types.variableDeclaration('let', [ | ||
types.variableDeclarator(types.identifier('urlParams'), types.objectExpression(urlParamsDecleration)), | ||
@@ -534,2 +558,3 @@ ]), | ||
fetchAST, | ||
fallbackAST, | ||
responseJSONAST, | ||
@@ -536,0 +561,0 @@ ], false); |
@@ -46,3 +46,3 @@ import * as types from '@babel/types'; | ||
export declare const wrapObjectPropertiesWithExpression: (properties: types.ObjectProperty[]) => types.ObjectExpression; | ||
export declare const generateRemoteResourceASTs: (resource: UIDLResourceItem) => types.VariableDeclaration[]; | ||
export declare const generateRemoteResourceASTs: (resource: UIDLResourceItem) => (types.IfStatement | types.VariableDeclaration)[]; | ||
export declare const generateMemberExpressionASTFromBase: (base: types.OptionalMemberExpression | types.MemberExpression | types.Identifier, path: string[]) => types.OptionalMemberExpression; | ||
@@ -49,0 +49,0 @@ export declare const generateMemberExpressionASTFromPath: (path: Array<string | number>) => types.OptionalMemberExpression | types.Identifier; |
@@ -382,3 +382,3 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
export var generateRemoteResourceASTs = function (resource) { | ||
var _a, _b, _c; | ||
var _a, _b, _c, _d; | ||
var fetchUrl = computeFetchUrl(resource); | ||
@@ -409,3 +409,3 @@ var headersASTs = (resource === null || resource === void 0 ? void 0 : resource.headers) ? generateRESTHeadersAST(resource.headers) : []; | ||
} | ||
var fetchAST = types.variableDeclaration('const', [ | ||
var fetchAST = types.variableDeclaration('let', [ | ||
types.variableDeclarator(types.identifier('data'), types.awaitExpression(types.callExpression(types.identifier('fetch'), [ | ||
@@ -426,3 +426,27 @@ url, | ||
]); | ||
var responseType = (_c = (_b = resource === null || resource === void 0 ? void 0 : resource.response) === null || _b === void 0 ? void 0 : _b.type) !== null && _c !== void 0 ? _c : 'json'; | ||
// Fallback in case i18n interferes with normal CMS flows | ||
var fallbackParams = JSON.parse(JSON.stringify(resource)); | ||
(_b = fallbackParams === null || fallbackParams === void 0 ? void 0 : fallbackParams.params) === null || _b === void 0 ? true : delete _b.locale; | ||
var fallbackUrlParamsDeclaration = generateParamsAST(fallbackParams === null || fallbackParams === void 0 ? void 0 : fallbackParams.params); | ||
var assignmentOfNewUrlParams = types.expressionStatement(types.assignmentExpression('=', types.identifier('urlParams'), types.objectExpression(__spreadArray([], fallbackUrlParamsDeclaration, true)))); | ||
var assignmentExpressionAST = types.expressionStatement(types.assignmentExpression('=', types.identifier('data'), types.awaitExpression(types.callExpression(types.identifier('fetch'), [ | ||
url, | ||
types.objectExpression(__spreadArray(__spreadArray([ | ||
method | ||
], (allHeaders.length > 0 | ||
? [ | ||
types.objectProperty(types.identifier('headers'), types.objectExpression(allHeaders)), | ||
] | ||
: []), true), (bodyParamsDecleration.length > 0 && (resource === null || resource === void 0 ? void 0 : resource.method) === 'POST' | ||
? [ | ||
types.objectProperty(types.identifier('body'), types.callExpression(types.memberExpression(types.identifier('JSON'), types.identifier('stringify')), [types.identifier('bodyParams')])), | ||
] | ||
: []), true)), | ||
])))); | ||
var fallbackAST = types.ifStatement(types.binaryExpression('!==', // The operator !== | ||
types.memberExpression(types.identifier('data'), // Access data | ||
types.identifier('status') // Access data.status | ||
), types.numericLiteral(200) // Check if it is not equal to 200 | ||
), types.blockStatement([assignmentOfNewUrlParams, assignmentExpressionAST])); | ||
var responseType = (_d = (_c = resource === null || resource === void 0 ? void 0 : resource.response) === null || _c === void 0 ? void 0 : _c.type) !== null && _d !== void 0 ? _d : 'json'; | ||
var responseJSONAST; | ||
@@ -469,3 +493,3 @@ /** | ||
? [ | ||
types.variableDeclaration('const', [ | ||
types.variableDeclaration('let', [ | ||
types.variableDeclarator(types.identifier('urlParams'), types.objectExpression(urlParamsDecleration)), | ||
@@ -482,2 +506,3 @@ ]), | ||
fetchAST, | ||
fallbackAST, | ||
responseJSONAST, | ||
@@ -484,0 +509,0 @@ ], false); |
{ | ||
"name": "@teleporthq/teleport-plugin-common", | ||
"version": "0.38.11", | ||
"version": "0.38.12", | ||
"description": "Common building and modelating functions for ASTs and HASTs", | ||
@@ -30,8 +30,8 @@ "author": "teleportHQ", | ||
"@babel/types": "^7.5.5", | ||
"@teleporthq/teleport-shared": "^0.38.10", | ||
"@teleporthq/teleport-types": "^0.38.3", | ||
"@teleporthq/teleport-shared": "^0.38.12", | ||
"@teleporthq/teleport-types": "^0.38.12", | ||
"jss": "^10.0.0", | ||
"jss-preset-default": "^10.0.0" | ||
}, | ||
"gitHead": "0456f0804e1c3521487b58ee39fb4460709359f5" | ||
"gitHead": "07b065d0821d18af43eaecced31d6be110d0b316" | ||
} |
@@ -616,3 +616,3 @@ import * as types from '@babel/types' | ||
const fetchAST = types.variableDeclaration('const', [ | ||
const fetchAST = types.variableDeclaration('let', [ | ||
types.variableDeclarator( | ||
@@ -653,2 +653,62 @@ types.identifier('data'), | ||
// Fallback in case i18n interferes with normal CMS flows | ||
const fallbackParams = JSON.parse(JSON.stringify(resource)) | ||
delete fallbackParams?.params?.locale | ||
const fallbackUrlParamsDeclaration = generateParamsAST(fallbackParams?.params) | ||
const assignmentOfNewUrlParams = types.expressionStatement( | ||
types.assignmentExpression( | ||
'=', | ||
types.identifier('urlParams'), | ||
types.objectExpression([...fallbackUrlParamsDeclaration]) | ||
) | ||
) | ||
const assignmentExpressionAST = types.expressionStatement( | ||
types.assignmentExpression( | ||
'=', | ||
types.identifier('data'), | ||
types.awaitExpression( | ||
types.callExpression(types.identifier('fetch'), [ | ||
url, | ||
types.objectExpression([ | ||
method, | ||
...(allHeaders.length > 0 | ||
? [ | ||
types.objectProperty( | ||
types.identifier('headers'), | ||
types.objectExpression(allHeaders) | ||
), | ||
] | ||
: []), | ||
...(bodyParamsDecleration.length > 0 && resource?.method === 'POST' | ||
? [ | ||
types.objectProperty( | ||
types.identifier('body'), | ||
types.callExpression( | ||
types.memberExpression( | ||
types.identifier('JSON'), | ||
types.identifier('stringify') | ||
), | ||
[types.identifier('bodyParams')] | ||
) | ||
), | ||
] | ||
: []), | ||
]), | ||
]) | ||
) | ||
) | ||
) | ||
const fallbackAST = types.ifStatement( | ||
types.binaryExpression( | ||
'!==', // The operator !== | ||
types.memberExpression( | ||
types.identifier('data'), // Access data | ||
types.identifier('status') // Access data.status | ||
), | ||
types.numericLiteral(200) // Check if it is not equal to 200 | ||
), | ||
types.blockStatement([assignmentOfNewUrlParams, assignmentExpressionAST]) | ||
) | ||
const responseType = resource?.response?.type ?? 'json' | ||
@@ -723,3 +783,3 @@ let responseJSONAST | ||
? [ | ||
types.variableDeclaration('const', [ | ||
types.variableDeclaration('let', [ | ||
types.variableDeclarator( | ||
@@ -743,2 +803,3 @@ types.identifier('urlParams'), | ||
fetchAST, | ||
fallbackAST, | ||
responseJSONAST, | ||
@@ -745,0 +806,0 @@ ] |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
688276
9142