Skip to content

Commit 292d982

Browse files
committed
Included a basic gen sdk test
1 parent 933ba9d commit 292d982

File tree

10 files changed

+830
-2
lines changed

10 files changed

+830
-2
lines changed

packages/data-connect/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
"test:node": "TS_NODE_FILES=true TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --file src/index.node.ts --config ../../config/mocharc.node.js",
3939
"test:unit": "TS_NODE_FILES=true TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/unit/**/*.test.ts' --file src/index.node.ts --config ../../config/mocharc.node.js",
4040
"test:emulator": "ts-node --compiler-options='{\"module\":\"commonjs\"}' ../../scripts/emulator-testing/dataconnect-test-runner.ts",
41+
"test:emulator:gensdk": "FIREBASE_GEN_SDK=true ts-node --compiler-options='{\"module\":\"commonjs\"}' ../../scripts/emulator-testing/dataconnect-test-runner.ts",
42+
"test:gensdk": "TS_NODE_FILES=true TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/gensdk/*.test.ts' --file src/index.node.ts --config ../../config/mocharc.node.js",
4143
"api-report": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' ts-node ../../repo-scripts/prune-dts/extract-public-api.ts --package data-connect --packageRoot . --typescriptDts ./dist/src/index.d.ts --rollupDts ./dist/private.d.ts --untrimmedRollupDts ./dist/internal.d.ts --publicDts ./dist/public.d.ts && yarn api-report:api-json",
4244
"api-report:api-json": "rm -rf temp && api-extractor run --local --verbose",
4345
"doc": "api-documenter markdown --input temp --output docs",

packages/data-connect/test/dataconnect/connector/connector.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ connectorId: "tests"
22
authMode: "PUBLIC"
33
generate:
44
javascriptSdk:
5-
outputDir: "./gen/web"
5+
outputDir: "../../gen/web"
66
package: "@test-app/tests"

packages/data-connect/test/gen/web/README.md

