@skipruntime/core 0.0.2 → 0.0.3

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/utils.d.ts CHANGED
@@ -1,22 +1,55 @@
1
1
  import type { Nullable } from "@skip-wasm/std";
2
2
  import { ManyToOneMapper } from "@skipruntime/api";
3
- import type { Reducer, NonEmptyIterator, Json } from "@skipruntime/api";
3
+ import type { Reducer, Values, Json } from "@skipruntime/api";
4
+ /**
5
+ * `Reducer` to maintain the sum of input values.
6
+ *
7
+ * A `Reducer` that maintains the sum of values as they are added and removed from a collection.
8
+ */
4
9
  export declare class Sum implements Reducer<number, number> {
5
- default: number;
6
- add(acc: number, value: number): number;
7
- remove(acc: number, value: number): Nullable<number>;
10
+ initial: number;
11
+ add(accum: number, value: number): number;
12
+ remove(accum: number, value: number): Nullable<number>;
8
13
  }
14
+ /**
15
+ * `Reducer` to maintain the minimum of input values.
16
+ *
17
+ * A `Reducer` that maintains the minimum of values as they are added and removed from a collection.
18
+ */
9
19
  export declare class Min implements Reducer<number, number> {
10
- default: null;
11
- add(acc: Nullable<number>, value: number): number;
12
- remove(acc: number, value: number): Nullable<number>;
20
+ initial: null;
21
+ add(accum: Nullable<number>, value: number): number;
22
+ remove(accum: number, value: number): Nullable<number>;
13
23
  }
24
+ /**
25
+ * `Reducer` to maintain the maximum of input values.
26
+ *
27
+ * A `Reducer` that maintains the maximum of values as they are added and removed from a collection.
28
+ */
14
29
  export declare class Max implements Reducer<number, number> {
15
- default: null;
16
- add(acc: Nullable<number>, value: number): number;
17
- remove(acc: number, value: number): Nullable<number>;
30
+ initial: null;
31
+ add(accum: Nullable<number>, value: number): number;
32
+ remove(accum: number, value: number): Nullable<number>;
18
33
  }
34
+ /**
35
+ * `Reducer` to maintain the count of input values.
36
+ *
37
+ * A `Reducer` that maintains the number of values as they are added and removed from a collection.
38
+ */
39
+ export declare class Count<T extends Json> implements Reducer<T, number> {
40
+ initial: number;
41
+ add(accum: number): number;
42
+ remove(accum: number): Nullable<number>;
43
+ }
44
+ /**
45
+ * `Mapper` to count input values.
46
+ *
47
+ * A `Mapper` that associates each key in the output with the number of values it is associated with in the input.
48
+ *
49
+ * @remarks
50
+ * If there are many values associated to keys in a collection, and they are updated frequently, using the `Count` `Reducer` instead could be more efficient.
51
+ */
19
52
  export declare class CountMapper<K extends Json, V extends Json> extends ManyToOneMapper<K, V, number> {
20
- mapValues(values: NonEmptyIterator<V>): number;
53
+ mapValues(values: Values<V>): number;
21
54
  }
22
55
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExE,qBAAa,GAAI,YAAW,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC;IACjD,OAAO,SAAK;IAEZ,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;IAIvC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;CAGrD;AAED,qBAAa,GAAI,YAAW,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC;IACjD,OAAO,OAAQ;IAEf,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;IAIjD,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;CAGrD;AAED,qBAAa,GAAI,YAAW,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC;IACjD,OAAO,OAAQ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,GAAI,YAAW,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC;IACjD,OAAO,OAAQ;IAEf,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;IAInD,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;CAGvD;AAED;;;;GAIG;AACH,qBAAa,KAAK,CAAC,CAAC,SAAS,IAAI,CAAE,YAAW,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC;IAC9D,OAAO,SAAK;IAEZ,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAI1B,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;CAGxC;AAED;;;;;;;GAOG;AACH,qBAAa,WAAW,CACtB,CAAC,SAAS,IAAI,EACd,CAAC,SAAS,IAAI,CACd,SAAQ,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM;CAGrC"}
package/dist/utils.js CHANGED
@@ -1,37 +1,76 @@
1
1
  import { ManyToOneMapper } from "@skipruntime/api";
