@itwin/core-backend 4.1.0-dev.0 → 4.1.0-dev.3
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/ChannelControl.d.ts +13 -1
- package/lib/cjs/ChannelControl.d.ts.map +1 -1
- package/lib/cjs/ChannelControl.js +8 -5
- package/lib/cjs/ChannelControl.js.map +1 -1
- package/lib/cjs/ElementAspect.d.ts +1 -1
- package/lib/cjs/ElementAspect.js +1 -1
- package/lib/cjs/ElementAspect.js.map +1 -1
- package/package.json +10 -10
|
@@ -28,8 +28,16 @@ export interface ChannelControl {
|
|
|
28
28
|
* @throws if the element does not exist
|
|
29
29
|
*/
|
|
30
30
|
getChannelKey(elementId: Id64String): ChannelKey;
|
|
31
|
-
/**
|
|
31
|
+
/** Make an existing element a new Channel root.
|
|
32
|
+
* @note if the element is already in a channel, this will throw an error.
|
|
33
|
+
*/
|
|
34
|
+
makeChannelRoot(args: {
|
|
35
|
+
elementId: Id64String;
|
|
36
|
+
channelKey: ChannelKey;
|
|
37
|
+
}): void;
|
|
38
|
+
/** Insert a new Subject element that is a Channel root in this iModel.
|
|
32
39
|
* @returns the ElementId of the new Subject element.
|
|
40
|
+
* @note if the parentSubject element is already in a channel, this will add the Subject element and then throw an error without making it a Channel root.
|
|
33
41
|
*/
|
|
34
42
|
insertChannelSubject(args: {
|
|
35
43
|
/** The name of the new Subject element */
|
|
@@ -60,6 +68,10 @@ export declare class ChannelAdmin implements ChannelControl {
|
|
|
60
68
|
get hasChannels(): boolean;
|
|
61
69
|
getChannelKey(elementId: Id64String): ChannelKey;
|
|
62
70
|
verifyChannel(modelId: Id64String): void;
|
|
71
|
+
makeChannelRoot(args: {
|
|
72
|
+
elementId: Id64String;
|
|
73
|
+
channelKey: ChannelKey;
|
|
74
|
+
}): void;
|
|
63
75
|
insertChannelSubject(args: {
|
|
64
76
|
subjectName: string;
|
|
65
77
|
channelKey: ChannelKey;
|
|
@@ -1 +1 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,CAAC;QAC7B,4CAA4C;QAC5C,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,GAAG,UAAU,CAAC;IAEf,gBAAgB;IAChB,aAAa,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,CAAC;CAC1C;AAED,gBAAgB;AAChB,qBAAa,YAAa,YAAW,cAAc;IAS9B,OAAO,CAAC,OAAO;IARlC,wGAAwG;IACxG,gBAAuB,aAAa,YAAY;IAChD,gBAAuB,gBAAgB,2BAA2B;IAClE,OAAO,CAAC,gBAAgB,CAAyB;IACjD,OAAO,CAAC,cAAc,CAAyB;IAC/C,OAAO,CAAC,aAAa,CAAqC;IAC1D,OAAO,CAAC,YAAY,CAAC,CAAU;gBAEJ,OAAO,EAAE,QAAQ;IAGrC,iBAAiB,CAAC,UAAU,EAAE,UAAU;IAIxC,oBAAoB,CAAC,UAAU,EAAE,UAAU;IAIlD,IAAW,WAAW,IAAI,OAAO,CAUhC;IACM,aAAa,CAAC,SAAS,EAAE,UAAU,GAAG,UAAU;IAkBhD,aAAa,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI;IAiBxC,eAAe,CAAC,IAAI,EAAE;QAAE,SAAS,EAAE,UAAU,CAAC;QAAC,UAAU,EAAE,UAAU,CAAA;KAAE;IAQvE,oBAAoB,CAAC,IAAI,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,UAAU,CAAC;QAAC,eAAe,CAAC,EAAE,UAAU,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,UAAU;CAKnJ"}
|
|
@@ -72,14 +72,17 @@ class ChannelAdmin {
|
|
|
72
72
|
this._deniedModels.set(modelId, channel);
|
|
73
73
|
return this.verifyChannel(modelId);
|
|
74
74
|
}
|
|
75
|
-
|
|
76
|
-
if (
|
|
75
|
+
makeChannelRoot(args) {
|
|
76
|
+
if (ChannelAdmin.sharedChannel !== this.getChannelKey(args.elementId))
|
|
77
77
|
throw new Error("channels may not nest");
|
|
78
|
-
const
|
|
79
|
-
const props = { classFullName: ChannelAdmin.channelClassName, element: { id: subjectId }, owner: args.channelKey };
|
|
78
|
+
const props = { classFullName: ChannelAdmin.channelClassName, element: { id: args.elementId }, owner: args.channelKey };
|
|
80
79
|
this._iModel.elements.insertAspect(props);
|
|
81
80
|
this._hasChannels = true;
|
|
82
|
-
|
|
81
|
+
}
|
|
82
|
+
insertChannelSubject(args) {
|
|
83
|
+
const elementId = Element_1.Subject.insert(this._iModel, args.parentSubjectId ?? core_common_1.IModel.rootSubjectId, args.subjectName, args.description);
|
|
84
|
+
this.makeChannelRoot({ elementId, channelKey: args.channelKey });
|
|
85
|
+
return elementId;
|
|
83
86
|
}
|
|
84
87
|
}
|
|
85
88
|
/** the name of the special "shared" channel holding information that is editable by any application. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChannelControl.js","sourceRoot":"","sources":["../../src/ChannelControl.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA2F;AAC3F,oDAAiF;AACjF,uCAAoC;AA+CpC,gBAAgB;AAChB,MAAa,YAAY;IASvB,YAA2B,OAAiB;QAAjB,YAAO,GAAP,OAAO,CAAU;QALpC,qBAAgB,GAAG,IAAI,GAAG,EAAc,CAAC;QACzC,mBAAc,GAAG,IAAI,GAAG,EAAc,CAAC;QACvC,kBAAa,GAAG,IAAI,GAAG,EAA0B,CAAC;QAIxD,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC;IACxD,CAAC;IACM,iBAAiB,CAAC,UAAsB;QAC7C,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACtC,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;IACM,oBAAoB,CAAC,UAAsB;QAChD,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACzC,IAAI,C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I,KAAK,CAAC,uBAAuB,CAAC,CAAC;QAE3C,MAAM,SAAS,GAAG,iBAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,IAAI,oBAAM,CAAC,aAAa,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QACjI,MAAM,KAAK,GAA2B,EAAE,aAAa,EAAE,YAAY,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC;QAC3I,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QAC1C,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QACzB,OAAO,SAAS,CAAC;IACnB,CAAC;;AA1ED,wGAAwG;AACjF,0BAAa,GAAG,QAAQ,AAAX,CAAY;AACzB,6BAAgB,GAAG,uBAAuB,AAA1B,CAA2B;AAHvD,oCAAY","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 Elements\r\n */\r\n\r\nimport { DbResult, Id64String, IModelStatus, RepositoryStatus } from \"@itwin/core-bentley\";\r\nimport { ChannelRootAspectProps, IModel, IModelError } from \"@itwin/core-common\";\r\nimport { Subject } from \"./Element\";\r\nimport { IModelDb } from \"./IModelDb\";\r\n\r\n/** The key for a channel. Used for \"allowed channels\" in [[ChannelControl]]\r\n * @beta\r\n */\r\nexport type ChannelKey = string;\r\n\r\n/**\r\n * Controls which channels of an iModel are permitted for write operations. An implementation of this interface is\r\n * available via [[IModelDb.channels]].\r\n * @see [Working With Channels]($docs/learning/backend/Channel.md) for details\r\n * @beta\r\n */\r\nexport interface ChannelControl {\r\n /** Determine whether this [[IModelDb]] has any channels in it. */\r\n get hasChannels(): boolean;\r\n /** Add a new channel to the list of allowed channels of the [[IModelDb]] for this session.\r\n * @param channelKey The key for the channel to become editable in this session.\r\n */\r\n addAllowedChannel(channelKey: ChannelKey): void;\r\n /** Remove a channel from the list of allowed channels of the [[IModelDb]] for this session.\r\n * @param channelKey The key of the channel that should no longer be editable in this session.\r\n */\r\n removeAllowedChannel(channelKey: ChannelKey): void;\r\n /** Get the channelKey of the channel for an element by ElementId.\r\n * @throws if the element does not exist\r\n */\r\n getChannelKey(elementId: Id64String): ChannelKey;\r\n /** Insert a new Subject element that defines a new Channel in this iModel.\r\n * @returns the ElementId of the new Subject element.\r\n */\r\n insertChannelSubject(args: {\r\n /** The name of the new Subject element */\r\n subjectName: string;\r\n /** The channel key for the new [[Subject]]. This is the string to pass to [[addAllowedChannel]]*/\r\n channelKey: ChannelKey;\r\n /** the Id of the parent of the new Subject. Default is [[IModel.rootSubjectId]]. */\r\n parentSubjectId?: Id64String;\r\n /** Optional description for new Subject. */\r\n description?: string;\r\n }): Id64String;\r\n\r\n /** @internal */\r\n verifyChannel(modelId: Id64String): void;\r\n}\r\n\r\n/** @internal */\r\nexport class ChannelAdmin implements ChannelControl {\r\n /** the name of the special \"shared\" channel holding information that is editable by any application. */\r\n public static readonly sharedChannel = \"shared\";\r\n public static readonly channelClassName = \"bis:ChannelRootAspect\";\r\n private _allowedChannels = new Set<ChannelKey>();\r\n private _allowedModels = new Set<Id64String>();\r\n private _deniedModels = new Map<Id64String, ChannelKey>();\r\n private _hasChannels?: boolean;\r\n\r\n public constructor(private _iModel: IModelDb) {\r\n this._allowedChannels.add(ChannelAdmin.sharedChannel);\r\n }\r\n public addAllowedChannel(channelKey: ChannelKey) {\r\n this._allowedChannels.add(channelKey);\r\n this._deniedModels.clear();\r\n }\r\n public removeAllowedChannel(channelKey: ChannelKey) {\r\n this._allowedChannels.delete(channelKey);\r\n this._allowedModels.clear();\r\n }\r\n public get hasChannels(): boolean {\r\n if (undefined === this._hasChannels) {\r\n try {\r\n this._hasChannels = this._iModel.withStatement(`SELECT 1 FROM ${ChannelAdmin.channelClassName}`, (stmt) => stmt.step() === DbResult.BE_SQLITE_ROW, false);\r\n } catch (e) {\r\n // iModel doesn't have channel class in its BIS schema\r\n this._hasChannels = false;\r\n }\r\n }\r\n return this._hasChannels;\r\n }\r\n public getChannelKey(elementId: Id64String): ChannelKey {\r\n if (!this.hasChannels || elementId === IModel.rootSubjectId)\r\n return ChannelAdmin.sharedChannel;\r\n\r\n const channel = this._iModel.withPreparedStatement(`SELECT Owner FROM ${ChannelAdmin.channelClassName} WHERE Element.Id=?`, (stmt) => {\r\n stmt.bindId(1, elementId);\r\n return DbResult.BE_SQLITE_ROW === stmt.step() ? stmt.getValue(0).getString() : undefined;\r\n });\r\n if (channel !== undefined)\r\n return channel;\r\n const parentId = this._iModel.withPreparedSqliteStatement(\"SELECT ParentId,ModelId FROM bis_Element WHERE id=?\", (stmt) => {\r\n stmt.bindId(1, elementId);\r\n if (DbResult.BE_SQLITE_ROW !== stmt.step())\r\n throw new IModelError(IModelStatus.NotFound, \"Element does not exist\");\r\n return stmt.getValueId(0) ?? stmt.getValueId(1); // if parent is undefined, use modelId\r\n });\r\n return this.getChannelKey(parentId);\r\n }\r\n public verifyChannel(modelId: Id64String): void {\r\n // Note: indirect changes are permitted to change any channel\r\n if (!this.hasChannels || this._allowedModels.has(modelId) || this._iModel.nativeDb.isIndirectChanges())\r\n return;\r\n\r\n const deniedChannel = this._deniedModels.get(modelId);\r\n if (undefined !== deniedChannel)\r\n throw new IModelError(RepositoryStatus.ChannelConstraintViolation, `channel \"${deniedChannel}\" is not allowed`);\r\n\r\n const channel = this.getChannelKey(modelId);\r\n if (this._allowedChannels.has(channel)) {\r\n this._allowedModels.add(modelId);\r\n return;\r\n }\r\n this._deniedModels.set(modelId, channel);\r\n return this.verifyChannel(modelId);\r\n }\r\n public insertChannelSubject(args: { subjectName: string, channelKey: ChannelKey, parentSubjectId?: Id64String, description?: string }): Id64String {\r\n if (args.parentSubjectId && ChannelAdmin.sharedChannel !== this.getChannelKey(args.parentSubjectId))\r\n throw new Error(\"channels may not nest\");\r\n\r\n const subjectId = Subject.insert(this._iModel, args.parentSubjectId ?? IModel.rootSubjectId, args.subjectName, args.description);\r\n const props: ChannelRootAspectProps = { classFullName: ChannelAdmin.channelClassName, element: { id: subjectId }, owner: args.channelKey };\r\n this._iModel.elements.insertAspect(props);\r\n this._hasChannels = true;\r\n return subjectId;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"ChannelControl.js","sourceRoot":"","sources":["../../src/ChannelControl.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA2F;AAC3F,oDAAiF;AACjF,uCAAoC;AAoDpC,gBAAgB;AAChB,MAAa,YAAY;IASvB,YAA2B,OAAiB;QAAjB,YAAO,GAAP,OAAO,CAAU;QALpC,qBAAgB,GAAG,IAAI,GAAG,EAAc,CAAC;QACzC,mBAAc,GAAG,IAAI,GAAG,EAAc,CAAC;QACvC,kBAAa,GAAG,IAAI,GAAG,EAA0B,CAAC;QAIxD,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC;IACxD,CAAC;IACM,iBAAiB,CAAC,UAAsB;QAC7C,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACtC,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;IACM,oBAAoB,CAAC,UAAsB;QAChD,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACzC,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;IAC9B,CAAC;IACD,IAAW,WAAW;QACpB,IAAI,SAAS,KAAK,IAAI,CAAC,YAAY,EAAE;YACnC,IAAI;gBACF,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,iBAA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CAAC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QAC1C,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;IAC3B,CAAC;IACM,oBAAoB,CAAC,IAAyG;QACnI,MAAM,SAAS,GAAG,iBAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,IAAI,oBAAM,CAAC,aAAa,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QACjI,IAAI,CAAC,eAAe,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;QACjE,OAAO,SAAS,CAAC;IACnB,CAAC;;AA7ED,wGAAwG;AACjF,0BAAa,GAAG,QAAQ,AAAX,CAAY;AACzB,6BAAgB,GAAG,uBAAuB,AAA1B,CAA2B;AAHvD,oCAAY","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 Elements\r\n */\r\n\r\nimport { DbResult, Id64String, IModelStatus, RepositoryStatus } from \"@itwin/core-bentley\";\r\nimport { ChannelRootAspectProps, IModel, IModelError } from \"@itwin/core-common\";\r\nimport { Subject } from \"./Element\";\r\nimport { IModelDb } from \"./IModelDb\";\r\n\r\n/** The key for a channel. Used for \"allowed channels\" in [[ChannelControl]]\r\n * @beta\r\n */\r\nexport type ChannelKey = string;\r\n\r\n/**\r\n * Controls which channels of an iModel are permitted for write operations. An implementation of this interface is\r\n * available via [[IModelDb.channels]].\r\n * @see [Working With Channels]($docs/learning/backend/Channel.md) for details\r\n * @beta\r\n */\r\nexport interface ChannelControl {\r\n /** Determine whether this [[IModelDb]] has any channels in it. */\r\n get hasChannels(): boolean;\r\n /** Add a new channel to the list of allowed channels of the [[IModelDb]] for this session.\r\n * @param channelKey The key for the channel to become editable in this session.\r\n */\r\n addAllowedChannel(channelKey: ChannelKey): void;\r\n /** Remove a channel from the list of allowed channels of the [[IModelDb]] for this session.\r\n * @param channelKey The key of the channel that should no longer be editable in this session.\r\n */\r\n removeAllowedChannel(channelKey: ChannelKey): void;\r\n /** Get the channelKey of the channel for an element by ElementId.\r\n * @throws if the element does not exist\r\n */\r\n getChannelKey(elementId: Id64String): ChannelKey;\r\n /** Make an existing element a new Channel root.\r\n * @note if the element is already in a channel, this will throw an error.\r\n */\r\n makeChannelRoot(args: { elementId: Id64String, channelKey: ChannelKey }): void;\r\n /** Insert a new Subject element that is a Channel root in this iModel.\r\n * @returns the ElementId of the new Subject element.\r\n * @note if the parentSubject element is already in a channel, this will add the Subject element and then throw an error without making it a Channel root.\r\n */\r\n insertChannelSubject(args: {\r\n /** The name of the new Subject element */\r\n subjectName: string;\r\n /** The channel key for the new [[Subject]]. This is the string to pass to [[addAllowedChannel]]*/\r\n channelKey: ChannelKey;\r\n /** the Id of the parent of the new Subject. Default is [[IModel.rootSubjectId]]. */\r\n parentSubjectId?: Id64String;\r\n /** Optional description for new Subject. */\r\n description?: string;\r\n }): Id64String;\r\n\r\n /** @internal */\r\n verifyChannel(modelId: Id64String): void;\r\n}\r\n\r\n/** @internal */\r\nexport class ChannelAdmin implements ChannelControl {\r\n /** the name of the special \"shared\" channel holding information that is editable by any application. */\r\n public static readonly sharedChannel = \"shared\";\r\n public static readonly channelClassName = \"bis:ChannelRootAspect\";\r\n private _allowedChannels = new Set<ChannelKey>();\r\n private _allowedModels = new Set<Id64String>();\r\n private _deniedModels = new Map<Id64String, ChannelKey>();\r\n private _hasChannels?: boolean;\r\n\r\n public constructor(private _iModel: IModelDb) {\r\n this._allowedChannels.add(ChannelAdmin.sharedChannel);\r\n }\r\n public addAllowedChannel(channelKey: ChannelKey) {\r\n this._allowedChannels.add(channelKey);\r\n this._deniedModels.clear();\r\n }\r\n public removeAllowedChannel(channelKey: ChannelKey) {\r\n this._allowedChannels.delete(channelKey);\r\n this._allowedModels.clear();\r\n }\r\n public get hasChannels(): boolean {\r\n if (undefined === this._hasChannels) {\r\n try {\r\n this._hasChannels = this._iModel.withStatement(`SELECT 1 FROM ${ChannelAdmin.channelClassName}`, (stmt) => stmt.step() === DbResult.BE_SQLITE_ROW, false);\r\n } catch (e) {\r\n // iModel doesn't have channel class in its BIS schema\r\n this._hasChannels = false;\r\n }\r\n }\r\n return this._hasChannels;\r\n }\r\n public getChannelKey(elementId: Id64String): ChannelKey {\r\n if (!this.hasChannels || elementId === IModel.rootSubjectId)\r\n return ChannelAdmin.sharedChannel;\r\n\r\n const channel = this._iModel.withPreparedStatement(`SELECT Owner FROM ${ChannelAdmin.channelClassName} WHERE Element.Id=?`, (stmt) => {\r\n stmt.bindId(1, elementId);\r\n return DbResult.BE_SQLITE_ROW === stmt.step() ? stmt.getValue(0).getString() : undefined;\r\n });\r\n if (channel !== undefined)\r\n return channel;\r\n const parentId = this._iModel.withPreparedSqliteStatement(\"SELECT ParentId,ModelId FROM bis_Element WHERE id=?\", (stmt) => {\r\n stmt.bindId(1, elementId);\r\n if (DbResult.BE_SQLITE_ROW !== stmt.step())\r\n throw new IModelError(IModelStatus.NotFound, \"Element does not exist\");\r\n return stmt.getValueId(0) ?? stmt.getValueId(1); // if parent is undefined, use modelId\r\n });\r\n return this.getChannelKey(parentId);\r\n }\r\n public verifyChannel(modelId: Id64String): void {\r\n // Note: indirect changes are permitted to change any channel\r\n if (!this.hasChannels || this._allowedModels.has(modelId) || this._iModel.nativeDb.isIndirectChanges())\r\n return;\r\n\r\n const deniedChannel = this._deniedModels.get(modelId);\r\n if (undefined !== deniedChannel)\r\n throw new IModelError(RepositoryStatus.ChannelConstraintViolation, `channel \"${deniedChannel}\" is not allowed`);\r\n\r\n const channel = this.getChannelKey(modelId);\r\n if (this._allowedChannels.has(channel)) {\r\n this._allowedModels.add(modelId);\r\n return;\r\n }\r\n this._deniedModels.set(modelId, channel);\r\n return this.verifyChannel(modelId);\r\n }\r\n public makeChannelRoot(args: { elementId: Id64String, channelKey: ChannelKey }) {\r\n if (ChannelAdmin.sharedChannel !== this.getChannelKey(args.elementId))\r\n throw new Error(\"channels may not nest\");\r\n\r\n const props: ChannelRootAspectProps = { classFullName: ChannelAdmin.channelClassName, element: { id: args.elementId }, owner: args.channelKey };\r\n this._iModel.elements.insertAspect(props);\r\n this._hasChannels = true;\r\n }\r\n public insertChannelSubject(args: { subjectName: string, channelKey: ChannelKey, parentSubjectId?: Id64String, description?: string }): Id64String {\r\n const elementId = Subject.insert(this._iModel, args.parentSubjectId ?? IModel.rootSubjectId, args.subjectName, args.description);\r\n this.makeChannelRoot({ elementId, channelKey: args.channelKey });\r\n return elementId;\r\n }\r\n}\r\n"]}
|
|
@@ -96,7 +96,7 @@ export declare class ChannelRootAspect extends ElementUniqueAspect {
|
|
|
96
96
|
/** @internal */
|
|
97
97
|
static get className(): string;
|
|
98
98
|
/** Insert a ChannelRootAspect on the specified element.
|
|
99
|
-
* @deprecated in 4.0 use [[ChannelControl.
|
|
99
|
+
* @deprecated in 4.0 use [[ChannelControl.makeChannelRoot]]. This method does not enforce the rule that channels may not nest and is therefore dangerous.
|
|
100
100
|
*/
|
|
101
101
|
static insert(iModel: IModelDb, ownerId: Id64String, channelName: string): void;
|
|
102
102
|
}
|
package/lib/cjs/ElementAspect.js
CHANGED
|
@@ -94,7 +94,7 @@ class ChannelRootAspect extends ElementUniqueAspect {
|
|
|
94
94
|
/** @internal */
|
|
95
95
|
static get className() { return "ChannelRootAspect"; }
|
|
96
96
|
/** Insert a ChannelRootAspect on the specified element.
|
|
97
|
-
* @deprecated in 4.0 use [[ChannelControl.
|
|
97
|
+
* @deprecated in 4.0 use [[ChannelControl.makeChannelRoot]]. This method does not enforce the rule that channels may not nest and is therefore dangerous.
|
|
98
98
|
*/
|
|
99
99
|
static insert(iModel, ownerId, channelName) {
|
|
100
100
|
const props = { classFullName: this.classFullName, element: { id: ownerId }, owner: channelName };
|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AI,CAAC,KAAK;YACZ,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACzC,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACzC,IAAI,IAAI,CAAC,MAAM;YACb,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC5C,CAAC;CACF;AAxGD,oDAwGC;AAED,cAAc;AACd,WAAiB,oBAAoB;IACnC;;OAEG;IACH,IAAY,IASX;IATD,WAAY,IAAI;QACd,oFAAoF;QACpF,2BAAmB,CAAA;QACnB,yFAAyF;QACzF,qCAA6B,CAAA;QAC7B;;WAEG;QACH,uBAAe,CAAA;IACjB,CAAC,EATW,IAAI,GAAJ,yBAAI,KAAJ,yBAAI,QASf;AACH,CAAC,EAdgB,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QAcpC","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 ElementAspects\r\n */\r\n\r\nimport { ChannelRootAspectProps, ElementAspectProps, EntityReferenceSet, ExternalSourceAspectProps, RelatedElement } from \"@itwin/core-common\";\r\nimport { Entity } from \"./Entity\";\r\nimport { IModelDb } from \"./IModelDb\";\r\nimport { ECSqlStatement } from \"./ECSqlStatement\";\r\nimport { DbResult, Id64String } from \"@itwin/core-bentley\";\r\n\r\n/** Argument for the `ElementAspect.onXxx` static methods\r\n * @beta\r\n */\r\nexport interface OnAspectArg {\r\n /** The iModel for the aspect affected by this event. */\r\n iModel: IModelDb;\r\n /** The model for the aspect affected by this event */\r\n model: Id64String;\r\n}\r\n/** Argument for the `ElementAspect.onXxx` static methods that supply the properties of an aspect to be inserted or updated.\r\n * @beta\r\n */\r\nexport interface OnAspectPropsArg extends OnAspectArg {\r\n /** The new properties of the aspect affected by this event. */\r\n props: Readonly<ElementAspectProps>;\r\n}\r\n/** Argument for the `ElementAspect.onXxx` static methods that only supply the Id of the affected aspect.\r\n * @beta\r\n */\r\nexport interface OnAspectIdArg extends OnAspectArg {\r\n /** The Id of the aspect affected by this event */\r\n aspectId: Id64String;\r\n}\r\n\r\n/** An Element Aspect is a class that defines a set of properties that are related to (and owned by) a single element.\r\n * Semantically, an ElementAspect can be considered part of the Element. Thus, an ElementAspect is deleted if its owning Element is deleted.\r\n * BIS Guideline: Subclass ElementUniqueAspect or ElementMultiAspect rather than subclassing ElementAspect directly.\r\n * @public\r\n */\r\nexport class ElementAspect extends Entity {\r\n /** @internal */\r\n public static override get className(): string { return \"ElementAspect\"; }\r\n public element: RelatedElement;\r\n\r\n /** @internal */\r\n constructor(props: ElementAspectProps, iModel: IModelDb) {\r\n super(props, iModel);\r\n this.element = RelatedElement.fromJSON(props.element)!; // eslint-disable-line @typescript-eslint/no-non-null-assertion\r\n }\r\n\r\n /** @internal */\r\n public override toJSON(): ElementAspectProps {\r\n const val = super.toJSON() as ElementAspectProps;\r\n val.element = this.element;\r\n return val;\r\n }\r\n\r\n /** Called before a new ElementAspect is inserted.\r\n * @note throw an exception to disallow the insert\r\n * @note If you override this method, you must call super.\r\n * @beta\r\n */\r\n protected static onInsert(arg: OnAspectPropsArg): void {\r\n arg.iModel.channels.verifyChannel(arg.model);\r\n }\r\n\r\n /** Called after a new ElementAspect was inserted.\r\n * @note If you override this method, you must call super.\r\n * @beta\r\n */\r\n protected static onInserted(_arg: OnAspectPropsArg): void { }\r\n\r\n /** Called before an ElementAspect is updated.\r\n * @note throw an exception to disallow the update\r\n * @note If you override this method, you must call super.\r\n * @beta\r\n */\r\n protected static onUpdate(arg: OnAspectPropsArg): void {\r\n arg.iModel.channels.verifyChannel(arg.model);\r\n }\r\n\r\n /** Called after an ElementAspect was updated.\r\n * @note If you override this method, you must call super.\r\n * @beta\r\n */\r\n protected static onUpdated(_arg: OnAspectPropsArg): void { }\r\n\r\n /** Called before an ElementAspect is deleted.\r\n * @note throw an exception to disallow the delete\r\n * @note If you override this method, you must call super.\r\n * @beta\r\n */\r\n protected static onDelete(arg: OnAspectIdArg): void {\r\n arg.iModel.channels.verifyChannel(arg.model);\r\n }\r\n\r\n /** Called after an ElementAspect was deleted.\r\n * @note If you override this method, you must call super.\r\n * @beta\r\n */\r\n protected static onDeleted(_arg: OnAspectIdArg): void { }\r\n}\r\n\r\n/** An Element Unique Aspect is an ElementAspect where there can be only zero or one instance of the Element Aspect class per Element.\r\n * @public\r\n */\r\nexport class ElementUniqueAspect extends ElementAspect {\r\n /** @internal */\r\n public static override get className(): string { return \"ElementUniqueAspect\"; }\r\n}\r\n\r\n/** An Element Multi-Aspect is an ElementAspect where there can be **n** instances of the Element Aspect class per Element.\r\n * @public\r\n */\r\nexport class ElementMultiAspect extends ElementAspect {\r\n /** @internal */\r\n public static override get className(): string { return \"ElementMultiAspect\"; }\r\n}\r\n\r\n/**\r\n * @public\r\n */\r\nexport class ChannelRootAspect extends ElementUniqueAspect {\r\n /** @internal */\r\n public static override get className(): string { return \"ChannelRootAspect\"; }\r\n /** Insert a ChannelRootAspect on the specified element.\r\n * @deprecated in 4.0 use [[ChannelControl.insertChannelSubject]]\r\n */\r\n public static insert(iModel: IModelDb, ownerId: Id64String, channelName: string) {\r\n const props: ChannelRootAspectProps = { classFullName: this.classFullName, element: { id: ownerId }, owner: channelName };\r\n iModel.elements.insertAspect(props);\r\n }\r\n}\r\n\r\n/** An ElementMultiAspect that stores synchronization information for an Element originating from an external source.\r\n * @note The associated ECClass was added to the BisCore schema in version 1.0.2\r\n * @public\r\n */\r\nexport class ExternalSourceAspect extends ElementMultiAspect {\r\n /** @internal */\r\n public static override get className(): string { return \"ExternalSourceAspect\"; }\r\n\r\n /** An element that scopes the combination of `kind` and `identifier` to uniquely identify the object from the external source.\r\n * @note Warning: in a future major release the `scope` property will be optional, since the scope is intended to be potentially invalid.\r\n * all references should treat it as potentially undefined, but we cannot change the type yet since that is a breaking change.\r\n */\r\n public scope: RelatedElement;\r\n /** The identifier of the object in the source repository. */\r\n public identifier: string;\r\n /** The kind of object within the source repository. */\r\n public kind: string;\r\n /** The cryptographic hash (any algorithm) of the source object's content. If defined, it must be guaranteed to change when the source object's content changes. */\r\n public checksum?: string;\r\n /** An optional value that is typically a version number or a pseudo version number like last modified time.\r\n * It will be used by the synchronization process to detect that a source object is unchanged so that computing a cryptographic hash can be avoided.\r\n * If present, this value must be guaranteed to change when any of the source object's content changes.\r\n */\r\n public version?: string;\r\n /** A place where additional JSON properties can be stored. For example, provenance information or properties relating to the synchronization process.\r\n * @note Warning: in a future major release, the type of `jsonProperties` will be changed to object, and itwin.js will automatically stringify it when writing to the iModel.\r\n * This will be a breaking change, since application code will have to change from supplying a string to supplying an object.\r\n */\r\n public jsonProperties?: string;\r\n /** The source of the imported/synchronized object. Should point to an instance of [ExternalSource]($backend). */\r\n public source?: RelatedElement;\r\n\r\n /** @internal */\r\n constructor(props: ExternalSourceAspectProps, iModel: IModelDb) {\r\n super(props, iModel);\r\n this.scope = RelatedElement.fromJSON(props.scope)!; // eslint-disable-line @typescript-eslint/no-non-null-assertion\r\n this.source = RelatedElement.fromJSON(props.source);\r\n this.identifier = props.identifier;\r\n this.kind = props.kind;\r\n this.checksum = props.checksum;\r\n this.version = props.version;\r\n this.jsonProperties = props.jsonProperties;\r\n }\r\n\r\n /** @deprecated in 3.x. findAllBySource */\r\n public static findBySource(iModelDb: IModelDb, scope: Id64String, kind: string, identifier: string): { elementId?: Id64String, aspectId?: Id64String } {\r\n const sql = `SELECT Element.Id, ECInstanceId FROM ${ExternalSourceAspect.classFullName} WHERE (Scope.Id=:scope AND Kind=:kind AND Identifier=:identifier)`;\r\n let elementId: Id64String | undefined;\r\n let aspectId: Id64String | undefined;\r\n iModelDb.withPreparedStatement(sql, (statement: ECSqlStatement) => {\r\n statement.bindId(\"scope\", scope);\r\n statement.bindString(\"kind\", kind);\r\n statement.bindString(\"identifier\", identifier);\r\n if (DbResult.BE_SQLITE_ROW === statement.step()) {\r\n elementId = statement.getValue(0).getId();\r\n aspectId = statement.getValue(1).getId();\r\n }\r\n });\r\n return { elementId, aspectId };\r\n }\r\n\r\n /** Look up the elements that contain one or more ExternalSourceAspect with the specified Scope, Kind, and Identifier.\r\n * The result of this function is an array of all of the ExternalSourceAspects that were found, each associated with the owning element.\r\n * A given element could have more than one ExternalSourceAspect with the given scope, kind, and identifier.\r\n * Also, many elements could have ExternalSourceAspect with the same scope, kind, and identifier.\r\n * Therefore, the result array could have more than one entry with the same elementId.\r\n * Aspects are never shared. Each aspect has its own unique ECInstanceId.\r\n * @param iModelDb The iModel to query\r\n * @param scope The scope of the ExternalSourceAspects to find\r\n * @param kind The kind of the ExternalSourceAspects to find\r\n * @param identifier The identifier of the ExternalSourceAspects to find\r\n * @returns the query results\r\n */\r\n public static findAllBySource(iModelDb: IModelDb, scope: Id64String, kind: string, identifier: string): Array<{ elementId: Id64String, aspectId: Id64String }> {\r\n const sql = `SELECT Element.Id, ECInstanceId FROM ${ExternalSourceAspect.classFullName} WHERE (Scope.Id=:scope AND Kind=:kind AND Identifier=:identifier)`;\r\n const found: Array<{ elementId: Id64String, aspectId: Id64String }> = [];\r\n iModelDb.withPreparedStatement(sql, (statement: ECSqlStatement) => {\r\n statement.bindId(\"scope\", scope);\r\n statement.bindString(\"kind\", kind);\r\n statement.bindString(\"identifier\", identifier);\r\n while (DbResult.BE_SQLITE_ROW === statement.step()) {\r\n found.push({ elementId: statement.getValue(0).getId(), aspectId: statement.getValue(1).getId() });\r\n }\r\n });\r\n return found;\r\n }\r\n\r\n /** @internal */\r\n public override toJSON(): ExternalSourceAspectProps {\r\n const val = super.toJSON() as ExternalSourceAspectProps;\r\n val.scope = this.scope;\r\n val.source = this.source;\r\n val.identifier = this.identifier;\r\n val.kind = this.kind;\r\n val.checksum = this.checksum;\r\n val.version = this.version;\r\n val.jsonProperties = this.jsonProperties;\r\n return val;\r\n }\r\n\r\n protected override collectReferenceIds(referenceIds: EntityReferenceSet): void {\r\n super.collectReferenceIds(referenceIds);\r\n if (this.scope)\r\n referenceIds.addElement(this.scope.id);\r\n referenceIds.addElement(this.element.id);\r\n if (this.source)\r\n referenceIds.addElement(this.source.id);\r\n }\r\n}\r\n\r\n/** @public */\r\nexport namespace ExternalSourceAspect { // eslint-disable-line no-redeclare\r\n /** Standard values for the `Kind` property of `ExternalSourceAspect`.\r\n * @public\r\n */\r\n export enum Kind {\r\n /** Indicates that the [[ExternalSourceAspect]] is storing [[Element]] provenance */\r\n Element = \"Element\",\r\n /** Indicates that the [[ExternalSourceAspect]] is storing [[Relationship]] provenance */\r\n Relationship = \"Relationship\",\r\n /** Indicates that the [[ExternalSourceAspect]] is storing *scope* provenance\r\n * @see [[ExternalSourceAspect.scope]]\r\n */\r\n Scope = \"Scope\",\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"ElementAspect.js","sourceRoot":"","sources":["../../src/ElementAspect.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,oDAA+I;AAC/I,qCAAkC;AAGlC,sDAA2D;AA0B3D;;;;GAIG;AACH,MAAa,aAAc,SAAQ,eAAM;IACvC,gBAAgB;IACT,MAAM,KAAc,SAAS,KAAa,OAAO,eAAe,CAAC,CAAC,CAAC;IAG1E,gBAAgB;IAChB,YAAY,KAAyB,EAAE,MAAgB;QACrD,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,4BAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAE,CAAC,CAAC,+DAA+D;IACzH,CAAC;IAED,gBAAgB;IACA,MAAM;QACpB,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,EAAwB,CAAC;QACjD,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC3B,OAAO,GAAG,CAAC;IACb,CAA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G,GAAG,KAAK,CAAC,MAAM,EAA+B,CAAC;QACxD,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACvB,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QACzB,GAAG,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QACjC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACrB,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC7B,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC3B,GAAG,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;QACzC,OAAO,GAAG,CAAC;IACb,CAAC;IAEkB,mBAAmB,CAAC,YAAgC;QACrE,KAAK,CAAC,mBAAmB,CAAC,YAAY,CAAC,CAAC;QACxC,IAAI,IAAI,CAAC,KAAK;YACZ,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACzC,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACzC,IAAI,IAAI,CAAC,MAAM;YACb,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC5C,CAAC;CACF;AAxGD,oDAwGC;AAED,cAAc;AACd,WAAiB,oBAAoB;IACnC;;OAEG;IACH,IAAY,IASX;IATD,WAAY,IAAI;QACd,oFAAoF;QACpF,2BAAmB,CAAA;QACnB,yFAAyF;QACzF,qCAA6B,CAAA;QAC7B;;WAEG;QACH,uBAAe,CAAA;IACjB,CAAC,EATW,IAAI,GAAJ,yBAAI,KAAJ,yBAAI,QASf;AACH,CAAC,EAdgB,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QAcpC","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 ElementAspects\r\n */\r\n\r\nimport { ChannelRootAspectProps, ElementAspectProps, EntityReferenceSet, ExternalSourceAspectProps, RelatedElement } from \"@itwin/core-common\";\r\nimport { Entity } from \"./Entity\";\r\nimport { IModelDb } from \"./IModelDb\";\r\nimport { ECSqlStatement } from \"./ECSqlStatement\";\r\nimport { DbResult, Id64String } from \"@itwin/core-bentley\";\r\n\r\n/** Argument for the `ElementAspect.onXxx` static methods\r\n * @beta\r\n */\r\nexport interface OnAspectArg {\r\n /** The iModel for the aspect affected by this event. */\r\n iModel: IModelDb;\r\n /** The model for the aspect affected by this event */\r\n model: Id64String;\r\n}\r\n/** Argument for the `ElementAspect.onXxx` static methods that supply the properties of an aspect to be inserted or updated.\r\n * @beta\r\n */\r\nexport interface OnAspectPropsArg extends OnAspectArg {\r\n /** The new properties of the aspect affected by this event. */\r\n props: Readonly<ElementAspectProps>;\r\n}\r\n/** Argument for the `ElementAspect.onXxx` static methods that only supply the Id of the affected aspect.\r\n * @beta\r\n */\r\nexport interface OnAspectIdArg extends OnAspectArg {\r\n /** The Id of the aspect affected by this event */\r\n aspectId: Id64String;\r\n}\r\n\r\n/** An Element Aspect is a class that defines a set of properties that are related to (and owned by) a single element.\r\n * Semantically, an ElementAspect can be considered part of the Element. Thus, an ElementAspect is deleted if its owning Element is deleted.\r\n * BIS Guideline: Subclass ElementUniqueAspect or ElementMultiAspect rather than subclassing ElementAspect directly.\r\n * @public\r\n */\r\nexport class ElementAspect extends Entity {\r\n /** @internal */\r\n public static override get className(): string { return \"ElementAspect\"; }\r\n public element: RelatedElement;\r\n\r\n /** @internal */\r\n constructor(props: ElementAspectProps, iModel: IModelDb) {\r\n super(props, iModel);\r\n this.element = RelatedElement.fromJSON(props.element)!; // eslint-disable-line @typescript-eslint/no-non-null-assertion\r\n }\r\n\r\n /** @internal */\r\n public override toJSON(): ElementAspectProps {\r\n const val = super.toJSON() as ElementAspectProps;\r\n val.element = this.element;\r\n return val;\r\n }\r\n\r\n /** Called before a new ElementAspect is inserted.\r\n * @note throw an exception to disallow the insert\r\n * @note If you override this method, you must call super.\r\n * @beta\r\n */\r\n protected static onInsert(arg: OnAspectPropsArg): void {\r\n arg.iModel.channels.verifyChannel(arg.model);\r\n }\r\n\r\n /** Called after a new ElementAspect was inserted.\r\n * @note If you override this method, you must call super.\r\n * @beta\r\n */\r\n protected static onInserted(_arg: OnAspectPropsArg): void { }\r\n\r\n /** Called before an ElementAspect is updated.\r\n * @note throw an exception to disallow the update\r\n * @note If you override this method, you must call super.\r\n * @beta\r\n */\r\n protected static onUpdate(arg: OnAspectPropsArg): void {\r\n arg.iModel.channels.verifyChannel(arg.model);\r\n }\r\n\r\n /** Called after an ElementAspect was updated.\r\n * @note If you override this method, you must call super.\r\n * @beta\r\n */\r\n protected static onUpdated(_arg: OnAspectPropsArg): void { }\r\n\r\n /** Called before an ElementAspect is deleted.\r\n * @note throw an exception to disallow the delete\r\n * @note If you override this method, you must call super.\r\n * @beta\r\n */\r\n protected static onDelete(arg: OnAspectIdArg): void {\r\n arg.iModel.channels.verifyChannel(arg.model);\r\n }\r\n\r\n /** Called after an ElementAspect was deleted.\r\n * @note If you override this method, you must call super.\r\n * @beta\r\n */\r\n protected static onDeleted(_arg: OnAspectIdArg): void { }\r\n}\r\n\r\n/** An Element Unique Aspect is an ElementAspect where there can be only zero or one instance of the Element Aspect class per Element.\r\n * @public\r\n */\r\nexport class ElementUniqueAspect extends ElementAspect {\r\n /** @internal */\r\n public static override get className(): string { return \"ElementUniqueAspect\"; }\r\n}\r\n\r\n/** An Element Multi-Aspect is an ElementAspect where there can be **n** instances of the Element Aspect class per Element.\r\n * @public\r\n */\r\nexport class ElementMultiAspect extends ElementAspect {\r\n /** @internal */\r\n public static override get className(): string { return \"ElementMultiAspect\"; }\r\n}\r\n\r\n/**\r\n * @public\r\n */\r\nexport class ChannelRootAspect extends ElementUniqueAspect {\r\n /** @internal */\r\n public static override get className(): string { return \"ChannelRootAspect\"; }\r\n /** Insert a ChannelRootAspect on the specified element.\r\n * @deprecated in 4.0 use [[ChannelControl.makeChannelRoot]]. This method does not enforce the rule that channels may not nest and is therefore dangerous.\r\n */\r\n public static insert(iModel: IModelDb, ownerId: Id64String, channelName: string) {\r\n const props: ChannelRootAspectProps = { classFullName: this.classFullName, element: { id: ownerId }, owner: channelName };\r\n iModel.elements.insertAspect(props);\r\n }\r\n}\r\n\r\n/** An ElementMultiAspect that stores synchronization information for an Element originating from an external source.\r\n * @note The associated ECClass was added to the BisCore schema in version 1.0.2\r\n * @public\r\n */\r\nexport class ExternalSourceAspect extends ElementMultiAspect {\r\n /** @internal */\r\n public static override get className(): string { return \"ExternalSourceAspect\"; }\r\n\r\n /** An element that scopes the combination of `kind` and `identifier` to uniquely identify the object from the external source.\r\n * @note Warning: in a future major release the `scope` property will be optional, since the scope is intended to be potentially invalid.\r\n * all references should treat it as potentially undefined, but we cannot change the type yet since that is a breaking change.\r\n */\r\n public scope: RelatedElement;\r\n /** The identifier of the object in the source repository. */\r\n public identifier: string;\r\n /** The kind of object within the source repository. */\r\n public kind: string;\r\n /** The cryptographic hash (any algorithm) of the source object's content. If defined, it must be guaranteed to change when the source object's content changes. */\r\n public checksum?: string;\r\n /** An optional value that is typically a version number or a pseudo version number like last modified time.\r\n * It will be used by the synchronization process to detect that a source object is unchanged so that computing a cryptographic hash can be avoided.\r\n * If present, this value must be guaranteed to change when any of the source object's content changes.\r\n */\r\n public version?: string;\r\n /** A place where additional JSON properties can be stored. For example, provenance information or properties relating to the synchronization process.\r\n * @note Warning: in a future major release, the type of `jsonProperties` will be changed to object, and itwin.js will automatically stringify it when writing to the iModel.\r\n * This will be a breaking change, since application code will have to change from supplying a string to supplying an object.\r\n */\r\n public jsonProperties?: string;\r\n /** The source of the imported/synchronized object. Should point to an instance of [ExternalSource]($backend). */\r\n public source?: RelatedElement;\r\n\r\n /** @internal */\r\n constructor(props: ExternalSourceAspectProps, iModel: IModelDb) {\r\n super(props, iModel);\r\n this.scope = RelatedElement.fromJSON(props.scope)!; // eslint-disable-line @typescript-eslint/no-non-null-assertion\r\n this.source = RelatedElement.fromJSON(props.source);\r\n this.identifier = props.identifier;\r\n this.kind = props.kind;\r\n this.checksum = props.checksum;\r\n this.version = props.version;\r\n this.jsonProperties = props.jsonProperties;\r\n }\r\n\r\n /** @deprecated in 3.x. findAllBySource */\r\n public static findBySource(iModelDb: IModelDb, scope: Id64String, kind: string, identifier: string): { elementId?: Id64String, aspectId?: Id64String } {\r\n const sql = `SELECT Element.Id, ECInstanceId FROM ${ExternalSourceAspect.classFullName} WHERE (Scope.Id=:scope AND Kind=:kind AND Identifier=:identifier)`;\r\n let elementId: Id64String | undefined;\r\n let aspectId: Id64String | undefined;\r\n iModelDb.withPreparedStatement(sql, (statement: ECSqlStatement) => {\r\n statement.bindId(\"scope\", scope);\r\n statement.bindString(\"kind\", kind);\r\n statement.bindString(\"identifier\", identifier);\r\n if (DbResult.BE_SQLITE_ROW === statement.step()) {\r\n elementId = statement.getValue(0).getId();\r\n aspectId = statement.getValue(1).getId();\r\n }\r\n });\r\n return { elementId, aspectId };\r\n }\r\n\r\n /** Look up the elements that contain one or more ExternalSourceAspect with the specified Scope, Kind, and Identifier.\r\n * The result of this function is an array of all of the ExternalSourceAspects that were found, each associated with the owning element.\r\n * A given element could have more than one ExternalSourceAspect with the given scope, kind, and identifier.\r\n * Also, many elements could have ExternalSourceAspect with the same scope, kind, and identifier.\r\n * Therefore, the result array could have more than one entry with the same elementId.\r\n * Aspects are never shared. Each aspect has its own unique ECInstanceId.\r\n * @param iModelDb The iModel to query\r\n * @param scope The scope of the ExternalSourceAspects to find\r\n * @param kind The kind of the ExternalSourceAspects to find\r\n * @param identifier The identifier of the ExternalSourceAspects to find\r\n * @returns the query results\r\n */\r\n public static findAllBySource(iModelDb: IModelDb, scope: Id64String, kind: string, identifier: string): Array<{ elementId: Id64String, aspectId: Id64String }> {\r\n const sql = `SELECT Element.Id, ECInstanceId FROM ${ExternalSourceAspect.classFullName} WHERE (Scope.Id=:scope AND Kind=:kind AND Identifier=:identifier)`;\r\n const found: Array<{ elementId: Id64String, aspectId: Id64String }> = [];\r\n iModelDb.withPreparedStatement(sql, (statement: ECSqlStatement) => {\r\n statement.bindId(\"scope\", scope);\r\n statement.bindString(\"kind\", kind);\r\n statement.bindString(\"identifier\", identifier);\r\n while (DbResult.BE_SQLITE_ROW === statement.step()) {\r\n found.push({ elementId: statement.getValue(0).getId(), aspectId: statement.getValue(1).getId() });\r\n }\r\n });\r\n return found;\r\n }\r\n\r\n /** @internal */\r\n public override toJSON(): ExternalSourceAspectProps {\r\n const val = super.toJSON() as ExternalSourceAspectProps;\r\n val.scope = this.scope;\r\n val.source = this.source;\r\n val.identifier = this.identifier;\r\n val.kind = this.kind;\r\n val.checksum = this.checksum;\r\n val.version = this.version;\r\n val.jsonProperties = this.jsonProperties;\r\n return val;\r\n }\r\n\r\n protected override collectReferenceIds(referenceIds: EntityReferenceSet): void {\r\n super.collectReferenceIds(referenceIds);\r\n if (this.scope)\r\n referenceIds.addElement(this.scope.id);\r\n referenceIds.addElement(this.element.id);\r\n if (this.source)\r\n referenceIds.addElement(this.source.id);\r\n }\r\n}\r\n\r\n/** @public */\r\nexport namespace ExternalSourceAspect { // eslint-disable-line no-redeclare\r\n /** Standard values for the `Kind` property of `ExternalSourceAspect`.\r\n * @public\r\n */\r\n export enum Kind {\r\n /** Indicates that the [[ExternalSourceAspect]] is storing [[Element]] provenance */\r\n Element = \"Element\",\r\n /** Indicates that the [[ExternalSourceAspect]] is storing [[Relationship]] provenance */\r\n Relationship = \"Relationship\",\r\n /** Indicates that the [[ExternalSourceAspect]] is storing *scope* provenance\r\n * @see [[ExternalSourceAspect.scope]]\r\n */\r\n Scope = \"Scope\",\r\n }\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-backend",
|
|
3
|
-
"version": "4.1.0-dev.
|
|
3
|
+
"version": "4.1.0-dev.3",
|
|
4
4
|
"description": "iTwin.js backend components",
|
|
5
5
|
"main": "lib/cjs/core-backend.js",
|
|
6
6
|
"typings": "lib/cjs/core-backend",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"url": "http://www.bentley.com"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@itwin/core-bentley": "^4.1.0-dev.
|
|
29
|
-
"@itwin/core-common": "^4.1.0-dev.
|
|
30
|
-
"@itwin/core-geometry": "^4.1.0-dev.
|
|
28
|
+
"@itwin/core-bentley": "^4.1.0-dev.3",
|
|
29
|
+
"@itwin/core-common": "^4.1.0-dev.3",
|
|
30
|
+
"@itwin/core-geometry": "^4.1.0-dev.3",
|
|
31
31
|
"@opentelemetry/api": "^1.0.4"
|
|
32
32
|
},
|
|
33
33
|
"peerDependenciesMeta": {
|
|
@@ -66,11 +66,11 @@
|
|
|
66
66
|
"source-map-loader": "^4.0.0",
|
|
67
67
|
"typescript": "~5.0.2",
|
|
68
68
|
"webpack": "^5.76.0",
|
|
69
|
-
"@itwin/build-tools": "4.1.0-dev.
|
|
70
|
-
"@itwin/core-
|
|
71
|
-
"@itwin/core-
|
|
72
|
-
"@itwin/core-
|
|
73
|
-
"@itwin/core-
|
|
69
|
+
"@itwin/build-tools": "4.1.0-dev.3",
|
|
70
|
+
"@itwin/core-bentley": "4.1.0-dev.3",
|
|
71
|
+
"@itwin/core-common": "4.1.0-dev.3",
|
|
72
|
+
"@itwin/core-geometry": "4.1.0-dev.3",
|
|
73
|
+
"@itwin/core-webpack-tools": "4.1.0-dev.3",
|
|
74
74
|
"internal-tools": "3.0.0-dev.69"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"multiparty": "^4.2.1",
|
|
86
86
|
"semver": "^7.3.5",
|
|
87
87
|
"ws": "^7.5.3",
|
|
88
|
-
"@itwin/core-telemetry": "4.1.0-dev.
|
|
88
|
+
"@itwin/core-telemetry": "4.1.0-dev.3"
|
|
89
89
|
},
|
|
90
90
|
"nyc": {
|
|
91
91
|
"extends": "./node_modules/@itwin/build-tools/.nycrc"
|