@entropic-bond/firebase 1.12.0 → 1.13.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/.firebaserc +5 -0
- package/.github/workflows/release.yml +27 -0
- package/CHANGELOG.md +331 -0
- package/firebase.json +30 -0
- package/firestore.indexes.json +4 -0
- package/firestore.rules +8 -0
- package/functions/package-lock.json +2344 -0
- package/functions/package.json +26 -0
- package/functions/src/index.ts +33 -0
- package/functions/tsconfig.json +19 -0
- package/package.json +15 -12
- package/src/auth/firebase-auth.spec.ts +90 -0
- package/src/auth/firebase-auth.ts +212 -0
- package/src/cloud-functions/firebase-cloud-functions.spec.ts +47 -0
- package/src/cloud-functions/firebase-cloud-functions.ts +25 -0
- package/src/cloud-storage/firebase-cloud-storage.spec.ts +135 -0
- package/src/cloud-storage/firebase-cloud-storage.ts +67 -0
- package/src/firebase-helper.ts +92 -0
- package/src/index.ts +5 -0
- package/src/mocks/mock-data.json +148 -0
- package/src/mocks/test-user.ts +121 -0
- package/src/store/firebase-datasource.spec.ts +555 -0
- package/src/store/firebase-datasource.ts +146 -0
- package/storage.rules +8 -0
- package/tsconfig-build.json +7 -0
- package/tsconfig.json +30 -0
- package/vite.config.ts +23 -0
- package/lib/auth/firebase-auth.d.ts +0 -20
- package/lib/auth/firebase-auth.js +0 -189
- package/lib/auth/firebase-auth.js.map +0 -1
- package/lib/cloud-functions/firebase-cloud-functions.d.ts +0 -7
- package/lib/cloud-functions/firebase-cloud-functions.js +0 -27
- package/lib/cloud-functions/firebase-cloud-functions.js.map +0 -1
- package/lib/cloud-storage/firebase-cloud-storage.d.ts +0 -10
- package/lib/cloud-storage/firebase-cloud-storage.js +0 -70
- package/lib/cloud-storage/firebase-cloud-storage.js.map +0 -1
- package/lib/firebase-helper.d.ts +0 -38
- package/lib/firebase-helper.js +0 -57
- package/lib/firebase-helper.js.map +0 -1
- package/lib/index.d.ts +0 -5
- package/lib/index.js +0 -22
- package/lib/index.js.map +0 -1
- package/lib/mocks/test-user.d.ts +0 -49
- package/lib/mocks/test-user.js +0 -134
- package/lib/mocks/test-user.js.map +0 -1
- package/lib/store/firebase-datasource.d.ts +0 -19
- package/lib/store/firebase-datasource.js +0 -117
- package/lib/store/firebase-datasource.js.map +0 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { registerCloudStorage, CloudStorage, UploadControl, UploadProgress } from 'entropic-bond'
|
|
2
|
+
import { deleteObject, getDownloadURL, ref, uploadBytesResumable, UploadTask, connectStorageEmulator } from 'firebase/storage'
|
|
3
|
+
import { EmulatorConfig, FirebaseHelper } from '../firebase-helper'
|
|
4
|
+
|
|
5
|
+
@registerCloudStorage( 'FirebaseCloudStorage', ()=> new FirebaseCloudStorage() )
|
|
6
|
+
export class FirebaseCloudStorage extends CloudStorage {
|
|
7
|
+
constructor( emulator?: EmulatorConfig ) {
|
|
8
|
+
super()
|
|
9
|
+
if ( emulator ) FirebaseHelper.useEmulator( emulator )
|
|
10
|
+
|
|
11
|
+
if ( FirebaseHelper.emulator?.emulate ) {
|
|
12
|
+
const { host, storagePort } = FirebaseHelper.emulator
|
|
13
|
+
connectStorageEmulator( FirebaseHelper.instance.storage(), host, storagePort )
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
save( id: string, data: Blob | Uint8Array | ArrayBuffer, progress?: UploadProgress ): Promise<string> {
|
|
18
|
+
const storage = FirebaseHelper.instance.storage()
|
|
19
|
+
|
|
20
|
+
return new Promise<string>(( resolve, reject ) => {
|
|
21
|
+
this._uploadTask = uploadBytesResumable( ref( storage, id ), data )
|
|
22
|
+
|
|
23
|
+
if ( progress ) {
|
|
24
|
+
var unsubscribe = this._uploadTask.on( 'state_changed',
|
|
25
|
+
snapshot => {
|
|
26
|
+
progress( snapshot.bytesTransferred, snapshot.totalBytes )
|
|
27
|
+
},
|
|
28
|
+
null,
|
|
29
|
+
()=>unsubscribe()
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
this._uploadTask
|
|
34
|
+
.then( () => resolve( id ) )
|
|
35
|
+
.catch( error => reject( error ))
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
getUrl( reference: string ): Promise<string> {
|
|
40
|
+
if ( !reference ) return Promise.reject( 'needs a reference' )
|
|
41
|
+
|
|
42
|
+
const storage = FirebaseHelper.instance.storage()
|
|
43
|
+
return getDownloadURL( ref( storage, reference ) )
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
uploadControl(): UploadControl {
|
|
47
|
+
if ( !this._uploadTask ) throw new Error( `You should call save() before uploadControl()` )
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
cancel: ()=>this._uploadTask?.cancel(),
|
|
51
|
+
pause: ()=>this._uploadTask?.pause(),
|
|
52
|
+
resume: ()=>this._uploadTask?.resume(),
|
|
53
|
+
onProgress: ( callback )=> this._uploadTask?.on( 'state_changed', snapShot => {
|
|
54
|
+
if ( callback ) {
|
|
55
|
+
callback( snapShot.bytesTransferred, snapShot.totalBytes )
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
delete( reference: string ): Promise<void> {
|
|
62
|
+
const storage = FirebaseHelper.instance.storage()
|
|
63
|
+
return deleteObject( ref( storage, reference ) )
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private _uploadTask: UploadTask | undefined
|
|
67
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { FirebaseApp, initializeApp } from "firebase/app"
|
|
2
|
+
import { CollectionReference, DocumentData, getFirestore, Query } from 'firebase/firestore'
|
|
3
|
+
import { getAuth } from 'firebase/auth'
|
|
4
|
+
import { getStorage } from 'firebase/storage'
|
|
5
|
+
import { getFunctions } from 'firebase/functions'
|
|
6
|
+
|
|
7
|
+
export type FirebaseQuery = CollectionReference<DocumentData>
|
|
8
|
+
| Query<DocumentData>
|
|
9
|
+
|
|
10
|
+
export interface FirebaseConfig {
|
|
11
|
+
apiKey?: string,
|
|
12
|
+
authDomain?: string,
|
|
13
|
+
projectId: string,
|
|
14
|
+
databaseURL?: string,
|
|
15
|
+
storageBucket?: string,
|
|
16
|
+
messagingSenderId?: string,
|
|
17
|
+
appId?: string,
|
|
18
|
+
measurementId?: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface EmulatorConfig {
|
|
22
|
+
host: string
|
|
23
|
+
firestorePort: number
|
|
24
|
+
storagePort: number
|
|
25
|
+
authPort: number
|
|
26
|
+
functionsPort: number
|
|
27
|
+
emulate: boolean
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class FirebaseHelper {
|
|
31
|
+
|
|
32
|
+
static setFirebaseConfig( config: FirebaseConfig ) {
|
|
33
|
+
FirebaseHelper._firebaseConfig = config
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private static defaultEmulatorConfig = {
|
|
37
|
+
host: 'localhost',
|
|
38
|
+
firestorePort: 8080,
|
|
39
|
+
storagePort: 9199,
|
|
40
|
+
authPort: 9099,
|
|
41
|
+
functionsPort: 5001,
|
|
42
|
+
emulate: false
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static useEmulator( emulatorConfig?: Partial<EmulatorConfig> ) {
|
|
46
|
+
|
|
47
|
+
this._emulatorConfig = {
|
|
48
|
+
...FirebaseHelper.defaultEmulatorConfig,
|
|
49
|
+
emulate: true,
|
|
50
|
+
...emulatorConfig
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static get emulator() {
|
|
55
|
+
return this._emulatorConfig
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private constructor() {
|
|
59
|
+
if ( !FirebaseHelper._firebaseConfig ) throw new Error( 'You should set a firebase config object before using Firebase' )
|
|
60
|
+
this._firebaseApp = initializeApp( FirebaseHelper._firebaseConfig )
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static get instance() {
|
|
64
|
+
return this._instance || ( this._instance = new FirebaseHelper() )
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
firestore() {
|
|
68
|
+
return getFirestore( this._firebaseApp )
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
storage() {
|
|
72
|
+
return getStorage( this._firebaseApp )
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
auth() {
|
|
76
|
+
return getAuth( this._firebaseApp )
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
functions() {
|
|
80
|
+
return getFunctions( this._firebaseApp, FirebaseHelper._region )
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static setRegion( region: string ) {
|
|
84
|
+
this._region = region
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private static _instance: FirebaseHelper
|
|
88
|
+
private static _firebaseConfig: FirebaseConfig
|
|
89
|
+
private static _emulatorConfig: EmulatorConfig = FirebaseHelper.defaultEmulatorConfig
|
|
90
|
+
private static _region: string
|
|
91
|
+
private _firebaseApp: FirebaseApp
|
|
92
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
{
|
|
2
|
+
"TestUser": {
|
|
3
|
+
"user1": {
|
|
4
|
+
"__className": "TestUser",
|
|
5
|
+
"id": "user1",
|
|
6
|
+
"name": {
|
|
7
|
+
"firstName": "userFirstName1",
|
|
8
|
+
"lastName": "userLastName1"
|
|
9
|
+
},
|
|
10
|
+
"age": 23,
|
|
11
|
+
"admin": true,
|
|
12
|
+
"skills": ["skill1", "skill2", "skill3"]
|
|
13
|
+
},
|
|
14
|
+
"user2": {
|
|
15
|
+
"__className": "TestUser",
|
|
16
|
+
"id": "user2",
|
|
17
|
+
"name": {
|
|
18
|
+
"firstName": "userFirstName2",
|
|
19
|
+
"lastName": "userLastName2",
|
|
20
|
+
"ancestorName": {
|
|
21
|
+
"father": "user2Father"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"age": 21,
|
|
25
|
+
"admin": false,
|
|
26
|
+
"skills": ["skill1", "skill2", "skill3"],
|
|
27
|
+
"colleagues": [
|
|
28
|
+
{
|
|
29
|
+
"id": "colleague1",
|
|
30
|
+
"__className": "TestUser"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"id": "user3",
|
|
34
|
+
"__className": "TestUser"
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"__colleagues_searchable": [ "colleague1", "user3" ]
|
|
38
|
+
},
|
|
39
|
+
"user3": {
|
|
40
|
+
"__className": "TestUser",
|
|
41
|
+
"id": "user3",
|
|
42
|
+
"name": {
|
|
43
|
+
"firstName": "userFirstName3",
|
|
44
|
+
"lastName": "userLastName3",
|
|
45
|
+
"ancestorName": {
|
|
46
|
+
"father": "user3Father"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"age": 56,
|
|
50
|
+
"admin": true,
|
|
51
|
+
"skills": ["skill21", "skill22", "skill23"],
|
|
52
|
+
"colleagues": [
|
|
53
|
+
{
|
|
54
|
+
"id": "user1",
|
|
55
|
+
"__className": "TestUser"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"id": "user3",
|
|
59
|
+
"__className": "TestUser"
|
|
60
|
+
}
|
|
61
|
+
],
|
|
62
|
+
"__colleagues_searchable": [ "user1", "user3" ]
|
|
63
|
+
},
|
|
64
|
+
"user4": {
|
|
65
|
+
"__className": "DerivedUser",
|
|
66
|
+
"id": "user4",
|
|
67
|
+
"name": {
|
|
68
|
+
"firstName": "userFirstName4",
|
|
69
|
+
"lastName": "userLastName4"
|
|
70
|
+
},
|
|
71
|
+
"age": 35,
|
|
72
|
+
"admin": false,
|
|
73
|
+
"skills": ["skill41", "skill42", "skill43"],
|
|
74
|
+
"salary": 2800,
|
|
75
|
+
"colleagues": [
|
|
76
|
+
{
|
|
77
|
+
"id": "colleague1",
|
|
78
|
+
"__className": "TestUser"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"id": "colleague2",
|
|
82
|
+
"__className": "TestUser"
|
|
83
|
+
}
|
|
84
|
+
],
|
|
85
|
+
"__colleagues_searchable": [ "colleague1", "colleague2" ]
|
|
86
|
+
},
|
|
87
|
+
"user5": {
|
|
88
|
+
"__className": "TestUser",
|
|
89
|
+
"id": "user5",
|
|
90
|
+
"name": {
|
|
91
|
+
"firstName": "userFirstName5",
|
|
92
|
+
"lastName": "userLastName5",
|
|
93
|
+
"ancestorName": {
|
|
94
|
+
"father": "user5Father"
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
"age": 41,
|
|
98
|
+
"skills": ["skill21", "skill22", "skill23"],
|
|
99
|
+
"derived": {
|
|
100
|
+
"id": "user3",
|
|
101
|
+
"__className": "DerivedUser",
|
|
102
|
+
"__documentReference": {
|
|
103
|
+
"storedInCollection": "DerivedUser"
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
"user6": {
|
|
108
|
+
"__className": "TestUser",
|
|
109
|
+
"id": "user6",
|
|
110
|
+
"name": {
|
|
111
|
+
"firstName": "userFirstName6",
|
|
112
|
+
"lastName": "userLastName6",
|
|
113
|
+
"ancestorName": {
|
|
114
|
+
"father": "user6Father"
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
"age": 40,
|
|
118
|
+
"skills": ["skill21", "skill22", "skill23"],
|
|
119
|
+
"derived": {
|
|
120
|
+
"id": "user4",
|
|
121
|
+
"__className": "DerivedUser",
|
|
122
|
+
"__documentReference": {
|
|
123
|
+
"storedInCollection": "TestUser"
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
"colleagues": [
|
|
127
|
+
{
|
|
128
|
+
"id": "colleague2",
|
|
129
|
+
"__className": "TestUser"
|
|
130
|
+
}
|
|
131
|
+
],
|
|
132
|
+
"__colleagues_searchable": [ "colleague2" ]
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
"DerivedUser": {
|
|
136
|
+
"user4": {
|
|
137
|
+
"__className": "DerivedUser",
|
|
138
|
+
"id": "user5",
|
|
139
|
+
"name": {
|
|
140
|
+
"firstName": "userFirstName5",
|
|
141
|
+
"lastName": "userLastName5"
|
|
142
|
+
},
|
|
143
|
+
"age": 35,
|
|
144
|
+
"admin": false,
|
|
145
|
+
"salary": 2300
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { persistent, Persistent, persistentReference, persistentReferenceAt, registerPersistentClass, searchableArray } from 'entropic-bond'
|
|
2
|
+
|
|
3
|
+
interface Name {
|
|
4
|
+
firstName: string,
|
|
5
|
+
lastName: string
|
|
6
|
+
ancestorName?: {
|
|
7
|
+
father?: string
|
|
8
|
+
mother?: string
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@registerPersistentClass( 'SubClass' )
|
|
13
|
+
export class SubClass extends Persistent {
|
|
14
|
+
set year( value: number | undefined ) {
|
|
15
|
+
this._year = value
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get year() {
|
|
19
|
+
return this._year
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@persistent private _year: number | undefined
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@registerPersistentClass( 'TestUser' )
|
|
26
|
+
export class TestUser extends Persistent {
|
|
27
|
+
set name( value: Name | undefined ) {
|
|
28
|
+
this._name = value
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get name() {
|
|
32
|
+
return this._name
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
set age( value: number | undefined ) {
|
|
36
|
+
this._age = value
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
get age() {
|
|
40
|
+
return this._age
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
set admin( value: boolean | undefined ) {
|
|
44
|
+
this._admin = value
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
get admin() {
|
|
48
|
+
return this._admin
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
set skills( value: string[] | undefined ) {
|
|
52
|
+
this._skills = value
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
get skills() {
|
|
56
|
+
return this._skills
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
set documentRef( value: SubClass | undefined ) {
|
|
60
|
+
this._documentRef = value
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
get documentRef() {
|
|
64
|
+
return this._documentRef
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
set manyRefs(value: SubClass[]) {
|
|
68
|
+
this._manyRefs = value
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
get manyRefs(): SubClass[] {
|
|
72
|
+
return this._manyRefs
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
set derived( value: DerivedUser | undefined ) {
|
|
76
|
+
this._derived = value
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
get derived(): DerivedUser | undefined {
|
|
80
|
+
return this._derived
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
set manyDerived( value: DerivedUser[] | undefined ) {
|
|
84
|
+
this._manyDerived = value
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
get manyDerived(): DerivedUser[] | undefined {
|
|
88
|
+
return this._manyDerived
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
set colleagues( value: TestUser[] ) {
|
|
92
|
+
this._colleagues = value
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
get colleagues(): TestUser[] {
|
|
96
|
+
return this._colleagues
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@persistent @searchableArray private _colleagues: TestUser[] = []
|
|
100
|
+
@persistent private _name: Name | undefined
|
|
101
|
+
@persistent private _age: number | undefined
|
|
102
|
+
@persistent private _admin: boolean | undefined
|
|
103
|
+
@persistent private _skills: string[] | undefined
|
|
104
|
+
@persistentReference private _documentRef: SubClass | undefined
|
|
105
|
+
@persistentReference private _manyRefs: SubClass[] = []
|
|
106
|
+
@persistentReferenceAt('TestUser') private _derived: DerivedUser | undefined
|
|
107
|
+
@persistentReferenceAt('TestUser') private _manyDerived: DerivedUser[] | undefined
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
@registerPersistentClass( 'DerivedUser' )
|
|
111
|
+
export class DerivedUser extends TestUser {
|
|
112
|
+
set salary(value: number | undefined ) {
|
|
113
|
+
this._salary = value
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
get salary(): number | undefined {
|
|
117
|
+
return this._salary
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@persistent private _salary: number | undefined
|
|
121
|
+
}
|