Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Rework using webapi-parser #14

Merged
merged 33 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f0ff233
Fix security issues
postatum Nov 18, 2019
0a50ea8
Start reworking
postatum Nov 18, 2019
7d0a27c
Rework part of the lib
postatum Nov 19, 2019
a8d0436
Finish initial reworking
postatum Nov 19, 2019
74f2938
Fix reworking bug
postatum Nov 19, 2019
3136234
Make initial tests rework
postatum Nov 19, 2019
46463a7
Fixing bugs and reworking tests
postatum Nov 19, 2019
610b5d8
Finish reworking and fixing tests
postatum Nov 20, 2019
fee9d88
Make code compatible with Node =<10
postatum Nov 20, 2019
3b84b05
Fix jsdocs comments
postatum Nov 20, 2019
3655d0c
Rename vars to remove ambiguity
postatum Nov 25, 2019
84fcc1c
Update dependencies
postatum Nov 28, 2019
c76574c
Await for webapi-parser init
postatum Nov 28, 2019
1d8c57a
Update webapi-parser
postatum Dec 4, 2019
65f65db
Attempt to rework with proper wap.init() call
postatum Dec 16, 2019
bfbb19e
Fix bugs after async rework
postatum Dec 16, 2019
f2d8e01
Link to github raml-sanitize
postatum Dec 20, 2019
cd46502
Use re match compatible with node v8
postatum Dec 20, 2019
63ff13c
Update readme
postatum Dec 23, 2019
7c1c910
Update readme
postatum Dec 23, 2019
abe8311
Update readme
postatum Dec 23, 2019
8b7e7c6
Add more tests
postatum Dec 24, 2019
a689641
Rework to not call webapi-parser.init()
postatum Dec 24, 2019
60939cd
Unlink gh dependencies
postatum Dec 24, 2019
5bfe78e
Remove unnecessary async/await
postatum Feb 4, 2020
a6bdfb3
Use ajv for validation instead of webapi-parser
postatum Feb 4, 2020
8ab0138
Update webapi-parser to 0.5.0
postatum Feb 5, 2020
1a2875c
Downgrade webapi-parser
postatum Feb 5, 2020
702c9b1
Update deps
postatum Feb 27, 2020
e3880cd
Merge master. Fix conflicts
postatum May 4, 2020
fd265a1
Update deps
postatum Jul 7, 2020
a7b731b
Merge fresh master
postatum Jul 8, 2020
8e279ad
Update dependencies
postatum Jul 28, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ language: node_js
node_js:
- "10"
- "12"
- "13"
- "14"
- "node"

cache:
Expand Down
31 changes: 14 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,38 @@ npm install raml-path-match --save
You must require the module and call it as a function with options to get the path matching utility back.

```javascript
var pathMatch = require('raml-path-match')({ ... });
const ramlPathMatch = require('raml-path-match')
const utils = require('./utils')

// Initialization Options
const options = {}

// Array<webapi-parser.Parameter>
const parameters = utils.getPathParameters()

// Create a simple path matching instance.
var match = patchMatch('/{route}', { route: { type: 'string' } });
const pathMatch = ramlPathMatch('/{route}', parameters, options)

match('/test'); //=> { match: '/test', params: { route: 'test' } }
pathMatch('/test'); //=> { match: '/test', params: { route: 'test' } }
```

### Initialization Options

* **end** - When set to `false`, the route will only match the beginning of paths.
* **strict** - When set to `true`, the route must match exactly without trailing slash.
* **sensitive** - When set to `true`, the route will be case-sensitive.
* **RAMLVersion** - The RAML version passed to [raml-validate](https://github.com/mulesoft/node-raml-validate) (default: `'RAML08'`)

### Routes

The route is a string that can be interpolated with parameters. E.g. `/{route}`.

### Parameters

Parameters in the route string can be defined by passing in an object definition adhering to the [RAML spec](https://github.com/raml-org/raml-spec/blob/master/raml-0.8.md#named-parameters). For example, to specify that `{route}` is a integer greater than `5` we would pass in:

```javascript
pathMatch('/{route}', {
route: {
type: 'integer',
minimum: 6
}
}); //=> [Function]
```
Parameters in the route string must be defined as an array of [webapi-parser](https://github.com/raml-org/webapi-parser) `Parameter` objects.

#### Optional parameters

Parameters can be optional according to the [RAML spec](https://github.com/raml-org/raml-spec/blob/master/raml-0.8.md#required). To set the parameter to be optional, you must set `required: false`. With this option set, `/{route}` will match just `/`. When the parameter is optional and not matched, the parameter value will be set to `undefined`.
Parameters can be optional according to the [RAML spec](https://github.com/raml-org/raml-spec/blob/master/raml-0.8.md#required). With optional parameters, `/{route}` will match just `/`. When the parameter is optional and not matched, the parameter value will be set to `undefined`.

### Matching the path

Expand All @@ -69,9 +66,9 @@ The path matching instance will return a function after you give it the route te

The above is an example of passing the path `/123` to the result of the previous example. Notice that parameters will be automatically sanitized to the native JavaScript types.

### Immutable Updates
### Updates

You can merge more parameters into the path after creation using `pathMatch.update(params)`. It'll return a new function, or reuse the current function if there's no functional difference with the new parameters.
You can merge more parameters into the path after creation using `pathMatch.update(params)`. It'll return a new patch matching function.

## License

Expand Down
Loading