Socket
Socket
Sign inDemoInstall

@effection/core

Package Overview
Dependencies
Maintainers
1
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@effection/core - npm Package Compare versions

Comparing version 2.0.0-beta.3 to 2.0.0-beta.4

dist/controller/controller.d.ts.map

6

CHANGELOG.md
# @effection/core
## 2.0.0-beta.4
### Patch Changes
- e297c86: rename Task.spawn() -> Task.run()
## 2.0.0-beta.3

@@ -4,0 +10,0 @@

1

dist/controller/controller.d.ts

@@ -16,1 +16,2 @@ import type { Task } from '../task';

export declare function createController<T>(task: Task<T>, operation: Operation<T>, options?: Options): Controller<T>;
//# sourceMappingURL=controller.d.ts.map

@@ -11,1 +11,2 @@ import { Task } from '../task';

};
//# sourceMappingURL=function-controller.d.ts.map

@@ -5,1 +5,2 @@ import { Controller } from './controller';

export declare function createFutureController<TOut>(task: Task<TOut>, future: FutureLike<TOut>): Controller<TOut>;
//# sourceMappingURL=future-controller.d.ts.map

@@ -10,1 +10,2 @@ import { Controller, Options } from './controller';

export {};
//# sourceMappingURL=iterator-controller.d.ts.map
import { Controller } from './controller';
import { Task } from '../task';
export declare function createPromiseController<TOut>(task: Task<TOut>, promise: PromiseLike<TOut>): Controller<TOut>;
//# sourceMappingURL=promise-controller.d.ts.map

@@ -5,1 +5,2 @@ import { Controller } from './controller';

export declare function createResolutionController<TOut>(task: Task<TOut>, resolution: OperationResolution<TOut>): Controller<TOut>;
//# sourceMappingURL=resolution-controller.d.ts.map

@@ -5,1 +5,2 @@ import { Controller } from './controller';

export declare function createResourceController<TOut>(task: Task<TOut>, resource: Resource<TOut>): Controller<TOut>;
//# sourceMappingURL=resource-controller.d.ts.map
import { Controller } from './controller';
export declare function createSuspendController<TOut>(): Controller<TOut>;
//# sourceMappingURL=suspend-controller.d.ts.map
export declare function deprecated<TThis, TArgs extends unknown[], TReturn>(message: string, fn: (this: TThis, ...args: TArgs) => TReturn): (this: TThis, ...args: TArgs) => TReturn;
//# sourceMappingURL=deprecated.d.ts.map

@@ -7,1 +7,2 @@ import { Task } from './task';

};
//# sourceMappingURL=effection.d.ts.map

@@ -6,1 +6,2 @@ import type { Task, TaskInfo } from './task';

export declare function addTrace(error: Error & Partial<HasEffectionTrace>, task: Task): Error & HasEffectionTrace;
//# sourceMappingURL=error.d.ts.map

5

dist/future.d.ts

@@ -15,3 +15,3 @@ export declare type State = 'pending' | 'errored' | 'completed' | 'halted';

export interface FutureLike<T> {
consume<R>(consumer: Consumer<T>): void;
consume(consumer: Consumer<T>): void;
}

@@ -23,4 +23,7 @@ export interface Future<T> extends Promise<T>, FutureLike<T> {

future: Future<T>;
produce(value: Value<T>): void;
/** @deprecated Use produce(value) instead */
resolve(value: Value<T>): void;
}
export declare function createFuture<T>(): NewFuture<T>;
//# sourceMappingURL=future.d.ts.map

