@skipruntime/core 0.0.5 → 0.0.10

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/src/index.js DELETED
@@ -1,742 +0,0 @@
1
- "use strict";
2
- /**
3
- * The @skipruntime/core package contains internal implementation detail for the Skip Framework and should not need to be used directly. See the public API exposed by the @skipruntime/helpers package.
4
- *
5
- * @packageDocumentation
6
- */
7
- var __extends = (this && this.__extends) || (function () {
8
- var extendStatics = function (d, b) {
9
- extendStatics = Object.setPrototypeOf ||
10
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
11
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
12
- return extendStatics(d, b);
13
- };
14
- return function (d, b) {
15
- if (typeof b !== "function" && b !== null)
16
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
17
- extendStatics(d, b);
18
- function __() { this.constructor = d; }
19
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
20
- };
21
- })();
22
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
23
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
24
- if (ar || !(i in from)) {
25
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
26
- ar[i] = from[i];
27
- }
28
- }
29
- return to.concat(ar || Array.prototype.slice.call(from));
30
- };
31
- Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.ToBinding = exports.ServiceInstance = exports.ServiceInstanceFactory = exports.Refs = exports.Stack = exports.Count = exports.Max = exports.Min = exports.Sum = exports.isSkManaged = exports.sk_freeze = exports.UnknownCollectionError = void 0;
33
- var json_1 = require("@skiplang/json");
34
- Object.defineProperty(exports, "sk_freeze", { enumerable: true, get: function () { return json_1.sk_freeze; } });
35
- Object.defineProperty(exports, "isSkManaged", { enumerable: true, get: function () { return json_1.isSkManaged; } });
36
- var std_1 = require("@skiplang/std");
37
- var api_1 = require("@skipruntime/api");
38
- var errors_js_1 = require("./errors.js");
39
- Object.defineProperty(exports, "UnknownCollectionError", { enumerable: true, get: function () { return errors_js_1.UnknownCollectionError; } });
40
- var binding_js_1 = require("./binding.js");
41
- var utils_js_1 = require("./utils.js");
42
- Object.defineProperty(exports, "Sum", { enumerable: true, get: function () { return utils_js_1.Sum; } });
43
- Object.defineProperty(exports, "Min", { enumerable: true, get: function () { return utils_js_1.Min; } });
44
- Object.defineProperty(exports, "Max", { enumerable: true, get: function () { return utils_js_1.Max; } });
45
- Object.defineProperty(exports, "Count", { enumerable: true, get: function () { return utils_js_1.Count; } });
46
- var Handles = /** @class */ (function () {
47
- function Handles() {
48
- this.nextID = 1;
49
- this.objects = [];
50
- this.freeIDs = [];
51
- }
52
- Handles.prototype.register = function (v) {
53
- var freeID = this.freeIDs.pop();
54
- var id = freeID !== null && freeID !== void 0 ? freeID : this.nextID++;
55
- this.objects[id] = v;
56
- return id;
57
- };
58
- Handles.prototype.get = function (id) {
59
- return this.objects[id];
60
- };
61
- Handles.prototype.apply = function (id, parameters) {
62
- var fn = this.get(id);
63
- return fn.apply(null, parameters);
64
- };
65
- Handles.prototype.deleteHandle = function (id) {
66
- var current = this.get(id);
67
- this.objects[id] = null;
68
- this.freeIDs.push(id);
69
- return current;
70
- };
71
- return Handles;
72
- }());
73
- var Stack = /** @class */ (function () {
74
- function Stack() {
75
- this.stack = [];
76
- }
77
- Stack.prototype.push = function (pointer) {
78
- this.stack.push(pointer);
79
- };
80
- Stack.prototype.get = function () {
81
- if (this.stack.length == 0)
82
- return null;
83
- return this.stack[this.stack.length - 1];
84
- };
85
- Stack.prototype.pop = function () {
86
- this.stack.pop();
87
- };
88
- return Stack;
89
- }());
90
- exports.Stack = Stack;
91
- var Refs = /** @class */ (function () {
92
- function Refs(binding, skjson, handles, needGC, runWithGC) {
93
- this.binding = binding;
94
- this.skjson = skjson;
95
- this.handles = handles;
96
- this.needGC = needGC;
97
- this.runWithGC = runWithGC;
98
- }
99
- return Refs;
100
- }());
101
- exports.Refs = Refs;
102
- var LazyCollectionImpl = /** @class */ (function (_super) {
103
- __extends(LazyCollectionImpl, _super);
104
- function LazyCollectionImpl(lazyCollection, refs) {
105
- var _this = _super.call(this) || this;
106
- _this.lazyCollection = lazyCollection;
107
- _this.refs = refs;
108
- Object.freeze(_this);
109
- return _this;
110
- }
111
- LazyCollectionImpl.prototype.getArray = function (key) {
112
- return this.refs.skjson.importJSON(this.refs.binding.SkipRuntime_LazyCollection__getArray(this.lazyCollection, this.refs.skjson.exportJSON(key)));
113
- };
114
- LazyCollectionImpl.prototype.getUnique = function (key) {
115
- var v = this.refs.skjson.importOptJSON(this.refs.binding.SkipRuntime_LazyCollection__getUnique(this.lazyCollection, this.refs.skjson.exportJSON(key)));
116
- if (v == null)
117
- throw new api_1.NonUniqueValueException();
118
- return v;
119
- };
120
- return LazyCollectionImpl;
121
- }(json_1.SkManaged));
122
- var EagerCollectionImpl = /** @class */ (function (_super) {
123
- __extends(EagerCollectionImpl, _super);
124
- function EagerCollectionImpl(collection, refs) {
125
- var _this = _super.call(this) || this;
126
- _this.collection = collection;
127
- _this.refs = refs;
128
- _this.size = function () {
129
- return Number(_this.refs.binding.SkipRuntime_Collection__size(_this.collection));
130
- };
131
- Object.freeze(_this);
132
- return _this;
133
- }
134
- EagerCollectionImpl.prototype.getArray = function (key) {
135
- return this.refs.skjson.importJSON(this.refs.binding.SkipRuntime_Collection__getArray(this.collection, this.refs.skjson.exportJSON(key)));
136
- };
137
- EagerCollectionImpl.prototype.getUnique = function (key) {
138
- var v = this.refs.skjson.importOptJSON(this.refs.binding.SkipRuntime_Collection__getUnique(this.collection, this.refs.skjson.exportJSON(key)));
139
- if (v == null)
140
- throw new api_1.NonUniqueValueException();
141
- return v;
142
- };
143
- EagerCollectionImpl.prototype.slice = function (start, end) {
144
- return this.slices([start, end]);
145
- };
146
- EagerCollectionImpl.prototype.slices = function () {
147
- var ranges = [];
148
- for (var _i = 0; _i < arguments.length; _i++) {
149
- ranges[_i] = arguments[_i];
150
- }
151
- var skcollection = this.refs.binding.SkipRuntime_Collection__slice(this.collection, this.refs.skjson.exportJSON(ranges));
152
- return this.derive(skcollection);
153
- };
154
- EagerCollectionImpl.prototype.take = function (limit) {
155
- var skcollection = this.refs.binding.SkipRuntime_Collection__take(this.collection, BigInt(limit));
156
- return this.derive(skcollection);
157
- };
158
- EagerCollectionImpl.prototype.map = function (mapper) {
159
- var params = [];
160
- for (var _i = 1; _i < arguments.length; _i++) {
161
- params[_i - 1] = arguments[_i];
162
- }
163
- var mapperParams = params.map(json_1.checkOrCloneParam);
164
- var mapperObj = new (mapper.bind.apply(mapper, __spreadArray([void 0], mapperParams, false)))();
165
- Object.freeze(mapperObj);
166
- if (!mapperObj.constructor.name) {
167
- throw new Error("Mapper classes must be defined at top-level.");
168
- }
169
- var skmapper = this.refs.binding.SkipRuntime_createMapper(this.refs.handles.register(mapperObj));
170
- var mapped = this.refs.binding.SkipRuntime_Collection__map(this.collection, skmapper);
171
- return this.derive(mapped);
172
- };
173
- EagerCollectionImpl.prototype.mapReduce = function (mapper) {
174
- var _this = this;
175
- var mapperParams = [];
176
- for (var _i = 1; _i < arguments.length; _i++) {
177
- mapperParams[_i - 1] = arguments[_i];
178
- }
179
- return function (reducer) {
180
- var reducerParams = [];
181
- for (var _i = 1; _i < arguments.length; _i++) {
182
- reducerParams[_i - 1] = arguments[_i];
183
- }
184
- var mParams = mapperParams.map(json_1.checkOrCloneParam);
185
- var rParams = reducerParams.map(json_1.checkOrCloneParam);
186
- var mapperObj = new (mapper.bind.apply(mapper, __spreadArray([void 0], mParams, false)))();
187
- var reducerObj = new (reducer.bind.apply(reducer, __spreadArray([void 0], rParams, false)))();
188
- Object.freeze(mapperObj);
189
- Object.freeze(reducerObj);
190
- if (!mapperObj.constructor.name) {
191
- throw new Error("Mapper classes must be defined at top-level.");
192
- }
193
- if (!reducerObj.constructor.name) {
194
- throw new Error("Reducer classes must be defined at top-level.");
195
- }
196
- var skmapper = _this.refs.binding.SkipRuntime_createMapper(_this.refs.handles.register(mapperObj));
197
- if (std_1.sknative in reducerObj && typeof reducerObj[std_1.sknative] == "string") {
198
- return _this.derive(_this.refs.binding.SkipRuntime_Collection__nativeMapReduce(_this.collection, skmapper, reducerObj[std_1.sknative]));
199
- }
200
- else {
201
- var skreducer = _this.refs.binding.SkipRuntime_createReducer(_this.refs.handles.register(reducerObj), _this.refs.skjson.exportJSON(reducerObj.initial));
202
- return _this.derive(_this.refs.binding.SkipRuntime_Collection__mapReduce(_this.collection, skmapper, skreducer));
203
- }
204
- };
205
- };
206
- EagerCollectionImpl.prototype.reduce = function (reducer) {
207
- var params = [];
208
- for (var _i = 1; _i < arguments.length; _i++) {
209
- params[_i - 1] = arguments[_i];
210
- }
211
- var reducerParams = params.map(json_1.checkOrCloneParam);
212
- var reducerObj = new (reducer.bind.apply(reducer, __spreadArray([void 0], reducerParams, false)))();
213
- Object.freeze(reducerObj);
214
- if (!reducerObj.constructor.name) {
215
- throw new Error("Reducer classes must be defined at top-level.");
216
- }
217
- if (std_1.sknative in reducerObj && typeof reducerObj[std_1.sknative] == "string") {
218
- return this.derive(this.refs.binding.SkipRuntime_Collection__nativeReduce(this.collection, reducerObj[std_1.sknative]));
219
- }
220
- else {
221
- var skreducer = this.refs.binding.SkipRuntime_createReducer(this.refs.handles.register(reducerObj), this.refs.skjson.exportJSON(reducerObj.initial));
222
- return this.derive(this.refs.binding.SkipRuntime_Collection__reduce(this.collection, skreducer));
223
- }
224
- };
225
- EagerCollectionImpl.prototype.merge = function () {
226
- var others = [];
227
- for (var _i = 0; _i < arguments.length; _i++) {
228
- others[_i] = arguments[_i];
229
- }
230
- var otherNames = others.map(function (other) { return other.collection; });
231
- var mapped = this.refs.binding.SkipRuntime_Collection__merge(this.collection, this.refs.skjson.exportJSON(otherNames));
232
- return this.derive(mapped);
233
- };
234
- EagerCollectionImpl.prototype.derive = function (collection) {
235
- return new EagerCollectionImpl(collection, this.refs);
236
- };
237
- return EagerCollectionImpl;
238
- }(json_1.SkManaged));
239
- var CollectionWriter = /** @class */ (function () {
240
- function CollectionWriter(collection, refs) {
241
- this.collection = collection;
242
- this.refs = refs;
243
- }
244
- CollectionWriter.prototype.update = function (values, isInit) {
245
- var _this = this;
246
- var update_ = function () {
247
- return _this.refs.binding.SkipRuntime_CollectionWriter__update(_this.collection, _this.refs.skjson.exportJSON(values), isInit);
248
- };
249
- if (this.refs.needGC()) {
250
- this.refs.runWithGC(update_);
251
- }
252
- else {
253
- update_();
254
- }
255
- };
256
- CollectionWriter.prototype.loading = function () {
257
- var _this = this;
258
- var loading_ = function () {
259
- return _this.refs.binding.SkipRuntime_CollectionWriter__loading(_this.collection);
260
- };
261
- if (this.refs.needGC())
262
- this.refs.runWithGC(loading_);
263
- else
264
- loading_();
265
- };
266
- CollectionWriter.prototype.error = function (error) {
267
- var _this = this;
268
- var error_ = function () {
269
- return _this.refs.binding.SkipRuntime_CollectionWriter__error(_this.collection, _this.refs.skjson.exportJSON(error));
270
- };
271
- if (this.refs.needGC())
272
- this.refs.runWithGC(error_);
273
- else
274
- error_();
275
- };
276
- return CollectionWriter;
277
- }());
278
- var ContextImpl = /** @class */ (function (_super) {
279
- __extends(ContextImpl, _super);
280
- function ContextImpl(refs) {
281
- var _this = _super.call(this) || this;
282
- _this.refs = refs;
283
- Object.freeze(_this);
284
- return _this;
285
- }
286
- ContextImpl.prototype.createLazyCollection = function (compute) {
287
- var params = [];
288
- for (var _i = 1; _i < arguments.length; _i++) {
289
- params[_i - 1] = arguments[_i];
290
- }
291
- var mapperParams = params.map(json_1.checkOrCloneParam);
292
- var computeObj = new (compute.bind.apply(compute, __spreadArray([void 0], mapperParams, false)))();
293
- Object.freeze(computeObj);
294
- if (!computeObj.constructor.name) {
295
- throw new Error("LazyCompute classes must be defined at top-level.");
296
- }
297
- var skcompute = this.refs.binding.SkipRuntime_createLazyCompute(this.refs.handles.register(computeObj));
298
- var lazyCollection = this.refs.binding.SkipRuntime_Context__createLazyCollection(skcompute);
299
- return new LazyCollectionImpl(lazyCollection, this.refs);
300
- };
301
- ContextImpl.prototype.useExternalResource = function (resource) {
302
- var _a;
303
- var collection = this.refs.binding.SkipRuntime_Context__useExternalResource(resource.service, resource.identifier, this.refs.skjson.exportJSON((_a = resource.params) !== null && _a !== void 0 ? _a : {}));
304
- return new EagerCollectionImpl(collection, this.refs);
305
- };
306
- ContextImpl.prototype.jsonExtract = function (value, pattern) {
307
- return this.refs.skjson.importJSON(this.refs.binding.SkipRuntime_Context__jsonExtract(this.refs.skjson.exportJSON(value), pattern));
308
- };
309
- return ContextImpl;
310
- }(json_1.SkManaged));
311
- var ServiceInstanceFactory = /** @class */ (function () {
312
- function ServiceInstanceFactory(init) {
313
- this.init = init;
314
- }
315
- ServiceInstanceFactory.prototype.initService = function (service) {
316
- return this.init(service);
317
- };
318
- return ServiceInstanceFactory;
319
- }());
320
- exports.ServiceInstanceFactory = ServiceInstanceFactory;
321
- var AllChecker = /** @class */ (function () {
322
- function AllChecker(service, executor, resource, params) {
323
- this.service = service;
324
- this.executor = executor;
325
- this.resource = resource;
326
- this.params = params;
327
- }
328
- AllChecker.prototype.check = function (request) {
329
- var result = this.service.getAll(this.resource, this.params, request);
330
- if (result.errors.length > 0) {
331
- this.executor.reject(new Error(JSON.stringify(result.errors)));
332
- }
333
- else {
334
- this.executor.resolve(result.payload);
335
- }
336
- };
337
- return AllChecker;
338
- }());
339
- var OneChecker = /** @class */ (function () {
340
- function OneChecker(service, executor, resource, params, key) {
341
- this.service = service;
342
- this.executor = executor;
343
- this.resource = resource;
344
- this.params = params;
345
- this.key = key;
346
- }
347
- OneChecker.prototype.check = function (request) {
348
- var result = this.service.getArray(this.resource, this.key, this.params, request);
349
- if (result.errors.length > 0) {
350
- this.executor.reject(new Error(JSON.stringify(result.errors)));
351
- }
352
- else {
353
- this.executor.resolve(result.payload);
354
- }
355
- };
356
- return OneChecker;
357
- }());
358
- /**
359
- * A `ServiceInstance` is a running instance of a `SkipService`, providing access to its resources
360
- * and operations to manage susbscriptions and the service itself.
361
- */
362
- var ServiceInstance = /** @class */ (function () {
363
- function ServiceInstance(refs) {
364
- this.refs = refs;
365
- }
366
- /**
367
- * Instantiate a resource with some parameters and client session authentication token
368
- * @param identifier - The resource instance identifier
369
- * @param resource - A resource name, which must correspond to a key in this `SkipService`'s `resources` field
370
- * @param params - Resource parameters, which will be passed to the resource constructor specified in this `SkipService`'s `resources` field
371
- */
372
- ServiceInstance.prototype.instantiateResource = function (identifier, resource, params) {
373
- var _this = this;
374
- var errorHdl = this.refs.runWithGC(function () {
375
- return _this.refs.binding.SkipRuntime_Runtime__createResource(identifier, resource, _this.refs.skjson.exportJSON(params));
376
- });
377
- if (errorHdl)
378
- throw this.refs.handles.deleteHandle(errorHdl);
379
- };
380
- /**
381
- * Creates if not exists and get all current values of specified resource
382
- * @param resource - the resource name corresponding to a key in remotes field of SkipService
383
- * @param params - the parameters of the resource used to build the resource with the corresponding constructor specified in remotes field of SkipService
384
- * @returns The current values of the corresponding resource with reactive responce token to allow subscription
385
- */
386
- ServiceInstance.prototype.getAll = function (resource, params, request) {
387
- var _this = this;
388
- if (params === void 0) { params = {}; }
389
- var get_ = function () {
390
- return _this.refs.skjson.importJSON(_this.refs.binding.SkipRuntime_Runtime__getAll(resource, _this.refs.skjson.exportJSON(params), request !== undefined
391
- ? typeof request == "string"
392
- ? _this.refs.binding.SkipRuntime_createIdentifier(request)
393
- : _this.refs.binding.SkipRuntime_createChecker(_this.refs.handles.register(new AllChecker(_this, request, resource, params)))
394
- : null), true);
395
- };
396
- var result = this.refs.needGC() ? this.refs.runWithGC(get_) : get_();
397
- if (typeof result == "number")
398
- throw this.refs.handles.deleteHandle(result);
399
- return result;
400
- };
401
- /**
402
- * Get the current value of a key in the specified resource instance, creating it if it doesn't already exist
403
- * @param resource - A resource name, which must correspond to a key in this `SkipService`'s `resources` field
404
- * @param key - A key to look up in the resource instance
405
- * @param params - Resource parameters, passed to the resource constructor specified in this `SkipService`'s `resources` field
406
- * @returns The current value(s) for this key in the specified resource instance
407
- */
408
- ServiceInstance.prototype.getArray = function (resource, key, params, request) {
409
- var _this = this;
410
- if (params === void 0) { params = {}; }
411
- var get_ = function () {
412
- return _this.refs.skjson.importJSON(_this.refs.binding.SkipRuntime_Runtime__getForKey(resource, _this.refs.skjson.exportJSON(params), _this.refs.skjson.exportJSON(key), request !== undefined
413
- ? typeof request == "string"
414
- ? _this.refs.binding.SkipRuntime_createIdentifier(request)
415
- : _this.refs.binding.SkipRuntime_createChecker(_this.refs.handles.register(new OneChecker(_this, request, resource, params, key)))
416
- : null), true);
417
- };
418
- var needGC = this.refs.needGC();
419
- var result = needGC ? this.refs.runWithGC(get_) : get_();
420
- if (typeof result == "number")
421
- throw this.refs.handles.deleteHandle(result);
422
- return result;
423
- };
424
- /**
425
- * Close the specified resource instance
426
- * @param resourceInstanceId - The resource identifier
427
- */
428
- ServiceInstance.prototype.closeResourceInstance = function (resourceInstanceId) {
429
- var _this = this;
430
- var errorHdl = this.refs.runWithGC(function () {
431
- return _this.refs.binding.SkipRuntime_Runtime__closeResource(resourceInstanceId);
432
- });
433
- if (errorHdl)
434
- throw this.refs.handles.deleteHandle(errorHdl);
435
- };
436
- /**
437
- * Initiate reactive subscription on a resource instance
438
- * @param resourceInstanceId - the resource instance identifier
439
- * @param notifier - the object containing subscription callbacks
440
- * @param notifier.subscribed - A callback to execute when subscription effectivly done
441
- * @param notifier.notify - A callback to execute on collection updates
442
- * @param notifier.close - A callback to execute on resource close
443
- * @param watermark - the watermark where to start the subscription
444
- * @returns A subcription identifier
445
- */
446
- ServiceInstance.prototype.subscribe = function (resourceInstanceId, notifier, watermark) {
447
- var _this = this;
448
- var session = this.refs.runWithGC(function () {
449
- var sknotifier = _this.refs.binding.SkipRuntime_createNotifier(_this.refs.handles.register(notifier));
450
- return _this.refs.binding.SkipRuntime_Runtime__subscribe(resourceInstanceId, sknotifier, watermark !== null && watermark !== void 0 ? watermark : null);
451
- });
452
- if (session == -1n) {
453
- throw new errors_js_1.UnknownCollectionError("Unknown resource instance '".concat(resourceInstanceId, "'"));
454
- }
455
- else if (session < 0n) {
456
- throw new Error("Unknown error");
457
- }
458
- return session;
459
- };
460
- /**
461
- * Terminate a client's subscription to a reactive resource instance
462
- * @param id - The subcription identifier returned by a call to `subscribe`
463
- */
464
- ServiceInstance.prototype.unsubscribe = function (id) {
465
- var _this = this;
466
- var errorHdl = this.refs.runWithGC(function () {
467
- return _this.refs.binding.SkipRuntime_Runtime__unsubscribe(id);
468
- });
469
- if (errorHdl) {
470
- throw this.refs.handles.deleteHandle(errorHdl);
471
- }
472
- };
473
- /**
474
- * Update an input collection
475
- * @param collection - the name of the input collection to update
476
- * @param entries - entries to update in the collection.
477
- */
478
- ServiceInstance.prototype.update = function (collection, entries) {
479
- var _this = this;
480
- var errorHdl = this.refs.runWithGC(function () {
481
- return _this.refs.binding.SkipRuntime_Runtime__update(collection, _this.refs.skjson.exportJSON(entries));
482
- });
483
- if (errorHdl) {
484
- throw this.refs.handles.deleteHandle(errorHdl);
485
- }
486
- };
487
- /**
488
- * Close all resources and shut down the service.
489
- * Any subsequent calls on the service will result in errors.
490
- */
491
- ServiceInstance.prototype.close = function () {
492
- var _this = this;
493
- var errorHdl = this.refs.runWithGC(function () {
494
- return _this.refs.binding.SkipRuntime_closeService();
495
- });
496
- if (errorHdl) {
497
- throw this.refs.handles.deleteHandle(errorHdl);
498
- }
499
- };
500
- return ServiceInstance;
501
- }());
502
- exports.ServiceInstance = ServiceInstance;
503
- var ValuesImpl = /** @class */ (function () {
504
- function ValuesImpl(skjson, binding, pointer) {
505
- var _this = this;
506
- this.skjson = skjson;
507
- this.binding = binding;
508
- this.pointer = pointer;
509
- this.toArray = function () {
510
- return Array.from(_this);
511
- };
512
- this.skjson = skjson;
513
- this.binding = binding;
514
- this.pointer = pointer;
515
- }
516
- ValuesImpl.prototype.next = function () {
517
- return this.skjson.importOptJSON(this.binding.SkipRuntime_NonEmptyIterator__next(this.pointer));
518
- };
519
- ValuesImpl.prototype.getUnique = function () {
520
- var value = this.skjson.importOptJSON(this.binding.SkipRuntime_NonEmptyIterator__uniqueValue(this.pointer));
521
- if (value == null)
522
- throw new api_1.NonUniqueValueException();
523
- return value;
524
- };
525
- ValuesImpl.prototype[Symbol.iterator] = function () {
526
- var cloned_iter = new ValuesImpl(this.skjson, this.binding, this.binding.SkipRuntime_NonEmptyIterator__clone(this.pointer));
527
- return {
528
- next: function () {
529
- var value = cloned_iter.next();
530
- return { value: value, done: value == null };
531
- },
532
- };
533
- };
534
- return ValuesImpl;
535
- }());
536
- var ToBinding = /** @class */ (function () {
537
- function ToBinding(binding, runWithGC, getConverter, getError) {
538
- this.binding = binding;
539
- this.runWithGC = runWithGC;
540
- this.getConverter = getConverter;
541
- this.getError = getError;
542
- this.stack = new Stack();
543
- this.handles = new Handles();
544
- }
545
- ToBinding.prototype.register = function (v) {
546
- return this.handles.register(v);
547
- };
548
- ToBinding.prototype.deleteHandle = function (id) {
549
- return this.handles.deleteHandle(id);
550
- };
551
- ToBinding.prototype.SkipRuntime_getErrorHdl = function (exn) {
552
- return this.handles.register(this.getError(exn));
553
- };
554
- ToBinding.prototype.SkipRuntime_pushContext = function (context) {
555
- this.stack.push(context);
556
- };
557
- ToBinding.prototype.SkipRuntime_popContext = function () {
558
- this.stack.pop();
559
- };
560
- ToBinding.prototype.SkipRuntime_getContext = function () {
561
- return this.stack.get();
562
- };
563
- // Mapper
564
- ToBinding.prototype.SkipRuntime_Mapper__mapEntry = function (skmapper, key, values) {
565
- var skjson = this.getJsonConverter();
566
- var mapper = this.handles.get(skmapper);
567
- var result = mapper.mapEntry(skjson.importJSON(key), new ValuesImpl(skjson, this.binding, values));
568
- return skjson.exportJSON(Array.from(result));
569
- };
570
- ToBinding.prototype.SkipRuntime_deleteMapper = function (mapper) {
571
- this.handles.deleteHandle(mapper);
572
- };
573
- // LazyCompute
574
- ToBinding.prototype.SkipRuntime_LazyCompute__compute = function (sklazyCompute, self, skkey) {
575
- var skjson = this.getJsonConverter();
576
- var lazyCompute = this.handles.get(sklazyCompute);
577
- var result = lazyCompute.compute(new LazyCollectionImpl(self, this.refs()), skjson.importJSON(skkey));
578
- return skjson.exportJSON(Array.from(result));
579
- };
580
- ToBinding.prototype.SkipRuntime_deleteLazyCompute = function (lazyCompute) {
581
- this.handles.deleteHandle(lazyCompute);
582
- };
583
- // Resource
584
- ToBinding.prototype.SkipRuntime_Resource__instantiate = function (skresource, skcollections) {
585
- var skjson = this.getJsonConverter();
586
- var resource = this.handles.get(skresource);
587
- var collections = {};
588
- var keysIds = skjson.importJSON(skcollections);
589
- var refs = this.refs();
590
- for (var _i = 0, _a = Object.entries(keysIds); _i < _a.length; _i++) {
591
- var _b = _a[_i], key = _b[0], name_1 = _b[1];
592
- collections[key] = new EagerCollectionImpl(name_1, refs);
593
- }
594
- var collection = resource.instantiate(collections, new ContextImpl(refs));
595
- return collection.collection;
596
- };
597
- ToBinding.prototype.SkipRuntime_deleteResource = function (resource) {
598
- this.handles.deleteHandle(resource);
599
- };
600
- // ResourceBuilder
601
- ToBinding.prototype.SkipRuntime_ResourceBuilder__build = function (skbuilder, skparams) {
602
- var skjson = this.getJsonConverter();
603
- var builder = this.handles.get(skbuilder);
604
- var resource = builder.build(skjson.importJSON(skparams));
605
- return this.binding.SkipRuntime_createResource(this.handles.register(resource));
606
- };
607
- ToBinding.prototype.SkipRuntime_deleteResourceBuilder = function (builder) {
608
- this.handles.deleteHandle(builder);
609
- };
610
- // Service
611
- ToBinding.prototype.SkipRuntime_Service__createGraph = function (skservice, skcollections) {
612
- var skjson = this.getJsonConverter();
613
- var service = this.handles.get(skservice);
614
- var collections = {};
615
- var keysIds = skjson.importJSON(skcollections);
616
- var refs = this.refs();
617
- for (var _i = 0, _a = Object.entries(keysIds); _i < _a.length; _i++) {
618
- var _b = _a[_i], key = _b[0], name_2 = _b[1];
619
- collections[key] = new EagerCollectionImpl(name_2, refs);
620
- }
621
- var result = service.createGraph(collections, new ContextImpl(refs));
622
- var collectionsNames = {};
623
- for (var _c = 0, _d = Object.entries(result); _c < _d.length; _c++) {
624
- var _e = _d[_c], name_3 = _e[0], collection = _e[1];
625
- collectionsNames[name_3] = collection.collection;
626
- }
627
- return skjson.exportJSON(collectionsNames);
628
- };
629
- ToBinding.prototype.SkipRuntime_deleteService = function (service) {
630
- this.handles.deleteHandle(service);
631
- };
632
- // Notifier
633
- ToBinding.prototype.SkipRuntime_Notifier__subscribed = function (sknotifier) {
634
- var notifier = this.handles.get(sknotifier);
635
- notifier.subscribed();
636
- };
637
- ToBinding.prototype.SkipRuntime_Notifier__notify = function (sknotifier, skvalues, watermark, isUpdates) {
638
- var skjson = this.getJsonConverter();
639
- var notifier = this.handles.get(sknotifier);
640
- var values = skjson.importJSON(skvalues, true);
641
- var isInitial = isUpdates ? false : true;
642
- notifier.notify({
643
- values: values,
644
- watermark: watermark,
645
- isInitial: isInitial,
646
- });
647
- };
648
- ToBinding.prototype.SkipRuntime_Notifier__close = function (sknotifier) {
649
- var notifier = this.handles.get(sknotifier);
650
- notifier.close();
651
- };
652
- ToBinding.prototype.SkipRuntime_deleteNotifier = function (notifier) {
653
- this.handles.deleteHandle(notifier);
654
- };
655
- // Reducer
656
- ToBinding.prototype.SkipRuntime_Reducer__add = function (skreducer, skacc, skvalue) {
657
- var skjson = this.getJsonConverter();
658
- var reducer = this.handles.get(skreducer);
659
- return skjson.exportJSON(reducer.add(skacc ? skjson.importJSON(skacc) : null, skjson.importJSON(skvalue)));
660
- };
661
- ToBinding.prototype.SkipRuntime_Reducer__remove = function (skreducer, skacc, skvalue) {
662
- var skjson = this.getJsonConverter();
663
- var reducer = this.handles.get(skreducer);
664
- return skjson.exportJSON(reducer.remove(skjson.importJSON(skacc), skjson.importJSON(skvalue)));
665
- };
666
- ToBinding.prototype.SkipRuntime_deleteReducer = function (reducer) {
667
- this.handles.deleteHandle(reducer);
668
- };
669
- // ExternalService
670
- ToBinding.prototype.SkipRuntime_ExternalService__subscribe = function (sksupplier, writerId, resource, skparams) {
671
- var skjson = this.getJsonConverter();
672
- var supplier = this.handles.get(sksupplier);
673
- var writer = new CollectionWriter(writerId, this.refs());
674
- var params = skjson.importJSON(skparams, true);
675
- supplier.subscribe(resource, params, {
676
- update: writer.update.bind(writer),
677
- error: writer.error.bind(writer),
678
- loading: writer.loading.bind(writer),
679
- });
680
- };
681
- ToBinding.prototype.SkipRuntime_ExternalService__unsubscribe = function (sksupplier, resource, skparams) {
682
- var skjson = this.getJsonConverter();
683
- var supplier = this.handles.get(sksupplier);
684
- var params = skjson.importJSON(skparams, true);
685
- supplier.unsubscribe(resource, params);
686
- };
687
- ToBinding.prototype.SkipRuntime_ExternalService__shutdown = function (sksupplier) {
688
- var supplier = this.handles.get(sksupplier);
689
- supplier.shutdown();
690
- };
691
- ToBinding.prototype.SkipRuntime_deleteExternalService = function (supplier) {
692
- this.handles.deleteHandle(supplier);
693
- };
694
- // Checker
695
- ToBinding.prototype.SkipRuntime_Checker__check = function (skchecker, request) {
696
- var checker = this.handles.get(skchecker);
697
- checker.check(request);
698
- };
699
- ToBinding.prototype.SkipRuntime_deleteChecker = function (checker) {
700
- this.handles.deleteHandle(checker);
701
- };
702
- ToBinding.prototype.initService = function (service) {
703
- var refs = this.refs();
704
- var errorHdl = refs.runWithGC(function () {
705
- var _a;
706
- var skExternalServices = refs.binding.SkipRuntime_ExternalServiceMap__create();
707
- if (service.externalServices) {
708
- for (var _i = 0, _b = Object.entries(service.externalServices); _i < _b.length; _i++) {
709
- var _c = _b[_i], name_4 = _c[0], remote = _c[1];
710
- var skremote = refs.binding.SkipRuntime_createExternalService(refs.handles.register(remote));
711
- refs.binding.SkipRuntime_ExternalServiceMap__add(skExternalServices, name_4, skremote);
712
- }
713
- }
714
- var skresources = refs.binding.SkipRuntime_ResourceBuilderMap__create();
715
- for (var _d = 0, _e = Object.entries(service.resources); _d < _e.length; _d++) {
716
- var _f = _e[_d], name_5 = _f[0], builder = _f[1];
717
- var skbuilder = refs.binding.SkipRuntime_createResourceBuilder(refs.handles.register(new binding_js_1.ResourceBuilder(builder)));
718
- refs.binding.SkipRuntime_ResourceBuilderMap__add(skresources, name_5, skbuilder);
719
- }
720
- var skservice = refs.binding.SkipRuntime_createService(refs.handles.register(service), refs.skjson.exportJSON((_a = service.initialData) !== null && _a !== void 0 ? _a : {}), skresources, skExternalServices);
721
- return refs.binding.SkipRuntime_initService(skservice);
722
- });
723
- if (errorHdl)
724
- throw refs.handles.deleteHandle(errorHdl);
725
- return new ServiceInstance(refs);
726
- };
727
- //
728
- ToBinding.prototype.getJsonConverter = function () {
729
- if (this.skjson == undefined) {
730
- this.skjson = this.getConverter();
731
- }
732
- return this.skjson;
733
- };
734
- ToBinding.prototype.needGC = function () {
735
- return this.SkipRuntime_getContext() == null;
736
- };
737
- ToBinding.prototype.refs = function () {
738
- return new Refs(this.binding, this.getConverter(), this.handles, this.needGC.bind(this), this.runWithGC);
739
- };
740
- return ToBinding;
741
- }());
742
- exports.ToBinding = ToBinding;