@architect/parser
Advanced tools
Comparing version 1.2.2 to 2.0.0
{ | ||
"name": "@architect/parser", | ||
"version": "1.2.2", | ||
"version": "2.0.0", | ||
"description": "Architect Parser accepts plaintext, JSON, or YAML .arc manifests and returns a plain JavaScript Object", | ||
"main": "index.js", | ||
"main": "./src/index.js", | ||
"scripts": { | ||
@@ -10,8 +10,14 @@ "lint": "npx eslint . --fix", | ||
"coverage": "nyc --reporter=lcov --reporter=text-summary npm run test:unit", | ||
"test": "npm run lint && npm run coverage", | ||
"_test": "npm run lint && npm run coverage", | ||
"test": "npm run lint && npm run test:unit", | ||
"rc": "npm version prerelease --preid RC" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/architect/parser.git" | ||
}, | ||
"author": "Brian LeRoux", | ||
"license": "Apache-2", | ||
"license": "Apache-2.0", | ||
"devDependencies": { | ||
"assert-diff": "^2.0.3", | ||
"codecov": "^3.6.1", | ||
@@ -21,5 +27,4 @@ "eslint": "^6.6.0", | ||
"tap-spec": "^5.0.0", | ||
"tape": "^4.11.0", | ||
"assert-diff": "^2.0.3" | ||
"tape": "^4.11.0" | ||
} | ||
} |
# [`@architect/parser`](https://www.npmjs.com/package/@architect/parser) [![GitHub CI status](https://github.com/architect/parser/workflows/Node%20CI/badge.svg)](https://github.com/architect/parser/actions?query=workflow%3A%22Node+CI%22) | ||
<!-- [![codecov](https://codecov.io/gh/architect/parser/branch/master/graph/badge.svg)](https://codecov.io/gh/architect/parser) --> | ||
> `.arc` is a simplistic text format for storing structured data; `@architect/parser` | ||
> is a function that accepts text and returns a plain JavaScript `Object` | ||
OpenJS Architect is an Infrastructure as Code (IaC) solution. The critical insight of *Infastructure as Code* is determinism. Infrastructure resources are defined in a declarative manifest file with the code that depends on them. This ensures deployment artifacts alway have the exact runtime resources expected for every version of the code. | ||
The format: | ||
Architect looks in the following places for the primary definition/configuration manifest file: | ||
- Starts with a `@section` | ||
- Sections start with `@` | ||
- Sections contain either scalar values, `Vector` or `Map` | ||
- Scalar values are either `String`, `Number` or `Boolean` | ||
- `Vector` values are space seperated scalar values on a single line | ||
- A `Map` is defined by a scalar value followed by Vectors indented two spaces | ||
- Comments follow `#` symbols | ||
- `.arc` | ||
- `app.arc` - [example](/examples/arc.arc) | ||
- `arc.json` - [example](/examples/arc.json) - [schema](https://arc.codes/schema.json) | ||
- `arc.yaml` - [example](/examples/arc.yaml) | ||
- `arc.toml` - [example](/examples/arc.toml) | ||
## Install | ||
> The `.arc` format is unique to Architect with many readability advantages; but is *not required* | ||
npm i @architect/parser | ||
--- | ||
# `.arc` | ||
> `.arc` is a text format for storing structured configuration data; it is not for serializing or transporting data | ||
The `.arc` format: | ||
- Comments follow `#` symbols | ||
- Top level keys start with `@` (example: `@pragma`) | ||
- Pragmas contain: scalar values or complex values | ||
- Scalar values are: `string`, `number` and `boolean` | ||
- Complex values are: `array`, `vector` and `map` | ||
- Whitespace is significant | ||
## Example | ||
@@ -33,6 +43,12 @@ | ||
@another-section-of-vectors | ||
@section-of-arrays | ||
vector of values | ||
vector tuple | ||
@vectors-section | ||
named | ||
vector | ||
of | ||
values | ||
@this-section-has-a-map | ||
@@ -43,12 +59,15 @@ hello-world | ||
Running the following inside nodejs: | ||
Parsing the file with the following code: | ||
```javascript | ||
var parser = require('@architect/parser') | ||
var fs = require('fs') | ||
var text = fs.readFileSync('./some-arc-file.txt').toString() | ||
var result = parse(text) | ||
#!/usr/bin/env node | ||
const parser = require('@architect/parser') | ||
const fs = require('fs') | ||
const text = fs.readFileSync('./some-arc-file.txt').toString() | ||
const result = parse(text) | ||
console.log(result) | ||
``` | ||
Would yield the following: | ||
Prints the following plain object to the console: | ||
@@ -63,6 +82,9 @@ ```javascript | ||
], | ||
"another-section-of-vectors": [ | ||
"section-of-arrays": [ | ||
["vector", "of", "values"], | ||
["vector", "tuple"] | ||
], | ||
"vectors-section": [ | ||
{named: ["vector", "of", "values"]}, | ||
], | ||
"this-section-has-a-map": [{ | ||
@@ -76,18 +98,8 @@ "hello-world": { | ||
## API | ||
Things to notice: | ||
### `parse(text)` | ||
- `array` values are space seperated scalar values on a single line | ||
- `vector` is a named `array` with scalar values indented two spaces on newlines | ||
- `map` is a named value followed by keys and values indented two spaces | ||
Takes as input raw `.arc` file text and outputs an @architect parsed `Object`. | ||
### `parse.json(jsonText)` | ||
Takes as input raw JSON text representing an @architect parsed `Object` and | ||
trims it down to only relevant @architect `Object` properties. | ||
### `parse.yaml(yamlText)` | ||
Takes as input raw YAML text representing an @architect parsed `Object`, | ||
converts it to JSON and trims it down to only relevant @architect `Object` properties. | ||
[npm]: https://www.npmjs.com/package/@architect/parser |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
475108
36
11695
102
7
4