@glissandoo/lib 1.52.3 → 1.53.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.
@@ -0,0 +1,11 @@
1
+ import * as firestore from '../types/firestore';
2
+ /** Create a DocumentSnapshot. */
3
+ export declare function makeDocumentSnapshot(
4
+ /** Key-value pairs representing data in the document, pass in `{}` to mock the snapshot of
5
+ * a document that doesn't exist.
6
+ */
7
+ data: {
8
+ [key: string]: unknown;
9
+ },
10
+ /** Full path of the reference (e.g. 'users/alovelace') */
11
+ refPath: string, project: string): firestore.DocumentSnapshot<firestore.DocumentData>;
@@ -0,0 +1,196 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.makeDocumentSnapshot = void 0;
27
+ const lodash_1 = require("lodash");
28
+ const firestore = __importStar(require("../types/firestore"));
29
+ const firebase = __importStar(require("firebase-admin"));
30
+ /** @internal */
31
+ function testApp() {
32
+ if (typeof testApp.singleton === 'undefined') {
33
+ testApp.init();
34
+ }
35
+ return testApp.singleton;
36
+ }
37
+ /** @internal */
38
+ (function (testApp) {
39
+ testApp.init = () => (testApp.singleton = new testApp.App());
40
+ class App {
41
+ constructor() {
42
+ return;
43
+ }
44
+ getApp() {
45
+ if (typeof this.appSingleton === 'undefined') {
46
+ const config = process.env.FIREBASE_CONFIG
47
+ ? JSON.parse(process.env.FIREBASE_CONFIG)
48
+ : {};
49
+ this.appSingleton = firebase.initializeApp(config,
50
+ // Give this app a name so it does not conflict with apps that user initialized.
51
+ 'firebase-functions-test');
52
+ }
53
+ return this.appSingleton;
54
+ }
55
+ deleteApp() {
56
+ if (this.appSingleton) {
57
+ void this.appSingleton.delete();
58
+ delete this.appSingleton;
59
+ }
60
+ }
61
+ }
62
+ testApp.App = App;
63
+ })(testApp || (testApp = {}));
64
+ /** @internal */
65
+ function objectToValueProto(data) {
66
+ const encodeHelper = (val) => {
67
+ if (typeof val === 'string') {
68
+ return {
69
+ stringValue: val,
70
+ };
71
+ }
72
+ if (typeof val === 'boolean') {
73
+ return {
74
+ booleanValue: val,
75
+ };
76
+ }
77
+ if (typeof val === 'number') {
78
+ if (val % 1 === 0) {
79
+ return {
80
+ integerValue: val,
81
+ };
82
+ }
83
+ return {
84
+ doubleValue: val,
85
+ };
86
+ }
87
+ if (val instanceof Date) {
88
+ return {
89
+ timestampValue: val.toISOString(),
90
+ };
91
+ }
92
+ if (val instanceof Array) {
93
+ const encodedElements = [];
94
+ for (const elem of val) {
95
+ const enc = encodeHelper(elem);
96
+ if (enc) {
97
+ encodedElements.push(enc);
98
+ }
99
+ }
100
+ return {
101
+ arrayValue: {
102
+ values: encodedElements,
103
+ },
104
+ };
105
+ }
106
+ if (val === null) {
107
+ // TODO: Look this up. This is a google.protobuf.NulLValue,
108
+ // and everything in google.protobuf has a customized JSON encoder.
109
+ // OTOH, Firestore's generated .d.ts files don't take this into
110
+ // account and have the default proto layout.
111
+ return {
112
+ nullValue: 'NULL_VALUE',
113
+ };
114
+ }
115
+ if (val instanceof Buffer || val instanceof Uint8Array) {
116
+ return {
117
+ bytesValue: val,
118
+ };
119
+ }
120
+ if (val instanceof firestore.DocumentReference) {
121
+ const projectId = (0, lodash_1.get)(val, '_referencePath.projectId');
122
+ const database = (0, lodash_1.get)(val, '_referencePath.databaseId');
123
+ const referenceValue = [
124
+ 'projects',
125
+ projectId,
126
+ 'databases',
127
+ database,
128
+ val.path,
129
+ ].join('/');
130
+ return { referenceValue };
131
+ }
132
+ if (val instanceof firestore.Timestamp) {
133
+ return {
134
+ timestampValue: val.toDate().toISOString(),
135
+ };
136
+ }
137
+ if (val instanceof firestore.GeoPoint) {
138
+ return {
139
+ geoPointValue: {
140
+ latitude: val.latitude,
141
+ longitude: val.longitude,
142
+ },
143
+ };
144
+ }
145
+ if ((0, lodash_1.isPlainObject)(val)) {
146
+ if (!val)
147
+ return;
148
+ return {
149
+ mapValue: {
150
+ fields: objectToValueProto(val),
151
+ },
152
+ };
153
+ }
154
+ throw new Error('Cannot encode to a Firestore Value');
155
+ };
156
+ return (0, lodash_1.mapValues)(data, encodeHelper);
157
+ }
158
+ function dateToTimestampProto(timeString) {
159
+ if (typeof timeString === 'undefined') {
160
+ return;
161
+ }
162
+ const date = new Date(timeString);
163
+ const seconds = Math.floor(date.getTime() / 1000);
164
+ let nanos = 0;
165
+ if (timeString.length > 20) {
166
+ const nanoString = timeString.substring(20, timeString.length - 1);
167
+ const trailingZeroes = 9 - nanoString.length;
168
+ nanos = parseInt(nanoString, 10) * Math.pow(10, trailingZeroes);
169
+ }
170
+ return { seconds, nanos };
171
+ }
172
+ /** Create a DocumentSnapshot. */
173
+ function makeDocumentSnapshot(
174
+ /** Key-value pairs representing data in the document, pass in `{}` to mock the snapshot of
175
+ * a document that doesn't exist.
176
+ */
177
+ data,
178
+ /** Full path of the reference (e.g. 'users/alovelace') */
179
+ refPath, project) {
180
+ const firestoreService = firebase.firestore(testApp().getApp());
181
+ const resource = `projects/${project}/databases/(default)/documents/${refPath}`;
182
+ const proto = (0, lodash_1.isEmpty)(data)
183
+ ? resource
184
+ : {
185
+ fields: objectToValueProto(data),
186
+ createTime: dateToTimestampProto(new Date().toISOString()),
187
+ updateTime: dateToTimestampProto(new Date().toISOString()),
188
+ name: resource,
189
+ };
190
+ const readTimeProto = dateToTimestampProto(new Date().toISOString());
191
+ /* eslint-disable */
192
+ // @ts-ignore
193
+ return firestoreService.snapshot_(proto, readTimeProto, 'json');
194
+ /* eslint-enable */
195
+ }
196
+ exports.makeDocumentSnapshot = makeDocumentSnapshot;
@@ -0,0 +1,28 @@
1
+ import { LanguagesTypes } from '../../../lang';
2
+ import { AEventPlayerBasicData } from '../types';
3
+ import { EventPlayerStatus } from './types';
4
+ export default class EventoPlayerBasic {
5
+ eventId: string;
6
+ exists: boolean;
7
+ protected data: AEventPlayerBasicData;
8
+ protected lang: LanguagesTypes;
9
+ constructor(eventId: string, data: AEventPlayerBasicData | null, lang?: LanguagesTypes);
10
+ get id(): string;
11
+ get username(): string;
12
+ get displayName(): string;
13
+ get photoURL(): string;
14
+ get mainInstrument(): import("../../../helpers/instruments").InstrumentId;
15
+ get status(): EventPlayerStatus | null;
16
+ get reason(): import("./types").EventPlayerReason | null;
17
+ get note(): string | null;
18
+ get rollcall(): EventPlayerStatus | null;
19
+ get interested(): true | null;
20
+ get selected(): boolean | null;
21
+ get isActive(): boolean;
22
+ get isInterested(): boolean;
23
+ get isConfirmed(): boolean;
24
+ get isDeclined(): boolean;
25
+ get isPending(): boolean;
26
+ get isRollCallConfirmed(): boolean;
27
+ get isRollCallDeclined(): boolean;
28
+ }
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const lodash_1 = require("lodash");
4
+ const lang_1 = require("../../../lang");
5
+ const types_1 = require("./types");
6
+ class EventoPlayerBasic {
7
+ constructor(eventId, data, lang = lang_1.defaultLocale) {
8
+ this.eventId = eventId;
9
+ this.data = data || {};
10
+ this.exists = data !== null;
11
+ this.lang = lang;
12
+ }
13
+ get id() {
14
+ return this.data.id;
15
+ }
16
+ get username() {
17
+ return this.data.username;
18
+ }
19
+ get displayName() {
20
+ return this.data.displayName;
21
+ }
22
+ get photoURL() {
23
+ return this.data.photoURL;
24
+ }
25
+ get mainInstrument() {
26
+ return this.data.mainInstrument;
27
+ }
28
+ get status() {
29
+ return this.data.status;
30
+ }
31
+ get reason() {
32
+ return this.data.reason || null;
33
+ }
34
+ get note() {
35
+ return this.data.note || null;
36
+ }
37
+ get rollcall() {
38
+ return this.data.rollcall || null;
39
+ }
40
+ get interested() {
41
+ return this.data.interested || null;
42
+ }
43
+ get selected() {
44
+ return !(0, lodash_1.isUndefined)(this.data.selected) ? this.data.selected : null;
45
+ }
46
+ get isActive() {
47
+ return this.exists && this.selected !== false;
48
+ }
49
+ get isInterested() {
50
+ return this.interested === true;
51
+ }
52
+ get isConfirmed() {
53
+ return this.status === types_1.EventPlayerStatus.Confirmed;
54
+ }
55
+ get isDeclined() {
56
+ return this.status === types_1.EventPlayerStatus.Declined;
57
+ }
58
+ get isPending() {
59
+ return this.status === null;
60
+ }
61
+ get isRollCallConfirmed() {
62
+ return this.rollcall === types_1.EventPlayerStatus.Confirmed;
63
+ }
64
+ get isRollCallDeclined() {
65
+ return this.rollcall === types_1.EventPlayerStatus.Declined;
66
+ }
67
+ }
68
+ exports.default = EventoPlayerBasic;
@@ -1,9 +1,9 @@
1
1
  import { InstrumentId } from '../../helpers/instruments';
