Skip to content

Commit 0229168

Browse files
committed
WIP
1 parent 32facb6 commit 0229168

File tree

17 files changed

+615
-271
lines changed

17 files changed

+615
-271
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Setup
2+
3+
If the user hasn't already installed the SDK, always run the user's node package manager of choice, and install the package in the directory ../package.json.
4+
For more information on where the library is located, look at the connector.yaml file.
5+
6+
```ts
7+
import { initializeApp } from 'firebase/app';
8+
9+
initializeApp({
10+
// fill in your project config here using the values from your Firebase project or from the `firebase_get_sdk_config` tool from the Firebase MCP server.
11+
});
12+
```
13+
14+
Then, you can run the SDK as needed.
15+
```ts
16+
import { ... } from '@firebasegen/default-connector';
17+
```
18+
19+
20+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Basic Usage
2+
3+
Always prioritize using a supported framework over using the generated SDK
4+
directly. Supported frameworks simplify the developer experience and help ensure
5+
best practices are followed.
6+
7+
8+
9+
10+
11+
## Advanced Usage
12+
If a user is not using a supported framework, they can use the generated SDK directly.
13+
14+
Here's an example of how to use it with the first 5 operations:
15+
16+
```js
17+
import { createMovie, listMovies } from '@firebasegen/default-connector';
18+
19+
20+
// Operation CreateMovie: For variables, look at type CreateMovieVars in ../index.d.ts
21+
const { data } = await CreateMovie(dataConnect, createMovieVars);
22+
23+
// Operation ListMovies:
24+
const { data } = await ListMovies(dataConnect);
25+
26+
27+
```

e2e/data-connect/dataconnect-generated/js/default-connector/esm/index.esm.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,6 @@ export const connectorConfig = {
66
location: 'us-central1'
77
};
88

