Skip to content

npm workspaces and bug fixes #912

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

Merged
merged 27 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
17,235 changes: 12,947 additions & 4,288 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion packages/concerto-core/lib/introspect/decorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,14 @@ class Decorator {
* @throws {IllegalModelException}
* @private
*/
validate() { }
validate() {
// check that all type ref arguments can be resolved
const typeRefs = this.arguments.filter(a => a?.type === 'Identifier');
typeRefs.forEach(typeRef => {
const mf = this.getParent().getModelFile();
mf.resolveType(`Decorator ${this.getName()} on ${this.getParent().getName()}`, typeRef.name);
});
}

/**
* Returns the name of a decorator
Expand Down
2 changes: 1 addition & 1 deletion packages/concerto-core/lib/introspect/modelfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ class ModelFile extends Decorated {

throw new IllegalModelException(formatter({
'type': type,
'imports': this.imports,
'imports': JSON.stringify(this.imports),
'namespace': this.getNamespace()
}),this);
}
Expand Down
15 changes: 15 additions & 0 deletions packages/concerto-core/test/data/decorators/categories-empty.cto
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace categories@1.0.0
17 changes: 17 additions & 0 deletions packages/concerto-core/test/data/decorators/categories.cto
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace categories@1.0.0

abstract concept Ok {}
20 changes: 20 additions & 0 deletions packages/concerto-core/test/data/decorators/invalid-typeref.cto
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace org.acme

@category(Missing)
asset Car identified by id {
o String id
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace org.acme@1.0.0

import categories@1.0.0.{Ok}

@category(Ok)
asset Car identified by id {
o String id
}
22 changes: 22 additions & 0 deletions packages/concerto-core/test/data/decorators/valid-typeref.cto
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace org.acme

abstract concept Ok {}

@category(Ok)
asset Car identified by id {
o String id
}
38 changes: 38 additions & 0 deletions packages/concerto-core/test/introspect/decorators.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,44 @@ describe('Decorators', () => {
modelManager.addCTOModel(modelDefinitions);
}).should.throw(/Duplicate decorator/);
});

it('should fail to validate type refs that are not defined locally', () => {

(() => {
const modelManager = new ModelManager();
Util.addComposerModel(modelManager);
let modelDefinitions = fs.readFileSync('test/data/decorators/invalid-typeref.cto', 'utf8');
modelManager.addCTOModel(modelDefinitions);
}).should.throw(/Undeclared type "Missing"/);
});

it('should fail to validate type refs that are not in imported namespace', () => {

(() => {
const modelManager = new ModelManager();
Util.addComposerModel(modelManager);
let modelDefinitions = fs.readFileSync('test/data/decorators/categories-empty.cto', 'utf8');
modelManager.addCTOModel(modelDefinitions);
modelDefinitions = fs.readFileSync('test/data/decorators/valid-typeref-imported.cto', 'utf8');
modelManager.addCTOModel(modelDefinitions);
}).should.throw(/Type "Ok" is not defined in namespace/);
});

it('should valdiate type refs that are defined locally', () => {
const modelManager = new ModelManager();
Util.addComposerModel(modelManager);
let modelDefinitions = fs.readFileSync('test/data/decorators/valid-typeref.cto', 'utf8');
modelManager.addCTOModel(modelDefinitions);
});

it('should valdiate type refs that are imported', () => {
const modelManager = new ModelManager();
Util.addComposerModel(modelManager);
let modelDefinitions = fs.readFileSync('test/data/decorators/categories.cto', 'utf8');
modelManager.addCTOModel(modelDefinitions);
modelDefinitions = fs.readFileSync('test/data/decorators/valid-typeref-imported.cto', 'utf8');
modelManager.addCTOModel(modelDefinitions);
});
});

describe('#factories', () => {
Expand Down
Loading