Skip to content

Commit

Permalink
prep for 17.1.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesdaniels committed May 14, 2024
1 parent 05e9da2 commit 4077a58
Show file tree
Hide file tree
Showing 15 changed files with 500 additions and 306 deletions.
617 changes: 316 additions & 301 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@angular/fire",
"version": "17.0.0",
"version": "17.1.0",
"description": "Angular + Firebase = ❤️",
"private": true,
"scripts": {
Expand Down Expand Up @@ -55,7 +55,7 @@
"@angular/platform-browser-dynamic": "^17.0.0",
"@angular/router": "^17.0.0",
"@schematics/angular": "^17.0.0",
"firebase": "^10.7.0",
"firebase": "^10.12.0",
"firebase-admin": "^9.11.1",
"firebase-functions": "^3.6.0",
"firebase-tools": "^13.0.0",
Expand Down
2 changes: 2 additions & 0 deletions src/app/firebase.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"firebase-tools": { "optional": true }
},
"dependencies": {
"firebase": "^10.7.0",
"firebase": "^10.12.0",
"rxfire": "^6.0.5",
"@angular-devkit/schematics": "^17.0.0",
"@schematics/angular": "^17.0.0",
Expand Down
4 changes: 3 additions & 1 deletion src/schematics/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ export const enum FEATURES {
Firestore,
Storage,
RemoteConfig,
VertexAI,
}

export const featureOptions = [
{ name: 'ng deploy -- hosting', value: FEATURES.Hosting },
{ name: 'ng deploy -- Hosting', value: FEATURES.Hosting },
{ name: 'Authentication', value: FEATURES.Authentication },
{ name: 'Google Analytics', value: FEATURES.Analytics },
{ name: 'App Check', value: FEATURES.AppCheck },
Expand All @@ -26,6 +27,7 @@ export const featureOptions = [
{ name: 'Performance Monitoring', value: FEATURES.Performance },
{ name: 'Cloud Storage', value: FEATURES.Storage },
{ name: 'Remote Config', value: FEATURES.RemoteConfig },
{ name: 'VertexAI (preview)', value: FEATURES.VertexAI },
];

export const enum PROJECT_TYPE { Static, CloudFunctions, CloudRun, WebFrameworks }
Expand Down
2 changes: 1 addition & 1 deletion src/schematics/setup/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const featuresPrompt = async (): Promise<FEATURES[]> => {
name: 'features',
choices: featureOptions,
message: 'What features would you like to setup?',
default: [FEATURES.Hosting],
default: [],
}) as { features: FEATURES[] };
return features;
};
Expand Down
5 changes: 5 additions & 0 deletions src/schematics/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ export function featureToRules(features: FEATURES[], projectName: string) {
external('getRemoteConfig', '@angular/fire/remote-config');
return code`${external('provideRemoteConfig', '@angular/fire/remote-config')}(() => getRemoteConfig())`;
});
case FEATURES.VertexAI:
return addRootProvider(projectName, ({code, external}) => {
external('getVertexAI', '@angular/fire/vertexai-preview');
return code`${external('provideVertexAI', '@angular/fire/vertexai-preview')}(() => getVertexAI())`;
});
default:
return undefined;
}
Expand Down
10 changes: 10 additions & 0 deletions src/vertexai-preview/firebase.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/vertexai-preview/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"lib": {
"entryFile": "public_api.ts"
}
}
3 changes: 3 additions & 0 deletions src/vertexai-preview/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"$schema": "../../node_modules/ng-packagr/package.schema.json"
}
3 changes: 3 additions & 0 deletions src/vertexai-preview/public_api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { VertexAI, VertexAIInstances, vertexAIInstance$ } from './vertexai';
export { provideVertexAI, VertexAIModule } from './vertexai.module';
export * from './firebase';
79 changes: 79 additions & 0 deletions src/vertexai-preview/vertexai.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import {
EnvironmentProviders,
InjectionToken,
Injector,
NgModule,
NgZone,
Optional,
makeEnvironmentProviders,
} from '@angular/core';
import { VERSION, ɵAngularFireSchedulers, ɵgetDefaultInstanceOf } from '@angular/fire';
import { ɵAppCheckInstances } from '@angular/fire';
import { FirebaseApp, FirebaseApps } from '@angular/fire/app';
import { registerVersion } from 'firebase/app';
import { VertexAI as FirebaseVertexAI } from 'firebase/vertexai-preview';
import { VERTEX_AI_PROVIDER_NAME, VertexAI, VertexAIInstances } from './vertexai';

export const PROVIDED_VERTEX_AI_INSTANCES = new InjectionToken<VertexAI[]>('angularfire2.vertexai-instances');

