@gbl-uzh/platform 0.2.14 → 0.3.1

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/LICENSE.md ADDED
@@ -0,0 +1,67 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+
6
+ Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
7
+
8
+ This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below.
9
+
10
+ 0. Additional Definitions.
11
+
12
+ As used herein, “this License” refers to version 3 of the GNU Lesser General Public License, and the “GNU GPL” refers to version 3 of the GNU General Public License.
13
+
14
+ “The Library” refers to a covered work governed by this License, other than an Application or a Combined Work as defined below.
15
+
16
+ An “Application” is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library.
17
+
18
+ A “Combined Work” is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the “Linked Version”.
19
+
20
+ The “Minimal Corresponding Source” for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version.
21
+
22
+ The “Corresponding Application Code” for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work.
23
+
24
+ 1. Exception to Section 3 of the GNU GPL.
25
+
26
+ You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL.
27
+
28
+ 2. Conveying Modified Versions.
29
+
30
+ If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version:
31
+
32
+ a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or
33
+ b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy.
34
+
35
+ 3. Object Code Incorporating Material from Library Header Files.
36
+
37
+ The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following:
38
+
39
+ a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License.
40
+ b) Accompany the object code with a copy of the GNU GPL and this license document.
41
+
42
+ 4. Combined Works.
43
+
44
+ You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following:
45
+
46
+ a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License.
47
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license document.
48
+ c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document.
49
+ d) Do one of the following:
50
+ 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.
51
+ 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user’s computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version.
52
+ e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.)
53
+
54
+ 5. Combined Libraries.
55
+
56
+ You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following:
57
+
58
+ a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License.
59
+ b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.
60
+
61
+ 6. Revised Versions of the GNU Lesser General Public License.
62
+
63
+ The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
64
+
65
+ Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation.
66
+
67
+ If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy’s public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.
package/dist/index.d.ts CHANGED
@@ -81,7 +81,7 @@ interface CreateLoginTokenArgs {
81
81
  token?: string;
82
82
  gameId?: number;
83
83
  }
84
- declare function createLoginToken({ sub, role, ...extra }: CreateLoginTokenArgs): string;
84
+ declare function createLoginToken({ sub, role, ...extra }: CreateLoginTokenArgs): any;
85
85
  interface LoginAsTeamArgs {
86
86
  token: string;
87
87
  }
@@ -114,16 +114,16 @@ declare function publishUserNotification(ctx: {
114
114
  };
115
115
  }, events?: any): void;
116
116
 
117
- declare const EventService_receiveEvents: typeof receiveEvents;
118
- declare const EventService_receiveEvent: typeof receiveEvent;
119
117
  declare const EventService_publishGlobalNotification: typeof publishGlobalNotification;
120
118
  declare const EventService_publishUserNotification: typeof publishUserNotification;
119
+ declare const EventService_receiveEvent: typeof receiveEvent;
120
+ declare const EventService_receiveEvents: typeof receiveEvents;
121
121
  declare namespace EventService {
122
122
  export {
123
- EventService_receiveEvents as receiveEvents,
124
- EventService_receiveEvent as receiveEvent,
125
123
  EventService_publishGlobalNotification as publishGlobalNotification,
126
124
  EventService_publishUserNotification as publishUserNotification,
125
+ EventService_receiveEvent as receiveEvent,
126
+ EventService_receiveEvents as receiveEvents,
127
127
  };
128
128
  }
129
129
 
