@effectionx/test-adapter 0.5.0 → 0.6.0

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.
package/esm/box.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { type Operation, type Result } from "effection";
2
+ export declare function box<T>(content: () => Operation<T>): Operation<Result<T>>;
3
+ export declare function unbox<T>(result: Result<T>): T;
4
+ //# sourceMappingURL=box.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"box.d.ts","sourceRoot":"","sources":["../src/box.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,SAAS,EAAE,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AAEjE,wBAAiB,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAMzE;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAK7C"}
package/esm/box.js ADDED
@@ -0,0 +1,15 @@
1
+ import { Err, Ok } from "effection";
2
+ export function* box(content) {
3
+ try {
4
+ return Ok(yield* content());
5
+ }
6
+ catch (error) {
7
+ return Err(error);
8
+ }
9
+ }
10
+ export function unbox(result) {
11
+ if (result.ok) {
12
+ return result.value;
13
+ }
14
+ throw result.error;
15
+ }
package/esm/mod.d.ts CHANGED
@@ -54,7 +54,7 @@ export interface TestAdapter {
54
54
  *
55
55
  * @ignore
56
56
  */
57
- ["@@init@@"](): Operation<Scope>;
57
+ ["@@init@@"](): Operation<Result<Scope>>;
58
58
  }
59
59
  export interface TestAdapterOptions {
60
60
  /**
package/esm/mod.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM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ok, run, suspend, useScope, withResolvers, } from "effection";
2
+ import { box } from "./box.js";
2
3
  const anonymousNames = (function* () {
3
4
  let count = 1;
4
5
  while (true) {
@@ -15,6 +16,7 @@ export function createTestAdapter(options = {}) {
15
16
  };
16
17
  const { parent, name = anonymousNames.next().value } = options;
17
18
  let scope = undefined;
19
+ let destroy = function* () { };
18
20
  const adapter = {
19
21
  parent,
20
22
  name,
@@ -36,47 +38,52 @@ export function createTestAdapter(options = {}) {
36
38
  setup.all.push(op);
37
39
  },
38
40
  runTest(op) {
39
- return run(() => box(function* () {
41
+ return run(function* () {
42
+ let init = yield* adapter["@@init@@"]();
43
+ if (!init.ok) {
44
+ return init;
45
+ }
46
+ let scope = init.value;
40
47
  const setups = adapter.lineage.reduce((all, adapter) => all.concat(adapter.setup.each), []);
41
- let scope = yield* adapter["@@init@@"]();
42
- let test = yield* scope.spawn(function* () {
43
- for (const setup of setups) {
44
- yield* setup();
48
+ let test = yield* scope.spawn(() => box(function* () {
49
+ for (let fn of setups) {
50
+ yield* fn();
45
51
  }
46
52
  yield* op();
47
- });
48
- yield* test;
49
- }()));
53
+ }));
54
+ return yield* test;
55
+ });
50
56
  },
51
- // no-op that will be replaced once initialze
52
- destroy: () => run(function* () { }),
53
57
  *["@@init@@"]() {
54
58
  if (scope) {
55
- return scope;
59
+ return yield* scope.operation;
56
60
  }
57
- let parentScope = parent
58
- ? yield* parent["@@init@@"]()
59
- : yield* useScope();
60
- let initialized = withResolvers();
61
- let task = yield* parentScope.spawn(function* () {
62
- scope = yield* useScope();
63
- for (let op of setup.all) {
64
- yield* op();
61
+ scope = withResolvers();
62
+ let parent = adapter.parent
63
+ ? yield* adapter.parent["@@init@@"]()
64
+ : Ok(createScope()[0]);
65
+ if (!parent.ok) {
66
+ scope.resolve(parent);
67
+ return yield* scope.operation;
68
+ }
69
+ let task = yield* parent.value.spawn(function* () {
70
+ let init = yield* box(function* () {
71
+ for (let initializer of adapter.setup.all) {
72
+ yield* initializer();
73
+ }
74
+ });
75
+ if (!init.ok) {
76
+ scope.resolve(init);
77
+ }
78
+ else {
79
+ scope.resolve(Ok(yield* useScope()));
80
+ yield* suspend();
65
81
  }
66
- initialized.resolve(scope);
67
- yield* suspend();
68
82
  });
69
- adapter.destroy = () => run(task.halt);
70
- return yield* initialized.operation;
83
+ destroy = task.halt;
84
+ return yield* scope.operation;
71
85
  },
86
+ destroy: () => run(destroy),
72
87
  };
73
88
  return adapter;
74
89
  }
75
- function* box(op) {
76
- try {
77
- return Ok(yield* op);
78
- }
79
- catch (error) {
80
- return Err(error);
81
- }
82
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effectionx/test-adapter",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "author": "engineering@frontside.com",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "sideEffects": false,
26
26
  "dependencies": {
27
- "effection": "^3"
27
+ "effection": "^3 || ^4.0.0-0"
28
28
  },
29
29
  "_generatedBy": "dnt@dev"
30
30
  }
@@ -0,0 +1,4 @@
1
+ import { type Operation, type Result } from "effection";
2
+ export declare function box<T>(content: () => Operation<T>): Operation<Result<T>>;
3
+ export declare function unbox<T>(result: Result<T>): T;
4
+ //# sourceMappingURL=box.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"box.d.ts","sourceRoot":"","sources":["../src/box.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,SAAS,EAAE,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AAEjE,wBAAiB,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAMzE;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAK7C"}
package/script/box.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.box = box;
4
+ exports.unbox = unbox;
5
+ const effection_1 = require("effection");
6
+ function* box(content) {
7
+ try {
8
+ return (0, effection_1.Ok)(yield* content());
9
+ }
10
+ catch (error) {
11
+ return (0, effection_1.Err)(error);
12
+ }
13
+ }
14
+ function unbox(result) {
15
+ if (result.ok) {
16
+ return result.value;
17
+ }
18
+ throw result.error;
19
+ }
package/script/mod.d.ts CHANGED
@@ -54,7 +54,7 @@ export interface TestAdapter {
54
54
  *
55
55
  * @ignore
56
56
  */
57
- ["@@init@@"](): Operation<Scope>;
57
+ ["@@init@@"](): Operation<Result<Scope>>;
58
58
  }
