Skip to content

Commit 144961b

Browse files
committed
Fix bug caused by type fix
1 parent 4d834de commit 144961b

File tree

4 files changed

+44
-41
lines changed

4 files changed

+44
-41
lines changed

packages/ai/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"dev": "rollup -c -w",
3636
"update-responses": "../../scripts/update_vertexai_responses.sh",
3737
"testsetup": "yarn update-responses && yarn ts-node ./test-utils/convert-mocks.ts",
38-
"test": "run-p --npm-path npm lint test:browser",
38+
"test": "run-p --npm-path npm lint type-check test:browser",
3939
"test:ci": "yarn testsetup && node ../../scripts/run_tests_in_ci.js -s test",
4040
"test:skip-clone": "karma start",
4141
"test:browser": "yarn testsetup && karma start",
@@ -44,6 +44,7 @@
4444
"test:integration:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' mocha integration/**/*.test.ts --config ../../config/mocharc.node.js",
4545
"api-report": "api-extractor run --local --verbose",
4646
"typings:public": "node ../../scripts/build/use_typings.js ./dist/ai-public.d.ts",
47+
"type-check": "yarn tsc --noEmit",
4748
"trusted-type-check": "tsec -p tsconfig.json --noEmit"
4849
},
4950
"peerDependencies": {

packages/ai/src/factory-browser.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
import { ComponentContainer, InstanceFactoryOptions } from "@firebase/component";
3+
import { AIError } from "./errors";
4+
import { decodeInstanceIdentifier } from "./helpers";
5+
import { chromeAdapterFactory } from "./methods/chrome-adapter";
6+
import { AIService } from "./service";
7+
import { AIErrorCode } from "./types";
8+
9+
export function factory(
10+
container: ComponentContainer,
11+
{ instanceIdentifier }: InstanceFactoryOptions
12+
): AIService {
13+
if (!instanceIdentifier) {
14+
throw new AIError(
15+
AIErrorCode.ERROR,
16+
'AIService instance identifier is undefined.'
17+
);
18+
}
19+
20+
const backend = decodeInstanceIdentifier(instanceIdentifier);
21+
22+
// getImmediate for FirebaseApp will always succeed
23+
const app = container.getProvider('app').getImmediate();
24+
const auth = container.getProvider('auth-internal');
25+
const appCheckProvider = container.getProvider('app-check-internal');
26+
27+
return new AIService(
28+
app,
29+
backend,
30+
auth,
31+
appCheckProvider,
32+
chromeAdapterFactory
33+
);
34+
}

packages/ai/src/index.ts

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -22,54 +22,18 @@
2222
*/
2323

2424
import { registerVersion, _registerComponent } from '@firebase/app';
25-
import { AIService } from './service';
2625
import { AI_TYPE } from './constants';
27-
import {
28-
Component,
29-
ComponentContainer,
30-
ComponentType,
31-
InstanceFactoryOptions
32-
} from '@firebase/component';
26+
import { Component, ComponentType } from '@firebase/component';
3327
import { name, version } from '../package.json';
34-
import { decodeInstanceIdentifier } from './helpers';
35-
import { AIError } from './api';
36-
import { AIErrorCode } from './types';
37-
import { chromeAdapterFactory } from './methods/chrome-adapter';
3828
import { LanguageModel } from './types/language-model';
29+
import { factory } from './factory-browser';
3930

4031
declare global {
4132
interface Window {
4233
LanguageModel: LanguageModel;
4334
}
4435
}
4536

46-
function factory(
47-
container: ComponentContainer,
48-
{ instanceIdentifier }: InstanceFactoryOptions
49-
): AIService {
50-
if (!instanceIdentifier) {
51-
throw new AIError(
52-
AIErrorCode.ERROR,
53-
'AIService instance identifier is undefined.'
54-
);
55-
}
56-
57-
const backend = decodeInstanceIdentifier(instanceIdentifier);
58-
59-
// getImmediate for FirebaseApp will always succeed
60-
const app = container.getProvider('app').getImmediate();
61-
const auth = container.getProvider('auth-internal');
62-
const appCheckProvider = container.getProvider('app-check-internal');
63-
64-
return new AIService(
65-
app,
66-
backend,
67-
auth,
68-
appCheckProvider,
69-
chromeAdapterFactory
70-
);
71-
}
72-
7337
function registerAI(): void {
7438
_registerComponent(
7539
new Component(AI_TYPE, factory, ComponentType.PUBLIC).setMultipleInstances(

packages/ai/test-utils/get-fake-firebase-services.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
import { Component, ComponentType } from '@firebase/component';
2525
import { FirebaseAppCheckInternal } from '@firebase/app-check-interop-types';
2626
import { AI_TYPE } from '../src/constants';
27-
import { factory } from '../src';
27+
import { factory } from '../src/factory-browser';
2828

2929
const fakeConfig = {
3030
projectId: 'projectId',
@@ -38,7 +38,11 @@ export function getFullApp(fakeAppParams?: {
3838
appId?: string;
3939
apiKey?: string;
4040
}): FirebaseApp {
41-
_registerComponent(new Component(AI_TYPE, factory, ComponentType.PUBLIC));
41+
_registerComponent(
42+
new Component(AI_TYPE, factory, ComponentType.PUBLIC).setMultipleInstances(
43+
true
44+
)
45+
);
4246
_registerComponent(
4347
new Component(
4448
'app-check-internal',

0 commit comments

Comments
 (0)