quidproquo-core 0.0.159 → 0.0.161

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.
@@ -14,5 +14,5 @@ export interface KeyValueStoreUpdateAction<Value> extends Action<KeyValueStoreUp
14
14
  type: KeyValueStoreActionType.Update;
15
15
  payload: KeyValueStoreUpdateActionPayload<Value>;
16
16
  }
17
- export type KeyValueStoreUpdateActionProcessor<Value> = ActionProcessor<KeyValueStoreUpdateAction<Value>, void>;
18
- export type KeyValueStoreUpdateActionRequester<Value> = ActionRequester<KeyValueStoreUpdateAction<Value>, void>;
17
+ export type KeyValueStoreUpdateActionProcessor<Value> = ActionProcessor<KeyValueStoreUpdateAction<Value>, Value>;
18
+ export type KeyValueStoreUpdateActionRequester<Value> = ActionRequester<KeyValueStoreUpdateAction<Value>, Value>;
@@ -1,2 +1,11 @@
1
1
  import { SystemRunParallelActionRequester } from './SystemRunParallelActionTypes';
2
- export declare function askParallel(stories: Array<any>): SystemRunParallelActionRequester;
2
+ /**
3
+ * @deprecated since version X.X. Please use {@link askRunParallel} instead.
4
+ * Runs n number of stories in parallel. This function is deprecated and has been replaced
5
+ * by a more efficient and type-supported version. The replacement function provides
6
+ * improved performance and better type support.
7
+ *
8
+ * @param {Array<any>} stories - An array of stories to be run in parallel.
9
+ * @returns {SystemRunParallelActionRequester} A requester for running actions in parallel.
10
+ */
11
+ export declare function askParallelDEPRECATED(stories: Array<any>): SystemRunParallelActionRequester;
@@ -2,12 +2,18 @@
2
2
  // NOTE: System actions have no platform specific processors and/or requestors
3
3
  // and therefore do not need to implement a SystemActionProcessor.ts
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.askParallel = void 0;
5
+ exports.askParallelDEPRECATED = void 0;
6
6
  const SystemBatchActionRequester_1 = require("./SystemBatchActionRequester");
7
- // TODO: Make this faster?
8
- // TODO: Type support
9
- // Runs n number of stories in parallel
10
- function* askParallel(stories) {
7
+ /**
8
+ * @deprecated since version X.X. Please use {@link askRunParallel} instead.
9
+ * Runs n number of stories in parallel. This function is deprecated and has been replaced
10
+ * by a more efficient and type-supported version. The replacement function provides
11
+ * improved performance and better type support.
12
+ *
13
+ * @param {Array<any>} stories - An array of stories to be run in parallel.
14
+ * @returns {SystemRunParallelActionRequester} A requester for running actions in parallel.
15
+ */
16
+ function* askParallelDEPRECATED(stories) {
11
17
  const itt = stories.map((s) => s[0](...s.slice(1)));
12
18
  let actions = itt.map((i) => i.next());
13
19
  let values = actions.map((a) => a.value);
@@ -34,4 +40,4 @@ function* askParallel(stories) {
34
40
  }
35
41
  }
36
42
  }
37
- exports.askParallel = askParallel;
43
+ exports.askParallelDEPRECATED = askParallelDEPRECATED;
@@ -1,2 +1,2 @@
1
1
  import { AskResponse } from '../../types';
2
- export declare function askFilter<T>(items: T[], askCallback: (item: T, index: number, srcArray: T[]) => AskResponse<T>): AskResponse<T[]>;
2
+ export declare function askFilter<T>(items: T[], askCallback: (item: T, index: number, srcArray: T[]) => AskResponse<boolean>): AskResponse<T[]>;
@@ -0,0 +1,2 @@
1
+ import { AskResponse } from '../../types';
2
+ export declare function askMapParallel<T, R>(items: T[], askCallback: (item: T, index: number, srcArray: T[]) => AskResponse<R>): AskResponse<R[]>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.askMapParallel = void 0;
4
+ const askRunParallel_1 = require("../system/askRunParallel");
5
+ function* askMapParallel(items, askCallback) {
6
+ const results = yield* (0, askRunParallel_1.askRunParallel)(items.map((item, index) => askCallback(item, index, items)));
7
+ return results;
8
+ }
9
+ exports.askMapParallel = askMapParallel;
@@ -1,3 +1,4 @@
1
1
  export * from './askFilter';
