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 all 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 @@ -8,7 +8,9 @@ import {
type JayveeServices,
type TypedConstraintDefinition,
createJayveeServices,
isTypedConstraintDefinition,
} from '@jvalue/jayvee-language-server';
import { extractTestElements } from '@jvalue/jayvee-language-server/test';
import {
type ParseHelperOptions,
expectNoParserAndLexerErrors,
Expand Down Expand Up @@ -51,10 +53,12 @@ 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;

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const constraint = extractTestElements(
document,
(x): x is TypedConstraintDefinition => isTypedConstraintDefinition(x),
)[0]!;

return new AllowlistConstraintExecutor().isValid(
value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import {
type JayveeServices,
type TypedConstraintDefinition,
createJayveeServices,
isTypedConstraintDefinition,
} from '@jvalue/jayvee-language-server';
import {
type ParseHelperOptions,
expectNoParserAndLexerErrors,
extractTestElements,
parseHelper,
readJvTestAssetHelper,
} from '@jvalue/jayvee-language-server/test';
Expand Down Expand Up @@ -51,10 +53,12 @@ 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;

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const constraint = extractTestElements(
document,
(x): x is TypedConstraintDefinition => isTypedConstraintDefinition(x),
)[0]!;

return new DenylistConstraintExecutor().isValid(
value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import {
type InternalValueRepresentation,
type JayveeServices,
createJayveeServices,
isExpressionConstraintDefinition,
} from '@jvalue/jayvee-language-server';
import {
type ParseHelperOptions,
expectNoParserAndLexerErrors,
extractTestElements,
parseHelper,
readJvTestAssetHelper,
} from '@jvalue/jayvee-language-server/test';
Expand Down Expand Up @@ -51,10 +53,13 @@ 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;

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const constraint = extractTestElements(
document,
(x): x is ExpressionConstraintDefinition =>
isExpressionConstraintDefinition(x),
)[0]!;

return new ExpressionConstraintExecutor(constraint).isValid(
value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import {
type JayveeServices,
type TypedConstraintDefinition,
createJayveeServices,
isTypedConstraintDefinition,
} from '@jvalue/jayvee-language-server';
import {
type ParseHelperOptions,
expectNoParserAndLexerErrors,
extractTestElements,
parseHelper,
readJvTestAssetHelper,
} from '@jvalue/jayvee-language-server/test';
Expand Down Expand Up @@ -51,10 +53,12 @@ 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;

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const constraint = extractTestElements(
document,
(x): x is TypedConstraintDefinition => isTypedConstraintDefinition(x),
)[0]!;

return new LengthConstraintExecutor().isValid(
value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import {
type TypedConstraintDefinition,
createJayveeServices,
initializeWorkspace,
isTypedConstraintDefinition,
} from '@jvalue/jayvee-language-server';
import {
type ParseHelperOptions,
expectNoParserAndLexerErrors,
extractTestElements,
parseHelper,
readJvTestAssetHelper,
} from '@jvalue/jayvee-language-server/test';
Expand Down Expand Up @@ -52,10 +54,12 @@ 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;

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const constraint = extractTestElements(
document,
(x): x is TypedConstraintDefinition => isTypedConstraintDefinition(x),
)[0]!;

return new RangeConstraintExecutor().isValid(
value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import {
type JayveeServices,
type TypedConstraintDefinition,
createJayveeServices,
isTypedConstraintDefinition,
} from '@jvalue/jayvee-language-server';
import {
type ParseHelperOptions,
expectNoParserAndLexerErrors,
extractTestElements,
parseHelper,
readJvTestAssetHelper,
} from '@jvalue/jayvee-language-server/test';
Expand Down Expand Up @@ -51,10 +53,12 @@ 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;

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const constraint = extractTestElements(
document,
(x): x is TypedConstraintDefinition => isTypedConstraintDefinition(x),
)[0]!;

return new RegexConstraintExecutor().isValid(
value,
Expand Down
11 changes: 7 additions & 4 deletions libs/execution/src/lib/transforms/transform-executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import {
type JayveeServices,
type TransformDefinition,
createJayveeServices,
isTransformDefinition,
} from '@jvalue/jayvee-language-server';
import {
type ParseHelperOptions,
expectNoParserAndLexerErrors,
extractTestElements,
loadTestExtensions,
parseHelper,
readJvTestAssetHelper,
Expand Down Expand Up @@ -77,10 +79,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;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const transform = extractTestElements(
document,
(x): x is TransformDefinition => isTransformDefinition(x),
)[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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
//
// 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 TestSheetLoader {
publish builtin blocktype TestSheetLoader {
input inPort oftype Sheet;
output outPort oftype None;
}

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

builtin blocktype TestSheetExtractor {
publish builtin blocktype TestSheetExtractor {
input inPort oftype None;
output outPort oftype Sheet;
}

builtin blocktype TestSheetLoader {
publish builtin blocktype TestSheetLoader {
input inPort oftype Sheet;
output outPort oftype None;
}

builtin blocktype TestTextFileExtractor {
publish builtin blocktype TestTextFileExtractor {
input inPort oftype None;
output outPort oftype TextFile;
}

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

builtin blocktype TestWorkbookExtractor {
publish builtin blocktype TestWorkbookExtractor {
input inPort oftype None;
output outPort oftype Workbook;
}

builtin blocktype TestWorkbookLoader {
publish builtin blocktype TestWorkbookLoader {
input inPort oftype Workbook;
output outPort oftype None;
}

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

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