@loomcore/common 0.0.39 → 0.0.40
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/models/auditable.model.d.ts +7 -6
- package/dist/models/auditable.model.js +5 -4
- package/dist/models/organization.model.d.ts +3 -2
- package/dist/models/organization.model.js +4 -4
- package/dist/utils/entity.utils.d.ts +1 -0
- package/dist/utils/entity.utils.js +5 -2
- package/package.json +1 -1
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
import { AppId } from '../types/app.types.js';
|
|
1
2
|
export interface IAuditable {
|
|
2
3
|
_created: Date;
|
|
3
|
-
_createdBy:
|
|
4
|
+
_createdBy: AppId;
|
|
4
5
|
_updated: Date;
|
|
5
|
-
_updatedBy:
|
|
6
|
+
_updatedBy: AppId;
|
|
6
7
|
_deleted?: Date;
|
|
7
|
-
_deletedBy?:
|
|
8
|
+
_deletedBy?: AppId;
|
|
8
9
|
}
|
|
9
10
|
export declare const AuditableSchema: import("@sinclair/typebox").TObject<{
|
|
10
11
|
_created: import("@sinclair/typebox").TTransform<import("@sinclair/typebox").TString, Date>;
|
|
11
|
-
_createdBy: import("@sinclair/typebox").
|
|
12
|
+
_createdBy: import("@sinclair/typebox").TSchema;
|
|
12
13
|
_updated: import("@sinclair/typebox").TTransform<import("@sinclair/typebox").TString, Date>;
|
|
13
|
-
_updatedBy: import("@sinclair/typebox").
|
|
14
|
+
_updatedBy: import("@sinclair/typebox").TSchema;
|
|
14
15
|
_deleted: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TTransform<import("@sinclair/typebox").TString, Date>>;
|
|
15
|
-
_deletedBy: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").
|
|
16
|
+
_deletedBy: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TSchema>;
|
|
16
17
|
}>;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Type } from '@sinclair/typebox';
|
|
2
|
-
import { TypeboxIsoDate } from '../validation/index.js';
|
|
2
|
+
import { getIdSchema, TypeboxIsoDate } from '../validation/index.js';
|
|
3
|
+
const idSchema = getIdSchema();
|
|
3
4
|
export const AuditableSchema = Type.Object({
|
|
4
5
|
_created: TypeboxIsoDate(),
|
|
5
|
-
_createdBy:
|
|
6
|
+
_createdBy: idSchema,
|
|
6
7
|
_updated: TypeboxIsoDate(),
|
|
7
|
-
_updatedBy:
|
|
8
|
+
_updatedBy: idSchema,
|
|
8
9
|
_deleted: Type.Optional(TypeboxIsoDate()),
|
|
9
|
-
_deletedBy: Type.Optional(
|
|
10
|
+
_deletedBy: Type.Optional(idSchema),
|
|
10
11
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IAuditable } from './auditable.model.js';
|
|
2
|
+
import { AppId } from '../types/app.types.js';
|
|
2
3
|
export interface IOrganization extends IAuditable {
|
|
3
|
-
_id:
|
|
4
|
+
_id: AppId;
|
|
4
5
|
name: string;
|
|
5
6
|
code: string;
|
|
6
7
|
description?: string;
|
|
@@ -9,7 +10,7 @@ export interface IOrganization extends IAuditable {
|
|
|
9
10
|
authToken?: string;
|
|
10
11
|
}
|
|
11
12
|
export declare const OrganizationSchema: import("@sinclair/typebox").TObject<{
|
|
12
|
-
_id: import("@sinclair/typebox").
|
|
13
|
+
_id: import("@sinclair/typebox").TSchema;
|
|
13
14
|
name: import("@sinclair/typebox").TString;
|
|
14
15
|
code: import("@sinclair/typebox").TString;
|
|
15
16
|
description: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Type } from '@sinclair/typebox';
|
|
2
2
|
import { entityUtils } from '../utils/index.js';
|
|
3
|
+
import { getIdSchema } from '../validation/index.js';
|
|
4
|
+
const idSchema = getIdSchema();
|
|
3
5
|
export const OrganizationSchema = Type.Object({
|
|
4
|
-
_id:
|
|
5
|
-
title: 'ID'
|
|
6
|
-
}),
|
|
6
|
+
_id: idSchema,
|
|
7
7
|
name: Type.String({
|
|
8
8
|
title: 'Name'
|
|
9
9
|
}),
|
|
@@ -24,4 +24,4 @@ export const OrganizationSchema = Type.Object({
|
|
|
24
24
|
title: 'Authentication Token'
|
|
25
25
|
}))
|
|
26
26
|
});
|
|
27
|
-
export const OrganizationSpec = entityUtils.getModelSpec(OrganizationSchema, { isAuditable: true });
|
|
27
|
+
export const OrganizationSpec = entityUtils.getModelSpec(OrganizationSchema, { isAuditable: true, isEntity: false });
|
|
@@ -6,6 +6,7 @@ import { IModelSpec } from '../models/model-spec.interface.js';
|
|
|
6
6
|
declare function getValidator(schema: TSchema): ReturnType<typeof TypeCompiler.Compile>;
|
|
7
7
|
declare function getModelSpec<T extends TSchema>(schema: T, options?: {
|
|
8
8
|
isAuditable?: boolean;
|
|
9
|
+
isEntity?: boolean;
|
|
9
10
|
}): IModelSpec;
|
|
10
11
|
declare function validate(validator: ReturnType<typeof TypeCompiler.Compile>, data: unknown): ValueError[] | null;
|
|
11
12
|
declare function handleValidationResult(validationErrors: ValueError[] | null, methodName: string): void;
|
|
@@ -9,11 +9,14 @@ function getValidator(schema) {
|
|
|
9
9
|
return validator;
|
|
10
10
|
}
|
|
11
11
|
function getModelSpec(schema, options = {}) {
|
|
12
|
+
const { isAuditable = false, isEntity = true } = options;
|
|
12
13
|
const partialSchema = Type.Partial(schema);
|
|
13
14
|
const schemasToIntersect = [];
|
|
14
15
|
schemasToIntersect.push(schema);
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
if (isEntity) {
|
|
17
|
+
schemasToIntersect.push(EntitySchema);
|
|
18
|
+
}
|
|
19
|
+
if (isAuditable) {
|
|
17
20
|
schemasToIntersect.push(AuditableSchema);
|
|
18
21
|
}
|
|
19
22
|
const fullSchema = Type.Intersect(schemasToIntersect);
|
package/package.json
CHANGED