@swaggerexpert/arazzo-runtime-expression 1.0.0
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 +202 -0
- package/NOTICE +10 -0
- package/README.md +290 -0
- package/SECURITY.md +15 -0
- package/cjs/apg-lite.cjs +1221 -0
- package/cjs/extract.cjs +21 -0
- package/cjs/index.cjs +13 -0
- package/cjs/parse/callbacks/body-reference.cjs +14 -0
- package/cjs/parse/callbacks/expression.cjs +15 -0
- package/cjs/parse/callbacks/header-reference.cjs +14 -0
- package/cjs/parse/callbacks/json-pointer.cjs +14 -0
- package/cjs/parse/callbacks/name.cjs +14 -0
- package/cjs/parse/callbacks/parameter-name.cjs +14 -0
- package/cjs/parse/callbacks/path-reference.cjs +14 -0
- package/cjs/parse/callbacks/query-reference.cjs +14 -0
- package/cjs/parse/callbacks/reference-token.cjs +14 -0
- package/cjs/parse/callbacks/source.cjs +14 -0
- package/cjs/parse/callbacks/token.cjs +15 -0
- package/cjs/parse/index.cjs +40 -0
- package/cjs/runtime-expression.cjs +779 -0
- package/cjs/test.cjs +15 -0
- package/es/extract.mjs +17 -0
- package/es/index.mjs +4 -0
- package/es/parse/callbacks/body-reference.mjs +10 -0
- package/es/parse/callbacks/expression.mjs +11 -0
- package/es/parse/callbacks/header-reference.mjs +10 -0
- package/es/parse/callbacks/json-pointer.mjs +10 -0
- package/es/parse/callbacks/name.mjs +10 -0
- package/es/parse/callbacks/parameter-name.mjs +10 -0
- package/es/parse/callbacks/path-reference.mjs +10 -0
- package/es/parse/callbacks/query-reference.mjs +10 -0
- package/es/parse/callbacks/reference-token.mjs +10 -0
- package/es/parse/callbacks/source.mjs +10 -0
- package/es/parse/callbacks/token.mjs +10 -0
- package/es/parse/index.mjs +35 -0
- package/es/runtime-expression.mjs +775 -0
- package/es/test.mjs +10 -0
- package/package.json +82 -0
- package/types/index.d.ts +54 -0
package/cjs/test.cjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
var _index = _interopRequireDefault(require("./parse/index.cjs"));
|
|
6
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
const test = runtimeExpression => {
|
|
8
|
+
try {
|
|
9
|
+
const parseResult = (0, _index.default)(runtimeExpression);
|
|
10
|
+
return parseResult.result.success;
|
|
11
|
+
} catch {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var _default = exports.default = test;
|
package/es/extract.mjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function is used for extracting the expression from Arazzo Runtime Expression notation.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
*
|
|
6
|
+
* extract('{$url}'); // => '$url'
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const extract = arazzoRuntimeExpression => {
|
|
10
|
+
var _match$groups$express, _match$groups;
|
|
11
|
+
if (typeof arazzoRuntimeExpression !== 'string') {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const match = arazzoRuntimeExpression.match(/^{(?<expression>.+)}$/);
|
|
15
|
+
return (_match$groups$express = match === null || match === void 0 || (_match$groups = match.groups) === null || _match$groups === void 0 ? void 0 : _match$groups.expression) !== null && _match$groups$express !== void 0 ? _match$groups$express : null;
|
|
16
|
+
};
|
|
17
|
+
export default extract;
|
package/es/index.mjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { identifiers, utilities } from 'apg-lite';
|
|
2
|
+
const bodyReference = (state, chars, phraseIndex, phraseLength, data) => {
|
|
3
|
+
if (state === identifiers.SEM_PRE) {
|
|
4
|
+
data.push(['body-reference', utilities.charsToString(chars, phraseIndex, phraseLength)]);
|
|
5
|
+
} else if (state === identifiers.SEM_POST) {
|
|
6
|
+
/* not used in this example */
|
|
7
|
+
}
|
|
8
|
+
return identifiers.SEM_OK;
|
|
9
|
+
};
|
|
10
|
+
export default bodyReference;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { identifiers, utilities } from 'apg-lite';
|
|
2
|
+
const expression = (state, chars, phraseIndex, phraseLength, data) => {
|
|
3
|
+
if (state === identifiers.SEM_PRE) {
|
|
4
|
+
if (Array.isArray(data) === false) {
|
|
5
|
+
throw new Error("parser's user data must be an array");
|
|
6
|
+
}
|
|
7
|
+
data.push(['expression', utilities.charsToString(chars, phraseIndex, phraseLength)]);
|
|
8
|
+
}
|
|
9
|
+
return identifiers.SEM_OK;
|
|
10
|
+
};
|
|
11
|
+
export default expression;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { identifiers, utilities } from 'apg-lite';
|
|
2
|
+
const headerReference = (state, chars, phraseIndex, phraseLength, data) => {
|
|
3
|
+
if (state === identifiers.SEM_PRE) {
|
|
4
|
+
data.push(['header-reference', utilities.charsToString(chars, phraseIndex, phraseLength)]);
|
|
5
|
+
} else if (state === identifiers.SEM_POST) {
|
|
6
|
+
/* not used in this example */
|
|
7
|
+
}
|
|
8
|
+
return identifiers.SEM_OK;
|
|
9
|
+
};
|
|
10
|
+
export default headerReference;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { identifiers, utilities } from 'apg-lite';
|
|
2
|
+
const jsonPointer = (state, chars, phraseIndex, phraseLength, data) => {
|
|
3
|
+
if (state === identifiers.SEM_PRE) {
|
|
4
|
+
data.push(['json-pointer', utilities.charsToString(chars, phraseIndex, phraseLength)]);
|
|
5
|
+
} else if (state === identifiers.SEM_POST) {
|
|
6
|
+
/* not used in this example */
|
|
7
|
+
}
|
|
8
|
+
return identifiers.SEM_OK;
|
|
9
|
+
};
|
|
10
|
+
export default jsonPointer;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { identifiers, utilities } from 'apg-lite';
|
|
2
|
+
const name = (state, chars, phraseIndex, phraseLength, data) => {
|
|
3
|
+
if (state === identifiers.SEM_PRE) {
|
|
4
|
+
data.push(['name', utilities.charsToString(chars, phraseIndex, phraseLength)]);
|
|
5
|
+
} else if (state === identifiers.SEM_POST) {
|
|
6
|
+
/* not used in this example */
|
|
7
|
+
}
|
|
8
|
+
return identifiers.SEM_OK;
|
|
9
|
+
};
|
|
10
|
+
export default name;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { identifiers, utilities } from 'apg-lite';
|
|
2
|
+
const parameterName = (state, chars, phraseIndex, phraseLength, data) => {
|
|
3
|
+
if (state === identifiers.SEM_PRE) {
|
|
4
|
+
data.push(['parameter-name', utilities.charsToString(chars, phraseIndex, phraseLength)]);
|
|
5
|
+
} else if (state === identifiers.SEM_POST) {
|
|
6
|
+
/* not used in this example */
|
|
7
|
+
}
|
|
8
|
+
return identifiers.SEM_OK;
|
|
9
|
+
};
|
|
10
|
+
export default parameterName;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { identifiers, utilities } from 'apg-lite';
|
|
2
|
+
const pathReference = (state, chars, phraseIndex, phraseLength, data) => {
|
|
3
|
+
if (state === identifiers.SEM_PRE) {
|
|
4
|
+
data.push(['path-reference', utilities.charsToString(chars, phraseIndex, phraseLength)]);
|
|
5
|
+
} else if (state === identifiers.SEM_POST) {
|
|
6
|
+
/* not used in this example */
|
|
7
|
+
}
|
|
8
|
+
return identifiers.SEM_OK;
|
|
9
|
+
};
|
|
10
|
+
export default pathReference;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { identifiers, utilities } from 'apg-lite';
|
|
2
|
+
const queryReference = (state, chars, phraseIndex, phraseLength, data) => {
|
|
3
|
+
if (state === identifiers.SEM_PRE) {
|
|
4
|
+
data.push(['query-reference', utilities.charsToString(chars, phraseIndex, phraseLength)]);
|
|
5
|
+
} else if (state === identifiers.SEM_POST) {
|
|
6
|
+
/* not used in this example */
|
|
7
|
+
}
|
|
8
|
+
return identifiers.SEM_OK;
|
|
9
|
+
};
|
|
10
|
+
export default queryReference;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { identifiers, utilities } from 'apg-lite';
|
|
2
|
+
const referenceToken = (state, chars, phraseIndex, phraseLength, data) => {
|
|
3
|
+
if (state === identifiers.SEM_PRE) {
|
|
4
|
+
data.push(['reference-token', utilities.charsToString(chars, phraseIndex, phraseLength)]);
|
|
5
|
+
} else if (state === identifiers.SEM_POST) {
|
|
6
|
+
/* not used in this example */
|
|
7
|
+
}
|
|
8
|
+
return identifiers.SEM_OK;
|
|
9
|
+
};
|
|
10
|
+
export default referenceToken;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { identifiers, utilities } from 'apg-lite';
|
|
2
|
+
const source = (state, chars, phraseIndex, phraseLength, data) => {
|
|
3
|
+
if (state === identifiers.SEM_PRE) {
|
|
4
|
+
data.push(['source', utilities.charsToString(chars, phraseIndex, phraseLength)]);
|
|
5
|
+
} else if (state === identifiers.SEM_POST) {
|
|
6
|
+
/* not used in this example */
|
|
7
|
+
}
|
|
8
|
+
return identifiers.SEM_OK;
|
|
9
|
+
};
|
|
10
|
+
export default source;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { identifiers, utilities } from 'apg-lite';
|
|
2
|
+
export const token = (state, chars, phraseIndex, phraseLength, data) => {
|
|
3
|
+
if (state === identifiers.SEM_PRE) {
|
|
4
|
+
data.push(['token', utilities.charsToString(chars, phraseIndex, phraseLength)]);
|
|
5
|
+
} else if (state === identifiers.SEM_POST) {
|
|
6
|
+
/* not used in this example */
|
|
7
|
+
}
|
|
8
|
+
return identifiers.SEM_OK;
|
|
9
|
+
};
|
|
10
|
+
export default token;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Ast as AST, Parser } from 'apg-lite';
|
|
2
|
+
import Grammar from "../runtime-expression.mjs";
|
|
3
|
+
import expressionCallback from "./callbacks/expression.mjs";
|
|
4
|
+
import parameterNameCallback from "./callbacks/parameter-name.mjs";
|
|
5
|
+
import sourceCallback from "./callbacks/source.mjs";
|
|
6
|
+
import headerReferenceCallback from "./callbacks/header-reference.mjs";
|
|
7
|
+
import queryReferenceCallback from "./callbacks/query-reference.mjs";
|
|
8
|
+
import pathReferenceCallback from "./callbacks/path-reference.mjs";
|
|
9
|
+
import bodyReferenceCallback from "./callbacks/body-reference.mjs";
|
|
10
|
+
import jsonPointerCallback from "./callbacks/json-pointer.mjs";
|
|
11
|
+
import referenceTokenCallback from "./callbacks/reference-token.mjs";
|
|
12
|
+
import nameCallback from "./callbacks/name.mjs";
|
|
13
|
+
import tokenCallback from "./callbacks/token.mjs";
|
|
14
|
+
const grammar = new Grammar();
|
|
15
|
+
const parse = runtimeExpression => {
|
|
16
|
+
const parser = new Parser();
|
|
17
|
+
parser.ast = new AST();
|
|
18
|
+
parser.ast.callbacks.expression = expressionCallback;
|
|
19
|
+
parser.ast.callbacks['parameter-name'] = parameterNameCallback;
|
|
20
|
+
parser.ast.callbacks.source = sourceCallback;
|
|
21
|
+
parser.ast.callbacks['header-reference'] = headerReferenceCallback;
|
|
22
|
+
parser.ast.callbacks['query-reference'] = queryReferenceCallback;
|
|
23
|
+
parser.ast.callbacks['path-reference'] = pathReferenceCallback;
|
|
24
|
+
parser.ast.callbacks['body-reference'] = bodyReferenceCallback;
|
|
25
|
+
parser.ast.callbacks['json-pointer'] = jsonPointerCallback;
|
|
26
|
+
parser.ast.callbacks['reference-token'] = referenceTokenCallback;
|
|
27
|
+
parser.ast.callbacks.name = nameCallback;
|
|
28
|
+
parser.ast.callbacks.token = tokenCallback;
|
|
29
|
+
const result = parser.parse(grammar, 'expression', runtimeExpression);
|
|
30
|
+
return {
|
|
31
|
+
result,
|
|
32
|
+
ast: parser.ast
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export default parse;
|