@ztimson/momentum 1.4.3 → 1.4.4
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/data.d.ts +11 -8
- package/dist/data.d.ts.map +1 -1
- package/dist/index.js +32 -29
- package/dist/index.mjs +32 -29
- package/dist/schemas.d.ts +2 -0
- package/dist/schemas.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/data.d.ts
CHANGED
|
@@ -3,14 +3,18 @@ import { Meta, PathEventEmitter } from './core';
|
|
|
3
3
|
import { Momentum } from './momentum';
|
|
4
4
|
/** Comparison operators for filters */
|
|
5
5
|
export type FilterOperator = '=' | '!=' | '>' | '>=' | '<' | '<=' | 'in' | 'nin' | 'regex' | 'exists';
|
|
6
|
-
/** Filter value - primitive for equality
|
|
7
|
-
export type FilterValue<T = any> = T | [FilterOperator, T];
|
|
8
|
-
/** Filter object with comparison support */
|
|
9
|
-
export type Filter<T = any> = {
|
|
6
|
+
/** Filter value - primitive for equality, operator array, or top-level OR array */
|
|
7
|
+
export type FilterValue<T = any> = T | [FilterOperator | T | '||' | '&&', ...(T | FilterOperator | '||' | '&&')[]];
|
|
8
|
+
/** Filter object with comparison support, or array for top-level OR logic */
|
|
9
|
+
export type Filter<T = any> = ({
|
|
10
10
|
[K in keyof T]?: FilterValue<T[K]>;
|
|
11
11
|
} & {
|
|
12
12
|
[key: string]: FilterValue;
|
|
13
|
-
}
|
|
13
|
+
}) | Array<({
|
|
14
|
+
[K in keyof T]?: FilterValue<T[K]>;
|
|
15
|
+
} & {
|
|
16
|
+
[key: string]: FilterValue;
|
|
17
|
+
}) | '||'>;
|
|
14
18
|
/** Generic MongoDB document */
|
|
15
19
|
export type Document<T> = Meta & T;
|
|
16
20
|
/** Read query options */
|
|
@@ -51,9 +55,7 @@ export declare class Data extends PathEventEmitter {
|
|
|
51
55
|
[key: string]: Unsubscribe;
|
|
52
56
|
};
|
|
53
57
|
constructor(momentum: Momentum);
|
|
54
|
-
protected dataUrl(collection: string, pk?: number
|
|
55
|
-
[key: string]: any;
|
|
56
|
-
}): string;
|
|
58
|
+
protected dataUrl(collection: string, pk?: number): string;
|
|
57
59
|
/**
|
|
58
60
|
* Create new document(s) in collection
|
|
59
61
|
* @param {string} collection Target collection
|
|
@@ -69,6 +71,7 @@ export declare class Data extends PathEventEmitter {
|
|
|
69
71
|
* @return {Promise<number[]>} Array of deleted document IDs
|
|
70
72
|
*/
|
|
71
73
|
delete(collection: string, id: number, options?: DeleteOptions): Promise<number[]>;
|
|
74
|
+
delete(collection: string, ids: number[], options?: DeleteOptions): Promise<number[]>;
|
|
72
75
|
delete<T>(collection: string, filter: Filter<T>, options?: DeleteOptions): Promise<number[]>;
|
|
73
76
|
/**
|
|
74
77
|
* Read document(s) from collection
|
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,
|
|
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,c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AAG,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
|
@@ -3196,14 +3196,8 @@ Must be either: call, email or sms`);
|
|
|
3196
3196
|
}
|
|
3197
3197
|
momentum;
|
|
3198
3198
|
subscribers = {};
|
|
3199
|
-
dataUrl(collection, pk
|
|
3200
|
-
|
|
3201
|
-
if (filter) params.set("q", JSON.stringify(filter));
|
|
3202
|
-
Object.entries(options ?? {}).forEach(([key, value]) => {
|
|
3203
|
-
if (value !== void 0 && value !== null) params.set(key, String(value));
|
|
3204
|
-
});
|
|
3205
|
-
const query = params.toString();
|
|
3206
|
-
return `api/data/${collection}${pk != null ? `/${pk}` : ""}${query ? `?${query}` : ""}`;
|
|
3199
|
+
dataUrl(collection, pk) {
|
|
3200
|
+
return `api/data/${collection}${pk != null ? `/${pk}` : ""}`;
|
|
3207
3201
|
}
|
|
3208
3202
|
/**
|
|
3209
3203
|
* Create new document(s) in collection
|
|
@@ -3225,19 +3219,29 @@ Must be either: call, email or sms`);
|
|
|
3225
3219
|
}
|
|
3226
3220
|
async delete(collection, filter, options) {
|
|
3227
3221
|
if (!collection || filter == null) throw new Error("Cannot delete document, missing collection or filter");
|
|
3228
|
-
const pk = typeof filter == "object" ? filter?._id ?? null : filter;
|
|
3229
|
-
const
|
|
3230
|
-
const
|
|
3231
|
-
|
|
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
3232
|
ids.forEach((id) => this.emit(PES`data/${collection}/${id}:d`, id));
|
|
3233
3233
|
return ids;
|
|
3234
3234
|
}
|
|
3235
3235
|
read(collection, filter, options) {
|
|
3236
3236
|
if (!collection) throw new Error("Cannot read documents, missing collection");
|
|
3237
|
-
const pk = typeof filter == "object" ? filter?.["_id"] ?? null : filter;
|
|
3237
|
+
const pk = typeof filter == "object" ? Array.isArray(filter) ? null : filter?.["_id"] ?? null : filter;
|
|
3238
3238
|
const q = typeof filter == "object" && filter != null && Object.keys(filter).length && pk == null ? filter : null;
|
|
3239
|
-
const url = this.dataUrl(collection, pk
|
|
3240
|
-
return this.momentum.api.request({
|
|
3239
|
+
const url = this.dataUrl(collection, pk);
|
|
3240
|
+
return this.momentum.api.request({
|
|
3241
|
+
url,
|
|
3242
|
+
method: "POST",
|
|
3243
|
+
body: { filter: q, ...options, _read: true }
|
|
3244
|
+
}).then((resp) => {
|
|
3241
3245
|
if (!resp) return null;
|
|
3242
3246
|
if (Array.isArray(resp)) {
|
|
3243
3247
|
if (!q && !options?.limit) this.emit(PES`data/${collection}:r`, collection, resp);
|
|
@@ -3261,12 +3265,11 @@ Must be either: call, email or sms`);
|
|
|
3261
3265
|
const isArray = Array.isArray(documents);
|
|
3262
3266
|
const firstDoc = isArray ? documents[0] : documents;
|
|
3263
3267
|
const pk = isArray ? null : filter ? filter?._id ?? firstDoc._id : firstDoc._id;
|
|
3264
|
-
const
|
|
3265
|
-
const url = this.dataUrl(collection, pk, q, queryOptions);
|
|
3268
|
+
const url = this.dataUrl(collection, pk);
|
|
3266
3269
|
return this.momentum.api.request({
|
|
3267
3270
|
url,
|
|
3268
3271
|
method: append === false ? "PUT" : "PATCH",
|
|
3269
|
-
body: documents
|
|
3272
|
+
body: { data: documents, filter: filter && filter?._id == null ? filter : null, ...queryOptions }
|
|
3270
3273
|
}).then((resp) => {
|
|
3271
3274
|
if (!resp) return null;
|
|
3272
3275
|
makeArray(resp).forEach((r) => this.emit(PES`data/${collection}/${r._id}:u`, r));
|
|
@@ -3282,7 +3285,7 @@ Must be either: call, email or sms`);
|
|
|
3282
3285
|
raw(collection, query) {
|
|
3283
3286
|
if (!collection || !query) throw new Error("Cannot execute raw query, missing collection or query");
|
|
3284
3287
|
const mode = query.operand.startsWith("find") ? "r" : query.operand == "insertOne" ? "c" : query.operand.startsWith("delete") ? "d" : "u";
|
|
3285
|
-
return this.momentum.api.request({ url: `api/` + PES`data/${collection}
|
|
3288
|
+
return this.momentum.api.request({ url: `api/` + PES`data/${collection}`, method: "POST", body: { ...query, _raw: true } }).then((resp) => {
|
|
3286
3289
|
this.emit(PES`data/${collection}:${mode}`, resp);
|
|
3287
3290
|
return resp;
|
|
3288
3291
|
});
|
|
@@ -4059,7 +4062,7 @@ ${log}`;
|
|
|
4059
4062
|
*/
|
|
4060
4063
|
all(path) {
|
|
4061
4064
|
if (!path) path = "/";
|
|
4062
|
-
return this.momentum.api.request({ url: `api/${this.module}
|
|
4065
|
+
return this.momentum.api.request({ url: `api/${this.module}${path.startsWith("/") ? "" : "/"}${path}?all=true` }).then((resp) => {
|
|
4063
4066
|
this.emit(PES`${this.module}/${path}:r`, resp);
|
|
4064
4067
|
return resp;
|
|
4065
4068
|
});
|
|
@@ -4078,7 +4081,7 @@ ${log}`;
|
|
|
4078
4081
|
destination = [...path.slice(0, -1), destination].join("/");
|
|
4079
4082
|
if (!destination.startsWith("/")) destination = "/" + destination;
|
|
4080
4083
|
}
|
|
4081
|
-
return this.momentum.api.request({ url: `api/${this.module}
|
|
4084
|
+
return this.momentum.api.request({ url: `api/${this.module}${destination.startsWith("/") ? "" : "/"}${destination}`, body: { from: source } }).then((response) => {
|
|
4082
4085
|
this.emit(PES`${this.module}/${destination}:c`, response);
|
|
4083
4086
|
return response;
|
|
4084
4087
|
});
|
|
@@ -4090,7 +4093,7 @@ ${log}`;
|
|
|
4090
4093
|
*/
|
|
4091
4094
|
async delete(path) {
|
|
4092
4095
|
if (!path) throw new Error("Cannot delete file or folder, missing module");
|
|
4093
|
-
const count = await this.momentum.api.request({ url: `api/${this.module}
|
|
4096
|
+
const count = await this.momentum.api.request({ url: `api/${this.module}${path.startsWith("/") ? "" : "/"}${path}`, method: "DELETE" });
|
|
4094
4097
|
if (count) this.emit(PES`${this.module}/${path}:d`, path);
|
|
4095
4098
|
return count;
|
|
4096
4099
|
}
|
|
@@ -4110,7 +4113,7 @@ ${log}`;
|
|
|
4110
4113
|
*/
|
|
4111
4114
|
meta(path) {
|
|
4112
4115
|
if (!path) path = "/";
|
|
4113
|
-
return this.momentum.api.request({ url: `api/${this.module}
|
|
4116
|
+
return this.momentum.api.request({ url: `api/${this.module}${path.startsWith("/") ? "" : "/"}${path}?meta=true` }).then((resp) => {
|
|
4114
4117
|
this.emit(PES`${this.module}/${path}:r`, resp);
|
|
4115
4118
|
return resp;
|
|
4116
4119
|
});
|
|
@@ -4122,7 +4125,7 @@ ${log}`;
|
|
|
4122
4125
|
*/
|
|
4123
4126
|
mkdir(path) {
|
|
4124
4127
|
if (!path) throw new Error("Cannot make directory, missing module");
|
|
4125
|
-
return this.momentum.api.request({ url: `api/${this.module}
|
|
4128
|
+
return this.momentum.api.request({ url: `api/${this.module}${path.startsWith("/") ? "" : "/"}${path}`, body: { directory: true } }).then((resp) => {
|
|
4126
4129
|
this.emit(PES`${this.module}/${path}:c`, resp);
|
|
4127
4130
|
return resp;
|
|
4128
4131
|
});
|
|
@@ -4136,7 +4139,7 @@ ${log}`;
|
|
|
4136
4139
|
move(source, destination) {
|
|
4137
4140
|
if (!source || !destination) throw new Error("Cannot move file or folder, missing source or destination");
|
|
4138
4141
|
if (source == destination) return this.meta(destination);
|
|
4139
|
-
return this.momentum.api.request({ url: `api/${this.module}
|
|
4142
|
+
return this.momentum.api.request({ url: `api/${this.module}${source.startsWith("/") ? "" : "/"}${source}`, method: "PUT", body: { move: destination } }).then((response) => {
|
|
4140
4143
|
this.emit(PES`${this.module}/${source}:u`, response);
|
|
4141
4144
|
return response;
|
|
4142
4145
|
});
|
|
@@ -4146,7 +4149,7 @@ ${log}`;
|
|
|
4146
4149
|
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
4150
|
if (target === "url" || target === false) return link;
|
|
4148
4151
|
if (target === "_blank" || target == "_self") return window.open(link, target);
|
|
4149
|
-
return this.momentum.api.request({ url: `api/${this.module}
|
|
4152
|
+
return this.momentum.api.request({ url: `api/${this.module}${path.startsWith("/") ? "" : "/"}${path}?download=true`, decode: false }).then(async (response) => {
|
|
4150
4153
|
const blob = await response.blob();
|
|
4151
4154
|
if (target !== "blob") {
|
|
4152
4155
|
const name = target === "download" ? path.split("/").pop() : target;
|
|
@@ -4157,7 +4160,7 @@ ${log}`;
|
|
|
4157
4160
|
}
|
|
4158
4161
|
text(path, set) {
|
|
4159
4162
|
if (!path) throw new Error("Missing path");
|
|
4160
|
-
if (set !== void 0) return this.momentum.api.request({ url: `api/${this.module}
|
|
4163
|
+
if (set !== void 0) return this.momentum.api.request({ url: `api/${this.module}${path.startsWith("/") ? "" : "/"}${path}`, method: "PATCH", body: { text: set } });
|
|
4161
4164
|
else return this.momentum.api.request({ url: `api/${this.module}/${path}?text=true` });
|
|
4162
4165
|
}
|
|
4163
4166
|
/**
|
|
@@ -4177,7 +4180,7 @@ ${log}`;
|
|
|
4177
4180
|
f = [new File([f[0]], opts.rename, { type: f[0].type })];
|
|
4178
4181
|
}
|
|
4179
4182
|
return uploadWithProgress({
|
|
4180
|
-
url: `${this.momentum.url.toString()}api/${this.module}
|
|
4183
|
+
url: `${this.momentum.url.toString()}api/${this.module}${path.startsWith("/") ? "" : "/"}${path}`,
|
|
4181
4184
|
headers: this.momentum.api.headers,
|
|
4182
4185
|
files: f
|
|
4183
4186
|
}).onProgress((p) => {
|
|
@@ -4332,7 +4335,7 @@ ${log}`;
|
|
|
4332
4335
|
}
|
|
4333
4336
|
momentum;
|
|
4334
4337
|
}
|
|
4335
|
-
const version = "1.4.
|
|
4338
|
+
const version = "1.4.4";
|
|
4336
4339
|
class WebRtc extends PathEventEmitter {
|
|
4337
4340
|
constructor(momentum) {
|
|
4338
4341
|
super("webrtc");
|
package/dist/index.mjs
CHANGED
|
@@ -3192,14 +3192,8 @@ class Data extends PathEventEmitter {
|
|
|
3192
3192
|
}
|
|
3193
3193
|
momentum;
|
|
3194
3194
|
subscribers = {};
|
|
3195
|
-
dataUrl(collection, pk
|
|
3196
|
-
|
|
3197
|
-
if (filter) params.set("q", JSON.stringify(filter));
|
|
3198
|
-
Object.entries(options ?? {}).forEach(([key, value]) => {
|
|
3199
|
-
if (value !== void 0 && value !== null) params.set(key, String(value));
|
|
3200
|
-
});
|
|
3201
|
-
const query = params.toString();
|
|
3202
|
-
return `api/data/${collection}${pk != null ? `/${pk}` : ""}${query ? `?${query}` : ""}`;
|
|
3195
|
+
dataUrl(collection, pk) {
|
|
3196
|
+
return `api/data/${collection}${pk != null ? `/${pk}` : ""}`;
|
|
3203
3197
|
}
|
|
3204
3198
|
/**
|
|
3205
3199
|
* Create new document(s) in collection
|
|
@@ -3221,19 +3215,29 @@ class Data extends PathEventEmitter {
|
|
|
3221
3215
|
}
|
|
3222
3216
|
async delete(collection, filter, options) {
|
|
3223
3217
|
if (!collection || filter == null) throw new Error("Cannot delete document, missing collection or filter");
|
|
3224
|
-
const pk = typeof filter == "object" ? filter?._id ?? null : filter;
|
|
3225
|
-
const
|
|
3226
|
-
const
|
|
3227
|
-
|
|
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
3228
|
ids.forEach((id) => this.emit(PES`data/${collection}/${id}:d`, id));
|
|
3229
3229
|
return ids;
|
|
3230
3230
|
}
|
|
3231
3231
|
read(collection, filter, options) {
|
|
3232
3232
|
if (!collection) throw new Error("Cannot read documents, missing collection");
|
|
3233
|
-
const pk = typeof filter == "object" ? filter?.["_id"] ?? null : filter;
|
|
3233
|
+
const pk = typeof filter == "object" ? Array.isArray(filter) ? null : filter?.["_id"] ?? null : filter;
|
|
3234
3234
|
const q = typeof filter == "object" && filter != null && Object.keys(filter).length && pk == null ? filter : null;
|
|
3235
|
-
const url = this.dataUrl(collection, pk
|
|
3236
|
-
return this.momentum.api.request({
|
|
3235
|
+
const url = this.dataUrl(collection, pk);
|
|
3236
|
+
return this.momentum.api.request({
|
|
3237
|
+
url,
|
|
3238
|
+
method: "POST",
|
|
3239
|
+
body: { filter: q, ...options, _read: true }
|
|
3240
|
+
}).then((resp) => {
|
|
3237
3241
|
if (!resp) return null;
|
|
3238
3242
|
if (Array.isArray(resp)) {
|
|
3239
3243
|
if (!q && !options?.limit) this.emit(PES`data/${collection}:r`, collection, resp);
|
|
@@ -3257,12 +3261,11 @@ class Data extends PathEventEmitter {
|
|
|
3257
3261
|
const isArray = Array.isArray(documents);
|
|
3258
3262
|
const firstDoc = isArray ? documents[0] : documents;
|
|
3259
3263
|
const pk = isArray ? null : filter ? filter?._id ?? firstDoc._id : firstDoc._id;
|
|
3260
|
-
const
|
|
3261
|
-
const url = this.dataUrl(collection, pk, q, queryOptions);
|
|
3264
|
+
const url = this.dataUrl(collection, pk);
|
|
3262
3265
|
return this.momentum.api.request({
|
|
3263
3266
|
url,
|
|
3264
3267
|
method: append === false ? "PUT" : "PATCH",
|
|
3265
|
-
body: documents
|
|
3268
|
+
body: { data: documents, filter: filter && filter?._id == null ? filter : null, ...queryOptions }
|
|
3266
3269
|
}).then((resp) => {
|
|
3267
3270
|
if (!resp) return null;
|
|
3268
3271
|
makeArray(resp).forEach((r) => this.emit(PES`data/${collection}/${r._id}:u`, r));
|
|
@@ -3278,7 +3281,7 @@ class Data extends PathEventEmitter {
|
|
|
3278
3281
|
raw(collection, query) {
|
|
3279
3282
|
if (!collection || !query) throw new Error("Cannot execute raw query, missing collection or query");
|
|
3280
3283
|
const mode = query.operand.startsWith("find") ? "r" : query.operand == "insertOne" ? "c" : query.operand.startsWith("delete") ? "d" : "u";
|
|
3281
|
-
return this.momentum.api.request({ url: `api/` + PES`data/${collection}
|
|
3284
|
+
return this.momentum.api.request({ url: `api/` + PES`data/${collection}`, method: "POST", body: { ...query, _raw: true } }).then((resp) => {
|
|
3282
3285
|
this.emit(PES`data/${collection}:${mode}`, resp);
|
|
3283
3286
|
return resp;
|
|
3284
3287
|
});
|
|
@@ -4055,7 +4058,7 @@ class Storage extends PathEventEmitter {
|
|
|
4055
4058
|
*/
|
|
4056
4059
|
all(path) {
|
|
4057
4060
|
if (!path) path = "/";
|
|
4058
|
-
return this.momentum.api.request({ url: `api/${this.module}
|
|
4061
|
+
return this.momentum.api.request({ url: `api/${this.module}${path.startsWith("/") ? "" : "/"}${path}?all=true` }).then((resp) => {
|
|
4059
4062
|
this.emit(PES`${this.module}/${path}:r`, resp);
|
|
4060
4063
|
return resp;
|
|
4061
4064
|
});
|
|
@@ -4074,7 +4077,7 @@ class Storage extends PathEventEmitter {
|
|
|
4074
4077
|
destination = [...path.slice(0, -1), destination].join("/");
|
|
4075
4078
|
if (!destination.startsWith("/")) destination = "/" + destination;
|
|
4076
4079
|
}
|
|
4077
|
-
return this.momentum.api.request({ url: `api/${this.module}
|
|
4080
|
+
return this.momentum.api.request({ url: `api/${this.module}${destination.startsWith("/") ? "" : "/"}${destination}`, body: { from: source } }).then((response) => {
|
|
4078
4081
|
this.emit(PES`${this.module}/${destination}:c`, response);
|
|
4079
4082
|
return response;
|
|
4080
4083
|
});
|
|
@@ -4086,7 +4089,7 @@ class Storage extends PathEventEmitter {
|
|
|
4086
4089
|
*/
|
|
4087
4090
|
async delete(path) {
|
|
4088
4091
|
if (!path) throw new Error("Cannot delete file or folder, missing module");
|
|
4089
|
-
const count = await this.momentum.api.request({ url: `api/${this.module}
|
|
4092
|
+
const count = await this.momentum.api.request({ url: `api/${this.module}${path.startsWith("/") ? "" : "/"}${path}`, method: "DELETE" });
|
|
4090
4093
|
if (count) this.emit(PES`${this.module}/${path}:d`, path);
|
|
4091
4094
|
return count;
|
|
4092
4095
|
}
|
|
@@ -4106,7 +4109,7 @@ class Storage extends PathEventEmitter {
|
|
|
4106
4109
|
*/
|
|
4107
4110
|
meta(path) {
|
|
4108
4111
|
if (!path) path = "/";
|
|
4109
|
-
return this.momentum.api.request({ url: `api/${this.module}
|
|
4112
|
+
return this.momentum.api.request({ url: `api/${this.module}${path.startsWith("/") ? "" : "/"}${path}?meta=true` }).then((resp) => {
|
|
4110
4113
|
this.emit(PES`${this.module}/${path}:r`, resp);
|
|
4111
4114
|
return resp;
|
|
4112
4115
|
});
|
|
@@ -4118,7 +4121,7 @@ class Storage extends PathEventEmitter {
|
|
|
4118
4121
|
*/
|
|
4119
4122
|
mkdir(path) {
|
|
4120
4123
|
if (!path) throw new Error("Cannot make directory, missing module");
|
|
4121
|
-
return this.momentum.api.request({ url: `api/${this.module}
|
|
4124
|
+
return this.momentum.api.request({ url: `api/${this.module}${path.startsWith("/") ? "" : "/"}${path}`, body: { directory: true } }).then((resp) => {
|
|
4122
4125
|
this.emit(PES`${this.module}/${path}:c`, resp);
|
|
4123
4126
|
return resp;
|
|
4124
4127
|
});
|
|
@@ -4132,7 +4135,7 @@ class Storage extends PathEventEmitter {
|
|
|
4132
4135
|
move(source, destination) {
|
|
4133
4136
|
if (!source || !destination) throw new Error("Cannot move file or folder, missing source or destination");
|
|
4134
4137
|
if (source == destination) return this.meta(destination);
|
|
4135
|
-
return this.momentum.api.request({ url: `api/${this.module}
|
|
4138
|
+
return this.momentum.api.request({ url: `api/${this.module}${source.startsWith("/") ? "" : "/"}${source}`, method: "PUT", body: { move: destination } }).then((response) => {
|
|
4136
4139
|
this.emit(PES`${this.module}/${source}:u`, response);
|
|
4137
4140
|
return response;
|
|
4138
4141
|
});
|
|
@@ -4142,7 +4145,7 @@ class Storage extends PathEventEmitter {
|
|
|
4142
4145
|
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}` : "");
|
|
4143
4146
|
if (target === "url" || target === false) return link;
|
|
4144
4147
|
if (target === "_blank" || target == "_self") return window.open(link, target);
|
|
4145
|
-
return this.momentum.api.request({ url: `api/${this.module}
|
|
4148
|
+
return this.momentum.api.request({ url: `api/${this.module}${path.startsWith("/") ? "" : "/"}${path}?download=true`, decode: false }).then(async (response) => {
|
|
4146
4149
|
const blob = await response.blob();
|
|
4147
4150
|
if (target !== "blob") {
|
|
4148
4151
|
const name = target === "download" ? path.split("/").pop() : target;
|
|
@@ -4153,7 +4156,7 @@ class Storage extends PathEventEmitter {
|
|
|
4153
4156
|
}
|
|
4154
4157
|
text(path, set) {
|
|
4155
4158
|
if (!path) throw new Error("Missing path");
|
|
4156
|
-
if (set !== void 0) return this.momentum.api.request({ url: `api/${this.module}
|
|
4159
|
+
if (set !== void 0) return this.momentum.api.request({ url: `api/${this.module}${path.startsWith("/") ? "" : "/"}${path}`, method: "PATCH", body: { text: set } });
|
|
4157
4160
|
else return this.momentum.api.request({ url: `api/${this.module}/${path}?text=true` });
|
|
4158
4161
|
}
|
|
4159
4162
|
/**
|
|
@@ -4173,7 +4176,7 @@ class Storage extends PathEventEmitter {
|
|
|
4173
4176
|
f = [new File([f[0]], opts.rename, { type: f[0].type })];
|
|
4174
4177
|
}
|
|
4175
4178
|
return uploadWithProgress({
|
|
4176
|
-
url: `${this.momentum.url.toString()}api/${this.module}
|
|
4179
|
+
url: `${this.momentum.url.toString()}api/${this.module}${path.startsWith("/") ? "" : "/"}${path}`,
|
|
4177
4180
|
headers: this.momentum.api.headers,
|
|
4178
4181
|
files: f
|
|
4179
4182
|
}).onProgress((p) => {
|
|
@@ -4328,7 +4331,7 @@ class Static extends Storage {
|
|
|
4328
4331
|
}
|
|
4329
4332
|
momentum;
|
|
4330
4333
|
}
|
|
4331
|
-
const version = "1.4.
|
|
4334
|
+
const version = "1.4.4";
|
|
4332
4335
|
class WebRtc extends PathEventEmitter {
|
|
4333
4336
|
constructor(momentum) {
|
|
4334
4337
|
super("webrtc");
|
package/dist/schemas.d.ts
CHANGED
package/dist/schemas.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAC,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAC,KAAK,IAAI,EAAC,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC,MAAM,MAAM,MAAM,GAAG,IAAI,GAAG;IAC3B,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,0CAA0C;IAC1C,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,mCAAmC;IACnC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;IACrB,0BAA0B;IAC1B,IAAI,CAAC,EAAE;QACN,0BAA0B;QAC1B,IAAI,EAAE,MAAM,CAAC;QACb,yDAAyD;QACzD,IAAI,CAAC,EAAE,OAAO,CAAA;KACd,CAAA;IACD,sCAAsC;IACtC,MAA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