quidproquo-core 0.0.21 → 0.0.24

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.
@@ -1,3 +1,5 @@
1
1
  export declare enum ConfigActionType {
2
- GetSecret = "@quidproquo-core/Config/GetSecret"
2
+ GetSecret = "@quidproquo-core/Config/GetSecret",
3
+ GetParameter = "@quidproquo-core/Config/GetParameter",
4
+ GetParameters = "@quidproquo-core/Config/GetParameters"
3
5
  }
@@ -4,4 +4,6 @@ exports.ConfigActionType = void 0;
4
4
  var ConfigActionType;
5
5
  (function (ConfigActionType) {
6
6
  ConfigActionType["GetSecret"] = "@quidproquo-core/Config/GetSecret";
7
+ ConfigActionType["GetParameter"] = "@quidproquo-core/Config/GetParameter";
8
+ ConfigActionType["GetParameters"] = "@quidproquo-core/Config/GetParameters";
7
9
  })(ConfigActionType = exports.ConfigActionType || (exports.ConfigActionType = {}));
@@ -0,0 +1,2 @@
1
+ import { ConfigGetParameterActionRequester } from './ConfigGetParameterActionTypes';
2
+ export declare function askConfigGetParameter(parameterName: string): ConfigGetParameterActionRequester;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.askConfigGetParameter = void 0;
4
+ const ConfigActionType_1 = require("./ConfigActionType");
5
+ function* askConfigGetParameter(parameterName) {
6
+ return yield { type: ConfigActionType_1.ConfigActionType.GetParameter, payload: { parameterName } };
7
+ }
8
+ exports.askConfigGetParameter = askConfigGetParameter;
@@ -0,0 +1,11 @@
1
+ import { Action, ActionProcessor, ActionRequester } from '../../types/Action';
2
+ import { ConfigActionType } from './ConfigActionType';
3
+ export interface ConfigGetParameterActionPayload {
4
+ parameterName: string;
5
+ }
6
+ export interface ConfigGetParameterAction extends Action<ConfigGetParameterActionPayload> {
7
+ type: ConfigActionType.GetParameter;
8
+ payload: ConfigGetParameterActionPayload;
9
+ }
10
+ export type ConfigGetParameterActionProcessor = ActionProcessor<ConfigGetParameterAction, string>;
11
+ export type ConfigGetParameterActionRequester = ActionRequester<ConfigGetParameterAction, string>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ import { ConfigGetParametersActionRequester } from './ConfigGetParametersActionTypes';
2
+ export declare function askConfigGetParameters(parameterNames: string[]): ConfigGetParametersActionRequester;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.askConfigGetParameters = void 0;
4
+ const ConfigActionType_1 = require("./ConfigActionType");
5
+ function* askConfigGetParameters(parameterNames) {
6
+ return yield { type: ConfigActionType_1.ConfigActionType.GetParameters, payload: { parameterNames } };
7
+ }
8
+ exports.askConfigGetParameters = askConfigGetParameters;
@@ -0,0 +1,11 @@
1
+ import { Action, ActionProcessor, ActionRequester } from '../../types/Action';
2
+ import { ConfigActionType } from './ConfigActionType';
3
+ export interface ConfigGetParametersActionPayload {
4
+ parameterNames: string[];
5
+ }
6
+ export interface ConfigGetParametersAction extends Action<ConfigGetParametersActionPayload> {
7
+ type: ConfigActionType.GetParameters;
8
+ payload: ConfigGetParametersActionPayload;
9
+ }
10
+ export type ConfigGetParametersActionProcessor = ActionProcessor<ConfigGetParametersAction, string[]>;
11
+ export type ConfigGetParametersActionRequester = ActionRequester<ConfigGetParametersAction, string[]>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,7 @@
1
1
  export * from './ConfigActionType';
2
+ export * from './ConfigGetParameterActionRequester';
3
+ export * from './ConfigGetParameterActionTypes';
4
+ export * from './ConfigGetParametersActionRequester';
5
+ export * from './ConfigGetParametersActionTypes';
2
6
  export * from './ConfigGetSecretActionRequester';
3
7
  export * from './ConfigGetSecretActionTypes';
