-
Notifications
You must be signed in to change notification settings - Fork 934
[FEAT] Restrict Firestore Doc/QuerySnapshot toJSON on client. #9048
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
Merged
DellaBitta
merged 35 commits into
ddb-firestore-result-serialization
from
ddb-no-client-origin-bundles
May 19, 2025
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
fdaa937
Draft of synchronized bundle reader
DellaBitta a888667
Sync bundle reader stands alone
DellaBitta ab90498
docsnapshot.FromJSON prototype
DellaBitta 5df33ec
Lint fixes.
DellaBitta 7c8ef87
Put more logic into bundle_impl.
DellaBitta f0d3304
Templated converter DocSnapshot.fromJSON
DellaBitta f80c49d
Update bundleReader to be multi use utility
DellaBitta be5aee8
Update sync engine use of bundle loader.
DellaBitta ad2f0ac
typo fix
DellaBitta 5ea4ea5
initial QuerySnapshot fromJSON impl
DellaBitta 95b69f6
docgen
DellaBitta 011ac37
Merge branch 'ddb-firestore-result-serialization' into ddb-sync-bundl…
DellaBitta fccd633
QuerySnapshot jsonSchema
DellaBitta 51bc4bc
Use jsonSchemas
DellaBitta 019aa4d
Remove need for toDocumentSnapshotData impl
DellaBitta 52bc217
Revised comments.
DellaBitta 90ade11
Add QuerySnapshot.fromJSON converter variant.
DellaBitta 7ec7a0c
DocumentSet fix.
DellaBitta d97009e
Unit tests.
DellaBitta 8a942f1
Non templated DocumentSnapshot.fromJSON
DellaBitta 78626ef
fromJSON integration tests
DellaBitta 5bf5767
remove fromJSONUsingConverter, user override.
DellaBitta 4f27dc4
DocumentReference fromJSON overload
DellaBitta 2840bb3
Created onSnapshotResume variant.
DellaBitta 96a49f7
Move doc / querysnapshot fromJSON to func impl.
DellaBitta df70734
Implementation. Test fails client side.
DellaBitta 8e1e51a
Remove tests on client side. Lint / format.
DellaBitta 8359b95
converter feedback
DellaBitta 2fb5df3
Test for specific exception text.
DellaBitta 04620bc
format
DellaBitta fbd59e1
Merge branch 'ddb-sync-bundle-parse' into ddb-no-client-origin-bundles
DellaBitta 3c91ad4
format
DellaBitta 1615df9
merge main
DellaBitta 618e3c2
format
DellaBitta 158b491
merged console logging
DellaBitta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/firestore/src/platform/browser/snapshot_to_json.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* @license | ||
* Copyright 2025 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** Return the Platform-specific build JSON bundle implementations. */ | ||
import { Firestore } from '../../api/database'; | ||
import { Query } from '../../core/query'; | ||
import { DocumentData } from '../../lite-api/reference'; | ||
import { Document } from '../../model/document'; | ||
|
||
export function buildDocumentSnapshotJsonBundle( | ||
db: Firestore, | ||
document: Document, | ||
docData: DocumentData, | ||
path: string | ||
): string { | ||
return 'NOT SUPPORTED'; | ||
} | ||
|
||
export function buildQuerySnapshotJsonBundle( | ||
db: Firestore, | ||
query: Query, | ||
bundleName: string, | ||
parent: string, | ||
paths: string[], | ||
docs: Document[], | ||
documentData: DocumentData[] | ||
): string { | ||
return 'NOT SUPPORTED'; | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/firestore/src/platform/browser_lite/snapshot_to_json.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* @license | ||
* Copyright 2025 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
export * from '../browser/snapshot_to_json'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/** | ||
* @license | ||
* Copyright 2025 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** Return the Platform-specific build JSON bundle implementations. */ | ||
import { Firestore } from '../../api/database'; | ||
import { Query } from '../../core/query'; | ||
import { DocumentData } from '../../lite-api/reference'; | ||
import { Document } from '../../model/document'; | ||
import { | ||
BundleBuilder, | ||
DocumentSnapshotBundleData, | ||
QuerySnapshotBundleData | ||
} from '../../util/bundle_builder_impl'; | ||
import { AutoId } from '../../util/misc'; | ||
|
||
export function buildDocumentSnapshotJsonBundle( | ||
db: Firestore, | ||
document: Document, | ||
docData: DocumentData, | ||
path: string | ||
): string { | ||
const builder: BundleBuilder = new BundleBuilder(db, AutoId.newId()); | ||
builder.addBundleDocument( | ||
documentToDocumentSnapshotBundleData(path, docData, document) | ||
); | ||
return builder.build(); | ||
} | ||
|
||
export function buildQuerySnapshotJsonBundle( | ||
db: Firestore, | ||
query: Query, | ||
bundleName: string, | ||
parent: string, | ||
paths: string[], | ||
docs: Document[], | ||
documentData: DocumentData[] | ||
): string { | ||
const docBundleDataArray: DocumentSnapshotBundleData[] = []; | ||
for (let i = 0; i < docs.length; i++) { | ||
docBundleDataArray.push( | ||
documentToDocumentSnapshotBundleData(paths[i], documentData[i], docs[i]) | ||
); | ||
} | ||
const bundleData: QuerySnapshotBundleData = { | ||
name: bundleName, | ||
query, | ||
parent, | ||
docBundleDataArray | ||
}; | ||
const builder: BundleBuilder = new BundleBuilder(db, bundleName); | ||
builder.addBundleQuery(bundleData); | ||
return builder.build(); | ||
} | ||
|
||
// Formats Document data for bundling a DocumentSnapshot. | ||
function documentToDocumentSnapshotBundleData( | ||
path: string, | ||
documentData: DocumentData, | ||
document: Document | ||
): DocumentSnapshotBundleData { | ||
return { | ||
documentData, | ||
documentKey: document.mutableCopy().key, | ||
documentPath: path, | ||
documentExists: true, | ||
createdTime: document.createTime.toTimestamp(), | ||
readTime: document.readTime.toTimestamp(), | ||
versionTime: document.version.toTimestamp() | ||
}; | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/firestore/src/platform/node_lite/snapshot_to_json.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* @license | ||
* Copyright 2025 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
export * from '../node/snapshot_to_json'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* @license | ||
* Copyright 2025 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
export { | ||
buildDocumentSnapshotJsonBundle, | ||
buildQuerySnapshotJsonBundle | ||
} from '../browser/snapshot_to_json'; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The bundle code is now moved into a platform specific file so only for
node
environments. The other platforms produce a bundle string that simply readsNOT SUPPORTED
.