@itwin/editor-backend 4.0.0-dev.8 → 4.0.0-dev.80

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.
@@ -1,137 +1,137 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
6
- /** @packageDocumentation
7
- * @module Editing
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.EditCommandAdmin = exports.EditCommand = void 0;
11
- const core_bentley_1 = require("@itwin/core-bentley");
12
- const core_backend_1 = require("@itwin/core-backend");
13
- const core_common_1 = require("@itwin/core-common");
14
- const editor_common_1 = require("@itwin/editor-common");
15
- /**
16
- * An EditCommand performs an editing action on the backend. EditCommands are usually paired with and driven by EditTools on the frontend.
17
- * EditCommands have a *commandId* that uniquely identifies them, so they can be found via a lookup in the [[EditCommandAdmin]].
18
- * Every time an EditCommand runs, a new instance of (a subclass of) this class is created.
19
- * @beta
20
- */
21
- class EditCommand {
22
- constructor(iModel, ..._args) {
23
- this.iModel = iModel;
24
- }
25
- get ctor() {
26
- return this.constructor;
27
- }
28
- async onStart() { }
29
- async ping() {
30
- return { version: this.ctor.version, commandId: this.ctor.commandId };
31
- }
32
- // This is only temporary to find subclasses that used to implement this method. It was made async and renamed `requestFinish`.
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
- }
44
- }
45
- exports.EditCommand = EditCommand;
46
- /** The unique string that identifies this EditCommand class. This must be overridden in every subclass. */
47
- EditCommand.commandId = "";
48
- EditCommand.version = "1.0.0";
49
- class EditorAppHandler extends core_backend_1.IpcHandler {
50
- get channelName() { return editor_common_1.editorIpcStrings.channel; }
51
- async startCommand(commandId, iModelKey, ...args) {
52
- await EditCommandAdmin.finishCommand();
53
- if (commandId === "") // just kill active command, don't start another
54
- return;
55
- const commandClass = EditCommandAdmin.commands.get(commandId);
56
- if (undefined === commandClass)
57
- throw new core_common_1.IModelError(core_bentley_1.IModelStatus.NotRegistered, `Command not registered [${commandId}]`);
58
- return EditCommandAdmin.runCommand(new commandClass(core_backend_1.IModelDb.findByKey(iModelKey), ...args));
59
- }
60
- async callMethod(methodName, ...args) {
61
- const cmd = EditCommandAdmin.activeCommand;
62
- if (!cmd)
63
- throw new core_common_1.IModelError(core_bentley_1.IModelStatus.NoActiveCommand, `No active command`);
64
- const func = cmd[methodName];
65
- if (typeof func !== "function")
66
- throw new core_common_1.IModelError(core_bentley_1.IModelStatus.FunctionNotFound, `Method ${methodName} not found on ${cmd.ctor.commandId}`);
67
- return func.call(cmd, ...args);
68
- }
69
- }
70
- /**
71
- * EditCommandAdmin holds a mapping between commandIds and their corresponding [[EditCommand]] class. This provides the mechanism to
72
- * run EditCommands by commandId.
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
76
- */
77
- class EditCommandAdmin {
78
- static get activeCommand() { return this._activeCommand; }
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();
93
- this._activeCommand = cmd;
94
- return cmd.onStart();
95
- }
96
- /**
97
- * Un-register a previously registered EditCommand class.
98
- * @param commandId the commandId of a previously registered EditCommand to unRegister.
99
- */
100
- static unRegister(commandId) {
101
- this.commands.delete(commandId);
102
- }
103
- /**
104
- * Register an EditCommand class. This establishes a connection between the commandId of the class and the class itself.
105
- * @param commandType the subclass of Tool to register.
106
- */
107
- static register(commandType) {
108
- if (!this._isInitialized) {
109
- this._isInitialized = true;
110
- if (!core_backend_1.IpcHost.isValid)
111
- throw new Error("Edit Commands require IpcHost");
112
- EditorAppHandler.register();
113
- }
114
- if (commandType.commandId.length !== 0)
115
- this.commands.set(commandType.commandId, commandType);
116
- }
117
- /**
118
- * Register all the EditCommand classes found in a module.
119
- * @param modelObj the module to search for subclasses of EditCommand.
120
- */
121
- static registerModule(moduleObj) {
122
- let foundOne = false;
123
- for (const thisMember in moduleObj) { // eslint-disable-line guard-for-in
124
- const thisCmd = moduleObj[thisMember];
125
- if (thisCmd.prototype instanceof EditCommand) {
126
- foundOne = true;
127
- this.register(thisCmd);
128
- }
129
- }
130
- if (!foundOne)
131
- throw new Error(`no EditCommands found - are you sure this is a module? Maybe you meant to call "register"?`);
132
- }
133
- }
134
- exports.EditCommandAdmin = EditCommandAdmin;
135
- EditCommandAdmin.commands = new Map();
136
- EditCommandAdmin._isInitialized = false;
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ /** @packageDocumentation
7
+ * @module Editing
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.EditCommandAdmin = exports.EditCommand = void 0;
11
+ const core_bentley_1 = require("@itwin/core-bentley");
12
+ const core_backend_1 = require("@itwin/core-backend");
13
+ const core_common_1 = require("@itwin/core-common");
14
+ const editor_common_1 = require("@itwin/editor-common");
15
+ /**
16
+ * An EditCommand performs an editing action on the backend. EditCommands are usually paired with and driven by EditTools on the frontend.
17
+ * EditCommands have a *commandId* that uniquely identifies them, so they can be found via a lookup in the [[EditCommandAdmin]].
18
+ * Every time an EditCommand runs, a new instance of (a subclass of) this class is created.
19
+ * @beta
20
+ */
21
+ class EditCommand {
22
+ constructor(iModel, ..._args) {
23
+ this.iModel = iModel;
24
+ }
25
+ get ctor() {
26
+ return this.constructor;
27
+ }
28
+ async onStart() { }
29
+ async ping() {
30
+ return { version: this.ctor.version, commandId: this.ctor.commandId };
31
+ }
32
+ // This is only temporary to find subclasses that used to implement this method. It was made async and renamed `requestFinish`.
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
+ }
44
+ }
45
+ /** The unique string that identifies this EditCommand class. This must be overridden in every subclass. */
46
+ EditCommand.commandId = "";
47
+ EditCommand.version = "1.0.0";
48
+ exports.EditCommand = EditCommand;
49
+ class EditorAppHandler extends core_backend_1.IpcHandler {
50
+ get channelName() { return editor_common_1.editorIpcStrings.channel; }
51
+ async startCommand(commandId, iModelKey, ...args) {
52
+ await EditCommandAdmin.finishCommand();
53
+ if (commandId === "") // just kill active command, don't start another
54
+ return;
55
+ const commandClass = EditCommandAdmin.commands.get(commandId);
56
+ if (undefined === commandClass)
57
+ throw new core_common_1.IModelError(core_bentley_1.IModelStatus.NotRegistered, `Command not registered [${commandId}]`);
58
+ return EditCommandAdmin.runCommand(new commandClass(core_backend_1.IModelDb.findByKey(iModelKey), ...args));
59
+ }
60
+ async callMethod(methodName, ...args) {
61
+ const cmd = EditCommandAdmin.activeCommand;
62
+ if (!cmd)
63
+ throw new core_common_1.IModelError(core_bentley_1.IModelStatus.NoActiveCommand, `No active command`);
64
+ const func = cmd[methodName];
65
+ if (typeof func !== "function")
66
+ throw new core_common_1.IModelError(core_bentley_1.IModelStatus.FunctionNotFound, `Method ${methodName} not found on ${cmd.ctor.commandId}`);
67
+ return func.call(cmd, ...args);
68
+ }
69
+ }
70
+ /**
71
+ * EditCommandAdmin holds a mapping between commandIds and their corresponding [[EditCommand]] class. This provides the mechanism to
72
+ * run EditCommands by commandId.
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
76
+ */
77
+ class EditCommandAdmin {
78
+ static get activeCommand() { return this._activeCommand; }
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();
93
+ this._activeCommand = cmd;
94
+ return cmd.onStart();
95
+ }
96
+ /**
97
+ * Un-register a previously registered EditCommand class.
98
+ * @param commandId the commandId of a previously registered EditCommand to unRegister.
99
+ */
100
+ static unRegister(commandId) {
101
+ this.commands.delete(commandId);
102
+ }
103
+ /**
104
+ * Register an EditCommand class. This establishes a connection between the commandId of the class and the class itself.
105
+ * @param commandType the subclass of Tool to register.
106
+ */
107
+ static register(commandType) {
108
+ if (!this._isInitialized) {
109
+ this._isInitialized = true;
110
+ if (!core_backend_1.IpcHost.isValid)
111
+ throw new Error("Edit Commands require IpcHost");
112
+ EditorAppHandler.register();
113
+ }
114
+ if (commandType.commandId.length !== 0)
115
+ this.commands.set(commandType.commandId, commandType);
116
+ }
117
+ /**
118
+ * Register all the EditCommand classes found in a module.
119
+ * @param modelObj the module to search for subclasses of EditCommand.
120
+ */
121
+ static registerModule(moduleObj) {
122
+ let foundOne = false;
123
+ for (const thisMember in moduleObj) { // eslint-disable-line guard-for-in
124
+ const thisCmd = moduleObj[thisMember];
125
+ if (thisCmd.prototype instanceof EditCommand) {
126
+ foundOne = true;
127
+ this.register(thisCmd);
128
+ }
129
+ }
130
+ if (!foundOne)
131
+ throw new Error(`no EditCommands found - are you sure this is a module? Maybe you meant to call "register"?`);
132
+ }
133
+ }
134
+ EditCommandAdmin.commands = new Map();
135
+ EditCommandAdmin._isInitialized = false;
136
+ exports.EditCommandAdmin = EditCommandAdmin;
137
137
  //# sourceMappingURL=EditCommand.js.map
