@twin.org/core 0.0.4-next.8 → 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.
- package/dist/es/encoding/base64.js +1 -1
- package/dist/es/encoding/base64.js.map +1 -1
- package/dist/es/errors/conflictError.js +1 -1
- package/dist/es/errors/conflictError.js.map +1 -1
- package/dist/es/errors/generalError.js +1 -1
- package/dist/es/errors/generalError.js.map +1 -1
- package/dist/es/errors/notImplementedError.js +1 -1
- package/dist/es/errors/notImplementedError.js.map +1 -1
- package/dist/es/errors/validationError.js +1 -1
- package/dist/es/errors/validationError.js.map +1 -1
- package/dist/es/helpers/arrayHelper.js +1 -1
- package/dist/es/helpers/arrayHelper.js.map +1 -1
- package/dist/es/helpers/errorHelper.js +1 -1
- package/dist/es/helpers/errorHelper.js.map +1 -1
- package/dist/es/helpers/jsonHelper.js +1 -1
- package/dist/es/helpers/jsonHelper.js.map +1 -1
- package/dist/es/helpers/objectHelper.js +2 -2
- package/dist/es/helpers/objectHelper.js.map +1 -1
- package/dist/es/helpers/stringHelper.js +2 -2
- package/dist/es/helpers/stringHelper.js.map +1 -1
- package/dist/es/index.js +7 -0
- package/dist/es/index.js.map +1 -1
- package/dist/es/models/IComponent.js.map +1 -1
- package/dist/es/models/IDuration.js +4 -0
- package/dist/es/models/IDuration.js.map +1 -0
- package/dist/es/models/ILocale.js.map +1 -1
- package/dist/es/models/ISharedObjectBufferOptions.js +4 -0
- package/dist/es/models/ISharedObjectBufferOptions.js.map +1 -0
- package/dist/es/models/ISharedObjectBufferWorkerMessage.js +2 -0
- package/dist/es/models/ISharedObjectBufferWorkerMessage.js.map +1 -0
- package/dist/es/models/IValidationFailure.js.map +1 -1
- package/dist/es/models/coerceType.js +5 -1
- package/dist/es/models/coerceType.js.map +1 -1
- package/dist/es/models/sharedObjectBufferMessageTypes.js +13 -0
- package/dist/es/models/sharedObjectBufferMessageTypes.js.map +1 -0
- package/dist/es/types/duration.js +184 -0
- package/dist/es/types/duration.js.map +1 -0
- package/dist/es/types/durationRegExp.js +4 -0
- package/dist/es/types/durationRegExp.js.map +1 -0
- package/dist/es/types/url.js +1 -0
- package/dist/es/types/url.js.map +1 -1
- package/dist/es/utils/asyncCache.js +1 -1
- package/dist/es/utils/asyncCache.js.map +1 -1
- package/dist/es/utils/coerce.js +34 -20
- package/dist/es/utils/coerce.js.map +1 -1
- package/dist/es/utils/compression.js +1 -1
- package/dist/es/utils/compression.js.map +1 -1
- package/dist/es/utils/guards.js +12 -0
- package/dist/es/utils/guards.js.map +1 -1
- package/dist/es/utils/is.js +65 -16
- package/dist/es/utils/is.js.map +1 -1
- package/dist/es/utils/mutex.js +49 -8
- package/dist/es/utils/mutex.js.map +1 -1
- package/dist/es/utils/sharedObjectBuffer.js +308 -0
- package/dist/es/utils/sharedObjectBuffer.js.map +1 -0
- package/dist/es/utils/sharedStore.js +2 -2
- package/dist/es/utils/sharedStore.js.map +1 -1
- package/dist/types/errors/conflictError.d.ts +1 -1
- package/dist/types/errors/generalError.d.ts +1 -1
- package/dist/types/errors/notImplementedError.d.ts +1 -1
- package/dist/types/errors/validationError.d.ts +1 -1
- package/dist/types/helpers/arrayHelper.d.ts +1 -1
- package/dist/types/helpers/errorHelper.d.ts +1 -1
- package/dist/types/helpers/jsonHelper.d.ts +1 -1
- package/dist/types/helpers/objectHelper.d.ts +2 -2
- package/dist/types/helpers/stringHelper.d.ts +2 -2
- package/dist/types/index.d.ts +7 -0
- package/dist/types/models/IComponent.d.ts +2 -2
- package/dist/types/models/IDuration.d.ts +45 -0
- package/dist/types/models/ILocale.d.ts +1 -1
- package/dist/types/models/ISharedObjectBufferOptions.d.ts +17 -0
- package/dist/types/models/ISharedObjectBufferWorkerMessage.d.ts +29 -0
- package/dist/types/models/IValidationFailure.d.ts +1 -1
- package/dist/types/models/coerceType.d.ts +4 -0
- package/dist/types/models/sharedObjectBufferMessageTypes.d.ts +13 -0
- package/dist/types/types/duration.d.ts +29 -0
- package/dist/types/types/durationRegExp.d.ts +1 -0
- package/dist/types/types/url.d.ts +1 -0
- package/dist/types/utils/asyncCache.d.ts +1 -1
- package/dist/types/utils/coerce.d.ts +19 -20
- package/dist/types/utils/compression.d.ts +1 -1
- package/dist/types/utils/guards.d.ts +9 -0
- package/dist/types/utils/is.d.ts +16 -9
- package/dist/types/utils/mutex.d.ts +12 -1
- package/dist/types/utils/sharedObjectBuffer.d.ts +74 -0
- package/dist/types/utils/sharedStore.d.ts +2 -2
- package/docs/changelog.md +273 -0
- package/docs/reference/classes/ArrayHelper.md +1 -1
- package/docs/reference/classes/AsyncCache.md +1 -1
- package/docs/reference/classes/Coerce.md +32 -48
- package/docs/reference/classes/Compression.md +1 -1
- package/docs/reference/classes/ConflictError.md +1 -1
- package/docs/reference/classes/Duration.md +88 -0
- package/docs/reference/classes/ErrorHelper.md +1 -1
- package/docs/reference/classes/GeneralError.md +1 -1
- package/docs/reference/classes/Guards.md +36 -0
- package/docs/reference/classes/Is.md +31 -9
- package/docs/reference/classes/JsonHelper.md +1 -1
- package/docs/reference/classes/Mutex.md +39 -1
- package/docs/reference/classes/NotImplementedError.md +1 -1
- package/docs/reference/classes/ObjectHelper.md +10 -2
- package/docs/reference/classes/SharedObjectBuffer.md +192 -0
- package/docs/reference/classes/SharedStore.md +2 -2
- package/docs/reference/classes/StringHelper.md +16 -13
- package/docs/reference/classes/Url.md +4 -0
- package/docs/reference/classes/ValidationError.md +1 -1
- package/docs/reference/index.md +8 -0
- package/docs/reference/interfaces/IComponent.md +2 -2
- package/docs/reference/interfaces/IDuration.md +83 -0
- package/docs/reference/interfaces/ILocale.md +1 -1
- package/docs/reference/interfaces/ISharedObjectBufferOptions.md +33 -0
- package/docs/reference/interfaces/ISharedObjectBufferWorkerMessage.md +44 -0
- package/docs/reference/interfaces/IValidationFailure.md +1 -1
- package/docs/reference/type-aliases/SharedObjectBufferMessageTypes.md +5 -0
- package/docs/reference/variables/CoerceType.md +6 -0
- package/docs/reference/variables/DURATION_REG_EXP.md +3 -0
- package/docs/reference/variables/SharedObjectBufferMessageTypes.md +13 -0
- package/locales/en.json +9 -2
- package/package.json +3 -3
|
@@ -26,7 +26,7 @@ export declare class JsonHelper {
|
|
|
26
26
|
* Applies a RFC 6902 diff set to an object.
|
|
27
27
|
* Based on https://www.rfc-editor.org/rfc/rfc6902.
|
|
28
28
|
* @param object The object to patch.
|
|
29
|
-
* @param patches The
|
|
29
|
+
* @param patches The patch operations to apply.
|
|
30
30
|
* @returns The updated object.
|
|
31
31
|
* @throws GeneralError if the patch fails.
|
|
32
32
|
*/
|
|
@@ -99,13 +99,13 @@ export declare class ObjectHelper {
|
|
|
99
99
|
*/
|
|
100
100
|
static omit<T, K extends keyof T>(obj: T | undefined, keys?: K[]): Omit<T, K> | undefined;
|
|
101
101
|
/**
|
|
102
|
-
*
|
|
102
|
+
* Convert the non JSON primitives to extended types.
|
|
103
103
|
* @param obj The object to convert.
|
|
104
104
|
* @returns The object with extended properties.
|
|
105
105
|
*/
|
|
106
106
|
static toExtended(obj: any): any;
|
|
107
107
|
/**
|
|
108
|
-
*
|
|
108
|
+
* Convert the extended types to non JSON primitives.
|
|
109
109
|
* @param obj The object to convert.
|
|
110
110
|
* @returns The object with regular properties.
|
|
111
111
|
*/
|
|
@@ -76,8 +76,8 @@ export declare class StringHelper {
|
|
|
76
76
|
static words(input: string): string[];
|
|
77
77
|
/**
|
|
78
78
|
* Check if a Node.js Buffer or Uint8Array is UTF-8.
|
|
79
|
-
*
|
|
80
|
-
*
|
|
79
|
+
* @see https://tools.ietf.org/html/rfc3629
|
|
80
|
+
* @see https://github.com/hcodes/isutf8
|
|
81
81
|
* UTF8-char = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4.
|
|
82
82
|
* UTF8-1 = %x00-7F.
|
|
83
83
|
* UTF8-2 = %xC2-DF UTF8-tail.
|
package/dist/types/index.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ export * from "./helpers/randomHelper.js";
|
|
|
27
27
|
export * from "./helpers/stringHelper.js";
|
|
28
28
|
export * from "./helpers/uint8ArrayHelper.js";
|
|
29
29
|
export * from "./models/coerceType.js";
|
|
30
|
+
export * from "./models/IDuration.js";
|
|
30
31
|
export * from "./models/compressionType.js";
|
|
31
32
|
export * from "./models/healthStatus.js";
|
|
32
33
|
export * from "./models/IComponent.js";
|
|
@@ -40,10 +41,15 @@ export * from "./models/ILocaleDictionary.js";
|
|
|
40
41
|
export * from "./models/ILocalesIndex.js";
|
|
41
42
|
export * from "./models/IMutexWorkerMessage.js";
|
|
42
43
|
export * from "./models/IPatchOperation.js";
|
|
44
|
+
export * from "./models/ISharedObjectBufferOptions.js";
|
|
45
|
+
export * from "./models/ISharedObjectBufferWorkerMessage.js";
|
|
43
46
|
export * from "./models/IUrlParts.js";
|
|
44
47
|
export * from "./models/IValidationFailure.js";
|
|
45
48
|
export * from "./models/mutexMessageTypes.js";
|
|
49
|
+
export * from "./models/sharedObjectBufferMessageTypes.js";
|
|
46
50
|
export * from "./types/bitString.js";
|
|
51
|
+
export * from "./types/duration.js";
|
|
52
|
+
export * from "./types/durationRegExp.js";
|
|
47
53
|
export * from "./types/objectOrArray.js";
|
|
48
54
|
export * from "./types/singleOccurrenceArray.js";
|
|
49
55
|
export * from "./types/singleOccurrenceArrayDepthHelper.js";
|
|
@@ -57,5 +63,6 @@ export * from "./utils/guards.js";
|
|
|
57
63
|
export * from "./utils/i18n.js";
|
|
58
64
|
export * from "./utils/is.js";
|
|
59
65
|
export * from "./utils/mutex.js";
|
|
66
|
+
export * from "./utils/sharedObjectBuffer.js";
|
|
60
67
|
export * from "./utils/sharedStore.js";
|
|
61
68
|
export * from "./utils/validation.js";
|
|
@@ -23,13 +23,13 @@ export interface IComponent {
|
|
|
23
23
|
/**
|
|
24
24
|
* The component needs to be started when the node is initialized.
|
|
25
25
|
* @param nodeLoggingComponentType The node logging component type.
|
|
26
|
-
* @returns
|
|
26
|
+
* @returns A promise that resolves when the component has started.
|
|
27
27
|
*/
|
|
28
28
|
start?(nodeLoggingComponentType?: string): Promise<void>;
|
|
29
29
|
/**
|
|
30
30
|
* The component needs to be stopped when the node is closed.
|
|
31
31
|
* @param nodeLoggingComponentType The node logging component type.
|
|
32
|
-
* @returns
|
|
32
|
+
* @returns A promise that resolves when the component has stopped.
|
|
33
33
|
*/
|
|
34
34
|
stop?(nodeLoggingComponentType?: string): Promise<void>;
|
|
35
35
|
/**
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a duration broken down into its component parts.
|
|
3
|
+
*/
|
|
4
|
+
export interface IDuration {
|
|
5
|
+
/**
|
|
6
|
+
* The number of years.
|
|
7
|
+
*/
|
|
8
|
+
years: number;
|
|
9
|
+
/**
|
|
10
|
+
* The number of months.
|
|
11
|
+
*/
|
|
12
|
+
months: number;
|
|
13
|
+
/**
|
|
14
|
+
* The number of weeks.
|
|
15
|
+
*/
|
|
16
|
+
weeks: number;
|
|
17
|
+
/**
|
|
18
|
+
* The number of days.
|
|
19
|
+
*/
|
|
20
|
+
days: number;
|
|
21
|
+
/**
|
|
22
|
+
* The number of hours.
|
|
23
|
+
*/
|
|
24
|
+
hours: number;
|
|
25
|
+
/**
|
|
26
|
+
* The number of minutes.
|
|
27
|
+
*/
|
|
28
|
+
minutes: number;
|
|
29
|
+
/**
|
|
30
|
+
* The number of seconds.
|
|
31
|
+
*/
|
|
32
|
+
seconds: number;
|
|
33
|
+
/**
|
|
34
|
+
* The number of milliseconds.
|
|
35
|
+
*/
|
|
36
|
+
milliseconds?: number;
|
|
37
|
+
/**
|
|
38
|
+
* The number of microseconds.
|
|
39
|
+
*/
|
|
40
|
+
microseconds?: number;
|
|
41
|
+
/**
|
|
42
|
+
* The number of nanoseconds.
|
|
43
|
+
*/
|
|
44
|
+
nanoseconds?: number;
|
|
45
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for configuring buffer capacity when creating a shared object buffer.
|
|
3
|
+
*/
|
|
4
|
+
export interface ISharedObjectBufferOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Initial payload capacity hint in bytes.
|
|
7
|
+
* Only honoured when the buffer does not yet exist; ignored on subsequent writes.
|
|
8
|
+
* @default 1 MiB.
|
|
9
|
+
*/
|
|
10
|
+
initialCapacityBytes?: number;
|
|
11
|
+
/**
|
|
12
|
+
* Maximum allowed payload capacity in bytes. The buffer will never grow beyond this limit.
|
|
13
|
+
* Only honoured when the buffer does not yet exist; ignored on subsequent writes.
|
|
14
|
+
* @default 256 MiB.
|
|
15
|
+
*/
|
|
16
|
+
maxCapacityBytes?: number;
|
|
17
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { MessagePort } from "node:worker_threads";
|
|
2
|
+
import type { ISharedObjectBufferOptions } from "./ISharedObjectBufferOptions.js";
|
|
3
|
+
import type { SharedObjectBufferMessageTypes } from "./sharedObjectBufferMessageTypes.js";
|
|
4
|
+
/**
|
|
5
|
+
* Message sent from a worker thread to the main thread to request the SharedArrayBuffer for an object.
|
|
6
|
+
*/
|
|
7
|
+
export interface ISharedObjectBufferWorkerMessage {
|
|
8
|
+
/**
|
|
9
|
+
* The message type discriminant.
|
|
10
|
+
*/
|
|
11
|
+
type: typeof SharedObjectBufferMessageTypes.GetBuffer;
|
|
12
|
+
/**
|
|
13
|
+
* The object id name that identifies which buffer is being requested.
|
|
14
|
+
*/
|
|
15
|
+
objectId: string;
|
|
16
|
+
/**
|
|
17
|
+
* One-shot SharedArrayBuffer used for the Atomics.wait/notify handshake so the
|
|
18
|
+
* worker can block synchronously until the main thread has posted the response.
|
|
19
|
+
*/
|
|
20
|
+
signal: SharedArrayBuffer;
|
|
21
|
+
/**
|
|
22
|
+
* MessagePort through which the main thread returns the object buffer.
|
|
23
|
+
*/
|
|
24
|
+
port: MessagePort;
|
|
25
|
+
/**
|
|
26
|
+
* Options for creating or fetching the buffer.
|
|
27
|
+
*/
|
|
28
|
+
options?: ISharedObjectBufferOptions;
|
|
29
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message type constants for the SharedObjectBuffer worker-to-main-thread protocol.
|
|
3
|
+
*/
|
|
4
|
+
export declare const SharedObjectBufferMessageTypes: {
|
|
5
|
+
/**
|
|
6
|
+
* Worker requests the SharedArrayBuffer for a named object from the main thread.
|
|
7
|
+
*/
|
|
8
|
+
readonly GetBuffer: "twin:sharedObjectBuffer:getBuffer";
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Union of all SharedObjectBuffer message type strings.
|
|
12
|
+
*/
|
|
13
|
+
export type SharedObjectBufferMessageTypes = (typeof SharedObjectBufferMessageTypes)[keyof typeof SharedObjectBufferMessageTypes];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { IDuration } from "../models/IDuration.js";
|
|
2
|
+
/**
|
|
3
|
+
* Helper methods for working with ISO 8601 durations.
|
|
4
|
+
*/
|
|
5
|
+
export declare class Duration {
|
|
6
|
+
/**
|
|
7
|
+
* Runtime name for the class.
|
|
8
|
+
*/
|
|
9
|
+
static readonly CLASS_NAME: string;
|
|
10
|
+
/**
|
|
11
|
+
* Parse an ISO 8601 duration string into its component parts.
|
|
12
|
+
* @param value The string to parse.
|
|
13
|
+
* @returns The parsed duration, or undefined if the string is not a valid ISO 8601 duration.
|
|
14
|
+
*/
|
|
15
|
+
static parse(value: string): IDuration | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Convert a duration object to an ISO 8601 duration string.
|
|
18
|
+
* @param duration The duration to convert.
|
|
19
|
+
* @returns The ISO 8601 duration string (e.g. "P1Y2M3DT4H5M6S").
|
|
20
|
+
*/
|
|
21
|
+
static toString(duration: IDuration): string;
|
|
22
|
+
/**
|
|
23
|
+
* Convert a duration object to total seconds.
|
|
24
|
+
* Year and month components use the average values 365.25 days and 30.4375 days.
|
|
25
|
+
* @param duration The duration to convert.
|
|
26
|
+
* @returns The total number of seconds.
|
|
27
|
+
*/
|
|
28
|
+
static toSeconds(duration: IDuration): number;
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const DURATION_REG_EXP: RegExp;
|
|
@@ -23,7 +23,7 @@ export declare class AsyncCache {
|
|
|
23
23
|
* @param key The key to set in the cache.
|
|
24
24
|
* @param value The value to set in the cache.
|
|
25
25
|
* @param ttlMs The TTL of the entry in the cache in milliseconds. Defaults to 1000 (1 second).
|
|
26
|
-
* @returns
|
|
26
|
+
* @returns A promise that resolves when the entry has been stored.
|
|
27
27
|
*/
|
|
28
28
|
static set<T = unknown>(key: string, value: T, ttlMs?: number): Promise<void>;
|
|
29
29
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CoerceType } from "../models/coerceType.js";
|
|
2
|
+
import type { IDuration } from "../models/IDuration.js";
|
|
2
3
|
/**
|
|
3
4
|
* Coerce an object from one type to another.
|
|
4
5
|
*/
|
|
@@ -6,71 +7,69 @@ export declare class Coerce {
|
|
|
6
7
|
/**
|
|
7
8
|
* Coerce the value to a string.
|
|
8
9
|
* @param value The value to coerce.
|
|
9
|
-
* @
|
|
10
|
-
* @returns The value if it can be coerced.
|
|
10
|
+
* @returns The coerced string, or undefined if the value cannot be coerced.
|
|
11
11
|
*/
|
|
12
12
|
static string(value: unknown): string | undefined;
|
|
13
13
|
/**
|
|
14
14
|
* Coerce the value to a number.
|
|
15
15
|
* @param value The value to coerce.
|
|
16
|
-
* @
|
|
17
|
-
* @returns The value if it can be coerced.
|
|
16
|
+
* @returns The coerced number, or undefined if the value cannot be coerced.
|
|
18
17
|
*/
|
|
19
18
|
static number(value: unknown): number | undefined;
|
|
20
19
|
/**
|
|
21
20
|
* Coerce the value to an integer.
|
|
22
21
|
* @param value The value to coerce.
|
|
23
|
-
* @
|
|
24
|
-
* @returns The value if it can be coerced.
|
|
22
|
+
* @returns The coerced integer, or undefined if the value cannot be coerced.
|
|
25
23
|
*/
|
|
26
24
|
static integer(value: unknown): number | undefined;
|
|
27
25
|
/**
|
|
28
26
|
* Coerce the value to a bigint.
|
|
29
27
|
* @param value The value to coerce.
|
|
30
|
-
* @
|
|
31
|
-
* @returns The value if it can be coerced.
|
|
28
|
+
* @returns The coerced bigint, or undefined if the value cannot be coerced.
|
|
32
29
|
*/
|
|
33
30
|
static bigint(value: unknown): bigint | undefined;
|
|
34
31
|
/**
|
|
35
32
|
* Coerce the value to a boolean.
|
|
36
33
|
* @param value The value to coerce.
|
|
37
|
-
* @
|
|
38
|
-
* @returns The value if it can be coerced.
|
|
34
|
+
* @returns The coerced boolean, or undefined if the value cannot be coerced.
|
|
39
35
|
*/
|
|
40
36
|
static boolean(value: unknown): boolean | undefined;
|
|
41
37
|
/**
|
|
42
38
|
* Coerce the value to a date.
|
|
43
39
|
* @param value The value to coerce.
|
|
44
|
-
* @
|
|
45
|
-
* @returns The value if it can be coerced.
|
|
40
|
+
* @returns The coerced date, or undefined if the value cannot be coerced.
|
|
46
41
|
*/
|
|
47
42
|
static date(value: unknown): Date | undefined;
|
|
48
43
|
/**
|
|
49
44
|
* Coerce the value to a date/time.
|
|
50
45
|
* @param value The value to coerce.
|
|
51
|
-
* @
|
|
52
|
-
* @returns The value if it can be coerced.
|
|
46
|
+
* @returns The coerced date/time, or undefined if the value cannot be coerced.
|
|
53
47
|
*/
|
|
54
48
|
static dateTime(value: unknown): Date | undefined;
|
|
55
49
|
/**
|
|
56
50
|
* Coerce the value to a time.
|
|
57
51
|
* @param value The value to coerce.
|
|
58
|
-
* @
|
|
59
|
-
* @returns The value if it can be coerced.
|
|
52
|
+
* @returns The coerced time, or undefined if the value cannot be coerced.
|
|
60
53
|
*/
|
|
61
54
|
static time(value: unknown): Date | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Coerce the value to a duration object.
|
|
57
|
+
* Accepts an IDuration object, ISO 8601 duration strings (e.g. "PT1H", "P1Y2M3DT4H5M6S"),
|
|
58
|
+
* or numeric values already expressed as seconds (stored in the seconds field).
|
|
59
|
+
* @param value The value to coerce.
|
|
60
|
+
* @returns The duration object, or undefined if the value cannot be coerced.
|
|
61
|
+
*/
|
|
62
|
+
static duration(value: unknown): IDuration | undefined;
|
|
62
63
|
/**
|
|
63
64
|
* Coerce the value to an object.
|
|
64
65
|
* @param value The value to coerce.
|
|
65
|
-
* @
|
|
66
|
-
* @returns The value if it can be coerced.
|
|
66
|
+
* @returns The coerced object, or undefined if the value cannot be coerced.
|
|
67
67
|
*/
|
|
68
68
|
static object<T = unknown>(value: unknown): T | undefined;
|
|
69
69
|
/**
|
|
70
70
|
* Coerce the value to a Uint8Array.
|
|
71
71
|
* @param value The value to coerce.
|
|
72
|
-
* @
|
|
73
|
-
* @returns The value if it can be coerced.
|
|
72
|
+
* @returns The coerced Uint8Array, or undefined if the value cannot be coerced.
|
|
74
73
|
*/
|
|
75
74
|
static uint8Array(value: unknown): Uint8Array | undefined;
|
|
76
75
|
/**
|
|
@@ -8,7 +8,7 @@ export declare class Compression {
|
|
|
8
8
|
*/
|
|
9
9
|
static readonly CLASS_NAME: string;
|
|
10
10
|
/**
|
|
11
|
-
* Compress bytes using
|
|
11
|
+
* Compress bytes using the specified compression type.
|
|
12
12
|
* @param bytes The bytes to compress.
|
|
13
13
|
* @param type The type of compression to use.
|
|
14
14
|
* @returns The compressed bytes.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { IDuration } from "../models/IDuration.js";
|
|
1
2
|
import type { ObjectOrArray } from "../types/objectOrArray.js";
|
|
2
3
|
/**
|
|
3
4
|
* Class to handle guard operations for parameters.
|
|
@@ -254,4 +255,12 @@ export declare class Guards {
|
|
|
254
255
|
* @throws GuardError If the value does not match the assertion.
|
|
255
256
|
*/
|
|
256
257
|
static uuidV7(source: string, property: string, value: unknown, format?: "standard" | "compact"): asserts value is string;
|
|
258
|
+
/**
|
|
259
|
+
* Is the property a valid ISO 8601 duration string or IDuration object.
|
|
260
|
+
* @param source The source of the error.
|
|
261
|
+
* @param property The name of the property.
|
|
262
|
+
* @param value The value to test.
|
|
263
|
+
* @throws GuardError If the value does not match the assertion.
|
|
264
|
+
*/
|
|
265
|
+
static duration(source: string, property: string, value: unknown): asserts value is string | IDuration;
|
|
257
266
|
}
|
package/dist/types/utils/is.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { IDuration } from "../models/IDuration.js";
|
|
1
2
|
/**
|
|
2
3
|
* Class to check types of objects.
|
|
3
4
|
*/
|
|
@@ -5,25 +6,25 @@ export declare class Is {
|
|
|
5
6
|
/**
|
|
6
7
|
* Is the property undefined.
|
|
7
8
|
* @param value The value to test.
|
|
8
|
-
* @returns True if the value is
|
|
9
|
+
* @returns True if the value is undefined.
|
|
9
10
|
*/
|
|
10
11
|
static undefined(value: unknown): value is undefined;
|
|
11
12
|
/**
|
|
12
13
|
* Is the property null.
|
|
13
14
|
* @param value The value to test.
|
|
14
|
-
* @returns True if the value is
|
|
15
|
+
* @returns True if the value is null.
|
|
15
16
|
*/
|
|
16
17
|
static null(value: unknown): value is null;
|
|
17
18
|
/**
|
|
18
19
|
* Is the property null or undefined.
|
|
19
20
|
* @param value The value to test.
|
|
20
|
-
* @returns True if the value is
|
|
21
|
+
* @returns True if the value is null or undefined.
|
|
21
22
|
*/
|
|
22
23
|
static empty(value: unknown): value is undefined | null;
|
|
23
24
|
/**
|
|
24
|
-
* Is the property
|
|
25
|
+
* Is the property not null or undefined.
|
|
25
26
|
* @param value The value to test.
|
|
26
|
-
* @returns True if the value is
|
|
27
|
+
* @returns True if the value is not null or undefined.
|
|
27
28
|
*/
|
|
28
29
|
static notEmpty(value: unknown): boolean;
|
|
29
30
|
/**
|
|
@@ -33,9 +34,9 @@ export declare class Is {
|
|
|
33
34
|
*/
|
|
34
35
|
static string(value: unknown): value is string;
|
|
35
36
|
/**
|
|
36
|
-
* Is the value a string.
|
|
37
|
+
* Is the value a non-empty string.
|
|
37
38
|
* @param value The value to test.
|
|
38
|
-
* @returns True if the value is a string.
|
|
39
|
+
* @returns True if the value is a non-empty string.
|
|
39
40
|
*/
|
|
40
41
|
static stringValue(value: unknown): value is string;
|
|
41
42
|
/**
|
|
@@ -134,13 +135,13 @@ export declare class Is {
|
|
|
134
135
|
/**
|
|
135
136
|
* Is the value a timestamp in seconds.
|
|
136
137
|
* @param value The value to test.
|
|
137
|
-
* @returns True if the value is a
|
|
138
|
+
* @returns True if the value is a timestamp in seconds.
|
|
138
139
|
*/
|
|
139
140
|
static timestampSeconds(value: unknown): value is number;
|
|
140
141
|
/**
|
|
141
142
|
* Is the value a timestamp in milliseconds.
|
|
142
143
|
* @param value The value to test.
|
|
143
|
-
* @returns True if the value is a
|
|
144
|
+
* @returns True if the value is a timestamp in milliseconds.
|
|
144
145
|
*/
|
|
145
146
|
static timestampMilliseconds(value: unknown): value is number;
|
|
146
147
|
/**
|
|
@@ -227,4 +228,10 @@ export declare class Is {
|
|
|
227
228
|
* @returns True if the value is a uuidV7 string.
|
|
228
229
|
*/
|
|
229
230
|
static uuidV7(value: unknown, format?: "standard" | "compact"): value is string;
|
|
231
|
+
/**
|
|
232
|
+
* Is the value a valid ISO 8601 duration string or an IDuration object.
|
|
233
|
+
* @param value The value to test.
|
|
234
|
+
* @returns True if the value is a valid ISO 8601 duration string or an IDuration object.
|
|
235
|
+
*/
|
|
236
|
+
static duration(value: unknown): value is string | IDuration;
|
|
230
237
|
}
|
|
@@ -19,6 +19,17 @@ export declare class Mutex {
|
|
|
19
19
|
* Runtime name for the class.
|
|
20
20
|
*/
|
|
21
21
|
static readonly CLASS_NAME: string;
|
|
22
|
+
/**
|
|
23
|
+
* Gets the default timeout in milliseconds for lock acquisition.
|
|
24
|
+
* @returns The default timeout in milliseconds.
|
|
25
|
+
*/
|
|
26
|
+
static getDefaultTimeoutMs(): number;
|
|
27
|
+
/**
|
|
28
|
+
* Sets the default timeout in milliseconds for lock acquisition.
|
|
29
|
+
* @param timeoutMs The default timeout in milliseconds.
|
|
30
|
+
* @throws GeneralError if timeoutMs is not a non-negative integer.
|
|
31
|
+
*/
|
|
32
|
+
static setDefaultTimeoutMs(timeoutMs: number): void;
|
|
22
33
|
/**
|
|
23
34
|
* Acquires a lock for the given key without blocking the event loop. If the lock is already
|
|
24
35
|
* held, it suspends the current async task until the lock is released or the timeout is reached.
|
|
@@ -28,7 +39,7 @@ export declare class Mutex {
|
|
|
28
39
|
* the same key, it will suspend until the timeout elapses.
|
|
29
40
|
* @param key The key to lock on.
|
|
30
41
|
* @param options Lock options.
|
|
31
|
-
* @param options.timeoutMs The maximum time to wait for the lock in milliseconds,
|
|
42
|
+
* @param options.timeoutMs The maximum time to wait for the lock in milliseconds, defaults to getDefaultTimeoutMs().
|
|
32
43
|
* @param options.throwOnTimeout Whether to throw an error if the lock could not be acquired within the timeout, default is false.
|
|
33
44
|
* @returns True if the lock was acquired, false if it timed out and throwOnTimeout is false.
|
|
34
45
|
* @throws GeneralError if the key is invalid or if the lock could not be acquired within the timeout and throwOnTimeout is true.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { ISharedObjectBufferOptions } from "../models/ISharedObjectBufferOptions.js";
|
|
2
|
+
/**
|
|
3
|
+
* Manages per-object SharedArrayBuffers that store objects as UTF-8 JSON.
|
|
4
|
+
* Buffer layout: 4-byte Int32 header (current data byte length) followed by the JSON-encoded object.
|
|
5
|
+
* Buffers are explicitly created with create and cached in SharedStore.
|
|
6
|
+
* On a worker thread an existing buffer is fetched via a MessagePort handshake
|
|
7
|
+
* (same protocol as Mutex) and cached locally.
|
|
8
|
+
* Buffers grow automatically when the payload exceeds capacity; when the payload drops well below
|
|
9
|
+
* capacity the buffer is replaced with a smaller one. The caller must hold the objectId-keyed Mutex
|
|
10
|
+
* around every read and write. The main thread's worker message handler must forward messages to
|
|
11
|
+
* both Mutex.handleWorkerMessage and SharedObjectBuffer.handleWorkerMessage.
|
|
12
|
+
*/
|
|
13
|
+
export declare class SharedObjectBuffer {
|
|
14
|
+
/**
|
|
15
|
+
* Runtime name for the class.
|
|
16
|
+
*/
|
|
17
|
+
static readonly CLASS_NAME: string;
|
|
18
|
+
/**
|
|
19
|
+
* Default payload capacity per object (1 MiB). The first caller that creates the buffer
|
|
20
|
+
* for an object determines its initial capacity; later callers that pass a different value
|
|
21
|
+
* are ignored.
|
|
22
|
+
*/
|
|
23
|
+
static readonly DEFAULT_CAPACITY_BYTES: number;
|
|
24
|
+
/**
|
|
25
|
+
* Default upper bound for how large a buffer may grow (256 MiB).
|
|
26
|
+
* Override per-object via the maxCapacityBytes option on create.
|
|
27
|
+
*/
|
|
28
|
+
static readonly MAX_CAPACITY_BYTES: number;
|
|
29
|
+
/**
|
|
30
|
+
* Create the buffer for the given objectId if it does not already exist.
|
|
31
|
+
* Must be called while holding Mutex.lock(objectId).
|
|
32
|
+
* @param objectId The object id that identifies the buffer.
|
|
33
|
+
* @param options Optional capacity configuration used when creating the buffer.
|
|
34
|
+
*/
|
|
35
|
+
static create(objectId: string, options?: ISharedObjectBufferOptions): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Read and decode the object stored for the given objectId.
|
|
38
|
+
* Must be called while holding Mutex.lock(objectId).
|
|
39
|
+
* @param objectId The object id that identifies the buffer.
|
|
40
|
+
* @returns The stored object, or undefined when nothing has been written yet.
|
|
41
|
+
*/
|
|
42
|
+
static read<T>(objectId: string): Promise<T | undefined>;
|
|
43
|
+
/**
|
|
44
|
+
* Encode and write the object into the buffer for the given objectId.
|
|
45
|
+
* The buffer must already exist, usually by calling create first.
|
|
46
|
+
* When the encoded payload exceeds the current buffer capacity the buffer is grown
|
|
47
|
+
* in-place via SharedArrayBuffer.grow so every thread with a reference sees the
|
|
48
|
+
* new size without any pointer swap. When the payload is smaller than
|
|
49
|
+
* _SHRINK_THRESHOLD of the current capacity and the capacity exceeds
|
|
50
|
+
* DEFAULT_CAPACITY_BYTES, the buffer is replaced with a smaller one on the calling thread.
|
|
51
|
+
* Must be called while holding Mutex.lock(objectId).
|
|
52
|
+
* @param objectId The object id that identifies the buffer.
|
|
53
|
+
* @param value The object to persist.
|
|
54
|
+
*/
|
|
55
|
+
static write<T>(objectId: string, value: T): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Remove the stored object and release the buffer for the given objectId.
|
|
58
|
+
* The entry is deleted from the local cache so subsequent reads or writes will
|
|
59
|
+
* create or fetch a fresh buffer. Worker threads that have cached the old buffer
|
|
60
|
+
* reference continue using it until they restart or re-request via the worker protocol.
|
|
61
|
+
* Must be called while holding Mutex.lock(objectId).
|
|
62
|
+
* @param objectId The object id that identifies the buffer.
|
|
63
|
+
*/
|
|
64
|
+
static remove(objectId: string): void;
|
|
65
|
+
/**
|
|
66
|
+
* Inspect a message from a worker thread and, if it is a SharedObjectBuffer
|
|
67
|
+
* buffer-fetch request, respond to it synchronously.
|
|
68
|
+
* Call this from the main thread's worker message handler alongside
|
|
69
|
+
* Mutex.handleWorkerMessage.
|
|
70
|
+
* @param msg The raw message received from the worker.
|
|
71
|
+
* @returns True if the message was a SharedObjectBuffer protocol message, false otherwise.
|
|
72
|
+
*/
|
|
73
|
+
static handleWorkerMessage(msg: unknown): boolean;
|
|
74
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Provide a store for shared objects which can be
|
|
3
|
-
* instance loads of a
|
|
2
|
+
* Provide a store for shared objects which can be accessed through multiple
|
|
3
|
+
* instance loads of a package.
|
|
4
4
|
*/
|
|
5
5
|
export declare class SharedStore {
|
|
6
6
|
/**
|