@@ -7,1 +7,2 @@ export declare class HaltError extends Error {

export declare function swallowHalt(error: Error): undefined;
//# sourceMappingURL=halt-error.d.ts.map

@@ -20,1 +20,2 @@ import { Operation } from './operation';

export declare function run<TOut>(operation?: Operation<TOut>, options?: TaskOptions): Task<TOut>;
//# sourceMappingURL=index.d.ts.map

@@ -1,8 +0,35 @@

'use strict'
if (process.env.NODE_ENV === 'production') {
module.exports = require('./core.cjs.production.min.js')
} else {
module.exports = require('./core.cjs.development.js')
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.run = exports.label = exports.all = exports.race = exports.spawn = exports.withTimeout = exports.timeout = exports.ensure = exports.sleep = exports.createFuture = exports.withLabels = exports.deprecated = exports.Effection = exports.createTask = void 0;
const effection_1 = require("./effection");
var task_1 = require("./task");
Object.defineProperty(exports, "createTask", { enumerable: true, get: function () { return task_1.createTask; } });
var effection_2 = require("./effection");
Object.defineProperty(exports, "Effection", { enumerable: true, get: function () { return effection_2.Effection; } });
var deprecated_1 = require("./deprecated");
Object.defineProperty(exports, "deprecated", { enumerable: true, get: function () { return deprecated_1.deprecated; } });
var labels_1 = require("./labels");
Object.defineProperty(exports, "withLabels", { enumerable: true, get: function () { return labels_1.withLabels; } });
var future_1 = require("./future");
Object.defineProperty(exports, "createFuture", { enumerable: true, get: function () { return future_1.createFuture; } });
var sleep_1 = require("./operations/sleep");
Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return sleep_1.sleep; } });
var ensure_1 = require("./operations/ensure");
Object.defineProperty(exports, "ensure", { enumerable: true, get: function () { return ensure_1.ensure; } });
var timeout_1 = require("./operations/timeout");
Object.defineProperty(exports, "timeout", { enumerable: true, get: function () { return timeout_1.timeout; } });
var with_timeout_1 = require("./operations/with-timeout");
Object.defineProperty(exports, "withTimeout", { enumerable: true, get: function () { return with_timeout_1.withTimeout; } });
var spawn_1 = require("./operations/spawn");
Object.defineProperty(exports, "spawn", { enumerable: true, get: function () { return spawn_1.spawn; } });
var race_1 = require("./operations/race");
Object.defineProperty(exports, "race", { enumerable: true, get: function () { return race_1.race; } });
var all_1 = require("./operations/all");
Object.defineProperty(exports, "all", { enumerable: true, get: function () { return all_1.all; } });
var label_1 = require("./operations/label");
Object.defineProperty(exports, "label", { enumerable: true, get: function () { return label_1.label; } });
function run(operation, options) {
return effection_1.Effection.root.run(operation, options);
}
exports.run = run;
//# sourceMappingURL=index.js.map
import { Operation } from './operation';
export declare type Labels = Record<string, string | number | boolean>;
export declare function withLabels<T>(operation: Operation<T>, labels: Labels): Operation<T>;
//# sourceMappingURL=labels.d.ts.map

@@ -24,1 +24,2 @@ import type { Task } from './task';

export declare type Operation<TOut> = OperationPromise<TOut> | OperationIterator<TOut> | OperationResolution<TOut> | OperationFuture<TOut> | OperationFunction<TOut> | Resource<TOut> | undefined;
//# sourceMappingURL=operation.d.ts.map

@@ -7,1 +7,2 @@ import type { Operation } from '../operation';

export {};
//# sourceMappingURL=all.d.ts.map
import { Operation, Resource } from '../operation';
export declare function ensure<T>(fn: () => Operation<T> | void): Resource<undefined>;
//# sourceMappingURL=ensure.d.ts.map
import { Resource } from '../operation';
import { Labels } from '../labels';
export declare function label(labels: Labels): Resource<void>;
//# sourceMappingURL=label.d.ts.map
import type { Operation } from '../operation';
export declare function race<T>(operations: Operation<T>[]): Operation<T>;
//# sourceMappingURL=race.d.ts.map
import { Operation } from '../operation';
export declare function sleep(duration?: number): Operation<void>;
//# sourceMappingURL=sleep.d.ts.map

@@ -8,1 +8,2 @@ import { Operation, Resource } from '../operation';

export {};
//# sourceMappingURL=spawn.d.ts.map
import { Operation } from '../operation';
export declare function timeout(duration: number): Operation<never>;
//# sourceMappingURL=timeout.d.ts.map
import { Operation } from '../operation';
export declare function withTimeout<T>(duration: number, operation: Operation<T>): Operation<T>;
//# sourceMappingURL=with-timeout.d.ts.map

@@ -8,1 +8,2 @@ import type { OperationResolution, Resource } from "./operation";

export declare function isResource<TOut>(value: any): value is Resource<TOut>;
//# sourceMappingURL=predicates.d.ts.map

@@ -6,1 +6,2 @@ export declare type Runnable = () => void;

export declare function createRunLoop(): RunLoop;
//# sourceMappingURL=run-loop.d.ts.map

@@ -19,1 +19,2 @@ /// <reference types="node" />

}
//# sourceMappingURL=state-machine.d.ts.map

@@ -35,2 +35,4 @@ /// <reference types="node" />

setLabels(labels: Labels): void;
run<R>(operation?: Operation<R>, options?: TaskOptions): Task<R>;
/** @deprecated Use run() instead */
spawn<R>(operation?: Operation<R>, options?: TaskOptions): Task<R>;

@@ -44,1 +46,2 @@ halt(): Promise<void>;

