@theconcurrent/resource
Advanced tools
Comparing version 0.0.18 to 0.0.19
@@ -1,7 +0,7 @@ | ||
(function(y,d){typeof exports=="object"&&typeof module!="undefined"?d(exports,require("@theconcurrent/query"),require("@theconcurrent/utility"),require("graphql")):typeof define=="function"&&define.amd?define(["exports","@theconcurrent/query","@theconcurrent/utility","graphql"],d):(y=typeof globalThis!="undefined"?globalThis:y||self,d(y["@theconcurrent/resource"]={},y.query,y.utility,y.graphql))})(this,function(y,d,p,l){"use strict";function P(t,n,i,a){var o;if(!t)return;const e=n?(o=p.getField(t,n))==null?void 0:o.fields:t.fields;return{fields:(i&&e?p.sortDataByOrder(e,i,"name"):e||[]).map(f=>a?a.find(s=>s.name===f.name)?{...f,isSortable:!0}:{...f}:f)}}var w=function(){return w=Object.assign||function(n){for(var i,a=1,e=arguments.length;a<e;a++){i=arguments[a];for(var r in i)Object.prototype.hasOwnProperty.call(i,r)&&(n[r]=i[r])}return n},w.apply(this,arguments)};typeof SuppressedError=="function"&&SuppressedError;var j=new Map,k=new Map,x=!0,Q=!1;function S(t){return t.replace(/[\s,]+/g," ").trim()}function B(t){return S(t.source.body.substring(t.start,t.end))}function z(t){var n=new Set,i=[];return t.definitions.forEach(function(a){if(a.kind==="FragmentDefinition"){var e=a.name.value,r=B(a.loc),o=k.get(e);o&&!o.has(r)?x&&console.warn("Warning: fragment with name "+e+` already exists. | ||
(function(h,y){typeof exports=="object"&&typeof module!="undefined"?y(exports,require("@theconcurrent/query"),require("@theconcurrent/utility"),require("graphql")):typeof define=="function"&&define.amd?define(["exports","@theconcurrent/query","@theconcurrent/utility","graphql"],y):(h=typeof globalThis!="undefined"?globalThis:h||self,y(h["@theconcurrent/resource"]={},h.query,h.utility,h.graphql))})(this,function(h,y,d,l){"use strict";function $(n,t,i,a){var o;if(!n)return;const e=t?(o=d.getField(n,t))==null?void 0:o.fields:n.fields;return{fields:(i&&e?d.sortDataByOrder(e,i,"name"):e||[]).map(s=>a?a.find(f=>f.name===s.name)?{...s,isSortable:!0}:{...s}:s)}}var Q=function(){return Q=Object.assign||function(t){for(var i,a=1,e=arguments.length;a<e;a++){i=arguments[a];for(var r in i)Object.prototype.hasOwnProperty.call(i,r)&&(t[r]=i[r])}return t},Q.apply(this,arguments)};typeof SuppressedError=="function"&&SuppressedError;var O=new Map,R=new Map,x=!0,P=!1;function S(n){return n.replace(/[\s,]+/g," ").trim()}function W(n){return S(n.source.body.substring(n.start,n.end))}function z(n){var t=new Set,i=[];return n.definitions.forEach(function(a){if(a.kind==="FragmentDefinition"){var e=a.name.value,r=W(a.loc),o=R.get(e);o&&!o.has(r)?x&&console.warn("Warning: fragment with name "+e+` already exists. | ||
graphql-tag enforces all fragment names across your application to be unique; read more about | ||
this in the docs: http://dev.apollodata.com/core/fragments.html#unique-names`):o||k.set(e,o=new Set),o.add(r),n.has(r)||(n.add(r),i.push(a))}else i.push(a)}),w(w({},t),{definitions:i})}function A(t){var n=new Set(t.definitions);n.forEach(function(a){a.loc&&delete a.loc,Object.keys(a).forEach(function(e){var r=a[e];r&&typeof r=="object"&&n.add(r)})});var i=t.loc;return i&&(delete i.startToken,delete i.endToken),t}function G(t){var n=S(t);if(!j.has(n)){var i=l.parse(t,{experimentalFragmentVariables:Q,allowLegacyFragmentVariables:Q});if(!i||i.kind!=="Document")throw new Error("Not a valid GraphQL document.");j.set(n,A(z(i)))}return j.get(n)}function v(t){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];typeof t=="string"&&(t=[t]);var a=t[0];return n.forEach(function(e,r){e&&e.kind==="Document"?a+=e.loc.source.body:a+=e,a+=t[r+1]}),G(a)}function L(){j.clear(),k.clear()}function H(){x=!1}function J(){Q=!0}function X(){Q=!1}var E={gql:v,resetCaches:L,disableFragmentWarnings:H,enableExperimentalFragmentVariables:J,disableExperimentalFragmentVariables:X};(function(t){t.gql=E.gql,t.resetCaches=E.resetCaches,t.disableFragmentWarnings=E.disableFragmentWarnings,t.enableExperimentalFragmentVariables=E.enableExperimentalFragmentVariables,t.disableExperimentalFragmentVariables=E.disableExperimentalFragmentVariables})(v||(v={})),v.default=v;function b(t,n,i,a){if(n.queries.find(o=>o.name===i))return n.queries;const r=`${a(t,n.path)}`;try{const o=v` | ||
this in the docs: http://dev.apollodata.com/core/fragments.html#unique-names`):o||R.set(e,o=new Set),o.add(r),t.has(r)||(t.add(r),i.push(a))}else i.push(a)}),Q(Q({},n),{definitions:i})}function A(n){var t=new Set(n.definitions);t.forEach(function(a){a.loc&&delete a.loc,Object.keys(a).forEach(function(e){var r=a[e];r&&typeof r=="object"&&t.add(r)})});var i=n.loc;return i&&(delete i.startToken,delete i.endToken),n}function G(n){var t=S(n);if(!O.has(t)){var i=l.parse(n,{experimentalFragmentVariables:P,allowLegacyFragmentVariables:P});if(!i||i.kind!=="Document")throw new Error("Not a valid GraphQL document.");O.set(t,A(z(i)))}return O.get(t)}function b(n){for(var t=[],i=1;i<arguments.length;i++)t[i-1]=arguments[i];typeof n=="string"&&(n=[n]);var a=n[0];return t.forEach(function(e,r){e&&e.kind==="Document"?a+=e.loc.source.body:a+=e,a+=n[r+1]}),G(a)}function L(){O.clear(),R.clear()}function H(){x=!1}function J(){P=!0}function X(){P=!1}var E={gql:b,resetCaches:L,disableFragmentWarnings:H,enableExperimentalFragmentVariables:J,disableExperimentalFragmentVariables:X};(function(n){n.gql=E.gql,n.resetCaches=E.resetCaches,n.disableFragmentWarnings=E.disableFragmentWarnings,n.enableExperimentalFragmentVariables=E.enableExperimentalFragmentVariables,n.disableExperimentalFragmentVariables=E.disableExperimentalFragmentVariables})(b||(b={})),b.default=b;function N(n,t,i,a){if(t.queries.find(o=>o.name===i))return t.queries;const r=`${a(n,t.path)}`;try{const o=b` | ||
${r} | ||
`;return[...n.queries,{name:i,gql:o}]}catch(o){throw console.error(o,n,i),console.error(r.replace(/\\n/g,` | ||
`)),new Error(`Failed to create query for ${i}`)}}function F(t,n){if(t)return t.queries.find(i=>i.name===n)}function Y(t){return l.isEnumType(t.type)||l.isNonNullType(t.type)&&l.isEnumType(t.type.ofType)}function Z(t){return l.isListType(t.type)||l.isNonNullType(t.type)&&l.isListType(t.type.ofType)}function K(t){return!!(l.isScalarType(t.type)||l.isNonNullType(t.type)&&(l.isScalarType(t.type.ofType)||l.isListType(t.type.ofType)&&(l.isScalarType(t.type.ofType.ofType)||l.isNonNullType(t.type.ofType.ofType)&&l.isScalarType(t.type.ofType.ofType.ofType))))}function _(t,n){return t?"Scalar":n?"Enum":"Object"}function C(t,n){var a,e,r;if(!n||!n.fields)throw new Error(`Parent entity not found: ${t}`);const i=n.fields.find(o=>o.name===t);return(r=(e=(a=i==null?void 0:i.directives)==null?void 0:a.find(o=>o.name==="label"))==null?void 0:e.args)==null?void 0:r.name}function U(t){if(t&&t.kind==="Enum")return t.enumValues}function D(t,n,i){var c,h;const a=Z(t),e=l.isNonNullType(t.type),r=l.getNamedType(t.type).toString(),o=Y(t),f=K(t),s=p.getEntityByName(n,r),u=p.getEntityByName(n,i),m=C(t.name,u),g=U(s);return{name:t.name,isList:a,isNonNull:e,typeName:r,isScalar:f,isEnum:o,kind:_(f,o),description:t.description,schemaDirectives:s==null?void 0:s.directives,label:m,enumValues:g,collection:(h=(c=s==null?void 0:s.directives)==null?void 0:c.find(O=>O.name==="collection"))==null?void 0:h.args,isUnion:(s==null?void 0:s.kind)==="Union"}}function nn(t,n,i,a){const e=D(t,i,a);return e.isScalar||e.isEnum?e:{...e,fields:[]}}function tn(t,n){const i=p.getEntityByName(n,t.name.value);if(!i)throw new Error("entity type not found");return i}function $(t,n){switch(t.kind){case"NamedType":return{variable:tn(t,n),isNonNull:!1,isList:!1};case"NonNullType":return{...$(t.type,n),isNonNull:!0};case"ListType":return{...$(t.type,n),isList:!0};default:throw new Error("extractType error")}}function en(t,n){return{...$(t.type,n),name:t.variable.name.value}}function V(t,n,i=0){var e;if(i>=n.length)return t;const a={...t};return a.fields=(e=t.fields)==null?void 0:e.map(r=>r.fields?{...r,representativeField:r.fields.find(o=>o.name===n.find(f=>{var s;return(s=r.fields)==null?void 0:s.find(u=>u.name===f)})),fields:V(r,n,i+1).fields}:r),a}function R(t,n,i,a){const e=new l.TypeInfo(t);let r=null;const o=[],f=[],s={VariableDefinition:{enter(u){f.push(en(u,i))}},Field:{enter(u){var h,O,W;const m=e.getParentType();if(!m)throw new Error("Parent type not found");const g=e.getFieldDef();if(!g)throw new Error("Field definition not found");const c=nn(g,u,i,m.name);if(m.toString()===((h=t.getQueryType())==null?void 0:h.name)||m.toString()===((O=t.getMutationType())==null?void 0:O.name)){r=c,o.push(c);return}r&&((W=o[o.length-1].fields)==null||W.push(c),!c.isScalar&&!c.isEnum&&o.push(c))},leave(u){o.length>1&&u.selectionSet&&o.pop()}}};if(l.visit(n,l.visitWithTypeInfo(e,s)),!r)throw new Error("Couldn't find query object");return{queryObject:V(r,a),variableDefinitionObjects:f}}function an(t,n,i,a){const{queryObject:e,variableDefinitionObjects:r}=R(t,n,i,a);if(!e)throw new Error("Query object not generated");return{structure:e,variableDefinitionObjects:r}}function rn(t,n,i,a){const{queryObject:e,variableDefinitionObjects:r}=R(t,n,i,a);if(!e)throw new Error("Query object not generated");return{structure:e,variablesStructure:r}}function M(t,n){return rn(t.graphqlSchema,n,t.simplifiedEntities,t.config.nodeRepresentatives)}function I(t,n){return an(t.graphqlSchema,n,t.simplifiedEntities,t.config.nodeRepresentatives)}function N(t,n,i,a){var r,o;if(!n)return;if(a&&i)return{...n,responseDataPath:{data:`${i}.nodes`,total:`${i}.totalCount`}};if(i)return{...n,responseDataPath:{data:`${i}`}};const e=(o=(r=n.queries)==null?void 0:r.find(f=>f.name==="main"))==null?void 0:o.gql;if(!e)throw new Error("Can't find gql");return{...n,responseDataPath:{data:`${e.definitions[0].name.value}.${p.lowercaseFirstLetter(t)}`}}}function on(t){var n,i;return((i=(n=t==null?void 0:t.find(a=>a.name==="label"))==null?void 0:n.args)==null?void 0:i.name)||void 0}function T(t){if(t)return l.print(t)}function q(){return[]}function fn(t,n,i,a,e){if(!n)return;const r=T(e==null?void 0:e.gql),f=t.filter(m=>m.kind==="Object").find(m=>{var c;const g=(c=m.directives)==null?void 0:c.find(h=>h.name==="collection");return g?g.args.typeName===i.typeName:!1});if(!f)return;const s=p.generatePath(t,n.typeName,f.typeName,a),u=(e==null?void 0:e.queries)||q();if(s)return{path:s,...e||{},query:r,queries:u};if(e!=null&&e.path)return{...e,path:e.path,queries:u}}function sn(t,n,i,a,e){if(!n)return;const r=T(e==null?void 0:e.gql),o=p.generatePath(t,n.typeName,i.typeName,a),f=(e==null?void 0:e.queries)||q();if(o)return{path:o,...e||{},query:r,queries:f};if(e!=null&&e.path)return{...e,path:e.path,queries:f}}function un(t,n,i,a,e){if(!e||!n)return;const r=T(e==null?void 0:e.gql),o=p.generatePath(t,n.typeName,i.typeName,a),f=o==null?void 0:o.split(".").pop(),s=`${f}Create.${f}`,u=(e==null?void 0:e.queries)||q();if(s)return{path:s,...e||{},query:r,queries:u};if(e!=null&&e.path)return{...e,path:e.path,queries:u}}function ln(t,n,i,a,e){if(!e||!n)return;const r=T(e==null?void 0:e.gql),o=p.generatePath(t,n.typeName,i.typeName,a),f=o==null?void 0:o.split(".").pop(),s=`${f}Update.${f}`,u=(e==null?void 0:e.queries)||q();if(s)return{path:s,...e||{},query:r,queries:u};if(e!=null&&e.path)return{...e,path:e.path,queries:u}}function pn(t,n,i,a,e){if(!e||!n)return;const r=T(e==null?void 0:e.gql),o=p.generatePath(t,n.typeName,i.typeName,a),f=o==null?void 0:o.split(".").pop(),s=`${f}Delete.${f}`,u=(e==null?void 0:e.queries)||q();if(s)return{path:s,...e||{},query:r,queries:u};if(e!=null&&e.path)return{...e,path:e.path,queries:u}}function cn(t,n){var r,o;const i=n.config.adminPath?`${n.config.adminPath}.`:"",a=p.findEntityFromPath(n.simplifiedEntities,"Query",((r=n.config.adminPath)==null?void 0:r.split("."))||[]),e=(o=n.config.resources)==null?void 0:o.find(f=>f.name===t.typeName);return{label:on(t.directives),name:t.typeName,typeName:t.typeName,skipMenu:e==null?void 0:e.skipMenu,list:fn(n.simplifiedEntities,a,t,i,e==null?void 0:e.list),show:sn(n.simplifiedEntities,a,t,i,e==null?void 0:e.show),create:un(n.simplifiedEntities,a,t,i,e==null?void 0:e.create),update:ln(n.simplifiedEntities,a,t,i,e==null?void 0:e.update),delete:pn(n.simplifiedEntities,a,t,i,e==null?void 0:e.delete)}}function dn(t){var a;const n=t.simplifiedEntities.filter(e=>{var r;return(r=e.directives)==null?void 0:r.find(o=>o.name==="model")}).map(e=>cn(e,t)),i=((a=t.config.resources)==null?void 0:a.map(e=>e.name))||n.map(e=>e.name);return p.sortDataByOrder(n,i,"name")}function mn(t,n){var a,e,r,o,f;const i="main";return{...n,create:(a=n.create)!=null&&a.path?{...n.create,queries:b(t,n.create,i,d.createQueryForCreate)}:n.create,update:(e=n.update)!=null&&e.path?{...n.update,queries:b(t,n.update,i,d.createQueryForUpdate)}:n.update,delete:(r=n.delete)!=null&&r.path?{...n.delete,queries:b(t,n.delete,i,d.createQueryForDelete)}:n.delete,show:(o=n.show)!=null&&o.path?{...n.show,queries:b(t,n.show,i,d.createQueryForShow)}:n.show,list:(f=n.list)!=null&&f.path?{...n.list,queries:b(t,n.list,i,d.createQueryForList)}:n.list}}function yn(t,n){var a;const i=F(n.list,"minimum");return{...n,list:(a=n.list)!=null&&a.path&&!i?{...n.list,queries:b(t,n.list,"minimum",d.createMinimumQueryForList)}:n.list}}function gn(t,n){const i="main",a=F(n.create,i),e=F(n.update,i),r=F(n.show,i),o=F(n.list,i);return{...n,create:a?{...n.create,...I(t,a.gql)}:n.create,update:e?{...n.update,...I(t,e.gql)}:n.update,show:r?{...n.show,...M(t,r.gql)}:n.show,list:o?{...n.list,...M(t,o.gql)}:n.list}}function hn({config:{nodeRepresentatives:t}},n){var e,r,o,f;const{show:i,list:a}=n;return{...n,show:i&&{...i,...P(i.structure,i.path,t)},list:a&&{...a,...P(a.structure,`${a.path}.nodes`,a==null?void 0:a.orderColumn,(f=(o=(r=(e=a==null?void 0:a.variablesStructure.find(s=>s.name==="sort"))==null?void 0:e.inputFields)==null?void 0:r.find(s=>s.typeName!=="BaseSortOrder"))==null?void 0:o.enumValues)==null?void 0:f.map(s=>({name:s.name})))}}}function vn(t,n){var i,a;return{...n,create:N(n.name,n.create),update:N(n.name,n.update),delete:N(n.name,n.delete),show:N(n.name,n.show,(i=n.show)==null?void 0:i.path),list:N(n.name,n.list,(a=n.list)==null?void 0:a.path,!0)}}function bn(t){return dn(t).map(n=>mn(t,n)).map(n=>yn(t,n)).map(n=>gn(t,n)).map(n=>hn(t,n)).map(n=>vn(t,n))}y.convert=bn,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})}); | ||
`;return[...t.queries,{name:i,gql:o}]}catch(o){throw console.error(o,t,i),console.error(r.replace(/\\n/g,` | ||
`)),new Error(`Failed to create query for ${i}`)}}function F(n,t){if(n)return n.queries.find(i=>i.name===t)}function Y(n){return l.isEnumType(n.type)||l.isNonNullType(n.type)&&l.isEnumType(n.type.ofType)}function Z(n){return l.isListType(n.type)||l.isNonNullType(n.type)&&l.isListType(n.type.ofType)}function K(n){return!!(l.isScalarType(n.type)||l.isNonNullType(n.type)&&(l.isScalarType(n.type.ofType)||l.isListType(n.type.ofType)&&(l.isScalarType(n.type.ofType.ofType)||l.isNonNullType(n.type.ofType.ofType)&&l.isScalarType(n.type.ofType.ofType.ofType))))}function _(n,t){return n?"Scalar":t?"Enum":"Object"}function C(n,t){var a,e,r;if(!t||!t.fields)throw new Error(`Parent entity not found: ${n}`);const i=t.fields.find(o=>o.name===n);return(r=(e=(a=i==null?void 0:i.directives)==null?void 0:a.find(o=>o.name==="label"))==null?void 0:e.args)==null?void 0:r.name}function U(n){if(n&&n.kind==="Enum")return n.enumValues}function D(n,t,i){var m,g;const a=Z(n),e=l.isNonNullType(n.type),r=l.getNamedType(n.type).toString(),o=Y(n),s=K(n),f=d.getEntityByName(t,r),u=d.getEntityByName(t,i),c=C(n.name,u),p=U(f);return{name:n.name,isList:a,isNonNull:e,typeName:r,isScalar:s,isEnum:o,kind:_(s,o),description:n.description,schemaDirectives:f==null?void 0:f.directives,label:c,enumValues:p,collection:(g=(m=f==null?void 0:f.directives)==null?void 0:m.find(j=>j.name==="collection"))==null?void 0:g.args,isUnion:(f==null?void 0:f.kind)==="Union"}}function nn(n,t,i,a){const e=D(n,i,a);return e.isScalar||e.isEnum?e:{...e,fields:[]}}function tn(n,t){const i=d.getEntityByName(t,n.name.value);if(!i)throw new Error("entity type not found");return i}function k(n,t){switch(n.kind){case"NamedType":return{variable:tn(n,t),isNonNull:!1,isList:!1};case"NonNullType":return{...k(n.type,t),isNonNull:!0};case"ListType":return{...k(n.type,t),isList:!0};default:throw new Error("extractType error")}}function en(n,t){return{...k(n.type,t),name:n.variable.name.value}}function V(n,t,i=0){var e;if(i>=t.length)return n;const a={...n};return a.fields=(e=n.fields)==null?void 0:e.map(r=>r.fields?{...r,representativeField:r.fields.find(o=>o.name===t.find(s=>{var f;return(f=r.fields)==null?void 0:f.find(u=>u.name===s)})),fields:V(r,t,i+1).fields}:r),a}function M(n,t,i,a){const e=new l.TypeInfo(n);let r=null;const o=[],s=[],f={VariableDefinition:{enter(u){s.push(en(u,i))}},Field:{enter(u){var g,j,v;const c=e.getParentType();if(!c)throw new Error("Parent type not found");const p=e.getFieldDef();if(!p)throw new Error("Field definition not found");const m=nn(p,u,i,c.name);if(c.toString()===((g=n.getQueryType())==null?void 0:g.name)||c.toString()===((j=n.getMutationType())==null?void 0:j.name)){r=m,o.push(m);return}r&&((v=o[o.length-1].fields)==null||v.push(m),!m.isScalar&&!m.isEnum&&o.push(m))},leave(u){o.length>1&&u.selectionSet&&o.pop()}}};if(l.visit(t,l.visitWithTypeInfo(e,f)),!r)throw new Error("Couldn't find query object");return{queryObject:V(r,a),variableDefinitionObjects:s}}function an(n,t,i,a){const{queryObject:e,variableDefinitionObjects:r}=M(n,t,i,a);if(!e)throw new Error("Query object not generated");return{structure:e,variableDefinitionObjects:r}}function rn(n,t,i,a){const{queryObject:e,variableDefinitionObjects:r}=M(n,t,i,a);if(!e)throw new Error("Query object not generated");return{structure:e,variablesStructure:r}}function B(n,t){return rn(n.graphqlSchema,t,n.simplifiedEntities,n.config.nodeRepresentatives)}function I(n,t){return an(n.graphqlSchema,t,n.simplifiedEntities,n.config.nodeRepresentatives)}function q(n,t,i,a){var r,o;if(!t)return;if(a&&i)return{...t,responseDataPath:{data:`${i}.nodes`,total:`${i}.totalCount`}};if(i)return{...t,responseDataPath:{data:`${i}`}};const e=(o=(r=t.queries)==null?void 0:r.find(s=>s.name==="main"))==null?void 0:o.gql;if(!e)throw new Error("Can't find gql");return{...t,responseDataPath:{data:`${e.definitions[0].name.value}.${d.lowercaseFirstLetter(n)}`}}}function on(n){var t,i;return((i=(t=n==null?void 0:n.find(a=>a.name==="label"))==null?void 0:t.args)==null?void 0:i.name)||void 0}function T(n){if(n)return l.print(n)}function w(){return[]}function sn(n,t,i,a,e){if(!t)return;const r=T(e==null?void 0:e.gql),s=n.filter(c=>c.kind==="Object").find(c=>{var m;const p=(m=c.directives)==null?void 0:m.find(g=>g.name==="collection");return p?p.args.typeName===i.typeName:!1});if(!s)return;const f=d.generatePath(n,t.typeName,s.typeName,a),u=(e==null?void 0:e.queries)||w();if(f)return{path:f,...e||{},query:r,queries:u};if(e!=null&&e.path)return{...e,path:e.path,queries:u}}function fn(n,t,i,a,e){if(!t)return;const r=T(e==null?void 0:e.gql),o=d.generatePath(n,t.typeName,i.typeName,a),s=(e==null?void 0:e.queries)||w();if(o)return{path:o,...e||{},query:r,queries:s};if(e!=null&&e.path)return{...e,path:e.path,queries:s}}function un(n,t,i,a,e){if(!e||!t)return;const r=T(e==null?void 0:e.gql),o=d.generatePath(n,t.typeName,i.typeName,a),s=o==null?void 0:o.split(".").pop(),f=`${s}Create.${s}`,u=(e==null?void 0:e.queries)||w();if(f)return{path:f,...e||{},query:r,queries:u};if(e!=null&&e.path)return{...e,path:e.path,queries:u}}function ln(n,t,i,a,e){if(!e||!t)return;const r=T(e==null?void 0:e.gql),o=d.generatePath(n,t.typeName,i.typeName,a),s=o==null?void 0:o.split(".").pop(),f=`${s}Update.${s}`,u=(e==null?void 0:e.queries)||w();if(f)return{path:f,...e||{},query:r,queries:u};if(e!=null&&e.path)return{...e,path:e.path,queries:u}}function pn(n,t,i,a,e){if(!e||!t)return;const r=T(e==null?void 0:e.gql),o=d.generatePath(n,t.typeName,i.typeName,a),s=o==null?void 0:o.split(".").pop(),f=`${s}Delete.${s}`,u=(e==null?void 0:e.queries)||w();if(f)return{path:f,...e||{},query:r,queries:u};if(e!=null&&e.path)return{...e,path:e.path,queries:u}}function cn(n,t){var f,u;const{simplifiedEntities:i,config:a}=t,e=a.adminPath?`${a.adminPath}.`:"",r=i.find(c=>{var p;return(p=c.directives)==null?void 0:p.find(m=>m.name==="queryRoot")}),o=d.findEntityFromPath(i,r.typeName,((f=a.adminPath)==null?void 0:f.split("."))||[]),s=(u=a.resources)==null?void 0:u.find(c=>c.name===n.typeName);return{label:on(n.directives),name:n.typeName,typeName:n.typeName,skipMenu:s==null?void 0:s.skipMenu,list:sn(i,o,n,e,s==null?void 0:s.list),show:fn(i,o,n,e,s==null?void 0:s.show),create:un(i,o,n,e,s==null?void 0:s.create),update:ln(i,o,n,e,s==null?void 0:s.update),delete:pn(i,o,n,e,s==null?void 0:s.delete)}}function mn(n){var s,f,u,c;const{simplifiedEntities:t,config:i}=n,a=d.findEntityByDirectiveName(t,"queryRoot");if(!a)throw new Error("queryRoot not found");const e=(u=(f=(s=a.directives)==null?void 0:s.find(p=>p.name==="queryRoot"))==null?void 0:f.args)==null?void 0:u.adminPaths;if(!e)throw new Error("adminPaths not found");const r=e.map(p=>{const m=p===""?a:d.findEntityFromPath(t,"Query",p.split("."));if(!m)throw new Error("adminEntity not found");const g=m.fields.map(v=>v.typeName);return d.filterEntitiesByDirectiveName(t,"model").filter(v=>g.includes(v.typeName)).map(v=>cn(v,n))}).flat(),o=((c=i.resources)==null?void 0:c.map(p=>p.name))||r.map(p=>p.name);return d.sortDataByOrder(r,o,"name")}function dn(n,t){var a,e,r,o,s;const i="main";return{...t,create:(a=t.create)!=null&&a.path?{...t.create,queries:N(n,t.create,i,y.createQueryForCreate)}:t.create,update:(e=t.update)!=null&&e.path?{...t.update,queries:N(n,t.update,i,y.createQueryForUpdate)}:t.update,delete:(r=t.delete)!=null&&r.path?{...t.delete,queries:N(n,t.delete,i,y.createQueryForDelete)}:t.delete,show:(o=t.show)!=null&&o.path?{...t.show,queries:N(n,t.show,i,y.createQueryForShow)}:t.show,list:(s=t.list)!=null&&s.path?{...t.list,queries:N(n,t.list,i,y.createQueryForList)}:t.list}}function yn(n,t){var a;const i=F(t.list,"minimum");return{...t,list:(a=t.list)!=null&&a.path&&!i?{...t.list,queries:N(n,t.list,"minimum",y.createMinimumQueryForList)}:t.list}}function hn(n,t){const i="main",a=F(t.create,i),e=F(t.update,i),r=F(t.show,i),o=F(t.list,i);return{...t,create:a?{...t.create,...I(n,a.gql)}:t.create,update:e?{...t.update,...I(n,e.gql)}:t.update,show:r?{...t.show,...B(n,r.gql)}:t.show,list:o?{...t.list,...B(n,o.gql)}:t.list}}function gn({config:{nodeRepresentatives:n}},t){var e,r,o,s;const{show:i,list:a}=t;return{...t,show:i&&{...i,...$(i.structure,i.path,n)},list:a&&{...a,...$(a.structure,`${a.path}.nodes`,a==null?void 0:a.orderColumn,(s=(o=(r=(e=a==null?void 0:a.variablesStructure.find(f=>f.name==="sort"))==null?void 0:e.inputFields)==null?void 0:r.find(f=>f.typeName!=="BaseSortOrder"))==null?void 0:o.enumValues)==null?void 0:s.map(f=>({name:f.name})))}}}function vn(n,t){var i,a;return{...t,create:q(t.name,t.create),update:q(t.name,t.update),delete:q(t.name,t.delete),show:q(t.name,t.show,(i=t.show)==null?void 0:i.path),list:q(t.name,t.list,(a=t.list)==null?void 0:a.path,!0)}}function bn(n){return mn(n).map(t=>dn(n,t)).map(t=>yn(n,t)).map(t=>hn(n,t)).map(t=>gn(n,t)).map(t=>vn(n,t))}h.convert=bn,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}); | ||
//# sourceMappingURL=index.umd.js.map |
@@ -1,108 +0,108 @@ | ||
import { createQueryForCreate as G, createQueryForUpdate as H, createQueryForDelete as J, createQueryForShow as X, createQueryForList as Y, createMinimumQueryForList as Z } from "@theconcurrent/query"; | ||
import { getField as L, sortDataByOrder as I, getEntityByName as O, lowercaseFirstLetter as K, findEntityFromPath as _, generatePath as q } from "@theconcurrent/utility"; | ||
import { parse as C, isEnumType as P, isNonNullType as b, isListType as k, isScalarType as N, TypeInfo as U, visit as D, visitWithTypeInfo as tt, getNamedType as nt, print as et } from "graphql"; | ||
function R(n, t, i, a) { | ||
import { createQueryForCreate as H, createQueryForUpdate as J, createQueryForDelete as X, createQueryForShow as Y, createQueryForList as Z, createMinimumQueryForList as L } from "@theconcurrent/query"; | ||
import { getField as K, sortDataByOrder as I, getEntityByName as R, lowercaseFirstLetter as _, findEntityFromPath as W, generatePath as F, findEntityByDirectiveName as C, filterEntitiesByDirectiveName as U } from "@theconcurrent/utility"; | ||
import { parse as D, isEnumType as V, isNonNullType as E, isListType as k, isScalarType as T, TypeInfo as tt, visit as nt, visitWithTypeInfo as et, getNamedType as it, print as at } from "graphql"; | ||
function P(t, n, i, a) { | ||
var o; | ||
if (!n) | ||
if (!t) | ||
return; | ||
const e = t ? (o = L(n, t)) == null ? void 0 : o.fields : n.fields; | ||
const e = n ? (o = K(t, n)) == null ? void 0 : o.fields : t.fields; | ||
return { | ||
fields: (i && e ? I(e, i, "name") : e || []).map((f) => a ? a.find((l) => l.name === f.name) ? { ...f, isSortable: !0 } : { ...f } : f) | ||
fields: (i && e ? I(e, i, "name") : e || []).map((f) => a ? a.find((s) => s.name === f.name) ? { ...f, isSortable: !0 } : { ...f } : f) | ||
}; | ||
} | ||
var Q = function() { | ||
return Q = Object.assign || function(t) { | ||
var j = function() { | ||
return j = Object.assign || function(n) { | ||
for (var i, a = 1, e = arguments.length; a < e; a++) { | ||
i = arguments[a]; | ||
for (var r in i) | ||
Object.prototype.hasOwnProperty.call(i, r) && (t[r] = i[r]); | ||
Object.prototype.hasOwnProperty.call(i, r) && (n[r] = i[r]); | ||
} | ||
return t; | ||
}, Q.apply(this, arguments); | ||
return n; | ||
}, j.apply(this, arguments); | ||
}; | ||
var T = /* @__PURE__ */ new Map(), $ = /* @__PURE__ */ new Map(), W = !0, j = !1; | ||
function B(n) { | ||
return n.replace(/[\s,]+/g, " ").trim(); | ||
var Q = /* @__PURE__ */ new Map(), $ = /* @__PURE__ */ new Map(), B = !0, O = !1; | ||
function z(t) { | ||
return t.replace(/[\s,]+/g, " ").trim(); | ||
} | ||
function it(n) { | ||
return B(n.source.body.substring(n.start, n.end)); | ||
function rt(t) { | ||
return z(t.source.body.substring(t.start, t.end)); | ||
} | ||
function at(n) { | ||
var t = /* @__PURE__ */ new Set(), i = []; | ||
return n.definitions.forEach(function(a) { | ||
function ot(t) { | ||
var n = /* @__PURE__ */ new Set(), i = []; | ||
return t.definitions.forEach(function(a) { | ||
if (a.kind === "FragmentDefinition") { | ||
var e = a.name.value, r = it(a.loc), o = $.get(e); | ||
o && !o.has(r) ? W && console.warn("Warning: fragment with name " + e + ` already exists. | ||
var e = a.name.value, r = rt(a.loc), o = $.get(e); | ||
o && !o.has(r) ? B && console.warn("Warning: fragment with name " + e + ` already exists. | ||
graphql-tag enforces all fragment names across your application to be unique; read more about | ||
this in the docs: http://dev.apollodata.com/core/fragments.html#unique-names`) : o || $.set(e, o = /* @__PURE__ */ new Set()), o.add(r), t.has(r) || (t.add(r), i.push(a)); | ||
this in the docs: http://dev.apollodata.com/core/fragments.html#unique-names`) : o || $.set(e, o = /* @__PURE__ */ new Set()), o.add(r), n.has(r) || (n.add(r), i.push(a)); | ||
} else | ||
i.push(a); | ||
}), Q(Q({}, n), { definitions: i }); | ||
}), j(j({}, t), { definitions: i }); | ||
} | ||
function rt(n) { | ||
var t = new Set(n.definitions); | ||
t.forEach(function(a) { | ||
function ft(t) { | ||
var n = new Set(t.definitions); | ||
n.forEach(function(a) { | ||
a.loc && delete a.loc, Object.keys(a).forEach(function(e) { | ||
var r = a[e]; | ||
r && typeof r == "object" && t.add(r); | ||
r && typeof r == "object" && n.add(r); | ||
}); | ||
}); | ||
var i = n.loc; | ||
return i && (delete i.startToken, delete i.endToken), n; | ||
var i = t.loc; | ||
return i && (delete i.startToken, delete i.endToken), t; | ||
} | ||
function ot(n) { | ||
var t = B(n); | ||
if (!T.has(t)) { | ||
var i = C(n, { | ||
experimentalFragmentVariables: j, | ||
allowLegacyFragmentVariables: j | ||
function st(t) { | ||
var n = z(t); | ||
if (!Q.has(n)) { | ||
var i = D(t, { | ||
experimentalFragmentVariables: O, | ||
allowLegacyFragmentVariables: O | ||
}); | ||
if (!i || i.kind !== "Document") | ||
throw new Error("Not a valid GraphQL document."); | ||
T.set(t, rt(at(i))); | ||
Q.set(n, ft(ot(i))); | ||
} | ||
return T.get(t); | ||
return Q.get(n); | ||
} | ||
function y(n) { | ||
for (var t = [], i = 1; i < arguments.length; i++) | ||
t[i - 1] = arguments[i]; | ||
typeof n == "string" && (n = [n]); | ||
var a = n[0]; | ||
return t.forEach(function(e, r) { | ||
e && e.kind === "Document" ? a += e.loc.source.body : a += e, a += n[r + 1]; | ||
}), ot(a); | ||
function g(t) { | ||
for (var n = [], i = 1; i < arguments.length; i++) | ||
n[i - 1] = arguments[i]; | ||
typeof t == "string" && (t = [t]); | ||
var a = t[0]; | ||
return n.forEach(function(e, r) { | ||
e && e.kind === "Document" ? a += e.loc.source.body : a += e, a += t[r + 1]; | ||
}), st(a); | ||
} | ||
function ft() { | ||
T.clear(), $.clear(); | ||
function ut() { | ||
Q.clear(), $.clear(); | ||
} | ||
function lt() { | ||
W = !1; | ||
B = !1; | ||
} | ||
function ut() { | ||
j = !0; | ||
function pt() { | ||
O = !0; | ||
} | ||
function st() { | ||
j = !1; | ||
function mt() { | ||
O = !1; | ||
} | ||
var g = { | ||
gql: y, | ||
resetCaches: ft, | ||
var v = { | ||
gql: g, | ||
resetCaches: ut, | ||
disableFragmentWarnings: lt, | ||
enableExperimentalFragmentVariables: ut, | ||
disableExperimentalFragmentVariables: st | ||
enableExperimentalFragmentVariables: pt, | ||
disableExperimentalFragmentVariables: mt | ||
}; | ||
(function(n) { | ||
n.gql = g.gql, n.resetCaches = g.resetCaches, n.disableFragmentWarnings = g.disableFragmentWarnings, n.enableExperimentalFragmentVariables = g.enableExperimentalFragmentVariables, n.disableExperimentalFragmentVariables = g.disableExperimentalFragmentVariables; | ||
})(y || (y = {})); | ||
y.default = y; | ||
function c(n, t, i, a) { | ||
if (t.queries.find((o) => o.name === i)) | ||
return t.queries; | ||
const r = `${a(n, t.path)}`; | ||
(function(t) { | ||
t.gql = v.gql, t.resetCaches = v.resetCaches, t.disableFragmentWarnings = v.disableFragmentWarnings, t.enableExperimentalFragmentVariables = v.enableExperimentalFragmentVariables, t.disableExperimentalFragmentVariables = v.disableExperimentalFragmentVariables; | ||
})(g || (g = {})); | ||
g.default = g; | ||
function y(t, n, i, a) { | ||
if (n.queries.find((o) => o.name === i)) | ||
return n.queries; | ||
const r = `${a(t, n.path)}`; | ||
try { | ||
const o = y` | ||
const o = g` | ||
${r} | ||
`; | ||
return [ | ||
...t.queries, | ||
...n.queries, | ||
{ | ||
@@ -114,38 +114,38 @@ name: i, | ||
} catch (o) { | ||
throw console.error(o, t, i), console.error(r.replace(/\\n/g, ` | ||
throw console.error(o, n, i), console.error(r.replace(/\\n/g, ` | ||
`)), new Error(`Failed to create query for ${i}`); | ||
} | ||
} | ||
function v(n, t) { | ||
if (n) | ||
return n.queries.find((i) => i.name === t); | ||
function q(t, n) { | ||
if (t) | ||
return t.queries.find((i) => i.name === n); | ||
} | ||
function pt(n) { | ||
return P(n.type) || b(n.type) && P(n.type.ofType); | ||
function dt(t) { | ||
return V(t.type) || E(t.type) && V(t.type.ofType); | ||
} | ||
function mt(n) { | ||
return k(n.type) || b(n.type) && k(n.type.ofType); | ||
function ct(t) { | ||
return k(t.type) || E(t.type) && k(t.type.ofType); | ||
} | ||
function dt(n) { | ||
return !!(N(n.type) || b(n.type) && (N(n.type.ofType) || k(n.type.ofType) && (N(n.type.ofType.ofType) || b(n.type.ofType.ofType) && N(n.type.ofType.ofType.ofType)))); | ||
function yt(t) { | ||
return !!(T(t.type) || E(t.type) && (T(t.type.ofType) || k(t.type.ofType) && (T(t.type.ofType.ofType) || E(t.type.ofType.ofType) && T(t.type.ofType.ofType.ofType)))); | ||
} | ||
function ct(n, t) { | ||
return n ? "Scalar" : t ? "Enum" : "Object"; | ||
function gt(t, n) { | ||
return t ? "Scalar" : n ? "Enum" : "Object"; | ||
} | ||
function yt(n, t) { | ||
function ht(t, n) { | ||
var a, e, r; | ||
if (!t || !t.fields) | ||
throw new Error(`Parent entity not found: ${n}`); | ||
const i = t.fields.find((o) => o.name === n); | ||
if (!n || !n.fields) | ||
throw new Error(`Parent entity not found: ${t}`); | ||
const i = n.fields.find((o) => o.name === t); | ||
return (r = (e = (a = i == null ? void 0 : i.directives) == null ? void 0 : a.find((o) => o.name === "label")) == null ? void 0 : e.args) == null ? void 0 : r.name; | ||
} | ||
function gt(n) { | ||
if (n && n.kind === "Enum") | ||
return n.enumValues; | ||
function vt(t) { | ||
if (t && t.kind === "Enum") | ||
return t.enumValues; | ||
} | ||
function ht(n, t, i) { | ||
var s, d; | ||
const a = mt(n), e = b(n.type), r = nt(n.type).toString(), o = pt(n), f = dt(n), l = O(t, r), u = O(t, i), p = yt(n.name, u), m = gt(l); | ||
function bt(t, n, i) { | ||
var m, d; | ||
const a = ct(t), e = E(t.type), r = it(t.type).toString(), o = dt(t), f = yt(t), s = R(n, r), u = R(n, i), p = ht(t.name, u), l = vt(s); | ||
return { | ||
name: n.name, | ||
name: t.name, | ||
isList: a, | ||
@@ -156,13 +156,13 @@ isNonNull: e, | ||
isEnum: o, | ||
kind: ct(f, o), | ||
description: n.description, | ||
schemaDirectives: l == null ? void 0 : l.directives, | ||
kind: gt(f, o), | ||
description: t.description, | ||
schemaDirectives: s == null ? void 0 : s.directives, | ||
label: p, | ||
enumValues: m, | ||
collection: (d = (s = l == null ? void 0 : l.directives) == null ? void 0 : s.find((w) => w.name === "collection")) == null ? void 0 : d.args, | ||
isUnion: (l == null ? void 0 : l.kind) === "Union" | ||
enumValues: l, | ||
collection: (d = (m = s == null ? void 0 : s.directives) == null ? void 0 : m.find((h) => h.name === "collection")) == null ? void 0 : d.args, | ||
isUnion: (s == null ? void 0 : s.kind) === "Union" | ||
}; | ||
} | ||
function vt(n, t, i, a) { | ||
const e = ht(n, i, a); | ||
function qt(t, n, i, a) { | ||
const e = bt(t, i, a); | ||
return e.isScalar || e.isEnum ? e : { | ||
@@ -173,4 +173,4 @@ ...e, | ||
} | ||
function bt(n, t) { | ||
const i = O(t, n.name.value); | ||
function Et(t, n) { | ||
const i = R(n, t.name.value); | ||
if (!i) | ||
@@ -180,10 +180,10 @@ throw new Error("entity type not found"); | ||
} | ||
function V(n, t) { | ||
switch (n.kind) { | ||
function x(t, n) { | ||
switch (t.kind) { | ||
case "NamedType": | ||
return { variable: bt(n, t), isNonNull: !1, isList: !1 }; | ||
return { variable: Et(t, n), isNonNull: !1, isList: !1 }; | ||
case "NonNullType": | ||
return { ...V(n.type, t), isNonNull: !0 }; | ||
return { ...x(t.type, n), isNonNull: !0 }; | ||
case "ListType": | ||
return { ...V(n.type, t), isList: !0 }; | ||
return { ...x(t.type, n), isList: !0 }; | ||
default: | ||
@@ -193,32 +193,32 @@ throw new Error("extractType error"); | ||
} | ||
function qt(n, t) { | ||
function Ft(t, n) { | ||
return { | ||
...V(n.type, t), | ||
name: n.variable.name.value | ||
...x(t.type, n), | ||
name: t.variable.name.value | ||
}; | ||
} | ||
function z(n, t, i = 0) { | ||
function A(t, n, i = 0) { | ||
var e; | ||
if (i >= t.length) | ||
return n; | ||
const a = { ...n }; | ||
return a.fields = (e = n.fields) == null ? void 0 : e.map((r) => r.fields ? { | ||
if (i >= n.length) | ||
return t; | ||
const a = { ...t }; | ||
return a.fields = (e = t.fields) == null ? void 0 : e.map((r) => r.fields ? { | ||
...r, | ||
representativeField: r.fields.find( | ||
(o) => o.name === t.find((f) => { | ||
var l; | ||
return (l = r.fields) == null ? void 0 : l.find((u) => u.name === f); | ||
(o) => o.name === n.find((f) => { | ||
var s; | ||
return (s = r.fields) == null ? void 0 : s.find((u) => u.name === f); | ||
}) | ||
), | ||
fields: z(r, t, i + 1).fields | ||
fields: A(r, n, i + 1).fields | ||
} : r), a; | ||
} | ||
function A(n, t, i, a) { | ||
const e = new U(n); | ||
function G(t, n, i, a) { | ||
const e = new tt(t); | ||
let r = null; | ||
const o = [], f = []; | ||
if (D(t, tt(e, { | ||
if (nt(n, et(e, { | ||
VariableDefinition: { | ||
enter(u) { | ||
f.push(qt(u, i)); | ||
f.push(Ft(u, i)); | ||
} | ||
@@ -228,11 +228,11 @@ }, | ||
enter(u) { | ||
var d, w, x; | ||
var d, h, c; | ||
const p = e.getParentType(); | ||
if (!p) | ||
throw new Error("Parent type not found"); | ||
const m = e.getFieldDef(); | ||
if (!m) | ||
const l = e.getFieldDef(); | ||
if (!l) | ||
throw new Error("Field definition not found"); | ||
const s = vt( | ||
m, | ||
const m = qt( | ||
l, | ||
u, | ||
@@ -242,7 +242,7 @@ i, | ||
); | ||
if (p.toString() === ((d = n.getQueryType()) == null ? void 0 : d.name) || p.toString() === ((w = n.getMutationType()) == null ? void 0 : w.name)) { | ||
r = s, o.push(s); | ||
if (p.toString() === ((d = t.getQueryType()) == null ? void 0 : d.name) || p.toString() === ((h = t.getMutationType()) == null ? void 0 : h.name)) { | ||
r = m, o.push(m); | ||
return; | ||
} | ||
r && ((x = o[o.length - 1].fields) == null || x.push(s), !s.isScalar && !s.isEnum && o.push(s)); | ||
r && ((c = o[o.length - 1].fields) == null || c.push(m), !m.isScalar && !m.isEnum && o.push(m)); | ||
}, | ||
@@ -256,10 +256,10 @@ leave(u) { | ||
return { | ||
queryObject: z(r, a), | ||
queryObject: A(r, a), | ||
variableDefinitionObjects: f | ||
}; | ||
} | ||
function Ft(n, t, i, a) { | ||
const { queryObject: e, variableDefinitionObjects: r } = A( | ||
function wt(t, n, i, a) { | ||
const { queryObject: e, variableDefinitionObjects: r } = G( | ||
t, | ||
n, | ||
t, | ||
i, | ||
@@ -272,6 +272,6 @@ a | ||
} | ||
function Et(n, t, i, a) { | ||
const { queryObject: e, variableDefinitionObjects: r } = A( | ||
function Nt(t, n, i, a) { | ||
const { queryObject: e, variableDefinitionObjects: r } = G( | ||
t, | ||
n, | ||
t, | ||
i, | ||
@@ -284,25 +284,25 @@ a | ||
} | ||
function S(n, t) { | ||
return Et( | ||
n.graphqlSchema, | ||
t, | ||
n.simplifiedEntities, | ||
n.config.nodeRepresentatives | ||
function S(t, n) { | ||
return Nt( | ||
t.graphqlSchema, | ||
n, | ||
t.simplifiedEntities, | ||
t.config.nodeRepresentatives | ||
); | ||
} | ||
function M(n, t) { | ||
return Ft( | ||
n.graphqlSchema, | ||
t, | ||
n.simplifiedEntities, | ||
n.config.nodeRepresentatives | ||
function M(t, n) { | ||
return wt( | ||
t.graphqlSchema, | ||
n, | ||
t.simplifiedEntities, | ||
t.config.nodeRepresentatives | ||
); | ||
} | ||
function h(n, t, i, a) { | ||
function b(t, n, i, a) { | ||
var r, o; | ||
if (!t) | ||
if (!n) | ||
return; | ||
if (a && i) | ||
return { | ||
...t, | ||
...n, | ||
responseDataPath: { data: `${i}.nodes`, total: `${i}.totalCount` } | ||
@@ -312,48 +312,48 @@ }; | ||
return { | ||
...t, | ||
...n, | ||
responseDataPath: { data: `${i}` } | ||
}; | ||
const e = (o = (r = t.queries) == null ? void 0 : r.find((f) => f.name === "main")) == null ? void 0 : o.gql; | ||
const e = (o = (r = n.queries) == null ? void 0 : r.find((f) => f.name === "main")) == null ? void 0 : o.gql; | ||
if (!e) | ||
throw new Error("Can't find gql"); | ||
return { | ||
...t, | ||
...n, | ||
responseDataPath: { | ||
// @ts-ignore | ||
// eslint-disable-next-line | ||
data: `${e.definitions[0].name.value}.${K(n)}` | ||
data: `${e.definitions[0].name.value}.${_(t)}` | ||
} | ||
}; | ||
} | ||
function wt(n) { | ||
var t, i; | ||
return ((i = (t = n == null ? void 0 : n.find((a) => a.name === "label")) == null ? void 0 : t.args) == null ? void 0 : i.name) || void 0; | ||
function Tt(t) { | ||
var n, i; | ||
return ((i = (n = t == null ? void 0 : t.find((a) => a.name === "label")) == null ? void 0 : n.args) == null ? void 0 : i.name) || void 0; | ||
} | ||
function F(n) { | ||
if (n) | ||
return et(n); | ||
function w(t) { | ||
if (t) | ||
return at(t); | ||
} | ||
function E() { | ||
function N() { | ||
return []; | ||
} | ||
function Nt(n, t, i, a, e) { | ||
if (!t) | ||
function Qt(t, n, i, a, e) { | ||
if (!n) | ||
return; | ||
const r = F(e == null ? void 0 : e.gql), f = n.filter((p) => p.kind === "Object").find((p) => { | ||
var s; | ||
const m = (s = p.directives) == null ? void 0 : s.find((d) => d.name === "collection"); | ||
return m ? m.args.typeName === i.typeName : !1; | ||
const r = w(e == null ? void 0 : e.gql), f = t.filter((p) => p.kind === "Object").find((p) => { | ||
var m; | ||
const l = (m = p.directives) == null ? void 0 : m.find((d) => d.name === "collection"); | ||
return l ? l.args.typeName === i.typeName : !1; | ||
}); | ||
if (!f) | ||
return; | ||
const l = q(n, t.typeName, f.typeName, a), u = (e == null ? void 0 : e.queries) || E(); | ||
if (l) | ||
return { path: l, ...e || {}, query: r, queries: u }; | ||
const s = F(t, n.typeName, f.typeName, a), u = (e == null ? void 0 : e.queries) || N(); | ||
if (s) | ||
return { path: s, ...e || {}, query: r, queries: u }; | ||
if (e != null && e.path) | ||
return { ...e, path: e.path, queries: u }; | ||
} | ||
function Tt(n, t, i, a, e) { | ||
if (!t) | ||
function jt(t, n, i, a, e) { | ||
if (!n) | ||
return; | ||
const r = F(e == null ? void 0 : e.gql), o = q(n, t.typeName, i.typeName, a), f = (e == null ? void 0 : e.queries) || E(); | ||
const r = w(e == null ? void 0 : e.gql), o = F(t, n.typeName, i.typeName, a), f = (e == null ? void 0 : e.queries) || N(); | ||
if (o) | ||
@@ -364,144 +364,140 @@ return { path: o, ...e || {}, query: r, queries: f }; | ||
} | ||
function Qt(n, t, i, a, e) { | ||
if (!e || !t) | ||
function Ot(t, n, i, a, e) { | ||
if (!e || !n) | ||
return; | ||
const r = F(e == null ? void 0 : e.gql), o = q(n, t.typeName, i.typeName, a), f = o == null ? void 0 : o.split(".").pop(), l = `${f}Create.${f}`, u = (e == null ? void 0 : e.queries) || E(); | ||
if (l) | ||
return { path: l, ...e || {}, query: r, queries: u }; | ||
const r = w(e == null ? void 0 : e.gql), o = F(t, n.typeName, i.typeName, a), f = o == null ? void 0 : o.split(".").pop(), s = `${f}Create.${f}`, u = (e == null ? void 0 : e.queries) || N(); | ||
if (s) | ||
return { path: s, ...e || {}, query: r, queries: u }; | ||
if (e != null && e.path) | ||
return { ...e, path: e.path, queries: u }; | ||
} | ||
function jt(n, t, i, a, e) { | ||
if (!e || !t) | ||
function Rt(t, n, i, a, e) { | ||
if (!e || !n) | ||
return; | ||
const r = F(e == null ? void 0 : e.gql), o = q(n, t.typeName, i.typeName, a), f = o == null ? void 0 : o.split(".").pop(), l = `${f}Update.${f}`, u = (e == null ? void 0 : e.queries) || E(); | ||
if (l) | ||
return { path: l, ...e || {}, query: r, queries: u }; | ||
const r = w(e == null ? void 0 : e.gql), o = F(t, n.typeName, i.typeName, a), f = o == null ? void 0 : o.split(".").pop(), s = `${f}Update.${f}`, u = (e == null ? void 0 : e.queries) || N(); | ||
if (s) | ||
return { path: s, ...e || {}, query: r, queries: u }; | ||
if (e != null && e.path) | ||
return { ...e, path: e.path, queries: u }; | ||
} | ||
function Ot(n, t, i, a, e) { | ||
if (!e || !t) | ||
function kt(t, n, i, a, e) { | ||
if (!e || !n) | ||
return; | ||
const r = F(e == null ? void 0 : e.gql), o = q(n, t.typeName, i.typeName, a), f = o == null ? void 0 : o.split(".").pop(), l = `${f}Delete.${f}`, u = (e == null ? void 0 : e.queries) || E(); | ||
if (l) | ||
return { path: l, ...e || {}, query: r, queries: u }; | ||
const r = w(e == null ? void 0 : e.gql), o = F(t, n.typeName, i.typeName, a), f = o == null ? void 0 : o.split(".").pop(), s = `${f}Delete.${f}`, u = (e == null ? void 0 : e.queries) || N(); | ||
if (s) | ||
return { path: s, ...e || {}, query: r, queries: u }; | ||
if (e != null && e.path) | ||
return { ...e, path: e.path, queries: u }; | ||
} | ||
function kt(n, t) { | ||
var r, o; | ||
const i = t.config.adminPath ? `${t.config.adminPath}.` : "", a = _( | ||
t.simplifiedEntities, | ||
"Query", | ||
((r = t.config.adminPath) == null ? void 0 : r.split(".")) || [] | ||
), e = (o = t.config.resources) == null ? void 0 : o.find((f) => f.name === n.typeName); | ||
function $t(t, n) { | ||
var s, u; | ||
const { simplifiedEntities: i, config: a } = n, e = a.adminPath ? `${a.adminPath}.` : "", r = i.find( | ||
(p) => { | ||
var l; | ||
return (l = p.directives) == null ? void 0 : l.find((m) => m.name === "queryRoot"); | ||
} | ||
), o = W( | ||
i, | ||
r.typeName, | ||
((s = a.adminPath) == null ? void 0 : s.split(".")) || [] | ||
), f = (u = a.resources) == null ? void 0 : u.find((p) => p.name === t.typeName); | ||
return { | ||
label: wt(n.directives), | ||
name: n.typeName, | ||
typeName: n.typeName, | ||
skipMenu: e == null ? void 0 : e.skipMenu, | ||
list: Nt(t.simplifiedEntities, a, n, i, e == null ? void 0 : e.list), | ||
show: Tt(t.simplifiedEntities, a, n, i, e == null ? void 0 : e.show), | ||
create: Qt( | ||
t.simplifiedEntities, | ||
a, | ||
n, | ||
i, | ||
e == null ? void 0 : e.create | ||
), | ||
update: jt( | ||
t.simplifiedEntities, | ||
a, | ||
n, | ||
i, | ||
e == null ? void 0 : e.update | ||
), | ||
delete: Ot( | ||
t.simplifiedEntities, | ||
a, | ||
n, | ||
i, | ||
e == null ? void 0 : e.delete | ||
) | ||
label: Tt(t.directives), | ||
name: t.typeName, | ||
typeName: t.typeName, | ||
skipMenu: f == null ? void 0 : f.skipMenu, | ||
list: Qt(i, o, t, e, f == null ? void 0 : f.list), | ||
show: jt(i, o, t, e, f == null ? void 0 : f.show), | ||
create: Ot(i, o, t, e, f == null ? void 0 : f.create), | ||
update: Rt(i, o, t, e, f == null ? void 0 : f.update), | ||
delete: kt(i, o, t, e, f == null ? void 0 : f.delete) | ||
}; | ||
} | ||
function $t(n) { | ||
var a; | ||
const t = n.simplifiedEntities.filter((e) => { | ||
var r; | ||
return (r = e.directives) == null ? void 0 : r.find((o) => o.name === "model"); | ||
}).map((e) => kt(e, n)), i = ((a = n.config.resources) == null ? void 0 : a.map((e) => e.name)) || t.map((e) => e.name); | ||
return I(t, i, "name"); | ||
function xt(t) { | ||
var f, s, u, p; | ||
const { simplifiedEntities: n, config: i } = t, a = C(n, "queryRoot"); | ||
if (!a) | ||
throw new Error("queryRoot not found"); | ||
const e = (u = (s = (f = a.directives) == null ? void 0 : f.find((l) => l.name === "queryRoot")) == null ? void 0 : s.args) == null ? void 0 : u.adminPaths; | ||
if (!e) | ||
throw new Error("adminPaths not found"); | ||
const r = e.map((l) => { | ||
const m = l === "" ? a : W(n, "Query", l.split(".")); | ||
if (!m) | ||
throw new Error("adminEntity not found"); | ||
const d = m.fields.map((c) => c.typeName); | ||
return U(n, "model").filter((c) => d.includes(c.typeName)).map((c) => $t(c, t)); | ||
}).flat(), o = ((p = i.resources) == null ? void 0 : p.map((l) => l.name)) || r.map((l) => l.name); | ||
return I(r, o, "name"); | ||
} | ||
function Vt(n, t) { | ||
function Vt(t, n) { | ||
var a, e, r, o, f; | ||
const i = "main"; | ||
return { | ||
...t, | ||
create: (a = t.create) != null && a.path ? { | ||
...t.create, | ||
queries: c(n, t.create, i, G) | ||
} : t.create, | ||
update: (e = t.update) != null && e.path ? { | ||
...t.update, | ||
queries: c(n, t.update, i, H) | ||
} : t.update, | ||
delete: (r = t.delete) != null && r.path ? { | ||
...t.delete, | ||
queries: c(n, t.delete, i, J) | ||
} : t.delete, | ||
show: (o = t.show) != null && o.path ? { | ||
...t.show, | ||
queries: c(n, t.show, i, X) | ||
} : t.show, | ||
list: (f = t.list) != null && f.path ? { | ||
...t.list, | ||
queries: c(n, t.list, i, Y) | ||
} : t.list | ||
...n, | ||
create: (a = n.create) != null && a.path ? { | ||
...n.create, | ||
queries: y(t, n.create, i, H) | ||
} : n.create, | ||
update: (e = n.update) != null && e.path ? { | ||
...n.update, | ||
queries: y(t, n.update, i, J) | ||
} : n.update, | ||
delete: (r = n.delete) != null && r.path ? { | ||
...n.delete, | ||
queries: y(t, n.delete, i, X) | ||
} : n.delete, | ||
show: (o = n.show) != null && o.path ? { | ||
...n.show, | ||
queries: y(t, n.show, i, Y) | ||
} : n.show, | ||
list: (f = n.list) != null && f.path ? { | ||
...n.list, | ||
queries: y(t, n.list, i, Z) | ||
} : n.list | ||
}; | ||
} | ||
function xt(n, t) { | ||
function Pt(t, n) { | ||
var a; | ||
const i = v(t.list, "minimum"); | ||
const i = q(n.list, "minimum"); | ||
return { | ||
...t, | ||
list: (a = t.list) != null && a.path && !i ? { | ||
...t.list, | ||
queries: c( | ||
n, | ||
t.list, | ||
...n, | ||
list: (a = n.list) != null && a.path && !i ? { | ||
...n.list, | ||
queries: y( | ||
t, | ||
n.list, | ||
"minimum", | ||
Z | ||
L | ||
) | ||
} : t.list | ||
} : n.list | ||
}; | ||
} | ||
function Pt(n, t) { | ||
const i = "main", a = v(t.create, i), e = v(t.update, i), r = v(t.show, i), o = v(t.list, i); | ||
function St(t, n) { | ||
const i = "main", a = q(n.create, i), e = q(n.update, i), r = q(n.show, i), o = q(n.list, i); | ||
return { | ||
...t, | ||
...n, | ||
create: a ? { | ||
...t.create, | ||
...M(n, a.gql) | ||
} : t.create, | ||
...n.create, | ||
...M(t, a.gql) | ||
} : n.create, | ||
update: e ? { | ||
...t.update, | ||
...M(n, e.gql) | ||
} : t.update, | ||
...n.update, | ||
...M(t, e.gql) | ||
} : n.update, | ||
show: r ? { | ||
...t.show, | ||
...S(n, r.gql) | ||
} : t.show, | ||
...n.show, | ||
...S(t, r.gql) | ||
} : n.show, | ||
list: o ? { | ||
...t.list, | ||
...S(n, o.gql) | ||
} : t.list | ||
...n.list, | ||
...S(t, o.gql) | ||
} : n.list | ||
}; | ||
} | ||
function Rt({ config: { nodeRepresentatives: n } }, t) { | ||
function Mt({ config: { nodeRepresentatives: t } }, n) { | ||
var e, r, o, f; | ||
const { show: i, list: a } = t; | ||
const { show: i, list: a } = n; | ||
return { | ||
...t, | ||
...n, | ||
show: i && { | ||
@@ -511,7 +507,7 @@ ...i, | ||
// eslint-disable-next-line | ||
...R(i.structure, i.path, n) | ||
...P(i.structure, i.path, t) | ||
}, | ||
list: a && { | ||
...a, | ||
...R( | ||
...P( | ||
// @ts-ignore | ||
@@ -525,6 +521,6 @@ // eslint-disable-next-line | ||
// eslint-disable-next-line | ||
(f = (o = (r = (e = a == null ? void 0 : a.variablesStructure.find((l) => l.name === "sort")) == null ? void 0 : e.inputFields) == null ? void 0 : r.find((l) => l.typeName !== "BaseSortOrder")) == null ? void 0 : o.enumValues) == null ? void 0 : f.map((l) => ({ | ||
(f = (o = (r = (e = a == null ? void 0 : a.variablesStructure.find((s) => s.name === "sort")) == null ? void 0 : e.inputFields) == null ? void 0 : r.find((s) => s.typeName !== "BaseSortOrder")) == null ? void 0 : o.enumValues) == null ? void 0 : f.map((s) => ({ | ||
// @ts-ignore | ||
// eslint-disable-next-line | ||
name: l.name | ||
name: s.name | ||
})) | ||
@@ -535,14 +531,14 @@ ) | ||
} | ||
function St(n, t) { | ||
function It(t, n) { | ||
var i, a; | ||
return { | ||
...t, | ||
create: h(t.name, t.create), | ||
update: h(t.name, t.update), | ||
delete: h(t.name, t.delete), | ||
show: h(t.name, t.show, (i = t.show) == null ? void 0 : i.path), | ||
list: h( | ||
t.name, | ||
t.list, | ||
(a = t.list) == null ? void 0 : a.path, | ||
...n, | ||
create: b(n.name, n.create), | ||
update: b(n.name, n.update), | ||
delete: b(n.name, n.delete), | ||
show: b(n.name, n.show, (i = n.show) == null ? void 0 : i.path), | ||
list: b( | ||
n.name, | ||
n.list, | ||
(a = n.list) == null ? void 0 : a.path, | ||
!0 | ||
@@ -552,8 +548,8 @@ ) | ||
} | ||
function Bt(n) { | ||
return $t(n).map((t) => Vt(n, t)).map((t) => xt(n, t)).map((t) => Pt(n, t)).map((t) => Rt(n, t)).map((t) => St(n, t)); | ||
function At(t) { | ||
return xt(t).map((n) => Vt(t, n)).map((n) => Pt(t, n)).map((n) => St(t, n)).map((n) => Mt(t, n)).map((n) => It(t, n)); | ||
} | ||
export { | ||
Bt as convert | ||
At as convert | ||
}; | ||
//# sourceMappingURL=index.es.js.map |
@@ -1,7 +0,7 @@ | ||
(function(y,d){typeof exports=="object"&&typeof module!="undefined"?d(exports,require("@theconcurrent/query"),require("@theconcurrent/utility"),require("graphql")):typeof define=="function"&&define.amd?define(["exports","@theconcurrent/query","@theconcurrent/utility","graphql"],d):(y=typeof globalThis!="undefined"?globalThis:y||self,d(y["@theconcurrent/resource"]={},y.query,y.utility,y.graphql))})(this,function(y,d,p,l){"use strict";function P(t,n,i,a){var o;if(!t)return;const e=n?(o=p.getField(t,n))==null?void 0:o.fields:t.fields;return{fields:(i&&e?p.sortDataByOrder(e,i,"name"):e||[]).map(f=>a?a.find(s=>s.name===f.name)?{...f,isSortable:!0}:{...f}:f)}}var w=function(){return w=Object.assign||function(n){for(var i,a=1,e=arguments.length;a<e;a++){i=arguments[a];for(var r in i)Object.prototype.hasOwnProperty.call(i,r)&&(n[r]=i[r])}return n},w.apply(this,arguments)};typeof SuppressedError=="function"&&SuppressedError;var j=new Map,k=new Map,x=!0,Q=!1;function S(t){return t.replace(/[\s,]+/g," ").trim()}function B(t){return S(t.source.body.substring(t.start,t.end))}function z(t){var n=new Set,i=[];return t.definitions.forEach(function(a){if(a.kind==="FragmentDefinition"){var e=a.name.value,r=B(a.loc),o=k.get(e);o&&!o.has(r)?x&&console.warn("Warning: fragment with name "+e+` already exists. | ||
(function(h,y){typeof exports=="object"&&typeof module!="undefined"?y(exports,require("@theconcurrent/query"),require("@theconcurrent/utility"),require("graphql")):typeof define=="function"&&define.amd?define(["exports","@theconcurrent/query","@theconcurrent/utility","graphql"],y):(h=typeof globalThis!="undefined"?globalThis:h||self,y(h["@theconcurrent/resource"]={},h.query,h.utility,h.graphql))})(this,function(h,y,d,l){"use strict";function $(n,t,i,a){var o;if(!n)return;const e=t?(o=d.getField(n,t))==null?void 0:o.fields:n.fields;return{fields:(i&&e?d.sortDataByOrder(e,i,"name"):e||[]).map(s=>a?a.find(f=>f.name===s.name)?{...s,isSortable:!0}:{...s}:s)}}var Q=function(){return Q=Object.assign||function(t){for(var i,a=1,e=arguments.length;a<e;a++){i=arguments[a];for(var r in i)Object.prototype.hasOwnProperty.call(i,r)&&(t[r]=i[r])}return t},Q.apply(this,arguments)};typeof SuppressedError=="function"&&SuppressedError;var O=new Map,R=new Map,x=!0,P=!1;function S(n){return n.replace(/[\s,]+/g," ").trim()}function W(n){return S(n.source.body.substring(n.start,n.end))}function z(n){var t=new Set,i=[];return n.definitions.forEach(function(a){if(a.kind==="FragmentDefinition"){var e=a.name.value,r=W(a.loc),o=R.get(e);o&&!o.has(r)?x&&console.warn("Warning: fragment with name "+e+` already exists. | ||
graphql-tag enforces all fragment names across your application to be unique; read more about | ||
this in the docs: http://dev.apollodata.com/core/fragments.html#unique-names`):o||k.set(e,o=new Set),o.add(r),n.has(r)||(n.add(r),i.push(a))}else i.push(a)}),w(w({},t),{definitions:i})}function A(t){var n=new Set(t.definitions);n.forEach(function(a){a.loc&&delete a.loc,Object.keys(a).forEach(function(e){var r=a[e];r&&typeof r=="object"&&n.add(r)})});var i=t.loc;return i&&(delete i.startToken,delete i.endToken),t}function G(t){var n=S(t);if(!j.has(n)){var i=l.parse(t,{experimentalFragmentVariables:Q,allowLegacyFragmentVariables:Q});if(!i||i.kind!=="Document")throw new Error("Not a valid GraphQL document.");j.set(n,A(z(i)))}return j.get(n)}function v(t){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];typeof t=="string"&&(t=[t]);var a=t[0];return n.forEach(function(e,r){e&&e.kind==="Document"?a+=e.loc.source.body:a+=e,a+=t[r+1]}),G(a)}function L(){j.clear(),k.clear()}function H(){x=!1}function J(){Q=!0}function X(){Q=!1}var E={gql:v,resetCaches:L,disableFragmentWarnings:H,enableExperimentalFragmentVariables:J,disableExperimentalFragmentVariables:X};(function(t){t.gql=E.gql,t.resetCaches=E.resetCaches,t.disableFragmentWarnings=E.disableFragmentWarnings,t.enableExperimentalFragmentVariables=E.enableExperimentalFragmentVariables,t.disableExperimentalFragmentVariables=E.disableExperimentalFragmentVariables})(v||(v={})),v.default=v;function b(t,n,i,a){if(n.queries.find(o=>o.name===i))return n.queries;const r=`${a(t,n.path)}`;try{const o=v` | ||
this in the docs: http://dev.apollodata.com/core/fragments.html#unique-names`):o||R.set(e,o=new Set),o.add(r),t.has(r)||(t.add(r),i.push(a))}else i.push(a)}),Q(Q({},n),{definitions:i})}function A(n){var t=new Set(n.definitions);t.forEach(function(a){a.loc&&delete a.loc,Object.keys(a).forEach(function(e){var r=a[e];r&&typeof r=="object"&&t.add(r)})});var i=n.loc;return i&&(delete i.startToken,delete i.endToken),n}function G(n){var t=S(n);if(!O.has(t)){var i=l.parse(n,{experimentalFragmentVariables:P,allowLegacyFragmentVariables:P});if(!i||i.kind!=="Document")throw new Error("Not a valid GraphQL document.");O.set(t,A(z(i)))}return O.get(t)}function b(n){for(var t=[],i=1;i<arguments.length;i++)t[i-1]=arguments[i];typeof n=="string"&&(n=[n]);var a=n[0];return t.forEach(function(e,r){e&&e.kind==="Document"?a+=e.loc.source.body:a+=e,a+=n[r+1]}),G(a)}function L(){O.clear(),R.clear()}function H(){x=!1}function J(){P=!0}function X(){P=!1}var E={gql:b,resetCaches:L,disableFragmentWarnings:H,enableExperimentalFragmentVariables:J,disableExperimentalFragmentVariables:X};(function(n){n.gql=E.gql,n.resetCaches=E.resetCaches,n.disableFragmentWarnings=E.disableFragmentWarnings,n.enableExperimentalFragmentVariables=E.enableExperimentalFragmentVariables,n.disableExperimentalFragmentVariables=E.disableExperimentalFragmentVariables})(b||(b={})),b.default=b;function N(n,t,i,a){if(t.queries.find(o=>o.name===i))return t.queries;const r=`${a(n,t.path)}`;try{const o=b` | ||
${r} | ||
`;return[...n.queries,{name:i,gql:o}]}catch(o){throw console.error(o,n,i),console.error(r.replace(/\\n/g,` | ||
`)),new Error(`Failed to create query for ${i}`)}}function F(t,n){if(t)return t.queries.find(i=>i.name===n)}function Y(t){return l.isEnumType(t.type)||l.isNonNullType(t.type)&&l.isEnumType(t.type.ofType)}function Z(t){return l.isListType(t.type)||l.isNonNullType(t.type)&&l.isListType(t.type.ofType)}function K(t){return!!(l.isScalarType(t.type)||l.isNonNullType(t.type)&&(l.isScalarType(t.type.ofType)||l.isListType(t.type.ofType)&&(l.isScalarType(t.type.ofType.ofType)||l.isNonNullType(t.type.ofType.ofType)&&l.isScalarType(t.type.ofType.ofType.ofType))))}function _(t,n){return t?"Scalar":n?"Enum":"Object"}function C(t,n){var a,e,r;if(!n||!n.fields)throw new Error(`Parent entity not found: ${t}`);const i=n.fields.find(o=>o.name===t);return(r=(e=(a=i==null?void 0:i.directives)==null?void 0:a.find(o=>o.name==="label"))==null?void 0:e.args)==null?void 0:r.name}function U(t){if(t&&t.kind==="Enum")return t.enumValues}function D(t,n,i){var c,h;const a=Z(t),e=l.isNonNullType(t.type),r=l.getNamedType(t.type).toString(),o=Y(t),f=K(t),s=p.getEntityByName(n,r),u=p.getEntityByName(n,i),m=C(t.name,u),g=U(s);return{name:t.name,isList:a,isNonNull:e,typeName:r,isScalar:f,isEnum:o,kind:_(f,o),description:t.description,schemaDirectives:s==null?void 0:s.directives,label:m,enumValues:g,collection:(h=(c=s==null?void 0:s.directives)==null?void 0:c.find(O=>O.name==="collection"))==null?void 0:h.args,isUnion:(s==null?void 0:s.kind)==="Union"}}function nn(t,n,i,a){const e=D(t,i,a);return e.isScalar||e.isEnum?e:{...e,fields:[]}}function tn(t,n){const i=p.getEntityByName(n,t.name.value);if(!i)throw new Error("entity type not found");return i}function $(t,n){switch(t.kind){case"NamedType":return{variable:tn(t,n),isNonNull:!1,isList:!1};case"NonNullType":return{...$(t.type,n),isNonNull:!0};case"ListType":return{...$(t.type,n),isList:!0};default:throw new Error("extractType error")}}function en(t,n){return{...$(t.type,n),name:t.variable.name.value}}function V(t,n,i=0){var e;if(i>=n.length)return t;const a={...t};return a.fields=(e=t.fields)==null?void 0:e.map(r=>r.fields?{...r,representativeField:r.fields.find(o=>o.name===n.find(f=>{var s;return(s=r.fields)==null?void 0:s.find(u=>u.name===f)})),fields:V(r,n,i+1).fields}:r),a}function R(t,n,i,a){const e=new l.TypeInfo(t);let r=null;const o=[],f=[],s={VariableDefinition:{enter(u){f.push(en(u,i))}},Field:{enter(u){var h,O,W;const m=e.getParentType();if(!m)throw new Error("Parent type not found");const g=e.getFieldDef();if(!g)throw new Error("Field definition not found");const c=nn(g,u,i,m.name);if(m.toString()===((h=t.getQueryType())==null?void 0:h.name)||m.toString()===((O=t.getMutationType())==null?void 0:O.name)){r=c,o.push(c);return}r&&((W=o[o.length-1].fields)==null||W.push(c),!c.isScalar&&!c.isEnum&&o.push(c))},leave(u){o.length>1&&u.selectionSet&&o.pop()}}};if(l.visit(n,l.visitWithTypeInfo(e,s)),!r)throw new Error("Couldn't find query object");return{queryObject:V(r,a),variableDefinitionObjects:f}}function an(t,n,i,a){const{queryObject:e,variableDefinitionObjects:r}=R(t,n,i,a);if(!e)throw new Error("Query object not generated");return{structure:e,variableDefinitionObjects:r}}function rn(t,n,i,a){const{queryObject:e,variableDefinitionObjects:r}=R(t,n,i,a);if(!e)throw new Error("Query object not generated");return{structure:e,variablesStructure:r}}function M(t,n){return rn(t.graphqlSchema,n,t.simplifiedEntities,t.config.nodeRepresentatives)}function I(t,n){return an(t.graphqlSchema,n,t.simplifiedEntities,t.config.nodeRepresentatives)}function N(t,n,i,a){var r,o;if(!n)return;if(a&&i)return{...n,responseDataPath:{data:`${i}.nodes`,total:`${i}.totalCount`}};if(i)return{...n,responseDataPath:{data:`${i}`}};const e=(o=(r=n.queries)==null?void 0:r.find(f=>f.name==="main"))==null?void 0:o.gql;if(!e)throw new Error("Can't find gql");return{...n,responseDataPath:{data:`${e.definitions[0].name.value}.${p.lowercaseFirstLetter(t)}`}}}function on(t){var n,i;return((i=(n=t==null?void 0:t.find(a=>a.name==="label"))==null?void 0:n.args)==null?void 0:i.name)||void 0}function T(t){if(t)return l.print(t)}function q(){return[]}function fn(t,n,i,a,e){if(!n)return;const r=T(e==null?void 0:e.gql),f=t.filter(m=>m.kind==="Object").find(m=>{var c;const g=(c=m.directives)==null?void 0:c.find(h=>h.name==="collection");return g?g.args.typeName===i.typeName:!1});if(!f)return;const s=p.generatePath(t,n.typeName,f.typeName,a),u=(e==null?void 0:e.queries)||q();if(s)return{path:s,...e||{},query:r,queries:u};if(e!=null&&e.path)return{...e,path:e.path,queries:u}}function sn(t,n,i,a,e){if(!n)return;const r=T(e==null?void 0:e.gql),o=p.generatePath(t,n.typeName,i.typeName,a),f=(e==null?void 0:e.queries)||q();if(o)return{path:o,...e||{},query:r,queries:f};if(e!=null&&e.path)return{...e,path:e.path,queries:f}}function un(t,n,i,a,e){if(!e||!n)return;const r=T(e==null?void 0:e.gql),o=p.generatePath(t,n.typeName,i.typeName,a),f=o==null?void 0:o.split(".").pop(),s=`${f}Create.${f}`,u=(e==null?void 0:e.queries)||q();if(s)return{path:s,...e||{},query:r,queries:u};if(e!=null&&e.path)return{...e,path:e.path,queries:u}}function ln(t,n,i,a,e){if(!e||!n)return;const r=T(e==null?void 0:e.gql),o=p.generatePath(t,n.typeName,i.typeName,a),f=o==null?void 0:o.split(".").pop(),s=`${f}Update.${f}`,u=(e==null?void 0:e.queries)||q();if(s)return{path:s,...e||{},query:r,queries:u};if(e!=null&&e.path)return{...e,path:e.path,queries:u}}function pn(t,n,i,a,e){if(!e||!n)return;const r=T(e==null?void 0:e.gql),o=p.generatePath(t,n.typeName,i.typeName,a),f=o==null?void 0:o.split(".").pop(),s=`${f}Delete.${f}`,u=(e==null?void 0:e.queries)||q();if(s)return{path:s,...e||{},query:r,queries:u};if(e!=null&&e.path)return{...e,path:e.path,queries:u}}function cn(t,n){var r,o;const i=n.config.adminPath?`${n.config.adminPath}.`:"",a=p.findEntityFromPath(n.simplifiedEntities,"Query",((r=n.config.adminPath)==null?void 0:r.split("."))||[]),e=(o=n.config.resources)==null?void 0:o.find(f=>f.name===t.typeName);return{label:on(t.directives),name:t.typeName,typeName:t.typeName,skipMenu:e==null?void 0:e.skipMenu,list:fn(n.simplifiedEntities,a,t,i,e==null?void 0:e.list),show:sn(n.simplifiedEntities,a,t,i,e==null?void 0:e.show),create:un(n.simplifiedEntities,a,t,i,e==null?void 0:e.create),update:ln(n.simplifiedEntities,a,t,i,e==null?void 0:e.update),delete:pn(n.simplifiedEntities,a,t,i,e==null?void 0:e.delete)}}function dn(t){var a;const n=t.simplifiedEntities.filter(e=>{var r;return(r=e.directives)==null?void 0:r.find(o=>o.name==="model")}).map(e=>cn(e,t)),i=((a=t.config.resources)==null?void 0:a.map(e=>e.name))||n.map(e=>e.name);return p.sortDataByOrder(n,i,"name")}function mn(t,n){var a,e,r,o,f;const i="main";return{...n,create:(a=n.create)!=null&&a.path?{...n.create,queries:b(t,n.create,i,d.createQueryForCreate)}:n.create,update:(e=n.update)!=null&&e.path?{...n.update,queries:b(t,n.update,i,d.createQueryForUpdate)}:n.update,delete:(r=n.delete)!=null&&r.path?{...n.delete,queries:b(t,n.delete,i,d.createQueryForDelete)}:n.delete,show:(o=n.show)!=null&&o.path?{...n.show,queries:b(t,n.show,i,d.createQueryForShow)}:n.show,list:(f=n.list)!=null&&f.path?{...n.list,queries:b(t,n.list,i,d.createQueryForList)}:n.list}}function yn(t,n){var a;const i=F(n.list,"minimum");return{...n,list:(a=n.list)!=null&&a.path&&!i?{...n.list,queries:b(t,n.list,"minimum",d.createMinimumQueryForList)}:n.list}}function gn(t,n){const i="main",a=F(n.create,i),e=F(n.update,i),r=F(n.show,i),o=F(n.list,i);return{...n,create:a?{...n.create,...I(t,a.gql)}:n.create,update:e?{...n.update,...I(t,e.gql)}:n.update,show:r?{...n.show,...M(t,r.gql)}:n.show,list:o?{...n.list,...M(t,o.gql)}:n.list}}function hn({config:{nodeRepresentatives:t}},n){var e,r,o,f;const{show:i,list:a}=n;return{...n,show:i&&{...i,...P(i.structure,i.path,t)},list:a&&{...a,...P(a.structure,`${a.path}.nodes`,a==null?void 0:a.orderColumn,(f=(o=(r=(e=a==null?void 0:a.variablesStructure.find(s=>s.name==="sort"))==null?void 0:e.inputFields)==null?void 0:r.find(s=>s.typeName!=="BaseSortOrder"))==null?void 0:o.enumValues)==null?void 0:f.map(s=>({name:s.name})))}}}function vn(t,n){var i,a;return{...n,create:N(n.name,n.create),update:N(n.name,n.update),delete:N(n.name,n.delete),show:N(n.name,n.show,(i=n.show)==null?void 0:i.path),list:N(n.name,n.list,(a=n.list)==null?void 0:a.path,!0)}}function bn(t){return dn(t).map(n=>mn(t,n)).map(n=>yn(t,n)).map(n=>gn(t,n)).map(n=>hn(t,n)).map(n=>vn(t,n))}y.convert=bn,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})}); | ||
`;return[...t.queries,{name:i,gql:o}]}catch(o){throw console.error(o,t,i),console.error(r.replace(/\\n/g,` | ||
`)),new Error(`Failed to create query for ${i}`)}}function F(n,t){if(n)return n.queries.find(i=>i.name===t)}function Y(n){return l.isEnumType(n.type)||l.isNonNullType(n.type)&&l.isEnumType(n.type.ofType)}function Z(n){return l.isListType(n.type)||l.isNonNullType(n.type)&&l.isListType(n.type.ofType)}function K(n){return!!(l.isScalarType(n.type)||l.isNonNullType(n.type)&&(l.isScalarType(n.type.ofType)||l.isListType(n.type.ofType)&&(l.isScalarType(n.type.ofType.ofType)||l.isNonNullType(n.type.ofType.ofType)&&l.isScalarType(n.type.ofType.ofType.ofType))))}function _(n,t){return n?"Scalar":t?"Enum":"Object"}function C(n,t){var a,e,r;if(!t||!t.fields)throw new Error(`Parent entity not found: ${n}`);const i=t.fields.find(o=>o.name===n);return(r=(e=(a=i==null?void 0:i.directives)==null?void 0:a.find(o=>o.name==="label"))==null?void 0:e.args)==null?void 0:r.name}function U(n){if(n&&n.kind==="Enum")return n.enumValues}function D(n,t,i){var m,g;const a=Z(n),e=l.isNonNullType(n.type),r=l.getNamedType(n.type).toString(),o=Y(n),s=K(n),f=d.getEntityByName(t,r),u=d.getEntityByName(t,i),c=C(n.name,u),p=U(f);return{name:n.name,isList:a,isNonNull:e,typeName:r,isScalar:s,isEnum:o,kind:_(s,o),description:n.description,schemaDirectives:f==null?void 0:f.directives,label:c,enumValues:p,collection:(g=(m=f==null?void 0:f.directives)==null?void 0:m.find(j=>j.name==="collection"))==null?void 0:g.args,isUnion:(f==null?void 0:f.kind)==="Union"}}function nn(n,t,i,a){const e=D(n,i,a);return e.isScalar||e.isEnum?e:{...e,fields:[]}}function tn(n,t){const i=d.getEntityByName(t,n.name.value);if(!i)throw new Error("entity type not found");return i}function k(n,t){switch(n.kind){case"NamedType":return{variable:tn(n,t),isNonNull:!1,isList:!1};case"NonNullType":return{...k(n.type,t),isNonNull:!0};case"ListType":return{...k(n.type,t),isList:!0};default:throw new Error("extractType error")}}function en(n,t){return{...k(n.type,t),name:n.variable.name.value}}function V(n,t,i=0){var e;if(i>=t.length)return n;const a={...n};return a.fields=(e=n.fields)==null?void 0:e.map(r=>r.fields?{...r,representativeField:r.fields.find(o=>o.name===t.find(s=>{var f;return(f=r.fields)==null?void 0:f.find(u=>u.name===s)})),fields:V(r,t,i+1).fields}:r),a}function M(n,t,i,a){const e=new l.TypeInfo(n);let r=null;const o=[],s=[],f={VariableDefinition:{enter(u){s.push(en(u,i))}},Field:{enter(u){var g,j,v;const c=e.getParentType();if(!c)throw new Error("Parent type not found");const p=e.getFieldDef();if(!p)throw new Error("Field definition not found");const m=nn(p,u,i,c.name);if(c.toString()===((g=n.getQueryType())==null?void 0:g.name)||c.toString()===((j=n.getMutationType())==null?void 0:j.name)){r=m,o.push(m);return}r&&((v=o[o.length-1].fields)==null||v.push(m),!m.isScalar&&!m.isEnum&&o.push(m))},leave(u){o.length>1&&u.selectionSet&&o.pop()}}};if(l.visit(t,l.visitWithTypeInfo(e,f)),!r)throw new Error("Couldn't find query object");return{queryObject:V(r,a),variableDefinitionObjects:s}}function an(n,t,i,a){const{queryObject:e,variableDefinitionObjects:r}=M(n,t,i,a);if(!e)throw new Error("Query object not generated");return{structure:e,variableDefinitionObjects:r}}function rn(n,t,i,a){const{queryObject:e,variableDefinitionObjects:r}=M(n,t,i,a);if(!e)throw new Error("Query object not generated");return{structure:e,variablesStructure:r}}function B(n,t){return rn(n.graphqlSchema,t,n.simplifiedEntities,n.config.nodeRepresentatives)}function I(n,t){return an(n.graphqlSchema,t,n.simplifiedEntities,n.config.nodeRepresentatives)}function q(n,t,i,a){var r,o;if(!t)return;if(a&&i)return{...t,responseDataPath:{data:`${i}.nodes`,total:`${i}.totalCount`}};if(i)return{...t,responseDataPath:{data:`${i}`}};const e=(o=(r=t.queries)==null?void 0:r.find(s=>s.name==="main"))==null?void 0:o.gql;if(!e)throw new Error("Can't find gql");return{...t,responseDataPath:{data:`${e.definitions[0].name.value}.${d.lowercaseFirstLetter(n)}`}}}function on(n){var t,i;return((i=(t=n==null?void 0:n.find(a=>a.name==="label"))==null?void 0:t.args)==null?void 0:i.name)||void 0}function T(n){if(n)return l.print(n)}function w(){return[]}function sn(n,t,i,a,e){if(!t)return;const r=T(e==null?void 0:e.gql),s=n.filter(c=>c.kind==="Object").find(c=>{var m;const p=(m=c.directives)==null?void 0:m.find(g=>g.name==="collection");return p?p.args.typeName===i.typeName:!1});if(!s)return;const f=d.generatePath(n,t.typeName,s.typeName,a),u=(e==null?void 0:e.queries)||w();if(f)return{path:f,...e||{},query:r,queries:u};if(e!=null&&e.path)return{...e,path:e.path,queries:u}}function fn(n,t,i,a,e){if(!t)return;const r=T(e==null?void 0:e.gql),o=d.generatePath(n,t.typeName,i.typeName,a),s=(e==null?void 0:e.queries)||w();if(o)return{path:o,...e||{},query:r,queries:s};if(e!=null&&e.path)return{...e,path:e.path,queries:s}}function un(n,t,i,a,e){if(!e||!t)return;const r=T(e==null?void 0:e.gql),o=d.generatePath(n,t.typeName,i.typeName,a),s=o==null?void 0:o.split(".").pop(),f=`${s}Create.${s}`,u=(e==null?void 0:e.queries)||w();if(f)return{path:f,...e||{},query:r,queries:u};if(e!=null&&e.path)return{...e,path:e.path,queries:u}}function ln(n,t,i,a,e){if(!e||!t)return;const r=T(e==null?void 0:e.gql),o=d.generatePath(n,t.typeName,i.typeName,a),s=o==null?void 0:o.split(".").pop(),f=`${s}Update.${s}`,u=(e==null?void 0:e.queries)||w();if(f)return{path:f,...e||{},query:r,queries:u};if(e!=null&&e.path)return{...e,path:e.path,queries:u}}function pn(n,t,i,a,e){if(!e||!t)return;const r=T(e==null?void 0:e.gql),o=d.generatePath(n,t.typeName,i.typeName,a),s=o==null?void 0:o.split(".").pop(),f=`${s}Delete.${s}`,u=(e==null?void 0:e.queries)||w();if(f)return{path:f,...e||{},query:r,queries:u};if(e!=null&&e.path)return{...e,path:e.path,queries:u}}function cn(n,t){var f,u;const{simplifiedEntities:i,config:a}=t,e=a.adminPath?`${a.adminPath}.`:"",r=i.find(c=>{var p;return(p=c.directives)==null?void 0:p.find(m=>m.name==="queryRoot")}),o=d.findEntityFromPath(i,r.typeName,((f=a.adminPath)==null?void 0:f.split("."))||[]),s=(u=a.resources)==null?void 0:u.find(c=>c.name===n.typeName);return{label:on(n.directives),name:n.typeName,typeName:n.typeName,skipMenu:s==null?void 0:s.skipMenu,list:sn(i,o,n,e,s==null?void 0:s.list),show:fn(i,o,n,e,s==null?void 0:s.show),create:un(i,o,n,e,s==null?void 0:s.create),update:ln(i,o,n,e,s==null?void 0:s.update),delete:pn(i,o,n,e,s==null?void 0:s.delete)}}function mn(n){var s,f,u,c;const{simplifiedEntities:t,config:i}=n,a=d.findEntityByDirectiveName(t,"queryRoot");if(!a)throw new Error("queryRoot not found");const e=(u=(f=(s=a.directives)==null?void 0:s.find(p=>p.name==="queryRoot"))==null?void 0:f.args)==null?void 0:u.adminPaths;if(!e)throw new Error("adminPaths not found");const r=e.map(p=>{const m=p===""?a:d.findEntityFromPath(t,"Query",p.split("."));if(!m)throw new Error("adminEntity not found");const g=m.fields.map(v=>v.typeName);return d.filterEntitiesByDirectiveName(t,"model").filter(v=>g.includes(v.typeName)).map(v=>cn(v,n))}).flat(),o=((c=i.resources)==null?void 0:c.map(p=>p.name))||r.map(p=>p.name);return d.sortDataByOrder(r,o,"name")}function dn(n,t){var a,e,r,o,s;const i="main";return{...t,create:(a=t.create)!=null&&a.path?{...t.create,queries:N(n,t.create,i,y.createQueryForCreate)}:t.create,update:(e=t.update)!=null&&e.path?{...t.update,queries:N(n,t.update,i,y.createQueryForUpdate)}:t.update,delete:(r=t.delete)!=null&&r.path?{...t.delete,queries:N(n,t.delete,i,y.createQueryForDelete)}:t.delete,show:(o=t.show)!=null&&o.path?{...t.show,queries:N(n,t.show,i,y.createQueryForShow)}:t.show,list:(s=t.list)!=null&&s.path?{...t.list,queries:N(n,t.list,i,y.createQueryForList)}:t.list}}function yn(n,t){var a;const i=F(t.list,"minimum");return{...t,list:(a=t.list)!=null&&a.path&&!i?{...t.list,queries:N(n,t.list,"minimum",y.createMinimumQueryForList)}:t.list}}function hn(n,t){const i="main",a=F(t.create,i),e=F(t.update,i),r=F(t.show,i),o=F(t.list,i);return{...t,create:a?{...t.create,...I(n,a.gql)}:t.create,update:e?{...t.update,...I(n,e.gql)}:t.update,show:r?{...t.show,...B(n,r.gql)}:t.show,list:o?{...t.list,...B(n,o.gql)}:t.list}}function gn({config:{nodeRepresentatives:n}},t){var e,r,o,s;const{show:i,list:a}=t;return{...t,show:i&&{...i,...$(i.structure,i.path,n)},list:a&&{...a,...$(a.structure,`${a.path}.nodes`,a==null?void 0:a.orderColumn,(s=(o=(r=(e=a==null?void 0:a.variablesStructure.find(f=>f.name==="sort"))==null?void 0:e.inputFields)==null?void 0:r.find(f=>f.typeName!=="BaseSortOrder"))==null?void 0:o.enumValues)==null?void 0:s.map(f=>({name:f.name})))}}}function vn(n,t){var i,a;return{...t,create:q(t.name,t.create),update:q(t.name,t.update),delete:q(t.name,t.delete),show:q(t.name,t.show,(i=t.show)==null?void 0:i.path),list:q(t.name,t.list,(a=t.list)==null?void 0:a.path,!0)}}function bn(n){return mn(n).map(t=>dn(n,t)).map(t=>yn(n,t)).map(t=>hn(n,t)).map(t=>gn(n,t)).map(t=>vn(n,t))}h.convert=bn,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}); | ||
//# sourceMappingURL=index.umd.js.map |
@@ -113,2 +113,3 @@ /// <reference types="react" /> | ||
schemeResourceName?: string; | ||
category?: string; | ||
create?: { | ||
@@ -115,0 +116,0 @@ queries: Array<RawQuery>; |
{ | ||
"name": "@theconcurrent/resource", | ||
"version": "0.0.18", | ||
"version": "0.0.19", | ||
"main": "./dist/index.umd.js", | ||
@@ -27,14 +27,14 @@ "module": "./dist/index.es.js", | ||
"dependencies": { | ||
"@theconcurrent/query": "0.0.18", | ||
"@theconcurrent/simplified-entity": "0.0.18", | ||
"@theconcurrent/utility": "0.0.18", | ||
"@theconcurrent/query": "0.0.19", | ||
"@theconcurrent/simplified-entity": "0.0.19", | ||
"@theconcurrent/utility": "0.0.19", | ||
"graphql": "16.0.1" | ||
}, | ||
"peerDependencies": { | ||
"@theconcurrent/query": "0.0.18", | ||
"@theconcurrent/simplified-entity": "0.0.18", | ||
"@theconcurrent/utility": "0.0.18", | ||
"@theconcurrent/query": "0.0.19", | ||
"@theconcurrent/simplified-entity": "0.0.19", | ||
"@theconcurrent/utility": "0.0.19", | ||
"graphql": "16.0.1" | ||
}, | ||
"gitHead": "e9b5ea92e453f508265e1693e10b87c3039eec03" | ||
"gitHead": "d92250a7361b0103695a48cc29c8e610f698e487" | ||
} |
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
211202
44
1289
+ Added@theconcurrent/query@0.0.19(transitive)
+ Added@theconcurrent/simplified-entity@0.0.19(transitive)
+ Added@theconcurrent/utility@0.0.19(transitive)
- Removed@theconcurrent/query@0.0.18(transitive)
- Removed@theconcurrent/simplified-entity@0.0.18(transitive)
- Removed@theconcurrent/utility@0.0.18(transitive)
Updated@theconcurrent/query@0.0.19