@itwin/editor-backend 3.6.0-dev.8 → 4.0.0-dev.2

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,31 @@
1
1
  # Change Log - @itwin/editor-backend
2
2
 
3
- This log was last generated on Wed, 07 Dec 2022 19:12:37 GMT and should not be manually modified.
3
+ This log was last generated on Thu, 26 Jan 2023 22:53:27 GMT and should not be manually modified.
4
+
5
+ ## 3.5.5
6
+ Thu, 26 Jan 2023 22:53:27 GMT
7
+
8
+ _Version update only_
9
+
10
+ ## 3.5.4
11
+ Wed, 18 Jan 2023 15:27:15 GMT
12
+
13
+ _Version update only_
14
+
15
+ ## 3.5.3
16
+ Fri, 13 Jan 2023 17:23:07 GMT
17
+
18
+ _Version update only_
19
+
20
+ ## 3.5.2
21
+ Wed, 11 Jan 2023 16:46:30 GMT
22
+
23
+ _Version update only_
24
+
25
+ ## 3.5.1
26
+ Thu, 15 Dec 2022 16:38:29 GMT
27
+
28
+ _Version update only_
4
29
 
5
30
  ## 3.5.0
6
31
  Wed, 07 Dec 2022 19:12:37 GMT
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MIT License
2
2
 
3
- Copyright © 2017-2022 Bentley Systems, Incorporated. All rights reserved.
3
+ Copyright © 2017-2023 Bentley Systems, Incorporated. All rights reserved.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
6
 
@@ -3,13 +3,13 @@
3
3
  */
4
4
  import { IModelDb } from "@itwin/core-backend";
5
5
  import { EditCommandIpc } from "@itwin/editor-common";
6
- /** @alpha */
6
+ /** @beta */
7
7
  export declare type EditCommandType = typeof EditCommand;
8
8
  /**
9
9
  * An EditCommand performs an editing action on the backend. EditCommands are usually paired with and driven by EditTools on the frontend.
10
10
  * EditCommands have a *commandId* that uniquely identifies them, so they can be found via a lookup in the [[EditCommandAdmin]].
11
11
  * Every time an EditCommand runs, a new instance of (a subclass of) this class is created.
12
- * @alpha
12
+ * @beta
13
13
  */
14
14
  export declare class EditCommand implements EditCommandIpc {
15
15
  /** The unique string that identifies this EditCommand class. This must be overridden in every subclass. */
@@ -25,20 +25,33 @@ export declare class EditCommand implements EditCommandIpc {
25
25
  version: string;
26
26
  [propName: string]: any;
27
27
  }>;
28
- onCleanup(): void;
29
- onFinish(): void;
28
+ private onFinish;
29
+ /**
30
+ * Called when another EditCommand wishes to become the active EditCommand.
31
+ * Subclasses should complete and save their work as soon as possible and then return "done".
32
+ * If it is not currently possible to finish, return any string other than "done" and the other EditCommand will have to wait and retry,
33
+ * potentially showing the returned string to the user.
34
+ */
35
+ requestFinish(): Promise<"done" | string>;
30
36
  }
31
- /** EditCommandAdmin holds a mapping between commandIds and their corresponding [[EditCommand]] class. This provides the mechanism to
37
+ /**
38
+ * EditCommandAdmin holds a mapping between commandIds and their corresponding [[EditCommand]] class. This provides the mechanism to
32
39
  * run EditCommands by commandId.
33
- * It also keeps track of the currently active EditCommand. When a new EditCommand starts, the active EditCommand is terminated.
34
- * @alpha
40
+ * It also keeps track of the currently active EditCommand. When a new EditCommand attempts to start, the active EditCommand
41
+ * is requested to finish, and the new EditCommand cannot start until it does.
42
+ * @beta
35
43
  */
