1 | /*!
|
2 | * Copyright 2018 Google LLC.
|
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 | import { ClientStub, ChannelCredentials, GoogleAuth, GoogleAuthOptions, CallOptions, Operation, ServiceError } from 'google-gax';
|
17 | import { entity, Entities, Entity, ValueProto } from './entity';
|
18 | import { AggregateField } from './aggregate';
|
19 | import Key = entity.Key;
|
20 | export { Entity, Key, AggregateField };
|
21 | import { PropertyFilter, and, or } from './filter';
|
22 | export { PropertyFilter, and, or };
|
23 | import { GetIndexesCallback, GetIndexesOptions, GetIndexesResponse, Index } from './index-class';
|
24 | import { Query } from './query';
|
25 | import { DatastoreRequest, CommitCallback, CommitResponse, SaveCallback, SaveResponse } from './request';
|
26 | import { Transaction } from './transaction';
|
27 | import { google } from '../protos/protos';
|
28 | import { AggregateQuery } from './aggregate';
|
29 | export type PathType = string | number | entity.Int;
|
30 | export interface BooleanObject {
|
31 | [key: string]: boolean;
|
32 | }
|
33 | export interface EntityProtoReduceAccumulator {
|
34 | [key: string]: ValueProto;
|
35 | }
|
36 | export interface EntityProtoReduceData {
|
37 | value: ValueProto;
|
38 | excludeFromIndexes: ValueProto;
|
39 | name: string | number;
|
40 | }
|
41 | export type UpdateCallback = CommitCallback;
|
42 | export type UpdateResponse = CommitResponse;
|
43 | export type UpsertCallback = CommitCallback;
|
44 | export type UpsertResponse = CommitResponse;
|
45 | export type InsertCallback = CommitCallback;
|
46 | export type InsertResponse = CommitResponse;
|
47 | export interface LongRunningCallback {
|
48 | (err: ServiceError | null, operation?: Operation, apiResponse?: google.longrunning.IOperation): void;
|
49 | }
|
50 | export type LongRunningResponse = [Operation, google.longrunning.IOperation];
|
51 | export type Fallback = boolean | 'rest' | 'proto';
|
52 | export interface ExportEntitiesConfig extends Omit<google.datastore.admin.v1.IExportEntitiesRequest, 'projectId'> {
|
53 | bucket?: string | {
|
54 | name: string;
|
55 | };
|
56 | kinds?: string[];
|
57 | namespaces?: string[];
|
58 | gaxOptions?: CallOptions;
|
59 | }
|
60 | export interface ImportEntitiesConfig extends Omit<google.datastore.admin.v1.IImportEntitiesRequest, 'projectId'> {
|
61 | file?: string | {
|
62 | bucket: {
|
63 | name: string;
|
64 | };
|
65 | name: string;
|
66 | };
|
67 | kinds?: string[];
|
68 | namespaces?: string[];
|
69 | gaxOptions?: CallOptions;
|
70 | }
|
71 | /**
|
72 | * Idiomatic class for interacting with Cloud Datastore. Uses the lower-level
|
73 | * {@link DatastoreClient} class under the hood.
|
74 | *
|
75 | * In addition to the constructor options shown here, the {@link Datastore}
|
76 | * class constructor accepts the same options accepted by
|
77 | * {@link DatastoreClient}.
|
78 | *
|
79 | * <h4>The Datastore Emulator</h4>
|
80 | *
|
81 | * Make sure you have the <a href="https://cloud.google.com/sdk/docs/install">
|
82 | * gcloud SDK installed</a>, then run:
|
83 | *
|
84 | * <pre>
|
85 | * $ gcloud beta emulators datastore start --no-legacy
|
86 | * </pre>
|
87 | *
|
88 | * You will see the following printed:
|
89 | *
|
90 | * <pre>
|
91 | * [datastore] API endpoint: http://localhost:8005
|
92 | * [datastore] If you are using a library that supports the
|
93 | * DATASTORE_EMULATOR_HOST environment variable, run:
|
94 | * [datastore]
|
95 | * [datastore] export DATASTORE_EMULATOR_HOST=localhost:8005
|
96 | * [datastore]
|
97 | * [datastore] Dev App Server is now running.
|
98 | * </pre>
|
99 | *
|
100 | * Set that environment variable and your localhost Datastore will
|
101 | * automatically be used. You can also pass this address in manually with
|
102 | * `apiEndpoint`.
|
103 | *
|
104 | * Additionally, `DATASTORE_PROJECT_ID` is recognized. If you have this set,
|
105 | * you don't need to provide a `projectId`.
|
106 | *
|
107 | *
|
108 | * See {@link https://cloud.google.com/datastore/docs/concepts/overview| Cloud Datastore Concepts Overview}
|
109 | *
|
110 | * @param {object} [options] Configuration options.
|
111 | * @param {string} [options.apiEndpoint] Override the default API endpoint used
|
112 | * to reach Datastore. This is useful for connecting to your local Datastore
|
113 | * server (usually "http://localhost:8080").
|
114 | * @param {string} [options.namespace] Namespace to isolate transactions to.
|
115 | *
|
116 | * @example Import the client library
|
117 | * ```
|
118 | * const {Datastore} = require('@google-cloud/datastore');
|
119 | *
|
120 | * ```
|
121 | * @example Create a client that uses <a href="https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application">Application Default Credentials (ADC)</a>:
|
122 | * ```
|
123 | * const datastore = new Datastore();
|
124 | *
|
125 | * ```
|
126 | * @example Create a client with <a href="https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually">explicit credentials</a>:
|
127 | * ```
|
128 | * const datastore = new Datastore({
|
129 | * projectId: 'your-project-id',
|
130 | * keyFilename: '/path/to/keyfile.json'
|
131 | * });
|
132 | *
|
133 | * ```
|
134 | * @example Retrieving Records
|
135 | * ```
|
136 | * const {Datastore} = require('@google-cloud/datastore');
|
137 | * const datastore = new Datastore();
|
138 | *
|
139 | * // Records, called "entities" in Datastore, are retrieved by using a key. The
|
140 | * // key is more than a numeric identifier, it is a complex data structure that
|
141 | * // can be used to model relationships. The simplest key has a string `kind`
|
142 | * // value, and either a numeric `id` value, or a string `name` value.
|
143 | * //
|
144 | * // A single record can be retrieved with {@link Datastore#key} and
|
145 | * // {@link Datastore#get}.
|
146 | * //-
|
147 | * const key = datastore.key(['Company', 'Google']);
|
148 | *
|
149 | * datastore.get(key, function(err, entity) {
|
150 | * // entity = The record.
|
151 | * // entity[datastore.KEY] = The key for this entity.
|
152 | * });
|
153 | *
|
154 | * //-
|
155 | * // <h3>Querying Records</h3>
|
156 | * //
|
157 | * // Create a query with {@link Datastore#createQuery}.
|
158 | * //-
|
159 | * const query = datastore.createQuery('Company');
|
160 | *
|
161 | * //-
|
162 | * // Multiple records can be found that match criteria with
|
163 | * // {@link Query#filter}.
|
164 | * //-
|
165 | * query.filter('location', 'CA');
|
166 | *
|
167 | * //-
|
168 | * // Records can also be ordered with {@link Query#order}.
|
169 | * //-
|
170 | * query.order('name');
|
171 | *
|
172 | * //-
|
173 | * // The number of records returned can be specified with
|
174 | * // {@link Query#limit}.
|
175 | * //-
|
176 | * query.limit(5);
|
177 | *
|
178 | * //-
|
179 | * // Records' key structures can also be queried with
|
180 | * // {@link Query#hasAncestor}.
|
181 | * //-
|
182 | * const ancestorKey = datastore.key(['ParentCompany', 'Alphabet']);
|
183 | *
|
184 | * query.hasAncestor(ancestorKey);
|
185 | *
|
186 | * //-
|
187 | * // Run the query with {@link Datastore#runQuery}.
|
188 | * //-
|
189 | * datastore.runQuery(query, (err, entities) => {
|
190 | * // entities = An array of records.
|
191 | *
|
192 | * // Access the Key object for an entity.
|
193 | * const firstEntityKey = entities[0][datastore.KEY];
|
194 | * });
|
195 | *
|
196 | * ```
|
197 | * @example Paginating Records
|
198 | * ```
|
199 | * // Imagine building a website that allows a user to sift through hundreds of
|
200 | * // their contacts. You'll likely want to only display a subset of these at
|
201 | * // once, so you set a limit.
|
202 | * //-
|
203 | * const express = require('express');
|
204 | * const app = express();
|
205 | *
|
206 | * const NUM_RESULTS_PER_PAGE = 15;
|
207 | *
|
208 | * app.get('/contacts', (req, res) => {
|
209 | * const query = datastore.createQuery('Contacts')
|
210 | * .limit(NUM_RESULTS_PER_PAGE);
|
211 | *
|
212 | * if (req.query.nextPageCursor) {
|
213 | * query.start(req.query.nextPageCursor);
|
214 | * }
|
215 | *
|
216 | * datastore.runQuery(query, (err, entities, info) => {
|
217 | * if (err) {
|
218 | * // Error handling omitted.
|
219 | * return;
|
220 | * }
|
221 | *
|
222 | * // Respond to the front end with the contacts and the cursoring token
|
223 | * // from the query we just ran.
|
224 | * const frontEndResponse = {
|
225 | * contacts: entities
|
226 | * };
|
227 | *
|
228 | * // Check if more results may exist.
|
229 | * if (info.moreResults !== datastore.NO_MORE_RESULTS) {
|
230 | * frontEndResponse.nextPageCursor = info.endCursor;
|
231 | * }
|
232 | *
|
233 | * res.render('contacts', frontEndResponse);
|
234 | * });
|
235 | * });
|
236 | *
|
237 | * ```
|
238 | * @example Creating Records
|
239 | * ```
|
240 | * // New entities can be created and persisted with {@link Datastore#save}.
|
241 | * // The entity must have a key to be saved. If you don't specify an
|
242 | * // identifier for the key, one is generated for you.
|
243 | * //
|
244 | * // We will create a key with a `name` identifier, "Google".
|
245 | * //-
|
246 | * const key = datastore.key(['Company', 'Google']);
|
247 | *
|
248 | * const data = {
|
249 | * name: 'Google',
|
250 | * location: 'CA'
|
251 | * };
|
252 | *
|
253 | * datastore.save({
|
254 | * key: key,
|
255 | * data: data
|
256 | * }, (err) => {
|
257 | * if (!err) {
|
258 | * // Record saved successfully.
|
259 | * }
|
260 | * });
|
261 | *
|
262 | * //-
|
263 | * // We can verify the data was saved by using {@link Datastore#get}.
|
264 | * //-
|
265 | * datastore.get(key, (err, entity) => {
|
266 | * // entity = {
|
267 | * // name: 'Google',
|
268 | * // location: 'CA'
|
269 | * // }
|
270 | * });
|
271 | *
|
272 | * //-
|
273 | * // If we want to update this record, we can modify the data object and re-
|
274 | * // save it.
|
275 | * //-
|
276 | * data.symbol = 'GOOG';
|
277 | *
|
278 | * datastore.save({
|
279 | * key: key, // defined above (datastore.key(['Company', 'Google']))
|
280 | * data: data
|
281 | * }, (err, entity) => {
|
282 | * if (!err) {
|
283 | * // Record updated successfully.
|
284 | * }
|
285 | * });
|
286 | *
|
287 | * ```
|
288 | * @example Deleting Records
|
289 | * ```
|
290 | * // Entities can be removed from Datastore by passing the entity's key object
|
291 | * // to {@link Datastore#delete}.
|
292 | * //-
|
293 | * const key = datastore.key(['Company', 'Google']);
|
294 | *
|
295 | * datastore.delete(key, (err) => {
|
296 | * if (!err) {
|
297 | * // Record deleted successfully.
|
298 | * }
|
299 | * });
|
300 | *
|
301 | * ```
|
302 | * @example Transactions
|
303 | * ```
|
304 | * // Complex logic can be wrapped in a transaction with
|
305 | * // {@link Datastore#transaction}. All queries and updates run within
|
306 | * // the transaction will be applied when the `done` function is called.
|
307 | * //-
|
308 | * const transaction = datastore.transaction();
|
309 | *
|
310 | * transaction.run((err) => {
|
311 | * if (err) {
|
312 | * // Error handling omitted.
|
313 | * }
|
314 | *
|
315 | * const key = datastore.key(['Company', 'Google']);
|
316 | *
|
317 | * transaction.get(key, (err, entity) => {
|
318 | * if (err) {
|
319 | * // Error handling omitted.
|
320 | * }
|
321 | *
|
322 | * entity.symbol = 'GOOG';
|
323 | *
|
324 | * transaction.save(entity);
|
325 | *
|
326 | * transaction.commit((err) => {
|
327 | * if (!err) {
|
328 | * // Transaction committed successfully.
|
329 | * }
|
330 | * });
|
331 | * });
|
332 | * });
|
333 | *
|
334 | * ```
|
335 | * @example Queries with Ancestors
|
336 | * ```
|
337 | * const {Datastore} = require('@google-cloud/datastore');
|
338 | * const datastore = new Datastore();
|
339 | *
|
340 | * const customerId1 = 2993844;
|
341 | * const customerId2 = 4993882;
|
342 | * const customerKey1 = datastore.key(['Customer', customerId1]);
|
343 | * const customerKey2 = datastore.key(['Customer', customerId2]);
|
344 | * const cookieKey1 = datastore.key(['Customer', customerId1, 'Cookie',
|
345 | * 'cookie28839']); // child entity const cookieKey2 =
|
346 | * datastore.key(['Customer', customerId1, 'Cookie', 'cookie78984']); // child
|
347 | * entity const cookieKey3 = datastore.key(['Customer', customerId2, 'Cookie',
|
348 | * 'cookie93911']); // child entity
|
349 | *
|
350 | * const entities = [];
|
351 | *
|
352 | * entities.push({
|
353 | * key: customerKey1,
|
354 | * data: {
|
355 | * name: 'Jane Doe',
|
356 | * address: '4848 Liller'
|
357 | * }
|
358 | * });
|
359 | *
|
360 | * entities.push({
|
361 | * key: customerKey2,
|
362 | * data: {
|
363 | * name: 'John Smith',
|
364 | * address: '4848 Pine'
|
365 | * }
|
366 | * });
|
367 | *
|
368 | * entities.push({
|
369 | * key: cookieKey1,
|
370 | * data: {
|
371 | * cookieVal: 'dj83kks88rkld'
|
372 | * }
|
373 | * });
|
374 | *
|
375 | * entities.push({
|
376 | * key: cookieKey2,
|
377 | * data: {
|
378 | * cookieVal: 'sj843ka99s'
|
379 | * }
|
380 | * });
|
381 | *
|
382 | * entities.push({
|
383 | * key: cookieKey3,
|
384 | * data: {
|
385 | * cookieVal: 'otk82k2kw'
|
386 | * }
|
387 | * });
|
388 | *
|
389 | * datastore.upsert(entities);
|
390 | *
|
391 | * const query = datastore.createQuery().hasAncestor(customerKey1);
|
392 | *
|
393 | * datastore.runQuery(query, (err, entities) => {
|
394 | * for (let entity of entities) {
|
395 | * console.log(entity[datastore.KEY]);
|
396 | * }
|
397 | * });
|
398 | *
|
399 | * const query2 = datastore.createQuery().hasAncestor(customerKey2);
|
400 | *
|
401 | * datastore.runQuery(query2, (err, entities) => {
|
402 | * for (let entity of entities) {
|
403 | * console.log(entity[datastore.KEY]);
|
404 | * }
|
405 | * });
|
406 | *
|
407 | * datastore.runQuery(query2, (entities) => {
|
408 | * console.log(entities);
|
409 | * });
|
410 | * ```
|
411 | */
|
412 | declare class Datastore extends DatastoreRequest {
|
413 | clients_: Map<string, ClientStub>;
|
414 | namespace?: string;
|
415 | defaultBaseUrl_: string;
|
416 | options: DatastoreOptions;
|
417 | baseUrl_?: string;
|
418 | port_?: number;
|
419 | customEndpoint_?: boolean;
|
420 | auth: GoogleAuth;
|
421 | constructor(options?: DatastoreOptions);
|
422 | /**
|
423 | * Create an aggregation query from a Query.
|
424 | *
|
425 | * @param {Query} query A Query object.
|
426 | */
|
427 | createAggregationQuery(query: Query): AggregateQuery;
|
428 | /**
|
429 | * Export entities from this project to a Google Cloud Storage bucket.
|
430 | *
|
431 | * @param {ExportEntitiesConfig} config Configuration object.
|
432 | * @param {string | Bucket} config.bucket The `gs://bucket` path or a
|
433 | * @google-cloud/storage Bucket object.
|
434 | * @param {string[]} [config.kinds] The kinds to include in this import.
|
435 | * @param {string[]} [config.namespaces] The namespace IDs to include in this
|
436 | * import.
|
437 | * @param {object} [config.gaxOptions] Request configuration options, outlined
|
438 | * here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions.
|
439 | * @param {function} callback The callback function.
|
440 | * @param {?error} callback.err An error returned while making this request.
|
441 | * @param {Operation} callback.operation An operation object that can be used
|
442 | * to check the status of the request.
|
443 | */
|
444 | export(config: ExportEntitiesConfig): Promise<LongRunningResponse>;
|
445 | export(config: ExportEntitiesConfig, callback: LongRunningCallback): void;
|
446 | /**
|
447 | * Get all of the indexes in this project.
|
448 | *
|
449 | * @param {GetIndexesOptions | GetIndexesCallback} [optionsOrCallback]
|
450 | * @param {object} [options.gaxOptions] Request configuration options,
|
451 | * outlined here:
|
452 | * https://googleapis.github.io/gax-nodejs/global.html#CallOptions.
|
453 | * @param {GetIndexesResponse} [callback] The callback function.
|
454 | * @param {?error} callback.error An error returned while making this request.
|
455 | * @param {Index[]} callback.indexes All matching Index instances.
|
456 | * @param {object} callback.apiResponse The full API response.
|
457 | * @return {void | Promise<GetIndexesResponse>}
|
458 | */
|
459 | getIndexes(options?: GetIndexesOptions): Promise<GetIndexesResponse>;
|
460 | getIndexes(options: GetIndexesOptions, callback: GetIndexesCallback): void;
|
461 | getIndexes(callback: GetIndexesCallback): void;
|
462 | /**
|
463 | * Get all of the indexes in this project as a readable object stream.
|
464 | *
|
465 | * @param {GetIndexesOptions} [options] Configuration object. See
|
466 | * {@link Datastore#getIndexes} for a complete list of options.
|
467 | * @returns {ReadableStream<Index>}
|
468 | */
|
469 | getIndexesStream(options?: GetIndexesOptions): NodeJS.ReadableStream;
|
470 | /**
|
471 | * Gets the database id that all requests will be run against.
|
472 | *
|
473 | * @returns {string} The database id that the current client is set to that
|
474 | * requests will run against.
|
475 | */
|
476 | getDatabaseId(): string | undefined;
|
477 | getProjectId(): Promise<string>;
|
478 | /**
|
479 | * Import entities into this project from a remote file.
|
480 | *
|
481 | * @param {ImportEntitiesConfig} config Configuration object.
|
482 | * @param {string | File} config.file The `gs://bucket/file` path or a
|
483 | * @google-cloud/storage File object.
|
484 | * @param {string[]} [config.kinds] The kinds to include in this import.
|
485 | * @param {string[]} [config.namespaces] The namespace IDs to include in this
|
486 | * import.
|
487 | * @param {object} [config.gaxOptions] Request configuration options, outlined
|
488 | * here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions.
|
489 | * @param {function} callback The callback function.
|
490 | * @param {?error} callback.err An error returned while making this request.
|
491 | * @param {Operation} callback.operation An operation object that can be used
|
492 | * to check the status of the request.
|
493 | */
|
494 | import(config: ImportEntitiesConfig): Promise<LongRunningResponse>;
|
495 | import(config: ImportEntitiesConfig, callback: LongRunningCallback): void;
|
496 | /**
|
497 | * Get a reference to an Index.
|
498 | *
|
499 | * @param {string} id The index name or id.
|
500 | * @returns {Index}
|
501 | */
|
502 | index(id: string): Index;
|
503 | /**
|
504 | * Maps to {@link https://cloud.google.com/nodejs/docs/reference/datastore/latest/datastore/datastore#_google_cloud_datastore_Datastore_save_member_1_|Datastore#save}, forcing the method to be `insert`.
|
505 | *
|
506 | * @param {object|object[]} entities Datastore key object(s).
|
507 | * @param {Key} entities.key Datastore key object.
|
508 | * @param {string[]} [entities.excludeFromIndexes] Exclude properties from
|
509 | * indexing using a simple JSON path notation. See the examples in
|
510 | * {@link Datastore#save} to see how to target properties at different
|
511 | * levels of nesting within your entity.
|
512 | * @param {object} entities.data Data to save with the provided key.
|
513 | * @param {function} callback The callback function.
|
514 | * @param {?error} callback.err An error returned while making this request
|
515 | * @param {object} callback.apiResponse The full API response.
|
516 | */
|
517 | insert(entities: Entities): Promise<InsertResponse>;
|
518 | insert(entities: Entities, callback: InsertCallback): void;
|
519 | /**
|
520 | * Insert or update the specified object(s). If a key is incomplete, its
|
521 | * associated object is inserted and the original Key object is updated to
|
522 | * contain the generated ID.
|
523 | *
|
524 | * This method will determine the correct Datastore method to execute
|
525 | * (`upsert`, `insert`, or `update`) by using the key(s) provided. For
|
526 | * example, if you provide an incomplete key (one without an ID), the request
|
527 | * will create a new entity and have its ID automatically assigned. If you
|
528 | * provide a complete key, the entity will be updated with the data specified.
|
529 | *
|
530 | * By default, all properties are indexed. To prevent a property from being
|
531 | * included in *all* indexes, you must supply an `excludeFromIndexes` array.
|
532 | *
|
533 | * To prevent large properties from being included in *all* indexes, you must supply
|
534 | * `excludeLargeProperties: true`.
|
535 | * See below for an example.
|
536 | *
|
537 | * @borrows {@link Transaction#save} as save
|
538 | *
|
539 | * @throws {Error} If an unrecognized method is provided.
|
540 | *
|
541 | * @param {object|object[]} entities Datastore key object(s).
|
542 | * @param {Key} entities.key Datastore key object.
|
543 | * @param {string[]} [entities.excludeFromIndexes] Exclude properties from
|
544 | * indexing using a simple JSON path notation. See the example below to
|
545 | * see how to target properties at different levels of nesting within your
|
546 | * @param {boolean} [entities.excludeLargeProperties] Automatically exclude
|
547 | * large properties from indexing. It help in storing large values.
|
548 | * @param {string} [entities.method] Explicit method to use, either 'insert',
|
549 | * 'update', or 'upsert'.
|
550 | * @param {object} entities.data Data to save with the provided key.
|
551 | * entity.
|
552 | * @param {object} [gaxOptions] Request configuration options, outlined here:
|
553 | * https://googleapis.github.io/gax-nodejs/global.html#CallOptions.
|
554 | * @param {function} callback The callback function.
|
555 | * @param {?error} callback.err An error returned while making this request
|
556 | * @param {object} callback.apiResponse The full API response.
|
557 | *
|
558 | * @example
|
559 | * ```
|
560 | * //-
|
561 | * // Save a single entity.
|
562 | * //
|
563 | * // Notice that we are providing an incomplete key. After saving, the
|
564 | * // original Key object used to save will be updated to contain the path
|
565 | * // with its generated ID.
|
566 | * //-
|
567 | * const key = datastore.key('Company');
|
568 | * const entity = {
|
569 | * key: key,
|
570 | * data: {
|
571 | * rating: '10'
|
572 | * }
|
573 | * };
|
574 | *
|
575 | * datastore.save(entity, (err) => {
|
576 | * console.log(key.path); // [ 'Company', 5669468231434240 ]
|
577 | * console.log(key.namespace); // undefined
|
578 | * });
|
579 | *
|
580 | * //-
|
581 | * // Save a single entity using a provided name instead of auto-generated ID.
|
582 | * //
|
583 | * // Here we are providing a key with name instead of an ID. After saving,
|
584 | * // the original Key object used to save will be updated to contain the
|
585 | * // path with the name instead of a generated ID.
|
586 | * //-
|
587 | * const key = datastore.key(['Company', 'donutshack']);
|
588 | * const entity = {
|
589 | * key: key,
|
590 | * data: {
|
591 | * name: 'DonutShack',
|
592 | * rating: 8
|
593 | * }
|
594 | * };
|
595 | *
|
596 | * datastore.save(entity, (err) => {
|
597 | * console.log(key.path); // ['Company', 'donutshack']
|
598 | * console.log(key.namespace); // undefined
|
599 | * });
|
600 | *
|
601 | * //-
|
602 | * // Save a single entity with a provided namespace. Namespaces allow for
|
603 | * // multitenancy. To read more about this, see
|
604 | * // [the Datastore docs on key concepts](https://goo.gl/M1LUAu).
|
605 | * //
|
606 | * // Here we are providing a key with namespace.
|
607 | * //-
|
608 | * const key = datastore.key({
|
609 | * namespace: 'my-namespace',
|
610 | * path: ['Company', 'donutshack']
|
611 | * });
|
612 | *
|
613 | * const entity = {
|
614 | * key: key,
|
615 | * data: {
|
616 | * name: 'DonutShack',
|
617 | * rating: 8
|
618 | * }
|
619 | * };
|
620 | *
|
621 | * datastore.save(entity, (err) => {
|
622 | * console.log(key.path); // ['Company', 'donutshack']
|
623 | * console.log(key.namespace); // 'my-namespace'
|
624 | * });
|
625 | *
|
626 | * //-
|
627 | * // Save different types of data, including ints, doubles, dates, booleans,
|
628 | * // blobs, and lists.
|
629 | * //
|
630 | * // Notice that we are providing an incomplete key. After saving, the
|
631 | * // original Key object used to save will be updated to contain the path
|
632 | * // with its generated ID.
|
633 | * //-
|
634 | * const key = datastore.key('Company');
|
635 | * const entity = {
|
636 | * key: key,
|
637 | * data: {
|
638 | * name: 'DonutShack',
|
639 | * rating: datastore.int(10),
|
640 | * worth: datastore.double(123456.78),
|
641 | * location: datastore.geoPoint({
|
642 | * latitude: 40.6894,
|
643 | * longitude: -74.0447
|
644 | * }),
|
645 | * numDonutsServed: 45,
|
646 | * founded: new Date('Tue May 12 2015 15:30:00 GMT-0400 (EDT)'),
|
647 | * isStartup: true,
|
648 | * donutEmoji: Buffer.from('\uD83C\uDF69'),
|
649 | * keywords: [
|
650 | * 'donut',
|
651 | * 'coffee',
|
652 | * 'yum'
|
653 | * ]
|
654 | * }
|
655 | * };
|
656 | *
|
657 | * datastore.save(entity, (err, apiResponse) => {});
|
658 | *
|
659 | * //-
|
660 | * // Use an array, `excludeFromIndexes`, to exclude properties from indexing.
|
661 | * // This will allow storing string values larger than 1500 bytes.
|
662 | * //-
|
663 | * const entity = {
|
664 | * key: datastore.key('Company'),
|
665 | * excludeFromIndexes: [
|
666 | * 'description',
|
667 | * 'embeddedEntity.description',
|
668 | * 'arrayValue[]',
|
669 | * 'arrayValue[].description'
|
670 | * ],
|
671 | * data: {
|
672 | * description: 'Long string (...)',
|
673 | * embeddedEntity: {
|
674 | * description: 'Long string (...)'
|
675 | * },
|
676 | * arrayValue: [
|
677 | * 'Long string (...)',
|
678 | * {
|
679 | * description: 'Long string (...)'
|
680 | * }
|
681 | * ]
|
682 | * }
|
683 | * };
|
684 | *
|
685 | * datastore.save(entity, (err, apiResponse) => {});
|
686 | *
|
687 | * //-
|
688 | * // Use boolean `excludeLargeProperties`, to auto exclude Large properties from indexing.
|
689 | * // This will allow storing string values larger than 1500 bytes.
|
690 | * //-
|
691 | * const entity = {
|
692 | * key: datastore.key('Company'),
|
693 | * data: {
|
694 | * description: 'Long string (...)',
|
695 | * embeddedEntity: {
|
696 | * description: 'Long string (...)'
|
697 | * },
|
698 | * arrayValue: [
|
699 | * 'Long string (...)',
|
700 | * {
|
701 | * description: 'Long string (...)'
|
702 | * }
|
703 | * ]
|
704 | * },
|
705 | * excludeLargeProperties: true
|
706 | * };
|
707 | *
|
708 | * datastore.save(entity, (err, apiResponse) => {});
|
709 | *
|
710 | * //-
|
711 | * // Save multiple entities at once.
|
712 | * //-
|
713 | * const companyKey = datastore.key(['Company', 123]);
|
714 | * const productKey = datastore.key(['Product', 'Computer']);
|
715 | * const entities = [
|
716 | * {
|
717 | * key: companyKey,
|
718 | * data: {
|
719 | * HQ: 'Dallas, TX'
|
720 | * }
|
721 | * },
|
722 | * {
|
723 | * key: productKey,
|
724 | * data: {
|
725 | * vendor: 'Dell'
|
726 | * }
|
727 | * }
|
728 | * ];
|
729 | *
|
730 | * datastore.save(entities, (err, apiResponse) => {});
|
731 | *
|
732 | * //-
|
733 | * // Explicitly attempt to 'insert' a specific entity.
|
734 | * //-
|
735 | * const userKey = datastore.key(['User', 'chilts']);
|
736 | * const entity = {
|
737 | * key: userKey,
|
738 | * method: 'insert',
|
739 | * data: {
|
740 | * fullName: 'Andrew Chilton'
|
741 | * }
|
742 | * };
|
743 | *
|
744 | * datastore.save(entity, (err, apiResponse) => {});
|
745 | *
|
746 | * //-
|
747 | * // Returns a Promise if callback is omitted.
|
748 | * //-
|
749 | * datastore.save(entity).then((data) => {
|
750 | * const apiResponse = data[0];
|
751 | * });
|
752 | * ```
|
753 | */
|
754 | save(entities: Entities, gaxOptions?: CallOptions): Promise<SaveResponse>;
|
755 | save(entities: Entities, gaxOptions: CallOptions, callback: SaveCallback): void;
|
756 | save(entities: Entities, callback: SaveCallback): void;
|
757 | /**
|
758 | * Maps to {@link https://cloud.google.com/nodejs/docs/reference/datastore/latest/datastore/datastore#_google_cloud_datastore_Datastore_save_member_1_|Datastore#save}, forcing the method to be `update`.
|
759 | *
|
760 | * @param {object|object[]} entities Datastore key object(s).
|
761 | * @param {Key} entities.key Datastore key object.
|
762 | * @param {string[]} [entities.excludeFromIndexes] Exclude properties from
|
763 | * indexing using a simple JSON path notation. See the examples in
|
764 | * {@link Datastore#save} to see how to target properties at different
|
765 | * levels of nesting within your entity.
|
766 | * @param {object} entities.data Data to save with the provided key.
|
767 | * @param {function} callback The callback function.
|
768 | * @param {?error} callback.err An error returned while making this request
|
769 | * @param {object} callback.apiResponse The full API response.
|
770 | */
|
771 | update(entities: Entities): Promise<UpdateResponse>;
|
772 | update(entities: Entities, callback: UpdateCallback): void;
|
773 | /**
|
774 | * Maps to {@link https://cloud.google.com/nodejs/docs/reference/datastore/latest/datastore/datastore#_google_cloud_datastore_Datastore_save_member_1_|Datastore#save}, forcing the method to be `upsert`.
|
775 | *
|
776 | * @param {object|object[]} entities Datastore key object(s).
|
777 | * @param {Key} entities.key Datastore key object.
|
778 | * @param {string[]} [entities.excludeFromIndexes] Exclude properties from
|
779 | * indexing using a simple JSON path notation. See the examples in
|
780 | * {@link Datastore#save} to see how to target properties at different
|
781 | * levels of nesting within your entity.
|
782 | * @param {object} entities.data Data to save with the provided key.
|
783 | * @param {function} callback The callback function.
|
784 | * @param {?error} callback.err An error returned while making this request
|
785 | * @param {object} callback.apiResponse The full API response.
|
786 | */
|
787 | upsert(entities: Entities): Promise<UpsertResponse>;
|
788 | upsert(entities: Entities, callback: UpsertCallback): void;
|
789 | /**
|
790 | * Helper function to get a Datastore Double object.
|
791 | *
|
792 | * @param {number} value The double value.
|
793 | * @returns {object}
|
794 | *
|
795 | * @example
|
796 | * ```
|
797 | * const {Datastore} = require('@google-cloud/datastore');
|
798 | * const datastore = new Datastore();
|
799 | * const threeDouble = datastore.double(3.0);
|
800 | * ```
|
801 | */
|
802 | static double(value: number): entity.Double;
|
803 | /**
|
804 | * Helper function to get a Datastore Double object.
|
805 | *
|
806 | * @param {number} value The double value.
|
807 | * @returns {object}
|
808 | */
|
809 | double(value: number): entity.Double;
|
810 | /**
|
811 | * Helper function to check if something is a Datastore Double object.
|
812 | *
|
813 | * @param {*} value The double value.
|
814 | * @returns {boolean}
|
815 | *
|
816 | * @example
|
817 | * ```
|
818 | * const {Datastore} = require('@google-cloud/datastore');
|
819 | * const datastore = new Datastore();
|
820 | * datastore.isDouble(0.42); // false
|
821 | * datastore.isDouble(datastore.double(0.42)); // true
|
822 | * ```
|
823 | */
|
824 | static isDouble(value?: {}): value is entity.Double;
|
825 | /**
|
826 | * Helper function to check if something is a Datastore Double object.
|
827 | *
|
828 | * @param {*} value The double value.
|
829 | * @returns {boolean}
|
830 | *
|
831 | */
|
832 | isDouble(value?: {}): value is entity.Double;
|
833 | /**
|
834 | * Helper function to get a Datastore Geo Point object.
|
835 | *
|
836 | * @param {object} coordinates The coordinates value.
|
837 | * @param {number} coordinates.latitude Latitudinal value.
|
838 | * @param {number} coordinates.longitude Longitudinal value.
|
839 | * @returns {object}
|
840 | *
|
841 | * @example
|
842 | * ```
|
843 | * const {Datastore} = require('@google-cloud/datastore');
|
844 | * const datastore = new Datastore();
|
845 | * const coordinates = {
|
846 | * latitude: 40.6894,
|
847 | * longitude: -74.0447
|
848 | * };
|
849 | *
|
850 | * const geoPoint = datastore.geoPoint(coordinates);
|
851 | *
|
852 | * //-
|
853 | * // List all companies that are located at 40.123 latitude
|
854 | * // and -74.0447 longitude.
|
855 | * //-
|
856 | * const query = datastore.createQuery('Company');
|
857 | * const companyQuery = query
|
858 | * .filter('geoPoint.latitude', datastore.double(40.123))
|
859 | * .filter('geoPoint.longitude', datastore.double(-74.0447));
|
860 | * ```
|
861 | */
|
862 | static geoPoint(coordinates: entity.Coordinates): entity.GeoPoint;
|
863 | /**
|
864 | * Helper function to get a Datastore Geo Point object.
|
865 | *
|
866 | * @param {object} coordinates The coordinates value.
|
867 | * @param {number} coordinates.latitude Latitudinal value.
|
868 | * @param {number} coordinates.longitude Longitudinal value.
|
869 | * @returns {object}
|
870 | *
|
871 | */
|
872 | geoPoint(coordinates: entity.Coordinates): entity.GeoPoint;
|
873 | /**
|
874 | * Helper function to check if something is a Datastore Geo Point object.
|
875 | *
|
876 | * @param {*} value The coordinates value.
|
877 | * @returns {boolean}
|
878 | *
|
879 | * @example
|
880 | * ```
|
881 | * const {Datastore} = require('@google-cloud/datastore');
|
882 | * const datastore = new Datastore();
|
883 | * const coordinates = {
|
884 | * latitude: 0,
|
885 | * longitude: 0
|
886 | * };
|
887 | *
|
888 | * datastore.isGeoPoint(coordinates); // false
|
889 | * datastore.isGeoPoint(datastore.geoPoint(coordinates)); // true
|
890 | * ```
|
891 | */
|
892 | static isGeoPoint(value?: {}): value is entity.GeoPoint;
|
893 | /**
|
894 | * Helper function to check if something is a Datastore Geo Point object.
|
895 | *
|
896 | * @param {*} value The coordinates value.
|
897 | * @returns {boolean}
|
898 | *
|
899 | */
|
900 | isGeoPoint(value?: {}): value is entity.GeoPoint;
|
901 | /**
|
902 | * Helper function to get a Datastore Integer object.
|
903 | *
|
904 | * This is also useful when using an ID outside the bounds of a JavaScript
|
905 | * Number object.
|
906 | *
|
907 | * @param {number} value The integer value.
|
908 | * @returns {object}
|
909 | *
|
910 | * @example
|
911 | * ```
|
912 | * const {Datastore} = require('@google-cloud/datastore');
|
913 | * const datastore = new Datastore();
|
914 | * const sevenInteger = datastore.int(7);
|
915 | *
|
916 | * //-
|
917 | * // Create an Int to support long Key IDs.
|
918 | * //-
|
919 | * const key = datastore.key([
|
920 | * 'Kind',
|
921 | * datastore.int('100000000000001234')
|
922 | * ]);
|
923 | * ```
|
924 | */
|
925 | static int(value: number | string): entity.Int;
|
926 | /**
|
927 | * Helper function to get a Datastore Integer object.
|
928 | *
|
929 | * This is also useful when using an ID outside the bounds of a JavaScript
|
930 | * Number object.
|
931 | *
|
932 | * @param {number | int} value The integer value.
|
933 | * @returns {object}
|
934 | *
|
935 | */
|
936 | int(value: number | string): entity.Int;
|
937 | /**
|
938 | * Helper function to check if something is a Datastore Integer object.
|
939 | *
|
940 | * @param {*} value The value to check
|
941 | * @returns {boolean}
|
942 | *
|
943 | * @example
|
944 | * ```
|
945 | * const {Datastore} = require('@google-cloud/datastore');
|
946 | * const datastore = new Datastore();
|
947 | * datastore.isInt(42); // false
|
948 | * datastore.isInt(datastore.int(42)); // true
|
949 | * ```
|
950 | */
|
951 | static isInt(value?: {}): value is entity.Int;
|
952 | /**
|
953 | * Helper function to check if something is a Datastore Integer object.
|
954 | *
|
955 | * @param {*} value The value to check
|
956 | * @returns {boolean}
|
957 | *
|
958 | */
|
959 | isInt(value?: {}): value is entity.Int;
|
960 | /**
|
961 | * Access the Key from an Entity object.
|
962 | *
|
963 | * @name Datastore.KEY
|
964 | * @type {symbol}
|
965 | */
|
966 | /**
|
967 | * Access the Key from an Entity object.
|
968 | *
|
969 | * @name Datastore#KEY
|
970 | * @type {symbol}
|
971 | */
|
972 | static KEY: typeof entity.KEY_SYMBOL;
|
973 | KEY: typeof entity.KEY_SYMBOL;
|
974 | /**
|
975 | * This is one of three values which may be returned from
|
976 | * {@link Datastore#runQuery}, {@link Transaction#runQuery}, and
|
977 | * {@link Query#run} as `info.moreResults`.
|
978 | *
|
979 | * There *may* be more results after the specified end cursor.
|
980 | *
|
981 | * @type {string}
|
982 | */
|
983 | static MORE_RESULTS_AFTER_CURSOR: string;
|
984 | MORE_RESULTS_AFTER_CURSOR: string;
|
985 | /**
|
986 | * This is one of three values which may be returned from
|
987 | * {@link Datastore#runQuery}, {@link Transaction#runQuery}, and
|
988 | * {@link Query#run} as `info.moreResults`.
|
989 | *
|
990 | * There *may* be more results after the specified limit.
|
991 | *
|
992 | * @type {string}
|
993 | */
|
994 | static MORE_RESULTS_AFTER_LIMIT: string;
|
995 | MORE_RESULTS_AFTER_LIMIT: string;
|
996 | /**
|
997 | * This is one of three values which may be returned from
|
998 | * {@link Datastore#runQuery}, {@link Transaction#runQuery}, and
|
999 | * {@link Query#run} as `info.moreResults`.
|
1000 | *
|
1001 | * There are no more results left to query for.
|
1002 | *
|
1003 | * @type {string}
|
1004 | */
|
1005 | static NO_MORE_RESULTS: string;
|
1006 | NO_MORE_RESULTS: string;
|
1007 | /**
|
1008 | * Create a query for the specified kind. See {@link Query} for all
|
1009 | * of the available methods.
|
1010 | *
|
1011 | * @see {@link https://cloud.google.com/datastore/docs/concepts/queries| Datastore Queries}
|
1012 | * @see {@link Query}
|
1013 | *
|
1014 | * @param {string} [namespace] Namespace.
|
1015 | * @param {string} kind The kind to query.
|
1016 | * @returns {Query}
|
1017 | *
|
1018 | * @example
|
1019 | * ```
|
1020 | * const {Datastore} = require('@google-cloud/datastore');
|
1021 | * const datastore = new Datastore();
|
1022 | * const query = datastore.createQuery('Company');
|
1023 | * ```
|
1024 | */
|
1025 | createQuery(kind?: string): Query;
|
1026 | createQuery(kind?: string[]): Query;
|
1027 | createQuery(namespace: string, kind: string): Query;
|
1028 | createQuery(namespace: string, kind: string[]): Query;
|
1029 | /**
|
1030 | * Helper to create a Key object, scoped to the instance's namespace by
|
1031 | * default.
|
1032 | *
|
1033 | * You may also specify a configuration object to define a namespace and path.
|
1034 | *
|
1035 | * @param {object|string|array} [options] Key path. To specify or override a namespace,
|
1036 | * you must use an object here to explicitly state it.
|
1037 | * @param {string|array} [options.path] Key path.
|
1038 | * @param {string} [options.namespace] Optional namespace.
|
1039 | * @returns {Key} A newly created Key from the options given.
|
1040 | *
|
1041 | * @example
|
1042 | * ```
|
1043 | * <caption>Create an incomplete key with a kind value of `Company`.
|
1044 | * Since no Id is supplied, Datastore will generate one on save.</caption>
|
1045 | * const {Datastore} = require('@google-cloud/datastore');
|
1046 | * const datastore = new Datastore();
|
1047 | * const key = datastore.key('Company');
|
1048 | *
|
1049 | * ```
|
1050 | * @example
|
1051 | * ```
|
1052 | * <caption>Create a complete key with a kind value of `Company` and Id `123`.</caption>
|
1053 | * const {Datastore} = require('@google-cloud/datastore');
|
1054 | * const datastore = new Datastore();
|
1055 | * const key = datastore.key(['Company', 123]);
|
1056 | *
|
1057 | * ```
|
1058 | * @example
|
1059 | * ```
|
1060 | * <caption>If the ID integer is outside the bounds of a JavaScript Number
|
1061 | * object, create an Int.</caption>
|
1062 | * const {Datastore} = require('@google-cloud/datastore');
|
1063 | * const datastore = new Datastore();
|
1064 | * const key = datastore.key([
|
1065 | * 'Company',
|
1066 | * datastore.int('100000000000001234')
|
1067 | * ]);
|
1068 | *
|
1069 | * ```
|
1070 | * @example
|
1071 | * ```
|
1072 | * <caption>Create a complete key with a kind value of `Company` and name `Google`.
|
1073 | * Because the supplied Id is a string, Datastore will prefix it with "name=".
|
1074 | * Had the supplied Id been numeric, Datastore would prefix it with the standard, "id=".</caption>
|
1075 | * const {Datastore} = require('@google-cloud/datastore');
|
1076 | * const datastore = new Datastore();
|
1077 | * const key = datastore.key(['Company', 'Google']);
|
1078 | *
|
1079 | * ```
|
1080 | * @example
|
1081 | * ```
|
1082 | * <caption>Create a complete key from a provided namespace and path.</caption>
|
1083 | * const {Datastore} = require('@google-cloud/datastore');
|
1084 | * const datastore = new Datastore();
|
1085 | * const key = datastore.key({
|
1086 | * namespace: 'My-NS',
|
1087 | * path: ['Company', 123]
|
1088 | * });
|
1089 | *
|
1090 | * ```
|
1091 | * @example
|
1092 | * ```
|
1093 | * <caption>Create a complete key that specifies an ancestor. This will create a Team entity
|
1094 | * with a name of "Datastore", which belongs to the Company with the "name=Google" key.</caption>
|
1095 | * const {Datastore} = require('@google-cloud/datastore');
|
1096 | * const datastore = new Datastore();
|
1097 | * const key = datastore.key(['Company', 'Google', 'Team', 'Datastore']);
|
1098 | *
|
1099 | * ```
|
1100 | * @example
|
1101 | * ```
|
1102 | * <caption>Create a incomplete key that specifies an ancestor. This will create an Employee entity
|
1103 | * with an auto-generated Id, which belongs to the Company with the "name=Google" key.</caption>
|
1104 | * const {Datastore} = require('@google-cloud/datastore');
|
1105 | * const datastore = new Datastore();
|
1106 | * const key = datastore.key(['Company', 'Google', 'Employee']);
|
1107 | * ```
|
1108 | */
|
1109 | key(options: entity.KeyOptions): entity.Key;
|
1110 | key(path: PathType[]): entity.Key;
|
1111 | key(path: string): entity.Key;
|
1112 | /**
|
1113 | * Helper function to check if something is a Datastore Key object.
|
1114 | *
|
1115 | * @param {*} value Value to compare property to.
|
1116 | * @returns {boolean}
|
1117 | *
|
1118 | * @example
|
1119 | * ```
|
1120 | * const {Datastore} = require('@google-cloud/datastore');
|
1121 | * const datastore = new Datastore();
|
1122 | * datastore.isKey({path: ['Company', 123]}); // false
|
1123 | * datastore.isKey(datastore.key(['Company', 123])); // true
|
1124 | * ```
|
1125 | */
|
1126 | static isKey(value?: {}): value is entity.Key;
|
1127 | isKey(value?: {}): value is entity.Key;
|
1128 | /**
|
1129 | * Helper to create a URL safe key.
|
1130 | *
|
1131 | * This is intended to work with the "legacy" representation of a
|
1132 | * datastore "Key" used within Google App Engine (a so-called "Reference").
|
1133 | * The returned string can be used as the "urlsafe"
|
1134 | * The base64 encoded values will have padding removed.
|
1135 | *
|
1136 | *
|
1137 | * @param {entity.Key} key Entity key object.
|
1138 | * @param {string} locationPrefix Optional .
|
1139 | * The location prefix of an App Engine project ID.
|
1140 | * Often this value is 's~', but may also be 'e~', or other location prefixes
|
1141 | * currently unknown.
|
1142 | * @param {function} callback The callback function.
|
1143 | * @param {?error} callback.err An error returned while making this request
|
1144 | * @param {string} callback.urlSafeKey A Base64-encoded URL-safe key.
|
1145 | *
|
1146 | * @example
|
1147 | * ```
|
1148 | * const {Datastore} = require('@google-cloud/datastore');
|
1149 | * const datastore = new Datastore();
|
1150 | * const key = datastore.key(['Company', 'Google']);
|
1151 | *
|
1152 | * datastore.keyToLegacyUrlSafe(key, (err, urlSafeKey) => {
|
1153 | * if (err) {
|
1154 | * // Error handling omitted.
|
1155 | * }
|
1156 | * console.log(urlSafeKey);
|
1157 | * });
|
1158 | *
|
1159 | * //-
|
1160 | * // Create a complete URL-safe key using a location prefix.
|
1161 | * //-
|
1162 | * const locationPrefix = 's~';
|
1163 | *
|
1164 | * datastore.keyToLegacyUrlSafe(key, locationPrefix, (err, urlSafeKey) => {
|
1165 | * if (err) {
|
1166 | * // Error handling omitted.
|
1167 | * }
|
1168 | * console.log(urlSafeKey);
|
1169 | * });
|
1170 | *
|
1171 | * //-
|
1172 | * // If the callback is omitted, we'll return a Promise.
|
1173 | * //-
|
1174 | * datastore.keyToLegacyUrlSafe(key).then((data) => {
|
1175 | * const urlSafeKey = data[0];
|
1176 | * console.log(urlSafeKey);
|
1177 | * });
|
1178 | * ```
|
1179 | */
|
1180 | keyToLegacyUrlSafe(key: entity.Key, locationPrefix?: string): Promise<string>;
|
1181 | keyToLegacyUrlSafe(key: entity.Key, callback: KeyToLegacyUrlSafeCallback): void;
|
1182 | keyToLegacyUrlSafe(key: entity.Key, locationPrefix: string, callback: KeyToLegacyUrlSafeCallback): void;
|
1183 | /**
|
1184 | * Helper to convert URL safe key string to entity key object
|
1185 | *
|
1186 | * This is intended to work with the "legacy" representation of a
|
1187 | * datastore "Key" used within Google App Engine (a so-called "Reference").
|
1188 | *
|
1189 | * @param {entity.Key} key Entity key object.
|
1190 | * @param {string} locationPrefix Optional .
|
1191 | * The location prefix of an App Engine project ID.
|
1192 | * Often this value is 's~', but may also be 'e~', or other location prefixes
|
1193 | * currently unknown.
|
1194 | * @returns {string} Created urlsafe key.
|
1195 | *
|
1196 | * @example
|
1197 | * ```
|
1198 | * const {Datastore} = require('@google-cloud/datastore');
|
1199 | * const datastore = new Datastore();
|
1200 | * const urlSafeKey = 'ag9ncmFzcy1jbHVtcC00NzlyEwsSB0NvbXBhbnkiBkdvb2dsZQw';
|
1201 | *
|
1202 | * datastore.keyFromLegacyUrlsafe(key);
|
1203 | *
|
1204 | * ```
|
1205 | */
|
1206 | keyFromLegacyUrlsafe(key: string): entity.Key;
|
1207 | /**
|
1208 | * Create a new Transaction object.
|
1209 | *
|
1210 | * @param {object} [options] Configuration object.
|
1211 | * @param {string} [options.id] The ID of a previously run transaction.
|
1212 | * @param {boolean} [options.readOnly=false] A read-only transaction cannot
|
1213 | * modify entities.
|
1214 | * @returns {Transaction}
|
1215 | *
|
1216 | * @example
|
1217 | * ```
|
1218 | * const {Datastore} = require('@google-cloud/datastore');
|
1219 | * const datastore = new Datastore();
|
1220 | * const transaction = datastore.transaction();
|
1221 | * ```
|
1222 | */
|
1223 | transaction(options?: TransactionOptions): Transaction;
|
1224 | /**
|
1225 | * Determine the appropriate endpoint to use for API requests. If not
|
1226 | * explicitly defined, check for the "DATASTORE_EMULATOR_HOST" environment
|
1227 | * variable, used to connect to a local Datastore server.
|
1228 | *
|
1229 | * @private
|
1230 | *
|
1231 | * @param {string} customApiEndpoint Custom API endpoint.
|
1232 | */
|
1233 | determineBaseUrl_(customApiEndpoint?: string): void;
|
1234 | /**
|
1235 | * {@link DatastoreRequest} class.
|
1236 | *
|
1237 | * @name Datastore.DatastoreRequest
|
1238 | * @see DatastoreRequest
|
1239 | * @type {constructor}
|
1240 | */
|
1241 | DatastoreRequest: typeof DatastoreRequest;
|
1242 | /**
|
1243 | * {@link Query} class.
|
1244 | *
|
1245 | * @name Datastore.Query
|
1246 | * @see Query
|
1247 | * @type {constructor}
|
1248 | */
|
1249 | Query: typeof Query;
|
1250 | /**
|
1251 | * {@link Transaction} class.
|
1252 | *
|
1253 | * @name Datastore.Transaction
|
1254 | * @see Transaction
|
1255 | * @type {constructor}
|
1256 | */
|
1257 | Transaction: typeof Transaction;
|
1258 | }
|
1259 | export { Datastore };
|
1260 | export interface TransactionOptions {
|
1261 | id?: string;
|
1262 | readOnly?: boolean;
|
1263 | }
|
1264 | export { Index, DatastoreRequest, Query, Transaction };
|
1265 | export interface DatastoreOptions extends GoogleAuthOptions {
|
1266 | namespace?: string;
|
1267 | apiEndpoint?: string;
|
1268 | sslCreds?: ChannelCredentials;
|
1269 | databaseId?: string;
|
1270 | fallback?: Fallback;
|
1271 | }
|
1272 | export interface KeyToLegacyUrlSafeCallback {
|
1273 | (err?: Error | null, urlSafeKey?: string): void;
|
1274 | }
|
1275 | declare const v1: any;
|
1276 | export { v1 };
|
1277 | export { DatastoreClient, DatastoreAdminClient } from './v1';
|