druxt-schema
Advanced tools
Comparing version 0.7.6 to 0.7.7
import consola from 'consola'; | ||
import { resolve } from 'path'; | ||
import 'drupal-jsonapi-params'; | ||
import { DrupalJsonApiParams } from 'drupal-jsonapi-params'; | ||
import { DruxtClient } from 'druxt'; | ||
@@ -267,3 +267,4 @@ import { mapActions } from 'vuex'; | ||
var resourceType = "entity_" + schemaType + "_display--entity_" + schemaType + "_display"; | ||
return (await this$1.druxt.getCollectionAll(resourceType)) | ||
var query = new DrupalJsonApiParams().addSort('drupal_internal__id'); | ||
return (await this$1.druxt.getCollectionAll(resourceType, query)) | ||
.map(function (collection) { return collection.data | ||
@@ -270,0 +271,0 @@ .filter(function (data) { return !!data.attributes.status; }) |
@@ -1,1 +0,1 @@ | ||
var VueDrupalSchema=function(t,e,i,s,r,n){"use strict";e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;var a=function(t,e){var i=e.druxtSchema,s=e.data;if(t.resourceFields&&(this.resourceFields=t.resourceFields,delete t.resourceFields),this.config=Object.assign({},{entityType:"node",bundle:null,mode:"default",schemaType:"view",filter:[]},t),!this.id&&this.config.resourceType&&(this.id=[this.config.resourceType,this.config.mode,this.config.schemaType].join("--")),!this.id&&this.config.bundle&&(this.id=[this.config.entityType,this.config.bundle,this.config.mode,this.config.schemaType].join("--")),this.isValid=!0,(this.config.filter||[]).length>0)for(var r of(this.isValid=!1,this.config.filter)){if(this.id.match(r)){this.isValid=!0;break}}this.displayId=[this.config.entityType,this.config.bundle,this.config.mode].join("."),this.resourceType=[this.config.entityType,this.config.bundle].join("--"),this.data={},void 0!==s&&(this.data[s.type]=s),this.fields={},this.druxtSchema=i};a.prototype.generate=async function(){return this[this.config.schemaType]()},a.prototype.getResources=async function(t,e){return this.data[t]||(this.data[t]=await this.druxtSchema.druxt.getCollection(t,e)),this.data[t]},a.prototype.form=async function(){var t=this,e=await this.getResources("entity_form_display--entity_form_display",{"filter[drupal_internal__id]":this.displayId}).then((function(t){return Array.isArray(t.data)?t.data[0]:t}));if(!e)return!1;var i=await this.getResources("field_config--field_config",{"filter[entity_type]":this.config.entityType,"filter[bundle]":this.config.bundle});if(!i)return!1;var s=await this.getResources("field_storage_config--field_storage_config",{"filter[entity_type]":this.config.entityType});if(!s)return!1;var r=function(r){var n=Object.assign({},{id:null,label:null,type:null,weight:null,settings:{},third_party_settings:{}},e.attributes.content[r]),a=Object.assign({},{attributes:{}},i.data.find((function(t){return t.attributes.field_name===r})));a=Object.assign({},{description:null,label:null,required:!1,settings:{}},a.attributes);var o=Object.assign({},{attributes:{}},s.data.find((function(t){return t.attributes.field_name===r})));o=Object.assign({},{cardinality:null,settings:{}},o.attributes);var u=r;t.resourceFields&&t.resourceFields[r]&&t.resourceFields[r].publicName!==r&&(u=t.resourceFields[r].publicName),t.fields[u]={id:u,description:a.description,label:{text:a.label,position:n.label},cardinality:o.cardinality,required:a.required,type:n.type,weight:n.weight,settings:{config:a.settings,display:n.settings,storage:o.settings},thirdPartySettings:n.third_party_settings}};for(var n in e.attributes.content)r(n);return this.schema={id:this.id,resourceType:this.resourceType,fields:Object.values(this.fields).sort((function(t,e){return t.weight-e.weight})),groups:[],config:this.config},this.schema},a.prototype.view=async function(){var t=this,e=await this.getResources("entity_view_display--entity_view_display",{"filter[drupal_internal__id]":this.displayId}).then((function(t){return Array.isArray(t.data)?t.data[0]:t}));if(!e)return!1;var i=await this.getResources("field_config--field_config",{"filter[entity_type]":this.config.entityType,"filter[bundle]":this.config.bundle});if(!i)return!1;var s=function(s){var r=Object.assign({},{id:null,label:null,type:null,weight:null,settings:{},third_party_settings:{}},e.attributes.content[s]),n=Object.assign({},{attributes:{}},i.data.find((function(t){return t.attributes.field_name===s})));n=Object.assign({},{description:null,label:null,required:!1,settings:{}},n.attributes);var a=s;t.resourceFields&&t.resourceFields[s]&&t.resourceFields[s].publicName!==s&&(a=t.resourceFields[s].publicName),t.fields[a]={id:a,description:n.description,label:{text:n.label,position:r.label},required:n.required,type:r.type,weight:r.weight,settings:{config:n.settings,display:r.settings},thirdPartySettings:r.third_party_settings}};for(var r in e.attributes.content)s(r);return this.schema={id:this.id,resourceType:this.resourceType,fields:Object.values(this.fields).sort((function(t,e){return t.weight-e.weight})),groups:[],config:this.config},this.schema};var o=function(t,e){if(void 0===e&&(e={}),!t)throw new Error("The 'baseUrl' parameter is required.");this.options=Object.assign({},{auth:{type:!1},schema:{filter:[]}},e),this.druxt=new r.DruxtClient(t,this.options)};o.prototype.get=async function(){var t=this,e=await this.druxt.getIndex(),i=(await Promise.all([].concat(["view","form"].map((async function(i){var s="entity_"+i+"_display--entity_"+i+"_display";return(await t.druxt.getCollectionAll(s)).map((function(s){return s.data.filter((function(t){return!!t.attributes.status})).map((function(s){return Object.assign({},{entityType:s.attributes.targetEntityType,bundle:s.attributes.bundle,mode:s.attributes.mode,schemaType:i,filter:t.options.schema.filter},e[[s.attributes.targetEntityType,s.attributes.bundle].join("--")])}))}))}))))).flat(2),s=Object.fromEntries((await Promise.all(i.map((function(e){return t.getSchema(e)})))).filter((function(t){return t})).map((function(t){return[t.id,t.schema]})));return{index:e,schemas:s}},o.prototype.getSchema=async function(t,e){void 0===e&&(e={});var i=new a(t,Object.assign({},{druxtSchema:this},e));return!!i.isValid&&(await i.generate(),i)};var u=function(t){var s=this;if(void 0===this.options||!this.options.druxt)throw new TypeError("Druxt settings missing.");var r=this.options.druxt;this.addPlugin({src:i.resolve(__dirname,"../nuxt/plugin.js"),fileName:"druxt-schema.js",options:r}),this.addPlugin({src:i.resolve(__dirname,"../nuxt/store.js"),fileName:"store/druxt-schema.js",options:r}),this.nuxt.hook("builder:prepared",(async function(t,n){var a=new o(r.baseUrl,r),u=(await a.get()).schemas;for(var c in u){var d=u[c];void 0!==d&&s.addTemplate({src:i.resolve(__dirname,"../nuxt/schema.json"),fileName:"schemas/"+c+".json",options:{schema:d}})}e.success("Druxt schema generated")}))};u.meta=require("../package.json");var c={props:{mode:{type:String,default:"default"},type:{type:String,required:!0}},fetch:async function(){this.schema=await this.getSchema({resourceType:this.type,mode:this.mode})},data:function(){return{schema:!1}},methods:Object.assign({},n.mapActions({getSchema:"druxtSchema/get"}))};return t.DruxtSchema=o,t.DruxtSchemaMixin=c,t.DruxtSchemaStore=function(t){var e=t.store;if(void 0===e)throw new TypeError("Vuex store not found.");var i="druxtSchema",s={namespaced:!0,state:function(){return{schemas:{}}},mutations:{addSchema:function(t,e){var i=e.id,s=e.schema;t.schemas[i]=s}},actions:{get:async function(t,e){var i=t.state,s=t.commit;if(void 0===e&&(e={}),!(e=Object.assign({},{id:null,resourceType:null,entityType:"node",bundle:null,mode:"default",schemaType:"view"},e)).id&&e.resourceType&&(e.id=[e.resourceType,e.mode,e.schemaType].join("--")),!e.id&&e.bundle&&(e.id=[e.entityType,e.bundle,e.mode,e.schemaType].join("--")),!e.id)return!1;if(!i.schemas[e.id]){var r=await this.$druxtSchema.import(e.id);s("addSchema",{id:e.id,schema:r})}return i.schemas[e.id]}}};e.registerModule(i,s,{preserveState:Boolean(e.state[i])})},t.default=u,t}({},consola,path,drupalJsonapiParams,druxt,vuex); | ||
var VueDrupalSchema=function(t,e,i,s,r,n){"use strict";e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;var a=function(t,e){var i=e.druxtSchema,s=e.data;if(t.resourceFields&&(this.resourceFields=t.resourceFields,delete t.resourceFields),this.config=Object.assign({},{entityType:"node",bundle:null,mode:"default",schemaType:"view",filter:[]},t),!this.id&&this.config.resourceType&&(this.id=[this.config.resourceType,this.config.mode,this.config.schemaType].join("--")),!this.id&&this.config.bundle&&(this.id=[this.config.entityType,this.config.bundle,this.config.mode,this.config.schemaType].join("--")),this.isValid=!0,(this.config.filter||[]).length>0)for(var r of(this.isValid=!1,this.config.filter)){if(this.id.match(r)){this.isValid=!0;break}}this.displayId=[this.config.entityType,this.config.bundle,this.config.mode].join("."),this.resourceType=[this.config.entityType,this.config.bundle].join("--"),this.data={},void 0!==s&&(this.data[s.type]=s),this.fields={},this.druxtSchema=i};a.prototype.generate=async function(){return this[this.config.schemaType]()},a.prototype.getResources=async function(t,e){return this.data[t]||(this.data[t]=await this.druxtSchema.druxt.getCollection(t,e)),this.data[t]},a.prototype.form=async function(){var t=this,e=await this.getResources("entity_form_display--entity_form_display",{"filter[drupal_internal__id]":this.displayId}).then((function(t){return Array.isArray(t.data)?t.data[0]:t}));if(!e)return!1;var i=await this.getResources("field_config--field_config",{"filter[entity_type]":this.config.entityType,"filter[bundle]":this.config.bundle});if(!i)return!1;var s=await this.getResources("field_storage_config--field_storage_config",{"filter[entity_type]":this.config.entityType});if(!s)return!1;var r=function(r){var n=Object.assign({},{id:null,label:null,type:null,weight:null,settings:{},third_party_settings:{}},e.attributes.content[r]),a=Object.assign({},{attributes:{}},i.data.find((function(t){return t.attributes.field_name===r})));a=Object.assign({},{description:null,label:null,required:!1,settings:{}},a.attributes);var o=Object.assign({},{attributes:{}},s.data.find((function(t){return t.attributes.field_name===r})));o=Object.assign({},{cardinality:null,settings:{}},o.attributes);var u=r;t.resourceFields&&t.resourceFields[r]&&t.resourceFields[r].publicName!==r&&(u=t.resourceFields[r].publicName),t.fields[u]={id:u,description:a.description,label:{text:a.label,position:n.label},cardinality:o.cardinality,required:a.required,type:n.type,weight:n.weight,settings:{config:a.settings,display:n.settings,storage:o.settings},thirdPartySettings:n.third_party_settings}};for(var n in e.attributes.content)r(n);return this.schema={id:this.id,resourceType:this.resourceType,fields:Object.values(this.fields).sort((function(t,e){return t.weight-e.weight})),groups:[],config:this.config},this.schema},a.prototype.view=async function(){var t=this,e=await this.getResources("entity_view_display--entity_view_display",{"filter[drupal_internal__id]":this.displayId}).then((function(t){return Array.isArray(t.data)?t.data[0]:t}));if(!e)return!1;var i=await this.getResources("field_config--field_config",{"filter[entity_type]":this.config.entityType,"filter[bundle]":this.config.bundle});if(!i)return!1;var s=function(s){var r=Object.assign({},{id:null,label:null,type:null,weight:null,settings:{},third_party_settings:{}},e.attributes.content[s]),n=Object.assign({},{attributes:{}},i.data.find((function(t){return t.attributes.field_name===s})));n=Object.assign({},{description:null,label:null,required:!1,settings:{}},n.attributes);var a=s;t.resourceFields&&t.resourceFields[s]&&t.resourceFields[s].publicName!==s&&(a=t.resourceFields[s].publicName),t.fields[a]={id:a,description:n.description,label:{text:n.label,position:r.label},required:n.required,type:r.type,weight:r.weight,settings:{config:n.settings,display:r.settings},thirdPartySettings:r.third_party_settings}};for(var r in e.attributes.content)s(r);return this.schema={id:this.id,resourceType:this.resourceType,fields:Object.values(this.fields).sort((function(t,e){return t.weight-e.weight})),groups:[],config:this.config},this.schema};var o=function(t,e){if(void 0===e&&(e={}),!t)throw new Error("The 'baseUrl' parameter is required.");this.options=Object.assign({},{auth:{type:!1},schema:{filter:[]}},e),this.druxt=new r.DruxtClient(t,this.options)};o.prototype.get=async function(){var t=this,e=await this.druxt.getIndex(),i=(await Promise.all([].concat(["view","form"].map((async function(i){var r="entity_"+i+"_display--entity_"+i+"_display",n=(new s.DrupalJsonApiParams).addSort("drupal_internal__id");return(await t.druxt.getCollectionAll(r,n)).map((function(s){return s.data.filter((function(t){return!!t.attributes.status})).map((function(s){return Object.assign({},{entityType:s.attributes.targetEntityType,bundle:s.attributes.bundle,mode:s.attributes.mode,schemaType:i,filter:t.options.schema.filter},e[[s.attributes.targetEntityType,s.attributes.bundle].join("--")])}))}))}))))).flat(2),r=Object.fromEntries((await Promise.all(i.map((function(e){return t.getSchema(e)})))).filter((function(t){return t})).map((function(t){return[t.id,t.schema]})));return{index:e,schemas:r}},o.prototype.getSchema=async function(t,e){void 0===e&&(e={});var i=new a(t,Object.assign({},{druxtSchema:this},e));return!!i.isValid&&(await i.generate(),i)};var u=function(t){var s=this;if(void 0===this.options||!this.options.druxt)throw new TypeError("Druxt settings missing.");var r=this.options.druxt;this.addPlugin({src:i.resolve(__dirname,"../nuxt/plugin.js"),fileName:"druxt-schema.js",options:r}),this.addPlugin({src:i.resolve(__dirname,"../nuxt/store.js"),fileName:"store/druxt-schema.js",options:r}),this.nuxt.hook("builder:prepared",(async function(t,n){var a=new o(r.baseUrl,r),u=(await a.get()).schemas;for(var c in u){var d=u[c];void 0!==d&&s.addTemplate({src:i.resolve(__dirname,"../nuxt/schema.json"),fileName:"schemas/"+c+".json",options:{schema:d}})}e.success("Druxt schema generated")}))};u.meta=require("../package.json");var c={props:{mode:{type:String,default:"default"},type:{type:String,required:!0}},fetch:async function(){this.schema=await this.getSchema({resourceType:this.type,mode:this.mode})},data:function(){return{schema:!1}},methods:Object.assign({},n.mapActions({getSchema:"druxtSchema/get"}))};return t.DruxtSchema=o,t.DruxtSchemaMixin=c,t.DruxtSchemaStore=function(t){var e=t.store;if(void 0===e)throw new TypeError("Vuex store not found.");var i="druxtSchema",s={namespaced:!0,state:function(){return{schemas:{}}},mutations:{addSchema:function(t,e){var i=e.id,s=e.schema;t.schemas[i]=s}},actions:{get:async function(t,e){var i=t.state,s=t.commit;if(void 0===e&&(e={}),!(e=Object.assign({},{id:null,resourceType:null,entityType:"node",bundle:null,mode:"default",schemaType:"view"},e)).id&&e.resourceType&&(e.id=[e.resourceType,e.mode,e.schemaType].join("--")),!e.id&&e.bundle&&(e.id=[e.entityType,e.bundle,e.mode,e.schemaType].join("--")),!e.id)return!1;if(!i.schemas[e.id]){var r=await this.$druxtSchema.import(e.id);s("addSchema",{id:e.id,schema:r})}return i.schemas[e.id]}}};e.registerModule(i,s,{preserveState:Boolean(e.state[i])})},t.default=u,t}({},consola,path,drupalJsonapiParams,druxt,vuex); |
@@ -1,2 +0,2 @@ | ||
'use strict';Object.defineProperty(exports,'__esModule',{value:true});function _interopDefault(e){return(e&&(typeof e==='object')&&'default'in e)?e['default']:e}var consola=_interopDefault(require('consola')),path=require('path');require('drupal-jsonapi-params');var druxt=require('druxt'),vuex=require('vuex');/** | ||
'use strict';Object.defineProperty(exports,'__esModule',{value:true});function _interopDefault(e){return(e&&(typeof e==='object')&&'default'in e)?e['default']:e}var consola=_interopDefault(require('consola')),path=require('path'),drupalJsonapiParams=require('drupal-jsonapi-params'),druxt=require('druxt'),vuex=require('vuex');/** | ||
* Schema. | ||
@@ -259,3 +259,4 @@ * | ||
var resourceType = "entity_" + schemaType + "_display--entity_" + schemaType + "_display"; | ||
return (await this$1.druxt.getCollectionAll(resourceType)) | ||
var query = new drupalJsonapiParams.DrupalJsonApiParams().addSort('drupal_internal__id'); | ||
return (await this$1.druxt.getCollectionAll(resourceType, query)) | ||
.map(function (collection) { return collection.data | ||
@@ -262,0 +263,0 @@ .filter(function (data) { return !!data.attributes.status; }) |
{ | ||
"name": "druxt-schema", | ||
"version": "0.7.6", | ||
"version": "0.7.7", | ||
"description": "Entity Form and View mode schemas for Drupal driven frontends.", | ||
@@ -5,0 +5,0 @@ "repository": { |
# Druxt.js Schema | ||
[![npm](https://badgen.net/npm/v/druxt-schema)](https://www.npmjs.com/package/druxt-schema) | ||
[![CircleCI](https://circleci.com/gh/druxt/druxt-schema.svg?style=svg)](https://circleci.com/gh/druxt/druxt-schema) | ||
@@ -4,0 +5,0 @@ [![Known Vulnerabilities](https://snyk.io/test/github/druxt/druxt-schema/badge.svg?targetFile=package.json)](https://snyk.io/test/github/druxt/druxt-schema?targetFile=package.json) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45452
1028
58