@anteros/core 0.0.8 → 0.0.10

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.
@@ -168,7 +168,7 @@ class MongoRest {
168
168
 
169
169
  const { request: requestMeta, ...restMeta } = ctxMeta ?? {}
170
170
 
171
- const meta: Record<string, any> = {
171
+ const meta: any = {
172
172
  ...restMeta,
173
173
  platform: restMeta?.platform ?? os.platform(),
174
174
  core_version: cfg.version ?? restMeta?.core_version,
@@ -273,17 +273,9 @@ class MongoRest {
273
273
  throw isSafe.error;
274
274
  }
275
275
  pipeline = func.toBson(pipeline, { col })
276
+ const meta: any = { action, collection, pipeline }
276
277
  if (col.hooks?.beforeOperation) {
277
- await col.hooks.beforeOperation({
278
- rest: this,
279
- io,
280
- action: action,
281
- meta: {
282
- action,
283
- collection: collection,
284
- pipeline: pipeline,
285
- }
286
- })
278
+ await col.hooks.beforeOperation({ rest: this, io, action, meta })
287
279
  }
288
280
 
289
281
  let result = await this.db.collection(collection).aggregate(pipeline, {
@@ -291,18 +283,9 @@ class MongoRest {
291
283
  allowDiskUse: true,
292
284
  }).toArray()
293
285
  result = func.toJson(result)
286
+ meta.result = result
294
287
 
295
- await col.hooks?.afterOperation?.({
296
- rest: this,
297
- io,
298
- action: action,
299
- meta: {
300
- action,
301
- collection: collection,
302
- pipeline: pipeline,
303
- result: result,
304
- }
305
- })
288
+ await col.hooks?.afterOperation?.({ rest: this, io, action, meta })
306
289
 
307
290
  return result as any[]
308
291
  } catch (err: any) {
@@ -320,18 +303,9 @@ class MongoRest {
320
303
  pipeline = await func.buildInput(pipeline, { rest: this })
321
304
  pipeline = func.toBson(pipeline, { col })
322
305
 
306
+ const meta: any = { action, collection, params, options }
323
307
  if (col.hooks?.beforeOperation) {
324
- await col.hooks.beforeOperation({
325
- rest: this,
326
- io,
327
- action: action,
328
- meta: {
329
- action: action,
330
- collection: collection,
331
- params: func.clone(params),
332
- options: func.clone(options),
333
- }
334
- })
308
+ await col.hooks.beforeOperation({ rest: this, io, action, meta })
335
309
  }
336
310
 
337
311
  let result = await this.db.collection(collection).aggregate(pipeline, {
@@ -339,20 +313,10 @@ class MongoRest {
339
313
  allowDiskUse: true
340
314
  }).toArray()
341
315
  result = func.toJson(result)
316
+ meta.result = result
342
317
 
343
318
  if (col.hooks?.afterOperation) {
344
- await col.hooks.afterOperation({
345
- rest: this,
346
- io,
347
- action: action,
348
- meta: {
349
- action: action,
350
- collection: collection,
351
- params: func.clone(params),
352
- options: func.clone(options),
353
- result: func.clone(result),
354
- }
355
- })
319
+ await col.hooks.afterOperation({ rest: this, io, action, meta })
356
320
  }
357
321
 
358
322
  return result as any[]
@@ -374,18 +338,9 @@ class MongoRest {
374
338
  pipeline = await func.buildInput(pipeline, { rest: this })
375
339
  pipeline = func.toBson(pipeline, { col })
376
340
 
341
+ const meta: any = { action, collection, params, id: _id }
377
342
  if (col.hooks?.beforeOperation) {
378
- await col.hooks.beforeOperation({
379
- rest: this,
380
- io,
381
- action: action,
382
- meta: {
383
- action: action,
384
- collection: collection,
385
- params: func.clone(params),
386
- id: _id,
387
- }
388
- })
343
+ await col.hooks.beforeOperation({ rest: this, io, action, meta })
389
344
  }
390
345
 
391
346
  let result = (await this.db.collection(collection).aggregate(pipeline, {
@@ -393,20 +348,10 @@ class MongoRest {
393
348
  allowDiskUse: true
394
349
  }).toArray()).at(0) ?? null
395
350
  result = func.toJson(result)
351
+ meta.result = result
396
352
 
397
353
  if (col.hooks?.afterOperation) {
398
- await col.hooks.afterOperation({
399
- rest: this,
400
- io,
401
- action: action,
402
- meta: {
403
- action: action,
404
- collection: collection,
405
- result: func.clone(result),
406
- params: func.clone(params),
407
- id: _id,
408
- }
409
- })
354
+ await col.hooks.afterOperation({ rest: this, io, action, meta })
410
355
  }
411
356
 
412
357
  return result
@@ -427,17 +372,9 @@ class MongoRest {
427
372
  })
428
373
  this._validate({ collection, action: action, data: data })
429
374
 
375
+ const meta: any = { action, collection, data }
430
376
  if (col.hooks?.beforeOperation) {
431
- await col.hooks.beforeOperation({
432
- rest: this,
433
- io,
434
- action,
435
- meta: {
436
- action,
437
- collection,
438
- data: func.clone(data),
439
- }
440
- })
377
+ await col.hooks.beforeOperation({ rest: this, io, action, meta })
441
378
  }
442
379
 
443
380
  await this.db.collection(collection).insertOne(func.toBson(data, { col }) as any, {
@@ -445,18 +382,9 @@ class MongoRest {
445
382
  })
446
383
 
447
384
  const result: T & { _id: string } = func.toJson(data as T & { _id: string })
385
+ meta.result = result
448
386
  if (col?.hooks?.afterOperation) {
449
- await col.hooks.afterOperation({
450
- rest: this,
451
- io,
452
- action: action,
453
- meta: {
454
- action: action,
455
- collection: collection,
456
- data: func.clone(data),
457
- result: func.clone(result),
458
- }
459
- })
387
+ await col.hooks.afterOperation({ rest: this, io, action, meta })
460
388
  }
461
389
 
462
390
  return result
@@ -482,17 +410,9 @@ class MongoRest {
482
410
 
483
411
  this._validate({ collection, action: action, data: dataInput })
484
412
 
413
+ const meta: any = { action, collection, data: dataInput }
485
414
  if (col.hooks?.beforeOperation) {
486
- await col.hooks.beforeOperation({
487
- rest: this,
488
- io,
489
- action: action,
490
- meta: {
491
- action: action,
492
- collection: collection,
493
- data: func.clone(dataInput),
494
- }
495
- })
415
+ await col.hooks.beforeOperation({ rest: this, io, action, meta })
496
416
  }
497
417
 
498
418
  await this.db.collection(collection).insertMany(func.toBson(dataInput, { col }) as any, {
@@ -500,18 +420,10 @@ class MongoRest {
500
420
  })
501
421
 
502
422
  const result: (T & { _id: string })[] = func.toJson(dataInput as (T & { _id: string })[])
423
+ meta.result = result
503
424
 
504
425
  if (col.hooks?.afterOperation) {
505
- await col.hooks.afterOperation({
506
- rest: this,
507
- io,
508
- action: action,
509
- meta: {
510
- action: action,
511
- collection: collection,
512
- result: func.clone(result),
513
- }
514
- })
426
+ await col.hooks.afterOperation({ rest: this, io, action, meta })
515
427
  }
516
428
 
517
429
  return result as (T & { _id: string })[]
@@ -533,18 +445,9 @@ class MongoRest {
533
445
  this._validate({ collection, action: action, update: update })
534
446
  update = func.toBson(update, { col })
535
447
 
448
+ const meta: any = { action, collection, update, id: _id }
536
449
  if (col.hooks?.beforeOperation) {
537
- await col.hooks.beforeOperation({
538
- rest: this,
539
- io,
540
- action: action,
541
- meta: {
542
- action: action,
543
- update: func.clone(update),
544
- collection: collection,
545
- id: _id,
546
- }
547
- })
450
+ await col.hooks.beforeOperation({ rest: this, io, action, meta })
548
451
  }
549
452
 
550
453
  const data = await this.db.collection(collection).findOneAndUpdate(
@@ -554,20 +457,10 @@ class MongoRest {
554
457
  )
555
458
 
556
459
  const result = func.toJson(data)
460
+ meta.result = result
557
461
 
558
462
  if (col.hooks?.afterOperation) {
559
- await col.hooks.afterOperation({
560
- rest: this,
561
- io,
562
- action: action,
563
- meta: {
564
- action: action,
565
- collection: collection,
566
- update: func.clone(update),
567
- id: _id,
568
- result: func.clone(result),
569
- }
570
- })
463
+ await col.hooks.afterOperation({ rest: this, io, action, meta })
571
464
  }
572
465
 
573
466
  return result
@@ -616,24 +509,11 @@ class MongoRest {
616
509
  update = func.toBson(update, { col })
617
510
  filter = func.toBson(filter, { col })
618
511
 
512
+ const meta: any = { action, collection, filter, update }
619
513
  if (col.hooks?.beforeOperation) {
620
- await col.hooks.beforeOperation({
621
- rest: this,
622
- io,
623
- action: action,
624
- meta: {
625
- action: action,
626
- collection: collection,
627
- filter: func.clone(filter),
628
- update: func.clone(update),
629
- }
630
- })
514
+ await col.hooks.beforeOperation({ rest: this, io, action, meta })
631
515
  }
632
516
 
633
-
634
-
635
-
636
-
637
517
  const data = await this.db.collection(collection).findOneAndUpdate(
638
518
  filter,
639
519
  {
@@ -644,20 +524,10 @@ class MongoRest {
644
524
  )
645
525
 
646
526
  const result = func.toJson(data)
527
+ meta.result = result
647
528
 
648
529
  if (col.hooks?.afterOperation) {
649
- await col.hooks.afterOperation({
650
- rest: this,
651
- io,
652
- action: action,
653
- meta: {
654
- action: action,
655
- collection: collection,
656
- filter: func.clone(filter),
657
- update: func.clone(update),
658
- result: func.clone(result),
659
- }
660
- })
530
+ await col.hooks.afterOperation({ rest: this, io, action, meta })
661
531
  }
662
532
 
663
533
  return result as Document | null
@@ -678,18 +548,9 @@ class MongoRest {
678
548
  this._validate({ collection, action: action, update: update })
679
549
  update = func.toBson(update, { col })
680
550
 
551
+ const meta: any = { action, collection, update, ids: _ids }
681
552
  if (col.hooks?.beforeOperation) {
682
- await col.hooks.beforeOperation({
683
- rest: this,
684
- io,
685
- action: action,
686
- meta: {
687
- action: action,
688
- collection: collection,
689
- update: func.clone(update),
690
- ids: _ids,
691
- }
692
- })
553
+ await col.hooks.beforeOperation({ rest: this, io, action, meta })
693
554
  }
694
555
 
695
556
  const result = await this.db.collection(collection).updateMany(
@@ -697,20 +558,10 @@ class MongoRest {
697
558
  { ...(update as any) },
698
559
  { session: this.session }
699
560
  )
561
+ meta.result = result
700
562
 
701
563
  if (col.hooks?.afterOperation) {
702
- await col.hooks.afterOperation({
703
- rest: this,
704
- io,
705
- action: action,
706
- meta: {
707
- action: action,
708
- collection: collection,
709
- update: func.clone(update),
710
- ids: _ids,
711
- result: func.clone(result),
712
- }
713
- })
564
+ await col.hooks.afterOperation({ rest: this, io, action, meta })
714
565
  }
715
566
 
716
567
  return result as UpdateResult
@@ -724,13 +575,9 @@ class MongoRest {
724
575
  return this.#executeWithAudit(action, collection, { id: _id }, async () => {
725
576
  const col = getCollection(collection, this.#tenant.id) as Collection
726
577
 
578
+ const meta: any = { action, collection, id: _id }
727
579
  if (col.hooks?.beforeOperation) {
728
- await col.hooks.beforeOperation({
729
- rest: this,
730
- io,
731
- action: action,
732
- meta: { action: action, collection: collection, id: _id }
733
- })
580
+ await col.hooks.beforeOperation({ rest: this, io, action, meta })
734
581
  }
735
582
 
736
583
  let result = await this.db.collection(collection).findOneAndDelete(
@@ -738,14 +585,10 @@ class MongoRest {
738
585
  { session: this.session }
739
586
  )
740
587
  result = func.toJson(result)
588
+ meta.result = result
741
589
 
742
590
  if (col.hooks?.afterOperation) {
743
- await col.hooks.afterOperation({
744
- rest: this,
745
- io,
746
- action: action,
747
- meta: { action: action, collection: collection, id: _id, result: func.clone(result) }
748
- })
591
+ await col.hooks.afterOperation({ rest: this, io, action, meta })
749
592
  }
750
593
 
751
594
  return result
@@ -760,13 +603,9 @@ class MongoRest {
760
603
  return this.#executeWithAudit(action, collection, { ids: _ids }, async () => {
761
604
  const col = getCollection(collection, this.#tenant.id) as Collection
762
605
 
606
+ const meta: any = { action, collection, ids: _ids }
763
607
  if (col.hooks?.beforeOperation) {
764
- await col.hooks.beforeOperation({
765
- rest: this,
766
- io,
767
- action: action,
768
- meta: { action: action, collection: collection, ids: _ids }
769
- })
608
+ await col.hooks.beforeOperation({ rest: this, io, action, meta })
770
609
  }
771
610
 
772
611
  let result: DeleteResult = await this.db.collection(collection).deleteMany(
@@ -774,14 +613,10 @@ class MongoRest {
774
613
  { session: this.session }
775
614
  )
776
615
  result = func.toJson(result) as DeleteResult
616
+ meta.result = result
777
617
 
778
618
  if (col.hooks?.afterOperation) {
779
- await col.hooks.afterOperation({
780
- rest: this,
781
- io,
782
- action: action,
783
- meta: { action: action, collection: collection, ids: _ids, result: func.clone(result) }
784
- })
619
+ await col.hooks.afterOperation({ rest: this, io, action, meta })
785
620
  }
786
621
 
787
622
  return result
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@anteros/core",
3
3
  "module": "index.ts",
4
- "version": "0.0.8",
4
+ "version": "0.0.10",
5
5
  "type": "module",
6
6
  "description": "Anteros Core",
7
7
  "private": false,
package/server/api.ts CHANGED
@@ -391,6 +391,7 @@ function initializeApi(app: Hono<{ Variables: HonoVariables }>) {
391
391
  return c.json(response);
392
392
 
393
393
  } catch (err: any) {
394
+ if (cfg?.debug) console.error(err)
394
395
  return errorResponse(c, err);
395
396
  }
396
397
  });
@@ -443,6 +444,7 @@ function initializeApi(app: Hono<{ Variables: HonoVariables }>) {
443
444
  throw err;
444
445
  }
445
446
  } catch (err: any) {
447
+ if (cfg?.debug) console.error(err)
446
448
  return errorResponse(c, err);
447
449
  }
448
450
  });
@@ -483,6 +485,7 @@ function initializeApi(app: Hono<{ Variables: HonoVariables }>) {
483
485
  const result = await handleUpload({ collection, tenant_id, file: fileField, data });
484
486
  return c.json(result);
485
487
  } catch (err: any) {
488
+ if (cfg?.debug) console.error(err)
486
489
  return errorResponse(c, err);
487
490
  }
488
491
  });
@@ -528,6 +531,7 @@ function initializeApi(app: Hono<{ Variables: HonoVariables }>) {
528
531
  c.header('Cache-Control', 'public, max-age=31536000, immutable');
529
532
  return c.newResponse(result.stream);
530
533
  } catch (err: any) {
534
+ if (cfg?.debug) console.error(err)
531
535
  return errorResponse(c, err);
532
536
  }
533
537
  });
@@ -555,6 +559,7 @@ function initializeApi(app: Hono<{ Variables: HonoVariables }>) {
555
559
  await handleDelete(tenant_id, collection, fileId);
556
560
  return c.json({ message: 'File deleted', ok: true });
557
561
  } catch (err: any) {
562
+ if (cfg?.debug) console.error(err)
558
563
  return errorResponse(c, err);
559
564
  }
560
565
  });
package/types/config.d.ts CHANGED
@@ -7,6 +7,7 @@ import type { Service } from "./service";
7
7
  import type { Script } from "./scripts";
8
8
  import type { FileCollection } from "./file";
9
9
  export type ServerConfig = {
10
+ debug?: boolean;
10
11
  version?: string;
11
12
  clusterMode?: boolean;
12
13
  server: {
package/utils/func.ts CHANGED
@@ -608,8 +608,6 @@ function collectDateFieldPathsFromCollection(col: Collection): string[] {
608
608
 
609
609
  function toBson<T>(data: any | any[], _options?: FormatInputOptions): T {
610
610
  let data_ = formatToObjectId(data);
611
- // Toujours convertir toutes les strings date valide en Date,
612
- // quel que soit le contexte (insert, update, match, pipeline).
613
611
  data_ = formatToDate(data_);
614
612
 
615
613
  if (Array.isArray(data)) {