@skipruntime/core 0.0.2 → 0.0.4
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/dist/binding.d.ts +4 -6
- package/dist/binding.d.ts.map +1 -1
- package/dist/binding.js.map +1 -1
- package/dist/index.d.ts +14 -56
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -102
- package/dist/index.js.map +1 -1
- package/dist/utils.d.ts +42 -16
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +32 -25
- package/dist/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/binding.js +14 -0
- package/src/binding.ts +11 -6
- package/src/errors.js +26 -0
- package/src/index.js +742 -0
- package/src/index.ts +106 -163
- package/src/internal.js +2 -0
- package/src/utils.js +57 -0
- package/src/utils.ts +55 -40
- package/dist/remote.d.ts +0 -22
- package/dist/remote.d.ts.map +0 -1
- package/dist/remote.js +0 -71
- package/dist/remote.js.map +0 -1
- package/src/remote.ts +0 -94
package/src/index.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 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.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { Opaque } from "@skiplang/std";
|
|
1
8
|
import type {
|
|
2
9
|
Pointer,
|
|
3
10
|
Nullable,
|
|
@@ -5,7 +12,15 @@ import type {
|
|
|
5
12
|
JsonConverter,
|
|
6
13
|
JsonObject,
|
|
7
14
|
} from "@skiplang/json";
|
|
8
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
sk_freeze,
|
|
17
|
+
isSkManaged,
|
|
18
|
+
SkManaged,
|
|
19
|
+
checkOrCloneParam,
|
|
20
|
+
} from "@skiplang/json";
|
|
21
|
+
|
|
22
|
+
import { sknative } from "@skiplang/std";
|
|
23
|
+
|
|
9
24
|
import type * as Internal from "./internal.js";
|
|
10
25
|
import {
|
|
11
26
|
NonUniqueValueException,
|
|
@@ -18,16 +33,14 @@ import {
|
|
|
18
33
|
type LazyCompute,
|
|
19
34
|
type Mapper,
|
|
20
35
|
type NamedCollections,
|
|
21
|
-
type
|
|
22
|
-
type
|
|
36
|
+
type Values,
|
|
37
|
+
type DepSafe,
|
|
23
38
|
type Reducer,
|
|
24
39
|
type Resource,
|
|
25
40
|
type SkipService,
|
|
26
|
-
type SubscriptionID,
|
|
27
41
|
type Watermark,
|
|
28
42
|
} from "@skipruntime/api";
|
|
29
43
|
|
|
30
|
-
import { Frozen } from "@skipruntime/api/internals.js";
|
|
31
44
|
import { UnknownCollectionError } from "./errors.js";
|
|
32
45
|
import {
|
|
33
46
|
ResourceBuilder,
|
|
@@ -37,99 +50,12 @@ import {
|
|
|
37
50
|
type FromBinding,
|
|
38
51
|
} from "./binding.js";
|
|
39
52
|
|
|
40
|
-
export { UnknownCollectionError, sk_freeze,
|
|
41
|
-
export {
|
|
42
|
-
export { Sum, Min, Max, CountMapper } from "./utils.js";
|
|
53
|
+
export { UnknownCollectionError, sk_freeze, isSkManaged };
|
|
54
|
+
export { Sum, Min, Max, Count } from "./utils.js";
|
|
43
55
|
|
|
44
56
|
export type JSONMapper = Mapper<Json, Json, Json, Json>;
|
|
45
57
|
export type JSONLazyCompute = LazyCompute<Json, Json>;
|
|
46
58
|
|
|
47
|
-
export type Entrypoint = {
|
|
48
|
-
host: string;
|
|
49
|
-
streaming_port: number;
|
|
50
|
-
control_port: number;
|
|
51
|
-
secured?: boolean;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
abstract class SkFrozen extends Frozen {
|
|
55
|
-
protected freeze() {
|
|
56
|
-
sk_freeze(this);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function checkOrCloneParam<T>(value: T): T {
|
|
61
|
-
if (
|
|
62
|
-
typeof value == "string" ||
|
|
63
|
-
typeof value == "number" ||
|
|
64
|
-
typeof value == "boolean"
|
|
65
|
-
)
|
|
66
|
-
return value;
|
|
67
|
-
if (typeof value == "object") {
|
|
68
|
-
if (value === null) return value;
|
|
69
|
-
if (isObjectProxy(value)) return value.clone() as T;
|
|
70
|
-
if (isSkFrozen(value)) return value;
|
|
71
|
-
throw new Error("Invalid object: must be deep-frozen.");
|
|
72
|
-
}
|
|
73
|
-
throw new Error(`'${typeof value}' cannot be deep-frozen.`);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* _Deep-freeze_ an object, returning the same object that was passed in.
|
|
78
|
-
*
|
|
79
|
-
* This function is similar to
|
|
80
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze | `Object.freeze()`}
|
|
81
|
-
* but freezes the object and deep-freezes all its properties,
|
|
82
|
-
* recursively. The object is then not only _immutable_ but also
|
|
83
|
-
* _constant_. Note that as a result all objects reachable from the
|
|
84
|
-
* parameter will be frozen and no longer mutable or extensible, even from
|
|
85
|
-
* other references.
|
|
86
|
-
*
|
|
87
|
-
* The argument object and all its properties, recursively, must not already
|
|
88
|
-
* be frozen by `Object.freeze` (or else `deepFreeze` cannot mark them
|
|
89
|
-
* deep-frozen). Undefined, function (and hence class) values cannot be
|
|
90
|
-
* deep-frozen.
|
|
91
|
-
*
|
|
92
|
-
* The primary use for this function is to satisfy the requirement that all
|
|
93
|
-
* parameters to Skip `Mapper` constructors must be deep-frozen: objects
|
|
94
|
-
* that have not been constructed by Skip can be passed to `deepFreeze()`
|
|
95
|
-
* before passing them to a `Mapper` constructor.
|
|
96
|
-
*
|
|
97
|
-
* @param value - The object to deep-freeze.
|
|
98
|
-
* @returns The same object that was passed in.
|
|
99
|
-
*/
|
|
100
|
-
export function deepFreeze<T>(value: T): T & Param {
|
|
101
|
-
if (
|
|
102
|
-
typeof value == "bigint" ||
|
|
103
|
-
typeof value == "boolean" ||
|
|
104
|
-
typeof value == "number" ||
|
|
105
|
-
typeof value == "string" ||
|
|
106
|
-
typeof value == "symbol"
|
|
107
|
-
) {
|
|
108
|
-
return value;
|
|
109
|
-
} else if (typeof value == "object") {
|
|
110
|
-
if (value === null) {
|
|
111
|
-
return value;
|
|
112
|
-
} else if (isSkFrozen(value)) {
|
|
113
|
-
return value;
|
|
114
|
-
} else if (Object.isFrozen(value)) {
|
|
115
|
-
throw new Error(`Cannot deep-freeze an Object.frozen value.`);
|
|
116
|
-
} else if (Array.isArray(value)) {
|
|
117
|
-
for (const elt of value) {
|
|
118
|
-
deepFreeze(elt);
|
|
119
|
-
}
|
|
120
|
-
return Object.freeze(sk_freeze(value));
|
|
121
|
-
} else {
|
|
122
|
-
for (const val of Object.values(value)) {
|
|
123
|
-
deepFreeze(val);
|
|
124
|
-
}
|
|
125
|
-
return Object.freeze(sk_freeze(value));
|
|
126
|
-
}
|
|
127
|
-
} else {
|
|
128
|
-
// typeof value == "function" || typeof value == "undefined"
|
|
129
|
-
throw new Error(`'${typeof value}' values cannot be deep-frozen.`);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
59
|
class Handles {
|
|
134
60
|
private nextID: number = 1;
|
|
135
61
|
private readonly objects: any[] = [];
|
|
@@ -187,7 +113,7 @@ export class Refs {
|
|
|
187
113
|
}
|
|
188
114
|
|
|
189
115
|
class LazyCollectionImpl<K extends Json, V extends Json>
|
|
190
|
-
extends
|
|
116
|
+
extends SkManaged
|
|
191
117
|
implements LazyCollection<K, V>
|
|
192
118
|
{
|
|
193
119
|
constructor(
|
|
@@ -198,29 +124,29 @@ class LazyCollectionImpl<K extends Json, V extends Json>
|
|
|
198
124
|
Object.freeze(this);
|
|
199
125
|
}
|
|
200
126
|
|
|
201
|
-
getArray(key: K): (V &
|
|
127
|
+
getArray(key: K): (V & DepSafe)[] {
|
|
202
128
|
return this.refs.skjson.importJSON(
|
|
203
129
|
this.refs.binding.SkipRuntime_LazyCollection__getArray(
|
|
204
130
|
this.lazyCollection,
|
|
205
131
|
this.refs.skjson.exportJSON(key),
|
|
206
132
|
),
|
|
207
|
-
) as (V &
|
|
133
|
+
) as (V & DepSafe)[];
|
|
208
134
|
}
|
|
209
135
|
|
|
210
|
-
getUnique(key: K): V &
|
|
136
|
+
getUnique(key: K): V & DepSafe {
|
|
211
137
|
const v = this.refs.skjson.importOptJSON(
|
|
212
138
|
this.refs.binding.SkipRuntime_LazyCollection__getUnique(
|
|
213
139
|
this.lazyCollection,
|
|
214
140
|
this.refs.skjson.exportJSON(key),
|
|
215
141
|
),
|
|
216
|
-
) as Nullable<V &
|
|
142
|
+
) as Nullable<V & DepSafe>;
|
|
217
143
|
if (v == null) throw new NonUniqueValueException();
|
|
218
144
|
return v;
|
|
219
145
|
}
|
|
220
146
|
}
|
|
221
147
|
|
|
222
148
|
class EagerCollectionImpl<K extends Json, V extends Json>
|
|
223
|
-
extends
|
|
149
|
+
extends SkManaged
|
|
224
150
|
implements EagerCollection<K, V>
|
|
225
151
|
{
|
|
226
152
|
constructor(
|
|
@@ -231,22 +157,22 @@ class EagerCollectionImpl<K extends Json, V extends Json>
|
|
|
231
157
|
Object.freeze(this);
|
|
232
158
|
}
|
|
233
159
|
|
|
234
|
-
getArray(key: K): (V &
|
|
160
|
+
getArray(key: K): (V & DepSafe)[] {
|
|
235
161
|
return this.refs.skjson.importJSON(
|
|
236
162
|
this.refs.binding.SkipRuntime_Collection__getArray(
|
|
237
163
|
this.collection,
|
|
238
164
|
this.refs.skjson.exportJSON(key),
|
|
239
165
|
),
|
|
240
|
-
) as (V &
|
|
166
|
+
) as (V & DepSafe)[];
|
|
241
167
|
}
|
|
242
168
|
|
|
243
|
-
getUnique(key: K): V &
|
|
169
|
+
getUnique(key: K): V & DepSafe {
|
|
244
170
|
const v = this.refs.skjson.importOptJSON(
|
|
245
171
|
this.refs.binding.SkipRuntime_Collection__getUnique(
|
|
246
172
|
this.collection,
|
|
247
173
|
this.refs.skjson.exportJSON(key),
|
|
248
174
|
),
|
|
249
|
-
) as Nullable<V &
|
|
175
|
+
) as Nullable<V & DepSafe>;
|
|
250
176
|
if (v == null) throw new NonUniqueValueException();
|
|
251
177
|
return v;
|
|
252
178
|
}
|
|
@@ -277,7 +203,7 @@ class EagerCollectionImpl<K extends Json, V extends Json>
|
|
|
277
203
|
return this.derive<K, V>(skcollection);
|
|
278
204
|
}
|
|
279
205
|
|
|
280
|
-
map<K2 extends Json, V2 extends Json, Params extends
|
|
206
|
+
map<K2 extends Json, V2 extends Json, Params extends DepSafe[]>(
|
|
281
207
|
mapper: new (...params: Params) => Mapper<K, V, K2, V2>,
|
|
282
208
|
...params: Params
|
|
283
209
|
): EagerCollection<K2, V2> {
|
|
@@ -297,11 +223,11 @@ class EagerCollectionImpl<K extends Json, V extends Json>
|
|
|
297
223
|
return this.derive<K2, V2>(mapped);
|
|
298
224
|
}
|
|
299
225
|
|
|
300
|
-
mapReduce<K2 extends Json, V2 extends Json, MapperParams extends
|
|
226
|
+
mapReduce<K2 extends Json, V2 extends Json, MapperParams extends DepSafe[]>(
|
|
301
227
|
mapper: new (...params: MapperParams) => Mapper<K, V, K2, V2>,
|
|
302
228
|
...mapperParams: MapperParams
|
|
303
229
|
) {
|
|
304
|
-
return <Accum extends Json, ReducerParams extends
|
|
230
|
+
return <Accum extends Json, ReducerParams extends DepSafe[]>(
|
|
305
231
|
reducer: new (...params: ReducerParams) => Reducer<V2, Accum>,
|
|
306
232
|
...reducerParams: ReducerParams
|
|
307
233
|
) => {
|
|
@@ -324,20 +250,32 @@ class EagerCollectionImpl<K extends Json, V extends Json>
|
|
|
324
250
|
const skmapper = this.refs.binding.SkipRuntime_createMapper(
|
|
325
251
|
this.refs.handles.register(mapperObj),
|
|
326
252
|
);
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
this.
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
253
|
+
|
|
254
|
+
if (sknative in reducerObj && typeof reducerObj[sknative] == "string") {
|
|
255
|
+
return this.derive<K2, Accum>(
|
|
256
|
+
this.refs.binding.SkipRuntime_Collection__nativeMapReduce(
|
|
257
|
+
this.collection,
|
|
258
|
+
skmapper,
|
|
259
|
+
reducerObj[sknative],
|
|
260
|
+
),
|
|
261
|
+
);
|
|
262
|
+
} else {
|
|
263
|
+
const skreducer = this.refs.binding.SkipRuntime_createReducer(
|
|
264
|
+
this.refs.handles.register(reducerObj),
|
|
265
|
+
this.refs.skjson.exportJSON(reducerObj.initial),
|
|
266
|
+
);
|
|
267
|
+
return this.derive<K2, Accum>(
|
|
268
|
+
this.refs.binding.SkipRuntime_Collection__mapReduce(
|
|
269
|
+
this.collection,
|
|
270
|
+
skmapper,
|
|
271
|
+
skreducer,
|
|
272
|
+
),
|
|
273
|
+
);
|
|
274
|
+
}
|
|
337
275
|
};
|
|
338
276
|
}
|
|
339
277
|
|
|
340
|
-
reduce<Accum extends Json, Params extends
|
|
278
|
+
reduce<Accum extends Json, Params extends DepSafe[]>(
|
|
341
279
|
reducer: new (...params: Params) => Reducer<V, Accum>,
|
|
342
280
|
...params: Params
|
|
343
281
|
): EagerCollection<K, Accum> {
|
|
@@ -347,16 +285,25 @@ class EagerCollectionImpl<K extends Json, V extends Json>
|
|
|
347
285
|
if (!reducerObj.constructor.name) {
|
|
348
286
|
throw new Error("Reducer classes must be defined at top-level.");
|
|
349
287
|
}
|
|
350
|
-
|
|
351
|
-
this.
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
288
|
+
if (sknative in reducerObj && typeof reducerObj[sknative] == "string") {
|
|
289
|
+
return this.derive<K, Accum>(
|
|
290
|
+
this.refs.binding.SkipRuntime_Collection__nativeReduce(
|
|
291
|
+
this.collection,
|
|
292
|
+
reducerObj[sknative],
|
|
293
|
+
),
|
|
294
|
+
);
|
|
295
|
+
} else {
|
|
296
|
+
const skreducer = this.refs.binding.SkipRuntime_createReducer(
|
|
297
|
+
this.refs.handles.register(reducerObj),
|
|
298
|
+
this.refs.skjson.exportJSON(reducerObj.initial),
|
|
299
|
+
);
|
|
300
|
+
return this.derive<K, Accum>(
|
|
301
|
+
this.refs.binding.SkipRuntime_Collection__reduce(
|
|
302
|
+
this.collection,
|
|
303
|
+
skreducer,
|
|
304
|
+
),
|
|
305
|
+
);
|
|
306
|
+
}
|
|
360
307
|
}
|
|
361
308
|
|
|
362
309
|
merge(...others: EagerCollection<K, V>[]): EagerCollection<K, V> {
|
|
@@ -420,13 +367,17 @@ class CollectionWriter<K extends Json, V extends Json> {
|
|
|
420
367
|
}
|
|
421
368
|
}
|
|
422
369
|
|
|
423
|
-
class ContextImpl extends
|
|
370
|
+
class ContextImpl extends SkManaged implements Context {
|
|
424
371
|
constructor(private readonly refs: Refs) {
|
|
425
372
|
super();
|
|
426
373
|
Object.freeze(this);
|
|
427
374
|
}
|
|
428
375
|
|
|
429
|
-
createLazyCollection<
|
|
376
|
+
createLazyCollection<
|
|
377
|
+
K extends Json,
|
|
378
|
+
V extends Json,
|
|
379
|
+
Params extends DepSafe[],
|
|
380
|
+
>(
|
|
430
381
|
compute: new (...params: Params) => LazyCompute<K, V>,
|
|
431
382
|
...params: Params
|
|
432
383
|
): LazyCollection<K, V> {
|
|
@@ -447,7 +398,7 @@ class ContextImpl extends SkFrozen implements Context {
|
|
|
447
398
|
useExternalResource<K extends Json, V extends Json>(resource: {
|
|
448
399
|
service: string;
|
|
449
400
|
identifier: string;
|
|
450
|
-
params?:
|
|
401
|
+
params?: Json;
|
|
451
402
|
}): EagerCollection<K, V> {
|
|
452
403
|
const collection =
|
|
453
404
|
this.refs.binding.SkipRuntime_Context__useExternalResource(
|
|
@@ -492,7 +443,7 @@ class AllChecker<K extends Json, V extends Json> implements Checker {
|
|
|
492
443
|
private readonly service: ServiceInstance,
|
|
493
444
|
private readonly executor: Executor<Entry<K, V>[]>,
|
|
494
445
|
private readonly resource: string,
|
|
495
|
-
private readonly params:
|
|
446
|
+
private readonly params: Json,
|
|
496
447
|
) {}
|
|
497
448
|
|
|
498
449
|
check(request: string): void {
|
|
@@ -514,7 +465,7 @@ class OneChecker<K extends Json, V extends Json> implements Checker {
|
|
|
514
465
|
private readonly service: ServiceInstance,
|
|
515
466
|
private readonly executor: Executor<V[]>,
|
|
516
467
|
private readonly resource: string,
|
|
517
|
-
private readonly params:
|
|
468
|
+
private readonly params: Json,
|
|
518
469
|
private readonly key: K,
|
|
519
470
|
) {}
|
|
520
471
|
|
|
@@ -533,6 +484,8 @@ class OneChecker<K extends Json, V extends Json> implements Checker {
|
|
|
533
484
|
}
|
|
534
485
|
}
|
|
535
486
|
|
|
487
|
+
export type SubscriptionID = Opaque<bigint, "subscription">;
|
|
488
|
+
|
|
536
489
|
/**
|
|
537
490
|
* A `ServiceInstance` is a running instance of a `SkipService`, providing access to its resources
|
|
538
491
|
* and operations to manage susbscriptions and the service itself.
|
|
@@ -549,7 +502,7 @@ export class ServiceInstance {
|
|
|
549
502
|
instantiateResource(
|
|
550
503
|
identifier: string,
|
|
551
504
|
resource: string,
|
|
552
|
-
params:
|
|
505
|
+
params: Json,
|
|
553
506
|
): void {
|
|
554
507
|
const errorHdl = this.refs.runWithGC(() => {
|
|
555
508
|
return this.refs.binding.SkipRuntime_Runtime__createResource(
|
|
@@ -569,7 +522,7 @@ export class ServiceInstance {
|
|
|
569
522
|
*/
|
|
570
523
|
getAll<K extends Json, V extends Json>(
|
|
571
524
|
resource: string,
|
|
572
|
-
params:
|
|
525
|
+
params: Json = {},
|
|
573
526
|
request?: string | Executor<Entry<K, V>[]>,
|
|
574
527
|
): GetResult<Entry<K, V>[]> {
|
|
575
528
|
const get_ = () => {
|
|
@@ -606,7 +559,7 @@ export class ServiceInstance {
|
|
|
606
559
|
getArray<K extends Json, V extends Json>(
|
|
607
560
|
resource: string,
|
|
608
561
|
key: K,
|
|
609
|
-
params:
|
|
562
|
+
params: Json = {},
|
|
610
563
|
request?: string | Executor<V[]>,
|
|
611
564
|
): GetResult<V[]> {
|
|
612
565
|
const get_ = () => {
|
|
@@ -734,7 +687,7 @@ export class ServiceInstance {
|
|
|
734
687
|
}
|
|
735
688
|
}
|
|
736
689
|
|
|
737
|
-
|
|
690
|
+
class ValuesImpl<T> implements Values<T> {
|
|
738
691
|
constructor(
|
|
739
692
|
private readonly skjson: JsonConverter,
|
|
740
693
|
private readonly binding: FromBinding,
|
|
@@ -745,26 +698,26 @@ export class NonEmptyIteratorImpl<T> implements NonEmptyIterator<T> {
|
|
|
745
698
|
this.pointer = pointer;
|
|
746
699
|
}
|
|
747
700
|
|
|
748
|
-
next(): Nullable<T &
|
|
701
|
+
next(): Nullable<T & DepSafe> {
|
|
749
702
|
return this.skjson.importOptJSON(
|
|
750
703
|
this.binding.SkipRuntime_NonEmptyIterator__next(this.pointer),
|
|
751
|
-
) as Nullable<T &
|
|
704
|
+
) as Nullable<T & DepSafe>;
|
|
752
705
|
}
|
|
753
706
|
|
|
754
|
-
getUnique(): T &
|
|
707
|
+
getUnique(): T & DepSafe {
|
|
755
708
|
const value = this.skjson.importOptJSON(
|
|
756
709
|
this.binding.SkipRuntime_NonEmptyIterator__uniqueValue(this.pointer),
|
|
757
|
-
) as Nullable<T &
|
|
710
|
+
) as Nullable<T & DepSafe>;
|
|
758
711
|
if (value == null) throw new NonUniqueValueException();
|
|
759
712
|
return value;
|
|
760
713
|
}
|
|
761
714
|
|
|
762
|
-
toArray: () => (T &
|
|
715
|
+
toArray: () => (T & DepSafe)[] = () => {
|
|
763
716
|
return Array.from(this);
|
|
764
717
|
};
|
|
765
718
|
|
|
766
|
-
[Symbol.iterator](): Iterator<T &
|
|
767
|
-
const cloned_iter = new
|
|
719
|
+
[Symbol.iterator](): Iterator<T & DepSafe> {
|
|
720
|
+
const cloned_iter = new ValuesImpl<T & DepSafe>(
|
|
768
721
|
this.skjson,
|
|
769
722
|
this.binding,
|
|
770
723
|
this.binding.SkipRuntime_NonEmptyIterator__clone(this.pointer),
|
|
@@ -773,14 +726,10 @@ export class NonEmptyIteratorImpl<T> implements NonEmptyIterator<T> {
|
|
|
773
726
|
return {
|
|
774
727
|
next() {
|
|
775
728
|
const value = cloned_iter.next();
|
|
776
|
-
return { value, done: value == null } as IteratorResult<T &
|
|
729
|
+
return { value, done: value == null } as IteratorResult<T & DepSafe>;
|
|
777
730
|
},
|
|
778
731
|
};
|
|
779
732
|
}
|
|
780
|
-
|
|
781
|
-
map<U>(f: (value: T & Param, index: number) => U, thisObj?: any): U[] {
|
|
782
|
-
return this.toArray().map(f, thisObj);
|
|
783
|
-
}
|
|
784
733
|
}
|
|
785
734
|
|
|
786
735
|
export class ToBinding {
|
|
@@ -833,7 +782,7 @@ export class ToBinding {
|
|
|
833
782
|
const mapper = this.handles.get(skmapper);
|
|
834
783
|
const result = mapper.mapEntry(
|
|
835
784
|
skjson.importJSON(key) as Json,
|
|
836
|
-
new
|
|
785
|
+
new ValuesImpl<Json>(skjson, this.binding, values),
|
|
837
786
|
);
|
|
838
787
|
return skjson.exportJSON(Array.from(result) as [[Json, Json]]);
|
|
839
788
|
}
|
|
@@ -851,11 +800,11 @@ export class ToBinding {
|
|
|
851
800
|
): Pointer<Internal.CJArray> {
|
|
852
801
|
const skjson = this.getJsonConverter();
|
|
853
802
|
const lazyCompute = this.handles.get(sklazyCompute);
|
|
854
|
-
const
|
|
803
|
+
const result = lazyCompute.compute(
|
|
855
804
|
new LazyCollectionImpl<Json, Json>(self, this.refs()),
|
|
856
805
|
skjson.importJSON(skkey) as Json,
|
|
857
806
|
);
|
|
858
|
-
return skjson.exportJSON(
|
|
807
|
+
return skjson.exportJSON(Array.from(result));
|
|
859
808
|
}
|
|
860
809
|
|
|
861
810
|
SkipRuntime_deleteLazyCompute(lazyCompute: Handle<JSONLazyCompute>): void {
|
|
@@ -894,9 +843,7 @@ export class ToBinding {
|
|
|
894
843
|
): Pointer<Internal.Resource> {
|
|
895
844
|
const skjson = this.getJsonConverter();
|
|
896
845
|
const builder = this.handles.get(skbuilder);
|
|
897
|
-
const resource = builder.build(
|
|
898
|
-
skjson.importJSON(skparams) as { [param: string]: string },
|
|
899
|
-
);
|
|
846
|
+
const resource = builder.build(skjson.importJSON(skparams) as Json);
|
|
900
847
|
return this.binding.SkipRuntime_createResource(
|
|
901
848
|
this.handles.register(resource),
|
|
902
849
|
);
|
|
@@ -987,7 +934,7 @@ export class ToBinding {
|
|
|
987
934
|
return skjson.exportJSON(
|
|
988
935
|
reducer.add(
|
|
989
936
|
skacc ? (skjson.importJSON(skacc) as Json) : null,
|
|
990
|
-
skjson.importJSON(skvalue) as Json &
|
|
937
|
+
skjson.importJSON(skvalue) as Json & DepSafe,
|
|
991
938
|
),
|
|
992
939
|
);
|
|
993
940
|
}
|
|
@@ -1002,7 +949,7 @@ export class ToBinding {
|
|
|
1002
949
|
return skjson.exportJSON(
|
|
1003
950
|
reducer.remove(
|
|
1004
951
|
skjson.importJSON(skacc) as Json,
|
|
1005
|
-
skjson.importJSON(skvalue) as Json &
|
|
952
|
+
skjson.importJSON(skvalue) as Json & DepSafe,
|
|
1006
953
|
),
|
|
1007
954
|
);
|
|
1008
955
|
}
|
|
@@ -1022,9 +969,7 @@ export class ToBinding {
|
|
|
1022
969
|
const skjson = this.getJsonConverter();
|
|
1023
970
|
const supplier = this.handles.get(sksupplier);
|
|
1024
971
|
const writer = new CollectionWriter(writerId, this.refs());
|
|
1025
|
-
const params = skjson.importJSON(skparams, true) as
|
|
1026
|
-
[param: string]: string;
|
|
1027
|
-
};
|
|
972
|
+
const params = skjson.importJSON(skparams, true) as Json;
|
|
1028
973
|
supplier.subscribe(resource, params, {
|
|
1029
974
|
update: writer.update.bind(writer),
|
|
1030
975
|
error: writer.error.bind(writer),
|
|
@@ -1039,9 +984,7 @@ export class ToBinding {
|
|
|
1039
984
|
): void {
|
|
1040
985
|
const skjson = this.getJsonConverter();
|
|
1041
986
|
const supplier = this.handles.get(sksupplier);
|
|
1042
|
-
const params = skjson.importJSON(skparams, true) as
|
|
1043
|
-
[param: string]: string;
|
|
1044
|
-
};
|
|
987
|
+
const params = skjson.importJSON(skparams, true) as Json;
|
|
1045
988
|
supplier.unsubscribe(resource, params);
|
|
1046
989
|
}
|
|
1047
990
|
|
package/src/internal.js
ADDED
package/src/utils.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a, _b, _c, _d;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Count = exports.Max = exports.Min = exports.Sum = void 0;
|
|
5
|
+
var std_1 = require("@skiplang/std");
|
|
6
|
+
/**
|
|
7
|
+
* `Reducer` to maintain the sum of input values.
|
|
8
|
+
*
|
|
9
|
+
* A `Reducer` that maintains the sum of values as they are added and removed from a collection.
|
|
10
|
+
*/
|
|
11
|
+
var Sum = /** @class */ (function () {
|
|
12
|
+
function Sum() {
|
|
13
|
+
this[_a] = "sum";
|
|
14
|
+
}
|
|
15
|
+
return Sum;
|
|
16
|
+
}());
|
|
17
|
+
exports.Sum = Sum;
|
|
18
|
+
_a = std_1.sknative;
|
|
19
|
+
/**
|
|
20
|
+
* `Reducer` to maintain the minimum of input values.
|
|
21
|
+
*
|
|
22
|
+
* A `Reducer` that maintains the minimum of values as they are added and removed from a collection.
|
|
23
|
+
*/
|
|
24
|
+
var Min = /** @class */ (function () {
|
|
25
|
+
function Min() {
|
|
26
|
+
this[_b] = "min";
|
|
27
|
+
}
|
|
28
|
+
return Min;
|
|
29
|
+
}());
|
|
30
|
+
exports.Min = Min;
|
|
31
|
+
_b = std_1.sknative;
|
|
32
|
+
/**
|
|
33
|
+
* `Reducer` to maintain the maximum of input values.
|
|
34
|
+
*
|
|
35
|
+
* A `Reducer` that maintains the maximum of values as they are added and removed from a collection.
|
|
36
|
+
*/
|
|
37
|
+
var Max = /** @class */ (function () {
|
|
38
|
+
function Max() {
|
|
39
|
+
this[_c] = "max";
|
|
40
|
+
}
|
|
41
|
+
return Max;
|
|
42
|
+
}());
|
|
43
|
+
exports.Max = Max;
|
|
44
|
+
_c = std_1.sknative;
|
|
45
|
+
/**
|
|
46
|
+
* `Reducer` to maintain the count of input values.
|
|
47
|
+
*
|
|
48
|
+
* A `Reducer` that maintains the number of values as they are added and removed from a collection.
|
|
49
|
+
*/
|
|
50
|
+
var Count = /** @class */ (function () {
|
|
51
|
+
function Count() {
|
|
52
|
+
this[_d] = "count";
|
|
53
|
+
}
|
|
54
|
+
return Count;
|
|
55
|
+
}());
|
|
56
|
+
exports.Count = Count;
|
|
57
|
+
_d = std_1.sknative;
|