proto.io 0.0.206 → 0.0.208

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.
Files changed (58) hide show
  1. package/dist/adapters/file/aliyun-oss.d.ts +3 -3
  2. package/dist/adapters/file/aliyun-oss.js +2 -2
  3. package/dist/adapters/file/aliyun-oss.js.map +1 -1
  4. package/dist/adapters/file/aliyun-oss.mjs +2 -2
  5. package/dist/adapters/file/aliyun-oss.mjs.map +1 -1
  6. package/dist/adapters/file/database.d.ts +2 -2
  7. package/dist/adapters/file/database.js +3 -3
  8. package/dist/adapters/file/database.js.map +1 -1
  9. package/dist/adapters/file/database.mjs +3 -3
  10. package/dist/adapters/file/database.mjs.map +1 -1
  11. package/dist/adapters/file/filesystem.d.ts +3 -3
  12. package/dist/adapters/file/google-cloud-storage.d.ts +3 -3
  13. package/dist/adapters/storage/progres.d.ts +9 -17
  14. package/dist/adapters/storage/progres.js +24 -101
  15. package/dist/adapters/storage/progres.js.map +1 -1
  16. package/dist/adapters/storage/progres.mjs +24 -101
  17. package/dist/adapters/storage/progres.mjs.map +1 -1
  18. package/dist/client.d.ts +3 -3
  19. package/dist/client.js +2 -2
  20. package/dist/client.mjs +3 -3
  21. package/dist/index.d.ts +3 -3
  22. package/dist/index.js +123 -144
  23. package/dist/index.js.map +1 -1
  24. package/dist/index.mjs +125 -146
  25. package/dist/index.mjs.map +1 -1
  26. package/dist/internals/{base-Be7PFKEC.d.ts → base-wSknxBv7.d.ts} +2 -2
  27. package/dist/internals/base-wSknxBv7.d.ts.map +1 -0
  28. package/dist/internals/{chunk-CEQtSsWb.d.ts → chunk-C_BXf1Er.d.ts} +3 -3
  29. package/dist/internals/chunk-C_BXf1Er.d.ts.map +1 -0
  30. package/dist/internals/{index-DnbbpIaO.d.ts → index-A-hoMfDO.d.ts} +48 -20
  31. package/dist/internals/index-A-hoMfDO.d.ts.map +1 -0
  32. package/dist/internals/{index-CsmAYB_t.js → index-B8TESzd9.js} +1 -2
  33. package/dist/internals/{index-CsmAYB_t.js.map → index-B8TESzd9.js.map} +1 -1
  34. package/dist/internals/{index-CSnRU_KQ.mjs → index-BvwYz4Yp.mjs} +60 -18
  35. package/dist/internals/index-BvwYz4Yp.mjs.map +1 -0
  36. package/dist/internals/{index-CyPxh5dl.js → index-CkAvNaAe.js} +2 -2
  37. package/dist/internals/{index-CyPxh5dl.js.map → index-CkAvNaAe.js.map} +1 -1
  38. package/dist/internals/{index-BFZlY3IO.js → index-DVUiXLfI.js} +60 -18
  39. package/dist/internals/index-DVUiXLfI.js.map +1 -0
  40. package/dist/internals/{index-iRVgw566.mjs → index-DlY33lfO.mjs} +2 -2
  41. package/dist/internals/{index-iRVgw566.mjs.map → index-DlY33lfO.mjs.map} +1 -1
  42. package/dist/internals/{index-DpN9tcbY.mjs → index-al1N-qi7.mjs} +2 -2
  43. package/dist/internals/{index-DpN9tcbY.mjs.map → index-al1N-qi7.mjs.map} +1 -1
  44. package/dist/internals/{index-CURcwPBG.d.ts → index-iqOd-Wdg.d.ts} +2 -2
  45. package/dist/internals/index-iqOd-Wdg.d.ts.map +1 -0
  46. package/dist/internals/{random-D7S1XD7F.js → random-B0V0EnjP.js} +3 -3
  47. package/dist/internals/random-B0V0EnjP.js.map +1 -0
  48. package/dist/internals/{random-BnGB_bVS.mjs → random-ZgzzM5v_.mjs} +3 -3
  49. package/dist/internals/random-ZgzzM5v_.mjs.map +1 -0
  50. package/package.json +1 -1
  51. package/dist/internals/base-Be7PFKEC.d.ts.map +0 -1
  52. package/dist/internals/chunk-CEQtSsWb.d.ts.map +0 -1
  53. package/dist/internals/index-BFZlY3IO.js.map +0 -1
  54. package/dist/internals/index-CSnRU_KQ.mjs.map +0 -1
  55. package/dist/internals/index-CURcwPBG.d.ts.map +0 -1
  56. package/dist/internals/index-DnbbpIaO.d.ts.map +0 -1
  57. package/dist/internals/random-BnGB_bVS.mjs.map +0 -1
  58. package/dist/internals/random-D7S1XD7F.js.map +0 -1