9-
export const listMoviesRef = (dc) => {
10-
const { dc: dcInstance} = validateArgs(connectorConfig, dc, undefined);
11-
dcInstance._useGeneratedSdk();
12-
return queryRef(dcInstance, 'ListMovies');
13-
}
14-
listMoviesRef.operationName = 'ListMovies';
15-
16-
export function listMovies(dc) {
17-
return executeQuery(listMoviesRef(dc));
18-
}
19-
209
export const createMovieRef = (dcOrVars, vars) => {
2110
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
2211
dcInstance._useGeneratedSdk();
@@ -28,3 +17,14 @@ export function createMovie(dcOrVars, vars) {
2817
return executeMutation(createMovieRef(dcOrVars, vars));
2918
}
3019

20+
export const listMoviesRef = (dc) => {
21+
const { dc: dcInstance} = validateArgs(connectorConfig, dc, undefined);
22+
dcInstance._useGeneratedSdk();
23+
return queryRef(dcInstance, 'ListMovies');
24+
}
25+
listMoviesRef.operationName = 'ListMovies';
26+
27+
export function listMovies(dc) {
28+
return executeQuery(listMoviesRef(dc));
29+
}
30+

e2e/data-connect/dataconnect-generated/js/default-connector/index.cjs.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,6 @@ const connectorConfig = {
77
};
88
exports.connectorConfig = connectorConfig;
99

10-
const listMoviesRef = (dc) => {
11-
const { dc: dcInstance} = validateArgs(connectorConfig, dc, undefined);
12-
dcInstance._useGeneratedSdk();
13-
return queryRef(dcInstance, 'ListMovies');
14-
}
15-
listMoviesRef.operationName = 'ListMovies';
16-
exports.listMoviesRef = listMoviesRef;
17-
18-
exports.listMovies = function listMovies(dc) {
19-
return executeQuery(listMoviesRef(dc));
20-
};
21-
2210
const createMovieRef = (dcOrVars, vars) => {
2311
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
2412
dcInstance._useGeneratedSdk();
@@ -30,3 +18,15 @@ exports.createMovieRef = createMovieRef;
3018
exports.createMovie = function createMovie(dcOrVars, vars) {
3119
return executeMutation(createMovieRef(dcOrVars, vars));
3220
};
21+
22+
const listMoviesRef = (dc) => {
23+
const { dc: dcInstance} = validateArgs(connectorConfig, dc, undefined);
24+
dcInstance._useGeneratedSdk();
25+
return queryRef(dcInstance, 'ListMovies');
26+
}
27+
listMoviesRef.operationName = 'ListMovies';
28+
exports.listMoviesRef = listMoviesRef;
29+
30+
exports.listMovies = function listMovies(dc) {
31+
return executeQuery(listMoviesRef(dc));
32+
};

e2e/data-connect/dataconnect-generated/js/default-connector/index.d.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,6 @@ export interface Movie_Key {
3434
__typename?: 'Movie_Key';
3535
}
3636

37-
interface ListMoviesRef {
38-
/* Allow users to create refs without passing in DataConnect */
39-
(): QueryRef<ListMoviesData, undefined>;
40-
/* Allow users to pass in custom DataConnect instances */
41-
(dc: DataConnect): QueryRef<ListMoviesData, undefined>;
42-
operationName: string;
43-
}
44-
export const listMoviesRef: ListMoviesRef;
45-
46-
export function listMovies(): QueryPromise<ListMoviesData, undefined>;
47-
export function listMovies(dc: DataConnect): QueryPromise<ListMoviesData, undefined>;
48-
4937
interface CreateMovieRef {
5038
/* Allow users to create refs without passing in DataConnect */
5139
(vars: CreateMovieVariables): MutationRef<CreateMovieData, CreateMovieVariables>;
@@ -58,3 +46,15 @@ export const createMovieRef: CreateMovieRef;
5846
export function createMovie(vars: CreateMovieVariables): MutationPromise<CreateMovieData, CreateMovieVariables>;
5947
export function createMovie(dc: DataConnect, vars: CreateMovieVariables): MutationPromise<CreateMovieData, CreateMovieVariables>;
6048

49+
interface ListMoviesRef {
50+
/* Allow users to create refs without passing in DataConnect */
51+
(): QueryRef<ListMoviesData, undefined>;
52+
/* Allow users to pass in custom DataConnect instances */
53+
(dc: DataConnect): QueryRef<ListMoviesData, undefined>;
54+
operationName: string;
55+
}
56+
export const listMoviesRef: ListMoviesRef;
57+
58+
export function listMovies(): QueryPromise<ListMoviesData, undefined>;
59+
export function listMovies(dc: DataConnect): QueryPromise<ListMoviesData, undefined>;
60+

e2e/data-connect/dataconnect/.dataconnect/schema/prelude.gql

Lines changed: 63 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,25 @@ input String_Filter {
205205
`LIKE '%value'`
206206
"""
207207
endsWith: String
208+
"""
209+
Match based on the provided pattern.
210+
"""
211+
pattern: String_Pattern
212+
}
213+
214+
input String_Pattern {
215+
"""
216+
Match using LIKE semantics (https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-LIKE)
217+
"""
218+
like: String @fdc_oneOf
219+
"""
220+
Match against a POSIX regular expression.
221+
"""
222+
regex: String @fdc_oneOf
223+
"""
224+
If true, match patterns case-insensitively.
225+
"""
226+
ignoreCase: Boolean
208227
}
209228

210229
"Query filter criteris for `[String!]` scalar fields."
@@ -515,6 +534,50 @@ input Any_ListFilter {
515534
excludesAll: [Any!]
516535
}
517536

537+
"""
538+
Mark a string field as searchable.
539+
When this directive is added, the field will be indexed for full-text search,
540+
and a <type>_search field will be generated at the query root.
541+
This directive accepts a `language` argument that defaults to `"english"` in
542+
case no value is specified.
543+
See:
544+
- go/fdc-full-text-search
545+
"""
546+
directive @searchable(
547+
"""
548+
Language of the fields that you are searching over can be specified here
549+
(e.g. "french", "spanish", etc.).
550+
Defaults to "english" if not specified.
551+
"""
552+
language: String = "english") on FIELD_DEFINITION
553+
554+
extend type _Metadata {
555+
# During full text search, the relevance of the query term to this row.
556+
# In other cases, this field is not set.
557+
relevance: Float
558+
}
559+
560+
561+
enum Search_QueryFormat @fdc_forbiddenAsFieldType {
562+
"""
563+
Allows search engine style semantics (e.g. quoted strings, AND and OR).
564+
"""
565+
QUERY,
566+
"""
567+
Splits the query into words and does ANDs between them.
568+
"""
569+
PLAIN,
570+
"""
571+
Matches an exact phrase. Requires the words to be in the same order (i.e. "brown
572+
dog" will not match "brown and red dog").
573+
"""
574+
PHRASE,
575+
"""
576+
Create complex queries using the full set of tsquery operators.
577+
"""
578+
ADVANCED,
579+
}
580+
518581
"""
519582
(Internal) A string that uniquely identifies a type, field, and so on.
520583
@@ -2129,69 +2192,3 @@ scalar Vector_Embed_Model
21292192

21302193
# Intentionally left blank.
21312194

2132-
"""
2133-
Mark a string field as searchable.
2134-
When this directive is added, the field will be indexed for full-text search,
2135-
and a <type>_search field will be generated at the query root.
2136-
This directive accepts a `language` argument that defaults to `"english"` in
2137-
case no value is specified.
2138-
See:
2139-
- go/fdc-full-text-search
2140-
"""
2141-
directive @searchable(
2142-
"""
2143-
Language of the fields that you are searching over can be specified here
2144-
(e.g. "french", "spanish", etc.).
2145-
Defaults to "english" if not specified.
2146-
"""
2147-
language: String = "english") on FIELD_DEFINITION
2148-
2149-
extend type _Metadata {
2150-
# During full text search, the relevance of the query term to this row.
2151-
# In other cases, this field is not set.
2152-
relevance: Float
2153-
}
2154-
2155-
2156-
enum Search_QueryFormat @fdc_forbiddenAsFieldType {
2157-
"""
2158-
Allows search engine style semantics (e.g. quoted strings, AND and OR).
2159-
"""
2160-
QUERY,
2161-
"""
2162-
Splits the query into words and does ANDs between them.
2163-
"""
2164-
PLAIN,
2165-
"""
2166-
Matches an exact phrase. Requires the words to be in the same order (i.e. "brown
2167-
dog" will not match "brown and red dog").
2168-
"""
2169-
PHRASE,
2170-
"""
2171-
Create complex queries using the full set of tsquery operators.
2172-
"""
2173-
ADVANCED,
2174-
}
2175-
2176-
input String_Pattern {
2177-
"""
2178-
Match using LIKE semantics (https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-LIKE)
2179-
"""
2180-
like: String @fdc_oneOf
2181-
"""
2182-
Match against a POSIX regular expression.
2183-
"""
2184-
regex: String @fdc_oneOf
2185-
"""
2186-
If true, match patterns case-insensitively.
2187-
"""
2188-
ignoreCase: Boolean
2189-
}
2190-
2191-
extend input String_Filter {
2192-
"""
2193-
Match based on the provided pattern.
2194-
"""
2195-
pattern: String_Pattern
2196-
}
2197-

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export class DataConnect {
194194
this._transportOptions.sslEnabled
195195
);
196196
}
197-
this._queryManager = new QueryManager(this._transport, this.cache);
197+
this._queryManager = new QueryManager(this._transport, this.cache, this);
198198
this._mutationManager = new MutationManager(this._transport);
199199
}
200200

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ export function queryRef<Data, Variables>(
120120
): QueryRef<Data, Variables> {
121121
dcInstance.setInitialized();
122122
if(initialCache !== undefined) {
123-
console.log('updating cache!');
124-
dcInstance._queryManager.updateCache(queryName, variables, initialCache);
123+
// TODO: Check the TTL etc. to see if cache needs to be updated.
124+
const changes = dcInstance._queryManager.updateCache(queryName, variables, initialCache);
125+
dcInstance._queryManager.publishCacheResultsToSubscribers(changes);
125126
}
126-
// dcInstance._queryManager.track(queryName, variables, initialCache);
127127
return {
128128
dataConnect: dcInstance,
129129
refType: QUERY_STR,
Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
1-
// TODO: Consolidate Types
2-
type FDCScalarValue = string | number | boolean | undefined | null | object | FDCScalarValue[];
1+
export type FDCScalarValue = string | number | boolean | undefined | null | object | FDCScalarValue[];
32

43
export class BackingDataObject {
5-
private map = new Map<String, FDCScalarValue>();
6-
constructor(public readonly globalID) {}
7-
updateServerValue(key: string, value: FDCScalarValue) {
4+
toStorableJson(): any {
5+
// TODO: This might not be ok.
6+
return this;
7+
}
8+
static fromStorableJson(json: any): BackingDataObject {
9+
const bdo = new BackingDataObject(json.globalID);
10+
// TODO: check whether the map can be stored in the database as-is
11+
bdo.map = new Map<string, FDCScalarValue>(json.map);
12+
// TODO: check whether the map can be stored in the database as-is
13+
bdo.queriesReferenced = json.queriesReferenced;
14+
return bdo;
15+
}
16+
private map = new Map<string, FDCScalarValue>();
17+
private queriesReferenced = new Set<string>();
18+
// private queryToFields = new Map<string, string[]>();
19+
constructor(public readonly globalID: string) {}
20+
updateServerValue(key: string, value: FDCScalarValue): string[] {
821
this.map.set(key, value);
22+
return Array.from(this.queriesReferenced);
23+
// TODO: Collect queries that need to be updated.
924
}
10-
// TODO(mtewani): Track fields related to a query.
11-
track(key: string, arg1: any) {
12-
throw new Error('Method not implemented.');
25+
track(queryId: string) {
26+
this.queriesReferenced.add(queryId);
27+
// if(!this.queryToFields.has(queryId)) {
28+
// this.queryToFields.set(queryId, []);
29+
// }
30+
// if(!this.queryToFields.get(queryId).includes(key)) {
31+
// this.queryToFields.get(queryId).push(key);
32+
// }
1333
}
1434
}

0 commit comments

Comments
 (0)