@quantform/core 0.7.0-beta.46 → 0.7.0-beta.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,6 @@ export declare class Script {
3
3
  private readonly name;
4
4
  private readonly dependencies;
5
5
  constructor(name: string, dependencies: Dependency[]);
6
- run(): Promise<unknown>;
6
+ run(): Promise<unknown[]>;
7
7
  }
8
8
  //# sourceMappingURL=script.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"script.d.ts","sourceRoot":"","sources":["../../../src/cli/internal/script.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAU,MAAM,aAAa,CAAC;AAKjD,qBAAa,MAAM;IAEf,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,YAAY;gBADZ,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,UAAU,EAAE;IAGvC,GAAG;CA0BV"}
1
+ {"version":3,"file":"script.d.ts","sourceRoot":"","sources":["../../../src/cli/internal/script.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,UAAU,EAAU,MAAM,aAAa,CAAC;AAMjD,qBAAa,MAAM;IAEf,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,YAAY;gBADZ,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,UAAU,EAAE;IAGvC,GAAG;CAmCV"}
@@ -47,11 +47,14 @@ class Script {
47
47
  run() {
48
48
  return __awaiter(this, void 0, void 0, function* () {
49
49
  const script = yield Promise.resolve(`${(0, path_1.join)((0, workspace_1.buildDirectory)(), this.name)}`).then(s => __importStar(require(s)));
50
- const module = new module_1.Module([...(0, core_1.core)(), ...script.onInstall(), ...this.dependencies]);
50
+ const { dependencies, description } = script.default;
51
+ const module = new module_1.Module([...(0, core_1.core)(), ...dependencies, ...this.dependencies]);
51
52
  const { act } = yield module.awake();
52
53
  return yield act(() => {
53
54
  process.stdin.resume();
54
- return (0, rxjs_1.firstValueFrom)((0, rxjs_1.merge)(script.onAwake().pipe((0, rxjs_1.last)()), (0, replay_1.whenReplayFinished)().pipe((0, rxjs_1.last)()), (0, rxjs_1.fromEvent)(process, 'exit'), (0, rxjs_1.fromEvent)(process, 'SIGINT'), (0, rxjs_1.fromEvent)(process, 'SIGUSR1'), (0, rxjs_1.fromEvent)(process, 'SIGUSR2'), (0, rxjs_1.fromEvent)(process, 'uncaughtException')).pipe((0, rxjs_1.take)(1), (0, rxjs_1.switchMap)(it => { var _a; return (_a = script.onExit()) !== null && _a !== void 0 ? _a : (0, rxjs_1.of)(it); }), (0, rxjs_1.finalize)(() => process.exit(0))));
55
+ return (0, rxjs_1.firstValueFrom)((0, rxjs_1.merge)((0, rxjs_1.forkJoin)(description.before.map(it => it()))
56
+ .pipe((0, rxjs_1.switchMap)(() => (0, rxjs_1.forkJoin)(description.behavior.map(it => it())).pipe((0, rxjs_1.last)())))
57
+ .pipe((0, rxjs_1.last)()), (0, replay_1.whenReplayFinished)().pipe((0, rxjs_1.last)()), (0, rxjs_1.fromEvent)(process, 'exit'), (0, rxjs_1.fromEvent)(process, 'SIGINT'), (0, rxjs_1.fromEvent)(process, 'SIGUSR1'), (0, rxjs_1.fromEvent)(process, 'SIGUSR2'), (0, rxjs_1.fromEvent)(process, 'uncaughtException')).pipe((0, rxjs_1.take)(1), (0, rxjs_1.switchMap)(it => { var _a; return (_a = (0, rxjs_1.forkJoin)(description.after.map(it => it())).pipe((0, rxjs_1.last)())) !== null && _a !== void 0 ? _a : (0, rxjs_1.of)(it); }), (0, rxjs_1.finalize)(() => process.exit(0))));
55
58
  });
56
59
  });
57
60
  }
package/dist/index.d.ts CHANGED
@@ -15,5 +15,6 @@ export * from './when-socket';
15
15
  export * from './with-request';
16
16
  export * from './with-memo';
17
17
  export * from './session';
18
+ export * from './strategy';
18
19
  export * from './operators';
19
20
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC;AAC1B,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC;AAC1B,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC"}
package/dist/index.js CHANGED
@@ -31,4 +31,5 @@ __exportStar(require("./when-socket"), exports);
31
31
  __exportStar(require("./with-request"), exports);
32
32
  __exportStar(require("./with-memo"), exports);
33
33
  __exportStar(require("./session"), exports);
34
+ __exportStar(require("./strategy"), exports);
34
35
  __exportStar(require("./operators"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"make-test-module.d.ts","sourceRoot":"","sources":["../src/make-test-module.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAG3C,OAAO,EAAE,UAAU,EAAU,MAAM,aAAa,CAAC;AAEjD,wBAAsB,cAAc,CAAC,YAAY,EAAE,UAAU,EAAE;;;GAS9D;AAED,KAAK,gBAAgB,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;AAEhD,eAAO,MAAM,UAAU,gFAC+B,CAAC;AAEvD,wBAAgB,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,iBAyBnD;AAED,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAE/E,wBAAgB,WAAW,CACzB,CAAC,SAAS,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAC9C,CAAC,SAAS,MAAM,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EACpD,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,qFAYrB"}
1
+ {"version":3,"file":"make-test-module.d.ts","sourceRoot":"","sources":["../src/make-test-module.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAG3C,OAAO,EAAE,UAAU,EAAU,MAAM,aAAa,CAAC;AAEjD,wBAAsB,cAAc,CAAC,YAAY,EAAE,UAAU,EAAE;;;GAS9D;AAED,KAAK,gBAAgB,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;AAEhD,eAAO,MAAM,UAAU,gFAC+B,CAAC;AAEvD,wBAAgB,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,iBAyBnD;AAED,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAE/E,wBAAgB,WAAW,CACzB,CAAC,SAAS,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAC9C,CAAC,SAAS,MAAM,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EACpD,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,qFAQrB"}
@@ -49,9 +49,7 @@ function toArray(observable) {
49
49
  exports.toArray = toArray;
50
50
  function mockSubject(object, method) {
51
51
  const subject = new rxjs_1.Subject();
52
- jest
53
- .spyOn(object, method)
54
- .mockReturnValue(subject.asObservable());
52
+ jest.spyOn(object, method).mockReturnValue(subject.asObservable());
55
53
  return subject;
56
54
  }
57
55
  exports.mockSubject = mockSubject;
@@ -0,0 +1,15 @@
1
+ import { Observable } from 'rxjs';
2
+ import { Dependency } from './module';
3
+ export type Descriptor = () => Observable<unknown>;
4
+ export declare let before: (descriptor: Descriptor) => void;
5
+ export declare let behavior: (descriptor: Descriptor) => void;
6
+ export declare let after: (descriptor: Descriptor) => void;
7
+ export declare function strategy(descriptor: () => Dependency[]): {
8
+ dependencies: Dependency[];
9
+ description: {
10
+ before: Descriptor[];
11
+ behavior: Descriptor[];
12
+ after: Descriptor[];
13
+ };
14
+ };
15
+ //# sourceMappingURL=strategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../src/strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,MAAM,MAAM,UAAU,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,CAAC;AAEnD,eAAO,IAAI,MAAM,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,CAAC;AACpD,eAAO,IAAI,QAAQ,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,CAAC;AACtD,eAAO,IAAI,KAAK,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,CAAC;AAEnD,wBAAgB,QAAQ,CAAC,UAAU,EAAE,MAAM,UAAU,EAAE;;;;;;;EAiBtD"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.strategy = exports.after = exports.behavior = exports.before = void 0;
4
+ function strategy(descriptor) {
5
+ const description = {
6
+ before: Array.of(),
7
+ behavior: Array.of(),
8
+ after: Array.of()
9
+ };
10
+ exports.before = descriptor => description.before.push(descriptor);
11
+ exports.behavior = descriptor => description.behavior.push(descriptor);
12
+ exports.after = descriptor => description.after.push(descriptor);
13
+ const dependencies = descriptor();
14
+ return {
15
+ dependencies,
16
+ description
17
+ };
18
+ }
19
+ exports.strategy = strategy;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=strategy.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategy.spec.d.ts","sourceRoot":"","sources":["../src/strategy.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const rxjs_1 = require("rxjs");
4
+ const strategy_1 = require("./strategy");
5
+ describe(strategy_1.strategy.name, () => {
6
+ let fixtures;
7
+ beforeEach(() => {
8
+ fixtures = getFixtures();
9
+ });
10
+ test('happy path', () => {
11
+ const sut = (0, strategy_1.strategy)(() => {
12
+ (0, strategy_1.before)(() => (0, rxjs_1.of)('before'));
13
+ (0, strategy_1.behavior)(() => (0, rxjs_1.of)('behavior 1'));
14
+ (0, strategy_1.behavior)(() => (0, rxjs_1.of)('behavior 2'));
15
+ (0, strategy_1.after)(() => (0, rxjs_1.of)('after'));
16
+ return fixtures.given.dependencies();
17
+ });
18
+ expect(sut.dependencies).toEqual(expect.arrayContaining(fixtures.given.dependencies()));
19
+ expect(sut.description).toEqual({
20
+ before: [expect.any(Function)],
21
+ behavior: [expect.any(Function), expect.any(Function)],
22
+ after: [expect.any(Function)]
23
+ });
24
+ });
25
+ });
26
+ function getFixtures() {
27
+ return {
28
+ given: {
29
+ dependencies() {
30
+ return [];
31
+ }
32
+ }
33
+ };
34
+ }
@@ -2,8 +2,7 @@ import { Observable } from 'rxjs';
2
2
  export type RequestMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH';
3
3
  export declare class RequestNetworkError extends Error {
4
4
  readonly statusCode: number;
5
- readonly json: () => Promise<string>;
6
- constructor(statusCode: number, json: () => Promise<string>);
5
+ constructor(statusCode: number);
7
6
  }
8
7
  export declare function withRequest({ method, url, headers, body }: {
9
8
  method: RequestMethod;
@@ -1 +1 @@
1
- {"version":3,"file":"with-request.d.ts","sourceRoot":"","sources":["../src/with-request.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAMlC,MAAM,MAAM,aAAa,GACrB,KAAK,GACL,MAAM,GACN,MAAM,GACN,KAAK,GACL,QAAQ,GACR,SAAS,GACT,SAAS,GACT,OAAO,GACP,OAAO,CAAC;AAEZ,qBAAa,mBAAoB,SAAQ,KAAK;IAChC,QAAQ,CAAC,UAAU,EAAE,MAAM;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC;gBAAxD,UAAU,EAAE,MAAM,EAAW,IAAI,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC;CAG9E;AAED,wBAAgB,WAAW,CAAC,EAC1B,MAAM,EACN,GAAG,EACH,OAAO,EACP,IAAI,EACL,EAAE;IACD,MAAM,EAAE,aAAa,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;eAGoC,MAAM;aAAW,OAAO;GA6C5D"}
1
+ {"version":3,"file":"with-request.d.ts","sourceRoot":"","sources":["../src/with-request.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAMlC,MAAM,MAAM,aAAa,GACrB,KAAK,GACL,MAAM,GACN,MAAM,GACN,KAAK,GACL,QAAQ,GACR,SAAS,GACT,SAAS,GACT,OAAO,GACP,OAAO,CAAC;AAEZ,qBAAa,mBAAoB,SAAQ,KAAK;IAChC,QAAQ,CAAC,UAAU,EAAE,MAAM;gBAAlB,UAAU,EAAE,MAAM;CAGxC;AAED,wBAAgB,WAAW,CAAC,EAC1B,MAAM,EACN,GAAG,EACH,OAAO,EACP,IAAI,EACL,EAAE;IACD,MAAM,EAAE,aAAa,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;eAGoC,MAAM;aAAW,OAAO;GA6C5D"}
@@ -16,10 +16,9 @@ const undici_1 = require("undici");
16
16
  const use_logger_1 = require("./use-logger");
17
17
  const use_timestamp_1 = require("./use-timestamp");
18
18
  class RequestNetworkError extends Error {
19
- constructor(statusCode, json) {
19
+ constructor(statusCode) {
20
20
  super(`Request network error, received status code: ${statusCode}`);
21
21
  this.statusCode = statusCode;
22
- this.json = json;
23
22
  }
24
23
  }
25
24
  exports.RequestNetworkError = RequestNetworkError;
@@ -47,7 +46,7 @@ function withRequest({ method, url, headers, body }) {
47
46
  body,
48
47
  statusCode
49
48
  });
50
- subscriber.error(new RequestNetworkError(statusCode, () => json));
49
+ subscriber.error(new RequestNetworkError(statusCode));
51
50
  }
52
51
  else {
53
52
  subscriber.next({ timestamp: (0, use_timestamp_1.useTimestamp)(), payload: json });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quantform/core",
3
- "version": "0.7.0-beta.46",
3
+ "version": "0.7.0-beta.48",
4
4
  "license": "MIT",
5
5
  "author": "Mateusz Majchrzak",
6
6
  "description": "Node.js library for building systematic trading strategies in reactive way.",
@@ -37,7 +37,7 @@
37
37
  "rxjs": "^7.8.0"
38
38
  },
39
39
  "peerDependencies": {
40
- "rxjs": "^7.5.6"
40
+ "rxjs": "^7.8.0"
41
41
  },
42
42
  "scripts": {
43
43
  "build": "tsc && tsc-alias",
@@ -2,17 +2,20 @@ import { join } from 'path';
2
2
  import {
3
3
  finalize,
4
4
  firstValueFrom,
5
+ forkJoin,
5
6
  fromEvent,
6
7
  last,
7
8
  merge,
8
9
  of,
9
10
  switchMap,
10
- take
11
+ take,
12
+ tap
11
13
  } from 'rxjs';
12
14
 
13
15
  import { core } from '@lib/core';
14
16
  import { Dependency, Module } from '@lib/module';
15
17
  import { whenReplayFinished } from '@lib/replay';
18
+ import { strategy } from '@lib/strategy';
16
19
 
17
20
  import { buildDirectory } from './workspace';
18
21
 
@@ -24,7 +27,10 @@ export class Script {
24
27
 
25
28
  async run() {
26
29
  const script = await import(join(buildDirectory(), this.name));
27
- const module = new Module([...core(), ...script.onInstall(), ...this.dependencies]);
30
+
31
+ const { dependencies, description } = script.default as ReturnType<typeof strategy>;
32
+
33
+ const module = new Module([...core(), ...dependencies, ...this.dependencies]);
28
34
 
29
35
  const { act } = await module.awake();
30
36
 
@@ -33,7 +39,11 @@ export class Script {
33
39
 
34
40
  return firstValueFrom(
35
41
  merge(
36
- script.onAwake().pipe(last()),
42
+ forkJoin(description.before.map(it => it()))
43
+ .pipe(
44
+ switchMap(() => forkJoin(description.behavior.map(it => it())).pipe(last()))
45
+ )
46
+ .pipe(last()),
37
47
  whenReplayFinished().pipe(last()),
38
48
  fromEvent(process, 'exit'),
39
49
  fromEvent(process, 'SIGINT'),
@@ -42,7 +52,9 @@ export class Script {
42
52
  fromEvent(process, 'uncaughtException')
43
53
  ).pipe(
44
54
  take(1),
45
- switchMap(it => script.onExit() ?? of(it)),
55
+ switchMap(
56
+ it => forkJoin(description.after.map(it => it())).pipe(last()) ?? of(it)
57
+ ),
46
58
  finalize(() => process.exit(0))
47
59
  )
48
60
  );
package/src/index.ts CHANGED
@@ -15,4 +15,5 @@ export * from '@lib/when-socket';
15
15
  export * from '@lib/with-request';
16
16
  export * from '@lib/with-memo';
17
17
  export * from '@lib/session';
18
+ export * from '@lib/strategy';
18
19
  export * from '@lib/operators';
@@ -56,11 +56,7 @@ export function mockSubject<
56
56
  InferObservableType<ReturnType<jest.FunctionProperties<Required<T>>[M]>>
57
57
  >();
58
58
 
59
- jest
60
- .spyOn<T, M>(object, method)
61
- .mockReturnValue(
62
- subject.asObservable() as ReturnType<jest.FunctionProperties<Required<T>>[M]>
63
- );
59
+ jest.spyOn<T, M>(object, method).mockReturnValue(subject.asObservable() as any);
64
60
 
65
61
  return subject;
66
62
  }
@@ -0,0 +1,42 @@
1
+ import { of } from 'rxjs';
2
+
3
+ import { Dependency } from './module';
4
+ import { after, before, behavior, strategy } from './strategy';
5
+
6
+ describe(strategy.name, () => {
7
+ let fixtures: ReturnType<typeof getFixtures>;
8
+
9
+ beforeEach(() => {
10
+ fixtures = getFixtures();
11
+ });
12
+
13
+ test('happy path', () => {
14
+ const sut = strategy(() => {
15
+ before(() => of('before'));
16
+ behavior(() => of('behavior 1'));
17
+ behavior(() => of('behavior 2'));
18
+ after(() => of('after'));
19
+
20
+ return fixtures.given.dependencies();
21
+ });
22
+
23
+ expect(sut.dependencies).toEqual(
24
+ expect.arrayContaining(fixtures.given.dependencies())
25
+ );
26
+ expect(sut.description).toEqual({
27
+ before: [expect.any(Function)],
28
+ behavior: [expect.any(Function), expect.any(Function)],
29
+ after: [expect.any(Function)]
30
+ });
31
+ });
32
+ });
33
+
34
+ function getFixtures() {
35
+ return {
36
+ given: {
37
+ dependencies(): Dependency[] {
38
+ return [];
39
+ }
40
+ }
41
+ };
42
+ }
@@ -0,0 +1,28 @@
1
+ import { Observable } from 'rxjs';
2
+
3
+ import { Dependency } from './module';
4
+
5
+ export type Descriptor = () => Observable<unknown>;
6
+
7
+ export let before: (descriptor: Descriptor) => void;
8
+ export let behavior: (descriptor: Descriptor) => void;
9
+ export let after: (descriptor: Descriptor) => void;
10
+
11
+ export function strategy(descriptor: () => Dependency[]) {
12
+ const description = {
13
+ before: Array.of<Descriptor>(),
14
+ behavior: Array.of<Descriptor>(),
15
+ after: Array.of<Descriptor>()
16
+ };
17
+
18
+ before = descriptor => description.before.push(descriptor);
19
+ behavior = descriptor => description.behavior.push(descriptor);
20
+ after = descriptor => description.after.push(descriptor);
21
+
22
+ const dependencies = descriptor();
23
+
24
+ return {
25
+ dependencies,
26
+ description
27
+ };
28
+ }
@@ -13,7 +13,7 @@ export function whenSocket(
13
13
  const message = new Observable<{ timestamp: number; payload: unknown }>(stream => {
14
14
  const socket = new WebSocket(url);
15
15
  let isAlive = false;
16
- let interval: NodeJS.Timer | undefined;
16
+ let interval: NodeJS.Timeout | undefined;
17
17
 
18
18
  socket.onmessage = it =>
19
19
  stream.next({ timestamp: useTimestamp(), payload: JSON.parse(it.data as string) });
@@ -17,7 +17,7 @@ export type RequestMethod =
17
17
  | 'PATCH';
18
18
 
19
19
  export class RequestNetworkError extends Error {
20
- constructor(readonly statusCode: number, readonly json: () => Promise<string>) {
20
+ constructor(readonly statusCode: number) {
21
21
  super(`Request network error, received status code: ${statusCode}`);
22
22
  }
23
23
  }
@@ -62,7 +62,7 @@ export function withRequest({
62
62
  statusCode
63
63
  });
64
64
 
65
- subscriber.error(new RequestNetworkError(statusCode, () => json));
65
+ subscriber.error(new RequestNetworkError(statusCode));
66
66
  } else {
67
67
  subscriber.next({ timestamp: useTimestamp(), payload: json });
68
68
  }