2
2
  export * from './askMap';
3
3
  export * from './askReduce';
4
+ export * from './askMapParallel';
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./askFilter"), exports);
18
18
  __exportStar(require("./askMap"), exports);
19
19
  __exportStar(require("./askReduce"), exports);
20
+ __exportStar(require("./askMapParallel"), exports);
@@ -1,2 +1,2 @@
1
- import { AskResponse, AskResponseReturnType, EitherActionResult } from "../../types";
1
+ import { AskResponse, AskResponseReturnType, EitherActionResult } from '../../types';
2
2
  export declare function askCatch<T extends AskResponse<any>>(storyIterator: T): AskResponse<EitherActionResult<AskResponseReturnType<T>>>;
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.askCatch = void 0;
4
4
  const types_1 = require("../../types");
5
5
  function* askCatch(storyIterator) {
6
- let nextResult = storyIterator.next();
7
6
  try {
7
+ let nextResult = storyIterator.next();
8
8
  while (!nextResult.done) {
9
9
  // Add returnErrors to the action, so we can "catch" errors
10
10
  const nextInput = yield Object.assign(Object.assign({}, nextResult.value), { returnErrors: true });
@@ -0,0 +1,4 @@
1
+ import { AskResponse, AskResponseReturnType } from '../../types';
2
+ export declare function askRunParallel<T extends Array<AskResponse<any>>>(storyRuntimes: [...T]): AskResponse<{
3
+ [K in keyof T]: AskResponseReturnType<T[K]>;
4
+ }>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.askRunParallel = void 0;
4
+ const actions_1 = require("../../actions");
5
+ function* askRunParallel(storyRuntimes) {
6
+ // No need to batch if we only have one story
7
+ if (storyRuntimes.length === 1) {
8
+ return [yield* storyRuntimes[0]];
9
+ }
10
+ // Begin executing the stories
11
+ const storyProgress = storyRuntimes.map((input) => ({
12
+ iterator: input,
13
+ iteratorResult: input.next(),
14
+ }));
15
+ while (true) {
16
+ // Get all the stories that are not done
17
+ const activeStoryProgress = storyProgress.filter((a) => !a.iteratorResult.done);
18
+ if (activeStoryProgress.length === 0) {
19
+ return storyProgress.map((a) => a.iteratorResult.value);
20
+ }
21
+ // Get the active story actions and batch them for results
22
+ const batchActions = activeStoryProgress.map((a) => a.iteratorResult.value);
23
+ const actionResults = yield* (0, actions_1.askBatch)(batchActions);
24
+ // continue each story with that new value
25
+ for (let i = 0; i < activeStoryProgress.length; i++) {
26
+ const storyIterator = activeStoryProgress[i];
27
+ storyIterator.iteratorResult = storyIterator.iterator.next(actionResults[i]);
28
+ }
29
+ }
30
+ }
31
+ exports.askRunParallel = askRunParallel;
@@ -1 +1,2 @@
1
- export * from "./askCatch";
1
+ export * from './askCatch';
2
+ export * from './askRunParallel';
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./askCatch"), exports);
18
+ __exportStar(require("./askRunParallel"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quidproquo-core",
3
- "version": "0.0.159",
3
+ "version": "0.0.161",
4
4
  "description": "",
5
5
  "main": "./lib/commonjs/index.js",
6
6
  "types": "./lib/commonjs/index.d.js",