@nu-art/ts-common 0.201.35 → 0.201.37

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/db/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { DB_Object, OmitDBObject, PartialProperties } from '../utils/types';
1
+ import { DB_Object, OmitDBObject, SubsetObjectByKeys, UniqueId } from '../utils/types';
2
2
  import { ValidatorTypeResolver } from '../validator/validator-core';
3
3
  export type DBIndex<T extends DB_Object> = {
4
4
  id: string;
@@ -10,17 +10,45 @@ export type DBIndex<T extends DB_Object> = {
10
10
  };
11
11
  export type Default_UniqueKey = '_id';
12
12
  export type VersionType = string;
13
- export type DBProto<T extends DB_Object, Ks extends keyof T = Default_UniqueKey, Versions extends VersionType[] = ['1.0.0'], GeneratedKeys extends keyof T = keyof DB_Object> = {
14
- generatedKeys: keyof DB_Object | GeneratedKeys;
15
- uiType: PartialProperties<T, keyof DB_Object | GeneratedKeys>;
16
- dbType: T;
17
- uniqueKeys: Ks;
13
+ export type VersionsDeclaration<T extends DB_Object, Versions extends VersionType[] = ['1.0.0'], Types extends [T, ...DB_Object[]] = [T, ...DB_Object[]]> = {
18
14
  versions: Versions;
19
- validatorBE: ValidatorTypeResolver<OmitDBObject<T>>;
20
- validatorFE: ValidatorTypeResolver<Omit<T, keyof GeneratedKeys>>;
21
- dbIndices: DBIndex<T>;
15
+ types: Types;
16
+ };
17
+ export type Proto_DB_Object<T extends DB_Object, GeneratedKeys extends keyof T, Versions extends VersionsDeclaration<T, any, any>, UniqueKeys extends keyof T = Default_UniqueKey> = {
18
+ type: T;
19
+ generatedKeys: GeneratedKeys;
20
+ versions: Versions;
21
+ uniqueKeys: UniqueKeys;
22
+ };
23
+ export type DBProto<P extends Proto_DB_Object<any, any, any, any>, ModifiableSubType = Omit<P['type'], P['generatedKeys'] | keyof DB_Object>, GeneratedSubType = SubsetObjectByKeys<P['type'], P['generatedKeys']>> = {
24
+ uiType: ModifiableSubType & Partial<GeneratedSubType> & Partial<DB_Object>;
25
+ dbType: P['type'];
26
+ generatedPropsValidator: ValidatorTypeResolver<GeneratedSubType>;
27
+ modifiablePropsValidator: ValidatorTypeResolver<ModifiableSubType>;
28
+ uniqueKeys: P['uniqueKeys'][];
29
+ generatedProps: P['generatedKeys'][];
30
+ versions: P['versions']['versions'];
31
+ indices: DBIndex<P['type']>[];
32
+ uniqueParam: UniqueId | {
33
+ [K in P['uniqueKeys']]: P['type'][K];
34
+ };
35
+ metadata?: Metadata<OmitDBObject<P['type']>>;
36
+ lockKeys?: (keyof P['type'])[];
37
+ };
38
+ export type DBDef_V3<P extends DBProto<any, any, any>> = {
39
+ dbName: string;
40
+ entityName: string;
41
+ TTL?: number;
42
+ lastUpdatedTTL?: number;
43
+ upgradeChunksSize?: number;
44
+ generatedPropsValidator: P['generatedPropsValidator'];
45
+ modifiablePropsValidator: P['modifiablePropsValidator'];
46
+ uniqueKeys?: P['uniqueKeys'];
47
+ versions?: P['versions'];
48
+ indices?: P['indices'];
49
+ lockKeys?: P['lockKeys'];
50
+ metadata?: P['metadata'];
22
51
  };
23
- export type DBDef_V2<Proto extends DBProto<any>> = DBDef<Proto['dbType'], Proto['uniqueKeys']>;
24
52
  /**
25
53
  * @field version - First item in the array is current version, Must pass all past versions with the current, default version is 1.0.0
26
54
  */
@@ -58,5 +86,36 @@ export type MetadataNested<T extends any> = T extends (infer I)[] ? MetadataProp
58
86
  export type Metadata<T extends any> = T extends (infer I)[] ? MetadataProperty<T> & {
59
87
  metadata: Metadata<I>;
60
88
  } : T extends object ? MetadataObject<T> : MetadataProperty<T>;
61
- export declare const DB_Object_Metadata: Metadata<DB_Object>;
89
+ export declare const DB_Object_Metadata: {
90
+ _id: {
91
+ optional: boolean;
92
+ valueType: string;
93
+ description: string;
94
+ };
95
+ _v: {
96
+ optional: boolean;
97
+ valueType: string;
98
+ description: string;
99
+ };
100
+ _originDocId: {
101
+ optional: boolean;
102
+ valueType: string;
103
+ description: string;
104
+ };
105
+ __hardDelete: {
106
+ optional: boolean;
107
+ valueType: string;
108
+ description: string;
109
+ };
110
+ __created: {
111
+ optional: boolean;
112
+ valueType: string;
113
+ description: string;
114
+ };
115
+ __updated: {
116
+ optional: boolean;
117
+ valueType: string;
118
+ description: string;
119
+ };
120
+ };
62
121
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nu-art/ts-common",
3
- "version": "0.201.35",
3
+ "version": "0.201.37",
4
4
  "description": "js and ts infra",
5
5
  "keywords": [
6
6
  "TacB0sS",
@@ -101,6 +101,7 @@ export declare function batchActionParallel<T extends any = any, R extends any =
101
101
  * @param result A flat array of single values
102
102
  */
103
103
  export declare function flatArray<T extends any[], K = NestedArrayType<T>>(arr: T, result?: K[]): K[];
104
+ export declare function filterFlatInstances<T extends any[], K = NestedArrayType<T>>(arr: T, result?: K[]): Exclude<K, undefined>[];
104
105
  export declare function groupArrayBy<T extends object, K extends string | number>(arr: T[], mapper: (item: T, index: number) => K): {
105
106
  key: K;
106
107
  values: T[];
@@ -26,7 +26,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
26
26
  });
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.arrayIncludesAny = exports.firstElement = exports.lastElement = exports.asOptionalArray = exports.asArray = exports.generateArray = exports.toggleInArray = exports.groupArrayBy = exports.flatArray = exports.batchActionParallel = exports.Promise_all_sequentially = exports.batchAction = exports.sortArray = exports.reduceToMap = exports.arrayToMap = exports.filterFalsy = exports.filterInstances = exports.filterDuplicates = exports.findDuplicates = exports.filterAsync = exports.toggleElementInArray = exports.addItemToArrayAtIndex = exports.addItemToArray = exports.removeFromArrayByIndex = exports.removeFromArray = exports.removeItemFromArray = exports.filterInOut = void 0;
29
+ exports.arrayIncludesAny = exports.firstElement = exports.lastElement = exports.asOptionalArray = exports.asArray = exports.generateArray = exports.toggleInArray = exports.groupArrayBy = exports.filterFlatInstances = exports.flatArray = exports.batchActionParallel = exports.Promise_all_sequentially = exports.batchAction = exports.sortArray = exports.reduceToMap = exports.arrayToMap = exports.filterFalsy = exports.filterInstances = exports.filterDuplicates = exports.findDuplicates = exports.filterAsync = exports.toggleElementInArray = exports.addItemToArrayAtIndex = exports.addItemToArray = exports.removeFromArrayByIndex = exports.removeFromArray = exports.removeItemFromArray = exports.filterInOut = void 0;
30
30
  const tools_1 = require("./tools");
31
31
  const object_tools_1 = require("./object-tools");
32
32
  function filterInOut(input, filter) {
@@ -254,6 +254,10 @@ function flatArray(arr, result = []) {
254
254
  return result;
255
255
  }
256
256
  exports.flatArray = flatArray;
257
+ function filterFlatInstances(arr, result = []) {
258
+ return filterInstances(flatArray(arr, result));
259
+ }
260
+ exports.filterFlatInstances = filterFlatInstances;
257
261
  function groupArrayBy(arr, mapper) {
258
262
  const map = arr.reduce((agg, item, index) => {
259
263
  const key = mapper(item, index);
@@ -1,5 +1,8 @@
1
- import { DB_Object, OmitDBObject } from './types';
1
+ import { DB_Object, OmitDBObject, SubsetObjectByKeys, TS_Object } from './types';
2
+ import { DBProto } from '../db/types';
2
3
  export declare const KeysOfDB_Object: (keyof DB_Object)[];
3
4
  export declare function dbObjectToId(i: DB_Object): string;
5
+ export declare function dbObjectToId_V3<Proto extends DBProto<any>>(i: Proto['dbType']): any;
4
6
  export declare function removeDBObjectKeys<T extends DB_Object>(instance: T): OmitDBObject<T>;
5
7
  export declare function keepDBObjectKeys<T extends DB_Object>(instance: T): DB_Object;
8
+ export declare function keepPartialObject<T extends TS_Object, Ks extends keyof T>(instance: T, keys: Ks[]): SubsetObjectByKeys<T, Ks>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.keepDBObjectKeys = exports.removeDBObjectKeys = exports.dbObjectToId = exports.KeysOfDB_Object = void 0;
3
+ exports.keepPartialObject = exports.keepDBObjectKeys = exports.removeDBObjectKeys = exports.dbObjectToId_V3 = exports.dbObjectToId = exports.KeysOfDB_Object = void 0;
4
4
  const object_tools_1 = require("./object-tools");
5
5
  const tools_1 = require("./tools");
6
6
  exports.KeysOfDB_Object = ['_id', '_v', '__created', '__updated'];
@@ -8,6 +8,10 @@ function dbObjectToId(i) {
8
8
  return i._id;
9
9
  }
10
10
  exports.dbObjectToId = dbObjectToId;
11
+ function dbObjectToId_V3(i) {
12
+ return i._id;
13
+ }
14
+ exports.dbObjectToId_V3 = dbObjectToId_V3;
11
15
  function removeDBObjectKeys(instance) {
12
16
  const _instance = (0, object_tools_1.deepClone)(instance);
13
17
  exports.KeysOfDB_Object.forEach(key => delete _instance[key]);
@@ -15,10 +19,14 @@ function removeDBObjectKeys(instance) {
15
19
  }
16
20
  exports.removeDBObjectKeys = removeDBObjectKeys;
17
21
  function keepDBObjectKeys(instance) {
18
- return exports.KeysOfDB_Object.reduce((objectToRet, key) => {
19
- if ((0, tools_1.exists)(instance[key])) // @ts-ignore
22
+ return keepPartialObject(instance, exports.KeysOfDB_Object);
23
+ }
24
+ exports.keepDBObjectKeys = keepDBObjectKeys;
25
+ function keepPartialObject(instance, keys) {
26
+ return keys.reduce((objectToRet, key) => {
27
+ if ((0, tools_1.exists)(instance[key]))
20
28
  objectToRet[key] = instance[key];
21
29
  return objectToRet;
22
30
  }, {});
23
31
  }
24
- exports.keepDBObjectKeys = keepDBObjectKeys;
32
+ exports.keepPartialObject = keepPartialObject;
@@ -1,5 +1,5 @@
1
1
  import { Validator, ValidatorTypeResolver } from './validator-core';
2
- import { AuditableV2, DB_Object } from '../utils/types';
2
+ import { AuditableV2 } from '../utils/types';
3
3
  export declare const tsValidate_OptionalArray: <T>(validator: ValidatorTypeResolver<T>) => Validator<T[]>;
4
4
  export declare const tsValidator_nonMandatoryString: Validator<string>;
5
5
  export declare const tsValidateMD5: (mandatory?: boolean) => Validator<string>;
@@ -25,4 +25,11 @@ export declare const tsValidator_LowerUpperStringWithSpaces: Validator<string>;
25
25
  export declare const tsValidator_LowerUpperStringWithDashesAndUnderscore: Validator<string>;
26
26
  export declare const tsValidator_InternationalPhoneNumber: Validator<string>;
27
27
  export declare const tsValidator_AuditableV2: ValidatorTypeResolver<AuditableV2>;
28
- export declare const DB_Object_validator: ValidatorTypeResolver<DB_Object>;
28
+ export declare const DB_Object_validator: {
29
+ _id: Validator<string>;
30
+ _v: Validator<string>;
31
+ _originDocId: Validator<string>;
32
+ __hardDelete: Validator<boolean>;
33
+ __created: Validator<number>;
34
+ __updated: Validator<number>;
35
+ };