Skip to content

Commit

Permalink
Added more logic
Browse files Browse the repository at this point in the history
  • Loading branch information
RohitPtnkr1996 committed Nov 15, 2024
1 parent 163b457 commit fee9279
Show file tree
Hide file tree
Showing 7 changed files with 285 additions and 73 deletions.
28 changes: 28 additions & 0 deletions common/config/rush/browser-approved-packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
"name": "@bentley/aec-units-schema",
"allowedCategories": [ "backend", "internal" ]
},
{
"name": "@bentley/analytical-schema",
"allowedCategories": [ "backend" ]
},
{
"name": "@bentley/architectural-physical-schema",
"allowedCategories": [ "backend" ]
Expand Down Expand Up @@ -74,10 +78,18 @@
"name": "@bentley/core-custom-attributes-schema",
"allowedCategories": [ "backend" ]
},
{
"name": "@bentley/ecdb-file-info-schema",
"allowedCategories": [ "backend" ]
},
{
"name": "@bentley/ecdb-map-schema",
"allowedCategories": [ "backend" ]
},
{
"name": "@bentley/ecdb-meta-schema",
"allowedCategories": [ "backend" ]
},
{
"name": "@bentley/ecdb-schema-policies-schema",
"allowedCategories": [ "backend" ]
Expand All @@ -86,6 +98,14 @@
"name": "@bentley/formats-schema",
"allowedCategories": [ "backend" ]
},
{
"name": "@bentley/functional-schema",
"allowedCategories": [ "backend" ]
},
{
"name": "@bentley/generic-schema",
"allowedCategories": [ "backend" ]
},
{
"name": "@bentley/icons-generic",
"allowedCategories": [ "internal" ]
Expand All @@ -110,6 +130,10 @@
"name": "@bentley/plant-custom-attributes-schema",
"allowedCategories": [ "backend", "internal" ]
},
{
"name": "@bentley/presentation-rules-schema",
"allowedCategories": [ "backend" ]
},
{
"name": "@bentley/process-functional-schema",
"allowedCategories": [ "internal" ]
Expand All @@ -126,6 +150,10 @@
"name": "@bentley/road-rail-units-schema",
"allowedCategories": [ "internal" ]
},
{
"name": "@bentley/schema-upgrade-custom-attributes-schema",
"allowedCategories": [ "backend" ]
},
{
"name": "@bentley/spatial-composition-schema",
"allowedCategories": [ "backend" ]
Expand Down
50 changes: 46 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.

11 changes: 9 additions & 2 deletions core/ecschema-locaters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,17 @@
"@bentley/aec-units-schema": "^1.0.3",
"@bentley/architectural-physical-schema": "^1.0.3",
"@bentley/bis-core-schema": "^1.0.15",
"@bentley/generic-schema": "^1.0.5",
"@bentley/analytical-schema": "^1.0.1",
"@bentley/functional-schema": "^1.0.4",
"@bentley/presentation-rules-schema": "^1.0.1",
"@bentley/ecdb-file-info-schema": "^2.0.1",
"@bentley/ecdb-meta-schema": "^4.0.3",
"@bentley/schema-upgrade-custom-attributes-schema": "^1.0.0",
"@bentley/bis-custom-attributes-schema": "^1.0.0",
"@bentley/construction-schema": "^1.0.4",
"@bentley/core-custom-attributes-schema": "^1.0.4",
"@bentley/ecdb-map-schema": "^2.0.1",
"@bentley/ecdb-map-schema": "^2.0.4",
"@bentley/ecdb-schema-policies-schema": "^1.0.1",
"@bentley/formats-schema": "^1.0.0",
"@bentley/linear-referencing-schema": "^2.0.3",
Expand Down Expand Up @@ -81,4 +88,4 @@
"extends": "./node_modules/@itwin/build-tools/.nycrc",
"sourceMap": false
}
}
}
75 changes: 59 additions & 16 deletions core/ecschema-locaters/src/SchemaXmlFileLocater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import * as path from "path";
import * as fs from "fs";
import { DOMParser } from "@xmldom/xmldom";
import {
ECObjectsError, ECObjectsStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType, SchemaReadHelper, XmlParser,
Expand Down Expand Up @@ -133,35 +134,77 @@ export class SchemaXmlFileLocater extends SchemaFileLocater implements ISchemaLo
export class BackendSchemasXmlFileLocater extends SchemaXmlFileLocater implements ISchemaLocater {
private _standardSchemaSearchPaths: Set<string>;

public constructor(assetsDir: string) {
public static defaultSchemaSearchPaths = new Set([
// Dgn schemas
path.join(__dirname, "..", "..", "node_modules", "@bentley", "bis-core-schema"),
path.join(__dirname, "..", "..", "node_modules", "@bentley", "generic-schema"),
// Domain schemas
path.join(__dirname, "..", "..", "node_modules", "@bentley", "analytical-schema"),
path.join(__dirname, "..", "..", "node_modules", "@bentley", "functional-schema"),
path.join(__dirname, "..", "..", "node_modules", "@bentley", "linear-referencing-schema"),
path.join(__dirname, "..", "..", "node_modules", "@bentley", "physical-material-schema"),
path.join(__dirname, "..", "..", "node_modules", "@bentley", "presentation-rules-schema"),
// ECDb schemas
path.join(__dirname, "..", "..", "node_modules", "@bentley", "ecdb-file-info-schema"),
path.join(__dirname, "..", "..", "node_modules", "@bentley", "ecdb-map-schema"),
path.join(__dirname, "..", "..", "node_modules", "@bentley", "ecdb-meta-schema"),
path.join(__dirname, "..", "..", "node_modules", "@bentley", "ecdb-schema-policies-schema"),
// Standard schemas
path.join(__dirname, "..", "..", "node_modules", "@bentley", "bis-custom-attributes-schema"),
path.join(__dirname, "..", "..", "node_modules", "@bentley", "core-custom-attributes-schema"),
path.join(__dirname, "..", "..", "node_modules", "@bentley", "formats-schema"),
path.join(__dirname, "..", "..", "node_modules", "@bentley", "schema-upgrade-custom-attributes-schema"),
path.join(__dirname, "..", "..", "node_modules", "@bentley", "units-schema"),
// Misc schemas
path.join(__dirname, "..", "..", "node_modules", "@bentley", "aec-units-schema"),
path.join(__dirname, "..", "..", "node_modules", "@bentley", "architectural-physical-schema"),
path.join(__dirname, "..", "..", "node_modules", "@bentley", "construction-schema"),
path.join(__dirname, "..", "..", "node_modules", "@bentley", "plant-custom-attributes-schema"),
path.join(__dirname, "..", "..", "node_modules", "@bentley", "quantity-takeoffs-aspects-schema"),
path.join(__dirname, "..", "..", "node_modules", "@bentley", "spatial-composition-schema"),
path.join(__dirname, "..", "..", "node_modules", "@bentley", "structural-physical-schema"),
]);

/**
* Constructs a new BackendSchemasXmlFileLocater
* @param knownBackendAssetsDir The assets directory where the core-backend package is installed.
*/
public constructor(knownBackendAssetsDir?: string) {
super();
// Pre-defined set of standard schema search paths
this._standardSchemaSearchPaths = new Set([
path.join(assetsDir, "ECSchemas", "Dgn"),
path.join(assetsDir, "ECSchemas", "Domain"),
path.join(assetsDir, "ECSchemas", "ECDb"),
path.join(assetsDir, "ECSchemas", "Standard"),
]);

this.searchPaths.push(...Array.from(this._standardSchemaSearchPaths));

// The precedence of the standard schema search paths is set to the lower priority of 1
// This is to ensure that user-defined search paths have higher precedence which will be set with the priority of 0

if (!knownBackendAssetsDir) {
this._standardSchemaSearchPaths = BackendSchemasXmlFileLocater.defaultSchemaSearchPaths;
} else {
// Pre-defined set of standard schema search paths
this._standardSchemaSearchPaths = new Set([
path.join(knownBackendAssetsDir, "ECSchemas", "Dgn"),
path.join(knownBackendAssetsDir, "ECSchemas", "Domain"),
path.join(knownBackendAssetsDir, "ECSchemas", "ECDb"),
path.join(knownBackendAssetsDir, "ECSchemas", "Standard"),
]);
}

this._standardSchemaSearchPaths.forEach((schemaPath) => {
this.searchPathPrecedence.set(schemaPath, 1);
if (fs.existsSync(schemaPath)) {
this.searchPaths.push(schemaPath);

// The precedence of the standard schema search paths is set to the lower priority of 1
// This is to ensure that user-defined search paths have higher precedence which will be set with the priority of 0
this.searchPathPrecedence.set(schemaPath, 1);
}
});
}

/**
* Add one search path used by this locator to find the Schema files.
* Add one search path to be used by this locator to find the Schema files.
* @param schemaPath A search path to add
*/
public override addSchemaSearchPath(schemaPath: string): void {
this.addSchemaSearchPaths([schemaPath]);
}

/**
* Adds more search paths used by this locator to find the Schema files.
* Adds more search paths to be used by this locator to find the Schema files.
* @param schemaPaths An array of search paths to add
*/
public override addSchemaSearchPaths(schemaPaths: string[]): void {
Expand Down
Loading

0 comments on commit fee9279

Please sign in to comment.