-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added FirebaseServerStorageService
- added firebase-server nestjs service/module related to the storage services - updated demo and template to provide/export a storage moduleÏ
- Loading branch information
Showing
21 changed files
with
247 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { firebaseServerStorageModuleMetadata } from '@dereekb/firebase-server'; | ||
import { Module } from '@nestjs/common'; | ||
|
||
@Module(firebaseServerStorageModuleMetadata()) | ||
export class DemoApiStorageModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './driver'; | ||
export * from './driver.accessor'; | ||
export * from './storage.nest'; | ||
export * from './storage.service'; | ||
export * from './storage'; |
46 changes: 46 additions & 0 deletions
46
packages/firebase-server/src/lib/storage/storage.nest.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { firebaseAdminFunctionNestContextFactory, initFirebaseServerAdminTestEnvironment } from '@dereekb/firebase-server/test'; | ||
import { firebaseServerStorageModuleMetadata } from './storage.nest'; | ||
import { FirebaseServerStorageService } from './storage.service'; | ||
import { FirebaseStorageContext } from '@dereekb/firebase'; | ||
|
||
class TestFirebaseServerStorageService extends FirebaseServerStorageService {} | ||
|
||
@Module( | ||
firebaseServerStorageModuleMetadata({ | ||
serviceProvider: { | ||
provide: TestFirebaseServerStorageService, | ||
useFactory: (x: FirebaseStorageContext) => new TestFirebaseServerStorageService(x) | ||
} | ||
}) | ||
) | ||
class TestStorageAppModule {} | ||
|
||
/** | ||
* Test context factory that will automatically instantiate TestAppModule for each test, and make it available. | ||
*/ | ||
const firebaseStorageAdminFunctionNestContext = firebaseAdminFunctionNestContextFactory({ | ||
nestModules: TestStorageAppModule, | ||
injectFirebaseServerAppTokenProvider: true | ||
}); | ||
|
||
describe('firebase nest storage', () => { | ||
initFirebaseServerAdminTestEnvironment(); | ||
|
||
firebaseStorageAdminFunctionNestContext((f) => { | ||
let storageService: TestFirebaseServerStorageService; | ||
|
||
beforeEach(() => { | ||
storageService = f.get(TestFirebaseServerStorageService); | ||
}); | ||
|
||
describe('FirebaseServerStorageService', () => { | ||
describe('file', () => { | ||
it('should create a file', () => { | ||
const file = storageService.file('hello.txt'); | ||
expect(file).toBeDefined(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/firebase-server/src/lib/storage/storage.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { FirebaseStorageAccessor, FirebaseStorageAccessorFile, FirebaseStorageAccessorFolder, FirebaseStorageContext, StorageBucketId, StoragePathInput } from '@dereekb/firebase'; | ||
|
||
// MARK: Service | ||
/** | ||
* Reference to a FirebaseServerStorageService | ||
*/ | ||
export interface FirebaseServerStorageServiceRef<S extends FirebaseServerStorageService = FirebaseServerStorageService> { | ||
readonly storageService: S; | ||
} | ||
|
||
/** | ||
* Basic service that implements FirebaseStorageAccessor and provides a FirebaseStorageContext. | ||
*/ | ||
export class FirebaseServerStorageService implements FirebaseStorageAccessor { | ||
constructor(readonly storageContext: FirebaseStorageContext) {} | ||
|
||
defaultBucket() { | ||
return this.storageContext.defaultBucket(); | ||
} | ||
|
||
file(path: StoragePathInput): FirebaseStorageAccessorFile { | ||
return this.storageContext.file(path); | ||
} | ||
|
||
folder(path: StoragePathInput): FirebaseStorageAccessorFolder { | ||
return this.storageContext.folder(path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.