@loomcore/common 0.0.3 → 0.0.4
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/errors/custom.error.d.ts +6 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/validation.error.d.ts +10 -0
- package/dist/models/address.interface.d.ts +11 -0
- package/dist/models/api-response.interface.d.ts +8 -0
- package/dist/models/auditable.model.d.ts +12 -0
- package/dist/models/entity.model.d.ts +8 -0
- package/dist/models/error.interface.d.ts +4 -0
- package/dist/models/geo-json.interface.d.ts +12 -0
- package/dist/models/index.d.ts +15 -0
- package/dist/models/login-response.model.d.ts +18 -0
- package/dist/models/model-spec.interface.d.ts +15 -0
- package/dist/models/organization.model.d.ts +19 -0
- package/dist/models/paged-result.interface.d.ts +7 -0
- package/dist/models/password-reset-token.interface.d.ts +12 -0
- package/dist/models/query-options.model.d.ts +33 -0
- package/dist/models/token-response.model.d.ts +11 -0
- package/dist/models/user-context.model.d.ts +11 -0
- package/dist/models/user.model.d.ts +30 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/sort-direction.type.d.ts +3 -0
- package/dist/utils/entity.utils.d.ts +25 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/validation/formats/date-time.d.ts +1 -0
- package/dist/validation/formats/date.d.ts +1 -0
- package/dist/validation/formats/email.d.ts +1 -0
- package/dist/validation/formats/objectid.d.ts +1 -0
- package/dist/validation/formats/time.d.ts +1 -0
- package/dist/validation/index.d.ts +5 -0
- package/dist/validation/typebox-extensions.d.ts +13 -0
- package/dist/validation/typebox-setup.d.ts +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CustomError } from './custom.error.js';
|
|
2
|
+
export declare class ValidationError extends CustomError {
|
|
3
|
+
statusCode: number;
|
|
4
|
+
protected validationError: any;
|
|
5
|
+
constructor(validationError: any);
|
|
6
|
+
serializeErrors(): {
|
|
7
|
+
message: string;
|
|
8
|
+
field?: string | undefined;
|
|
9
|
+
}[];
|
|
10
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface IAuditable {
|
|
2
|
+
_created: Date;
|
|
3
|
+
_createdBy: string;
|
|
4
|
+
_updated: Date;
|
|
5
|
+
_updatedBy: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const AuditableSchema: import("@sinclair/typebox").TObject<{
|
|
8
|
+
_created: import("@sinclair/typebox").TTransform<import("@sinclair/typebox").TString, Date>;
|
|
9
|
+
_createdBy: import("@sinclair/typebox").TString;
|
|
10
|
+
_updated: import("@sinclair/typebox").TTransform<import("@sinclair/typebox").TString, Date>;
|
|
11
|
+
_updatedBy: import("@sinclair/typebox").TString;
|
|
12
|
+
}>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface IEntity {
|
|
2
|
+
_id: string;
|
|
3
|
+
_orgId?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare const EntitySchema: import("@sinclair/typebox").TObject<{
|
|
6
|
+
_id: import("@sinclair/typebox").TString;
|
|
7
|
+
_orgId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
8
|
+
}>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './user.model.js';
|
|
2
|
+
export * from './organization.model.js';
|
|
3
|
+
export * from './user-context.model.js';
|
|
4
|
+
export * from './entity.model.js';
|
|
5
|
+
export * from './login-response.model.js';
|
|
6
|
+
export * from './token-response.model.js';
|
|
7
|
+
export * from './auditable.model.js';
|
|
8
|
+
export * from './query-options.model.js';
|
|
9
|
+
export * from './password-reset-token.interface.js';
|
|
10
|
+
export * from './model-spec.interface.js';
|
|
11
|
+
export * from './paged-result.interface.js';
|
|
12
|
+
export * from './geo-json.interface.js';
|
|
13
|
+
export * from './address.interface.js';
|
|
14
|
+
export * from './error.interface.js';
|
|
15
|
+
export * from './api-response.interface.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ITokenResponse } from './token-response.model.js';
|
|
2
|
+
import { IUserContext } from './user-context.model.js';
|
|
3
|
+
export interface ILoginResponse {
|
|
4
|
+
tokens: ITokenResponse;
|
|
5
|
+
userContext: IUserContext;
|
|
6
|
+
}
|
|
7
|
+
export declare const LoginResponseSchema: import("@sinclair/typebox").TObject<{
|
|
8
|
+
tokens: import("@sinclair/typebox").TObject<{
|
|
9
|
+
accessToken: import("@sinclair/typebox").TString;
|
|
10
|
+
refreshToken: import("@sinclair/typebox").TString;
|
|
11
|
+
expiresOn: import("@sinclair/typebox").TNumber;
|
|
12
|
+
}>;
|
|
13
|
+
userContext: import("@sinclair/typebox").TObject<{
|
|
14
|
+
user: import("@sinclair/typebox").TObject<{}>;
|
|
15
|
+
_orgId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
16
|
+
}>;
|
|
17
|
+
}>;
|
|
18
|
+
export declare const LoginResponseSpec: import("./model-spec.interface.js").IModelSpec<import("@sinclair/typebox").TSchema>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TSchema } from '@sinclair/typebox';
|
|
2
|
+
import { TypeCompiler } from '@sinclair/typebox/compiler';
|
|
3
|
+
export interface IModelSpec<T extends TSchema = TSchema> {
|
|
4
|
+
schema: T;
|
|
5
|
+
partialSchema: TSchema;
|
|
6
|
+
fullSchema: T;
|
|
7
|
+
validator: ReturnType<typeof TypeCompiler.Compile>;
|
|
8
|
+
partialValidator: ReturnType<typeof TypeCompiler.Compile>;
|
|
9
|
+
fullValidator: ReturnType<typeof TypeCompiler.Compile>;
|
|
10
|
+
isAuditable?: boolean;
|
|
11
|
+
isMultiTenant?: boolean;
|
|
12
|
+
encode: <E>(entity: E, overrideSchema?: TSchema) => E;
|
|
13
|
+
decode: <E>(entity: E) => E;
|
|
14
|
+
clean: <E>(entity: E) => E;
|
|
15
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IAuditable } from './auditable.model.js';
|
|
2
|
+
export interface IOrganization extends IAuditable {
|
|
3
|
+
_id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
code: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
status: number;
|
|
8
|
+
isMetaOrg: boolean;
|
|
9
|
+
authToken?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const OrganizationSchema: import("@sinclair/typebox").TObject<{
|
|
12
|
+
name: import("@sinclair/typebox").TString;
|
|
13
|
+
code: import("@sinclair/typebox").TString;
|
|
14
|
+
description: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
15
|
+
status: import("@sinclair/typebox").TNumber;
|
|
16
|
+
isMetaOrg: import("@sinclair/typebox").TBoolean;
|
|
17
|
+
authToken: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
18
|
+
}>;
|
|
19
|
+
export declare const OrganizationSpec: import("./model-spec.interface.js").IModelSpec<import("@sinclair/typebox").TSchema>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IEntity, IAuditable } from './index.js';
|
|
2
|
+
export interface IPasswordResetToken extends IEntity, IAuditable {
|
|
3
|
+
email: string;
|
|
4
|
+
token: string;
|
|
5
|
+
expiresOn: number;
|
|
6
|
+
}
|
|
7
|
+
export declare const PasswordResetTokenSchema: import("@sinclair/typebox").TObject<{
|
|
8
|
+
email: import("@sinclair/typebox").TString;
|
|
9
|
+
token: import("@sinclair/typebox").TString;
|
|
10
|
+
expiresOn: import("@sinclair/typebox").TNumber;
|
|
11
|
+
}>;
|
|
12
|
+
export declare const PasswordResetTokenSpec: import("./model-spec.interface.js").IModelSpec<import("@sinclair/typebox").TSchema>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { SortDirection } from '../types/sort-direction.type.js';
|
|
2
|
+
export type Filter = {
|
|
3
|
+
eq?: string | number | boolean | Date;
|
|
4
|
+
ne?: string | number | boolean | Date;
|
|
5
|
+
any?: string[] | number[];
|
|
6
|
+
all?: string[] | number[];
|
|
7
|
+
lt?: number | Date;
|
|
8
|
+
lte?: number | Date;
|
|
9
|
+
gt?: number | Date;
|
|
10
|
+
gte?: number | Date;
|
|
11
|
+
startsWith?: string;
|
|
12
|
+
endsWith?: string;
|
|
13
|
+
contains?: string;
|
|
14
|
+
};
|
|
15
|
+
export interface IQueryOptions {
|
|
16
|
+
orderBy?: string;
|
|
17
|
+
sortDirection?: SortDirection;
|
|
18
|
+
page?: number;
|
|
19
|
+
pageSize?: number;
|
|
20
|
+
filters?: {
|
|
21
|
+
[key: string]: Filter;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export declare class QueryOptions implements IQueryOptions {
|
|
25
|
+
orderBy?: string;
|
|
26
|
+
sortDirection: SortDirection;
|
|
27
|
+
page: number;
|
|
28
|
+
pageSize: number;
|
|
29
|
+
filters?: {
|
|
30
|
+
[key: string]: Filter;
|
|
31
|
+
};
|
|
32
|
+
constructor(options?: IQueryOptions);
|
|
33
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface ITokenResponse {
|
|
2
|
+
accessToken: string;
|
|
3
|
+
refreshToken: string;
|
|
4
|
+
expiresOn: number;
|
|
5
|
+
}
|
|
6
|
+
export declare const TokenResponseSchema: import("@sinclair/typebox").TObject<{
|
|
7
|
+
accessToken: import("@sinclair/typebox").TString;
|
|
8
|
+
refreshToken: import("@sinclair/typebox").TString;
|
|
9
|
+
expiresOn: import("@sinclair/typebox").TNumber;
|
|
10
|
+
}>;
|
|
11
|
+
export declare const TokenResponseSpec: import("./model-spec.interface.js").IModelSpec<import("@sinclair/typebox").TSchema>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IUser } from './user.model.js';
|
|
2
|
+
export interface IUserContext {
|
|
3
|
+
user: IUser;
|
|
4
|
+
_orgId?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const EmptyUserContext: IUserContext;
|
|
7
|
+
export declare const UserContextSchema: import("@sinclair/typebox").TObject<{
|
|
8
|
+
user: import("@sinclair/typebox").TObject<{}>;
|
|
9
|
+
_orgId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
10
|
+
}>;
|
|
11
|
+
export declare const UserContextSpec: import("./model-spec.interface.js").IModelSpec<import("@sinclair/typebox").TSchema>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { IAuditable } from './auditable.model.js';
|
|
2
|
+
import { IEntity } from './entity.model.js';
|
|
3
|
+
export interface IUser extends IAuditable, IEntity {
|
|
4
|
+
email: string;
|
|
5
|
+
firstName?: string;
|
|
6
|
+
lastName?: string;
|
|
7
|
+
displayName?: string;
|
|
8
|
+
password: string;
|
|
9
|
+
roles?: string[];
|
|
10
|
+
_lastLoggedIn?: Date;
|
|
11
|
+
_lastPasswordChange?: Date;
|
|
12
|
+
}
|
|
13
|
+
export declare const UserPasswordSchema: import("@sinclair/typebox").TObject<{
|
|
14
|
+
password: import("@sinclair/typebox").TString;
|
|
15
|
+
}>;
|
|
16
|
+
export declare const passwordValidator: import("@sinclair/typebox/compiler").TypeCheck<import("@sinclair/typebox").TObject<{
|
|
17
|
+
password: import("@sinclair/typebox").TString;
|
|
18
|
+
}>>;
|
|
19
|
+
export declare const UserSchema: import("@sinclair/typebox").TObject<{
|
|
20
|
+
email: import("@sinclair/typebox").TString;
|
|
21
|
+
firstName: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
22
|
+
lastName: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
23
|
+
displayName: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
24
|
+
password: import("@sinclair/typebox").TString;
|
|
25
|
+
roles: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
|
|
26
|
+
_lastLoggedIn: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TTransform<import("@sinclair/typebox").TString, Date>>;
|
|
27
|
+
_lastPasswordChange: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TTransform<import("@sinclair/typebox").TString, Date>>;
|
|
28
|
+
}>;
|
|
29
|
+
export declare const UserSpec: import("./model-spec.interface.js").IModelSpec<import("@sinclair/typebox").TSchema>;
|
|
30
|
+
export declare const PublicUserSchema: import("@sinclair/typebox").TObject<{}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './sort-direction.type.js';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { TSchema } from '@sinclair/typebox';
|
|
2
|
+
import { TypeCompiler } from '@sinclair/typebox/compiler';
|
|
3
|
+
import { ValueError } from '@sinclair/typebox/errors';
|
|
4
|
+
import { IAuditable } from '../models/auditable.model.js';
|
|
5
|
+
import { IModelSpec } from '../models/model-spec.interface.js';
|
|
6
|
+
declare function getValidator(schema: TSchema): ReturnType<typeof TypeCompiler.Compile>;
|
|
7
|
+
declare function getModelSpec<T extends TSchema>(schema: T, options?: {
|
|
8
|
+
isAuditable?: boolean;
|
|
9
|
+
isMultiTenant?: boolean;
|
|
10
|
+
}): IModelSpec;
|
|
11
|
+
declare function validate(validator: ReturnType<typeof TypeCompiler.Compile>, data: unknown): ValueError[] | null;
|
|
12
|
+
declare function handleValidationResult(validationErrors: ValueError[] | null, methodName: string): void;
|
|
13
|
+
declare function isValidObjectId(id: any): boolean;
|
|
14
|
+
declare function isAuditable(entity: any): entity is IAuditable;
|
|
15
|
+
declare function isDecimalMultipleOf(value: number, multipleOf: number, precision?: number): boolean;
|
|
16
|
+
export declare const entityUtils: {
|
|
17
|
+
handleValidationResult: typeof handleValidationResult;
|
|
18
|
+
isValidObjectId: typeof isValidObjectId;
|
|
19
|
+
isAuditable: typeof isAuditable;
|
|
20
|
+
getValidator: typeof getValidator;
|
|
21
|
+
getModelSpec: typeof getModelSpec;
|
|
22
|
+
validate: typeof validate;
|
|
23
|
+
isDecimalMultipleOf: typeof isDecimalMultipleOf;
|
|
24
|
+
};
|
|
25
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './entity.utils.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function IsDateTime(value: string, strictTimeZone?: boolean): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function IsDate(value: string): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function IsEmail(value: string): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function IsObjectId(value: string): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function IsTime(value: string, strictTimeZone?: boolean): boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Kind, TSchema, NumberOptions } from '@sinclair/typebox';
|
|
2
|
+
export declare function TypeboxIsoDate(options?: object): import("@sinclair/typebox").TTransform<import("@sinclair/typebox").TString, Date>;
|
|
3
|
+
export declare function TypeboxDate(options?: object): import("@sinclair/typebox").TTransform<import("@sinclair/typebox").TString, Date>;
|
|
4
|
+
export declare function TypeboxObjectId(options?: object): import("@sinclair/typebox").TString;
|
|
5
|
+
export interface TDecimal extends TSchema, NumberOptions {
|
|
6
|
+
[Kind]: 'Decimal';
|
|
7
|
+
type: 'number';
|
|
8
|
+
static: number;
|
|
9
|
+
}
|
|
10
|
+
export declare function TypeboxDecimal(options?: NumberOptions): TDecimal;
|
|
11
|
+
export declare function TypeboxMoney(options?: NumberOptions): TDecimal;
|
|
12
|
+
export declare function TypeboxPercentage(options?: NumberOptions): TDecimal;
|
|
13
|
+
export declare function testMoneyType(): void;
|
package/package.json
CHANGED