Gathering detailed insights and metrics for @diotoborg/sit-et-quibusdam
Gathering detailed insights and metrics for @diotoborg/sit-et-quibusdam
Gathering detailed insights and metrics for @diotoborg/sit-et-quibusdam
Gathering detailed insights and metrics for @diotoborg/sit-et-quibusdam
npm install @diotoborg/sit-et-quibusdam
Typescript
Module System
Node Version
NPM Version
73.4
Supply Chain
100
Quality
86.2
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
1,772 Commits
1 Watching
1 Branches
1 Contributors
Latest Version
3.10.92
Package Id
@diotoborg/sit-et-quibusdam@3.10.92
Unpacked Size
238.67 kB
Size
123.77 kB
File Count
653
NPM Version
10.8.2
Node Version
20.17.0
Publised On
22 Sept 2024
Cumulative downloads
Total Downloads
Last day
0%
0
Compared to previous day
Last week
0%
0
Compared to previous week
Last month
0%
0
Compared to previous month
Last year
0%
0
Compared to previous year
29
Path Templating allow defining values based on information that will only be available within the HTTP message in an actual API call. This mechanism is used by Paths Object of OpenAPI specification.
@diotoborg/sit-et-quibusdam
is a parser, validator and resolver for OpenAPI Path Templating. It supports
Path Templating defined in following OpenAPI specification versions:
Get professionally supported @diotoborg/sit-et-quibusdam with Tidelift Subscription. |
You can install @diotoborg/sit-et-quibusdam
using npm
:
1 $ npm install @diotoborg/sit-et-quibusdam
@diotoborg/sit-et-quibusdam
currently supports parsing, validation and resolution.
Both parser and validator are based on a superset of ABNF (SABNF)
and use apg-lite parser generator.
Parsing a Path Templating is as simple as importing the parse function and calling it.
1import { parse } from '@diotoborg/sit-et-quibusdam'; 2 3const parseResult = parse('/pets/{petId}'); 4parseResult.result.success; // => true
parseResult variable has the following shape:
{
result: {
success: true,
state: 101,
stateName: 'MATCH',
length: 13,
matched: 13,
maxMatched: 13,
maxTreeDepth: 18,
nodeHits: 324
},
ast: fnast {
callbacks: [
'path-template': [Function: pathTemplate],
path: [Function: path],
query: [Function: query],
'query-marker': [Function: queryMarker],
fragment: [Function: fragment],
'fragment-marker': [Function: fragmentMarker],
slash: [Function: slash],
'path-literal': [Function: pathLiteral],
'template-expression': [Function: templateExpression],
'template-expression-param-name': [Function: templateExpressionParamName]
],
init: [Function (anonymous)],
ruleDefined: [Function (anonymous)],
udtDefined: [Function (anonymous)],
down: [Function (anonymous)],
up: [Function (anonymous)],
translate: [Function (anonymous)],
setLength: [Function (anonymous)],
getLength: [Function (anonymous)],
toXml: [Function (anonymous)]
}
}
1import { parse } from '@diotoborg/sit-et-quibusdam'; 2 3const parseResult = parse('/pets/{petId}'); 4const parts = []; 5 6parseResult.ast.translate(parts);
After running the above code, parts variable has the following shape:
1[ 2 [ 'path-template', '/pets/{petId}' ], 3 [ 'path', '/pets/{petId}' ], 4 [ 'slash', '/' ], 5 [ 'path-literal', 'pets' ], 6 [ 'slash', '/' ], 7 [ 'template-expression', '{petId}' ], 8 [ 'template-expression-param-name', 'petId' ] 9]
1import { parse } from '@diotoborg/sit-et-quibusdam'; 2 3const parseResult = parse('/pets/{petId}'); 4const xml = parseResult.ast.toXml();
After running the above code, xml variable has the following content:
1<?xml version="1.0" encoding="utf-8"?> 2<root nodes="7" characters="13"> 3 <!-- input string --> 4 /pets/{petId} 5 <node name="path-template" index="0" length="13"> 6 /pets/{petId} 7 <node name="path" index="0" length="13"> 8 /pets/{petId} 9 <node name="slash" index="0" length="1"> 10 / 11 </node><!-- name="slash" --> 12 <node name="path-literal" index="1" length="4"> 13 pets 14 </node><!-- name="path-literal" --> 15 <node name="slash" index="5" length="1"> 16 / 17 </node><!-- name="slash" --> 18 <node name="template-expression" index="6" length="7"> 19 {petId} 20 <node name="template-expression-param-name" index="7" length="5"> 21 petId 22 </node><!-- name="template-expression-param-name" --> 23 </node><!-- name="template-expression" --> 24 </node><!-- name="path" --> 25 </node><!-- name="path-template" --> 26</root>
NOTE: AST can also be traversed in classical way using depth first traversal. For more information about this option please refer to apg-js and apg-js-examples.
Validating a Path Templating is as simple as importing the test function and calling it.
1import { test } from '@diotoborg/sit-et-quibusdam'; 2 3test('/pets/{petId}'); // => true 4test('/a{petId}'); // => true 5test('/pets'); // => true 6test('/pets', { strict: true }); // => false (doesn't contain any template-expression)
Resolving a Path Templating is as simple as importing the resolve function and calling it.
1import { resolve } from '@diotoborg/sit-et-quibusdam'; 2 3resolve('/pets/{petId}', { petId: 3 }); // => "/pets/3"
Resolved Path Templating is automatically encoded using encodeURIComponent function. It is possible to provide a custom encoder.
1import { resolve } from '@diotoborg/sit-et-quibusdam'; 2 3resolve('/pets/{petId}', { petId: '/?#' }, { 4 encoder: (component) => component, // no encoding 5}); // => "/pets//?#"
New grammar instance can be created in following way:
1import { Grammar } from '@diotoborg/sit-et-quibusdam'; 2 3const grammar = new Grammar();
To obtain original ABNF (SABNF) grammar as a string:
1import { Grammar } from '@diotoborg/sit-et-quibusdam'; 2 3const grammar = new Grammar(); 4 5grammar.toString(); 6// or 7String(grammar);
The Path Templating is defined by the following ABNF syntax
1; OpenAPI Path Templating ABNF syntax 2path-template = path [ query-marker query ] [ fragment-marker fragment ] 3path = slash *( path-segment slash ) [ path-segment ] 4path-segment = 1*( path-literal / template-expression ) 5query = *( query-literal ) 6query-literal = 1*( unreserved / pct-encoded / sub-delims / ":" / "@" / "/" / "?" / "&" / "=" ) 7query-marker = "?" 8fragment = *( fragment-literal ) 9fragment-literal = 1*( unreserved / pct-encoded / sub-delims / ":" / "@" / "/" / "?" ) 10fragment-marker = "#" 11slash = "/" 12path-literal = 1*( unreserved / pct-encoded / sub-delims / ":" / "@" ) 13template-expression = "{" template-expression-param-name "}" 14template-expression-param-name = 1*( unreserved / pct-encoded / sub-delims / ":" / "@" ) 15 16; Characters definitions (from RFC 3986) 17unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" 18pct-encoded = "%" HEXDIG HEXDIG 19sub-delims = "!" / "$" / "&" / "'" / "(" / ")" 20 / "*" / "+" / "," / ";" / "=" 21ALPHA = %x41-5A / %x61-7A ; A-Z / a-z 22DIGIT = %x30-39 ; 0-9 23HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F"
@diotoborg/sit-et-quibusdam
is licensed under Apache 2.0 license.
@diotoborg/sit-et-quibusdam
comes with an explicit NOTICE file
containing additional legal notices and information.
No vulnerabilities found.
No security vulnerabilities found.