Skip to content

Commit

Permalink
clean up tests that write "extraction" files
Browse files Browse the repository at this point in the history
  * add a CLI util to generate "extractions"
  * Refactor type name SerializationModel -> SerializationChunk
  • Loading branch information
dslmeinte committed Aug 22, 2023
1 parent 2271d56 commit 9dbc8e1
Show file tree
Hide file tree
Showing 34 changed files with 247 additions and 5,653 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# IntelliJ IDEA:
/.idea
/lioncore-typescript.iml

# NPM (build):
/npm

# CLI
/lib/*

33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ The following is a list of links to potential starting points:
* [Models](models/) - various models in their serialized formats (the LIonWeb JSON format, or Ecore XML); see the [specific README](models/README.md).
* [Schemas](schemas/) - various JSON Schema files for validating models serialized in the LIonWeb JSON format against; see the [specific README](schemas/README.md).
* [Source](src/) - all TypeScript source to be exported as part of the NPM/Deno package.
* [Auxiliary](src-aux/) - all TypeScript source that's not core to the NPM/Deno package but still useful, e.g. for testing.
* [Scripts](src-build) - a `build-npm.ts` Deno script to package the source as an NPM package using [`dnt`](https://github.com/denoland/dnt).
* [Test sources](src-test/) - all TypeScript sources with/for (unit) tests.
Tests are located in files with names ending with `.test.ts`.
Expand All @@ -89,6 +90,7 @@ The following are considerations or concerns that bubbled up during implementati
* What happens during deserialization if things don't match the provided M2?
Just error out, or return `(model', issues*)`?


## Building an NPM Package

Run
Expand Down Expand Up @@ -120,3 +122,34 @@ Or, we can publish the package to the NPM registry with
```shell
pushd npm; npm publish; popd
```


## Extracting essential information from a serialization

Run

```shell
deno task compile-cli
```

to produce a binary executable `lib/extract-serialization` for your platform.

This you can then call to make "extractions" from a serialization ("chunk"), as follows (e.g.):

```shell
lib/extract-serialization models/meta/lioncore.json
```

This is meant as a way to inspect, reason about, and compare serialization because the format is rather verbose.
These extractions are:

* A "sorted" JSON with:
* all nodes sorted by ID,
* for all nodes, their properties, containments, and references sorted by key (from the meta-pointer),
* and all containments and references sorted by ID.
* A "shortened" JSON where keys are used as key names.
* If the serialization represents a language - i.e.: a LIonCore model - then a textual version is generated as well.

This CLI utility does not perform any explicit validation apart from the file at the given path existing and being valid JSON.
It does some implicit validation as it can error out on incorrect serializations.

38 changes: 22 additions & 16 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
{
"tasks": {
"run-tests": "deno test --allow-read --allow-write src-test/",
"watch-tests": "deno test --watch --allow-write --allow-read src-test/",
"lint": "deno lint src/ src-test/",
"lock-deps": "deno cache --reload --lock=deno.lock --lock-write src/deps.ts src-build/build-npm.ts src-test/deps.ts"
},
"lint": {
"include": [
"src/",
"src-build/",
"src-test/"
],
"rules": {
"tags": ["recommended"],
"exclude": ["no-explicit-any"]
}
"tasks": {
"run-tests": "deno test --allow-read --allow-write src-test/",
"watch-tests": "deno test --watch --allow-write --allow-read src-test/",
"lint": "deno lint src/ src-test/ src-aux/",
"lock-deps": "deno cache --reload --lock=deno.lock --lock-write src/deps.ts src-aux/deps.ts src-build/build-npm.ts src-test/deps.ts",
"compile-cli": "deno compile --allow-read --allow-write src-aux/extract-serialization.ts && mv extract-serialization lib/"
},
"lint": {
"include": [
"src/",
"src-aux/",
"src-build/",
"src-test/"
],
"rules": {
"tags": [
"recommended"
],
"exclude": [
"no-explicit-any"
]
}
}
}
48 changes: 39 additions & 9 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9dbc8e1

Please sign in to comment.