New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@plasmicapp/data-sources

Package Overview
Dependencies
Maintainers
1
Versions
166
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@plasmicapp/data-sources - npm Package Compare versions

Comparing version

to
0.1.96

dist/helpers.d.ts

145

dist/data-sources.cjs.development.js

@@ -836,2 +836,18 @@ 'use strict';

}
var tuple = function tuple() {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return args;
};
function mkIdMap(xs) {
return new Map(xs.map(function (x) {
return tuple(x.id, x);
}));
}
function withoutNils(xs) {
return xs.filter(function (x) {
return x != null;
});
}

@@ -1069,2 +1085,129 @@ function makeCacheKey(dataOp, opts) {

function normalizeData(rawData) {
var _rawData$schema;
if (!rawData) {
return undefined;
}
var dataArray = tryGetDataArray(rawData);
if (!dataArray) {
return undefined;
}
var schema = (_rawData$schema = rawData.schema) != null ? _rawData$schema : tryGetSchema(dataArray);
if (!schema) {
return undefined;
}
return {
data: dataArray,
schema: schema
};
}
function tryGetDataArray(rawData) {
if (rawData == null || typeof rawData !== 'object') {
return undefined;
}
if (Array.isArray(rawData)) {
if (isArrayOfObjects(rawData)) {
return rawData;
} else {
// TODO: array of primitives? Maybe we can wrap this?
return undefined;
}
}
if (rawData == null) {
return undefined;
}
if ('data' in rawData && typeof rawData.data === 'object') {
if (Array.isArray(rawData.data) && isArrayOfObjects(rawData.data)) {
return rawData.data;
} else if (rawData.data != null) {
return [rawData.data];
} else {
return undefined;
}
}
if ('isLoading' in rawData || 'error' in rawData) {
return undefined;
}
// Maybe a singleton record?
return [rawData];
}
function isArrayOfObjects(arr) {
return arr.every(function (x) {
return typeof x === 'object' && !Array.isArray(x);
});
}
function tryGetSchema(data) {
var fieldMap = {};
data.forEach(function (entry) {
if (entry && typeof entry === 'object') {
Array.from(Object.entries(entry)).forEach(function (_ref) {
var k = _ref[0],
v = _ref[1];
var inferredType = typeof v === 'string' ? 'string' : typeof v === 'boolean' ? 'boolean' : typeof v === 'number' ? 'number' : 'unknown';
if (fieldMap[k] && fieldMap[k] !== inferredType) {
fieldMap[k] = 'unknown';
} else {
fieldMap[k] = inferredType;
}
});
}
});
return {
id: 'inferred',
fields: Object.entries(fieldMap).map(function (_ref2) {
var f = _ref2[0],
t = _ref2[1];
return {
id: f,
type: t,
readOnly: false
};
})
};
}
var mkShortId = function mkShortId() {
return "" + Math.random();
};
function deriveFieldConfigs(specifiedFieldsPartial, schema, makeDefaultConfig) {
var _schema$fields;
var schemaFields = (_schema$fields = schema == null ? void 0 : schema.fields) != null ? _schema$fields : [];
var fieldById = mkIdMap(schemaFields);
var specifiedFieldIds = new Set(withoutNils(specifiedFieldsPartial.map(function (f) {
return f.fieldId;
})));
var keptSpecifiedFields = specifiedFieldsPartial.flatMap(function (f) {
if (!f.fieldId) {
return [_extends({
key: mkShortId()
}, makeDefaultConfig(undefined), f)];
}
var field = fieldById.get(f.fieldId);
// Drop configs with fieldIds no longer in the data.
if (!field) {
return [];
}
return [_extends({
key: mkShortId()
}, makeDefaultConfig(field), f)];
});
var newVirtualFields = schemaFields.filter(function (f) {
return !specifiedFieldIds.has(f.id);
}).map(function (f) {
return _extends({
key: mkShortId()
}, makeDefaultConfig(f));
});
var mergedFields = [].concat(keptSpecifiedFields, newVirtualFields);
var minimalFullLengthFields = [].concat(specifiedFieldsPartial, newVirtualFields.map(function (f) {
return {
key: f.key,
fieldId: f.fieldId
};
}));
return {
mergedFields: mergedFields,
minimalFullLengthFields: minimalFullLengthFields
};
}
Object.defineProperty(exports, 'usePlasmicDataConfig', {

@@ -1078,4 +1221,6 @@ enumerable: true,

exports.FetcherMeta = FetcherMeta;
exports.deriveFieldConfigs = deriveFieldConfigs;
exports.executePlasmicDataOp = executePlasmicDataOp;
exports.makeCacheKey = makeCacheKey;
exports.normalizeData = normalizeData;
exports.useDependencyAwareQuery = useDependencyAwareQuery;

@@ -1082,0 +1227,0 @@ exports.usePlasmicDataMutationOp = usePlasmicDataMutationOp;

2

dist/data-sources.cjs.production.min.js

@@ -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=require("@plasmicapp/host"),a=e(require("@plasmicapp/isomorphic-unfetch")),i=e(require("fast-stringify"));function u(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 c(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function i(e){u(a,n,o,i,c,"next",e)}function c(e){u(a,n,o,i,c,"throw",e)}i(void 0)}))}}function s(){return(s=Object.assign?Object.assign.bind():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 l(e,t){return e(t={exports:{}},t.exports),t.exports}var p=l((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 L(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 f(){}function h(){}var d={};u(d,o,(function(){return this}));var v=Object.getPrototypeOf,g=v&&v(v(E([])));g&&g!==t&&r.call(g,o)&&(d=g);var y=h.prototype=p.prototype=Object.create(d);function m(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 P(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function L(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(b,this),this.reset(!0)}function E(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 f.prototype=h,u(y,"constructor",h),u(h,"constructor",f),f.displayName=u(h,i,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===f||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,h):(e.__proto__=h,u(e,i,"GeneratorFunction")),e.prototype=Object.create(y),e},e.awrap=function(e){return{__await:e}},m(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()}))},m(y),u(y,i,"Generator"),u(y,o,(function(){return this})),u(y,"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=E,L.prototype={constructor:L,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(P),!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),P(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;P(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:E(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)}})),f="You do not have permission to perform this operation. Login to get access or contact the app owner to get access.";function h(e,t){return d.apply(this,arguments)}function d(){return(d=c(p.mark((function e(r,n){var o;return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=y("__PLASMIC_EXECUTE_DATA_OP",v),e.next=3,t.wrapLoadingFetcher(o)(r,n);case 3:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function v(e,t){return g.apply(this,arguments)}function g(){return(g=c(p.mark((function e(t,r){var n,o,u,c;return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.roleId){e.next=4;break}if(null!=r&&r.user&&r.user.roleIds.includes(t.roleId)){e.next=4;break}throw console.error(f),new Error(f);case 4:return o=y("__PLASMIC_DATA_HOST","https://data.plasmic.app"),u=o+"/api/v1/server-data/sources/"+t.sourceId+"/execute",e.next=8,a(u,{method:"POST",headers:s({"Content-Type":"application/json"},(null==r?void 0:r.userAuthToken)&&{"x-plasmic-data-user-auth-token":r.userAuthToken}),body:i({opId:t.opId,userArgs:null!=(n=t.userArgs)?n:{},paginate:null==r?void 0:r.paginate})});case 8:if(200===(c=e.sent).status){e.next=14;break}return e.next=12,c.text();case 12:throw new Error(e.sent);case 14:return e.next=16,c.json();case 16:return e.abrupt("return",e.sent);case 17:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function y(e,t){return"undefined"==typeof globalThis?t:null!=(r=globalThis[e])?r:t;var r}function m(e,t){var r=JSON.stringify({sourceId:e.sourceId,opId:e.opId,args:e.userArgs,userAuthToken:null==t?void 0:t.userAuthToken,paginate:null==t?void 0:t.paginate});return e.cacheKey?""+e.cacheKey+r:r}function x(e,t){return new Proxy({},{get:function(r,n){if("isPlasmicUndefinedDataProxy"===n)return!0;var o=e.fetchingPromise||t();throw o.plasmicType="PlasmicUndefinedDataError",o.message="Cannot read property "+String(n)+" - data is still loading",o}})}var w=+r.version.split(".")[0];function b(e,a){var i,u=n.usePlasmicDataSourceContext(),c=!(null==o.useDataEnv||null==(i=o.useDataEnv())||!i.plasmicInternalEnableLoadingBoundary),l=t.usePlasmicDataConfig(),p=l.mutate,f=l.cache,d=!e,v=d?null:m(e,{paginate:null==a?void 0:a.paginate,userAuthToken:null==u?void 0:u.userAuthToken}),g=r.useMemo((function(){return{fetchingPromise:void 0}}),[v]),y=r.useMemo((function(){return function(){if(g.fetchingPromise)return g.fetchingPromise;var t=h(e,{userAuthToken:(null==u?void 0:u.userAuthToken)||void 0,user:null==u?void 0:u.user,paginate:null==a?void 0:a.paginate});return g.fetchingPromise=t,t}}),[v,g]),b=r.useMemo((function(){return function(){if(g.fetchingPromise)return g.fetchingPromise;var e=y();return e.then((function(e){return p(v,e)})).catch((function(e){var t,r=v?"$swr$"+v:"";f.set(r,s({},null!=(t=f.get(r))?t:{},{error:e}))})),e}}),[y,g,f,v]),P=t.useMutablePlasmicQueryData(v,y,{shouldRetryOnError:!1}),L=P.data,E=P.error,O=P.isLoading;return null!=g.fetchingPromise&&void 0!==L&&(g.fetchingPromise=void 0),r.useMemo((function(){var e=s({},null!=L?L:{},function(e){for(var t={},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 e&&(t[u]=e[u])}return t}(P,"isLoading","error"));return(null==a||!a.noUndefinedDataProxy)&&w>=18&&c&&(O||d)&&void 0===e.data&&void 0===e.schema&&(e.data=x(g,b),e.schema=x(g,b)),e}),[d,L,E,O,null==a?void 0:a.noUndefinedDataProxy,c,g,b])}Object.defineProperty(exports,"usePlasmicDataConfig",{enumerable:!0,get:function(){return t.usePlasmicDataConfig}}),exports.Fetcher=function(e){var t,n=e.children,o=e.name,a=e.pageIndex,i=e.pageSize,u=b(e.dataOp,s({},!!a&&!!i&&{paginate:{pageIndex:a,pageSize:i}})),c=r.useMemo((function(){var t;return s({},e.queries,((t={})[null!=o?o:"data"]=u,t))}),[e.queries,o,u]);return null!=(t=null==n?void 0:n(c))?t:null},exports.FetcherMeta={name:"plasmic-data-source-fetcher",displayName:"Data Fetcher",props:{dataOp:{type:"dataSourceOp",displayName:"Data"},name:{type:"string",displayName:"Variable name"},children:{type:"slot",renderPropParams:["$queries"]},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",alwaysAutoName:!0,styleSections:!1},exports.executePlasmicDataOp=h,exports.makeCacheKey=m,exports.useDependencyAwareQuery=function(e){var t,n,o=e.$queries,a=e.setDollarQueries,i=e.name,u=e.pageIndex,c=e.pageSize,l=b(function(e){try{return e()}catch(e){return}}(e.getDataOp),s({},!!u&&!!c&&{paginate:{pageIndex:u,pageSize:c}})),p=null!=i?i:"data",f=(t=p,n=r.useRef(void 0),r.useEffect((function(){return n.current=t,function(){n.current=void 0}})),n.current);r.useEffect((function(){if(!(p in o)||o[p]!==l){var e,t=s({},o,((e={})[p]=l,e));f&&p!==f&&f in o&&delete t[f],a(t)}}),[p,f,l,o,a])},exports.usePlasmicDataMutationOp=function(e){var t=null!=e?e:{},o=t.sourceId,a=t.opId,i=t.userArgs,u=n.usePlasmicDataSourceContext(),s=null==u?void 0:u.userAuthToken;return r.useCallback(c(p.mark((function e(){return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o&&a){e.next=2;break}return e.abrupt("return",void 0);case 2:return e.abrupt("return",h({sourceId:o,opId:a,userArgs:i},{userAuthToken:s||void 0,user:null==u?void 0:u.user}));case 3:case"end":return e.stop()}}),e)}))),[o,a,i,s])},exports.usePlasmicDataOp=b;
"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=require("@plasmicapp/host"),a=e(require("@plasmicapp/isomorphic-unfetch")),i=e(require("fast-stringify"));function u(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 c(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function i(e){u(a,n,o,i,c,"next",e)}function c(e){u(a,n,o,i,c,"throw",e)}i(void 0)}))}}function s(){return(s=Object.assign?Object.assign.bind():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 l(e,t){return e(t={exports:{}},t.exports),t.exports}var f=l((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 f?t:f).prototype),a=new L(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=x(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 f(){}function p(){}function d(){}var h={};u(h,o,(function(){return this}));var v=Object.getPrototypeOf,y=v&&v(v(E([])));y&&y!==t&&r.call(y,o)&&(h=y);var g=d.prototype=f.prototype=Object.create(h);function m(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function w(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,f=l.value;return f&&"object"==typeof f&&r.call(f,"__await")?t.resolve(f.__await).then((function(e){n("next",e,i,u)}),(function(e){n("throw",e,i,u)})):t.resolve(f).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 x(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,x(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 P(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function L(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(b,this),this.reset(!0)}function E(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:k}}function k(){return{value:void 0,done:!0}}return p.prototype=d,u(g,"constructor",d),u(d,"constructor",p),p.displayName=u(d,i,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===p||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,d):(e.__proto__=d,u(e,i,"GeneratorFunction")),e.prototype=Object.create(g),e},e.awrap=function(e){return{__await:e}},m(w.prototype),u(w.prototype,a,(function(){return this})),e.AsyncIterator=w,e.async=function(t,r,n,o,a){void 0===a&&(a=Promise);var i=new w(c(t,r,n,o),a);return e.isGeneratorFunction(r)?i:i.next().then((function(e){return e.done?e.value:i.next()}))},m(g),u(g,i,"Generator"),u(g,o,(function(){return this})),u(g,"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=E,L.prototype={constructor:L,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(P),!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),P(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;P(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:E(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)}})),p="You do not have permission to perform this operation. Login to get access or contact the app owner to get access.";function d(e,t){return h.apply(this,arguments)}function h(){return(h=c(f.mark((function e(r,n){var o;return f.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=g("__PLASMIC_EXECUTE_DATA_OP",v),e.next=3,t.wrapLoadingFetcher(o)(r,n);case 3:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function v(e,t){return y.apply(this,arguments)}function y(){return(y=c(f.mark((function e(t,r){var n,o,u,c;return f.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.roleId){e.next=4;break}if(null!=r&&r.user&&r.user.roleIds.includes(t.roleId)){e.next=4;break}throw console.error(p),new Error(p);case 4:return o=g("__PLASMIC_DATA_HOST","https://data.plasmic.app"),u=o+"/api/v1/server-data/sources/"+t.sourceId+"/execute",e.next=8,a(u,{method:"POST",headers:s({"Content-Type":"application/json"},(null==r?void 0:r.userAuthToken)&&{"x-plasmic-data-user-auth-token":r.userAuthToken}),body:i({opId:t.opId,userArgs:null!=(n=t.userArgs)?n:{},paginate:null==r?void 0:r.paginate})});case 8:if(200===(c=e.sent).status){e.next=14;break}return e.next=12,c.text();case 12:throw new Error(e.sent);case 14:return e.next=16,c.json();case 16:return e.abrupt("return",e.sent);case 17:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function g(e,t){return"undefined"==typeof globalThis?t:null!=(r=globalThis[e])?r:t;var r}function m(e,t){var r=JSON.stringify({sourceId:e.sourceId,opId:e.opId,args:e.userArgs,userAuthToken:null==t?void 0:t.userAuthToken,paginate:null==t?void 0:t.paginate});return e.cacheKey?""+e.cacheKey+r:r}function w(e,t){return new Proxy({},{get:function(r,n){if("isPlasmicUndefinedDataProxy"===n)return!0;var o=e.fetchingPromise||t();throw o.plasmicType="PlasmicUndefinedDataError",o.message="Cannot read property "+String(n)+" - data is still loading",o}})}var x=+r.version.split(".")[0];function b(e,a){var i,u=n.usePlasmicDataSourceContext(),c=!(null==o.useDataEnv||null==(i=o.useDataEnv())||!i.plasmicInternalEnableLoadingBoundary),l=t.usePlasmicDataConfig(),f=l.mutate,p=l.cache,h=!e,v=h?null:m(e,{paginate:null==a?void 0:a.paginate,userAuthToken:null==u?void 0:u.userAuthToken}),y=r.useMemo((function(){return{fetchingPromise:void 0}}),[v]),g=r.useMemo((function(){return function(){if(y.fetchingPromise)return y.fetchingPromise;var t=d(e,{userAuthToken:(null==u?void 0:u.userAuthToken)||void 0,user:null==u?void 0:u.user,paginate:null==a?void 0:a.paginate});return y.fetchingPromise=t,t}}),[v,y]),b=r.useMemo((function(){return function(){if(y.fetchingPromise)return y.fetchingPromise;var e=g();return e.then((function(e){return f(v,e)})).catch((function(e){var t,r=v?"$swr$"+v:"";p.set(r,s({},null!=(t=p.get(r))?t:{},{error:e}))})),e}}),[g,y,p,v]),P=t.useMutablePlasmicQueryData(v,g,{shouldRetryOnError:!1}),L=P.data,E=P.error,k=P.isLoading;return null!=y.fetchingPromise&&void 0!==L&&(y.fetchingPromise=void 0),r.useMemo((function(){var e=s({},null!=L?L:{},function(e){for(var t={},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 e&&(t[u]=e[u])}return t}(P,"isLoading","error"));return(null==a||!a.noUndefinedDataProxy)&&x>=18&&c&&(k||h)&&void 0===e.data&&void 0===e.schema&&(e.data=w(y,b),e.schema=w(y,b)),e}),[h,L,E,k,null==a?void 0:a.noUndefinedDataProxy,c,y,b])}function P(e){return e.every((function(e){return"object"==typeof e&&!Array.isArray(e)}))}var L=function(){return""+Math.random()};Object.defineProperty(exports,"usePlasmicDataConfig",{enumerable:!0,get:function(){return t.usePlasmicDataConfig}}),exports.Fetcher=function(e){var t,n=e.children,o=e.name,a=e.pageIndex,i=e.pageSize,u=b(e.dataOp,s({},!!a&&!!i&&{paginate:{pageIndex:a,pageSize:i}})),c=r.useMemo((function(){var t;return s({},e.queries,((t={})[null!=o?o:"data"]=u,t))}),[e.queries,o,u]);return null!=(t=null==n?void 0:n(c))?t:null},exports.FetcherMeta={name:"plasmic-data-source-fetcher",displayName:"Data Fetcher",props:{dataOp:{type:"dataSourceOp",displayName:"Data"},name:{type:"string",displayName:"Variable name"},children:{type:"slot",renderPropParams:["$queries"]},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",alwaysAutoName:!0,styleSections:!1},exports.deriveFieldConfigs=function(e,t,r){var n,o=null!=(n=null==t?void 0:t.fields)?n:[],a=new Map(o.map((function(e){return function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return t}(e.id,e)}))),i=new Set(e.map((function(e){return e.fieldId})).filter((function(e){return null!=e}))),u=e.flatMap((function(e){if(!e.fieldId)return[s({key:L()},r(void 0),e)];var t=a.get(e.fieldId);return t?[s({key:L()},r(t),e)]:[]})),c=o.filter((function(e){return!i.has(e.id)})).map((function(e){return s({key:L()},r(e))}));return{mergedFields:[].concat(u,c),minimalFullLengthFields:[].concat(e,c.map((function(e){return{key:e.key,fieldId:e.fieldId}})))}},exports.executePlasmicDataOp=d,exports.makeCacheKey=m,exports.normalizeData=function(e){var t;if(e){var r=function(e){if(null!=e&&"object"==typeof e){if(Array.isArray(e))return P(e)?e:void 0;if(null!=e){if("data"in e&&"object"==typeof e.data)return Array.isArray(e.data)&&P(e.data)?e.data:null!=e.data?[e.data]:void 0;if(!("isLoading"in e)&&!("error"in e))return[e]}}}(e);if(r){var n,o=null!=(t=e.schema)?t:(n={},r.forEach((function(e){e&&"object"==typeof e&&Array.from(Object.entries(e)).forEach((function(e){var t=e[0],r=e[1],o="string"==typeof r?"string":"boolean"==typeof r?"boolean":"number"==typeof r?"number":"unknown";n[t]=n[t]&&n[t]!==o?"unknown":o}))})),{id:"inferred",fields:Object.entries(n).map((function(e){return{id:e[0],type:e[1],readOnly:!1}}))});if(o)return{data:r,schema:o}}}},exports.useDependencyAwareQuery=function(e){var t,n,o=e.$queries,a=e.setDollarQueries,i=e.name,u=e.pageIndex,c=e.pageSize,l=b(function(e){try{return e()}catch(e){return}}(e.getDataOp),s({},!!u&&!!c&&{paginate:{pageIndex:u,pageSize:c}})),f=null!=i?i:"data",p=(t=f,n=r.useRef(void 0),r.useEffect((function(){return n.current=t,function(){n.current=void 0}})),n.current);r.useEffect((function(){if(!(f in o)||o[f]!==l){var e,t=s({},o,((e={})[f]=l,e));p&&f!==p&&p in o&&delete t[p],a(t)}}),[f,p,l,o,a])},exports.usePlasmicDataMutationOp=function(e){var t=null!=e?e:{},o=t.sourceId,a=t.opId,i=t.userArgs,u=n.usePlasmicDataSourceContext(),s=null==u?void 0:u.userAuthToken;return r.useCallback(c(f.mark((function e(){return f.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o&&a){e.next=2;break}return e.abrupt("return",void 0);case 2:return e.abrupt("return",d({sourceId:o,opId:a,userArgs:i},{userAuthToken:s||void 0,user:null==u?void 0:u.user}));case 3:case"end":return e.stop()}}),e)}))),[o,a,i,s])},exports.usePlasmicDataOp=b;
//# sourceMappingURL=data-sources.cjs.production.min.js.map

@@ -831,2 +831,18 @@ import { wrapLoadingFetcher, usePlasmicDataConfig, useMutablePlasmicQueryData } from '@plasmicapp/query';

}
var tuple = function tuple() {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return args;
};
function mkIdMap(xs) {
return new Map(xs.map(function (x) {
return tuple(x.id, x);
}));
}
function withoutNils(xs) {
return xs.filter(function (x) {
return x != null;
});
}

@@ -1064,3 +1080,130 @@ function makeCacheKey(dataOp, opts) {

export { Fetcher, FetcherMeta, executePlasmicDataOp, makeCacheKey, useDependencyAwareQuery, usePlasmicDataMutationOp, usePlasmicDataOp };
function normalizeData(rawData) {
var _rawData$schema;
if (!rawData) {
return undefined;
}
var dataArray = tryGetDataArray(rawData);
if (!dataArray) {
return undefined;
}
var schema = (_rawData$schema = rawData.schema) != null ? _rawData$schema : tryGetSchema(dataArray);
if (!schema) {
return undefined;
}
return {
data: dataArray,
schema: schema
};
}
function tryGetDataArray(rawData) {
if (rawData == null || typeof rawData !== 'object') {
return undefined;
}
if (Array.isArray(rawData)) {
if (isArrayOfObjects(rawData)) {
return rawData;
} else {
// TODO: array of primitives? Maybe we can wrap this?
return undefined;
}
}
if (rawData == null) {
return undefined;
}
if ('data' in rawData && typeof rawData.data === 'object') {
if (Array.isArray(rawData.data) && isArrayOfObjects(rawData.data)) {
return rawData.data;
} else if (rawData.data != null) {
return [rawData.data];
} else {
return undefined;
}
}
if ('isLoading' in rawData || 'error' in rawData) {
return undefined;
}
// Maybe a singleton record?
return [rawData];
}
function isArrayOfObjects(arr) {
return arr.every(function (x) {
return typeof x === 'object' && !Array.isArray(x);
});
}
function tryGetSchema(data) {
var fieldMap = {};
data.forEach(function (entry) {
if (entry && typeof entry === 'object') {
Array.from(Object.entries(entry)).forEach(function (_ref) {
var k = _ref[0],
v = _ref[1];
var inferredType = typeof v === 'string' ? 'string' : typeof v === 'boolean' ? 'boolean' : typeof v === 'number' ? 'number' : 'unknown';
if (fieldMap[k] && fieldMap[k] !== inferredType) {
fieldMap[k] = 'unknown';
} else {
fieldMap[k] = inferredType;
}
});
}
});
return {
id: 'inferred',
fields: Object.entries(fieldMap).map(function (_ref2) {
var f = _ref2[0],
t = _ref2[1];
return {
id: f,
type: t,
readOnly: false
};
})
};
}
var mkShortId = function mkShortId() {
return "" + Math.random();
};
function deriveFieldConfigs(specifiedFieldsPartial, schema, makeDefaultConfig) {
var _schema$fields;
var schemaFields = (_schema$fields = schema == null ? void 0 : schema.fields) != null ? _schema$fields : [];
var fieldById = mkIdMap(schemaFields);
var specifiedFieldIds = new Set(withoutNils(specifiedFieldsPartial.map(function (f) {
return f.fieldId;
})));
var keptSpecifiedFields = specifiedFieldsPartial.flatMap(function (f) {
if (!f.fieldId) {
return [_extends({
key: mkShortId()
}, makeDefaultConfig(undefined), f)];
}
var field = fieldById.get(f.fieldId);
// Drop configs with fieldIds no longer in the data.
if (!field) {
return [];
}
return [_extends({
key: mkShortId()
}, makeDefaultConfig(field), f)];
});
var newVirtualFields = schemaFields.filter(function (f) {
return !specifiedFieldIds.has(f.id);
}).map(function (f) {
return _extends({
key: mkShortId()
}, makeDefaultConfig(f));
});
var mergedFields = [].concat(keptSpecifiedFields, newVirtualFields);
var minimalFullLengthFields = [].concat(specifiedFieldsPartial, newVirtualFields.map(function (f) {
return {
key: f.key,
fieldId: f.fieldId
};
}));
return {
mergedFields: mergedFields,
minimalFullLengthFields: minimalFullLengthFields
};
}
export { Fetcher, FetcherMeta, deriveFieldConfigs, executePlasmicDataOp, makeCacheKey, normalizeData, useDependencyAwareQuery, usePlasmicDataMutationOp, usePlasmicDataOp };
//# sourceMappingURL=data-sources.esm.js.map

@@ -7,1 +7,3 @@ export { usePlasmicDataConfig } from '@plasmicapp/query';

export type { DataSourceSchema, ManyRowsResult, Pagination, SingleRowResult, TableFieldSchema, TableFieldType, TableSchema, } from './types';
export type { QueryResult, NormalizedData, BaseFieldConfig } from './helpers';
export { normalizeData, deriveFieldConfigs } from './helpers';

@@ -19,2 +19,3 @@ export interface Pagination {

readOnly: boolean;
primaryKey?: boolean;
}

@@ -21,0 +22,0 @@ export declare type TableFieldType = 'string' | 'boolean' | 'number' | 'date' | 'datetime' | 'unknown';

@@ -0,2 +1,31 @@

/// <reference types="react" />
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>;
declare type ReactElt = {
children: ReactElt | ReactElt[];
props: {
children: ReactElt | ReactElt[];
[prop: string]: any;
} | null;
type: React.ComponentType<any> | null;
key: string | null;
} | null;
export declare function traverseReactEltTree(children: React.ReactNode, callback: (elt: ReactElt) => void): void;
export declare function asArray<T>(x: T[] | T | undefined | null): T[];
export declare function ensureNumber(x: number | string): number;
export declare function ensure<T>(x: T | null | undefined): T;
export declare function isOneOf<T, U extends T>(elem: T, arr: readonly U[]): elem is U;
export declare function maybe<T, U>(x: T | undefined | null, f: (y: T) => U): U | undefined;
export declare function isLikeImage(value: unknown): false | RegExpMatchArray | null;
export declare function ensureArray<T>(xs: T | T[]): T[];
export declare const tuple: <T extends any[]>(...args: T) => T;
export interface HasId {
id: string;
}
export declare function mkIdMap<T extends HasId>(xs: ReadonlyArray<T>): Map<string, T>;
export declare const mkShortId: () => string;
export declare function withoutNils<T>(xs: Array<T | undefined | null>): T[];
export declare type Falsey = null | undefined | false | '' | 0 | 0n;
export declare type Truthy<T> = T extends Falsey ? never : T;
export declare function withoutFalsey<T>(xs: Array<T | Falsey>): T[];
export {};
{
"version": "0.1.95",
"version": "0.1.96",
"license": "MIT",

@@ -61,3 +61,3 @@ "main": "dist/index.js",

"@plasmicapp/data-sources-context": "0.1.11",
"@plasmicapp/host": "1.0.150",
"@plasmicapp/host": "1.0.151",
"@plasmicapp/isomorphic-unfetch": "^1.0.1",

@@ -70,3 +70,3 @@ "@plasmicapp/query": "0.1.67",

},
"gitHead": "d933fd1793c7b2d01af2400582593724ec364085"
"gitHead": "35d4595c6d82b47128fdb0c536fab54d7bbc609f"
}

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