|
| 1 | +/*! |
| 2 | + * Copyright 2019 Google Inc. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import {CallOptions, GrpcClientOptions} from 'google-gax'; |
| 18 | +import {ServiceError} from 'grpc'; |
| 19 | +import {common as protobuf} from 'protobufjs'; |
| 20 | + |
| 21 | +declare class DatastoreClient { |
| 22 | + static servicePath: string; |
| 23 | + static port: number; |
| 24 | + static scopes: string[]; |
| 25 | + |
| 26 | + constructor(opts?: GrpcClientOptions); |
| 27 | + |
| 28 | + getProjectId(callback: DatastoreClient.GetProjectIdCallback): void; |
| 29 | + |
| 30 | + lookup(request: DatastoreClient.LookupRequest, options?: CallOptions): DatastoreClient.CancelablePromise<[DatastoreClient.LookupResponse]>; |
| 31 | + lookup(request: DatastoreClient.LookupRequest, callback: DatastoreClient.LookupCallback): void; |
| 32 | + lookup(request: DatastoreClient.LookupRequest, options: CallOptions, callback: DatastoreClient.LookupCallback): void; |
| 33 | + |
| 34 | + runQuery(request: DatastoreClient.RunQueryRequest, options?: CallOptions): DatastoreClient.CancelablePromise<[DatastoreClient.RunQueryResponse]>; |
| 35 | + runQuery(request: DatastoreClient.RunQueryRequest, callback: DatastoreClient.RunQueryCallback): void; |
| 36 | + runQuery(request: DatastoreClient.RunQueryRequest, options: CallOptions, callback: DatastoreClient.RunQueryCallback): void; |
| 37 | + |
| 38 | + beginTransaction(request: DatastoreClient.BeginTransactionRequest, options?: CallOptions): DatastoreClient.CancelablePromise<[DatastoreClient.BeginTransactionResponse]>; |
| 39 | + beginTransaction(request: DatastoreClient.BeginTransactionRequest, callback: DatastoreClient.BeginTransactionCallback): void; |
| 40 | + beginTransaction(request: DatastoreClient.BeginTransactionRequest, options: CallOptions, callback: DatastoreClient.BeginTransactionCallback): void; |
| 41 | + |
| 42 | + commit(request: DatastoreClient.CommitRequest, options?: CallOptions): DatastoreClient.CancelablePromise<[DatastoreClient.CommitResponse]>; |
| 43 | + commit(request: DatastoreClient.CommitRequest, callback: DatastoreClient.CommitCallback): void; |
| 44 | + commit(request: DatastoreClient.CommitRequest, options: CallOptions, callback: DatastoreClient.CommitCallback): void; |
| 45 | + |
| 46 | + rollback(request: DatastoreClient.RollbackRequest, options?: CallOptions): DatastoreClient.CancelablePromise<[DatastoreClient.RollbackResponse]>; |
| 47 | + rollback(request: DatastoreClient.RollbackRequest, callback: DatastoreClient.RollbackCallback): void; |
| 48 | + rollback(request: DatastoreClient.RollbackRequest, options: CallOptions, callback: DatastoreClient.RollbackCallback): void; |
| 49 | + |
| 50 | + allocateIds(request: DatastoreClient.AllocateIdsRequest, options?: CallOptions): DatastoreClient.CancelablePromise<[DatastoreClient.AllocateIdsResponse]>; |
| 51 | + allocateIds(request: DatastoreClient.AllocateIdsRequest, callback: DatastoreClient.AllocateIdsCallback): void; |
| 52 | + allocateIds(request: DatastoreClient.AllocateIdsRequest, options: CallOptions, callback: DatastoreClient.AllocateIdsCallback): void; |
| 53 | + |
| 54 | + reserveIds(request: DatastoreClient.ReserveIdsRequest, options?: CallOptions): DatastoreClient.CancelablePromise<[DatastoreClient.ReserveIdsResponse]>; |
| 55 | + reserveIds(request: DatastoreClient.ReserveIdsRequest, callback: DatastoreClient.ReserveIdsCallback): void; |
| 56 | + reserveIds(request: DatastoreClient.ReserveIdsRequest, options: CallOptions, callback: DatastoreClient.ReserveIdsCallback): void; |
| 57 | +} |
| 58 | + |
| 59 | +declare namespace DatastoreClient { |
| 60 | + interface CancelablePromise <T> extends Promise<T> { |
| 61 | + cancel(): void; |
| 62 | + } |
| 63 | + |
| 64 | + interface GetProjectIdCallback { |
| 65 | + (error: null|Error, projectId: string): void; |
| 66 | + } |
| 67 | + |
| 68 | + interface LookupRequest { |
| 69 | + projectId: string; |
| 70 | + readOptions?: ReadOptions; |
| 71 | + keys: Key[]; |
| 72 | + } |
| 73 | + |
| 74 | + interface LookupResponse { |
| 75 | + found: EntityResult[]; |
| 76 | + missing: EntityResult[]; |
| 77 | + deferred: Key[]; |
| 78 | + } |
| 79 | + |
| 80 | + interface LookupCallback { |
| 81 | + (err: null|ServiceError, response: LookupResponse): void; |
| 82 | + } |
| 83 | + |
| 84 | + interface RunQueryRequest { |
| 85 | + projectId: string; |
| 86 | + partitionId?: PartitionId; |
| 87 | + readOptions?: ReadOptions; |
| 88 | + queryType?: string; |
| 89 | + query?: Query; |
| 90 | + gqlQuery?: GqlQuery; |
| 91 | + } |
| 92 | + |
| 93 | + interface RunQueryResponse { |
| 94 | + batch: QueryResultBatch; |
| 95 | + query: Query; |
| 96 | + } |
| 97 | + |
| 98 | + interface RunQueryCallback { |
| 99 | + (err: null|ServiceError, response: RunQueryResponse): void; |
| 100 | + } |
| 101 | + |
| 102 | + interface BeginTransactionRequest { |
| 103 | + projectId: string; |
| 104 | + transactionOptions?: TransactionOptions; |
| 105 | + } |
| 106 | + |
| 107 | + interface BeginTransactionResponse { |
| 108 | + transaction: string|Buffer; |
| 109 | + } |
| 110 | + |
| 111 | + interface BeginTransactionCallback { |
| 112 | + (err: null|ServiceError, response: BeginTransactionResponse): void; |
| 113 | + } |
| 114 | + |
| 115 | + const enum CommitRequestMode { |
| 116 | + MODE_UNSPECIFIED = 'MODE_UNSPECIFIED', |
| 117 | + TRANSACTIONAL = 'TRANSACTIONAL', |
| 118 | + NON_TRANSACTIONAL = 'NON_TRANSACTIONAL' |
| 119 | + } |
| 120 | + |
| 121 | + interface CommitRequest { |
| 122 | + projectId: string; |
| 123 | + mode: CommitRequestMode; |
| 124 | + transactionSelector?: string; |
| 125 | + transaction?: string|Buffer; |
| 126 | + mutations: Mutation[]; |
| 127 | + } |
| 128 | + |
| 129 | + interface CommitResponse { |
| 130 | + mutationResults: MutationResult[]; |
| 131 | + indexUpdates: number; |
| 132 | + } |
| 133 | + |
| 134 | + interface CommitCallback { |
| 135 | + (err: null|ServiceError, response: CommitResponse): void; |
| 136 | + } |
| 137 | + |
| 138 | + interface RollbackRequest { |
| 139 | + projectId: string; |
| 140 | + transaction: string|Buffer; |
| 141 | + } |
| 142 | + |
| 143 | + interface RollbackResponse {} |
| 144 | + |
| 145 | + interface RollbackCallback { |
| 146 | + (err: null|ServiceError, response: RollbackResponse): void; |
| 147 | + } |
| 148 | + |
| 149 | + interface AllocateIdsRequest { |
| 150 | + projectId: string; |
| 151 | + keys: Key[]; |
| 152 | + } |
| 153 | + |
| 154 | + interface AllocateIdsResponse { |
| 155 | + keys: Key[]; |
| 156 | + } |
| 157 | + |
| 158 | + interface AllocateIdsCallback { |
| 159 | + (err: null|ServiceError, response: AllocateIdsResponse): void; |
| 160 | + } |
| 161 | + |
| 162 | + interface ReserveIdsRequest { |
| 163 | + projectId: string; |
| 164 | + databaseId?: string; |
| 165 | + keys: Key[]; |
| 166 | + } |
| 167 | + |
| 168 | + interface ReserveIdsResponse {} |
| 169 | + |
| 170 | + interface ReserveIdsCallback { |
| 171 | + (err: null|ServiceError, response: ReserveIdsResponse): void; |
| 172 | + } |
| 173 | + |
| 174 | + interface Mutation { |
| 175 | + insert?: Entity; |
| 176 | + update?: Entity; |
| 177 | + upsert?: Entity; |
| 178 | + delete?: Key; |
| 179 | + operation?: string; |
| 180 | + conflictDetectionStrategy?: string; |
| 181 | + baseVersion?: number; |
| 182 | + } |
| 183 | + |
| 184 | + interface MutationResult { |
| 185 | + key: null|Key; |
| 186 | + version: number; |
| 187 | + conflictDetected: boolean; |
| 188 | + } |
| 189 | + |
| 190 | + const enum ReadConsistency { |
| 191 | + READ_CONSISTENCY_UNSPECIFIED = 'READ_CONSISTENCY_UNSPECIFIED', |
| 192 | + STRONG = 'STRONG', |
| 193 | + EVENTUAL = 'EVENTUAL' |
| 194 | + } |
| 195 | + |
| 196 | + interface ReadOptions { |
| 197 | + consistencyType?: string; |
| 198 | + readConsistency?: ReadConsistency; |
| 199 | + transaction?: string|Buffer; |
| 200 | + } |
| 201 | + |
| 202 | + interface ReadWrite { |
| 203 | + previousTransaction?: string|Buffer; |
| 204 | + } |
| 205 | + |
| 206 | + interface ReadOnly {} |
| 207 | + |
| 208 | + interface TransactionOptions { |
| 209 | + mode?: string; |
| 210 | + readWrite?: ReadWrite; |
| 211 | + readOnly?: ReadOnly; |
| 212 | + } |
| 213 | + |
| 214 | + interface PartitionId { |
| 215 | + projectId: string; |
| 216 | + namespaceId?: string; |
| 217 | + } |
| 218 | + |
| 219 | + interface PathElement { |
| 220 | + kind: string; |
| 221 | + id?: number; |
| 222 | + name?: string; |
| 223 | + idType?: string; |
| 224 | + } |
| 225 | + |
| 226 | + interface Key { |
| 227 | + partitionId?: PartitionId; |
| 228 | + path: PathElement[]; |
| 229 | + } |
| 230 | + |
| 231 | + interface ArrayValue { |
| 232 | + values: Value[]; |
| 233 | + } |
| 234 | + |
| 235 | + interface Value { |
| 236 | + nullValue?: 0; |
| 237 | + booleanValue?: boolean; |
| 238 | + integerValue?: number; |
| 239 | + doubleValue?: number; |
| 240 | + timestampValue?: protobuf.ITimestamp; |
| 241 | + keyValue?: Key; |
| 242 | + stringValue?: string; |
| 243 | + blobValue?: string|Buffer; |
| 244 | + geoPointValue?: LatLng; |
| 245 | + entityValue?: Entity; |
| 246 | + arrayValue?: ArrayValue; |
| 247 | + valueType?: string; |
| 248 | + meaning?: number; |
| 249 | + excludeFromIndexes?: boolean; |
| 250 | + } |
| 251 | + |
| 252 | + interface Entity { |
| 253 | + key: null|Key; |
| 254 | + properties: {[name: string]: Value}; |
| 255 | + } |
| 256 | + |
| 257 | + const enum ResultType { |
| 258 | + RESULT_TYPE_UNSPECIFIED = 'RESULT_TYPE_UNSPECIFIED', |
| 259 | + FULL = 'FULL', |
| 260 | + PROJECTION = 'PROJECTION', |
| 261 | + KEY_ONLY = 'KEY_ONLY' |
| 262 | + } |
| 263 | + |
| 264 | + interface EntityResult { |
| 265 | + entity: Entity; |
| 266 | + version: number; |
| 267 | + cursor: string|Buffer; |
| 268 | + } |
| 269 | + |
| 270 | + interface Query { |
| 271 | + pojection: Projection[]; |
| 272 | + kind: KindExpression[]; |
| 273 | + filter?: Filter; |
| 274 | + order: PropertyOrder[]; |
| 275 | + distinctOn: PropertyReference[]; |
| 276 | + startCursor?: string|Buffer; |
| 277 | + endCursor?: string|Buffer; |
| 278 | + offset?: number; |
| 279 | + limit?: protobuf.IInt32Value; |
| 280 | + } |
| 281 | + |
| 282 | + interface KindExpression { |
| 283 | + name: string; |
| 284 | + } |
| 285 | + |
| 286 | + interface PropertyReference { |
| 287 | + name: string; |
| 288 | + } |
| 289 | + |
| 290 | + interface Projection { |
| 291 | + property: PropertyReference; |
| 292 | + } |
| 293 | + |
| 294 | + const enum Direction { |
| 295 | + DIRECTION_UNSPECIFIED = 'DIRECTION_UNSPECIFIED', |
| 296 | + ASCENDING = 'ASCENDING', |
| 297 | + DESCENDING = 'DESCENDING' |
| 298 | + } |
| 299 | + |
| 300 | + interface PropertyOrder { |
| 301 | + property: PropertyReference; |
| 302 | + direction: Direction; |
| 303 | + } |
| 304 | + |
| 305 | + interface Filter { |
| 306 | + filterType?: string; |
| 307 | + compositeFilter?: CompositeFilter; |
| 308 | + propertyFilter?: PropertyFilter; |
| 309 | + } |
| 310 | + |
| 311 | + const enum CompositeFilterOperator { |
| 312 | + OPERATOR_UNSPECIFIED = 'OPERATOR_UNSPECIFIED', |
| 313 | + AND = 'AND' |
| 314 | + } |
| 315 | + |
| 316 | + interface CompositeFilter { |
| 317 | + op: CompositeFilterOperator; |
| 318 | + filters: Filter[]; |
| 319 | + } |
| 320 | + |
| 321 | + const enum PropertyFilterOperator { |
| 322 | + OPERATOR_UNSPECIFIED = 'OPERATOR_UNSPECIFIED', |
| 323 | + LESS_THAN = 'LESS_THAN', |
| 324 | + LESS_THAN_OR_EQUAL = 'LESS_THAN_OR_EQUAL', |
| 325 | + GREATER_THAN = 'GREATER_THAN', |
| 326 | + GREATER_THAN_OR_EQUAL = 'GREATER_THAN_OR_EQUAL', |
| 327 | + EQUAL = 'EQUAL', |
| 328 | + HAS_ANCESTOR = 'HAS_ANCESTOR' |
| 329 | + } |
| 330 | + |
| 331 | + interface PropertyFilter { |
| 332 | + property: PropertyReference; |
| 333 | + op: PropertyFilterOperator; |
| 334 | + value: Value; |
| 335 | + } |
| 336 | + |
| 337 | + interface GqlQuery { |
| 338 | + queryString: string; |
| 339 | + allowLiterals?: boolean; |
| 340 | + namedBindings?: {[name: string]: GqlQueryParameter}; |
| 341 | + positionalBindings?: GqlQueryParameter[]; |
| 342 | + } |
| 343 | + |
| 344 | + interface GqlQueryParameter { |
| 345 | + parameterType?: string; |
| 346 | + value?: Value; |
| 347 | + cursor?: string|Buffer; |
| 348 | + } |
| 349 | + |
| 350 | + const enum MoreResultsType { |
| 351 | + MORE_RESULTS_TYPE_UNSPECIFIED = 'MORE_RESULTS_TYPE_UNSPECIFIED', |
| 352 | + NOT_FINISHED = 'NOT_FINISHED', |
| 353 | + MORE_RESULTS_AFTER_LIMIT = 'MORE_RESULTS_AFTER_LIMIT', |
| 354 | + NO_MORE_RESULTS = 'NO_MORE_RESULTS', |
| 355 | + MORE_RESULTS_AFTER_CURSOR = 'MORE_RESULTS_AFTER_CURSOR' |
| 356 | + } |
| 357 | + |
| 358 | + interface QueryResultBatch { |
| 359 | + skippedResults: number; |
| 360 | + skippedCursor: string|Buffer; |
| 361 | + entityResultType: ResultType; |
| 362 | + entityResults: EntityResult[]; |
| 363 | + endCursor: string|Buffer; |
| 364 | + moreResults: MoreResultsType; |
| 365 | + snapshotVersion: number; |
| 366 | + } |
| 367 | + |
| 368 | + interface LatLng { |
| 369 | + latitude: number; |
| 370 | + longitude: number; |
| 371 | + } |
| 372 | +} |
0 commit comments