@revisium/formula 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +85 -0
- package/dist/chunk-7LP2WY43.js +113 -0
- package/dist/chunk-7LP2WY43.js.map +1 -0
- package/dist/chunk-MHCRMTWJ.cjs +115 -0
- package/dist/chunk-MHCRMTWJ.cjs.map +1 -0
- package/dist/editor/index.cjs +12 -0
- package/dist/editor/index.cjs.map +1 -0
- package/dist/editor/index.d.cts +1 -0
- package/dist/editor/index.d.ts +1 -0
- package/dist/editor/index.js +3 -0
- package/dist/editor/index.js.map +1 -0
- package/dist/index.cjs +12 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +84 -0
- package/dist/index.d.ts +84 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/package.json +91 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 revisium
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# @revisium/formula
|
|
4
|
+
|
|
5
|
+
[](https://sonarcloud.io/summary/new_code?id=revisium_formula)
|
|
6
|
+
[](https://codecov.io/gh/revisium/formula)
|
|
7
|
+
[](https://github.com/revisium/formula/blob/master/LICENSE)
|
|
8
|
+
[](https://github.com/revisium/formula/releases)
|
|
9
|
+
|
|
10
|
+
Formula expression parser and evaluator for [Revisium](https://revisium.io).
|
|
11
|
+
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @revisium/formula
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { detectVersion } from '@revisium/formula';
|
|
24
|
+
|
|
25
|
+
// Simple v1.0 formula
|
|
26
|
+
const result1 = detectVersion('baseDamage * attackSpeed');
|
|
27
|
+
// { minVersion: "1.0", features: [], dependencies: ["baseDamage", "attackSpeed"] }
|
|
28
|
+
|
|
29
|
+
// v1.1 formula with nested paths
|
|
30
|
+
const result2 = detectVersion('stats.damage * /multiplier');
|
|
31
|
+
// { minVersion: "1.1", features: ["nested_path", "root_path"], dependencies: [...] }
|
|
32
|
+
|
|
33
|
+
// Excel-style running total
|
|
34
|
+
const result3 = detectVersion('if(#first, value, @prev.runningTotal + value)');
|
|
35
|
+
// { minVersion: "1.1", features: ["context_token"], dependencies: [...] }
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## API
|
|
39
|
+
|
|
40
|
+
| Function | Description |
|
|
41
|
+
|----------|-------------|
|
|
42
|
+
| `detectVersion` | Analyze formula and detect minimum required version |
|
|
43
|
+
|
|
44
|
+
## Path Syntax
|
|
45
|
+
|
|
46
|
+
| Syntax | Description | Example |
|
|
47
|
+
|--------|-------------|---------|
|
|
48
|
+
| `field` | Top-level field | `baseDamage` |
|
|
49
|
+
| `obj.field` | Nested object | `stats.damage` |
|
|
50
|
+
| `arr[N]` | Array index | `items[0].price` |
|
|
51
|
+
| `arr[-1]` | Last element | `items[-1]` |
|
|
52
|
+
| `arr[*]` | Wildcard | `items[*].price` |
|
|
53
|
+
| `../field` | Parent (relative) | `../quantity` |
|
|
54
|
+
| `/field` | Root (absolute) | `/basePrice` |
|
|
55
|
+
|
|
56
|
+
## Array Context Tokens
|
|
57
|
+
|
|
58
|
+
| Token | Type | Description |
|
|
59
|
+
|-------|------|-------------|
|
|
60
|
+
| `#index` | number | Current array index |
|
|
61
|
+
| `#length` | number | Array length |
|
|
62
|
+
| `#first` | boolean | Is first element |
|
|
63
|
+
| `#last` | boolean | Is last element |
|
|
64
|
+
| `@prev` | object | Previous element |
|
|
65
|
+
| `@next` | object | Next element |
|
|
66
|
+
| `@current` | object | Current element |
|
|
67
|
+
|
|
68
|
+
## Version Detection
|
|
69
|
+
|
|
70
|
+
| Feature | Min Version |
|
|
71
|
+
|---------|-------------|
|
|
72
|
+
| Simple refs (`field`) | 1.0 |
|
|
73
|
+
| Nested paths (`a.b`) | 1.1 |
|
|
74
|
+
| Arrays (`[0]`, `[*]`) | 1.1 |
|
|
75
|
+
| Relative (`../`) | 1.1 |
|
|
76
|
+
| Context tokens | 1.1 |
|
|
77
|
+
| FK refs (`@table.field`) | 2.0 |
|
|
78
|
+
|
|
79
|
+
## Specification
|
|
80
|
+
|
|
81
|
+
See [Formula Specification v1.1](https://github.com/revisium/architecture/blob/master/specs/formula-v1.spec.md).
|
|
82
|
+
|
|
83
|
+
## License
|
|
84
|
+
|
|
85
|
+
MIT
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// src/detect-version.ts
|
|
2
|
+
var NESTED_PATH_REGEX = /[a-zA-Z_]\w*\.[a-zA-Z_]/;
|
|
3
|
+
var ARRAY_INDEX_REGEX = /\[-?\d+]/;
|
|
4
|
+
var ROOT_PATH_REGEX = /(?:^|\W)\/[a-zA-Z_]/;
|
|
5
|
+
var CONTEXT_TOKEN_REGEX = /@(?:prev|next|current)\b|#(?:index|first|last|length)\b/;
|
|
6
|
+
var ARRAY_FUNCTION_REGEX = /\b(?:sum|avg|count|first|last|join|filter|map|includes)\s*\(/i;
|
|
7
|
+
var IDENTIFIER_REGEX = /(?:^|[^.@#/\w])([a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*(?:\[-?\d+]|\[\*])?(?:\.[a-zA-Z_]\w*)*)/g;
|
|
8
|
+
var ROOT_PATH_DEP_REGEX = /(?:^|\W)\/([a-zA-Z_]\w*)/g;
|
|
9
|
+
var RELATIVE_PATH_DEP_REGEX = /\.\.\/([a-zA-Z_]\w*)/g;
|
|
10
|
+
function detectVersion(expression) {
|
|
11
|
+
const features = [];
|
|
12
|
+
if (expression.includes(".") && NESTED_PATH_REGEX.test(expression)) {
|
|
13
|
+
features.push("nested_path");
|
|
14
|
+
}
|
|
15
|
+
if (ARRAY_INDEX_REGEX.test(expression)) {
|
|
16
|
+
features.push("array_index");
|
|
17
|
+
}
|
|
18
|
+
if (expression.includes("[*]")) {
|
|
19
|
+
features.push("array_wildcard");
|
|
20
|
+
}
|
|
21
|
+
if (expression.includes("../")) {
|
|
22
|
+
features.push("relative_path");
|
|
23
|
+
}
|
|
24
|
+
if (ROOT_PATH_REGEX.test(expression)) {
|
|
25
|
+
features.push("root_path");
|
|
26
|
+
}
|
|
27
|
+
if (CONTEXT_TOKEN_REGEX.test(expression)) {
|
|
28
|
+
features.push("context_token");
|
|
29
|
+
}
|
|
30
|
+
if (ARRAY_FUNCTION_REGEX.test(expression)) {
|
|
31
|
+
features.push("array_function");
|
|
32
|
+
}
|
|
33
|
+
const minVersion = features.length > 0 ? "1.1" : "1.0";
|
|
34
|
+
const dependencies = extractDependencies(expression);
|
|
35
|
+
return {
|
|
36
|
+
minVersion,
|
|
37
|
+
features,
|
|
38
|
+
dependencies
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function extractDependencies(expression) {
|
|
42
|
+
const deps = /* @__PURE__ */ new Set();
|
|
43
|
+
IDENTIFIER_REGEX.lastIndex = 0;
|
|
44
|
+
let match;
|
|
45
|
+
while ((match = IDENTIFIER_REGEX.exec(expression)) !== null) {
|
|
46
|
+
const identifier = match[1];
|
|
47
|
+
if (identifier && !isKeyword(identifier)) {
|
|
48
|
+
deps.add(identifier);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
ROOT_PATH_DEP_REGEX.lastIndex = 0;
|
|
52
|
+
while ((match = ROOT_PATH_DEP_REGEX.exec(expression)) !== null) {
|
|
53
|
+
deps.add("/" + match[1]);
|
|
54
|
+
}
|
|
55
|
+
RELATIVE_PATH_DEP_REGEX.lastIndex = 0;
|
|
56
|
+
while ((match = RELATIVE_PATH_DEP_REGEX.exec(expression)) !== null) {
|
|
57
|
+
deps.add("../" + match[1]);
|
|
58
|
+
}
|
|
59
|
+
return Array.from(deps);
|
|
60
|
+
}
|
|
61
|
+
var KEYWORDS = /* @__PURE__ */ new Set([
|
|
62
|
+
"true",
|
|
63
|
+
"false",
|
|
64
|
+
"null",
|
|
65
|
+
"and",
|
|
66
|
+
"or",
|
|
67
|
+
"not",
|
|
68
|
+
"if",
|
|
69
|
+
"round",
|
|
70
|
+
"floor",
|
|
71
|
+
"ceil",
|
|
72
|
+
"abs",
|
|
73
|
+
"sqrt",
|
|
74
|
+
"pow",
|
|
75
|
+
"min",
|
|
76
|
+
"max",
|
|
77
|
+
"log",
|
|
78
|
+
"log10",
|
|
79
|
+
"exp",
|
|
80
|
+
"sign",
|
|
81
|
+
"concat",
|
|
82
|
+
"upper",
|
|
83
|
+
"lower",
|
|
84
|
+
"length",
|
|
85
|
+
"trim",
|
|
86
|
+
"left",
|
|
87
|
+
"right",
|
|
88
|
+
"replace",
|
|
89
|
+
"contains",
|
|
90
|
+
"startswith",
|
|
91
|
+
"endswith",
|
|
92
|
+
"tostring",
|
|
93
|
+
"tonumber",
|
|
94
|
+
"toboolean",
|
|
95
|
+
"isnull",
|
|
96
|
+
"coalesce",
|
|
97
|
+
"sum",
|
|
98
|
+
"avg",
|
|
99
|
+
"count",
|
|
100
|
+
"first",
|
|
101
|
+
"last",
|
|
102
|
+
"join",
|
|
103
|
+
"filter",
|
|
104
|
+
"map",
|
|
105
|
+
"includes"
|
|
106
|
+
]);
|
|
107
|
+
function isKeyword(identifier) {
|
|
108
|
+
return KEYWORDS.has(identifier.toLowerCase());
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export { detectVersion };
|
|
112
|
+
//# sourceMappingURL=chunk-7LP2WY43.js.map
|
|
113
|
+
//# sourceMappingURL=chunk-7LP2WY43.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/detect-version.ts"],"names":[],"mappings":";AAEA,IAAM,iBAAA,GAAoB,yBAAA;AAC1B,IAAM,iBAAA,GAAoB,UAAA;AAC1B,IAAM,eAAA,GAAkB,qBAAA;AACxB,IAAM,mBAAA,GACJ,yDAAA;AACF,IAAM,oBAAA,GACJ,+DAAA;AACF,IAAM,gBAAA,GACJ,yFAAA;AACF,IAAM,mBAAA,GAAsB,2BAAA;AAC5B,IAAM,uBAAA,GAA0B,uBAAA;AAezB,SAAS,cAAc,UAAA,EAAqC;AACjE,EAAA,MAAM,WAA6B,EAAC;AAEpC,EAAA,IAAI,WAAW,QAAA,CAAS,GAAG,KAAK,iBAAA,CAAkB,IAAA,CAAK,UAAU,CAAA,EAAG;AAClE,IAAA,QAAA,CAAS,KAAK,aAAa,CAAA;AAAA,EAC7B;AAEA,EAAA,IAAI,iBAAA,CAAkB,I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,EACA,KAAA;AAAA,EACA,OAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA,QAAA;AAAA,EACA,KAAA;AAAA,EACA;AACF,CAAC,CAAA;AAED,SAAS,UAAU,UAAA,EAA6B;AAC9C,EAAA,OAAO,QAAA,CAAS,GAAA,CAAI,UAAA,CAAW,WAAA,EAAa,CAAA;AAC9C","file":"chunk-7LP2WY43.js","sourcesContent":["import { FormulaFeature, FormulaMinorVersion, FormulaAnalysis } from './types';\n\nconst NESTED_PATH_REGEX = /[a-zA-Z_]\\w*\\.[a-zA-Z_]/;\nconst ARRAY_INDEX_REGEX = /\\[-?\\d+]/;\nconst ROOT_PATH_REGEX = /(?:^|\\W)\\/[a-zA-Z_]/;\nconst CONTEXT_TOKEN_REGEX =\n /@(?:prev|next|current)\\b|#(?:index|first|last|length)\\b/;\nconst ARRAY_FUNCTION_REGEX =\n /\\b(?:sum|avg|count|first|last|join|filter|map|includes)\\s*\\(/i;\nconst IDENTIFIER_REGEX =\n /(?:^|[^.@#/\\w])([a-zA-Z_]\\w*(?:\\.[a-zA-Z_]\\w*)*(?:\\[-?\\d+]|\\[\\*])?(?:\\.[a-zA-Z_]\\w*)*)/g;\nconst ROOT_PATH_DEP_REGEX = /(?:^|\\W)\\/([a-zA-Z_]\\w*)/g;\nconst RELATIVE_PATH_DEP_REGEX = /\\.\\.\\/([a-zA-Z_]\\w*)/g;\n\n/**\n * Detect formula features and minimum required version from expression\n *\n * @param expression - Formula expression string\n * @returns Analysis result with detected version and features\n *\n * @example\n * detectVersion(\"baseDamage * attackSpeed\")\n * // { minVersion: \"1.0\", features: [], dependencies: [\"baseDamage\", \"attackSpeed\"] }\n *\n * detectVersion(\"stats.damage * /multiplier\")\n * // { minVersion: \"1.1\", features: [\"nested_path\", \"root_path\"], dependencies: [\"stats.damage\", \"multiplier\"] }\n */\nexport function detectVersion(expression: string): FormulaAnalysis {\n const features: FormulaFeature[] = [];\n\n if (expression.includes('.') && NESTED_PATH_REGEX.test(expression)) {\n features.push('nested_path');\n }\n\n if (ARRAY_INDEX_REGEX.test(expression)) {\n features.push('array_index');\n }\n\n if (expression.includes('[*]')) {\n features.push('array_wildcard');\n }\n\n if (expression.includes('../')) {\n features.push('relative_path');\n }\n\n if (ROOT_PATH_REGEX.test(expression)) {\n features.push('root_path');\n }\n\n if (CONTEXT_TOKEN_REGEX.test(expression)) {\n features.push('context_token');\n }\n\n if (ARRAY_FUNCTION_REGEX.test(expression)) {\n features.push('array_function');\n }\n\n const minVersion: FormulaMinorVersion = features.length > 0 ? '1.1' : '1.0';\n\n const dependencies = extractDependencies(expression);\n\n return {\n minVersion,\n features,\n dependencies,\n };\n}\n\nfunction extractDependencies(expression: string): string[] {\n const deps = new Set<string>();\n\n IDENTIFIER_REGEX.lastIndex = 0;\n let match;\n while ((match = IDENTIFIER_REGEX.exec(expression)) !== null) {\n const identifier = match[1];\n if (identifier && !isKeyword(identifier)) {\n deps.add(identifier);\n }\n }\n\n ROOT_PATH_DEP_REGEX.lastIndex = 0;\n while ((match = ROOT_PATH_DEP_REGEX.exec(expression)) !== null) {\n deps.add('/' + match[1]);\n }\n\n RELATIVE_PATH_DEP_REGEX.lastIndex = 0;\n while ((match = RELATIVE_PATH_DEP_REGEX.exec(expression)) !== null) {\n deps.add('../' + match[1]);\n }\n\n return Array.from(deps);\n}\n\nconst KEYWORDS = new Set([\n 'true',\n 'false',\n 'null',\n 'and',\n 'or',\n 'not',\n 'if',\n 'round',\n 'floor',\n 'ceil',\n 'abs',\n 'sqrt',\n 'pow',\n 'min',\n 'max',\n 'log',\n 'log10',\n 'exp',\n 'sign',\n 'concat',\n 'upper',\n 'lower',\n 'length',\n 'trim',\n 'left',\n 'right',\n 'replace',\n 'contains',\n 'startswith',\n 'endswith',\n 'tostring',\n 'tonumber',\n 'toboolean',\n 'isnull',\n 'coalesce',\n 'sum',\n 'avg',\n 'count',\n 'first',\n 'last',\n 'join',\n 'filter',\n 'map',\n 'includes',\n]);\n\nfunction isKeyword(identifier: string): boolean {\n return KEYWORDS.has(identifier.toLowerCase());\n}\n"]}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/detect-version.ts
|
|
4
|
+
var NESTED_PATH_REGEX = /[a-zA-Z_]\w*\.[a-zA-Z_]/;
|
|
5
|
+
var ARRAY_INDEX_REGEX = /\[-?\d+]/;
|
|
6
|
+
var ROOT_PATH_REGEX = /(?:^|\W)\/[a-zA-Z_]/;
|
|
7
|
+
var CONTEXT_TOKEN_REGEX = /@(?:prev|next|current)\b|#(?:index|first|last|length)\b/;
|
|
8
|
+
var ARRAY_FUNCTION_REGEX = /\b(?:sum|avg|count|first|last|join|filter|map|includes)\s*\(/i;
|
|
9
|
+
var IDENTIFIER_REGEX = /(?:^|[^.@#/\w])([a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*(?:\[-?\d+]|\[\*])?(?:\.[a-zA-Z_]\w*)*)/g;
|
|
10
|
+
var ROOT_PATH_DEP_REGEX = /(?:^|\W)\/([a-zA-Z_]\w*)/g;
|
|
11
|
+
var RELATIVE_PATH_DEP_REGEX = /\.\.\/([a-zA-Z_]\w*)/g;
|
|
12
|
+
function detectVersion(expression) {
|
|
13
|
+
const features = [];
|
|
14
|
+
if (expression.includes(".") && NESTED_PATH_REGEX.test(expression)) {
|
|
15
|
+
features.push("nested_path");
|
|
16
|
+
}
|
|
17
|
+
if (ARRAY_INDEX_REGEX.test(expression)) {
|
|
18
|
+
features.push("array_index");
|
|
19
|
+
}
|
|
20
|
+
if (expression.includes("[*]")) {
|
|
21
|
+
features.push("array_wildcard");
|
|
22
|
+
}
|
|
23
|
+
if (expression.includes("../")) {
|
|
24
|
+
features.push("relative_path");
|
|
25
|
+
}
|
|
26
|
+
if (ROOT_PATH_REGEX.test(expression)) {
|
|
27
|
+
features.push("root_path");
|
|
28
|
+
}
|
|
29
|
+
if (CONTEXT_TOKEN_REGEX.test(expression)) {
|
|
30
|
+
features.push("context_token");
|
|
31
|
+
}
|
|
32
|
+
if (ARRAY_FUNCTION_REGEX.test(expression)) {
|
|
33
|
+
features.push("array_function");
|
|
34
|
+
}
|
|
35
|
+
const minVersion = features.length > 0 ? "1.1" : "1.0";
|
|
36
|
+
const dependencies = extractDependencies(expression);
|
|
37
|
+
return {
|
|
38
|
+
minVersion,
|
|
39
|
+
features,
|
|
40
|
+
dependencies
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function extractDependencies(expression) {
|
|
44
|
+
const deps = /* @__PURE__ */ new Set();
|
|
45
|
+
IDENTIFIER_REGEX.lastIndex = 0;
|
|
46
|
+
let match;
|
|
47
|
+
while ((match = IDENTIFIER_REGEX.exec(expression)) !== null) {
|
|
48
|
+
const identifier = match[1];
|
|
49
|
+
if (identifier && !isKeyword(identifier)) {
|
|
50
|
+
deps.add(identifier);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
ROOT_PATH_DEP_REGEX.lastIndex = 0;
|
|
54
|
+
while ((match = ROOT_PATH_DEP_REGEX.exec(expression)) !== null) {
|
|
55
|
+
deps.add("/" + match[1]);
|
|
56
|
+
}
|
|
57
|
+
RELATIVE_PATH_DEP_REGEX.lastIndex = 0;
|
|
58
|
+
while ((match = RELATIVE_PATH_DEP_REGEX.exec(expression)) !== null) {
|
|
59
|
+
deps.add("../" + match[1]);
|
|
60
|
+
}
|
|
61
|
+
return Array.from(deps);
|
|
62
|
+
}
|
|
63
|
+
var KEYWORDS = /* @__PURE__ */ new Set([
|
|
64
|
+
"true",
|
|
65
|
+
"false",
|
|
66
|
+
"null",
|
|
67
|
+
"and",
|
|
68
|
+
"or",
|
|
69
|
+
"not",
|
|
70
|
+
"if",
|
|
71
|
+
"round",
|
|
72
|
+
"floor",
|
|
73
|
+
"ceil",
|
|
74
|
+
"abs",
|
|
75
|
+
"sqrt",
|
|
76
|
+
"pow",
|
|
77
|
+
"min",
|
|
78
|
+
"max",
|
|
79
|
+
"log",
|
|
80
|
+
"log10",
|
|
81
|
+
"exp",
|
|
82
|
+
"sign",
|
|
83
|
+
"concat",
|
|
84
|
+
"upper",
|
|
85
|
+
"lower",
|
|
86
|
+
"length",
|
|
87
|
+
"trim",
|
|
88
|
+
"left",
|
|
89
|
+
"right",
|
|
90
|
+
"replace",
|
|
91
|
+
"contains",
|
|
92
|
+
"startswith",
|
|
93
|
+
"endswith",
|
|
94
|
+
"tostring",
|
|
95
|
+
"tonumber",
|
|
96
|
+
"toboolean",
|
|
97
|
+
"isnull",
|
|
98
|
+
"coalesce",
|
|
99
|
+
"sum",
|
|
100
|
+
"avg",
|
|
101
|
+
"count",
|
|
102
|
+
"first",
|
|
103
|
+
"last",
|
|
104
|
+
"join",
|
|
105
|
+
"filter",
|
|
106
|
+
"map",
|
|
107
|
+
"includes"
|
|
108
|
+
]);
|
|
109
|
+
function isKeyword(identifier) {
|
|
110
|
+
return KEYWORDS.has(identifier.toLowerCase());
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
exports.detectVersion = detectVersion;
|
|
114
|
+
//# sourceMappingURL=chunk-MHCRMTWJ.cjs.map
|
|
115
|
+
//# sourceMappingURL=chunk-MHCRMTWJ.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/detect-version.ts"],"names":[],"mappings":";;;AAEA,IAAM,iBAAA,GAAoB,yBAAA;AAC1B,IAAM,iBAAA,GAAoB,UAAA;AAC1B,IAAM,eAAA,GAAkB,qBAAA;AACxB,IAAM,mBAAA,GACJ,yDAAA;AACF,IAAM,oBAAA,GACJ,+DAAA;AACF,IAAM,gBAAA,GACJ,yFAAA;AACF,IAAM,mBAAA,GAAsB,2BAAA;AAC5B,IAAM,uBAAA,GAA0B,uBAAA;AAezB,SAAS,cAAc,UAAA,EAAqC;AACjE,EAAA,MAAM,WAA6B,EAAC;AAEpC,EAAA,IAAI,WAAW,QAAA,CAAS,GAAG,KAAK,iBAAA,CAAkB,IAAA,CAAK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A;AAAA,EACA,UAAA;AAAA,EACA,UAAA;AAAA,EACA,WAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,OAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA,QAAA;AAAA,EACA,KAAA;AAAA,EACA;AACF,CAAC,CAAA;AAED,SAAS,UAAU,UAAA,EAA6B;AAC9C,EAAA,OAAO,QAAA,CAAS,GAAA,CAAI,UAAA,CAAW,WAAA,EAAa,CAAA;AAC9C","file":"chunk-MHCRMTWJ.cjs","sourcesContent":["import { FormulaFeature, FormulaMinorVersion, FormulaAnalysis } from './types';\n\nconst NESTED_PATH_REGEX = /[a-zA-Z_]\\w*\\.[a-zA-Z_]/;\nconst ARRAY_INDEX_REGEX = /\\[-?\\d+]/;\nconst ROOT_PATH_REGEX = /(?:^|\\W)\\/[a-zA-Z_]/;\nconst CONTEXT_TOKEN_REGEX =\n /@(?:prev|next|current)\\b|#(?:index|first|last|length)\\b/;\nconst ARRAY_FUNCTION_REGEX =\n /\\b(?:sum|avg|count|first|last|join|filter|map|includes)\\s*\\(/i;\nconst IDENTIFIER_REGEX =\n /(?:^|[^.@#/\\w])([a-zA-Z_]\\w*(?:\\.[a-zA-Z_]\\w*)*(?:\\[-?\\d+]|\\[\\*])?(?:\\.[a-zA-Z_]\\w*)*)/g;\nconst ROOT_PATH_DEP_REGEX = /(?:^|\\W)\\/([a-zA-Z_]\\w*)/g;\nconst RELATIVE_PATH_DEP_REGEX = /\\.\\.\\/([a-zA-Z_]\\w*)/g;\n\n/**\n * Detect formula features and minimum required version from expression\n *\n * @param expression - Formula expression string\n * @returns Analysis result with detected version and features\n *\n * @example\n * detectVersion(\"baseDamage * attackSpeed\")\n * // { minVersion: \"1.0\", features: [], dependencies: [\"baseDamage\", \"attackSpeed\"] }\n *\n * detectVersion(\"stats.damage * /multiplier\")\n * // { minVersion: \"1.1\", features: [\"nested_path\", \"root_path\"], dependencies: [\"stats.damage\", \"multiplier\"] }\n */\nexport function detectVersion(expression: string): FormulaAnalysis {\n const features: FormulaFeature[] = [];\n\n if (expression.includes('.') && NESTED_PATH_REGEX.test(expression)) {\n features.push('nested_path');\n }\n\n if (ARRAY_INDEX_REGEX.test(expression)) {\n features.push('array_index');\n }\n\n if (expression.includes('[*]')) {\n features.push('array_wildcard');\n }\n\n if (expression.includes('../')) {\n features.push('relative_path');\n }\n\n if (ROOT_PATH_REGEX.test(expression)) {\n features.push('root_path');\n }\n\n if (CONTEXT_TOKEN_REGEX.test(expression)) {\n features.push('context_token');\n }\n\n if (ARRAY_FUNCTION_REGEX.test(expression)) {\n features.push('array_function');\n }\n\n const minVersion: FormulaMinorVersion = features.length > 0 ? '1.1' : '1.0';\n\n const dependencies = extractDependencies(expression);\n\n return {\n minVersion,\n features,\n dependencies,\n };\n}\n\nfunction extractDependencies(expression: string): string[] {\n const deps = new Set<string>();\n\n IDENTIFIER_REGEX.lastIndex = 0;\n let match;\n while ((match = IDENTIFIER_REGEX.exec(expression)) !== null) {\n const identifier = match[1];\n if (identifier && !isKeyword(identifier)) {\n deps.add(identifier);\n }\n }\n\n ROOT_PATH_DEP_REGEX.lastIndex = 0;\n while ((match = ROOT_PATH_DEP_REGEX.exec(expression)) !== null) {\n deps.add('/' + match[1]);\n }\n\n RELATIVE_PATH_DEP_REGEX.lastIndex = 0;\n while ((match = RELATIVE_PATH_DEP_REGEX.exec(expression)) !== null) {\n deps.add('../' + match[1]);\n }\n\n return Array.from(deps);\n}\n\nconst KEYWORDS = new Set([\n 'true',\n 'false',\n 'null',\n 'and',\n 'or',\n 'not',\n 'if',\n 'round',\n 'floor',\n 'ceil',\n 'abs',\n 'sqrt',\n 'pow',\n 'min',\n 'max',\n 'log',\n 'log10',\n 'exp',\n 'sign',\n 'concat',\n 'upper',\n 'lower',\n 'length',\n 'trim',\n 'left',\n 'right',\n 'replace',\n 'contains',\n 'startswith',\n 'endswith',\n 'tostring',\n 'tonumber',\n 'toboolean',\n 'isnull',\n 'coalesce',\n 'sum',\n 'avg',\n 'count',\n 'first',\n 'last',\n 'join',\n 'filter',\n 'map',\n 'includes',\n]);\n\nfunction isKeyword(identifier: string): boolean {\n return KEYWORDS.has(identifier.toLowerCase());\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkMHCRMTWJ_cjs = require('../chunk-MHCRMTWJ.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "detectVersion", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () { return chunkMHCRMTWJ_cjs.detectVersion; }
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=index.cjs.map
|
|
12
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FormulaAnalysis, FormulaFeature, FormulaFieldSchema, FormulaMinorVersion, FormulaValidationError, FormulaValidationErrorType, FormulaValidationResult, FormulaValidationWarning, FormulaValidationWarningType, ParsedFormula, ParsedPath, PathSegment, PathValidationResult, XFormula, detectVersion } from '../index.cjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FormulaAnalysis, FormulaFeature, FormulaFieldSchema, FormulaMinorVersion, FormulaValidationError, FormulaValidationErrorType, FormulaValidationResult, FormulaValidationWarning, FormulaValidationWarningType, ParsedFormula, ParsedPath, PathSegment, PathValidationResult, XFormula, detectVersion } from '../index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkMHCRMTWJ_cjs = require('./chunk-MHCRMTWJ.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "detectVersion", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () { return chunkMHCRMTWJ_cjs.detectVersion; }
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=index.cjs.map
|
|
12
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
interface XFormula {
|
|
2
|
+
version: 1;
|
|
3
|
+
expression: string;
|
|
4
|
+
onError?: 'null' | 'default' | 'throw';
|
|
5
|
+
}
|
|
6
|
+
type FormulaMinorVersion = '1.0' | '1.1';
|
|
7
|
+
type FormulaFeature = 'nested_path' | 'array_index' | 'array_wildcard' | 'relative_path' | 'root_path' | 'context_token' | 'array_function';
|
|
8
|
+
interface FormulaAnalysis {
|
|
9
|
+
minVersion: FormulaMinorVersion;
|
|
10
|
+
features: FormulaFeature[];
|
|
11
|
+
dependencies: string[];
|
|
12
|
+
}
|
|
13
|
+
type PathSegment = {
|
|
14
|
+
type: 'property';
|
|
15
|
+
name: string;
|
|
16
|
+
} | {
|
|
17
|
+
type: 'index';
|
|
18
|
+
value: number;
|
|
19
|
+
} | {
|
|
20
|
+
type: 'wildcard';
|
|
21
|
+
} | {
|
|
22
|
+
type: 'parent';
|
|
23
|
+
} | {
|
|
24
|
+
type: 'root';
|
|
25
|
+
} | {
|
|
26
|
+
type: 'token';
|
|
27
|
+
name: string;
|
|
28
|
+
};
|
|
29
|
+
interface ParsedPath {
|
|
30
|
+
original: string;
|
|
31
|
+
segments: PathSegment[];
|
|
32
|
+
isAbsolute: boolean;
|
|
33
|
+
isRelative: boolean;
|
|
34
|
+
}
|
|
35
|
+
interface PathValidationResult {
|
|
36
|
+
isValid: boolean;
|
|
37
|
+
error?: string;
|
|
38
|
+
segments?: PathSegment[];
|
|
39
|
+
}
|
|
40
|
+
interface FormulaContext {
|
|
41
|
+
[fieldName: string]: unknown;
|
|
42
|
+
}
|
|
43
|
+
type FormulaResult = number | string | boolean | null;
|
|
44
|
+
interface FormulaValidationResult {
|
|
45
|
+
isValid: boolean;
|
|
46
|
+
errors: FormulaValidationError[];
|
|
47
|
+
warnings: FormulaValidationWarning[];
|
|
48
|
+
dependencyGraph: Map<string, string[]>;
|
|
49
|
+
}
|
|
50
|
+
type FormulaValidationErrorType = 'MISSING_DEPENDENCY' | 'CIRCULAR_DEPENDENCY' | 'INVALID_SYNTAX' | 'TYPE_MISMATCH';
|
|
51
|
+
interface FormulaValidationError {
|
|
52
|
+
type: FormulaValidationErrorType;
|
|
53
|
+
field: string;
|
|
54
|
+
expression: string;
|
|
55
|
+
message: string;
|
|
56
|
+
details?: {
|
|
57
|
+
missingField?: string;
|
|
58
|
+
cycle?: string[];
|
|
59
|
+
expectedType?: string;
|
|
60
|
+
actualType?: string;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
type FormulaValidationWarningType = 'TYPE_COERCION' | 'DEPRECATED_FUNCTION';
|
|
64
|
+
interface FormulaValidationWarning {
|
|
65
|
+
type: FormulaValidationWarningType;
|
|
66
|
+
field: string;
|
|
67
|
+
message: string;
|
|
68
|
+
}
|
|
69
|
+
interface FormulaFieldSchema {
|
|
70
|
+
type: 'number' | 'string' | 'boolean';
|
|
71
|
+
default: number | string | boolean;
|
|
72
|
+
readOnly: true;
|
|
73
|
+
'x-formula': XFormula;
|
|
74
|
+
}
|
|
75
|
+
interface ParsedFormula {
|
|
76
|
+
fieldName: string;
|
|
77
|
+
expression: string;
|
|
78
|
+
dependencies: string[];
|
|
79
|
+
resultType: 'number' | 'string' | 'boolean';
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
declare function detectVersion(expression: string): FormulaAnalysis;
|
|
83
|
+
|
|
84
|
+
export { type FormulaAnalysis, type FormulaContext, type FormulaFeature, type FormulaFieldSchema, type FormulaMinorVersion, type FormulaResult, type FormulaValidationError, type FormulaValidationErrorType, type FormulaValidationResult, type FormulaValidationWarning, type FormulaValidationWarningType, type ParsedFormula, type ParsedPath, type PathSegment, type PathValidationResult, type XFormula, detectVersion };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
interface XFormula {
|
|
2
|
+
version: 1;
|
|
3
|
+
expression: string;
|
|
4
|
+
onError?: 'null' | 'default' | 'throw';
|
|
5
|
+
}
|
|
6
|
+
type FormulaMinorVersion = '1.0' | '1.1';
|
|
7
|
+
type FormulaFeature = 'nested_path' | 'array_index' | 'array_wildcard' | 'relative_path' | 'root_path' | 'context_token' | 'array_function';
|
|
8
|
+
interface FormulaAnalysis {
|
|
9
|
+
minVersion: FormulaMinorVersion;
|
|
10
|
+
features: FormulaFeature[];
|
|
11
|
+
dependencies: string[];
|
|
12
|
+
}
|
|
13
|
+
type PathSegment = {
|
|
14
|
+
type: 'property';
|
|
15
|
+
name: string;
|
|
16
|
+
} | {
|
|
17
|
+
type: 'index';
|
|
18
|
+
value: number;
|
|
19
|
+
} | {
|
|
20
|
+
type: 'wildcard';
|
|
21
|
+
} | {
|
|
22
|
+
type: 'parent';
|
|
23
|
+
} | {
|
|
24
|
+
type: 'root';
|
|
25
|
+
} | {
|
|
26
|
+
type: 'token';
|
|
27
|
+
name: string;
|
|
28
|
+
};
|
|
29
|
+
interface ParsedPath {
|
|
30
|
+
original: string;
|
|
31
|
+
segments: PathSegment[];
|
|
32
|
+
isAbsolute: boolean;
|
|
33
|
+
isRelative: boolean;
|
|
34
|
+
}
|
|
35
|
+
interface PathValidationResult {
|
|
36
|
+
isValid: boolean;
|
|
37
|
+
error?: string;
|
|
38
|
+
segments?: PathSegment[];
|
|
39
|
+
}
|
|
40
|
+
interface FormulaContext {
|
|
41
|
+
[fieldName: string]: unknown;
|
|
42
|
+
}
|
|
43
|
+
type FormulaResult = number | string | boolean | null;
|
|
44
|
+
interface FormulaValidationResult {
|
|
45
|
+
isValid: boolean;
|
|
46
|
+
errors: FormulaValidationError[];
|
|
47
|
+
warnings: FormulaValidationWarning[];
|
|
48
|
+
dependencyGraph: Map<string, string[]>;
|
|
49
|
+
}
|
|
50
|
+
type FormulaValidationErrorType = 'MISSING_DEPENDENCY' | 'CIRCULAR_DEPENDENCY' | 'INVALID_SYNTAX' | 'TYPE_MISMATCH';
|
|
51
|
+
interface FormulaValidationError {
|
|
52
|
+
type: FormulaValidationErrorType;
|
|
53
|
+
field: string;
|
|
54
|
+
expression: string;
|
|
55
|
+
message: string;
|
|
56
|
+
details?: {
|
|
57
|
+
missingField?: string;
|
|
58
|
+
cycle?: string[];
|
|
59
|
+
expectedType?: string;
|
|
60
|
+
actualType?: string;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
type FormulaValidationWarningType = 'TYPE_COERCION' | 'DEPRECATED_FUNCTION';
|
|
64
|
+
interface FormulaValidationWarning {
|
|
65
|
+
type: FormulaValidationWarningType;
|
|
66
|
+
field: string;
|
|
67
|
+
message: string;
|
|
68
|
+
}
|
|
69
|
+
interface FormulaFieldSchema {
|
|
70
|
+
type: 'number' | 'string' | 'boolean';
|
|
71
|
+
default: number | string | boolean;
|
|
72
|
+
readOnly: true;
|
|
73
|
+
'x-formula': XFormula;
|
|
74
|
+
}
|
|
75
|
+
interface ParsedFormula {
|
|
76
|
+
fieldName: string;
|
|
77
|
+
expression: string;
|
|
78
|
+
dependencies: string[];
|
|
79
|
+
resultType: 'number' | 'string' | 'boolean';
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
declare function detectVersion(expression: string): FormulaAnalysis;
|
|
83
|
+
|
|
84
|
+
export { type FormulaAnalysis, type FormulaContext, type FormulaFeature, type FormulaFieldSchema, type FormulaMinorVersion, type FormulaResult, type FormulaValidationError, type FormulaValidationErrorType, type FormulaValidationResult, type FormulaValidationWarning, type FormulaValidationWarningType, type ParsedFormula, type ParsedPath, type PathSegment, type PathValidationResult, type XFormula, detectVersion };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
package/package.json
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@revisium/formula",
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
|
+
"description": "Formula expression parser and evaluator for Revisium CMS",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"formula",
|
|
7
|
+
"expression",
|
|
8
|
+
"parser",
|
|
9
|
+
"revisium",
|
|
10
|
+
"computed-fields",
|
|
11
|
+
"typescript"
|
|
12
|
+
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/revisium/formula.git"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"author": "Anton Kashirov",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"import": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"require": {
|
|
27
|
+
"types": "./dist/index.d.cts",
|
|
28
|
+
"default": "./dist/index.cjs"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"./editor": {
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./dist/editor/index.d.ts",
|
|
34
|
+
"default": "./dist/editor/index.js"
|
|
35
|
+
},
|
|
36
|
+
"require": {
|
|
37
|
+
"types": "./dist/editor/index.d.cts",
|
|
38
|
+
"default": "./dist/editor/index.cjs"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"main": "./dist/index.cjs",
|
|
43
|
+
"module": "./dist/index.js",
|
|
44
|
+
"types": "./dist/index.d.ts",
|
|
45
|
+
"typesVersions": {
|
|
46
|
+
"*": {
|
|
47
|
+
"editor": [
|
|
48
|
+
"./dist/editor/index.d.ts"
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"files": [
|
|
53
|
+
"dist"
|
|
54
|
+
],
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "tsup",
|
|
57
|
+
"dev": "tsup --watch",
|
|
58
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
59
|
+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch",
|
|
60
|
+
"test:cov": "NODE_OPTIONS=--experimental-vm-modules jest --coverage --silent",
|
|
61
|
+
"lint:ci": "eslint . --max-warnings 0",
|
|
62
|
+
"lint:fix": "eslint . --fix",
|
|
63
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
64
|
+
"format:check": "prettier --check \"src/**/*.ts\"",
|
|
65
|
+
"tsc": "tsc --noEmit",
|
|
66
|
+
"prepublishOnly": "npm run build && npm run tsc"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@eslint/js": "^9.15.0",
|
|
70
|
+
"@jest/globals": "^29.7.0",
|
|
71
|
+
"@types/jest": "^29.5.14",
|
|
72
|
+
"@types/node": "^24.10.7",
|
|
73
|
+
"eslint": "^9.15.0",
|
|
74
|
+
"eslint-config-prettier": "^10.1.8",
|
|
75
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
76
|
+
"eslint-plugin-sonarjs": "^3.0.5",
|
|
77
|
+
"globals": "^15.12.0",
|
|
78
|
+
"jest": "^29.7.0",
|
|
79
|
+
"prettier": "^3.4.2",
|
|
80
|
+
"ts-jest": "^29.2.5",
|
|
81
|
+
"tsup": "^8.3.5",
|
|
82
|
+
"typescript": "^5.7.2",
|
|
83
|
+
"typescript-eslint": "^8.15.0"
|
|
84
|
+
},
|
|
85
|
+
"engines": {
|
|
86
|
+
"node": ">=18.0.0"
|
|
87
|
+
},
|
|
88
|
+
"publishConfig": {
|
|
89
|
+
"access": "public"
|
|
90
|
+
}
|
|
91
|
+
}
|