datastore-api 2.2.0 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -0
- package/dist/datastore-api.cjs.development.js +1436 -0
- package/dist/datastore-api.cjs.development.js.map +1 -0
- package/dist/datastore-api.cjs.production.min.js +2 -0
- package/dist/datastore-api.cjs.production.min.js.map +1 -0
- package/dist/datastore-api.esm.js +1415 -0
- package/dist/datastore-api.esm.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +8 -0
- package/dist/lib/dstore-api.d.ts +350 -0
- package/dist/mock/index.d.ts +107 -0
- package/dist/mock/operators.d.ts +8 -0
- package/package.json +21 -27
- package/src/index.ts +1 -0
- package/src/lib/dstore-api-cloud.spec.ts +435 -0
- package/src/lib/dstore-api-emulator.spec.ts +440 -0
- package/src/lib/dstore-api-simulator.spec.ts +461 -0
- package/src/lib/dstore-api.ts +706 -0
- package/src/mock/index.ts +649 -0
- package/src/mock/operators.ts +20 -0
- package/CHANGELOG.md +0 -124
|
@@ -0,0 +1,1436 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var async_hooks = require('async_hooks');
|
|
6
|
+
var promises = require('timers/promises');
|
|
7
|
+
var datastore = require('@google-cloud/datastore');
|
|
8
|
+
var entity = require('@google-cloud/datastore/build/src/entity');
|
|
9
|
+
var assertateDebug = require('assertate-debug');
|
|
10
|
+
var Debug = require('debug');
|
|
11
|
+
var promClient = require('prom-client');
|
|
12
|
+
|
|
13
|
+
function _regeneratorRuntime() {
|
|
14
|
+
_regeneratorRuntime = function () {
|
|
15
|
+
return e;
|
|
16
|
+
};
|
|
17
|
+
var t,
|
|
18
|
+
e = {},
|
|
19
|
+
r = Object.prototype,
|
|
20
|
+
n = r.hasOwnProperty,
|
|
21
|
+
o = Object.defineProperty || function (t, e, r) {
|
|
22
|
+
t[e] = r.value;
|
|
23
|
+
},
|
|
24
|
+
i = "function" == typeof Symbol ? Symbol : {},
|
|
25
|
+
a = i.iterator || "@@iterator",
|
|
26
|
+
c = i.asyncIterator || "@@asyncIterator",
|
|
27
|
+
u = i.toStringTag || "@@toStringTag";
|
|
28
|
+
function define(t, e, r) {
|
|
29
|
+
return Object.defineProperty(t, e, {
|
|
30
|
+
value: r,
|
|
31
|
+
enumerable: !0,
|
|
32
|
+
configurable: !0,
|
|
33
|
+
writable: !0
|
|
34
|
+
}), t[e];
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
define({}, "");
|
|
38
|
+
} catch (t) {
|
|
39
|
+
define = function (t, e, r) {
|
|
40
|
+
return t[e] = r;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function wrap(t, e, r, n) {
|
|
44
|
+
var i = e && e.prototype instanceof Generator ? e : Generator,
|
|
45
|
+
a = Object.create(i.prototype),
|
|
46
|
+
c = new Context(n || []);
|
|
47
|
+
return o(a, "_invoke", {
|
|
48
|
+
value: makeInvokeMethod(t, r, c)
|
|
49
|
+
}), a;
|
|
50
|
+
}
|
|
51
|
+
function tryCatch(t, e, r) {
|
|
52
|
+
try {
|
|
53
|
+
return {
|
|
54
|
+
type: "normal",
|
|
55
|
+
arg: t.call(e, r)
|
|
56
|
+
};
|
|
57
|
+
} catch (t) {
|
|
58
|
+
return {
|
|
59
|
+
type: "throw",
|
|
60
|
+
arg: t
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
e.wrap = wrap;
|
|
65
|
+
var h = "suspendedStart",
|
|
66
|
+
l = "suspendedYield",
|
|
67
|
+
f = "executing",
|
|
68
|
+
s = "completed",
|
|
69
|
+
y = {};
|
|
70
|
+
function Generator() {}
|
|
71
|
+
function GeneratorFunction() {}
|
|
72
|
+
function GeneratorFunctionPrototype() {}
|
|
73
|
+
var p = {};
|
|
74
|
+
define(p, a, function () {
|
|
75
|
+
return this;
|
|
76
|
+
});
|
|
77
|
+
var d = Object.getPrototypeOf,
|
|
78
|
+
v = d && d(d(values([])));
|
|
79
|
+
v && v !== r && n.call(v, a) && (p = v);
|
|
80
|
+
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
|
|
81
|
+
function defineIteratorMethods(t) {
|
|
82
|
+
["next", "throw", "return"].forEach(function (e) {
|
|
83
|
+
define(t, e, function (t) {
|
|
84
|
+
return this._invoke(e, t);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function AsyncIterator(t, e) {
|
|
89
|
+
function invoke(r, o, i, a) {
|
|
90
|
+
var c = tryCatch(t[r], t, o);
|
|
91
|
+
if ("throw" !== c.type) {
|
|
92
|
+
var u = c.arg,
|
|
93
|
+
h = u.value;
|
|
94
|
+
return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
|
|
95
|
+
invoke("next", t, i, a);
|
|
96
|
+
}, function (t) {
|
|
97
|
+
invoke("throw", t, i, a);
|
|
98
|
+
}) : e.resolve(h).then(function (t) {
|
|
99
|
+
u.value = t, i(u);
|
|
100
|
+
}, function (t) {
|
|
101
|
+
return invoke("throw", t, i, a);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
a(c.arg);
|
|
105
|
+
}
|
|
106
|
+
var r;
|
|
107
|
+
o(this, "_invoke", {
|
|
108
|
+
value: function (t, n) {
|
|
109
|
+
function callInvokeWithMethodAndArg() {
|
|
110
|
+
return new e(function (e, r) {
|
|
111
|
+
invoke(t, n, e, r);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
function makeInvokeMethod(e, r, n) {
|
|
119
|
+
var o = h;
|
|
120
|
+
return function (i, a) {
|
|
121
|
+
if (o === f) throw new Error("Generator is already running");
|
|
122
|
+
if (o === s) {
|
|
123
|
+
if ("throw" === i) throw a;
|
|
124
|
+
return {
|
|
125
|
+
value: t,
|
|
126
|
+
done: !0
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
for (n.method = i, n.arg = a;;) {
|
|
130
|
+
var c = n.delegate;
|
|
131
|
+
if (c) {
|
|
132
|
+
var u = maybeInvokeDelegate(c, n);
|
|
133
|
+
if (u) {
|
|
134
|
+
if (u === y) continue;
|
|
135
|
+
return u;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
|
|
139
|
+
if (o === h) throw o = s, n.arg;
|
|
140
|
+
n.dispatchException(n.arg);
|
|
141
|
+
} else "return" === n.method && n.abrupt("return", n.arg);
|
|
142
|
+
o = f;
|
|
143
|
+
var p = tryCatch(e, r, n);
|
|
144
|
+
if ("normal" === p.type) {
|
|
145
|
+
if (o = n.done ? s : l, p.arg === y) continue;
|
|
146
|
+
return {
|
|
147
|
+
value: p.arg,
|
|
148
|
+
done: n.done
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function maybeInvokeDelegate(e, r) {
|
|
156
|
+
var n = r.method,
|
|
157
|
+
o = e.iterator[n];
|
|
158
|
+
if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
|
|
159
|
+
var i = tryCatch(o, e.iterator, r.arg);
|
|
160
|
+
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
|
|
161
|
+
var a = i.arg;
|
|
162
|
+
return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
|
|
163
|
+
}
|
|
164
|
+
function pushTryEntry(t) {
|
|
165
|
+
var e = {
|
|
166
|
+
tryLoc: t[0]
|
|
167
|
+
};
|
|
168
|
+
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
|
|
169
|
+
}
|
|
170
|
+
function resetTryEntry(t) {
|
|
171
|
+
var e = t.completion || {};
|
|
172
|
+
e.type = "normal", delete e.arg, t.completion = e;
|
|
173
|
+
}
|
|
174
|
+
function Context(t) {
|
|
175
|
+
this.tryEntries = [{
|
|
176
|
+
tryLoc: "root"
|
|
177
|
+
}], t.forEach(pushTryEntry, this), this.reset(!0);
|
|
178
|
+
}
|
|
179
|
+
function values(e) {
|
|
180
|
+
if (e || "" === e) {
|
|
181
|
+
var r = e[a];
|
|
182
|
+
if (r) return r.call(e);
|
|
183
|
+
if ("function" == typeof e.next) return e;
|
|
184
|
+
if (!isNaN(e.length)) {
|
|
185
|
+
var o = -1,
|
|
186
|
+
i = function next() {
|
|
187
|
+
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
|
|
188
|
+
return next.value = t, next.done = !0, next;
|
|
189
|
+
};
|
|
190
|
+
return i.next = i;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
throw new TypeError(typeof e + " is not iterable");
|
|
194
|
+
}
|
|
195
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
|
|
196
|
+
value: GeneratorFunctionPrototype,
|
|
197
|
+
configurable: !0
|
|
198
|
+
}), o(GeneratorFunctionPrototype, "constructor", {
|
|
199
|
+
value: GeneratorFunction,
|
|
200
|
+
configurable: !0
|
|
201
|
+
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
|
|
202
|
+
var e = "function" == typeof t && t.constructor;
|
|
203
|
+
return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
|
|
204
|
+
}, e.mark = function (t) {
|
|
205
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
|
|
206
|
+
}, e.awrap = function (t) {
|
|
207
|
+
return {
|
|
208
|
+
__await: t
|
|
209
|
+
};
|
|
210
|
+
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
|
|
211
|
+
return this;
|
|
212
|
+
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
|
|
213
|
+
void 0 === i && (i = Promise);
|
|
214
|
+
var a = new AsyncIterator(wrap(t, r, n, o), i);
|
|
215
|
+
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
|
|
216
|
+
return t.done ? t.value : a.next();
|
|
217
|
+
});
|
|
218
|
+
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
|
|
219
|
+
return this;
|
|
220
|
+
}), define(g, "toString", function () {
|
|
221
|
+
return "[object Generator]";
|
|
222
|
+
}), e.keys = function (t) {
|
|
223
|
+
var e = Object(t),
|
|
224
|
+
r = [];
|
|
225
|
+
for (var n in e) r.push(n);
|
|
226
|
+
return r.reverse(), function next() {
|
|
227
|
+
for (; r.length;) {
|
|
228
|
+
var t = r.pop();
|
|
229
|
+
if (t in e) return next.value = t, next.done = !1, next;
|
|
230
|
+
}
|
|
231
|
+
return next.done = !0, next;
|
|
232
|
+
};
|
|
233
|
+
}, e.values = values, Context.prototype = {
|
|
234
|
+
constructor: Context,
|
|
235
|
+
reset: function (e) {
|
|
236
|
+
if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
|
|
237
|
+
},
|
|
238
|
+
stop: function () {
|
|
239
|
+
this.done = !0;
|
|
240
|
+
var t = this.tryEntries[0].completion;
|
|
241
|
+
if ("throw" === t.type) throw t.arg;
|
|
242
|
+
return this.rval;
|
|
243
|
+
},
|
|
244
|
+
dispatchException: function (e) {
|
|
245
|
+
if (this.done) throw e;
|
|
246
|
+
var r = this;
|
|
247
|
+
function handle(n, o) {
|
|
248
|
+
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
|
|
249
|
+
}
|
|
250
|
+
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
|
|
251
|
+
var i = this.tryEntries[o],
|
|
252
|
+
a = i.completion;
|
|
253
|
+
if ("root" === i.tryLoc) return handle("end");
|
|
254
|
+
if (i.tryLoc <= this.prev) {
|
|
255
|
+
var c = n.call(i, "catchLoc"),
|
|
256
|
+
u = n.call(i, "finallyLoc");
|
|
257
|
+
if (c && u) {
|
|
258
|
+
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
259
|
+
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
260
|
+
} else if (c) {
|
|
261
|
+
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
262
|
+
} else {
|
|
263
|
+
if (!u) throw new Error("try statement without catch or finally");
|
|
264
|
+
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
abrupt: function (t, e) {
|
|
270
|
+
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
|
|
271
|
+
var o = this.tryEntries[r];
|
|
272
|
+
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
|
|
273
|
+
var i = o;
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
|
|
278
|
+
var a = i ? i.completion : {};
|
|
279
|
+
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
|
|
280
|
+
},
|
|
281
|
+
complete: function (t, e) {
|
|
282
|
+
if ("throw" === t.type) throw t.arg;
|
|
283
|
+
return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
|
|
284
|
+
},
|
|
285
|
+
finish: function (t) {
|
|
286
|
+
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
287
|
+
var r = this.tryEntries[e];
|
|
288
|
+
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
catch: function (t) {
|
|
292
|
+
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
293
|
+
var r = this.tryEntries[e];
|
|
294
|
+
if (r.tryLoc === t) {
|
|
295
|
+
var n = r.completion;
|
|
296
|
+
if ("throw" === n.type) {
|
|
297
|
+
var o = n.arg;
|
|
298
|
+
resetTryEntry(r);
|
|
299
|
+
}
|
|
300
|
+
return o;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
throw new Error("illegal catch attempt");
|
|
304
|
+
},
|
|
305
|
+
delegateYield: function (e, r, n) {
|
|
306
|
+
return this.delegate = {
|
|
307
|
+
iterator: values(e),
|
|
308
|
+
resultName: r,
|
|
309
|
+
nextLoc: n
|
|
310
|
+
}, "next" === this.method && (this.arg = t), y;
|
|
311
|
+
}
|
|
312
|
+
}, e;
|
|
313
|
+
}
|
|
314
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
315
|
+
try {
|
|
316
|
+
var info = gen[key](arg);
|
|
317
|
+
var value = info.value;
|
|
318
|
+
} catch (error) {
|
|
319
|
+
reject(error);
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
if (info.done) {
|
|
323
|
+
resolve(value);
|
|
324
|
+
} else {
|
|
325
|
+
Promise.resolve(value).then(_next, _throw);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
function _asyncToGenerator(fn) {
|
|
329
|
+
return function () {
|
|
330
|
+
var self = this,
|
|
331
|
+
args = arguments;
|
|
332
|
+
return new Promise(function (resolve, reject) {
|
|
333
|
+
var gen = fn.apply(self, args);
|
|
334
|
+
function _next(value) {
|
|
335
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
336
|
+
}
|
|
337
|
+
function _throw(err) {
|
|
338
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
339
|
+
}
|
|
340
|
+
_next(undefined);
|
|
341
|
+
});
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
function _extends() {
|
|
345
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
346
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
347
|
+
var source = arguments[i];
|
|
348
|
+
for (var key in source) {
|
|
349
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
350
|
+
target[key] = source[key];
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
return target;
|
|
355
|
+
};
|
|
356
|
+
return _extends.apply(this, arguments);
|
|
357
|
+
}
|
|
358
|
+
function _inheritsLoose(subClass, superClass) {
|
|
359
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
360
|
+
subClass.prototype.constructor = subClass;
|
|
361
|
+
_setPrototypeOf(subClass, superClass);
|
|
362
|
+
}
|
|
363
|
+
function _getPrototypeOf(o) {
|
|
364
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
|
|
365
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
366
|
+
};
|
|
367
|
+
return _getPrototypeOf(o);
|
|
368
|
+
}
|
|
369
|
+
function _setPrototypeOf(o, p) {
|
|
370
|
+
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
371
|
+
o.__proto__ = p;
|
|
372
|
+
return o;
|
|
373
|
+
};
|
|
374
|
+
return _setPrototypeOf(o, p);
|
|
375
|
+
}
|
|
376
|
+
function _isNativeReflectConstruct() {
|
|
377
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
378
|
+
if (Reflect.construct.sham) return false;
|
|
379
|
+
if (typeof Proxy === "function") return true;
|
|
380
|
+
try {
|
|
381
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
382
|
+
return true;
|
|
383
|
+
} catch (e) {
|
|
384
|
+
return false;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
function _construct(Parent, args, Class) {
|
|
388
|
+
if (_isNativeReflectConstruct()) {
|
|
389
|
+
_construct = Reflect.construct.bind();
|
|
390
|
+
} else {
|
|
391
|
+
_construct = function _construct(Parent, args, Class) {
|
|
392
|
+
var a = [null];
|
|
393
|
+
a.push.apply(a, args);
|
|
394
|
+
var Constructor = Function.bind.apply(Parent, a);
|
|
395
|
+
var instance = new Constructor();
|
|
396
|
+
if (Class) _setPrototypeOf(instance, Class.prototype);
|
|
397
|
+
return instance;
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
return _construct.apply(null, arguments);
|
|
401
|
+
}
|
|
402
|
+
function _isNativeFunction(fn) {
|
|
403
|
+
try {
|
|
404
|
+
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
405
|
+
} catch (e) {
|
|
406
|
+
return typeof fn === "function";
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
function _wrapNativeSuper(Class) {
|
|
410
|
+
var _cache = typeof Map === "function" ? new Map() : undefined;
|
|
411
|
+
_wrapNativeSuper = function _wrapNativeSuper(Class) {
|
|
412
|
+
if (Class === null || !_isNativeFunction(Class)) return Class;
|
|
413
|
+
if (typeof Class !== "function") {
|
|
414
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
415
|
+
}
|
|
416
|
+
if (typeof _cache !== "undefined") {
|
|
417
|
+
if (_cache.has(Class)) return _cache.get(Class);
|
|
418
|
+
_cache.set(Class, Wrapper);
|
|
419
|
+
}
|
|
420
|
+
function Wrapper() {
|
|
421
|
+
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
|
|
422
|
+
}
|
|
423
|
+
Wrapper.prototype = Object.create(Class.prototype, {
|
|
424
|
+
constructor: {
|
|
425
|
+
value: Wrapper,
|
|
426
|
+
enumerable: false,
|
|
427
|
+
writable: true,
|
|
428
|
+
configurable: true
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
return _setPrototypeOf(Wrapper, Class);
|
|
432
|
+
};
|
|
433
|
+
return _wrapNativeSuper(Class);
|
|
434
|
+
}
|
|
435
|
+
function _assertThisInitialized(self) {
|
|
436
|
+
if (self === void 0) {
|
|
437
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
438
|
+
}
|
|
439
|
+
return self;
|
|
440
|
+
}
|
|
441
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
442
|
+
if (!o) return;
|
|
443
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
444
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
445
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
446
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
447
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
448
|
+
}
|
|
449
|
+
function _arrayLikeToArray(arr, len) {
|
|
450
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
451
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
452
|
+
return arr2;
|
|
453
|
+
}
|
|
454
|
+
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
455
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
456
|
+
if (it) return (it = it.call(o)).next.bind(it);
|
|
457
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
458
|
+
if (it) o = it;
|
|
459
|
+
var i = 0;
|
|
460
|
+
return function () {
|
|
461
|
+
if (i >= o.length) return {
|
|
462
|
+
done: true
|
|
463
|
+
};
|
|
464
|
+
return {
|
|
465
|
+
done: false,
|
|
466
|
+
value: o[i++]
|
|
467
|
+
};
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/** @ignore */
|
|
474
|
+
var debug = /*#__PURE__*/Debug('ds:api');
|
|
475
|
+
/** @ignore */
|
|
476
|
+
var transactionAsyncLocalStorage = /*#__PURE__*/new async_hooks.AsyncLocalStorage();
|
|
477
|
+
/** @ignore */
|
|
478
|
+
var metricHistogram = /*#__PURE__*/new promClient.Histogram({
|
|
479
|
+
name: 'dstore_requests_seconds',
|
|
480
|
+
help: 'How long did Datastore operations take?',
|
|
481
|
+
labelNames: ['operation']
|
|
482
|
+
});
|
|
483
|
+
var metricFailureCounter = /*#__PURE__*/new promClient.Counter({
|
|
484
|
+
name: 'dstore_failures_total',
|
|
485
|
+
help: 'How many Datastore operations failed?',
|
|
486
|
+
labelNames: ['operation']
|
|
487
|
+
});
|
|
488
|
+
/** Use instead of Datastore.KEY
|
|
489
|
+
*
|
|
490
|
+
* Even better: use `_key` instead.
|
|
491
|
+
*/
|
|
492
|
+
var KEYSYM = datastore.Datastore.KEY;
|
|
493
|
+
/** Dstore implements a slightly more accessible version of the [Google Cloud Datastore: Node.js Client](https://cloud.google.com/nodejs/docs/reference/datastore/latest)
|
|
494
|
+
|
|
495
|
+
[@google-cloud/datastore](https://github.com/googleapis/nodejs-datastore#readme) is a strange beast: [The documentation is auto generated](https://cloud.google.com/nodejs/docs/reference/datastore/latest) and completely shy of documenting any advanced concepts.
|
|
496
|
+
(Example: If you ask the datastore to auto-generate keys during save: how do you retrieve the generated key?) Generally I suggest to look at the Python 2.x [db](https://cloud.google.com/appengine/docs/standard/python/datastore/api-overview) and [ndb](https://cloud.google.com/appengine/docs/standard/python/ndb) documentation to get a better explanation of the workings of the datastore.
|
|
497
|
+
|
|
498
|
+
Also the typings are strange. The Google provided type `Entities` can be the on disk representation, the same but including a key reference (`Datastore.KEY` - [[IDstoreEntry]]), a list of these or a structured object containing the on disk representation under the `data` property and a `key` property and maybe some configuration like `excludeFromIndexes` ([[DstoreSaveEntity]]) or a list of these.
|
|
499
|
+
|
|
500
|
+
KvStore tries to abstract away most surprises the datastore provides to you but als tries to stay as API compatible as possible to [@google-cloud/datastore](https://github.com/googleapis/nodejs-datastore).
|
|
501
|
+
|
|
502
|
+
Main differences:
|
|
503
|
+
|
|
504
|
+
- Everything asynchronous is Promise-based - no callbacks.
|
|
505
|
+
- [[get]] always returns a single [[IDstoreEntry]].
|
|
506
|
+
- [[getMulti]] always returns an Array<[[IDstoreEntry]]> of the same length as the input Array. Items not found are represented by null.
|
|
507
|
+
- [[set]] is called with `(key, value)` and always returns the complete [[Key]] of the entity being written. Keys are normalized, numeric IDs are always encoded as strings.
|
|
508
|
+
- [[key]] handles [[Key]] object instantiation for you.
|
|
509
|
+
- [[readKey]] extracts the key from an [[IDstoreEntry]] you have read without the need of fancy `Symbol`-based access to `entity[Datastore.KEY]`. If needed, it tries to deserialize `_keyStr` to create `entity[Datastore.KEY]`. This ist important when rehydrating an [[IDstoreEntry]] from a serializing cache.
|
|
510
|
+
- [[allocateOneId]] returns a single numeric string encoded unique datastore id without the need of fancy unpacking.
|
|
511
|
+
- [[runInTransaction]] allows you to provide a function to be executed inside an transaction without the need of passing around the transaction object. This is modelled after Python 2.7 [ndb's `@ndb.transactional` feature](https://cloud.google.com/appengine/docs/standard/python/ndb/transactions). This is implemented via node's [AsyncLocalStorage](https://nodejs.org/docs/latest-v14.x/api/async_hooks.html).
|
|
512
|
+
- [[keySerialize]] is synchronous.
|
|
513
|
+
|
|
514
|
+
This documentation also tries to document the little known idiosyncrasies of the [@google-cloud/datastore](https://github.com/googleapis/nodejs-datastore) library. See the corresponding functions.
|
|
515
|
+
*/
|
|
516
|
+
var Dstore = /*#__PURE__*/function () {
|
|
517
|
+
/** Generate a Dstore instance for a specific [[Datastore]] instance.
|
|
518
|
+
```
|
|
519
|
+
const dstore = Dstore(new Datastore())
|
|
520
|
+
```
|
|
521
|
+
You are encouraged to provide the second parameter to provide the ProjectID. This makes [[keySerialize]] more robust. Usually you can get this from the Environment:
|
|
522
|
+
```
|
|
523
|
+
const dstore = Dstore(new Datastore(), process.env.GCLOUD_PROJECT)
|
|
524
|
+
@param datastore A [[Datastore]] instance. Can be freely accessed by the client. Be aware that using this inside [[runInTransaction]] ignores the transaction.
|
|
525
|
+
@param projectId The `GCLOUD_PROJECT ID`. Used for Key generation during serialization.
|
|
526
|
+
```
|
|
527
|
+
*/
|
|
528
|
+
function Dstore(datastore, projectId, logger) {
|
|
529
|
+
this.datastore = void 0;
|
|
530
|
+
this.projectId = void 0;
|
|
531
|
+
this.logger = void 0;
|
|
532
|
+
this.engine = 'Dstore';
|
|
533
|
+
this.engines = [];
|
|
534
|
+
this.urlSaveKey = new entity.entity.URLSafeKey();
|
|
535
|
+
this.datastore = datastore;
|
|
536
|
+
this.projectId = projectId;
|
|
537
|
+
this.logger = logger;
|
|
538
|
+
assertateDebug.assertIsObject(datastore);
|
|
539
|
+
this.engines.push(this.engine);
|
|
540
|
+
}
|
|
541
|
+
/** Gets the Datastore or the current Transaction. */
|
|
542
|
+
var _proto = Dstore.prototype;
|
|
543
|
+
_proto.getDoT = function getDoT() {
|
|
544
|
+
return transactionAsyncLocalStorage.getStore() || this.datastore;
|
|
545
|
+
}
|
|
546
|
+
/** `key()` creates a [[Key]] Object from a path.
|
|
547
|
+
*
|
|
548
|
+
* Compatible to [Datastore.key](https://cloud.google.com/nodejs/docs/reference/datastore/latest/datastore/datastore#_google_cloud_datastore_Datastore_key_member_1_)
|
|
549
|
+
*
|
|
550
|
+
* If the Path has an odd number of elements, it is considered an incomplete Key. This can only be used for saving and will prompt the Datastore to auto-generate an (random) ID. See also [[save]].
|
|
551
|
+
*
|
|
552
|
+
* @category Datastore Drop-In
|
|
553
|
+
*/;
|
|
554
|
+
_proto.key = function key(path) {
|
|
555
|
+
return this.datastore.key(path);
|
|
556
|
+
}
|
|
557
|
+
/** `keyFromSerialized()` serializes [[Key]] to a string.
|
|
558
|
+
*
|
|
559
|
+
* Compatible to [keyToLegacyUrlSafe](https://cloud.google.com/nodejs/docs/reference/datastore/latest/datastore/datastore#_google_cloud_datastore_Datastore_keyToLegacyUrlSafe_member_1_), but does not support the "locationPrefix" since the use for this parameter is undocumented and unknown. It seems to be an artifact from early App Engine days.
|
|
560
|
+
*
|
|
561
|
+
* It can be a synchronous function because it does not look up the `projectId`. Instead it is assumed, that you give the `projectId` upon instantiation of [[Dstore]]. It also seems, that a wrong `projectId` bears no ill effects.
|
|
562
|
+
*
|
|
563
|
+
* @category Datastore Drop-In
|
|
564
|
+
*/;
|
|
565
|
+
_proto.keySerialize = function keySerialize(key) {
|
|
566
|
+
var _this$projectId;
|
|
567
|
+
return key ? this.urlSaveKey.legacyEncode((_this$projectId = this.projectId) != null ? _this$projectId : '', key) : '';
|
|
568
|
+
}
|
|
569
|
+
/** `keyFromSerialized()` deserializes a string created with [[keySerialize]] to a [[Key]].
|
|
570
|
+
*
|
|
571
|
+
* Compatible to [keyFromLegacyUrlsafe](https://cloud.google.com/nodejs/docs/reference/datastore/latest/datastore/datastore#_google_cloud_datastore_Datastore_keyFromLegacyUrlsafe_member_1_).
|
|
572
|
+
*
|
|
573
|
+
* @category Datastore Drop-In
|
|
574
|
+
*/;
|
|
575
|
+
_proto.keyFromSerialized = function keyFromSerialized(text) {
|
|
576
|
+
return this.urlSaveKey.legacyDecode(text);
|
|
577
|
+
}
|
|
578
|
+
/** `readKey()` extracts the [[Key]] from an [[IDstoreEntry]].
|
|
579
|
+
*
|
|
580
|
+
* Is is an alternative to `entity[Datastore.KEY]` which tends to fail in various contexts and also confuses older Typescript compilers.
|
|
581
|
+
* It can extract the [[Key]] form a [[IDstoreEntry]] which has been serialized to JSON by leveraging the property `_keyStr`.
|
|
582
|
+
*
|
|
583
|
+
* @category Additional
|
|
584
|
+
*/;
|
|
585
|
+
_proto.readKey = function readKey(ent) {
|
|
586
|
+
assertateDebug.assertIsObject(ent);
|
|
587
|
+
var ret = ent[datastore.Datastore.KEY];
|
|
588
|
+
if (ent._keyStr && !ret) {
|
|
589
|
+
ret = this.keyFromSerialized(ent._keyStr);
|
|
590
|
+
}
|
|
591
|
+
assertateDebug.assertIsObject(ret, 'entity[Datastore.KEY]/entity._keyStr', "Entity is missing the datastore Key: " + JSON.stringify(ent));
|
|
592
|
+
return ret;
|
|
593
|
+
}
|
|
594
|
+
/** `fixKeys()` is called for all [[IDstoreEntry]]sa returned from [[Dstore]].
|
|
595
|
+
*
|
|
596
|
+
* Is ensures that besides `entity[Datastore.KEY]` there is `_keyStr` to be leveraged by [[readKey]].
|
|
597
|
+
*
|
|
598
|
+
* @internal
|
|
599
|
+
*/;
|
|
600
|
+
_proto.fixKeys = function fixKeys(entities) {
|
|
601
|
+
var _this = this;
|
|
602
|
+
entities.forEach(function (x) {
|
|
603
|
+
if (!!(x != null && x[datastore.Datastore.KEY]) && x[datastore.Datastore.KEY]) {
|
|
604
|
+
assertateDebug.assertIsDefined(x[datastore.Datastore.KEY]);
|
|
605
|
+
assertateDebug.assertIsObject(x[datastore.Datastore.KEY]);
|
|
606
|
+
// Old TypesScript has problems with symbols as a property
|
|
607
|
+
x._keyStr = _this.keySerialize(x[datastore.Datastore.KEY]);
|
|
608
|
+
}
|
|
609
|
+
});
|
|
610
|
+
return entities;
|
|
611
|
+
}
|
|
612
|
+
/** `get()` reads a [[IDstoreEntry]] from the Datastore.
|
|
613
|
+
*
|
|
614
|
+
* It returns [[IDstoreEntry]] or `null` if not found.
|
|
615
|
+
* The underlying Datastore API Call is [lookup](https://cloud.google.com/datastore/docs/reference/data/rest/v1/projects/lookup).
|
|
616
|
+
*
|
|
617
|
+
* It is in the Spirit of [Datastore.get()]. Unfortunately currently (late 2021) there is no formal documentation from Google on [Datastore.get()].
|
|
618
|
+
*
|
|
619
|
+
* Differences between [[Dstore.get]] and [[Datastore.get]]:
|
|
620
|
+
*
|
|
621
|
+
* - [Dstore.get]] takes a single [[Key]] as Parameter, no Array. Check [[getMulti]] if you want Arrays.
|
|
622
|
+
* - [Dstore.get]] returns a single [[IDstoreEntry]], no Array.
|
|
623
|
+
*
|
|
624
|
+
* @category Datastore Drop-In
|
|
625
|
+
*/;
|
|
626
|
+
_proto.get =
|
|
627
|
+
/*#__PURE__*/
|
|
628
|
+
function () {
|
|
629
|
+
var _get = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(key) {
|
|
630
|
+
var result;
|
|
631
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
632
|
+
while (1) switch (_context.prev = _context.next) {
|
|
633
|
+
case 0:
|
|
634
|
+
assertateDebug.assertIsObject(key);
|
|
635
|
+
assertateDebug.assert(!Array.isArray(key));
|
|
636
|
+
assertateDebug.assert(key.path.length % 2 == 0, "key.path must be complete: " + JSON.stringify(key.path));
|
|
637
|
+
_context.next = 5;
|
|
638
|
+
return this.getMulti([key]);
|
|
639
|
+
case 5:
|
|
640
|
+
result = _context.sent;
|
|
641
|
+
return _context.abrupt("return", (result == null ? void 0 : result[0]) || null);
|
|
642
|
+
case 7:
|
|
643
|
+
case "end":
|
|
644
|
+
return _context.stop();
|
|
645
|
+
}
|
|
646
|
+
}, _callee, this);
|
|
647
|
+
}));
|
|
648
|
+
function get(_x) {
|
|
649
|
+
return _get.apply(this, arguments);
|
|
650
|
+
}
|
|
651
|
+
return get;
|
|
652
|
+
}()
|
|
653
|
+
/** `getMulti()` reads several [[IDstoreEntry]]s from the Datastore.
|
|
654
|
+
*
|
|
655
|
+
* It returns a list of [[IDstoreEntry]]s or `undefined` if not found. Entries are in the same Order as the keys in the Parameter.
|
|
656
|
+
* This is different from the @google-cloud/datastore where not found items are not present in the result and the order in the result list is undefined.
|
|
657
|
+
*
|
|
658
|
+
* The underlying Datastore API Call is [lookup](https://cloud.google.com/datastore/docs/reference/data/rest/v1/projects/lookup).
|
|
659
|
+
*
|
|
660
|
+
* It is in the Spirit of [Datastore.get()]. Unfortunately currently (late 2021) there is no formal documentation from Google on [Datastore.get()].
|
|
661
|
+
*
|
|
662
|
+
* Differences between [[Dstore.getMulti]] and [[Datastore.get]]:
|
|
663
|
+
*
|
|
664
|
+
* - [[Dstore.getMulti]] always takes an Array of [[Key]]s as Parameter.
|
|
665
|
+
* - [[Dstore.getMulti]] returns always a Array of [[IDstoreEntry]], or null.
|
|
666
|
+
* - [[Datastore.get]] has many edge cases - e.g. when not being able to find any of the provided keys - which return surprising results. [[Dstore.getMulti]] always returns an Array. TODO: return a Array with the same length as the Input.
|
|
667
|
+
*
|
|
668
|
+
* @category Datastore Drop-In
|
|
669
|
+
*/
|
|
670
|
+
;
|
|
671
|
+
_proto.getMulti =
|
|
672
|
+
/*#__PURE__*/
|
|
673
|
+
function () {
|
|
674
|
+
var _getMulti = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(keys) {
|
|
675
|
+
var results, metricEnd, _yield$this$getDoT$ge, entities, entitiesByKey;
|
|
676
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
677
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
678
|
+
case 0:
|
|
679
|
+
// assertIsArray(keys);
|
|
680
|
+
metricEnd = metricHistogram.startTimer();
|
|
681
|
+
_context2.prev = 1;
|
|
682
|
+
_context2.t0 = this;
|
|
683
|
+
if (!(keys.length > 0)) {
|
|
684
|
+
_context2.next = 15;
|
|
685
|
+
break;
|
|
686
|
+
}
|
|
687
|
+
_context2.next = 6;
|
|
688
|
+
return this.getDoT().get(keys);
|
|
689
|
+
case 6:
|
|
690
|
+
_context2.t2 = _yield$this$getDoT$ge = _context2.sent;
|
|
691
|
+
if (!(_context2.t2 == null)) {
|
|
692
|
+
_context2.next = 11;
|
|
693
|
+
break;
|
|
694
|
+
}
|
|
695
|
+
_context2.t3 = void 0;
|
|
696
|
+
_context2.next = 12;
|
|
697
|
+
break;
|
|
698
|
+
case 11:
|
|
699
|
+
_context2.t3 = _yield$this$getDoT$ge[0];
|
|
700
|
+
case 12:
|
|
701
|
+
_context2.t1 = _context2.t3;
|
|
702
|
+
_context2.next = 16;
|
|
703
|
+
break;
|
|
704
|
+
case 15:
|
|
705
|
+
_context2.t1 = [];
|
|
706
|
+
case 16:
|
|
707
|
+
_context2.t4 = _context2.t1;
|
|
708
|
+
results = _context2.t0.fixKeys.call(_context2.t0, _context2.t4);
|
|
709
|
+
_context2.next = 26;
|
|
710
|
+
break;
|
|
711
|
+
case 20:
|
|
712
|
+
_context2.prev = 20;
|
|
713
|
+
_context2.t5 = _context2["catch"](1);
|
|
714
|
+
metricFailureCounter.inc({
|
|
715
|
+
operation: 'get'
|
|
716
|
+
});
|
|
717
|
+
_context2.next = 25;
|
|
718
|
+
return promises.setImmediate();
|
|
719
|
+
case 25:
|
|
720
|
+
throw new DstoreError('datastore.getMulti error', _context2.t5, {
|
|
721
|
+
keys: keys
|
|
722
|
+
});
|
|
723
|
+
case 26:
|
|
724
|
+
_context2.prev = 26;
|
|
725
|
+
metricEnd({
|
|
726
|
+
operation: 'get'
|
|
727
|
+
});
|
|
728
|
+
return _context2.finish(26);
|
|
729
|
+
case 29:
|
|
730
|
+
// Sort resulting entities by the keys they were requested with.
|
|
731
|
+
assertateDebug.assertIsArray(results);
|
|
732
|
+
entities = results;
|
|
733
|
+
entitiesByKey = {};
|
|
734
|
+
entities.forEach(function (entity) {
|
|
735
|
+
entitiesByKey[JSON.stringify(entity[datastore.Datastore.KEY])] = entity;
|
|
736
|
+
});
|
|
737
|
+
return _context2.abrupt("return", keys.map(function (key) {
|
|
738
|
+
return entitiesByKey[JSON.stringify(key)] || null;
|
|
739
|
+
}));
|
|
740
|
+
case 34:
|
|
741
|
+
case "end":
|
|
742
|
+
return _context2.stop();
|
|
743
|
+
}
|
|
744
|
+
}, _callee2, this, [[1, 20, 26, 29]]);
|
|
745
|
+
}));
|
|
746
|
+
function getMulti(_x2) {
|
|
747
|
+
return _getMulti.apply(this, arguments);
|
|
748
|
+
}
|
|
749
|
+
return getMulti;
|
|
750
|
+
}()
|
|
751
|
+
/** `set()` is addition to [[Datastore]]. It provides a classic Key-value Interface.
|
|
752
|
+
*
|
|
753
|
+
* Instead providing a nested [[DstoreSaveEntity]] to [[save]] you can call set directly as `set( key, value)`.
|
|
754
|
+
* Observe that set takes a [[Key]] as first parameter. you call it like this;
|
|
755
|
+
*
|
|
756
|
+
* ```js
|
|
757
|
+
* const ds = Dstore()
|
|
758
|
+
* ds.set(ds.key('kind', '123'), {props1: 'foo', prop2: 'bar'})
|
|
759
|
+
* ```
|
|
760
|
+
*
|
|
761
|
+
* It returns the [[Key]] of the Object being written.
|
|
762
|
+
* If the Key provided was an incomplete [[Key]] it will return a completed [[Key]].
|
|
763
|
+
* See [[save]] for more information on key generation.
|
|
764
|
+
*
|
|
765
|
+
* @category Additional
|
|
766
|
+
*/
|
|
767
|
+
;
|
|
768
|
+
_proto.set =
|
|
769
|
+
/*#__PURE__*/
|
|
770
|
+
function () {
|
|
771
|
+
var _set = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(key, data) {
|
|
772
|
+
var saveEntity;
|
|
773
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
774
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
775
|
+
case 0:
|
|
776
|
+
assertateDebug.assertIsObject(key);
|
|
777
|
+
assertateDebug.assertIsObject(data);
|
|
778
|
+
saveEntity = {
|
|
779
|
+
key: key,
|
|
780
|
+
data: data
|
|
781
|
+
};
|
|
782
|
+
_context3.next = 5;
|
|
783
|
+
return this.save([saveEntity]);
|
|
784
|
+
case 5:
|
|
785
|
+
return _context3.abrupt("return", saveEntity.key);
|
|
786
|
+
case 6:
|
|
787
|
+
case "end":
|
|
788
|
+
return _context3.stop();
|
|
789
|
+
}
|
|
790
|
+
}, _callee3, this);
|
|
791
|
+
}));
|
|
792
|
+
function set(_x3, _x4) {
|
|
793
|
+
return _set.apply(this, arguments);
|
|
794
|
+
}
|
|
795
|
+
return set;
|
|
796
|
+
}()
|
|
797
|
+
/** `save()` is compatible to [Datastore.save()](https://cloud.google.com/nodejs/docs/reference/datastore/latest/datastore/datastore#_google_cloud_datastore_Datastore_save_member_1_).
|
|
798
|
+
*
|
|
799
|
+
* The single Parameter is a list of [[DstoreSaveEntity]]s.
|
|
800
|
+
* If called within a transaction it returns `undefined`.
|
|
801
|
+
* If not, it returns a [[CommitResponse]] which is not documented by Google.
|
|
802
|
+
*
|
|
803
|
+
* Different [DstoreSaveEntity]]s in the `entities` parameter can have different values in their [[DstoreSaveEntity.method]] property.
|
|
804
|
+
* This allows you to do `insert`, `update` and `upsert` (the default) in a single request.
|
|
805
|
+
*
|
|
806
|
+
* `save()` seems to basically be an alias to [upsert](https://cloud.google.com/nodejs/docs/reference/datastore/latest/datastore/datastore#_google_cloud_datastore_Datastore_upsert_member_1_).
|
|
807
|
+
*
|
|
808
|
+
* If the [[Key]] provided in [[DstoreSaveEntity.key]] was an incomplete [[Key]] it will be updated by `save()` inside the [[DstoreSaveEntity]].
|
|
809
|
+
*
|
|
810
|
+
* If the Datastore generates a new ID because of an incomplete [[Key]] *on first save* it will return an large integer as [[Key.id]].
|
|
811
|
+
* On every subsequent `save()` an string encoded number representation is returned.
|
|
812
|
+
* @todo Dstore should normalizes that and always return an string encoded number representation.
|
|
813
|
+
*
|
|
814
|
+
* Each [[DstoreSaveEntity]] can have an `excludeFromIndexes` property which is somewhat underdocumented.
|
|
815
|
+
* It can use something like JSON-Path notation
|
|
816
|
+
* ([Source](https://github.com/googleapis/nodejs-datastore/blob/2941f2f0f132b41534e303d441d837051ce88fd7/src/index.ts#L948))
|
|
817
|
+
* [.*](https://github.com/googleapis/nodejs-datastore/blob/406b15d2014087172df617c6e0a397a2c0902c5f/test/index.ts#L1598),
|
|
818
|
+
* [parent[]](https://github.com/googleapis/nodejs-datastore/blob/406b15d2014087172df617c6e0a397a2c0902c5f/test/index.ts#L1672),
|
|
819
|
+
* [parent.*](https://github.com/googleapis/nodejs-datastore/blob/406b15d2014087172df617c6e0a397a2c0902c5f/test/index.ts#L1672),
|
|
820
|
+
* [parent[].*](https://github.com/googleapis/nodejs-datastore/blob/406b15d2014087172df617c6e0a397a2c0902c5f/test/index.ts#L1672)
|
|
821
|
+
* and [more complex patterns](https://github.com/googleapis/nodejs-datastore/blob/406b15d2014087172df617c6e0a397a2c0902c5f/test/index.ts#L1754)
|
|
822
|
+
* seem to be supported patterns.
|
|
823
|
+
*
|
|
824
|
+
* If the caller has not provided an `excludeLargeProperties` in a [[DstoreSaveEntity]] we will default it
|
|
825
|
+
* to `excludeLargeProperties: true`. Without this you can not store strings longer than 1500 bytes easily
|
|
826
|
+
* ([source](https://github.com/googleapis/nodejs-datastore/blob/c7a08a8382c6706ccbfbbf77950babf40bac757c/src/entity.ts#L961)).
|
|
827
|
+
*
|
|
828
|
+
* @category Datastore Drop-In
|
|
829
|
+
*/
|
|
830
|
+
;
|
|
831
|
+
_proto.save =
|
|
832
|
+
/*#__PURE__*/
|
|
833
|
+
function () {
|
|
834
|
+
var _save = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(entities) {
|
|
835
|
+
var ret, metricEnd, _iterator, _step, e, _iterator2, _step2, _e;
|
|
836
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
837
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
838
|
+
case 0:
|
|
839
|
+
assertateDebug.assertIsArray(entities);
|
|
840
|
+
metricEnd = metricHistogram.startTimer();
|
|
841
|
+
_context4.prev = 2;
|
|
842
|
+
// Within Transaction we don't get any answer here!
|
|
843
|
+
// [ { mutationResults: [ [Object], [Object] ], indexUpdates: 51 } ]
|
|
844
|
+
for (_iterator = _createForOfIteratorHelperLoose(entities); !(_step = _iterator()).done;) {
|
|
845
|
+
e = _step.value;
|
|
846
|
+
assertateDebug.assertIsObject(e.key);
|
|
847
|
+
assertateDebug.assertIsObject(e.data);
|
|
848
|
+
this.fixKeys([e.data]);
|
|
849
|
+
e.excludeLargeProperties = e.excludeLargeProperties === undefined ? true : e.excludeLargeProperties;
|
|
850
|
+
e.data = _extends({}, e.data, {
|
|
851
|
+
_keyStr: undefined
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
_context4.next = 6;
|
|
855
|
+
return this.getDoT().save(entities);
|
|
856
|
+
case 6:
|
|
857
|
+
_context4.t0 = _context4.sent;
|
|
858
|
+
if (_context4.t0) {
|
|
859
|
+
_context4.next = 9;
|
|
860
|
+
break;
|
|
861
|
+
}
|
|
862
|
+
_context4.t0 = undefined;
|
|
863
|
+
case 9:
|
|
864
|
+
ret = _context4.t0;
|
|
865
|
+
for (_iterator2 = _createForOfIteratorHelperLoose(entities); !(_step2 = _iterator2()).done;) {
|
|
866
|
+
_e = _step2.value;
|
|
867
|
+
_e.data[datastore.Datastore.KEY] = _e.key;
|
|
868
|
+
this.fixKeys([_e.data]);
|
|
869
|
+
}
|
|
870
|
+
_context4.next = 19;
|
|
871
|
+
break;
|
|
872
|
+
case 13:
|
|
873
|
+
_context4.prev = 13;
|
|
874
|
+
_context4.t1 = _context4["catch"](2);
|
|
875
|
+
metricFailureCounter.inc({
|
|
876
|
+
operation: 'save'
|
|
877
|
+
});
|
|
878
|
+
_context4.next = 18;
|
|
879
|
+
return promises.setImmediate();
|
|
880
|
+
case 18:
|
|
881
|
+
throw new DstoreError('datastore.save error', _context4.t1);
|
|
882
|
+
case 19:
|
|
883
|
+
_context4.prev = 19;
|
|
884
|
+
metricEnd({
|
|
885
|
+
operation: 'save'
|
|
886
|
+
});
|
|
887
|
+
return _context4.finish(19);
|
|
888
|
+
case 22:
|
|
889
|
+
return _context4.abrupt("return", ret);
|
|
890
|
+
case 23:
|
|
891
|
+
case "end":
|
|
892
|
+
return _context4.stop();
|
|
893
|
+
}
|
|
894
|
+
}, _callee4, this, [[2, 13, 19, 22]]);
|
|
895
|
+
}));
|
|
896
|
+
function save(_x5) {
|
|
897
|
+
return _save.apply(this, arguments);
|
|
898
|
+
}
|
|
899
|
+
return save;
|
|
900
|
+
}()
|
|
901
|
+
/** `insert()` is compatible to [Datastore.insert()](https://cloud.google.com/nodejs/docs/reference/datastore/latest/datastore/datastore#_google_cloud_datastore_Datastore_insert_member_1_).
|
|
902
|
+
*
|
|
903
|
+
* The single Parameter is a list of [[DstoreSaveEntity]]s.
|
|
904
|
+
* If called within a transaction it returns `undefined`.
|
|
905
|
+
* If not, it returns a [[CommitResponse]] which is not documented by Google.
|
|
906
|
+
*
|
|
907
|
+
* `insert()` seems to be like [[save]] where [[DstoreSaveEntity.method]] is set to `'insert'`. It throws an [[DstoreError]] if there is already a Entity with the same [[Key]] in the Datastore.
|
|
908
|
+
*
|
|
909
|
+
* For handling of incomplete [[Key]]s see [[save]].
|
|
910
|
+
*
|
|
911
|
+
* This function can be completely emulated by using [[save]] with `method: 'insert'` inside each [[DstoreSaveEntity]].
|
|
912
|
+
* Prefer using `save()` because it is much better tested.
|
|
913
|
+
*
|
|
914
|
+
* await ds.insert([{key: ds.key(['testKind', 123]), entity: {data:' 123'}}])
|
|
915
|
+
*
|
|
916
|
+
* @throws [[DstoreError]]
|
|
917
|
+
* @category Datastore Drop-In
|
|
918
|
+
*/
|
|
919
|
+
;
|
|
920
|
+
_proto.insert =
|
|
921
|
+
/*#__PURE__*/
|
|
922
|
+
function () {
|
|
923
|
+
var _insert = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(entities) {
|
|
924
|
+
var ret, metricEnd;
|
|
925
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
926
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
927
|
+
case 0:
|
|
928
|
+
assertateDebug.assertIsArray(entities);
|
|
929
|
+
metricEnd = metricHistogram.startTimer();
|
|
930
|
+
_context5.prev = 2;
|
|
931
|
+
_context5.next = 5;
|
|
932
|
+
return this.getDoT().insert(entities);
|
|
933
|
+
case 5:
|
|
934
|
+
_context5.t0 = _context5.sent;
|
|
935
|
+
if (_context5.t0) {
|
|
936
|
+
_context5.next = 8;
|
|
937
|
+
break;
|
|
938
|
+
}
|
|
939
|
+
_context5.t0 = undefined;
|
|
940
|
+
case 8:
|
|
941
|
+
ret = _context5.t0;
|
|
942
|
+
_context5.next = 17;
|
|
943
|
+
break;
|
|
944
|
+
case 11:
|
|
945
|
+
_context5.prev = 11;
|
|
946
|
+
_context5.t1 = _context5["catch"](2);
|
|
947
|
+
// console.error(error)
|
|
948
|
+
metricFailureCounter.inc({
|
|
949
|
+
operation: 'insert'
|
|
950
|
+
});
|
|
951
|
+
_context5.next = 16;
|
|
952
|
+
return promises.setImmediate();
|
|
953
|
+
case 16:
|
|
954
|
+
throw new DstoreError('datastore.insert error', _context5.t1);
|
|
955
|
+
case 17:
|
|
956
|
+
_context5.prev = 17;
|
|
957
|
+
metricEnd({
|
|
958
|
+
operation: 'insert'
|
|
959
|
+
});
|
|
960
|
+
return _context5.finish(17);
|
|
961
|
+
case 20:
|
|
962
|
+
return _context5.abrupt("return", ret);
|
|
963
|
+
case 21:
|
|
964
|
+
case "end":
|
|
965
|
+
return _context5.stop();
|
|
966
|
+
}
|
|
967
|
+
}, _callee5, this, [[2, 11, 17, 20]]);
|
|
968
|
+
}));
|
|
969
|
+
function insert(_x6) {
|
|
970
|
+
return _insert.apply(this, arguments);
|
|
971
|
+
}
|
|
972
|
+
return insert;
|
|
973
|
+
}()
|
|
974
|
+
/** `update()` is compatible to [Datastore.update()](https://cloud.google.com/nodejs/docs/reference/datastore/latest/datastore/datastore#_google_cloud_datastore_Datastore_update_member_1_).
|
|
975
|
+
* The single Parameter is a list of [[DstoreSaveEntity]]s.
|
|
976
|
+
* If called within a transaction it returns `undefined`.
|
|
977
|
+
* If not, it returns a [[CommitResponse]] which is not documented by Google.
|
|
978
|
+
*
|
|
979
|
+
* `update()` seems to be like [[save]] where [[DstoreSaveEntity.method]] is set to `'update'`.
|
|
980
|
+
* It throws an [[DstoreError]] if there is no Entity with the same [[Key]] in the Datastore. `update()` *overwrites all existing data* for that [[Key]].
|
|
981
|
+
* There was an alpha functionality called `merge()` in the Datastore which read an Entity, merged it with the new data and wrote it back, but this was never documented.
|
|
982
|
+
*
|
|
983
|
+
* `update()` is idempotent. Updating the same [[Key]] twice is no error.
|
|
984
|
+
*
|
|
985
|
+
* This function can be completely emulated by using [[save]] with `method: 'update'` inside each [[DstoreSaveEntity]].
|
|
986
|
+
* Prefer using `save()` because it is much better tested.
|
|
987
|
+
*
|
|
988
|
+
* @throws [[DstoreError]]
|
|
989
|
+
* @category Datastore Drop-In
|
|
990
|
+
*/
|
|
991
|
+
;
|
|
992
|
+
_proto.update =
|
|
993
|
+
/*#__PURE__*/
|
|
994
|
+
function () {
|
|
995
|
+
var _update = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(entities) {
|
|
996
|
+
var ret, metricEnd;
|
|
997
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
998
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
999
|
+
case 0:
|
|
1000
|
+
assertateDebug.assertIsArray(entities);
|
|
1001
|
+
entities.forEach(function (entity) {
|
|
1002
|
+
return assertateDebug.assertIsObject(entity.key);
|
|
1003
|
+
});
|
|
1004
|
+
entities.forEach(function (entity) {
|
|
1005
|
+
return assertateDebug.assert(entity.key.path.length % 2 == 0, "entity.key.path must be complete: " + JSON.stringify([entity.key.path, entity]));
|
|
1006
|
+
});
|
|
1007
|
+
metricEnd = metricHistogram.startTimer();
|
|
1008
|
+
_context6.prev = 4;
|
|
1009
|
+
_context6.next = 7;
|
|
1010
|
+
return this.getDoT().update(entities);
|
|
1011
|
+
case 7:
|
|
1012
|
+
_context6.t0 = _context6.sent;
|
|
1013
|
+
if (_context6.t0) {
|
|
1014
|
+
_context6.next = 10;
|
|
1015
|
+
break;
|
|
1016
|
+
}
|
|
1017
|
+
_context6.t0 = undefined;
|
|
1018
|
+
case 10:
|
|
1019
|
+
ret = _context6.t0;
|
|
1020
|
+
_context6.next = 19;
|
|
1021
|
+
break;
|
|
1022
|
+
case 13:
|
|
1023
|
+
_context6.prev = 13;
|
|
1024
|
+
_context6.t1 = _context6["catch"](4);
|
|
1025
|
+
// console.error(error)
|
|
1026
|
+
metricFailureCounter.inc({
|
|
1027
|
+
operation: 'update'
|
|
1028
|
+
});
|
|
1029
|
+
_context6.next = 18;
|
|
1030
|
+
return promises.setImmediate();
|
|
1031
|
+
case 18:
|
|
1032
|
+
throw new DstoreError('datastore.update error', _context6.t1);
|
|
1033
|
+
case 19:
|
|
1034
|
+
_context6.prev = 19;
|
|
1035
|
+
metricEnd({
|
|
1036
|
+
operation: 'update'
|
|
1037
|
+
});
|
|
1038
|
+
return _context6.finish(19);
|
|
1039
|
+
case 22:
|
|
1040
|
+
return _context6.abrupt("return", ret);
|
|
1041
|
+
case 23:
|
|
1042
|
+
case "end":
|
|
1043
|
+
return _context6.stop();
|
|
1044
|
+
}
|
|
1045
|
+
}, _callee6, this, [[4, 13, 19, 22]]);
|
|
1046
|
+
}));
|
|
1047
|
+
function update(_x7) {
|
|
1048
|
+
return _update.apply(this, arguments);
|
|
1049
|
+
}
|
|
1050
|
+
return update;
|
|
1051
|
+
}()
|
|
1052
|
+
/** `delete()` is compatible to [Datastore.delete()].
|
|
1053
|
+
*
|
|
1054
|
+
* Unfortunately currently (late 2021) there is no formal documentation from Google on [Datastore.delete()].
|
|
1055
|
+
*
|
|
1056
|
+
* The single Parameter is a list of [[Key]]s.
|
|
1057
|
+
* If called within a transaction it returns `undefined`.
|
|
1058
|
+
* If not, it returns a [[CommitResponse]] which is not documented by Google.
|
|
1059
|
+
*
|
|
1060
|
+
* `delete()` is idempotent. Deleting the same [[Key]] twice is no error.
|
|
1061
|
+
*
|
|
1062
|
+
* @throws [[DstoreError]]
|
|
1063
|
+
* @category Datastore Drop-In
|
|
1064
|
+
*/
|
|
1065
|
+
;
|
|
1066
|
+
_proto["delete"] =
|
|
1067
|
+
/*#__PURE__*/
|
|
1068
|
+
function () {
|
|
1069
|
+
var _delete2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(keys) {
|
|
1070
|
+
var ret, metricEnd;
|
|
1071
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
1072
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
1073
|
+
case 0:
|
|
1074
|
+
assertateDebug.assertIsArray(keys);
|
|
1075
|
+
keys.forEach(function (key) {
|
|
1076
|
+
return assertateDebug.assertIsObject(key);
|
|
1077
|
+
});
|
|
1078
|
+
keys.forEach(function (key) {
|
|
1079
|
+
return assertateDebug.assert(key.path.length % 2 == 0, "key.path must be complete: " + JSON.stringify(key.path));
|
|
1080
|
+
});
|
|
1081
|
+
metricEnd = metricHistogram.startTimer();
|
|
1082
|
+
_context7.prev = 4;
|
|
1083
|
+
_context7.next = 7;
|
|
1084
|
+
return this.getDoT()["delete"](keys);
|
|
1085
|
+
case 7:
|
|
1086
|
+
_context7.t0 = _context7.sent;
|
|
1087
|
+
if (_context7.t0) {
|
|
1088
|
+
_context7.next = 10;
|
|
1089
|
+
break;
|
|
1090
|
+
}
|
|
1091
|
+
_context7.t0 = undefined;
|
|
1092
|
+
case 10:
|
|
1093
|
+
ret = _context7.t0;
|
|
1094
|
+
_context7.next = 19;
|
|
1095
|
+
break;
|
|
1096
|
+
case 13:
|
|
1097
|
+
_context7.prev = 13;
|
|
1098
|
+
_context7.t1 = _context7["catch"](4);
|
|
1099
|
+
metricFailureCounter.inc({
|
|
1100
|
+
operation: 'delete'
|
|
1101
|
+
});
|
|
1102
|
+
_context7.next = 18;
|
|
1103
|
+
return promises.setImmediate();
|
|
1104
|
+
case 18:
|
|
1105
|
+
throw new DstoreError('datastore.delete error', _context7.t1);
|
|
1106
|
+
case 19:
|
|
1107
|
+
_context7.prev = 19;
|
|
1108
|
+
metricEnd({
|
|
1109
|
+
operation: 'delete'
|
|
1110
|
+
});
|
|
1111
|
+
return _context7.finish(19);
|
|
1112
|
+
case 22:
|
|
1113
|
+
return _context7.abrupt("return", ret);
|
|
1114
|
+
case 23:
|
|
1115
|
+
case "end":
|
|
1116
|
+
return _context7.stop();
|
|
1117
|
+
}
|
|
1118
|
+
}, _callee7, this, [[4, 13, 19, 22]]);
|
|
1119
|
+
}));
|
|
1120
|
+
function _delete(_x8) {
|
|
1121
|
+
return _delete2.apply(this, arguments);
|
|
1122
|
+
}
|
|
1123
|
+
return _delete;
|
|
1124
|
+
}()
|
|
1125
|
+
/** `createQuery()` creates an "empty" [[Query]] Object.
|
|
1126
|
+
*
|
|
1127
|
+
* Compatible to [createQuery](https://cloud.google.com/nodejs/docs/reference/datastore/latest/datastore/datastore#_google_cloud_datastore_Datastore_createQuery_member_1_) in the datastore.
|
|
1128
|
+
*
|
|
1129
|
+
* @param kindName Name of the [[Datastore]][Kind](https://cloud.google.com/datastore/docs/concepts/entities#kinds_and_identifiers) ("Table") which should be searched.
|
|
1130
|
+
*
|
|
1131
|
+
* @category Datastore Drop-In
|
|
1132
|
+
*/
|
|
1133
|
+
;
|
|
1134
|
+
_proto.createQuery = function createQuery(kindName) {
|
|
1135
|
+
try {
|
|
1136
|
+
return this.getDoT().createQuery(kindName);
|
|
1137
|
+
} catch (error) {
|
|
1138
|
+
throw new DstoreError('datastore.createQuery error', error);
|
|
1139
|
+
}
|
|
1140
|
+
};
|
|
1141
|
+
_proto.runQuery = /*#__PURE__*/function () {
|
|
1142
|
+
var _runQuery = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(query) {
|
|
1143
|
+
var ret, metricEnd, _yield$this$getDoT$ru, entities, info;
|
|
1144
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
1145
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
1146
|
+
case 0:
|
|
1147
|
+
metricEnd = metricHistogram.startTimer();
|
|
1148
|
+
_context8.prev = 1;
|
|
1149
|
+
_context8.next = 4;
|
|
1150
|
+
return this.getDoT().runQuery(query);
|
|
1151
|
+
case 4:
|
|
1152
|
+
_yield$this$getDoT$ru = _context8.sent;
|
|
1153
|
+
entities = _yield$this$getDoT$ru[0];
|
|
1154
|
+
info = _yield$this$getDoT$ru[1];
|
|
1155
|
+
ret = [this.fixKeys(entities), info];
|
|
1156
|
+
_context8.next = 15;
|
|
1157
|
+
break;
|
|
1158
|
+
case 10:
|
|
1159
|
+
_context8.prev = 10;
|
|
1160
|
+
_context8.t0 = _context8["catch"](1);
|
|
1161
|
+
_context8.next = 14;
|
|
1162
|
+
return promises.setImmediate();
|
|
1163
|
+
case 14:
|
|
1164
|
+
throw new DstoreError('datastore.runQuery error', _context8.t0);
|
|
1165
|
+
case 15:
|
|
1166
|
+
_context8.prev = 15;
|
|
1167
|
+
metricEnd({
|
|
1168
|
+
operation: 'query'
|
|
1169
|
+
});
|
|
1170
|
+
return _context8.finish(15);
|
|
1171
|
+
case 18:
|
|
1172
|
+
return _context8.abrupt("return", ret);
|
|
1173
|
+
case 19:
|
|
1174
|
+
case "end":
|
|
1175
|
+
return _context8.stop();
|
|
1176
|
+
}
|
|
1177
|
+
}, _callee8, this, [[1, 10, 15, 18]]);
|
|
1178
|
+
}));
|
|
1179
|
+
function runQuery(_x9) {
|
|
1180
|
+
return _runQuery.apply(this, arguments);
|
|
1181
|
+
}
|
|
1182
|
+
return runQuery;
|
|
1183
|
+
}()
|
|
1184
|
+
/** `query()` combined [[createQuery]] and [[runQuery]] in a single call.
|
|
1185
|
+
*
|
|
1186
|
+
*
|
|
1187
|
+
* @param kindName Name of the [[Datastore]][Kind](https://cloud.google.com/datastore/docs/concepts/entities#kinds_and_identifiers) ("Table") which should be searched.
|
|
1188
|
+
* @param filters List of [[Query]] filter() calls.
|
|
1189
|
+
* @param limit Maximum Number of Results to return.
|
|
1190
|
+
* @param ordering List of [[Query]] order() calls.
|
|
1191
|
+
* @param selection selectionList of [[Query]] select() calls.
|
|
1192
|
+
* @param cursor unsupported so far.
|
|
1193
|
+
*
|
|
1194
|
+
* @category Datastore Drop-In
|
|
1195
|
+
*/
|
|
1196
|
+
;
|
|
1197
|
+
_proto.query =
|
|
1198
|
+
/*#__PURE__*/
|
|
1199
|
+
function () {
|
|
1200
|
+
var _query = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(kindName, filters, limit, ordering, selection, cursor) {
|
|
1201
|
+
var q, _iterator3, _step3, filterSpec, _iterator4, _step4, orderField;
|
|
1202
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
1203
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
1204
|
+
case 0:
|
|
1205
|
+
if (filters === void 0) {
|
|
1206
|
+
filters = [];
|
|
1207
|
+
}
|
|
1208
|
+
if (limit === void 0) {
|
|
1209
|
+
limit = 2500;
|
|
1210
|
+
}
|
|
1211
|
+
if (ordering === void 0) {
|
|
1212
|
+
ordering = [];
|
|
1213
|
+
}
|
|
1214
|
+
if (selection === void 0) {
|
|
1215
|
+
selection = [];
|
|
1216
|
+
}
|
|
1217
|
+
assertateDebug.assertIsString(kindName);
|
|
1218
|
+
assertateDebug.assertIsArray(filters);
|
|
1219
|
+
assertateDebug.assertIsNumber(limit);
|
|
1220
|
+
_context9.prev = 7;
|
|
1221
|
+
q = this.createQuery(kindName);
|
|
1222
|
+
for (_iterator3 = _createForOfIteratorHelperLoose(filters); !(_step3 = _iterator3()).done;) {
|
|
1223
|
+
filterSpec = _step3.value;
|
|
1224
|
+
assertateDebug.assertIsObject(filterSpec);
|
|
1225
|
+
// @ts-ignore
|
|
1226
|
+
q.filter(_construct(datastore.PropertyFilter, filterSpec));
|
|
1227
|
+
}
|
|
1228
|
+
for (_iterator4 = _createForOfIteratorHelperLoose(ordering); !(_step4 = _iterator4()).done;) {
|
|
1229
|
+
orderField = _step4.value;
|
|
1230
|
+
q.order(orderField);
|
|
1231
|
+
}
|
|
1232
|
+
if (limit > 0) {
|
|
1233
|
+
q.limit(limit);
|
|
1234
|
+
}
|
|
1235
|
+
if (selection.length > 0) {
|
|
1236
|
+
q.select(selection);
|
|
1237
|
+
}
|
|
1238
|
+
_context9.next = 15;
|
|
1239
|
+
return this.runQuery(q);
|
|
1240
|
+
case 15:
|
|
1241
|
+
return _context9.abrupt("return", _context9.sent);
|
|
1242
|
+
case 18:
|
|
1243
|
+
_context9.prev = 18;
|
|
1244
|
+
_context9.t0 = _context9["catch"](7);
|
|
1245
|
+
_context9.next = 22;
|
|
1246
|
+
return promises.setImmediate();
|
|
1247
|
+
case 22:
|
|
1248
|
+
throw new DstoreError('datastore.query error', _context9.t0, {
|
|
1249
|
+
kindName: kindName,
|
|
1250
|
+
filters: filters,
|
|
1251
|
+
limit: limit,
|
|
1252
|
+
ordering: ordering
|
|
1253
|
+
});
|
|
1254
|
+
case 23:
|
|
1255
|
+
case "end":
|
|
1256
|
+
return _context9.stop();
|
|
1257
|
+
}
|
|
1258
|
+
}, _callee9, this, [[7, 18]]);
|
|
1259
|
+
}));
|
|
1260
|
+
function query(_x10, _x11, _x12, _x13, _x14, _x15) {
|
|
1261
|
+
return _query.apply(this, arguments);
|
|
1262
|
+
}
|
|
1263
|
+
return query;
|
|
1264
|
+
}()
|
|
1265
|
+
/** Allocate one ID in the Datastore.
|
|
1266
|
+
*
|
|
1267
|
+
* Currently (late 2021) there is no documentation provided by Google for the underlying node function.
|
|
1268
|
+
* Check the Documentation for [the low-level function](https://cloud.google.com/datastore/docs/reference/data/rest/v1/projects/allocateIds)
|
|
1269
|
+
* and [the conceptual overview](https://cloud.google.com/datastore/docs/concepts/entities#assigning_your_own_numeric_id)
|
|
1270
|
+
* and [this Stackoverflow post](https://stackoverflow.com/questions/60516959/how-does-allocateids-work-in-cloud-datastore-mode).
|
|
1271
|
+
*
|
|
1272
|
+
* The ID is a string encoded large number. This function will never return the same ID twice for any given Datastore.
|
|
1273
|
+
* If you provide a kindName the ID will be namespaced to this kind.
|
|
1274
|
+
* In fact the generated ID is namespaced via an incomplete [[Key]] of the given Kind.
|
|
1275
|
+
*/
|
|
1276
|
+
;
|
|
1277
|
+
_proto.allocateOneId =
|
|
1278
|
+
/*#__PURE__*/
|
|
1279
|
+
function () {
|
|
1280
|
+
var _allocateOneId = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(kindName) {
|
|
1281
|
+
var ret;
|
|
1282
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
1283
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
1284
|
+
case 0:
|
|
1285
|
+
if (kindName === void 0) {
|
|
1286
|
+
kindName = 'Numbering';
|
|
1287
|
+
}
|
|
1288
|
+
assertateDebug.assertIsString(kindName);
|
|
1289
|
+
_context10.next = 4;
|
|
1290
|
+
return this.datastore.allocateIds(this.key([kindName]), 1);
|
|
1291
|
+
case 4:
|
|
1292
|
+
ret = _context10.sent[0][0].id;
|
|
1293
|
+
assertateDebug.assertIsString(ret);
|
|
1294
|
+
return _context10.abrupt("return", ret);
|
|
1295
|
+
case 7:
|
|
1296
|
+
case "end":
|
|
1297
|
+
return _context10.stop();
|
|
1298
|
+
}
|
|
1299
|
+
}, _callee10, this);
|
|
1300
|
+
}));
|
|
1301
|
+
function allocateOneId(_x16) {
|
|
1302
|
+
return _allocateOneId.apply(this, arguments);
|
|
1303
|
+
}
|
|
1304
|
+
return allocateOneId;
|
|
1305
|
+
}()
|
|
1306
|
+
/** This tries to give high level access to transactions.
|
|
1307
|
+
So called "Gross Group Transactions" are always enabled. Transactions are never Cross Project. `runInTransaction()` works only if you use the same [[KvStore] instance for all access within the Transaction.
|
|
1308
|
+
[[runInTransaction]] is modelled after Python 2.7 [ndb's `@ndb.transactional` feature](https://cloud.google.com/appengine/docs/standard/python/ndb/transactions). This is based on node's [AsyncLocalStorage](https://nodejs.org/docs/latest-v14.x/api/async_hooks.html).
|
|
1309
|
+
Transactions frequently fail if you try to access the same data via in a transaction. See the [Documentation on Locking](https://cloud.google.com/datastore/docs/concepts/transactions#transaction_locks) for further reference. You are advised to use [p-limit](https://github.com/sindresorhus/p-limit)(1) to serialize transactions touching the same resource. This should work nicely with node's single process model. It is a much bigger problem on shared-nothing approaches, like Python on App Engine.
|
|
1310
|
+
Transactions might be wrapped in [p-retry](https://github.com/sindresorhus/p-retry) to implement automatically retrying them with exponential back-off should they fail due to contention.
|
|
1311
|
+
Be aware that Transactions differ considerable between Master-Slave Datastore (very old), High Replication Datastore (old, later called [Google Cloud Datastore](https://cloud.google.com/datastore/docs/concepts/cloud-datastore-transactions)) and [Firestore in Datastore Mode](https://cloud.google.com/datastore/docs/firestore-or-datastore#in_datastore_mode) (current).
|
|
1312
|
+
Most Applications today are running on "Firestore in Datastore Mode". Beware that the Datastore-Emulator fails with `error: 3 INVALID_ARGUMENT: Only ancestor queries are allowed inside transactions.` during [[runQuery]] while the Datastore on Google Infrastructure does not have such an restriction anymore as of 2022.
|
|
1313
|
+
*/
|
|
1314
|
+
;
|
|
1315
|
+
_proto.runInTransaction =
|
|
1316
|
+
/*#__PURE__*/
|
|
1317
|
+
function () {
|
|
1318
|
+
var _runInTransaction = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(func) {
|
|
1319
|
+
var ret, transaction;
|
|
1320
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
1321
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
1322
|
+
case 0:
|
|
1323
|
+
transaction = this.datastore.transaction();
|
|
1324
|
+
_context12.next = 3;
|
|
1325
|
+
return transactionAsyncLocalStorage.run(transaction, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
|
|
1326
|
+
var _yield$transaction$ru, transactionInfo, transactionRunApiResponse, commitApiResponse, rollbackInfo;
|
|
1327
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
1328
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
1329
|
+
case 0:
|
|
1330
|
+
_context11.next = 2;
|
|
1331
|
+
return transaction.run();
|
|
1332
|
+
case 2:
|
|
1333
|
+
_yield$transaction$ru = _context11.sent;
|
|
1334
|
+
transactionInfo = _yield$transaction$ru[0];
|
|
1335
|
+
transactionRunApiResponse = _yield$transaction$ru[1];
|
|
1336
|
+
_context11.prev = 5;
|
|
1337
|
+
_context11.next = 8;
|
|
1338
|
+
return func();
|
|
1339
|
+
case 8:
|
|
1340
|
+
ret = _context11.sent;
|
|
1341
|
+
_context11.next = 20;
|
|
1342
|
+
break;
|
|
1343
|
+
case 11:
|
|
1344
|
+
_context11.prev = 11;
|
|
1345
|
+
_context11.t0 = _context11["catch"](5);
|
|
1346
|
+
_context11.next = 15;
|
|
1347
|
+
return transaction.rollback();
|
|
1348
|
+
case 15:
|
|
1349
|
+
rollbackInfo = _context11.sent;
|
|
1350
|
+
debug('Transaction failed, rollback initiated: %O %O %O %O', transactionInfo, transactionRunApiResponse, rollbackInfo, _context11.t0);
|
|
1351
|
+
_context11.next = 19;
|
|
1352
|
+
return promises.setImmediate();
|
|
1353
|
+
case 19:
|
|
1354
|
+
throw new DstoreError('datastore.transaction execution error', _context11.t0);
|
|
1355
|
+
case 20:
|
|
1356
|
+
_context11.prev = 20;
|
|
1357
|
+
_context11.next = 23;
|
|
1358
|
+
return transaction.commit();
|
|
1359
|
+
case 23:
|
|
1360
|
+
commitApiResponse = _context11.sent[0];
|
|
1361
|
+
_context11.next = 32;
|
|
1362
|
+
break;
|
|
1363
|
+
case 26:
|
|
1364
|
+
_context11.prev = 26;
|
|
1365
|
+
_context11.t1 = _context11["catch"](20);
|
|
1366
|
+
debug('Transaction commit failed: %O %O %O %O ret: %O', transactionInfo, transactionRunApiResponse, commitApiResponse, _context11.t1, ret);
|
|
1367
|
+
_context11.next = 31;
|
|
1368
|
+
return promises.setImmediate();
|
|
1369
|
+
case 31:
|
|
1370
|
+
throw new DstoreError('datastore.transaction execution error', _context11.t1);
|
|
1371
|
+
case 32:
|
|
1372
|
+
case "end":
|
|
1373
|
+
return _context11.stop();
|
|
1374
|
+
}
|
|
1375
|
+
}, _callee11, null, [[5, 11], [20, 26]]);
|
|
1376
|
+
})));
|
|
1377
|
+
case 3:
|
|
1378
|
+
return _context12.abrupt("return", ret);
|
|
1379
|
+
case 4:
|
|
1380
|
+
case "end":
|
|
1381
|
+
return _context12.stop();
|
|
1382
|
+
}
|
|
1383
|
+
}, _callee12, this);
|
|
1384
|
+
}));
|
|
1385
|
+
function runInTransaction(_x17) {
|
|
1386
|
+
return _runInTransaction.apply(this, arguments);
|
|
1387
|
+
}
|
|
1388
|
+
return runInTransaction;
|
|
1389
|
+
}();
|
|
1390
|
+
return Dstore;
|
|
1391
|
+
}();
|
|
1392
|
+
var DstoreError = /*#__PURE__*/function (_Error) {
|
|
1393
|
+
_inheritsLoose(DstoreError, _Error);
|
|
1394
|
+
function DstoreError(message, originalError, extensions) {
|
|
1395
|
+
var _this2$stack, _originalError$stack, _this2$stack2;
|
|
1396
|
+
var _this2;
|
|
1397
|
+
_this2 = _Error.call(this, message + ": " + (originalError == null ? void 0 : originalError.message)) || this;
|
|
1398
|
+
// if no name provided, use the default. defineProperty ensures that it stays non-enumerable
|
|
1399
|
+
_this2.extensions = void 0;
|
|
1400
|
+
_this2.originalError = void 0;
|
|
1401
|
+
if (!_this2.name) {
|
|
1402
|
+
Object.defineProperty(_assertThisInitialized(_this2), 'name', {
|
|
1403
|
+
value: 'DstoreError'
|
|
1404
|
+
});
|
|
1405
|
+
}
|
|
1406
|
+
// metadata: Metadata { internalRepr: Map(0) {}, options: {} },
|
|
1407
|
+
_this2.originalError = originalError;
|
|
1408
|
+
_this2.extensions = _extends({}, extensions);
|
|
1409
|
+
_this2.stack = (((_this2$stack = _this2.stack) == null ? void 0 : _this2$stack.split('\n')[0]) || '') + '\n' + ((originalError == null || (_originalError$stack = originalError.stack) == null || (_originalError$stack = _originalError$stack.split('\n')) == null || (_originalError$stack = _originalError$stack.slice(1)) == null ? void 0 : _originalError$stack.join('\n')) || '') + '\n' + (((_this2$stack2 = _this2.stack) == null || (_this2$stack2 = _this2$stack2.split('\n')) == null || (_this2$stack2 = _this2$stack2.slice(1)) == null ? void 0 : _this2$stack2.join('\n')) || '');
|
|
1410
|
+
// These are usually present on Datastore Errors
|
|
1411
|
+
// logger.error({ err: originalError, extensions }, message);
|
|
1412
|
+
return _this2;
|
|
1413
|
+
}
|
|
1414
|
+
return DstoreError;
|
|
1415
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
1416
|
+
|
|
1417
|
+
Object.defineProperty(exports, 'Datastore', {
|
|
1418
|
+
enumerable: true,
|
|
1419
|
+
get: function () { return datastore.Datastore; }
|
|
1420
|
+
});
|
|
1421
|
+
Object.defineProperty(exports, 'Key', {
|
|
1422
|
+
enumerable: true,
|
|
1423
|
+
get: function () { return datastore.Key; }
|
|
1424
|
+
});
|
|
1425
|
+
Object.defineProperty(exports, 'Query', {
|
|
1426
|
+
enumerable: true,
|
|
1427
|
+
get: function () { return datastore.Query; }
|
|
1428
|
+
});
|
|
1429
|
+
Object.defineProperty(exports, 'Transaction', {
|
|
1430
|
+
enumerable: true,
|
|
1431
|
+
get: function () { return datastore.Transaction; }
|
|
1432
|
+
});
|
|
1433
|
+
exports.Dstore = Dstore;
|
|
1434
|
+
exports.DstoreError = DstoreError;
|
|
1435
|
+
exports.KEYSYM = KEYSYM;
|
|
1436
|
+
//# sourceMappingURL=datastore-api.cjs.development.js.map
|