Skip to content

Commit

Permalink
feat: task runner
Browse files Browse the repository at this point in the history
  • Loading branch information
izatop committed Jun 14, 2023
1 parent b535cfe commit b108fc0
Show file tree
Hide file tree
Showing 248 changed files with 2,143 additions and 462 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@
"license": "MIT",
"private": true,
"devDependencies": {
"@commitlint/cli": "^17.6.3",
"@commitlint/config-conventional": "^17.6.3",
"@types/jest": "^29.2.5",
"@types/node": "^20.2.5",
"@typescript-eslint/eslint-plugin": "^5.59.8",
"@typescript-eslint/parser": "^5.59.8",
"@commitlint/cli": "^17.6.5",
"@commitlint/config-conventional": "^17.6.5",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
"@typescript-eslint/eslint-plugin": "^5.59.11",
"@typescript-eslint/parser": "^5.59.11",
"cross-env": "^7.0.3",
"eslint": "^8.41.0",
"eslint-plugin-import": "^2.26.0",
"eslint": "^8.42.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-unused-imports": "^2.0.0",
"jest": "^29.3.1",
"jest": "^29.5.0",
"lerna": "^6.6.2",
"rimraf": "^5.0.1",
"ts-jest": "^29.0.3",
"typescript": "^5.0.4"
"ts-jest": "^29.1.0",
"typescript": "^5.1.3"
},
"packageManager": "yarn@3.5.1"
}
3 changes: 3 additions & 0 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@
"access": "public"
},
"dependencies": {
"@bunt/assert": "^0.1.0",
"@bunt/async": "^0.26.3",
"@bunt/input": "^0.26.3",
"@bunt/is": "^0.1.0",
"@bunt/unit": "^0.26.3",
"@bunt/util": "^0.26.3",
"@types/busboy": "^1.5.0",
Expand Down
4 changes: 3 additions & 1 deletion packages/app/src/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {
Unit,
unit,
} from "@bunt/unit";
import {assert, isDefined, logger, Logger} from "@bunt/util";
import {logger, Logger} from "@bunt/util";
import {assert} from "@bunt/assert";
import {isDefined} from "@bunt/is";
import {ActionResponse, IRequest} from "./interfaces.js";
import {IRoute, RouteNotFound} from "./Route/index.js";

Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/Payload/Resolver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ActionAny, ActionState} from "@bunt/unit";
import {isFunction, isObject} from "@bunt/util";
import {isFunction, isObject} from "@bunt/is";
import {IRouteContext} from "../Route/index.js";
import {ResolverResolvers} from "./interfaces.js";