@@ -162,11 +162,25 @@ declare function addPeriodSegment<TFacts>({ gameId, periodIx, facts, learningEle
162
162
  interface ActivateNextPeriodArgs {
163
163
  gameId: number;
164
164
  }
165
- declare function activateNextPeriod({ gameId }: ActivateNextPeriodArgs, ctx: Context$1, { reducers }: CtxWithFacts<any, PrismaClient>): Promise<[_prisma_client.Game, _prisma_client.Period, ...any[]] | null>;
165
+ declare function activateNextPeriod({ gameId }: ActivateNextPeriodArgs, ctx: Context$1, { reducers }: CtxWithFacts<any, PrismaClient>): Promise<[_prisma_client.Game & {
166
+ periods: (_prisma_client.Period & {
167
+ segments: _prisma_client.PeriodSegment[];
168
+ })[];
169
+ }, _prisma_client.Period, ...any[]] | null>;
166
170
  interface ActivateSegmentArgs {
167
171
  gameId: number;
168
172
  }
169
- declare function activateNextSegment({ gameId }: ActivateSegmentArgs, ctx: Context$1, { reducers }: CtxWithFacts<any, PrismaClient>): Promise<[_prisma_client.Game, _prisma_client.Period, _prisma_client.PeriodSegment, ...any[]] | [_prisma_client.Game, _prisma_client.PeriodSegment & {
173
+ declare function activateNextSegment({ gameId }: ActivateSegmentArgs, ctx: Context$1, { reducers }: CtxWithFacts<any, PrismaClient>): Promise<[_prisma_client.Game & {
174
+ periods: (_prisma_client.Period & {
175
+ segments: _prisma_client.PeriodSegment[];
176
+ })[];
177
+ players: _prisma_client.Player[];
178
+ }, _prisma_client.Period, _prisma_client.PeriodSegment, ...any[]] | [_prisma_client.Game & {
179
+ periods: (_prisma_client.Period & {
180
+ segments: _prisma_client.PeriodSegment[];
181
+ })[];
182
+ players: _prisma_client.Player[];
183
+ }, _prisma_client.PeriodSegment & {
170
184
  results: _prisma_client.PlayerResult[];
171
185
  }, ...any[]] | null>;
172
186
  declare const PlayerFactsSchema: yup.ObjectSchema<{
@@ -250,38 +264,38 @@ declare function computeSegmentEndResults(game: any, ctx: any, { reducers }: {
250
264
  extras: any[];
251
265
  };
252
266
 
253
- declare const GameService_createGame: typeof createGame;
254
- declare const GameService_addGamePeriod: typeof addGamePeriod;
255
- declare const GameService_addPeriodSegment: typeof addPeriodSegment;
267
+ type GameService_PlayerFacts = PlayerFacts;
256
268
  declare const GameService_activateNextPeriod: typeof activateNextPeriod;
257
269
  declare const GameService_activateNextSegment: typeof activateNextSegment;
258
- type GameService_PlayerFacts = PlayerFacts;
259
- declare const GameService_updatePlayerData: typeof updatePlayerData;
260
- declare const GameService_getGames: typeof getGames;
270
+ declare const GameService_addGamePeriod: typeof addGamePeriod;
271
+ declare const GameService_addPeriodSegment: typeof addPeriodSegment;
272
+ declare const GameService_computePeriodEndResults: typeof computePeriodEndResults;
273
+ declare const GameService_computePeriodStartResults: typeof computePeriodStartResults;
274
+ declare const GameService_computeSegmentEndResults: typeof computeSegmentEndResults;
275
+ declare const GameService_computeSegmentStartResults: typeof computeSegmentStartResults;
276
+ declare const GameService_createGame: typeof createGame;
261
277
  declare const GameService_getGame: typeof getGame;
262
278
  declare const GameService_getGameFromContext: typeof getGameFromContext;
279
+ declare const GameService_getGames: typeof getGames;
263
280
  declare const GameService_getLearningElements: typeof getLearningElements;
264
- declare const GameService_computePeriodStartResults: typeof computePeriodStartResults;
265
- declare const GameService_computePeriodEndResults: typeof computePeriodEndResults;
266
- declare const GameService_computeSegmentStartResults: typeof computeSegmentStartResults;
267
- declare const GameService_computeSegmentEndResults: typeof computeSegmentEndResults;
281
+ declare const GameService_updatePlayerData: typeof updatePlayerData;
268
282
  declare namespace GameService {
269
283
  export {
270
- GameService_createGame as createGame,
271
- GameService_addGamePeriod as addGamePeriod,
272
- GameService_addPeriodSegment as addPeriodSegment,
284
+ GameService_PlayerFacts as PlayerFacts,
273
285
  GameService_activateNextPeriod as activateNextPeriod,
274
286
  GameService_activateNextSegment as activateNextSegment,
275
- GameService_PlayerFacts as PlayerFacts,
276
- GameService_updatePlayerData as updatePlayerData,
277
- GameService_getGames as getGames,
287
+ GameService_addGamePeriod as addGamePeriod,
288
+ GameService_addPeriodSegment as addPeriodSegment,
289
+ GameService_computePeriodEndResults as computePeriodEndResults,
290
+ GameService_computePeriodStartResults as computePeriodStartResults,
291
+ GameService_computeSegmentEndResults as computeSegmentEndResults,
292
+ GameService_computeSegmentStartResults as computeSegmentStartResults,
293
+ GameService_createGame as createGame,
278
294
  GameService_getGame as getGame,
279
295
  GameService_getGameFromContext as getGameFromContext,
296
+ GameService_getGames as getGames,
280
297
  GameService_getLearningElements as getLearningElements,
281
- GameService_computePeriodStartResults as computePeriodStartResults,
282
- GameService_computePeriodEndResults as computePeriodEndResults,
283
- GameService_computeSegmentStartResults as computeSegmentStartResults,
284
- GameService_computeSegmentEndResults as computeSegmentEndResults,
298
+ GameService_updatePlayerData as updatePlayerData,
285
299
  };
286
300
  }
287
301
 
@@ -337,10 +351,10 @@ declare function getPlayerResult(args: GetPlayerResultArgs, ctx: Context): Promi
337
351
  visitedStoryElements: _prisma_client.StoryElement[];
338
352
  };
339
353
  }) | null;
340
- previousResults: _prisma_client.PrismaPromise<(_prisma_client.PlayerResult & {
354
+ previousResults: _prisma_client.Prisma.PrismaPromise<(_prisma_client.PlayerResult & {
341
355
  period: _prisma_client.Period;
342
356
  })[]>;
343
- transactions: _prisma_client.PrismaPromise<_prisma_client.PlayerAction[]>;
357
+ transactions: _prisma_client.Prisma.PrismaPromise<_prisma_client.PlayerAction[]>;
344
358
  } | null>;
345
359
  interface GetPlayerDataArgs {
346
360
  playerId: string;
@@ -402,29 +416,29 @@ declare function getPastResults(args: any, ctx: Context): Promise<(_prisma_clien
402
416
  })[] | null>;
403
417
  declare function updateReadyState(args: any, ctx: Context): Promise<_prisma_client.Player>;
404
418
 
405
- declare const PlayService_performAction: typeof performAction;
406
- declare const PlayService_saveDecisions: typeof saveDecisions;
407
- declare const PlayService_getPlayerResult: typeof getPlayerResult;
408
- declare const PlayService_getPlayerData: typeof getPlayerData;
409
- declare const PlayService_getLearningElement: typeof getLearningElement;
410
419
  declare const PlayService_attemptLearningElement: typeof attemptLearningElement;
411
- declare const PlayService_markStoryElement: typeof markStoryElement;
412
- declare const PlayService_getPlayerTransactions: typeof getPlayerTransactions;
413
- declare const PlayService_getPlayerResults: typeof getPlayerResults;
420
+ declare const PlayService_getLearningElement: typeof getLearningElement;
414
421
  declare const PlayService_getPastResults: typeof getPastResults;
422
+ declare const PlayService_getPlayerData: typeof getPlayerData;
423
+ declare const PlayService_getPlayerResult: typeof getPlayerResult;
424
+ declare const PlayService_getPlayerResults: typeof getPlayerResults;
425
+ declare const PlayService_getPlayerTransactions: typeof getPlayerTransactions;
426
+ declare const PlayService_markStoryElement: typeof markStoryElement;
427
+ declare const PlayService_performAction: typeof performAction;
428
+ declare const PlayService_saveDecisions: typeof saveDecisions;
415
429
  declare const PlayService_updateReadyState: typeof updateReadyState;
416
430
  declare namespace PlayService {
417
431
  export {
418
- PlayService_performAction as performAction,
419
- PlayService_saveDecisions as saveDecisions,
420
- PlayService_getPlayerResult as getPlayerResult,
421
- PlayService_getPlayerData as getPlayerData,
422
- PlayService_getLearningElement as getLearningElement,
423
432
  PlayService_attemptLearningElement as attemptLearningElement,
424
- PlayService_markStoryElement as markStoryElement,
425
- PlayService_getPlayerTransactions as getPlayerTransactions,
426
- PlayService_getPlayerResults as getPlayerResults,
433
+ PlayService_getLearningElement as getLearningElement,
427
434
  PlayService_getPastResults as getPastResults,
435
+ PlayService_getPlayerData as getPlayerData,
436
+ PlayService_getPlayerResult as getPlayerResult,
437
+ PlayService_getPlayerResults as getPlayerResults,
438
+ PlayService_getPlayerTransactions as getPlayerTransactions,
439
+ PlayService_markStoryElement as markStoryElement,
440
+ PlayService_performAction as performAction,
441
+ PlayService_saveDecisions as saveDecisions,
428
442
  PlayService_updateReadyState as updateReadyState,
429
443
  };
430
444
  }
package/dist/index.js CHANGED
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  return to;
19
19
  };
20
20
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
25
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
26
  mod
23
27
  ));
@@ -667,6 +671,13 @@ async function activateNextPeriod({ gameId }, ctx, { reducers }) {
667
671
  where: {
668
672
  id: gameId
669
673
  },
674
+ include: {
675
+ periods: {
676
+ include: {
677
+ segments: true
678
+ }
679
+ }
680
+ },
670
681
  data: {
671
682
  status: "PREPARATION" /* Preparation */,
672
683
  activePeriodIx: nextPeriodIx,
@@ -718,6 +729,13 @@ async function activateNextPeriod({ gameId }, ctx, { reducers }) {
718
729
  data: {
719
730
  status: "CONSOLIDATION" /* Consolidation */
720
731
  },
732
+ include: {
733
+ periods: {
734
+ include: {
735
+ segments: true
736
+ }
737
+ }
738
+ },
721
739
  where: {
722
740
  id: gameId
723
741
  }
@@ -743,6 +761,7 @@ async function activateNextPeriod({ gameId }, ctx, { reducers }) {
743
761
  },
744
762
  data: {
745
763
  results: {
764
+ // compute SEGMENT_END results using model
746
765
  update: results
747
766
  }
748
767
  },
@@ -775,10 +794,18 @@ async function activateNextPeriod({ gameId }, ctx, { reducers }) {
775
794
  );
776
795
  await Promise.all(promises);
777
796
  const result = await ctx.prisma.$transaction([
797
+ // update the status and active period of the current game
778
798
  ctx.prisma.game.update({
779
799
  where: {
780
800
  id: gameId
781
801
  },
802
+ include: {
803
+ periods: {
804
+ include: {
805
+ segments: true
806
+ }
807
+ }
808
+ },
782
809
  data: {
783
810
  status: "RESULTS" /* Results */,
784
811
  activePeriodIx: nextPeriodIx,
@@ -792,6 +819,7 @@ async function activateNextPeriod({ gameId }, ctx, { reducers }) {
792
819
  }
793
820
  }
794
821
  }),
822
+ // create PERIOD_END results based on the previous SEGMENT_END results
795
823
  ctx.prisma.period.update({
796
824
  where: {
797
825
  gameId_index: {
@@ -828,14 +856,23 @@ async function activateNextPeriod({ gameId }, ctx, { reducers }) {
828
856
  { reducers }
829
857
  );
830
858
  const result = await ctx.prisma.$transaction([
859
+ // update the status and active period of the current game
831
860
  ctx.prisma.game.update({
832
861
  where: {
833
862
  id: gameId
834
863
  },
864
+ include: {
865
+ periods: {
866
+ include: {
867
+ segments: true
868
+ }
869
+ }
870
+ },
835
871
  data: {
836
872
  status: "PREPARATION" /* Preparation */
837
873
  }
838
874
  }),
875
+ // create PERIOD_START results based on the previous PERIOD_END results
839
876
  ctx.prisma.period.update({
840
877
  where: {
841
878
  gameId_index: {
@@ -903,10 +940,19 @@ async function activateNextSegment({ gameId }, ctx, { reducers }) {
903
940
  where: {
904
941
  id: gameId
905
942
  },
943
+ include: {
944
+ periods: {
945
+ include: {
946
+ segments: true
947
+ }
948
+ },
949
+ players: true
950
+ },
906
951
  data: {
907
952
  status: "RUNNING" /* Running */
908
953
  }
909
954
  }),
955
+ // update the active segment of the current period
910
956
  ctx.prisma.period.update({
911
957
  where: {
912
958
  gameId_index: {
@@ -927,6 +973,7 @@ async function activateNextSegment({ gameId }, ctx, { reducers }) {
927
973
  }
928
974
  }
929
975
  }),
976
+ // SEGMENT INITIALIZATION
930
977
  ctx.prisma.periodSegment.update({
931
978
  where: {
932
979
  gameId_periodIx_index: {
@@ -969,6 +1016,14 @@ async function activateNextSegment({ gameId }, ctx, { reducers }) {
969
1016
  const result = await ctx.prisma.$transaction([
970
1017
  ctx.prisma.game.update({
971
1018
  where: { id: gameId },
1019
+ include: {
1020
+ periods: {
1021
+ include: {
1022
+ segments: true
1023
+ }
1024
+ },
1025
+ players: true
1026
+ },
972
1027
  data: {
973
1028
  status: "PAUSED" /* Paused */
974
1029
  }
@@ -1140,7 +1195,7 @@ function computePeriodStartResults({ results, players, activePeriodIx, gameId, p
1140
1195
  type: reducers.PeriodResult.ActionTypes.PERIOD_RESULTS_START,
1141
1196
  payload: {
1142
1197
  playerRole: result3.player.role ?? result3.player.connect.role,
1143
- initialCash: periodFacts.initialCash
1198
+ periodFacts
1144
1199
  }
1145
1200
  });
1146
1201
  const mapper = mapAction({
@@ -1180,7 +1235,7 @@ function computePeriodStartResults({ results, players, activePeriodIx, gameId, p
1180
1235
  type: reducers.PeriodResult.ActionTypes.PERIOD_RESULTS_INITIALIZE,
1181
1236
  payload: {
1182
1237
  playerRole: player.role,
1183
- initialCash: periodFacts.initialCash
1238
+ periodFacts
1184
1239
  }
1185
1240
  }
1186
1241
  );
@@ -1235,19 +1290,12 @@ async function computePeriodEndResults({
1235
1290
  } = reducers.PeriodResult.apply(result.facts, {
1236
1291
  type: reducers.PeriodResult.ActionTypes.PERIOD_RESULTS_END,
1237
1292
  payload: {
1238
- interestRate: periodFacts.interestRate,
1239
- spotPrice: segmentFacts.spotPrice,
1240
- futuresPrice: segmentFacts.futuresPrice,
1241
- randomSeed: periodFacts.randomSeed,
1242
- initialSpotPrice: periodFacts.initialSpotPrice,
1293
+ periodFacts,
1294
+ segmentFacts,
1243
1295
  playerRole: result.player.role,
1244
1296
  playerLevel: result.player.levelIx + 1,
1245
1297
  playerExperience: result.player.experience,
1246
- storageCostPerItem: periodFacts.storageCostPerItem,
1247
- trendE: periodFacts.trendE,
1248
- trendGap: periodFacts.trendGap,
1249
1298
  consolidationDecisions,
1250
- cashInflowTotal: segmentFacts.cashInflowTotal,
1251
1299
  periodIx: activePeriodIx
1252
1300
  }
1253
1301
  });
@@ -1312,12 +1360,10 @@ function computeSegmentStartResults(game, ctx, { reducers }) {
1312
1360
  type: reducers.SegmentResult.ActionTypes.SEGMENT_RESULTS_START,
1313
1361
  payload: {
1314
1362
  playerRole: result.player.role,
1315
- interestRate: game.activePeriod.facts.interestRate,
1316
- futuresPriceNext: game.activePeriod.activeSegment.nextSegment.facts.futuresPrice,
1317
- futuresPriceCurrent: game.activePeriod.activeSegment.facts.futuresPrice,
1318
- spotPriceNext: game.activePeriod.activeSegment.nextSegment.facts.spotPrice,
1319
- segmentIx: nextSegmentIx,
1320
- cashInflow: game.activePeriod.activeSegment.nextSegment.facts.cashInflow
1363
+ periodFacts: game.activePeriod.facts,
1364
+ segmentFacts: game.activePeriod.activeSegment.facts,
1365
+ nextSegmentFacts: game.activePeriod.activeSegment.nextSegment?.facts,
1366
+ segmentIx: nextSegmentIx
1321
1367
  }
1322
1368
  }
1323
1369
  );
@@ -1371,10 +1417,11 @@ function computeSegmentStartResults(game, ctx, { reducers }) {
1371
1417
  const { result: facts } = reducers.SegmentResult.apply(result.facts, {
1372
1418
  type: reducers.SegmentResult.ActionTypes.SEGMENT_RESULTS_INITIALIZE,
1373
1419
  payload: {
1374
- cashBalance: result.facts.cashBalance,
1375
- storageAmount: result.facts.storageAmount,
1376
- spotPrice: game.activePeriod.facts.initialSpotPrice,
1377
- playerRole: result.player.role
1420
+ playerRole: result.player.role,
1421
+ periodFacts: game.activePeriod.facts,
1422
+ segmentFacts: game.activePeriod.activeSegment?.facts,
1423
+ nextSegmentFacts: game.activePeriod.activeSegment?.nextSegment?.facts,
1424
+ segmentIx: nextSegmentIx
1378
1425
  }
1379
1426
  });
1380
1427
  const common = {
@@ -1422,7 +1469,9 @@ function computeSegmentEndResults(game, ctx, { reducers }) {
1422
1469
  {
1423
1470
  type: reducers.SegmentResult.ActionTypes.SEGMENT_RESULTS_END,
1424
1471
  payload: {
1425
- storageCostPerItem: game.activePeriod.facts.storageCostPerItem,
1472
+ playerRole: result.player.role,
1473
+ periodFacts: game.activePeriod.facts,
1474
+ segmentFacts: game.activePeriod.activeSegment.facts,
1426
1475
  segmentIx: game.activePeriod.activeSegmentIx
1427
1476
  }
1428
1477
  }
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  return to;
19
19
  };
20
20
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
25
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
26
  mod
23
27
  ));
@@ -1,4 +1,9 @@
1
1
  declare function setDifference(a: any, b: any, filterNoId?: boolean): any;
2
2
  declare function setIntersection(a: any, b: any): any;
3
+ declare function debugLog(...args: any[]): void;
4
+ declare function diceRoll(seeds?: number[]): number;
5
+ declare function computeScenarioOutcome(trend: any, gap: any, diceRoll: any): any;
6
+ declare function computePercentChange(newValue: any, oldValue: any): number;
7
+ declare function withPercentChange(value: any, percentChange: any): number;
3
8
 
4
- export { setDifference, setIntersection };
9
+ export { computePercentChange, computeScenarioOutcome, debugLog, diceRoll, setDifference, setIntersection, withPercentChange };
package/dist/lib/util.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,15 +17,30 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/lib/util.ts
21
31
  var util_exports = {};
22
32
  __export(util_exports, {
33
+ computePercentChange: () => computePercentChange,
34
+ computeScenarioOutcome: () => computeScenarioOutcome,
35
+ debugLog: () => debugLog,
36
+ diceRoll: () => diceRoll,
23
37
  setDifference: () => setDifference,
24
- setIntersection: () => setIntersection
38
+ setIntersection: () => setIntersection,
39
+ withPercentChange: () => withPercentChange
25
40
  });
26
41
  module.exports = __toCommonJS(util_exports);
42
+ var import_random_js = require("random-js");
43
+ var import_util = __toESM(require("util"));
27
44
  function setDifference(a, b, filterNoId = false) {
28
45
  if (!b)
29
46
  return a;
@@ -37,8 +54,31 @@ function setIntersection(a, b) {
37
54
  const B = new Set(b.map((item) => item.id));
38
55
  return a.filter((item) => B.has(item.id) && item.id);
39
56
  }
57
+ function debugLog(...args) {
58
+ if (process.env.NODE_ENV === "development") {
59
+ console.log(import_util.default.inspect(args, { showHidden: false, depth: null }));
60
+ }
61
+ }
62
+ function diceRoll(seeds = []) {
63
+ const rng = import_random_js.MersenneTwister19937.seedWithArray(seeds);
64
+ return (0, import_random_js.integer)(1, 6)(rng);
65
+ }
66
+ function computeScenarioOutcome(trend, gap, diceRoll2) {
67
+ return trend + (diceRoll2 - 7) * gap;
68
+ }
69
+ function computePercentChange(newValue, oldValue) {
70
+ return (newValue - oldValue) / oldValue;
71
+ }
72
+ function withPercentChange(value, percentChange) {
73
+ return value * (1 + percentChange);
74
+ }
40
75
  // Annotate the CommonJS export names for ESM import in node:
41
76
  0 && (module.exports = {
77
+ computePercentChange,
78
+ computeScenarioOutcome,
79
+ debugLog,
80
+ diceRoll,
42
81
  setDifference,
43
- setIntersection
82
+ setIntersection,
83
+ withPercentChange
44
84
  });
package/dist/nexus.js CHANGED
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  return to;
19
19
  };
20
20
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
25
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
26
  mod
23
27
  ));
@@ -326,10 +330,10 @@ var Game = (0, import_nexus5.objectType)({
326
330
  t.field("activePeriod", {
327
331
  type: Period
328
332
  });
329
- t.list.nonNull.field("players", {
333
+ t.nonNull.list.nonNull.field("players", {
330
334
  type: Player
331
335
  });
332
- t.list.nonNull.field("periods", {
336
+ t.nonNull.list.nonNull.field("periods", {
333
337
  type: Period
334
338
  });
335
339
  }
@@ -953,6 +957,13 @@ async function activateNextPeriod({ gameId }, ctx, { reducers }) {
953
957
  where: {
954
958
  id: gameId
955
959
  },
960
+ include: {
961
+ periods: {
962
+ include: {
963
+ segments: true
964
+ }
965
+ }
966
+ },
956
967
  data: {
957
968
  status: "PREPARATION" /* Preparation */,
958
969
  activePeriodIx: nextPeriodIx,
@@ -1004,6 +1015,13 @@ async function activateNextPeriod({ gameId }, ctx, { reducers }) {
1004
1015
  data: {
1005
1016
  status: "CONSOLIDATION" /* Consolidation */
1006
1017
  },
1018
+ include: {
1019
+ periods: {
1020
+ include: {
1021
+ segments: true
1022
+ }
1023
+ }
1024
+ },
1007
1025
  where: {
1008
1026
  id: gameId
1009
1027
  }
@@ -1029,6 +1047,7 @@ async function activateNextPeriod({ gameId }, ctx, { reducers }) {
1029
1047
  },
1030
1048
  data: {
1031
1049
  results: {
1050
+ // compute SEGMENT_END results using model
1032
1051
  update: results
1033
1052
  }
1034
1053
  },
@@ -1061,10 +1080,18 @@ async function activateNextPeriod({ gameId }, ctx, { reducers }) {
1061
1080
  );
1062
1081
  await Promise.all(promises);
1063
1082
  const result = await ctx.prisma.$transaction([
1083
+ // update the status and active period of the current game
1064
1084
  ctx.prisma.game.update({
1065
1085
  where: {
1066
1086
  id: gameId
1067
1087
  },
1088
+ include: {
1089
+ periods: {
1090
+ include: {
1091
+ segments: true
1092
+ }
1093
+ }
1094
+ },
1068
1095
  data: {
1069
1096
  status: "RESULTS" /* Results */,
1070
1097
  activePeriodIx: nextPeriodIx,
@@ -1078,6 +1105,7 @@ async function activateNextPeriod({ gameId }, ctx, { reducers }) {
1078
1105
  }
1079
1106
  }
1080
1107
  }),
1108
+ // create PERIOD_END results based on the previous SEGMENT_END results
1081
1109
  ctx.prisma.period.update({
1082
1110
  where: {
1083
1111
  gameId_index: {
@@ -1114,14 +1142,23 @@ async function activateNextPeriod({ gameId }, ctx, { reducers }) {
1114
1142
  { reducers }
1115
1143
  );
1116
1144
  const result = await ctx.prisma.$transaction([
1145
+ // update the status and active period of the current game
1117
1146
  ctx.prisma.game.update({
1118
1147
  where: {
1119
1148
  id: gameId
1120
1149
  },
1150
+ include: {
1151
+ periods: {
1152
+ include: {
1153
+ segments: true
1154
+ }
1155
+ }
1156
+ },
1121
1157
  data: {
1122
1158
  status: "PREPARATION" /* Preparation */
1123
1159
  }
1124
1160
  }),
1161
+ // create PERIOD_START results based on the previous PERIOD_END results
1125
1162
  ctx.prisma.period.update({
1126
1163
  where: {
1127
1164
  gameId_index: {
@@ -1189,10 +1226,19 @@ async function activateNextSegment({ gameId }, ctx, { reducers }) {
1189
1226
  where: {
1190
1227
  id: gameId
1191
1228
  },
1229
+ include: {
1230
+ periods: {
1231
+ include: {
1232
+ segments: true
1233
+ }
1234
+ },
1235
+ players: true
1236
+ },
1192
1237
  data: {
1193
1238
  status: "RUNNING" /* Running */
1194
1239
  }
1195
1240
  }),
1241
+ // update the active segment of the current period
1196
1242
  ctx.prisma.period.update({
1197
1243
  where: {
1198
1244
  gameId_index: {
@@ -1213,6 +1259,7 @@ async function activateNextSegment({ gameId }, ctx, { reducers }) {
1213
1259
  }
1214
1260
  }
1215
1261
  }),
1262
+ // SEGMENT INITIALIZATION
1216
1263
  ctx.prisma.periodSegment.update({
1217
1264
  where: {
1218
1265
  gameId_periodIx_index: {
@@ -1255,6 +1302,14 @@ async function activateNextSegment({ gameId }, ctx, { reducers }) {
1255
1302
  const result = await ctx.prisma.$transaction([
1256
1303
  ctx.prisma.game.update({
1257
1304
  where: { id: gameId },
1305
+ include: {
1306
+ periods: {
1307
+ include: {
1308
+ segments: true
1309
+ }
1310
+ },
1311
+ players: true
1312
+ },
1258
1313
  data: {
1259
1314
  status: "PAUSED" /* Paused */
1260
1315
  }
@@ -1426,7 +1481,7 @@ function computePeriodStartResults({ results, players, activePeriodIx, gameId, p
1426
1481
  type: reducers.PeriodResult.ActionTypes.PERIOD_RESULTS_START,
1427
1482
  payload: {
1428
1483
  playerRole: result3.player.role ?? result3.player.connect.role,
1429
- initialCash: periodFacts.initialCash
1484
+ periodFacts
1430
1485
  }
1431
1486
  });
1432
1487
  const mapper = mapAction({
@@ -1466,7 +1521,7 @@ function computePeriodStartResults({ results, players, activePeriodIx, gameId, p
1466
1521
  type: reducers.PeriodResult.ActionTypes.PERIOD_RESULTS_INITIALIZE,
1467
1522
  payload: {
1468
1523
  playerRole: player.role,
1469
- initialCash: periodFacts.initialCash
1524
+ periodFacts
1470
1525
  }
1471
1526
  }
1472
1527
  );
@@ -1521,19 +1576,12 @@ async function computePeriodEndResults({
1521
1576
  } = reducers.PeriodResult.apply(result.facts, {
1522
1577
  type: reducers.PeriodResult.ActionTypes.PERIOD_RESULTS_END,
1523
1578
  payload: {
1524
- interestRate: periodFacts.interestRate,
1525
- spotPrice: segmentFacts.spotPrice,
1526
- futuresPrice: segmentFacts.futuresPrice,
1527
- randomSeed: periodFacts.randomSeed,
1528
- initialSpotPrice: periodFacts.initialSpotPrice,
1579
+ periodFacts,
1580
+ segmentFacts,
1529
1581
  playerRole: result.player.role,
1530
1582
  playerLevel: result.player.levelIx + 1,
1531
1583
  playerExperience: result.player.experience,
1532
- storageCostPerItem: periodFacts.storageCostPerItem,
1533
- trendE: periodFacts.trendE,
1534
- trendGap: periodFacts.trendGap,
1535
1584
  consolidationDecisions,
1536
- cashInflowTotal: segmentFacts.cashInflowTotal,
1537
1585
  periodIx: activePeriodIx
1538
1586
  }
1539
1587
  });
@@ -1598,12 +1646,10 @@ function computeSegmentStartResults(game, ctx, { reducers }) {
1598
1646
  type: reducers.SegmentResult.ActionTypes.SEGMENT_RESULTS_START,
1599
1647
  payload: {
1600
1648
  playerRole: result.player.role,
1601
- interestRate: game.activePeriod.facts.interestRate,
1602
- futuresPriceNext: game.activePeriod.activeSegment.nextSegment.facts.futuresPrice,
1603
- futuresPriceCurrent: game.activePeriod.activeSegment.facts.futuresPrice,
1604
- spotPriceNext: game.activePeriod.activeSegment.nextSegment.facts.spotPrice,
1605
- segmentIx: nextSegmentIx,
1606
- cashInflow: game.activePeriod.activeSegment.nextSegment.facts.cashInflow
1649
+ periodFacts: game.activePeriod.facts,
1650
+ segmentFacts: game.activePeriod.activeSegment.facts,
1651
+ nextSegmentFacts: game.activePeriod.activeSegment.nextSegment?.facts,
1652
+ segmentIx: nextSegmentIx
1607
1653
  }
1608
1654
  }
1609
1655
  );
@@ -1657,10 +1703,11 @@ function computeSegmentStartResults(game, ctx, { reducers }) {
1657
1703
  const { result: facts } = reducers.SegmentResult.apply(result.facts, {
1658
1704
  type: reducers.SegmentResult.ActionTypes.SEGMENT_RESULTS_INITIALIZE,
1659
1705
  payload: {
1660
- cashBalance: result.facts.cashBalance,
1661
- storageAmount: result.facts.storageAmount,
1662
- spotPrice: game.activePeriod.facts.initialSpotPrice,
1663
- playerRole: result.player.role
1706
+ playerRole: result.player.role,
1707
+ periodFacts: game.activePeriod.facts,
1708
+ segmentFacts: game.activePeriod.activeSegment?.facts,
1709
+ nextSegmentFacts: game.activePeriod.activeSegment?.nextSegment?.facts,
1710
+ segmentIx: nextSegmentIx
1664
1711
  }
1665
1712
  });
1666
1713
  const common = {
@@ -1708,7 +1755,9 @@ function computeSegmentEndResults(game, ctx, { reducers }) {
1708
1755
  {
1709
1756
  type: reducers.SegmentResult.ActionTypes.SEGMENT_RESULTS_END,
1710
1757
  payload: {
1711
- storageCostPerItem: game.activePeriod.facts.storageCostPerItem,
1758
+ playerRole: result.player.role,
1759
+ periodFacts: game.activePeriod.facts,
1760
+ segmentFacts: game.activePeriod.activeSegment.facts,
1712
1761
  segmentIx: game.activePeriod.activeSegmentIx
1713
1762
  }
1714
1763
  }
@@ -5,7 +5,20 @@ mutation ActivateNextPeriod($gameId: Int!) {
5
5
  activateNextPeriod(gameId: $gameId) {
6
6
  ...GameData
7
7
  periods {
8
- ...PeriodData
8
+ id
9
+
10
+ index
11
+ activeSegmentIx
12
+
13
+ facts
14
+
15
+ segments {
16
+ id
17
+
18
+ index
19
+
20
+ facts
21
+ }
9
22
  }
10
23
  }
11
24
  }
@@ -5,10 +5,37 @@ mutation ActivateNextSegment($gameId: Int!) {
5
5
  activateNextSegment(gameId: $gameId) {
6
6
  ...GameData
7
7
  periods {
8
- ...PeriodData
8
+ id
9
+
10
+ index
11
+ activeSegmentIx
12
+
13
+ facts
14
+
15
+ segments {
16
+ id
17
+
18
+ index
19
+
20
+ facts
21
+ }
9
22
  }
10
23
  players {
11
- ...PlayerData
24
+ id
25
+
26
+ isReady
27
+
28
+ role
29
+
30
+ name
31
+ avatar
32
+ location
33
+ color
34
+
35
+ facts
36
+
37
+ experience
38
+ experienceToNext
12
39
  }
13
40
  }
14
41
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gbl-uzh/platform",
3
- "version": "0.2.14",
4
- "license": "AGPL-3.0",
3
+ "version": "0.3.1",
4
+ "license": "LGPL-3.0",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
@@ -21,32 +21,32 @@
21
21
  "node": ">=18"
22
22
  },
23
23
  "devDependencies": {
24
- "@graphql-codegen/cli": "2.13.11",
25
- "@graphql-codegen/fragment-matcher": "3.3.1",
26
- "@graphql-codegen/introspection": "2.2.1",
27
- "@graphql-codegen/typed-document-node": "2.3.6",
28
- "@graphql-codegen/typescript": "2.8.1",
29
- "@graphql-codegen/typescript-operations": "2.5.6",
30
- "@graphql-codegen/typescript-resolvers": "2.7.6",
24
+ "@graphql-codegen/cli": "3.2.2",
25
+ "@graphql-codegen/fragment-matcher": "4.0.1",
26
+ "@graphql-codegen/introspection": "3.0.1",
27
+ "@graphql-codegen/typed-document-node": "3.0.2",
28
+ "@graphql-codegen/typescript": "3.0.2",
29
+ "@graphql-codegen/typescript-operations": "3.0.2",
30
+ "@graphql-codegen/typescript-resolvers": "3.1.1",
31
31
  "@tsconfig/node18": "1.0.1",
32
- "@tsconfig/recommended": "1.0.1",
32
+ "@tsconfig/recommended": "1.0.2",
33
33
  "@types/jest": "^29.2.2",
34
34
  "@types/node": "^18.11.9",
35
35
  "cross-env": "7.0.3",
36
36
  "fs-extra": "11.1.0",
37
- "jest": "29.3.1",
37
+ "jest": "29.5.0",
38
38
  "npm-run-all": "4.1.5",
39
- "prisma": "4.8.0",
39
+ "prisma": "4.11.0",
40
40
  "rollup-plugin-copy": "3.4.0",
41
- "ts-jest": "29.0.3",
41
+ "ts-jest": "29.0.5",
42
42
  "ts-node": "10.9.1",
43
- "tsup": "6.5.0",
44
- "typescript": "4.9.4"
43
+ "tsup": "6.6.3",
44
+ "typescript": "4.9.5"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@apollo/client": "^3.7.0",
48
- "@prisma/client": "^4.8.0",
49
- "@uzh-bf/design-system": "^0.0.79",
48
+ "@prisma/client": "^4.11.0",
49
+ "@uzh-bf/design-system": "^1.0.0",
50
50
  "graphql": "^16.6.0",
51
51
  "graphql-scalars": "^1.19.0",
52
52
  "graphql-yoga": "^3.0.0",
@@ -56,9 +56,12 @@
56
56
  "nookies": "^2.5.2",
57
57
  "ramda": "^0.28.0",
58
58
  "react": "^18.0.0",
59
- "yup": "^1.0.0-beta.8"
59
+ "yup": "^1.0.0"
60
60
  },
61
61
  "volta": {
62
62
  "extends": "../../package.json"
63
+ },
64
+ "dependencies": {
65
+ "random-js": "2.1.0"
63
66
  }
64
67
  }