Skip to content

Commit

Permalink
Merge remote-tracking branch 'DevTest/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
A-M-A-X committed Jul 28, 2023
2 parents 9499a52 + c4b17b7 commit d705a2b
Show file tree
Hide file tree
Showing 70 changed files with 1,449 additions and 131 deletions.
3 changes: 3 additions & 0 deletions apps/docs/docs/user/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg
#
# SPDX-License-Identifier: AGPL-3.0-only
2 changes: 1 addition & 1 deletion apps/docs/docs/user/constraint-types/_category_.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"label": "Constraint Types",
"position": 4,
"position": 5,
"link": {
"type": "generated-index",
"description": "These constraints are shipped with Jayvee and are available right out of the box."
Expand Down
55 changes: 14 additions & 41 deletions apps/docs/docs/user/core-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,56 +81,29 @@ In the example above, the `url` property of type `text` is defined by the corres
A `ValueType` is the definition of a data type of the processed data.
Some `Blocks` use `ValueTypes` to define logic (like filtering or assessing the data type in a data sink).
We differentiate the following types of `ValueTypes`:
- `Built-in ValueTypes` come with the basic version of Jayvee.
Currently `text`, `decimal`, `integer`, and `boolean` are supported.
- `Built-in ValueTypes` come with the basic version of Jayvee. See [Built-in Valuetypes](./valuetypes/builtin-valuetypes).
- `Primitive ValueTypes` can be defined by the user to model domain-specific data types and represent a single value.
`Constraints` can be added to a `Primitive ValueType` (see [below](#constraints)).
`Constraints` can be added to a `Primitive ValueType`.
See [Primitive Valuetypes](./valuetypes/primitive-valuetypes).
- `Compound ValueTypes`: UPCOMING.

### Constraints

`Constraints` for `ValueTypes` declare the validity criteria that each concrete value is checked against.

#### Syntax 1: Expression syntax

The syntax of expression-based `Constraints` uses an expression that evaluates to `true` or `false` for the given `value`. The type of the values the expression is working in is indicated ofter the keyword `on`:

```jayvee
valuetype GasFillLevel oftype integer {
constraints: [ GasFillLevelRange ];
}
constraint GasFillLevelRange on decimal:
value >= 0 and value <= 100;
```

Refer to the [Expression documentation](./expressions.md) for further reading on expressions.


#### Syntax 2: Block-like syntax

The syntax of `Constraints` is similar to the syntax of `Blocks`.
The availability of property keys and their respective `ValueTypes` is determined by the type of the `Constraint` - indicated by the identifier after the keyword `oftype`:
## Transforms
`Transforms` are used to transform data from one `ValueType` to a different one. For more details, see [Transforms](./transforms.md).

```jayvee
constraint GasFillLevelRange oftype RangeConstraint {
lowerBound: 0;
lowerBoundInclusive: true;
upperBound: 100;
upperBoundInclusive: true;
}
```

Note that the type of `Constraint` also determines its applicability to `ValueTypes`.
For instance, a `RangeConstraint` can only be applied to the numerical types `integer` and `decimal`.

### Primitive ValueTypes

`Primitive ValueTypes` are based on `Built-in ValueTypes` and use a collection of constraints to restrict the range of valid values.
Such constraints are implicitly connected via a logical `AND` relation.
Note that the `Constraints` need to be applicable to the base-type of the `ValueType` - indicated by the identifier after the keyword `oftype`:
transform CelsiusToKelvin {
from tempCelsius oftype decimal;
to tempKelvin oftype decimal;
```jayvee
valuetype GasFillLevel oftype integer {
constraints: [ GasFillLevelRange ];
tempKelvin: tempCelsius + 273.15;
}
```

### Transforms
`Transforms` are used to transform data from one `ValueType` to a different one. For more details, see [Transforms](./transforms.md)
```
4 changes: 2 additions & 2 deletions apps/docs/docs/user/expressions.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 5
sidebar_position: 6
---

# Expressions
Expand All @@ -9,7 +9,7 @@ Expressions in Jayvee are arbitrarily nested statements. They consist of:
- variables (e.g., declared by `from` properties in [Transforms](./transforms.md))
- operators (e.g., `*` or `sqrt`)

Expressions get evaluated at runtime by the interpreter to a [Built-in ValueType](./core-concepts.md#valuetypes).
Expressions get evaluated at runtime by the interpreter to a [Built-in ValueType](./valuetypes/builtin-valuetypes).

### Example

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/docs/user/runtime-parameters.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 5
sidebar_position: 8
---

# Runtime Parameters
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/docs/user/transforms.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 4
sidebar_position: 7
---

# Transforms
Expand Down
5 changes: 5 additions & 0 deletions apps/docs/docs/user/valuetypes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg
#
# SPDX-License-Identifier: AGPL-3.0-only

builtin-valuetypes.md
8 changes: 8 additions & 0 deletions apps/docs/docs/user/valuetypes/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"label": "Valuetypes",
"position": 4,
"link": {
"type": "generated-index",
"description": "Jayvee supports these different kinds of valuetypes."
}
}
3 changes: 3 additions & 0 deletions apps/docs/docs/user/valuetypes/_category_.json.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg

SPDX-License-Identifier: AGPL-3.0-only
48 changes: 48 additions & 0 deletions apps/docs/docs/user/valuetypes/primitive-valuetypes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
sidebar_position: 2
---
# Primitive ValueTypes

`Primitive ValueTypes` are based on `Built-in ValueTypes` and use a collection of constraints to restrict the range of valid values.
Such constraints are implicitly connected via a logical `AND` relation.
Note that the `Constraints` need to be applicable to the base-type of the `ValueType` - indicated by the identifier after the keyword `oftype`:

```jayvee
valuetype GasFillLevel oftype integer {
constraints: [ GasFillLevelRange ];
}
```


## Constraints

`Constraints` for `ValueTypes` declare the validity criteria that each concrete value is checked against.

### Syntax 1: Expression syntax

The syntax of expression-based `Constraints` uses an expression that evaluates to `true` or `false` for the given `value`. The type of the values the expression is working in is indicated ofter the keyword `on`:

```jayvee
constraint GasFillLevelRange on decimal:
value >= 0 and value <= 100;
```

Refer to the [Expression documentation](../expressions.md) for further reading on expressions.


### Syntax 2: Block-like syntax

The syntax of `Constraints` is similar to the syntax of `Blocks`.
The availability of property keys and their respective `ValueTypes` is determined by the type of the `Constraint` - indicated by the identifier after the keyword `oftype`:

```jayvee
constraint GasFillLevelRange oftype RangeConstraint {
lowerBound: 0;
lowerBoundInclusive: true;
upperBound: 100;
upperBoundInclusive: true;
}
```

Note that the type of `Constraint` also determines its applicability to `ValueTypes`.
For instance, a `RangeConstraint` can only be applied to the numerical types `integer` and `decimal`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg

SPDX-License-Identifier: AGPL-3.0-only
15 changes: 15 additions & 0 deletions apps/docs/generator/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { join } from 'path';

import { StdLangExtension } from '@jvalue/jayvee-extensions/std/lang';
import {
PrimitiveValuetypes,
getRegisteredBlockMetaInformation,
getRegisteredConstraintMetaInformation,
registerConstraints,
Expand All @@ -21,6 +22,7 @@ function main(): void {
const rootPath = join(__dirname, '..', '..', '..', '..');
generateBlockTypeDocs(rootPath);
generateConstraintTypeDocs(rootPath);
generateValueTypeDocs(rootPath);
}

function generateBlockTypeDocs(rootPath: string): void {
Expand Down Expand Up @@ -69,4 +71,17 @@ function generateConstraintTypeDocs(rootPath: string): void {
}
}

function generateValueTypeDocs(rootPath: string): void {
const docsPath = join(rootPath, 'apps', 'docs', 'docs', 'user', 'valuetypes');
const userDocBuilder = new UserDocGenerator();
const valueTypeDoc =
userDocBuilder.generateValueTypesDoc(PrimitiveValuetypes);

const fileName = `builtin-valuetypes.md`;
writeFileSync(join(docsPath, fileName), valueTypeDoc, {
flag: 'w',
});
console.info(`Generated file ${fileName}`);
}

main();
63 changes: 62 additions & 1 deletion apps/docs/generator/src/user-doc-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,76 @@
//
// SPDX-License-Identifier: AGPL-3.0-only

import { strict as assert } from 'assert';

import {
BlockMetaInformation,
ConstraintMetaInformation,
ExampleDoc,
IOType,
JayveeBlockTypeDocGenerator,
JayveeConstraintTypeDocGenerator,
JayveeValueTypesDocGenerator,
MarkdownBuilder,
PrimitiveValuetype,
PropertySpecification,
} from '@jvalue/jayvee-language-server';

export class UserDocGenerator
implements JayveeBlockTypeDocGenerator, JayveeConstraintTypeDocGenerator
implements
JayveeBlockTypeDocGenerator,
JayveeConstraintTypeDocGenerator,
JayveeValueTypesDocGenerator
{
generateValueTypesDoc(valueTypes: {
[name: string]: PrimitiveValuetype;
}): string {
const builder = new UserDocMarkdownBuilder()
.docTitle('Built-in Valuetypes')
.generationComment()
.description(
`
For an introduction to valuetypes, see the [Core Concepts](../core-concepts).
Built-in valuetypes come with the basic version of Jayvee.
They are the basis for more restricted [Primitive Valuetypes](./primitive-valuetypes)
that fullfil [Constraints](./primitive-valuetypes#constraints).`.trim(),
1,
)
.heading('Available built-in valuetypes', 1);

Object.entries(valueTypes)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
.filter(([_, valueType]) => valueType.isUserExtendable())
.forEach(([name, valueType]) => {
assert(
valueType.getUserDoc(),
`Documentation is missing for user extendable value type: ${valueType.getName()}`,
);
builder
.heading(name, 2)
.description(valueType.getUserDoc() ?? '', 3)
.examples(
[
{
code: `
block ExampleTableInterpreter oftype TableInterpreter {
header: true;
columns: [
"columnName" oftype ${valueType.getName()}
];
}`.trim(),
description: `A block of type \`TableInterpreter\` that
interprets data in the column \`columnName\` as \`${valueType.getName()}\`.
`.trim(),
},
],
3,
);
});

return builder.build();
}

generateBlockTypeDoc(metaInf: BlockMetaInformation): string {
const builder = new UserDocMarkdownBuilder()
.docTitle(metaInf.type)
Expand Down Expand Up @@ -84,6 +140,11 @@ class UserDocMarkdownBuilder {
return this;
}

heading(heading: string, depth = 1): UserDocMarkdownBuilder {
this.markdownBuilder.heading(heading, depth);
return this;
}

propertyHeading(propertyName: string, depth = 1): UserDocMarkdownBuilder {
this.markdownBuilder.heading(`\`${propertyName}\``, depth);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export class StandardLibraryFileSystemProvider implements FileSystemProvider {
onDidChangeFile = this.didChangeFile.event;

constructor() {
this.registerStdLib();
}

private registerStdLib() {
Object.entries(StdLib).forEach(([libName, lib]) => {
this.libraries.set(
Uri.parse(libName).toString(), // removes slashes if missing authorities, required for matching later on
Expand Down
64 changes: 64 additions & 0 deletions libs/extensions/std/lang/src/gtfs-rt-interpreter-meta-inf.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg
//
// SPDX-License-Identifier: AGPL-3.0-only

import {
createJayveeServices,
useExtension,
} from '@jvalue/jayvee-language-server';
import {
TestLangExtension,
ValidationResult,
readJvTestAssetHelper,
validationHelper,
} from '@jvalue/jayvee-language-server/test';
import { AstNode } from 'langium';
import { NodeFileSystem } from 'langium/node';

import { StdLangExtension } from './extension';

describe('Validation of GtfsRTInterpreterMetaInformation', () => {
let validate: (input: string) => Promise<ValidationResult<AstNode>>;

const readJvTestAsset = readJvTestAssetHelper(__dirname, '../test/assets/');

beforeAll(() => {
// Register std extension
useExtension(new StdLangExtension());
// Register test extension
useExtension(new TestLangExtension());
// Create language services
const services = createJayveeServices(NodeFileSystem).Jayvee;
// Create validation helper for language services
validate = validationHelper(services);
});

it('should diagnose no error on valid entity parameter value', async () => {
const text = readJvTestAsset(
'gtfs-rt-interpreter-meta-inf/valid-valid-entity-param.jv',
);

const validationResult = await validate(text);
const diagnostics = validationResult.diagnostics;

expect(diagnostics).toHaveLength(0);
});

it('should diagnose error on invalid entity parameter value', async () => {
const text = readJvTestAsset(
'gtfs-rt-interpreter-meta-inf/invalid-invalid-entity-param.jv',
);

const validationResult = await validate(text);
const diagnostics = validationResult.diagnostics;

expect(diagnostics).toHaveLength(1);
expect(diagnostics).toEqual(
expect.arrayContaining([
expect.objectContaining({
message: 'Entity must be "trip_update", "alert" or "vehicle"',
}),
]),
);
});
});
Loading

0 comments on commit d705a2b

Please sign in to comment.