@naturalcycles/js-lib 14.196.0 → 14.197.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.
@@ -116,8 +116,8 @@ export declare class JsonSchemaObjectBuilder<T extends AnyObject> extends JsonSc
116
116
  minProps(minProperties: number): this;
117
117
  maxProps(maxProperties: number): this;
118
118
  additionalProps(additionalProperties: boolean): this;
119
- baseDBEntity<ID extends string | number = string>(idType?: string): JsonSchemaObjectBuilder<T & BaseDBEntity<ID>>;
120
- savedDBEntity<ID extends string | number = string>(idType?: string): JsonSchemaObjectBuilder<T & SavedDBEntity<ID>>;
119
+ baseDBEntity(): JsonSchemaObjectBuilder<T & BaseDBEntity>;
120
+ savedDBEntity(): JsonSchemaObjectBuilder<T & SavedDBEntity>;
121
121
  extend<T2 extends AnyObject>(s2: JsonSchemaObjectBuilder<T2>): JsonSchemaObjectBuilder<T & T2>;
122
122
  }
123
123
  export declare class JsonSchemaArrayBuilder<ITEM> extends JsonSchemaAnyBuilder<ITEM[], JsonSchemaArray<ITEM>> {
@@ -311,16 +311,16 @@ class JsonSchemaObjectBuilder extends JsonSchemaAnyBuilder {
311
311
  Object.assign(this.schema, { additionalProperties });
312
312
  return this;
313
313
  }
314
- baseDBEntity(idType = 'string') {
314
+ baseDBEntity() {
315
315
  Object.assign(this.schema.properties, {
316
- id: { type: idType },
316
+ id: { type: 'string' },
317
317
  created: { type: 'number', format: 'unixTimestamp2000' },
318
318
  updated: { type: 'number', format: 'unixTimestamp2000' },
319
319
  });
320
320
  return this;
321
321
  }
322
- savedDBEntity(idType = 'string') {
323
- return this.baseDBEntity(idType).addRequired(['id', 'created', 'updated']);
322
+ savedDBEntity() {
323
+ return this.baseDBEntity().addRequired(['id', 'created', 'updated']);
324
324
  }
325
325
  extend(s2) {
326
326
  const builder = new JsonSchemaObjectBuilder();
package/dist/types.d.ts CHANGED
@@ -19,19 +19,19 @@ export type CreatedUpdated = {
19
19
  created: number;
20
20
  updated: number;
21
21
  };
22
- export interface CreatedUpdatedId<ID extends string | number = string | number> extends CreatedUpdated {
23
- id: ID;
22
+ export interface CreatedUpdatedId extends CreatedUpdated {
23
+ id: string;
24
24
  }
25
- export type ObjectWithId<ID extends string | number = string | number> = {
26
- id: ID;
25
+ export type ObjectWithId = {
26
+ id: string;
27
27
  };
28
- export interface AnyObjectWithId<ID extends string | number = string | number> extends AnyObject, ObjectWithId<ID> {
28
+ export interface AnyObjectWithId extends AnyObject, ObjectWithId {
29
29
  }
30
30
  /**
31
31
  * Base interface for any Entity that was saved to DB.
32
32
  */
33
- export type SavedDBEntity<ID extends string | number = string> = {
34
- id: ID;
33
+ export type SavedDBEntity = {
34
+ id: string;
35
35
  /**
36
36
  * unixTimestamp of when the entity was first created (in the DB).
37
37
  */
@@ -47,8 +47,8 @@ export type SavedDBEntity<ID extends string | number = string> = {
47
47
  * hence `id`, `created` and `updated` fields CAN BE undefined (yet).
48
48
  * When it's known to be saved - `SavedDBEntity` interface can be used instead.
49
49
  */
50
- export type BaseDBEntity<ID extends string | number = string> = {
51
- id?: ID;
50
+ export type BaseDBEntity = {
51
+ id?: string;
52
52
  /**
53
53
  * unixTimestamp of when the entity was first created (in the DB).
54
54
  */
@@ -58,8 +58,8 @@ export type BaseDBEntity<ID extends string | number = string> = {
58
58
  */
59
59
  updated?: UnixTimestampNumber;
60
60
  };
61
- export type Saved<T extends Partial<ObjectWithId>> = T extends AnyObject ? Omit<T, 'id' | 'created' | 'updated'> & SavedDBEntity<NonNullable<T['id']>> : T;
62
- export type Unsaved<T extends Partial<ObjectWithId>> = T extends AnyObject ? Omit<T, 'id' | 'created' | 'updated'> & BaseDBEntity<NonNullable<T['id']>> : T;
61
+ export type Saved<T extends Partial<ObjectWithId>> = T extends AnyObject ? Omit<T, 'id' | 'created' | 'updated'> & SavedDBEntity : T;
62
+ export type Unsaved<T extends Partial<ObjectWithId>> = T extends AnyObject ? Omit<T, 'id' | 'created' | 'updated'> & BaseDBEntity : T;
63
63
  export type UnsavedId<T extends Partial<ObjectWithId>> = Omit<T, 'id'> & {
64
64
  id?: T['id'];
65
65
  };
@@ -306,16 +306,16 @@ export class JsonSchemaObjectBuilder extends JsonSchemaAnyBuilder {
306
306
  Object.assign(this.schema, { additionalProperties });
307
307
  return this;
308
308
  }
309
- baseDBEntity(idType = 'string') {
309
+ baseDBEntity() {
310
310
  Object.assign(this.schema.properties, {
311
- id: { type: idType },
311
+ id: { type: 'string' },
312
312
  created: { type: 'number', format: 'unixTimestamp2000' },
313
313
  updated: { type: 'number', format: 'unixTimestamp2000' },
314
314
  });
315
315
  return this;
316
316
  }
317
- savedDBEntity(idType = 'string') {
318
- return this.baseDBEntity(idType).addRequired(['id', 'created', 'updated']);
317
+ savedDBEntity() {
318
+ return this.baseDBEntity().addRequired(['id', 'created', 'updated']);
319
319
  }
320
320
  extend(s2) {
321
321
  const builder = new JsonSchemaObjectBuilder();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.196.0",
3
+ "version": "14.197.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -368,11 +368,9 @@ export class JsonSchemaObjectBuilder<T extends AnyObject> extends JsonSchemaAnyB
368
368
  return this
369
369
  }
370
370
 
371
- baseDBEntity<ID extends string | number = string>(
372
- idType = 'string',
373
- ): JsonSchemaObjectBuilder<T & BaseDBEntity<ID>> {
371
+ baseDBEntity(): JsonSchemaObjectBuilder<T & BaseDBEntity> {
374
372
  Object.assign(this.schema.properties, {
375
- id: { type: idType },
373
+ id: { type: 'string' },
376
374
  created: { type: 'number', format: 'unixTimestamp2000' },
377
375
  updated: { type: 'number', format: 'unixTimestamp2000' },
378
376
  })
@@ -380,10 +378,8 @@ export class JsonSchemaObjectBuilder<T extends AnyObject> extends JsonSchemaAnyB
380
378
  return this
381
379
  }
382
380
 
383
- savedDBEntity<ID extends string | number = string>(
384
- idType = 'string',
385
- ): JsonSchemaObjectBuilder<T & SavedDBEntity<ID>> {
386
- return this.baseDBEntity(idType).addRequired(['id', 'created', 'updated']) as any
381
+ savedDBEntity(): JsonSchemaObjectBuilder<T & SavedDBEntity> {
382
+ return this.baseDBEntity().addRequired(['id', 'created', 'updated']) as any
387
383
  }
388
384
 
389
385
  extend<T2 extends AnyObject>(s2: JsonSchemaObjectBuilder<T2>): JsonSchemaObjectBuilder<T & T2> {
package/src/types.ts CHANGED
@@ -25,26 +25,23 @@ export type CreatedUpdated = {
25
25
  updated: number
26
26
  }
27
27
 
28
- export interface CreatedUpdatedId<ID extends string | number = string | number>
29
- extends CreatedUpdated {
30
- id: ID
28
+ export interface CreatedUpdatedId extends CreatedUpdated {
29
+ id: string
31
30
  }
32
31
 
33
32
  // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
34
- export type ObjectWithId<ID extends string | number = string | number> = {
35
- id: ID
33
+ export type ObjectWithId = {
34
+ id: string
36
35
  }
37
36
 
38
- export interface AnyObjectWithId<ID extends string | number = string | number>
39
- extends AnyObject,
40
- ObjectWithId<ID> {}
37
+ export interface AnyObjectWithId extends AnyObject, ObjectWithId {}
41
38
 
42
39
  /**
43
40
  * Base interface for any Entity that was saved to DB.
44
41
  */
45
42
  // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
46
- export type SavedDBEntity<ID extends string | number = string> = {
47
- id: ID
43
+ export type SavedDBEntity = {
44
+ id: string
48
45
 
49
46
  /**
50
47
  * unixTimestamp of when the entity was first created (in the DB).
@@ -64,8 +61,8 @@ export type SavedDBEntity<ID extends string | number = string> = {
64
61
  * When it's known to be saved - `SavedDBEntity` interface can be used instead.
65
62
  */
66
63
  // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
67
- export type BaseDBEntity<ID extends string | number = string> = {
68
- id?: ID
64
+ export type BaseDBEntity = {
65
+ id?: string
69
66
 
70
67
  /**
71
68
  * unixTimestamp of when the entity was first created (in the DB).
@@ -79,11 +76,11 @@ export type BaseDBEntity<ID extends string | number = string> = {
79
76
  }
80
77
 
81
78
  export type Saved<T extends Partial<ObjectWithId>> = T extends AnyObject
82
- ? Omit<T, 'id' | 'created' | 'updated'> & SavedDBEntity<NonNullable<T['id']>>
79
+ ? Omit<T, 'id' | 'created' | 'updated'> & SavedDBEntity
83
80
  : T
84
81
 
85
82
  export type Unsaved<T extends Partial<ObjectWithId>> = T extends AnyObject
86
- ? Omit<T, 'id' | 'created' | 'updated'> & BaseDBEntity<NonNullable<T['id']>>
83
+ ? Omit<T, 'id' | 'created' | 'updated'> & BaseDBEntity
87
84
  : T
88
85
 
89
86
  export type UnsavedId<T extends Partial<ObjectWithId>> = Omit<T, 'id'> & {