@naturalcycles/db-lib 8.30.0 → 8.31.0

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.
@@ -25,7 +25,8 @@ class CommonDao {
25
25
  // otherwise to log Operations
26
26
  // e.g in Dev (local machine), Test - it will log operations (useful for debugging)
27
27
  logLevel: isGAE || isCI ? common_dao_model_1.CommonDaoLogLevel.NONE : common_dao_model_1.CommonDaoLogLevel.OPERATIONS,
28
- createdUpdated: true,
28
+ created: true,
29
+ updated: true,
29
30
  logger: console,
30
31
  ...cfg,
31
32
  hooks: {
@@ -405,9 +406,13 @@ class CommonDao {
405
406
  assignIdCreatedUpdated(obj, opt = {}) {
406
407
  const now = Math.floor(Date.now() / 1000);
407
408
  obj.id = obj.id || this.cfg.hooks.createId(obj);
408
- if (this.cfg.createdUpdated) {
409
+ if (this.cfg.created) {
409
410
  Object.assign(obj, {
410
411
  created: obj.created || obj.updated || now,
412
+ });
413
+ }
414
+ if (this.cfg.updated) {
415
+ Object.assign(obj, {
411
416
  updated: opt.preserveUpdatedCreated && obj.updated ? obj.updated : now,
412
417
  });
413
418
  }
@@ -76,10 +76,15 @@ export interface CommonDaoCfg<BM extends Partial<ObjectWithId>, DBM extends Obje
76
76
  logStarted?: boolean;
77
77
  hooks?: Partial<CommonDaoHooks<BM, DBM, TM>>;
78
78
  /**
79
- * @default true
80
- * Set to false to disable created/updated fields management.
79
+ * Defaults to true
80
+ * Set to false to disable `created` field management.
81
81
  */
82
- createdUpdated?: boolean;
82
+ created?: boolean;
83
+ /**
84
+ * Defaults to true
85
+ * Set to false to disable `updated` field management.
86
+ */
87
+ updated?: boolean;
83
88
  /**
84
89
  * Default is false.
85
90
  * If true - will run `_filterNullishValues` inside `validateAndConvert` function
@@ -17,7 +17,7 @@ export interface TestItemTM {
17
17
  export declare const testItemBMSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<TestItemBM, TestItemBM>;
18
18
  export declare const testItemDBMSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<TestItemDBM, TestItemDBM>;
19
19
  export declare const testItemTMSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<TestItemTM, TestItemTM>;
20
- export declare const testItemBMJsonSchema: import("@naturalcycles/js-lib/dist/json-schema/jsonSchemaBuilder").JsonSchemaObjectBuilder<TestItemBM & Partial<import("@naturalcycles/js-lib").SavedDBEntity>>;
20
+ export declare const testItemBMJsonSchema: import("@naturalcycles/js-lib/dist/json-schema/jsonSchemaBuilder").JsonSchemaObjectBuilder<TestItemBM & Partial<import("@naturalcycles/js-lib").SavedDBEntity<string>>>;
21
21
  export declare const testItemDBMJsonSchema: import("@naturalcycles/js-lib/dist/json-schema/jsonSchemaBuilder").JsonSchemaObjectBuilder<TestItemDBM>;
22
22
  export declare function createTestItemDBM(num?: number): TestItemDBM;
23
23
  export declare function createTestItemBM(num?: number): Saved<TestItemBM>;
@@ -1,8 +1,8 @@
1
1
  import { CommonDBOptions, CommonDBSaveOptions } from '../db.model';
2
2
  import { DBQuery, DBQueryFilter, DBQueryOrder } from '../query/dbQuery';
3
3
  export declare const commonDBOptionsSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<CommonDBOptions, CommonDBOptions>;
4
- export declare const commonDBSaveOptionsSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<CommonDBSaveOptions<import("@naturalcycles/js-lib").AnyObjectWithId>, CommonDBSaveOptions<import("@naturalcycles/js-lib").AnyObjectWithId>>;
4
+ export declare const commonDBSaveOptionsSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<CommonDBSaveOptions<import("@naturalcycles/js-lib").AnyObjectWithId<string>>, CommonDBSaveOptions<import("@naturalcycles/js-lib").AnyObjectWithId<string>>>;
5
5
  export declare const dbQueryFilterOperatorSchema: import("@naturalcycles/nodejs-lib/dist/validation/joi/string.extensions").ExtendedStringSchema;
6
- export declare const dbQueryFilterSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<DBQueryFilter<import("@naturalcycles/js-lib").AnyObjectWithId>, DBQueryFilter<import("@naturalcycles/js-lib").AnyObjectWithId>>;
7
- export declare const dbQueryOrderSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<DBQueryOrder<import("@naturalcycles/js-lib").AnyObjectWithId>, DBQueryOrder<import("@naturalcycles/js-lib").AnyObjectWithId>>;
6
+ export declare const dbQueryFilterSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<DBQueryFilter<import("@naturalcycles/js-lib").AnyObjectWithId<string>>, DBQueryFilter<import("@naturalcycles/js-lib").AnyObjectWithId<string>>>;
7
+ export declare const dbQueryOrderSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<DBQueryOrder<import("@naturalcycles/js-lib").AnyObjectWithId<string>>, DBQueryOrder<import("@naturalcycles/js-lib").AnyObjectWithId<string>>>;
8
8
  export declare const dbQuerySchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<DBQuery<any>, DBQuery<any>>;
package/package.json CHANGED
@@ -43,7 +43,7 @@
43
43
  "engines": {
44
44
  "node": ">=14.15"
45
45
  },
46
- "version": "8.30.0",
46
+ "version": "8.31.0",
47
47
  "description": "Lowest Common Denominator API to supported Databases",
48
48
  "keywords": [
49
49
  "db",
@@ -102,10 +102,16 @@ export interface CommonDaoCfg<
102
102
  hooks?: Partial<CommonDaoHooks<BM, DBM, TM>>
103
103
 
104
104
  /**
105
- * @default true
106
- * Set to false to disable created/updated fields management.
105
+ * Defaults to true
106
+ * Set to false to disable `created` field management.
107
107
  */
108
- createdUpdated?: boolean
108
+ created?: boolean
109
+
110
+ /**
111
+ * Defaults to true
112
+ * Set to false to disable `updated` field management.
113
+ */
114
+ updated?: boolean
109
115
 
110
116
  /**
111
117
  * Default is false.
@@ -69,7 +69,8 @@ export class CommonDao<
69
69
  // otherwise to log Operations
70
70
  // e.g in Dev (local machine), Test - it will log operations (useful for debugging)
71
71
  logLevel: isGAE || isCI ? CommonDaoLogLevel.NONE : CommonDaoLogLevel.OPERATIONS,
72
- createdUpdated: true,
72
+ created: true,
73
+ updated: true,
73
74
  logger: console,
74
75
  ...cfg,
75
76
  hooks: {
@@ -562,9 +563,14 @@ export class CommonDao<
562
563
 
563
564
  obj.id = obj.id || this.cfg.hooks!.createId!(obj)
564
565
 
565
- if (this.cfg.createdUpdated) {
566
+ if (this.cfg.created) {
566
567
  Object.assign(obj, {
567
568
  created: (obj as any).created || (obj as any).updated || now,
569
+ })
570
+ }
571
+
572
+ if (this.cfg.updated) {
573
+ Object.assign(obj, {
568
574
  updated: opt.preserveUpdatedCreated && (obj as any).updated ? (obj as any).updated : now,
569
575
  })
570
576
  }