@@ -15,5 +15,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./ConfigActionType"), exports);
18
+ __exportStar(require("./ConfigGetParameterActionRequester"), exports);
19
+ __exportStar(require("./ConfigGetParameterActionTypes"), exports);
20
+ __exportStar(require("./ConfigGetParametersActionRequester"), exports);
21
+ __exportStar(require("./ConfigGetParametersActionTypes"), exports);
18
22
  __exportStar(require("./ConfigGetSecretActionRequester"), exports);
19
23
  __exportStar(require("./ConfigGetSecretActionTypes"), exports);
@@ -2,7 +2,8 @@ export declare enum QPQCoreConfigSettingType {
2
2
  appName = "@quidproquo-core/config/AppName",
3
3
  storageDrive = "@quidproquo-core/config/storageDrive",
4
4
  schedule = "@quidproquo-core/config/schedule",
5
- secret = "@quidproquo-core/config/secret"
5
+ secret = "@quidproquo-core/config/secret",
6
+ parameter = "@quidproquo-core/config/parameter"
6
7
  }
7
8
  export interface QPQConfigSetting {
8
9
  configSettingType: string;
@@ -7,4 +7,5 @@ var QPQCoreConfigSettingType;
7
7
  QPQCoreConfigSettingType["storageDrive"] = "@quidproquo-core/config/storageDrive";
8
8
  QPQCoreConfigSettingType["schedule"] = "@quidproquo-core/config/schedule";
9
9
  QPQCoreConfigSettingType["secret"] = "@quidproquo-core/config/secret";
10
+ QPQCoreConfigSettingType["parameter"] = "@quidproquo-core/config/parameter";
10
11
  })(QPQCoreConfigSettingType = exports.QPQCoreConfigSettingType || (exports.QPQCoreConfigSettingType = {}));
@@ -1,4 +1,5 @@
1
1
  export * from './appName';
2
+ export * from './parameter';
2
3
  export * from './schedule';
3
4
  export * from './secret';
4
5
  export * from './storageDrive';
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./appName"), exports);
18
+ __exportStar(require("./parameter"), exports);
18
19
  __exportStar(require("./schedule"), exports);
19
20
  __exportStar(require("./secret"), exports);
20
21
  __exportStar(require("./storageDrive"), exports);
@@ -0,0 +1,7 @@
1
+ import { QPQConfigSetting } from '../QPQConfig';
2
+ export interface ParameterQPQConfigSetting extends QPQConfigSetting {
3
+ key: string;
4
+ value: string;
5
+ owned: boolean;
6
+ }
7
+ export declare const defineParameter: (key: string, value?: string) => ParameterQPQConfigSetting;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defineParameter = void 0;
4
+ const QPQConfig_1 = require("../QPQConfig");
5
+ const defineParameter = (key, value = '') => ({
6
+ configSettingType: QPQConfig_1.QPQCoreConfigSettingType.parameter,
7
+ key,
8
+ value,
9
+ owned: !!value,
10
+ });
11
+ exports.defineParameter = defineParameter;
@@ -1,5 +1,5 @@
1
1
  import { QPQConfig, QPQConfigSetting } from './config/QPQConfig';
2
- import { ScheduleQPQConfigSetting, SecretQPQConfigSetting } from './config/settings';
2
+ import { ScheduleQPQConfigSetting, SecretQPQConfigSetting, ParameterQPQConfigSetting } from './config/settings';
3
3
  export declare const getConfigSettings: <T extends QPQConfigSetting>(configs: QPQConfig, configSettingType: string) => T[];
4
4
  export declare const getConfigSetting: <T extends QPQConfigSetting>(configs: QPQConfig, serviceInfrastructureConfigType: string) => T | undefined;
5
5
  export declare const getAppName: (configs: QPQConfig) => string;
@@ -7,4 +7,5 @@ export declare const getStorageDriveNames: (configs: QPQConfig) => string[];
7
7
  export declare const getScheduleEvents: (configs: QPQConfig) => ScheduleQPQConfigSetting[];
8
8
  export declare const getAllSrcEntries: (configs: QPQConfig) => string[];
9
9
  export declare const getOwnedSecrets: (configs: QPQConfig) => SecretQPQConfigSetting[];