@@ -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,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,QAAQ,KAAK,CAAC;IAEtB;;;;;OAKG;IACI,KAAK,CAAC,aAAa;QACxB,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,0BAA0B;QAC3C,OAAO,MAAM,CAAC;IAChB,CAAC;;AAjCH,kCAkCC;AAjCC,2GAA2G;AAC7F,qBAAS,GAAG,EAAE,CAAC;AACf,mBAAO,GAAG,OAAO,CAAC;AAiClC,MAAM,gBAAiB,SAAQ,yBAAU;IACvC,IAAW,WAAW,KAAK,OAAO,gCAAgB,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,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"]}
1
+ {"version":3,"file":"EditCommand.js","sourceRoot":"","sources":["../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C,aAAa,EAAE,CAAC;QAC3B,IAAI,CAAC,cAAc,GAAG,GAAG,CAAC;QAC1B,OAAO,GAAG,CAAC,OAAO,EAAE,CAAC;IACvB,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,UAAU,CAAC,SAAiB;QACxC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAClC,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,QAAQ,CAAC,WAA4B;QACjD,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE;YACxB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;YAC3B,IAAI,CAAC,sBAAO,CAAC,OAAO;gBAClB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;YACnD,gBAAgB,CAAC,QAAQ,EAAE,CAAC;SAC7B;QACD,IAAI,WAAW,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;;AA/DsB,yBAAQ,GAAG,IAAI,GAAG,EAA2B,CAAC;AAGtD,+BAAc,GAAG,KAAK,CAAC;AAJ3B,4CAAgB","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"]}
@@ -1,3 +1,3 @@
1
- export * from "./EditCommand";
2
- export * from "./EditBuiltInCommand";
1
+ export * from "./EditCommand";
2
+ export * from "./EditBuiltInCommand";
3
3
  //# sourceMappingURL=editor-backend.d.ts.map
