@ztimson/momentum 1.4.1 → 1.4.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.
- package/dist/actions.d.ts +4 -0
- package/dist/actions.d.ts.map +1 -1
- package/dist/core.d.ts +1 -1
- package/dist/core.d.ts.map +1 -1
- package/dist/data.d.ts +50 -29
- package/dist/data.d.ts.map +1 -1
- package/dist/index.js +64 -51
- package/dist/index.mjs +64 -51
- package/dist/storage.d.ts +7 -8
- package/dist/storage.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/actions.d.ts
CHANGED
|
@@ -72,6 +72,10 @@ export type ActionResult = {
|
|
|
72
72
|
readonly response?: any;
|
|
73
73
|
/** Action return value */
|
|
74
74
|
readonly return?: any;
|
|
75
|
+
/** Captured HTTP headers (REST actions only) */
|
|
76
|
+
readonly headers?: Record<string, any>;
|
|
77
|
+
/** HTTP status code (REST actions only) */
|
|
78
|
+
readonly statusCode?: number;
|
|
75
79
|
};
|
|
76
80
|
/** Action triggers - Ordered to optimize filtering */
|
|
77
81
|
export declare enum ActionType {
|
package/dist/actions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAY,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAC,eAAe,EAAC,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC,MAAM,MAAM,QAAQ,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG;
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAY,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAC,eAAe,E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EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACtB,4BAA4B;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iEAAiE;IACjE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;CACb,CAAA;AAED,wBAAwB;AACxB,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;IAC3B,kBAAkB;IAClB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,qBAAqB;IACrB,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,wBAAwB;IACxB,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC;IAC5B,mBAAmB;IACnB,OAAO,EAAE,CAAC,CAAC;CACX,CAAA;AAED,OAAO,EACN,KAAK,iBAAiB,EACtB,EAAE,EAAE,GAAG,EAAE,SAAS,EAClB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,gBAAgB,EAChB,MAAM,gBAAgB,CAAC;AAExB,4CAA4C;AAC5C,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG;IAC7B,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,oBAAoB;IACpB,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;CACxB,CAAC;AAEF,OAAO,EAAC,KAAK,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAEhD,wBAAgB,WAAW,CAAC,CAAC,SAAS;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,EAAE,CA0CjF;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,WAMvC"}
|
package/dist/data.d.ts
CHANGED
|
@@ -13,6 +13,24 @@ export type Filter<T = any> = {
|
|
|
13
13
|
};
|
|
14
14
|
/** Generic MongoDB document */
|
|
15
15
|
export type Document<T> = Meta & T;
|
|
16
|
+
/** Read query options */
|
|
17
|
+
export type ReadOptions = {
|
|
18
|
+
limit?: number;
|
|
19
|
+
page?: number;
|
|
20
|
+
sortBy?: string;
|
|
21
|
+
sortDir?: 'asc' | 'desc';
|
|
22
|
+
};
|
|
23
|
+
/** Delete query options */
|
|
24
|
+
export type DeleteOptions = {
|
|
25
|
+
limit?: number;
|
|
26
|
+
};
|
|
27
|
+
/** Update query options */
|
|
28
|
+
export type UpdateOptions<T = any> = {
|
|
29
|
+
filter?: Filter<T>;
|
|
30
|
+
append?: boolean;
|
|
31
|
+
limit?: number;
|
|
32
|
+
upsert?: boolean;
|
|
33
|
+
};
|
|
16
34
|
/** Raw MongoDB query */
|
|
17
35
|
export type RawQuery = {
|
|
18
36
|
/** Query operation type */
|
|
@@ -33,53 +51,56 @@ export declare class Data extends PathEventEmitter {
|
|
|
33
51
|
[key: string]: Unsubscribe;
|
|
34
52
|
};
|
|
35
53
|
constructor(momentum: Momentum);
|
|
54
|
+
protected dataUrl(collection: string, pk?: number, filter?: any, options?: {
|
|
55
|
+
[key: string]: any;
|
|
56
|
+
}): string;
|
|
36
57
|
/**
|
|
37
|
-
* Create new document in collection
|
|
58
|
+
* Create new document(s) in collection
|
|
38
59
|
* @param {string} collection Target collection
|
|
39
|
-
* @param {Document<T>}
|
|
40
|
-
* @return {Promise<Document<T
|
|
60
|
+
* @param {Document<T> | Document<T>[]} documents New document(s)
|
|
61
|
+
* @return {Promise<Document<T> | Document<T>[]>} New saved document(s)
|
|
41
62
|
*/
|
|
42
|
-
create<T>(collection: string,
|
|
63
|
+
create<T>(collection: string, documents: Document<T> | Document<T>[]): Promise<Document<T> | Document<T>[]>;
|
|
43
64
|
/**
|
|
44
|
-
* Delete document from collection
|
|
65
|
+
* Delete document(s) from collection
|
|
45
66
|
* @param {string} collection Target collection
|
|
46
|
-
* @param {number}
|
|
47
|
-
* @
|
|
67
|
+
* @param {number | Filter<T>} filter Document ID or filter object
|
|
68
|
+
* @param {DeleteOptions} options Delete options
|
|
69
|
+
* @return {Promise<number[]>} Array of deleted document IDs
|
|
48
70
|
*/
|
|
49
|
-
delete(collection: string, id: number): Promise<number[]>;
|
|
50
|
-
delete<T>(collection: string, filter: Filter<T
|
|
71
|
+
delete(collection: string, id: number, options?: DeleteOptions): Promise<number[]>;
|
|
72
|
+
delete<T>(collection: string, filter: Filter<T>, options?: DeleteOptions): Promise<number[]>;
|
|
51
73
|
/**
|
|
52
|
-
* Read collection
|
|
53
|
-
* @param {string} collection
|
|
54
|
-
* @
|
|
74
|
+
* Read document(s) from collection
|
|
75
|
+
* @param {string} collection Target collection
|
|
76
|
+
* @param {number | Filter<T>} filter Document ID or filter object
|
|
77
|
+
* @param {ReadOptions} options Read options (limit, page, sortBy, sortDir)
|
|
78
|
+
* @return {Promise<T | T[]>} Single document if ID provided, array of documents if filter or no filter provided
|
|
55
79
|
*/
|
|
56
|
-
read<T extends Meta>(collection: string): Promise<T[]>;
|
|
57
|
-
read<T extends Meta>(collection: string,
|
|
58
|
-
read<T extends Meta>(collection: string, filter
|
|
80
|
+
read<T extends Meta>(collection: string, filter?: undefined, options?: ReadOptions): Promise<T[]>;
|
|
81
|
+
read<T extends Meta>(collection: string, filter?: number, options?: ReadOptions): Promise<T>;
|
|
82
|
+
read<T extends Meta>(collection: string, filter?: Filter<T>, options?: ReadOptions): Promise<T[]>;
|
|
59
83
|
/**
|
|
60
|
-
* Update document in collection
|
|
84
|
+
* Update document(s) in collection
|
|
61
85
|
* @param {string} collection Target collection
|
|
62
|
-
* @param {Document<T>}
|
|
63
|
-
* @param {
|
|
86
|
+
* @param {Document<T> | Document<T>[]} documents Document(s) to update
|
|
87
|
+
* @param {UpdateOptions<T>} options Update options (filter, append, limit, upsert)
|
|
64
88
|
* @return {Promise<Document<T> | Document<T>[]>} Updated document(s)
|
|
65
89
|
*/
|
|
66
|
-
update<T>(collection: string,
|
|
67
|
-
filter?: Filter<T>;
|
|
68
|
-
append?: boolean;
|
|
69
|
-
}): Promise<Document<T> | Document<T>[]>;
|
|
90
|
+
update<T>(collection: string, documents: Document<T> | Document<T>[], options?: UpdateOptions<T>): Promise<Document<T> | Document<T>[]>;
|
|
70
91
|
/**
|
|
71
|
-
*
|
|
92
|
+
* Execute raw MongoDB query
|
|
72
93
|
* @param {string} collection Target collection name
|
|
73
|
-
* @param {RawQuery} query Raw query
|
|
94
|
+
* @param {RawQuery} query Raw MongoDB query object
|
|
74
95
|
* @return {Promise<any>} Query response
|
|
75
96
|
*/
|
|
76
97
|
raw<T>(collection: string, query: RawQuery): Promise<any>;
|
|
77
98
|
/**
|
|
78
|
-
* Subscribe to live updates
|
|
79
|
-
* @param path
|
|
80
|
-
* @param {(value: T[]) => any
|
|
81
|
-
* @param opts
|
|
82
|
-
* @return {
|
|
99
|
+
* Subscribe to live data updates
|
|
100
|
+
* @param {string} path Data path to subscribe to
|
|
101
|
+
* @param {(value: T | T[]) => any} callback Function called with updated data
|
|
102
|
+
* @param {object} opts Options object with reload flag
|
|
103
|
+
* @return {Unsubscribe} Function to unsubscribe from updates
|
|
83
104
|
*/
|
|
84
105
|
sync<T>(path: string, callback: ((value: T | T[]) => any), opts?: {
|
|
85
106
|
reload?: boolean;
|
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,
|
|
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,IA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AE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IACjG,IAAI,CAAC,CAAC,SAAS,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAC5F,IAAI,CAAC,CAAC,SAAS,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAkBjG;;;;;;OAMG;IACH,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,OAAO,GAAE,aAAa,CAAC,CAAC,CAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;IAmB3I;;;;;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
|
@@ -1892,11 +1892,11 @@
|
|
|
1892
1892
|
async debug(id, callback, opts = {}) {
|
|
1893
1893
|
const uid = await this.momentum.api.request({ url: `api/actions/debug/${id}`, method: "POST", ...opts }).then((resp) => resp.uid);
|
|
1894
1894
|
if (!this.momentum.socket || !callback) return uid;
|
|
1895
|
-
const unsubscribe = this.momentum.socket.on(`actions
|
|
1895
|
+
const unsubscribe = this.momentum.socket.on(`actions/${uid}:x`, (event, payload) => {
|
|
1896
1896
|
if (payload.return) unsubscribe();
|
|
1897
1897
|
callback(payload);
|
|
1898
1898
|
});
|
|
1899
|
-
await this.momentum.socket.subscribe(`actions
|
|
1899
|
+
await this.momentum.socket.subscribe(`actions/${uid}`);
|
|
1900
1900
|
return uid;
|
|
1901
1901
|
}
|
|
1902
1902
|
/**
|
|
@@ -1914,7 +1914,7 @@
|
|
|
1914
1914
|
* @return {Promise<T>} HTTP response
|
|
1915
1915
|
*/
|
|
1916
1916
|
run(path, opts = {}) {
|
|
1917
|
-
return this.momentum.api.request({ ...opts, url: `api/
|
|
1917
|
+
return this.momentum.api.request({ ...opts, url: `api${path.startsWith("/") ? "" : "/"}${path}` });
|
|
1918
1918
|
}
|
|
1919
1919
|
}
|
|
1920
1920
|
class Agents extends AssetController {
|
|
@@ -3197,42 +3197,51 @@ Must be either: call, email or sms`);
|
|
|
3197
3197
|
}
|
|
3198
3198
|
momentum;
|
|
3199
3199
|
subscribers = {};
|
|
3200
|
+
dataUrl(collection, pk, filter, options) {
|
|
3201
|
+
const params = new URLSearchParams();
|
|
3202
|
+
if (filter) params.set("q", JSON.stringify(filter));
|
|
3203
|
+
Object.entries(options ?? {}).forEach(([key, value]) => {
|
|
3204
|
+
if (value !== void 0 && value !== null) params.set(key, String(value));
|
|
3205
|
+
});
|
|
3206
|
+
const query = params.toString();
|
|
3207
|
+
return `api/data/${collection}${pk != null ? `/${pk}` : ""}${query ? `?${query}` : ""}`;
|
|
3208
|
+
}
|
|
3200
3209
|
/**
|
|
3201
|
-
* Create new document in collection
|
|
3210
|
+
* Create new document(s) in collection
|
|
3202
3211
|
* @param {string} collection Target collection
|
|
3203
|
-
* @param {Document<T>}
|
|
3204
|
-
* @return {Promise<Document<T
|
|
3212
|
+
* @param {Document<T> | Document<T>[]} documents New document(s)
|
|
3213
|
+
* @return {Promise<Document<T> | Document<T>[]>} New saved document(s)
|
|
3205
3214
|
*/
|
|
3206
|
-
create(collection,
|
|
3207
|
-
if (!collection || !
|
|
3215
|
+
create(collection, documents) {
|
|
3216
|
+
if (!collection || !documents) throw new Error("Cannot create document, missing collection or document");
|
|
3208
3217
|
return this.momentum.api.request({
|
|
3209
3218
|
url: `api/` + PES`data/${collection}`,
|
|
3210
3219
|
method: "POST",
|
|
3211
|
-
body:
|
|
3220
|
+
body: documents
|
|
3212
3221
|
}).then((resp) => {
|
|
3213
3222
|
if (!resp) return null;
|
|
3214
|
-
this.emit(PES`data/${collection}:c`,
|
|
3223
|
+
makeArray(resp).forEach((r) => this.emit(PES`data/${collection}/${r._id}:c`, r));
|
|
3215
3224
|
return resp;
|
|
3216
3225
|
});
|
|
3217
3226
|
}
|
|
3218
|
-
async delete(collection, filter) {
|
|
3219
|
-
if (!collection ||
|
|
3220
|
-
const pk = typeof filter == "object" ? filter?.
|
|
3221
|
-
const q = typeof filter == "object" ?
|
|
3222
|
-
const url =
|
|
3227
|
+
async delete(collection, filter, options) {
|
|
3228
|
+
if (!collection || filter == null) throw new Error("Cannot delete document, missing collection or filter");
|
|
3229
|
+
const pk = typeof filter == "object" ? filter?._id ?? null : filter;
|
|
3230
|
+
const q = typeof filter == "object" && pk == null ? filter : null;
|
|
3231
|
+
const url = this.dataUrl(collection, pk, q, options);
|
|
3223
3232
|
const ids = await this.momentum.api.request({ url, method: "DELETE" });
|
|
3224
3233
|
ids.forEach((id) => this.emit(PES`data/${collection}/${id}:d`, id));
|
|
3225
3234
|
return ids;
|
|
3226
3235
|
}
|
|
3227
|
-
read(collection, filter) {
|
|
3236
|
+
read(collection, filter, options) {
|
|
3228
3237
|
if (!collection) throw new Error("Cannot read documents, missing collection");
|
|
3229
3238
|
const pk = typeof filter == "object" ? filter?.["_id"] ?? null : filter;
|
|
3230
|
-
const q = typeof filter == "object"
|
|
3231
|
-
const url =
|
|
3239
|
+
const q = typeof filter == "object" && filter != null && Object.keys(filter).length && pk == null ? filter : null;
|
|
3240
|
+
const url = this.dataUrl(collection, pk, q, options);
|
|
3232
3241
|
return this.momentum.api.request({ url }).then((resp) => {
|
|
3233
3242
|
if (!resp) return null;
|
|
3234
3243
|
if (Array.isArray(resp)) {
|
|
3235
|
-
if (!q) this.emit(PES`data/${collection}:r`, collection, resp);
|
|
3244
|
+
if (!q && !options?.limit) this.emit(PES`data/${collection}:r`, collection, resp);
|
|
3236
3245
|
else resp.forEach((r) => this.emit(PES`data/${collection}/${r._id}:r`, collection, resp));
|
|
3237
3246
|
} else {
|
|
3238
3247
|
this.emit(PES`data/${collection}/${resp._id}:r`, collection, resp);
|
|
@@ -3241,32 +3250,34 @@ Must be either: call, email or sms`);
|
|
|
3241
3250
|
});
|
|
3242
3251
|
}
|
|
3243
3252
|
/**
|
|
3244
|
-
* Update document in collection
|
|
3253
|
+
* Update document(s) in collection
|
|
3245
3254
|
* @param {string} collection Target collection
|
|
3246
|
-
* @param {Document<T>}
|
|
3247
|
-
* @param {
|
|
3255
|
+
* @param {Document<T> | Document<T>[]} documents Document(s) to update
|
|
3256
|
+
* @param {UpdateOptions<T>} options Update options (filter, append, limit, upsert)
|
|
3248
3257
|
* @return {Promise<Document<T> | Document<T>[]>} Updated document(s)
|
|
3249
3258
|
*/
|
|
3250
|
-
update(collection,
|
|
3251
|
-
if (!collection || !
|
|
3252
|
-
const
|
|
3253
|
-
const
|
|
3254
|
-
const
|
|
3259
|
+
update(collection, documents, options = {}) {
|
|
3260
|
+
if (!collection || !documents) throw new Error("Cannot update document, missing collection or document");
|
|
3261
|
+
const { filter, append, ...queryOptions } = options;
|
|
3262
|
+
const isArray = Array.isArray(documents);
|
|
3263
|
+
const firstDoc = isArray ? documents[0] : documents;
|
|
3264
|
+
const pk = isArray ? null : filter ? filter?._id ?? firstDoc._id : firstDoc._id;
|
|
3265
|
+
const q = filter && filter?._id == null ? filter : null;
|
|
3266
|
+
const url = this.dataUrl(collection, pk, q, queryOptions);
|
|
3255
3267
|
return this.momentum.api.request({
|
|
3256
3268
|
url,
|
|
3257
|
-
method:
|
|
3258
|
-
body:
|
|
3269
|
+
method: append === false ? "PUT" : "PATCH",
|
|
3270
|
+
body: documents
|
|
3259
3271
|
}).then((resp) => {
|
|
3260
3272
|
if (!resp) return null;
|
|
3261
|
-
|
|
3262
|
-
else this.emit(PES`data/${collection}/${resp._id}:u`, resp);
|
|
3273
|
+
makeArray(resp).forEach((r) => this.emit(PES`data/${collection}/${r._id}:u`, r));
|
|
3263
3274
|
return resp;
|
|
3264
3275
|
});
|
|
3265
3276
|
}
|
|
3266
3277
|
/**
|
|
3267
|
-
*
|
|
3278
|
+
* Execute raw MongoDB query
|
|
3268
3279
|
* @param {string} collection Target collection name
|
|
3269
|
-
* @param {RawQuery} query Raw query
|
|
3280
|
+
* @param {RawQuery} query Raw MongoDB query object
|
|
3270
3281
|
* @return {Promise<any>} Query response
|
|
3271
3282
|
*/
|
|
3272
3283
|
raw(collection, query) {
|
|
@@ -3278,11 +3289,11 @@ Must be either: call, email or sms`);
|
|
|
3278
3289
|
});
|
|
3279
3290
|
}
|
|
3280
3291
|
/**
|
|
3281
|
-
* Subscribe to live updates
|
|
3282
|
-
* @param path
|
|
3283
|
-
* @param {(value: T[]) => any
|
|
3284
|
-
* @param opts
|
|
3285
|
-
* @return {
|
|
3292
|
+
* Subscribe to live data updates
|
|
3293
|
+
* @param {string} path Data path to subscribe to
|
|
3294
|
+
* @param {(value: T | T[]) => any} callback Function called with updated data
|
|
3295
|
+
* @param {object} opts Options object with reload flag
|
|
3296
|
+
* @return {Unsubscribe} Function to unsubscribe from updates
|
|
3286
3297
|
*/
|
|
3287
3298
|
sync(path, callback, opts = {}) {
|
|
3288
3299
|
const e = PES`data/${path}`;
|
|
@@ -4095,17 +4106,11 @@ ${log}`;
|
|
|
4095
4106
|
/**
|
|
4096
4107
|
* Download module
|
|
4097
4108
|
* @param {string} path Path to target
|
|
4098
|
-
* @param {
|
|
4109
|
+
* @param {rename?: string} rename Rename file on download
|
|
4099
4110
|
* @return {PromiseProgress<Blob>} File as blob with progress tracking
|
|
4100
4111
|
*/
|
|
4101
|
-
download(path,
|
|
4102
|
-
|
|
4103
|
-
return this.momentum.api.request({ url: `api/${this.module}/${path}?download=true`, decode: false }).then(async (response) => {
|
|
4104
|
-
const blob = await response.blob();
|
|
4105
|
-
const name = opts.downloadAs || path.split("/").pop();
|
|
4106
|
-
downloadFile(blob, name);
|
|
4107
|
-
return response;
|
|
4108
|
-
});
|
|
4112
|
+
download(path, rename) {
|
|
4113
|
+
return this.open(path, rename || "download");
|
|
4109
4114
|
}
|
|
4110
4115
|
/**
|
|
4111
4116
|
* Retrieve file/folder metadata
|
|
@@ -4145,11 +4150,19 @@ ${log}`;
|
|
|
4145
4150
|
return response;
|
|
4146
4151
|
});
|
|
4147
4152
|
}
|
|
4148
|
-
open(path, target = "_blank") {
|
|
4153
|
+
open(path, target = typeof window !== "undefined" ? "_blank" : "blob") {
|
|
4149
4154
|
if (!path) throw new Error("Cannot download file, missing module");
|
|
4150
4155
|
const link = `${this.momentum.url.toString()}api/${this.module}/${path}`.replaceAll(/([^:])\/+/g, "$1/") + (!this.momentum.api.sameOrigin && this.momentum.api.token ? `?token=${this.momentum.api.token}` : "");
|
|
4151
|
-
if (
|
|
4152
|
-
return window.open(link, target);
|
|
4156
|
+
if (target === "url" || target === false) return link;
|
|
4157
|
+
if (target === "_blank" || target == "_self") return window.open(link, target);
|
|
4158
|
+
return this.momentum.api.request({ url: `api/${this.module}/${path}?download=true`, decode: false }).then(async (response) => {
|
|
4159
|
+
const blob = await response.blob();
|
|
4160
|
+
if (target !== "blob") {
|
|
4161
|
+
const name = target === "download" ? path.split("/").pop() : target;
|
|
4162
|
+
downloadFile(blob, name);
|
|
4163
|
+
}
|
|
4164
|
+
return blob;
|
|
4165
|
+
});
|
|
4153
4166
|
}
|
|
4154
4167
|
text(path, set) {
|
|
4155
4168
|
if (!path) throw new Error("Missing path");
|
|
@@ -4328,7 +4341,7 @@ ${log}`;
|
|
|
4328
4341
|
}
|
|
4329
4342
|
momentum;
|
|
4330
4343
|
}
|
|
4331
|
-
const version = "1.4.
|
|
4344
|
+
const version = "1.4.2";
|
|
4332
4345
|
class WebRtc extends PathEventEmitter {
|
|
4333
4346
|
constructor(momentum) {
|
|
4334
4347
|
super("webrtc");
|
package/dist/index.mjs
CHANGED
|
@@ -1888,11 +1888,11 @@ class Actions extends AssetController {
|
|
|
1888
1888
|
async debug(id, callback, opts = {}) {
|
|
1889
1889
|
const uid = await this.momentum.api.request({ url: `api/actions/debug/${id}`, method: "POST", ...opts }).then((resp) => resp.uid);
|
|
1890
1890
|
if (!this.momentum.socket || !callback) return uid;
|
|
1891
|
-
const unsubscribe = this.momentum.socket.on(`actions
|
|
1891
|
+
const unsubscribe = this.momentum.socket.on(`actions/${uid}:x`, (event, payload) => {
|
|
1892
1892
|
if (payload.return) unsubscribe();
|
|
1893
1893
|
callback(payload);
|
|
1894
1894
|
});
|
|
1895
|
-
await this.momentum.socket.subscribe(`actions
|
|
1895
|
+
await this.momentum.socket.subscribe(`actions/${uid}`);
|
|
1896
1896
|
return uid;
|
|
1897
1897
|
}
|
|
1898
1898
|
/**
|
|
@@ -1910,7 +1910,7 @@ class Actions extends AssetController {
|
|
|
1910
1910
|
* @return {Promise<T>} HTTP response
|
|
1911
1911
|
*/
|
|
1912
1912
|
run(path, opts = {}) {
|
|
1913
|
-
return this.momentum.api.request({ ...opts, url: `api/
|
|
1913
|
+
return this.momentum.api.request({ ...opts, url: `api${path.startsWith("/") ? "" : "/"}${path}` });
|
|
1914
1914
|
}
|
|
1915
1915
|
}
|
|
1916
1916
|
class Agents extends AssetController {
|
|
@@ -3193,42 +3193,51 @@ class Data extends PathEventEmitter {
|
|
|
3193
3193
|
}
|
|
3194
3194
|
momentum;
|
|
3195
3195
|
subscribers = {};
|
|
3196
|
+
dataUrl(collection, pk, filter, options) {
|
|
3197
|
+
const params = new URLSearchParams();
|
|
3198
|
+
if (filter) params.set("q", JSON.stringify(filter));
|
|
3199
|
+
Object.entries(options ?? {}).forEach(([key, value]) => {
|
|
3200
|
+
if (value !== void 0 && value !== null) params.set(key, String(value));
|
|
3201
|
+
});
|
|
3202
|
+
const query = params.toString();
|
|
3203
|
+
return `api/data/${collection}${pk != null ? `/${pk}` : ""}${query ? `?${query}` : ""}`;
|
|
3204
|
+
}
|
|
3196
3205
|
/**
|
|
3197
|
-
* Create new document in collection
|
|
3206
|
+
* Create new document(s) in collection
|
|
3198
3207
|
* @param {string} collection Target collection
|
|
3199
|
-
* @param {Document<T>}
|
|
3200
|
-
* @return {Promise<Document<T
|
|
3208
|
+
* @param {Document<T> | Document<T>[]} documents New document(s)
|
|
3209
|
+
* @return {Promise<Document<T> | Document<T>[]>} New saved document(s)
|
|
3201
3210
|
*/
|
|
3202
|
-
create(collection,
|
|
3203
|
-
if (!collection || !
|
|
3211
|
+
create(collection, documents) {
|
|
3212
|
+
if (!collection || !documents) throw new Error("Cannot create document, missing collection or document");
|
|
3204
3213
|
return this.momentum.api.request({
|
|
3205
3214
|
url: `api/` + PES`data/${collection}`,
|
|
3206
3215
|
method: "POST",
|
|
3207
|
-
body:
|
|
3216
|
+
body: documents
|
|
3208
3217
|
}).then((resp) => {
|
|
3209
3218
|
if (!resp) return null;
|
|
3210
|
-
this.emit(PES`data/${collection}:c`,
|
|
3219
|
+
makeArray(resp).forEach((r) => this.emit(PES`data/${collection}/${r._id}:c`, r));
|
|
3211
3220
|
return resp;
|
|
3212
3221
|
});
|
|
3213
3222
|
}
|
|
3214
|
-
async delete(collection, filter) {
|
|
3215
|
-
if (!collection ||
|
|
3216
|
-
const pk = typeof filter == "object" ? filter?.
|
|
3217
|
-
const q = typeof filter == "object" ?
|
|
3218
|
-
const url =
|
|
3223
|
+
async delete(collection, filter, options) {
|
|
3224
|
+
if (!collection || filter == null) throw new Error("Cannot delete document, missing collection or filter");
|
|
3225
|
+
const pk = typeof filter == "object" ? filter?._id ?? null : filter;
|
|
3226
|
+
const q = typeof filter == "object" && pk == null ? filter : null;
|
|
3227
|
+
const url = this.dataUrl(collection, pk, q, options);
|
|
3219
3228
|
const ids = await this.momentum.api.request({ url, method: "DELETE" });
|
|
3220
3229
|
ids.forEach((id) => this.emit(PES`data/${collection}/${id}:d`, id));
|
|
3221
3230
|
return ids;
|
|
3222
3231
|
}
|
|
3223
|
-
read(collection, filter) {
|
|
3232
|
+
read(collection, filter, options) {
|
|
3224
3233
|
if (!collection) throw new Error("Cannot read documents, missing collection");
|
|
3225
3234
|
const pk = typeof filter == "object" ? filter?.["_id"] ?? null : filter;
|
|
3226
|
-
const q = typeof filter == "object"
|
|
3227
|
-
const url =
|
|
3235
|
+
const q = typeof filter == "object" && filter != null && Object.keys(filter).length && pk == null ? filter : null;
|
|
3236
|
+
const url = this.dataUrl(collection, pk, q, options);
|
|
3228
3237
|
return this.momentum.api.request({ url }).then((resp) => {
|
|
3229
3238
|
if (!resp) return null;
|
|
3230
3239
|
if (Array.isArray(resp)) {
|
|
3231
|
-
if (!q) this.emit(PES`data/${collection}:r`, collection, resp);
|
|
3240
|
+
if (!q && !options?.limit) this.emit(PES`data/${collection}:r`, collection, resp);
|
|
3232
3241
|
else resp.forEach((r) => this.emit(PES`data/${collection}/${r._id}:r`, collection, resp));
|
|
3233
3242
|
} else {
|
|
3234
3243
|
this.emit(PES`data/${collection}/${resp._id}:r`, collection, resp);
|
|
@@ -3237,32 +3246,34 @@ class Data extends PathEventEmitter {
|
|
|
3237
3246
|
});
|
|
3238
3247
|
}
|
|
3239
3248
|
/**
|
|
3240
|
-
* Update document in collection
|
|
3249
|
+
* Update document(s) in collection
|
|
3241
3250
|
* @param {string} collection Target collection
|
|
3242
|
-
* @param {Document<T>}
|
|
3243
|
-
* @param {
|
|
3251
|
+
* @param {Document<T> | Document<T>[]} documents Document(s) to update
|
|
3252
|
+
* @param {UpdateOptions<T>} options Update options (filter, append, limit, upsert)
|
|
3244
3253
|
* @return {Promise<Document<T> | Document<T>[]>} Updated document(s)
|
|
3245
3254
|
*/
|
|
3246
|
-
update(collection,
|
|
3247
|
-
if (!collection || !
|
|
3248
|
-
const
|
|
3249
|
-
const
|
|
3250
|
-
const
|
|
3255
|
+
update(collection, documents, options = {}) {
|
|
3256
|
+
if (!collection || !documents) throw new Error("Cannot update document, missing collection or document");
|
|
3257
|
+
const { filter, append, ...queryOptions } = options;
|
|
3258
|
+
const isArray = Array.isArray(documents);
|
|
3259
|
+
const firstDoc = isArray ? documents[0] : documents;
|
|
3260
|
+
const pk = isArray ? null : filter ? filter?._id ?? firstDoc._id : firstDoc._id;
|
|
3261
|
+
const q = filter && filter?._id == null ? filter : null;
|
|
3262
|
+
const url = this.dataUrl(collection, pk, q, queryOptions);
|
|
3251
3263
|
return this.momentum.api.request({
|
|
3252
3264
|
url,
|
|
3253
|
-
method:
|
|
3254
|
-
body:
|
|
3265
|
+
method: append === false ? "PUT" : "PATCH",
|
|
3266
|
+
body: documents
|
|
3255
3267
|
}).then((resp) => {
|
|
3256
3268
|
if (!resp) return null;
|
|
3257
|
-
|
|
3258
|
-
else this.emit(PES`data/${collection}/${resp._id}:u`, resp);
|
|
3269
|
+
makeArray(resp).forEach((r) => this.emit(PES`data/${collection}/${r._id}:u`, r));
|
|
3259
3270
|
return resp;
|
|
3260
3271
|
});
|
|
3261
3272
|
}
|
|
3262
3273
|
/**
|
|
3263
|
-
*
|
|
3274
|
+
* Execute raw MongoDB query
|
|
3264
3275
|
* @param {string} collection Target collection name
|
|
3265
|
-
* @param {RawQuery} query Raw query
|
|
3276
|
+
* @param {RawQuery} query Raw MongoDB query object
|
|
3266
3277
|
* @return {Promise<any>} Query response
|
|
3267
3278
|
*/
|
|
3268
3279
|
raw(collection, query) {
|
|
@@ -3274,11 +3285,11 @@ class Data extends PathEventEmitter {
|
|
|
3274
3285
|
});
|
|
3275
3286
|
}
|
|
3276
3287
|
/**
|
|
3277
|
-
* Subscribe to live updates
|
|
3278
|
-
* @param path
|
|
3279
|
-
* @param {(value: T[]) => any
|
|
3280
|
-
* @param opts
|
|
3281
|
-
* @return {
|
|
3288
|
+
* Subscribe to live data updates
|
|
3289
|
+
* @param {string} path Data path to subscribe to
|
|
3290
|
+
* @param {(value: T | T[]) => any} callback Function called with updated data
|
|
3291
|
+
* @param {object} opts Options object with reload flag
|
|
3292
|
+
* @return {Unsubscribe} Function to unsubscribe from updates
|
|
3282
3293
|
*/
|
|
3283
3294
|
sync(path, callback, opts = {}) {
|
|
3284
3295
|
const e = PES`data/${path}`;
|
|
@@ -4091,17 +4102,11 @@ class Storage extends PathEventEmitter {
|
|
|
4091
4102
|
/**
|
|
4092
4103
|
* Download module
|
|
4093
4104
|
* @param {string} path Path to target
|
|
4094
|
-
* @param {
|
|
4105
|
+
* @param {rename?: string} rename Rename file on download
|
|
4095
4106
|
* @return {PromiseProgress<Blob>} File as blob with progress tracking
|
|
4096
4107
|
*/
|
|
4097
|
-
download(path,
|
|
4098
|
-
|
|
4099
|
-
return this.momentum.api.request({ url: `api/${this.module}/${path}?download=true`, decode: false }).then(async (response) => {
|
|
4100
|
-
const blob = await response.blob();
|
|
4101
|
-
const name = opts.downloadAs || path.split("/").pop();
|
|
4102
|
-
downloadFile(blob, name);
|
|
4103
|
-
return response;
|
|
4104
|
-
});
|
|
4108
|
+
download(path, rename) {
|
|
4109
|
+
return this.open(path, rename || "download");
|
|
4105
4110
|
}
|
|
4106
4111
|
/**
|
|
4107
4112
|
* Retrieve file/folder metadata
|
|
@@ -4141,11 +4146,19 @@ class Storage extends PathEventEmitter {
|
|
|
4141
4146
|
return response;
|
|
4142
4147
|
});
|
|
4143
4148
|
}
|
|
4144
|
-
open(path, target = "_blank") {
|
|
4149
|
+
open(path, target = typeof window !== "undefined" ? "_blank" : "blob") {
|
|
4145
4150
|
if (!path) throw new Error("Cannot download file, missing module");
|
|
4146
4151
|
const link = `${this.momentum.url.toString()}api/${this.module}/${path}`.replaceAll(/([^:])\/+/g, "$1/") + (!this.momentum.api.sameOrigin && this.momentum.api.token ? `?token=${this.momentum.api.token}` : "");
|
|
4147
|
-
if (
|
|
4148
|
-
return window.open(link, target);
|
|
4152
|
+
if (target === "url" || target === false) return link;
|
|
4153
|
+
if (target === "_blank" || target == "_self") return window.open(link, target);
|
|
4154
|
+
return this.momentum.api.request({ url: `api/${this.module}/${path}?download=true`, decode: false }).then(async (response) => {
|
|
4155
|
+
const blob = await response.blob();
|
|
4156
|
+
if (target !== "blob") {
|
|
4157
|
+
const name = target === "download" ? path.split("/").pop() : target;
|
|
4158
|
+
downloadFile(blob, name);
|
|
4159
|
+
}
|
|
4160
|
+
return blob;
|
|
4161
|
+
});
|
|
4149
4162
|
}
|
|
4150
4163
|
text(path, set) {
|
|
4151
4164
|
if (!path) throw new Error("Missing path");
|
|
@@ -4324,7 +4337,7 @@ class Static extends Storage {
|
|
|
4324
4337
|
}
|
|
4325
4338
|
momentum;
|
|
4326
4339
|
}
|
|
4327
|
-
const version = "1.4.
|
|
4340
|
+
const version = "1.4.2";
|
|
4328
4341
|
class WebRtc extends PathEventEmitter {
|
|
4329
4342
|
constructor(momentum) {
|
|
4330
4343
|
super("webrtc");
|
package/dist/storage.d.ts
CHANGED
|
@@ -52,12 +52,10 @@ export declare class Storage extends PathEventEmitter {
|
|
|
52
52
|
/**
|
|
53
53
|
* Download module
|
|
54
54
|
* @param {string} path Path to target
|
|
55
|
-
* @param {
|
|
55
|
+
* @param {rename?: string} rename Rename file on download
|
|
56
56
|
* @return {PromiseProgress<Blob>} File as blob with progress tracking
|
|
57
57
|
*/
|
|
58
|
-
download(path: string,
|
|
59
|
-
'downloadAs'?: string;
|
|
60
|
-
}): PromiseProgress<Blob>;
|
|
58
|
+
download(path: string, rename?: string): PromiseProgress<Blob>;
|
|
61
59
|
/**
|
|
62
60
|
* Retrieve file/folder metadata
|
|
63
61
|
* @param {string} path Path to target
|
|
@@ -80,11 +78,12 @@ export declare class Storage extends PathEventEmitter {
|
|
|
80
78
|
/**
|
|
81
79
|
* Create file link & open
|
|
82
80
|
* @param {string} path Path to target
|
|
83
|
-
* @param {false} target
|
|
84
|
-
* @return {string} URL
|
|
81
|
+
* @param {'url' | 'blob' | 'download' | false | '_blank' | '_self' | string} target File destination: url/false - returns absolute URL, blob - returns blob object, download/string - downloads/renames file, _blank/_self - Redirects / opens in new tab
|
|
82
|
+
* @return {string | Blob | Window | null} URL, Blob, or Window depending on target
|
|
85
83
|
*/
|
|
86
|
-
open(path: string, target: false): string;
|
|
87
|
-
open(path: string, target
|
|
84
|
+
open(path: string, target: 'url' | false): string;
|
|
85
|
+
open(path: string, target: 'blob' | 'download' | string): PromiseProgress<Blob>;
|
|
86
|
+
open(path: string, target: '_blank' | '_self'): Window | null;
|
|
88
87
|
/**
|
|
89
88
|
* Read file as text via extraction or OCR
|
|
90
89
|
* @param {string} path Path to target
|
package/dist/storage.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,IAAI,EAAK,MAAM,QAAQ,CAAC;AACrC,OAAO,EACN,KAAK,EACL,eAAe,EAKf,gBAAgB,EAAO,WAAW,EAAE,SAAS,EAC7C,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC,4BAA4B;AAC5B,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG;IAChC,sBAAsB;IACtB,QAAQ,CAAC,QAAQ,EAAE,CAAC,OAAO,GAAG,QAAQ,CAAC,EAAE,CAAC;IAC1C,kCAAkC;IAClC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;CAC3B,CAAA;AAED,uBAAuB;AACvB,MAAM,MAAM,QAAQ,GAAG,IAAI,GAAG;IAC7B,oBAAoB;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,gBAAgB;IAChB,QAAQ,CA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