@spytecgps/nova-orm 0.0.9 → 0.0.11
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/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/migration/1684483704434-addLowerCaseIndex.d.ts +5 -0
- package/dist/novaDataSource.d.ts +3 -1
- package/dist/repositories/baseRepository.d.ts +3 -1
- package/dist/repositories/devices/getDeviceByImei.d.ts +5 -0
- package/dist/repositories/devices/getDeviceTypes.d.ts +5 -0
- package/dist/repositories/devices/getDevicesByDeviceTypeId.d.ts +5 -0
- package/dist/repositories/devices/index.d.ts +28 -0
- package/dist/repositories/index.d.ts +2 -2
- package/dist/repositories/security/getAllRoles.d.ts +4 -0
- package/dist/repositories/security/getUserRoles.d.ts +5 -0
- package/dist/repositories/security/getUserRolesByClientId.d.ts +5 -0
- package/dist/repositories/security/index.d.ts +29 -0
- package/dist/repositories/security/userIsInRole.d.ts +4 -0
- package/dist/types/devices.d.ts +24 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/logger.d.ts +60 -0
- package/dist/types/security.d.ts +18 -0
- package/package.json +2 -2
- package/dist/repositories/devicesRepository.d.ts +0 -24
- package/dist/repositories/securityRepository.d.ts +0 -21
package/dist/novaDataSource.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DataSource, EntityTarget, LoggerOptions, ObjectLiteral, Repository, SelectQueryBuilder } from 'typeorm';
|
|
2
|
+
import { Logger } from './types/logger';
|
|
2
3
|
export interface NovaDataSourceConfig {
|
|
3
4
|
/**
|
|
4
5
|
* Database username.
|
|
@@ -31,7 +32,8 @@ export interface NovaDataSourceConfig {
|
|
|
31
32
|
}
|
|
32
33
|
export declare class NovaDataSource {
|
|
33
34
|
protected readonly dataSource: DataSource;
|
|
34
|
-
|
|
35
|
+
protected readonly logger: Logger;
|
|
36
|
+
constructor(config: NovaDataSourceConfig, logger: Logger);
|
|
35
37
|
/**
|
|
36
38
|
* Performs connection to the database.
|
|
37
39
|
*/
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { NovaDataSourceConfig } from '../novaDataSource';
|
|
2
|
+
import { Logger } from '../types/logger';
|
|
2
3
|
export declare class BaseRepository {
|
|
3
4
|
protected readonly novaDataSourceConfig: NovaDataSourceConfig;
|
|
4
|
-
|
|
5
|
+
protected readonly logger: Logger;
|
|
6
|
+
constructor(config: NovaDataSourceConfig, logger: Logger);
|
|
5
7
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Device } from '../../entities';
|
|
2
|
+
import { NovaDataSource } from '../../novaDataSource';
|
|
3
|
+
import { GetDeviceByImeiParams } from '../../types/devices';
|
|
4
|
+
import { Logger } from '../../types/logger';
|
|
5
|
+
export declare const getDeviceByImei: (novaDataSource: NovaDataSource, params: GetDeviceByImeiParams, logger: Logger) => Promise<Device>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { DeviceType } from '../../entities';
|
|
2
|
+
import { NovaDataSource } from '../../novaDataSource';
|
|
3
|
+
import { GetDeviceTypesParams } from '../../types/devices';
|
|
4
|
+
import { Logger } from '../../types/logger';
|
|
5
|
+
export declare const getDeviceTypes: (novaDataSource: NovaDataSource, params: GetDeviceTypesParams, logger: Logger) => Promise<DeviceType[]>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Device } from '../../entities';
|
|
2
|
+
import { NovaDataSource } from '../../novaDataSource';
|
|
3
|
+
import { GetDevicesByDeviceTypeIdParams } from '../../types/devices';
|
|
4
|
+
import { Logger } from '../../types/logger';
|
|
5
|
+
export declare const getDevicesByDeviceTypeId: (novaDataSource: NovaDataSource, params: GetDevicesByDeviceTypeIdParams, logger: Logger) => Promise<Device[]>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Device, DeviceType } from '../../entities';
|
|
2
|
+
import { GetDeviceByImeiParams, GetDevicesByDeviceTypeIdParams, GetDeviceTypesParams } from '../../types/devices';
|
|
3
|
+
import { BaseRepository } from './../baseRepository';
|
|
4
|
+
export declare class DevicesRepository extends BaseRepository {
|
|
5
|
+
/**
|
|
6
|
+
* Get device by imei
|
|
7
|
+
* @param {GetDeviceByImeiParams} params containing information to get a device by imei
|
|
8
|
+
* - filters.imei: The imei of the device
|
|
9
|
+
* - projectionOptions.withDeviceType: Whether to get the device type object
|
|
10
|
+
* - projectionOptions.withIccidCarrier: Whether to get the iccid carrier object
|
|
11
|
+
*/
|
|
12
|
+
getDeviceByImei(params: GetDeviceByImeiParams): Promise<Device>;
|
|
13
|
+
/**
|
|
14
|
+
* Get devices by type id
|
|
15
|
+
* @param {GetDevicesByDeviceTypeIdParams} params containing information to get devices by type id
|
|
16
|
+
* - filters.deviceTypeId: The device type id
|
|
17
|
+
* - filters.onlyActiveDevices: Whether to get only active devices
|
|
18
|
+
* - projectionOptions.withDeviceType: Whether to get the device type object
|
|
19
|
+
* - projectionOptions.withIccidCarrier: Whether to get the iccid carrier object
|
|
20
|
+
*/
|
|
21
|
+
getDevicesByDeviceTypeId(params: GetDevicesByDeviceTypeIdParams): Promise<Device[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Get device types
|
|
24
|
+
* @param {GetDeviceTypesParams} params containing information to get device types
|
|
25
|
+
* - filters.onlyWithRelatedIccidCarrier: Whether to get only device types with iccid carrier
|
|
26
|
+
*/
|
|
27
|
+
getDeviceTypes(params: GetDeviceTypesParams): Promise<DeviceType[]>;
|
|
28
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DevicesRepository } from './
|
|
2
|
-
import { SecurityRepository } from './
|
|
1
|
+
import { DevicesRepository } from './devices';
|
|
2
|
+
import { SecurityRepository } from './security';
|
|
3
3
|
export { SecurityRepository, DevicesRepository };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { UserSecurityRole } from '../../entities';
|
|
2
|
+
import { NovaDataSource } from '../../novaDataSource';
|
|
3
|
+
import { Logger } from '../../types/logger';
|
|
4
|
+
import { GetUserRolesParams } from '../../types/security';
|
|
5
|
+
export declare const getUserRoles: (novaDataSource: NovaDataSource, params: GetUserRolesParams, logger: Logger) => Promise<UserSecurityRole[]>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { UserSecurityRole } from '../../entities';
|
|
2
|
+
import { NovaDataSource } from '../../novaDataSource';
|
|
3
|
+
import { Logger } from '../../types/logger';
|
|
4
|
+
import { GetUserRolesByClientIdParams } from '../../types/security';
|
|
5
|
+
export declare const getUserRolesByClientId: (novaDataSource: NovaDataSource, params: GetUserRolesByClientIdParams, logger: Logger) => Promise<UserSecurityRole[]>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { SecurityRole, UserSecurityRole } from '../../entities';
|
|
2
|
+
import { GetUserRolesByClientIdParams, GetUserRolesParams, UserIsInRoleParams } from '../../types/security';
|
|
3
|
+
import { BaseRepository } from '../baseRepository';
|
|
4
|
+
export declare class SecurityRepository extends BaseRepository {
|
|
5
|
+
/**
|
|
6
|
+
* Get all security roles
|
|
7
|
+
*/
|
|
8
|
+
getAllRoles(): Promise<SecurityRole[]>;
|
|
9
|
+
/**
|
|
10
|
+
* Get roles of the user
|
|
11
|
+
* @param {GetUserRolesParams} params containing information to get roles of the user
|
|
12
|
+
* - filters.userId: The user id
|
|
13
|
+
*/
|
|
14
|
+
getUserRoles(params: GetUserRolesParams): Promise<UserSecurityRole[]>;
|
|
15
|
+
/**
|
|
16
|
+
* Get user roles by clientId
|
|
17
|
+
* @param {GetUserRolesByClientIdParams} params containing information to get user roles by clientId
|
|
18
|
+
* - filters.clientId: The client id
|
|
19
|
+
* - filters.role: The role to only obtain user roles with that role, optional
|
|
20
|
+
*/
|
|
21
|
+
getUserRolesByClientId(params: GetUserRolesByClientIdParams): Promise<UserSecurityRole[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Whether the user is in role
|
|
24
|
+
* @param {UserIsInRoleParams} params containing information to know if the user is in role
|
|
25
|
+
* - filters.userId: The user id
|
|
26
|
+
* - filters.role: The role to check if the user is in that role
|
|
27
|
+
*/
|
|
28
|
+
userIsInRole(params: UserIsInRoleParams): Promise<boolean>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { NovaDataSource } from '../../novaDataSource';
|
|
2
|
+
import { Logger } from '../../types/logger';
|
|
3
|
+
import { UserIsInRoleParams } from '../../types/security';
|
|
4
|
+
export declare const userIsInRole: (novaDataSource: NovaDataSource, params: UserIsInRoleParams, logger: Logger) => Promise<boolean>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface GetDeviceByImeiParams {
|
|
2
|
+
filters: {
|
|
3
|
+
imei: string;
|
|
4
|
+
};
|
|
5
|
+
projectionOptions: {
|
|
6
|
+
withDeviceType: boolean;
|
|
7
|
+
withIccidCarrier: boolean;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export interface GetDevicesByDeviceTypeIdParams {
|
|
11
|
+
filters: {
|
|
12
|
+
deviceTypeId: number;
|
|
13
|
+
onlyActiveDevices: boolean;
|
|
14
|
+
};
|
|
15
|
+
projectionOptions: {
|
|
16
|
+
withDeviceType: boolean;
|
|
17
|
+
withIccidCarrier: boolean;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface GetDeviceTypesParams {
|
|
21
|
+
filters: {
|
|
22
|
+
onlyWithRelatedIccidCarrier: boolean;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export interface LogFn {
|
|
2
|
+
(msg: string, ...args: any[]): void;
|
|
3
|
+
(obj: object, msg?: string, ...args: any[]): void;
|
|
4
|
+
}
|
|
5
|
+
export interface Logger {
|
|
6
|
+
/**
|
|
7
|
+
* Log at `'fatal'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line.
|
|
8
|
+
* If more args follows `msg`, these will be used to format `msg` using `util.format`.
|
|
9
|
+
*
|
|
10
|
+
* @param obj: object to be serialized
|
|
11
|
+
* @param msg: the log message to write
|
|
12
|
+
* @param ...args: format string values when `msg` is a format string
|
|
13
|
+
*/
|
|
14
|
+
fatal: LogFn;
|
|
15
|
+
/**
|
|
16
|
+
* Log at `'error'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line.
|
|
17
|
+
* If more args follows `msg`, these will be used to format `msg` using `util.format`.
|
|
18
|
+
*
|
|
19
|
+
* @param obj: object to be serialized
|
|
20
|
+
* @param msg: the log message to write
|
|
21
|
+
* @param ...args: format string values when `msg` is a format string
|
|
22
|
+
*/
|
|
23
|
+
error: LogFn;
|
|
24
|
+
/**
|
|
25
|
+
* Log at `'warn'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line.
|
|
26
|
+
* If more args follows `msg`, these will be used to format `msg` using `util.format`.
|
|
27
|
+
*
|
|
28
|
+
* @param obj: object to be serialized
|
|
29
|
+
* @param msg: the log message to write
|
|
30
|
+
* @param ...args: format string values when `msg` is a format string
|
|
31
|
+
*/
|
|
32
|
+
warn: LogFn;
|
|
33
|
+
/**
|
|
34
|
+
* Log at `'info'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line.
|
|
35
|
+
* If more args follows `msg`, these will be used to format `msg` using `util.format`.
|
|
36
|
+
*
|
|
37
|
+
* @param obj: object to be serialized
|
|
38
|
+
* @param msg: the log message to write
|
|
39
|
+
* @param ...args: format string values when `msg` is a format string
|
|
40
|
+
*/
|
|
41
|
+
info: LogFn;
|
|
42
|
+
/**
|
|
43
|
+
* Log at `'debug'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line.
|
|
44
|
+
* If more args follows `msg`, these will be used to format `msg` using `util.format`.
|
|
45
|
+
*
|
|
46
|
+
* @param obj: object to be serialized
|
|
47
|
+
* @param msg: the log message to write
|
|
48
|
+
* @param ...args: format string values when `msg` is a format string
|
|
49
|
+
*/
|
|
50
|
+
debug: LogFn;
|
|
51
|
+
/**
|
|
52
|
+
* Log at `'trace'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line.
|
|
53
|
+
* If more args follows `msg`, these will be used to format `msg` using `util.format`.
|
|
54
|
+
*
|
|
55
|
+
* @param obj: object to be serialized
|
|
56
|
+
* @param msg: the log message to write
|
|
57
|
+
* @param ...args: format string values when `msg` is a format string
|
|
58
|
+
*/
|
|
59
|
+
trace: LogFn;
|
|
60
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { HapnSecurityRole } from './enums';
|
|
2
|
+
export interface GetUserRolesParams {
|
|
3
|
+
filters: {
|
|
4
|
+
userId: string;
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
export interface GetUserRolesByClientIdParams {
|
|
8
|
+
filters: {
|
|
9
|
+
clientId: number;
|
|
10
|
+
role?: HapnSecurityRole;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface UserIsInRoleParams {
|
|
14
|
+
filters: {
|
|
15
|
+
userId: string;
|
|
16
|
+
role: HapnSecurityRole;
|
|
17
|
+
};
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spytecgps/nova-orm",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "ORM with PlanetScale",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"lint-fix": "eslint \"./src/**\" --fix",
|
|
40
40
|
"build-dev": "webpack --mode=development",
|
|
41
41
|
"build": "webpack --mode=production",
|
|
42
|
-
"schema-sync": "yarn typeorm schema:drop --dataSource ./data-source.ts & yarn typeorm schema:sync --dataSource ./data-source.ts"
|
|
42
|
+
"schema-sync": "yarn typeorm schema:drop --dataSource ./data-source.ts & yarn typeorm schema:sync --dataSource ./data-source.ts & yarn typeorm migration:run --dataSource ./data-source.ts"
|
|
43
43
|
},
|
|
44
44
|
"author": "Spytec",
|
|
45
45
|
"license": "ISC",
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Device, DeviceType } from '../entities';
|
|
2
|
-
import { BaseRepository } from './baseRepository';
|
|
3
|
-
export interface GetDevicesOptions {
|
|
4
|
-
withDeviceType: boolean;
|
|
5
|
-
withIccidCarrier: boolean;
|
|
6
|
-
}
|
|
7
|
-
export declare class DevicesRepository extends BaseRepository {
|
|
8
|
-
/**
|
|
9
|
-
* Get device by imei
|
|
10
|
-
* @param {string} imei The imei of the device
|
|
11
|
-
*/
|
|
12
|
-
getDeviceByImei(imei: string, options: GetDevicesOptions): Promise<Device>;
|
|
13
|
-
/**
|
|
14
|
-
* Get devices by type id
|
|
15
|
-
* @param {number} deviceTypeId The device type id
|
|
16
|
-
* @param {boolean} onlyActiveDevices Whether to get only active devices
|
|
17
|
-
*/
|
|
18
|
-
getDevicesByDeviceTypeId(deviceTypeId: number, onlyActiveDevices: boolean, options: GetDevicesOptions): Promise<Device[]>;
|
|
19
|
-
/**
|
|
20
|
-
* Get device types
|
|
21
|
-
* @param {boolean} onlyWithRelatedIccidCarrier Whether to get only device types with iccid carrier
|
|
22
|
-
*/
|
|
23
|
-
getDeviceTypes(onlyWithRelatedIccidCarrier: boolean): Promise<DeviceType[]>;
|
|
24
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { SecurityRole, UserSecurityRole } from '../entities';
|
|
2
|
-
import { HapnSecurityRole } from '../types/enums';
|
|
3
|
-
import { BaseRepository } from './baseRepository';
|
|
4
|
-
export declare class SecurityRepository extends BaseRepository {
|
|
5
|
-
/**
|
|
6
|
-
* Get all security roles
|
|
7
|
-
*/
|
|
8
|
-
getAllRoles(): Promise<SecurityRole[]>;
|
|
9
|
-
/**
|
|
10
|
-
* Get roles of the user
|
|
11
|
-
*/
|
|
12
|
-
getUserRoles(userId: string): Promise<UserSecurityRole[]>;
|
|
13
|
-
/**
|
|
14
|
-
* Get user roles by clientId
|
|
15
|
-
*/
|
|
16
|
-
getUserRolesByClientId(clientId: number, filterRole?: HapnSecurityRole): Promise<UserSecurityRole[]>;
|
|
17
|
-
/**
|
|
18
|
-
* Whether the user is in role
|
|
19
|
-
*/
|
|
20
|
-
isInRole(userId: string, role: HapnSecurityRole): Promise<boolean>;
|
|
21
|
-
}
|