Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions schema/out/ts/ifcx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export interface components {
[key: string]: components["schemas"]["IfcxSchema"];
};
data: components["schemas"]["IfcxNode"][];
// hack hack hack
src?: string;
};
IfcxHeader: {
id: string;
Expand Down
4 changes: 3 additions & 1 deletion src/ifcx-core/layers/layer-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,15 @@ export class IfcxLayerStackBuilder
private async SatisfyDependencies(activeLayer: IfcxFile, placed: Map<string, boolean>, orderedLayers: IfcxFile[])
{
let pending: IfcxFile[] = [];
for (const impt of activeLayer.imports) {
for (const impt of activeLayer.imports || []) {
if (!placed.has(impt.uri))
{
let layer = await this.provider.GetLayerByURI(impt.uri);
if (layer instanceof Error)
{
return layer;
} else {
layer.src = impt.uri;
}
pending.push(layer);
placed.set(impt.uri, true);
Expand Down
24 changes: 22 additions & 2 deletions src/ifcx-core/workflows.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FlattenCompositionInput, CreateArtificialRoot, ExpandFirstRootInInput } from "./composition/compose";
import { CompositionInputNode } from "./composition/node";
import { IfcxFile, IfcxNode, ImportNode } from "./schema/schema-helper";
import { Validate } from "./schema/schema-validation";
import { SchemaValidationError, Validate } from "./schema/schema-validation";
import { MMSet } from "./util/mm";

function ToInputNodes(data: IfcxNode[])
Expand Down Expand Up @@ -151,7 +151,7 @@ export function Diff(file1: IfcxFile, file2: IfcxFile)
return result;
}

export function Federate(files: IfcxFile[])
export function Federate(files: IfcxFile[], acceptDuplicateSchemas: boolean = false)
{
if (files.length === 0)
{
Expand All @@ -165,6 +165,26 @@ export function Federate(files: IfcxFile[])
data: []
};

if (!acceptDuplicateSchemas) {
files.forEach((file) => {
// @todo not very efficient in case of deep import trees
const localSchemas = new Set(Object.keys(file.schemas));
const importedSchemas : Set<String> = new Set();
const recurse = (uri : string) => {
files.filter(f => f.src == uri).forEach(f => {
Object.keys(f.schemas).forEach(s => importedSchemas.add(s));
f.imports.map(i => i.uri).forEach(recurse);
});
};
file.imports.map(i => i.uri).forEach(recurse);
for (let s of localSchemas) {
if (importedSchemas.has(s)) {
throw new SchemaValidationError(`Imported schema '${s}' also defined in base layer`);
}
}
})
}

files.forEach((file) => {
Object.keys(file.schemas).forEach((schemaID) => result.schemas[schemaID] = file.schemas[schemaID]);
})
Expand Down