@agoric/time 0.3.3-dev-2dc53d7.0 → 0.3.3-dev-0f94e34.0
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/package.json +4 -4
- package/src/timeMath.js +21 -17
- package/src/types.d.ts +10 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/time",
|
|
3
|
-
"version": "0.3.3-dev-
|
|
3
|
+
"version": "0.3.3-dev-0f94e34.0+0f94e34",
|
|
4
4
|
"description": "Timestamps, time math, timer service API definition",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/Agoric/agoric-sdk#readme",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@agoric/assert": "0.6.1-dev-
|
|
34
|
+
"@agoric/assert": "0.6.1-dev-0f94e34.0+0f94e34",
|
|
35
35
|
"@endo/nat": "^5.0.7",
|
|
36
36
|
"@endo/patterns": "^1.4.0"
|
|
37
37
|
},
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"access": "public"
|
|
59
59
|
},
|
|
60
60
|
"typeCoverage": {
|
|
61
|
-
"atLeast": 87.
|
|
61
|
+
"atLeast": 87.29
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "0f94e34eb539b8f91c82d0877df836738e58cc69"
|
|
64
64
|
}
|
package/src/timeMath.js
CHANGED
|
@@ -2,14 +2,16 @@ import { Nat } from '@endo/nat';
|
|
|
2
2
|
import { mustMatch } from '@endo/patterns';
|
|
3
3
|
import { RelativeTimeRecordShape, TimestampRecordShape } from './typeGuards.js';
|
|
4
4
|
|
|
5
|
+
/** @import {RelativeTime, RelativeTimeValue, TimerBrand, TimeMathType, Timestamp, TimestampRecord, TimestampValue} from './types.js' */
|
|
6
|
+
|
|
5
7
|
const { Fail, quote: q } = assert;
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* `agreedTimerBrand` is internal to this module.
|
|
9
11
|
*
|
|
10
|
-
* @param {
|
|
11
|
-
* @param {
|
|
12
|
-
* @returns {
|
|
12
|
+
* @param {TimerBrand | undefined} leftBrand
|
|
13
|
+
* @param {TimerBrand | undefined} rightBrand
|
|
14
|
+
* @returns {TimerBrand | undefined}
|
|
13
15
|
*/
|
|
14
16
|
const agreedTimerBrand = (leftBrand, rightBrand) => {
|
|
15
17
|
if (leftBrand === undefined) {
|
|
@@ -34,9 +36,9 @@ const agreedTimerBrand = (leftBrand, rightBrand) => {
|
|
|
34
36
|
* this logic. It does the error checking between the operands, and returns
|
|
35
37
|
* the brand, if any, that should label the resulting time value.
|
|
36
38
|
*
|
|
37
|
-
* @param {
|
|
38
|
-
* @param {
|
|
39
|
-
* @returns {
|
|
39
|
+
* @param {Timestamp | RelativeTime} left
|
|
40
|
+
* @param {Timestamp | RelativeTime} right
|
|
41
|
+
* @returns {TimerBrand | undefined}
|
|
40
42
|
*/
|
|
41
43
|
const sharedTimerBrand = (left, right) => {
|
|
42
44
|
const leftBrand = typeof left === 'bigint' ? undefined : left.timerBrand;
|
|
@@ -49,10 +51,10 @@ const sharedTimerBrand = (left, right) => {
|
|
|
49
51
|
* operators in the case where the returned time should be a `Timestamp`
|
|
50
52
|
* rather than a `RelativeTime`.
|
|
51
53
|
*
|
|
52
|
-
* @param {
|
|
53
|
-
* @param {
|
|
54
|
-
* @param {
|
|
55
|
-
* @returns {
|
|
54
|
+
* @param {Timestamp | RelativeTime} left
|
|
55
|
+
* @param {Timestamp | RelativeTime} right
|
|
56
|
+
* @param {TimestampValue} absValue
|
|
57
|
+
* @returns {Timestamp}
|
|
56
58
|
*/
|
|
57
59
|
const absLike = (left, right, absValue) => {
|
|
58
60
|
Nat(absValue);
|
|
@@ -72,10 +74,10 @@ const absLike = (left, right, absValue) => {
|
|
|
72
74
|
* operators in the case where the returned time should be a `RelativeTime`
|
|
73
75
|
* rather than a `Timestamp`.
|
|
74
76
|
*
|
|
75
|
-
* @param {
|
|
76
|
-
* @param {
|
|
77
|
-
* @param {
|
|
78
|
-
* @returns {
|
|
77
|
+
* @param {Timestamp | RelativeTime} left
|
|
78
|
+
* @param {Timestamp | RelativeTime} right
|
|
79
|
+
* @param {RelativeTimeValue} relValue
|
|
80
|
+
* @returns {RelativeTime}
|
|
79
81
|
*/
|
|
80
82
|
const relLike = (left, right, relValue) => {
|
|
81
83
|
Nat(relValue);
|
|
@@ -187,8 +189,8 @@ const modRelRel = (rel, step) =>
|
|
|
187
189
|
* `compareValues` is internal to this module, and used to implement
|
|
188
190
|
* the time comparison operators.
|
|
189
191
|
*
|
|
190
|
-
* @param {
|
|
191
|
-
* @param {
|
|
192
|
+
* @param {Timestamp | RelativeTime} left
|
|
193
|
+
* @param {Timestamp | RelativeTime} right
|
|
192
194
|
* @param {bigint} v1
|
|
193
195
|
* @param {bigint} v2
|
|
194
196
|
* @returns {import('@endo/marshal').RankComparison}
|
|
@@ -237,14 +239,16 @@ const compareValues = (left, right, v1, v2) => {
|
|
|
237
239
|
* operand, and return a labeled time object with the brand of the labeled
|
|
238
240
|
* operand.
|
|
239
241
|
*
|
|
240
|
-
* @type {
|
|
242
|
+
* @type {TimeMathType}
|
|
241
243
|
*/
|
|
242
244
|
export const TimeMath = harden({
|
|
243
245
|
absValue,
|
|
244
246
|
relValue,
|
|
245
247
|
coerceTimestampRecord,
|
|
246
248
|
coerceRelativeTimeRecord,
|
|
249
|
+
// @ts-expect-error xxx dynamic typing
|
|
247
250
|
addAbsRel,
|
|
251
|
+
// @ts-expect-error xxx dynamic typing
|
|
248
252
|
addRelRel,
|
|
249
253
|
subtractAbsAbs,
|
|
250
254
|
clampedSubtractAbsAbs,
|
package/src/types.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { ERef, RemotableBrand } from '@endo/eventual-send';
|
|
|
2
2
|
|
|
3
3
|
import type { RankComparison, RemotableObject } from '@endo/marshal';
|
|
4
4
|
|
|
5
|
-
/// <reference types="@agoric/notifier/src/types.js"/>
|
|
5
|
+
/// <reference types="@agoric/notifier/src/types.js" />
|
|
6
6
|
|
|
7
7
|
// These aren't in the global runtime environment. They are just types that are
|
|
8
8
|
// meant to be globally accessible as a side-effect of importing this module.
|
|
@@ -167,7 +167,7 @@ export interface TimerServiceI {
|
|
|
167
167
|
delay: RelativeTime,
|
|
168
168
|
interval: RelativeTime,
|
|
169
169
|
cancelToken?: CancelToken,
|
|
170
|
-
) => Notifier<TimestampRecord>;
|
|
170
|
+
) => import('@agoric/notifier').Notifier<TimestampRecord>;
|
|
171
171
|
/**
|
|
172
172
|
* Cancel a previously-established wakeup or repeater.
|
|
173
173
|
*/
|
|
@@ -290,17 +290,19 @@ export type TimeMathType = {
|
|
|
290
290
|
) => RelativeTimeRecord;
|
|
291
291
|
/**
|
|
292
292
|
* An absolute time + a relative time gives a new absolute time.
|
|
293
|
-
*
|
|
294
|
-
* @template {Timestamp} T
|
|
295
293
|
*/
|
|
296
|
-
addAbsRel:
|
|
294
|
+
addAbsRel: <T extends Timestamp>(
|
|
295
|
+
abs: T,
|
|
296
|
+
rel: RelativeTime,
|
|
297
|
+
) => T extends TimestampRecord ? TimestampRecord : TimestampValue;
|
|
297
298
|
/**
|
|
298
299
|
* A relative time (i.e., a duration) + another relative time
|
|
299
300
|
* gives a new relative time.
|
|
300
|
-
*
|
|
301
|
-
* @template {RelativeTime} T
|
|
302
301
|
*/
|
|
303
|
-
addRelRel:
|
|
302
|
+
addRelRel: <T extends RelativeTime>(
|
|
303
|
+
rel1: T,
|
|
304
|
+
rel2: T,
|
|
305
|
+
) => T extends RelativeTimeRecord ? RelativeTimeRecord : RelativeTimeValue;
|
|
304
306
|
/**
|
|
305
307
|
* The difference between two absolute times is a relative time. If abs1 > abs2
|
|
306
308
|
* the difference would be negative, so this method throws instead.
|