export declare function createTask<TOut = unknown>(operation: Operation<TOut>, options?: TaskOptions): Task<TOut>;
//# sourceMappingURL=task.d.ts.map

@@ -5,1 +5,2 @@ import { Task } from './task';

}
//# sourceMappingURL=trapper.d.ts.map
{
"name": "@effection/core",
"version": "2.0.0-beta.3",
"version": "2.0.0-beta.4",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",
"homepage": "https://github.com/thefrontside/effection",
"repository": {
"type": "git",
"url": "https://github.com/thefrontside/effection.git",
"directory": "packages/core"
},
"scripts": {

@@ -12,22 +18,20 @@ "lint": "eslint '{src,bin,test}/**/*.ts'",

"docs": "yarn typedoc src/index.ts",
"prepack": "tsdx build --tsconfig tsconfig.dist.json"
"build": "yarn prepack",
"prepack": "tsc --build tsconfig.dist.json"
},
"files": [
"CHANGELOG.md",
"dist/**/*",
"src/**/*"
],
"devDependencies": {
"@frontside/tsconfig": "^1.2.0",
"@types/mocha": "^7.0.2",
"@types/node": "^13.13.5",
"eslint": "^6.8.0",
"@types/node": "^16.3.2",
"eslint": "^7.30.0",
"expect": "^25.3.0",
"mocha": "^8.3.1",
"ts-node": "^8.8.2",
"tsdx": "0.13.2",
"ts-node": "^10.1.0",
"typedoc": "^0.20.36",
"typescript": "^3.8.3"
"typescript": "^4.3.5"
},
"dependencies": {}
"dependencies": {},
"volta": {
"extends": "../../package.json"
}
}

@@ -8,3 +8,3 @@ import { Task } from '../task';

let delegate: Controller<TOut>;
let { resolve, future } = createFuture<TOut>();
let { produce, future } = createFuture<TOut>();

@@ -20,7 +20,7 @@ function start() {

} catch (error) {
resolve({ state: 'errored', error });
produce({ state: 'errored', error });
return;
}
delegate.future.consume((value) => {
resolve(value);
produce(value);
});

@@ -48,3 +48,3 @@ delegate.start();

halt,
}
};
}

@@ -6,10 +6,10 @@ import { Controller } from './controller';

export function createFutureController<TOut>(task: Task<TOut>, future: FutureLike<TOut>): Controller<TOut> {
let { future: inner, resolve } = createFuture<TOut>();
let { future: inner, produce } = createFuture<TOut>();
function start() {
future.consume(resolve);
future.consume(produce);
}
function halt() {
resolve({ state: 'halted' });
produce({ state: 'halted' });
}

@@ -16,0 +16,0 @@

@@ -20,3 +20,3 @@ import { Controller, Options } from './controller';

let { resolve, future } = createFuture<TOut>();
let { produce, future } = createFuture<TOut>();
let runLoop = createRunLoop();

@@ -26,5 +26,5 @@

if (iterator[claimed]) {
let error = new Error(`An operation iterator can only be run once in a single task, but it looks like has been either yielded to, or run multiple times`)
let error = new Error(`An operation iterator can only be run once in a single task, but it looks like has been either yielded to, or run multiple times`);
error.name = 'DoubleEvalError';
resolve({ state: 'errored', error });
produce({ state: 'errored', error });
} else {

@@ -42,3 +42,3 @@ iterator[claimed] = true;

} catch(error) {
resolve({ state: 'errored', error });
produce({ state: 'errored', error });
return;

@@ -48,5 +48,5 @@ }

if(didHalt) {
resolve({ state: 'halted' });
produce({ state: 'halted' });
} else {
resolve({ state: 'completed', value: next.value });
produce({ state: 'completed', value: next.value });
}

@@ -53,0 +53,0 @@ } else {

@@ -6,3 +6,3 @@ import { Controller } from './controller';

export function createPromiseController<TOut>(task: Task<TOut>, promise: PromiseLike<TOut>): Controller<TOut> {
let { resolve, future } = createFuture<TOut>();
let { produce, future } = createFuture<TOut>();

@@ -12,12 +12,12 @@ function start() {

(value) => {
resolve({ state: 'completed', value });
produce({ state: 'completed', value });
},
(error) => {
resolve({ state: 'errored', error });
produce({ state: 'errored', error });
}
)
);
}
function halt() {
resolve({ state: 'halted' });
produce({ state: 'halted' });
}

@@ -24,0 +24,0 @@

@@ -7,3 +7,3 @@ import { Controller } from './controller';

