druxt-schema 0.12.1 → 0.12.2-dev.20261118025746

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -245,13 +245,33 @@ class DruxtSchema {
245
245
  };
246
246
  this.druxt = new DruxtClient(baseUrl, this.options);
247
247
  }
248
+ async getDisplays(resourceType) {
249
+ const query = () => new DrupalJsonApiParams().addSort("drupal_internal__id");
250
+ try {
251
+ return await this.druxt.getCollectionAll(resourceType, query());
252
+ } catch (err) {
253
+ await this.druxt.getCollection(resourceType, query());
254
+ }
255
+ const index = await this.druxt.getIndex();
256
+ const bundles = {};
257
+ for (const key of Object.keys(index || {})) {
258
+ const [entityType, bundle] = key.split("--");
259
+ if (entityType && bundle)
260
+ (bundles[entityType] = bundles[entityType] || []).push(bundle);
261
+ }
262
+ return (await Promise.all(Object.keys(bundles).map(async (entityType) => {
263
+ const byType = await this.druxt.getCollection(resourceType, query().addFilter("targetEntityType", entityType));
264
+ if (!((byType.links || {}).next || {}).href)
265
+ return [byType];
266
+ return (await Promise.all(bundles[entityType].map((bundle) => this.druxt.getCollectionAll(resourceType, query().addFilter("targetEntityType", entityType).addFilter("bundle", bundle))))).flat();
267
+ }))).flat();
268
+ }
248
269
  async get() {
249
270
  const index = await this.druxt.getIndex();
250
271
  const displays = (await Promise.all([
251
272
  ...["view", "form"].map(async (schemaType) => {
252
273
  const resourceType = `entity_${schemaType}_display--entity_${schemaType}_display`;
253
- const query = new DrupalJsonApiParams().addSort("drupal_internal__id");
254
- const result = await this.druxt.getCollectionAll(resourceType, query);
274
+ const result = await this.getDisplays(resourceType);
255
275
  try {
256
276
  result.forEach((collection) => this.druxt.checkPermissions({ data: collection }));
257
277
  } catch (err) {
@@ -274,8 +294,7 @@ class DruxtSchema {
274
294
  if (!this.displayIds) {
275
295
  this.displayIds = Promise.all(["view", "form"].map(async (schemaType) => {
276
296
  const resourceType = `entity_${schemaType}_display--entity_${schemaType}_display`;
277
- const query = new DrupalJsonApiParams().addSort("drupal_internal__id");
278
- const result = await this.druxt.getCollectionAll(resourceType, query);
297
+ const result = await this.getDisplays(resourceType);
279
298
  return result.flatMap((collection) => (collection.data || []).filter((data) => !!data.attributes.status).map((data) => [data.attributes.targetEntityType, data.attributes.bundle, data.attributes.mode, schemaType].join("--")));
280
299
  })).then((ids) => new Set(ids.flat()));
281
300
  this.displayIds.catch(() => {
@@ -254,13 +254,33 @@ class DruxtSchema {
254
254
  };
255
255
  this.druxt = new druxt.DruxtClient(baseUrl, this.options);
256
256
  }
257
+ async getDisplays(resourceType) {
258
+ const query = () => new drupalJsonapiParams.DrupalJsonApiParams().addSort("drupal_internal__id");
259
+ try {
260
+ return await this.druxt.getCollectionAll(resourceType, query());
261
+ } catch (err) {
262
+ await this.druxt.getCollection(resourceType, query());
263
+ }
264
+ const index = await this.druxt.getIndex();
265
+ const bundles = {};
266
+ for (const key of Object.keys(index || {})) {
267
+ const [entityType, bundle] = key.split("--");
268
+ if (entityType && bundle)
269
+ (bundles[entityType] = bundles[entityType] || []).push(bundle);
270
+ }
271
+ return (await Promise.all(Object.keys(bundles).map(async (entityType) => {
272
+ const byType = await this.druxt.getCollection(resourceType, query().addFilter("targetEntityType", entityType));
273
+ if (!((byType.links || {}).next || {}).href)
274
+ return [byType];
275
+ return (await Promise.all(bundles[entityType].map((bundle) => this.druxt.getCollectionAll(resourceType, query().addFilter("targetEntityType", entityType).addFilter("bundle", bundle))))).flat();
276
+ }))).flat();
277
+ }
257
278
  async get() {
258
279
  const index = await this.druxt.getIndex();
259
280
  const displays = (await Promise.all([
260
281
  ...["view", "form"].map(async (schemaType) => {
261
282
  const resourceType = `entity_${schemaType}_display--entity_${schemaType}_display`;
262
- const query = new drupalJsonapiParams.DrupalJsonApiParams().addSort("drupal_internal__id");
263
- const result = await this.druxt.getCollectionAll(resourceType, query);
283
+ const result = await this.getDisplays(resourceType);
264
284
  try {
265
285
  result.forEach((collection) => this.druxt.checkPermissions({ data: collection }));
266
286
  } catch (err) {
@@ -283,8 +303,7 @@ class DruxtSchema {
283
303
  if (!this.displayIds) {
284
304
  this.displayIds = Promise.all(["view", "form"].map(async (schemaType) => {
285
305
  const resourceType = `entity_${schemaType}_display--entity_${schemaType}_display`;
286
- const query = new drupalJsonapiParams.DrupalJsonApiParams().addSort("drupal_internal__id");
287
- const result = await this.druxt.getCollectionAll(resourceType, query);
306
+ const result = await this.getDisplays(resourceType);
288
307
  return result.flatMap((collection) => (collection.data || []).filter((data) => !!data.attributes.status).map((data) => [data.attributes.targetEntityType, data.attributes.bundle, data.attributes.mode, schemaType].join("--")));
289
308
  })).then((ids) => new Set(ids.flat()));
290
309
  this.displayIds.catch(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "druxt-schema",
3
- "version": "0.12.1",
3
+ "version": "0.12.2-dev.20261118025746",
4
4
  "description": "Drupal Content Entity schema generator for Druxt with support for View and Form displays.",
5
5
  "keywords": [
6
6
  "cms",
@@ -46,10 +46,10 @@
46
46
  "dependencies": {
47
47
  "consola": "^2.15.3",
48
48
  "drupal-jsonapi-params": "^2.3.2",
49
- "druxt": "^0.25.1"
49
+ "druxt": "0.25.2-dev.20261118025746"
50
50
  },
51
51
  "devDependencies": {
52
- "axios": "0.34.0",
52
+ "axios": "0.35.0",
53
53
  "lodash": "^4.18.1"
54
54
  },
55
55
  "peerDependencies": {