@nu-art/ts-common 0.201.8 → 0.201.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.
@@ -65,10 +65,14 @@ class ModuleManager extends Logger_1.Logger {
65
65
  });
66
66
  this.modules.forEach(module => {
67
67
  this.logDebug(`--------- ${module.getName()} ---------`);
68
- // @ts-ignore
69
- module.init();
70
- // @ts-ignore
71
- module.initiated = true;
68
+ try { // @ts-ignore
69
+ module.init();
70
+ // @ts-ignore
71
+ module.initiated = true;
72
+ }
73
+ catch (e) {
74
+ this.logError(`Failed to init module ${module.getName()}.\n`, e);
75
+ }
72
76
  });
73
77
  // @ts-ignore
74
78
  this.modules.forEach(module => module.validate());
package/db/consts.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export declare const Const_UniqueKey = "_id";
2
+ export declare const Const_UniqueKeys: string[];
2
3
  export declare const DefaultDBVersion = "1.0.0";
package/db/consts.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DefaultDBVersion = exports.Const_UniqueKey = void 0;
3
+ exports.DefaultDBVersion = exports.Const_UniqueKeys = exports.Const_UniqueKey = void 0;
4
4
  exports.Const_UniqueKey = '_id';
5
+ exports.Const_UniqueKeys = [exports.Const_UniqueKey];
5
6
  exports.DefaultDBVersion = '1.0.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nu-art/ts-common",
3
- "version": "0.201.8",
3
+ "version": "0.201.10",
4
4
  "description": "js and ts infra",
5
5
  "keywords": [
6
6
  "TacB0sS",
@@ -2,3 +2,4 @@ import { DB_Object, OmitDBObject } from './types';
2
2
  export declare const KeysOfDB_Object: (keyof DB_Object)[];
3
3
  export declare function dbObjectToId(i: DB_Object): string;
4
4
  export declare function removeDBObjectKeys<T extends DB_Object>(instance: T): OmitDBObject<T>;
5
+ export declare function keepDBObjectKeys<T extends DB_Object>(instance: T): DB_Object;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.removeDBObjectKeys = exports.dbObjectToId = exports.KeysOfDB_Object = void 0;
3
+ exports.keepDBObjectKeys = exports.removeDBObjectKeys = exports.dbObjectToId = exports.KeysOfDB_Object = void 0;
4
4
  const object_tools_1 = require("./object-tools");
5
+ const tools_1 = require("./tools");
5
6
  exports.KeysOfDB_Object = ['_id', '_v', '__created', '__updated'];
6
7
  function dbObjectToId(i) {
7
8
  return i._id;
@@ -13,3 +14,11 @@ function removeDBObjectKeys(instance) {
13
14
  return _instance;
14
15
  }
15
16
  exports.removeDBObjectKeys = removeDBObjectKeys;
17
+ function keepDBObjectKeys(instance) {
18
+ return exports.KeysOfDB_Object.reduce((objectToRet, key) => {
19
+ if ((0, tools_1.exists)(instance[key])) // @ts-ignore
20
+ objectToRet[key] = instance[key];
21
+ return objectToRet;
22
+ }, {});
23
+ }
24
+ exports.keepDBObjectKeys = keepDBObjectKeys;
package/utils/tools.d.ts CHANGED
@@ -12,5 +12,5 @@ export declare const functionThatReturnsFalse: () => false;
12
12
  export declare const functionThatReturnsTrue: () => true;
13
13
  export declare const resolveContent: <T extends unknown = any>(content: ResolvableContent<T>) => T;
14
14
  export declare const resolveFunctionOrValue: <T extends unknown = any>(content: ResolvableContent<T>) => T;
15
- export declare function exists(item: any): boolean;
15
+ export declare function exists<T extends any = any>(item: any): item is T;
16
16
  export declare const logicalXOR: (a: boolean, b: boolean) => boolean;
package/utils/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Default_UniqueKey } from '../db/types';
1
2
  export type CustomOptional<T, K> = {
2
3
  [P in keyof T]?: K;
3
4
  };
@@ -60,6 +61,10 @@ export type DB_Object = DB_BaseObject & {
60
61
  export type UniqueId = string;
61
62
  export type PreDB<T extends DB_Object, K extends keyof T = never> = PartialProperties<T, keyof DB_Object | K>;
62
63
  export type OmitDBObject<T extends DB_Object> = Omit<T, keyof DB_Object>;
64
+ export type IndexKeys<T extends Object, Ks extends keyof T> = {
65
+ [K in Ks]: T[K];
66
+ };
67
+ export type UniqueParam<Type extends DB_Object, Ks extends keyof PreDB<Type> = Default_UniqueKey> = UniqueId | IndexKeys<Type, Ks>;
63
68
  export type Draftable = {
64
69
  _isDraft: boolean;
65
70
  };