36
44
  export declare class EditCommandAdmin {
37
45
  static readonly commands: Map<string, typeof EditCommand>;
38
46
  private static _activeCommand?;
39
47
  private static _isInitialized;
40
48
  static get activeCommand(): EditCommand | undefined;
41
- static runCommand(cmd?: EditCommand): Promise<any> | undefined;
49
+ /** @internal */
50
+ static finishCommand(): Promise<void>;
51
+ /** Called from frontend via `EditorIpc.startCommand`
52
+ * @internal
53
+ */
54
+ static runCommand(cmd: EditCommand): Promise<any>;
42
55
  /**
43
56
  * Un-register a previously registered EditCommand class.
44
57
  * @param commandId the commandId of a previously registered EditCommand to unRegister.
@@ -1 +1 @@
1
- {"version":3,"file":"EditCommand.d.ts","sourceRoot":"","sources":["../../src/EditCommand.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,QAAQ,EAAuB,MAAM,qBAAqB,CAAC;AAEpE,OAAO,EAAE,cAAc,EAA4B,MAAM,sBAAsB,CAAC;AAEhF,aAAa;AACb,oBAAY,eAAe,GAAG,OAAO,WAAW,CAAC;AAEjD;;;;;GAKG;AACH,qBAAa,WAAY,YAAW,cAAc;IAChD,2GAA2G;IAC3G,OAAc,SAAS,SAAM;IAC7B,OAAc,OAAO,SAAW;IAEhC,8CAA8C;IAC9C,SAAgB,MAAM,EAAE,QAAQ,CAAC;gBAEd,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,GAAG,EAAE;IAGpD,IAAW,IAAI,IAAI,eAAe,CAAgD;IAErE,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC;IAEvB,IAAI,IAAI,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;IAItF,SAAS,IAAI,IAAI;IAEjB,QAAQ,IAAI,IAAI;CACxB;AA0BD;;;;GAIG;AACH,qBAAa,gBAAgB;IAC3B,gBAAuB,QAAQ,kCAAsC;IAErE,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAc;IAC5C,OAAO,CAAC,MAAM,CAAC,cAAc,CAAS;IACtC,WAAkB,aAAa,4BAAkC;WAEnD,UAAU,CAAC,GAAG,CAAC,EAAE,WAAW;IAO1C;;;OAGG;WACW,UAAU,CAAC,SAAS,EAAE,MAAM;IAI1C;;;OAGG;WACW,QAAQ,CAAC,WAAW,EAAE,eAAe;IAWnD;;;OAGG;WACW,cAAc,CAAC,SAAS,EAAE,GAAG;CAY5C"}
1
+ {"version":3,"file":"EditCommand.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,EAAE,GAAG;CAY5C"}
@@ -16,27 +16,42 @@ const editor_common_1 = require("@itwin/editor-common");
16
16
  * An EditCommand performs an editing action on the backend. EditCommands are usually paired with and driven by EditTools on the frontend.
17
17
  * EditCommands have a *commandId* that uniquely identifies them, so they can be found via a lookup in the [[EditCommandAdmin]].
18
18
  * Every time an EditCommand runs, a new instance of (a subclass of) this class is created.
19
- * @alpha
19
+ * @beta
20
20
  */
21
21
  class EditCommand {
22
22
  constructor(iModel, ..._args) {
23
23
  this.iModel = iModel;
24
24
  }
25
- get ctor() { return this.constructor; }
25
+ get ctor() {
26
+ return this.constructor;
27
+ }
26
28
  async onStart() { }
27
29
  async ping() {
28
30
  return { version: this.ctor.version, commandId: this.ctor.commandId };
29
31
  }
30
- onCleanup() { }
32
+ // This is only temporary to find subclasses that used to implement this method. It was made async and renamed `requestFinish`.
31
33
  onFinish() { }
34
+ /**
35
+ * Called when another EditCommand wishes to become the active EditCommand.
36
+ * Subclasses should complete and save their work as soon as possible and then return "done".
37
+ * If it is not currently possible to finish, return any string other than "done" and the other EditCommand will have to wait and retry,
38
+ * potentially showing the returned string to the user.
39
+ */
40
+ async requestFinish() {
41
+ this.onFinish(); // TODO: temporary, remove
42
+ return "done";
43
+ }
32
44
  }
33
45
  exports.EditCommand = EditCommand;
34
46
  /** The unique string that identifies this EditCommand class. This must be overridden in every subclass. */
35
47
  EditCommand.commandId = "";
36
48
  EditCommand.version = "1.0.0";
37
49
  class EditorAppHandler extends core_backend_1.IpcHandler {
38
- get channelName() { return editor_common_1.editorChannel; }
50
+ get channelName() { return editor_common_1.editorIpcStrings.channel; }
39
51
  async startCommand(commandId, iModelKey, ...args) {
52
+ await EditCommandAdmin.finishCommand();
53
+ if (commandId === "") // just kill active command, don't start another
54
+ return;
40
55
  const commandClass = EditCommandAdmin.commands.get(commandId);
41
56
  if (undefined === commandClass)
42
57
  throw new core_common_1.IModelError(core_bentley_1.IModelStatus.NotRegistered, `Command not registered [${commandId}]`);
@@ -52,18 +67,31 @@ class EditorAppHandler extends core_backend_1.IpcHandler {
52
67
  return func.call(cmd, ...args);
53
68
  }
54
69
  }
55
- /** EditCommandAdmin holds a mapping between commandIds and their corresponding [[EditCommand]] class. This provides the mechanism to
70
+ /**
71
+ * EditCommandAdmin holds a mapping between commandIds and their corresponding [[EditCommand]] class. This provides the mechanism to
56
72
  * run EditCommands by commandId.
57
- * It also keeps track of the currently active EditCommand. When a new EditCommand starts, the active EditCommand is terminated.
58
- * @alpha
73
+ * It also keeps track of the currently active EditCommand. When a new EditCommand attempts to start, the active EditCommand
74
+ * is requested to finish, and the new EditCommand cannot start until it does.
75
+ * @beta
59
76
  */
60
77
  class EditCommandAdmin {
61
78
  static get activeCommand() { return this._activeCommand; }
62
- static runCommand(cmd) {
63
- if (this._activeCommand)
64
- this._activeCommand.onFinish();
79
+ /** @internal */
80
+ static async finishCommand() {
81
+ if (this._activeCommand) {
82
+ const finished = await this._activeCommand.requestFinish();
83
+ if ("done" !== finished)
84
+ throw new core_common_1.BackendError(core_bentley_1.IModelStatus.ServerTimeout, editor_common_1.editorIpcStrings.commandBusy, finished);
85
+ }
86
+ this._activeCommand = undefined;
87
+ }
88
+ /** Called from frontend via `EditorIpc.startCommand`
89
+ * @internal
90
+ */
91
+ static async runCommand(cmd) {
92
+ await this.finishCommand();
65
93
  this._activeCommand = cmd;
66
- return cmd ? cmd.onStart() : undefined;
94
+ return cmd.onStart();
67
95
  }
68
96
  /**
69
97
  * Un-register a previously registered EditCommand class.
@@ -1 +1 @@
1
- {"version":3,"file":"EditCommand.js","sourceRoot":"","sources":["../../src/EditCommand.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAmD;AACnD,sDAAoE;AACpE,oDAAiD;AACjD,wDAAgF;AAKhF;;;;;GAKG;AACH,MAAa,WAAW;IAQtB,YAAmB,MAAgB,EAAE,GAAG,KAAY;QAClD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;I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,SAAS,EAAE,EAAG,mCAAmC;YACxE,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;YACtC,IAAI,OAAO,CAAC,SAAS,YAAY,WAAW,EAAE;gBAC5C,QAAQ,GAAG,IAAI,CAAC;gBAChB,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;aACxB;SACF;QACD,IAAI,CAAC,QAAQ;YACX,MAAM,IAAI,KAAK,CAAC,4FAA4F,CAAC,CAAC;IAClH,CAAC;;AApDH,4CAqDC;AApDwB,yBAAQ,GAAG,IAAI,GAAG,EAA2B,CAAC;AAGtD,+BAAc,GAAG,KAAK,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Editing\r\n */\r\n\r\nimport { IModelStatus } from \"@itwin/core-bentley\";\r\nimport { IModelDb, IpcHandler, IpcHost } from \"@itwin/core-backend\";\r\nimport { IModelError } from \"@itwin/core-common\";\r\nimport { EditCommandIpc, editorChannel, EditorIpc } from \"@itwin/editor-common\";\r\n\r\n/** @alpha */\r\nexport type EditCommandType = typeof EditCommand;\r\n\r\n/**\r\n * An EditCommand performs an editing action on the backend. EditCommands are usually paired with and driven by EditTools on the frontend.\r\n * EditCommands have a *commandId* that uniquely identifies them, so they can be found via a lookup in the [[EditCommandAdmin]].\r\n * Every time an EditCommand runs, a new instance of (a subclass of) this class is created.\r\n * @alpha\r\n */\r\nexport class EditCommand implements EditCommandIpc {\r\n /** The unique string that identifies this EditCommand class. This must be overridden in every subclass. */\r\n public static commandId = \"\";\r\n public static version = \"1.0.0\";\r\n\r\n /** The iModel this EditCommand may modify. */\r\n public readonly iModel: IModelDb;\r\n\r\n public constructor(iModel: IModelDb, ..._args: any[]) {\r\n this.iModel = iModel;\r\n }\r\n public get ctor(): EditCommandType { return this.constructor as EditCommandType; }\r\n\r\n public async onStart(): Promise<any> { }\r\n\r\n public async ping(): Promise<{ commandId: string, version: string, [propName: string]: any }> {\r\n return { version: this.ctor.version, commandId: this.ctor.commandId };\r\n }\r\n\r\n public onCleanup(): void { }\r\n\r\n public onFinish(): void { }\r\n}\r\n\r\nclass EditorAppHandler extends IpcHandler implements EditorIpc {\r\n public get channelName() { return editorChannel; }\r\n\r\n public async startCommand(commandId: string, iModelKey: string, ...args: any[]) {\r\n const commandClass = EditCommandAdmin.commands.get(commandId);\r\n if (undefined === commandClass)\r\n throw new IModelError(IModelStatus.NotRegistered, `Command not registered [${commandId}]`);\r\n\r\n return EditCommandAdmin.runCommand(new commandClass(IModelDb.findByKey(iModelKey), ...args));\r\n }\r\n\r\n public async callMethod(methodName: string, ...args: any[]) {\r\n const cmd = EditCommandAdmin.activeCommand;\r\n if (!cmd)\r\n throw new IModelError(IModelStatus.NoActiveCommand, `No active command`);\r\n\r\n const func = (cmd as any)[methodName];\r\n if (typeof func !== \"function\")\r\n throw new IModelError(IModelStatus.FunctionNotFound, `Method ${methodName} not found on ${cmd.ctor.commandId}`);\r\n\r\n return func.call(cmd, ...args);\r\n }\r\n}\r\n\r\n/** EditCommandAdmin holds a mapping between commandIds and their corresponding [[EditCommand]] class. This provides the mechanism to\r\n * run EditCommands by commandId.\r\n * It also keeps track of the currently active EditCommand. When a new EditCommand starts, the active EditCommand is terminated.\r\n * @alpha\r\n */\r\nexport class EditCommandAdmin {\r\n public static readonly commands = new Map<string, EditCommandType>();\r\n\r\n private static _activeCommand?: EditCommand;\r\n private static _isInitialized = false;\r\n public static get activeCommand() { return this._activeCommand; }\r\n\r\n public static runCommand(cmd?: EditCommand) {\r\n if (this._activeCommand)\r\n this._activeCommand.onFinish();\r\n this._activeCommand = cmd;\r\n return cmd ? cmd.onStart() : undefined;\r\n }\r\n\r\n /**\r\n * Un-register a previously registered EditCommand class.\r\n * @param commandId the commandId of a previously registered EditCommand to unRegister.\r\n */\r\n public static unRegister(commandId: string) {\r\n this.commands.delete(commandId);\r\n }\r\n\r\n /**\r\n * Register an EditCommand class. This establishes a connection between the commandId of the class and the class itself.\r\n * @param commandType the subclass of Tool to register.\r\n */\r\n public static register(commandType: EditCommandType) {\r\n if (!this._isInitialized) {\r\n this._isInitialized = true;\r\n if (!IpcHost.isValid)\r\n throw new Error(\"Edit Commands require IpcHost\");\r\n EditorAppHandler.register();\r\n }\r\n if (commandType.commandId.length !== 0)\r\n this.commands.set(commandType.commandId, commandType);\r\n }\r\n\r\n /**\r\n * Register all the EditCommand classes found in a module.\r\n * @param modelObj the module to search for subclasses of EditCommand.\r\n */\r\n public static registerModule(moduleObj: any) {\r\n let foundOne = false;\r\n for (const thisMember in moduleObj) { // eslint-disable-line guard-for-in\r\n const thisCmd = moduleObj[thisMember];\r\n if (thisCmd.prototype instanceof EditCommand) {\r\n foundOne = true;\r\n this.register(thisCmd);\r\n }\r\n }\r\n if (!foundOne)\r\n throw new Error(`no EditCommands found - are you sure this is a module? Maybe you meant to call \"register\"?`);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"EditCommand.js","sourceRoot":"","sources":["../../src/EditCommand.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAmD;AACnD,sDAAoE;AACpE,oDAA+D;AAC/D,wDAAmF;AAKnF;;;;;GAKG;AACH,MAAa,WAAW;IAQtB,YAAmB,MAAgB,EAAE,GAAG,KAAY;QAClD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IACD,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,WAA8B,CAAC;IAC7C,CAAC;IAEM,KAAK,CAAC,OAAO,KAAmB,CAAC;IAEjC,KAAK,CAAC,IAAI;QACf,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;IACxE,CAAC;IAED,+HAA+H;IACvH,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,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC;YACpC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IAC1D,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,cAAc,CAAC,SAAc;QACzC,IAAI,QAAQ,GAAG,KAAK,CAAC;QACrB,KAAK,MAAM,UAAU,IAAI,SAAS,EAAE,EAAG,mCAAmC;YACxE,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;YACtC,IAAI,OAAO,CAAC,SAAS,YAAY,WAAW,EAAE;gBAC5C,QAAQ,GAAG,IAAI,CAAC;gBAChB,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;aACxB;SACF;QACD,IAAI,CAAC,QAAQ;YACX,MAAM,IAAI,KAAK,CAAC,4FAA4F,CAAC,CAAC;IAClH,CAAC;;AAhEH,4CAiEC;AAhEwB,yBAAQ,GAAG,IAAI,GAAG,EAA2B,CAAC;AAGtD,+BAAc,GAAG,KAAK,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Editing\r\n */\r\n\r\nimport { IModelStatus } from \"@itwin/core-bentley\";\r\nimport { IModelDb, IpcHandler, IpcHost } from \"@itwin/core-backend\";\r\nimport { BackendError, IModelError } from \"@itwin/core-common\";\r\nimport { EditCommandIpc, EditorIpc, editorIpcStrings } from \"@itwin/editor-common\";\r\n\r\n/** @beta */\r\nexport type EditCommandType = typeof EditCommand;\r\n\r\n/**\r\n * An EditCommand performs an editing action on the backend. EditCommands are usually paired with and driven by EditTools on the frontend.\r\n * EditCommands have a *commandId* that uniquely identifies them, so they can be found via a lookup in the [[EditCommandAdmin]].\r\n * Every time an EditCommand runs, a new instance of (a subclass of) this class is created.\r\n * @beta\r\n */\r\nexport class EditCommand implements EditCommandIpc {\r\n /** The unique string that identifies this EditCommand class. This must be overridden in every subclass. */\r\n public static commandId = \"\";\r\n public static version = \"1.0.0\";\r\n\r\n /** The iModel this EditCommand may modify. */\r\n public readonly iModel: IModelDb;\r\n\r\n public constructor(iModel: IModelDb, ..._args: any[]) {\r\n this.iModel = iModel;\r\n }\r\n public get ctor(): EditCommandType {\r\n return this.constructor as EditCommandType;\r\n }\r\n\r\n public async onStart(): Promise<any> { }\r\n\r\n public async ping(): Promise<{ commandId: string, version: string, [propName: string]: any }> {\r\n return { version: this.ctor.version, commandId: this.ctor.commandId };\r\n }\r\n\r\n // This is only temporary to find subclasses that used to implement this method. It was made async and renamed `requestFinish`.\r\n private onFinish() { }\r\n\r\n /**\r\n * Called when another EditCommand wishes to become the active EditCommand.\r\n * Subclasses should complete and save their work as soon as possible and then return \"done\".\r\n * If it is not currently possible to finish, return any string other than \"done\" and the other EditCommand will have to wait and retry,\r\n * potentially showing the returned string to the user.\r\n */\r\n public async requestFinish(): Promise<\"done\" | string> {\r\n this.onFinish(); // TODO: temporary, remove\r\n return \"done\";\r\n }\r\n}\r\n\r\nclass EditorAppHandler extends IpcHandler implements EditorIpc {\r\n public get channelName() { return editorIpcStrings.channel; }\r\n\r\n public async startCommand(commandId: string, iModelKey: string, ...args: any[]) {\r\n await EditCommandAdmin.finishCommand();\r\n if (commandId === \"\") // just kill active command, don't start another\r\n return;\r\n\r\n const commandClass = EditCommandAdmin.commands.get(commandId);\r\n if (undefined === commandClass)\r\n throw new IModelError(IModelStatus.NotRegistered, `Command not registered [${commandId}]`);\r\n\r\n return EditCommandAdmin.runCommand(new commandClass(IModelDb.findByKey(iModelKey), ...args));\r\n }\r\n\r\n public async callMethod(methodName: string, ...args: any[]) {\r\n const cmd = EditCommandAdmin.activeCommand;\r\n if (!cmd)\r\n throw new IModelError(IModelStatus.NoActiveCommand, `No active command`);\r\n\r\n const func = (cmd as any)[methodName];\r\n if (typeof func !== \"function\")\r\n throw new IModelError(IModelStatus.FunctionNotFound, `Method ${methodName} not found on ${cmd.ctor.commandId}`);\r\n\r\n return func.call(cmd, ...args);\r\n }\r\n}\r\n\r\n/**\r\n * EditCommandAdmin holds a mapping between commandIds and their corresponding [[EditCommand]] class. This provides the mechanism to\r\n * run EditCommands by commandId.\r\n * It also keeps track of the currently active EditCommand. When a new EditCommand attempts to start, the active EditCommand\r\n * is requested to finish, and the new EditCommand cannot start until it does.\r\n * @beta\r\n */\r\nexport class EditCommandAdmin {\r\n public static readonly commands = new Map<string, EditCommandType>();\r\n\r\n private static _activeCommand?: EditCommand;\r\n private static _isInitialized = false;\r\n public static get activeCommand() { return this._activeCommand; }\r\n\r\n /** @internal */\r\n public static async finishCommand() {\r\n if (this._activeCommand) {\r\n const finished = await this._activeCommand.requestFinish();\r\n if (\"done\" !== finished)\r\n throw new BackendError(IModelStatus.ServerTimeout, editorIpcStrings.commandBusy, finished);\r\n }\r\n this._activeCommand = undefined;\r\n }\r\n\r\n /** Called from frontend via `EditorIpc.startCommand`\r\n * @internal\r\n */\r\n public static async runCommand(cmd: EditCommand): Promise<any> {\r\n await this.finishCommand();\r\n this._activeCommand = cmd;\r\n return cmd.onStart();\r\n }\r\n\r\n /**\r\n * Un-register a previously registered EditCommand class.\r\n * @param commandId the commandId of a previously registered EditCommand to unRegister.\r\n */\r\n public static unRegister(commandId: string) {\r\n this.commands.delete(commandId);\r\n }\r\n\r\n /**\r\n * Register an EditCommand class. This establishes a connection between the commandId of the class and the class itself.\r\n * @param commandType the subclass of Tool to register.\r\n */\r\n public static register(commandType: EditCommandType) {\r\n if (!this._isInitialized) {\r\n this._isInitialized = true;\r\n if (!IpcHost.isValid)\r\n throw new Error(\"Edit Commands require IpcHost\");\r\n EditorAppHandler.register();\r\n }\r\n if (commandType.commandId.length !== 0)\r\n this.commands.set(commandType.commandId, commandType);\r\n }\r\n\r\n /**\r\n * Register all the EditCommand classes found in a module.\r\n * @param modelObj the module to search for subclasses of EditCommand.\r\n */\r\n public static registerModule(moduleObj: any) {\r\n let foundOne = false;\r\n for (const thisMember in moduleObj) { // eslint-disable-line guard-for-in\r\n const thisCmd = moduleObj[thisMember];\r\n if (thisCmd.prototype instanceof EditCommand) {\r\n foundOne = true;\r\n this.register(thisCmd);\r\n }\r\n }\r\n if (!foundOne)\r\n throw new Error(`no EditCommands found - are you sure this is a module? Maybe you meant to call \"register\"?`);\r\n }\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/editor-backend",
3
- "version": "3.6.0-dev.8",
3
+ "version": "4.0.0-dev.2",
4
4
  "description": "iTwin.js editor backend",
5
5
  "main": "lib/cjs/editor-backend.js",
6
6
  "typings": "lib/cjs/editor-backend",
@@ -24,28 +24,28 @@
24
24
  "url": "http://www.bentley.com"
25
25
  },
26
26
  "peerDependencies": {
27
- "@itwin/core-backend": "^3.6.0-dev.8",
28
- "@itwin/core-bentley": "^3.6.0-dev.8",
29
- "@itwin/core-common": "^3.6.0-dev.8",
30
- "@itwin/core-geometry": "^3.6.0-dev.8"
27
+ "@itwin/core-backend": "^4.0.0-dev.2",
28
+ "@itwin/core-bentley": "^4.0.0-dev.2",
29
+ "@itwin/core-common": "^4.0.0-dev.2",
30
+ "@itwin/core-geometry": "^4.0.0-dev.2"
31
31
  },
32
32
  "//devDependencies": [
33
33
  "NOTE: All peerDependencies should also be listed as devDependencies since peerDependencies are not considered by npm install",
34
34
  "NOTE: All tools used by scripts in this package must be listed as devDependencies"
35
35
  ],
36
36
  "devDependencies": {
37
- "@itwin/build-tools": "3.6.0-dev.8",
38
- "@itwin/core-backend": "3.6.0-dev.8",
39
- "@itwin/core-bentley": "3.6.0-dev.8",
40
- "@itwin/core-common": "3.6.0-dev.8",
41
- "@itwin/core-geometry": "3.6.0-dev.8",
42
- "@itwin/eslint-plugin": "3.6.0-dev.8",
37
+ "@itwin/build-tools": "4.0.0-dev.2",
38
+ "@itwin/core-backend": "4.0.0-dev.2",
39
+ "@itwin/core-bentley": "4.0.0-dev.2",
40
+ "@itwin/core-common": "4.0.0-dev.2",
41
+ "@itwin/core-geometry": "4.0.0-dev.2",
42
+ "@itwin/eslint-plugin": "4.0.0-dev.2",
43
43
  "eslint": "^7.11.0",
44
44
  "rimraf": "^3.0.2",
45
45
  "typescript": "~4.4.0"
46
46
  },
47
47
  "dependencies": {
48
- "@itwin/editor-common": "3.6.0-dev.8"
48
+ "@itwin/editor-common": "4.0.0-dev.2"
49
49
  },
50
50
  "eslintConfig": {
51
51
  "plugins": [