@feathersjs/transport-commons 5.0.39 → 6.0.0-pre.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/CHANGELOG.md +86 -0
- package/LICENSE +1 -2
- package/README.md +1 -1
- package/client.d.ts +1 -1
- package/client.js +1 -1
- package/lib/client.d.ts +1 -1
- package/lib/client.js +6 -10
- package/lib/client.js.map +1 -1
- package/lib/index.d.ts +3 -6
- package/lib/index.js +3 -45
- package/lib/index.js.map +1 -1
- package/lib/socket/index.d.ts +1 -1
- package/lib/socket/index.js +6 -13
- package/lib/socket/index.js.map +1 -1
- package/lib/socket/utils.d.ts +2 -2
- package/lib/socket/utils.js +17 -26
- package/lib/socket/utils.js.map +1 -1
- package/package.json +9 -9
- package/src/client.ts +1 -2
- package/src/index.ts +3 -7
- package/src/socket/index.ts +3 -7
- package/src/socket/utils.ts +3 -9
- package/lib/channels/channel/base.d.ts +0 -12
- package/lib/channels/channel/base.js +0 -48
- package/lib/channels/channel/base.js.map +0 -1
- package/lib/channels/channel/combined.d.ts +0 -15
- package/lib/channels/channel/combined.js +0 -45
- package/lib/channels/channel/combined.js.map +0 -1
- package/lib/channels/index.d.ts +0 -28
- package/lib/channels/index.js +0 -86
- package/lib/channels/index.js.map +0 -1
- package/lib/channels/mixins.d.ts +0 -29
- package/lib/channels/mixins.js +0 -72
- package/lib/channels/mixins.js.map +0 -1
- package/lib/http.d.ts +0 -35
- package/lib/http.js +0 -77
- package/lib/http.js.map +0 -1
- package/lib/routing/index.d.ts +0 -21
- package/lib/routing/index.js +0 -49
- package/lib/routing/index.js.map +0 -1
- package/lib/routing/router.d.ts +0 -31
- package/lib/routing/router.js +0 -114
- package/lib/routing/router.js.map +0 -1
- package/src/channels/channel/base.ts +0 -58
- package/src/channels/channel/combined.ts +0 -57
- package/src/channels/index.ts +0 -120
- package/src/channels/mixins.ts +0 -108
- package/src/http.ts +0 -95
- package/src/routing/index.ts +0 -62
- package/src/routing/router.ts +0 -148
package/src/routing/router.ts
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { stripSlashes } from '@feathersjs/commons'
|
|
2
|
-
|
|
3
|
-
export interface LookupData {
|
|
4
|
-
params: { [key: string]: string }
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface LookupResult<T> extends LookupData {
|
|
8
|
-
data?: T
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export class RouteNode<T = any> {
|
|
12
|
-
data?: T
|
|
13
|
-
children: { [key: string]: RouteNode } = {}
|
|
14
|
-
placeholders: RouteNode[] = []
|
|
15
|
-
|
|
16
|
-
constructor(
|
|
17
|
-
public name: string,
|
|
18
|
-
public depth: number
|
|
19
|
-
) {}
|
|
20
|
-
|
|
21
|
-
get hasChildren() {
|
|
22
|
-
return Object.keys(this.children).length !== 0 || this.placeholders.length !== 0
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
insert(path: string[], data: T): RouteNode<T> {
|
|
26
|
-
if (this.depth === path.length) {
|
|
27
|
-
if (this.data !== undefined) {
|
|
28
|
-
throw new Error(`Path ${path.join('/')} already exists`)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
this.data = data
|
|
32
|
-
return this
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const current = path[this.depth]
|
|
36
|
-
const nextDepth = this.depth + 1
|
|
37
|
-
|
|
38
|
-
if (current.startsWith(':')) {
|
|
39
|
-
// Insert a placeholder node like /messages/:id
|
|
40
|
-
const placeholderName = current.substring(1)
|
|
41
|
-
let placeholder = this.placeholders.find((p) => p.name === placeholderName)
|
|
42
|
-
|
|
43
|
-
if (!placeholder) {
|
|
44
|
-
placeholder = new RouteNode(placeholderName, nextDepth)
|
|
45
|
-
this.placeholders.push(placeholder)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return placeholder.insert(path, data)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const child = this.children[current] || new RouteNode(current, nextDepth)
|
|
52
|
-
|
|
53
|
-
this.children[current] = child
|
|
54
|
-
|
|
55
|
-
return child.insert(path, data)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
remove(path: string[]) {
|
|
59
|
-
if (path.length === this.depth) {
|
|
60
|
-
delete this.data
|
|
61
|
-
return
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const current = path[this.depth]
|
|
65
|
-
|
|
66
|
-
if (current.startsWith(':')) {
|
|
67
|
-
const placeholderName = current.substring(1)
|
|
68
|
-
const placeholder = this.placeholders.find((p) => p.name === placeholderName)
|
|
69
|
-
|
|
70
|
-
placeholder.remove(path)
|
|
71
|
-
this.placeholders = this.placeholders.filter((p) => p !== placeholder)
|
|
72
|
-
} else if (this.children[current]) {
|
|
73
|
-
const child = this.children[current]
|
|
74
|
-
|
|
75
|
-
child.remove(path)
|
|
76
|
-
|
|
77
|
-
if (!child.hasChildren) {
|
|
78
|
-
delete this.children[current]
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
lookup(path: string[], info: LookupData): LookupResult<T> | null {
|
|
84
|
-
if (path.length === this.depth) {
|
|
85
|
-
return this.data === undefined
|
|
86
|
-
? null
|
|
87
|
-
: {
|
|
88
|
-
...info,
|
|
89
|
-
data: this.data
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const current = path[this.depth]
|
|
94
|
-
const child = this.children[current]
|
|
95
|
-
|
|
96
|
-
if (child) {
|
|
97
|
-
const lookup = child.lookup(path, info)
|
|
98
|
-
|
|
99
|
-
if (lookup !== null) {
|
|
100
|
-
return lookup
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// This will return the first placeholder that matches early
|
|
105
|
-
for (const placeholder of this.placeholders) {
|
|
106
|
-
const result = placeholder.lookup(path, info)
|
|
107
|
-
|
|
108
|
-
if (result !== null) {
|
|
109
|
-
result.params[placeholder.name] = current
|
|
110
|
-
return result
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return null
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export class Router<T = any> {
|
|
119
|
-
public caseSensitive = true
|
|
120
|
-
|
|
121
|
-
constructor(public root: RouteNode<T> = new RouteNode<T>('', 0)) {}
|
|
122
|
-
|
|
123
|
-
getPath(path: string) {
|
|
124
|
-
const result = stripSlashes(path).split('/')
|
|
125
|
-
|
|
126
|
-
if (!this.caseSensitive) {
|
|
127
|
-
return result.map((p) => (p.startsWith(':') ? p : p.toLowerCase()))
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return result
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
insert(path: string, data: T) {
|
|
134
|
-
return this.root.insert(this.getPath(path), data)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
remove(path: string) {
|
|
138
|
-
return this.root.remove(this.getPath(path))
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
lookup(path: string) {
|
|
142
|
-
if (typeof path !== 'string') {
|
|
143
|
-
return null
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return this.root.lookup(this.getPath(path), { params: {} })
|
|
147
|
-
}
|
|
148
|
-
}
|