couchset 0.4.1 → 0.5.0
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 +84 -1
- package/dist/eventing.d.ts +179 -0
- package/dist/eventing.js +822 -0
- package/dist/eventing.js.map +1 -0
- package/dist/next.d.ts +8 -0
- package/dist/next.js +23 -0
- package/dist/next.js.map +1 -1
- package/docs/next-primitives.md +33 -0
- package/package.json +1 -1
package/dist/eventing.js
ADDED
|
@@ -0,0 +1,822 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __values = (this && this.__values) || function(o) {
|
|
50
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
51
|
+
if (m) return m.call(o);
|
|
52
|
+
if (o && typeof o.length === "number") return {
|
|
53
|
+
next: function () {
|
|
54
|
+
if (o && i >= o.length) o = void 0;
|
|
55
|
+
return { value: o && o[i++], done: !o };
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
59
|
+
};
|
|
60
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
61
|
+
exports.defineEventingFunction = exports.createEventingWithManager = exports.createEventing = exports.Eventing = void 0;
|
|
62
|
+
var timerStateWarning = 'Undeploying an Eventing function erases its Eventing timers and checkpoints.';
|
|
63
|
+
var emptyReport = function () { return ({
|
|
64
|
+
created: [],
|
|
65
|
+
outcomes: [],
|
|
66
|
+
paused: [],
|
|
67
|
+
pruned: [],
|
|
68
|
+
removed: [],
|
|
69
|
+
requiresRecreate: [],
|
|
70
|
+
resumed: [],
|
|
71
|
+
unchanged: [],
|
|
72
|
+
updated: [],
|
|
73
|
+
}); };
|
|
74
|
+
var normalizeKeyspace = function (keyspace) { return ({
|
|
75
|
+
bucket: keyspace.bucket,
|
|
76
|
+
collection: keyspace.collection || '_default',
|
|
77
|
+
scope: keyspace.scope || '_default',
|
|
78
|
+
}); };
|
|
79
|
+
var keyspaceEquals = function (left, right) {
|
|
80
|
+
var normalizedLeft = normalizeKeyspace(left);
|
|
81
|
+
var normalizedRight = normalizeKeyspace(right);
|
|
82
|
+
return (normalizedLeft.bucket === normalizedRight.bucket &&
|
|
83
|
+
normalizedLeft.scope === normalizedRight.scope &&
|
|
84
|
+
normalizedLeft.collection === normalizedRight.collection);
|
|
85
|
+
};
|
|
86
|
+
var requiredKeyspace = function (keyspace, label) {
|
|
87
|
+
if (!keyspace || !keyspace.bucket) {
|
|
88
|
+
throw new Error("".concat(label, " requires a non-empty bucket"));
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
var stableValue = function (value) {
|
|
92
|
+
if (value === undefined) {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
if (value === null || typeof value !== 'object') {
|
|
96
|
+
return value;
|
|
97
|
+
}
|
|
98
|
+
if (Array.isArray(value)) {
|
|
99
|
+
return value.map(stableValue);
|
|
100
|
+
}
|
|
101
|
+
var normalized = {};
|
|
102
|
+
Object.keys(value)
|
|
103
|
+
.sort()
|
|
104
|
+
.forEach(function (key) {
|
|
105
|
+
var item = stableValue(value[key]);
|
|
106
|
+
if (item !== undefined) {
|
|
107
|
+
normalized[key] = item;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
return normalized;
|
|
111
|
+
};
|
|
112
|
+
var equal = function (left, right) {
|
|
113
|
+
return JSON.stringify(stableValue(left)) === JSON.stringify(stableValue(right));
|
|
114
|
+
};
|
|
115
|
+
var settingsMatch = function (live, desired) {
|
|
116
|
+
var requested = desired || {};
|
|
117
|
+
var comparableLive = {};
|
|
118
|
+
Object.keys(requested).forEach(function (key) {
|
|
119
|
+
if (key !== 'deploymentStatus' && key !== 'processingStatus') {
|
|
120
|
+
comparableLive[key] = live === null || live === void 0 ? void 0 : live[key];
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
var comparableDesired = {};
|
|
124
|
+
Object.keys(requested).forEach(function (key) {
|
|
125
|
+
if (key !== 'deploymentStatus' && key !== 'processingStatus') {
|
|
126
|
+
comparableDesired[key] = requested[key];
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
return equal(comparableLive, comparableDesired);
|
|
130
|
+
};
|
|
131
|
+
var lifecycleFor = function (state, functionDefinition) {
|
|
132
|
+
var _a, _b;
|
|
133
|
+
var status = (state === null || state === void 0 ? void 0 : state.status) || '';
|
|
134
|
+
var deploymentStatus = (state === null || state === void 0 ? void 0 : state.deploymentStatus) ||
|
|
135
|
+
((_a = functionDefinition.settings) === null || _a === void 0 ? void 0 : _a.deploymentStatus) ||
|
|
136
|
+
'';
|
|
137
|
+
var processingStatus = (state === null || state === void 0 ? void 0 : state.processingStatus) ||
|
|
138
|
+
((_b = functionDefinition.settings) === null || _b === void 0 ? void 0 : _b.processingStatus) ||
|
|
139
|
+
'';
|
|
140
|
+
return {
|
|
141
|
+
deployed: status === 'deployed' || status === 'paused' || deploymentStatus === 'deployed',
|
|
142
|
+
paused: status === 'paused' || processingStatus === 'paused',
|
|
143
|
+
transitional: status === 'deploying' ||
|
|
144
|
+
status === 'undeploying' ||
|
|
145
|
+
status === 'pausing' ||
|
|
146
|
+
deploymentStatus === 'deploying' ||
|
|
147
|
+
deploymentStatus === 'undeploying',
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
var own = function (object, key) {
|
|
151
|
+
return Object.prototype.hasOwnProperty.call(object, key);
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Declarative Eventing reconciler backed by the SDK 4.7 EventingFunctionManager.
|
|
155
|
+
* It only manages names starting with its namespace prefix.
|
|
156
|
+
*/
|
|
157
|
+
var Eventing = /** @class */ (function () {
|
|
158
|
+
function Eventing(client, options) {
|
|
159
|
+
var _this = this;
|
|
160
|
+
this.definitionsByName = new Map();
|
|
161
|
+
if (!options || !options.namespace || !options.namespace.trim()) {
|
|
162
|
+
throw new Error('Eventing requires an explicit, non-empty namespace');
|
|
163
|
+
}
|
|
164
|
+
requiredKeyspace(options.metadataKeyspace, 'Eventing metadataKeyspace');
|
|
165
|
+
if (!options.metadataKeyspace.collection ||
|
|
166
|
+
options.metadataKeyspace.collection === '_default') {
|
|
167
|
+
throw new Error('Eventing metadataKeyspace requires a dedicated non-default collection; CouchSet never uses it as application data');
|
|
168
|
+
}
|
|
169
|
+
this.client = client;
|
|
170
|
+
this.explicitManager = options.manager;
|
|
171
|
+
this.eventingMetadataKeyspace = __assign({}, options.metadataKeyspace);
|
|
172
|
+
this.lifecycleTimeoutMs = this.positiveNumber(options.lifecycleTimeoutMs, 30000);
|
|
173
|
+
this.lifecyclePollIntervalMs = this.nonNegativeNumber(options.lifecyclePollIntervalMs, 250);
|
|
174
|
+
this.prefix = "".concat(options.namespace.trim(), "__");
|
|
175
|
+
(options.definitions || options.functions || []).forEach(function (definition) {
|
|
176
|
+
return _this.register(definition);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
Object.defineProperty(Eventing.prototype, "namespace", {
|
|
180
|
+
/** Logical namespace that owns this controller's physical functions. */
|
|
181
|
+
get: function () {
|
|
182
|
+
return this.prefix.slice(0, -2);
|
|
183
|
+
},
|
|
184
|
+
enumerable: false,
|
|
185
|
+
configurable: true
|
|
186
|
+
});
|
|
187
|
+
/** A copy of registered, code-only declarations. This performs no I/O. */
|
|
188
|
+
Eventing.prototype.definitions = function () {
|
|
189
|
+
return Array.from(this.definitionsByName.values()).map(function (definition) { return (__assign({}, definition)); });
|
|
190
|
+
};
|
|
191
|
+
/** Converts a logical declaration name into its Couchbase function name. */
|
|
192
|
+
Eventing.prototype.physicalName = function (name) {
|
|
193
|
+
this.assertLogicalName(name);
|
|
194
|
+
return "".concat(this.prefix).concat(name);
|
|
195
|
+
};
|
|
196
|
+
/** Registers or replaces an in-memory manifest declaration without I/O. */
|
|
197
|
+
Eventing.prototype.register = function (definition) {
|
|
198
|
+
this.assertDefinition(definition);
|
|
199
|
+
this.definitionsByName.set(definition.name, __assign({}, definition));
|
|
200
|
+
return definition;
|
|
201
|
+
};
|
|
202
|
+
/** Alias for register(), matching the declaration-oriented API vocabulary. */
|
|
203
|
+
Eventing.prototype.define = function (definition) {
|
|
204
|
+
return this.register(definition);
|
|
205
|
+
};
|
|
206
|
+
Eventing.prototype.apply = function (definitionOrOptions_1) {
|
|
207
|
+
return __awaiter(this, arguments, void 0, function (definitionOrOptions, possibleOptions) {
|
|
208
|
+
var dynamic, options, report, manager, live, states, statesByName, liveByName, targets, targets_1, targets_1_1, definition, e_1_1, declared_1, live_1, live_1_1, functionDefinition, e_2_1;
|
|
209
|
+
var e_1, _a, e_2, _b;
|
|
210
|
+
var _this = this;
|
|
211
|
+
if (possibleOptions === void 0) { possibleOptions = {}; }
|
|
212
|
+
return __generator(this, function (_c) {
|
|
213
|
+
switch (_c.label) {
|
|
214
|
+
case 0:
|
|
215
|
+
dynamic = this.isDefinition(definitionOrOptions) ? definitionOrOptions : undefined;
|
|
216
|
+
options = dynamic
|
|
217
|
+
? possibleOptions
|
|
218
|
+
: definitionOrOptions || {};
|
|
219
|
+
report = emptyReport();
|
|
220
|
+
return [4 /*yield*/, this.manager()];
|
|
221
|
+
case 1:
|
|
222
|
+
manager = _c.sent();
|
|
223
|
+
if (dynamic) {
|
|
224
|
+
this.register(dynamic);
|
|
225
|
+
}
|
|
226
|
+
return [4 /*yield*/, manager.getAllFunctions()];
|
|
227
|
+
case 2:
|
|
228
|
+
live = _c.sent();
|
|
229
|
+
return [4 /*yield*/, this.states(manager)];
|
|
230
|
+
case 3:
|
|
231
|
+
states = _c.sent();
|
|
232
|
+
statesByName = new Map();
|
|
233
|
+
states.forEach(function (state) { return statesByName.set(state.name, state); });
|
|
234
|
+
liveByName = new Map();
|
|
235
|
+
live.forEach(function (functionDefinition) {
|
|
236
|
+
return liveByName.set(functionDefinition.name, functionDefinition);
|
|
237
|
+
});
|
|
238
|
+
targets = dynamic ? [dynamic] : this.definitions();
|
|
239
|
+
_c.label = 4;
|
|
240
|
+
case 4:
|
|
241
|
+
_c.trys.push([4, 9, 10, 11]);
|
|
242
|
+
targets_1 = __values(targets), targets_1_1 = targets_1.next();
|
|
243
|
+
_c.label = 5;
|
|
244
|
+
case 5:
|
|
245
|
+
if (!!targets_1_1.done) return [3 /*break*/, 8];
|
|
246
|
+
definition = targets_1_1.value;
|
|
247
|
+
return [4 /*yield*/, this.reconcile(manager, definition, liveByName.get(this.physicalName(definition.name)), statesByName.get(this.physicalName(definition.name)), options, report)];
|
|
248
|
+
case 6:
|
|
249
|
+
_c.sent();
|
|
250
|
+
_c.label = 7;
|
|
251
|
+
case 7:
|
|
252
|
+
targets_1_1 = targets_1.next();
|
|
253
|
+
return [3 /*break*/, 5];
|
|
254
|
+
case 8: return [3 /*break*/, 11];
|
|
255
|
+
case 9:
|
|
256
|
+
e_1_1 = _c.sent();
|
|
257
|
+
e_1 = { error: e_1_1 };
|
|
258
|
+
return [3 /*break*/, 11];
|
|
259
|
+
case 10:
|
|
260
|
+
try {
|
|
261
|
+
if (targets_1_1 && !targets_1_1.done && (_a = targets_1.return)) _a.call(targets_1);
|
|
262
|
+
}
|
|
263
|
+
finally { if (e_1) throw e_1.error; }
|
|
264
|
+
return [7 /*endfinally*/];
|
|
265
|
+
case 11:
|
|
266
|
+
if (!!dynamic) return [3 /*break*/, 19];
|
|
267
|
+
declared_1 = new Set();
|
|
268
|
+
targets.forEach(function (definition) { return declared_1.add(_this.physicalName(definition.name)); });
|
|
269
|
+
_c.label = 12;
|
|
270
|
+
case 12:
|
|
271
|
+
_c.trys.push([12, 17, 18, 19]);
|
|
272
|
+
live_1 = __values(live), live_1_1 = live_1.next();
|
|
273
|
+
_c.label = 13;
|
|
274
|
+
case 13:
|
|
275
|
+
if (!!live_1_1.done) return [3 /*break*/, 16];
|
|
276
|
+
functionDefinition = live_1_1.value;
|
|
277
|
+
if (!(this.owns(functionDefinition.name) && !declared_1.has(functionDefinition.name))) return [3 /*break*/, 15];
|
|
278
|
+
return [4 /*yield*/, this.prune(manager, functionDefinition, statesByName.get(functionDefinition.name), report)];
|
|
279
|
+
case 14:
|
|
280
|
+
_c.sent();
|
|
281
|
+
_c.label = 15;
|
|
282
|
+
case 15:
|
|
283
|
+
live_1_1 = live_1.next();
|
|
284
|
+
return [3 /*break*/, 13];
|
|
285
|
+
case 16: return [3 /*break*/, 19];
|
|
286
|
+
case 17:
|
|
287
|
+
e_2_1 = _c.sent();
|
|
288
|
+
e_2 = { error: e_2_1 };
|
|
289
|
+
return [3 /*break*/, 19];
|
|
290
|
+
case 18:
|
|
291
|
+
try {
|
|
292
|
+
if (live_1_1 && !live_1_1.done && (_b = live_1.return)) _b.call(live_1);
|
|
293
|
+
}
|
|
294
|
+
finally { if (e_2) throw e_2.error; }
|
|
295
|
+
return [7 /*endfinally*/];
|
|
296
|
+
case 19: return [2 /*return*/, report];
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
};
|
|
301
|
+
/** Temporarily disables one namespace-owned Eventing function. */
|
|
302
|
+
Eventing.prototype.pause = function (name) {
|
|
303
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
304
|
+
var report, physicalName, manager, live, current, states, state, lifecycle;
|
|
305
|
+
return __generator(this, function (_a) {
|
|
306
|
+
switch (_a.label) {
|
|
307
|
+
case 0:
|
|
308
|
+
report = emptyReport();
|
|
309
|
+
physicalName = this.physicalName(name);
|
|
310
|
+
return [4 /*yield*/, this.manager()];
|
|
311
|
+
case 1:
|
|
312
|
+
manager = _a.sent();
|
|
313
|
+
return [4 /*yield*/, manager.getAllFunctions()];
|
|
314
|
+
case 2:
|
|
315
|
+
live = _a.sent();
|
|
316
|
+
current = live.filter(function (functionDefinition) { return functionDefinition.name === physicalName; })[0];
|
|
317
|
+
if (!current) {
|
|
318
|
+
this.record(report, this.outcome('unchanged', name, ['unchanged'], 'No namespace-owned Eventing function exists with this name.'));
|
|
319
|
+
return [2 /*return*/, report];
|
|
320
|
+
}
|
|
321
|
+
return [4 /*yield*/, this.states(manager)];
|
|
322
|
+
case 3:
|
|
323
|
+
states = _a.sent();
|
|
324
|
+
state = states.filter(function (item) { return item.name === physicalName; })[0];
|
|
325
|
+
return [4 /*yield*/, this.stableLifecycle(manager, physicalName, current, state)];
|
|
326
|
+
case 4:
|
|
327
|
+
lifecycle = _a.sent();
|
|
328
|
+
if (!lifecycle.deployed || lifecycle.paused) {
|
|
329
|
+
this.record(report, this.outcome('unchanged', name, ['unchanged']));
|
|
330
|
+
return [2 /*return*/, report];
|
|
331
|
+
}
|
|
332
|
+
return [4 /*yield*/, manager.pauseFunction(physicalName)];
|
|
333
|
+
case 5:
|
|
334
|
+
_a.sent();
|
|
335
|
+
return [4 /*yield*/, this.waitForLifecycle(manager, physicalName, 'paused')];
|
|
336
|
+
case 6:
|
|
337
|
+
_a.sent();
|
|
338
|
+
this.record(report, this.outcome('paused', name, ['paused']));
|
|
339
|
+
return [2 /*return*/, report];
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
};
|
|
344
|
+
/**
|
|
345
|
+
* Intentionally undeploys then deletes one namespace-owned function.
|
|
346
|
+
* Undeployment erases Couchbase Eventing timers and checkpoints.
|
|
347
|
+
*/
|
|
348
|
+
Eventing.prototype.remove = function (name) {
|
|
349
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
350
|
+
var report, physicalName, manager, live, current, states, state, lifecycle;
|
|
351
|
+
return __generator(this, function (_a) {
|
|
352
|
+
switch (_a.label) {
|
|
353
|
+
case 0:
|
|
354
|
+
report = emptyReport();
|
|
355
|
+
physicalName = this.physicalName(name);
|
|
356
|
+
return [4 /*yield*/, this.manager()];
|
|
357
|
+
case 1:
|
|
358
|
+
manager = _a.sent();
|
|
359
|
+
return [4 /*yield*/, manager.getAllFunctions()];
|
|
360
|
+
case 2:
|
|
361
|
+
live = _a.sent();
|
|
362
|
+
current = live.filter(function (functionDefinition) { return functionDefinition.name === physicalName; })[0];
|
|
363
|
+
if (!current) {
|
|
364
|
+
this.record(report, this.outcome('unchanged', name, ['unchanged'], 'No namespace-owned Eventing function exists with this name.'));
|
|
365
|
+
return [2 /*return*/, report];
|
|
366
|
+
}
|
|
367
|
+
return [4 /*yield*/, this.states(manager)];
|
|
368
|
+
case 3:
|
|
369
|
+
states = _a.sent();
|
|
370
|
+
state = states.filter(function (item) { return item.name === physicalName; })[0];
|
|
371
|
+
return [4 /*yield*/, this.stableLifecycle(manager, physicalName, current, state)];
|
|
372
|
+
case 4:
|
|
373
|
+
lifecycle = _a.sent();
|
|
374
|
+
if (!lifecycle.deployed) return [3 /*break*/, 7];
|
|
375
|
+
return [4 /*yield*/, manager.undeployFunction(physicalName)];
|
|
376
|
+
case 5:
|
|
377
|
+
_a.sent();
|
|
378
|
+
return [4 /*yield*/, this.waitForLifecycle(manager, physicalName, 'undeployed')];
|
|
379
|
+
case 6:
|
|
380
|
+
_a.sent();
|
|
381
|
+
_a.label = 7;
|
|
382
|
+
case 7: return [4 /*yield*/, manager.dropFunction(physicalName)];
|
|
383
|
+
case 8:
|
|
384
|
+
_a.sent();
|
|
385
|
+
this.definitionsByName.delete(name);
|
|
386
|
+
this.record(report, this.outcome('removed', name, ['removed'], timerStateWarning, lifecycle.deployed));
|
|
387
|
+
return [2 /*return*/, report];
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
});
|
|
391
|
+
};
|
|
392
|
+
Eventing.prototype.reconcile = function (manager, definition, current, state, options, report) {
|
|
393
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
394
|
+
var physicalName, desired, lifecycle, keyspaceChanged, actions;
|
|
395
|
+
return __generator(this, function (_a) {
|
|
396
|
+
switch (_a.label) {
|
|
397
|
+
case 0:
|
|
398
|
+
physicalName = this.physicalName(definition.name);
|
|
399
|
+
desired = this.sdkDefinition(definition);
|
|
400
|
+
if (!!current) return [3 /*break*/, 4];
|
|
401
|
+
return [4 /*yield*/, manager.upsertFunction(desired)];
|
|
402
|
+
case 1:
|
|
403
|
+
_a.sent();
|
|
404
|
+
return [4 /*yield*/, manager.deployFunction(physicalName)];
|
|
405
|
+
case 2:
|
|
406
|
+
_a.sent();
|
|
407
|
+
return [4 /*yield*/, this.waitForLifecycle(manager, physicalName, 'deployed')];
|
|
408
|
+
case 3:
|
|
409
|
+
_a.sent();
|
|
410
|
+
this.record(report, this.outcome('created', definition.name, ['created']));
|
|
411
|
+
return [2 /*return*/];
|
|
412
|
+
case 4: return [4 /*yield*/, this.stableLifecycle(manager, physicalName, current, state)];
|
|
413
|
+
case 5:
|
|
414
|
+
lifecycle = _a.sent();
|
|
415
|
+
keyspaceChanged = !keyspaceEquals(current.sourceKeyspace, desired.sourceKeyspace) ||
|
|
416
|
+
!keyspaceEquals(current.metadataKeyspace, desired.metadataKeyspace);
|
|
417
|
+
if (!keyspaceChanged) return [3 /*break*/, 12];
|
|
418
|
+
if (!options.allowRecreate) {
|
|
419
|
+
this.record(report, this.outcome('requires-recreate', definition.name, ['requires-recreate'], "".concat(timerStateWarning, " Re-run apply with {allowRecreate: true} to permit this keyspace change.")));
|
|
420
|
+
return [2 /*return*/];
|
|
421
|
+
}
|
|
422
|
+
if (!lifecycle.deployed) return [3 /*break*/, 8];
|
|
423
|
+
return [4 /*yield*/, manager.undeployFunction(physicalName)];
|
|
424
|
+
case 6:
|
|
425
|
+
_a.sent();
|
|
426
|
+
return [4 /*yield*/, this.waitForLifecycle(manager, physicalName, 'undeployed')];
|
|
427
|
+
case 7:
|
|
428
|
+
_a.sent();
|
|
429
|
+
_a.label = 8;
|
|
430
|
+
case 8: return [4 /*yield*/, manager.upsertFunction(desired)];
|
|
431
|
+
case 9:
|
|
432
|
+
_a.sent();
|
|
433
|
+
return [4 /*yield*/, manager.deployFunction(physicalName)];
|
|
434
|
+
case 10:
|
|
435
|
+
_a.sent();
|
|
436
|
+
return [4 /*yield*/, this.waitForLifecycle(manager, physicalName, 'deployed')];
|
|
437
|
+
case 11:
|
|
438
|
+
_a.sent();
|
|
439
|
+
this.record(report, this.outcome('updated', definition.name, ['updated'], timerStateWarning, lifecycle.deployed));
|
|
440
|
+
return [2 /*return*/];
|
|
441
|
+
case 12:
|
|
442
|
+
if (!this.matches(current, desired, definition)) return [3 /*break*/, 20];
|
|
443
|
+
if (!lifecycle.paused) return [3 /*break*/, 15];
|
|
444
|
+
return [4 /*yield*/, manager.resumeFunction(physicalName)];
|
|
445
|
+
case 13:
|
|
446
|
+
_a.sent();
|
|
447
|
+
return [4 /*yield*/, this.waitForLifecycle(manager, physicalName, 'deployed')];
|
|
448
|
+
case 14:
|
|
449
|
+
_a.sent();
|
|
450
|
+
this.record(report, this.outcome('resumed', definition.name, ['resumed']));
|
|
451
|
+
return [3 /*break*/, 19];
|
|
452
|
+
case 15:
|
|
453
|
+
if (!!lifecycle.deployed) return [3 /*break*/, 18];
|
|
454
|
+
return [4 /*yield*/, manager.deployFunction(physicalName)];
|
|
455
|
+
case 16:
|
|
456
|
+
_a.sent();
|
|
457
|
+
return [4 /*yield*/, this.waitForLifecycle(manager, physicalName, 'deployed')];
|
|
458
|
+
case 17:
|
|
459
|
+
_a.sent();
|
|
460
|
+
this.record(report, this.outcome('resumed', definition.name, ['resumed']));
|
|
461
|
+
return [3 /*break*/, 19];
|
|
462
|
+
case 18:
|
|
463
|
+
this.record(report, this.outcome('unchanged', definition.name, ['unchanged']));
|
|
464
|
+
_a.label = 19;
|
|
465
|
+
case 19: return [2 /*return*/];
|
|
466
|
+
case 20:
|
|
467
|
+
actions = [];
|
|
468
|
+
if (!(lifecycle.deployed && !lifecycle.paused)) return [3 /*break*/, 23];
|
|
469
|
+
return [4 /*yield*/, manager.pauseFunction(physicalName)];
|
|
470
|
+
case 21:
|
|
471
|
+
_a.sent();
|
|
472
|
+
return [4 /*yield*/, this.waitForLifecycle(manager, physicalName, 'paused')];
|
|
473
|
+
case 22:
|
|
474
|
+
_a.sent();
|
|
475
|
+
actions.push('paused');
|
|
476
|
+
_a.label = 23;
|
|
477
|
+
case 23: return [4 /*yield*/, manager.upsertFunction(desired)];
|
|
478
|
+
case 24:
|
|
479
|
+
_a.sent();
|
|
480
|
+
actions.push('updated');
|
|
481
|
+
return [4 /*yield*/, this.activateAfterUpsert(manager, physicalName, desired, actions)];
|
|
482
|
+
case 25:
|
|
483
|
+
_a.sent();
|
|
484
|
+
this.record(report, this.outcome('updated', definition.name, actions));
|
|
485
|
+
return [2 /*return*/];
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
});
|
|
489
|
+
};
|
|
490
|
+
Eventing.prototype.prune = function (manager, functionDefinition, state, report) {
|
|
491
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
492
|
+
var lifecycle;
|
|
493
|
+
return __generator(this, function (_a) {
|
|
494
|
+
switch (_a.label) {
|
|
495
|
+
case 0: return [4 /*yield*/, this.stableLifecycle(manager, functionDefinition.name, functionDefinition, state)];
|
|
496
|
+
case 1:
|
|
497
|
+
lifecycle = _a.sent();
|
|
498
|
+
if (!lifecycle.deployed) return [3 /*break*/, 4];
|
|
499
|
+
return [4 /*yield*/, manager.undeployFunction(functionDefinition.name)];
|
|
500
|
+
case 2:
|
|
501
|
+
_a.sent();
|
|
502
|
+
return [4 /*yield*/, this.waitForLifecycle(manager, functionDefinition.name, 'undeployed')];
|
|
503
|
+
case 3:
|
|
504
|
+
_a.sent();
|
|
505
|
+
_a.label = 4;
|
|
506
|
+
case 4: return [4 /*yield*/, manager.dropFunction(functionDefinition.name)];
|
|
507
|
+
case 5:
|
|
508
|
+
_a.sent();
|
|
509
|
+
this.record(report, this.outcome('pruned', this.logicalName(functionDefinition.name), ['pruned'], timerStateWarning, lifecycle.deployed));
|
|
510
|
+
return [2 /*return*/];
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
});
|
|
514
|
+
};
|
|
515
|
+
Eventing.prototype.matches = function (current, desired, definition) {
|
|
516
|
+
return (current.code === desired.code &&
|
|
517
|
+
(definition.enforceSchema === undefined ||
|
|
518
|
+
current.enforceSchema === desired.enforceSchema) &&
|
|
519
|
+
equal(current.bucketBindings || [], desired.bucketBindings || []) &&
|
|
520
|
+
equal(current.urlBindings || [], desired.urlBindings || []) &&
|
|
521
|
+
equal(current.constantBindings || [], desired.constantBindings || []) &&
|
|
522
|
+
settingsMatch(current.settings, definition.settings));
|
|
523
|
+
};
|
|
524
|
+
Eventing.prototype.sdkDefinition = function (definition) {
|
|
525
|
+
var metadataKeyspace = normalizeKeyspace(this.metadataKeyspace());
|
|
526
|
+
var sourceKeyspace = normalizeKeyspace(definition.sourceKeyspace);
|
|
527
|
+
var settings = __assign({}, (definition.settings || {}));
|
|
528
|
+
// Lifecycle is controlled through manager methods, never through an upsert payload.
|
|
529
|
+
delete settings.deploymentStatus;
|
|
530
|
+
delete settings.processingStatus;
|
|
531
|
+
return {
|
|
532
|
+
bucketBindings: definition.bucketBindings || [],
|
|
533
|
+
code: definition.code,
|
|
534
|
+
constantBindings: definition.constantBindings || [],
|
|
535
|
+
enforceSchema: definition.enforceSchema,
|
|
536
|
+
metadataKeyspace: metadataKeyspace,
|
|
537
|
+
name: this.physicalName(definition.name),
|
|
538
|
+
settings: settings,
|
|
539
|
+
sourceKeyspace: sourceKeyspace,
|
|
540
|
+
urlBindings: definition.urlBindings || [],
|
|
541
|
+
};
|
|
542
|
+
};
|
|
543
|
+
Eventing.prototype.metadataKeyspace = function () {
|
|
544
|
+
// The keyspace has already been validated in the constructor. Keeping it
|
|
545
|
+
// behind this helper prevents accidental exposure as a CouchSet collection.
|
|
546
|
+
return this.eventingMetadataKeyspace;
|
|
547
|
+
};
|
|
548
|
+
Eventing.prototype.manager = function () {
|
|
549
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
550
|
+
var cluster;
|
|
551
|
+
return __generator(this, function (_a) {
|
|
552
|
+
switch (_a.label) {
|
|
553
|
+
case 0:
|
|
554
|
+
if (this.explicitManager) {
|
|
555
|
+
return [2 /*return*/, this.explicitManager];
|
|
556
|
+
}
|
|
557
|
+
if (!this.client) {
|
|
558
|
+
throw new Error('Eventing requires a CouchSet client or an explicit EventingFunctionManager');
|
|
559
|
+
}
|
|
560
|
+
return [4 /*yield*/, this.client.ready()];
|
|
561
|
+
case 1:
|
|
562
|
+
_a.sent();
|
|
563
|
+
cluster = this.client.getConnection().cluster;
|
|
564
|
+
if (!cluster || typeof cluster.eventingFunctions !== 'function') {
|
|
565
|
+
throw new Error('The connected Couchbase SDK does not expose EventingFunctionManager');
|
|
566
|
+
}
|
|
567
|
+
return [2 /*return*/, cluster.eventingFunctions()];
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
});
|
|
571
|
+
};
|
|
572
|
+
Eventing.prototype.states = function (manager) {
|
|
573
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
574
|
+
var result;
|
|
575
|
+
return __generator(this, function (_a) {
|
|
576
|
+
switch (_a.label) {
|
|
577
|
+
case 0: return [4 /*yield*/, manager.functionsStatus()];
|
|
578
|
+
case 1:
|
|
579
|
+
result = _a.sent();
|
|
580
|
+
return [2 /*return*/, result.functions || []];
|
|
581
|
+
}
|
|
582
|
+
});
|
|
583
|
+
});
|
|
584
|
+
};
|
|
585
|
+
/**
|
|
586
|
+
* Management requests acknowledge receipt, not necessarily completion. Do
|
|
587
|
+
* not issue the next incompatible Eventing operation until status confirms
|
|
588
|
+
* that Couchbase has converged.
|
|
589
|
+
*/
|
|
590
|
+
Eventing.prototype.waitForLifecycle = function (manager, physicalName, expected) {
|
|
591
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
592
|
+
var deadline, state, lifecycle, reached;
|
|
593
|
+
var _this = this;
|
|
594
|
+
return __generator(this, function (_a) {
|
|
595
|
+
switch (_a.label) {
|
|
596
|
+
case 0:
|
|
597
|
+
deadline = Date.now() + this.lifecycleTimeoutMs;
|
|
598
|
+
_a.label = 1;
|
|
599
|
+
case 1:
|
|
600
|
+
if (!true) return [3 /*break*/, 4];
|
|
601
|
+
return [4 /*yield*/, this.states(manager)];
|
|
602
|
+
case 2:
|
|
603
|
+
state = (_a.sent()).filter(function (item) { return item.name === physicalName; })[0];
|
|
604
|
+
lifecycle = lifecycleFor(state, { settings: {} });
|
|
605
|
+
reached = !!state &&
|
|
606
|
+
!lifecycle.transitional &&
|
|
607
|
+
((expected === 'deployed' && lifecycle.deployed && !lifecycle.paused) ||
|
|
608
|
+
(expected === 'paused' && lifecycle.deployed && lifecycle.paused) ||
|
|
609
|
+
(expected === 'undeployed' && !lifecycle.deployed));
|
|
610
|
+
if (reached) {
|
|
611
|
+
return [2 /*return*/];
|
|
612
|
+
}
|
|
613
|
+
if (Date.now() >= deadline) {
|
|
614
|
+
throw new Error("Timed out waiting for Eventing function ".concat(physicalName, " to become ").concat(expected));
|
|
615
|
+
}
|
|
616
|
+
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, _this.lifecyclePollIntervalMs); })];
|
|
617
|
+
case 3:
|
|
618
|
+
_a.sent();
|
|
619
|
+
return [3 /*break*/, 1];
|
|
620
|
+
case 4: return [2 /*return*/];
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
});
|
|
624
|
+
};
|
|
625
|
+
/**
|
|
626
|
+
* Couchbase Server may turn a paused function into an undeployed function
|
|
627
|
+
* when upsert persists new code/settings/bindings. Inspect that post-upsert
|
|
628
|
+
* state rather than assuming resume is legal; deploy is the compatible
|
|
629
|
+
* activation operation in that case.
|
|
630
|
+
*/
|
|
631
|
+
Eventing.prototype.activateAfterUpsert = function (manager, physicalName, functionDefinition, actions) {
|
|
632
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
633
|
+
var lifecycle;
|
|
634
|
+
return __generator(this, function (_a) {
|
|
635
|
+
switch (_a.label) {
|
|
636
|
+
case 0: return [4 /*yield*/, this.waitForStableLifecycle(manager, physicalName, functionDefinition)];
|
|
637
|
+
case 1:
|
|
638
|
+
lifecycle = _a.sent();
|
|
639
|
+
if (!(lifecycle.deployed && lifecycle.paused)) return [3 /*break*/, 4];
|
|
640
|
+
return [4 /*yield*/, manager.resumeFunction(physicalName)];
|
|
641
|
+
case 2:
|
|
642
|
+
_a.sent();
|
|
643
|
+
return [4 /*yield*/, this.waitForLifecycle(manager, physicalName, 'deployed')];
|
|
644
|
+
case 3:
|
|
645
|
+
_a.sent();
|
|
646
|
+
actions.push('resumed');
|
|
647
|
+
return [3 /*break*/, 7];
|
|
648
|
+
case 4:
|
|
649
|
+
if (!!lifecycle.deployed) return [3 /*break*/, 7];
|
|
650
|
+
return [4 /*yield*/, manager.deployFunction(physicalName)];
|
|
651
|
+
case 5:
|
|
652
|
+
_a.sent();
|
|
653
|
+
return [4 /*yield*/, this.waitForLifecycle(manager, physicalName, 'deployed')];
|
|
654
|
+
case 6:
|
|
655
|
+
_a.sent();
|
|
656
|
+
actions.push('resumed');
|
|
657
|
+
_a.label = 7;
|
|
658
|
+
case 7: return [2 /*return*/];
|
|
659
|
+
}
|
|
660
|
+
});
|
|
661
|
+
});
|
|
662
|
+
};
|
|
663
|
+
/**
|
|
664
|
+
* A live function with no status row is unknown, not safely undeployed.
|
|
665
|
+
* Poll for a positive row; a known transitional row remains an immediate
|
|
666
|
+
* blocker so callers do not race an operator's in-progress lifecycle call.
|
|
667
|
+
*/
|
|
668
|
+
Eventing.prototype.stableLifecycle = function (manager, physicalName, functionDefinition, initialState) {
|
|
669
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
670
|
+
var lifecycle, deadline, state, lifecycle;
|
|
671
|
+
var _this = this;
|
|
672
|
+
return __generator(this, function (_a) {
|
|
673
|
+
switch (_a.label) {
|
|
674
|
+
case 0:
|
|
675
|
+
if (initialState) {
|
|
676
|
+
lifecycle = lifecycleFor(initialState, functionDefinition);
|
|
677
|
+
this.assertStable(physicalName, lifecycle);
|
|
678
|
+
return [2 /*return*/, lifecycle];
|
|
679
|
+
}
|
|
680
|
+
deadline = Date.now() + this.lifecycleTimeoutMs;
|
|
681
|
+
_a.label = 1;
|
|
682
|
+
case 1:
|
|
683
|
+
if (!true) return [3 /*break*/, 4];
|
|
684
|
+
return [4 /*yield*/, this.states(manager)];
|
|
685
|
+
case 2:
|
|
686
|
+
state = (_a.sent()).filter(function (item) { return item.name === physicalName; })[0];
|
|
687
|
+
if (state) {
|
|
688
|
+
lifecycle = lifecycleFor(state, functionDefinition);
|
|
689
|
+
this.assertStable(physicalName, lifecycle);
|
|
690
|
+
return [2 /*return*/, lifecycle];
|
|
691
|
+
}
|
|
692
|
+
if (Date.now() >= deadline) {
|
|
693
|
+
throw new Error("Timed out waiting for Eventing status for function ".concat(physicalName));
|
|
694
|
+
}
|
|
695
|
+
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, _this.lifecyclePollIntervalMs); })];
|
|
696
|
+
case 3:
|
|
697
|
+
_a.sent();
|
|
698
|
+
return [3 /*break*/, 1];
|
|
699
|
+
case 4: return [2 /*return*/];
|
|
700
|
+
}
|
|
701
|
+
});
|
|
702
|
+
});
|
|
703
|
+
};
|
|
704
|
+
/** Waits for a stable state caused by this controller's own upsert call. */
|
|
705
|
+
Eventing.prototype.waitForStableLifecycle = function (manager, physicalName, functionDefinition) {
|
|
706
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
707
|
+
var deadline, state, lifecycle;
|
|
708
|
+
var _this = this;
|
|
709
|
+
return __generator(this, function (_a) {
|
|
710
|
+
switch (_a.label) {
|
|
711
|
+
case 0:
|
|
712
|
+
deadline = Date.now() + this.lifecycleTimeoutMs;
|
|
713
|
+
_a.label = 1;
|
|
714
|
+
case 1:
|
|
715
|
+
if (!true) return [3 /*break*/, 4];
|
|
716
|
+
return [4 /*yield*/, this.states(manager)];
|
|
717
|
+
case 2:
|
|
718
|
+
state = (_a.sent()).filter(function (item) { return item.name === physicalName; })[0];
|
|
719
|
+
if (state) {
|
|
720
|
+
lifecycle = lifecycleFor(state, functionDefinition);
|
|
721
|
+
if (!lifecycle.transitional) {
|
|
722
|
+
return [2 /*return*/, lifecycle];
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
if (Date.now() >= deadline) {
|
|
726
|
+
throw new Error("Timed out waiting for Eventing function ".concat(physicalName, " to settle after upsert"));
|
|
727
|
+
}
|
|
728
|
+
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, _this.lifecyclePollIntervalMs); })];
|
|
729
|
+
case 3:
|
|
730
|
+
_a.sent();
|
|
731
|
+
return [3 /*break*/, 1];
|
|
732
|
+
case 4: return [2 /*return*/];
|
|
733
|
+
}
|
|
734
|
+
});
|
|
735
|
+
});
|
|
736
|
+
};
|
|
737
|
+
Eventing.prototype.record = function (report, outcome) {
|
|
738
|
+
report.outcomes.push(outcome);
|
|
739
|
+
var actions = outcome.actions.length ? outcome.actions : [outcome.action];
|
|
740
|
+
actions.forEach(function (action) {
|
|
741
|
+
var list = action === 'requires-recreate' ? report.requiresRecreate : report[action];
|
|
742
|
+
if (list && list.indexOf(outcome) === -1) {
|
|
743
|
+
list.push(outcome);
|
|
744
|
+
}
|
|
745
|
+
});
|
|
746
|
+
};
|
|
747
|
+
Eventing.prototype.outcome = function (action, name, actions, message, timerStateLost) {
|
|
748
|
+
return {
|
|
749
|
+
action: action,
|
|
750
|
+
actions: actions,
|
|
751
|
+
message: message,
|
|
752
|
+
name: name,
|
|
753
|
+
physicalName: this.physicalName(name),
|
|
754
|
+
timerStateLost: timerStateLost,
|
|
755
|
+
};
|
|
756
|
+
};
|
|
757
|
+
Eventing.prototype.owns = function (name) {
|
|
758
|
+
return typeof name === 'string' && name.indexOf(this.prefix) === 0;
|
|
759
|
+
};
|
|
760
|
+
Eventing.prototype.logicalName = function (physicalName) {
|
|
761
|
+
if (!this.owns(physicalName)) {
|
|
762
|
+
throw new Error("Refusing to manage Eventing function outside namespace ".concat(this.namespace));
|
|
763
|
+
}
|
|
764
|
+
return physicalName.slice(this.prefix.length);
|
|
765
|
+
};
|
|
766
|
+
Eventing.prototype.assertDefinition = function (definition) {
|
|
767
|
+
if (!definition || !definition.name || !definition.name.trim()) {
|
|
768
|
+
throw new Error('Eventing definitions require a non-empty logical name');
|
|
769
|
+
}
|
|
770
|
+
if (!definition.code || typeof definition.code !== 'string') {
|
|
771
|
+
throw new Error("Eventing definition ".concat(definition.name, " requires handler code"));
|
|
772
|
+
}
|
|
773
|
+
requiredKeyspace(definition.sourceKeyspace, "Eventing definition ".concat(definition.name, " sourceKeyspace"));
|
|
774
|
+
if (keyspaceEquals(definition.sourceKeyspace, this.metadataKeyspace())) {
|
|
775
|
+
throw new Error("Eventing definition ".concat(definition.name, " must use a dedicated metadata keyspace distinct from its source keyspace"));
|
|
776
|
+
}
|
|
777
|
+
};
|
|
778
|
+
Eventing.prototype.assertLogicalName = function (name) {
|
|
779
|
+
if (!name || !name.trim()) {
|
|
780
|
+
throw new Error('Eventing requires a non-empty logical function name');
|
|
781
|
+
}
|
|
782
|
+
if (name.indexOf(this.prefix) === 0) {
|
|
783
|
+
throw new Error('Pass Eventing logical names, not physical namespace-prefixed names');
|
|
784
|
+
}
|
|
785
|
+
};
|
|
786
|
+
Eventing.prototype.assertStable = function (physicalName, lifecycle) {
|
|
787
|
+
if (lifecycle.transitional) {
|
|
788
|
+
throw new Error("Eventing function ".concat(physicalName, " is transitioning; wait for Couchbase to settle before reconciling it"));
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
Eventing.prototype.isDefinition = function (value) {
|
|
792
|
+
return !!value && own(value, 'name') && own(value, 'code') && own(value, 'sourceKeyspace');
|
|
793
|
+
};
|
|
794
|
+
Eventing.prototype.positiveNumber = function (value, fallback) {
|
|
795
|
+
return typeof value === 'number' && value > 0 ? value : fallback;
|
|
796
|
+
};
|
|
797
|
+
Eventing.prototype.nonNegativeNumber = function (value, fallback) {
|
|
798
|
+
return typeof value === 'number' && value >= 0 ? value : fallback;
|
|
799
|
+
};
|
|
800
|
+
return Eventing;
|
|
801
|
+
}());
|
|
802
|
+
exports.Eventing = Eventing;
|
|
803
|
+
/**
|
|
804
|
+
* Construct an Eventing control plane from a CouchSet client. The client is
|
|
805
|
+
* used only to obtain the SDK EventingFunctionManager after `ready()`.
|
|
806
|
+
*/
|
|
807
|
+
var createEventing = function (client, options) {
|
|
808
|
+
return new Eventing(client, options);
|
|
809
|
+
};
|
|
810
|
+
exports.createEventing = createEventing;
|
|
811
|
+
/** Construct an Eventing control plane around an application-owned SDK manager. */
|
|
812
|
+
var createEventingWithManager = function (options) {
|
|
813
|
+
if (!options.manager) {
|
|
814
|
+
throw new Error('createEventingWithManager requires EventingOptions.manager');
|
|
815
|
+
}
|
|
816
|
+
return new Eventing(undefined, options);
|
|
817
|
+
};
|
|
818
|
+
exports.createEventingWithManager = createEventingWithManager;
|
|
819
|
+
/** A small helper that makes Eventing definitions read as manifest declarations. */
|
|
820
|
+
var defineEventingFunction = function (definition) { return (__assign({}, definition)); };
|
|
821
|
+
exports.defineEventingFunction = defineEventingFunction;
|
|
822
|
+
//# sourceMappingURL=eventing.js.map
|