@startinblox/core 0.19.0-beta.1 → 0.19.0-beta.2

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.
@@ -28,43 +28,12 @@ export class CustomGetter {
28
28
  this.serverContext = serverContext;
29
29
  this.parentId = parentId;
30
30
  this.resource = resource;
31
- // this.resource = this.expandProperties({ ...resource }, serverContext);
32
31
  this.resourceId = resourceId;
33
32
  this.serverPagination = serverPagination;
34
33
  this.serverSearch = serverSearch;
35
34
  this.containerTypes = [this.getExpandedPredicate("ldp:Container"), this.getExpandedPredicate("ldp:BasicContainer"), this.getExpandedPredicate("ldp:DirectContainer"), this.getExpandedPredicate("ldp:IndirectContainer"), "sib:federatedContainer"];
36
35
  }
37
36
 
38
- // /**
39
- // * Expand all predicates of a resource with a given context
40
- // * @param resource: object
41
- // * @param context: object
42
- // */
43
- // expandProperties(resource: object, context: object | string) {
44
- // for (let prop of Object.keys(resource)) {
45
- // if (!prop) continue;
46
- // this.objectReplaceProperty(resource, prop, ContextParser.expandTerm(prop, context as JSONLDContextParser.IJsonLdContextNormalized, true));
47
- // }
48
- // return resource
49
- // }
50
-
51
- // /**
52
- // * Change the key of an object
53
- // * @param object: object
54
- // * @param oldProp: string - current key
55
- // * @param newProp: string - new key to set
56
- // */
57
- // objectReplaceProperty(object: object, oldProp: string, newProp: string) {
58
- // if (newProp !== oldProp) {
59
- // Object.defineProperty(
60
- // object,
61
- // newProp,
62
- // Object.getOwnPropertyDescriptor(object, oldProp) || ''
63
- // );
64
- // delete object[oldProp];
65
- // }
66
- // }
67
-
68
37
  /**
69
38
  * Get the property of a resource for a given path
70
39
  * Which means that if the resource is not complete, it will fetch it
@@ -122,7 +122,13 @@ const WidgetMixin = {
122
122
  async fetchValue(field, resource) {
123
123
  if (resource && !resource.isContainer?.()) {
124
124
  let fieldValue = await resource[field];
125
- if (Array.isArray(fieldValue) && !fieldValue['ldp:contains']) return JSON.stringify(fieldValue);
125
+ if (fieldValue === null || fieldValue === undefined || fieldValue === '') return undefined;
126
+ if (Array.isArray(fieldValue) && !fieldValue['ldp:contains']) {
127
+ return JSON.stringify(fieldValue);
128
+ // Dumb edge case because if it bears only one item, when compacted the array translates into one object
129
+ } else if (typeof fieldValue === 'object' && fieldValue['@id'] && 1 === Object.keys(fieldValue).length) {
130
+ return JSON.stringify([fieldValue]);
131
+ }
126
132
  }
127
133
  return resource && !resource.isContainer?.() ? await resource[field] : undefined;
128
134
  },
@@ -63,7 +63,16 @@ const MultipleFormMixin = {
63
63
  };
64
64
  },
65
65
  setDataSrc(value, listValueTransformations) {
66
- if (value && value !== this.dataSrc) this.dataSrc = value;
66
+ if (value && value !== this.dataSrc) {
67
+ try {
68
+ if (Array.isArray(JSON.parse(value))) {
69
+ this.setValue(JSON.parse(value));
70
+ }
71
+ } catch (ex) {
72
+ this.dataSrc = value;
73
+ console.log('Not an array', ex);
74
+ }
75
+ }
67
76
  const nextProcessor = listValueTransformations.shift();
68
77
  if (nextProcessor) nextProcessor(value, listValueTransformations);
69
78
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startinblox/core",
3
- "version": "0.19.0-beta.1",
3
+ "version": "0.19.0-beta.2",
4
4
  "description": "This is a series of web component respecting both the web components standards and the Linked Data Platform convention.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",