package/dist/client.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { P as ProtoClient } from './internals/index-CURcwPBG.js';
2
- export { c as classExtends, e as isFile, f as isJob, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-CURcwPBG.js';
1
+ import { P as ProtoClient } from './internals/index-iqOd-Wdg.js';
2
+ export { c as classExtends, e as isFile, f as isJob, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-iqOd-Wdg.js';
3
3
  export { Decimal } from 'decimal.js';
4
- export { D as DeserializeOptions, S as SerializeOptions, e as TNumber, f as TSerializable, g as deserialize, s as serialize } from './internals/index-DnbbpIaO.js';
4
+ export { D as DeserializeOptions, S as SerializeOptions, e as TNumber, f as TSerializable, g as deserialize, s as serialize } from './internals/index-A-hoMfDO.js';
5
5
  import '@o2ter/utils-js';
6
6
  import 'socket.io-client';
7
7
  import '@socket.io/component-emitter';
package/dist/client.js CHANGED
@@ -2,12 +2,12 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./internals/index-BFZlY3IO.js');
5
+ var index = require('./internals/index-DVUiXLfI.js');
6
6
  var Decimal = require('decimal.js');
7
7
  require('@o2ter/utils-js');
8
8
  require('./internals/private-Ciddhure.js');
9
9
  require('lodash');
10
- require('./internals/index-CsmAYB_t.js');
10
+ require('./internals/index-B8TESzd9.js');
11
11
  require('axios');
12
12
  require('@o2ter/server-js/dist/const');
13
13
  require('socket.io-client');
package/dist/client.mjs CHANGED
@@ -1,10 +1,10 @@
1
- import { e as ProtoClient } from './internals/index-CSnRU_KQ.mjs';
2
- export { f as classExtends, d as deserialize, k as isFile, l as isJob, g as isObject, i as isQuery, j as isRole, h as isUser, s as serialize } from './internals/index-CSnRU_KQ.mjs';
1
+ import { e as ProtoClient } from './internals/index-BvwYz4Yp.mjs';
2
+ export { f as classExtends, d as deserialize, k as isFile, l as isJob, g as isObject, i as isQuery, j as isRole, h as isUser, s as serialize } from './internals/index-BvwYz4Yp.mjs';
3
3
  export { Decimal } from 'decimal.js';
4
4
  import '@o2ter/utils-js';
5
5
  import './internals/private-CNw40LZ7.mjs';
6
6
  import 'lodash';
7
- import './internals/index-DpN9tcbY.mjs';
7
+ import './internals/index-al1N-qi7.mjs';
8
8
  import 'axios';
9
9
  import '@o2ter/server-js/dist/const';
10
10
  import 'socket.io-client';
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import * as socket_io from 'socket.io';
2
2
  import { Router } from 'express';
3
3
  import { Server } from '@o2ter/server-js';
4
- import { T as TSchema, a as TValueWithoutObject, P as ProtoService, b as ProtoServiceOptions, c as ProtoServiceKeyOptions } from './internals/index-DnbbpIaO.js';
5
- export { D as DeserializeOptions, S as SerializeOptions, d as TFileStorage, e as TNumber, f as TSerializable, g as deserialize, s as serialize } from './internals/index-DnbbpIaO.js';
4
+ import { T as TSchema, a as TValueWithoutObject, P as ProtoService, b as ProtoServiceOptions, c as ProtoServiceKeyOptions } from './internals/index-A-hoMfDO.js';
5
+ export { D as DeserializeOptions, S as SerializeOptions, d as TFileStorage, e as TNumber, f as TSerializable, g as deserialize, s as serialize } from './internals/index-A-hoMfDO.js';
6
6
  import Decimal from 'decimal.js';
7
7
  export { Decimal } from 'decimal.js';
8
- export { P as ProtoClient, c as classExtends, e as isFile, f as isJob, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-CURcwPBG.js';
8
+ export { P as ProtoClient, c as classExtends, e as isFile, f as isJob, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-iqOd-Wdg.js';
9
9
  import '@o2ter/utils-js';
10
10
  import 'jsonwebtoken';
11
11
  import 'lodash';
package/dist/index.js CHANGED
@@ -4,11 +4,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _ = require('lodash');
6
6
  var serverJs = require('@o2ter/server-js');
7
- var random = require('./internals/random-D7S1XD7F.js');
7
+ var random = require('./internals/random-B0V0EnjP.js');
8
8
  var _private = require('./internals/private-Ciddhure.js');
9
9
  var utilsJs = require('@o2ter/utils-js');
10
- var index = require('./internals/index-BFZlY3IO.js');
11
- var index$1 = require('./internals/index-CsmAYB_t.js');
10
+ var index = require('./internals/index-DVUiXLfI.js');
11
+ var index$1 = require('./internals/index-B8TESzd9.js');
12
12
  var jwt = require('jsonwebtoken');
13
13
  var node_buffer = require('node:buffer');
14
14
  var node_stream = require('node:stream');
@@ -16,7 +16,7 @@ var node_crypto = require('node:crypto');
16
16
  var util = require('util');
17
17
  var cryptoJs = require('@o2ter/crypto-js');
18
18
  var Decimal = require('decimal.js');
19
- var index$2 = require('./internals/index-CyPxh5dl.js');
19
+ var index$2 = require('./internals/index-CkAvNaAe.js');
20
20
  var queryType = require('query-types');
21
21
  var busboy = require('busboy');
22
22
  require('axios');
@@ -88,6 +88,7 @@ const dispatcher = (proto, options) => {
88
88
  master: options.master ?? false,
89
89
  disableSecurity: options.disableSecurity,
90
90
  });
91
+ const createFile = options.createFile;
91
92
  return {
92
93
  async explain(query) {
93
94
  random.QueryValidator.recursiveCheck(query);
@@ -134,35 +135,9 @@ const dispatcher = (proto, options) => {
134
135
  throw Error('No permission');
135
136
  return proto.storage.random(decoded, opts);
136
137
  },
137
- async insert(options, attrs) {
138
- random.QueryValidator.recursiveCheck(attrs);
139
- const _validator = await validator();
140
- _validator.validateCountMatches(options.className, options.countMatches ?? []);
141
- const _includes = _validator.decodeIncludes(options.className, options.includes ?? ['*']);
142
- const _matches = _validator.decodeMatches(options.className, options.matches ?? {}, _includes);
143
- if (!_validator.validateCLPs(options.className, 'create'))
144
- throw Error('No permission');
145
- const _attrs = normalize(_validator.validateFields(options.className, attrs, 'create', random.QueryValidator.patterns.path));
146
- while (true) {
147
- try {
148
- return await proto.storage.atomic((storage) => storage.insert({
149
- className: options.className,
150
- includes: _includes,
151
- matches: _matches,
152
- countMatches: options.countMatches ?? [],
153
- objectIdSize: proto[_private.PVK].options.objectIdSize
154
- }, _attrs), { lockTable: options.className, retry: true });
155
- }
156
- catch (e) {
157
- if (proto.storage.isDuplicateIdError(e))
158
- continue;
159
- throw e;
160
- }
161
- }
162
- },
163
- async insertMany(options, values) {
164
- if (options.className === 'File')
165
- throw Error('File is not support insertMany');
138
+ async insert(options, values) {
139
+ if (!createFile && options.className === 'File')
140
+ throw Error('File is not support insert');
166
141
  random.QueryValidator.recursiveCheck(values);
167
142
  const _validator = await validator();
168
143
  _validator.validateCountMatches(options.className, options.countMatches ?? []);
@@ -173,7 +148,7 @@ const dispatcher = (proto, options) => {
173
148
  const _attrs = normalize(_.map(values, attr => _validator.validateFields(options.className, attr, 'create', random.QueryValidator.patterns.path)));
174
149
  while (true) {
175
150
  try {
176
- return await proto.storage.atomic((storage) => storage.insertMany({
151
+ return await proto.storage.atomic((storage) => storage.insert({
177
152
  className: options.className,
178
153
  includes: _includes,
179
154
  matches: _matches,
@@ -188,44 +163,16 @@ const dispatcher = (proto, options) => {
188
163
  }
189
164
  }
190
165
  },
191
- async updateOne(query, update) {
192
- random.QueryValidator.recursiveCheck(query, update);
193
- const _validator = await validator();
194
- if (!_validator.validateCLPs(query.className, 'update'))
195
- throw Error('No permission');
196
- return proto.storage.atomic((storage) => storage.updateOne(_validator.decodeQuery(normalize(query), 'update'), normalize(_validator.validateFields(query.className, update, 'update', random.QueryValidator.patterns.path))));
197
- },
198
- async updateMany(query, update) {
166
+ async update(query, update) {
199
167
  random.QueryValidator.recursiveCheck(query, update);
200
168
  const _validator = await validator();
201
169
  if (!_validator.validateCLPs(query.className, 'update'))
202
170
  throw Error('No permission');
203
- return proto.storage.atomic((storage) => storage.updateMany(_validator.decodeQuery(normalize(query), 'update'), normalize(_validator.validateFields(query.className, update, 'update', random.QueryValidator.patterns.path))));
204
- },
205
- async upsertOne(query, update, setOnInsert) {
206
- if (query.className === 'File')
207
- throw Error('File is not support upsertOne');
208
- random.QueryValidator.recursiveCheck(query, update, setOnInsert);
209
- const _validator = await validator();
210
- if (!_validator.validateCLPs(query.className, 'create', 'update'))
211
- throw Error('No permission');
212
- const _query = _validator.decodeQuery(normalize(query), 'update');
213
- const _update = normalize(_validator.validateFields(query.className, update, 'update', random.QueryValidator.patterns.path));
214
- const _setOnInsert = normalize(_validator.validateFields(query.className, setOnInsert, 'create', random.QueryValidator.patterns.path));
215
- while (true) {
216
- try {
217
- return await proto.storage.atomic((storage) => storage.upsertOne(_query, _update, _setOnInsert), { lockTable: query.className, retry: true });
218
- }
219
- catch (e) {
220
- if (proto.storage.isDuplicateIdError(e))
221
- continue;
222
- throw e;
223
- }
224
- }
171
+ return proto.storage.atomic((storage) => storage.update(_validator.decodeQuery(normalize(query), 'update'), normalize(_validator.validateFields(query.className, update, 'update', random.QueryValidator.patterns.path))));
225
172
  },
226
- async upsertMany(query, update, setOnInsert) {
173
+ async upsert(query, update, setOnInsert) {
227
174
  if (query.className === 'File')
228
- throw Error('File is not support upsertOne');
175
+ throw Error('File is not support upsert');
229
176
  random.QueryValidator.recursiveCheck(query, update, setOnInsert);
230
177
  const _validator = await validator();
231
178
  if (!_validator.validateCLPs(query.className, 'create', 'update'))
@@ -235,7 +182,7 @@ const dispatcher = (proto, options) => {
235
182
  const _setOnInsert = normalize(_validator.validateFields(query.className, setOnInsert, 'create', random.QueryValidator.patterns.path));
236
183
  while (true) {
237
184
  try {
238
- return await proto.storage.atomic((storage) => storage.upsertMany(_query, _update, _setOnInsert), { lockTable: query.className, retry: true });
185
+ return await proto.storage.atomic((storage) => storage.upsert(_query, _update, _setOnInsert), { lockTable: query.className, retry: true });
239
186
  }
240
187
  catch (e) {
241
188
  if (proto.storage.isDuplicateIdError(e))
@@ -244,23 +191,52 @@ const dispatcher = (proto, options) => {
244
191
  }
245
192
  }
246
193
  },
247
- async deleteOne(query) {
248
- random.QueryValidator.recursiveCheck(query);
249
- const _validator = await validator();
250
- if (!_validator.validateCLPs(query.className, 'delete'))
251
- throw Error('No permission');
252
- return proto.storage.atomic((storage) => storage.deleteOne(_validator.decodeQuery(normalize(query), 'update')));
253
- },
254
- async deleteMany(query) {
194
+ async delete(query) {
255
195
  random.QueryValidator.recursiveCheck(query);
256
196
  const _validator = await validator();
257
197
  if (!_validator.validateCLPs(query.className, 'delete'))
258
198
  throw Error('No permission');
259
- return proto.storage.atomic((storage) => storage.deleteMany(_validator.decodeQuery(normalize(query), 'update')));
199
+ return proto.storage.atomic((storage) => storage.delete(_validator.decodeQuery(normalize(query), 'update')));
260
200
  },
261
201
  };
262
202
  };
263
203
 
204
+ //
205
+ // proxy.ts
206
+ //
207
+ // The MIT License
208
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
209
+ //
210
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
211
+ // of this software and associated documentation files (the "Software"), to deal
212
+ // in the Software without restriction, including without limitation the rights
213
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
214
+ // copies of the Software, and to permit persons to whom the Software is
215
+ // furnished to do so, subject to the following conditions:
216
+ //
217
+ // The above copyright notice and this permission notice shall be included in
218
+ // all copies or substantial portions of the Software.
219
+ //
220
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
221
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
222
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
223
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
224
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
225
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
226
+ // THE SOFTWARE.
227
+ //
228
+ const proxy = (x) => {
229
+ const self = x;
230
+ const proxy = _.create(self);
231
+ for (const name of _.uniq(_.flatMap(utilsJs.prototypes(proxy), x => Object.getOwnPropertyNames(x)))) {
232
+ if (name === 'constructor')
233
+ continue;
234
+ const value = _.isFunction(self[name]) ? self[name].bind(self) : self[name];
235
+ Object.defineProperty(proxy, name, { get: () => value });
236
+ }
237
+ return proxy;
238
+ };
239
+
264
240
  //
265
241
  // methods.ts
266
242
  //
@@ -311,6 +287,7 @@ class _ProtoQuery extends index.TQuery {
311
287
  return dispatcher(_serviceOf(options) ?? this._proto, {
312
288
  ...options ?? {},
313
289
  disableSecurity: !!this._opts.insecure,
290
+ createFile: !!this._opts.createFile,
314
291
  });
315
292
  }
316
293
  explain(options) {
@@ -346,45 +323,65 @@ class _ProtoQuery extends index.TQuery {
346
323
  yield self._objectMethods(object);
347
324
  });
348
325
  }
349
- async insert(attrs, options) {
350
- const result = this._objectMethods(await this._dispatcher(options).insert({
351
- className: this.className,
352
- includes: this[_private.PVK].options.includes,
353
- matches: this[_private.PVK].options.matches,
354
- countMatches: this[_private.PVK].options.countMatches,
355
- }, attrs));
356
- if (!result)
357
- throw Error('Unable to insert document');
358
- return result;
326
+ _on_upsert(objects) {
327
+ const createTraggers = this._proto[_private.PVK].triggers[this.className]?.create ?? [];
328
+ const updateTraggers = this._proto[_private.PVK].triggers[this.className]?.update ?? [];
329
+ for (const obj of objects) {
330
+ for (const tragger of obj.__v === 0 ? createTraggers : updateTraggers) {
331
+ (async () => {
332
+ try {
333
+ await tragger(proxy(Object.setPrototypeOf({ object: obj }, this._proto)));
334
+ }
335
+ catch (e) {
336
+ console.error(e);
337
+ }
338
+ })();
339
+ }
340
+ }
341
+ }
342
+ _on_delete(objects) {
343
+ const traggers = this._proto[_private.PVK].triggers[this.className]?.delete ?? [];
344
+ for (const obj of objects) {
345
+ for (const tragger of traggers) {
346
+ (async () => {
347
+ try {
348
+ await tragger(proxy(Object.setPrototypeOf({ object: obj }, this._proto)));
349
+ }
350
+ catch (e) {
351
+ console.error(e);
352
+ }
353
+ })();
354
+ }
355
+ }
359
356
  }
360
357
  async insertMany(values, options) {
361
- return this._objectMethods(await this._dispatcher(options).insertMany({
358
+ const objs = this._objectMethods(await this._dispatcher(options).insert({
362
359
  className: this.className,
363
360
  includes: this[_private.PVK].options.includes,
364
361
  matches: this[_private.PVK].options.matches,
365
362
  countMatches: this[_private.PVK].options.countMatches,
366
363
  }, values));
367
- }
368
- async updateOne(update, options) {
369
- return this._objectMethods(await this._dispatcher(options).updateOne(this._queryOptions, update));
364
+ if (!options?.silent)
365
+ this._on_upsert(objs);
366
+ return objs;
370
367
  }
371
368
  async updateMany(update, options) {
372
- return this._objectMethods(await this._dispatcher(options).updateMany(this._queryOptions, update));
373
- }
374
- async upsertOne(update, setOnInsert, options) {
375
- const result = this._objectMethods(await this._dispatcher(options).upsertOne(this._queryOptions, update, setOnInsert));
376
- if (!result)
377
- throw Error('Unable to upsert document');
378
- return result;
369
+ const objs = this._objectMethods(await this._dispatcher(options).update(this._queryOptions, update));
370
+ if (!options?.silent)
371
+ this._on_upsert(objs);
372
+ return objs;
379
373
  }
380
374
  async upsertMany(update, setOnInsert, options) {
381
- return this._objectMethods(await this._dispatcher(options).upsertMany(this._queryOptions, update, setOnInsert));
382
- }
383
- async deleteOne(options) {
384
- return this._objectMethods(await this._dispatcher(options).deleteOne(this._queryOptions));
375
+ const objs = this._objectMethods(await this._dispatcher(options).upsert(this._queryOptions, update, setOnInsert));
376
+ if (!options?.silent)
377
+ this._on_upsert(objs);
378
+ return objs;
385
379
  }
386
380
  async deleteMany(options) {
387
- return this._objectMethods(await this._dispatcher(options).deleteMany(this._queryOptions));
381
+ const objs = this._objectMethods(await this._dispatcher(options).delete(this._queryOptions));
382
+ if (!options?.silent)
383
+ this._on_delete(objs);
384
+ return objs;
388
385
  }
389
386
  }
390
387
  class ProtoQuery extends _ProtoQuery {
@@ -639,42 +636,6 @@ const varifyPassword = async (alg, password, options) => {
639
636
  }
640
637
  };
641
638
 
642
- //
643
- // proxy.ts
644
- //
645
- // The MIT License
646
- // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
647
- //
648
- // Permission is hereby granted, free of charge, to any person obtaining a copy
649
- // of this software and associated documentation files (the "Software"), to deal
650
- // in the Software without restriction, including without limitation the rights
651
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
652
- // copies of the Software, and to permit persons to whom the Software is
653
- // furnished to do so, subject to the following conditions:
654
- //
655
- // The above copyright notice and this permission notice shall be included in
656
- // all copies or substantial portions of the Software.
657
- //
658
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
659
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
660
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
661
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
662
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
663
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
664
- // THE SOFTWARE.
665
- //
666
- const proxy = (x) => {
667
- const self = x;
668
- const proxy = _.create(self);
669
- for (const name of _.uniq(_.flatMap(utilsJs.prototypes(proxy), x => Object.getOwnPropertyNames(x)))) {
670
- if (name === 'constructor')
671
- continue;
672
- const value = _.isFunction(self[name]) ? self[name].bind(self) : self[name];
673
- Object.defineProperty(proxy, name, { get: () => value });
674
- }
675
- return proxy;
676
- };
677
-
678
639
  //
679
640
  // internal.ts
680
641
  //
@@ -799,6 +760,7 @@ const mergeSchema = (...schemas) => _.reduce(schemas, (acc, schema) => ({
799
760
  class ProtoInternal {
800
761
  options;
801
762
  functions = {};
763
+ triggers = {};
802
764
  jobs = {};
803
765
  jobRunner = new JobRunner();
804
766
  constructor(options) {
@@ -961,9 +923,8 @@ class ProtoInternal {
961
923
  object.set('size', file.size);
962
924
  if (nonce)
963
925
  object.set('nonce', nonce);
964
- const created = await proto.Query('File')
965
- .includes(...object.keys())
966
- .insert(_.fromPairs([...object._set_entries()]), options);
926
+ const query = new ProtoQuery('File', proto, { createFile: true });
927
+ const created = await query.includes(...object.keys()).insert(_.fromPairs([...object._set_entries()]), options);
967
928
  if (created) {
968
929
  object[_private.PVK].attributes = created.attributes;
969
930
  object[_private.PVK].mutated = {};
@@ -1615,6 +1576,24 @@ class ProtoService extends index.ProtoType {
1615
1576
  define(name, callback, options) {
1616
1577
  this[_private.PVK].functions[name] = options ? { callback, ...options } : callback;
1617
1578
  }
1579
+ afterCreate(className, callback) {
1580
+ if (_.isNil(this[_private.PVK].triggers[className])) {
1581
+ this[_private.PVK].triggers[className] = { create: [], update: [], delete: [] };
1582
+ }
1583
+ this[_private.PVK].triggers[className].create.push(callback);
1584
+ }
1585
+ afterUpdate(className, callback) {
1586
+ if (_.isNil(this[_private.PVK].triggers[className])) {
1587
+ this[_private.PVK].triggers[className] = { create: [], update: [], delete: [] };
1588
+ }
1589
+ this[_private.PVK].triggers[className].update.push(callback);
1590
+ }
1591
+ afterDelete(className, callback) {
1592
+ if (_.isNil(this[_private.PVK].triggers[className])) {
1593
+ this[_private.PVK].triggers[className] = { create: [], update: [], delete: [] };
1594
+ }
1595
+ this[_private.PVK].triggers[className].delete.push(callback);
1596
+ }
1618
1597
  scheduleJob(name, params, options) {
1619
1598
  return this[_private.PVK].scheduleJob(this, name, params, options);
1620
1599
  }
@@ -1679,7 +1658,7 @@ class ProtoService extends index.ProtoType {
1679
1658
  await this.fileStorage.destroy(this, token);
1680
1659
  }
1681
1660
  }
1682
- await this.storage.deleteMany({
1661
+ await this.storage.delete({
1683
1662
  className,
1684
1663
  filter: index$2.QuerySelector.decode({ _expired_at: { $lt: time } }),
1685
1664
  includes: ['_id', '_expired_at'],
@@ -1824,12 +1803,12 @@ const verifyRelatedBy = (relatedBy) => {
1824
1803
  var classesRoute = (router, proto) => {
1825
1804
  const defaultHandler = async (req) => {
1826
1805
  const { name } = req.params;
1827
- const { operation, random, attributes, update, setOnInsert, relatedBy, ...options } = index.deserialize(req.body);
1806
+ const { operation, random, attributes, update, setOnInsert, relatedBy, silent, ...options } = index.deserialize(req.body);
1828
1807
  verifyRelatedBy(relatedBy);
1829
1808
  const payload = proto.connect(req);
1830
1809
  const query = relatedBy ? payload.Relation(payload.Object(relatedBy.className, relatedBy.objectId), relatedBy.key) : payload.Query(name);
1831
1810
  query[_private.PVK].options = options;
1832
- const opts = { master: payload.isMaster };
1811
+ const opts = { master: payload.isMaster, silent };
1833
1812
  if (_.includes(['File', '_Job', '_JobScope'], name) &&
1834
1813
  _.includes(['insert', 'insertMany', 'upsertOne', 'upsertMany'], operation))
1835
1814
  throw Error('Invaild operation');