@livequery/client 1.0.52 → 1.0.53
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/build/Collection.js +7 -8
- package/package.json +1 -1
package/build/Collection.js
CHANGED
|
@@ -195,21 +195,20 @@ export class CollectionObservable extends Observable {
|
|
|
195
195
|
filter(filters) {
|
|
196
196
|
this.fetch_data(filters, true);
|
|
197
197
|
}
|
|
198
|
-
async add(payload) {
|
|
199
|
-
if (this.ref.includes('.'))
|
|
200
|
-
throw 'INVAILD_COLLECTION_REF_FOR_ADDING';
|
|
201
|
-
return await this.collection_options.transporter.add(`${this.ref}`, payload);
|
|
202
|
-
}
|
|
203
198
|
#find_ref_by_id(id) {
|
|
204
199
|
if (!id)
|
|
205
200
|
return { ref: this.ref, collection_ref: this.ref };
|
|
206
|
-
const
|
|
207
|
-
if (!
|
|
201
|
+
const origin_ref = this.#state.items[this.#IdMap.get(id)].__ref;
|
|
202
|
+
if (!origin_ref)
|
|
208
203
|
throw 'COLLECTION_REF_NOT_FOUND';
|
|
209
|
-
const refs =
|
|
204
|
+
const refs = origin_ref.split('/');
|
|
210
205
|
const collection_ref = refs.slice(0, refs.length - (refs.length % 2 == 1 ? 0 : 1)).join('/');
|
|
206
|
+
const ref = `${collection_ref}/${id}`;
|
|
211
207
|
return { ref, id, collection_ref };
|
|
212
208
|
}
|
|
209
|
+
async add(payload) {
|
|
210
|
+
return await this.collection_options.transporter.add(`${this.ref}`, payload);
|
|
211
|
+
}
|
|
213
212
|
async update({ id: update_payload_id, ...payload }) {
|
|
214
213
|
const { id, ref } = this.#find_ref_by_id(update_payload_id);
|
|
215
214
|
// Trigger local update
|