@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.
Files changed (39) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +10 -0
  3. package/README.md +290 -0
  4. package/SECURITY.md +15 -0
  5. package/cjs/apg-lite.cjs +1221 -0
  6. package/cjs/extract.cjs +21 -0
  7. package/cjs/index.cjs +13 -0
  8. package/cjs/parse/callbacks/body-reference.cjs +14 -0
  9. package/cjs/parse/callbacks/expression.cjs +15 -0
  10. package/cjs/parse/callbacks/header-reference.cjs +14 -0
  11. package/cjs/parse/callbacks/json-pointer.cjs +14 -0
  12. package/cjs/parse/callbacks/name.cjs +14 -0
  13. package/cjs/parse/callbacks/parameter-name.cjs +14 -0
  14. package/cjs/parse/callbacks/path-reference.cjs +14 -0
  15. package/cjs/parse/callbacks/query-reference.cjs +14 -0
  16. package/cjs/parse/callbacks/reference-token.cjs +14 -0
  17. package/cjs/parse/callbacks/source.cjs +14 -0
  18. package/cjs/parse/callbacks/token.cjs +15 -0
  19. package/cjs/parse/index.cjs +40 -0
  20. package/cjs/runtime-expression.cjs +779 -0
  21. package/cjs/test.cjs +15 -0
  22. package/es/extract.mjs +17 -0
  23. package/es/index.mjs +4 -0
  24. package/es/parse/callbacks/body-reference.mjs +10 -0
  25. package/es/parse/callbacks/expression.mjs +11 -0
  26. package/es/parse/callbacks/header-reference.mjs +10 -0
  27. package/es/parse/callbacks/json-pointer.mjs +10 -0
  28. package/es/parse/callbacks/name.mjs +10 -0
  29. package/es/parse/callbacks/parameter-name.mjs +10 -0
  30. package/es/parse/callbacks/path-reference.mjs +10 -0
  31. package/es/parse/callbacks/query-reference.mjs +10 -0
  32. package/es/parse/callbacks/reference-token.mjs +10 -0
  33. package/es/parse/callbacks/source.mjs +10 -0
  34. package/es/parse/callbacks/token.mjs +10 -0
  35. package/es/parse/index.mjs +35 -0
  36. package/es/runtime-expression.mjs +775 -0
  37. package/es/test.mjs +10 -0
  38. package/package.json +82 -0
  39. 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,4 @@
1
+ export { default as Grammar } from "./runtime-expression.mjs";
2
+ export { default as extract } from "./extract.mjs";
3
+ export { default as test } from "./test.mjs";
4
+ export { default as parse } from "./parse/index.mjs";
@@ -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;