export function createResolutionController<TOut>(task: Task<TOut>, resolution: OperationResolution<TOut>): Controller<TOut> {
let { future, resolve } = createFuture<TOut>();
let { future, produce } = createFuture<TOut>();

@@ -13,4 +13,4 @@ function start() {

let atExit = resolution.perform(
(value) => resolve({ state: 'completed', value }),
(error) => resolve({ state: 'errored', error }),
(value) => produce({ state: 'completed', value }),
(error) => produce({ state: 'errored', error }),
);

@@ -22,3 +22,3 @@

} catch(error) {
resolve({ state: 'errored', error });
produce({ state: 'errored', error });
}

@@ -28,3 +28,3 @@ }

function halt() {
resolve({ state: 'halted' });
produce({ state: 'halted' });
}

@@ -31,0 +31,0 @@

@@ -10,7 +10,7 @@ import { Controller } from './controller';

let { resourceScope } = task.options;
let { resolve, future } = createFuture<TOut>();
let { produce, future } = createFuture<TOut>();
function start() {
if(!resourceScope) {
throw new Error('cannot spawn resource in task which has no resource scope')
throw new Error('cannot spawn resource in task which has no resource scope');
}

@@ -21,3 +21,3 @@ let init;

} catch(error) {
resolve({ state: 'errored', error });
produce({ state: 'errored', error });
return;

@@ -27,3 +27,3 @@ }

delegate.future.consume((value) => {
resolve(value);
produce(value);
});

@@ -30,0 +30,0 @@ delegate.start();

@@ -5,3 +5,3 @@ import { Controller } from './controller';

export function createSuspendController<TOut>(): Controller<TOut> {
let { resolve, future } = createFuture<TOut>();
let { produce, future } = createFuture<TOut>();

@@ -13,3 +13,3 @@ function start() {

function halt() {
resolve({ state: 'halted' });
produce({ state: 'halted' });
}

@@ -16,0 +16,0 @@

/* eslint-disable @typescript-eslint/no-explicit-any */
import { Task, createTask } from './task';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { version } from '../package.json';

@@ -44,2 +46,2 @@

}
}
};

@@ -19,4 +19,4 @@ import type { Task, TaskInfo } from './task';

enumerable: true,
}
};
return Object.create(Object.getPrototypeOf(error), properties);
}

@@ -16,3 +16,3 @@ import { HaltError } from './halt-error';

export interface FutureLike<T> {
consume<R>(consumer: Consumer<T>): void;
consume(consumer: Consumer<T>): void;
}

@@ -26,2 +26,4 @@

future: Future<T>;
produce(value: Value<T>): void;
/** @deprecated Use produce(value) instead */
resolve(value: Value<T>): void;

@@ -53,3 +55,3 @@ }

function resolve(value: Value<T>) {
function produce(value: Value<T>) {
if(!result) {

@@ -61,3 +63,8 @@ result = value;

function resolve(value: Value<T>) {
console.warn(`DEPRECATED: resolve() is deprecated and will be changed or removed prior to the release of effection 2.0\nuse produce() instead`);
produce(value);
}
let promise: Promise<T>;

@@ -80,3 +87,3 @@

return {
resolve,
produce,
future: {

@@ -89,4 +96,5 @@ get state() { return result?.state || 'pending' },

[Symbol.toStringTag]: '[continuation]',
}
}
},
resolve
};
}

@@ -24,3 +24,3 @@ import { Operation } from './operation';

export function run<TOut>(operation?: Operation<TOut>, options?: TaskOptions): Task<TOut> {
return Effection.root.spawn(operation, options);
return Effection.root.run(operation, options);
}

@@ -12,13 +12,13 @@ /* eslint-disable @typescript-eslint/no-explicit-any */

export interface OperationIterator<TOut> extends Generator<Operation<any>, TOut | undefined, any>, Labelled {
};
}
export interface OperationPromise<TOut> extends PromiseLike<TOut>, Labelled {
};
}
export interface OperationResolution<TOut> extends Labelled {
perform(resolve: (value: TOut) => void, reject: (err: Error) => void): void | (() => void);
};
}
export interface OperationFuture<TOut> extends FutureLike<TOut>, Labelled {
};
}

@@ -25,0 +25,0 @@ export interface Resource<TOut> extends Labelled {

@@ -16,3 +16,3 @@ /* eslint-disable @typescript-eslint/no-explicit-any */

if(scope.state === 'running') {
tasks.push(scope.spawn(operation));
tasks.push(scope.run(operation));
}

@@ -19,0 +19,0 @@ }

