Skip to content

Commit

Permalink
feat(logging): create StarkLogging module. Fixed imports
Browse files Browse the repository at this point in the history
  • Loading branch information
tenretC committed Mar 29, 2018
1 parent 21d067e commit f3684db
Show file tree
Hide file tree
Showing 35 changed files with 1,601 additions and 211 deletions.
5 changes: 5 additions & 0 deletions packages/stark-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@
"dependencies": {
"@types/core-js": "0.9.46",
"@types/node": "6.0.102",
"@types/uuid": "3.4.3",
"@ngrx/store": "5.2.0",
"cerialize": "0.1.18",
"class-validator": "0.7.3",
"core-js": "2.5.3",
"deep-freeze-strict": "1.1.1",
"moment": "2.21.0",
"rxjs": "5.5.6",
"typescript": "2.6.2",
"uuid": "3.2.1",
"zone.js": "0.8.20"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/stark-core/src/common/store/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { StarkCoreApplicationState } from "./starkCoreApplicationState";
25 changes: 25 additions & 0 deletions packages/stark-core/src/common/store/starkCoreApplicationState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Interface defining the shape of the application state of Stark Core (i.e., what's stored in Redux by Stark)
*/
import { StarkLogging } from "../../logging/entities/index";
// import {StarkSession} from "../../session/entities";
// import {StarkSettings} from "../../settings/entities";

export interface StarkCoreApplicationState
extends StarkLoggingApplicationState /*, StarkSessionApplicationState, StarkSettingsApplicationState*/ {
// starkApplicationMetadata: StarkApplicationMetadata;
// starkLogging: StarkLogging;
// starkSession: StarkSession;
// starkSettings: StarkSettings;
// starkUser: StarkUser; // not stored in Redux
}
export interface StarkLoggingApplicationState {
starkLogging: StarkLogging;
}

// export interface StarkSessionApplicationState {
// starkSession: StarkSession;
// }
// export interface StarkSettingsApplicationState {
// starkSettings: StarkSettings;
// }
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
"use strict";

import { StarkBackend } from "../../../http/entities/backend";

export const starkAppConfigConstantName: string = "StarkAppConfig";
/**
* Minimal set of configuration options for Stark applications.
* An implementation should be instantiated and be available under the name defined in the constants.
*/
export interface StarkApplicationConfig {
/**
* Url of the state defined as root of the router state tree definition
*/
rootStateUrl: string;

/**
* Name of the state defined as root of the router state tree definition
*/
rootStateName: string;

/**
* Name of the state defined as home (homepage)
*/
homeStateName: string;

/**
* Name of the state to be navigated to on generic errors
*/
errorStateName: string;

/**
* Enable Angular's debug runtime information
* @link https://docs.angularjs.org/guide/production#disabling-debug-data
* @link https://docs.angularjs.org/api/ng/provider/$compileProvider#debugInfoEnabled
*/
angularDebugInfoEnabled: boolean;

/**
* Enable logging of debug level messages
*/
debugLoggingEnabled: boolean;

/**
* When the number of log messages reaches the loggingFlushPersistSize value,
* the log messages are sent to the back-end and removed from the redux store.
* Default: 15
*/
loggingFlushPersistSize: number;

/**
* The loggingFlushApplicationId uniquely identifies the application.
* It makes that the back-end can recognize your application.
*/
loggingFlushApplicationId: string;

/**
* The loggingFlushResourceName defines the name of the logging resource on the back-end. Default: "logging"
*/
loggingFlushResourceName: string;

/**
* Enable router logging
*/
routerLoggingEnabled: boolean;

/**
* Timeout period before the session is ended if no user interaction occurs
*/
sessionTimeout: number;

/**
* Seconds before the session is ended (due to no user interaction) when the timeout warning event will be emitted.
* Default: 15
*/
sessionTimeoutWarningPeriod: number;

/**
* Interval in seconds between every "keepalive" ping. Default: 15
*/
keepAliveInterval: number;

/**
* Url where the "keepalive" pings should be sent to
*/
keepAliveUrl: string;

/**
* Url to be navigated to logout the user
*/
logoutUrl: string;

/**
* Base Url of the application
*/
baseUrl: string;

/**
* The language to be used as default.
* If a translation key is not found in the current language, the one from the default language is used as fallback
*/
defaultLanguage: string;

/**
* Whether the application is public or private.
* Public applications don't require authentication and usually provide read-only access to information
*/
publicApp: boolean;

/**
* Option to disable the logging flush if it not needed for the application.
* default: false
*/
loggingFlushDisabled?: boolean;

/**
* Option to disable the keepAlive if it not needed for the application.
* default: false
*/
keepAliveDisabled?: boolean;

/**
* Backends that the application will interact to.
*/
backends: Map<string, StarkBackend>;

/**
* Get a back-end by name
* @param name name of the back-end object to get
* @returns StarkBackend The requested backend
*/
getBackend(name: string): StarkBackend;

/**
* Add a back-end
* @param backend back-end object to add
*/
addBackend(backend: StarkBackend): void;

/**
* Define all back-ends
* @param backends the array of back-end objects
*/
setBackends(backends: StarkBackend[]): void;

/***
* Get all currently defined back-end objects
* @returns Map<string,StarkBackend> A Map containing the different backends
*/
getBackends(): Map<string, StarkBackend>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
"use strict";

import { IsBoolean, IsDefined, IsNotEmpty, IsNumber, IsString, IsUrl, Matches, Min, /* ValidateIf,*/ validateSync } from "class-validator";
import { autoserialize, autoserializeAs } from "cerialize";
import { StarkApplicationConfig } from "./app-config.entity.intf";
import { StarkBackend, StarkBackendImpl } from "../../../http/entities/backend/index";
import { stringMap } from "../../../serialization/index";
import { StarkValidationErrorsUtil } from "../../../util/index";
// import {StarkMapIsValid, StarkMapNotEmpty} from "../../../validation/decorators";

export class StarkApplicationConfigImpl implements StarkApplicationConfig {
@IsDefined()
@IsString()
@autoserialize
public rootStateUrl: string;

@IsDefined()
@IsString()
@autoserialize
public rootStateName: string;

@IsDefined()
@IsString()
@autoserialize
public homeStateName: string;

@IsDefined()
@IsString()
@autoserialize
public errorStateName: string;

@IsDefined()
@IsBoolean()
@autoserialize
public angularDebugInfoEnabled: boolean;

@IsDefined()
@IsBoolean()
@autoserialize
public debugLoggingEnabled: boolean;

@IsNumber()
@Min(1)
@autoserialize
public loggingFlushPersistSize: number;

@IsDefined()
@IsString()
@autoserialize
public loggingFlushApplicationId: string;

@IsDefined()
@IsString()
@autoserialize
public loggingFlushResourceName: string;

@IsDefined()
@IsBoolean()
@autoserialize
public routerLoggingEnabled: boolean;

@IsNotEmpty()
@IsString()
@Matches(/^[a-z]{2}$/)
@autoserialize
public defaultLanguage: string;

@IsDefined()
@IsNumber()
@autoserialize
public sessionTimeout: number;

@IsNumber()
@autoserialize
public sessionTimeoutWarningPeriod: number;

@IsNumber()
@autoserialize
public keepAliveInterval: number;

// @ValidateIf((keepAliveUrl: string) => typeof keepAliveUrl === "string")
@IsUrl()
@autoserialize
public keepAliveUrl: string;

@IsDefined()
@IsUrl()
@autoserialize
public logoutUrl: string;

@IsNotEmpty()
@IsString()
@autoserialize
public baseUrl: string;

@IsDefined()
@IsBoolean()
@autoserialize
public publicApp: boolean;

// @ValidateIf((loggingFlushDisabled: boolean) => typeof loggingFlushDisabled === "boolean")
@IsBoolean()
@autoserialize
public loggingFlushDisabled: boolean;

// @ValidateIf((keepAliveDisabled: boolean) => typeof keepAliveDisabled === "boolean")
@IsBoolean()
@autoserialize
public keepAliveDisabled: boolean;
//FIXME Import StarkMapIsValid & StarkMapNotEmpty from validation/decorators
// @StarkMapNotEmpty()
// @StarkMapIsValid()
@autoserializeAs(stringMap(StarkBackendImpl)) // using custom serialization type (stringMap) to handle ES6 Maps
public backends: Map<string, StarkBackend> = new Map<string, StarkBackend>();

public constructor() {
// Default values
// FIXME: DEVELOPMENT env variable?
/*if (DEVELOPMENT) {
this.loggingFlushPersistSize = 500;
} else {*/
this.loggingFlushPersistSize = 15;
// }

this.loggingFlushResourceName = "logging";
this.sessionTimeoutWarningPeriod = 15;
this.keepAliveInterval = 15;
}

public addBackend(backend: StarkBackend): void {
if (!backend) {
throw new Error("A backend instance must be provided");
}

StarkValidationErrorsUtil.throwOnError(validateSync(backend), "The backend instance provided is not valid.");

this.backends.set(backend.name, backend);
}

public setBackends(backends: StarkBackend[]): void {
this.backends = new Map<string, StarkBackend>();

for (const backend of backends) {
this.addBackend(backend);
}
}

public getBackend(name: string): StarkBackend {
const backend: StarkBackend | undefined = this.backends.get(name);
if (backend === undefined) {
throw new Error("Backend " + name + " is undefined.");
}
return backend;
}

public getBackends(): Map<string, StarkBackend> {
return this.backends;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";

export * from "./app-config.entity.intf";
export * from "./app-config.entity";
1 change: 1 addition & 0 deletions packages/stark-core/src/configuration/entities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

export * from "./language/index";
export * from "./metadata/index";
export * from "./application/index";
2 changes: 1 addition & 1 deletion packages/stark-core/src/http/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export * from "./entities/index";
export * from "./enumerators/index";
export * from "./repository/index";
export * from "./serializer/index";
export * from "./service/index";
export * from "./services/index";
export * from "./http.module";
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
StarkResource,
StarkSingleItemResponseWrapper
} from "../entities/index";
import { StarkHttpService } from "../service/http.service.intf";
import { StarkHttpService } from "../services/http.service.intf";
import { StarkLoggingService } from "../../logging";
import { UnitTestingUtils } from "../../test/unit-testing/index";
import { StarkHttpRequestBuilderImpl } from "../builder/index";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
StarkHttpSearchRequestParams,
StarkHttpUpdateRequestParams
} from "../builder/index";
import { StarkHttpService } from "../service/http.service.intf";
import { StarkHttpService } from "../services/http.service.intf";
import { StarkLoggingService } from "../../logging/index";
import { StarkSerializable } from "../../serialization/index";
import { StarkHttpSerializer, StarkHttpSerializerImpl } from "../serializer/index";
Expand Down

0 comments on commit f3684db

Please sign in to comment.