59
59
  export interface TestAdapterOptions {
60
60
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAGlE,MAAM,WAAW,aAAa;IAC5B,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAE9B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IAErC;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE;QAAE,GAAG,EAAE,aAAa,EAAE,CAAC;QAAC,IAAI,EAAE,aAAa,EAAE,CAAA;KAAE,CAAC;IAEhE;;;OAGG;IACH,QAAQ,CAAC,EAAE,EAAE,aAAa,GAAG,IAAI,CAAC;IAElC;;;OAGG;IACH,eAAe,CAAC,EAAE,EAAE,aA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AAa,GAAG,IAAI,CAAC;IAEzC;;;OAGG;IACH,OAAO,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAEnD;;;OAGG;IACH,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC;IAExB;;;;OAIG;IACH,CAAC,UAAU,CAAC,IAAI,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;CAC1C;AAED,MAAM,WAAW,kBAAkB;IACjC;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AASD;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,GAAE,kBAAuB,GAC/B,WAAW,CA4Fb"}
package/script/mod.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createTestAdapter = createTestAdapter;
4
4
  const effection_1 = require("effection");
5
+ const box_js_1 = require("./box.js");
5
6
  const anonymousNames = (function* () {
6
7
  let count = 1;
7
8
  while (true) {
@@ -18,6 +19,7 @@ function createTestAdapter(options = {}) {
18
19
  };
19
20
  const { parent, name = anonymousNames.next().value } = options;
20
21
  let scope = undefined;
22
+ let destroy = function* () { };
21
23
  const adapter = {
22
24
  parent,
23
25
  name,
@@ -39,47 +41,52 @@ function createTestAdapter(options = {}) {
39
41
  setup.all.push(op);
40
42
  },
41
43
  runTest(op) {
42
- return (0, effection_1.run)(() => box(function* () {
44
+ return (0, effection_1.run)(function* () {
45
+ let init = yield* adapter["@@init@@"]();
46
+ if (!init.ok) {
47
+ return init;
48
+ }
49
+ let scope = init.value;
43
50
  const setups = adapter.lineage.reduce((all, adapter) => all.concat(adapter.setup.each), []);
44
- let scope = yield* adapter["@@init@@"]();
45
- let test = yield* scope.spawn(function* () {
46
- for (const setup of setups) {
47
- yield* setup();
51
+ let test = yield* scope.spawn(() => (0, box_js_1.box)(function* () {
52
+ for (let fn of setups) {
53
+ yield* fn();
48
54
  }
49
55
  yield* op();
50
- });
51
- yield* test;
52
- }()));
56
+ }));
57
+ return yield* test;
58
+ });
53
59
  },
54
- // no-op that will be replaced once initialze
55
- destroy: () => (0, effection_1.run)(function* () { }),
56
60
  *["@@init@@"]() {
57
61
  if (scope) {
58
- return scope;
62
+ return yield* scope.operation;
59
63
  }
60
- let parentScope = parent
61
- ? yield* parent["@@init@@"]()
62
- : yield* (0, effection_1.useScope)();
63
- let initialized = (0, effection_1.withResolvers)();
64
- let task = yield* parentScope.spawn(function* () {
65
- scope = yield* (0, effection_1.useScope)();
66
- for (let op of setup.all) {
67
- yield* op();
64
+ scope = (0, effection_1.withResolvers)();
65
+ let parent = adapter.parent
66
+ ? yield* adapter.parent["@@init@@"]()
67
+ : (0, effection_1.Ok)((0, effection_1.createScope)()[0]);
68
+ if (!parent.ok) {
69
+ scope.resolve(parent);
70
+ return yield* scope.operation;
71
+ }
72
+ let task = yield* parent.value.spawn(function* () {
73
+ let init = yield* (0, box_js_1.box)(function* () {
74
+ for (let initializer of adapter.setup.all) {
75
+ yield* initializer();
76
+ }
77
+ });
78
+ if (!init.ok) {
79
+ scope.resolve(init);
80
+ }
81
+ else {
82
+ scope.resolve((0, effection_1.Ok)(yield* (0, effection_1.useScope)()));
83
+ yield* (0, effection_1.suspend)();
68
84
  }
69
- initialized.resolve(scope);
70
- yield* (0, effection_1.suspend)();
71
85
  });
72
- adapter.destroy = () => (0, effection_1.run)(task.halt);
73
- return yield* initialized.operation;
86
+ destroy = task.halt;
87
+ return yield* scope.operation;
74
88
  },
89
+ destroy: () => (0, effection_1.run)(destroy),
75
90
  };
76
91
  return adapter;
77
92
  }
78
- function* box(op) {
79
- try {
80
- return (0, effection_1.Ok)(yield* op);
81
- }
82
- catch (error) {
83
- return (0, effection_1.Err)(error);
84
- }
85
- }