diff --git a/Core/tests/Snippet/ServiceBuilderTest.php b/Core/tests/Snippet/ServiceBuilderTest.php index 752c5ea54b47..53c69c38d317 100644 --- a/Core/tests/Snippet/ServiceBuilderTest.php +++ b/Core/tests/Snippet/ServiceBuilderTest.php @@ -51,7 +51,6 @@ public function serviceBuilderMethods() { return [ ['bigQuery', BigQueryClient::class, 'bigQuery'], - ['datastore', DatastoreClient::class, 'datastore'], ['firestore', FirestoreClient::class, 'firestore', true], ['logging', LoggingClient::class, 'logging'], ['language', LanguageClient::class, 'language'], diff --git a/Core/tests/Unit/ServiceBuilderTest.php b/Core/tests/Unit/ServiceBuilderTest.php index 5bd0656b2cb7..e6e17b383e82 100644 --- a/Core/tests/Unit/ServiceBuilderTest.php +++ b/Core/tests/Unit/ServiceBuilderTest.php @@ -20,7 +20,6 @@ use Google\Cloud\Core\ServiceBuilder; use Google\Cloud\Core\Testing\CheckForClassTrait; use Google\Cloud\Core\Testing\GrpcTestTrait; -use Google\Cloud\Datastore\DatastoreClient; use Google\Cloud\Firestore\FirestoreClient; use Google\Cloud\Language\LanguageClient; use Google\Cloud\Logging\LoggingClient; @@ -147,10 +146,7 @@ public function serviceProvider() [ 'bigQuery', BigQueryClient::class - ], [ - 'datastore', - DatastoreClient::class - ], [ + ],[ 'firestore', FirestoreClient::class, [], diff --git a/Datastore/composer.json b/Datastore/composer.json index 3ae13ef7ab15..bfec5d80f871 100644 --- a/Datastore/composer.json +++ b/Datastore/composer.json @@ -14,7 +14,8 @@ "squizlabs/php_codesniffer": "2.*", "phpdocumentor/reflection": "^5.3.3||^6.0", "phpdocumentor/reflection-docblock": "^5.3", - "erusev/parsedown": "^1.6" + "erusev/parsedown": "^1.6", + "dg/bypass-finals": "^1.9" }, "extra": { "component": { diff --git a/Datastore/owlbot.py b/Datastore/owlbot.py index 6d38be2ead7b..0328c9ccc3f3 100644 --- a/Datastore/owlbot.py +++ b/Datastore/owlbot.py @@ -1,4 +1,4 @@ -# Copyright 2018 Google LLC +# 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. @@ -30,65 +30,27 @@ # Added so that we can pass copy_excludes in the owlbot_main() call _tracked_paths.add(src) -php.owlbot_main( - src=src, - dest=dest, - copy_excludes=[ - src / "*/proto/src/Google/Cloud/Datastore/V1/TransactionOptions/ReadOnly.php" - ] -) +php.owlbot_main(src=src, dest=dest) - -# Fix class references in gapic samples -for version in ['V1']: - pathExpr = 'src/' + version + '/Gapic/DatastoreGapicClient.php' - - types = { - '= new DatastoreClient': r'= new Google\\Cloud\\Datastore\\' + version + r'\\DatastoreClient', - '= Mode::': r'= Google\\Cloud\\Datastore\\' + version + r'\\CommitRequest\\Mode::', - 'new PartitionId': r'new Google\\Cloud\\Datastore\\' + version + r'\\PartitionId', - } - - for search, replace in types.items(): - s.replace( - pathExpr, - search, - replace) - -# remove ReadOnly class_alias code +# remove class_alias code s.replace( - "src/V*/**/PBReadOnly.php", - r"^// Adding a class alias for backwards compatibility with the \"readonly\" keyword.$" + "src/V*/**/*.php", + r"^// Adding a class alias for backwards compatibility with the previous class name.$" + "\n" - + r"^class_alias\(PBReadOnly::class, __NAMESPACE__ . '\\ReadOnly'\);$" + + r"^class_alias\(.*\);$" + "\n", '') -### [START] protoc backwards compatibility fixes - -# roll back to private properties. -s.replace( - "src/**/V*/**/*.php", - r"Generated from protobuf field ([^\n]{0,})\n\s{5}\*/\n\s{4}protected \$", - r"""Generated from protobuf field \1 - */ - private $""") - -# Replace "Unwrapped" with "Value" for method names. -s.replace( - "src/**/V*/**/*.php", - r"public function ([s|g]\w{3,})Unwrapped", - r"public function \1Value" -) - -### [END] protoc backwards compatibility fixes - -# fix relative cloud.google.com links -s.replace( - "src/**/V*/**/*.php", - r"(.{0,})\]\((/.{0,})\)", - r"\1](https://cloud.google.com\2)" -) - -# Address breaking changes -subprocess.run('git show 8ada2c97c72ffabf5c3031021378874f8caa8804 | git apply', shell=True) +# format generated clients +subprocess.run([ + 'npm', + 'exec', + '--yes', + '--package=@prettier/plugin-php@^0.19', + '--', + 'prettier', + '**/Client/*', + '--write', + '--parser=php', + '--single-quote', + '--print-width=120']) diff --git a/Datastore/phpunit.xml.dist b/Datastore/phpunit.xml.dist index 29f7a123ce1a..1577cec6ccda 100644 --- a/Datastore/phpunit.xml.dist +++ b/Datastore/phpunit.xml.dist @@ -1,5 +1,5 @@ - + src diff --git a/Datastore/src/Connection/ConnectionInterface.php b/Datastore/src/Connection/ConnectionInterface.php deleted file mode 100644 index 6a1a9ebbd3fa..000000000000 --- a/Datastore/src/Connection/ConnectionInterface.php +++ /dev/null @@ -1,62 +0,0 @@ - null - ]; - - //@codeCoverageIgnoreStart - $this->serializer = new Serializer([], [ - 'google.protobuf.Value' => function ($v) { - return $this->flattenValue($v); - }, - 'google.protobuf.Timestamp' => function ($v) { - return $this->formatTimestampFromApi($v); - }, - 'google.protobuf.Duration' => function ($v) { - return $this->formatDurationFromApi($v); - } - ], [], [ - 'google.protobuf.Timestamp' => function ($v) { - if (is_string($v)) { - $dt = new \DateTime($v); - return ['seconds' => $dt->format('U')]; - } - return $v; - } - ]); - //@codeCoverageIgnoreEnd - - $config['serializer'] = $this->serializer; - $this->setRequestWrapper(new GrpcRequestWrapper($config)); - $grpcConfig = $this->getGaxConfig( - ManualDatastoreClient::VERSION, - isset($config['authHttpHandler']) - ? $config['authHttpHandler'] - : null - ); - - if (isset($config['apiEndpoint'])) { - $grpcConfig['apiEndpoint'] = $config['apiEndpoint']; - } - - if ((bool) $config['emulatorHost']) { - $grpcConfig = array_merge( - $grpcConfig, - $this->emulatorGapicConfig($config['emulatorHost']) - ); - } - - $this->datastoreClient = $config['gapicDatastoreClient'] - ?? $this->constructGapic(DatastoreClient::class, $grpcConfig); - } - - /** - * @param array $args - */ - public function allocateIds(array $args) - { - $keys = $this->pluck('keys', $args); - - return $this->send([$this->datastoreClient, 'allocateIds'], [ - $this->pluck('projectId', $args), - $this->keysList($keys), - $args - ]); - } - - /** - * @param array $args - */ - public function beginTransaction(array $args) - { - if (isset($args['transactionOptions'])) { - array_walk($args['transactionOptions'], function (&$item) { - if ($item instanceof \stdClass) { - $item = []; - } - }); - - $args['transactionOptions'] = $this->serializer->decodeMessage( - new TransactionOptions(), - $args['transactionOptions'] - ); - } - - return $this->send([$this->datastoreClient, 'beginTransaction'], [ - $this->pluck('projectId', $args), - $args - ]); - } - - /** - * @param array $args - */ - public function commit(array $args) - { - $mode = $this->pluck('mode', $args) === 'TRANSACTIONAL' - ? Mode::TRANSACTIONAL - : Mode::NON_TRANSACTIONAL; - - $mutations = $this->pluck('mutations', $args); - foreach ($mutations as &$mutation) { - $mutationType = array_keys($mutation)[0]; - $data = $mutation[$mutationType]; - if (isset($data['properties'])) { - foreach ($data['properties'] as &$property) { - list($type, $val) = $this->toGrpcValue($property); - - $property[$type] = $val; - } - } - - $mutation[$mutationType] = $data; - - $mutation = $this->serializer->decodeMessage(new Mutation(), $mutation); - } - - return $this->send([$this->datastoreClient, 'commit'], [ - $this->pluck('projectId', $args), - $mode, - $mutations, - $args - ]); - } - - /** - * @param array $args - */ - public function lookup(array $args) - { - $keys = $this->pluck('keys', $args); - - if (isset($args['readOptions'])) { - $args['readOptions'] = $this->readOptions($args['readOptions']); - } - - return $this->send([$this->datastoreClient, 'lookup'], [ - $this->pluck('projectId', $args), - $this->keysList($keys), - $args - ]); - } - - /** - * @param array $args - */ - public function rollback(array $args) - { - return $this->send([$this->datastoreClient, 'rollback'], [ - $this->pluck('projectId', $args), - $this->pluck('transaction', $args), - $args - ]); - } - - /** - * @param array $args - */ - public function runAggregationQuery(array $args) - { - $partitionId = $this->serializer->decodeMessage( - new PartitionId(), - $this->pluck('partitionId', $args) - ); - $args['partitionId'] = $partitionId; - - if (isset($args['readOptions'])) { - $args['readOptions'] = $this->readOptions($args['readOptions']); - } - - if (isset($args['aggregationQuery'])) { - if (isset($args['aggregationQuery']['nestedQuery'])) { - $args['aggregationQuery']['nestedQuery'] = $this->parseQuery( - $args['aggregationQuery']['nestedQuery'] - ); - } - - $args['aggregationQuery'] = $this->serializer->decodeMessage( - new AggregationQuery(), - $args['aggregationQuery'] - ); - } - - if (isset($args['gqlQuery'])) { - $args['gqlQuery'] = $this->parseGqlQuery($args['gqlQuery']); - } - - return $this->send([$this->datastoreClient, 'runAggregationQuery'], [ - $this->pluck('projectId', $args), - $args - ]); - } - - /** - * @param array $args - */ - public function runQuery(array $args) - { - $partitionId = $this->serializer->decodeMessage( - new PartitionId(), - $this->pluck('partitionId', $args) - ); - - if (isset($args['readOptions'])) { - $args['readOptions'] = $this->readOptions($args['readOptions']); - } - - if (isset($args['query'])) { - $args['query'] = $this->parseQuery($args['query']); - } - - if (isset($args['gqlQuery'])) { - $args['gqlQuery'] = $this->parseGqlQuery($args['gqlQuery']); - } - - return $this->send([$this->datastoreClient, 'runQuery'], [ - $this->pluck('projectId', $args), - $partitionId, - $args - ]); - } - - /** - * Convert array representation of Query to {@see Google\Cloud\Datastore\V1\Query}. - * - * @param array $query - * @return Query - */ - private function parseQuery(array $query) - { - if (isset($query['order'])) { - foreach ($query['order'] as &$order) { - $order['direction'] = $order['direction'] === 'ASCENDING' - ? Direction::ASCENDING - : Direction::DESCENDING; - } - } - - if (isset($query['filter'])) { - $query['filter'] = $this->convertFilterProps($query['filter']); - } - - if (isset($query['limit']) && !is_array($query['limit'])) { - $query['limit'] = [ - 'value' => $query['limit'] - ]; - } - - $parsedQuery = $this->serializer->decodeMessage( - new Query(), - $query - ); - return $parsedQuery; - } - - /** - * Convert array representation of GqlQuery to {@see Google\Cloud\Datastore\V1\GqlQuery}. - * - * @param array $gqlQuery - * @return GqlQuery - */ - private function parseGqlQuery(array $gqlQuery) - { - if (isset($gqlQuery['namedBindings'])) { - foreach ($gqlQuery['namedBindings'] as $name => &$binding) { - if (!isset($binding['value'])) { - continue; - } - - $binding = $this->prepareQueryBinding($binding); - } - } - - if (isset($gqlQuery['positionalBindings'])) { - foreach ($gqlQuery['positionalBindings'] as &$binding) { - if (!isset($binding['value'])) { - continue; - } - - $binding = $this->prepareQueryBinding($binding); - } - } - - $parsedGqlQuery = $this->serializer->decodeMessage( - new GqlQuery(), - $gqlQuery - ); - - return $parsedGqlQuery; - } - - /** - * Convert a list of keys to a list of {@see Google\Cloud\Datastore\V1\Key}. - * - * @param array[] $keys - * @return Key[] - */ - private function keysList(array $keys) - { - $out = []; - foreach ($keys as $key) { - $local = []; - - if (isset($key['partitionId'])) { - $p = $this->arrayFilterRemoveNull([ - 'project_id' => isset($key['partitionId']['projectId']) - ? $key['partitionId']['projectId'] - : null, - 'namespace_id' => isset($key['partitionId']['namespaceId']) - ? $key['partitionId']['namespaceId'] - : null, - 'database_id' => isset($key['partitionId']['databaseId']) - ? $key['partitionId']['databaseId'] - : null, - ]); - - $local['partition_id'] = new PartitionId($p); - } - - $local['path'] = []; - if (isset($key['path'])) { - foreach ($key['path'] as $element) { - $local['path'][] = new PathElement($element); - } - } - - $out[] = new Key($local); - } - - return $out; - } - - /** - * Convert a query binding to an API-compatible value. - * - * @param array $binding The input binding data - * @return array - */ - private function prepareQueryBinding(array $binding) - { - $value = $binding['value']; - - list($type, $val) = $this->toGrpcValue($value); - - $binding['value'][$type] = $val; - - return $binding; - } - - /** - * Convert read options into an API-compatible value. - * - * @param array $readOptions The input readOptions data. - * @return array - */ - private function readOptions(array $readOptions) - { - if (isset($readOptions['readConsistency'])) { - switch ($readOptions['readConsistency']) { - case 'STRONG': - $readOptions['readConsistency'] = ReadConsistency::STRONG; - break; - - case 'EVENTUAL': - $readOptions['readConsistency'] = ReadConsistency::EVENTUAL; - break; - - default: - //@codeCoverageIgnoreStart - throw new \InvalidArgumentException('Invalid value for Read Consistency.'); - break; - //@codeCoverageIgnoreEnd - } - } - - return $this->serializer->decodeMessage( - new ReadOptions(), - $readOptions - ); - } - - /** - * Convert Query filters to an API-compatible value. - * - * @param array $filter The input filter data - * @return array - */ - private function convertFilterProps(array $filter) - { - if (isset($filter['propertyFilter'])) { - $operator = $filter['propertyFilter']['op']; - - try { - if (is_int($operator)) { - // verify that the operator, given as enum value, exists. - PropertyFilterOperator::name($operator); - } else { - // convert the operator, given as a string, to a grpc value. - $operator = PropertyFilterOperator::value($operator); - } - } catch (\UnexpectedValueException $e) { - throw new \InvalidArgumentException($e->getMessage()); - } - - $filter['propertyFilter']['op'] = $operator; - } - - if (isset($filter['compositeFilter'])) { - if ($filter['compositeFilter']['op'] == 'AND') { - $filter['compositeFilter']['op'] = CompositeFilterOperator::PBAND; - } elseif ($filter['compositeFilter']['op'] == 'OR') { - $filter['compositeFilter']['op'] = CompositeFilterOperator::PBOR; - } else { - $filter['compositeFilter']['op'] = CompositeFilterOperator::OPERATOR_UNSPECIFIED; - } - foreach ($filter['compositeFilter']['filters'] as &$nested) { - $nested = $this->convertFilterProps($nested); - } - } - - return $filter; - } - - /** - * Convert a property value to a gRPC value. - * - * @param array $property The input property. - * @return array - */ - private function toGrpcValue(array $property) - { - $type = array_keys($property)[0]; - $val = $property[$type]; - if ($val === null) { - $val = NullValue::NULL_VALUE; - } - - if ($type === 'timestampValue') { - $val = $this->formatTimestampForApi($val); - } - - if ($type === 'geoPointValue') { - $val = $this->arrayFilterRemoveNull($val); - } - - return [$type, $val]; - } -} diff --git a/Datastore/src/Connection/Rest.php b/Datastore/src/Connection/Rest.php deleted file mode 100644 index f4c60cfd90be..000000000000 --- a/Datastore/src/Connection/Rest.php +++ /dev/null @@ -1,175 +0,0 @@ - null]; - - $baseUri = $this->getApiEndpoint(self::BASE_URI, $config); - if ((bool) $config['emulatorHost']) { - // @codeCoverageIgnoreStart - $baseUri = $this->emulatorBaseUri($config['emulatorHost']); - $config['shouldSignRequest'] = false; - // @codeCoverageIgnoreEnd - } - - $config += [ - 'serviceDefinitionPath' => __DIR__ . '/ServiceDefinition/datastore-v1.json', - 'componentVersion' => DatastoreClient::VERSION - ]; - - $this->setRequestWrapper(new RequestWrapper($config)); - $this->setRequestBuilder(new RequestBuilder( - $config['serviceDefinitionPath'], - $baseUri - )); - } - - /** - * @param array $args - * @return array - */ - public function allocateIds(array $args) - { - return $this->sendWithHeaders('projects', 'allocateIds', $args); - } - - /** - * @param array $args - * @return array - */ - public function beginTransaction(array $args) - { - return $this->sendWithHeaders('projects', 'beginTransaction', $args); - } - - /** - * @param array $args - * @return array - */ - public function commit(array $args) - { - return $this->sendWithHeaders('projects', 'commit', $args); - } - - /** - * @param array $args - * @return array - */ - public function lookup(array $args) - { - return $this->sendWithHeaders('projects', 'lookup', $args); - } - - /** - * @param array $args - * @return array - */ - public function rollback(array $args) - { - return $this->sendWithHeaders('projects', 'rollback', $args); - } - - /** - * @param array $args - * @return array - */ - public function runQuery(array $args) - { - // There is a push to stop using generic arrays for options. - // We will transition into using structured options in the future - // hence we add this to handle options with the message type - if (isset($args['explainOptions'])) { - $args['explainOptions'] = json_decode($args['explainOptions']->serializeToJsonString()); - } - - return $this->sendWithHeaders('projects', 'runQuery', $args); - } - - /** - * @param array $args - * @return array - */ - public function runAggregationQuery(array $args) - { - if (isset($args['aggregationQuery']['aggregations'])) { - foreach ($args['aggregationQuery']['aggregations'] as &$aggregation) { - $aggregation = array_map( - fn ($item) => is_array($item) && count($item) === 0 - ? new \stdClass() - : $item, - $aggregation - ); - } - } - // There is a push to stop using generic arrays for options. - // We will transition into using structured options in the future - // hence we add this to handle options with the message type - if (isset($args['explainOptions'])) { - $args['explainOptions'] = json_decode($args['explainOptions']->serializeToJsonString()); - } - return $this->sendWithHeaders('projects', 'runAggregationQuery', $args); - } - - /** - * Deliver the request built from serice definition. - * Also apply the `x-goog-request-params` header to the request. This header - * is required for operations involving a non-default databases. - * - * @param string $resource The resource type used for the request. - * @param string $method The method used for the request. - * @param array $args Options used to build out the request. - */ - private function sendWithHeaders($resource, $method, $args) - { - if (isset($args['projectId']) && isset($args['databaseId'])) { - $args['restOptions']['headers']['x-goog-request-params'] = sprintf( - 'project_id=%s&database_id=%s', - $args['projectId'], - $args['databaseId'] - ); - } - - return $this->send($resource, $method, $args); - } -} diff --git a/Datastore/src/Connection/ServiceDefinition/datastore-v1.json b/Datastore/src/Connection/ServiceDefinition/datastore-v1.json deleted file mode 100644 index fd7726f07299..000000000000 --- a/Datastore/src/Connection/ServiceDefinition/datastore-v1.json +++ /dev/null @@ -1,2758 +0,0 @@ -{ - "basePath": "", - "title": "Cloud Datastore API", - "parameters": { - "access_token": { - "type": "string", - "description": "OAuth access token.", - "location": "query" - }, - "alt": { - "type": "string", - "description": "Data format for response.", - "default": "json", - "enum": [ - "json", - "media", - "proto" - ], - "enumDescriptions": [ - "Responses with Content-Type of application/json", - "Media download with context-dependent Content-Type", - "Responses with Content-Type of application/x-protobuf" - ], - "location": "query" - }, - "callback": { - "type": "string", - "description": "JSONP", - "location": "query" - }, - "fields": { - "type": "string", - "description": "Selector specifying which fields to include in a partial response.", - "location": "query" - }, - "key": { - "type": "string", - "description": "API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.", - "location": "query" - }, - "oauth_token": { - "type": "string", - "description": "OAuth 2.0 token for the current user.", - "location": "query" - }, - "prettyPrint": { - "type": "boolean", - "description": "Returns response with indentations and line breaks.", - "default": "true", - "location": "query" - }, - "quotaUser": { - "type": "string", - "description": "Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters.", - "location": "query" - }, - "upload_protocol": { - "type": "string", - "description": "Upload protocol for media (e.g. \"raw\", \"multipart\").", - "location": "query" - }, - "uploadType": { - "type": "string", - "description": "Legacy upload protocol for media (e.g. \"media\", \"multipart\").", - "location": "query" - }, - "$.xgafv": { - "type": "string", - "description": "V1 error format.", - "enum": [ - "1", - "2" - ], - "enumDescriptions": [ - "v1 error format", - "v2 error format" - ], - "location": "query" - } - }, - "servicePath": "", - "documentationLink": "https://cloud.google.com/datastore/", - "schemas": { - "GoogleLongrunningListOperationsResponse": { - "id": "GoogleLongrunningListOperationsResponse", - "description": "The response message for Operations.ListOperations.", - "type": "object", - "properties": { - "operations": { - "description": "A list of operations that matches the specified filter in the request.", - "type": "array", - "items": { - "$ref": "GoogleLongrunningOperation" - } - }, - "nextPageToken": { - "description": "The standard List next-page token.", - "type": "string" - } - } - }, - "GoogleLongrunningOperation": { - "id": "GoogleLongrunningOperation", - "description": "This resource represents a long-running operation that is the result of a network API call.", - "type": "object", - "properties": { - "name": { - "description": "The server-assigned name, which is only unique within the same service that originally returns it. If you use the default HTTP mapping, the `name` should be a resource name ending with `operations/{unique_id}`.", - "type": "string" - }, - "metadata": { - "description": "Service-specific metadata associated with the operation. It typically contains progress information and common metadata such as create time. Some services might not provide such metadata. Any method that returns a long-running operation should document the metadata type, if any.", - "type": "object", - "additionalProperties": { - "type": "any", - "description": "Properties of the object. Contains field @type with type URL." - } - }, - "done": { - "description": "If the value is `false`, it means the operation is still in progress. If `true`, the operation is completed, and either `error` or `response` is available.", - "type": "boolean" - }, - "error": { - "description": "The error result of the operation in case of failure or cancellation.", - "$ref": "Status" - }, - "response": { - "description": "The normal, successful response of the operation. If the original method returns no data on success, such as `Delete`, the response is `google.protobuf.Empty`. If the original method is standard `Get`/`Create`/`Update`, the response should be the resource. For other methods, the response should have the type `XxxResponse`, where `Xxx` is the original method name. For example, if the original method name is `TakeSnapshot()`, the inferred response type is `TakeSnapshotResponse`.", - "type": "object", - "additionalProperties": { - "type": "any", - "description": "Properties of the object. Contains field @type with type URL." - } - } - } - }, - "Status": { - "id": "Status", - "description": "The `Status` type defines a logical error model that is suitable for different programming environments, including REST APIs and RPC APIs. It is used by [gRPC](https://github.com/grpc). Each `Status` message contains three pieces of data: error code, error message, and error details. You can find out more about this error model and how to work with it in the [API Design Guide](https://cloud.google.com/apis/design/errors).", - "type": "object", - "properties": { - "code": { - "description": "The status code, which should be an enum value of google.rpc.Code.", - "type": "integer", - "format": "int32" - }, - "message": { - "description": "A developer-facing error message, which should be in English. Any user-facing error message should be localized and sent in the google.rpc.Status.details field, or localized by the client.", - "type": "string" - }, - "details": { - "description": "A list of messages that carry the error details. There is a common set of message types for APIs to use.", - "type": "array", - "items": { - "type": "object", - "additionalProperties": { - "type": "any", - "description": "Properties of the object. Contains field @type with type URL." - } - } - } - } - }, - "Empty": { - "id": "Empty", - "description": "A generic empty message that you can re-use to avoid defining duplicated empty messages in your APIs. A typical example is to use it as the request or the response type of an API method. For instance: service Foo { rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); }", - "type": "object", - "properties": {} - }, - "GoogleDatastoreAdminV1ExportEntitiesRequest": { - "id": "GoogleDatastoreAdminV1ExportEntitiesRequest", - "description": "The request for google.datastore.admin.v1.DatastoreAdmin.ExportEntities.", - "type": "object", - "properties": { - "labels": { - "description": "Client-assigned labels.", - "type": "object", - "additionalProperties": { - "type": "string" - } - }, - "entityFilter": { - "description": "Description of what data from the project is included in the export.", - "$ref": "GoogleDatastoreAdminV1EntityFilter" - }, - "outputUrlPrefix": { - "description": "Required. Location for the export metadata and data files. The full resource URL of the external storage location. Currently, only Google Cloud Storage is supported. So output_url_prefix should be of the form: `gs://BUCKET_NAME[/NAMESPACE_PATH]`, where `BUCKET_NAME` is the name of the Cloud Storage bucket and `NAMESPACE_PATH` is an optional Cloud Storage namespace path (this is not a Cloud Datastore namespace). For more information about Cloud Storage namespace paths, see [Object name considerations](https://cloud.google.com/storage/docs/naming#object-considerations). The resulting files will be nested deeper than the specified URL prefix. The final output URL will be provided in the google.datastore.admin.v1.ExportEntitiesResponse.output_url field. That value should be used for subsequent ImportEntities operations. By nesting the data files deeper, the same Cloud Storage bucket can be used in multiple ExportEntities operations without conflict.", - "type": "string" - } - } - }, - "GoogleDatastoreAdminV1EntityFilter": { - "id": "GoogleDatastoreAdminV1EntityFilter", - "description": "Identifies a subset of entities in a project. This is specified as combinations of kinds and namespaces (either or both of which may be all, as described in the following examples). Example usage: Entire project: kinds=[], namespace_ids=[] Kinds Foo and Bar in all namespaces: kinds=['Foo', 'Bar'], namespace_ids=[] Kinds Foo and Bar only in the default namespace: kinds=['Foo', 'Bar'], namespace_ids=[''] Kinds Foo and Bar in both the default and Baz namespaces: kinds=['Foo', 'Bar'], namespace_ids=['', 'Baz'] The entire Baz namespace: kinds=[], namespace_ids=['Baz']", - "type": "object", - "properties": { - "kinds": { - "description": "If empty, then this represents all kinds.", - "type": "array", - "items": { - "type": "string" - } - }, - "namespaceIds": { - "description": "An empty list represents all namespaces. This is the preferred usage for projects that don't use namespaces. An empty string element represents the default namespace. This should be used if the project has data in non-default namespaces, but doesn't want to include them. Each namespace in this list must be unique.", - "type": "array", - "items": { - "type": "string" - } - } - } - }, - "GoogleDatastoreAdminV1ImportEntitiesRequest": { - "id": "GoogleDatastoreAdminV1ImportEntitiesRequest", - "description": "The request for google.datastore.admin.v1.DatastoreAdmin.ImportEntities.", - "type": "object", - "properties": { - "labels": { - "description": "Client-assigned labels.", - "type": "object", - "additionalProperties": { - "type": "string" - } - }, - "inputUrl": { - "description": "Required. The full resource URL of the external storage location. Currently, only Google Cloud Storage is supported. So input_url should be of the form: `gs://BUCKET_NAME[/NAMESPACE_PATH]/OVERALL_EXPORT_METADATA_FILE`, where `BUCKET_NAME` is the name of the Cloud Storage bucket, `NAMESPACE_PATH` is an optional Cloud Storage namespace path (this is not a Cloud Datastore namespace), and `OVERALL_EXPORT_METADATA_FILE` is the metadata file written by the ExportEntities operation. For more information about Cloud Storage namespace paths, see [Object name considerations](https://cloud.google.com/storage/docs/naming#object-considerations). For more information, see google.datastore.admin.v1.ExportEntitiesResponse.output_url.", - "type": "string" - }, - "entityFilter": { - "description": "Optionally specify which kinds/namespaces are to be imported. If provided, the list must be a subset of the EntityFilter used in creating the export, otherwise a FAILED_PRECONDITION error will be returned. If no filter is specified then all entities from the export are imported.", - "$ref": "GoogleDatastoreAdminV1EntityFilter" - } - } - }, - "GoogleDatastoreAdminV1Index": { - "id": "GoogleDatastoreAdminV1Index", - "description": "Datastore composite index definition.", - "type": "object", - "properties": { - "projectId": { - "description": "Output only. Project ID.", - "readOnly": true, - "type": "string" - }, - "indexId": { - "description": "Output only. The resource ID of the index.", - "readOnly": true, - "type": "string" - }, - "kind": { - "description": "Required. The entity kind to which this index applies.", - "type": "string" - }, - "ancestor": { - "description": "Required. The index's ancestor mode. Must not be ANCESTOR_MODE_UNSPECIFIED.", - "type": "string", - "enumDescriptions": [ - "The ancestor mode is unspecified.", - "Do not include the entity's ancestors in the index.", - "Include all the entity's ancestors in the index." - ], - "enum": [ - "ANCESTOR_MODE_UNSPECIFIED", - "NONE", - "ALL_ANCESTORS" - ] - }, - "properties": { - "description": "Required. An ordered sequence of property names and their index attributes. Requires: * A maximum of 100 properties.", - "type": "array", - "items": { - "$ref": "GoogleDatastoreAdminV1IndexedProperty" - } - }, - "state": { - "description": "Output only. The state of the index.", - "readOnly": true, - "type": "string", - "enumDescriptions": [ - "The state is unspecified.", - "The index is being created, and cannot be used by queries. There is an active long-running operation for the index. The index is updated when writing an entity. Some index data may exist.", - "The index is ready to be used. The index is updated when writing an entity. The index is fully populated from all stored entities it applies to.", - "The index is being deleted, and cannot be used by queries. There is an active long-running operation for the index. The index is not updated when writing an entity. Some index data may exist.", - "The index was being created or deleted, but something went wrong. The index cannot by used by queries. There is no active long-running operation for the index, and the most recently finished long-running operation failed. The index is not updated when writing an entity. Some index data may exist." - ], - "enum": [ - "STATE_UNSPECIFIED", - "CREATING", - "READY", - "DELETING", - "ERROR" - ] - } - } - }, - "GoogleDatastoreAdminV1IndexedProperty": { - "id": "GoogleDatastoreAdminV1IndexedProperty", - "description": "A property of an index.", - "type": "object", - "properties": { - "name": { - "description": "Required. The property name to index.", - "type": "string" - }, - "direction": { - "description": "Required. The indexed property's direction. Must not be DIRECTION_UNSPECIFIED.", - "type": "string", - "enumDescriptions": [ - "The direction is unspecified.", - "The property's values are indexed so as to support sequencing in ascending order and also query by \u003c, \u003e, \u003c=, \u003e=, and =.", - "The property's values are indexed so as to support sequencing in descending order and also query by \u003c, \u003e, \u003c=, \u003e=, and =." - ], - "enum": [ - "DIRECTION_UNSPECIFIED", - "ASCENDING", - "DESCENDING" - ] - } - } - }, - "GoogleDatastoreAdminV1ListIndexesResponse": { - "id": "GoogleDatastoreAdminV1ListIndexesResponse", - "description": "The response for google.datastore.admin.v1.DatastoreAdmin.ListIndexes.", - "type": "object", - "properties": { - "indexes": { - "description": "The indexes.", - "type": "array", - "items": { - "$ref": "GoogleDatastoreAdminV1Index" - } - }, - "nextPageToken": { - "description": "The standard List next-page token.", - "type": "string" - } - } - }, - "LookupRequest": { - "id": "LookupRequest", - "description": "The request for Datastore.Lookup.", - "type": "object", - "properties": { - "databaseId": { - "description": "The ID of the database against which to make the request. '(default)' is not allowed; please use empty string '' to refer the default database.", - "type": "string" - }, - "readOptions": { - "description": "The options for this lookup request.", - "$ref": "ReadOptions" - }, - "keys": { - "description": "Required. Keys of entities to look up.", - "type": "array", - "items": { - "$ref": "Key" - } - }, - "propertyMask": { - "description": "The properties to return. Defaults to returning all properties. If this field is set and an entity has a property not referenced in the mask, it will be absent from LookupResponse.found.entity.properties. The entity's key is always returned.", - "$ref": "PropertyMask" - } - } - }, - "ReadOptions": { - "id": "ReadOptions", - "description": "The options shared by read requests.", - "type": "object", - "properties": { - "readConsistency": { - "description": "The non-transactional read consistency to use.", - "type": "string", - "enumDescriptions": [ - "Unspecified. This value must not be used.", - "Strong consistency.", - "Eventual consistency." - ], - "enum": [ - "READ_CONSISTENCY_UNSPECIFIED", - "STRONG", - "EVENTUAL" - ] - }, - "transaction": { - "description": "The identifier of the transaction in which to read. A transaction identifier is returned by a call to Datastore.BeginTransaction.", - "type": "string", - "format": "byte" - }, - "newTransaction": { - "description": "Options for beginning a new transaction for this request. The new transaction identifier will be returned in the corresponding response as either LookupResponse.transaction or RunQueryResponse.transaction.", - "$ref": "TransactionOptions" - }, - "readTime": { - "description": "Reads entities as they were at the given time. This value is only supported for Cloud Firestore in Datastore mode. This must be a microsecond precision timestamp within the past one hour, or if Point-in-Time Recovery is enabled, can additionally be a whole minute timestamp within the past 7 days.", - "type": "string", - "format": "google-datetime" - } - } - }, - "TransactionOptions": { - "id": "TransactionOptions", - "description": "Options for beginning a new transaction. Transactions can be created explicitly with calls to Datastore.BeginTransaction or implicitly by setting ReadOptions.new_transaction in read requests.", - "type": "object", - "properties": { - "readWrite": { - "description": "The transaction should allow both reads and writes.", - "$ref": "ReadWrite" - }, - "readOnly": { - "description": "The transaction should only allow reads.", - "$ref": "ReadOnly" - } - } - }, - "ReadWrite": { - "id": "ReadWrite", - "description": "Options specific to read / write transactions.", - "type": "object", - "properties": { - "previousTransaction": { - "description": "The transaction identifier of the transaction being retried.", - "type": "string", - "format": "byte" - } - } - }, - "ReadOnly": { - "id": "ReadOnly", - "description": "Options specific to read-only transactions.", - "type": "object", - "properties": { - "readTime": { - "description": "Reads entities at the given time. This must be a microsecond precision timestamp within the past one hour, or if Point-in-Time Recovery is enabled, can additionally be a whole minute timestamp within the past 7 days.", - "type": "string", - "format": "google-datetime" - } - } - }, - "Key": { - "id": "Key", - "description": "A unique identifier for an entity. If a key's partition ID or any of its path kinds or names are reserved/read-only, the key is reserved/read-only. A reserved/read-only key is forbidden in certain documented contexts.", - "type": "object", - "properties": { - "partitionId": { - "description": "Entities are partitioned into subsets, currently identified by a project ID and namespace ID. Queries are scoped to a single partition.", - "$ref": "PartitionId" - }, - "path": { - "description": "The entity path. An entity path consists of one or more elements composed of a kind and a string or numerical identifier, which identify entities. The first element identifies a _root entity_, the second element identifies a _child_ of the root entity, the third element identifies a child of the second entity, and so forth. The entities identified by all prefixes of the path are called the element's _ancestors_. An entity path is always fully complete: *all* of the entity's ancestors are required to be in the path along with the entity identifier itself. The only exception is that in some documented cases, the identifier in the last path element (for the entity) itself may be omitted. For example, the last path element of the key of `Mutation.insert` may have no identifier. A path can never be empty, and a path can have at most 100 elements.", - "type": "array", - "items": { - "$ref": "PathElement" - } - } - } - }, - "PartitionId": { - "id": "PartitionId", - "description": "A partition ID identifies a grouping of entities. The grouping is always by project and namespace, however the namespace ID may be empty. A partition ID contains several dimensions: project ID and namespace ID. Partition dimensions: - May be `\"\"`. - Must be valid UTF-8 bytes. - Must have values that match regex `[A-Za-z\\d\\.\\-_]{1,100}` If the value of any dimension matches regex `__.*__`, the partition is reserved/read-only. A reserved/read-only partition ID is forbidden in certain documented contexts. Foreign partition IDs (in which the project ID does not match the context project ID ) are discouraged. Reads and writes of foreign partition IDs may fail if the project is not in an active state.", - "type": "object", - "properties": { - "projectId": { - "description": "The ID of the project to which the entities belong.", - "type": "string" - }, - "databaseId": { - "description": "If not empty, the ID of the database to which the entities belong.", - "type": "string" - }, - "namespaceId": { - "description": "If not empty, the ID of the namespace to which the entities belong.", - "type": "string" - } - } - }, - "PathElement": { - "id": "PathElement", - "description": "A (kind, ID/name) pair used to construct a key path. If either name or ID is set, the element is complete. If neither is set, the element is incomplete.", - "type": "object", - "properties": { - "kind": { - "description": "The kind of the entity. A kind matching regex `__.*__` is reserved/read-only. A kind must not contain more than 1500 bytes when UTF-8 encoded. Cannot be `\"\"`. Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are encoded as `__bytes__` where `` is the base-64 encoding of the bytes.", - "type": "string" - }, - "id": { - "description": "The auto-allocated ID of the entity. Never equal to zero. Values less than zero are discouraged and may not be supported in the future.", - "type": "string", - "format": "int64" - }, - "name": { - "description": "The name of the entity. A name matching regex `__.*__` is reserved/read-only. A name must not be more than 1500 bytes when UTF-8 encoded. Cannot be `\"\"`. Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are encoded as `__bytes__` where `` is the base-64 encoding of the bytes.", - "type": "string" - } - } - }, - "PropertyMask": { - "id": "PropertyMask", - "description": "The set of arbitrarily nested property paths used to restrict an operation to only a subset of properties in an entity.", - "type": "object", - "properties": { - "paths": { - "description": "The paths to the properties covered by this mask. A path is a list of property names separated by dots (`.`), for example `foo.bar` means the property `bar` inside the entity property `foo` inside the entity associated with this path. If a property name contains a dot `.` or a backslash `\\`, then that name must be escaped. A path must not be empty, and may not reference a value inside an array value.", - "type": "array", - "items": { - "type": "string" - } - } - } - }, - "LookupResponse": { - "id": "LookupResponse", - "description": "The response for Datastore.Lookup.", - "type": "object", - "properties": { - "found": { - "description": "Entities found as `ResultType.FULL` entities. The order of results in this field is undefined and has no relation to the order of the keys in the input.", - "type": "array", - "items": { - "$ref": "EntityResult" - } - }, - "missing": { - "description": "Entities not found as `ResultType.KEY_ONLY` entities. The order of results in this field is undefined and has no relation to the order of the keys in the input.", - "type": "array", - "items": { - "$ref": "EntityResult" - } - }, - "deferred": { - "description": "A list of keys that were not looked up due to resource constraints. The order of results in this field is undefined and has no relation to the order of the keys in the input.", - "type": "array", - "items": { - "$ref": "Key" - } - }, - "transaction": { - "description": "The identifier of the transaction that was started as part of this Lookup request. Set only when ReadOptions.new_transaction was set in LookupRequest.read_options.", - "type": "string", - "format": "byte" - }, - "readTime": { - "description": "The time at which these entities were read or found missing.", - "type": "string", - "format": "google-datetime" - } - } - }, - "EntityResult": { - "id": "EntityResult", - "description": "The result of fetching an entity from Datastore.", - "type": "object", - "properties": { - "entity": { - "description": "The resulting entity.", - "$ref": "Entity" - }, - "version": { - "description": "The version of the entity, a strictly positive number that monotonically increases with changes to the entity. This field is set for `FULL` entity results. For missing entities in `LookupResponse`, this is the version of the snapshot that was used to look up the entity, and it is always set except for eventually consistent reads.", - "type": "string", - "format": "int64" - }, - "createTime": { - "description": "The time at which the entity was created. This field is set for `FULL` entity results. If this entity is missing, this field will not be set.", - "type": "string", - "format": "google-datetime" - }, - "updateTime": { - "description": "The time at which the entity was last changed. This field is set for `FULL` entity results. If this entity is missing, this field will not be set.", - "type": "string", - "format": "google-datetime" - }, - "cursor": { - "description": "A cursor that points to the position after the result entity. Set only when the `EntityResult` is part of a `QueryResultBatch` message.", - "type": "string", - "format": "byte" - } - } - }, - "Entity": { - "id": "Entity", - "description": "A Datastore data object. Must not exceed 1 MiB - 4 bytes.", - "type": "object", - "properties": { - "key": { - "description": "The entity's key. An entity must have a key, unless otherwise documented (for example, an entity in `Value.entity_value` may have no key). An entity's kind is its key path's last element's kind, or null if it has no key.", - "$ref": "Key" - }, - "properties": { - "description": "The entity's properties. The map's keys are property names. A property name matching regex `__.*__` is reserved. A reserved property name is forbidden in certain documented contexts. The map keys, represented as UTF-8, must not exceed 1,500 bytes and cannot be empty.", - "type": "object", - "additionalProperties": { - "$ref": "Value" - } - } - } - }, - "Value": { - "id": "Value", - "description": "A message that can hold any of the supported value types and associated metadata.", - "type": "object", - "properties": { - "nullValue": { - "description": "A null value.", - "type": "string", - "enumDescriptions": [ - "Null value." - ], - "enum": [ - "NULL_VALUE" - ] - }, - "booleanValue": { - "description": "A boolean value.", - "type": "boolean" - }, - "integerValue": { - "description": "An integer value.", - "type": "string", - "format": "int64" - }, - "doubleValue": { - "description": "A double value.", - "type": "number", - "format": "double" - }, - "timestampValue": { - "description": "A timestamp value. When stored in the Datastore, precise only to microseconds; any additional precision is rounded down.", - "type": "string", - "format": "google-datetime" - }, - "keyValue": { - "description": "A key value.", - "$ref": "Key" - }, - "stringValue": { - "description": "A UTF-8 encoded string value. When `exclude_from_indexes` is false (it is indexed) , may have at most 1500 bytes. Otherwise, may be set to at most 1,000,000 bytes.", - "type": "string" - }, - "blobValue": { - "description": "A blob value. May have at most 1,000,000 bytes. When `exclude_from_indexes` is false, may have at most 1500 bytes. In JSON requests, must be base64-encoded.", - "type": "string", - "format": "byte" - }, - "geoPointValue": { - "description": "A geo point value representing a point on the surface of Earth.", - "$ref": "LatLng" - }, - "entityValue": { - "description": "An entity value. - May have no key. - May have a key with an incomplete key path. - May have a reserved/read-only key.", - "$ref": "Entity" - }, - "arrayValue": { - "description": "An array value. Cannot contain another array value. A `Value` instance that sets field `array_value` must not set fields `meaning` or `exclude_from_indexes`.", - "$ref": "ArrayValue" - }, - "meaning": { - "description": "The `meaning` field should only be populated for backwards compatibility.", - "type": "integer", - "format": "int32" - }, - "excludeFromIndexes": { - "description": "If the value should be excluded from all indexes including those defined explicitly.", - "type": "boolean" - } - } - }, - "LatLng": { - "id": "LatLng", - "description": "An object that represents a latitude/longitude pair. This is expressed as a pair of doubles to represent degrees latitude and degrees longitude. Unless specified otherwise, this object must conform to the WGS84 standard. Values must be within normalized ranges.", - "type": "object", - "properties": { - "latitude": { - "description": "The latitude in degrees. It must be in the range [-90.0, +90.0].", - "type": "number", - "format": "double" - }, - "longitude": { - "description": "The longitude in degrees. It must be in the range [-180.0, +180.0].", - "type": "number", - "format": "double" - } - } - }, - "ArrayValue": { - "id": "ArrayValue", - "description": "An array value.", - "type": "object", - "properties": { - "values": { - "description": "Values in the array. The order of values in an array is preserved as long as all values have identical settings for 'exclude_from_indexes'.", - "type": "array", - "items": { - "$ref": "Value" - } - } - } - }, - "RunQueryRequest": { - "id": "RunQueryRequest", - "description": "The request for Datastore.RunQuery.", - "type": "object", - "properties": { - "databaseId": { - "description": "The ID of the database against which to make the request. '(default)' is not allowed; please use empty string '' to refer the default database.", - "type": "string" - }, - "partitionId": { - "description": "Entities are partitioned into subsets, identified by a partition ID. Queries are scoped to a single partition. This partition ID is normalized with the standard default context partition ID.", - "$ref": "PartitionId" - }, - "readOptions": { - "description": "The options for this query.", - "$ref": "ReadOptions" - }, - "query": { - "description": "The query to run.", - "$ref": "Query" - }, - "gqlQuery": { - "description": "The GQL query to run. This query must be a non-aggregation query.", - "$ref": "GqlQuery" - }, - "propertyMask": { - "description": "The properties to return. This field must not be set for a projection query. See LookupRequest.property_mask.", - "$ref": "PropertyMask" - }, - "explainOptions": { - "description": "Optional. Explain options for the query. If set, additional query statistics will be returned. If not, only query results will be returned.", - "$ref": "ExplainOptions" - } - } - }, - "Query": { - "id": "Query", - "description": "A query for entities. The query stages are executed in the following order: 1. kind 2. filter 3. projection 4. order + start_cursor + end_cursor 5. offset 6. limit 7. find_nearest", - "type": "object", - "properties": { - "projection": { - "description": "The projection to return. Defaults to returning all properties.", - "type": "array", - "items": { - "$ref": "Projection" - } - }, - "kind": { - "description": "The kinds to query (if empty, returns entities of all kinds). Currently at most 1 kind may be specified.", - "type": "array", - "items": { - "$ref": "KindExpression" - } - }, - "filter": { - "description": "The filter to apply.", - "$ref": "Filter" - }, - "order": { - "description": "The order to apply to the query results (if empty, order is unspecified).", - "type": "array", - "items": { - "$ref": "PropertyOrder" - } - }, - "distinctOn": { - "description": "The properties to make distinct. The query results will contain the first result for each distinct combination of values for the given properties (if empty, all results are returned). Requires: * If `order` is specified, the set of distinct on properties must appear before the non-distinct on properties in `order`.", - "type": "array", - "items": { - "$ref": "PropertyReference" - } - }, - "startCursor": { - "description": "A starting point for the query results. Query cursors are returned in query result batches and [can only be used to continue the same query](https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets).", - "type": "string", - "format": "byte" - }, - "endCursor": { - "description": "An ending point for the query results. Query cursors are returned in query result batches and [can only be used to limit the same query](https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets).", - "type": "string", - "format": "byte" - }, - "offset": { - "description": "The number of results to skip. Applies before limit, but after all other constraints. Optional. Must be \u003e= 0 if specified.", - "type": "integer", - "format": "int32" - }, - "limit": { - "description": "The maximum number of results to return. Applies after all other constraints. Optional. Unspecified is interpreted as no limit. Must be \u003e= 0 if specified.", - "type": "integer", - "format": "int32" - }, - "findNearest": { - "description": "Optional. A potential Nearest Neighbors Search. Applies after all other filters and ordering. Finds the closest vector embeddings to the given query vector.", - "$ref": "FindNearest" - } - } - }, - "Projection": { - "id": "Projection", - "description": "A representation of a property in a projection.", - "type": "object", - "properties": { - "property": { - "description": "The property to project.", - "$ref": "PropertyReference" - } - } - }, - "PropertyReference": { - "id": "PropertyReference", - "description": "A reference to a property relative to the kind expressions.", - "type": "object", - "properties": { - "name": { - "description": "A reference to a property. Requires: * MUST be a dot-delimited (`.`) string of segments, where each segment conforms to entity property name limitations.", - "type": "string" - } - } - }, - "KindExpression": { - "id": "KindExpression", - "description": "A representation of a kind.", - "type": "object", - "properties": { - "name": { - "description": "The name of the kind.", - "type": "string" - } - } - }, - "Filter": { - "id": "Filter", - "description": "A holder for any type of filter.", - "type": "object", - "properties": { - "compositeFilter": { - "description": "A composite filter.", - "$ref": "CompositeFilter" - }, - "propertyFilter": { - "description": "A filter on a property.", - "$ref": "PropertyFilter" - } - } - }, - "CompositeFilter": { - "id": "CompositeFilter", - "description": "A filter that merges multiple other filters using the given operator.", - "type": "object", - "properties": { - "op": { - "description": "The operator for combining multiple filters.", - "type": "string", - "enumDescriptions": [ - "Unspecified. This value must not be used.", - "The results are required to satisfy each of the combined filters.", - "Documents are required to satisfy at least one of the combined filters." - ], - "enum": [ - "OPERATOR_UNSPECIFIED", - "AND", - "OR" - ] - }, - "filters": { - "description": "The list of filters to combine. Requires: * At least one filter is present.", - "type": "array", - "items": { - "$ref": "Filter" - } - } - } - }, - "PropertyFilter": { - "id": "PropertyFilter", - "description": "A filter on a specific property.", - "type": "object", - "properties": { - "property": { - "description": "The property to filter by.", - "$ref": "PropertyReference" - }, - "op": { - "description": "The operator to filter by.", - "type": "string", - "enumDescriptions": [ - "Unspecified. This value must not be used.", - "The given `property` is less than the given `value`. Requires: * That `property` comes first in `order_by`.", - "The given `property` is less than or equal to the given `value`. Requires: * That `property` comes first in `order_by`.", - "The given `property` is greater than the given `value`. Requires: * That `property` comes first in `order_by`.", - "The given `property` is greater than or equal to the given `value`. Requires: * That `property` comes first in `order_by`.", - "The given `property` is equal to the given `value`.", - "The given `property` is equal to at least one value in the given array. Requires: * That `value` is a non-empty `ArrayValue`, subject to disjunction limits. * No `NOT_IN` is in the same query.", - "The given `property` is not equal to the given `value`. Requires: * No other `NOT_EQUAL` or `NOT_IN` is in the same query. * That `property` comes first in the `order_by`.", - "Limit the result set to the given entity and its descendants. Requires: * That `value` is an entity key. * All evaluated disjunctions must have the same `HAS_ANCESTOR` filter.", - "The value of the `property` is not in the given array. Requires: * That `value` is a non-empty `ArrayValue` with at most 10 values. * No other `OR`, `IN`, `NOT_IN`, `NOT_EQUAL` is in the same query. * That `field` comes first in the `order_by`." - ], - "enum": [ - "OPERATOR_UNSPECIFIED", - "LESS_THAN", - "LESS_THAN_OR_EQUAL", - "GREATER_THAN", - "GREATER_THAN_OR_EQUAL", - "EQUAL", - "IN", - "NOT_EQUAL", - "HAS_ANCESTOR", - "NOT_IN" - ] - }, - "value": { - "description": "The value to compare the property to.", - "$ref": "Value" - } - } - }, - "PropertyOrder": { - "id": "PropertyOrder", - "description": "The desired order for a specific property.", - "type": "object", - "properties": { - "property": { - "description": "The property to order by.", - "$ref": "PropertyReference" - }, - "direction": { - "description": "The direction to order by. Defaults to `ASCENDING`.", - "type": "string", - "enumDescriptions": [ - "Unspecified. This value must not be used.", - "Ascending.", - "Descending." - ], - "enum": [ - "DIRECTION_UNSPECIFIED", - "ASCENDING", - "DESCENDING" - ] - } - } - }, - "FindNearest": { - "id": "FindNearest", - "description": "Nearest Neighbors search config. The ordering provided by FindNearest supersedes the order_by stage. If multiple documents have the same vector distance, the returned document order is not guaranteed to be stable between queries.", - "type": "object", - "properties": { - "vectorProperty": { - "description": "Required. An indexed vector property to search upon. Only documents which contain vectors whose dimensionality match the query_vector can be returned.", - "$ref": "PropertyReference" - }, - "queryVector": { - "description": "Required. The query vector that we are searching on. Must be a vector of no more than 2048 dimensions.", - "$ref": "Value" - }, - "distanceMeasure": { - "description": "Required. The Distance Measure to use, required.", - "type": "string", - "enumDescriptions": [ - "Should not be set.", - "Measures the EUCLIDEAN distance between the vectors. See [Euclidean](https://en.wikipedia.org/wiki/Euclidean_distance) to learn more. The resulting distance decreases the more similar two vectors are.", - "COSINE distance compares vectors based on the angle between them, which allows you to measure similarity that isn't based on the vectors magnitude. We recommend using DOT_PRODUCT with unit normalized vectors instead of COSINE distance, which is mathematically equivalent with better performance. See [Cosine Similarity](https://en.wikipedia.org/wiki/Cosine_similarity) to learn more about COSINE similarity and COSINE distance. The resulting COSINE distance decreases the more similar two vectors are.", - "Similar to cosine but is affected by the magnitude of the vectors. See [Dot Product](https://en.wikipedia.org/wiki/Dot_product) to learn more. The resulting distance increases the more similar two vectors are." - ], - "enum": [ - "DISTANCE_MEASURE_UNSPECIFIED", - "EUCLIDEAN", - "COSINE", - "DOT_PRODUCT" - ] - }, - "limit": { - "description": "Required. The number of nearest neighbors to return. Must be a positive integer of no more than 100.", - "type": "integer", - "format": "int32" - }, - "distanceResultProperty": { - "description": "Optional. Optional name of the field to output the result of the vector distance calculation. Must conform to entity property limitations.", - "type": "string" - }, - "distanceThreshold": { - "description": "Optional. Option to specify a threshold for which no less similar documents will be returned. The behavior of the specified `distance_measure` will affect the meaning of the distance threshold. Since DOT_PRODUCT distances increase when the vectors are more similar, the comparison is inverted. * For EUCLIDEAN, COSINE: WHERE distance \u003c= distance_threshold * For DOT_PRODUCT: WHERE distance \u003e= distance_threshold", - "type": "number", - "format": "double" - } - } - }, - "GqlQuery": { - "id": "GqlQuery", - "description": "A [GQL query](https://cloud.google.com/datastore/docs/apis/gql/gql_reference).", - "type": "object", - "properties": { - "queryString": { - "description": "A string of the format described [here](https://cloud.google.com/datastore/docs/apis/gql/gql_reference).", - "type": "string" - }, - "allowLiterals": { - "description": "When false, the query string must not contain any literals and instead must bind all values. For example, `SELECT * FROM Kind WHERE a = 'string literal'` is not allowed, while `SELECT * FROM Kind WHERE a = @value` is.", - "type": "boolean" - }, - "namedBindings": { - "description": "For each non-reserved named binding site in the query string, there must be a named parameter with that name, but not necessarily the inverse. Key must match regex `A-Za-z_$*`, must not match regex `__.*__`, and must not be `\"\"`.", - "type": "object", - "additionalProperties": { - "$ref": "GqlQueryParameter" - } - }, - "positionalBindings": { - "description": "Numbered binding site @1 references the first numbered parameter, effectively using 1-based indexing, rather than the usual 0. For each binding site numbered i in `query_string`, there must be an i-th numbered parameter. The inverse must also be true.", - "type": "array", - "items": { - "$ref": "GqlQueryParameter" - } - } - } - }, - "GqlQueryParameter": { - "id": "GqlQueryParameter", - "description": "A binding parameter for a GQL query.", - "type": "object", - "properties": { - "value": { - "description": "A value parameter.", - "$ref": "Value" - }, - "cursor": { - "description": "A query cursor. Query cursors are returned in query result batches.", - "type": "string", - "format": "byte" - } - } - }, - "ExplainOptions": { - "id": "ExplainOptions", - "description": "Explain options for the query.", - "type": "object", - "properties": { - "analyze": { - "description": "Optional. Whether to execute this query. When false (the default), the query will be planned, returning only metrics from the planning stages. When true, the query will be planned and executed, returning the full query results along with both planning and execution stage metrics.", - "type": "boolean" - } - } - }, - "RunQueryResponse": { - "id": "RunQueryResponse", - "description": "The response for Datastore.RunQuery.", - "type": "object", - "properties": { - "batch": { - "description": "A batch of query results. This is always present unless running a query under explain-only mode: RunQueryRequest.explain_options was provided and ExplainOptions.analyze was set to false.", - "$ref": "QueryResultBatch" - }, - "query": { - "description": "The parsed form of the `GqlQuery` from the request, if it was set.", - "$ref": "Query" - }, - "transaction": { - "description": "The identifier of the transaction that was started as part of this RunQuery request. Set only when ReadOptions.new_transaction was set in RunQueryRequest.read_options.", - "type": "string", - "format": "byte" - }, - "explainMetrics": { - "description": "Query explain metrics. This is only present when the RunQueryRequest.explain_options is provided, and it is sent only once with the last response in the stream.", - "$ref": "ExplainMetrics" - } - } - }, - "QueryResultBatch": { - "id": "QueryResultBatch", - "description": "A batch of results produced by a query.", - "type": "object", - "properties": { - "skippedResults": { - "description": "The number of results skipped, typically because of an offset.", - "type": "integer", - "format": "int32" - }, - "skippedCursor": { - "description": "A cursor that points to the position after the last skipped result. Will be set when `skipped_results` != 0.", - "type": "string", - "format": "byte" - }, - "entityResultType": { - "description": "The result type for every entity in `entity_results`.", - "type": "string", - "enumDescriptions": [ - "Unspecified. This value is never used.", - "The key and properties.", - "A projected subset of properties. The entity may have no key.", - "Only the key." - ], - "enum": [ - "RESULT_TYPE_UNSPECIFIED", - "FULL", - "PROJECTION", - "KEY_ONLY" - ] - }, - "entityResults": { - "description": "The results for this batch.", - "type": "array", - "items": { - "$ref": "EntityResult" - } - }, - "endCursor": { - "description": "A cursor that points to the position after the last result in the batch.", - "type": "string", - "format": "byte" - }, - "moreResults": { - "description": "The state of the query after the current batch.", - "type": "string", - "enumDescriptions": [ - "Unspecified. This value is never used.", - "There may be additional batches to fetch from this query.", - "The query is finished, but there may be more results after the limit.", - "The query is finished, but there may be more results after the end cursor.", - "The query is finished, and there are no more results." - ], - "enum": [ - "MORE_RESULTS_TYPE_UNSPECIFIED", - "NOT_FINISHED", - "MORE_RESULTS_AFTER_LIMIT", - "MORE_RESULTS_AFTER_CURSOR", - "NO_MORE_RESULTS" - ] - }, - "snapshotVersion": { - "description": "The version number of the snapshot this batch was returned from. This applies to the range of results from the query's `start_cursor` (or the beginning of the query if no cursor was given) to this batch's `end_cursor` (not the query's `end_cursor`). In a single transaction, subsequent query result batches for the same query can have a greater snapshot version number. Each batch's snapshot version is valid for all preceding batches. The value will be zero for eventually consistent queries.", - "type": "string", - "format": "int64" - }, - "readTime": { - "description": "Read timestamp this batch was returned from. This applies to the range of results from the query's `start_cursor` (or the beginning of the query if no cursor was given) to this batch's `end_cursor` (not the query's `end_cursor`). In a single transaction, subsequent query result batches for the same query can have a greater timestamp. Each batch's read timestamp is valid for all preceding batches. This value will not be set for eventually consistent queries in Cloud Datastore.", - "type": "string", - "format": "google-datetime" - } - } - }, - "ExplainMetrics": { - "id": "ExplainMetrics", - "description": "Explain metrics for the query.", - "type": "object", - "properties": { - "planSummary": { - "description": "Planning phase information for the query.", - "$ref": "PlanSummary" - }, - "executionStats": { - "description": "Aggregated stats from the execution of the query. Only present when ExplainOptions.analyze is set to true.", - "$ref": "ExecutionStats" - } - } - }, - "PlanSummary": { - "id": "PlanSummary", - "description": "Planning phase information for the query.", - "type": "object", - "properties": { - "indexesUsed": { - "description": "The indexes selected for the query. For example: [ {\"query_scope\": \"Collection\", \"properties\": \"(foo ASC, __name__ ASC)\"}, {\"query_scope\": \"Collection\", \"properties\": \"(bar ASC, __name__ ASC)\"} ]", - "type": "array", - "items": { - "type": "object", - "additionalProperties": { - "type": "any", - "description": "Properties of the object." - } - } - } - } - }, - "ExecutionStats": { - "id": "ExecutionStats", - "description": "Execution statistics for the query.", - "type": "object", - "properties": { - "resultsReturned": { - "description": "Total number of results returned, including documents, projections, aggregation results, keys.", - "type": "string", - "format": "int64" - }, - "executionDuration": { - "description": "Total time to execute the query in the backend.", - "type": "string", - "format": "google-duration" - }, - "readOperations": { - "description": "Total billable read operations.", - "type": "string", - "format": "int64" - }, - "debugStats": { - "description": "Debugging statistics from the execution of the query. Note that the debugging stats are subject to change as Firestore evolves. It could include: { \"indexes_entries_scanned\": \"1000\", \"documents_scanned\": \"20\", \"billing_details\" : { \"documents_billable\": \"20\", \"index_entries_billable\": \"1000\", \"min_query_cost\": \"0\" } }", - "type": "object", - "additionalProperties": { - "type": "any", - "description": "Properties of the object." - } - } - } - }, - "RunAggregationQueryRequest": { - "id": "RunAggregationQueryRequest", - "description": "The request for Datastore.RunAggregationQuery.", - "type": "object", - "properties": { - "databaseId": { - "description": "The ID of the database against which to make the request. '(default)' is not allowed; please use empty string '' to refer the default database.", - "type": "string" - }, - "partitionId": { - "description": "Entities are partitioned into subsets, identified by a partition ID. Queries are scoped to a single partition. This partition ID is normalized with the standard default context partition ID.", - "$ref": "PartitionId" - }, - "readOptions": { - "description": "The options for this query.", - "$ref": "ReadOptions" - }, - "aggregationQuery": { - "description": "The query to run.", - "$ref": "AggregationQuery" - }, - "gqlQuery": { - "description": "The GQL query to run. This query must be an aggregation query.", - "$ref": "GqlQuery" - }, - "explainOptions": { - "description": "Optional. Explain options for the query. If set, additional query statistics will be returned. If not, only query results will be returned.", - "$ref": "ExplainOptions" - } - } - }, - "AggregationQuery": { - "id": "AggregationQuery", - "description": "Datastore query for running an aggregation over a Query.", - "type": "object", - "properties": { - "nestedQuery": { - "description": "Nested query for aggregation", - "$ref": "Query" - }, - "aggregations": { - "description": "Optional. Series of aggregations to apply over the results of the `nested_query`. Requires: * A minimum of one and maximum of five aggregations per query.", - "type": "array", - "items": { - "$ref": "Aggregation" - } - } - } - }, - "Aggregation": { - "id": "Aggregation", - "description": "Defines an aggregation that produces a single result.", - "type": "object", - "properties": { - "count": { - "description": "Count aggregator.", - "$ref": "Count" - }, - "sum": { - "description": "Sum aggregator.", - "$ref": "Sum" - }, - "avg": { - "description": "Average aggregator.", - "$ref": "Avg" - }, - "alias": { - "description": "Optional. Optional name of the property to store the result of the aggregation. If not provided, Datastore will pick a default name following the format `property_`. For example: ``` AGGREGATE COUNT_UP_TO(1) AS count_up_to_1, COUNT_UP_TO(2), COUNT_UP_TO(3) AS count_up_to_3, COUNT(*) OVER ( ... ); ``` becomes: ``` AGGREGATE COUNT_UP_TO(1) AS count_up_to_1, COUNT_UP_TO(2) AS property_1, COUNT_UP_TO(3) AS count_up_to_3, COUNT(*) AS property_2 OVER ( ... ); ``` Requires: * Must be unique across all aggregation aliases. * Conform to entity property name limitations.", - "type": "string" - } - } - }, - "Count": { - "id": "Count", - "description": "Count of entities that match the query. The `COUNT(*)` aggregation function operates on the entire entity so it does not require a field reference.", - "type": "object", - "properties": { - "upTo": { - "description": "Optional. Optional constraint on the maximum number of entities to count. This provides a way to set an upper bound on the number of entities to scan, limiting latency, and cost. Unspecified is interpreted as no bound. If a zero value is provided, a count result of zero should always be expected. High-Level Example: ``` AGGREGATE COUNT_UP_TO(1000) OVER ( SELECT * FROM k ); ``` Requires: * Must be non-negative when present.", - "type": "string", - "format": "int64" - } - } - }, - "Sum": { - "id": "Sum", - "description": "Sum of the values of the requested property. * Only numeric values will be aggregated. All non-numeric values including `NULL` are skipped. * If the aggregated values contain `NaN`, returns `NaN`. Infinity math follows IEEE-754 standards. * If the aggregated value set is empty, returns 0. * Returns a 64-bit integer if all aggregated numbers are integers and the sum result does not overflow. Otherwise, the result is returned as a double. Note that even if all the aggregated values are integers, the result is returned as a double if it cannot fit within a 64-bit signed integer. When this occurs, the returned value will lose precision. * When underflow occurs, floating-point aggregation is non-deterministic. This means that running the same query repeatedly without any changes to the underlying values could produce slightly different results each time. In those cases, values should be stored as integers over floating-point numbers.", - "type": "object", - "properties": { - "property": { - "description": "The property to aggregate on.", - "$ref": "PropertyReference" - } - } - }, - "Avg": { - "id": "Avg", - "description": "Average of the values of the requested property. * Only numeric values will be aggregated. All non-numeric values including `NULL` are skipped. * If the aggregated values contain `NaN`, returns `NaN`. Infinity math follows IEEE-754 standards. * If the aggregated value set is empty, returns `NULL`. * Always returns the result as a double.", - "type": "object", - "properties": { - "property": { - "description": "The property to aggregate on.", - "$ref": "PropertyReference" - } - } - }, - "RunAggregationQueryResponse": { - "id": "RunAggregationQueryResponse", - "description": "The response for Datastore.RunAggregationQuery.", - "type": "object", - "properties": { - "batch": { - "description": "A batch of aggregation results. Always present.", - "$ref": "AggregationResultBatch" - }, - "query": { - "description": "The parsed form of the `GqlQuery` from the request, if it was set.", - "$ref": "AggregationQuery" - }, - "transaction": { - "description": "The identifier of the transaction that was started as part of this RunAggregationQuery request. Set only when ReadOptions.new_transaction was set in RunAggregationQueryRequest.read_options.", - "type": "string", - "format": "byte" - }, - "explainMetrics": { - "description": "Query explain metrics. This is only present when the RunAggregationQueryRequest.explain_options is provided, and it is sent only once with the last response in the stream.", - "$ref": "ExplainMetrics" - } - } - }, - "AggregationResultBatch": { - "id": "AggregationResultBatch", - "description": "A batch of aggregation results produced by an aggregation query.", - "type": "object", - "properties": { - "aggregationResults": { - "description": "The aggregation results for this batch.", - "type": "array", - "items": { - "$ref": "AggregationResult" - } - }, - "moreResults": { - "description": "The state of the query after the current batch. Only COUNT(*) aggregations are supported in the initial launch. Therefore, expected result type is limited to `NO_MORE_RESULTS`.", - "type": "string", - "enumDescriptions": [ - "Unspecified. This value is never used.", - "There may be additional batches to fetch from this query.", - "The query is finished, but there may be more results after the limit.", - "The query is finished, but there may be more results after the end cursor.", - "The query is finished, and there are no more results." - ], - "enum": [ - "MORE_RESULTS_TYPE_UNSPECIFIED", - "NOT_FINISHED", - "MORE_RESULTS_AFTER_LIMIT", - "MORE_RESULTS_AFTER_CURSOR", - "NO_MORE_RESULTS" - ] - }, - "readTime": { - "description": "Read timestamp this batch was returned from. In a single transaction, subsequent query result batches for the same query can have a greater timestamp. Each batch's read timestamp is valid for all preceding batches.", - "type": "string", - "format": "google-datetime" - } - } - }, - "AggregationResult": { - "id": "AggregationResult", - "description": "The result of a single bucket from a Datastore aggregation query. The keys of `aggregate_properties` are the same for all results in an aggregation query, unlike entity queries which can have different fields present for each result.", - "type": "object", - "properties": { - "aggregateProperties": { - "description": "The result of the aggregation functions, ex: `COUNT(*) AS total_entities`. The key is the alias assigned to the aggregation function on input and the size of this map equals the number of aggregation functions in the query.", - "type": "object", - "additionalProperties": { - "$ref": "Value" - } - } - } - }, - "BeginTransactionRequest": { - "id": "BeginTransactionRequest", - "description": "The request for Datastore.BeginTransaction.", - "type": "object", - "properties": { - "databaseId": { - "description": "The ID of the database against which to make the request. '(default)' is not allowed; please use empty string '' to refer the default database.", - "type": "string" - }, - "transactionOptions": { - "description": "Options for a new transaction.", - "$ref": "TransactionOptions" - } - } - }, - "BeginTransactionResponse": { - "id": "BeginTransactionResponse", - "description": "The response for Datastore.BeginTransaction.", - "type": "object", - "properties": { - "transaction": { - "description": "The transaction identifier (always present).", - "type": "string", - "format": "byte" - } - } - }, - "CommitRequest": { - "id": "CommitRequest", - "description": "The request for Datastore.Commit.", - "type": "object", - "properties": { - "databaseId": { - "description": "The ID of the database against which to make the request. '(default)' is not allowed; please use empty string '' to refer the default database.", - "type": "string" - }, - "mode": { - "description": "The type of commit to perform. Defaults to `TRANSACTIONAL`.", - "type": "string", - "enumDescriptions": [ - "Unspecified. This value must not be used.", - "Transactional: The mutations are either all applied, or none are applied. Learn about transactions [here](https://cloud.google.com/datastore/docs/concepts/transactions).", - "Non-transactional: The mutations may not apply as all or none." - ], - "enum": [ - "MODE_UNSPECIFIED", - "TRANSACTIONAL", - "NON_TRANSACTIONAL" - ] - }, - "transaction": { - "description": "The identifier of the transaction associated with the commit. A transaction identifier is returned by a call to Datastore.BeginTransaction.", - "type": "string", - "format": "byte" - }, - "singleUseTransaction": { - "description": "Options for beginning a new transaction for this request. The transaction is committed when the request completes. If specified, TransactionOptions.mode must be TransactionOptions.ReadWrite.", - "$ref": "TransactionOptions" - }, - "mutations": { - "description": "The mutations to perform. When mode is `TRANSACTIONAL`, mutations affecting a single entity are applied in order. The following sequences of mutations affecting a single entity are not permitted in a single `Commit` request: - `insert` followed by `insert` - `update` followed by `insert` - `upsert` followed by `insert` - `delete` followed by `update` When mode is `NON_TRANSACTIONAL`, no two mutations may affect a single entity.", - "type": "array", - "items": { - "$ref": "Mutation" - } - } - } - }, - "Mutation": { - "id": "Mutation", - "description": "A mutation to apply to an entity.", - "type": "object", - "properties": { - "insert": { - "description": "The entity to insert. The entity must not already exist. The entity key's final path element may be incomplete.", - "$ref": "Entity" - }, - "update": { - "description": "The entity to update. The entity must already exist. Must have a complete key path.", - "$ref": "Entity" - }, - "upsert": { - "description": "The entity to upsert. The entity may or may not already exist. The entity key's final path element may be incomplete.", - "$ref": "Entity" - }, - "delete": { - "description": "The key of the entity to delete. The entity may or may not already exist. Must have a complete key path and must not be reserved/read-only.", - "$ref": "Key" - }, - "baseVersion": { - "description": "The version of the entity that this mutation is being applied to. If this does not match the current version on the server, the mutation conflicts.", - "type": "string", - "format": "int64" - }, - "updateTime": { - "description": "The update time of the entity that this mutation is being applied to. If this does not match the current update time on the server, the mutation conflicts.", - "type": "string", - "format": "google-datetime" - }, - "conflictResolutionStrategy": { - "description": "The strategy to use when a conflict is detected. Defaults to `SERVER_VALUE`. If this is set, then `conflict_detection_strategy` must also be set.", - "type": "string", - "enumDescriptions": [ - "Unspecified. Defaults to `SERVER_VALUE`.", - "The server entity is kept.", - "The whole commit request fails." - ], - "enum": [ - "STRATEGY_UNSPECIFIED", - "SERVER_VALUE", - "FAIL" - ] - }, - "propertyMask": { - "description": "The properties to write in this mutation. None of the properties in the mask may have a reserved name, except for `__key__`. This field is ignored for `delete`. If the entity already exists, only properties referenced in the mask are updated, others are left untouched. Properties referenced in the mask but not in the entity are deleted.", - "$ref": "PropertyMask" - }, - "propertyTransforms": { - "description": "Optional. The transforms to perform on the entity. This field can be set only when the operation is `insert`, `update`, or `upsert`. If present, the transforms are be applied to the entity regardless of the property mask, in order, after the operation.", - "type": "array", - "items": { - "$ref": "PropertyTransform" - } - } - } - }, - "PropertyTransform": { - "id": "PropertyTransform", - "description": "A transformation of an entity property.", - "type": "object", - "properties": { - "property": { - "description": "Optional. The name of the property. Property paths (a list of property names separated by dots (`.`)) may be used to refer to properties inside entity values. For example `foo.bar` means the property `bar` inside the entity property `foo`. If a property name contains a dot `.` or a backlslash `\\`, then that name must be escaped.", - "type": "string" - }, - "setToServerValue": { - "description": "Sets the property to the given server value.", - "type": "string", - "enumDescriptions": [ - "Unspecified. This value must not be used.", - "The time at which the server processed the request, with millisecond precision. If used on multiple properties (same or different entities) in a transaction, all the properties will get the same server timestamp." - ], - "enum": [ - "SERVER_VALUE_UNSPECIFIED", - "REQUEST_TIME" - ] - }, - "increment": { - "description": "Adds the given value to the property's current value. This must be an integer or a double value. If the property is not an integer or double, or if the property does not yet exist, the transformation will set the property to the given value. If either of the given value or the current property value are doubles, both values will be interpreted as doubles. Double arithmetic and representation of double values follows IEEE 754 semantics. If there is positive/negative integer overflow, the property is resolved to the largest magnitude positive/negative integer.", - "$ref": "Value" - }, - "maximum": { - "description": "Sets the property to the maximum of its current value and the given value. This must be an integer or a double value. If the property is not an integer or double, or if the property does not yet exist, the transformation will set the property to the given value. If a maximum operation is applied where the property and the input value are of mixed types (that is - one is an integer and one is a double) the property takes on the type of the larger operand. If the operands are equivalent (e.g. 3 and 3.0), the property does not change. 0, 0.0, and -0.0 are all zero. The maximum of a zero stored value and zero input value is always the stored value. The maximum of any numeric value x and NaN is NaN.", - "$ref": "Value" - }, - "minimum": { - "description": "Sets the property to the minimum of its current value and the given value. This must be an integer or a double value. If the property is not an integer or double, or if the property does not yet exist, the transformation will set the property to the input value. If a minimum operation is applied where the property and the input value are of mixed types (that is - one is an integer and one is a double) the property takes on the type of the smaller operand. If the operands are equivalent (e.g. 3 and 3.0), the property does not change. 0, 0.0, and -0.0 are all zero. The minimum of a zero stored value and zero input value is always the stored value. The minimum of any numeric value x and NaN is NaN.", - "$ref": "Value" - }, - "appendMissingElements": { - "description": "Appends the given elements in order if they are not already present in the current property value. If the property is not an array, or if the property does not yet exist, it is first set to the empty array. Equivalent numbers of different types (e.g. 3L and 3.0) are considered equal when checking if a value is missing. NaN is equal to NaN, and the null value is equal to the null value. If the input contains multiple equivalent values, only the first will be considered. The corresponding transform result will be the null value.", - "$ref": "ArrayValue" - }, - "removeAllFromArray": { - "description": "Removes all of the given elements from the array in the property. If the property is not an array, or if the property does not yet exist, it is set to the empty array. Equivalent numbers of different types (e.g. 3L and 3.0) are considered equal when deciding whether an element should be removed. NaN is equal to NaN, and the null value is equal to the null value. This will remove all equivalent values if there are duplicates. The corresponding transform result will be the null value.", - "$ref": "ArrayValue" - } - } - }, - "CommitResponse": { - "id": "CommitResponse", - "description": "The response for Datastore.Commit.", - "type": "object", - "properties": { - "mutationResults": { - "description": "The result of performing the mutations. The i-th mutation result corresponds to the i-th mutation in the request.", - "type": "array", - "items": { - "$ref": "MutationResult" - } - }, - "indexUpdates": { - "description": "The number of index entries updated during the commit, or zero if none were updated.", - "type": "integer", - "format": "int32" - }, - "commitTime": { - "description": "The transaction commit timestamp. Not set for non-transactional commits.", - "type": "string", - "format": "google-datetime" - } - } - }, - "MutationResult": { - "id": "MutationResult", - "description": "The result of applying a mutation.", - "type": "object", - "properties": { - "key": { - "description": "The automatically allocated key. Set only when the mutation allocated a key.", - "$ref": "Key" - }, - "version": { - "description": "The version of the entity on the server after processing the mutation. If the mutation doesn't change anything on the server, then the version will be the version of the current entity or, if no entity is present, a version that is strictly greater than the version of any previous entity and less than the version of any possible future entity.", - "type": "string", - "format": "int64" - }, - "createTime": { - "description": "The create time of the entity. This field will not be set after a 'delete'.", - "type": "string", - "format": "google-datetime" - }, - "updateTime": { - "description": "The update time of the entity on the server after processing the mutation. If the mutation doesn't change anything on the server, then the timestamp will be the update timestamp of the current entity. This field will not be set after a 'delete'.", - "type": "string", - "format": "google-datetime" - }, - "conflictDetected": { - "description": "Whether a conflict was detected for this mutation. Always false when a conflict detection strategy field is not set in the mutation.", - "type": "boolean" - }, - "transformResults": { - "description": "The results of applying each PropertyTransform, in the same order of the request.", - "type": "array", - "items": { - "$ref": "Value" - } - } - } - }, - "RollbackRequest": { - "id": "RollbackRequest", - "description": "The request for Datastore.Rollback.", - "type": "object", - "properties": { - "databaseId": { - "description": "The ID of the database against which to make the request. '(default)' is not allowed; please use empty string '' to refer the default database.", - "type": "string" - }, - "transaction": { - "description": "Required. The transaction identifier, returned by a call to Datastore.BeginTransaction.", - "type": "string", - "format": "byte" - } - } - }, - "RollbackResponse": { - "id": "RollbackResponse", - "description": "The response for Datastore.Rollback. (an empty message).", - "type": "object", - "properties": {} - }, - "AllocateIdsRequest": { - "id": "AllocateIdsRequest", - "description": "The request for Datastore.AllocateIds.", - "type": "object", - "properties": { - "databaseId": { - "description": "The ID of the database against which to make the request. '(default)' is not allowed; please use empty string '' to refer the default database.", - "type": "string" - }, - "keys": { - "description": "Required. A list of keys with incomplete key paths for which to allocate IDs. No key may be reserved/read-only.", - "type": "array", - "items": { - "$ref": "Key" - } - } - } - }, - "AllocateIdsResponse": { - "id": "AllocateIdsResponse", - "description": "The response for Datastore.AllocateIds.", - "type": "object", - "properties": { - "keys": { - "description": "The keys specified in the request (in the same order), each with its key path completed with a newly allocated ID.", - "type": "array", - "items": { - "$ref": "Key" - } - } - } - }, - "ReserveIdsRequest": { - "id": "ReserveIdsRequest", - "description": "The request for Datastore.ReserveIds.", - "type": "object", - "properties": { - "databaseId": { - "description": "The ID of the database against which to make the request. '(default)' is not allowed; please use empty string '' to refer the default database.", - "type": "string" - }, - "keys": { - "description": "Required. A list of keys with complete key paths whose numeric IDs should not be auto-allocated.", - "type": "array", - "items": { - "$ref": "Key" - } - } - } - }, - "ReserveIdsResponse": { - "id": "ReserveIdsResponse", - "description": "The response for Datastore.ReserveIds.", - "type": "object", - "properties": {} - }, - "GoogleDatastoreAdminV1beta1ExportEntitiesMetadata": { - "id": "GoogleDatastoreAdminV1beta1ExportEntitiesMetadata", - "description": "Metadata for ExportEntities operations.", - "type": "object", - "properties": { - "common": { - "description": "Metadata common to all Datastore Admin operations.", - "$ref": "GoogleDatastoreAdminV1beta1CommonMetadata" - }, - "progressEntities": { - "description": "An estimate of the number of entities processed.", - "$ref": "GoogleDatastoreAdminV1beta1Progress" - }, - "progressBytes": { - "description": "An estimate of the number of bytes processed.", - "$ref": "GoogleDatastoreAdminV1beta1Progress" - }, - "entityFilter": { - "description": "Description of which entities are being exported.", - "$ref": "GoogleDatastoreAdminV1beta1EntityFilter" - }, - "outputUrlPrefix": { - "description": "Location for the export metadata and data files. This will be the same value as the google.datastore.admin.v1beta1.ExportEntitiesRequest.output_url_prefix field. The final output location is provided in google.datastore.admin.v1beta1.ExportEntitiesResponse.output_url.", - "type": "string" - } - } - }, - "GoogleDatastoreAdminV1beta1CommonMetadata": { - "id": "GoogleDatastoreAdminV1beta1CommonMetadata", - "description": "Metadata common to all Datastore Admin operations.", - "type": "object", - "properties": { - "startTime": { - "description": "The time that work began on the operation.", - "type": "string", - "format": "google-datetime" - }, - "endTime": { - "description": "The time the operation ended, either successfully or otherwise.", - "type": "string", - "format": "google-datetime" - }, - "operationType": { - "description": "The type of the operation. Can be used as a filter in ListOperationsRequest.", - "type": "string", - "enumDescriptions": [ - "Unspecified.", - "ExportEntities.", - "ImportEntities." - ], - "enum": [ - "OPERATION_TYPE_UNSPECIFIED", - "EXPORT_ENTITIES", - "IMPORT_ENTITIES" - ] - }, - "labels": { - "description": "The client-assigned labels which were provided when the operation was created. May also include additional labels.", - "type": "object", - "additionalProperties": { - "type": "string" - } - }, - "state": { - "description": "The current state of the Operation.", - "type": "string", - "enumDescriptions": [ - "Unspecified.", - "Request is being prepared for processing.", - "Request is actively being processed.", - "Request is in the process of being cancelled after user called google.longrunning.Operations.CancelOperation on the operation.", - "Request has been processed and is in its finalization stage.", - "Request has completed successfully.", - "Request has finished being processed, but encountered an error.", - "Request has finished being cancelled after user called google.longrunning.Operations.CancelOperation." - ], - "enum": [ - "STATE_UNSPECIFIED", - "INITIALIZING", - "PROCESSING", - "CANCELLING", - "FINALIZING", - "SUCCESSFUL", - "FAILED", - "CANCELLED" - ] - } - } - }, - "GoogleDatastoreAdminV1beta1Progress": { - "id": "GoogleDatastoreAdminV1beta1Progress", - "description": "Measures the progress of a particular metric.", - "type": "object", - "properties": { - "workCompleted": { - "description": "The amount of work that has been completed. Note that this may be greater than work_estimated.", - "type": "string", - "format": "int64" - }, - "workEstimated": { - "description": "An estimate of how much work needs to be performed. May be zero if the work estimate is unavailable.", - "type": "string", - "format": "int64" - } - } - }, - "GoogleDatastoreAdminV1beta1EntityFilter": { - "id": "GoogleDatastoreAdminV1beta1EntityFilter", - "description": "Identifies a subset of entities in a project. This is specified as combinations of kinds and namespaces (either or both of which may be all, as described in the following examples). Example usage: Entire project: kinds=[], namespace_ids=[] Kinds Foo and Bar in all namespaces: kinds=['Foo', 'Bar'], namespace_ids=[] Kinds Foo and Bar only in the default namespace: kinds=['Foo', 'Bar'], namespace_ids=[''] Kinds Foo and Bar in both the default and Baz namespaces: kinds=['Foo', 'Bar'], namespace_ids=['', 'Baz'] The entire Baz namespace: kinds=[], namespace_ids=['Baz']", - "type": "object", - "properties": { - "kinds": { - "description": "If empty, then this represents all kinds.", - "type": "array", - "items": { - "type": "string" - } - }, - "namespaceIds": { - "description": "An empty list represents all namespaces. This is the preferred usage for projects that don't use namespaces. An empty string element represents the default namespace. This should be used if the project has data in non-default namespaces, but doesn't want to include them. Each namespace in this list must be unique.", - "type": "array", - "items": { - "type": "string" - } - } - } - }, - "GoogleDatastoreAdminV1beta1ExportEntitiesResponse": { - "id": "GoogleDatastoreAdminV1beta1ExportEntitiesResponse", - "description": "The response for google.datastore.admin.v1beta1.DatastoreAdmin.ExportEntities.", - "type": "object", - "properties": { - "outputUrl": { - "description": "Location of the output metadata file. This can be used to begin an import into Cloud Datastore (this project or another project). See google.datastore.admin.v1beta1.ImportEntitiesRequest.input_url. Only present if the operation completed successfully.", - "type": "string" - } - } - }, - "GoogleDatastoreAdminV1beta1ImportEntitiesMetadata": { - "id": "GoogleDatastoreAdminV1beta1ImportEntitiesMetadata", - "description": "Metadata for ImportEntities operations.", - "type": "object", - "properties": { - "common": { - "description": "Metadata common to all Datastore Admin operations.", - "$ref": "GoogleDatastoreAdminV1beta1CommonMetadata" - }, - "progressEntities": { - "description": "An estimate of the number of entities processed.", - "$ref": "GoogleDatastoreAdminV1beta1Progress" - }, - "progressBytes": { - "description": "An estimate of the number of bytes processed.", - "$ref": "GoogleDatastoreAdminV1beta1Progress" - }, - "entityFilter": { - "description": "Description of which entities are being imported.", - "$ref": "GoogleDatastoreAdminV1beta1EntityFilter" - }, - "inputUrl": { - "description": "The location of the import metadata file. This will be the same value as the google.datastore.admin.v1beta1.ExportEntitiesResponse.output_url field.", - "type": "string" - } - } - }, - "GoogleDatastoreAdminV1ExportEntitiesMetadata": { - "id": "GoogleDatastoreAdminV1ExportEntitiesMetadata", - "description": "Metadata for ExportEntities operations.", - "type": "object", - "properties": { - "common": { - "description": "Metadata common to all Datastore Admin operations.", - "$ref": "GoogleDatastoreAdminV1CommonMetadata" - }, - "progressEntities": { - "description": "An estimate of the number of entities processed.", - "$ref": "GoogleDatastoreAdminV1Progress" - }, - "progressBytes": { - "description": "An estimate of the number of bytes processed.", - "$ref": "GoogleDatastoreAdminV1Progress" - }, - "entityFilter": { - "description": "Description of which entities are being exported.", - "$ref": "GoogleDatastoreAdminV1EntityFilter" - }, - "outputUrlPrefix": { - "description": "Location for the export metadata and data files. This will be the same value as the google.datastore.admin.v1.ExportEntitiesRequest.output_url_prefix field. The final output location is provided in google.datastore.admin.v1.ExportEntitiesResponse.output_url.", - "type": "string" - } - } - }, - "GoogleDatastoreAdminV1CommonMetadata": { - "id": "GoogleDatastoreAdminV1CommonMetadata", - "description": "Metadata common to all Datastore Admin operations.", - "type": "object", - "properties": { - "startTime": { - "description": "The time that work began on the operation.", - "type": "string", - "format": "google-datetime" - }, - "endTime": { - "description": "The time the operation ended, either successfully or otherwise.", - "type": "string", - "format": "google-datetime" - }, - "operationType": { - "description": "The type of the operation. Can be used as a filter in ListOperationsRequest.", - "type": "string", - "enumDescriptions": [ - "Unspecified.", - "ExportEntities.", - "ImportEntities.", - "CreateIndex.", - "DeleteIndex." - ], - "enum": [ - "OPERATION_TYPE_UNSPECIFIED", - "EXPORT_ENTITIES", - "IMPORT_ENTITIES", - "CREATE_INDEX", - "DELETE_INDEX" - ] - }, - "labels": { - "description": "The client-assigned labels which were provided when the operation was created. May also include additional labels.", - "type": "object", - "additionalProperties": { - "type": "string" - } - }, - "state": { - "description": "The current state of the Operation.", - "type": "string", - "enumDescriptions": [ - "Unspecified.", - "Request is being prepared for processing.", - "Request is actively being processed.", - "Request is in the process of being cancelled after user called google.longrunning.Operations.CancelOperation on the operation.", - "Request has been processed and is in its finalization stage.", - "Request has completed successfully.", - "Request has finished being processed, but encountered an error.", - "Request has finished being cancelled after user called google.longrunning.Operations.CancelOperation." - ], - "enum": [ - "STATE_UNSPECIFIED", - "INITIALIZING", - "PROCESSING", - "CANCELLING", - "FINALIZING", - "SUCCESSFUL", - "FAILED", - "CANCELLED" - ] - } - } - }, - "GoogleDatastoreAdminV1Progress": { - "id": "GoogleDatastoreAdminV1Progress", - "description": "Measures the progress of a particular metric.", - "type": "object", - "properties": { - "workCompleted": { - "description": "The amount of work that has been completed. Note that this may be greater than work_estimated.", - "type": "string", - "format": "int64" - }, - "workEstimated": { - "description": "An estimate of how much work needs to be performed. May be zero if the work estimate is unavailable.", - "type": "string", - "format": "int64" - } - } - }, - "GoogleDatastoreAdminV1ExportEntitiesResponse": { - "id": "GoogleDatastoreAdminV1ExportEntitiesResponse", - "description": "The response for google.datastore.admin.v1.DatastoreAdmin.ExportEntities.", - "type": "object", - "properties": { - "outputUrl": { - "description": "Location of the output metadata file. This can be used to begin an import into Cloud Datastore (this project or another project). See google.datastore.admin.v1.ImportEntitiesRequest.input_url. Only present if the operation completed successfully.", - "type": "string" - } - } - }, - "GoogleDatastoreAdminV1ImportEntitiesMetadata": { - "id": "GoogleDatastoreAdminV1ImportEntitiesMetadata", - "description": "Metadata for ImportEntities operations.", - "type": "object", - "properties": { - "common": { - "description": "Metadata common to all Datastore Admin operations.", - "$ref": "GoogleDatastoreAdminV1CommonMetadata" - }, - "progressEntities": { - "description": "An estimate of the number of entities processed.", - "$ref": "GoogleDatastoreAdminV1Progress" - }, - "progressBytes": { - "description": "An estimate of the number of bytes processed.", - "$ref": "GoogleDatastoreAdminV1Progress" - }, - "entityFilter": { - "description": "Description of which entities are being imported.", - "$ref": "GoogleDatastoreAdminV1EntityFilter" - }, - "inputUrl": { - "description": "The location of the import metadata file. This will be the same value as the google.datastore.admin.v1.ExportEntitiesResponse.output_url field.", - "type": "string" - } - } - }, - "GoogleDatastoreAdminV1IndexOperationMetadata": { - "id": "GoogleDatastoreAdminV1IndexOperationMetadata", - "description": "Metadata for Index operations.", - "type": "object", - "properties": { - "common": { - "description": "Metadata common to all Datastore Admin operations.", - "$ref": "GoogleDatastoreAdminV1CommonMetadata" - }, - "progressEntities": { - "description": "An estimate of the number of entities processed.", - "$ref": "GoogleDatastoreAdminV1Progress" - }, - "indexId": { - "description": "The index resource ID that this operation is acting on.", - "type": "string" - } - } - }, - "GoogleDatastoreAdminV1DatastoreFirestoreMigrationMetadata": { - "id": "GoogleDatastoreAdminV1DatastoreFirestoreMigrationMetadata", - "description": "Metadata for Datastore to Firestore migration operations. The DatastoreFirestoreMigration operation is not started by the end-user via an explicit \"creation\" method. This is an intentional deviation from the LRO design pattern. This singleton resource can be accessed at: \"projects/{project_id}/operations/datastore-firestore-migration\"", - "type": "object", - "properties": { - "migrationState": { - "description": "The current state of migration from Cloud Datastore to Cloud Firestore in Datastore mode.", - "type": "string", - "enumDescriptions": [ - "Unspecified.", - "The migration is running.", - "The migration is paused.", - "The migration is complete." - ], - "enum": [ - "MIGRATION_STATE_UNSPECIFIED", - "RUNNING", - "PAUSED", - "COMPLETE" - ] - }, - "migrationStep": { - "description": "The current step of migration from Cloud Datastore to Cloud Firestore in Datastore mode.", - "type": "string", - "enumDescriptions": [ - "Unspecified.", - "Pre-migration: the database is prepared for migration.", - "Start of migration.", - "Writes are applied synchronously to at least one replica.", - "Data is copied to Cloud Firestore and then verified to match the data in Cloud Datastore.", - "Eventually-consistent reads are redirected to Cloud Firestore.", - "Strongly-consistent reads are redirected to Cloud Firestore.", - "Writes are redirected to Cloud Firestore." - ], - "enum": [ - "MIGRATION_STEP_UNSPECIFIED", - "PREPARE", - "START", - "APPLY_WRITES_SYNCHRONOUSLY", - "COPY_AND_VERIFY", - "REDIRECT_EVENTUALLY_CONSISTENT_READS", - "REDIRECT_STRONGLY_CONSISTENT_READS", - "REDIRECT_WRITES" - ] - } - } - }, - "GoogleDatastoreAdminV1MigrationProgressEvent": { - "id": "GoogleDatastoreAdminV1MigrationProgressEvent", - "description": "An event signifying the start of a new step in a [migration from Cloud Datastore to Cloud Firestore in Datastore mode](https://cloud.google.com/datastore/docs/upgrade-to-firestore).", - "type": "object", - "properties": { - "step": { - "description": "The step that is starting. An event with step set to `START` indicates that the migration has been reverted back to the initial pre-migration state.", - "type": "string", - "enumDescriptions": [ - "Unspecified.", - "Pre-migration: the database is prepared for migration.", - "Start of migration.", - "Writes are applied synchronously to at least one replica.", - "Data is copied to Cloud Firestore and then verified to match the data in Cloud Datastore.", - "Eventually-consistent reads are redirected to Cloud Firestore.", - "Strongly-consistent reads are redirected to Cloud Firestore.", - "Writes are redirected to Cloud Firestore." - ], - "enum": [ - "MIGRATION_STEP_UNSPECIFIED", - "PREPARE", - "START", - "APPLY_WRITES_SYNCHRONOUSLY", - "COPY_AND_VERIFY", - "REDIRECT_EVENTUALLY_CONSISTENT_READS", - "REDIRECT_STRONGLY_CONSISTENT_READS", - "REDIRECT_WRITES" - ] - }, - "prepareStepDetails": { - "description": "Details for the `PREPARE` step.", - "$ref": "GoogleDatastoreAdminV1PrepareStepDetails" - }, - "redirectWritesStepDetails": { - "description": "Details for the `REDIRECT_WRITES` step.", - "$ref": "GoogleDatastoreAdminV1RedirectWritesStepDetails" - } - } - }, - "GoogleDatastoreAdminV1PrepareStepDetails": { - "id": "GoogleDatastoreAdminV1PrepareStepDetails", - "description": "Details for the `PREPARE` step.", - "type": "object", - "properties": { - "concurrencyMode": { - "description": "The concurrency mode this database will use when it reaches the `REDIRECT_WRITES` step.", - "type": "string", - "enumDescriptions": [ - "Unspecified.", - "Pessimistic concurrency.", - "Optimistic concurrency.", - "Optimistic concurrency with entity groups." - ], - "enum": [ - "CONCURRENCY_MODE_UNSPECIFIED", - "PESSIMISTIC", - "OPTIMISTIC", - "OPTIMISTIC_WITH_ENTITY_GROUPS" - ] - } - } - }, - "GoogleDatastoreAdminV1RedirectWritesStepDetails": { - "id": "GoogleDatastoreAdminV1RedirectWritesStepDetails", - "description": "Details for the `REDIRECT_WRITES` step.", - "type": "object", - "properties": { - "concurrencyMode": { - "description": "The concurrency mode for this database.", - "type": "string", - "enumDescriptions": [ - "Unspecified.", - "Pessimistic concurrency.", - "Optimistic concurrency.", - "Optimistic concurrency with entity groups." - ], - "enum": [ - "CONCURRENCY_MODE_UNSPECIFIED", - "PESSIMISTIC", - "OPTIMISTIC", - "OPTIMISTIC_WITH_ENTITY_GROUPS" - ] - } - } - }, - "GoogleDatastoreAdminV1MigrationStateEvent": { - "id": "GoogleDatastoreAdminV1MigrationStateEvent", - "description": "An event signifying a change in state of a [migration from Cloud Datastore to Cloud Firestore in Datastore mode](https://cloud.google.com/datastore/docs/upgrade-to-firestore).", - "type": "object", - "properties": { - "state": { - "description": "The new state of the migration.", - "type": "string", - "enumDescriptions": [ - "Unspecified.", - "The migration is running.", - "The migration is paused.", - "The migration is complete." - ], - "enum": [ - "MIGRATION_STATE_UNSPECIFIED", - "RUNNING", - "PAUSED", - "COMPLETE" - ] - } - } - } - }, - "auth": { - "oauth2": { - "scopes": { - "https://www.googleapis.com/auth/cloud-platform": { - "description": "See, edit, configure, and delete your Google Cloud data and see the email address for your Google Account." - }, - "https://www.googleapis.com/auth/datastore": { - "description": "View and manage your Google Cloud Datastore data" - } - } - } - }, - "name": "datastore", - "kind": "discovery#restDescription", - "ownerName": "Google", - "mtlsRootUrl": "https://datastore.mtls.googleapis.com/", - "ownerDomain": "google.com", - "revision": "20250524", - "baseUrl": "https://datastore.googleapis.com/", - "discoveryVersion": "v1", - "resources": { - "projects": { - "methods": { - "export": { - "id": "datastore.projects.export", - "path": "v1/projects/{projectId}:export", - "flatPath": "v1/projects/{projectId}:export", - "httpMethod": "POST", - "parameters": { - "projectId": { - "description": "Required. Project ID against which to make the request.", - "location": "path", - "required": true, - "type": "string" - } - }, - "parameterOrder": [ - "projectId" - ], - "request": { - "$ref": "GoogleDatastoreAdminV1ExportEntitiesRequest" - }, - "response": { - "$ref": "GoogleLongrunningOperation" - }, - "scopes": [ - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/datastore" - ], - "description": "Exports a copy of all or a subset of entities from Google Cloud Datastore to another storage system, such as Google Cloud Storage. Recent updates to entities may not be reflected in the export. The export occurs in the background and its progress can be monitored and managed via the Operation resource that is created. The output of an export may only be used once the associated operation is done. If an export operation is cancelled before completion it may leave partial data behind in Google Cloud Storage." - }, - "import": { - "id": "datastore.projects.import", - "path": "v1/projects/{projectId}:import", - "flatPath": "v1/projects/{projectId}:import", - "httpMethod": "POST", - "parameters": { - "projectId": { - "description": "Required. Project ID against which to make the request.", - "location": "path", - "required": true, - "type": "string" - } - }, - "parameterOrder": [ - "projectId" - ], - "request": { - "$ref": "GoogleDatastoreAdminV1ImportEntitiesRequest" - }, - "response": { - "$ref": "GoogleLongrunningOperation" - }, - "scopes": [ - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/datastore" - ], - "description": "Imports entities into Google Cloud Datastore. Existing entities with the same key are overwritten. The import occurs in the background and its progress can be monitored and managed via the Operation resource that is created. If an ImportEntities operation is cancelled, it is possible that a subset of the data has already been imported to Cloud Datastore." - }, - "lookup": { - "id": "datastore.projects.lookup", - "path": "v1/projects/{projectId}:lookup", - "flatPath": "v1/projects/{projectId}:lookup", - "httpMethod": "POST", - "parameters": { - "projectId": { - "description": "Required. The ID of the project against which to make the request.", - "location": "path", - "required": true, - "type": "string" - } - }, - "parameterOrder": [ - "projectId" - ], - "request": { - "$ref": "LookupRequest" - }, - "response": { - "$ref": "LookupResponse" - }, - "scopes": [ - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/datastore" - ], - "description": "Looks up entities by key." - }, - "runQuery": { - "id": "datastore.projects.runQuery", - "path": "v1/projects/{projectId}:runQuery", - "flatPath": "v1/projects/{projectId}:runQuery", - "httpMethod": "POST", - "parameters": { - "projectId": { - "description": "Required. The ID of the project against which to make the request.", - "location": "path", - "required": true, - "type": "string" - } - }, - "parameterOrder": [ - "projectId" - ], - "request": { - "$ref": "RunQueryRequest" - }, - "response": { - "$ref": "RunQueryResponse" - }, - "scopes": [ - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/datastore" - ], - "description": "Queries for entities." - }, - "runAggregationQuery": { - "id": "datastore.projects.runAggregationQuery", - "path": "v1/projects/{projectId}:runAggregationQuery", - "flatPath": "v1/projects/{projectId}:runAggregationQuery", - "httpMethod": "POST", - "parameters": { - "projectId": { - "description": "Required. The ID of the project against which to make the request.", - "location": "path", - "required": true, - "type": "string" - } - }, - "parameterOrder": [ - "projectId" - ], - "request": { - "$ref": "RunAggregationQueryRequest" - }, - "response": { - "$ref": "RunAggregationQueryResponse" - }, - "scopes": [ - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/datastore" - ], - "description": "Runs an aggregation query." - }, - "beginTransaction": { - "id": "datastore.projects.beginTransaction", - "path": "v1/projects/{projectId}:beginTransaction", - "flatPath": "v1/projects/{projectId}:beginTransaction", - "httpMethod": "POST", - "parameters": { - "projectId": { - "description": "Required. The ID of the project against which to make the request.", - "location": "path", - "required": true, - "type": "string" - } - }, - "parameterOrder": [ - "projectId" - ], - "request": { - "$ref": "BeginTransactionRequest" - }, - "response": { - "$ref": "BeginTransactionResponse" - }, - "scopes": [ - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/datastore" - ], - "description": "Begins a new transaction." - }, - "commit": { - "id": "datastore.projects.commit", - "path": "v1/projects/{projectId}:commit", - "flatPath": "v1/projects/{projectId}:commit", - "httpMethod": "POST", - "parameters": { - "projectId": { - "description": "Required. The ID of the project against which to make the request.", - "location": "path", - "required": true, - "type": "string" - } - }, - "parameterOrder": [ - "projectId" - ], - "request": { - "$ref": "CommitRequest" - }, - "response": { - "$ref": "CommitResponse" - }, - "scopes": [ - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/datastore" - ], - "description": "Commits a transaction, optionally creating, deleting or modifying some entities." - }, - "rollback": { - "id": "datastore.projects.rollback", - "path": "v1/projects/{projectId}:rollback", - "flatPath": "v1/projects/{projectId}:rollback", - "httpMethod": "POST", - "parameters": { - "projectId": { - "description": "Required. The ID of the project against which to make the request.", - "location": "path", - "required": true, - "type": "string" - } - }, - "parameterOrder": [ - "projectId" - ], - "request": { - "$ref": "RollbackRequest" - }, - "response": { - "$ref": "RollbackResponse" - }, - "scopes": [ - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/datastore" - ], - "description": "Rolls back a transaction." - }, - "allocateIds": { - "id": "datastore.projects.allocateIds", - "path": "v1/projects/{projectId}:allocateIds", - "flatPath": "v1/projects/{projectId}:allocateIds", - "httpMethod": "POST", - "parameters": { - "projectId": { - "description": "Required. The ID of the project against which to make the request.", - "location": "path", - "required": true, - "type": "string" - } - }, - "parameterOrder": [ - "projectId" - ], - "request": { - "$ref": "AllocateIdsRequest" - }, - "response": { - "$ref": "AllocateIdsResponse" - }, - "scopes": [ - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/datastore" - ], - "description": "Allocates IDs for the given keys, which is useful for referencing an entity before it is inserted." - }, - "reserveIds": { - "id": "datastore.projects.reserveIds", - "path": "v1/projects/{projectId}:reserveIds", - "flatPath": "v1/projects/{projectId}:reserveIds", - "httpMethod": "POST", - "parameters": { - "projectId": { - "description": "Required. The ID of the project against which to make the request.", - "location": "path", - "required": true, - "type": "string" - } - }, - "parameterOrder": [ - "projectId" - ], - "request": { - "$ref": "ReserveIdsRequest" - }, - "response": { - "$ref": "ReserveIdsResponse" - }, - "scopes": [ - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/datastore" - ], - "description": "Prevents the supplied keys' IDs from being auto-allocated by Cloud Datastore." - } - }, - "resources": { - "operations": { - "methods": { - "list": { - "id": "datastore.projects.operations.list", - "path": "v1/{+name}/operations", - "flatPath": "v1/projects/{projectsId}/operations", - "httpMethod": "GET", - "parameters": { - "name": { - "description": "The name of the operation's parent resource.", - "pattern": "^projects/[^/]+$", - "location": "path", - "required": true, - "type": "string" - }, - "filter": { - "description": "The standard list filter.", - "location": "query", - "type": "string" - }, - "pageSize": { - "description": "The standard list page size.", - "location": "query", - "type": "integer", - "format": "int32" - }, - "pageToken": { - "description": "The standard list page token.", - "location": "query", - "type": "string" - } - }, - "parameterOrder": [ - "name" - ], - "response": { - "$ref": "GoogleLongrunningListOperationsResponse" - }, - "scopes": [ - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/datastore" - ], - "description": "Lists operations that match the specified filter in the request. If the server doesn't support this method, it returns `UNIMPLEMENTED`." - }, - "get": { - "id": "datastore.projects.operations.get", - "path": "v1/{+name}", - "flatPath": "v1/projects/{projectsId}/operations/{operationsId}", - "httpMethod": "GET", - "parameters": { - "name": { - "description": "The name of the operation resource.", - "pattern": "^projects/[^/]+/operations/[^/]+$", - "location": "path", - "required": true, - "type": "string" - } - }, - "parameterOrder": [ - "name" - ], - "response": { - "$ref": "GoogleLongrunningOperation" - }, - "scopes": [ - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/datastore" - ], - "description": "Gets the latest state of a long-running operation. Clients can use this method to poll the operation result at intervals as recommended by the API service." - }, - "delete": { - "id": "datastore.projects.operations.delete", - "path": "v1/{+name}", - "flatPath": "v1/projects/{projectsId}/operations/{operationsId}", - "httpMethod": "DELETE", - "parameters": { - "name": { - "description": "The name of the operation resource to be deleted.", - "pattern": "^projects/[^/]+/operations/[^/]+$", - "location": "path", - "required": true, - "type": "string" - } - }, - "parameterOrder": [ - "name" - ], - "response": { - "$ref": "Empty" - }, - "scopes": [ - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/datastore" - ], - "description": "Deletes a long-running operation. This method indicates that the client is no longer interested in the operation result. It does not cancel the operation. If the server doesn't support this method, it returns `google.rpc.Code.UNIMPLEMENTED`." - }, - "cancel": { - "id": "datastore.projects.operations.cancel", - "path": "v1/{+name}:cancel", - "flatPath": "v1/projects/{projectsId}/operations/{operationsId}:cancel", - "httpMethod": "POST", - "parameters": { - "name": { - "description": "The name of the operation resource to be cancelled.", - "pattern": "^projects/[^/]+/operations/[^/]+$", - "location": "path", - "required": true, - "type": "string" - } - }, - "parameterOrder": [ - "name" - ], - "response": { - "$ref": "Empty" - }, - "scopes": [ - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/datastore" - ], - "description": "Starts asynchronous cancellation on a long-running operation. The server makes a best effort to cancel the operation, but success is not guaranteed. If the server doesn't support this method, it returns `google.rpc.Code.UNIMPLEMENTED`. Clients can use Operations.GetOperation or other methods to check whether the cancellation succeeded or whether the operation completed despite cancellation. On successful cancellation, the operation is not deleted; instead, it becomes an operation with an Operation.error value with a google.rpc.Status.code of `1`, corresponding to `Code.CANCELLED`." - } - } - }, - "indexes": { - "methods": { - "create": { - "id": "datastore.projects.indexes.create", - "path": "v1/projects/{projectId}/indexes", - "flatPath": "v1/projects/{projectId}/indexes", - "httpMethod": "POST", - "parameters": { - "projectId": { - "description": "Project ID against which to make the request.", - "location": "path", - "required": true, - "type": "string" - } - }, - "parameterOrder": [ - "projectId" - ], - "request": { - "$ref": "GoogleDatastoreAdminV1Index" - }, - "response": { - "$ref": "GoogleLongrunningOperation" - }, - "scopes": [ - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/datastore" - ], - "description": "Creates the specified index. A newly created index's initial state is `CREATING`. On completion of the returned google.longrunning.Operation, the state will be `READY`. If the index already exists, the call will return an `ALREADY_EXISTS` status. During index creation, the process could result in an error, in which case the index will move to the `ERROR` state. The process can be recovered by fixing the data that caused the error, removing the index with delete, then re-creating the index with create. Indexes with a single property cannot be created." - }, - "delete": { - "id": "datastore.projects.indexes.delete", - "path": "v1/projects/{projectId}/indexes/{indexId}", - "flatPath": "v1/projects/{projectId}/indexes/{indexId}", - "httpMethod": "DELETE", - "parameters": { - "projectId": { - "description": "Project ID against which to make the request.", - "location": "path", - "required": true, - "type": "string" - }, - "indexId": { - "description": "The resource ID of the index to delete.", - "location": "path", - "required": true, - "type": "string" - } - }, - "parameterOrder": [ - "projectId", - "indexId" - ], - "response": { - "$ref": "GoogleLongrunningOperation" - }, - "scopes": [ - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/datastore" - ], - "description": "Deletes an existing index. An index can only be deleted if it is in a `READY` or `ERROR` state. On successful execution of the request, the index will be in a `DELETING` state. And on completion of the returned google.longrunning.Operation, the index will be removed. During index deletion, the process could result in an error, in which case the index will move to the `ERROR` state. The process can be recovered by fixing the data that caused the error, followed by calling delete again." - }, - "get": { - "id": "datastore.projects.indexes.get", - "path": "v1/projects/{projectId}/indexes/{indexId}", - "flatPath": "v1/projects/{projectId}/indexes/{indexId}", - "httpMethod": "GET", - "parameters": { - "projectId": { - "description": "Project ID against which to make the request.", - "location": "path", - "required": true, - "type": "string" - }, - "indexId": { - "description": "The resource ID of the index to get.", - "location": "path", - "required": true, - "type": "string" - } - }, - "parameterOrder": [ - "projectId", - "indexId" - ], - "response": { - "$ref": "GoogleDatastoreAdminV1Index" - }, - "scopes": [ - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/datastore" - ], - "description": "Gets an index." - }, - "list": { - "id": "datastore.projects.indexes.list", - "path": "v1/projects/{projectId}/indexes", - "flatPath": "v1/projects/{projectId}/indexes", - "httpMethod": "GET", - "parameters": { - "projectId": { - "description": "Project ID against which to make the request.", - "location": "path", - "required": true, - "type": "string" - }, - "filter": { - "location": "query", - "type": "string" - }, - "pageSize": { - "description": "The maximum number of items to return. If zero, then all results will be returned.", - "location": "query", - "type": "integer", - "format": "int32" - }, - "pageToken": { - "description": "The next_page_token value returned from a previous List request, if any.", - "location": "query", - "type": "string" - } - }, - "parameterOrder": [ - "projectId" - ], - "response": { - "$ref": "GoogleDatastoreAdminV1ListIndexesResponse" - }, - "scopes": [ - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/datastore" - ], - "description": "Lists the indexes that match the specified filters. Datastore uses an eventually consistent query to fetch the list of indexes and may occasionally return stale results." - } - } - } - } - } - }, - "version_module": true, - "batchPath": "batch", - "description": "Accesses the schemaless NoSQL database to provide fully managed, robust, scalable storage for your application. ", - "fullyEncodeReservedExpansion": true, - "protocol": "rest", - "rootUrl": "https://datastore.googleapis.com/", - "version": "v1", - "id": "datastore:v1", - "icons": { - "x16": "http://www.google.com/images/icons/product/search-16.gif", - "x32": "http://www.google.com/images/icons/product/search-32.gif" - } -} \ No newline at end of file diff --git a/Datastore/src/DatastoreClient.php b/Datastore/src/DatastoreClient.php index 0d514dfc4391..3506527dff78 100644 --- a/Datastore/src/DatastoreClient.php +++ b/Datastore/src/DatastoreClient.php @@ -18,18 +18,20 @@ namespace Google\Cloud\Datastore; use DomainException; +use Google\ApiCore\Options\ClientOptions; use Google\Auth\FetchAuthTokenInterface; +use Google\Cloud\Core\ApiHelperTrait; use Google\Cloud\Core\ArrayTrait; use Google\Cloud\Core\ClientTrait; use Google\Cloud\Core\Int64; -use Google\Cloud\Datastore\Connection\ConnectionInterface; -use Google\Cloud\Datastore\Connection\Grpc; -use Google\Cloud\Datastore\Connection\Rest; +use Google\Cloud\Core\TimestampTrait; use Google\Cloud\Datastore\Query\AggregationQuery; use Google\Cloud\Datastore\Query\AggregationQueryResult; use Google\Cloud\Datastore\Query\GqlQuery; use Google\Cloud\Datastore\Query\Query; use Google\Cloud\Datastore\Query\QueryInterface; +use Google\Cloud\Datastore\V1\Client\DatastoreClient as GapicDatastoreClient; +use InvalidArgumentException; use Psr\Cache\CacheItemPoolInterface; use Psr\Http\Message\StreamInterface; @@ -87,20 +89,15 @@ */ class DatastoreClient { - use ArrayTrait; use ClientTrait; use DatastoreTrait; + use TimestampTrait; + use ApiHelperTrait; const VERSION = '1.34.0'; const FULL_CONTROL_SCOPE = 'https://www.googleapis.com/auth/datastore'; - /** - * @deprecated - * @var ConnectionInterface - */ - protected $connection; - /** * @var Operation */ @@ -111,25 +108,86 @@ class DatastoreClient */ private $entityMapper; + /** + * @var GapicDatastoreClient + */ + private GapicDatastoreClient $gapicClient; + /** * Create a Datastore client. * * @param array $config [optional] { * Configuration Options. + * Some of this options details on {@see ClientOptions}. * - * @type string $apiEndpoint A hostname with optional port to use in - * place of the service's default endpoint. * @type string $projectId The project ID from the Google Developer's * Console. - * @type CacheItemPoolInterface $authCache A cache for storing access - * tokens. **Defaults to** a simple in memory implementation. - * @type array $authCacheOptions Cache configuration options. - * @type callable $authHttpHandler A handler used to deliver Psr7 - * requests specifically for authentication. - * @type FetchAuthTokenInterface $credentialsFetcher A credentials - * fetcher instance. - * @type callable $httpHandler A handler used to deliver Psr7 requests. - * Only valid for requests sent over REST. + * @type string $namespaceId Partitions data under a namespace. Useful for + * [Multitenant Projects](https://cloud.google.com/datastore/docs/concepts/multitenancy). + * @type string $databaseId ID of the database to which the entities belong. + * @type bool $returnInt64AsObject If true, 64 bit integers will be + * returned as a {@see \Google\Cloud\Core\Int64} object for 32 bit + * platform compatibility. **Defaults to** false. + * @type GapicDatastoreClient $datastoreClient A client that is of + * type {@see GapicDatastoreClient} + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'datastore.googleapis.com:443'. + * @type FetchAuthTokenInterface|CredentialsWrapper $credentials + * This option should only be used with a pre-constructed + * {@see FetchAuthTokenInterface} or {@see CredentialsWrapper} object. Note that + * when one of these objects are provided, any settings in $credentialsConfig will + * be ignored. + * **Important**: If you are providing a path to a credentials file, or a decoded + * credentials file as a PHP array, this usage is now DEPRECATED. Providing an + * unvalidated credential configuration to Google APIs can compromise the security + * of your systems and data. It is recommended to create the credentials explicitly + * ``` + * use Google\Auth\Credentials\ServiceAccountCredentials; + * use Google\Cloud\Datastore\V1\DatastoreClient; + * $creds = new ServiceAccountCredentials($scopes, $json); + * $options = new DatastoreClient(['credentials' => $creds]); + * ``` + * {@see + * https://cloud.google.com/docs/authentication/external/externally-sourced-credentials} + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * @type false|LoggerInterface $logger + * A PSR-3 compliant logger. If set to false, logging is disabled, ignoring the + * 'GOOGLE_SDK_PHP_LOGGING' environment flag + * @type string $universeDomain + * The service domain for the client. Defaults to 'googleapis.com'. * @type array $keyFile [DEPRECATED] * @deprecated This option is being deprecated because of a potential security risk. * This option does not validate the credential configuration. The security @@ -174,26 +232,13 @@ class DatastoreClient * Regardless of the method used, it is always your responsibility to validate * configurations received from external sources. * @see https://cloud.google.com/docs/authentication/external/externally-sourced-credentials - * @type float $requestTimeout Seconds to wait before timing out the - * request. **Defaults to** `0` with REST and `60` with gRPC. - * @type int $retries Number of retries for a failed request. **Defaults - * to** `3`. - * @type array $scopes Scopes to be used for the request. - * @type string $quotaProject Specifies a user project to bill for - * access charges associated with the request. - * @type string $namespaceId Partitions data under a namespace. Useful for - * [Multitenant Projects](https://cloud.google.com/datastore/docs/concepts/multitenancy). - * @type string $databaseId ID of the database to which the entities belong. - * @type bool $returnInt64AsObject If true, 64 bit integers will be - * returned as a {@see \Google\Cloud\Core\Int64} object for 32 bit - * platform compatibility. **Defaults to** false. * } * @throws \InvalidArgumentException */ public function __construct(array $config = []) { $emulatorHost = getenv('DATASTORE_EMULATOR_HOST'); - + $this->validateConfigurationOptions($config); $connectionType = $this->getConnectionType($config); $config += [ @@ -207,9 +252,7 @@ public function __construct(array $config = []) ]; $config = $this->configureAuthentication($config); - $this->connection = $connectionType === 'grpc' - ? new Grpc($config) - : new Rest($config); + $this->gapicClient = $this->getGapicClient($config); // The second parameter here should change to a variable // when gRPC support is added for variable encoding. @@ -220,7 +263,7 @@ public function __construct(array $config = []) $connectionType ); $this->operation = new Operation( - $this->connection, + $this->gapicClient, $this->projectId, $config['namespaceId'], $this->entityMapper, @@ -562,7 +605,11 @@ public function allocateId(Key $key, array $options = []) * @see https://cloud.google.com/datastore/reference/rest/v1/projects/allocateIds allocateIds * * @param Key[] $keys The incomplete keys. - * @param array $options [optional] Configuration options. + * @param array $options [optional] { + * Configuration Options. + * + * string $databaseId The ID of the database against which to make the request. + * }. * @return Key[] */ public function allocateIds(array $keys, array $options = []) @@ -584,7 +631,6 @@ public function allocateIds(array $keys, array $options = []) * @codingStandardsIgnoreStart * @param array $options { * Configuration options. - * * @type array $transactionOptions Transaction configuration. See * [ReadWrite](https://cloud.google.com/datastore/docs/reference/rest/v1/projects/beginTransaction#ReadWrite). * @type string $databaseId ID of the database to which the entities belong. @@ -792,7 +838,7 @@ public function updateBatch(array $entities, array $options = []) 'allowOverwrite' => false ]; - $this->operation->checkOverwrite($entities, $options['allowOverwrite']); + $this->operation->checkOverwrite($entities, $this->pluck('allowOverwrite', $options)); $mutations = []; foreach ($entities as $entity) { $mutations[] = $this->operation->mutation('update', $entity, Entity::class); @@ -956,7 +1002,7 @@ public function deleteBatch(array $keys, array $options = []) $mutations = []; foreach ($keys as $key) { - $mutations[] = $this->operation->mutation('delete', $key, Key::class, $options['baseVersion']); + $mutations[] = $this->operation->mutation('delete', $key, Key::class, $this->pluck('baseVersion', $options, false)); } return $this->operation->commit($mutations, $options); @@ -1293,4 +1339,38 @@ private function parseSingleMutationResult(array $res) // cast to string for conformance between REST and gRPC. return (string) $mutationResult['version']; } + + private function getGapicClient(array $config): GapicDatastoreClient + { + if (isset($config['datastoreClient']) && (!$config['datastoreClient'] instanceof GapicDatastoreClient)) { + throw new InvalidArgumentException('The client configuration option must be an instance of ' . GapicDatastoreClient::class); + } + + return $config['datastoreClient'] ?? new GapicDatastoreClient($config); + } + + private function validateConfigurationOptions(array $config): void + { + $availableOptions = [ + 'projectId', + 'namespaceId', + 'databaseId', + 'returnInt64AsObject', + 'datastoreClient', + 'apiEndpoint', + 'credentials', + 'credentialsConfig', + 'disableRetries', + 'clientConfig', + 'transport', + 'transportConfig', + 'clientCertSource', + 'logger', + 'universeDomain', + 'keyFile', + 'keyFilePath', + ]; + + $this->validateOptions($config, $availableOptions); + } } diff --git a/Datastore/src/EntityMapper.php b/Datastore/src/EntityMapper.php index 17f75930c0e0..5ae2c70b0923 100644 --- a/Datastore/src/EntityMapper.php +++ b/Datastore/src/EntityMapper.php @@ -222,14 +222,26 @@ public function convertValue($type, $value, $className = Entity::class) break; case 'timestampValue': - $result = \DateTimeImmutable::createFromFormat(self::DATE_FORMAT, $value); + if (is_array($value)) { + // The Serializer converts timestamps to an array [seconds, nanos]. + // This code is taking that format to convert it into an Immutable date. + $seconds = $value['seconds']; + $nanos = $value['nanos'] ?? 0; + $microseconds = (int)($nanos / 1000); + $result = \DateTimeImmutable::createFromFormat( + 'U.u', + sprintf('%d.%06d', $seconds, $microseconds) + ); + } else { + // This is to keep compatibility with the previous implementation + $result = \DateTimeImmutable::createFromFormat(self::DATE_FORMAT, $value); - if (!$result) { - $result = \DateTimeImmutable::createFromFormat(self::DATE_FORMAT_NO_MS, $value); + if (!$result) { + $result = \DateTimeImmutable::createFromFormat(self::DATE_FORMAT_NO_MS, $value); + } } break; - case 'keyValue': $namespaceId = (isset($value['partitionId']['namespaceId'])) ? $value['partitionId']['namespaceId'] @@ -355,18 +367,14 @@ public function valueObject($value, $exclude = false, $meaning = null) break; case 'double': - // The mappings happen automatically for grpc hence - // this is required only incase of rest as grpc - // doesn't recognises 'Infinity', '-Infinity' and 'NaN'. - if ($this->connectionType == 'rest') { - if ($value == INF) { - $value = 'Infinity'; - } elseif ($value == -INF) { - $value = '-Infinity'; - } elseif (is_nan($value)) { - $value = 'NaN'; - } + if ($value == INF) { + $value = 'Infinity'; + } elseif ($value == -INF) { + $value = '-Infinity'; + } elseif (is_nan($value)) { + $value = 'NaN'; } + $propertyValue = [ 'doubleValue' => $value ]; diff --git a/Datastore/src/Operation.php b/Datastore/src/Operation.php index 4030c760ee84..1ccfbaaf9b62 100644 --- a/Datastore/src/Operation.php +++ b/Datastore/src/Operation.php @@ -17,16 +17,35 @@ namespace Google\Cloud\Datastore; +use Google\ApiCore\Options\CallOptions; +use Google\ApiCore\Serializer; +use Google\Cloud\Core\ApiHelperTrait; use Google\Cloud\Core\Timestamp; use Google\Cloud\Core\TimestampTrait; use Google\Cloud\Core\ValidateTrait; -use Google\Cloud\Datastore\Connection\ConnectionInterface; use Google\Cloud\Datastore\Query\AggregationQuery; use Google\Cloud\Datastore\Query\AggregationQueryResult; use Google\Cloud\Datastore\Query\Query; use Google\Cloud\Datastore\Query\QueryInterface; +use Google\Cloud\Datastore\V1\AllocateIdsRequest; +use Google\Cloud\Datastore\V1\BeginTransactionRequest; use Google\Cloud\Datastore\V1\ExplainOptions; use Google\Cloud\Datastore\V1\QueryResultBatch\MoreResultsType; +use Google\Cloud\Datastore\V1\Client\DatastoreClient; +use Google\Cloud\Datastore\V1\CommitRequest; +use Google\Cloud\Datastore\V1\CommitRequest\Mode; +use Google\Cloud\Datastore\V1\EntityResult; +use Google\Cloud\Datastore\V1\Key as ProtobufKey; +use Google\Cloud\Datastore\V1\LookupRequest; +use Google\Cloud\Datastore\V1\Mutation; +use Google\Cloud\Datastore\V1\ReadOptions; +use Google\Cloud\Datastore\V1\ReadOptions_ReadConsistency; +use Google\Cloud\Datastore\V1\RollbackRequest; +use Google\Cloud\Datastore\V1\RunAggregationQueryRequest; +use Google\Cloud\Datastore\V1\RunQueryRequest; +use Google\Cloud\Datastore\V1\TransactionOptions; +use Google\Protobuf\RepeatedField; +use Google\Protobuf\Timestamp as ProtobufTimestamp; use InvalidArgumentException; /** @@ -45,12 +64,13 @@ class Operation use DatastoreTrait; use ValidateTrait; use TimestampTrait; + use ApiHelperTrait; /** - * @var ConnectionInterface + * @var DatastoreClient * @internal */ - protected $connection; + protected DatastoreClient $gapicClient; /** * @var string @@ -72,29 +92,47 @@ class Operation */ private $entityMapper; + /** + * @var Serializer + */ + private Serializer $serializer; + /** * Create an operation * - * @param ConnectionInterface $connection A connection to Google Cloud Platform's Datastore API. - * This object is created by DatastoreClient, - * and should not be instantiated outside of this client. + * @param DatastoreClient $gapicClient A Datastore Gapic Client instance. * @param string $projectId The Google Cloud Platform project ID. * @param string $namespaceId The namespace to use for all service requests. * @param EntityMapper $entityMapper A Datastore Entity Mapper instance. * @param string $databaseId ID of the database to which the entities belong. */ public function __construct( - ConnectionInterface $connection, + DatastoreClient $gapicClient, $projectId, $namespaceId, EntityMapper $entityMapper, $databaseId = '' ) { - $this->connection = $connection; + $this->gapicClient = $gapicClient; $this->projectId = $projectId; $this->namespaceId = $namespaceId; $this->databaseId = $databaseId; $this->entityMapper = $entityMapper; + $this->serializer = new Serializer([ + 'end_cursor' => function ($v) { + return base64_encode($v); + }, + 'start_cursor' => function ($v) { + return base64_encode($v); + }, + 'cursor' => function ($v) { + return base64_encode($v); + } + ],[ + 'google.protobuf.Duration' => function ($v) { + return $this->formatDurationFromApi($v); + } + ]); } /** @@ -269,26 +307,37 @@ public function entity($key = null, array $entity = [], array $options = []) * * @param array $transactionOptions * [Transaction Options](https://cloud.google.com/datastore/docs/reference/data/rest/v1/projects/beginTransaction#TransactionOptions) - * @param array $options Configuration options. + * @param array $options { + * Configuration Options. + * + * string $databaseId The ID of the database against which to make the request. + * } * @return string */ public function beginTransaction($transactionOptions, array $options = []) { - // Read Only option might not be present or empty - if (isset($transactionOptions['readOnly']) && - is_array($transactionOptions['readOnly']) - ) { - $transactionOptions['readOnly'] = $this->formatReadTimeOption( - $transactionOptions['readOnly'] - ); - } - $res = $this->connection->beginTransaction($options + [ + $protoTransactionOptions = new TransactionOptions(); + $protoTransactionOptions->mergeFromJsonString(json_encode($transactionOptions)); + + $requestOptions = [ + 'databaseId' => $options['databaseId'] ?? $this->databaseId, 'projectId' => $this->projectId, - 'databaseId' => $this->databaseId, - 'transactionOptions' => $transactionOptions, - ]); + 'transactionOptions' => $transactionOptions + ] + $options; + + /** + * @var BegintransactionRequest $beginTransactionRequest + * @var CallOptions $callOptions + */ + [$beginTransactionRequest, $callOptions] = $this->validateOptions( + $requestOptions, + new BeginTransactionRequest(), + CallOptions::class + ); - return $res['transaction']; + $res = $this->gapicClient->beginTransaction($beginTransactionRequest, $callOptions); + + return base64_encode($res->getTransaction()); } /** @@ -302,7 +351,11 @@ public function beginTransaction($transactionOptions, array $options = []) * @see https://cloud.google.com/datastore/reference/rest/v1/projects/allocateIds allocateIds * * @param Key[] $keys The incomplete keys. - * @param array $options [optional] Configuration Options. + * @param array $options [optional] { + * Configuration Options + * + * @type string $databaseId The ID of the database against which to make the request. + * }. * @return Key[] * @throws \InvalidArgumentException */ @@ -322,27 +375,39 @@ public function allocateIds(array $keys, array $options = []) } }); + $requestOptions = [ + 'projectId' => $this->projectId, + 'databaseId' => $options['databaseId'] ?? $this->databaseId, + ] + $options; + $serviceKeys = []; foreach ($keys as $key) { $serviceKeys[] = $key->keyObject(); } - $res = $this->connection->allocateIds($options + [ - 'projectId' => $this->projectId, - 'databaseId' => $this->databaseId, - 'keys' => $serviceKeys, - ]); + $requestOptions['keys'] = $serviceKeys; - if (isset($res['keys'])) { - foreach ($res['keys'] as $index => $key) { - if (!isset($keys[$index])) { - continue; - } + /** + * @var AllocateIdsRequest $allocateIdsRequest + * @var CallOptions $callOptions + */ + [$allocateIdsRequest, $callOptions] = $this->validateOptions( + $requestOptions, + new AllocateIdsRequest(), + CallOptions::class + ); - $end = end($key['path']); - $id = $end['id']; - $keys[$index]->setLastElementIdentifier($id); - } + $allocateIdsResponse = $this->gapicClient->allocateIds($allocateIdsRequest, $callOptions); + + /** @var protobufKey $responseKey */ + foreach ($allocateIdsResponse->getKeys() as $index => $responseKey) { + $path = $responseKey->getPath(); + + // @phpstan-ignore argument.type + $lastPathElement = count($path) - 1; + + $id = $path[$lastPathElement]->getId(); + $keys[$index]->setLastElementIdentifier($id); } return $keys; @@ -379,9 +444,12 @@ public function allocateIds(array $keys, array $options = []) */ public function lookup(array $keys, array $options = []) { + $className = $this->pluck('className', $options, false) ?? Entity::class; + $sort = $this->pluck('sort', $options, false) ?? false; + $options += [ - 'className' => Entity::class, - 'sort' => false, + 'databaseId' => $options['databaseId'] ?? $this->databaseId, + 'projectId' => $this->projectId, ]; $serviceKeys = []; @@ -396,46 +464,65 @@ public function lookup(array $keys, array $options = []) $serviceKeys[] = $key->keyObject(); }); + $options['keys'] = $serviceKeys; + + $readOptions = $this->createReadOptions($this->pluckArray( + [ + 'readConsistency', + 'transaction', + 'readTime' + ], + $options, + false + )); + + /** + * @var LookupRequest $lookupRequest + * @var CallOptions $callOptions + */ + [$lookupRequest, $callOptions] = $this->validateOptions( + $options, + new LookupRequest(), + CallOptions::class + ); - $res = $this->connection->lookup($options + $this->readOptions($options) + [ - 'projectId' => $this->projectId, - 'databaseId' => $this->databaseId, - 'keys' => $serviceKeys, - ]); + if ($readOptions) { + $lookupRequest->setReadOptions($readOptions); + } - $result = []; - if (isset($res['found'])) { - foreach ($res['found'] as $found) { - $result['found'][] = $this->mapEntityResult($found, $options['className']); - } + $lookupResponse = $this->gapicClient->lookup($lookupRequest, $callOptions); - if ($options['sort']) { - $result['found'] = $this->sortEntities($result['found'], $keys); - } - } + $result = [ + 'result' => [], + 'missing' => [], + 'deferred' => [], + ]; - if (isset($res['missing'])) { - $result['missing'] = []; - foreach ($res['missing'] as $missing) { - $key = $this->key( - $missing['entity']['key']['path'], - $missing['entity']['key']['partitionId'] - ); + /** @var protoEntity $found */ + foreach ($lookupResponse->getFound() as $found) { + $result['found'][] = $this->mapEntityResult( + $this->serializer->encodeMessage($found), $className + ); + } - $result['missing'][] = $key; - } + if (!empty($sort)) { + $result['found'] = $this->sortEntities($result['found'], $keys); } - if (isset($res['deferred'])) { - $result['deferred'] = []; - foreach ($res['deferred'] as $deferred) { - $key = $this->key( - $deferred['path'], - $deferred['partitionId'] - ); + /** @var entityResult $missing*/ + foreach ($lookupResponse->getMissing() as $missing) { + $result['missing'][] = $this->key( + $missing->getEntity()->getKey()->getPath(), + $missing->getEntity()->getKey()->getPartitionId() + ); + } - $result['deferred'][] = $key; - } + /** @var protobufKey $deferred */ + foreach ($lookupResponse->getDeferred() as $deferred) { + $result['deferred'][] = $this->key( + $deferred->getPath(), + $deferred->getPartitionId() + ); } return $result; @@ -466,8 +553,8 @@ public function lookup(array $keys, array $options = []) */ public function runQuery(QueryInterface $query, array $options = []) { + $className = $this->pluck('className', $options, false) ?? Entity::class; $options += [ - 'className' => Entity::class, 'namespaceId' => $this->namespaceId, 'databaseId' => $this->databaseId, ]; @@ -509,17 +596,52 @@ public function runQuery(QueryInterface $query, array $options = []) if (isset($remainingLimit)) { $requestQueryArr['limit'] = $remainingLimit; } + + $readOptions = $this->createReadOptions($this->pluckArray( + [ + 'readConsistency', + 'transaction', + 'readTime' + ], + $options + )); + + $databaseId = $this->pluck('databaseId', $options); + $request = [ + 'databaseId' => $databaseId, 'projectId' => $this->projectId, 'partitionId' => $this->partitionId( $this->projectId, - $options['namespaceId'], - $options['databaseId'] + $this->pluck('namespaceId', $options), + $databaseId ), $runQueryObj->queryKey() => $requestQueryArr, - ] + $this->readOptions($options) + $options; + ] + $options; + + $explainOptions = $this->pluck('explainOptions', $request, false); + + /** + * @var RunQueryRequest $runQueryRequest + * @var CallOptions $callOptions + */ + [$runQueryRequest, $callOptions] = $this->validateOptions( + $request, + new RunQueryRequest(), + CallOptions::class + ); + + if (!empty($explainOptions)) { + $runQueryRequest->setExplainOptions($explainOptions); + } + + if (!empty($readOptions)) { + $runQueryRequest->setReadOptions($readOptions); + } + + $runQueryResponse = $this->gapicClient->runQuery($runQueryRequest, $callOptions); - $res = $this->connection->runQuery($request); + $res = $this->serializer->encodeMessage($runQueryResponse); // When executing a GQL Query, the server will compute a query object // and return it with the first response batch. @@ -548,8 +670,8 @@ public function runQuery(QueryInterface $query, array $options = []) return new EntityIterator( new EntityPageIterator( - function (array $entityResult) use ($options) { - return $this->mapEntityResult($entityResult, $options['className']); + function (array $entityResult) use ($className) { + return $this->mapEntityResult($entityResult, $className); }, $runQueryFn, [], @@ -571,36 +693,64 @@ function (array $entityResult) use ($options) { * [ReadConsistency](https://cloud.google.com/datastore/reference/rest/v1/ReadOptions#ReadConsistency). * @type string $databaseId ID of the database to which the entities belong. * @type Timestamp $readTime Reads entities as they were at the given timestamp. + * @type ExplainOptions $explainOptions An ExplainOptions object to get the execution stats + * {@see ExplainOptions} * } * @return AggregationQueryResult */ public function runAggregationQuery(AggregationQuery $runQueryObj, array $options = []) { $options += [ - 'namespaceId' => $this->namespaceId, - 'databaseId' => $this->databaseId, - ]; - - if (isset($options['explainOptions']) && !$options['explainOptions'] instanceof ExplainOptions) { - throw new InvalidArgumentException( - 'The explainOptions option needs to be an instance of the ExplainOptions class' - ); - } - - $args = [ - 'query' => [], - ]; - $requestQueryArr = $args['query'] + $runQueryObj->queryObject(); - $request = [ 'projectId' => $this->projectId, + 'databaseId' => $this->databaseId, 'partitionId' => $this->partitionId( $this->projectId, - $options['namespaceId'], - $options['databaseId'] + $this->namespaceId, + $this->databaseId ), - ] + $requestQueryArr + $this->readOptions($options) + $options; + ] + $runQueryObj->queryObject(); + + $pluckedReadOptions = $this->pluckArray( + [ + 'readConsistency', + 'transaction', + 'readTime' + ], + $options + ); + + /** + * @var RunAggregationQueryRequest $runAggregationQueryRequest + * @var CallOptions $callOptions + */ + [$runAggregationQueryRequest, $callOptions] = $this->validateOptions( + $options, + new RunAggregationQueryRequest(), + CallOptions::class + ); + + // Setting the readOptions as validateOptions is not able to serialize a Message type + $explainOptions = $this->pluck('explainOptions', $options, false); + if (!empty($explainOptions)) { + if (!$explainOptions instanceof ExplainOptions) { + throw new InvalidArgumentException( + 'The explainOptions option needs to be an instance of the ExplainOptions class' + ); + } + + $runAggregationQueryRequest->setExplainOptions($explainOptions); + } + + $readOptions = $this->createReadOptions($pluckedReadOptions); + + if (!empty($readOptions)) { + $runAggregationQueryRequest->setReadOptions($readOptions); + } + + $runAggregationQueryResponse = $this->gapicClient->runAggregationQuery($runAggregationQueryRequest, $callOptions); + + $res = $this->serializer->encodeMessage($runAggregationQueryResponse); - $res = $this->connection->runAggregationQuery($request); return new AggregationQueryResult($res, $this->entityMapper); } @@ -625,17 +775,30 @@ public function runAggregationQuery(AggregationQuery $runQueryObj, array $option public function commit(array $mutations, array $options = []) { $options += [ - 'transaction' => null, 'databaseId' => $this->databaseId, + 'projectId' => $this->projectId, + 'mutations' => $mutations, ]; - $res = $this->connection->commit($options + [ - 'mode' => ($options['transaction']) ? 'TRANSACTIONAL' : 'NON_TRANSACTIONAL', - 'mutations' => $mutations, - 'projectId' => $this->projectId, - ]); + /** + * @var CallOptions $callOptions + * @var CommitRequest $commitRequest + */ + [$commitRequest, $callOptions] = $this->validateOptions( + $options, + new CommitRequest(), + CallOptions::class, + ); + + $commitRequest->setMode( + empty($commitRequest->getTransaction()) + ? MODE::NON_TRANSACTIONAL + : MODE::TRANSACTIONAL + ); - return $res; + $commitResponse = $this->gapicClient->commit($commitRequest, $callOptions); + + return $this->serializer->encodeMessage($commitResponse); } /** @@ -725,11 +888,12 @@ public function mutation( */ public function rollback($transactionId) { - $this->connection->rollback([ - 'projectId' => $this->projectId, - 'transaction' => $transactionId, - 'databaseId' => $this->databaseId, - ]); + $rollbackRequest = (new RollbackRequest()) + ->setProjectId($this->projectId) + ->setDatabaseId($this->databaseId) + ->setTransaction(base64_decode($transactionId)); + + $this->gapicClient->rollback($rollbackRequest); } /** @@ -816,7 +980,7 @@ private function mapEntityResult(array $result, $class) } return $this->entity($key, $properties, [ - 'cursor' => (isset($result['cursor'])) + 'cursor' => !empty($result['cursor']) ? $result['cursor'] : null, 'baseVersion' => (isset($result['version'])) @@ -829,40 +993,6 @@ private function mapEntityResult(array $result, $class) ]); } - /** - * Format the readOptions - * - * @param array $options [optional] { - * Read Options - * - * @type string $transaction If set, query or lookup will run in transaction. - * @type string $readConsistency See - * [ReadConsistency](https://cloud.google.com/datastore/reference/rest/v1/ReadOptions#ReadConsistency). - * @type Timestamp $readTime Reads entities as they were at the given timestamp. - * } - * @return array - */ - private function readOptions(array $options = []) - { - $options += [ - 'readConsistency' => null, - 'transaction' => null, - 'readTime' => null - ]; - - $options = $this->formatReadTimeOption($options); - - $readOptions = array_filter([ - 'readConsistency' => $options['readConsistency'], - 'transaction' => $options['transaction'], - 'readTime' => $options['readTime'] - ]); - - return array_filter([ - 'readOptions' => $readOptions, - ]); - } - /** * Sort entities into the order given in $keys. * @@ -886,4 +1016,56 @@ private function sortEntities(array $entities, array $keys) return $ret; } + + /** + * Create a ReadOptions object from an options array. + * + * @param array $options The options. + * @return null|ReadOptions + */ + private function createReadOptions(array $options) + { + $totalSet = 0; + + $readOptions = new ReadOptions(); + if (isset($options['transaction'])) { + $totalSet++; + $readOptions->setTransaction(base64_decode($options['transaction'])); + } + if (isset($options['readConsistency'])) { + $totalSet++; + $readOptions->setReadConsistency($options['readConsistency']); + } + if (isset($options['readTime'])) { + $totalSet++; + $protoTime = new ProtobufTimestamp(); + // Timestamps can be passed as an array or a Timestamp object. + $protoTime->mergeFromJsonString(json_encode($options['readTime'])); + $readOptions->setReadTime($protoTime); + } + + if ($totalSet === 0) { + return null; + } + + if ($totalSet > 1) { + throw new InvalidArgumentException('Only one of `readConsistency`, `transaction` or `readTime` may be set.'); + } + + return $readOptions; + } + + /** + * Format a duration from the API + * + * @param array $value + * @return string + */ + private function formatDurationFromApi($value): string + { + $seconds = $value['seconds']; + $nanos = str_pad($value['nanos'], 9, 0, STR_PAD_LEFT); + + return "{$seconds}.{$nanos}s"; + } } diff --git a/Datastore/src/Transaction.php b/Datastore/src/Transaction.php index 39c0ba015444..2769831b944b 100644 --- a/Datastore/src/Transaction.php +++ b/Datastore/src/Transaction.php @@ -350,6 +350,15 @@ public function deleteBatch(array $keys) */ public function commit(array $options = []) { + if (empty($this->mutations)) { + $this->operation->rollback($this->transactionId); + + return [ + 'mutationResults' => [], + 'indexUpdates' => 0 + ]; + } + $options['transaction'] = $this->transactionId; return $this->operation->commit($this->mutations, $options); diff --git a/Datastore/src/TransactionTrait.php b/Datastore/src/TransactionTrait.php index b30176e54f89..667417bf0399 100644 --- a/Datastore/src/TransactionTrait.php +++ b/Datastore/src/TransactionTrait.php @@ -19,6 +19,7 @@ use Google\Cloud\Datastore\Query\AggregationQuery; use Google\Cloud\Datastore\Query\QueryInterface; +use InvalidArgumentException; /** * Common operations for datastore transactions. @@ -126,6 +127,13 @@ public function lookup(Key $key, array $options = []) */ public function lookupBatch(array $keys, array $options = []) { + if (isset($options['readTime']) || isset($options['readConsistency']) || isset($options['newTransaction'])) { + throw new InvalidArgumentException( + 'Transaction::lookup and Transaction::batchLookup methods ' . + 'do not take a `readTime`, `readConsistency` or `newTransaction` option.' + ); + } + return $this->operation->lookup($keys, $options + [ 'transaction' => $this->transactionId ]); diff --git a/Datastore/src/V1/AggregationQuery/Aggregation.php b/Datastore/src/V1/AggregationQuery/Aggregation.php index fb137d823817..fc4726e49d0a 100644 --- a/Datastore/src/V1/AggregationQuery/Aggregation.php +++ b/Datastore/src/V1/AggregationQuery/Aggregation.php @@ -48,7 +48,7 @@ class Aggregation extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string alias = 7 [(.google.api.field_behavior) = OPTIONAL]; */ - private $alias = ''; + protected $alias = ''; protected $operator; /** @@ -285,6 +285,4 @@ public function getOperator() } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(Aggregation::class, \Google\Cloud\Datastore\V1\AggregationQuery_Aggregation::class); diff --git a/Datastore/src/V1/AggregationQuery/Aggregation/Avg.php b/Datastore/src/V1/AggregationQuery/Aggregation/Avg.php index b5ec942bdb28..250cb1cbe8b5 100644 --- a/Datastore/src/V1/AggregationQuery/Aggregation/Avg.php +++ b/Datastore/src/V1/AggregationQuery/Aggregation/Avg.php @@ -26,7 +26,7 @@ class Avg extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.datastore.v1.PropertyReference property = 1; */ - private $property = null; + protected $property = null; /** * Constructor. @@ -81,6 +81,4 @@ public function setProperty($var) } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(Avg::class, \Google\Cloud\Datastore\V1\AggregationQuery_Aggregation_Avg::class); diff --git a/Datastore/src/V1/AggregationQuery/Aggregation/Count.php b/Datastore/src/V1/AggregationQuery/Aggregation/Count.php index b4eefb58afb6..7d1e8f213080 100644 --- a/Datastore/src/V1/AggregationQuery/Aggregation/Count.php +++ b/Datastore/src/V1/AggregationQuery/Aggregation/Count.php @@ -34,7 +34,7 @@ class Count extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.protobuf.Int64Value up_to = 1 [(.google.api.field_behavior) = OPTIONAL]; */ - private $up_to = null; + protected $up_to = null; /** * Constructor. @@ -116,7 +116,7 @@ public function clearUpTo() * Generated from protobuf field .google.protobuf.Int64Value up_to = 1 [(.google.api.field_behavior) = OPTIONAL]; * @return int|string|null */ - public function getUpToValue() + public function getUpToUnwrapped() { return $this->readWrapperValue("up_to"); } @@ -169,13 +169,11 @@ public function setUpTo($var) * @param int|string|null $var * @return $this */ - public function setUpToValue($var) + public function setUpToUnwrapped($var) { $this->writeWrapperValue("up_to", $var); return $this;} } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(Count::class, \Google\Cloud\Datastore\V1\AggregationQuery_Aggregation_Count::class); diff --git a/Datastore/src/V1/AggregationQuery/Aggregation/Sum.php b/Datastore/src/V1/AggregationQuery/Aggregation/Sum.php index f881817905a6..54befb080e65 100644 --- a/Datastore/src/V1/AggregationQuery/Aggregation/Sum.php +++ b/Datastore/src/V1/AggregationQuery/Aggregation/Sum.php @@ -35,7 +35,7 @@ class Sum extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.datastore.v1.PropertyReference property = 1; */ - private $property = null; + protected $property = null; /** * Constructor. @@ -90,6 +90,4 @@ public function setProperty($var) } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(Sum::class, \Google\Cloud\Datastore\V1\AggregationQuery_Aggregation_Sum::class); diff --git a/Datastore/src/V1/AggregationQuery_Aggregation.php b/Datastore/src/V1/AggregationQuery_Aggregation.php deleted file mode 100644 index d37da97cdbc1..000000000000 --- a/Datastore/src/V1/AggregationQuery_Aggregation.php +++ /dev/null @@ -1,16 +0,0 @@ -.google.datastore.v1.QueryResultBatch.MoreResultsType more_results = 2; */ - private $more_results = 0; + protected $more_results = 0; /** * Read timestamp this batch was returned from. * In a single transaction, subsequent query result batches for the same query @@ -37,7 +37,7 @@ class AggregationResultBatch extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.protobuf.Timestamp read_time = 3; */ - private $read_time = null; + protected $read_time = null; /** * Constructor. diff --git a/Datastore/src/V1/AllocateIdsRequest.php b/Datastore/src/V1/AllocateIdsRequest.php index 79b3ea32269e..df1f2e88eb08 100644 --- a/Datastore/src/V1/AllocateIdsRequest.php +++ b/Datastore/src/V1/AllocateIdsRequest.php @@ -21,7 +21,7 @@ class AllocateIdsRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string project_id = 8 [(.google.api.field_behavior) = REQUIRED]; */ - private $project_id = ''; + protected $project_id = ''; /** * The ID of the database against which to make the request. * '(default)' is not allowed; please use empty string '' to refer the default @@ -29,7 +29,7 @@ class AllocateIdsRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string database_id = 9; */ - private $database_id = ''; + protected $database_id = ''; /** * Required. A list of keys with incomplete key paths for which to allocate * IDs. No key may be reserved/read-only. diff --git a/Datastore/src/V1/BeginTransactionRequest.php b/Datastore/src/V1/BeginTransactionRequest.php index a14f0a36473c..03c7ca69e5e0 100644 --- a/Datastore/src/V1/BeginTransactionRequest.php +++ b/Datastore/src/V1/BeginTransactionRequest.php @@ -21,7 +21,7 @@ class BeginTransactionRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string project_id = 8 [(.google.api.field_behavior) = REQUIRED]; */ - private $project_id = ''; + protected $project_id = ''; /** * The ID of the database against which to make the request. * '(default)' is not allowed; please use empty string '' to refer the default @@ -29,13 +29,13 @@ class BeginTransactionRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string database_id = 9; */ - private $database_id = ''; + protected $database_id = ''; /** * Options for a new transaction. * * Generated from protobuf field .google.datastore.v1.TransactionOptions transaction_options = 10; */ - private $transaction_options = null; + protected $transaction_options = null; /** * @param string $projectId Required. The ID of the project against which to make the request. diff --git a/Datastore/src/V1/BeginTransactionResponse.php b/Datastore/src/V1/BeginTransactionResponse.php index 28e59fc67bee..09b15c04119b 100644 --- a/Datastore/src/V1/BeginTransactionResponse.php +++ b/Datastore/src/V1/BeginTransactionResponse.php @@ -21,7 +21,7 @@ class BeginTransactionResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field bytes transaction = 1; */ - private $transaction = ''; + protected $transaction = ''; /** * Constructor. diff --git a/Datastore/src/V1/Client/DatastoreClient.php b/Datastore/src/V1/Client/DatastoreClient.php index 598cf77a204b..35db4f7e7562 100644 --- a/Datastore/src/V1/Client/DatastoreClient.php +++ b/Datastore/src/V1/Client/DatastoreClient.php @@ -1,6 +1,6 @@ :". Default 'datastore.googleapis.com:443'. - * @type FetchAuthTokenInterface|CredentialsWrapper $credentials - * This option should only be used with a pre-constructed - * {@see FetchAuthTokenInterface} or {@see CredentialsWrapper} object. Note that - * when one of these objects are provided, any settings in $credentialsConfig will - * be ignored. - * **Important**: If you are providing a path to a credentials file, or a decoded - * credentials file as a PHP array, this usage is now DEPRECATED. Providing an - * unvalidated credential configuration to Google APIs can compromise the security - * of your systems and data. It is recommended to create the credentials explicitly - * ``` - * use Google\Auth\Credentials\ServiceAccountCredentials; - * use Google\Cloud\Datastore\V1\DatastoreClient; - * $creds = new ServiceAccountCredentials($scopes, $json); - * $options = new DatastoreClient(['credentials' => $creds]); - * ``` - * {@see + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * *Important*: If you accept a credential configuration (credential + * JSON/File/Stream) from an external source for authentication to Google Cloud + * Platform, you must validate it before providing it to any Google API or library. + * Providing an unvalidated credential configuration to Google APIs can compromise + * the security of your systems and data. For more information {@see * https://cloud.google.com/docs/authentication/external/externally-sourced-credentials} * @type array $credentialsConfig * Options used to configure credentials, including auth token caching, for the @@ -254,8 +251,10 @@ public function allocateIds(AllocateIdsRequest $request, array $callOptions = [] * * @throws ApiException Thrown if the API call fails. */ - public function beginTransaction(BeginTransactionRequest $request, array $callOptions = []): BeginTransactionResponse - { + public function beginTransaction( + BeginTransactionRequest $request, + array $callOptions = [] + ): BeginTransactionResponse { return $this->startApiCall('BeginTransaction', $request, $callOptions)->wait(); } @@ -386,8 +385,10 @@ public function rollback(RollbackRequest $request, array $callOptions = []): Rol * * @throws ApiException Thrown if the API call fails. */ - public function runAggregationQuery(RunAggregationQueryRequest $request, array $callOptions = []): RunAggregationQueryResponse - { + public function runAggregationQuery( + RunAggregationQueryRequest $request, + array $callOptions = [] + ): RunAggregationQueryResponse { return $this->startApiCall('RunAggregationQuery', $request, $callOptions)->wait(); } diff --git a/Datastore/src/V1/CommitRequest.php b/Datastore/src/V1/CommitRequest.php index fe4ce3062ad6..3d25a236d48b 100644 --- a/Datastore/src/V1/CommitRequest.php +++ b/Datastore/src/V1/CommitRequest.php @@ -20,7 +20,7 @@ class CommitRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string project_id = 8 [(.google.api.field_behavior) = REQUIRED]; */ - private $project_id = ''; + protected $project_id = ''; /** * The ID of the database against which to make the request. * '(default)' is not allowed; please use empty string '' to refer the default @@ -28,13 +28,13 @@ class CommitRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string database_id = 9; */ - private $database_id = ''; + protected $database_id = ''; /** * The type of commit to perform. Defaults to `TRANSACTIONAL`. * * Generated from protobuf field .google.datastore.v1.CommitRequest.Mode mode = 5; */ - private $mode = 0; + protected $mode = 0; /** * The mutations to perform. * When mode is `TRANSACTIONAL`, mutations affecting a single entity are diff --git a/Datastore/src/V1/CommitRequest/Mode.php b/Datastore/src/V1/CommitRequest/Mode.php index b4e9acbd6eb8..f75dd1647dbd 100644 --- a/Datastore/src/V1/CommitRequest/Mode.php +++ b/Datastore/src/V1/CommitRequest/Mode.php @@ -61,6 +61,4 @@ public static function value($name) } } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(Mode::class, \Google\Cloud\Datastore\V1\CommitRequest_Mode::class); diff --git a/Datastore/src/V1/CommitRequest_Mode.php b/Datastore/src/V1/CommitRequest_Mode.php deleted file mode 100644 index 7a700c7321b2..000000000000 --- a/Datastore/src/V1/CommitRequest_Mode.php +++ /dev/null @@ -1,16 +0,0 @@ -int32 index_updates = 4; */ - private $index_updates = 0; + protected $index_updates = 0; /** * The transaction commit timestamp. Not set for non-transactional commits. * * Generated from protobuf field .google.protobuf.Timestamp commit_time = 8; */ - private $commit_time = null; + protected $commit_time = null; /** * Constructor. diff --git a/Datastore/src/V1/CompositeFilter.php b/Datastore/src/V1/CompositeFilter.php index 612b1ef0cf25..8426fe7cea32 100644 --- a/Datastore/src/V1/CompositeFilter.php +++ b/Datastore/src/V1/CompositeFilter.php @@ -20,7 +20,7 @@ class CompositeFilter extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.datastore.v1.CompositeFilter.Operator op = 1; */ - private $op = 0; + protected $op = 0; /** * The list of filters to combine. * Requires: diff --git a/Datastore/src/V1/CompositeFilter/Operator.php b/Datastore/src/V1/CompositeFilter/Operator.php index 4cd871b7ed94..d4f17db45c12 100644 --- a/Datastore/src/V1/CompositeFilter/Operator.php +++ b/Datastore/src/V1/CompositeFilter/Operator.php @@ -63,6 +63,4 @@ public static function value($name) } } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(Operator::class, \Google\Cloud\Datastore\V1\CompositeFilter_Operator::class); diff --git a/Datastore/src/V1/CompositeFilter_Operator.php b/Datastore/src/V1/CompositeFilter_Operator.php deleted file mode 100644 index 78b8e9c89b67..000000000000 --- a/Datastore/src/V1/CompositeFilter_Operator.php +++ /dev/null @@ -1,16 +0,0 @@ -_simpleRequest('/google.datastore.v1.Datastore/Lookup', - $argument, - ['\Google\Cloud\Datastore\V1\LookupResponse', 'decode'], - $metadata, $options); - } - - /** - * Queries for entities. - * @param \Google\Cloud\Datastore\V1\RunQueryRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function RunQuery(\Google\Cloud\Datastore\V1\RunQueryRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.datastore.v1.Datastore/RunQuery', - $argument, - ['\Google\Cloud\Datastore\V1\RunQueryResponse', 'decode'], - $metadata, $options); - } - - /** - * Runs an aggregation query. - * @param \Google\Cloud\Datastore\V1\RunAggregationQueryRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function RunAggregationQuery(\Google\Cloud\Datastore\V1\RunAggregationQueryRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.datastore.v1.Datastore/RunAggregationQuery', - $argument, - ['\Google\Cloud\Datastore\V1\RunAggregationQueryResponse', 'decode'], - $metadata, $options); - } - - /** - * Begins a new transaction. - * @param \Google\Cloud\Datastore\V1\BeginTransactionRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function BeginTransaction(\Google\Cloud\Datastore\V1\BeginTransactionRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.datastore.v1.Datastore/BeginTransaction', - $argument, - ['\Google\Cloud\Datastore\V1\BeginTransactionResponse', 'decode'], - $metadata, $options); - } - - /** - * Commits a transaction, optionally creating, deleting or modifying some - * entities. - * @param \Google\Cloud\Datastore\V1\CommitRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function Commit(\Google\Cloud\Datastore\V1\CommitRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.datastore.v1.Datastore/Commit', - $argument, - ['\Google\Cloud\Datastore\V1\CommitResponse', 'decode'], - $metadata, $options); - } - - /** - * Rolls back a transaction. - * @param \Google\Cloud\Datastore\V1\RollbackRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function Rollback(\Google\Cloud\Datastore\V1\RollbackRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.datastore.v1.Datastore/Rollback', - $argument, - ['\Google\Cloud\Datastore\V1\RollbackResponse', 'decode'], - $metadata, $options); - } - - /** - * Allocates IDs for the given keys, which is useful for referencing an entity - * before it is inserted. - * @param \Google\Cloud\Datastore\V1\AllocateIdsRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function AllocateIds(\Google\Cloud\Datastore\V1\AllocateIdsRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.datastore.v1.Datastore/AllocateIds', - $argument, - ['\Google\Cloud\Datastore\V1\AllocateIdsResponse', 'decode'], - $metadata, $options); - } - - /** - * Prevents the supplied keys' IDs from being auto-allocated by Cloud - * Datastore. - * @param \Google\Cloud\Datastore\V1\ReserveIdsRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function ReserveIds(\Google\Cloud\Datastore\V1\ReserveIdsRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.datastore.v1.Datastore/ReserveIds', - $argument, - ['\Google\Cloud\Datastore\V1\ReserveIdsResponse', 'decode'], - $metadata, $options); - } - -} diff --git a/Datastore/src/V1/Entity.php b/Datastore/src/V1/Entity.php index a15a639fea54..53b46087f3a6 100644 --- a/Datastore/src/V1/Entity.php +++ b/Datastore/src/V1/Entity.php @@ -25,7 +25,7 @@ class Entity extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.datastore.v1.Key key = 1; */ - private $key = null; + protected $key = null; /** * The entity's properties. * The map's keys are property names. diff --git a/Datastore/src/V1/EntityResult.php b/Datastore/src/V1/EntityResult.php index c623ba169fe1..2fb16860fbd9 100644 --- a/Datastore/src/V1/EntityResult.php +++ b/Datastore/src/V1/EntityResult.php @@ -20,7 +20,7 @@ class EntityResult extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.datastore.v1.Entity entity = 1; */ - private $entity = null; + protected $entity = null; /** * The version of the entity, a strictly positive number that monotonically * increases with changes to the entity. @@ -32,7 +32,7 @@ class EntityResult extends \Google\Protobuf\Internal\Message * * Generated from protobuf field int64 version = 4; */ - private $version = 0; + protected $version = 0; /** * The time at which the entity was created. * This field is set for @@ -41,7 +41,7 @@ class EntityResult extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.protobuf.Timestamp create_time = 6; */ - private $create_time = null; + protected $create_time = null; /** * The time at which the entity was last changed. * This field is set for @@ -50,14 +50,14 @@ class EntityResult extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.protobuf.Timestamp update_time = 5; */ - private $update_time = null; + protected $update_time = null; /** * A cursor that points to the position after the result entity. * Set only when the `EntityResult` is part of a `QueryResultBatch` message. * * Generated from protobuf field bytes cursor = 3; */ - private $cursor = ''; + protected $cursor = ''; /** * Constructor. diff --git a/Datastore/src/V1/EntityResult/ResultType.php b/Datastore/src/V1/EntityResult/ResultType.php index 2e2471e78e19..f5f46b877fcf 100644 --- a/Datastore/src/V1/EntityResult/ResultType.php +++ b/Datastore/src/V1/EntityResult/ResultType.php @@ -70,6 +70,4 @@ public static function value($name) } } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(ResultType::class, \Google\Cloud\Datastore\V1\EntityResult_ResultType::class); diff --git a/Datastore/src/V1/EntityResult_ResultType.php b/Datastore/src/V1/EntityResult_ResultType.php deleted file mode 100644 index 95edc89e3a70..000000000000 --- a/Datastore/src/V1/EntityResult_ResultType.php +++ /dev/null @@ -1,16 +0,0 @@ -int64 results_returned = 1; */ - private $results_returned = 0; + protected $results_returned = 0; /** * Total time to execute the query in the backend. * * Generated from protobuf field .google.protobuf.Duration execution_duration = 3; */ - private $execution_duration = null; + protected $execution_duration = null; /** * Total billable read operations. * * Generated from protobuf field int64 read_operations = 4; */ - private $read_operations = 0; + protected $read_operations = 0; /** * Debugging statistics from the execution of the query. Note that the * debugging stats are subject to change as Firestore evolves. It could @@ -50,7 +50,7 @@ class ExecutionStats extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.protobuf.Struct debug_stats = 5; */ - private $debug_stats = null; + protected $debug_stats = null; /** * Constructor. diff --git a/Datastore/src/V1/ExplainMetrics.php b/Datastore/src/V1/ExplainMetrics.php index 8b1a69015857..99decd220a7d 100644 --- a/Datastore/src/V1/ExplainMetrics.php +++ b/Datastore/src/V1/ExplainMetrics.php @@ -20,7 +20,7 @@ class ExplainMetrics extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.datastore.v1.PlanSummary plan_summary = 1; */ - private $plan_summary = null; + protected $plan_summary = null; /** * Aggregated stats from the execution of the query. Only present when * [ExplainOptions.analyze][google.datastore.v1.ExplainOptions.analyze] is set @@ -28,7 +28,7 @@ class ExplainMetrics extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.datastore.v1.ExecutionStats execution_stats = 2; */ - private $execution_stats = null; + protected $execution_stats = null; /** * Constructor. diff --git a/Datastore/src/V1/ExplainOptions.php b/Datastore/src/V1/ExplainOptions.php index c9662558beb4..d903d204f9ea 100644 --- a/Datastore/src/V1/ExplainOptions.php +++ b/Datastore/src/V1/ExplainOptions.php @@ -24,7 +24,7 @@ class ExplainOptions extends \Google\Protobuf\Internal\Message * * Generated from protobuf field bool analyze = 1 [(.google.api.field_behavior) = OPTIONAL]; */ - private $analyze = false; + protected $analyze = false; /** * Constructor. diff --git a/Datastore/src/V1/FindNearest.php b/Datastore/src/V1/FindNearest.php index cdad9dfa7c0f..93efe15d4d17 100644 --- a/Datastore/src/V1/FindNearest.php +++ b/Datastore/src/V1/FindNearest.php @@ -25,27 +25,27 @@ class FindNearest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.datastore.v1.PropertyReference vector_property = 1 [(.google.api.field_behavior) = REQUIRED]; */ - private $vector_property = null; + protected $vector_property = null; /** * Required. The query vector that we are searching on. Must be a vector of no * more than 2048 dimensions. * * Generated from protobuf field .google.datastore.v1.Value query_vector = 2 [(.google.api.field_behavior) = REQUIRED]; */ - private $query_vector = null; + protected $query_vector = null; /** * Required. The Distance Measure to use, required. * * Generated from protobuf field .google.datastore.v1.FindNearest.DistanceMeasure distance_measure = 3 [(.google.api.field_behavior) = REQUIRED]; */ - private $distance_measure = 0; + protected $distance_measure = 0; /** * Required. The number of nearest neighbors to return. Must be a positive * integer of no more than 100. * * Generated from protobuf field .google.protobuf.Int32Value limit = 4 [(.google.api.field_behavior) = REQUIRED]; */ - private $limit = null; + protected $limit = null; /** * Optional. Optional name of the field to output the result of the vector * distance calculation. Must conform to [entity @@ -53,7 +53,7 @@ class FindNearest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string distance_result_property = 5 [(.google.api.field_behavior) = OPTIONAL]; */ - private $distance_result_property = ''; + protected $distance_result_property = ''; /** * Optional. Option to specify a threshold for which no less similar documents * will be returned. The behavior of the specified `distance_measure` will @@ -64,7 +64,7 @@ class FindNearest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.protobuf.DoubleValue distance_threshold = 6 [(.google.api.field_behavior) = OPTIONAL]; */ - private $distance_threshold = null; + protected $distance_threshold = null; /** * Constructor. @@ -237,7 +237,7 @@ public function clearLimit() * Generated from protobuf field .google.protobuf.Int32Value limit = 4 [(.google.api.field_behavior) = REQUIRED]; * @return int|null */ - public function getLimitValue() + public function getLimitUnwrapped() { return $this->readWrapperValue("limit"); } @@ -268,7 +268,7 @@ public function setLimit($var) * @param int|null $var * @return $this */ - public function setLimitValue($var) + public function setLimitUnwrapped($var) { $this->writeWrapperValue("limit", $var); return $this;} @@ -342,7 +342,7 @@ public function clearDistanceThreshold() * Generated from protobuf field .google.protobuf.DoubleValue distance_threshold = 6 [(.google.api.field_behavior) = OPTIONAL]; * @return float|null */ - public function getDistanceThresholdValue() + public function getDistanceThresholdUnwrapped() { return $this->readWrapperValue("distance_threshold"); } @@ -381,7 +381,7 @@ public function setDistanceThreshold($var) * @param float|null $var * @return $this */ - public function setDistanceThresholdValue($var) + public function setDistanceThresholdUnwrapped($var) { $this->writeWrapperValue("distance_threshold", $var); return $this;} diff --git a/Datastore/src/V1/FindNearest/DistanceMeasure.php b/Datastore/src/V1/FindNearest/DistanceMeasure.php index 5eb0ccc00196..f1c7fbd29a44 100644 --- a/Datastore/src/V1/FindNearest/DistanceMeasure.php +++ b/Datastore/src/V1/FindNearest/DistanceMeasure.php @@ -77,6 +77,4 @@ public static function value($name) } } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(DistanceMeasure::class, \Google\Cloud\Datastore\V1\FindNearest_DistanceMeasure::class); diff --git a/Datastore/src/V1/Gapic/DatastoreGapicClient.php b/Datastore/src/V1/Gapic/DatastoreGapicClient.php deleted file mode 100644 index bf7597e3a4ec..000000000000 --- a/Datastore/src/V1/Gapic/DatastoreGapicClient.php +++ /dev/null @@ -1,739 +0,0 @@ -allocateIds($projectId, $keys); - * } finally { - * $datastoreClient->close(); - * } - * ``` - * - * @deprecated Please use the new service client {@see \Google\Cloud\Datastore\V1\Client\DatastoreClient}. - */ -class DatastoreGapicClient -{ - use GapicClientTrait; - - /** The name of the service. */ - const SERVICE_NAME = 'google.datastore.v1.Datastore'; - - /** - * The default address of the service. - * - * @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead. - */ - const SERVICE_ADDRESS = 'datastore.googleapis.com'; - - /** The address template of the service. */ - private const SERVICE_ADDRESS_TEMPLATE = 'datastore.UNIVERSE_DOMAIN'; - - /** The default port of the service. */ - const DEFAULT_SERVICE_PORT = 443; - - /** The name of the code generator, to be included in the agent header. */ - const CODEGEN_NAME = 'gapic'; - - /** The default scopes required by the service. */ - public static $serviceScopes = [ - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/datastore', - ]; - - private static function getClientDefaults() - { - return [ - 'serviceName' => self::SERVICE_NAME, - 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, - 'clientConfig' => __DIR__ . '/../resources/datastore_client_config.json', - 'descriptorsConfigPath' => __DIR__ . '/../resources/datastore_descriptor_config.php', - 'gcpApiConfigPath' => __DIR__ . '/../resources/datastore_grpc_config.json', - 'credentialsConfig' => [ - 'defaultScopes' => self::$serviceScopes, - ], - 'transportConfig' => [ - 'rest' => [ - 'restClientConfigPath' => __DIR__ . '/../resources/datastore_rest_client_config.php', - ], - ], - ]; - } - - /** - * Constructor. - * - * @param array $options { - * Optional. Options for configuring the service API wrapper. - * - * @type string $apiEndpoint - * The address of the API remote host. May optionally include the port, formatted - * as ":". Default 'datastore.googleapis.com:443'. - * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials - * The credentials to be used by the client to authorize API calls. This option - * accepts either a path to a credentials file, or a decoded credentials file as a - * PHP array. - * *Advanced usage*: In addition, this option can also accept a pre-constructed - * {@see \Google\Auth\FetchAuthTokenInterface} object or - * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these - * objects are provided, any settings in $credentialsConfig will be ignored. - * @type array $credentialsConfig - * Options used to configure credentials, including auth token caching, for the - * client. For a full list of supporting configuration options, see - * {@see \Google\ApiCore\CredentialsWrapper::build()} . - * @type bool $disableRetries - * Determines whether or not retries defined by the client configuration should be - * disabled. Defaults to `false`. - * @type string|array $clientConfig - * Client method configuration, including retry settings. This option can be either - * a path to a JSON file, or a PHP array containing the decoded JSON data. By - * default this settings points to the default client config file, which is - * provided in the resources folder. - * @type string|TransportInterface $transport - * The transport used for executing network requests. May be either the string - * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. - * *Advanced usage*: Additionally, it is possible to pass in an already - * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note - * that when this object is provided, any settings in $transportConfig, and any - * $apiEndpoint setting, will be ignored. - * @type array $transportConfig - * Configuration options that will be used to construct the transport. Options for - * each supported transport type should be passed in a key for that transport. For - * example: - * $transportConfig = [ - * 'grpc' => [...], - * 'rest' => [...], - * ]; - * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and - * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the - * supported options. - * @type callable $clientCertSource - * A callable which returns the client cert as a string. This can be used to - * provide a certificate and private key to the transport layer for mTLS. - * } - * - * @throws ValidationException - */ - public function __construct(array $options = []) - { - $clientOptions = $this->buildClientOptions($options); - $this->setClientOptions($clientOptions); - } - - /** - * Allocates IDs for the given keys, which is useful for referencing an entity - * before it is inserted. - * - * Sample code: - * ``` - * $datastoreClient = new Google\Cloud\Datastore\V1\DatastoreClient(); - * try { - * $projectId = 'project_id'; - * $keys = []; - * $response = $datastoreClient->allocateIds($projectId, $keys); - * } finally { - * $datastoreClient->close(); - * } - * ``` - * - * @param string $projectId Required. The ID of the project against which to make the request. - * @param Key[] $keys Required. A list of keys with incomplete key paths for which to allocate - * IDs. No key may be reserved/read-only. - * @param array $optionalArgs { - * Optional. - * - * @type string $databaseId - * The ID of the database against which to make the request. - * - * '(default)' is not allowed; please use empty string '' to refer the default - * database. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\Cloud\Datastore\V1\AllocateIdsResponse - * - * @throws ApiException if the remote call fails - */ - public function allocateIds($projectId, $keys, array $optionalArgs = []) - { - $request = new AllocateIdsRequest(); - $requestParamHeaders = []; - $request->setProjectId($projectId); - $request->setKeys($keys); - $requestParamHeaders['project_id'] = $projectId; - if (isset($optionalArgs['databaseId'])) { - $request->setDatabaseId($optionalArgs['databaseId']); - $requestParamHeaders['database_id'] = $optionalArgs['databaseId']; - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('AllocateIds', AllocateIdsResponse::class, $optionalArgs, $request)->wait(); - } - - /** - * Begins a new transaction. - * - * Sample code: - * ``` - * $datastoreClient = new Google\Cloud\Datastore\V1\DatastoreClient(); - * try { - * $projectId = 'project_id'; - * $response = $datastoreClient->beginTransaction($projectId); - * } finally { - * $datastoreClient->close(); - * } - * ``` - * - * @param string $projectId Required. The ID of the project against which to make the request. - * @param array $optionalArgs { - * Optional. - * - * @type string $databaseId - * The ID of the database against which to make the request. - * - * '(default)' is not allowed; please use empty string '' to refer the default - * database. - * @type TransactionOptions $transactionOptions - * Options for a new transaction. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\Cloud\Datastore\V1\BeginTransactionResponse - * - * @throws ApiException if the remote call fails - */ - public function beginTransaction($projectId, array $optionalArgs = []) - { - $request = new BeginTransactionRequest(); - $requestParamHeaders = []; - $request->setProjectId($projectId); - $requestParamHeaders['project_id'] = $projectId; - if (isset($optionalArgs['databaseId'])) { - $request->setDatabaseId($optionalArgs['databaseId']); - $requestParamHeaders['database_id'] = $optionalArgs['databaseId']; - } - - if (isset($optionalArgs['transactionOptions'])) { - $request->setTransactionOptions($optionalArgs['transactionOptions']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('BeginTransaction', BeginTransactionResponse::class, $optionalArgs, $request)->wait(); - } - - /** - * Commits a transaction, optionally creating, deleting or modifying some - * entities. - * - * Sample code: - * ``` - * $datastoreClient = new Google\Cloud\Datastore\V1\DatastoreClient(); - * try { - * $projectId = 'project_id'; - * $mode = Google\Cloud\Datastore\V1\CommitRequest\Mode::MODE_UNSPECIFIED; - * $mutations = []; - * $response = $datastoreClient->commit($projectId, $mode, $mutations); - * } finally { - * $datastoreClient->close(); - * } - * ``` - * - * @param string $projectId Required. The ID of the project against which to make the request. - * @param int $mode The type of commit to perform. Defaults to `TRANSACTIONAL`. - * For allowed values, use constants defined on {@see \Google\Cloud\Datastore\V1\CommitRequest\Mode} - * @param Mutation[] $mutations The mutations to perform. - * - * When mode is `TRANSACTIONAL`, mutations affecting a single entity are - * applied in order. The following sequences of mutations affecting a single - * entity are not permitted in a single `Commit` request: - * - * - `insert` followed by `insert` - * - `update` followed by `insert` - * - `upsert` followed by `insert` - * - `delete` followed by `update` - * - * When mode is `NON_TRANSACTIONAL`, no two mutations may affect a single - * entity. - * @param array $optionalArgs { - * Optional. - * - * @type string $databaseId - * The ID of the database against which to make the request. - * - * '(default)' is not allowed; please use empty string '' to refer the default - * database. - * @type string $transaction - * The identifier of the transaction associated with the commit. A - * transaction identifier is returned by a call to - * [Datastore.BeginTransaction][google.datastore.v1.Datastore.BeginTransaction]. - * @type TransactionOptions $singleUseTransaction - * Options for beginning a new transaction for this request. - * The transaction is committed when the request completes. If specified, - * [TransactionOptions.mode][google.datastore.v1.TransactionOptions] must be - * [TransactionOptions.ReadWrite][google.datastore.v1.TransactionOptions.ReadWrite]. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\Cloud\Datastore\V1\CommitResponse - * - * @throws ApiException if the remote call fails - */ - public function commit($projectId, $mode, $mutations, array $optionalArgs = []) - { - $request = new CommitRequest(); - $requestParamHeaders = []; - $request->setProjectId($projectId); - $request->setMode($mode); - $request->setMutations($mutations); - $requestParamHeaders['project_id'] = $projectId; - if (isset($optionalArgs['databaseId'])) { - $request->setDatabaseId($optionalArgs['databaseId']); - $requestParamHeaders['database_id'] = $optionalArgs['databaseId']; - } - - if (isset($optionalArgs['transaction'])) { - $request->setTransaction($optionalArgs['transaction']); - } - - if (isset($optionalArgs['singleUseTransaction'])) { - $request->setSingleUseTransaction($optionalArgs['singleUseTransaction']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('Commit', CommitResponse::class, $optionalArgs, $request)->wait(); - } - - /** - * Looks up entities by key. - * - * Sample code: - * ``` - * $datastoreClient = new Google\Cloud\Datastore\V1\DatastoreClient(); - * try { - * $projectId = 'project_id'; - * $keys = []; - * $response = $datastoreClient->lookup($projectId, $keys); - * } finally { - * $datastoreClient->close(); - * } - * ``` - * - * @param string $projectId Required. The ID of the project against which to make the request. - * @param Key[] $keys Required. Keys of entities to look up. - * @param array $optionalArgs { - * Optional. - * - * @type string $databaseId - * The ID of the database against which to make the request. - * - * '(default)' is not allowed; please use empty string '' to refer the default - * database. - * @type ReadOptions $readOptions - * The options for this lookup request. - * @type PropertyMask $propertyMask - * The properties to return. Defaults to returning all properties. - * - * If this field is set and an entity has a property not referenced in the - * mask, it will be absent from [LookupResponse.found.entity.properties][]. - * - * The entity's key is always returned. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\Cloud\Datastore\V1\LookupResponse - * - * @throws ApiException if the remote call fails - */ - public function lookup($projectId, $keys, array $optionalArgs = []) - { - $request = new LookupRequest(); - $requestParamHeaders = []; - $request->setProjectId($projectId); - $request->setKeys($keys); - $requestParamHeaders['project_id'] = $projectId; - if (isset($optionalArgs['databaseId'])) { - $request->setDatabaseId($optionalArgs['databaseId']); - $requestParamHeaders['database_id'] = $optionalArgs['databaseId']; - } - - if (isset($optionalArgs['readOptions'])) { - $request->setReadOptions($optionalArgs['readOptions']); - } - - if (isset($optionalArgs['propertyMask'])) { - $request->setPropertyMask($optionalArgs['propertyMask']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('Lookup', LookupResponse::class, $optionalArgs, $request)->wait(); - } - - /** - * Prevents the supplied keys' IDs from being auto-allocated by Cloud - * Datastore. - * - * Sample code: - * ``` - * $datastoreClient = new Google\Cloud\Datastore\V1\DatastoreClient(); - * try { - * $projectId = 'project_id'; - * $keys = []; - * $response = $datastoreClient->reserveIds($projectId, $keys); - * } finally { - * $datastoreClient->close(); - * } - * ``` - * - * @param string $projectId Required. The ID of the project against which to make the request. - * @param Key[] $keys Required. A list of keys with complete key paths whose numeric IDs should - * not be auto-allocated. - * @param array $optionalArgs { - * Optional. - * - * @type string $databaseId - * The ID of the database against which to make the request. - * - * '(default)' is not allowed; please use empty string '' to refer the default - * database. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\Cloud\Datastore\V1\ReserveIdsResponse - * - * @throws ApiException if the remote call fails - */ - public function reserveIds($projectId, $keys, array $optionalArgs = []) - { - $request = new ReserveIdsRequest(); - $requestParamHeaders = []; - $request->setProjectId($projectId); - $request->setKeys($keys); - $requestParamHeaders['project_id'] = $projectId; - if (isset($optionalArgs['databaseId'])) { - $request->setDatabaseId($optionalArgs['databaseId']); - $requestParamHeaders['database_id'] = $optionalArgs['databaseId']; - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('ReserveIds', ReserveIdsResponse::class, $optionalArgs, $request)->wait(); - } - - /** - * Rolls back a transaction. - * - * Sample code: - * ``` - * $datastoreClient = new Google\Cloud\Datastore\V1\DatastoreClient(); - * try { - * $projectId = 'project_id'; - * $transaction = '...'; - * $response = $datastoreClient->rollback($projectId, $transaction); - * } finally { - * $datastoreClient->close(); - * } - * ``` - * - * @param string $projectId Required. The ID of the project against which to make the request. - * @param string $transaction Required. The transaction identifier, returned by a call to - * [Datastore.BeginTransaction][google.datastore.v1.Datastore.BeginTransaction]. - * @param array $optionalArgs { - * Optional. - * - * @type string $databaseId - * The ID of the database against which to make the request. - * - * '(default)' is not allowed; please use empty string '' to refer the default - * database. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\Cloud\Datastore\V1\RollbackResponse - * - * @throws ApiException if the remote call fails - */ - public function rollback($projectId, $transaction, array $optionalArgs = []) - { - $request = new RollbackRequest(); - $requestParamHeaders = []; - $request->setProjectId($projectId); - $request->setTransaction($transaction); - $requestParamHeaders['project_id'] = $projectId; - if (isset($optionalArgs['databaseId'])) { - $request->setDatabaseId($optionalArgs['databaseId']); - $requestParamHeaders['database_id'] = $optionalArgs['databaseId']; - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('Rollback', RollbackResponse::class, $optionalArgs, $request)->wait(); - } - - /** - * Runs an aggregation query. - * - * Sample code: - * ``` - * $datastoreClient = new Google\Cloud\Datastore\V1\DatastoreClient(); - * try { - * $projectId = 'project_id'; - * $response = $datastoreClient->runAggregationQuery($projectId); - * } finally { - * $datastoreClient->close(); - * } - * ``` - * - * @param string $projectId Required. The ID of the project against which to make the request. - * @param array $optionalArgs { - * Optional. - * - * @type string $databaseId - * The ID of the database against which to make the request. - * - * '(default)' is not allowed; please use empty string '' to refer the default - * database. - * @type PartitionId $partitionId - * Entities are partitioned into subsets, identified by a partition ID. - * Queries are scoped to a single partition. - * This partition ID is normalized with the standard default context - * partition ID. - * @type ReadOptions $readOptions - * The options for this query. - * @type AggregationQuery $aggregationQuery - * The query to run. - * @type GqlQuery $gqlQuery - * The GQL query to run. This query must be an aggregation query. - * @type ExplainOptions $explainOptions - * Optional. Explain options for the query. If set, additional query - * statistics will be returned. If not, only query results will be returned. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\Cloud\Datastore\V1\RunAggregationQueryResponse - * - * @throws ApiException if the remote call fails - */ - public function runAggregationQuery($projectId, array $optionalArgs = []) - { - $request = new RunAggregationQueryRequest(); - $requestParamHeaders = []; - $request->setProjectId($projectId); - $requestParamHeaders['project_id'] = $projectId; - if (isset($optionalArgs['databaseId'])) { - $request->setDatabaseId($optionalArgs['databaseId']); - $requestParamHeaders['database_id'] = $optionalArgs['databaseId']; - } - - if (isset($optionalArgs['partitionId'])) { - $request->setPartitionId($optionalArgs['partitionId']); - } - - if (isset($optionalArgs['readOptions'])) { - $request->setReadOptions($optionalArgs['readOptions']); - } - - if (isset($optionalArgs['aggregationQuery'])) { - $request->setAggregationQuery($optionalArgs['aggregationQuery']); - } - - if (isset($optionalArgs['gqlQuery'])) { - $request->setGqlQuery($optionalArgs['gqlQuery']); - } - - if (isset($optionalArgs['explainOptions'])) { - $request->setExplainOptions($optionalArgs['explainOptions']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('RunAggregationQuery', RunAggregationQueryResponse::class, $optionalArgs, $request)->wait(); - } - - /** - * Queries for entities. - * - * Sample code: - * ``` - * $datastoreClient = new Google\Cloud\Datastore\V1\DatastoreClient(); - * try { - * $projectId = 'project_id'; - * $partitionId = new Google\Cloud\Datastore\V1\PartitionId(); - * $response = $datastoreClient->runQuery($projectId, $partitionId); - * } finally { - * $datastoreClient->close(); - * } - * ``` - * - * @param string $projectId Required. The ID of the project against which to make the request. - * @param PartitionId $partitionId Entities are partitioned into subsets, identified by a partition ID. - * Queries are scoped to a single partition. - * This partition ID is normalized with the standard default context - * partition ID. - * @param array $optionalArgs { - * Optional. - * - * @type string $databaseId - * The ID of the database against which to make the request. - * - * '(default)' is not allowed; please use empty string '' to refer the default - * database. - * @type ReadOptions $readOptions - * The options for this query. - * @type Query $query - * The query to run. - * @type GqlQuery $gqlQuery - * The GQL query to run. This query must be a non-aggregation query. - * @type PropertyMask $propertyMask - * The properties to return. - * This field must not be set for a projection query. - * - * See - * [LookupRequest.property_mask][google.datastore.v1.LookupRequest.property_mask]. - * @type ExplainOptions $explainOptions - * Optional. Explain options for the query. If set, additional query - * statistics will be returned. If not, only query results will be returned. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\Cloud\Datastore\V1\RunQueryResponse - * - * @throws ApiException if the remote call fails - */ - public function runQuery($projectId, $partitionId, array $optionalArgs = []) - { - $request = new RunQueryRequest(); - $requestParamHeaders = []; - $request->setProjectId($projectId); - $request->setPartitionId($partitionId); - $requestParamHeaders['project_id'] = $projectId; - if (isset($optionalArgs['databaseId'])) { - $request->setDatabaseId($optionalArgs['databaseId']); - $requestParamHeaders['database_id'] = $optionalArgs['databaseId']; - } - - if (isset($optionalArgs['readOptions'])) { - $request->setReadOptions($optionalArgs['readOptions']); - } - - if (isset($optionalArgs['query'])) { - $request->setQuery($optionalArgs['query']); - } - - if (isset($optionalArgs['gqlQuery'])) { - $request->setGqlQuery($optionalArgs['gqlQuery']); - } - - if (isset($optionalArgs['propertyMask'])) { - $request->setPropertyMask($optionalArgs['propertyMask']); - } - - if (isset($optionalArgs['explainOptions'])) { - $request->setExplainOptions($optionalArgs['explainOptions']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('RunQuery', RunQueryResponse::class, $optionalArgs, $request)->wait(); - } -} diff --git a/Datastore/src/V1/GqlQuery.php b/Datastore/src/V1/GqlQuery.php index d6a05a355184..ba0e57d29944 100644 --- a/Datastore/src/V1/GqlQuery.php +++ b/Datastore/src/V1/GqlQuery.php @@ -22,7 +22,7 @@ class GqlQuery extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string query_string = 1; */ - private $query_string = ''; + protected $query_string = ''; /** * When false, the query string must not contain any literals and instead must * bind all values. For example, @@ -31,7 +31,7 @@ class GqlQuery extends \Google\Protobuf\Internal\Message * * Generated from protobuf field bool allow_literals = 2; */ - private $allow_literals = false; + protected $allow_literals = false; /** * For each non-reserved named binding site in the query string, there must be * a named parameter with that name, but not necessarily the inverse. diff --git a/Datastore/src/V1/Key.php b/Datastore/src/V1/Key.php index 4f824d68659f..a399e216a16d 100644 --- a/Datastore/src/V1/Key.php +++ b/Datastore/src/V1/Key.php @@ -25,7 +25,7 @@ class Key extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.datastore.v1.PartitionId partition_id = 1; */ - private $partition_id = null; + protected $partition_id = null; /** * The entity path. * An entity path consists of one or more elements composed of a kind and a diff --git a/Datastore/src/V1/Key/PathElement.php b/Datastore/src/V1/Key/PathElement.php index 76dcafb46c99..2063992e96ad 100644 --- a/Datastore/src/V1/Key/PathElement.php +++ b/Datastore/src/V1/Key/PathElement.php @@ -28,7 +28,7 @@ class PathElement extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string kind = 1; */ - private $kind = ''; + protected $kind = ''; protected $id_type; /** @@ -190,6 +190,4 @@ public function getIdType() } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(PathElement::class, \Google\Cloud\Datastore\V1\Key_PathElement::class); diff --git a/Datastore/src/V1/Key_PathElement.php b/Datastore/src/V1/Key_PathElement.php deleted file mode 100644 index 7e97a3582d0c..000000000000 --- a/Datastore/src/V1/Key_PathElement.php +++ /dev/null @@ -1,16 +0,0 @@ -string name = 1; */ - private $name = ''; + protected $name = ''; /** * Constructor. diff --git a/Datastore/src/V1/LookupRequest.php b/Datastore/src/V1/LookupRequest.php index e714464e4d5f..de73e6c97ef1 100644 --- a/Datastore/src/V1/LookupRequest.php +++ b/Datastore/src/V1/LookupRequest.php @@ -20,7 +20,7 @@ class LookupRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string project_id = 8 [(.google.api.field_behavior) = REQUIRED]; */ - private $project_id = ''; + protected $project_id = ''; /** * The ID of the database against which to make the request. * '(default)' is not allowed; please use empty string '' to refer the default @@ -28,13 +28,13 @@ class LookupRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string database_id = 9; */ - private $database_id = ''; + protected $database_id = ''; /** * The options for this lookup request. * * Generated from protobuf field .google.datastore.v1.ReadOptions read_options = 1; */ - private $read_options = null; + protected $read_options = null; /** * Required. Keys of entities to look up. * @@ -49,7 +49,7 @@ class LookupRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.datastore.v1.PropertyMask property_mask = 5; */ - private $property_mask = null; + protected $property_mask = null; /** * @param string $projectId Required. The ID of the project against which to make the request. diff --git a/Datastore/src/V1/LookupResponse.php b/Datastore/src/V1/LookupResponse.php index 49b5d094bd47..e33d8a7f8742 100644 --- a/Datastore/src/V1/LookupResponse.php +++ b/Datastore/src/V1/LookupResponse.php @@ -49,13 +49,13 @@ class LookupResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field bytes transaction = 5; */ - private $transaction = ''; + protected $transaction = ''; /** * The time at which these entities were read or found missing. * * Generated from protobuf field .google.protobuf.Timestamp read_time = 7; */ - private $read_time = null; + protected $read_time = null; /** * Constructor. diff --git a/Datastore/src/V1/Mutation.php b/Datastore/src/V1/Mutation.php index d511ae376384..8721321c562a 100644 --- a/Datastore/src/V1/Mutation.php +++ b/Datastore/src/V1/Mutation.php @@ -22,7 +22,7 @@ class Mutation extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.datastore.v1.Mutation.ConflictResolutionStrategy conflict_resolution_strategy = 10; */ - private $conflict_resolution_strategy = 0; + protected $conflict_resolution_strategy = 0; /** * The properties to write in this mutation. * None of the properties in the mask may have a reserved name, except for @@ -34,7 +34,7 @@ class Mutation extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.datastore.v1.PropertyMask property_mask = 9; */ - private $property_mask = null; + protected $property_mask = null; /** * Optional. The transforms to perform on the entity. * This field can be set only when the operation is `insert`, `update`, diff --git a/Datastore/src/V1/Mutation/ConflictResolutionStrategy.php b/Datastore/src/V1/Mutation/ConflictResolutionStrategy.php index f2809890ebe1..27357ade2ef2 100644 --- a/Datastore/src/V1/Mutation/ConflictResolutionStrategy.php +++ b/Datastore/src/V1/Mutation/ConflictResolutionStrategy.php @@ -59,6 +59,4 @@ public static function value($name) } } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(ConflictResolutionStrategy::class, \Google\Cloud\Datastore\V1\Mutation_ConflictResolutionStrategy::class); diff --git a/Datastore/src/V1/MutationResult.php b/Datastore/src/V1/MutationResult.php index 388e3aae280f..8dad8eba89fa 100644 --- a/Datastore/src/V1/MutationResult.php +++ b/Datastore/src/V1/MutationResult.php @@ -21,7 +21,7 @@ class MutationResult extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.datastore.v1.Key key = 3; */ - private $key = null; + protected $key = null; /** * The version of the entity on the server after processing the mutation. If * the mutation doesn't change anything on the server, then the version will @@ -31,13 +31,13 @@ class MutationResult extends \Google\Protobuf\Internal\Message * * Generated from protobuf field int64 version = 4; */ - private $version = 0; + protected $version = 0; /** * The create time of the entity. This field will not be set after a 'delete'. * * Generated from protobuf field .google.protobuf.Timestamp create_time = 7; */ - private $create_time = null; + protected $create_time = null; /** * The update time of the entity on the server after processing the mutation. * If the mutation doesn't change anything on the server, then the timestamp @@ -46,14 +46,14 @@ class MutationResult extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.protobuf.Timestamp update_time = 6; */ - private $update_time = null; + protected $update_time = null; /** * Whether a conflict was detected for this mutation. Always false when a * conflict detection strategy field is not set in the mutation. * * Generated from protobuf field bool conflict_detected = 5; */ - private $conflict_detected = false; + protected $conflict_detected = false; /** * The results of applying each * [PropertyTransform][google.datastore.v1.PropertyTransform], in the same diff --git a/Datastore/src/V1/PartitionId.php b/Datastore/src/V1/PartitionId.php index 892b4adce1b5..c2f4e7864f4b 100644 --- a/Datastore/src/V1/PartitionId.php +++ b/Datastore/src/V1/PartitionId.php @@ -35,20 +35,20 @@ class PartitionId extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string project_id = 2; */ - private $project_id = ''; + protected $project_id = ''; /** * If not empty, the ID of the database to which the entities * belong. * * Generated from protobuf field string database_id = 3; */ - private $database_id = ''; + protected $database_id = ''; /** * If not empty, the ID of the namespace to which the entities belong. * * Generated from protobuf field string namespace_id = 4; */ - private $namespace_id = ''; + protected $namespace_id = ''; /** * Constructor. diff --git a/Datastore/src/V1/Projection.php b/Datastore/src/V1/Projection.php index 4e48f9db63e7..614ebde6d27f 100644 --- a/Datastore/src/V1/Projection.php +++ b/Datastore/src/V1/Projection.php @@ -20,7 +20,7 @@ class Projection extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.datastore.v1.PropertyReference property = 1; */ - private $property = null; + protected $property = null; /** * Constructor. diff --git a/Datastore/src/V1/PropertyFilter.php b/Datastore/src/V1/PropertyFilter.php index 81e7df8031c0..9e303711f8aa 100644 --- a/Datastore/src/V1/PropertyFilter.php +++ b/Datastore/src/V1/PropertyFilter.php @@ -20,19 +20,19 @@ class PropertyFilter extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.datastore.v1.PropertyReference property = 1; */ - private $property = null; + protected $property = null; /** * The operator to filter by. * * Generated from protobuf field .google.datastore.v1.PropertyFilter.Operator op = 2; */ - private $op = 0; + protected $op = 0; /** * The value to compare the property to. * * Generated from protobuf field .google.datastore.v1.Value value = 3; */ - private $value = null; + protected $value = null; /** * Constructor. diff --git a/Datastore/src/V1/PropertyFilter/Operator.php b/Datastore/src/V1/PropertyFilter/Operator.php index b1188ff2d39a..3d5fb77fe983 100644 --- a/Datastore/src/V1/PropertyFilter/Operator.php +++ b/Datastore/src/V1/PropertyFilter/Operator.php @@ -130,6 +130,4 @@ public static function value($name) } } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(Operator::class, \Google\Cloud\Datastore\V1\PropertyFilter_Operator::class); diff --git a/Datastore/src/V1/PropertyFilter_Operator.php b/Datastore/src/V1/PropertyFilter_Operator.php deleted file mode 100644 index d483975e158c..000000000000 --- a/Datastore/src/V1/PropertyFilter_Operator.php +++ /dev/null @@ -1,16 +0,0 @@ -.google.datastore.v1.PropertyReference property = 1; */ - private $property = null; + protected $property = null; /** * The direction to order by. Defaults to `ASCENDING`. * * Generated from protobuf field .google.datastore.v1.PropertyOrder.Direction direction = 2; */ - private $direction = 0; + protected $direction = 0; /** * Constructor. diff --git a/Datastore/src/V1/PropertyOrder/Direction.php b/Datastore/src/V1/PropertyOrder/Direction.php index 6534ba280732..942c1741f1b8 100644 --- a/Datastore/src/V1/PropertyOrder/Direction.php +++ b/Datastore/src/V1/PropertyOrder/Direction.php @@ -59,6 +59,4 @@ public static function value($name) } } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(Direction::class, \Google\Cloud\Datastore\V1\PropertyOrder_Direction::class); diff --git a/Datastore/src/V1/PropertyOrder_Direction.php b/Datastore/src/V1/PropertyOrder_Direction.php deleted file mode 100644 index 17c988947f58..000000000000 --- a/Datastore/src/V1/PropertyOrder_Direction.php +++ /dev/null @@ -1,16 +0,0 @@ -string name = 2; */ - private $name = ''; + protected $name = ''; /** * Constructor. diff --git a/Datastore/src/V1/PropertyTransform.php b/Datastore/src/V1/PropertyTransform.php index 5be9066dcaa6..1114cd9027ae 100644 --- a/Datastore/src/V1/PropertyTransform.php +++ b/Datastore/src/V1/PropertyTransform.php @@ -25,7 +25,7 @@ class PropertyTransform extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string property = 1 [(.google.api.field_behavior) = OPTIONAL]; */ - private $property = ''; + protected $property = ''; protected $transform_type; /** diff --git a/Datastore/src/V1/PropertyTransform/ServerValue.php b/Datastore/src/V1/PropertyTransform/ServerValue.php index 6162f10f4c4d..d95864cf1470 100644 --- a/Datastore/src/V1/PropertyTransform/ServerValue.php +++ b/Datastore/src/V1/PropertyTransform/ServerValue.php @@ -54,6 +54,4 @@ public static function value($name) } } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(ServerValue::class, \Google\Cloud\Datastore\V1\PropertyTransform_ServerValue::class); diff --git a/Datastore/src/V1/Query.php b/Datastore/src/V1/Query.php index e89908155e7d..5d1def8847b7 100644 --- a/Datastore/src/V1/Query.php +++ b/Datastore/src/V1/Query.php @@ -41,7 +41,7 @@ class Query extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.datastore.v1.Filter filter = 4; */ - private $filter = null; + protected $filter = null; /** * The order to apply to the query results (if empty, order is unspecified). * @@ -67,7 +67,7 @@ class Query extends \Google\Protobuf\Internal\Message * * Generated from protobuf field bytes start_cursor = 7; */ - private $start_cursor = ''; + protected $start_cursor = ''; /** * An ending point for the query results. Query cursors are * returned in query result batches and @@ -76,14 +76,14 @@ class Query extends \Google\Protobuf\Internal\Message * * Generated from protobuf field bytes end_cursor = 8; */ - private $end_cursor = ''; + protected $end_cursor = ''; /** * The number of results to skip. Applies before limit, but after all other * constraints. Optional. Must be >= 0 if specified. * * Generated from protobuf field int32 offset = 10; */ - private $offset = 0; + protected $offset = 0; /** * The maximum number of results to return. Applies after all other * constraints. Optional. @@ -92,7 +92,7 @@ class Query extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.protobuf.Int32Value limit = 12; */ - private $limit = null; + protected $limit = null; /** * Optional. A potential Nearest Neighbors Search. * Applies after all other filters and ordering. @@ -100,7 +100,7 @@ class Query extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.datastore.v1.FindNearest find_nearest = 13 [(.google.api.field_behavior) = OPTIONAL]; */ - private $find_nearest = null; + protected $find_nearest = null; /** * Constructor. @@ -432,7 +432,7 @@ public function clearLimit() * Generated from protobuf field .google.protobuf.Int32Value limit = 12; * @return int|null */ - public function getLimitValue() + public function getLimitUnwrapped() { return $this->readWrapperValue("limit"); } @@ -467,7 +467,7 @@ public function setLimit($var) * @param int|null $var * @return $this */ - public function setLimitValue($var) + public function setLimitUnwrapped($var) { $this->writeWrapperValue("limit", $var); return $this;} diff --git a/Datastore/src/V1/QueryMode.php b/Datastore/src/V1/QueryMode.php deleted file mode 100644 index c72fe017288d..000000000000 --- a/Datastore/src/V1/QueryMode.php +++ /dev/null @@ -1,63 +0,0 @@ -google.datastore.v1.QueryMode - */ -class QueryMode -{ - /** - * The default mode. Only the query results are returned. - * - * Generated from protobuf enum NORMAL = 0; - */ - const NORMAL = 0; - /** - * This mode returns only the query plan, without any results or execution - * statistics information. - * - * Generated from protobuf enum PLAN = 1; - */ - const PLAN = 1; - /** - * This mode returns both the query plan and the execution statistics along - * with the results. - * - * Generated from protobuf enum PROFILE = 2; - */ - const PROFILE = 2; - - private static $valueToName = [ - self::NORMAL => 'NORMAL', - self::PLAN => 'PLAN', - self::PROFILE => 'PROFILE', - ]; - - public static function name($value) - { - if (!isset(self::$valueToName[$value])) { - throw new UnexpectedValueException(sprintf( - 'Enum %s has no name defined for value %s', __CLASS__, $value)); - } - return self::$valueToName[$value]; - } - - - public static function value($name) - { - $const = __CLASS__ . '::' . strtoupper($name); - if (!defined($const)) { - throw new UnexpectedValueException(sprintf( - 'Enum %s has no value defined for name %s', __CLASS__, $name)); - } - return constant($const); - } -} - diff --git a/Datastore/src/V1/QueryPlan.php b/Datastore/src/V1/QueryPlan.php deleted file mode 100644 index 0c5fecf69a9d..000000000000 --- a/Datastore/src/V1/QueryPlan.php +++ /dev/null @@ -1,101 +0,0 @@ -google.datastore.v1.QueryPlan - */ -class QueryPlan extends \Google\Protobuf\Internal\Message -{ - /** - * Planning phase information for the query. It will include: - * { - * "indexes_used": [ - * {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"}, - * {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"} - * ] - * } - * - * Generated from protobuf field .google.protobuf.Struct plan_info = 1; - */ - private $plan_info = null; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type \Google\Protobuf\Struct $plan_info - * Planning phase information for the query. It will include: - * { - * "indexes_used": [ - * {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"}, - * {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"} - * ] - * } - * } - */ - public function __construct($data = NULL) { - \GPBMetadata\Google\Datastore\V1\QueryProfile::initOnce(); - parent::__construct($data); - } - - /** - * Planning phase information for the query. It will include: - * { - * "indexes_used": [ - * {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"}, - * {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"} - * ] - * } - * - * Generated from protobuf field .google.protobuf.Struct plan_info = 1; - * @return \Google\Protobuf\Struct|null - */ - public function getPlanInfo() - { - return $this->plan_info; - } - - public function hasPlanInfo() - { - return isset($this->plan_info); - } - - public function clearPlanInfo() - { - unset($this->plan_info); - } - - /** - * Planning phase information for the query. It will include: - * { - * "indexes_used": [ - * {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"}, - * {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"} - * ] - * } - * - * Generated from protobuf field .google.protobuf.Struct plan_info = 1; - * @param \Google\Protobuf\Struct $var - * @return $this - */ - public function setPlanInfo($var) - { - GPBUtil::checkMessage($var, \Google\Protobuf\Struct::class); - $this->plan_info = $var; - - return $this; - } - -} - diff --git a/Datastore/src/V1/QueryResultBatch.php b/Datastore/src/V1/QueryResultBatch.php index f49a9054e89a..04cc35cb4ad8 100644 --- a/Datastore/src/V1/QueryResultBatch.php +++ b/Datastore/src/V1/QueryResultBatch.php @@ -20,20 +20,20 @@ class QueryResultBatch extends \Google\Protobuf\Internal\Message * * Generated from protobuf field int32 skipped_results = 6; */ - private $skipped_results = 0; + protected $skipped_results = 0; /** * A cursor that points to the position after the last skipped result. * Will be set when `skipped_results` != 0. * * Generated from protobuf field bytes skipped_cursor = 3; */ - private $skipped_cursor = ''; + protected $skipped_cursor = ''; /** * The result type for every entity in `entity_results`. * * Generated from protobuf field .google.datastore.v1.EntityResult.ResultType entity_result_type = 1; */ - private $entity_result_type = 0; + protected $entity_result_type = 0; /** * The results for this batch. * @@ -45,13 +45,13 @@ class QueryResultBatch extends \Google\Protobuf\Internal\Message * * Generated from protobuf field bytes end_cursor = 4; */ - private $end_cursor = ''; + protected $end_cursor = ''; /** * The state of the query after the current batch. * * Generated from protobuf field .google.datastore.v1.QueryResultBatch.MoreResultsType more_results = 5; */ - private $more_results = 0; + protected $more_results = 0; /** * The version number of the snapshot this batch was returned from. * This applies to the range of results from the query's `start_cursor` (or @@ -64,7 +64,7 @@ class QueryResultBatch extends \Google\Protobuf\Internal\Message * * Generated from protobuf field int64 snapshot_version = 7; */ - private $snapshot_version = 0; + protected $snapshot_version = 0; /** * Read timestamp this batch was returned from. * This applies to the range of results from the query's `start_cursor` (or @@ -78,7 +78,7 @@ class QueryResultBatch extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.protobuf.Timestamp read_time = 8; */ - private $read_time = null; + protected $read_time = null; /** * Constructor. diff --git a/Datastore/src/V1/QueryResultBatch/MoreResultsType.php b/Datastore/src/V1/QueryResultBatch/MoreResultsType.php index 6f4a9d2dd046..c832b425b7c7 100644 --- a/Datastore/src/V1/QueryResultBatch/MoreResultsType.php +++ b/Datastore/src/V1/QueryResultBatch/MoreResultsType.php @@ -74,6 +74,4 @@ public static function value($name) } } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(MoreResultsType::class, \Google\Cloud\Datastore\V1\QueryResultBatch_MoreResultsType::class); diff --git a/Datastore/src/V1/QueryResultBatch_MoreResultsType.php b/Datastore/src/V1/QueryResultBatch_MoreResultsType.php deleted file mode 100644 index e3e4655f3a96..000000000000 --- a/Datastore/src/V1/QueryResultBatch_MoreResultsType.php +++ /dev/null @@ -1,16 +0,0 @@ - new PartitionId([ - 'project_id' => $projectId - ]), - 'path' => [ - new PathElement([ - 'kind' => 'Company', - 'name' => 'Google' - ]) - ] -]); - -$entity = $datastoreClient->lookup($projectId, $keys); -``` diff --git a/Datastore/src/V1/ReadOptions/ReadConsistency.php b/Datastore/src/V1/ReadOptions/ReadConsistency.php index 631a403de9f1..3fdeeca58c99 100644 --- a/Datastore/src/V1/ReadOptions/ReadConsistency.php +++ b/Datastore/src/V1/ReadOptions/ReadConsistency.php @@ -59,6 +59,4 @@ public static function value($name) } } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(ReadConsistency::class, \Google\Cloud\Datastore\V1\ReadOptions_ReadConsistency::class); diff --git a/Datastore/src/V1/ReadOptions_ReadConsistency.php b/Datastore/src/V1/ReadOptions_ReadConsistency.php deleted file mode 100644 index 0a79bffd2bbd..000000000000 --- a/Datastore/src/V1/ReadOptions_ReadConsistency.php +++ /dev/null @@ -1,16 +0,0 @@ -string project_id = 8 [(.google.api.field_behavior) = REQUIRED]; */ - private $project_id = ''; + protected $project_id = ''; /** * The ID of the database against which to make the request. * '(default)' is not allowed; please use empty string '' to refer the default @@ -29,7 +29,7 @@ class ReserveIdsRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string database_id = 9; */ - private $database_id = ''; + protected $database_id = ''; /** * Required. A list of keys with complete key paths whose numeric IDs should * not be auto-allocated. diff --git a/Datastore/src/V1/ResultSetStats.php b/Datastore/src/V1/ResultSetStats.php deleted file mode 100644 index 636ee1fc5106..000000000000 --- a/Datastore/src/V1/ResultSetStats.php +++ /dev/null @@ -1,153 +0,0 @@ -google.datastore.v1.ResultSetStats - */ -class ResultSetStats extends \Google\Protobuf\Internal\Message -{ - /** - * Plan for the query. - * - * Generated from protobuf field .google.datastore.v1.QueryPlan query_plan = 1; - */ - private $query_plan = null; - /** - * Aggregated statistics from the execution of the query. - * This will only be present when the request specifies `PROFILE` mode. - * For example, a query will return the statistics including: - * { - * "results_returned": "20", - * "documents_scanned": "20", - * "indexes_entries_scanned": "10050", - * "total_execution_time": "100.7 msecs" - * } - * - * Generated from protobuf field .google.protobuf.Struct query_stats = 2; - */ - private $query_stats = null; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type \Google\Cloud\Datastore\V1\QueryPlan $query_plan - * Plan for the query. - * @type \Google\Protobuf\Struct $query_stats - * Aggregated statistics from the execution of the query. - * This will only be present when the request specifies `PROFILE` mode. - * For example, a query will return the statistics including: - * { - * "results_returned": "20", - * "documents_scanned": "20", - * "indexes_entries_scanned": "10050", - * "total_execution_time": "100.7 msecs" - * } - * } - */ - public function __construct($data = NULL) { - \GPBMetadata\Google\Datastore\V1\QueryProfile::initOnce(); - parent::__construct($data); - } - - /** - * Plan for the query. - * - * Generated from protobuf field .google.datastore.v1.QueryPlan query_plan = 1; - * @return \Google\Cloud\Datastore\V1\QueryPlan|null - */ - public function getQueryPlan() - { - return $this->query_plan; - } - - public function hasQueryPlan() - { - return isset($this->query_plan); - } - - public function clearQueryPlan() - { - unset($this->query_plan); - } - - /** - * Plan for the query. - * - * Generated from protobuf field .google.datastore.v1.QueryPlan query_plan = 1; - * @param \Google\Cloud\Datastore\V1\QueryPlan $var - * @return $this - */ - public function setQueryPlan($var) - { - GPBUtil::checkMessage($var, \Google\Cloud\Datastore\V1\QueryPlan::class); - $this->query_plan = $var; - - return $this; - } - - /** - * Aggregated statistics from the execution of the query. - * This will only be present when the request specifies `PROFILE` mode. - * For example, a query will return the statistics including: - * { - * "results_returned": "20", - * "documents_scanned": "20", - * "indexes_entries_scanned": "10050", - * "total_execution_time": "100.7 msecs" - * } - * - * Generated from protobuf field .google.protobuf.Struct query_stats = 2; - * @return \Google\Protobuf\Struct|null - */ - public function getQueryStats() - { - return $this->query_stats; - } - - public function hasQueryStats() - { - return isset($this->query_stats); - } - - public function clearQueryStats() - { - unset($this->query_stats); - } - - /** - * Aggregated statistics from the execution of the query. - * This will only be present when the request specifies `PROFILE` mode. - * For example, a query will return the statistics including: - * { - * "results_returned": "20", - * "documents_scanned": "20", - * "indexes_entries_scanned": "10050", - * "total_execution_time": "100.7 msecs" - * } - * - * Generated from protobuf field .google.protobuf.Struct query_stats = 2; - * @param \Google\Protobuf\Struct $var - * @return $this - */ - public function setQueryStats($var) - { - GPBUtil::checkMessage($var, \Google\Protobuf\Struct::class); - $this->query_stats = $var; - - return $this; - } - -} - diff --git a/Datastore/src/V1/RollbackRequest.php b/Datastore/src/V1/RollbackRequest.php index 218b10d193c3..8e823c1778c8 100644 --- a/Datastore/src/V1/RollbackRequest.php +++ b/Datastore/src/V1/RollbackRequest.php @@ -20,7 +20,7 @@ class RollbackRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string project_id = 8 [(.google.api.field_behavior) = REQUIRED]; */ - private $project_id = ''; + protected $project_id = ''; /** * The ID of the database against which to make the request. * '(default)' is not allowed; please use empty string '' to refer the default @@ -28,14 +28,14 @@ class RollbackRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string database_id = 9; */ - private $database_id = ''; + protected $database_id = ''; /** * Required. The transaction identifier, returned by a call to * [Datastore.BeginTransaction][google.datastore.v1.Datastore.BeginTransaction]. * * Generated from protobuf field bytes transaction = 1 [(.google.api.field_behavior) = REQUIRED]; */ - private $transaction = ''; + protected $transaction = ''; /** * @param string $projectId Required. The ID of the project against which to make the request. diff --git a/Datastore/src/V1/RunAggregationQueryRequest.php b/Datastore/src/V1/RunAggregationQueryRequest.php index 28c405b65164..85f561b5e40b 100644 --- a/Datastore/src/V1/RunAggregationQueryRequest.php +++ b/Datastore/src/V1/RunAggregationQueryRequest.php @@ -21,7 +21,7 @@ class RunAggregationQueryRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string project_id = 8 [(.google.api.field_behavior) = REQUIRED]; */ - private $project_id = ''; + protected $project_id = ''; /** * The ID of the database against which to make the request. * '(default)' is not allowed; please use empty string '' to refer the default @@ -29,7 +29,7 @@ class RunAggregationQueryRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string database_id = 9; */ - private $database_id = ''; + protected $database_id = ''; /** * Entities are partitioned into subsets, identified by a partition ID. * Queries are scoped to a single partition. @@ -38,20 +38,20 @@ class RunAggregationQueryRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.datastore.v1.PartitionId partition_id = 2; */ - private $partition_id = null; + protected $partition_id = null; /** * The options for this query. * * Generated from protobuf field .google.datastore.v1.ReadOptions read_options = 1; */ - private $read_options = null; + protected $read_options = null; /** * Optional. Explain options for the query. If set, additional query * statistics will be returned. If not, only query results will be returned. * * Generated from protobuf field .google.datastore.v1.ExplainOptions explain_options = 11 [(.google.api.field_behavior) = OPTIONAL]; */ - private $explain_options = null; + protected $explain_options = null; protected $query_type; /** diff --git a/Datastore/src/V1/RunAggregationQueryResponse.php b/Datastore/src/V1/RunAggregationQueryResponse.php index 4996b8888ca9..0ebff5e68fa2 100644 --- a/Datastore/src/V1/RunAggregationQueryResponse.php +++ b/Datastore/src/V1/RunAggregationQueryResponse.php @@ -21,13 +21,13 @@ class RunAggregationQueryResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.datastore.v1.AggregationResultBatch batch = 1; */ - private $batch = null; + protected $batch = null; /** * The parsed form of the `GqlQuery` from the request, if it was set. * * Generated from protobuf field .google.datastore.v1.AggregationQuery query = 2; */ - private $query = null; + protected $query = null; /** * The identifier of the transaction that was started as part of this * RunAggregationQuery request. @@ -38,7 +38,7 @@ class RunAggregationQueryResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field bytes transaction = 5; */ - private $transaction = ''; + protected $transaction = ''; /** * Query explain metrics. This is only present when the * [RunAggregationQueryRequest.explain_options][google.datastore.v1.RunAggregationQueryRequest.explain_options] @@ -46,7 +46,7 @@ class RunAggregationQueryResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.datastore.v1.ExplainMetrics explain_metrics = 9; */ - private $explain_metrics = null; + protected $explain_metrics = null; /** * Constructor. diff --git a/Datastore/src/V1/RunQueryRequest.php b/Datastore/src/V1/RunQueryRequest.php index 2d1f158a209c..a622f98a1e1e 100644 --- a/Datastore/src/V1/RunQueryRequest.php +++ b/Datastore/src/V1/RunQueryRequest.php @@ -20,7 +20,7 @@ class RunQueryRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string project_id = 8 [(.google.api.field_behavior) = REQUIRED]; */ - private $project_id = ''; + protected $project_id = ''; /** * The ID of the database against which to make the request. * '(default)' is not allowed; please use empty string '' to refer the default @@ -28,7 +28,7 @@ class RunQueryRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string database_id = 9; */ - private $database_id = ''; + protected $database_id = ''; /** * Entities are partitioned into subsets, identified by a partition ID. * Queries are scoped to a single partition. @@ -37,13 +37,13 @@ class RunQueryRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.datastore.v1.PartitionId partition_id = 2; */ - private $partition_id = null; + protected $partition_id = null; /** * The options for this query. * * Generated from protobuf field .google.datastore.v1.ReadOptions read_options = 1; */ - private $read_options = null; + protected $read_options = null; /** * The properties to return. * This field must not be set for a projection query. @@ -52,14 +52,14 @@ class RunQueryRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.datastore.v1.PropertyMask property_mask = 10; */ - private $property_mask = null; + protected $property_mask = null; /** * Optional. Explain options for the query. If set, additional query * statistics will be returned. If not, only query results will be returned. * * Generated from protobuf field .google.datastore.v1.ExplainOptions explain_options = 12 [(.google.api.field_behavior) = OPTIONAL]; */ - private $explain_options = null; + protected $explain_options = null; protected $query_type; /** diff --git a/Datastore/src/V1/RunQueryResponse.php b/Datastore/src/V1/RunQueryResponse.php index 51d00b4fc007..752570362949 100644 --- a/Datastore/src/V1/RunQueryResponse.php +++ b/Datastore/src/V1/RunQueryResponse.php @@ -21,13 +21,13 @@ class RunQueryResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.datastore.v1.QueryResultBatch batch = 1; */ - private $batch = null; + protected $batch = null; /** * The parsed form of the `GqlQuery` from the request, if it was set. * * Generated from protobuf field .google.datastore.v1.Query query = 2; */ - private $query = null; + protected $query = null; /** * The identifier of the transaction that was started as part of this * RunQuery request. @@ -38,7 +38,7 @@ class RunQueryResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field bytes transaction = 5; */ - private $transaction = ''; + protected $transaction = ''; /** * Query explain metrics. This is only present when the * [RunQueryRequest.explain_options][google.datastore.v1.RunQueryRequest.explain_options] @@ -46,7 +46,7 @@ class RunQueryResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.datastore.v1.ExplainMetrics explain_metrics = 9; */ - private $explain_metrics = null; + protected $explain_metrics = null; /** * Constructor. diff --git a/Datastore/src/V1/TransactionOptions/PBReadOnly.php b/Datastore/src/V1/TransactionOptions/PBReadOnly.php index 2852b0972c58..3ec9287bffb8 100644 --- a/Datastore/src/V1/TransactionOptions/PBReadOnly.php +++ b/Datastore/src/V1/TransactionOptions/PBReadOnly.php @@ -23,7 +23,7 @@ class PBReadOnly extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.protobuf.Timestamp read_time = 1; */ - private $read_time = null; + protected $read_time = null; /** * Constructor. @@ -87,7 +87,7 @@ public function setReadTime($var) } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(PBReadOnly::class, \Google\Cloud\Datastore\V1\TransactionOptions_ReadOnly::class); +// Adding a class alias for backwards compatibility with the "readonly" keyword. +class_alias(PBReadOnly::class, __NAMESPACE__ . '\ReadOnly'); diff --git a/Datastore/src/V1/TransactionOptions/ReadOnly.php b/Datastore/src/V1/TransactionOptions/ReadOnly.php index dd90e2031428..f6ef4bbabdcc 100644 --- a/Datastore/src/V1/TransactionOptions/ReadOnly.php +++ b/Datastore/src/V1/TransactionOptions/ReadOnly.php @@ -4,16 +4,6 @@ namespace Google\Cloud\Datastore\V1\TransactionOptions; -if (version_compare(PHP_VERSION, '8.1', '<')) { - $readOnlyClass = <<bytes previous_transaction = 1; */ - private $previous_transaction = ''; + protected $previous_transaction = ''; /** * Constructor. @@ -65,6 +65,4 @@ public function setPreviousTransaction($var) } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(ReadWrite::class, \Google\Cloud\Datastore\V1\TransactionOptions_ReadWrite::class); diff --git a/Datastore/src/V1/TransactionOptions_ReadOnly.php b/Datastore/src/V1/TransactionOptions_ReadOnly.php deleted file mode 100644 index 540ab73f7ac0..000000000000 --- a/Datastore/src/V1/TransactionOptions_ReadOnly.php +++ /dev/null @@ -1,16 +0,0 @@ -int32 meaning = 14; */ - private $meaning = 0; + protected $meaning = 0; /** * If the value should be excluded from all indexes including those defined * explicitly. * * Generated from protobuf field bool exclude_from_indexes = 19; */ - private $exclude_from_indexes = false; + protected $exclude_from_indexes = false; protected $value_type; /** diff --git a/Datastore/src/V1/resources/datastore_descriptor_config.php b/Datastore/src/V1/resources/datastore_descriptor_config.php index 533cf81dbb42..3d24f64fd44e 100644 --- a/Datastore/src/V1/resources/datastore_descriptor_config.php +++ b/Datastore/src/V1/resources/datastore_descriptor_config.php @@ -1,6 +1,6 @@ checkAndSkipGrpcTests(); - - $this->requestWrapper = $this->prophesize(GrpcRequestWrapper::class); - $this->successMessage = 'success'; - $this->serializer = new Serializer; - } - - public function testApiEndpoint() - { - $expected = 'foobar.com'; - - $grpc = new GrpcStub(['apiEndpoint' => $expected]); - - $this->assertEquals($expected, $grpc->config['apiEndpoint']); - } - - public function testAllocateIds() - { - $key = [ - 'partitionId' => [ - 'projectId' => self::PROJECT_ID - ], - 'path' => [ - [ - 'kind' => 'foo' - ] - ] - ]; - - $args = [ - 'projectId' => self::PROJECT_ID, - 'keys' => [$key], - ]; - - $expectedArgs = [ - self::PROJECT_ID, - [$this->serializer->decodeMessage(new Key, $key)], - [] - ]; - - $this->assertRunsServiceCall('allocateIds', $args, $expectedArgs); - } - - public function testBeginTransaction() - { - $args = [ - 'projectId' => self::PROJECT_ID, - 'transactionOptions' => [ - 'readWrite' => [ - 'previousTransaction' => '1234' - ] - ] - ]; - - $expectedArgs = [ - self::PROJECT_ID, - [ - 'transactionOptions' => $this->serializer->decodeMessage( - new TransactionOptions, - $args['transactionOptions'] - ) - ] - ]; - - $this->assertRunsServiceCall('beginTransaction', $args, $expectedArgs); - } - - /** - * @dataProvider modes - */ - public function testCommit($mode) - { - $timestamp = new Timestamp(new \DateTime); - - $mutation = [ - 'insert' => [ - 'key' => [ - 'partitionId' => [ - 'projectId' => self::PROJECT_ID - ], - 'path' => [ - [ - 'kind' => 'foo', - 'id' => 1 - ] - ] - ], - 'properties' => [ - 'prop' => [ - 'stringValue' => 'val' - ], - 'nullVal' => [ - 'nullValue' => null - ], - 'time' => [ - 'timestampValue' => $timestamp->formatAsString() - ], - 'point' => [ - 'geoPointValue' => [ - 'latitude' => 1.0, - 'longitude' => null - ] - ] - ] - ] - ]; - - $args = [ - 'projectId' => self::PROJECT_ID, - 'mode' => $mode, - 'mutations' => [ - $mutation - ] - ]; - - $mutation['insert']['properties']['nullVal']['nullValue'] = NullValue::NULL_VALUE; - $mutation['insert']['properties']['time']['timestampValue'] = $timestamp->formatForApi(); - $mutation['insert']['properties']['point']['geoPointValue'] = [ - 'latitude' => 1.0, - 'longitude' => 0.0 - ]; - - $expectedArgs = [ - self::PROJECT_ID, - constant(Mode::class .'::' . $mode), - [$this->serializer->decodeMessage(new Mutation, $mutation)], - [] - ]; - - $this->assertRunsServiceCall('commit', $args, $expectedArgs); - } - - public function modes() - { - return [ - ['TRANSACTIONAL'], - ['NON_TRANSACTIONAL'] - ]; - } - - /** - * @dataProvider readOptions - */ - public function testLookup($readOptions, $readOptionsProto) - { - $args = [ - 'projectId' => self::PROJECT_ID, - 'keys' => [ - [ - 'partitionId' => [ - 'projectId' => self::PROJECT_ID, - 'namespaceId' => 'foobar' - ], - 'path' => [ - [ - 'kind' => 'person', - 'name' => 'steve' - ] - ] - ] - ], - 'readOptions' => $readOptions - ]; - - $keysList = []; - foreach ($args['keys'] as $key) { - $keysList[] = $this->serializer->decodeMessage(new Key, $key); - } - - $expectedArgs = [ - self::PROJECT_ID, - $keysList, - [ - 'readOptions' => $readOptionsProto - ] - ]; - - $this->assertRunsServiceCall('lookup', $args, $expectedArgs); - } - - public function readOptions() - { - $this->setUp(); - - $readOptionsTransaction = [ - 'transaction' => 1234 - ]; - - $strongConsistency = [ - 'readConsistency' => 'STRONG' - ]; - - $strongConsistencyProto = new ReadOptions([ - 'read_consistency' => ReadConsistency::STRONG - ]); - - $eventualConsistency = [ - 'readConsistency' => 'EVENTUAL' - ]; - - $eventualConsistencyProto = new ReadOptions([ - 'read_consistency' => ReadConsistency::EVENTUAL - ]); - - return [ - [ - $readOptionsTransaction, - $this->serializer->decodeMessage(new ReadOptions, $readOptionsTransaction) - ], [ - $strongConsistency, - $strongConsistencyProto - ], [ - $eventualConsistency, - $eventualConsistencyProto - ] - ]; - } - - public function testRollback() - { - $args = [ - 'projectId' => self::PROJECT_ID, - 'transaction' => '1234' - ]; - - $expectedArgs = [ - self::PROJECT_ID, - '1234', - [] - ]; - - $this->assertRunsServiceCall('rollback', $args, $expectedArgs); - } - - public function testRunQuery() - { - $timestamp = new Timestamp(new \DateTime); - - $query = [ - 'order' => [ - [ - 'property' => [ - 'name' => 'foo' - ], - 'direction' => 'DESCENDING', - ], [ - 'property' => [ - 'name' => 'bar' - ], - 'direction' => 'ASCENDING' - ] - ], - 'limit' => 500 - ]; - - $gqlQuery = [ - 'queryString' => 'SELECT 1=1', - 'allowLiterals' => false, - 'namedBindings' => [ - 'foo' => [ - 'value' => [ - 'timestampValue' => $timestamp->formatAsString() - ] - ], - 'bar' => [ - 'cursor' => '1234' - ] - ], - 'positionalBindings' => [ - [ - 'value' => [ - 'timestampValue' => $timestamp->formatAsString() - ] - ], [ - 'cursor' => '531252' - ] - ] - ]; - - $args = [ - 'projectId' => self::PROJECT_ID, - 'partitionId' => [ - 'projectId' => self::PROJECT_ID, - 'namespaceId' => 'foobar' - ], - 'readOptions' => [ - 'transaction' => '1234' - ], - 'query' => $query, - 'gqlQuery' => $gqlQuery - ]; - - $gqlQuery['namedBindings']['foo']['value']['timestampValue'] = $timestamp->formatForApi(); - $gqlQuery['positionalBindings'][0]['value']['timestampValue'] = $timestamp->formatForApi(); - - $expectedArgs = [ - self::PROJECT_ID, - $this->serializer->decodeMessage(new PartitionId, $args['partitionId']), - [ - 'readOptions' => $this->serializer->decodeMessage(new ReadOptions, $args['readOptions']), - 'query' => $this->serializer->decodeMessage(new Query, [ - 'order' => [ - [ - 'property' => [ - 'name' => 'foo' - ], - 'direction' => Direction::DESCENDING - ], - [ - 'property' => [ - 'name' => 'bar' - ], - 'direction' => Direction::ASCENDING - ] - ], - 'limit' => [ - 'value' => 500 - ] - ]), - 'gqlQuery' => $this->serializer->decodeMessage(new GqlQuery, $gqlQuery), - ] - ]; - - $this->assertRunsServiceCall('runQuery', $args, $expectedArgs); - } - - /** - * @dataProvider propertyFilters - */ - public function testQueryPropertyFilters($operator) - { - $query = [ - 'filter' => [ - 'propertyFilter' => [ - 'property' => [ - 'name' => 'foo' - ], - 'op' => $operator, - 'value' => [ - 'stringValue' => 'bar' - ] - ] - ] - ]; - - $args = [ - 'projectId' => self::PROJECT_ID, - 'partitionId' => [ - 'projectId' => self::PROJECT_ID, - ], - 'query' => $query - ]; - - $operator = $query['filter']['propertyFilter']['op']; - $constName = PropertyFilterOperator::class .'::'. $operator; - $query['filter']['propertyFilter']['op'] = defined($constName) - ? constant($constName) - : 0; - - $expectedArgs = [ - self::PROJECT_ID, - $this->serializer->decodeMessage(new PartitionId, $args['partitionId']), - [ - 'query' => $this->serializer->decodeMessage(new Query, $query) - ] - ]; - - $this->assertRunsServiceCall('runQuery', $args, $expectedArgs); - } - - public function testQueryCompositeFilter() - { - $query = [ - 'filter' => [ - 'compositeFilter' => [ - 'op' => 'AND', - 'filters' => [ - [ - 'propertyFilter' => [ - 'property' => [ - 'name' => 'foo' - ], - 'op' => 'EQUAL', - 'value' => [ - 'stringValue' => 'bar' - ] - ] - ], [ - 'compositeFilter' => [ - 'op' => 'AND', - 'filters' => [ - [ - 'propertyFilter' => [ - 'property' => [ - 'name' => 'foo' - ], - 'op' => 'EQUAL', - 'value' => [ - 'stringValue' => 'bar' - ] - ] - ] - ] - ] - ] - ] - ] - ] - ]; - - $args = [ - 'projectId' => self::PROJECT_ID, - 'partitionId' => [ - 'projectId' => self::PROJECT_ID, - ], - 'query' => $query - ]; - - $query['filter']['compositeFilter']['op'] = CompositeFilterOperator::PBAND; - $query['filter']['compositeFilter']['filters'][0]['propertyFilter']['op'] = PropertyFilterOperator::EQUAL; - - $query['filter']['compositeFilter']['filters'][1]['compositeFilter']['op'] = CompositeFilterOperator::PBAND; - $query['filter']['compositeFilter']['filters'][1]['compositeFilter']['filters'][0]['propertyFilter']['op'] - = PropertyFilterOperator::EQUAL; - - $expectedArgs = [ - self::PROJECT_ID, - $this->serializer->decodeMessage(new PartitionId, $args['partitionId']), - [ - 'query' => $this->serializer->decodeMessage(new Query, $query) - ] - ]; - - $this->assertRunsServiceCall('runQuery', $args, $expectedArgs); - } - - public function propertyFilters() - { - return [ - ['LESS_THAN'], - ['LESS_THAN_OR_EQUAL'], - ['GREATER_THAN'], - ['GREATER_THAN_OR_EQUAL'], - ['EQUAL'], - ['HAS_ANCESTOR'], - ]; - } - - /** - * @dataProvider invalidFilters - */ - public function testInvalidFilter($filter) - { - $this->expectException(InvalidArgumentException::class); - - return $this->testQueryPropertyFilters($filter); - } - - public function invalidFilters() - { - return [ - ['F00'], - [9999999] - ]; - } - - private function assertRunsServiceCall($method, $args, $expectedArgs, $return = null, $result = '') - { - $this->requestWrapper->send( - Argument::type('callable'), - $expectedArgs, - Argument::type('array') - )->willReturn($return ?: $this->successMessage); - - $grpc = new Grpc(); - $grpc->setRequestWrapper($this->requestWrapper->reveal()); - - $this->assertEquals($result !== '' ? $result : $this->successMessage, $grpc->$method($args)); - } -} - -//@codingStandardsIgnoreStart -class GrpcStub extends Grpc -{ - public $config; - - protected function constructGapic($gapicName, array $config) - { - $this->config = $config; - - return parent::constructGapic($gapicName, $config); - } -} -//@codingStandardsIgnoreEnd diff --git a/Datastore/tests/Unit/Connection/RestTest.php b/Datastore/tests/Unit/Connection/RestTest.php deleted file mode 100644 index de7303ffdb51..000000000000 --- a/Datastore/tests/Unit/Connection/RestTest.php +++ /dev/null @@ -1,161 +0,0 @@ -requestWrapper = $this->prophesize(RequestWrapper::class); - $this->successBody = '{"canI":"kickIt"}'; - } - - public function testApiEndpoint() - { - $endpoint = 'https://foobar.com/'; - $rest = TestHelpers::stub(Rest::class, [ - [ - 'apiEndpoint' => $endpoint - ] - ], ['requestBuilder']); - - $rb = $rest->___getProperty('requestBuilder'); - $r = new \ReflectionObject($rb); - $p = $r->getProperty('baseUri'); - $p->setAccessible(true); - - $this->assertEquals($endpoint, $p->getValue($rb)); - } - - /** - * @dataProvider methodProvider - * @todo revisit this approach - */ - public function testCallBasicMethods($method) - { - $options = []; - $request = new Request('GET', '/somewhere'); - $response = new Response(200, [], $this->successBody); - - $requestBuilder = $this->prophesize(RequestBuilder::class); - $requestBuilder->build( - Argument::type('string'), - Argument::type('string'), - Argument::type('array') - )->willReturn($request); - - $this->requestWrapper->send( - Argument::type(RequestInterface::class), - Argument::type('array') - )->willReturn($response); - - $rest = new Rest(); - $rest->setRequestBuilder($requestBuilder->reveal()); - $rest->setRequestWrapper($this->requestWrapper->reveal()); - - $this->assertEquals(json_decode($this->successBody, true), $rest->$method($options)); - } - - /** - * @dataProvider methodProvider - */ - public function testSendWithRoutingHeaders($method) - { - $optionsWithDatabaseId = ['databaseId' => 'dbId']; - $optionsWithProjectId = ['projectId' => 'prodId']; - - $request = new Request('GET', '/somewhere'); - $requestBuilder = $this->prophesize(RequestBuilder::class); - $requestBuilder->build( - Argument::type('string'), - Argument::type('string'), - Argument::type('array') - )->willReturn($request); - - $rest = new Rest(); - $rest->setRequestBuilder($requestBuilder->reveal()); - - $args = []; - $this->validateMethodHasHeaders($rest, $method, $args, false); - - $args = $optionsWithDatabaseId; - $this->validateMethodHasHeaders($rest, $method, $args, false); - - $args = $optionsWithProjectId; - $this->validateMethodHasHeaders($rest, $method, $args, false); - - $args = $optionsWithProjectId + $optionsWithDatabaseId; - $this->validateMethodHasHeaders($rest, $method, $args, true); - } - - public function methodProvider() - { - return [ - ['allocateIds'], - ['beginTransaction'], - ['commit'], - ['lookup'], - ['rollback'], - ['runQuery'], - ]; - } - - private function validateMethodHasHeaders($rest, $method, $args, $isHeaderExpected) - { - $isCalled = 0; - $this->requestWrapper->send( - Argument::type(RequestInterface::class), - Argument::that(function ($options) use ($isHeaderExpected, $args, &$isCalled) { - $isCalled++; - if ($isHeaderExpected) { - $expectedHeaderValue = sprintf( - 'project_id=%s&database_id=%s', - $args['projectId'], - $args['databaseId'] - ); - return $expectedHeaderValue === - $options['restOptions']['headers']['x-goog-request-params']; - } else { - return !isset($options['restOptions']['headers']['x-goog-request-params']); - } - }) - )->willReturn(new Response(200, [], $this->successBody)); - $rest->setRequestWrapper($this->requestWrapper->reveal()); - $rest->$method($args); - $this->assertEquals(1, $isCalled); - } -} diff --git a/Datastore/tests/Unit/DatastoreClientTest.php b/Datastore/tests/Unit/DatastoreClientTest.php index 36cb51ac0471..983eb04acb37 100644 --- a/Datastore/tests/Unit/DatastoreClientTest.php +++ b/Datastore/tests/Unit/DatastoreClientTest.php @@ -17,19 +17,20 @@ namespace Google\Cloud\Datastore\Tests\Unit; +use DateTime; +use Google\ApiCore\Transport\TransportInterface; use Google\Cloud\Core\Int64; use Google\Cloud\Core\Testing\DatastoreOperationRefreshTrait; use Google\Cloud\Core\Testing\GrpcTestTrait; use Google\Cloud\Core\Testing\TestHelpers; use Google\Cloud\Core\Timestamp; use Google\Cloud\Datastore\Blob; -use Google\Cloud\Datastore\Connection\ConnectionInterface; -use Google\Cloud\Datastore\Connection\Grpc; -use Google\Cloud\Datastore\Connection\Rest; use Google\Cloud\Datastore\DatastoreClient; use Google\Cloud\Datastore\Entity; +use Google\Cloud\Datastore\EntityMapper; use Google\Cloud\Datastore\GeoPoint; use Google\Cloud\Datastore\Key; +use Google\Cloud\Datastore\Operation; use Google\Cloud\Datastore\Query\AggregationQuery; use Google\Cloud\Datastore\Query\AggregationQueryResult; use Google\Cloud\Datastore\Query\GqlQuery; @@ -38,9 +39,26 @@ use Google\Cloud\Datastore\ReadOnlyTransaction; use Google\Cloud\Datastore\Transaction; use Google\Cloud\Datastore\V1\ExplainOptions; +use Google\Cloud\Datastore\V1\Client\DatastoreClient as GapicClient; use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Google\Cloud\Datastore\V1\CommitRequest; +use Google\Cloud\Datastore\V1\CommitResponse; +use Google\Cloud\Datastore\V1\Entity as V1Entity; +use Google\Cloud\Datastore\V1\EntityResult; +use Google\Cloud\Datastore\V1\LookupRequest; +use Google\Cloud\Datastore\V1\LookupResponse; use Prophecy\PhpUnit\ProphecyTrait; +use Google\Cloud\Datastore\V1\AllocateIdsRequest; +use Google\Cloud\Datastore\V1\AllocateIdsResponse; +use Google\Cloud\Datastore\V1\BeginTransactionRequest; +use Google\Cloud\Datastore\V1\BeginTransactionResponse; +use Google\Cloud\Datastore\V1\Key as V1Key; +use Google\Cloud\Datastore\V1\RunAggregationQueryRequest; +use Google\Cloud\Datastore\V1\RunAggregationQueryResponse; +use Google\Cloud\Datastore\V1\RunQueryRequest; +use Google\Cloud\Datastore\V1\RunQueryResponse; +use Google\Protobuf\Timestamp as ProtobufTimestamp; /** * @group datastore @@ -53,43 +71,21 @@ class DatastoreClientTest extends TestCase use ProphecyTrait; const PROJECT = 'example-project'; + const DATABASE = 'example-database'; const TRANSACTION = 'transaction-id'; - private $connection; private $client; + private $gapicClient; + private $operation; public function setUp(): void { - $this->connection = $this->prophesize(ConnectionInterface::class); - $this->client = TestHelpers::stub(DatastoreClient::class, [ - ['projectId' => self::PROJECT] - ], [ - 'operation' - ]); - } - - public function testGrpcConnection() - { - $this->checkAndSkipGrpcTests(); - - $client = TestHelpers::stub(DatastoreClient::class, [[ + $this->gapicClient = $this->prophesize(GapicClient::class); + $this->client = new DatastoreClient([ 'projectId' => self::PROJECT, - 'transport' => 'grpc', - ]]); - - $this->assertInstanceOf(Grpc::class, $client->___getProperty('connection')); - } - - public function testRestConnection() - { - $this->checkAndSkipGrpcTests(); - - $client = TestHelpers::stub(DatastoreClient::class, [[ - 'projectId' => self::PROJECT, - 'transport' => 'rest', - ]]); - - $this->assertInstanceOf(Rest::class, $client->___getProperty('connection')); + 'databaseId' => self::DATABASE, + 'datastoreClient' => $this->gapicClient->reveal() + ]); } public function testKeyIncomplete() @@ -180,317 +176,377 @@ public function testGeoPoint() ]); } - /** - * @dataProvider allocateIdProvider - */ - public function testAllocateId($method, $batch = false) - { - $key = new Key('foo'); - $key->pathElement('Person'); - $id = 12345; - $keyWithId = clone $key; - $keyWithId->setLastElementIdentifier($id); - - $this->connection->allocateIds(Argument::withEntry('keys', [ - $key->keyObject() - ]))->shouldBeCalled()->willReturn([ - 'keys' => [ - $keyWithId->keyObject() - ] - ]); + public function testAllocateId() + { + // 1. Setup keys and expected gRPC request/response + $incompleteKey = $this->client->key('Person'); + $id = 123; + $completeKey = $this->client->key('Person', $id); - $this->refreshOperation($this->client, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $v1IncompleteKey = new V1Key(); + $v1IncompleteKey->mergeFromJsonString(json_encode($incompleteKey->keyObject())); - $res = $batch - ? $this->client->$method([$key])[0] - : $this->client->$method($key); + $v1CompleteKey = new V1Key(); + $v1CompleteKey->mergeFromJsonString(json_encode($completeKey->keyObject())); - $this->assertInstanceOf(Key::class, $res); - $this->assertEquals($id, $res->pathEnd()['id']); - $this->assertEquals('Person', $res->pathEnd()['kind']); - } + $request = (new AllocateIdsRequest()) + ->setProjectId(self::PROJECT) + ->setDatabaseId(self::DATABASE) + ->setKeys([$v1IncompleteKey]); - public function allocateIdProvider() - { - return [ - ['allocateId'], - ['allocateIds', true] - ]; + $response = new AllocateIdsResponse(); + $response->setKeys([$v1CompleteKey]); + + // 2. Set expectation on the mocked GapicClient + $this->gapicClient->allocateIds($request, []) + ->shouldBeCalled(1) + ->willReturn($response); + + // 5. Call the method under test + $responseKey = $this->client->allocateId($incompleteKey); + + // 6. Assert the result + $this->assertInstanceOf(Key::class, $responseKey); + $this->assertEquals($id, $responseKey->pathEndIdentifier()); + $this->assertEquals('Person', $responseKey->pathEnd()['kind']); } - /** - * @dataProvider transactionProvider - */ - public function testTransaction($method, $type, $key) + public function testAllocateIds() { - $this->connection->beginTransaction(Argument::allOf( - Argument::withEntry('projectId', self::PROJECT), - // can't do direct comparisons between (object)[]. - Argument::that(function ($arg) use ($key) { - if (!($arg['transactionOptions'][$key] instanceof \stdClass)) { - return false; - } + $incompleteKeys = [$this->client->key('Person'), $this->client->key('Book')]; + $ids = [123, 456]; + $completeKeys = [$this->client->key('Person', $ids[0]), $this->client->key('Book', $ids[1])]; - if ((array) $arg['transactionOptions'][$key]) { - return false; - } + $incompleteKey1 = new V1Key(); + $incompleteKey1->mergeFromJsonString(json_encode($incompleteKeys[0]->keyObject())); + $incompleteKey2 = new V1Key(); + $incompleteKey2->mergeFromJsonString(json_encode($incompleteKeys[1]->keyObject())); - return true; - }) - ))->shouldBeCalled()->willReturn([ - 'transaction' => self::TRANSACTION - ]); + $v1IncompleteKeys = [ + $incompleteKey1, + $incompleteKey2 + ]; + $v1CompleteKey1 = new V1Key(); + $v1CompleteKey1->mergeFromJsonString(json_encode($completeKeys[0]->keyObject())); + $v1CompleteKey2 = new V1Key(); + $v1CompleteKey2->mergeFromJsonString(json_encode($completeKeys[1]->keyObject())); + $v1CompleteKeys = [ + $v1CompleteKey1, + $v1CompleteKey2 + ]; - $this->refreshOperation($this->client, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $request = (new AllocateIdsRequest())->setProjectId(self::PROJECT)->setDatabaseId(self::DATABASE)->setKeys($v1IncompleteKeys); + $response = (new AllocateIdsResponse())->setKeys($v1CompleteKeys); - $res = $this->client->$method(); - $this->assertInstanceOf($type, $res); - } + $this->gapicClient->allocateIds($request, [])->shouldBeCalled(1)->willReturn($response); - /** - * @dataProvider transactionProvider - */ - public function testTransactionWithOptions($method, $type, $key) - { - $options = ['foo' => 'bar']; + $responseKeys = $this->client->allocateIds($incompleteKeys); - $this->connection->beginTransaction(Argument::allOf( - Argument::withEntry('projectId', self::PROJECT), - Argument::withEntry('transactionOptions', [ - $key => $options - ]) - ))->shouldBeCalled()->willReturn([ - 'transaction' => self::TRANSACTION - ]); + $this->assertCount(2, $responseKeys); + $this->assertEquals($ids[0], $responseKeys[0]->pathEndIdentifier()); + $this->assertEquals($ids[1], $responseKeys[1]->pathEndIdentifier()); + } - // Make sure the correct transaction ID was injected. - $this->connection->runQuery(Argument::withEntry('transaction', self::TRANSACTION)) - ->shouldBeCalled() - ->willReturn([]); + public function testTransaction() + { + $expectedId = 'transactionString'; - $this->refreshOperation($this->client, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $response = new BeginTransactionResponse(); + $response->setTransaction($expectedId); + + $this->gapicClient->beginTransaction(Argument::that(function (BeginTransactionRequest $request) { + $this->assertEquals($request->getProjectId(), self::PROJECT); + $this->assertEquals($request->getDatabaseId(), self::DATABASE); + $this->assertNotNull($request->getTransactionOptions()->getReadWrite()); + return true; + }), []) + ->shouldBeCalled(1) + ->willReturn($response); - $res = $this->client->$method(['transactionOptions' => $options]); - $this->assertInstanceOf($type, $res); + $expectedTransaction = new Transaction( + $this->getOperationMock(), + self::PROJECT, + base64_encode($expectedId) + ); - iterator_to_array($res->runQuery($this->client->gqlQuery('SELECT 1=1'))); + $response = $this->client->transaction(); + $this->assertInstanceOf(Transaction::class, $response); + $this->assertEquals($expectedTransaction, $response); } - public function transactionProvider() + public function testReadOnlyTransaction() { - return [ - ['readOnlyTransaction', ReadOnlyTransaction::class, 'readOnly'], - ['transaction', Transaction::class, 'readWrite'] - ]; + $expectedId = 'transactionString'; + + $expectedTransaction = new ReadOnlyTransaction( + $this->getOperationMock(), + self::PROJECT, + base64_encode($expectedId) + ); + + $response = new BeginTransactionResponse(); + $response->setTransaction($expectedId); + + $this->gapicClient->beginTransaction(Argument::that(function (BeginTransactionRequest $request) { + $this->assertEquals($request->getProjectId(), self::PROJECT); + $this->assertEquals($request->getDatabaseId(), self::DATABASE); + $this->assertNotNull($request->getTransactionOptions()->getReadOnly()); + return true; + }), [])->shouldBeCalled(1)->willReturn($response); + + $response = $this->client->readOnlyTransaction(); + $this->assertInstanceOf(ReadOnlyTransaction::class, $response); + $this->assertEquals($expectedTransaction, $response); } - /** - * @dataProvider mutationsProvider - */ - public function testEntityMutations($method, $mutation, $key) + public function testTransactionWithOptions() { - $this->connection->commit(Argument::allOf( - Argument::withEntry('transaction', null), - Argument::withEntry('mode', 'NON_TRANSACTIONAL'), - Argument::withEntry('mutations', [[$method => $mutation]]) - ))->shouldBeCalled()->willReturn($this->commitResponse()); + $options = ['previousTransaction' => 'previousId']; + $expectedTransaction = new Transaction( + $this->getOperationMock(), + self::PROJECT, + base64_encode(self::TRANSACTION), + $options + ); - $this->refreshOperation($this->client, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $response = (new BeginTransactionResponse())->setTransaction('transaction-id'); - $entity = $this->client->entity($key, ['name' => 'John']); - $res = $this->client->$method($entity, ['allowOverwrite' => true]); + $this->gapicClient->beginTransaction(Argument::that(function(BeginTransactionRequest $request){ + $this->assertEquals($request->getProjectId(), self::PROJECT); + $this->assertEquals($request->getDatabaseId(), self::DATABASE); + $previousTransaction = $request->getTransactionOptions() + ->getReadWrite() + ->getPreviousTransaction(); + $this->assertNotEmpty($previousTransaction); + $this->assertEquals(base64_decode('previousId'), $previousTransaction); + return true; + }), [])->shouldBeCalled(1)->willReturn( + $response + ); - $this->assertEquals($this->commitResponse()['mutationResults'][0]['version'], $res); + $res = $this->client->transaction(['transactionOptions' => $options]); + $this->assertInstanceOf(Transaction::class, $res); + $this->assertEquals($expectedTransaction, $res); } - /** - * @dataProvider mutationsProvider - */ - public function testEntityMutationsBatch($method, $mutation, $key) + public function testReadOnlyTransactionWithOptions() { - $this->connection->commit(Argument::allOf( - Argument::withEntry('transaction', null), - Argument::withEntry('mode', 'NON_TRANSACTIONAL'), - Argument::withEntry('mutations', [[$method => $mutation]]) - ))->shouldBeCalled()->willReturn($this->commitResponse()); + $dateTime = new DateTime(); + $timestamp = new Timestamp($dateTime); + $options = ['readTime' => $timestamp]; + $expectedTransaction = new ReadOnlyTransaction( + $this->getOperationMock(), + self::PROJECT, + base64_encode(self::TRANSACTION), + $options + ); + + $response = new BeginTransactionResponse(); + $response->setTransaction(self::TRANSACTION); + + $this->gapicClient->beginTransaction(Argument::that(function(BeginTransactionRequest $request) use ($timestamp) { + $this->assertEquals($request->getProjectId(), self::PROJECT); + $this->assertEquals($request->getDatabaseId(), self::DATABASE); + $readTime = $request->getTransactionOptions() + ->getReadOnly() + ->getReadTime(); + $this->assertNotEmpty($readTime); + $this->assertNull($request->getTransactionOptions()->getReadWrite()); + return true; + }), [])->shouldBeCalled(1)->willReturn( + $response + ); + + $res = $this->client->readOnlyTransaction(['transactionOptions' => $options]); + $this->assertInstanceOf(ReadOnlyTransaction::class, $res); + $this->assertEquals($expectedTransaction, $res); + } + + public function testDatastoreCrudOperations() + { + $key = $this->client->key('Person', 'jeff'); + $data = ['firstName' => 'Jeff']; + $entity = $this->client->entity($key, $data); - $this->refreshOperation($this->client, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + // Common commit response for mutations + $commitResponse = new CommitResponse(); + $commitResponse->mergeFromJsonString(json_encode($this->commitResponse())); + + // 1. Test Insert + $this->gapicClient->commit(Argument::that(function(CommitRequest $request) { + switch ($request->getMutations()[0]->getOperation()) { + case 'insert': + case 'update': + case 'upsert': + case 'delete': + return true; + default: + $this->fail('Unexpected value received to the commit function'); + return false; + } + return true; + }), Argument::any())->shouldBeCalledTimes(4) + ->willReturn($commitResponse); - $method .= 'Batch'; + $this->client->insert($entity); - $entity = $this->client->entity($key, ['name' => 'John']); - $res = $this->client->$method([$entity], ['allowOverwrite' => true]); + // 2. Test Update + $updateData = ['firstName' => 'Jeffrey']; + $updateEntity = $this->client->entity($key, $updateData, ['populatedByService' => true]); - $this->assertEquals($this->commitResponse(), $res); + $this->client->update($updateEntity); + + // 3. Test Upsert + $upsertData = ['firstName' => 'Geoff']; + $upsertEntity = $this->client->entity($key, $upsertData); + + $this->client->upsert($upsertEntity); + + // 4. Test Delete + $this->client->delete($key); } - public function mutationsProvider() + public function testDatastoreBatchCrudOperations() { - return $this->mutationsProviderProvider(123245); - } + $key1 = $this->client->key('Person', 'jeff'); + $key2 = $this->client->key('Person', 'bob'); + $keys = [$key1, $key2]; - /** - * @dataProvider partialKeyMutationsProvider - */ - public function testMutationsWithPartialKey($method, $mutation, $key, $id) - { - $this->connection->commit(Argument::allOf( - Argument::withEntry('transaction', null), - Argument::withEntry('mode', 'NON_TRANSACTIONAL'), - Argument::withEntry('mutations', [[$method => $mutation]]) - ))->shouldBeCalled()->willReturn($this->commitResponse()); - - $keyWithId = clone $key; - $keyWithId->setLastElementIdentifier($id); - $this->connection->allocateIds(Argument::allOf( - Argument::withEntry('keys', [$key->keyObject()]) - ))->shouldBeCalled()->willReturn([ - 'keys' => [ - $keyWithId->keyObject() - ] - ]); + $entity1 = $this->client->entity($key1, ['firstName' => 'Jeff']); + $entity2 = $this->client->entity($key2, ['firstName' => 'Bob']); + $entities = [$entity1, $entity2]; - $this->refreshOperation($this->client, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + // Common commit response for mutations + $commitResponse = new CommitResponse(); + $commitResponse->mergeFromJsonString(json_encode($this->commitResponse())); - $entity = $this->client->entity($key, ['name' => 'John']); - $this->client->$method($entity); - } + // Set all expectations up front + $this->gapicClient->commit(Argument::that(function (CommitRequest $request) { + $mutations = $request->getMutations(); + if (count($mutations) !== 2) return false; + return $mutations[0]->getOperation() == 'insert' && $mutations[1]->getOperation() == 'insert'; + }), Argument::any())->shouldBeCalledTimes(1)->willReturn($commitResponse); - /** - * @dataProvider partialKeyMutationsProvider - */ - public function testBatchMutationsWithPartialKey($method, $mutation, $key, $id) - { - $this->connection->commit(Argument::allOf( - Argument::withEntry('transaction', null), - Argument::withEntry('mode', 'NON_TRANSACTIONAL'), - Argument::withEntry('mutations', [[$method => $mutation]]) - ))->shouldBeCalled()->willReturn($this->commitResponse()); - - $keyWithId = clone $key; - $keyWithId->setLastElementIdentifier($id); - $this->connection->allocateIds(Argument::allOf( - Argument::withEntry('keys', [$key->keyObject()]) - ))->shouldBeCalled()->willReturn([ - 'keys' => [ - $keyWithId->keyObject() - ] - ]); + $this->gapicClient->commit(Argument::that(function (CommitRequest $request) { + $mutations = $request->getMutations(); + if (count($mutations) !== 2) return false; + return $mutations[0]->getOperation() == 'update' && $mutations[1]->getOperation() == 'update'; + }), Argument::any())->shouldBeCalledTimes(1)->willReturn($commitResponse); - $this->refreshOperation($this->client, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $this->gapicClient->commit(Argument::that(function (CommitRequest $request) { + $mutations = $request->getMutations(); + if (count($mutations) !== 2) return false; + return $mutations[0]->getOperation() == 'upsert' && $mutations[1]->getOperation() == 'upsert'; + }), Argument::any())->shouldBeCalledTimes(1)->willReturn($commitResponse); - $method .= 'Batch'; - $entity = $this->client->entity($key, ['name' => 'John']); - $this->client->$method([$entity]); - } + $this->gapicClient->commit(Argument::that(function (CommitRequest $request) { + $mutations = $request->getMutations(); + if (count($mutations) !== 2) return false; + return $mutations[0]->getOperation() == 'delete' && $mutations[1]->getOperation() == 'delete'; + }), Argument::any())->shouldBeCalledTimes(1)->willReturn($commitResponse); - public function partialKeyMutationsProvider() - { - $res = $this->mutationsProviderProvider(12345, true); - return array_filter($res, function ($case) { - return $case[0] !== 'update'; - }); + // Execute the operations + // 1. Test insertBatch + $this->client->insertBatch($entities); + + // 2. Test updateBatch + $updateEntity1 = $this->client->entity($key1, ['firstName' => 'Jeffrey'], ['populatedByService' => true]); + $updateEntity2 = $this->client->entity($key2, ['firstName' => 'Bobby'], ['populatedByService' => true]); + $this->client->updateBatch([$updateEntity1, $updateEntity2]); + + // 3. Test upsertBatch + $upsertEntity1 = $this->client->entity($key1, ['firstName' => 'Geoff']); + $upsertEntity2 = $this->client->entity($key2, ['firstName' => 'Rob']); + $this->client->upsertBatch([$upsertEntity1, $upsertEntity2]); + + // 4. Test deleteBatch + $this->client->deleteBatch($keys); } - public function testSingleMutationConflict() + public function testInsertBatchWithIncompleteKey() { - $this->expectException(\DomainException::class); + [$incompleteEntities, $protoIncompleteKeys, $protoCompleteKeys] = $this->getTestData(); + $response = new AllocateIdsResponse(); + $response->setKeys($protoCompleteKeys); - $this->connection->commit(Argument::any()) - ->shouldBeCalled() - ->willReturn([ - 'mutationResults' => [ - [ - 'conflictDetected' => true - ] - ] - ]); + $commitResponse = new CommitResponse(); + $commitResponse->mergeFromJsonString(json_encode($this->commitResponse())); - $this->refreshOperation($this->client, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $this->gapicClient->allocateIds(Argument::type(AllocateIdsRequest::class), []) + ->shouldBeCalled(1) + ->willReturn($response); - $entity = $this->client->entity($this->client->key('test', 'test'), ['name' => 'John']); - $this->client->insert($entity); + $this->gapicClient->commit(Argument::that(function (CommitRequest $request) { + if (count($request->getMutations()) !== 2) { + return false; + } + + return $request->getMutations()[0]->getOperation() == 'insert' && $request->getMutations()[1]->getOperation() == 'insert'; + }), Argument::any()) + ->shouldBeCalled(1) + ->willReturn($commitResponse); + + $this->client->insertBatch($incompleteEntities); } - public function testDelete() + public function testUpsertBatchWithIncompleteKey() { - $key = $this->client->key('Person', 'John'); + [$incompleteEntities, $protoIncompleteKeys, $protoCompleteKeys] = $this->getTestData(); + $response = new AllocateIdsResponse(); + $response->setKeys($protoCompleteKeys); - $this->connection->commit(Argument::allOf( - Argument::withEntry('transaction', null), - Argument::withEntry('mode', 'NON_TRANSACTIONAL'), - Argument::withEntry('mutations', [ - [ - 'delete' => $key->keyObject() - ] - ]) - ))->shouldBeCalled()->willReturn($this->commitResponse()); + $commitResponse = new CommitResponse(); + $commitResponse->mergeFromJsonString(json_encode($this->commitResponse())); - $this->refreshOperation($this->client, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $this->gapicClient->allocateIds(Argument::type(AllocateIdsRequest::class), []) + ->shouldBeCalled(1) + ->willReturn($response); - $res = $this->client->delete($key); + $this->gapicClient->commit(Argument::that(function (CommitRequest $request) { + if (count($request->getMutations()) !== 2) { + return false; + } - $this->assertEquals($this->commitResponse()['mutationResults'][0]['version'], $res); + return $request->getMutations()[0]->getOperation() == 'upsert' && $request->getMutations()[1]->getOperation() == 'upsert'; + }), Argument::any()) + ->shouldBeCalled(1) + ->willReturn($commitResponse); + + $this->client->upsertBatch($incompleteEntities); } - public function testDeleteBatch() + public function testSingleMutationConflict() { - $key = $this->client->key('Person', 'John'); - - $this->connection->commit(Argument::allOf( - Argument::withEntry('transaction', null), - Argument::withEntry('mode', 'NON_TRANSACTIONAL'), - Argument::withEntry('mutations', [ - [ - 'delete' => $key->keyObject() - ] - ]) - ))->shouldBeCalled()->willReturn($this->commitResponse()); + $this->expectException(\DomainException::class); - $this->refreshOperation($this->client, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $commitResponse = new CommitResponse(); + $commitResponse->mergeFromJsonString(json_encode($this->conflictCommitResponse())); - $res = $this->client->deleteBatch([$key]); + $this->gapicClient->commit(Argument::type(CommitRequest::class), Argument::any()) + ->shouldBeCalled(1) + ->willReturn($commitResponse); - $this->assertEquals($this->commitResponse(), $res); + $entity = $this->client->entity($this->client->key('test', 'test'), ['name' => 'John']); + $this->client->insert($entity); } public function testLookup() { $key = $this->client->key('Person', 'John'); - $this->connection->lookup( - Argument::withEntry('keys', [$key->keyObject()]) - )->shouldBeCalled()->willReturn([ + $data = [ 'found' => [ [ 'entity' => $this->entityArray($key) ] ] - ]); + ]; + $response = new LookupResponse(); + $response->mergeFromJsonString(json_encode($data)); - $this->refreshOperation($this->client, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $this->gapicClient->lookup(Argument::type(LookupRequest::class), Argument::any()) + ->shouldBeCalled(1) + ->willReturn($response); $key = $this->client->key('Person', 'John'); $res = $this->client->lookup($key); @@ -502,19 +558,19 @@ public function testLookupMissing() { $key = $this->client->key('Person', 'John'); - $this->connection->lookup( - Argument::withEntry('keys', [$key->keyObject()]) - )->shouldBeCalled()->willReturn([ + $data = [ 'missing' => [ [ 'entity' => $this->entityArray($key) ] ] - ]); + ]; + $response = new LookupResponse(); + $response->mergeFromJsonString(json_encode($data)); - $this->refreshOperation($this->client, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $this->gapicClient->lookup(Argument::type(LookupRequest::class), Argument::any()) + ->shouldBeCalled(1) + ->willReturn($response); $key = $this->client->key('Person', 'John'); $res = $this->client->lookup($key); @@ -525,9 +581,7 @@ public function testLookupBatch() { $key = $this->client->key('Person', 'John'); - $this->connection->lookup( - Argument::withEntry('keys', [$key->keyObject()]) - )->shouldBeCalled()->willReturn([ + $data = [ 'found' => [ [ 'entity' => $this->entityArray($key) @@ -541,14 +595,18 @@ public function testLookupBatch() 'deferred' => [ $key->keyObject() ] - ]); + ]; - $this->refreshOperation($this->client, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $response = new LookupResponse(); + $response->mergeFromJsonString(json_encode($data)); + + $this->gapicClient->lookup(Argument::type(LookupRequest::class), Argument::any()) + ->shouldBeCalled(1) + ->willReturn($response); $key = $this->client->key('Person', 'John'); $res = $this->client->lookupBatch([$key]); + $this->assertInstanceOf(Entity::class, $res['found'][0]); $this->assertInstanceOf(Key::class, $res['missing'][0]); $this->assertInstanceOf(Key::class, $res['deferred'][0]); @@ -558,20 +616,25 @@ public function testLookupBatchWithReadTime() { $key = $this->client->key('Person', 'John'); $time = new Timestamp(new \DateTime()); + $protoTime = new ProtobufTimestamp(); + $protoTime->mergeFromJsonString(json_encode($time)); - $this->connection->lookup( - Argument::withEntry('readTime', $time) - )->shouldBeCalled()->willReturn([ + $data = [ 'found' => [ [ 'entity' => $this->entityArray($key) ] ] - ]); + ]; - $this->refreshOperation($this->client, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $response = new LookupResponse(); + $response->mergeFromJsonString(json_encode($data)); + + $this->gapicClient->lookup(Argument::that(function(LookupRequest $request) use ($protoTime) { + return $request->getReadOptions()->getReadTime()->getSeconds() === $protoTime->getSeconds(); + }), Argument::any()) + ->shouldBeCalled(1) + ->willReturn($response); $res = $this->client->lookupBatch([$key], ['readTime' => $time]); $this->assertInstanceOf(Entity::class, $res['found'][0]); @@ -581,21 +644,25 @@ public function testLookupWithReadTime() { $key = $this->client->key('Person', 'John'); $time = new Timestamp(new \DateTime()); + $protoTime = new ProtobufTimestamp(); + $protoTime->mergeFromJsonString(json_encode($time)); - $this->connection->lookup(Argument::allOf( - Argument::withEntry('keys', [$key->keyObject()]), - Argument::withEntry('readTime', $time) - ))->shouldBeCalled()->willReturn([ + $data = [ 'found' => [ [ 'entity' => $this->entityArray($key) ] ] - ]); + ]; - $this->refreshOperation($this->client, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $response = new LookupResponse(); + $response->mergeFromJsonString(json_encode($data)); + + $this->gapicClient->lookup(Argument::that(function(LookupRequest $request) use ($protoTime) { + return $request->getReadOptions()->getReadTime()->getSeconds() === $protoTime->getSeconds(); + }), Argument::any()) + ->shouldBeCalled(1) + ->willReturn($response); $res = $this->client->lookup($key, ['readTime' => $time]); $this->assertInstanceOf(Entity::class, $res); @@ -621,10 +688,7 @@ public function testRunQuery() { $key = $this->client->key('Person', 'John'); - $this->connection->runQuery(Argument::allOf( - Argument::withEntry('partitionId', ['projectId' => self::PROJECT]), - Argument::withEntry('gqlQuery', ['queryString' => 'SELECT 1=1']) - ))->shouldBeCalled()->willReturn([ + $data = [ 'batch' => [ 'entityResults' => [ [ @@ -632,15 +696,18 @@ public function testRunQuery() ] ] ] - ]); + ]; + $response = new RunQueryResponse(); + $response->mergeFromJsonString(json_encode($data)); - $this->refreshOperation($this->client, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $this->gapicClient->runQuery(Argument::type(RunQueryRequest::class), Argument::any()) + ->shouldBeCalled(1) + ->willReturn($response); $query = $this->prophesize(QueryInterface::class); $query->queryKey()->willReturn('gqlQuery'); $query->queryObject()->willReturn(['queryString' => 'SELECT 1=1']); + $query->canPaginate()->willReturn(true); $res = iterator_to_array($this->client->runQuery($query->reveal())); $this->assertContainsOnlyInstancesOf(Entity::class, $res); @@ -648,25 +715,28 @@ public function testRunQuery() public function testRunAggregationQuery() { - $this->connection->runAggregationQuery(Argument::allOf( - Argument::withEntry('partitionId', ['projectId' => self::PROJECT]), - Argument::withEntry('gqlQuery', [ - 'queryString' => 'AGGREGATE (COUNT(*)) over (SELECT 1=1)' - ]) - ))->shouldBeCalled()->willReturn([ + $time = new Timestamp(new \DateTime()); + + $data = [ 'batch' => [ 'aggregationResults' => [ [ - 'aggregateProperties' => ['property_1' => 1] + 'aggregateProperties' => [ + 'property_1' => [ + 'integerValue' => 1 + ] + ] ] ], - 'readTime' => (new \DateTime)->format('Y-m-d\TH:i:s') .'.000001Z' + 'readTime' => $time ] - ]); + ]; + $response = new RunAggregationQueryResponse(); + $response->mergeFromJsonString(json_encode($data)); - $this->refreshOperation($this->client, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $this->gapicClient->runAggregationQuery(Argument::type(RunAggregationQueryRequest::class), Argument::any()) + ->shouldBeCalled(1) + ->willReturn($response); $query = $this->prophesize(AggregationQuery::class); $query->queryObject()->willReturn([ @@ -684,25 +754,23 @@ public function testRunAggregationQuery() */ public function testAggregationQueryWithDifferentReturnTypes($response, $expected) { - $this->connection->runAggregationQuery(Argument::allOf( - Argument::withEntry('partitionId', ['projectId' => self::PROJECT]), - Argument::withEntry('gqlQuery', [ - 'queryString' => 'foo bar' - ]) - ))->shouldBeCalled()->willReturn([ + $responseData = [ 'batch' => [ 'aggregationResults' => [ [ 'aggregateProperties' => ['property_1' => $response] ] ], - 'readTime' => (new \DateTime)->format('Y-m-d\TH:i:s') .'.000001Z' + 'readTime' => new Timestamp(new \DateTime()) ] - ]); + ]; - $this->refreshOperation($this->client, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $response = new RunAggregationQueryResponse(); + $response->mergeFromJsonString(json_encode($responseData)); + + $this->gapicClient->runAggregationQuery(Argument::type(RunAggregationQueryRequest::class), Argument::any()) + ->shouldBeCalled(1) + ->willReturn($response); $query = $this->prophesize(AggregationQuery::class); $query->queryObject()->willReturn([ @@ -721,11 +789,7 @@ public function testRunQueryWithReadTime() $key = $this->client->key('Person', 'John'); $time = new Timestamp(new \DateTime()); - $this->connection->runQuery(Argument::allOf( - Argument::withEntry('partitionId', ['projectId' => self::PROJECT]), - Argument::withEntry('gqlQuery', ['queryString' => 'SELECT 1=1']), - Argument::withEntry('readTime', $time) - ))->shouldBeCalled()->willReturn([ + $responseData = [ 'batch' => [ 'entityResults' => [ [ @@ -733,15 +797,19 @@ public function testRunQueryWithReadTime() ] ] ] - ]); + ]; - $this->refreshOperation($this->client, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $response = new RunQueryResponse(); + $response->mergeFromJsonString(json_encode($responseData)); + + $this->gapicClient->runQuery(Argument::type(RunQueryRequest::class), Argument::any()) + ->shouldBeCalled(1) + ->willReturn($response); $query = $this->prophesize(QueryInterface::class); $query->queryKey()->willReturn('gqlQuery'); $query->queryObject()->willReturn(['queryString' => 'SELECT 1=1']); + $query->canPaginate()->willReturn(true); $res = iterator_to_array($this->client->runQuery($query->reveal(), ['readTime' => $time])); $this->assertContainsOnlyInstancesOf(Entity::class, $res); @@ -753,11 +821,7 @@ public function testRunQuerySendsExplainOptions() $explainOptions = new ExplainOptions(); $explainOptions->setAnalyze(true); - $this->connection->runQuery(Argument::allOf( - Argument::withEntry('partitionId', ['projectId' => self::PROJECT]), - Argument::withEntry('gqlQuery', ['queryString' => 'SELECT 1=1']), - Argument::withEntry('explainOptions', $explainOptions) - ))->shouldBeCalled()->willReturn([ + $responseData = [ 'batch' => [ 'entityResults' => [ [ @@ -765,15 +829,18 @@ public function testRunQuerySendsExplainOptions() ] ] ] - ]); + ]; + $response = new RunQueryResponse(); + $response->mergeFromJsonString(json_encode($responseData)); - $this->refreshOperation($this->client, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $this->gapicClient->runQuery(Argument::type(RunQueryRequest::class), Argument::any()) + ->shouldBeCalled(1) + ->willReturn($response); $query = $this->prophesize(QueryInterface::class); $query->queryKey()->willReturn('gqlQuery'); $query->queryObject()->willReturn(['queryString' => 'SELECT 1=1']); + $query->canPaginate()->willReturn(true); $result = $this->client->runQuery($query->reveal(), ['explainOptions' => $explainOptions]); @@ -785,19 +852,10 @@ public function aggregationReturnTypesCases() return [ [['integerValue' => 1], 1], [['doubleValue' => 1.1], 1.1], - - // Returned incase of grpc client - [['doubleValue' => INF], INF], - [['doubleValue' => -INF], -INF], - [['doubleValue' => NAN], NAN], - - // Returned incase of rest client [['doubleValue' => 'Infinity'], INF], [['doubleValue' => '-Infinity'], -INF], [['doubleValue' => 'NaN'], NAN], - - - [['nullValue' => ''], null], + [['nullValue' => null], null], ]; } @@ -812,6 +870,17 @@ private function commitResponse() ]; } + private function conflictCommitResponse() + { + return [ + 'mutationResults' => [ + [ + 'conflictDetected' => true + ] + ] + ]; + } + private function entityArray(Key $key) { return [ @@ -854,4 +923,69 @@ private function compareResult($expected, $actual) $this->assertSame($expected, $actual); } } + + private function getOperationMock(): Operation + { + $entityMapper = new EntityMapper(self::PROJECT, true, false); + return new Operation( + $this->gapicClient->reveal(), + self::PROJECT, + null, // namespaceId + $entityMapper, + self::DATABASE + ); + } + + private function getTestData(): array + { + // Setup keys and entities + $incompleteKey1 = $this->client->key('Person'); + $incompleteKey2 = $this->client->key('Book'); + $incompleteEntities = [ + $this->client->entity($incompleteKey1, ['name' => 'John']), + $this->client->entity($incompleteKey2, ['title' => 'The Stand']) + ]; + $ids = [123, 456]; + + // Setup proto keys + $incompleteProtoKey1 = new V1Key(); + $incompleteProtoKey1->mergeFromJsonString(json_encode($incompleteKey1->keyObject())); + $incompleteProtoKey2 = new V1Key(); + $incompleteProtoKey2->mergeFromJsonString(json_encode($incompleteKey2->keyObject())); + + // Setup complete proto keys + $completeProtoKey1 = new V1Key(); + $completeProtoKey1->mergeFromJsonString(json_encode($this->client->key('Person', $ids[0])->keyObject())); + $completeProtoKey2 = new V1Key(); + $completeProtoKey2->mergeFromJsonString(json_encode($this->client->key('Book', $ids[1])->keyObject())); + + $v1IncompleteKeys = [ + $incompleteProtoKey1, + $incompleteProtoKey2 + ]; + $v1CompleteKeys = [ + $completeProtoKey1, + $completeProtoKey2 + ]; + + return [ + $incompleteEntities, + $v1IncompleteKeys, + $v1CompleteKeys + ]; + } + + private function getClient(null|GapicClient $client): DatastoreClient + { + $config = [ + 'databaseId' => self::DATABASE, + 'projectId' => self::PROJECT + ]; + + if (!is_null($client)) { + $config['client'] = $client; + } + + return new DatastoreClient($config); + } } diff --git a/Datastore/tests/Unit/EntityMapperTest.php b/Datastore/tests/Unit/EntityMapperTest.php index f1937a85af6b..57dc801af2a7 100644 --- a/Datastore/tests/Unit/EntityMapperTest.php +++ b/Datastore/tests/Unit/EntityMapperTest.php @@ -109,11 +109,22 @@ public function testResponseToPropertiesDoubleValue($input, $expected) public function testResponseToPropertiesTimestampValue() { - $date = new \DateTimeImmutable; + $seconds = 1678886400; + $nanos = 123456789; + $microseconds = floor($nanos / 1000); + $date = \DateTimeImmutable::createFromFormat( + 'U.u', + sprintf('%d.%06d', $seconds, $microseconds) + ); $data = [ 'foo' => [ - 'timestampValue' => $date->format(self::DATE_FORMAT) + // This data is after a Proto has been transformed + // by the serializer class + 'timestampValue' => [ + 'seconds' => $seconds, + 'nanos' => $nanos + ] ] ]; @@ -676,16 +687,6 @@ public function testValueObjectInt() $this->assertEquals(1, $int['integerValue']); } - /** - * @dataProvider valueObjectDoubleCases - */ - public function testValueObjectDoubleForGrpcClient($input, $expected) - { - $double = $this->mapper->valueObject($input); - - $this->compareResult($expected, $double['doubleValue']); - } - /** * @dataProvider valueObjectDoubleForRestCases */ @@ -922,16 +923,9 @@ public function datastoreToSimpleDoubleValueCases() { return [ [1.1, 1.1], - - // Happens when using rest client ['Infinity', INF], ['-Infinity', -INF], ['NaN', NAN], - - // Happens when using grpc client - [INF, INF], - [-INF, -INF], - [NAN, NAN] ]; } diff --git a/Datastore/tests/Unit/OperationTest.php b/Datastore/tests/Unit/OperationTest.php index 308f06a9c840..a23c77539c12 100644 --- a/Datastore/tests/Unit/OperationTest.php +++ b/Datastore/tests/Unit/OperationTest.php @@ -18,7 +18,7 @@ namespace Google\Cloud\Datastore\Tests\Unit; use Google\Cloud\Core\Testing\TestHelpers; -use Google\Cloud\Datastore\Connection\ConnectionInterface; +use Google\Cloud\Core\Timestamp; use Google\Cloud\Datastore\Entity; use Google\Cloud\Datastore\EntityIterator; use Google\Cloud\Datastore\EntityMapper; @@ -27,6 +27,23 @@ use Google\Cloud\Datastore\Query\GqlQuery; use Google\Cloud\Datastore\Query\Query; use Google\Cloud\Datastore\Query\QueryInterface; +use Google\Cloud\Datastore\V1\AllocateIdsRequest; +use Google\Cloud\Datastore\V1\AllocateIdsResponse; +use Google\Cloud\Datastore\V1\BeginTransactionRequest; +use Google\Cloud\Datastore\V1\BeginTransactionResponse; +use Google\Cloud\Datastore\V1\Client\DatastoreClient; +use Google\Cloud\Datastore\V1\CommitRequest; +use Google\Cloud\Datastore\V1\CommitRequest\Mode; +use Google\Cloud\Datastore\V1\CommitResponse; +use Google\Cloud\Datastore\V1\Key as V1Key; +use Google\Cloud\Datastore\V1\LookupRequest; +use Google\Cloud\Datastore\V1\LookupResponse; +use Google\Cloud\Datastore\V1\MutationResult; +use Google\Cloud\Datastore\V1\ReadOptions\ReadConsistency; +use Google\Cloud\Datastore\V1\RollbackRequest; +use Google\Cloud\Datastore\V1\RollbackResponse; +use Google\Cloud\Datastore\V1\RunQueryRequest; +use Google\Cloud\Datastore\V1\RunQueryResponse; use InvalidArgumentException; use PHPUnit\Framework\TestCase; use Prophecy\Argument; @@ -39,24 +56,25 @@ class OperationTest extends TestCase { use ProphecyTrait; + use ProtoEncodeTrait; const PROJECT = 'example-project'; const NAMESPACEID = 'namespace-id'; const DATABASEID = 'database-id'; private $operation; - private $connection; + private $gapicClient; public function setUp(): void { - $this->connection = $this->prophesize(ConnectionInterface::class); + $this->gapicClient = $this->prophesize(DatastoreClient::class); $this->operation = TestHelpers::stub(Operation::class, [ - $this->connection->reveal(), + $this->gapicClient->reveal(), self::PROJECT, - null, + self::NAMESPACEID, new EntityMapper('foo', true, false), self::DATABASEID, - ], ['connection', 'namespaceId']); + ], ['gapicClient', 'namespaceId']); } public function testKey() @@ -87,7 +105,6 @@ public function testKeyWithDatabaseId() public function testKeyWithNamespaceIdOverride() { - $this->operation->___setProperty('namespaceId', self::NAMESPACEID); $key = $this->operation->key('Person', 'Bob', [ 'namespaceId' => 'otherNamespace', ]); @@ -226,15 +243,16 @@ public function testAllocateIds() $id = 12345; $keyWithId = clone $key; $keyWithId->setLastElementIdentifier($id); - $this->connection->allocateIds(Argument::withEntry('keys', [$key->keyObject()])) - ->shouldBeCalled() - ->willReturn([ - 'keys' => [ - $keyWithId->keyObject(), - ], - ]); - $this->operation->___setProperty('connection', $this->connection->reveal()); + $responseData = [ + 'keys' => [ + $keyWithId->keyObject(), + ], + ]; + + $this->gapicClient->allocateIds(Argument::type(AllocateIdsRequest::class), Argument::any()) + ->shouldBeCalled() + ->willReturn(self::generateProto(AllocateIdsResponse::class, $responseData)); $res = $this->operation->allocateIds([$key]); @@ -255,11 +273,9 @@ public function testLookup() { $key = $this->operation->key('foo', 'Bar'); - $this->connection->lookup(Argument::type('array')) + $this->gapicClient->lookup(Argument::type(LookupRequest::class), Argument::any()) ->shouldBeCalled() - ->willReturn([]); - - $this->operation->___setProperty('connection', $this->connection->reveal()); + ->willReturn(new LookupResponse()); $res = $this->operation->lookup([$key]); @@ -269,11 +285,12 @@ public function testLookup() public function testLookupFound() { $body = json_decode(file_get_contents(Fixtures::ENTITY_BATCH_LOOKUP_FIXTURE()), true); - $this->connection->lookup(Argument::any())->willReturn([ + + $responseData = [ 'found' => $body, - ]); + ]; - $this->operation->___setProperty('connection', $this->connection->reveal()); + $this->gapicClient->lookup(Argument::any(), Argument::any())->willReturn(self::generateProto(LookupResponse::class, $responseData)); $key = $this->operation->key('Kind', 'ID'); $res = $this->operation->lookup([$key]); @@ -291,11 +308,9 @@ public function testLookupFound() public function testLookupMissing() { $body = json_decode(file_get_contents(Fixtures::ENTITY_BATCH_LOOKUP_FIXTURE()), true); - $this->connection->lookup(Argument::any())->willReturn([ - 'missing' => $body, - ]); - - $this->operation->___setProperty('connection', $this->connection->reveal()); + $this->gapicClient->lookup(Argument::any(), Argument::any())->willReturn( + self::generateProto(LookupResponse::class, ['missing' => $body]) + ); $key = $this->operation->key('Kind', 'ID'); @@ -311,11 +326,9 @@ public function testLookupMissing() public function testLookupDeferred() { $body = json_decode(file_get_contents(Fixtures::ENTITY_BATCH_LOOKUP_FIXTURE()), true); - $this->connection->lookup(Argument::any())->willReturn([ + $this->gapicClient->lookup(Argument::any(), Argument::any())->willReturn(self::generateProto(LookupResponse::class, [ 'deferred' => [$body[0]['entity']['key']], - ]); - - $this->operation->___setProperty('connection', $this->connection->reveal()); + ])); $key = $this->operation->key('Kind', 'ID'); @@ -328,9 +341,9 @@ public function testLookupDeferred() public function testLookupWithReadOptionsFromTransaction() { - $this->connection->lookup(Argument::withKey('readOptions'))->shouldBeCalled()->willReturn([]); - - $this->operation->___setProperty('connection', $this->connection->reveal()); + $this->gapicClient->lookup(Argument::type(LookupRequest::class), Argument::any()) + ->shouldBeCalled() + ->willReturn(self::generateProto(LookupResponse::class, [])); $k = new Key('test-project', [ 'path' => [['kind' => 'kind', 'id' => '123']], @@ -341,24 +354,24 @@ public function testLookupWithReadOptionsFromTransaction() public function testLookupWithReadOptionsFromReadConsistency() { - $this->connection->lookup(Argument::withKey('readOptions'))->shouldBeCalled()->willReturn([]); - - $this->operation->___setProperty('connection', $this->connection->reveal()); + $this->gapicClient->lookup(Argument::that(function (LookupRequest $request) { + return $request->getReadOptions()->getReadConsistency() === ReadConsistency::STRONG; + }), Argument::any()) + ->shouldBeCalled() + ->willReturn(self::generateProto(LookupResponse::class, [])); $k = new Key('test-project', [ 'path' => [['kind' => 'kind', 'id' => '123']], ]); - $this->operation->lookup([$k], ['readConsistency' => 'foo']); + $this->operation->lookup([$k], ['readConsistency' => ReadConsistency::STRONG]); } public function testLookupWithoutReadOptions() { - $this->connection->lookup(Argument::that(function ($args) { - return !isset($args['readOptions']); - }))->shouldBeCalled()->willReturn([]); - - $this->operation->___setProperty('connection', $this->connection->reveal()); + $this->gapicClient->lookup(Argument::that(function (LookupRequest $request) { + return is_null($request->getReadOptions()); + }), Argument::any())->shouldBeCalled()->willReturn(self::generateProto(LookupResponse::class, [])); $k = new Key('test-project', [ 'path' => [['kind' => 'kind', 'id' => '123']], @@ -378,11 +391,10 @@ public function testLookupWithSort() ]); } - $this->connection->lookup(Argument::any())->willReturn([ - 'found' => $data['entities'], - ]); - - $this->operation->___setProperty('connection', $this->connection->reveal()); + $this->gapicClient->lookup(Argument::any(), Argument::any()) + ->willReturn(self::generateProto(LookupResponse::class, [ + 'found' => $data['entities'], + ])); $res = $this->operation->lookup($keys, [ 'sort' => true, @@ -406,12 +418,11 @@ public function testLookupWithoutSort() ]); } - $this->connection->lookup(Argument::any())->willReturn([ - 'found' => $data['entities'], - 'missing' => $data['missing'], - ]); - - $this->operation->___setProperty('connection', $this->connection->reveal()); + $this->gapicClient->lookup(Argument::any(), Argument::any()) + ->willReturn(self::generateProto(LookupResponse::class, [ + 'found' => $data['entities'], + 'missing' => $data['missing'], + ])); $res = $this->operation->lookup($keys); @@ -438,11 +449,10 @@ public function testLookupWithSortAndMissingKey() ]); } - $this->connection->lookup(Argument::any())->willReturn([ - 'found' => $data['entities'], - ]); - - $this->operation->___setProperty('connection', $this->connection->reveal()); + $this->gapicClient->lookup(Argument::any(), Argument::any()) + ->willReturn(self::generateProto(LookupResponse::class, [ + 'found' => $data['entities'], + ])); $res = $this->operation->lookup($keys, [ 'sort' => true, @@ -474,10 +484,8 @@ public function testLookupInvalidKey() public function testRunQuery() { $queryResult = json_decode(file_get_contents(Fixtures::QUERY_RESULTS_FIXTURE()), true); - $this->connection->runQuery(Argument::type('array')) - ->willReturn($queryResult['notPaged']); - - $this->operation->___setProperty('connection', $this->connection->reveal()); + $this->gapicClient->runQuery(Argument::type(RunQueryRequest::class), Argument::any()) + ->willReturn(self::generateProto(RunQueryResponse::class, $queryResult['notPaged'])); $q = $this->prophesize(QueryInterface::class); $q->queryKey()->shouldBeCalled()->willReturn('query'); @@ -497,29 +505,29 @@ public function testRunQuery() /** * @dataProvider queries */ - public function testRunQueryPaged($query) - { - $queryResult = json_decode(file_get_contents(Fixtures::QUERY_RESULTS_FIXTURE()), true); - $this->connection->runQuery(Argument::type('array')) - ->will(function ($args, $mock) use ($queryResult) { - // The 2nd call will return the 2nd page of results! - $mock->runQuery(Argument::that(function ($arg) use ($queryResult) { - return $arg['query']['startCursor'] === $queryResult['paged'][0]['batch']['endCursor']; - }))->willReturn($queryResult['paged'][1]); + // public function testRunQueryPaged($query) + // { + // $queryResult = json_decode(file_get_contents(Fixtures::QUERY_RESULTS_FIXTURE()), true); + // $this->gapicClient->runQuery(Argument::type(RunQueryRequest::class), Argument::any()) + // ->will(function ($args, $mock) use ($queryResult) { + // // The 2nd call will return the 2nd page of results! + // $mock->runQuery(Argument::that(function ($arg) use ($queryResult) { + // return $arg['query']['startCursor'] === $queryResult['paged'][0]['batch']['endCursor']; + // }))->willReturn($queryResult['paged'][1]); - return $queryResult['paged'][0]; - }); + // return $queryResult['paged'][0]; + // }); - $this->operation->___setProperty('connection', $this->connection->reveal()); + // $this->operation->___setProperty('gapicClient', $this->gapicClient->reveal()); - $res = $this->operation->runQuery($query); + // $res = $this->operation->runQuery($query); - $this->assertInstanceOf(EntityIterator::class, $res); + // $this->assertInstanceOf(EntityIterator::class, $res); - $arr = iterator_to_array($res); - $this->assertCount(3, $arr); - $this->assertInstanceOf(Entity::class, $arr[0]); - } + // $arr = iterator_to_array($res); + // $this->assertCount(3, $arr); + // $this->assertInstanceOf(Entity::class, $arr[0]); + // } public function queries() { @@ -535,10 +543,8 @@ public function queries() public function testRunQueryNoResults() { $queryResult = json_decode(file_get_contents(Fixtures::QUERY_RESULTS_FIXTURE()), true); - $this->connection->runQuery(Argument::type('array')) - ->willReturn($queryResult['noResults']); - - $this->operation->___setProperty('connection', $this->connection->reveal()); + $this->gapicClient->runQuery(Argument::type(RunQueryRequest::class), Argument::any()) + ->willReturn(self::generateProto(RunQueryResponse::class, $queryResult['noResults'])); $q = $this->prophesize(QueryInterface::class); $q->queryKey()->shouldBeCalled()->willReturn('query'); @@ -555,10 +561,11 @@ public function testRunQueryNoResults() public function testRunQueryWithReadOptionsFromTransaction() { - $this->connection->runQuery(Argument::withKey('readOptions'))->willReturn([]) - ->shouldBeCalled(); - - $this->operation->___setProperty('connection', $this->connection->reveal()); + $this->gapicClient->runQuery(Argument::that(function (RunQueryRequest $request) { + return !is_null($request->getReadOptions()); + }), Argument::any())->willReturn(self::generateProto(RunQueryResponse::class, [])) + ->shouldBeCalled() + ->willReturn(self::generateProto(RunQueryResponse::class, [])); $q = $this->prophesize(QueryInterface::class); $q->queryKey()->willReturn('query'); @@ -570,26 +577,27 @@ public function testRunQueryWithReadOptionsFromTransaction() public function testRunQueryWithReadOptionsFromReadConsistency() { - $this->connection->runQuery(Argument::withKey('readOptions'))->willReturn([]) - ->shouldBeCalled(); - - $this->operation->___setProperty('connection', $this->connection->reveal()); + $this->gapicClient->runQuery(Argument::that(function (RunQueryRequest $request) { + return !is_null($request->getReadOptions()->getReadConsistency()); + }), Argument::any())->willReturn(self::generateProto(RunQueryResponse::class, [])) + ->shouldBeCalled() + ->willReturn(self::generateProto(RunQueryResponse::class, [])); $q = $this->prophesize(QueryInterface::class); $q->queryKey()->willReturn('query'); $q->queryObject()->willReturn([]); - $res = $this->operation->runQuery($q->reveal(), ['readConsistency' => 'foo']); + $res = $this->operation->runQuery($q->reveal(), ['readConsistency' => ReadConsistency::STRONG]); iterator_to_array($res); } public function testRunQueryWithoutReadOptions() { - $this->connection->runQuery(Argument::that(function ($args) { - return !isset($args['readOptions']); - }))->willReturn([])->shouldBeCalled(); - - $this->operation->___setProperty('connection', $this->connection->reveal()); + $this->gapicClient->runQuery(Argument::that(function (RunQueryRequest $request) { + return is_null($request->getReadOptions()); + }), Argument::any())->willReturn(self::generateProto(RunQueryResponse::class, [])) + ->shouldBeCalled() + ->willReturn(self::generateProto(RunQueryResponse::class, [])); $q = $this->prophesize(QueryInterface::class); $q->queryKey()->willReturn('query'); @@ -601,12 +609,13 @@ public function testRunQueryWithoutReadOptions() public function testRunQueryWithDatabaseIdOverride() { - $this->connection - ->runQuery( - Argument::withEntry('databaseId', 'otherDatabaseId') - ) + $this->gapicClient + ->runQuery(Argument::that(function (RunQueryRequest $request) { + $this->assertEquals('otherDatabaseId', $request->getDatabaseId()); + return true; + }), Argument::any()) ->shouldBeCalledTimes(1) - ->willReturn([]); + ->willReturn(self::generateProto(RunQueryResponse::class, [])); $mapper = new EntityMapper('foo', true, false); $query = new Query($mapper); @@ -620,58 +629,83 @@ public function testRunQueryWithDatabaseIdOverride() public function testCommit() { - $this->connection->commit(Argument::allOf( - Argument::withEntry('mode', 'NON_TRANSACTIONAL'), - Argument::that(function ($arg) { - return count($arg['mutations']) === 0; - }) - ))->shouldBeCalled()->willReturn(['foo']); - - $this->operation->___setProperty('connection', $this->connection->reveal()); + $this->gapicClient->commit(Argument::that(function (CommitRequest $request) { + return ($request->getMode() === Mode::NON_TRANSACTIONAL && + count($request->getMutations()) === 0); + }), Argument::any())->shouldBeCalled() + ->willReturn(self::generateProto(CommitResponse::class, [])); + + $expectedResult = [ + 'mutationResults' => [], + 'indexUpdates' => 0 + ]; - $this->assertEquals(['foo'], $this->operation->commit([])); + $this->assertEquals($expectedResult, $this->operation->commit([])); } public function testCommitInTransaction() { - $this->connection->commit(Argument::allOf( - Argument::withEntry('mode', 'TRANSACTIONAL'), - Argument::that(function ($arg) { - return count($arg['mutations']) === 0; - }) - ))->shouldBeCalled()->willReturn(['foo']); - - $this->operation->___setProperty('connection', $this->connection->reveal()); + $this->gapicClient->commit(Argument::that(function (CommitRequest $request) { + return ($request->getMode() === Mode::TRANSACTIONAL && + count($request->getMutations()) === 0); + }), Argument::any())->shouldBeCalled() + ->willReturn(self::generateProto(CommitResponse::class, [])); - $this->operation->commit([], [ + $response = $this->operation->commit([], [ 'transaction' => '1234', ]); + + $expectedResult = [ + 'mutationResults' => [], + 'indexUpdates' => 0 + ]; + + $this->assertEquals($expectedResult, $response); } public function testCommitWithMutation() { - $this->connection->commit(Argument::that(function ($arg) { - return count($arg['mutations']) === 1; - }))->shouldBeCalled()->willReturn(['foo']); - - $this->operation->___setProperty('connection', $this->connection->reveal()); - $key = $this->operation->key('Person'); $e = new Entity($key); $mutation = $this->operation->mutation('insert', $e, Entity::class, null); - $this->operation->commit([$mutation]); + $allocatedKey = clone $key; + $allocatedKey->setLastElementIdentifier('12345'); + + $commitResponseData = [ + 'mutationResults' => [ + [ + 'key' => $allocatedKey->keyObject(), + 'version' => '1', + 'conflictDetected' => false + ] + ], + 'indexUpdates' => 1 + ]; + + $this->gapicClient->commit(Argument::that(function (CommitRequest $request) { + return count($request->getMutations()) === 1; + }), Argument::any()) + ->shouldBeCalled() + ->willReturn(self::generateProto(CommitResponse::class, $commitResponseData)); + + $res = $this->operation->commit([$mutation]); + + $this->assertIsArray($res); + $this->assertEquals($commitResponseData['indexUpdates'], $res['indexUpdates']); + $this->assertCount(1, $res['mutationResults']); + $this->assertEquals('1', $res['mutationResults'][0]['version']); } public function testCommitWithDatabaseIdOverride() { - $this->connection - ->commit( - Argument::withEntry('databaseId', 'otherDatabaseId') - ) + $this->gapicClient + ->commit(Argument::that(function (CommitRequest $request) { + return $request->getDatabaseId() === 'otherDatabaseId'; + }), Argument::any()) ->shouldBeCalledTimes(1) - ->willReturn([]); + ->willReturn(self::generateProto(CommitResponse::class, [])); $iterator = $this->operation->commit( [], @@ -681,14 +715,15 @@ public function testCommitWithDatabaseIdOverride() public function testRollback() { - $this->connection->rollback(Argument::allOf( - Argument::withEntry('projectId', self::PROJECT), - Argument::withEntry('transaction', 'bar') - ))->shouldBeCalled()->willReturn(null); + $rawTransactionId = 'testTransactionId'; + $decodedId = base64_decode($rawTransactionId); - $this->operation->___setProperty('connection', $this->connection->reveal()); + $this->gapicClient->rollback(Argument::that(function (RollbackRequest $request) use ($decodedId) { + return $request->getProjectId() === self::PROJECT && + $request->getTransaction() === $decodedId; + }), Argument::any())->shouldBeCalled()->willReturn(self::generateProto(RollbackResponse::class, [])); - $this->operation->rollback('bar'); + $this->operation->rollback($rawTransactionId); } public function testAllocateIdsToEntities() @@ -699,15 +734,15 @@ public function testAllocateIdsToEntities() $id = 12345; $keyWithId = clone $partialKey; $keyWithId->setLastElementIdentifier($id); - $this->connection->allocateIds(Argument::withEntry('keys', [$partialKey->keyObject()])) - ->shouldBeCalled() - ->willReturn([ + + $this->gapicClient->allocateIds(Argument::that(function (AllocateIdsRequest $request) { + return count($request->getKeys()) === 1; + }), Argument::any())->shouldBeCalled() + ->willReturn(self::generateProto(AllocateIdsResponse::class, [ 'keys' => [ $keyWithId->keyObject(), ], - ]); - - $this->operation->___setProperty('connection', $this->connection->reveal()); + ])); $entities = [ $this->operation->entity($completeKey), @@ -726,61 +761,109 @@ public function testAllocateIdsToEntities() public function testMutate() { $id = 12345; + $commitResponseData = [ + 'mutationResults' => [ + [ + 'version' => 1, + 'conflictDetected' => false, + 'transformResults' => [] + ] + ], + 'indexUpdates' => 1 + ]; - $this->connection->commit(Argument::that(function ($arg) { - if (count($arg['mutations']) !== 1) { + $this->gapicClient->commit(Argument::that(function (CommitRequest $request) { + if (count($request->getMutations()) !== 1) { return false; } - if (!isset($arg['mutations'][0]['insert'])) { + if (is_null($request->getMutations()[0]->getInsert())) { return false; } return true; - }))->shouldBeCalled(); - - $this->operation->___setProperty('connection', $this->connection->reveal()); + }), Argument::any()) + ->shouldBeCalled() + ->willReturn(self::generateProto(CommitResponse::class, $commitResponseData)); $key = $this->operation->key('Person', $id); $e = new Entity($key); $mutation = $this->operation->mutation('insert', $e, Entity::class, null); - $this->operation->commit([$mutation]); + $res = $this->operation->commit([$mutation]); + + $this->assertEquals($commitResponseData, $res); } + public function testMutateWithBaseVersion() { - $this->connection->commit(Argument::that(function ($arg) { - return $arg['mutations'][0]['baseVersion'] === 1; - }))->willReturn('foo'); + $timestamp = new Timestamp(new \DateTime()); + $commitResponseData = [ + 'mutationResults' => [ + [ + 'version' => 2, + 'conflictDetected' => false, + 'createTime' => $timestamp, + 'updateTime' => $timestamp, + 'transformResults' => [], + ] + ], + 'indexUpdates' => 1, + 'commitTime' => $timestamp, + ]; - $this->operation->___setProperty('connection', $this->connection->reveal()); + $this->gapicClient->commit(Argument::that(function (CommitRequest $request) { + return $request->getMutations()[0]->getBaseVersion() === 1; + }), Argument::any())->willReturn(self::generateProto(CommitResponse::class, $commitResponseData)); - $key = $this->prophesize(Key::class); - $e = new Entity($key->reveal(), [], [ + $key = $this->operation->key('Person', 'Bob'); + $e = new Entity($key, [], [ 'baseVersion' => 1, ]); $mutation = $this->operation->mutation('insert', $e, Entity::class); $ret = $this->operation->commit([$mutation]); - $this->assertEquals('foo', $ret); + + $expected = $commitResponseData; + $encodedTimestamp = [ + 'seconds' => $timestamp->get()->getTimestamp(), + 'nanos' => $timestamp->nanoSeconds() + ]; + $expected['commitTime'] = $encodedTimestamp; + $expected['mutationResults'][0]['createTime'] = $encodedTimestamp; + $expected['mutationResults'][0]['updateTime'] = $encodedTimestamp; + + $this->assertEquals($expected, $ret); } public function testMutateWithKey() { - $this->connection->commit(Argument::that(function ($arg) { - if (!isset($arg['mutations'][0]['delete'])) { + $timestamp = new Timestamp(new \DateTime()); + $commitResponseData = [ + 'mutationResults' => [ + [ + // For a delete, the key is not returned, but a version is. + 'version' => '2', + 'conflictDetected' => false, + 'transformResults' => [], + ] + ], + 'indexUpdates' => 1, + 'commitTime' => $timestamp, + ]; + + $this->gapicClient->commit(Argument::that(function (CommitRequest $request) { + if (is_null($request->getMutations()[0]->getDelete())) { return false; } - if (!isset($arg['mutations'][0]['delete']['path'])) { + if (is_null($request->getMutations()[0]->getDelete()->getPath(0))) { return false; } return true; - }))->willReturn('foo'); - - $this->operation->___setProperty('connection', $this->connection->reveal()); + }), Argument::any())->willReturn(self::generateProto(CommitResponse::class, $commitResponseData)); $key = new Key('foo', [ 'path' => [['kind' => 'foo', 'id' => 1]], @@ -788,7 +871,14 @@ public function testMutateWithKey() $mutation = $this->operation->mutation('delete', $key, Key::class); $ret = $this->operation->commit([$mutation]); - $this->assertEquals('foo', $ret); + + $expected = $commitResponseData; + $encodedTimestamp = [ + 'seconds' => $timestamp->get()->getTimestamp(), + 'nanos' => $timestamp->nanoSeconds() + ]; + $expected['commitTime'] = $encodedTimestamp; + $this->assertEquals($expected, $ret); } public function testMutateInvalidType() @@ -825,16 +915,16 @@ public function testCheckOverwriteWithException() $this->operation->checkOverwrite([$e->reveal()]); } - public function testMapEntityResult() + public function testMapEntityResultFromLookup() { $res = json_decode(file_get_contents(Fixtures::ENTITY_RESULT_FIXTURE()), true); + // Cursors are not returned on lookups, so remove it from the test fixture. + unset($res[0]['cursor']); - $this->connection->lookup(Argument::type('array')) - ->willReturn([ + $this->gapicClient->lookup(Argument::type(LookupRequest::class), Argument::any()) + ->willReturn(self::generateProto(LookupResponse::class, [ 'found' => $res, - ]); - - $this->operation->___setProperty('connection', $this->connection->reveal()); + ])); $key = $this->operation->key('Person', 12345); @@ -842,20 +932,41 @@ public function testMapEntityResult() $this->assertInstanceOf(Entity::class, $entity['found'][0]); $this->assertEquals($entity['found'][0]->baseVersion(), $res[0]['version']); - $this->assertEquals($entity['found'][0]->cursor(), $res[0]['cursor']); + $this->assertNull($entity['found'][0]->cursor()); $this->assertEquals($entity['found'][0]->prop, $res[0]['entity']['properties']['prop']['stringValue']); } + public function testMapEntityResultFromQuery() + { + $res = json_decode(file_get_contents(Fixtures::ENTITY_RESULT_FIXTURE()), true); + + $this->gapicClient->runQuery(Argument::type(RunQueryRequest::class), Argument::any()) + ->willReturn(self::generateProto(RunQueryResponse::class, [ + 'batch' => ['entityResults' => $res] + ])); + + $query = $this->prophesize(QueryInterface::class); + $query->queryKey()->willReturn('query'); + $query->queryObject()->willReturn([]); + $query->canPaginate()->willReturn(true); + + $entities = iterator_to_array($this->operation->runQuery($query->reveal())); + + $this->assertEquals($entities[0]->baseVersion(), $res[0]['version']); + $this->assertEquals($res[0]['cursor'], $entities[0]->cursor()); + $this->assertEquals($entities[0]->prop, $res[0]['entity']['properties']['prop']['stringValue']); + } + public function testMapEntityResultWithoutProperties() { $res = json_decode(file_get_contents(Fixtures::ENTITY_RESULT_NO_PROPERTIES_FIXTURE()), true); + // Cursors are not returned on lookups, so remove it from the test fixture. + unset($res[0]['cursor']); - $this->connection->lookup(Argument::type('array')) - ->willReturn([ + $this->gapicClient->lookup(Argument::type(LookupRequest::class), Argument::any()) + ->willReturn(self::generateProto(LookupResponse::class, [ 'found' => $res, - ]); - - $this->operation->___setProperty('connection', $this->connection->reveal()); + ])); $key = $this->operation->key('Person', 12345); @@ -863,19 +974,17 @@ public function testMapEntityResultWithoutProperties() $this->assertInstanceOf(Entity::class, $entity['found'][0]); $this->assertEquals($entity['found'][0]->baseVersion(), $res[0]['version']); - $this->assertEquals($entity['found'][0]->cursor(), $res[0]['cursor']); + $this->assertNull($entity['found'][0]->cursor()); } public function testMapEntityResultArrayOfClassNames() { $res = json_decode(file_get_contents(Fixtures::ENTITY_RESULT_FIXTURE()), true); - $this->connection->lookup(Argument::type('array')) - ->willReturn([ + $this->gapicClient->lookup(Argument::type(LookupRequest::class), Argument::any()) + ->willReturn(self::generateProto(LookupResponse::class, [ 'found' => $res, - ]); - - $this->operation->___setProperty('connection', $this->connection->reveal()); + ])); $key = $this->operation->key('Person', 12345); @@ -894,12 +1003,10 @@ public function testMapEntityResultArrayOfClassNamesMissingKindMapItem() $res = json_decode(file_get_contents(Fixtures::ENTITY_RESULT_FIXTURE()), true); - $this->connection->lookup(Argument::type('array')) - ->willReturn([ + $this->gapicClient->lookup(Argument::type(LookupRequest::class), Argument::any()) + ->willReturn(self::generateProto(LookupResponse::class, [ 'found' => $res, - ]); - - $this->operation->___setProperty('connection', $this->connection->reveal()); + ])); $key = $this->operation->key('Person', 12345); @@ -912,14 +1019,12 @@ public function testMapEntityResultArrayOfClassNamesMissingKindMapItem() public function testTransactionInReadOptions() { - $this->connection->lookup(Argument::that(function ($arg) { - return isset($arg['readOptions']['transaction']); - })) - ->willReturn([]) + $this->gapicClient->lookup(Argument::that(function (LookupRequest $request) { + return !is_null($request->getReadOptions()->getTransaction()); + }), Argument::any()) + ->willReturn(self::generateProto(LookupResponse::class, [])) ->shouldBeCalled(); - $this->operation->___setProperty('connection', $this->connection->reveal()); - $key = $this->operation->key('Person', 12345); $this->operation->lookup([$key], [ 'transaction' => '1234', @@ -928,29 +1033,26 @@ public function testTransactionInReadOptions() public function testNonTransactionalReadOptions() { - $this->connection->lookup(Argument::that(function ($arg) { - return !isset($arg['readOptions']['transaction']); - })) - ->willReturn([]) + $this->gapicClient->lookup(Argument::that(function (LookupRequest $request) { + return is_null($request->getReadOptions()); + }), Argument::any()) + ->willReturn(self::generateProto(LookupResponse::class, [])) ->shouldBeCalled(); - $this->operation->___setProperty('connection', $this->connection->reveal()); - $key = $this->operation->key('Person', 12345); $this->operation->lookup([$key]); } public function testReadConsistencyInReadOptions() { - $this->connection->lookup(Argument::withEntry('readOptions', ['readConsistency' => 'test'])) - ->willReturn([]) - ->shouldBeCalled(); - - $this->operation->___setProperty('connection', $this->connection->reveal()); + $this->gapicClient->lookup(Argument::that(function (LookupRequest $request) { + return $request->getReadOptions()->getReadConsistency() === ReadConsistency::STRONG; + }), Argument::any())->shouldBeCalled() + ->willReturn(self::generateProto(LookupResponse::class, [])); $key = $this->operation->key('Person', 12345); $this->operation->lookup([$key], [ - 'readConsistency' => 'test', + 'readConsistency' => ReadConsistency::STRONG, ]); } @@ -963,28 +1065,36 @@ public function testInvalidBatchType() public function testBeginTransactionWithDatabaseIdOverride() { - $this->connection + $rawTransactionId = 'valid_test_transaction'; + + $this->gapicClient ->beginTransaction( - Argument::withEntry('databaseId', 'otherDatabaseId') + Argument::that(function (BeginTransactionRequest $request) { + return $request->getDatabaseId() === 'otherDatabaseId'; + }), + Argument::any() ) - ->willReturn(['transaction' => 'valid_test_transaction']); + ->willReturn(self::generateProto(BeginTransactionResponse::class, ['transaction' => base64_encode($rawTransactionId)])); $transactionId = $this->operation->beginTransaction( [], ['databaseId' => 'otherDatabaseId'] ); - $this->assertEquals('valid_test_transaction', $transactionId); + $this->assertEquals(base64_encode($rawTransactionId), $transactionId); } public function testAllocateIdsWithDatabaseIdOverride() { - $this->connection + $this->gapicClient ->allocateIds( - Argument::withEntry('databaseId', 'otherDatabaseId') + Argument::that(function (AllocateIdsRequest $request) { + return $request->getDatabaseId() === 'otherDatabaseId'; + }), + Argument::any() ) ->shouldBeCalledTimes(1) - ->willReturn([]); + ->willReturn(self::generateProto(AllocateIdsResponse::class, [])); $this->operation->allocateIds( [], @@ -994,12 +1104,15 @@ public function testAllocateIdsWithDatabaseIdOverride() public function testLookupWithDatabaseIdOverride() { - $this->connection + $this->gapicClient ->lookup( - Argument::withEntry('databaseId', 'otherDatabaseId') + Argument::that(function (LookupRequest $request) { + return $request->getDatabaseId() === 'otherDatabaseId'; + }), + Argument::any() ) ->shouldBeCalledTimes(1) - ->willReturn([]); + ->willReturn(self::generateProto(LookupResponse::class, [])); $this->operation->lookup( [], diff --git a/Datastore/tests/Unit/ProtoEncodeTrait.php b/Datastore/tests/Unit/ProtoEncodeTrait.php new file mode 100644 index 000000000000..8c1f44dc07ec --- /dev/null +++ b/Datastore/tests/Unit/ProtoEncodeTrait.php @@ -0,0 +1,39 @@ +mergeFromJsonString($json); + + return $message; + } +} diff --git a/Datastore/tests/Unit/TransactionTest.php b/Datastore/tests/Unit/TransactionTest.php index 382dcfc0f454..cdc3d0269cee 100644 --- a/Datastore/tests/Unit/TransactionTest.php +++ b/Datastore/tests/Unit/TransactionTest.php @@ -31,6 +31,20 @@ use Google\Cloud\Datastore\Query\QueryInterface; use Google\Cloud\Datastore\ReadOnlyTransaction; use Google\Cloud\Datastore\Transaction; +use Google\Cloud\Datastore\V1\AllocateIdsRequest; +use Google\Cloud\Datastore\V1\AllocateIdsResponse; +use Google\Cloud\Datastore\V1\Client\DatastoreClient; +use Google\Cloud\Datastore\V1\CommitRequest; +use Google\Cloud\Datastore\V1\CommitRequest\Mode; +use Google\Cloud\Datastore\V1\CommitResponse; +use Google\Cloud\Datastore\V1\LookupRequest; +use Google\Cloud\Datastore\V1\LookupResponse; +use Google\Cloud\Datastore\V1\RollbackRequest; +use Google\Cloud\Datastore\V1\RunAggregationQueryRequest; +use Google\Cloud\Datastore\V1\RunAggregationQueryResponse; +use Google\Cloud\Datastore\V1\RunQueryRequest; +use Google\Cloud\Datastore\V1\RunQueryResponse; +use InvalidArgumentException; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; @@ -43,13 +57,15 @@ */ class TransactionTest extends TestCase { + use ProtoEncodeTrait; use DatastoreOperationRefreshTrait; use ProphecyTrait; const PROJECT = 'example-project'; - const TRANSACTION = 'transaction-id'; + const TRANSACTION = 'base64EncodedId'; - private $connection; + private $gapicClient; + private $operation; private $transaction; private $readOnly; private $key; @@ -57,72 +73,82 @@ class TransactionTest extends TestCase public function setUp(): void { - $this->connection = $this->prophesize(ConnectionInterface::class); + $this->gapicClient = $this->prophesize(DatastoreClient::class); - $op = new Operation( - $this->connection->reveal(), + $this->operation = new Operation( + $this->gapicClient->reveal(), self::PROJECT, null, new EntityMapper(self::PROJECT, false, false) ); - $this->transaction = TestHelpers::stub(Transaction::class, [ - $op, self::PROJECT, self::TRANSACTION - ], ['operation']); + $this->transaction = new Transaction( + $this->operation, + self::PROJECT, + self::TRANSACTION + ); - $this->readOnly = TestHelpers::stub(ReadOnlyTransaction::class, [ - $op, self::PROJECT, self::TRANSACTION - ], ['operation']); + $this->readOnly = new ReadOnlyTransaction( + $this->operation, + self::PROJECT, + self::TRANSACTION + ); - $this->key = $op->key('Person', 12345); - $this->entity = $op->entity($this->key, ['name' => 'John']); + $this->key = $this->operation->key('Person', 12345); + $this->entity = $this->operation->entity($this->key, ['name' => 'John']); } - /** - * @dataProvider transactionProvider - */ - public function testLookup(callable $transaction) + public function testTesting() { - $this->connection->lookup(Argument::allOf( - Argument::withEntry('transaction', self::TRANSACTION), - Argument::withEntry('keys', [$this->key->keyObject()]) - ))->shouldBeCalled()->willReturn([ + $this->gapicClient->lookup( + Argument::type(LookupRequest::class), + Argument::any() + )->shouldBeCalled(1) + ->willReturn(self::generateProto(LookupResponse::class, [ 'found' => [ [ 'entity' => $this->entityArray($this->key) ] ] - ]); + ])); - $transaction = $transaction(); - $this->refreshOperation($transaction, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $transaction = new Transaction($this->operation, self::PROJECT, self::TRANSACTION); $res = $transaction->lookup($this->key); $this->assertInstanceOf(Entity::class, $res); $this->assertEquals($this->key->keyObject(), $res->key()->keyObject()); } - public function testLookupWithReadTime() + /** + * @dataProvider transactionProvider + */ + public function testLookup(string $transactionName) { - $time = new Timestamp(new \DateTime()); - $this->connection->lookup(Argument::allOf( - Argument::withEntry('transaction', self::TRANSACTION), - Argument::withEntry('keys', [$this->key->keyObject()]), - Argument::withEntry('readTime', $time) - ))->shouldBeCalled()->willReturn([ + $this->gapicClient->lookup( + Argument::type(LookupRequest::class), + Argument::any() + )->shouldBeCalled(1) + ->willReturn(self::generateProto(LookupResponse::class, [ 'found' => [ [ 'entity' => $this->entityArray($this->key) ] ] - ]); + ])); - $transaction = $this->readOnly; - $this->refreshOperation($transaction, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $transaction = $this->$transactionName; + + $res = $transaction->lookup($this->key); + $this->assertInstanceOf(Entity::class, $res); + $this->assertEquals($this->key->keyObject(), $res->key()->keyObject()); + } + + public function testLookupWithReadTimeThrowsAnException() + { + $this->expectException(InvalidArgumentException::class); + $time = new Timestamp(new \DateTime()); + + $transaction = $this->transaction; $res = $transaction->lookup($this->key, ['readTime' => $time]); $this->assertInstanceOf(Entity::class, $res); @@ -131,22 +157,20 @@ public function testLookupWithReadTime() /** * @dataProvider transactionProvider */ - public function testLookupMissing(callable $transaction) + public function testLookupMissing(string $transaction) { - $this->connection->lookup( - Argument::withEntry('keys', [$this->key->keyObject()]) - )->shouldBeCalled()->willReturn([ + $this->gapicClient->lookup( + Argument::type(LookupRequest::class), + Argument::any() + )->shouldBeCalled(1)->willReturn(self::generateProto(LookupResponse::class, [ 'missing' => [ [ 'entity' => $this->entityArray($this->key) ] ] - ]); + ])); - $transaction = $transaction(); - $this->refreshOperation($transaction, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $transaction = $this->$transaction; $res = $transaction->lookup($this->key); $this->assertNull($res); @@ -155,11 +179,13 @@ public function testLookupMissing(callable $transaction) /** * @dataProvider transactionProvider */ - public function testLookupBatch(callable $transaction) + public function testLookupBatch(string $transaction) { - $this->connection->lookup( - Argument::withEntry('keys', [$this->key->keyObject()]) - )->shouldBeCalled()->willReturn([ + $this->gapicClient->lookup(Argument::that(function (LookupRequest $request) { + $this->assertEquals(1, count($request->getKeys())); + return true; + }), Argument::any()) + ->shouldBeCalled(1)->willReturn(self::generateProto(LookupResponse::class, [ 'found' => [ [ 'entity' => $this->entityArray($this->key) @@ -173,13 +199,9 @@ public function testLookupBatch(callable $transaction) 'deferred' => [ $this->key->keyObject() ] - ]); - - $transaction = $transaction(); - $this->refreshOperation($transaction, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + ])); + $transaction = $this->$transaction; $res = $transaction->lookupBatch([$this->key]); $this->assertInstanceOf(Entity::class, $res['found'][0]); $this->assertInstanceOf(Key::class, $res['missing'][0]); @@ -189,36 +211,27 @@ public function testLookupBatch(callable $transaction) /** * @dataProvider transactionProvider */ - public function testLookupBatchWithReadTime(callable $transaction) + public function testLookupBatchWithReadTimeThrowsAnException(string $transaction) { + $this->expectException(InvalidArgumentException::class); $time = new Timestamp(new \DateTime()); - $this->connection->lookup( - Argument::withEntry('readTime', $time) - )->shouldBeCalled()->willReturn([ - 'found' => [ - [ - 'entity' => $this->entityArray($this->key) - ] - ] - ]); - $transaction = $transaction(); - $this->refreshOperation($transaction, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $transaction = $this->$transaction; - $res = $transaction->lookupBatch([$this->key], ['readTime' => $time]); + $transaction->lookupBatch([$this->key], ['readTime' => $time]); } /** * @dataProvider transactionProvider */ - public function testRunQuery(callable $transaction) + public function testRunQuery(string $transaction) { - $this->connection->runQuery(Argument::allOf( - Argument::withEntry('partitionId', ['projectId' => self::PROJECT]), - Argument::withEntry('gqlQuery', ['queryString' => 'SELECT 1=1']) - ))->shouldBeCalled()->willReturn([ + $this->gapicClient->runQuery(Argument::that(function (RunQueryRequest $request) { + $this->assertEquals(self::PROJECT, $request->getProjectId()); + $this->assertNotNull($request->getGqlQuery()); + $this->assertEquals('SELECT 1=1', $request->getGqlQuery()->getQueryString()); + return true; + }), Argument::any())->shouldBeCalled(1)->willReturn(self::generateProto(RunQueryResponse::class, [ 'batch' => [ 'entityResults' => [ [ @@ -226,16 +239,14 @@ public function testRunQuery(callable $transaction) ] ] ] - ]); + ])); - $transaction = $transaction(); - $this->refreshOperation($transaction, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $transaction = $this->$transaction; $query = $this->prophesize(QueryInterface::class); $query->queryKey()->willReturn('gqlQuery'); $query->queryObject()->willReturn(['queryString' => 'SELECT 1=1']); + $query->canPaginate()->willReturn(false); $res = iterator_to_array($transaction->runQuery($query->reveal())); $this->assertContainsOnlyInstancesOf(Entity::class, $res); @@ -244,33 +255,33 @@ public function testRunQuery(callable $transaction) /** * @dataProvider transactionProvider */ - public function testRunAggregationQuery(callable $transaction) + public function testRunAggregationQuery(string $transaction) { - $this->connection->runAggregationQuery(Argument::allOf( - Argument::withEntry('partitionId', ['projectId' => self::PROJECT]), - Argument::withEntry('gqlQuery', [ - 'queryString' => 'AGGREGATE (COUNT(*)) over (SELECT 1=1)' - ]) - ))->shouldBeCalled()->willReturn([ - 'batch' => [ - 'aggregationResults' => [ - [ - 'aggregateProperties' => ['property_1' => 1] + $expectedQueryString = 'AGGREGATE (COUNT(*)) over (SELECT 1=1)'; + + $this->gapicClient->runAggregationQuery(Argument::that(function (RunAggregationQueryRequest $request) use ($expectedQueryString) { + $this->assertEquals(self::PROJECT, $request->getPartitionId()->getProjectId()); + $this->assertEquals($expectedQueryString, $request->getGqlQuery()->getQueryString()); + return true; + }), Argument::any())->shouldBeCalled(1) + ->willReturn(self::generateProto(RunAggregationQueryResponse::class, [ + 'batch' => [ + 'aggregationResults' => [ + [ + 'aggregateProperties' => ['property_1' => ['integerValue' => 1]] + ] + ], + 'readTime' => (new \DateTime)->format('Y-m-d\TH:i:s') .'.000001Z' ] - ], - 'readTime' => (new \DateTime)->format('Y-m-d\TH:i:s') .'.000001Z' - ] - ]); + ] + )); - $transaction = $transaction(); - $this->refreshOperation($transaction, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $transaction = $this->$transaction; $query = $this->prophesize(AggregationQuery::class); $query->queryObject()->willReturn([ 'gqlQuery' => [ - 'queryString' => 'AGGREGATE (COUNT(*)) over (SELECT 1=1)' + 'queryString' => $expectedQueryString ] ]); @@ -278,48 +289,32 @@ public function testRunAggregationQuery(callable $transaction) $this->assertInstanceOf(AggregationQueryResult::class, $res); } - public function testRunQueryWithReadTime() + public function testRunQueryWithReadTimeThrowsAnException() { + $this->expectException(InvalidArgumentException::class); + $time = new Timestamp(new \DateTime()); - $this->connection->runQuery(Argument::allOf( - Argument::withEntry('partitionId', ['projectId' => self::PROJECT]), - Argument::withEntry('gqlQuery', ['queryString' => 'SELECT 1=1']), - Argument::withEntry('readTime', $time) - ))->shouldBeCalled()->willReturn([ - 'batch' => [ - 'entityResults' => [ - [ - 'entity' => $this->entityArray($this->key) - ] - ] - ] - ]); $transaction = $this->readOnly; - $this->refreshOperation($transaction, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); $query = $this->prophesize(QueryInterface::class); $query->queryKey()->willReturn('gqlQuery'); $query->queryObject()->willReturn(['queryString' => 'SELECT 1=1']); $res = iterator_to_array($transaction->runQuery($query->reveal(), ['readTime' => $time])); - $this->assertContainsOnlyInstancesOf(Entity::class, $res); } /** * @dataProvider transactionProvider */ - public function testRollback(callable $transaction) + public function testRollback(string $transaction) { - $this->connection->rollback(Argument::withEntry('transaction', self::TRANSACTION)) - ->shouldBeCalled(); + $this->gapicClient->rollback(Argument::that(function (RollbackRequest $request) { + $this->assertEquals(base64_decode(self::TRANSACTION), $request->getTransaction()); + return true; + }))->shouldBeCalled(1); - $transaction = $transaction(); - $this->refreshOperation($transaction, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $transaction = $this->$transaction; $transaction->rollback(); } @@ -329,20 +324,28 @@ public function testRollback(callable $transaction) */ public function testEntityMutations($method, $mutation, $key) { - $this->connection->commit(Argument::allOf( - Argument::withEntry('transaction', self::TRANSACTION), - Argument::withEntry('mode', 'TRANSACTIONAL'), - Argument::withEntry('mutations', [[$method => $mutation]]) - ))->shouldBeCalled()->willReturn($this->commitResponse()); - - $this->refreshOperation($this->transaction, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $expectedResult = [ + 'mutationResults' => [ + [ + 'version' => 1, + 'conflictDetected' => false, + 'transformResults' => [] + ] + ], + 'indexUpdates' => 0 + ]; + + $this->gapicClient->commit(Argument::that(function (CommitRequest $request) { + $this->assertEquals(base64_decode(self::TRANSACTION), $request->getTransaction()); + $this->assertEquals(Mode::TRANSACTIONAL, $request->getMode()); + $this->assertNotEmpty($request->getMutations()); + return true; + }), Argument::any())->shouldBeCalled(1)->willReturn(self::generateProto(CommitResponse::class, $expectedResult)); $this->transaction->$method($this->entity, ['allowOverwrite' => true]); $res = $this->transaction->commit(); - $this->assertEquals($this->commitResponse(), $res); + $this->assertEquals($expectedResult, $res); } /** @@ -350,22 +353,21 @@ public function testEntityMutations($method, $mutation, $key) */ public function testEntityMutationsBatch($method, $mutation, $key) { - $this->connection->commit(Argument::allOf( - Argument::withEntry('transaction', self::TRANSACTION), - Argument::withEntry('mode', 'TRANSACTIONAL'), - Argument::withEntry('mutations', [[$method => $mutation]]) - ))->shouldBeCalled()->willReturn($this->commitResponse()); - - $this->refreshOperation($this->transaction, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $expectedResult = $this->basicCommitResponse(); + + $this->gapicClient->commit(Argument::that(function (CommitRequest $request) { + $this->assertEquals(base64_decode(self::TRANSACTION), $request->getTransaction()); + $this->assertEquals(Mode::TRANSACTIONAL, $request->getMode()); + $this->assertNotEmpty($request->getMutations()); + return true; + }), Argument::any())->shouldBeCalled(1)->willReturn(self::generateProto(CommitResponse::class, $expectedResult)); $method .= 'Batch'; $this->transaction->$method([$this->entity], ['allowOverwrite' => true]); $res = $this->transaction->commit(); - $this->assertEquals($this->commitResponse(), $res); + $this->assertEquals($expectedResult, $res); } public function mutationsProvider() @@ -378,31 +380,31 @@ public function mutationsProvider() */ public function testMutationsWithPartialKey($method, $mutation, $key, $id) { - $this->connection->commit(Argument::allOf( - Argument::withEntry('transaction', self::TRANSACTION), - Argument::withEntry('mode', 'TRANSACTIONAL'), - Argument::withEntry('mutations', [[$method => $mutation]]) - ))->shouldBeCalled()->willReturn($this->commitResponse()); + $expectedResponse = $this->basicCommitResponse(); + + $this->gapicClient->commit(Argument::that(function (CommitRequest $request) { + $this->assertEquals(base64_decode(self::TRANSACTION), $request->getTransaction()); + $this->assertEquals(Mode::TRANSACTIONAL, $request->getMode()); + $this->assertNotEmpty($request->getMutations()); + return true; + }), Argument::any())->shouldBeCalled(1)->willReturn(self::generateProto(CommitResponse::class, $expectedResponse)); $keyWithId = clone $key; $keyWithId->setLastElementIdentifier($id); - $this->connection->allocateIds(Argument::allOf( - Argument::withEntry('keys', [$key->keyObject()]) - ))->shouldBeCalled()->willReturn([ + $this->gapicClient->allocateIds(Argument::that(function (AllocateIdsRequest $request) { + $this->assertEquals(1, count($request->getKeys())); + return true; + }), Argument::any())->shouldBeCalled()->willReturn(self::generateProto(AllocateIdsResponse::class, [ 'keys' => [ $keyWithId->keyObject() ] - ]); - - $this->refreshOperation($this->transaction, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + ])); $entity = new Entity($key, ['name' => 'John']); $this->transaction->$method($entity); $res = $this->transaction->commit(); - $this->assertEquals($this->commitResponse(), $res); + $this->assertEquals($expectedResponse, $res); } /** @@ -410,32 +412,33 @@ public function testMutationsWithPartialKey($method, $mutation, $key, $id) */ public function testBatchMutationsWithPartialKey($method, $mutation, $key, $id) { - $this->connection->commit(Argument::allOf( - Argument::withEntry('transaction', self::TRANSACTION), - Argument::withEntry('mode', 'TRANSACTIONAL'), - Argument::withEntry('mutations', [[$method => $mutation]]) - ))->shouldBeCalled()->willReturn($this->commitResponse()); + $expectedResult = $this->basicCommitResponse(); + + $this->gapicClient->commit(Argument::that(function (CommitRequest $request) { + $this->assertEquals(base64_decode(self::TRANSACTION), $request->getTransaction()); + $this->assertEquals(Mode::TRANSACTIONAL, $request->getMode()); + $this->assertNotEmpty($request->getMutations()); + return true; + }), Argument::any())->shouldBeCalled(1) + ->willReturn(self::generateProto(CommitResponse::class, $expectedResult)); $keyWithId = clone $key; $keyWithId->setLastElementIdentifier($id); - $this->connection->allocateIds(Argument::allOf( - Argument::withEntry('keys', [$key->keyObject()]) - ))->shouldBeCalled()->willReturn([ + $this->gapicClient->allocateIds(Argument::that(function (AllocateIdsRequest $request) { + $this->assertEquals(1, count($request->getKeys())); + return true; + }), Argument::any())->shouldBeCalled(1)->willReturn(self::generateProto(AllocateIdsResponse::class, [ 'keys' => [ $keyWithId->keyObject() ] - ]); - - $this->refreshOperation($this->transaction, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + ])); $method .= 'Batch'; $entity = new Entity($key, ['name' => 'John']); $this->transaction->$method([$entity]); $res = $this->transaction->commit(); - $this->assertEquals($this->commitResponse(), $res); + $this->assertEquals($expectedResult, $res); } public function partialKeyMutationsProvider() @@ -448,47 +451,36 @@ public function partialKeyMutationsProvider() public function testDelete() { - $this->connection->commit(Argument::allOf( - Argument::withEntry('transaction', self::TRANSACTION), - Argument::withEntry('mode', 'TRANSACTIONAL'), - Argument::withEntry('mutations', [ - [ - 'delete' => $this->key->keyObject() - ] - ]) - ))->shouldBeCalled()->willReturn($this->commitResponse()); + $expectedResult = $this->basicCommitResponse(); - $this->refreshOperation($this->transaction, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $this->gapicClient->commit(Argument::that(function (CommitRequest $request) { + $this->assertEquals(base64_decode(self::TRANSACTION), $request->getTransaction()); + $this->assertEquals(Mode::TRANSACTIONAL, $request->getMode()); + $this->assertNotEmpty($request->getMutations()); + return true; + }), Argument::any())->shouldBeCalled(1)->willReturn(self::generateProto(CommitResponse::class, $expectedResult)); $this->transaction->delete($this->key); $res = $this->transaction->commit(); - $this->assertEquals($this->commitResponse(), $res); + $this->assertEquals($expectedResult, $res); } public function testDeleteBatch() { + $expectedResult = $this->basicCommitResponse(); - $this->connection->commit(Argument::allOf( - Argument::withEntry('transaction', self::TRANSACTION), - Argument::withEntry('mode', 'TRANSACTIONAL'), - Argument::withEntry('mutations', [ - [ - 'delete' => $this->key->keyObject() - ] - ]) - ))->shouldBeCalled()->willReturn($this->commitResponse()); - - $this->refreshOperation($this->transaction, $this->connection->reveal(), [ - 'projectId' => self::PROJECT - ]); + $this->gapicClient->commit(Argument::that(function (CommitRequest $request) { + $this->assertEquals(base64_decode(self::TRANSACTION), $request->getTransaction()); + $this->assertEquals(Mode::TRANSACTIONAL, $request->getMode()); + $this->assertNotEmpty($request->getMutations()); + return true; + }), Argument::any())->shouldBeCalled(1)->willReturn(self::generateProto(CommitResponse::class, $expectedResult)); $this->transaction->deleteBatch([$this->key]); $res = $this->transaction->commit(); - $this->assertEquals($this->commitResponse(), $res); + $this->assertEquals($expectedResult, $res); } private function entityArray(Key $key) @@ -520,33 +512,29 @@ private function mutationsProviderProvider($id, $partialKey = false) ]; } - private function commitResponse() + public function transactionProvider() { return [ - 'mutationResults' => [ - [ - 'version' => 1 - ] + [ + 'transaction' + ], + [ + 'readOnly' ] ]; } - public function transactionProvider() + private function basicCommitResponse(): array { - // init so the callbacks have a reference to hold until invoked. - $this->setUp(); - return [ - // return callables to get around phpunit's annoying habit of running data providers way too early. - [ - function () { - return $this->transaction; - } - ], [ - function () { - return $this->readOnly; - } - ] + 'mutationResults' => [ + [ + 'version' => 1, + 'conflictDetected' => false, + 'transformResults' => [] + ] + ], + 'indexUpdates' => 0 ]; } } diff --git a/Datastore/tests/Unit/V1/Client/DatastoreClientTest.php b/Datastore/tests/Unit/V1/Client/DatastoreClientTest.php index bdf7922dfd76..9201a8e0ceed 100644 --- a/Datastore/tests/Unit/V1/Client/DatastoreClientTest.php +++ b/Datastore/tests/Unit/V1/Client/DatastoreClientTest.php @@ -1,6 +1,6 @@ getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + return $this->getMockBuilder(CredentialsWrapper::class) + ->disableOriginalConstructor() + ->getMock(); } /** @return DatastoreClient */ @@ -90,9 +92,7 @@ public function allocateIdsTest() // Mock request $projectId = 'projectId-1969970175'; $keys = []; - $request = (new AllocateIdsRequest()) - ->setProjectId($projectId) - ->setKeys($keys); + $request = (new AllocateIdsRequest())->setProjectId($projectId)->setKeys($keys); $response = $gapicClient->allocateIds($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -118,19 +118,20 @@ public function allocateIdsExceptionTest() $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); + $expectedExceptionMessage = json_encode( + [ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], + JSON_PRETTY_PRINT + ); $transport->addResponse(null, $status); // Mock request $projectId = 'projectId-1969970175'; $keys = []; - $request = (new AllocateIdsRequest()) - ->setProjectId($projectId) - ->setKeys($keys); + $request = (new AllocateIdsRequest())->setProjectId($projectId)->setKeys($keys); try { $gapicClient->allocateIds($request); // If the $gapicClient method call did not throw, fail the test @@ -159,8 +160,7 @@ public function beginTransactionTest() $transport->addResponse($expectedResponse); // Mock request $projectId = 'projectId-1969970175'; - $request = (new BeginTransactionRequest()) - ->setProjectId($projectId); + $request = (new BeginTransactionRequest())->setProjectId($projectId); $response = $gapicClient->beginTransaction($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -184,17 +184,19 @@ public function beginTransactionExceptionTest() $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); + $expectedExceptionMessage = json_encode( + [ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], + JSON_PRETTY_PRINT + ); $transport->addResponse(null, $status); // Mock request $projectId = 'projectId-1969970175'; - $request = (new BeginTransactionRequest()) - ->setProjectId($projectId); + $request = (new BeginTransactionRequest())->setProjectId($projectId); try { $gapicClient->beginTransaction($request); // If the $gapicClient method call did not throw, fail the test @@ -256,12 +258,15 @@ public function commitExceptionTest() $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); + $expectedExceptionMessage = json_encode( + [ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], + JSON_PRETTY_PRINT + ); $transport->addResponse(null, $status); // Mock request $projectId = 'projectId-1969970175'; @@ -300,9 +305,7 @@ public function lookupTest() // Mock request $projectId = 'projectId-1969970175'; $keys = []; - $request = (new LookupRequest()) - ->setProjectId($projectId) - ->setKeys($keys); + $request = (new LookupRequest())->setProjectId($projectId)->setKeys($keys); $response = $gapicClient->lookup($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -328,19 +331,20 @@ public function lookupExceptionTest() $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); + $expectedExceptionMessage = json_encode( + [ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], + JSON_PRETTY_PRINT + ); $transport->addResponse(null, $status); // Mock request $projectId = 'projectId-1969970175'; $keys = []; - $request = (new LookupRequest()) - ->setProjectId($projectId) - ->setKeys($keys); + $request = (new LookupRequest())->setProjectId($projectId)->setKeys($keys); try { $gapicClient->lookup($request); // If the $gapicClient method call did not throw, fail the test @@ -368,9 +372,7 @@ public function reserveIdsTest() // Mock request $projectId = 'projectId-1969970175'; $keys = []; - $request = (new ReserveIdsRequest()) - ->setProjectId($projectId) - ->setKeys($keys); + $request = (new ReserveIdsRequest())->setProjectId($projectId)->setKeys($keys); $response = $gapicClient->reserveIds($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -396,19 +398,20 @@ public function reserveIdsExceptionTest() $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); + $expectedExceptionMessage = json_encode( + [ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], + JSON_PRETTY_PRINT + ); $transport->addResponse(null, $status); // Mock request $projectId = 'projectId-1969970175'; $keys = []; - $request = (new ReserveIdsRequest()) - ->setProjectId($projectId) - ->setKeys($keys); + $request = (new ReserveIdsRequest())->setProjectId($projectId)->setKeys($keys); try { $gapicClient->reserveIds($request); // If the $gapicClient method call did not throw, fail the test @@ -436,9 +439,7 @@ public function rollbackTest() // Mock request $projectId = 'projectId-1969970175'; $transaction = '-34'; - $request = (new RollbackRequest()) - ->setProjectId($projectId) - ->setTransaction($transaction); + $request = (new RollbackRequest())->setProjectId($projectId)->setTransaction($transaction); $response = $gapicClient->rollback($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -464,19 +465,20 @@ public function rollbackExceptionTest() $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); + $expectedExceptionMessage = json_encode( + [ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], + JSON_PRETTY_PRINT + ); $transport->addResponse(null, $status); // Mock request $projectId = 'projectId-1969970175'; $transaction = '-34'; - $request = (new RollbackRequest()) - ->setProjectId($projectId) - ->setTransaction($transaction); + $request = (new RollbackRequest())->setProjectId($projectId)->setTransaction($transaction); try { $gapicClient->rollback($request); // If the $gapicClient method call did not throw, fail the test @@ -505,8 +507,7 @@ public function runAggregationQueryTest() $transport->addResponse($expectedResponse); // Mock request $projectId = 'projectId-1969970175'; - $request = (new RunAggregationQueryRequest()) - ->setProjectId($projectId); + $request = (new RunAggregationQueryRequest())->setProjectId($projectId); $response = $gapicClient->runAggregationQuery($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -530,17 +531,19 @@ public function runAggregationQueryExceptionTest() $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); + $expectedExceptionMessage = json_encode( + [ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], + JSON_PRETTY_PRINT + ); $transport->addResponse(null, $status); // Mock request $projectId = 'projectId-1969970175'; - $request = (new RunAggregationQueryRequest()) - ->setProjectId($projectId); + $request = (new RunAggregationQueryRequest())->setProjectId($projectId); try { $gapicClient->runAggregationQuery($request); // If the $gapicClient method call did not throw, fail the test @@ -570,9 +573,7 @@ public function runQueryTest() // Mock request $projectId = 'projectId-1969970175'; $partitionId = new PartitionId(); - $request = (new RunQueryRequest()) - ->setProjectId($projectId) - ->setPartitionId($partitionId); + $request = (new RunQueryRequest())->setProjectId($projectId)->setPartitionId($partitionId); $response = $gapicClient->runQuery($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -598,19 +599,20 @@ public function runQueryExceptionTest() $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); + $expectedExceptionMessage = json_encode( + [ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], + JSON_PRETTY_PRINT + ); $transport->addResponse(null, $status); // Mock request $projectId = 'projectId-1969970175'; $partitionId = new PartitionId(); - $request = (new RunQueryRequest()) - ->setProjectId($projectId) - ->setPartitionId($partitionId); + $request = (new RunQueryRequest())->setProjectId($projectId)->setPartitionId($partitionId); try { $gapicClient->runQuery($request); // If the $gapicClient method call did not throw, fail the test @@ -638,9 +640,7 @@ public function allocateIdsAsyncTest() // Mock request $projectId = 'projectId-1969970175'; $keys = []; - $request = (new AllocateIdsRequest()) - ->setProjectId($projectId) - ->setKeys($keys); + $request = (new AllocateIdsRequest())->setProjectId($projectId)->setKeys($keys); $response = $gapicClient->allocateIdsAsync($request)->wait(); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); diff --git a/Datastore/tests/Unit/V1/DatastoreClientTest.php b/Datastore/tests/Unit/V1/DatastoreClientTest.php deleted file mode 100644 index 566a17821645..000000000000 --- a/Datastore/tests/Unit/V1/DatastoreClientTest.php +++ /dev/null @@ -1,572 +0,0 @@ -getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); - } - - /** @return DatastoreClient */ - private function createClient(array $options = []) - { - $options += [ - 'credentials' => $this->createCredentials(), - ]; - return new DatastoreClient($options); - } - - /** @test */ - public function allocateIdsTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new AllocateIdsResponse(); - $transport->addResponse($expectedResponse); - // Mock request - $projectId = 'projectId-1969970175'; - $keys = []; - $response = $gapicClient->allocateIds($projectId, $keys); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.datastore.v1.Datastore/AllocateIds', $actualFuncCall); - $actualValue = $actualRequestObject->getProjectId(); - $this->assertProtobufEquals($projectId, $actualValue); - $actualValue = $actualRequestObject->getKeys(); - $this->assertProtobufEquals($keys, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function allocateIdsExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $projectId = 'projectId-1969970175'; - $keys = []; - try { - $gapicClient->allocateIds($projectId, $keys); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function beginTransactionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $transaction = '-34'; - $expectedResponse = new BeginTransactionResponse(); - $expectedResponse->setTransaction($transaction); - $transport->addResponse($expectedResponse); - // Mock request - $projectId = 'projectId-1969970175'; - $response = $gapicClient->beginTransaction($projectId); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.datastore.v1.Datastore/BeginTransaction', $actualFuncCall); - $actualValue = $actualRequestObject->getProjectId(); - $this->assertProtobufEquals($projectId, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function beginTransactionExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $projectId = 'projectId-1969970175'; - try { - $gapicClient->beginTransaction($projectId); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function commitTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $indexUpdates = 1425228195; - $expectedResponse = new CommitResponse(); - $expectedResponse->setIndexUpdates($indexUpdates); - $transport->addResponse($expectedResponse); - // Mock request - $projectId = 'projectId-1969970175'; - $mode = Mode::MODE_UNSPECIFIED; - $mutations = []; - $response = $gapicClient->commit($projectId, $mode, $mutations); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.datastore.v1.Datastore/Commit', $actualFuncCall); - $actualValue = $actualRequestObject->getProjectId(); - $this->assertProtobufEquals($projectId, $actualValue); - $actualValue = $actualRequestObject->getMode(); - $this->assertProtobufEquals($mode, $actualValue); - $actualValue = $actualRequestObject->getMutations(); - $this->assertProtobufEquals($mutations, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function commitExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $projectId = 'projectId-1969970175'; - $mode = Mode::MODE_UNSPECIFIED; - $mutations = []; - try { - $gapicClient->commit($projectId, $mode, $mutations); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function lookupTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $transaction = '-34'; - $expectedResponse = new LookupResponse(); - $expectedResponse->setTransaction($transaction); - $transport->addResponse($expectedResponse); - // Mock request - $projectId = 'projectId-1969970175'; - $keys = []; - $response = $gapicClient->lookup($projectId, $keys); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.datastore.v1.Datastore/Lookup', $actualFuncCall); - $actualValue = $actualRequestObject->getProjectId(); - $this->assertProtobufEquals($projectId, $actualValue); - $actualValue = $actualRequestObject->getKeys(); - $this->assertProtobufEquals($keys, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function lookupExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $projectId = 'projectId-1969970175'; - $keys = []; - try { - $gapicClient->lookup($projectId, $keys); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function reserveIdsTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new ReserveIdsResponse(); - $transport->addResponse($expectedResponse); - // Mock request - $projectId = 'projectId-1969970175'; - $keys = []; - $response = $gapicClient->reserveIds($projectId, $keys); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.datastore.v1.Datastore/ReserveIds', $actualFuncCall); - $actualValue = $actualRequestObject->getProjectId(); - $this->assertProtobufEquals($projectId, $actualValue); - $actualValue = $actualRequestObject->getKeys(); - $this->assertProtobufEquals($keys, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function reserveIdsExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $projectId = 'projectId-1969970175'; - $keys = []; - try { - $gapicClient->reserveIds($projectId, $keys); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function rollbackTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new RollbackResponse(); - $transport->addResponse($expectedResponse); - // Mock request - $projectId = 'projectId-1969970175'; - $transaction = '-34'; - $response = $gapicClient->rollback($projectId, $transaction); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.datastore.v1.Datastore/Rollback', $actualFuncCall); - $actualValue = $actualRequestObject->getProjectId(); - $this->assertProtobufEquals($projectId, $actualValue); - $actualValue = $actualRequestObject->getTransaction(); - $this->assertProtobufEquals($transaction, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function rollbackExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $projectId = 'projectId-1969970175'; - $transaction = '-34'; - try { - $gapicClient->rollback($projectId, $transaction); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function runAggregationQueryTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $transaction = '-34'; - $expectedResponse = new RunAggregationQueryResponse(); - $expectedResponse->setTransaction($transaction); - $transport->addResponse($expectedResponse); - // Mock request - $projectId = 'projectId-1969970175'; - $response = $gapicClient->runAggregationQuery($projectId); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.datastore.v1.Datastore/RunAggregationQuery', $actualFuncCall); - $actualValue = $actualRequestObject->getProjectId(); - $this->assertProtobufEquals($projectId, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function runAggregationQueryExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $projectId = 'projectId-1969970175'; - try { - $gapicClient->runAggregationQuery($projectId); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function runQueryTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $transaction = '-34'; - $expectedResponse = new RunQueryResponse(); - $expectedResponse->setTransaction($transaction); - $transport->addResponse($expectedResponse); - // Mock request - $projectId = 'projectId-1969970175'; - $partitionId = new PartitionId(); - $response = $gapicClient->runQuery($projectId, $partitionId); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.datastore.v1.Datastore/RunQuery', $actualFuncCall); - $actualValue = $actualRequestObject->getProjectId(); - $this->assertProtobufEquals($projectId, $actualValue); - $actualValue = $actualRequestObject->getPartitionId(); - $this->assertProtobufEquals($partitionId, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function runQueryExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $projectId = 'projectId-1969970175'; - $partitionId = new PartitionId(); - try { - $gapicClient->runQuery($projectId, $partitionId); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } -} diff --git a/Datastore/tests/Unit/bootstrap.php b/Datastore/tests/Unit/bootstrap.php new file mode 100644 index 000000000000..d56aebd48bf8 --- /dev/null +++ b/Datastore/tests/Unit/bootstrap.php @@ -0,0 +1,9 @@ +