import { Operation, Resource } from '../operation';
import { spawn } from './spawn';
export function ensure<T>(fn: () => Operation<T> | void): Resource<undefined> {
return {
name: 'ensure',
*init(scope) {
scope.spawn(function*() {
*init() {
yield spawn(function*() {
try {
yield
yield;
} finally {

@@ -11,0 +13,0 @@ let result = fn();

@@ -10,3 +10,3 @@ import { Resource } from '../operation';

}
}
};
}

@@ -9,3 +9,3 @@ import type { Operation } from '../operation';

if(scope.state === 'running') {
scope.spawn(function*() {
scope.run(function*() {
try {

@@ -12,0 +12,0 @@ resolve(yield operation);

@@ -12,3 +12,3 @@ import { Operation } from '../operation';

}
}
};
}

@@ -10,3 +10,3 @@ import { Operation, Resource } from '../operation';

function* init(scope: Task) {
return scope.spawn(operation, options);
return scope.run(operation, options);
}

@@ -17,3 +17,3 @@

init: () => init(scope)
}
};
}

@@ -20,0 +20,0 @@

@@ -11,5 +11,5 @@ import { Operation } from '../operation';

return withLabels(function*() {
yield sleep(duration)
yield sleep(duration);
throw new TimeoutError(`timed out after ${duration}ms`);
}, { name: 'timeout', duration });
}
import { Operation } from '../operation';
import { timeout } from './timeout';
import { spawn } from './spawn';
import { withLabels } from '../labels';
export function withTimeout<T>(duration: number, operation: Operation<T>): Operation<T> {
return withLabels(function*(task) {
task.spawn(timeout(duration));
return withLabels(function*() {
yield spawn(timeout(duration));
return yield operation;
}, { name: 'withTimeout', duration });
}

@@ -5,3 +5,3 @@ import { EventEmitter } from 'events';

function f(value: string) { return JSON.stringify(value) };
function f(value: string) { return JSON.stringify(value) }

@@ -24,3 +24,3 @@ export type StateTransition = {

let options = Object.keys(validTransitions).map(f).join(', ');
throw new Error(`INTERNAL ERROR: state transition ${f(event)} is not valid in current state ${f(from)}, should be one of ${options}`)
throw new Error(`INTERNAL ERROR: state transition ${f(event)} is not valid in current state ${f(from)}, should be one of ${options}`);
}

@@ -27,0 +27,0 @@

@@ -45,2 +45,4 @@ /* eslint-disable @typescript-eslint/no-explicit-any */

setLabels(labels: Labels): void;
run<R>(operation?: Operation<R>, options?: TaskOptions): Task<R>;
/** @deprecated Use run() instead */
spawn<R>(operation?: Operation<R>, options?: TaskOptions): Task<R>;

@@ -64,3 +66,3 @@ halt(): Promise<void>;

let { resolve, future } = createFuture<TOut>();
let { produce, future } = createFuture<TOut>();
let result: Value<TOut>;

@@ -71,3 +73,3 @@ let runLoop = createRunLoop();

let labels: Labels = { ...operation?.labels, ...options.labels }
let labels: Labels = { ...operation?.labels, ...options.labels };
let yieldingTo: Task | undefined;

@@ -93,7 +95,7 @@

get state() { return stateMachine.current; },
get state() { return stateMachine.current },
get type() { return controller.type },
get children() { return Array.from(children); },
get children() { return Array.from(children) },

@@ -111,3 +113,3 @@ get yieldingTo() { return yieldingTo },

spawn(operation?, options = {}) {
run(operation?, options = {}) {
if(stateMachine.current !== 'running') {

@@ -122,2 +124,7 @@ throw new Error('cannot spawn a child on a task which is not running');

spawn(operation?, options = {}) {
console.warn(`DEPRECATED: task.spawn() is deprecated and will be changed or removed prior to the release of effection 2.0\nuse task.run() instead`);
return task.run(operation, options);
},
start() {

@@ -150,3 +157,3 @@ if(stateMachine.current === 'pending') {

children: Array.from(children).map((c) => c.toJSON()),
}
};
},

@@ -161,3 +168,3 @@

[Symbol.toStringTag]: `[Task ${id}]`,
}
};

@@ -214,7 +221,7 @@ controller = createController(task, operation, {

.reverse()
.find((c) => (c !== nextChild) && (force || !c.options.blockParent))
.find((c) => (c !== nextChild) && (force || !c.options.blockParent));
if(nextChild) {
nextChild.consume(haltNextChild);
nextChild.halt()
nextChild.halt();
}

@@ -234,3 +241,3 @@ });

stateMachine.finish();
resolve(result);
produce(result);
});

@@ -240,2 +247,2 @@ }

return task;
};
}
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