@ztimson/momentum 1.4.4 → 1.4.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/dist/audit.d.ts +2 -2
- package/dist/audit.d.ts.map +1 -1
- package/dist/data.d.ts +19 -13
- package/dist/data.d.ts.map +1 -1
- package/dist/index.js +29 -34
- package/dist/index.mjs +29 -34
- package/package.json +2 -2
package/dist/audit.d.ts
CHANGED
package/dist/audit.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAE,gBAAgB,EAAC,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC,qBAAqB;AACrB,MAAM,MAAM,QAAQ,CAAC,CAAC,GAAG,GAAG,IAAI,IAAI,GAAG;IACtC,oBAAoB;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,
|
|
1
|
+
{"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAE,gBAAgB,EAAC,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC,qBAAqB;AACrB,MAAM,MAAM,QAAQ,CAAC,CAAC,GAAG,GAAG,IAAI,IAAI,GAAG;IACtC,oBAAoB;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,cAAc;IACd,KAAK,EAAE,GAAG,CAAC;CACX,CAAA;AAED,qBAAa,KAAM,SAAQ,gBAAgB;IAE9B,SAAS,CAAC,QAAQ,EAAE,QAAQ;gBAAlB,QAAQ,EAAE,QAAQ;IAIlC,SAAS,IAAI,OAAO,CAAC;QAAC,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;KAAC,CAAC;IAChD,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAK5C,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAKzD,QAAQ,CAAC,EAAE,EAAE,MAAM;CAIzB"}
|
package/dist/data.d.ts
CHANGED
|
@@ -55,30 +55,21 @@ export declare class Data extends PathEventEmitter {
|
|
|
55
55
|
[key: string]: Unsubscribe;
|
|
56
56
|
};
|
|
57
57
|
constructor(momentum: Momentum);
|
|
58
|
-
protected dataUrl(collection: string, pk?: number): string;
|
|
58
|
+
protected dataUrl(collection: string, pk?: number | null): string;
|
|
59
59
|
/**
|
|
60
60
|
* Create new document(s) in collection
|
|
61
61
|
* @param {string} collection Target collection
|
|
62
62
|
* @param {Document<T> | Document<T>[]} documents New document(s)
|
|
63
63
|
* @return {Promise<Document<T> | Document<T>[]>} New saved document(s)
|
|
64
64
|
*/
|
|
65
|
-
create<T>(collection: string, documents: Document<T>
|
|
66
|
-
|
|
67
|
-
* Delete document(s) from collection
|
|
68
|
-
* @param {string} collection Target collection
|
|
69
|
-
* @param {number | Filter<T>} filter Document ID or filter object
|
|
70
|
-
* @param {DeleteOptions} options Delete options
|
|
71
|
-
* @return {Promise<number[]>} Array of deleted document IDs
|
|
72
|
-
*/
|
|
73
|
-
delete(collection: string, id: number, options?: DeleteOptions): Promise<number[]>;
|
|
74
|
-
delete(collection: string, ids: number[], options?: DeleteOptions): Promise<number[]>;
|
|
75
|
-
delete<T>(collection: string, filter: Filter<T>, options?: DeleteOptions): Promise<number[]>;
|
|
65
|
+
create<T>(collection: string, documents: Document<T>): Promise<Document<T>>;
|
|
66
|
+
create<T>(collection: string, documents: Document<T>[]): Promise<Document<T>[]>;
|
|
76
67
|
/**
|
|
77
68
|
* Read document(s) from collection
|
|
78
69
|
* @param {string} collection Target collection
|
|
79
70
|
* @param {number | Filter<T>} filter Document ID or filter object
|
|
80
71
|
* @param {ReadOptions} options Read options (limit, page, sortBy, sortDir)
|
|
81
|
-
* @return {Promise<T | T[]>} Single document if ID provided, array
|
|
72
|
+
* @return {Promise<T | T[]>} Single document if numeric ID provided, array otherwise
|
|
82
73
|
*/
|
|
83
74
|
read<T extends Meta>(collection: string, filter?: undefined, options?: ReadOptions): Promise<T[]>;
|
|
84
75
|
read<T extends Meta>(collection: string, filter?: number, options?: ReadOptions): Promise<T>;
|
|
@@ -90,7 +81,22 @@ export declare class Data extends PathEventEmitter {
|
|
|
90
81
|
* @param {UpdateOptions<T>} options Update options (filter, append, limit, upsert)
|
|
91
82
|
* @return {Promise<Document<T> | Document<T>[]>} Updated document(s)
|
|
92
83
|
*/
|
|
84
|
+
update<T>(collection: string, documents: Document<T>, options?: UpdateOptions<T>): Promise<Document<T>>;
|
|
85
|
+
update<T>(collection: string, documents: Document<T>[], options?: UpdateOptions<T>): Promise<Document<T>[]>;
|
|
86
|
+
update<T>(collection: string, documents: Partial<T>, options: UpdateOptions<T> & {
|
|
87
|
+
filter: Filter<T>;
|
|
88
|
+
}): Promise<Document<T>[]>;
|
|
93
89
|
update<T>(collection: string, documents: Document<T> | Document<T>[], options?: UpdateOptions<T>): Promise<Document<T> | Document<T>[]>;
|
|
90
|
+
/**
|
|
91
|
+
* Delete document(s) from collection
|
|
92
|
+
* @param {string} collection Target collection
|
|
93
|
+
* @param {number | Filter<T>} filter Document ID or filter object
|
|
94
|
+
* @param {DeleteOptions} options Delete options
|
|
95
|
+
* @return {Promise<number[]>} Array of deleted document IDs
|
|
96
|
+
*/
|
|
97
|
+
delete(collection: string, id: number, options?: DeleteOptions): Promise<number[]>;
|
|
98
|
+
delete(collection: string, ids: number[], options?: DeleteOptions): Promise<number[]>;
|
|
99
|
+
delete<T>(collection: string, filter: Filter<T>, options?: DeleteOptions): Promise<number[]>;
|
|
94
100
|
/**
|
|
95
101
|
* Execute raw MongoDB query
|
|
96
102
|
* @param {string} collection Target collection name
|
package/dist/data.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../src/data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAC,KAAK,IAAI,EAAE,gBAAgB,EAAM,MAAM,QAAQ,CAAC;AACxD,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC,uCAAuC;AACvC,MAAM,MAAM,cAAc,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEtG,mFAAmF;AACnF,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,cAAc,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,EAAE,GAAG,CAAC,CAAC,GAAG,cAAc,GAAG,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;AAEnH,6EAA6E;AAC7E,MAAM,MAAM,MAAM,CAAC,CAAC,GAAG,GAAG,IAAI,CAAA;KAC5B,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAG,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAC;CAAC,IACrE,KAAK,CAAC,CAAA;KAAE,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAC,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAA;CAAC,IAAG,IAAI,CAAC,CAAC;AAEnF,+BAA+B;AAC/B,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,IAAI,GAAG,CAAC,CAAC;AAEnC,yBAAyB;AACzB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,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,OAAO,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;IAoBvI;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAClF,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IACrF,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAkB5F;;;;;OAKG;IACH,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;IASzD;;;;;;OAMG;IACH,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,IAAI,GAAE;QAAC,MAAM,CAAC,EAAE,OAAO,CAAA;KAAM,GAAG,WAAW;CAmBtG"}
|
package/dist/index.js
CHANGED
|
@@ -3189,6 +3189,11 @@ Must be either: call, email or sms`);
|
|
|
3189
3189
|
}
|
|
3190
3190
|
}
|
|
3191
3191
|
}
|
|
3192
|
+
function numericPk(filter) {
|
|
3193
|
+
if (filter == null || typeof filter !== "object" || Array.isArray(filter)) return null;
|
|
3194
|
+
const id = filter["_id"];
|
|
3195
|
+
return typeof id === "number" ? id : null;
|
|
3196
|
+
}
|
|
3192
3197
|
class Data extends PathEventEmitter {
|
|
3193
3198
|
constructor(momentum) {
|
|
3194
3199
|
super();
|
|
@@ -3199,14 +3204,9 @@ Must be either: call, email or sms`);
|
|
|
3199
3204
|
dataUrl(collection, pk) {
|
|
3200
3205
|
return `api/data/${collection}${pk != null ? `/${pk}` : ""}`;
|
|
3201
3206
|
}
|
|
3202
|
-
/**
|
|
3203
|
-
* Create new document(s) in collection
|
|
3204
|
-
* @param {string} collection Target collection
|
|
3205
|
-
* @param {Document<T> | Document<T>[]} documents New document(s)
|
|
3206
|
-
* @return {Promise<Document<T> | Document<T>[]>} New saved document(s)
|
|
3207
|
-
*/
|
|
3208
3207
|
create(collection, documents) {
|
|
3209
3208
|
if (!collection || !documents) throw new Error("Cannot create document, missing collection or document");
|
|
3209
|
+
if (Array.isArray(documents) && !documents.length) return Promise.resolve([]);
|
|
3210
3210
|
return this.momentum.api.request({
|
|
3211
3211
|
url: `api/` + PES`data/${collection}`,
|
|
3212
3212
|
method: "POST",
|
|
@@ -3217,25 +3217,10 @@ Must be either: call, email or sms`);
|
|
|
3217
3217
|
return resp;
|
|
3218
3218
|
});
|
|
3219
3219
|
}
|
|
3220
|
-
async delete(collection, filter, options) {
|
|
3221
|
-
if (!collection || filter == null) throw new Error("Cannot delete document, missing collection or filter");
|
|
3222
|
-
const pk = Array.isArray(filter) ? null : typeof filter == "object" ? filter?.["_id"] ?? null : filter;
|
|
3223
|
-
const url = this.dataUrl(collection, pk);
|
|
3224
|
-
const ids = await this.momentum.api.request({
|
|
3225
|
-
url,
|
|
3226
|
-
method: "DELETE",
|
|
3227
|
-
body: {
|
|
3228
|
-
filter: Array.isArray(filter) ? { _id: ["in", filter] } : typeof filter == "object" && pk == null ? filter : null,
|
|
3229
|
-
...options
|
|
3230
|
-
}
|
|
3231
|
-
});
|
|
3232
|
-
ids.forEach((id) => this.emit(PES`data/${collection}/${id}:d`, id));
|
|
3233
|
-
return ids;
|
|
3234
|
-
}
|
|
3235
3220
|
read(collection, filter, options) {
|
|
3236
3221
|
if (!collection) throw new Error("Cannot read documents, missing collection");
|
|
3237
|
-
const pk = typeof filter
|
|
3238
|
-
const q = typeof filter
|
|
3222
|
+
const pk = typeof filter === "number" ? filter : numericPk(filter);
|
|
3223
|
+
const q = typeof filter === "object" && filter != null && Object.keys(filter).length && pk == null ? filter : null;
|
|
3239
3224
|
const url = this.dataUrl(collection, pk);
|
|
3240
3225
|
return this.momentum.api.request({
|
|
3241
3226
|
url,
|
|
@@ -3252,30 +3237,40 @@ Must be either: call, email or sms`);
|
|
|
3252
3237
|
return resp;
|
|
3253
3238
|
});
|
|
3254
3239
|
}
|
|
3255
|
-
/**
|
|
3256
|
-
* Update document(s) in collection
|
|
3257
|
-
* @param {string} collection Target collection
|
|
3258
|
-
* @param {Document<T> | Document<T>[]} documents Document(s) to update
|
|
3259
|
-
* @param {UpdateOptions<T>} options Update options (filter, append, limit, upsert)
|
|
3260
|
-
* @return {Promise<Document<T> | Document<T>[]>} Updated document(s)
|
|
3261
|
-
*/
|
|
3262
3240
|
update(collection, documents, options = {}) {
|
|
3263
|
-
if (!collection || !documents) throw new Error("Cannot update
|
|
3241
|
+
if (!collection || !documents) throw new Error("Cannot update, missing collection or document");
|
|
3242
|
+
if (Array.isArray(documents) && !documents.length) return Promise.resolve([]);
|
|
3264
3243
|
const { filter, append, ...queryOptions } = options;
|
|
3265
3244
|
const isArray = Array.isArray(documents);
|
|
3266
3245
|
const firstDoc = isArray ? documents[0] : documents;
|
|
3267
|
-
const pk = isArray
|
|
3246
|
+
const pk = !isArray && !filter ? typeof firstDoc._id === "number" ? firstDoc._id : null : null;
|
|
3268
3247
|
const url = this.dataUrl(collection, pk);
|
|
3269
3248
|
return this.momentum.api.request({
|
|
3270
3249
|
url,
|
|
3271
3250
|
method: append === false ? "PUT" : "PATCH",
|
|
3272
|
-
body: { data: documents, filter: filter && filter
|
|
3251
|
+
body: { data: documents, filter: filter && numericPk(filter) == null ? filter : null, ...queryOptions }
|
|
3273
3252
|
}).then((resp) => {
|
|
3274
3253
|
if (!resp) return null;
|
|
3275
3254
|
makeArray(resp).forEach((r) => this.emit(PES`data/${collection}/${r._id}:u`, r));
|
|
3276
3255
|
return resp;
|
|
3277
3256
|
});
|
|
3278
3257
|
}
|
|
3258
|
+
async delete(collection, filter, options) {
|
|
3259
|
+
if (!collection || filter == null) throw new Error("Cannot delete document, missing collection or filter");
|
|
3260
|
+
if (Array.isArray(filter) && !filter.length) return [];
|
|
3261
|
+
const pk = typeof filter === "number" ? filter : null;
|
|
3262
|
+
const url = this.dataUrl(collection, pk);
|
|
3263
|
+
const ids = await this.momentum.api.request({
|
|
3264
|
+
url,
|
|
3265
|
+
method: "DELETE",
|
|
3266
|
+
body: {
|
|
3267
|
+
filter: Array.isArray(filter) ? { _id: ["in", filter] } : typeof filter === "object" ? filter : null,
|
|
3268
|
+
...options
|
|
3269
|
+
}
|
|
3270
|
+
});
|
|
3271
|
+
ids.forEach((id) => this.emit(PES`data/${collection}/${id}:d`, id));
|
|
3272
|
+
return ids;
|
|
3273
|
+
}
|
|
3279
3274
|
/**
|
|
3280
3275
|
* Execute raw MongoDB query
|
|
3281
3276
|
* @param {string} collection Target collection name
|
|
@@ -4335,7 +4330,7 @@ ${log}`;
|
|
|
4335
4330
|
}
|
|
4336
4331
|
momentum;
|
|
4337
4332
|
}
|
|
4338
|
-
const version = "1.4.
|
|
4333
|
+
const version = "1.4.6";
|
|
4339
4334
|
class WebRtc extends PathEventEmitter {
|
|
4340
4335
|
constructor(momentum) {
|
|
4341
4336
|
super("webrtc");
|
package/dist/index.mjs
CHANGED
|
@@ -3185,6 +3185,11 @@ class Client extends PathEventEmitter {
|
|
|
3185
3185
|
}
|
|
3186
3186
|
}
|
|
3187
3187
|
}
|
|
3188
|
+
function numericPk(filter) {
|
|
3189
|
+
if (filter == null || typeof filter !== "object" || Array.isArray(filter)) return null;
|
|
3190
|
+
const id = filter["_id"];
|
|
3191
|
+
return typeof id === "number" ? id : null;
|
|
3192
|
+
}
|
|
3188
3193
|
class Data extends PathEventEmitter {
|
|
3189
3194
|
constructor(momentum) {
|
|
3190
3195
|
super();
|
|
@@ -3195,14 +3200,9 @@ class Data extends PathEventEmitter {
|
|
|
3195
3200
|
dataUrl(collection, pk) {
|
|
3196
3201
|
return `api/data/${collection}${pk != null ? `/${pk}` : ""}`;
|
|
3197
3202
|
}
|
|
3198
|
-
/**
|
|
3199
|
-
* Create new document(s) in collection
|
|
3200
|
-
* @param {string} collection Target collection
|
|
3201
|
-
* @param {Document<T> | Document<T>[]} documents New document(s)
|
|
3202
|
-
* @return {Promise<Document<T> | Document<T>[]>} New saved document(s)
|
|
3203
|
-
*/
|
|
3204
3203
|
create(collection, documents) {
|
|
3205
3204
|
if (!collection || !documents) throw new Error("Cannot create document, missing collection or document");
|
|
3205
|
+
if (Array.isArray(documents) && !documents.length) return Promise.resolve([]);
|
|
3206
3206
|
return this.momentum.api.request({
|
|
3207
3207
|
url: `api/` + PES`data/${collection}`,
|
|
3208
3208
|
method: "POST",
|
|
@@ -3213,25 +3213,10 @@ class Data extends PathEventEmitter {
|
|
|
3213
3213
|
return resp;
|
|
3214
3214
|
});
|
|
3215
3215
|
}
|
|
3216
|
-
async delete(collection, filter, options) {
|
|
3217
|
-
if (!collection || filter == null) throw new Error("Cannot delete document, missing collection or filter");
|
|
3218
|
-
const pk = Array.isArray(filter) ? null : typeof filter == "object" ? filter?.["_id"] ?? null : filter;
|
|
3219
|
-
const url = this.dataUrl(collection, pk);
|
|
3220
|
-
const ids = await this.momentum.api.request({
|
|
3221
|
-
url,
|
|
3222
|
-
method: "DELETE",
|
|
3223
|
-
body: {
|
|
3224
|
-
filter: Array.isArray(filter) ? { _id: ["in", filter] } : typeof filter == "object" && pk == null ? filter : null,
|
|
3225
|
-
...options
|
|
3226
|
-
}
|
|
3227
|
-
});
|
|
3228
|
-
ids.forEach((id) => this.emit(PES`data/${collection}/${id}:d`, id));
|
|
3229
|
-
return ids;
|
|
3230
|
-
}
|
|
3231
3216
|
read(collection, filter, options) {
|
|
3232
3217
|
if (!collection) throw new Error("Cannot read documents, missing collection");
|
|
3233
|
-
const pk = typeof filter
|
|
3234
|
-
const q = typeof filter
|
|
3218
|
+
const pk = typeof filter === "number" ? filter : numericPk(filter);
|
|
3219
|
+
const q = typeof filter === "object" && filter != null && Object.keys(filter).length && pk == null ? filter : null;
|
|
3235
3220
|
const url = this.dataUrl(collection, pk);
|
|
3236
3221
|
return this.momentum.api.request({
|
|
3237
3222
|
url,
|
|
@@ -3248,30 +3233,40 @@ class Data extends PathEventEmitter {
|
|
|
3248
3233
|
return resp;
|
|
3249
3234
|
});
|
|
3250
3235
|
}
|
|
3251
|
-
/**
|
|
3252
|
-
* Update document(s) in collection
|
|
3253
|
-
* @param {string} collection Target collection
|
|
3254
|
-
* @param {Document<T> | Document<T>[]} documents Document(s) to update
|
|
3255
|
-
* @param {UpdateOptions<T>} options Update options (filter, append, limit, upsert)
|
|
3256
|
-
* @return {Promise<Document<T> | Document<T>[]>} Updated document(s)
|
|
3257
|
-
*/
|
|
3258
3236
|
update(collection, documents, options = {}) {
|
|
3259
|
-
if (!collection || !documents) throw new Error("Cannot update
|
|
3237
|
+
if (!collection || !documents) throw new Error("Cannot update, missing collection or document");
|
|
3238
|
+
if (Array.isArray(documents) && !documents.length) return Promise.resolve([]);
|
|
3260
3239
|
const { filter, append, ...queryOptions } = options;
|
|
3261
3240
|
const isArray = Array.isArray(documents);
|
|
3262
3241
|
const firstDoc = isArray ? documents[0] : documents;
|
|
3263
|
-
const pk = isArray
|
|
3242
|
+
const pk = !isArray && !filter ? typeof firstDoc._id === "number" ? firstDoc._id : null : null;
|
|
3264
3243
|
const url = this.dataUrl(collection, pk);
|
|
3265
3244
|
return this.momentum.api.request({
|
|
3266
3245
|
url,
|
|
3267
3246
|
method: append === false ? "PUT" : "PATCH",
|
|
3268
|
-
body: { data: documents, filter: filter && filter
|
|
3247
|
+
body: { data: documents, filter: filter && numericPk(filter) == null ? filter : null, ...queryOptions }
|
|
3269
3248
|
}).then((resp) => {
|
|
3270
3249
|
if (!resp) return null;
|
|
3271
3250
|
makeArray(resp).forEach((r) => this.emit(PES`data/${collection}/${r._id}:u`, r));
|
|
3272
3251
|
return resp;
|
|
3273
3252
|
});
|
|
3274
3253
|
}
|
|
3254
|
+
async delete(collection, filter, options) {
|
|
3255
|
+
if (!collection || filter == null) throw new Error("Cannot delete document, missing collection or filter");
|
|
3256
|
+
if (Array.isArray(filter) && !filter.length) return [];
|
|
3257
|
+
const pk = typeof filter === "number" ? filter : null;
|
|
3258
|
+
const url = this.dataUrl(collection, pk);
|
|
3259
|
+
const ids = await this.momentum.api.request({
|
|
3260
|
+
url,
|
|
3261
|
+
method: "DELETE",
|
|
3262
|
+
body: {
|
|
3263
|
+
filter: Array.isArray(filter) ? { _id: ["in", filter] } : typeof filter === "object" ? filter : null,
|
|
3264
|
+
...options
|
|
3265
|
+
}
|
|
3266
|
+
});
|
|
3267
|
+
ids.forEach((id) => this.emit(PES`data/${collection}/${id}:d`, id));
|
|
3268
|
+
return ids;
|
|
3269
|
+
}
|
|
3275
3270
|
/**
|
|
3276
3271
|
* Execute raw MongoDB query
|
|
3277
3272
|
* @param {string} collection Target collection name
|
|
@@ -4331,7 +4326,7 @@ class Static extends Storage {
|
|
|
4331
4326
|
}
|
|
4332
4327
|
momentum;
|
|
4333
4328
|
}
|
|
4334
|
-
const version = "1.4.
|
|
4329
|
+
const version = "1.4.6";
|
|
4335
4330
|
class WebRtc extends PathEventEmitter {
|
|
4336
4331
|
constructor(momentum) {
|
|
4337
4332
|
super("webrtc");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ztimson/momentum",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.6",
|
|
4
4
|
"description": "Client library for momentum",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Momentum"
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"postbuild": "npm run build:docs && node -e \"const fs=require('fs');fs.cpSync('dist/index.mjs','../server/public/momentum.mjs');fs.cpSync('dist/index.js','../server/public/momentum.js');fs.cpSync('dist/momentum.worker.mjs','../server/public/momentum.worker.mjs')\""
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@ztimson/utils": "^0.
|
|
36
|
+
"@ztimson/utils": "^0.30.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^22.5.4",
|