@samet-it/be-db-common 1.0.11 → 1.1.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/repo/index.types.d.ts +77 -26
- package/package.json +2 -2
|
@@ -3,7 +3,7 @@ import type { DbConnectionBase, DbExecOpt } from "../connection";
|
|
|
3
3
|
import type { DefDims, Portion, View } from "@samet-it/be-base-common";
|
|
4
4
|
import type { QueryAny, QueryRegular } from "@leyyo/query";
|
|
5
5
|
import type { CacheConnectionLike, CacheChannelLike } from "@samet-it/be-cache-common";
|
|
6
|
-
import type {
|
|
6
|
+
import type { KeyValue, StrKey } from "@leyyo/common";
|
|
7
7
|
/**
|
|
8
8
|
* Urn delimiter literals (options)
|
|
9
9
|
* */
|
|
@@ -391,7 +391,6 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
|
|
|
391
391
|
*
|
|
392
392
|
* @param {Entity} doc - document object
|
|
393
393
|
* @param {string?} dim - dimension, default: `def`
|
|
394
|
-
* @param {boolean?} ignoreCheck - ignores to check input
|
|
395
394
|
* @return {Promise<IdDocLike>} - dim object
|
|
396
395
|
* @async
|
|
397
396
|
* */
|
|
@@ -501,20 +500,22 @@ export interface DbRepoOpt<ID extends KeyValue, ENTITY extends Entity<ID>> {
|
|
|
501
500
|
/**
|
|
502
501
|
* Model version
|
|
503
502
|
*
|
|
504
|
-
* @default
|
|
505
|
-
* @type {
|
|
503
|
+
* @default 1
|
|
504
|
+
* @type {number}
|
|
506
505
|
* */
|
|
507
506
|
version?: number;
|
|
508
507
|
/**
|
|
509
508
|
* Urn delimiter
|
|
510
509
|
*
|
|
511
|
-
* @default
|
|
510
|
+
* @default ","
|
|
512
511
|
* @type {UrnDelimiter}
|
|
513
512
|
* */
|
|
514
513
|
urnDelimiter?: UrnDelimiter;
|
|
515
514
|
/**
|
|
516
515
|
* Urn prefix, like domain:subdomain
|
|
517
516
|
*
|
|
517
|
+
* @example domain:subdomain
|
|
518
|
+
*
|
|
518
519
|
* @type {string}
|
|
519
520
|
* */
|
|
520
521
|
urnPrefix?: string;
|
|
@@ -522,7 +523,8 @@ export interface DbRepoOpt<ID extends KeyValue, ENTITY extends Entity<ID>> {
|
|
|
522
523
|
* Id format, number or string
|
|
523
524
|
* - if yes, it evaluates as integer
|
|
524
525
|
* - if no, it evaluates as string, uuid etc
|
|
525
|
-
*
|
|
526
|
+
*
|
|
527
|
+
* @default false
|
|
526
528
|
* */
|
|
527
529
|
useNumericId?: boolean;
|
|
528
530
|
/**
|
|
@@ -531,7 +533,7 @@ export interface DbRepoOpt<ID extends KeyValue, ENTITY extends Entity<ID>> {
|
|
|
531
533
|
* - if no, it generates number - timestamp
|
|
532
534
|
*
|
|
533
535
|
* @fields `createdAt`, `updatedAt`
|
|
534
|
-
* @default
|
|
536
|
+
* @default false
|
|
535
537
|
* */
|
|
536
538
|
useIsoDate?: boolean;
|
|
537
539
|
/**
|
|
@@ -539,8 +541,8 @@ export interface DbRepoOpt<ID extends KeyValue, ENTITY extends Entity<ID>> {
|
|
|
539
541
|
* - if yes, id is same with urn
|
|
540
542
|
* - if no, id is not same with urn
|
|
541
543
|
*
|
|
542
|
-
* @fields `_urn`
|
|
543
|
-
* @default
|
|
544
|
+
* @fields `_urn`, `id`
|
|
545
|
+
* @default false
|
|
544
546
|
* */
|
|
545
547
|
idSame?: boolean;
|
|
546
548
|
/**
|
|
@@ -549,7 +551,7 @@ export interface DbRepoOpt<ID extends KeyValue, ENTITY extends Entity<ID>> {
|
|
|
549
551
|
* - if no, it validates trash case
|
|
550
552
|
*
|
|
551
553
|
* @fields `_trashId`
|
|
552
|
-
* @default
|
|
554
|
+
* @default false
|
|
553
555
|
* */
|
|
554
556
|
useSoftDelete?: boolean;
|
|
555
557
|
/**
|
|
@@ -558,7 +560,7 @@ export interface DbRepoOpt<ID extends KeyValue, ENTITY extends Entity<ID>> {
|
|
|
558
560
|
* - if no, it ignores `createdAt`
|
|
559
561
|
*
|
|
560
562
|
* @fields `createdAt`
|
|
561
|
-
* @default
|
|
563
|
+
* @default false
|
|
562
564
|
* */
|
|
563
565
|
useCreatedAt?: boolean;
|
|
564
566
|
/**
|
|
@@ -567,7 +569,7 @@ export interface DbRepoOpt<ID extends KeyValue, ENTITY extends Entity<ID>> {
|
|
|
567
569
|
* - if no, it ignores `createdBy`
|
|
568
570
|
*
|
|
569
571
|
* @fields `createdBy`
|
|
570
|
-
* @default
|
|
572
|
+
* @default false
|
|
571
573
|
* */
|
|
572
574
|
useCreatedBy?: boolean;
|
|
573
575
|
/**
|
|
@@ -576,7 +578,7 @@ export interface DbRepoOpt<ID extends KeyValue, ENTITY extends Entity<ID>> {
|
|
|
576
578
|
* - if no, it builds updatedAt
|
|
577
579
|
*
|
|
578
580
|
* @fields `updatedAt`
|
|
579
|
-
* @default
|
|
581
|
+
* @default false
|
|
580
582
|
* */
|
|
581
583
|
useUpdatedAt?: boolean;
|
|
582
584
|
/**
|
|
@@ -585,7 +587,7 @@ export interface DbRepoOpt<ID extends KeyValue, ENTITY extends Entity<ID>> {
|
|
|
585
587
|
* - if no, it ignores `updatedBy`
|
|
586
588
|
*
|
|
587
589
|
* @fields `updatedBy`
|
|
588
|
-
* @default
|
|
590
|
+
* @default false
|
|
589
591
|
* */
|
|
590
592
|
useUpdatedBy?: boolean;
|
|
591
593
|
/**
|
|
@@ -594,7 +596,7 @@ export interface DbRepoOpt<ID extends KeyValue, ENTITY extends Entity<ID>> {
|
|
|
594
596
|
* - if no, it ignores `_ver`
|
|
595
597
|
*
|
|
596
598
|
* @fields `_ver`
|
|
597
|
-
* @default
|
|
599
|
+
* @default false
|
|
598
600
|
* */
|
|
599
601
|
useVersion?: boolean;
|
|
600
602
|
/**
|
|
@@ -603,7 +605,7 @@ export interface DbRepoOpt<ID extends KeyValue, ENTITY extends Entity<ID>> {
|
|
|
603
605
|
* - if no, it ignores `_rev`
|
|
604
606
|
*
|
|
605
607
|
* @fields `_rev`
|
|
606
|
-
* @default
|
|
608
|
+
* @default false
|
|
607
609
|
* */
|
|
608
610
|
useRevision?: boolean;
|
|
609
611
|
/**
|
|
@@ -612,27 +614,33 @@ export interface DbRepoOpt<ID extends KeyValue, ENTITY extends Entity<ID>> {
|
|
|
612
614
|
* - if no, it ignores `_alpha`
|
|
613
615
|
*
|
|
614
616
|
* @fields `_alpha`
|
|
615
|
-
*
|
|
617
|
+
*
|
|
618
|
+
* @param {Entity} doc
|
|
619
|
+
* @async
|
|
616
620
|
* */
|
|
617
|
-
alphaFn?:
|
|
621
|
+
alphaFn?: DbRepoExtensionLambda<ID, ENTITY>;
|
|
618
622
|
/**
|
|
619
623
|
* Manages `search` case, to power search
|
|
620
624
|
* - if yes, it builds `_search`
|
|
621
625
|
* - if no, it ignores `_search`
|
|
622
626
|
*
|
|
623
|
-
* @fields `
|
|
624
|
-
*
|
|
627
|
+
* @fields `_search`
|
|
628
|
+
*
|
|
629
|
+
* @param {Entity} doc
|
|
630
|
+
* @async
|
|
625
631
|
* */
|
|
626
|
-
searchFn?:
|
|
632
|
+
searchFn?: DbRepoExtensionLambda<ID, ENTITY>;
|
|
627
633
|
/**
|
|
628
634
|
* Manages `irregular` case, to store irregular field which is not in model
|
|
629
635
|
* - if yes, it builds `_irregular`
|
|
630
636
|
* - if no, it ignores `_irregular`
|
|
631
637
|
*
|
|
632
638
|
* @fields `_irregular`
|
|
633
|
-
*
|
|
639
|
+
*
|
|
640
|
+
* @param {Entity} doc
|
|
641
|
+
* @async
|
|
634
642
|
* */
|
|
635
|
-
irregularFn?:
|
|
643
|
+
irregularFn?: DbRepoExtensionLambda<ID, ENTITY>;
|
|
636
644
|
/**
|
|
637
645
|
* Field list which can not be set (update/replace)
|
|
638
646
|
*
|
|
@@ -683,19 +691,62 @@ export interface DbCheckKeysResult<ID extends KeyValue> {
|
|
|
683
691
|
urns: Array<string>;
|
|
684
692
|
ordered: Array<DbCheckKeysTuple<ID>>;
|
|
685
693
|
}
|
|
694
|
+
/**
|
|
695
|
+
* Response model during key is being checked
|
|
696
|
+
* @tuple
|
|
697
|
+
*
|
|
698
|
+
* Options
|
|
699
|
+
* - if primary(urn) => `[value (string), '_urn'];
|
|
700
|
+
* - if secondary(id) => `[value (string|number), 'id'];
|
|
701
|
+
* */
|
|
686
702
|
export type DbCheckKeysTuple<ID extends KeyValue> = [string, '_urn'] | [ID, 'id'];
|
|
687
703
|
/**
|
|
688
704
|
* DB `$toUrnTuple` lambda
|
|
689
|
-
*
|
|
705
|
+
*
|
|
706
|
+
* @see {@link DbRepoLike#$toUrnTuple}
|
|
707
|
+
* @method
|
|
708
|
+
*
|
|
709
|
+
* @param {UrnDocLike} urnRec - an object which will be a source to generate an urn
|
|
710
|
+
* @return {UrnTuple} - tuple
|
|
690
711
|
* */
|
|
691
712
|
export type DbRepoToUrnTuple<URN extends UrnDocLike = UrnDocLike> = (urnRec: URN) => UrnTuple;
|
|
692
713
|
/**
|
|
693
714
|
* DB `toDim` lambda
|
|
694
|
-
*
|
|
715
|
+
*
|
|
716
|
+
* @see {@link DbRepoLike#$toDim}
|
|
717
|
+
* @method
|
|
718
|
+
*
|
|
719
|
+
* @param {Entity} doc - document
|
|
720
|
+
* @param {DefDims} dim - dimension
|
|
695
721
|
* */
|
|
696
722
|
export type DbRepoToDim<R, ID extends KeyValue, ENTITY extends Entity<ID>, DIMS extends DefDims = DefDims> = (doc: ENTITY, dim: DIMS | undefined) => Promise<R>;
|
|
723
|
+
/**
|
|
724
|
+
* Default model which contains keys
|
|
725
|
+
* */
|
|
697
726
|
export interface DbIdLike {
|
|
727
|
+
/**
|
|
728
|
+
* Secondary key for an entity
|
|
729
|
+
*
|
|
730
|
+
* @type {KeyValue}
|
|
731
|
+
*/
|
|
698
732
|
id?: KeyValue;
|
|
699
|
-
|
|
733
|
+
/**
|
|
734
|
+
* Primary key for an entity
|
|
735
|
+
*
|
|
736
|
+
* @type {string}
|
|
737
|
+
*/
|
|
700
738
|
_urn?: string;
|
|
739
|
+
/**
|
|
740
|
+
* Alternative usage for {@link #_urn}
|
|
741
|
+
*
|
|
742
|
+
* @type {string}
|
|
743
|
+
*/
|
|
744
|
+
urn?: string;
|
|
701
745
|
}
|
|
746
|
+
/**
|
|
747
|
+
* Lambda to handle several extensions, ie: search, ...
|
|
748
|
+
*
|
|
749
|
+
* @param {Entity} doc - document
|
|
750
|
+
* @async
|
|
751
|
+
* */
|
|
752
|
+
export type DbRepoExtensionLambda<ID extends KeyValue, ENTITY extends Entity<ID>> = (doc: ENTITY) => Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@samet-it/be-db-common",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Backend DB Common",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
}
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
+
"@leyyo/query": "^1.2.2",
|
|
66
67
|
"@leyyo/common": "^1.2.1",
|
|
67
|
-
"@leyyo/query": "^1.2.1",
|
|
68
68
|
"@leyyo/type": "^1.1.1",
|
|
69
69
|
"@samet-it/be-base-common": "^1.1.1",
|
|
70
70
|
"@samet-it/be-cache-common": "^1.1.1"
|