@gbl-uzh/platform 0.2.10 → 0.2.12

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/dist/index.d.ts CHANGED
@@ -16,17 +16,17 @@ declare enum LearningElementState {
16
16
  ATTEMPTED = "ATTEMPTED",
17
17
  SOLVED = "SOLVED"
18
18
  }
19
- declare type Notification<NotificationType> = {
19
+ type Notification<NotificationType> = {
20
20
  type: NotificationType;
21
21
  sub?: string;
22
22
  facts?: any;
23
23
  };
24
- declare type Event<EventType> = {
24
+ type Event<EventType> = {
25
25
  type: EventType;
26
26
  sub?: string;
27
27
  facts?: any;
28
28
  };
29
- declare type Output<OutputType, NotificationType, EventType> = {
29
+ type Output<OutputType, NotificationType, EventType> = {
30
30
  type: OutputType;
31
31
  extras?: any;
32
32
  result: any;
@@ -35,7 +35,7 @@ declare type Output<OutputType, NotificationType, EventType> = {
35
35
  actions?: any[];
36
36
  isDirty: boolean;
37
37
  };
38
- declare type Action<ActionType, PayloadType, PrismaType> = {
38
+ type Action<ActionType, PayloadType, PrismaType> = {
39
39
  type: ActionType;
40
40
  payload: PayloadType;
41
41
  ctx?: CtxWithPrisma<PrismaType>;
@@ -130,7 +130,7 @@ declare namespace EventService {
130
130
  };
131
131
  }
132
132
 
133
- declare type Context$1 = CtxWithPrisma<PrismaClient>;
133
+ type Context$1 = CtxWithPrisma<PrismaClient>;
134
134
  interface CreateGameArgs {
135
135
  name: string;
136
136
  playerCount: number;
@@ -288,7 +288,7 @@ declare namespace GameService {
288
288
  };
289
289
  }
290
290
 
291
- declare type Context = CtxWithPrisma<PrismaClient>;
291
+ type Context = CtxWithPrisma<PrismaClient>;
292
292
  interface PerformActionArgs<ActionTypes> {
293
293
  gameId: number;
294
294
  periodIx: number;
package/dist/index.js CHANGED
@@ -195,12 +195,10 @@ function prepareAchievementData({
195
195
  };
196
196
  }
197
197
  async function receiveEvent(event, definedEvents, definedLevels, prisma) {
198
- var _a;
199
198
  const matchingEvent = definedEvents.find((item) => item.id === event.type);
200
- if (matchingEvent && ((_a = matchingEvent.achievements) == null ? void 0 : _a.length) > 0) {
199
+ if (matchingEvent && matchingEvent.achievements?.length > 0) {
201
200
  const awardedAchievements = await matchingEvent.achievements.reduce(
202
201
  async (acc, achievement) => {
203
- var _a2;
204
202
  if (achievement.when === "FIRST" /* First */ && event.ctx.achievements.includes(achievement.id)) {
205
203
  return acc;
206
204
  }
@@ -250,7 +248,7 @@ async function receiveEvent(event, definedEvents, definedLevels, prisma) {
250
248
  achievementKeys: [...acc.achievementKeys, achievement.id],
251
249
  rewards: {
252
250
  ...acc.rewards,
253
- xp: (acc.rewards.xp ?? 0) + (((_a2 = achievement.reward) == null ? void 0 : _a2.xp) ?? 0)
251
+ xp: (acc.rewards.xp ?? 0) + (achievement.reward?.xp ?? 0)
254
252
  }
255
253
  };
256
254
  },
@@ -439,7 +437,6 @@ async function createGame({ name, playerCount }, ctx, { roleAssigner }) {
439
437
  });
440
438
  }
441
439
  async function addGamePeriod({ gameId, facts }, ctx, { schema, reducers }) {
442
- var _a, _b, _c, _d;
443
440
  const validatedFacts = schema.validateSync(facts);
444
441
  const game = await ctx.prisma.game.findUnique({
445
442
  where: {
@@ -464,13 +461,13 @@ async function addGamePeriod({ gameId, facts }, ctx, { schema, reducers }) {
464
461
  });
465
462
  if (!game)
466
463
  return null;
467
- const index = ((_a = game.periods[0]) == null ? void 0 : _a.index) + 1 || 0;
464
+ const index = game.periods[0]?.index + 1 || 0;
468
465
  const { result: initializedFacts } = reducers.Period.apply(validatedFacts, {
469
466
  type: reducers.Period.ActionTypes.PERIOD_INITIALIZE,
470
467
  payload: {
471
468
  periodFacts: validatedFacts,
472
- previousPeriodFacts: (_b = game.periods[0]) == null ? void 0 : _b.facts,
473
- previousSegmentFacts: (_d = (_c = game.periods[0]) == null ? void 0 : _c.segments[0]) == null ? void 0 : _d.facts,
469
+ previousPeriodFacts: game.periods[0]?.facts,
470
+ previousSegmentFacts: game.periods[0]?.segments[0]?.facts,
474
471
  periodIx: index
475
472
  }
476
473
  });
@@ -518,7 +515,6 @@ async function addPeriodSegment({
518
515
  learningElements,
519
516
  storyElements
520
517
  }, ctx, { schema, reducers }) {
521
- var _a, _b;
522
518
  const validatedFacts = schema.validateSync(facts);
523
519
  const period = await ctx.prisma.period.findUnique({
524
520
  where: {
@@ -538,12 +534,12 @@ async function addPeriodSegment({
538
534
  });
539
535
  if (!period)
540
536
  return null;
541
- const index = ((_a = period.segments[0]) == null ? void 0 : _a.index) + 1 || 0;
537
+ const index = period.segments[0]?.index + 1 || 0;
542
538
  const { result: initializedFacts } = reducers.Segment.apply(validatedFacts, {
543
539
  type: reducers.Segment.ActionTypes.SEGMENT_INITIALIZE,
544
540
  payload: {
545
541
  periodFacts: period.facts,
546
- previousSegmentFacts: (_b = period.segments[0]) == null ? void 0 : _b.facts,
542
+ previousSegmentFacts: period.segments[0]?.facts,
547
543
  segmentIx: index,
548
544
  segmentCount: 4,
549
545
  periodIx
@@ -606,7 +602,6 @@ async function addPeriodSegment({
606
602
  });
607
603
  }
608
604
  async function activateNextPeriod({ gameId }, ctx, { reducers }) {
609
- var _a, _b, _c, _d, _e;
610
605
  const game = await ctx.prisma.game.findUnique({
611
606
  where: {
612
607
  id: gameId
@@ -652,7 +647,7 @@ async function activateNextPeriod({ gameId }, ctx, { reducers }) {
652
647
  if (!game)
653
648
  return null;
654
649
  const currentPeriodIx = game.activePeriodIx;
655
- const currentSegmentIx = (_a = game.activePeriod) == null ? void 0 : _a.activeSegmentIx;
650
+ const currentSegmentIx = game.activePeriod?.activeSegmentIx;
656
651
  const nextPeriodIx = currentPeriodIx + 1;
657
652
  switch (game.status) {
658
653
  case "SCHEDULED" /* Scheduled */: {
@@ -662,7 +657,7 @@ async function activateNextPeriod({ gameId }, ctx, { reducers }) {
662
657
  players: game.players,
663
658
  activePeriodIx: currentPeriodIx,
664
659
  gameId: game.id,
665
- periodFacts: (_b = game.periods) == null ? void 0 : _b[0].facts
660
+ periodFacts: game.periods?.[0].facts
666
661
  },
667
662
  ctx,
668
663
  { reducers }
@@ -703,7 +698,7 @@ async function activateNextPeriod({ gameId }, ctx, { reducers }) {
703
698
  return result;
704
699
  }
705
700
  case "RUNNING" /* Running */: {
706
- if (!((_c = game.activePeriod) == null ? void 0 : _c.activeSegment) || !currentSegmentIx)
701
+ if (!game.activePeriod?.activeSegment || !currentSegmentIx)
707
702
  return null;
708
703
  const { results, extras } = computeSegmentEndResults(game, ctx, {
709
704
  reducers
@@ -764,7 +759,7 @@ async function activateNextPeriod({ gameId }, ctx, { reducers }) {
764
759
  return result;
765
760
  }
766
761
  case "CONSOLIDATION" /* Consolidation */: {
767
- if (!((_d = game.activePeriod) == null ? void 0 : _d.activeSegment))
762
+ if (!game.activePeriod?.activeSegment)
768
763
  return null;
769
764
  const { results, extras, promises } = await computePeriodEndResults(
770
765
  {
@@ -818,7 +813,7 @@ async function activateNextPeriod({ gameId }, ctx, { reducers }) {
818
813
  return result;
819
814
  }
820
815
  case "RESULTS" /* Results */: {
821
- if (!((_e = game.activePeriod) == null ? void 0 : _e.nextPeriod)) {
816
+ if (!game.activePeriod?.nextPeriod) {
822
817
  return null;
823
818
  }
824
819
  const { results, extras } = computePeriodStartResults(
@@ -863,7 +858,6 @@ async function activateNextPeriod({ gameId }, ctx, { reducers }) {
863
858
  }
864
859
  }
865
860
  async function activateNextSegment({ gameId }, ctx, { reducers }) {
866
- var _a, _b;
867
861
  const game = await ctx.prisma.game.findUnique({
868
862
  where: {
869
863
  id: gameId
@@ -893,7 +887,7 @@ async function activateNextSegment({ gameId }, ctx, { reducers }) {
893
887
  }
894
888
  }
895
889
  });
896
- if (!(game == null ? void 0 : game.activePeriod))
890
+ if (!game?.activePeriod)
897
891
  return null;
898
892
  const currentPeriodIx = game.activePeriodIx;
899
893
  const currentSegmentIx = game.activePeriod.activeSegmentIx;
@@ -966,7 +960,7 @@ async function activateNextSegment({ gameId }, ctx, { reducers }) {
966
960
  return result;
967
961
  }
968
962
  case "RUNNING" /* Running */: {
969
- if (!((_b = (_a = game.activePeriod) == null ? void 0 : _a.activeSegment) == null ? void 0 : _b.nextSegment)) {
963
+ if (!game.activePeriod?.activeSegment?.nextSegment) {
970
964
  return null;
971
965
  }
972
966
  const { results, extras } = computeSegmentEndResults(game, ctx, {
@@ -1483,7 +1477,6 @@ __export(PlayService_exports, {
1483
1477
  updateReadyState: () => updateReadyState
1484
1478
  });
1485
1479
  async function performAction(args, ctx, { reducers }) {
1486
- var _a;
1487
1480
  const periodIx_segmentIx_playerId_type = {
1488
1481
  periodIx: args.periodIx,
1489
1482
  segmentIx: args.segmentIx,
@@ -1510,7 +1503,7 @@ async function performAction(args, ctx, { reducers }) {
1510
1503
  type: args.actionType,
1511
1504
  payload: {
1512
1505
  playerArgs: args.facts,
1513
- segmentFacts: (_a = previousResult.segment) == null ? void 0 : _a.facts,
1506
+ segmentFacts: previousResult.segment?.facts,
1514
1507
  periodFacts: previousResult.period.facts
1515
1508
  }
1516
1509
  });
@@ -1595,7 +1588,7 @@ async function saveDecisions(args, ctx) {
1595
1588
  }
1596
1589
  }
1597
1590
  });
1598
- if (!(game == null ? void 0 : game.activePeriod))
1591
+ if (!game?.activePeriod)
1599
1592
  return null;
1600
1593
  if (args.decisionType !== game.status) {
1601
1594
  throw new Error("INVALID_DECISION");
@@ -1672,7 +1665,7 @@ async function getPlayerResult(args, ctx) {
1672
1665
  }
1673
1666
  }
1674
1667
  });
1675
- if (!(currentGame == null ? void 0 : currentGame.activePeriod))
1668
+ if (!currentGame?.activePeriod)
1676
1669
  return null;
1677
1670
  const previousResults = ctx.prisma.playerResult.findMany({
1678
1671
  where: {
@@ -33,7 +33,7 @@ module.exports = __toCommonJS(apollo_exports);
33
33
  var import_client = require("@apollo/client");
34
34
  var import_http = require("@apollo/client/link/http");
35
35
  var import_utilities = require("@apollo/client/utilities");
36
- var import_config = __toESM(require("next/config"));
36
+ var import_node_assert = __toESM(require("assert"));
37
37
  var import_react = require("react");
38
38
 
39
39
  // src/lib/SSELink.ts
@@ -69,15 +69,15 @@ var SSELink_default = SSELink;
69
69
  // src/lib/apollo.ts
70
70
  var apolloClient;
71
71
  function createIsomorphLink() {
72
- const { publicRuntimeConfig, serverRuntimeConfig } = (0, import_config.default)();
72
+ (0, import_node_assert.default)(typeof process.env.NEXT_PUBLIC_API_URL === "string");
73
73
  const isBrowser = typeof window !== "undefined";
74
74
  let httpLink = new import_http.HttpLink({
75
- uri: publicRuntimeConfig.apiURL,
75
+ uri: process.env.NEXT_PUBLIC_API_URL,
76
76
  credentials: "same-origin"
77
77
  });
78
78
  if (isBrowser) {
79
79
  const sseLink = new SSELink_default({
80
- url: publicRuntimeConfig.apiURL
80
+ url: process.env.NEXT_PUBLIC_API_URL
81
81
  });
82
82
  httpLink = (0, import_client.split)(
83
83
  ({ query }) => {
package/dist/nexus.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import * as nexus_dist_core from 'nexus/dist/core';
2
- import * as yup from 'yup';
3
2
 
4
3
  declare const GameStatus: nexus_dist_core.NexusEnumTypeDef<"GameStatus">;
5
4
  declare const Game: nexus_dist_core.NexusObjectTypeDef<"Game">;
@@ -13,48 +12,13 @@ declare const LearningElement: nexus_dist_core.NexusObjectTypeDef<"LearningEleme
13
12
 
14
13
  interface GenerateBaseMutationsArgs {
15
14
  reducers?: any;
15
+ schemas?: any;
16
+ inputTypes?: any;
16
17
  roleAssigner?: (ix: number) => void;
17
18
  }
18
- declare function generateBaseMutations({ reducers, roleAssigner, }?: GenerateBaseMutationsArgs): nexus_dist_core.NexusObjectTypeDef<"Mutation">;
19
+ declare function generateBaseMutations<PeriodFacts, PeriodSegmentFacts>({ reducers, roleAssigner, schemas, inputTypes }?: GenerateBaseMutationsArgs): nexus_dist_core.NexusObjectTypeDef<"Mutation">;
19
20
  declare const Mutation: nexus_dist_core.NexusObjectTypeDef<"Mutation">;
20
21
 
21
- declare const PeriodFactsSchema: yup.ObjectSchema<{
22
- spotTradingEnabled: boolean;
23
- futuresTradingEnabled: boolean;
24
- optionsTradingEnabled: boolean;
25
- interestRate: number;
26
- convenienceYield: number;
27
- storageCostPerItem: number;
28
- initialSpotPrice: number | undefined;
29
- randomSeed: number | undefined;
30
- trendE: number;
31
- trendGap: number;
32
- }, yup.AnyObject, {
33
- spotTradingEnabled: true;
34
- futuresTradingEnabled: false;
35
- optionsTradingEnabled: false;
36
- interestRate: 0.01;
37
- convenienceYield: 0.008;
38
- storageCostPerItem: 50;
39
- initialSpotPrice: undefined;
40
- randomSeed: undefined;
41
- trendE: 0.005;
42
- trendGap: 0.02;
43
- }, "">;
44
- interface PeriodFacts extends yup.InferType<typeof PeriodFactsSchema> {
45
- }
46
- declare const PeriodFactsInput: nexus_dist_core.NexusInputObjectTypeDef<"PeriodFactsInput">;
47
- declare const PeriodSegmentFactsSchema: yup.ObjectSchema<{
48
- trendE: number | undefined;
49
- trendGap: number | undefined;
50
- }, yup.AnyObject, {
51
- trendE: undefined;
52
- trendGap: undefined;
53
- }, "">;
54
- interface PeriodSegmentFacts extends yup.InferType<typeof PeriodSegmentFactsSchema> {
55
- }
56
- declare const PeriodSegmentFactsInput: nexus_dist_core.NexusInputObjectTypeDef<"PeriodSegmentFactsInput">;
57
-
58
22
  declare const PlayerDecisionType: nexus_dist_core.NexusEnumTypeDef<"PlayerDecisionType">;
59
23
  declare const PlayerResultType: nexus_dist_core.NexusEnumTypeDef<"PlayerResultType">;
60
24
  declare const PlayerLevel: nexus_dist_core.NexusObjectTypeDef<"PlayerLevel">;
@@ -75,4 +39,4 @@ declare const DateScalar: nexus_dist_core.AllNexusOutputTypeDefs;
75
39
  declare const UserRole: nexus_dist_core.NexusEnumTypeDef<"UserRole">;
76
40
  declare const Event: nexus_dist_core.NexusObjectTypeDef<"Event">;
77
41
 
78
- export { DateScalar, Event, Game, GameStatus, JsonScalar, LearningAnswerOption, LearningElement, LearningElementAttempt, LearningElementState, Mutation, Period, PeriodFacts, PeriodFactsInput, PeriodFactsSchema, PeriodSegment, PeriodSegmentFacts, PeriodSegmentFactsInput, PeriodSegmentFactsSchema, Player, PlayerAction, PlayerDecision, PlayerDecisionType, PlayerLevel, PlayerResult, PlayerResultType, PlayerState, Query, Subscription, UserRole, generateBaseMutations, generateBaseQueries, generateBaseSubscriptions };
42
+ export { DateScalar, Event, Game, GameStatus, JsonScalar, LearningAnswerOption, LearningElement, LearningElementAttempt, LearningElementState, Mutation, Period, PeriodSegment, Player, PlayerAction, PlayerDecision, PlayerDecisionType, PlayerLevel, PlayerResult, PlayerResultType, PlayerState, Query, Subscription, UserRole, generateBaseMutations, generateBaseQueries, generateBaseSubscriptions };