Expand Down
4 changes: 3 additions & 1 deletion packages/app/src/Request/HeadersAbstract.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {assert, ILogable, isBoolean, isFunction} from "@bunt/util";
import {isBoolean, isFunction} from "@bunt/is";
import {ILogable} from "@bunt/type";
import {assert} from "@bunt/assert";
import {HeaderAssertValue, IHeaders} from "../interfaces.js";
import {StrictKeyValueMap} from "./StrictKeyValueMap.js";

Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/Request/RequestAbstract.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {ILogable, isFunction, Promisify} from "@bunt/util";
import {ILogable, Promisify} from "@bunt/type";
import {isFunction} from "@bunt/is";
import {Application} from "../Application.js";
import {IHeaders, IKeyValueMap, IRequest, IRequestTransform, RequestTransformType} from "../interfaces.js";
import {
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/Route/Route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {ActionAny, ActionFactory} from "@bunt/unit";
import {ILogable, isFunction, isString} from "@bunt/util";
import {isFunction, isString} from "@bunt/is";
import {ILogable} from "@bunt/type";
import {
IRoute,
IRouteMatcher,
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/Route/RouteNotFound.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {NotFound} from "@bunt/util";
import {NotFound} from "@bunt/assert";

export class RouteNotFound extends NotFound {
constructor(route: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import {randomBytes} from "crypto";
import {tmpdir} from "os";
import {join} from "path";
import {createWriteStream} from "fs";
import {Defer, QueryString} from "@bunt/util";
import {QueryString} from "@bunt/util";
import * as busboy from "busboy";
import {Defer} from "@bunt/async";
import {IRequest} from "../interfaces.js";

export const MultipartFormDataTransform = async <T = unknown>(request: IRequest): Promise<T> => {
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Promisify} from "@bunt/util";
import {Promisify} from "@bunt/type";
import {Application} from "./Application.js";

export type ActionResponse = Error
Expand Down
21 changes: 21 additions & 0 deletions packages/assert/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Artur Bier

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
40 changes: 40 additions & 0 deletions packages/assert/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "@bunt/assert",
"version": "0.1.0",
"keywords": [
"typescript"
],
"author": {
"name": "Artur Bier",
"email": "izatop@gmail.com"
},
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/cjs/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.js"
}
}
},
"files": [
"dist/",
"LICENSE"
],
"description": "Utils",
"repository": "git@github.com:izatop/bunt.git",
"publishConfig": {
"access": "public"
},
"license": "MIT",
"dependencies": {
"@bunt/is": "^0.1.0",
"@bunt/type": "^0.1.0"
}
}
19 changes: 19 additions & 0 deletions packages/assert/src/Exception/AssertionError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {isFunction} from "@bunt/is";
import {ILogable} from "@bunt/type";
import {ValidationError} from "./ValidationError.js";

export class AssertionError extends ValidationError implements ILogable<Record<any, any>> {
public readonly details?: any;

constructor(message?: string, details?: unknown | (() => unknown)) {
super(message || "Assertion fails");

this.details = isFunction(details)
? details()
: details;
}

public getLogValue(): Record<any, any> {
return this.details;
}
}
1 change: 1 addition & 0 deletions packages/assert/src/Exception/NotFound.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class NotFound extends Error {}
1 change: 1 addition & 0 deletions packages/assert/src/Exception/PermissionError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class PermissionError extends Error {}
1 change: 1 addition & 0 deletions packages/assert/src/Exception/ValidationError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class ValidationError extends Error {}
5 changes: 5 additions & 0 deletions packages/assert/src/Exception/functions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {IReadableError} from "./interfaces.js";

export const isReadableError = (error: Error): error is IReadableError & Error => {
return "toSafeJSON" in error && "toSafeString" in error;
};
6 changes: 6 additions & 0 deletions packages/assert/src/Exception/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from "./interfaces.js";
export * from "./PermissionError.js";
export * from "./ValidationError.js";
export * from "./AssertionError.js";
export * from "./NotFound.js";
export * from "./functions.js";
5 changes: 5 additions & 0 deletions packages/assert/src/Exception/interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface IReadableError {
toSafeString(): string;

toSafeJSON(): Record<any, any>;
}
56 changes: 56 additions & 0 deletions packages/assert/src/assert.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {isFunction, isInstanceOf, isString} from "@bunt/is";
import {AssertionError} from "./Exception/index.js";

export type AssertionDetailsAllowType = string | Record<any, any> | null | number;
export type AssertionDetails = (() => AssertionDetailsAllowType) | AssertionDetailsAllowType;
export type AssertionMessage = string | (() => string) | (() => Error);

function createAssertionError(message?: AssertionMessage, details?: AssertionDetails): Error | AssertionError {
const description = isFunction(message) ? message() : message;

return isInstanceOf(description, Error)
? description
: new AssertionError(description, details);
}

export function assert(expr: unknown, message?: AssertionMessage, details?: AssertionDetails): asserts expr {
if (!expr) {
throw createAssertionError(message, details);
}
}

export function validateTrue(result: true | string, details?: AssertionDetails): void {
if (isString(result)) {
throw createAssertionError(result, details);
}
}

