@furystack/core
Advanced tools
Comparing version 1.0.4 to 1.0.6
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -26,79 +18,45 @@ const fs_1 = require("fs"); | ||
this.saveInProgress = false; | ||
this.get = (key) => __awaiter(this, void 0, void 0, function* () { return this.cache.get(key); }); | ||
this.filter = (filter) => __awaiter(this, void 0, void 0, function* () { | ||
return [...this.cache.values()].filter((item) => { | ||
for (const key in filter) { | ||
if (filter[key] !== item[key]) { | ||
return false; | ||
} | ||
this.get = async (key) => this.cache.get(key); | ||
this.filter = async (filter) => [...this.cache.values()].filter((item) => { | ||
for (const key in filter) { | ||
if (filter[key] !== item[key]) { | ||
return false; | ||
} | ||
return true; | ||
}); | ||
}); | ||
} | ||
remove(key) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.cache.delete(key); | ||
this.hasChanges = true; | ||
}); | ||
} | ||
add(data) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this.cache.has(data[this.primaryKey])) { | ||
throw new Error("Item with the same key already exists"); | ||
} | ||
this.update(data[this.primaryKey], data); | ||
return data; | ||
return true; | ||
}); | ||
} | ||
count() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.cache.size; | ||
}); | ||
async remove(key) { | ||
this.cache.delete(key); | ||
this.hasChanges = true; | ||
} | ||
saveChanges() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this.saveInProgress || !this.hasChanges) { | ||
return; | ||
} | ||
this.saveInProgress = true; | ||
const values = []; | ||
for (const key of this.cache.keys()) { | ||
values.push(this.cache.get(key)); | ||
} | ||
try { | ||
yield new Promise((resolve, reject) => { | ||
this.writeFile(this.fileName, JSON.stringify(values), (error) => { | ||
if (!error) { | ||
resolve(); | ||
} | ||
else { | ||
this.logger.Error({ | ||
scope: this.LogScope, | ||
message: "Error when saving store data to file:", | ||
data: { error }, | ||
}); | ||
reject(error); | ||
} | ||
}); | ||
}); | ||
this.hasChanges = false; | ||
} | ||
finally { | ||
this.saveInProgress = false; | ||
} | ||
}); | ||
async add(data) { | ||
if (this.cache.has(data[this.primaryKey])) { | ||
throw new Error("Item with the same key already exists"); | ||
} | ||
this.update(data[this.primaryKey], data); | ||
return data; | ||
} | ||
dispose() { | ||
this.saveChanges(); | ||
clearInterval(this.tick); | ||
async count() { | ||
return this.cache.size; | ||
} | ||
reloadData() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield new Promise((resolve, reject) => { | ||
this.readFile(this.fileName, (error, data) => { | ||
if (error) { | ||
async saveChanges() { | ||
if (this.saveInProgress || !this.hasChanges) { | ||
return; | ||
} | ||
this.saveInProgress = true; | ||
const values = []; | ||
for (const key of this.cache.keys()) { | ||
values.push(this.cache.get(key)); | ||
} | ||
try { | ||
await new Promise((resolve, reject) => { | ||
this.writeFile(this.fileName, JSON.stringify(values), (error) => { | ||
if (!error) { | ||
resolve(); | ||
} | ||
else { | ||
this.logger.Error({ | ||
scope: this.LogScope, | ||
message: "Error when loading store data from file:", | ||
message: "Error when saving store data to file:", | ||
data: { error }, | ||
@@ -108,22 +66,42 @@ }); | ||
} | ||
else { | ||
this.cache.clear(); | ||
const json = JSON.parse(data.toString()); | ||
for (const user of json) { | ||
this.cache.set(user[this.primaryKey], user); | ||
} | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
}); | ||
this.hasChanges = false; | ||
} | ||
finally { | ||
this.saveInProgress = false; | ||
} | ||
} | ||
update(id, data) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.cache.set(id, data); | ||
this.hasChanges = true; | ||
dispose() { | ||
this.saveChanges(); | ||
clearInterval(this.tick); | ||
} | ||
async reloadData() { | ||
await new Promise((resolve, reject) => { | ||
this.readFile(this.fileName, (error, data) => { | ||
if (error) { | ||
this.logger.Error({ | ||
scope: this.LogScope, | ||
message: "Error when loading store data from file:", | ||
data: { error }, | ||
}); | ||
reject(error); | ||
} | ||
else { | ||
this.cache.clear(); | ||
const json = JSON.parse(data.toString()); | ||
for (const user of json) { | ||
this.cache.set(user[this.primaryKey], user); | ||
} | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
} | ||
async update(id, data) { | ||
this.cache.set(id, data); | ||
this.hasChanges = true; | ||
} | ||
} | ||
exports.FileStore = FileStore; | ||
//# sourceMappingURL=FileStore.js.map |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -20,3 +12,3 @@ const inject_1 = require("@furystack/inject"); | ||
this.LogScope = "@furystack/core/" + this.constructor.name; | ||
this.options = Object.assign({}, exports.defaultFuryStackOptions, options); | ||
this.options = { ...exports.defaultFuryStackOptions, ...options }; | ||
this.injector = new inject_1.Injector({ parent: this.options.injectorParent, owner: this }); | ||
@@ -27,27 +19,23 @@ this.injector.SetInstance(this.injector); | ||
} | ||
dispose() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.logger.Debug({ | ||
scope: this.LogScope, | ||
message: `Disposing ${this.constructor.name}.`, | ||
}); | ||
yield this.apis.map((api) => api.dispose()); | ||
this.logger.Debug({ | ||
scope: this.LogScope, | ||
message: `Disposing ${this.constructor.name} finished.`, | ||
}); | ||
async dispose() { | ||
this.logger.Debug({ | ||
scope: this.LogScope, | ||
message: `Disposing ${this.constructor.name}.`, | ||
}); | ||
await this.apis.map((api) => api.dispose()); | ||
this.logger.Debug({ | ||
scope: this.LogScope, | ||
message: `Disposing ${this.constructor.name} finished.`, | ||
}); | ||
} | ||
start() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.logger.Debug({ | ||
scope: this.LogScope, | ||
message: `Starting ${this.constructor.name}.`, | ||
}); | ||
yield this.apis.map((api) => api.activate()); | ||
this.logger.Debug({ | ||
scope: this.LogScope, | ||
message: `Starting ${this.constructor.name} finished.`, | ||
}); | ||
async start() { | ||
this.logger.Debug({ | ||
scope: this.LogScope, | ||
message: `Starting ${this.constructor.name}.`, | ||
}); | ||
await this.apis.map((api) => api.activate()); | ||
this.logger.Debug({ | ||
scope: this.LogScope, | ||
message: `Starting ${this.constructor.name} finished.`, | ||
}); | ||
} | ||
@@ -54,0 +42,0 @@ } |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -18,37 +10,27 @@ const Loggers_1 = require("./Loggers"); | ||
this.cache = new Map(); | ||
this.get = (key) => __awaiter(this, void 0, void 0, function* () { return this.cache.get(key); }); | ||
this.filter = (filter) => __awaiter(this, void 0, void 0, function* () { | ||
return [...this.cache.values()].filter((item) => { | ||
for (const key in filter) { | ||
if (filter[key] !== item[key]) { | ||
return false; | ||
} | ||
this.get = async (key) => this.cache.get(key); | ||
this.filter = async (filter) => [...this.cache.values()].filter((item) => { | ||
for (const key in filter) { | ||
if (filter[key] !== item[key]) { | ||
return false; | ||
} | ||
return true; | ||
}); | ||
} | ||
return true; | ||
}); | ||
} | ||
remove(key) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.cache.delete(key); | ||
}); | ||
async remove(key) { | ||
this.cache.delete(key); | ||
} | ||
add(data) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this.cache.has(data[this.primaryKey])) { | ||
throw new Error("Item with the primary key already exists."); | ||
} | ||
this.cache.set(data[this.primaryKey], data); | ||
return data; | ||
}); | ||
async add(data) { | ||
if (this.cache.has(data[this.primaryKey])) { | ||
throw new Error("Item with the primary key already exists."); | ||
} | ||
this.cache.set(data[this.primaryKey], data); | ||
return data; | ||
} | ||
count() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.cache.size; | ||
}); | ||
async count() { | ||
return this.cache.size; | ||
} | ||
update(id, data) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.cache.set(id, data); | ||
}); | ||
async update(id, data) { | ||
this.cache.set(id, data); | ||
} | ||
@@ -55,0 +37,0 @@ dispose() { |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -18,64 +10,71 @@ const ILogEntries_1 = require("../Models/ILogEntries"); | ||
constructor(options) { | ||
this.options = Object.assign({}, exports.defaultLoggerOptions, options); | ||
this.options = { | ||
...exports.defaultLoggerOptions, | ||
...options, | ||
}; | ||
} | ||
addEntryInternal(entry) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this.options.filter(entry)) { | ||
return; | ||
} | ||
try { | ||
yield this.AddEntry(entry); | ||
} | ||
catch (error) { | ||
this.Error({ | ||
scope: exports.AbstractLoggerScope, | ||
message: "There was an error adding entry to the log", | ||
data: { | ||
entry, | ||
error, | ||
}, | ||
}); | ||
} | ||
}); | ||
async addEntryInternal(entry) { | ||
if (!this.options.filter(entry)) { | ||
return; | ||
} | ||
try { | ||
await this.AddEntry(entry); | ||
} | ||
catch (error) { | ||
this.Error({ | ||
scope: exports.AbstractLoggerScope, | ||
message: "There was an error adding entry to the log", | ||
data: { | ||
entry, | ||
error, | ||
}, | ||
}); | ||
} | ||
} | ||
Verbose(entry) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.addEntryInternal(Object.assign({}, entry, { level: ILogEntries_1.LogLevel.Verbose })); | ||
async Verbose(entry) { | ||
await this.addEntryInternal({ | ||
...entry, | ||
level: ILogEntries_1.LogLevel.Verbose, | ||
}); | ||
} | ||
Debug(entry) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.addEntryInternal(Object.assign({}, entry, { level: ILogEntries_1.LogLevel.Debug })); | ||
async Debug(entry) { | ||
await this.addEntryInternal({ | ||
...entry, | ||
level: ILogEntries_1.LogLevel.Debug, | ||
}); | ||
} | ||
Information(entry) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.addEntryInternal(Object.assign({}, entry, { level: ILogEntries_1.LogLevel.Information })); | ||
async Information(entry) { | ||
await this.addEntryInternal({ | ||
...entry, | ||
level: ILogEntries_1.LogLevel.Information, | ||
}); | ||
} | ||
Warning(entry) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.addEntryInternal(Object.assign({}, entry, { level: ILogEntries_1.LogLevel.Warning })); | ||
async Warning(entry) { | ||
await this.addEntryInternal({ | ||
...entry, | ||
level: ILogEntries_1.LogLevel.Warning, | ||
}); | ||
} | ||
Error(entry) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
yield this.AddEntry(Object.assign({}, entry, { level: ILogEntries_1.LogLevel.Error })); | ||
} | ||
catch (error) { | ||
yield this.Fatal({ | ||
scope: exports.AbstractLoggerScope, | ||
message: "There was an error persisting an Error event in the log and therefore the event was elevated to Fatal level.", | ||
data: { | ||
originalEntry: entry, | ||
error, | ||
}, | ||
}); | ||
} | ||
}); | ||
async Error(entry) { | ||
try { | ||
await this.AddEntry({ | ||
...entry, | ||
level: ILogEntries_1.LogLevel.Error, | ||
}); | ||
} | ||
catch (error) { | ||
await this.Fatal({ | ||
scope: exports.AbstractLoggerScope, | ||
message: "There was an error persisting an Error event in the log and therefore the event was elevated to Fatal level.", | ||
data: { | ||
originalEntry: entry, | ||
error, | ||
}, | ||
}); | ||
} | ||
} | ||
Fatal(entry) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.AddEntry(Object.assign({}, entry, { level: ILogEntries_1.LogLevel.Fatal })); | ||
async Fatal(entry) { | ||
await this.AddEntry({ | ||
...entry, | ||
level: ILogEntries_1.LogLevel.Fatal, | ||
}); | ||
@@ -82,0 +81,0 @@ } |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -53,12 +45,14 @@ const ILogEntries_1 = require("../Models/ILogEntries"); | ||
super(options); | ||
this.options = Object.assign({}, AbstractLogger_1.defaultLoggerOptions, { | ||
formatter: exports.defaultFormatter, | ||
}, options); | ||
this.options = { | ||
...AbstractLogger_1.defaultLoggerOptions, | ||
...{ | ||
formatter: exports.defaultFormatter, | ||
}, | ||
...options, | ||
}; | ||
} | ||
AddEntry(entry) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const data = this.options.formatter(entry); | ||
// tslint:disable-next-line:no-console | ||
console.log(...data); | ||
}); | ||
async AddEntry(entry) { | ||
const data = this.options.formatter(entry); | ||
// tslint:disable-next-line:no-console | ||
console.log(...data); | ||
} | ||
@@ -65,0 +59,0 @@ } |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -17,7 +9,5 @@ const AbstractLogger_1 = require("./AbstractLogger"); | ||
} | ||
AddEntry(entry) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const promises = this.loggers.filter((l) => l.options.filter(entry)).map((l) => l.AddEntry(entry)); | ||
yield Promise.all(promises); | ||
}); | ||
async AddEntry(entry) { | ||
const promises = this.loggers.filter((l) => l.options.filter(entry)).map((l) => l.AddEntry(entry)); | ||
await Promise.all(promises); | ||
} | ||
@@ -24,0 +14,0 @@ attachLogger(...loggers) { |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -17,6 +9,4 @@ const AbstractLogger_1 = require("./AbstractLogger"); | ||
} | ||
AddEntry(entry) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.onAddEntry(entry); | ||
}); | ||
async AddEntry(entry) { | ||
await this.onAddEntry(entry); | ||
} | ||
@@ -23,0 +13,0 @@ } |
{ | ||
"name": "@furystack/core", | ||
"version": "1.0.4", | ||
"version": "1.0.6", | ||
"description": "Core FuryStack package", | ||
@@ -13,6 +13,6 @@ "main": "dist/index.js", | ||
"commit": "git-cz", | ||
"pretest": "tslint --project tsconfig.test.json && rimraf temp && tsc -p tsconfig.test.json", | ||
"test": "rimraf coverage && nyc mocha -p tsconfig.test.json ./temp/test/index.js", | ||
"test": "jest", | ||
"prebuild": "tslint --project tsconfig.json", | ||
"build": "rimraf dist && tsc -p tsconfig.json", | ||
"clean": "rimraf dist && rimraf coverage", | ||
"build": "tsc -b", | ||
"prepublishOnly": "npm run test && npm run build", | ||
@@ -59,13 +59,10 @@ "publish:development": "npm run build && npm t && npm run typedoc && npm publish --tag development", | ||
"dependencies": { | ||
"@furystack/inject": "^1.0.1", | ||
"@sensenet/client-utils": "^1.2.1", | ||
"@types/node": "^10.12.5" | ||
"@furystack/inject": "^1.0.5", | ||
"@sensenet/client-utils": "^1.2.1" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^4.1.7", | ||
"@types/mocha": "^5.2.5", | ||
"chai": "^4.2.0", | ||
"mocha": "^5.2.0", | ||
"nyc": "^13.1.0", | ||
"@types/jest": "^23.3.9", | ||
"jest": "^23.6.0", | ||
"rimraf": "^2.6.1", | ||
"ts-jest": "^23.10.4", | ||
"tslint": "^5.11.0", | ||
@@ -79,3 +76,4 @@ "typescript": "^3.1.6" | ||
}, | ||
"typings": "./dist/index.d.ts" | ||
"typings": "./dist/index.d.ts", | ||
"gitHead": "d4c394442cdc67c7ba1ae87225c0181336454e70" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2
6
81880
1273
- Removed@types/node@^10.12.5
- Removed@types/node@10.17.60(transitive)
Updated@furystack/inject@^1.0.5