2
2
  import { LanguagesTypes } from '../../lang';
3
3
  import { DocumentReference, DocumentSnapshot } from '../../types/firestore';
4
- import { EventPlayerStatus } from './Player/types';
5
4
  import EventoPromoter from './promoter';
6
- import { EventData, EventPlayerBasicData, EventResponseDeadlineOptions, EventStatusByTime } from './types';
5
+ import { EventData, EventResponseDeadlineOptions, EventStatusByTime } from './types';
6
+ import EventoPlayerBasic from './Player/Basic';
7
7
  export default class Evento extends EventoPromoter<EventData> {
8
8
  constructor(doc: DocumentSnapshot, lang?: LanguagesTypes);
9
9
  get maxAttendance(): number | null;
@@ -17,7 +17,9 @@ export default class Evento extends EventoPromoter<EventData> {
17
17
  get relEvents(): string[];
18
18
  get isASerie(): boolean;
19
19
  get playerIds(): string[];
20
- get players(): Record<string, EventPlayerBasicData>;
20
+ get players(): {
21
+ [x: string]: EventoPlayerBasic;
22
+ };
21
23
  get playersCount(): number;
22
24
  get repertory(): Record<string, import("./types").EventThemeBasicData>;
23
25
  get repertoryIds(): string[];
@@ -49,19 +51,7 @@ export default class Evento extends EventoPromoter<EventData> {
49
51
  playersList({ showAll, order }?: {
50
52
  showAll?: boolean;
51
53
  order?: InstrumentId[];
52
- }): {
53
- note?: string | null | undefined;
54
- reason?: import("./Player/types").EventPlayerReason | null | undefined;
55
- status: EventPlayerStatus | null;
56
- rollcall: EventPlayerStatus | null;
57
- interested: true | null;
58
- selected: boolean | null;
59
- mainInstrument: InstrumentId;
60
- username: string;
61
- displayName: string;
62
- photoURL: string;
63
- id: string;
64
- }[];
54
+ }): EventoPlayerBasic[];
65
55
  get interestedPlayers(): string[];
66
56
  get confirmedPlayers(): string[];
67
57
  get declinedPlayers(): string[];
@@ -73,13 +63,7 @@ export default class Evento extends EventoPromoter<EventData> {
73
63
  get templateId(): string | null;
74
64
  get repeat(): import("./types").EventRepeatType | null;
75
65
  isPlayer: (userId: string) => boolean;
76
- isPlayerActive: (userId: string) => boolean;
77
- getPlayer: (userId: string) => EventPlayerBasicData | null;
78
- isPlayerInterested(player: EventPlayerBasicData): boolean;
79
- isPlayerConfirmed(player: EventPlayerBasicData): boolean;
80
- isPlayerDeclined(player: EventPlayerBasicData): boolean;
81
- isPlayerRollCallConfirmed(player: EventPlayerBasicData): boolean;
82
- isPlayerRollCallDeclined(player: EventPlayerBasicData): boolean;
66
+ getPlayer: (userId: string) => EventoPlayerBasic | null;
83
67
  get responseDeadline(): {
84
68
  option: EventResponseDeadlineOptions;
85
69
  customAt: import("../../types/firestore").Timestamp | null;
@@ -8,19 +8,15 @@ const lodash_1 = require("lodash");
8
8
  const orders_1 = require("../../helpers/musicStyles/orders");
9
9
  const utils_1 = require("../../helpers/utils");
10
10
  const lang_1 = require("../../lang");
11
- const types_1 = require("./Player/types");
12
11
  const promoter_1 = __importDefault(require("./promoter"));
13
- const types_2 = require("./types");
12
+ const types_1 = require("./types");
13
+ const Basic_1 = __importDefault(require("./Player/Basic"));
14
14
  class Evento extends promoter_1.default {
15
15
  constructor(doc, lang = lang_1.defaultLocale) {
16
16
  super(doc, lang);
17
17
  this.isPlayer = (userId) => {
18
18
  return this.playerIds.includes(userId);
19
19
  };
20
- this.isPlayerActive = (userId) => {
21
- const player = this.getPlayer(userId);
22
- return player !== null && player.selected !== false;
23
- };
24
20
  this.getPlayer = (userId) => {
25
21
  return userId in this.players ? this.players[userId] : null;
26
22
  };
@@ -59,7 +55,7 @@ class Evento extends promoter_1.default {
59
55
  return this.data.playerIds || [];
60
56
  }
61
57
  get players() {
62
- return this.data.players || {};
58
+ return (0, lodash_1.mapValues)(this.data.players || {}, (player, id) => new Basic_1.default(this.id, { id, ...player }, this.lang));
63
59
  }
64
60
  get playersCount() {
65
61
  return this.data.playerIds.length;
@@ -121,12 +117,12 @@ class Evento extends promoter_1.default {
121
117
  }
122
118
  get statusByTime() {
123
119
  if (this.isOutDate) {
124
- return types_2.EventStatusByTime.Past;
120
+ return types_1.EventStatusByTime.Past;
125
121
  }
126
122
  if (this.isHappening) {
127
- return types_2.EventStatusByTime.Now;
123
+ return types_1.EventStatusByTime.Now;
128
124
  }
129
- return types_2.EventStatusByTime.Future;
125
+ return types_1.EventStatusByTime.Future;
130
126
  }
131
127
  get repertoryList() {
132
128
  const repertory = Object.keys(this.repertory).map((themeId) => ({
@@ -136,34 +132,31 @@ class Evento extends promoter_1.default {
136
132
  return (0, lodash_1.orderBy)(repertory, 'order', 'asc');
137
133
  }
138
134
  playersList({ showAll, order } = {}) {
139
- const players = this.playerIds.map((playerId) => ({
140
- id: playerId,
141
- ...this.players[playerId],
142
- }));
135
+ const players = Object.values(this.players);
143
136
  const orderedPlayers = order
144
137
  ? (0, utils_1.sortByMatch)(players, 'mainInstrument', order)
145
138
  : (0, orders_1.orderByMusicStyle)(players, 'mainInstrument', this.promoterInfo.musicStyle);
146
139
  if (showAll)
147
140
  return orderedPlayers;
148
- return orderedPlayers.filter((player) => this.isPlayerActive(player.id));
141
+ return orderedPlayers.filter((player) => player.isActive);
149
142
  }
150
143
  get interestedPlayers() {
151
- return this.playerIds.filter((playerId) => this.isPlayerInterested(this.players[playerId]));
144
+ return this.playerIds.filter((playerId) => this.players[playerId].isInterested);
152
145
  }
153
146
  get confirmedPlayers() {
154
- return this.playerIds.filter((playerId) => this.isPlayerConfirmed(this.players[playerId]));
147
+ return this.playerIds.filter((playerId) => this.players[playerId].isConfirmed);
155
148
  }
156
149
  get declinedPlayers() {
157
- return this.playerIds.filter((playerId) => this.isPlayerDeclined(this.players[playerId]));
150
+ return this.playerIds.filter((playerId) => this.players[playerId].isDeclined);
158
151
  }
159
152
  get pendingPlayers() {
160
- return this.playerIds.filter((playerId) => !this.players[playerId].status);
153
+ return this.playerIds.filter((playerId) => this.players[playerId].isPending);
161
154
  }
162
155
  get confirmedRollCallPlayers() {
163
- return this.playerIds.filter((playerId) => this.isPlayerRollCallConfirmed(this.players[playerId]));
156
+ return this.playerIds.filter((playerId) => this.players[playerId].isRollCallConfirmed);
164
157
  }
165
158
  get declinedRollCallPlayers() {
166
- return this.playerIds.filter((playerId) => this.isPlayerRollCallDeclined(this.players[playerId]));
159
+ return this.playerIds.filter((playerId) => this.players[playerId].isRollCallDeclined);
167
160
  }
168
161
  get isRollCalled() {
169
162
  return this.rollCalledAt !== null;
@@ -177,24 +170,9 @@ class Evento extends promoter_1.default {
177
170
  get repeat() {
178
171
  return this.data.repeat || null;
179
172
  }
180
- isPlayerInterested(player) {
181
- return player.interested === true;
182
- }
183
- isPlayerConfirmed(player) {
184
- return player.status === types_1.EventPlayerStatus.Confirmed;
185
- }
186
- isPlayerDeclined(player) {
187
- return player.status === types_1.EventPlayerStatus.Declined;
188
- }
189
- isPlayerRollCallConfirmed(player) {
190
- return player.rollcall === types_1.EventPlayerStatus.Confirmed;
191
- }
192
- isPlayerRollCallDeclined(player) {
193
- return player.rollcall === types_1.EventPlayerStatus.Declined;
194
- }
195
173
  get responseDeadline() {
196
174
  return (this.data.responseDeadline || {
197
- option: types_2.EventResponseDeadlineOptions.BeforeEvent,
175
+ option: types_1.EventResponseDeadlineOptions.BeforeEvent,
198
176
  customAt: null,
199
177
  });
200
178
  }
@@ -205,10 +183,10 @@ class Evento extends promoter_1.default {
205
183
  return this.data.selectionModeClosedAt || null;
206
184
  }
207
185
  get isSelectionModeClose() {
208
- return (!(0, lodash_1.isNull)(this.selectionModeClosedAt) && this.selectionMode === types_2.EventSelectionMode.Closed);
186
+ return (!(0, lodash_1.isNull)(this.selectionModeClosedAt) && this.selectionMode === types_1.EventSelectionMode.Closed);
209
187
  }
210
188
  get isSelectionModeOpen() {
211
- return (0, lodash_1.isNull)(this.selectionModeClosedAt) && this.selectionMode === types_2.EventSelectionMode.Open;
189
+ return (0, lodash_1.isNull)(this.selectionModeClosedAt) && this.selectionMode === types_1.EventSelectionMode.Open;
212
190
  }
213
191
  }
214
192
  exports.default = Evento;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glissandoo/lib",
3
- "version": "1.52.3",
3
+ "version": "1.53.1",
4
4
  "description": "Glissandoo library js",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",