holosphere 1.0.5 → 1.0.6
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/holosphere.js +24 -17
- package/package.json +1 -1
package/holosphere.js
CHANGED
|
@@ -121,6 +121,28 @@ class HoloSphere {
|
|
|
121
121
|
this.gun.get(hex).get(lense).set(node)
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
async parse(data) {
|
|
125
|
+
var parsed = {}
|
|
126
|
+
|
|
127
|
+
if (data._ && data._["#"]) {
|
|
128
|
+
// If the data is a reference, fetch the actual content
|
|
129
|
+
let query = data._['#'].split('/')
|
|
130
|
+
let hex = query[1]
|
|
131
|
+
let lense = query[2]
|
|
132
|
+
let key = query[3]
|
|
133
|
+
parsed = await this.getKey(hex, lense, key)
|
|
134
|
+
|
|
135
|
+
} else
|
|
136
|
+
|
|
137
|
+
try {
|
|
138
|
+
parsed = JSON.parse(data);
|
|
139
|
+
} catch (e) {
|
|
140
|
+
console.log('Invalid JSON:', data);
|
|
141
|
+
parsed = data //return the raw data
|
|
142
|
+
}
|
|
143
|
+
return parsed
|
|
144
|
+
}
|
|
145
|
+
|
|
124
146
|
/**
|
|
125
147
|
* Retrieves content from the specified hex and lense.
|
|
126
148
|
* @param {string} hex - The hex identifier.
|
|
@@ -147,23 +169,8 @@ class HoloSphere {
|
|
|
147
169
|
this.gun.get(hex.toString()).get(lense).map().once(async (itemdata, key) => {
|
|
148
170
|
counter += 1
|
|
149
171
|
if (itemdata) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
// If the data is a reference, fetch the actual content
|
|
153
|
-
let query = itemdata._['#'].split('/')
|
|
154
|
-
let hex = query[1]
|
|
155
|
-
let lense = query[2]
|
|
156
|
-
let key = query[3]
|
|
157
|
-
itemdata = await this.getNode(hex, lense, key)
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
var parsed = {}
|
|
161
|
-
try {
|
|
162
|
-
parsed = JSON.parse(itemdata);
|
|
163
|
-
} catch (e) {
|
|
164
|
-
console.log('Invalid JSON:', itemdata);
|
|
165
|
-
parsed = itemdata //return the raw data
|
|
166
|
-
}
|
|
172
|
+
let parsed = await this.parse (itemdata)
|
|
173
|
+
|
|
167
174
|
|
|
168
175
|
if (schema) {
|
|
169
176
|
let valid = this.validator.validate(schema, parsed);
|