Skip to content

Commit

Permalink
Code trim behaviors (backport #5861) [release/4.1.x] (#5882)
Browse files Browse the repository at this point in the history
  • Loading branch information
aruniverse authored Aug 18, 2023
2 parents f45e5bb + 76abfb0 commit d760a49
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 8 deletions.
3 changes: 3 additions & 0 deletions common/api/core-backend.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2905,6 +2905,9 @@ export abstract class IModelDb extends IModel {
// @internal (undocumented)
protected _codeService?: CodeService;
get codeSpecs(): CodeSpecs;
// @internal
get codeValueBehavior(): "exact" | "trim-unicode-whitespace";
set codeValueBehavior(newBehavior: "exact" | "trim-unicode-whitespace");
computeProjectExtents(options?: ComputeProjectExtentsOptions): ComputedProjectExtents;
constructEntity<T extends Entity, P extends EntityProps = EntityProps>(props: P): T;
containsClass(classFullName: string): boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/core-backend",
"comment": "add `internal` `codeValueBehavior` API ",
"type": "none"
}
],
"packageName": "@itwin/core-backend"
}
1 change: 1 addition & 0 deletions common/config/azure-pipelines/templates/core-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ steps:
env:
RUSH_BUILD_CACHE_CREDENTIAL: $(RushBuildCacheSAS)
RUSH_BUILD_CACHE_ENABLED: ${{parameters.rushBuildCacheEnabled}}
VITE_CI: true

- script: npm run ios:all
workingDirectory: test-apps/display-test-app
Expand Down
8 changes: 4 additions & 4 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"webpack": "^5.76.0"
},
"dependencies": {
"@bentley/imodeljs-native": "4.1.8",
"@bentley/imodeljs-native": "4.1.9",
"@itwin/cloud-agnostic-core": "^2.0.0",
"@itwin/core-telemetry": "workspace:*",
"@itwin/object-storage-azure": "^2.0.0",
Expand Down
12 changes: 12 additions & 0 deletions core/backend/src/IModelDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,18 @@ export abstract class IModelDb extends IModel {
}
});
}

/**
* Controls how [Code]($common)s are copied from this iModel into another iModel, to work around problems with iModels created by older connectors. The [imodel-transformer](https://github.com/iTwin/imodel-transformer) sets this appropriately on your behalf - you should never need to set or interrogate this property yourself.
* @internal
*/
public get codeValueBehavior(): "exact" | "trim-unicode-whitespace" {
return this.nativeDb.getCodeValueBehavior();
}

public set codeValueBehavior(newBehavior: "exact" | "trim-unicode-whitespace") {
this.nativeDb.setCodeValueBehavior(newBehavior);
}
}

/** @public */
Expand Down
41 changes: 40 additions & 1 deletion core/backend/src/test/imodel/IModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as sinon from "sinon";
import { DbResult, Guid, GuidString, Id64, Id64String, Logger, OpenMode, ProcessDetector, using } from "@itwin/core-bentley";
import {
AxisAlignedBox3d, BisCodeSpec, BriefcaseIdValue, ChangesetIdWithIndex, Code, CodeScopeSpec, CodeSpec, ColorByName, ColorDef, DefinitionElementProps,
DisplayStyleProps, DisplayStyleSettings, DisplayStyleSettingsProps, EcefLocation, EntityMetaData, EntityProps, FilePropertyProps,
DisplayStyleProps, DisplayStyleSettings, DisplayStyleSettingsProps, EcefLocation, ElementProps, EntityMetaData, EntityProps, FilePropertyProps,
FontMap, FontType, GeoCoordinatesRequestProps, GeoCoordStatus, GeographicCRS, GeographicCRSProps, GeometricElementProps, GeometryParams, GeometryStreamBuilder,
ImageSourceFormat, IModel, IModelCoordinatesRequestProps, IModelError, IModelStatus, LightLocationProps, MapImageryProps, PhysicalElementProps,
PointWithStatus, PrimitiveTypeCode, RelatedElement, RenderMode, SchemaState, SpatialViewDefinitionProps, SubCategoryAppearance, SubjectProps, TextureMapping,
Expand Down Expand Up @@ -2781,4 +2781,43 @@ describe("iModel", () => {
assert.isUndefined(subject4.federationGuid); // should not have changed

});

it('should allow untrimmed codes when using "exact" codeValueBehavior', () => {
const imodelPath = IModelTestUtils.prepareOutputFile("IModel", "codeValueBehavior.bim");
const imodel = SnapshotDb.createEmpty(imodelPath, { rootSubject: { name: "codeValueBehaviors" } });

const getNumberedCodeValAndProps = (n: number) => {
const trimmedCodeVal = `CodeValue${n}`;
const untrimmedCodeVal = `${trimmedCodeVal}\xa0`;
const spec = imodel.codeSpecs.getByName(SpatialCategory.getCodeSpecName()).id;
const props: ElementProps = {
// the [[Code]] class still (as it always has) trims unicode space, so avoid it
code: { spec, scope: IModelDb.dictionaryId, value: untrimmedCodeVal },
model: IModelDb.dictionaryId,
classFullName: SpatialCategory.classFullName,
};
return { trimmedCodeVal, untrimmedCodeVal, props };
};

expect(imodel.codeValueBehavior).to.equal("trim-unicode-whitespace");

const code1 = getNumberedCodeValAndProps(1);
const categ1Id = imodel.elements.insertElement(code1.props);
const categ1 = imodel.elements.getElementJson({ id: categ1Id });
expect(categ1.code.value).to.equal(code1.trimmedCodeVal);

imodel.codeValueBehavior = "exact";
const code2 = getNumberedCodeValAndProps(2);
const categ2Id = imodel.elements.insertElement(code2.props);
const categ2 = imodel.elements.getElementJson({ id: categ2Id });
expect(categ2.code.value).to.equal(code2.untrimmedCodeVal);

imodel.codeValueBehavior = "trim-unicode-whitespace";
const code3 = getNumberedCodeValAndProps(3);
const categ3Id = imodel.elements.insertElement(code3.props);
const categ3 = imodel.elements.getElement({ id: categ3Id });
expect(categ3.code.value).to.equal(code3.trimmedCodeVal);

imodel.close();
});
});
2 changes: 1 addition & 1 deletion test-apps/display-performance-test-app/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default defineConfig(() => {
publicDir: ".static-assets",
build: {
outDir: "./lib",
sourcemap: "inline", // append to the resulting output file
sourcemap: !!process.env.VITE_CI,
minify: false, // disable compaction of source code
target: browserslistToEsbuild(), // for browserslist in package.json
commonjsOptions: {
Expand Down
3 changes: 2 additions & 1 deletion test-apps/display-test-app/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ export default defineConfig(() => {
},
envPrefix: "IMJS_",
publicDir: ".static-assets",
logLevel: process.env.VITE_CI ? "error" : "warn",
build: {
outDir: "./lib",
sourcemap: "inline", // append to the resulting output file
sourcemap: !!process.env.VITE_CI, // append to the resulting output file if not running in CI.
minify: false, // disable compaction of source code
target: browserslistToEsbuild(), // for browserslist in package.json
commonjsOptions: {
Expand Down

0 comments on commit d760a49

Please sign in to comment.