Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@artus/pipeline

Package Overview
Dependencies
Maintainers
7
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@artus/pipeline - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

6

dist/base.d.ts

@@ -15,4 +15,4 @@ import type { ExecutionContainer } from '@artus/injection';

export declare class Context implements BaseContext {
input: BaseInput;
output: BaseOutput;
input: Input;
output: Output;
private _container;

@@ -26,3 +26,3 @@ private storageMap;

}
export declare type Middleware = (context: Context, next: Next) => void;
export declare type Middleware<T extends BaseContext = any> = (context: T, next: Next) => void;
export declare type Middlewares = Middleware[];

@@ -29,0 +29,0 @@ export declare type PipelineLike = {

@@ -1,9 +0,10 @@

import { Context, Middlewares, MiddlewareInput, PipelineLike } from "./base";
import { Middlewares, MiddlewareInput, PipelineLike } from './base';
import { BaseContext } from './types';
export declare class Pipeline implements PipelineLike {
middlewares: Middlewares;
use(middleware: MiddlewareInput): void;
dispatch(i: number, ctx: Context, execution?: {
dispatch(i: number, ctx: BaseContext, execution?: {
index: number;
}): Promise<any>;
run(ctx: Context): Promise<any>;
run(ctx: BaseContext): Promise<any>;
}

@@ -5,6 +5,6 @@ export interface ParamsDictionary {

export interface BaseInput<P = ParamsDictionary> {
params: P;
params?: P;
}
export interface BaseOutput<P = ParamsDictionary> {
data: P;
data?: P;
}

@@ -14,3 +14,3 @@ export interface BaseContext extends ParamsDictionary {

output: BaseOutput;
namespace: (namespace: string) => ContextStorage<any>;
namespace?: (namespace: string) => ContextStorage<any>;
restore?: () => void;

@@ -17,0 +17,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
;
;
;
//# sourceMappingURL=types.js.map
{
"name": "@artus/pipeline",
"version": "0.2.1",
"version": "0.2.2",
"main": "dist/index.js",

@@ -5,0 +5,0 @@ "scripts": {

import type { ExecutionContainer } from '@artus/injection';
import {
BaseContext, BaseInput, BaseOutput,
ContextStorage, ParamsDictionary, Next
} from './types';
import { BaseContext, BaseInput, BaseOutput, ContextStorage, ParamsDictionary, Next } from './types';

@@ -17,3 +14,3 @@ const ContextStorageSymbol = Symbol('ARTUS::ContextStorage');

export class Storage implements ContextStorage<any>{
export class Storage implements ContextStorage<any> {
private storageMap = new Map();

@@ -33,4 +30,4 @@

export class Context implements BaseContext {
public input: BaseInput = new Input();
public output: BaseOutput = new Output();
public input: Input = new Input();
public output: Output = new Output();

@@ -71,5 +68,5 @@ private _container!: ExecutionContainer;

export type Middleware = (context: Context, next: Next) => void;
export type Middleware<T extends BaseContext = any> = (context: T, next: Next) => void;
export type Middlewares = Middleware[];
export type PipelineLike = { middlewares: Middlewares };
export type MiddlewareInput = Middleware | Middlewares | PipelineLike;

@@ -0,4 +1,4 @@

import { Middlewares, MiddlewareInput, PipelineLike } from './base';
import { BaseContext } from './types';
import { Context, Middlewares, MiddlewareInput, PipelineLike } from "./base";
export class Pipeline implements PipelineLike {

@@ -29,3 +29,3 @@ middlewares: Middlewares = [];

dispatch(i: number, ctx: Context, execution = { index: -1 }): Promise<any> {
dispatch(i: number, ctx: BaseContext, execution = { index: -1 }): Promise<any> {
if (i <= execution.index) return Promise.reject(new Error('next() called multiple times'));

@@ -42,5 +42,5 @@ execution.index = i;

run(ctx: Context): Promise<any> {
run(ctx: BaseContext): Promise<any> {
return this.dispatch(0, ctx);
}
}

@@ -6,20 +6,20 @@ export interface ParamsDictionary {

export interface BaseInput<P = ParamsDictionary> {
params: P
};
params?: P;
}
export interface BaseOutput<P = ParamsDictionary> {
data: P
};
data?: P;
}
export interface BaseContext extends ParamsDictionary {
input: BaseInput,
output: BaseOutput,
namespace: (namespace: string) => ContextStorage<any>,
restore?: () => void,
};
input: BaseInput;
output: BaseOutput;
namespace?: (namespace: string) => ContextStorage<any>;
restore?: () => void;
}
export type ContextStorage<T> = {
set: (value: T, key?: string | symbol) => void,
get: (key?: string | symbol) => T
set: (value: T, key?: string | symbol) => void;
get: (key?: string | symbol) => T;
};
export type Next = () => Promise<any>;
import { ContextPool } from '../src/context_pool';
describe("test/context_pool.test.ts", () => {
it('should get ok', () => {
const ctxPool = new ContextPool(1);
const container = new Map();
const ctx = ctxPool.get(container as any);
expect(ctx.container).toBe(container);
expect(ctx.input.params).toBeInstanceOf(Map);
expect(ctx.output.data).toBeInstanceOf(Map);
});
describe('test/context_pool.test.ts', () => {
it('should get ok', () => {
const ctxPool = new ContextPool(1);
const container = new Map();
const ctx = ctxPool.get(container as any);
expect(ctx.container).toBe(container);
expect(ctx.input.params).toBeInstanceOf(Map);
expect(ctx.output.data).toBeInstanceOf(Map);
});
it('should release ok', () => {
const ctxPool = new ContextPool(1);
const container = new Map();
const ctx = ctxPool.get(container as any);
ctx.input.params.set('id', 12);
ctx.output.data.set('user', { id: 12 });
ctxPool.release(ctx);
const container2 = new Map();
const ctx2 = ctxPool.get(container2 as any);
expect(ctx2.container).toBe(container2);
expect(ctx.input.params.has('id')).toBe(false);
expect(ctx.output.data.has('user')).toBe(false);
});
});
it('should release ok', () => {
const ctxPool = new ContextPool(1);
const container = new Map();
const ctx = ctxPool.get(container as any);
ctx.input.params!.set('id', 12);
ctx.output.data!.set('user', { id: 12 });
ctxPool.release(ctx);
const container2 = new Map();
const ctx2 = ctxPool.get(container2 as any);
expect(ctx2.container).toBe(container2);
expect(ctx.input.params!.has('id')).toBe(false);
expect(ctx.output.data!.has('user')).toBe(false);
});
});

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc