@cobol-ts/cel 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -2
- package/dist/index.d.ts +6 -0
- package/dist/index.js +23 -0
- package/package.json +60 -3
package/README.md
CHANGED
|
@@ -1,3 +1,50 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @cobol-ts/cel
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Tagless CEL syntax parser with injected **`CelInterpreter<T>`**. This is an intentionally restricted CEL syntax parser, not a CEL runtime or full CEL type checker.
|
|
4
|
+
|
|
5
|
+
An interpreter operation returns `ErrorsOr<T>` from `@cobol-ts/errors`. Independent child errors accumulate; a parent operation is invoked only when its operands succeeded. Syntax errors and interpreter errors are returned together when recovery permits. Lexical errors also accumulate.
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { evaluate, type CelInterpreter } from '@cobol-ts/cel'
|
|
9
|
+
import { valueOrThrow } from '@cobol-ts/errors'
|
|
10
|
+
|
|
11
|
+
const printer: CelInterpreter<string> = {
|
|
12
|
+
identifier: name => ({ value: name }),
|
|
13
|
+
literal: literal => ({ value: String(literal) }),
|
|
14
|
+
member: (target, name) => ({ value: `${target}.${name}` }),
|
|
15
|
+
index: (target, index) => ({ value: `${target}[${index}]` }),
|
|
16
|
+
call: (target, name, args) => ({ value: `${target ? `${target}.` : ''}${name}(${args.join(', ')})` }),
|
|
17
|
+
unary: (op, operand) => ({ value: `${op}${operand}` }),
|
|
18
|
+
binary: (op, left, right) => ({ value: `(${left} ${op} ${right})` }),
|
|
19
|
+
conditional: (condition, yes, no) => ({ value: `(${condition} ? ${yes} : ${no})` }),
|
|
20
|
+
list: values => ({ value: `[${values.join(', ')}]` }),
|
|
21
|
+
map: entries => ({ value: `{${entries.map(([k, v]) => `${k}: ${v}`).join(', ')}}` })
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const result: string = valueOrThrow(evaluate('input.age + 1', printer))
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`evaluate(cel, interpreter)` is the public convenience function; `parseCel(cel, interpreter)` is also available. Both return `ErrorsOr<T>`.
|
|
28
|
+
|
|
29
|
+
## Error composition
|
|
30
|
+
|
|
31
|
+
- Interpreter errors are recorded once at their originating operation.
|
|
32
|
+
- If children fail, the parent is not called, while independent sibling expressions are still inspected.
|
|
33
|
+
- Parsing does not return a partial successful value if syntax or interpreter errors occurred.
|
|
34
|
+
- This interpreter is invoked during syntax traversal, not CEL execution. No short-circuit semantic evaluation is performed, including for `&&`, `||`, and `?:`.
|
|
35
|
+
- Interpreter methods should return `ErrorsOr<T>` instead of throwing for expected semantic failures; unexpected thrown exceptions propagate.
|
|
36
|
+
|
|
37
|
+
## Compatibility
|
|
38
|
+
|
|
39
|
+
Supports identifiers, member selection, indexing, calls, arithmetic/comparison/logical operators, conditionals, lists, maps, strings, numeric literals, and comments. Full CEL syntax including typed messages, optional entries/indexing, raw/bytes strings, and static type checking is not implemented. Keep `@bufbuild/cel` as the authority when validating or executing full CEL.
|
|
40
|
+
|
|
41
|
+
## Commands
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npm run typecheck
|
|
45
|
+
npm test
|
|
46
|
+
npm run build
|
|
47
|
+
npm pack
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Tests are Jest specs under `src/`, matching the monorepo layout.
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./src/cel.lexer"), exports);
|
|
18
|
+
__exportStar(require("./src/cel.parser"), exports);
|
|
19
|
+
__exportStar(require("./src/cel.interpreter"), exports);
|
|
20
|
+
__exportStar(require("./src/cel.evaluate"), exports);
|
|
21
|
+
__exportStar(require("./src/cel.identifiers"), exports);
|
|
22
|
+
__exportStar(require("./src/cel.normaliser.interpreter"), exports);
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cobol-ts/cel",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"description": "agless CEL syntax parser for reusable interpreters",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"main": "dist/index",
|
|
6
|
+
"types": "dist/index",
|
|
7
|
+
"browserslist": {
|
|
8
|
+
"development": [
|
|
9
|
+
"last 1 chrome version",
|
|
10
|
+
"last 1 firefox version",
|
|
11
|
+
"last 1 safari version"
|
|
12
|
+
],
|
|
13
|
+
"production": [
|
|
14
|
+
">0.2%",
|
|
15
|
+
"not dead",
|
|
16
|
+
"not op_mini all"
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@bufbuild/cel": "^0.6.1",
|
|
21
|
+
"@bufbuild/protobuf": "^2",
|
|
22
|
+
"@cobol-ts/graph": "0.0.1"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@testing-library/jest-dom": "^6.1.4",
|
|
26
|
+
"@types/jest": "^29.0.0",
|
|
27
|
+
"@types/node": "^14.0.0",
|
|
28
|
+
"jest": "^29.0.0",
|
|
29
|
+
"ts-jest": "^29.0.0",
|
|
30
|
+
"typescript": "^5.2.2"
|
|
31
|
+
},
|
|
32
|
+
"eslintConfig": {
|
|
33
|
+
"extends": [
|
|
34
|
+
"react-app",
|
|
35
|
+
"react-app/jest"
|
|
36
|
+
],
|
|
37
|
+
"overrides": [
|
|
38
|
+
{
|
|
39
|
+
"files": [
|
|
40
|
+
"**/*.stories.*"
|
|
41
|
+
],
|
|
42
|
+
"rules": {
|
|
43
|
+
"import/no-anonymous-default-export": "off"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
"files": [
|
|
49
|
+
"dist/index.js",
|
|
50
|
+
"dist/index.d.ts",
|
|
51
|
+
"dist/src/",
|
|
52
|
+
"build/"
|
|
53
|
+
],
|
|
54
|
+
"keywords": [
|
|
55
|
+
"indexing"
|
|
56
|
+
],
|
|
57
|
+
"license": "MIT",
|
|
58
|
+
"repository": "git@github.com:intellimaintain/intellimaintain.git",
|
|
59
|
+
"scripts": {
|
|
60
|
+
"test": "jest --config jest.config.json --env node",
|
|
61
|
+
"test:watch": "npm run test -- --watch"
|
|
62
|
+
}
|
|
6
63
|
}
|