@itwin/core-mobile 4.11.0-dev.2 → 4.11.0-dev.4
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/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
# Change Log - @itwin/core-mobile
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Wed, 02 Apr 2025 19:37:09 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 4.10.12
|
|
6
|
+
Wed, 02 Apr 2025 19:35:47 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
9
|
+
|
|
10
|
+
## 4.10.11
|
|
11
|
+
Wed, 19 Mar 2025 15:30:39 GMT
|
|
12
|
+
|
|
13
|
+
_Version update only_
|
|
14
|
+
|
|
15
|
+
## 4.10.10
|
|
16
|
+
Tue, 11 Mar 2025 15:25:11 GMT
|
|
17
|
+
|
|
18
|
+
_Version update only_
|
|
19
|
+
|
|
20
|
+
## 4.10.9
|
|
21
|
+
Tue, 11 Mar 2025 05:17:33 GMT
|
|
22
|
+
|
|
23
|
+
_Version update only_
|
|
24
|
+
|
|
25
|
+
## 4.10.8
|
|
26
|
+
Thu, 06 Mar 2025 14:13:37 GMT
|
|
27
|
+
|
|
28
|
+
_Version update only_
|
|
29
|
+
|
|
30
|
+
## 4.10.7
|
|
31
|
+
Tue, 18 Feb 2025 17:27:03 GMT
|
|
32
|
+
|
|
33
|
+
_Version update only_
|
|
34
|
+
|
|
35
|
+
## 4.10.6
|
|
36
|
+
Fri, 24 Jan 2025 08:02:40 GMT
|
|
37
|
+
|
|
38
|
+
_Version update only_
|
|
4
39
|
|
|
5
40
|
## 4.10.5
|
|
6
41
|
Tue, 21 Jan 2025 21:56:45 GMT
|
|
@@ -90,7 +90,7 @@ class MobileRpcServer {
|
|
|
90
90
|
_onConnectionMessage(data) {
|
|
91
91
|
let message = data;
|
|
92
92
|
if (Array.isArray(message)) {
|
|
93
|
-
throw new core_common_1.IModelError(
|
|
93
|
+
throw new core_common_1.IModelError(core_bentley_1.BentleyStatus.ERROR, "Unsupported data type");
|
|
94
94
|
}
|
|
95
95
|
if (Buffer.isBuffer(message)) {
|
|
96
96
|
if (message.byteOffset !== 0 || message.byteLength !== message.buffer.byteLength) {
|
|
@@ -115,9 +115,9 @@ class MobileRpcServer {
|
|
|
115
115
|
exports.MobileRpcServer = MobileRpcServer;
|
|
116
116
|
MobileRpcServer._nextId = -1;
|
|
117
117
|
MobileRpcServer.interop = {
|
|
118
|
-
handler: (_payload) => { throw new core_common_1.IModelError(
|
|
119
|
-
sendString: (_message, _connectionId) => { throw new core_common_1.IModelError(
|
|
120
|
-
sendBinary: (_message, _connectionId) => { throw new core_common_1.IModelError(
|
|
118
|
+
handler: (_payload) => { throw new core_common_1.IModelError(core_bentley_1.BentleyStatus.ERROR, "Not implemented."); },
|
|
119
|
+
sendString: (_message, _connectionId) => { throw new core_common_1.IModelError(core_bentley_1.BentleyStatus.ERROR, "No connection."); },
|
|
120
|
+
sendBinary: (_message, _connectionId) => { throw new core_common_1.IModelError(core_bentley_1.BentleyStatus.ERROR, "No connection."); },
|
|
121
121
|
port: 0,
|
|
122
122
|
connectionId: 0,
|
|
123
123
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileRpcServer.js","sourceRoot":"","sources":["../../../src/backend/MobileRpcServer.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAmJ/F,wCAoEC;AArND,yBAAyB;AACzB,oDAAgE;AAChE,mEAAkF;AAClF,iEAAoE;AACpE,6CAA0C;AAC1C,sDAAsD;AAOtD,IAAI,KAA8B,CAAC;AAEnC,gBAAgB;AAChB,MAAa,eAAe;IAgB1B,YAA2B,mBAA2D,SAAS;QAApE,qBAAgB,GAAhB,gBAAgB,CAAoD;QAC7F;;;;;;;;WAQG;QACH,IAAI,CAAC,UAAU,GAAG,WAAW,CAAC,GAAG,EAAE,G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,CAAC,EAAE,IAAI,CAAC,CAAC;QAC5C,MAAM,CAAC,OAAO,EAAE,CAAC;QACjB,gBAAgB,EAAE,CAAC;QACnB,MAAM,GAAG,IAAI,CAAC;QACb,MAAc,CAAC,iBAAiB,GAAG,KAAK,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,uBAAU,CAAC,iBAAiB,CAAC,WAAW,CAAC,GAAG,EAAE;QAC5C,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,OAAO;QACT,CAAC;QAED,MAAM,GAAG,IAAI,eAAe,CAAC,eAAe,CAAC,CAAC;QAC9C,aAAa,CAAC,YAAY,CAAC,CAAC;QAC5B,YAAY,GAAG,SAAS,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,uBAAU,CAAC,eAAe,CAAC,WAAW,CAAC,GAAG,EAAE;QAC1C,IAAI,OAAO,CAAC,YAAY,CAAC,KAAK,WAAW,EAAE,CAAC;YAC1C,aAAa,CAAC,YAAY,CAAC,CAAC;YAC5B,YAAY,GAAG,SAAS,CAAC;QAC3B,CAAC;QAED,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QAED,MAAM,CAAC,OAAO,EAAE,CAAC;QACjB,MAAM,GAAG,IAAI,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,qCAAiB,CAAC,aAAa,GAAG,GAAG,EAAE,CAAC,eAAe,CAAC,OAAO,CAAC;IAChE,WAAW,GAAG,IAAI,CAAC;AACrB,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\nimport * as ws from \"ws\";\nimport { BentleyStatus, IModelError } from \"@itwin/core-common\";\nimport { MobileRpcGateway, MobileRpcProtocol } from \"../common/MobileRpcProtocol\";\nimport { MobileRpcConfiguration } from \"../common/MobileRpcManager\";\nimport { MobileHost } from \"./MobileHost\";\nimport { ProcessDetector } from \"@itwin/core-bentley\";\n\ninterface MobileAddon {\n notifyListening: (port: number) => void;\n registerDeviceImpl: () => void;\n}\n\nlet addon: MobileAddon | undefined;\n\n/** @internal */\nexport class MobileRpcServer {\n private static _nextId = -1;\n\n public static interop: MobileRpcGateway = {\n handler: (_payload: ArrayBuffer | string) => { throw new IModelError(BentleyStatus.ERROR, \"Not implemented.\"); },\n sendString: (_message: string, _connectionId: number) => { throw new IModelError(BentleyStatus.ERROR, \"No connection.\"); },\n sendBinary: (_message: Uint8Array, _connectionId: number) => { throw new IModelError(BentleyStatus.ERROR, \"No connection.\"); },\n port: 0,\n connectionId: 0,\n };\n\n private _server: ws.Server;\n private _connection: ws | undefined;\n private _port: number;\n private _connectionId: number;\n private _pingTimer: NodeJS.Timeout;\n public constructor(private _pendingMessages: Array<string | Uint8Array> | undefined = undefined) {\n /* _pingTime is a fix for ios/mobile case where when the app moves into foreground from\n * background backend restart ws.Server and then notify frontend to reconnect. But ws.Server\n * listening event is not fired as node yield to kevent and wait for some io event to happen.\n * This causes a delay in reconnection which may be as long a 40 secs. To solve the issue we\n * create _pingTimer which causes kevent to yield back to uv poll so timer event can be fired.\n * This allow listening event to go through quickly (max 5ms). Once the listening event occur we\n * clear the timer. Here we use setInterval() just to make sure otherwise setTimeout() could equally\n * be effective\n */\n this._pingTimer = setInterval(() => { }, 5);\n this._port = MobileRpcConfiguration.setup.obtainPort();\n this._server = new ws.Server({ port: this._port });\n this._connectionId = ++MobileRpcServer._nextId;\n MobileRpcServer.interop.connectionId = this._connectionId;\n this._onListening();\n this._onConnection();\n }\n\n private _onListening() {\n this._server.on(\"listening\", () => {\n const address = this._server.address() as ws.AddressInfo;\n this._port = address.port;\n clearInterval(this._pingTimer);\n this._notifyListening();\n });\n }\n\n private _notifyListening() {\n MobileRpcServer.interop.port = this._port;\n\n if (addon) {\n addon.notifyListening(this._port);\n }\n\n if (this._connectionId !== 0) {\n MobileHost.reconnect(this._port);\n }\n }\n\n private _onConnection() {\n this._server.on(\"connection\", (connection) => {\n this._connection = connection;\n this._connection.on(\"message\", (data) => this._onConnectionMessage(data));\n this._createSender();\n this._sendPending();\n (global as any).__iTwinJsRpcReady = true;\n MobileHost.onConnected.raiseEvent();\n });\n }\n\n private _createSender() {\n const sender = (message: string | Uint8Array, connectionId: number) => {\n if (connectionId !== this._connectionId) {\n return;\n }\n\n this._connection!.send(message, (err) => {\n if (err) {\n throw err;\n }\n });\n };\n\n MobileRpcServer.interop.sendString = sender;\n MobileRpcServer.interop.sendBinary = sender;\n }\n\n private _sendPending() {\n if (this._pendingMessages === undefined)\n return;\n\n for (const message of this._pendingMessages) {\n this._connection!.send(message, (err) => {\n if (err) {\n throw err;\n }\n });\n }\n this._pendingMessages.length = 0;\n }\n\n private _onConnectionMessage(data: ws.Data) {\n let message = data;\n if (Array.isArray(message)) {\n throw new IModelError(BentleyStatus.ERROR, \"Unsupported data type\");\n }\n\n if (Buffer.isBuffer(message)) {\n if (message.byteOffset !== 0 || message.byteLength !== message.buffer.byteLength) {\n message = new Uint8Array(message.buffer, message.byteOffset, message.byteLength);\n } else {\n message = message.buffer;\n }\n }\n\n MobileRpcServer.interop.handler(message, this._connectionId);\n }\n\n public dispose() {\n clearInterval(this._pingTimer);\n if (this._connection) {\n MobileRpcServer.interop.sendString = () => { };\n MobileRpcServer.interop.sendBinary = () => { };\n this._connection.close();\n }\n\n this._server.close();\n }\n}\n\nlet mobileReady = false;\nlet hasSuspended = false;\n\nexport function setupMobileRpc() {\n if (mobileReady) {\n return;\n }\n\n if (ProcessDetector.isMobileAppBackend) {\n addon = (process as any)._linkedBinding(\"iModelJsMobile\");\n addon?.registerDeviceImpl();\n }\n\n let server: MobileRpcServer | null = new MobileRpcServer();\n\n /* The UV event loop (internal to node) is retained by handles,\n such as those created for setInterval/setTimeout and client/server connections.\n In a simple app, the RPC server may be the only handle retaining the UV loop.\n Thus, we install a temporary timer on suspend to prevent the loop from exiting prematurely.\n */\n let retainUvLoop: NodeJS.Timeout | undefined;\n const pendingMessages: Array<string | Uint8Array> = [];\n\n function usePendingSender() {\n const sender = (message: string | Uint8Array, _connectionId: number) => {\n pendingMessages.push(message);\n };\n MobileRpcServer.interop.sendString = sender;\n MobileRpcServer.interop.sendBinary = sender;\n }\n\n MobileHost.onEnterBackground.addListener(() => {\n hasSuspended = true;\n\n if (server === null) {\n return;\n }\n\n retainUvLoop = setInterval(() => { }, 1000);\n server.dispose();\n usePendingSender();\n server = null;\n (global as any).__iTwinJsRpcReady = false;\n });\n\n MobileHost.onEnterForeground.addListener(() => {\n if (!hasSuspended) {\n return;\n }\n\n server = new MobileRpcServer(pendingMessages);\n clearInterval(retainUvLoop);\n retainUvLoop = undefined;\n });\n\n MobileHost.onWillTerminate.addListener(() => {\n if (typeof (retainUvLoop) !== \"undefined\") {\n clearInterval(retainUvLoop);\n retainUvLoop = undefined;\n }\n\n if (server === null) {\n return;\n }\n\n server.dispose();\n server = null;\n });\n\n MobileRpcProtocol.obtainInterop = () => MobileRpcServer.interop;\n mobileReady = true;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MobileRpcServer.js","sourceRoot":"","sources":["../../../src/backend/MobileRpcServer.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAmJ/F,wCAoEC;AArND,yBAAyB;AACzB,oDAAiD;AACjD,mEAAkF;AAClF,iEAAoE;AACpE,6CAA0C;AAC1C,sDAAqE;AAOrE,IAAI,KAA8B,CAAC;AAEnC,gBAAgB;AAChB,MAAa,eAAe;IAgB1B,YAA2B,mBAA2D,SAAS;QAApE,qBAAgB,GAAhB,gBAAgB,CAAoD;QAC7F;;;;;;;;WAQG;QACH,IAAI,CAAC,UAAU,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;QAC5C,IAAI,CAAC,KAAK,GAAG,yCAAsB,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;QACvD,IAAI,CAAC,OAAO,GAAG,IAAI,EAAE,CAAC,M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K,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,uBAAU,CAAC,iBAAiB,CAAC,WAAW,CAAC,GAAG,EAAE;QAC5C,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,OAAO;QACT,CAAC;QAED,MAAM,GAAG,IAAI,eAAe,CAAC,eAAe,CAAC,CAAC;QAC9C,aAAa,CAAC,YAAY,CAAC,CAAC;QAC5B,YAAY,GAAG,SAAS,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,uBAAU,CAAC,eAAe,CAAC,WAAW,CAAC,GAAG,EAAE;QAC1C,IAAI,OAAO,CAAC,YAAY,CAAC,KAAK,WAAW,EAAE,CAAC;YAC1C,aAAa,CAAC,YAAY,CAAC,CAAC;YAC5B,YAAY,GAAG,SAAS,CAAC;QAC3B,CAAC;QAED,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QAED,MAAM,CAAC,OAAO,EAAE,CAAC;QACjB,MAAM,GAAG,IAAI,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,qCAAiB,CAAC,aAAa,GAAG,GAAG,EAAE,CAAC,eAAe,CAAC,OAAO,CAAC;IAChE,WAAW,GAAG,IAAI,CAAC;AACrB,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\nimport * as ws from \"ws\";\nimport { IModelError } from \"@itwin/core-common\";\nimport { MobileRpcGateway, MobileRpcProtocol } from \"../common/MobileRpcProtocol\";\nimport { MobileRpcConfiguration } from \"../common/MobileRpcManager\";\nimport { MobileHost } from \"./MobileHost\";\nimport { BentleyStatus, ProcessDetector } from \"@itwin/core-bentley\";\n\ninterface MobileAddon {\n notifyListening: (port: number) => void;\n registerDeviceImpl: () => void;\n}\n\nlet addon: MobileAddon | undefined;\n\n/** @internal */\nexport class MobileRpcServer {\n private static _nextId = -1;\n\n public static interop: MobileRpcGateway = {\n handler: (_payload: ArrayBuffer | string) => { throw new IModelError(BentleyStatus.ERROR, \"Not implemented.\"); },\n sendString: (_message: string, _connectionId: number) => { throw new IModelError(BentleyStatus.ERROR, \"No connection.\"); },\n sendBinary: (_message: Uint8Array, _connectionId: number) => { throw new IModelError(BentleyStatus.ERROR, \"No connection.\"); },\n port: 0,\n connectionId: 0,\n };\n\n private _server: ws.Server;\n private _connection: ws | undefined;\n private _port: number;\n private _connectionId: number;\n private _pingTimer: NodeJS.Timeout;\n public constructor(private _pendingMessages: Array<string | Uint8Array> | undefined = undefined) {\n /* _pingTime is a fix for ios/mobile case where when the app moves into foreground from\n * background backend restart ws.Server and then notify frontend to reconnect. But ws.Server\n * listening event is not fired as node yield to kevent and wait for some io event to happen.\n * This causes a delay in reconnection which may be as long a 40 secs. To solve the issue we\n * create _pingTimer which causes kevent to yield back to uv poll so timer event can be fired.\n * This allow listening event to go through quickly (max 5ms). Once the listening event occur we\n * clear the timer. Here we use setInterval() just to make sure otherwise setTimeout() could equally\n * be effective\n */\n this._pingTimer = setInterval(() => { }, 5);\n this._port = MobileRpcConfiguration.setup.obtainPort();\n this._server = new ws.Server({ port: this._port });\n this._connectionId = ++MobileRpcServer._nextId;\n MobileRpcServer.interop.connectionId = this._connectionId;\n this._onListening();\n this._onConnection();\n }\n\n private _onListening() {\n this._server.on(\"listening\", () => {\n const address = this._server.address() as ws.AddressInfo;\n this._port = address.port;\n clearInterval(this._pingTimer);\n this._notifyListening();\n });\n }\n\n private _notifyListening() {\n MobileRpcServer.interop.port = this._port;\n\n if (addon) {\n addon.notifyListening(this._port);\n }\n\n if (this._connectionId !== 0) {\n MobileHost.reconnect(this._port);\n }\n }\n\n private _onConnection() {\n this._server.on(\"connection\", (connection) => {\n this._connection = connection;\n this._connection.on(\"message\", (data) => this._onConnectionMessage(data));\n this._createSender();\n this._sendPending();\n (global as any).__iTwinJsRpcReady = true;\n MobileHost.onConnected.raiseEvent();\n });\n }\n\n private _createSender() {\n const sender = (message: string | Uint8Array, connectionId: number) => {\n if (connectionId !== this._connectionId) {\n return;\n }\n\n this._connection!.send(message, (err) => {\n if (err) {\n throw err;\n }\n });\n };\n\n MobileRpcServer.interop.sendString = sender;\n MobileRpcServer.interop.sendBinary = sender;\n }\n\n private _sendPending() {\n if (this._pendingMessages === undefined)\n return;\n\n for (const message of this._pendingMessages) {\n this._connection!.send(message, (err) => {\n if (err) {\n throw err;\n }\n });\n }\n this._pendingMessages.length = 0;\n }\n\n private _onConnectionMessage(data: ws.Data) {\n let message = data;\n if (Array.isArray(message)) {\n throw new IModelError(BentleyStatus.ERROR, \"Unsupported data type\");\n }\n\n if (Buffer.isBuffer(message)) {\n if (message.byteOffset !== 0 || message.byteLength !== message.buffer.byteLength) {\n message = new Uint8Array(message.buffer, message.byteOffset, message.byteLength);\n } else {\n message = message.buffer;\n }\n }\n\n MobileRpcServer.interop.handler(message, this._connectionId);\n }\n\n public dispose() {\n clearInterval(this._pingTimer);\n if (this._connection) {\n MobileRpcServer.interop.sendString = () => { };\n MobileRpcServer.interop.sendBinary = () => { };\n this._connection.close();\n }\n\n this._server.close();\n }\n}\n\nlet mobileReady = false;\nlet hasSuspended = false;\n\nexport function setupMobileRpc() {\n if (mobileReady) {\n return;\n }\n\n if (ProcessDetector.isMobileAppBackend) {\n addon = (process as any)._linkedBinding(\"iModelJsMobile\");\n addon?.registerDeviceImpl();\n }\n\n let server: MobileRpcServer | null = new MobileRpcServer();\n\n /* The UV event loop (internal to node) is retained by handles,\n such as those created for setInterval/setTimeout and client/server connections.\n In a simple app, the RPC server may be the only handle retaining the UV loop.\n Thus, we install a temporary timer on suspend to prevent the loop from exiting prematurely.\n */\n let retainUvLoop: NodeJS.Timeout | undefined;\n const pendingMessages: Array<string | Uint8Array> = [];\n\n function usePendingSender() {\n const sender = (message: string | Uint8Array, _connectionId: number) => {\n pendingMessages.push(message);\n };\n MobileRpcServer.interop.sendString = sender;\n MobileRpcServer.interop.sendBinary = sender;\n }\n\n MobileHost.onEnterBackground.addListener(() => {\n hasSuspended = true;\n\n if (server === null) {\n return;\n }\n\n retainUvLoop = setInterval(() => { }, 1000);\n server.dispose();\n usePendingSender();\n server = null;\n (global as any).__iTwinJsRpcReady = false;\n });\n\n MobileHost.onEnterForeground.addListener(() => {\n if (!hasSuspended) {\n return;\n }\n\n server = new MobileRpcServer(pendingMessages);\n clearInterval(retainUvLoop);\n retainUvLoop = undefined;\n });\n\n MobileHost.onWillTerminate.addListener(() => {\n if (typeof (retainUvLoop) !== \"undefined\") {\n clearInterval(retainUvLoop);\n retainUvLoop = undefined;\n }\n\n if (server === null) {\n return;\n }\n\n server.dispose();\n server = null;\n });\n\n MobileRpcProtocol.obtainInterop = () => MobileRpcServer.interop;\n mobileReady = true;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-mobile",
|
|
3
|
-
"version": "4.11.0-dev.
|
|
3
|
+
"version": "4.11.0-dev.4",
|
|
4
4
|
"description": "iTwin.js MobileHost and MobileApp",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"url": "http://www.bentley.com"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@itwin/core-backend": "^4.11.0-dev.
|
|
26
|
-
"@itwin/core-bentley": "^4.11.0-dev.
|
|
27
|
-
"@itwin/core-common": "^4.11.0-dev.
|
|
28
|
-
"@itwin/core-frontend": "^4.11.0-dev.
|
|
25
|
+
"@itwin/core-backend": "^4.11.0-dev.4",
|
|
26
|
+
"@itwin/core-bentley": "^4.11.0-dev.4",
|
|
27
|
+
"@itwin/core-common": "^4.11.0-dev.4",
|
|
28
|
+
"@itwin/core-frontend": "^4.11.0-dev.4"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"lodash": "^4.17.21",
|
|
@@ -49,11 +49,11 @@
|
|
|
49
49
|
"mocha": "^10.2.0",
|
|
50
50
|
"rimraf": "^3.0.2",
|
|
51
51
|
"typescript": "~5.6.2",
|
|
52
|
-
"@itwin/build-tools": "4.11.0-dev.
|
|
53
|
-
"@itwin/core-
|
|
54
|
-
"@itwin/core-
|
|
55
|
-
"@itwin/core-
|
|
56
|
-
"@itwin/core-
|
|
52
|
+
"@itwin/build-tools": "4.11.0-dev.4",
|
|
53
|
+
"@itwin/core-bentley": "4.11.0-dev.4",
|
|
54
|
+
"@itwin/core-common": "4.11.0-dev.4",
|
|
55
|
+
"@itwin/core-backend": "4.11.0-dev.4",
|
|
56
|
+
"@itwin/core-frontend": "4.11.0-dev.4"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "npm run -s build:cjs",
|