export function fails(expr: unknown, message?: AssertionMessage, details?: AssertionDetails): void {
if (expr) {
throw createAssertionError(message, details);
}
}

export function pass<T>(value: unknown, transform: (v: any) => T, validator: (v: any) => boolean, label?: string): T {
assert(value, `${label || "Value"} should be defined`);

const nextValue = transform(value);
assert(
validator(nextValue),
`This ${label || "value"} "${nextValue}" should pass the validation stage: ${validator.toString()}`,
);

return nextValue;
}

export function toError(error: unknown, alt: Error | string = "Unexpected error"): Error {
if (error instanceof Error) {
return error;
}

if (typeof alt === "string") {
return new Error(alt);
}

return alt;
}
2 changes: 2 additions & 0 deletions packages/assert/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./Exception/index.js";
export * from "./assert";
8 changes: 8 additions & 0 deletions packages/assert/test/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
transform: {"src/.+\\.[jt]s?$": ["ts-jest", {}]},
moduleNameMapper: {
"^([\\.]+\\/.+)\\/index\\.js": "$1",
"^([\\.]+\\/.+)\\.js": "$1",
},
rootDir: "src",
};
6 changes: 6 additions & 0 deletions packages/assert/test/src/assert.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {assert} from "../../src";

test("assert", () => {
expect(() => assert(false)).toThrow();
expect(() => assert(true)).not.toThrow();
});
7 changes: 7 additions & 0 deletions packages/assert/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../../tsconfig.test.json",
"include": [
"src",
"../src"
]
}
20 changes: 20 additions & 0 deletions packages/assert/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "../../tsconfig.lib.json",
"compilerOptions": {
"module": "esnext",
"moduleResolution": "nodenext",
"rootDir": "src",
"outDir": "dist/esm"
},
"references": [
{
"path": "../type"
},
{
"path": "../is"
}
],
"include": [
"src"
]
}
18 changes: 18 additions & 0 deletions packages/assert/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "../../tsconfig.lib.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist/cjs"
},
"references": [
{
"path": "../type"
},
{
"path": "../is"
}
],
"include": [
"src"
]
}
2 changes: 2 additions & 0 deletions packages/async/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"description": "Async utils",
"repository": "git@github.com:izatop/bunt.git",
"dependencies": {
"@bunt/assert": "^0.1.0",
"@bunt/is": "^0.1.0",
"@bunt/util": "^0.26.3"
},
"publishConfig": {
Expand Down
2 changes: 1 addition & 1 deletion packages/async/src/AsyncIteratorFactory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {isUndefined} from "@bunt/util";
import {isUndefined} from "@bunt/is";
import {AsyncPool} from "./AsyncPool.js";

export type AsyncIteratorFactoryControl<T> = {
Expand Down
2 changes: 1 addition & 1 deletion packages/async/src/AsyncPool.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {assert} from "@bunt/util";
import {assert} from "@bunt/assert";
import {Defer} from "./Defer.js";

export interface IAsyncPushPullOptions {
Expand Down
2 changes: 1 addition & 1 deletion packages/async/src/AsyncState.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {isDefined} from "@bunt/util";
import {isDefined} from "@bunt/is";

export interface IAsyncStateMap<T> {
resolve: (value: T | PromiseLike<T>) => void;
Expand Down
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
},
"dependencies": {
"@bunt/app": "^0.26.3",
"@bunt/assert": "^0.1.0",
"@bunt/util": "^0.26.3",
"path-to-regexp": "^6.2.1"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/Request/RequestCommand.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {KeyValueMap, RequestAbstract} from "@bunt/app";
import {Argv, assert} from "@bunt/util";
import {Argv} from "@bunt/util";
import {assert} from "@bunt/assert";
import {Headers} from "./Headers.js";

export class RequestCommand extends RequestAbstract {
Expand Down

0 comments on commit b108fc0

Please sign in to comment.