druxt 0.18.2 → 0.19.1

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.
@@ -38,6 +38,14 @@ export default {
38
38
 
39
39
  /** */
40
40
  props: {
41
+ /**
42
+ * The resource langcode.
43
+ */
44
+ langcode: {
45
+ type: String,
46
+ default: undefined
47
+ },
48
+
41
49
  /**
42
50
  * The module value.
43
51
  *
@@ -170,7 +178,17 @@ export default {
170
178
  this.component = component
171
179
  },
172
180
 
181
+ computed: {
182
+ lang: ({ langcode, $route }) => langcode || ($route.meta || {}).langcode
183
+ },
184
+
173
185
  watch: {
186
+ lang(to, from) {
187
+ if (to !== from) {
188
+ this.$fetch()
189
+ }
190
+ },
191
+
174
192
  model() {
175
193
  if (this.component.props && this.component.props.value !== this.model) {
176
194
  this.component.props.value = this.model
@@ -237,7 +255,12 @@ export default {
237
255
  let components = []
238
256
  for (const set of options.filter(set => Array.isArray(set))) {
239
257
  const variants = []
240
- components = [...components, ...set.filter((o) => o).map(item => {
258
+
259
+ // Add langcode suffix to all sets.
260
+ // console.log('SET', set)
261
+ // set.push(this.lang)
262
+
263
+ for (const item of set.filter((o) => o)) {
241
264
  // Build array of name parts.
242
265
  const parts = variants.length ? [...variants[0].parts] : []
243
266
  parts.push(pascalCase(splitByCase(item)))
@@ -245,14 +268,26 @@ export default {
245
268
  // Convert parts into a pascalCase component name.
246
269
  const name = pascalCase([this.$options.name, ...parts])
247
270
 
248
- // Check if component is globally registered.
249
- const global = !!this.$options.components[name]
250
-
251
271
  // Store set variant data to be used in next set item.
252
272
  variants.unshift({ global, name, parts })
253
273
 
254
- return { global, name, parts }
255
- })]
274
+ // Add langcode suffixed component option.
275
+ if (this.lang) {
276
+ const langcodeName = pascalCase([this.$options.name, ...parts, this.lang])
277
+ components.push({
278
+ global: !!this.$options.components[langcodeName],
279
+ name: langcodeName,
280
+ parts: [...parts, this.lang]
281
+ })
282
+ }
283
+
284
+ // And component option.
285
+ components.push({
286
+ global: !!this.$options.components[name],
287
+ name,
288
+ parts
289
+ })
290
+ }
256
291
  }
257
292
 
258
293
  // Filter unique components.
@@ -280,7 +315,10 @@ export default {
280
315
  return {}
281
316
  }
282
317
 
283
- const propsData = this.$options.druxt.propsData.call(this, this)
318
+ const propsData = {
319
+ langcode: this.lang,
320
+ ...this.$options.druxt.propsData.call(this, this)
321
+ }
284
322
 
285
323
  // Props.
286
324
  const props = {}
@@ -391,8 +429,9 @@ export default {
391
429
  props: (this.wrapper || {}).propsData || undefined,
392
430
  }
393
431
 
394
- // Return only wrapper if fetch state is still pending.
395
- if (this.$fetchState.pending && this.component.is === 'DruxtWrapper') {
432
+ // Return only wrapper if fetch state is still pending and Druxt hasn't set
433
+ // the available component options.
434
+ if (this.$fetchState.pending && !this.component.options.length) {
396
435
  return h((this.wrapper || {}).component || 'div', wrapperData)
397
436
  }
398
437
 
package/dist/druxt.esm.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import chalk from 'chalk';
2
+ import { DrupalJsonApiParams } from 'drupal-jsonapi-params';
2
3
  import { join, resolve } from 'path';
3
4
  import axios from 'axios';
4
5
  import { stringify } from 'querystring';
@@ -6,168 +7,6 @@ import consola from 'consola';
6
7
  import merge from 'deepmerge';
7
8
  import md5 from 'md5';
8
9
  import Vue from 'vue';
9
- import { DrupalJsonApiParams } from 'drupal-jsonapi-params';
10
-
11
- var name = "druxt";
12
- var version = "0.18.2";
13
- var description = "The Fully Decoupled Drupal Framework for Nuxt.js.";
14
- var keywords = [
15
- "cms",
16
- "decoupled",
17
- "drupal",
18
- "druxt",
19
- "headless",
20
- "jsonapi",
21
- "json:api",
22
- "nuxt",
23
- "module",
24
- "vue"
25
- ];
26
- var homepage = "https://druxtjs.org";
27
- var bugs = {
28
- url: "https://github.com/druxt/druxt.js/issues"
29
- };
30
- var repository = {
31
- type: "git",
32
- url: "git+https://github.com/druxt/druxt.js"
33
- };
34
- var license = "MIT";
35
- var exports = {
36
- ".": {
37
- require: "./dist/druxt.ssr.js",
38
- "import": "./dist/druxt.esm.js"
39
- },
40
- "./components/*": "./dist/components/*"
41
- };
42
- var main = "dist/druxt.ssr.js";
43
- var module = "dist/druxt.esm.js";
44
- var files = [
45
- "dist",
46
- "stories",
47
- "templates"
48
- ];
49
- var dependencies = {
50
- "@nuxtjs/axios": "^5.13.6",
51
- "@nuxtjs/proxy": "^2.1.0",
52
- chalk: "^4.1.2",
53
- deepmerge: "^4.2.2",
54
- "drupal-jsonapi-params": "^2.0.0",
55
- md5: "^2.3.0",
56
- querystring: "^0.2.0",
57
- scule: "^0.2.0"
58
- };
59
- var devDependencies = {
60
- "@storybook/addon-docs": "^6.4.13"
61
- };
62
- var peerDependencies = {
63
- axios: "*",
64
- consola: "*"
65
- };
66
- var optionalDependencies = {
67
- "core-js": "^3.16.1",
68
- vue: "^2.6.14",
69
- vuex: "^3.6.2"
70
- };
71
- var publishConfig = {
72
- access: "public"
73
- };
74
- var meta = {
75
- name: name,
76
- version: version,
77
- description: description,
78
- keywords: keywords,
79
- homepage: homepage,
80
- bugs: bugs,
81
- repository: repository,
82
- license: license,
83
- exports: exports,
84
- main: main,
85
- module: module,
86
- files: files,
87
- dependencies: dependencies,
88
- devDependencies: devDependencies,
89
- peerDependencies: peerDependencies,
90
- optionalDependencies: optionalDependencies,
91
- publishConfig: publishConfig
92
- };
93
-
94
- const DruxtNuxtModule = function(moduleOptions = {}) {
95
- var _a;
96
- const options = {
97
- endpoint: "/jsonapi",
98
- ...moduleOptions,
99
- ...(this.options || {}).druxt
100
- };
101
- if (options.proxy) {
102
- const proxies = {};
103
- if ((options.proxy || {}).api) {
104
- proxies[options.endpoint] = options.baseUrl;
105
- proxies["/router/translate-path"] = options.baseUrl;
106
- }
107
- if ((options.proxy || {}).files) {
108
- const filesPath = typeof options.proxy.files === "string" ? options.proxy.files : "default";
109
- proxies[`/sites/${filesPath}/files`] = options.baseUrl;
110
- }
111
- if (this.options.proxy) {
112
- if (Array.isArray(this.options.proxy)) {
113
- this.options.proxy = [
114
- ...Object.keys(proxies).map((path) => `${options.baseUrl}${path}`),
115
- ...this.options.proxy
116
- ];
117
- } else {
118
- this.options.proxy = {
119
- ...proxies,
120
- ...this.options.proxy
121
- };
122
- }
123
- } else {
124
- this.options.proxy = proxies;
125
- }
126
- this.addModule("@nuxtjs/proxy");
127
- }
128
- if (!options.axios) {
129
- this.options.axios = {
130
- baseURL: options.baseUrl,
131
- proxy: !!(options.proxy || {}).api,
132
- ...this.options.axios
133
- };
134
- this.addModule("@nuxtjs/axios");
135
- }
136
- this.nuxt.hook("components:dirs", (dirs) => {
137
- dirs.push({ path: join(__dirname, "components") });
138
- });
139
- this.addPlugin({
140
- src: resolve(__dirname, "../templates/plugin.js"),
141
- fileName: "druxt.js",
142
- options
143
- });
144
- const extendPlugins = this.options.extendPlugins;
145
- this.options.extendPlugins = (plugins) => {
146
- plugins = typeof extendPlugins === "function" ? extendPlugins(plugins) : plugins;
147
- const axiosIndex = plugins.findIndex(({ src }) => src === `${this.options.buildDir}/axios.js`);
148
- const axiosPlugin = plugins[axiosIndex];
149
- plugins.splice(axiosIndex, 1);
150
- const druxtIndex = plugins.findIndex(({ src }) => src === `${this.options.buildDir}/druxt.js`);
151
- const druxtPlugin = plugins[druxtIndex];
152
- plugins.splice(druxtIndex, 1);
153
- plugins = [axiosPlugin, druxtPlugin, ...plugins];
154
- return plugins;
155
- };
156
- this.addPlugin({
157
- src: resolve(__dirname, "../templates/store.js"),
158
- fileName: "store/druxt.js",
159
- options
160
- });
161
- this.options.store = true;
162
- this.options.components = (_a = this.options.components) != null ? _a : true;
163
- this.options.cli.badgeMessages.push(`${chalk.blue.bold("Druxt")} @ v${meta.version}`);
164
- this.options.cli.badgeMessages.push(`${chalk.bold("API:")} ${chalk.blue.underline(options.baseUrl + options.endpoint)}`);
165
- this.nuxt.hook("storybook:config", async ({ stories }) => {
166
- stories.push("druxt/stories/*.stories.mdx");
167
- stories.push("druxt/dist/components/*.stories.mdx");
168
- stories.push("druxt/dist/components/*.stories.mjs");
169
- });
170
- };
171
10
 
172
11
  class DruxtClient {
173
12
  constructor(baseUrl, options = {}) {
@@ -183,7 +22,7 @@ class DruxtClient {
183
22
  } else {
184
23
  this.axios = axios.create({
185
24
  ...options.axios || {},
186
- baseURL: baseUrl
25
+ baseURL: baseUrl && !(options.proxy || {}).api ? baseUrl : void 0
187
26
  });
188
27
  }
189
28
  if (options.debug) {
@@ -201,6 +40,7 @@ class DruxtClient {
201
40
  jsonapiResourceConfig: "jsonapi_resource_config--jsonapi_resource_config",
202
41
  ...options
203
42
  };
43
+ this.index = {};
204
44
  }
205
45
  addHeaders(headers) {
206
46
  if (typeof headers === "undefined") {
@@ -250,11 +90,11 @@ class DruxtClient {
250
90
  }
251
91
  }
252
92
  }
253
- async createResource(resource) {
93
+ async createResource(resource, prefix = "") {
254
94
  if (resource.id) {
255
- return this.updateResource(resource);
95
+ return this.updateResource(resource, prefix);
256
96
  }
257
- const { href } = await this.getIndex(resource.type);
97
+ const { href } = await this.getIndex(resource.type, prefix);
258
98
  if (!href) {
259
99
  return false;
260
100
  }
@@ -301,8 +141,8 @@ class DruxtClient {
301
141
  this.error(err, { url });
302
142
  }
303
143
  }
304
- async getCollection(type, query) {
305
- const { href } = await this.getIndex(type);
144
+ async getCollection(type, query, prefix) {
145
+ const { href } = await this.getIndex(type, prefix);
306
146
  if (!href) {
307
147
  return false;
308
148
  }
@@ -310,25 +150,25 @@ class DruxtClient {
310
150
  const { data } = await this.get(url);
311
151
  return data;
312
152
  }
313
- async getCollectionAll(type, query) {
153
+ async getCollectionAll(type, query, prefix) {
314
154
  const collections = [];
315
- let res = await this.getCollection(type, query);
155
+ let res = await this.getCollection(type, query, prefix);
316
156
  collections.push(res);
317
157
  while (((res.links || {}).next || {}).href) {
318
158
  query = res.links.next.href.split("?")[1];
319
- res = await this.getCollection(type, query);
159
+ res = await this.getCollection(type, query, prefix);
320
160
  collections.push(res);
321
161
  }
322
162
  return collections;
323
163
  }
324
- async getIndex(resource) {
325
- if (this.index && !resource) {
326
- return this.index;
164
+ async getIndex(resource, prefix) {
165
+ if ((this.index || {})[prefix] && !resource) {
166
+ return this.index[prefix];
327
167
  }
328
- if (this.index && resource) {
329
- return this.index[resource] ? this.index[resource] : false;
168
+ if ((this.index || {})[prefix] && resource) {
169
+ return this.index[prefix][resource] ? this.index[prefix][resource] : false;
330
170
  }
331
- const url = this.options.endpoint;
171
+ const url = [prefix, this.options.endpoint].join("");
332
172
  const { data } = await this.get(url);
333
173
  let index = data.links;
334
174
  if (typeof index !== "object") {
@@ -363,14 +203,14 @@ class DruxtClient {
363
203
  };
364
204
  }
365
205
  }
366
- this.index = index;
367
- return resource ? this.index[resource] || false : this.index;
206
+ this.index[prefix] = index;
207
+ return resource ? this.index[prefix][resource] || false : this.index[prefix];
368
208
  }
369
- async getRelated(type, id, related, query) {
209
+ async getRelated(type, id, related, query, prefix = "") {
370
210
  if (!id || !type || !related) {
371
211
  return false;
372
212
  }
373
- let { href } = await this.getIndex(type);
213
+ let { href } = await this.getIndex(type, prefix);
374
214
  if (!href) {
375
215
  href = this.options.endpoint + "/" + type.replace("--", "/");
376
216
  }
@@ -378,11 +218,11 @@ class DruxtClient {
378
218
  const { data } = await this.get(url);
379
219
  return data;
380
220
  }
381
- async getResource(type, id, query) {
221
+ async getResource(type, id, query, prefix) {
382
222
  if (!id || !type) {
383
223
  return false;
384
224
  }
385
- let { href } = await this.getIndex(type);
225
+ let { href } = await this.getIndex(type, prefix);
386
226
  if (!href) {
387
227
  href = this.options.endpoint + "/" + type.replace("--", "/");
388
228
  }
@@ -390,8 +230,8 @@ class DruxtClient {
390
230
  const { data } = await this.get(url);
391
231
  return data;
392
232
  }
393
- async updateResource(resource) {
394
- const { href } = await this.getIndex(resource.type);
233
+ async updateResource(resource, prefix) {
234
+ const { href } = await this.getIndex(resource.type, prefix);
395
235
  if (!href) {
396
236
  return false;
397
237
  }
@@ -410,15 +250,189 @@ class DruxtClient {
410
250
  }
411
251
  }
412
252
 
253
+ var name = "druxt";
254
+ var version = "0.19.1";
255
+ var description = "The Fully Decoupled Drupal Framework for Nuxt.js.";
256
+ var keywords = [
257
+ "cms",
258
+ "decoupled",
259
+ "drupal",
260
+ "druxt",
261
+ "headless",
262
+ "jsonapi",
263
+ "json:api",
264
+ "nuxt",
265
+ "module",
266
+ "vue"
267
+ ];
268
+ var homepage = "https://druxtjs.org";
269
+ var bugs = {
270
+ url: "https://github.com/druxt/druxt.js/issues"
271
+ };
272
+ var repository = {
273
+ type: "git",
274
+ url: "git+https://github.com/druxt/druxt.js"
275
+ };
276
+ var license = "MIT";
277
+ var exports = {
278
+ ".": {
279
+ require: "./dist/druxt.ssr.js",
280
+ "import": "./dist/druxt.esm.js"
281
+ },
282
+ "./components/*": "./dist/components/*"
283
+ };
284
+ var main = "dist/druxt.ssr.js";
285
+ var module = "dist/druxt.esm.js";
286
+ var files = [
287
+ "dist",
288
+ "stories",
289
+ "templates"
290
+ ];
291
+ var dependencies = {
292
+ "@nuxtjs/axios": "^5.13.6",
293
+ "@nuxtjs/proxy": "^2.1.0",
294
+ chalk: "^4.1.2",
295
+ deepmerge: "^4.2.2",
296
+ "drupal-jsonapi-params": "^2.0.0",
297
+ md5: "^2.3.0",
298
+ querystring: "^0.2.1",
299
+ scule: "^0.2.1"
300
+ };
301
+ var devDependencies = {
302
+ "@storybook/addon-docs": "^6.4.22"
303
+ };
304
+ var peerDependencies = {
305
+ axios: "*",
306
+ consola: "*"
307
+ };
308
+ var optionalDependencies = {
309
+ "core-js": "^3.22.5",
310
+ vue: "^2.6.14",
311
+ vuex: "^3.6.2"
312
+ };
313
+ var publishConfig = {
314
+ access: "public"
315
+ };
316
+ var meta = {
317
+ name: name,
318
+ version: version,
319
+ description: description,
320
+ keywords: keywords,
321
+ homepage: homepage,
322
+ bugs: bugs,
323
+ repository: repository,
324
+ license: license,
325
+ exports: exports,
326
+ main: main,
327
+ module: module,
328
+ files: files,
329
+ dependencies: dependencies,
330
+ devDependencies: devDependencies,
331
+ peerDependencies: peerDependencies,
332
+ optionalDependencies: optionalDependencies,
333
+ publishConfig: publishConfig
334
+ };
335
+
336
+ const DruxtNuxtModule = async function(moduleOptions = {}) {
337
+ var _a;
338
+ const options = {
339
+ endpoint: "/jsonapi",
340
+ ...moduleOptions,
341
+ ...(this.options || {}).druxt
342
+ };
343
+ const druxt = new DruxtClient(options.baseUrl, {
344
+ ...options,
345
+ proxy: { ...options.proxy || {}, api: false }
346
+ });
347
+ if (options.proxy) {
348
+ const proxies = {};
349
+ if ((options.proxy || {}).api) {
350
+ proxies[options.endpoint] = options.baseUrl;
351
+ const languageResourceType = "configurable_language--configurable_language";
352
+ if (await druxt.getIndex(languageResourceType)) {
353
+ const query = new DrupalJsonApiParams().addFields(languageResourceType, ["drupal_internal__id"]);
354
+ const languages = (await druxt.getCollectionAll(languageResourceType, query) || []).map((o) => o.data).flat().filter((o) => !["und", "zxx"].includes(((o || {}).attributes || {}).drupal_internal__id)).map((o) => o.attributes.drupal_internal__id);
355
+ for (const langcode of languages) {
356
+ proxies[`/${langcode}${options.endpoint}`] = options.baseUrl;
357
+ }
358
+ }
359
+ proxies["/router/translate-path"] = options.baseUrl;
360
+ }
361
+ if ((options.proxy || {}).files) {
362
+ const filesPath = typeof options.proxy.files === "string" ? options.proxy.files : "default";
363
+ proxies[`/sites/${filesPath}/files`] = options.baseUrl;
364
+ }
365
+ if (this.options.proxy) {
366
+ if (Array.isArray(this.options.proxy)) {
367
+ this.options.proxy = [
368
+ ...Object.keys(proxies).map((path) => `${options.baseUrl}${path}`),
369
+ ...this.options.proxy
370
+ ];
371
+ } else {
372
+ this.options.proxy = {
373
+ ...proxies,
374
+ ...this.options.proxy
375
+ };
376
+ }
377
+ } else {
378
+ this.options.proxy = proxies;
379
+ }
380
+ this.addModule("@nuxtjs/proxy");
381
+ }
382
+ if (!options.axios) {
383
+ this.options.axios = {
384
+ baseURL: options.baseUrl,
385
+ proxy: !!(options.proxy || {}).api,
386
+ ...this.options.axios
387
+ };
388
+ this.addModule("@nuxtjs/axios");
389
+ }
390
+ this.nuxt.hook("components:dirs", (dirs) => {
391
+ dirs.push({ path: join(__dirname, "components") });
392
+ });
393
+ this.addPlugin({
394
+ src: resolve(__dirname, "../templates/plugin.js"),
395
+ fileName: "druxt.js",
396
+ options
397
+ });
398
+ const extendPlugins = this.options.extendPlugins;
399
+ this.options.extendPlugins = (plugins) => {
400
+ plugins = typeof extendPlugins === "function" ? extendPlugins(plugins) : plugins;
401
+ const axiosIndex = plugins.findIndex(({ src }) => src === `${this.options.buildDir}/axios.js`);
402
+ const axiosPlugin = plugins[axiosIndex];
403
+ plugins.splice(axiosIndex, 1);
404
+ const druxtIndex = plugins.findIndex(({ src }) => src === `${this.options.buildDir}/druxt.js`);
405
+ const druxtPlugin = plugins[druxtIndex];
406
+ plugins.splice(druxtIndex, 1);
407
+ plugins = [axiosPlugin, druxtPlugin, ...plugins];
408
+ return plugins;
409
+ };
410
+ this.addPlugin({
411
+ src: resolve(__dirname, "../templates/store.js"),
412
+ fileName: "store/druxt.js",
413
+ options
414
+ });
415
+ this.options.store = true;
416
+ this.options.components = (_a = this.options.components) != null ? _a : true;
417
+ this.options.cli.badgeMessages.push(`${chalk.blue.bold("Druxt")} @ v${meta.version}`);
418
+ this.options.cli.badgeMessages.push(`${chalk.bold("API:")} ${chalk.blue.underline(options.baseUrl + options.endpoint)}`);
419
+ this.nuxt.hook("storybook:config", async ({ stories }) => {
420
+ stories.push("druxt/stories/*.stories.mdx");
421
+ stories.push("druxt/dist/components/*.stories.mdx");
422
+ stories.push("druxt/dist/components/*.stories.mjs");
423
+ });
424
+ };
425
+
413
426
  const getDrupalJsonApiParams = (query) => {
414
427
  return new DrupalJsonApiParams().initialize(query);
415
428
  };
416
429
 
417
- const dehydrateResources = ({ commit, queryObject, resources }) => {
430
+ const dehydrateResources = ({ commit, queryObject, resources, prefix }) => {
418
431
  return (resources || []).map((data) => {
419
432
  const link = decodeURI(((data.links || {}).self || {}).href || "");
420
433
  const href = typeof (queryObject.fields || {})[data.type] === "string" ? [link.split("?")[0], `fields[${data.type}]=${queryObject.fields[data.type]}`].join("?") : link;
421
434
  commit("druxt/addResource", {
435
+ prefix,
422
436
  resource: {
423
437
  data,
424
438
  links: { self: { href } }
@@ -439,21 +453,23 @@ const DruxtStore = ({ store }) => {
439
453
  resources: {}
440
454
  }),
441
455
  mutations: {
442
- addCollection(state, { collection, type, hash }) {
456
+ addCollection(state, { collection, type, hash, prefix }) {
443
457
  if (!state.collections[type])
444
458
  Vue.set(state.collections, type, {});
459
+ if (!state.collections[type][hash])
460
+ Vue.set(state.collections[type], hash, {});
445
461
  const link = decodeURI((((collection || {}).links || {}).self || {}).href || "");
446
462
  const query = link.split("?")[1] || "";
447
463
  const queryObject = getDrupalJsonApiParams(query).getQueryObject();
448
- collection.data = dehydrateResources({ commit: this.commit, queryObject, resources: collection.data });
464
+ collection.data = dehydrateResources({ commit: this.commit, prefix, queryObject, resources: collection.data });
449
465
  if (collection.included) {
450
- collection.included = dehydrateResources({ commit: this.commit, queryObject, resources: collection.included });
466
+ collection.included = dehydrateResources({ commit: this.commit, prefix, queryObject, resources: collection.included });
451
467
  delete collection.included;
452
468
  }
453
- collection = merge(state.collections[type][hash] || {}, collection, { arrayMerge: (dst, src) => src });
454
- Vue.set(state.collections[type], hash, collection);
469
+ collection = merge(state.collections[type][hash][prefix] || {}, collection, { arrayMerge: (dst, src) => src });
470
+ Vue.set(state.collections[type][hash], prefix, collection);
455
471
  },
456
- addResource(state, { resource, hash }) {
472
+ addResource(state, { prefix, resource, hash }) {
457
473
  if (hash) {
458
474
  console.warn("[druxt] The `hash` argument for `druxt/addResource` has been deprecated, see https://druxtjs.org/guide/deprecations.html#druxtstore-addresource-hash");
459
475
  }
@@ -468,30 +484,32 @@ const DruxtStore = ({ store }) => {
468
484
  resource[flag] = Date.now();
469
485
  if (!state.resources[type])
470
486
  Vue.set(state.resources, type, {});
487
+ if (!state.resources[type][id])
488
+ Vue.set(state.resources[type], id, {});
471
489
  if (resource.included) {
472
- dehydrateResources({ commit: this.commit, queryObject, resources: resource.included });
490
+ dehydrateResources({ commit: this.commit, prefix, queryObject, resources: resource.included });
473
491
  delete resource.included;
474
492
  }
475
- resource = merge(state.resources[type][id] || {}, resource, { arrayMerge: (dst, src) => src });
476
- Vue.set(state.resources[type], id, resource);
493
+ resource = merge(state.resources[type][id][prefix] || {}, resource, { arrayMerge: (dst, src) => src });
494
+ Vue.set(state.resources[type][id], prefix, resource);
477
495
  }
478
496
  },
479
497
  actions: {
480
- async getCollection({ commit, state }, { type, query }) {
498
+ async getCollection({ commit, state }, { type, query, prefix }) {
481
499
  const queryObject = getDrupalJsonApiParams(query).getQueryObject();
482
500
  const hash = query ? md5(JSON.stringify({ ...queryObject, fields: {}, include: [] })) : "_default";
483
- if ((state.collections[type] || {})[hash]) {
501
+ if (((state.collections[type] || {})[hash] || {})[prefix]) {
484
502
  return {
485
- ...state.collections[type][hash],
486
- data: state.collections[type][hash].data.map((o) => (state.resources[o.type][o.id] || {}).data)
503
+ ...state.collections[type][hash][prefix],
504
+ data: state.collections[type][hash][prefix].data.map((o) => ((state.resources[o.type][o.id] || {})[prefix] || {}).data)
487
505
  };
488
506
  }
489
- const collection = await this.$druxt.getCollection(type, query);
490
- commit("addCollection", { collection: { ...collection }, type, hash });
507
+ const collection = await this.$druxt.getCollection(type, query, prefix);
508
+ commit("addCollection", { collection: { ...collection }, type, hash, prefix });
491
509
  return collection;
492
510
  },
493
- async getResource({ commit, dispatch, state }, { type, id, query }) {
494
- const storedResource = (state.resources[type] || {})[id] ? { ...state.resources[type][id] } : null;
511
+ async getResource({ commit, dispatch, state }, { type, id, query, prefix }) {
512
+ const storedResource = ((state.resources[type] || {})[id] || {})[prefix] ? { ...state.resources[type][id][prefix] } : null;
495
513
  const queryObject = getDrupalJsonApiParams(query).getQueryObject();
496
514
  queryObject.include = Array.isArray(queryObject.include) ? queryObject.include.join(",") : queryObject.include;
497
515
  if (queryObject.include && typeof (queryObject.fields || {})[type] === "string") {
@@ -535,10 +553,10 @@ const DruxtStore = ({ store }) => {
535
553
  }
536
554
  let resource;
537
555
  if (!storedResource || fields) {
538
- resource = await this.$druxt.getResource(type, id, getDrupalJsonApiParams(queryObject));
539
- commit("addResource", { resource: { ...resource } });
556
+ resource = await this.$druxt.getResource(type, id, getDrupalJsonApiParams(queryObject), prefix);
557
+ commit("addResource", { prefix, resource: { ...resource } });
540
558
  }
541
- const result = { ...(state.resources[type] || {})[id] };
559
+ const result = { ...((state.resources[type] || {})[id] || {})[prefix] };
542
560
  if (queryObject.include && ((resource || {}).included || (storedResource || {}).included)) {
543
561
  included = [
544
562
  ...(resource || {}).included || [],
@@ -608,5 +626,4 @@ class DruxtClass {
608
626
 
609
627
  DruxtNuxtModule.meta = require("../package.json");
610
628
 
611
- export default DruxtNuxtModule;
612
- export { DruxtClass, DruxtClient, DruxtStore };
629
+ export { DruxtClass, DruxtClient, DruxtStore, DruxtNuxtModule as default };
package/dist/druxt.ssr.js CHANGED
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const chalk = require('chalk');
6
+ const drupalJsonapiParams = require('drupal-jsonapi-params');
6
7
  const path = require('path');
7
8
  const axios = require('axios');
8
9
  const querystring = require('querystring');
@@ -10,7 +11,6 @@ const consola = require('consola');
10
11
  const merge = require('deepmerge');
11
12
  const md5 = require('md5');
12
13
  const Vue = require('vue');
13
- const drupalJsonapiParams = require('drupal-jsonapi-params');
14
14
 
15
15
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
16
 
@@ -21,170 +21,9 @@ const merge__default = /*#__PURE__*/_interopDefaultLegacy(merge);
21
21
  const md5__default = /*#__PURE__*/_interopDefaultLegacy(md5);
22
22
  const Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);
23
23
 
24
- var name = "druxt";
25
- var version = "0.18.2";
26
- var description = "The Fully Decoupled Drupal Framework for Nuxt.js.";
27
- var keywords = [
28
- "cms",
29
- "decoupled",
30
- "drupal",
31
- "druxt",
32
- "headless",
33
- "jsonapi",
34
- "json:api",
35
- "nuxt",
36
- "module",
37
- "vue"
38
- ];
39
- var homepage = "https://druxtjs.org";
40
- var bugs = {
41
- url: "https://github.com/druxt/druxt.js/issues"
42
- };
43
- var repository = {
44
- type: "git",
45
- url: "git+https://github.com/druxt/druxt.js"
46
- };
47
- var license = "MIT";
48
- var exports$1 = {
49
- ".": {
50
- require: "./dist/druxt.ssr.js",
51
- "import": "./dist/druxt.esm.js"
52
- },
53
- "./components/*": "./dist/components/*"
54
- };
55
- var main = "dist/druxt.ssr.js";
56
- var module$1 = "dist/druxt.esm.js";
57
- var files = [
58
- "dist",
59
- "stories",
60
- "templates"
61
- ];
62
- var dependencies = {
63
- "@nuxtjs/axios": "^5.13.6",
64
- "@nuxtjs/proxy": "^2.1.0",
65
- chalk: "^4.1.2",
66
- deepmerge: "^4.2.2",
67
- "drupal-jsonapi-params": "^2.0.0",
68
- md5: "^2.3.0",
69
- querystring: "^0.2.0",
70
- scule: "^0.2.0"
71
- };
72
- var devDependencies = {
73
- "@storybook/addon-docs": "^6.4.13"
74
- };
75
- var peerDependencies = {
76
- axios: "*",
77
- consola: "*"
78
- };
79
- var optionalDependencies = {
80
- "core-js": "^3.16.1",
81
- vue: "^2.6.14",
82
- vuex: "^3.6.2"
83
- };
84
- var publishConfig = {
85
- access: "public"
86
- };
87
- const meta = {
88
- name: name,
89
- version: version,
90
- description: description,
91
- keywords: keywords,
92
- homepage: homepage,
93
- bugs: bugs,
94
- repository: repository,
95
- license: license,
96
- exports: exports$1,
97
- main: main,
98
- module: module$1,
99
- files: files,
100
- dependencies: dependencies,
101
- devDependencies: devDependencies,
102
- peerDependencies: peerDependencies,
103
- optionalDependencies: optionalDependencies,
104
- publishConfig: publishConfig
105
- };
106
-
107
- const DruxtNuxtModule = function(moduleOptions = {}) {
108
- var _a;
109
- const options = {
110
- endpoint: "/jsonapi",
111
- ...moduleOptions,
112
- ...(this.options || {}).druxt
113
- };
114
- if (options.proxy) {
115
- const proxies = {};
116
- if ((options.proxy || {}).api) {
117
- proxies[options.endpoint] = options.baseUrl;
118
- proxies["/router/translate-path"] = options.baseUrl;
119
- }
120
- if ((options.proxy || {}).files) {
121
- const filesPath = typeof options.proxy.files === "string" ? options.proxy.files : "default";
122
- proxies[`/sites/${filesPath}/files`] = options.baseUrl;
123
- }
124
- if (this.options.proxy) {
125
- if (Array.isArray(this.options.proxy)) {
126
- this.options.proxy = [
127
- ...Object.keys(proxies).map((path) => `${options.baseUrl}${path}`),
128
- ...this.options.proxy
129
- ];
130
- } else {
131
- this.options.proxy = {
132
- ...proxies,
133
- ...this.options.proxy
134
- };
135
- }
136
- } else {
137
- this.options.proxy = proxies;
138
- }
139
- this.addModule("@nuxtjs/proxy");
140
- }
141
- if (!options.axios) {
142
- this.options.axios = {
143
- baseURL: options.baseUrl,
144
- proxy: !!(options.proxy || {}).api,
145
- ...this.options.axios
146
- };
147
- this.addModule("@nuxtjs/axios");
148
- }
149
- this.nuxt.hook("components:dirs", (dirs) => {
150
- dirs.push({ path: path.join(__dirname, "components") });
151
- });
152
- this.addPlugin({
153
- src: path.resolve(__dirname, "../templates/plugin.js"),
154
- fileName: "druxt.js",
155
- options
156
- });
157
- const extendPlugins = this.options.extendPlugins;
158
- this.options.extendPlugins = (plugins) => {
159
- plugins = typeof extendPlugins === "function" ? extendPlugins(plugins) : plugins;
160
- const axiosIndex = plugins.findIndex(({ src }) => src === `${this.options.buildDir}/axios.js`);
161
- const axiosPlugin = plugins[axiosIndex];
162
- plugins.splice(axiosIndex, 1);
163
- const druxtIndex = plugins.findIndex(({ src }) => src === `${this.options.buildDir}/druxt.js`);
164
- const druxtPlugin = plugins[druxtIndex];
165
- plugins.splice(druxtIndex, 1);
166
- plugins = [axiosPlugin, druxtPlugin, ...plugins];
167
- return plugins;
168
- };
169
- this.addPlugin({
170
- src: path.resolve(__dirname, "../templates/store.js"),
171
- fileName: "store/druxt.js",
172
- options
173
- });
174
- this.options.store = true;
175
- this.options.components = (_a = this.options.components) != null ? _a : true;
176
- this.options.cli.badgeMessages.push(`${chalk__default['default'].blue.bold("Druxt")} @ v${meta.version}`);
177
- this.options.cli.badgeMessages.push(`${chalk__default['default'].bold("API:")} ${chalk__default['default'].blue.underline(options.baseUrl + options.endpoint)}`);
178
- this.nuxt.hook("storybook:config", async ({ stories }) => {
179
- stories.push("druxt/stories/*.stories.mdx");
180
- stories.push("druxt/dist/components/*.stories.mdx");
181
- stories.push("druxt/dist/components/*.stories.mjs");
182
- });
183
- };
184
-
185
24
  class DruxtClient {
186
25
  constructor(baseUrl, options = {}) {
187
- this.log = consola__default['default'].create({ defaults: {
26
+ this.log = consola__default["default"].create({ defaults: {
188
27
  tag: "DruxtClient"
189
28
  } });
190
29
  if (!baseUrl) {
@@ -194,9 +33,9 @@ class DruxtClient {
194
33
  if (typeof options.axios === "function") {
195
34
  this.axios = options.axios;
196
35
  } else {
197
- this.axios = axios__default['default'].create({
36
+ this.axios = axios__default["default"].create({
198
37
  ...options.axios || {},
199
- baseURL: baseUrl
38
+ baseURL: baseUrl && !(options.proxy || {}).api ? baseUrl : void 0
200
39
  });
201
40
  }
202
41
  if (options.debug) {
@@ -214,6 +53,7 @@ class DruxtClient {
214
53
  jsonapiResourceConfig: "jsonapi_resource_config--jsonapi_resource_config",
215
54
  ...options
216
55
  };
56
+ this.index = {};
217
57
  }
218
58
  addHeaders(headers) {
219
59
  if (typeof headers === "undefined") {
@@ -263,11 +103,11 @@ class DruxtClient {
263
103
  }
264
104
  }
265
105
  }
266
- async createResource(resource) {
106
+ async createResource(resource, prefix = "") {
267
107
  if (resource.id) {
268
- return this.updateResource(resource);
108
+ return this.updateResource(resource, prefix);
269
109
  }
270
- const { href } = await this.getIndex(resource.type);
110
+ const { href } = await this.getIndex(resource.type, prefix);
271
111
  if (!href) {
272
112
  return false;
273
113
  }
@@ -314,8 +154,8 @@ class DruxtClient {
314
154
  this.error(err, { url });
315
155
  }
316
156
  }
317
- async getCollection(type, query) {
318
- const { href } = await this.getIndex(type);
157
+ async getCollection(type, query, prefix) {
158
+ const { href } = await this.getIndex(type, prefix);
319
159
  if (!href) {
320
160
  return false;
321
161
  }
@@ -323,25 +163,25 @@ class DruxtClient {
323
163
  const { data } = await this.get(url);
324
164
  return data;
325
165
  }
326
- async getCollectionAll(type, query) {
166
+ async getCollectionAll(type, query, prefix) {
327
167
  const collections = [];
328
- let res = await this.getCollection(type, query);
168
+ let res = await this.getCollection(type, query, prefix);
329
169
  collections.push(res);
330
170
  while (((res.links || {}).next || {}).href) {
331
171
  query = res.links.next.href.split("?")[1];
332
- res = await this.getCollection(type, query);
172
+ res = await this.getCollection(type, query, prefix);
333
173
  collections.push(res);
334
174
  }
335
175
  return collections;
336
176
  }
337
- async getIndex(resource) {
338
- if (this.index && !resource) {
339
- return this.index;
177
+ async getIndex(resource, prefix) {
178
+ if ((this.index || {})[prefix] && !resource) {
179
+ return this.index[prefix];
340
180
  }
341
- if (this.index && resource) {
342
- return this.index[resource] ? this.index[resource] : false;
181
+ if ((this.index || {})[prefix] && resource) {
182
+ return this.index[prefix][resource] ? this.index[prefix][resource] : false;
343
183
  }
344
- const url = this.options.endpoint;
184
+ const url = [prefix, this.options.endpoint].join("");
345
185
  const { data } = await this.get(url);
346
186
  let index = data.links;
347
187
  if (typeof index !== "object") {
@@ -376,14 +216,14 @@ class DruxtClient {
376
216
  };
377
217
  }
378
218
  }
379
- this.index = index;
380
- return resource ? this.index[resource] || false : this.index;
219
+ this.index[prefix] = index;
220
+ return resource ? this.index[prefix][resource] || false : this.index[prefix];
381
221
  }
382
- async getRelated(type, id, related, query) {
222
+ async getRelated(type, id, related, query, prefix = "") {
383
223
  if (!id || !type || !related) {
384
224
  return false;
385
225
  }
386
- let { href } = await this.getIndex(type);
226
+ let { href } = await this.getIndex(type, prefix);
387
227
  if (!href) {
388
228
  href = this.options.endpoint + "/" + type.replace("--", "/");
389
229
  }
@@ -391,11 +231,11 @@ class DruxtClient {
391
231
  const { data } = await this.get(url);
392
232
  return data;
393
233
  }
394
- async getResource(type, id, query) {
234
+ async getResource(type, id, query, prefix) {
395
235
  if (!id || !type) {
396
236
  return false;
397
237
  }
398
- let { href } = await this.getIndex(type);
238
+ let { href } = await this.getIndex(type, prefix);
399
239
  if (!href) {
400
240
  href = this.options.endpoint + "/" + type.replace("--", "/");
401
241
  }
@@ -403,8 +243,8 @@ class DruxtClient {
403
243
  const { data } = await this.get(url);
404
244
  return data;
405
245
  }
406
- async updateResource(resource) {
407
- const { href } = await this.getIndex(resource.type);
246
+ async updateResource(resource, prefix) {
247
+ const { href } = await this.getIndex(resource.type, prefix);
408
248
  if (!href) {
409
249
  return false;
410
250
  }
@@ -423,15 +263,189 @@ class DruxtClient {
423
263
  }
424
264
  }
425
265
 
266
+ var name = "druxt";
267
+ var version = "0.19.1";
268
+ var description = "The Fully Decoupled Drupal Framework for Nuxt.js.";
269
+ var keywords = [
270
+ "cms",
271
+ "decoupled",
272
+ "drupal",
273
+ "druxt",
274
+ "headless",
275
+ "jsonapi",
276
+ "json:api",
277
+ "nuxt",
278
+ "module",
279
+ "vue"
280
+ ];
281
+ var homepage = "https://druxtjs.org";
282
+ var bugs = {
283
+ url: "https://github.com/druxt/druxt.js/issues"
284
+ };
285
+ var repository = {
286
+ type: "git",
287
+ url: "git+https://github.com/druxt/druxt.js"
288
+ };
289
+ var license = "MIT";
290
+ var exports$1 = {
291
+ ".": {
292
+ require: "./dist/druxt.ssr.js",
293
+ "import": "./dist/druxt.esm.js"
294
+ },
295
+ "./components/*": "./dist/components/*"
296
+ };
297
+ var main = "dist/druxt.ssr.js";
298
+ var module$1 = "dist/druxt.esm.js";
299
+ var files = [
300
+ "dist",
301
+ "stories",
302
+ "templates"
303
+ ];
304
+ var dependencies = {
305
+ "@nuxtjs/axios": "^5.13.6",
306
+ "@nuxtjs/proxy": "^2.1.0",
307
+ chalk: "^4.1.2",
308
+ deepmerge: "^4.2.2",
309
+ "drupal-jsonapi-params": "^2.0.0",
310
+ md5: "^2.3.0",
311
+ querystring: "^0.2.1",
312
+ scule: "^0.2.1"
313
+ };
314
+ var devDependencies = {
315
+ "@storybook/addon-docs": "^6.4.22"
316
+ };
317
+ var peerDependencies = {
318
+ axios: "*",
319
+ consola: "*"
320
+ };
321
+ var optionalDependencies = {
322
+ "core-js": "^3.22.5",
323
+ vue: "^2.6.14",
324
+ vuex: "^3.6.2"
325
+ };
326
+ var publishConfig = {
327
+ access: "public"
328
+ };
329
+ const meta = {
330
+ name: name,
331
+ version: version,
332
+ description: description,
333
+ keywords: keywords,
334
+ homepage: homepage,
335
+ bugs: bugs,
336
+ repository: repository,
337
+ license: license,
338
+ exports: exports$1,
339
+ main: main,
340
+ module: module$1,
341
+ files: files,
342
+ dependencies: dependencies,
343
+ devDependencies: devDependencies,
344
+ peerDependencies: peerDependencies,
345
+ optionalDependencies: optionalDependencies,
346
+ publishConfig: publishConfig
347
+ };
348
+
349
+ const DruxtNuxtModule = async function(moduleOptions = {}) {
350
+ var _a;
351
+ const options = {
352
+ endpoint: "/jsonapi",
353
+ ...moduleOptions,
354
+ ...(this.options || {}).druxt
355
+ };
356
+ const druxt = new DruxtClient(options.baseUrl, {
357
+ ...options,
358
+ proxy: { ...options.proxy || {}, api: false }
359
+ });
360
+ if (options.proxy) {
361
+ const proxies = {};
362
+ if ((options.proxy || {}).api) {
363
+ proxies[options.endpoint] = options.baseUrl;
364
+ const languageResourceType = "configurable_language--configurable_language";
365
+ if (await druxt.getIndex(languageResourceType)) {
366
+ const query = new drupalJsonapiParams.DrupalJsonApiParams().addFields(languageResourceType, ["drupal_internal__id"]);
367
+ const languages = (await druxt.getCollectionAll(languageResourceType, query) || []).map((o) => o.data).flat().filter((o) => !["und", "zxx"].includes(((o || {}).attributes || {}).drupal_internal__id)).map((o) => o.attributes.drupal_internal__id);
368
+ for (const langcode of languages) {
369
+ proxies[`/${langcode}${options.endpoint}`] = options.baseUrl;
370
+ }
371
+ }
372
+ proxies["/router/translate-path"] = options.baseUrl;
373
+ }
374
+ if ((options.proxy || {}).files) {
375
+ const filesPath = typeof options.proxy.files === "string" ? options.proxy.files : "default";
376
+ proxies[`/sites/${filesPath}/files`] = options.baseUrl;
377
+ }
378
+ if (this.options.proxy) {
379
+ if (Array.isArray(this.options.proxy)) {
380
+ this.options.proxy = [
381
+ ...Object.keys(proxies).map((path) => `${options.baseUrl}${path}`),
382
+ ...this.options.proxy
383
+ ];
384
+ } else {
385
+ this.options.proxy = {
386
+ ...proxies,
387
+ ...this.options.proxy
388
+ };
389
+ }
390
+ } else {
391
+ this.options.proxy = proxies;
392
+ }
393
+ this.addModule("@nuxtjs/proxy");
394
+ }
395
+ if (!options.axios) {
396
+ this.options.axios = {
397
+ baseURL: options.baseUrl,
398
+ proxy: !!(options.proxy || {}).api,
399
+ ...this.options.axios
400
+ };
401
+ this.addModule("@nuxtjs/axios");
402
+ }
403
+ this.nuxt.hook("components:dirs", (dirs) => {
404
+ dirs.push({ path: path.join(__dirname, "components") });
405
+ });
406
+ this.addPlugin({
407
+ src: path.resolve(__dirname, "../templates/plugin.js"),
408
+ fileName: "druxt.js",
409
+ options
410
+ });
411
+ const extendPlugins = this.options.extendPlugins;
412
+ this.options.extendPlugins = (plugins) => {
413
+ plugins = typeof extendPlugins === "function" ? extendPlugins(plugins) : plugins;
414
+ const axiosIndex = plugins.findIndex(({ src }) => src === `${this.options.buildDir}/axios.js`);
415
+ const axiosPlugin = plugins[axiosIndex];
416
+ plugins.splice(axiosIndex, 1);
417
+ const druxtIndex = plugins.findIndex(({ src }) => src === `${this.options.buildDir}/druxt.js`);
418
+ const druxtPlugin = plugins[druxtIndex];
419
+ plugins.splice(druxtIndex, 1);
420
+ plugins = [axiosPlugin, druxtPlugin, ...plugins];
421
+ return plugins;
422
+ };
423
+ this.addPlugin({
424
+ src: path.resolve(__dirname, "../templates/store.js"),
425
+ fileName: "store/druxt.js",
426
+ options
427
+ });
428
+ this.options.store = true;
429
+ this.options.components = (_a = this.options.components) != null ? _a : true;
430
+ this.options.cli.badgeMessages.push(`${chalk__default["default"].blue.bold("Druxt")} @ v${meta.version}`);
431
+ this.options.cli.badgeMessages.push(`${chalk__default["default"].bold("API:")} ${chalk__default["default"].blue.underline(options.baseUrl + options.endpoint)}`);
432
+ this.nuxt.hook("storybook:config", async ({ stories }) => {
433
+ stories.push("druxt/stories/*.stories.mdx");
434
+ stories.push("druxt/dist/components/*.stories.mdx");
435
+ stories.push("druxt/dist/components/*.stories.mjs");
436
+ });
437
+ };
438
+
426
439
  const getDrupalJsonApiParams = (query) => {
427
440
  return new drupalJsonapiParams.DrupalJsonApiParams().initialize(query);
428
441
  };
429
442
 
430
- const dehydrateResources = ({ commit, queryObject, resources }) => {
443
+ const dehydrateResources = ({ commit, queryObject, resources, prefix }) => {
431
444
  return (resources || []).map((data) => {
432
445
  const link = decodeURI(((data.links || {}).self || {}).href || "");
433
446
  const href = typeof (queryObject.fields || {})[data.type] === "string" ? [link.split("?")[0], `fields[${data.type}]=${queryObject.fields[data.type]}`].join("?") : link;
434
447
  commit("druxt/addResource", {
448
+ prefix,
435
449
  resource: {
436
450
  data,
437
451
  links: { self: { href } }
@@ -452,21 +466,23 @@ const DruxtStore = ({ store }) => {
452
466
  resources: {}
453
467
  }),
454
468
  mutations: {
455
- addCollection(state, { collection, type, hash }) {
469
+ addCollection(state, { collection, type, hash, prefix }) {
456
470
  if (!state.collections[type])
457
- Vue__default['default'].set(state.collections, type, {});
471
+ Vue__default["default"].set(state.collections, type, {});
472
+ if (!state.collections[type][hash])
473
+ Vue__default["default"].set(state.collections[type], hash, {});
458
474
  const link = decodeURI((((collection || {}).links || {}).self || {}).href || "");
459
475
  const query = link.split("?")[1] || "";
460
476
  const queryObject = getDrupalJsonApiParams(query).getQueryObject();
461
- collection.data = dehydrateResources({ commit: this.commit, queryObject, resources: collection.data });
477
+ collection.data = dehydrateResources({ commit: this.commit, prefix, queryObject, resources: collection.data });
462
478
  if (collection.included) {
463
- collection.included = dehydrateResources({ commit: this.commit, queryObject, resources: collection.included });
479
+ collection.included = dehydrateResources({ commit: this.commit, prefix, queryObject, resources: collection.included });
464
480
  delete collection.included;
465
481
  }
466
- collection = merge__default['default'](state.collections[type][hash] || {}, collection, { arrayMerge: (dst, src) => src });
467
- Vue__default['default'].set(state.collections[type], hash, collection);
482
+ collection = merge__default["default"](state.collections[type][hash][prefix] || {}, collection, { arrayMerge: (dst, src) => src });
483
+ Vue__default["default"].set(state.collections[type][hash], prefix, collection);
468
484
  },
469
- addResource(state, { resource, hash }) {
485
+ addResource(state, { prefix, resource, hash }) {
470
486
  if (hash) {
471
487
  console.warn("[druxt] The `hash` argument for `druxt/addResource` has been deprecated, see https://druxtjs.org/guide/deprecations.html#druxtstore-addresource-hash");
472
488
  }
@@ -480,31 +496,33 @@ const DruxtStore = ({ store }) => {
480
496
  const flag = typeof (queryObject.fields || {})[((resource || {}).data || {}).type] === "string" ? "_druxt_partial" : "_druxt_full";
481
497
  resource[flag] = Date.now();
482
498
  if (!state.resources[type])
483
- Vue__default['default'].set(state.resources, type, {});
499
+ Vue__default["default"].set(state.resources, type, {});
500
+ if (!state.resources[type][id])
501
+ Vue__default["default"].set(state.resources[type], id, {});
484
502
  if (resource.included) {
485
- dehydrateResources({ commit: this.commit, queryObject, resources: resource.included });
503
+ dehydrateResources({ commit: this.commit, prefix, queryObject, resources: resource.included });
486
504
  delete resource.included;
487
505
  }
488
- resource = merge__default['default'](state.resources[type][id] || {}, resource, { arrayMerge: (dst, src) => src });
489
- Vue__default['default'].set(state.resources[type], id, resource);
506
+ resource = merge__default["default"](state.resources[type][id][prefix] || {}, resource, { arrayMerge: (dst, src) => src });
507
+ Vue__default["default"].set(state.resources[type][id], prefix, resource);
490
508
  }
491
509
  },
492
510
  actions: {
493
- async getCollection({ commit, state }, { type, query }) {
511
+ async getCollection({ commit, state }, { type, query, prefix }) {
494
512
  const queryObject = getDrupalJsonApiParams(query).getQueryObject();
495
- const hash = query ? md5__default['default'](JSON.stringify({ ...queryObject, fields: {}, include: [] })) : "_default";
496
- if ((state.collections[type] || {})[hash]) {
513
+ const hash = query ? md5__default["default"](JSON.stringify({ ...queryObject, fields: {}, include: [] })) : "_default";
514
+ if (((state.collections[type] || {})[hash] || {})[prefix]) {
497
515
  return {
498
- ...state.collections[type][hash],
499
- data: state.collections[type][hash].data.map((o) => (state.resources[o.type][o.id] || {}).data)
516
+ ...state.collections[type][hash][prefix],
517
+ data: state.collections[type][hash][prefix].data.map((o) => ((state.resources[o.type][o.id] || {})[prefix] || {}).data)
500
518
  };
501
519
  }
502
- const collection = await this.$druxt.getCollection(type, query);
503
- commit("addCollection", { collection: { ...collection }, type, hash });
520
+ const collection = await this.$druxt.getCollection(type, query, prefix);
521
+ commit("addCollection", { collection: { ...collection }, type, hash, prefix });
504
522
  return collection;
505
523
  },
506
- async getResource({ commit, dispatch, state }, { type, id, query }) {
507
- const storedResource = (state.resources[type] || {})[id] ? { ...state.resources[type][id] } : null;
524
+ async getResource({ commit, dispatch, state }, { type, id, query, prefix }) {
525
+ const storedResource = ((state.resources[type] || {})[id] || {})[prefix] ? { ...state.resources[type][id][prefix] } : null;
508
526
  const queryObject = getDrupalJsonApiParams(query).getQueryObject();
509
527
  queryObject.include = Array.isArray(queryObject.include) ? queryObject.include.join(",") : queryObject.include;
510
528
  if (queryObject.include && typeof (queryObject.fields || {})[type] === "string") {
@@ -548,10 +566,10 @@ const DruxtStore = ({ store }) => {
548
566
  }
549
567
  let resource;
550
568
  if (!storedResource || fields) {
551
- resource = await this.$druxt.getResource(type, id, getDrupalJsonApiParams(queryObject));
552
- commit("addResource", { resource: { ...resource } });
569
+ resource = await this.$druxt.getResource(type, id, getDrupalJsonApiParams(queryObject), prefix);
570
+ commit("addResource", { prefix, resource: { ...resource } });
553
571
  }
554
- const result = { ...(state.resources[type] || {})[id] };
572
+ const result = { ...((state.resources[type] || {})[id] || {})[prefix] };
555
573
  if (queryObject.include && ((resource || {}).included || (storedResource || {}).included)) {
556
574
  included = [
557
575
  ...(resource || {}).included || [],
@@ -624,4 +642,4 @@ DruxtNuxtModule.meta = require("../package.json");
624
642
  exports.DruxtClass = DruxtClass;
625
643
  exports.DruxtClient = DruxtClient;
626
644
  exports.DruxtStore = DruxtStore;
627
- exports.default = DruxtNuxtModule;
645
+ exports["default"] = DruxtNuxtModule;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "druxt",
3
- "version": "0.18.2",
3
+ "version": "0.19.1",
4
4
  "description": "The Fully Decoupled Drupal Framework for Nuxt.js.",
5
5
  "keywords": [
6
6
  "cms",
@@ -44,18 +44,18 @@
44
44
  "deepmerge": "^4.2.2",
45
45
  "drupal-jsonapi-params": "^2.0.0",
46
46
  "md5": "^2.3.0",
47
- "querystring": "^0.2.0",
48
- "scule": "^0.2.0"
47
+ "querystring": "^0.2.1",
48
+ "scule": "^0.2.1"
49
49
  },
50
50
  "devDependencies": {
51
- "@storybook/addon-docs": "^6.4.13"
51
+ "@storybook/addon-docs": "^6.4.22"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "axios": "*",
55
55
  "consola": "*"
56
56
  },
57
57
  "optionalDependencies": {
58
- "core-js": "^3.16.1",
58
+ "core-js": "^3.22.5",
59
59
  "vue": "^2.6.14",
60
60
  "vuex": "^3.6.2"
61
61
  },