UNPKG

2.37 kBJavaScriptView Raw
1"use strict";
2// Copyright 2020 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// https://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.
15Object.defineProperty(exports, "__esModule", { value: true });
16exports.Index = void 0;
17const promisify_1 = require("@google-cloud/promisify");
18/**
19 * @class
20 * @param {Datastore} datastore The parent instance of this index.
21 * @param {string} id The index name or id.
22 *
23 * @example
24 * ```
25 * const {Datastore} = require('@google-cloud/datastore');
26 * const datastore = new Datastore();
27 * const index = datastore.index('my-index');
28 * ```
29 */
30class Index {
31 constructor(datastore, id) {
32 this.datastore = datastore;
33 this.id = id.split('/').pop();
34 }
35 get(gaxOptionsOrCallback, cb) {
36 const gaxOpts = typeof gaxOptionsOrCallback === 'object' ? gaxOptionsOrCallback : {};
37 const callback = typeof gaxOptionsOrCallback === 'function' ? gaxOptionsOrCallback : cb;
38 this.getMetadata(gaxOpts, (err, metadata) => {
39 callback(err, err ? null : this, metadata);
40 });
41 }
42 getMetadata(gaxOptionsOrCallback, cb) {
43 const gaxOpts = typeof gaxOptionsOrCallback === 'object' ? gaxOptionsOrCallback : {};
44 const callback = typeof gaxOptionsOrCallback === 'function' ? gaxOptionsOrCallback : cb;
45 this.datastore.request_({
46 client: 'DatastoreAdminClient',
47 method: 'getIndex',
48 reqOpts: {
49 indexId: this.id,
50 },
51 gaxOpts,
52 }, (err, resp) => {
53 if (resp) {
54 this.metadata = resp;
55 }
56 callback(err, resp);
57 });
58 }
59}
60exports.Index = Index;
61/*! Developer Documentation
62 *
63 * All async methods (except for streams) will return a Promise in the event
64 * that a callback is omitted.
65 */
66(0, promisify_1.promisifyAll)(Index);
67//# sourceMappingURL=index-class.js.map
\No newline at end of file