export function defaultVertexAIInstanceFactory(provided: FirebaseVertexAI[]|undefined, defaultApp: FirebaseApp) {
const defaultVertexAI = ɵgetDefaultInstanceOf<FirebaseVertexAI>(VERTEX_AI_PROVIDER_NAME, provided, defaultApp);
return defaultVertexAI && new VertexAI(defaultVertexAI);
}

export function vertexAIInstanceFactory(fn: (injector: Injector) => FirebaseVertexAI) {
return (zone: NgZone, injector: Injector) => {
const vertexAI = zone.runOutsideAngular(() => fn(injector));
return new VertexAI(vertexAI);
};
}

const VERTEX_AI_INSTANCES_PROVIDER = {
provide: VertexAIInstances,
deps: [
[new Optional(), PROVIDED_VERTEX_AI_INSTANCES ],
]
};

const DEFAULT_VERTEX_AI_INSTANCE_PROVIDER = {
provide: VertexAI,
useFactory: defaultVertexAIInstanceFactory,
deps: [
[new Optional(), PROVIDED_VERTEX_AI_INSTANCES ],
FirebaseApp,
]
};

@NgModule({
providers: [
DEFAULT_VERTEX_AI_INSTANCE_PROVIDER,
VERTEX_AI_INSTANCES_PROVIDER,
]
})
export class VertexAIModule {
constructor() {
registerVersion('angularfire', VERSION.full, 'vertexai');
}
}

export function provideVertexAI(fn: (injector: Injector) => FirebaseVertexAI, ...deps: any[]): EnvironmentProviders {
registerVersion('angularfire', VERSION.full, 'vertexai');

return makeEnvironmentProviders([
DEFAULT_VERTEX_AI_INSTANCE_PROVIDER,
VERTEX_AI_INSTANCES_PROVIDER,
{
provide: PROVIDED_VERTEX_AI_INSTANCES,
useFactory: vertexAIInstanceFactory(fn),
multi: true,
deps: [
NgZone,
Injector,
ɵAngularFireSchedulers,
FirebaseApps,
[new Optional(), ɵAppCheckInstances ],
...deps,
]
}
]);
}
38 changes: 38 additions & 0 deletions src/vertexai-preview/vertexai.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { TestBed } from '@angular/core/testing';
import { FirebaseApp, getApp, initializeApp, provideFirebaseApp } from '@angular/fire/app';
import { VertexAI, getVertexAI, provideVertexAI } from '@angular/fire/vertexai-preview';
import { COMMON_CONFIG } from '../test-config';
import { rando } from '../utils';

describe('VertexAI', () => {
let app: FirebaseApp;
let vertexAI: VertexAI;
let providedVertexAI: VertexAI;
let appName: string;

describe('single injection', () => {

beforeEach(() => {
appName = rando();
TestBed.configureTestingModule({
providers: [
provideFirebaseApp(() => initializeApp(COMMON_CONFIG, appName)),
provideVertexAI(() => {
providedVertexAI = getVertexAI(getApp(appName));
return providedVertexAI;
}),
],
});
app = TestBed.inject(FirebaseApp);
vertexAI = TestBed.inject(VertexAI);
});

it('should be injectable', () => {
expect(providedVertexAI).toBeTruthy();
expect(vertexAI).toEqual(providedVertexAI);
expect(vertexAI.app).toEqual(app);
});

});

});
30 changes: 30 additions & 0 deletions src/vertexai-preview/vertexai.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { ɵgetAllInstancesOf } from '@angular/fire';
import { VertexAI as FirebaseVertexAI } from 'firebase/vertexai-preview';
import { from, timer } from 'rxjs';
import { concatMap, distinct } from 'rxjs/operators';

// see notes in core/firebase.app.module.ts for why we're building the class like this
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface VertexAI extends FirebaseVertexAI {}

export class VertexAI {
constructor(vertexai: FirebaseVertexAI) {
return vertexai;
}
}

export const VERTEX_AI_PROVIDER_NAME = 'vertexai';

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface VertexAIInstances extends Array<FirebaseVertexAI> {}

export class VertexAIInstances {
constructor() {
return ɵgetAllInstancesOf<FirebaseVertexAI>(VERTEX_AI_PROVIDER_NAME);
}
}

export const vertexAIInstance$ = timer(0, 300).pipe(
concatMap(() => from(ɵgetAllInstancesOf<FirebaseVertexAI>(VERTEX_AI_PROVIDER_NAME))),
distinct(),
);
1 change: 1 addition & 0 deletions tools/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ ${exportedZoneWrappedFns}
collection: { exportName: 'collectionSnapshots' },
}),
reexport('firestore/lite', 'firebase', 'firebase/firestore/lite', tsKeys<typeof import('firebase/firestore/lite')>()),
reexport('vertexai-preview', 'firebase', 'firebase/vertexai-preview', tsKeys<typeof import('firebase/vertexai-preview')>()),
]);
}

Expand Down

0 comments on commit 4077a58

Please sign in to comment.