@ztimson/momentum 1.3.1 → 1.4.1

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 CHANGED
@@ -26,6 +26,12 @@ export type ToolArgs = {
26
26
  };
27
27
  };
28
28
  };
29
+ export type LogEntry = {
30
+ /** Log level */
31
+ level: 'debug' | 'log' | 'info' | 'warn' | 'error';
32
+ /** Message parts */
33
+ message: any[];
34
+ };
29
35
  /** Action model */
30
36
  export type Action = Meta & {
31
37
  /** Action name */
@@ -60,10 +66,8 @@ export type ActionResult = {
60
66
  readonly duration: number;
61
67
  /** Start timestamp */
62
68
  readonly start: Date;
63
- /** Console output */
64
- readonly stdout: any[];
65
- /** Console errors */
66
- readonly stderr: any[];
69
+ /** Console logs with levels and timestamps */
70
+ readonly logs: LogEntry[];
67
71
  /** HTTP Response */
68
72
  readonly response?: any;
69
73
  /** Action return value */
@@ -93,12 +97,19 @@ export declare class Actions extends AssetController<Action> {
93
97
  protected momentum: Momentum;
94
98
  constructor(momentum: Momentum);
95
99
  /**
96
- * Manually trigger an actions execution
100
+ * Manually trigger an actions execution with real-time updates
97
101
  * @param {string} id Action ID
102
+ * @param {(payload: ActionUpdate) => any} callback Get updates in real time
98
103
  * @param {HttpRequestOptions} opts Additional arguments
99
- * @return {Promise<ActionResult>} All action output including console logs & return
104
+ * @return {Promise<string>} Run UID for socket subscription
105
+ */
106
+ debug(id: string, callback?: (payload: Partial<ActionResult>) => any, opts?: HttpRequestOptions): Promise<string>;
107
+ /**
108
+ * Terminate a running action
109
+ * @param {string} id Action ID
110
+ * @return {Promise<boolean>} Success status
100
111
  */
101
- debug(id: string, opts?: HttpRequestOptions): Promise<ActionResult>;
112
+ terminate(id: string): Promise<boolean>;
102
113
  /**
103
114
  * Run an HTTP action
104
115
  * @param {string} path HTTP path excluding `/api/actions/run`
@@ -1 +1 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"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AoB;IACpB,QAAQ,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC;IACxB,0BAA0B;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC;CACtB,CAAA;AAED,sDAAsD;AACtD,oBAAY,UAAU;IACrB,0BAA0B;IACzB,QAAQ,IAAI;IACb,wBAAwB;IACvB,MAAM,IAAI;IACX,yBAAyB;IACxB,OAAO,IAAI;IACZ,uBAAuB;IACtB,KAAK,IAAI;IACV,uBAAuB;IACtB,KAAK,IAAI;IACV,qBAAqB;IACpB,OAAO,IAAI;IACZ,eAAe;IACd,MAAM,IAAI;IACX,mBAAmB;IAClB,IAAI,IAAI;CACT;AAED,wCAAwC;AACxC,qBAAa,OAAQ,SAAQ,eAAe,CAAC,MAAM,CAAC;IACvC,SAAS,CAAC,QAAQ,EAAE,QAAQ;gBAAlB,QAAQ,EAAE,QAAQ;IAIxC;;;;;;OAMG;IACG,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,KAAK,GAAG,EAAE,IAAI,GAAE,kBAAuB,GAAG,OAAO,CAAC,MAAM,CAAC;IAY3H;;;;OAIG;IACH,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKvC;;;;;OAKG;IACH,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,kBAAuB,GAAG,OAAO,CAAC,CAAC,CAAC;CAG/D"}
package/dist/ai.d.ts CHANGED
@@ -54,17 +54,49 @@ export type AiModel = {
54
54
  /** Authentication token */
55
55
  token?: string;
56
56
  };
57
+ export type AiMessageSchema = {
58
+ [key: string]: {
59
+ /** Argument type */
60
+ type: 'array' | 'boolean' | 'number' | 'object' | 'string';
61
+ /** Argument description */
62
+ description: string;
63
+ /** Required argument */
64
+ required?: boolean;
65
+ /** Default value */
66
+ default?: any;
67
+ /** Options */
68
+ enum?: string[];
69
+ /** Minimum value or length */
70
+ min?: number;
71
+ /** Maximum value or length */
72
+ max?: number;
73
+ /** Match pattern */
74
+ pattern?: string;
75
+ /** Child arguments */
76
+ items?: {
77
+ [key: string]: AiMessageSchema;
78
+ };
79
+ };
80
+ };
57
81
  /**
58
82
  * Configuration options defining the interaction settings for an AI agent session.
59
83
  * Includes identification of the target agent, optional context information parsed separately from user messages, file attachments to be processed with the message, and a streaming callback handler that manages progress events such as response chunks, completion status, and tool invocation updates.
60
84
  */
61
85
  export type AiOptions = {
86
+ /** Disable history, personality, and memory for question (Default: true) */
87
+ anonymous?: boolean;
62
88
  /** Which AI agent are you speaking to */
63
89
  agent?: string;
64
- /** Additional context information kept separate from user messages */
90
+ /** Additional context information to attach to message */
65
91
  context?: any;
66
- /** Files that will be parsed with message */
92
+ /** Attach files to message context */
67
93
  files?: File[];
94
+ /** Format response to match JSON schema */
95
+ schema?: AiMessageSchema;
96
+ /** Add to agents system prompt */
97
+ system?: string;
98
+ /** Override agents temperature */
99
+ temperature?: number;
68
100
  };
69
101
  /** Skills the LLM can call learn on demand */
70
102
  export type AiSkill = Meta & {
package/dist/ai.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ai.d.ts","sourceRoot":"","sources":["../src/ai.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAC,IAAI,EAAE,gBAAgB,EAAM,MAAM,QAAQ,CAAC;AACnD,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC,qBAAqB;AACrB,MAAM,MAAM,OAAO,GAAG,IAAI,GAAG;IAC5B,iBAAiB;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,2CAA2C;IAC3C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gBAAgB;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,mCAAmC;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,sBAAsB;I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;CAGxC;AAED,kCAAkC;AAClC,qBAAa,MAAO,SAAQ,eAAe,CAAC,OAAO,CAAC;IACvC,SAAS,CAAC,QAAQ,EAAE,QAAQ;gBAAlB,QAAQ,EAAE,QAAQ;CAGxC;AAED,sBAAsB;AACtB,qBAAa,EAAG,SAAQ,gBAAgB;IAI3B,SAAS,CAAC,QAAQ,EAAE,QAAQ;IAHxC,MAAM,EAAG,MAAM,CAAC;IAChB,MAAM,EAAG,MAAM,CAAC;gBAEM,QAAQ,EAAE,QAAQ;IAQxC,iCAAiC;IACjC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB;;;;;OAKG;IACG,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,SAAS,GAAG;QAAC,MAAM,CAAC,EAAE,SAAS,CAAA;KAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA2B5F;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAKtB;;;OAGG;IACH,OAAO,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAO/B;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC;QAAC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;KAAC,CAAC;CAG1C"}
package/dist/data.d.ts CHANGED
@@ -1,12 +1,22 @@
1
1
  import { Unsubscribe } from '@ztimson/utils';
2
2
  import { Meta, PathEventEmitter } from './core';
3
3
  import { Momentum } from './momentum';
4
+ /** Comparison operators for filters */
5
+ export type FilterOperator = '=' | '!=' | '>' | '>=' | '<' | '<=' | 'in' | 'nin' | 'regex' | 'exists';
6
+ /** Filter value - primitive for equality or [operator, value] for comparison */
7
+ export type FilterValue<T = any> = T | [FilterOperator, T];
8
+ /** Filter object with comparison support */
9
+ export type Filter<T = any> = {
10
+ [K in keyof T]?: FilterValue<T[K]>;
11
+ } & {
12
+ [key: string]: FilterValue;
13
+ };
4
14
  /** Generic MongoDB document */
5
15
  export type Document<T> = Meta & T;
6
16
  /** Raw MongoDB query */
7
17
  export type RawQuery = {
8
18
  /** Query operation type */
9
- operand: 'delete' | 'deleteOne' | 'find' | 'findOne' | 'insertOne' | 'replaceOne' | 'update' | 'updateOne';
19
+ operand: 'deleteMany' | 'deleteOne' | 'findMany' | 'findOne' | 'insertMany' | 'insertOne' | 'replaceMany' | 'replaceOne' | 'updateMany' | 'updateOne';
10
20
  /** Filter affected documents */
11
21
  filter?: any;
12
22
  /** Query */
@@ -36,7 +46,8 @@ export declare class Data extends PathEventEmitter {
36
46
  * @param {number} id Document ID
37
47
  * @return {Promise<void>} Returns once complete
38
48
  */
39
- delete(collection: string, id: number): Promise<number>;
49
+ delete(collection: string, id: number): Promise<number[]>;
50
+ delete<T>(collection: string, filter: Filter<T>): Promise<number[]>;
40
51
  /**
41
52
  * Read collection/document
42
53
  * @param {string} collection target collection/document
@@ -44,14 +55,18 @@ export declare class Data extends PathEventEmitter {
44
55
  */
45
56
  read<T extends Meta>(collection: string): Promise<T[]>;
46
57
  read<T extends Meta>(collection: string, id: number): Promise<T>;
58
+ read<T extends Meta>(collection: string, filter: Filter<T>): Promise<T[]>;
47
59
  /**
48
60
  * Update document in collection
49
61
  * @param {string} collection Target collection
50
62
  * @param {Document<T>} document Document to update
51
- * @param {boolean} append Append or replace existing document
52
- * @return {Promise<Document<T>>} New saved document
63
+ * @param {object} options Filter and append options
64
+ * @return {Promise<Document<T> | Document<T>[]>} Updated document(s)
53
65
  */
54
- update<T>(collection: string, document: Document<T>, append?: boolean): Promise<Document<T>>;
66
+ update<T>(collection: string, document: Document<T>, options?: {
67
+ filter?: Filter<T>;
68
+ append?: boolean;
69
+ }): Promise<Document<T> | Document<T>[]>;
55
70
  /**
56
71
  * Create raw MongoDB query
57
72
  * @param {string} collection Target collection name
@@ -1 +1 @@
1
- {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../src/data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAClD,OAAO,E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AE,CAAC;IAWnE;;;;OAIG;IACH,IAAI,CAAC,CAAC,SAAS,IAAI,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IACtD,IAAI,CAAC,CAAC,SAAS,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAChE,IAAI,CAAC,CAAC,SAAS,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAkBzE;;;;;;OAMG;IACH,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,GAAE;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAA;KAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;IAiBhJ;;;;;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
@@ -1087,18 +1087,36 @@
1087
1087
  return timestamp;
1088
1088
  }
1089
1089
  function uploadWithProgress(options) {
1090
- return new PromiseProgress((res, rej, prog) => {
1091
- const xhr = new XMLHttpRequest();
1092
- const formData2 = new FormData();
1093
- options.files.forEach((f) => formData2.append("file", f));
1094
- xhr.withCredentials = !!options.withCredentials;
1095
- xhr.upload.addEventListener("progress", (event) => event.lengthComputable ? prog(event.loaded / event.total) : null);
1096
- xhr.addEventListener("loadend", () => res(JSONAttemptParse(xhr.responseText)));
1097
- xhr.addEventListener("error", () => rej(JSONAttemptParse(xhr.responseText)));
1098
- xhr.addEventListener("timeout", () => rej({ error: "Request timed out" }));
1099
- xhr.open("POST", options.url);
1100
- Object.entries(options.headers || {}).forEach(([key, value]) => xhr.setRequestHeader(key, value));
1101
- xhr.send(formData2);
1090
+ if (typeof XMLHttpRequest !== "undefined") {
1091
+ return new PromiseProgress((res, rej, prog) => {
1092
+ const xhr = new XMLHttpRequest();
1093
+ const formData2 = new FormData();
1094
+ options.files.forEach((f) => formData2.append("files", f));
1095
+ xhr.withCredentials = !!options.withCredentials;
1096
+ xhr.upload.addEventListener("progress", (event) => event.lengthComputable ? prog(event.loaded / event.total) : null);
1097
+ xhr.addEventListener("loadend", () => res(JSONAttemptParse(xhr.responseText)));
1098
+ xhr.addEventListener("error", () => rej(JSONAttemptParse(xhr.responseText)));
1099
+ xhr.addEventListener("timeout", () => rej({ error: "Request timed out" }));
1100
+ xhr.open("POST", options.url);
1101
+ Object.entries(options.headers || {}).forEach(([key, value]) => xhr.setRequestHeader(key, value));
1102
+ xhr.send(formData2);
1103
+ });
1104
+ }
1105
+ return new PromiseProgress(async (res, rej) => {
1106
+ try {
1107
+ const formData2 = new FormData();
1108
+ options.files.forEach((f) => formData2.append("files", f));
1109
+ const response = await fetch(options.url, { method: "POST", headers: options.headers || {}, body: formData2 });
1110
+ if (!response.ok) {
1111
+ const error = await response.text();
1112
+ rej(JSONAttemptParse(error));
1113
+ } else {
1114
+ const result = await response.text();
1115
+ res(JSONAttemptParse(result));
1116
+ }
1117
+ } catch (error) {
1118
+ rej(error);
1119
+ }
1102
1120
  });
1103
1121
  }
1104
1122
  class HttpResponse extends Response {
@@ -1251,8 +1269,10 @@
1251
1269
  methods;
1252
1270
  /** Whether this path contains glob patterns */
1253
1271
  hasGlob;
1254
- /** Internal cache for PathEvent instances to avoid redundant parsing */
1272
+ /** Internal cache for parsed path data (plain objects, not instances) */
1255
1273
  static pathEventCache = /* @__PURE__ */ new Map();
1274
+ /** Max size for path cache before LRU eviction */
1275
+ static MAX_PATH_CACHE_SIZE = 1e3;
1256
1276
  /** Cache for compiled permissions (path + required permissions → result) */
1257
1277
  static permissionCache = /* @__PURE__ */ new Map();
1258
1278
  /** Max size for permission cache before LRU eviction */
@@ -1312,7 +1332,16 @@
1312
1332
  return;
1313
1333
  }
1314
1334
  if (PathEvent.pathEventCache.has(e)) {
1315
- Object.assign(this, PathEvent.pathEventCache.get(e));
1335
+ const cached = PathEvent.pathEventCache.get(e);
1336
+ PathEvent.pathEventCache.delete(e);
1337
+ PathEvent.pathEventCache.set(e, cached);
1338
+ this.module = cached.module;
1339
+ this.fullPath = cached.fullPath;
1340
+ this.dir = cached.dir;
1341
+ this.path = cached.path;
1342
+ this.name = cached.name;
1343
+ this.methods = new ASet(cached.methods);
1344
+ this.hasGlob = cached.hasGlob;
1316
1345
  return;
1317
1346
  }
1318
1347
  let [p, method] = e.replaceAll(/(^|\/)\*+\/?$/g, "").split(":");
@@ -1325,7 +1354,19 @@
1325
1354
  this.name = "";
1326
1355
  this.methods = new ASet(p === "*" ? ["*"] : method.split(""));
1327
1356
  this.hasGlob = true;
1328
- PathEvent.pathEventCache.set(e, this);
1357
+ if (PathEvent.pathEventCache.size >= PathEvent.MAX_PATH_CACHE_SIZE) {
1358
+ const firstKey = PathEvent.pathEventCache.keys().next().value;
1359
+ if (firstKey) PathEvent.pathEventCache.delete(firstKey);
1360
+ }
1361
+ PathEvent.pathEventCache.set(e, {
1362
+ module: this.module,
1363
+ fullPath: this.fullPath,
1364
+ dir: this.dir,
1365
+ path: this.path,
1366
+ name: this.name,
1367
+ methods: [...this.methods],
1368
+ hasGlob: this.hasGlob
1369
+ });
1329
1370
  return;
1330
1371
  }
1331
1372
  let temp = p.split("/").filter((p2) => !!p2);
@@ -1336,7 +1377,19 @@
1336
1377
  this.name = temp.pop() || "";
1337
1378
  this.hasGlob = this.fullPath.includes("*");
1338
1379
  this.methods = new ASet(method.split(""));
1339
- PathEvent.pathEventCache.set(e, this);
1380
+ if (PathEvent.pathEventCache.size >= PathEvent.MAX_PATH_CACHE_SIZE) {
1381
+ const firstKey = PathEvent.pathEventCache.keys().next().value;
1382
+ if (firstKey) PathEvent.pathEventCache.delete(firstKey);
1383
+ }
1384
+ PathEvent.pathEventCache.set(e, {
1385
+ module: this.module,
1386
+ fullPath: this.fullPath,
1387
+ dir: this.dir,
1388
+ path: this.path,
1389
+ name: this.name,
1390
+ methods: [...this.methods],
1391
+ hasGlob: this.hasGlob
1392
+ });
1340
1393
  }
1341
1394
  /**
1342
1395
  * Check if a filter pattern matches a target path
@@ -1830,13 +1883,29 @@
1830
1883
  }
1831
1884
  momentum;
1832
1885
  /**
1833
- * Manually trigger an actions execution
1886
+ * Manually trigger an actions execution with real-time updates
1834
1887
  * @param {string} id Action ID
1888
+ * @param {(payload: ActionUpdate) => any} callback Get updates in real time
1835
1889
  * @param {HttpRequestOptions} opts Additional arguments
1836
- * @return {Promise<ActionResult>} All action output including console logs & return
1890
+ * @return {Promise<string>} Run UID for socket subscription
1891
+ */
1892
+ async debug(id, callback, opts = {}) {
1893
+ const uid = await this.momentum.api.request({ url: `api/actions/debug/${id}`, method: "POST", ...opts }).then((resp) => resp.uid);
1894
+ if (!this.momentum.socket || !callback) return uid;
1895
+ const unsubscribe = this.momentum.socket.on(`actions-debug/${uid}`, (event, payload) => {
1896
+ if (payload.return) unsubscribe();
1897
+ callback(payload);
1898
+ });
1899
+ await this.momentum.socket.subscribe(`actions-debug/${uid}`);
1900
+ return uid;
1901
+ }
1902
+ /**
1903
+ * Terminate a running action
1904
+ * @param {string} id Action ID
1905
+ * @return {Promise<boolean>} Success status
1837
1906
  */
1838
- debug(id, opts = {}) {
1839
- return this.momentum.api.request({ url: `api/actions/debug/${id}`, method: "POST", ...opts });
1907
+ terminate(id) {
1908
+ return this.momentum.api.request({ url: `api/actions/terminate/${id}`, method: "POST" }).then((resp) => resp.success);
1840
1909
  }
1841
1910
  /**
1842
1911
  * Run an HTTP action
@@ -1891,7 +1960,7 @@
1891
1960
  reader.onload = () => res([f.name, reader.result]);
1892
1961
  reader.readAsDataURL(f);
1893
1962
  })))).reduce((acc, f) => ({ ...acc, [f[0]]: f[1] }), {});
1894
- const q = { agent: options?.agent, question: question.trim(), context: options.context, files };
1963
+ const q = { ...options, question: question.trim(), files: Object.keys(files).length ? files : void 0 };
1895
1964
  if (options.stream && this.momentum.socket?.connected) {
1896
1965
  let unsub = () => {
1897
1966
  };
@@ -3141,29 +3210,33 @@ Must be either: call, email or sms`);
3141
3210
  method: "POST",
3142
3211
  body: document2
3143
3212
  }).then((resp) => {
3213
+ if (!resp) return null;
3144
3214
  this.emit(PES`data/${collection}:c`, resp);
3145
3215
  return resp;
3146
3216
  });
3147
3217
  }
3148
- /**
3149
- * Delete document from collection
3150
- * @param {string} collection Target collection
3151
- * @param {number} id Document ID
3152
- * @return {Promise<void>} Returns once complete
3153
- */
3154
- async delete(collection, id) {
3155
- if (!collection || !id) throw new Error("Cannot delete document, missing collection or ID");
3156
- const count = await this.momentum.api.request({
3157
- url: `api/` + PES`data/${collection}/${id}`,
3158
- method: "DELETE"
3159
- });
3160
- if (count) this.emit(PES`data/${collection}/${id}:d`, id);
3161
- return count;
3218
+ async delete(collection, filter) {
3219
+ if (!collection || !filter) throw new Error("Cannot delete document, missing collection or filter");
3220
+ const pk = typeof filter == "object" ? filter?.["_id"] ?? null : filter;
3221
+ const q = typeof filter == "object" ? JSON.stringify(filter) : null;
3222
+ const url = `api/data/${collection}${pk ? `/${pk}` : ""}${q ? `?q=${encodeURIComponent(q)}` : ""}`;
3223
+ const ids = await this.momentum.api.request({ url, method: "DELETE" });
3224
+ ids.forEach((id) => this.emit(PES`data/${collection}/${id}:d`, id));
3225
+ return ids;
3162
3226
  }
3163
- read(collection, id) {
3227
+ read(collection, filter) {
3164
3228
  if (!collection) throw new Error("Cannot read documents, missing collection");
3165
- return this.momentum.api.request({ url: `api/` + PES`data/${collection}/${id}` }).then((resp) => {
3166
- this.emit(PES`data/${collection}/${id}:r`, collection, resp);
3229
+ const pk = typeof filter == "object" ? filter?.["_id"] ?? null : filter;
3230
+ const q = typeof filter == "object" ? JSON.stringify(filter) : null;
3231
+ const url = `api/data/${collection}${pk ? `/${pk}` : ""}${q ? `?q=${encodeURIComponent(q)}` : ""}`;
3232
+ return this.momentum.api.request({ url }).then((resp) => {
3233
+ if (!resp) return null;
3234
+ if (Array.isArray(resp)) {
3235
+ if (!q) this.emit(PES`data/${collection}:r`, collection, resp);
3236
+ else resp.forEach((r) => this.emit(PES`data/${collection}/${r._id}:r`, collection, resp));
3237
+ } else {
3238
+ this.emit(PES`data/${collection}/${resp._id}:r`, collection, resp);
3239
+ }
3167
3240
  return resp;
3168
3241
  });
3169
3242
  }
@@ -3171,17 +3244,22 @@ Must be either: call, email or sms`);
3171
3244
  * Update document in collection
3172
3245
  * @param {string} collection Target collection
3173
3246
  * @param {Document<T>} document Document to update
3174
- * @param {boolean} append Append or replace existing document
3175
- * @return {Promise<Document<T>>} New saved document
3247
+ * @param {object} options Filter and append options
3248
+ * @return {Promise<Document<T> | Document<T>[]>} Updated document(s)
3176
3249
  */
3177
- update(collection, document2, append) {
3250
+ update(collection, document2, options = {}) {
3178
3251
  if (!collection || !document2) throw new Error("Cannot update document, missing collection or document");
3252
+ const pk = options.filter ? options.filter?.["_id"] ?? document2._id : document2._id;
3253
+ const q = options.filter && !options.filter?.["_id"] ? JSON.stringify(options.filter) : null;
3254
+ const url = `api/data/${collection}${pk ? `/${pk}` : ""}${q ? `?q=${encodeURIComponent(q)}` : ""}`;
3179
3255
  return this.momentum.api.request({
3180
- url: `api/` + PES`data/${collection}/${document2._id}`,
3181
- method: append ? "PATCH" : "PUT",
3256
+ url,
3257
+ method: options.append === false ? "PUT" : "PATCH",
3182
3258
  body: document2
3183
3259
  }).then((resp) => {
3184
- this.emit(PES`data/${collection}/${document2._id}:u`, resp);
3260
+ if (!resp) return null;
3261
+ if (Array.isArray(resp)) resp.forEach((r) => this.emit(PES`data/${collection}/${r._id}:u`, r));
3262
+ else this.emit(PES`data/${collection}/${resp._id}:u`, resp);
3185
3263
  return resp;
3186
3264
  });
3187
3265
  }
@@ -3216,12 +3294,12 @@ Must be either: call, email or sms`);
3216
3294
  callback(cache.all());
3217
3295
  });
3218
3296
  if (opts.reload == void 0 || opts.reload) this.read(path);
3219
- if (!this.subscribers.length) this.momentum.socket?.subscribe(e);
3297
+ if (!Object.keys(this.subscribers).length) this.momentum.socket?.subscribe(e);
3220
3298
  const key = Object.keys(this.subscribers).length.toString();
3221
3299
  this.subscribers[key] = () => {
3222
3300
  unsubscribe();
3223
3301
  delete this.subscribers[key];
3224
- if (!this.subscribers.length) this.momentum.socket?.unsubscribe(e);
3302
+ if (!Object.keys(this.subscribers).length) this.momentum.socket?.unsubscribe(e);
3225
3303
  };
3226
3304
  return this.subscribers[key];
3227
3305
  }
@@ -4250,7 +4328,7 @@ ${log}`;
4250
4328
  }
4251
4329
  momentum;
4252
4330
  }
4253
- const version = "1.3.1";
4331
+ const version = "1.4.1";
4254
4332
  class WebRtc extends PathEventEmitter {
4255
4333
  constructor(momentum) {
4256
4334
  super("webrtc");
@@ -4371,18 +4449,46 @@ ${log}`;
4371
4449
  this.momentum = momentum;
4372
4450
  }
4373
4451
  momentum;
4452
+ static create = (event) => new PathEvent(event);
4453
+ static combine = PathEvent.combine;
4454
+ static filter = PathEvent.filter;
4455
+ static has = PathEvent.has;
4456
+ static hasFatal = PathEvent.hasFatal;
4457
+ static hasAll = PathEvent.hasAll;
4458
+ static hasAllFatal = PathEvent.hasAllFatal;
4374
4459
  /** Get all permissions */
4375
4460
  all = () => this.momentum.auth.session?.permissions || [];
4461
+ combine(...events) {
4462
+ return PathEvent.combine(...events);
4463
+ }
4464
+ create(event) {
4465
+ return new PathEvent(event);
4466
+ }
4376
4467
  /** Filter list of permissions to ones the user has */
4377
- filter = (...events) => PathEvent.filter(this.all(), ...events);
4468
+ filter = (...events) => {
4469
+ const check = Array.isArray(events[0]) ? events.shift() : this.all();
4470
+ return PathEvent.filter(check, ...events.flat());
4471
+ };
4378
4472
  /** Does user have any permissions (or) */
4379
- has = (...events) => PathEvent.has(this.all(), ...events);
4473
+ has = (...events) => {
4474
+ const check = Array.isArray(events[0]) ? events.shift() : this.all();
4475
+ return PathEvent.has(check, ...events.flat());
4476
+ };
4380
4477
  /** Does user have all permissions (and) */
4381
- hasAll = (...events) => PathEvent.hasAll(this.all(), ...events);
4478
+ hasAll = (...events) => {
4479
+ const check = Array.isArray(events[0]) ? events.shift() : this.all();
4480
+ return PathEvent.hasAll(check, ...events.flat());
4481
+ };
4382
4482
  /** Raise error if user has no permissions (or) */
4383
- hasFatal = (...events) => PathEvent.hasFatal(this.all(), ...events);
4483
+ hasFatal = (...events) => {
4484
+ const check = Array.isArray(events[0]) ? events.shift() : this.all();
4485
+ return PathEvent.hasFatal(check, ...events.flat());
4486
+ };
4384
4487
  /** Raise error if user missing any permissions (and) */
4385
- hasAllFatal = (...events) => PathEvent.hasAllFatal(this.all(), ...events);
4488
+ hasAllFatal = (...events) => {
4489
+ const check = Array.isArray(events[0]) ? events.shift() : this.all();
4490
+ return PathEvent.hasAllFatal(check, ...events.flat());
4491
+ };
4386
4492
  }
4387
4493
  class Momentum extends PathEventEmitter {
4388
4494
  static pathEvent = PathEvent;
package/dist/index.mjs CHANGED
@@ -1083,18 +1083,36 @@ function timestampFilename(name, date = /* @__PURE__ */ new Date()) {
1083
1083
  return timestamp;
1084
1084
  }
1085
1085
  function uploadWithProgress(options) {
1086
- return new PromiseProgress((res, rej, prog) => {
1087
- const xhr = new XMLHttpRequest();
1088
- const formData2 = new FormData();
1089
- options.files.forEach((f) => formData2.append("file", f));
1090
- xhr.withCredentials = !!options.withCredentials;
1091
- xhr.upload.addEventListener("progress", (event) => event.lengthComputable ? prog(event.loaded / event.total) : null);
1092
- xhr.addEventListener("loadend", () => res(JSONAttemptParse(xhr.responseText)));
1093
- xhr.addEventListener("error", () => rej(JSONAttemptParse(xhr.responseText)));
1094
- xhr.addEventListener("timeout", () => rej({ error: "Request timed out" }));
1095
- xhr.open("POST", options.url);
1096
- Object.entries(options.headers || {}).forEach(([key, value]) => xhr.setRequestHeader(key, value));
1097
- xhr.send(formData2);
1086
+ if (typeof XMLHttpRequest !== "undefined") {
1087
+ return new PromiseProgress((res, rej, prog) => {
1088
+ const xhr = new XMLHttpRequest();
1089
+ const formData2 = new FormData();
1090
+ options.files.forEach((f) => formData2.append("files", f));
1091
+ xhr.withCredentials = !!options.withCredentials;
1092
+ xhr.upload.addEventListener("progress", (event) => event.lengthComputable ? prog(event.loaded / event.total) : null);
1093
+ xhr.addEventListener("loadend", () => res(JSONAttemptParse(xhr.responseText)));
1094
+ xhr.addEventListener("error", () => rej(JSONAttemptParse(xhr.responseText)));
1095
+ xhr.addEventListener("timeout", () => rej({ error: "Request timed out" }));
1096
+ xhr.open("POST", options.url);
1097
+ Object.entries(options.headers || {}).forEach(([key, value]) => xhr.setRequestHeader(key, value));
1098
+ xhr.send(formData2);
1099
+ });
1100
+ }
1101
+ return new PromiseProgress(async (res, rej) => {
1102
+ try {
1103
+ const formData2 = new FormData();
1104
+ options.files.forEach((f) => formData2.append("files", f));
1105
+ const response = await fetch(options.url, { method: "POST", headers: options.headers || {}, body: formData2 });
1106
+ if (!response.ok) {
1107
+ const error = await response.text();
1108
+ rej(JSONAttemptParse(error));
1109
+ } else {
1110
+ const result = await response.text();
1111
+ res(JSONAttemptParse(result));
1112
+ }
1113
+ } catch (error) {
1114
+ rej(error);
1115
+ }
1098
1116
  });
1099
1117
  }
1100
1118
  class HttpResponse extends Response {
@@ -1247,8 +1265,10 @@ class PathEvent {
1247
1265
  methods;
1248
1266
  /** Whether this path contains glob patterns */
1249
1267
  hasGlob;
1250
- /** Internal cache for PathEvent instances to avoid redundant parsing */
1268
+ /** Internal cache for parsed path data (plain objects, not instances) */
1251
1269
  static pathEventCache = /* @__PURE__ */ new Map();
1270
+ /** Max size for path cache before LRU eviction */
1271
+ static MAX_PATH_CACHE_SIZE = 1e3;
1252
1272
  /** Cache for compiled permissions (path + required permissions → result) */
1253
1273
  static permissionCache = /* @__PURE__ */ new Map();
1254
1274
  /** Max size for permission cache before LRU eviction */
@@ -1308,7 +1328,16 @@ class PathEvent {
1308
1328
  return;
1309
1329
  }
1310
1330
  if (PathEvent.pathEventCache.has(e)) {
1311
- Object.assign(this, PathEvent.pathEventCache.get(e));
1331
+ const cached = PathEvent.pathEventCache.get(e);
1332
+ PathEvent.pathEventCache.delete(e);
1333
+ PathEvent.pathEventCache.set(e, cached);
1334
+ this.module = cached.module;
1335
+ this.fullPath = cached.fullPath;
1336
+ this.dir = cached.dir;
1337
+ this.path = cached.path;
1338
+ this.name = cached.name;
1339
+ this.methods = new ASet(cached.methods);
1340
+ this.hasGlob = cached.hasGlob;
1312
1341
  return;
1313
1342
  }
1314
1343
  let [p, method] = e.replaceAll(/(^|\/)\*+\/?$/g, "").split(":");
@@ -1321,7 +1350,19 @@ class PathEvent {
1321
1350
  this.name = "";
1322
1351
  this.methods = new ASet(p === "*" ? ["*"] : method.split(""));
1323
1352
  this.hasGlob = true;
1324
- PathEvent.pathEventCache.set(e, this);
1353
+ if (PathEvent.pathEventCache.size >= PathEvent.MAX_PATH_CACHE_SIZE) {
1354
+ const firstKey = PathEvent.pathEventCache.keys().next().value;
1355
+ if (firstKey) PathEvent.pathEventCache.delete(firstKey);
1356
+ }
1357
+ PathEvent.pathEventCache.set(e, {
1358
+ module: this.module,
1359
+ fullPath: this.fullPath,
1360
+ dir: this.dir,
1361
+ path: this.path,
1362
+ name: this.name,
1363
+ methods: [...this.methods],
1364
+ hasGlob: this.hasGlob
1365
+ });
1325
1366
  return;
1326
1367
  }
1327
1368
  let temp = p.split("/").filter((p2) => !!p2);
@@ -1332,7 +1373,19 @@ class PathEvent {
1332
1373
  this.name = temp.pop() || "";
1333
1374
  this.hasGlob = this.fullPath.includes("*");
1334
1375
  this.methods = new ASet(method.split(""));
1335
- PathEvent.pathEventCache.set(e, this);
1376
+ if (PathEvent.pathEventCache.size >= PathEvent.MAX_PATH_CACHE_SIZE) {
1377
+ const firstKey = PathEvent.pathEventCache.keys().next().value;
1378
+ if (firstKey) PathEvent.pathEventCache.delete(firstKey);
1379
+ }
1380
+ PathEvent.pathEventCache.set(e, {
1381
+ module: this.module,
1382
+ fullPath: this.fullPath,
1383
+ dir: this.dir,
1384
+ path: this.path,
1385
+ name: this.name,
1386
+ methods: [...this.methods],
1387
+ hasGlob: this.hasGlob
1388
+ });
1336
1389
  }
1337
1390
  /**
1338
1391
  * Check if a filter pattern matches a target path
@@ -1826,13 +1879,29 @@ class Actions extends AssetController {
1826
1879
  }
1827
1880
  momentum;
1828
1881
  /**
1829
- * Manually trigger an actions execution
1882
+ * Manually trigger an actions execution with real-time updates
1830
1883
  * @param {string} id Action ID
1884
+ * @param {(payload: ActionUpdate) => any} callback Get updates in real time
1831
1885
  * @param {HttpRequestOptions} opts Additional arguments
1832
- * @return {Promise<ActionResult>} All action output including console logs & return
1886
+ * @return {Promise<string>} Run UID for socket subscription
1887
+ */
1888
+ async debug(id, callback, opts = {}) {
1889
+ const uid = await this.momentum.api.request({ url: `api/actions/debug/${id}`, method: "POST", ...opts }).then((resp) => resp.uid);
1890
+ if (!this.momentum.socket || !callback) return uid;
1891
+ const unsubscribe = this.momentum.socket.on(`actions-debug/${uid}`, (event, payload) => {
1892
+ if (payload.return) unsubscribe();
1893
+ callback(payload);
1894
+ });
1895
+ await this.momentum.socket.subscribe(`actions-debug/${uid}`);
1896
+ return uid;
1897
+ }
1898
+ /**
1899
+ * Terminate a running action
1900
+ * @param {string} id Action ID
1901
+ * @return {Promise<boolean>} Success status
1833
1902
  */
1834
- debug(id, opts = {}) {
1835
- return this.momentum.api.request({ url: `api/actions/debug/${id}`, method: "POST", ...opts });
1903
+ terminate(id) {
1904
+ return this.momentum.api.request({ url: `api/actions/terminate/${id}`, method: "POST" }).then((resp) => resp.success);
1836
1905
  }
1837
1906
  /**
1838
1907
  * Run an HTTP action
@@ -1887,7 +1956,7 @@ class Ai extends PathEventEmitter {
1887
1956
  reader.onload = () => res([f.name, reader.result]);
1888
1957
  reader.readAsDataURL(f);
1889
1958
  })))).reduce((acc, f) => ({ ...acc, [f[0]]: f[1] }), {});
1890
- const q = { agent: options?.agent, question: question.trim(), context: options.context, files };
1959
+ const q = { ...options, question: question.trim(), files: Object.keys(files).length ? files : void 0 };
1891
1960
  if (options.stream && this.momentum.socket?.connected) {
1892
1961
  let unsub = () => {
1893
1962
  };
@@ -3137,29 +3206,33 @@ class Data extends PathEventEmitter {
3137
3206
  method: "POST",
3138
3207
  body: document2
3139
3208
  }).then((resp) => {
3209
+ if (!resp) return null;
3140
3210
  this.emit(PES`data/${collection}:c`, resp);
3141
3211
  return resp;
3142
3212
  });
3143
3213
  }
3144
- /**
3145
- * Delete document from collection
3146
- * @param {string} collection Target collection
3147
- * @param {number} id Document ID
3148
- * @return {Promise<void>} Returns once complete
3149
- */
3150
- async delete(collection, id) {
3151
- if (!collection || !id) throw new Error("Cannot delete document, missing collection or ID");
3152
- const count = await this.momentum.api.request({
3153
- url: `api/` + PES`data/${collection}/${id}`,
3154
- method: "DELETE"
3155
- });
3156
- if (count) this.emit(PES`data/${collection}/${id}:d`, id);
3157
- return count;
3214
+ async delete(collection, filter) {
3215
+ if (!collection || !filter) throw new Error("Cannot delete document, missing collection or filter");
3216
+ const pk = typeof filter == "object" ? filter?.["_id"] ?? null : filter;
3217
+ const q = typeof filter == "object" ? JSON.stringify(filter) : null;
3218
+ const url = `api/data/${collection}${pk ? `/${pk}` : ""}${q ? `?q=${encodeURIComponent(q)}` : ""}`;
3219
+ const ids = await this.momentum.api.request({ url, method: "DELETE" });
3220
+ ids.forEach((id) => this.emit(PES`data/${collection}/${id}:d`, id));
3221
+ return ids;
3158
3222
  }
3159
- read(collection, id) {
3223
+ read(collection, filter) {
3160
3224
  if (!collection) throw new Error("Cannot read documents, missing collection");
3161
- return this.momentum.api.request({ url: `api/` + PES`data/${collection}/${id}` }).then((resp) => {
3162
- this.emit(PES`data/${collection}/${id}:r`, collection, resp);
3225
+ const pk = typeof filter == "object" ? filter?.["_id"] ?? null : filter;
3226
+ const q = typeof filter == "object" ? JSON.stringify(filter) : null;
3227
+ const url = `api/data/${collection}${pk ? `/${pk}` : ""}${q ? `?q=${encodeURIComponent(q)}` : ""}`;
3228
+ return this.momentum.api.request({ url }).then((resp) => {
3229
+ if (!resp) return null;
3230
+ if (Array.isArray(resp)) {
3231
+ if (!q) this.emit(PES`data/${collection}:r`, collection, resp);
3232
+ else resp.forEach((r) => this.emit(PES`data/${collection}/${r._id}:r`, collection, resp));
3233
+ } else {
3234
+ this.emit(PES`data/${collection}/${resp._id}:r`, collection, resp);
3235
+ }
3163
3236
  return resp;
3164
3237
  });
3165
3238
  }
@@ -3167,17 +3240,22 @@ class Data extends PathEventEmitter {
3167
3240
  * Update document in collection
3168
3241
  * @param {string} collection Target collection
3169
3242
  * @param {Document<T>} document Document to update
3170
- * @param {boolean} append Append or replace existing document
3171
- * @return {Promise<Document<T>>} New saved document
3243
+ * @param {object} options Filter and append options
3244
+ * @return {Promise<Document<T> | Document<T>[]>} Updated document(s)
3172
3245
  */
3173
- update(collection, document2, append) {
3246
+ update(collection, document2, options = {}) {
3174
3247
  if (!collection || !document2) throw new Error("Cannot update document, missing collection or document");
3248
+ const pk = options.filter ? options.filter?.["_id"] ?? document2._id : document2._id;
3249
+ const q = options.filter && !options.filter?.["_id"] ? JSON.stringify(options.filter) : null;
3250
+ const url = `api/data/${collection}${pk ? `/${pk}` : ""}${q ? `?q=${encodeURIComponent(q)}` : ""}`;
3175
3251
  return this.momentum.api.request({
3176
- url: `api/` + PES`data/${collection}/${document2._id}`,
3177
- method: append ? "PATCH" : "PUT",
3252
+ url,
3253
+ method: options.append === false ? "PUT" : "PATCH",
3178
3254
  body: document2
3179
3255
  }).then((resp) => {
3180
- this.emit(PES`data/${collection}/${document2._id}:u`, resp);
3256
+ if (!resp) return null;
3257
+ if (Array.isArray(resp)) resp.forEach((r) => this.emit(PES`data/${collection}/${r._id}:u`, r));
3258
+ else this.emit(PES`data/${collection}/${resp._id}:u`, resp);
3181
3259
  return resp;
3182
3260
  });
3183
3261
  }
@@ -3212,12 +3290,12 @@ class Data extends PathEventEmitter {
3212
3290
  callback(cache.all());
3213
3291
  });
3214
3292
  if (opts.reload == void 0 || opts.reload) this.read(path);
3215
- if (!this.subscribers.length) this.momentum.socket?.subscribe(e);
3293
+ if (!Object.keys(this.subscribers).length) this.momentum.socket?.subscribe(e);
3216
3294
  const key = Object.keys(this.subscribers).length.toString();
3217
3295
  this.subscribers[key] = () => {
3218
3296
  unsubscribe();
3219
3297
  delete this.subscribers[key];
3220
- if (!this.subscribers.length) this.momentum.socket?.unsubscribe(e);
3298
+ if (!Object.keys(this.subscribers).length) this.momentum.socket?.unsubscribe(e);
3221
3299
  };
3222
3300
  return this.subscribers[key];
3223
3301
  }
@@ -4246,7 +4324,7 @@ class Static extends Storage {
4246
4324
  }
4247
4325
  momentum;
4248
4326
  }
4249
- const version = "1.3.1";
4327
+ const version = "1.4.1";
4250
4328
  class WebRtc extends PathEventEmitter {
4251
4329
  constructor(momentum) {
4252
4330
  super("webrtc");
@@ -4367,18 +4445,46 @@ class Permissions {
4367
4445
  this.momentum = momentum;
4368
4446
  }
4369
4447
  momentum;
4448
+ static create = (event) => new PathEvent(event);
4449
+ static combine = PathEvent.combine;
4450
+ static filter = PathEvent.filter;
4451
+ static has = PathEvent.has;
4452
+ static hasFatal = PathEvent.hasFatal;
4453
+ static hasAll = PathEvent.hasAll;
4454
+ static hasAllFatal = PathEvent.hasAllFatal;
4370
4455
  /** Get all permissions */
4371
4456
  all = () => this.momentum.auth.session?.permissions || [];
4457
+ combine(...events) {
4458
+ return PathEvent.combine(...events);
4459
+ }
4460
+ create(event) {
4461
+ return new PathEvent(event);
4462
+ }
4372
4463
  /** Filter list of permissions to ones the user has */
4373
- filter = (...events) => PathEvent.filter(this.all(), ...events);
4464
+ filter = (...events) => {
4465
+ const check = Array.isArray(events[0]) ? events.shift() : this.all();
4466
+ return PathEvent.filter(check, ...events.flat());
4467
+ };
4374
4468
  /** Does user have any permissions (or) */
4375
- has = (...events) => PathEvent.has(this.all(), ...events);
4469
+ has = (...events) => {
4470
+ const check = Array.isArray(events[0]) ? events.shift() : this.all();
4471
+ return PathEvent.has(check, ...events.flat());
4472
+ };
4376
4473
  /** Does user have all permissions (and) */
4377
- hasAll = (...events) => PathEvent.hasAll(this.all(), ...events);
4474
+ hasAll = (...events) => {
4475
+ const check = Array.isArray(events[0]) ? events.shift() : this.all();
4476
+ return PathEvent.hasAll(check, ...events.flat());
4477
+ };
4378
4478
  /** Raise error if user has no permissions (or) */
4379
- hasFatal = (...events) => PathEvent.hasFatal(this.all(), ...events);
4479
+ hasFatal = (...events) => {
4480
+ const check = Array.isArray(events[0]) ? events.shift() : this.all();
4481
+ return PathEvent.hasFatal(check, ...events.flat());
4482
+ };
4380
4483
  /** Raise error if user missing any permissions (and) */
4381
- hasAllFatal = (...events) => PathEvent.hasAllFatal(this.all(), ...events);
4484
+ hasAllFatal = (...events) => {
4485
+ const check = Array.isArray(events[0]) ? events.shift() : this.all();
4486
+ return PathEvent.hasAllFatal(check, ...events.flat());
4487
+ };
4382
4488
  }
4383
4489
  class Momentum extends PathEventEmitter {
4384
4490
  static pathEvent = PathEvent;
@@ -3,17 +3,26 @@ import { Momentum } from './momentum';
3
3
  export declare class Permissions {
4
4
  protected momentum: Momentum;
5
5
  constructor(momentum: Momentum);
6
+ static create: (event: string | PathEvent) => PathEvent;
7
+ static combine: typeof PathEvent.combine;
8
+ static filter: typeof PathEvent.filter;
9
+ static has: typeof PathEvent.has;
10
+ static hasFatal: typeof PathEvent.hasFatal;
11
+ static hasAll: typeof PathEvent.hasAll;
12
+ static hasAllFatal: typeof PathEvent.hasAllFatal;
6
13
  /** Get all permissions */
7
14
  all: () => string[];
15
+ combine(...events: (string | PathEvent)[]): PathEvent;
16
+ create(event: string | PathEvent): PathEvent;
8
17
  /** Filter list of permissions to ones the user has */
9
- filter: (...events: (string | PathEvent)[]) => PathEvent[];
18
+ filter: (...events: (string | PathEvent | string[] | PathEvent[])[]) => PathEvent[];
10
19
  /** Does user have any permissions (or) */
11
- has: (...events: (string | PathEvent)[]) => boolean;
20
+ has: (...events: (string | PathEvent | string[] | PathEvent[])[]) => boolean;
12
21
  /** Does user have all permissions (and) */
13
- hasAll: (...events: (string | PathEvent)[]) => boolean;
22
+ hasAll: (...events: (string | PathEvent | string[] | PathEvent[])[]) => boolean;
14
23
  /** Raise error if user has no permissions (or) */
15
- hasFatal: (...events: (string | PathEvent)[]) => void;
24
+ hasFatal: (...events: (string | PathEvent | string[] | PathEvent[])[]) => void;
16
25
  /** Raise error if user missing any permissions (and) */
17
- hasAllFatal: (...events: (string | PathEvent)[]) => void;
26
+ hasAllFatal: (...events: (string | PathEvent | string[] | PathEvent[])[]) => void;
18
27
  }
19
28
  //# sourceMappingURL=permissions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../src/permissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC,qBAAa,WAAW;IACX,SAAS,CAAC,QAAQ,EAAE,QAAQ;gBAAlB,QAAQ,EAAE,QAAQ;IAExC,0BAA0B;IAC1B,GAAG,QAAO,MAAM,EAAE,CAAkD;IACpE,sDAAsD;IACtD,MAAM,GAAI,GAAG,QAAQ,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,KAAG,SAAS,EAAE,CAA4C;IACrG,0CAA0C;IAC1C,GAAG,GAAI,GAAG,QAAQ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,GAAI,GAAG,QAAQ,CAAC,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,GAAG,SAAS,EAAE,CAAC,EAAE,KAAG,OAAO,CAG1E;IAED,2CAA2C;IAC3C,MAAM,GAAI,GAAG,QAAQ,CAAC,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,GAAG,SAAS,EAAE,CAAC,EAAE,KAAG,OAAO,CAG7E;IAED,kDAAkD;IAClD,QAAQ,GAAI,GAAG,QAAQ,CAAC,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,GAAG,SAAS,EAAE,CAAC,EAAE,KAAG,IAAI,CAG5E;IAED,wDAAwD;IACxD,WAAW,GAAI,GAAG,QAAQ,CAAC,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,GAAG,SAAS,EAAE,CAAC,EAAE,KAAG,IAAI,CAG/E;CACD"}
package/dist/schemas.d.ts CHANGED
@@ -6,6 +6,8 @@ export type Schema = Meta & {
6
6
  path: string;
7
7
  /** Description of data */
8
8
  description: string | null;
9
+ /** Create AI embeddings */
10
+ embed?: boolean;
9
11
  /** Associated form for viewing/editing */
10
12
  form?: string | null;
11
13
  /** Lock collection from changes */
@@ -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,0CAA0C;IAC1C,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,mCAAmC;IACnC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;I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CAAC;IACf,4BAA4B;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gCAAgC;IAChC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,4BAA4B;IAC5B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,mBAAmB;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4BAA4B;IAC5B,WAAW,CAAC,EAAE,CAAC,IAAI,CAAC,iBAAiB,EAAE,aAAa,CAAC,GAAG;QAAC,SAAS,EAAE,MAAM,CAAA;KAAC,CAAC,EAAE,CAAA;CAC9E,CAAA;AAED,qBAAa,OAAQ,SAAQ,mBAAmB,CAAC,MAAM,CAAC;IAC3C,SAAS,CAAC,QAAQ,EAAE,QAAQ;gBAAlB,QAAQ,EAAE,QAAQ;CAGxC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ztimson/momentum",
3
- "version": "1.3.1",
3
+ "version": "1.4.1",
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.29.5"
36
+ "@ztimson/utils": "^0.29.7"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/node": "^22.5.4",