Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

druxt-schema

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

druxt-schema - npm Package Compare versions

Comparing version 0.7.1 to 0.7.2

44

dist/druxt-schema.esm.js
import consola from 'consola';
import { resolve } from 'path';
import { DrupalJsonApiParams } from 'drupal-jsonapi-params';
import { DruxtClient } from 'druxt';

@@ -260,29 +261,26 @@ import { mapActions } from 'vuex';

DruxtSchema.prototype.get = async function get () {
var this$1 = this;
var index = await this.druxt.getIndex();
var schemas = {};
for (var schemaType of ['view', 'form']) {
var resourceType = "entity_" + schemaType + "_display--entity_" + schemaType + "_display";
var displays = await this.druxt.getCollectionAll(resourceType);
var displays = (await Promise.all([].concat( ['view', 'form'].map(async function (schemaType) {
var resourceType = "entity_" + schemaType + "_display--entity_" + schemaType + "_display";
return (await this$1.druxt.getCollectionAll(
resourceType,
new DrupalJsonApiParams()
.addFields(resourceType, [
'targetEntityType',
'bundle',
'mode' ])
.addFilter('status', 1)
)).map(function (collection) { return collection.data.map(function (data) { return (Object.assign({}, {entityType: data.attributes.targetEntityType,
bundle: data.attributes.bundle,
mode: data.attributes.mode,
schemaType: schemaType,
filter: this$1.options.schema.filter},
index[[data.attributes.targetEntityType, data.attributes.bundle].join('--')])); }); })
}) ))).flat(2);
for (var collection of displays) {
for (var display of collection.data) {
var resource = index[[display.attributes.targetEntityType, display.attributes.bundle].join('--')];
var schemas = Object.fromEntries((await Promise.all([].concat( displays.map(function (config) { return this$1.getSchema(config); }) ))).map(function (schema) { return ([schema.id, schema.schema]); }));
var config = Object.assign({}, {entityType: display.attributes.targetEntityType,
bundle: display.attributes.bundle,
mode: display.attributes.mode,
schemaType: schemaType,
filter: this.options.schema.filter},
resource);
var schema = await this.getSchema(config, { data: display });
if (schema) {
schemas[schema.id] = schema.schema;
}
}
}
}
return { index: index, schemas: schemas }

@@ -289,0 +287,0 @@ };

@@ -1,1 +0,1 @@

var VueDrupalSchema=function(t,e,i,s,r){"use strict";e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;var n=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};n.prototype.generate=async function(){return this[this.config.schemaType]()},n.prototype.getResources=async function(t,e){return this.data[t]||(this.data[t]=await this.druxtSchema.druxt.getCollection(t,e)),this.data[t]},n.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 d=r;t.resourceFields&&t.resourceFields[r]&&t.resourceFields[r].publicName!==r&&(d=t.resourceFields[r].publicName),t.fields[d]={id:d,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},n.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 a=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 s.DruxtClient(t,this.options)};a.prototype.get=async function(){var t=await this.druxt.getIndex(),e={};for(var i of["view","form"]){var s="entity_"+i+"_display--entity_"+i+"_display",r=await this.druxt.getCollectionAll(s);for(var n of r)for(var a of n.data){var o=t[[a.attributes.targetEntityType,a.attributes.bundle].join("--")],d=Object.assign({},{entityType:a.attributes.targetEntityType,bundle:a.attributes.bundle,mode:a.attributes.mode,schemaType:i,filter:this.options.schema.filter},o),c=await this.getSchema(d,{data:a});c&&(e[c.id]=c.schema)}}return{index:t,schemas:e}},a.prototype.getSchema=async function(t,e){void 0===e&&(e={});var i=new n(t,Object.assign({},{druxtSchema:this},e));return!!i.isValid&&(await i.generate(),i)};var o=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 o=new a(r.baseUrl,r),d=(await o.get()).schemas;for(var c in d){var u=d[c];void 0!==u&&s.addTemplate({src:i.resolve(__dirname,"../nuxt/schema.json"),fileName:"schemas/"+c+".json",options:{schema:u}})}e.success("Druxt schema generated")}))};o.meta=require("../package.json");var d={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({},r.mapActions({getSchema:"druxtSchema/get"}))};return t.DruxtSchema=a,t.DruxtSchemaMixin=d,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=o,t}({},consola,path,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 c=r;t.resourceFields&&t.resourceFields[r]&&t.resourceFields[r].publicName!==r&&(c=t.resourceFields[r].publicName),t.fields[c]={id:c,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";return(await t.druxt.getCollectionAll(r,(new s.DrupalJsonApiParams).addFields(r,["targetEntityType","bundle","mode"]).addFilter("status",1))).map((function(s){return s.data.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([].concat(i.map((function(e){return t.getSchema(e)}))))).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 c=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),c=(await a.get()).schemas;for(var u in c){var d=c[u];void 0!==d&&s.addTemplate({src:i.resolve(__dirname,"../nuxt/schema.json"),fileName:"schemas/"+u+".json",options:{schema:d}})}e.success("Druxt schema generated")}))};c.meta=require("../package.json");var u={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=u,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=c,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'),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.

@@ -253,29 +253,26 @@ *

DruxtSchema.prototype.get = async function get () {
var this$1 = this;
var index = await this.druxt.getIndex();
var schemas = {};
for (var schemaType of ['view', 'form']) {
var resourceType = "entity_" + schemaType + "_display--entity_" + schemaType + "_display";
var displays = await this.druxt.getCollectionAll(resourceType);
var displays = (await Promise.all([].concat( ['view', 'form'].map(async function (schemaType) {
var resourceType = "entity_" + schemaType + "_display--entity_" + schemaType + "_display";
return (await this$1.druxt.getCollectionAll(
resourceType,
new drupalJsonapiParams.DrupalJsonApiParams()
.addFields(resourceType, [
'targetEntityType',
'bundle',
'mode' ])
.addFilter('status', 1)
)).map(function (collection) { return collection.data.map(function (data) { return (Object.assign({}, {entityType: data.attributes.targetEntityType,
bundle: data.attributes.bundle,
mode: data.attributes.mode,
schemaType: schemaType,
filter: this$1.options.schema.filter},
index[[data.attributes.targetEntityType, data.attributes.bundle].join('--')])); }); })
}) ))).flat(2);
for (var collection of displays) {
for (var display of collection.data) {
var resource = index[[display.attributes.targetEntityType, display.attributes.bundle].join('--')];
var schemas = Object.fromEntries((await Promise.all([].concat( displays.map(function (config) { return this$1.getSchema(config); }) ))).map(function (schema) { return ([schema.id, schema.schema]); }));
var config = Object.assign({}, {entityType: display.attributes.targetEntityType,
bundle: display.attributes.bundle,
mode: display.attributes.mode,
schemaType: schemaType,
filter: this.options.schema.filter},
resource);
var schema = await this.getSchema(config, { data: display });
if (schema) {
schemas[schema.id] = schema.schema;
}
}
}
}
return { index: index, schemas: schemas }

@@ -282,0 +279,0 @@ };

{
"name": "druxt-schema",
"version": "0.7.1",
"version": "0.7.2",
"description": "Entity Form and View mode schemas for Drupal driven frontends.",

@@ -18,3 +18,7 @@ "repository": {

],
"author": "Stuart Clark <stuart@realityloop.com> (realityloop.com)",
"author": {
"name": "Stuart Clark",
"email": "stuart@realityloop.com",
"url": "https://realityloop.com"
},
"license": "MIT",

@@ -21,0 +25,0 @@ "bugs": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc