@twin.org/core 0.0.4-next.9 → 0.9.0-next.1

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.
Files changed (46) hide show
  1. package/dist/es/index.js +3 -0
  2. package/dist/es/index.js.map +1 -1
  3. package/dist/es/models/IDuration.js +4 -0
  4. package/dist/es/models/IDuration.js.map +1 -0
  5. package/dist/es/models/coerceType.js +5 -1
  6. package/dist/es/models/coerceType.js.map +1 -1
  7. package/dist/es/types/duration.js +184 -0
  8. package/dist/es/types/duration.js.map +1 -0
  9. package/dist/es/types/durationRegExp.js +4 -0
  10. package/dist/es/types/durationRegExp.js.map +1 -0
  11. package/dist/es/types/url.js +1 -0
  12. package/dist/es/types/url.js.map +1 -1
  13. package/dist/es/utils/coerce.js +24 -0
  14. package/dist/es/utils/coerce.js.map +1 -1
  15. package/dist/es/utils/guards.js +12 -0
  16. package/dist/es/utils/guards.js.map +1 -1
  17. package/dist/es/utils/is.js +56 -7
  18. package/dist/es/utils/is.js.map +1 -1
  19. package/dist/es/utils/mutex.js +49 -8
  20. package/dist/es/utils/mutex.js.map +1 -1
  21. package/dist/es/utils/sharedObjectBuffer.js +4 -1
  22. package/dist/es/utils/sharedObjectBuffer.js.map +1 -1
  23. package/dist/types/index.d.ts +3 -0
  24. package/dist/types/models/IDuration.d.ts +45 -0
  25. package/dist/types/models/coerceType.d.ts +4 -0
  26. package/dist/types/types/duration.d.ts +29 -0
  27. package/dist/types/types/durationRegExp.d.ts +1 -0
  28. package/dist/types/types/url.d.ts +1 -0
  29. package/dist/types/utils/coerce.d.ts +9 -0
  30. package/dist/types/utils/guards.d.ts +9 -0
  31. package/dist/types/utils/is.d.ts +7 -0
  32. package/dist/types/utils/mutex.d.ts +12 -1
  33. package/docs/changelog.md +251 -0
  34. package/docs/reference/classes/Coerce.md +24 -0
  35. package/docs/reference/classes/Duration.md +88 -0
  36. package/docs/reference/classes/Guards.md +36 -0
  37. package/docs/reference/classes/Is.md +22 -0
  38. package/docs/reference/classes/Mutex.md +39 -1
  39. package/docs/reference/classes/ObjectHelper.md +8 -0
  40. package/docs/reference/classes/Url.md +4 -0
  41. package/docs/reference/index.md +3 -0
  42. package/docs/reference/interfaces/IDuration.md +83 -0
  43. package/docs/reference/variables/CoerceType.md +6 -0
  44. package/docs/reference/variables/DURATION_REG_EXP.md +3 -0
  45. package/locales/en.json +4 -2
  46. package/package.json +3 -3
@@ -0,0 +1,88 @@
1
+ # Class: Duration
2
+
3
+ Helper methods for working with ISO 8601 durations.
4
+
5
+ ## Constructors
6
+
7
+ ### Constructor
8
+
9
+ > **new Duration**(): `Duration`
10
+
11
+ #### Returns
12
+
13
+ `Duration`
14
+
15
+ ## Properties
16
+
17
+ ### CLASS\_NAME {#class_name}
18
+
19
+ > `readonly` `static` **CLASS\_NAME**: `string`
20
+
21
+ Runtime name for the class.
22
+
23
+ ## Methods
24
+
25
+ ### parse() {#parse}
26
+
27
+ > `static` **parse**(`value`): [`IDuration`](../interfaces/IDuration.md) \| `undefined`
28
+
29
+ Parse an ISO 8601 duration string into its component parts.
30
+
31
+ #### Parameters
32
+
33
+ ##### value
34
+
35
+ `string`
36
+
37
+ The string to parse.
38
+
39
+ #### Returns
40
+
41
+ [`IDuration`](../interfaces/IDuration.md) \| `undefined`
42
+
43
+ The parsed duration, or undefined if the string is not a valid ISO 8601 duration.
44
+
45
+ ***
46
+
47
+ ### toString() {#tostring}
48
+
49
+ > `static` **toString**(`duration`): `string`
50
+
51
+ Convert a duration object to an ISO 8601 duration string.
52
+
53
+ #### Parameters
54
+
55
+ ##### duration
56
+
57
+ [`IDuration`](../interfaces/IDuration.md)
58
+
59
+ The duration to convert.
60
+
61
+ #### Returns
62
+
63
+ `string`
64
+
65
+ The ISO 8601 duration string (e.g. "P1Y2M3DT4H5M6S").
66
+
67
+ ***
68
+
69
+ ### toSeconds() {#toseconds}
70
+
71
+ > `static` **toSeconds**(`duration`): `number`
72
+
73
+ Convert a duration object to total seconds.
74
+ Year and month components use the average values 365.25 days and 30.4375 days.
75
+
76
+ #### Parameters
77
+
78
+ ##### duration
79
+
80
+ [`IDuration`](../interfaces/IDuration.md)
81
+
82
+ The duration to convert.
83
+
84
+ #### Returns
85
+
86
+ `number`
87
+
88
+ The total number of seconds.
@@ -1181,3 +1181,39 @@ The format of the uuidV7, either standard or compact.
1181
1181
  #### Throws
1182
1182
 
1183
1183
  GuardError If the value does not match the assertion.
1184
+
1185
+ ***
1186
+
1187
+ ### duration() {#duration}
1188
+
1189
+ > `static` **duration**(`source`, `property`, `value`): asserts value is string \| IDuration
1190
+
1191
+ Is the property a valid ISO 8601 duration string or IDuration object.
1192
+
1193
+ #### Parameters
1194
+
1195
+ ##### source
1196
+
1197
+ `string`
1198
+
1199
+ The source of the error.
1200
+
1201
+ ##### property
1202
+
1203
+ `string`
1204
+
1205
+ The name of the property.
1206
+
1207
+ ##### value
1208
+
1209
+ `unknown`
1210
+
1211
+ The value to test.
1212
+
1213
+ #### Returns
1214
+
1215
+ asserts value is string \| IDuration
1216
+
1217
+ #### Throws
1218
+
1219
+ GuardError If the value does not match the assertion.
@@ -881,3 +881,25 @@ The format of the UUIDv7 string.
881
881
  `value is string`
882
882
 
883
883
  True if the value is a uuidV7 string.
884
+
885
+ ***
886
+
887
+ ### duration() {#duration}
888
+
889
+ > `static` **duration**(`value`): value is string \| IDuration
890
+
891
+ Is the value a valid ISO 8601 duration string or an IDuration object.
892
+
893
+ #### Parameters
894
+
895
+ ##### value
896
+
897
+ `unknown`
898
+
899
+ The value to test.
900
+
901
+ #### Returns
902
+
903
+ value is string \| IDuration
904
+
905
+ True if the value is a valid ISO 8601 duration string or an IDuration object.
@@ -35,6 +35,44 @@ Runtime name for the class.
35
35
 
36
36
  ## Methods
37
37
 
38
+ ### getDefaultTimeoutMs() {#getdefaulttimeoutms}
39
+
40
+ > `static` **getDefaultTimeoutMs**(): `number`
41
+
42
+ Gets the default timeout in milliseconds for lock acquisition.
43
+
44
+ #### Returns
45
+
46
+ `number`
47
+
48
+ The default timeout in milliseconds.
49
+
50
+ ***
51
+
52
+ ### setDefaultTimeoutMs() {#setdefaulttimeoutms}
53
+
54
+ > `static` **setDefaultTimeoutMs**(`timeoutMs`): `void`
55
+
56
+ Sets the default timeout in milliseconds for lock acquisition.
57
+
58
+ #### Parameters
59
+
60
+ ##### timeoutMs
61
+
62
+ `number`
63
+
64
+ The default timeout in milliseconds.
65
+
66
+ #### Returns
67
+
68
+ `void`
69
+
70
+ #### Throws
71
+
72
+ GeneralError if timeoutMs is not a non-negative integer.
73
+
74
+ ***
75
+
38
76
  ### lock() {#lock}
39
77
 
40
78
  > `static` **lock**(`key`, `options?`): `Promise`\<`boolean`\>
@@ -62,7 +100,7 @@ Lock options.
62
100
 
63
101
  `number`
64
102
 
65
- The maximum time to wait for the lock in milliseconds, default is 5000.
103
+ The maximum time to wait for the lock in milliseconds, defaults to getDefaultTimeoutMs().
66
104
 
67
105
  ###### throwOnTimeout?
68
106
 
@@ -336,10 +336,14 @@ Pick a subset of properties from an object.
336
336
 
337
337
  #### Param
338
338
 
339
+ **obj**
340
+
339
341
  The object to pick the properties from.
340
342
 
341
343
  #### Param
342
344
 
345
+ **keys**
346
+
343
347
  The property keys to pick.
344
348
 
345
349
  #### Call Signature
@@ -422,10 +426,14 @@ Omit a subset of properties from an object.
422
426
 
423
427
  #### Param
424
428
 
429
+ **obj**
430
+
425
431
  The object to omit the properties from.
426
432
 
427
433
  #### Param
428
434
 
435
+ **keys**
436
+
429
437
  The property keys to omit.
430
438
 
431
439
  #### Call Signature
@@ -22,6 +22,10 @@ The url string.
22
22
 
23
23
  `Url`
24
24
 
25
+ #### Throws
26
+
27
+ GuardError if the url is not valid.
28
+
25
29
  ## Properties
26
30
 
27
31
  ### CLASS\_NAME {#class_name}
@@ -30,6 +30,7 @@
30
30
  - [StringHelper](classes/StringHelper.md)
31
31
  - [Uint8ArrayHelper](classes/Uint8ArrayHelper.md)
32
32
  - [BitString](classes/BitString.md)
33
+ - [Duration](classes/Duration.md)
33
34
  - [Url](classes/Url.md)
34
35
  - [Urn](classes/Urn.md)
35
36
  - [AsyncCache](classes/AsyncCache.md)
@@ -47,6 +48,7 @@
47
48
  ## Interfaces
48
49
 
49
50
  - [IComponent](interfaces/IComponent.md)
51
+ - [IDuration](interfaces/IDuration.md)
50
52
  - [IError](interfaces/IError.md)
51
53
  - [IHealth](interfaces/IHealth.md)
52
54
  - [II18nShared](interfaces/II18nShared.md)
@@ -81,3 +83,4 @@
81
83
  - [HealthStatus](variables/HealthStatus.md)
82
84
  - [MutexMessageTypes](variables/MutexMessageTypes.md)
83
85
  - [SharedObjectBufferMessageTypes](variables/SharedObjectBufferMessageTypes.md)
86
+ - [DURATION\_REG\_EXP](variables/DURATION_REG_EXP.md)
@@ -0,0 +1,83 @@
1
+ # Interface: IDuration
2
+
3
+ Represents a duration broken down into its component parts.
4
+
5
+ ## Properties
6
+
7
+ ### years {#years}
8
+
9
+ > **years**: `number`
10
+
11
+ The number of years.
12
+
13
+ ***
14
+
15
+ ### months {#months}
16
+
17
+ > **months**: `number`
18
+
19
+ The number of months.
20
+
21
+ ***
22
+
23
+ ### weeks {#weeks}
24
+
25
+ > **weeks**: `number`
26
+
27
+ The number of weeks.
28
+
29
+ ***
30
+
31
+ ### days {#days}
32
+
33
+ > **days**: `number`
34
+
35
+ The number of days.
36
+
37
+ ***
38
+
39
+ ### hours {#hours}
40
+
41
+ > **hours**: `number`
42
+
43
+ The number of hours.
44
+
45
+ ***
46
+
47
+ ### minutes {#minutes}
48
+
49
+ > **minutes**: `number`
50
+
51
+ The number of minutes.
52
+
53
+ ***
54
+
55
+ ### seconds {#seconds}
56
+
57
+ > **seconds**: `number`
58
+
59
+ The number of seconds.
60
+
61
+ ***
62
+
63
+ ### milliseconds? {#milliseconds}
64
+
65
+ > `optional` **milliseconds?**: `number`
66
+
67
+ The number of milliseconds.
68
+
69
+ ***
70
+
71
+ ### microseconds? {#microseconds}
72
+
73
+ > `optional` **microseconds?**: `number`
74
+
75
+ The number of microseconds.
76
+
77
+ ***
78
+
79
+ ### nanoseconds? {#nanoseconds}
80
+
81
+ > `optional` **nanoseconds?**: `number`
82
+
83
+ The number of nanoseconds.
@@ -65,3 +65,9 @@ Object.
65
65
  > `readonly` **Uint8Array**: `"uint8array"` = `"uint8array"`
66
66
 
67
67
  Uint8Array.
68
+
69
+ ### Duration {#duration}
70
+
71
+ > `readonly` **Duration**: `"duration"` = `"duration"`
72
+
73
+ Duration in seconds.
@@ -0,0 +1,3 @@
1
+ # Variable: DURATION\_REG\_EXP
2
+
3
+ > `const` **DURATION\_REG\_EXP**: `RegExp`
package/locales/en.json CHANGED
@@ -74,7 +74,8 @@
74
74
  "url": "Property \"{property}\" must be a URL formatted string, it is \"{value}\"",
75
75
  "email": "Property \"{property}\" must be string in e-mail format, it is \"{value}\"",
76
76
  "uuidV7": "Property \"{property}\" must be a UUIDv7 formatted string, it is \"{value}\"",
77
- "uuidV7Compact": "Property \"{property}\" must be a UUIDv7 formatted string in compact mode, it is \"{value}\""
77
+ "uuidV7Compact": "Property \"{property}\" must be a UUIDv7 formatted string in compact mode, it is \"{value}\"",
78
+ "duration": "Property \"{property}\" must be an ISO 8601 duration string, it is \"{value}\""
78
79
  },
79
80
  "objectHelper": {
80
81
  "failedBytesToJSON": "Failed converting bytes to JSON",
@@ -109,7 +110,8 @@
109
110
  "lockNotFound": "The key \"{key}\" has no active lock",
110
111
  "lockAlreadyReleased": "The key \"{key}\" is not currently locked",
111
112
  "lockTimeout": "Failed to acquire lock for key \"{key}\" within the timeout of {timeout} milliseconds",
112
- "bufferFetchFailed": "Failed to retrieve shared buffer for key \"{key}\" from the main thread"
113
+ "bufferFetchFailed": "Failed to retrieve shared buffer for key \"{key}\" from the main thread",
114
+ "invalidTimeout": "The timeout value \"{timeoutMs}\" is invalid, it must be a non-negative integer"
113
115
  },
114
116
  "sharedObjectBuffer": {
115
117
  "notCreated": "The shared buffer for object \"{objectId}\" has not been created",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/core",
3
- "version": "0.0.4-next.9",
3
+ "version": "0.9.0-next.1",
4
4
  "description": "Helper methods/classes for data type checking/validation/guarding/error handling",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,8 +14,8 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@twin.org/nameof": "0.0.4-next.9",
18
- "intl-messageformat": "11.2.6",
17
+ "@twin.org/nameof": "0.9.0-next.1",
18
+ "intl-messageformat": "11.2.8",
19
19
  "rfc6902": "5.2.0"
20
20
  },
21
21
  "main": "./dist/es/index.js",