druxt-schema 0.11.2 → 0.11.4-dev.20260920043715

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.
package/README.md CHANGED
@@ -1,58 +1,105 @@
1
- # Druxt.js Schema
1
+ <img src="./banner.svg" alt="DruxtSchema: content entity schema generation for displays and forms">
2
+
3
+ # DruxtSchema
2
4
 
3
5
  [![npm](https://badgen.net/npm/v/druxt-schema)](https://www.npmjs.com/package/druxt-schema)
4
- [![CircleCI](https://circleci.com/gh/druxt/druxt-schema.svg?style=svg)](https://circleci.com/gh/druxt/druxt-schema)
5
- [![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)
6
- [![codecov](https://codecov.io/gh/druxt/druxt-schema/branch/develop/graph/badge.svg)](https://codecov.io/gh/druxt/druxt-schema)
6
+ [![CI](https://github.com/druxt/druxt.js/actions/workflows/ci.yml/badge.svg)](https://github.com/druxt/druxt.js/actions/workflows/ci.yml)
7
+ [![Known Vulnerabilities](https://snyk.io/test/github/druxt/druxt.js/badge.svg?targetFile=package.json)](https://snyk.io/test/github/druxt/druxt.js?targetFile=package.json)
8
+ [![codecov](https://codecov.io/gh/druxt/druxt.js/branch/develop/graph/badge.svg)](https://codecov.io/gh/druxt/druxt.js)
7
9
 
8
10
  > Drupal Content Entity schema generator for Druxt with support for View and Form displays.
9
11
 
10
- ## Links
12
+ DruxtSchema turns Drupal display configuration into build-time schemas. For
13
+ each entity type, bundle and display mode it records which fields render, in
14
+ what order and with which formatter settings, and stores the result in a Vuex
15
+ store. The Entity module renders from these schemas at runtime, so your
16
+ frontend follows Drupal's display configuration without querying it on every
17
+ request.
11
18
 
12
- - Druxt.js: https://druxtjs.org
13
- - Documentation: https://druxtjs.org/modules/schema
14
- - Community Discord server: https://discord.druxtjs.org
19
+ ## Features
15
20
 
16
- ## Install
21
+ - **Generates schemas on build**
22
+ - **Configurable schema filter**
23
+ - **View and Form schemas**
17
24
 
18
- `$ npm install druxt-schema`
25
+ ---
19
26
 
20
- ## Usage
27
+ ## Installation
21
28
 
22
- Add module to `nuxt.config.js`
29
+ > Included with [`druxt-site`](https://druxtjs.org/modules/site). Install it separately only when composing modules yourself.
23
30
 
24
- ```js
25
- module.exports = {
26
- modules: [
27
- ...
28
- 'druxt-schema'
29
- ],
31
+ 1. Install the package:
32
+
33
+ ```sh
34
+ npm i druxt-schema
35
+ ```
36
+
37
+ 2. Add the module to `nuxt.config.js`:
38
+
39
+ ```js
40
+ export default {
41
+ modules: ['druxt-schema'],
42
+ };
43
+ ```
44
+
45
+ ---
46
+
47
+ ## Settings
48
+
49
+ ### Filter schemas
50
+
51
+ The Schema module will generate a schema for all available content entity type by bundle, display mode and schema type.
30
52
 
53
+ This generated schemas can be filtered by providing a `druxt.schema.filter` setting in the `nuxt.config.js` file:
54
+
55
+ ```js
56
+ export default {
57
+ modules: ['druxt-schema'],
31
58
  druxt: {
32
- baseUrl: 'https://example.com',
33
59
  schema: {
34
- filter: ['node--.*?--view']
35
- }
36
- }
37
- }
60
+ filter: [
61
+ // List specific schema files to generate.
62
+ 'node--page--default--view',
63
+ 'media--image--square--view',
64
+ // Or use a regular expression.
65
+ '.*?--form',
66
+ ],
67
+ },
68
+ },
69
+ };
38
70
  ```
39
71
 
72
+ ---
73
+
74
+ ## API
75
+
76
+ - For the full class and store reference, see the
77
+ [DruxtSchema API documentation](https://druxtjs.org/api/packages/schema).
78
+
79
+ ---
80
+
40
81
  ## Options
41
82
 
42
83
  ### Druxt options
43
84
 
44
85
  These options are available to all Druxt modules.
45
86
 
46
- | Option | Type | Required | Default | Description |
47
- | --- | --- | --- | --- | --- |
48
- | `axios` | `object` | No | `{}` | [Axios instance settings](https://github.com/axios/axios#axioscreateconfig). |
49
- | `baseUrl` | `string` | Yes | `null` | Base URL for the Drupal installation. |
50
- | `endpoint` | `string` | No | `/jsonapi` | JSON:API Endpoint of the Drupal installation. |
87
+ | Option | Type | Required | Default | Description |
88
+ | ---------- | -------- | -------- | ---------- | ---------------------------------------------------------------------------- |
89
+ | `axios` | `object` | No | `{}` | [Axios instance settings](https://github.com/axios/axios#axioscreateconfig). |
90
+ | `baseUrl` | `string` | Yes | `null` | Base URL for the Drupal installation. |
91
+ | `endpoint` | `string` | No | `/jsonapi` | JSON:API Endpoint of the Drupal installation. |
51
92
 
52
93
  ### Druxt Schema options
53
94
 
54
95
  These options are specific to this module.
55
96
 
56
- | Option | Type | Required | Default | Description |
57
- | --- | --- | --- | --- | --- |
58
- | `schema.filter` | `array` | No | `[]` | Array of regular expression rules to filter generated schemas. |
97
+ | Option | Type | Required | Default | Description |
98
+ | --------------- | ------- | -------- | ------- | -------------------------------------------------------------- |
99
+ | `schema.filter` | `array` | No | `[]` | Array of regular expression rules to filter generated schemas. |
100
+
101
+ ## Links
102
+
103
+ - DruxtJS: https://druxtjs.org
104
+ - Documentation: https://druxtjs.org/modules/schema
105
+ - Community Discord server: https://discord.druxtjs.org
package/banner.svg ADDED
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1280 320" width="1280" height="320" role="img" aria-label="druxt-schema: Content Entity schema generation for displays and forms."><defs><linearGradient id="g" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#1f2937"/><stop offset="0.7" stop-color="#2f495e"/><stop offset="1" stop-color="#36566e"/></linearGradient></defs><rect width="1280" height="320" rx="16" fill="url(#g)"/><rect x="250" y="85" width="150" height="150" rx="32" fill="rgba(229,236,241,0.07)"/><g transform="translate(277,112) scale(4)" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9.75 4.5C7.95 4.5 7 5.45 7 7.25v2.1c0 1.35-.85 2.25-2.5 2.65 1.65.4 2.5 1.3 2.5 2.65v2.1c0 1.8.95 2.75 2.75 2.75" stroke="#7cc5f1"/><path d="M14.25 4.5c1.8 0 2.75.95 2.75 2.75v2.1c0 1.35.85 2.25 2.5 2.65-1.65.4-2.5 1.3-2.5 2.65v2.1c0 1.8-.95 2.75-2.75 2.75" stroke="#68cb9f"/></g><text x="440" y="150" style="font-family:ui-sans-serif,system-ui,sans-serif" font-size="64" font-weight="700" letter-spacing="-1" fill="#eef2f6">Schema</text><text x="688" y="150" style="font-family:ui-monospace,Menlo,Consolas,monospace" font-size="26" fill="#7cc5f1">druxt-schema</text><text x="440" y="196" style="font-family:ui-sans-serif,system-ui,sans-serif" font-size="25" fill="rgba(229,236,241,0.75)">Content Entity schema generation for displays and forms.</text><g transform="translate(440,236) scale(0.0994)"><path d="M139 330l-1-2c-2-4-2-8-1-13H29L189 31l67 121 22-16-67-121c-1-2-9-14-22-14-6 0-15 2-22 15L5 303c-1 3-8 16-2 27 4 6 10 12 24 12h136c-14 0-21-6-24-12z" fill="#3498DB"/><path d="M447 304L317 70c-2-2-9-15-22-15-6 0-15 3-22 15l-17 28v54l39-67 129 230h-49a23 23 0 0 1-2 14l-1 1c-6 11-21 12-23 12h76c3 0 17-1 24-12 3-5 5-14-2-26z" fill="#108775"/><path d="M376 330v-1l1-2c1-4 2-8 1-12l-4-12-102-178-15-27h-1l-15 27-102 178-4 12a24 24 0 0 0 2 15c4 6 10 12 24 12h190c3 0 18-1 25-12zM256 152l93 163H163l93-163z" fill="#E5ECF1"/></g><text x="492" y="260" style="font-family:ui-sans-serif,system-ui,sans-serif" font-size="17" font-weight="600" fill="rgba(229,236,241,0.85)">druxtjs.org</text></svg>
@@ -4,6 +4,7 @@ import { DrupalJsonApiParams } from 'drupal-jsonapi-params';
4
4
  import { DruxtClient } from 'druxt';
5
5
  import { mapActions } from 'vuex';
6
6
 
7
+ const resourceCache = new WeakMap();
7
8
  class Schema {
8
9
  constructor(config, { druxtSchema, data }) {
9
10
  if (config.resourceFields) {
@@ -50,8 +51,17 @@ class Schema {
50
51
  async getResources(resource, query) {
51
52
  if (this.data[resource])
52
53
  return this.data[resource];
53
- this.data[resource] = await this.druxtSchema.druxt.getCollection(resource, query);
54
- return this.data[resource];
54
+ const client = this.druxtSchema.druxt;
55
+ if (!resourceCache.has(client))
56
+ resourceCache.set(client, new Map());
57
+ const cache = resourceCache.get(client);
58
+ const cacheKey = JSON.stringify([resource, query]);
59
+ if (!cache.has(cacheKey)) {
60
+ const request = client.getCollection(resource, query);
61
+ cache.set(cacheKey, request);
62
+ request.catch(() => cache.delete(cacheKey));
63
+ }
64
+ return cache.get(cacheKey);
55
65
  }
56
66
  async form() {
57
67
  const entityFormDisplay = await this.getResources("entity_form_display--entity_form_display", { "filter[drupal_internal__id]": this.displayId }).then((res) => Array.isArray(res.data) ? res.data[0] : res);
@@ -12,6 +12,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
12
12
 
13
13
  const consola__default = /*#__PURE__*/_interopDefaultLegacy(consola);
14
14
 
15
+ const resourceCache = new WeakMap();
15
16
  class Schema {
16
17
  constructor(config, { druxtSchema, data }) {
17
18
  if (config.resourceFields) {
@@ -58,8 +59,17 @@ class Schema {
58
59
  async getResources(resource, query) {
59
60
  if (this.data[resource])
60
61
  return this.data[resource];
61
- this.data[resource] = await this.druxtSchema.druxt.getCollection(resource, query);
62
- return this.data[resource];
62
+ const client = this.druxtSchema.druxt;
63
+ if (!resourceCache.has(client))
64
+ resourceCache.set(client, new Map());
65
+ const cache = resourceCache.get(client);
66
+ const cacheKey = JSON.stringify([resource, query]);
67
+ if (!cache.has(cacheKey)) {
68
+ const request = client.getCollection(resource, query);
69
+ cache.set(cacheKey, request);
70
+ request.catch(() => cache.delete(cacheKey));
71
+ }
72
+ return cache.get(cacheKey);
63
73
  }
64
74
  async form() {
65
75
  const entityFormDisplay = await this.getResources("entity_form_display--entity_form_display", { "filter[drupal_internal__id]": this.displayId }).then((res) => Array.isArray(res.data) ? res.data[0] : res);
package/icon.svg ADDED
@@ -0,0 +1,4 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
2
+ <path stroke="#036397" d="M9.75 4.5C7.95 4.5 7 5.45 7 7.25v2.1c0 1.35-.85 2.25-2.5 2.65 1.65.4 2.5 1.3 2.5 2.65v2.1c0 1.8.95 2.75 2.75 2.75" />
3
+ <path stroke="#3b8070" d="M14.25 4.5c1.8 0 2.75.95 2.75 2.75v2.1c0 1.35.85 2.25 2.5 2.65-1.65.4-2.5 1.3-2.5 2.65v2.1c0 1.8-.95 2.75-2.75 2.75" />
4
+ </svg>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "druxt-schema",
3
- "version": "0.11.2",
3
+ "version": "0.11.4-dev.20260920043715",
4
4
  "description": "Drupal Content Entity schema generator for Druxt with support for View and Form displays.",
5
5
  "keywords": [
6
6
  "cms",
@@ -25,6 +25,7 @@
25
25
  "url": "git+https://github.com/druxt/druxt.js"
26
26
  },
27
27
  "license": "MIT",
28
+ "author": "Stuart Clark <stuart@druxtjs.org>",
28
29
  "exports": {
29
30
  ".": {
30
31
  "require": "./dist/druxt-schema.ssr.js",
@@ -36,15 +37,20 @@
36
37
  "module": "dist/druxt-schema.esm.js",
37
38
  "files": [
38
39
  "dist",
39
- "templates"
40
+ "templates",
41
+ "icon.svg",
42
+ "banner.svg"
40
43
  ],
41
44
  "dependencies": {
42
45
  "consola": "^2.15.3",
43
- "drupal-jsonapi-params": "^2.2.0",
44
- "druxt": "^0.22.0"
46
+ "drupal-jsonapi-params": "^2.3.2",
47
+ "druxt": "0.24.1-dev.20260920043715"
48
+ },
49
+ "devDependencies": {
50
+ "axios": "0.33.0"
45
51
  },
46
52
  "optionalDependencies": {
47
- "vue": "^2.7.14",
53
+ "vue": "^2.7.16",
48
54
  "vuex": "^3.6.2"
49
55
  },
50
56
  "publishConfig": {