@spytecgps/nova-orm 0.0.10 → 0.0.12

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.
@@ -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
- constructor(config: NovaDataSourceConfig);
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
- constructor(config: NovaDataSourceConfig);
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 './devicesRepository';
2
- import { SecurityRepository } from './securityRepository';
1
+ import { DevicesRepository } from './devices';
2
+ import { SecurityRepository } from './security';
3
3
  export { SecurityRepository, DevicesRepository };
@@ -0,0 +1,4 @@
1
+ import { SecurityRole } from '../../entities';
2
+ import { NovaDataSource } from '../../novaDataSource';
3
+ import { Logger } from '../../types/logger';
4
+ export declare const getAllRoles: (novaDataSource: NovaDataSource, logger: Logger) => Promise<SecurityRole[]>;
@@ -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,4 @@
1
+ import * as Devices from './devices';
2
+ import * as Logger from './logger';
3
+ import * as Security from './security';
4
+ export { Logger, Devices, Security };
@@ -0,0 +1,68 @@
1
+ export interface LogFn {
2
+ (msg: string, ...args: any[]): void;
3
+ (obj: object, msg?: string, ...args: any[]): void;
4
+ }
5
+ export declare enum LogLevel {
6
+ FATAL = "fatal",
7
+ ERROR = "error",
8
+ WARN = "warn",
9
+ INFO = "info",
10
+ DEBUG = "debug",
11
+ TRACE = "trace"
12
+ }
13
+ export interface Logger {
14
+ /**
15
+ * Log at `'fatal'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line.
16
+ * If more args follows `msg`, these will be used to format `msg` using `util.format`.
17
+ *
18
+ * @param obj: object to be serialized
19
+ * @param msg: the log message to write
20
+ * @param ...args: format string values when `msg` is a format string
21
+ */
22
+ fatal: LogFn;
23
+ /**
24
+ * Log at `'error'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line.
25
+ * If more args follows `msg`, these will be used to format `msg` using `util.format`.
26
+ *
27
+ * @param obj: object to be serialized
28
+ * @param msg: the log message to write
29
+ * @param ...args: format string values when `msg` is a format string
30
+ */
31
+ error: LogFn;
32
+ /**
33
+ * Log at `'warn'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line.
34
+ * If more args follows `msg`, these will be used to format `msg` using `util.format`.
35
+ *
36
+ * @param obj: object to be serialized
37
+ * @param msg: the log message to write
38
+ * @param ...args: format string values when `msg` is a format string
39
+ */
40
+ warn: LogFn;
41
+ /**
42
+ * Log at `'info'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line.
43
+ * If more args follows `msg`, these will be used to format `msg` using `util.format`.
44
+ *
45
+ * @param obj: object to be serialized
46
+ * @param msg: the log message to write
47
+ * @param ...args: format string values when `msg` is a format string
48
+ */
49
+ info: LogFn;
50
+ /**
51
+ * Log at `'debug'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line.
52
+ * If more args follows `msg`, these will be used to format `msg` using `util.format`.
53
+ *
54
+ * @param obj: object to be serialized
55
+ * @param msg: the log message to write
56
+ * @param ...args: format string values when `msg` is a format string
57
+ */
58
+ debug: LogFn;
59
+ /**
60
+ * Log at `'trace'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line.
61
+ * If more args follows `msg`, these will be used to format `msg` using `util.format`.
62
+ *
63
+ * @param obj: object to be serialized
64
+ * @param msg: the log message to write
65
+ * @param ...args: format string values when `msg` is a format string
66
+ */
67
+ trace: LogFn;
68
+ }
@@ -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
+ }
@@ -0,0 +1,2 @@
1
+ import { Logger, LogLevel } from '../types/logger';
2
+ export declare const writeToLog: (logger: Logger, level: LogLevel, obj: any, message: string) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spytecgps/nova-orm",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "description": "ORM with PlanetScale",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -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
- }