Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New schema locater to locate the standard schemas delivered as part of the core-backend package #7347

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d7e4797
Added new loacter for xml files
RohitPtnkr1996 Nov 12, 2024
aca1529
Updated schema xml file logic
RohitPtnkr1996 Nov 12, 2024
6976e06
Merge branch 'master' into rohitptnkr/backend-schemas-file-locater
RohitPtnkr1996 Nov 14, 2024
163b457
Adding new schema xml string locater
RohitPtnkr1996 Nov 14, 2024
41a7e7b
Merge branch 'master' into rohitptnkr/backend-schemas-file-locater
RohitPtnkr1996 Nov 14, 2024
dd2b175
Merge branch 'master' into rohitptnkr/backend-schemas-file-locater
RohitPtnkr1996 Nov 14, 2024
804024b
Merge branch 'master' into rohitptnkr/backend-schemas-file-locater
RohitPtnkr1996 Nov 15, 2024
fee9279
Added more logic
RohitPtnkr1996 Nov 15, 2024
1eccfb5
Revert "Added more logic"
RohitPtnkr1996 Nov 15, 2024
adbc79b
Merge branch 'rohitptnkr/backend-schemas-file-locater' of https://git…
RohitPtnkr1996 Nov 15, 2024
ce0f02d
Added more logic
RohitPtnkr1996 Nov 15, 2024
d01786a
Added new locater for json files, cleaned up code and added tests.
RohitPtnkr1996 Nov 15, 2024
5dc2b02
Added changelog
RohitPtnkr1996 Nov 15, 2024
c56af1d
Fixed linting error
RohitPtnkr1996 Nov 15, 2024
df25062
Removed only from test function
RohitPtnkr1996 Nov 15, 2024
fa72fae
Merge branch 'master' into rohitptnkr/backend-schemas-file-locater
RohitPtnkr1996 Nov 18, 2024
3ede031
Merge branch 'master' into rohitptnkr/backend-schemas-file-locater
RohitPtnkr1996 Nov 25, 2024
9e85416
Merge branch 'master' into rohitptnkr/backend-schemas-file-locater
RohitPtnkr1996 Nov 29, 2024
dace842
Added glob to get default schema paths
RohitPtnkr1996 Nov 29, 2024
300cf1b
Updated api signatures
RohitPtnkr1996 Nov 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions common/api/ecschema-locaters.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,29 @@ export class FileSchemaKey extends SchemaKey {
schemaText?: string;
}

// @beta
export class PublishedSchemaJsonFileLocater extends SchemaJsonFileLocater implements ISchemaLocater {
constructor();
addSchemaSearchPath(schemaPath: string): void;
addSchemaSearchPaths(schemaPaths: string[]): void;
}

// @beta
export class PublishedSchemaXmlFileLocater extends SchemaXmlFileLocater implements ISchemaLocater {
constructor(knownBackendAssetsDir?: string);
addSchemaSearchPath(schemaPath: string): void;
addSchemaSearchPaths(schemaPaths: string[]): void;
}

// @beta
export class PublishedSchemaXmlStringLocater extends SchemaXmlStringLocater implements ISchemaLocater {
constructor(knownBackendAssetsDir?: string);
addSchemaString(schemaString: string): void;
addSchemaStrings(schemaStrings: string[]): void;
// (undocumented)
static defaultSchemaSearchPaths: Set<string>;
}

// @beta
export abstract class SchemaFileLocater {
constructor();
Expand All @@ -40,6 +63,8 @@ export abstract class SchemaFileLocater {
// (undocumented)
readUtf8FileToStringSync(filePath: string): string | undefined;
// (undocumented)
protected searchPathPrecedence: Map<string, number>;
// (undocumented)
searchPaths: string[];
}

Expand Down
3 changes: 3 additions & 0 deletions common/api/summary/ecschema-locaters.exports.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
sep=;
Release Tag;API Item Type;API Item Name
beta;class;FileSchemaKey
beta;class;PublishedSchemaJsonFileLocater
beta;class;PublishedSchemaXmlFileLocater
beta;class;PublishedSchemaXmlStringLocater
beta;class;SchemaFileLocater
beta;class;SchemaJsonFileLocater
beta;namespace;SchemaXml
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/ecschema-locaters",
"comment": "Implemented new schema locaters PublishedSchemaXmlFileLocater, PublishedSchemaXmlStringLocater, PublishedSchemaJsonFileLocater that will locate/load schemas from published schema xml/json files.",
"type": "none"
}
],
"packageName": "@itwin/ecschema-locaters"
}
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.

2 changes: 1 addition & 1 deletion core/ecschema-locaters/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ Tue, 17 Oct 2023 15:14:32 GMT

### Updates

- Expose the SchemaFileUtility class to allow users to export in memory Schemas to xml files.
- Expose the SchemaFileUtility class to allow users to export in memory Schemas to xml files.
- extract-api run
- Export SchemaFileUtility and make beta
- Change SchemaFileUtility class to SchemaXml namespace, update class names
Expand Down
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
}
}
}
1 change: 1 addition & 0 deletions core/ecschema-locaters/src/SchemaFileLocater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class FileSchemaKey extends SchemaKey {
*/
export abstract class SchemaFileLocater {
public searchPaths: string[];
protected searchPathPrecedence = new Map<string, number>();

constructor() {
this.searchPaths = [];
Expand Down
47 changes: 47 additions & 0 deletions core/ecschema-locaters/src/SchemaJsonFileLocater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
ECObjectsError, ECObjectsStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType,
} from "@itwin/ecschema-metadata";
import { FileSchemaKey, SchemaFileLocater } from "./SchemaFileLocater";
import { globSync } from "glob";

/**
* A SchemaLocator implementation for locating JSON Schema files
Expand Down Expand Up @@ -116,3 +117,49 @@ export class SchemaJsonFileLocater extends SchemaFileLocater implements ISchemaL
return schema as T;
}
}

/**
* A SchemaLocator implementation for locating JSON Schema files
* from the file system using configurable search paths.
* @beta This is a workaround the current lack of a full xml parser.
*/
export class PublishedSchemaJsonFileLocater extends SchemaJsonFileLocater implements ISchemaLocater {
public constructor() {
super();

globSync(path.join(__dirname, "..", "..", "node_modules", "@bentley", "*-schema"), { windowsPathsNoEscape: true }).forEach((schemaPath) => {
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 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 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 {
// Add a schema path if it doesn't exist in the locater's search paths
schemaPaths.forEach((schemaPath) => {
if (!this.searchPaths.includes(schemaPath) && !this.searchPaths.includes(`\\\\?\\${schemaPath}`)) {
this.searchPaths.push(schemaPath);

// User defined search paths have the highesh precendence/priority of 0
if (this.searchPathPrecedence.get(schemaPath) === undefined)
this.searchPathPrecedence.set(schemaPath, 0);
}
});
}
}
1 change: 1 addition & 0 deletions core/ecschema-locaters/src/SchemaStringLocater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class StringSchemaKey extends SchemaKey {
*/
export abstract class SchemaStringLocater {
public schemaStrings: string[];
protected searchPathPrecedence = new Map<string, number>();

constructor() {
this.schemaStrings = [];
Expand Down
Loading