@naturalcycles/js-lib 14.204.0 → 14.205.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.
- package/dist/json-schema/jsonSchemaBuilder.d.ts +1 -2
- package/dist/json-schema/jsonSchemaBuilder.js +1 -4
- package/dist/json-schema/jsonSchemas.d.ts +1 -2
- package/dist/json-schema/jsonSchemas.js +6 -6
- package/dist/types.d.ts +3 -20
- package/dist/zod/zod.shared.schemas.d.ts +0 -13
- package/dist/zod/zod.shared.schemas.js +5 -5
- package/dist-esm/json-schema/jsonSchemaBuilder.js +1 -4
- package/dist-esm/json-schema/jsonSchemas.js +5 -5
- package/dist-esm/zod/zod.shared.schemas.js +4 -4
- package/package.json +1 -1
- package/src/json-schema/jsonSchemaBuilder.ts +1 -6
- package/src/json-schema/jsonSchemas.ts +7 -7
- package/src/types.ts +3 -24
- package/src/zod/zod.shared.schemas.ts +4 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type { BaseDBEntity, JsonSchemaAllOf, JsonSchemaArray, JsonSchemaOneOf, JsonSchemaTuple,
|
|
2
|
+
import type { BaseDBEntity, JsonSchemaAllOf, JsonSchemaArray, JsonSchemaOneOf, JsonSchemaTuple, AnyObject } from '../index';
|
|
3
3
|
import type { JsonSchema, JsonSchemaAny, JsonSchemaBoolean, JsonSchemaConst, JsonSchemaEnum, JsonSchemaNull, JsonSchemaNumber, JsonSchemaObject, JsonSchemaRef, JsonSchemaString } from './jsonSchema.model';
|
|
4
4
|
export interface JsonSchemaBuilder<T = unknown> {
|
|
5
5
|
build: () => JsonSchema<T>;
|
|
@@ -117,7 +117,6 @@ export declare class JsonSchemaObjectBuilder<T extends AnyObject> extends JsonSc
|
|
|
117
117
|
maxProps(maxProperties: number): this;
|
|
118
118
|
additionalProps(additionalProperties: boolean): this;
|
|
119
119
|
baseDBEntity(): JsonSchemaObjectBuilder<T & BaseDBEntity>;
|
|
120
|
-
savedDBEntity(): JsonSchemaObjectBuilder<T & SavedDBEntity>;
|
|
121
120
|
extend<T2 extends AnyObject>(s2: JsonSchemaObjectBuilder<T2>): JsonSchemaObjectBuilder<T & T2>;
|
|
122
121
|
}
|
|
123
122
|
export declare class JsonSchemaArrayBuilder<ITEM> extends JsonSchemaAnyBuilder<ITEM[], JsonSchemaArray<ITEM>> {
|
|
@@ -317,10 +317,7 @@ class JsonSchemaObjectBuilder extends JsonSchemaAnyBuilder {
|
|
|
317
317
|
created: { type: 'number', format: 'unixTimestamp2000' },
|
|
318
318
|
updated: { type: 'number', format: 'unixTimestamp2000' },
|
|
319
319
|
});
|
|
320
|
-
return this;
|
|
321
|
-
}
|
|
322
|
-
savedDBEntity() {
|
|
323
|
-
return this.baseDBEntity().addRequired(['id', 'created', 'updated']);
|
|
320
|
+
return this.addRequired(['id', 'created', 'updated']);
|
|
324
321
|
}
|
|
325
322
|
extend(s2) {
|
|
326
323
|
const builder = new JsonSchemaObjectBuilder();
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import type { BaseDBEntity
|
|
1
|
+
import type { BaseDBEntity } from '../types';
|
|
2
2
|
export declare const baseDBEntityJsonSchema: import("./jsonSchemaBuilder").JsonSchemaObjectBuilder<BaseDBEntity>;
|
|
3
|
-
export declare const savedDBEntityJsonSchema: import("./jsonSchemaBuilder").JsonSchemaObjectBuilder<SavedDBEntity>;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.baseDBEntityJsonSchema = void 0;
|
|
4
4
|
const jsonSchemaBuilder_1 = require("./jsonSchemaBuilder");
|
|
5
5
|
exports.baseDBEntityJsonSchema = jsonSchemaBuilder_1.jsonSchema.object({
|
|
6
|
-
id: jsonSchemaBuilder_1.jsonSchema.string().optional(),
|
|
7
|
-
created: jsonSchemaBuilder_1.jsonSchema.unixTimestamp2000().optional(),
|
|
8
|
-
updated: jsonSchemaBuilder_1.jsonSchema.unixTimestamp2000().optional(),
|
|
9
|
-
});
|
|
10
|
-
exports.savedDBEntityJsonSchema = jsonSchemaBuilder_1.jsonSchema.object({
|
|
11
6
|
id: jsonSchemaBuilder_1.jsonSchema.string(),
|
|
12
7
|
created: jsonSchemaBuilder_1.jsonSchema.unixTimestamp2000(),
|
|
13
8
|
updated: jsonSchemaBuilder_1.jsonSchema.unixTimestamp2000(),
|
|
14
9
|
});
|
|
10
|
+
// export const savedDBEntityJsonSchema = jsonSchema.object<SavedDBEntity>({
|
|
11
|
+
// id: jsonSchema.string(),
|
|
12
|
+
// created: jsonSchema.unixTimestamp2000(),
|
|
13
|
+
// updated: jsonSchema.unixTimestamp2000(),
|
|
14
|
+
// })
|
package/dist/types.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ export interface AnyObjectWithId extends AnyObject, ObjectWithId {
|
|
|
35
35
|
/**
|
|
36
36
|
* Base interface for any Entity that was saved to DB.
|
|
37
37
|
*/
|
|
38
|
-
export type
|
|
38
|
+
export type BaseDBEntity = {
|
|
39
39
|
id: string;
|
|
40
40
|
/**
|
|
41
41
|
* unixTimestamp of when the entity was first created (in the DB).
|
|
@@ -46,25 +46,8 @@ export type SavedDBEntity = {
|
|
|
46
46
|
*/
|
|
47
47
|
updated: UnixTimestampNumber;
|
|
48
48
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
* This interface fits when entity was NOT YET saved to DB,
|
|
52
|
-
* hence `id`, `created` and `updated` fields CAN BE undefined (yet).
|
|
53
|
-
* When it's known to be saved - `SavedDBEntity` interface can be used instead.
|
|
54
|
-
*/
|
|
55
|
-
export type BaseDBEntity = {
|
|
56
|
-
id?: string;
|
|
57
|
-
/**
|
|
58
|
-
* unixTimestamp of when the entity was first created (in the DB).
|
|
59
|
-
*/
|
|
60
|
-
created?: UnixTimestampNumber;
|
|
61
|
-
/**
|
|
62
|
-
* unixTimestamp of when the entity was last updated (in the DB).
|
|
63
|
-
*/
|
|
64
|
-
updated?: UnixTimestampNumber;
|
|
65
|
-
};
|
|
66
|
-
export type Saved<T> = T & SavedDBEntity;
|
|
67
|
-
export type Unsaved<T> = T extends AnyObject ? Omit<T, 'id' | 'created' | 'updated'> & BaseDBEntity : T;
|
|
49
|
+
export type Saved<T> = T & BaseDBEntity;
|
|
50
|
+
export type Unsaved<T> = T extends AnyObject ? Omit<T, 'id' | 'created' | 'updated'> & Partial<BaseDBEntity> : T;
|
|
68
51
|
export type UnsavedId<T> = Omit<T, 'id'> & {
|
|
69
52
|
id?: string;
|
|
70
53
|
};
|
|
@@ -25,19 +25,6 @@ export declare const zIdBase64Url: z.ZodString;
|
|
|
25
25
|
*/
|
|
26
26
|
export declare const zSlug: z.ZodString;
|
|
27
27
|
export declare const zBaseDBEntity: z.ZodObject<{
|
|
28
|
-
id: z.ZodOptional<z.ZodString>;
|
|
29
|
-
created: z.ZodOptional<z.ZodNumber>;
|
|
30
|
-
updated: z.ZodOptional<z.ZodNumber>;
|
|
31
|
-
}, "strip", z.ZodTypeAny, {
|
|
32
|
-
id?: string | undefined;
|
|
33
|
-
created?: number | undefined;
|
|
34
|
-
updated?: number | undefined;
|
|
35
|
-
}, {
|
|
36
|
-
id?: string | undefined;
|
|
37
|
-
created?: number | undefined;
|
|
38
|
-
updated?: number | undefined;
|
|
39
|
-
}>;
|
|
40
|
-
export declare const zSavedDBEntity: z.ZodObject<{
|
|
41
28
|
id: z.ZodString;
|
|
42
29
|
created: z.ZodNumber;
|
|
43
30
|
updated: z.ZodNumber;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.zBaseDBEntity = exports.zSlug = exports.zIdBase64Url = exports.zIdBase64 = exports.zIdBase62 = exports.zId = exports.zJwt = exports.JWT_REGEX = exports.zBase64Url = exports.zBase64 = exports.zBase62 = exports.BASE64URL_REGEX = exports.BASE64_REGEX = exports.BASE62_REGEX = exports.zEmail = exports.zIsoDateString = exports.zSemVer = exports.zUnixTimestampMillis2000 = exports.zUnixTimestampMillis = exports.zUnixTimestamp2000 = exports.zUnixTimestamp = exports.TS_2000 = exports.TS_2500 = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
exports.TS_2500 = 16725225600; // 2500-01-01
|
|
6
6
|
exports.TS_2000 = 946684800; // 2000-01-01
|
|
@@ -86,9 +86,9 @@ exports.zSlug = zod_1.z
|
|
|
86
86
|
.describe('Slug');
|
|
87
87
|
exports.zBaseDBEntity = zod_1.z
|
|
88
88
|
.object({
|
|
89
|
-
id: zod_1.z.string()
|
|
90
|
-
created: exports.zUnixTimestamp2000
|
|
91
|
-
updated: exports.zUnixTimestamp2000
|
|
89
|
+
id: zod_1.z.string(),
|
|
90
|
+
created: exports.zUnixTimestamp2000,
|
|
91
|
+
updated: exports.zUnixTimestamp2000,
|
|
92
92
|
})
|
|
93
93
|
.describe('BaseDBEntity');
|
|
94
|
-
|
|
94
|
+
// export const zSavedDBEntity = zBaseDBEntity.required().describe('SavedDBEntity')
|
|
@@ -312,10 +312,7 @@ export class JsonSchemaObjectBuilder extends JsonSchemaAnyBuilder {
|
|
|
312
312
|
created: { type: 'number', format: 'unixTimestamp2000' },
|
|
313
313
|
updated: { type: 'number', format: 'unixTimestamp2000' },
|
|
314
314
|
});
|
|
315
|
-
return this;
|
|
316
|
-
}
|
|
317
|
-
savedDBEntity() {
|
|
318
|
-
return this.baseDBEntity().addRequired(['id', 'created', 'updated']);
|
|
315
|
+
return this.addRequired(['id', 'created', 'updated']);
|
|
319
316
|
}
|
|
320
317
|
extend(s2) {
|
|
321
318
|
const builder = new JsonSchemaObjectBuilder();
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { jsonSchema } from './jsonSchemaBuilder';
|
|
2
2
|
export const baseDBEntityJsonSchema = jsonSchema.object({
|
|
3
|
-
id: jsonSchema.string().optional(),
|
|
4
|
-
created: jsonSchema.unixTimestamp2000().optional(),
|
|
5
|
-
updated: jsonSchema.unixTimestamp2000().optional(),
|
|
6
|
-
});
|
|
7
|
-
export const savedDBEntityJsonSchema = jsonSchema.object({
|
|
8
3
|
id: jsonSchema.string(),
|
|
9
4
|
created: jsonSchema.unixTimestamp2000(),
|
|
10
5
|
updated: jsonSchema.unixTimestamp2000(),
|
|
11
6
|
});
|
|
7
|
+
// export const savedDBEntityJsonSchema = jsonSchema.object<SavedDBEntity>({
|
|
8
|
+
// id: jsonSchema.string(),
|
|
9
|
+
// created: jsonSchema.unixTimestamp2000(),
|
|
10
|
+
// updated: jsonSchema.unixTimestamp2000(),
|
|
11
|
+
// })
|
|
@@ -83,9 +83,9 @@ export const zSlug = z
|
|
|
83
83
|
.describe('Slug');
|
|
84
84
|
export const zBaseDBEntity = z
|
|
85
85
|
.object({
|
|
86
|
-
id: z.string()
|
|
87
|
-
created: zUnixTimestamp2000
|
|
88
|
-
updated: zUnixTimestamp2000
|
|
86
|
+
id: z.string(),
|
|
87
|
+
created: zUnixTimestamp2000,
|
|
88
|
+
updated: zUnixTimestamp2000,
|
|
89
89
|
})
|
|
90
90
|
.describe('BaseDBEntity');
|
|
91
|
-
export const zSavedDBEntity = zBaseDBEntity.required().describe('SavedDBEntity')
|
|
91
|
+
// export const zSavedDBEntity = zBaseDBEntity.required().describe('SavedDBEntity')
|
package/package.json
CHANGED
|
@@ -5,7 +5,6 @@ import type {
|
|
|
5
5
|
JsonSchemaArray,
|
|
6
6
|
JsonSchemaOneOf,
|
|
7
7
|
JsonSchemaTuple,
|
|
8
|
-
SavedDBEntity,
|
|
9
8
|
AnyObject,
|
|
10
9
|
} from '../index'
|
|
11
10
|
import { mergeJsonSchemaObjects, _deepCopy, _sortObject } from '../index'
|
|
@@ -375,11 +374,7 @@ export class JsonSchemaObjectBuilder<T extends AnyObject> extends JsonSchemaAnyB
|
|
|
375
374
|
updated: { type: 'number', format: 'unixTimestamp2000' },
|
|
376
375
|
})
|
|
377
376
|
|
|
378
|
-
return this
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
savedDBEntity(): JsonSchemaObjectBuilder<T & SavedDBEntity> {
|
|
382
|
-
return this.baseDBEntity().addRequired(['id', 'created', 'updated']) as any
|
|
377
|
+
return this.addRequired(['id', 'created', 'updated']) as any
|
|
383
378
|
}
|
|
384
379
|
|
|
385
380
|
extend<T2 extends AnyObject>(s2: JsonSchemaObjectBuilder<T2>): JsonSchemaObjectBuilder<T & T2> {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type { BaseDBEntity
|
|
1
|
+
import type { BaseDBEntity } from '../types'
|
|
2
2
|
import { jsonSchema } from './jsonSchemaBuilder'
|
|
3
3
|
|
|
4
4
|
export const baseDBEntityJsonSchema = jsonSchema.object<BaseDBEntity>({
|
|
5
|
-
id: jsonSchema.string().optional(),
|
|
6
|
-
created: jsonSchema.unixTimestamp2000().optional(),
|
|
7
|
-
updated: jsonSchema.unixTimestamp2000().optional(),
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
export const savedDBEntityJsonSchema = jsonSchema.object<SavedDBEntity>({
|
|
11
5
|
id: jsonSchema.string(),
|
|
12
6
|
created: jsonSchema.unixTimestamp2000(),
|
|
13
7
|
updated: jsonSchema.unixTimestamp2000(),
|
|
14
8
|
})
|
|
9
|
+
|
|
10
|
+
// export const savedDBEntityJsonSchema = jsonSchema.object<SavedDBEntity>({
|
|
11
|
+
// id: jsonSchema.string(),
|
|
12
|
+
// created: jsonSchema.unixTimestamp2000(),
|
|
13
|
+
// updated: jsonSchema.unixTimestamp2000(),
|
|
14
|
+
// })
|
package/src/types.ts
CHANGED
|
@@ -47,7 +47,7 @@ export interface AnyObjectWithId extends AnyObject, ObjectWithId {}
|
|
|
47
47
|
* Base interface for any Entity that was saved to DB.
|
|
48
48
|
*/
|
|
49
49
|
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
50
|
-
export type
|
|
50
|
+
export type BaseDBEntity = {
|
|
51
51
|
id: string
|
|
52
52
|
|
|
53
53
|
/**
|
|
@@ -61,31 +61,10 @@ export type SavedDBEntity = {
|
|
|
61
61
|
updated: UnixTimestampNumber
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
* Base interface for any Entity that can be saved to DB.
|
|
66
|
-
* This interface fits when entity was NOT YET saved to DB,
|
|
67
|
-
* hence `id`, `created` and `updated` fields CAN BE undefined (yet).
|
|
68
|
-
* When it's known to be saved - `SavedDBEntity` interface can be used instead.
|
|
69
|
-
*/
|
|
70
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
71
|
-
export type BaseDBEntity = {
|
|
72
|
-
id?: string
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* unixTimestamp of when the entity was first created (in the DB).
|
|
76
|
-
*/
|
|
77
|
-
created?: UnixTimestampNumber
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* unixTimestamp of when the entity was last updated (in the DB).
|
|
81
|
-
*/
|
|
82
|
-
updated?: UnixTimestampNumber
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export type Saved<T> = T & SavedDBEntity
|
|
64
|
+
export type Saved<T> = T & BaseDBEntity
|
|
86
65
|
|
|
87
66
|
export type Unsaved<T> = T extends AnyObject
|
|
88
|
-
? Omit<T, 'id' | 'created' | 'updated'> & BaseDBEntity
|
|
67
|
+
? Omit<T, 'id' | 'created' | 'updated'> & Partial<BaseDBEntity>
|
|
89
68
|
: T
|
|
90
69
|
|
|
91
70
|
export type UnsavedId<T> = Omit<T, 'id'> & {
|
|
@@ -93,10 +93,10 @@ export const zSlug = z
|
|
|
93
93
|
|
|
94
94
|
export const zBaseDBEntity = z
|
|
95
95
|
.object({
|
|
96
|
-
id: z.string()
|
|
97
|
-
created: zUnixTimestamp2000
|
|
98
|
-
updated: zUnixTimestamp2000
|
|
96
|
+
id: z.string(),
|
|
97
|
+
created: zUnixTimestamp2000,
|
|
98
|
+
updated: zUnixTimestamp2000,
|
|
99
99
|
})
|
|
100
100
|
.describe('BaseDBEntity')
|
|
101
101
|
|
|
102
|
-
export const zSavedDBEntity = zBaseDBEntity.required().describe('SavedDBEntity')
|
|
102
|
+
// export const zSavedDBEntity = zBaseDBEntity.required().describe('SavedDBEntity')
|