Skip to content

Commit

Permalink
feat(logging): Added Storm logging package
Browse files Browse the repository at this point in the history
  • Loading branch information
sullivanpj committed Nov 15, 2023
1 parent c069cda commit 435748f
Show file tree
Hide file tree
Showing 27 changed files with 1,173 additions and 296 deletions.
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are supported funding model platforms

patreon: StormSoftware
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
"relay.rootDirectory": "../",
"relay.pathToConfig": "@storm-software/graphql-tools/config/relay.config.js",

/******************************
* JSON Schemas
******************************/
"json.schemas": [
{
"url": "https://cdn.jsdelivr.net/npm/tsup/schema.json",
"fileMatch": ["package.json", "tsup.config.json"]
}
],

/******************************
* VS Code Search
******************************/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<br />
<h1>Storm Stack</h1>
⚡ The <b>Storm Stack<b> monorepo contains utility applications, tools, and various libraries to create modern and scalable web applications.
⚡ The <b>Storm Stack</b> monorepo contains utility applications, tools, and various libraries to create modern and scalable web applications.
<br /><br />
⚡ <b>Storm Workspaces</b> are built using <a href="https://nx.dev/" target="_blank">Nx</a>, a set of extensible dev tools for monorepos, which helps you develop like Google, Facebook, and Microsoft. Building on top of Nx, the Open System provides a set of tools and patterns that help you scale your monorepo to many teams while keeping the codebase maintainable.

