@plasmicapp/data-sources
Advanced tools
Comparing version 0.1.16 to 0.1.17
@@ -6,3 +6,2 @@ import { ComponentMeta } from '@plasmicapp/host'; | ||
name?: string; | ||
includeSchema?: boolean; | ||
pageIndex?: number; | ||
@@ -9,0 +8,0 @@ pageSize?: number; |
@@ -850,3 +850,2 @@ 'use strict'; | ||
userArgs: (_op$userArgs = op.userArgs) != null ? _op$userArgs : {}, | ||
includeSchema: opts == null ? void 0 : opts.includeSchema, | ||
paginate: opts == null ? void 0 : opts.paginate | ||
@@ -898,5 +897,30 @@ }) | ||
function swallow(f) { | ||
try { | ||
return f(); | ||
} catch (_unused) { | ||
return undefined; | ||
} | ||
} | ||
function pick(obj) { | ||
var res = {}; | ||
for (var _len = arguments.length, keys = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
keys[_key - 1] = arguments[_key]; | ||
} | ||
for (var _i = 0, _keys = keys; _i < _keys.length; _i++) { | ||
var key = _keys[_i]; | ||
if (key in obj) { | ||
res[key] = obj[key]; | ||
} | ||
} | ||
return res; | ||
} | ||
function usePlasmicDataOp(dataOp, opts) { | ||
var ctx = dataSourcesContext.usePlasmicDataSourceContext(); | ||
return query.useMutablePlasmicQueryData(function () { | ||
var res = query.useMutablePlasmicQueryData(function () { | ||
return dataOp ? dataOp.cacheKey ? dataOp.cacheKey : JSON.stringify({ | ||
@@ -907,3 +931,2 @@ sourceId: dataOp.sourceId, | ||
userAuthToken: ctx == null ? void 0 : ctx.userAuthToken, | ||
includeSchema: opts == null ? void 0 : opts.includeSchema, | ||
paginate: opts == null ? void 0 : opts.paginate | ||
@@ -919,3 +942,2 @@ }) : null; | ||
userAuthToken: ctx == null ? void 0 : ctx.userAuthToken, | ||
includeSchema: opts == null ? void 0 : opts.includeSchema, | ||
paginate: opts == null ? void 0 : opts.paginate | ||
@@ -934,2 +956,8 @@ }); | ||
}))); | ||
var data = res.data, | ||
error = res.error, | ||
isLoading = res.isLoading; | ||
return React.useMemo(function () { | ||
return _extends({}, data != null ? data : {}, pick(res, 'isLoading', 'error')); | ||
}, [data, error, isLoading]); | ||
} | ||
@@ -962,4 +990,3 @@ function usePlasmicDataMutationOp(dataOp, opts) { | ||
}, { | ||
userAuthToken: userToken, | ||
includeSchema: opts == null ? void 0 : opts.includeSchema | ||
userAuthToken: userToken | ||
})); | ||
@@ -977,3 +1004,3 @@ | ||
function Fetcher(props) { | ||
var _data$error, _children; | ||
var _children; | ||
@@ -983,9 +1010,5 @@ var dataOp = props.dataOp, | ||
name = props.name, | ||
includeSchema = props.includeSchema, | ||
pageIndex = props.pageIndex, | ||
pageSize = props.pageSize; | ||
var _usePlasmicDataOp = usePlasmicDataOp(dataOp, _extends({ | ||
includeSchema: includeSchema | ||
}, !!pageIndex && !!pageSize && { | ||
var data = usePlasmicDataOp(dataOp, _extends({}, !!pageIndex && !!pageSize && { | ||
paginate: { | ||
@@ -995,6 +1018,3 @@ pageIndex: pageIndex, | ||
} | ||
})), | ||
data = _usePlasmicDataOp.data, | ||
error = _usePlasmicDataOp.error; | ||
})); | ||
var $queries = React.useMemo(function () { | ||
@@ -1005,3 +1025,3 @@ var _extends2; | ||
}, [props.queries, name, data]); | ||
return error || data != null && data.error ? React.createElement("div", null, "Error: ", (error == null ? void 0 : error.toString()) || (data == null ? void 0 : (_data$error = data.error) == null ? void 0 : _data$error.message)) : (_children = children == null ? void 0 : children($queries)) != null ? _children : null; | ||
return (_children = children == null ? void 0 : children($queries)) != null ? _children : null; | ||
} | ||
@@ -1021,8 +1041,2 @@ var FetcherMeta = { | ||
children: 'slot', | ||
includeSchema: { | ||
type: 'boolean', | ||
advanced: true, | ||
displayName: 'Include data schema', | ||
description: 'Includes the data schema in the payload' | ||
}, | ||
pageSize: { | ||
@@ -1046,10 +1060,2 @@ type: 'number', | ||
function swallow(f) { | ||
try { | ||
return f(); | ||
} catch (_unused) { | ||
return undefined; | ||
} | ||
} | ||
function useDependencyAwareQuery(_ref) { | ||
@@ -1059,10 +1065,6 @@ var $queries = _ref.$queries, | ||
setDollarQueries = _ref.setDollarQueries, | ||
includeSchema = _ref.includeSchema, | ||
name = _ref.name, | ||
pageIndex = _ref.pageIndex, | ||
pageSize = _ref.pageSize; | ||
var _usePlasmicDataOp = usePlasmicDataOp(swallow(getDataOp), _extends({ | ||
includeSchema: includeSchema | ||
}, !!pageIndex && !!pageSize && { | ||
var data = usePlasmicDataOp(swallow(getDataOp), _extends({}, !!pageIndex && !!pageSize && { | ||
paginate: { | ||
@@ -1072,12 +1074,4 @@ pageIndex: pageIndex, | ||
} | ||
})), | ||
data = _usePlasmicDataOp.data, | ||
error = _usePlasmicDataOp.error; | ||
})); | ||
React.useEffect(function () { | ||
if (error) { | ||
console.error("Error while executing data source operation" + (name ? " " + name : '') + ":", error); | ||
} | ||
}, [error]); | ||
React.useEffect(function () { | ||
var finalName = name != null ? name : 'data'; | ||
@@ -1084,0 +1078,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@plasmicapp/query"),r=e(require("react")),n=require("@plasmicapp/data-sources-context"),o=e(require("isomorphic-unfetch"));function a(e,t,r,n,o,a,i){try{var u=e[a](i),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,o)}function i(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function u(e){a(i,n,o,u,c,"next",e)}function c(e){a(i,n,o,u,c,"throw",e)}u(void 0)}))}}function u(){return(u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function c(e,t){return e(t={exports:{}},t.exports),t.exports}var s=c((function(e){var t=function(e){var t=Object.prototype,r=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",a=n.asyncIterator||"@@asyncIterator",i=n.toStringTag||"@@toStringTag";function u(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,r){return e[t]=r}}function c(e,t,r,n){var o=Object.create((t&&t.prototype instanceof p?t:p).prototype),a=new E(n||[]);return o._invoke=function(e,t,r){var n="suspendedStart";return function(o,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw a;return{value:void 0,done:!0}}for(r.method=o,r.arg=a;;){var i=r.delegate;if(i){var u=w(i,r);if(u){if(u===l)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=s(e,t,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===l)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}(e,r,a),o}function s(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=c;var l={};function p(){}function h(){}function f(){}var d={};u(d,o,(function(){return this}));var v=Object.getPrototypeOf,y=v&&v(v(L([])));y&&y!==t&&r.call(y,o)&&(d=y);var m=f.prototype=p.prototype=Object.create(d);function g(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function x(e,t){var n;this._invoke=function(o,a){function i(){return new t((function(n,i){!function n(o,a,i,u){var c=s(e[o],e,a);if("throw"!==c.type){var l=c.arg,p=l.value;return p&&"object"==typeof p&&r.call(p,"__await")?t.resolve(p.__await).then((function(e){n("next",e,i,u)}),(function(e){n("throw",e,i,u)})):t.resolve(p).then((function(e){l.value=e,i(l)}),(function(e){return n("throw",e,i,u)}))}u(c.arg)}(o,a,n,i)}))}return n=n?n.then(i,i):i()}}function w(e,t){var r=e.iterator[t.method];if(void 0===r){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,w(e,t),"throw"===t.method))return l;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=s(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,l;var o=n.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,l):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,l)}function b(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function S(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function E(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(b,this),this.reset(!0)}function L(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,a=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return a.next=a}}return{next:O}}function O(){return{value:void 0,done:!0}}return h.prototype=f,u(m,"constructor",f),u(f,"constructor",h),h.displayName=u(f,i,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===h||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,f):(e.__proto__=f,u(e,i,"GeneratorFunction")),e.prototype=Object.create(m),e},e.awrap=function(e){return{__await:e}},g(x.prototype),u(x.prototype,a,(function(){return this})),e.AsyncIterator=x,e.async=function(t,r,n,o,a){void 0===a&&(a=Promise);var i=new x(c(t,r,n,o),a);return e.isGeneratorFunction(r)?i:i.next().then((function(e){return e.done?e.value:i.next()}))},g(m),u(m,i,"Generator"),u(m,o,(function(){return this})),u(m,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=L,E.prototype={constructor:E,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(S),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return i.type="throw",i.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var u=r.call(a,"catchLoc"),c=r.call(a,"finallyLoc");if(u&&c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=e,i.arg=t,a?(this.method="next",this.next=a.finallyLoc,l):this.complete(i)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),l},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),S(r),l}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;S(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:L(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},e}(e.exports);try{regeneratorRuntime=t}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}}));function l(e,t){return p.apply(this,arguments)}function p(){return(p=i(s.mark((function e(t,r){var n;return s.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=d("__PLASMIC_EXECUTE_DATA_OP",h),e.next=3,n(t,r);case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function h(e,t){return f.apply(this,arguments)}function f(){return(f=i(s.mark((function e(t,r){var n,a,i,c;return s.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=d("__PLASMIC_DATA_HOST","https://studio.plasmic.app"),i=a+"/api/v1/server-data/sources/"+t.sourceId+"/execute",e.next=4,o(i,{method:"POST",headers:u({"Content-Type":"application/json"},(null==r?void 0:r.userAuthToken)&&{"x-plasmic-data-user-auth-token":r.userAuthToken}),body:JSON.stringify({opId:t.opId,userArgs:null!=(n=t.userArgs)?n:{},includeSchema:null==r?void 0:r.includeSchema,paginate:null==r?void 0:r.paginate})});case 4:if(200===(c=e.sent).status){e.next=10;break}return e.next=8,c.text();case 8:throw new Error(e.sent);case 10:return e.next=12,c.json();case 12:return e.abrupt("return",e.sent);case 13:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function d(e,t){return"undefined"==typeof globalThis?t:null!=(r=globalThis[e])?r:t;var r}function v(e,r){var o=n.usePlasmicDataSourceContext();return t.useMutablePlasmicQueryData((function(){return e?e.cacheKey?e.cacheKey:JSON.stringify({sourceId:e.sourceId,opId:e.opId,args:e.userArgs,userAuthToken:null==o?void 0:o.userAuthToken,includeSchema:null==r?void 0:r.includeSchema,paginate:null==r?void 0:r.paginate}):null}),i(s.mark((function t(){return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,l(e,{userAuthToken:null==o?void 0:o.userAuthToken,includeSchema:null==r?void 0:r.includeSchema,paginate:null==r?void 0:r.paginate});case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t)}))))}Object.defineProperty(exports,"usePlasmicDataConfig",{enumerable:!0,get:function(){return t.usePlasmicDataConfig}}),exports.Fetcher=function(e){var t,n,o=e.children,a=e.name,i=e.pageIndex,c=e.pageSize,s=v(e.dataOp,u({includeSchema:e.includeSchema},!!i&&!!c&&{paginate:{pageIndex:i,pageSize:c}})),l=s.data,p=s.error,h=r.useMemo((function(){var t;return u({},e.queries,((t={})[null!=a?a:"data"]=l,t))}),[e.queries,a,l]);return p||null!=l&&l.error?r.createElement("div",null,"Error: ",(null==p?void 0:p.toString())||(null==l||null==(t=l.error)?void 0:t.message)):null!=(n=null==o?void 0:o(h))?n:null},exports.FetcherMeta={name:"plasmic-data-source-fetcher",displayName:"Data Source Fetcher",props:{dataOp:{type:"dataSourceOp",displayName:"Data"},name:{type:"string",displayName:"Variable name"},children:"slot",includeSchema:{type:"boolean",advanced:!0,displayName:"Include data schema",description:"Includes the data schema in the payload"},pageSize:{type:"number",advanced:!0,displayName:"Page size",description:"Only fetch in batches of this size; for pagination"},pageIndex:{type:"number",advanced:!0,displayName:"Page index",description:"0-based index of the paginated page to fetch"}},importPath:"@plasmicapp/react-web/lib/data-sources",importName:"Fetcher",styleSections:!1},exports.executePlasmicDataOp=l,exports.useDependencyAwareQuery=function(e){var t=e.$queries,n=e.setDollarQueries,o=e.includeSchema,a=e.name,i=e.pageIndex,c=e.pageSize,s=v(function(e){try{return e()}catch(e){return}}(e.getDataOp),u({includeSchema:o},!!i&&!!c&&{paginate:{pageIndex:i,pageSize:c}})),l=s.data,p=s.error;r.useEffect((function(){p&&console.error("Error while executing data source operation"+(a?" "+a:"")+":",p)}),[p]),r.useEffect((function(){var e,r=null!=a?a:"data";r in t&&t[r]===l||n(u({},t,((e={})[r]=l,e)))}),[a,l,t,n])},exports.usePlasmicDataMutationOp=function(e,t){var o=null!=e?e:{},a=o.sourceId,u=o.opId,c=o.userArgs,p=n.usePlasmicDataSourceContext(),h=null==p?void 0:p.userAuthToken;return r.useCallback(i(s.mark((function e(){return s.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(a&&u){e.next=2;break}return e.abrupt("return",void 0);case 2:return e.abrupt("return",l({sourceId:a,opId:u,userArgs:c},{userAuthToken:h,includeSchema:null==t?void 0:t.includeSchema}));case 3:case"end":return e.stop()}}),e)}))),[a,u,c,h])},exports.usePlasmicDataOp=v; | ||
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@plasmicapp/query"),r=t(require("react")),n=require("@plasmicapp/data-sources-context"),o=t(require("isomorphic-unfetch"));function a(t,e,r,n,o,a,i){try{var u=t[a](i),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function i(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function u(t){a(i,n,o,u,c,"next",t)}function c(t){a(i,n,o,u,c,"throw",t)}u(void 0)}))}}function u(){return(u=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function c(t,e){return t(e={exports:{}},e.exports),e.exports}var s=c((function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",a=n.asyncIterator||"@@asyncIterator",i=n.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function c(t,e,r,n){var o=Object.create((e&&e.prototype instanceof p?e:p).prototype),a=new O(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw a;return{value:void 0,done:!0}}for(r.method=o,r.arg=a;;){var i=r.delegate;if(i){var u=w(i,r);if(u){if(u===l)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=s(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===l)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}(t,r,a),o}function s(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=c;var l={};function p(){}function f(){}function h(){}var d={};u(d,o,(function(){return this}));var v=Object.getPrototypeOf,y=v&&v(v(E([])));y&&y!==e&&r.call(y,o)&&(d=y);var g=h.prototype=p.prototype=Object.create(d);function m(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function x(t,e){var n;this._invoke=function(o,a){function i(){return new e((function(n,i){!function n(o,a,i,u){var c=s(t[o],t,a);if("throw"!==c.type){var l=c.arg,p=l.value;return p&&"object"==typeof p&&r.call(p,"__await")?e.resolve(p.__await).then((function(t){n("next",t,i,u)}),(function(t){n("throw",t,i,u)})):e.resolve(p).then((function(t){l.value=t,i(l)}),(function(t){return n("throw",t,i,u)}))}u(c.arg)}(o,a,n,i)}))}return n=n?n.then(i,i):i()}}function w(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,w(t,e),"throw"===e.method))return l;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=s(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,l;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,l):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,l)}function b(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function L(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(b,this),this.reset(!0)}function E(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,a=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return a.next=a}}return{next:P}}function P(){return{value:void 0,done:!0}}return f.prototype=h,u(g,"constructor",h),u(h,"constructor",f),f.displayName=u(h,i,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===f||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,h):(t.__proto__=h,u(t,i,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},m(x.prototype),u(x.prototype,a,(function(){return this})),t.AsyncIterator=x,t.async=function(e,r,n,o,a){void 0===a&&(a=Promise);var i=new x(c(e,r,n,o),a);return t.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},m(g),u(g,i,"Generator"),u(g,o,(function(){return this})),u(g,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=E,O.prototype={constructor:O,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(L),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return i.type="throw",i.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var u=r.call(a,"catchLoc"),c=r.call(a,"finallyLoc");if(u&&c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a.finallyLoc,l):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),l},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),L(r),l}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;L(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:E(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}));function l(t,e){return p.apply(this,arguments)}function p(){return(p=i(s.mark((function t(e,r){var n;return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=d("__PLASMIC_EXECUTE_DATA_OP",f),t.next=3,n(e,r);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function f(t,e){return h.apply(this,arguments)}function h(){return(h=i(s.mark((function t(e,r){var n,a,i,c;return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=d("__PLASMIC_DATA_HOST","https://studio.plasmic.app"),i=a+"/api/v1/server-data/sources/"+e.sourceId+"/execute",t.next=4,o(i,{method:"POST",headers:u({"Content-Type":"application/json"},(null==r?void 0:r.userAuthToken)&&{"x-plasmic-data-user-auth-token":r.userAuthToken}),body:JSON.stringify({opId:e.opId,userArgs:null!=(n=e.userArgs)?n:{},paginate:null==r?void 0:r.paginate})});case 4:if(200===(c=t.sent).status){t.next=10;break}return t.next=8,c.text();case 8:throw new Error(t.sent);case 10:return t.next=12,c.json();case 12:return t.abrupt("return",t.sent);case 13:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function d(t,e){return"undefined"==typeof globalThis?e:null!=(r=globalThis[t])?r:e;var r}function v(t,o){var a=n.usePlasmicDataSourceContext(),c=e.useMutablePlasmicQueryData((function(){return t?t.cacheKey?t.cacheKey:JSON.stringify({sourceId:t.sourceId,opId:t.opId,args:t.userArgs,userAuthToken:null==a?void 0:a.userAuthToken,paginate:null==o?void 0:o.paginate}):null}),i(s.mark((function e(){return s.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,l(t,{userAuthToken:null==a?void 0:a.userAuthToken,paginate:null==o?void 0:o.paginate});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e)})))),p=c.data;return r.useMemo((function(){return u({},null!=p?p:{},function(t){for(var e={},r=arguments.length,n=new Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];for(var a=0,i=n;a<i.length;a++){var u=i[a];u in t&&(e[u]=t[u])}return e}(c,"isLoading","error"))}),[p,c.error,c.isLoading])}Object.defineProperty(exports,"usePlasmicDataConfig",{enumerable:!0,get:function(){return e.usePlasmicDataConfig}}),exports.Fetcher=function(t){var e,n=t.children,o=t.name,a=t.pageIndex,i=t.pageSize,c=v(t.dataOp,u({},!!a&&!!i&&{paginate:{pageIndex:a,pageSize:i}})),s=r.useMemo((function(){var e;return u({},t.queries,((e={})[null!=o?o:"data"]=c,e))}),[t.queries,o,c]);return null!=(e=null==n?void 0:n(s))?e:null},exports.FetcherMeta={name:"plasmic-data-source-fetcher",displayName:"Data Source Fetcher",props:{dataOp:{type:"dataSourceOp",displayName:"Data"},name:{type:"string",displayName:"Variable name"},children:"slot",pageSize:{type:"number",advanced:!0,displayName:"Page size",description:"Only fetch in batches of this size; for pagination"},pageIndex:{type:"number",advanced:!0,displayName:"Page index",description:"0-based index of the paginated page to fetch"}},importPath:"@plasmicapp/react-web/lib/data-sources",importName:"Fetcher",styleSections:!1},exports.executePlasmicDataOp=l,exports.useDependencyAwareQuery=function(t){var e=t.$queries,n=t.setDollarQueries,o=t.name,a=t.pageIndex,i=t.pageSize,c=v(function(t){try{return t()}catch(t){return}}(t.getDataOp),u({},!!a&&!!i&&{paginate:{pageIndex:a,pageSize:i}}));r.useEffect((function(){var t,r=null!=o?o:"data";r in e&&e[r]===c||n(u({},e,((t={})[r]=c,t)))}),[o,c,e,n])},exports.usePlasmicDataMutationOp=function(t,e){var o=null!=t?t:{},a=o.sourceId,u=o.opId,c=o.userArgs,p=n.usePlasmicDataSourceContext(),f=null==p?void 0:p.userAuthToken;return r.useCallback(i(s.mark((function t(){return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(a&&u){t.next=2;break}return t.abrupt("return",void 0);case 2:return t.abrupt("return",l({sourceId:a,opId:u,userArgs:c},{userAuthToken:f}));case 3:case"end":return t.stop()}}),t)}))),[a,u,c,f])},exports.usePlasmicDataOp=v; | ||
//# sourceMappingURL=data-sources.cjs.production.min.js.map |
@@ -845,3 +845,2 @@ import { useMutablePlasmicQueryData } from '@plasmicapp/query'; | ||
userArgs: (_op$userArgs = op.userArgs) != null ? _op$userArgs : {}, | ||
includeSchema: opts == null ? void 0 : opts.includeSchema, | ||
paginate: opts == null ? void 0 : opts.paginate | ||
@@ -893,5 +892,30 @@ }) | ||
function swallow(f) { | ||
try { | ||
return f(); | ||
} catch (_unused) { | ||
return undefined; | ||
} | ||
} | ||
function pick(obj) { | ||
var res = {}; | ||
for (var _len = arguments.length, keys = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
keys[_key - 1] = arguments[_key]; | ||
} | ||
for (var _i = 0, _keys = keys; _i < _keys.length; _i++) { | ||
var key = _keys[_i]; | ||
if (key in obj) { | ||
res[key] = obj[key]; | ||
} | ||
} | ||
return res; | ||
} | ||
function usePlasmicDataOp(dataOp, opts) { | ||
var ctx = usePlasmicDataSourceContext(); | ||
return useMutablePlasmicQueryData(function () { | ||
var res = useMutablePlasmicQueryData(function () { | ||
return dataOp ? dataOp.cacheKey ? dataOp.cacheKey : JSON.stringify({ | ||
@@ -902,3 +926,2 @@ sourceId: dataOp.sourceId, | ||
userAuthToken: ctx == null ? void 0 : ctx.userAuthToken, | ||
includeSchema: opts == null ? void 0 : opts.includeSchema, | ||
paginate: opts == null ? void 0 : opts.paginate | ||
@@ -914,3 +937,2 @@ }) : null; | ||
userAuthToken: ctx == null ? void 0 : ctx.userAuthToken, | ||
includeSchema: opts == null ? void 0 : opts.includeSchema, | ||
paginate: opts == null ? void 0 : opts.paginate | ||
@@ -929,2 +951,8 @@ }); | ||
}))); | ||
var data = res.data, | ||
error = res.error, | ||
isLoading = res.isLoading; | ||
return React.useMemo(function () { | ||
return _extends({}, data != null ? data : {}, pick(res, 'isLoading', 'error')); | ||
}, [data, error, isLoading]); | ||
} | ||
@@ -957,4 +985,3 @@ function usePlasmicDataMutationOp(dataOp, opts) { | ||
}, { | ||
userAuthToken: userToken, | ||
includeSchema: opts == null ? void 0 : opts.includeSchema | ||
userAuthToken: userToken | ||
})); | ||
@@ -972,3 +999,3 @@ | ||
function Fetcher(props) { | ||
var _data$error, _children; | ||
var _children; | ||
@@ -978,9 +1005,5 @@ var dataOp = props.dataOp, | ||
name = props.name, | ||
includeSchema = props.includeSchema, | ||
pageIndex = props.pageIndex, | ||
pageSize = props.pageSize; | ||
var _usePlasmicDataOp = usePlasmicDataOp(dataOp, _extends({ | ||
includeSchema: includeSchema | ||
}, !!pageIndex && !!pageSize && { | ||
var data = usePlasmicDataOp(dataOp, _extends({}, !!pageIndex && !!pageSize && { | ||
paginate: { | ||
@@ -990,6 +1013,3 @@ pageIndex: pageIndex, | ||
} | ||
})), | ||
data = _usePlasmicDataOp.data, | ||
error = _usePlasmicDataOp.error; | ||
})); | ||
var $queries = React.useMemo(function () { | ||
@@ -1000,3 +1020,3 @@ var _extends2; | ||
}, [props.queries, name, data]); | ||
return error || data != null && data.error ? React.createElement("div", null, "Error: ", (error == null ? void 0 : error.toString()) || (data == null ? void 0 : (_data$error = data.error) == null ? void 0 : _data$error.message)) : (_children = children == null ? void 0 : children($queries)) != null ? _children : null; | ||
return (_children = children == null ? void 0 : children($queries)) != null ? _children : null; | ||
} | ||
@@ -1016,8 +1036,2 @@ var FetcherMeta = { | ||
children: 'slot', | ||
includeSchema: { | ||
type: 'boolean', | ||
advanced: true, | ||
displayName: 'Include data schema', | ||
description: 'Includes the data schema in the payload' | ||
}, | ||
pageSize: { | ||
@@ -1041,10 +1055,2 @@ type: 'number', | ||
function swallow(f) { | ||
try { | ||
return f(); | ||
} catch (_unused) { | ||
return undefined; | ||
} | ||
} | ||
function useDependencyAwareQuery(_ref) { | ||
@@ -1054,10 +1060,6 @@ var $queries = _ref.$queries, | ||
setDollarQueries = _ref.setDollarQueries, | ||
includeSchema = _ref.includeSchema, | ||
name = _ref.name, | ||
pageIndex = _ref.pageIndex, | ||
pageSize = _ref.pageSize; | ||
var _usePlasmicDataOp = usePlasmicDataOp(swallow(getDataOp), _extends({ | ||
includeSchema: includeSchema | ||
}, !!pageIndex && !!pageSize && { | ||
var data = usePlasmicDataOp(swallow(getDataOp), _extends({}, !!pageIndex && !!pageSize && { | ||
paginate: { | ||
@@ -1067,12 +1069,4 @@ pageIndex: pageIndex, | ||
} | ||
})), | ||
data = _usePlasmicDataOp.data, | ||
error = _usePlasmicDataOp.error; | ||
})); | ||
React.useEffect(function () { | ||
if (error) { | ||
console.error("Error while executing data source operation" + (name ? " " + name : '') + ":", error); | ||
} | ||
}, [error]); | ||
React.useEffect(function () { | ||
var finalName = name != null ? name : 'data'; | ||
@@ -1079,0 +1073,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { Pagination } from './types'; | ||
import { ManyRowsResult, Pagination, SingleRowResult } from './types'; | ||
export interface DataOp { | ||
@@ -9,6 +9,5 @@ sourceId: string; | ||
} | ||
export declare function executePlasmicDataOp<T = any>(op: DataOp, opts?: { | ||
export declare function executePlasmicDataOp<T extends SingleRowResult | ManyRowsResult>(op: DataOp, opts?: { | ||
userAuthToken?: string; | ||
includeSchema?: boolean; | ||
paginate?: Pagination; | ||
}): Promise<T>; |
@@ -8,2 +8,2 @@ import { DataOpConfig } from '../components/Fetcher'; | ||
} | ||
export declare function useDependencyAwareQuery({ $queries, getDataOp, setDollarQueries, includeSchema, name, pageIndex, pageSize, }: DependencyAwareQueryConfig): void; | ||
export declare function useDependencyAwareQuery({ $queries, getDataOp, setDollarQueries, name, pageIndex, pageSize, }: DependencyAwareQueryConfig): void; |
import { DataOp } from '../executor'; | ||
import { Pagination } from '../types'; | ||
export declare function usePlasmicDataOp<T = any, E = any>(dataOp: DataOp | undefined, opts?: { | ||
includeSchema?: boolean; | ||
import { ManyRowsResult, Pagination, SingleRowResult } from '../types'; | ||
export declare function usePlasmicDataOp<T extends SingleRowResult | ManyRowsResult, E = any>(dataOp: DataOp | undefined, opts?: { | ||
paginate?: Pagination; | ||
}): import("@plasmicapp/query").SWRResponse<T, E>; | ||
export declare function usePlasmicDataMutationOp<T = any>(dataOp: DataOp | undefined, opts?: { | ||
includeSchema?: boolean; | ||
}): () => Promise<T | undefined>; | ||
}): Partial<T> & { | ||
error?: E; | ||
isLoading?: boolean; | ||
}; | ||
export declare function usePlasmicDataMutationOp<T extends SingleRowResult | ManyRowsResult>(dataOp: DataOp | undefined, opts?: {}): () => Promise<T | undefined>; |
@@ -21,3 +21,3 @@ export interface Pagination { | ||
data: T; | ||
schema?: TableSchema; | ||
schema: TableSchema; | ||
} | ||
@@ -27,4 +27,4 @@ export interface ManyRowsResult<T = any> { | ||
total?: number; | ||
schema?: TableSchema; | ||
schema: TableSchema; | ||
paginate?: Pagination; | ||
} |
export declare function swallow<T>(f: () => T): T | undefined; | ||
export declare function pick<T extends object, K extends keyof T>(obj: T, ...keys: K[]): Pick<T, K>; |
{ | ||
"version": "0.1.16", | ||
"version": "0.1.17", | ||
"license": "MIT", | ||
@@ -62,4 +62,4 @@ "main": "dist/index.js", | ||
"@plasmicapp/data-sources-context": "0.1.2", | ||
"@plasmicapp/host": "1.0.86", | ||
"@plasmicapp/query": "0.1.55", | ||
"@plasmicapp/host": "1.0.87", | ||
"@plasmicapp/query": "0.1.56", | ||
"isomorphic-unfetch": "^3.1.0" | ||
@@ -70,3 +70,3 @@ }, | ||
}, | ||
"gitHead": "67231ddf20b0f6f111f49326c483e09100e0eb8c" | ||
"gitHead": "681e87be189b1cc22fed1e2aa62a022c1eee78ab" | ||
} |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
250572
1946
+ Added@plasmicapp/host@1.0.87(transitive)
+ Added@plasmicapp/query@0.1.56(transitive)
- Removed@plasmicapp/host@1.0.86(transitive)
- Removed@plasmicapp/query@0.1.55(transitive)
Updated@plasmicapp/host@1.0.87
Updated@plasmicapp/query@0.1.56