Lines changed: 448 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
* @license
3+
* Copyright 2025 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+
queryRef,
20+
executeQuery,
21+
mutationRef,
22+
executeMutation,
23+
validateArgs
24+
} from 'firebase/data-connect';
25+
26+
export const connectorConfig = {
27+
connector: 'tests',
28+
service: 'fdc-service',
29+
location: 'us-west2'
30+
};
31+
32+
export function removePostRef(dcOrVars, vars) {
33+
const { dc: dcInstance, vars: inputVars } = validateArgs(
34+
connectorConfig,
35+
dcOrVars,
36+
vars,
37+
true
38+
);
39+
dcInstance._useGeneratedSdk();
40+
return mutationRef(dcInstance, 'RemovePost', inputVars);
41+
}
42+
43+
export function removePost(dcOrVars, vars) {
44+
return executeMutation(removePostRef(dcOrVars, vars));
45+
}
46+
47+
export function addPostRef(dcOrVars, vars) {
48+
const { dc: dcInstance, vars: inputVars } = validateArgs(
49+
connectorConfig,
50+
dcOrVars,
51+
vars,
52+
true
53+
);
54+
dcInstance._useGeneratedSdk();
55+
return mutationRef(dcInstance, 'AddPost', inputVars);
56+
}
57+
58+
export function addPost(dcOrVars, vars) {
59+
return executeMutation(addPostRef(dcOrVars, vars));
60+
}
61+
62+
export function listPostsRef(dcOrVars, vars) {
63+
const { dc: dcInstance, vars: inputVars } = validateArgs(
64+
connectorConfig,
65+
dcOrVars,
66+
vars,
67+
true
68+
);
69+
dcInstance._useGeneratedSdk();
70+
return queryRef(dcInstance, 'ListPosts', inputVars);
71+
}
72+
73+
export function listPosts(dcOrVars, vars) {
74+
return executeQuery(listPostsRef(dcOrVars, vars));
75+
}
76+
77+
export function unauthorizedQueryRef(dc) {
78+
const { dc: dcInstance } = validateArgs(connectorConfig, dc, undefined);
79+
dcInstance._useGeneratedSdk();
80+
return queryRef(dcInstance, 'UnauthorizedQuery');
81+
}
82+
83+
export function unauthorizedQuery(dc) {
84+
return executeQuery(unauthorizedQueryRef(dc));
85+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"type":"module"}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/**
2+
* @license
3+
* Copyright 2025 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+
const {
19+
queryRef,
20+
executeQuery,
21+
mutationRef,
22+
executeMutation,
23+
validateArgs
24+
} = require('firebase/data-connect');
25+
26+
const connectorConfig = {
27+
connector: 'tests',
28+
service: 'fdc-service',
29+
location: 'us-west2'
30+
};
31+
exports.connectorConfig = connectorConfig;
32+
33+
function removePostRef(dcOrVars, vars) {
34+
const { dc: dcInstance, vars: inputVars } = validateArgs(
35+
connectorConfig,
36+
dcOrVars,
37+
vars,
38+
true
39+
);
40+
dcInstance._useGeneratedSdk();
41+
return mutationRef(dcInstance, 'RemovePost', inputVars);
42+
}
43+
exports.removePostRef = removePostRef;
44+
45+
exports.removePost = function removePost(dcOrVars, vars) {
46+
return executeMutation(removePostRef(dcOrVars, vars));
47+
};
48+
49+
function addPostRef(dcOrVars, vars) {
50+
const { dc: dcInstance, vars: inputVars } = validateArgs(
51+
connectorConfig,
52+
dcOrVars,
53+
vars,
54+
true
55+
);
56+
dcInstance._useGeneratedSdk();
57+
return mutationRef(dcInstance, 'AddPost', inputVars);
58+
}
59+
exports.addPostRef = addPostRef;
60+
61+
exports.addPost = function addPost(dcOrVars, vars) {
62+
return executeMutation(addPostRef(dcOrVars, vars));
63+
};
64+
65+
function listPostsRef(dcOrVars, vars) {
66+
const { dc: dcInstance, vars: inputVars } = validateArgs(
67+
connectorConfig,
68+
dcOrVars,
69+
vars,
70+
true
71+
);
72+
dcInstance._useGeneratedSdk();
73+
return queryRef(dcInstance, 'ListPosts', inputVars);
74+
}
75+
exports.listPostsRef = listPostsRef;
76+
77+
exports.listPosts = function listPosts(dcOrVars, vars) {
78+
return executeQuery(listPostsRef(dcOrVars, vars));
79+
};
80+
81+
function unauthorizedQueryRef(dc) {
82+
const { dc: dcInstance } = validateArgs(connectorConfig, dc, undefined);
83+
dcInstance._useGeneratedSdk();
84+
return queryRef(dcInstance, 'UnauthorizedQuery');
85+
}
86+
exports.unauthorizedQueryRef = unauthorizedQueryRef;
87+
88+
exports.unauthorizedQuery = function unauthorizedQuery(dc) {
89+
return executeQuery(unauthorizedQueryRef(dc));
90+
};
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/**
2+
* @license
3+
* Copyright 2025 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+
QueryRef,
22+
QueryPromise,
23+
MutationRef,
24+
MutationPromise
25+
} from 'firebase/data-connect';
26+
27+
export const connectorConfig: ConnectorConfig;
28+
29+
export type TimestampString = string;
30+
export type UUIDString = string;
31+
export type Int64String = string;
32+
export type DateString = string;
33+
34+
export interface AddPostData {
35+
post_insert: Post_Key;
36+
}
37+
38+
export interface AddPostVariables {
39+
id: UUIDString;
40+
description: string;
41+
testId: string;
42+
}
43+
44+
export interface ListPostsData {
45+
posts: ({
46+
id: UUIDString;
47+
description: string;
48+
} & Post_Key)[];
49+
}
50+
51+
export interface ListPostsVariables {
52+
testId: string;
53+
}
54+
55+
export interface Post_Key {
56+
id: UUIDString;
57+
__typename?: 'Post_Key';
58+
}
59+
60+
export interface RemovePostData {
61+
post_delete?: Post_Key | null;
62+
}
63+
64+
export interface RemovePostVariables {
65+
id: UUIDString;
66+
}
67+
68+
export interface UnauthorizedQueryData {
69+
posts: ({
70+
id: UUIDString;
71+
description: string;
72+
} & Post_Key)[];
73+
}
74+
75+
/* Allow users to create refs without passing in DataConnect */
76+
export function removePostRef(
77+
vars: RemovePostVariables
78+
): MutationRef<RemovePostData, RemovePostVariables>;
79+
/* Allow users to pass in custom DataConnect instances */
80+
export function removePostRef(
81+
dc: DataConnec,
82+
vars: RemovePostVariables
83+
): MutationRef<RemovePostData, RemovePostVariables>;
84+
85+
export function removePost(
86+
vars: RemovePostVariables
87+
): MutationPromise<RemovePostData, RemovePostVariables>;
88+
export function removePost(
89+
dc: DataConnect,
90+
vars: RemovePostVariables
91+
): MutationPromise<RemovePostData, RemovePostVariables>;
92+
93+
/* Allow users to create refs without passing in DataConnect */
94+
export function addPostRef(
95+
vars: AddPostVariables
96+
): MutationRef<AddPostData, AddPostVariables>;
97+
/* Allow users to pass in custom DataConnect instances */
98+
export function addPostRef(
99+
dc: DataConnec,
100+
vars: AddPostVariables
101+
): MutationRef<AddPostData, AddPostVariables>;
102+
103+
export function addPost(
104+
vars: AddPostVariables
105+
): MutationPromise<AddPostData, AddPostVariables>;
106+
export function addPost(
107+
dc: DataConnect,
108+
vars: AddPostVariables
109+
): MutationPromise<AddPostData, AddPostVariables>;
110+
111+
/* Allow users to create refs without passing in DataConnect */
112+
export function listPostsRef(
113+
vars: ListPostsVariables
114+
): QueryRef<ListPostsData, ListPostsVariables>;
115+
/* Allow users to pass in custom DataConnect instances */
116+
export function listPostsRef(
117+
dc: DataConnec,
118+
vars: ListPostsVariables
119+
): QueryRef<ListPostsData, ListPostsVariables>;
120+
121+
export function listPosts(
122+
vars: ListPostsVariables
123+
): QueryPromise<ListPostsData, ListPostsVariables>;
124+
export function listPosts(
125+
dc: DataConnect,
126+
vars: ListPostsVariables
127+
): QueryPromise<ListPostsData, ListPostsVariables>;
128+
129+
/* Allow users to create refs without passing in DataConnect */
130+
export function unauthorizedQueryRef(): QueryRef<
131+
UnauthorizedQueryData,
132+
undefined
133+
>;
134+
/* Allow users to pass in custom DataConnect instances */
135+
export function unauthorizedQueryRef(
136+
dc: DataConnect
137+
): QueryRef<UnauthorizedQueryData, undefined>;
138+
139+
export function unauthorizedQuery(): QueryPromise<
140+
UnauthorizedQueryData,
141+
undefined
142+
>;
143+
export function unauthorizedQuery(
144+
dc: DataConnect
145+
): QueryPromise<UnauthorizedQueryData, undefined>;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "@test-app/tests",
3+
"version": "1.0.0",
4+
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
5+
"description": "Generated SDK For tests",
6+
"license": "Apache-2.0",
7+
"engines": {
8+
"node": " >=18.0"
9+
},
10+
"typings": "index.d.ts",
11+
"module": "esm/index.esm.js",
12+
"main": "index.cjs.js",
13+
"browser": "esm/index.esm.js",
14+
"exports": {
15+
".": {
16+
"types": "./index.d.ts",
17+
"require": "./index.cjs.js",
18+
"default": "./esm/index.esm.js"
19+
},
20+
"./package.json": "./package.json"
21+
},
22+
"peerDependencies": {
23+
"firebase": "^10.14.0 || ^11.3.0"
24+
}
25+
}

0 commit comments

Comments
 (0)