Expand Down
18 changes: 12 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
"type": "github",
"url": "https://github.com/storm-software/storm-stack.git"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/storm-software"
},
"license": "Apache License 2.0",
"author": {
"name": "Storm Software",
Expand Down Expand Up @@ -71,11 +75,11 @@
"prettier": "@storm-software/linting-tools/prettier/config.json",
"dependencies": {
"@eslint/eslintrc": "^2.1.3",
"@nx/devkit": "^17.1.1",
"@nx/eslint": "^17.1.1",
"@nx/eslint-plugin": "^17.1.1",
"@nx/jest": "^17.1.1",
"@nx/js": "^17.1.1",
"@nx/devkit": "^17.1.2",
"@nx/eslint": "^17.1.2",
"@nx/eslint-plugin": "^17.1.2",
"@nx/jest": "^17.1.2",
"@nx/js": "^17.1.2",
"@nx/workspace": "17.0.3",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/commit-analyzer": "^11.1.0",
Expand Down Expand Up @@ -108,6 +112,7 @@
"prettier-plugin-packagejson": "^2.4.6",
"prettier-plugin-prisma": "^5.0.0",
"semantic-release": "^22.0.7",
"terser": "^5.24.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"tslib": "^2.6.2",
Expand All @@ -133,7 +138,8 @@
"@storm-software/unique-identifier": "workspace:*",
"@storm-software/date-time": "workspace:*",
"@storm-software/errors": "workspace:*",
"@storm-software/serialization": "workspace:*"
"@storm-software/serialization": "workspace:*",
"@storm-software/logging": "workspace:*"
}
},
"triggerEmptyDevReleaseByIncrementingThisNumber": 0
Expand Down
52 changes: 6 additions & 46 deletions packages/date-time/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,14 @@
"version": "0.0.1",
"private": false,
"description": "This package includes a DateTime class, various utility functions for working with dates and times, and a number of formatting options.",
"keywords": [
"storm",
"storm-stack",
"stormstack",
"sullivanpj",
"open-system",
"monorepo"
],
"homepage": "https://stormsoftware.org",
"bugs": {
"url": "https://github.com/storm-software/storm-stack/issues",
"email": "support@stormsoftware.org"
},
"repository": {
"type": "github",
"url": "https://github.com/storm-software/storm-stack.git",
"directory": "packages/date-time"
},
"license": "Apache License 2.0",
"author": {
"name": "Storm Software",
"email": "contact@stormsoftware.org",
"url": "https://stormsoftware.org"
"dependencies": {
"@js-temporal/polyfill": "^0.4.4"
},
"sideEffects": false,
"type": "module",
"exports": {
".": {
"import": {
"types": "./build/modern/index.d.ts",
"default": "./build/modern/index.js"
},
"require": {
"types": "./build/modern/index.d.cts",
"default": "./build/modern/index.cjs"
}
},
"./package.json": "./package.json"
"devDependencies": {
"@storm-software/testing-tools": "latest",
"@storm-software/workspace-tools": "latest"
},
"main": "build/legacy/index.cjs",
"module": "build/legacy/index.js",
"types": "build/legacy/index.d.ts",
"files": [
"build",
"src"
],
"dependencies": {
"@js-temporal/polyfill": "^0.4.4",
"peerDependencies": {
"@storm-software/testing-tools": "latest",
"@storm-software/workspace-tools": "latest"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/errors/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./errors";
export * from "./is-storm-error";
export * from "./storm-error";
export * from "./utilities";
57 changes: 47 additions & 10 deletions packages/errors/src/storm-error.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { JsonObject, Serializable } from "@storm-software/serialization";
import { EMPTY_STRING } from "@storm-software/utilities";
import { EMPTY_STRING, NEWLINE_STRING } from "@storm-software/utilities";
import StackTracey from "stacktracey";
import { ErrorCode } from "./errors";

Expand All @@ -24,6 +24,8 @@ export class StormError<TCode extends string = string> extends Error {
public data?: any;
public innerError?: StormError;

#stack?: string;

public constructor() {
super();

Expand All @@ -33,15 +35,15 @@ export class StormError<TCode extends string = string> extends Error {
public static create<TCode extends string = string>(
code: TCode,
{ name, message, cause, stack, data, innerError }: StormErrorOptions = {
name: "StormError",
message: "An error occurred"
name: "Storm Error",
message: "An error occurred during processing"
}
) {
const error = new StormError();

error.code = code;
error.message ??= message ?? EMPTY_STRING;
error.name ??= name ? name : "StormError";
error.name ??= name ? name : "Storm Error";
stack && (error.stack = stack);
error.cause = cause;
error.data = data;
Expand All @@ -50,17 +52,52 @@ export class StormError<TCode extends string = string> extends Error {
return error;
}

/**
* Prints the stack trace
*
* @returns The stack trace string
*/
public override get stack(): string {
return this.#stack
? `Stack Trace: ${NEWLINE_STRING}${new StackTracey(this.#stack)
.withSources()
.asTable()}`
: EMPTY_STRING;
}

/**
* Store the stack trace
*/
public override set stack(_stack: string) {
this.#stack = _stack;
}

/**
* Prints the display error message string
*
* @returns The display error message string
*/
public get display(): string {
return this.message
? `${
this.name ? (this.code ? this.name + " " : this.name) : EMPTY_STRING
} ${
this.code
? this.code && this.name
? `(${this.code})`
: this.code
: EMPTY_STRING
}${this.code || this.name ? ": " : EMPTY_STRING}${this.message}`
: EMPTY_STRING;
}

/**
* Prints the error message and stack trace
*
* @returns The error message and stack trace string
*/
public override toString(): string {
return `${this.name} (${this.code}): ${this.message}\nStack Trace:\n${
this.stack
? new StackTracey(this.stack).withSources().asTable()
: EMPTY_STRING
}`;
return `${this.display} ${NEWLINE_STRING}Stack Trace: ${NEWLINE_STRING}${this.stack}`;
}

public serialize(): JsonObject {
Expand All @@ -76,7 +113,7 @@ export class StormError<TCode extends string = string> extends Error {
public deserialize(json: JsonObject) {
json?.code && (this.code = json.code as TCode);
json?.message && (this.message = json.message as string);
json?.stack && (this.stack = json.stack as string);
json?.stack && (this.#stack = json.stack as string);
json?.data && (this.data = json.data);

if (json?.innerError) {
Expand Down
1 change: 1 addition & 0 deletions packages/errors/src/utilities/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./is-storm-error";
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { isError } from "@storm-software/utilities/type-checks/is-error";
import { isSetString } from "@storm-software/utilities/type-checks/is-set-string";
import { StormError } from "./storm-error";
import { StormError } from "../storm-error";

/**
* Type-check to determine if `obj` is a `StormError` object
*
* @param obj - the object to check
* @param value - the object to check
* @returns The function isStormError is returning a boolean value.
*/
export function isStormError<TCode extends string = any>(
obj: unknown
): obj is StormError<TCode> {
value: unknown
): value is StormError<TCode> {
return (
isError(obj) &&
isSetString((obj as unknown as StormError<TCode>)?.code) &&
isSetString((obj as unknown as StormError<TCode>)?.message) &&
isSetString((obj as unknown as StormError<TCode>)?.stack)
isError(value) &&
isSetString((value as unknown as StormError<TCode>)?.code) &&
isSetString((value as unknown as StormError<TCode>)?.message) &&
isSetString((value as unknown as StormError<TCode>)?.stack)
);
}

0 comments on commit 435748f

Please sign in to comment.