Skip to content

Commit 6aae5f5

Browse files
authored
Moved validateArgs to core SDK (#8370)
1 parent f48864c commit 6aae5f5

File tree

11 files changed

+170
-82
lines changed

11 files changed

+170
-82
lines changed

common/api-review/data-connect.api.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,5 @@ export interface TransportOptions {
295295
sslEnabled?: boolean;
296296
}
297297

298-
// @public (undocumented)
299-
export function validateDCOptions(dcOptions: ConnectorConfig): boolean;
300-
301298

302299
```

docs-devsite/_toc.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,57 @@ toc:
173173
path: /docs/reference/js/auth.userinfo.md
174174
- title: UserMetadata
175175
path: /docs/reference/js/auth.usermetadata.md
176+
- title: data-connect
177+
path: /docs/reference/js/data-connect.md
178+
section:
179+
- title: AuthTokenProvider
180+
path: /docs/reference/js/data-connect.authtokenprovider.md
181+
- title: CancellableOperation
182+
path: /docs/reference/js/data-connect.cancellableoperation.md
183+
- title: ConnectorConfig
184+
path: /docs/reference/js/data-connect.connectorconfig.md
185+
- title: DataConnect
186+
path: /docs/reference/js/data-connect.dataconnect.md
187+
- title: DataConnectOptions
188+
path: /docs/reference/js/data-connect.dataconnectoptions.md
189+
- title: DataConnectResult
190+
path: /docs/reference/js/data-connect.dataconnectresult.md
191+
- title: DataConnectSubscription
192+
path: /docs/reference/js/data-connect.dataconnectsubscription.md
193+
- title: DataConnectTransport
194+
path: /docs/reference/js/data-connect.dataconnecttransport.md
195+
- title: FirebaseAuthProvider
196+
path: /docs/reference/js/data-connect.firebaseauthprovider.md
197+
- title: MutationPromise
198+
path: /docs/reference/js/data-connect.mutationpromise.md
199+
- title: MutationRef
200+
path: /docs/reference/js/data-connect.mutationref.md
201+
- title: MutationResponse
202+
path: /docs/reference/js/data-connect.mutationresponse.md
203+
- title: MutationResult
204+
path: /docs/reference/js/data-connect.mutationresult.md
205+
- title: OperationRef
206+
path: /docs/reference/js/data-connect.operationref.md
207+
- title: OpResult
208+
path: /docs/reference/js/data-connect.opresult.md
209+
- title: QueryPromise
210+
path: /docs/reference/js/data-connect.querypromise.md
211+
- title: QueryRef
212+
path: /docs/reference/js/data-connect.queryref.md
213+
- title: QueryResponse
214+
path: /docs/reference/js/data-connect.queryresponse.md
215+
- title: QueryResult
216+
path: /docs/reference/js/data-connect.queryresult.md
217+
- title: RefInfo
218+
path: /docs/reference/js/data-connect.refinfo.md
219+
- title: Sender
220+
path: /docs/reference/js/data-connect.sender.md
221+
- title: SerializedRef
222+
path: /docs/reference/js/data-connect.serializedref.md
223+
- title: SubscriptionOptions
224+
path: /docs/reference/js/data-connect.subscriptionoptions.md
225+
- title: TransportOptions
226+
path: /docs/reference/js/data-connect.transportoptions.md
176227
- title: database
177228
path: /docs/reference/js/database.md
178229
section:

docs-devsite/data-connect.firebaseauthprovider.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ constructor(_appName: string, _options: FirebaseOptions, _authProvider: Provider
4646
| Parameter | Type | Description |
4747
| --- | --- | --- |
4848
| \_appName | string | |
49-
| \_options | [FirebaseOptions](./app.firebaseoptions.md#firebaseoptions_interface) | |
49+
| \_options | FirebaseOptions | |
5050
| \_authProvider | Provider<FirebaseAuthInternalName> | |
5151
5252
## FirebaseAuthProvider.addTokenChangeListener()

docs-devsite/data-connect.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ Converts serialized ref to query ref
408408
<b>Signature:</b>
409409

410410
```typescript
411-
export declare function toQueryRef<Data, Variables>(serializedRef: SerializedRef<Data, Variables>): QueryRef<unknown, Variables>;
411+
export declare function toQueryRef<Data, Variables>(serializedRef: SerializedRef<Data, Variables>): QueryRef<Data, Variables>;
412412
```
413413

414414
#### Parameters
@@ -419,7 +419,7 @@ export declare function toQueryRef<Data, Variables>(serializedRef: SerializedRef
419419

420420
<b>Returns:</b>
421421

422-
[QueryRef](./data-connect.queryref.md#queryref_interface)<!-- -->&lt;unknown, Variables&gt;
422+
[QueryRef](./data-connect.queryref.md#queryref_interface)<!-- -->&lt;Data, Variables&gt;
423423

424424
`QueryRef`
425425

packages/data-connect/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
## UNRELEASED
33
* Updated reporting to use @firebase/data-connect instead of @firebase/connect
44
* Added functionality to retry queries and mutations if the server responds with UNAUTHENTICATED.
5+
* Moved `validateArgs` to core SDK
56
* Updated errors to only show relevant details to the user.

packages/data-connect/notes.md

Lines changed: 0 additions & 74 deletions
This file was deleted.

packages/data-connect/src/api/DataConnect.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ export function getDataConnect(
234234
});
235235
}
236236

237+
/**
238+
*
239+
* @param dcOptions
240+
* @returns {void}
241+
* @internal
242+
*/
237243
export function validateDCOptions(dcOptions: ConnectorConfig): boolean {
238244
const fields = ['connector', 'location', 'service'];
239245
if (!dcOptions) {

packages/data-connect/src/api/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ export * from './Reference';
2121
export * from './Mutation';
2222
export * from './query';
2323
export { setLogLevel } from '../logger';
24+
export { validateArgs } from '../util/validateArgs';
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* @license
3+
* Copyright 2024 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import {
19+
ConnectorConfig,
20+
DataConnect,
21+
getDataConnect
22+
} from '../api/DataConnect';
23+
import { Code, DataConnectError } from '../core/error';
24+
interface ParsedArgs<Variables> {
25+
dc: DataConnect;
26+
vars: Variables;
27+
}
28+
29+
/**
30+
* The generated SDK will allow the user to pass in either the variable or the data connect instance with the variable,
31+
* and this function validates the variables and returns back the DataConnect instance and variables based on the arguments passed in.
32+
* @param connectorConfig
33+
* @param dcOrVars
34+
* @param vars
35+
* @param validateVars
36+
* @returns {DataConnect} and {Variables} instance
37+
* @internal
38+
*/
39+
export function validateArgs<Variables extends object>(
40+
connectorConfig: ConnectorConfig,
41+
dcOrVars?: DataConnect | Variables,
42+
vars?: Variables,
43+
validateVars?: boolean
44+
): ParsedArgs<Variables> {
45+
let dcInstance: DataConnect;
46+
let realVars: Variables;
47+
if (dcOrVars && 'enableEmulator' in dcOrVars) {
48+
dcInstance = dcOrVars as DataConnect;
49+
realVars = vars;
50+
} else {
51+
dcInstance = getDataConnect(connectorConfig);
52+
realVars = dcOrVars as Variables;
53+
}
54+
if (!dcInstance || (!realVars && validateVars)) {
55+
throw new DataConnectError(Code.INVALID_ARGUMENT, 'Variables required.');
56+
}
57+
return { dc: dcInstance, vars: realVars };
58+
}

packages/data-connect/test/queries.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ describe('DataConnect Tests', async () => {
165165
location: 'wrong',
166166
service: 'wrong'
167167
});
168-
connectDataConnectEmulator(fakeInstance, 'localhost', Number(0));
169-
const taskListQuery = queryRef<TaskListResponse>(dc, 'listPosts');
168+
connectDataConnectEmulator(fakeInstance, 'localhost', 3512);
169+
const taskListQuery = queryRef<TaskListResponse>(fakeInstance, 'listPosts');
170170
await expect(executeQuery(taskListQuery)).to.eventually.be.rejectedWith(
171171
'ECONNREFUSED'
172172
);

0 commit comments

Comments
 (0)