10
+ export declare const getOwnedParameters: (configs: QPQConfig) => ParameterQPQConfigSetting[];
10
11
  export declare const getSharedSecrets: (configs: QPQConfig) => SecretQPQConfigSetting[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSharedSecrets = exports.getOwnedSecrets = exports.getAllSrcEntries = exports.getScheduleEvents = exports.getStorageDriveNames = exports.getAppName = exports.getConfigSetting = exports.getConfigSettings = void 0;
3
+ exports.getSharedSecrets = exports.getOwnedParameters = exports.getOwnedSecrets = exports.getAllSrcEntries = exports.getScheduleEvents = exports.getStorageDriveNames = exports.getAppName = exports.getConfigSetting = exports.getConfigSettings = void 0;
4
4
  const QPQConfig_1 = require("./config/QPQConfig");
5
5
  const getConfigSettings = (configs, configSettingType) => {
6
6
  return configs.filter((c) => c.configSettingType === configSettingType);
@@ -40,6 +40,11 @@ const getOwnedSecrets = (configs) => {
40
40
  return secrets.filter((s) => s.owned);
41
41
  };
42
42
  exports.getOwnedSecrets = getOwnedSecrets;
43
+ const getOwnedParameters = (configs) => {
44
+ const secrets = (0, exports.getConfigSettings)(configs, QPQConfig_1.QPQCoreConfigSettingType.parameter);
45
+ return secrets.filter((s) => s.owned);
46
+ };
47
+ exports.getOwnedParameters = getOwnedParameters;
43
48
  const getSharedSecrets = (configs) => {
44
49
  const secrets = (0, exports.getConfigSettings)(configs, QPQConfig_1.QPQCoreConfigSettingType.secret);
45
50
  return secrets.filter((s) => !s.owned);
@@ -1,5 +1,3 @@
1
- import { Action, ActionProcessor } from './types/Action';
1
+ import { Action, ActionProcessorList } from './types/Action';
2
2
  import { StoryResult, StorySession } from './types/StorySession';
3
- export declare const createRuntime: (session: StorySession, actionProcessors: {
4
- [key: string]: ActionProcessor<any, any, any>;
5
- }, getTimeNow: () => string, logger: (res: StoryResult<any>) => void, newGuid: () => string) => <TArgs extends any[]>(story: (...args: TArgs) => Generator<any, any, Action<any>>, args: TArgs) => Promise<StoryResult<any>>;
3
+ export declare const createRuntime: (session: StorySession, actionProcessors: ActionProcessorList, getTimeNow: () => string, logger: (res: StoryResult<any>) => void, newGuid: () => string) => <TArgs extends any[]>(story: (...args: TArgs) => Generator<any, any, Action<any>>, args: TArgs) => Promise<StoryResult<any>>;
package/lib/qpqRuntime.js CHANGED
@@ -26,7 +26,7 @@ function processAction(action, actionProcessors, session) {
26
26
  if (!processor) {
27
27
  throw new Error(`Unable to process action: ${action === null || action === void 0 ? void 0 : action.type} from ${Object.keys(actionProcessors).join(', ')}`);
28
28
  }
29
- return yield processor(action.payload, session);
29
+ return yield processor(action.payload, session, actionProcessors);
30
30
  });
31
31
  }
32
32
  const createRuntime = (session, actionProcessors, getTimeNow, logger, newGuid) => {
@@ -47,12 +47,14 @@ const createRuntime = (session, actionProcessors, getTimeNow, logger, newGuid) =
47
47
  while (!action.done) {
48
48
  const executionTime = getTimeNow();
49
49
  const actionResult = yield processAction(action.value, actionProcessors, session);
50
- response.history.push({
50
+ const history = {
51
51
  act: action.value,
52
52
  res: actionResult,
53
53
  startedAt: executionTime,
54
54
  finishedAt: getTimeNow(),
55
- });
55
+ };
56
+ console.log(`${action.value.type}: took ${new Date(history.finishedAt).getTime() - new Date(history.startedAt).getTime()}ms`);
57
+ response.history.push(history);
56
58
  if ((0, actionLogic_1.isErroredActionResult)(actionResult)) {
57
59
  return Object.assign(Object.assign({}, response), { finishedAt: getTimeNow(), error: (0, actionLogic_1.resolveActionResultError)(actionResult) });
58
60
  }
@@ -75,6 +77,7 @@ const createRuntime = (session, actionProcessors, getTimeNow, logger, newGuid) =
75
77
  }
76
78
  const storyResult = Object.assign(Object.assign({}, response), { finishedAt: getTimeNow(), result: action.value });
77
79
  yield logger(storyResult);
80
+ console.log(`story took took ${new Date(storyResult.finishedAt).getTime() - new Date(storyResult.startedAt).getTime()}ms`);
78
81
  return storyResult;
79
82
  });
