This repository was archived by the owner on Feb 20, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 109
refactor: Add a separate function for building the entity proto #1350
Merged
danieljbruce
merged 35 commits into
exclude-from-indexes-cleanup
from
376498249-separate-function-for-building-the-entity-proto
Nov 5, 2024
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
b337a5c
Add some test cases for findLargeProperties_
danieljbruce 59889b5
Add a test for arrays and skip it.
danieljbruce 3ca8d1c
Add a test for the complex case wrapped in an arra
danieljbruce d2c0138
Add a test case for an array without name/value.
danieljbruce 3307e7e
Add another test for name/value pair
danieljbruce 03bd79e
Change the test case involving a name/value pair
danieljbruce 63427a6
Add two simple test cases for excludeFromIndexes
danieljbruce 7c8b7be
Merge branch 'main' of https://github.com/googleapis/nodejs-datastore…
danieljbruce 111a968
Add another unit test for findLargeProperties_
danieljbruce 2587728
Remove if block that stops recursion
danieljbruce bc963cc
Add a test for save with a `name/value` pair
danieljbruce ce23c71
Add some test code that ensures name/value encoded
danieljbruce c96cf51
Add header
danieljbruce 3aef723
Remove only
danieljbruce 83cfff5
Add a test that saves a long string value property
danieljbruce b1a4dcf
Add a unit test checking longString for value
danieljbruce 891bc65
Remove only
danieljbruce 459a3e0
TODO is done
danieljbruce 9bef8e4
Refactor the save function
danieljbruce c8de349
Add TODO
danieljbruce 52034a8
Merge branch '1242-write-tests-for-findLargeProperties-revisit' of ht…
danieljbruce 7bc65dd
Write unit tests for the new excludeFromIndexes fn
danieljbruce feab4b8
Add the header
danieljbruce 35f6831
Refactor the code for building the entity proto
danieljbruce 7eb39e5
Rename it buildEntityProto
danieljbruce e5b4011
The tests need another mock due to the structure
danieljbruce 516a4a7
First two tests for buildEntityProto
danieljbruce 2a64930
Reintroduce extendExcludeFromIndexes.ts tests
danieljbruce b9e2cb1
Adjust the test to match expected proto
danieljbruce ff38fd0
Add another test for an entity in an array
danieljbruce e00ee11
Add headers
danieljbruce 360e382
Add another header
danieljbruce c8c0a2a
Merge branch 'main' of https://github.com/googleapis/nodejs-datastore…
danieljbruce a4c5508
Merge branch 'exclude-from-indexes-cleanup' of
danieljbruce ffa8956
Eliminate space. Simplify diff
danieljbruce 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
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,60 @@ | ||
| // Copyright 2024 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. | ||
|
|
||
| import {entity, Entity, EntityProto, ValueProto} from '../../entity'; | ||
| import {EntityProtoReduceAccumulator, EntityProtoReduceData} from '../../index'; | ||
| import addExcludeFromIndexes = entity.addExcludeFromIndexes; | ||
|
|
||
| /** | ||
| * This function builds the entity proto from the entity object. We cannot | ||
| * rely on entity.entityToEntityProto for this because this function is only | ||
| * designed to be used for non-array entities. | ||
| * | ||
| */ | ||
| export function buildEntityProto(entityObject: Entity) { | ||
|
Contributor
Author
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 is the new function that all the code from src/index.ts is being pulled into |
||
| let entityProto: EntityProto = {}; | ||
| if (Array.isArray(entityObject.data)) { | ||
| // This code builds the right entityProto from the entityObject | ||
| entityProto.properties = entityObject.data.reduce( | ||
| (acc: EntityProtoReduceAccumulator, data: EntityProtoReduceData) => { | ||
| const value = entity.encodeValue(data.value, data.name.toString()); | ||
|
|
||
| if (typeof data.excludeFromIndexes === 'boolean') { | ||
| const excluded = data.excludeFromIndexes; | ||
| let values = value.arrayValue && value.arrayValue.values; | ||
|
|
||
| if (values) { | ||
| values = values.map((x: ValueProto) => { | ||
| x.excludeFromIndexes = excluded; | ||
| return x; | ||
| }); | ||
| } else { | ||
| value.excludeFromIndexes = data.excludeFromIndexes; | ||
| } | ||
| } | ||
|
|
||
| acc[data.name] = value; | ||
|
|
||
| return acc; | ||
| }, | ||
| {} | ||
| ); | ||
| // This code adds excludeFromIndexes in the right places | ||
| addExcludeFromIndexes(entityObject.excludeFromIndexes, entityProto); | ||
| } else { | ||
| // This code builds the right entityProto from the entityObject | ||
| entityProto = entity.entityToEntityProto(entityObject); | ||
| } | ||
| return entityProto; | ||
| } | ||
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.
This entire code block has been pulled into the
buildEntityProtofunction.