@plasmicpkgs/plasmic-contentful 0.0.119 → 0.0.121

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/dist/index.d.mts CHANGED
@@ -3,7 +3,7 @@ import registerGlobalContext from '@plasmicapp/host/registerGlobalContext';
3
3
  import { GlobalContextMeta, ComponentMeta } from '@plasmicapp/host';
4
4
  import React, { ReactNode } from 'react';
5
5
 
6
- declare function ensure<T>(x: T | null | undefined): T;
6
+ declare function ensure<T>(x: T | null | undefined, msg?: string): T;
7
7
  interface ContentfulCredentialsProviderProps {
8
8
  space: string;
9
9
  accessToken: string;
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ import registerGlobalContext from '@plasmicapp/host/registerGlobalContext';
3
3
  import { GlobalContextMeta, ComponentMeta } from '@plasmicapp/host';
4
4
  import React, { ReactNode } from 'react';
5
5
 
6
- declare function ensure<T>(x: T | null | undefined): T;
6
+ declare function ensure<T>(x: T | null | undefined, msg?: string): T;
7
7
  interface ContentfulCredentialsProviderProps {
8
8
  space: string;
9
9
  accessToken: string;
package/dist/index.js CHANGED
@@ -73,9 +73,9 @@ var searchParameters = [
73
73
  var uniq = (xs) => Array.from(new Set(xs));
74
74
 
75
75
  // src/contentful.tsx
76
- function ensure(x) {
76
+ function ensure(x, msg) {
77
77
  if (x === null || x === void 0) {
78
- throw new Error(`Value must not be undefined or null`);
78
+ throw new Error(msg != null ? msg : `Value must not be undefined or null`);
79
79
  } else {
80
80
  return x;
81
81
  }
@@ -228,7 +228,10 @@ function ContentfulFetcher({
228
228
  setControlContextData
229
229
  }) {
230
230
  var _a, _b, _c, _d, _e, _f, _g, _h;
231
- const creds = ensure((0, import_react.useContext)(CredentialsContext));
231
+ const creds = ensure(
232
+ (0, import_react.useContext)(CredentialsContext),
233
+ "Could not find context with current credentials"
234
+ );
232
235
  const cacheKey = JSON.stringify({
233
236
  include,
234
237
  limit,
@@ -325,75 +328,55 @@ function ContentfulFetcher({
325
328
  const entryMap = {};
326
329
  if (data.includes.Entry) {
327
330
  data.includes.Entry.forEach((entry) => {
328
- entryMap[entry.sys.id] = entry.fields;
331
+ entryMap[entry.sys.id] = entry;
329
332
  });
330
333
  }
331
- const itemsWithDenormalizedFields = data.items.map((item) => {
334
+ const denormalizeField = (fieldValue) => {
332
335
  var _a2, _b2;
333
- const updatedFields = {};
334
- for (const fieldName in item.fields) {
335
- const fieldValue = item.fields[fieldName];
336
- if (Array.isArray(fieldValue)) {
337
- const updatedArray = fieldValue.map((arrayItem) => {
338
- var _a3, _b3;
339
- if (data.includes.Asset && arrayItem && typeof arrayItem === "object" && "sys" in arrayItem && arrayItem.sys.linkType === "Asset") {
340
- const fieldId = arrayItem.sys.id;
341
- const asset = data.includes.Asset.find(
342
- (asset2) => asset2.sys.id === fieldId
343
- );
344
- if (asset) {
345
- return {
346
- ...arrayItem,
347
- url: "https:" + ((_b3 = (_a3 = asset.fields) == null ? void 0 : _a3.file) == null ? void 0 : _b3.url)
348
- };
349
- } else {
350
- console.log(`Asset URL not found for ID: ${fieldId}`);
351
- }
352
- } else if (data.includes.Entry && arrayItem && typeof arrayItem === "object" && "sys" in arrayItem && arrayItem.sys.linkType === "Entry") {
353
- const fieldId = arrayItem.sys.id;
354
- if (entryMap[fieldId]) {
355
- updatedFields[fieldName] = {
356
- ...fieldValue,
357
- fields: entryMap[fieldId]
358
- };
359
- } else {
360
- console.log(`Entry not found for ID: ${fieldId}`);
361
- }
362
- }
363
- return arrayItem;
364
- });
365
- updatedFields[fieldName] = updatedArray;
366
- } else if (data.includes.Asset && fieldValue && typeof fieldValue === "object" && "sys" in fieldValue && fieldValue.sys.linkType === "Asset") {
367
- const fieldId = fieldValue.sys.id;
368
- const asset = data.includes.Asset.find(
369
- (asset2) => asset2.sys.id === fieldId
370
- );
371
- if (asset) {
372
- updatedFields[fieldName] = {
373
- ...fieldValue,
374
- url: "https:" + ((_b2 = (_a2 = asset.fields) == null ? void 0 : _a2.file) == null ? void 0 : _b2.url)
375
- };
376
- } else {
377
- console.log(`Asset URL not found for ID: ${fieldId}`);
378
- }
379
- } else if (data.includes.Entry && fieldValue && typeof fieldValue === "object" && "sys" in fieldValue && fieldValue.sys.linkType === "Entry") {
380
- const fieldId = fieldValue.sys.id;
381
- if (entryMap[fieldId]) {
382
- updatedFields[fieldName] = {
383
- ...fieldValue,
384
- fields: entryMap[fieldId]
385
- };
386
- } else {
387
- console.log(`Entry not found for ID: ${fieldId}`);
388
- }
336
+ if (Array.isArray(fieldValue)) {
337
+ const updatedArray = fieldValue.map((arrayItem) => {
338
+ return denormalizeField(arrayItem);
339
+ });
340
+ return updatedArray;
341
+ } else if (data.includes.Asset && fieldValue && typeof fieldValue === "object" && "sys" in fieldValue && fieldValue.sys.linkType === "Asset") {
342
+ const fieldId = fieldValue.sys.id;
343
+ const asset = data.includes.Asset.find(
344
+ (a) => a.sys.id === fieldId
345
+ );
346
+ if (asset) {
347
+ return {
348
+ ...fieldValue,
349
+ url: "https:" + ((_b2 = (_a2 = asset.fields) == null ? void 0 : _a2.file) == null ? void 0 : _b2.url)
350
+ };
389
351
  } else {
390
- updatedFields[fieldName] = fieldValue;
352
+ console.log(`Asset URL not found for ID: ${fieldId}`);
391
353
  }
354
+ } else if (data.includes.Entry && fieldValue && typeof fieldValue === "object" && "sys" in fieldValue && fieldValue.sys.linkType === "Entry") {
355
+ const fieldId = fieldValue.sys.id;
356
+ if (entryMap[fieldId]) {
357
+ return {
358
+ ...fieldValue,
359
+ fields: denormalizeItem(entryMap[fieldId]).fields
360
+ };
361
+ } else {
362
+ console.log(`Entry not found for ID: ${fieldId}`);
363
+ }
364
+ } else {
365
+ return fieldValue;
366
+ }
367
+ };
368
+ const denormalizeItem = (item) => {
369
+ const updatedFields = {};
370
+ for (const fieldName in item.fields) {
371
+ updatedFields[fieldName] = denormalizeField(item.fields[fieldName]);
392
372
  }
393
373
  return {
394
374
  ...item,
395
- fields: updatedFields
375
+ fields: updatedFields != null ? updatedFields : void 0
396
376
  };
377
+ };
378
+ const itemsWithDenormalizedFields = data.items.map((item) => {
379
+ return denormalizeItem(item);
397
380
  });
398
381
  return {
399
382
  ...data,
package/dist/index.mjs CHANGED
@@ -36,9 +36,9 @@ var searchParameters = [
36
36
  var uniq = (xs) => Array.from(new Set(xs));
37
37
 
38
38
  // src/contentful.tsx
39
- function ensure(x) {
39
+ function ensure(x, msg) {
40
40
  if (x === null || x === void 0) {
41
- throw new Error(`Value must not be undefined or null`);
41
+ throw new Error(msg != null ? msg : `Value must not be undefined or null`);
42
42
  } else {
43
43
  return x;
44
44
  }
@@ -191,7 +191,10 @@ function ContentfulFetcher({
191
191
  setControlContextData
192
192
  }) {
193
193
  var _a, _b, _c, _d, _e, _f, _g, _h;
194
- const creds = ensure(useContext(CredentialsContext));
194
+ const creds = ensure(
195
+ useContext(CredentialsContext),
196
+ "Could not find context with current credentials"
197
+ );
195
198
  const cacheKey = JSON.stringify({
196
199
  include,
197
200
  limit,
@@ -288,75 +291,55 @@ function ContentfulFetcher({
288
291
  const entryMap = {};
289
292
  if (data.includes.Entry) {
290
293
  data.includes.Entry.forEach((entry) => {
291
- entryMap[entry.sys.id] = entry.fields;
294
+ entryMap[entry.sys.id] = entry;
292
295
  });
293
296
  }
294
- const itemsWithDenormalizedFields = data.items.map((item) => {
297
+ const denormalizeField = (fieldValue) => {
295
298
  var _a2, _b2;
296
- const updatedFields = {};
297
- for (const fieldName in item.fields) {
298
- const fieldValue = item.fields[fieldName];
299
- if (Array.isArray(fieldValue)) {
300
- const updatedArray = fieldValue.map((arrayItem) => {
301
- var _a3, _b3;
302
- if (data.includes.Asset && arrayItem && typeof arrayItem === "object" && "sys" in arrayItem && arrayItem.sys.linkType === "Asset") {
303
- const fieldId = arrayItem.sys.id;
304
- const asset = data.includes.Asset.find(
305
- (asset2) => asset2.sys.id === fieldId
306
- );
307
- if (asset) {
308
- return {
309
- ...arrayItem,
310
- url: "https:" + ((_b3 = (_a3 = asset.fields) == null ? void 0 : _a3.file) == null ? void 0 : _b3.url)
311
- };
312
- } else {
313
- console.log(`Asset URL not found for ID: ${fieldId}`);
314
- }
315
- } else if (data.includes.Entry && arrayItem && typeof arrayItem === "object" && "sys" in arrayItem && arrayItem.sys.linkType === "Entry") {
316
- const fieldId = arrayItem.sys.id;
317
- if (entryMap[fieldId]) {
318
- updatedFields[fieldName] = {
319
- ...fieldValue,
320
- fields: entryMap[fieldId]
321
- };
322
- } else {
323
- console.log(`Entry not found for ID: ${fieldId}`);
324
- }
325
- }
326
- return arrayItem;
327
- });
328
- updatedFields[fieldName] = updatedArray;
329
- } else if (data.includes.Asset && fieldValue && typeof fieldValue === "object" && "sys" in fieldValue && fieldValue.sys.linkType === "Asset") {
330
- const fieldId = fieldValue.sys.id;
331
- const asset = data.includes.Asset.find(
332
- (asset2) => asset2.sys.id === fieldId
333
- );
334
- if (asset) {
335
- updatedFields[fieldName] = {
336
- ...fieldValue,
337
- url: "https:" + ((_b2 = (_a2 = asset.fields) == null ? void 0 : _a2.file) == null ? void 0 : _b2.url)
338
- };
339
- } else {
340
- console.log(`Asset URL not found for ID: ${fieldId}`);
341
- }
342
- } else if (data.includes.Entry && fieldValue && typeof fieldValue === "object" && "sys" in fieldValue && fieldValue.sys.linkType === "Entry") {
343
- const fieldId = fieldValue.sys.id;
344
- if (entryMap[fieldId]) {
345
- updatedFields[fieldName] = {
346
- ...fieldValue,
347
- fields: entryMap[fieldId]
348
- };
349
- } else {
350
- console.log(`Entry not found for ID: ${fieldId}`);
351
- }
299
+ if (Array.isArray(fieldValue)) {
300
+ const updatedArray = fieldValue.map((arrayItem) => {
301
+ return denormalizeField(arrayItem);
302
+ });
303
+ return updatedArray;
304
+ } else if (data.includes.Asset && fieldValue && typeof fieldValue === "object" && "sys" in fieldValue && fieldValue.sys.linkType === "Asset") {
305
+ const fieldId = fieldValue.sys.id;
306
+ const asset = data.includes.Asset.find(
307
+ (a) => a.sys.id === fieldId
308
+ );
309
+ if (asset) {
310
+ return {
311
+ ...fieldValue,
312
+ url: "https:" + ((_b2 = (_a2 = asset.fields) == null ? void 0 : _a2.file) == null ? void 0 : _b2.url)
313
+ };
352
314
  } else {
353
- updatedFields[fieldName] = fieldValue;
315
+ console.log(`Asset URL not found for ID: ${fieldId}`);
354
316
  }
317
+ } else if (data.includes.Entry && fieldValue && typeof fieldValue === "object" && "sys" in fieldValue && fieldValue.sys.linkType === "Entry") {
318
+ const fieldId = fieldValue.sys.id;
319
+ if (entryMap[fieldId]) {
320
+ return {
321
+ ...fieldValue,
322
+ fields: denormalizeItem(entryMap[fieldId]).fields
323
+ };
324
+ } else {
325
+ console.log(`Entry not found for ID: ${fieldId}`);
326
+ }
327
+ } else {
328
+ return fieldValue;
329
+ }
330
+ };
331
+ const denormalizeItem = (item) => {
332
+ const updatedFields = {};
333
+ for (const fieldName in item.fields) {
334
+ updatedFields[fieldName] = denormalizeField(item.fields[fieldName]);
355
335
  }
356
336
  return {
357
337
  ...item,
358
- fields: updatedFields
338
+ fields: updatedFields != null ? updatedFields : void 0
359
339
  };
340
+ };
341
+ const itemsWithDenormalizedFields = data.items.map((item) => {
342
+ return denormalizeItem(item);
360
343
  });
361
344
  return {
362
345
  ...data,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plasmicpkgs/plasmic-contentful",
3
- "version": "0.0.119",
3
+ "version": "0.0.121",
4
4
  "description": "Plasmic Contentful components.",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -32,8 +32,8 @@
32
32
  }
33
33
  ],
34
34
  "devDependencies": {
35
- "@plasmicapp/host": "1.0.180",
36
- "@plasmicapp/query": "0.1.76",
35
+ "@plasmicapp/host": "1.0.182",
36
+ "@plasmicapp/query": "0.1.77",
37
37
  "@size-limit/preset-small-lib": "^7.0.8",
38
38
  "@types/dlv": "^1.1.2",
39
39
  "@types/react": "^18.0.27",
@@ -52,5 +52,5 @@
52
52
  "change-case": "^4.1.2",
53
53
  "dlv": "^1.1.3"
54
54
  },
55
- "gitHead": "e509f855bddb2f2a527bbf0b4fc5fed35e607e5c"
55
+ "gitHead": "14c20ab68d180b65010b1cce060172af9a6826fd"
56
56
  }