@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/README.md +20 -0
- package/dist/api.d.ts +561 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +75 -0
- package/dist/api.js.map +1 -0
- package/dist/binding.d.ts +1 -1
- package/dist/binding.d.ts.map +1 -1
- package/dist/binding.js +1 -1
- package/dist/binding.js.map +1 -1
- package/dist/errors.d.ts +46 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +46 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +54 -43
- package/dist/index.js.map +1 -1
- package/dist/utils.d.ts +2 -3
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/api.ts +665 -0
- package/src/binding.ts +1 -1
- package/src/errors.ts +46 -1
- package/src/index.ts +74 -48
- package/src/utils.ts +2 -3
- package/src/binding.js +0 -14
- package/src/errors.js +0 -26
- package/src/index.js +0 -742
- package/src/internal.js +0 -2
- package/src/utils.js +0 -57
package/src/errors.ts
CHANGED
|
@@ -1 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Umbrella type for run-time errors thrown by the Skip runtime.
|
|
3
|
+
* @hideconstructor
|
|
4
|
+
*/
|
|
5
|
+
export class SkipError extends Error {}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Exception indicating an attempted read/write to a collection that does not exist.
|
|
9
|
+
* @hideconstructor
|
|
10
|
+
*/
|
|
11
|
+
export class SkipUnknownCollectionError extends SkipError {}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Exception indicating an attempted read/write to a resource that does not exist.
|
|
15
|
+
* @hideconstructor
|
|
16
|
+
*/
|
|
17
|
+
export class SkipUnknownResourceError extends SkipError {}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Exception indicating a malformed REST query to a Skip service.
|
|
21
|
+
* @hideconstructor
|
|
22
|
+
*/
|
|
23
|
+
export class SkipRESTError extends SkipError {}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Exception indicating that a fetch returned an HTTP status outside of the 200-299 range.
|
|
27
|
+
* @hideconstructor
|
|
28
|
+
*/
|
|
29
|
+
export class SkipFetchError extends SkipError {}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Exception indicating a non-top-level class being used as a mapper/reducer/etc.
|
|
33
|
+
*
|
|
34
|
+
* The Skip runtime requires that these classes be defined at the top-level, so that their names can be used to generate cache keys and the like.
|
|
35
|
+
* @hideconstructor
|
|
36
|
+
*/
|
|
37
|
+
export class SkipClassNameError extends SkipError {}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Exception indicating a key did not have a unique value.
|
|
41
|
+
*
|
|
42
|
+
* Some collections are used to associate each key to a unique value.
|
|
43
|
+
* When this expectation is not met (a key is associated to either zero or multiple values), operations such as `getUnique` throw `SkipNonUniqueValueError`.
|
|
44
|
+
* @hideconstructor
|
|
45
|
+
*/
|
|
46
|
+
export class SkipNonUniqueValueError extends SkipError {}
|
package/src/index.ts
CHANGED
|
@@ -23,7 +23,6 @@ import { sknative } from "@skiplang/std";
|
|
|
23
23
|
|
|
24
24
|
import type * as Internal from "./internal.js";
|
|
25
25
|
import {
|
|
26
|
-
NonUniqueValueException,
|
|
27
26
|
type CollectionUpdate,
|
|
28
27
|
type Context,
|
|
29
28
|
type EagerCollection,
|
|
@@ -39,9 +38,14 @@ import {
|
|
|
39
38
|
type Resource,
|
|
40
39
|
type SkipService,
|
|
41
40
|
type Watermark,
|
|
42
|
-
} from "
|
|
41
|
+
} from "./api.js";
|
|
43
42
|
|
|
44
|
-
import {
|
|
43
|
+
import {
|
|
44
|
+
SkipClassNameError,
|
|
45
|
+
SkipError,
|
|
46
|
+
SkipNonUniqueValueError,
|
|
47
|
+
SkipUnknownCollectionError,
|
|
48
|
+
} from "./errors.js";
|
|
45
49
|
import {
|
|
46
50
|
ResourceBuilder,
|
|
47
51
|
type Notifier,
|
|
@@ -50,8 +54,10 @@ import {
|
|
|
50
54
|
type FromBinding,
|
|
51
55
|
} from "./binding.js";
|
|
52
56
|
|
|
53
|
-
export {
|
|
57
|
+
export { sk_freeze, isSkManaged };
|
|
54
58
|
export { Sum, Min, Max, Count } from "./utils.js";
|
|
59
|
+
export * from "./api.js";
|
|
60
|
+
export * from "./errors.js";
|
|
55
61
|
|
|
56
62
|
export type JSONMapper = Mapper<Json, Json, Json, Json>;
|
|
57
63
|
export type JSONLazyCompute = LazyCompute<Json, Json>;
|
|
@@ -140,7 +146,7 @@ class LazyCollectionImpl<K extends Json, V extends Json>
|
|
|
140
146
|
this.refs.skjson.exportJSON(key),
|
|
141
147
|
),
|
|
142
148
|
) as Nullable<V & DepSafe>;
|
|
143
|
-
if (v == null) throw new
|
|
149
|
+
if (v == null) throw new SkipNonUniqueValueError();
|
|
144
150
|
return v;
|
|
145
151
|
}
|
|
146
152
|
}
|
|
@@ -173,7 +179,7 @@ class EagerCollectionImpl<K extends Json, V extends Json>
|
|
|
173
179
|
this.refs.skjson.exportJSON(key),
|
|
174
180
|
),
|
|
175
181
|
) as Nullable<V & DepSafe>;
|
|
176
|
-
if (v == null) throw new
|
|
182
|
+
if (v == null) throw new SkipNonUniqueValueError();
|
|
177
183
|
return v;
|
|
178
184
|
}
|
|
179
185
|
|
|
@@ -211,7 +217,9 @@ class EagerCollectionImpl<K extends Json, V extends Json>
|
|
|
211
217
|
const mapperObj = new mapper(...mapperParams);
|
|
212
218
|
Object.freeze(mapperObj);
|
|
213
219
|
if (!mapperObj.constructor.name) {
|
|
214
|
-
throw new
|
|
220
|
+
throw new SkipClassNameError(
|
|
221
|
+
"Mapper classes must be defined at top-level.",
|
|
222
|
+
);
|
|
215
223
|
}
|
|
216
224
|
const skmapper = this.refs.binding.SkipRuntime_createMapper(
|
|
217
225
|
this.refs.handles.register(mapperObj),
|
|
@@ -241,10 +249,14 @@ class EagerCollectionImpl<K extends Json, V extends Json>
|
|
|
241
249
|
Object.freeze(reducerObj);
|
|
242
250
|
|
|
243
251
|
if (!mapperObj.constructor.name) {
|
|
244
|
-
throw new
|
|
252
|
+
throw new SkipClassNameError(
|
|
253
|
+
"Mapper classes must be defined at top-level.",
|
|
254
|
+
);
|
|
245
255
|
}
|
|
246
256
|
if (!reducerObj.constructor.name) {
|
|
247
|
-
throw new
|
|
257
|
+
throw new SkipClassNameError(
|
|
258
|
+
"Reducer classes must be defined at top-level.",
|
|
259
|
+
);
|
|
248
260
|
}
|
|
249
261
|
|
|
250
262
|
const skmapper = this.refs.binding.SkipRuntime_createMapper(
|
|
@@ -283,7 +295,9 @@ class EagerCollectionImpl<K extends Json, V extends Json>
|
|
|
283
295
|
const reducerObj = new reducer(...reducerParams);
|
|
284
296
|
Object.freeze(reducerObj);
|
|
285
297
|
if (!reducerObj.constructor.name) {
|
|
286
|
-
throw new
|
|
298
|
+
throw new SkipClassNameError(
|
|
299
|
+
"Reducer classes must be defined at top-level.",
|
|
300
|
+
);
|
|
287
301
|
}
|
|
288
302
|
if (sknative in reducerObj && typeof reducerObj[sknative] == "string") {
|
|
289
303
|
return this.derive<K, Accum>(
|
|
@@ -338,11 +352,11 @@ class CollectionWriter<K extends Json, V extends Json> {
|
|
|
338
352
|
isInit,
|
|
339
353
|
);
|
|
340
354
|
};
|
|
341
|
-
|
|
342
|
-
this.refs.runWithGC(update_)
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
355
|
+
const errorHdl = this.refs.needGC()
|
|
356
|
+
? this.refs.runWithGC(update_)
|
|
357
|
+
: update_();
|
|
358
|
+
|
|
359
|
+
if (errorHdl) throw this.refs.handles.deleteHandle(errorHdl);
|
|
346
360
|
}
|
|
347
361
|
|
|
348
362
|
loading(): void {
|
|
@@ -351,8 +365,10 @@ class CollectionWriter<K extends Json, V extends Json> {
|
|
|
351
365
|
this.collection,
|
|
352
366
|
);
|
|
353
367
|
};
|
|
354
|
-
|
|
355
|
-
|
|
368
|
+
const errorHdl = this.refs.needGC()
|
|
369
|
+
? this.refs.runWithGC(loading_)
|
|
370
|
+
: loading_();
|
|
371
|
+
if (errorHdl) throw this.refs.handles.deleteHandle(errorHdl);
|
|
356
372
|
}
|
|
357
373
|
|
|
358
374
|
error(error: Json): void {
|
|
@@ -362,8 +378,10 @@ class CollectionWriter<K extends Json, V extends Json> {
|
|
|
362
378
|
this.refs.skjson.exportJSON(error),
|
|
363
379
|
);
|
|
364
380
|
};
|
|
365
|
-
|
|
366
|
-
|
|
381
|
+
const errorHdl = this.refs.needGC()
|
|
382
|
+
? this.refs.runWithGC(error_)
|
|
383
|
+
: error_();
|
|
384
|
+
if (errorHdl) throw this.refs.handles.deleteHandle(errorHdl);
|
|
367
385
|
}
|
|
368
386
|
}
|
|
369
387
|
|
|
@@ -385,7 +403,9 @@ class ContextImpl extends SkManaged implements Context {
|
|
|
385
403
|
const computeObj = new compute(...mapperParams);
|
|
386
404
|
Object.freeze(computeObj);
|
|
387
405
|
if (!computeObj.constructor.name) {
|
|
388
|
-
throw new
|
|
406
|
+
throw new SkipClassNameError(
|
|
407
|
+
"LazyCompute classes must be defined at top-level.",
|
|
408
|
+
);
|
|
389
409
|
}
|
|
390
410
|
const skcompute = this.refs.binding.SkipRuntime_createLazyCompute(
|
|
391
411
|
this.refs.handles.register(computeObj),
|
|
@@ -447,15 +467,19 @@ class AllChecker<K extends Json, V extends Json> implements Checker {
|
|
|
447
467
|
) {}
|
|
448
468
|
|
|
449
469
|
check(request: string): void {
|
|
450
|
-
|
|
451
|
-
this.
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
470
|
+
try {
|
|
471
|
+
const result = this.service.getAll<K, V>(
|
|
472
|
+
this.resource,
|
|
473
|
+
this.params,
|
|
474
|
+
request,
|
|
475
|
+
);
|
|
476
|
+
if (result.errors.length > 0) {
|
|
477
|
+
this.executor.reject(new Error(JSON.stringify(result.errors)));
|
|
478
|
+
} else {
|
|
479
|
+
this.executor.resolve(result.payload);
|
|
480
|
+
}
|
|
481
|
+
} catch (ex: unknown) {
|
|
482
|
+
this.executor.reject(ex);
|
|
459
483
|
}
|
|
460
484
|
}
|
|
461
485
|
}
|
|
@@ -470,16 +494,20 @@ class OneChecker<K extends Json, V extends Json> implements Checker {
|
|
|
470
494
|
) {}
|
|
471
495
|
|
|
472
496
|
check(request: string): void {
|
|
473
|
-
|
|
474
|
-
this.
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
497
|
+
try {
|
|
498
|
+
const result = this.service.getArray<K, V>(
|
|
499
|
+
this.resource,
|
|
500
|
+
this.key,
|
|
501
|
+
this.params,
|
|
502
|
+
request,
|
|
503
|
+
);
|
|
504
|
+
if (result.errors.length > 0) {
|
|
505
|
+
this.executor.reject(new Error(JSON.stringify(result.errors)));
|
|
506
|
+
} else {
|
|
507
|
+
this.executor.resolve(result.payload);
|
|
508
|
+
}
|
|
509
|
+
} catch (ex: unknown) {
|
|
510
|
+
this.executor.reject(ex);
|
|
483
511
|
}
|
|
484
512
|
}
|
|
485
513
|
}
|
|
@@ -631,11 +659,11 @@ export class ServiceInstance {
|
|
|
631
659
|
);
|
|
632
660
|
});
|
|
633
661
|
if (session == -1n) {
|
|
634
|
-
throw new
|
|
662
|
+
throw new SkipUnknownCollectionError(
|
|
635
663
|
`Unknown resource instance '${resourceInstanceId}'`,
|
|
636
664
|
);
|
|
637
665
|
} else if (session < 0n) {
|
|
638
|
-
throw new
|
|
666
|
+
throw new SkipError("Unknown error");
|
|
639
667
|
}
|
|
640
668
|
return session as SubscriptionID;
|
|
641
669
|
}
|
|
@@ -708,7 +736,7 @@ class ValuesImpl<T> implements Values<T> {
|
|
|
708
736
|
const value = this.skjson.importOptJSON(
|
|
709
737
|
this.binding.SkipRuntime_NonEmptyIterator__uniqueValue(this.pointer),
|
|
710
738
|
) as Nullable<T & DepSafe>;
|
|
711
|
-
if (value == null) throw new
|
|
739
|
+
if (value == null) throw new SkipNonUniqueValueError();
|
|
712
740
|
return value;
|
|
713
741
|
}
|
|
714
742
|
|
|
@@ -963,6 +991,7 @@ export class ToBinding {
|
|
|
963
991
|
SkipRuntime_ExternalService__subscribe(
|
|
964
992
|
sksupplier: Handle<ExternalService>,
|
|
965
993
|
writerId: string,
|
|
994
|
+
instance: string,
|
|
966
995
|
resource: string,
|
|
967
996
|
skparams: Pointer<Internal.CJObject>,
|
|
968
997
|
): void {
|
|
@@ -970,7 +999,7 @@ export class ToBinding {
|
|
|
970
999
|
const supplier = this.handles.get(sksupplier);
|
|
971
1000
|
const writer = new CollectionWriter(writerId, this.refs());
|
|
972
1001
|
const params = skjson.importJSON(skparams, true) as Json;
|
|
973
|
-
supplier.subscribe(resource, params, {
|
|
1002
|
+
supplier.subscribe(instance, resource, params, {
|
|
974
1003
|
update: writer.update.bind(writer),
|
|
975
1004
|
error: writer.error.bind(writer),
|
|
976
1005
|
loading: writer.loading.bind(writer),
|
|
@@ -979,13 +1008,10 @@ export class ToBinding {
|
|
|
979
1008
|
|
|
980
1009
|
SkipRuntime_ExternalService__unsubscribe(
|
|
981
1010
|
sksupplier: Handle<ExternalService>,
|
|
982
|
-
|
|
983
|
-
skparams: Pointer<Internal.CJObject>,
|
|
1011
|
+
instance: string,
|
|
984
1012
|
): void {
|
|
985
|
-
const skjson = this.getJsonConverter();
|
|
986
1013
|
const supplier = this.handles.get(sksupplier);
|
|
987
|
-
|
|
988
|
-
supplier.unsubscribe(resource, params);
|
|
1014
|
+
supplier.unsubscribe(instance);
|
|
989
1015
|
}
|
|
990
1016
|
|
|
991
1017
|
SkipRuntime_ExternalService__shutdown(
|
package/src/utils.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import {
|
|
3
|
-
import type { Reducer, Json } from "@skipruntime/api";
|
|
1
|
+
import { type NativeStub, type Nullable, sknative } from "@skiplang/std";
|
|
2
|
+
import type { Reducer, Json } from "./api.js";
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* `Reducer` to maintain the sum of input values.
|
package/src/binding.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ResourceBuilder = void 0;
|
|
4
|
-
var ResourceBuilder = /** @class */ (function () {
|
|
5
|
-
function ResourceBuilder(builder) {
|
|
6
|
-
this.builder = builder;
|
|
7
|
-
}
|
|
8
|
-
ResourceBuilder.prototype.build = function (parameters) {
|
|
9
|
-
var builder = this.builder;
|
|
10
|
-
return new builder(parameters);
|
|
11
|
-
};
|
|
12
|
-
return ResourceBuilder;
|
|
13
|
-
}());
|
|
14
|
-
exports.ResourceBuilder = ResourceBuilder;
|
package/src/errors.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.UnknownCollectionError = void 0;
|
|
19
|
-
var UnknownCollectionError = /** @class */ (function (_super) {
|
|
20
|
-
__extends(UnknownCollectionError, _super);
|
|
21
|
-
function UnknownCollectionError() {
|
|
22
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
23
|
-
}
|
|
24
|
-
return UnknownCollectionError;
|
|
25
|
-
}(Error));
|
|
26
|
-
exports.UnknownCollectionError = UnknownCollectionError;
|