80
83
  }
@@ -5,5 +5,8 @@ export interface Action<T> {
5
5
  payload?: T;
6
6
  }
7
7
  export type ActionProcessorResult<T> = [T?, QPQError?];
8
- export type ActionProcessor<TAction extends Action<any>, TReturn = any, TActionPayload = TAction['payload']> = (payload: TActionPayload, session: StorySession) => Promise<ActionProcessorResult<TReturn>>;
8
+ export type ActionProcessor<TAction extends Action<any>, TReturn = any, TActionPayload = TAction['payload']> = (payload: TActionPayload, session: StorySession, actionProcessors: ActionProcessorList) => Promise<ActionProcessorResult<TReturn>>;
9
9
  export type ActionRequester<TAction extends Action<any>, TReturn = undefined, TQPQReturn = TReturn> = Generator<TAction, TReturn, TQPQReturn>;
10
+ export type ActionProcessorList = {
11
+ [key: string]: ActionProcessor<any, any, any>;
12
+ };
@@ -9,7 +9,8 @@ export declare enum ErrorTypeEnum {
9
9
  GenericError = "GenericError",
10
10
  NotImplemented = "NotImplemented",
11
11
  NoContent = "NoContent",
12
- BadRequest = "BadRequest"
12
+ BadRequest = "BadRequest",
13
+ Invalid = "Invalid"
13
14
  }
14
15
  export interface QPQError {
15
16
  errorType: ErrorTypeEnum;
@@ -28,4 +28,6 @@ var ErrorTypeEnum;
28
28
  ErrorTypeEnum["NoContent"] = "NoContent";
29
29
  // Bad data from client
30
30
  ErrorTypeEnum["BadRequest"] = "BadRequest";
31
+ // Bad data from client / invalid payload?
32
+ ErrorTypeEnum["Invalid"] = "Invalid";
31
33
  })(ErrorTypeEnum = exports.ErrorTypeEnum || (exports.ErrorTypeEnum = {}));
package/package.json CHANGED
@@ -1,30 +1,30 @@
1
- {
2
- "name": "quidproquo-core",
3
- "version": "0.0.21",
4
- "description": "",
5
- "main": "./lib/index.js",
6
- "types": "./lib/index.d.js",
7
- "files": [
8
- "lib/**/*"
9
- ],
10
- "scripts": {
11
- "test": "echo \"Error: no test specified\" && exit 1",
12
- "build": "npx rimraf lib && tsc",
13
- "watch": "tsc -w"
14
- },
15
- "repository": {
16
- "type": "git",
17
- "url": "git+https://github.com/joe-coady/quidproquo.git"
18
- },
19
- "keywords": [],
20
- "author": "",
21
- "license": "MIT",
22
- "bugs": {
23
- "url": "https://github.com/joe-coady/quidproquo/issues"
24
- },
25
- "homepage": "https://github.com/joe-coady/quidproquo#readme",
26
- "devDependencies": {
27
- "quidproquo-tsconfig": "*",
28
- "typescript": "^4.9.3"
29
- }
30
- }
1
+ {
2
+ "name": "quidproquo-core",
3
+ "version": "0.0.24",
4
+ "description": "",
5
+ "main": "./lib/index.js",
6
+ "types": "./lib/index.d.js",
7
+ "files": [
8
+ "lib/**/*"
9
+ ],
10
+ "scripts": {
11
+ "test": "echo \"Error: no test specified\" && exit 1",
12
+ "build": "npx rimraf lib && tsc",
13
+ "watch": "tsc -w"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/joe-coady/quidproquo.git"
18
+ },
19
+ "keywords": [],
20
+ "author": "",
21
+ "license": "MIT",
22
+ "bugs": {
23
+ "url": "https://github.com/joe-coady/quidproquo/issues"
24
+ },
25
+ "homepage": "https://github.com/joe-coady/quidproquo#readme",
26
+ "devDependencies": {
27
+ "quidproquo-tsconfig": "*",
28
+ "typescript": "^4.9.3"
29
+ }
30
+ }