@openstax/ts-utils 1.5.0 → 1.5.2

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,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.envConfig = exports.ENV_BUILD_CONFIGS = void 0;
4
- const assertions_1 = require("../assertions");
5
- const guards_1 = require("../guards");
4
+ const _1 = require(".");
6
5
  /**
7
6
  * A list of environment variables that were requested at build time. Used by webpack to
8
7
  * capture build-time environment variables values.
@@ -35,7 +34,17 @@ const envConfig = (name, type = 'build', defaultValue) => {
35
34
  // - https://github.com/webpack/webpack/issues/14800
36
35
  // - https://github.com/webpack/webpack/issues/5392
37
36
  const envs = { ...process.env, ...(typeof __PROCESS_ENV !== 'undefined' ? __PROCESS_ENV : {}) };
38
- return (0, assertions_1.assertDefined)((0, guards_1.ifDefined)(envs[name], defaultValue), `expected to find environment variable with name: ${name}`);
37
+ if (envs[name] === undefined) {
38
+ if (defaultValue === undefined) {
39
+ throw new Error(`expected to find environment variable with name: ${name}`);
40
+ }
41
+ else {
42
+ return (0, _1.resolveConfigValue)(defaultValue);
43
+ }
44
+ }
45
+ else {
46
+ return envs[name];
47
+ }
39
48
  };
40
49
  };
41
50
  exports.envConfig = envConfig;
@@ -1,6 +1,7 @@
1
1
  import { AccountsGateway } from '../accountsGateway';
2
2
  import { AuthProvider } from '../authProvider';
3
3
  import { Logger } from '../logger';
4
+ import { ActivityState } from './attempt-utils';
4
5
  import { LrsGateway } from '.';
5
6
  export interface Grade {
6
7
  scoreGiven: number;
@@ -13,7 +14,7 @@ export interface Grade {
13
14
  export declare const getRegistrationAttemptInfo: (lrs: LrsGateway, registration: string, options?: {
14
15
  anyUser?: boolean | undefined;
15
16
  } | undefined) => Promise<{
16
- [key: string]: import("./attempt-utils").ActivityState;
17
+ [key: string]: ActivityState;
17
18
  }>;
18
19
  export declare const getCurrentGrade: (services: {
19
20
  lrs: LrsGateway;
@@ -27,6 +28,7 @@ export declare const getAllGradesForAssignment: (services: {
27
28
  lrs: LrsGateway;
28
29
  logger: Logger;
29
30
  }, registration: string, options?: {
31
+ incompleteAttemptsCallback?: ((mappedInfo: [string, ActivityState][]) => Promise<Grade[]>) | undefined;
30
32
  platformId?: string | undefined;
31
33
  scoreMaximum?: number | undefined;
32
34
  } | undefined) => Promise<Grade[]>;
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.getAllGradesForAssignment = exports.getCurrentGrade = exports.getRegistrationAttemptInfo = void 0;
7
+ const partition_1 = __importDefault(require("lodash/fp/partition"));
4
8
  const __1 = require("../..");
5
9
  const attempt_utils_1 = require("./attempt-utils");
6
10
  const getRegistrationAttemptInfo = async (lrs, registration, options) => {
@@ -55,7 +59,12 @@ const getCurrentGrade = async (services, registration, options) => {
55
59
  exports.getCurrentGrade = getCurrentGrade;
56
60
  const getAllGradesForAssignment = async (services, registration, options) => {
57
61
  const infoPerUserUuid = await (0, exports.getRegistrationAttemptInfo)(services.lrs, registration, { anyUser: true });
58
- const mappedResults = await services.accountsGateway.mapUserUuids(infoPerUserUuid, services.logger, options === null || options === void 0 ? void 0 : options.platformId);
59
- return mappedResults.map(([userId, userInfo]) => getInfoGrade(userInfo, userId, options === null || options === void 0 ? void 0 : options.scoreMaximum));
62
+ const mappedInfo = await services.accountsGateway.mapUserUuids(infoPerUserUuid, services.logger, options === null || options === void 0 ? void 0 : options.platformId);
63
+ const gradeCompletedAttemptsOnly = (results) => results.map(([userId, userInfo]) => getInfoGrade(userInfo, userId, options === null || options === void 0 ? void 0 : options.scoreMaximum));
64
+ if (!(options === null || options === void 0 ? void 0 : options.incompleteAttemptsCallback)) {
65
+ return gradeCompletedAttemptsOnly(mappedInfo);
66
+ }
67
+ const [incompleteInfo, completedInfo] = (0, partition_1.default)((info) => info[1].currentAttemptCompleted === undefined)(mappedInfo);
68
+ return gradeCompletedAttemptsOnly(completedInfo).concat(await options.incompleteAttemptsCallback(incompleteInfo));
60
69
  };
61
70
  exports.getAllGradesForAssignment = getAllGradesForAssignment;