@glissandoo/lib 1.56.0 → 1.57.0
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/helpers/firestore.d.ts +11 -0
- package/helpers/firestore.js +196 -0
- package/lang/ca.json +1 -0
- package/lang/de.json +1 -0
- package/lang/en.json +1 -0
- package/lang/es.json +1 -0
- package/lang/eu.json +2 -1
- package/lang/gl.json +1 -0
- package/lang/pt.json +1 -0
- package/models/Instrument/group.js +6 -3
- package/models/Instrument/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -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;
|
package/lang/ca.json
CHANGED
|
@@ -130,6 +130,7 @@
|
|
|
130
130
|
"instruments.ukelele": "Ukelele",
|
|
131
131
|
"instruments.viola": "Viola",
|
|
132
132
|
"instruments.violin": "Violí",
|
|
133
|
+
"instruments.unknown": "Instrument desconegut",
|
|
133
134
|
"musicStyles.banda-cornetas-y-tambores": "Banda de cornetes i tambors",
|
|
134
135
|
"musicStyles.banda-de-musica": "Banda de música",
|
|
135
136
|
"musicStyles.batucada": "Batucada",
|
package/lang/de.json
CHANGED
|
@@ -130,6 +130,7 @@
|
|
|
130
130
|
"instruments.ukelele": "Ukulele",
|
|
131
131
|
"instruments.viola": "Viola",
|
|
132
132
|
"instruments.violin": "Violine",
|
|
133
|
+
"instruments.unknown": "Unbekanntes Instrument",
|
|
133
134
|
"musicStyles.banda-cornetas-y-tambores": "Schlagzeug und Blasorchester",
|
|
134
135
|
"musicStyles.banda-de-musica": "Blasorchester",
|
|
135
136
|
"musicStyles.batucada": "Batukada",
|
package/lang/en.json
CHANGED
|
@@ -130,6 +130,7 @@
|
|
|
130
130
|
"instruments.ukelele": "Ukelele",
|
|
131
131
|
"instruments.viola": "Viola",
|
|
132
132
|
"instruments.violin": "Violin",
|
|
133
|
+
"instruments.unknown": "Unknown {musicType}",
|
|
133
134
|
"musicStyles.banda-cornetas-y-tambores": "Drums and winds band",
|
|
134
135
|
"musicStyles.banda-de-musica": "Concert band",
|
|
135
136
|
"musicStyles.batucada": "Batucada",
|
package/lang/es.json
CHANGED
|
@@ -130,6 +130,7 @@
|
|
|
130
130
|
"instruments.ukelele": "Ukelele",
|
|
131
131
|
"instruments.viola": "Viola",
|
|
132
132
|
"instruments.violin": "Violín",
|
|
133
|
+
"instruments.unknown": "Instrumento desconocido",
|
|
133
134
|
"musicStyles.banda-cornetas-y-tambores": "Banda de cornetas y tambores",
|
|
134
135
|
"musicStyles.banda-de-musica": "Banda de música",
|
|
135
136
|
"musicStyles.batucada": "Batucada",
|
package/lang/eu.json
CHANGED
|
@@ -129,7 +129,8 @@
|
|
|
129
129
|
"instruments.txistu": "Txistua",
|
|
130
130
|
"instruments.ukelele": "Ukelelea",
|
|
131
131
|
"instruments.viola": "Biola",
|
|
132
|
-
"instruments.violin": "Biolina
|
|
132
|
+
"instruments.violin": "Biolina",
|
|
133
|
+
"instruments.unknown": "Intrumentu ezezaguna",
|
|
133
134
|
"musicStyles.banda-cornetas-y-tambores": "Danbor eta korneta banda",
|
|
134
135
|
"musicStyles.banda-de-musica": "Musika banda",
|
|
135
136
|
"musicStyles.batucada": "Batukada",
|
package/lang/gl.json
CHANGED
|
@@ -130,6 +130,7 @@
|
|
|
130
130
|
"instruments.ukelele": "Ukelele",
|
|
131
131
|
"instruments.viola": "Viola",
|
|
132
132
|
"instruments.violin": "Violín",
|
|
133
|
+
"instruments.unknown": "Instrumento descoñecido",
|
|
133
134
|
"musicStyles.banda-cornetas-y-tambores": "Banda de cornetas e tambores",
|
|
134
135
|
"musicStyles.banda-de-musica": "Banda de música",
|
|
135
136
|
"musicStyles.batucada": "Batucada",
|
package/lang/pt.json
CHANGED
|
@@ -130,6 +130,7 @@
|
|
|
130
130
|
"instruments.ukelele": "Ukelele",
|
|
131
131
|
"instruments.viola": "viola",
|
|
132
132
|
"instruments.violin": "Violino",
|
|
133
|
+
"instruments.unknown": "Instrumento desconhecido",
|
|
133
134
|
"musicStyles.banda-cornetas-y-tambores": "Banda de Sopros e Percussão",
|
|
134
135
|
"musicStyles.banda-de-musica": "Banda",
|
|
135
136
|
"musicStyles.batucada": "Batucada",
|
|
@@ -17,9 +17,12 @@ class GroupInstrument extends _1.default {
|
|
|
17
17
|
return GroupInstrument.isCustom(this.id);
|
|
18
18
|
}
|
|
19
19
|
get name() {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
if (!GroupInstrument.isCustom(this.id))
|
|
21
|
+
return super.name;
|
|
22
|
+
if (this.id in this.groupInstruments) {
|
|
23
|
+
return this.groupInstruments[this.id].name;
|
|
24
|
+
}
|
|
25
|
+
return (0, lang_1.getTranslation)('instruments.unknown', this.lang) || this.id;
|
|
23
26
|
}
|
|
24
27
|
get icon() {
|
|
25
28
|
return GroupInstrument.isCustom(this.id) && this.id in this.groupInstruments
|
|
@@ -2,7 +2,7 @@ import { InstrumentId } from '../../helpers/instruments';
|
|
|
2
2
|
import { LanguagesTypes } from '../../lang';
|
|
3
3
|
export default class Instrument {
|
|
4
4
|
id: InstrumentId;
|
|
5
|
-
|
|
5
|
+
protected lang: LanguagesTypes;
|
|
6
6
|
constructor(id: InstrumentId, lang?: LanguagesTypes);
|
|
7
7
|
get name(): string;
|
|
8
8
|
get icon(): string;
|