@skipruntime/core 0.0.13 → 0.0.15
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/src/api.d.ts +14 -18
- package/dist/src/api.d.ts.map +1 -1
- package/dist/src/binding.d.ts +12 -9
- package/dist/src/binding.d.ts.map +1 -1
- package/dist/src/index.d.ts +9 -17
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +140 -141
- package/dist/src/index.js.map +1 -1
- package/dist/src/internal.d.ts +2 -2
- package/dist/src/internal.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/api.ts +14 -18
- package/src/binding.ts +18 -8
- package/src/index.ts +208 -220
- package/src/internal.ts +2 -2
package/src/binding.ts
CHANGED
|
@@ -32,6 +32,11 @@ export interface Checker {
|
|
|
32
32
|
check(request: string): void;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
export type Executor = {
|
|
36
|
+
resolve: () => void;
|
|
37
|
+
reject: (reason: Error) => void;
|
|
38
|
+
};
|
|
39
|
+
|
|
35
40
|
export interface FromBinding {
|
|
36
41
|
// NonEmptyIterator
|
|
37
42
|
SkipRuntime_NonEmptyIterator__next(
|
|
@@ -66,6 +71,7 @@ export interface FromBinding {
|
|
|
66
71
|
name: string,
|
|
67
72
|
values: Pointer<Internal.CJArray<Internal.CJArray<Internal.CJSON>>>,
|
|
68
73
|
isInit: boolean,
|
|
74
|
+
executor: Pointer<Internal.Executor>,
|
|
69
75
|
): Handle<Error>;
|
|
70
76
|
|
|
71
77
|
SkipRuntime_CollectionWriter__error(
|
|
@@ -73,7 +79,10 @@ export interface FromBinding {
|
|
|
73
79
|
error: Pointer<Internal.CJSON>,
|
|
74
80
|
): Handle<Error>;
|
|
75
81
|
|
|
76
|
-
|
|
82
|
+
SkipRuntime_CollectionWriter__initialized(
|
|
83
|
+
name: string,
|
|
84
|
+
error: Pointer<Internal.CJSON>,
|
|
85
|
+
): Handle<Error>;
|
|
77
86
|
|
|
78
87
|
// Resource
|
|
79
88
|
|
|
@@ -176,19 +185,18 @@ export interface FromBinding {
|
|
|
176
185
|
identifier: string,
|
|
177
186
|
resource: string,
|
|
178
187
|
jsonParams: Pointer<Internal.CJObject>,
|
|
188
|
+
executor: Pointer<Internal.Executor>,
|
|
179
189
|
): Handle<Error>;
|
|
180
190
|
|
|
181
191
|
SkipRuntime_Runtime__getAll(
|
|
182
192
|
resource: string,
|
|
183
193
|
jsonParams: Pointer<Internal.CJObject>,
|
|
184
|
-
request: Pointer<Internal.Request> | null,
|
|
185
194
|
): Pointer<Internal.CJObject | Internal.CJFloat>;
|
|
186
195
|
|
|
187
196
|
SkipRuntime_Runtime__getForKey(
|
|
188
197
|
resource: string,
|
|
189
198
|
jsonParams: Pointer<Internal.CJObject>,
|
|
190
199
|
key: Pointer<Internal.CJSON>,
|
|
191
|
-
request: Pointer<Internal.Request> | null,
|
|
192
200
|
): Pointer<Internal.CJObject | Internal.CJFloat>;
|
|
193
201
|
|
|
194
202
|
SkipRuntime_Runtime__closeResource(identifier: string): Handle<Error>;
|
|
@@ -204,6 +212,7 @@ export interface FromBinding {
|
|
|
204
212
|
SkipRuntime_Runtime__update(
|
|
205
213
|
input: string,
|
|
206
214
|
values: Pointer<Internal.CJArray<Internal.CJArray<Internal.CJSON>>>,
|
|
215
|
+
executor: Pointer<Internal.Executor>,
|
|
207
216
|
): Handle<Error>;
|
|
208
217
|
|
|
209
218
|
// Reducer
|
|
@@ -214,7 +223,10 @@ export interface FromBinding {
|
|
|
214
223
|
): Pointer<Internal.Reducer>;
|
|
215
224
|
|
|
216
225
|
// initService
|
|
217
|
-
SkipRuntime_initService(
|
|
226
|
+
SkipRuntime_initService(
|
|
227
|
+
service: Pointer<Internal.Service>,
|
|
228
|
+
executor: Pointer<Internal.Executor>,
|
|
229
|
+
): Handle<Error>;
|
|
218
230
|
|
|
219
231
|
// closeClose
|
|
220
232
|
SkipRuntime_closeService(): Pointer<Internal.CJSON>;
|
|
@@ -236,9 +248,7 @@ export interface FromBinding {
|
|
|
236
248
|
params: Pointer<Internal.CJObject>,
|
|
237
249
|
): string;
|
|
238
250
|
|
|
239
|
-
//
|
|
240
|
-
|
|
241
|
-
SkipRuntime_createIdentifier(supplier: string): Pointer<Internal.Request>;
|
|
251
|
+
// Executor
|
|
242
252
|
|
|
243
|
-
|
|
253
|
+
SkipRuntime_createExecutor(ref: Handle<Executor>): Pointer<Internal.Executor>;
|
|
244
254
|
}
|
package/src/index.ts
CHANGED
|
@@ -41,6 +41,7 @@ import {
|
|
|
41
41
|
|
|
42
42
|
import {
|
|
43
43
|
SkipClassNameError,
|
|
44
|
+
SkipError,
|
|
44
45
|
SkipNonUniqueValueError,
|
|
45
46
|
SkipResourceInstanceInUseError,
|
|
46
47
|
SkipUnknownCollectionError,
|
|
@@ -48,7 +49,7 @@ import {
|
|
|
48
49
|
import {
|
|
49
50
|
ResourceBuilder,
|
|
50
51
|
type Notifier,
|
|
51
|
-
type
|
|
52
|
+
type Executor,
|
|
52
53
|
type Handle,
|
|
53
54
|
type FromBinding,
|
|
54
55
|
} from "./binding.js";
|
|
@@ -342,45 +343,62 @@ class CollectionWriter<K extends Json, V extends Json> {
|
|
|
342
343
|
private readonly refs: Refs,
|
|
343
344
|
) {}
|
|
344
345
|
|
|
345
|
-
update(values: Entry<K, V>[], isInit: boolean): void {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
346
|
+
async update(values: Entry<K, V>[], isInit: boolean): Promise<void> {
|
|
347
|
+
await new Promise<void>((resolve, reject) => {
|
|
348
|
+
if (!this.refs.needGC()) {
|
|
349
|
+
reject(new SkipError("CollectionWriter.update cannot be performed."));
|
|
350
|
+
}
|
|
351
|
+
const errorHdl = this.refs.runWithGC(() => {
|
|
352
|
+
const exHdl = this.refs.handles.register({
|
|
353
|
+
resolve,
|
|
354
|
+
reject: (ex: Error) => reject(ex),
|
|
355
|
+
});
|
|
356
|
+
return this.refs.binding.SkipRuntime_CollectionWriter__update(
|
|
357
|
+
this.collection,
|
|
358
|
+
this.refs.skjson.exportJSON(values),
|
|
359
|
+
isInit,
|
|
360
|
+
this.refs.binding.SkipRuntime_createExecutor(exHdl),
|
|
361
|
+
);
|
|
362
|
+
});
|
|
363
|
+
if (errorHdl) reject(this.refs.handles.deleteHandle(errorHdl));
|
|
364
|
+
});
|
|
358
365
|
}
|
|
359
366
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
367
|
+
error(error: unknown): void {
|
|
368
|
+
if (!this.refs.needGC()) {
|
|
369
|
+
throw new SkipError("CollectionWriter.update cannot be performed.");
|
|
370
|
+
}
|
|
371
|
+
const errorHdl = this.refs.runWithGC(() =>
|
|
372
|
+
this.refs.binding.SkipRuntime_CollectionWriter__error(
|
|
363
373
|
this.collection,
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
? this.refs.runWithGC(loading_)
|
|
368
|
-
: loading_();
|
|
374
|
+
this.refs.skjson.exportJSON(this.toJSONError(error)),
|
|
375
|
+
),
|
|
376
|
+
);
|
|
369
377
|
if (errorHdl) throw this.refs.handles.deleteHandle(errorHdl);
|
|
370
378
|
}
|
|
371
379
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
380
|
+
initialized(error?: unknown): void {
|
|
381
|
+
if (!this.refs.needGC()) {
|
|
382
|
+
throw new SkipError("CollectionWriter.update cannot be performed.");
|
|
383
|
+
}
|
|
384
|
+
const errorHdl = this.refs.runWithGC(() =>
|
|
385
|
+
this.refs.binding.SkipRuntime_CollectionWriter__initialized(
|
|
375
386
|
this.collection,
|
|
376
|
-
this.refs.skjson.exportJSON(error),
|
|
377
|
-
)
|
|
378
|
-
|
|
379
|
-
const errorHdl = this.refs.needGC()
|
|
380
|
-
? this.refs.runWithGC(error_)
|
|
381
|
-
: error_();
|
|
387
|
+
this.refs.skjson.exportJSON(error ? this.toJSONError(error) : null),
|
|
388
|
+
),
|
|
389
|
+
);
|
|
382
390
|
if (errorHdl) throw this.refs.handles.deleteHandle(errorHdl);
|
|
383
391
|
}
|
|
392
|
+
|
|
393
|
+
private toJSONError(error: unknown): Json {
|
|
394
|
+
if (error instanceof Error) return error.message;
|
|
395
|
+
if (typeof error == "number") return error;
|
|
396
|
+
if (typeof error == "boolean") return error;
|
|
397
|
+
if (typeof error == "string") return error;
|
|
398
|
+
return JSON.parse(
|
|
399
|
+
JSON.stringify(error, Object.getOwnPropertyNames(error)),
|
|
400
|
+
) as Json;
|
|
401
|
+
}
|
|
384
402
|
}
|
|
385
403
|
|
|
386
404
|
class ContextImpl extends SkManaged implements Context {
|
|
@@ -438,71 +456,11 @@ export class ServiceInstanceFactory {
|
|
|
438
456
|
}
|
|
439
457
|
}
|
|
440
458
|
|
|
441
|
-
|
|
442
|
-
request?: string;
|
|
459
|
+
type GetResult<T> = {
|
|
443
460
|
payload: T;
|
|
444
461
|
errors: Json[];
|
|
445
462
|
};
|
|
446
463
|
|
|
447
|
-
export type Executor<T> = {
|
|
448
|
-
resolve: (value: T) => void;
|
|
449
|
-
reject: (reason?: any) => void;
|
|
450
|
-
};
|
|
451
|
-
|
|
452
|
-
class AllChecker<K extends Json, V extends Json> implements Checker {
|
|
453
|
-
constructor(
|
|
454
|
-
private readonly service: ServiceInstance,
|
|
455
|
-
private readonly executor: Executor<Entry<K, V>[]>,
|
|
456
|
-
private readonly resource: string,
|
|
457
|
-
private readonly params: Json,
|
|
458
|
-
) {}
|
|
459
|
-
|
|
460
|
-
check(request: string): void {
|
|
461
|
-
try {
|
|
462
|
-
const result = this.service.getAll<K, V>(
|
|
463
|
-
this.resource,
|
|
464
|
-
this.params,
|
|
465
|
-
request,
|
|
466
|
-
);
|
|
467
|
-
if (result.errors.length > 0) {
|
|
468
|
-
this.executor.reject(new Error(JSON.stringify(result.errors)));
|
|
469
|
-
} else {
|
|
470
|
-
this.executor.resolve(result.payload);
|
|
471
|
-
}
|
|
472
|
-
} catch (ex: unknown) {
|
|
473
|
-
this.executor.reject(ex);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
class OneChecker<K extends Json, V extends Json> implements Checker {
|
|
479
|
-
constructor(
|
|
480
|
-
private readonly service: ServiceInstance,
|
|
481
|
-
private readonly executor: Executor<V[]>,
|
|
482
|
-
private readonly resource: string,
|
|
483
|
-
private readonly params: Json,
|
|
484
|
-
private readonly key: K,
|
|
485
|
-
) {}
|
|
486
|
-
|
|
487
|
-
check(request: string): void {
|
|
488
|
-
try {
|
|
489
|
-
const result = this.service.getArray<K, V>(
|
|
490
|
-
this.resource,
|
|
491
|
-
this.key,
|
|
492
|
-
this.params,
|
|
493
|
-
request,
|
|
494
|
-
);
|
|
495
|
-
if (result.errors.length > 0) {
|
|
496
|
-
this.executor.reject(new Error(JSON.stringify(result.errors)));
|
|
497
|
-
} else {
|
|
498
|
-
this.executor.resolve(result.payload);
|
|
499
|
-
}
|
|
500
|
-
} catch (ex: unknown) {
|
|
501
|
-
this.executor.reject(ex);
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
|
|
506
464
|
export type SubscriptionID = Opaque<bigint, "subscription">;
|
|
507
465
|
|
|
508
466
|
/**
|
|
@@ -522,15 +480,22 @@ export class ServiceInstance {
|
|
|
522
480
|
identifier: string,
|
|
523
481
|
resource: string,
|
|
524
482
|
params: Json,
|
|
525
|
-
): void {
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
483
|
+
): Promise<void> {
|
|
484
|
+
return new Promise((resolve, reject) => {
|
|
485
|
+
const errorHdl = this.refs.runWithGC(() => {
|
|
486
|
+
const exHdl = this.refs.handles.register({
|
|
487
|
+
resolve,
|
|
488
|
+
reject: (ex: Error) => reject(ex),
|
|
489
|
+
});
|
|
490
|
+
return this.refs.binding.SkipRuntime_Runtime__createResource(
|
|
491
|
+
identifier,
|
|
492
|
+
resource,
|
|
493
|
+
this.refs.skjson.exportJSON(params),
|
|
494
|
+
this.refs.binding.SkipRuntime_createExecutor(exHdl),
|
|
495
|
+
);
|
|
496
|
+
});
|
|
497
|
+
if (errorHdl) reject(this.refs.handles.deleteHandle(errorHdl));
|
|
532
498
|
});
|
|
533
|
-
if (errorHdl) throw this.refs.handles.deleteHandle(errorHdl);
|
|
534
499
|
}
|
|
535
500
|
|
|
536
501
|
/**
|
|
@@ -539,33 +504,31 @@ export class ServiceInstance {
|
|
|
539
504
|
* @param params - the parameters of the resource used to build the resource with the corresponding constructor specified in remotes field of SkipService
|
|
540
505
|
* @returns The current values of the corresponding resource with reactive response token to allow subscription
|
|
541
506
|
*/
|
|
542
|
-
getAll<K extends Json, V extends Json>(
|
|
507
|
+
async getAll<K extends Json, V extends Json>(
|
|
543
508
|
resource: string,
|
|
544
509
|
params: Json = {},
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
this.refs.
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
throw this.refs.handles.deleteHandle(result as Handle<Error>);
|
|
568
|
-
return result as GetResult<Entry<K, V>[]>;
|
|
510
|
+
): Promise<Entry<K, V>[]> {
|
|
511
|
+
const uuid = crypto.randomUUID();
|
|
512
|
+
await this.instantiateResource(uuid, resource, params);
|
|
513
|
+
try {
|
|
514
|
+
const result = this.refs.runWithGC(() => {
|
|
515
|
+
return this.refs.skjson.importJSON(
|
|
516
|
+
this.refs.binding.SkipRuntime_Runtime__getAll(
|
|
517
|
+
resource,
|
|
518
|
+
this.refs.skjson.exportJSON(params),
|
|
519
|
+
),
|
|
520
|
+
true,
|
|
521
|
+
);
|
|
522
|
+
});
|
|
523
|
+
if (typeof result == "number")
|
|
524
|
+
throw this.refs.handles.deleteHandle(result as Handle<Error>);
|
|
525
|
+
const info = result as GetResult<Entry<K, V>[]>;
|
|
526
|
+
if (info.errors.length > 0)
|
|
527
|
+
throw new SkipError(JSON.stringify(info.errors));
|
|
528
|
+
return info.payload;
|
|
529
|
+
} finally {
|
|
530
|
+
this.closeResourceInstance(uuid);
|
|
531
|
+
}
|
|
569
532
|
}
|
|
570
533
|
|
|
571
534
|
/**
|
|
@@ -575,36 +538,33 @@ export class ServiceInstance {
|
|
|
575
538
|
* @param params - Resource parameters, passed to the resource constructor specified in this `SkipService`'s `resources` field
|
|
576
539
|
* @returns The current value(s) for this key in the specified resource instance
|
|
577
540
|
*/
|
|
578
|
-
getArray<K extends Json, V extends Json>(
|
|
541
|
+
async getArray<K extends Json, V extends Json>(
|
|
579
542
|
resource: string,
|
|
580
543
|
key: K,
|
|
581
544
|
params: Json = {},
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
this.refs.
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
if (typeof result == "number")
|
|
606
|
-
throw this.refs.handles.deleteHandle(result as Handle<Error>);
|
|
607
|
-
return result as GetResult<V[]>;
|
|
545
|
+
): Promise<V[]> {
|
|
546
|
+
const uuid = crypto.randomUUID();
|
|
547
|
+
await this.instantiateResource(uuid, resource, params);
|
|
548
|
+
try {
|
|
549
|
+
const result = this.refs.runWithGC(() => {
|
|
550
|
+
return this.refs.skjson.importJSON(
|
|
551
|
+
this.refs.binding.SkipRuntime_Runtime__getForKey(
|
|
552
|
+
resource,
|
|
553
|
+
this.refs.skjson.exportJSON(params),
|
|
554
|
+
this.refs.skjson.exportJSON(key),
|
|
555
|
+
),
|
|
556
|
+
true,
|
|
557
|
+
);
|
|
558
|
+
});
|
|
559
|
+
if (typeof result == "number")
|
|
560
|
+
throw this.refs.handles.deleteHandle(result as Handle<Error>);
|
|
561
|
+
const info = result as GetResult<V[]>;
|
|
562
|
+
if (info.errors.length > 0)
|
|
563
|
+
throw new SkipError(JSON.stringify(info.errors));
|
|
564
|
+
return info.payload;
|
|
565
|
+
} finally {
|
|
566
|
+
this.closeResourceInstance(uuid);
|
|
567
|
+
}
|
|
608
568
|
}
|
|
609
569
|
|
|
610
570
|
/**
|
|
@@ -684,16 +644,21 @@ export class ServiceInstance {
|
|
|
684
644
|
update<K extends Json, V extends Json>(
|
|
685
645
|
collection: string,
|
|
686
646
|
entries: Entry<K, V>[],
|
|
687
|
-
): void {
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
647
|
+
): Promise<void> {
|
|
648
|
+
return new Promise((resolve, reject) => {
|
|
649
|
+
const errorHdl = this.refs.runWithGC(() => {
|
|
650
|
+
const exHdl = this.refs.handles.register({
|
|
651
|
+
resolve,
|
|
652
|
+
reject: (ex: Error) => reject(ex),
|
|
653
|
+
});
|
|
654
|
+
return this.refs.binding.SkipRuntime_Runtime__update(
|
|
655
|
+
collection,
|
|
656
|
+
this.refs.skjson.exportJSON(entries),
|
|
657
|
+
this.refs.binding.SkipRuntime_createExecutor(exHdl),
|
|
658
|
+
);
|
|
659
|
+
});
|
|
660
|
+
if (errorHdl) reject(this.refs.handles.deleteHandle(errorHdl));
|
|
693
661
|
});
|
|
694
|
-
if (errorHdl) {
|
|
695
|
-
throw this.refs.handles.deleteHandle(errorHdl);
|
|
696
|
-
}
|
|
697
662
|
}
|
|
698
663
|
|
|
699
664
|
/**
|
|
@@ -840,18 +805,12 @@ export class ToBinding {
|
|
|
840
805
|
const skjson = this.getJsonConverter();
|
|
841
806
|
const mapper = this.handles.get(skmapper);
|
|
842
807
|
const context = new ContextImpl(this.refs());
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
return skjson.exportJSON(Array.from(result));
|
|
850
|
-
} catch (e: unknown) {
|
|
851
|
-
console.error("Uncaught error during Skip runtime reactive update: ", e);
|
|
852
|
-
// Exception in async context will be dropped -- this `throw` is just to appease typechecker
|
|
853
|
-
throw e;
|
|
854
|
-
}
|
|
808
|
+
const result = mapper.mapEntry(
|
|
809
|
+
skjson.importJSON(key) as Json,
|
|
810
|
+
new ValuesImpl<Json>(skjson, this.binding, values),
|
|
811
|
+
context,
|
|
812
|
+
);
|
|
813
|
+
return skjson.exportJSON(Array.from(result));
|
|
855
814
|
}
|
|
856
815
|
|
|
857
816
|
SkipRuntime_deleteMapper(mapper: Handle<JSONMapper>): void {
|
|
@@ -1036,11 +995,22 @@ export class ToBinding {
|
|
|
1036
995
|
const supplier = this.handles.get(sksupplier);
|
|
1037
996
|
const writer = new CollectionWriter(writerId, this.refs());
|
|
1038
997
|
const params = skjson.importJSON(skparams, true) as Json;
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
998
|
+
// Ensure notification is made outside the current context update
|
|
999
|
+
setTimeout(() => {
|
|
1000
|
+
supplier
|
|
1001
|
+
.subscribe(instance, resource, params, {
|
|
1002
|
+
update: writer.update.bind(writer),
|
|
1003
|
+
error: writer.error.bind(writer),
|
|
1004
|
+
})
|
|
1005
|
+
.then(() => writer.initialized())
|
|
1006
|
+
.catch((e: unknown) =>
|
|
1007
|
+
writer.initialized(
|
|
1008
|
+
e instanceof Error
|
|
1009
|
+
? e.message
|
|
1010
|
+
: JSON.stringify(e, Object.getOwnPropertyNames(e)),
|
|
1011
|
+
),
|
|
1012
|
+
);
|
|
1013
|
+
}, 0);
|
|
1044
1014
|
}
|
|
1045
1015
|
|
|
1046
1016
|
SkipRuntime_ExternalService__unsubscribe(
|
|
@@ -1062,58 +1032,76 @@ export class ToBinding {
|
|
|
1062
1032
|
this.handles.deleteHandle(supplier);
|
|
1063
1033
|
}
|
|
1064
1034
|
|
|
1065
|
-
//
|
|
1035
|
+
// Executor
|
|
1066
1036
|
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
): void {
|
|
1071
|
-
const checker = this.handles.get(skchecker);
|
|
1072
|
-
checker.check(request);
|
|
1073
|
-
}
|
|
1074
|
-
|
|
1075
|
-
SkipRuntime_deleteChecker(checker: Handle<Checker>): void {
|
|
1076
|
-
this.handles.deleteHandle(checker);
|
|
1037
|
+
SkipRuntime_Executor__resolve(skexecutor: Handle<Executor>): void {
|
|
1038
|
+
const checker = this.handles.get(skexecutor);
|
|
1039
|
+
checker.resolve();
|
|
1077
1040
|
}
|
|
1078
1041
|
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1042
|
+
SkipRuntime_Executor__reject(
|
|
1043
|
+
skexecutor: Handle<Executor>,
|
|
1044
|
+
error: Handle<Error>,
|
|
1045
|
+
): void {
|
|
1046
|
+
const checker = this.handles.get(skexecutor);
|
|
1047
|
+
checker.reject(this.handles.deleteHandle(error));
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
SkipRuntime_deleteExecutor(executor: Handle<Executor>): void {
|
|
1051
|
+
this.handles.deleteHandle(executor);
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
initService(service: SkipService): Promise<ServiceInstance> {
|
|
1055
|
+
return new Promise((resolve, reject) => {
|
|
1056
|
+
const refs = this.refs();
|
|
1057
|
+
const errorHdl = refs.runWithGC(() => {
|
|
1058
|
+
const skExternalServices =
|
|
1059
|
+
refs.binding.SkipRuntime_ExternalServiceMap__create();
|
|
1060
|
+
if (service.externalServices) {
|
|
1061
|
+
for (const [name, remote] of Object.entries(
|
|
1062
|
+
service.externalServices,
|
|
1063
|
+
)) {
|
|
1064
|
+
const skremote = refs.binding.SkipRuntime_createExternalService(
|
|
1065
|
+
refs.handles.register(remote),
|
|
1066
|
+
);
|
|
1067
|
+
refs.binding.SkipRuntime_ExternalServiceMap__add(
|
|
1068
|
+
skExternalServices,
|
|
1069
|
+
name,
|
|
1070
|
+
skremote,
|
|
1071
|
+
);
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
const skresources =
|
|
1075
|
+
refs.binding.SkipRuntime_ResourceBuilderMap__create();
|
|
1076
|
+
for (const [name, builder] of Object.entries(service.resources)) {
|
|
1077
|
+
const skbuilder = refs.binding.SkipRuntime_createResourceBuilder(
|
|
1078
|
+
refs.handles.register(new ResourceBuilder(builder)),
|
|
1088
1079
|
);
|
|
1089
|
-
refs.binding.
|
|
1090
|
-
|
|
1080
|
+
refs.binding.SkipRuntime_ResourceBuilderMap__add(
|
|
1081
|
+
skresources,
|
|
1091
1082
|
name,
|
|
1092
|
-
|
|
1083
|
+
skbuilder,
|
|
1093
1084
|
);
|
|
1094
1085
|
}
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
const skbuilder = refs.binding.SkipRuntime_createResourceBuilder(
|
|
1099
|
-
refs.handles.register(new ResourceBuilder(builder)),
|
|
1100
|
-
);
|
|
1101
|
-
refs.binding.SkipRuntime_ResourceBuilderMap__add(
|
|
1086
|
+
const skservice = refs.binding.SkipRuntime_createService(
|
|
1087
|
+
refs.handles.register(service),
|
|
1088
|
+
refs.skjson.exportJSON(service.initialData ?? {}),
|
|
1102
1089
|
skresources,
|
|
1103
|
-
|
|
1104
|
-
skbuilder,
|
|
1090
|
+
skExternalServices,
|
|
1105
1091
|
);
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1092
|
+
const exHdl = refs.handles.register({
|
|
1093
|
+
resolve: () => {
|
|
1094
|
+
resolve(new ServiceInstance(refs));
|
|
1095
|
+
},
|
|
1096
|
+
reject: (ex: Error) => reject(ex),
|
|
1097
|
+
});
|
|
1098
|
+
return refs.binding.SkipRuntime_initService(
|
|
1099
|
+
skservice,
|
|
1100
|
+
refs.binding.SkipRuntime_createExecutor(exHdl),
|
|
1101
|
+
);
|
|
1102
|
+
});
|
|
1103
|
+
if (errorHdl) reject(refs.handles.deleteHandle(errorHdl));
|
|
1114
1104
|
});
|
|
1115
|
-
if (errorHdl) throw refs.handles.deleteHandle(errorHdl);
|
|
1116
|
-
return new ServiceInstance(refs);
|
|
1117
1105
|
}
|
|
1118
1106
|
|
|
1119
1107
|
//
|
package/src/internal.ts
CHANGED
|
@@ -51,5 +51,5 @@ export type Reducer = T<typeof reducer>;
|
|
|
51
51
|
declare const notifier: unique symbol;
|
|
52
52
|
export type Notifier = T<typeof notifier>;
|
|
53
53
|
|
|
54
|
-
declare const
|
|
55
|
-
export type
|
|
54
|
+
declare const executor: unique symbol;
|
|
55
|
+
export type Executor = T<typeof executor>;
|