2
+ /**
3
+ * `Reducer` to maintain the sum of input values.
4
+ *
5
+ * A `Reducer` that maintains the sum of values as they are added and removed from a collection.
6
+ */
2
7
  export class Sum {
3
8
  constructor() {
4
- this.default = 0;
9
+ this.initial = 0;
5
10
  }
6
- add(acc, value) {
7
- return acc + value;
11
+ add(accum, value) {
12
+ return accum + value;
8
13
  }
9
- remove(acc, value) {
10
- return acc - value;
14
+ remove(accum, value) {
15
+ return accum - value;
11
16
  }
12
17
  }
18
+ /**
19
+ * `Reducer` to maintain the minimum of input values.
20
+ *
21
+ * A `Reducer` that maintains the minimum of values as they are added and removed from a collection.
22
+ */
13
23
  export class Min {
14
24
  constructor() {
15
- this.default = null;
25
+ this.initial = null;
16
26
  }
17
- add(acc, value) {
18
- return acc === null ? value : Math.min(acc, value);
27
+ add(accum, value) {
28
+ return accum === null ? value : Math.min(accum, value);
19
29
  }
20
- remove(acc, value) {
21
- return value > acc ? acc : null;
30
+ remove(accum, value) {
31
+ return value > accum ? accum : null;
22
32
  }
23
33
  }
34
+ /**
35
+ * `Reducer` to maintain the maximum of input values.
36
+ *
37
+ * A `Reducer` that maintains the maximum of values as they are added and removed from a collection.
38
+ */
24
39
  export class Max {
25
40
  constructor() {
26
- this.default = null;
41
+ this.initial = null;
27
42
  }
28
- add(acc, value) {
29
- return acc === null ? value : Math.max(acc, value);
43
+ add(accum, value) {
44
+ return accum === null ? value : Math.max(accum, value);
30
45
  }
31
- remove(acc, value) {
32
- return value < acc ? acc : null;
46
+ remove(accum, value) {
47
+ return value < accum ? accum : null;
33
48
  }
34
49
  }
50
+ /**
51
+ * `Reducer` to maintain the count of input values.
52
+ *
53
+ * A `Reducer` that maintains the number of values as they are added and removed from a collection.
54
+ */
55
+ export class Count {
56
+ constructor() {
57
+ this.initial = 0;
58
+ }
59
+ add(accum) {
60
+ return accum + 1;
61
+ }
62
+ remove(accum) {
63
+ return accum - 1;
64
+ }
65
+ }
66
+ /**
67
+ * `Mapper` to count input values.
68
+ *
69
+ * A `Mapper` that associates each key in the output with the number of values it is associated with in the input.
70
+ *
71
+ * @remarks
72
+ * If there are many values associated to keys in a collection, and they are updated frequently, using the `Count` `Reducer` instead could be more efficient.
73
+ */
35
74
  export class CountMapper extends ManyToOneMapper {
36
75
  mapValues(values) {
37
76
  return values.toArray().length;
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGnD,MAAM,OAAO,GAAG;IAAhB;QACE,YAAO,GAAG,CAAC,CAAC;IASd,CAAC;IAPC,GAAG,CAAC,GAAW,EAA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G;AACH,MAAM,OAAO,WAGX,SAAQ,eAA6B;IACrC,SAAS,CAAC,MAAiB;QACzB,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC;IACjC,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skipruntime/core",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
@@ -13,6 +13,6 @@
13
13
  "lint": "eslint"
14
14
  },
15
15
  "dependencies": {
16
- "@skipruntime/api": "^0.0.4"
16
+ "@skipruntime/api": "^0.0.5"
17
17
  }
18
18
  }
package/src/binding.ts CHANGED
@@ -14,13 +14,9 @@ import {
14
14
  export type Handle<T> = Internal.Opaque<number, { handle_for: T }>;
15
15
 
16
16
  export class ResourceBuilder {
17
- constructor(
18
- private readonly builder: new (params: {
19
- [param: string]: string;
20
- }) => Resource,
21
- ) {}
17
+ constructor(private readonly builder: new (params: Json) => Resource) {}
22
18
 
23
- build(parameters: { [param: string]: string }): Resource {
19
+ build(parameters: Json): Resource {
24
20
  const builder = this.builder;
25
21
  return new builder(parameters);
26
22
  }