@itwin/core-common 5.0.0-dev.82 → 5.0.0-dev.84
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/lib/cjs/ITwinError.d.ts +63 -27
- package/lib/cjs/ITwinError.d.ts.map +1 -1
- package/lib/cjs/ITwinError.js +93 -45
- package/lib/cjs/ITwinError.js.map +1 -1
- package/lib/cjs/ipc/IpcSocket.d.ts +1 -0
- package/lib/cjs/ipc/IpcSocket.d.ts.map +1 -1
- package/lib/cjs/ipc/IpcSocket.js.map +1 -1
- package/lib/esm/ITwinError.d.ts +63 -27
- package/lib/esm/ITwinError.d.ts.map +1 -1
- package/lib/esm/ITwinError.js +87 -44
- package/lib/esm/ITwinError.js.map +1 -1
- package/lib/esm/ipc/IpcSocket.d.ts +1 -0
- package/lib/esm/ipc/IpcSocket.d.ts.map +1 -1
- package/lib/esm/ipc/IpcSocket.js.map +1 -1
- package/package.json +6 -6
package/lib/cjs/ITwinError.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { LoggingMetaData } from "@itwin/core-bentley";
|
|
5
5
|
import { LockState } from "./IModelError";
|
|
6
|
+
import { BriefcaseId } from "./BriefcaseTypes";
|
|
6
7
|
/**
|
|
7
8
|
* Detailed information about a particular object Lock that is causing the Lock update conflict.
|
|
8
9
|
* An example of a lock update conflict would be attempting to use [LockControl.acquireLocks]($backend) on an object that is already locked by another Briefcase.
|
|
@@ -17,20 +18,34 @@ export interface InUseLock {
|
|
|
17
18
|
*/
|
|
18
19
|
state: LockState;
|
|
19
20
|
/** An array of Briefcase ids that hold this lock. */
|
|
20
|
-
briefcaseIds:
|
|
21
|
+
briefcaseIds: BriefcaseId[];
|
|
21
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* iTwinjs Core namespace namespace for a developer/application.
|
|
25
|
+
* @beta
|
|
26
|
+
*/
|
|
27
|
+
export declare const iTwinjsCoreNamespace = "itwinjs-core";
|
|
28
|
+
/**
|
|
29
|
+
* error keys object used to describe an error keys for a developer/application.
|
|
30
|
+
* @beta
|
|
31
|
+
*/
|
|
32
|
+
export declare const iTwinErrorKeys: {
|
|
33
|
+
readonly inUseLocks: "in-use-locks";
|
|
34
|
+
readonly channelNest: "channel-may-not-nest";
|
|
35
|
+
readonly channelNotAllowed: "channel-not-allowed";
|
|
36
|
+
readonly channelRootExists: "channel-root-exists";
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Record for all itwin error messages.
|
|
40
|
+
* @beta
|
|
41
|
+
*/
|
|
42
|
+
export declare const iTwinErrorMessages: Record<keyof typeof iTwinErrorKeys, (...args: any[]) => string>;
|
|
22
43
|
/**
|
|
23
44
|
* An interface used to describe an error for a developer/application. The message is not intended to be displayed to an end user.
|
|
24
45
|
* This error interface should be extended when needing to throw errors with extra properties defined on them. See [[InUseLocksError]] for an example.
|
|
25
|
-
* When extending ITwinError, one should typically add a type guard function and a function to throw the error either to a namespace for their error or as standalone functions.
|
|
26
|
-
* See [[InUseLocksError.throwInUseLocksError]] and [[InUseLocksError.isInUseLocksError]] for examples of how to throw and check that an error is of type InUseLocksError.
|
|
27
|
-
* * Example of catching a ITwinError:
|
|
28
|
-
* ``` ts
|
|
29
|
-
* [[include:ITwinError.catchAndHandleITwinError]]
|
|
30
|
-
* ```
|
|
31
46
|
* @beta
|
|
32
47
|
*/
|
|
33
|
-
export interface ITwinError {
|
|
48
|
+
export interface ITwinError extends Error {
|
|
34
49
|
/** namespace for the error. This is a unique qualifier for the errorKey. */
|
|
35
50
|
namespace: string;
|
|
36
51
|
/** unique key for error, within namespace. All errorKeys within the same namespace must be unique. */
|
|
@@ -48,25 +63,46 @@ export interface ITwinError {
|
|
|
48
63
|
* @beta
|
|
49
64
|
*/
|
|
50
65
|
export interface InUseLocksError extends ITwinError {
|
|
51
|
-
namespace: "itwinjs-core";
|
|
52
|
-
errorKey: "in-use-locks";
|
|
53
66
|
inUseLocks: InUseLock[];
|
|
54
67
|
}
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
/**
|
|
69
|
+
* A function which will be used to construct an [[ITwinError]].
|
|
70
|
+
* @param namespace The namespace associated with the error.
|
|
71
|
+
* @param errorKey The errorKey associated with the error.
|
|
72
|
+
* @param message The message associated with the error.
|
|
73
|
+
* @param metadata Metadata associated with the error.
|
|
74
|
+
* @beta
|
|
75
|
+
*/
|
|
76
|
+
export declare function constructITwinError(namespace: string, errorKey: string, message?: string, metadata?: LoggingMetaData): ITwinError;
|
|
77
|
+
/**
|
|
78
|
+
* A function which constructs a detailed error for example [[ InUseLocksError ]] above.
|
|
79
|
+
* @param namespace The namespace associated with the error.
|
|
80
|
+
* @param errorKey The errorKey associated with the error.
|
|
81
|
+
* @param details Other details associated with the error.
|
|
82
|
+
* @param message The message associated with the error.
|
|
83
|
+
* @param metadata Metadata associated with the error.
|
|
84
|
+
* @beta
|
|
85
|
+
*/
|
|
86
|
+
export declare function constructDetailedError<T extends ITwinError>(namespace: string, errorKey: string, details: Omit<T, keyof ITwinError>, message?: string, metadata?: LoggingMetaData): T;
|
|
87
|
+
/**
|
|
88
|
+
* a high level function that returns a type asserter function which would return whether or not the passed in parameter is an [[ITwinError]]
|
|
89
|
+
* @param namespace The namespace associated with the error.
|
|
90
|
+
* @param errorKey The errorKey associated with the error.
|
|
91
|
+
* @beta
|
|
92
|
+
*/
|
|
93
|
+
export declare function createITwinErrorTypeAsserter<T extends ITwinError>(namespace: string, errorKey: string): (error: unknown) => error is T;
|
|
94
|
+
/**
|
|
95
|
+
* get the meta data associated with this ITwinError, if any.
|
|
96
|
+
* @param error The error for which metadata is required.
|
|
97
|
+
* @beta
|
|
98
|
+
*/
|
|
99
|
+
export declare function getITwinErrorMetaData(error: ITwinError): object | undefined;
|
|
100
|
+
/**
|
|
101
|
+
* type guard function that returns whether or not the passed in parameter is an [[ITwinError]]
|
|
102
|
+
* @param error The error which is to ve verified.
|
|
103
|
+
* @param namespace The namespace associated with the error.
|
|
104
|
+
* @param errorKey The errorKey associated with the error.
|
|
105
|
+
* @beta
|
|
106
|
+
*/
|
|
107
|
+
export declare function isITwinError(error: unknown, namespace?: string, errorKey?: string): error is ITwinError;
|
|
72
108
|
//# sourceMappingURL=ITwinError.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ITwinError.d.ts","sourceRoot":"","sources":["../../src/ITwinError.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"ITwinError.d.ts","sourceRoot":"","sources":["../../src/ITwinError.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,KAAK,EAAE,SAAS,CAAC;IACjB,qDAAqD;IACrD,YAAY,EAAE,WAAW,EAAE,CAAC;CAC7B;AAED;;;GAGG;AACH,eAAO,MAAM,oBAAoB,iBAAiB,CAAC;AAEnD;;;GAGG;AACH,eAAO,MAAM,cAAc;;;;;CAKjB,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,OAAO,cAAc,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAK9F,CAAC;AAGF;;;;GAIG;AACH,MAAM,WAAW,UAAW,SAAQ,KAAK;IACvC,4EA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8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
;
|
|
10
|
+
exports.iTwinErrorMessages = exports.iTwinErrorKeys = exports.iTwinjsCoreNamespace = void 0;
|
|
11
|
+
exports.constructITwinError = constructITwinError;
|
|
12
|
+
exports.constructDetailedError = constructDetailedError;
|
|
13
|
+
exports.createITwinErrorTypeAsserter = createITwinErrorTypeAsserter;
|
|
14
|
+
exports.getITwinErrorMetaData = getITwinErrorMetaData;
|
|
15
|
+
exports.isITwinError = isITwinError;
|
|
16
|
+
/**
|
|
17
|
+
* iTwinjs Core namespace namespace for a developer/application.
|
|
18
|
+
* @beta
|
|
19
|
+
*/
|
|
20
|
+
exports.iTwinjsCoreNamespace = "itwinjs-core";
|
|
21
|
+
/**
|
|
22
|
+
* error keys object used to describe an error keys for a developer/application.
|
|
23
|
+
* @beta
|
|
24
|
+
*/
|
|
25
|
+
exports.iTwinErrorKeys = {
|
|
26
|
+
inUseLocks: "in-use-locks",
|
|
27
|
+
channelNest: "channel-may-not-nest",
|
|
28
|
+
channelNotAllowed: "channel-not-allowed",
|
|
29
|
+
channelRootExists: "channel-root-exists"
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Record for all itwin error messages.
|
|
33
|
+
* @beta
|
|
34
|
+
*/
|
|
35
|
+
exports.iTwinErrorMessages = {
|
|
36
|
+
"inUseLocks": () => 'Objects are locked by another briefcase',
|
|
37
|
+
"channelNest": (id) => `Channel ${id} may not nest`,
|
|
38
|
+
"channelNotAllowed": (id) => `Channel ${id} is not allowed`,
|
|
39
|
+
"channelRootExists": (id) => `Channel ${id} root already exist`,
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* A function which will be used to construct an [[ITwinError]].
|
|
43
|
+
* @param namespace The namespace associated with the error.
|
|
44
|
+
* @param errorKey The errorKey associated with the error.
|
|
45
|
+
* @param message The message associated with the error.
|
|
46
|
+
* @param metadata Metadata associated with the error.
|
|
47
|
+
* @beta
|
|
48
|
+
*/
|
|
49
|
+
function constructITwinError(namespace, errorKey, message, metadata) {
|
|
50
|
+
const error = new Error();
|
|
51
|
+
error.message = message ?? `${errorKey} occurred`;
|
|
52
|
+
error.name = `${namespace}:${errorKey}`;
|
|
53
|
+
error.namespace = namespace;
|
|
54
|
+
error.errorKey = errorKey;
|
|
55
|
+
error.metadata = metadata;
|
|
56
|
+
Error.captureStackTrace(error, constructITwinError); // Optional, but this would hide constructITwinError from stack.
|
|
57
|
+
return error;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A function which constructs a detailed error for example [[ InUseLocksError ]] above.
|
|
61
|
+
* @param namespace The namespace associated with the error.
|
|
62
|
+
* @param errorKey The errorKey associated with the error.
|
|
63
|
+
* @param details Other details associated with the error.
|
|
64
|
+
* @param message The message associated with the error.
|
|
65
|
+
* @param metadata Metadata associated with the error.
|
|
66
|
+
* @beta
|
|
67
|
+
*/
|
|
68
|
+
function constructDetailedError(namespace, errorKey, details, message, metadata) {
|
|
69
|
+
const baseError = constructITwinError(namespace, errorKey, message, metadata);
|
|
70
|
+
Error.captureStackTrace(baseError, constructDetailedError); // Optional, but this would hide constructDetailedError from stack.
|
|
71
|
+
return Object.assign(baseError, details);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* a high level function that returns a type asserter function which would return whether or not the passed in parameter is an [[ITwinError]]
|
|
75
|
+
* @param namespace The namespace associated with the error.
|
|
76
|
+
* @param errorKey The errorKey associated with the error.
|
|
77
|
+
* @beta
|
|
78
|
+
*/
|
|
79
|
+
function createITwinErrorTypeAsserter(namespace, errorKey) {
|
|
80
|
+
return (error) => isITwinError(error, namespace, errorKey);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* get the meta data associated with this ITwinError, if any.
|
|
84
|
+
* @param error The error for which metadata is required.
|
|
85
|
+
* @beta
|
|
86
|
+
*/
|
|
87
|
+
function getITwinErrorMetaData(error) {
|
|
88
|
+
return (typeof error.metadata === "function") ? error.metadata() : error.metadata;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* type guard function that returns whether or not the passed in parameter is an [[ITwinError]]
|
|
92
|
+
* @param error The error which is to ve verified.
|
|
93
|
+
* @param namespace The namespace associated with the error.
|
|
94
|
+
* @param errorKey The errorKey associated with the error.
|
|
95
|
+
* @beta
|
|
96
|
+
*/
|
|
97
|
+
function isITwinError(error, namespace, errorKey) {
|
|
98
|
+
return error !== undefined && error !== null && typeof error === "object"
|
|
99
|
+
&& "namespace" in error && "errorKey" in error && "message" in error
|
|
100
|
+
&& (namespace === undefined || error.namespace === namespace)
|
|
101
|
+
&& (errorKey === undefined || error.errorKey === errorKey);
|
|
102
|
+
}
|
|
55
103
|
//# sourceMappingURL=ITwinError.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ITwinError.js","sourceRoot":"","sources":["../../src/ITwinError.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;
|
|
1
|
+
{"version":3,"file":"ITwinError.js","sourceRoot":"","sources":["../../src/ITwinError.ts"],"names":[],"mapp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C,EAAE,OAAgB,EAAE,QAA0B;IAChL,MAAM,SAAS,GAAG,mBAAmB,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IAE9E,KAAK,CAAC,iBAAiB,CAAC,SAAS,EAAE,sBAAsB,CAAC,CAAC,CAAC,mEAAmE;IAC/H,OAAO,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAM,CAAC;AAChD,CAAC;AAED;;;;;EAKE;AACF,SAAgB,4BAA4B,CAAuB,SAAiB,EAAE,QAAgB;IACpG,OAAO,CAAC,KAAc,EAAc,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;AAClF,CAAC;AAED;;;;EAIE;AACF,SAAgB,qBAAqB,CAAC,KAAiB;IACrD,OAAO,CAAC,OAAO,KAAK,CAAC,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC;AACpF,CAAC;AAED;;;;;;EAME;AACF,SAAgB,YAAY,CAAC,KAAc,EAAE,SAAkB,EAAE,QAAiB;IAChF,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;WACpE,WAAW,IAAI,KAAK,IAAI,UAAU,IAAI,KAAK,IAAI,SAAS,IAAI,KAAK;WACjE,CAAC,SAAS,KAAK,SAAS,IAAK,KAAoB,CAAC,SAAS,KAAK,SAAS,CAAC;WAC1E,CAAC,QAAQ,KAAK,SAAS,IAAK,KAAoB,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC;AAC/E,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module iModels\n */\n\nimport { LoggingMetaData } from \"@itwin/core-bentley\";\nimport { LockState } from \"./IModelError\";\nimport { BriefcaseId } from \"./BriefcaseTypes\";\n\n/**\n * Detailed information about a particular object Lock that is causing the Lock update conflict.\n * An example of a lock update conflict would be attempting to use [LockControl.acquireLocks]($backend) on an object that is already locked by another Briefcase.\n * @beta\n */\nexport interface InUseLock {\n /** Id of the object that is causing conflict. */\n objectId: string;\n /**\n * The level of conflicting lock. Possible values are {@link LockState.Shared}, {@link LockState.Exclusive}.\n * See {@link LockState}.\n */\n state: LockState;\n /** An array of Briefcase ids that hold this lock. */\n briefcaseIds: BriefcaseId[];\n}\n\n/**\n * iTwinjs Core namespace namespace for a developer/application.\n * @beta\n */\nexport const iTwinjsCoreNamespace = \"itwinjs-core\";\n\n/**\n * error keys object used to describe an error keys for a developer/application.\n * @beta\n */\nexport const iTwinErrorKeys = {\n inUseLocks: \"in-use-locks\",\n channelNest: \"channel-may-not-nest\",\n channelNotAllowed: \"channel-not-allowed\",\n channelRootExists: \"channel-root-exists\"\n} as const;\n\n/**\n * Record for all itwin error messages.\n * @beta\n */\nexport const iTwinErrorMessages: Record<keyof typeof iTwinErrorKeys, (...args: any[]) => string> = {\n \"inUseLocks\": () => 'Objects are locked by another briefcase',\n \"channelNest\": (id) => `Channel ${id} may not nest`,\n \"channelNotAllowed\": (id) => `Channel ${id} is not allowed`,\n \"channelRootExists\": (id) => `Channel ${id} root already exist`,\n};\n\n\n/**\n * An interface used to describe an error for a developer/application. The message is not intended to be displayed to an end user.\n * This error interface should be extended when needing to throw errors with extra properties defined on them. See [[InUseLocksError]] for an example.\n * @beta\n */\nexport interface ITwinError extends Error {\n /** namespace for the error. This is a unique qualifier for the errorKey. */\n namespace: string;\n /** unique key for error, within namespace. All errorKeys within the same namespace must be unique. */\n errorKey: string;\n /** explanation of what went wrong. Intended to be read by a developer. */\n message: string;\n /** stack trace of the error. */\n stack?: string;\n /** metadata about the exception. */\n metadata?: LoggingMetaData;\n}\n\n/**\n * An error raised when there is a lock conflict detected.\n * Typically this error would be thrown by [LockControl.acquireLocks]($backend) when you are requesting a lock on an element that is already held by another briefcase.\n * @beta\n*/\nexport interface InUseLocksError extends ITwinError {\n inUseLocks: InUseLock[];\n}\n\n/**\n* A function which will be used to construct an [[ITwinError]].\n* @param namespace The namespace associated with the error.\n* @param errorKey The errorKey associated with the error.\n* @param message The message associated with the error.\n* @param metadata Metadata associated with the error.\n* @beta\n*/\nexport function constructITwinError(namespace: string, errorKey: string, message?: string, metadata?: LoggingMetaData): ITwinError {\n\n const error = new Error() as ITwinError;\n error.message = message ?? `${errorKey} occurred`;\n error.name = `${namespace}:${errorKey}`;\n error.namespace = namespace;\n error.errorKey = errorKey;\n error.metadata = metadata;\n\n Error.captureStackTrace(error, constructITwinError); // Optional, but this would hide constructITwinError from stack.\n return error;\n}\n\n/**\n* A function which constructs a detailed error for example [[ InUseLocksError ]] above.\n* @param namespace The namespace associated with the error.\n* @param errorKey The errorKey associated with the error.\n* @param details Other details associated with the error.\n* @param message The message associated with the error.\n* @param metadata Metadata associated with the error.\n* @beta\n*/\nexport function constructDetailedError<T extends ITwinError>(namespace: string, errorKey: string, details: Omit<T, keyof ITwinError>, message?: string, metadata?: LoggingMetaData): T {\n const baseError = constructITwinError(namespace, errorKey, message, metadata);\n\n Error.captureStackTrace(baseError, constructDetailedError); // Optional, but this would hide constructDetailedError from stack.\n return Object.assign(baseError, details) as T;\n}\n\n/**\n * a high level function that returns a type asserter function which would return whether or not the passed in parameter is an [[ITwinError]]\n * @param namespace The namespace associated with the error.\n * @param errorKey The errorKey associated with the error.\n * @beta\n*/\nexport function createITwinErrorTypeAsserter<T extends ITwinError>(namespace: string, errorKey: string) {\n return (error: unknown): error is T => isITwinError(error, namespace, errorKey);\n}\n\n/**\n * get the meta data associated with this ITwinError, if any.\n * @param error The error for which metadata is required.\n * @beta\n*/\nexport function getITwinErrorMetaData(error: ITwinError): object | undefined {\n return (typeof error.metadata === \"function\") ? error.metadata() : error.metadata;\n}\n\n/**\n * type guard function that returns whether or not the passed in parameter is an [[ITwinError]]\n * @param error The error which is to ve verified.\n * @param namespace The namespace associated with the error.\n * @param errorKey The errorKey associated with the error.\n * @beta\n*/\nexport function isITwinError(error: unknown, namespace?: string, errorKey?: string): error is ITwinError {\n return error !== undefined && error !== null && typeof error === \"object\"\n && \"namespace\" in error && \"errorKey\" in error && \"message\" in error\n && (namespace === undefined || (error as ITwinError).namespace === namespace)\n && (errorKey === undefined || (error as ITwinError).errorKey === errorKey);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IpcSocket.d.ts","sourceRoot":"","sources":["../../../src/ipc/IpcSocket.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD;;;KAGK;AACL,eAAO,MAAM,YAAY,YAAa,MAAM,WAAuB,CAAC;AAEpE;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;AAE/D;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC;AAExC;;;;;eAKe;AACf,MAAM,MAAM,eAAe,GAAG;IAAE,MAAM,EAAE,GAAG,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IAAC,UAAU,CAAC,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,MAAM,CAAC,EAAE,KAAK,CAAC;IAAC,UAAU,CAAC,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"IpcSocket.d.ts","sourceRoot":"","sources":["../../../src/ipc/IpcSocket.ts"],"names":[],"mappings":"AA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ChD;;;;;OAKG;IACH,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,KAAK,cAAc,CAAC;IACxE;;;;OAIG;IACH,cAAc,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,KAAK,IAAI,CAAC;CAClE;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAkB,SAAQ,SAAS;IAClD;;;;;;;;;OASG;IACH,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;CAC3D;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAiB,SAAQ,SAAS;IACjD;;;;;OAKG;IACH,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,KAAK,cAAc,CAAC;CACxF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IpcSocket.js","sourceRoot":"","sources":["../../../src/ipc/IpcSocket.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAIH;;;KAGK;AACE,MAAM,YAAY,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,SAAS,OAAO,EAAE,CAAC;AAAvD,QAAA,YAAY,gBAA2C","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module IpcSocket\n */\n\nimport { LoggingMetaData } from \"@itwin/core-bentley\";\n\n/**\n * The prefix for all IpcSocket channels to disambiguate from system channels.\n * @internal\n * */\nexport const iTwinChannel = (channel: string) => `itwin.${channel}`;\n\n/**\n * A function to handle an Ipc message.\n * @public\n */\nexport type IpcListener = (evt: Event, ...args: any[]) => void;\n\n/**\n * Function returned when establishing an Ipc `receive` listener or `invoke` handler. Call this method to remove the listener/handler.\n * @public\n * @extensions\n */\nexport type RemoveFunction = () => void;\n\n/**\n * Payload of an IpcInvoke response. The presence of `error` indicates that the backend threw an exception and the\n * frontend will re-throw a [BackendError]$(frontend) with the `errorNumber` and `message` values.\n * The presence of iTwinError indicates that the backend threw an exception of type [[ITwinError]] and the frontend will re-throw that same error.\n * Otherwise the `result` member holds the response.\n * @internal */\nexport type IpcInvokeReturn = { result: any, error?: never, iTwinError?: never } | { result?: never, iTwinError?: never, error: { name: string, message: string, errorNumber: number, stack?: string } } |\n{ result?: never, error?: never, iTwinError: {namespace: string, errorKey: string, message: string, stack?: string, metadata?: LoggingMetaData, [key: string]: any } };\n/**\n * An inter-process socket connection between a single [IModelHost]($backend) on the backend (the node process), and an [IModelApp]($frontend) on\n * the frontend (the browser process.) Each side will implement this interface to form a two way connection. The frontend and backend\n * processes connected through an IpcSocket don't necessarily have to be on the same computer, but often are.\n * @public\n*/\nexport interface IpcSocket {\n /**\n * Send a message over the socket.\n * @param channel The name of the channel for the message. Must begin with the [[iTwinChannel]] prefix.\n * @param data The optional data of the message.\n * @note `data` is serialized with the [Structured Clone Algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm), so only\n * primitive types and `ArrayBuffers` are allowed.\n */\n send: (channel: string, ...data: any[]) => void;\n /**\n * Establish a handler to receive messages for a channel through a socket.\n * @param channel The name of the channel for the messages. Must begin with the [[iTwinChannel]] prefix.\n * @param listener A function called when messages are sent over `channel`\n * @note returns A function to call to remove the listener.\n */\n addListener: (channel: string, listener: IpcListener) => RemoveFunction;\n /**\n * Remove a previously registered listener\n * @param channel The name of the channel for the listener previously registered with [[addListener]]\n * @param listener The function passed to [[addListener]]\n */\n removeListener: (channel: string, listener: IpcListener) => void;\n}\n\n/**\n * Interface for the frontend (browser) side of a socket connection. Frontends may invoke methods implemented on the backend.\n * @public\n */\nexport interface IpcSocketFrontend extends IpcSocket {\n /**\n * Send a message to the backend via `channel` and expect a result asynchronously.\n * @param channel The name of the channel for the method. Must begin with the [[iTwinChannel]] prefix.\n * @see Electron [ipcRenderer.invoke](https://www.electronjs.org/docs/api/ipc-renderer) documentation for details.\n * Note that this interface *may* be implemented via Electron for desktop apps, or via\n * [WebSockets](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API) for mobile or web-based\n * Ipc connections. In either case, the Electron documentation provides the specifications for how it works.\n * @note `args` are serialized with the [Structured Clone Algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm), so only\n * primitive types and `ArrayBuffers` are allowed.\n */\n invoke: (channel: string, ...args: any[]) => Promise<any>;\n}\n\n/**\n * Interface for the backend (Node.js) side of a socket connection. Backends provide the implementation\n * of methods that are invoked from the frontend.\n * @public\n */\nexport interface IpcSocketBackend extends IpcSocket {\n /**\n * Establish a backend implementation of an Ipc interface for a channel.\n * @param channel The name of the channel for this handler. Must begin with the [[iTwinChannel]] prefix.\n * @param handler A function that supplies the implementation for methods invoked over `channel` via [[IpcSocketFrontend.invoke]]\n * @note returns A function to call to remove the handler.\n */\n handle: (channel: string, handler: (...args: any[]) => Promise<any>) => RemoveFunction;\n}\n\n"]}
|
|
1
|
+
{"version":3,"file":"IpcSocket.js","sourceRoot":"","sources":["../../../src/ipc/IpcSocket.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAIH;;;KAGK;AACE,MAAM,YAAY,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,SAAS,OAAO,EAAE,CAAC;AAAvD,QAAA,YAAY,gBAA2C","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module IpcSocket\n */\n\nimport { LoggingMetaData } from \"@itwin/core-bentley\";\n\n/**\n * The prefix for all IpcSocket channels to disambiguate from system channels.\n * @internal\n * */\nexport const iTwinChannel = (channel: string) => `itwin.${channel}`;\n\n/**\n * A function to handle an Ipc message.\n * @public\n */\nexport type IpcListener = (evt: Event, ...args: any[]) => void;\n\n/**\n * Function returned when establishing an Ipc `receive` listener or `invoke` handler. Call this method to remove the listener/handler.\n * @public\n * @extensions\n */\nexport type RemoveFunction = () => void;\n\n/**\n * Payload of an IpcInvoke response. The presence of `error` indicates that the backend threw an exception and the\n * frontend will re-throw a [BackendError]$(frontend) with the `errorNumber` and `message` values.\n * The presence of iTwinError indicates that the backend threw an exception of type [[ITwinError]] and the frontend will re-throw that same error.\n * Otherwise the `result` member holds the response.\n * @internal */\nexport type IpcInvokeReturn = { result: any, error?: never, iTwinError?: never } | { result?: never, iTwinError?: never, error: { name: string, message: string, errorNumber: number, stack?: string, metadata?: LoggingMetaData } } |\n{ result?: never, error?: never, iTwinError: { namespace: string, errorKey: string, message: string, stack?: string, metadata?: LoggingMetaData, [key: string]: any } };\n/**\n * An inter-process socket connection between a single [IModelHost]($backend) on the backend (the node process), and an [IModelApp]($frontend) on\n * the frontend (the browser process.) Each side will implement this interface to form a two way connection. The frontend and backend\n * processes connected through an IpcSocket don't necessarily have to be on the same computer, but often are.\n * @public\n*/\nexport interface IpcSocket {\n /**\n * Send a message over the socket.\n * @param channel The name of the channel for the message. Must begin with the [[iTwinChannel]] prefix.\n * @param data The optional data of the message.\n * @note `data` is serialized with the [Structured Clone Algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm), so only\n * primitive types and `ArrayBuffers` are allowed.\n */\n send: (channel: string, ...data: any[]) => void;\n /**\n * Establish a handler to receive messages for a channel through a socket.\n * @param channel The name of the channel for the messages. Must begin with the [[iTwinChannel]] prefix.\n * @param listener A function called when messages are sent over `channel`\n * @note returns A function to call to remove the listener.\n */\n addListener: (channel: string, listener: IpcListener) => RemoveFunction;\n /**\n * Remove a previously registered listener\n * @param channel The name of the channel for the listener previously registered with [[addListener]]\n * @param listener The function passed to [[addListener]]\n */\n removeListener: (channel: string, listener: IpcListener) => void;\n}\n\n/**\n * Interface for the frontend (browser) side of a socket connection. Frontends may invoke methods implemented on the backend.\n * @public\n */\nexport interface IpcSocketFrontend extends IpcSocket {\n /**\n * Send a message to the backend via `channel` and expect a result asynchronously.\n * @param channel The name of the channel for the method. Must begin with the [[iTwinChannel]] prefix.\n * @see Electron [ipcRenderer.invoke](https://www.electronjs.org/docs/api/ipc-renderer) documentation for details.\n * Note that this interface *may* be implemented via Electron for desktop apps, or via\n * [WebSockets](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API) for mobile or web-based\n * Ipc connections. In either case, the Electron documentation provides the specifications for how it works.\n * @note `args` are serialized with the [Structured Clone Algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm), so only\n * primitive types and `ArrayBuffers` are allowed.\n */\n invoke: (channel: string, ...args: any[]) => Promise<any>;\n}\n\n/**\n * Interface for the backend (Node.js) side of a socket connection. Backends provide the implementation\n * of methods that are invoked from the frontend.\n * @public\n */\nexport interface IpcSocketBackend extends IpcSocket {\n /**\n * Establish a backend implementation of an Ipc interface for a channel.\n * @param channel The name of the channel for this handler. Must begin with the [[iTwinChannel]] prefix.\n * @param handler A function that supplies the implementation for methods invoked over `channel` via [[IpcSocketFrontend.invoke]]\n * @note returns A function to call to remove the handler.\n */\n handle: (channel: string, handler: (...args: any[]) => Promise<any>) => RemoveFunction;\n}\n\n"]}
|
package/lib/esm/ITwinError.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { LoggingMetaData } from "@itwin/core-bentley";
|
|
5
5
|
import { LockState } from "./IModelError";
|
|
6
|
+
import { BriefcaseId } from "./BriefcaseTypes";
|
|
6
7
|
/**
|
|
7
8
|
* Detailed information about a particular object Lock that is causing the Lock update conflict.
|
|
8
9
|
* An example of a lock update conflict would be attempting to use [LockControl.acquireLocks]($backend) on an object that is already locked by another Briefcase.
|
|
@@ -17,20 +18,34 @@ export interface InUseLock {
|
|
|
17
18
|
*/
|
|
18
19
|
state: LockState;
|
|
19
20
|
/** An array of Briefcase ids that hold this lock. */
|
|
20
|
-
briefcaseIds:
|
|
21
|
+
briefcaseIds: BriefcaseId[];
|
|
21
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* iTwinjs Core namespace namespace for a developer/application.
|
|
25
|
+
* @beta
|
|
26
|
+
*/
|
|
27
|
+
export declare const iTwinjsCoreNamespace = "itwinjs-core";
|
|
28
|
+
/**
|
|
29
|
+
* error keys object used to describe an error keys for a developer/application.
|
|
30
|
+
* @beta
|
|
31
|
+
*/
|
|
32
|
+
export declare const iTwinErrorKeys: {
|
|
33
|
+
readonly inUseLocks: "in-use-locks";
|
|
34
|
+
readonly channelNest: "channel-may-not-nest";
|
|
35
|
+
readonly channelNotAllowed: "channel-not-allowed";
|
|
36
|
+
readonly channelRootExists: "channel-root-exists";
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Record for all itwin error messages.
|
|
40
|
+
* @beta
|
|
41
|
+
*/
|
|
42
|
+
export declare const iTwinErrorMessages: Record<keyof typeof iTwinErrorKeys, (...args: any[]) => string>;
|
|
22
43
|
/**
|
|
23
44
|
* An interface used to describe an error for a developer/application. The message is not intended to be displayed to an end user.
|
|
24
45
|
* This error interface should be extended when needing to throw errors with extra properties defined on them. See [[InUseLocksError]] for an example.
|
|
25
|
-
* When extending ITwinError, one should typically add a type guard function and a function to throw the error either to a namespace for their error or as standalone functions.
|
|
26
|
-
* See [[InUseLocksError.throwInUseLocksError]] and [[InUseLocksError.isInUseLocksError]] for examples of how to throw and check that an error is of type InUseLocksError.
|
|
27
|
-
* * Example of catching a ITwinError:
|
|
28
|
-
* ``` ts
|
|
29
|
-
* [[include:ITwinError.catchAndHandleITwinError]]
|
|
30
|
-
* ```
|
|
31
46
|
* @beta
|
|
32
47
|
*/
|
|
33
|
-
export interface ITwinError {
|
|
48
|
+
export interface ITwinError extends Error {
|
|
34
49
|
/** namespace for the error. This is a unique qualifier for the errorKey. */
|
|
35
50
|
namespace: string;
|
|
36
51
|
/** unique key for error, within namespace. All errorKeys within the same namespace must be unique. */
|
|
@@ -48,25 +63,46 @@ export interface ITwinError {
|
|
|
48
63
|
* @beta
|
|
49
64
|
*/
|
|
50
65
|
export interface InUseLocksError extends ITwinError {
|
|
51
|
-
namespace: "itwinjs-core";
|
|
52
|
-
errorKey: "in-use-locks";
|
|
53
66
|
inUseLocks: InUseLock[];
|
|
54
67
|
}
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
/**
|
|
69
|
+
* A function which will be used to construct an [[ITwinError]].
|
|
70
|
+
* @param namespace The namespace associated with the error.
|
|
71
|
+
* @param errorKey The errorKey associated with the error.
|
|
72
|
+
* @param message The message associated with the error.
|
|
73
|
+
* @param metadata Metadata associated with the error.
|
|
74
|
+
* @beta
|
|
75
|
+
*/
|
|
76
|
+
export declare function constructITwinError(namespace: string, errorKey: string, message?: string, metadata?: LoggingMetaData): ITwinError;
|
|
77
|
+
/**
|
|
78
|
+
* A function which constructs a detailed error for example [[ InUseLocksError ]] above.
|
|
79
|
+
* @param namespace The namespace associated with the error.
|
|
80
|
+
* @param errorKey The errorKey associated with the error.
|
|
81
|
+
* @param details Other details associated with the error.
|
|
82
|
+
* @param message The message associated with the error.
|
|
83
|
+
* @param metadata Metadata associated with the error.
|
|
84
|
+
* @beta
|
|
85
|
+
*/
|
|
86
|
+
export declare function constructDetailedError<T extends ITwinError>(namespace: string, errorKey: string, details: Omit<T, keyof ITwinError>, message?: string, metadata?: LoggingMetaData): T;
|
|
87
|
+
/**
|
|
88
|
+
* a high level function that returns a type asserter function which would return whether or not the passed in parameter is an [[ITwinError]]
|
|
89
|
+
* @param namespace The namespace associated with the error.
|
|
90
|
+
* @param errorKey The errorKey associated with the error.
|
|
91
|
+
* @beta
|
|
92
|
+
*/
|
|
93
|
+
export declare function createITwinErrorTypeAsserter<T extends ITwinError>(namespace: string, errorKey: string): (error: unknown) => error is T;
|
|
94
|
+
/**
|
|
95
|
+
* get the meta data associated with this ITwinError, if any.
|
|
96
|
+
* @param error The error for which metadata is required.
|
|
97
|
+
* @beta
|
|
98
|
+
*/
|
|
99
|
+
export declare function getITwinErrorMetaData(error: ITwinError): object | undefined;
|
|
100
|
+
/**
|
|
101
|
+
* type guard function that returns whether or not the passed in parameter is an [[ITwinError]]
|
|
102
|
+
* @param error The error which is to ve verified.
|
|
103
|
+
* @param namespace The namespace associated with the error.
|
|
104
|
+
* @param errorKey The errorKey associated with the error.
|
|
105
|
+
* @beta
|
|
106
|
+
*/
|
|
107
|
+
export declare function isITwinError(error: unknown, namespace?: string, errorKey?: string): error is ITwinError;
|
|
72
108
|
//# sourceMappingURL=ITwinError.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ITwinError.d.ts","sourceRoot":"","sources":["../../src/ITwinError.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"ITwinError.d.ts","sourceRoot":"","sources":["../../src/ITwinError.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,KAAK,EAAE,SAAS,CAAC;IACjB,qDAAqD;IACrD,YAAY,E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,IAAI,CAAC,CACpC;AAED;;;;EAIE;AACF,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAE3E;AAED;;;;;;EAME;AACF,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,KAAK,IAAI,UAAU,CAKvG"}
|
package/lib/esm/ITwinError.js
CHANGED
|
@@ -5,48 +5,91 @@
|
|
|
5
5
|
/** @packageDocumentation
|
|
6
6
|
* @module iModels
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
8
|
+
/**
|
|
9
|
+
* iTwinjs Core namespace namespace for a developer/application.
|
|
10
|
+
* @beta
|
|
11
|
+
*/
|
|
12
|
+
export const iTwinjsCoreNamespace = "itwinjs-core";
|
|
13
|
+
/**
|
|
14
|
+
* error keys object used to describe an error keys for a developer/application.
|
|
15
|
+
* @beta
|
|
16
|
+
*/
|
|
17
|
+
export const iTwinErrorKeys = {
|
|
18
|
+
inUseLocks: "in-use-locks",
|
|
19
|
+
channelNest: "channel-may-not-nest",
|
|
20
|
+
channelNotAllowed: "channel-not-allowed",
|
|
21
|
+
channelRootExists: "channel-root-exists"
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Record for all itwin error messages.
|
|
25
|
+
* @beta
|
|
26
|
+
*/
|
|
27
|
+
export const iTwinErrorMessages = {
|
|
28
|
+
"inUseLocks": () => 'Objects are locked by another briefcase',
|
|
29
|
+
"channelNest": (id) => `Channel ${id} may not nest`,
|
|
30
|
+
"channelNotAllowed": (id) => `Channel ${id} is not allowed`,
|
|
31
|
+
"channelRootExists": (id) => `Channel ${id} root already exist`,
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* A function which will be used to construct an [[ITwinError]].
|
|
35
|
+
* @param namespace The namespace associated with the error.
|
|
36
|
+
* @param errorKey The errorKey associated with the error.
|
|
37
|
+
* @param message The message associated with the error.
|
|
38
|
+
* @param metadata Metadata associated with the error.
|
|
39
|
+
* @beta
|
|
40
|
+
*/
|
|
41
|
+
export function constructITwinError(namespace, errorKey, message, metadata) {
|
|
42
|
+
const error = new Error();
|
|
43
|
+
error.message = message ?? `${errorKey} occurred`;
|
|
44
|
+
error.name = `${namespace}:${errorKey}`;
|
|
45
|
+
error.namespace = namespace;
|
|
46
|
+
error.errorKey = errorKey;
|
|
47
|
+
error.metadata = metadata;
|
|
48
|
+
Error.captureStackTrace(error, constructITwinError); // Optional, but this would hide constructITwinError from stack.
|
|
49
|
+
return error;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* A function which constructs a detailed error for example [[ InUseLocksError ]] above.
|
|
53
|
+
* @param namespace The namespace associated with the error.
|
|
54
|
+
* @param errorKey The errorKey associated with the error.
|
|
55
|
+
* @param details Other details associated with the error.
|
|
56
|
+
* @param message The message associated with the error.
|
|
57
|
+
* @param metadata Metadata associated with the error.
|
|
58
|
+
* @beta
|
|
59
|
+
*/
|
|
60
|
+
export function constructDetailedError(namespace, errorKey, details, message, metadata) {
|
|
61
|
+
const baseError = constructITwinError(namespace, errorKey, message, metadata);
|
|
62
|
+
Error.captureStackTrace(baseError, constructDetailedError); // Optional, but this would hide constructDetailedError from stack.
|
|
63
|
+
return Object.assign(baseError, details);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* a high level function that returns a type asserter function which would return whether or not the passed in parameter is an [[ITwinError]]
|
|
67
|
+
* @param namespace The namespace associated with the error.
|
|
68
|
+
* @param errorKey The errorKey associated with the error.
|
|
69
|
+
* @beta
|
|
70
|
+
*/
|
|
71
|
+
export function createITwinErrorTypeAsserter(namespace, errorKey) {
|
|
72
|
+
return (error) => isITwinError(error, namespace, errorKey);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* get the meta data associated with this ITwinError, if any.
|
|
76
|
+
* @param error The error for which metadata is required.
|
|
77
|
+
* @beta
|
|
78
|
+
*/
|
|
79
|
+
export function getITwinErrorMetaData(error) {
|
|
80
|
+
return (typeof error.metadata === "function") ? error.metadata() : error.metadata;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* type guard function that returns whether or not the passed in parameter is an [[ITwinError]]
|
|
84
|
+
* @param error The error which is to ve verified.
|
|
85
|
+
* @param namespace The namespace associated with the error.
|
|
86
|
+
* @param errorKey The errorKey associated with the error.
|
|
87
|
+
* @beta
|
|
88
|
+
*/
|
|
89
|
+
export function isITwinError(error, namespace, errorKey) {
|
|
90
|
+
return error !== undefined && error !== null && typeof error === "object"
|
|
91
|
+
&& "namespace" in error && "errorKey" in error && "message" in error
|
|
92
|
+
&& (namespace === undefined || error.namespace === namespace)
|
|
93
|
+
&& (errorKey === undefined || error.errorKey === errorKey);
|
|
94
|
+
}
|
|
52
95
|
//# sourceMappingURL=ITwinError.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ITwinError.js","sourceRoot":"","sources":["../../src/ITwinError.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;
|
|
1
|
+
{"version":3,"file":"ITwinError.js","sourceRo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B,EAAE,OAAkC,EAAE,OAAgB,EAAE,QAA0B;IAChL,MAAM,SAAS,GAAG,mBAAmB,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IAE9E,KAAK,CAAC,iBAAiB,CAAC,SAAS,EAAE,sBAAsB,CAAC,CAAC,CAAC,mEAAmE;IAC/H,OAAO,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAM,CAAC;AAChD,CAAC;AAED;;;;;EAKE;AACF,MAAM,UAAU,4BAA4B,CAAuB,SAAiB,EAAE,QAAgB;IACpG,OAAO,CAAC,KAAc,EAAc,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;AAClF,CAAC;AAED;;;;EAIE;AACF,MAAM,UAAU,qBAAqB,CAAC,KAAiB;IACrD,OAAO,CAAC,OAAO,KAAK,CAAC,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC;AACpF,CAAC;AAED;;;;;;EAME;AACF,MAAM,UAAU,YAAY,CAAC,KAAc,EAAE,SAAkB,EAAE,QAAiB;IAChF,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;WACpE,WAAW,IAAI,KAAK,IAAI,UAAU,IAAI,KAAK,IAAI,SAAS,IAAI,KAAK;WACjE,CAAC,SAAS,KAAK,SAAS,IAAK,KAAoB,CAAC,SAAS,KAAK,SAAS,CAAC;WAC1E,CAAC,QAAQ,KAAK,SAAS,IAAK,KAAoB,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC;AAC/E,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module iModels\n */\n\nimport { LoggingMetaData } from \"@itwin/core-bentley\";\nimport { LockState } from \"./IModelError\";\nimport { BriefcaseId } from \"./BriefcaseTypes\";\n\n/**\n * Detailed information about a particular object Lock that is causing the Lock update conflict.\n * An example of a lock update conflict would be attempting to use [LockControl.acquireLocks]($backend) on an object that is already locked by another Briefcase.\n * @beta\n */\nexport interface InUseLock {\n /** Id of the object that is causing conflict. */\n objectId: string;\n /**\n * The level of conflicting lock. Possible values are {@link LockState.Shared}, {@link LockState.Exclusive}.\n * See {@link LockState}.\n */\n state: LockState;\n /** An array of Briefcase ids that hold this lock. */\n briefcaseIds: BriefcaseId[];\n}\n\n/**\n * iTwinjs Core namespace namespace for a developer/application.\n * @beta\n */\nexport const iTwinjsCoreNamespace = \"itwinjs-core\";\n\n/**\n * error keys object used to describe an error keys for a developer/application.\n * @beta\n */\nexport const iTwinErrorKeys = {\n inUseLocks: \"in-use-locks\",\n channelNest: \"channel-may-not-nest\",\n channelNotAllowed: \"channel-not-allowed\",\n channelRootExists: \"channel-root-exists\"\n} as const;\n\n/**\n * Record for all itwin error messages.\n * @beta\n */\nexport const iTwinErrorMessages: Record<keyof typeof iTwinErrorKeys, (...args: any[]) => string> = {\n \"inUseLocks\": () => 'Objects are locked by another briefcase',\n \"channelNest\": (id) => `Channel ${id} may not nest`,\n \"channelNotAllowed\": (id) => `Channel ${id} is not allowed`,\n \"channelRootExists\": (id) => `Channel ${id} root already exist`,\n};\n\n\n/**\n * An interface used to describe an error for a developer/application. The message is not intended to be displayed to an end user.\n * This error interface should be extended when needing to throw errors with extra properties defined on them. See [[InUseLocksError]] for an example.\n * @beta\n */\nexport interface ITwinError extends Error {\n /** namespace for the error. This is a unique qualifier for the errorKey. */\n namespace: string;\n /** unique key for error, within namespace. All errorKeys within the same namespace must be unique. */\n errorKey: string;\n /** explanation of what went wrong. Intended to be read by a developer. */\n message: string;\n /** stack trace of the error. */\n stack?: string;\n /** metadata about the exception. */\n metadata?: LoggingMetaData;\n}\n\n/**\n * An error raised when there is a lock conflict detected.\n * Typically this error would be thrown by [LockControl.acquireLocks]($backend) when you are requesting a lock on an element that is already held by another briefcase.\n * @beta\n*/\nexport interface InUseLocksError extends ITwinError {\n inUseLocks: InUseLock[];\n}\n\n/**\n* A function which will be used to construct an [[ITwinError]].\n* @param namespace The namespace associated with the error.\n* @param errorKey The errorKey associated with the error.\n* @param message The message associated with the error.\n* @param metadata Metadata associated with the error.\n* @beta\n*/\nexport function constructITwinError(namespace: string, errorKey: string, message?: string, metadata?: LoggingMetaData): ITwinError {\n\n const error = new Error() as ITwinError;\n error.message = message ?? `${errorKey} occurred`;\n error.name = `${namespace}:${errorKey}`;\n error.namespace = namespace;\n error.errorKey = errorKey;\n error.metadata = metadata;\n\n Error.captureStackTrace(error, constructITwinError); // Optional, but this would hide constructITwinError from stack.\n return error;\n}\n\n/**\n* A function which constructs a detailed error for example [[ InUseLocksError ]] above.\n* @param namespace The namespace associated with the error.\n* @param errorKey The errorKey associated with the error.\n* @param details Other details associated with the error.\n* @param message The message associated with the error.\n* @param metadata Metadata associated with the error.\n* @beta\n*/\nexport function constructDetailedError<T extends ITwinError>(namespace: string, errorKey: string, details: Omit<T, keyof ITwinError>, message?: string, metadata?: LoggingMetaData): T {\n const baseError = constructITwinError(namespace, errorKey, message, metadata);\n\n Error.captureStackTrace(baseError, constructDetailedError); // Optional, but this would hide constructDetailedError from stack.\n return Object.assign(baseError, details) as T;\n}\n\n/**\n * a high level function that returns a type asserter function which would return whether or not the passed in parameter is an [[ITwinError]]\n * @param namespace The namespace associated with the error.\n * @param errorKey The errorKey associated with the error.\n * @beta\n*/\nexport function createITwinErrorTypeAsserter<T extends ITwinError>(namespace: string, errorKey: string) {\n return (error: unknown): error is T => isITwinError(error, namespace, errorKey);\n}\n\n/**\n * get the meta data associated with this ITwinError, if any.\n * @param error The error for which metadata is required.\n * @beta\n*/\nexport function getITwinErrorMetaData(error: ITwinError): object | undefined {\n return (typeof error.metadata === \"function\") ? error.metadata() : error.metadata;\n}\n\n/**\n * type guard function that returns whether or not the passed in parameter is an [[ITwinError]]\n * @param error The error which is to ve verified.\n * @param namespace The namespace associated with the error.\n * @param errorKey The errorKey associated with the error.\n * @beta\n*/\nexport function isITwinError(error: unknown, namespace?: string, errorKey?: string): error is ITwinError {\n return error !== undefined && error !== null && typeof error === \"object\"\n && \"namespace\" in error && \"errorKey\" in error && \"message\" in error\n && (namespace === undefined || (error as ITwinError).namespace === namespace)\n && (errorKey === undefined || (error as ITwinError).errorKey === errorKey);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IpcSocket.d.ts","sourceRoot":"","sources":["../../../src/ipc/IpcSocket.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD;;;KAGK;AACL,eAAO,MAAM,YAAY,YAAa,MAAM,WAAuB,CAAC;AAEpE;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;AAE/D;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC;AAExC;;;;;eAKe;AACf,MAAM,MAAM,eAAe,GAAG;IAAE,MAAM,EAAE,GAAG,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IAAC,UAAU,CAAC,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,MAAM,CAAC,EAAE,KAAK,CAAC;IAAC,UAAU,CAAC,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"IpcSocket.d.ts","sourceRoot":"","sources":["../../../src/ipc/I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,EAAE,KAAK,IAAI,CAAC;IAChD;;;;;OAKG;IACH,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,KAAK,cAAc,CAAC;IACxE;;;;OAIG;IACH,cAAc,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,KAAK,IAAI,CAAC;CAClE;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAkB,SAAQ,SAAS;IAClD;;;;;;;;;OASG;IACH,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;CAC3D;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAiB,SAAQ,SAAS;IACjD;;;;;OAKG;IACH,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,KAAK,cAAc,CAAC;CACxF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IpcSocket.js","sourceRoot":"","sources":["../../../src/ipc/IpcSocket.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAIH;;;KAGK;AACL,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,SAAS,OAAO,EAAE,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module IpcSocket\n */\n\nimport { LoggingMetaData } from \"@itwin/core-bentley\";\n\n/**\n * The prefix for all IpcSocket channels to disambiguate from system channels.\n * @internal\n * */\nexport const iTwinChannel = (channel: string) => `itwin.${channel}`;\n\n/**\n * A function to handle an Ipc message.\n * @public\n */\nexport type IpcListener = (evt: Event, ...args: any[]) => void;\n\n/**\n * Function returned when establishing an Ipc `receive` listener or `invoke` handler. Call this method to remove the listener/handler.\n * @public\n * @extensions\n */\nexport type RemoveFunction = () => void;\n\n/**\n * Payload of an IpcInvoke response. The presence of `error` indicates that the backend threw an exception and the\n * frontend will re-throw a [BackendError]$(frontend) with the `errorNumber` and `message` values.\n * The presence of iTwinError indicates that the backend threw an exception of type [[ITwinError]] and the frontend will re-throw that same error.\n * Otherwise the `result` member holds the response.\n * @internal */\nexport type IpcInvokeReturn = { result: any, error?: never, iTwinError?: never } | { result?: never, iTwinError?: never, error: { name: string, message: string, errorNumber: number, stack?: string } } |\n{ result?: never, error?: never, iTwinError: {namespace: string, errorKey: string, message: string, stack?: string, metadata?: LoggingMetaData, [key: string]: any } };\n/**\n * An inter-process socket connection between a single [IModelHost]($backend) on the backend (the node process), and an [IModelApp]($frontend) on\n * the frontend (the browser process.) Each side will implement this interface to form a two way connection. The frontend and backend\n * processes connected through an IpcSocket don't necessarily have to be on the same computer, but often are.\n * @public\n*/\nexport interface IpcSocket {\n /**\n * Send a message over the socket.\n * @param channel The name of the channel for the message. Must begin with the [[iTwinChannel]] prefix.\n * @param data The optional data of the message.\n * @note `data` is serialized with the [Structured Clone Algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm), so only\n * primitive types and `ArrayBuffers` are allowed.\n */\n send: (channel: string, ...data: any[]) => void;\n /**\n * Establish a handler to receive messages for a channel through a socket.\n * @param channel The name of the channel for the messages. Must begin with the [[iTwinChannel]] prefix.\n * @param listener A function called when messages are sent over `channel`\n * @note returns A function to call to remove the listener.\n */\n addListener: (channel: string, listener: IpcListener) => RemoveFunction;\n /**\n * Remove a previously registered listener\n * @param channel The name of the channel for the listener previously registered with [[addListener]]\n * @param listener The function passed to [[addListener]]\n */\n removeListener: (channel: string, listener: IpcListener) => void;\n}\n\n/**\n * Interface for the frontend (browser) side of a socket connection. Frontends may invoke methods implemented on the backend.\n * @public\n */\nexport interface IpcSocketFrontend extends IpcSocket {\n /**\n * Send a message to the backend via `channel` and expect a result asynchronously.\n * @param channel The name of the channel for the method. Must begin with the [[iTwinChannel]] prefix.\n * @see Electron [ipcRenderer.invoke](https://www.electronjs.org/docs/api/ipc-renderer) documentation for details.\n * Note that this interface *may* be implemented via Electron for desktop apps, or via\n * [WebSockets](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API) for mobile or web-based\n * Ipc connections. In either case, the Electron documentation provides the specifications for how it works.\n * @note `args` are serialized with the [Structured Clone Algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm), so only\n * primitive types and `ArrayBuffers` are allowed.\n */\n invoke: (channel: string, ...args: any[]) => Promise<any>;\n}\n\n/**\n * Interface for the backend (Node.js) side of a socket connection. Backends provide the implementation\n * of methods that are invoked from the frontend.\n * @public\n */\nexport interface IpcSocketBackend extends IpcSocket {\n /**\n * Establish a backend implementation of an Ipc interface for a channel.\n * @param channel The name of the channel for this handler. Must begin with the [[iTwinChannel]] prefix.\n * @param handler A function that supplies the implementation for methods invoked over `channel` via [[IpcSocketFrontend.invoke]]\n * @note returns A function to call to remove the handler.\n */\n handle: (channel: string, handler: (...args: any[]) => Promise<any>) => RemoveFunction;\n}\n\n"]}
|
|
1
|
+
{"version":3,"file":"IpcSocket.js","sourceRoot":"","sources":["../../../src/ipc/IpcSocket.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAIH;;;KAGK;AACL,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,SAAS,OAAO,EAAE,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module IpcSocket\n */\n\nimport { LoggingMetaData } from \"@itwin/core-bentley\";\n\n/**\n * The prefix for all IpcSocket channels to disambiguate from system channels.\n * @internal\n * */\nexport const iTwinChannel = (channel: string) => `itwin.${channel}`;\n\n/**\n * A function to handle an Ipc message.\n * @public\n */\nexport type IpcListener = (evt: Event, ...args: any[]) => void;\n\n/**\n * Function returned when establishing an Ipc `receive` listener or `invoke` handler. Call this method to remove the listener/handler.\n * @public\n * @extensions\n */\nexport type RemoveFunction = () => void;\n\n/**\n * Payload of an IpcInvoke response. The presence of `error` indicates that the backend threw an exception and the\n * frontend will re-throw a [BackendError]$(frontend) with the `errorNumber` and `message` values.\n * The presence of iTwinError indicates that the backend threw an exception of type [[ITwinError]] and the frontend will re-throw that same error.\n * Otherwise the `result` member holds the response.\n * @internal */\nexport type IpcInvokeReturn = { result: any, error?: never, iTwinError?: never } | { result?: never, iTwinError?: never, error: { name: string, message: string, errorNumber: number, stack?: string, metadata?: LoggingMetaData } } |\n{ result?: never, error?: never, iTwinError: { namespace: string, errorKey: string, message: string, stack?: string, metadata?: LoggingMetaData, [key: string]: any } };\n/**\n * An inter-process socket connection between a single [IModelHost]($backend) on the backend (the node process), and an [IModelApp]($frontend) on\n * the frontend (the browser process.) Each side will implement this interface to form a two way connection. The frontend and backend\n * processes connected through an IpcSocket don't necessarily have to be on the same computer, but often are.\n * @public\n*/\nexport interface IpcSocket {\n /**\n * Send a message over the socket.\n * @param channel The name of the channel for the message. Must begin with the [[iTwinChannel]] prefix.\n * @param data The optional data of the message.\n * @note `data` is serialized with the [Structured Clone Algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm), so only\n * primitive types and `ArrayBuffers` are allowed.\n */\n send: (channel: string, ...data: any[]) => void;\n /**\n * Establish a handler to receive messages for a channel through a socket.\n * @param channel The name of the channel for the messages. Must begin with the [[iTwinChannel]] prefix.\n * @param listener A function called when messages are sent over `channel`\n * @note returns A function to call to remove the listener.\n */\n addListener: (channel: string, listener: IpcListener) => RemoveFunction;\n /**\n * Remove a previously registered listener\n * @param channel The name of the channel for the listener previously registered with [[addListener]]\n * @param listener The function passed to [[addListener]]\n */\n removeListener: (channel: string, listener: IpcListener) => void;\n}\n\n/**\n * Interface for the frontend (browser) side of a socket connection. Frontends may invoke methods implemented on the backend.\n * @public\n */\nexport interface IpcSocketFrontend extends IpcSocket {\n /**\n * Send a message to the backend via `channel` and expect a result asynchronously.\n * @param channel The name of the channel for the method. Must begin with the [[iTwinChannel]] prefix.\n * @see Electron [ipcRenderer.invoke](https://www.electronjs.org/docs/api/ipc-renderer) documentation for details.\n * Note that this interface *may* be implemented via Electron for desktop apps, or via\n * [WebSockets](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API) for mobile or web-based\n * Ipc connections. In either case, the Electron documentation provides the specifications for how it works.\n * @note `args` are serialized with the [Structured Clone Algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm), so only\n * primitive types and `ArrayBuffers` are allowed.\n */\n invoke: (channel: string, ...args: any[]) => Promise<any>;\n}\n\n/**\n * Interface for the backend (Node.js) side of a socket connection. Backends provide the implementation\n * of methods that are invoked from the frontend.\n * @public\n */\nexport interface IpcSocketBackend extends IpcSocket {\n /**\n * Establish a backend implementation of an Ipc interface for a channel.\n * @param channel The name of the channel for this handler. Must begin with the [[iTwinChannel]] prefix.\n * @param handler A function that supplies the implementation for methods invoked over `channel` via [[IpcSocketFrontend.invoke]]\n * @note returns A function to call to remove the handler.\n */\n handle: (channel: string, handler: (...args: any[]) => Promise<any>) => RemoveFunction;\n}\n\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-common",
|
|
3
|
-
"version": "5.0.0-dev.
|
|
3
|
+
"version": "5.0.0-dev.84",
|
|
4
4
|
"description": "iTwin.js components common to frontend and backend",
|
|
5
5
|
"main": "lib/cjs/core-common.js",
|
|
6
6
|
"module": "lib/esm/core-common.js",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"js-base64": "^3.6.1"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@itwin/core-bentley": "5.0.0-dev.
|
|
31
|
-
"@itwin/core-geometry": "5.0.0-dev.
|
|
30
|
+
"@itwin/core-bentley": "5.0.0-dev.84",
|
|
31
|
+
"@itwin/core-geometry": "5.0.0-dev.84"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@itwin/eslint-plugin": "5.0.0-dev.1",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"rimraf": "^6.0.1",
|
|
43
43
|
"typescript": "~5.6.2",
|
|
44
44
|
"vitest": "^3.0.6",
|
|
45
|
-
"@itwin/build-tools": "5.0.0-dev.
|
|
46
|
-
"@itwin/core-bentley": "5.0.0-dev.
|
|
47
|
-
"@itwin/core-geometry": "5.0.0-dev.
|
|
45
|
+
"@itwin/build-tools": "5.0.0-dev.84",
|
|
46
|
+
"@itwin/core-bentley": "5.0.0-dev.84",
|
|
47
|
+
"@itwin/core-geometry": "5.0.0-dev.84"
|
|
48
48
|
},
|
|
49
49
|
"nyc": {
|
|
50
50
|
"extends": "./node_modules/@itwin/build-tools/.nycrc",
|