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

Add publish keyword #571

Merged
merged 19 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
78706d2
Introduce `publish` keyword and adapt scoping
georg-schwarz May 22, 2024
ca8cee6
Refactor scoping to only import exported elements
georg-schwarz May 23, 2024
01ca888
Add scoping behavior for delayed export statements
georg-schwarz May 23, 2024
9b6861f
Remove unnecessary recursion in followExportDefinitionChain
georg-schwarz May 23, 2024
48df33a
Add validation for import cycles
georg-schwarz May 23, 2024
dd29b3b
Show dependency cycle to user in validation
georg-schwarz May 23, 2024
5aceb98
Add license information to newly added test files
georg-schwarz May 23, 2024
15eeb73
Remove outdated TODO comment
georg-schwarz May 23, 2024
11e2f24
Update documentation of followExportDefinitionChain method
georg-schwarz May 23, 2024
b94c29c
Fix followExportDefinitionChain
georg-schwarz May 23, 2024
4fef7c4
Refactor export mechanism to have a common grammar element instead of…
georg-schwarz May 24, 2024
5e9aba2
Fix typo in JayveeScopeProvider
georg-schwarz May 26, 2024
2a1c5e7
Document import and export feature
georg-schwarz May 26, 2024
d7ef7ec
Add caching to document-based scoping
georg-schwarz May 26, 2024
a197d1a
Remove outdated TODO comment
georg-schwarz May 26, 2024
3db1d0e
Fix expect in executeExpressionTestHelper
georg-schwarz May 28, 2024
279300d
Pull out test helper function extractTestElements
georg-schwarz May 28, 2024
99dcda2
Move extractTestElements to @language-server/test
georg-schwarz May 28, 2024
5a5ea86
Use extractTestElements in execution lib
georg-schwarz May 28, 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
41 changes: 38 additions & 3 deletions apps/docs/docs/user/core-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pipeline CarsPipeline {
A _block_ is a processing step within a _pipeline_.
It can have a default input and a default output.
We differentiate the following types of _blocks_:

- _Extractor blocks_ do not have a default input but only a default output. They model a **data source**.
- _Transformator blocks_ have a default input and a default output. They model a **transformation**.
- _Loader blocks_ do have a default input but nor a default output. They model a **data sink**.
Expand All @@ -49,7 +50,7 @@ The availability of property keys and their respective _value types_ is determin
block GasReserveHttpExtractor oftype HttpExtractor {
// key: value
url: "https://www.bundesnetzagentur.de/_tools/SVG/js2/_functions/csv_export.html?view=renderCSV&id=1089590";
}
}
```

In the example above, the `url` property of type `text` is defined by the corresponding `HttpExtractor` _block type_.
Expand All @@ -61,10 +62,11 @@ _Blocks_ can be either defined as part of the language, called _built-in_ or def
A _value type_ is the definition of a data type of the processed data.
Some _blocks_ use _value types_ to define logic (like filtering or assessing the data type in a data sink).
We differentiate the following kinds of _value types_:

- _Built-in value types_ come with the basic version of Jayvee. See [built-in value types](./value-types/built-in-value-types).
- _Primitive value types_ can be defined by the user to model domain-specific data types and represent a single value.
_Constraints_ can be added to a _primitive value types_.
See [primitive value types](./value-types/primitive-value-types).
See [primitive value types](./value-types/primitive-value-types).
- _Compound value types_: UPCOMING.

```jayvee
Expand All @@ -77,6 +79,7 @@ constraint GasFillLevelRange on decimal:
```

## Transforms

_Transforms_ are used to transform data from one _value type_ to a different one. For more details, see [transforms](./transforms.md).

```jayvee
Expand All @@ -86,4 +89,36 @@ transform CelsiusToKelvin {

tempKelvin: tempCelsius + 273.15;
}
```
```

## Publishing / using model elements

If you want to use a model element in a different file other than the one you define it, you need to _publish_ and _use_ it.

1. Publish the element to make it usable in other files.

```jayvee
// Either publish right away when defining an element
publish constraint GasFillLevelRange on decimal:
value >= 0 and value <= 100;

// Or define first and publish separately
constraint GasFillLevelRange on decimal:
value >= 0 and value <= 100;

publish GasFillLevelRange;
```

2. Use the element in another file

```jayvee
// Define from where you want to take elements
use * from './relative/path/to/file.jv';

// Then just use them as if they were defined on root level
valuetype GasFillLevel oftype integer {
constraints: [ GasFillLevelRange ]; // GasFillLevelRange is defined in another file
}
```

