@gbl-uzh/platform 0.2.10

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.
@@ -0,0 +1,4 @@
1
+ declare function initializeApollo(initialState?: null): any;
2
+ declare function useApollo(initialState: any): any;
3
+
4
+ export { initializeApollo, useApollo };
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+
26
+ // src/lib/apollo.ts
27
+ var apollo_exports = {};
28
+ __export(apollo_exports, {
29
+ initializeApollo: () => initializeApollo,
30
+ useApollo: () => useApollo
31
+ });
32
+ module.exports = __toCommonJS(apollo_exports);
33
+ var import_client = require("@apollo/client");
34
+ var import_http = require("@apollo/client/link/http");
35
+ var import_utilities = require("@apollo/client/utilities");
36
+ var import_config = __toESM(require("next/config"));
37
+ var import_react = require("react");
38
+
39
+ // src/lib/SSELink.ts
40
+ var import_core = require("@apollo/client/core");
41
+ var import_graphql = require("graphql");
42
+ var SSELink = class extends import_core.ApolloLink {
43
+ constructor(options) {
44
+ super();
45
+ this.options = options;
46
+ }
47
+ request(operation) {
48
+ const url = new URL(this.options.url);
49
+ url.searchParams.append("query", (0, import_graphql.print)(operation.query));
50
+ url.searchParams.append("variables", JSON.stringify(operation.variables));
51
+ return new import_core.Observable((sink) => {
52
+ const eventsource = new EventSource(url.toString(), this.options);
53
+ eventsource.onmessage = function(event) {
54
+ const data = JSON.parse(event.data);
55
+ sink.next(data);
56
+ if (eventsource.readyState === 2) {
57
+ sink.complete();
58
+ }
59
+ };
60
+ eventsource.onerror = function(error) {
61
+ sink.error(error);
62
+ };
63
+ return () => eventsource.close();
64
+ });
65
+ }
66
+ };
67
+ var SSELink_default = SSELink;
68
+
69
+ // src/lib/apollo.ts
70
+ var apolloClient;
71
+ function createIsomorphLink() {
72
+ const { publicRuntimeConfig, serverRuntimeConfig } = (0, import_config.default)();
73
+ const isBrowser = typeof window !== "undefined";
74
+ let httpLink = new import_http.HttpLink({
75
+ uri: publicRuntimeConfig.apiURL,
76
+ credentials: "same-origin"
77
+ });
78
+ if (isBrowser) {
79
+ const sseLink = new SSELink_default({
80
+ url: publicRuntimeConfig.apiURL
81
+ });
82
+ httpLink = (0, import_client.split)(
83
+ ({ query }) => {
84
+ const { kind, operation } = (0, import_utilities.getMainDefinition)(query);
85
+ return kind === "OperationDefinition" && operation === "subscription";
86
+ },
87
+ sseLink,
88
+ httpLink
89
+ );
90
+ }
91
+ return httpLink;
92
+ }
93
+ function createApolloClient() {
94
+ return new import_client.ApolloClient({
95
+ ssrMode: typeof window === "undefined",
96
+ link: createIsomorphLink(),
97
+ cache: new import_client.InMemoryCache()
98
+ });
99
+ }
100
+ function initializeApollo(initialState = null) {
101
+ const _apolloClient = apolloClient ?? createApolloClient();
102
+ if (initialState) {
103
+ _apolloClient.cache.restore(initialState);
104
+ }
105
+ if (typeof window === "undefined")
106
+ return _apolloClient;
107
+ if (!apolloClient)
108
+ apolloClient = _apolloClient;
109
+ return _apolloClient;
110
+ }
111
+ function useApollo(initialState) {
112
+ const store = (0, import_react.useMemo)(() => initializeApollo(initialState), [initialState]);
113
+ return store;
114
+ }
115
+ // Annotate the CommonJS export names for ESM import in node:
116
+ 0 && (module.exports = {
117
+ initializeApollo,
118
+ useApollo
119
+ });
@@ -0,0 +1,4 @@
1
+ declare function setDifference(a: any, b: any, filterNoId?: boolean): any;
2
+ declare function setIntersection(a: any, b: any): any;
3
+
4
+ export { setDifference, setIntersection };
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/lib/util.ts
21
+ var util_exports = {};
22
+ __export(util_exports, {
23
+ setDifference: () => setDifference,
24
+ setIntersection: () => setIntersection
25
+ });
26
+ module.exports = __toCommonJS(util_exports);
27
+ function setDifference(a, b, filterNoId = false) {
28
+ if (!b)
29
+ return a;
30
+ const A = a || [];
31
+ const B = new Set(b.map((item) => item.id));
32
+ return A.filter((item) => !B.has(item.id) || filterNoId && !item.id);
33
+ }
34
+ function setIntersection(a, b) {
35
+ if (!a || !b)
36
+ return [];
37
+ const B = new Set(b.map((item) => item.id));
38
+ return a.filter((item) => B.has(item.id) && item.id);
39
+ }
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ setDifference,
43
+ setIntersection
44
+ });
@@ -0,0 +1,78 @@
1
+ import * as nexus_dist_core from 'nexus/dist/core';
2
+ import * as yup from 'yup';
3
+
4
+ declare const GameStatus: nexus_dist_core.NexusEnumTypeDef<"GameStatus">;
5
+ declare const Game: nexus_dist_core.NexusObjectTypeDef<"Game">;
6
+ declare const Period: nexus_dist_core.NexusObjectTypeDef<"Period">;
7
+ declare const PeriodSegment: nexus_dist_core.NexusObjectTypeDef<"PeriodSegment">;
8
+
9
+ declare const LearningAnswerOption: nexus_dist_core.NexusObjectTypeDef<"LearningAnswerOption">;
10
+ declare const LearningElementState: nexus_dist_core.NexusObjectTypeDef<"LearningElementState">;
11
+ declare const LearningElementAttempt: nexus_dist_core.NexusObjectTypeDef<"LearningElementAttempt">;
12
+ declare const LearningElement: nexus_dist_core.NexusObjectTypeDef<"LearningElement">;
13
+
14
+ interface GenerateBaseMutationsArgs {
15
+ reducers?: any;
16
+ roleAssigner?: (ix: number) => void;
17
+ }
18
+ declare function generateBaseMutations({ reducers, roleAssigner, }?: GenerateBaseMutationsArgs): nexus_dist_core.NexusObjectTypeDef<"Mutation">;
19
+ declare const Mutation: nexus_dist_core.NexusObjectTypeDef<"Mutation">;
20
+
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
+ declare const PlayerDecisionType: nexus_dist_core.NexusEnumTypeDef<"PlayerDecisionType">;
59
+ declare const PlayerResultType: nexus_dist_core.NexusEnumTypeDef<"PlayerResultType">;
60
+ declare const PlayerLevel: nexus_dist_core.NexusObjectTypeDef<"PlayerLevel">;
61
+ declare const PlayerState: nexus_dist_core.NexusObjectTypeDef<"PlayerState">;
62
+ declare const Player: nexus_dist_core.NexusObjectTypeDef<"Player">;
63
+ declare const PlayerResult: nexus_dist_core.NexusObjectTypeDef<"PlayerResult">;
64
+ declare const PlayerAction: nexus_dist_core.NexusObjectTypeDef<"PlayerAction">;
65
+ declare const PlayerDecision: nexus_dist_core.NexusObjectTypeDef<"PlayerDecision">;
66
+
67
+ declare function generateBaseQueries(): nexus_dist_core.NexusObjectTypeDef<"Query">;
68
+ declare const Query: nexus_dist_core.NexusObjectTypeDef<"Query">;
69
+
70
+ declare function generateBaseSubscriptions(): nexus_dist_core.NexusObjectTypeDef<string>;
71
+ declare const Subscription: nexus_dist_core.NexusObjectTypeDef<string>;
72
+
73
+ declare const JsonScalar: nexus_dist_core.AllNexusOutputTypeDefs;
74
+ declare const DateScalar: nexus_dist_core.AllNexusOutputTypeDefs;
75
+ declare const UserRole: nexus_dist_core.NexusEnumTypeDef<"UserRole">;
76
+ declare const Event: nexus_dist_core.NexusObjectTypeDef<"Event">;
77
+
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 };