@@ -1,19 +1,23 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- /*---------------------------------------------------------------------------------------------
14
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
15
- * See LICENSE.md in the project root for license terms and full copyright notice.
16
- *--------------------------------------------------------------------------------------------*/
17
- __exportStar(require("./EditCommand"), exports);
18
- __exportStar(require("./EditBuiltInCommand"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /*---------------------------------------------------------------------------------------------
18
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
19
+ * See LICENSE.md in the project root for license terms and full copyright notice.
20
+ *--------------------------------------------------------------------------------------------*/
21
+ __exportStar(require("./EditCommand"), exports);
22
+ __exportStar(require("./EditBuiltInCommand"), exports);
19
23
  //# sourceMappingURL=editor-backend.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"editor-backend.js","sourceRoot":"","sources":["../../src/editor-backend.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,gDAA8B;AAC9B,uDAAqC","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\nexport * from \"./EditCommand\";\r\nexport * from \"./EditBuiltInCommand\";\r\n\r\n"]}
1
+ {"version":3,"file":"editor-backend.js","sourceRoot":"","sources":["../../src/editor-backend.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,gDAA8B;AAC9B,uDAAqC","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\nexport * from \"./EditCommand\";\r\nexport * from \"./EditBuiltInCommand\";\r\n\r\n"]}
package/package.json CHANGED
@@ -1,16 +1,17 @@
1
1
  {
2
2
  "name": "@itwin/editor-backend",
3
- "version": "4.0.0-dev.8",
3
+ "version": "4.0.0-dev.80",
4
4
  "description": "iTwin.js editor backend",
5
5
  "main": "lib/cjs/editor-backend.js",
6
6
  "typings": "lib/cjs/editor-backend",
7
7
  "license": "MIT",
8
8
  "engines": {
9
- "node": ">=16.13.0 < 19.0"
9
+ "node": "^18.0.0"
10
10
  },
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "https://github.com/iTwin/itwinjs-core/tree/master/editor/backend"
13
+ "url": "https://github.com/iTwin/itwinjs-core.git",
14
+ "directory": "editor/backend"
14
15
  },
15
16
  "keywords": [
16
17
  "Bentley",
@@ -24,28 +25,28 @@
24
25
  "url": "http://www.bentley.com"
25
26
  },
26
27
  "peerDependencies": {
27
- "@itwin/core-backend": "^4.0.0-dev.8",
28
- "@itwin/core-bentley": "^4.0.0-dev.8",
29
- "@itwin/core-common": "^4.0.0-dev.8",
30
- "@itwin/core-geometry": "^4.0.0-dev.8"
28
+ "@itwin/core-backend": "^4.0.0-dev.80",
29
+ "@itwin/core-bentley": "^4.0.0-dev.80",
30
+ "@itwin/core-common": "^4.0.0-dev.80",
31
+ "@itwin/core-geometry": "^4.0.0-dev.80"
31
32
  },
32
33
  "//devDependencies": [
33
34
  "NOTE: All peerDependencies should also be listed as devDependencies since peerDependencies are not considered by npm install",
34
35
  "NOTE: All tools used by scripts in this package must be listed as devDependencies"
35
36
  ],
36
37
  "devDependencies": {
37
- "@itwin/build-tools": "4.0.0-dev.8",
38
- "@itwin/core-backend": "4.0.0-dev.8",
39
- "@itwin/core-bentley": "4.0.0-dev.8",
40
- "@itwin/core-common": "4.0.0-dev.8",
41
- "@itwin/core-geometry": "4.0.0-dev.8",
42
- "@itwin/eslint-plugin": "4.0.0-dev.8",
43
- "eslint": "^7.11.0",
38
+ "@itwin/build-tools": "4.0.0-dev.80",
39
+ "@itwin/core-backend": "4.0.0-dev.80",
40
+ "@itwin/core-bentley": "4.0.0-dev.80",
41
+ "@itwin/core-common": "4.0.0-dev.80",
42
+ "@itwin/core-geometry": "4.0.0-dev.80",
43
+ "@itwin/eslint-plugin": "^4.0.0-dev.33",
44
+ "eslint": "^8.36.0",
44
45
  "rimraf": "^3.0.2",
45
- "typescript": "~4.4.0"
46
+ "typescript": "~5.0.2"
46
47
  },
47
48
  "dependencies": {
48
- "@itwin/editor-common": "4.0.0-dev.8"
49
+ "@itwin/editor-common": "4.0.0-dev.80"
49
50
  },
50
51
  "eslintConfig": {
51
52
  "plugins": [
@@ -55,7 +56,6 @@
55
56
  },
56
57
  "scripts": {
57
58
  "build": "npm run -s build:cjs",
58
- "build:ci": "npm run -s build",
59
59
  "build:cjs": "tsc 1>&2 --outDir lib/cjs",
60
60
  "clean": "rimraf lib .rush/temp/package-deps*.json",
61
61
  "docs": "betools docs --includes=../../generated-docs/extract --json=../../generated-docs/editor/editor-backend/file.json --tsIndexFile=./editor-backend.ts --onlyJson",