Currently, only root-level elements can be published, so elements defined within a pipeline cannot be used in other files.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
type BlockDefinition,
type InternalValueRepresentation,
type JayveeServices,
type TypedConstraintDefinition,
createJayveeServices,
isTypedConstraintDefinition,
} from '@jvalue/jayvee-language-server';
import {
type ParseHelperOptions,
Expand All @@ -18,6 +18,7 @@ import {
import {
type AstNode,
type AstNodeLocator,
AstUtils,
type LangiumDocument,
} from 'langium';
import { NodeFileSystem } from 'langium/node';
Expand Down Expand Up @@ -51,10 +52,15 @@ describe('Validation of AllowlistConstraintExecutor', () => {
document.parseResult.value,
'pipelines@0/blocks@2',
) as BlockDefinition;
const constraint = locator.getAstNode<TypedConstraintDefinition>(
document.parseResult.value,
'constraints@0',
) as TypedConstraintDefinition;

const allElements = AstUtils.streamAllContents(document.parseResult.value);
const allConstraints = [...allElements.filter(isTypedConstraintDefinition)];
expect(
allConstraints.length > 0,
'No constraint definition found in test file',
);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const constraint = allConstraints[0]!;

return new AllowlistConstraintExecutor().isValid(
value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
type BlockDefinition,
type InternalValueRepresentation,
type JayveeServices,
type TypedConstraintDefinition,
createJayveeServices,
isTypedConstraintDefinition,
} from '@jvalue/jayvee-language-server';
import {
type ParseHelperOptions,
Expand All @@ -18,6 +18,7 @@ import {
import {
type AstNode,
type AstNodeLocator,
AstUtils,
type LangiumDocument,
} from 'langium';
import { NodeFileSystem } from 'langium/node';
Expand Down Expand Up @@ -51,10 +52,15 @@ describe('Validation of DenylistConstraintExecutor', () => {
document.parseResult.value,
'pipelines@0/blocks@2',
) as BlockDefinition;
const constraint = locator.getAstNode<TypedConstraintDefinition>(
document.parseResult.value,
'constraints@0',
) as TypedConstraintDefinition;

const allElements = AstUtils.streamAllContents(document.parseResult.value);
const allConstraints = [...allElements.filter(isTypedConstraintDefinition)];
expect(
allConstraints.length > 0,
'No constraint definition found in test file',
);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const constraint = allConstraints[0]!;

return new DenylistConstraintExecutor().isValid(
value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import {
type BlockDefinition,
type ExpressionConstraintDefinition,
type InternalValueRepresentation,
type JayveeServices,
createJayveeServices,
isExpressionConstraintDefinition,
} from '@jvalue/jayvee-language-server';
import {
type ParseHelperOptions,
Expand All @@ -18,6 +18,7 @@ import {
import {
type AstNode,
type AstNodeLocator,
AstUtils,
type LangiumDocument,
} from 'langium';
import { NodeFileSystem } from 'langium/node';
Expand Down Expand Up @@ -51,10 +52,17 @@ describe('Validation of AllowlistConstraintExecutor', () => {
document.parseResult.value,
'pipelines@0/blocks@2',
) as BlockDefinition;
const constraint = locator.getAstNode<ExpressionConstraintDefinition>(
document.parseResult.value,
'constraints@0',
) as ExpressionConstraintDefinition;

const allElements = AstUtils.streamAllContents(document.parseResult.value);
const allConstraints = [
...allElements.filter(isExpressionConstraintDefinition),
];
expect(
allConstraints.length > 0,
'No constraint definition found in test file',
);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const constraint = allConstraints[0]!;

return new ExpressionConstraintExecutor(constraint).isValid(
value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
type BlockDefinition,
type InternalValueRepresentation,
type JayveeServices,
type TypedConstraintDefinition,
createJayveeServices,
isTypedConstraintDefinition,
} from '@jvalue/jayvee-language-server';
import {
type ParseHelperOptions,
Expand All @@ -18,6 +18,7 @@ import {
import {
type AstNode,
type AstNodeLocator,
AstUtils,
type LangiumDocument,
} from 'langium';
import { NodeFileSystem } from 'langium/node';
Expand Down Expand Up @@ -51,10 +52,15 @@ describe('Validation of LengthConstraintExecutor', () => {
document.parseResult.value,
'pipelines@0/blocks@2',
) as BlockDefinition;
const constraint = locator.getAstNode<TypedConstraintDefinition>(
document.parseResult.value,
'constraints@0',
) as TypedConstraintDefinition;

const allElements = AstUtils.streamAllContents(document.parseResult.value);
const allConstraints = [...allElements.filter(isTypedConstraintDefinition)];
expect(
allConstraints.length > 0,
'No constraint definition found in test file',
);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const constraint = allConstraints[0]!;

return new LengthConstraintExecutor().isValid(
value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
type BlockDefinition,
type InternalValueRepresentation,
type JayveeServices,
type TypedConstraintDefinition,
createJayveeServices,
initializeWorkspace,
isTypedConstraintDefinition,
} from '@jvalue/jayvee-language-server';
import {
type ParseHelperOptions,
Expand All @@ -19,6 +19,7 @@ import {
import {
type AstNode,
type AstNodeLocator,
AstUtils,
type LangiumDocument,
} from 'langium';
import { NodeFileSystem } from 'langium/node';
Expand Down Expand Up @@ -52,10 +53,15 @@ describe('Validation of RangeConstraintExecutor', () => {
document.parseResult.value,
'pipelines@0/blocks@2',
) as BlockDefinition;
const constraint = locator.getAstNode<TypedConstraintDefinition>(
document.parseResult.value,
'constraints@0',
) as TypedConstraintDefinition;

const allElements = AstUtils.streamAllContents(document.parseResult.value);
georg-schwarz marked this conversation as resolved.
Show resolved Hide resolved
const allConstraints = [...allElements.filter(isTypedConstraintDefinition)];
expect(
allConstraints.length > 0,
'No constraint definition found in test file',
);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const constraint = allConstraints[0]!;

return new RangeConstraintExecutor().isValid(
value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
type BlockDefinition,
type InternalValueRepresentation,
type JayveeServices,
type TypedConstraintDefinition,
createJayveeServices,
isTypedConstraintDefinition,
} from '@jvalue/jayvee-language-server';
import {
type ParseHelperOptions,
Expand All @@ -18,6 +18,7 @@ import {
import {
type AstNode,
type AstNodeLocator,
AstUtils,
type LangiumDocument,
} from 'langium';
import { NodeFileSystem } from 'langium/node';
Expand Down Expand Up @@ -51,10 +52,15 @@ describe('Validation of RegexConstraintExecutor', () => {
document.parseResult.value,
'pipelines@0/blocks@2',
) as BlockDefinition;
const constraint = locator.getAstNode<TypedConstraintDefinition>(
document.parseResult.value,
'constraints@0',
) as TypedConstraintDefinition;

const allElements = AstUtils.streamAllContents(document.parseResult.value);
const allConstraints = [...allElements.filter(isTypedConstraintDefinition)];
expect(
allConstraints.length > 0,
'No constraint definition found in test file',
);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const constraint = allConstraints[0]!;

return new RegexConstraintExecutor().isValid(
value,
Expand Down
12 changes: 7 additions & 5 deletions libs/execution/src/lib/transforms/transform-executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import path from 'node:path';
import {
type InternalValueRepresentation,
type JayveeServices,
type TransformDefinition,
createJayveeServices,
isTransformDefinition,
} from '@jvalue/jayvee-language-server';
import {
type ParseHelperOptions,
Expand All @@ -22,6 +22,7 @@ import {
import {
type AstNode,
type AstNodeLocator,
AstUtils,
type LangiumDocument,
} from 'langium';
import { NodeFileSystem } from 'langium/node';
Expand Down Expand Up @@ -77,10 +78,11 @@ describe('Validation of TransformExecutor', () => {
const document = await parse(input, { validation: true });
expectNoParserAndLexerErrors(document);

const transform = locator.getAstNode<TransformDefinition>(
document.parseResult.value,
'transforms@0',
) as TransformDefinition;
const allElements = AstUtils.streamAllContents(document.parseResult.value);
const allTransforms = [...allElements.filter(isTransformDefinition)];
expect(allTransforms.length > 0);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const transform = allTransforms[0]!;

const executionContext = getTestExecutionContext(
locator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
//
// SPDX-License-Identifier: AGPL-3.0-only

builtin blocktype TestFileExtractor {
publish builtin blocktype TestFileExtractor {
input inPort oftype None;
output outPort oftype File;
}

builtin blocktype TestFileLoader {
publish builtin blocktype TestFileLoader {
input inPort oftype File;
output outPort oftype None;
}

builtin blocktype TestTableLoader {
publish builtin blocktype TestTableLoader {
input inPort oftype Table;
output outPort oftype None;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: AGPL-3.0-only

builtin blocktype TestTableExtractor {
publish builtin blocktype TestTableExtractor {
input inPort oftype None;
output outPort oftype Table;
}
Loading
Loading