-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Include empty clientCache configs on init #10167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c5c754d
bc44b42
9a6a205
2edc93c
f38bf71
98f13d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,9 @@ import { | |
| DartSDK, | ||
| JavascriptSDK, | ||
| KotlinSDK, | ||
| SwiftSDK, | ||
| } from "../../../dataconnect/types"; | ||
| import * as experiments from "../../../experiments"; | ||
| import { FirebaseError } from "../../../error"; | ||
| import { isArray } from "lodash"; | ||
| import { | ||
|
|
@@ -381,19 +383,23 @@ export function addSdkGenerateToConnectorYaml( | |
|
|
||
| case Platform.WEB: { | ||
| const javascriptSdk: JavascriptSDK = { | ||
| outputDir: path.relative(connectorDir, path.join(appDir, `src/dataconnect-generated`)), | ||
| package: `@dataconnect/generated`, | ||
| packageJsonDir: path.relative(connectorDir, appDir), | ||
| react: false, | ||
| angular: false, | ||
| outputDir: path.relative( | ||
| connectorDir, | ||
| path.join(app.directory, "src/dataconnect-generated"), | ||
| ), | ||
| package: "@dataconnect/generated", | ||
| packageJsonDir: path.relative(connectorDir, app.directory), | ||
| react: app.frameworks?.includes(Framework.REACT) ?? false, | ||
| angular: app.frameworks?.includes(Framework.ANGULAR) ?? false, | ||
| }; | ||
| for (const f of app.frameworks || []) { | ||
| javascriptSdk[f] = true; | ||
| if (experiments.isEnabled("fdcrealtime")) { | ||
| javascriptSdk.clientCache = {}; | ||
| } | ||
| if (!isArray(generate?.javascriptSdk)) { | ||
| generate.javascriptSdk = generate.javascriptSdk ? [generate.javascriptSdk] : []; | ||
| } | ||
| if (!generate.javascriptSdk.some((s) => s.outputDir === javascriptSdk.outputDir)) { | ||
| const existing = generate.javascriptSdk.find((s) => s.outputDir === javascriptSdk.outputDir); | ||
| if (!existing) { | ||
| generate.javascriptSdk.push(javascriptSdk); | ||
| } | ||
| break; | ||
|
|
@@ -403,39 +409,51 @@ export function addSdkGenerateToConnectorYaml( | |
| outputDir: path.relative(connectorDir, path.join(appDir, `lib/dataconnect_generated`)), | ||
| package: "dataconnect_generated/generated.dart", | ||
| }; | ||
| if (experiments.isEnabled("fdcrealtime")) { | ||
| dartSdk.clientCache = {}; | ||
| } | ||
| if (!isArray(generate?.dartSdk)) { | ||
| generate.dartSdk = generate.dartSdk ? [generate.dartSdk] : []; | ||
| } | ||
| if (!generate.dartSdk.some((s) => s.outputDir === dartSdk.outputDir)) { | ||
| const existing = generate.dartSdk.find((s) => s.outputDir === dartSdk.outputDir); | ||
| if (!existing) { | ||
| generate.dartSdk.push(dartSdk); | ||
| } | ||
|
Comment on lines
+412
to
421
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the web platform case, this logic only adds To make if (!isArray(generate?.dartSdk)) {
generate.dartSdk = generate.dartSdk ? [generate.dartSdk] : [];
}
const existing = generate.dartSdk.find((s) => s.outputDir === dartSdk.outputDir);
if (existing) {
if (experiments.isEnabled("fdcrealtime") && !existing.clientCache) {
existing.clientCache = {};
}
} else {
if (experiments.isEnabled("fdcrealtime")) {
dartSdk.clientCache = {};
}
generate.dartSdk.push(dartSdk);
} |
||
| break; | ||
| } | ||
| case Platform.ANDROID: { | ||
| const kotlinSdk: KotlinSDK = { | ||
| outputDir: path.relative(connectorDir, path.join(appDir, `src/main/kotlin`)), | ||
| outputDir: path.relative(connectorDir, path.join(app.directory, "src/main/kotlin")), | ||
| package: `com.google.firebase.dataconnect.generated`, | ||
| }; | ||
| if (experiments.isEnabled("fdcrealtime")) { | ||
| kotlinSdk.clientCache = {}; | ||
| } | ||
| if (!isArray(generate?.kotlinSdk)) { | ||
| generate.kotlinSdk = generate.kotlinSdk ? [generate.kotlinSdk] : []; | ||
| } | ||
| if (!generate.kotlinSdk.some((s) => s.outputDir === kotlinSdk.outputDir)) { | ||
| const existing = generate.kotlinSdk.find((s) => s.outputDir === kotlinSdk.outputDir); | ||
| if (!existing) { | ||
| generate.kotlinSdk.push(kotlinSdk); | ||
| } | ||
|
Comment on lines
+429
to
438
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic only adds To improve idempotency, consider updating existing configurations if they are missing the if (!isArray(generate?.kotlinSdk)) {
generate.kotlinSdk = generate.kotlinSdk ? [generate.kotlinSdk] : [];
}
const existing = generate.kotlinSdk.find((s) => s.outputDir === kotlinSdk.outputDir);
if (existing) {
if (experiments.isEnabled("fdcrealtime") && !existing.clientCache) {
existing.clientCache = {};
}
} else {
if (experiments.isEnabled("fdcrealtime")) {
kotlinSdk.clientCache = {};
}
generate.kotlinSdk.push(kotlinSdk);
} |
||
| break; | ||
| } | ||
| case Platform.IOS: { | ||
| const swiftSdk = { | ||
| const swiftSdk: SwiftSDK = { | ||
| outputDir: path.relative( | ||
| connectorDir, | ||
| path.join(app.directory, `../FirebaseDataConnectGenerated`), | ||
| ), | ||
| package: "DataConnectGenerated", | ||
| }; | ||
| if (experiments.isEnabled("fdcrealtime")) { | ||
| swiftSdk.clientCache = {}; | ||
| } | ||
| if (!isArray(generate?.swiftSdk)) { | ||
| generate.swiftSdk = generate.swiftSdk ? [generate.swiftSdk] : []; | ||
| } | ||
| if (!generate.swiftSdk.some((s) => s.outputDir === swiftSdk.outputDir)) { | ||
| const existing = generate.swiftSdk.find((s) => s.outputDir === swiftSdk.outputDir); | ||
| if (!existing) { | ||
| generate.swiftSdk.push(swiftSdk); | ||
| } | ||
|
Comment on lines
+449
to
458
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic only adds To make the if (!isArray(generate?.swiftSdk)) {
generate.swiftSdk = generate.swiftSdk ? [generate.swiftSdk] : [];
}
const existing = generate.swiftSdk.find((s) => s.outputDir === swiftSdk.outputDir);
if (existing) {
if (experiments.isEnabled("fdcrealtime") && !existing.clientCache) {
existing.clientCache = {};
}
} else {
if (experiments.isEnabled("fdcrealtime")) {
swiftSdk.clientCache = {};
}
generate.swiftSdk.push(swiftSdk);
} |
||
| break; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic only adds
clientCacheto newly created SDK configurations. If a configuration for thisoutputDiralready exists, it is not modified. This meansclientCachewon't be added if it's missing. Similarly, the refactoring to detect React/Angular frameworks is only applied to new configurations.Consider updating the logic to modify existing configurations. This would make
firebase init dataconnect:sdkmore robust and idempotent, ensuring that running it again updates configurations with new defaults or detected frameworks.